@hilux/ngx-motion 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +289 -269
- package/fesm2022/hilux-ngx-motion.mjs +2030 -0
- package/fesm2022/hilux-ngx-motion.mjs.map +1 -0
- package/package.json +35 -31
- package/types/hilux-ngx-motion.d.ts +777 -0
- package/ng-package.json +0 -7
- package/src/lib/components/motion-one-presence.component.ts +0 -116
- package/src/lib/constants/motion-defaults.constants.ts +0 -41
- package/src/lib/directives/motion-animate.directive.ts +0 -55
- package/src/lib/directives/motion-if.directive.ts +0 -138
- package/src/lib/directives/motion-one.directive.backup.ts +0 -1591
- package/src/lib/directives/motion-one.directive.ts +0 -1154
- package/src/lib/directives/motion-presence.directive.ts +0 -145
- package/src/lib/services/motion-animation-options.service.ts +0 -142
- package/src/lib/services/motion-animation.service.ts +0 -86
- package/src/lib/services/motion-browser-safe.ts +0 -64
- package/src/lib/services/motion-gesture.service.ts +0 -141
- package/src/lib/services/motion-inview.service.ts +0 -91
- package/src/lib/services/motion-one.service.ts +0 -424
- package/src/lib/services/motion-stagger.service.ts +0 -70
- package/src/lib/services/motion-timeline.service.ts +0 -182
- package/src/lib/types/motion-animation.types.ts +0 -46
- package/src/lib/utils/color.utils.ts +0 -54
- package/src/lib/utils/easing.utils.ts +0 -77
- package/src/lib/utils/index.ts +0 -7
- package/src/lib/utils/style-extraction.utils.ts +0 -70
- package/src/lib/utils/timing.utils.ts +0 -61
- package/src/lib/utils/transform.utils.ts +0 -112
- package/src/lib/utils/variant.utils.ts +0 -55
- package/src/public-api.ts +0 -21
- package/tsconfig.lib.json +0 -17
- package/tsconfig.lib.prod.json +0 -11
- package/tsconfig.spec.json +0 -15
package/README.md
CHANGED
|
@@ -1,14 +1,65 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ngx-motion: Framer Motion-style animations for Angular
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@hilux/ngx-motion)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+

