motion-dom 12.35.1 → 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.
Files changed (53) hide show
  1. package/dist/cjs/index.js +224 -86
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/es/animation/AsyncMotionValueAnimation.mjs +8 -1
  4. package/dist/es/animation/AsyncMotionValueAnimation.mjs.map +1 -1
  5. package/dist/es/animation/JSAnimation.mjs +17 -0
  6. package/dist/es/animation/JSAnimation.mjs.map +1 -1
  7. package/dist/es/animation/NativeAnimationExtended.mjs +6 -1
  8. package/dist/es/animation/NativeAnimationExtended.mjs.map +1 -1
  9. package/dist/es/animation/generators/inertia.mjs +3 -3
  10. package/dist/es/animation/generators/inertia.mjs.map +1 -1
  11. package/dist/es/animation/generators/spring.mjs +329 -0
  12. package/dist/es/animation/generators/spring.mjs.map +1 -0
  13. package/dist/es/animation/generators/utils/velocity.mjs +2 -2
  14. package/dist/es/animation/generators/utils/velocity.mjs.map +1 -1
  15. package/dist/es/animation/keyframes/utils/unit-conversion.mjs +12 -2
  16. package/dist/es/animation/keyframes/utils/unit-conversion.mjs.map +1 -1
  17. package/dist/es/animation/utils/replace-transition-type.mjs +1 -1
  18. package/dist/es/effects/MotionValueState.mjs +0 -5
  19. package/dist/es/effects/MotionValueState.mjs.map +1 -1
  20. package/dist/es/effects/style/transform.mjs +1 -2
  21. package/dist/es/effects/style/transform.mjs.map +1 -1
  22. package/dist/es/effects/utils/create-effect.mjs +1 -1
  23. package/dist/es/effects/utils/create-effect.mjs.map +1 -1
  24. package/dist/es/frameloop/batcher.mjs +3 -2
  25. package/dist/es/frameloop/batcher.mjs.map +1 -1
  26. package/dist/es/frameloop/render-step.mjs +5 -3
  27. package/dist/es/frameloop/render-step.mjs.map +1 -1
  28. package/dist/es/index.mjs +1 -1
  29. package/dist/es/layout/LayoutAnimationBuilder.mjs.map +1 -1
  30. package/dist/es/projection/geometry/delta-apply.mjs +5 -4
  31. package/dist/es/projection/geometry/delta-apply.mjs.map +1 -1
  32. package/dist/es/projection/node/create-projection-node.mjs +24 -10
  33. package/dist/es/projection/node/create-projection-node.mjs.map +1 -1
  34. package/dist/es/utils/is-html-element.mjs +3 -1
  35. package/dist/es/utils/is-html-element.mjs.map +1 -1
  36. package/dist/es/value/follow-value.mjs +29 -10
  37. package/dist/es/value/follow-value.mjs.map +1 -1
  38. package/dist/es/value/types/complex/index.mjs +27 -5
  39. package/dist/es/value/types/complex/index.mjs.map +1 -1
  40. package/dist/index.d.ts +25 -8
  41. package/dist/motion-dom.dev.js +224 -86
  42. package/dist/motion-dom.js +1 -1
  43. package/dist/size-rollup-motion-value.js +1 -1
  44. package/dist/size-rollup-motion-value.js.map +1 -1
  45. package/dist/size-rollup-style-effect.js +1 -1
  46. package/dist/size-rollup-style-effect.js.map +1 -1
  47. package/package.json +3 -3
  48. package/dist/es/animation/generators/spring/defaults.mjs +0 -28
  49. package/dist/es/animation/generators/spring/defaults.mjs.map +0 -1
  50. package/dist/es/animation/generators/spring/find.mjs +0 -85
  51. package/dist/es/animation/generators/spring/find.mjs.map +0 -1
  52. package/dist/es/animation/generators/spring/index.mjs +0 -181
  53. package/dist/es/animation/generators/spring/index.mjs.map +0 -1
@@ -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;;;;"}
@@ -52,16 +52,23 @@ function attachFollow(value, source, options = {}) {
52
52
  }
53
53
  };
