motion-dom 12.27.5 → 12.28.1

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.
@@ -23,7 +23,8 @@ function buildTransform(state) {
23
23
  valueIsDefault = value === (key.startsWith("scale") ? 1 : 0);
24
24
  }
25
25
  else {
26
- valueIsDefault = parseFloat(value) === 0;
26
+ const parsed = parseFloat(value);
27
+ valueIsDefault = key.startsWith("scale") ? parsed === 1 : parsed === 0;
27
28
  }
28
29
  if (!valueIsDefault) {
29
30
  transformIsDefault = false;
@@ -1 +1 @@
1
- {"version":3,"file":"transform.mjs","sources":["../../../../src/effects/style/transform.ts"],"sourcesContent":["import { transformPropOrder } from \"../../render/utils/keys-transform\"\nimport { MotionValueState } from \"../MotionValueState\"\n\nconst translateAlias = {\n x: \"translateX\",\n y: \"translateY\",\n z: \"translateZ\",\n transformPerspective: \"perspective\",\n}\n\nexport function buildTransform(state: MotionValueState) {\n let transform = \"\"\n let transformIsDefault = true\n\n /**\n * Loop over all possible transforms in order, adding the ones that\n * are present to the transform string.\n */\n for (let i = 0; i < transformPropOrder.length; i++) {\n const key = transformPropOrder[i] as keyof typeof translateAlias\n const value = state.latest[key]\n\n if (value === undefined) continue\n\n let valueIsDefault = true\n if (typeof value === \"number\") {\n valueIsDefault = value === (key.startsWith(\"scale\") ? 1 : 0)\n } else {\n valueIsDefault = parseFloat(value) === 0\n }\n\n if (!valueIsDefault) {\n transformIsDefault = false\n const transformName = translateAlias[key] || key\n const valueToRender = state.latest[key]\n transform += `${transformName}(${valueToRender}) `\n }\n }\n\n return transformIsDefault ? \"none\" : transform.trim()\n}\n"],"names":[],"mappings":";;AAGA,MAAM,cAAc,GAAG;AACnB,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,oBAAoB,EAAE,aAAa;CACtC,CAAA;AAEK,SAAU,cAAc,CAAC,KAAuB,EAAA;IAClD,IAAI,SAAS,GAAG,EAAE,CAAA;IAClB,IAAI,kBAAkB,GAAG,IAAI,CAAA;AAE7B;;;AAGG;AACH,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAChD,QAAA,MAAM,GAAG,GAAG,kBAAkB,CAAC,CAAC,CAAgC,CAAA;QAChE,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAE/B,IAAI,KAAK,KAAK,SAAS;YAAE,SAAQ;QAEjC,IAAI,cAAc,GAAG,IAAI,CAAA;AACzB,QAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC3B,YAAA,cAAc,GAAG,KAAK,MAAM,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;SAC/D;aAAM;AACH,YAAA,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;SAC3C;QAED,IAAI,CAAC,cAAc,EAAE;YACjB,kBAAkB,GAAG,KAAK,CAAA;YAC1B,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,GAAG,CAAA;YAChD,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACvC,YAAA,SAAS,IAAI,CAAG,EAAA,aAAa,CAAI,CAAA,EAAA,aAAa,IAAI,CAAA;SACrD;KACJ;AAED,IAAA,OAAO,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,CAAA;AACzD;;;;"}
1
+ {"version":3,"file":"transform.mjs","sources":["../../../../src/effects/style/transform.ts"],"sourcesContent":["import { transformPropOrder } from \"../../render/utils/keys-transform\"\nimport { MotionValueState } from \"../MotionValueState\"\n\nconst translateAlias = {\n x: \"translateX\",\n y: \"translateY\",\n z: \"translateZ\",\n transformPerspective: \"perspective\",\n}\n\nexport function buildTransform(state: MotionValueState) {\n let transform = \"\"\n let transformIsDefault = true\n\n /**\n * Loop over all possible transforms in order, adding the ones that\n * are present to the transform string.\n */\n for (let i = 0; i < transformPropOrder.length; i++) {\n const key = transformPropOrder[i] as keyof typeof translateAlias\n const value = state.latest[key]\n\n if (value === undefined) continue\n\n let valueIsDefault = true\n if (typeof value === \"number\") {\n valueIsDefault = value === (key.startsWith(\"scale\") ? 1 : 0)\n } else {\n const parsed = parseFloat(value)\n valueIsDefault = key.startsWith(\"scale\") ? parsed === 1 : parsed === 0\n }\n\n if (!valueIsDefault) {\n transformIsDefault = false\n const transformName = translateAlias[key] || key\n const valueToRender = state.latest[key]\n transform += `${transformName}(${valueToRender}) `\n }\n }\n\n return transformIsDefault ? \"none\" : transform.trim()\n}\n"],"names":[],"mappings":";;AAGA,MAAM,cAAc,GAAG;AACnB,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,oBAAoB,EAAE,aAAa;CACtC,CAAA;AAEK,SAAU,cAAc,CAAC,KAAuB,EAAA;IAClD,IAAI,SAAS,GAAG,EAAE,CAAA;IAClB,IAAI,kBAAkB,GAAG,IAAI,CAAA;AAE7B;;;AAGG;AACH,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAChD,QAAA,MAAM,GAAG,GAAG,kBAAkB,CAAC,CAAC,CAAgC,CAAA;QAChE,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAE/B,IAAI,KAAK,KAAK,SAAS;YAAE,SAAQ;QAEjC,IAAI,cAAc,GAAG,IAAI,CAAA;AACzB,QAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC3B,YAAA,cAAc,GAAG,KAAK,MAAM,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;SAC/D;aAAM;AACH,YAAA,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;AAChC,YAAA,cAAc,GAAG,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,KAAK,CAAC,GAAG,MAAM,KAAK,CAAC,CAAA;SACzE;QAED,IAAI,CAAC,cAAc,EAAE;YACjB,kBAAkB,GAAG,KAAK,CAAA;YAC1B,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,GAAG,CAAA;YAChD,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACvC,YAAA,SAAS,IAAI,CAAG,EAAA,aAAa,CAAI,CAAA,EAAA,aAAa,IAAI,CAAA;SACrD;KACJ;AAED,IAAA,OAAO,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,CAAA;AACzD;;;;"}
package/dist/es/index.mjs CHANGED
@@ -85,6 +85,7 @@ export { supportsLinearEasing } from './utils/supports/linear-easing.mjs';
85
85
  export { supportsScrollTimeline } from './utils/supports/scroll-timeline.mjs';
86
86
  export { transform } from './utils/transform.mjs';
87
87
  export { MotionValue, collectMotionValues, motionValue } from './value/index.mjs';
88
+ export { attachFollow, followValue } from './value/follow-value.mjs';
88
89
  export { mapValue } from './value/map-value.mjs';
89
90
  export { attachSpring, springValue } from './value/spring-value.mjs';
90
91
  export { transformValue } from './value/transform-value.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -33,7 +33,8 @@ function buildTransform(latestValues, transform, transformTemplate) {
33
33
  valueIsDefault = value === (key.startsWith("scale") ? 1 : 0);
34
34
  }
