motion 12.0.0-alpha.2 → 12.0.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.
- package/LICENSE.md +1 -1
- package/README.md +7 -24
- package/dist/cjs/index.js +2792 -2446
- package/dist/cjs/mini.js +629 -193
- package/dist/cjs/react-client.js +3611 -3416
- package/dist/cjs/react-m.js +397 -351
- package/dist/cjs/react-mini.js +225 -191
- package/dist/es/framer-motion/dist/es/animation/animate/index.mjs +3 -2
- package/dist/es/framer-motion/dist/es/animation/animate/resolve-subjects.mjs +2 -1
- 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/animators/AcceleratedAnimation.mjs +16 -12
- package/dist/es/framer-motion/dist/es/animation/animators/BaseAnimation.mjs +3 -2
- package/dist/es/framer-motion/dist/es/animation/animators/MainThreadAnimation.mjs +10 -10
- package/dist/es/framer-motion/dist/es/animation/animators/utils/can-animate.mjs +2 -2
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/NativeAnimation.mjs +30 -89
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-elements.mjs +4 -4
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-sequence.mjs +14 -0
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/animate-style.mjs +2 -1
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/index.mjs +2 -1
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-partial-keyframes.mjs +2 -1
- package/dist/es/framer-motion/dist/es/animation/animators/waapi/utils/supports-waapi.mjs +2 -1
- package/dist/es/framer-motion/dist/es/animation/generators/spring/defaults.mjs +27 -0
- package/dist/es/framer-motion/dist/es/animation/generators/spring/find.mjs +10 -13
- package/dist/es/framer-motion/dist/es/animation/generators/spring/index.mjs +57 -18
- package/dist/es/framer-motion/dist/es/animation/hooks/animation-controls.mjs +1 -1
- package/dist/es/framer-motion/dist/es/animation/interfaces/motion-value.mjs +7 -6
- package/dist/es/framer-motion/dist/es/animation/interfaces/visual-element-target.mjs +6 -5
- package/dist/es/framer-motion/dist/es/animation/optimized-appear/start.mjs +2 -1
- package/dist/es/framer-motion/dist/es/animation/optimized-appear/store-id.mjs +1 -1
- package/dist/es/framer-motion/dist/es/animation/sequence/create.mjs +32 -6
- package/dist/es/framer-motion/dist/es/animation/sequence/utils/calc-repeat-duration.mjs +5 -0
- package/dist/es/framer-motion/dist/es/animation/sequence/utils/normalize-times.mjs +13 -0
- package/dist/es/framer-motion/dist/es/animation/utils/default-transitions.mjs +1 -1
- package/dist/es/framer-motion/dist/es/components/AnimatePresence/index.mjs +10 -7
- package/dist/es/framer-motion/dist/es/components/AnimatePresence/use-presence.mjs +6 -3
- package/dist/es/framer-motion/dist/es/components/AnimateSharedLayout.mjs +1 -1
- package/dist/es/framer-motion/dist/es/components/Reorder/Group.mjs +1 -1
- package/dist/es/framer-motion/dist/es/components/Reorder/Item.mjs +1 -1
- package/dist/es/framer-motion/dist/es/easing/cubic-bezier.mjs +2 -1
- package/dist/es/framer-motion/dist/es/easing/utils/map.mjs +6 -6
- package/dist/es/framer-motion/dist/es/events/event-info.mjs +5 -4
- package/dist/es/framer-motion/dist/es/frameloop/frame.mjs +2 -1
- package/dist/es/framer-motion/dist/es/frameloop/render-step.mjs +3 -2
- package/dist/es/framer-motion/dist/es/gestures/drag/VisualElementDragControls.mjs +12 -15
- package/dist/es/framer-motion/dist/es/gestures/drag/index.mjs +2 -1
- package/dist/es/framer-motion/dist/es/gestures/drag/utils/constraints.mjs +2 -1
- package/dist/es/framer-motion/dist/es/gestures/hover.mjs +20 -22
- package/dist/es/framer-motion/dist/es/gestures/pan/PanSession.mjs +6 -5
- package/dist/es/framer-motion/dist/es/gestures/pan/index.mjs +2 -1
- package/dist/es/framer-motion/dist/es/gestures/press.mjs +20 -119
- package/dist/es/framer-motion/dist/es/motion/index.mjs +11 -7
- package/dist/es/framer-motion/dist/es/motion/utils/is-forced-motion-value.mjs +1 -1
- package/dist/es/framer-motion/dist/es/motion/utils/use-motion-ref.mjs +3 -1
- package/dist/es/framer-motion/dist/es/motion/utils/use-visual-element.mjs +1 -1
- package/dist/es/framer-motion/dist/es/motion/utils/use-visual-state.mjs +11 -5
- package/dist/es/framer-motion/dist/es/projection/animation/mix-values.mjs +3 -2
- package/dist/es/framer-motion/dist/es/projection/node/create-projection-node.mjs +29 -23
- package/dist/es/framer-motion/dist/es/render/VisualElement.mjs +15 -13
- package/dist/es/framer-motion/dist/es/render/dom/DOMKeyframesResolver.mjs +4 -3
- package/dist/es/framer-motion/dist/es/render/dom/DOMVisualElement.mjs +15 -0
- package/dist/es/framer-motion/dist/es/render/dom/resize/handle-element.mjs +2 -1
- package/dist/es/framer-motion/dist/es/render/dom/scroll/index.mjs +4 -4
- package/dist/es/framer-motion/dist/es/render/dom/scroll/info.mjs +2 -1
- package/dist/es/framer-motion/dist/es/render/dom/scroll/offsets/index.mjs +6 -5
- package/dist/es/framer-motion/dist/es/render/dom/utils/css-variables-conversion.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/dom/utils/unit-conversion.mjs +2 -14
- package/dist/es/framer-motion/dist/es/render/dom/viewport/index.mjs +4 -3
- package/dist/es/framer-motion/dist/es/render/html/HTMLVisualElement.mjs +6 -20
- package/dist/es/framer-motion/dist/es/render/html/utils/build-styles.mjs +2 -2
- package/dist/es/framer-motion/dist/es/render/html/utils/build-transform.mjs +1 -1
- package/dist/es/framer-motion/dist/es/render/html/utils/keys-position.mjs +13 -0
- package/dist/es/framer-motion/dist/es/render/svg/SVGVisualElement.mjs +6 -6
- package/dist/es/framer-motion/dist/es/render/svg/config-motion.mjs +57 -24
- package/dist/es/framer-motion/dist/es/render/svg/utils/build-attrs.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/utils/delay.mjs +2 -1
- package/dist/es/framer-motion/dist/es/utils/get-context-window.mjs +1 -1
- package/dist/es/framer-motion/dist/es/utils/interpolate.mjs +8 -5
- package/dist/es/framer-motion/dist/es/utils/mix/color.mjs +1 -1
- package/dist/es/framer-motion/dist/es/utils/mix/complex.mjs +1 -1
- package/dist/es/framer-motion/dist/es/utils/offsets/fill.mjs +2 -1
- package/dist/es/framer-motion/dist/es/utils/use-instant-transition.mjs +1 -1
- package/dist/es/framer-motion/dist/es/value/index.mjs +2 -2
- package/dist/es/framer-motion/dist/es/value/use-inverted-scale.mjs +1 -1
- package/dist/es/framer-motion/dist/es/value/use-scroll.mjs +1 -1
- package/dist/es/framer-motion/dist/es/value/use-spring.mjs +3 -3
- package/dist/es/framer-motion/dist/es/value/use-will-change/get-will-change-name.mjs +1 -1
- package/dist/es/motion/lib/index.mjs +12 -7
- package/dist/es/motion/lib/mini.mjs +1 -0
- package/dist/es/motion/lib/react.mjs +41 -37
- package/dist/es/{framer-motion/dist/es/animation/GroupPlaybackControls.mjs → motion-dom/dist/es/animation/controls/BaseGroup.mjs} +7 -6
- package/dist/es/motion-dom/dist/es/animation/controls/Group.mjs +13 -0
- package/dist/es/{framer-motion/dist/es/easing → motion-dom/dist/es/animation/generators}/utils/create-generator-easing.mjs +6 -3
- package/dist/es/motion-dom/dist/es/animation/waapi/NativeAnimationControls.mjs +85 -0
- package/dist/es/{framer-motion/dist/es/animation/animators/waapi → motion-dom/dist/es/animation/waapi/utils}/easing.mjs +3 -3
- package/dist/es/{framer-motion/dist/es/animation/animators → motion-dom/dist/es/animation}/waapi/utils/linear.mjs +4 -4
- package/dist/es/motion-dom/dist/es/gestures/drag/state/is-active.mjs +9 -0
- package/dist/es/motion-dom/dist/es/gestures/drag/state/set-active.mjs +28 -0
- package/dist/es/motion-dom/dist/es/gestures/hover.mjs +37 -0
- package/dist/es/motion-dom/dist/es/gestures/press/index.mjs +76 -0
- package/dist/es/motion-dom/dist/es/gestures/press/utils/is-keyboard-accessible.mjs +13 -0
- package/dist/es/motion-dom/dist/es/gestures/press/utils/keyboard.mjs +38 -0
- package/dist/es/motion-dom/dist/es/gestures/press/utils/state.mjs +3 -0
- package/dist/es/motion-dom/dist/es/gestures/utils/setup.mjs +15 -0
- package/dist/es/motion-dom/dist/es/utils/resolve-elements.mjs +22 -0
- package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/supports-linear-easing.mjs → motion-dom/dist/es/utils/supports/linear-easing.mjs} +1 -1
- package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/memo-supports.mjs → motion-dom/dist/es/utils/supports/memo.mjs} +3 -2
- package/dist/es/motion-dom/dist/es/utils/supports/scroll-timeline.mjs +6 -0
- package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/memo.mjs +1 -0
- package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/noop.mjs +1 -0
- package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/progress.mjs +1 -0
- package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/time-conversion.mjs +2 -0
- package/dist/motion.dev.js +2792 -2446
- package/dist/motion.js +1 -1
- package/package.json +6 -6
- package/.turbo/turbo-build.log +0 -47
- package/dist/es/framer-motion/dist/es/gestures/drag/utils/lock.mjs +0 -53
- package/dist/es/framer-motion/dist/es/render/dom/scroll/supports.mjs +0 -5
- package/dist/es/framer-motion/dist/es/render/dom/utils/resolve-element.mjs +0 -28
- package/lib/index.js +0 -2
- package/lib/index.js.map +0 -1
- package/lib/mini.js +0 -2
- package/lib/mini.js.map +0 -1
- package/lib/react-client.js +0 -3
- package/lib/react-client.js.map +0 -1
- package/lib/react-m.js +0 -3
- package/lib/react-m.js.map +0 -1
- package/lib/react-mini.js +0 -3
- package/lib/react-mini.js.map +0 -1
- package/lib/react.js +0 -3
- package/lib/react.js.map +0 -1
- package/rollup.config.mjs +0 -210
- package/src/index.ts +0 -1
- package/src/mini.ts +0 -1
- package/src/react-client.ts +0 -3
- package/src/react-m.ts +0 -3
- package/src/react-mini.ts +0 -3
- package/src/react.ts +0 -3
- package/tsconfig.json +0 -25
- package/types/index.d.ts +0 -1
- package/types/mini.d.ts +0 -1
- package/types/react-client.d.ts +0 -1
- package/types/react-m.d.ts +0 -1
- package/types/react-mini.d.ts +0 -1
- package/types/react.d.ts +0 -1
- /package/dist/es/framer-motion/dist/es/render/html/utils/{transform.mjs → keys-transform.mjs} +0 -0
- /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/generators/utils/calc-duration.mjs +0 -0
- /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/generators/utils/is-generator.mjs +0 -0
- /package/dist/es/{framer-motion → motion-dom}/dist/es/animation/utils/get-value-transition.mjs +0 -0
- /package/dist/es/{framer-motion/dist/es/animation/animators → motion-dom/dist/es/animation}/waapi/utils/attach-timeline.mjs +0 -0
- /package/dist/es/{framer-motion → motion-dom}/dist/es/gestures/utils/is-node-or-child.mjs +0 -0
- /package/dist/es/{framer-motion/dist/es/events → motion-dom/dist/es/gestures}/utils/is-primary-pointer.mjs +0 -0
- /package/dist/es/{framer-motion/dist/es/easing → motion-dom/dist/es}/utils/is-bezier-definition.mjs +0 -0
- /package/dist/es/{framer-motion/dist/es/animation/animators/waapi/utils/supports-flags.mjs → motion-dom/dist/es/utils/supports/flags.mjs} +0 -0
- /package/dist/es/{framer-motion/dist/es/utils → motion-utils/dist/es}/errors.mjs +0 -0
package/dist/cjs/react-m.js
CHANGED
|
@@ -5,6 +5,28 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var react = require('react');
|
|
7
7
|
|
|
8
|
+
/*#__NO_SIDE_EFFECTS__*/
|
|
9
|
+
const noop = (any) => any;
|
|
10
|
+
|
|
11
|
+
let warning = noop;
|
|
12
|
+
let invariant = noop;
|
|
13
|
+
if (process.env.NODE_ENV !== "production") {
|
|
14
|
+
warning = (check, message) => {
|
|
15
|
+
if (!check && typeof console !== "undefined") {
|
|
16
|
+
console.warn(message);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
invariant = (check, message) => {
|
|
20
|
+
if (!check) {
|
|
21
|
+
throw new Error(message);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const LayoutGroupContext = react.createContext({});
|
|
27
|
+
|
|
28
|
+
const LazyContext = react.createContext({ strict: false });
|
|
29
|
+
|
|
8
30
|
/**
|
|
9
31
|
* @public
|
|
10
32
|
*/
|
|
@@ -17,15 +39,144 @@ const MotionConfigContext = react.createContext({
|
|
|
17
39
|
const MotionContext = react.createContext({});
|
|
18
40
|
|
|
19
41
|
/**
|
|
20
|
-
*
|
|
42
|
+
* Decides if the supplied variable is variant label
|
|
21
43
|
*/
|
|
22
|
-
|
|
44
|
+
function isVariantLabel(v) {
|
|
45
|
+
return typeof v === "string" || Array.isArray(v);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isAnimationControls(v) {
|
|
49
|
+
return (v !== null &&
|
|
50
|
+
typeof v === "object" &&
|
|
51
|
+
typeof v.start === "function");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const variantPriorityOrder = [
|
|
55
|
+
"animate",
|
|
56
|
+
"whileInView",
|
|
57
|
+
"whileFocus",
|
|
58
|
+
"whileHover",
|
|
59
|
+
"whileTap",
|
|
60
|
+
"whileDrag",
|
|
61
|
+
"exit",
|
|
62
|
+
];
|
|
63
|
+
const variantProps = ["initial", ...variantPriorityOrder];
|
|
64
|
+
|
|
65
|
+
function isControllingVariants(props) {
|
|
66
|
+
return (isAnimationControls(props.animate) ||
|
|
67
|
+
variantProps.some((name) => isVariantLabel(props[name])));
|
|
68
|
+
}
|
|
69
|
+
function isVariantNode(props) {
|
|
70
|
+
return Boolean(isControllingVariants(props) || props.variants);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getCurrentTreeVariants(props, context) {
|
|
74
|
+
if (isControllingVariants(props)) {
|
|
75
|
+
const { initial, animate } = props;
|
|
76
|
+
return {
|
|
77
|
+
initial: initial === false || isVariantLabel(initial)
|
|
78
|
+
? initial
|
|
79
|
+
: undefined,
|
|
80
|
+
animate: isVariantLabel(animate) ? animate : undefined,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return props.inherit !== false ? context : {};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function useCreateMotionContext(props) {
|
|
87
|
+
const { initial, animate } = getCurrentTreeVariants(props, react.useContext(MotionContext));
|
|
88
|
+
return react.useMemo(() => ({ initial, animate }), [variantLabelsAsDependency(initial), variantLabelsAsDependency(animate)]);
|
|
89
|
+
}
|
|
90
|
+
function variantLabelsAsDependency(prop) {
|
|
91
|
+
return Array.isArray(prop) ? prop.join(" ") : prop;
|
|
92
|
+
}
|
|
23
93
|
|
|
24
94
|
const isBrowser = typeof window !== "undefined";
|
|
25
95
|
|
|
26
|
-
const
|
|
96
|
+
const featureProps = {
|
|
97
|
+
animation: [
|
|
98
|
+
"animate",
|
|
99
|
+
"variants",
|
|
100
|
+
"whileHover",
|
|
101
|
+
"whileTap",
|
|
102
|
+
"exit",
|
|
103
|
+
"whileInView",
|
|
104
|
+
"whileFocus",
|
|
105
|
+
"whileDrag",
|
|
106
|
+
],
|
|
107
|
+
exit: ["exit"],
|
|
108
|
+
drag: ["drag", "dragControls"],
|
|
109
|
+
focus: ["whileFocus"],
|
|
110
|
+
hover: ["whileHover", "onHoverStart", "onHoverEnd"],
|
|
111
|
+
tap: ["whileTap", "onTap", "onTapStart", "onTapCancel"],
|
|
112
|
+
pan: ["onPan", "onPanStart", "onPanSessionStart", "onPanEnd"],
|
|
113
|
+
inView: ["whileInView", "onViewportEnter", "onViewportLeave"],
|
|
114
|
+
layout: ["layout", "layoutId"],
|
|
115
|
+
};
|
|
116
|
+
const featureDefinitions = {};
|
|
117
|
+
for (const key in featureProps) {
|
|
118
|
+
featureDefinitions[key] = {
|
|
119
|
+
isEnabled: (props) => featureProps[key].some((name) => !!props[name]),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
27
122
|
|
|
28
|
-
|
|
123
|
+
function loadFeatures(features) {
|
|
124
|
+
for (const key in features) {
|
|
125
|
+
featureDefinitions[key] = {
|
|
126
|
+
...featureDefinitions[key],
|
|
127
|
+
...features[key],
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const motionComponentSymbol = Symbol.for("motionComponentSymbol");
|
|
133
|
+
|
|
134
|
+
function isRefObject(ref) {
|
|
135
|
+
return (ref &&
|
|
136
|
+
typeof ref === "object" &&
|
|
137
|
+
Object.prototype.hasOwnProperty.call(ref, "current"));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Creates a ref function that, when called, hydrates the provided
|
|
142
|
+
* external ref and VisualElement.
|
|
143
|
+
*/
|
|
144
|
+
function useMotionRef(visualState, visualElement, externalRef) {
|
|
145
|
+
return react.useCallback((instance) => {
|
|
146
|
+
if (instance) {
|
|
147
|
+
visualState.onMount && visualState.onMount(instance);
|
|
148
|
+
}
|
|
149
|
+
if (visualElement) {
|
|
150
|
+
if (instance) {
|
|
151
|
+
visualElement.mount(instance);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
visualElement.unmount();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (externalRef) {
|
|
158
|
+
if (typeof externalRef === "function") {
|
|
159
|
+
externalRef(instance);
|
|
160
|
+
}
|
|
161
|
+
else if (isRefObject(externalRef)) {
|
|
162
|
+
externalRef.current = instance;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Only pass a new ref callback to React if we've received a visual element
|
|
168
|
+
* factory. Otherwise we'll be mounting/remounting every time externalRef
|
|
169
|
+
* or other dependencies change.
|
|
170
|
+
*/
|
|
171
|
+
[visualElement]);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
const PresenceContext = react.createContext(null);
|
|
178
|
+
|
|
179
|
+
const useIsomorphicLayoutEffect = isBrowser ? react.useLayoutEffect : react.useEffect;
|
|
29
180
|
|
|
30
181
|
/**
|
|
31
182
|
* Convert camelCase to dash-case properties.
|
|
@@ -100,10 +251,11 @@ function createRenderStep(runNextFrame) {
|
|
|
100
251
|
}
|
|
101
252
|
isProcessing = true;
|
|
102
253
|
[thisFrame, nextFrame] = [nextFrame, thisFrame];
|
|
103
|
-
// Clear the next frame queue
|
|
104
|
-
nextFrame.clear();
|
|
105
254
|
// Execute this frame
|
|
106
255
|
thisFrame.forEach(triggerCallback);
|
|
256
|
+
// Clear the frame so no callbacks remain. This is to avoid
|
|
257
|
+
// memory leaks should this render step not run for a while.
|
|
258
|
+
thisFrame.clear();
|
|
107
259
|
isProcessing = false;
|
|
108
260
|
if (flushNextFrame) {
|
|
109
261
|
flushNextFrame = false;
|
|
@@ -184,12 +336,6 @@ function createRenderBatcher(scheduleNextBatch, allowKeepAlive) {
|
|
|
184
336
|
|
|
185
337
|
const { schedule: microtask, cancel: cancelMicrotask } = createRenderBatcher(queueMicrotask, false);
|
|
186
338
|
|
|
187
|
-
function isRefObject(ref) {
|
|
188
|
-
return (ref &&
|
|
189
|
-
typeof ref === "object" &&
|
|
190
|
-
Object.prototype.hasOwnProperty.call(ref, "current"));
|
|
191
|
-
}
|
|
192
|
-
|
|
193
339
|
/**
|
|
194
340
|
* Internal, exported only for usage in Framer
|
|
195
341
|
*/
|
|
@@ -201,7 +347,7 @@ function useVisualElement(Component, visualState, props, createVisualElement, Pr
|
|
|
201
347
|
const lazyContext = react.useContext(LazyContext);
|
|
202
348
|
const presenceContext = react.useContext(PresenceContext);
|
|
203
349
|
const reducedMotionConfig = react.useContext(MotionConfigContext).reducedMotion;
|
|
204
|
-
const visualElementRef = react.useRef(
|
|
350
|
+
const visualElementRef = react.useRef(null);
|
|
205
351
|
/**
|
|
206
352
|
* If we haven't preloaded a renderer, check to see if we have one lazy-loaded
|
|
207
353
|
*/
|
|
@@ -317,148 +463,6 @@ function getClosestProjectingNode(visualElement) {
|
|
|
317
463
|
: getClosestProjectingNode(visualElement.parent);
|
|
318
464
|
}
|
|
319
465
|
|
|
320
|
-
/**
|
|
321
|
-
* Creates a ref function that, when called, hydrates the provided
|
|
322
|
-
* external ref and VisualElement.
|
|
323
|
-
*/
|
|
324
|
-
function useMotionRef(visualState, visualElement, externalRef) {
|
|
325
|
-
return react.useCallback((instance) => {
|
|
326
|
-
instance && visualState.mount && visualState.mount(instance);
|
|
327
|
-
if (visualElement) {
|
|
328
|
-
if (instance) {
|
|
329
|
-
visualElement.mount(instance);
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
visualElement.unmount();
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
if (externalRef) {
|
|
336
|
-
if (typeof externalRef === "function") {
|
|
337
|
-
externalRef(instance);
|
|
338
|
-
}
|
|
339
|
-
else if (isRefObject(externalRef)) {
|
|
340
|
-
externalRef.current = instance;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
},
|
|
344
|
-
/**
|
|
345
|
-
* Only pass a new ref callback to React if we've received a visual element
|
|
346
|
-
* factory. Otherwise we'll be mounting/remounting every time externalRef
|
|
347
|
-
* or other dependencies change.
|
|
348
|
-
*/
|
|
349
|
-
[visualElement]);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Decides if the supplied variable is variant label
|
|
354
|
-
*/
|
|
355
|
-
function isVariantLabel(v) {
|
|
356
|
-
return typeof v === "string" || Array.isArray(v);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
function isAnimationControls(v) {
|
|
360
|
-
return (v !== null &&
|
|
361
|
-
typeof v === "object" &&
|
|
362
|
-
typeof v.start === "function");
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
const variantPriorityOrder = [
|
|
366
|
-
"animate",
|
|
367
|
-
"whileInView",
|
|
368
|
-
"whileFocus",
|
|
369
|
-
"whileHover",
|
|
370
|
-
"whileTap",
|
|
371
|
-
"whileDrag",
|
|
372
|
-
"exit",
|
|
373
|
-
];
|
|
374
|
-
const variantProps = ["initial", ...variantPriorityOrder];
|
|
375
|
-
|
|
376
|
-
function isControllingVariants(props) {
|
|
377
|
-
return (isAnimationControls(props.animate) ||
|
|
378
|
-
variantProps.some((name) => isVariantLabel(props[name])));
|
|
379
|
-
}
|
|
380
|
-
function isVariantNode(props) {
|
|
381
|
-
return Boolean(isControllingVariants(props) || props.variants);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
function getCurrentTreeVariants(props, context) {
|
|
385
|
-
if (isControllingVariants(props)) {
|
|
386
|
-
const { initial, animate } = props;
|
|
387
|
-
return {
|
|
388
|
-
initial: initial === false || isVariantLabel(initial)
|
|
389
|
-
? initial
|
|
390
|
-
: undefined,
|
|
391
|
-
animate: isVariantLabel(animate) ? animate : undefined,
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
return props.inherit !== false ? context : {};
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
function useCreateMotionContext(props) {
|
|
398
|
-
const { initial, animate } = getCurrentTreeVariants(props, react.useContext(MotionContext));
|
|
399
|
-
return react.useMemo(() => ({ initial, animate }), [variantLabelsAsDependency(initial), variantLabelsAsDependency(animate)]);
|
|
400
|
-
}
|
|
401
|
-
function variantLabelsAsDependency(prop) {
|
|
402
|
-
return Array.isArray(prop) ? prop.join(" ") : prop;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
const featureProps = {
|
|
406
|
-
animation: [
|
|
407
|
-
"animate",
|
|
408
|
-
"variants",
|
|
409
|
-
"whileHover",
|
|
410
|
-
"whileTap",
|
|
411
|
-
"exit",
|
|
412
|
-
"whileInView",
|
|
413
|
-
"whileFocus",
|
|
414
|
-
"whileDrag",
|
|
415
|
-
],
|
|
416
|
-
exit: ["exit"],
|
|
417
|
-
drag: ["drag", "dragControls"],
|
|
418
|
-
focus: ["whileFocus"],
|
|
419
|
-
hover: ["whileHover", "onHoverStart", "onHoverEnd"],
|
|
420
|
-
tap: ["whileTap", "onTap", "onTapStart", "onTapCancel"],
|
|
421
|
-
pan: ["onPan", "onPanStart", "onPanSessionStart", "onPanEnd"],
|
|
422
|
-
inView: ["whileInView", "onViewportEnter", "onViewportLeave"],
|
|
423
|
-
layout: ["layout", "layoutId"],
|
|
424
|
-
};
|
|
425
|
-
const featureDefinitions = {};
|
|
426
|
-
for (const key in featureProps) {
|
|
427
|
-
featureDefinitions[key] = {
|
|
428
|
-
isEnabled: (props) => featureProps[key].some((name) => !!props[name]),
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
function loadFeatures(features) {
|
|
433
|
-
for (const key in features) {
|
|
434
|
-
featureDefinitions[key] = {
|
|
435
|
-
...featureDefinitions[key],
|
|
436
|
-
...features[key],
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
const LayoutGroupContext = react.createContext({});
|
|
442
|
-
|
|
443
|
-
const motionComponentSymbol = Symbol.for("motionComponentSymbol");
|
|
444
|
-
|
|
445
|
-
const noop = (any) => any;
|
|
446
|
-
|
|
447
|
-
let warning = noop;
|
|
448
|
-
let invariant = noop;
|
|
449
|
-
if (process.env.NODE_ENV !== "production") {
|
|
450
|
-
warning = (check, message) => {
|
|
451
|
-
if (!check && typeof console !== "undefined") {
|
|
452
|
-
console.warn(message);
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
invariant = (check, message) => {
|
|
456
|
-
if (!check) {
|
|
457
|
-
throw new Error(message);
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
|
|
462
466
|
/**
|
|
463
467
|
* Create a `motion` component.
|
|
464
468
|
*
|
|
@@ -469,6 +473,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
469
473
|
* component "offline", or outside the React render cycle.
|
|
470
474
|
*/
|
|
471
475
|
function createRendererMotionComponent({ preloadedFeatures, createVisualElement, useRender, useVisualState, Component, }) {
|
|
476
|
+
var _a, _b;
|
|
472
477
|
preloadedFeatures && loadFeatures(preloadedFeatures);
|
|
473
478
|
function MotionComponent(props, externalRef) {
|
|
474
479
|
/**
|
|
@@ -502,6 +507,9 @@ function createRendererMotionComponent({ preloadedFeatures, createVisualElement,
|
|
|
502
507
|
*/
|
|
503
508
|
return (jsxRuntime.jsxs(MotionContext.Provider, { value: context, children: [MeasureLayout && context.visualElement ? (jsxRuntime.jsx(MeasureLayout, { visualElement: context.visualElement, ...configAndProps })) : null, useRender(Component, props, useMotionRef(visualState, context.visualElement, externalRef), visualState, isStatic, context.visualElement)] }));
|
|
504
509
|
}
|
|
510
|
+
MotionComponent.displayName = `motion.${typeof Component === "string"
|
|
511
|
+
? Component
|
|
512
|
+
: `create(${(_b = (_a = Component.displayName) !== null && _a !== void 0 ? _a : Component.name) !== null && _b !== void 0 ? _b : ""})`}`;
|
|
505
513
|
const ForwardRefMotionComponent = react.forwardRef(MotionComponent);
|
|
506
514
|
ForwardRefMotionComponent[motionComponentSymbol] = Component;
|
|
507
515
|
return ForwardRefMotionComponent;
|
|
@@ -562,155 +570,45 @@ const lowercaseSVGElements = [
|
|
|
562
570
|
"polygon",
|
|
563
571
|
"polyline",
|
|
564
572
|
"rect",
|
|
565
|
-
"stop",
|
|
566
|
-
"switch",
|
|
567
|
-
"symbol",
|
|
568
|
-
"svg",
|
|
569
|
-
"text",
|
|
570
|
-
"tspan",
|
|
571
|
-
"use",
|
|
572
|
-
"view",
|
|
573
|
-
];
|
|
574
|
-
|
|
575
|
-
function isSVGComponent(Component) {
|
|
576
|
-
if (
|
|
577
|
-
/**
|
|
578
|
-
* If it's not a string, it's a custom React component. Currently we only support
|
|
579
|
-
* HTML custom React components.
|
|
580
|
-
*/
|
|
581
|
-
typeof Component !== "string" ||
|
|
582
|
-
/**
|
|
583
|
-
* If it contains a dash, the element is a custom HTML webcomponent.
|
|
584
|
-
*/
|
|
585
|
-
Component.includes("-")) {
|
|
586
|
-
return false;
|
|
587
|
-
}
|
|
588
|
-
else if (
|
|
589
|
-
/**
|
|
590
|
-
* If it's in our list of lowercase SVG tags, it's an SVG component
|
|
591
|
-
*/
|
|
592
|
-
lowercaseSVGElements.indexOf(Component) > -1 ||
|
|
593
|
-
/**
|
|
594
|
-
* If it contains a capital letter, it's an SVG component
|
|
595
|
-
*/
|
|
596
|
-
/[A-Z]/u.test(Component)) {
|
|
597
|
-
return true;
|
|
598
|
-
}
|
|
599
|
-
return false;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
603
|
-
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
604
|
-
// Loop over any CSS variables and assign those.
|
|
605
|
-
for (const key in vars) {
|
|
606
|
-
element.style.setProperty(key, vars[key]);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
/**
|
|
611
|
-
* A set of attribute names that are always read/written as camel case.
|
|
612
|
-
*/
|
|
613
|
-
const camelCaseAttributes = new Set([
|
|
614
|
-
"baseFrequency",
|
|
615
|
-
"diffuseConstant",
|
|
616
|
-
"kernelMatrix",
|
|
617
|
-
"kernelUnitLength",
|
|
618
|
-
"keySplines",
|
|
619
|
-
"keyTimes",
|
|
620
|
-
"limitingConeAngle",
|
|
621
|
-
"markerHeight",
|
|
622
|
-
"markerWidth",
|
|
623
|
-
"numOctaves",
|
|
624
|
-
"targetX",
|
|
625
|
-
"targetY",
|
|
626
|
-
"surfaceScale",
|
|
627
|
-
"specularConstant",
|
|
628
|
-
"specularExponent",
|
|
629
|
-
"stdDeviation",
|
|
630
|
-
"tableValues",
|
|
631
|
-
"viewBox",
|
|
632
|
-
"gradientTransform",
|
|
633
|
-
"pathLength",
|
|
634
|
-
"startOffset",
|
|
635
|
-
"textLength",
|
|
636
|
-
"lengthAdjust",
|
|
637
|
-
]);
|
|
638
|
-
|
|
639
|
-
function renderSVG(element, renderState, _styleProp, projection) {
|
|
640
|
-
renderHTML(element, renderState, undefined, projection);
|
|
641
|
-
for (const key in renderState.attrs) {
|
|
642
|
-
element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
const isMotionValue = (value) => Boolean(value && value.getVelocity);
|
|
647
|
-
|
|
648
|
-
const scaleCorrectors = {};
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* Generate a list of every possible transform key.
|
|
652
|
-
*/
|
|
653
|
-
const transformPropOrder = [
|
|
654
|
-
"transformPerspective",
|
|
655
|
-
"x",
|
|
656
|
-
"y",
|
|
657
|
-
"z",
|
|
658
|
-
"translateX",
|
|
659
|
-
"translateY",
|
|
660
|
-
"translateZ",
|
|
661
|
-
"scale",
|
|
662
|
-
"scaleX",
|
|
663
|
-
"scaleY",
|
|
664
|
-
"rotate",
|
|
665
|
-
"rotateX",
|
|
666
|
-
"rotateY",
|
|
667
|
-
"rotateZ",
|
|
668
|
-
"skew",
|
|
669
|
-
"skewX",
|
|
670
|
-
"skewY",
|
|
573
|
+
"stop",
|
|
574
|
+
"switch",
|
|
575
|
+
"symbol",
|
|
576
|
+
"svg",
|
|
577
|
+
"text",
|
|
578
|
+
"tspan",
|
|
579
|
+
"use",
|
|
580
|
+
"view",
|
|
671
581
|
];
|
|
672
|
-
/**
|
|
673
|
-
* A quick lookup for transform props.
|
|
674
|
-
*/
|
|
675
|
-
const transformProps = new Set(transformPropOrder);
|
|
676
|
-
|
|
677
|
-
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
678
|
-
return (transformProps.has(key) ||
|
|
679
|
-
key.startsWith("origin") ||
|
|
680
|
-
((layout || layoutId !== undefined) &&
|
|
681
|
-
(!!scaleCorrectors[key] || key === "opacity")));
|
|
682
|
-
}
|
|
683
582
|
|
|
684
|
-
function
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
583
|
+
function isSVGComponent(Component) {
|
|
584
|
+
if (
|
|
585
|
+
/**
|
|
586
|
+
* If it's not a string, it's a custom React component. Currently we only support
|
|
587
|
+
* HTML custom React components.
|
|
588
|
+
*/
|
|
589
|
+
typeof Component !== "string" ||
|
|
590
|
+
/**
|
|
591
|
+
* If it contains a dash, the element is a custom HTML webcomponent.
|
|
592
|
+
*/
|
|
593
|
+
Component.includes("-")) {
|
|
594
|
+
return false;
|
|
696
595
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
: key;
|
|
708
|
-
newValues[targetKey] = props[key];
|
|
709
|
-
}
|
|
596
|
+
else if (
|
|
597
|
+
/**
|
|
598
|
+
* If it's in our list of lowercase SVG tags, it's an SVG component
|
|
599
|
+
*/
|
|
600
|
+
lowercaseSVGElements.indexOf(Component) > -1 ||
|
|
601
|
+
/**
|
|
602
|
+
* If it contains a capital letter, it's an SVG component
|
|
603
|
+
*/
|
|
604
|
+
/[A-Z]/u.test(Component)) {
|
|
605
|
+
return true;
|
|
710
606
|
}
|
|
711
|
-
return
|
|
607
|
+
return false;
|
|
712
608
|
}
|
|
713
609
|
|
|
610
|
+
const { schedule: frame, cancel: cancelFrame, state: frameData, steps: frameSteps, } = createRenderBatcher(typeof requestAnimationFrame !== "undefined" ? requestAnimationFrame : noop, true);
|
|
611
|
+
|
|
714
612
|
function getValueState(visualElement) {
|
|
715
613
|
const state = [{}, {}];
|
|
716
614
|
visualElement === null || visualElement === void 0 ? void 0 : visualElement.values.forEach((value, key) => {
|
|
@@ -765,6 +663,8 @@ const isCustomValue = (v) => {
|
|
|
765
663
|
return Boolean(v && typeof v === "object" && v.mix && v.toValue);
|
|
766
664
|
};
|
|
767
665
|
|
|
666
|
+
const isMotionValue = (value) => Boolean(value && value.getVelocity);
|
|
667
|
+
|
|
768
668
|
/**
|
|
769
669
|
* If the provided value is a MotionValue, this returns the actual value, otherwise just the value itself
|
|
770
670
|
*
|
|
@@ -777,13 +677,19 @@ function resolveMotionValue(value) {
|
|
|
777
677
|
: unwrappedValue;
|
|
778
678
|
}
|
|
779
679
|
|
|
780
|
-
function makeState({ scrapeMotionValuesFromProps, createRenderState,
|
|
680
|
+
function makeState({ scrapeMotionValuesFromProps, createRenderState, onUpdate, }, props, context, presenceContext) {
|
|
781
681
|
const state = {
|
|
782
682
|
latestValues: makeLatestValues(props, context, presenceContext, scrapeMotionValuesFromProps),
|
|
783
683
|
renderState: createRenderState(),
|
|
784
684
|
};
|
|
785
|
-
if (
|
|
786
|
-
|
|
685
|
+
if (onUpdate) {
|
|
686
|
+
/**
|
|
687
|
+
* onMount works without the VisualElement because it could be
|
|
688
|
+
* called before the VisualElement payload has been hydrated.
|
|
689
|
+
* (e.g. if someone is using m components <m.circle />)
|
|
690
|
+
*/
|
|
691
|
+
state.onMount = (instance) => onUpdate({ props, current: instance, ...state });
|
|
692
|
+
state.onUpdate = (visualElement) => onUpdate(visualElement);
|
|
787
693
|
}
|
|
788
694
|
return state;
|
|
789
695
|
}
|
|
@@ -849,17 +755,36 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
|
849
755
|
return values;
|
|
850
756
|
}
|
|
851
757
|
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
758
|
+
/**
|
|
759
|
+
* Generate a list of every possible transform key.
|
|
760
|
+
*/
|
|
761
|
+
const transformPropOrder = [
|
|
762
|
+
"transformPerspective",
|
|
763
|
+
"x",
|
|
764
|
+
"y",
|
|
765
|
+
"z",
|
|
766
|
+
"translateX",
|
|
767
|
+
"translateY",
|
|
768
|
+
"translateZ",
|
|
769
|
+
"scale",
|
|
770
|
+
"scaleX",
|
|
771
|
+
"scaleY",
|
|
772
|
+
"rotate",
|
|
773
|
+
"rotateX",
|
|
774
|
+
"rotateY",
|
|
775
|
+
"rotateZ",
|
|
776
|
+
"skew",
|
|
777
|
+
"skewX",
|
|
778
|
+
"skewY",
|
|
779
|
+
];
|
|
780
|
+
/**
|
|
781
|
+
* A quick lookup for transform props.
|
|
782
|
+
*/
|
|
783
|
+
const transformProps = new Set(transformPropOrder);
|
|
858
784
|
|
|
859
|
-
const
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
});
|
|
785
|
+
const checkStringStartsWith = (token) => (key) => typeof key === "string" && key.startsWith(token);
|
|
786
|
+
const isCSSVariableName =
|
|
787
|
+
/*@__PURE__*/ checkStringStartsWith("--");
|
|
863
788
|
|
|
864
789
|
/**
|
|
865
790
|
* Provided a value and a ValueType, returns the value as that value type.
|
|
@@ -1044,10 +969,6 @@ function buildTransform(latestValues, transform, transformTemplate) {
|
|
|
1044
969
|
return transformString;
|
|
1045
970
|
}
|
|
1046
971
|
|
|
1047
|
-
const checkStringStartsWith = (token) => (key) => typeof key === "string" && key.startsWith(token);
|
|
1048
|
-
const isCSSVariableName =
|
|
1049
|
-
/*@__PURE__*/ checkStringStartsWith("--");
|
|
1050
|
-
|
|
1051
972
|
function buildHTMLStyles(state, latestValues, transformTemplate) {
|
|
1052
973
|
const { style, vars, transformOrigin } = state;
|
|
1053
974
|
// Track whether we encounter any transform or transformOrigin values.
|
|
@@ -1106,21 +1027,6 @@ function buildHTMLStyles(state, latestValues, transformTemplate) {
|
|
|
1106
1027
|
}
|
|
1107
1028
|
}
|
|
1108
1029
|
|
|
1109
|
-
function calcOrigin(origin, offset, size) {
|
|
1110
|
-
return typeof origin === "string"
|
|
1111
|
-
? origin
|
|
1112
|
-
: px.transform(offset + size * origin);
|
|
1113
|
-
}
|
|
1114
|
-
/**
|
|
1115
|
-
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
1116
|
-
* so we use the measured dimensions of the SVG to reconcile these.
|
|
1117
|
-
*/
|
|
1118
|
-
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
1119
|
-
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
1120
|
-
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
1121
|
-
return `${pxOriginX} ${pxOriginY}`;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
1030
|
const dashKeys = {
|
|
1125
1031
|
offset: "stroke-dashoffset",
|
|
1126
1032
|
array: "stroke-dasharray",
|
|
@@ -1150,6 +1056,21 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
1150
1056
|
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
1151
1057
|
}
|
|
1152
1058
|
|
|
1059
|
+
function calcOrigin(origin, offset, size) {
|
|
1060
|
+
return typeof origin === "string"
|
|
1061
|
+
? origin
|
|
1062
|
+
: px.transform(offset + size * origin);
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* The SVG transform origin defaults are different to CSS and is less intuitive,
|
|
1066
|
+
* so we use the measured dimensions of the SVG to reconcile these.
|
|
1067
|
+
*/
|
|
1068
|
+
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
1069
|
+
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
1070
|
+
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
1071
|
+
return `${pxOriginX} ${pxOriginY}`;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1153
1074
|
/**
|
|
1154
1075
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
1155
1076
|
*/
|
|
@@ -1197,36 +1118,161 @@ function buildSVGAttrs(state, { attrX, attrY, attrScale, originX, originY, pathL
|
|
|
1197
1118
|
}
|
|
1198
1119
|
}
|
|
1199
1120
|
|
|
1121
|
+
const createHtmlRenderState = () => ({
|
|
1122
|
+
style: {},
|
|
1123
|
+
transform: {},
|
|
1124
|
+
transformOrigin: {},
|
|
1125
|
+
vars: {},
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
const createSvgRenderState = () => ({
|
|
1129
|
+
...createHtmlRenderState(),
|
|
1130
|
+
attrs: {},
|
|
1131
|
+
});
|
|
1132
|
+
|
|
1200
1133
|
const isSVGTag = (tag) => typeof tag === "string" && tag.toLowerCase() === "svg";
|
|
1201
1134
|
|
|
1202
|
-
|
|
1135
|
+
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
1136
|
+
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
1137
|
+
// Loop over any CSS variables and assign those.
|
|
1138
|
+
for (const key in vars) {
|
|
1139
|
+
element.style.setProperty(key, vars[key]);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
/**
|
|
1144
|
+
* A set of attribute names that are always read/written as camel case.
|
|
1145
|
+
*/
|
|
1146
|
+
const camelCaseAttributes = new Set([
|
|
1147
|
+
"baseFrequency",
|
|
1148
|
+
"diffuseConstant",
|
|
1149
|
+
"kernelMatrix",
|
|
1150
|
+
"kernelUnitLength",
|
|
1151
|
+
"keySplines",
|
|
1152
|
+
"keyTimes",
|
|
1153
|
+
"limitingConeAngle",
|
|
1154
|
+
"markerHeight",
|
|
1155
|
+
"markerWidth",
|
|
1156
|
+
"numOctaves",
|
|
1157
|
+
"targetX",
|
|
1158
|
+
"targetY",
|
|
1159
|
+
"surfaceScale",
|
|
1160
|
+
"specularConstant",
|
|
1161
|
+
"specularExponent",
|
|
1162
|
+
"stdDeviation",
|
|
1163
|
+
"tableValues",
|
|
1164
|
+
"viewBox",
|
|
1165
|
+
"gradientTransform",
|
|
1166
|
+
"pathLength",
|
|
1167
|
+
"startOffset",
|
|
1168
|
+
"textLength",
|
|
1169
|
+
"lengthAdjust",
|
|
1170
|
+
]);
|
|
1171
|
+
|
|
1172
|
+
function renderSVG(element, renderState, _styleProp, projection) {
|
|
1173
|
+
renderHTML(element, renderState, undefined, projection);
|
|
1174
|
+
for (const key in renderState.attrs) {
|
|
1175
|
+
element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
const scaleCorrectors = {};
|
|
1180
|
+
|
|
1181
|
+
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
1182
|
+
return (transformProps.has(key) ||
|
|
1183
|
+
key.startsWith("origin") ||
|
|
1184
|
+
((layout || layoutId !== undefined) &&
|
|
1185
|
+
(!!scaleCorrectors[key] || key === "opacity")));
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
function scrapeMotionValuesFromProps$1(props, prevProps, visualElement) {
|
|
1189
|
+
var _a;
|
|
1190
|
+
const { style } = props;
|
|
1191
|
+
const newValues = {};
|
|
1192
|
+
for (const key in style) {
|
|
1193
|
+
if (isMotionValue(style[key]) ||
|
|
1194
|
+
(prevProps.style &&
|
|
1195
|
+
isMotionValue(prevProps.style[key])) ||
|
|
1196
|
+
isForcedMotionValue(key, props) ||
|
|
1197
|
+
((_a = visualElement === null || visualElement === void 0 ? void 0 : visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.liveStyle) !== undefined) {
|
|
1198
|
+
newValues[key] = style[key];
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
return newValues;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
function scrapeMotionValuesFromProps(props, prevProps, visualElement) {
|
|
1205
|
+
const newValues = scrapeMotionValuesFromProps$1(props, prevProps, visualElement);
|
|
1206
|
+
for (const key in props) {
|
|
1207
|
+
if (isMotionValue(props[key]) ||
|
|
1208
|
+
isMotionValue(prevProps[key])) {
|
|
1209
|
+
const targetKey = transformPropOrder.indexOf(key) !== -1
|
|
1210
|
+
? "attr" + key.charAt(0).toUpperCase() + key.substring(1)
|
|
1211
|
+
: key;
|
|
1212
|
+
newValues[targetKey] = props[key];
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return newValues;
|
|
1216
|
+
}
|
|
1203
1217
|
|
|
1218
|
+
function updateSVGDimensions(instance, renderState) {
|
|
1219
|
+
try {
|
|
1220
|
+
renderState.dimensions =
|
|
1221
|
+
typeof instance.getBBox === "function"
|
|
1222
|
+
? instance.getBBox()
|
|
1223
|
+
: instance.getBoundingClientRect();
|
|
1224
|
+
}
|
|
1225
|
+
catch (e) {
|
|
1226
|
+
// Most likely trying to measure an unrendered element under Firefox
|
|
1227
|
+
renderState.dimensions = {
|
|
1228
|
+
x: 0,
|
|
1229
|
+
y: 0,
|
|
1230
|
+
width: 0,
|
|
1231
|
+
height: 0,
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
const layoutProps = ["x", "y", "width", "height", "cx", "cy", "r"];
|
|
1204
1236
|
const svgMotionConfig = {
|
|
1205
1237
|
useVisualState: makeUseVisualState({
|
|
1206
1238
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
1207
1239
|
createRenderState: createSvgRenderState,
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1240
|
+
onUpdate: ({ props, prevProps, current, renderState, latestValues, }) => {
|
|
1241
|
+
if (!current)
|
|
1242
|
+
return;
|
|
1243
|
+
let hasTransform = !!props.drag;
|
|
1244
|
+
if (!hasTransform) {
|
|
1245
|
+
for (const key in latestValues) {
|
|
1246
|
+
if (transformProps.has(key)) {
|
|
1247
|
+
hasTransform = true;
|
|
1248
|
+
break;
|
|
1249
|
+
}
|
|
1216
1250
|
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1251
|
+
}
|
|
1252
|
+
if (!hasTransform)
|
|
1253
|
+
return;
|
|
1254
|
+
let needsMeasure = !prevProps;
|
|
1255
|
+
if (prevProps) {
|
|
1256
|
+
/**
|
|
1257
|
+
* Check the layout props for changes, if any are found we need to
|
|
1258
|
+
* measure the element again.
|
|
1259
|
+
*/
|
|
1260
|
+
for (let i = 0; i < layoutProps.length; i++) {
|
|
1261
|
+
const key = layoutProps[i];
|
|
1262
|
+
if (props[key] !==
|
|
1263
|
+
prevProps[key]) {
|
|
1264
|
+
needsMeasure = true;
|
|
1265
|
+
}
|
|
1225
1266
|
}
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1267
|
+
}
|
|
1268
|
+
if (!needsMeasure)
|
|
1269
|
+
return;
|
|
1270
|
+
frame.read(() => {
|
|
1271
|
+
updateSVGDimensions(current, renderState);
|
|
1272
|
+
frame.render(() => {
|
|
1273
|
+
buildSVGAttrs(renderState, latestValues, isSVGTag(current.tagName), props.transformTemplate);
|
|
1274
|
+
renderSVG(current, renderState);
|
|
1275
|
+
});
|
|
1230
1276
|
});
|
|
1231
1277
|
},
|
|
1232
1278
|
}),
|