motion-dom 12.4.11 → 12.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/dist/index.d.ts CHANGED
@@ -581,6 +581,63 @@ declare function mapEasingToNativeEasing(easing: Easing | Easing[] | undefined,
581
581
 
582
582
  declare const generateLinearEasing: (easing: EasingFunction, duration: number, resolution?: number) => string;
583
583
 
584
+ declare const frame: Batcher;
585
+ declare const cancelFrame: (process: Process) => void;
586
+ declare const frameData: FrameData;
587
+ declare const frameSteps: Steps;
588
+
589
+ type Process = (data: FrameData) => void;
590
+ type Schedule = (process: Process, keepAlive?: boolean, immediate?: boolean) => Process;
591
+ interface Step {
592
+ schedule: Schedule;
593
+ cancel: (process: Process) => void;
594
+ process: (data: FrameData) => void;
595
+ }
596
+ type StepId = "read" | "resolveKeyframes" | "update" | "preRender" | "render" | "postRender";
597
+ type CancelProcess = (process: Process) => void;
598
+ type Batcher = {
599
+ [key in StepId]: Schedule;
600
+ };
601
+ type Steps = {
602
+ [key in StepId]: Step;
603
+ };
604
+ interface FrameData {
605
+ delta: number;
606
+ timestamp: number;
607
+ isProcessing: boolean;
608
+ }
609
+
610
+ declare function createRenderBatcher(scheduleNextBatch: (callback: Function) => void, allowKeepAlive: boolean): {
611
+ schedule: Batcher;
612
+ cancel: (process: Process) => void;
613
+ state: FrameData;
614
+ steps: Steps;
615
+ };
616
+
617
+ declare const microtask: Batcher;
618
+ declare const cancelMicrotask: (process: Process) => void;
619
+
620
+ /**
621
+ * An eventloop-synchronous alternative to performance.now().
622
+ *
623
+ * Ensures that time measurements remain consistent within a synchronous context.
624
+ * Usually calling performance.now() twice within the same synchronous context
625
+ * will return different values which isn't useful for animations when we're usually
626
+ * trying to sync animations to the same frame.
627
+ */
628
+ declare const time: {
629
+ now: () => number;
630
+ set: (newTime: number) => void;
631
+ };
632
+
633
+ declare const isDragging: {
634
+ x: boolean;
635
+ y: boolean;
636
+ };
637
+ declare function isDragActive(): boolean;
638
+
639
+ declare function setDragLock(axis: boolean | "x" | "y" | "lockDirection"): (() => void) | null;
640
+
584
641
  type ElementOrSelector = Element | Element[] | NodeListOf<Element> | string;
585
642
  interface WithQuerySelectorAll {
586
643
  querySelectorAll: Element["querySelectorAll"];
@@ -671,6 +728,69 @@ declare function press(targetOrSelector: ElementOrSelector, onPressStart: OnPres
671
728
 
672
729
  declare function capturePointer(event: PointerEvent, action: "set" | "release"): void;
673
730
 
731
+ /**
732
+ * Recursively traverse up the tree to check whether the provided child node
733
+ * is the parent or a descendant of it.
734
+ *
735
+ * @param parent - Element to find
736
+ * @param child - Element to test against parent
737
+ */
738
+ declare const isNodeOrChild: (parent: Element | null, child?: Element | null) => boolean;
739
+
740
+ declare const isPrimaryPointer: (event: PointerEvent) => boolean;
741
+
742
+ declare const stepsOrder: StepId[];
743
+ type StepNames = (typeof stepsOrder)[number];
744
+
745
+ interface Summary {
746
+ min: number;
747
+ max: number;
748
+ avg: number;
749
+ }
750
+ type FrameloopStatNames = "rate" | StepNames;
751
+ interface Stats<T> {
752
+ frameloop: {
753
+ [key in FrameloopStatNames]: T;
754
+ };
755
+ animations: {
756
+ mainThread: T;
757
+ waapi: T;
758
+ layout: T;
759
+ };
760
+ layoutProjection: {
761
+ nodes: T;
762
+ calculatedTargetDeltas: T;
763
+ calculatedProjections: T;
764
+ };
765
+ }
766
+ type StatsBuffer = number[];
767
+ type FrameStats = Stats<number>;
768
+ type StatsRecording = Stats<StatsBuffer>;
769
+ type StatsSummary = Stats<Summary>;
770
+
771
+ declare function reportStats(): StatsSummary;
772
+ declare function recordStats(): typeof reportStats;
773
+
774
+ declare const activeAnimations: {
775
+ layout: number;
776
+ mainThread: number;
777
+ waapi: number;
778
+ };
779
+
780
+ type InactiveStatsBuffer = {
781
+ value: null;
782
+ addProjectionMetrics: null;
783
+ };
784
+ type ActiveStatsBuffer = {
785
+ value: StatsRecording;
786
+ addProjectionMetrics: (metrics: {
787
+ nodes: number;
788
+ calculatedTargetDeltas: number;
789
+ calculatedProjections: number;
790
+ }) => void;
791
+ };
792
+ declare const statsBuffer: InactiveStatsBuffer | ActiveStatsBuffer;
793
+
674
794
  declare const isBezierDefinition: (easing: Easing | Easing[]) => easing is BezierDefinition;
675
795
 
676
796
  /**
@@ -695,6 +815,225 @@ declare class ScrollTimeline implements ProgressTimeline {
695
815
  }
696
816
  declare const supportsScrollTimeline: () => boolean;
697
817
 
818
+ type Transformer<T> = (v: T) => T;
819
+ /**
820
+ * @public
821
+ */
822
+ type Subscriber<T> = (v: T) => void;
823
+ /**
824
+ * @public
825
+ */
826
+ type PassiveEffect<T> = (v: T, safeSetter: (v: T) => void) => void;
827
+ type StartAnimation = (complete: () => void) => AnimationPlaybackControls | undefined;
828
+ interface MotionValueEventCallbacks<V> {
829
+ animationStart: () => void;
830
+ animationComplete: () => void;
831
+ animationCancel: () => void;
832
+ change: (latestValue: V) => void;
833
+ renderRequest: () => void;
834
+ }
835
+ interface ResolvedValues {
836
+ [key: string]: string | number;
837
+ }
838
+ interface Owner {
839
+ current: HTMLElement | unknown;
840
+ getProps: () => {
841
+ onUpdate?: (latest: ResolvedValues) => void;
842
+ transformTemplate?: (transform: TransformProperties, generatedTransform: string) => string;
843
+ };
844
+ }
845
+ interface MotionValueOptions {
846
+ owner?: Owner;
847
+ }
848
+ declare const collectMotionValues: {
849
+ current: MotionValue[] | undefined;
850
+ };
851
+ /**
852
+ * `MotionValue` is used to track the state and velocity of motion values.
853
+ *
854
+ * @public
855
+ */
856
+ declare class MotionValue<V = any> {
857
+ /**
858
+ * This will be replaced by the build step with the latest version number.
859
+ * When MotionValues are provided to motion components, warn if versions are mixed.
860
+ */
861
+ version: string;
862
+ /**
863
+ * If a MotionValue has an owner, it was created internally within Motion
864
+ * and therefore has no external listeners. It is therefore safe to animate via WAAPI.
865
+ */
866
+ owner?: Owner;
867
+ /**
868
+ * The current state of the `MotionValue`.
869
+ */
870
+ private current;
871
+ /**
872
+ * The previous state of the `MotionValue`.
873
+ */
874
+ private prev;
875
+ /**
876
+ * The previous state of the `MotionValue` at the end of the previous frame.
877
+ */
878
+ private prevFrameValue;
879
+ /**
880
+ * The last time the `MotionValue` was updated.
881
+ */
882
+ updatedAt: number;
883
+ /**
884
+ * The time `prevFrameValue` was updated.
885
+ */
886
+ prevUpdatedAt: number | undefined;
887
+ private stopPassiveEffect?;
888
+ /**
889
+ * A reference to the currently-controlling animation.
890
+ */
891
+ animation?: AnimationPlaybackControls;
892
+ /**
893
+ * Tracks whether this value should be removed
894
+ */
895
+ liveStyle?: boolean;
896
+ /**
897
+ * @param init - The initiating value
898
+ * @param config - Optional configuration options
899
+ *
900
+ * - `transformer`: A function to transform incoming values with.
901
+ */
902
+ constructor(init: V, options?: MotionValueOptions);
903
+ setCurrent(current: V): void;
904
+ setPrevFrameValue(prevFrameValue?: V | undefined): void;
905
+ /**
906
+ * Adds a function that will be notified when the `MotionValue` is updated.
907
+ *
908
+ * It returns a function that, when called, will cancel the subscription.
909
+ *
910
+ * When calling `onChange` inside a React component, it should be wrapped with the
911
+ * `useEffect` hook. As it returns an unsubscribe function, this should be returned
912
+ * from the `useEffect` function to ensure you don't add duplicate subscribers..
913
+ *
914
+ * ```jsx
915
+ * export const MyComponent = () => {
916
+ * const x = useMotionValue(0)
917
+ * const y = useMotionValue(0)
918
+ * const opacity = useMotionValue(1)
919
+ *
920
+ * useEffect(() => {
921
+ * function updateOpacity() {
922
+ * const maxXY = Math.max(x.get(), y.get())
923
+ * const newOpacity = transform(maxXY, [0, 100], [1, 0])
924
+ * opacity.set(newOpacity)
925
+ * }
926
+ *
927
+ * const unsubscribeX = x.on("change", updateOpacity)
928
+ * const unsubscribeY = y.on("change", updateOpacity)
929
+ *
930
+ * return () => {
931
+ * unsubscribeX()
932
+ * unsubscribeY()
933
+ * }
934
+ * }, [])
935
+ *
936
+ * return <motion.div style={{ x }} />
937
+ * }
938
+ * ```
939
+ *
940
+ * @param subscriber - A function that receives the latest value.
941
+ * @returns A function that, when called, will cancel this subscription.
942
+ *
943
+ * @deprecated
944
+ */
945
+ onChange(subscription: Subscriber<V>): () => void;
946
+ /**
947
+ * An object containing a SubscriptionManager for each active event.
948
+ */
949
+ private events;
950
+ on<EventName extends keyof MotionValueEventCallbacks<V>>(eventName: EventName, callback: MotionValueEventCallbacks<V>[EventName]): VoidFunction;
951
+ clearListeners(): void;
952
+ /**
953
+ * Attaches a passive effect to the `MotionValue`.
954
+ */
955
+ attach(passiveEffect: PassiveEffect<V>, stopPassiveEffect: VoidFunction): void;
956
+ /**
957
+ * Sets the state of the `MotionValue`.
958
+ *
959
+ * @remarks
960
+ *
961
+ * ```jsx
962
+ * const x = useMotionValue(0)
963
+ * x.set(10)
964
+ * ```
965
+ *
966
+ * @param latest - Latest value to set.
967
+ * @param render - Whether to notify render subscribers. Defaults to `true`
968
+ *
969
+ * @public
970
+ */
971
+ set(v: V, render?: boolean): void;
972
+ setWithVelocity(prev: V, current: V, delta: number): void;
973
+ /**
974
+ * Set the state of the `MotionValue`, stopping any active animations,
975
+ * effects, and resets velocity to `0`.
976
+ */
977
+ jump(v: V, endAnimation?: boolean): void;
978
+ updateAndNotify: (v: V, render?: boolean) => void;
979
+ /**
980
+ * Returns the latest state of `MotionValue`
981
+ *
982
+ * @returns - The latest state of `MotionValue`
983
+ *
984
+ * @public
985
+ */
986
+ get(): NonNullable<V>;
987
+ /**
988
+ * @public
989
+ */
990
+ getPrevious(): V | undefined;
991
+ /**
992
+ * Returns the latest velocity of `MotionValue`
993
+ *
994
+ * @returns - The latest velocity of `MotionValue`. Returns `0` if the state is non-numerical.
995
+ *
996
+ * @public
997
+ */
998
+ getVelocity(): number;
999
+ hasAnimated: boolean;
1000
+ /**
1001
+ * Registers a new animation to control this `MotionValue`. Only one
1002
+ * animation can drive a `MotionValue` at one time.
1003
+ *
1004
+ * ```jsx
1005
+ * value.start()
1006
+ * ```
1007
+ *
1008
+ * @param animation - A function that starts the provided animation
1009
+ */
1010
+ start(startAnimation: StartAnimation): Promise<void>;
1011
+ /**
1012
+ * Stop the currently active animation.
1013
+ *
1014
+ * @public
1015
+ */
1016
+ stop(): void;
1017
+ /**
1018
+ * Returns `true` if this value is currently animating.
1019
+ *
1020
+ * @public
1021
+ */
1022
+ isAnimating(): boolean;
1023
+ private clearAnimation;
1024
+ /**
1025
+ * Destroy and clean up subscribers to this `MotionValue`.
1026
+ *
1027
+ * The `MotionValue` hooks like `useMotionValue` and `useTransform` automatically
1028
+ * handle the lifecycle of the returned `MotionValue`, so this method is only necessary if you've manually
1029
+ * created a `MotionValue` via the `motionValue` function.
1030
+ *
1031
+ * @public
1032
+ */
1033
+ destroy(): void;
1034
+ }
1035
+ declare function motionValue<V>(init: V, options?: MotionValueOptions): MotionValue<V>;
1036
+
698
1037
  type ViewTransitionAnimationDefinition = {
699
1038
  keyframes: DOMKeyframesDefinition;
700
1039
  options: AnimationOptions;
@@ -707,19 +1046,16 @@ type ViewTransitionTarget = {
707
1046
  old?: ViewTransitionAnimationDefinition;
708
1047
  };
709
1048
  interface ViewTransitionOptions extends AnimationOptions {
1049
+ interrupt?: "wait" | "immediate";
710
1050
  }
711
1051
  type Target = string | Element;
712
1052
 
713
- /**
714
- * TODO:
715
- * - Create view transition on next tick
716
- * - Replace animations with Motion animations
717
- * - Return GroupAnimation on next tick
718
- */
719
1053
  declare class ViewTransitionBuilder {
720
1054
  private currentTarget;
721
- private targets;
722
- private notifyReady;
1055
+ targets: Map<Target, ViewTransitionTarget>;
1056
+ update: () => void | Promise<void>;
1057
+ options: ViewTransitionOptions;
1058
+ notifyReady: (value: BaseGroupPlaybackControls) => void;
723
1059
  private readyPromise;
724
1060
  constructor(update: () => void | Promise<void>, options?: ViewTransitionOptions);
725
1061
  get(selector: Target): this;
@@ -732,25 +1068,6 @@ declare class ViewTransitionBuilder {
732
1068
  updateTarget(target: "enter" | "exit" | "layout" | "new" | "old", keyframes: DOMKeyframesDefinition, options?: AnimationOptions): void;
733
1069
  then(resolve: () => void, reject?: () => void): Promise<void>;
734
1070
  }
735
- declare function view(update: () => void | Promise<void>, defaultOptions?: ViewTransitionOptions): ViewTransitionBuilder;
736
-
737
- declare const isDragging: {
738
- x: boolean;
739
- y: boolean;
740
- };
741
- declare function isDragActive(): boolean;
742
-
743
- declare function setDragLock(axis: boolean | "x" | "y" | "lockDirection"): (() => void) | null;
744
-
745
- /**
746
- * Recursively traverse up the tree to check whether the provided child node
747
- * is the parent or a descendant of it.
748
- *
749
- * @param parent - Element to find
750
- * @param child - Element to test against parent
751
- */
752
- declare const isNodeOrChild: (parent: Element | null, child?: Element | null) => boolean;
753
-
754
- declare const isPrimaryPointer: (event: PointerEvent) => boolean;
1071
+ declare function animateView(update: () => void | Promise<void>, defaultOptions?: ViewTransitionOptions): ViewTransitionBuilder;
755
1072
 
756
- export { type AnimationGeneratorType, type AnimationOptions, type AnimationOptionsWithValueOverrides, type AnimationPlaybackControls, type AnimationPlaybackControlsWithFinished, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, type BezierDefinition, type CSSStyleDeclarationWithTransform, type DOMKeyframesDefinition, type DecayOptions, type Driver, type DriverControls, type DurationSpringOptions, type DynamicOption, type Easing, type EasingDefinition, type EasingFunction, type EasingModifier, type ElementOrSelector, type EventOptions, type GeneratorFactory, GroupPlaybackControls, type InertiaOptions, type KeyframeGenerator, type KeyframeOptions, NativeAnimationControls, type OnHoverEndEvent, type OnHoverStartEvent, type OnPressEndEvent, type OnPressStartEvent, type PointerEventOptions, type PressGestureInfo, type ProgressTimeline, type RepeatType, type ResolvedValueKeyframe, type SVGAttributes, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGTransitions, type SelectorCache, type SpringOptions, type StyleKeyframesDefinition, type StyleTransitions, type Target, type TransformProperties, type Transition, type UnresolvedValueKeyframe, type ValueAnimationOptions, type ValueAnimationTransition, type ValueKeyframe, type ValueKeyframesDefinition, type VariableKeyframesDefinition, type VariableTransitions, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type WithQuerySelectorAll, attachTimeline, calcGeneratorDuration, capturePointer, createGeneratorEasing, cubicBezierAsString, generateLinearEasing, getValueTransition, hover, isBezierDefinition, isDragActive, isDragging, isGenerator, isNodeOrChild, isPrimaryPointer, isWaapiSupportedEasing, mapEasingToNativeEasing, maxGeneratorDuration, press, resolveElements, setDragLock, supportedWaapiEasing, supportsFlags, supportsLinearEasing, supportsScrollTimeline, view };
1073
+ export { type ActiveStatsBuffer, type AnimationGeneratorType, type AnimationOptions, type AnimationOptionsWithValueOverrides, type AnimationPlaybackControls, type AnimationPlaybackControlsWithFinished, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, type Batcher, type BezierDefinition, type CSSStyleDeclarationWithTransform, type CancelProcess, type DOMKeyframesDefinition, type DecayOptions, type Driver, type DriverControls, type DurationSpringOptions, type DynamicOption, type Easing, type EasingDefinition, type EasingFunction, type EasingModifier, type ElementOrSelector, type EventOptions, type FrameData, type FrameStats, type GeneratorFactory, GroupPlaybackControls, type InactiveStatsBuffer, type InertiaOptions, type KeyframeGenerator, type KeyframeOptions, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, NativeAnimationControls, type OnHoverEndEvent, type OnHoverStartEvent, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PassiveEffect, type PointerEventOptions, type PressGestureInfo, type Process, type ProgressTimeline, type RepeatType, type ResolvedValueKeyframe, type SVGAttributes, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGTransitions, type Schedule, type SelectorCache, type SpringOptions, type StartAnimation, type Stats, type StatsBuffer, type StatsRecording, type StatsSummary, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type Summary, type Target, type TransformProperties, type Transformer, type Transition, type UnresolvedValueKeyframe, type ValueAnimationOptions, type ValueAnimationTransition, type ValueKeyframe, type ValueKeyframesDefinition, type VariableKeyframesDefinition, type VariableTransitions, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type WithQuerySelectorAll, activeAnimations, animateView, attachTimeline, calcGeneratorDuration, cancelFrame, cancelMicrotask, capturePointer, collectMotionValues, createGeneratorEasing, createRenderBatcher, cubicBezierAsString, frame, frameData, frameSteps, generateLinearEasing, getValueTransition, hover, isBezierDefinition, isDragActive, isDragging, isGenerator, isNodeOrChild, isPrimaryPointer, isWaapiSupportedEasing, mapEasingToNativeEasing, maxGeneratorDuration, microtask, motionValue, press, recordStats, resolveElements, setDragLock, statsBuffer, supportedWaapiEasing, supportsFlags, supportsLinearEasing, supportsScrollTimeline, time };