@hilux/ngx-motion 2.5.0 → 2.7.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.
@@ -154,6 +156,23 @@ export class VariantsExample {
154
156
  }
155
157
  ```
156
158
 
159
+ ### Gesture Variants
160
+ Give `whileHover`, `whileTap` or `whileFocus` a variant name instead of styles, and it passes down: while the parent is hovered, every motion child with a variant of that name animates to it (as in Framer Motion). One hover, many parts:
161
+
162
+ ```html
163
+ <a motionone whileHover="hover" whileTap="press"
164
+ [variants]="{ hover: { y: -4, transition: { staggerChildren: 0.04 } }, press: { scale: 0.97 } }">
165
+ <div motionone initial="rest" [variants]="{ rest: { rotate: 0 }, hover: { rotate: -15, scale: 1.1 } }">★</div>
166
+ <span motionone initial="rest" [variants]="{ rest: { scaleX: 0 }, hover: { scaleX: 1 } }"></span>
167
+ <span motionone initial="rest" [variants]="{ rest: { x: 0 }, hover: { x: 6 } }">→</span>
168
+ </a>
169
+ ```
170
+
171
+ - Children without that variant are left alone; grandchildren get it through their own parent.
172
+ - The parent's variant transition can stagger them: `staggerChildren`, `delayChildren`, `staggerDirection`.
173
+ - When the gesture ends, everything returns to its `animate` state, else its `initial` one. Values only a gesture sets return to neutral (`x: 0`, `scale: 1`…) or to what they were before.
174
+ - Gestures layer: tap over focus over hover. Release a press while still hovering and it goes back to the hover state.
175
+
157
176
  ### Conditional Animation with motionIf
158
177
  ```html
159
178
  <button (click)="isVisible = !isVisible">Toggle</button>
@@ -449,6 +468,52 @@ Like Framer Motion's `layout` and `layoutId`. Change the layout however you like
449
468
  - Layout animations use the element's `transform`, so don't give it a CSS transform of its own; wrap it instead.
450
469
  - Interrupted animations continue from where the element is drawn. Resizing the window re-measures without animating, and with reduced motion nothing animates.
451
470
 