35
35
  else {
36
- valueIsDefault = parseFloat(value) === 0;
36
+ const parsed = parseFloat(value);
37
+ valueIsDefault = key.startsWith("scale") ? parsed === 1 : parsed === 0;
37
38
  }
38
39
  if (!valueIsDefault || transformTemplate) {
39
40
  const valueAsType = getValueAsType(value, numberValueTypes[key]);
@@ -1 +1 @@
1
- {"version":3,"file":"build-transform.mjs","sources":["../../../../../src/render/html/utils/build-transform.ts"],"sourcesContent":["import { getValueAsType } from \"../../../value/types/utils/get-as-type\"\nimport { numberValueTypes } from \"../../../value/types/maps/number\"\nimport { transformPropOrder } from \"../../utils/keys-transform\"\nimport { ResolvedValues } from \"../../types\"\nimport { HTMLRenderState } from \"../types\"\nimport type { MotionNodeOptions } from \"../../../node/types\"\n\nconst translateAlias = {\n x: \"translateX\",\n y: \"translateY\",\n z: \"translateZ\",\n transformPerspective: \"perspective\",\n}\n\nconst numTransforms = transformPropOrder.length\n\n/**\n * Build a CSS transform style from individual x/y/scale etc properties.\n *\n * This outputs with a default order of transforms/scales/rotations, this can be customised by\n * providing a transformTemplate function.\n */\nexport function buildTransform(\n latestValues: ResolvedValues,\n transform: HTMLRenderState[\"transform\"],\n transformTemplate?: MotionNodeOptions[\"transformTemplate\"]\n) {\n // The transform string we're going to build into.\n let transformString = \"\"\n let transformIsDefault = true\n\n /**\n * Loop over all possible transforms in order, adding the ones that\n * are present to the transform string.\n */\n for (let i = 0; i < numTransforms; i++) {\n const key = transformPropOrder[i] as keyof typeof translateAlias\n const value = latestValues[key]\n\n if (value === undefined) continue\n\n let valueIsDefault = true\n if (typeof value === \"number\") {\n valueIsDefault = value === (key.startsWith(\"scale\") ? 1 : 0)\n } else {\n valueIsDefault = parseFloat(value) === 0\n }\n\n if (!valueIsDefault || transformTemplate) {\n const valueAsType = getValueAsType(value, numberValueTypes[key])\n\n if (!valueIsDefault) {\n transformIsDefault = false\n const transformName = translateAlias[key] || key\n transformString += `${transformName}(${valueAsType}) `\n }\n\n if (transformTemplate) {\n transform[key] = valueAsType\n }\n }\n }\n\n transformString = transformString.trim()\n\n // If we have a custom `transform` template, pass our transform values and\n // generated transformString to that before returning\n if (transformTemplate) {\n transformString = transformTemplate(\n transform,\n transformIsDefault ? \"\" : transformString\n )\n } else if (transformIsDefault) {\n transformString = \"none\"\n }\n\n return transformString\n}\n"],"names":[],"mappings":";;;;AAOA,MAAM,cAAc,GAAG;AACnB,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,oBAAoB,EAAE,aAAa;CACtC,CAAA;AAED,MAAM,aAAa,GAAG,kBAAkB,CAAC,MAAM,CAAA;AAE/C;;;;;AAKG;SACa,cAAc,CAC1B,YAA4B,EAC5B,SAAuC,EACvC,iBAA0D,EAAA;;IAG1D,IAAI,eAAe,GAAG,EAAE,CAAA;IACxB,IAAI,kBAAkB,GAAG,IAAI,CAAA;AAE7B;;;AAGG;AACH,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,EAAE,CAAC,EAAE,EAAE;AACpC,QAAA,MAAM,GAAG,GAAG,kBAAkB,CAAC,CAAC,CAAgC,CAAA;AAChE,QAAA,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAA;QAE/B,IAAI,KAAK,KAAK,SAAS;YAAE,SAAQ;QAEjC,IAAI,cAAc,GAAG,IAAI,CAAA;AACzB,QAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC3B,YAAA,cAAc,GAAG,KAAK,MAAM,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;SAC/D;aAAM;AACH,YAAA,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;SAC3C;AAED,QAAA,IAAI,CAAC,cAAc,IAAI,iBAAiB,EAAE;YACtC,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAA;YAEhE,IAAI,CAAC,cAAc,EAAE;gBACjB,kBAAkB,GAAG,KAAK,CAAA;gBAC1B,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,GAAG,CAAA;AAChD,gBAAA,eAAe,IAAI,CAAG,EAAA,aAAa,CAAI,CAAA,EAAA,WAAW,IAAI,CAAA;aACzD;YAED,IAAI,iBAAiB,EAAE;AACnB,gBAAA,SAAS,CAAC,GAAG,CAAC,GAAG,WAAW,CAAA;aAC/B;SACJ;KACJ;AAED,IAAA,eAAe,GAAG,eAAe,CAAC,IAAI,EAAE,CAAA;;;IAIxC,IAAI,iBAAiB,EAAE;AACnB,QAAA,eAAe,GAAG,iBAAiB,CAC/B,SAAS,EACT,kBAAkB,GAAG,EAAE,GAAG,eAAe,CAC5C,CAAA;KACJ;SAAM,IAAI,kBAAkB,EAAE;QAC3B,eAAe,GAAG,MAAM,CAAA;KAC3B;AAED,IAAA,OAAO,eAAe,CAAA;AAC1B;;;;"}
1
+ {"version":3,"file":"build-transform.mjs","sources":["../../../../../src/render/html/utils/build-transform.ts"],"sourcesContent":["import { getValueAsType } from \"../../../value/types/utils/get-as-type\"\nimport { numberValueTypes } from \"../../../value/types/maps/number\"\nimport { transformPropOrder } from \"../../utils/keys-transform\"\nimport { ResolvedValues } from \"../../types\"\nimport { HTMLRenderState } from \"../types\"\nimport type { MotionNodeOptions } from \"../../../node/types\"\n\nconst translateAlias = {\n x: \"translateX\",\n y: \"translateY\",\n z: \"translateZ\",\n transformPerspective: \"perspective\",\n}\n\nconst numTransforms = transformPropOrder.length\n\n/**\n * Build a CSS transform style from individual x/y/scale etc properties.\n *\n * This outputs with a default order of transforms/scales/rotations, this can be customised by\n * providing a transformTemplate function.\n */\nexport function buildTransform(\n latestValues: ResolvedValues,\n transform: HTMLRenderState[\"transform\"],\n transformTemplate?: MotionNodeOptions[\"transformTemplate\"]\n) {\n // The transform string we're going to build into.\n let transformString = \"\"\n let transformIsDefault = true\n\n /**\n * Loop over all possible transforms in order, adding the ones that\n * are present to the transform string.\n */\n for (let i = 0; i < numTransforms; i++) {\n const key = transformPropOrder[i] as keyof typeof translateAlias\n const value = latestValues[key]\n\n if (value === undefined) continue\n\n let valueIsDefault = true\n if (typeof value === \"number\") {\n valueIsDefault = value === (key.startsWith(\"scale\") ? 1 : 0)\n } else {\n const parsed = parseFloat(value)\n valueIsDefault = key.startsWith(\"scale\") ? parsed === 1 : parsed === 0\n }\n\n if (!valueIsDefault || transformTemplate) {\n const valueAsType = getValueAsType(value, numberValueTypes[key])\n\n if (!valueIsDefault) {\n transformIsDefault = false\n const transformName = translateAlias[key] || key\n transformString += `${transformName}(${valueAsType}) `\n }\n\n if (transformTemplate) {\n transform[key] = valueAsType\n }\n }\n }\n\n transformString = transformString.trim()\n\n // If we have a custom `transform` template, pass our transform values and\n // generated transformString to that before returning\n if (transformTemplate) {\n transformString = transformTemplate(\n transform,\n transformIsDefault ? \"\" : transformString\n )\n } else if (transformIsDefault) {\n transformString = \"none\"\n }\n\n return transformString\n}\n"],"names":[],"mappings":";;;;AAOA,MAAM,cAAc,GAAG;AACnB,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,CAAC,EAAE,YAAY;AACf,IAAA,oBAAoB,EAAE,aAAa;CACtC,CAAA;AAED,MAAM,aAAa,GAAG,kBAAkB,CAAC,MAAM,CAAA;AAE/C;;;;;A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,CAAA;aAC/B;SACJ;KACJ;AAED,IAAA,eAAe,GAAG,eAAe,CAAC,IAAI,EAAE,CAAA;;;IAIxC,IAAI,iBAAiB,EAAE;AACnB,QAAA,eAAe,GAAG,iBAAiB,CAC/B,SAAS,EACT,kBAAkB,GAAG,EAAE,GAAG,eAAe,CAC5C,CAAA;KACJ;SAAM,IAAI,kBAAkB,EAAE;QAC3B,eAAe,GAAG,MAAM,CAAA;KAC3B;AAED,IAAA,OAAO,eAAe,CAAA;AAC1B;;;;"}
@@ -0,0 +1,102 @@
1
+ import { motionValue } from './index.mjs';
2
+ import { JSAnimation } from '../animation/JSAnimation.mjs';
3
+ import { isMotionValue } from './utils/is-motion-value.mjs';
4
+ import { frame } from '../frameloop/frame.mjs';
5
+
6
+ /**
7
+ * Create a `MotionValue` that animates to its latest value using any transition type.
8
+ * Can either be a value or track another `MotionValue`.
9
+ *
10
+ * ```jsx
11
+ * const x = motionValue(0)
12
+ * const y = followValue(x, { type: "spring", stiffness: 300 })
13
+ * // or with tween
14
+ * const z = followValue(x, { type: "tween", duration: 0.5, ease: "easeOut" })
15
+ * ```
16
+ *
17
+ * @param source - Initial value or MotionValue to track
18
+ * @param options - Animation transition options
19
+ * @returns `MotionValue`
20
+ *
21
+ * @public
22
+ */
23
+ function followValue(source, options) {
24
+ const initialValue = isMotionValue(source) ? source.get() : source;
25
+ const value = motionValue(initialValue);
26
+ attachFollow(value, source, options);
27
+ return value;
28
+ }
29
+ /**
30
+ * Attach an animation to a MotionValue that will animate whenever the value changes.
31
+ * Similar to attachSpring but supports any transition type (spring, tween, inertia, etc.)
32
+ *
33
+ * @param value - The MotionValue to animate
34
+ * @param source - Initial value or MotionValue to track
35
+ * @param options - Animation transition options
36
+ * @returns Cleanup function
37
+ *
38
+ * @public
39
+ */
40
+ function attachFollow(value, source, options = {}) {
41
+ const initialValue = value.get();
42
+ let activeAnimation = null;
43
+ let latestValue = initialValue;
44
+ let latestSetter;
45
+ const unit = typeof initialValue === "string"
46
+ ? initialValue.replace(/[\d.-]/g, "")
47
+ : undefined;
48
+ const stopAnimation = () => {
49
+ if (activeAnimation) {
50
+ activeAnimation.stop();
51
+ activeAnimation = null;
52
+ }
53
+ };
54
+ const startAnimation = () => {
55
+ stopAnimation();
56
+ const currentValue = asNumber(value.get());
57
+ const targetValue = asNumber(latestValue);
58
+ // Don't animate if we're already at the target
59
+ if (currentValue === targetValue) {
60
+ return;
61
+ }
62
+ activeAnimation = new JSAnimation({
63
+ keyframes: [currentValue, targetValue],
64
+ velocity: value.getVelocity(),
65
+ // Default to spring if no type specified (matches useSpring behavior)
66
+ type: "spring",
67
+ restDelta: 0.001,
68
+ restSpeed: 0.01,
69
+ ...options,
70
+ onUpdate: latestSetter,
71
+ });
72
+ };
73
+ value.attach((v, set) => {
74
+ latestValue = v;
75
+ 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
+ });
83
+ }, stopAnimation);
84
+ if (isMotionValue(source)) {
85
+ const removeSourceOnChange = source.on("change", (v) => value.set(parseValue(v, unit)));
86
+ const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
87
+ return () => {
88
+ removeSourceOnChange();
89
+ removeValueOnDestroy();
90
+ };
91
+ }
92
+ return stopAnimation;
93
+ }
94
+ function parseValue(v, unit) {
95
+ return unit ? v + unit : v;
96
+ }
97
+ function asNumber(v) {
98
+ return typeof v === "number" ? v : parseFloat(v);
99
+ }
100
+
101
+ export { attachFollow, followValue };
102
+ //# sourceMappingURL=follow-value.mjs.map
@@ -0,0 +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;AACa,SAAA,WAAW,CACvB,MAA0B,EAC1B,OAA4B,EAAA;AAE5B,IAAA,MAAM,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,MAAM,CAAA;AAClE,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC,CAAA;AAEvC,IAAA,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;AAEpC,IAAA,OAAO,KAAK,CAAA;AAChB,CAAC;AAED;;;;;;;;;;AAUG;AACG,SAAU,YAAY,CACxB,KAAqB,EACrB,MAA0B,EAC1B,UAA8B,EAAE,EAAA;AAEhC,IAAA,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,EAAE,CAAA;IAEhC,IAAI,eAAe,GAA+B,IAAI,CAAA;IACtD,IAAI,WAAW,GAAG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;AACxC,YAAA,eAAe,EAAE,IAAI,CAAC,MAAK;gBACvB,KAAK,CAAC,QAAQ,CAAC,CAAC,iBAAiB,EAAE,MAAM,EAAE,CAAA;AAC/C,aAAC,CAAC,CAAA;AACN,SAAC,CAAC,CAAA;KACL,EAAE,aAAa,CAAC,CAAA;AAEjB,IAAA,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE;QACvB,MAAM,oBAAoB,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,KAC/C,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAM,CAAC,CACtC,CAAA;QAED,MAAM,oBAAoB,GAAG,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAA;AAEtE,QAAA,OAAO,MAAK;AACR,YAAA,oBAAoB,EAAE,CAAA;AACtB,YAAA,oBAAoB,EAAE,CAAA;AAC1B,SAAC,CAAA;KACJ;AAED,IAAA,OAAO,aAAa,CAAA;AACxB,CAAC;AAED,SAAS,UAAU,CAAC,CAAsB,EAAE,IAAa,EAAA;IACrD,OAAO,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAA;AAC9B,CAAC;AAED,SAAS,QAAQ,CAAC,CAAsB,EAAA;AACpC,IAAA,OAAO,OAAO,CAAC,KAAK,QAAQ,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;AACpD;;;;"}
@@ -1,7 +1,4 @@
1
- import { motionValue } from './index.mjs';
2
- import { JSAnimation } from '../animation/JSAnimation.mjs';
3
- import { isMotionValue } from './utils/is-motion-value.mjs';
4
- import { frame } from '../frameloop/frame.mjs';
1
+ import { followValue, attachFollow } from './follow-value.mjs';
5
2
 
