@hilux/ngx-motion 1.1.2 → 2.0.1
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 +137 -57
- package/fesm2022/hilux-ngx-motion.mjs +2020 -0
- package/fesm2022/hilux-ngx-motion.mjs.map +1 -0
- package/package.json +35 -31
- package/types/hilux-ngx-motion.d.ts +782 -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,63 @@ 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
|
+
## Changelog
|
|
279
|
+
|
|
280
|
+
**2.0.1**
|
|
281
|
+
- `delayChildren` set inside `[transition]` is now honoured, as in Framer Motion. Before, only the `[delayChildren]` input was read.
|
|
282
|
+
- A `runInView` parent now orchestrates its children fully when it scrolls into view: stagger slots, `delayChildren`, each child's own `delay`, and nested children. Before, its direct children animated flat, grandchildren never played, and an in-view child inside it never played.
|
|
283
|
+
|
|
284
|
+
## Upgrading from 1.x
|
|
285
|
+
|
|
286
|
+
2.0 fixes several behaviours, some of which change how existing animations look:
|
|
287
|
+
|
|
288
|
+
- **`staggerChildren` defaults to `0`** (was 1 second), matching Framer Motion. Set it explicitly if you relied on the old default.
|
|
289
|
+
- **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.
|
|
290
|
+
- **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.
|
|
291
|
+
- **Parents only orchestrate their direct `motionone` children**; nested parents pass the animation down. `childMotionDirectives` is now an array of direct children.
|
|
292
|
+
- **Requires Angular 22+.** `@angular/router` is no longer a peer dependency.
|
|
252
293
|
|
|
253
294
|
## Development Setup
|
|
254
295
|
|
|
255
296
|
### Prerequisites
|
|
256
|
-
- Node.js
|
|
257
|
-
- Angular 19
|
|
258
|
-
-
|
|
297
|
+
- Node.js 22.22+ or 24.15+ (required by Angular 22)
|
|
298
|
+
- Angular 22+ (for Angular 19, use `@hilux/ngx-motion@1`)
|
|
299
|
+
- `motion` 12, 13 or 14
|
|
259
300
|
|
|
260
301
|
### Running the Demo
|
|
261
302
|
```bash
|
|
262
303
|
# Install dependencies
|
|
263
|
-
|
|
304
|
+
npm install
|
|
264
305
|
|
|
265
306
|
# Start development server
|
|
266
|
-
|
|
307
|
+
npm start
|
|
267
308
|
|
|
268
309
|
# Build the library
|
|
269
|
-
|
|
310
|
+
npm run build:lib
|
|
270
311
|
|
|
271
312
|
# Test library build
|
|
272
|
-
|
|
313
|
+
npm run pack:lib
|
|
273
314
|
```
|
|
274
315
|
|
|
275
316
|
### Building for Production
|
|
276
317
|
```bash
|
|
277
318
|
# Build demo app
|
|
278
|
-
|
|
319
|
+
npm run build
|
|
279
320
|
|
|
280
321
|
# Build and publish library
|
|
281
|
-
|
|
322
|
+
npm run publish:lib
|
|
282
323
|
```
|
|
283
324
|
|
|
284
325
|
## API Reference
|
|
@@ -295,8 +336,18 @@ yarn publish:lib
|
|
|
295
336
|
| `whileHover` | `VariantWithTransition` | Animation while hovering |
|
|
296
337
|
| `whileTap` | `VariantWithTransition` | Animation while pressing |
|
|
297
338
|
| `whileFocus` | `VariantWithTransition` | Animation while focused |
|
|
339
|
+
| `whileInView` | `VariantWithTransition` | Animation while the element is in the viewport |
|
|
340
|
+
| `runInView` | `'once' \| 'always' \| 'never'` | Play `animate` when scrolled into view: once, or reset and replay every time |
|
|
341
|
+
| `staggerChildren` | `number` | Seconds between direct `motionone` children (default `0`) |
|
|
342
|
+
| `delayChildren` | `number` | Seconds before the first child starts |
|
|
298
343
|
| `timeline` | `TimelineStep[]` | Sequential animation timeline |
|
|
299
344
|
|
|
345
|
+
### Outputs
|
|
346
|
+
|
|
347
|
+
| Output | Description |
|
|
348
|
+
|--------|-------------|
|
|
349
|
+
| `animationComplete` | Emits when an animation finishes |
|
|
350
|
+
|
|
300
351
|
### Transition Options
|
|
301
352
|
|
|
302
353
|
```typescript
|
|
@@ -304,6 +355,9 @@ interface TransitionOptions {
|
|
|
304
355
|
duration?: number;
|
|
305
356
|
delay?: number;
|
|
306
357
|
ease?: string | number[] | { type: 'spring'; stiffness?: number; damping?: number };
|
|
358
|
+
type?: 'spring' | 'tween';
|
|
359
|
+
stiffness?: number;
|
|
360
|
+
damping?: number;
|
|
307
361
|
repeat?: number | boolean;
|
|
308
362
|
repeatType?: 'loop' | 'mirror' | 'reverse' | 'forwards' | 'pingPong';
|
|
309
363
|
repeatDelay?: number;
|
|
@@ -322,18 +376,46 @@ interface TransitionOptions {
|
|
|
322
376
|
- `[0.4, 0, 0.2, 1]` - Custom cubic bezier
|
|
323
377
|
- `{ type: 'spring', stiffness: 400, damping: 17 }` - Spring physics
|
|
324
378
|
|
|
379
|
+
## FAQ
|
|
380
|
+
|
|
381
|
+
### Is this Framer Motion for Angular?
|
|
382
|
+
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.
|
|
383
|
+
|
|
384
|
+
### Which Angular versions are supported?
|
|
385
|
+
2.x supports Angular 22 and later. 1.x supports Angular 19.
|
|
386
|
+
|
|
387
|
+
### How is it different from Angular's built-in animations?
|
|
388
|
+
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:
|
|
389
|
+
- physics springs
|
|
390
|
+
- hover, tap and focus gestures
|
|
391
|
+
- staggered children
|
|
392
|
+
- scroll-triggered animation
|
|
393
|
+
- interruptible animations that start from the element's current value
|
|
394
|
+
|
|
395
|
+
### Does it work with server-side rendering?
|
|
396
|
+
Yes. Animation code only runs in the browser, so server rendering outputs the elements without errors.
|
|
397
|
+
|
|
398
|
+
### Does it trigger change detection on every frame?
|
|
399
|
+
No. Animations, timers and gesture listeners run outside Angular's zone.
|
|
400
|
+
|
|
401
|
+
### How do I animate a list as items are added and removed?
|
|
402
|
+
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).
|
|
403
|
+
|
|
404
|
+
### How do I animate on scroll?
|
|
405
|
+
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).
|
|
406
|
+
|
|
325
407
|
## Project Structure
|
|
326
408
|
|
|
327
409
|
```
|
|
328
|
-
|
|
329
|
-
├── projects/ngx-motion/ # Library source
|
|
330
|
-
│ ├── src/lib/directives/ #
|
|
410
|
+
angular-motion-poc/
|
|
411
|
+
├── projects/ngx-motion/ # Library source (published as @hilux/ngx-motion)
|
|
412
|
+
│ ├── src/lib/directives/ # motionone, *motionIf, *motionPresence
|
|
331
413
|
│ ├── src/lib/services/ # Animation services
|
|
332
414
|
│ └── src/public-api.ts # Library exports
|
|
333
|
-
├── src/app/ # Demo
|
|
334
|
-
│ ├──
|
|
335
|
-
│ ├── pages/ #
|
|
336
|
-
│ └──
|
|
415
|
+
├── src/app/ # Demo and docs site
|
|
416
|
+
│ ├── examples/ # One component per example
|
|
417
|
+
│ ├── pages/ # Docs and examples pages
|
|
418
|
+
│ └── components/ # Demo UI components
|
|
337
419
|
└── dist/ngx-motion/ # Built library output
|
|
338
420
|
```
|
|
339
421
|
|
|
@@ -351,10 +433,8 @@ MIT License - see LICENSE file for details
|
|
|
351
433
|
|
|
352
434
|
## Links
|
|
353
435
|
|
|
354
|
-
- [
|
|
355
|
-
- [
|
|
356
|
-
- [
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
Built with Angular and Motion One
|
|
436
|
+
- [Live demo and examples](https://rikisommers.github.io/angular-motion-poc/examples)
|
|
437
|
+
- [Documentation](https://rikisommers.github.io/angular-motion-poc/docs)
|
|
438
|
+
- [npm package](https://www.npmjs.com/package/@hilux/ngx-motion)
|
|
439
|
+
- [Motion documentation](https://motion.dev/)
|
|
440
|
+
- [Angular documentation](https://angular.dev/)
|