framer-motion 12.11.3 → 12.12.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 (41) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/client.js +1 -1
  3. package/dist/cjs/{create-9d9azvs6.js → create-BiMCrvDh.js} +78 -79
  4. package/dist/cjs/dom-mini.js +1 -3
  5. package/dist/cjs/dom.js +18 -18
  6. package/dist/cjs/index.js +15 -53
  7. package/dist/cjs/m.js +113 -115
  8. package/dist/dom.js +1 -1
  9. package/dist/es/animation/animate/single-value.mjs +1 -2
  10. package/dist/es/animation/animate/subject.mjs +1 -1
  11. package/dist/es/animation/sequence/create.mjs +1 -2
  12. package/dist/es/components/Reorder/Item.mjs +1 -1
  13. package/dist/es/index.mjs +0 -1
  14. package/dist/es/render/VisualElement.mjs +1 -2
  15. package/dist/es/render/dom/DOMVisualElement.mjs +1 -2
  16. package/dist/es/render/dom/use-render.mjs +2 -2
  17. package/dist/es/render/html/HTMLVisualElement.mjs +4 -2
  18. package/dist/es/render/html/use-props.mjs +1 -1
  19. package/dist/es/render/html/utils/scrape-motion-values.mjs +1 -1
  20. package/dist/es/render/svg/utils/scrape-motion-values.mjs +1 -2
  21. package/dist/es/render/utils/motion-values.mjs +1 -2
  22. package/dist/es/value/use-motion-template.mjs +1 -1
  23. package/dist/es/value/use-spring.mjs +12 -52
  24. package/dist/es/value/use-will-change/is.mjs +1 -1
  25. package/dist/es/value/utils/resolve-motion-value.mjs +1 -1
  26. package/dist/framer-motion.dev.js +145 -111
  27. package/dist/framer-motion.js +1 -1
  28. package/dist/m.d.ts +3 -3
  29. package/dist/size-rollup-animate.js +1 -1
  30. package/dist/size-rollup-dom-animation-assets.js +1 -1
  31. package/dist/size-rollup-dom-animation-m.js +1 -1
  32. package/dist/size-rollup-dom-animation.js +1 -1
  33. package/dist/size-rollup-dom-max-assets.js +1 -1
  34. package/dist/size-rollup-dom-max.js +1 -1
  35. package/dist/size-rollup-m.js +1 -1
  36. package/dist/size-rollup-motion.js +1 -1
  37. package/dist/types/client.d.ts +1 -1
  38. package/dist/types/index.d.ts +7 -9
  39. package/dist/{types.d-CQt5spQA.d.ts → types.d-CtuPurYT.d.ts} +3 -3
  40. package/package.json +3 -3
  41. package/dist/es/value/utils/is-motion-value.mjs +0 -3
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img width="100" height="100" alt="Motion logo" src="https://user-images.githubusercontent.com/7850794/164965523-3eced4c4-6020-467e-acde-f11b7900ad62.png" />
2
+ <img width="100" height="100" alt="Motion logo" src="https://github.com/user-attachments/assets/00d6d1c3-72c4-4c2f-a664-69da13182ffc" />
3
3
  </p>
4
4
  <h1 align="center">Motion for React</h1>
5
5
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var create = require('./create-9d9azvs6.js');
5
+ var create = require('./create-BiMCrvDh.js');
6
6
  require('motion-dom');
7
7
  require('motion-utils');
8
8
  require('react/jsx-runtime');
@@ -156,8 +156,6 @@ function calcRelativePosition(target, layout, parent) {
156
156
  calcRelativeAxisPosition(target.y, layout.y, parent.y);
157
157
  }
158
158
 
159
- const isMotionValue = (value) => Boolean(value && value.getVelocity);
160
-
161
159
  const isNotNull = (value) => value !== null;
162
160
  function getFinalKeyframe(keyframes, { repeat, repeatType = "loop" }, finalKeyframe) {
163
161
  const resolvedKeyframes = keyframes.filter(isNotNull);
@@ -307,7 +305,7 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
307
305
  };
308
306
 
309
307
  function animateSingleValue(value, keyframes, options) {
310
- const motionValue = isMotionValue(value) ? value : motionDom.motionValue(value);
308
+ const motionValue = motionDom.isMotionValue(value) ? value : motionDom.motionValue(value);
311
309
  motionValue.start(animateMotionValue("", motionValue, keyframes, options));
312
310
  return motionValue.animation;
313
311
  }