6
3
  /**
7
4
  * Create a `MotionValue` that animates to its latest value using a spring.
@@ -9,72 +6,30 @@ import { frame } from '../frameloop/frame.mjs';
9
6
  *
10
7
  * ```jsx
11
8
  * const x = motionValue(0)
12
- * const y = transformValue(() => x.get() * 2) // double x
9
+ * const y = springValue(x, { stiffness: 300 })
13
10
  * ```
14
11
  *
15
- * @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.
12
+ * @param source - Initial value or MotionValue to track
13
+ * @param options - Spring configuration options
16
14
  * @returns `MotionValue`
17
15
  *
18
16
  * @public
19
17
  */
20
18
  function springValue(source, options) {
21
- const initialValue = isMotionValue(source) ? source.get() : source;
22
- const value = motionValue(initialValue);
23
- attachSpring(value, source, options);
24
- return value;
19
+ return followValue(source, { type: "spring", ...options });
25
20
  }
21
+ /**
22
+ * Attach a spring animation to a MotionValue that will animate whenever the value changes.
23
+ *
24
+ * @param value - The MotionValue to animate
25
+ * @param source - Initial value or MotionValue to track
26
+ * @param options - Spring configuration options
27
+ * @returns Cleanup function
28
+ *
29
+ * @public
30
+ */
26
31
  function attachSpring(value, source, options) {
27
- const initialValue = value.get();
28
- let activeAnimation = null;
29
- let latestValue = initialValue;
30
- let latestSetter;
31
- const unit = typeof initialValue === "string"
32
- ? initialValue.replace(/[\d.-]/g, "")
33
- : undefined;
34
- const stopAnimation = () => {
35
- if (activeAnimation) {
36
- activeAnimation.stop();
37
- activeAnimation = null;
38
- }
39
- };
40
- const startAnimation = () => {
41
- stopAnimation();
42
- activeAnimation = new JSAnimation({
43
- keyframes: [asNumber(value.get()), asNumber(latestValue)],
44
- velocity: value.getVelocity(),
45
- type: "spring",
46
- restDelta: 0.001,
47
- restSpeed: 0.01,
48
- ...options,
49
- onUpdate: latestSetter,
50
- });
51
- };
52
- value.attach((v, set) => {
53
- latestValue = v;
54
- latestSetter = (latest) => set(parseValue(latest, unit));
55
- frame.postRender(() => {
56
- startAnimation();
57
- value['events'].animationStart?.notify();
58
- activeAnimation?.then(() => {
59
- value['events'].animationComplete?.notify();
60
- });
61
- });
62
- }, stopAnimation);
63
- if (isMotionValue(source)) {
64
- const removeSourceOnChange = source.on("change", (v) => value.set(parseValue(v, unit)));
65
- const removeValueOnDestroy = value.on("destroy", removeSourceOnChange);
66
- return () => {
67
- removeSourceOnChange();
68
- removeValueOnDestroy();
69
- };
70
- }
71
- return stopAnimation;
72
- }
73
- function parseValue(v, unit) {
74
- return unit ? v + unit : v;
75
- }
76
- function asNumber(v) {
77
- return typeof v === "number" ? v : parseFloat(v);
32
+ return attachFollow(value, source, { type: "spring", ...options });
78
33
  }
