motion-dom 12.36.0 → 12.37.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/cjs/index.js +134 -65
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/animation/AsyncMotionValueAnimation.mjs +15 -6
- package/dist/es/animation/AsyncMotionValueAnimation.mjs.map +1 -1
- package/dist/es/animation/JSAnimation.mjs +16 -3
- package/dist/es/animation/JSAnimation.mjs.map +1 -1
- package/dist/es/animation/interfaces/motion-value.mjs +1 -1
- package/dist/es/animation/interfaces/motion-value.mjs.map +1 -1
- package/dist/es/animation/utils/active-animations.mjs +5 -2
- package/dist/es/animation/utils/active-animations.mjs.map +1 -1
- package/dist/es/animation/utils/is-transition-defined.mjs +18 -2
- package/dist/es/animation/utils/is-transition-defined.mjs.map +1 -1
- package/dist/es/animation/waapi/supports/waapi.mjs +21 -12
- package/dist/es/animation/waapi/supports/waapi.mjs.map +1 -1
- package/dist/es/animation/waapi/utils/is-browser-color.mjs +13 -0
- package/dist/es/animation/waapi/utils/is-browser-color.mjs.map +1 -0
- package/dist/es/index.mjs +1 -1
- package/dist/es/projection/animation/mix-values.mjs +8 -3
- package/dist/es/projection/animation/mix-values.mjs.map +1 -1
- package/dist/es/projection/geometry/delta-apply.mjs +4 -6
- package/dist/es/projection/geometry/delta-apply.mjs.map +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +24 -9
- package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
- package/dist/es/value/follow-value.mjs +3 -0
- package/dist/es/value/follow-value.mjs.map +1 -1
- package/dist/index.d.ts +12 -7
- package/dist/motion-dom.dev.js +134 -65
- package/dist/motion-dom.js +1 -1
- package/package.json +2 -2
- package/dist/es/animation/utils/get-final-keyframe.mjs +0 -13
- package/dist/es/animation/utils/get-final-keyframe.mjs.map +0 -1
|
@@ -50,6 +50,7 @@ function attachFollow(value, source, options = {}) {
|
|
|
50
50
|
activeAnimation.stop();
|
|
51
51
|
activeAnimation = null;
|
|
52
52
|
}
|
|
53
|
+
value.animation = undefined;
|
|
53
54
|
};
|
|
54
55
|
const startAnimation = () => {
|
|
55
56
|
const currentValue = asNumber(value.get());
|
|
@@ -81,8 +82,10 @@ function attachFollow(value, source, options = {}) {
|
|
|
81
82
|
// multiple calls within the same frame (e.g. rapid mouse events)
|
|
82
83
|
const scheduleAnimation = () => {
|
|
83
84
|
startAnimation();
|
|
85
|
+
value.animation = activeAnimation ?? undefined;
|
|
84
86
|
value["events"].animationStart?.notify();
|
|
85
87
|
activeAnimation?.then(() => {
|
|
88
|
+
value.animation = undefined;
|
|
86
89
|
value["events"].animationComplete?.notify();
|
|
87
90
|
});
|
|
88
91
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"follow-value.mjs","sources":["../../../src/value/follow-value.ts"],"sourcesContent":["import { MotionValue, motionValue } from \".\"\nimport { JSAnimation } from \"../animation/JSAnimation\"\nimport { AnyResolvedKeyframe, ValueAnimationTransition } from \"../animation/types\"\nimport { frame } from \"../frameloop\"\nimport { isMotionValue } from \"./utils/is-motion-value\"\n\n/**\n * Options for useFollowValue hook, extending ValueAnimationTransition\n * but excluding lifecycle callbacks that don't make sense for the hook pattern.\n */\nexport type FollowValueOptions = Omit<\n ValueAnimationTransition,\n \"onUpdate\" | \"onComplete\" | \"onPlay\" | \"onRepeat\" | \"onStop\"\n> & {\n /**\n * When true, the first change from a tracked `MotionValue` source\n * will jump to the new value instead of animating. Subsequent\n * changes animate normally. This prevents unwanted animations\n * on page refresh or back navigation (e.g. `useScroll` + `useSpring`).\n *\n * @default false\n */\n skipInitialAnimation?: boolean\n}\n\n/**\n * Create a `MotionValue` that animates to its latest value using any transition type.\n * Can either be a value or track another `MotionValue`.\n *\n * ```jsx\n * const x = motionValue(0)\n * const y = followValue(x, { type: \"spring\", stiffness: 300 })\n * // or with tween\n * const z = followValue(x, { type: \"tween\", duration: 0.5, ease: \"easeOut\" })\n * ```\n *\n * @param source - Initial value or MotionValue to track\n * @param options - Animation transition options\n * @returns `MotionValue`\n *\n * @public\n */\nexport function followValue<T extends AnyResolvedKeyframe>(\n source: T | MotionValue<T>,\n options?: FollowValueOptions\n) {\n const initialValue = isMotionValue(source) ? source.get() : source\n const value = motionValue(initialValue)\n\n attachFollow(value, source, options)\n\n return value\n}\n\n/**\n * Attach an animation to a MotionValue that will animate whenever the value changes.\n * Similar to attachSpring but supports any transition type (spring, tween, inertia, etc.)\n *\n * @param value - The MotionValue to animate\n * @param source - Initial value or MotionValue to track\n * @param options - Animation transition options\n * @returns Cleanup function\n *\n * @public\n */\nexport function attachFollow<T extends AnyResolvedKeyframe>(\n value: MotionValue<T>,\n source: T | MotionValue<T>,\n options: FollowValueOptions = {}\n): VoidFunction {\n const initialValue = value.get()\n\n let activeAnimation: JSAnimation<number> | null = null\n let latestValue = initialValue\n let latestSetter: (v: T) => void\n\n const unit =\n typeof initialValue === \"string\"\n ? initialValue.replace(/[\\d.-]/g, \"\")\n : undefined\n\n const stopAnimation = () => {\n if (activeAnimation) {\n activeAnimation.stop()\n activeAnimation = null\n }\n }\n\n const startAnimation = () => {\n const currentValue = asNumber(value.get())\n const targetValue = asNumber(latestValue)\n\n // Don't animate if we're already at the target\n if (currentValue === targetValue) {\n stopAnimation()\n return\n }\n\n // Use the running animation's analytical velocity for accuracy,\n // falling back to the MotionValue's velocity for the initial animation.\n // This prevents systematic velocity loss at high frame rates (240hz+).\n const velocity = activeAnimation\n ? activeAnimation.getGeneratorVelocity()\n : value.getVelocity()\n\n stopAnimation()\n\n activeAnimation = new JSAnimation({\n keyframes: [currentValue, targetValue],\n velocity,\n // Default to spring if no type specified (matches useSpring behavior)\n type: \"spring\",\n restDelta: 0.001,\n restSpeed: 0.01,\n ...options,\n onUpdate: latestSetter,\n })\n }\n\n // Use a stable function reference so the frame loop Set deduplicates\n // multiple calls within the same frame (e.g. rapid mouse events)\n const scheduleAnimation = () => {\n startAnimation()\n value[\"events\"].animationStart?.notify()\n activeAnimation?.then(() => {\n value[\"events\"].animationComplete?.notify()\n })\n }\n\n value.attach((v, set) => {\n latestValue = v\n latestSetter = (latest) => set(parseValue(latest, unit) as T)\n frame.postRender(scheduleAnimation)\n }, stopAnimation)\n\n if (isMotionValue(source)) {\n let skipNextAnimation = options.skipInitialAnimation === true\n\n const removeSourceOnChange = source.on(\"change\", (v) => {\n if (skipNextAnimation) {\n skipNextAnimation = false\n value.jump(parseValue(v, unit) as T, false)\n } else {\n value.set(parseValue(v, unit) as T)\n }\n })\n\n const removeValueOnDestroy = value.on(\"destroy\", removeSourceOnChange)\n\n return () => {\n removeSourceOnChange()\n removeValueOnDestroy()\n }\n }\n\n return stopAnimation\n}\n\nfunction parseValue(v: AnyResolvedKeyframe, unit?: string) {\n return unit ? v + unit : v\n}\n\nfunction asNumber(v: AnyResolvedKeyframe) {\n return typeof v === \"number\" ? v : parseFloat(v)\n}\n"],"names":[],"mappings":";;;;;AAyBA;;;;;;;;;;;;;;;;AAgBG;AACG,SAAU,WAAW,CACvB,MAA0B,EAC1B,OAA4B,EAAA;AAE5B,IAAA,MAAM,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,MAAM;AAClE,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC;AAEvC,IAAA,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC;AAEpC,IAAA,OAAO,KAAK;AAChB;AAEA;;;;;;;;;;AAUG;AACG,SAAU,YAAY,CACxB,KAAqB,EACrB,MAA0B,EAC1B,UAA8B,EAAE,EAAA;AAEhC,IAAA,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,EAAE;IAEhC,IAAI,eAAe,GAA+B,IAAI;IACtD,IAAI,WAAW,GAAG,YAAY;AAC9B,IAAA,IAAI,YAA4B;AAEhC,IAAA,MAAM,IAAI,GACN,OAAO,YAAY,KAAK;UAClB,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE;UAClC,SAAS;IAEnB,MAAM,aAAa,GAAG,MAAK;QACvB,IAAI,eAAe,EAAE;YACjB,eAAe,CAAC,IAAI,EAAE;YACtB,eAAe,GAAG,IAAI;QAC1B;
|
|
1
|
+
{"version":3,"file":"follow-value.mjs","sources":["../../../src/value/follow-value.ts"],"sourcesContent":["import { MotionValue, motionValue } from \".\"\nimport { JSAnimation } from \"../animation/JSAnimation\"\nimport { AnyResolvedKeyframe, ValueAnimationTransition } from \"../animation/types\"\nimport { frame } from \"../frameloop\"\nimport { isMotionValue } from \"./utils/is-motion-value\"\n\n/**\n * Options for useFollowValue hook, extending ValueAnimationTransition\n * but excluding lifecycle callbacks that don't make sense for the hook pattern.\n */\nexport type FollowValueOptions = Omit<\n ValueAnimationTransition,\n \"onUpdate\" | \"onComplete\" | \"onPlay\" | \"onRepeat\" | \"onStop\"\n> & {\n /**\n * When true, the first change from a tracked `MotionValue` source\n * will jump to the new value instead of animating. Subsequent\n * changes animate normally. This prevents unwanted animations\n * on page refresh or back navigation (e.g. `useScroll` + `useSpring`).\n *\n * @default false\n */\n skipInitialAnimation?: boolean\n}\n\n/**\n * Create a `MotionValue` that animates to its latest value using any transition type.\n * Can either be a value or track another `MotionValue`.\n *\n * ```jsx\n * const x = motionValue(0)\n * const y = followValue(x, { type: \"spring\", stiffness: 300 })\n * // or with tween\n * const z = followValue(x, { type: \"tween\", duration: 0.5, ease: \"easeOut\" })\n * ```\n *\n * @param source - Initial value or MotionValue to track\n * @param options - Animation transition options\n * @returns `MotionValue`\n *\n * @public\n */\nexport function followValue<T extends AnyResolvedKeyframe>(\n source: T | MotionValue<T>,\n options?: FollowValueOptions\n) {\n const initialValue = isMotionValue(source) ? source.get() : source\n const value = motionValue(initialValue)\n\n attachFollow(value, source, options)\n\n return value\n}\n\n/**\n * Attach an animation to a MotionValue that will animate whenever the value changes.\n * Similar to attachSpring but supports any transition type (spring, tween, inertia, etc.)\n *\n * @param value - The MotionValue to animate\n * @param source - Initial value or MotionValue to track\n * @param options - Animation transition options\n * @returns Cleanup function\n *\n * @public\n */\nexport function attachFollow<T extends AnyResolvedKeyframe>(\n value: MotionValue<T>,\n source: T | MotionValue<T>,\n options: FollowValueOptions = {}\n): VoidFunction {\n const initialValue = value.get()\n\n let activeAnimation: JSAnimation<number> | null = null\n let latestValue = initialValue\n let latestSetter: (v: T) => void\n\n const unit =\n typeof initialValue === \"string\"\n ? initialValue.replace(/[\\d.-]/g, \"\")\n : undefined\n\n const stopAnimation = () => {\n if (activeAnimation) {\n activeAnimation.stop()\n activeAnimation = null\n }\n value.animation = undefined\n }\n\n const startAnimation = () => {\n const currentValue = asNumber(value.get())\n const targetValue = asNumber(latestValue)\n\n // Don't animate if we're already at the target\n if (currentValue === targetValue) {\n stopAnimation()\n return\n }\n\n // Use the running animation's analytical velocity for accuracy,\n // falling back to the MotionValue's velocity for the initial animation.\n // This prevents systematic velocity loss at high frame rates (240hz+).\n const velocity = activeAnimation\n ? activeAnimation.getGeneratorVelocity()\n : value.getVelocity()\n\n stopAnimation()\n\n activeAnimation = new JSAnimation({\n keyframes: [currentValue, targetValue],\n velocity,\n // Default to spring if no type specified (matches useSpring behavior)\n type: \"spring\",\n restDelta: 0.001,\n restSpeed: 0.01,\n ...options,\n onUpdate: latestSetter,\n })\n }\n\n // Use a stable function reference so the frame loop Set deduplicates\n // multiple calls within the same frame (e.g. rapid mouse events)\n const scheduleAnimation = () => {\n startAnimation()\n value.animation = activeAnimation ?? undefined\n value[\"events\"].animationStart?.notify()\n activeAnimation?.then(() => {\n value.animation = undefined\n value[\"events\"].animationComplete?.notify()\n })\n }\n\n value.attach((v, set) => {\n latestValue = v\n latestSetter = (latest) => set(parseValue(latest, unit) as T)\n frame.postRender(scheduleAnimation)\n }, stopAnimation)\n\n if (isMotionValue(source)) {\n let skipNextAnimation = options.skipInitialAnimation === true\n\n const removeSourceOnChange = source.on(\"change\", (v) => {\n if (skipNextAnimation) {\n skipNextAnimation = false\n value.jump(parseValue(v, unit) as T, false)\n } else {\n value.set(parseValue(v, unit) as T)\n }\n })\n\n const removeValueOnDestroy = value.on(\"destroy\", removeSourceOnChange)\n\n return () => {\n removeSourceOnChange()\n removeValueOnDestroy()\n }\n }\n\n return stopAnimation\n}\n\nfunction parseValue(v: AnyResolvedKeyframe, unit?: string) {\n return unit ? v + unit : v\n}\n\nfunction asNumber(v: AnyResolvedKeyframe) {\n return typeof v === \"number\" ? v : parseFloat(v)\n}\n"],"names":[],"mappings":";;;;;AAyBA;;;;;;;;;;;;;;;;AAgBG;AACG,SAAU,WAAW,CACvB,MAA0B,EAC1B,OAA4B,EAAA;AAE5B,IAAA,MAAM,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,MAAM;AAClE,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC;AAEvC,IAAA,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC;AAEpC,IAAA,OAAO,KAAK;AAChB;AAEA;;;;;;;;;;AAUG;AACG,SAAU,YAAY,CACxB,KAAqB,EACrB,MAA0B,EAC1B,UAA8B,EAAE,EAAA;AAEhC,IAAA,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,EAAE;IAEhC,IAAI,eAAe,GAA+B,IAAI;IACtD,IAAI,WAAW,GAAG,YAAY;AAC9B,IAAA,IAAI,YAA4B;AAEhC,IAAA,MAAM,IAAI,GACN,OAAO,YAAY,KAAK;UAClB,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE;UAClC,SAAS;IAEnB,MAAM,aAAa,GAAG,MAAK;QACvB,IAAI,eAAe,EAAE;YACjB,eAAe,CAAC,IAAI,EAAE;YACtB,eAAe,GAAG,IAAI;QAC1B;AACA,QAAA,KAAK,CAAC,SAAS,GAAG,SAAS;AAC/B,IAAA,CAAC;IAED,MAAM,cAAc,GAAG,MAAK;QACxB,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAC1C,QAAA,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;;AAGzC,QAAA,IAAI,YAAY,KAAK,WAAW,EAAE;AAC9B,YAAA,aAAa,EAAE;YACf;QACJ;;;;QAKA,MAAM,QAAQ,GAAG;AACb,cAAE,eAAe,CAAC,oBAAoB;AACtC,cAAE,KAAK,CAAC,WAAW,EAAE;AAEzB,QAAA,aAAa,EAAE;QAEf,eAAe,GAAG,IAAI,WAAW,CAAC;AAC9B,YAAA,SAAS,EAAE,CAAC,YAAY,EAAE,WAAW,CAAC;YACtC,QAAQ;;AAER,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,SAAS,EAAE,KAAK;AAChB,YAAA,SAAS,EAAE,IAAI;AACf,YAAA,GAAG,OAAO;AACV,YAAA,QAAQ,EAAE,YAAY;AACzB,SAAA,CAAC;AACN,IAAA,CAAC;;;IAID,MAAM,iBAAiB,GAAG,MAAK;AAC3B,QAAA,cAAc,EAAE;AAChB,QAAA,KAAK,CAAC,SAAS,GAAG,eAAe,IAAI,SAAS;QAC9C,KAAK,CAAC,QAAQ,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE;AACxC,QAAA,eAAe,EAAE,IAAI,CAAC,MAAK;AACvB,YAAA,KAAK,CAAC,SAAS,GAAG,SAAS;YAC3B,KAAK,CAAC,QAAQ,CAAC,CAAC,iBAAiB,EAAE,MAAM,EAAE;AAC/C,QAAA,CAAC,CAAC;AACN,IAAA,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,KAAI;QACpB,WAAW,GAAG,CAAC;AACf,QAAA,YAAY,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAM,CAAC;AAC7D,QAAA,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC;IACvC,CAAC,EAAE,aAAa,CAAC;AAEjB,IAAA,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE;AACvB,QAAA,IAAI,iBAAiB,GAAG,OAAO,CAAC,oBAAoB,KAAK,IAAI;QAE7D,MAAM,oBAAoB,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAI;YACnD,IAAI,iBAAiB,EAAE;gBACnB,iBAAiB,GAAG,KAAK;AACzB,gBAAA,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAM,EAAE,KAAK,CAAC;YAC/C;iBAAO;gBACH,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAM,CAAC;YACvC;AACJ,QAAA,CAAC,CAAC;QAEF,MAAM,oBAAoB,GAAG,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,oBAAoB,CAAC;AAEtE,QAAA,OAAO,MAAK;AACR,YAAA,oBAAoB,EAAE;AACtB,YAAA,oBAAoB,EAAE;AAC1B,QAAA,CAAC;IACL;AAEA,IAAA,OAAO,aAAa;AACxB;AAEA,SAAS,UAAU,CAAC,CAAsB,EAAE,IAAa,EAAA;IACrD,OAAO,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC;AAC9B;AAEA,SAAS,QAAQ,CAAC,CAAsB,EAAA;AACpC,IAAA,OAAO,OAAO,CAAC,KAAK,QAAQ,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;AACpD;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2360,6 +2360,11 @@ declare class JSAnimation<T extends number | string> extends WithPromise impleme
|
|
|
2360
2360
|
private playbackSpeed;
|
|
2361
2361
|
private mixKeyframes;
|
|
2362
2362
|
private mirroredGenerator;
|
|
2363
|
+
/**
|
|
2364
|
+
* Reusable state object for the delay phase to avoid
|
|
2365
|
+
* allocating a new object every frame.
|
|
2366
|
+
*/
|
|
2367
|
+
private delayState;
|
|
2363
2368
|
constructor(options: ValueAnimationOptions<T>);
|
|
2364
2369
|
initAnimation(): void;
|
|
2365
2370
|
updateTime(timestamp: number): void;
|
|
@@ -2481,7 +2486,7 @@ declare class NativeAnimationWrapper<T extends AnyResolvedKeyframe> extends Nati
|
|
|
2481
2486
|
}
|
|
2482
2487
|
|
|
2483
2488
|
declare const animationMapKey: (name: string, pseudoElement?: string) => string;
|
|
2484
|
-
declare function getAnimationMap(element: Element): Map<
|
|
2489
|
+
declare function getAnimationMap(element: Element): Map<string, NativeAnimation<AnyResolvedKeyframe>>;
|
|
2485
2490
|
|
|
2486
2491
|
interface VisualElementAnimationOptions {
|
|
2487
2492
|
delay?: number;
|
|
@@ -2847,7 +2852,7 @@ declare function getVariableValue(current: CSSVariableToken, element: Element, d
|
|
|
2847
2852
|
|
|
2848
2853
|
declare const getDefaultTransition: (valueKey: string, { keyframes }: ValueAnimationOptions) => Partial<ValueAnimationOptions>;
|
|
2849
2854
|
|
|
2850
|
-
declare function getFinalKeyframe<T>(keyframes: T[], { repeat, repeatType }: AnimationPlaybackOptions, finalKeyframe?: T): T;
|
|
2855
|
+
declare function getFinalKeyframe<T>(keyframes: T[], { repeat, repeatType }: AnimationPlaybackOptions, finalKeyframe?: T, speed?: number): T;
|
|
2851
2856
|
|
|
2852
2857
|
declare function getValueTransition(transition: any, key: string): any;
|
|
2853
2858
|
|
|
@@ -2863,7 +2868,7 @@ declare function resolveTransition(transition: any, parentTransition?: any): any
|
|
|
2863
2868
|
* This filters out orchestration options and returns true
|
|
2864
2869
|
* if any options are left.
|
|
2865
2870
|
*/
|
|
2866
|
-
declare function isTransitionDefined(
|
|
2871
|
+
declare function isTransitionDefined(transition: Transition & {
|
|
2867
2872
|
elapsed?: number;
|
|
2868
2873
|
from?: AnyResolvedKeyframe;
|
|
2869
2874
|
}): boolean;
|
|
@@ -4298,7 +4303,7 @@ interface IProjectionNode<I = unknown> {
|
|
|
4298
4303
|
setTargetDelta(delta: Delta): void;
|
|
4299
4304
|
resetTransform(): void;
|
|
4300
4305
|
resetSkewAndRotation(): void;
|
|
4301
|
-
applyTransform(box: Box, transformOnly?: boolean): Box;
|
|
4306
|
+
applyTransform(box: Box, transformOnly?: boolean, output?: Box): Box;
|
|
4302
4307
|
resolveTargetDelta(force?: boolean): void;
|
|
4303
4308
|
calcProjection(): void;
|
|
4304
4309
|
applyProjectionStyles(targetStyle: CSSStyleDeclaration, styleProp?: MotionStyle): void;
|
|
@@ -4647,7 +4652,7 @@ declare function createProjectionNode<I>({ attachResizeListener, defaultParent,
|
|
|
4647
4652
|
};
|
|
4648
4653
|
measurePageBox(): Box;
|
|
4649
4654
|
removeElementScroll(box: Box): Box;
|
|
4650
|
-
applyTransform(box: Box, transformOnly?: boolean): Box;
|
|
4655
|
+
applyTransform(box: Box, transformOnly?: boolean, output?: Box): Box;
|
|
4651
4656
|
removeTransform(box: Box): Box;
|
|
4652
4657
|
setTargetDelta(delta: Delta): void;
|
|
4653
4658
|
setOptions(options: ProjectionNodeOptions): void;
|
|
@@ -4793,7 +4798,7 @@ declare const DocumentProjectionNode: {
|
|
|
4793
4798
|
};
|
|
4794
4799
|
measurePageBox(): motion_utils.Box;
|
|
4795
4800
|
removeElementScroll(box: motion_utils.Box): motion_utils.Box;
|
|
4796
|
-
applyTransform(box: motion_utils.Box, transformOnly?: boolean): motion_utils.Box;
|
|
4801
|
+
applyTransform(box: motion_utils.Box, transformOnly?: boolean, output?: motion_utils.Box | undefined): motion_utils.Box;
|
|
4797
4802
|
removeTransform(box: motion_utils.Box): motion_utils.Box;
|
|
4798
4803
|
setTargetDelta(delta: motion_utils.Delta): void;
|
|
4799
4804
|
setOptions(options: ProjectionNodeOptions): void;
|
|
@@ -4938,7 +4943,7 @@ declare const HTMLProjectionNode: {
|
|
|
4938
4943
|
};
|
|
4939
4944
|
measurePageBox(): motion_utils.Box;
|
|
4940
4945
|
removeElementScroll(box: motion_utils.Box): motion_utils.Box;
|
|
4941
|
-
applyTransform(box: motion_utils.Box, transformOnly?: boolean): motion_utils.Box;
|
|
4946
|
+
applyTransform(box: motion_utils.Box, transformOnly?: boolean, output?: motion_utils.Box | undefined): motion_utils.Box;
|
|
4942
4947
|
removeTransform(box: motion_utils.Box): motion_utils.Box;
|
|
4943
4948
|
setTargetDelta(delta: motion_utils.Delta): void;
|
|
4944
4949
|
setOptions(options: ProjectionNodeOptions): void;
|
package/dist/motion-dom.dev.js
CHANGED
|
@@ -1324,9 +1324,9 @@
|
|
|
1324
1324
|
};
|
|
1325
1325
|
}
|
|
1326
1326
|
|
|
1327
|
-
const isNotNull
|
|
1328
|
-
function getFinalKeyframe
|
|
1329
|
-
const resolvedKeyframes = keyframes.filter(isNotNull
|
|
1327
|
+
const isNotNull = (value) => value !== null;
|
|
1328
|
+
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe, speed = 1) {
|
|
1329
|
+
const resolvedKeyframes = keyframes.filter(isNotNull);
|
|
1330
1330
|
const useFirstKeyframe = speed < 0 || (repeat && repeatType !== "loop" && repeat % 2 === 1);
|
|
1331
1331
|
const index = useFirstKeyframe ? 0 : resolvedKeyframes.length - 1;
|
|
1332
1332
|
return !index || finalKeyframe === undefined
|
|
@@ -1391,6 +1391,14 @@
|
|
|
1391
1391
|
* Playback speed as a factor. 0 would be stopped, -1 reverse and 2 double speed.
|
|
1392
1392
|
*/
|
|
1393
1393
|
this.playbackSpeed = 1;
|
|
1394
|
+
/**
|
|
1395
|
+
* Reusable state object for the delay phase to avoid
|
|
1396
|
+
* allocating a new object every frame.
|
|
1397
|
+
*/
|
|
1398
|
+
this.delayState = {
|
|
1399
|
+
done: false,
|
|
1400
|
+
value: undefined,
|
|
1401
|
+
};
|
|
1394
1402
|
/**
|
|
1395
1403
|
* This method is bound to the instance to fix a pattern where
|
|
1396
1404
|
* animation.stop is returned as a reference from a useEffect.
|
|
@@ -1552,9 +1560,14 @@
|
|
|
1552
1560
|
* This prevents delay: x, duration: 0 animations from finishing
|
|
1553
1561
|
* instantly.
|
|
1554
1562
|
*/
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1563
|
+
let state;
|
|
1564
|
+
if (isInDelayPhase) {
|
|
1565
|
+
this.delayState.value = keyframes[0];
|
|
1566
|
+
state = this.delayState;
|
|
1567
|
+
}
|
|
1568
|
+
else {
|
|
1569
|
+
state = frameGenerator.next(elapsed);
|
|
1570
|
+
}
|
|
1558
1571
|
if (mixKeyframes && !isInDelayPhase) {
|
|
1559
1572
|
state.value = mixKeyframes(state.value);
|
|
1560
1573
|
}
|
|
@@ -1569,7 +1582,7 @@
|
|
|
1569
1582
|
(this.state === "finished" || (this.state === "running" && done));
|
|
1570
1583
|
// TODO: The exception for inertia could be cleaner here
|
|
1571
1584
|
if (isAnimationFinished && type !== inertia) {
|
|
1572
|
-
state.value = getFinalKeyframe
|
|
1585
|
+
state.value = getFinalKeyframe(keyframes, this.options, finalKeyframe, this.speed);
|
|
1573
1586
|
}
|
|
1574
1587
|
if (onUpdate) {
|
|
1575
1588
|
onUpdate(state.value);
|
|
@@ -2177,7 +2190,7 @@
|
|
|
2177
2190
|
this.animation.onfinish = () => {
|
|
2178
2191
|
this.finishedTime = this.time;
|
|
2179
2192
|
if (!pseudoElement) {
|
|
2180
|
-
const keyframe = getFinalKeyframe
|
|
2193
|
+
const keyframe = getFinalKeyframe(keyframes, this.options, finalKeyframe, this.speed);
|
|
2181
2194
|
if (this.updateMotionValue) {
|
|
2182
2195
|
this.updateMotionValue(keyframe);
|
|
2183
2196
|
}
|
|
@@ -2483,17 +2496,42 @@
|
|
|
2483
2496
|
/**
|
|
2484
2497
|
* A list of values that can be hardware-accelerated.
|
|
2485
2498
|
*/
|
|
2486
|
-
const acceleratedValues
|
|
2499
|
+
const acceleratedValues = new Set([
|
|
2487
2500
|
"opacity",
|
|
2488
2501
|
"clipPath",
|
|
2489
2502
|
"filter",
|
|
2490
2503
|
"transform",
|
|
2491
|
-
// TODO:
|
|
2504
|
+
// TODO: Can be accelerated but currently disabled until https://issues.chromium.org/issues/41491098 is resolved
|
|
2505
|
+
// or until we implement support for linear() easing.
|
|
2492
2506
|
// "background-color"
|
|
2493
2507
|
]);
|
|
2508
|
+
|
|
2509
|
+
const browserColorFunctions = /^(?:oklch|oklab|lab|lch|color|color-mix|light-dark)\(/;
|
|
2510
|
+
function hasBrowserOnlyColors(keyframes) {
|
|
2511
|
+
for (let i = 0; i < keyframes.length; i++) {
|
|
2512
|
+
if (typeof keyframes[i] === "string" &&
|
|
2513
|
+
browserColorFunctions.test(keyframes[i])) {
|
|
2514
|
+
return true;
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
return false;
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
const colorProperties = new Set([
|
|
2521
|
+
"color",
|
|
2522
|
+
"backgroundColor",
|
|
2523
|
+
"outlineColor",
|
|
2524
|
+
"fill",
|
|
2525
|
+
"stroke",
|
|
2526
|
+
"borderColor",
|
|
2527
|
+
"borderTopColor",
|
|
2528
|
+
"borderRightColor",
|
|
2529
|
+
"borderBottomColor",
|
|
2530
|
+
"borderLeftColor",
|
|
2531
|
+
]);
|
|
2494
2532
|
const supportsWaapi = /*@__PURE__*/ motionUtils.memo(() => Object.hasOwnProperty.call(Element.prototype, "animate"));
|
|
2495
2533
|
function supportsBrowserAnimation(options) {
|
|
2496
|
-
const { motionValue, name, repeatDelay, repeatType, damping, type } = options;
|
|
2534
|
+
const { motionValue, name, repeatDelay, repeatType, damping, type, keyframes, } = options;
|
|
2497
2535
|
const subject = motionValue?.owner?.current;
|
|
2498
2536
|
/**
|
|
2499
2537
|
* We use this check instead of isHTMLElement() because we explicitly
|
|
@@ -2507,7 +2545,13 @@
|
|
|
2507
2545
|
const { onUpdate, transformTemplate } = motionValue.owner.getProps();
|
|
2508
2546
|
return (supportsWaapi() &&
|
|
2509
2547
|
name &&
|
|
2510
|
-
|
|
2548
|
+
/**
|
|
2549
|
+
* Force WAAPI for color properties with browser-only color formats
|
|
2550
|
+
* (oklch, oklab, lab, lch, etc.) that the JS animation path can't parse.
|
|
2551
|
+
*/
|
|
2552
|
+
(acceleratedValues.has(name) ||
|
|
2553
|
+
(colorProperties.has(name) &&
|
|
2554
|
+
hasBrowserOnlyColors(keyframes))) &&
|
|
2511
2555
|
(name !== "transform" || !transformTemplate) &&
|
|
2512
2556
|
/**
|
|
2513
2557
|
* If we're outputting values to onUpdate then we can't use WAAPI as there's
|
|
@@ -2571,7 +2615,7 @@
|
|
|
2571
2615
|
if (!canAnimate(keyframes, name, type, velocity)) {
|
|
2572
2616
|
canAnimateValue = false;
|
|
2573
2617
|
if (motionUtils.MotionGlobalConfig.instantAnimations || !delay) {
|
|
2574
|
-
onUpdate?.(getFinalKeyframe
|
|
2618
|
+
onUpdate?.(getFinalKeyframe(keyframes, options, finalKeyframe));
|
|
2575
2619
|
}
|
|
2576
2620
|
keyframes[0] = keyframes[keyframes.length - 1];
|
|
2577
2621
|
makeAnimationInstant(options);
|
|
@@ -2614,12 +2658,21 @@
|
|
|
2614
2658
|
!isHandoff &&
|
|
2615
2659
|
supportsBrowserAnimation(resolvedOptions);
|
|
2616
2660
|
const element = resolvedOptions.motionValue?.owner?.current;
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2661
|
+
let animation;
|
|
2662
|
+
if (useWaapi) {
|
|
2663
|
+
try {
|
|
2664
|
+
animation = new NativeAnimationExtended({
|
|
2665
|
+
...resolvedOptions,
|
|
2666
|
+
element,
|
|
2667
|
+
});
|
|
2668
|
+
}
|
|
2669
|
+
catch {
|
|
2670
|
+
animation = new JSAnimation(resolvedOptions);
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
else {
|
|
2674
|
+
animation = new JSAnimation(resolvedOptions);
|
|
2675
|
+
}
|
|
2623
2676
|
animation.finished.then(() => {
|
|
2624
2677
|
this.notifyFinished();
|
|
2625
2678
|
}).catch(motionUtils.noop);
|
|
@@ -2797,8 +2850,11 @@
|
|
|
2797
2850
|
const animationMaps = new WeakMap();
|
|
2798
2851
|
const animationMapKey = (name, pseudoElement = "") => `${name}:${pseudoElement}`;
|
|
2799
2852
|
function getAnimationMap(element) {
|
|
2800
|
-
|
|
2801
|
-
|
|
2853
|
+
let map = animationMaps.get(element);
|
|
2854
|
+
if (!map) {
|
|
2855
|
+
map = new Map();
|
|
2856
|
+
animationMaps.set(element, map);
|
|
2857
|
+
}
|
|
2802
2858
|
return map;
|
|
2803
2859
|
}
|
|
2804
2860
|
|
|
@@ -2890,17 +2946,6 @@
|
|
|
2890
2946
|
return ease;
|
|
2891
2947
|
};
|
|
2892
2948
|
|
|
2893
|
-
const isNotNull = (value) => value !== null;
|
|
2894
|
-
function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
|
|
2895
|
-
const resolvedKeyframes = keyframes.filter(isNotNull);
|
|
2896
|
-
const index = repeat && repeatType !== "loop" && repeat % 2 === 1
|
|
2897
|
-
? 0
|
|
2898
|
-
: resolvedKeyframes.length - 1;
|
|
2899
|
-
return !index || finalKeyframe === undefined
|
|
2900
|
-
? resolvedKeyframes[index]
|
|
2901
|
-
: finalKeyframe;
|
|
2902
|
-
}
|
|
2903
|
-
|
|
2904
2949
|
/**
|
|
2905
2950
|
* If `transition` has `inherit: true`, shallow-merge it with
|
|
2906
2951
|
* `parentTransition` (child keys win) and strip the `inherit` key.
|
|
@@ -2924,13 +2969,29 @@
|
|
|
2924
2969
|
return valueTransition;
|
|
2925
2970
|
}
|
|
2926
2971
|
|
|
2972
|
+
const orchestrationKeys = new Set([
|
|
2973
|
+
"when",
|
|
2974
|
+
"delay",
|
|
2975
|
+
"delayChildren",
|
|
2976
|
+
"staggerChildren",
|
|
2977
|
+
"staggerDirection",
|
|
2978
|
+
"repeat",
|
|
2979
|
+
"repeatType",
|
|
2980
|
+
"repeatDelay",
|
|
2981
|
+
"from",
|
|
2982
|
+
"elapsed",
|
|
2983
|
+
]);
|
|
2927
2984
|
/**
|
|
2928
2985
|
* Decide whether a transition is defined on a given Transition.
|
|
2929
2986
|
* This filters out orchestration options and returns true
|
|
2930
2987
|
* if any options are left.
|
|
2931
2988
|
*/
|
|
2932
|
-
function isTransitionDefined(
|
|
2933
|
-
|
|
2989
|
+
function isTransitionDefined(transition) {
|
|
2990
|
+
for (const key in transition) {
|
|
2991
|
+
if (!orchestrationKeys.has(key))
|
|
2992
|
+
return true;
|
|
2993
|
+
}
|
|
2994
|
+
return false;
|
|
2934
2995
|
}
|
|
2935
2996
|
|
|
2936
2997
|
const animateMotionValue = (name, value, target, transition = {}, element, isHandoff) => (onComplete) => {
|
|
@@ -4062,19 +4123,6 @@
|
|
|
4062
4123
|
return true;
|
|
4063
4124
|
});
|
|
4064
4125
|
|
|
4065
|
-
/**
|
|
4066
|
-
* A list of values that can be hardware-accelerated.
|
|
4067
|
-
*/
|
|
4068
|
-
const acceleratedValues = new Set([
|
|
4069
|
-
"opacity",
|
|
4070
|
-
"clipPath",
|
|
4071
|
-
"filter",
|
|
4072
|
-
"transform",
|
|
4073
|
-
// TODO: Can be accelerated but currently disabled until https://issues.chromium.org/issues/41491098 is resolved
|
|
4074
|
-
// or until we implement support for linear() easing.
|
|
4075
|
-
// "background-color"
|
|
4076
|
-
]);
|
|
4077
|
-
|
|
4078
4126
|
function resolveElements(elementOrSelector, scope, selectorCache) {
|
|
4079
4127
|
if (elementOrSelector == null) {
|
|
4080
4128
|
return [];
|
|
@@ -4960,6 +5008,7 @@
|
|
|
4960
5008
|
activeAnimation.stop();
|
|
4961
5009
|
activeAnimation = null;
|
|
4962
5010
|
}
|
|
5011
|
+
value.animation = undefined;
|
|
4963
5012
|
};
|
|
4964
5013
|
const startAnimation = () => {
|
|
4965
5014
|
const currentValue = asNumber$1(value.get());
|
|
@@ -4991,8 +5040,10 @@
|
|
|
4991
5040
|
// multiple calls within the same frame (e.g. rapid mouse events)
|
|
4992
5041
|
const scheduleAnimation = () => {
|
|
4993
5042
|
startAnimation();
|
|
5043
|
+
value.animation = activeAnimation ?? undefined;
|
|
4994
5044
|
value["events"].animationStart?.notify();
|
|
4995
5045
|
activeAnimation?.then(() => {
|
|
5046
|
+
value.animation = undefined;
|
|
4996
5047
|
value["events"].animationComplete?.notify();
|
|
4997
5048
|
});
|
|
4998
5049
|
};
|
|
@@ -6291,10 +6342,8 @@
|
|
|
6291
6342
|
node.options.layoutScroll &&
|
|
6292
6343
|
node.scroll &&
|
|
6293
6344
|
node !== node.root) {
|
|
6294
|
-
|
|
6295
|
-
|
|
6296
|
-
y: -node.scroll.offset.y,
|
|
6297
|
-
});
|
|
6345
|
+
translateAxis(box.x, -node.scroll.offset.x);
|
|
6346
|
+
translateAxis(box.y, -node.scroll.offset.y);
|
|
6298
6347
|
}
|
|
6299
6348
|
if (delta) {
|
|
6300
6349
|
// Incoporate each ancestor's scale into a cumulative treeScale for this component
|
|
@@ -6321,8 +6370,8 @@
|
|
|
6321
6370
|
}
|
|
6322
6371
|
}
|
|
6323
6372
|
function translateAxis(axis, distance) {
|
|
6324
|
-
axis.min
|
|
6325
|
-
axis.max
|
|
6373
|
+
axis.min += distance;
|
|
6374
|
+
axis.max += distance;
|
|
6326
6375
|
}
|
|
6327
6376
|
/**
|
|
6328
6377
|
* Apply a transform to an axis from the latest resolved motion values.
|
|
@@ -7489,8 +7538,13 @@
|
|
|
7489
7538
|
return transform || "none";
|
|
7490
7539
|
}
|
|
7491
7540
|
|
|
7492
|
-
const
|
|
7493
|
-
|
|
7541
|
+
const borderLabels = [
|
|
7542
|
+
"borderTopLeftRadius",
|
|
7543
|
+
"borderTopRightRadius",
|
|
7544
|
+
"borderBottomLeftRadius",
|
|
7545
|
+
"borderBottomRightRadius",
|
|
7546
|
+
];
|
|
7547
|
+
const numBorders = borderLabels.length;
|
|
7494
7548
|
const asNumber = (value) => typeof value === "string" ? parseFloat(value) : value;
|
|
7495
7549
|
const isPx = (value) => typeof value === "number" || px.test(value);
|
|
7496
7550
|
function mixValues(target, follow, lead, progress, shouldCrossfadeOpacity, isOnlyMember) {
|
|
@@ -7505,7 +7559,7 @@
|
|
|
7505
7559
|
* Mix border radius
|
|
7506
7560
|
*/
|
|
7507
7561
|
for (let i = 0; i < numBorders; i++) {
|
|
7508
|
-
const borderLabel =
|
|
7562
|
+
const borderLabel = borderLabels[i];
|
|
7509
7563
|
let followRadius = getRadius(follow, borderLabel);
|
|
7510
7564
|
let leadRadius = getRadius(lead, borderLabel);
|
|
7511
7565
|
if (followRadius === undefined && leadRadius === undefined)
|
|
@@ -8150,6 +8204,11 @@
|
|
|
8150
8204
|
}
|
|
8151
8205
|
else {
|
|
8152
8206
|
this.isUpdating = false;
|
|
8207
|
+
/**
|
|
8208
|
+
* Ensure animation-blocked nodes (e.g. during drag)
|
|
8209
|
+
* get measured even when memoized (willUpdate skipped).
|
|
8210
|
+
*/
|
|
8211
|
+
this.nodes.forEach(ensureDraggedNodesSnapshotted);
|
|
8153
8212
|
/**
|
|
8154
8213
|
* Write
|
|
8155
8214
|
*/
|
|
@@ -8248,7 +8307,8 @@
|
|
|
8248
8307
|
const prevLayout = this.layout;
|
|
8249
8308
|
this.layout = this.measure(false);
|
|
8250
8309
|
this.layoutVersion++;
|
|
8251
|
-
this.layoutCorrected
|
|
8310
|
+
if (!this.layoutCorrected)
|
|
8311
|
+
this.layoutCorrected = createBox();
|
|
8252
8312
|
this.isLayoutDirty = false;
|
|
8253
8313
|
this.projectionDelta = undefined;
|
|
8254
8314
|
this.notifyListeners("measure", this.layout.layoutBox);
|
|
@@ -8359,8 +8419,8 @@
|
|
|
8359
8419
|
}
|
|
8360
8420
|
return boxWithoutScroll;
|
|
8361
8421
|
}
|
|
8362
|
-
applyTransform(box, transformOnly = false) {
|
|
8363
|
-
const withTransforms = createBox();
|
|
8422
|
+
applyTransform(box, transformOnly = false, output) {
|
|
8423
|
+
const withTransforms = output || createBox();
|
|
8364
8424
|
copyBoxInto(withTransforms, box);
|
|
8365
8425
|
for (let i = 0; i < this.path.length; i++) {
|
|
8366
8426
|
const node = this.path[i];
|
|
@@ -8368,10 +8428,8 @@
|
|
|
8368
8428
|
node.options.layoutScroll &&
|
|
8369
8429
|
node.scroll &&
|
|
8370
8430
|
node !== node.root) {
|
|
8371
|
-
|
|
8372
|
-
|
|
8373
|
-
y: -node.scroll.offset.y,
|
|
8374
|
-
});
|
|
8431
|
+
translateAxis(withTransforms.x, -node.scroll.offset.x);
|
|
8432
|
+
translateAxis(withTransforms.y, -node.scroll.offset.y);
|
|
8375
8433
|
}
|
|
8376
8434
|
if (!hasTransform(node.latestValues))
|
|
8377
8435
|
continue;
|
|
@@ -8514,8 +8572,7 @@
|
|
|
8514
8572
|
}
|
|
8515
8573
|
else if (this.targetDelta) {
|
|
8516
8574
|
if (Boolean(this.resumingFrom)) {
|
|
8517
|
-
|
|
8518
|
-
this.target = this.applyTransform(this.layout.layoutBox);
|
|
8575
|
+
this.applyTransform(this.layout.layoutBox, false, this.target);
|
|
8519
8576
|
}
|
|
8520
8577
|
else {
|
|
8521
8578
|
copyBoxInto(this.target, this.layout.layoutBox);
|
|
@@ -9246,6 +9303,18 @@
|
|
|
9246
9303
|
function clearIsLayoutDirty(node) {
|
|
9247
9304
|
node.isLayoutDirty = false;
|
|
9248
9305
|
}
|
|
9306
|
+
/**
|
|
9307
|
+
* When a node is animation-blocked (e.g. during drag) and its component
|
|
9308
|
+
* didn't re-render (memoized), willUpdate() is never called so there's
|
|
9309
|
+
* no snapshot. Use the previous layout as a snapshot and mark dirty so
|
|
9310
|
+
* resetTransform/updateLayout/notifyLayoutUpdate process it normally.
|
|
9311
|
+
*/
|
|
9312
|
+
function ensureDraggedNodesSnapshotted(node) {
|
|
9313
|
+
if (node.isAnimationBlocked && node.layout && !node.isLayoutDirty) {
|
|
9314
|
+
node.snapshot = node.layout;
|
|
9315
|
+
node.isLayoutDirty = true;
|
|
9316
|
+
}
|
|
9317
|
+
}
|
|
9249
9318
|
function resetTransformStyle(node) {
|
|
9250
9319
|
const { visualElement } = node.options;
|
|
9251
9320
|
if (visualElement && visualElement.getProps().onBeforeLayoutMeasure) {
|