|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
**@hilux/ngx-motion** is an Angular animation library that brings a Framer Motion-style declarative API to Angular templates. Add `motionone` to any element and describe its `initial`, `animate` and `exit` states. You also get spring physics, hover/tap/focus gestures, staggered children, scroll-triggered (in-view) animation and exit animations. It's built on [Motion](https://motion.dev) (motion.dev), so animations run on the Web Animations API where possible.
|
|
8
|
+
|
|
9
|
+
**[Live demo and examples →](https://rikisommers.github.io/angular-motion-poc/examples)** · **[Docs →](https://rikisommers.github.io/angular-motion-poc/docs)** · **[npm →](https://www.npmjs.com/package/@hilux/ngx-motion)**
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
6
12
|
|
|
7
13
|
```bash
|
|
8
|
-
npm install ngx-motion motion
|
|
14
|
+
npm install @hilux/ngx-motion motion
|
|
9
15
|
```
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
```typescript
|
|
18
|
+
import { Component } from '@angular/core';
|
|
19
|
+
import { MotionOneDirective } from '@hilux/ngx-motion';
|
|
20
|
+
|
|
21
|
+
@Component({
|
|
22
|
+
selector: 'app-card',
|
|
23
|
+
imports: [MotionOneDirective],
|
|
24
|
+
template: `
|
|
25
|
+
<div motionone
|
|
26
|
+
[initial]="{ opacity: 0, y: 40 }"
|
|
27
|
+
[animate]="{ opacity: 1, y: 0 }"
|
|
28
|
+
[whileHover]="{ scale: 1.05 }"
|
|
29
|
+
[transition]="{ type: 'spring', stiffness: 300, damping: 20 }">
|
|
30
|
+
Hello
|
|
31
|
+
</div>
|
|
32
|
+
`
|
|
33
|
+
})
|
|
34
|
+
export class CardComponent {}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Requirements
|
|
38
|
+
|
|
39
|
+
| Package | Version |
|
|
40
|
+
|---------|---------|
|
|
41
|
+
| Angular (`@angular/core`, `@angular/common`) | 22+ (for Angular 19, use `@hilux/ngx-motion@1`) |
|
|
42
|
+
| `motion` | 12, 13 or 14 |
|
|
43
|
+
| Node.js | 22.22+ or 24.15+ |
|
|
44
|
+
|
|
45
|
+
## Features
|
|
46
|
+
|
|
47
|
+
- **Declarative states:** `initial`, `animate` and `exit`, written as plain objects in the template.
|
|
48
|
+
- **Spring physics:** `transition: { type: 'spring', stiffness, damping }`.
|
|
49
|
+
- **Gestures:** `whileHover`, `whileTap` and `whileFocus` animate in and spring back out.
|
|
50
|
+
- **Stagger orchestration:** `staggerChildren`, `delayChildren` and `staggerDirection`. Nested parents orchestrate their own children.
|
|
51
|
+
- **Scroll / in-view:** `runInView="once"` or `"always"`, and `whileInView`.
|
|
52
|
+
- **Exit animations:** `*motionIf` and `*motionPresence` keep elements in the DOM until their exit animation finishes. If shown again mid-exit, they animate back in.
|
|
53
|
+
- **Variants:** named, reusable animation states.
|
|
54
|
+
- **Timelines:** sequence several steps on one element.
|
|
55
|
+
- **Transform shortcuts:** `x`, `y`, `scale`, `rotate` and `skew`, instead of transform strings.
|
|
56
|
+
- **Repeat:** `repeat: Infinity` with `loop`, `reverse` or `mirror`.
|
|
57
|
+
- **Per-property transitions:** different timing for each property.
|
|
58
|
+
- **Performance:** animations, timers and listeners run outside Angular's change detection, and gesture listeners are only attached when used.
|
|
59
|
+
- **SSR-safe:** animation code only runs in the browser.
|
|
60
|
+
- **Typed:** full TypeScript types for states, transitions and variants.
|
|
61
|
+
|
|
62
|
+
## Basic Usage
|
|
12
63
|
|
|
13
64
|
Import the directive in your component:
|
|
14
65
|
|
|
@@ -24,7 +75,7 @@ import { MotionOneDirective } from '@hilux/ngx-motion';
|
|
|
24
75
|
motionone
|
|
25
76
|
[initial]="{ opacity: 0, y: 50 }"
|
|
26
77
|
[animate]="{ opacity: 1, y: 0 }"
|
|
27
|
-
[transition]="{ duration: 0.5 }"
|
|
78
|
+
[transition]="{ duration: 0.5, ease: 'easeOut' }"
|
|
28
79
|
>
|
|
29
80
|
Animated content
|
|
30
81
|
</div>
|
|
@@ -33,126 +84,9 @@ import { MotionOneDirective } from '@hilux/ngx-motion';
|
|
|
33
84
|
export class ExampleComponent {}
|
|
34
85
|
```
|
|
35
86
|
|
|
36
|
-
##
|
|
37
|
-
|
|
38
|
-
- ✅ **Motion One Integration**: Built on top of the performant Motion One animation library
|
|
39
|
-
- ✅ **Framer Motion API**: Familiar API for React developers
|
|
40
|
-
- ✅ **TypeScript Support**: Full type safety with TypeScript
|
|
41
|
-
- ✅ **Server-Side Rendering**: Compatible with Angular Universal
|
|
42
|
-
- ✅ **Stagger Animations**: Built-in support for staggered animations
|
|
43
|
-
- ✅ **Timeline Support**: Create complex sequential animations
|
|
44
|
-
- ✅ **Conditional Rendering**: `motionIf` directive for animated presence
|
|
45
|
-
- ✅ **Gesture Support**: whileHover, whileTap, whileFocus animations
|
|
46
|
-
|
|
47
|
-
## API Reference
|
|
48
|
-
|
|
49
|
-
### Animation State Inputs
|
|
50
|
-
|
|
51
|
-
| Input | Type | Default | Description |
|
|
52
|
-
|-------|------|---------|-------------|
|
|
53
|
-
| `initial` | `VariantWithTransition \| string` | `{}` | Initial animation state when element mounts |
|
|
54
|
-
| `animate` | `VariantWithTransition \| string` | `{}` | Target animation state to animate to |
|
|
55
|
-
| `exit` | `VariantWithTransition \| string` | `{}` | Animation state when element unmounts |
|
|
56
|
-
| `inView` | `VariantWithTransition` | `{}` | Animation state when element enters viewport |
|
|
57
|
-
| `whileHover` | `VariantWithTransition` | `{}` | Animation state while hovering over element |
|
|
58
|
-
| `whileTap` | `VariantWithTransition` | `{}` | Animation state while pressing/tapping element |
|
|
59
|
-
| `whileFocus` | `VariantWithTransition` | `{}` | Animation state while element is focused |
|
|
60
|
-
| `whileInView` | `VariantWithTransition` | `{}` | Animation state while element is in viewport |
|
|
61
|
-
|
|
62
|
-
### Timing & Easing Inputs
|
|
63
|
-
|
|
64
|
-
| Input | Type | Default | Description |
|
|
65
|
-
|-------|------|---------|-------------|
|
|
66
|
-
| `duration` | `number` | `0.3` | Default animation duration in seconds |
|
|
67
|
-
| `delay` | `number` | `0` | Default delay before animation starts in seconds |
|
|
68
|
-
| `exitDelay` | `number` | `0` | Delay before exit animation starts in seconds |
|
|
69
|
-
| `easing` | `string \| number[] \| SpringConfig` | `'ease'` | Default easing function for animations |
|
|
70
|
-
|
|
71
|
-
### Children Animation Inputs
|
|
72
|
-
|
|
73
|
-
| Input | Type | Default | Description |
|
|
74
|
-
|-------|------|---------|-------------|
|
|
75
|
-
| `delayChildren` | `number` | `0` | Delay before children animations start in seconds |
|
|
76
|
-
| `staggerChildren` | `number` | `1` | Time between each child animation start in seconds |
|
|
77
|
-
| `staggerDirection` | `number` | `1` | Direction of stagger (1 = forward, -1 = reverse) |
|
|
78
|
-
|
|
79
|
-
### Advanced Inputs
|
|
80
|
-
|
|
81
|
-
| Input | Type | Default | Description |
|
|
82
|
-
|-------|------|---------|-------------|
|
|
83
|
-
| `variants` | `Record<string, VariantWithTransition>` | `{}` | Named animation variants for reusable states |
|
|
84
|
-
| `transition` | `TransitionOptions \| Record<string, TransitionOptions>` | `{}` | Transition configuration (overrides individual timing inputs) |
|
|
85
|
-
| `timeline` | `TimelineStep[]` | `undefined` | Sequential animation timeline for complex animations |
|
|
86
|
-
| `repeat` | `boolean` | `false` | Whether to repeat the animation infinitely |
|
|
87
|
-
| `offset` | `string` | `'0px'` | Intersection observer margin for inView detection |
|
|
88
|
-
|
|
89
|
-
### Output Events
|
|
90
|
-
|
|
91
|
-
| Output | Type | Description |
|
|
92
|
-
|--------|------|-------------|
|
|
93
|
-
| `animationComplete` | `EventEmitter<void>` | Emitted when animation completes |
|
|
94
|
-
|
|
95
|
-
## Type Definitions
|
|
96
|
-
|
|
97
|
-
### VariantWithTransition
|
|
98
|
-
```typescript
|
|
99
|
-
interface VariantWithTransition {
|
|
100
|
-
[key: string]: any;
|
|
101
|
-
transition?: TransitionOptions;
|
|
102
|
-
at?: number; // Delay in seconds before this variant triggers
|
|
103
|
-
}
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### TransitionOptions
|
|
107
|
-
```typescript
|
|
108
|
-
interface TransitionOptions {
|
|
109
|
-
duration?: number;
|
|
110
|
-
delay?: number;
|
|
111
|
-
ease?: string | number[] | { type: 'spring'; stiffness?: number; damping?: number };
|
|
112
|
-
repeat?: number | boolean;
|
|
113
|
-
repeatType?: 'loop' | 'mirror' | 'reverse' | 'forwards' | 'pingPong';
|
|
114
|
-
repeatDelay?: number;
|
|
115
|
-
staggerChildren?: number;
|
|
116
|
-
staggerDirection?: number;
|
|
117
|
-
when?: 'beforeChildren' | 'afterChildren' | 'together';
|
|
118
|
-
delayChildren?: number;
|
|
119
|
-
times?: number[]; // Keyframe timing array (0-1)
|
|
120
|
-
}
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### TimelineStep
|
|
124
|
-
```typescript
|
|
125
|
-
interface TimelineStep {
|
|
126
|
-
prop: string; // CSS property to animate
|
|
127
|
-
keyframes?: any[] | any; // Keyframe values
|
|
128
|
-
to?: any; // End value
|
|
129
|
-
duration: number; // Duration in seconds
|
|
130
|
-
delay?: number; // Delay in seconds
|
|
131
|
-
ease?: string | number[] | SpringConfig;
|
|
132
|
-
atTime?: number; // Absolute start time relative to element start
|
|
133
|
-
times?: number[]; // Keyframe timing array (0-1)
|
|
134
|
-
repeat?: number | boolean;
|
|
135
|
-
repeatType?: 'loop' | 'mirror' | 'reverse' | 'forwards' | 'pingPong';
|
|
136
|
-
repeatDelay?: number;
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## Examples
|
|
141
|
-
|
|
142
|
-
### Basic Animation
|
|
143
|
-
```html
|
|
144
|
-
<div
|
|
145
|
-
motionone
|
|
146
|
-
[initial]="{ opacity: 0, scale: 0.8 }"
|
|
147
|
-
[animate]="{ opacity: 1, scale: 1 }"
|
|
148
|
-
[duration]="0.5"
|
|
149
|
-
[easing]="'ease-out'"
|
|
150
|
-
>
|
|
151
|
-
Fade and scale in
|
|
152
|
-
</div>
|
|
153
|
-
```
|
|
87
|
+
## Animation Examples
|
|
154
88
|
|
|
155
|
-
### Hover
|
|
89
|
+
### Hover Animations
|
|
156
90
|
```html
|
|
157
91
|
<button
|
|
158
92
|
motionone
|
|
@@ -161,7 +95,7 @@ interface TimelineStep {
|
|
|
161
95
|
[whileTap]="{ scale: 0.95 }"
|
|
162
96
|
[transition]="{ type: 'spring', stiffness: 400, damping: 17 }"
|
|
163
97
|
>
|
|
164
|
-
|
|
98
|
+
Hover me!
|
|
165
99
|
</button>
|
|
166
100
|
```
|
|
167
101
|
|
|
@@ -171,8 +105,7 @@ interface TimelineStep {
|
|
|
171
105
|
motionone
|
|
172
106
|
[initial]="{ opacity: 0 }"
|
|
173
107
|
[animate]="{ opacity: 1 }"
|
|
174
|
-
[
|
|
175
|
-
[delayChildren]="0.3"
|
|
108
|
+
[transition]="{ staggerChildren: 0.1, delayChildren: 0.3 }"
|
|
176
109
|
>
|
|
177
110
|
<div motionone [initial]="{ x: -50, opacity: 0 }" [animate]="{ x: 0, opacity: 1 }">Item 1</div>
|
|
178
111
|
<div motionone [initial]="{ x: -50, opacity: 0 }" [animate]="{ x: 0, opacity: 1 }">Item 2</div>
|
|
@@ -180,7 +113,7 @@ interface TimelineStep {
|
|
|
180
113
|
</div>
|
|
181
114
|
```
|
|
182
115
|
|
|
183
|
-
###
|
|
116
|
+
### Variants
|
|
184
117
|
```typescript
|
|
185
118
|
@Component({
|
|
186
119
|
template: `
|
|
@@ -201,30 +134,37 @@ export class VariantsExample {
|
|
|
201
134
|
visible: {
|
|
202
135
|
opacity: 1,
|
|
203
136
|
transition: {
|
|
204
|
-
staggerChildren: 0.2
|
|
205
|
-
delayChildren: 0.1
|
|
137
|
+
staggerChildren: 0.2
|
|
206
138
|
}
|
|
207
139
|
}
|
|
208
140
|
};
|
|
209
141
|
|
|
210
142
|
itemVariants = {
|
|
211
143
|
hidden: { x: -20, opacity: 0 },
|
|
212
|
-
visible: {
|
|
213
|
-
x: 0,
|
|
214
|
-
opacity: 1,
|
|
215
|
-
transition: {
|
|
216
|
-
duration: 0.6,
|
|
217
|
-
ease: [0.33, 1, 0.68, 1]
|
|
218
|
-
}
|
|
219
|
-
}
|
|
144
|
+
visible: { x: 0, opacity: 1 }
|
|
220
145
|
};
|
|
221
146
|
}
|
|
222
147
|
```
|
|
223
148
|
|
|
224
|
-
###
|
|
149
|
+
### Conditional Animation with motionIf
|
|
150
|
+
```html
|
|
151
|
+
<button (click)="isVisible = !isVisible">Toggle</button>
|
|
225
152
|
|
|
226
|
-
|
|
153
|
+
<div *motionIf="isVisible">
|
|
154
|
+
<div
|
|
155
|
+
motionone
|
|
156
|
+
[initial]="{ scale: 0, opacity: 0 }"
|
|
157
|
+
[animate]="{ scale: 1, opacity: 1 }"
|
|
158
|
+
[exit]="{ scale: 0, opacity: 0 }"
|
|
159
|
+
[transition]="{ duration: 0.3 }"
|
|
160
|
+
>
|
|
161
|
+
This will animate in and out!
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
```
|
|
227
165
|
|
|
166
|
+
|
|
167
|
+
### Timeline Animations
|
|
228
168
|
```typescript
|
|
229
169
|
@Component({
|
|
230
170
|
template: `
|
|
@@ -232,183 +172,263 @@ Timeline animations allow you to orchestrate multiple properties with precise ti
|
|
|
232
172
|
motionone
|
|
233
173
|
[timeline]="complexTimeline"
|
|
234
174
|
[animate]="{ opacity: 1 }"
|
|
235
|
-
(animationComplete)="onAnimationComplete()"
|
|
236
175
|
>
|
|
237
176
|
Complex sequenced animation
|
|
238
177
|
</div>
|
|
239
178
|
`
|
|
240
179
|
})
|
|
241
180
|
export class TimelineExample {
|
|
242
|
-
complexTimeline
|
|
181
|
+
complexTimeline = [
|
|
243
182
|
{ prop: 'x', to: 100, duration: 1, atTime: 0 },
|
|
244
183
|
{ prop: 'rotate', to: 180, duration: 0.5, atTime: 0.5 },
|
|
245
|
-
{ prop: 'scale', to: 1.2, duration: 0.3, atTime: 1.2 }
|
|
246
|
-
{ prop: 'opacity', keyframes: [0, 1, 0.5, 1], duration: 2, atTime: 0.8 }
|
|
184
|
+
{ prop: 'scale', to: 1.2, duration: 0.3, atTime: 1.2 }
|
|
247
185
|
];
|
|
248
|
-
|
|
249
|
-
onAnimationComplete() {
|
|
250
|
-
console.log('Timeline animation completed!');
|
|
251
|
-
}
|
|
252
186
|
}
|
|
253
187
|
```
|
|
254
188
|
|
|
255
|
-
|
|
189
|
+
## Angular Control Flow Integration
|
|
256
190
|
|
|
257
|
-
|
|
191
|
+
Angular's control flow (`@if`, `@for`, etc.) removes elements immediately from the DOM when conditions change. To support exit animations, `@hilux/ngx-motion` provides structural directives that manage the animation lifecycle.
|
|
258
192
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
</div>
|
|
193
|
+
### Using `*motionIf` Directive
|
|
194
|
+
|
|
195
|
+
The `*motionIf` structural directive wraps Angular's template logic and manages enter/exit animations:
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
@Component({
|
|
199
|
+
selector: 'app-example',
|
|
200
|
+
imports: [MotionOneDirective, MotionIfDirective],
|
|
201
|
+
template: `
|
|
202
|
+
<button (click)="show = !show">
|
|
203
|
+
{{ show ? 'Hide' : 'Show' }}
|
|
204
|
+
</button>
|
|
205
|
+
|
|
206
|
+
<div *motionIf="show">
|
|
207
|
+
<div
|
|
208
|
+
motionone
|
|
209
|
+
[initial]="{ x: -100, opacity: 0 }"
|
|
210
|
+
[animate]="{ x: 0, opacity: 1 }"
|
|
211
|
+
[exit]="{ x: 100, opacity: 0 }"
|
|
212
|
+
[transition]="{ duration: 0.4, ease: { type: 'spring', stiffness: 300 } }"
|
|
213
|
+
>
|
|
214
|
+
Slides in from left, slides out to right
|
|
215
|
+
</div>
|
|
216
|
+
</div>
|
|
217
|
+
`
|
|
218
|
+
})
|
|
219
|
+
export class ControlFlowExample {
|
|
220
|
+
show = true;
|
|
221
|
+
}
|
|
289
222
|
```
|
|
290
223
|
|
|
291
|
-
**
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
224
|
+
**How it works:**
|
|
225
|
+
- `*motionIf` uses `ViewContainerRef` to control when views are created/destroyed
|
|
226
|
+
- When condition becomes `true`, it creates the view and triggers enter animation
|
|
227
|
+
- When condition becomes `false`, it triggers exit animation then removes from DOM
|
|
228
|
+
- Automatically calculates the longest animation duration to ensure smooth exit
|
|
229
|
+
- Supports multiple animated elements in a single template
|
|
230
|
+
|
|
231
|
+
### Using `*motionPresence` Directive
|
|
295
232
|
|
|
296
|
-
|
|
297
|
-
- **Overlapping Animations**: Multiple properties animate simultaneously with different timings
|
|
298
|
-
- **Custom Keyframe Timing**: `times` array controls when each keyframe occurs (0-1 normalized)
|
|
299
|
-
- **Mixed Easing**: Different easing functions per property (ease-out, ease-in, spring)
|
|
300
|
-
- **Absolute Timing**: `atTime` sets when each animation begins relative to timeline start
|
|
301
|
-
- **Duration Independence**: Each property can have completely different durations
|
|
233
|
+
Alternative structural directive with identical functionality, named for developers familiar with Framer Motion's `<AnimatePresence>`:
|
|
302
234
|
|
|
303
|
-
### Conditional Rendering with motionIf
|
|
304
235
|
```html
|
|
305
|
-
<div *
|
|
306
|
-
<div
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
[transition]="{ duration: 0.3, ease: 'backOut' }"
|
|
312
|
-
>
|
|
313
|
-
This will animate in and out smoothly!
|
|
236
|
+
<div *motionPresence="isVisible">
|
|
237
|
+
<div motionone
|
|
238
|
+
[initial]="{ opacity: 0, scale: 0.8 }"
|
|
239
|
+
[animate]="{ opacity: 1, scale: 1 }"
|
|
240
|
+
[exit]="{ opacity: 0, scale: 0.8 }">
|
|
241
|
+
Content
|
|
314
242
|
</div>
|
|
315
243
|
</div>
|
|
316
244
|
```
|
|
317
245
|
|
|
318
|
-
###
|
|
246
|
+
### Using with Angular's New Control Flow
|
|
247
|
+
|
|
248
|
+
The directives work seamlessly with Angular's new control flow syntax:
|
|
249
|
+
|
|
319
250
|
```html
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
[
|
|
323
|
-
[animate]="{ y: 0 }"
|
|
324
|
-
[easing]="{ type: 'spring', stiffness: 300, damping: 20 }"
|
|
325
|
-
>
|
|
326
|
-
Bouncy spring animation
|
|
251
|
+
<!-- With @if -->
|
|
252
|
+
<div *motionIf="condition">
|
|
253
|
+
<div motionone [animate]="..." [exit]="...">Content</div>
|
|
327
254
|
</div>
|
|
328
|
-
```
|
|
329
255
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
[offset]="'-100px'"
|
|
338
|
-
>
|
|
339
|
-
Animates when scrolled into view
|
|
256
|
+
<!-- With @for -->
|
|
257
|
+
<div *motionPresence="items.length > 0">
|
|
258
|
+
@for (item of items; track item.id) {
|
|
259
|
+
<div motionone [animate]="..." [exit]="...">
|
|
260
|
+
{{ item.name }}
|
|
261
|
+
</div>
|
|
262
|
+
}
|
|
340
263
|
</div>
|
|
341
264
|
```
|
|
342
265
|
|
|
343
|
-
|
|
266
|
+
### Coming from Framer Motion (React)
|
|
344
267
|
|
|
345
|
-
|
|
346
|
-
|
|
268
|
+
| Framer Motion (React) | ngx-motion (Angular) |
|
|
269
|
+
|----------------------|---------------------|
|
|
270
|
+
| `<motion.div>` | `<div motionone>` |
|
|
271
|
+
| `initial` / `animate` / `exit` props | `[initial]` / `[animate]` / `[exit]` inputs |
|
|
272
|
+
| `whileHover` / `whileTap` / `whileFocus` | `[whileHover]` / `[whileTap]` / `[whileFocus]` |
|
|
273
|
+
| `whileInView`, `viewport={{ once: true }}` | `[whileInView]`, `runInView="once"` |
|
|
274
|
+
| `variants` + `staggerChildren` | `[variants]` + `[transition]="{ staggerChildren }"` |
|
|
275
|
+
| `transition={{ type: 'spring' }}` | `[transition]="{ type: 'spring' }"` |
|
|
276
|
+
| `<AnimatePresence>` | `*motionIf` or `*motionPresence` |
|
|
347
277
|
|
|
348
|
-
|
|
349
|
-
Structural directive for conditional rendering with enter/exit animations:
|
|
278
|
+
## Upgrading from 1.x
|
|
350
279
|
|
|
351
|
-
|
|
352
|
-
<div *motionIf="condition">
|
|
353
|
-
Content with enter/exit animations
|
|
354
|
-
</div>
|
|
355
|
-
```
|
|
280
|
+
2.0 fixes several behaviours, some of which change how existing animations look:
|
|
356
281
|
|
|
357
|
-
|
|
282
|
+
- **`staggerChildren` defaults to `0`** (was 1 second), matching Framer Motion. Set it explicitly if you relied on the old default.
|
|
283
|
+
- **Stagger delays are applied once.** 1.x applied each child's stagger delay twice, so staggered sequences now run twice as fast; double your `staggerChildren` value to keep the old timing.
|
|
284
|
+
- **Plain child elements are no longer animated with their parent.** 1.x animated every non-`motionone` child to the parent's target too, compounding transforms.
|
|
285
|
+
- **Parents only orchestrate their direct `motionone` children**; nested parents pass the animation down. `childMotionDirectives` is now an array of direct children.
|
|
286
|
+
- **Requires Angular 22+.** `@angular/router` is no longer a peer dependency.
|
|
358
287
|
|
|
359
|
-
|
|
360
|
-
- `'ease'` - Default CSS ease
|
|
361
|
-
- `'ease-in'` - CSS ease-in
|
|
362
|
-
- `'ease-out'` - CSS ease-out
|
|
363
|
-
- `'ease-in-out'` - CSS ease-in-out
|
|
364
|
-
- `'linear'` - Linear timing
|
|
288
|
+
## Development Setup
|
|
365
289
|
|
|
366
|
-
###
|
|
367
|
-
|
|
368
|
-
|
|
290
|
+
### Prerequisites
|
|
291
|
+
- Node.js 22.22+ or 24.15+ (required by Angular 22)
|
|
292
|
+
- Angular 22+ (for Angular 19, use `@hilux/ngx-motion@1`)
|
|
293
|
+
- `motion` 12, 13 or 14
|
|
294
|
+
|
|
295
|
+
### Running the Demo
|
|
296
|
+
```bash
|
|
297
|
+
# Install dependencies
|
|
298
|
+
npm install
|
|
299
|
+
|
|
300
|
+
# Start development server
|
|
301
|
+
npm start
|
|
302
|
+
|
|
303
|
+
# Build the library
|
|
304
|
+
npm run build:lib
|
|
305
|
+
|
|
306
|
+
# Test library build
|
|
307
|
+
npm run pack:lib
|
|
369
308
|
```
|
|
370
309
|
|
|
371
|
-
###
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
310
|
+
### Building for Production
|
|
311
|
+
```bash
|
|
312
|
+
# Build demo app
|
|
313
|
+
npm run build
|
|
314
|
+
|
|
315
|
+
# Build and publish library
|
|
316
|
+
npm run publish:lib
|
|
378
317
|
```
|
|
379
318
|
|
|
380
|
-
##
|
|
319
|
+
## API Reference
|
|
320
|
+
|
|
321
|
+
### Inputs
|
|
381
322
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
323
|
+
| Input | Type | Description |
|
|
324
|
+
|-------|------|-------------|
|
|
325
|
+
| `initial` | `VariantWithTransition \| string` | Initial animation state |
|
|
326
|
+
| `animate` | `VariantWithTransition \| string` | Target animation state |
|
|
327
|
+
| `exit` | `VariantWithTransition \| string` | Exit animation state |
|
|
328
|
+
| `transition` | `TransitionOptions \| Record<string, TransitionOptions>` | Animation transition configuration |
|
|
329
|
+
| `variants` | `Record<string, VariantWithTransition>` | Named animation variants |
|
|
330
|
+
| `whileHover` | `VariantWithTransition` | Animation while hovering |
|
|
331
|
+
| `whileTap` | `VariantWithTransition` | Animation while pressing |
|
|
332
|
+
| `whileFocus` | `VariantWithTransition` | Animation while focused |
|
|
333
|
+
| `whileInView` | `VariantWithTransition` | Animation while the element is in the viewport |
|
|
334
|
+
| `runInView` | `'once' \| 'always' \| 'never'` | Play `animate` when scrolled into view: once, or reset and replay every time |
|
|
335
|
+
| `staggerChildren` | `number` | Seconds between direct `motionone` children (default `0`) |
|
|
336
|
+
| `delayChildren` | `number` | Seconds before the first child starts |
|
|
337
|
+
| `timeline` | `TimelineStep[]` | Sequential animation timeline |
|
|
387
338
|
|
|
388
|
-
|
|
339
|
+
### Outputs
|
|
340
|
+
|
|
341
|
+
| Output | Description |
|
|
342
|
+
|--------|-------------|
|
|
343
|
+
| `animationComplete` | Emits when an animation finishes |
|
|
344
|
+
|
|
345
|
+
### Transition Options
|
|
389
346
|
|
|
390
|
-
Supports smooth color transitions:
|
|
391
347
|
```typescript
|
|
392
|
-
{
|
|
393
|
-
|
|
394
|
-
|
|
348
|
+
interface TransitionOptions {
|
|
349
|
+
duration?: number;
|
|
350
|
+
delay?: number;
|
|
351
|
+
ease?: string | number[] | { type: 'spring'; stiffness?: number; damping?: number };
|
|
352
|
+
type?: 'spring' | 'tween';
|
|
353
|
+
stiffness?: number;
|
|
354
|
+
damping?: number;
|
|
355
|
+
repeat?: number | boolean;
|
|
356
|
+
repeatType?: 'loop' | 'mirror' | 'reverse' | 'forwards' | 'pingPong';
|
|
357
|
+
repeatDelay?: number;
|
|
358
|
+
staggerChildren?: number;
|
|
359
|
+
staggerDirection?: number;
|
|
360
|
+
when?: 'beforeChildren' | 'afterChildren' | 'together';
|
|
361
|
+
delayChildren?: number;
|
|
395
362
|
}
|
|
396
363
|
```
|
|
397
364
|
|
|
398
|
-
|
|
365
|
+
### Available Easing Functions
|
|
366
|
+
- `'ease'` - Default CSS ease
|
|
367
|
+
- `'ease-in'` - CSS ease-in
|
|
368
|
+
- `'ease-out'` - CSS ease-out
|
|
369
|
+
- `'ease-in-out'` - CSS ease-in-out
|
|
370
|
+
- `[0.4, 0, 0.2, 1]` - Custom cubic bezier
|
|
371
|
+
- `{ type: 'spring', stiffness: 400, damping: 17 }` - Spring physics
|
|
372
|
+
|
|
373
|
+
## FAQ
|
|
374
|
+
|
|
375
|
+
### Is this Framer Motion for Angular?
|
|
376
|
+
It's the closest equivalent. Framer Motion (now Motion for React) is React-only. ngx-motion offers the same model in Angular templates: `initial`/`animate`/`exit` states, gesture states, variants, stagger, springs and presence. It uses the same Motion engine underneath.
|
|
377
|
+
|
|
378
|
+
### Which Angular versions are supported?
|
|
379
|
+
2.x supports Angular 22 and later. 1.x supports Angular 19.
|
|
399
380
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
-
|
|
403
|
-
-
|
|
381
|
+
### How is it different from Angular's built-in animations?
|
|
382
|
+
Angular's `animate.enter` / `animate.leave` (and the older `@angular/animations`) are built around CSS classes and state-transition triggers. ngx-motion adds things those don't cover:
|
|
383
|
+
- physics springs
|
|
384
|
+
- hover, tap and focus gestures
|
|
385
|
+
- staggered children
|
|
386
|
+
- scroll-triggered animation
|
|
387
|
+
- interruptible animations that start from the element's current value
|
|
404
388
|
|
|
405
|
-
|
|
389
|
+
### Does it work with server-side rendering?
|
|
390
|
+
Yes. Animation code only runs in the browser, so server rendering outputs the elements without errors.
|
|
406
391
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
392
|
+
### Does it trigger change detection on every frame?
|
|
393
|
+
No. Animations, timers and gesture listeners run outside Angular's zone.
|
|
394
|
+
|
|
395
|
+
### How do I animate a list as items are added and removed?
|
|
396
|
+
Put `motionone` on each `@for` item for enter animations. Wrap items in `*motionPresence` (or `*motionIf`) to animate them out before they are removed. See the [Dynamic List example](https://rikisommers.github.io/angular-motion-poc/examples/dynamic-list).
|
|
397
|
+
|
|
398
|
+
### How do I animate on scroll?
|
|
399
|
+
Add `runInView="once"` to play `animate` the first time the element scrolls into view. Use `runInView="always"` to reset it when it leaves and replay it when it returns. See the [Run In View example](https://rikisommers.github.io/angular-motion-poc/examples/in-view).
|
|
400
|
+
|
|
401
|
+
## Project Structure
|
|
402
|
+
|
|
403
|
+
```
|
|
404
|
+
angular-motion-poc/
|
|
405
|
+
├── projects/ngx-motion/ # Library source (published as @hilux/ngx-motion)
|
|
406
|
+
│ ├── src/lib/directives/ # motionone, *motionIf, *motionPresence
|
|
407
|
+
│ ├── src/lib/services/ # Animation services
|
|
408
|
+
│ └── src/public-api.ts # Library exports
|
|
409
|
+
├── src/app/ # Demo and docs site
|
|
410
|
+
│ ├── examples/ # One component per example
|
|
411
|
+
│ ├── pages/ # Docs and examples pages
|
|
412
|
+
│ └── components/ # Demo UI components
|
|
413
|
+
└── dist/ngx-motion/ # Built library output
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
## Contributing
|
|
417
|
+
|
|
418
|
+
1. Fork the repository
|
|
419
|
+
2. Create a feature branch
|
|
420
|
+
3. Make your changes
|
|
421
|
+
4. Add tests if applicable
|
|
422
|
+
5. Submit a pull request
|
|
411
423
|
|
|
412
424
|
## License
|
|
413
425
|
|
|
414
|
-
MIT
|
|
426
|
+
MIT License - see LICENSE file for details
|
|
427
|
+
|
|
428
|
+
## Links
|
|
429
|
+
|
|
430
|
+
- [Live demo and examples](https://rikisommers.github.io/angular-motion-poc/examples)
|
|
431
|
+
- [Documentation](https://rikisommers.github.io/angular-motion-poc/docs)
|
|
432
|
+
- [npm package](https://www.npmjs.com/package/@hilux/ngx-motion)
|
|
433
|
+
- [Motion documentation](https://motion.dev/)
|
|
434
|
+
- [Angular documentation](https://angular.dev/)
|