@hilux/ngx-motion 2.5.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 CHANGED
@@ -55,6 +55,7 @@ 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.
58
59
  - **SVG line drawing:** `pathLength`, `pathOffset` and `pathSpacing` on any SVG shape, with every trigger (enter, hover, in view, scroll, `[motionStyle]`).
59
60
  - **Layout animations:** `motionLayout` glides elements to their new place and size after any layout change, and `motionLayoutId` makes shared-element transitions.
60
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.
@@ -63,6 +64,7 @@ export class CardComponent {}
63
64
  - **Transform shortcuts:** `x`, `y`, `scale`, `rotate` and `skew`, instead of transform strings.
64
65
  - **Repeat:** `repeat: Infinity` with `loop`, `reverse` or `mirror`.
65
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`.
66
68
  - **Performance:** animations, timers and listeners run outside Angular's change detection, and gesture listeners are only attached when used.
67
69
  - **SSR-safe:** animation code only runs in the browser.
68
70
  - **Typed:** full TypeScript types for states, transitions and variants.
@@ -449,6 +451,52 @@ Like Framer Motion's `layout` and `layoutId`. Change the layout however you like
449
451
  - Layout animations use the element's `transform`, so don't give it a CSS transform of its own; wrap it instead.
450
452
  - Interrupted animations continue from where the element is drawn. Resizing the window re-measures without animating, and with reduced motion nothing animates.
451
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
+
452
500
  ## Angular Control Flow Integration
453
501
 
454
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.
@@ -544,6 +592,8 @@ The directives work seamlessly with Angular's new control flow syntax:
544
592
  | `useMotionValue`, `useTransform`, `useSpring`, `useVelocity`, `useScroll` | `motionSignal`, `mapSignal`, `springSignal`, `velocitySignal`, `scrollSignal` |
545
593
  | `style={{ x, opacity }}` with motion values | `[motionStyle]="{ x: x, opacity: opacity }"` |
546
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) |
547
597
  | `layout`, `layout="position"` | `motionLayout`, `motionLayout="position"` |
548
598
  | `layoutId` | `motionLayoutId` |
549
599
  | `<LayoutGroup>` | not needed: every layout element is measured after every render |
@@ -570,13 +620,18 @@ A lot of animation is plain CSS now, and where CSS is enough it is the better ch
570
620
  | Drag to reorder | ❌ | Two-way bound order, keyboard moves, neighbours glide aside |
571
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 |
572
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 |
573
- | Reduced motion | ✅ `@media (prefers-reduced-motion)` | Respected by every directive automatically |
623
+ | Reduced motion | ✅ `@media (prefers-reduced-motion)` | Movement jumps to its end and fades still play, in every directive and `injectAnimate`; `provideMotionConfig` changes it |
574
624
  | Change detection and SSR | No JavaScript | Runs outside Angular's change detection; does nothing on the server |
575
625
 
576
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).
577
627
 
578
628
  ## Changelog
579
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
+
580
635
  **2.5.0**
581
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).
582
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.
@@ -699,6 +754,7 @@ interface TransitionOptions {
699
754
  - `'ease-out'` - CSS ease-out
700
755
  - `'ease-in-out'` - CSS ease-in-out
701
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
702
758
  - `(t) => number` - An easing function
703
759
  - `[0.4, 0, 0.2, 1]` - Custom cubic bezier
704
760
  - `{ type: 'spring', stiffness: 400, damping: 17 }` - Spring physics
@@ -731,6 +787,18 @@ No. Animations, timers and gesture listeners run outside Angular's zone.
731
787
  ### How do I animate a list as items are added and removed?
732
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).
733
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
+
734
802
  ### How do I animate on scroll?
735
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).
736
804
 
@@ -739,7 +807,9 @@ Add `runInView="once"` to play `animate` the first time the element scrolls into
739
807
  ```
740
808
  angular-motion-poc/
741
809
  ├── projects/ngx-motion/ # Library source (published as @hilux/ngx-motion)
742
- │ ├── 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
743
813
  │ ├── src/lib/services/ # Animation services
744
814
  │ └── src/public-api.ts # Library exports
745
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;
@@ -290,15 +290,50 @@ function withSvgPathContext(target, keyframes) {
290
290
  hold("pathOffset");
291
291
  return out;
292
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
+ }
293
323
  const noopControls = () => ({ stop: () => {} });
294
324
  const linear = (t) => t;