54
54
  const startAnimation = () => {
55
- stopAnimation();
56
55
  const currentValue = asNumber(value.get());
57
56
  const targetValue = asNumber(latestValue);
58
57
  // Don't animate if we're already at the target
59
58
  if (currentValue === targetValue) {
59
+ stopAnimation();
60
60
  return;
61
61
  }
62
+ // Use the running animation's analytical velocity for accuracy,
63
+ // falling back to the MotionValue's velocity for the initial animation.
64
+ // This prevents systematic velocity loss at high frame rates (240hz+).
65
+ const velocity = activeAnimation
66
+ ? activeAnimation.getGeneratorVelocity()
67
+ : value.getVelocity();
68
+ stopAnimation();
62
69
  activeAnimation = new JSAnimation({
63
70
  keyframes: [currentValue, targetValue],
64
- velocity: value.getVelocity(),
71
+ velocity,
65
72
  // Default to spring if no type specified (matches useSpring behavior)
66
73
  type: "spring",
67
74
  restDelta: 0.001,
@@ -70,19 +77,31 @@ function attachFollow(value, source, options = {}) {
70
77
  onUpdate: latestSetter,
71
78
  });
72
79
  };
80
+ // Use a stable function reference so the frame loop Set deduplicates
81
+ // multiple calls within the same frame (e.g. rapid mouse events)
82
+ const scheduleAnimation = () => {
83
+ startAnimation();
84
+ value["events"].animationStart?.notify();
85
+ activeAnimation?.then(() => {
86
+ value["events"].animationComplete?.notify();
87
+ });
88
+ };
73
89
  value.attach((v, set) => {
74
90
  latestValue = v;
75
91
  latestSetter = (latest) => set(parseValue(latest, unit));
76
- frame.postRender(() => {
77
- startAnimation();
78
- value["events"].animationStart?.notify();
79
- activeAnimation?.then(() => {
80
- value["events"].animationComplete?.notify();
81
- });
82
- });
92
+ frame.postRender(scheduleAnimation);
83
93
  }, stopAnimation);
84
94
  if (isMotionValue(source)) {
85
- 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
+ });
86
105
  const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
