motion 12.11.4 → 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 (26) hide show
  1. package/dist/cjs/index.js +72 -3
  2. package/dist/cjs/react-client.js +109 -109
  3. package/dist/cjs/react-m.js +108 -108
  4. package/dist/es/framer-motion/dist/es/animation/animate/single-value.mjs +1 -1
  5. package/dist/es/framer-motion/dist/es/animation/animate/subject.mjs +1 -1
  6. package/dist/es/framer-motion/dist/es/animation/sequence/create.mjs +1 -1
  7. package/dist/es/framer-motion/dist/es/components/Reorder/Item.mjs +1 -1
  8. package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +1 -1
  9. package/dist/es/framer-motion/dist/es/render/dom/DOMVisualElement.mjs +1 -1
  10. package/dist/es/framer-motion/dist/es/render/dom/use-render.mjs +2 -2
  11. package/dist/es/framer-motion/dist/es/render/html/use-props.mjs +1 -1
  12. package/dist/es/framer-motion/dist/es/render/html/utils/scrape-motion-values.mjs +1 -1
  13. package/dist/es/framer-motion/dist/es/render/svg/utils/scrape-motion-values.mjs +1 -1
  14. package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
  15. package/dist/es/framer-motion/dist/es/value/use-motion-template.mjs +1 -1
  16. package/dist/es/framer-motion/dist/es/value/use-spring.mjs +13 -53
  17. package/dist/es/framer-motion/dist/es/value/use-will-change/is.mjs +1 -1
  18. package/dist/es/framer-motion/dist/es/value/utils/resolve-motion-value.mjs +1 -1
  19. package/dist/es/motion/lib/index.mjs +2 -0
  20. package/dist/es/motion/lib/react.mjs +2 -1
  21. package/dist/es/motion-dom/dist/es/utils/interpolate.mjs +1 -1
  22. package/dist/es/motion-dom/dist/es/value/spring-value.mjs +72 -0
  23. package/dist/motion.dev.js +72 -3
  24. package/dist/motion.js +1 -1
  25. package/package.json +3 -3
  26. /package/dist/es/{framer-motion → motion-dom}/dist/es/value/utils/is-motion-value.mjs +0 -0
@@ -1,9 +1,9 @@
1
1
  import { Fragment, useMemo, createElement } from 'react';
2
2
  import { useHTMLProps } from '../html/use-props.mjs';
3
+ import { useSVGProps } from '../svg/use-props.mjs';
3
4
  import { filterProps } from './utils/filter-props.mjs';
4
5
  import { isSVGComponent } from './utils/is-svg-component.mjs';
5
- import { useSVGProps } from '../svg/use-props.mjs';
6
- import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
6
+ import { isMotionValue } from '../../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
7
7
 