471
+ ### Animate from Code
472
+ 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.
473
+
474
+ ```typescript
475
+ import { injectAnimate, stagger, motionSignal } from '@hilux/ngx-motion';
476
+
477
+ export class SendButton {
478
+ private readonly animate = injectAnimate();
479
+ readonly visits = motionSignal(0);
480
+
481
+ async send() {
482
+ // A sequence: each step starts when the one before ends; `at` moves it
483
+ await this.animate([
484
+ ['.button', { scale: 0.92 }, { duration: 0.12 }],
485
+ ['.button', { scale: 1 }, { duration: 0.3, ease: 'backOut' }],
486
+ ['.plane', { x: 140, y: -90, opacity: 0 }, { duration: 0.45, at: '-0.2' }],
487
+ ['.tick path', { pathLength: [0, 1] }, { duration: 0.3 }],
488
+ ]);
489
+ }
490
+
491
+ async load() {
492
+ // Staggered, and a number signal counting up to a result
493
+ this.animate('li', { opacity: [0, 1], y: [10, 0] }, { delay: stagger(0.04, { from: 'center' }) });
494
+ const total = await firstValueFrom(this.http.get<number>('/api/visits'));
495
+ await this.animate(this.visits, total, { duration: 1.2 });
496
+ }
497
+ }
498
+ ```
499
+
500
+ - `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.
501
+ - `animate(signal, to, options)`: a `motionSignal` or `springSignal`; bind it with `[motionStyle]` or read it in the template.
502
+ - `animate([...steps], options)`: a sequence. Steps can be elements or signals; `at` places a step (`'-0.2'`, `'<'`, a time or a label).
503
+ - It returns the running animation: `await` it, or call `stop()`, `pause()`, `play()`, `complete()`, and set `speed` or `time`.
504
+ - `animate.stop()` stops everything that function started. Everything is stopped when the component is destroyed.
505
+ - `stagger(each, { from, ease, startDelay })` is Motion's, re-exported.
506
+ - Runs outside change detection, does nothing on the server, and follows the reduced-motion setting.
507
+ - Call it in an injection context (a field or the constructor), or pass `{ injector }`.
508
+
509
+ ### Reduced Motion
510
+ 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.
511
+
512
+ ```typescript
513
+ // app.config.ts: 'user' (default), 'always' or 'never'
514
+ providers: [provideMotionConfig({ reducedMotion: 'never' })]
515
+ ```
516
+
452
517
  ## Angular Control Flow Integration
453
518
 
454
519
  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.
@@ -533,6 +598,7 @@ The directives work seamlessly with Angular's new control flow syntax:
533
598
  | `<motion.div>` | `<div motionone>` |
534
599
  | `initial` / `animate` / `exit` props | `[initial]` / `[animate]` / `[exit]` inputs |
535
600
  | `whileHover` / `whileTap` / `whileFocus` | `[whileHover]` / `[whileTap]` / `[whileFocus]` |
601
+ | `whileHover="hover"` passed down to children's `variants` | `whileHover="hover"` with `[variants]` on the children |
536
602
  | `whileInView`, `viewport={{ once: true }}` | `[whileInView]`, `runInView="once"` |
537
603
  | `variants` + `staggerChildren` | `[variants]` + `[transition]="{ staggerChildren }"` |
538
604
  | `transition={{ type: 'spring' }}` | `[transition]="{ type: 'spring' }"` |
@@ -544,6 +610,8 @@ The directives work seamlessly with Angular's new control flow syntax:
544
610
  | `useMotionValue`, `useTransform`, `useSpring`, `useVelocity`, `useScroll` | `motionSignal`, `mapSignal`, `springSignal`, `velocitySignal`, `scrollSignal` |
545
611
  | `style={{ x, opacity }}` with motion values | `[motionStyle]="{ x: x, opacity: opacity }"` |
546
612
  | `pathLength`, `pathOffset`, `pathSpacing` | the same keys in `[initial]`, `[animate]`, `[whileHover]`, `[motionScroll]`, `[motionStyle]` |
613
+ | `useAnimate`, `animate(sequence)`, `stagger()` | `injectAnimate()`, `animate(sequence)`, `stagger()` |
614
+ | `<MotionConfig reducedMotion="user">` | `provideMotionConfig({ reducedMotion: 'user' })` (the default) |
547
615
  | `layout`, `layout="position"` | `motionLayout`, `motionLayout="position"` |
548
616
  | `layoutId` | `motionLayoutId` |
549
617
  | `<LayoutGroup>` | not needed: every layout element is measured after every render |
@@ -570,13 +638,23 @@ A lot of animation is plain CSS now, and where CSS is enough it is the better ch
570
638
  | Drag to reorder | ❌ | Two-way bound order, keyboard moves, neighbours glide aside |
571
639
  | 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
640
  | 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 |
641
+ | Reduced motion | ✅ `@media (prefers-reduced-motion)` | Movement jumps to its end and fades still play, in every directive and `injectAnimate`; `provideMotionConfig` changes it |
574
642
  | Change detection and SSR | No JavaScript | Runs outside Angular's change detection; does nothing on the server |
575
643
 
576
644
  **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
645
 
578
646
  ## Changelog
579
647
 
648
+ **2.7.0**
649
+ - Gesture variants: `whileHover`, `whileTap` and `whileFocus` take a variant name that passes down to children with that variant, with `staggerChildren` / `delayChildren` from the parent's variant. See [Gesture Variants](#gesture-variants).
650
+ - Gestures layer like Framer Motion's: tap over focus over hover. Releasing a press while hovering goes back to the hover state, not to rest.
651
+ - Fixed: an element with only `whileHover` (or tap or focus) and no `initial` or `animate` stayed in its gesture state after the gesture ended. Its values now return to neutral (`x: 0`, `scale: 1`…) or to what they were before.
652
+
653
+ **2.6.0**
654
+ - `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).
655
+ - 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).
656
+ - 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).
657
+
580
658
  **2.5.0**
581
659
  - 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
