motion-dom 12.35.2 → 12.36.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.
@@ -5,7 +5,9 @@ import { isObject } from 'motion-utils';
5
5
  * that works across iframes
6
6
  */
7
7
  function isHTMLElement(element) {
8
- return isObject(element) && "offsetHeight" in element;
8
+ return (isObject(element) &&
9
+ "offsetHeight" in element &&
10
+ !("ownerSVGElement" in element));
9
11
  }
10
12
 
11
13
  export { isHTMLElement };
@@ -1 +1 @@
1
- {"version":3,"file":"is-html-element.mjs","sources":["../../../src/utils/is-html-element.ts"],"sourcesContent":["import { isObject } from \"motion-utils\"\n\n/**\n * Checks if an element is an HTML element in a way\n * that works across iframes\n */\nexport function isHTMLElement(element: unknown): element is HTMLElement {\n return isObject(element) && \"offsetHeight\" in element\n}\n"],"names":[],"mappings":";;AAEA;;;AAGG;AACG,SAAU,aAAa,CAAC,OAAgB,EAAA;IAC1C,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,cAAc,IAAI,OAAO;AACzD;;;;"}
1
+ {"version":3,"file":"is-html-element.mjs","sources":["../../../src/utils/is-html-element.ts"],"sourcesContent":["import { isObject } from \"motion-utils\"\n\n/**\n * Checks if an element is an HTML element in a way\n * that works across iframes\n */\nexport function isHTMLElement(element: unknown): element is HTMLElement {\n return (\n isObject(element) &&\n \"offsetHeight\" in element &&\n !(\"ownerSVGElement\" in element)\n )\n}\n"],"names":[],"mappings":";;AAEA;;;AAGG;AACG,SAAU,aAAa,CAAC,OAAgB,EAAA;AAC1C,IAAA,QACI,QAAQ,CAAC,OAAO,CAAC;AACjB,QAAA,cAAc,IAAI,OAAO;AACzB,QAAA,EAAE,iBAAiB,IAAI,OAAO,CAAC;AAEvC;;;;"}
@@ -92,7 +92,16 @@ function attachFollow(value, source, options = {}) {
92
92
  frame.postRender(scheduleAnimation);
93
93
  }, stopAnimation);
