framer-motion 7.2.0 → 7.2.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/dist/cjs/index.js +728 -624
- package/dist/es/animation/use-animated-state.mjs +3 -5
- package/dist/es/animation/utils/default-transitions.mjs +1 -1
- package/dist/es/animation/utils/transitions.mjs +28 -26
- package/dist/es/components/AnimatePresence/PopChild.mjs +3 -2
- package/dist/es/components/AnimatePresence/PresenceChild.mjs +5 -2
- package/dist/es/components/AnimatePresence/use-presence.mjs +1 -1
- package/dist/es/components/LayoutGroup/index.mjs +4 -5
- package/dist/es/components/LazyMotion/index.mjs +3 -5
- package/dist/es/components/MotionConfig/index.mjs +2 -4
- package/dist/es/components/Reorder/Group.mjs +2 -4
- package/dist/es/components/Reorder/Item.mjs +6 -8
- package/dist/es/context/MotionContext/utils.mjs +3 -2
- package/dist/es/gestures/PanSession.mjs +2 -2
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +16 -4
- package/dist/es/gestures/use-focus-gesture.mjs +3 -4
- package/dist/es/gestures/use-hover-gesture.mjs +4 -3
- package/dist/es/gestures/use-tap-gesture.mjs +9 -10
- package/dist/es/index.mjs +2 -1
- package/dist/es/motion/features/animations.mjs +8 -3
- package/dist/es/motion/features/definitions.mjs +1 -13
- package/dist/es/motion/features/layout/MeasureLayout.mjs +12 -6
- package/dist/es/motion/features/load-features.mjs +14 -0
- package/dist/es/motion/features/viewport/observers.mjs +4 -7
- package/dist/es/motion/features/viewport/use-viewport.mjs +8 -6
- package/dist/es/motion/index.mjs +23 -23
- package/dist/es/motion/utils/VisualElementHandler.mjs +2 -5
- package/dist/es/motion/utils/is-forced-motion-value.mjs +3 -3
- package/dist/es/motion/utils/use-motion-ref.mjs +1 -2
- package/dist/es/motion/utils/use-visual-element.mjs +14 -12
- package/dist/es/motion/utils/use-visual-state.mjs +19 -16
- package/dist/es/motion/utils/valid-prop.mjs +22 -17
- package/dist/es/projection/node/HTMLProjectionNode.mjs +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +34 -16
- package/dist/es/projection/use-instant-layout-transition.mjs +2 -2
- package/dist/es/render/dom/features-animation.mjs +5 -1
- package/dist/es/render/dom/features-max.mjs +6 -1
- package/dist/es/render/dom/motion.mjs +6 -1
- package/dist/es/render/dom/use-render.mjs +5 -1
- package/dist/es/render/dom/utils/camel-to-dash.mjs +1 -3
- package/dist/es/render/dom/utils/create-config.mjs +7 -2
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +5 -7
- package/dist/es/render/dom/utils/unit-conversion.mjs +4 -4
- package/dist/es/render/dom/value-types/defaults.mjs +15 -3
- package/dist/es/render/dom/value-types/type-int.mjs +4 -1
- package/dist/es/render/html/config-motion.mjs +1 -1
- package/dist/es/render/html/use-props.mjs +5 -9
- package/dist/es/render/html/utils/build-styles.mjs +17 -15
- package/dist/es/render/html/utils/build-transform.mjs +8 -18
- package/dist/es/render/html/utils/transform.mjs +20 -30
- package/dist/es/render/html/visual-element.mjs +8 -9
- package/dist/es/render/index.mjs +118 -40
- package/dist/es/render/svg/use-props.mjs +5 -2
- package/dist/es/render/svg/utils/build-attrs.mjs +3 -5
- package/dist/es/render/svg/utils/create-render-state.mjs +4 -1
- package/dist/es/render/svg/visual-element.mjs +8 -4
- package/dist/es/render/utils/animation-state.mjs +12 -9
- package/dist/es/render/utils/animation.mjs +14 -8
- package/dist/es/render/utils/is-controlling-variants.mjs +22 -0
- package/dist/es/render/utils/is-variant-label.mjs +8 -0
- package/dist/es/render/utils/motion-values.mjs +3 -3
- package/dist/es/render/utils/resolve-dynamic-variants.mjs +24 -0
- package/dist/es/render/utils/resolve-variants.mjs +26 -0
- package/dist/es/render/utils/setters.mjs +12 -9
- package/dist/es/utils/reduced-motion/index.mjs +19 -0
- package/dist/es/utils/reduced-motion/state.mjs +5 -0
- package/dist/es/utils/reduced-motion/use-reduced-motion-config.mjs +19 -0
- package/dist/es/utils/reduced-motion/use-reduced-motion.mjs +43 -0
- package/dist/es/utils/transform.mjs +4 -1
- package/dist/es/utils/use-in-view.mjs +1 -2
- package/dist/es/value/index.mjs +1 -1
- package/dist/es/value/use-scroll.mjs +6 -4
- package/dist/es/value/use-spring.mjs +7 -1
- package/dist/es/value/use-will-change/index.mjs +4 -4
- package/dist/es/value/utils/is-motion-value.mjs +1 -3
- package/dist/framer-motion.dev.js +769 -664
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +55 -52
- package/dist/projection.dev.js +368 -210
- package/dist/size-rollup-dom-animation-assets.js +1 -0
- package/dist/size-rollup-dom-animation-m.js +1 -0
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max-assets.js +1 -0
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/dist/size-rollup-motion.js +1 -0
- package/dist/size-webpack-dom-animation.js +1 -1
- package/dist/size-webpack-dom-max.js +1 -1
- package/dist/size-webpack-m.js +1 -1
- package/dist/three-entry.d.ts +36 -20
- package/package.json +12 -8
- package/dist/es/motion/features/use-features.mjs +0 -40
- package/dist/es/motion/features/use-projection.mjs +0 -33
- package/dist/es/render/utils/variants.mjs +0 -73
- package/dist/es/utils/use-reduced-motion.mjs +0 -73
|
@@ -24,110 +24,8 @@
|
|
|
24
24
|
return Object.freeze(n);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
28
27
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Browser-safe usage of process
|
|
32
|
-
*/
|
|
33
|
-
const defaultEnvironment = "production";
|
|
34
|
-
const env = typeof process === "undefined" || process.env === undefined
|
|
35
|
-
? defaultEnvironment
|
|
36
|
-
: "development" ;
|
|
37
|
-
|
|
38
|
-
const createDefinition = (propNames) => ({
|
|
39
|
-
isEnabled: (props) => propNames.some((name) => !!props[name]),
|
|
40
|
-
});
|
|
41
|
-
const featureDefinitions = {
|
|
42
|
-
measureLayout: createDefinition(["layout", "layoutId", "drag"]),
|
|
43
|
-
animation: createDefinition([
|
|
44
|
-
"animate",
|
|
45
|
-
"exit",
|
|
46
|
-
"variants",
|
|
47
|
-
"whileHover",
|
|
48
|
-
"whileTap",
|
|
49
|
-
"whileFocus",
|
|
50
|
-
"whileDrag",
|
|
51
|
-
"whileInView",
|
|
52
|
-
]),
|
|
53
|
-
exit: createDefinition(["exit"]),
|
|
54
|
-
drag: createDefinition(["drag", "dragControls"]),
|
|
55
|
-
focus: createDefinition(["whileFocus"]),
|
|
56
|
-
hover: createDefinition(["whileHover", "onHoverStart", "onHoverEnd"]),
|
|
57
|
-
tap: createDefinition(["whileTap", "onTap", "onTapStart", "onTapCancel"]),
|
|
58
|
-
pan: createDefinition([
|
|
59
|
-
"onPan",
|
|
60
|
-
"onPanStart",
|
|
61
|
-
"onPanSessionStart",
|
|
62
|
-
"onPanEnd",
|
|
63
|
-
]),
|
|
64
|
-
inView: createDefinition([
|
|
65
|
-
"whileInView",
|
|
66
|
-
"onViewportEnter",
|
|
67
|
-
"onViewportLeave",
|
|
68
|
-
]),
|
|
69
|
-
};
|
|
70
|
-
function loadFeatures(features) {
|
|
71
|
-
for (const key in features) {
|
|
72
|
-
if (features[key] === null)
|
|
73
|
-
continue;
|
|
74
|
-
if (key === "projectionNodeConstructor") {
|
|
75
|
-
featureDefinitions.projectionNodeConstructor = features[key];
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
featureDefinitions[key].Component = features[key];
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
var warning = function () { };
|
|
84
|
-
var invariant = function () { };
|
|
85
|
-
{
|
|
86
|
-
warning = function (check, message) {
|
|
87
|
-
if (!check && typeof console !== 'undefined') {
|
|
88
|
-
console.warn(message);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
invariant = function (check, message) {
|
|
92
|
-
if (!check) {
|
|
93
|
-
throw new Error(message);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const LazyContext = React.createContext({ strict: false });
|
|
99
|
-
|
|
100
|
-
const featureNames = Object.keys(featureDefinitions);
|
|
101
|
-
const numFeatures = featureNames.length;
|
|
102
|
-
/**
|
|
103
|
-
* Load features via renderless components based on the provided MotionProps.
|
|
104
|
-
*/
|
|
105
|
-
function useFeatures(props, visualElement, preloadedFeatures) {
|
|
106
|
-
const features = [];
|
|
107
|
-
const lazyContext = React.useContext(LazyContext);
|
|
108
|
-
if (!visualElement)
|
|
109
|
-
return null;
|
|
110
|
-
/**
|
|
111
|
-
* If we're in development mode, check to make sure we're not rendering a motion component
|
|
112
|
-
* as a child of LazyMotion, as this will break the file-size benefits of using it.
|
|
113
|
-
*/
|
|
114
|
-
if (env !== "production" && preloadedFeatures && lazyContext.strict) {
|
|
115
|
-
invariant(false, "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.");
|
|
116
|
-
}
|
|
117
|
-
for (let i = 0; i < numFeatures; i++) {
|
|
118
|
-
const name = featureNames[i];
|
|
119
|
-
const { isEnabled, Component } = featureDefinitions[name];
|
|
120
|
-
/**
|
|
121
|
-
* It might be possible in the future to use this moment to
|
|
122
|
-
* dynamically request functionality. In initial tests this
|
|
123
|
-
* was producing a lot of duplication amongst bundles.
|
|
124
|
-
*/
|
|
125
|
-
if (isEnabled(props) && Component) {
|
|
126
|
-
features.push(React__namespace.createElement(Component, Object.assign({ key: name }, props, { visualElement: visualElement })));
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return features;
|
|
130
|
-
}
|
|
28
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
131
29
|
|
|
132
30
|
/**
|
|
133
31
|
* @public
|
|
@@ -152,104 +50,40 @@
|
|
|
152
50
|
|
|
153
51
|
const useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : React.useEffect;
|
|
154
52
|
|
|
155
|
-
|
|
156
|
-
const prefersReducedMotion = { current: null };
|
|
157
|
-
let hasDetected = false;
|
|
158
|
-
function initPrefersReducedMotion() {
|
|
159
|
-
hasDetected = true;
|
|
160
|
-
if (!isBrowser)
|
|
161
|
-
return;
|
|
162
|
-
if (window.matchMedia) {
|
|
163
|
-
const motionMediaQuery = window.matchMedia("(prefers-reduced-motion)");
|
|
164
|
-
const setReducedMotionPreferences = () => (prefersReducedMotion.current = motionMediaQuery.matches);
|
|
165
|
-
motionMediaQuery.addListener(setReducedMotionPreferences);
|
|
166
|
-
setReducedMotionPreferences();
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
prefersReducedMotion.current = false;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
174
|
-
*
|
|
175
|
-
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
176
|
-
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
177
|
-
*
|
|
178
|
-
* It will actively respond to changes and re-render your components with the latest setting.
|
|
179
|
-
*
|
|
180
|
-
* ```jsx
|
|
181
|
-
* export function Sidebar({ isOpen }) {
|
|
182
|
-
* const shouldReduceMotion = useReducedMotion()
|
|
183
|
-
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
184
|
-
*
|
|
185
|
-
* return (
|
|
186
|
-
* <motion.div animate={{
|
|
187
|
-
* opacity: isOpen ? 1 : 0,
|
|
188
|
-
* x: isOpen ? 0 : closedX
|
|
189
|
-
* }} />
|
|
190
|
-
* )
|
|
191
|
-
* }
|
|
192
|
-
* ```
|
|
193
|
-
*
|
|
194
|
-
* @return boolean
|
|
195
|
-
*
|
|
196
|
-
* @public
|
|
197
|
-
*/
|
|
198
|
-
function useReducedMotion() {
|
|
199
|
-
/**
|
|
200
|
-
* Lazy initialisation of prefersReducedMotion
|
|
201
|
-
*/
|
|
202
|
-
!hasDetected && initPrefersReducedMotion();
|
|
203
|
-
const [shouldReduceMotion] = React.useState(prefersReducedMotion.current);
|
|
204
|
-
/**
|
|
205
|
-
* TODO See if people miss automatically updating shouldReduceMotion setting
|
|
206
|
-
*/
|
|
207
|
-
return shouldReduceMotion;
|
|
208
|
-
}
|
|
209
|
-
function useReducedMotionConfig() {
|
|
210
|
-
const reducedMotionPreference = useReducedMotion();
|
|
211
|
-
const { reducedMotion } = React.useContext(MotionConfigContext);
|
|
212
|
-
if (reducedMotion === "never") {
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
else if (reducedMotion === "always") {
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
return reducedMotionPreference;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
53
|
+
const LazyContext = React.createContext({ strict: false });
|
|
222
54
|
|
|
223
55
|
function useVisualElement(Component, visualState, props, createVisualElement) {
|
|
224
|
-
const lazyContext = React.useContext(LazyContext);
|
|
225
56
|
const parent = useVisualElementContext();
|
|
57
|
+
const lazyContext = React.useContext(LazyContext);
|
|
226
58
|
const presenceContext = React.useContext(PresenceContext);
|
|
227
|
-
const
|
|
59
|
+
const reducedMotionConfig = React.useContext(MotionConfigContext).reducedMotion;
|
|
228
60
|
const visualElementRef = React.useRef(undefined);
|
|
229
61
|
/**
|
|
230
62
|
* If we haven't preloaded a renderer, check to see if we have one lazy-loaded
|
|
231
63
|
*/
|
|
232
|
-
|
|
233
|
-
createVisualElement = lazyContext.renderer;
|
|
64
|
+
createVisualElement = createVisualElement || lazyContext.renderer;
|
|
234
65
|
if (!visualElementRef.current && createVisualElement) {
|
|
235
66
|
visualElementRef.current = createVisualElement(Component, {
|
|
236
67
|
visualState,
|
|
237
68
|
parent,
|
|
238
69
|
props,
|
|
239
|
-
presenceId: presenceContext
|
|
240
|
-
blockInitialAnimation:
|
|
241
|
-
|
|
70
|
+
presenceId: presenceContext ? presenceContext.id : undefined,
|
|
71
|
+
blockInitialAnimation: presenceContext
|
|
72
|
+
? presenceContext.initial === false
|
|
73
|
+
: false,
|
|
74
|
+
reducedMotionConfig,
|
|
242
75
|
});
|
|
243
76
|
}
|
|
244
77
|
const visualElement = visualElementRef.current;
|
|
245
78
|
useIsomorphicLayoutEffect(() => {
|
|
246
|
-
visualElement
|
|
79
|
+
visualElement && visualElement.syncRender();
|
|
247
80
|
});
|
|
248
81
|
React.useEffect(() => {
|
|
249
|
-
|
|
250
|
-
|
|
82
|
+
if (visualElement && visualElement.animationState) {
|
|
83
|
+
visualElement.animationState.animateChanges();
|
|
84
|
+
}
|
|
251
85
|
});
|
|
252
|
-
useIsomorphicLayoutEffect(() => () => visualElement
|
|
86
|
+
useIsomorphicLayoutEffect(() => () => visualElement && visualElement.notifyUnmount(), []);
|
|
253
87
|
return visualElement;
|
|
254
88
|
}
|
|
255
89
|
|
|
@@ -264,8 +98,7 @@
|
|
|
264
98
|
*/
|
|
265
99
|
function useMotionRef(visualState, visualElement, externalRef) {
|
|
266
100
|
return React.useCallback((instance) => {
|
|
267
|
-
|
|
268
|
-
instance && ((_a = visualState.mount) === null || _a === void 0 ? void 0 : _a.call(visualState, instance));
|
|
101
|
+
instance && visualState.mount && visualState.mount(instance);
|
|
269
102
|
if (visualElement) {
|
|
270
103
|
instance
|
|
271
104
|
? visualElement.mount(instance)
|
|
@@ -288,80 +121,37 @@
|
|
|
288
121
|
[visualElement]);
|
|
289
122
|
}
|
|
290
123
|
|
|
291
|
-
/**
|
|
292
|
-
* Decides if the supplied variable is an array of variant labels
|
|
293
|
-
*/
|
|
294
|
-
function isVariantLabels(v) {
|
|
295
|
-
return Array.isArray(v);
|
|
296
|
-
}
|
|
297
124
|
/**
|
|
298
125
|
* Decides if the supplied variable is variant label
|
|
299
126
|
*/
|
|
300
127
|
function isVariantLabel(v) {
|
|
301
|
-
return typeof v === "string" ||
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Creates an object containing the latest state of every MotionValue on a VisualElement
|
|
305
|
-
*/
|
|
306
|
-
function getCurrent(visualElement) {
|
|
307
|
-
const current = {};
|
|
308
|
-
visualElement.forEachValue((value, key) => (current[key] = value.get()));
|
|
309
|
-
return current;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Creates an object containing the latest velocity of every MotionValue on a VisualElement
|
|
313
|
-
*/
|
|
314
|
-
function getVelocity$1(visualElement) {
|
|
315
|
-
const velocity = {};
|
|
316
|
-
visualElement.forEachValue((value, key) => (velocity[key] = value.getVelocity()));
|
|
317
|
-
return velocity;
|
|
318
|
-
}
|
|
319
|
-
function resolveVariantFromProps(props, definition, custom, currentValues = {}, currentVelocity = {}) {
|
|
320
|
-
var _a;
|
|
321
|
-
/**
|
|
322
|
-
* If the variant definition is a function, resolve.
|
|
323
|
-
*/
|
|
324
|
-
if (typeof definition === "function") {
|
|
325
|
-
definition = definition(custom !== null && custom !== void 0 ? custom : props.custom, currentValues, currentVelocity);
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* If the variant definition is a variant label, or
|
|
329
|
-
* the function returned a variant label, resolve.
|
|
330
|
-
*/
|
|
331
|
-
if (typeof definition === "string") {
|
|
332
|
-
definition = (_a = props.variants) === null || _a === void 0 ? void 0 : _a[definition];
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* At this point we've resolved both functions and variant labels,
|
|
336
|
-
* but the resolved variant label might itself have been a function.
|
|
337
|
-
* If so, resolve. This can only have returned a valid target object.
|
|
338
|
-
*/
|
|
339
|
-
if (typeof definition === "function") {
|
|
340
|
-
definition = definition(custom !== null && custom !== void 0 ? custom : props.custom, currentValues, currentVelocity);
|
|
341
|
-
}
|
|
342
|
-
return definition;
|
|
128
|
+
return typeof v === "string" || Array.isArray(v);
|
|
343
129
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return
|
|
130
|
+
|
|
131
|
+
function isAnimationControls(v) {
|
|
132
|
+
return typeof v === "object" && typeof v.start === "function";
|
|
347
133
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
134
|
+
|
|
135
|
+
const variantProps$1 = [
|
|
136
|
+
"initial",
|
|
137
|
+
"animate",
|
|
138
|
+
"exit",
|
|
139
|
+
"whileHover",
|
|
140
|
+
"whileDrag",
|
|
141
|
+
"whileTap",
|
|
142
|
+
"whileFocus",
|
|
143
|
+
"whileInView",
|
|
144
|
+
];
|
|
145
|
+
function isControllingVariants(props) {
|
|
146
|
+
return (isAnimationControls(props.animate) ||
|
|
147
|
+
variantProps$1.some((name) => isVariantLabel(props[name])));
|
|
358
148
|
}
|
|
359
|
-
function
|
|
360
|
-
return Boolean(
|
|
149
|
+
function isVariantNode(props) {
|
|
150
|
+
return Boolean(isControllingVariants(props) || props.variants);
|
|
361
151
|
}
|
|
362
152
|
|
|
363
153
|
function getCurrentTreeVariants(props, context) {
|
|
364
|
-
if (
|
|
154
|
+
if (isControllingVariants(props)) {
|
|
365
155
|
const { initial, animate } = props;
|
|
366
156
|
return {
|
|
367
157
|
initial: initial === false || isVariantLabel(initial)
|
|
@@ -381,6 +171,50 @@
|
|
|
381
171
|
return Array.isArray(prop) ? prop.join(" ") : prop;
|
|
382
172
|
}
|
|
383
173
|
|
|
174
|
+
const createDefinition = (propNames) => ({
|
|
175
|
+
isEnabled: (props) => propNames.some((name) => !!props[name]),
|
|
176
|
+
});
|
|
177
|
+
const featureDefinitions = {
|
|
178
|
+
measureLayout: createDefinition(["layout", "layoutId", "drag"]),
|
|
179
|
+
animation: createDefinition([
|
|
180
|
+
"animate",
|
|
181
|
+
"exit",
|
|
182
|
+
"variants",
|
|
183
|
+
"whileHover",
|
|
184
|
+
"whileTap",
|
|
185
|
+
"whileFocus",
|
|
186
|
+
"whileDrag",
|
|
187
|
+
"whileInView",
|
|
188
|
+
]),
|
|
189
|
+
exit: createDefinition(["exit"]),
|
|
190
|
+
drag: createDefinition(["drag", "dragControls"]),
|
|
191
|
+
focus: createDefinition(["whileFocus"]),
|
|
192
|
+
hover: createDefinition(["whileHover", "onHoverStart", "onHoverEnd"]),
|
|
193
|
+
tap: createDefinition(["whileTap", "onTap", "onTapStart", "onTapCancel"]),
|
|
194
|
+
pan: createDefinition([
|
|
195
|
+
"onPan",
|
|
196
|
+
"onPanStart",
|
|
197
|
+
"onPanSessionStart",
|
|
198
|
+
"onPanEnd",
|
|
199
|
+
]),
|
|
200
|
+
inView: createDefinition([
|
|
201
|
+
"whileInView",
|
|
202
|
+
"onViewportEnter",
|
|
203
|
+
"onViewportLeave",
|
|
204
|
+
]),
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
function loadFeatures(features) {
|
|
208
|
+
for (const key in features) {
|
|
209
|
+
if (key === "projectionNodeConstructor") {
|
|
210
|
+
featureDefinitions.projectionNodeConstructor = features[key];
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
featureDefinitions[key].Component = features[key];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
384
218
|
/**
|
|
385
219
|
* Creates a constant value over the lifecycle of a component.
|
|
386
220
|
*
|
|
@@ -425,58 +259,27 @@
|
|
|
425
259
|
|
|
426
260
|
const LayoutGroupContext = React.createContext({});
|
|
427
261
|
|
|
428
|
-
/**
|
|
429
|
-
* Internal, exported only for usage in Framer
|
|
430
|
-
*/
|
|
431
|
-
const SwitchLayoutGroupContext = React.createContext({});
|
|
432
|
-
|
|
433
|
-
function useProjection(projectionId, { layoutId, layout, drag, dragConstraints, layoutScroll }, visualElement, ProjectionNodeConstructor) {
|
|
434
|
-
var _a;
|
|
435
|
-
const initialPromotionConfig = React.useContext(SwitchLayoutGroupContext);
|
|
436
|
-
if (!ProjectionNodeConstructor ||
|
|
437
|
-
!visualElement ||
|
|
438
|
-
(visualElement === null || visualElement === void 0 ? void 0 : visualElement.projection)) {
|
|
439
|
-
return;
|
|
440
|
-
}
|
|
441
|
-
visualElement.projection = new ProjectionNodeConstructor(projectionId, visualElement.getLatestValues(), (_a = visualElement.parent) === null || _a === void 0 ? void 0 : _a.projection);
|
|
442
|
-
visualElement.projection.setOptions({
|
|
443
|
-
layoutId,
|
|
444
|
-
layout,
|
|
445
|
-
alwaysMeasureLayout: Boolean(drag) || (dragConstraints && isRefObject(dragConstraints)),
|
|
446
|
-
visualElement,
|
|
447
|
-
scheduleRender: () => visualElement.scheduleRender(),
|
|
448
|
-
/**
|
|
449
|
-
* TODO: Update options in an effect. This could be tricky as it'll be too late
|
|
450
|
-
* to update by the time layout animations run.
|
|
451
|
-
* We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
|
|
452
|
-
* ensuring it gets called if there's no potential layout animations.
|
|
453
|
-
*
|
|
454
|
-
*/
|
|
455
|
-
animationType: typeof layout === "string" ? layout : "both",
|
|
456
|
-
initialPromotionConfig,
|
|
457
|
-
layoutScroll,
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
|
|
461
262
|
class VisualElementHandler extends React__default["default"].Component {
|
|
462
263
|
/**
|
|
463
264
|
* Update visual element props as soon as we know this update is going to be commited.
|
|
464
265
|
*/
|
|
465
266
|
getSnapshotBeforeUpdate() {
|
|
466
|
-
this.updateProps();
|
|
467
|
-
return null;
|
|
468
|
-
}
|
|
469
|
-
componentDidUpdate() { }
|
|
470
|
-
updateProps() {
|
|
471
267
|
const { visualElement, props } = this.props;
|
|
472
268
|
if (visualElement)
|
|
473
269
|
visualElement.setProps(props);
|
|
270
|
+
return null;
|
|
474
271
|
}
|
|
272
|
+
componentDidUpdate() { }
|
|
475
273
|
render() {
|
|
476
274
|
return this.props.children;
|
|
477
275
|
}
|
|
478
276
|
}
|
|
479
277
|
|
|
278
|
+
/**
|
|
279
|
+
* Internal, exported only for usage in Framer
|
|
280
|
+
*/
|
|
281
|
+
const SwitchLayoutGroupContext = React.createContext({});
|
|
282
|
+
|
|
480
283
|
/**
|
|
481
284
|
* Create a `motion` component.
|
|
482
285
|
*
|
|
@@ -489,15 +292,12 @@
|
|
|
489
292
|
function createMotionComponent({ preloadedFeatures, createVisualElement, projectionNodeConstructor, useRender, useVisualState, Component, }) {
|
|
490
293
|
preloadedFeatures && loadFeatures(preloadedFeatures);
|
|
491
294
|
function MotionComponent(props, externalRef) {
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
* or any gesture/animation features.
|
|
499
|
-
*/
|
|
500
|
-
const config = React.useContext(MotionConfigContext);
|
|
295
|
+
const configAndProps = {
|
|
296
|
+
...React.useContext(MotionConfigContext),
|
|
297
|
+
...props,
|
|
298
|
+
layoutId: useLayoutId(props),
|
|
299
|
+
};
|
|
300
|
+
const { isStatic } = configAndProps;
|
|
501
301
|
let features = null;
|
|
502
302
|
const context = useCreateMotionContext(props);
|
|
503
303
|
/**
|
|
@@ -511,40 +311,42 @@
|
|
|
511
311
|
* shared element transitions however. Perhaps for those we could revert to a root node
|
|
512
312
|
* that gets forceRendered and layout animations are triggered on its layout effect.
|
|
513
313
|
*/
|
|
514
|
-
const projectionId =
|
|
314
|
+
const projectionId = isStatic ? undefined : useProjectionId();
|
|
515
315
|
/**
|
|
516
316
|
*
|
|
517
317
|
*/
|
|
518
|
-
const visualState = useVisualState(props,
|
|
519
|
-
if (!
|
|
318
|
+
const visualState = useVisualState(props, isStatic);
|
|
319
|
+
if (!isStatic && isBrowser) {
|
|
520
320
|
/**
|
|
521
321
|
* Create a VisualElement for this component. A VisualElement provides a common
|
|
522
322
|
* interface to renderer-specific APIs (ie DOM/Three.js etc) as well as
|
|
523
323
|
* providing a way of rendering to these APIs outside of the React render loop
|
|
524
324
|
* for more performant animations and interactions
|
|
525
325
|
*/
|
|
526
|
-
context.visualElement = useVisualElement(Component, visualState,
|
|
527
|
-
useProjection(projectionId, props, context.visualElement, projectionNodeConstructor ||
|
|
528
|
-
featureDefinitions.projectionNodeConstructor);
|
|
326
|
+
context.visualElement = useVisualElement(Component, visualState, configAndProps, createVisualElement);
|
|
529
327
|
/**
|
|
530
328
|
* Load Motion gesture and animation features. These are rendered as renderless
|
|
531
329
|
* components so each feature can optionally make use of React lifecycle methods.
|
|
532
330
|
*/
|
|
533
|
-
|
|
331
|
+
const lazyStrictMode = React.useContext(LazyContext).strict;
|
|
332
|
+
const initialLayoutGroupConfig = React.useContext(SwitchLayoutGroupContext);
|
|
333
|
+
if (context.visualElement) {
|
|
334
|
+
features = context.visualElement.loadFeatures(props, lazyStrictMode, preloadedFeatures, projectionId, projectionNodeConstructor ||
|
|
335
|
+
featureDefinitions.projectionNodeConstructor, initialLayoutGroupConfig);
|
|
336
|
+
}
|
|
534
337
|
}
|
|
535
338
|
/**
|
|
536
339
|
* The mount order and hierarchy is specific to ensure our element ref
|
|
537
340
|
* is hydrated by the time features fire their effects.
|
|
538
341
|
*/
|
|
539
|
-
return (React__namespace.createElement(VisualElementHandler, { visualElement: context.visualElement, props:
|
|
342
|
+
return (React__namespace.createElement(VisualElementHandler, { visualElement: context.visualElement, props: configAndProps },
|
|
540
343
|
features,
|
|
541
|
-
React__namespace.createElement(MotionContext.Provider, { value: context }, useRender(Component, props, projectionId, useMotionRef(visualState, context.visualElement, externalRef), visualState,
|
|
344
|
+
React__namespace.createElement(MotionContext.Provider, { value: context }, useRender(Component, props, projectionId, useMotionRef(visualState, context.visualElement, externalRef), visualState, isStatic, context.visualElement))));
|
|
542
345
|
}
|
|
543
346
|
return React.forwardRef(MotionComponent);
|
|
544
347
|
}
|
|
545
348
|
function useLayoutId({ layoutId }) {
|
|
546
|
-
|
|
547
|
-
const layoutGroupId = (_a = React.useContext(LayoutGroupContext)) === null || _a === void 0 ? void 0 : _a.id;
|
|
349
|
+
const layoutGroupId = React.useContext(LayoutGroupContext).id;
|
|
548
350
|
return layoutGroupId && layoutId !== undefined
|
|
549
351
|
? layoutGroupId + "-" + layoutId
|
|
550
352
|
: layoutId;
|
|
@@ -658,52 +460,40 @@
|
|
|
658
460
|
Object.assign(scaleCorrectors, correctors);
|
|
659
461
|
}
|
|
660
462
|
|
|
661
|
-
/**
|
|
662
|
-
* A list of all transformable axes. We'll use this list to generated a version
|
|
663
|
-
* of each axes for each transform.
|
|
664
|
-
*/
|
|
665
|
-
const transformAxes = ["", "X", "Y", "Z"];
|
|
666
|
-
/**
|
|
667
|
-
* An ordered array of each transformable value. By default, transform values
|
|
668
|
-
* will be sorted to this order.
|
|
669
|
-
*/
|
|
670
|
-
const order = ["translate", "scale", "rotate", "skew"];
|
|
671
463
|
/**
|
|
672
464
|
* Generate a list of every possible transform key.
|
|
673
465
|
*/
|
|
674
|
-
const
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
466
|
+
const transformPropOrder = [
|
|
467
|
+
"transformPerspective",
|
|
468
|
+
"x",
|
|
469
|
+
"y",
|
|
470
|
+
"z",
|
|
471
|
+
"translateX",
|
|
472
|
+
"translateY",
|
|
473
|
+
"translateZ",
|
|
474
|
+
"scale",
|
|
475
|
+
"scaleX",
|
|
476
|
+
"scaleY",
|
|
477
|
+
"rotate",
|
|
478
|
+
"rotateX",
|
|
479
|
+
"rotateY",
|
|
480
|
+
"skew",
|
|
481
|
+
"skewX",
|
|
482
|
+
"skewY",
|
|
483
|
+
];
|
|
682
484
|
/**
|
|
683
485
|
* A quick lookup for transform props.
|
|
684
486
|
*/
|
|
685
|
-
const
|
|
686
|
-
function isTransformProp(key) {
|
|
687
|
-
return transformPropSet.has(key);
|
|
688
|
-
}
|
|
689
|
-
/**
|
|
690
|
-
* A quick lookup for transform origin props
|
|
691
|
-
*/
|
|
692
|
-
const transformOriginProps = new Set(["originX", "originY", "originZ"]);
|
|
693
|
-
function isTransformOriginProp(key) {
|
|
694
|
-
return transformOriginProps.has(key);
|
|
695
|
-
}
|
|
487
|
+
const transformProps = new Set(transformPropOrder);
|
|
696
488
|
|
|
697
489
|
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
698
|
-
return (
|
|
699
|
-
|
|
490
|
+
return (transformProps.has(key) ||
|
|
491
|
+
key.startsWith("origin") ||
|
|
700
492
|
((layout || layoutId !== undefined) &&
|
|
701
493
|
(!!scaleCorrectors[key] || key === "opacity")));
|
|
702
494
|
}
|
|
703
495
|
|
|
704
|
-
const isMotionValue = (value) =>
|
|
705
|
-
return Boolean(value !== null && typeof value === "object" && value.getVelocity);
|
|
706
|
-
};
|
|
496
|
+
const isMotionValue = (value) => value === undefined ? false : !!value.getVelocity;
|
|
707
497
|
|
|
708
498
|
const translateAlias = {
|
|
709
499
|
x: "translateX",
|
|
@@ -711,6 +501,10 @@
|
|
|
711
501
|
z: "translateZ",
|
|
712
502
|
transformPerspective: "perspective",
|
|
713
503
|
};
|
|
504
|
+
/**
|
|
505
|
+
* A function to use with Array.sort to sort transform keys by their default order.
|
|
506
|
+
*/
|
|
507
|
+
const sortTransformProps = (a, b) => transformPropOrder.indexOf(a) - transformPropOrder.indexOf(b);
|
|
714
508
|
/**
|
|
715
509
|
* Build a CSS transform style from individual x/y/scale etc properties.
|
|
716
510
|
*
|
|
@@ -722,18 +516,11 @@
|
|
|
722
516
|
let transformString = "";
|
|
723
517
|
// Transform keys into their default order - this will determine the output order.
|
|
724
518
|
transformKeys.sort(sortTransformProps);
|
|
725
|
-
// Track whether the defined transform has a defined z so we don't add a
|
|
726
|
-
// second to enable hardware acceleration
|
|
727
|
-
let transformHasZ = false;
|
|
728
519
|
// Loop over each transform and build them into transformString
|
|
729
|
-
const
|
|
730
|
-
for (let i = 0; i < numTransformKeys; i++) {
|
|
731
|
-
const key = transformKeys[i];
|
|
520
|
+
for (const key of transformKeys) {
|
|
732
521
|
transformString += `${translateAlias[key] || key}(${transform[key]}) `;
|
|
733
|
-
if (key === "z")
|
|
734
|
-
transformHasZ = true;
|
|
735
522
|
}
|
|
736
|
-
if (
|
|
523
|
+
if (enableHardwareAcceleration && !transform.z) {
|
|
737
524
|
transformString += "translateZ(0)";
|
|
738
525
|
}
|
|
739
526
|
transformString = transformString.trim();
|
|
@@ -747,13 +534,6 @@
|
|
|
747
534
|
}
|
|
748
535
|
return transformString;
|
|
749
536
|
}
|
|
750
|
-
/**
|
|
751
|
-
* Build a transformOrigin style. Uses the same defaults as the browser for
|
|
752
|
-
* undefined origins.
|
|
753
|
-
*/
|
|
754
|
-
function buildTransformOrigin({ originX = "50%", originY = "50%", originZ = 0, }) {
|
|
755
|
-
return `${originX} ${originY} ${originZ}`;
|
|
756
|
-
}
|
|
757
537
|
|
|
758
538
|
/**
|
|
759
539
|
* Returns true if the provided key is a CSS variable
|
|
@@ -972,7 +752,10 @@
|
|
|
972
752
|
return functions ? functions.map(applyDefaultFilter).join(' ') : v;
|
|
973
753
|
} });
|
|
974
754
|
|
|
975
|
-
const int =
|
|
755
|
+
const int = {
|
|
756
|
+
...number,
|
|
757
|
+
transform: Math.round,
|
|
758
|
+
};
|
|
976
759
|
|
|
977
760
|
const numberValueTypes = {
|
|
978
761
|
// Border props
|
|
@@ -1042,11 +825,7 @@
|
|
|
1042
825
|
};
|
|
1043
826
|
|
|
1044
827
|
function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
1045
|
-
var _a;
|
|
1046
828
|
const { style, vars, transform, transformKeys, transformOrigin } = state;
|
|
1047
|
-
// Empty the transformKeys array. As we're throwing out refs to its items
|
|
1048
|
-
// this might not be as cheap as suspected. Maybe using the array as a buffer
|
|
1049
|
-
// with a manual incrementation would be better.
|
|
1050
829
|
transformKeys.length = 0;
|
|
1051
830
|
// Track whether we encounter any transform or transformOrigin values.
|
|
1052
831
|
let hasTransform = false;
|
|
@@ -1071,7 +850,7 @@
|
|
|
1071
850
|
// Convert the value to its default value type, ie 0 -> "0px"
|
|
1072
851
|
const valueType = numberValueTypes[key];
|
|
1073
852
|
const valueAsType = getValueAsType(value, valueType);
|
|
1074
|
-
if (
|
|
853
|
+
if (transformProps.has(key)) {
|
|
1075
854
|
// If this is a transform, flag to enable further transform processing
|
|
1076
855
|
hasTransform = true;
|
|
1077
856
|
transform[key] = valueAsType;
|
|
@@ -1080,29 +859,35 @@
|
|
|
1080
859
|
if (!transformIsNone)
|
|
1081
860
|
continue;
|
|
1082
861
|
// Otherwise check to see if this is a default transform
|
|
1083
|
-
if (value !== (
|
|
862
|
+
if (value !== (valueType.default || 0))
|
|
1084
863
|
transformIsNone = false;
|
|
1085
864
|
}
|
|
1086
|
-
else if (
|
|
1087
|
-
transformOrigin[key] = valueAsType;
|
|
865
|
+
else if (key.startsWith("origin")) {
|
|
1088
866
|
// If this is a transform origin, flag and enable further transform-origin processing
|
|
1089
867
|
hasTransformOrigin = true;
|
|
868
|
+
transformOrigin[key] = valueAsType;
|
|
1090
869
|
}
|
|
1091
870
|
else {
|
|
1092
871
|
style[key] = valueAsType;
|
|
1093
872
|
}
|
|
1094
873
|
}
|
|
1095
|
-
if (hasTransform) {
|
|
874
|
+
if (hasTransform || transformTemplate) {
|
|
1096
875
|
style.transform = buildTransform(state, options, transformIsNone, transformTemplate);
|
|
1097
876
|
}
|
|
1098
|
-
else if (transformTemplate) {
|
|
1099
|
-
style.transform = transformTemplate({}, "");
|
|
1100
|
-
}
|
|
1101
877
|
else if (!latestValues.transform && style.transform) {
|
|
878
|
+
/**
|
|
879
|
+
* If we have previously created a transform but currently don't have any,
|
|
880
|
+
* reset transform style to none.
|
|
881
|
+
*/
|
|
1102
882
|
style.transform = "none";
|
|
1103
883
|
}
|
|
884
|
+
/**
|
|
885
|
+
* Build a transformOrigin style. Uses the same defaults as the browser for
|
|
886
|
+
* undefined origins.
|
|
887
|
+
*/
|
|
1104
888
|
if (hasTransformOrigin) {
|
|
1105
|
-
|
|
889
|
+
const { originX = "50%", originY = "50%", originZ = 0, } = transformOrigin;
|
|
890
|
+
style.transformOrigin = `${originX} ${originY} ${originZ}`;
|
|
1106
891
|
}
|
|
1107
892
|
}
|
|
1108
893
|
|
|
@@ -1125,28 +910,24 @@
|
|
|
1125
910
|
return React.useMemo(() => {
|
|
1126
911
|
const state = createHtmlRenderState();
|
|
1127
912
|
buildHTMLStyles(state, visualState, { enableHardwareAcceleration: !isStatic }, transformTemplate);
|
|
1128
|
-
|
|
1129
|
-
return Object.assign(Object.assign({}, vars), style);
|
|
913
|
+
return Object.assign({}, state.vars, state.style);
|
|
1130
914
|
}, [visualState]);
|
|
1131
915
|
}
|
|
1132
916
|
function useStyle(props, visualState, isStatic) {
|
|
1133
917
|
const styleProp = props.style || {};
|
|
1134
|
-
|
|
918
|
+
const style = {};
|
|
1135
919
|
/**
|
|
1136
920
|
* Copy non-Motion Values straight into style
|
|
1137
921
|
*/
|
|
1138
922
|
copyRawValuesOnly(style, styleProp, props);
|
|
1139
923
|
Object.assign(style, useInitialMotionValues(props, visualState, isStatic));
|
|
1140
|
-
|
|
1141
|
-
style = props.transformValues(style);
|
|
1142
|
-
}
|
|
1143
|
-
return style;
|
|
924
|
+
return props.transformValues ? props.transformValues(style) : style;
|
|
1144
925
|
}
|
|
1145
926
|
function useHTMLProps(props, visualState, isStatic) {
|
|
1146
927
|
// The `any` isn't ideal but it is the type of createElement props argument
|
|
1147
928
|
const htmlProps = {};
|
|
1148
929
|
const style = useStyle(props, visualState, isStatic);
|
|
1149
|
-
if (
|
|
930
|
+
if (props.drag && props.dragListener !== false) {
|
|
1150
931
|
// Disable the ghost element when a user drags
|
|
1151
932
|
htmlProps.draggable = false;
|
|
1152
933
|
// Disable text selection
|
|
@@ -1164,6 +945,24 @@
|
|
|
1164
945
|
return htmlProps;
|
|
1165
946
|
}
|
|
1166
947
|
|
|
948
|
+
const animationProps = [
|
|
949
|
+
"animate",
|
|
950
|
+
"exit",
|
|
951
|
+
"variants",
|
|
952
|
+
"whileHover",
|
|
953
|
+
"whileTap",
|
|
954
|
+
"whileFocus",
|
|
955
|
+
"whileDrag",
|
|
956
|
+
"whileInView",
|
|
957
|
+
];
|
|
958
|
+
const tapProps = ["whileTap", "onTap", "onTapStart", "onTapCancel"];
|
|
959
|
+
const panProps = ["onPan", "onPanStart", "onPanSessionStart", "onPanEnd"];
|
|
960
|
+
const inViewProps = [
|
|
961
|
+
"whileInView",
|
|
962
|
+
"onViewportEnter",
|
|
963
|
+
"onViewportLeave",
|
|
964
|
+
"viewport",
|
|
965
|
+
];
|
|
1167
966
|
/**
|
|
1168
967
|
* A list of all valid MotionProps.
|
|
1169
968
|
*
|
|
@@ -1172,8 +971,6 @@
|
|
|
1172
971
|
*/
|
|
1173
972
|
const validMotionProps = new Set([
|
|
1174
973
|
"initial",
|
|
1175
|
-
"animate",
|
|
1176
|
-
"exit",
|
|
1177
974
|
"style",
|
|
1178
975
|
"variants",
|
|
1179
976
|
"transition",
|
|
@@ -1209,24 +1006,13 @@
|
|
|
1209
1006
|
"dragMomentum",
|
|
1210
1007
|
"dragPropagation",
|
|
1211
1008
|
"dragTransition",
|
|
1212
|
-
"whileDrag",
|
|
1213
|
-
"onPan",
|
|
1214
|
-
"onPanStart",
|
|
1215
|
-
"onPanEnd",
|
|
1216
|
-
"onPanSessionStart",
|
|
1217
|
-
"onTap",
|
|
1218
|
-
"onTapStart",
|
|
1219
|
-
"onTapCancel",
|
|
1220
1009
|
"onHoverStart",
|
|
1221
1010
|
"onHoverEnd",
|
|
1222
|
-
"whileFocus",
|
|
1223
|
-
"whileTap",
|
|
1224
|
-
"whileHover",
|
|
1225
|
-
"whileInView",
|
|
1226
|
-
"onViewportEnter",
|
|
1227
|
-
"onViewportLeave",
|
|
1228
|
-
"viewport",
|
|
1229
1011
|
"layoutScroll",
|
|
1012
|
+
...inViewProps,
|
|
1013
|
+
...tapProps,
|
|
1014
|
+
...animationProps,
|
|
1015
|
+
...panProps,
|
|
1230
1016
|
]);
|
|
1231
1017
|
/**
|
|
1232
1018
|
* Check whether a prop name is a valid `MotionProp` key.
|
|
@@ -1285,33 +1071,6 @@
|
|
|
1285
1071
|
return filteredProps;
|
|
1286
1072
|
}
|
|
1287
1073
|
|
|
1288
|
-
/******************************************************************************
|
|
1289
|
-
Copyright (c) Microsoft Corporation.
|
|
1290
|
-
|
|
1291
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
1292
|
-
purpose with or without fee is hereby granted.
|
|
1293
|
-
|
|
1294
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1295
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1296
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1297
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1298
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1299
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1300
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
1301
|
-
***************************************************************************** */
|
|
1302
|
-
|
|
1303
|
-
function __rest(s, e) {
|
|
1304
|
-
var t = {};
|
|
1305
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
1306
|
-
t[p] = s[p];
|
|
1307
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
1308
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
1309
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
1310
|
-
t[p[i]] = s[p[i]];
|
|
1311
|
-
}
|
|
1312
|
-
return t;
|
|
1313
|
-
}
|
|
1314
|
-
|
|
1315
1074
|
function calcOrigin$1(origin, offset, size) {
|
|
1316
1075
|
return typeof origin === "string"
|
|
1317
1076
|
? origin
|
|
@@ -1359,10 +1118,9 @@
|
|
|
1359
1118
|
/**
|
|
1360
1119
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
1361
1120
|
*/
|
|
1362
|
-
function buildSVGAttrs(state,
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
latest = __rest(_a, ["attrX", "attrY", "originX", "originY", "pathLength", "pathSpacing", "pathOffset"]);
|
|
1121
|
+
function buildSVGAttrs(state, { attrX, attrY, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0,
|
|
1122
|
+
// This is object creation, which we try to avoid per-frame.
|
|
1123
|
+
...latest }, options, transformTemplate) {
|
|
1366
1124
|
buildHTMLStyles(state, latest, options, transformTemplate);
|
|
1367
1125
|
state.attrs = state.style;
|
|
1368
1126
|
state.style = {};
|
|
@@ -1392,18 +1150,24 @@
|
|
|
1392
1150
|
}
|
|
1393
1151
|
}
|
|
1394
1152
|
|
|
1395
|
-
const createSvgRenderState = () => (
|
|
1153
|
+
const createSvgRenderState = () => ({
|
|
1154
|
+
...createHtmlRenderState(),
|
|
1155
|
+
attrs: {},
|
|
1156
|
+
});
|
|
1396
1157
|
|
|
1397
1158
|
function useSVGProps(props, visualState) {
|
|
1398
1159
|
const visualProps = React.useMemo(() => {
|
|
1399
1160
|
const state = createSvgRenderState();
|
|
1400
1161
|
buildSVGAttrs(state, visualState, { enableHardwareAcceleration: false }, props.transformTemplate);
|
|
1401
|
-
return
|
|
1162
|
+
return {
|
|
1163
|
+
...state.attrs,
|
|
1164
|
+
style: { ...state.style },
|
|
1165
|
+
};
|
|
1402
1166
|
}, [visualState]);
|
|
1403
1167
|
if (props.style) {
|
|
1404
1168
|
const rawStyles = {};
|
|
1405
1169
|
copyRawValuesOnly(rawStyles, props.style, props);
|
|
1406
|
-
visualProps.style =
|
|
1170
|
+
visualProps.style = { ...rawStyles, ...visualProps.style };
|
|
1407
1171
|
}
|
|
1408
1172
|
return visualProps;
|
|
1409
1173
|
}
|
|
@@ -1415,7 +1179,11 @@
|
|
|
1415
1179
|
: useHTMLProps;
|
|
1416
1180
|
const visualProps = useVisualProps(props, latestValues, isStatic);
|
|
1417
1181
|
const filteredProps = filterProps(props, typeof Component === "string", forwardMotionProps);
|
|
1418
|
-
const elementProps =
|
|
1182
|
+
const elementProps = {
|
|
1183
|
+
...filteredProps,
|
|
1184
|
+
...visualProps,
|
|
1185
|
+
ref,
|
|
1186
|
+
};
|
|
1419
1187
|
if (projectionId) {
|
|
1420
1188
|
elementProps["data-projection-id"] = projectionId;
|
|
1421
1189
|
}
|
|
@@ -1424,12 +1192,10 @@
|
|
|
1424
1192
|
return useRender;
|
|
1425
1193
|
}
|
|
1426
1194
|
|
|
1427
|
-
const CAMEL_CASE_PATTERN = /([a-z])([A-Z])/g;
|
|
1428
|
-
const REPLACE_TEMPLATE = "$1-$2";
|
|
1429
1195
|
/**
|
|
1430
1196
|
* Convert camelCase to dash-case properties.
|
|
1431
1197
|
*/
|
|
1432
|
-
const camelToDash = (str) => str.replace(
|
|
1198
|
+
const camelToDash = (str) => str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
1433
1199
|
|
|
1434
1200
|
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
1435
1201
|
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
@@ -1494,8 +1260,29 @@
|
|
|
1494
1260
|
return newValues;
|
|
1495
1261
|
}
|
|
1496
1262
|
|
|
1497
|
-
function
|
|
1498
|
-
|
|
1263
|
+
function resolveVariantFromProps(props, definition, custom, currentValues = {}, currentVelocity = {}) {
|
|
1264
|
+
/**
|
|
1265
|
+
* If the variant definition is a function, resolve.
|
|
1266
|
+
*/
|
|
1267
|
+
if (typeof definition === "function") {
|
|
1268
|
+
definition = definition(custom !== undefined ? custom : props.custom, currentValues, currentVelocity);
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* If the variant definition is a variant label, or
|
|
1272
|
+
* the function returned a variant label, resolve.
|
|
1273
|
+
*/
|
|
1274
|
+
if (typeof definition === "string") {
|
|
1275
|
+
definition = props.variants && props.variants[definition];
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* At this point we've resolved both functions and variant labels,
|
|
1279
|
+
* but the resolved variant label might itself have been a function.
|
|
1280
|
+
* If so, resolve. This can only have returned a valid target object.
|
|
1281
|
+
*/
|
|
1282
|
+
if (typeof definition === "function") {
|
|
1283
|
+
definition = definition(custom !== undefined ? custom : props.custom, currentValues, currentVelocity);
|
|
1284
|
+
}
|
|
1285
|
+
return definition;
|
|
1499
1286
|
}
|
|
1500
1287
|
|
|
1501
1288
|
const isKeyframesTarget = (v) => {
|
|
@@ -1535,29 +1322,32 @@
|
|
|
1535
1322
|
const makeUseVisualState = (config) => (props, isStatic) => {
|
|
1536
1323
|
const context = React.useContext(MotionContext);
|
|
1537
1324
|
const presenceContext = React.useContext(PresenceContext);
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
: useConstant(() => makeState(config, props, context, presenceContext));
|
|
1325
|
+
const make = () => makeState(config, props, context, presenceContext);
|
|
1326
|
+
return isStatic ? make() : useConstant(make);
|
|
1541
1327
|
};
|
|
1542
1328
|
function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
1543
1329
|
const values = {};
|
|
1544
|
-
const blockInitialAnimation = (presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.initial) === false;
|
|
1545
1330
|
const motionValues = scrapeMotionValues(props);
|
|
1546
1331
|
for (const key in motionValues) {
|
|
1547
1332
|
values[key] = resolveMotionValue(motionValues[key]);
|
|
1548
1333
|
}
|
|
1549
1334
|
let { initial, animate } = props;
|
|
1550
|
-
const isControllingVariants =
|
|
1551
|
-
const isVariantNode =
|
|
1335
|
+
const isControllingVariants$1 = isControllingVariants(props);
|
|
1336
|
+
const isVariantNode$1 = isVariantNode(props);
|
|
1552
1337
|
if (context &&
|
|
1553
|
-
isVariantNode &&
|
|
1554
|
-
!isControllingVariants &&
|
|
1338
|
+
isVariantNode$1 &&
|
|
1339
|
+
!isControllingVariants$1 &&
|
|
1555
1340
|
props.inherit !== false) {
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1341
|
+
if (initial === undefined)
|
|
1342
|
+
initial = context.initial;
|
|
1343
|
+
if (animate === undefined)
|
|
1344
|
+
animate = context.animate;
|
|
1345
|
+
}
|
|
1346
|
+
let isInitialAnimationBlocked = presenceContext
|
|
1347
|
+
? presenceContext.initial === false
|
|
1348
|
+
: false;
|
|
1349
|
+
isInitialAnimationBlocked = isInitialAnimationBlocked || initial === false;
|
|
1350
|
+
const variantToSet = isInitialAnimationBlocked ? animate : initial;
|
|
1561
1351
|
if (variantToSet &&
|
|
1562
1352
|
typeof variantToSet !== "boolean" &&
|
|
1563
1353
|
!isAnimationControls(variantToSet)) {
|
|
@@ -1566,7 +1356,7 @@
|
|
|
1566
1356
|
const resolved = resolveVariantFromProps(props, definition);
|
|
1567
1357
|
if (!resolved)
|
|
1568
1358
|
return;
|
|
1569
|
-
const { transitionEnd, transition
|
|
1359
|
+
const { transitionEnd, transition, ...target } = resolved;
|
|
1570
1360
|
for (const key in target) {
|
|
1571
1361
|
let valueTarget = target[key];
|
|
1572
1362
|
if (Array.isArray(valueTarget)) {
|
|
@@ -1574,7 +1364,7 @@
|
|
|
1574
1364
|
* Take final keyframe if the initial animation is blocked because
|
|
1575
1365
|
* we want to initialise at the end of that blocked animation.
|
|
1576
1366
|
*/
|
|
1577
|
-
const index =
|
|
1367
|
+
const index = isInitialAnimationBlocked
|
|
1578
1368
|
? valueTarget.length - 1
|
|
1579
1369
|
: 0;
|
|
1580
1370
|
valueTarget = valueTarget[index];
|
|
@@ -1628,9 +1418,14 @@
|
|
|
1628
1418
|
const baseConfig = isSVGComponent(Component)
|
|
1629
1419
|
? svgMotionConfig
|
|
1630
1420
|
: htmlMotionConfig;
|
|
1631
|
-
return
|
|
1421
|
+
return {
|
|
1422
|
+
...baseConfig,
|
|
1423
|
+
preloadedFeatures,
|
|
1424
|
+
useRender: createUseRender(forwardMotionProps),
|
|
1425
|
+
createVisualElement,
|
|
1632
1426
|
projectionNodeConstructor,
|
|
1633
|
-
Component
|
|
1427
|
+
Component,
|
|
1428
|
+
};
|
|
1634
1429
|
}
|
|
1635
1430
|
|
|
1636
1431
|
exports.AnimationType = void 0;
|
|
@@ -1685,13 +1480,12 @@
|
|
|
1685
1480
|
* @internal
|
|
1686
1481
|
*/
|
|
1687
1482
|
function useFocusGesture({ whileFocus, visualElement }) {
|
|
1483
|
+
const { animationState } = visualElement;
|
|
1688
1484
|
const onFocus = () => {
|
|
1689
|
-
|
|
1690
|
-
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(exports.AnimationType.Focus, true);
|
|
1485
|
+
animationState && animationState.setActive(exports.AnimationType.Focus, true);
|
|
1691
1486
|
};
|
|
1692
1487
|
const onBlur = () => {
|
|
1693
|
-
|
|
1694
|
-
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(exports.AnimationType.Focus, false);
|
|
1488
|
+
animationState && animationState.setActive(exports.AnimationType.Focus, false);
|
|
1695
1489
|
};
|
|
1696
1490
|
useDomEvent(visualElement, "focus", whileFocus ? onFocus : undefined);
|
|
1697
1491
|
useDomEvent(visualElement, "blur", whileFocus ? onBlur : undefined);
|
|
@@ -1846,14 +1640,15 @@
|
|
|
1846
1640
|
|
|
1847
1641
|
function createHoverEvent(visualElement, isActive, callback) {
|
|
1848
1642
|
return (event, info) => {
|
|
1849
|
-
var _a;
|
|
1850
1643
|
if (!isMouseEvent(event) || isDragActive())
|
|
1851
1644
|
return;
|
|
1852
1645
|
/**
|
|
1853
1646
|
* Ensure we trigger animations before firing event callback
|
|
1854
1647
|
*/
|
|
1855
|
-
(
|
|
1856
|
-
|
|
1648
|
+
if (visualElement.animationState) {
|
|
1649
|
+
visualElement.animationState.setActive(exports.AnimationType.Hover, isActive);
|
|
1650
|
+
}
|
|
1651
|
+
callback && callback(event, info);
|
|
1857
1652
|
};
|
|
1858
1653
|
}
|
|
1859
1654
|
function useHoverGesture({ onHoverStart, onHoverEnd, whileHover, visualElement, }) {
|
|
@@ -1888,6 +1683,48 @@
|
|
|
1888
1683
|
return React.useEffect(() => () => callback(), []);
|
|
1889
1684
|
}
|
|
1890
1685
|
|
|
1686
|
+
/******************************************************************************
|
|
1687
|
+
Copyright (c) Microsoft Corporation.
|
|
1688
|
+
|
|
1689
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
1690
|
+
purpose with or without fee is hereby granted.
|
|
1691
|
+
|
|
1692
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1693
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1694
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1695
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1696
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1697
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1698
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
1699
|
+
***************************************************************************** */
|
|
1700
|
+
|
|
1701
|
+
function __rest(s, e) {
|
|
1702
|
+
var t = {};
|
|
1703
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
1704
|
+
t[p] = s[p];
|
|
1705
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
1706
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
1707
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
1708
|
+
t[p[i]] = s[p[i]];
|
|
1709
|
+
}
|
|
1710
|
+
return t;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
var warning = function () { };
|
|
1714
|
+
var invariant = function () { };
|
|
1715
|
+
{
|
|
1716
|
+
warning = function (check, message) {
|
|
1717
|
+
if (!check && typeof console !== 'undefined') {
|
|
1718
|
+
console.warn(message);
|
|
1719
|
+
}
|
|
1720
|
+
};
|
|
1721
|
+
invariant = function (check, message) {
|
|
1722
|
+
if (!check) {
|
|
1723
|
+
throw new Error(message);
|
|
1724
|
+
}
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1891
1728
|
const clamp$1 = (min, max, v) => Math.min(Math.max(v, min), max);
|
|
1892
1729
|
|
|
1893
1730
|
const safeMin = 0.001;
|
|
@@ -2834,15 +2671,14 @@
|
|
|
2834
2671
|
passive: !(onTapStart || onTap || onTapCancel || onPointerDown),
|
|
2835
2672
|
};
|
|
2836
2673
|
function removePointerEndListener() {
|
|
2837
|
-
|
|
2838
|
-
(_a = cancelPointerEndListeners.current) === null || _a === void 0 ? void 0 : _a.call(cancelPointerEndListeners);
|
|
2674
|
+
cancelPointerEndListeners.current && cancelPointerEndListeners.current();
|
|
2839
2675
|
cancelPointerEndListeners.current = null;
|
|
2840
2676
|
}
|
|
2841
2677
|
function checkPointerEnd() {
|
|
2842
|
-
var _a;
|
|
2843
2678
|
removePointerEndListener();
|
|
2844
2679
|
isPressing.current = false;
|
|
2845
|
-
|
|
2680
|
+
visualElement.animationState &&
|
|
2681
|
+
visualElement.animationState.setActive(exports.AnimationType.Tap, false);
|
|
2846
2682
|
return !isDragActive();
|
|
2847
2683
|
}
|
|
2848
2684
|
function onPointerUp(event, info) {
|
|
@@ -2853,16 +2689,15 @@
|
|
|
2853
2689
|
* as, or a child of, this component's element
|
|
2854
2690
|
*/
|
|
2855
2691
|
!isNodeOrChild(visualElement.getInstance(), event.target)
|
|
2856
|
-
? onTapCancel
|
|
2857
|
-
: onTap
|
|
2692
|
+
? onTapCancel && onTapCancel(event, info)
|
|
2693
|
+
: onTap && onTap(event, info);
|
|
2858
2694
|
}
|
|
2859
2695
|
function onPointerCancel(event, info) {
|
|
2860
2696
|
if (!checkPointerEnd())
|
|
2861
2697
|
return;
|
|
2862
|
-
onTapCancel
|
|
2698
|
+
onTapCancel && onTapCancel(event, info);
|
|
2863
2699
|
}
|
|
2864
2700
|
function onPointerDown(event, info) {
|
|
2865
|
-
var _a;
|
|
2866
2701
|
removePointerEndListener();
|
|
2867
2702
|
if (isPressing.current)
|
|
2868
2703
|
return;
|
|
@@ -2871,13 +2706,22 @@
|
|
|
2871
2706
|
/**
|
|
2872
2707
|
* Ensure we trigger animations before firing event callback
|
|
2873
2708
|
*/
|
|
2874
|
-
|
|
2875
|
-
|
|
2709
|
+
visualElement.animationState &&
|
|
2710
|
+
visualElement.animationState.setActive(exports.AnimationType.Tap, true);
|
|
2711
|
+
onTapStart && onTapStart(event, info);
|
|
2876
2712
|
}
|
|
2877
2713
|
usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined, eventOptions);
|
|
2878
2714
|
useUnmountEffect(removePointerEndListener);
|
|
2879
2715
|
}
|
|
2880
2716
|
|
|
2717
|
+
/**
|
|
2718
|
+
* Browser-safe usage of process
|
|
2719
|
+
*/
|
|
2720
|
+
const defaultEnvironment = "production";
|
|
2721
|
+
const env = typeof process === "undefined" || process.env === undefined
|
|
2722
|
+
? defaultEnvironment
|
|
2723
|
+
: "development" ;
|
|
2724
|
+
|
|
2881
2725
|
const warned = new Set();
|
|
2882
2726
|
function warnOnce(condition, message, element) {
|
|
2883
2727
|
if (condition || warned.has(message))
|
|
@@ -2901,14 +2745,13 @@
|
|
|
2901
2745
|
*/
|
|
2902
2746
|
const observers = new WeakMap();
|
|
2903
2747
|
const fireObserverCallback = (entry) => {
|
|
2904
|
-
|
|
2905
|
-
|
|
2748
|
+
const callback = observerCallbacks.get(entry.target);
|
|
2749
|
+
callback && callback(entry);
|
|
2906
2750
|
};
|
|
2907
2751
|
const fireAllObserverCallbacks = (entries) => {
|
|
2908
2752
|
entries.forEach(fireObserverCallback);
|
|
2909
2753
|
};
|
|
2910
|
-
function initIntersectionObserver(
|
|
2911
|
-
var { root } = _a, options = __rest(_a, ["root"]);
|
|
2754
|
+
function initIntersectionObserver({ root, ...options }) {
|
|
2912
2755
|
const lookupRoot = root || document;
|
|
2913
2756
|
/**
|
|
2914
2757
|
* If we don't have an observer lookup map for this root, create one.
|
|
@@ -2923,7 +2766,7 @@
|
|
|
2923
2766
|
* create one.
|
|
2924
2767
|
*/
|
|
2925
2768
|
if (!rootObservers[key]) {
|
|
2926
|
-
rootObservers[key] = new IntersectionObserver(fireAllObserverCallbacks,
|
|
2769
|
+
rootObservers[key] = new IntersectionObserver(fireAllObserverCallbacks, { root, ...options });
|
|
2927
2770
|
}
|
|
2928
2771
|
return rootObservers[key];
|
|
2929
2772
|
}
|
|
@@ -2964,7 +2807,6 @@
|
|
|
2964
2807
|
threshold: typeof amount === "number" ? amount : thresholdNames[amount],
|
|
2965
2808
|
};
|
|
2966
2809
|
const intersectionCallback = (entry) => {
|
|
2967
|
-
var _a;
|
|
2968
2810
|
const { isIntersecting } = entry;
|
|
2969
2811
|
/**
|
|
2970
2812
|
* If there's been no change in the viewport state, early return.
|
|
@@ -2982,7 +2824,9 @@
|
|
|
2982
2824
|
else if (isIntersecting) {
|
|
2983
2825
|
state.hasEnteredView = true;
|
|
2984
2826
|
}
|
|
2985
|
-
(
|
|
2827
|
+
if (visualElement.animationState) {
|
|
2828
|
+
visualElement.animationState.setActive(exports.AnimationType.InView, isIntersecting);
|
|
2829
|
+
}
|
|
2986
2830
|
/**
|
|
2987
2831
|
* Use the latest committed props rather than the ones in scope
|
|
2988
2832
|
* when this observer is created
|
|
@@ -2991,7 +2835,7 @@
|
|
|
2991
2835
|
const callback = isIntersecting
|
|
2992
2836
|
? props.onViewportEnter
|
|
2993
2837
|
: props.onViewportLeave;
|
|
2994
|
-
callback
|
|
2838
|
+
callback && callback(entry);
|
|
2995
2839
|
};
|
|
2996
2840
|
return observeIntersection(visualElement.getInstance(), options, intersectionCallback);
|
|
2997
2841
|
}, [shouldObserve, root, rootMargin, amount]);
|
|
@@ -3017,11 +2861,12 @@
|
|
|
3017
2861
|
* is preferred to changing the behaviour of the animation state.
|
|
3018
2862
|
*/
|
|
3019
2863
|
requestAnimationFrame(() => {
|
|
3020
|
-
var _a;
|
|
3021
2864
|
state.hasEnteredView = true;
|
|
3022
2865
|
const { onViewportEnter } = visualElement.getProps();
|
|
3023
|
-
onViewportEnter
|
|
3024
|
-
(
|
|
2866
|
+
onViewportEnter && onViewportEnter(null);
|
|
2867
|
+
if (visualElement.animationState) {
|
|
2868
|
+
visualElement.animationState.setActive(exports.AnimationType.InView, true);
|
|
2869
|
+
}
|
|
3025
2870
|
});
|
|
3026
2871
|
}, [shouldObserve]);
|
|
3027
2872
|
}
|
|
@@ -3071,7 +2916,7 @@
|
|
|
3071
2916
|
// Replace with useId when released in React
|
|
3072
2917
|
const id = React.useId();
|
|
3073
2918
|
React.useEffect(() => register(id), []);
|
|
3074
|
-
const safeToRemove = () => onExitComplete
|
|
2919
|
+
const safeToRemove = () => onExitComplete && onExitComplete(id);
|
|
3075
2920
|
return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
|
|
3076
2921
|
}
|
|
3077
2922
|
/**
|
|
@@ -3230,17 +3075,29 @@
|
|
|
3230
3075
|
transitionFactory =
|
|
3231
3076
|
defaultTransitions[valueKey] || defaultTransitions.default;
|
|
3232
3077
|
}
|
|
3233
|
-
return
|
|
3078
|
+
return { to, ...transitionFactory(to) };
|
|
3234
3079
|
};
|
|
3235
3080
|
|
|
3236
3081
|
/**
|
|
3237
3082
|
* A map of default value types for common values
|
|
3238
3083
|
*/
|
|
3239
|
-
const defaultValueTypes =
|
|
3084
|
+
const defaultValueTypes = {
|
|
3085
|
+
...numberValueTypes,
|
|
3240
3086
|
// Color props
|
|
3241
|
-
color,
|
|
3087
|
+
color,
|
|
3088
|
+
backgroundColor: color,
|
|
3089
|
+
outlineColor: color,
|
|
3090
|
+
fill: color,
|
|
3091
|
+
stroke: color,
|
|
3242
3092
|
// Border props
|
|
3243
|
-
borderColor: color,
|
|
3093
|
+
borderColor: color,
|
|
3094
|
+
borderTopColor: color,
|
|
3095
|
+
borderRightColor: color,
|
|
3096
|
+
borderBottomColor: color,
|
|
3097
|
+
borderLeftColor: color,
|
|
3098
|
+
filter,
|
|
3099
|
+
WebkitFilter: filter,
|
|
3100
|
+
};
|
|
3244
3101
|
/**
|
|
3245
3102
|
* Gets the default ValueType for the provided value key
|
|
3246
3103
|
*/
|
|
@@ -3264,17 +3121,15 @@
|
|
|
3264
3121
|
* This filters out orchestration options and returns true
|
|
3265
3122
|
* if any options are left.
|
|
3266
3123
|
*/
|
|
3267
|
-
function isTransitionDefined(
|
|
3268
|
-
var transition = __rest(_a, ["when", "delay", "delayChildren", "staggerChildren", "staggerDirection", "repeat", "repeatType", "repeatDelay", "from"]);
|
|
3124
|
+
function isTransitionDefined({ when, delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
|
|
3269
3125
|
return !!Object.keys(transition).length;
|
|
3270
3126
|
}
|
|
3271
3127
|
let legacyRepeatWarning = false;
|
|
3272
3128
|
/**
|
|
3273
3129
|
* Convert Framer Motion's Transition type into Popmotion-compatible options.
|
|
3274
3130
|
*/
|
|
3275
|
-
function convertTransitionToAnimationOptions(
|
|
3276
|
-
|
|
3277
|
-
const options = Object.assign({}, transition);
|
|
3131
|
+
function convertTransitionToAnimationOptions({ ease, times, yoyo, flip, loop, ...transition }) {
|
|
3132
|
+
const options = { ...transition };
|
|
3278
3133
|
if (times)
|
|
3279
3134
|
options["offset"] = times;
|
|
3280
3135
|
/**
|
|
@@ -3339,26 +3194,30 @@
|
|
|
3339
3194
|
return options;
|
|
3340
3195
|
}
|
|
3341
3196
|
function getPopmotionAnimationOptions(transition, options, key) {
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
(_a = transition.duration) !== null && _a !== void 0 ? _a : (transition.duration = 0.8);
|
|
3197
|
+
if (Array.isArray(options.to) && transition.duration === undefined) {
|
|
3198
|
+
transition.duration = 0.8;
|
|
3345
3199
|
}
|
|
3346
3200
|
hydrateKeyframes(options);
|
|
3347
3201
|
/**
|
|
3348
3202
|
* Get a default transition if none is determined to be defined.
|
|
3349
3203
|
*/
|
|
3350
3204
|
if (!isTransitionDefined(transition)) {
|
|
3351
|
-
transition =
|
|
3205
|
+
transition = {
|
|
3206
|
+
...transition,
|
|
3207
|
+
...getDefaultTransition(key, options.to),
|
|
3208
|
+
};
|
|
3352
3209
|
}
|
|
3353
|
-
return
|
|
3210
|
+
return {
|
|
3211
|
+
...options,
|
|
3212
|
+
...convertTransitionToAnimationOptions(transition),
|
|
3213
|
+
};
|
|
3354
3214
|
}
|
|
3355
3215
|
/**
|
|
3356
3216
|
*
|
|
3357
3217
|
*/
|
|
3358
3218
|
function getAnimation(key, value, target, transition, onComplete) {
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
let origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
|
|
3219
|
+
const valueTransition = getValueTransition(transition, key) || {};
|
|
3220
|
+
let origin = valueTransition.from !== undefined ? valueTransition.from : value.get();
|
|
3362
3221
|
const isTargetAnimatable = isAnimatable(key, target);
|
|
3363
3222
|
if (origin === "none" && isTargetAnimatable && typeof target === "string") {
|
|
3364
3223
|
/**
|
|
@@ -3387,24 +3246,25 @@
|
|
|
3387
3246
|
};
|
|
3388
3247
|
return valueTransition.type === "inertia" ||
|
|
3389
3248
|
valueTransition.type === "decay"
|
|
3390
|
-
? inertia(
|
|
3391
|
-
: animate$1(
|
|
3392
|
-
|
|
3249
|
+
? inertia({ ...options, ...valueTransition })
|
|
3250
|
+
: animate$1({
|
|
3251
|
+
...getPopmotionAnimationOptions(valueTransition, options, key),
|
|
3252
|
+
onUpdate: (v) => {
|
|
3393
3253
|
options.onUpdate(v);
|
|
3394
|
-
|
|
3395
|
-
},
|
|
3396
|
-
|
|
3254
|
+
valueTransition.onUpdate && valueTransition.onUpdate(v);
|
|
3255
|
+
},
|
|
3256
|
+
onComplete: () => {
|
|
3397
3257
|
options.onComplete();
|
|
3398
|
-
|
|
3399
|
-
}
|
|
3258
|
+
valueTransition.onComplete && valueTransition.onComplete();
|
|
3259
|
+
},
|
|
3260
|
+
});
|
|
3400
3261
|
}
|
|
3401
3262
|
function set() {
|
|
3402
|
-
var _a, _b;
|
|
3403
3263
|
const finalTarget = resolveFinalValueInKeyframes(target);
|
|
3404
3264
|
value.set(finalTarget);
|
|
3405
3265
|
onComplete();
|
|
3406
|
-
|
|
3407
|
-
|
|
3266
|
+
valueTransition.onUpdate && valueTransition.onUpdate(finalTarget);
|
|
3267
|
+
valueTransition.onComplete && valueTransition.onComplete();
|
|
3408
3268
|
return { stop: () => { } };
|
|
3409
3269
|
}
|
|
3410
3270
|
return !isOriginAnimatable ||
|
|
@@ -3449,7 +3309,7 @@
|
|
|
3449
3309
|
}
|
|
3450
3310
|
return () => {
|
|
3451
3311
|
clearTimeout(delayTimer);
|
|
3452
|
-
controls
|
|
3312
|
+
controls && controls.stop();
|
|
3453
3313
|
};
|
|
3454
3314
|
});
|
|
3455
3315
|
}
|
|
@@ -3543,7 +3403,7 @@
|
|
|
3543
3403
|
* This will be replaced by the build step with the latest version number.
|
|
3544
3404
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
3545
3405
|
*/
|
|
3546
|
-
this.version = "7.2.
|
|
3406
|
+
this.version = "7.2.1";
|
|
3547
3407
|
/**
|
|
3548
3408
|
* Duration, in milliseconds, since last updating frame.
|
|
3549
3409
|
*
|
|
@@ -3852,6 +3712,27 @@
|
|
|
3852
3712
|
*/
|
|
3853
3713
|
const findValueType = (v) => valueTypes.find(testValueType(v));
|
|
3854
3714
|
|
|
3715
|
+
/**
|
|
3716
|
+
* Creates an object containing the latest state of every MotionValue on a VisualElement
|
|
3717
|
+
*/
|
|
3718
|
+
function getCurrent(visualElement) {
|
|
3719
|
+
const current = {};
|
|
3720
|
+
visualElement.forEachValue((value, key) => (current[key] = value.get()));
|
|
3721
|
+
return current;
|
|
3722
|
+
}
|
|
3723
|
+
/**
|
|
3724
|
+
* Creates an object containing the latest velocity of every MotionValue on a VisualElement
|
|
3725
|
+
*/
|
|
3726
|
+
function getVelocity$1(visualElement) {
|
|
3727
|
+
const velocity = {};
|
|
3728
|
+
visualElement.forEachValue((value, key) => (velocity[key] = value.getVelocity()));
|
|
3729
|
+
return velocity;
|
|
3730
|
+
}
|
|
3731
|
+
function resolveVariant(visualElement, definition, custom) {
|
|
3732
|
+
const props = visualElement.getProps();
|
|
3733
|
+
return resolveVariantFromProps(props, definition, custom !== undefined ? custom : props.custom, getCurrent(visualElement), getVelocity$1(visualElement));
|
|
3734
|
+
}
|
|
3735
|
+
|
|
3855
3736
|
/**
|
|
3856
3737
|
* Set VisualElement's MotionValue, creating a new MotionValue for it if
|
|
3857
3738
|
* it doesn't exist.
|
|
@@ -3866,8 +3747,8 @@
|
|
|
3866
3747
|
}
|
|
3867
3748
|
function setTarget(visualElement, definition) {
|
|
3868
3749
|
const resolved = resolveVariant(visualElement, definition);
|
|
3869
|
-
let
|
|
3870
|
-
target =
|
|
3750
|
+
let { transitionEnd = {}, transition = {}, ...target } = resolved ? visualElement.makeTargetAnimatable(resolved, false) : {};
|
|
3751
|
+
target = { ...target, ...transitionEnd };
|
|
3871
3752
|
for (const key in target) {
|
|
3872
3753
|
const value = resolveFinalValueInKeyframes(target[key]);
|
|
3873
3754
|
setMotionValue(visualElement, key, value);
|
|
@@ -3896,8 +3777,7 @@
|
|
|
3896
3777
|
}
|
|
3897
3778
|
}
|
|
3898
3779
|
function checkTargetForNewValues(visualElement, target, origin) {
|
|
3899
|
-
var _a, _b
|
|
3900
|
-
var _d;
|
|
3780
|
+
var _a, _b;
|
|
3901
3781
|
const newValueKeys = Object.keys(target).filter((key) => !visualElement.hasValue(key));
|
|
3902
3782
|
const numNewValues = newValueKeys.length;
|
|
3903
3783
|
if (!numNewValues)
|
|
@@ -3936,7 +3816,9 @@
|
|
|
3936
3816
|
value = getAnimatableNone(key, targetValue);
|
|
3937
3817
|
}
|
|
3938
3818
|
visualElement.addValue(key, motionValue(value));
|
|
3939
|
-
|
|
3819
|
+
if (origin[key] === undefined) {
|
|
3820
|
+
origin[key] = value;
|
|
3821
|
+
}
|
|
3940
3822
|
visualElement.setBaseTarget(key, value);
|
|
3941
3823
|
}
|
|
3942
3824
|
}
|
|
@@ -3947,11 +3829,14 @@
|
|
|
3947
3829
|
return valueTransition.from;
|
|
3948
3830
|
}
|
|
3949
3831
|
function getOrigin(target, transition, visualElement) {
|
|
3950
|
-
var _a
|
|
3832
|
+
var _a;
|
|
3951
3833
|
const origin = {};
|
|
3952
3834
|
for (const key in target) {
|
|
3835
|
+
const transitionOrigin = getOriginFromTransition(key, transition);
|
|
3953
3836
|
origin[key] =
|
|
3954
|
-
|
|
3837
|
+
transitionOrigin !== undefined
|
|
3838
|
+
? transitionOrigin
|
|
3839
|
+
: (_a = visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.get();
|
|
3955
3840
|
}
|
|
3956
3841
|
return origin;
|
|
3957
3842
|
}
|
|
@@ -4022,7 +3907,7 @@
|
|
|
4022
3907
|
*/
|
|
4023
3908
|
function animateTarget(visualElement, definition, { delay = 0, transitionOverride, type } = {}) {
|
|
4024
3909
|
var _a;
|
|
4025
|
-
let
|
|
3910
|
+
let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = visualElement.makeTargetAnimatable(definition);
|
|
4026
3911
|
const willChange = visualElement.getValue("willChange");
|
|
4027
3912
|
if (transitionOverride)
|
|
4028
3913
|
transition = transitionOverride;
|
|
@@ -4037,12 +3922,16 @@
|
|
|
4037
3922
|
shouldBlockAnimation(animationTypeState, key))) {
|
|
4038
3923
|
continue;
|
|
4039
3924
|
}
|
|
4040
|
-
let valueTransition =
|
|
3925
|
+
let valueTransition = { delay, ...transition };
|
|
4041
3926
|
/**
|
|
4042
3927
|
* Make animation instant if this is a transform prop and we should reduce motion.
|
|
4043
3928
|
*/
|
|
4044
|
-
if (visualElement.shouldReduceMotion &&
|
|
4045
|
-
valueTransition =
|
|
3929
|
+
if (visualElement.shouldReduceMotion && transformProps.has(key)) {
|
|
3930
|
+
valueTransition = {
|
|
3931
|
+
...valueTransition,
|
|
3932
|
+
type: false,
|
|
3933
|
+
delay: 0,
|
|
3934
|
+
};
|
|
4046
3935
|
}
|
|
4047
3936
|
let animation = startAnimation(key, value, valueTarget, valueTransition);
|
|
4048
3937
|
if (isWillChangeMotionValue(willChange)) {
|
|
@@ -4064,7 +3953,10 @@
|
|
|
4064
3953
|
Array.from(visualElement.variantChildren)
|
|
4065
3954
|
.sort(sortByTreeOrder)
|
|
4066
3955
|
.forEach((child, i) => {
|
|
4067
|
-
animations.push(animateVariant(child, variant,
|
|
3956
|
+
animations.push(animateVariant(child, variant, {
|
|
3957
|
+
...options,
|
|
3958
|
+
delay: delayChildren + generateStaggerDuration(i),
|
|
3959
|
+
}).then(() => child.notifyAnimationComplete(variant)));
|
|
4068
3960
|
});
|
|
4069
3961
|
return Promise.all(animations);
|
|
4070
3962
|
}
|
|
@@ -4111,8 +4003,8 @@
|
|
|
4111
4003
|
const buildResolvedTypeValues = (acc, definition) => {
|
|
4112
4004
|
const resolved = resolveVariant(visualElement, definition);
|
|
4113
4005
|
if (resolved) {
|
|
4114
|
-
const { transition, transitionEnd
|
|
4115
|
-
acc =
|
|
4006
|
+
const { transition, transitionEnd, ...target } = resolved;
|
|
4007
|
+
acc = { ...acc, ...target, ...transitionEnd };
|
|
4116
4008
|
}
|
|
4117
4009
|
return acc;
|
|
4118
4010
|
};
|
|
@@ -4195,7 +4087,7 @@
|
|
|
4195
4087
|
* Set all encountered keys so far as the protected keys for this type. This will
|
|
4196
4088
|
* be any key that has been animated or otherwise handled by active, higher-priortiy types.
|
|
4197
4089
|
*/
|
|
4198
|
-
typeState.protectedKeys =
|
|
4090
|
+
typeState.protectedKeys = { ...encounteredKeys };
|
|
4199
4091
|
// Check if we can skip analysing this prop early
|
|
4200
4092
|
if (
|
|
4201
4093
|
// If it isn't active and hasn't *just* been set as inactive
|
|
@@ -4243,7 +4135,10 @@
|
|
|
4243
4135
|
* needs adding to the type's protectedKeys list.
|
|
4244
4136
|
*/
|
|
4245
4137
|
const { prevResolvedValues = {} } = typeState;
|
|
4246
|
-
const allKeys =
|
|
4138
|
+
const allKeys = {
|
|
4139
|
+
...prevResolvedValues,
|
|
4140
|
+
...resolvedValues,
|
|
4141
|
+
};
|
|
4247
4142
|
const markToAnimate = (key) => {
|
|
4248
4143
|
shouldAnimateType = true;
|
|
4249
4144
|
removedKeys.delete(key);
|
|
@@ -4309,7 +4204,7 @@
|
|
|
4309
4204
|
*
|
|
4310
4205
|
*/
|
|
4311
4206
|
if (typeState.isActive) {
|
|
4312
|
-
encounteredKeys =
|
|
4207
|
+
encounteredKeys = { ...encounteredKeys, ...resolvedValues };
|
|
4313
4208
|
}
|
|
4314
4209
|
if (isInitialRender && visualElement.blockInitialAnimation) {
|
|
4315
4210
|
shouldAnimateType = false;
|
|
@@ -4322,7 +4217,7 @@
|
|
|
4322
4217
|
if (shouldAnimateType && !isInherited) {
|
|
4323
4218
|
animations.push(...definitionList.map((animation) => ({
|
|
4324
4219
|
animation: animation,
|
|
4325
|
-
options:
|
|
4220
|
+
options: { type, ...options },
|
|
4326
4221
|
})));
|
|
4327
4222
|
}
|
|
4328
4223
|
}
|
|
@@ -4378,7 +4273,7 @@
|
|
|
4378
4273
|
if (typeof next === "string") {
|
|
4379
4274
|
return next !== prev;
|
|
4380
4275
|
}
|
|
4381
|
-
else if (
|
|
4276
|
+
else if (Array.isArray(next)) {
|
|
4382
4277
|
return !shallowCompare(next, prev);
|
|
4383
4278
|
}
|
|
4384
4279
|
return false;
|
|
@@ -4423,10 +4318,15 @@
|
|
|
4423
4318
|
const [isPresent, safeToRemove] = usePresence();
|
|
4424
4319
|
const presenceContext = React.useContext(PresenceContext);
|
|
4425
4320
|
React.useEffect(() => {
|
|
4426
|
-
var _a, _b;
|
|
4427
4321
|
visualElement.isPresent = isPresent;
|
|
4428
|
-
const animation =
|
|
4429
|
-
|
|
4322
|
+
const animation = visualElement.animationState &&
|
|
4323
|
+
visualElement.animationState.setActive(exports.AnimationType.Exit, !isPresent, {
|
|
4324
|
+
custom: (presenceContext && presenceContext.custom) ||
|
|
4325
|
+
custom,
|
|
4326
|
+
});
|
|
4327
|
+
if (animation && !isPresent) {
|
|
4328
|
+
animation.then(safeToRemove);
|
|
4329
|
+
}
|
|
4430
4330
|
}, [isPresent]);
|
|
4431
4331
|
}),
|
|
4432
4332
|
};
|
|
@@ -4465,7 +4365,7 @@
|
|
|
4465
4365
|
return;
|
|
4466
4366
|
const { point } = info;
|
|
4467
4367
|
const { timestamp } = getFrameData();
|
|
4468
|
-
this.history.push(
|
|
4368
|
+
this.history.push({ ...point, timestamp });
|
|
4469
4369
|
const { onStart, onMove } = this.handlers;
|
|
4470
4370
|
if (!isPanStarted) {
|
|
4471
4371
|
onStart && onStart(this.lastMoveEvent, info);
|
|
@@ -4502,7 +4402,7 @@
|
|
|
4502
4402
|
const initialInfo = transformPoint(info, this.transformPagePoint);
|
|
4503
4403
|
const { point } = initialInfo;
|
|
4504
4404
|
const { timestamp } = getFrameData();
|
|
4505
|
-
this.history = [
|
|
4405
|
+
this.history = [{ ...point, timestamp }];
|
|
4506
4406
|
const { onSessionStart } = handlers;
|
|
4507
4407
|
onSessionStart &&
|
|
4508
4408
|
onSessionStart(event, getPanInfo(initialInfo, this.history));
|
|
@@ -5147,8 +5047,17 @@
|
|
|
5147
5047
|
*/
|
|
5148
5048
|
const bounceStiffness = dragElastic ? 200 : 1000000;
|
|
5149
5049
|
const bounceDamping = dragElastic ? 40 : 10000000;
|
|
5150
|
-
const inertia =
|
|
5151
|
-
|
|
5050
|
+
const inertia = {
|
|
5051
|
+
type: "inertia",
|
|
5052
|
+
velocity: dragMomentum ? velocity[axis] : 0,
|
|
5053
|
+
bounceStiffness,
|
|
5054
|
+
bounceDamping,
|
|
5055
|
+
timeConstant: 750,
|
|
5056
|
+
restDelta: 1,
|
|
5057
|
+
restSpeed: 10,
|
|
5058
|
+
...dragTransition,
|
|
5059
|
+
...transition,
|
|
5060
|
+
};
|
|
5152
5061
|
// If we're not animating on an externally-provided `MotionValue` we can use the
|
|
5153
5062
|
// component's animation controls which will handle interactions with whileHover (etc),
|
|
5154
5063
|
// otherwise we just have to animate the `MotionValue` itself.
|
|
@@ -5300,12 +5209,15 @@
|
|
|
5300
5209
|
getProps() {
|
|
5301
5210
|
const props = this.visualElement.getProps();
|
|
5302
5211
|
const { drag = false, dragDirectionLock = false, dragPropagation = false, dragConstraints = false, dragElastic = defaultElastic, dragMomentum = true, } = props;
|
|
5303
|
-
return
|
|
5212
|
+
return {
|
|
5213
|
+
...props,
|
|
5214
|
+
drag,
|
|
5304
5215
|
dragDirectionLock,
|
|
5305
5216
|
dragPropagation,
|
|
5306
5217
|
dragConstraints,
|
|
5307
5218
|
dragElastic,
|
|
5308
|
-
dragMomentum
|
|
5219
|
+
dragMomentum,
|
|
5220
|
+
};
|
|
5309
5221
|
}
|
|
5310
5222
|
}
|
|
5311
5223
|
function shouldDrag(direction, drag, currentDirection) {
|
|
@@ -5389,6 +5301,25 @@
|
|
|
5389
5301
|
drag: makeRenderlessComponent(useDrag),
|
|
5390
5302
|
};
|
|
5391
5303
|
|
|
5304
|
+
// Does this device prefer reduced motion? Returns `null` server-side.
|
|
5305
|
+
const prefersReducedMotion = { current: null };
|
|
5306
|
+
const hasReducedMotionListener = { current: false };
|
|
5307
|
+
|
|
5308
|
+
function initPrefersReducedMotion() {
|
|
5309
|
+
hasReducedMotionListener.current = true;
|
|
5310
|
+
if (!isBrowser)
|
|
5311
|
+
return;
|
|
5312
|
+
if (window.matchMedia) {
|
|
5313
|
+
const motionMediaQuery = window.matchMedia("(prefers-reduced-motion)");
|
|
5314
|
+
const setReducedMotionPreferences = () => (prefersReducedMotion.current = motionMediaQuery.matches);
|
|
5315
|
+
motionMediaQuery.addListener(setReducedMotionPreferences);
|
|
5316
|
+
setReducedMotionPreferences();
|
|
5317
|
+
}
|
|
5318
|
+
else {
|
|
5319
|
+
prefersReducedMotion.current = false;
|
|
5320
|
+
}
|
|
5321
|
+
}
|
|
5322
|
+
|
|
5392
5323
|
const names = [
|
|
5393
5324
|
"LayoutMeasure",
|
|
5394
5325
|
"BeforeLayoutMeasure",
|
|
@@ -5430,7 +5361,6 @@
|
|
|
5430
5361
|
}
|
|
5431
5362
|
|
|
5432
5363
|
function updateMotionValuesFromProps(element, next, prev) {
|
|
5433
|
-
var _a;
|
|
5434
5364
|
const { willChange } = next;
|
|
5435
5365
|
for (const key in next) {
|
|
5436
5366
|
const nextValue = next[key];
|
|
@@ -5449,7 +5379,7 @@
|
|
|
5449
5379
|
* and warn against mismatches.
|
|
5450
5380
|
*/
|
|
5451
5381
|
{
|
|
5452
|
-
warnOnce(nextValue.version === "7.2.
|
|
5382
|
+
warnOnce(nextValue.version === "7.2.1", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.2.1 may not work as expected.`);
|
|
5453
5383
|
}
|
|
5454
5384
|
}
|
|
5455
5385
|
else if (isMotionValue(prevValue)) {
|
|
@@ -5474,7 +5404,8 @@
|
|
|
5474
5404
|
!existingValue.hasAnimated && existingValue.set(nextValue);
|
|
5475
5405
|
}
|
|
5476
5406
|
else {
|
|
5477
|
-
|
|
5407
|
+
const latestValue = element.getStaticValue(key);
|
|
5408
|
+
element.addValue(key, motionValue(latestValue !== undefined ? latestValue : nextValue));
|
|
5478
5409
|
}
|
|
5479
5410
|
}
|
|
5480
5411
|
}
|
|
@@ -5486,7 +5417,9 @@
|
|
|
5486
5417
|
return next;
|
|
5487
5418
|
}
|
|
5488
5419
|
|
|
5489
|
-
const
|
|
5420
|
+
const featureNames = Object.keys(featureDefinitions);
|
|
5421
|
+
const numFeatures = featureNames.length;
|
|
5422
|
+
const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatable, measureViewportBox, render: renderInstance, readValueFromInstance, removeValueFromRenderState, sortNodePosition, scrapeMotionValuesFromProps, }) => ({ parent, props, presenceId, blockInitialAnimation, visualState, reducedMotionConfig, }, options = {}) => {
|
|
5490
5423
|
let isMounted = false;
|
|
5491
5424
|
const { latestValues, renderState } = visualState;
|
|
5492
5425
|
/**
|
|
@@ -5522,7 +5455,9 @@
|
|
|
5522
5455
|
* When values are removed from all animation props we need to search
|
|
5523
5456
|
* for a fallback value to animate to. These values are tracked in baseTarget.
|
|
5524
5457
|
*/
|
|
5525
|
-
const baseTarget =
|
|
5458
|
+
const baseTarget = {
|
|
5459
|
+
...latestValues,
|
|
5460
|
+
};
|
|
5526
5461
|
// Internal methods ========================
|
|
5527
5462
|
/**
|
|
5528
5463
|
* On mount, this will be hydrated with a callback to disconnect
|
|
@@ -5569,7 +5504,7 @@
|
|
|
5569
5504
|
* Doing so will break some tests but this isn't neccessarily a breaking change,
|
|
5570
5505
|
* more a reflection of the test.
|
|
5571
5506
|
*/
|
|
5572
|
-
const
|
|
5507
|
+
const { willChange, ...initialMotionValues } = scrapeMotionValuesFromProps(props);
|
|
5573
5508
|
for (const key in initialMotionValues) {
|
|
5574
5509
|
const value = initialMotionValues[key];
|
|
5575
5510
|
if (latestValues[key] !== undefined && isMotionValue(value)) {
|
|
@@ -5582,36 +5517,39 @@
|
|
|
5582
5517
|
/**
|
|
5583
5518
|
* Determine what role this visual element should take in the variant tree.
|
|
5584
5519
|
*/
|
|
5585
|
-
const isControllingVariants =
|
|
5586
|
-
const isVariantNode =
|
|
5587
|
-
const element =
|
|
5520
|
+
const isControllingVariants$1 = isControllingVariants(props);
|
|
5521
|
+
const isVariantNode$1 = isVariantNode(props);
|
|
5522
|
+
const element = {
|
|
5523
|
+
treeType,
|
|
5588
5524
|
/**
|
|
5589
5525
|
* This is a mirror of the internal instance prop, which keeps
|
|
5590
5526
|
* VisualElement type-compatible with React's RefObject.
|
|
5591
5527
|
*/
|
|
5592
|
-
current: null,
|
|
5528
|
+
current: null,
|
|
5593
5529
|
/**
|
|
5594
5530
|
* The depth of this visual element within the visual element tree.
|
|
5595
5531
|
*/
|
|
5596
|
-
depth: parent ? parent.depth + 1 : 0,
|
|
5532
|
+
depth: parent ? parent.depth + 1 : 0,
|
|
5533
|
+
parent,
|
|
5534
|
+
children: new Set(),
|
|
5597
5535
|
/**
|
|
5598
5536
|
*
|
|
5599
5537
|
*/
|
|
5600
5538
|
presenceId,
|
|
5601
|
-
shouldReduceMotion,
|
|
5539
|
+
shouldReduceMotion: null,
|
|
5602
5540
|
/**
|
|
5603
5541
|
* If this component is part of the variant tree, it should track
|
|
5604
5542
|
* any children that are also part of the tree. This is essentially
|
|
5605
5543
|
* a shadow tree to simplify logic around how to stagger over children.
|
|
5606
5544
|
*/
|
|
5607
|
-
variantChildren: isVariantNode ? new Set() : undefined,
|
|
5545
|
+
variantChildren: isVariantNode$1 ? new Set() : undefined,
|
|
5608
5546
|
/**
|
|
5609
5547
|
* Whether this instance is visible. This can be changed imperatively
|
|
5610
5548
|
* by the projection tree, is analogous to CSS's visibility in that
|
|
5611
5549
|
* hidden elements should take up layout, and needs enacting by the configured
|
|
5612
5550
|
* render function.
|
|
5613
5551
|
*/
|
|
5614
|
-
isVisible: undefined,
|
|
5552
|
+
isVisible: undefined,
|
|
5615
5553
|
/**
|
|
5616
5554
|
* Normally, if a component is controlled by a parent's variants, it can
|
|
5617
5555
|
* rely on that ancestor to trigger animations further down the tree.
|
|
@@ -5620,27 +5558,37 @@
|
|
|
5620
5558
|
*
|
|
5621
5559
|
* TODO: This might be better replaced with a method isParentMounted
|
|
5622
5560
|
*/
|
|
5623
|
-
manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
|
|
5561
|
+
manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
|
|
5624
5562
|
/**
|
|
5625
5563
|
* This can be set by AnimatePresence to force components that mount
|
|
5626
5564
|
* at the same time as it to mount as if they have initial={false} set.
|
|
5627
5565
|
*/
|
|
5628
|
-
blockInitialAnimation,
|
|
5566
|
+
blockInitialAnimation,
|
|
5629
5567
|
/**
|
|
5630
5568
|
* Determine whether this component has mounted yet. This is mostly used
|
|
5631
5569
|
* by variant children to determine whether they need to trigger their
|
|
5632
5570
|
* own animations on mount.
|
|
5633
5571
|
*/
|
|
5634
|
-
isMounted: () => Boolean(instance),
|
|
5572
|
+
isMounted: () => Boolean(instance),
|
|
5573
|
+
mount(newInstance) {
|
|
5635
5574
|
isMounted = true;
|
|
5636
5575
|
instance = element.current = newInstance;
|
|
5637
5576
|
if (element.projection) {
|
|
5638
5577
|
element.projection.mount(newInstance);
|
|
5639
5578
|
}
|
|
5640
|
-
if (isVariantNode && parent && !isControllingVariants) {
|
|
5579
|
+
if (isVariantNode$1 && parent && !isControllingVariants$1) {
|
|
5641
5580
|
removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
|
|
5642
5581
|
}
|
|
5643
5582
|
values.forEach((value, key) => bindToMotionValue(key, value));
|
|
5583
|
+
if (!hasReducedMotionListener.current) {
|
|
5584
|
+
initPrefersReducedMotion();
|
|
5585
|
+
}
|
|
5586
|
+
element.shouldReduceMotion =
|
|
5587
|
+
reducedMotionConfig === "never"
|
|
5588
|
+
? false
|
|
5589
|
+
: reducedMotionConfig === "always"
|
|
5590
|
+
? true
|
|
5591
|
+
: prefersReducedMotion.current;
|
|
5644
5592
|
parent === null || parent === void 0 ? void 0 : parent.children.add(element);
|
|
5645
5593
|
element.setProps(props);
|
|
5646
5594
|
},
|
|
@@ -5659,6 +5607,55 @@
|
|
|
5659
5607
|
instance = undefined;
|
|
5660
5608
|
isMounted = false;
|
|
5661
5609
|
},
|
|
5610
|
+
loadFeatures(renderedProps, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
|
|
5611
|
+
const features = [];
|
|
5612
|
+
/**
|
|
5613
|
+
* If we're in development mode, check to make sure we're not rendering a motion component
|
|
5614
|
+
* as a child of LazyMotion, as this will break the file-size benefits of using it.
|
|
5615
|
+
*/
|
|
5616
|
+
if (env !== "production" && preloadedFeatures && isStrict) {
|
|
5617
|
+
invariant(false, "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.");
|
|
5618
|
+
}
|
|
5619
|
+
for (let i = 0; i < numFeatures; i++) {
|
|
5620
|
+
const name = featureNames[i];
|
|
5621
|
+
const { isEnabled, Component } = featureDefinitions[name];
|
|
5622
|
+
/**
|
|
5623
|
+
* It might be possible in the future to use this moment to
|
|
5624
|
+
* dynamically request functionality. In initial tests this
|
|
5625
|
+
* was producing a lot of duplication amongst bundles.
|
|
5626
|
+
*/
|
|
5627
|
+
if (isEnabled(props) && Component) {
|
|
5628
|
+
features.push(React.createElement(Component, {
|
|
5629
|
+
key: name,
|
|
5630
|
+
...renderedProps,
|
|
5631
|
+
visualElement: element,
|
|
5632
|
+
}));
|
|
5633
|
+
}
|
|
5634
|
+
}
|
|
5635
|
+
if (!element.projection && ProjectionNodeConstructor) {
|
|
5636
|
+
element.projection = new ProjectionNodeConstructor(projectionId, element.getLatestValues(), parent && parent.projection);
|
|
5637
|
+
const { layoutId, layout, drag, dragConstraints, layoutScroll, } = renderedProps;
|
|
5638
|
+
element.projection.setOptions({
|
|
5639
|
+
layoutId,
|
|
5640
|
+
layout,
|
|
5641
|
+
alwaysMeasureLayout: Boolean(drag) ||
|
|
5642
|
+
(dragConstraints && isRefObject(dragConstraints)),
|
|
5643
|
+
visualElement: element,
|
|
5644
|
+
scheduleRender: () => element.scheduleRender(),
|
|
5645
|
+
/**
|
|
5646
|
+
* TODO: Update options in an effect. This could be tricky as it'll be too late
|
|
5647
|
+
* to update by the time layout animations run.
|
|
5648
|
+
* We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
|
|
5649
|
+
* ensuring it gets called if there's no potential layout animations.
|
|
5650
|
+
*
|
|
5651
|
+
*/
|
|
5652
|
+
animationType: typeof layout === "string" ? layout : "both",
|
|
5653
|
+
initialPromotionConfig: initialLayoutGroupConfig,
|
|
5654
|
+
layoutScroll,
|
|
5655
|
+
});
|
|
5656
|
+
}
|
|
5657
|
+
return features;
|
|
5658
|
+
},
|
|
5662
5659
|
/**
|
|
5663
5660
|
* Add a child visual element to our set of children.
|
|
5664
5661
|
*/
|
|
@@ -5677,30 +5674,31 @@
|
|
|
5677
5674
|
if (!sortNodePosition || treeType !== other.treeType)
|
|
5678
5675
|
return 0;
|
|
5679
5676
|
return sortNodePosition(element.getInstance(), other.getInstance());
|
|
5680
|
-
},
|
|
5677
|
+
},
|
|
5681
5678
|
/**
|
|
5682
5679
|
* Returns the closest variant node in the tree starting from
|
|
5683
5680
|
* this visual element.
|
|
5684
5681
|
*/
|
|
5685
|
-
getClosestVariantNode: () => isVariantNode ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
|
|
5682
|
+
getClosestVariantNode: () => isVariantNode$1 ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
|
|
5686
5683
|
/**
|
|
5687
5684
|
* Expose the latest layoutId prop.
|
|
5688
5685
|
*/
|
|
5689
|
-
getLayoutId: () => props.layoutId,
|
|
5686
|
+
getLayoutId: () => props.layoutId,
|
|
5690
5687
|
/**
|
|
5691
5688
|
* Returns the current instance.
|
|
5692
5689
|
*/
|
|
5693
|
-
getInstance: () => instance,
|
|
5690
|
+
getInstance: () => instance,
|
|
5694
5691
|
/**
|
|
5695
5692
|
* Get/set the latest static values.
|
|
5696
5693
|
*/
|
|
5697
|
-
getStaticValue: (key) => latestValues[key],
|
|
5694
|
+
getStaticValue: (key) => latestValues[key],
|
|
5695
|
+
setStaticValue: (key, value) => (latestValues[key] = value),
|
|
5698
5696
|
/**
|
|
5699
5697
|
* Returns the latest motion value state. Currently only used to take
|
|
5700
5698
|
* a snapshot of the visual element - perhaps this can return the whole
|
|
5701
5699
|
* visual state
|
|
5702
5700
|
*/
|
|
5703
|
-
getLatestValues: () => latestValues,
|
|
5701
|
+
getLatestValues: () => latestValues,
|
|
5704
5702
|
/**
|
|
5705
5703
|
* Set the visiblity of the visual element. If it's changed, schedule
|
|
5706
5704
|
* a render to reflect these changes.
|
|
@@ -5751,11 +5749,11 @@
|
|
|
5751
5749
|
valueSubscriptions.delete(key);
|
|
5752
5750
|
delete latestValues[key];
|
|
5753
5751
|
removeValueFromRenderState(key, renderState);
|
|
5754
|
-
},
|
|
5752
|
+
},
|
|
5755
5753
|
/**
|
|
5756
5754
|
* Check whether we have a motion value for this key
|
|
5757
5755
|
*/
|
|
5758
|
-
hasValue: (key) => values.has(key),
|
|
5756
|
+
hasValue: (key) => values.has(key),
|
|
5759
5757
|
/**
|
|
5760
5758
|
* Get a motion value for this key. If called with a default
|
|
5761
5759
|
* value, we'll create one if none exists.
|
|
@@ -5767,20 +5765,19 @@
|
|
|
5767
5765
|
element.addValue(key, value);
|
|
5768
5766
|
}
|
|
5769
5767
|
return value;
|
|
5770
|
-
},
|
|
5768
|
+
},
|
|
5771
5769
|
/**
|
|
5772
5770
|
* Iterate over our motion values.
|
|
5773
5771
|
*/
|
|
5774
|
-
forEachValue: (callback) => values.forEach(callback),
|
|
5772
|
+
forEachValue: (callback) => values.forEach(callback),
|
|
5775
5773
|
/**
|
|
5776
5774
|
* If we're trying to animate to a previously unencountered value,
|
|
5777
5775
|
* we need to check for it in our state and as a last resort read it
|
|
5778
5776
|
* directly from the instance (which might have performance implications).
|
|
5779
5777
|
*/
|
|
5780
|
-
readValue: (key) =>
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
},
|
|
5778
|
+
readValue: (key) => latestValues[key] !== undefined
|
|
5779
|
+
? latestValues[key]
|
|
5780
|
+
: readValueFromInstance(instance, key, options),
|
|
5784
5781
|
/**
|
|
5785
5782
|
* Set the base target to later animate back to. This is currently
|
|
5786
5783
|
* only hydrated on creation and when we first read a value.
|
|
@@ -5799,7 +5796,9 @@
|
|
|
5799
5796
|
return target;
|
|
5800
5797
|
}
|
|
5801
5798
|
return baseTarget[key];
|
|
5802
|
-
}
|
|
5799
|
+
},
|
|
5800
|
+
// Lifecyles ========================
|
|
5801
|
+
...lifecycles,
|
|
5803
5802
|
/**
|
|
5804
5803
|
* Build the renderer state based on the latest visual state.
|
|
5805
5804
|
*/
|
|
@@ -5812,14 +5811,14 @@
|
|
|
5812
5811
|
*/
|
|
5813
5812
|
scheduleRender() {
|
|
5814
5813
|
sync.render(render, false, true);
|
|
5815
|
-
},
|
|
5814
|
+
},
|
|
5816
5815
|
/**
|
|
5817
5816
|
* Synchronously fire render. It's prefered that we batch renders but
|
|
5818
5817
|
* in many circumstances, like layout measurement, we need to run this
|
|
5819
5818
|
* synchronously. However in those instances other measures should be taken
|
|
5820
5819
|
* to batch reads/writes.
|
|
5821
5820
|
*/
|
|
5822
|
-
syncRender: render,
|
|
5821
|
+
syncRender: render,
|
|
5823
5822
|
/**
|
|
5824
5823
|
* Update the provided props. Ensure any newly-added motion values are
|
|
5825
5824
|
* added to our map, old ones removed, and listeners updated.
|
|
@@ -5831,25 +5830,27 @@
|
|
|
5831
5830
|
props = newProps;
|
|
5832
5831
|
lifecycles.updatePropListeners(newProps);
|
|
5833
5832
|
prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
|
|
5834
|
-
},
|
|
5833
|
+
},
|
|
5834
|
+
getProps: () => props,
|
|
5835
5835
|
// Variants ==============================
|
|
5836
5836
|
/**
|
|
5837
5837
|
* Returns the variant definition with a given name.
|
|
5838
5838
|
*/
|
|
5839
|
-
getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
5839
|
+
getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
5840
5840
|
/**
|
|
5841
5841
|
* Returns the defined default transition on this component.
|
|
5842
5842
|
*/
|
|
5843
|
-
getDefaultTransition: () => props.transition,
|
|
5843
|
+
getDefaultTransition: () => props.transition,
|
|
5844
|
+
getTransformPagePoint: () => {
|
|
5844
5845
|
return props.transformPagePoint;
|
|
5845
|
-
},
|
|
5846
|
+
},
|
|
5846
5847
|
/**
|
|
5847
5848
|
* Used by child variant nodes to get the closest ancestor variant props.
|
|
5848
5849
|
*/
|
|
5849
5850
|
getVariantContext(startAtParent = false) {
|
|
5850
5851
|
if (startAtParent)
|
|
5851
5852
|
return parent === null || parent === void 0 ? void 0 : parent.getVariantContext();
|
|
5852
|
-
if (!isControllingVariants) {
|
|
5853
|
+
if (!isControllingVariants$1) {
|
|
5853
5854
|
const context = (parent === null || parent === void 0 ? void 0 : parent.getVariantContext()) || {};
|
|
5854
5855
|
if (props.initial !== undefined) {
|
|
5855
5856
|
context.initial = props.initial;
|
|
@@ -5865,7 +5866,8 @@
|
|
|
5865
5866
|
}
|
|
5866
5867
|
}
|
|
5867
5868
|
return context;
|
|
5868
|
-
}
|
|
5869
|
+
},
|
|
5870
|
+
};
|
|
5869
5871
|
return element;
|
|
5870
5872
|
};
|
|
5871
5873
|
const variantProps = ["initial", ...variantPriorityOrder];
|
|
@@ -5916,16 +5918,14 @@
|
|
|
5916
5918
|
*
|
|
5917
5919
|
* @internal
|
|
5918
5920
|
*/
|
|
5919
|
-
function resolveCSSVariables(visualElement,
|
|
5920
|
-
var _b;
|
|
5921
|
-
var target = __rest(_a, []);
|
|
5921
|
+
function resolveCSSVariables(visualElement, { ...target }, transitionEnd) {
|
|
5922
5922
|
const element = visualElement.getInstance();
|
|
5923
5923
|
if (!(element instanceof Element))
|
|
5924
5924
|
return { target, transitionEnd };
|
|
5925
5925
|
// If `transitionEnd` isn't `undefined`, clone it. We could clone `target` and `transitionEnd`
|
|
5926
5926
|
// only if they change but I think this reads clearer and this isn't a performance-critical path.
|
|
5927
5927
|
if (transitionEnd) {
|
|
5928
|
-
transitionEnd =
|
|
5928
|
+
transitionEnd = { ...transitionEnd };
|
|
5929
5929
|
}
|
|
5930
5930
|
// Go through existing `MotionValue`s and ensure any existing CSS variables are resolved
|
|
5931
5931
|
visualElement.forEachValue((value) => {
|
|
@@ -5950,8 +5950,9 @@
|
|
|
5950
5950
|
// If the user hasn't already set this key on `transitionEnd`, set it to the unresolved
|
|
5951
5951
|
// CSS variable. This will ensure that after the animation the component will reflect
|
|
5952
5952
|
// changes in the value of the CSS variable.
|
|
5953
|
-
if (transitionEnd)
|
|
5954
|
-
|
|
5953
|
+
if (transitionEnd && transitionEnd[key] === undefined) {
|
|
5954
|
+
transitionEnd[key] = current;
|
|
5955
|
+
}
|
|
5955
5956
|
}
|
|
5956
5957
|
return { target, transitionEnd };
|
|
5957
5958
|
}
|
|
@@ -6005,7 +6006,7 @@
|
|
|
6005
6006
|
}
|
|
6006
6007
|
};
|
|
6007
6008
|
const transformKeys = new Set(["x", "y", "z"]);
|
|
6008
|
-
const nonTranslationalTransformKeys =
|
|
6009
|
+
const nonTranslationalTransformKeys = transformPropOrder.filter((key) => !transformKeys.has(key));
|
|
6009
6010
|
function removeNonTranslationalTransform(visualElement) {
|
|
6010
6011
|
const removedTransforms = [];
|
|
6011
6012
|
nonTranslationalTransformKeys.forEach((key) => {
|
|
@@ -6062,8 +6063,8 @@
|
|
|
6062
6063
|
return target;
|
|
6063
6064
|
};
|
|
6064
6065
|
const checkAndConvertChangedValueTypes = (visualElement, target, origin = {}, transitionEnd = {}) => {
|
|
6065
|
-
target =
|
|
6066
|
-
transitionEnd =
|
|
6066
|
+
target = { ...target };
|
|
6067
|
+
transitionEnd = { ...transitionEnd };
|
|
6067
6068
|
const targetPositionalKeys = Object.keys(target).filter(isPositionalKey);
|
|
6068
6069
|
// We want to remove any transform values that could affect the element's bounding box before
|
|
6069
6070
|
// it's measured. We'll reapply these later.
|
|
@@ -6198,7 +6199,7 @@
|
|
|
6198
6199
|
const htmlConfig = {
|
|
6199
6200
|
treeType: "dom",
|
|
6200
6201
|
readValueFromInstance(domElement, key) {
|
|
6201
|
-
if (
|
|
6202
|
+
if (transformProps.has(key)) {
|
|
6202
6203
|
const defaultType = getDefaultValueType(key);
|
|
6203
6204
|
return defaultType ? defaultType.default || 0 : 0;
|
|
6204
6205
|
}
|
|
@@ -6251,10 +6252,7 @@
|
|
|
6251
6252
|
* Ensure that HTML and Framer-specific value types like `px`->`%` and `Color`
|
|
6252
6253
|
* can be animated by Motion.
|
|
6253
6254
|
*/
|
|
6254
|
-
makeTargetAnimatable(element,
|
|
6255
|
-
var { transition, transitionEnd } = _a, target = __rest(_a, ["transition", "transitionEnd"]);
|
|
6256
|
-
var transformValues = _b.transformValues;
|
|
6257
|
-
if (isMounted === void 0) { isMounted = true; }
|
|
6255
|
+
makeTargetAnimatable(element, { transition, transitionEnd, ...target }, { transformValues }, isMounted = true) {
|
|
6258
6256
|
let origin = getOrigin(target, transition || {}, element);
|
|
6259
6257
|
/**
|
|
6260
6258
|
* If Framer has provided a function to convert `Color` etc value types, convert them
|
|
@@ -6273,8 +6271,11 @@
|
|
|
6273
6271
|
transitionEnd = parsed.transitionEnd;
|
|
6274
6272
|
target = parsed.target;
|
|
6275
6273
|
}
|
|
6276
|
-
return
|
|
6277
|
-
|
|
6274
|
+
return {
|
|
6275
|
+
transition,
|
|
6276
|
+
transitionEnd,
|
|
6277
|
+
...target,
|
|
6278
|
+
};
|
|
6278
6279
|
},
|
|
6279
6280
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps$1,
|
|
6280
6281
|
build(element, renderState, latestValues, options, props) {
|
|
@@ -6289,12 +6290,14 @@
|
|
|
6289
6290
|
};
|
|
6290
6291
|
const htmlVisualElement = visualElement(htmlConfig);
|
|
6291
6292
|
|
|
6292
|
-
const svgVisualElement = visualElement(
|
|
6293
|
+
const svgVisualElement = visualElement({
|
|
6294
|
+
...htmlConfig,
|
|
6295
|
+
getBaseTarget(props, key) {
|
|
6293
6296
|
return props[key];
|
|
6294
6297
|
},
|
|
6295
6298
|
readValueFromInstance(domElement, key) {
|
|
6296
6299
|
var _a;
|
|
6297
|
-
if (
|
|
6300
|
+
if (transformProps.has(key)) {
|
|
6298
6301
|
return ((_a = getDefaultValueType(key)) === null || _a === void 0 ? void 0 : _a.default) || 0;
|
|
6299
6302
|
}
|
|
6300
6303
|
key = !camelCaseAttributes.has(key) ? camelToDash(key) : key;
|
|
@@ -6303,7 +6306,9 @@
|
|
|
6303
6306
|
scrapeMotionValuesFromProps,
|
|
6304
6307
|
build(_element, renderState, latestValues, options, props) {
|
|
6305
6308
|
buildSVGAttrs(renderState, latestValues, options, props.transformTemplate);
|
|
6306
|
-
},
|
|
6309
|
+
},
|
|
6310
|
+
render: renderSVG,
|
|
6311
|
+
});
|
|
6307
6312
|
|
|
6308
6313
|
const createDomVisualElement = (Component, options) => {
|
|
6309
6314
|
return isSVGComponent(Component)
|
|
@@ -6412,16 +6417,19 @@
|
|
|
6412
6417
|
const { projection } = visualElement;
|
|
6413
6418
|
addScaleCorrector(defaultScaleCorrectors);
|
|
6414
6419
|
if (projection) {
|
|
6415
|
-
if (layoutGroup
|
|
6420
|
+
if (layoutGroup.group)
|
|
6416
6421
|
layoutGroup.group.add(projection);
|
|
6417
|
-
if (
|
|
6422
|
+
if (switchLayoutGroup && switchLayoutGroup.register && layoutId) {
|
|
6418
6423
|
switchLayoutGroup.register(projection);
|
|
6419
6424
|
}
|
|
6420
6425
|
projection.root.didUpdate();
|
|
6421
6426
|
projection.addEventListener("animationComplete", () => {
|
|
6422
6427
|
this.safeToRemove();
|
|
6423
6428
|
});
|
|
6424
|
-
projection.setOptions(
|
|
6429
|
+
projection.setOptions({
|
|
6430
|
+
...projection.options,
|
|
6431
|
+
onExitComplete: () => this.safeToRemove(),
|
|
6432
|
+
});
|
|
6425
6433
|
}
|
|
6426
6434
|
globalProjectionState.hasEverUpdated = true;
|
|
6427
6435
|
}
|
|
@@ -6497,15 +6505,18 @@
|
|
|
6497
6505
|
function MeasureLayout(props) {
|
|
6498
6506
|
const [isPresent, safeToRemove] = usePresence();
|
|
6499
6507
|
const layoutGroup = React.useContext(LayoutGroupContext);
|
|
6500
|
-
return (React__default["default"].createElement(MeasureLayoutWithContext,
|
|
6508
|
+
return (React__default["default"].createElement(MeasureLayoutWithContext, { ...props, layoutGroup: layoutGroup, switchLayoutGroup: React.useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove }));
|
|
6501
6509
|
}
|
|
6502
6510
|
const defaultScaleCorrectors = {
|
|
6503
|
-
borderRadius:
|
|
6511
|
+
borderRadius: {
|
|
6512
|
+
...correctBorderRadius,
|
|
6513
|
+
applyTo: [
|
|
6504
6514
|
"borderTopLeftRadius",
|
|
6505
6515
|
"borderTopRightRadius",
|
|
6506
6516
|
"borderBottomLeftRadius",
|
|
6507
6517
|
"borderBottomRightRadius",
|
|
6508
|
-
]
|
|
6518
|
+
],
|
|
6519
|
+
},
|
|
6509
6520
|
borderTopLeftRadius: correctBorderRadius,
|
|
6510
6521
|
borderTopRightRadius: correctBorderRadius,
|
|
6511
6522
|
borderBottomLeftRadius: correctBorderRadius,
|
|
@@ -6886,6 +6897,7 @@
|
|
|
6886
6897
|
}
|
|
6887
6898
|
}
|
|
6888
6899
|
|
|
6900
|
+
const transformAxes = ["", "X", "Y", "Z"];
|
|
6889
6901
|
/**
|
|
6890
6902
|
* We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
|
|
6891
6903
|
* which has a noticeable difference in spring animations
|
|
@@ -7077,7 +7089,11 @@
|
|
|
7077
7089
|
this.resumingFrom.resumingFrom = undefined;
|
|
7078
7090
|
}
|
|
7079
7091
|
this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
|
|
7080
|
-
const animationOptions =
|
|
7092
|
+
const animationOptions = {
|
|
7093
|
+
...getValueTransition(layoutTransition, "layout"),
|
|
7094
|
+
onPlay: onLayoutAnimationStart,
|
|
7095
|
+
onComplete: onLayoutAnimationComplete,
|
|
7096
|
+
};
|
|
7081
7097
|
if (visualElement.shouldReduceMotion) {
|
|
7082
7098
|
animationOptions.delay = 0;
|
|
7083
7099
|
animationOptions.type = false;
|
|
@@ -7400,8 +7416,11 @@
|
|
|
7400
7416
|
this.root.scheduleUpdateProjection();
|
|
7401
7417
|
}
|
|
7402
7418
|
setOptions(options) {
|
|
7403
|
-
|
|
7404
|
-
|
|
7419
|
+
this.options = {
|
|
7420
|
+
...this.options,
|
|
7421
|
+
...options,
|
|
7422
|
+
crossfade: options.crossfade !== undefined ? options.crossfade : true,
|
|
7423
|
+
};
|
|
7405
7424
|
}
|
|
7406
7425
|
clearMeasurements() {
|
|
7407
7426
|
this.scroll = undefined;
|
|
@@ -7583,7 +7602,7 @@
|
|
|
7583
7602
|
var _a;
|
|
7584
7603
|
const snapshot = this.snapshot;
|
|
7585
7604
|
const snapshotLatestValues = (snapshot === null || snapshot === void 0 ? void 0 : snapshot.latestValues) || {};
|
|
7586
|
-
const mixedValues =
|
|
7605
|
+
const mixedValues = { ...this.latestValues };
|
|
7587
7606
|
const targetDelta = createDelta();
|
|
7588
7607
|
this.relativeTarget = this.relativeTargetOrigin = undefined;
|
|
7589
7608
|
this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
|
|
@@ -7636,15 +7655,19 @@
|
|
|
7636
7655
|
*/
|
|
7637
7656
|
this.pendingAnimation = sync.update(() => {
|
|
7638
7657
|
globalProjectionState.hasAnimatedSinceResize = true;
|
|
7639
|
-
this.currentAnimation = animate(0, animationTarget,
|
|
7658
|
+
this.currentAnimation = animate(0, animationTarget, {
|
|
7659
|
+
...options,
|
|
7660
|
+
onUpdate: (latest) => {
|
|
7640
7661
|
var _a;
|
|
7641
7662
|
this.mixTargetDelta(latest);
|
|
7642
7663
|
(_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, latest);
|
|
7643
|
-
},
|
|
7664
|
+
},
|
|
7665
|
+
onComplete: () => {
|
|
7644
7666
|
var _a;
|
|
7645
7667
|
(_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
7646
7668
|
this.completeAnimation();
|
|
7647
|
-
}
|
|
7669
|
+
},
|
|
7670
|
+
});
|
|
7648
7671
|
if (this.resumingFrom) {
|
|
7649
7672
|
this.resumingFrom.currentAnimation = this.currentAnimation;
|
|
7650
7673
|
}
|
|
@@ -7779,7 +7802,7 @@
|
|
|
7779
7802
|
visualElement.scheduleRender();
|
|
7780
7803
|
}
|
|
7781
7804
|
getProjectionStyles(styleProp = {}) {
|
|
7782
|
-
var _a, _b, _c
|
|
7805
|
+
var _a, _b, _c;
|
|
7783
7806
|
// TODO: Return lifecycle-persistent object
|
|
7784
7807
|
const styles = {};
|
|
7785
7808
|
if (!this.instance || this.isSVG)
|
|
@@ -7805,7 +7828,10 @@
|
|
|
7805
7828
|
if (!this.projectionDelta || !this.layout || !lead.target) {
|
|
7806
7829
|
const emptyStyles = {};
|
|
7807
7830
|
if (this.options.layoutId) {
|
|
7808
|
-
emptyStyles.opacity =
|
|
7831
|
+
emptyStyles.opacity =
|
|
7832
|
+
this.latestValues.opacity !== undefined
|
|
7833
|
+
? this.latestValues.opacity
|
|
7834
|
+
: 1;
|
|
7809
7835
|
emptyStyles.pointerEvents =
|
|
7810
7836
|
resolveMotionValue(styleProp.pointerEvents) || "";
|
|
7811
7837
|
}
|
|
@@ -7832,7 +7858,7 @@
|
|
|
7832
7858
|
*/
|
|
7833
7859
|
styles.opacity =
|
|
7834
7860
|
lead === this
|
|
7835
|
-
? (
|
|
7861
|
+
? (_c = (_b = valuesToRender.opacity) !== null && _b !== void 0 ? _b : this.latestValues.opacity) !== null && _c !== void 0 ? _c : 1
|
|
7836
7862
|
: this.preserveOpacity
|
|
7837
7863
|
? this.latestValues.opacity
|
|
7838
7864
|
: valuesToRender.opacityExit;
|
|
@@ -7844,8 +7870,12 @@
|
|
|
7844
7870
|
*/
|
|
7845
7871
|
styles.opacity =
|
|
7846
7872
|
lead === this
|
|
7847
|
-
?
|
|
7848
|
-
|
|
7873
|
+
? valuesToRender.opacity !== undefined
|
|
7874
|
+
? valuesToRender.opacity
|
|
7875
|
+
: ""
|
|
7876
|
+
: valuesToRender.opacityExit !== undefined
|
|
7877
|
+
? valuesToRender.opacityExit
|
|
7878
|
+
: 0;
|
|
7849
7879
|
}
|
|
7850
7880
|
/**
|
|
7851
7881
|
* Apply scale correction
|
|
@@ -7893,8 +7923,8 @@
|
|
|
7893
7923
|
node.updateLayout();
|
|
7894
7924
|
}
|
|
7895
7925
|
function notifyLayoutUpdate(node) {
|
|
7896
|
-
var _a, _b, _c
|
|
7897
|
-
const snapshot = (
|
|
7926
|
+
var _a, _b, _c;
|
|
7927
|
+
const snapshot = ((_a = node.resumeFrom) === null || _a === void 0 ? void 0 : _a.snapshot) || node.snapshot;
|
|
7898
7928
|
if (node.isLead() &&
|
|
7899
7929
|
node.layout &&
|
|
7900
7930
|
snapshot &&
|
|
@@ -7961,7 +7991,7 @@
|
|
|
7961
7991
|
});
|
|
7962
7992
|
}
|
|
7963
7993
|
else if (node.isLead()) {
|
|
7964
|
-
(
|
|
7994
|
+
(_c = (_b = node.options).onExitComplete) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
7965
7995
|
}
|
|
7966
7996
|
/**
|
|
7967
7997
|
* Clearing transition
|
|
@@ -8073,12 +8103,17 @@
|
|
|
8073
8103
|
return rootProjectionNode.current;
|
|
8074
8104
|
},
|
|
8075
8105
|
resetTransform: (instance, value) => {
|
|
8076
|
-
instance.style.transform = value !==
|
|
8106
|
+
instance.style.transform = value !== undefined ? value : "none";
|
|
8077
8107
|
},
|
|
8078
8108
|
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
8079
8109
|
});
|
|
8080
8110
|
|
|
8081
|
-
const featureBundle =
|
|
8111
|
+
const featureBundle = {
|
|
8112
|
+
...animations,
|
|
8113
|
+
...gestureAnimations,
|
|
8114
|
+
...drag,
|
|
8115
|
+
...layoutFeatures,
|
|
8116
|
+
};
|
|
8082
8117
|
/**
|
|
8083
8118
|
* HTML & SVG components, optimised for use with gestures and animation. These can be used as
|
|
8084
8119
|
* drop-in replacements for any HTML & SVG component, all CSS & SVG properties are supported.
|
|
@@ -8178,14 +8213,14 @@
|
|
|
8178
8213
|
* styles set via the style prop.
|
|
8179
8214
|
*/
|
|
8180
8215
|
React.useInsertionEffect(() => {
|
|
8181
|
-
var _a;
|
|
8182
8216
|
const { width, height, top, left } = size.current;
|
|
8183
8217
|
if (isPresent || !ref.current || !width || !height)
|
|
8184
8218
|
return;
|
|
8185
8219
|
ref.current.dataset.motionPopId = id;
|
|
8186
8220
|
const style = document.createElement("style");
|
|
8187
8221
|
document.head.appendChild(style);
|
|
8188
|
-
(
|
|
8222
|
+
if (style.sheet) {
|
|
8223
|
+
style.sheet.insertRule(`
|
|
8189
8224
|
[data-motion-pop-id="${id}"] {
|
|
8190
8225
|
position: absolute !important;
|
|
8191
8226
|
width: ${width}px !important;
|
|
@@ -8194,6 +8229,7 @@
|
|
|
8194
8229
|
left: ${left}px !important;
|
|
8195
8230
|
}
|
|
8196
8231
|
`);
|
|
8232
|
+
}
|
|
8197
8233
|
return () => {
|
|
8198
8234
|
document.head.removeChild(style);
|
|
8199
8235
|
};
|
|
@@ -8215,7 +8251,7 @@
|
|
|
8215
8251
|
if (!isComplete)
|
|
8216
8252
|
return; // can stop searching when any is incomplete
|
|
8217
8253
|
}
|
|
8218
|
-
onExitComplete
|
|
8254
|
+
onExitComplete && onExitComplete();
|
|
8219
8255
|
},
|
|
8220
8256
|
register: (childId) => {
|
|
8221
8257
|
presenceChildren.set(childId, false);
|
|
@@ -8236,7 +8272,10 @@
|
|
|
8236
8272
|
* component immediately.
|
|
8237
8273
|
*/
|
|
8238
8274
|
React__namespace.useEffect(() => {
|
|
8239
|
-
!isPresent &&
|
|
8275
|
+
!isPresent &&
|
|
8276
|
+
!presenceChildren.size &&
|
|
8277
|
+
onExitComplete &&
|
|
8278
|
+
onExitComplete();
|
|
8240
8279
|
}, [isPresent]);
|
|
8241
8280
|
if (mode === "popLayout") {
|
|
8242
8281
|
children = React__namespace.createElement(PopChild, { isPresent: isPresent }, children);
|
|
@@ -8424,8 +8463,7 @@
|
|
|
8424
8463
|
|
|
8425
8464
|
const shouldInheritGroup = (inherit) => inherit === true;
|
|
8426
8465
|
const shouldInheritId = (inherit) => shouldInheritGroup(inherit === true) || inherit === "id";
|
|
8427
|
-
const LayoutGroup = ({ children, id, inheritId, inherit = true
|
|
8428
|
-
var _a, _b;
|
|
8466
|
+
const LayoutGroup = ({ children, id, inheritId, inherit = true }) => {
|
|
8429
8467
|
// Maintain backwards-compatibility with inheritId until 7.0
|
|
8430
8468
|
if (inheritId !== undefined)
|
|
8431
8469
|
inherit = inheritId;
|
|
@@ -8433,7 +8471,7 @@
|
|
|
8433
8471
|
const deprecatedLayoutGroupContext = React.useContext(DeprecatedLayoutGroupContext);
|
|
8434
8472
|
const [forceRender, key] = useForceUpdate();
|
|
8435
8473
|
const context = React.useRef(null);
|
|
8436
|
-
const upstreamId =
|
|
8474
|
+
const upstreamId = layoutGroupContext.id || deprecatedLayoutGroupContext;
|
|
8437
8475
|
if (context.current === null) {
|
|
8438
8476
|
if (shouldInheritId(inherit) && upstreamId) {
|
|
8439
8477
|
id = id ? upstreamId + "-" + id : upstreamId;
|
|
@@ -8441,11 +8479,11 @@
|
|
|
8441
8479
|
context.current = {
|
|
8442
8480
|
id,
|
|
8443
8481
|
group: shouldInheritGroup(inherit)
|
|
8444
|
-
?
|
|
8482
|
+
? layoutGroupContext.group || nodeGroup()
|
|
8445
8483
|
: nodeGroup(),
|
|
8446
8484
|
};
|
|
8447
8485
|
}
|
|
8448
|
-
const memoizedContext = React.useMemo(() => (
|
|
8486
|
+
const memoizedContext = React.useMemo(() => ({ ...context.current, forceRender }), [key]);
|
|
8449
8487
|
return (React__namespace.createElement(LayoutGroupContext.Provider, { value: memoizedContext }, children));
|
|
8450
8488
|
};
|
|
8451
8489
|
|
|
@@ -8474,13 +8512,12 @@
|
|
|
8474
8512
|
*
|
|
8475
8513
|
* @public
|
|
8476
8514
|
*/
|
|
8477
|
-
function MotionConfig(
|
|
8478
|
-
var { children, isValidProp } = _a, config = __rest(_a, ["children", "isValidProp"]);
|
|
8515
|
+
function MotionConfig({ children, isValidProp, ...config }) {
|
|
8479
8516
|
isValidProp && loadExternalIsValidProp(isValidProp);
|
|
8480
8517
|
/**
|
|
8481
8518
|
* Inherit props from any parent MotionConfig components
|
|
8482
8519
|
*/
|
|
8483
|
-
config =
|
|
8520
|
+
config = { ...React.useContext(MotionConfigContext), ...config };
|
|
8484
8521
|
/**
|
|
8485
8522
|
* Don't allow isStatic to change between renders as it affects how many hooks
|
|
8486
8523
|
* motion components fire.
|
|
@@ -8536,14 +8573,13 @@
|
|
|
8536
8573
|
* If this is a synchronous load, load features immediately
|
|
8537
8574
|
*/
|
|
8538
8575
|
if (!isLazyBundle(features)) {
|
|
8539
|
-
const { renderer
|
|
8576
|
+
const { renderer, ...loadedFeatures } = features;
|
|
8540
8577
|
loadedRenderer.current = renderer;
|
|
8541
8578
|
loadFeatures(loadedFeatures);
|
|
8542
8579
|
}
|
|
8543
8580
|
React.useEffect(() => {
|
|
8544
8581
|
if (isLazyBundle(features)) {
|
|
8545
|
-
features().then((
|
|
8546
|
-
var { renderer } = _a, loadedFeatures = __rest(_a, ["renderer"]);
|
|
8582
|
+
features().then(({ renderer, ...loadedFeatures }) => {
|
|
8547
8583
|
loadFeatures(loadedFeatures);
|
|
8548
8584
|
loadedRenderer.current = renderer;
|
|
8549
8585
|
setIsLoaded(true);
|
|
@@ -8578,8 +8614,7 @@
|
|
|
8578
8614
|
return order;
|
|
8579
8615
|
}
|
|
8580
8616
|
|
|
8581
|
-
function ReorderGroup(
|
|
8582
|
-
var { children, as = "ul", axis = "y", onReorder, values } = _a, props = __rest(_a, ["children", "as", "axis", "onReorder", "values"]);
|
|
8617
|
+
function ReorderGroup({ children, as = "ul", axis = "y", onReorder, values, ...props }, externalRef) {
|
|
8583
8618
|
const Component = useConstant(() => motion(as));
|
|
8584
8619
|
const order = [];
|
|
8585
8620
|
const isReordering = React.useRef(false);
|
|
@@ -8611,7 +8646,7 @@
|
|
|
8611
8646
|
React.useEffect(() => {
|
|
8612
8647
|
isReordering.current = false;
|
|
8613
8648
|
});
|
|
8614
|
-
return (React__namespace.createElement(Component,
|
|
8649
|
+
return (React__namespace.createElement(Component, { ...props, ref: externalRef },
|
|
8615
8650
|
React__namespace.createElement(ReorderContext.Provider, { value: context }, children)));
|
|
8616
8651
|
}
|
|
8617
8652
|
const Group = React.forwardRef(ReorderGroup);
|
|
@@ -8665,7 +8700,10 @@
|
|
|
8665
8700
|
const inputRange = args[1 + argOffset];
|
|
8666
8701
|
const outputRange = args[2 + argOffset];
|
|
8667
8702
|
const options = args[3 + argOffset];
|
|
8668
|
-
const interpolator = interpolate$1(inputRange, outputRange,
|
|
8703
|
+
const interpolator = interpolate$1(inputRange, outputRange, {
|
|
8704
|
+
mixer: getMixer(outputRange[0]),
|
|
8705
|
+
...options,
|
|
8706
|
+
});
|
|
8669
8707
|
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
8670
8708
|
}
|
|
8671
8709
|
|
|
@@ -8730,13 +8768,12 @@
|
|
|
8730
8768
|
function useDefaultMotionValue(value, defaultValue = 0) {
|
|
8731
8769
|
return isMotionValue(value) ? value : useMotionValue(defaultValue);
|
|
8732
8770
|
}
|
|
8733
|
-
function ReorderItem(
|
|
8734
|
-
var { children, style, value, as = "li", onDrag, layout = true } = _a, props = __rest(_a, ["children", "style", "value", "as", "onDrag", "layout"]);
|
|
8771
|
+
function ReorderItem({ children, style = {}, value, as = "li", onDrag, layout = true, ...props }, externalRef) {
|
|
8735
8772
|
const Component = useConstant(() => motion(as));
|
|
8736
8773
|
const context = React.useContext(ReorderContext);
|
|
8737
8774
|
const point = {
|
|
8738
|
-
x: useDefaultMotionValue(style
|
|
8739
|
-
y: useDefaultMotionValue(style
|
|
8775
|
+
x: useDefaultMotionValue(style.x),
|
|
8776
|
+
y: useDefaultMotionValue(style.y),
|
|
8740
8777
|
};
|
|
8741
8778
|
const zIndex = useTransform([point.x, point.y], ([latestX, latestY]) => latestX || latestY ? 1 : "unset");
|
|
8742
8779
|
const measuredLayout = React.useRef(null);
|
|
@@ -8745,14 +8782,14 @@
|
|
|
8745
8782
|
React.useEffect(() => {
|
|
8746
8783
|
registerItem(value, measuredLayout.current);
|
|
8747
8784
|
}, [context]);
|
|
8748
|
-
return (React__namespace.createElement(Component,
|
|
8785
|
+
return (React__namespace.createElement(Component, { drag: axis, ...props, dragSnapToOrigin: true, style: { ...style, x: point.x, y: point.y, zIndex }, layout: layout, onDrag: (event, gesturePoint) => {
|
|
8749
8786
|
const { velocity } = gesturePoint;
|
|
8750
8787
|
velocity[axis] &&
|
|
8751
8788
|
updateOrder(value, point[axis].get(), velocity[axis]);
|
|
8752
|
-
onDrag
|
|
8789
|
+
onDrag && onDrag(event, gesturePoint);
|
|
8753
8790
|
}, onLayoutMeasure: (measured) => {
|
|
8754
8791
|
measuredLayout.current = measured;
|
|
8755
|
-
}, ref: externalRef }
|
|
8792
|
+
}, ref: externalRef }, children));
|
|
8756
8793
|
}
|
|
8757
8794
|
const Item = React.forwardRef(ReorderItem);
|
|
8758
8795
|
|
|
@@ -8764,12 +8801,21 @@
|
|
|
8764
8801
|
/**
|
|
8765
8802
|
* @public
|
|
8766
8803
|
*/
|
|
8767
|
-
const domAnimation =
|
|
8804
|
+
const domAnimation = {
|
|
8805
|
+
renderer: createDomVisualElement,
|
|
8806
|
+
...animations,
|
|
8807
|
+
...gestureAnimations,
|
|
8808
|
+
};
|
|
8768
8809
|
|
|
8769
8810
|
/**
|
|
8770
8811
|
* @public
|
|
8771
8812
|
*/
|
|
8772
|
-
const domMax =
|
|
8813
|
+
const domMax = {
|
|
8814
|
+
...domAnimation,
|
|
8815
|
+
...drag,
|
|
8816
|
+
...layoutFeatures,
|
|
8817
|
+
projectionNodeConstructor: HTMLProjectionNode,
|
|
8818
|
+
};
|
|
8773
8819
|
|
|
8774
8820
|
/**
|
|
8775
8821
|
* Combine multiple motion values into a new one using a string template literal.
|
|
@@ -8845,7 +8891,13 @@
|
|
|
8845
8891
|
if (activeSpringAnimation.current) {
|
|
8846
8892
|
activeSpringAnimation.current.stop();
|
|
8847
8893
|
}
|
|
8848
|
-
activeSpringAnimation.current = animate$1(
|
|
8894
|
+
activeSpringAnimation.current = animate$1({
|
|
8895
|
+
from: value.get(),
|
|
8896
|
+
to: v,
|
|
8897
|
+
velocity: value.getVelocity(),
|
|
8898
|
+
...config,
|
|
8899
|
+
onUpdate: set,
|
|
8900
|
+
});
|
|
8849
8901
|
return value.get();
|
|
8850
8902
|
});
|
|
8851
8903
|
}, [JSON.stringify(config)]);
|
|
@@ -9461,8 +9513,7 @@
|
|
|
9461
9513
|
scrollXProgress: motionValue(0),
|
|
9462
9514
|
scrollYProgress: motionValue(0),
|
|
9463
9515
|
});
|
|
9464
|
-
function useScroll(
|
|
9465
|
-
var { container, target } = _a, options = __rest(_a, ["container", "target"]);
|
|
9516
|
+
function useScroll({ container, target, ...options } = {}) {
|
|
9466
9517
|
const values = useConstant(createScrollMotionValues);
|
|
9467
9518
|
useIsomorphicLayoutEffect(() => {
|
|
9468
9519
|
return scroll(({ x, y }) => {
|
|
@@ -9470,7 +9521,11 @@
|
|
|
9470
9521
|
values.scrollXProgress.set(x.progress);
|
|
9471
9522
|
values.scrollY.set(y.current);
|
|
9472
9523
|
values.scrollYProgress.set(y.progress);
|
|
9473
|
-
},
|
|
9524
|
+
}, {
|
|
9525
|
+
...options,
|
|
9526
|
+
container: (container === null || container === void 0 ? void 0 : container.current) || undefined,
|
|
9527
|
+
target: (target === null || target === void 0 ? void 0 : target.current) || undefined,
|
|
9528
|
+
});
|
|
9474
9529
|
}, []);
|
|
9475
9530
|
return values;
|
|
9476
9531
|
}
|
|
@@ -9521,11 +9576,11 @@
|
|
|
9521
9576
|
}
|
|
9522
9577
|
add(name) {
|
|
9523
9578
|
let memberName;
|
|
9524
|
-
if (
|
|
9579
|
+
if (transformProps.has(name)) {
|
|
9525
9580
|
this.transforms.add(name);
|
|
9526
9581
|
memberName = "transform";
|
|
9527
9582
|
}
|
|
9528
|
-
else if (!
|
|
9583
|
+
else if (!name.startsWith("origin") &&
|
|
9529
9584
|
!isCSSVariable$1(name) &&
|
|
9530
9585
|
name !== "willChange") {
|
|
9531
9586
|
memberName = camelToDash(name);
|
|
@@ -9536,7 +9591,7 @@
|
|
|
9536
9591
|
}
|
|
9537
9592
|
}
|
|
9538
9593
|
remove(name) {
|
|
9539
|
-
if (
|
|
9594
|
+
if (transformProps.has(name)) {
|
|
9540
9595
|
this.transforms.delete(name);
|
|
9541
9596
|
if (!this.transforms.size) {
|
|
9542
9597
|
removeItem(this.members, "transform");
|
|
@@ -9555,6 +9610,58 @@
|
|
|
9555
9610
|
return useConstant(() => new WillChangeMotionValue("auto"));
|
|
9556
9611
|
}
|
|
9557
9612
|
|
|
9613
|
+
/**
|
|
9614
|
+
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
9615
|
+
*
|
|
9616
|
+
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
9617
|
+
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
9618
|
+
*
|
|
9619
|
+
* It will actively respond to changes and re-render your components with the latest setting.
|
|
9620
|
+
*
|
|
9621
|
+
* ```jsx
|
|
9622
|
+
* export function Sidebar({ isOpen }) {
|
|
9623
|
+
* const shouldReduceMotion = useReducedMotion()
|
|
9624
|
+
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
9625
|
+
*
|
|
9626
|
+
* return (
|
|
9627
|
+
* <motion.div animate={{
|
|
9628
|
+
* opacity: isOpen ? 1 : 0,
|
|
9629
|
+
* x: isOpen ? 0 : closedX
|
|
9630
|
+
* }} />
|
|
9631
|
+
* )
|
|
9632
|
+
* }
|
|
9633
|
+
* ```
|
|
9634
|
+
*
|
|
9635
|
+
* @return boolean
|
|
9636
|
+
*
|
|
9637
|
+
* @public
|
|
9638
|
+
*/
|
|
9639
|
+
function useReducedMotion() {
|
|
9640
|
+
/**
|
|
9641
|
+
* Lazy initialisation of prefersReducedMotion
|
|
9642
|
+
*/
|
|
9643
|
+
!hasReducedMotionListener.current && initPrefersReducedMotion();
|
|
9644
|
+
const [shouldReduceMotion] = React.useState(prefersReducedMotion.current);
|
|
9645
|
+
/**
|
|
9646
|
+
* TODO See if people miss automatically updating shouldReduceMotion setting
|
|
9647
|
+
*/
|
|
9648
|
+
return shouldReduceMotion;
|
|
9649
|
+
}
|
|
9650
|
+
|
|
9651
|
+
function useReducedMotionConfig() {
|
|
9652
|
+
const reducedMotionPreference = useReducedMotion();
|
|
9653
|
+
const { reducedMotion } = React.useContext(MotionConfigContext);
|
|
9654
|
+
if (reducedMotion === "never") {
|
|
9655
|
+
return false;
|
|
9656
|
+
}
|
|
9657
|
+
else if (reducedMotion === "always") {
|
|
9658
|
+
return true;
|
|
9659
|
+
}
|
|
9660
|
+
else {
|
|
9661
|
+
return reducedMotionPreference;
|
|
9662
|
+
}
|
|
9663
|
+
}
|
|
9664
|
+
|
|
9558
9665
|
/**
|
|
9559
9666
|
* @public
|
|
9560
9667
|
*/
|
|
@@ -9709,7 +9816,6 @@
|
|
|
9709
9816
|
function useInView(ref, { root, margin, amount, once = false } = {}) {
|
|
9710
9817
|
const [isInView, setInView] = React.useState(false);
|
|
9711
9818
|
React.useEffect(() => {
|
|
9712
|
-
var _a;
|
|
9713
9819
|
if (!ref.current || (once && isInView))
|
|
9714
9820
|
return;
|
|
9715
9821
|
const onEnter = () => {
|
|
@@ -9717,7 +9823,7 @@
|
|
|
9717
9823
|
return once ? undefined : () => setInView(false);
|
|
9718
9824
|
};
|
|
9719
9825
|
const options = {
|
|
9720
|
-
root: (
|
|
9826
|
+
root: (root && root.current) || undefined,
|
|
9721
9827
|
margin,
|
|
9722
9828
|
amount: amount === "some" ? "any" : amount,
|
|
9723
9829
|
};
|
|
@@ -9814,12 +9920,12 @@
|
|
|
9814
9920
|
function useInstantLayoutTransition() {
|
|
9815
9921
|
return startTransition;
|
|
9816
9922
|
}
|
|
9817
|
-
function startTransition(
|
|
9923
|
+
function startTransition(callback) {
|
|
9818
9924
|
if (!rootProjectionNode.current)
|
|
9819
9925
|
return;
|
|
9820
9926
|
rootProjectionNode.current.isUpdating = false;
|
|
9821
9927
|
rootProjectionNode.current.blockUpdate();
|
|
9822
|
-
|
|
9928
|
+
callback && callback();
|
|
9823
9929
|
}
|
|
9824
9930
|
|
|
9825
9931
|
function useInstantTransition() {
|
|
@@ -9862,11 +9968,10 @@
|
|
|
9862
9968
|
readValueFromInstance(_state, key, options) {
|
|
9863
9969
|
return options.initialState[key] || 0;
|
|
9864
9970
|
},
|
|
9865
|
-
makeTargetAnimatable(element,
|
|
9866
|
-
var { transition, transitionEnd } = _a, target = __rest(_a, ["transition", "transitionEnd"]);
|
|
9971
|
+
makeTargetAnimatable(element, { transition, transitionEnd, ...target }) {
|
|
9867
9972
|
const origin = getOrigin(target, transition || {}, element);
|
|
9868
9973
|
checkTargetForNewValues(element, target, origin);
|
|
9869
|
-
return
|
|
9974
|
+
return { transition, transitionEnd, ...target };
|
|
9870
9975
|
},
|
|
9871
9976
|
});
|
|
9872
9977
|
const useVisualState = makeUseVisualState({
|
|
@@ -9888,7 +9993,7 @@
|
|
|
9888
9993
|
React.useEffect(() => {
|
|
9889
9994
|
element.setProps({
|
|
9890
9995
|
onUpdate: (v) => {
|
|
9891
|
-
setAnimationState(
|
|
9996
|
+
setAnimationState({ ...v });
|
|
9892
9997
|
},
|
|
9893
9998
|
});
|
|
9894
9999
|
}, [setAnimationState, element]);
|