@hilux/ngx-motion 1.1.0 → 1.1.2
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 +214 -268
- package/ng-package.json +7 -0
- package/package.json +21 -14
- package/src/lib/components/motion-one-presence.component.ts +116 -0
- package/src/lib/constants/motion-defaults.constants.ts +41 -0
- package/src/lib/directives/motion-animate.directive.ts +55 -0
- package/src/lib/directives/motion-if.directive.ts +138 -0
- package/src/lib/directives/motion-one.directive.backup.ts +1591 -0
- package/src/lib/directives/motion-one.directive.ts +1154 -0
- package/src/lib/directives/motion-presence.directive.ts +145 -0
- package/src/lib/services/motion-animation-options.service.ts +142 -0
- package/src/lib/services/motion-animation.service.ts +86 -0
- package/src/lib/services/motion-browser-safe.ts +64 -0
- package/src/lib/services/motion-gesture.service.ts +141 -0
- package/src/lib/services/motion-inview.service.ts +91 -0
- package/src/lib/services/motion-one.service.ts +424 -0
- package/src/lib/services/motion-stagger.service.ts +70 -0
- package/src/lib/services/motion-timeline.service.ts +182 -0
- package/src/lib/types/motion-animation.types.ts +46 -0
- package/src/lib/utils/color.utils.ts +54 -0
- package/src/lib/utils/easing.utils.ts +77 -0
- package/src/lib/utils/index.ts +7 -0
- package/src/lib/utils/style-extraction.utils.ts +70 -0
- package/src/lib/utils/timing.utils.ts +61 -0
- package/src/lib/utils/transform.utils.ts +112 -0
- package/src/lib/utils/variant.utils.ts +55 -0
- package/src/public-api.ts +21 -0
- package/tsconfig.lib.json +17 -0
- package/tsconfig.lib.prod.json +11 -0
- package/tsconfig.spec.json +15 -0
- package/fesm2022/hilux-ngx-motion.mjs +0 -1562
- package/fesm2022/hilux-ngx-motion.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/lib/directives/motion-if.directive.d.ts +0 -14
- package/lib/directives/motion-one.directive.d.ts +0 -142
- package/lib/services/motion-animation.service.d.ts +0 -20
- package/lib/services/motion-browser-safe.d.ts +0 -10
- package/lib/services/motion-one.service.d.ts +0 -87
- package/public-api.d.ts +0 -6
package/README.md
CHANGED
|
@@ -1,14 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Angular Motion Demo & Library
|
|
2
2
|
|
|
3
|
-
Angular directive for Motion One animations with Framer Motion-like API.
|
|
3
|
+
This project demonstrates **@hilux/ngx-motion**, a powerful Angular directive library for Motion One animations with a Framer Motion-like API.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## [ Demo →](https://rikisommers.github.io/angular-motion-poc)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
### Motion One Integration
|
|
11
|
+
- Built on top of the performant Motion One animation library
|
|
12
|
+
- Familiar Framer Motion API for React developers transitioning to Angular
|
|
13
|
+
- Full TypeScript support with type safety
|
|
14
|
+
- Server-Side Rendering (SSR) compatible with Angular Universal
|
|
15
|
+
|
|
16
|
+
### Animation Capabilities
|
|
17
|
+
- **Basic Animations**: `initial`, `animate`, and `exit` states
|
|
18
|
+
- **Gesture Animations**: `whileHover`, `whileTap`, `whileFocus`
|
|
19
|
+
- **Stagger Animations**: Built-in support for staggered children animations
|
|
20
|
+
- **Timeline Support**: Create complex sequential animations with precise timing
|
|
21
|
+
- **Conditional Rendering**: `motionIf` directive for animated presence
|
|
22
|
+
- **Variants**: Named animation states for clean, reusable animations
|
|
23
|
+
- **Spring Physics**: Native spring animations with customizable stiffness and damping
|
|
24
|
+
|
|
25
|
+
### Advanced Features
|
|
26
|
+
- **Transform Shortcuts**: Use `x`, `y`, `scale`, `rotate` instead of transform strings
|
|
27
|
+
- **Color Animation**: Smooth color transitions with automatic color format handling
|
|
28
|
+
- **Keyframe Arrays**: Support for complex keyframe-based animations
|
|
29
|
+
- **Per-Property Transitions**: Different timing for each animated property
|
|
30
|
+
- **Responsive Design**: Animation that work across all screen sizes
|
|
31
|
+
- **Performance Optimized**: Leverages Motion One's efficient animation engine
|
|
32
|
+
|
|
33
|
+
## Library Installation
|
|
6
34
|
|
|
7
35
|
```bash
|
|
8
36
|
npm install @hilux/ngx-motion motion
|
|
9
37
|
```
|
|
10
38
|
|
|
11
|
-
## Usage
|
|
39
|
+
## Basic Usage
|
|
12
40
|
|
|
13
41
|
Import the directive in your component:
|
|
14
42
|
|
|
@@ -24,7 +52,7 @@ import { MotionOneDirective } from '@hilux/ngx-motion';
|
|
|
24
52
|
motionone
|
|
25
53
|
[initial]="{ opacity: 0, y: 50 }"
|
|
26
54
|
[animate]="{ opacity: 1, y: 0 }"
|
|
27
|
-
[transition]="{ duration: 0.5 }"
|
|
55
|
+
[transition]="{ duration: 0.5, ease: 'easeOut' }"
|
|
28
56
|
>
|
|
29
57
|
Animated content
|
|
30
58
|
</div>
|
|
@@ -33,126 +61,9 @@ import { MotionOneDirective } from '@hilux/ngx-motion';
|
|
|
33
61
|
export class ExampleComponent {}
|
|
34
62
|
```
|
|
35
63
|
|
|
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 |
|
|
64
|
+
## Animation Examples
|
|
94
65
|
|
|
95
|
-
|
|
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
|
-
```
|
|
154
|
-
|
|
155
|
-
### Hover Interactions
|
|
66
|
+
### Hover Animations
|
|
156
67
|
```html
|
|
157
68
|
<button
|
|
158
69
|
motionone
|
|
@@ -161,7 +72,7 @@ interface TimelineStep {
|
|
|
161
72
|
[whileTap]="{ scale: 0.95 }"
|
|
162
73
|
[transition]="{ type: 'spring', stiffness: 400, damping: 17 }"
|
|
163
74
|
>
|
|
164
|
-
|
|
75
|
+
Hover me!
|
|
165
76
|
</button>
|
|
166
77
|
```
|
|
167
78
|
|
|
@@ -171,8 +82,7 @@ interface TimelineStep {
|
|
|
171
82
|
motionone
|
|
172
83
|
[initial]="{ opacity: 0 }"
|
|
173
84
|
[animate]="{ opacity: 1 }"
|
|
174
|
-
[
|
|
175
|
-
[delayChildren]="0.3"
|
|
85
|
+
[transition]="{ staggerChildren: 0.1, delayChildren: 0.3 }"
|
|
176
86
|
>
|
|
177
87
|
<div motionone [initial]="{ x: -50, opacity: 0 }" [animate]="{ x: 0, opacity: 1 }">Item 1</div>
|
|
178
88
|
<div motionone [initial]="{ x: -50, opacity: 0 }" [animate]="{ x: 0, opacity: 1 }">Item 2</div>
|
|
@@ -180,7 +90,7 @@ interface TimelineStep {
|
|
|
180
90
|
</div>
|
|
181
91
|
```
|
|
182
92
|
|
|
183
|
-
###
|
|
93
|
+
### Variants
|
|
184
94
|
```typescript
|
|
185
95
|
@Component({
|
|
186
96
|
template: `
|
|
@@ -201,30 +111,37 @@ export class VariantsExample {
|
|
|
201
111
|
visible: {
|
|
202
112
|
opacity: 1,
|
|
203
113
|
transition: {
|
|
204
|
-
staggerChildren: 0.2
|
|
205
|
-
delayChildren: 0.1
|
|
114
|
+
staggerChildren: 0.2
|
|
206
115
|
}
|
|
207
116
|
}
|
|
208
117
|
};
|
|
209
118
|
|
|
210
119
|
itemVariants = {
|
|
211
120
|
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
|
-
}
|
|
121
|
+
visible: { x: 0, opacity: 1 }
|
|
220
122
|
};
|
|
221
123
|
}
|
|
222
124
|
```
|
|
223
125
|
|
|
224
|
-
###
|
|
126
|
+
### Conditional Animation with motionIf
|
|
127
|
+
```html
|
|
128
|
+
<button (click)="isVisible = !isVisible">Toggle</button>
|
|
129
|
+
|
|
130
|
+
<div *motionIf="isVisible">
|
|
131
|
+
<div
|
|
132
|
+
motionone
|
|
133
|
+
[initial]="{ scale: 0, opacity: 0 }"
|
|
134
|
+
[animate]="{ scale: 1, opacity: 1 }"
|
|
135
|
+
[exit]="{ scale: 0, opacity: 0 }"
|
|
136
|
+
[transition]="{ duration: 0.3 }"
|
|
137
|
+
>
|
|
138
|
+
This will animate in and out!
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
```
|
|
225
142
|
|
|
226
|
-
Timeline animations allow you to orchestrate multiple properties with precise timing control. Each timeline step can have different durations, delays, and easing functions.
|
|
227
143
|
|
|
144
|
+
### Timeline Animations
|
|
228
145
|
```typescript
|
|
229
146
|
@Component({
|
|
230
147
|
template: `
|
|
@@ -232,183 +149,212 @@ Timeline animations allow you to orchestrate multiple properties with precise ti
|
|
|
232
149
|
motionone
|
|
233
150
|
[timeline]="complexTimeline"
|
|
234
151
|
[animate]="{ opacity: 1 }"
|
|
235
|
-
(animationComplete)="onAnimationComplete()"
|
|
236
152
|
>
|
|
237
153
|
Complex sequenced animation
|
|
238
154
|
</div>
|
|
239
155
|
`
|
|
240
156
|
})
|
|
241
157
|
export class TimelineExample {
|
|
242
|
-
complexTimeline
|
|
158
|
+
complexTimeline = [
|
|
243
159
|
{ prop: 'x', to: 100, duration: 1, atTime: 0 },
|
|
244
160
|
{ 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 }
|
|
161
|
+
{ prop: 'scale', to: 1.2, duration: 0.3, atTime: 1.2 }
|
|
247
162
|
];
|
|
248
|
-
|
|
249
|
-
onAnimationComplete() {
|
|
250
|
-
console.log('Timeline animation completed!');
|
|
251
|
-
}
|
|
252
163
|
}
|
|
253
164
|
```
|
|
254
165
|
|
|
255
|
-
|
|
166
|
+
## Angular Control Flow Integration
|
|
256
167
|
|
|
257
|
-
|
|
168
|
+
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
169
|
|
|
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>
|
|
170
|
+
### Using `*motionIf` Directive
|
|
171
|
+
|
|
172
|
+
The `*motionIf` structural directive wraps Angular's template logic and manages enter/exit animations:
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
@Component({
|
|
176
|
+
selector: 'app-example',
|
|
177
|
+
imports: [MotionOneDirective, MotionIfDirective],
|
|
178
|
+
template: `
|
|
179
|
+
<button (click)="show = !show">
|
|
180
|
+
{{ show ? 'Hide' : 'Show' }}
|
|
181
|
+
</button>
|
|
182
|
+
|
|
183
|
+
<div *motionIf="show">
|
|
184
|
+
<div
|
|
185
|
+
motionone
|
|
186
|
+
[initial]="{ x: -100, opacity: 0 }"
|
|
187
|
+
[animate]="{ x: 0, opacity: 1 }"
|
|
188
|
+
[exit]="{ x: 100, opacity: 0 }"
|
|
189
|
+
[transition]="{ duration: 0.4, ease: { type: 'spring', stiffness: 300 } }"
|
|
190
|
+
>
|
|
191
|
+
Slides in from left, slides out to right
|
|
192
|
+
</div>
|
|
193
|
+
</div>
|
|
194
|
+
`
|
|
195
|
+
})
|
|
196
|
+
export class ControlFlowExample {
|
|
197
|
+
show = true;
|
|
198
|
+
}
|
|
289
199
|
```
|
|
290
200
|
|
|
291
|
-
**
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
201
|
+
**How it works:**
|
|
202
|
+
- `*motionIf` uses `ViewContainerRef` to control when views are created/destroyed
|
|
203
|
+
- When condition becomes `true`, it creates the view and triggers enter animation
|
|
204
|
+
- When condition becomes `false`, it triggers exit animation then removes from DOM
|
|
205
|
+
- Automatically calculates the longest animation duration to ensure smooth exit
|
|
206
|
+
- Supports multiple animated elements in a single template
|
|
295
207
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
|
208
|
+
### Using `*motionPresence` Directive
|
|
209
|
+
|
|
210
|
+
Alternative structural directive with identical functionality, named for developers familiar with Framer Motion's `<AnimatePresence>`:
|
|
302
211
|
|
|
303
|
-
### Conditional Rendering with motionIf
|
|
304
212
|
```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!
|
|
213
|
+
<div *motionPresence="isVisible">
|
|
214
|
+
<div motionone
|
|
215
|
+
[initial]="{ opacity: 0, scale: 0.8 }"
|
|
216
|
+
[animate]="{ opacity: 1, scale: 1 }"
|
|
217
|
+
[exit]="{ opacity: 0, scale: 0.8 }">
|
|
218
|
+
Content
|
|
314
219
|
</div>
|
|
315
220
|
</div>
|
|
316
221
|
```
|
|
317
222
|
|
|
318
|
-
###
|
|
223
|
+
### Using with Angular's New Control Flow
|
|
224
|
+
|
|
225
|
+
The directives work seamlessly with Angular's new control flow syntax:
|
|
226
|
+
|
|
319
227
|
```html
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
[
|
|
323
|
-
[animate]="{ y: 0 }"
|
|
324
|
-
[easing]="{ type: 'spring', stiffness: 300, damping: 20 }"
|
|
325
|
-
>
|
|
326
|
-
Bouncy spring animation
|
|
228
|
+
<!-- With @if -->
|
|
229
|
+
<div *motionIf="condition">
|
|
230
|
+
<div motionone [animate]="..." [exit]="...">Content</div>
|
|
327
231
|
</div>
|
|
328
|
-
```
|
|
329
232
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
[offset]="'-100px'"
|
|
338
|
-
>
|
|
339
|
-
Animates when scrolled into view
|
|
233
|
+
<!-- With @for -->
|
|
234
|
+
<div *motionPresence="items.length > 0">
|
|
235
|
+
@for (item of items; track item.id) {
|
|
236
|
+
<div motionone [animate]="..." [exit]="...">
|
|
237
|
+
{{ item.name }}
|
|
238
|
+
</div>
|
|
239
|
+
}
|
|
340
240
|
</div>
|
|
341
241
|
```
|
|
342
242
|
|
|
343
|
-
|
|
243
|
+
### Comparison with Framer Motion
|
|
344
244
|
|
|
345
|
-
|
|
346
|
-
|
|
245
|
+
| Framer Motion (React) | ngx-motion (Angular) |
|
|
246
|
+
|----------------------|---------------------|
|
|
247
|
+
| `<AnimatePresence>` | `*motionIf` or `*motionPresence` |
|
|
248
|
+
| `initial` prop | `[initial]` input |
|
|
249
|
+
| `animate` prop | `[animate]` input |
|
|
250
|
+
| `exit` prop | `[exit]` input |
|
|
251
|
+
| `<motion.div>` | `<div motionone>` |
|
|
347
252
|
|
|
348
|
-
|
|
349
|
-
Structural directive for conditional rendering with enter/exit animations:
|
|
253
|
+
## Development Setup
|
|
350
254
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
```
|
|
255
|
+
### Prerequisites
|
|
256
|
+
- Node.js 18+
|
|
257
|
+
- Angular 19+
|
|
258
|
+
- Motion One library
|
|
356
259
|
|
|
357
|
-
|
|
260
|
+
### Running the Demo
|
|
261
|
+
```bash
|
|
262
|
+
# Install dependencies
|
|
263
|
+
yarn install
|
|
358
264
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
- `'ease-in'` - CSS ease-in
|
|
362
|
-
- `'ease-out'` - CSS ease-out
|
|
363
|
-
- `'ease-in-out'` - CSS ease-in-out
|
|
364
|
-
- `'linear'` - Linear timing
|
|
265
|
+
# Start development server
|
|
266
|
+
yarn start
|
|
365
267
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
268
|
+
# Build the library
|
|
269
|
+
yarn build:lib
|
|
270
|
+
|
|
271
|
+
# Test library build
|
|
272
|
+
yarn pack:lib
|
|
369
273
|
```
|
|
370
274
|
|
|
371
|
-
###
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
275
|
+
### Building for Production
|
|
276
|
+
```bash
|
|
277
|
+
# Build demo app
|
|
278
|
+
yarn build
|
|
279
|
+
|
|
280
|
+
# Build and publish library
|
|
281
|
+
yarn publish:lib
|
|
378
282
|
```
|
|
379
283
|
|
|
380
|
-
##
|
|
284
|
+
## API Reference
|
|
381
285
|
|
|
382
|
-
|
|
383
|
-
- `x`, `y` - Translate in pixels
|
|
384
|
-
- `scale`, `scaleX`, `scaleY` - Scale transforms
|
|
385
|
-
- `rotate` - Rotation in degrees
|
|
386
|
-
- `transform` - Raw transform string (for advanced use)
|
|
286
|
+
### Inputs
|
|
387
287
|
|
|
388
|
-
|
|
288
|
+
| Input | Type | Description |
|
|
289
|
+
|-------|------|-------------|
|
|
290
|
+
| `initial` | `VariantWithTransition \| string` | Initial animation state |
|
|
291
|
+
| `animate` | `VariantWithTransition \| string` | Target animation state |
|
|
292
|
+
| `exit` | `VariantWithTransition \| string` | Exit animation state |
|
|
293
|
+
| `transition` | `TransitionOptions \| Record<string, TransitionOptions>` | Animation transition configuration |
|
|
294
|
+
| `variants` | `Record<string, VariantWithTransition>` | Named animation variants |
|
|
295
|
+
| `whileHover` | `VariantWithTransition` | Animation while hovering |
|
|
296
|
+
| `whileTap` | `VariantWithTransition` | Animation while pressing |
|
|
297
|
+
| `whileFocus` | `VariantWithTransition` | Animation while focused |
|
|
298
|
+
| `timeline` | `TimelineStep[]` | Sequential animation timeline |
|
|
299
|
+
|
|
300
|
+
### Transition Options
|
|
389
301
|
|
|
390
|
-
Supports smooth color transitions:
|
|
391
302
|
```typescript
|
|
392
|
-
{
|
|
393
|
-
|
|
394
|
-
|
|
303
|
+
interface TransitionOptions {
|
|
304
|
+
duration?: number;
|
|
305
|
+
delay?: number;
|
|
306
|
+
ease?: string | number[] | { type: 'spring'; stiffness?: number; damping?: number };
|
|
307
|
+
repeat?: number | boolean;
|
|
308
|
+
repeatType?: 'loop' | 'mirror' | 'reverse' | 'forwards' | 'pingPong';
|
|
309
|
+
repeatDelay?: number;
|
|
310
|
+
staggerChildren?: number;
|
|
311
|
+
staggerDirection?: number;
|
|
312
|
+
when?: 'beforeChildren' | 'afterChildren' | 'together';
|
|
313
|
+
delayChildren?: number;
|
|
395
314
|
}
|
|
396
315
|
```
|
|
397
316
|
|
|
398
|
-
|
|
317
|
+
### Available Easing Functions
|
|
318
|
+
- `'ease'` - Default CSS ease
|
|
319
|
+
- `'ease-in'` - CSS ease-in
|
|
320
|
+
- `'ease-out'` - CSS ease-out
|
|
321
|
+
- `'ease-in-out'` - CSS ease-in-out
|
|
322
|
+
- `[0.4, 0, 0.2, 1]` - Custom cubic bezier
|
|
323
|
+
- `{ type: 'spring', stiffness: 400, damping: 17 }` - Spring physics
|
|
324
|
+
|
|
325
|
+
## Project Structure
|
|
399
326
|
|
|
400
|
-
|
|
401
|
-
-
|
|
402
|
-
-
|
|
403
|
-
|
|
327
|
+
```
|
|
328
|
+
ng-motion-demo/
|
|
329
|
+
├── projects/ngx-motion/ # Library source code
|
|
330
|
+
│ ├── src/lib/directives/ # Motion directives
|
|
331
|
+
│ ├── src/lib/services/ # Animation services
|
|
332
|
+
│ └── src/public-api.ts # Library exports
|
|
333
|
+
├── src/app/ # Demo application
|
|
334
|
+
│ ├── components/ # Demo components
|
|
335
|
+
│ ├── pages/ # Demo pages
|
|
336
|
+
│ └── directives/ # Original directive sources
|
|
337
|
+
└── dist/ngx-motion/ # Built library output
|
|
338
|
+
```
|
|
404
339
|
|
|
405
|
-
##
|
|
340
|
+
## Contributing
|
|
406
341
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
342
|
+
1. Fork the repository
|
|
343
|
+
2. Create a feature branch
|
|
344
|
+
3. Make your changes
|
|
345
|
+
4. Add tests if applicable
|
|
346
|
+
5. Submit a pull request
|
|
411
347
|
|
|
412
348
|
## License
|
|
413
349
|
|
|
414
|
-
MIT
|
|
350
|
+
MIT License - see LICENSE file for details
|
|
351
|
+
|
|
352
|
+
## Links
|
|
353
|
+
|
|
354
|
+
- [Motion One Documentation](https://motion.dev/)
|
|
355
|
+
- [Angular Documentation](https://angular.dev/)
|
|
356
|
+
- [Framer Motion API Reference](https://www.framer.com/motion/)
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
Built with Angular and Motion One
|
package/ng-package.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hilux/ngx-motion",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Angular directive for Motion One animations",
|
|
5
5
|
"author": "Hilux",
|
|
6
6
|
"keywords": [
|
|
@@ -30,16 +30,23 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"tslib": "^2.3.0"
|
|
32
32
|
},
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@angular/common": "^19.0.0",
|
|
35
|
+
"@angular/core": "^19.0.0",
|
|
36
|
+
"@angular/router": "^19.0.0",
|
|
37
|
+
"motion": "^12.0.0",
|
|
38
|
+
"rxjs": "~7.8.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"ng": "ng",
|
|
42
|
+
"start": "ng serve",
|
|
43
|
+
"build": "ng build",
|
|
44
|
+
"build:lib": "ng build ngx-motion",
|
|
45
|
+
"watch": "ng build --watch --configuration development",
|
|
46
|
+
"test": "ng test",
|
|
47
|
+
"serve:ssr:ng-motion-poc": "node dist/ng-motion-poc/server/server.mjs",
|
|
48
|
+
"publish:lib": "ng build && cd dist/ngx-motion && npm publish",
|
|
49
|
+
"pack:lib": "ng build && cd dist/ngx-motion && npm pack"
|
|
50
|
+
},
|
|
51
|
+
"sideEffects": false
|
|
52
|
+
}
|