@hilux/ngx-motion 2.4.0 → 2.6.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 +121 -2
- package/fesm2022/hilux-ngx-motion.mjs +262 -15
- package/fesm2022/hilux-ngx-motion.mjs.map +1 -1
- package/package.json +1 -1
- package/types/hilux-ngx-motion.d.ts +100 -3
package/README.md
CHANGED
|
@@ -55,6 +55,8 @@ export class CardComponent {}
|
|
|
55
55
|
- **Pan and swipe:** `motionPan` reports pointer movement and swipe directions, with `whilePan` styles.
|
|
56
56
|
- **Reorder:** `motionReorderGroup` and `motionReorderItem` for drag-to-reorder lists, with keyboard support.
|
|
57
57
|
- **Motion values:** `motionSignal`, `mapSignal`, `springSignal`, `velocitySignal` and `scrollSignal`: values that change every frame, as Angular signals, bound to styles with `[motionStyle]` without change detection.
|
|
58
|
+
- **Animate from code:** `injectAnimate()` runs animations, staggers and sequences from TypeScript, scoped to the component and stopped when it's destroyed.
|
|
59
|
+
- **SVG line drawing:** `pathLength`, `pathOffset` and `pathSpacing` on any SVG shape, with every trigger (enter, hover, in view, scroll, `[motionStyle]`).
|
|
58
60
|
- **Layout animations:** `motionLayout` glides elements to their new place and size after any layout change, and `motionLayoutId` makes shared-element transitions.
|
|
59
61
|
- **Exit animations:** `*motionIf` and `*motionPresence` keep elements in the DOM until their exit animation finishes. If shown again mid-exit, they animate back in.
|
|
60
62
|
- **Variants:** named, reusable animation states.
|
|
@@ -62,6 +64,7 @@ export class CardComponent {}
|
|
|
62
64
|
- **Transform shortcuts:** `x`, `y`, `scale`, `rotate` and `skew`, instead of transform strings.
|
|
63
65
|
- **Repeat:** `repeat: Infinity` with `loop`, `reverse` or `mirror`.
|
|
64
66
|
- **Per-property transitions:** different timing for each property.
|
|
67
|
+
- **Reduced motion:** with `prefers-reduced-motion`, movement jumps to its end while fades still play. Change it with `provideMotionConfig`.
|
|
65
68
|
- **Performance:** animations, timers and listeners run outside Angular's change detection, and gesture listeners are only attached when used.
|
|
66
69
|
- **SSR-safe:** animation code only runs in the browser.
|
|
67
70
|
- **Typed:** full TypeScript types for states, transitions and variants.
|
|
@@ -368,6 +371,44 @@ export class Example {
|
|
|
368
371
|
- `[motionStyle]`: transform shortcuts `x`, `y`, `z` (px), `scale`, `scaleX`, `scaleY`, `rotate`, `rotateX/Y/Z`, `skewX/Y` (deg) are combined into `transform`, so don't animate the same element's transform another way. Other styles use camelCase names; numbers get px except unitless ones such as `opacity`. CSS custom properties (`'--progress'`) take any value.
|
|
369
372
|
- With reduced motion, and on the server, springs go straight to their target.
|
|
370
373
|
|
|
374
|
+
### SVG Line Drawing
|
|
375
|
+
Like Framer Motion's `pathLength`. Animate how much of a line is drawn, from 0 to 1, on any SVG shape: `path`, `circle`, `rect`, `line`, `polyline`, `polygon`, `ellipse`. It works with every trigger.
|
|
376
|
+
|
|
377
|
+
A simple hover draw is fine in plain CSS: give the shape `pathLength="1"`, set `stroke-dasharray: 1; stroke-dashoffset: 1` and transition `stroke-dashoffset`. Use ngx-motion when a line should draw when it scrolls into view, one part after another, as the page scrolls (in every browser), on exit, follow a value on a spring, or spring and loop on hover and settle smoothly when the pointer leaves (a CSS loop snaps back).
|
|
378
|
+
|
|
379
|
+
```html
|
|
380
|
+
<!-- Draws when scrolled into view, one part after another -->
|
|
381
|
+
<svg viewBox="0 0 100 100" fill="none" stroke="currentColor" stroke-width="6"
|
|
382
|
+
motionone runInView="once" [staggerChildren]="0.12" [initial]="{}" [animate]="{}">
|
|
383
|
+
<circle cx="50" cy="50" r="42"
|
|
384
|
+
motionone [initial]="{ pathLength: 0 }" [animate]="{ pathLength: 1 }" />
|
|
385
|
+
<path d="M30 52 L45 66 L72 36"
|
|
386
|
+
motionone [initial]="{ pathLength: 0 }" [animate]="{ pathLength: 1 }" />
|
|
387
|
+
</svg>
|
|
388
|
+
|
|
389
|
+
<!-- Draws as the page scrolls -->
|
|
390
|
+
<path d="…" [motionScroll]="{ pathLength: [0, 1] }" />
|
|
391
|
+
|
|
392
|
+
<!-- On hover: draws in and runs off the end, round and round; on leave it finishes forward -->
|
|
393
|
+
<path d="…" motionone
|
|
394
|
+
[initial]="{ pathLength: 0, pathOffset: 1 }"
|
|
395
|
+
[whileHover]="{ pathLength: [0, 1, 0], pathOffset: [0, 0, 1], transition: { duration: 1.6, repeat: Infinity } }" />
|
|
396
|
+
|
|
397
|
+
<!-- A dash running round a circle: dash 0.25 + gap 0.75 = 1, so it loops seamlessly -->
|
|
398
|
+
<circle cx="50" cy="50" r="40"
|
|
399
|
+
motionone [initial]="{ pathLength: 0.25, pathSpacing: 0.75, pathOffset: 0 }" [animate]="{ pathOffset: 1 }"
|
|
400
|
+
[transition]="{ duration: 1.2, ease: 'linear', repeat: Infinity }" />
|
|
401
|
+
|
|
402
|
+
<!-- Or follow a value on a spring (a gauge) -->
|
|
403
|
+
<path d="…" [motionStyle]="{ pathLength: length }" />
|
|
404
|
+
<!-- readonly length = mapSignal(springSignal(this.value), [0, 100], [0, 1]); -->
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
- `pathLength`: how much is drawn (0 to 1). `pathOffset`: where the drawn part starts. `pathSpacing`: the gap after each drawn part (default 1).
|
|
408
|
+
- They are fractions of the shape's own length: the shape gets `pathLength="1"`, and `stroke-dasharray` / `stroke-dashoffset` are set for you.
|
|
409
|
+
- With round or square line caps a line at `pathLength: 0` still shows a dot, so fade it in too (`opacity: 0` → `1`).
|
|
410
|
+
- Animating only `pathOffset` or `pathSpacing` keeps the dash length it had.
|
|
411
|
+
|
|
371
412
|
### Layout Animations
|
|
372
413
|
Like Framer Motion's `layout` and `layoutId`. Change the layout however you like (reorder or filter a list, switch flex to grid, toggle a class) and `motionLayout` animates each element from where it was drawn to where it is now. No positions to calculate.
|
|
373
414
|
|
|
@@ -410,6 +451,52 @@ Like Framer Motion's `layout` and `layoutId`. Change the layout however you like
|
|
|
410
451
|
- Layout animations use the element's `transform`, so don't give it a CSS transform of its own; wrap it instead.
|
|
411
452
|
- Interrupted animations continue from where the element is drawn. Resizing the window re-measures without animating, and with reduced motion nothing animates.
|
|
412
453
|
|
|
454
|
+
### Animate from Code
|
|
455
|
+
Like Framer Motion's `useAnimate`. Templates cover states; `injectAnimate()` covers what happens in code: a click handler, the result of a request, a sequence of steps.
|
|
456
|
+
|
|
457
|
+
```typescript
|
|
458
|
+
import { injectAnimate, stagger, motionSignal } from '@hilux/ngx-motion';
|
|
459
|
+
|
|
460
|
+
export class SendButton {
|
|
461
|
+
private readonly animate = injectAnimate();
|
|
462
|
+
readonly visits = motionSignal(0);
|
|
463
|
+
|
|
464
|
+
async send() {
|
|
465
|
+
// A sequence: each step starts when the one before ends; `at` moves it
|
|
466
|
+
await this.animate([
|
|
467
|
+
['.button', { scale: 0.92 }, { duration: 0.12 }],
|
|
468
|
+
['.button', { scale: 1 }, { duration: 0.3, ease: 'backOut' }],
|
|
469
|
+
['.plane', { x: 140, y: -90, opacity: 0 }, { duration: 0.45, at: '-0.2' }],
|
|
470
|
+
['.tick path', { pathLength: [0, 1] }, { duration: 0.3 }],
|
|
471
|
+
]);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
async load() {
|
|
475
|
+
// Staggered, and a number signal counting up to a result
|
|
476
|
+
this.animate('li', { opacity: [0, 1], y: [10, 0] }, { delay: stagger(0.04, { from: 'center' }) });
|
|
477
|
+
const total = await firstValueFrom(this.http.get<number>('/api/visits'));
|
|
478
|
+
await this.animate(this.visits, total, { duration: 1.2 });
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
- `animate(target, keyframes, options)`: a selector, element, element list or `ElementRef`. Selectors are looked up inside the component's own element (or `injectAnimate({ scope })`), never elsewhere on the page.
|
|
484
|
+
- `animate(signal, to, options)`: a `motionSignal` or `springSignal`; bind it with `[motionStyle]` or read it in the template.
|
|
485
|
+
- `animate([...steps], options)`: a sequence. Steps can be elements or signals; `at` places a step (`'-0.2'`, `'<'`, a time or a label).
|
|
486
|
+
- It returns the running animation: `await` it, or call `stop()`, `pause()`, `play()`, `complete()`, and set `speed` or `time`.
|
|
487
|
+
- `animate.stop()` stops everything that function started. Everything is stopped when the component is destroyed.
|
|
488
|
+
- `stagger(each, { from, ease, startDelay })` is Motion's, re-exported.
|
|
489
|
+
- Runs outside change detection, does nothing on the server, and follows the reduced-motion setting.
|
|
490
|
+
- Call it in an injection context (a field or the constructor), or pass `{ injector }`.
|
|
491
|
+
|
|
492
|
+
### Reduced Motion
|
|
493
|
+
When the user asks for reduced motion (`prefers-reduced-motion: reduce`), movement (`x`, `y`, `scale`, `rotate`, size) jumps straight to its end, while fades, colours and line drawing still play. This applies to every directive and to `injectAnimate`, like Framer Motion's `reducedMotion="user"`. Layout animations, pointer effects and scroll-linked keyframes stay still, and springs go straight to their target.
|
|
494
|
+
|
|
495
|
+
```typescript
|
|
496
|
+
// app.config.ts: 'user' (default), 'always' or 'never'
|
|
497
|
+
providers: [provideMotionConfig({ reducedMotion: 'never' })]
|
|
498
|
+
```
|
|
499
|
+
|
|
413
500
|
## Angular Control Flow Integration
|
|
414
501
|
|
|
415
502
|
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.
|
|
@@ -504,6 +591,9 @@ The directives work seamlessly with Angular's new control flow syntax:
|
|
|
504
591
|
| `<Reorder.Group values onReorder>` / `<Reorder.Item value>` | `[(motionReorderGroup)]` / `[motionReorderItem]` |
|
|
505
592
|
| `useMotionValue`, `useTransform`, `useSpring`, `useVelocity`, `useScroll` | `motionSignal`, `mapSignal`, `springSignal`, `velocitySignal`, `scrollSignal` |
|
|
506
593
|
| `style={{ x, opacity }}` with motion values | `[motionStyle]="{ x: x, opacity: opacity }"` |
|
|
594
|
+
| `pathLength`, `pathOffset`, `pathSpacing` | the same keys in `[initial]`, `[animate]`, `[whileHover]`, `[motionScroll]`, `[motionStyle]` |
|
|
595
|
+
| `useAnimate`, `animate(sequence)`, `stagger()` | `injectAnimate()`, `animate(sequence)`, `stagger()` |
|
|
596
|
+
| `<MotionConfig reducedMotion="user">` | `provideMotionConfig({ reducedMotion: 'user' })` (the default) |
|
|
507
597
|
| `layout`, `layout="position"` | `motionLayout`, `motionLayout="position"` |
|
|
508
598
|
| `layoutId` | `motionLayoutId` |
|
|
509
599
|
| `<LayoutGroup>` | not needed: every layout element is measured after every render |
|
|
@@ -523,19 +613,31 @@ A lot of animation is plain CSS now, and where CSS is enough it is the better ch
|
|
|
523
613
|
| Sequences | ⚠️ Percentages in one `@keyframes`; several elements need hand-tuned delays | Timelines, `repeat` with `mirror` / `reverse`, per-property transitions |
|
|
524
614
|
| Play once when scrolled into view | ❌ No trigger yet (`animation-trigger` is experimental); needs IntersectionObserver | `runInView`, `whileInView` |
|
|
525
615
|
| Scroll-linked values | ✅ / ⚠️ `animation-timeline: scroll()` / `view()` in Chrome and Safari 26, not in Firefox by default | Same API everywhere (uses the native timeline where available), plus `progress()` and `velocity()` signals |
|
|
616
|
+
| SVG line drawing | ✅ / ⚠️ `pathLength="1"` plus a `stroke-dashoffset` transition or `@keyframes` covers simple hover, enter and looping spinners; no springs, a loop snaps back when hover ends, no in-view trigger, scroll-linked only with scroll timelines | Hover that springs or loops and settles on leave; draw when scrolled into view, staggered; scroll-linked in every browser; undraw on exit; follow a value on a spring |
|
|
526
617
|
| Magnetic, tilt, follow-pointer | ❌ CSS can't read the pointer position | `motionMagnetic`, `motionTilt` (sets `--motion-pointer-x/y` for CSS), `motionFollowPointer` |
|
|
527
618
|
| Drag | ❌ | Constraints, elastic edges, momentum, snap points |
|
|
528
619
|
| Pan and swipe | ❌ Only `touch-action` and scroll snap | Offset, delta, velocity and swipe direction |
|
|
529
620
|
| Drag to reorder | ❌ | Two-way bound order, keyboard moves, neighbours glide aside |
|
|
530
621
|
| Layout changes | ⚠️ View Transitions animate layout changes, but snapshot the whole page as an image, run one at a time and restart if interrupted; `interpolate-size` animates `height: auto` (Chrome only) | `motionLayout`: the real elements animate and stay clickable, several at once, interruptible, on springs; text can keep its size and corners stay round |
|
|
531
622
|
| Shared elements | ✅ / ⚠️ `view-transition-name` covers a thumbnail growing into a detail view | `motionLayoutId`: across scroll containers, while the page stays interactive, no `startViewTransition` call |
|
|
532
|
-
| Reduced motion | ✅ `@media (prefers-reduced-motion)` |
|
|
623
|
+
| Reduced motion | ✅ `@media (prefers-reduced-motion)` | Movement jumps to its end and fades still play, in every directive and `injectAnimate`; `provideMotionConfig` changes it |
|
|
533
624
|
| Change detection and SSR | No JavaScript | Runs outside Angular's change detection; does nothing on the server |
|
|
534
625
|
|
|
535
626
|
**Use CSS for** hover and focus styling, simple enter animations, looping decorations and fixed-length transitions. **Use ngx-motion for** gestures and pointer effects, interruptible springs, exits from `@if` and `@for`, scroll triggers, and layout animations inside a page. For full-page route changes, View Transitions are often the better tool (the demo's Route Transitions examples use them).
|
|
536
627
|
|
|
537
628
|
## Changelog
|
|
538
629
|
|
|
630
|
+
**2.6.0**
|
|
631
|
+
- `injectAnimate()`: animate elements, number signals and sequences from TypeScript, with Motion's `stagger()`. Scoped to the component and stopped when it's destroyed. See [Animate from Code](#animate-from-code).
|
|
632
|
+
- Reduced motion now applies to `motionone` too (before, only layout, pointer, scroll and spring signals respected it): movement jumps to its end and fades still play. New `provideMotionConfig({ reducedMotion: 'user' | 'always' | 'never' })` to change it. See [Reduced Motion](#reduced-motion).
|
|
633
|
+
- Easing names: `easeInCirc`, `easeOutCirc`, `easeInOutCirc`, `easeInBack`, `easeOutBack` and `easeInOutBack` are accepted as Motion's `circIn`, `backOut` and so on. An unknown name warns in development (it still falls back to ease-in-out).
|
|
634
|
+
|
|
635
|
+
**2.5.0**
|
|
636
|
+
- SVG line drawing: `pathLength`, `pathOffset` and `pathSpacing` on any SVG shape, in every state (`initial`, `animate`, `whileHover`, `whileInView`, `exit`), in `[motionScroll]` and in `[motionStyle]`. See [SVG Line Drawing](#svg-line-drawing).
|
|
637
|
+
- Fixed: SVG shapes (path, circle…) with styles in `initial`, such as `opacity: 0`, stayed at those values. The starting values are now written as attributes, which is how Motion animates SVG, so the animation shows.
|
|
638
|
+
- Fixed: Motion's easing names (`'linear'`, `'easeOut'`, `'backOut'`, `'anticipate'`…) and easing functions were replaced by ease-in-out. They are now passed to Motion as given.
|
|
639
|
+
- Fixed: `springSignal` following a value that changes every frame (pointer, drag) no longer jitters: the spring keeps its position and speed, and only its target moves.
|
|
640
|
+
|
|
539
641
|
**2.4.0**
|
|
540
642
|
- Motion values as Angular signals: `motionSignal`, `mapSignal`, `springSignal`, `velocitySignal` and `scrollSignal`, and the `[motionStyle]` directive, which writes them to the element without change detection. See [Motion Values](#motion-values).
|
|
541
643
|
|
|
@@ -651,6 +753,9 @@ interface TransitionOptions {
|
|
|
651
753
|
- `'ease-in'` - CSS ease-in
|
|
652
754
|
- `'ease-out'` - CSS ease-out
|
|
653
755
|
- `'ease-in-out'` - CSS ease-in-out
|
|
756
|
+
- `'linear'`, `'easeIn'`, `'easeOut'`, `'easeInOut'`, `'circIn'`, `'circOut'`, `'circInOut'`, `'backIn'`, `'backOut'`, `'backInOut'`, `'anticipate'` - Motion's named easings
|
|
757
|
+
- `'easeInCirc'`, `'easeOutCirc'`, `'easeInOutCirc'`, `'easeInBack'`, `'easeOutBack'`, `'easeInOutBack'` - Aliases for Motion's `circIn`, `backOut` and so on
|
|
758
|
+
- `(t) => number` - An easing function
|
|
654
759
|
- `[0.4, 0, 0.2, 1]` - Custom cubic bezier
|
|
655
760
|
- `{ type: 'spring', stiffness: 400, damping: 17 }` - Spring physics
|
|
656
761
|
|
|
@@ -682,6 +787,18 @@ No. Animations, timers and gesture listeners run outside Angular's zone.
|
|
|
682
787
|
### How do I animate a list as items are added and removed?
|
|
683
788
|
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).
|
|
684
789
|
|
|
790
|
+
### Can I start animations from TypeScript?
|
|
791
|
+
Yes. `injectAnimate()` animates elements (by selector, inside the component), number signals and sequences from any method, for example after a request. It returns controls you can await, pause or stop, and cleans up when the component is destroyed. See [Animate from Code](#animate-from-code).
|
|
792
|
+
|
|
793
|
+
### How does it handle reduced motion?
|
|
794
|
+
With `prefers-reduced-motion: reduce`, movement jumps to its end while fades, colours and line drawing still play, everywhere in the library. Use `provideMotionConfig({ reducedMotion: 'never' })` to turn that off or `'always'` to force it. See [Reduced Motion](#reduced-motion).
|
|
795
|
+
|
|
796
|
+
### Can animated values be Angular signals?
|
|
797
|
+
Yes. `motionSignal`, `mapSignal`, `springSignal`, `velocitySignal` and `scrollSignal` are signals that change every frame, and `[motionStyle]` writes them to the element without change detection. See [Motion Values](#motion-values).
|
|
798
|
+
|
|
799
|
+
### Can it draw SVG lines?
|
|
800
|
+
Yes: animate `pathLength` (0 to 1), `pathOffset` and `pathSpacing` on any SVG shape, with any trigger. A simple hover draw is fine in plain CSS; ngx-motion adds drawing when scrolled into view, staggered, scroll-linked in every browser, on exit, on a spring and from a signal. See [SVG Line Drawing](#svg-line-drawing).
|
|
801
|
+
|
|
685
802
|
### How do I animate on scroll?
|
|
686
803
|
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). To tie styles to the scroll position itself (parallax, progress bars, pinned sections), use [`motionScroll`](#scroll-linked-values).
|
|
687
804
|
|
|
@@ -690,7 +807,9 @@ Add `runInView="once"` to play `animate` the first time the element scrolls into
|
|
|
690
807
|
```
|
|
691
808
|
angular-motion-poc/
|
|
692
809
|
├── projects/ngx-motion/ # Library source (published as @hilux/ngx-motion)
|
|
693
|
-
│ ├── src/lib/directives/ # motionone, *motionIf, *motionPresence
|
|
810
|
+
│ ├── src/lib/directives/ # motionone, *motionIf, *motionPresence, drag, pan, layout…
|
|
811
|
+
│ ├── src/lib/values/ # Motion values as signals
|
|
812
|
+
│ ├── src/lib/animate/ # injectAnimate
|
|
694
813
|
│ ├── src/lib/services/ # Animation services
|
|
695
814
|
│ └── src/public-api.ts # Library exports
|
|
696
815
|
├── src/app/ # Demo and docs site
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { ChangeDetectorRef, DOCUMENT, DestroyRef, Directive, ElementRef, EventEmitter, HostListener, Inject, Injectable, Injector, Input, NgZone, Output, PLATFORM_ID, TemplateRef, ViewContainerRef, afterEveryRender, afterNextRender, afterRenderEffect, assertInInjectionContext, effect, forwardRef, inject, input, isDevMode, isSignal, model, output, signal, untracked } from "@angular/core";
|
|
2
|
+
import { ChangeDetectorRef, DOCUMENT, DestroyRef, Directive, ElementRef, EventEmitter, HostListener, Inject, Injectable, InjectionToken, Injector, Input, NgZone, Output, PLATFORM_ID, TemplateRef, ViewContainerRef, afterEveryRender, afterNextRender, afterRenderEffect, assertInInjectionContext, effect, forwardRef, inject, input, isDevMode, isSignal, model, output, signal, untracked } from "@angular/core";
|
|
3
3
|
import { isPlatformBrowser } from "@angular/common";
|
|
4
4
|
import { Subject, timer } from "rxjs";
|
|
5
5
|
import { map, take } from "rxjs/operators";
|
|
6
|
-
import { animate, easeIn, easeInOut, easeOut, inView, scroll, spring, stagger, transform } from "motion";
|
|
6
|
+
import { animate, createScopedAnimate, easeIn, easeInOut, easeOut, inView, scroll, spring, stagger, stagger as stagger$1, transform } from "motion";
|
|
7
7
|
var MotionOneService = class MotionOneService {
|
|
8
8
|
document;
|
|
9
9
|
platformId;
|
|
@@ -227,16 +227,114 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
227
227
|
{ type: NgZone }
|
|
228
228
|
]
|
|
229
229
|
});
|
|
230
|
+
const SVG_PATH_KEYS = /* @__PURE__ */ new Set([
|
|
231
|
+
"pathLength",
|
|
232
|
+
"pathOffset",
|
|
233
|
+
"pathSpacing"
|
|
234
|
+
]);
|
|
235
|
+
function isSvgPathKey(key) {
|
|
236
|
+
return SVG_PATH_KEYS.has(key);
|
|
237
|
+
}
|
|
238
|
+
function readSvgPath(el) {
|
|
239
|
+
if (!el.hasAttribute("pathLength")) return {};
|
|
240
|
+
const out = {};
|
|
241
|
+
const dash = el.getAttribute("stroke-dasharray")?.trim().split(/[\s,]+/).map(parseFloat);
|
|
242
|
+
if (dash && !isNaN(dash[0])) {
|
|
243
|
+
out.pathLength = dash[0];
|
|
244
|
+
if (dash.length > 1 && !isNaN(dash[1]) && dash[1] !== 1) out.pathSpacing = dash[1];
|
|
245
|
+
}
|
|
246
|
+
const offset = parseFloat(el.getAttribute("stroke-dashoffset") ?? "");
|
|
247
|
+
if (!isNaN(offset) && offset !== 0) out.pathOffset = -offset;
|
|
248
|
+
return out;
|
|
249
|
+
}
|
|
250
|
+
function applySvgPath(el, values) {
|
|
251
|
+
if (typeof SVGElement === "undefined" || !(el instanceof SVGElement)) return;
|
|
252
|
+
const current = readSvgPath(el);
|
|
253
|
+
for (const key of SVG_PATH_KEYS) {
|
|
254
|
+
if (!(key in values)) continue;
|
|
255
|
+
const v = values[key];
|
|
256
|
+
current[key] = v == null || v === "" ? void 0 : Number(v);
|
|
257
|
+
}
|
|
258
|
+
if (current.pathLength === void 0 && current.pathOffset === void 0 && current.pathSpacing === void 0) {
|
|
259
|
+
el.removeAttribute("pathLength");
|
|
260
|
+
el.removeAttribute("stroke-dasharray");
|
|
261
|
+
el.removeAttribute("stroke-dashoffset");
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
el.setAttribute("pathLength", "1");
|
|
265
|
+
el.setAttribute("stroke-dasharray", `${current.pathLength ?? 1} ${current.pathSpacing ?? 1}`);
|
|
266
|
+
el.setAttribute("stroke-dashoffset", `${-(current.pathOffset ?? 0)}`);
|
|
267
|
+
}
|
|
268
|
+
function withSvgPathContext(target, keyframes) {
|
|
269
|
+
if (typeof SVGElement === "undefined" || !(target instanceof SVGElement) || !keyframes || typeof keyframes !== "object") return keyframes;
|
|
270
|
+
if (!Object.keys(keyframes).some(isSvgPathKey)) return keyframes;
|
|
271
|
+
const current = readSvgPath(target);
|
|
272
|
+
const out = { ...keyframes };
|
|
273
|
+
const defaults = {
|
|
274
|
+
pathLength: 1,
|
|
275
|
+
pathOffset: 0,
|
|
276
|
+
pathSpacing: 1
|
|
277
|
+
};
|
|
278
|
+
for (const key of SVG_PATH_KEYS) {
|
|
279
|
+
const v = out[key];
|
|
280
|
+
if (v === void 0 || Array.isArray(v)) continue;
|
|
281
|
+
const k = key;
|
|
282
|
+
out[key] = [current[k] ?? defaults[k], v];
|
|
283
|
+
}
|
|
284
|
+
const hold = (key, fallback) => {
|
|
285
|
+
const v = current[key] ?? fallback;
|
|
286
|
+
if (!(key in out) && v !== void 0) out[key] = [v, v];
|
|
287
|
+
};
|
|
288
|
+
hold("pathLength", 1);
|
|
289
|
+
hold("pathSpacing");
|
|
290
|
+
hold("pathOffset");
|
|
291
|
+
return out;
|
|
292
|
+
}
|
|
293
|
+
const MOTION_CONFIG = new InjectionToken("MOTION_CONFIG", { factory: () => ({}) });
|
|
294
|
+
function provideMotionConfig(config) {
|
|
295
|
+
return {
|
|
296
|
+
provide: MOTION_CONFIG,
|
|
297
|
+
useValue: config
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
const MOVEMENT = /^(x|y|z|scale[XYZ]?|rotate[XYZ]?|skew[XY]?|translate[XYZ]?|transform|perspective|width|height|top|left|right|bottom|inset|margin|padding)/;
|
|
301
|
+
function isMovementKey(key) {
|
|
302
|
+
return MOVEMENT.test(key);
|
|
303
|
+
}
|
|
304
|
+
function prefersReducedMotion(config) {
|
|
305
|
+
const mode = config.reducedMotion ?? "user";
|
|
306
|
+
if (mode === "never") return false;
|
|
307
|
+
if (mode === "always") return true;
|
|
308
|
+
return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
309
|
+
}
|
|
310
|
+
function withoutMovement(keyframes, options) {
|
|
311
|
+
if (!keyframes || typeof keyframes !== "object" || Array.isArray(keyframes)) return options;
|
|
312
|
+
const keys = Object.keys(keyframes).filter(isMovementKey);
|
|
313
|
+
if (!keys.length) return options;
|
|
314
|
+
const out = { ...options ?? {} };
|
|
315
|
+
for (const key of keys) out[key] = {
|
|
316
|
+
type: "tween",
|
|
317
|
+
duration: 0,
|
|
318
|
+
delay: 0,
|
|
319
|
+
repeat: 0
|
|
320
|
+
};
|
|
321
|
+
return out;
|
|
322
|
+
}
|
|
230
323
|
const noopControls = () => ({ stop: () => {} });
|
|
231
324
|
const linear = (t) => t;
|
|
232
325
|
var MotionAnimationService = class MotionAnimationService {
|
|
233
326
|
platformId = inject(PLATFORM_ID);
|
|
234
327
|
ngZone = inject(NgZone);
|
|
235
328
|
isBrowser = isPlatformBrowser(this.platformId);
|
|
329
|
+
config = inject(MOTION_CONFIG);
|
|
330
|
+
reducedMotion() {
|
|
331
|
+
return this.isBrowser && prefersReducedMotion(this.config);
|
|
332
|
+
}
|
|
236
333
|
animate(target, keyframes, options) {
|
|
237
334
|
if (!this.isBrowser) return noopControls();
|
|
238
335
|
try {
|
|
239
|
-
|
|
336
|
+
if (this.reducedMotion()) options = withoutMovement(keyframes, options);
|
|
337
|
+
return this.ngZone.runOutsideAngular(() => animate(target, withSvgPathContext(target, keyframes), options));
|
|
240
338
|
} catch (e) {
|
|
241
339
|
console.error("[ngx-motion] Error in animate:", e);
|
|
242
340
|
return noopControls();
|
|
@@ -258,7 +356,7 @@ var MotionAnimationService = class MotionAnimationService {
|
|
|
258
356
|
stagger(duration, options) {
|
|
259
357
|
if (!this.isBrowser) return 0;
|
|
260
358
|
try {
|
|
261
|
-
return stagger(duration, options);
|
|
359
|
+
return stagger$1(duration, options);
|
|
262
360
|
} catch (e) {
|
|
263
361
|
console.error("[ngx-motion] Error in stagger:", e);
|
|
264
362
|
return 0;
|
|
@@ -303,6 +401,28 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
303
401
|
args: [{ providedIn: "root" }]
|
|
304
402
|
}]
|
|
305
403
|
});
|
|
404
|
+
const MOTION_EASINGS = /* @__PURE__ */ new Set([
|
|
405
|
+
"linear",
|
|
406
|
+
"easeIn",
|
|
407
|
+
"easeOut",
|
|
408
|
+
"easeInOut",
|
|
409
|
+
"circIn",
|
|
410
|
+
"circOut",
|
|
411
|
+
"circInOut",
|
|
412
|
+
"backIn",
|
|
413
|
+
"backOut",
|
|
414
|
+
"backInOut",
|
|
415
|
+
"anticipate"
|
|
416
|
+
]);
|
|
417
|
+
const ALIASES = {
|
|
418
|
+
easeInCirc: "circIn",
|
|
419
|
+
easeOutCirc: "circOut",
|
|
420
|
+
easeInOutCirc: "circInOut",
|
|
421
|
+
easeInBack: "backIn",
|
|
422
|
+
easeOutBack: "backOut",
|
|
423
|
+
easeInOutBack: "backInOut"
|
|
424
|
+
};
|
|
425
|
+
const warned = /* @__PURE__ */ new Set();
|
|
306
426
|
function getEasing(easingString, motionAnimation) {
|
|
307
427
|
if (!easingString) return motionAnimation.easeInOut;
|
|
308
428
|
if (Array.isArray(easingString)) return easingString;
|
|
@@ -310,11 +430,18 @@ function getEasing(easingString, motionAnimation) {
|
|
|
310
430
|
stiffness: easingString.stiffness || 100,
|
|
311
431
|
damping: easingString.damping || 10
|
|
312
432
|
});
|
|
433
|
+
if (typeof easingString === "function") return easingString;
|
|
313
434
|
if (typeof easingString === "string") {
|
|
314
435
|
if (easingString === "ease-in") return motionAnimation.easeIn;
|
|
315
436
|
if (easingString === "ease-out") return motionAnimation.easeOut;
|
|
316
437
|
if (easingString === "ease-in-out" || easingString === "ease") return motionAnimation.easeInOut;
|
|
317
438
|
if (easingString === "spring") return motionAnimation.spring();
|
|
439
|
+
if (MOTION_EASINGS.has(easingString)) return easingString;
|
|
440
|
+
if (ALIASES[easingString]) return ALIASES[easingString];
|
|
441
|
+
if (isDevMode() && !warned.has(easingString)) {
|
|
442
|
+
warned.add(easingString);
|
|
443
|
+
console.warn(`[ngx-motion] Unknown easing "${easingString}", using easeInOut. Use one of: ${[...MOTION_EASINGS].join(", ")}, a cubic bezier array or a function.`);
|
|
444
|
+
}
|
|
318
445
|
}
|
|
319
446
|
return motionAnimation.easeInOut;
|
|
320
447
|
}
|
|
@@ -909,6 +1036,7 @@ function transformFunction(key, value) {
|
|
|
909
1036
|
default: return `${key}(${v})`;
|
|
910
1037
|
}
|
|
911
1038
|
}
|
|
1039
|
+
const kebab = (key) => key.replace(/[A-Z]/g, (c) => "-" + c.toLowerCase());
|
|
912
1040
|
function firstFrame(value) {
|
|
913
1041
|
return Array.isArray(value) ? value[0] : value;
|
|
914
1042
|
}
|
|
@@ -916,12 +1044,21 @@ function applyInlineStyles(el, styles) {
|
|
|
916
1044
|
if (!el?.style || !styles) return;
|
|
917
1045
|
const transforms = [];
|
|
918
1046
|
let rawTransform;
|
|
1047
|
+
let path;
|
|
1048
|
+
const svgShape = typeof SVGElement !== "undefined" && el instanceof SVGElement && !(el instanceof SVGSVGElement);
|
|
919
1049
|
for (const key of Object.keys(styles)) {
|
|
920
1050
|
const value = firstFrame(styles[key]);
|
|
921
1051
|
if (value === void 0 || value === null) continue;
|
|
922
1052
|
if (key === "transform") rawTransform = String(value);
|
|
923
|
-
else if (
|
|
1053
|
+
else if (isSvgPathKey(key)) (path ??= {})[key] = value;
|
|
1054
|
+
else if (!TRANSFORM_KEYS.has(key)) {
|
|
1055
|
+
if (svgShape && !key.startsWith("--")) {
|
|
1056
|
+
el.style.removeProperty(kebab(key));
|
|
1057
|
+
el.setAttribute(kebab(key), String(value));
|
|
1058
|
+
} else el.style[key] = value;
|
|
1059
|
+
}
|
|
924
1060
|
}
|
|
1061
|
+
if (path) applySvgPath(el, path);
|
|
925
1062
|
for (const key of TRANSFORM_ORDER) if (key in styles) {
|
|
926
1063
|
const value = firstFrame(styles[key]);
|
|
927
1064
|
if (value !== void 0 && value !== null) transforms.push(transformFunction(key, value));
|
|
@@ -2061,7 +2198,7 @@ var MotionScrollDirective = class MotionScrollDirective {
|
|
|
2061
2198
|
this._progress.set(p);
|
|
2062
2199
|
this._velocity.set(info?.[axis]?.velocity ?? 0);
|
|
2063
2200
|
}, options));
|
|
2064
|
-
const reduced = respect &&
|
|
2201
|
+
const reduced = respect && this.motion.reducedMotion();
|
|
2065
2202
|
if (keyframes && Object.keys(keyframes).length && !reduced) {
|
|
2066
2203
|
const animation = this.motion.animate(this.el, keyframes, {
|
|
2067
2204
|
ease: "linear",
|
|
@@ -2236,9 +2373,6 @@ const POINTER_SPRING = {
|
|
|
2236
2373
|
damping: 20,
|
|
2237
2374
|
mass: .6
|
|
2238
2375
|
};
|
|
2239
|
-
function reducedMotion() {
|
|
2240
|
-
return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
2241
|
-
}
|
|
2242
2376
|
function listener() {
|
|
2243
2377
|
const zone = inject(NgZone);
|
|
2244
2378
|
const destroyRef = inject(DestroyRef);
|
|
@@ -2260,7 +2394,7 @@ var MotionMagneticDirective = class MotionMagneticDirective {
|
|
|
2260
2394
|
const listen = listener();
|
|
2261
2395
|
if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
|
|
2262
2396
|
afterNextRender(() => {
|
|
2263
|
-
if (reducedMotion()) return;
|
|
2397
|
+
if (motion.reducedMotion()) return;
|
|
2264
2398
|
let x = 0, y = 0;
|
|
2265
2399
|
listen(document, "pointermove", (e) => {
|
|
2266
2400
|
if (e.pointerType !== "mouse") return;
|
|
@@ -2377,7 +2511,7 @@ var MotionTiltDirective = class MotionTiltDirective {
|
|
|
2377
2511
|
const listen = listener();
|
|
2378
2512
|
if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
|
|
2379
2513
|
afterNextRender(() => {
|
|
2380
|
-
const reduced = reducedMotion();
|
|
2514
|
+
const reduced = motion.reducedMotion();
|
|
2381
2515
|
const max = () => this.motionTilt() === "" ? 10 : Number(this.motionTilt());
|
|
2382
2516
|
listen(el, "pointermove", (e) => {
|
|
2383
2517
|
if (e.pointerType === "touch") return;
|
|
@@ -2518,7 +2652,7 @@ var MotionFollowPointerDirective = class MotionFollowPointerDirective {
|
|
|
2518
2652
|
const listen = listener();
|
|
2519
2653
|
if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
|
|
2520
2654
|
afterNextRender(() => {
|
|
2521
|
-
const reduced = reducedMotion();
|
|
2655
|
+
const reduced = motion.reducedMotion();
|
|
2522
2656
|
const mode = this.motionFollowPointer();
|
|
2523
2657
|
const area = mode instanceof Element ? mode : mode === "window" ? null : el.parentElement;
|
|
2524
2658
|
if (this.followHide()) motion.animate(el, {
|
|
@@ -3885,7 +4019,7 @@ var MotionLayoutDirective = class MotionLayoutDirective {
|
|
|
3885
4019
|
resumeFrom;
|
|
3886
4020
|
radii = null;
|
|
3887
4021
|
inlineRadius = "";
|
|
3888
|
-
reduced =
|
|
4022
|
+
reduced = inject(MotionAnimationService).reducedMotion();
|
|
3889
4023
|
constructor() {
|
|
3890
4024
|
const destroyRef = inject(DestroyRef);
|
|
3891
4025
|
if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
|
|
@@ -4227,7 +4361,7 @@ function springSignal(source, options = {}) {
|
|
|
4227
4361
|
const injector = injectorFor(springSignal, options);
|
|
4228
4362
|
const zone = injector.get(NgZone);
|
|
4229
4363
|
const browser = isPlatformBrowser(injector.get(PLATFORM_ID)) && typeof requestAnimationFrame !== "undefined";
|
|
4230
|
-
const reduced = browser &&
|
|
4364
|
+
const reduced = browser && injector.get(MotionAnimationService).reducedMotion();
|
|
4231
4365
|
const { stiffness = 300, damping = 30, mass = 1, restDelta = .01, restSpeed = .05 } = options;
|
|
4232
4366
|
const start = typeof source === "number" ? source : isMotionSignal(source) ? source.get() : untracked(source);
|
|
4233
4367
|
const value = motionSignal(start);
|
|
@@ -4413,6 +4547,7 @@ var MotionStyleDirective = class MotionStyleDirective {
|
|
|
4413
4547
|
});
|
|
4414
4548
|
}
|
|
4415
4549
|
write(key, value) {
|
|
4550
|
+
if (isSvgPathKey(key)) return applySvgPath(this.el, { [key]: value });
|
|
4416
4551
|
if (TRANSFORMS.includes(key)) {
|
|
4417
4552
|
if (value == null) this.transform.delete(key);
|
|
4418
4553
|
else this.transform.set(key, value);
|
|
@@ -4476,6 +4611,118 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
4476
4611
|
}]
|
|
4477
4612
|
}] }
|
|
4478
4613
|
});
|
|
4479
|
-
|
|
4614
|
+
function injectAnimate(options = {}) {
|
|
4615
|
+
if (!options.injector) assertInInjectionContext(injectAnimate);
|
|
4616
|
+
const injector = options.injector ?? inject(Injector);
|
|
4617
|
+
const motion = injector.get(MotionAnimationService);
|
|
4618
|
+
const zone = injector.get(NgZone);
|
|
4619
|
+
const browser = isPlatformBrowser(injector.get(PLATFORM_ID));
|
|
4620
|
+
const host = injector.get(ElementRef, null);
|
|
4621
|
+
const resolve = (s) => {
|
|
4622
|
+
const v = typeof s === "function" ? s() : s;
|
|
4623
|
+
return v instanceof ElementRef ? v.nativeElement : v ?? void 0;
|
|
4624
|
+
};
|
|
4625
|
+
const scoped = createScopedAnimate({
|
|
4626
|
+
get current() {
|
|
4627
|
+
return resolve(options.scope) ?? host?.nativeElement;
|
|
4628
|
+
},
|
|
4629
|
+
animations: []
|
|
4630
|
+
});
|
|
4631
|
+
const running = /* @__PURE__ */ new Set();
|
|
4632
|
+
const element = (t) => t instanceof ElementRef ? t.nativeElement : t;
|
|
4633
|
+
const prepare = (target, keyframes, opts) => {
|
|
4634
|
+
if (isMotionSignal(target)) {
|
|
4635
|
+
const sig = target;
|
|
4636
|
+
const write = writer(sig);
|
|
4637
|
+
return [
|
|
4638
|
+
Array.isArray(keyframes) ? keyframes : [sig.get(), keyframes],
|
|
4639
|
+
{
|
|
4640
|
+
...opts,
|
|
4641
|
+
onUpdate: (v) => {
|
|
4642
|
+
write(v);
|
|
4643
|
+
opts?.["onUpdate"]?.(v);
|
|
4644
|
+
}
|
|
4645
|
+
},
|
|
4646
|
+
void 0
|
|
4647
|
+
];
|
|
4648
|
+
}
|
|
4649
|
+
const el = element(target);
|
|
4650
|
+
let o = opts;
|
|
4651
|
+
if (motion.reducedMotion()) o = withoutMovement(keyframes, o);
|
|
4652
|
+
return [
|
|
4653
|
+
el,
|
|
4654
|
+
el instanceof Element ? withSvgPathContext(el, keyframes) : keyframes,
|
|
4655
|
+
o
|
|
4656
|
+
];
|
|
4657
|
+
};
|
|
4658
|
+
const animate = ((first, second, third) => {
|
|
4659
|
+
if (!browser) return done();
|
|
4660
|
+
let controls;
|
|
4661
|
+
if (Array.isArray(first) && first.some(Array.isArray)) {
|
|
4662
|
+
const steps = first.map((step) => {
|
|
4663
|
+
if (!Array.isArray(step)) return step;
|
|
4664
|
+
const [target, keyframes, opts] = step;
|
|
4665
|
+
if (isMotionSignal(target)) {
|
|
4666
|
+
const write = writer(target);
|
|
4667
|
+
const proxy = {
|
|
4668
|
+
get v() {
|
|
4669
|
+
return target.get();
|
|
4670
|
+
},
|
|
4671
|
+
set v(x) {
|
|
4672
|
+
write(x);
|
|
4673
|
+
}
|
|
4674
|
+
};
|
|
4675
|
+
const to = Array.isArray(keyframes) ? keyframes : [proxy.v, keyframes];
|
|
4676
|
+
return opts ? [
|
|
4677
|
+
proxy,
|
|
4678
|
+
{ v: to },
|
|
4679
|
+
opts
|
|
4680
|
+
] : [proxy, { v: to }];
|
|
4681
|
+
}
|
|
4682
|
+
const [t, k, o] = prepare(target, keyframes, opts);
|
|
4683
|
+
return o === void 0 ? [t, k] : [
|
|
4684
|
+
t,
|
|
4685
|
+
k,
|
|
4686
|
+
o
|
|
4687
|
+
];
|
|
4688
|
+
});
|
|
4689
|
+
controls = zone.runOutsideAngular(() => scoped(steps, second));
|
|
4690
|
+
} else if (isMotionSignal(first)) {
|
|
4691
|
+
const [values, opts] = prepare(first, second, third);
|
|
4692
|
+
controls = zone.runOutsideAngular(() => scoped(values[0], values, opts));
|
|
4693
|
+
} else {
|
|
4694
|
+
const [t, k, o] = prepare(first, second, third);
|
|
4695
|
+
controls = zone.runOutsideAngular(() => scoped(t, k, o));
|
|
4696
|
+
}
|
|
4697
|
+
running.add(controls);
|
|
4698
|
+
controls.finished.then(() => running.delete(controls), () => running.delete(controls));
|
|
4699
|
+
return controls;
|
|
4700
|
+
});
|
|
4701
|
+
animate.stop = () => {
|
|
4702
|
+
for (const c of running) c.stop();
|
|
4703
|
+
running.clear();
|
|
4704
|
+
};
|
|
4705
|
+
injector.get(DestroyRef).onDestroy(animate.stop);
|
|
4706
|
+
return animate;
|
|
4707
|
+
}
|
|
4708
|
+
function writer(sig) {
|
|
4709
|
+
return "jump" in sig ? (v) => sig.jump(v) : (v) => sig.set(v);
|
|
4710
|
+
}
|
|
4711
|
+
function done() {
|
|
4712
|
+
const finished = Promise.resolve();
|
|
4713
|
+
return {
|
|
4714
|
+
finished,
|
|
4715
|
+
time: 0,
|
|
4716
|
+
speed: 1,
|
|
4717
|
+
duration: 0,
|
|
4718
|
+
stop() {},
|
|
4719
|
+
cancel() {},
|
|
4720
|
+
complete() {},
|
|
4721
|
+
play() {},
|
|
4722
|
+
pause() {},
|
|
4723
|
+
then: (onFulfilled, onRejected) => finished.then(onFulfilled, onRejected)
|
|
4724
|
+
};
|
|
4725
|
+
}
|
|
4726
|
+
export { MOTION_CONFIG, MotionAnimationService, MotionDragDirective, MotionFollowPointerDirective, MotionIfDirective, MotionLayoutDirective, MotionLayoutRegistry, MotionMagneticDirective, MotionOneDirective, MotionOneService, MotionPanDirective, MotionPresenceDirective, MotionReorderGroupDirective, MotionReorderItemDirective, MotionScrollDirective, MotionStyleDirective, MotionTiltDirective, POINTER_SPRING, SCROLL_THROUGH, SCROLL_WHILE_VISIBLE, injectAnimate, isMotionSignal, isMovementKey, mapSignal, motionSignal, prefersReducedMotion, provideMotionConfig, scrollSignal, springSignal, stagger, velocitySignal, withoutMovement };
|
|
4480
4727
|
|
|
4481
4728
|
//# sourceMappingURL=hilux-ngx-motion.mjs.map
|