79
34
 
80
35
  export { attachSpring, springValue };
@@ -1 +1 @@
1
- {"version":3,"file":"spring-value.mjs","sources":["../../../src/value/spring-value.ts"],"sourcesContent":["import { MotionValue, motionValue } from \".\"\nimport { JSAnimation } from \"../animation/JSAnimation\"\nimport { AnyResolvedKeyframe, SpringOptions } from \"../animation/types\"\nimport { frame } from \"../frameloop\"\nimport { isMotionValue } from \"./utils/is-motion-value\"\n\n/**\n * Create a `MotionValue` that animates to its latest value using a spring.\n * Can either be a value or track another `MotionValue`.\n *\n * ```jsx\n * const x = motionValue(0)\n * const y = transformValue(() => x.get() * 2) // double x\n * ```\n *\n * @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.\n * @returns `MotionValue`\n *\n * @public\n */\nexport function springValue<T extends AnyResolvedKeyframe>(\n source: T | MotionValue<T>,\n options?: SpringOptions\n) {\n const initialValue = isMotionValue(source) ? source.get() : source\n const value = motionValue(initialValue)\n\n attachSpring(value, source, options)\n\n return value\n}\n\nexport function attachSpring<T extends AnyResolvedKeyframe>(\n value: MotionValue<T>,\n source: T | MotionValue<T>,\n options?: SpringOptions\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 const startAnimation = () => {\n stopAnimation()\n\n activeAnimation = new JSAnimation({\n keyframes: [asNumber(value.get()), asNumber(latestValue)],\n velocity: value.getVelocity(),\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":";;;;;AAMA;;;;;;;;;;;;;AAaG;AACa,SAAA,WAAW,CACvB,MAA0B,EAC1B,OAAuB,EAAA;AAEvB,IAAA,MAAM,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,MAAM,CAAA;AAClE,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC,CAAA;AAEvC,IAAA,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;AAEpC,IAAA,OAAO,KAAK,CAAA;AAChB,CAAC;SAEe,YAAY,CACxB,KAAqB,EACrB,MAA0B,EAC1B,OAAuB,EAAA;AAEvB,IAAA,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,EAAE,CAAA;IAEhC,IAAI,eAAe,GAA+B,IAAI,CAAA;IACtD,IAAI,WAAW,GAAG,YAAY,CAAA;AAC9B,IAAA,IAAI,YAA4B,CAAA;AAEhC,IAAA,MAAM,IAAI,GACN,OAAO,YAAY,KAAK,QAAQ;UAC1B,YAAY,CAAC,OAAO,CAA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,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,KAC/C,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAM,CAAC,CACtC,CAAA;QAED,MAAM,oBAAoB,GAAG,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,oBAAoB,CAAC,CAAA;AAEtE,QAAA,OAAO,MAAK;AACR,YAAA,oBAAoB,EAAE,CAAA;AACtB,YAAA,oBAAoB,EAAE,CAAA;AAC1B,SAAC,CAAA;KACJ;AAED,IAAA,OAAO,aAAa,CAAA;AACxB,CAAC;AAED,SAAS,UAAU,CAAC,CAAsB,EAAE,IAAa,EAAA;IACrD,OAAO,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAA;AAC9B,CAAC;AAED,SAAS,QAAQ,CAAC,CAAsB,EAAA;AACpC,IAAA,OAAO,OAAO,CAAC,KAAK,QAAQ,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;AACpD;;;;"}
1
+ {"version":3,"file":"spring-value.mjs","sources":["../../../src/value/spring-value.ts"],"sourcesContent":["import { MotionValue } from \".\"\nimport { AnyResolvedKeyframe, SpringOptions } from \"../animation/types\"\nimport { attachFollow, followValue } from \"./follow-value\"\n\n/**\n * Create a `MotionValue` that animates to its latest value using a spring.\n * Can either be a value or track another `MotionValue`.\n *\n * ```jsx\n * const x = motionValue(0)\n * const y = springValue(x, { stiffness: 300 })\n * ```\n *\n * @param source - Initial value or MotionValue to track\n * @param options - Spring configuration options\n * @returns `MotionValue`\n *\n * @public\n */\nexport function springValue<T extends AnyResolvedKeyframe>(\n source: T | MotionValue<T>,\n options?: SpringOptions\n) {\n return followValue(source, { type: \"spring\", ...options })\n}\n\n/**\n * Attach a spring animation to a MotionValue that will animate whenever the value changes.\n *\n * @param value - The MotionValue to animate\n * @param source - Initial value or MotionValue to track\n * @param options - Spring configuration options\n * @returns Cleanup function\n *\n * @public\n */\nexport function attachSpring<T extends AnyResolvedKeyframe>(\n value: MotionValue<T>,\n source: T | MotionValue<T>,\n options?: SpringOptions\n): VoidFunction {\n return attachFollow(value, source, { type: \"spring\", ...options })\n}\n"],"names":[],"mappings":";;AAIA;;;;;;;;;;;;;;AAcG;AACa,SAAA,WAAW,CACvB,MAA0B,EAC1B,OAAuB,EAAA;AAEvB,IAAA,OAAO,WAAW,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;AAC9D,CAAC;AAED;;;;;;;;;AASG;SACa,YAAY,CACxB,KAAqB,EACrB,MAA0B,EAC1B,OAAuB,EAAA;AAEvB,IAAA,OAAO,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;AACtE;;;;"}
package/dist/index.d.ts CHANGED
@@ -3400,6 +3400,42 @@ declare function transform<T>(inputValue: number, inputRange: number[], outputRa
3400
3400
  */
3401
3401
  declare function transform<T>(inputRange: number[], outputRange: T[], options?: TransformOptions<T>): (inputValue: number) => T;
3402
3402
 
3403
+ /**
3404
+ * Options for useFollowValue hook, extending ValueAnimationTransition
3405
+ * but excluding lifecycle callbacks that don't make sense for the hook pattern.
3406
+ */
3407
+ type FollowValueOptions = Omit<ValueAnimationTransition, "onUpdate" | "onComplete" | "onPlay" | "onRepeat" | "onStop">;
3408
+ /**
3409
+ * Create a `MotionValue` that animates to its latest value using any transition type.
3410
+ * Can either be a value or track another `MotionValue`.
3411
+ *
3412
+ * ```jsx
3413
+ * const x = motionValue(0)
3414
+ * const y = followValue(x, { type: "spring", stiffness: 300 })
3415
+ * // or with tween
3416
+ * const z = followValue(x, { type: "tween", duration: 0.5, ease: "easeOut" })
3417
+ * ```
3418
+ *
3419
+ * @param source - Initial value or MotionValue to track
3420
+ * @param options - Animation transition options
3421
+ * @returns `MotionValue`
3422
+ *
3423
+ * @public
3424
+ */
3425
+ declare function followValue<T extends AnyResolvedKeyframe>(source: T | MotionValue<T>, options?: FollowValueOptions): MotionValue<T>;
3426
+ /**
3427
+ * Attach an animation to a MotionValue that will animate whenever the value changes.
3428
+ * Similar to attachSpring but supports any transition type (spring, tween, inertia, etc.)
3429
+ *
3430
+ * @param value - The MotionValue to animate
3431
+ * @param source - Initial value or MotionValue to track
3432
+ * @param options - Animation transition options
3433
+ * @returns Cleanup function
3434
+ *
3435
+ * @public
3436
+ */
3437
+ declare function attachFollow<T extends AnyResolvedKeyframe>(value: MotionValue<T>, source: T | MotionValue<T>, options?: FollowValueOptions): VoidFunction;
3438
+
3403
3439
  type MapInputRange = number[];
3404
3440
  /**
3405
3441
  * Create a `MotionValue` that maps the output of another `MotionValue` by
@@ -3446,15 +3482,26 @@ declare function mapValue<O>(inputValue: MotionValue<number>, inputRange: MapInp
3446
3482
  *
3447
3483
  * ```jsx
3448
3484
  * const x = motionValue(0)
3449
- * const y = transformValue(() => x.get() * 2) // double x
3485
+ * const y = springValue(x, { stiffness: 300 })
3450
3486
  * ```
3451
3487
  *
3452
- * @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.
3488
+ * @param source - Initial value or MotionValue to track
3489
+ * @param options - Spring configuration options
3453
3490
  * @returns `MotionValue`
3454
3491
  *
3455
3492
  * @public
3456
3493
  */
3457
3494
  declare function springValue<T extends AnyResolvedKeyframe>(source: T | MotionValue<T>, options?: SpringOptions): MotionValue<T>;
3495
+ /**
3496
+ * Attach a spring animation to a MotionValue that will animate whenever the value changes.
3497
+ *
3498
+ * @param value - The MotionValue to animate
3499
+ * @param source - Initial value or MotionValue to track
3500
+ * @param options - Spring configuration options
3501
+ * @returns Cleanup function
3502
+ *
3503
+ * @public
3504
+ */
3458
3505
  declare function attachSpring<T extends AnyResolvedKeyframe>(value: MotionValue<T>, source: T | MotionValue<T>, options?: SpringOptions): VoidFunction;
3459
3506
 
3460
3507
  type TransformInputRange = number[];
@@ -4920,4 +4967,4 @@ declare const sync: Batcher;
4920
4967
  */
4921
4968
  declare const cancelSync: Record<string, (process: Process) => void>;
4922
4969
 
4923
- export { type AcceptedAnimations, type ActiveStatsBuffer, type AnimationDefinition, type AnimationGeneratorName, type AnimationGeneratorType, type AnimationList, type AnimationOptions, type AnimationOrchestrationOptions, type AnimationPlaybackControls, type AnimationPlaybackControlsWithThen, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, type AnimationType, type AnimationTypeState, type AnyResolvedKeyframe, AsyncMotionValueAnimation, type Batcher, type CSSStyleDeclarationWithTransform, type CSSVariableName, type CSSVariableToken, type CancelProcess, type Color, type ComplexValueInfo, type ComplexValues, type DOMKeyframesDefinition, DOMKeyframesResolver, type DOMValueAnimationOptions, DOMVisualElement, type DOMVisualElementOptions, type DecayOptions, type DelayedFunction, DocumentProjectionNode, type DragElastic, type DragHandler, type DraggableProps, type DurationSpringOptions, type DynamicOption, type ElementOrSelector, type EventInfo, type EventOptions, Feature, type FeatureClass, FlatTree, type FrameData, type FrameStats, type GeneratorFactory, type GeneratorFactoryFunction, GroupAnimation, GroupAnimationWithThen, type GroupedAnimations, type HSLA, HTMLProjectionNode, type HTMLRenderState, HTMLVisualElement, type HandoffFunction, type IProjectionNode, type InactiveStatsBuffer, type InertiaOptions, type InitialPromotionConfig, type InterpolateOptions, JSAnimation, type KeyframeGenerator, type KeyframeOptions, KeyframeResolver, LayoutAnimationBuilder, type LayoutEvents, type LayoutLifecycles, type LayoutUpdateData, type LayoutUpdateHandler, type LegacyAnimationControls, type MapInputRange, type Measurements, type Mixer, type MixerFactory, type MotionConfigContextProps, type MotionNodeAdvancedOptions, type MotionNodeAnimationOptions, type MotionNodeDragHandlers, type MotionNodeDraggableOptions, type MotionNodeEventOptions, type MotionNodeFocusHandlers, type MotionNodeHoverHandlers, type MotionNodeLayoutOptions, type MotionNodeOptions, type MotionNodePanHandlers, type MotionNodeTapHandlers, type MotionNodeViewportOptions, type MotionStyle, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, type MultiTransformer, NativeAnimation, NativeAnimationExtended, type NativeAnimationOptions, type NativeAnimationOptionsExtended, NativeAnimationWrapper, type NodeGroup, NodeStack, type NumberMap, ObjectVisualElement, type OnHoverEndEvent, type OnHoverStartEvent, type OnKeyframesResolved, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PanHandler, type PanInfo, type PassiveEffect, type Phase, type PointerEventOptions, type PresenceContextProps, type PressGestureInfo, type Process, type ProgressTimeline, type ProjectionEventName, type ProjectionNodeConfig, type ProjectionNodeOptions, type RGBA, type ReducedMotionConfig, type RepeatType, type ResolvedConstraints, type ResolvedElastic, type ResolvedKeyframes, type ResolvedValueKeyframe, type ResolvedValues$1 as ResolvedValues, type SVGAttributes, type SVGForcedAttrKeyframesDefinition, type SVGForcedAttrProperties, type SVGForcedAttrTransitions, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGRenderState, type SVGTransitions, SVGVisualElement, type ScaleCorrectionNode, type ScaleCorrector, type ScaleCorrectorDefinition, type ScaleCorrectorMap, type Schedule, type ScrapeMotionValuesFromProps, type ScrollMeasurements, type SelectorCache, type SingleTransformer, type Spring, type SpringOptions, type StaggerOptions, type StaggerOrigin, type StartAnimation, type Stats, type StatsBuffer, type StatsRecording, type StatsSummary, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type Summary, type TapHandlers, type TapInfo, type Target, type TargetAndTransition, type TargetResolver, type TimelineWithFallback, type TransformInputRange, type TransformOptions, type TransformOrigin, type TransformProperties, type TransformTemplate, type Transformer, type Transition, type TransitionWithValueOverrides, type Tween, type UnresolvedKeyframes, type UnresolvedValueKeyframe, type UseRenderState, type ValueAnimationOptions, type ValueAnimationOptionsWithRenderContext, type ValueAnimationTransition, type ValueAnimationWithDynamicDelay, type ValueIndexes, type ValueKeyframe, type ValueKeyframesDefinition, type ValueTransformer, type ValueTransition, type ValueType, type ValueTypeMap, type VariableKeyframesDefinition, type VariableTransitions, type Variant, type VariantLabels, type Variants, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type ViewTransitionTargetDefinition, type ViewportEventHandler, type ViewportOptions, VisualElement, type VisualElementAnimationOptions, type VisualElementEventCallbacks, type VisualElementOptions, type VisualState, type WillChange, type WithAppearProps, type WithDepth, type WithQuerySelectorAll, acceleratedValues, activeAnimations, addAttrValue, addDomEvent, addScaleCorrector, addStyleValue, addValueToWillChange, alpha, analyseComplexValue, animateMotionValue, animateSingleValue, animateTarget, animateValue, animateVariant, animateView, animateVisualElement, animationMapKey, applyAxisDelta, applyBoxDelta, applyGeneratorOptions, applyPointDelta, applyPxDefaults, applyTreeDeltas, aspectRatio, attachSpring, attrEffect, axisDeltaEquals, axisEquals, axisEqualsRounded, boxEquals, boxEqualsRounded, buildHTMLStyles, buildProjectionTransform, buildSVGAttrs, buildSVGPath, buildTransform, calcAxisDelta, calcBoxDelta, calcChildStagger, calcGeneratorDuration, calcLength, calcRelativeAxis, calcRelativeAxisPosition, calcRelativeBox, calcRelativePosition, camelCaseAttributes, camelToDash, cancelFrame, cancelMicrotask, cancelSync, checkVariantsDidChange, cleanDirtyNodes, collectMotionValues, color, compareByDepth, complex, containsCSSVariable, convertBoundingBoxToBox, convertBoxToBoundingBox, convertOffsetToTimes, copyAxisDeltaInto, copyAxisInto, copyBoxInto, correctBorderRadius, correctBoxShadow, createAnimationState, createAxis, createAxisDelta, createBox, createDelta, createGeneratorEasing, createProjectionNode, createRenderBatcher, cubicBezierAsString, defaultEasing, defaultOffset, defaultTransformValue, defaultValueTypes, degrees, delay, delayInSeconds, dimensionValueTypes, eachAxis, fillOffset, fillWildcards, findDimensionValueType, findValueType, flushKeyframeResolvers, frame, frameData, frameSteps, generateLinearEasing, getAnimatableNone, getAnimationMap, getComputedStyle, getDefaultTransition, getDefaultValueType, getFeatureDefinitions, getFinalKeyframe, getMixer, getOptimisedAppearId, getOriginIndex, getValueAsType, getValueTransition, getVariableValue, getVariantContext, getViewAnimationLayerInfo, getViewAnimations, globalProjectionState, has2DTranslate, hasReducedMotionListener, hasScale, hasTransform, hex, hover, hsla, hslaToRgba, inertia, initPrefersReducedMotion, interpolate, invisibleValues, isAnimationControls, isCSSVariableName, isCSSVariableToken, isControllingVariants, isDeltaZero, isDragActive, isDragging, isElementKeyboardAccessible, isForcedMotionValue, isGenerator, isHTMLElement, isKeyframesTarget, isMotionValue, isNear, isNodeOrChild, isPrimaryPointer, isSVGElement, isSVGSVGElement, isSVGTag, isTransitionDefined, isVariantLabel, isVariantNode, isWaapiSupportedEasing, isWillChangeMotionValue, keyframes, makeAnimationInstant, mapEasingToNativeEasing, mapValue, maxGeneratorDuration, measurePageBox, measureViewportBox, microtask, mix, mixArray, mixColor, mixComplex, mixImmediate, mixLinearColor, mixNumber, mixObject, mixValues, mixVisibility, motionValue, nodeGroup, number, numberValueTypes, observeTimeline, optimizedAppearDataAttribute, optimizedAppearDataId, parseAnimateLayoutArgs, parseCSSVariable, parseValueFromTransform, percent, pixelsToPercent, positionalKeys, prefersReducedMotion, press, progressPercentage, propEffect, propagateDirtyNodes, px, readTransformValue, recordStats, removeAxisDelta, removeAxisTransforms, removeBoxTransforms, removePointDelta, renderHTML, renderSVG, resize, resolveElements, resolveMotionValue, resolveVariant, resolveVariantFromProps, rgbUnit, rgba, rootProjectionNode, scale, scaleCorrectors, scalePoint, scrapeMotionValuesFromProps$1 as scrapeHTMLMotionValuesFromProps, scrapeMotionValuesFromProps as scrapeSVGMotionValuesFromProps, setDragLock, setFeatureDefinitions, setStyle, setTarget, spring, springValue, stagger, startWaapiAnimation, statsBuffer, styleEffect, supportedWaapiEasing, supportsBrowserAnimation, supportsFlags, supportsLinearEasing, supportsPartialKeyframes, supportsScrollTimeline, svgEffect, sync, testValueType, time, transform, transformAxis, transformBox, transformBoxPoints, transformPropOrder, transformProps, transformValue, transformValueTypes, translateAxis, updateMotionValuesFromProps, variantPriorityOrder, variantProps, vh, visualElementStore, vw };
4970
+ export { type AcceptedAnimations, type ActiveStatsBuffer, type AnimationDefinition, type AnimationGeneratorName, type AnimationGeneratorType, type AnimationList, type AnimationOptions, type AnimationOrchestrationOptions, type AnimationPlaybackControls, type AnimationPlaybackControlsWithThen, type AnimationPlaybackLifecycles, type AnimationPlaybackOptions, type AnimationScope, type AnimationState, type AnimationType, type AnimationTypeState, type AnyResolvedKeyframe, AsyncMotionValueAnimation, type Batcher, type CSSStyleDeclarationWithTransform, type CSSVariableName, type CSSVariableToken, type CancelProcess, type Color, type ComplexValueInfo, type ComplexValues, type DOMKeyframesDefinition, DOMKeyframesResolver, type DOMValueAnimationOptions, DOMVisualElement, type DOMVisualElementOptions, type DecayOptions, type DelayedFunction, DocumentProjectionNode, type DragElastic, type DragHandler, type DraggableProps, type DurationSpringOptions, type DynamicOption, type ElementOrSelector, type EventInfo, type EventOptions, Feature, type FeatureClass, FlatTree, type FollowValueOptions, type FrameData, type FrameStats, type GeneratorFactory, type GeneratorFactoryFunction, GroupAnimation, GroupAnimationWithThen, type GroupedAnimations, type HSLA, HTMLProjectionNode, type HTMLRenderState, HTMLVisualElement, type HandoffFunction, type IProjectionNode, type InactiveStatsBuffer, type InertiaOptions, type InitialPromotionConfig, type InterpolateOptions, JSAnimation, type KeyframeGenerator, type KeyframeOptions, KeyframeResolver, LayoutAnimationBuilder, type LayoutEvents, type LayoutLifecycles, type LayoutUpdateData, type LayoutUpdateHandler, type LegacyAnimationControls, type MapInputRange, type Measurements, type Mixer, type MixerFactory, type MotionConfigContextProps, type MotionNodeAdvancedOptions, type MotionNodeAnimationOptions, type MotionNodeDragHandlers, type MotionNodeDraggableOptions, type MotionNodeEventOptions, type MotionNodeFocusHandlers, type MotionNodeHoverHandlers, type MotionNodeLayoutOptions, type MotionNodeOptions, type MotionNodePanHandlers, type MotionNodeTapHandlers, type MotionNodeViewportOptions, type MotionStyle, MotionValue, type MotionValueEventCallbacks, type MotionValueOptions, type MultiTransformer, NativeAnimation, NativeAnimationExtended, type NativeAnimationOptions, type NativeAnimationOptionsExtended, NativeAnimationWrapper, type NodeGroup, NodeStack, type NumberMap, ObjectVisualElement, type OnHoverEndEvent, type OnHoverStartEvent, type OnKeyframesResolved, type OnPressEndEvent, type OnPressStartEvent, type Owner, type PanHandler, type PanInfo, type PassiveEffect, type Phase, type PointerEventOptions, type PresenceContextProps, type PressGestureInfo, type Process, type ProgressTimeline, type ProjectionEventName, type ProjectionNodeConfig, type ProjectionNodeOptions, type RGBA, type ReducedMotionConfig, type RepeatType, type ResolvedConstraints, type ResolvedElastic, type ResolvedKeyframes, type ResolvedValueKeyframe, type ResolvedValues$1 as ResolvedValues, type SVGAttributes, type SVGForcedAttrKeyframesDefinition, type SVGForcedAttrProperties, type SVGForcedAttrTransitions, type SVGKeyframesDefinition, type SVGPathKeyframesDefinition, type SVGPathProperties, type SVGPathTransitions, type SVGRenderState, type SVGTransitions, SVGVisualElement, type ScaleCorrectionNode, type ScaleCorrector, type ScaleCorrectorDefinition, type ScaleCorrectorMap, type Schedule, type ScrapeMotionValuesFromProps, type ScrollMeasurements, type SelectorCache, type SingleTransformer, type Spring, type SpringOptions, type StaggerOptions, type StaggerOrigin, type StartAnimation, type Stats, type StatsBuffer, type StatsRecording, type StatsSummary, type Step, type StepId, type Steps, type StyleKeyframesDefinition, type StyleTransitions, type Subscriber, type Summary, type TapHandlers, type TapInfo, type Target, type TargetAndTransition, type TargetResolver, type TimelineWithFallback, type TransformInputRange, type TransformOptions, type TransformOrigin, type TransformProperties, type TransformTemplate, type Transformer, type Transition, type TransitionWithValueOverrides, type Tween, type UnresolvedKeyframes, type UnresolvedValueKeyframe, type UseRenderState, type ValueAnimationOptions, type ValueAnimationOptionsWithRenderContext, type ValueAnimationTransition, type ValueAnimationWithDynamicDelay, type ValueIndexes, type ValueKeyframe, type ValueKeyframesDefinition, type ValueTransformer, type ValueTransition, type ValueType, type ValueTypeMap, type VariableKeyframesDefinition, type VariableTransitions, type Variant, type VariantLabels, type Variants, type VelocityOptions, type ViewTransitionAnimationDefinition, ViewTransitionBuilder, type ViewTransitionOptions, type ViewTransitionTarget, type ViewTransitionTargetDefinition, type ViewportEventHandler, type ViewportOptions, VisualElement, type VisualElementAnimationOptions, type VisualElementEventCallbacks, type VisualElementOptions, type VisualState, type WillChange, type WithAppearProps, type WithDepth, type WithQuerySelectorAll, acceleratedValues, activeAnimations, addAttrValue, addDomEvent, addScaleCorrector, addStyleValue, addValueToWillChange, alpha, analyseComplexValue, animateMotionValue, animateSingleValue, animateTarget, animateValue, animateVariant, animateView, animateVisualElement, animationMapKey, applyAxisDelta, applyBoxDelta, applyGeneratorOptions, applyPointDelta, applyPxDefaults, applyTreeDeltas, aspectRatio, attachFollow, attachSpring, attrEffect, axisDeltaEquals, axisEquals, axisEqualsRounded, boxEquals, boxEqualsRounded, buildHTMLStyles, buildProjectionTransform, buildSVGAttrs, buildSVGPath, buildTransform, calcAxisDelta, calcBoxDelta, calcChildStagger, calcGeneratorDuration, calcLength, calcRelativeAxis, calcRelativeAxisPosition, calcRelativeBox, calcRelativePosition, camelCaseAttributes, camelToDash, cancelFrame, cancelMicrotask, cancelSync, checkVariantsDidChange, cleanDirtyNodes, collectMotionValues, color, compareByDepth, complex, containsCSSVariable, convertBoundingBoxToBox, convertBoxToBoundingBox, convertOffsetToTimes, copyAxisDeltaInto, copyAxisInto, copyBoxInto, correctBorderRadius, correctBoxShadow, createAnimationState, createAxis, createAxisDelta, createBox, createDelta, createGeneratorEasing, createProjectionNode, createRenderBatcher, cubicBezierAsString, defaultEasing, defaultOffset, defaultTransformValue, defaultValueTypes, degrees, delay, delayInSeconds, dimensionValueTypes, eachAxis, fillOffset, fillWildcards, findDimensionValueType, findValueType, flushKeyframeResolvers, followValue, frame, frameData, frameSteps, generateLinearEasing, getAnimatableNone, getAnimationMap, getComputedStyle, getDefaultTransition, getDefaultValueType, getFeatureDefinitions, getFinalKeyframe, getMixer, getOptimisedAppearId, getOriginIndex, getValueAsType, getValueTransition, getVariableValue, getVariantContext, getViewAnimationLayerInfo, getViewAnimations, globalProjectionState, has2DTranslate, hasReducedMotionListener, hasScale, hasTransform, hex, hover, hsla, hslaToRgba, inertia, initPrefersReducedMotion, interpolate, invisibleValues, isAnimationControls, isCSSVariableName, isCSSVariableToken, isControllingVariants, isDeltaZero, isDragActive, isDragging, isElementKeyboardAccessible, isForcedMotionValue, isGenerator, isHTMLElement, isKeyframesTarget, isMotionValue, isNear, isNodeOrChild, isPrimaryPointer, isSVGElement, isSVGSVGElement, isSVGTag, isTransitionDefined, isVariantLabel, isVariantNode, isWaapiSupportedEasing, isWillChangeMotionValue, keyframes, makeAnimationInstant, mapEasingToNativeEasing, mapValue, maxGeneratorDuration, measurePageBox, measureViewportBox, microtask, mix, mixArray, mixColor, mixComplex, mixImmediate, mixLinearColor, mixNumber, mixObject, mixValues, mixVisibility, motionValue, nodeGroup, number, numberValueTypes, observeTimeline, optimizedAppearDataAttribute, optimizedAppearDataId, parseAnimateLayoutArgs, parseCSSVariable, parseValueFromTransform, percent, pixelsToPercent, positionalKeys, prefersReducedMotion, press, progressPercentage, propEffect, propagateDirtyNodes, px, readTransformValue, recordStats, removeAxisDelta, removeAxisTransforms, removeBoxTransforms, removePointDelta, renderHTML, renderSVG, resize, resolveElements, resolveMotionValue, resolveVariant, resolveVariantFromProps, rgbUnit, rgba, rootProjectionNode, scale, scaleCorrectors, scalePoint, scrapeMotionValuesFromProps$1 as scrapeHTMLMotionValuesFromProps, scrapeMotionValuesFromProps as scrapeSVGMotionValuesFromProps, setDragLock, setFeatureDefinitions, setStyle, setTarget, spring, springValue, stagger, startWaapiAnimation, statsBuffer, styleEffect, supportedWaapiEasing, supportsBrowserAnimation, supportsFlags, supportsLinearEasing, supportsPartialKeyframes, supportsScrollTimeline, svgEffect, sync, testValueType, time, transform, transformAxis, transformBox, transformBoxPoints, transformPropOrder, transformProps, transformValue, transformValueTypes, translateAxis, updateMotionValuesFromProps, variantPriorityOrder, variantProps, vh, visualElementStore, vw };