|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Motion for Vue is a Vue.js port of Framer Motion, providing declarative animations with a hybrid engine combining JavaScript animations and native browser APIs. The library exports components like `motion`, `AnimatePresence`, `LayoutGroup`, `MotionConfig`, and `Reorder` for creating animations, gestures, and layout transitions. |
| 8 | + |
| 9 | +## Key Commands |
| 10 | + |
| 11 | +### Development |
| 12 | +- `pnpm dev` - Start development watch mode for motion package |
| 13 | +- `pnpm build` - Build the motion package and plugins |
| 14 | +- `pnpm test` - Run unit tests for motion package |
| 15 | +- `pnpm test:e2e` - Run Playwright end-to-end tests |
| 16 | +- `pnpm play` - Start the Nuxt playground for interactive testing |
| 17 | + |
| 18 | +### Documentation |
| 19 | +- `pnpm docs:dev` - Start documentation development server |
| 20 | +- `pnpm docs:build` - Build documentation site |
| 21 | + |
| 22 | +### Testing |
| 23 | +- Single test: `pnpm --filter motion-v test [test-file-name]` |
| 24 | +- Coverage: `pnpm --filter motion-v coverage` |
| 25 | +- E2E UI: `pnpm test:e2e:ui` |
| 26 | + |
| 27 | +### Linting & Formatting |
| 28 | +- ESLint is configured to run automatically on pre-commit via git hooks |
| 29 | +- Manual lint: Files are automatically fixed on commit |
| 30 | + |
| 31 | +## Architecture |
| 32 | + |
| 33 | +### Package Structure |
| 34 | +The monorepo contains three main packages: |
| 35 | +- `packages/motion/` - Core motion library (published as `motion-v`) |
| 36 | +- `packages/plugins/` - Nuxt module and resolver for unplugin-vue-components |
| 37 | +- `playground/` - Testing environments (Nuxt and Vite playgrounds) |
| 38 | + |
| 39 | +### Core Components Architecture |
| 40 | +Motion components are built on top of Framer Motion's core, with Vue-specific adaptations: |
| 41 | + |
| 42 | +1. **Motion Component System** (`packages/motion/src/components/motion/`) |
| 43 | + - Creates motion-enabled HTML/SVG elements using dynamic component rendering |
| 44 | + - Manages animation state through `useMotionState` composable |
| 45 | + - Handles variant propagation and gesture features |
| 46 | + |
| 47 | +2. **Visual Element State** (`packages/motion/src/state/`) |
| 48 | + - Creates and manages visual elements with projection nodes for layout animations |
| 49 | + - Handles style transformations and animation lifecycles |
| 50 | + - Integrates with Framer Motion's store system |
| 51 | + |
| 52 | +3. **Feature System** (`packages/motion/src/features/`) |
| 53 | + - Modular feature loading (gestures, animations, layout) |
| 54 | + - Each feature extends the visual element with specific capabilities |
| 55 | + - Gesture features include drag, hover, press, pan, and in-view detection |
| 56 | + |
| 57 | +4. **Animation Controls** (`packages/motion/src/animation/`) |
| 58 | + - Provides imperative animation controls via `useAnimationControls` |
| 59 | + - Manages animation sequencing and orchestration across components |
| 60 | + |
| 61 | +5. **Layout Animations** (`packages/motion/src/features/layout/`) |
| 62 | + - Handles shared layout animations between components |
| 63 | + - Manages projection nodes for FLIP animations |
| 64 | + - Supports layout groups for coordinated animations |
| 65 | + |
| 66 | +### Build Configuration |
| 67 | +- Uses Vite for building with separate ES and CJS outputs |
| 68 | +- Includes complex path aliasing for Framer Motion internals |
| 69 | +- Post-build step triggers plugin builds automatically |
| 70 | + |
| 71 | +### Testing Strategy |
| 72 | +- Unit tests use Vitest with Vue Test Utils in JSDOM environment |
| 73 | +- E2E tests use Playwright for browser-based testing |
| 74 | +- Test files are co-located with source code in `__tests__` directories |
| 75 | + |
| 76 | +## Important Implementation Notes |
| 77 | + |
| 78 | +1. **Framer Motion Integration**: The library wraps Framer Motion's core functionality, requiring careful path aliasing to specific internal modules. |
| 79 | + |
| 80 | +2. **Component Rendering**: Motion components use Vue's dynamic component system with render functions to create motion-enabled elements. |
| 81 | + |
| 82 | +3. **State Management**: Visual element state is managed through a combination of Vue reactivity and Framer Motion's store system. |
| 83 | + |
| 84 | +4. **Gesture Handling**: Gesture features are implemented as composables that attach event listeners and manage interaction state. |
| 85 | + |
| 86 | +5. **Performance**: The library uses lazy loading for features and optimizes re-renders through careful state management. |
| 87 | + |
| 88 | +## Development Workflow |
| 89 | + |
| 90 | +1. Always run `pnpm build` after modifying the motion package before testing in playground |
| 91 | +2. Use the playground environments to test changes interactively |
| 92 | +3. Add tests for new features in the appropriate `__tests__` directory |
| 93 | +4. Ensure commits follow conventional commit format (enforced by commitlint) |
0 commit comments