94
94
  if (isMotionValue(source)) {
95
- const removeSourceOnChange = source.on("change", (v) => value.set(parseValue(v, unit)));
95
+ let skipNextAnimation = options.skipInitialAnimation === true;
96
+ const removeSourceOnChange = source.on("change", (v) => {
97
+ if (skipNextAnimation) {
98
+ skipNextAnimation = false;
99
+ value.jump(parseValue(v, unit), false);
100
+ }
101
+ else {
102
+ value.set(parseValue(v, unit));
103
+ }
104
+ });
96
105
  const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
97
106
  return () => {
98
107
  removeSourceOnChange();
@@ -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/**\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 const removeSourceOnChange = source.on(\"change\", (v) =>\n value.set(parseValue(v, unit) as T)\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":";;;;;AAeA;;;;;;;;;;;;;;;;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;AACJ,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,C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AoB,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;;;;"}
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;AACJ,IAAA,CAAC;IAED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AAiB,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
@@ -734,14 +734,15 @@ interface MotionNodeDraggableOptions {
734
734
  */
735
735
  dragControls?: any;
736
736
  /**
737
- * If true, element will snap back to its origin when dragging ends.
737
+ * If `true`, element will snap back to its origin when dragging ends.
738
+ * Set to `"x"` or `"y"` to only snap back on a specific axis.
738
739
  *
739
740
  * Enabling this is the equivalent of setting all `dragConstraints` axes to `0`
740
741
  * with `dragElastic={1}`, but when used together `dragConstraints` can define
741
742
  * a wider draggable area and `dragSnapToOrigin` will ensure the element
742
743
  * animates back to its origin on release.
743
744
  */
744
- dragSnapToOrigin?: boolean;
745
+ dragSnapToOrigin?: boolean | "x" | "y";
745
746
  /**
746
747
  * By default, if `drag` is defined on a component then an event listener will be attached
747
748
  * to automatically initiate dragging when a user presses down on it.
@@ -894,7 +895,7 @@ interface MotionNodeLayoutOptions {
894
895
  *
895
896
  * @public
896
897
  */
897
- layout?: boolean | "position" | "size" | "preserve-aspect";
898
+ layout?: boolean | "position" | "size" | "preserve-aspect" | "x" | "y";
898
899
  /**
899
900
  * Enable shared layout transitions between different components with the same `layoutId`.
900
901
  *
@@ -3517,7 +3518,17 @@ declare function transform<T>(inputRange: number[], outputRange: T[], options?:
3517
3518
  * Options for useFollowValue hook, extending ValueAnimationTransition
3518
3519
  * but excluding lifecycle callbacks that don't make sense for the hook pattern.
3519
3520
  */
3520
- type FollowValueOptions = Omit<ValueAnimationTransition, "onUpdate" | "onComplete" | "onPlay" | "onRepeat" | "onStop">;
3521
+ type FollowValueOptions = Omit<ValueAnimationTransition, "onUpdate" | "onComplete" | "onPlay" | "onRepeat" | "onStop"> & {
3522
+ /**
3523
+ * When true, the first change from a tracked `MotionValue` source
3524
+ * will jump to the new value instead of animating. Subsequent
3525
+ * changes animate normally. This prevents unwanted animations
3526
+ * on page refresh or back navigation (e.g. `useScroll` + `useSpring`).
3527
+ *
3528
+ * @default false
3529
+ */
3530
+ skipInitialAnimation?: boolean;
3531
+ };
3521
3532
  /**
3522
3533
  * Create a `MotionValue` that animates to its latest value using any transition type.
3523
3534
  * Can either be a value or track another `MotionValue`.
@@ -4357,7 +4368,7 @@ interface ProjectionNodeOptions {
4357
4368
  layoutRoot?: boolean;
4358
4369
  alwaysMeasureLayout?: boolean;
4359
4370
  onExitComplete?: VoidFunction;
4360
- animationType?: "size" | "position" | "both" | "preserve-aspect";
4371
+ animationType?: "size" | "position" | "both" | "preserve-aspect" | "x" | "y";
4361
4372
  layoutId?: string;
4362
4373
  layout?: boolean | string;
4363
4374
  visualElement?: VisualElement;
@@ -60,8 +60,7 @@
60
60
  const queue = addToCurrentFrame ? thisFrame : nextFrame;
61
61
  if (keepAlive)
62
62
  toKeepAlive.add(callback);
63
- if (!queue.has(callback))
64
- queue.add(callback);
63
+ queue.add(callback);
65
64
  return callback;
66
65
  },
67
66
  /**
@@ -86,7 +85,10 @@
86
85
  return;
87
86
  }
88
87
  isProcessing = true;
89
- [thisFrame, nextFrame] = [nextFrame, thisFrame];
88
+ // Swap this frame and the next to avoid GC
89
+ const prevFrame = thisFrame;
90
+ thisFrame = nextFrame;
91
+ nextFrame = prevFrame;
90
92
  // Execute this frame
91
93
  thisFrame.forEach(triggerCallback);
92
94
  /**
@@ -125,11 +127,12 @@
125
127
  }, {});
126
128
  const { setup, read, resolveKeyframes, preUpdate, update, preRender, render, postRender, } = steps;
127
129
  const processBatch = () => {
128
- const timestamp = motionUtils.MotionGlobalConfig.useManualTiming
130
+ const useManualTiming = motionUtils.MotionGlobalConfig.useManualTiming;
131
+ const timestamp = useManualTiming
129
132
  ? state.timestamp
130
133
  : performance.now();
131
134
  runNextFrame = false;
132
- if (!motionUtils.MotionGlobalConfig.useManualTiming) {
135
+ if (!useManualTiming) {
133
136
  state.delta = useDefaultElapsed
134
137
  ? 1000 / 60
135
138
  : Math.max(Math.min(timestamp - state.timestamp, maxElapsed), 1);
@@ -1861,8 +1864,18 @@
1861
1864
  }
1862
1865
  const positionalValues = {
1863
1866
  // Dimensions
1864
- width: ({ x }, { paddingLeft = "0", paddingRight = "0" }) => x.max - x.min - parseFloat(paddingLeft) - parseFloat(paddingRight),
1865
- height: ({ y }, { paddingTop = "0", paddingBottom = "0" }) => y.max - y.min - parseFloat(paddingTop) - parseFloat(paddingBottom),
1867
+ width: ({ x }, { paddingLeft = "0", paddingRight = "0", boxSizing }) => {
1868
+ const width = x.max - x.min;
1869
+ return boxSizing === "border-box"
1870
+ ? width
1871
+ : width - parseFloat(paddingLeft) - parseFloat(paddingRight);
1872
+ },
1873
+ height: ({ y }, { paddingTop = "0", paddingBottom = "0", boxSizing }) => {
1874
+ const height = y.max - y.min;
1875
+ return boxSizing === "border-box"
1876
+ ? height
1877
+ : height - parseFloat(paddingTop) - parseFloat(paddingBottom);
1878
+ },
1866
1879
  top: (_bbox, { top }) => parseFloat(top),
1867
1880
  left: (_bbox, { left }) => parseFloat(left),
1868
1881
  bottom: ({ y }, { top }) => parseFloat(top) + (y.max - y.min),
@@ -2554,7 +2567,9 @@
2554
2567
  * If we can't animate this value with the resolved keyframes
2555
2568
  * then we should complete it immediately.
2556
2569
  */
2570
+ let canAnimateValue = true;
2557
2571
  if (!canAnimate(keyframes, name, type, velocity)) {
2572
+ canAnimateValue = false;
2558
2573
  if (motionUtils.MotionGlobalConfig.instantAnimations || !delay) {
2559
2574
  onUpdate?.(getFinalKeyframe$1(keyframes, options, finalKeyframe));
2560
2575
  }
@@ -2591,8 +2606,13 @@
2591
2606
  * Animate via WAAPI if possible. If this is a handoff animation, the optimised animation will be running via
2592
2607
  * WAAPI. Therefore, this animation must be JS to ensure it runs "under" the
2593
2608
  * optimised animation.
2609
+ *
2610
+ * Also skip WAAPI when keyframes aren't animatable, as the resolved
2611
+ * values may not be valid CSS and would trigger browser warnings.
2594
2612
  */
2595
- const useWaapi = !isHandoff && supportsBrowserAnimation(resolvedOptions);
2613
+ const useWaapi = canAnimateValue &&
2614
+ !isHandoff &&
2615
+ supportsBrowserAnimation(resolvedOptions);
2596
2616
  const element = resolvedOptions.motionValue?.owner?.current;
2597
2617
  const animation = useWaapi
2598
2618
  ? new NativeAnimationExtended({
@@ -4200,7 +4220,9 @@
4200
4220
  * that works across iframes
4201
4221
  */
4202
4222
  function isHTMLElement(element) {
4203
- return motionUtils.isObject(element) && "offsetHeight" in element;
4223
+ return (motionUtils.isObject(element) &&
4224
+ "offsetHeight" in element &&
4225
+ !("ownerSVGElement" in element));
4204
4226
  }
4205
4227
 
4206
4228
  const translateAlias$1 = {
@@ -4980,7 +5002,16 @@
4980
5002
  frame.postRender(scheduleAnimation);
4981
5003
  }, stopAnimation);
4982
5004
  if (isMotionValue(source)) {
4983
- const removeSourceOnChange = source.on("change", (v) => value.set(parseValue(v, unit)));
5005
+ let skipNextAnimation = options.skipInitialAnimation === true;
5006
+ const removeSourceOnChange = source.on("change", (v) => {
5007
+ if (skipNextAnimation) {
5008
+ skipNextAnimation = false;
5009
+ value.jump(parseValue(v, unit), false);
5010
+ }
5011
+ else {
5012
+ value.set(parseValue(v, unit));
5013
+ }
5014
+ });
4984
5015
  const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
4985
5016
  return () => {
4986
5017
  removeSourceOnChange();
@@ -9094,6 +9125,12 @@
9094
9125
  axisSnapshot.max = axisSnapshot.min + length;
9095
9126
  });
9096
9127
  }
9128
+ else if (animationType === "x" || animationType === "y") {
9129
+ const snapAxis = animationType === "x" ? "y" : "x";
9130
+ copyAxisInto(isShared
9131
+ ? snapshot.measuredBox[snapAxis]
9132
+ : snapshot.layoutBox[snapAxis], layout[snapAxis]);
9133
+ }
9097
9134
  else if (shouldAnimatePositionOnly(animationType, snapshot.layoutBox, layout)) {
9098
9135
  eachAxis((axis) => {
9099
9136
  const axisSnapshot = isShared