660
  - 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 +777,7 @@ interface TransitionOptions {
699
777
  - `'ease-out'` - CSS ease-out
700
778
  - `'ease-in-out'` - CSS ease-in-out
701
779
  - `'linear'`, `'easeIn'`, `'easeOut'`, `'easeInOut'`, `'circIn'`, `'circOut'`, `'circInOut'`, `'backIn'`, `'backOut'`, `'backInOut'`, `'anticipate'` - Motion's named easings
780
+ - `'easeInCirc'`, `'easeOutCirc'`, `'easeInOutCirc'`, `'easeInBack'`, `'easeOutBack'`, `'easeInOutBack'` - Aliases for Motion's `circIn`, `backOut` and so on
702
781
  - `(t) => number` - An easing function
703
782
  - `[0.4, 0, 0.2, 1]` - Custom cubic bezier
704
783
  - `{ type: 'spring', stiffness: 400, damping: 17 }` - Spring physics
@@ -731,6 +810,18 @@ No. Animations, timers and gesture listeners run outside Angular's zone.
731
810
  ### How do I animate a list as items are added and removed?
732
811
  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
812
 
813
+ ### Can I start animations from TypeScript?
814
+ 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).
815
+
816
+ ### How does it handle reduced motion?
817
+ 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).
818
+
819
+ ### Can animated values be Angular signals?
820
+ 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).
821
+
822
+ ### Can it draw SVG lines?
823
+ 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).
824
+
734
825
  ### How do I animate on scroll?
735
826
  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
827
 
