@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/package.json CHANGED
@@ -52,5 +52,5 @@
52
52
  "default": "./package.json"
53
53
  }
54
54
  },
55
- "version": "2.4.0"
55
+ "version": "2.6.0"
56
56
  }
@@ -1,7 +1,7 @@
1
1
  import * as i0 from "@angular/core";
2
- import { AfterContentInit, ChangeDetectorRef, ElementRef, EventEmitter, Injector, NgZone, OnChanges, OnDestroy, OnInit, Signal, SimpleChanges, TemplateRef, ViewContainerRef, WritableSignal } from "@angular/core";
2
+ import { AfterContentInit, ChangeDetectorRef, ElementRef, EventEmitter, InjectionToken, Injector, NgZone, OnChanges, OnDestroy, OnInit, Provider, Signal, SimpleChanges, TemplateRef, ViewContainerRef, WritableSignal } from "@angular/core";
3
3
  import { Observable } from "rxjs";
4
- import { AnimationOptions } from "motion";
4
+ import { AnimationOptions, stagger } from "motion";
5
5
  export interface MotionElement {
6
6
  elementId: string;
7
7
  getDuration(): number;
@@ -122,6 +122,9 @@ export declare class MotionAnimationService {
122
122
  private readonly platformId;
123
123
  private readonly ngZone;
124
124
  private readonly isBrowser;
125
+ private readonly config;
126
+ /** True when animations should skip movement: the user asks for reduced motion (see provideMotionConfig). */
127
+ reducedMotion(): boolean;
125
128
  animate(target: any, keyframes: any, options?: any): any;
126
129
  /**
127
130
  * Observe when an element enters the viewport. Returns a stop function.
@@ -1648,6 +1651,8 @@ export type MotionStyleValue = MotionSignal<number | string> | (() => number | s
1648
1651
  * - Transform shortcuts: x, y, z (px), scale, scaleX, scaleY, rotate,
1649
1652
  * rotateX/Y/Z, skewX/Y (deg). They are combined into `transform`, so don't
1650
1653
  * animate the same element's transform another way.
1654
+ * - SVG line drawing: pathLength, pathOffset, pathSpacing (0 to 1), e.g.
1655
+ * `{ pathLength: scroll.progress }` draws a line as the page scrolls.
1651
1656
  * - Other styles take camelCase names; numbers get px except unitless ones
1652
1657
  * (opacity, zIndex, …). CSS custom properties (`'--progress'`) take any value.
1653
1658
  * - Values can be motion signals, plain Angular signals (updated with change
@@ -1669,4 +1674,96 @@ export declare class MotionStyleDirective {
1669
1674
  };
1670
1675
  }, {}, never, never, true, never>;
1671
1676
  }
1672
- export type { TimelineStep, TransitionOptions, VariantWithTransition };
1677
+ /** What injectAnimate resolves selectors in: an element, an ElementRef, or a function returning one (a viewChild). */
1678
+ export type AnimateScope = Element | ElementRef<Element> | (() => Element | ElementRef<Element> | null | undefined);
1679
+ /** The running animation: await it (or `.finished`), or stop, pause, play, complete it. */
1680
+ export interface AnimationControls extends PromiseLike<void> {
1681
+ readonly finished: Promise<unknown>;
1682
+ stop(): void;
1683
+ cancel(): void;
1684
+ complete(): void;
1685
+ play(): void;
1686
+ pause(): void;
1687
+ time: number;
1688
+ speed: number;
1689
+ readonly duration: number;
1690
+ }
1691
+ type Target = string | Element | Element[] | NodeListOf<Element> | ElementRef<Element>;
1692
+ type Keyframes = Record<string, unknown>;
1693
+ type Options = Record<string, unknown>;
1694
+ /** A step of a sequence: [target, keyframes, options?], [signal, to, options?] or a label. */
1695
+ export type SequenceStep = [Target | MotionSignal<number>, unknown, Options?] | string;
1696
+ /** A number signal it can animate: a motionSignal or springSignal (springs are moved frame by frame). */
1697
+ type NumberSignal = MotionSignal<number> & ({
1698
+ set(v: number): void;
1699
+ } | {
1700
+ jump(v: number): void;
1701
+ });
1702
+ export interface ScopedAnimate {
1703
+ /** Animate elements (or a CSS selector, looked up inside the scope). */
1704
+ (target: Target, keyframes: Keyframes, options?: Options): AnimationControls;
1705
+ /** Animate a number signal to a value (or through keyframes). */
1706
+ (signal: NumberSignal, to: number | number[], options?: Options): AnimationControls;
1707
+ /** Play a sequence: steps run one after another; `at` places a step on the timeline. */
1708
+ (sequence: SequenceStep[], options?: Options): AnimationControls;
1709
+ /** Stop everything started with this function. */
1710
+ stop(): void;
1711
+ }
1712
+ export interface InjectAnimateOptions {
1713
+ /** Where selectors are looked up. Defaults to the host element of the component or directive. */
1714
+ scope?: AnimateScope;
1715
+ injector?: Injector;
1716
+ }
1717
+ /**
1718
+ * Animate from code (Framer Motion's `useAnimate`), for animations a template
1719
+ * state doesn't express: after a request, in a sequence, from a service.
1720
+ *
1721
+ * private readonly animate = injectAnimate();
1722
+ *
1723
+ * async save() {
1724
+ * await this.animate('.card', { scale: 0.95 }, { duration: 0.1 });
1725
+ * await this.animate([
1726
+ * ['.card', { scale: 1 }, { type: 'spring', stiffness: 400 }],
1727
+ * ['.tick', { pathLength: [0, 1], opacity: 1 }, { at: '-0.1' }],
1728
+ * ['li', { opacity: [0, 1], y: [8, 0] }, { delay: stagger(0.05) }],
1729
+ * ]);
1730
+ * }
1731
+ *
1732
+ * - Selectors are looked up inside the host element (or `scope`), so they
1733
+ * never match another component's elements.
1734
+ * - Every animation it started is stopped when the component is destroyed.
1735
+ * - Runs outside Angular's change detection; does nothing on the server.
1736
+ * - With reduced motion, movement jumps to its end (see provideMotionConfig).
1737
+ * - Also animates number signals: `animate(this.count, 100)`.
1738
+ *
1739
+ * Call it in an injection context (a field or the constructor), or pass `injector`.
1740
+ */
1741
+ export declare function injectAnimate(options?: InjectAnimateOptions): ScopedAnimate;
1742
+ export interface MotionConfig {
1743
+ /**
1744
+ * What to do when the user asks for reduced motion
1745
+ * (`prefers-reduced-motion: reduce`), like Framer Motion's
1746
+ * `<MotionConfig reducedMotion>`:
1747
+ * - 'user' (default): movement (position, scale, rotation, size) jumps
1748
+ * straight to its end; fades, colours and line drawing still play.
1749
+ * - 'always': the same, whatever the user's setting.
1750
+ * - 'never': everything animates.
1751
+ */
1752
+ reducedMotion?: 'user' | 'always' | 'never';
1753
+ }
1754
+ export declare const MOTION_CONFIG: InjectionToken<MotionConfig>;
1755
+ /**
1756
+ * App-wide ngx-motion settings.
1757
+ *
1758
+ * bootstrapApplication(App, { providers: [provideMotionConfig({ reducedMotion: 'never' })] });
1759
+ */
1760
+ export declare function provideMotionConfig(config: MotionConfig): Provider;
1761
+ export declare function isMovementKey(key: string): boolean;
1762
+ export declare function prefersReducedMotion(config: MotionConfig): boolean;
1763
+ /**
1764
+ * Animation options with every movement value in `keyframes` made instant
1765
+ * (Motion takes per-value transitions keyed by value name). Other values keep
1766
+ * their transition.
1767
+ */
1768
+ export declare function withoutMovement(keyframes: unknown, options: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
1769
+ export { type TimelineStep, type TransitionOptions, type VariantWithTransition, stagger };