@@ -372,7 +370,7 @@ function delay(callback, timeout) {
372
370
  * TODO: Remove and move to library
373
371
  */
374
372
  function resolveMotionValue(value) {
375
- return isMotionValue(value) ? value.get() : value;
373
+ return motionDom.isMotionValue(value) ? value.get() : value;
376
374
  }
377
375
 
378
376
  const borders = ["TopLeft", "TopRight", "BottomLeft", "BottomRight"];
@@ -2713,14 +2711,14 @@ function updateMotionValuesFromProps(element, next, prev) {
2713
2711
  for (const key in next) {
2714
2712
  const nextValue = next[key];
2715
2713
  const prevValue = prev[key];
2716
- if (isMotionValue(nextValue)) {
2714
+ if (motionDom.isMotionValue(nextValue)) {
2717
2715
  /**
2718
2716
  * If this is a motion value found in props or style, we want to add it
2719
2717
  * to our visual element's motion value map.
2720
2718
  */
2721
2719
  element.addValue(key, nextValue);
2722
2720
  }
2723
- else if (isMotionValue(prevValue)) {
2721
+ else if (motionDom.isMotionValue(prevValue)) {
2724
2722
  /**
2725
2723
  * If we're swapping from a motion value to a static value,
2726
2724
  * create a new motion value from that
@@ -2916,7 +2914,7 @@ class VisualElement {
2916
2914
  const { willChange, ...initialMotionValues } = this.scrapeMotionValuesFromProps(props, {}, this);
2917
2915
  for (const key in initialMotionValues) {
2918
2916
  const value = initialMotionValues[key];
2919
- if (latestValues[key] !== undefined && isMotionValue(value)) {
2917
+ if (latestValues[key] !== undefined && motionDom.isMotionValue(value)) {
2920
2918
  value.set(latestValues[key], false);
2921
2919
  }
2922
2920
  }
@@ -3187,9 +3185,9 @@ class VisualElement {
3187
3185
  else if (!motionDom.findValueType(value) && motionDom.complex.test(target)) {
3188
3186
  value = motionDom.getAnimatableNone(key, target);
3189
3187
  }
3190
- this.setBaseTarget(key, isMotionValue(value) ? value.get() : value);
3188
+ this.setBaseTarget(key, motionDom.isMotionValue(value) ? value.get() : value);
3191
3189
  }
3192
- return isMotionValue(value) ? value.get() : value;
3190
+ return motionDom.isMotionValue(value) ? value.get() : value;
3193
3191
  }
3194
3192
  /**
3195
3193
  * Set the base target to later animate back to. This is currently
@@ -3222,7 +3220,7 @@ class VisualElement {
3222
3220
  * so we can read the value from an alternative source, try that.
3223
3221
  */
3224
3222
  const target = this.getBaseTargetFromProps(this.props, key);
3225
- if (target !== undefined && !isMotionValue(target))
3223
+ if (target !== undefined && !motionDom.isMotionValue(target))
3226
3224
  return target;
3227
3225
  /**
3228
3226
  * If the value was initially defined on initial, but it doesn't any more,
@@ -3274,7 +3272,7 @@ class DOMVisualElement extends VisualElement {
3274
3272
  delete this.childSubscription;
3275
3273
  }
3276
3274
  const { children } = this.props;
3277
- if (isMotionValue(children)) {
3275
+ if (motionDom.isMotionValue(children)) {
3278
3276
  this.childSubscription = children.on("change", (latest) => {
3279
3277
  if (this.current) {
3280
3278
  this.current.textContent = `${latest}`;
@@ -3418,9 +3416,9 @@ function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
3418
3416
  const { style } = props;
3419
3417
  const newValues = {};
3420
3418
  for (const key in style) {
3421
- if (isMotionValue(style[key]) ||
3419
+ if (motionDom.isMotionValue(style[key]) ||
3422
3420
  (prevProps.style &&
3423
- isMotionValue(prevProps.style[key])) ||
3421
+ motionDom.isMotionValue(prevProps.style[key])) ||
3424
3422
  isForcedMotionValue(key, props) ||
3425
3423
  visualElement?.getValue(key)?.liveStyle !== undefined) {
3426
3424
  newValues[key] = style[key];
@@ -3440,7 +3438,9 @@ class HTMLVisualElement extends DOMVisualElement {
3440
3438
  }
3441
3439
  readValueFromInstance(instance, key) {
3442
3440
  if (motionDom.transformProps.has(key)) {
3443
- return motionDom.readTransformValue(instance, key);
3441
+ return this.projection?.isProjecting
3442
+ ? motionDom.defaultTransformValue(key)
3443
+ : motionDom.readTransformValue(instance, key);
3444
3444
  }
3445
3445
  else {
3446
3446
  const computedStyle = getComputedStyle(instance);
@@ -3620,7 +3620,7 @@ function setTarget(visualElement, definition) {
3620
3620
  }
3621
3621
 
3622
3622
  function isWillChangeMotionValue(value) {
3623
- return Boolean(isMotionValue(value) && value.add);
3623
+ return Boolean(motionDom.isMotionValue(value) && value.add);
3624
3624
  }
3625
3625
 
3626
3626
  function addValueToWillChange(visualElement, key) {
@@ -5713,7 +5713,7 @@ const createHtmlRenderState = () => ({
5713
5713
 
5714
5714
  function copyRawValuesOnly(target, source, props) {
5715
5715
  for (const key in source) {
5716
- if (!isMotionValue(source[key]) && !isForcedMotionValue(key, props)) {
5716
+ if (!motionDom.isMotionValue(source[key]) && !isForcedMotionValue(key, props)) {
5717
5717
  target[key] = source[key];
5718
5718
  }
5719
5719
  }
@@ -5761,65 +5761,6 @@ function useHTMLProps(props, visualState) {
5761
5761
  return htmlProps;
5762
5762
  }
5763
5763
 
5764
- /**
5765
- * We keep these listed separately as we use the lowercase tag names as part
5766
- * of the runtime bundle to detect SVG components
5767
- */
5768
- const lowercaseSVGElements = [
5769
- "animate",
5770
- "circle",
5771
- "defs",
5772
- "desc",
5773
- "ellipse",
5774
- "g",
5775
- "image",
5776
- "line",
5777
- "filter",
5778
- "marker",
5779
- "mask",
5780
- "metadata",
5781
- "path",
5782
- "pattern",
5783
- "polygon",
5784
- "polyline",
5785
- "rect",
5786
- "stop",
5787
- "switch",
5788
- "symbol",
5789
- "svg",
5790
- "text",
5791
- "tspan",
5792
- "use",
5793
- "view",
5794
- ];
5795
-
5796
- function isSVGComponent(Component) {
5797
- if (
5798
- /**
5799
- * If it's not a string, it's a custom React component. Currently we only support
5800
- * HTML custom React components.
5801
- */
5802
- typeof Component !== "string" ||
5803
- /**
5804
- * If it contains a dash, the element is a custom HTML webcomponent.
5805
- */
5806
- Component.includes("-")) {
5807
- return false;
5808
- }
5809
- else if (
5810
- /**
5811
- * If it's in our list of lowercase SVG tags, it's an SVG component
5812
- */
5813
- lowercaseSVGElements.indexOf(Component) > -1 ||
5814
- /**
5815
- * If it contains a capital letter, it's an SVG component
5816
- */
5817
- /[A-Z]/u.test(Component)) {
5818
- return true;
5819
- }
5820
- return false;
5821
- }
5822
-
5823
5764
  const dashKeys = {
5824
5765
  offset: "stroke-dashoffset",
5825
5766
  array: "stroke-dasharray",
@@ -5926,6 +5867,65 @@ function useSVGProps(props, visualState, _isStatic, Component) {
5926
5867
  return visualProps;
5927
5868
  }
5928
5869
 
5870
+ /**
5871
+ * We keep these listed separately as we use the lowercase tag names as part
5872
+ * of the runtime bundle to detect SVG components
5873
+ */
5874
+ const lowercaseSVGElements = [
5875
+ "animate",
5876
+ "circle",
5877
+ "defs",
5878
+ "desc",
5879
+ "ellipse",
5880
+ "g",
5881
+ "image",
5882
+ "line",
5883
+ "filter",
5884
+ "marker",
5885
+ "mask",
5886
+ "metadata",
5887
+ "path",
5888
+ "pattern",
5889
+ "polygon",
5890
+ "polyline",
5891
+ "rect",
5892
+ "stop",
5893
+ "switch",
5894
+ "symbol",
5895
+ "svg",
5896
+ "text",
5897
+ "tspan",
5898
+ "use",
5899
+ "view",
5900
+ ];
5901
+
5902
+ function isSVGComponent(Component) {
5903
+ if (
5904
+ /**
5905
+ * If it's not a string, it's a custom React component. Currently we only support
5906
+ * HTML custom React components.
5907
+ */
5908
+ typeof Component !== "string" ||
5909
+ /**
5910
+ * If it contains a dash, the element is a custom HTML webcomponent.
5911
+ */
5912
+ Component.includes("-")) {
5913
+ return false;
5914
+ }
5915
+ else if (
5916
+ /**
5917
+ * If it's in our list of lowercase SVG tags, it's an SVG component
5918
+ */
5919
+ lowercaseSVGElements.indexOf(Component) > -1 ||
5920
+ /**
5921
+ * If it contains a capital letter, it's an SVG component
5922
+ */
5923
+ /[A-Z]/u.test(Component)) {
5924
+ return true;
5925
+ }
5926
+ return false;
5927
+ }
5928
+
5929
5929
  function createUseRender(forwardMotionProps = false) {
5930
5930
  const useRender = (Component, props, ref, { latestValues }, isStatic) => {
5931
5931
  const useVisualProps = isSVGComponent(Component)
@@ -5942,7 +5942,7 @@ function createUseRender(forwardMotionProps = false) {
5942
5942
  * will be handled by the onChange handler
5943
5943
  */
5944
5944
  const { children } = props;
5945
- const renderedChildren = React.useMemo(() => (isMotionValue(children) ? children.get() : children), [children]);
5945
+ const renderedChildren = React.useMemo(() => (motionDom.isMotionValue(children) ? children.get() : children), [children]);
5946
5946
  return React.createElement(Component, {
5947
5947
  ...elementProps,
5948
5948
  children: renderedChildren,
@@ -6030,8 +6030,8 @@ const htmlMotionConfig = {
6030
6030
  function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
6031
6031
  const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
6032
6032
  for (const key in props) {
6033
- if (isMotionValue(props[key]) ||
6034
- isMotionValue(prevProps[key])) {
6033
+ if (motionDom.isMotionValue(props[key]) ||
6034
+ motionDom.isMotionValue(prevProps[key])) {
6035
6035
  const targetKey = motionDom.transformPropOrder.indexOf(key) !== -1
6036
6036
  ? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
6037
6037
  : key;
@@ -6183,7 +6183,6 @@ exports.getOptimisedAppearId = getOptimisedAppearId;
6183
6183
  exports.hasReducedMotionListener = hasReducedMotionListener;
6184
6184
  exports.initPrefersReducedMotion = initPrefersReducedMotion;
6185
6185
  exports.isBrowser = isBrowser;
6186
- exports.isMotionValue = isMotionValue;
6187
6186
  exports.isSVGElement = isSVGElement;
6188
6187
  exports.isValidMotionProp = isValidMotionProp;
6189
6188
  exports.layout = layout;
@@ -5,8 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var motionDom = require('motion-dom');
6
6
  var motionUtils = require('motion-utils');
7
7
 
8
- const isMotionValue = (value) => Boolean(value && value.getVelocity);
9
-
10
8
  function isDOMKeyframes(keyframes) {
11
9
  return typeof keyframes === "object" && !Array.isArray(keyframes);
12
10
  }
@@ -229,7 +227,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
229
227
  maxDuration = Math.max(calculatedDelay + duration, maxDuration);
230
228
  totalDuration = Math.max(targetTime, totalDuration);
231
229
  };
232
- if (isMotionValue(subject)) {
230
+ if (motionDom.isMotionValue(subject)) {
233
231
  const subjectSequence = getSubjectSequence(subject, sequences);
234
232
  resolveValueSequence(keyframes, transition, getValueSequence("default", subjectSequence));
235
233
  }
package/dist/cjs/dom.js CHANGED
@@ -5,8 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var motionDom = require('motion-dom');
6
6
  var motionUtils = require('motion-utils');
7
7
 
8
- const isMotionValue = (value) => Boolean(value && value.getVelocity);
9
-
10
8
  function isDOMKeyframes(keyframes) {
11
9
  return typeof keyframes === "object" && !Array.isArray(keyframes);
12
10
  }
@@ -229,7 +227,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
229
227
  maxDuration = Math.max(calculatedDelay + duration, maxDuration);
230
228
  totalDuration = Math.max(targetTime, totalDuration);
231
229
  };
232
- if (isMotionValue(subject)) {
230
+ if (motionDom.isMotionValue(subject)) {
233
231
  const subjectSequence = getSubjectSequence(subject, sequences);
234
232
  resolveValueSequence(keyframes, transition, getValueSequence("default", subjectSequence));
235
233
  }
@@ -412,7 +410,7 @@ function setTarget(visualElement, definition) {
412
410
  }
413
411
 
414
412
  function isWillChangeMotionValue(value) {
415
- return Boolean(isMotionValue(value) && value.add);
413
+ return Boolean(motionDom.isMotionValue(value) && value.add);
416
414
  }
417
415
 
418
416
  function addValueToWillChange(visualElement, key) {
@@ -794,14 +792,14 @@ function updateMotionValuesFromProps(element, next, prev) {
794
792
  for (const key in next) {
795
793
  const nextValue = next[key];
796
794
  const prevValue = prev[key];
797
- if (isMotionValue(nextValue)) {
795
+ if (motionDom.isMotionValue(nextValue)) {
798
796
  /**
799
797
  * If this is a motion value found in props or style, we want to add it
800
798
  * to our visual element's motion value map.
801
799
  */
802
800
  element.addValue(key, nextValue);
803
801
  }
804
- else if (isMotionValue(prevValue)) {
802
+ else if (motionDom.isMotionValue(prevValue)) {
805
803
  /**
806
804
  * If we're swapping from a motion value to a static value,
807
805
  * create a new motion value from that
@@ -962,7 +960,7 @@ class VisualElement {
962
960
  const { willChange, ...initialMotionValues } = this.scrapeMotionValuesFromProps(props, {}, this);
963
961
  for (const key in initialMotionValues) {
964
962
  const value = initialMotionValues[key];
965
- if (latestValues[key] !== undefined && isMotionValue(value)) {
963
+ if (latestValues[key] !== undefined && motionDom.isMotionValue(value)) {
966
964
  value.set(latestValues[key], false);
967
965
  }
968
966
  }
@@ -1233,9 +1231,9 @@ class VisualElement {
1233
1231
  else if (!motionDom.findValueType(value) && motionDom.complex.test(target)) {
1234
1232
  value = motionDom.getAnimatableNone(key, target);
1235
1233
  }
1236
- this.setBaseTarget(key, isMotionValue(value) ? value.get() : value);
1234
+ this.setBaseTarget(key, motionDom.isMotionValue(value) ? value.get() : value);
1237
1235
  }
1238
- return isMotionValue(value) ? value.get() : value;
1236
+ return motionDom.isMotionValue(value) ? value.get() : value;
1239
1237
  }
1240
1238
  /**
1241
1239
  * Set the base target to later animate back to. This is currently
@@ -1268,7 +1266,7 @@ class VisualElement {
1268
1266
  * so we can read the value from an alternative source, try that.
1269
1267
  */
1270
1268
  const target = this.getBaseTargetFromProps(this.props, key);
1271
- if (target !== undefined && !isMotionValue(target))
1269
+ if (target !== undefined && !motionDom.isMotionValue(target))
1272
1270
  return target;
1273
1271
  /**
1274
1272
  * If the value was initially defined on initial, but it doesn't any more,
@@ -1320,7 +1318,7 @@ class DOMVisualElement extends VisualElement {
1320
1318
  delete this.childSubscription;
1321
1319
  }
1322
1320
  const { children } = this.props;
1323
- if (isMotionValue(children)) {
1321
+ if (motionDom.isMotionValue(children)) {
1324
1322
  this.childSubscription = children.on("change", (latest) => {
1325
1323
  if (this.current) {
1326
1324
  this.current.textContent = `${latest}`;
@@ -1466,9 +1464,9 @@ function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
1466
1464
  const { style } = props;
1467
1465
  const newValues = {};
1468
1466
  for (const key in style) {
1469
- if (isMotionValue(style[key]) ||
1467
+ if (motionDom.isMotionValue(style[key]) ||
1470
1468
  (prevProps.style &&
1471
- isMotionValue(prevProps.style[key])) ||
1469
+ motionDom.isMotionValue(prevProps.style[key])) ||
1472
1470
  isForcedMotionValue(key, props) ||
1473
1471
  visualElement?.getValue(key)?.liveStyle !== undefined) {
1474
1472
  newValues[key] = style[key];
@@ -1488,7 +1486,9 @@ class HTMLVisualElement extends DOMVisualElement {
1488
1486
  }
1489
1487
  readValueFromInstance(instance, key) {
1490
1488
  if (motionDom.transformProps.has(key)) {
1491
- return motionDom.readTransformValue(instance, key);
1489
+ return this.projection?.isProjecting
1490
+ ? motionDom.defaultTransformValue(key)
1491
+ : motionDom.readTransformValue(instance, key);
1492
1492
  }
1493
1493
  else {
1494
1494
  const computedStyle = getComputedStyle$1(instance);
@@ -1669,8 +1669,8 @@ function renderSVG(element, renderState, _styleProp, projection) {
1669
1669
  function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
1670
1670
  const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
1671
1671
  for (const key in props) {
1672
- if (isMotionValue(props[key]) ||
1673
- isMotionValue(prevProps[key])) {
1672
+ if (motionDom.isMotionValue(props[key]) ||
1673
+ motionDom.isMotionValue(prevProps[key])) {
1674
1674
  const targetKey = motionDom.transformPropOrder.indexOf(key) !== -1
1675
1675
  ? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
1676
1676
  : key;
@@ -1751,13 +1751,13 @@ function createObjectVisualElement(subject) {
1751
1751
  }
1752
1752
 
1753
1753
  function animateSingleValue(value, keyframes, options) {
1754
- const motionValue = isMotionValue(value) ? value : motionDom.motionValue(value);
1754
+ const motionValue = motionDom.isMotionValue(value) ? value : motionDom.motionValue(value);
1755
1755
  motionValue.start(animateMotionValue("", motionValue, keyframes, options));
1756
1756
  return motionValue.animation;
1757
1757
  }
1758
1758
 
1759
1759
  function isSingleValue(subject, keyframes) {
1760
- return (isMotionValue(subject) ||
1760
+ return (motionDom.isMotionValue(subject) ||
1761
1761
  typeof subject === "number" ||
1762
1762
  (typeof subject === "string" && !isDOMKeyframes(keyframes)));
1763
1763
  }
package/dist/cjs/index.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var React = require('react');
7
- var create = require('./create-9d9azvs6.js');
7
+ var create = require('./create-BiMCrvDh.js');
8
8
  var motionDom = require('motion-dom');
9
9
  var motionUtils = require('motion-utils');
10
10
 
@@ -709,7 +709,7 @@ function useListTransform(values, transformer) {
709
709
  }
710
710
 
711
711
  function useDefaultMotionValue(value, defaultValue = 0) {
712
- return create.isMotionValue(value) ? value : useMotionValue(defaultValue);
712
+ return motionDom.isMotionValue(value) ? value : useMotionValue(defaultValue);
713
713
  }
714
714
  function ReorderItemComponent({ children, style = {}, value, as = "li", onDrag, layout = true, ...props }, externalRef) {
715
715
  const Component = create.useConstant(() => motion[as]);
@@ -958,7 +958,7 @@ function createAnimationsFromSequence(sequence, { defaultTransition = {}, ...seq
958
958
  maxDuration = Math.max(calculatedDelay + duration, maxDuration);
959
959
  totalDuration = Math.max(targetTime, totalDuration);
960
960
  };
961
- if (create.isMotionValue(subject)) {
961
+ if (motionDom.isMotionValue(subject)) {
962
962
  const subjectSequence = getSubjectSequence(subject, sequences);
963
963
  resolveValueSequence(keyframes, transition, getValueSequence("default", subjectSequence));
964
964
  }
@@ -1143,7 +1143,7 @@ function createObjectVisualElement(subject) {
1143
1143
  }
1144
1144
 
1145
1145
  function isSingleValue(subject, keyframes) {
1146
- return (create.isMotionValue(subject) ||
1146
+ return (motionDom.isMotionValue(subject) ||
1147
1147
  typeof subject === "number" ||
1148
1148
  (typeof subject === "string" && !isDOMKeyframes(keyframes)));
1149
1149
  }
@@ -2048,64 +2048,27 @@ function useMotionTemplate(fragments, ...values) {
2048
2048
  output += fragments[i];
2049
2049
  const value = values[i];
2050
2050
  if (value) {
2051
- output += create.isMotionValue(value) ? value.get() : value;
2051
+ output += motionDom.isMotionValue(value) ? value.get() : value;
2052
2052
  }
2053
2053
  }
2054
2054
  return output;
2055
2055
  }
2056
- return useCombineMotionValues(values.filter(create.isMotionValue), buildValue);
2056
+ return useCombineMotionValues(values.filter(motionDom.isMotionValue), buildValue);
2057
2057
  }
2058
2058
 
2059
- function useSpring(source, config = {}) {
2059
+ function useSpring(source, options = {}) {
2060
2060
  const { isStatic } = React.useContext(create.MotionConfigContext);
2061
- const activeSpringAnimation = React.useRef(null);
2062
- const initialValue = create.useConstant(() => create.isMotionValue(source) ? source.get() : source);
2063
- const unit = create.useConstant(() => typeof initialValue === "string"
2064
- ? initialValue.replace(/[\d.-]/g, "")
2065
- : undefined);
2066
- const value = useMotionValue(initialValue);
2067
- const latestValue = React.useRef(initialValue);
2068
- const latestSetter = React.useRef(motionUtils.noop);
2069
- const startAnimation = () => {
2070
- stopAnimation();
2071
- activeSpringAnimation.current = new motionDom.JSAnimation({
2072
- keyframes: [asNumber(value.get()), asNumber(latestValue.current)],
2073
- velocity: value.getVelocity(),
2074
- type: "spring",
2075
- restDelta: 0.001,
2076
- restSpeed: 0.01,
2077
- ...config,
2078
- onUpdate: latestSetter.current,
2079
- });
2080
- };
2081
- const stopAnimation = () => {
2082
- if (activeSpringAnimation.current) {
2083
- activeSpringAnimation.current.stop();
2084
- }
2085
- };
2061
+ const getFromSource = () => (motionDom.isMotionValue(source) ? source.get() : source);
2062
+ // isStatic will never change, allowing early hooks return
2063
+ if (isStatic) {
2064
+ return useTransform(getFromSource);
2065
+ }
2066
+ const value = useMotionValue(getFromSource());
2086
2067
  React.useInsertionEffect(() => {
2087
- return value.attach((v, set) => {
2088
- if (isStatic)
2089
- return set(v);
2090
- latestValue.current = v;
2091
- latestSetter.current = (latest) => set(parseValue(latest, unit));
2092
- motionDom.frame.postRender(startAnimation);
2093
- return value.get();
2094
- }, stopAnimation);
2095
- }, [JSON.stringify(config)]);
2096
- create.useIsomorphicLayoutEffect(() => {
2097
- if (create.isMotionValue(source)) {
2098
- return source.on("change", (v) => value.set(parseValue(v, unit)));
2099
- }
2100
- }, [value, unit]);
2068
+ return motionDom.attachSpring(value, source, options);
2069
+ }, [value, JSON.stringify(options)]);
2101
2070
  return value;
2102
2071
  }
2103
- function parseValue(v, unit) {
2104
- return unit ? v + unit : v;
2105
- }
2106
- function asNumber(v) {
2107
- return typeof v === "number" ? v : parseFloat(v);
2108
- }
2109
2072
 
2110
2073
  function useAnimationFrame(callback) {
2111
2074
  const initialTimestamp = React.useRef(0);
@@ -2962,7 +2925,6 @@ exports.distance = create.distance;
2962
2925
  exports.distance2D = create.distance2D;
2963
2926
  exports.filterProps = create.filterProps;
2964
2927
  exports.isBrowser = create.isBrowser;
2965
- exports.isMotionValue = create.isMotionValue;
2966
2928
  exports.isValidMotionProp = create.isValidMotionProp;
2967
2929
  exports.makeUseVisualState = create.makeUseVisualState;
2968
2930
  exports.optimizedAppearDataAttribute = create.optimizedAppearDataAttribute;