framer-motion 7.2.0 → 7.3.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 +762 -627
- 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/geometry/utils.mjs +10 -1
- package/dist/es/projection/node/HTMLProjectionNode.mjs +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +62 -20
- 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 +21 -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 +806 -670
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +60 -54
- package/dist/projection.dev.js +402 -213
- 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 +41 -22
- 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;
|
|
128
|
+
return typeof v === "string" || Array.isArray(v);
|
|
318
129
|
}
|
|
319
|
-
|
|
320
|
-
|
|
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;
|
|
343
|
-
}
|
|
344
|
-
function resolveVariant(visualElement, definition, custom) {
|
|
345
|
-
const props = visualElement.getProps();
|
|
346
|
-
return resolveVariantFromProps(props, definition, custom !== null && custom !== void 0 ? custom : props.custom, getCurrent(visualElement), getVelocity$1(visualElement));
|
|
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,41 @@
|
|
|
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
|
+
"rotateZ",
|
|
481
|
+
"skew",
|
|
482
|
+
"skewX",
|
|
483
|
+
"skewY",
|
|
484
|
+
];
|
|
682
485
|
/**
|
|
683
486
|
* A quick lookup for transform props.
|
|
684
487
|
*/
|
|
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
|
-
}
|
|
488
|
+
const transformProps = new Set(transformPropOrder);
|
|
696
489
|
|
|
697
490
|
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
698
|
-
return (
|
|
699
|
-
|
|
491
|
+
return (transformProps.has(key) ||
|
|
492
|
+
key.startsWith("origin") ||
|
|
700
493
|
((layout || layoutId !== undefined) &&
|
|
701
494
|
(!!scaleCorrectors[key] || key === "opacity")));
|
|
702
495
|
}
|
|
703
496
|
|
|
704
|
-
const isMotionValue = (value) =>
|
|
705
|
-
return Boolean(value !== null && typeof value === "object" && value.getVelocity);
|
|
706
|
-
};
|
|
497
|
+
const isMotionValue = (value) => value === undefined ? false : !!value.getVelocity;
|
|
707
498
|
|
|
708
499
|
const translateAlias = {
|
|
709
500
|
x: "translateX",
|
|
@@ -711,6 +502,10 @@
|
|
|
711
502
|
z: "translateZ",
|
|
712
503
|
transformPerspective: "perspective",
|
|
713
504
|
};
|
|
505
|
+
/**
|
|
506
|
+
* A function to use with Array.sort to sort transform keys by their default order.
|
|
507
|
+
*/
|
|
508
|
+
const sortTransformProps = (a, b) => transformPropOrder.indexOf(a) - transformPropOrder.indexOf(b);
|
|
714
509
|
/**
|
|
715
510
|
* Build a CSS transform style from individual x/y/scale etc properties.
|
|
716
511
|
*
|
|
@@ -722,18 +517,11 @@
|
|
|
722
517
|
let transformString = "";
|
|
723
518
|
// Transform keys into their default order - this will determine the output order.
|
|
724
519
|
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
520
|
// Loop over each transform and build them into transformString
|
|
729
|
-
const
|
|
730
|
-
for (let i = 0; i < numTransformKeys; i++) {
|
|
731
|
-
const key = transformKeys[i];
|
|
521
|
+
for (const key of transformKeys) {
|
|
732
522
|
transformString += `${translateAlias[key] || key}(${transform[key]}) `;
|
|
733
|
-
if (key === "z")
|
|
734
|
-
transformHasZ = true;
|
|
735
523
|
}
|
|
736
|
-
if (
|
|
524
|
+
if (enableHardwareAcceleration && !transform.z) {
|
|
737
525
|
transformString += "translateZ(0)";
|
|
738
526
|
}
|
|
739
527
|
transformString = transformString.trim();
|
|
@@ -747,13 +535,6 @@
|
|
|
747
535
|
}
|
|
748
536
|
return transformString;
|
|
749
537
|
}
|
|
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
538
|
|
|
758
539
|
/**
|
|
759
540
|
* Returns true if the provided key is a CSS variable
|
|
@@ -972,7 +753,10 @@
|
|
|
972
753
|
return functions ? functions.map(applyDefaultFilter).join(' ') : v;
|
|
973
754
|
} });
|
|
974
755
|
|
|
975
|
-
const int =
|
|
756
|
+
const int = {
|
|
757
|
+
...number,
|
|
758
|
+
transform: Math.round,
|
|
759
|
+
};
|
|
976
760
|
|
|
977
761
|
const numberValueTypes = {
|
|
978
762
|
// Border props
|
|
@@ -1042,11 +826,7 @@
|
|
|
1042
826
|
};
|
|
1043
827
|
|
|
1044
828
|
function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
1045
|
-
var _a;
|
|
1046
829
|
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
830
|
transformKeys.length = 0;
|
|
1051
831
|
// Track whether we encounter any transform or transformOrigin values.
|
|
1052
832
|
let hasTransform = false;
|
|
@@ -1071,7 +851,7 @@
|
|
|
1071
851
|
// Convert the value to its default value type, ie 0 -> "0px"
|
|
1072
852
|
const valueType = numberValueTypes[key];
|
|
1073
853
|
const valueAsType = getValueAsType(value, valueType);
|
|
1074
|
-
if (
|
|
854
|
+
if (transformProps.has(key)) {
|
|
1075
855
|
// If this is a transform, flag to enable further transform processing
|
|
1076
856
|
hasTransform = true;
|
|
1077
857
|
transform[key] = valueAsType;
|
|
@@ -1080,29 +860,35 @@
|
|
|
1080
860
|
if (!transformIsNone)
|
|
1081
861
|
continue;
|
|
1082
862
|
// Otherwise check to see if this is a default transform
|
|
1083
|
-
if (value !== (
|
|
863
|
+
if (value !== (valueType.default || 0))
|
|
1084
864
|
transformIsNone = false;
|
|
1085
865
|
}
|
|
1086
|
-
else if (
|
|
1087
|
-
transformOrigin[key] = valueAsType;
|
|
866
|
+
else if (key.startsWith("origin")) {
|
|
1088
867
|
// If this is a transform origin, flag and enable further transform-origin processing
|
|
1089
868
|
hasTransformOrigin = true;
|
|
869
|
+
transformOrigin[key] = valueAsType;
|
|
1090
870
|
}
|
|
1091
871
|
else {
|
|
1092
872
|
style[key] = valueAsType;
|
|
1093
873
|
}
|
|
1094
874
|
}
|
|
1095
|
-
if (hasTransform) {
|
|
875
|
+
if (hasTransform || transformTemplate) {
|
|
1096
876
|
style.transform = buildTransform(state, options, transformIsNone, transformTemplate);
|
|
1097
877
|
}
|
|
1098
|
-
else if (transformTemplate) {
|
|
1099
|
-
style.transform = transformTemplate({}, "");
|
|
1100
|
-
}
|
|
1101
878
|
else if (!latestValues.transform && style.transform) {
|
|
879
|
+
/**
|
|
880
|
+
* If we have previously created a transform but currently don't have any,
|
|
881
|
+
* reset transform style to none.
|
|
882
|
+
*/
|
|
1102
883
|
style.transform = "none";
|
|
1103
884
|
}
|
|
885
|
+
/**
|
|
886
|
+
* Build a transformOrigin style. Uses the same defaults as the browser for
|
|
887
|
+
* undefined origins.
|
|
888
|
+
*/
|
|
1104
889
|
if (hasTransformOrigin) {
|
|
1105
|
-
|
|
890
|
+
const { originX = "50%", originY = "50%", originZ = 0, } = transformOrigin;
|
|
891
|
+
style.transformOrigin = `${originX} ${originY} ${originZ}`;
|
|
1106
892
|
}
|
|
1107
893
|
}
|
|
1108
894
|
|
|
@@ -1125,28 +911,24 @@
|
|
|
1125
911
|
return React.useMemo(() => {
|
|
1126
912
|
const state = createHtmlRenderState();
|
|
1127
913
|
buildHTMLStyles(state, visualState, { enableHardwareAcceleration: !isStatic }, transformTemplate);
|
|
1128
|
-
|
|
1129
|
-
return Object.assign(Object.assign({}, vars), style);
|
|
914
|
+
return Object.assign({}, state.vars, state.style);
|
|
1130
915
|
}, [visualState]);
|
|
1131
916
|
}
|
|
1132
917
|
function useStyle(props, visualState, isStatic) {
|
|
1133
918
|
const styleProp = props.style || {};
|
|
1134
|
-
|
|
919
|
+
const style = {};
|
|
1135
920
|
/**
|
|
1136
921
|
* Copy non-Motion Values straight into style
|
|
1137
922
|
*/
|
|
1138
923
|
copyRawValuesOnly(style, styleProp, props);
|
|
1139
924
|
Object.assign(style, useInitialMotionValues(props, visualState, isStatic));
|
|
1140
|
-
|
|
1141
|
-
style = props.transformValues(style);
|
|
1142
|
-
}
|
|
1143
|
-
return style;
|
|
925
|
+
return props.transformValues ? props.transformValues(style) : style;
|
|
1144
926
|
}
|
|
1145
927
|
function useHTMLProps(props, visualState, isStatic) {
|
|
1146
928
|
// The `any` isn't ideal but it is the type of createElement props argument
|
|
1147
929
|
const htmlProps = {};
|
|
1148
930
|
const style = useStyle(props, visualState, isStatic);
|
|
1149
|
-
if (
|
|
931
|
+
if (props.drag && props.dragListener !== false) {
|
|
1150
932
|
// Disable the ghost element when a user drags
|
|
1151
933
|
htmlProps.draggable = false;
|
|
1152
934
|
// Disable text selection
|
|
@@ -1164,6 +946,24 @@
|
|
|
1164
946
|
return htmlProps;
|
|
1165
947
|
}
|
|
1166
948
|
|
|
949
|
+
const animationProps = [
|
|
950
|
+
"animate",
|
|
951
|
+
"exit",
|
|
952
|
+
"variants",
|
|
953
|
+
"whileHover",
|
|
954
|
+
"whileTap",
|
|
955
|
+
"whileFocus",
|
|
956
|
+
"whileDrag",
|
|
957
|
+
"whileInView",
|
|
958
|
+
];
|
|
959
|
+
const tapProps = ["whileTap", "onTap", "onTapStart", "onTapCancel"];
|
|
960
|
+
const panProps = ["onPan", "onPanStart", "onPanSessionStart", "onPanEnd"];
|
|
961
|
+
const inViewProps = [
|
|
962
|
+
"whileInView",
|
|
963
|
+
"onViewportEnter",
|
|
964
|
+
"onViewportLeave",
|
|
965
|
+
"viewport",
|
|
966
|
+
];
|
|
1167
967
|
/**
|
|
1168
968
|
* A list of all valid MotionProps.
|
|
1169
969
|
*
|
|
@@ -1172,8 +972,6 @@
|
|
|
1172
972
|
*/
|
|
1173
973
|
const validMotionProps = new Set([
|
|
1174
974
|
"initial",
|
|
1175
|
-
"animate",
|
|
1176
|
-
"exit",
|
|
1177
975
|
"style",
|
|
1178
976
|
"variants",
|
|
1179
977
|
"transition",
|
|
@@ -1209,24 +1007,13 @@
|
|
|
1209
1007
|
"dragMomentum",
|
|
1210
1008
|
"dragPropagation",
|
|
1211
1009
|
"dragTransition",
|
|
1212
|
-
"whileDrag",
|
|
1213
|
-
"onPan",
|
|
1214
|
-
"onPanStart",
|
|
1215
|
-
"onPanEnd",
|
|
1216
|
-
"onPanSessionStart",
|
|
1217
|
-
"onTap",
|
|
1218
|
-
"onTapStart",
|
|
1219
|
-
"onTapCancel",
|
|
1220
1010
|
"onHoverStart",
|
|
1221
1011
|
"onHoverEnd",
|
|
1222
|
-
"whileFocus",
|
|
1223
|
-
"whileTap",
|
|
1224
|
-
"whileHover",
|
|
1225
|
-
"whileInView",
|
|
1226
|
-
"onViewportEnter",
|
|
1227
|
-
"onViewportLeave",
|
|
1228
|
-
"viewport",
|
|
1229
1012
|
"layoutScroll",
|
|
1013
|
+
...inViewProps,
|
|
1014
|
+
...tapProps,
|
|
1015
|
+
...animationProps,
|
|
1016
|
+
...panProps,
|
|
1230
1017
|
]);
|
|
1231
1018
|
/**
|
|
1232
1019
|
* Check whether a prop name is a valid `MotionProp` key.
|
|
@@ -1285,33 +1072,6 @@
|
|
|
1285
1072
|
return filteredProps;
|
|
1286
1073
|
}
|
|
1287
1074
|
|
|
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
1075
|
function calcOrigin$1(origin, offset, size) {
|
|
1316
1076
|
return typeof origin === "string"
|
|
1317
1077
|
? origin
|
|
@@ -1359,10 +1119,9 @@
|
|
|
1359
1119
|
/**
|
|
1360
1120
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
1361
1121
|
*/
|
|
1362
|
-
function buildSVGAttrs(state,
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
latest = __rest(_a, ["attrX", "attrY", "originX", "originY", "pathLength", "pathSpacing", "pathOffset"]);
|
|
1122
|
+
function buildSVGAttrs(state, { attrX, attrY, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0,
|
|
1123
|
+
// This is object creation, which we try to avoid per-frame.
|
|
1124
|
+
...latest }, options, transformTemplate) {
|
|
1366
1125
|
buildHTMLStyles(state, latest, options, transformTemplate);
|
|
1367
1126
|
state.attrs = state.style;
|
|
1368
1127
|
state.style = {};
|
|
@@ -1392,18 +1151,24 @@
|
|
|
1392
1151
|
}
|
|
1393
1152
|
}
|
|
1394
1153
|
|
|
1395
|
-
const createSvgRenderState = () => (
|
|
1154
|
+
const createSvgRenderState = () => ({
|
|
1155
|
+
...createHtmlRenderState(),
|
|
1156
|
+
attrs: {},
|
|
1157
|
+
});
|
|
1396
1158
|
|
|
1397
1159
|
function useSVGProps(props, visualState) {
|
|
1398
1160
|
const visualProps = React.useMemo(() => {
|
|
1399
1161
|
const state = createSvgRenderState();
|
|
1400
1162
|
buildSVGAttrs(state, visualState, { enableHardwareAcceleration: false }, props.transformTemplate);
|
|
1401
|
-
return
|
|
1163
|
+
return {
|
|
1164
|
+
...state.attrs,
|
|
1165
|
+
style: { ...state.style },
|
|
1166
|
+
};
|
|
1402
1167
|
}, [visualState]);
|
|
1403
1168
|
if (props.style) {
|
|
1404
1169
|
const rawStyles = {};
|
|
1405
1170
|
copyRawValuesOnly(rawStyles, props.style, props);
|
|
1406
|
-
visualProps.style =
|
|
1171
|
+
visualProps.style = { ...rawStyles, ...visualProps.style };
|
|
1407
1172
|
}
|
|
1408
1173
|
return visualProps;
|
|
1409
1174
|
}
|
|
@@ -1415,7 +1180,11 @@
|
|
|
1415
1180
|
: useHTMLProps;
|
|
1416
1181
|
const visualProps = useVisualProps(props, latestValues, isStatic);
|
|
1417
1182
|
const filteredProps = filterProps(props, typeof Component === "string", forwardMotionProps);
|
|
1418
|
-
const elementProps =
|
|
1183
|
+
const elementProps = {
|
|
1184
|
+
...filteredProps,
|
|
1185
|
+
...visualProps,
|
|
1186
|
+
ref,
|
|
1187
|
+
};
|
|
1419
1188
|
if (projectionId) {
|
|
1420
1189
|
elementProps["data-projection-id"] = projectionId;
|
|
1421
1190
|
}
|
|
@@ -1424,12 +1193,10 @@
|
|
|
1424
1193
|
return useRender;
|
|
1425
1194
|
}
|
|
1426
1195
|
|
|
1427
|
-
const CAMEL_CASE_PATTERN = /([a-z])([A-Z])/g;
|
|
1428
|
-
const REPLACE_TEMPLATE = "$1-$2";
|
|
1429
1196
|
/**
|
|
1430
1197
|
* Convert camelCase to dash-case properties.
|
|
1431
1198
|
*/
|
|
1432
|
-
const camelToDash = (str) => str.replace(
|
|
1199
|
+
const camelToDash = (str) => str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
1433
1200
|
|
|
1434
1201
|
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
1435
1202
|
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
@@ -1491,11 +1258,32 @@
|
|
|
1491
1258
|
newValues[targetKey] = props[key];
|
|
1492
1259
|
}
|
|
1493
1260
|
}
|
|
1494
|
-
return newValues;
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
function
|
|
1498
|
-
|
|
1261
|
+
return newValues;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
function resolveVariantFromProps(props, definition, custom, currentValues = {}, currentVelocity = {}) {
|
|
1265
|
+
/**
|
|
1266
|
+
* If the variant definition is a function, resolve.
|
|
1267
|
+
*/
|
|
1268
|
+
if (typeof definition === "function") {
|
|
1269
|
+
definition = definition(custom !== undefined ? custom : props.custom, currentValues, currentVelocity);
|
|
1270
|
+
}
|
|
1271
|
+
/**
|
|
1272
|
+
* If the variant definition is a variant label, or
|
|
1273
|
+
* the function returned a variant label, resolve.
|
|
1274
|
+
*/
|
|
1275
|
+
if (typeof definition === "string") {
|
|
1276
|
+
definition = props.variants && props.variants[definition];
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* At this point we've resolved both functions and variant labels,
|
|
1280
|
+
* but the resolved variant label might itself have been a function.
|
|
1281
|
+
* If so, resolve. This can only have returned a valid target object.
|
|
1282
|
+
*/
|
|
1283
|
+
if (typeof definition === "function") {
|
|
1284
|
+
definition = definition(custom !== undefined ? custom : props.custom, currentValues, currentVelocity);
|
|
1285
|
+
}
|
|
1286
|
+
return definition;
|
|
1499
1287
|
}
|
|
1500
1288
|
|
|
1501
1289
|
const isKeyframesTarget = (v) => {
|
|
@@ -1535,29 +1323,32 @@
|
|
|
1535
1323
|
const makeUseVisualState = (config) => (props, isStatic) => {
|
|
1536
1324
|
const context = React.useContext(MotionContext);
|
|
1537
1325
|
const presenceContext = React.useContext(PresenceContext);
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
: useConstant(() => makeState(config, props, context, presenceContext));
|
|
1326
|
+
const make = () => makeState(config, props, context, presenceContext);
|
|
1327
|
+
return isStatic ? make() : useConstant(make);
|
|
1541
1328
|
};
|
|
1542
1329
|
function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
1543
1330
|
const values = {};
|
|
1544
|
-
const blockInitialAnimation = (presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.initial) === false;
|
|
1545
1331
|
const motionValues = scrapeMotionValues(props);
|
|
1546
1332
|
for (const key in motionValues) {
|
|
1547
1333
|
values[key] = resolveMotionValue(motionValues[key]);
|
|
1548
1334
|
}
|
|
1549
1335
|
let { initial, animate } = props;
|
|
1550
|
-
const isControllingVariants =
|
|
1551
|
-
const isVariantNode =
|
|
1336
|
+
const isControllingVariants$1 = isControllingVariants(props);
|
|
1337
|
+
const isVariantNode$1 = isVariantNode(props);
|
|
1552
1338
|
if (context &&
|
|
1553
|
-
isVariantNode &&
|
|
1554
|
-
!isControllingVariants &&
|
|
1339
|
+
isVariantNode$1 &&
|
|
1340
|
+
!isControllingVariants$1 &&
|
|
1555
1341
|
props.inherit !== false) {
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1342
|
+
if (initial === undefined)
|
|
1343
|
+
initial = context.initial;
|
|
1344
|
+
if (animate === undefined)
|
|
1345
|
+
animate = context.animate;
|
|
1346
|
+
}
|
|
1347
|
+
let isInitialAnimationBlocked = presenceContext
|
|
1348
|
+
? presenceContext.initial === false
|
|
1349
|
+
: false;
|
|
1350
|
+
isInitialAnimationBlocked = isInitialAnimationBlocked || initial === false;
|
|
1351
|
+
const variantToSet = isInitialAnimationBlocked ? animate : initial;
|
|
1561
1352
|
if (variantToSet &&
|
|
1562
1353
|
typeof variantToSet !== "boolean" &&
|
|
1563
1354
|
!isAnimationControls(variantToSet)) {
|
|
@@ -1566,7 +1357,7 @@
|
|
|
1566
1357
|
const resolved = resolveVariantFromProps(props, definition);
|
|
1567
1358
|
if (!resolved)
|
|
1568
1359
|
return;
|
|
1569
|
-
const { transitionEnd, transition
|
|
1360
|
+
const { transitionEnd, transition, ...target } = resolved;
|
|
1570
1361
|
for (const key in target) {
|
|
1571
1362
|
let valueTarget = target[key];
|
|
1572
1363
|
if (Array.isArray(valueTarget)) {
|
|
@@ -1574,7 +1365,7 @@
|
|
|
1574
1365
|
* Take final keyframe if the initial animation is blocked because
|
|
1575
1366
|
* we want to initialise at the end of that blocked animation.
|
|
1576
1367
|
*/
|
|
1577
|
-
const index =
|
|
1368
|
+
const index = isInitialAnimationBlocked
|
|
1578
1369
|
? valueTarget.length - 1
|
|
1579
1370
|
: 0;
|
|
1580
1371
|
valueTarget = valueTarget[index];
|
|
@@ -1628,9 +1419,14 @@
|
|
|
1628
1419
|
const baseConfig = isSVGComponent(Component)
|
|
1629
1420
|
? svgMotionConfig
|
|
1630
1421
|
: htmlMotionConfig;
|
|
1631
|
-
return
|
|
1422
|
+
return {
|
|
1423
|
+
...baseConfig,
|
|
1424
|
+
preloadedFeatures,
|
|
1425
|
+
useRender: createUseRender(forwardMotionProps),
|
|
1426
|
+
createVisualElement,
|
|
1632
1427
|
projectionNodeConstructor,
|
|
1633
|
-
Component
|
|
1428
|
+
Component,
|
|
1429
|
+
};
|
|
1634
1430
|
}
|
|
1635
1431
|
|
|
1636
1432
|
exports.AnimationType = void 0;
|
|
@@ -1685,13 +1481,12 @@
|
|
|
1685
1481
|
* @internal
|
|
1686
1482
|
*/
|
|
1687
1483
|
function useFocusGesture({ whileFocus, visualElement }) {
|
|
1484
|
+
const { animationState } = visualElement;
|
|
1688
1485
|
const onFocus = () => {
|
|
1689
|
-
|
|
1690
|
-
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(exports.AnimationType.Focus, true);
|
|
1486
|
+
animationState && animationState.setActive(exports.AnimationType.Focus, true);
|
|
1691
1487
|
};
|
|
1692
1488
|
const onBlur = () => {
|
|
1693
|
-
|
|
1694
|
-
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(exports.AnimationType.Focus, false);
|
|
1489
|
+
animationState && animationState.setActive(exports.AnimationType.Focus, false);
|
|
1695
1490
|
};
|
|
1696
1491
|
useDomEvent(visualElement, "focus", whileFocus ? onFocus : undefined);
|
|
1697
1492
|
useDomEvent(visualElement, "blur", whileFocus ? onBlur : undefined);
|
|
@@ -1846,14 +1641,15 @@
|
|
|
1846
1641
|
|
|
1847
1642
|
function createHoverEvent(visualElement, isActive, callback) {
|
|
1848
1643
|
return (event, info) => {
|
|
1849
|
-
var _a;
|
|
1850
1644
|
if (!isMouseEvent(event) || isDragActive())
|
|
1851
1645
|
return;
|
|
1852
1646
|
/**
|
|
1853
1647
|
* Ensure we trigger animations before firing event callback
|
|
1854
1648
|
*/
|
|
1855
|
-
(
|
|
1856
|
-
|
|
1649
|
+
if (visualElement.animationState) {
|
|
1650
|
+
visualElement.animationState.setActive(exports.AnimationType.Hover, isActive);
|
|
1651
|
+
}
|
|
1652
|
+
callback && callback(event, info);
|
|
1857
1653
|
};
|
|
1858
1654
|
}
|
|
1859
1655
|
function useHoverGesture({ onHoverStart, onHoverEnd, whileHover, visualElement, }) {
|
|
@@ -1888,6 +1684,48 @@
|
|
|
1888
1684
|
return React.useEffect(() => () => callback(), []);
|
|
1889
1685
|
}
|
|
1890
1686
|
|
|
1687
|
+
/******************************************************************************
|
|
1688
|
+
Copyright (c) Microsoft Corporation.
|
|
1689
|
+
|
|
1690
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
1691
|
+
purpose with or without fee is hereby granted.
|
|
1692
|
+
|
|
1693
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1694
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1695
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1696
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1697
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1698
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1699
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
1700
|
+
***************************************************************************** */
|
|
1701
|
+
|
|
1702
|
+
function __rest(s, e) {
|
|
1703
|
+
var t = {};
|
|
1704
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
1705
|
+
t[p] = s[p];
|
|
1706
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
1707
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
1708
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
1709
|
+
t[p[i]] = s[p[i]];
|
|
1710
|
+
}
|
|
1711
|
+
return t;
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
var warning = function () { };
|
|
1715
|
+
var invariant = function () { };
|
|
1716
|
+
{
|
|
1717
|
+
warning = function (check, message) {
|
|
1718
|
+
if (!check && typeof console !== 'undefined') {
|
|
1719
|
+
console.warn(message);
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
invariant = function (check, message) {
|
|
1723
|
+
if (!check) {
|
|
1724
|
+
throw new Error(message);
|
|
1725
|
+
}
|
|
1726
|
+
};
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1891
1729
|
const clamp$1 = (min, max, v) => Math.min(Math.max(v, min), max);
|
|
1892
1730
|
|
|
1893
1731
|
const safeMin = 0.001;
|
|
@@ -2834,15 +2672,14 @@
|
|
|
2834
2672
|
passive: !(onTapStart || onTap || onTapCancel || onPointerDown),
|
|
2835
2673
|
};
|
|
2836
2674
|
function removePointerEndListener() {
|
|
2837
|
-
|
|
2838
|
-
(_a = cancelPointerEndListeners.current) === null || _a === void 0 ? void 0 : _a.call(cancelPointerEndListeners);
|
|
2675
|
+
cancelPointerEndListeners.current && cancelPointerEndListeners.current();
|
|
2839
2676
|
cancelPointerEndListeners.current = null;
|
|
2840
2677
|
}
|
|
2841
2678
|
function checkPointerEnd() {
|
|
2842
|
-
var _a;
|
|
2843
2679
|
removePointerEndListener();
|
|
2844
2680
|
isPressing.current = false;
|
|
2845
|
-
|
|
2681
|
+
visualElement.animationState &&
|
|
2682
|
+
visualElement.animationState.setActive(exports.AnimationType.Tap, false);
|
|
2846
2683
|
return !isDragActive();
|
|
2847
2684
|
}
|
|
2848
2685
|
function onPointerUp(event, info) {
|
|
@@ -2853,16 +2690,15 @@
|
|
|
2853
2690
|
* as, or a child of, this component's element
|
|
2854
2691
|
*/
|
|
2855
2692
|
!isNodeOrChild(visualElement.getInstance(), event.target)
|
|
2856
|
-
? onTapCancel
|
|
2857
|
-
: onTap
|
|
2693
|
+
? onTapCancel && onTapCancel(event, info)
|
|
2694
|
+
: onTap && onTap(event, info);
|
|
2858
2695
|
}
|
|
2859
2696
|
function onPointerCancel(event, info) {
|
|
2860
2697
|
if (!checkPointerEnd())
|
|
2861
2698
|
return;
|
|
2862
|
-
onTapCancel
|
|
2699
|
+
onTapCancel && onTapCancel(event, info);
|
|
2863
2700
|
}
|
|
2864
2701
|
function onPointerDown(event, info) {
|
|
2865
|
-
var _a;
|
|
2866
2702
|
removePointerEndListener();
|
|
2867
2703
|
if (isPressing.current)
|
|
2868
2704
|
return;
|
|
@@ -2871,13 +2707,22 @@
|
|
|
2871
2707
|
/**
|
|
2872
2708
|
* Ensure we trigger animations before firing event callback
|
|
2873
2709
|
*/
|
|
2874
|
-
|
|
2875
|
-
|
|
2710
|
+
visualElement.animationState &&
|
|
2711
|
+
visualElement.animationState.setActive(exports.AnimationType.Tap, true);
|
|
2712
|
+
onTapStart && onTapStart(event, info);
|
|
2876
2713
|
}
|
|
2877
2714
|
usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined, eventOptions);
|
|
2878
2715
|
useUnmountEffect(removePointerEndListener);
|
|
2879
2716
|
}
|
|
2880
2717
|
|
|
2718
|
+
/**
|
|
2719
|
+
* Browser-safe usage of process
|
|
2720
|
+
*/
|
|
2721
|
+
const defaultEnvironment = "production";
|
|
2722
|
+
const env = typeof process === "undefined" || process.env === undefined
|
|
2723
|
+
? defaultEnvironment
|
|
2724
|
+
: "development" ;
|
|
2725
|
+
|
|
2881
2726
|
const warned = new Set();
|
|
2882
2727
|
function warnOnce(condition, message, element) {
|
|
2883
2728
|
if (condition || warned.has(message))
|
|
@@ -2901,14 +2746,13 @@
|
|
|
2901
2746
|
*/
|
|
2902
2747
|
const observers = new WeakMap();
|
|
2903
2748
|
const fireObserverCallback = (entry) => {
|
|
2904
|
-
|
|
2905
|
-
|
|
2749
|
+
const callback = observerCallbacks.get(entry.target);
|
|
2750
|
+
callback && callback(entry);
|
|
2906
2751
|
};
|
|
2907
2752
|
const fireAllObserverCallbacks = (entries) => {
|
|
2908
2753
|
entries.forEach(fireObserverCallback);
|
|
2909
2754
|
};
|
|
2910
|
-
function initIntersectionObserver(
|
|
2911
|
-
var { root } = _a, options = __rest(_a, ["root"]);
|
|
2755
|
+
function initIntersectionObserver({ root, ...options }) {
|
|
2912
2756
|
const lookupRoot = root || document;
|
|
2913
2757
|
/**
|
|
2914
2758
|
* If we don't have an observer lookup map for this root, create one.
|
|
@@ -2923,7 +2767,7 @@
|
|
|
2923
2767
|
* create one.
|
|
2924
2768
|
*/
|
|
2925
2769
|
if (!rootObservers[key]) {
|
|
2926
|
-
rootObservers[key] = new IntersectionObserver(fireAllObserverCallbacks,
|
|
2770
|
+
rootObservers[key] = new IntersectionObserver(fireAllObserverCallbacks, { root, ...options });
|
|
2927
2771
|
}
|
|
2928
2772
|
return rootObservers[key];
|
|
2929
2773
|
}
|
|
@@ -2964,7 +2808,6 @@
|
|
|
2964
2808
|
threshold: typeof amount === "number" ? amount : thresholdNames[amount],
|
|
2965
2809
|
};
|
|
2966
2810
|
const intersectionCallback = (entry) => {
|
|
2967
|
-
var _a;
|
|
2968
2811
|
const { isIntersecting } = entry;
|
|
2969
2812
|
/**
|
|
2970
2813
|
* If there's been no change in the viewport state, early return.
|
|
@@ -2982,7 +2825,9 @@
|
|
|
2982
2825
|
else if (isIntersecting) {
|
|
2983
2826
|
state.hasEnteredView = true;
|
|
2984
2827
|
}
|
|
2985
|
-
(
|
|
2828
|
+
if (visualElement.animationState) {
|
|
2829
|
+
visualElement.animationState.setActive(exports.AnimationType.InView, isIntersecting);
|
|
2830
|
+
}
|
|
2986
2831
|
/**
|
|
2987
2832
|
* Use the latest committed props rather than the ones in scope
|
|
2988
2833
|
* when this observer is created
|
|
@@ -2991,7 +2836,7 @@
|
|
|
2991
2836
|
const callback = isIntersecting
|
|
2992
2837
|
? props.onViewportEnter
|
|
2993
2838
|
: props.onViewportLeave;
|
|
2994
|
-
callback
|
|
2839
|
+
callback && callback(entry);
|
|
2995
2840
|
};
|
|
2996
2841
|
return observeIntersection(visualElement.getInstance(), options, intersectionCallback);
|
|
2997
2842
|
}, [shouldObserve, root, rootMargin, amount]);
|
|
@@ -3017,11 +2862,12 @@
|
|
|
3017
2862
|
* is preferred to changing the behaviour of the animation state.
|
|
3018
2863
|
*/
|
|
3019
2864
|
requestAnimationFrame(() => {
|
|
3020
|
-
var _a;
|
|
3021
2865
|
state.hasEnteredView = true;
|
|
3022
2866
|
const { onViewportEnter } = visualElement.getProps();
|
|
3023
|
-
onViewportEnter
|
|
3024
|
-
(
|
|
2867
|
+
onViewportEnter && onViewportEnter(null);
|
|
2868
|
+
if (visualElement.animationState) {
|
|
2869
|
+
visualElement.animationState.setActive(exports.AnimationType.InView, true);
|
|
2870
|
+
}
|
|
3025
2871
|
});
|
|
3026
2872
|
}, [shouldObserve]);
|
|
3027
2873
|
}
|
|
@@ -3071,7 +2917,7 @@
|
|
|
3071
2917
|
// Replace with useId when released in React
|
|
3072
2918
|
const id = React.useId();
|
|
3073
2919
|
React.useEffect(() => register(id), []);
|
|
3074
|
-
const safeToRemove = () => onExitComplete
|
|
2920
|
+
const safeToRemove = () => onExitComplete && onExitComplete(id);
|
|
3075
2921
|
return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
|
|
3076
2922
|
}
|
|
3077
2923
|
/**
|
|
@@ -3230,17 +3076,29 @@
|
|
|
3230
3076
|
transitionFactory =
|
|
3231
3077
|
defaultTransitions[valueKey] || defaultTransitions.default;
|
|
3232
3078
|
}
|
|
3233
|
-
return
|
|
3079
|
+
return { to, ...transitionFactory(to) };
|
|
3234
3080
|
};
|
|
3235
3081
|
|
|
3236
3082
|
/**
|
|
3237
3083
|
* A map of default value types for common values
|
|
3238
3084
|
*/
|
|
3239
|
-
const defaultValueTypes =
|
|
3085
|
+
const defaultValueTypes = {
|
|
3086
|
+
...numberValueTypes,
|
|
3240
3087
|
// Color props
|
|
3241
|
-
color,
|
|
3088
|
+
color,
|
|
3089
|
+
backgroundColor: color,
|
|
3090
|
+
outlineColor: color,
|
|
3091
|
+
fill: color,
|
|
3092
|
+
stroke: color,
|
|
3242
3093
|
// Border props
|
|
3243
|
-
borderColor: color,
|
|
3094
|
+
borderColor: color,
|
|
3095
|
+
borderTopColor: color,
|
|
3096
|
+
borderRightColor: color,
|
|
3097
|
+
borderBottomColor: color,
|
|
3098
|
+
borderLeftColor: color,
|
|
3099
|
+
filter,
|
|
3100
|
+
WebkitFilter: filter,
|
|
3101
|
+
};
|
|
3244
3102
|
/**
|
|
3245
3103
|
* Gets the default ValueType for the provided value key
|
|
3246
3104
|
*/
|
|
@@ -3264,17 +3122,15 @@
|
|
|
3264
3122
|
* This filters out orchestration options and returns true
|
|
3265
3123
|
* if any options are left.
|
|
3266
3124
|
*/
|
|
3267
|
-
function isTransitionDefined(
|
|
3268
|
-
var transition = __rest(_a, ["when", "delay", "delayChildren", "staggerChildren", "staggerDirection", "repeat", "repeatType", "repeatDelay", "from"]);
|
|
3125
|
+
function isTransitionDefined({ when, delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
|
|
3269
3126
|
return !!Object.keys(transition).length;
|
|
3270
3127
|
}
|
|
3271
3128
|
let legacyRepeatWarning = false;
|
|
3272
3129
|
/**
|
|
3273
3130
|
* Convert Framer Motion's Transition type into Popmotion-compatible options.
|
|
3274
3131
|
*/
|
|
3275
|
-
function convertTransitionToAnimationOptions(
|
|
3276
|
-
|
|
3277
|
-
const options = Object.assign({}, transition);
|
|
3132
|
+
function convertTransitionToAnimationOptions({ ease, times, yoyo, flip, loop, ...transition }) {
|
|
3133
|
+
const options = { ...transition };
|
|
3278
3134
|
if (times)
|
|
3279
3135
|
options["offset"] = times;
|
|
3280
3136
|
/**
|
|
@@ -3339,26 +3195,30 @@
|
|
|
3339
3195
|
return options;
|
|
3340
3196
|
}
|
|
3341
3197
|
function getPopmotionAnimationOptions(transition, options, key) {
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
(_a = transition.duration) !== null && _a !== void 0 ? _a : (transition.duration = 0.8);
|
|
3198
|
+
if (Array.isArray(options.to) && transition.duration === undefined) {
|
|
3199
|
+
transition.duration = 0.8;
|
|
3345
3200
|
}
|
|
3346
3201
|
hydrateKeyframes(options);
|
|
3347
3202
|
/**
|
|
3348
3203
|
* Get a default transition if none is determined to be defined.
|
|
3349
3204
|
*/
|
|
3350
3205
|
if (!isTransitionDefined(transition)) {
|
|
3351
|
-
transition =
|
|
3206
|
+
transition = {
|
|
3207
|
+
...transition,
|
|
3208
|
+
...getDefaultTransition(key, options.to),
|
|
3209
|
+
};
|
|
3352
3210
|
}
|
|
3353
|
-
return
|
|
3211
|
+
return {
|
|
3212
|
+
...options,
|
|
3213
|
+
...convertTransitionToAnimationOptions(transition),
|
|
3214
|
+
};
|
|
3354
3215
|
}
|
|
3355
3216
|
/**
|
|
3356
3217
|
*
|
|
3357
3218
|
*/
|
|
3358
3219
|
function getAnimation(key, value, target, transition, onComplete) {
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
let origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
|
|
3220
|
+
const valueTransition = getValueTransition(transition, key) || {};
|
|
3221
|
+
let origin = valueTransition.from !== undefined ? valueTransition.from : value.get();
|
|
3362
3222
|
const isTargetAnimatable = isAnimatable(key, target);
|
|
3363
3223
|
if (origin === "none" && isTargetAnimatable && typeof target === "string") {
|
|
3364
3224
|
/**
|
|
@@ -3387,24 +3247,25 @@
|
|
|
3387
3247
|
};
|
|
3388
3248
|
return valueTransition.type === "inertia" ||
|
|
3389
3249
|
valueTransition.type === "decay"
|
|
3390
|
-
? inertia(
|
|
3391
|
-
: animate$1(
|
|
3392
|
-
|
|
3250
|
+
? inertia({ ...options, ...valueTransition })
|
|
3251
|
+
: animate$1({
|
|
3252
|
+
...getPopmotionAnimationOptions(valueTransition, options, key),
|
|
3253
|
+
onUpdate: (v) => {
|
|
3393
3254
|
options.onUpdate(v);
|
|
3394
|
-
|
|
3395
|
-
},
|
|
3396
|
-
|
|
3255
|
+
valueTransition.onUpdate && valueTransition.onUpdate(v);
|
|
3256
|
+
},
|
|
3257
|
+
onComplete: () => {
|
|
3397
3258
|
options.onComplete();
|
|
3398
|
-
|
|
3399
|
-
}
|
|
3259
|
+
valueTransition.onComplete && valueTransition.onComplete();
|
|
3260
|
+
},
|
|
3261
|
+
});
|
|
3400
3262
|
}
|
|
3401
3263
|
function set() {
|
|
3402
|
-
var _a, _b;
|
|
3403
3264
|
const finalTarget = resolveFinalValueInKeyframes(target);
|
|
3404
3265
|
value.set(finalTarget);
|
|
3405
3266
|
onComplete();
|
|
3406
|
-
|
|
3407
|
-
|
|
3267
|
+
valueTransition.onUpdate && valueTransition.onUpdate(finalTarget);
|
|
3268
|
+
valueTransition.onComplete && valueTransition.onComplete();
|
|
3408
3269
|
return { stop: () => { } };
|
|
3409
3270
|
}
|
|
3410
3271
|
return !isOriginAnimatable ||
|
|
@@ -3449,7 +3310,7 @@
|
|
|
3449
3310
|
}
|
|
3450
3311
|
return () => {
|
|
3451
3312
|
clearTimeout(delayTimer);
|
|
3452
|
-
controls
|
|
3313
|
+
controls && controls.stop();
|
|
3453
3314
|
};
|
|
3454
3315
|
});
|
|
3455
3316
|
}
|
|
@@ -3543,7 +3404,7 @@
|
|
|
3543
3404
|
* This will be replaced by the build step with the latest version number.
|
|
3544
3405
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
3545
3406
|
*/
|
|
3546
|
-
this.version = "7.
|
|
3407
|
+
this.version = "7.3.1";
|
|
3547
3408
|
/**
|
|
3548
3409
|
* Duration, in milliseconds, since last updating frame.
|
|
3549
3410
|
*
|
|
@@ -3852,6 +3713,27 @@
|
|
|
3852
3713
|
*/
|
|
3853
3714
|
const findValueType = (v) => valueTypes.find(testValueType(v));
|
|
3854
3715
|
|
|
3716
|
+
/**
|
|
3717
|
+
* Creates an object containing the latest state of every MotionValue on a VisualElement
|
|
3718
|
+
*/
|
|
3719
|
+
function getCurrent(visualElement) {
|
|
3720
|
+
const current = {};
|
|
3721
|
+
visualElement.forEachValue((value, key) => (current[key] = value.get()));
|
|
3722
|
+
return current;
|
|
3723
|
+
}
|
|
3724
|
+
/**
|
|
3725
|
+
* Creates an object containing the latest velocity of every MotionValue on a VisualElement
|
|
3726
|
+
*/
|
|
3727
|
+
function getVelocity$1(visualElement) {
|
|
3728
|
+
const velocity = {};
|
|
3729
|
+
visualElement.forEachValue((value, key) => (velocity[key] = value.getVelocity()));
|
|
3730
|
+
return velocity;
|
|
3731
|
+
}
|
|
3732
|
+
function resolveVariant(visualElement, definition, custom) {
|
|
3733
|
+
const props = visualElement.getProps();
|
|
3734
|
+
return resolveVariantFromProps(props, definition, custom !== undefined ? custom : props.custom, getCurrent(visualElement), getVelocity$1(visualElement));
|
|
3735
|
+
}
|
|
3736
|
+
|
|
3855
3737
|
/**
|
|
3856
3738
|
* Set VisualElement's MotionValue, creating a new MotionValue for it if
|
|
3857
3739
|
* it doesn't exist.
|
|
@@ -3866,8 +3748,8 @@
|
|
|
3866
3748
|
}
|
|
3867
3749
|
function setTarget(visualElement, definition) {
|
|
3868
3750
|
const resolved = resolveVariant(visualElement, definition);
|
|
3869
|
-
let
|
|
3870
|
-
target =
|
|
3751
|
+
let { transitionEnd = {}, transition = {}, ...target } = resolved ? visualElement.makeTargetAnimatable(resolved, false) : {};
|
|
3752
|
+
target = { ...target, ...transitionEnd };
|
|
3871
3753
|
for (const key in target) {
|
|
3872
3754
|
const value = resolveFinalValueInKeyframes(target[key]);
|
|
3873
3755
|
setMotionValue(visualElement, key, value);
|
|
@@ -3896,8 +3778,7 @@
|
|
|
3896
3778
|
}
|
|
3897
3779
|
}
|
|
3898
3780
|
function checkTargetForNewValues(visualElement, target, origin) {
|
|
3899
|
-
var _a, _b
|
|
3900
|
-
var _d;
|
|
3781
|
+
var _a, _b;
|
|
3901
3782
|
const newValueKeys = Object.keys(target).filter((key) => !visualElement.hasValue(key));
|
|
3902
3783
|
const numNewValues = newValueKeys.length;
|
|
3903
3784
|
if (!numNewValues)
|
|
@@ -3936,7 +3817,9 @@
|
|
|
3936
3817
|
value = getAnimatableNone(key, targetValue);
|
|
3937
3818
|
}
|
|
3938
3819
|
visualElement.addValue(key, motionValue(value));
|
|
3939
|
-
|
|
3820
|
+
if (origin[key] === undefined) {
|
|
3821
|
+
origin[key] = value;
|
|
3822
|
+
}
|
|
3940
3823
|
visualElement.setBaseTarget(key, value);
|
|
3941
3824
|
}
|
|
3942
3825
|
}
|
|
@@ -3947,11 +3830,14 @@
|
|
|
3947
3830
|
return valueTransition.from;
|
|
3948
3831
|
}
|
|
3949
3832
|
function getOrigin(target, transition, visualElement) {
|
|
3950
|
-
var _a
|
|
3833
|
+
var _a;
|
|
3951
3834
|
const origin = {};
|
|
3952
3835
|
for (const key in target) {
|
|
3836
|
+
const transitionOrigin = getOriginFromTransition(key, transition);
|
|
3953
3837
|
origin[key] =
|
|
3954
|
-
|
|
3838
|
+
transitionOrigin !== undefined
|
|
3839
|
+
? transitionOrigin
|
|
3840
|
+
: (_a = visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.get();
|
|
3955
3841
|
}
|
|
3956
3842
|
return origin;
|
|
3957
3843
|
}
|
|
@@ -4022,7 +3908,7 @@
|
|
|
4022
3908
|
*/
|
|
4023
3909
|
function animateTarget(visualElement, definition, { delay = 0, transitionOverride, type } = {}) {
|
|
4024
3910
|
var _a;
|
|
4025
|
-
let
|
|
3911
|
+
let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = visualElement.makeTargetAnimatable(definition);
|
|
4026
3912
|
const willChange = visualElement.getValue("willChange");
|
|
4027
3913
|
if (transitionOverride)
|
|
4028
3914
|
transition = transitionOverride;
|
|
@@ -4037,12 +3923,16 @@
|
|
|
4037
3923
|
shouldBlockAnimation(animationTypeState, key))) {
|
|
4038
3924
|
continue;
|
|
4039
3925
|
}
|
|
4040
|
-
let valueTransition =
|
|
3926
|
+
let valueTransition = { delay, ...transition };
|
|
4041
3927
|
/**
|
|
4042
3928
|
* Make animation instant if this is a transform prop and we should reduce motion.
|
|
4043
3929
|
*/
|
|
4044
|
-
if (visualElement.shouldReduceMotion &&
|
|
4045
|
-
valueTransition =
|
|
3930
|
+
if (visualElement.shouldReduceMotion && transformProps.has(key)) {
|
|
3931
|
+
valueTransition = {
|
|
3932
|
+
...valueTransition,
|
|
3933
|
+
type: false,
|
|
3934
|
+
delay: 0,
|
|
3935
|
+
};
|
|
4046
3936
|
}
|
|
4047
3937
|
let animation = startAnimation(key, value, valueTarget, valueTransition);
|
|
4048
3938
|
if (isWillChangeMotionValue(willChange)) {
|
|
@@ -4064,7 +3954,10 @@
|
|
|
4064
3954
|
Array.from(visualElement.variantChildren)
|
|
4065
3955
|
.sort(sortByTreeOrder)
|
|
4066
3956
|
.forEach((child, i) => {
|
|
4067
|
-
animations.push(animateVariant(child, variant,
|
|
3957
|
+
animations.push(animateVariant(child, variant, {
|
|
3958
|
+
...options,
|
|
3959
|
+
delay: delayChildren + generateStaggerDuration(i),
|
|
3960
|
+
}).then(() => child.notifyAnimationComplete(variant)));
|
|
4068
3961
|
});
|
|
4069
3962
|
return Promise.all(animations);
|
|
4070
3963
|
}
|
|
@@ -4111,8 +4004,8 @@
|
|
|
4111
4004
|
const buildResolvedTypeValues = (acc, definition) => {
|
|
4112
4005
|
const resolved = resolveVariant(visualElement, definition);
|
|
4113
4006
|
if (resolved) {
|
|
4114
|
-
const { transition, transitionEnd
|
|
4115
|
-
acc =
|
|
4007
|
+
const { transition, transitionEnd, ...target } = resolved;
|
|
4008
|
+
acc = { ...acc, ...target, ...transitionEnd };
|
|
4116
4009
|
}
|
|
4117
4010
|
return acc;
|
|
4118
4011
|
};
|
|
@@ -4195,7 +4088,7 @@
|
|
|
4195
4088
|
* Set all encountered keys so far as the protected keys for this type. This will
|
|
4196
4089
|
* be any key that has been animated or otherwise handled by active, higher-priortiy types.
|
|
4197
4090
|
*/
|
|
4198
|
-
typeState.protectedKeys =
|
|
4091
|
+
typeState.protectedKeys = { ...encounteredKeys };
|
|
4199
4092
|
// Check if we can skip analysing this prop early
|
|
4200
4093
|
if (
|
|
4201
4094
|
// If it isn't active and hasn't *just* been set as inactive
|
|
@@ -4243,7 +4136,10 @@
|
|
|
4243
4136
|
* needs adding to the type's protectedKeys list.
|
|
4244
4137
|
*/
|
|
4245
4138
|
const { prevResolvedValues = {} } = typeState;
|
|
4246
|
-
const allKeys =
|
|
4139
|
+
const allKeys = {
|
|
4140
|
+
...prevResolvedValues,
|
|
4141
|
+
...resolvedValues,
|
|
4142
|
+
};
|
|
4247
4143
|
const markToAnimate = (key) => {
|
|
4248
4144
|
shouldAnimateType = true;
|
|
4249
4145
|
removedKeys.delete(key);
|
|
@@ -4309,7 +4205,7 @@
|
|
|
4309
4205
|
*
|
|
4310
4206
|
*/
|
|
4311
4207
|
if (typeState.isActive) {
|
|
4312
|
-
encounteredKeys =
|
|
4208
|
+
encounteredKeys = { ...encounteredKeys, ...resolvedValues };
|
|
4313
4209
|
}
|
|
4314
4210
|
if (isInitialRender && visualElement.blockInitialAnimation) {
|
|
4315
4211
|
shouldAnimateType = false;
|
|
@@ -4322,7 +4218,7 @@
|
|
|
4322
4218
|
if (shouldAnimateType && !isInherited) {
|
|
4323
4219
|
animations.push(...definitionList.map((animation) => ({
|
|
4324
4220
|
animation: animation,
|
|
4325
|
-
options:
|
|
4221
|
+
options: { type, ...options },
|
|
4326
4222
|
})));
|
|
4327
4223
|
}
|
|
4328
4224
|
}
|
|
@@ -4378,7 +4274,7 @@
|
|
|
4378
4274
|
if (typeof next === "string") {
|
|
4379
4275
|
return next !== prev;
|
|
4380
4276
|
}
|
|
4381
|
-
else if (
|
|
4277
|
+
else if (Array.isArray(next)) {
|
|
4382
4278
|
return !shallowCompare(next, prev);
|
|
4383
4279
|
}
|
|
4384
4280
|
return false;
|
|
@@ -4423,10 +4319,15 @@
|
|
|
4423
4319
|
const [isPresent, safeToRemove] = usePresence();
|
|
4424
4320
|
const presenceContext = React.useContext(PresenceContext);
|
|
4425
4321
|
React.useEffect(() => {
|
|
4426
|
-
var _a, _b;
|
|
4427
4322
|
visualElement.isPresent = isPresent;
|
|
4428
|
-
const animation =
|
|
4429
|
-
|
|
4323
|
+
const animation = visualElement.animationState &&
|
|
4324
|
+
visualElement.animationState.setActive(exports.AnimationType.Exit, !isPresent, {
|
|
4325
|
+
custom: (presenceContext && presenceContext.custom) ||
|
|
4326
|
+
custom,
|
|
4327
|
+
});
|
|
4328
|
+
if (animation && !isPresent) {
|
|
4329
|
+
animation.then(safeToRemove);
|
|
4330
|
+
}
|
|
4430
4331
|
}, [isPresent]);
|
|
4431
4332
|
}),
|
|
4432
4333
|
};
|
|
@@ -4465,7 +4366,7 @@
|
|
|
4465
4366
|
return;
|
|
4466
4367
|
const { point } = info;
|
|
4467
4368
|
const { timestamp } = getFrameData();
|
|
4468
|
-
this.history.push(
|
|
4369
|
+
this.history.push({ ...point, timestamp });
|
|
4469
4370
|
const { onStart, onMove } = this.handlers;
|
|
4470
4371
|
if (!isPanStarted) {
|
|
4471
4372
|
onStart && onStart(this.lastMoveEvent, info);
|
|
@@ -4502,7 +4403,7 @@
|
|
|
4502
4403
|
const initialInfo = transformPoint(info, this.transformPagePoint);
|
|
4503
4404
|
const { point } = initialInfo;
|
|
4504
4405
|
const { timestamp } = getFrameData();
|
|
4505
|
-
this.history = [
|
|
4406
|
+
this.history = [{ ...point, timestamp }];
|
|
4506
4407
|
const { onSessionStart } = handlers;
|
|
4507
4408
|
onSessionStart &&
|
|
4508
4409
|
onSessionStart(event, getPanInfo(initialInfo, this.history));
|
|
@@ -5147,8 +5048,17 @@
|
|
|
5147
5048
|
*/
|
|
5148
5049
|
const bounceStiffness = dragElastic ? 200 : 1000000;
|
|
5149
5050
|
const bounceDamping = dragElastic ? 40 : 10000000;
|
|
5150
|
-
const inertia =
|
|
5151
|
-
|
|
5051
|
+
const inertia = {
|
|
5052
|
+
type: "inertia",
|
|
5053
|
+
velocity: dragMomentum ? velocity[axis] : 0,
|
|
5054
|
+
bounceStiffness,
|
|
5055
|
+
bounceDamping,
|
|
5056
|
+
timeConstant: 750,
|
|
5057
|
+
restDelta: 1,
|
|
5058
|
+
restSpeed: 10,
|
|
5059
|
+
...dragTransition,
|
|
5060
|
+
...transition,
|
|
5061
|
+
};
|
|
5152
5062
|
// If we're not animating on an externally-provided `MotionValue` we can use the
|
|
5153
5063
|
// component's animation controls which will handle interactions with whileHover (etc),
|
|
5154
5064
|
// otherwise we just have to animate the `MotionValue` itself.
|
|
@@ -5300,12 +5210,15 @@
|
|
|
5300
5210
|
getProps() {
|
|
5301
5211
|
const props = this.visualElement.getProps();
|
|
5302
5212
|
const { drag = false, dragDirectionLock = false, dragPropagation = false, dragConstraints = false, dragElastic = defaultElastic, dragMomentum = true, } = props;
|
|
5303
|
-
return
|
|
5213
|
+
return {
|
|
5214
|
+
...props,
|
|
5215
|
+
drag,
|
|
5304
5216
|
dragDirectionLock,
|
|
5305
5217
|
dragPropagation,
|
|
5306
5218
|
dragConstraints,
|
|
5307
5219
|
dragElastic,
|
|
5308
|
-
dragMomentum
|
|
5220
|
+
dragMomentum,
|
|
5221
|
+
};
|
|
5309
5222
|
}
|
|
5310
5223
|
}
|
|
5311
5224
|
function shouldDrag(direction, drag, currentDirection) {
|
|
@@ -5389,6 +5302,25 @@
|
|
|
5389
5302
|
drag: makeRenderlessComponent(useDrag),
|
|
5390
5303
|
};
|
|
5391
5304
|
|
|
5305
|
+
// Does this device prefer reduced motion? Returns `null` server-side.
|
|
5306
|
+
const prefersReducedMotion = { current: null };
|
|
5307
|
+
const hasReducedMotionListener = { current: false };
|
|
5308
|
+
|
|
5309
|
+
function initPrefersReducedMotion() {
|
|
5310
|
+
hasReducedMotionListener.current = true;
|
|
5311
|
+
if (!isBrowser)
|
|
5312
|
+
return;
|
|
5313
|
+
if (window.matchMedia) {
|
|
5314
|
+
const motionMediaQuery = window.matchMedia("(prefers-reduced-motion)");
|
|
5315
|
+
const setReducedMotionPreferences = () => (prefersReducedMotion.current = motionMediaQuery.matches);
|
|
5316
|
+
motionMediaQuery.addListener(setReducedMotionPreferences);
|
|
5317
|
+
setReducedMotionPreferences();
|
|
5318
|
+
}
|
|
5319
|
+
else {
|
|
5320
|
+
prefersReducedMotion.current = false;
|
|
5321
|
+
}
|
|
5322
|
+
}
|
|
5323
|
+
|
|
5392
5324
|
const names = [
|
|
5393
5325
|
"LayoutMeasure",
|
|
5394
5326
|
"BeforeLayoutMeasure",
|
|
@@ -5430,7 +5362,6 @@
|
|
|
5430
5362
|
}
|
|
5431
5363
|
|
|
5432
5364
|
function updateMotionValuesFromProps(element, next, prev) {
|
|
5433
|
-
var _a;
|
|
5434
5365
|
const { willChange } = next;
|
|
5435
5366
|
for (const key in next) {
|
|
5436
5367
|
const nextValue = next[key];
|
|
@@ -5449,7 +5380,7 @@
|
|
|
5449
5380
|
* and warn against mismatches.
|
|
5450
5381
|
*/
|
|
5451
5382
|
{
|
|
5452
|
-
warnOnce(nextValue.version === "7.
|
|
5383
|
+
warnOnce(nextValue.version === "7.3.1", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.3.1 may not work as expected.`);
|
|
5453
5384
|
}
|
|
5454
5385
|
}
|
|
5455
5386
|
else if (isMotionValue(prevValue)) {
|
|
@@ -5474,7 +5405,8 @@
|
|
|
5474
5405
|
!existingValue.hasAnimated && existingValue.set(nextValue);
|
|
5475
5406
|
}
|
|
5476
5407
|
else {
|
|
5477
|
-
|
|
5408
|
+
const latestValue = element.getStaticValue(key);
|
|
5409
|
+
element.addValue(key, motionValue(latestValue !== undefined ? latestValue : nextValue));
|
|
5478
5410
|
}
|
|
5479
5411
|
}
|
|
5480
5412
|
}
|
|
@@ -5486,7 +5418,9 @@
|
|
|
5486
5418
|
return next;
|
|
5487
5419
|
}
|
|
5488
5420
|
|
|
5489
|
-
const
|
|
5421
|
+
const featureNames = Object.keys(featureDefinitions);
|
|
5422
|
+
const numFeatures = featureNames.length;
|
|
5423
|
+
const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatable, measureViewportBox, render: renderInstance, readValueFromInstance, removeValueFromRenderState, sortNodePosition, scrapeMotionValuesFromProps, }) => ({ parent, props, presenceId, blockInitialAnimation, visualState, reducedMotionConfig, }, options = {}) => {
|
|
5490
5424
|
let isMounted = false;
|
|
5491
5425
|
const { latestValues, renderState } = visualState;
|
|
5492
5426
|
/**
|
|
@@ -5522,7 +5456,9 @@
|
|
|
5522
5456
|
* When values are removed from all animation props we need to search
|
|
5523
5457
|
* for a fallback value to animate to. These values are tracked in baseTarget.
|
|
5524
5458
|
*/
|
|
5525
|
-
const baseTarget =
|
|
5459
|
+
const baseTarget = {
|
|
5460
|
+
...latestValues,
|
|
5461
|
+
};
|
|
5526
5462
|
// Internal methods ========================
|
|
5527
5463
|
/**
|
|
5528
5464
|
* On mount, this will be hydrated with a callback to disconnect
|
|
@@ -5569,7 +5505,7 @@
|
|
|
5569
5505
|
* Doing so will break some tests but this isn't neccessarily a breaking change,
|
|
5570
5506
|
* more a reflection of the test.
|
|
5571
5507
|
*/
|
|
5572
|
-
const
|
|
5508
|
+
const { willChange, ...initialMotionValues } = scrapeMotionValuesFromProps(props);
|
|
5573
5509
|
for (const key in initialMotionValues) {
|
|
5574
5510
|
const value = initialMotionValues[key];
|
|
5575
5511
|
if (latestValues[key] !== undefined && isMotionValue(value)) {
|
|
@@ -5582,36 +5518,39 @@
|
|
|
5582
5518
|
/**
|
|
5583
5519
|
* Determine what role this visual element should take in the variant tree.
|
|
5584
5520
|
*/
|
|
5585
|
-
const isControllingVariants =
|
|
5586
|
-
const isVariantNode =
|
|
5587
|
-
const element =
|
|
5521
|
+
const isControllingVariants$1 = isControllingVariants(props);
|
|
5522
|
+
const isVariantNode$1 = isVariantNode(props);
|
|
5523
|
+
const element = {
|
|
5524
|
+
treeType,
|
|
5588
5525
|
/**
|
|
5589
5526
|
* This is a mirror of the internal instance prop, which keeps
|
|
5590
5527
|
* VisualElement type-compatible with React's RefObject.
|
|
5591
5528
|
*/
|
|
5592
|
-
current: null,
|
|
5529
|
+
current: null,
|
|
5593
5530
|
/**
|
|
5594
5531
|
* The depth of this visual element within the visual element tree.
|
|
5595
5532
|
*/
|
|
5596
|
-
depth: parent ? parent.depth + 1 : 0,
|
|
5533
|
+
depth: parent ? parent.depth + 1 : 0,
|
|
5534
|
+
parent,
|
|
5535
|
+
children: new Set(),
|
|
5597
5536
|
/**
|
|
5598
5537
|
*
|
|
5599
5538
|
*/
|
|
5600
5539
|
presenceId,
|
|
5601
|
-
shouldReduceMotion,
|
|
5540
|
+
shouldReduceMotion: null,
|
|
5602
5541
|
/**
|
|
5603
5542
|
* If this component is part of the variant tree, it should track
|
|
5604
5543
|
* any children that are also part of the tree. This is essentially
|
|
5605
5544
|
* a shadow tree to simplify logic around how to stagger over children.
|
|
5606
5545
|
*/
|
|
5607
|
-
variantChildren: isVariantNode ? new Set() : undefined,
|
|
5546
|
+
variantChildren: isVariantNode$1 ? new Set() : undefined,
|
|
5608
5547
|
/**
|
|
5609
5548
|
* Whether this instance is visible. This can be changed imperatively
|
|
5610
5549
|
* by the projection tree, is analogous to CSS's visibility in that
|
|
5611
5550
|
* hidden elements should take up layout, and needs enacting by the configured
|
|
5612
5551
|
* render function.
|
|
5613
5552
|
*/
|
|
5614
|
-
isVisible: undefined,
|
|
5553
|
+
isVisible: undefined,
|
|
5615
5554
|
/**
|
|
5616
5555
|
* Normally, if a component is controlled by a parent's variants, it can
|
|
5617
5556
|
* rely on that ancestor to trigger animations further down the tree.
|
|
@@ -5620,27 +5559,37 @@
|
|
|
5620
5559
|
*
|
|
5621
5560
|
* TODO: This might be better replaced with a method isParentMounted
|
|
5622
5561
|
*/
|
|
5623
|
-
manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
|
|
5562
|
+
manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
|
|
5624
5563
|
/**
|
|
5625
5564
|
* This can be set by AnimatePresence to force components that mount
|
|
5626
5565
|
* at the same time as it to mount as if they have initial={false} set.
|
|
5627
5566
|
*/
|
|
5628
|
-
blockInitialAnimation,
|
|
5567
|
+
blockInitialAnimation,
|
|
5629
5568
|
/**
|
|
5630
5569
|
* Determine whether this component has mounted yet. This is mostly used
|
|
5631
5570
|
* by variant children to determine whether they need to trigger their
|
|
5632
5571
|
* own animations on mount.
|
|
5633
5572
|
*/
|
|
5634
|
-
isMounted: () => Boolean(instance),
|
|
5573
|
+
isMounted: () => Boolean(instance),
|
|
5574
|
+
mount(newInstance) {
|
|
5635
5575
|
isMounted = true;
|
|
5636
5576
|
instance = element.current = newInstance;
|
|
5637
5577
|
if (element.projection) {
|
|
5638
5578
|
element.projection.mount(newInstance);
|
|
5639
5579
|
}
|
|
5640
|
-
if (isVariantNode && parent && !isControllingVariants) {
|
|
5580
|
+
if (isVariantNode$1 && parent && !isControllingVariants$1) {
|
|
5641
5581
|
removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
|
|
5642
5582
|
}
|
|
5643
5583
|
values.forEach((value, key) => bindToMotionValue(key, value));
|
|
5584
|
+
if (!hasReducedMotionListener.current) {
|
|
5585
|
+
initPrefersReducedMotion();
|
|
5586
|
+
}
|
|
5587
|
+
element.shouldReduceMotion =
|
|
5588
|
+
reducedMotionConfig === "never"
|
|
5589
|
+
? false
|
|
5590
|
+
: reducedMotionConfig === "always"
|
|
5591
|
+
? true
|
|
5592
|
+
: prefersReducedMotion.current;
|
|
5644
5593
|
parent === null || parent === void 0 ? void 0 : parent.children.add(element);
|
|
5645
5594
|
element.setProps(props);
|
|
5646
5595
|
},
|
|
@@ -5659,6 +5608,55 @@
|
|
|
5659
5608
|
instance = undefined;
|
|
5660
5609
|
isMounted = false;
|
|
5661
5610
|
},
|
|
5611
|
+
loadFeatures(renderedProps, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
|
|
5612
|
+
const features = [];
|
|
5613
|
+
/**
|
|
5614
|
+
* If we're in development mode, check to make sure we're not rendering a motion component
|
|
5615
|
+
* as a child of LazyMotion, as this will break the file-size benefits of using it.
|
|
5616
|
+
*/
|
|
5617
|
+
if (env !== "production" && preloadedFeatures && isStrict) {
|
|
5618
|
+
invariant(false, "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.");
|
|
5619
|
+
}
|
|
5620
|
+
for (let i = 0; i < numFeatures; i++) {
|
|
5621
|
+
const name = featureNames[i];
|
|
5622
|
+
const { isEnabled, Component } = featureDefinitions[name];
|
|
5623
|
+
/**
|
|
5624
|
+
* It might be possible in the future to use this moment to
|
|
5625
|
+
* dynamically request functionality. In initial tests this
|
|
5626
|
+
* was producing a lot of duplication amongst bundles.
|
|
5627
|
+
*/
|
|
5628
|
+
if (isEnabled(props) && Component) {
|
|
5629
|
+
features.push(React.createElement(Component, {
|
|
5630
|
+
key: name,
|
|
5631
|
+
...renderedProps,
|
|
5632
|
+
visualElement: element,
|
|
5633
|
+
}));
|
|
5634
|
+
}
|
|
5635
|
+
}
|
|
5636
|
+
if (!element.projection && ProjectionNodeConstructor) {
|
|
5637
|
+
element.projection = new ProjectionNodeConstructor(projectionId, element.getLatestValues(), parent && parent.projection);
|
|
5638
|
+
const { layoutId, layout, drag, dragConstraints, layoutScroll, } = renderedProps;
|
|
5639
|
+
element.projection.setOptions({
|
|
5640
|
+
layoutId,
|
|
5641
|
+
layout,
|
|
5642
|
+
alwaysMeasureLayout: Boolean(drag) ||
|
|
5643
|
+
(dragConstraints && isRefObject(dragConstraints)),
|
|
5644
|
+
visualElement: element,
|
|
5645
|
+
scheduleRender: () => element.scheduleRender(),
|
|
5646
|
+
/**
|
|
5647
|
+
* TODO: Update options in an effect. This could be tricky as it'll be too late
|
|
5648
|
+
* to update by the time layout animations run.
|
|
5649
|
+
* We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
|
|
5650
|
+
* ensuring it gets called if there's no potential layout animations.
|
|
5651
|
+
*
|
|
5652
|
+
*/
|
|
5653
|
+
animationType: typeof layout === "string" ? layout : "both",
|
|
5654
|
+
initialPromotionConfig: initialLayoutGroupConfig,
|
|
5655
|
+
layoutScroll,
|
|
5656
|
+
});
|
|
5657
|
+
}
|
|
5658
|
+
return features;
|
|
5659
|
+
},
|
|
5662
5660
|
/**
|
|
5663
5661
|
* Add a child visual element to our set of children.
|
|
5664
5662
|
*/
|
|
@@ -5677,30 +5675,31 @@
|
|
|
5677
5675
|
if (!sortNodePosition || treeType !== other.treeType)
|
|
5678
5676
|
return 0;
|
|
5679
5677
|
return sortNodePosition(element.getInstance(), other.getInstance());
|
|
5680
|
-
},
|
|
5678
|
+
},
|
|
5681
5679
|
/**
|
|
5682
5680
|
* Returns the closest variant node in the tree starting from
|
|
5683
5681
|
* this visual element.
|
|
5684
5682
|
*/
|
|
5685
|
-
getClosestVariantNode: () => isVariantNode ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
|
|
5683
|
+
getClosestVariantNode: () => isVariantNode$1 ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
|
|
5686
5684
|
/**
|
|
5687
5685
|
* Expose the latest layoutId prop.
|
|
5688
5686
|
*/
|
|
5689
|
-
getLayoutId: () => props.layoutId,
|
|
5687
|
+
getLayoutId: () => props.layoutId,
|
|
5690
5688
|
/**
|
|
5691
5689
|
* Returns the current instance.
|
|
5692
5690
|
*/
|
|
5693
|
-
getInstance: () => instance,
|
|
5691
|
+
getInstance: () => instance,
|
|
5694
5692
|
/**
|
|
5695
5693
|
* Get/set the latest static values.
|
|
5696
5694
|
*/
|
|
5697
|
-
getStaticValue: (key) => latestValues[key],
|
|
5695
|
+
getStaticValue: (key) => latestValues[key],
|
|
5696
|
+
setStaticValue: (key, value) => (latestValues[key] = value),
|
|
5698
5697
|
/**
|
|
5699
5698
|
* Returns the latest motion value state. Currently only used to take
|
|
5700
5699
|
* a snapshot of the visual element - perhaps this can return the whole
|
|
5701
5700
|
* visual state
|
|
5702
5701
|
*/
|
|
5703
|
-
getLatestValues: () => latestValues,
|
|
5702
|
+
getLatestValues: () => latestValues,
|
|
5704
5703
|
/**
|
|
5705
5704
|
* Set the visiblity of the visual element. If it's changed, schedule
|
|
5706
5705
|
* a render to reflect these changes.
|
|
@@ -5751,11 +5750,11 @@
|
|
|
5751
5750
|
valueSubscriptions.delete(key);
|
|
5752
5751
|
delete latestValues[key];
|
|
5753
5752
|
removeValueFromRenderState(key, renderState);
|
|
5754
|
-
},
|
|
5753
|
+
},
|
|
5755
5754
|
/**
|
|
5756
5755
|
* Check whether we have a motion value for this key
|
|
5757
5756
|
*/
|
|
5758
|
-
hasValue: (key) => values.has(key),
|
|
5757
|
+
hasValue: (key) => values.has(key),
|
|
5759
5758
|
/**
|
|
5760
5759
|
* Get a motion value for this key. If called with a default
|
|
5761
5760
|
* value, we'll create one if none exists.
|
|
@@ -5767,20 +5766,19 @@
|
|
|
5767
5766
|
element.addValue(key, value);
|
|
5768
5767
|
}
|
|
5769
5768
|
return value;
|
|
5770
|
-
},
|
|
5769
|
+
},
|
|
5771
5770
|
/**
|
|
5772
5771
|
* Iterate over our motion values.
|
|
5773
5772
|
*/
|
|
5774
|
-
forEachValue: (callback) => values.forEach(callback),
|
|
5773
|
+
forEachValue: (callback) => values.forEach(callback),
|
|
5775
5774
|
/**
|
|
5776
5775
|
* If we're trying to animate to a previously unencountered value,
|
|
5777
5776
|
* we need to check for it in our state and as a last resort read it
|
|
5778
5777
|
* directly from the instance (which might have performance implications).
|
|
5779
5778
|
*/
|
|
5780
|
-
readValue: (key) =>
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
},
|
|
5779
|
+
readValue: (key) => latestValues[key] !== undefined
|
|
5780
|
+
? latestValues[key]
|
|
5781
|
+
: readValueFromInstance(instance, key, options),
|
|
5784
5782
|
/**
|
|
5785
5783
|
* Set the base target to later animate back to. This is currently
|
|
5786
5784
|
* only hydrated on creation and when we first read a value.
|
|
@@ -5799,7 +5797,9 @@
|
|
|
5799
5797
|
return target;
|
|
5800
5798
|
}
|
|
5801
5799
|
return baseTarget[key];
|
|
5802
|
-
}
|
|
5800
|
+
},
|
|
5801
|
+
// Lifecyles ========================
|
|
5802
|
+
...lifecycles,
|
|
5803
5803
|
/**
|
|
5804
5804
|
* Build the renderer state based on the latest visual state.
|
|
5805
5805
|
*/
|
|
@@ -5812,14 +5812,14 @@
|
|
|
5812
5812
|
*/
|
|
5813
5813
|
scheduleRender() {
|
|
5814
5814
|
sync.render(render, false, true);
|
|
5815
|
-
},
|
|
5815
|
+
},
|
|
5816
5816
|
/**
|
|
5817
5817
|
* Synchronously fire render. It's prefered that we batch renders but
|
|
5818
5818
|
* in many circumstances, like layout measurement, we need to run this
|
|
5819
5819
|
* synchronously. However in those instances other measures should be taken
|
|
5820
5820
|
* to batch reads/writes.
|
|
5821
5821
|
*/
|
|
5822
|
-
syncRender: render,
|
|
5822
|
+
syncRender: render,
|
|
5823
5823
|
/**
|
|
5824
5824
|
* Update the provided props. Ensure any newly-added motion values are
|
|
5825
5825
|
* added to our map, old ones removed, and listeners updated.
|
|
@@ -5831,25 +5831,27 @@
|
|
|
5831
5831
|
props = newProps;
|
|
5832
5832
|
lifecycles.updatePropListeners(newProps);
|
|
5833
5833
|
prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
|
|
5834
|
-
},
|
|
5834
|
+
},
|
|
5835
|
+
getProps: () => props,
|
|
5835
5836
|
// Variants ==============================
|
|
5836
5837
|
/**
|
|
5837
5838
|
* Returns the variant definition with a given name.
|
|
5838
5839
|
*/
|
|
5839
|
-
getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
5840
|
+
getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
5840
5841
|
/**
|
|
5841
5842
|
* Returns the defined default transition on this component.
|
|
5842
5843
|
*/
|
|
5843
|
-
getDefaultTransition: () => props.transition,
|
|
5844
|
+
getDefaultTransition: () => props.transition,
|
|
5845
|
+
getTransformPagePoint: () => {
|
|
5844
5846
|
return props.transformPagePoint;
|
|
5845
|
-
},
|
|
5847
|
+
},
|
|
5846
5848
|
/**
|
|
5847
5849
|
* Used by child variant nodes to get the closest ancestor variant props.
|
|
5848
5850
|
*/
|
|
5849
5851
|
getVariantContext(startAtParent = false) {
|
|
5850
5852
|
if (startAtParent)
|
|
5851
5853
|
return parent === null || parent === void 0 ? void 0 : parent.getVariantContext();
|
|
5852
|
-
if (!isControllingVariants) {
|
|
5854
|
+
if (!isControllingVariants$1) {
|
|
5853
5855
|
const context = (parent === null || parent === void 0 ? void 0 : parent.getVariantContext()) || {};
|
|
5854
5856
|
if (props.initial !== undefined) {
|
|
5855
5857
|
context.initial = props.initial;
|
|
@@ -5865,7 +5867,8 @@
|
|
|
5865
5867
|
}
|
|
5866
5868
|
}
|
|
5867
5869
|
return context;
|
|
5868
|
-
}
|
|
5870
|
+
},
|
|
5871
|
+
};
|
|
5869
5872
|
return element;
|
|
5870
5873
|
};
|
|
5871
5874
|
const variantProps = ["initial", ...variantPriorityOrder];
|
|
@@ -5916,16 +5919,14 @@
|
|
|
5916
5919
|
*
|
|
5917
5920
|
* @internal
|
|
5918
5921
|
*/
|
|
5919
|
-
function resolveCSSVariables(visualElement,
|
|
5920
|
-
var _b;
|
|
5921
|
-
var target = __rest(_a, []);
|
|
5922
|
+
function resolveCSSVariables(visualElement, { ...target }, transitionEnd) {
|
|
5922
5923
|
const element = visualElement.getInstance();
|
|
5923
5924
|
if (!(element instanceof Element))
|
|
5924
5925
|
return { target, transitionEnd };
|
|
5925
5926
|
// If `transitionEnd` isn't `undefined`, clone it. We could clone `target` and `transitionEnd`
|
|
5926
5927
|
// only if they change but I think this reads clearer and this isn't a performance-critical path.
|
|
5927
5928
|
if (transitionEnd) {
|
|
5928
|
-
transitionEnd =
|
|
5929
|
+
transitionEnd = { ...transitionEnd };
|
|
5929
5930
|
}
|
|
5930
5931
|
// Go through existing `MotionValue`s and ensure any existing CSS variables are resolved
|
|
5931
5932
|
visualElement.forEachValue((value) => {
|
|
@@ -5950,8 +5951,9 @@
|
|
|
5950
5951
|
// If the user hasn't already set this key on `transitionEnd`, set it to the unresolved
|
|
5951
5952
|
// CSS variable. This will ensure that after the animation the component will reflect
|
|
5952
5953
|
// changes in the value of the CSS variable.
|
|
5953
|
-
if (transitionEnd)
|
|
5954
|
-
|
|
5954
|
+
if (transitionEnd && transitionEnd[key] === undefined) {
|
|
5955
|
+
transitionEnd[key] = current;
|
|
5956
|
+
}
|
|
5955
5957
|
}
|
|
5956
5958
|
return { target, transitionEnd };
|
|
5957
5959
|
}
|
|
@@ -6005,7 +6007,7 @@
|
|
|
6005
6007
|
}
|
|
6006
6008
|
};
|
|
6007
6009
|
const transformKeys = new Set(["x", "y", "z"]);
|
|
6008
|
-
const nonTranslationalTransformKeys =
|
|
6010
|
+
const nonTranslationalTransformKeys = transformPropOrder.filter((key) => !transformKeys.has(key));
|
|
6009
6011
|
function removeNonTranslationalTransform(visualElement) {
|
|
6010
6012
|
const removedTransforms = [];
|
|
6011
6013
|
nonTranslationalTransformKeys.forEach((key) => {
|
|
@@ -6062,8 +6064,8 @@
|
|
|
6062
6064
|
return target;
|
|
6063
6065
|
};
|
|
6064
6066
|
const checkAndConvertChangedValueTypes = (visualElement, target, origin = {}, transitionEnd = {}) => {
|
|
6065
|
-
target =
|
|
6066
|
-
transitionEnd =
|
|
6067
|
+
target = { ...target };
|
|
6068
|
+
transitionEnd = { ...transitionEnd };
|
|
6067
6069
|
const targetPositionalKeys = Object.keys(target).filter(isPositionalKey);
|
|
6068
6070
|
// We want to remove any transform values that could affect the element's bounding box before
|
|
6069
6071
|
// it's measured. We'll reapply these later.
|
|
@@ -6198,7 +6200,7 @@
|
|
|
6198
6200
|
const htmlConfig = {
|
|
6199
6201
|
treeType: "dom",
|
|
6200
6202
|
readValueFromInstance(domElement, key) {
|
|
6201
|
-
if (
|
|
6203
|
+
if (transformProps.has(key)) {
|
|
6202
6204
|
const defaultType = getDefaultValueType(key);
|
|
6203
6205
|
return defaultType ? defaultType.default || 0 : 0;
|
|
6204
6206
|
}
|
|
@@ -6251,10 +6253,7 @@
|
|
|
6251
6253
|
* Ensure that HTML and Framer-specific value types like `px`->`%` and `Color`
|
|
6252
6254
|
* can be animated by Motion.
|
|
6253
6255
|
*/
|
|
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; }
|
|
6256
|
+
makeTargetAnimatable(element, { transition, transitionEnd, ...target }, { transformValues }, isMounted = true) {
|
|
6258
6257
|
let origin = getOrigin(target, transition || {}, element);
|
|
6259
6258
|
/**
|
|
6260
6259
|
* If Framer has provided a function to convert `Color` etc value types, convert them
|
|
@@ -6273,8 +6272,11 @@
|
|
|
6273
6272
|
transitionEnd = parsed.transitionEnd;
|
|
6274
6273
|
target = parsed.target;
|
|
6275
6274
|
}
|
|
6276
|
-
return
|
|
6277
|
-
|
|
6275
|
+
return {
|
|
6276
|
+
transition,
|
|
6277
|
+
transitionEnd,
|
|
6278
|
+
...target,
|
|
6279
|
+
};
|
|
6278
6280
|
},
|
|
6279
6281
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps$1,
|
|
6280
6282
|
build(element, renderState, latestValues, options, props) {
|
|
@@ -6289,12 +6291,14 @@
|
|
|
6289
6291
|
};
|
|
6290
6292
|
const htmlVisualElement = visualElement(htmlConfig);
|
|
6291
6293
|
|
|
6292
|
-
const svgVisualElement = visualElement(
|
|
6294
|
+
const svgVisualElement = visualElement({
|
|
6295
|
+
...htmlConfig,
|
|
6296
|
+
getBaseTarget(props, key) {
|
|
6293
6297
|
return props[key];
|
|
6294
6298
|
},
|
|
6295
6299
|
readValueFromInstance(domElement, key) {
|
|
6296
6300
|
var _a;
|
|
6297
|
-
if (
|
|
6301
|
+
if (transformProps.has(key)) {
|
|
6298
6302
|
return ((_a = getDefaultValueType(key)) === null || _a === void 0 ? void 0 : _a.default) || 0;
|
|
6299
6303
|
}
|
|
6300
6304
|
key = !camelCaseAttributes.has(key) ? camelToDash(key) : key;
|
|
@@ -6303,7 +6307,9 @@
|
|
|
6303
6307
|
scrapeMotionValuesFromProps,
|
|
6304
6308
|
build(_element, renderState, latestValues, options, props) {
|
|
6305
6309
|
buildSVGAttrs(renderState, latestValues, options, props.transformTemplate);
|
|
6306
|
-
},
|
|
6310
|
+
},
|
|
6311
|
+
render: renderSVG,
|
|
6312
|
+
});
|
|
6307
6313
|
|
|
6308
6314
|
const createDomVisualElement = (Component, options) => {
|
|
6309
6315
|
return isSVGComponent(Component)
|
|
@@ -6412,16 +6418,19 @@
|
|
|
6412
6418
|
const { projection } = visualElement;
|
|
6413
6419
|
addScaleCorrector(defaultScaleCorrectors);
|
|
6414
6420
|
if (projection) {
|
|
6415
|
-
if (layoutGroup
|
|
6421
|
+
if (layoutGroup.group)
|
|
6416
6422
|
layoutGroup.group.add(projection);
|
|
6417
|
-
if (
|
|
6423
|
+
if (switchLayoutGroup && switchLayoutGroup.register && layoutId) {
|
|
6418
6424
|
switchLayoutGroup.register(projection);
|
|
6419
6425
|
}
|
|
6420
6426
|
projection.root.didUpdate();
|
|
6421
6427
|
projection.addEventListener("animationComplete", () => {
|
|
6422
6428
|
this.safeToRemove();
|
|
6423
6429
|
});
|
|
6424
|
-
projection.setOptions(
|
|
6430
|
+
projection.setOptions({
|
|
6431
|
+
...projection.options,
|
|
6432
|
+
onExitComplete: () => this.safeToRemove(),
|
|
6433
|
+
});
|
|
6425
6434
|
}
|
|
6426
6435
|
globalProjectionState.hasEverUpdated = true;
|
|
6427
6436
|
}
|
|
@@ -6497,15 +6506,18 @@
|
|
|
6497
6506
|
function MeasureLayout(props) {
|
|
6498
6507
|
const [isPresent, safeToRemove] = usePresence();
|
|
6499
6508
|
const layoutGroup = React.useContext(LayoutGroupContext);
|
|
6500
|
-
return (React__default["default"].createElement(MeasureLayoutWithContext,
|
|
6509
|
+
return (React__default["default"].createElement(MeasureLayoutWithContext, { ...props, layoutGroup: layoutGroup, switchLayoutGroup: React.useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove }));
|
|
6501
6510
|
}
|
|
6502
6511
|
const defaultScaleCorrectors = {
|
|
6503
|
-
borderRadius:
|
|
6512
|
+
borderRadius: {
|
|
6513
|
+
...correctBorderRadius,
|
|
6514
|
+
applyTo: [
|
|
6504
6515
|
"borderTopLeftRadius",
|
|
6505
6516
|
"borderTopRightRadius",
|
|
6506
6517
|
"borderBottomLeftRadius",
|
|
6507
6518
|
"borderBottomRightRadius",
|
|
6508
|
-
]
|
|
6519
|
+
],
|
|
6520
|
+
},
|
|
6509
6521
|
borderTopLeftRadius: correctBorderRadius,
|
|
6510
6522
|
borderTopRightRadius: correctBorderRadius,
|
|
6511
6523
|
borderBottomLeftRadius: correctBorderRadius,
|
|
@@ -6720,6 +6732,12 @@
|
|
|
6720
6732
|
a.y.min === b.y.min &&
|
|
6721
6733
|
a.y.max === b.y.max);
|
|
6722
6734
|
}
|
|
6735
|
+
function aspectRatio(box) {
|
|
6736
|
+
return calcLength(box.x) / calcLength(box.y);
|
|
6737
|
+
}
|
|
6738
|
+
function isCloseTo(a, b, max = 0.01) {
|
|
6739
|
+
return distance(a, b) <= max;
|
|
6740
|
+
}
|
|
6723
6741
|
|
|
6724
6742
|
class NodeStack {
|
|
6725
6743
|
constructor() {
|
|
@@ -6886,6 +6904,7 @@
|
|
|
6886
6904
|
}
|
|
6887
6905
|
}
|
|
6888
6906
|
|
|
6907
|
+
const transformAxes = ["", "X", "Y", "Z"];
|
|
6889
6908
|
/**
|
|
6890
6909
|
* We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
|
|
6891
6910
|
* which has a noticeable difference in spring animations
|
|
@@ -7077,7 +7096,11 @@
|
|
|
7077
7096
|
this.resumingFrom.resumingFrom = undefined;
|
|
7078
7097
|
}
|
|
7079
7098
|
this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
|
|
7080
|
-
const animationOptions =
|
|
7099
|
+
const animationOptions = {
|
|
7100
|
+
...getValueTransition(layoutTransition, "layout"),
|
|
7101
|
+
onPlay: onLayoutAnimationStart,
|
|
7102
|
+
onComplete: onLayoutAnimationComplete,
|
|
7103
|
+
};
|
|
7081
7104
|
if (visualElement.shouldReduceMotion) {
|
|
7082
7105
|
animationOptions.delay = 0;
|
|
7083
7106
|
animationOptions.type = false;
|
|
@@ -7400,8 +7423,11 @@
|
|
|
7400
7423
|
this.root.scheduleUpdateProjection();
|
|
7401
7424
|
}
|
|
7402
7425
|
setOptions(options) {
|
|
7403
|
-
|
|
7404
|
-
|
|
7426
|
+
this.options = {
|
|
7427
|
+
...this.options,
|
|
7428
|
+
...options,
|
|
7429
|
+
crossfade: options.crossfade !== undefined ? options.crossfade : true,
|
|
7430
|
+
};
|
|
7405
7431
|
}
|
|
7406
7432
|
clearMeasurements() {
|
|
7407
7433
|
this.scroll = undefined;
|
|
@@ -7583,7 +7609,7 @@
|
|
|
7583
7609
|
var _a;
|
|
7584
7610
|
const snapshot = this.snapshot;
|
|
7585
7611
|
const snapshotLatestValues = (snapshot === null || snapshot === void 0 ? void 0 : snapshot.latestValues) || {};
|
|
7586
|
-
const mixedValues =
|
|
7612
|
+
const mixedValues = { ...this.latestValues };
|
|
7587
7613
|
const targetDelta = createDelta();
|
|
7588
7614
|
this.relativeTarget = this.relativeTargetOrigin = undefined;
|
|
7589
7615
|
this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
|
|
@@ -7636,15 +7662,19 @@
|
|
|
7636
7662
|
*/
|
|
7637
7663
|
this.pendingAnimation = sync.update(() => {
|
|
7638
7664
|
globalProjectionState.hasAnimatedSinceResize = true;
|
|
7639
|
-
this.currentAnimation = animate(0, animationTarget,
|
|
7665
|
+
this.currentAnimation = animate(0, animationTarget, {
|
|
7666
|
+
...options,
|
|
7667
|
+
onUpdate: (latest) => {
|
|
7640
7668
|
var _a;
|
|
7641
7669
|
this.mixTargetDelta(latest);
|
|
7642
7670
|
(_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, latest);
|
|
7643
|
-
},
|
|
7671
|
+
},
|
|
7672
|
+
onComplete: () => {
|
|
7644
7673
|
var _a;
|
|
7645
7674
|
(_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
7646
7675
|
this.completeAnimation();
|
|
7647
|
-
}
|
|
7676
|
+
},
|
|
7677
|
+
});
|
|
7648
7678
|
if (this.resumingFrom) {
|
|
7649
7679
|
this.resumingFrom.currentAnimation = this.currentAnimation;
|
|
7650
7680
|
}
|
|
@@ -7673,9 +7703,27 @@
|
|
|
7673
7703
|
this.completeAnimation();
|
|
7674
7704
|
}
|
|
7675
7705
|
applyTransformsToTarget() {
|
|
7676
|
-
const
|
|
7706
|
+
const lead = this.getLead();
|
|
7707
|
+
let { targetWithTransforms, target, layout, latestValues } = lead;
|
|
7677
7708
|
if (!targetWithTransforms || !target || !layout)
|
|
7678
7709
|
return;
|
|
7710
|
+
/**
|
|
7711
|
+
* If we're only animating position, and this element isn't the lead element,
|
|
7712
|
+
* then instead of projecting into the lead box we instead want to calculate
|
|
7713
|
+
* a new target that aligns the two boxes but maintains the layout shape.
|
|
7714
|
+
*/
|
|
7715
|
+
if (this !== lead &&
|
|
7716
|
+
this.layout &&
|
|
7717
|
+
layout &&
|
|
7718
|
+
shouldAnimatePositionOnly(this.options.animationType, this.layout.actual, layout.actual)) {
|
|
7719
|
+
target = this.target || createBox();
|
|
7720
|
+
const xLength = calcLength(this.layout.actual.x);
|
|
7721
|
+
target.x.min = lead.target.x.min;
|
|
7722
|
+
target.x.max = target.x.min + xLength;
|
|
7723
|
+
const yLength = calcLength(this.layout.actual.y);
|
|
7724
|
+
target.y.min = lead.target.y.min;
|
|
7725
|
+
target.y.max = target.y.min + yLength;
|
|
7726
|
+
}
|
|
7679
7727
|
copyBoxInto(targetWithTransforms, target);
|
|
7680
7728
|
/**
|
|
7681
7729
|
* Apply the latest user-set transforms to the targetBox to produce the targetBoxFinal.
|
|
@@ -7779,7 +7827,7 @@
|
|
|
7779
7827
|
visualElement.scheduleRender();
|
|
7780
7828
|
}
|
|
7781
7829
|
getProjectionStyles(styleProp = {}) {
|
|
7782
|
-
var _a, _b, _c
|
|
7830
|
+
var _a, _b, _c;
|
|
7783
7831
|
// TODO: Return lifecycle-persistent object
|
|
7784
7832
|
const styles = {};
|
|
7785
7833
|
if (!this.instance || this.isSVG)
|
|
@@ -7805,7 +7853,10 @@
|
|
|
7805
7853
|
if (!this.projectionDelta || !this.layout || !lead.target) {
|
|
7806
7854
|
const emptyStyles = {};
|
|
7807
7855
|
if (this.options.layoutId) {
|
|
7808
|
-
emptyStyles.opacity =
|
|
7856
|
+
emptyStyles.opacity =
|
|
7857
|
+
this.latestValues.opacity !== undefined
|
|
7858
|
+
? this.latestValues.opacity
|
|
7859
|
+
: 1;
|
|
7809
7860
|
emptyStyles.pointerEvents =
|
|
7810
7861
|
resolveMotionValue(styleProp.pointerEvents) || "";
|
|
7811
7862
|
}
|
|
@@ -7832,7 +7883,7 @@
|
|
|
7832
7883
|
*/
|
|
7833
7884
|
styles.opacity =
|
|
7834
7885
|
lead === this
|
|
7835
|
-
? (
|
|
7886
|
+
? (_c = (_b = valuesToRender.opacity) !== null && _b !== void 0 ? _b : this.latestValues.opacity) !== null && _c !== void 0 ? _c : 1
|
|
7836
7887
|
: this.preserveOpacity
|
|
7837
7888
|
? this.latestValues.opacity
|
|
7838
7889
|
: valuesToRender.opacityExit;
|
|
@@ -7844,8 +7895,12 @@
|
|
|
7844
7895
|
*/
|
|
7845
7896
|
styles.opacity =
|
|
7846
7897
|
lead === this
|
|
7847
|
-
?
|
|
7848
|
-
|
|
7898
|
+
? valuesToRender.opacity !== undefined
|
|
7899
|
+
? valuesToRender.opacity
|
|
7900
|
+
: ""
|
|
7901
|
+
: valuesToRender.opacityExit !== undefined
|
|
7902
|
+
? valuesToRender.opacityExit
|
|
7903
|
+
: 0;
|
|
7849
7904
|
}
|
|
7850
7905
|
/**
|
|
7851
7906
|
* Apply scale correction
|
|
@@ -7893,16 +7948,17 @@
|
|
|
7893
7948
|
node.updateLayout();
|
|
7894
7949
|
}
|
|
7895
7950
|
function notifyLayoutUpdate(node) {
|
|
7896
|
-
var _a, _b, _c
|
|
7897
|
-
const snapshot = (
|
|
7951
|
+
var _a, _b, _c;
|
|
7952
|
+
const snapshot = ((_a = node.resumeFrom) === null || _a === void 0 ? void 0 : _a.snapshot) || node.snapshot;
|
|
7898
7953
|
if (node.isLead() &&
|
|
7899
7954
|
node.layout &&
|
|
7900
7955
|
snapshot &&
|
|
7901
7956
|
node.hasListeners("didUpdate")) {
|
|
7902
7957
|
const { actual: layout, measured: measuredLayout } = node.layout;
|
|
7958
|
+
const { animationType } = node.options;
|
|
7903
7959
|
// TODO Maybe we want to also resize the layout snapshot so we don't trigger
|
|
7904
7960
|
// animations for instance if layout="size" and an element has only changed position
|
|
7905
|
-
if (
|
|
7961
|
+
if (animationType === "size") {
|
|
7906
7962
|
eachAxis((axis) => {
|
|
7907
7963
|
const axisSnapshot = snapshot.isShared
|
|
7908
7964
|
? snapshot.measured[axis]
|
|
@@ -7912,7 +7968,7 @@
|
|
|
7912
7968
|
axisSnapshot.max = axisSnapshot.min + length;
|
|
7913
7969
|
});
|
|
7914
7970
|
}
|
|
7915
|
-
else if (
|
|
7971
|
+
else if (shouldAnimatePositionOnly(animationType, snapshot.layout, layout)) {
|
|
7916
7972
|
eachAxis((axis) => {
|
|
7917
7973
|
const axisSnapshot = snapshot.isShared
|
|
7918
7974
|
? snapshot.measured[axis]
|
|
@@ -7961,7 +8017,7 @@
|
|
|
7961
8017
|
});
|
|
7962
8018
|
}
|
|
7963
8019
|
else if (node.isLead()) {
|
|
7964
|
-
(
|
|
8020
|
+
(_c = (_b = node.options).onExitComplete) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
7965
8021
|
}
|
|
7966
8022
|
/**
|
|
7967
8023
|
* Clearing transition
|
|
@@ -8045,6 +8101,11 @@
|
|
|
8045
8101
|
roundAxis(box.x);
|
|
8046
8102
|
roundAxis(box.y);
|
|
8047
8103
|
}
|
|
8104
|
+
function shouldAnimatePositionOnly(animationType, snapshot, layout) {
|
|
8105
|
+
return (animationType === "position" ||
|
|
8106
|
+
(animationType === "preserve-aspect" &&
|
|
8107
|
+
!isCloseTo(aspectRatio(snapshot), aspectRatio(layout))));
|
|
8108
|
+
}
|
|
8048
8109
|
|
|
8049
8110
|
const DocumentProjectionNode = createProjectionNode({
|
|
8050
8111
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
@@ -8073,12 +8134,17 @@
|
|
|
8073
8134
|
return rootProjectionNode.current;
|
|
8074
8135
|
},
|
|
8075
8136
|
resetTransform: (instance, value) => {
|
|
8076
|
-
instance.style.transform = value !==
|
|
8137
|
+
instance.style.transform = value !== undefined ? value : "none";
|
|
8077
8138
|
},
|
|
8078
8139
|
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
8079
8140
|
});
|
|
8080
8141
|
|
|
8081
|
-
const featureBundle =
|
|
8142
|
+
const featureBundle = {
|
|
8143
|
+
...animations,
|
|
8144
|
+
...gestureAnimations,
|
|
8145
|
+
...drag,
|
|
8146
|
+
...layoutFeatures,
|
|
8147
|
+
};
|
|
8082
8148
|
/**
|
|
8083
8149
|
* HTML & SVG components, optimised for use with gestures and animation. These can be used as
|
|
8084
8150
|
* drop-in replacements for any HTML & SVG component, all CSS & SVG properties are supported.
|
|
@@ -8178,14 +8244,14 @@
|
|
|
8178
8244
|
* styles set via the style prop.
|
|
8179
8245
|
*/
|
|
8180
8246
|
React.useInsertionEffect(() => {
|
|
8181
|
-
var _a;
|
|
8182
8247
|
const { width, height, top, left } = size.current;
|
|
8183
8248
|
if (isPresent || !ref.current || !width || !height)
|
|
8184
8249
|
return;
|
|
8185
8250
|
ref.current.dataset.motionPopId = id;
|
|
8186
8251
|
const style = document.createElement("style");
|
|
8187
8252
|
document.head.appendChild(style);
|
|
8188
|
-
(
|
|
8253
|
+
if (style.sheet) {
|
|
8254
|
+
style.sheet.insertRule(`
|
|
8189
8255
|
[data-motion-pop-id="${id}"] {
|
|
8190
8256
|
position: absolute !important;
|
|
8191
8257
|
width: ${width}px !important;
|
|
@@ -8194,6 +8260,7 @@
|
|
|
8194
8260
|
left: ${left}px !important;
|
|
8195
8261
|
}
|
|
8196
8262
|
`);
|
|
8263
|
+
}
|
|
8197
8264
|
return () => {
|
|
8198
8265
|
document.head.removeChild(style);
|
|
8199
8266
|
};
|
|
@@ -8215,7 +8282,7 @@
|
|
|
8215
8282
|
if (!isComplete)
|
|
8216
8283
|
return; // can stop searching when any is incomplete
|
|
8217
8284
|
}
|
|
8218
|
-
onExitComplete
|
|
8285
|
+
onExitComplete && onExitComplete();
|
|
8219
8286
|
},
|
|
8220
8287
|
register: (childId) => {
|
|
8221
8288
|
presenceChildren.set(childId, false);
|
|
@@ -8236,7 +8303,10 @@
|
|
|
8236
8303
|
* component immediately.
|
|
8237
8304
|
*/
|
|
8238
8305
|
React__namespace.useEffect(() => {
|
|
8239
|
-
!isPresent &&
|
|
8306
|
+
!isPresent &&
|
|
8307
|
+
!presenceChildren.size &&
|
|
8308
|
+
onExitComplete &&
|
|
8309
|
+
onExitComplete();
|
|
8240
8310
|
}, [isPresent]);
|
|
8241
8311
|
if (mode === "popLayout") {
|
|
8242
8312
|
children = React__namespace.createElement(PopChild, { isPresent: isPresent }, children);
|
|
@@ -8424,8 +8494,7 @@
|
|
|
8424
8494
|
|
|
8425
8495
|
const shouldInheritGroup = (inherit) => inherit === true;
|
|
8426
8496
|
const shouldInheritId = (inherit) => shouldInheritGroup(inherit === true) || inherit === "id";
|
|
8427
|
-
const LayoutGroup = ({ children, id, inheritId, inherit = true
|
|
8428
|
-
var _a, _b;
|
|
8497
|
+
const LayoutGroup = ({ children, id, inheritId, inherit = true }) => {
|
|
8429
8498
|
// Maintain backwards-compatibility with inheritId until 7.0
|
|
8430
8499
|
if (inheritId !== undefined)
|
|
8431
8500
|
inherit = inheritId;
|
|
@@ -8433,7 +8502,7 @@
|
|
|
8433
8502
|
const deprecatedLayoutGroupContext = React.useContext(DeprecatedLayoutGroupContext);
|
|
8434
8503
|
const [forceRender, key] = useForceUpdate();
|
|
8435
8504
|
const context = React.useRef(null);
|
|
8436
|
-
const upstreamId =
|
|
8505
|
+
const upstreamId = layoutGroupContext.id || deprecatedLayoutGroupContext;
|
|
8437
8506
|
if (context.current === null) {
|
|
8438
8507
|
if (shouldInheritId(inherit) && upstreamId) {
|
|
8439
8508
|
id = id ? upstreamId + "-" + id : upstreamId;
|
|
@@ -8441,11 +8510,11 @@
|
|
|
8441
8510
|
context.current = {
|
|
8442
8511
|
id,
|
|
8443
8512
|
group: shouldInheritGroup(inherit)
|
|
8444
|
-
?
|
|
8513
|
+
? layoutGroupContext.group || nodeGroup()
|
|
8445
8514
|
: nodeGroup(),
|
|
8446
8515
|
};
|
|
8447
8516
|
}
|
|
8448
|
-
const memoizedContext = React.useMemo(() => (
|
|
8517
|
+
const memoizedContext = React.useMemo(() => ({ ...context.current, forceRender }), [key]);
|
|
8449
8518
|
return (React__namespace.createElement(LayoutGroupContext.Provider, { value: memoizedContext }, children));
|
|
8450
8519
|
};
|
|
8451
8520
|
|
|
@@ -8474,13 +8543,12 @@
|
|
|
8474
8543
|
*
|
|
8475
8544
|
* @public
|
|
8476
8545
|
*/
|
|
8477
|
-
function MotionConfig(
|
|
8478
|
-
var { children, isValidProp } = _a, config = __rest(_a, ["children", "isValidProp"]);
|
|
8546
|
+
function MotionConfig({ children, isValidProp, ...config }) {
|
|
8479
8547
|
isValidProp && loadExternalIsValidProp(isValidProp);
|
|
8480
8548
|
/**
|
|
8481
8549
|
* Inherit props from any parent MotionConfig components
|
|
8482
8550
|
*/
|
|
8483
|
-
config =
|
|
8551
|
+
config = { ...React.useContext(MotionConfigContext), ...config };
|
|
8484
8552
|
/**
|
|
8485
8553
|
* Don't allow isStatic to change between renders as it affects how many hooks
|
|
8486
8554
|
* motion components fire.
|
|
@@ -8536,14 +8604,13 @@
|
|
|
8536
8604
|
* If this is a synchronous load, load features immediately
|
|
8537
8605
|
*/
|
|
8538
8606
|
if (!isLazyBundle(features)) {
|
|
8539
|
-
const { renderer
|
|
8607
|
+
const { renderer, ...loadedFeatures } = features;
|
|
8540
8608
|
loadedRenderer.current = renderer;
|
|
8541
8609
|
loadFeatures(loadedFeatures);
|
|
8542
8610
|
}
|
|
8543
8611
|
React.useEffect(() => {
|
|
8544
8612
|
if (isLazyBundle(features)) {
|
|
8545
|
-
features().then((
|
|
8546
|
-
var { renderer } = _a, loadedFeatures = __rest(_a, ["renderer"]);
|
|
8613
|
+
features().then(({ renderer, ...loadedFeatures }) => {
|
|
8547
8614
|
loadFeatures(loadedFeatures);
|
|
8548
8615
|
loadedRenderer.current = renderer;
|
|
8549
8616
|
setIsLoaded(true);
|
|
@@ -8578,8 +8645,7 @@
|
|
|
8578
8645
|
return order;
|
|
8579
8646
|
}
|
|
8580
8647
|
|
|
8581
|
-
function ReorderGroup(
|
|
8582
|
-
var { children, as = "ul", axis = "y", onReorder, values } = _a, props = __rest(_a, ["children", "as", "axis", "onReorder", "values"]);
|
|
8648
|
+
function ReorderGroup({ children, as = "ul", axis = "y", onReorder, values, ...props }, externalRef) {
|
|
8583
8649
|
const Component = useConstant(() => motion(as));
|
|
8584
8650
|
const order = [];
|
|
8585
8651
|
const isReordering = React.useRef(false);
|
|
@@ -8611,7 +8677,7 @@
|
|
|
8611
8677
|
React.useEffect(() => {
|
|
8612
8678
|
isReordering.current = false;
|
|
8613
8679
|
});
|
|
8614
|
-
return (React__namespace.createElement(Component,
|
|
8680
|
+
return (React__namespace.createElement(Component, { ...props, ref: externalRef },
|
|
8615
8681
|
React__namespace.createElement(ReorderContext.Provider, { value: context }, children)));
|
|
8616
8682
|
}
|
|
8617
8683
|
const Group = React.forwardRef(ReorderGroup);
|
|
@@ -8665,7 +8731,10 @@
|
|
|
8665
8731
|
const inputRange = args[1 + argOffset];
|
|
8666
8732
|
const outputRange = args[2 + argOffset];
|
|
8667
8733
|
const options = args[3 + argOffset];
|
|
8668
|
-
const interpolator = interpolate$1(inputRange, outputRange,
|
|
8734
|
+
const interpolator = interpolate$1(inputRange, outputRange, {
|
|
8735
|
+
mixer: getMixer(outputRange[0]),
|
|
8736
|
+
...options,
|
|
8737
|
+
});
|
|
8669
8738
|
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
8670
8739
|
}
|
|
8671
8740
|
|
|
@@ -8730,13 +8799,12 @@
|
|
|
8730
8799
|
function useDefaultMotionValue(value, defaultValue = 0) {
|
|
8731
8800
|
return isMotionValue(value) ? value : useMotionValue(defaultValue);
|
|
8732
8801
|
}
|
|
8733
|
-
function ReorderItem(
|
|
8734
|
-
var { children, style, value, as = "li", onDrag, layout = true } = _a, props = __rest(_a, ["children", "style", "value", "as", "onDrag", "layout"]);
|
|
8802
|
+
function ReorderItem({ children, style = {}, value, as = "li", onDrag, layout = true, ...props }, externalRef) {
|
|
8735
8803
|
const Component = useConstant(() => motion(as));
|
|
8736
8804
|
const context = React.useContext(ReorderContext);
|
|
8737
8805
|
const point = {
|
|
8738
|
-
x: useDefaultMotionValue(style
|
|
8739
|
-
y: useDefaultMotionValue(style
|
|
8806
|
+
x: useDefaultMotionValue(style.x),
|
|
8807
|
+
y: useDefaultMotionValue(style.y),
|
|
8740
8808
|
};
|
|
8741
8809
|
const zIndex = useTransform([point.x, point.y], ([latestX, latestY]) => latestX || latestY ? 1 : "unset");
|
|
8742
8810
|
const measuredLayout = React.useRef(null);
|
|
@@ -8745,14 +8813,14 @@
|
|
|
8745
8813
|
React.useEffect(() => {
|
|
8746
8814
|
registerItem(value, measuredLayout.current);
|
|
8747
8815
|
}, [context]);
|
|
8748
|
-
return (React__namespace.createElement(Component,
|
|
8816
|
+
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
8817
|
const { velocity } = gesturePoint;
|
|
8750
8818
|
velocity[axis] &&
|
|
8751
8819
|
updateOrder(value, point[axis].get(), velocity[axis]);
|
|
8752
|
-
onDrag
|
|
8820
|
+
onDrag && onDrag(event, gesturePoint);
|
|
8753
8821
|
}, onLayoutMeasure: (measured) => {
|
|
8754
8822
|
measuredLayout.current = measured;
|
|
8755
|
-
}, ref: externalRef }
|
|
8823
|
+
}, ref: externalRef }, children));
|
|
8756
8824
|
}
|
|
8757
8825
|
const Item = React.forwardRef(ReorderItem);
|
|
8758
8826
|
|
|
@@ -8764,12 +8832,21 @@
|
|
|
8764
8832
|
/**
|
|
8765
8833
|
* @public
|
|
8766
8834
|
*/
|
|
8767
|
-
const domAnimation =
|
|
8835
|
+
const domAnimation = {
|
|
8836
|
+
renderer: createDomVisualElement,
|
|
8837
|
+
...animations,
|
|
8838
|
+
...gestureAnimations,
|
|
8839
|
+
};
|
|
8768
8840
|
|
|
8769
8841
|
/**
|
|
8770
8842
|
* @public
|
|
8771
8843
|
*/
|
|
8772
|
-
const domMax =
|
|
8844
|
+
const domMax = {
|
|
8845
|
+
...domAnimation,
|
|
8846
|
+
...drag,
|
|
8847
|
+
...layoutFeatures,
|
|
8848
|
+
projectionNodeConstructor: HTMLProjectionNode,
|
|
8849
|
+
};
|
|
8773
8850
|
|
|
8774
8851
|
/**
|
|
8775
8852
|
* Combine multiple motion values into a new one using a string template literal.
|
|
@@ -8845,7 +8922,13 @@
|
|
|
8845
8922
|
if (activeSpringAnimation.current) {
|
|
8846
8923
|
activeSpringAnimation.current.stop();
|
|
8847
8924
|
}
|
|
8848
|
-
activeSpringAnimation.current = animate$1(
|
|
8925
|
+
activeSpringAnimation.current = animate$1({
|
|
8926
|
+
from: value.get(),
|
|
8927
|
+
to: v,
|
|
8928
|
+
velocity: value.getVelocity(),
|
|
8929
|
+
...config,
|
|
8930
|
+
onUpdate: set,
|
|
8931
|
+
});
|
|
8849
8932
|
return value.get();
|
|
8850
8933
|
});
|
|
8851
8934
|
}, [JSON.stringify(config)]);
|
|
@@ -9461,8 +9544,7 @@
|
|
|
9461
9544
|
scrollXProgress: motionValue(0),
|
|
9462
9545
|
scrollYProgress: motionValue(0),
|
|
9463
9546
|
});
|
|
9464
|
-
function useScroll(
|
|
9465
|
-
var { container, target } = _a, options = __rest(_a, ["container", "target"]);
|
|
9547
|
+
function useScroll({ container, target, ...options } = {}) {
|
|
9466
9548
|
const values = useConstant(createScrollMotionValues);
|
|
9467
9549
|
useIsomorphicLayoutEffect(() => {
|
|
9468
9550
|
return scroll(({ x, y }) => {
|
|
@@ -9470,7 +9552,11 @@
|
|
|
9470
9552
|
values.scrollXProgress.set(x.progress);
|
|
9471
9553
|
values.scrollY.set(y.current);
|
|
9472
9554
|
values.scrollYProgress.set(y.progress);
|
|
9473
|
-
},
|
|
9555
|
+
}, {
|
|
9556
|
+
...options,
|
|
9557
|
+
container: (container === null || container === void 0 ? void 0 : container.current) || undefined,
|
|
9558
|
+
target: (target === null || target === void 0 ? void 0 : target.current) || undefined,
|
|
9559
|
+
});
|
|
9474
9560
|
}, []);
|
|
9475
9561
|
return values;
|
|
9476
9562
|
}
|
|
@@ -9521,11 +9607,11 @@
|
|
|
9521
9607
|
}
|
|
9522
9608
|
add(name) {
|
|
9523
9609
|
let memberName;
|
|
9524
|
-
if (
|
|
9610
|
+
if (transformProps.has(name)) {
|
|
9525
9611
|
this.transforms.add(name);
|
|
9526
9612
|
memberName = "transform";
|
|
9527
9613
|
}
|
|
9528
|
-
else if (!
|
|
9614
|
+
else if (!name.startsWith("origin") &&
|
|
9529
9615
|
!isCSSVariable$1(name) &&
|
|
9530
9616
|
name !== "willChange") {
|
|
9531
9617
|
memberName = camelToDash(name);
|
|
@@ -9536,7 +9622,7 @@
|
|
|
9536
9622
|
}
|
|
9537
9623
|
}
|
|
9538
9624
|
remove(name) {
|
|
9539
|
-
if (
|
|
9625
|
+
if (transformProps.has(name)) {
|
|
9540
9626
|
this.transforms.delete(name);
|
|
9541
9627
|
if (!this.transforms.size) {
|
|
9542
9628
|
removeItem(this.members, "transform");
|
|
@@ -9555,6 +9641,58 @@
|
|
|
9555
9641
|
return useConstant(() => new WillChangeMotionValue("auto"));
|
|
9556
9642
|
}
|
|
9557
9643
|
|
|
9644
|
+
/**
|
|
9645
|
+
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
9646
|
+
*
|
|
9647
|
+
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
9648
|
+
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
9649
|
+
*
|
|
9650
|
+
* It will actively respond to changes and re-render your components with the latest setting.
|
|
9651
|
+
*
|
|
9652
|
+
* ```jsx
|
|
9653
|
+
* export function Sidebar({ isOpen }) {
|
|
9654
|
+
* const shouldReduceMotion = useReducedMotion()
|
|
9655
|
+
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
9656
|
+
*
|
|
9657
|
+
* return (
|
|
9658
|
+
* <motion.div animate={{
|
|
9659
|
+
* opacity: isOpen ? 1 : 0,
|
|
9660
|
+
* x: isOpen ? 0 : closedX
|
|
9661
|
+
* }} />
|
|
9662
|
+
* )
|
|
9663
|
+
* }
|
|
9664
|
+
* ```
|
|
9665
|
+
*
|
|
9666
|
+
* @return boolean
|
|
9667
|
+
*
|
|
9668
|
+
* @public
|
|
9669
|
+
*/
|
|
9670
|
+
function useReducedMotion() {
|
|
9671
|
+
/**
|
|
9672
|
+
* Lazy initialisation of prefersReducedMotion
|
|
9673
|
+
*/
|
|
9674
|
+
!hasReducedMotionListener.current && initPrefersReducedMotion();
|
|
9675
|
+
const [shouldReduceMotion] = React.useState(prefersReducedMotion.current);
|
|
9676
|
+
/**
|
|
9677
|
+
* TODO See if people miss automatically updating shouldReduceMotion setting
|
|
9678
|
+
*/
|
|
9679
|
+
return shouldReduceMotion;
|
|
9680
|
+
}
|
|
9681
|
+
|
|
9682
|
+
function useReducedMotionConfig() {
|
|
9683
|
+
const reducedMotionPreference = useReducedMotion();
|
|
9684
|
+
const { reducedMotion } = React.useContext(MotionConfigContext);
|
|
9685
|
+
if (reducedMotion === "never") {
|
|
9686
|
+
return false;
|
|
9687
|
+
}
|
|
9688
|
+
else if (reducedMotion === "always") {
|
|
9689
|
+
return true;
|
|
9690
|
+
}
|
|
9691
|
+
else {
|
|
9692
|
+
return reducedMotionPreference;
|
|
9693
|
+
}
|
|
9694
|
+
}
|
|
9695
|
+
|
|
9558
9696
|
/**
|
|
9559
9697
|
* @public
|
|
9560
9698
|
*/
|
|
@@ -9709,7 +9847,6 @@
|
|
|
9709
9847
|
function useInView(ref, { root, margin, amount, once = false } = {}) {
|
|
9710
9848
|
const [isInView, setInView] = React.useState(false);
|
|
9711
9849
|
React.useEffect(() => {
|
|
9712
|
-
var _a;
|
|
9713
9850
|
if (!ref.current || (once && isInView))
|
|
9714
9851
|
return;
|
|
9715
9852
|
const onEnter = () => {
|
|
@@ -9717,7 +9854,7 @@
|
|
|
9717
9854
|
return once ? undefined : () => setInView(false);
|
|
9718
9855
|
};
|
|
9719
9856
|
const options = {
|
|
9720
|
-
root: (
|
|
9857
|
+
root: (root && root.current) || undefined,
|
|
9721
9858
|
margin,
|
|
9722
9859
|
amount: amount === "some" ? "any" : amount,
|
|
9723
9860
|
};
|
|
@@ -9814,12 +9951,12 @@
|
|
|
9814
9951
|
function useInstantLayoutTransition() {
|
|
9815
9952
|
return startTransition;
|
|
9816
9953
|
}
|
|
9817
|
-
function startTransition(
|
|
9954
|
+
function startTransition(callback) {
|
|
9818
9955
|
if (!rootProjectionNode.current)
|
|
9819
9956
|
return;
|
|
9820
9957
|
rootProjectionNode.current.isUpdating = false;
|
|
9821
9958
|
rootProjectionNode.current.blockUpdate();
|
|
9822
|
-
|
|
9959
|
+
callback && callback();
|
|
9823
9960
|
}
|
|
9824
9961
|
|
|
9825
9962
|
function useInstantTransition() {
|
|
@@ -9862,11 +9999,10 @@
|
|
|
9862
9999
|
readValueFromInstance(_state, key, options) {
|
|
9863
10000
|
return options.initialState[key] || 0;
|
|
9864
10001
|
},
|
|
9865
|
-
makeTargetAnimatable(element,
|
|
9866
|
-
var { transition, transitionEnd } = _a, target = __rest(_a, ["transition", "transitionEnd"]);
|
|
10002
|
+
makeTargetAnimatable(element, { transition, transitionEnd, ...target }) {
|
|
9867
10003
|
const origin = getOrigin(target, transition || {}, element);
|
|
9868
10004
|
checkTargetForNewValues(element, target, origin);
|
|
9869
|
-
return
|
|
10005
|
+
return { transition, transitionEnd, ...target };
|
|
9870
10006
|
},
|
|
9871
10007
|
});
|
|
9872
10008
|
const useVisualState = makeUseVisualState({
|
|
@@ -9888,7 +10024,7 @@
|
|
|
9888
10024
|
React.useEffect(() => {
|
|
9889
10025
|
element.setProps({
|
|
9890
10026
|
onUpdate: (v) => {
|
|
9891
|
-
setAnimationState(
|
|
10027
|
+
setAnimationState({ ...v });
|
|
9892
10028
|
},
|
|
9893
10029
|
});
|
|
9894
10030
|
}, [setAnimationState, element]);
|