295
325
  var MotionAnimationService = class MotionAnimationService {
296
326
  platformId = inject(PLATFORM_ID);
297
327
  ngZone = inject(NgZone);
298
328
  isBrowser = isPlatformBrowser(this.platformId);
329
+ config = inject(MOTION_CONFIG);
330
+ reducedMotion() {
331
+ return this.isBrowser && prefersReducedMotion(this.config);
332
+ }
299
333
  animate(target, keyframes, options) {
300
334
  if (!this.isBrowser) return noopControls();
301
335
  try {
336
+ if (this.reducedMotion()) options = withoutMovement(keyframes, options);
302
337
  return this.ngZone.runOutsideAngular(() => animate(target, withSvgPathContext(target, keyframes), options));
303
338
  } catch (e) {
304
339
  console.error("[ngx-motion] Error in animate:", e);
@@ -321,7 +356,7 @@ var MotionAnimationService = class MotionAnimationService {
321
356
  stagger(duration, options) {
322
357
  if (!this.isBrowser) return 0;
323
358
  try {
324
- return stagger(duration, options);
359
+ return stagger$1(duration, options);
325
360
  } catch (e) {
326
361
  console.error("[ngx-motion] Error in stagger:", e);
327
362
  return 0;
@@ -379,6 +414,15 @@ const MOTION_EASINGS = /* @__PURE__ */ new Set([
379
414
  "backInOut",
380
415
  "anticipate"
381
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();
382
426
  function getEasing(easingString, motionAnimation) {
383
427
  if (!easingString) return motionAnimation.easeInOut;
384
428
  if (Array.isArray(easingString)) return easingString;
@@ -393,6 +437,11 @@ function getEasing(easingString, motionAnimation) {
393
437
  if (easingString === "ease-in-out" || easingString === "ease") return motionAnimation.easeInOut;
394
438
  if (easingString === "spring") return motionAnimation.spring();
395
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
+ }
396
445
  }
397
446
  return motionAnimation.easeInOut;
398
447
  }
@@ -2149,7 +2198,7 @@ var MotionScrollDirective = class MotionScrollDirective {
2149
2198
  this._progress.set(p);
2150
2199
  this._velocity.set(info?.[axis]?.velocity ?? 0);
2151
2200
  }, options));
2152
- const reduced = respect && typeof matchMedia !== "undefined" && matchMedia("(prefers-reduced-motion: reduce)").matches;
2201
+ const reduced = respect && this.motion.reducedMotion();
2153
2202
  if (keyframes && Object.keys(keyframes).length && !reduced) {
2154
2203
  const animation = this.motion.animate(this.el, keyframes, {
2155
2204
  ease: "linear",
@@ -2324,9 +2373,6 @@ const POINTER_SPRING = {
2324
2373
  damping: 20,
2325
2374
  mass: .6
2326
2375
  };
2327
- function reducedMotion() {
2328
- return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
2329
- }
2330
2376
  function listener() {
2331
2377
  const zone = inject(NgZone);
2332
2378
  const destroyRef = inject(DestroyRef);
@@ -2348,7 +2394,7 @@ var MotionMagneticDirective = class MotionMagneticDirective {
2348
2394
  const listen = listener();
2349
2395
  if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
2350
2396
  afterNextRender(() => {
2351
- if (reducedMotion()) return;
2397
+ if (motion.reducedMotion()) return;
2352
2398
  let x = 0, y = 0;
2353
2399
  listen(document, "pointermove", (e) => {
2354
2400
  if (e.pointerType !== "mouse") return;
@@ -2465,7 +2511,7 @@ var MotionTiltDirective = class MotionTiltDirective {
2465
2511
  const listen = listener();
2466
2512
  if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
2467
2513
  afterNextRender(() => {
2468
- const reduced = reducedMotion();
2514
+ const reduced = motion.reducedMotion();
2469
2515
  const max = () => this.motionTilt() === "" ? 10 : Number(this.motionTilt());
2470
2516
  listen(el, "pointermove", (e) => {
2471
2517
  if (e.pointerType === "touch") return;
@@ -2606,7 +2652,7 @@ var MotionFollowPointerDirective = class MotionFollowPointerDirective {
2606
2652
  const listen = listener();
2607
2653
  if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
2608
2654
  afterNextRender(() => {
2609
- const reduced = reducedMotion();
2655
+ const reduced = motion.reducedMotion();
2610
2656
  const mode = this.motionFollowPointer();
2611
2657
  const area = mode instanceof Element ? mode : mode === "window" ? null : el.parentElement;
2612
2658
  if (this.followHide()) motion.animate(el, {
@@ -3973,7 +4019,7 @@ var MotionLayoutDirective = class MotionLayoutDirective {
3973
4019
  resumeFrom;
3974
4020
  radii = null;
3975
4021
  inlineRadius = "";
3976
- reduced = typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
4022
+ reduced = inject(MotionAnimationService).reducedMotion();
3977
4023
  constructor() {
3978
4024
  const destroyRef = inject(DestroyRef);
3979
4025
  if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
@@ -4315,7 +4361,7 @@ function springSignal(source, options = {}) {
4315
4361
  const injector = injectorFor(springSignal, options);
4316
4362
  const zone = injector.get(NgZone);
4317
4363
  const browser = isPlatformBrowser(injector.get(PLATFORM_ID)) && typeof requestAnimationFrame !== "undefined";
4318
- const reduced = browser && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
4364
+ const reduced = browser && injector.get(MotionAnimationService).reducedMotion();
4319
4365
  const { stiffness = 300, damping = 30, mass = 1, restDelta = .01, restSpeed = .05 } = options;
4320
4366
  const start = typeof source === "number" ? source : isMotionSignal(source) ? source.get() : untracked(source);
4321
4367
  const value = motionSignal(start);
@@ -4565,6 +4611,118 @@ i0.ɵɵngDeclareClassMetadata({
4565
4611
  }]
4566
4612
  }] }
4567
4613
  });
4568
- export { MotionAnimationService, MotionDragDirective, MotionFollowPointerDirective, MotionIfDirective, MotionLayoutDirective, MotionLayoutRegistry, MotionMagneticDirective, MotionOneDirective, MotionOneService, MotionPanDirective, MotionPresenceDirective, MotionReorderGroupDirective, MotionReorderItemDirective, MotionScrollDirective, MotionStyleDirective, MotionTiltDirective, POINTER_SPRING, SCROLL_THROUGH, SCROLL_WHILE_VISIBLE, isMotionSignal, mapSignal, motionSignal, scrollSignal, springSignal, velocitySignal };
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 };
4569
4727
 
4570
4728
  //# sourceMappingURL=hilux-ngx-motion.mjs.map