8
8
  function createUseRender(forwardMotionProps = false) {
9
9
  const useRender = (Component, props, ref, { latestValues }, isStatic) => {
@@ -1,8 +1,8 @@
1
1
  import { useMemo } from 'react';
2
2
  import { isForcedMotionValue } from '../../motion/utils/is-forced-motion-value.mjs';
3
- import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
4
3
  import { buildHTMLStyles } from './utils/build-styles.mjs';
5
4
  import { createHtmlRenderState } from './utils/create-render-state.mjs';
5
+ import { isMotionValue } from '../../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
6
6
 
7
7
  function copyRawValuesOnly(target, source, props) {
8
8
  for (const key in source) {
@@ -1,5 +1,5 @@
1
1
  import { isForcedMotionValue } from '../../../motion/utils/is-forced-motion-value.mjs';
2
- import { isMotionValue } from '../../../value/utils/is-motion-value.mjs';
2
+ import { isMotionValue } from '../../../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
3
3
 
4
4
  function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
5
5
  const { style } = props;
@@ -1,5 +1,5 @@
1
- import { isMotionValue } from '../../../value/utils/is-motion-value.mjs';
2
1
  import { scrapeMotionValuesFromProps as scrapeMotionValuesFromProps$1 } from '../../html/utils/scrape-motion-values.mjs';
2
+ import { isMotionValue } from '../../../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
3
3
  import { transformPropOrder } from '../../../../../../motion-dom/dist/es/render/utils/keys-transform.mjs';
4
4
 
5
5
  function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
@@ -1,4 +1,4 @@
1
- import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
1
+ import { isMotionValue } from '../../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
2
2
  import { motionValue } from '../../../../../motion-dom/dist/es/value/index.mjs';
3
3
 
4
4
  function updateMotionValuesFromProps(element, next, prev) {
@@ -1,5 +1,5 @@
1
1
  import { useCombineMotionValues } from './use-combine-values.mjs';
2
- import { isMotionValue } from './utils/is-motion-value.mjs';
2
+ import { isMotionValue } from '../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
3
3
 
4
4
  /**
5
5
  * Combine multiple motion values into a new one using a string template literal.
@@ -1,62 +1,22 @@
1
- import { useContext, useRef, useInsertionEffect } from 'react';
1
+ import { useContext, useInsertionEffect } from 'react';
2
2
  import { MotionConfigContext } from '../context/MotionConfigContext.mjs';
3
- import { useConstant } from '../utils/use-constant.mjs';
4
- import { useIsomorphicLayoutEffect } from '../utils/use-isomorphic-effect.mjs';
5
3
  import { useMotionValue } from './use-motion-value.mjs';
6
- import { isMotionValue } from './utils/is-motion-value.mjs';
7
- import { noop } from '../../../../motion-utils/dist/es/noop.mjs';
8
- import { frame } from '../../../../motion-dom/dist/es/frameloop/frame.mjs';
9
- import { JSAnimation } from '../../../../motion-dom/dist/es/animation/JSAnimation.mjs';
4
+ import { useTransform } from './use-transform.mjs';
5
+ import { attachSpring } from '../../../../motion-dom/dist/es/value/spring-value.mjs';
6
+ import { isMotionValue } from '../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
10
7
 
11
- function useSpring(source, config = {}) {
8
+ function useSpring(source, options = {}) {
12
9
  const { isStatic } = useContext(MotionConfigContext);
13
- const activeSpringAnimation = useRef(null);
14
- const initialValue = useConstant(() => isMotionValue(source) ? source.get() : source);
15
- const unit = useConstant(() => typeof initialValue === "string"
16
- ? initialValue.replace(/[\d.-]/g, "")
17
- : undefined);
18
- const value = useMotionValue(initialValue);
19
- const latestValue = useRef(initialValue);
20
- const latestSetter = useRef(noop);
21
- const startAnimation = () => {
22
- stopAnimation();
23
- activeSpringAnimation.current = new JSAnimation({
24
- keyframes: [asNumber(value.get()), asNumber(latestValue.current)],
25
- velocity: value.getVelocity(),
26
- type: "spring",
27
- restDelta: 0.001,
28
- restSpeed: 0.01,
29
- ...config,
30
- onUpdate: latestSetter.current,
31
- });
32
- };
33
- const stopAnimation = () => {
34
- if (activeSpringAnimation.current) {
35
- activeSpringAnimation.current.stop();
36
- }
37
- };
10
+ const getFromSource = () => (isMotionValue(source) ? source.get() : source);
11
+ // isStatic will never change, allowing early hooks return
12
+ if (isStatic) {
13
+ return useTransform(getFromSource);
14
+ }
15
+ const value = useMotionValue(getFromSource());
38
16
  useInsertionEffect(() => {
39
- return value.attach((v, set) => {
40
- if (isStatic)
41
- return set(v);
42
- latestValue.current = v;
43
- latestSetter.current = (latest) => set(parseValue(latest, unit));
44
- frame.postRender(startAnimation);
45
- return value.get();
46
- }, stopAnimation);
47
- }, [JSON.stringify(config)]);
48
- useIsomorphicLayoutEffect(() => {
49
- if (isMotionValue(source)) {
50
- return source.on("change", (v) => value.set(parseValue(v, unit)));
51
- }
52
- }, [value, unit]);
17
+ return attachSpring(value, source, options);
18
+ }, [value, JSON.stringify(options)]);
53
19
  return value;
54
20
  }
55
- function parseValue(v, unit) {
56
- return unit ? v + unit : v;
57
- }
58
- function asNumber(v) {
59
- return typeof v === "number" ? v : parseFloat(v);
60
- }
61
21
 
62
22
  export { useSpring };
@@ -1,4 +1,4 @@
1
- import { isMotionValue } from '../utils/is-motion-value.mjs';
1
+ import { isMotionValue } from '../../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
2
2
 
3
3
  function isWillChangeMotionValue(value) {
4
4
  return Boolean(isMotionValue(value) && value.add);
@@ -1,4 +1,4 @@
1
- import { isMotionValue } from './is-motion-value.mjs';
1
+ import { isMotionValue } from '../../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
2
2
 
3
3
  /**
4
4
  * If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
@@ -72,6 +72,7 @@ export { supportsScrollTimeline } from '../../motion-dom/dist/es/utils/supports/
72
72
  export { transform } from '../../motion-dom/dist/es/utils/transform.mjs';
73
73
  export { MotionValue, collectMotionValues, motionValue } from '../../motion-dom/dist/es/value/index.mjs';
74
74
  export { mapValue } from '../../motion-dom/dist/es/value/map-value.mjs';
75
+ export { attachSpring, springValue } from '../../motion-dom/dist/es/value/spring-value.mjs';
75
76
  export { transformValue } from '../../motion-dom/dist/es/value/transform-value.mjs';
76
77
  export { color } from '../../motion-dom/dist/es/value/types/color/index.mjs';
77
78
  export { hex } from '../../motion-dom/dist/es/value/types/color/hex.mjs';
@@ -89,6 +90,7 @@ export { testValueType } from '../../motion-dom/dist/es/value/types/test.mjs';
89
90
  export { getAnimatableNone } from '../../motion-dom/dist/es/value/types/utils/animatable-none.mjs';
90
91
  export { findValueType } from '../../motion-dom/dist/es/value/types/utils/find.mjs';
91
92
  export { getValueAsType } from '../../motion-dom/dist/es/value/types/utils/get-as-type.mjs';
93
+ export { isMotionValue } from '../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
92
94
  export { ViewTransitionBuilder, animateView } from '../../motion-dom/dist/es/view/index.mjs';
93
95
  export { cancelSync, sync } from '../../motion-dom/dist/es/frameloop/index-legacy.mjs';
94
96
  export { cancelFrame, frame, frameData, frameSteps } from '../../motion-dom/dist/es/frameloop/frame.mjs';
@@ -16,7 +16,6 @@ export { isBrowser } from '../../framer-motion/dist/es/utils/is-browser.mjs';
16
16
  export { useForceUpdate } from '../../framer-motion/dist/es/utils/use-force-update.mjs';
17
17
  export { useIsomorphicLayoutEffect } from '../../framer-motion/dist/es/utils/use-isomorphic-effect.mjs';
18
18
  export { useUnmountEffect } from '../../framer-motion/dist/es/utils/use-unmount-effect.mjs';
19
- export { isMotionValue } from '../../framer-motion/dist/es/value/utils/is-motion-value.mjs';
20
19
  export { domAnimation } from '../../framer-motion/dist/es/render/dom/features-animation.mjs';
21
20
  export { domMax } from '../../framer-motion/dist/es/render/dom/features-max.mjs';
22
21
  export { domMin } from '../../framer-motion/dist/es/render/dom/features-min.mjs';
@@ -171,6 +170,7 @@ export { supportsScrollTimeline } from '../../motion-dom/dist/es/utils/supports/
171
170
  export { transform } from '../../motion-dom/dist/es/utils/transform.mjs';
172
171
  export { MotionValue, collectMotionValues, motionValue } from '../../motion-dom/dist/es/value/index.mjs';
173
172
  export { mapValue } from '../../motion-dom/dist/es/value/map-value.mjs';
173
+ export { attachSpring, springValue } from '../../motion-dom/dist/es/value/spring-value.mjs';
174
174
  export { transformValue } from '../../motion-dom/dist/es/value/transform-value.mjs';
175
175
  export { color } from '../../motion-dom/dist/es/value/types/color/index.mjs';
176
176
  export { hex } from '../../motion-dom/dist/es/value/types/color/hex.mjs';
@@ -188,6 +188,7 @@ export { testValueType } from '../../motion-dom/dist/es/value/types/test.mjs';
188
188
  export { getAnimatableNone } from '../../motion-dom/dist/es/value/types/utils/animatable-none.mjs';
189
189
  export { findValueType } from '../../motion-dom/dist/es/value/types/utils/find.mjs';
190
190
  export { getValueAsType } from '../../motion-dom/dist/es/value/types/utils/get-as-type.mjs';
191
+ export { isMotionValue } from '../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
191
192
  export { ViewTransitionBuilder, animateView } from '../../motion-dom/dist/es/view/index.mjs';
192
193
  export { cancelSync, sync } from '../../motion-dom/dist/es/frameloop/index-legacy.mjs';
193
194
  export { cancelFrame, frame, frameData, frameSteps } from '../../motion-dom/dist/es/frameloop/frame.mjs';
@@ -34,7 +34,7 @@ function createMixers(output, ease, customMixer) {
34
34
  * mixColor(0.5) // 'rgba(128, 128, 128, 1)'
35
35
  * ```
36
36
  *
37
- * TODO Revist this approach once we've moved to data models for values,
37
+ * TODO Revisit this approach once we've moved to data models for values,
38
38
  * probably not needed to pregenerate mixer functions.
39
39
  *
40
40
  * @public
@@ -0,0 +1,72 @@
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 a spring.
8
+ * Can either be a value or track another `MotionValue`.
9
+ *
10
+ * ```jsx
11
+ * const x = motionValue(0)
12
+ * const y = transformValue(() => x.get() * 2) // double x
13
+ * ```
14
+ *
15
+ * @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.
16
+ * @returns `MotionValue`
17
+ *
18
+ * @public
19
+ */
20
+ 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;
25
+ }
26
+ 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(startAnimation);
56
+ return value.get();
57
+ }, stopAnimation);
58
+ let unsubscribe = undefined;
59
+ if (isMotionValue(source)) {
60
+ unsubscribe = source.on("change", (v) => value.set(parseValue(v, unit)));
61
+ value.on("destroy", unsubscribe);
62
+ }
63
+ return unsubscribe;
64
+ }
65
+ function parseValue(v, unit) {
66
+ return unit ? v + unit : v;
67
+ }
68
+ function asNumber(v) {
69
+ return typeof v === "number" ? v : parseFloat(v);
70
+ }
71
+
72
+ export { attachSpring, springValue };
@@ -1425,7 +1425,7 @@
1425
1425
  * mixColor(0.5) // 'rgba(128, 128, 128, 1)'
1426
1426
  * ```
1427
1427
  *
1428
- * TODO Revist this approach once we've moved to data models for values,
1428
+ * TODO Revisit this approach once we've moved to data models for values,
1429
1429
  * probably not needed to pregenerate mixer functions.
1430
1430
  *
1431
1431
  * @public
@@ -4269,6 +4269,74 @@
4269
4269
  return transformValue(() => map(inputValue.get()));
4270
4270
  }
4271
4271
 
4272
+ const isMotionValue = (value) => Boolean(value && value.getVelocity);
4273
+
4274
+ /**
4275
+ * Create a `MotionValue` that animates to its latest value using a spring.
4276
+ * Can either be a value or track another `MotionValue`.
4277
+ *
4278
+ * ```jsx
4279
+ * const x = motionValue(0)
4280
+ * const y = transformValue(() => x.get() * 2) // double x
4281
+ * ```
4282
+ *
4283
+ * @param transformer - A transform function. This function must be pure with no side-effects or conditional statements.
4284
+ * @returns `MotionValue`
4285
+ *
4286
+ * @public
4287
+ */
4288
+ function springValue(source, options) {
4289
+ const initialValue = isMotionValue(source) ? source.get() : source;
4290
+ const value = motionValue(initialValue);
4291
+ attachSpring(value, source, options);
4292
+ return value;
4293
+ }
4294
+ function attachSpring(value, source, options) {
4295
+ const initialValue = value.get();
4296
+ let activeAnimation = null;
4297
+ let latestValue = initialValue;
4298
+ let latestSetter;
4299
+ const unit = typeof initialValue === "string"
4300
+ ? initialValue.replace(/[\d.-]/g, "")
4301
+ : undefined;
4302
+ const stopAnimation = () => {
4303
+ if (activeAnimation) {
4304
+ activeAnimation.stop();
4305
+ activeAnimation = null;
4306
+ }
4307
+ };
4308
+ const startAnimation = () => {
4309
+ stopAnimation();
4310
+ activeAnimation = new JSAnimation({
4311
+ keyframes: [asNumber(value.get()), asNumber(latestValue)],
4312
+ velocity: value.getVelocity(),
4313
+ type: "spring",
4314
+ restDelta: 0.001,
4315
+ restSpeed: 0.01,
4316
+ ...options,
4317
+ onUpdate: latestSetter,
4318
+ });
4319
+ };
4320
+ value.attach((v, set) => {
4321
+ latestValue = v;
4322
+ latestSetter = (latest) => set(parseValue(latest, unit));
4323
+ frame.postRender(startAnimation);
4324
+ return value.get();
4325
+ }, stopAnimation);
4326
+ let unsubscribe = undefined;
4327
+ if (isMotionValue(source)) {
4328
+ unsubscribe = source.on("change", (v) => value.set(parseValue(v, unit)));
4329
+ value.on("destroy", unsubscribe);
4330
+ }
4331
+ return unsubscribe;
4332
+ }
4333
+ function parseValue(v, unit) {
4334
+ return unit ? v + unit : v;
4335
+ }
4336
+ function asNumber(v) {
4337
+ return typeof v === "number" ? v : parseFloat(v);
4338
+ }
4339
+
4272
4340
  /**
4273
4341
  * A list of all ValueTypes
4274
4342
  */
@@ -4605,8 +4673,6 @@
4605
4673
  return acc;
4606
4674
  }, {});
4607
4675
 
4608
- const isMotionValue = (value) => Boolean(value && value.getVelocity);
4609
-
4610
4676
  function isDOMKeyframes(keyframes) {
4611
4677
  return typeof keyframes === "object" && !Array.isArray(keyframes);
4612
4678
  }
@@ -7187,6 +7253,7 @@
7187
7253
  exports.animationMapKey = animationMapKey;
7188
7254
  exports.anticipate = anticipate;
7189
7255
  exports.applyPxDefaults = applyPxDefaults;
7256
+ exports.attachSpring = attachSpring;
7190
7257
  exports.backIn = backIn;
7191
7258
  exports.backInOut = backInOut;
7192
7259
  exports.backOut = backOut;
@@ -7254,6 +7321,7 @@
7254
7321
  exports.isDragging = isDragging;
7255
7322
  exports.isEasingArray = isEasingArray;
7256
7323
  exports.isGenerator = isGenerator;
7324
+ exports.isMotionValue = isMotionValue;
7257
7325
  exports.isNodeOrChild = isNodeOrChild;
7258
7326
  exports.isNumericalString = isNumericalString;
7259
7327
  exports.isPrimaryPointer = isPrimaryPointer;
@@ -7305,6 +7373,7 @@
7305
7373
  exports.setDragLock = setDragLock;
7306
7374
  exports.setStyle = setStyle;
7307
7375
  exports.spring = spring;
7376
+ exports.springValue = springValue;
7308
7377
  exports.stagger = stagger;
7309
7378
  exports.startWaapiAnimation = startWaapiAnimation;
7310
7379
  exports.statsBuffer = statsBuffer;