87
106
  return () => {
88
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 stopAnimation()\n\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 return\n }\n\n activeAnimation = new JSAnimation({\n keyframes: [currentValue, targetValue],\n velocity: value.getVelocity(),\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 value.attach((v, set) => {\n latestValue = v\n latestSetter = (latest) => set(parseValue(latest, unit) as T)\n\n frame.postRender(() => {\n startAnimation()\n value[\"events\"].animationStart?.notify()\n activeAnimation?.then(() => {\n value[\"events\"].animationComplete?.notify()\n })\n })\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;AACxB,QAAA,aAAa,EAAE;QAEf,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAC1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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;;;;"}
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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AM,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;;;;"}
@@ -52,8 +52,7 @@ function analyseComplexValue(value) {
52
52
  function parseComplexValue(v) {
53
53
  return analyseComplexValue(v).values;
54
54
  }
55
- function createTransformer(source) {
56
- const { split, types } = analyseComplexValue(source);
55
+ function buildTransformer({ split, types }) {
57
56
  const numSections = split.length;
58
57
  return (v) => {
59
58
  let output = "";
@@ -75,11 +74,34 @@ function createTransformer(source) {
75
74
  return output;
76
75
  };
77
76
  }
77
+ function createTransformer(source) {
78
+ return buildTransformer(analyseComplexValue(source));
79
+ }
78
80
  const convertNumbersToZero = (v) => typeof v === "number" ? 0 : color.test(v) ? color.getAnimatableNone(v) : v;
81
+ /**
82
+ * Convert a parsed value to its zero equivalent, but preserve numbers
83
+ * that act as divisors in CSS calc() expressions.
84
+ *
85
+ * analyseComplexValue extracts numbers from CSS strings and puts the
86
+ * surrounding text into a `split` template array. For example:
87
+ * "calc(var(--gap) / 5)" → values: [var(--gap), 5]
88
+ * split: ["calc(", " / ", ")"]
89
+ *
90
+ * When building a zero-equivalent for animation, naively zeroing all
91
+ * numbers turns the divisor into 0 → "calc(var(--gap) / 0)" → NaN.
92
+ * We detect this by checking whether the text preceding a number
93
+ * (split[i]) ends with "/" — the CSS calc division operator.
94
+ */
95
+ const convertToZero = (value, splitBefore) => {
96
+ if (typeof value === "number") {
97
+ return splitBefore?.trim().endsWith("/") ? value : 0;
98
+ }
99
+ return convertNumbersToZero(value);
100
+ };
79
101
  function getAnimatableNone(v) {
80
- const parsed = parseComplexValue(v);
81
- const transformer = createTransformer(v);
82
- return transformer(parsed.map(convertNumbersToZero));
102
+ const info = analyseComplexValue(v);
103
+ const transformer = buildTransformer(info);
104
+ return transformer(info.values.map((value, i) => convertToZero(value, info.split[i])));
83
105
  }
84
106
  const complex = {
85
107
  test,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../../src/value/types/complex/index.ts"],"sourcesContent":["import { AnyResolvedKeyframe } from \"../../../animation/types\"\nimport { CSSVariableToken } from \"../../../animation/utils/is-css-variable\"\nimport { color } from \"../color\"\nimport { Color } from \"../types\"\nimport { colorRegex } from \"../utils/color-regex\"\nimport { floatRegex } from \"../utils/float-regex\"\nimport { sanitize } from \"../utils/sanitize\"\n\nfunction test(v: any) {\n return (\n isNaN(v) &&\n typeof v === \"string\" &&\n (v.match(floatRegex)?.length || 0) +\n (v.match(colorRegex)?.length || 0) >\n 0\n )\n}\n\nconst NUMBER_TOKEN = \"number\"\nconst COLOR_TOKEN = \"color\"\nconst VAR_TOKEN = \"var\"\nconst VAR_FUNCTION_TOKEN = \"var(\"\nconst SPLIT_TOKEN = \"${}\"\n\nexport type ComplexValues = Array<\n CSSVariableToken | AnyResolvedKeyframe | Color\n>\n\nexport interface ValueIndexes {\n color: number[]\n number: number[]\n var: number[]\n}\n\nexport interface ComplexValueInfo {\n values: ComplexValues\n split: string[]\n indexes: ValueIndexes\n types: Array<keyof ValueIndexes>\n}\n\n// this regex consists of the `singleCssVariableRegex|rgbHSLValueRegex|digitRegex`\nconst complexRegex =\n /var\\s*\\(\\s*--(?:[\\w-]+\\s*|[\\w-]+\\s*,(?:\\s*[^)(\\s]|\\s*\\((?:[^)(]|\\([^)(]*\\))*\\))+\\s*)\\)|#[\\da-f]{3,8}|(?:rgb|hsl)a?\\((?:-?[\\d.]+%?[,\\s]+){2}-?[\\d.]+%?\\s*(?:[,/]\\s*)?(?:\\b\\d+(?:\\.\\d+)?|\\.\\d+)?%?\\)|-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)/giu\n\nexport function analyseComplexValue(\n value: AnyResolvedKeyframe\n): ComplexValueInfo {\n const originalValue = value.toString()\n\n const values: ComplexValues = []\n const indexes: ValueIndexes = {\n color: [],\n number: [],\n var: [],\n }\n const types: Array<keyof ValueIndexes> = []\n\n let i = 0\n const tokenised = originalValue.replace(complexRegex, (parsedValue) => {\n if (color.test(parsedValue)) {\n indexes.color.push(i)\n types.push(COLOR_TOKEN)\n values.push(color.parse(parsedValue))\n } else if (parsedValue.startsWith(VAR_FUNCTION_TOKEN)) {\n indexes.var.push(i)\n types.push(VAR_TOKEN)\n values.push(parsedValue)\n } else {\n indexes.number.push(i)\n types.push(NUMBER_TOKEN)\n values.push(parseFloat(parsedValue))\n }\n ++i\n return SPLIT_TOKEN\n })\n const split = tokenised.split(SPLIT_TOKEN)\n\n return { values, split, indexes, types }\n}\n\nfunction parseComplexValue(v: AnyResolvedKeyframe) {\n return analyseComplexValue(v).values\n}\n\nfunction createTransformer(source: AnyResolvedKeyframe) {\n const { split, types } = analyseComplexValue(source)\n\n const numSections = split.length\n return (v: Array<CSSVariableToken | Color | number | string>) => {\n let output = \"\"\n for (let i = 0; i < numSections; i++) {\n output += split[i]\n if (v[i] !== undefined) {\n const type = types[i]\n if (type === NUMBER_TOKEN) {\n output += sanitize(v[i] as number)\n } else if (type === COLOR_TOKEN) {\n output += color.transform(v[i] as Color)\n } else {\n output += v[i]\n }\n }\n }\n\n return output\n }\n}\n\nconst convertNumbersToZero = (v: number | string) =>\n typeof v === \"number\" ? 0 : color.test(v) ? color.getAnimatableNone(v) : v\n\nfunction getAnimatableNone(v: AnyResolvedKeyframe) {\n const parsed = parseComplexValue(v)\n const transformer = createTransformer(v)\n return transformer(parsed.map(convertNumbersToZero))\n}\n\nexport const complex = {\n test,\n parse: parseComplexValue,\n createTransformer,\n getAnimatableNone,\n}\n"],"names":[],"mappings":";;;;;AAQA,SAAS,IAAI,CAAC,CAAM,EAAA;AAChB,IAAA,QACI,KAAK,CAAC,CAAC,CAAC;QACR,OAAO,CAAC,KAAK,QAAQ;QACrB,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;aAC5B,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;AAClC,YAAA,CAAC;AAEb;AAEA,MAAM,YAAY,GAAG,QAAQ;AAC7B,MAAM,WAAW,GAAG,OAAO;AAC3B,MAAM,SAAS,GAAG,KAAK;AACvB,MAAM,kBAAkB,GAAG,MAAM;AACjC,MAAM,WAAW,GAAG,KAAK;AAmBzB;AACA,MAAM,YAAY,GACd,iOAAiO;AAE/N,SAAU,mBAAmB,CAC/B,KAA0B,EAAA;AAE1B,IAAA,MAAM,aAAa,GAAG,KAAK,CAAC,QAAQ,EAAE;IAEtC,MAAM,MAAM,GAAkB,EAAE;AAChC,IAAA,MAAM,OAAO,GAAiB;AAC1B,QAAA,KAAK,EAAE,EAAE;AACT,QAAA,MAAM,EAAE,EAAE;AACV,QAAA,GAAG,EAAE,EAAE;KACV;IACD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"file":"index.mjs","sources":["../../../../../src/value/types/complex/index.ts"],"sourcesContent":["import { AnyResolvedKeyframe } from \"../../../animation/types\"\nimport { CSSVariableToken } from \"../../../animation/utils/is-css-variable\"\nimport { color } from \"../color\"\nimport { Color } from \"../types\"\nimport { colorRegex } from \"../utils/color-regex\"\nimport { floatRegex } from \"../utils/float-regex\"\nimport { sanitize } from \"../utils/sanitize\"\n\nfunction test(v: any) {\n return (\n isNaN(v) &&\n typeof v === \"string\" &&\n (v.match(floatRegex)?.length || 0) +\n (v.match(colorRegex)?.length || 0) >\n 0\n )\n}\n\nconst NUMBER_TOKEN = \"number\"\nconst COLOR_TOKEN = \"color\"\nconst VAR_TOKEN = \"var\"\nconst VAR_FUNCTION_TOKEN = \"var(\"\nconst SPLIT_TOKEN = \"${}\"\n\nexport type ComplexValues = Array<\n CSSVariableToken | AnyResolvedKeyframe | Color\n>\n\nexport interface ValueIndexes {\n color: number[]\n number: number[]\n var: number[]\n}\n\nexport interface ComplexValueInfo {\n values: ComplexValues\n split: string[]\n indexes: ValueIndexes\n types: Array<keyof ValueIndexes>\n}\n\n// this regex consists of the `singleCssVariableRegex|rgbHSLValueRegex|digitRegex`\nconst complexRegex =\n /var\\s*\\(\\s*--(?:[\\w-]+\\s*|[\\w-]+\\s*,(?:\\s*[^)(\\s]|\\s*\\((?:[^)(]|\\([^)(]*\\))*\\))+\\s*)\\)|#[\\da-f]{3,8}|(?:rgb|hsl)a?\\((?:-?[\\d.]+%?[,\\s]+){2}-?[\\d.]+%?\\s*(?:[,/]\\s*)?(?:\\b\\d+(?:\\.\\d+)?|\\.\\d+)?%?\\)|-?(?:\\d+(?:\\.\\d+)?|\\.\\d+)/giu\n\nexport function analyseComplexValue(\n value: AnyResolvedKeyframe\n): ComplexValueInfo {\n const originalValue = value.toString()\n\n const values: ComplexValues = []\n const indexes: ValueIndexes = {\n color: [],\n number: [],\n var: [],\n }\n const types: Array<keyof ValueIndexes> = []\n\n let i = 0\n const tokenised = originalValue.replace(complexRegex, (parsedValue) => {\n if (color.test(parsedValue)) {\n indexes.color.push(i)\n types.push(COLOR_TOKEN)\n values.push(color.parse(parsedValue))\n } else if (parsedValue.startsWith(VAR_FUNCTION_TOKEN)) {\n indexes.var.push(i)\n types.push(VAR_TOKEN)\n values.push(parsedValue)\n } else {\n indexes.number.push(i)\n types.push(NUMBER_TOKEN)\n values.push(parseFloat(parsedValue))\n }\n ++i\n return SPLIT_TOKEN\n })\n const split = tokenised.split(SPLIT_TOKEN)\n\n return { values, split, indexes, types }\n}\n\nfunction parseComplexValue(v: AnyResolvedKeyframe) {\n return analyseComplexValue(v).values\n}\n\nfunction buildTransformer({ split, types }: ComplexValueInfo) {\n const numSections = split.length\n return (v: Array<CSSVariableToken | Color | number | string>) => {\n let output = \"\"\n for (let i = 0; i < numSections; i++) {\n output += split[i]\n if (v[i] !== undefined) {\n const type = types[i]\n if (type === NUMBER_TOKEN) {\n output += sanitize(v[i] as number)\n } else if (type === COLOR_TOKEN) {\n output += color.transform(v[i] as Color)\n } else {\n output += v[i]\n }\n }\n }\n\n return output\n }\n}\n\nfunction createTransformer(source: AnyResolvedKeyframe) {\n return buildTransformer(analyseComplexValue(source))\n}\n\nconst convertNumbersToZero = (v: number | string) =>\n typeof v === \"number\" ? 0 : color.test(v) ? color.getAnimatableNone(v) : v\n\n/**\n * Convert a parsed value to its zero equivalent, but preserve numbers\n * that act as divisors in CSS calc() expressions.\n *\n * analyseComplexValue extracts numbers from CSS strings and puts the\n * surrounding text into a `split` template array. For example:\n * \"calc(var(--gap) / 5)\" → values: [var(--gap), 5]\n * split: [\"calc(\", \" / \", \")\"]\n *\n * When building a zero-equivalent for animation, naively zeroing all\n * numbers turns the divisor into 0 → \"calc(var(--gap) / 0)\" → NaN.\n * We detect this by checking whether the text preceding a number\n * (split[i]) ends with \"/\" — the CSS calc division operator.\n */\nconst convertToZero = (\n value: ComplexValues[number],\n splitBefore: string\n): ComplexValues[number] => {\n if (typeof value === \"number\") {\n return splitBefore?.trim().endsWith(\"/\") ? value : 0\n }\n return convertNumbersToZero(value as string)\n}\n\nfunction getAnimatableNone(v: AnyResolvedKeyframe) {\n const info = analyseComplexValue(v)\n const transformer = buildTransformer(info)\n return transformer(\n info.values.map((value, i) => convertToZero(value, info.split[i]))\n )\n}\n\nexport const complex = {\n test,\n parse: parseComplexValue,\n createTransformer,\n getAnimatableNone,\n}\n"],"names":[],"mappings":";;;;;AAQA,SAAS,IAAI,CAAC,CAAM,EAAA;AAChB,IAAA,QACI,KAAK,CAAC,CAAC,CAAC;QACR,OAAO,CAAC,KAAK,QAAQ;QACrB,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;aAC5B,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;AAClC,YAAA,CAAC;AAEb;AAEA,MAAM,YAAY,GAAG,QAAQ;AAC7B,MAAM,WAAW,GAAG,OAAO;AAC3B,MAAM,SAAS,GAAG,KAAK;AACvB,MAAM,kBAAkB,GAAG,MAAM;AACjC,MAAM,WAAW,GAAG,KAAK;AAmBzB;AACA,MAAM,YAAY,GACd,iOAAiO;AAE/N,SAAU,mBAAmB,CAC/B,KAA0B,EAAA;AAE1B,IAAA,MAAM,aAAa,GAAG,KAAK,CAAC,QAAQ,EAAE;IAEtC,MAAM,MAAM,GAAkB,EAAE;AAChC,IAAA,MAAM,OAAO,GAAiB;AAC1B,QAAA,KAAK,EAAE,EAAE;AACT,QAAA,MAAM,EAAE,EAAE;AACV,QAAA,GAAG,EAAE,EAAE;KACV;IACD,MAAM,KAAK,GAA8B,EAAE;IAE3C,IAAI,CAAC,GAAG,CAAC;IACT,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,WAAW,KAAI;AAClE,QAAA,IAAI,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;AACzB,YAAA,OAAO,CAAC,KAAK,CAAC,IAAI,CAA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CAAC,KAAK,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CACrE;AACL;AAEO,MAAM,OAAO,GAAG;IACnB,IAAI;AACJ,IAAA,KAAK,EAAE,iBAAiB;IACxB,iBAAiB;IACjB,iBAAiB;;;;;"}
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
  *
@@ -1558,6 +1559,7 @@ interface AnimationState$1<V> {
1558
1559
  interface KeyframeGenerator<V> {
1559
1560
  calculatedDuration: null | number;
1560
1561
  next: (t: number) => AnimationState$1<V>;
1562
+ velocity?: (t: number) => number;
1561
1563
  toString: () => string;
1562
1564
  }
1563
1565
  interface DOMValueAnimationOptions<V extends AnyResolvedKeyframe = number> extends ValueAnimationTransition<V> {
@@ -2372,6 +2374,12 @@ declare class JSAnimation<T extends number | string> extends WithPromise impleme
2372
2374
  get iterationDuration(): number;
2373
2375
  get time(): number;
2374
2376
  set time(newTime: number);
2377
+ /**
2378
+ * Returns the generator's velocity at the current time in units/second.
2379
+ * Uses the analytical derivative when available (springs), avoiding
2380
+ * the MotionValue's frame-dependent velocity estimation.
2381
+ */
2382
+ getGeneratorVelocity(): number;
2375
2383
  get speed(): number;
2376
2384
  set speed(newSpeed: number);
2377
2385
  play(): void;
@@ -3020,7 +3028,6 @@ declare class MotionValueState {
3020
3028
  private values;
3021
3029
  set(name: string, value: MotionValue, render?: VoidFunction, computed?: MotionValue, useDefaultValueType?: boolean): () => void;
3022
3030
  get(name: string): MotionValue | undefined;
3023
- destroy(): void;
3024
3031
  }
3025
3032
 
3026
3033
  declare const addAttrValue: (element: HTMLElement | SVGElement, state: MotionValueState, key: string, value: MotionValue) => () => void;
@@ -3511,7 +3518,17 @@ declare function transform<T>(inputRange: number[], outputRange: T[], options?:
3511
3518
  * Options for useFollowValue hook, extending ValueAnimationTransition
3512
3519
  * but excluding lifecycle callbacks that don't make sense for the hook pattern.
3513
3520
  */
3514
- 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
+ };
3515
3532
  /**
3516
3533
  * Create a `MotionValue` that animates to its latest value using any transition type.
3517
3534
  * Can either be a value or track another `MotionValue`.
@@ -3682,7 +3699,7 @@ interface ComplexValueInfo {
3682
3699
  }
3683
3700
  declare function analyseComplexValue(value: AnyResolvedKeyframe): ComplexValueInfo;
3684
3701
  declare function parseComplexValue(v: AnyResolvedKeyframe): ComplexValues;
3685
- declare function createTransformer(source: AnyResolvedKeyframe): (v: Array<CSSVariableToken | Color | number | string>) => string;
3702
+ declare function createTransformer(source: AnyResolvedKeyframe): (v: (string | number | Color)[]) => string;
3686
3703
  declare function getAnimatableNone$1(v: AnyResolvedKeyframe): string;
3687
3704
  declare const complex: {
3688
3705
  test: typeof test;
@@ -4100,7 +4117,7 @@ declare function transformAxis(axis: Axis, axisTranslate?: number, axisScale?: n
4100
4117
  /**
4101
4118
  * Apply a transform to a box from the latest resolved motion values.
4102
4119
  */
4103
- declare function transformBox(box: Box, transform: ResolvedValues$1): void;
4120
+ declare function transformBox(box: Box, transform: ResolvedValues$1, sourceBox?: Box): void;
4104
4121
 
4105
4122
  declare function calcLength(axis: Axis): number;
4106
4123
  declare function isNear(value: number, target: number, maxDistance: number): boolean;
@@ -4351,7 +4368,7 @@ interface ProjectionNodeOptions {
4351
4368
  layoutRoot?: boolean;
4352
4369
  alwaysMeasureLayout?: boolean;
4353
4370
  onExitComplete?: VoidFunction;
4354
- animationType?: "size" | "position" | "both" | "preserve-aspect";
4371
+ animationType?: "size" | "position" | "both" | "preserve-aspect" | "x" | "y";
4355
4372
  layoutId?: string;
4356
4373
  layout?: boolean | string;
4357
4374
  visualElement?: VisualElement;