@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 +95 -2
- package/fesm2022/hilux-ngx-motion.mjs +293 -27
- package/fesm2022/hilux-ngx-motion.mjs.map +1 -1
- package/package.json +1 -1
- package/types/hilux-ngx-motion.d.ts +134 -6
package/package.json
CHANGED
|
@@ -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.
|
|
@@ -409,11 +412,12 @@ export declare class MotionOneDirective implements OnInit, OnDestroy, OnChanges,
|
|
|
409
412
|
damping?: number;
|
|
410
413
|
};
|
|
411
414
|
offset: string;
|
|
412
|
-
|
|
415
|
+
/** A style object, or a variant name: children with that variant animate too. */
|
|
416
|
+
whileHover: VariantWithTransition | string;
|
|
413
417
|
staggerChildren: number;
|
|
414
418
|
staggerDirection: number;
|
|
415
|
-
whileTap: VariantWithTransition;
|
|
416
|
-
whileFocus: VariantWithTransition;
|
|
419
|
+
whileTap: VariantWithTransition | string;
|
|
420
|
+
whileFocus: VariantWithTransition | string;
|
|
417
421
|
whileInView: VariantWithTransition;
|
|
418
422
|
runInView?: 'never' | 'once' | 'always';
|
|
419
423
|
variants: {
|
|
@@ -519,6 +523,38 @@ export declare class MotionOneDirective implements OnInit, OnDestroy, OnChanges,
|
|
|
519
523
|
*/
|
|
520
524
|
private syncGestureListeners;
|
|
521
525
|
private hasKeys;
|
|
526
|
+
/** Where this element rests when a gesture ends: its animate state, else its initial one. */
|
|
527
|
+
private restingState;
|
|
528
|
+
/** Values from before any gesture changed them, for keys the resting state doesn't set. */
|
|
529
|
+
private gestureBase;
|
|
530
|
+
/** Remember what a gesture is about to change, if nothing else says where it rests. */
|
|
531
|
+
private captureGestureBase;
|
|
532
|
+
/**
|
|
533
|
+
* Where to go when a gesture ends: the resting state, plus (as in Framer
|
|
534
|
+
* Motion) neutral transforms and the earlier values of any other style the
|
|
535
|
+
* gesture changed. Without this, an element with only whileHover stayed in
|
|
536
|
+
* its hover state.
|
|
537
|
+
*/
|
|
538
|
+
private restTarget;
|
|
539
|
+
/** Gestures in progress on this element. */
|
|
540
|
+
private readonly activeGestures;
|
|
541
|
+
/** The gesture that shows: tap over focus over hover, as in Framer Motion. */
|
|
542
|
+
private topGesture;
|
|
543
|
+
private asVariant;
|
|
544
|
+
/** Start a gesture; it only shows if no stronger gesture is on. */
|
|
545
|
+
private beginGesture;
|
|
546
|
+
/** End a gesture: fall back to one still on (hover under a released tap), else to rest. */
|
|
547
|
+
private endGesture;
|
|
548
|
+
/** A pending staggered start from a parent's gesture, cancelled if the gesture ends first. */
|
|
549
|
+
private gestureTimer;
|
|
550
|
+
/**
|
|
551
|
+
* Pass a gesture's variant name down the tree (Framer Motion's variant
|
|
552
|
+
* propagation): while the parent is hovered, tapped or focused, every
|
|
553
|
+
* descendant with a variant of that name animates to it, then returns to
|
|
554
|
+
* where it rests. The parent's variant transition can stagger them
|
|
555
|
+
* (staggerChildren, delayChildren, staggerDirection).
|
|
556
|
+
*/
|
|
557
|
+
private propagateGesture;
|
|
522
558
|
/**
|
|
523
559
|
* Cancel running animations before writing reset styles. Motion's stop()
|
|
524
560
|
* commits the current value on the next frame, which overwrote the reset
|
|
@@ -1671,4 +1707,96 @@ export declare class MotionStyleDirective {
|
|
|
1671
1707
|
};
|
|
1672
1708
|
}, {}, never, never, true, never>;
|
|
1673
1709
|
}
|
|
1674
|
-
|
|
1710
|
+
/** What injectAnimate resolves selectors in: an element, an ElementRef, or a function returning one (a viewChild). */
|
|
1711
|
+
export type AnimateScope = Element | ElementRef<Element> | (() => Element | ElementRef<Element> | null | undefined);
|
|
1712
|
+
/** The running animation: await it (or `.finished`), or stop, pause, play, complete it. */
|
|
1713
|
+
export interface AnimationControls extends PromiseLike<void> {
|
|
1714
|
+
readonly finished: Promise<unknown>;
|
|
1715
|
+
stop(): void;
|
|
1716
|
+
cancel(): void;
|
|
1717
|
+
complete(): void;
|
|
1718
|
+
play(): void;
|
|
1719
|
+
pause(): void;
|
|
1720
|
+
time: number;
|
|
1721
|
+
speed: number;
|
|
1722
|
+
readonly duration: number;
|
|
1723
|
+
}
|
|
1724
|
+
type Target = string | Element | Element[] | NodeListOf<Element> | ElementRef<Element>;
|
|
1725
|
+
type Keyframes = Record<string, unknown>;
|
|
1726
|
+
type Options = Record<string, unknown>;
|
|
1727
|
+
/** A step of a sequence: [target, keyframes, options?], [signal, to, options?] or a label. */
|
|
1728
|
+
export type SequenceStep = [Target | MotionSignal<number>, unknown, Options?] | string;
|
|
1729
|
+
/** A number signal it can animate: a motionSignal or springSignal (springs are moved frame by frame). */
|
|
1730
|
+
type NumberSignal = MotionSignal<number> & ({
|
|
1731
|
+
set(v: number): void;
|
|
1732
|
+
} | {
|
|
1733
|
+
jump(v: number): void;
|
|
1734
|
+
});
|
|
1735
|
+
export interface ScopedAnimate {
|
|
1736
|
+
/** Animate elements (or a CSS selector, looked up inside the scope). */
|
|
1737
|
+
(target: Target, keyframes: Keyframes, options?: Options): AnimationControls;
|
|
1738
|
+
/** Animate a number signal to a value (or through keyframes). */
|
|
1739
|
+
(signal: NumberSignal, to: number | number[], options?: Options): AnimationControls;
|
|
1740
|
+
/** Play a sequence: steps run one after another; `at` places a step on the timeline. */
|
|
1741
|
+
(sequence: SequenceStep[], options?: Options): AnimationControls;
|
|
1742
|
+
/** Stop everything started with this function. */
|
|
1743
|
+
stop(): void;
|
|
1744
|
+
}
|
|
1745
|
+
export interface InjectAnimateOptions {
|
|
1746
|
+
/** Where selectors are looked up. Defaults to the host element of the component or directive. */
|
|
1747
|
+
scope?: AnimateScope;
|
|
1748
|
+
injector?: Injector;
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Animate from code (Framer Motion's `useAnimate`), for animations a template
|
|
1752
|
+
* state doesn't express: after a request, in a sequence, from a service.
|
|
1753
|
+
*
|
|
1754
|
+
* private readonly animate = injectAnimate();
|
|
1755
|
+
*
|
|
1756
|
+
* async save() {
|
|
1757
|
+
* await this.animate('.card', { scale: 0.95 }, { duration: 0.1 });
|
|
1758
|
+
* await this.animate([
|
|
1759
|
+
* ['.card', { scale: 1 }, { type: 'spring', stiffness: 400 }],
|
|
1760
|
+
* ['.tick', { pathLength: [0, 1], opacity: 1 }, { at: '-0.1' }],
|
|
1761
|
+
* ['li', { opacity: [0, 1], y: [8, 0] }, { delay: stagger(0.05) }],
|
|
1762
|
+
* ]);
|
|
1763
|
+
* }
|
|
1764
|
+
*
|
|
1765
|
+
* - Selectors are looked up inside the host element (or `scope`), so they
|
|
1766
|
+
* never match another component's elements.
|
|
1767
|
+
* - Every animation it started is stopped when the component is destroyed.
|
|
1768
|
+
* - Runs outside Angular's change detection; does nothing on the server.
|
|
1769
|
+
* - With reduced motion, movement jumps to its end (see provideMotionConfig).
|
|
1770
|
+
* - Also animates number signals: `animate(this.count, 100)`.
|
|
1771
|
+
*
|
|
1772
|
+
* Call it in an injection context (a field or the constructor), or pass `injector`.
|
|
1773
|
+
*/
|
|
1774
|
+
export declare function injectAnimate(options?: InjectAnimateOptions): ScopedAnimate;
|
|
1775
|
+
export interface MotionConfig {
|
|
1776
|
+
/**
|
|
1777
|
+
* What to do when the user asks for reduced motion
|
|
1778
|
+
* (`prefers-reduced-motion: reduce`), like Framer Motion's
|
|
1779
|
+
* `<MotionConfig reducedMotion>`:
|
|
1780
|
+
* - 'user' (default): movement (position, scale, rotation, size) jumps
|
|
1781
|
+
* straight to its end; fades, colours and line drawing still play.
|
|
1782
|
+
* - 'always': the same, whatever the user's setting.
|
|
1783
|
+
* - 'never': everything animates.
|
|
1784
|
+
*/
|
|
1785
|
+
reducedMotion?: 'user' | 'always' | 'never';
|
|
1786
|
+
}
|
|
1787
|
+
export declare const MOTION_CONFIG: InjectionToken<MotionConfig>;
|
|
1788
|
+
/**
|
|
1789
|
+
* App-wide ngx-motion settings.
|
|
1790
|
+
*
|
|
1791
|
+
* bootstrapApplication(App, { providers: [provideMotionConfig({ reducedMotion: 'never' })] });
|
|
1792
|
+
*/
|
|
1793
|
+
export declare function provideMotionConfig(config: MotionConfig): Provider;
|
|
1794
|
+
export declare function isMovementKey(key: string): boolean;
|
|
1795
|
+
export declare function prefersReducedMotion(config: MotionConfig): boolean;
|
|
1796
|
+
/**
|
|
1797
|
+
* Animation options with every movement value in `keyframes` made instant
|
|
1798
|
+
* (Motion takes per-value transitions keyed by value name). Other values keep
|
|
1799
|
+
* their transition.
|
|
1800
|
+
*/
|
|
1801
|
+
export declare function withoutMovement(keyframes: unknown, options: Record<string, unknown> | undefined): Record<string, unknown> | undefined;
|
|
1802
|
+
export { type TimelineStep, type TransitionOptions, type VariantWithTransition, stagger };
|