framer-motion 7.2.0 → 7.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +728 -624
- package/dist/es/animation/use-animated-state.mjs +3 -5
- package/dist/es/animation/utils/default-transitions.mjs +1 -1
- package/dist/es/animation/utils/transitions.mjs +28 -26
- package/dist/es/components/AnimatePresence/PopChild.mjs +3 -2
- package/dist/es/components/AnimatePresence/PresenceChild.mjs +5 -2
- package/dist/es/components/AnimatePresence/use-presence.mjs +1 -1
- package/dist/es/components/LayoutGroup/index.mjs +4 -5
- package/dist/es/components/LazyMotion/index.mjs +3 -5
- package/dist/es/components/MotionConfig/index.mjs +2 -4
- package/dist/es/components/Reorder/Group.mjs +2 -4
- package/dist/es/components/Reorder/Item.mjs +6 -8
- package/dist/es/context/MotionContext/utils.mjs +3 -2
- package/dist/es/gestures/PanSession.mjs +2 -2
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +16 -4
- package/dist/es/gestures/use-focus-gesture.mjs +3 -4
- package/dist/es/gestures/use-hover-gesture.mjs +4 -3
- package/dist/es/gestures/use-tap-gesture.mjs +9 -10
- package/dist/es/index.mjs +2 -1
- package/dist/es/motion/features/animations.mjs +8 -3
- package/dist/es/motion/features/definitions.mjs +1 -13
- package/dist/es/motion/features/layout/MeasureLayout.mjs +12 -6
- package/dist/es/motion/features/load-features.mjs +14 -0
- package/dist/es/motion/features/viewport/observers.mjs +4 -7
- package/dist/es/motion/features/viewport/use-viewport.mjs +8 -6
- package/dist/es/motion/index.mjs +23 -23
- package/dist/es/motion/utils/VisualElementHandler.mjs +2 -5
- package/dist/es/motion/utils/is-forced-motion-value.mjs +3 -3
- package/dist/es/motion/utils/use-motion-ref.mjs +1 -2
- package/dist/es/motion/utils/use-visual-element.mjs +14 -12
- package/dist/es/motion/utils/use-visual-state.mjs +19 -16
- package/dist/es/motion/utils/valid-prop.mjs +22 -17
- package/dist/es/projection/node/HTMLProjectionNode.mjs +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +34 -16
- package/dist/es/projection/use-instant-layout-transition.mjs +2 -2
- package/dist/es/render/dom/features-animation.mjs +5 -1
- package/dist/es/render/dom/features-max.mjs +6 -1
- package/dist/es/render/dom/motion.mjs +6 -1
- package/dist/es/render/dom/use-render.mjs +5 -1
- package/dist/es/render/dom/utils/camel-to-dash.mjs +1 -3
- package/dist/es/render/dom/utils/create-config.mjs +7 -2
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +5 -7
- package/dist/es/render/dom/utils/unit-conversion.mjs +4 -4
- package/dist/es/render/dom/value-types/defaults.mjs +15 -3
- package/dist/es/render/dom/value-types/type-int.mjs +4 -1
- package/dist/es/render/html/config-motion.mjs +1 -1
- package/dist/es/render/html/use-props.mjs +5 -9
- package/dist/es/render/html/utils/build-styles.mjs +17 -15
- package/dist/es/render/html/utils/build-transform.mjs +8 -18
- package/dist/es/render/html/utils/transform.mjs +20 -30
- package/dist/es/render/html/visual-element.mjs +8 -9
- package/dist/es/render/index.mjs +118 -40
- package/dist/es/render/svg/use-props.mjs +5 -2
- package/dist/es/render/svg/utils/build-attrs.mjs +3 -5
- package/dist/es/render/svg/utils/create-render-state.mjs +4 -1
- package/dist/es/render/svg/visual-element.mjs +8 -4
- package/dist/es/render/utils/animation-state.mjs +12 -9
- package/dist/es/render/utils/animation.mjs +14 -8
- package/dist/es/render/utils/is-controlling-variants.mjs +22 -0
- package/dist/es/render/utils/is-variant-label.mjs +8 -0
- package/dist/es/render/utils/motion-values.mjs +3 -3
- package/dist/es/render/utils/resolve-dynamic-variants.mjs +24 -0
- package/dist/es/render/utils/resolve-variants.mjs +26 -0
- package/dist/es/render/utils/setters.mjs +12 -9
- package/dist/es/utils/reduced-motion/index.mjs +19 -0
- package/dist/es/utils/reduced-motion/state.mjs +5 -0
- package/dist/es/utils/reduced-motion/use-reduced-motion-config.mjs +19 -0
- package/dist/es/utils/reduced-motion/use-reduced-motion.mjs +43 -0
- package/dist/es/utils/transform.mjs +4 -1
- package/dist/es/utils/use-in-view.mjs +1 -2
- package/dist/es/value/index.mjs +1 -1
- package/dist/es/value/use-scroll.mjs +6 -4
- package/dist/es/value/use-spring.mjs +7 -1
- package/dist/es/value/use-will-change/index.mjs +4 -4
- package/dist/es/value/utils/is-motion-value.mjs +1 -3
- package/dist/framer-motion.dev.js +769 -664
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +55 -52
- package/dist/projection.dev.js +368 -210
- package/dist/size-rollup-dom-animation-assets.js +1 -0
- package/dist/size-rollup-dom-animation-m.js +1 -0
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max-assets.js +1 -0
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/dist/size-rollup-motion.js +1 -0
- package/dist/size-webpack-dom-animation.js +1 -1
- package/dist/size-webpack-dom-max.js +1 -1
- package/dist/size-webpack-m.js +1 -1
- package/dist/three-entry.d.ts +36 -20
- package/package.json +12 -8
- package/dist/es/motion/features/use-features.mjs +0 -40
- package/dist/es/motion/features/use-projection.mjs +0 -33
- package/dist/es/render/utils/variants.mjs +0 -73
- package/dist/es/utils/use-reduced-motion.mjs +0 -73
package/dist/cjs/index.js
CHANGED
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var heyListen = require('hey-listen');
|
|
7
6
|
var styleValueTypes = require('style-value-types');
|
|
8
|
-
var tslib = require('tslib');
|
|
9
7
|
var popmotion = require('popmotion');
|
|
8
|
+
var heyListen = require('hey-listen');
|
|
10
9
|
var sync = require('framesync');
|
|
11
10
|
var dom = require('@motionone/dom');
|
|
12
11
|
|
|
@@ -30,97 +29,10 @@ function _interopNamespace(e) {
|
|
|
30
29
|
return Object.freeze(n);
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
34
32
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
33
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
35
34
|
var sync__default = /*#__PURE__*/_interopDefaultLegacy(sync);
|
|
36
35
|
|
|
37
|
-
/**
|
|
38
|
-
* Browser-safe usage of process
|
|
39
|
-
*/
|
|
40
|
-
const defaultEnvironment = "production";
|
|
41
|
-
const env = typeof process === "undefined" || process.env === undefined
|
|
42
|
-
? defaultEnvironment
|
|
43
|
-
: process.env.NODE_ENV || defaultEnvironment;
|
|
44
|
-
|
|
45
|
-
const createDefinition = (propNames) => ({
|
|
46
|
-
isEnabled: (props) => propNames.some((name) => !!props[name]),
|
|
47
|
-
});
|
|
48
|
-
const featureDefinitions = {
|
|
49
|
-
measureLayout: createDefinition(["layout", "layoutId", "drag"]),
|
|
50
|
-
animation: createDefinition([
|
|
51
|
-
"animate",
|
|
52
|
-
"exit",
|
|
53
|
-
"variants",
|
|
54
|
-
"whileHover",
|
|
55
|
-
"whileTap",
|
|
56
|
-
"whileFocus",
|
|
57
|
-
"whileDrag",
|
|
58
|
-
"whileInView",
|
|
59
|
-
]),
|
|
60
|
-
exit: createDefinition(["exit"]),
|
|
61
|
-
drag: createDefinition(["drag", "dragControls"]),
|
|
62
|
-
focus: createDefinition(["whileFocus"]),
|
|
63
|
-
hover: createDefinition(["whileHover", "onHoverStart", "onHoverEnd"]),
|
|
64
|
-
tap: createDefinition(["whileTap", "onTap", "onTapStart", "onTapCancel"]),
|
|
65
|
-
pan: createDefinition([
|
|
66
|
-
"onPan",
|
|
67
|
-
"onPanStart",
|
|
68
|
-
"onPanSessionStart",
|
|
69
|
-
"onPanEnd",
|
|
70
|
-
]),
|
|
71
|
-
inView: createDefinition([
|
|
72
|
-
"whileInView",
|
|
73
|
-
"onViewportEnter",
|
|
74
|
-
"onViewportLeave",
|
|
75
|
-
]),
|
|
76
|
-
};
|
|
77
|
-
function loadFeatures(features) {
|
|
78
|
-
for (const key in features) {
|
|
79
|
-
if (features[key] === null)
|
|
80
|
-
continue;
|
|
81
|
-
if (key === "projectionNodeConstructor") {
|
|
82
|
-
featureDefinitions.projectionNodeConstructor = features[key];
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
featureDefinitions[key].Component = features[key];
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const LazyContext = React.createContext({ strict: false });
|
|
91
|
-
|
|
92
|
-
const featureNames = Object.keys(featureDefinitions);
|
|
93
|
-
const numFeatures = featureNames.length;
|
|
94
|
-
/**
|
|
95
|
-
* Load features via renderless components based on the provided MotionProps.
|
|
96
|
-
*/
|
|
97
|
-
function useFeatures(props, visualElement, preloadedFeatures) {
|
|
98
|
-
const features = [];
|
|
99
|
-
const lazyContext = React.useContext(LazyContext);
|
|
100
|
-
if (!visualElement)
|
|
101
|
-
return null;
|
|
102
|
-
/**
|
|
103
|
-
* If we're in development mode, check to make sure we're not rendering a motion component
|
|
104
|
-
* as a child of LazyMotion, as this will break the file-size benefits of using it.
|
|
105
|
-
*/
|
|
106
|
-
if (env !== "production" && preloadedFeatures && lazyContext.strict) {
|
|
107
|
-
heyListen.invariant(false, "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.");
|
|
108
|
-
}
|
|
109
|
-
for (let i = 0; i < numFeatures; i++) {
|
|
110
|
-
const name = featureNames[i];
|
|
111
|
-
const { isEnabled, Component } = featureDefinitions[name];
|
|
112
|
-
/**
|
|
113
|
-
* It might be possible in the future to use this moment to
|
|
114
|
-
* dynamically request functionality. In initial tests this
|
|
115
|
-
* was producing a lot of duplication amongst bundles.
|
|
116
|
-
*/
|
|
117
|
-
if (isEnabled(props) && Component) {
|
|
118
|
-
features.push(React__namespace.createElement(Component, Object.assign({ key: name }, props, { visualElement: visualElement })));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return features;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
36
|
/**
|
|
125
37
|
* @public
|
|
126
38
|
*/
|
|
@@ -144,104 +56,40 @@ const isBrowser = typeof document !== "undefined";
|
|
|
144
56
|
|
|
145
57
|
const useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : React.useEffect;
|
|
146
58
|
|
|
147
|
-
|
|
148
|
-
const prefersReducedMotion = { current: null };
|
|
149
|
-
let hasDetected = false;
|
|
150
|
-
function initPrefersReducedMotion() {
|
|
151
|
-
hasDetected = true;
|
|
152
|
-
if (!isBrowser)
|
|
153
|
-
return;
|
|
154
|
-
if (window.matchMedia) {
|
|
155
|
-
const motionMediaQuery = window.matchMedia("(prefers-reduced-motion)");
|
|
156
|
-
const setReducedMotionPreferences = () => (prefersReducedMotion.current = motionMediaQuery.matches);
|
|
157
|
-
motionMediaQuery.addListener(setReducedMotionPreferences);
|
|
158
|
-
setReducedMotionPreferences();
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
prefersReducedMotion.current = false;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
166
|
-
*
|
|
167
|
-
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
168
|
-
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
169
|
-
*
|
|
170
|
-
* It will actively respond to changes and re-render your components with the latest setting.
|
|
171
|
-
*
|
|
172
|
-
* ```jsx
|
|
173
|
-
* export function Sidebar({ isOpen }) {
|
|
174
|
-
* const shouldReduceMotion = useReducedMotion()
|
|
175
|
-
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
176
|
-
*
|
|
177
|
-
* return (
|
|
178
|
-
* <motion.div animate={{
|
|
179
|
-
* opacity: isOpen ? 1 : 0,
|
|
180
|
-
* x: isOpen ? 0 : closedX
|
|
181
|
-
* }} />
|
|
182
|
-
* )
|
|
183
|
-
* }
|
|
184
|
-
* ```
|
|
185
|
-
*
|
|
186
|
-
* @return boolean
|
|
187
|
-
*
|
|
188
|
-
* @public
|
|
189
|
-
*/
|
|
190
|
-
function useReducedMotion() {
|
|
191
|
-
/**
|
|
192
|
-
* Lazy initialisation of prefersReducedMotion
|
|
193
|
-
*/
|
|
194
|
-
!hasDetected && initPrefersReducedMotion();
|
|
195
|
-
const [shouldReduceMotion] = React.useState(prefersReducedMotion.current);
|
|
196
|
-
/**
|
|
197
|
-
* TODO See if people miss automatically updating shouldReduceMotion setting
|
|
198
|
-
*/
|
|
199
|
-
return shouldReduceMotion;
|
|
200
|
-
}
|
|
201
|
-
function useReducedMotionConfig() {
|
|
202
|
-
const reducedMotionPreference = useReducedMotion();
|
|
203
|
-
const { reducedMotion } = React.useContext(MotionConfigContext);
|
|
204
|
-
if (reducedMotion === "never") {
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
else if (reducedMotion === "always") {
|
|
208
|
-
return true;
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
return reducedMotionPreference;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
59
|
+
const LazyContext = React.createContext({ strict: false });
|
|
214
60
|
|
|
215
61
|
function useVisualElement(Component, visualState, props, createVisualElement) {
|
|
216
|
-
const lazyContext = React.useContext(LazyContext);
|
|
217
62
|
const parent = useVisualElementContext();
|
|
63
|
+
const lazyContext = React.useContext(LazyContext);
|
|
218
64
|
const presenceContext = React.useContext(PresenceContext);
|
|
219
|
-
const
|
|
65
|
+
const reducedMotionConfig = React.useContext(MotionConfigContext).reducedMotion;
|
|
220
66
|
const visualElementRef = React.useRef(undefined);
|
|
221
67
|
/**
|
|
222
68
|
* If we haven't preloaded a renderer, check to see if we have one lazy-loaded
|
|
223
69
|
*/
|
|
224
|
-
|
|
225
|
-
createVisualElement = lazyContext.renderer;
|
|
70
|
+
createVisualElement = createVisualElement || lazyContext.renderer;
|
|
226
71
|
if (!visualElementRef.current && createVisualElement) {
|
|
227
72
|
visualElementRef.current = createVisualElement(Component, {
|
|
228
73
|
visualState,
|
|
229
74
|
parent,
|
|
230
75
|
props,
|
|
231
|
-
presenceId: presenceContext
|
|
232
|
-
blockInitialAnimation:
|
|
233
|
-
|
|
76
|
+
presenceId: presenceContext ? presenceContext.id : undefined,
|
|
77
|
+
blockInitialAnimation: presenceContext
|
|
78
|
+
? presenceContext.initial === false
|
|
79
|
+
: false,
|
|
80
|
+
reducedMotionConfig,
|
|
234
81
|
});
|
|
235
82
|
}
|
|
236
83
|
const visualElement = visualElementRef.current;
|
|
237
84
|
useIsomorphicLayoutEffect(() => {
|
|
238
|
-
visualElement
|
|
85
|
+
visualElement && visualElement.syncRender();
|
|
239
86
|
});
|
|
240
87
|
React.useEffect(() => {
|
|
241
|
-
|
|
242
|
-
|
|
88
|
+
if (visualElement && visualElement.animationState) {
|
|
89
|
+
visualElement.animationState.animateChanges();
|
|
90
|
+
}
|
|
243
91
|
});
|
|
244
|
-
useIsomorphicLayoutEffect(() => () => visualElement
|
|
92
|
+
useIsomorphicLayoutEffect(() => () => visualElement && visualElement.notifyUnmount(), []);
|
|
245
93
|
return visualElement;
|
|
246
94
|
}
|
|
247
95
|
|
|
@@ -256,8 +104,7 @@ function isRefObject(ref) {
|
|
|
256
104
|
*/
|
|
257
105
|
function useMotionRef(visualState, visualElement, externalRef) {
|
|
258
106
|
return React.useCallback((instance) => {
|
|
259
|
-
|
|
260
|
-
instance && ((_a = visualState.mount) === null || _a === void 0 ? void 0 : _a.call(visualState, instance));
|
|
107
|
+
instance && visualState.mount && visualState.mount(instance);
|
|
261
108
|
if (visualElement) {
|
|
262
109
|
instance
|
|
263
110
|
? visualElement.mount(instance)
|
|
@@ -280,80 +127,37 @@ function useMotionRef(visualState, visualElement, externalRef) {
|
|
|
280
127
|
[visualElement]);
|
|
281
128
|
}
|
|
282
129
|
|
|
283
|
-
/**
|
|
284
|
-
* Decides if the supplied variable is an array of variant labels
|
|
285
|
-
*/
|
|
286
|
-
function isVariantLabels(v) {
|
|
287
|
-
return Array.isArray(v);
|
|
288
|
-
}
|
|
289
130
|
/**
|
|
290
131
|
* Decides if the supplied variable is variant label
|
|
291
132
|
*/
|
|
292
133
|
function isVariantLabel(v) {
|
|
293
|
-
return typeof v === "string" ||
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Creates an object containing the latest state of every MotionValue on a VisualElement
|
|
297
|
-
*/
|
|
298
|
-
function getCurrent(visualElement) {
|
|
299
|
-
const current = {};
|
|
300
|
-
visualElement.forEachValue((value, key) => (current[key] = value.get()));
|
|
301
|
-
return current;
|
|
134
|
+
return typeof v === "string" || Array.isArray(v);
|
|
302
135
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
function getVelocity$1(visualElement) {
|
|
307
|
-
const velocity = {};
|
|
308
|
-
visualElement.forEachValue((value, key) => (velocity[key] = value.getVelocity()));
|
|
309
|
-
return velocity;
|
|
310
|
-
}
|
|
311
|
-
function resolveVariantFromProps(props, definition, custom, currentValues = {}, currentVelocity = {}) {
|
|
312
|
-
var _a;
|
|
313
|
-
/**
|
|
314
|
-
* If the variant definition is a function, resolve.
|
|
315
|
-
*/
|
|
316
|
-
if (typeof definition === "function") {
|
|
317
|
-
definition = definition(custom !== null && custom !== void 0 ? custom : props.custom, currentValues, currentVelocity);
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* If the variant definition is a variant label, or
|
|
321
|
-
* the function returned a variant label, resolve.
|
|
322
|
-
*/
|
|
323
|
-
if (typeof definition === "string") {
|
|
324
|
-
definition = (_a = props.variants) === null || _a === void 0 ? void 0 : _a[definition];
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* At this point we've resolved both functions and variant labels,
|
|
328
|
-
* but the resolved variant label might itself have been a function.
|
|
329
|
-
* If so, resolve. This can only have returned a valid target object.
|
|
330
|
-
*/
|
|
331
|
-
if (typeof definition === "function") {
|
|
332
|
-
definition = definition(custom !== null && custom !== void 0 ? custom : props.custom, currentValues, currentVelocity);
|
|
333
|
-
}
|
|
334
|
-
return definition;
|
|
335
|
-
}
|
|
336
|
-
function resolveVariant(visualElement, definition, custom) {
|
|
337
|
-
const props = visualElement.getProps();
|
|
338
|
-
return resolveVariantFromProps(props, definition, custom !== null && custom !== void 0 ? custom : props.custom, getCurrent(visualElement), getVelocity$1(visualElement));
|
|
136
|
+
|
|
137
|
+
function isAnimationControls(v) {
|
|
138
|
+
return typeof v === "object" && typeof v.start === "function";
|
|
339
139
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
140
|
+
|
|
141
|
+
const variantProps$1 = [
|
|
142
|
+
"initial",
|
|
143
|
+
"animate",
|
|
144
|
+
"exit",
|
|
145
|
+
"whileHover",
|
|
146
|
+
"whileDrag",
|
|
147
|
+
"whileTap",
|
|
148
|
+
"whileFocus",
|
|
149
|
+
"whileInView",
|
|
150
|
+
];
|
|
151
|
+
function isControllingVariants(props) {
|
|
152
|
+
return (isAnimationControls(props.animate) ||
|
|
153
|
+
variantProps$1.some((name) => isVariantLabel(props[name])));
|
|
350
154
|
}
|
|
351
|
-
function
|
|
352
|
-
return Boolean(
|
|
155
|
+
function isVariantNode(props) {
|
|
156
|
+
return Boolean(isControllingVariants(props) || props.variants);
|
|
353
157
|
}
|
|
354
158
|
|
|
355
159
|
function getCurrentTreeVariants(props, context) {
|
|
356
|
-
if (
|
|
160
|
+
if (isControllingVariants(props)) {
|
|
357
161
|
const { initial, animate } = props;
|
|
358
162
|
return {
|
|
359
163
|
initial: initial === false || isVariantLabel(initial)
|
|
@@ -373,6 +177,50 @@ function variantLabelsAsDependency(prop) {
|
|
|
373
177
|
return Array.isArray(prop) ? prop.join(" ") : prop;
|
|
374
178
|
}
|
|
375
179
|
|
|
180
|
+
const createDefinition = (propNames) => ({
|
|
181
|
+
isEnabled: (props) => propNames.some((name) => !!props[name]),
|
|
182
|
+
});
|
|
183
|
+
const featureDefinitions = {
|
|
184
|
+
measureLayout: createDefinition(["layout", "layoutId", "drag"]),
|
|
185
|
+
animation: createDefinition([
|
|
186
|
+
"animate",
|
|
187
|
+
"exit",
|
|
188
|
+
"variants",
|
|
189
|
+
"whileHover",
|
|
190
|
+
"whileTap",
|
|
191
|
+
"whileFocus",
|
|
192
|
+
"whileDrag",
|
|
193
|
+
"whileInView",
|
|
194
|
+
]),
|
|
195
|
+
exit: createDefinition(["exit"]),
|
|
196
|
+
drag: createDefinition(["drag", "dragControls"]),
|
|
197
|
+
focus: createDefinition(["whileFocus"]),
|
|
198
|
+
hover: createDefinition(["whileHover", "onHoverStart", "onHoverEnd"]),
|
|
199
|
+
tap: createDefinition(["whileTap", "onTap", "onTapStart", "onTapCancel"]),
|
|
200
|
+
pan: createDefinition([
|
|
201
|
+
"onPan",
|
|
202
|
+
"onPanStart",
|
|
203
|
+
"onPanSessionStart",
|
|
204
|
+
"onPanEnd",
|
|
205
|
+
]),
|
|
206
|
+
inView: createDefinition([
|
|
207
|
+
"whileInView",
|
|
208
|
+
"onViewportEnter",
|
|
209
|
+
"onViewportLeave",
|
|
210
|
+
]),
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
function loadFeatures(features) {
|
|
214
|
+
for (const key in features) {
|
|
215
|
+
if (key === "projectionNodeConstructor") {
|
|
216
|
+
featureDefinitions.projectionNodeConstructor = features[key];
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
featureDefinitions[key].Component = features[key];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
376
224
|
/**
|
|
377
225
|
* Creates a constant value over the lifecycle of a component.
|
|
378
226
|
*
|
|
@@ -417,58 +265,27 @@ function useProjectionId() {
|
|
|
417
265
|
|
|
418
266
|
const LayoutGroupContext = React.createContext({});
|
|
419
267
|
|
|
420
|
-
/**
|
|
421
|
-
* Internal, exported only for usage in Framer
|
|
422
|
-
*/
|
|
423
|
-
const SwitchLayoutGroupContext = React.createContext({});
|
|
424
|
-
|
|
425
|
-
function useProjection(projectionId, { layoutId, layout, drag, dragConstraints, layoutScroll }, visualElement, ProjectionNodeConstructor) {
|
|
426
|
-
var _a;
|
|
427
|
-
const initialPromotionConfig = React.useContext(SwitchLayoutGroupContext);
|
|
428
|
-
if (!ProjectionNodeConstructor ||
|
|
429
|
-
!visualElement ||
|
|
430
|
-
(visualElement === null || visualElement === void 0 ? void 0 : visualElement.projection)) {
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
visualElement.projection = new ProjectionNodeConstructor(projectionId, visualElement.getLatestValues(), (_a = visualElement.parent) === null || _a === void 0 ? void 0 : _a.projection);
|
|
434
|
-
visualElement.projection.setOptions({
|
|
435
|
-
layoutId,
|
|
436
|
-
layout,
|
|
437
|
-
alwaysMeasureLayout: Boolean(drag) || (dragConstraints && isRefObject(dragConstraints)),
|
|
438
|
-
visualElement,
|
|
439
|
-
scheduleRender: () => visualElement.scheduleRender(),
|
|
440
|
-
/**
|
|
441
|
-
* TODO: Update options in an effect. This could be tricky as it'll be too late
|
|
442
|
-
* to update by the time layout animations run.
|
|
443
|
-
* We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
|
|
444
|
-
* ensuring it gets called if there's no potential layout animations.
|
|
445
|
-
*
|
|
446
|
-
*/
|
|
447
|
-
animationType: typeof layout === "string" ? layout : "both",
|
|
448
|
-
initialPromotionConfig,
|
|
449
|
-
layoutScroll,
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
|
|
453
268
|
class VisualElementHandler extends React__default["default"].Component {
|
|
454
269
|
/**
|
|
455
270
|
* Update visual element props as soon as we know this update is going to be commited.
|
|
456
271
|
*/
|
|
457
272
|
getSnapshotBeforeUpdate() {
|
|
458
|
-
this.updateProps();
|
|
459
|
-
return null;
|
|
460
|
-
}
|
|
461
|
-
componentDidUpdate() { }
|
|
462
|
-
updateProps() {
|
|
463
273
|
const { visualElement, props } = this.props;
|
|
464
274
|
if (visualElement)
|
|
465
275
|
visualElement.setProps(props);
|
|
276
|
+
return null;
|
|
466
277
|
}
|
|
278
|
+
componentDidUpdate() { }
|
|
467
279
|
render() {
|
|
468
280
|
return this.props.children;
|
|
469
281
|
}
|
|
470
282
|
}
|
|
471
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Internal, exported only for usage in Framer
|
|
286
|
+
*/
|
|
287
|
+
const SwitchLayoutGroupContext = React.createContext({});
|
|
288
|
+
|
|
472
289
|
/**
|
|
473
290
|
* Create a `motion` component.
|
|
474
291
|
*
|
|
@@ -481,15 +298,12 @@ class VisualElementHandler extends React__default["default"].Component {
|
|
|
481
298
|
function createMotionComponent({ preloadedFeatures, createVisualElement, projectionNodeConstructor, useRender, useVisualState, Component, }) {
|
|
482
299
|
preloadedFeatures && loadFeatures(preloadedFeatures);
|
|
483
300
|
function MotionComponent(props, externalRef) {
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
* or any gesture/animation features.
|
|
491
|
-
*/
|
|
492
|
-
const config = React.useContext(MotionConfigContext);
|
|
301
|
+
const configAndProps = {
|
|
302
|
+
...React.useContext(MotionConfigContext),
|
|
303
|
+
...props,
|
|
304
|
+
layoutId: useLayoutId(props),
|
|
305
|
+
};
|
|
306
|
+
const { isStatic } = configAndProps;
|
|
493
307
|
let features = null;
|
|
494
308
|
const context = useCreateMotionContext(props);
|
|
495
309
|
/**
|
|
@@ -503,40 +317,42 @@ function createMotionComponent({ preloadedFeatures, createVisualElement, project
|
|
|
503
317
|
* shared element transitions however. Perhaps for those we could revert to a root node
|
|
504
318
|
* that gets forceRendered and layout animations are triggered on its layout effect.
|
|
505
319
|
*/
|
|
506
|
-
const projectionId =
|
|
320
|
+
const projectionId = isStatic ? undefined : useProjectionId();
|
|
507
321
|
/**
|
|
508
322
|
*
|
|
509
323
|
*/
|
|
510
|
-
const visualState = useVisualState(props,
|
|
511
|
-
if (!
|
|
324
|
+
const visualState = useVisualState(props, isStatic);
|
|
325
|
+
if (!isStatic && isBrowser) {
|
|
512
326
|
/**
|
|
513
327
|
* Create a VisualElement for this component. A VisualElement provides a common
|
|
514
328
|
* interface to renderer-specific APIs (ie DOM/Three.js etc) as well as
|
|
515
329
|
* providing a way of rendering to these APIs outside of the React render loop
|
|
516
330
|
* for more performant animations and interactions
|
|
517
331
|
*/
|
|
518
|
-
context.visualElement = useVisualElement(Component, visualState,
|
|
519
|
-
useProjection(projectionId, props, context.visualElement, projectionNodeConstructor ||
|
|
520
|
-
featureDefinitions.projectionNodeConstructor);
|
|
332
|
+
context.visualElement = useVisualElement(Component, visualState, configAndProps, createVisualElement);
|
|
521
333
|
/**
|
|
522
334
|
* Load Motion gesture and animation features. These are rendered as renderless
|
|
523
335
|
* components so each feature can optionally make use of React lifecycle methods.
|
|
524
336
|
*/
|
|
525
|
-
|
|
337
|
+
const lazyStrictMode = React.useContext(LazyContext).strict;
|
|
338
|
+
const initialLayoutGroupConfig = React.useContext(SwitchLayoutGroupContext);
|
|
339
|
+
if (context.visualElement) {
|
|
340
|
+
features = context.visualElement.loadFeatures(props, lazyStrictMode, preloadedFeatures, projectionId, projectionNodeConstructor ||
|
|
341
|
+
featureDefinitions.projectionNodeConstructor, initialLayoutGroupConfig);
|
|
342
|
+
}
|
|
526
343
|
}
|
|
527
344
|
/**
|
|
528
345
|
* The mount order and hierarchy is specific to ensure our element ref
|
|
529
346
|
* is hydrated by the time features fire their effects.
|
|
530
347
|
*/
|
|
531
|
-
return (React__namespace.createElement(VisualElementHandler, { visualElement: context.visualElement, props:
|
|
348
|
+
return (React__namespace.createElement(VisualElementHandler, { visualElement: context.visualElement, props: configAndProps },
|
|
532
349
|
features,
|
|
533
|
-
React__namespace.createElement(MotionContext.Provider, { value: context }, useRender(Component, props, projectionId, useMotionRef(visualState, context.visualElement, externalRef), visualState,
|
|
350
|
+
React__namespace.createElement(MotionContext.Provider, { value: context }, useRender(Component, props, projectionId, useMotionRef(visualState, context.visualElement, externalRef), visualState, isStatic, context.visualElement))));
|
|
534
351
|
}
|
|
535
352
|
return React.forwardRef(MotionComponent);
|
|
536
353
|
}
|
|
537
354
|
function useLayoutId({ layoutId }) {
|
|
538
|
-
|
|
539
|
-
const layoutGroupId = (_a = React.useContext(LayoutGroupContext)) === null || _a === void 0 ? void 0 : _a.id;
|
|
355
|
+
const layoutGroupId = React.useContext(LayoutGroupContext).id;
|
|
540
356
|
return layoutGroupId && layoutId !== undefined
|
|
541
357
|
? layoutGroupId + "-" + layoutId
|
|
542
358
|
: layoutId;
|
|
@@ -650,52 +466,40 @@ function addScaleCorrector(correctors) {
|
|
|
650
466
|
Object.assign(scaleCorrectors, correctors);
|
|
651
467
|
}
|
|
652
468
|
|
|
653
|
-
/**
|
|
654
|
-
* A list of all transformable axes. We'll use this list to generated a version
|
|
655
|
-
* of each axes for each transform.
|
|
656
|
-
*/
|
|
657
|
-
const transformAxes = ["", "X", "Y", "Z"];
|
|
658
|
-
/**
|
|
659
|
-
* An ordered array of each transformable value. By default, transform values
|
|
660
|
-
* will be sorted to this order.
|
|
661
|
-
*/
|
|
662
|
-
const order = ["translate", "scale", "rotate", "skew"];
|
|
663
469
|
/**
|
|
664
470
|
* Generate a list of every possible transform key.
|
|
665
471
|
*/
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
472
|
+
const transformPropOrder = [
|
|
473
|
+
"transformPerspective",
|
|
474
|
+
"x",
|
|
475
|
+
"y",
|
|
476
|
+
"z",
|
|
477
|
+
"translateX",
|
|
478
|
+
"translateY",
|
|
479
|
+
"translateZ",
|
|
480
|
+
"scale",
|
|
481
|
+
"scaleX",
|
|
482
|
+
"scaleY",
|
|
483
|
+
"rotate",
|
|
484
|
+
"rotateX",
|
|
485
|
+
"rotateY",
|
|
486
|
+
"skew",
|
|
487
|
+
"skewX",
|
|
488
|
+
"skewY",
|
|
489
|
+
];
|
|
674
490
|
/**
|
|
675
491
|
* A quick lookup for transform props.
|
|
676
492
|
*/
|
|
677
|
-
const
|
|
678
|
-
function isTransformProp(key) {
|
|
679
|
-
return transformPropSet.has(key);
|
|
680
|
-
}
|
|
681
|
-
/**
|
|
682
|
-
* A quick lookup for transform origin props
|
|
683
|
-
*/
|
|
684
|
-
const transformOriginProps = new Set(["originX", "originY", "originZ"]);
|
|
685
|
-
function isTransformOriginProp(key) {
|
|
686
|
-
return transformOriginProps.has(key);
|
|
687
|
-
}
|
|
493
|
+
const transformProps = new Set(transformPropOrder);
|
|
688
494
|
|
|
689
495
|
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
690
|
-
return (
|
|
691
|
-
|
|
496
|
+
return (transformProps.has(key) ||
|
|
497
|
+
key.startsWith("origin") ||
|
|
692
498
|
((layout || layoutId !== undefined) &&
|
|
693
499
|
(!!scaleCorrectors[key] || key === "opacity")));
|
|
694
500
|
}
|
|
695
501
|
|
|
696
|
-
const isMotionValue = (value) =>
|
|
697
|
-
return Boolean(value !== null && typeof value === "object" && value.getVelocity);
|
|
698
|
-
};
|
|
502
|
+
const isMotionValue = (value) => value === undefined ? false : !!value.getVelocity;
|
|
699
503
|
|
|
700
504
|
const translateAlias = {
|
|
701
505
|
x: "translateX",
|
|
@@ -703,6 +507,10 @@ const translateAlias = {
|
|
|
703
507
|
z: "translateZ",
|
|
704
508
|
transformPerspective: "perspective",
|
|
705
509
|
};
|
|
510
|
+
/**
|
|
511
|
+
* A function to use with Array.sort to sort transform keys by their default order.
|
|
512
|
+
*/
|
|
513
|
+
const sortTransformProps = (a, b) => transformPropOrder.indexOf(a) - transformPropOrder.indexOf(b);
|
|
706
514
|
/**
|
|
707
515
|
* Build a CSS transform style from individual x/y/scale etc properties.
|
|
708
516
|
*
|
|
@@ -714,18 +522,11 @@ function buildTransform({ transform, transformKeys }, { enableHardwareAccelerati
|
|
|
714
522
|
let transformString = "";
|
|
715
523
|
// Transform keys into their default order - this will determine the output order.
|
|
716
524
|
transformKeys.sort(sortTransformProps);
|
|
717
|
-
// Track whether the defined transform has a defined z so we don't add a
|
|
718
|
-
// second to enable hardware acceleration
|
|
719
|
-
let transformHasZ = false;
|
|
720
525
|
// Loop over each transform and build them into transformString
|
|
721
|
-
const
|
|
722
|
-
for (let i = 0; i < numTransformKeys; i++) {
|
|
723
|
-
const key = transformKeys[i];
|
|
526
|
+
for (const key of transformKeys) {
|
|
724
527
|
transformString += `${translateAlias[key] || key}(${transform[key]}) `;
|
|
725
|
-
if (key === "z")
|
|
726
|
-
transformHasZ = true;
|
|
727
528
|
}
|
|
728
|
-
if (
|
|
529
|
+
if (enableHardwareAcceleration && !transform.z) {
|
|
729
530
|
transformString += "translateZ(0)";
|
|
730
531
|
}
|
|
731
532
|
transformString = transformString.trim();
|
|
@@ -739,13 +540,6 @@ function buildTransform({ transform, transformKeys }, { enableHardwareAccelerati
|
|
|
739
540
|
}
|
|
740
541
|
return transformString;
|
|
741
542
|
}
|
|
742
|
-
/**
|
|
743
|
-
* Build a transformOrigin style. Uses the same defaults as the browser for
|
|
744
|
-
* undefined origins.
|
|
745
|
-
*/
|
|
746
|
-
function buildTransformOrigin({ originX = "50%", originY = "50%", originZ = 0, }) {
|
|
747
|
-
return `${originX} ${originY} ${originZ}`;
|
|
748
|
-
}
|
|
749
543
|
|
|
750
544
|
/**
|
|
751
545
|
* Returns true if the provided key is a CSS variable
|
|
@@ -763,7 +557,10 @@ const getValueAsType = (value, type) => {
|
|
|
763
557
|
: value;
|
|
764
558
|
};
|
|
765
559
|
|
|
766
|
-
const int =
|
|
560
|
+
const int = {
|
|
561
|
+
...styleValueTypes.number,
|
|
562
|
+
transform: Math.round,
|
|
563
|
+
};
|
|
767
564
|
|
|
768
565
|
const numberValueTypes = {
|
|
769
566
|
// Border props
|
|
@@ -833,11 +630,7 @@ const numberValueTypes = {
|
|
|
833
630
|
};
|
|
834
631
|
|
|
835
632
|
function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
836
|
-
var _a;
|
|
837
633
|
const { style, vars, transform, transformKeys, transformOrigin } = state;
|
|
838
|
-
// Empty the transformKeys array. As we're throwing out refs to its items
|
|
839
|
-
// this might not be as cheap as suspected. Maybe using the array as a buffer
|
|
840
|
-
// with a manual incrementation would be better.
|
|
841
634
|
transformKeys.length = 0;
|
|
842
635
|
// Track whether we encounter any transform or transformOrigin values.
|
|
843
636
|
let hasTransform = false;
|
|
@@ -862,7 +655,7 @@ function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
|
862
655
|
// Convert the value to its default value type, ie 0 -> "0px"
|
|
863
656
|
const valueType = numberValueTypes[key];
|
|
864
657
|
const valueAsType = getValueAsType(value, valueType);
|
|
865
|
-
if (
|
|
658
|
+
if (transformProps.has(key)) {
|
|
866
659
|
// If this is a transform, flag to enable further transform processing
|
|
867
660
|
hasTransform = true;
|
|
868
661
|
transform[key] = valueAsType;
|
|
@@ -871,29 +664,35 @@ function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
|
871
664
|
if (!transformIsNone)
|
|
872
665
|
continue;
|
|
873
666
|
// Otherwise check to see if this is a default transform
|
|
874
|
-
if (value !== (
|
|
667
|
+
if (value !== (valueType.default || 0))
|
|
875
668
|
transformIsNone = false;
|
|
876
669
|
}
|
|
877
|
-
else if (
|
|
878
|
-
transformOrigin[key] = valueAsType;
|
|
670
|
+
else if (key.startsWith("origin")) {
|
|
879
671
|
// If this is a transform origin, flag and enable further transform-origin processing
|
|
880
672
|
hasTransformOrigin = true;
|
|
673
|
+
transformOrigin[key] = valueAsType;
|
|
881
674
|
}
|
|
882
675
|
else {
|
|
883
676
|
style[key] = valueAsType;
|
|
884
677
|
}
|
|
885
678
|
}
|
|
886
|
-
if (hasTransform) {
|
|
679
|
+
if (hasTransform || transformTemplate) {
|
|
887
680
|
style.transform = buildTransform(state, options, transformIsNone, transformTemplate);
|
|
888
681
|
}
|
|
889
|
-
else if (transformTemplate) {
|
|
890
|
-
style.transform = transformTemplate({}, "");
|
|
891
|
-
}
|
|
892
682
|
else if (!latestValues.transform && style.transform) {
|
|
683
|
+
/**
|
|
684
|
+
* If we have previously created a transform but currently don't have any,
|
|
685
|
+
* reset transform style to none.
|
|
686
|
+
*/
|
|
893
687
|
style.transform = "none";
|
|
894
688
|
}
|
|
689
|
+
/**
|
|
690
|
+
* Build a transformOrigin style. Uses the same defaults as the browser for
|
|
691
|
+
* undefined origins.
|
|
692
|
+
*/
|
|
895
693
|
if (hasTransformOrigin) {
|
|
896
|
-
|
|
694
|
+
const { originX = "50%", originY = "50%", originZ = 0, } = transformOrigin;
|
|
695
|
+
style.transformOrigin = `${originX} ${originY} ${originZ}`;
|
|
897
696
|
}
|
|
898
697
|
}
|
|
899
698
|
|
|
@@ -916,28 +715,24 @@ function useInitialMotionValues({ transformTemplate }, visualState, isStatic) {
|
|
|
916
715
|
return React.useMemo(() => {
|
|
917
716
|
const state = createHtmlRenderState();
|
|
918
717
|
buildHTMLStyles(state, visualState, { enableHardwareAcceleration: !isStatic }, transformTemplate);
|
|
919
|
-
|
|
920
|
-
return Object.assign(Object.assign({}, vars), style);
|
|
718
|
+
return Object.assign({}, state.vars, state.style);
|
|
921
719
|
}, [visualState]);
|
|
922
720
|
}
|
|
923
721
|
function useStyle(props, visualState, isStatic) {
|
|
924
722
|
const styleProp = props.style || {};
|
|
925
|
-
|
|
723
|
+
const style = {};
|
|
926
724
|
/**
|
|
927
725
|
* Copy non-Motion Values straight into style
|
|
928
726
|
*/
|
|
929
727
|
copyRawValuesOnly(style, styleProp, props);
|
|
930
728
|
Object.assign(style, useInitialMotionValues(props, visualState, isStatic));
|
|
931
|
-
|
|
932
|
-
style = props.transformValues(style);
|
|
933
|
-
}
|
|
934
|
-
return style;
|
|
729
|
+
return props.transformValues ? props.transformValues(style) : style;
|
|
935
730
|
}
|
|
936
731
|
function useHTMLProps(props, visualState, isStatic) {
|
|
937
732
|
// The `any` isn't ideal but it is the type of createElement props argument
|
|
938
733
|
const htmlProps = {};
|
|
939
734
|
const style = useStyle(props, visualState, isStatic);
|
|
940
|
-
if (
|
|
735
|
+
if (props.drag && props.dragListener !== false) {
|
|
941
736
|
// Disable the ghost element when a user drags
|
|
942
737
|
htmlProps.draggable = false;
|
|
943
738
|
// Disable text selection
|
|
@@ -955,6 +750,24 @@ function useHTMLProps(props, visualState, isStatic) {
|
|
|
955
750
|
return htmlProps;
|
|
956
751
|
}
|
|
957
752
|
|
|
753
|
+
const animationProps = [
|
|
754
|
+
"animate",
|
|
755
|
+
"exit",
|
|
756
|
+
"variants",
|
|
757
|
+
"whileHover",
|
|
758
|
+
"whileTap",
|
|
759
|
+
"whileFocus",
|
|
760
|
+
"whileDrag",
|
|
761
|
+
"whileInView",
|
|
762
|
+
];
|
|
763
|
+
const tapProps = ["whileTap", "onTap", "onTapStart", "onTapCancel"];
|
|
764
|
+
const panProps = ["onPan", "onPanStart", "onPanSessionStart", "onPanEnd"];
|
|
765
|
+
const inViewProps = [
|
|
766
|
+
"whileInView",
|
|
767
|
+
"onViewportEnter",
|
|
768
|
+
"onViewportLeave",
|
|
769
|
+
"viewport",
|
|
770
|
+
];
|
|
958
771
|
/**
|
|
959
772
|
* A list of all valid MotionProps.
|
|
960
773
|
*
|
|
@@ -963,8 +776,6 @@ function useHTMLProps(props, visualState, isStatic) {
|
|
|
963
776
|
*/
|
|
964
777
|
const validMotionProps = new Set([
|
|
965
778
|
"initial",
|
|
966
|
-
"animate",
|
|
967
|
-
"exit",
|
|
968
779
|
"style",
|
|
969
780
|
"variants",
|
|
970
781
|
"transition",
|
|
@@ -1000,24 +811,13 @@ const validMotionProps = new Set([
|
|
|
1000
811
|
"dragMomentum",
|
|
1001
812
|
"dragPropagation",
|
|
1002
813
|
"dragTransition",
|
|
1003
|
-
"whileDrag",
|
|
1004
|
-
"onPan",
|
|
1005
|
-
"onPanStart",
|
|
1006
|
-
"onPanEnd",
|
|
1007
|
-
"onPanSessionStart",
|
|
1008
|
-
"onTap",
|
|
1009
|
-
"onTapStart",
|
|
1010
|
-
"onTapCancel",
|
|
1011
814
|
"onHoverStart",
|
|
1012
815
|
"onHoverEnd",
|
|
1013
|
-
"whileFocus",
|
|
1014
|
-
"whileTap",
|
|
1015
|
-
"whileHover",
|
|
1016
|
-
"whileInView",
|
|
1017
|
-
"onViewportEnter",
|
|
1018
|
-
"onViewportLeave",
|
|
1019
|
-
"viewport",
|
|
1020
816
|
"layoutScroll",
|
|
817
|
+
...inViewProps,
|
|
818
|
+
...tapProps,
|
|
819
|
+
...animationProps,
|
|
820
|
+
...panProps,
|
|
1021
821
|
]);
|
|
1022
822
|
/**
|
|
1023
823
|
* Check whether a prop name is a valid `MotionProp` key.
|
|
@@ -1123,10 +923,9 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
1123
923
|
/**
|
|
1124
924
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
1125
925
|
*/
|
|
1126
|
-
function buildSVGAttrs(state,
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
latest = tslib.__rest(_a, ["attrX", "attrY", "originX", "originY", "pathLength", "pathSpacing", "pathOffset"]);
|
|
926
|
+
function buildSVGAttrs(state, { attrX, attrY, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0,
|
|
927
|
+
// This is object creation, which we try to avoid per-frame.
|
|
928
|
+
...latest }, options, transformTemplate) {
|
|
1130
929
|
buildHTMLStyles(state, latest, options, transformTemplate);
|
|
1131
930
|
state.attrs = state.style;
|
|
1132
931
|
state.style = {};
|
|
@@ -1156,18 +955,24 @@ function buildSVGAttrs(state, _a, options, transformTemplate) {
|
|
|
1156
955
|
}
|
|
1157
956
|
}
|
|
1158
957
|
|
|
1159
|
-
const createSvgRenderState = () => (
|
|
958
|
+
const createSvgRenderState = () => ({
|
|
959
|
+
...createHtmlRenderState(),
|
|
960
|
+
attrs: {},
|
|
961
|
+
});
|
|
1160
962
|
|
|
1161
963
|
function useSVGProps(props, visualState) {
|
|
1162
964
|
const visualProps = React.useMemo(() => {
|
|
1163
965
|
const state = createSvgRenderState();
|
|
1164
966
|
buildSVGAttrs(state, visualState, { enableHardwareAcceleration: false }, props.transformTemplate);
|
|
1165
|
-
return
|
|
967
|
+
return {
|
|
968
|
+
...state.attrs,
|
|
969
|
+
style: { ...state.style },
|
|
970
|
+
};
|
|
1166
971
|
}, [visualState]);
|
|
1167
972
|
if (props.style) {
|
|
1168
973
|
const rawStyles = {};
|
|
1169
974
|
copyRawValuesOnly(rawStyles, props.style, props);
|
|
1170
|
-
visualProps.style =
|
|
975
|
+
visualProps.style = { ...rawStyles, ...visualProps.style };
|
|
1171
976
|
}
|
|
1172
977
|
return visualProps;
|
|
1173
978
|
}
|
|
@@ -1179,7 +984,11 @@ function createUseRender(forwardMotionProps = false) {
|
|
|
1179
984
|
: useHTMLProps;
|
|
1180
985
|
const visualProps = useVisualProps(props, latestValues, isStatic);
|
|
1181
986
|
const filteredProps = filterProps(props, typeof Component === "string", forwardMotionProps);
|
|
1182
|
-
const elementProps =
|
|
987
|
+
const elementProps = {
|
|
988
|
+
...filteredProps,
|
|
989
|
+
...visualProps,
|
|
990
|
+
ref,
|
|
991
|
+
};
|
|
1183
992
|
if (projectionId) {
|
|
1184
993
|
elementProps["data-projection-id"] = projectionId;
|
|
1185
994
|
}
|
|
@@ -1188,12 +997,10 @@ function createUseRender(forwardMotionProps = false) {
|
|
|
1188
997
|
return useRender;
|
|
1189
998
|
}
|
|
1190
999
|
|
|
1191
|
-
const CAMEL_CASE_PATTERN = /([a-z])([A-Z])/g;
|
|
1192
|
-
const REPLACE_TEMPLATE = "$1-$2";
|
|
1193
1000
|
/**
|
|
1194
1001
|
* Convert camelCase to dash-case properties.
|
|
1195
1002
|
*/
|
|
1196
|
-
const camelToDash = (str) => str.replace(
|
|
1003
|
+
const camelToDash = (str) => str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
1197
1004
|
|
|
1198
1005
|
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
1199
1006
|
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
@@ -1258,8 +1065,29 @@ function scrapeMotionValuesFromProps(props) {
|
|
|
1258
1065
|
return newValues;
|
|
1259
1066
|
}
|
|
1260
1067
|
|
|
1261
|
-
function
|
|
1262
|
-
|
|
1068
|
+
function resolveVariantFromProps(props, definition, custom, currentValues = {}, currentVelocity = {}) {
|
|
1069
|
+
/**
|
|
1070
|
+
* If the variant definition is a function, resolve.
|
|
1071
|
+
*/
|
|
1072
|
+
if (typeof definition === "function") {
|
|
1073
|
+
definition = definition(custom !== undefined ? custom : props.custom, currentValues, currentVelocity);
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* If the variant definition is a variant label, or
|
|
1077
|
+
* the function returned a variant label, resolve.
|
|
1078
|
+
*/
|
|
1079
|
+
if (typeof definition === "string") {
|
|
1080
|
+
definition = props.variants && props.variants[definition];
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* At this point we've resolved both functions and variant labels,
|
|
1084
|
+
* but the resolved variant label might itself have been a function.
|
|
1085
|
+
* If so, resolve. This can only have returned a valid target object.
|
|
1086
|
+
*/
|
|
1087
|
+
if (typeof definition === "function") {
|
|
1088
|
+
definition = definition(custom !== undefined ? custom : props.custom, currentValues, currentVelocity);
|
|
1089
|
+
}
|
|
1090
|
+
return definition;
|
|
1263
1091
|
}
|
|
1264
1092
|
|
|
1265
1093
|
const isKeyframesTarget = (v) => {
|
|
@@ -1299,29 +1127,32 @@ function makeState({ scrapeMotionValuesFromProps, createRenderState, onMount, },
|
|
|
1299
1127
|
const makeUseVisualState = (config) => (props, isStatic) => {
|
|
1300
1128
|
const context = React.useContext(MotionContext);
|
|
1301
1129
|
const presenceContext = React.useContext(PresenceContext);
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
: useConstant(() => makeState(config, props, context, presenceContext));
|
|
1130
|
+
const make = () => makeState(config, props, context, presenceContext);
|
|
1131
|
+
return isStatic ? make() : useConstant(make);
|
|
1305
1132
|
};
|
|
1306
1133
|
function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
1307
1134
|
const values = {};
|
|
1308
|
-
const blockInitialAnimation = (presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.initial) === false;
|
|
1309
1135
|
const motionValues = scrapeMotionValues(props);
|
|
1310
1136
|
for (const key in motionValues) {
|
|
1311
1137
|
values[key] = resolveMotionValue(motionValues[key]);
|
|
1312
1138
|
}
|
|
1313
1139
|
let { initial, animate } = props;
|
|
1314
|
-
const isControllingVariants =
|
|
1315
|
-
const isVariantNode =
|
|
1140
|
+
const isControllingVariants$1 = isControllingVariants(props);
|
|
1141
|
+
const isVariantNode$1 = isVariantNode(props);
|
|
1316
1142
|
if (context &&
|
|
1317
|
-
isVariantNode &&
|
|
1318
|
-
!isControllingVariants &&
|
|
1143
|
+
isVariantNode$1 &&
|
|
1144
|
+
!isControllingVariants$1 &&
|
|
1319
1145
|
props.inherit !== false) {
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1146
|
+
if (initial === undefined)
|
|
1147
|
+
initial = context.initial;
|
|
1148
|
+
if (animate === undefined)
|
|
1149
|
+
animate = context.animate;
|
|
1150
|
+
}
|
|
1151
|
+
let isInitialAnimationBlocked = presenceContext
|
|
1152
|
+
? presenceContext.initial === false
|
|
1153
|
+
: false;
|
|
1154
|
+
isInitialAnimationBlocked = isInitialAnimationBlocked || initial === false;
|
|
1155
|
+
const variantToSet = isInitialAnimationBlocked ? animate : initial;
|
|
1325
1156
|
if (variantToSet &&
|
|
1326
1157
|
typeof variantToSet !== "boolean" &&
|
|
1327
1158
|
!isAnimationControls(variantToSet)) {
|
|
@@ -1330,7 +1161,7 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
|
1330
1161
|
const resolved = resolveVariantFromProps(props, definition);
|
|
1331
1162
|
if (!resolved)
|
|
1332
1163
|
return;
|
|
1333
|
-
const { transitionEnd, transition
|
|
1164
|
+
const { transitionEnd, transition, ...target } = resolved;
|
|
1334
1165
|
for (const key in target) {
|
|
1335
1166
|
let valueTarget = target[key];
|
|
1336
1167
|
if (Array.isArray(valueTarget)) {
|
|
@@ -1338,7 +1169,7 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
|
1338
1169
|
* Take final keyframe if the initial animation is blocked because
|
|
1339
1170
|
* we want to initialise at the end of that blocked animation.
|
|
1340
1171
|
*/
|
|
1341
|
-
const index =
|
|
1172
|
+
const index = isInitialAnimationBlocked
|
|
1342
1173
|
? valueTarget.length - 1
|
|
1343
1174
|
: 0;
|
|
1344
1175
|
valueTarget = valueTarget[index];
|
|
@@ -1392,9 +1223,14 @@ function createDomMotionConfig(Component, { forwardMotionProps = false }, preloa
|
|
|
1392
1223
|
const baseConfig = isSVGComponent(Component)
|
|
1393
1224
|
? svgMotionConfig
|
|
1394
1225
|
: htmlMotionConfig;
|
|
1395
|
-
return
|
|
1226
|
+
return {
|
|
1227
|
+
...baseConfig,
|
|
1228
|
+
preloadedFeatures,
|
|
1229
|
+
useRender: createUseRender(forwardMotionProps),
|
|
1230
|
+
createVisualElement,
|
|
1396
1231
|
projectionNodeConstructor,
|
|
1397
|
-
Component
|
|
1232
|
+
Component,
|
|
1233
|
+
};
|
|
1398
1234
|
}
|
|
1399
1235
|
|
|
1400
1236
|
exports.AnimationType = void 0;
|
|
@@ -1449,13 +1285,12 @@ function useDomEvent(ref, eventName, handler, options) {
|
|
|
1449
1285
|
* @internal
|
|
1450
1286
|
*/
|
|
1451
1287
|
function useFocusGesture({ whileFocus, visualElement }) {
|
|
1288
|
+
const { animationState } = visualElement;
|
|
1452
1289
|
const onFocus = () => {
|
|
1453
|
-
|
|
1454
|
-
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(exports.AnimationType.Focus, true);
|
|
1290
|
+
animationState && animationState.setActive(exports.AnimationType.Focus, true);
|
|
1455
1291
|
};
|
|
1456
1292
|
const onBlur = () => {
|
|
1457
|
-
|
|
1458
|
-
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(exports.AnimationType.Focus, false);
|
|
1293
|
+
animationState && animationState.setActive(exports.AnimationType.Focus, false);
|
|
1459
1294
|
};
|
|
1460
1295
|
useDomEvent(visualElement, "focus", whileFocus ? onFocus : undefined);
|
|
1461
1296
|
useDomEvent(visualElement, "blur", whileFocus ? onBlur : undefined);
|
|
@@ -1610,14 +1445,15 @@ function isDragActive() {
|
|
|
1610
1445
|
|
|
1611
1446
|
function createHoverEvent(visualElement, isActive, callback) {
|
|
1612
1447
|
return (event, info) => {
|
|
1613
|
-
var _a;
|
|
1614
1448
|
if (!isMouseEvent(event) || isDragActive())
|
|
1615
1449
|
return;
|
|
1616
1450
|
/**
|
|
1617
1451
|
* Ensure we trigger animations before firing event callback
|
|
1618
1452
|
*/
|
|
1619
|
-
(
|
|
1620
|
-
|
|
1453
|
+
if (visualElement.animationState) {
|
|
1454
|
+
visualElement.animationState.setActive(exports.AnimationType.Hover, isActive);
|
|
1455
|
+
}
|
|
1456
|
+
callback && callback(event, info);
|
|
1621
1457
|
};
|
|
1622
1458
|
}
|
|
1623
1459
|
function useHoverGesture({ onHoverStart, onHoverEnd, whileHover, visualElement, }) {
|
|
@@ -1667,15 +1503,14 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
|
|
|
1667
1503
|
passive: !(onTapStart || onTap || onTapCancel || onPointerDown),
|
|
1668
1504
|
};
|
|
1669
1505
|
function removePointerEndListener() {
|
|
1670
|
-
|
|
1671
|
-
(_a = cancelPointerEndListeners.current) === null || _a === void 0 ? void 0 : _a.call(cancelPointerEndListeners);
|
|
1506
|
+
cancelPointerEndListeners.current && cancelPointerEndListeners.current();
|
|
1672
1507
|
cancelPointerEndListeners.current = null;
|
|
1673
1508
|
}
|
|
1674
1509
|
function checkPointerEnd() {
|
|
1675
|
-
var _a;
|
|
1676
1510
|
removePointerEndListener();
|
|
1677
1511
|
isPressing.current = false;
|
|
1678
|
-
|
|
1512
|
+
visualElement.animationState &&
|
|
1513
|
+
visualElement.animationState.setActive(exports.AnimationType.Tap, false);
|
|
1679
1514
|
return !isDragActive();
|
|
1680
1515
|
}
|
|
1681
1516
|
function onPointerUp(event, info) {
|
|
@@ -1686,16 +1521,15 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
|
|
|
1686
1521
|
* as, or a child of, this component's element
|
|
1687
1522
|
*/
|
|
1688
1523
|
!isNodeOrChild(visualElement.getInstance(), event.target)
|
|
1689
|
-
? onTapCancel
|
|
1690
|
-
: onTap
|
|
1524
|
+
? onTapCancel && onTapCancel(event, info)
|
|
1525
|
+
: onTap && onTap(event, info);
|
|
1691
1526
|
}
|
|
1692
1527
|
function onPointerCancel(event, info) {
|
|
1693
1528
|
if (!checkPointerEnd())
|
|
1694
1529
|
return;
|
|
1695
|
-
onTapCancel
|
|
1530
|
+
onTapCancel && onTapCancel(event, info);
|
|
1696
1531
|
}
|
|
1697
1532
|
function onPointerDown(event, info) {
|
|
1698
|
-
var _a;
|
|
1699
1533
|
removePointerEndListener();
|
|
1700
1534
|
if (isPressing.current)
|
|
1701
1535
|
return;
|
|
@@ -1704,13 +1538,22 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
|
|
|
1704
1538
|
/**
|
|
1705
1539
|
* Ensure we trigger animations before firing event callback
|
|
1706
1540
|
*/
|
|
1707
|
-
|
|
1708
|
-
|
|
1541
|
+
visualElement.animationState &&
|
|
1542
|
+
visualElement.animationState.setActive(exports.AnimationType.Tap, true);
|
|
1543
|
+
onTapStart && onTapStart(event, info);
|
|
1709
1544
|
}
|
|
1710
1545
|
usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined, eventOptions);
|
|
1711
1546
|
useUnmountEffect(removePointerEndListener);
|
|
1712
1547
|
}
|
|
1713
1548
|
|
|
1549
|
+
/**
|
|
1550
|
+
* Browser-safe usage of process
|
|
1551
|
+
*/
|
|
1552
|
+
const defaultEnvironment = "production";
|
|
1553
|
+
const env = typeof process === "undefined" || process.env === undefined
|
|
1554
|
+
? defaultEnvironment
|
|
1555
|
+
: process.env.NODE_ENV || defaultEnvironment;
|
|
1556
|
+
|
|
1714
1557
|
const warned = new Set();
|
|
1715
1558
|
function warnOnce(condition, message, element) {
|
|
1716
1559
|
if (condition || warned.has(message))
|
|
@@ -1734,14 +1577,13 @@ const observerCallbacks = new WeakMap();
|
|
|
1734
1577
|
*/
|
|
1735
1578
|
const observers = new WeakMap();
|
|
1736
1579
|
const fireObserverCallback = (entry) => {
|
|
1737
|
-
|
|
1738
|
-
|
|
1580
|
+
const callback = observerCallbacks.get(entry.target);
|
|
1581
|
+
callback && callback(entry);
|
|
1739
1582
|
};
|
|
1740
1583
|
const fireAllObserverCallbacks = (entries) => {
|
|
1741
1584
|
entries.forEach(fireObserverCallback);
|
|
1742
1585
|
};
|
|
1743
|
-
function initIntersectionObserver(
|
|
1744
|
-
var { root } = _a, options = tslib.__rest(_a, ["root"]);
|
|
1586
|
+
function initIntersectionObserver({ root, ...options }) {
|
|
1745
1587
|
const lookupRoot = root || document;
|
|
1746
1588
|
/**
|
|
1747
1589
|
* If we don't have an observer lookup map for this root, create one.
|
|
@@ -1756,7 +1598,7 @@ function initIntersectionObserver(_a) {
|
|
|
1756
1598
|
* create one.
|
|
1757
1599
|
*/
|
|
1758
1600
|
if (!rootObservers[key]) {
|
|
1759
|
-
rootObservers[key] = new IntersectionObserver(fireAllObserverCallbacks,
|
|
1601
|
+
rootObservers[key] = new IntersectionObserver(fireAllObserverCallbacks, { root, ...options });
|
|
1760
1602
|
}
|
|
1761
1603
|
return rootObservers[key];
|
|
1762
1604
|
}
|
|
@@ -1797,7 +1639,6 @@ function useIntersectionObserver(shouldObserve, state, visualElement, { root, ma
|
|
|
1797
1639
|
threshold: typeof amount === "number" ? amount : thresholdNames[amount],
|
|
1798
1640
|
};
|
|
1799
1641
|
const intersectionCallback = (entry) => {
|
|
1800
|
-
var _a;
|
|
1801
1642
|
const { isIntersecting } = entry;
|
|
1802
1643
|
/**
|
|
1803
1644
|
* If there's been no change in the viewport state, early return.
|
|
@@ -1815,7 +1656,9 @@ function useIntersectionObserver(shouldObserve, state, visualElement, { root, ma
|
|
|
1815
1656
|
else if (isIntersecting) {
|
|
1816
1657
|
state.hasEnteredView = true;
|
|
1817
1658
|
}
|
|
1818
|
-
(
|
|
1659
|
+
if (visualElement.animationState) {
|
|
1660
|
+
visualElement.animationState.setActive(exports.AnimationType.InView, isIntersecting);
|
|
1661
|
+
}
|
|
1819
1662
|
/**
|
|
1820
1663
|
* Use the latest committed props rather than the ones in scope
|
|
1821
1664
|
* when this observer is created
|
|
@@ -1824,7 +1667,7 @@ function useIntersectionObserver(shouldObserve, state, visualElement, { root, ma
|
|
|
1824
1667
|
const callback = isIntersecting
|
|
1825
1668
|
? props.onViewportEnter
|
|
1826
1669
|
: props.onViewportLeave;
|
|
1827
|
-
callback
|
|
1670
|
+
callback && callback(entry);
|
|
1828
1671
|
};
|
|
1829
1672
|
return observeIntersection(visualElement.getInstance(), options, intersectionCallback);
|
|
1830
1673
|
}, [shouldObserve, root, rootMargin, amount]);
|
|
@@ -1850,11 +1693,12 @@ function useMissingIntersectionObserver(shouldObserve, state, visualElement, { f
|
|
|
1850
1693
|
* is preferred to changing the behaviour of the animation state.
|
|
1851
1694
|
*/
|
|
1852
1695
|
requestAnimationFrame(() => {
|
|
1853
|
-
var _a;
|
|
1854
1696
|
state.hasEnteredView = true;
|
|
1855
1697
|
const { onViewportEnter } = visualElement.getProps();
|
|
1856
|
-
onViewportEnter
|
|
1857
|
-
(
|
|
1698
|
+
onViewportEnter && onViewportEnter(null);
|
|
1699
|
+
if (visualElement.animationState) {
|
|
1700
|
+
visualElement.animationState.setActive(exports.AnimationType.InView, true);
|
|
1701
|
+
}
|
|
1858
1702
|
});
|
|
1859
1703
|
}, [shouldObserve]);
|
|
1860
1704
|
}
|
|
@@ -1904,7 +1748,7 @@ function usePresence() {
|
|
|
1904
1748
|
// Replace with useId when released in React
|
|
1905
1749
|
const id = React.useId();
|
|
1906
1750
|
React.useEffect(() => register(id), []);
|
|
1907
|
-
const safeToRemove = () => onExitComplete
|
|
1751
|
+
const safeToRemove = () => onExitComplete && onExitComplete(id);
|
|
1908
1752
|
return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
|
|
1909
1753
|
}
|
|
1910
1754
|
/**
|
|
@@ -2063,17 +1907,29 @@ const getDefaultTransition = (valueKey, to) => {
|
|
|
2063
1907
|
transitionFactory =
|
|
2064
1908
|
defaultTransitions[valueKey] || defaultTransitions.default;
|
|
2065
1909
|
}
|
|
2066
|
-
return
|
|
1910
|
+
return { to, ...transitionFactory(to) };
|
|
2067
1911
|
};
|
|
2068
1912
|
|
|
2069
1913
|
/**
|
|
2070
1914
|
* A map of default value types for common values
|
|
2071
1915
|
*/
|
|
2072
|
-
const defaultValueTypes =
|
|
1916
|
+
const defaultValueTypes = {
|
|
1917
|
+
...numberValueTypes,
|
|
2073
1918
|
// Color props
|
|
2074
|
-
color: styleValueTypes.color,
|
|
1919
|
+
color: styleValueTypes.color,
|
|
1920
|
+
backgroundColor: styleValueTypes.color,
|
|
1921
|
+
outlineColor: styleValueTypes.color,
|
|
1922
|
+
fill: styleValueTypes.color,
|
|
1923
|
+
stroke: styleValueTypes.color,
|
|
2075
1924
|
// Border props
|
|
2076
|
-
borderColor: styleValueTypes.color,
|
|
1925
|
+
borderColor: styleValueTypes.color,
|
|
1926
|
+
borderTopColor: styleValueTypes.color,
|
|
1927
|
+
borderRightColor: styleValueTypes.color,
|
|
1928
|
+
borderBottomColor: styleValueTypes.color,
|
|
1929
|
+
borderLeftColor: styleValueTypes.color,
|
|
1930
|
+
filter: styleValueTypes.filter,
|
|
1931
|
+
WebkitFilter: styleValueTypes.filter,
|
|
1932
|
+
};
|
|
2077
1933
|
/**
|
|
2078
1934
|
* Gets the default ValueType for the provided value key
|
|
2079
1935
|
*/
|
|
@@ -2097,17 +1953,15 @@ const instantAnimationState = {
|
|
|
2097
1953
|
* This filters out orchestration options and returns true
|
|
2098
1954
|
* if any options are left.
|
|
2099
1955
|
*/
|
|
2100
|
-
function isTransitionDefined(
|
|
2101
|
-
var transition = tslib.__rest(_a, ["when", "delay", "delayChildren", "staggerChildren", "staggerDirection", "repeat", "repeatType", "repeatDelay", "from"]);
|
|
1956
|
+
function isTransitionDefined({ when, delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
|
|
2102
1957
|
return !!Object.keys(transition).length;
|
|
2103
1958
|
}
|
|
2104
1959
|
let legacyRepeatWarning = false;
|
|
2105
1960
|
/**
|
|
2106
1961
|
* Convert Framer Motion's Transition type into Popmotion-compatible options.
|
|
2107
1962
|
*/
|
|
2108
|
-
function convertTransitionToAnimationOptions(
|
|
2109
|
-
|
|
2110
|
-
const options = Object.assign({}, transition);
|
|
1963
|
+
function convertTransitionToAnimationOptions({ ease, times, yoyo, flip, loop, ...transition }) {
|
|
1964
|
+
const options = { ...transition };
|
|
2111
1965
|
if (times)
|
|
2112
1966
|
options["offset"] = times;
|
|
2113
1967
|
/**
|
|
@@ -2172,26 +2026,30 @@ function hydrateKeyframes(options) {
|
|
|
2172
2026
|
return options;
|
|
2173
2027
|
}
|
|
2174
2028
|
function getPopmotionAnimationOptions(transition, options, key) {
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
(_a = transition.duration) !== null && _a !== void 0 ? _a : (transition.duration = 0.8);
|
|
2029
|
+
if (Array.isArray(options.to) && transition.duration === undefined) {
|
|
2030
|
+
transition.duration = 0.8;
|
|
2178
2031
|
}
|
|
2179
2032
|
hydrateKeyframes(options);
|
|
2180
2033
|
/**
|
|
2181
2034
|
* Get a default transition if none is determined to be defined.
|
|
2182
2035
|
*/
|
|
2183
2036
|
if (!isTransitionDefined(transition)) {
|
|
2184
|
-
transition =
|
|
2037
|
+
transition = {
|
|
2038
|
+
...transition,
|
|
2039
|
+
...getDefaultTransition(key, options.to),
|
|
2040
|
+
};
|
|
2185
2041
|
}
|
|
2186
|
-
return
|
|
2042
|
+
return {
|
|
2043
|
+
...options,
|
|
2044
|
+
...convertTransitionToAnimationOptions(transition),
|
|
2045
|
+
};
|
|
2187
2046
|
}
|
|
2188
2047
|
/**
|
|
2189
2048
|
*
|
|
2190
2049
|
*/
|
|
2191
2050
|
function getAnimation(key, value, target, transition, onComplete) {
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
let origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
|
|
2051
|
+
const valueTransition = getValueTransition(transition, key) || {};
|
|
2052
|
+
let origin = valueTransition.from !== undefined ? valueTransition.from : value.get();
|
|
2195
2053
|
const isTargetAnimatable = isAnimatable(key, target);
|
|
2196
2054
|
if (origin === "none" && isTargetAnimatable && typeof target === "string") {
|
|
2197
2055
|
/**
|
|
@@ -2220,24 +2078,25 @@ function getAnimation(key, value, target, transition, onComplete) {
|
|
|
2220
2078
|
};
|
|
2221
2079
|
return valueTransition.type === "inertia" ||
|
|
2222
2080
|
valueTransition.type === "decay"
|
|
2223
|
-
? popmotion.inertia(
|
|
2224
|
-
: popmotion.animate(
|
|
2225
|
-
|
|
2081
|
+
? popmotion.inertia({ ...options, ...valueTransition })
|
|
2082
|
+
: popmotion.animate({
|
|
2083
|
+
...getPopmotionAnimationOptions(valueTransition, options, key),
|
|
2084
|
+
onUpdate: (v) => {
|
|
2226
2085
|
options.onUpdate(v);
|
|
2227
|
-
|
|
2228
|
-
},
|
|
2229
|
-
|
|
2086
|
+
valueTransition.onUpdate && valueTransition.onUpdate(v);
|
|
2087
|
+
},
|
|
2088
|
+
onComplete: () => {
|
|
2230
2089
|
options.onComplete();
|
|
2231
|
-
|
|
2232
|
-
}
|
|
2090
|
+
valueTransition.onComplete && valueTransition.onComplete();
|
|
2091
|
+
},
|
|
2092
|
+
});
|
|
2233
2093
|
}
|
|
2234
2094
|
function set() {
|
|
2235
|
-
var _a, _b;
|
|
2236
2095
|
const finalTarget = resolveFinalValueInKeyframes(target);
|
|
2237
2096
|
value.set(finalTarget);
|
|
2238
2097
|
onComplete();
|
|
2239
|
-
|
|
2240
|
-
|
|
2098
|
+
valueTransition.onUpdate && valueTransition.onUpdate(finalTarget);
|
|
2099
|
+
valueTransition.onComplete && valueTransition.onComplete();
|
|
2241
2100
|
return { stop: () => { } };
|
|
2242
2101
|
}
|
|
2243
2102
|
return !isOriginAnimatable ||
|
|
@@ -2282,7 +2141,7 @@ function startAnimation(key, value, target, transition = {}) {
|
|
|
2282
2141
|
}
|
|
2283
2142
|
return () => {
|
|
2284
2143
|
clearTimeout(delayTimer);
|
|
2285
|
-
controls
|
|
2144
|
+
controls && controls.stop();
|
|
2286
2145
|
};
|
|
2287
2146
|
});
|
|
2288
2147
|
}
|
|
@@ -2376,7 +2235,7 @@ class MotionValue {
|
|
|
2376
2235
|
* This will be replaced by the build step with the latest version number.
|
|
2377
2236
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
2378
2237
|
*/
|
|
2379
|
-
this.version = "7.2.
|
|
2238
|
+
this.version = "7.2.1";
|
|
2380
2239
|
/**
|
|
2381
2240
|
* Duration, in milliseconds, since last updating frame.
|
|
2382
2241
|
*
|
|
@@ -2685,6 +2544,27 @@ const valueTypes = [...dimensionValueTypes, styleValueTypes.color, styleValueTyp
|
|
|
2685
2544
|
*/
|
|
2686
2545
|
const findValueType = (v) => valueTypes.find(testValueType(v));
|
|
2687
2546
|
|
|
2547
|
+
/**
|
|
2548
|
+
* Creates an object containing the latest state of every MotionValue on a VisualElement
|
|
2549
|
+
*/
|
|
2550
|
+
function getCurrent(visualElement) {
|
|
2551
|
+
const current = {};
|
|
2552
|
+
visualElement.forEachValue((value, key) => (current[key] = value.get()));
|
|
2553
|
+
return current;
|
|
2554
|
+
}
|
|
2555
|
+
/**
|
|
2556
|
+
* Creates an object containing the latest velocity of every MotionValue on a VisualElement
|
|
2557
|
+
*/
|
|
2558
|
+
function getVelocity$1(visualElement) {
|
|
2559
|
+
const velocity = {};
|
|
2560
|
+
visualElement.forEachValue((value, key) => (velocity[key] = value.getVelocity()));
|
|
2561
|
+
return velocity;
|
|
2562
|
+
}
|
|
2563
|
+
function resolveVariant(visualElement, definition, custom) {
|
|
2564
|
+
const props = visualElement.getProps();
|
|
2565
|
+
return resolveVariantFromProps(props, definition, custom !== undefined ? custom : props.custom, getCurrent(visualElement), getVelocity$1(visualElement));
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2688
2568
|
/**
|
|
2689
2569
|
* Set VisualElement's MotionValue, creating a new MotionValue for it if
|
|
2690
2570
|
* it doesn't exist.
|
|
@@ -2699,8 +2579,8 @@ function setMotionValue(visualElement, key, value) {
|
|
|
2699
2579
|
}
|
|
2700
2580
|
function setTarget(visualElement, definition) {
|
|
2701
2581
|
const resolved = resolveVariant(visualElement, definition);
|
|
2702
|
-
let
|
|
2703
|
-
target =
|
|
2582
|
+
let { transitionEnd = {}, transition = {}, ...target } = resolved ? visualElement.makeTargetAnimatable(resolved, false) : {};
|
|
2583
|
+
target = { ...target, ...transitionEnd };
|
|
2704
2584
|
for (const key in target) {
|
|
2705
2585
|
const value = resolveFinalValueInKeyframes(target[key]);
|
|
2706
2586
|
setMotionValue(visualElement, key, value);
|
|
@@ -2729,8 +2609,7 @@ function setValues(visualElement, definition) {
|
|
|
2729
2609
|
}
|
|
2730
2610
|
}
|
|
2731
2611
|
function checkTargetForNewValues(visualElement, target, origin) {
|
|
2732
|
-
var _a, _b
|
|
2733
|
-
var _d;
|
|
2612
|
+
var _a, _b;
|
|
2734
2613
|
const newValueKeys = Object.keys(target).filter((key) => !visualElement.hasValue(key));
|
|
2735
2614
|
const numNewValues = newValueKeys.length;
|
|
2736
2615
|
if (!numNewValues)
|
|
@@ -2769,7 +2648,9 @@ function checkTargetForNewValues(visualElement, target, origin) {
|
|
|
2769
2648
|
value = getAnimatableNone(key, targetValue);
|
|
2770
2649
|
}
|
|
2771
2650
|
visualElement.addValue(key, motionValue(value));
|
|
2772
|
-
|
|
2651
|
+
if (origin[key] === undefined) {
|
|
2652
|
+
origin[key] = value;
|
|
2653
|
+
}
|
|
2773
2654
|
visualElement.setBaseTarget(key, value);
|
|
2774
2655
|
}
|
|
2775
2656
|
}
|
|
@@ -2780,11 +2661,14 @@ function getOriginFromTransition(key, transition) {
|
|
|
2780
2661
|
return valueTransition.from;
|
|
2781
2662
|
}
|
|
2782
2663
|
function getOrigin(target, transition, visualElement) {
|
|
2783
|
-
var _a
|
|
2664
|
+
var _a;
|
|
2784
2665
|
const origin = {};
|
|
2785
2666
|
for (const key in target) {
|
|
2667
|
+
const transitionOrigin = getOriginFromTransition(key, transition);
|
|
2786
2668
|
origin[key] =
|
|
2787
|
-
|
|
2669
|
+
transitionOrigin !== undefined
|
|
2670
|
+
? transitionOrigin
|
|
2671
|
+
: (_a = visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.get();
|
|
2788
2672
|
}
|
|
2789
2673
|
return origin;
|
|
2790
2674
|
}
|
|
@@ -2855,7 +2739,7 @@ function animateVariant(visualElement, variant, options = {}) {
|
|
|
2855
2739
|
*/
|
|
2856
2740
|
function animateTarget(visualElement, definition, { delay = 0, transitionOverride, type } = {}) {
|
|
2857
2741
|
var _a;
|
|
2858
|
-
let
|
|
2742
|
+
let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = visualElement.makeTargetAnimatable(definition);
|
|
2859
2743
|
const willChange = visualElement.getValue("willChange");
|
|
2860
2744
|
if (transitionOverride)
|
|
2861
2745
|
transition = transitionOverride;
|
|
@@ -2870,12 +2754,16 @@ function animateTarget(visualElement, definition, { delay = 0, transitionOverrid
|
|
|
2870
2754
|
shouldBlockAnimation(animationTypeState, key))) {
|
|
2871
2755
|
continue;
|
|
2872
2756
|
}
|
|
2873
|
-
let valueTransition =
|
|
2757
|
+
let valueTransition = { delay, ...transition };
|
|
2874
2758
|
/**
|
|
2875
2759
|
* Make animation instant if this is a transform prop and we should reduce motion.
|
|
2876
2760
|
*/
|
|
2877
|
-
if (visualElement.shouldReduceMotion &&
|
|
2878
|
-
valueTransition =
|
|
2761
|
+
if (visualElement.shouldReduceMotion && transformProps.has(key)) {
|
|
2762
|
+
valueTransition = {
|
|
2763
|
+
...valueTransition,
|
|
2764
|
+
type: false,
|
|
2765
|
+
delay: 0,
|
|
2766
|
+
};
|
|
2879
2767
|
}
|
|
2880
2768
|
let animation = startAnimation(key, value, valueTarget, valueTransition);
|
|
2881
2769
|
if (isWillChangeMotionValue(willChange)) {
|
|
@@ -2897,7 +2785,10 @@ function animateChildren(visualElement, variant, delayChildren = 0, staggerChild
|
|
|
2897
2785
|
Array.from(visualElement.variantChildren)
|
|
2898
2786
|
.sort(sortByTreeOrder)
|
|
2899
2787
|
.forEach((child, i) => {
|
|
2900
|
-
animations.push(animateVariant(child, variant,
|
|
2788
|
+
animations.push(animateVariant(child, variant, {
|
|
2789
|
+
...options,
|
|
2790
|
+
delay: delayChildren + generateStaggerDuration(i),
|
|
2791
|
+
}).then(() => child.notifyAnimationComplete(variant)));
|
|
2901
2792
|
});
|
|
2902
2793
|
return Promise.all(animations);
|
|
2903
2794
|
}
|
|
@@ -2944,8 +2835,8 @@ function createAnimationState(visualElement) {
|
|
|
2944
2835
|
const buildResolvedTypeValues = (acc, definition) => {
|
|
2945
2836
|
const resolved = resolveVariant(visualElement, definition);
|
|
2946
2837
|
if (resolved) {
|
|
2947
|
-
const { transition, transitionEnd
|
|
2948
|
-
acc =
|
|
2838
|
+
const { transition, transitionEnd, ...target } = resolved;
|
|
2839
|
+
acc = { ...acc, ...target, ...transitionEnd };
|
|
2949
2840
|
}
|
|
2950
2841
|
return acc;
|
|
2951
2842
|
};
|
|
@@ -3028,7 +2919,7 @@ function createAnimationState(visualElement) {
|
|
|
3028
2919
|
* Set all encountered keys so far as the protected keys for this type. This will
|
|
3029
2920
|
* be any key that has been animated or otherwise handled by active, higher-priortiy types.
|
|
3030
2921
|
*/
|
|
3031
|
-
typeState.protectedKeys =
|
|
2922
|
+
typeState.protectedKeys = { ...encounteredKeys };
|
|
3032
2923
|
// Check if we can skip analysing this prop early
|
|
3033
2924
|
if (
|
|
3034
2925
|
// If it isn't active and hasn't *just* been set as inactive
|
|
@@ -3076,7 +2967,10 @@ function createAnimationState(visualElement) {
|
|
|
3076
2967
|
* needs adding to the type's protectedKeys list.
|
|
3077
2968
|
*/
|
|
3078
2969
|
const { prevResolvedValues = {} } = typeState;
|
|
3079
|
-
const allKeys =
|
|
2970
|
+
const allKeys = {
|
|
2971
|
+
...prevResolvedValues,
|
|
2972
|
+
...resolvedValues,
|
|
2973
|
+
};
|
|
3080
2974
|
const markToAnimate = (key) => {
|
|
3081
2975
|
shouldAnimateType = true;
|
|
3082
2976
|
removedKeys.delete(key);
|
|
@@ -3142,7 +3036,7 @@ function createAnimationState(visualElement) {
|
|
|
3142
3036
|
*
|
|
3143
3037
|
*/
|
|
3144
3038
|
if (typeState.isActive) {
|
|
3145
|
-
encounteredKeys =
|
|
3039
|
+
encounteredKeys = { ...encounteredKeys, ...resolvedValues };
|
|
3146
3040
|
}
|
|
3147
3041
|
if (isInitialRender && visualElement.blockInitialAnimation) {
|
|
3148
3042
|
shouldAnimateType = false;
|
|
@@ -3155,7 +3049,7 @@ function createAnimationState(visualElement) {
|
|
|
3155
3049
|
if (shouldAnimateType && !isInherited) {
|
|
3156
3050
|
animations.push(...definitionList.map((animation) => ({
|
|
3157
3051
|
animation: animation,
|
|
3158
|
-
options:
|
|
3052
|
+
options: { type, ...options },
|
|
3159
3053
|
})));
|
|
3160
3054
|
}
|
|
3161
3055
|
}
|
|
@@ -3211,7 +3105,7 @@ function checkVariantsDidChange(prev, next) {
|
|
|
3211
3105
|
if (typeof next === "string") {
|
|
3212
3106
|
return next !== prev;
|
|
3213
3107
|
}
|
|
3214
|
-
else if (
|
|
3108
|
+
else if (Array.isArray(next)) {
|
|
3215
3109
|
return !shallowCompare(next, prev);
|
|
3216
3110
|
}
|
|
3217
3111
|
return false;
|
|
@@ -3256,10 +3150,15 @@ const animations = {
|
|
|
3256
3150
|
const [isPresent, safeToRemove] = usePresence();
|
|
3257
3151
|
const presenceContext = React.useContext(PresenceContext);
|
|
3258
3152
|
React.useEffect(() => {
|
|
3259
|
-
var _a, _b;
|
|
3260
3153
|
visualElement.isPresent = isPresent;
|
|
3261
|
-
const animation =
|
|
3262
|
-
|
|
3154
|
+
const animation = visualElement.animationState &&
|
|
3155
|
+
visualElement.animationState.setActive(exports.AnimationType.Exit, !isPresent, {
|
|
3156
|
+
custom: (presenceContext && presenceContext.custom) ||
|
|
3157
|
+
custom,
|
|
3158
|
+
});
|
|
3159
|
+
if (animation && !isPresent) {
|
|
3160
|
+
animation.then(safeToRemove);
|
|
3161
|
+
}
|
|
3263
3162
|
}, [isPresent]);
|
|
3264
3163
|
}),
|
|
3265
3164
|
};
|
|
@@ -3298,7 +3197,7 @@ class PanSession {
|
|
|
3298
3197
|
return;
|
|
3299
3198
|
const { point } = info;
|
|
3300
3199
|
const { timestamp } = sync.getFrameData();
|
|
3301
|
-
this.history.push(
|
|
3200
|
+
this.history.push({ ...point, timestamp });
|
|
3302
3201
|
const { onStart, onMove } = this.handlers;
|
|
3303
3202
|
if (!isPanStarted) {
|
|
3304
3203
|
onStart && onStart(this.lastMoveEvent, info);
|
|
@@ -3335,7 +3234,7 @@ class PanSession {
|
|
|
3335
3234
|
const initialInfo = transformPoint(info, this.transformPagePoint);
|
|
3336
3235
|
const { point } = initialInfo;
|
|
3337
3236
|
const { timestamp } = sync.getFrameData();
|
|
3338
|
-
this.history = [
|
|
3237
|
+
this.history = [{ ...point, timestamp }];
|
|
3339
3238
|
const { onSessionStart } = handlers;
|
|
3340
3239
|
onSessionStart &&
|
|
3341
3240
|
onSessionStart(event, getPanInfo(initialInfo, this.history));
|
|
@@ -3980,8 +3879,17 @@ class VisualElementDragControls {
|
|
|
3980
3879
|
*/
|
|
3981
3880
|
const bounceStiffness = dragElastic ? 200 : 1000000;
|
|
3982
3881
|
const bounceDamping = dragElastic ? 40 : 10000000;
|
|
3983
|
-
const inertia =
|
|
3984
|
-
|
|
3882
|
+
const inertia = {
|
|
3883
|
+
type: "inertia",
|
|
3884
|
+
velocity: dragMomentum ? velocity[axis] : 0,
|
|
3885
|
+
bounceStiffness,
|
|
3886
|
+
bounceDamping,
|
|
3887
|
+
timeConstant: 750,
|
|
3888
|
+
restDelta: 1,
|
|
3889
|
+
restSpeed: 10,
|
|
3890
|
+
...dragTransition,
|
|
3891
|
+
...transition,
|
|
3892
|
+
};
|
|
3985
3893
|
// If we're not animating on an externally-provided `MotionValue` we can use the
|
|
3986
3894
|
// component's animation controls which will handle interactions with whileHover (etc),
|
|
3987
3895
|
// otherwise we just have to animate the `MotionValue` itself.
|
|
@@ -4133,12 +4041,15 @@ class VisualElementDragControls {
|
|
|
4133
4041
|
getProps() {
|
|
4134
4042
|
const props = this.visualElement.getProps();
|
|
4135
4043
|
const { drag = false, dragDirectionLock = false, dragPropagation = false, dragConstraints = false, dragElastic = defaultElastic, dragMomentum = true, } = props;
|
|
4136
|
-
return
|
|
4044
|
+
return {
|
|
4045
|
+
...props,
|
|
4046
|
+
drag,
|
|
4137
4047
|
dragDirectionLock,
|
|
4138
4048
|
dragPropagation,
|
|
4139
4049
|
dragConstraints,
|
|
4140
4050
|
dragElastic,
|
|
4141
|
-
dragMomentum
|
|
4051
|
+
dragMomentum,
|
|
4052
|
+
};
|
|
4142
4053
|
}
|
|
4143
4054
|
}
|
|
4144
4055
|
function shouldDrag(direction, drag, currentDirection) {
|
|
@@ -4222,6 +4133,25 @@ const drag = {
|
|
|
4222
4133
|
drag: makeRenderlessComponent(useDrag),
|
|
4223
4134
|
};
|
|
4224
4135
|
|
|
4136
|
+
// Does this device prefer reduced motion? Returns `null` server-side.
|
|
4137
|
+
const prefersReducedMotion = { current: null };
|
|
4138
|
+
const hasReducedMotionListener = { current: false };
|
|
4139
|
+
|
|
4140
|
+
function initPrefersReducedMotion() {
|
|
4141
|
+
hasReducedMotionListener.current = true;
|
|
4142
|
+
if (!isBrowser)
|
|
4143
|
+
return;
|
|
4144
|
+
if (window.matchMedia) {
|
|
4145
|
+
const motionMediaQuery = window.matchMedia("(prefers-reduced-motion)");
|
|
4146
|
+
const setReducedMotionPreferences = () => (prefersReducedMotion.current = motionMediaQuery.matches);
|
|
4147
|
+
motionMediaQuery.addListener(setReducedMotionPreferences);
|
|
4148
|
+
setReducedMotionPreferences();
|
|
4149
|
+
}
|
|
4150
|
+
else {
|
|
4151
|
+
prefersReducedMotion.current = false;
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4154
|
+
|
|
4225
4155
|
const names = [
|
|
4226
4156
|
"LayoutMeasure",
|
|
4227
4157
|
"BeforeLayoutMeasure",
|
|
@@ -4263,7 +4193,6 @@ function createLifecycles() {
|
|
|
4263
4193
|
}
|
|
4264
4194
|
|
|
4265
4195
|
function updateMotionValuesFromProps(element, next, prev) {
|
|
4266
|
-
var _a;
|
|
4267
4196
|
const { willChange } = next;
|
|
4268
4197
|
for (const key in next) {
|
|
4269
4198
|
const nextValue = next[key];
|
|
@@ -4282,7 +4211,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
4282
4211
|
* and warn against mismatches.
|
|
4283
4212
|
*/
|
|
4284
4213
|
if (process.env.NODE_ENV === "development") {
|
|
4285
|
-
warnOnce(nextValue.version === "7.2.
|
|
4214
|
+
warnOnce(nextValue.version === "7.2.1", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.2.1 may not work as expected.`);
|
|
4286
4215
|
}
|
|
4287
4216
|
}
|
|
4288
4217
|
else if (isMotionValue(prevValue)) {
|
|
@@ -4307,7 +4236,8 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
4307
4236
|
!existingValue.hasAnimated && existingValue.set(nextValue);
|
|
4308
4237
|
}
|
|
4309
4238
|
else {
|
|
4310
|
-
|
|
4239
|
+
const latestValue = element.getStaticValue(key);
|
|
4240
|
+
element.addValue(key, motionValue(latestValue !== undefined ? latestValue : nextValue));
|
|
4311
4241
|
}
|
|
4312
4242
|
}
|
|
4313
4243
|
}
|
|
@@ -4319,7 +4249,9 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
4319
4249
|
return next;
|
|
4320
4250
|
}
|
|
4321
4251
|
|
|
4322
|
-
const
|
|
4252
|
+
const featureNames = Object.keys(featureDefinitions);
|
|
4253
|
+
const numFeatures = featureNames.length;
|
|
4254
|
+
const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatable, measureViewportBox, render: renderInstance, readValueFromInstance, removeValueFromRenderState, sortNodePosition, scrapeMotionValuesFromProps, }) => ({ parent, props, presenceId, blockInitialAnimation, visualState, reducedMotionConfig, }, options = {}) => {
|
|
4323
4255
|
let isMounted = false;
|
|
4324
4256
|
const { latestValues, renderState } = visualState;
|
|
4325
4257
|
/**
|
|
@@ -4355,7 +4287,9 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4355
4287
|
* When values are removed from all animation props we need to search
|
|
4356
4288
|
* for a fallback value to animate to. These values are tracked in baseTarget.
|
|
4357
4289
|
*/
|
|
4358
|
-
const baseTarget =
|
|
4290
|
+
const baseTarget = {
|
|
4291
|
+
...latestValues,
|
|
4292
|
+
};
|
|
4359
4293
|
// Internal methods ========================
|
|
4360
4294
|
/**
|
|
4361
4295
|
* On mount, this will be hydrated with a callback to disconnect
|
|
@@ -4402,7 +4336,7 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4402
4336
|
* Doing so will break some tests but this isn't neccessarily a breaking change,
|
|
4403
4337
|
* more a reflection of the test.
|
|
4404
4338
|
*/
|
|
4405
|
-
const
|
|
4339
|
+
const { willChange, ...initialMotionValues } = scrapeMotionValuesFromProps(props);
|
|
4406
4340
|
for (const key in initialMotionValues) {
|
|
4407
4341
|
const value = initialMotionValues[key];
|
|
4408
4342
|
if (latestValues[key] !== undefined && isMotionValue(value)) {
|
|
@@ -4415,36 +4349,39 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4415
4349
|
/**
|
|
4416
4350
|
* Determine what role this visual element should take in the variant tree.
|
|
4417
4351
|
*/
|
|
4418
|
-
const isControllingVariants =
|
|
4419
|
-
const isVariantNode =
|
|
4420
|
-
const element =
|
|
4352
|
+
const isControllingVariants$1 = isControllingVariants(props);
|
|
4353
|
+
const isVariantNode$1 = isVariantNode(props);
|
|
4354
|
+
const element = {
|
|
4355
|
+
treeType,
|
|
4421
4356
|
/**
|
|
4422
4357
|
* This is a mirror of the internal instance prop, which keeps
|
|
4423
4358
|
* VisualElement type-compatible with React's RefObject.
|
|
4424
4359
|
*/
|
|
4425
|
-
current: null,
|
|
4360
|
+
current: null,
|
|
4426
4361
|
/**
|
|
4427
4362
|
* The depth of this visual element within the visual element tree.
|
|
4428
4363
|
*/
|
|
4429
|
-
depth: parent ? parent.depth + 1 : 0,
|
|
4364
|
+
depth: parent ? parent.depth + 1 : 0,
|
|
4365
|
+
parent,
|
|
4366
|
+
children: new Set(),
|
|
4430
4367
|
/**
|
|
4431
4368
|
*
|
|
4432
4369
|
*/
|
|
4433
4370
|
presenceId,
|
|
4434
|
-
shouldReduceMotion,
|
|
4371
|
+
shouldReduceMotion: null,
|
|
4435
4372
|
/**
|
|
4436
4373
|
* If this component is part of the variant tree, it should track
|
|
4437
4374
|
* any children that are also part of the tree. This is essentially
|
|
4438
4375
|
* a shadow tree to simplify logic around how to stagger over children.
|
|
4439
4376
|
*/
|
|
4440
|
-
variantChildren: isVariantNode ? new Set() : undefined,
|
|
4377
|
+
variantChildren: isVariantNode$1 ? new Set() : undefined,
|
|
4441
4378
|
/**
|
|
4442
4379
|
* Whether this instance is visible. This can be changed imperatively
|
|
4443
4380
|
* by the projection tree, is analogous to CSS's visibility in that
|
|
4444
4381
|
* hidden elements should take up layout, and needs enacting by the configured
|
|
4445
4382
|
* render function.
|
|
4446
4383
|
*/
|
|
4447
|
-
isVisible: undefined,
|
|
4384
|
+
isVisible: undefined,
|
|
4448
4385
|
/**
|
|
4449
4386
|
* Normally, if a component is controlled by a parent's variants, it can
|
|
4450
4387
|
* rely on that ancestor to trigger animations further down the tree.
|
|
@@ -4453,27 +4390,37 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4453
4390
|
*
|
|
4454
4391
|
* TODO: This might be better replaced with a method isParentMounted
|
|
4455
4392
|
*/
|
|
4456
|
-
manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
|
|
4393
|
+
manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
|
|
4457
4394
|
/**
|
|
4458
4395
|
* This can be set by AnimatePresence to force components that mount
|
|
4459
4396
|
* at the same time as it to mount as if they have initial={false} set.
|
|
4460
4397
|
*/
|
|
4461
|
-
blockInitialAnimation,
|
|
4398
|
+
blockInitialAnimation,
|
|
4462
4399
|
/**
|
|
4463
4400
|
* Determine whether this component has mounted yet. This is mostly used
|
|
4464
4401
|
* by variant children to determine whether they need to trigger their
|
|
4465
4402
|
* own animations on mount.
|
|
4466
4403
|
*/
|
|
4467
|
-
isMounted: () => Boolean(instance),
|
|
4404
|
+
isMounted: () => Boolean(instance),
|
|
4405
|
+
mount(newInstance) {
|
|
4468
4406
|
isMounted = true;
|
|
4469
4407
|
instance = element.current = newInstance;
|
|
4470
4408
|
if (element.projection) {
|
|
4471
4409
|
element.projection.mount(newInstance);
|
|
4472
4410
|
}
|
|
4473
|
-
if (isVariantNode && parent && !isControllingVariants) {
|
|
4411
|
+
if (isVariantNode$1 && parent && !isControllingVariants$1) {
|
|
4474
4412
|
removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
|
|
4475
4413
|
}
|
|
4476
4414
|
values.forEach((value, key) => bindToMotionValue(key, value));
|
|
4415
|
+
if (!hasReducedMotionListener.current) {
|
|
4416
|
+
initPrefersReducedMotion();
|
|
4417
|
+
}
|
|
4418
|
+
element.shouldReduceMotion =
|
|
4419
|
+
reducedMotionConfig === "never"
|
|
4420
|
+
? false
|
|
4421
|
+
: reducedMotionConfig === "always"
|
|
4422
|
+
? true
|
|
4423
|
+
: prefersReducedMotion.current;
|
|
4477
4424
|
parent === null || parent === void 0 ? void 0 : parent.children.add(element);
|
|
4478
4425
|
element.setProps(props);
|
|
4479
4426
|
},
|
|
@@ -4492,6 +4439,55 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4492
4439
|
instance = undefined;
|
|
4493
4440
|
isMounted = false;
|
|
4494
4441
|
},
|
|
4442
|
+
loadFeatures(renderedProps, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
|
|
4443
|
+
const features = [];
|
|
4444
|
+
/**
|
|
4445
|
+
* If we're in development mode, check to make sure we're not rendering a motion component
|
|
4446
|
+
* as a child of LazyMotion, as this will break the file-size benefits of using it.
|
|
4447
|
+
*/
|
|
4448
|
+
if (env !== "production" && preloadedFeatures && isStrict) {
|
|
4449
|
+
heyListen.invariant(false, "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.");
|
|
4450
|
+
}
|
|
4451
|
+
for (let i = 0; i < numFeatures; i++) {
|
|
4452
|
+
const name = featureNames[i];
|
|
4453
|
+
const { isEnabled, Component } = featureDefinitions[name];
|
|
4454
|
+
/**
|
|
4455
|
+
* It might be possible in the future to use this moment to
|
|
4456
|
+
* dynamically request functionality. In initial tests this
|
|
4457
|
+
* was producing a lot of duplication amongst bundles.
|
|
4458
|
+
*/
|
|
4459
|
+
if (isEnabled(props) && Component) {
|
|
4460
|
+
features.push(React.createElement(Component, {
|
|
4461
|
+
key: name,
|
|
4462
|
+
...renderedProps,
|
|
4463
|
+
visualElement: element,
|
|
4464
|
+
}));
|
|
4465
|
+
}
|
|
4466
|
+
}
|
|
4467
|
+
if (!element.projection && ProjectionNodeConstructor) {
|
|
4468
|
+
element.projection = new ProjectionNodeConstructor(projectionId, element.getLatestValues(), parent && parent.projection);
|
|
4469
|
+
const { layoutId, layout, drag, dragConstraints, layoutScroll, } = renderedProps;
|
|
4470
|
+
element.projection.setOptions({
|
|
4471
|
+
layoutId,
|
|
4472
|
+
layout,
|
|
4473
|
+
alwaysMeasureLayout: Boolean(drag) ||
|
|
4474
|
+
(dragConstraints && isRefObject(dragConstraints)),
|
|
4475
|
+
visualElement: element,
|
|
4476
|
+
scheduleRender: () => element.scheduleRender(),
|
|
4477
|
+
/**
|
|
4478
|
+
* TODO: Update options in an effect. This could be tricky as it'll be too late
|
|
4479
|
+
* to update by the time layout animations run.
|
|
4480
|
+
* We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
|
|
4481
|
+
* ensuring it gets called if there's no potential layout animations.
|
|
4482
|
+
*
|
|
4483
|
+
*/
|
|
4484
|
+
animationType: typeof layout === "string" ? layout : "both",
|
|
4485
|
+
initialPromotionConfig: initialLayoutGroupConfig,
|
|
4486
|
+
layoutScroll,
|
|
4487
|
+
});
|
|
4488
|
+
}
|
|
4489
|
+
return features;
|
|
4490
|
+
},
|
|
4495
4491
|
/**
|
|
4496
4492
|
* Add a child visual element to our set of children.
|
|
4497
4493
|
*/
|
|
@@ -4510,30 +4506,31 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4510
4506
|
if (!sortNodePosition || treeType !== other.treeType)
|
|
4511
4507
|
return 0;
|
|
4512
4508
|
return sortNodePosition(element.getInstance(), other.getInstance());
|
|
4513
|
-
},
|
|
4509
|
+
},
|
|
4514
4510
|
/**
|
|
4515
4511
|
* Returns the closest variant node in the tree starting from
|
|
4516
4512
|
* this visual element.
|
|
4517
4513
|
*/
|
|
4518
|
-
getClosestVariantNode: () => isVariantNode ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
|
|
4514
|
+
getClosestVariantNode: () => isVariantNode$1 ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
|
|
4519
4515
|
/**
|
|
4520
4516
|
* Expose the latest layoutId prop.
|
|
4521
4517
|
*/
|
|
4522
|
-
getLayoutId: () => props.layoutId,
|
|
4518
|
+
getLayoutId: () => props.layoutId,
|
|
4523
4519
|
/**
|
|
4524
4520
|
* Returns the current instance.
|
|
4525
4521
|
*/
|
|
4526
|
-
getInstance: () => instance,
|
|
4522
|
+
getInstance: () => instance,
|
|
4527
4523
|
/**
|
|
4528
4524
|
* Get/set the latest static values.
|
|
4529
4525
|
*/
|
|
4530
|
-
getStaticValue: (key) => latestValues[key],
|
|
4526
|
+
getStaticValue: (key) => latestValues[key],
|
|
4527
|
+
setStaticValue: (key, value) => (latestValues[key] = value),
|
|
4531
4528
|
/**
|
|
4532
4529
|
* Returns the latest motion value state. Currently only used to take
|
|
4533
4530
|
* a snapshot of the visual element - perhaps this can return the whole
|
|
4534
4531
|
* visual state
|
|
4535
4532
|
*/
|
|
4536
|
-
getLatestValues: () => latestValues,
|
|
4533
|
+
getLatestValues: () => latestValues,
|
|
4537
4534
|
/**
|
|
4538
4535
|
* Set the visiblity of the visual element. If it's changed, schedule
|
|
4539
4536
|
* a render to reflect these changes.
|
|
@@ -4584,11 +4581,11 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4584
4581
|
valueSubscriptions.delete(key);
|
|
4585
4582
|
delete latestValues[key];
|
|
4586
4583
|
removeValueFromRenderState(key, renderState);
|
|
4587
|
-
},
|
|
4584
|
+
},
|
|
4588
4585
|
/**
|
|
4589
4586
|
* Check whether we have a motion value for this key
|
|
4590
4587
|
*/
|
|
4591
|
-
hasValue: (key) => values.has(key),
|
|
4588
|
+
hasValue: (key) => values.has(key),
|
|
4592
4589
|
/**
|
|
4593
4590
|
* Get a motion value for this key. If called with a default
|
|
4594
4591
|
* value, we'll create one if none exists.
|
|
@@ -4600,20 +4597,19 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4600
4597
|
element.addValue(key, value);
|
|
4601
4598
|
}
|
|
4602
4599
|
return value;
|
|
4603
|
-
},
|
|
4600
|
+
},
|
|
4604
4601
|
/**
|
|
4605
4602
|
* Iterate over our motion values.
|
|
4606
4603
|
*/
|
|
4607
|
-
forEachValue: (callback) => values.forEach(callback),
|
|
4604
|
+
forEachValue: (callback) => values.forEach(callback),
|
|
4608
4605
|
/**
|
|
4609
4606
|
* If we're trying to animate to a previously unencountered value,
|
|
4610
4607
|
* we need to check for it in our state and as a last resort read it
|
|
4611
4608
|
* directly from the instance (which might have performance implications).
|
|
4612
4609
|
*/
|
|
4613
|
-
readValue: (key) =>
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
},
|
|
4610
|
+
readValue: (key) => latestValues[key] !== undefined
|
|
4611
|
+
? latestValues[key]
|
|
4612
|
+
: readValueFromInstance(instance, key, options),
|
|
4617
4613
|
/**
|
|
4618
4614
|
* Set the base target to later animate back to. This is currently
|
|
4619
4615
|
* only hydrated on creation and when we first read a value.
|
|
@@ -4632,7 +4628,9 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4632
4628
|
return target;
|
|
4633
4629
|
}
|
|
4634
4630
|
return baseTarget[key];
|
|
4635
|
-
}
|
|
4631
|
+
},
|
|
4632
|
+
// Lifecyles ========================
|
|
4633
|
+
...lifecycles,
|
|
4636
4634
|
/**
|
|
4637
4635
|
* Build the renderer state based on the latest visual state.
|
|
4638
4636
|
*/
|
|
@@ -4645,14 +4643,14 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4645
4643
|
*/
|
|
4646
4644
|
scheduleRender() {
|
|
4647
4645
|
sync__default["default"].render(render, false, true);
|
|
4648
|
-
},
|
|
4646
|
+
},
|
|
4649
4647
|
/**
|
|
4650
4648
|
* Synchronously fire render. It's prefered that we batch renders but
|
|
4651
4649
|
* in many circumstances, like layout measurement, we need to run this
|
|
4652
4650
|
* synchronously. However in those instances other measures should be taken
|
|
4653
4651
|
* to batch reads/writes.
|
|
4654
4652
|
*/
|
|
4655
|
-
syncRender: render,
|
|
4653
|
+
syncRender: render,
|
|
4656
4654
|
/**
|
|
4657
4655
|
* Update the provided props. Ensure any newly-added motion values are
|
|
4658
4656
|
* added to our map, old ones removed, and listeners updated.
|
|
@@ -4664,25 +4662,27 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4664
4662
|
props = newProps;
|
|
4665
4663
|
lifecycles.updatePropListeners(newProps);
|
|
4666
4664
|
prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
|
|
4667
|
-
},
|
|
4665
|
+
},
|
|
4666
|
+
getProps: () => props,
|
|
4668
4667
|
// Variants ==============================
|
|
4669
4668
|
/**
|
|
4670
4669
|
* Returns the variant definition with a given name.
|
|
4671
4670
|
*/
|
|
4672
|
-
getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
4671
|
+
getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
4673
4672
|
/**
|
|
4674
4673
|
* Returns the defined default transition on this component.
|
|
4675
4674
|
*/
|
|
4676
|
-
getDefaultTransition: () => props.transition,
|
|
4675
|
+
getDefaultTransition: () => props.transition,
|
|
4676
|
+
getTransformPagePoint: () => {
|
|
4677
4677
|
return props.transformPagePoint;
|
|
4678
|
-
},
|
|
4678
|
+
},
|
|
4679
4679
|
/**
|
|
4680
4680
|
* Used by child variant nodes to get the closest ancestor variant props.
|
|
4681
4681
|
*/
|
|
4682
4682
|
getVariantContext(startAtParent = false) {
|
|
4683
4683
|
if (startAtParent)
|
|
4684
4684
|
return parent === null || parent === void 0 ? void 0 : parent.getVariantContext();
|
|
4685
|
-
if (!isControllingVariants) {
|
|
4685
|
+
if (!isControllingVariants$1) {
|
|
4686
4686
|
const context = (parent === null || parent === void 0 ? void 0 : parent.getVariantContext()) || {};
|
|
4687
4687
|
if (props.initial !== undefined) {
|
|
4688
4688
|
context.initial = props.initial;
|
|
@@ -4698,7 +4698,8 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4698
4698
|
}
|
|
4699
4699
|
}
|
|
4700
4700
|
return context;
|
|
4701
|
-
}
|
|
4701
|
+
},
|
|
4702
|
+
};
|
|
4702
4703
|
return element;
|
|
4703
4704
|
};
|
|
4704
4705
|
const variantProps = ["initial", ...variantPriorityOrder];
|
|
@@ -4749,16 +4750,14 @@ function getVariableValue(current, element, depth = 1) {
|
|
|
4749
4750
|
*
|
|
4750
4751
|
* @internal
|
|
4751
4752
|
*/
|
|
4752
|
-
function resolveCSSVariables(visualElement,
|
|
4753
|
-
var _b;
|
|
4754
|
-
var target = tslib.__rest(_a, []);
|
|
4753
|
+
function resolveCSSVariables(visualElement, { ...target }, transitionEnd) {
|
|
4755
4754
|
const element = visualElement.getInstance();
|
|
4756
4755
|
if (!(element instanceof Element))
|
|
4757
4756
|
return { target, transitionEnd };
|
|
4758
4757
|
// If `transitionEnd` isn't `undefined`, clone it. We could clone `target` and `transitionEnd`
|
|
4759
4758
|
// only if they change but I think this reads clearer and this isn't a performance-critical path.
|
|
4760
4759
|
if (transitionEnd) {
|
|
4761
|
-
transitionEnd =
|
|
4760
|
+
transitionEnd = { ...transitionEnd };
|
|
4762
4761
|
}
|
|
4763
4762
|
// Go through existing `MotionValue`s and ensure any existing CSS variables are resolved
|
|
4764
4763
|
visualElement.forEachValue((value) => {
|
|
@@ -4783,8 +4782,9 @@ function resolveCSSVariables(visualElement, _a, transitionEnd) {
|
|
|
4783
4782
|
// If the user hasn't already set this key on `transitionEnd`, set it to the unresolved
|
|
4784
4783
|
// CSS variable. This will ensure that after the animation the component will reflect
|
|
4785
4784
|
// changes in the value of the CSS variable.
|
|
4786
|
-
if (transitionEnd)
|
|
4787
|
-
|
|
4785
|
+
if (transitionEnd && transitionEnd[key] === undefined) {
|
|
4786
|
+
transitionEnd[key] = current;
|
|
4787
|
+
}
|
|
4788
4788
|
}
|
|
4789
4789
|
return { target, transitionEnd };
|
|
4790
4790
|
}
|
|
@@ -4838,7 +4838,7 @@ const getTranslateFromMatrix = (pos2, pos3) => (_bbox, { transform }) => {
|
|
|
4838
4838
|
}
|
|
4839
4839
|
};
|
|
4840
4840
|
const transformKeys = new Set(["x", "y", "z"]);
|
|
4841
|
-
const nonTranslationalTransformKeys =
|
|
4841
|
+
const nonTranslationalTransformKeys = transformPropOrder.filter((key) => !transformKeys.has(key));
|
|
4842
4842
|
function removeNonTranslationalTransform(visualElement) {
|
|
4843
4843
|
const removedTransforms = [];
|
|
4844
4844
|
nonTranslationalTransformKeys.forEach((key) => {
|
|
@@ -4895,8 +4895,8 @@ const convertChangedValueTypes = (target, visualElement, changedKeys) => {
|
|
|
4895
4895
|
return target;
|
|
4896
4896
|
};
|
|
4897
4897
|
const checkAndConvertChangedValueTypes = (visualElement, target, origin = {}, transitionEnd = {}) => {
|
|
4898
|
-
target =
|
|
4899
|
-
transitionEnd =
|
|
4898
|
+
target = { ...target };
|
|
4899
|
+
transitionEnd = { ...transitionEnd };
|
|
4900
4900
|
const targetPositionalKeys = Object.keys(target).filter(isPositionalKey);
|
|
4901
4901
|
// We want to remove any transform values that could affect the element's bounding box before
|
|
4902
4902
|
// it's measured. We'll reapply these later.
|
|
@@ -5031,7 +5031,7 @@ function getComputedStyle$1(element) {
|
|
|
5031
5031
|
const htmlConfig = {
|
|
5032
5032
|
treeType: "dom",
|
|
5033
5033
|
readValueFromInstance(domElement, key) {
|
|
5034
|
-
if (
|
|
5034
|
+
if (transformProps.has(key)) {
|
|
5035
5035
|
const defaultType = getDefaultValueType(key);
|
|
5036
5036
|
return defaultType ? defaultType.default || 0 : 0;
|
|
5037
5037
|
}
|
|
@@ -5084,10 +5084,7 @@ const htmlConfig = {
|
|
|
5084
5084
|
* Ensure that HTML and Framer-specific value types like `px`->`%` and `Color`
|
|
5085
5085
|
* can be animated by Motion.
|
|
5086
5086
|
*/
|
|
5087
|
-
makeTargetAnimatable(element,
|
|
5088
|
-
var { transition, transitionEnd } = _a, target = tslib.__rest(_a, ["transition", "transitionEnd"]);
|
|
5089
|
-
var transformValues = _b.transformValues;
|
|
5090
|
-
if (isMounted === void 0) { isMounted = true; }
|
|
5087
|
+
makeTargetAnimatable(element, { transition, transitionEnd, ...target }, { transformValues }, isMounted = true) {
|
|
5091
5088
|
let origin = getOrigin(target, transition || {}, element);
|
|
5092
5089
|
/**
|
|
5093
5090
|
* If Framer has provided a function to convert `Color` etc value types, convert them
|
|
@@ -5106,8 +5103,11 @@ const htmlConfig = {
|
|
|
5106
5103
|
transitionEnd = parsed.transitionEnd;
|
|
5107
5104
|
target = parsed.target;
|
|
5108
5105
|
}
|
|
5109
|
-
return
|
|
5110
|
-
|
|
5106
|
+
return {
|
|
5107
|
+
transition,
|
|
5108
|
+
transitionEnd,
|
|
5109
|
+
...target,
|
|
5110
|
+
};
|
|
5111
5111
|
},
|
|
5112
5112
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps$1,
|
|
5113
5113
|
build(element, renderState, latestValues, options, props) {
|
|
@@ -5122,12 +5122,14 @@ const htmlConfig = {
|
|
|
5122
5122
|
};
|
|
5123
5123
|
const htmlVisualElement = visualElement(htmlConfig);
|
|
5124
5124
|
|
|
5125
|
-
const svgVisualElement = visualElement(
|
|
5125
|
+
const svgVisualElement = visualElement({
|
|
5126
|
+
...htmlConfig,
|
|
5127
|
+
getBaseTarget(props, key) {
|
|
5126
5128
|
return props[key];
|
|
5127
5129
|
},
|
|
5128
5130
|
readValueFromInstance(domElement, key) {
|
|
5129
5131
|
var _a;
|
|
5130
|
-
if (
|
|
5132
|
+
if (transformProps.has(key)) {
|
|
5131
5133
|
return ((_a = getDefaultValueType(key)) === null || _a === void 0 ? void 0 : _a.default) || 0;
|
|
5132
5134
|
}
|
|
5133
5135
|
key = !camelCaseAttributes.has(key) ? camelToDash(key) : key;
|
|
@@ -5136,7 +5138,9 @@ const svgVisualElement = visualElement(Object.assign(Object.assign({}, htmlConfi
|
|
|
5136
5138
|
scrapeMotionValuesFromProps,
|
|
5137
5139
|
build(_element, renderState, latestValues, options, props) {
|
|
5138
5140
|
buildSVGAttrs(renderState, latestValues, options, props.transformTemplate);
|
|
5139
|
-
},
|
|
5141
|
+
},
|
|
5142
|
+
render: renderSVG,
|
|
5143
|
+
});
|
|
5140
5144
|
|
|
5141
5145
|
const createDomVisualElement = (Component, options) => {
|
|
5142
5146
|
return isSVGComponent(Component)
|
|
@@ -5245,16 +5249,19 @@ class MeasureLayoutWithContext extends React__default["default"].Component {
|
|
|
5245
5249
|
const { projection } = visualElement;
|
|
5246
5250
|
addScaleCorrector(defaultScaleCorrectors);
|
|
5247
5251
|
if (projection) {
|
|
5248
|
-
if (layoutGroup
|
|
5252
|
+
if (layoutGroup.group)
|
|
5249
5253
|
layoutGroup.group.add(projection);
|
|
5250
|
-
if (
|
|
5254
|
+
if (switchLayoutGroup && switchLayoutGroup.register && layoutId) {
|
|
5251
5255
|
switchLayoutGroup.register(projection);
|
|
5252
5256
|
}
|
|
5253
5257
|
projection.root.didUpdate();
|
|
5254
5258
|
projection.addEventListener("animationComplete", () => {
|
|
5255
5259
|
this.safeToRemove();
|
|
5256
5260
|
});
|
|
5257
|
-
projection.setOptions(
|
|
5261
|
+
projection.setOptions({
|
|
5262
|
+
...projection.options,
|
|
5263
|
+
onExitComplete: () => this.safeToRemove(),
|
|
5264
|
+
});
|
|
5258
5265
|
}
|
|
5259
5266
|
globalProjectionState.hasEverUpdated = true;
|
|
5260
5267
|
}
|
|
@@ -5330,15 +5337,18 @@ class MeasureLayoutWithContext extends React__default["default"].Component {
|
|
|
5330
5337
|
function MeasureLayout(props) {
|
|
5331
5338
|
const [isPresent, safeToRemove] = usePresence();
|
|
5332
5339
|
const layoutGroup = React.useContext(LayoutGroupContext);
|
|
5333
|
-
return (React__default["default"].createElement(MeasureLayoutWithContext,
|
|
5340
|
+
return (React__default["default"].createElement(MeasureLayoutWithContext, { ...props, layoutGroup: layoutGroup, switchLayoutGroup: React.useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove }));
|
|
5334
5341
|
}
|
|
5335
5342
|
const defaultScaleCorrectors = {
|
|
5336
|
-
borderRadius:
|
|
5343
|
+
borderRadius: {
|
|
5344
|
+
...correctBorderRadius,
|
|
5345
|
+
applyTo: [
|
|
5337
5346
|
"borderTopLeftRadius",
|
|
5338
5347
|
"borderTopRightRadius",
|
|
5339
5348
|
"borderBottomLeftRadius",
|
|
5340
5349
|
"borderBottomRightRadius",
|
|
5341
|
-
]
|
|
5350
|
+
],
|
|
5351
|
+
},
|
|
5342
5352
|
borderTopLeftRadius: correctBorderRadius,
|
|
5343
5353
|
borderTopRightRadius: correctBorderRadius,
|
|
5344
5354
|
borderBottomLeftRadius: correctBorderRadius,
|
|
@@ -5719,6 +5729,7 @@ class FlatTree {
|
|
|
5719
5729
|
}
|
|
5720
5730
|
}
|
|
5721
5731
|
|
|
5732
|
+
const transformAxes = ["", "X", "Y", "Z"];
|
|
5722
5733
|
/**
|
|
5723
5734
|
* We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
|
|
5724
5735
|
* which has a noticeable difference in spring animations
|
|
@@ -5910,7 +5921,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
5910
5921
|
this.resumingFrom.resumingFrom = undefined;
|
|
5911
5922
|
}
|
|
5912
5923
|
this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
|
|
5913
|
-
const animationOptions =
|
|
5924
|
+
const animationOptions = {
|
|
5925
|
+
...getValueTransition(layoutTransition, "layout"),
|
|
5926
|
+
onPlay: onLayoutAnimationStart,
|
|
5927
|
+
onComplete: onLayoutAnimationComplete,
|
|
5928
|
+
};
|
|
5914
5929
|
if (visualElement.shouldReduceMotion) {
|
|
5915
5930
|
animationOptions.delay = 0;
|
|
5916
5931
|
animationOptions.type = false;
|
|
@@ -6233,8 +6248,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6233
6248
|
this.root.scheduleUpdateProjection();
|
|
6234
6249
|
}
|
|
6235
6250
|
setOptions(options) {
|
|
6236
|
-
|
|
6237
|
-
|
|
6251
|
+
this.options = {
|
|
6252
|
+
...this.options,
|
|
6253
|
+
...options,
|
|
6254
|
+
crossfade: options.crossfade !== undefined ? options.crossfade : true,
|
|
6255
|
+
};
|
|
6238
6256
|
}
|
|
6239
6257
|
clearMeasurements() {
|
|
6240
6258
|
this.scroll = undefined;
|
|
@@ -6416,7 +6434,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6416
6434
|
var _a;
|
|
6417
6435
|
const snapshot = this.snapshot;
|
|
6418
6436
|
const snapshotLatestValues = (snapshot === null || snapshot === void 0 ? void 0 : snapshot.latestValues) || {};
|
|
6419
|
-
const mixedValues =
|
|
6437
|
+
const mixedValues = { ...this.latestValues };
|
|
6420
6438
|
const targetDelta = createDelta();
|
|
6421
6439
|
this.relativeTarget = this.relativeTargetOrigin = undefined;
|
|
6422
6440
|
this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
|
|
@@ -6469,15 +6487,19 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6469
6487
|
*/
|
|
6470
6488
|
this.pendingAnimation = sync__default["default"].update(() => {
|
|
6471
6489
|
globalProjectionState.hasAnimatedSinceResize = true;
|
|
6472
|
-
this.currentAnimation = animate(0, animationTarget,
|
|
6490
|
+
this.currentAnimation = animate(0, animationTarget, {
|
|
6491
|
+
...options,
|
|
6492
|
+
onUpdate: (latest) => {
|
|
6473
6493
|
var _a;
|
|
6474
6494
|
this.mixTargetDelta(latest);
|
|
6475
6495
|
(_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, latest);
|
|
6476
|
-
},
|
|
6496
|
+
},
|
|
6497
|
+
onComplete: () => {
|
|
6477
6498
|
var _a;
|
|
6478
6499
|
(_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
6479
6500
|
this.completeAnimation();
|
|
6480
|
-
}
|
|
6501
|
+
},
|
|
6502
|
+
});
|
|
6481
6503
|
if (this.resumingFrom) {
|
|
6482
6504
|
this.resumingFrom.currentAnimation = this.currentAnimation;
|
|
6483
6505
|
}
|
|
@@ -6612,7 +6634,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6612
6634
|
visualElement.scheduleRender();
|
|
6613
6635
|
}
|
|
6614
6636
|
getProjectionStyles(styleProp = {}) {
|
|
6615
|
-
var _a, _b, _c
|
|
6637
|
+
var _a, _b, _c;
|
|
6616
6638
|
// TODO: Return lifecycle-persistent object
|
|
6617
6639
|
const styles = {};
|
|
6618
6640
|
if (!this.instance || this.isSVG)
|
|
@@ -6638,7 +6660,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6638
6660
|
if (!this.projectionDelta || !this.layout || !lead.target) {
|
|
6639
6661
|
const emptyStyles = {};
|
|
6640
6662
|
if (this.options.layoutId) {
|
|
6641
|
-
emptyStyles.opacity =
|
|
6663
|
+
emptyStyles.opacity =
|
|
6664
|
+
this.latestValues.opacity !== undefined
|
|
6665
|
+
? this.latestValues.opacity
|
|
6666
|
+
: 1;
|
|
6642
6667
|
emptyStyles.pointerEvents =
|
|
6643
6668
|
resolveMotionValue(styleProp.pointerEvents) || "";
|
|
6644
6669
|
}
|
|
@@ -6665,7 +6690,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6665
6690
|
*/
|
|
6666
6691
|
styles.opacity =
|
|
6667
6692
|
lead === this
|
|
6668
|
-
? (
|
|
6693
|
+
? (_c = (_b = valuesToRender.opacity) !== null && _b !== void 0 ? _b : this.latestValues.opacity) !== null && _c !== void 0 ? _c : 1
|
|
6669
6694
|
: this.preserveOpacity
|
|
6670
6695
|
? this.latestValues.opacity
|
|
6671
6696
|
: valuesToRender.opacityExit;
|
|
@@ -6677,8 +6702,12 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6677
6702
|
*/
|
|
6678
6703
|
styles.opacity =
|
|
6679
6704
|
lead === this
|
|
6680
|
-
?
|
|
6681
|
-
|
|
6705
|
+
? valuesToRender.opacity !== undefined
|
|
6706
|
+
? valuesToRender.opacity
|
|
6707
|
+
: ""
|
|
6708
|
+
: valuesToRender.opacityExit !== undefined
|
|
6709
|
+
? valuesToRender.opacityExit
|
|
6710
|
+
: 0;
|
|
6682
6711
|
}
|
|
6683
6712
|
/**
|
|
6684
6713
|
* Apply scale correction
|
|
@@ -6726,8 +6755,8 @@ function updateLayout(node) {
|
|
|
6726
6755
|
node.updateLayout();
|
|
6727
6756
|
}
|
|
6728
6757
|
function notifyLayoutUpdate(node) {
|
|
6729
|
-
var _a, _b, _c
|
|
6730
|
-
const snapshot = (
|
|
6758
|
+
var _a, _b, _c;
|
|
6759
|
+
const snapshot = ((_a = node.resumeFrom) === null || _a === void 0 ? void 0 : _a.snapshot) || node.snapshot;
|
|
6731
6760
|
if (node.isLead() &&
|
|
6732
6761
|
node.layout &&
|
|
6733
6762
|
snapshot &&
|
|
@@ -6794,7 +6823,7 @@ function notifyLayoutUpdate(node) {
|
|
|
6794
6823
|
});
|
|
6795
6824
|
}
|
|
6796
6825
|
else if (node.isLead()) {
|
|
6797
|
-
(
|
|
6826
|
+
(_c = (_b = node.options).onExitComplete) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
6798
6827
|
}
|
|
6799
6828
|
/**
|
|
6800
6829
|
* Clearing transition
|
|
@@ -6906,12 +6935,17 @@ const HTMLProjectionNode = createProjectionNode({
|
|
|
6906
6935
|
return rootProjectionNode.current;
|
|
6907
6936
|
},
|
|
6908
6937
|
resetTransform: (instance, value) => {
|
|
6909
|
-
instance.style.transform = value !==
|
|
6938
|
+
instance.style.transform = value !== undefined ? value : "none";
|
|
6910
6939
|
},
|
|
6911
6940
|
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
6912
6941
|
});
|
|
6913
6942
|
|
|
6914
|
-
const featureBundle =
|
|
6943
|
+
const featureBundle = {
|
|
6944
|
+
...animations,
|
|
6945
|
+
...gestureAnimations,
|
|
6946
|
+
...drag,
|
|
6947
|
+
...layoutFeatures,
|
|
6948
|
+
};
|
|
6915
6949
|
/**
|
|
6916
6950
|
* HTML & SVG components, optimised for use with gestures and animation. These can be used as
|
|
6917
6951
|
* drop-in replacements for any HTML & SVG component, all CSS & SVG properties are supported.
|
|
@@ -7011,14 +7045,14 @@ function PopChild({ children, isPresent }) {
|
|
|
7011
7045
|
* styles set via the style prop.
|
|
7012
7046
|
*/
|
|
7013
7047
|
React.useInsertionEffect(() => {
|
|
7014
|
-
var _a;
|
|
7015
7048
|
const { width, height, top, left } = size.current;
|
|
7016
7049
|
if (isPresent || !ref.current || !width || !height)
|
|
7017
7050
|
return;
|
|
7018
7051
|
ref.current.dataset.motionPopId = id;
|
|
7019
7052
|
const style = document.createElement("style");
|
|
7020
7053
|
document.head.appendChild(style);
|
|
7021
|
-
(
|
|
7054
|
+
if (style.sheet) {
|
|
7055
|
+
style.sheet.insertRule(`
|
|
7022
7056
|
[data-motion-pop-id="${id}"] {
|
|
7023
7057
|
position: absolute !important;
|
|
7024
7058
|
width: ${width}px !important;
|
|
@@ -7027,6 +7061,7 @@ function PopChild({ children, isPresent }) {
|
|
|
7027
7061
|
left: ${left}px !important;
|
|
7028
7062
|
}
|
|
7029
7063
|
`);
|
|
7064
|
+
}
|
|
7030
7065
|
return () => {
|
|
7031
7066
|
document.head.removeChild(style);
|
|
7032
7067
|
};
|
|
@@ -7048,7 +7083,7 @@ const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, p
|
|
|
7048
7083
|
if (!isComplete)
|
|
7049
7084
|
return; // can stop searching when any is incomplete
|
|
7050
7085
|
}
|
|
7051
|
-
onExitComplete
|
|
7086
|
+
onExitComplete && onExitComplete();
|
|
7052
7087
|
},
|
|
7053
7088
|
register: (childId) => {
|
|
7054
7089
|
presenceChildren.set(childId, false);
|
|
@@ -7069,7 +7104,10 @@ const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, p
|
|
|
7069
7104
|
* component immediately.
|
|
7070
7105
|
*/
|
|
7071
7106
|
React__namespace.useEffect(() => {
|
|
7072
|
-
!isPresent &&
|
|
7107
|
+
!isPresent &&
|
|
7108
|
+
!presenceChildren.size &&
|
|
7109
|
+
onExitComplete &&
|
|
7110
|
+
onExitComplete();
|
|
7073
7111
|
}, [isPresent]);
|
|
7074
7112
|
if (mode === "popLayout") {
|
|
7075
7113
|
children = React__namespace.createElement(PopChild, { isPresent: isPresent }, children);
|
|
@@ -7257,8 +7295,7 @@ function nodeGroup() {
|
|
|
7257
7295
|
|
|
7258
7296
|
const shouldInheritGroup = (inherit) => inherit === true;
|
|
7259
7297
|
const shouldInheritId = (inherit) => shouldInheritGroup(inherit === true) || inherit === "id";
|
|
7260
|
-
const LayoutGroup = ({ children, id, inheritId, inherit = true
|
|
7261
|
-
var _a, _b;
|
|
7298
|
+
const LayoutGroup = ({ children, id, inheritId, inherit = true }) => {
|
|
7262
7299
|
// Maintain backwards-compatibility with inheritId until 7.0
|
|
7263
7300
|
if (inheritId !== undefined)
|
|
7264
7301
|
inherit = inheritId;
|
|
@@ -7266,7 +7303,7 @@ const LayoutGroup = ({ children, id, inheritId, inherit = true, }) => {
|
|
|
7266
7303
|
const deprecatedLayoutGroupContext = React.useContext(DeprecatedLayoutGroupContext);
|
|
7267
7304
|
const [forceRender, key] = useForceUpdate();
|
|
7268
7305
|
const context = React.useRef(null);
|
|
7269
|
-
const upstreamId =
|
|
7306
|
+
const upstreamId = layoutGroupContext.id || deprecatedLayoutGroupContext;
|
|
7270
7307
|
if (context.current === null) {
|
|
7271
7308
|
if (shouldInheritId(inherit) && upstreamId) {
|
|
7272
7309
|
id = id ? upstreamId + "-" + id : upstreamId;
|
|
@@ -7274,11 +7311,11 @@ const LayoutGroup = ({ children, id, inheritId, inherit = true, }) => {
|
|
|
7274
7311
|
context.current = {
|
|
7275
7312
|
id,
|
|
7276
7313
|
group: shouldInheritGroup(inherit)
|
|
7277
|
-
?
|
|
7314
|
+
? layoutGroupContext.group || nodeGroup()
|
|
7278
7315
|
: nodeGroup(),
|
|
7279
7316
|
};
|
|
7280
7317
|
}
|
|
7281
|
-
const memoizedContext = React.useMemo(() => (
|
|
7318
|
+
const memoizedContext = React.useMemo(() => ({ ...context.current, forceRender }), [key]);
|
|
7282
7319
|
return (React__namespace.createElement(LayoutGroupContext.Provider, { value: memoizedContext }, children));
|
|
7283
7320
|
};
|
|
7284
7321
|
|
|
@@ -7307,13 +7344,12 @@ const AnimateSharedLayout = ({ children, }) => {
|
|
|
7307
7344
|
*
|
|
7308
7345
|
* @public
|
|
7309
7346
|
*/
|
|
7310
|
-
function MotionConfig(
|
|
7311
|
-
var { children, isValidProp } = _a, config = tslib.__rest(_a, ["children", "isValidProp"]);
|
|
7347
|
+
function MotionConfig({ children, isValidProp, ...config }) {
|
|
7312
7348
|
isValidProp && loadExternalIsValidProp(isValidProp);
|
|
7313
7349
|
/**
|
|
7314
7350
|
* Inherit props from any parent MotionConfig components
|
|
7315
7351
|
*/
|
|
7316
|
-
config =
|
|
7352
|
+
config = { ...React.useContext(MotionConfigContext), ...config };
|
|
7317
7353
|
/**
|
|
7318
7354
|
* Don't allow isStatic to change between renders as it affects how many hooks
|
|
7319
7355
|
* motion components fire.
|
|
@@ -7369,14 +7405,13 @@ function LazyMotion({ children, features, strict = false }) {
|
|
|
7369
7405
|
* If this is a synchronous load, load features immediately
|
|
7370
7406
|
*/
|
|
7371
7407
|
if (!isLazyBundle(features)) {
|
|
7372
|
-
const { renderer
|
|
7408
|
+
const { renderer, ...loadedFeatures } = features;
|
|
7373
7409
|
loadedRenderer.current = renderer;
|
|
7374
7410
|
loadFeatures(loadedFeatures);
|
|
7375
7411
|
}
|
|
7376
7412
|
React.useEffect(() => {
|
|
7377
7413
|
if (isLazyBundle(features)) {
|
|
7378
|
-
features().then((
|
|
7379
|
-
var { renderer } = _a, loadedFeatures = tslib.__rest(_a, ["renderer"]);
|
|
7414
|
+
features().then(({ renderer, ...loadedFeatures }) => {
|
|
7380
7415
|
loadFeatures(loadedFeatures);
|
|
7381
7416
|
loadedRenderer.current = renderer;
|
|
7382
7417
|
setIsLoaded(true);
|
|
@@ -7411,8 +7446,7 @@ function checkReorder(order, value, offset, velocity) {
|
|
|
7411
7446
|
return order;
|
|
7412
7447
|
}
|
|
7413
7448
|
|
|
7414
|
-
function ReorderGroup(
|
|
7415
|
-
var { children, as = "ul", axis = "y", onReorder, values } = _a, props = tslib.__rest(_a, ["children", "as", "axis", "onReorder", "values"]);
|
|
7449
|
+
function ReorderGroup({ children, as = "ul", axis = "y", onReorder, values, ...props }, externalRef) {
|
|
7416
7450
|
const Component = useConstant(() => motion(as));
|
|
7417
7451
|
const order = [];
|
|
7418
7452
|
const isReordering = React.useRef(false);
|
|
@@ -7444,7 +7478,7 @@ function ReorderGroup(_a, externalRef) {
|
|
|
7444
7478
|
React.useEffect(() => {
|
|
7445
7479
|
isReordering.current = false;
|
|
7446
7480
|
});
|
|
7447
|
-
return (React__namespace.createElement(Component,
|
|
7481
|
+
return (React__namespace.createElement(Component, { ...props, ref: externalRef },
|
|
7448
7482
|
React__namespace.createElement(ReorderContext.Provider, { value: context }, children)));
|
|
7449
7483
|
}
|
|
7450
7484
|
const Group = React.forwardRef(ReorderGroup);
|
|
@@ -7498,7 +7532,10 @@ function transform(...args) {
|
|
|
7498
7532
|
const inputRange = args[1 + argOffset];
|
|
7499
7533
|
const outputRange = args[2 + argOffset];
|
|
7500
7534
|
const options = args[3 + argOffset];
|
|
7501
|
-
const interpolator = popmotion.interpolate(inputRange, outputRange,
|
|
7535
|
+
const interpolator = popmotion.interpolate(inputRange, outputRange, {
|
|
7536
|
+
mixer: getMixer(outputRange[0]),
|
|
7537
|
+
...options,
|
|
7538
|
+
});
|
|
7502
7539
|
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
7503
7540
|
}
|
|
7504
7541
|
|
|
@@ -7563,13 +7600,12 @@ function useListTransform(values, transformer) {
|
|
|
7563
7600
|
function useDefaultMotionValue(value, defaultValue = 0) {
|
|
7564
7601
|
return isMotionValue(value) ? value : useMotionValue(defaultValue);
|
|
7565
7602
|
}
|
|
7566
|
-
function ReorderItem(
|
|
7567
|
-
var { children, style, value, as = "li", onDrag, layout = true } = _a, props = tslib.__rest(_a, ["children", "style", "value", "as", "onDrag", "layout"]);
|
|
7603
|
+
function ReorderItem({ children, style = {}, value, as = "li", onDrag, layout = true, ...props }, externalRef) {
|
|
7568
7604
|
const Component = useConstant(() => motion(as));
|
|
7569
7605
|
const context = React.useContext(ReorderContext);
|
|
7570
7606
|
const point = {
|
|
7571
|
-
x: useDefaultMotionValue(style
|
|
7572
|
-
y: useDefaultMotionValue(style
|
|
7607
|
+
x: useDefaultMotionValue(style.x),
|
|
7608
|
+
y: useDefaultMotionValue(style.y),
|
|
7573
7609
|
};
|
|
7574
7610
|
const zIndex = useTransform([point.x, point.y], ([latestX, latestY]) => latestX || latestY ? 1 : "unset");
|
|
7575
7611
|
const measuredLayout = React.useRef(null);
|
|
@@ -7578,14 +7614,14 @@ function ReorderItem(_a, externalRef) {
|
|
|
7578
7614
|
React.useEffect(() => {
|
|
7579
7615
|
registerItem(value, measuredLayout.current);
|
|
7580
7616
|
}, [context]);
|
|
7581
|
-
return (React__namespace.createElement(Component,
|
|
7617
|
+
return (React__namespace.createElement(Component, { drag: axis, ...props, dragSnapToOrigin: true, style: { ...style, x: point.x, y: point.y, zIndex }, layout: layout, onDrag: (event, gesturePoint) => {
|
|
7582
7618
|
const { velocity } = gesturePoint;
|
|
7583
7619
|
velocity[axis] &&
|
|
7584
7620
|
updateOrder(value, point[axis].get(), velocity[axis]);
|
|
7585
|
-
onDrag
|
|
7621
|
+
onDrag && onDrag(event, gesturePoint);
|
|
7586
7622
|
}, onLayoutMeasure: (measured) => {
|
|
7587
7623
|
measuredLayout.current = measured;
|
|
7588
|
-
}, ref: externalRef }
|
|
7624
|
+
}, ref: externalRef }, children));
|
|
7589
7625
|
}
|
|
7590
7626
|
const Item = React.forwardRef(ReorderItem);
|
|
7591
7627
|
|
|
@@ -7597,12 +7633,21 @@ const Reorder = {
|
|
|
7597
7633
|
/**
|
|
7598
7634
|
* @public
|
|
7599
7635
|
*/
|
|
7600
|
-
const domAnimation =
|
|
7636
|
+
const domAnimation = {
|
|
7637
|
+
renderer: createDomVisualElement,
|
|
7638
|
+
...animations,
|
|
7639
|
+
...gestureAnimations,
|
|
7640
|
+
};
|
|
7601
7641
|
|
|
7602
7642
|
/**
|
|
7603
7643
|
* @public
|
|
7604
7644
|
*/
|
|
7605
|
-
const domMax =
|
|
7645
|
+
const domMax = {
|
|
7646
|
+
...domAnimation,
|
|
7647
|
+
...drag,
|
|
7648
|
+
...layoutFeatures,
|
|
7649
|
+
projectionNodeConstructor: HTMLProjectionNode,
|
|
7650
|
+
};
|
|
7606
7651
|
|
|
7607
7652
|
/**
|
|
7608
7653
|
* Combine multiple motion values into a new one using a string template literal.
|
|
@@ -7678,7 +7723,13 @@ function useSpring(source, config = {}) {
|
|
|
7678
7723
|
if (activeSpringAnimation.current) {
|
|
7679
7724
|
activeSpringAnimation.current.stop();
|
|
7680
7725
|
}
|
|
7681
|
-
activeSpringAnimation.current = popmotion.animate(
|
|
7726
|
+
activeSpringAnimation.current = popmotion.animate({
|
|
7727
|
+
from: value.get(),
|
|
7728
|
+
to: v,
|
|
7729
|
+
velocity: value.getVelocity(),
|
|
7730
|
+
...config,
|
|
7731
|
+
onUpdate: set,
|
|
7732
|
+
});
|
|
7682
7733
|
return value.get();
|
|
7683
7734
|
});
|
|
7684
7735
|
}, [JSON.stringify(config)]);
|
|
@@ -7713,8 +7764,7 @@ const createScrollMotionValues = () => ({
|
|
|
7713
7764
|
scrollXProgress: motionValue(0),
|
|
7714
7765
|
scrollYProgress: motionValue(0),
|
|
7715
7766
|
});
|
|
7716
|
-
function useScroll(
|
|
7717
|
-
var { container, target } = _a, options = tslib.__rest(_a, ["container", "target"]);
|
|
7767
|
+
function useScroll({ container, target, ...options } = {}) {
|
|
7718
7768
|
const values = useConstant(createScrollMotionValues);
|
|
7719
7769
|
useIsomorphicLayoutEffect(() => {
|
|
7720
7770
|
return dom.scroll(({ x, y }) => {
|
|
@@ -7722,7 +7772,11 @@ function useScroll(_a = {}) {
|
|
|
7722
7772
|
values.scrollXProgress.set(x.progress);
|
|
7723
7773
|
values.scrollY.set(y.current);
|
|
7724
7774
|
values.scrollYProgress.set(y.progress);
|
|
7725
|
-
},
|
|
7775
|
+
}, {
|
|
7776
|
+
...options,
|
|
7777
|
+
container: (container === null || container === void 0 ? void 0 : container.current) || undefined,
|
|
7778
|
+
target: (target === null || target === void 0 ? void 0 : target.current) || undefined,
|
|
7779
|
+
});
|
|
7726
7780
|
}, []);
|
|
7727
7781
|
return values;
|
|
7728
7782
|
}
|
|
@@ -7773,11 +7827,11 @@ class WillChangeMotionValue extends MotionValue {
|
|
|
7773
7827
|
}
|
|
7774
7828
|
add(name) {
|
|
7775
7829
|
let memberName;
|
|
7776
|
-
if (
|
|
7830
|
+
if (transformProps.has(name)) {
|
|
7777
7831
|
this.transforms.add(name);
|
|
7778
7832
|
memberName = "transform";
|
|
7779
7833
|
}
|
|
7780
|
-
else if (!
|
|
7834
|
+
else if (!name.startsWith("origin") &&
|
|
7781
7835
|
!isCSSVariable$1(name) &&
|
|
7782
7836
|
name !== "willChange") {
|
|
7783
7837
|
memberName = camelToDash(name);
|
|
@@ -7788,7 +7842,7 @@ class WillChangeMotionValue extends MotionValue {
|
|
|
7788
7842
|
}
|
|
7789
7843
|
}
|
|
7790
7844
|
remove(name) {
|
|
7791
|
-
if (
|
|
7845
|
+
if (transformProps.has(name)) {
|
|
7792
7846
|
this.transforms.delete(name);
|
|
7793
7847
|
if (!this.transforms.size) {
|
|
7794
7848
|
removeItem(this.members, "transform");
|
|
@@ -7807,6 +7861,58 @@ function useWillChange() {
|
|
|
7807
7861
|
return useConstant(() => new WillChangeMotionValue("auto"));
|
|
7808
7862
|
}
|
|
7809
7863
|
|
|
7864
|
+
/**
|
|
7865
|
+
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
7866
|
+
*
|
|
7867
|
+
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
7868
|
+
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
7869
|
+
*
|
|
7870
|
+
* It will actively respond to changes and re-render your components with the latest setting.
|
|
7871
|
+
*
|
|
7872
|
+
* ```jsx
|
|
7873
|
+
* export function Sidebar({ isOpen }) {
|
|
7874
|
+
* const shouldReduceMotion = useReducedMotion()
|
|
7875
|
+
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
7876
|
+
*
|
|
7877
|
+
* return (
|
|
7878
|
+
* <motion.div animate={{
|
|
7879
|
+
* opacity: isOpen ? 1 : 0,
|
|
7880
|
+
* x: isOpen ? 0 : closedX
|
|
7881
|
+
* }} />
|
|
7882
|
+
* )
|
|
7883
|
+
* }
|
|
7884
|
+
* ```
|
|
7885
|
+
*
|
|
7886
|
+
* @return boolean
|
|
7887
|
+
*
|
|
7888
|
+
* @public
|
|
7889
|
+
*/
|
|
7890
|
+
function useReducedMotion() {
|
|
7891
|
+
/**
|
|
7892
|
+
* Lazy initialisation of prefersReducedMotion
|
|
7893
|
+
*/
|
|
7894
|
+
!hasReducedMotionListener.current && initPrefersReducedMotion();
|
|
7895
|
+
const [shouldReduceMotion] = React.useState(prefersReducedMotion.current);
|
|
7896
|
+
/**
|
|
7897
|
+
* TODO See if people miss automatically updating shouldReduceMotion setting
|
|
7898
|
+
*/
|
|
7899
|
+
return shouldReduceMotion;
|
|
7900
|
+
}
|
|
7901
|
+
|
|
7902
|
+
function useReducedMotionConfig() {
|
|
7903
|
+
const reducedMotionPreference = useReducedMotion();
|
|
7904
|
+
const { reducedMotion } = React.useContext(MotionConfigContext);
|
|
7905
|
+
if (reducedMotion === "never") {
|
|
7906
|
+
return false;
|
|
7907
|
+
}
|
|
7908
|
+
else if (reducedMotion === "always") {
|
|
7909
|
+
return true;
|
|
7910
|
+
}
|
|
7911
|
+
else {
|
|
7912
|
+
return reducedMotionPreference;
|
|
7913
|
+
}
|
|
7914
|
+
}
|
|
7915
|
+
|
|
7810
7916
|
/**
|
|
7811
7917
|
* @public
|
|
7812
7918
|
*/
|
|
@@ -7961,7 +8067,6 @@ function useCycle(...items) {
|
|
|
7961
8067
|
function useInView(ref, { root, margin, amount, once = false } = {}) {
|
|
7962
8068
|
const [isInView, setInView] = React.useState(false);
|
|
7963
8069
|
React.useEffect(() => {
|
|
7964
|
-
var _a;
|
|
7965
8070
|
if (!ref.current || (once && isInView))
|
|
7966
8071
|
return;
|
|
7967
8072
|
const onEnter = () => {
|
|
@@ -7969,7 +8074,7 @@ function useInView(ref, { root, margin, amount, once = false } = {}) {
|
|
|
7969
8074
|
return once ? undefined : () => setInView(false);
|
|
7970
8075
|
};
|
|
7971
8076
|
const options = {
|
|
7972
|
-
root: (
|
|
8077
|
+
root: (root && root.current) || undefined,
|
|
7973
8078
|
margin,
|
|
7974
8079
|
amount: amount === "some" ? "any" : amount,
|
|
7975
8080
|
};
|
|
@@ -8066,12 +8171,12 @@ function useDragControls() {
|
|
|
8066
8171
|
function useInstantLayoutTransition() {
|
|
8067
8172
|
return startTransition;
|
|
8068
8173
|
}
|
|
8069
|
-
function startTransition(
|
|
8174
|
+
function startTransition(callback) {
|
|
8070
8175
|
if (!rootProjectionNode.current)
|
|
8071
8176
|
return;
|
|
8072
8177
|
rootProjectionNode.current.isUpdating = false;
|
|
8073
8178
|
rootProjectionNode.current.blockUpdate();
|
|
8074
|
-
|
|
8179
|
+
callback && callback();
|
|
8075
8180
|
}
|
|
8076
8181
|
|
|
8077
8182
|
function useInstantTransition() {
|
|
@@ -8114,11 +8219,10 @@ const stateVisualElement = visualElement({
|
|
|
8114
8219
|
readValueFromInstance(_state, key, options) {
|
|
8115
8220
|
return options.initialState[key] || 0;
|
|
8116
8221
|
},
|
|
8117
|
-
makeTargetAnimatable(element,
|
|
8118
|
-
var { transition, transitionEnd } = _a, target = tslib.__rest(_a, ["transition", "transitionEnd"]);
|
|
8222
|
+
makeTargetAnimatable(element, { transition, transitionEnd, ...target }) {
|
|
8119
8223
|
const origin = getOrigin(target, transition || {}, element);
|
|
8120
8224
|
checkTargetForNewValues(element, target, origin);
|
|
8121
|
-
return
|
|
8225
|
+
return { transition, transitionEnd, ...target };
|
|
8122
8226
|
},
|
|
8123
8227
|
});
|
|
8124
8228
|
const useVisualState = makeUseVisualState({
|
|
@@ -8140,7 +8244,7 @@ function useAnimatedState(initialState) {
|
|
|
8140
8244
|
React.useEffect(() => {
|
|
8141
8245
|
element.setProps({
|
|
8142
8246
|
onUpdate: (v) => {
|
|
8143
|
-
setAnimationState(
|
|
8247
|
+
setAnimationState({ ...v });
|
|
8144
8248
|
},
|
|
8145
8249
|
});
|
|
8146
8250
|
}, [setAnimationState, element]);
|