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.
- package/README.md +21 -5
- package/dist/cjs/index.js +76 -4
- package/dist/cjs/react-client.js +112 -110
- package/dist/cjs/react-m.js +108 -108
- package/dist/es/framer-motion/dist/es/animation/animate/single-value.mjs +1 -1
- package/dist/es/framer-motion/dist/es/animation/animate/subject.mjs +1 -1
- package/dist/es/framer-motion/dist/es/animation/sequence/create.mjs +1 -1
- package/dist/es/framer-motion/dist/es/components/Reorder/Item.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/dom/DOMVisualElement.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/dom/use-render.mjs +2 -2
- package/dist/es/framer-motion/dist/es/render/html/HTMLVisualElement.mjs +4 -2
- package/dist/es/framer-motion/dist/es/render/html/use-props.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/html/utils/scrape-motion-values.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/svg/utils/scrape-motion-values.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/framer-motion/dist/es/value/use-motion-template.mjs +1 -1
- package/dist/es/framer-motion/dist/es/value/use-spring.mjs +13 -53
- package/dist/es/framer-motion/dist/es/value/use-will-change/is.mjs +1 -1
- package/dist/es/framer-motion/dist/es/value/utils/resolve-motion-value.mjs +1 -1
- package/dist/es/motion/lib/index.mjs +3 -1
- package/dist/es/motion/lib/react.mjs +3 -2
- package/dist/es/motion-dom/dist/es/render/dom/parse-transform.mjs +1 -1
- package/dist/es/motion-dom/dist/es/utils/interpolate.mjs +1 -1
- package/dist/es/motion-dom/dist/es/value/spring-value.mjs +72 -0
- package/dist/motion.dev.js +76 -4
- package/dist/motion.js +1 -1
- package/package.json +3 -3
- /package/dist/es/{framer-motion → motion-dom}/dist/es/value/utils/is-motion-value.mjs +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { visualElementStore } from '../../render/store.mjs';
|
|
2
|
-
import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
|
|
3
2
|
import { animateTarget } from '../interfaces/visual-element-target.mjs';
|
|
4
3
|
import { createDOMVisualElement, createObjectVisualElement } from '../utils/create-visual-element.mjs';
|
|
5
4
|
import { isDOMKeyframes } from '../utils/is-dom-keyframes.mjs';
|
|
6
5
|
import { resolveSubjects } from './resolve-subjects.mjs';
|
|
7
6
|
import { animateSingleValue } from './single-value.mjs';
|
|
8
7
|
import { invariant } from '../../../../../motion-utils/dist/es/errors.mjs';
|
|
8
|
+
import { isMotionValue } from '../../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
|
|
9
9
|
|
|
10
10
|
function isSingleValue(subject, keyframes) {
|
|
11
11
|
return (isMotionValue(subject) ||
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
|
|
2
1
|
import { resolveSubjects } from '../animate/resolve-subjects.mjs';
|
|
3
2
|
import { calculateRepeatDuration } from './utils/calc-repeat-duration.mjs';
|
|
4
3
|
import { calcNextTime } from './utils/calc-time.mjs';
|
|
5
4
|
import { addKeyframes } from './utils/edit.mjs';
|
|
6
5
|
import { normalizeTimes } from './utils/normalize-times.mjs';
|
|
7
6
|
import { compareByTime } from './utils/sort.mjs';
|
|
7
|
+
import { isMotionValue } from '../../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
|
|
8
8
|
import { defaultOffset } from '../../../../../motion-dom/dist/es/animation/keyframes/offsets/default.mjs';
|
|
9
9
|
import { isGenerator } from '../../../../../motion-dom/dist/es/animation/generators/utils/is-generator.mjs';
|
|
10
10
|
import { createGeneratorEasing } from '../../../../../motion-dom/dist/es/animation/generators/utils/create-generator-easing.mjs';
|
|
@@ -6,8 +6,8 @@ import { motion } from '../../render/components/motion/proxy.mjs';
|
|
|
6
6
|
import { useConstant } from '../../utils/use-constant.mjs';
|
|
7
7
|
import { useMotionValue } from '../../value/use-motion-value.mjs';
|
|
8
8
|
import { useTransform } from '../../value/use-transform.mjs';
|
|
9
|
-
import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
|
|
10
9
|
import { invariant } from '../../../../../motion-utils/dist/es/errors.mjs';
|
|
10
|
+
import { isMotionValue } from '../../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
|
|
11
11
|
|
|
12
12
|
function useDefaultMotionValue(value, defaultValue = 0) {
|
|
13
13
|
return isMotionValue(value) ? value : useMotionValue(defaultValue);
|
|
@@ -2,7 +2,6 @@ import { featureDefinitions } from '../motion/features/definitions.mjs';
|
|
|
2
2
|
import { createBox } from '../projection/geometry/models.mjs';
|
|
3
3
|
import { initPrefersReducedMotion } from '../utils/reduced-motion/index.mjs';
|
|
4
4
|
import { hasReducedMotionListener, prefersReducedMotion } from '../utils/reduced-motion/state.mjs';
|
|
5
|
-
import { isMotionValue } from '../value/utils/is-motion-value.mjs';
|
|
6
5
|
import { visualElementStore } from './store.mjs';
|
|
7
6
|
import { isControllingVariants, isVariantNode } from './utils/is-controlling-variants.mjs';
|
|
8
7
|
import { updateMotionValuesFromProps } from './utils/motion-values.mjs';
|
|
@@ -10,6 +9,7 @@ import { resolveVariantFromProps } from './utils/resolve-variants.mjs';
|
|
|
10
9
|
import { KeyframeResolver } from '../../../../motion-dom/dist/es/animation/keyframes/KeyframesResolver.mjs';
|
|
11
10
|
import { time } from '../../../../motion-dom/dist/es/frameloop/sync-time.mjs';
|
|
12
11
|
import { frame, cancelFrame } from '../../../../motion-dom/dist/es/frameloop/frame.mjs';
|
|
12
|
+
import { isMotionValue } from '../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
|
|
13
13
|
import { warnOnce } from '../../../../motion-utils/dist/es/warn-once.mjs';
|
|
14
14
|
import { transformProps } from '../../../../motion-dom/dist/es/render/utils/keys-transform.mjs';
|
|
15
15
|
import { motionValue } from '../../../../motion-dom/dist/es/value/index.mjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
|
|
2
1
|
import { VisualElement } from '../VisualElement.mjs';
|
|
3
2
|
import { DOMKeyframesResolver } from '../../../../../motion-dom/dist/es/animation/keyframes/DOMKeyframesResolver.mjs';
|
|
3
|
+
import { isMotionValue } from '../../../../../motion-dom/dist/es/value/utils/is-motion-value.mjs';
|
|
4
4
|
|
|
5
5
|
class DOMVisualElement extends VisualElement {
|
|
6
6
|
constructor() {
|
|
@@ -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 {
|
|
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) => {
|
|
@@ -4,7 +4,7 @@ import { buildHTMLStyles } from './utils/build-styles.mjs';
|
|
|
4
4
|
import { renderHTML } from './utils/render.mjs';
|
|
5
5
|
import { scrapeMotionValuesFromProps } from './utils/scrape-motion-values.mjs';
|
|
6
6
|
import { transformProps } from '../../../../../motion-dom/dist/es/render/utils/keys-transform.mjs';
|
|
7
|
-
import { readTransformValue } from '../../../../../motion-dom/dist/es/render/dom/parse-transform.mjs';
|
|
7
|
+
import { defaultTransformValue, readTransformValue } from '../../../../../motion-dom/dist/es/render/dom/parse-transform.mjs';
|
|
8
8
|
import { isCSSVariableName } from '../../../../../motion-dom/dist/es/animation/utils/is-css-variable.mjs';
|
|
9
9
|
|
|
10
10
|
function getComputedStyle(element) {
|
|
@@ -18,7 +18,9 @@ class HTMLVisualElement extends DOMVisualElement {
|
|
|
18
18
|
}
|
|
19
19
|
readValueFromInstance(instance, key) {
|
|
20
20
|
if (transformProps.has(key)) {
|
|
21
|
-
return
|
|
21
|
+
return this.projection?.isProjecting
|
|
22
|
+
? defaultTransformValue(key)
|
|
23
|
+
: readTransformValue(instance, key);
|
|
22
24
|
}
|
|
23
25
|
else {
|
|
24
26
|
const computedStyle = getComputedStyle(instance);
|
|
@@ -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 '
|
|
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 '
|
|
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 '
|
|
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,
|
|
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 {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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,
|
|
8
|
+
function useSpring(source, options = {}) {
|
|
12
9
|
const { isStatic } = useContext(MotionConfigContext);
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const value = useMotionValue(
|
|
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
|
|
40
|
-
|
|
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 };
|
|
@@ -49,7 +49,7 @@ export { hover } from '../../motion-dom/dist/es/gestures/hover.mjs';
|
|
|
49
49
|
export { press } from '../../motion-dom/dist/es/gestures/press/index.mjs';
|
|
50
50
|
export { isNodeOrChild } from '../../motion-dom/dist/es/gestures/utils/is-node-or-child.mjs';
|
|
51
51
|
export { isPrimaryPointer } from '../../motion-dom/dist/es/gestures/utils/is-primary-pointer.mjs';
|
|
52
|
-
export { parseValueFromTransform, readTransformValue } from '../../motion-dom/dist/es/render/dom/parse-transform.mjs';
|
|
52
|
+
export { defaultTransformValue, parseValueFromTransform, readTransformValue } from '../../motion-dom/dist/es/render/dom/parse-transform.mjs';
|
|
53
53
|
export { getComputedStyle } from '../../motion-dom/dist/es/render/dom/style-computed.mjs';
|
|
54
54
|
export { setStyle } from '../../motion-dom/dist/es/render/dom/style-set.mjs';
|
|
55
55
|
export { positionalKeys } from '../../motion-dom/dist/es/render/utils/keys-position.mjs';
|
|
@@ -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';
|
|
@@ -148,7 +147,7 @@ export { hover } from '../../motion-dom/dist/es/gestures/hover.mjs';
|
|
|
148
147
|
export { press } from '../../motion-dom/dist/es/gestures/press/index.mjs';
|
|
149
148
|
export { isNodeOrChild } from '../../motion-dom/dist/es/gestures/utils/is-node-or-child.mjs';
|
|
150
149
|
export { isPrimaryPointer } from '../../motion-dom/dist/es/gestures/utils/is-primary-pointer.mjs';
|
|
151
|
-
export { parseValueFromTransform, readTransformValue } from '../../motion-dom/dist/es/render/dom/parse-transform.mjs';
|
|
150
|
+
export { defaultTransformValue, parseValueFromTransform, readTransformValue } from '../../motion-dom/dist/es/render/dom/parse-transform.mjs';
|
|
152
151
|
export { getComputedStyle } from '../../motion-dom/dist/es/render/dom/style-computed.mjs';
|
|
153
152
|
export { setStyle } from '../../motion-dom/dist/es/render/dom/style-set.mjs';
|
|
154
153
|
export { positionalKeys } from '../../motion-dom/dist/es/render/utils/keys-position.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
|
|
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 };
|
package/dist/motion.dev.js
CHANGED
|
@@ -1425,7 +1425,7 @@
|
|
|
1425
1425
|
* mixColor(0.5) // 'rgba(128, 128, 128, 1)'
|
|
1426
1426
|
* ```
|
|
1427
1427
|
*
|
|
1428
|
-
* TODO
|
|
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
|
}
|
|
@@ -6088,7 +6154,9 @@
|
|
|
6088
6154
|
}
|
|
6089
6155
|
readValueFromInstance(instance, key) {
|
|
6090
6156
|
if (transformProps.has(key)) {
|
|
6091
|
-
return
|
|
6157
|
+
return this.projection?.isProjecting
|
|
6158
|
+
? defaultTransformValue(key)
|
|
6159
|
+
: readTransformValue(instance, key);
|
|
6092
6160
|
}
|
|
6093
6161
|
else {
|
|
6094
6162
|
const computedStyle = getComputedStyle$1(instance);
|
|
@@ -7185,6 +7253,7 @@
|
|
|
7185
7253
|
exports.animationMapKey = animationMapKey;
|
|
7186
7254
|
exports.anticipate = anticipate;
|
|
7187
7255
|
exports.applyPxDefaults = applyPxDefaults;
|
|
7256
|
+
exports.attachSpring = attachSpring;
|
|
7188
7257
|
exports.backIn = backIn;
|
|
7189
7258
|
exports.backInOut = backInOut;
|
|
7190
7259
|
exports.backOut = backOut;
|
|
@@ -7207,6 +7276,7 @@
|
|
|
7207
7276
|
exports.cubicBezierAsString = cubicBezierAsString;
|
|
7208
7277
|
exports.defaultEasing = defaultEasing;
|
|
7209
7278
|
exports.defaultOffset = defaultOffset$1;
|
|
7279
|
+
exports.defaultTransformValue = defaultTransformValue;
|
|
7210
7280
|
exports.defaultValueTypes = defaultValueTypes;
|
|
7211
7281
|
exports.degrees = degrees;
|
|
7212
7282
|
exports.delay = delayInSeconds;
|
|
@@ -7251,6 +7321,7 @@
|
|
|
7251
7321
|
exports.isDragging = isDragging;
|
|
7252
7322
|
exports.isEasingArray = isEasingArray;
|
|
7253
7323
|
exports.isGenerator = isGenerator;
|
|
7324
|
+
exports.isMotionValue = isMotionValue;
|
|
7254
7325
|
exports.isNodeOrChild = isNodeOrChild;
|
|
7255
7326
|
exports.isNumericalString = isNumericalString;
|
|
7256
7327
|
exports.isPrimaryPointer = isPrimaryPointer;
|
|
@@ -7302,6 +7373,7 @@
|
|
|
7302
7373
|
exports.setDragLock = setDragLock;
|
|
7303
7374
|
exports.setStyle = setStyle;
|
|
7304
7375
|
exports.spring = spring;
|
|
7376
|
+
exports.springValue = springValue;
|
|
7305
7377
|
exports.stagger = stagger;
|
|
7306
7378
|
exports.startWaapiAnimation = startWaapiAnimation;
|
|
7307
7379
|
exports.statsBuffer = statsBuffer;
|