@@ -739,7 +830,9 @@ Add `runInView="once"` to play `animate` the first time the element scrolls into
739
830
  ```
740
831
  angular-motion-poc/
741
832
  ├── projects/ngx-motion/ # Library source (published as @hilux/ngx-motion)
742
- │ ├── src/lib/directives/ # motionone, *motionIf, *motionPresence
833
+ │ ├── src/lib/directives/ # motionone, *motionIf, *motionPresence, drag, pan, layout…
834
+ │ ├── src/lib/values/ # Motion values as signals
835
+ │ ├── src/lib/animate/ # injectAnimate
743
836
  │ ├── src/lib/services/ # Animation services
744
837
  │ └── src/public-api.ts # Library exports
745
838
  ├── 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
  }
@@ -1029,6 +1078,21 @@ function nearestMotionAncestor(el, stop) {
1029
1078
  if (found) return found;
1030
1079
  }
1031
1080
  }
1081
+ const NEUTRAL_TRANSFORMS = {
1082
+ x: 0,
1083
+ y: 0,
1084
+ z: 0,
1085
+ scale: 1,
1086
+ scaleX: 1,
1087
+ scaleY: 1,
1088
+ rotate: 0,
1089
+ rotateX: 0,
1090
+ rotateY: 0,
1091
+ rotateZ: 0,
1092
+ skew: 0,
1093
+ skewX: 0,
1094
+ skewY: 0
1095
+ };
1032
1096
  var MotionOneDirective = class MotionOneDirective {
1033
1097
  el;
1034
1098
  motionService;
@@ -1413,8 +1477,104 @@ var MotionOneDirective = class MotionOneDirective {
1413
1477
  }
1414
1478
  }
1415
1479
  hasKeys(value) {
1480
+ if (typeof value === "string") return value.length > 0;
1416
1481
  return !!value && typeof value === "object" && Object.keys(value).length > 0;
1417
1482
  }
1483
+ restingState() {
1484
+ return this.hasKeys(this.animate) ? this.animate : this.initial;
1485
+ }
1486
+ gestureBase = {};
1487
+ captureGestureBase(gesture) {
1488
+ if (!isPlatformBrowser(this.platformId)) return;
1489
+ const rest = resolveVariant(this.restingState(), this.variants);
1490
+ const style = getComputedStyle(this.el.nativeElement);
1491
+ for (const key of Object.keys(extractStyleProperties(resolveVariant(gesture, this.variants)))) {
1492
+ if (key in rest || key in this.gestureBase || key in NEUTRAL_TRANSFORMS) continue;
1493
+ this.gestureBase[key] = style.getPropertyValue(key.replace(/[A-Z]/g, (c) => "-" + c.toLowerCase())) || style[key];
1494
+ }
1495
+ }
1496
+ restTarget(gesture) {
1497
+ const rest = this.restingState();
1498
+ const resolved = resolveVariant(rest, this.variants);
1499
+ const missing = Object.keys(extractStyleProperties(resolveVariant(gesture, this.variants))).filter((k) => !(k in resolved));
1500
+ if (!missing.length) return rest;
1501
+ const out = { ...resolved };
1502
+ for (const key of missing) {
1503
+ const value = key in NEUTRAL_TRANSFORMS ? NEUTRAL_TRANSFORMS[key] : this.gestureBase[key];
1504
+ if (value !== void 0 && value !== "") out[key] = value;
1505
+ }
1506
+ return out;
1507
+ }
1508
+ activeGestures = /* @__PURE__ */ new Set();
1509
+ topGesture() {
1510
+ const top = [
1511
+ ["tap", this.whileTap],
1512
+ ["focus", this.whileFocus],
1513
+ ["hover", this.whileHover]
1514
+ ].find(([type, value]) => this.activeGestures.has(type) && this.hasKeys(value));
1515
+ return top && {
1516
+ type: top[0],
1517
+ value: top[1]
1518
+ };
1519
+ }
1520
+ asVariant(v) {
1521
+ return resolveVariant(v, this.variants);
1522
+ }
1523
+ beginGesture(type, value) {
1524
+ this.activeGestures.add(type);
1525
+ if (this.topGesture()?.type !== type) return;
1526
+ this.captureGestureBase(value);
1527
+ this.playAnimationToTarget(value, type);
1528
+ this.propagateGesture(value, true);
1529
+ }
1530
+ endGesture(type, value) {
1531
+ const wasTop = this.topGesture()?.type === type;
1532
+ this.activeGestures.delete(type);
1533
+ if (!wasTop) return;
1534
+ const next = this.topGesture();
1535
+ if (!next) {
1536
+ this.playAnimationToTarget(this.restTarget(value));
1537
+ this.propagateGesture(value, false);
1538
+ return;
1539
+ }
1540
+ this.playAnimationToTarget({
1541
+ ...this.asVariant(this.restTarget(value)),
1542
+ ...this.asVariant(next.value)
1543
+ }, next.type);
1544
+ if (typeof next.value === "string") this.propagateGesture(next.value, true, value);
1545
+ else this.propagateGesture(value, false);
1546
+ }
1547
+ gestureTimer;
1548
+ propagateGesture(label, active, ended) {
1549
+ if (typeof label !== "string" || !label) return;
1550
+ const transition = resolveVariant(label, this.variants)?.transition ?? {};
1551
+ const each = active && !ended ? transition["staggerChildren"] ?? 0 : 0;
1552
+ const first = active && !ended ? transition["delayChildren"] ?? 0 : 0;
1553
+ const children = this.motionChildren;
1554
+ const reversed = (transition["staggerDirection"] ?? 1) < 0;
1555
+ children.forEach((child, i) => {
1556
+ const slot = reversed ? children.length - 1 - i : i;
1557
+ const run = () => {
1558
+ child.gestureTimer = void 0;
1559
+ const endedHere = typeof ended === "string" && !!child.variants?.[ended];
1560
+ if (child.variants?.[label]) {
1561
+ if (active) child.captureGestureBase(label);
1562
+ if (!active) child.playAnimationToTarget(child.restTarget(label));
1563
+ else if (endedHere) child.playAnimationToTarget({
1564
+ ...child.asVariant(child.restTarget(ended)),
1565
+ ...child.getVariant(label)
1566
+ });
1567
+ else child.playAnimationToTarget(label);
1568
+ } else if (active && endedHere) child.playAnimationToTarget(child.restTarget(ended));
1569
+ child.propagateGesture(label, active, ended);
1570
+ };
1571
+ child.cancelScheduled(child.gestureTimer);
1572
+ child.gestureTimer = void 0;
1573
+ const delay = first + slot * each;
1574
+ if (delay > 0) child.gestureTimer = child.schedule(run, delay * 1e3);
1575
+ else run();
1576
+ });
1577
+ }
1418
1578
  cancelForReset() {
1419
1579
  const cancel = (c) => {
1420
1580
  if (!c) return;
@@ -1449,36 +1609,34 @@ var MotionOneDirective = class MotionOneDirective {
1449
1609
  elements.forEach((el) => el.style.transition = "");
1450
1610
  }
1451
1611
  onMouseEnter() {
1452
- if (Object.keys(this.whileHover).length > 0) {
1612
+ if (this.hasKeys(this.whileHover)) {
1453
1613
  clearTimeout(this.hoverTimeout);
1454
1614
  if (!this.gestureService.shouldAllowGesture(this.elementId, "hover")) return;
1455
1615
  this.gestureService.cancelGesture(this.elementId);
1456
- this.playAnimationToTarget(this.whileHover, "hover");
1616
+ this.beginGesture("hover", this.whileHover);
1457
1617
  }
1458
1618
  }
1459
1619
  onMouseLeave() {
1460
- if (Object.keys(this.whileHover).length > 0) {
1620
+ if (this.hasKeys(this.whileHover)) {
1461
1621
  clearTimeout(this.hoverTimeout);
1462
1622
  this.gestureService.cancelGesture(this.elementId);
1463
1623
  this.hoverTimeout = this.ngZone.runOutsideAngular(() => setTimeout(() => {
1464
- if (Object.keys(this.animate).length > 0) this.playAnimationToTarget(this.animate);
1465
- else this.playAnimationToTarget(this.initial);
1624
+ this.endGesture("hover", this.whileHover);
1466
1625
  }, 100));
1467
1626
  }
1468
1627
  }
1469
1628
  onPress(event) {
1470
- if (Object.keys(this.whileTap).length > 0) {
1629
+ if (this.hasKeys(this.whileTap)) {
1471
1630
  if (!this.gestureService.shouldAllowGesture(this.elementId, "tap")) return;
1472
1631
  this.gestureService.cancelGesture(this.elementId);
1473
- this.playAnimationToTarget(this.whileTap, "tap");
1632
+ this.beginGesture("tap", this.whileTap);
1474
1633
  if (isPlatformBrowser(this.platformId)) {
1475
1634
  const endEvent = event.type === "mousedown" ? "mouseup" : "touchend";
1476
1635
  this.pressEndCleanup?.();
1477
1636
  const endListener = () => {
1478
1637
  this.pressEndCleanup = null;
1479
1638
  this.gestureService.cancelGesture(this.elementId);
1480
- if (Object.keys(this.animate).length > 0) this.playAnimationToTarget(this.animate);
1481
- else this.playAnimationToTarget(this.initial);
1639
+ this.endGesture("tap", this.whileTap);
1482
1640
  window.removeEventListener(endEvent, endListener);
1483
1641
  };
1484
1642
  this.ngZone.runOutsideAngular(() => window.addEventListener(endEvent, endListener));
@@ -1487,17 +1645,16 @@ var MotionOneDirective = class MotionOneDirective {
1487
1645
  }
1488
1646
  }
1489
1647
  onFocus() {
1490
- if (Object.keys(this.whileFocus).length > 0) {
1648
+ if (this.hasKeys(this.whileFocus)) {
1491
1649
  if (!this.gestureService.shouldAllowGesture(this.elementId, "focus")) return;
1492
1650
  this.gestureService.cancelGesture(this.elementId);
1493
- this.playAnimationToTarget(this.whileFocus, "focus");
1651
+ this.beginGesture("focus", this.whileFocus);
1494
1652
  }
1495
1653
  }
1496
1654
  onBlur() {
1497
- if (Object.keys(this.whileFocus).length > 0) {
1655
+ if (this.hasKeys(this.whileFocus)) {
1498
1656
  this.gestureService.cancelGesture(this.elementId);
1499
- if (Object.keys(this.animate).length > 0) this.playAnimationToTarget(this.animate);
1500
- else this.playAnimationToTarget(this.initial);
1657
+ this.endGesture("focus", this.whileFocus);
1501
1658
  }
1502
1659
  }
1503
1660
  applyInitialValues() {
@@ -2149,7 +2306,7 @@ var MotionScrollDirective = class MotionScrollDirective {
2149
2306
  this._progress.set(p);
2150
2307
  this._velocity.set(info?.[axis]?.velocity ?? 0);
2151
2308
  }, options));
2152
- const reduced = respect && typeof matchMedia !== "undefined" && matchMedia("(prefers-reduced-motion: reduce)").matches;
2309
+ const reduced = respect && this.motion.reducedMotion();
2153
2310
  if (keyframes && Object.keys(keyframes).length && !reduced) {
2154
2311
  const animation = this.motion.animate(this.el, keyframes, {
2155
2312
  ease: "linear",
@@ -2324,9 +2481,6 @@ const POINTER_SPRING = {
2324
2481
  damping: 20,
2325
2482
  mass: .6
2326
2483
  };
2327
- function reducedMotion() {
2328
- return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
2329
- }
2330
2484
  function listener() {
2331
2485
  const zone = inject(NgZone);
2332
2486
  const destroyRef = inject(DestroyRef);
@@ -2348,7 +2502,7 @@ var MotionMagneticDirective = class MotionMagneticDirective {
2348
2502
  const listen = listener();
2349
2503
  if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
2350
2504
  afterNextRender(() => {
2351
- if (reducedMotion()) return;
2505
+ if (motion.reducedMotion()) return;
2352
2506
  let x = 0, y = 0;
2353
2507
  listen(document, "pointermove", (e) => {
2354
2508
  if (e.pointerType !== "mouse") return;
@@ -2465,7 +2619,7 @@ var MotionTiltDirective = class MotionTiltDirective {
2465
2619
  const listen = listener();
2466
2620
  if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
2467
2621
  afterNextRender(() => {
2468
- const reduced = reducedMotion();
2622
+ const reduced = motion.reducedMotion();
2469
2623
  const max = () => this.motionTilt() === "" ? 10 : Number(this.motionTilt());
2470
2624
  listen(el, "pointermove", (e) => {
2471
2625
  if (e.pointerType === "touch") return;
@@ -2606,7 +2760,7 @@ var MotionFollowPointerDirective = class MotionFollowPointerDirective {
2606
2760
  const listen = listener();
2607
2761
  if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
2608
2762
  afterNextRender(() => {
2609
- const reduced = reducedMotion();
2763
+ const reduced = motion.reducedMotion();
2610
2764
  const mode = this.motionFollowPointer();
2611
2765
  const area = mode instanceof Element ? mode : mode === "window" ? null : el.parentElement;
2612
2766
  if (this.followHide()) motion.animate(el, {
@@ -3973,7 +4127,7 @@ var MotionLayoutDirective = class MotionLayoutDirective {
3973
4127
  resumeFrom;
3974
4128
  radii = null;
3975
4129
  inlineRadius = "";
3976
- reduced = typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
4130
+ reduced = inject(MotionAnimationService).reducedMotion();
3977
4131
  constructor() {
3978
4132
  const destroyRef = inject(DestroyRef);
3979
4133
  if (!isPlatformBrowser(inject(PLATFORM_ID))) return;
@@ -4315,7 +4469,7 @@ function springSignal(source, options = {}) {
4315
4469
  const injector = injectorFor(springSignal, options);
4316
4470
  const zone = injector.get(NgZone);
4317
4471
  const browser = isPlatformBrowser(injector.get(PLATFORM_ID)) && typeof requestAnimationFrame !== "undefined";
4318
- const reduced = browser && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
4472
+ const reduced = browser && injector.get(MotionAnimationService).reducedMotion();
4319
4473
  const { stiffness = 300, damping = 30, mass = 1, restDelta = .01, restSpeed = .05 } = options;
4320
4474
  const start = typeof source === "number" ? source : isMotionSignal(source) ? source.get() : untracked(source);
4321
4475
  const value = motionSignal(start);
@@ -4565,6 +4719,118 @@ i0.ɵɵngDeclareClassMetadata({
4565
4719
  }]
4566
4720
  }] }
4567
4721
  });
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 };
4722
+ function injectAnimate(options = {}) {
4723
+ if (!options.injector) assertInInjectionContext(injectAnimate);
4724
+ const injector = options.injector ?? inject(Injector);
4725
+ const motion = injector.get(MotionAnimationService);
4726
+ const zone = injector.get(NgZone);
4727
+ const browser = isPlatformBrowser(injector.get(PLATFORM_ID));
4728
+ const host = injector.get(ElementRef, null);
4729
+ const resolve = (s) => {
4730
+ const v = typeof s === "function" ? s() : s;
4731
+ return v instanceof ElementRef ? v.nativeElement : v ?? void 0;
4732
+ };
4733
+ const scoped = createScopedAnimate({
4734
+ get current() {
4735
+ return resolve(options.scope) ?? host?.nativeElement;
4736
+ },
4737
+ animations: []
4738
+ });
4739
+ const running = /* @__PURE__ */ new Set();
4740
+ const element = (t) => t instanceof ElementRef ? t.nativeElement : t;
4741
+ const prepare = (target, keyframes, opts) => {
4742
+ if (isMotionSignal(target)) {
4743
+ const sig = target;
4744
+ const write = writer(sig);
4745
+ return [
4746
+ Array.isArray(keyframes) ? keyframes : [sig.get(), keyframes],
4747
+ {
4748
+ ...opts,
4749
+ onUpdate: (v) => {
4750
+ write(v);
4751
+ opts?.["onUpdate"]?.(v);
4752
+ }
4753
+ },
4754
+ void 0
4755
+ ];
4756
+ }
4757
+ const el = element(target);
4758
+ let o = opts;
4759
+ if (motion.reducedMotion()) o = withoutMovement(keyframes, o);
4760
+ return [
4761
+ el,
4762
+ el instanceof Element ? withSvgPathContext(el, keyframes) : keyframes,
4763
+ o
4764
+ ];
4765
+ };
4766
+ const animate = ((first, second, third) => {
4767
+ if (!browser) return done();
4768
+ let controls;
4769
+ if (Array.isArray(first) && first.some(Array.isArray)) {
4770
+ const steps = first.map((step) => {
4771
+ if (!Array.isArray(step)) return step;
4772
+ const [target, keyframes, opts] = step;
4773
+ if (isMotionSignal(target)) {
4774
+ const write = writer(target);
4775
+ const proxy = {
4776
+ get v() {
4777
+ return target.get();
4778
+ },
4779
+ set v(x) {
4780
+ write(x);
4781
+ }
4782
+ };
4783
+ const to = Array.isArray(keyframes) ? keyframes : [proxy.v, keyframes];
4784
+ return opts ? [
4785
+ proxy,
4786
+ { v: to },
4787
+ opts
4788
+ ] : [proxy, { v: to }];
4789
+ }
4790
+ const [t, k, o] = prepare(target, keyframes, opts);
4791
+ return o === void 0 ? [t, k] : [
4792
+ t,
4793
+ k,
4794
+ o
4795
+ ];
4796
+ });
4797
+ controls = zone.runOutsideAngular(() => scoped(steps, second));
4798
+ } else if (isMotionSignal(first)) {
4799
+ const [values, opts] = prepare(first, second, third);
4800
+ controls = zone.runOutsideAngular(() => scoped(values[0], values, opts));
4801
+ } else {
4802
+ const [t, k, o] = prepare(first, second, third);
4803
+ controls = zone.runOutsideAngular(() => scoped(t, k, o));
4804
+ }
4805
+ running.add(controls);
4806
+ controls.finished.then(() => running.delete(controls), () => running.delete(controls));
4807
+ return controls;
4808
+ });
4809
+ animate.stop = () => {
4810
+ for (const c of running) c.stop();
4811
+ running.clear();
4812
+ };
4813
+ injector.get(DestroyRef).onDestroy(animate.stop);
4814
+ return animate;
4815
+ }
4816
+ function writer(sig) {
4817
+ return "jump" in sig ? (v) => sig.jump(v) : (v) => sig.set(v);
4818
+ }
4819
+ function done() {
4820
+ const finished = Promise.resolve();
4821
+ return {
4822
+ finished,
4823
+ time: 0,
4824
+ speed: 1,
4825
+ duration: 0,
4826
+ stop() {},
4827
+ cancel() {},
4828
+ complete() {},
4829
+ play() {},
4830
+ pause() {},
4831
+ then: (onFulfilled, onRejected) => finished.then(onFulfilled, onRejected)
4832
+ };
4833
+ }
4834
+ 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
4835
 
4570
4836
  //# sourceMappingURL=hilux-ngx-motion.mjs.map