@hilux/ngx-motion 1.1.2 → 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 +131 -57
- 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,41 +1,64 @@
|
|
|
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.
|
|
6
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)**
|
|
7
10
|
|
|
8
|
-
##
|
|
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
|
|
11
|
+
## Quick start
|
|
34
12
|
|
|
35
13
|
```bash
|
|
36
14
|
npm install @hilux/ngx-motion motion
|
|
37
15
|
```
|
|
38
16
|
|
|
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
|
+
|
|
39
62
|
## Basic Usage
|
|
40
63
|
|
|
41
64
|
Import the directive in your component:
|
|
@@ -240,45 +263,57 @@ The directives work seamlessly with Angular's new control flow syntax:
|
|
|
240
263
|
</div>
|
|
241
264
|
```
|
|
242
265
|
|
|
243
|
-
###
|
|
266
|
+
### Coming from Framer Motion (React)
|
|
244
267
|
|
|
245
268
|
| Framer Motion (React) | ngx-motion (Angular) |
|
|
246
269
|
|----------------------|---------------------|
|
|
247
|
-
| `<AnimatePresence>` | `*motionIf` or `*motionPresence` |
|
|
248
|
-
| `initial` prop | `[initial]` input |
|
|
249
|
-
| `animate` prop | `[animate]` input |
|
|
250
|
-
| `exit` prop | `[exit]` input |
|
|
251
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` |
|
|
277
|
+
|
|
278
|
+
## Upgrading from 1.x
|
|
279
|
+
|
|
280
|
+
2.0 fixes several behaviours, some of which change how existing animations look:
|
|
281
|
+
|
|
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.
|
|
252
287
|
|
|
253
288
|
## Development Setup
|
|
254
289
|
|
|
255
290
|
### Prerequisites
|
|
256
|
-
- Node.js
|
|
257
|
-
- Angular 19
|
|
258
|
-
-
|
|
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
|
|
259
294
|
|
|
260
295
|
### Running the Demo
|
|
261
296
|
```bash
|
|
262
297
|
# Install dependencies
|
|
263
|
-
|
|
298
|
+
npm install
|
|
264
299
|
|
|
265
300
|
# Start development server
|
|
266
|
-
|
|
301
|
+
npm start
|
|
267
302
|
|
|
268
303
|
# Build the library
|
|
269
|
-
|
|
304
|
+
npm run build:lib
|
|
270
305
|
|
|
271
306
|
# Test library build
|
|
272
|
-
|
|
307
|
+
npm run pack:lib
|
|
273
308
|
```
|
|
274
309
|
|
|
275
310
|
### Building for Production
|
|
276
311
|
```bash
|
|
277
312
|
# Build demo app
|
|
278
|
-
|
|
313
|
+
npm run build
|
|
279
314
|
|
|
280
315
|
# Build and publish library
|
|
281
|
-
|
|
316
|
+
npm run publish:lib
|
|
282
317
|
```
|
|
283
318
|
|
|
284
319
|
## API Reference
|
|
@@ -295,8 +330,18 @@ yarn publish:lib
|
|
|
295
330
|
| `whileHover` | `VariantWithTransition` | Animation while hovering |
|
|
296
331
|
| `whileTap` | `VariantWithTransition` | Animation while pressing |
|
|
297
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 |
|
|
298
337
|
| `timeline` | `TimelineStep[]` | Sequential animation timeline |
|
|
299
338
|
|
|
339
|
+
### Outputs
|
|
340
|
+
|
|
341
|
+
| Output | Description |
|
|
342
|
+
|--------|-------------|
|
|
343
|
+
| `animationComplete` | Emits when an animation finishes |
|
|
344
|
+
|
|
300
345
|
### Transition Options
|
|
301
346
|
|
|
302
347
|
```typescript
|
|
@@ -304,6 +349,9 @@ interface TransitionOptions {
|
|
|
304
349
|
duration?: number;
|
|
305
350
|
delay?: number;
|
|
306
351
|
ease?: string | number[] | { type: 'spring'; stiffness?: number; damping?: number };
|
|
352
|
+
type?: 'spring' | 'tween';
|
|
353
|
+
stiffness?: number;
|
|
354
|
+
damping?: number;
|
|
307
355
|
repeat?: number | boolean;
|
|
308
356
|
repeatType?: 'loop' | 'mirror' | 'reverse' | 'forwards' | 'pingPong';
|
|
309
357
|
repeatDelay?: number;
|
|
@@ -322,18 +370,46 @@ interface TransitionOptions {
|
|
|
322
370
|
- `[0.4, 0, 0.2, 1]` - Custom cubic bezier
|
|
323
371
|
- `{ type: 'spring', stiffness: 400, damping: 17 }` - Spring physics
|
|
324
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.
|
|
380
|
+
|
|
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
|
|
388
|
+
|
|
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.
|
|
391
|
+
|
|
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
|
+
|
|
325
401
|
## Project Structure
|
|
326
402
|
|
|
327
403
|
```
|
|
328
|
-
|
|
329
|
-
├── projects/ngx-motion/ # Library source
|
|
330
|
-
│ ├── src/lib/directives/ #
|
|
404
|
+
angular-motion-poc/
|
|
405
|
+
├── projects/ngx-motion/ # Library source (published as @hilux/ngx-motion)
|
|
406
|
+
│ ├── src/lib/directives/ # motionone, *motionIf, *motionPresence
|
|
331
407
|
│ ├── src/lib/services/ # Animation services
|
|
332
408
|
│ └── src/public-api.ts # Library exports
|
|
333
|
-
├── src/app/ # Demo
|
|
334
|
-
│ ├──
|
|
335
|
-
│ ├── pages/ #
|
|
336
|
-
│ └──
|
|
409
|
+
├── src/app/ # Demo and docs site
|
|
410
|
+
│ ├── examples/ # One component per example
|
|
411
|
+
│ ├── pages/ # Docs and examples pages
|
|
412
|
+
│ └── components/ # Demo UI components
|
|
337
413
|
└── dist/ngx-motion/ # Built library output
|
|
338
414
|
```
|
|
339
415
|
|
|
@@ -351,10 +427,8 @@ MIT License - see LICENSE file for details
|
|
|
351
427
|
|
|
352
428
|
## Links
|
|
353
429
|
|
|
354
|
-
- [
|
|
355
|
-
- [
|
|
356
|
-
- [
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
Built with Angular and Motion One
|
|
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/)
|