framer-motion 7.2.0 → 7.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +762 -627
- package/dist/es/animation/use-animated-state.mjs +3 -5
- package/dist/es/animation/utils/default-transitions.mjs +1 -1
- package/dist/es/animation/utils/transitions.mjs +28 -26
- package/dist/es/components/AnimatePresence/PopChild.mjs +3 -2
- package/dist/es/components/AnimatePresence/PresenceChild.mjs +5 -2
- package/dist/es/components/AnimatePresence/use-presence.mjs +1 -1
- package/dist/es/components/LayoutGroup/index.mjs +4 -5
- package/dist/es/components/LazyMotion/index.mjs +3 -5
- package/dist/es/components/MotionConfig/index.mjs +2 -4
- package/dist/es/components/Reorder/Group.mjs +2 -4
- package/dist/es/components/Reorder/Item.mjs +6 -8
- package/dist/es/context/MotionContext/utils.mjs +3 -2
- package/dist/es/gestures/PanSession.mjs +2 -2
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +16 -4
- package/dist/es/gestures/use-focus-gesture.mjs +3 -4
- package/dist/es/gestures/use-hover-gesture.mjs +4 -3
- package/dist/es/gestures/use-tap-gesture.mjs +9 -10
- package/dist/es/index.mjs +2 -1
- package/dist/es/motion/features/animations.mjs +8 -3
- package/dist/es/motion/features/definitions.mjs +1 -13
- package/dist/es/motion/features/layout/MeasureLayout.mjs +12 -6
- package/dist/es/motion/features/load-features.mjs +14 -0
- package/dist/es/motion/features/viewport/observers.mjs +4 -7
- package/dist/es/motion/features/viewport/use-viewport.mjs +8 -6
- package/dist/es/motion/index.mjs +23 -23
- package/dist/es/motion/utils/VisualElementHandler.mjs +2 -5
- package/dist/es/motion/utils/is-forced-motion-value.mjs +3 -3
- package/dist/es/motion/utils/use-motion-ref.mjs +1 -2
- package/dist/es/motion/utils/use-visual-element.mjs +14 -12
- package/dist/es/motion/utils/use-visual-state.mjs +19 -16
- package/dist/es/motion/utils/valid-prop.mjs +22 -17
- package/dist/es/projection/geometry/utils.mjs +10 -1
- package/dist/es/projection/node/HTMLProjectionNode.mjs +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +62 -20
- package/dist/es/projection/use-instant-layout-transition.mjs +2 -2
- package/dist/es/render/dom/features-animation.mjs +5 -1
- package/dist/es/render/dom/features-max.mjs +6 -1
- package/dist/es/render/dom/motion.mjs +6 -1
- package/dist/es/render/dom/use-render.mjs +5 -1
- package/dist/es/render/dom/utils/camel-to-dash.mjs +1 -3
- package/dist/es/render/dom/utils/create-config.mjs +7 -2
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +5 -7
- package/dist/es/render/dom/utils/unit-conversion.mjs +4 -4
- package/dist/es/render/dom/value-types/defaults.mjs +15 -3
- package/dist/es/render/dom/value-types/type-int.mjs +4 -1
- package/dist/es/render/html/config-motion.mjs +1 -1
- package/dist/es/render/html/use-props.mjs +5 -9
- package/dist/es/render/html/utils/build-styles.mjs +17 -15
- package/dist/es/render/html/utils/build-transform.mjs +8 -18
- package/dist/es/render/html/utils/transform.mjs +21 -30
- package/dist/es/render/html/visual-element.mjs +8 -9
- package/dist/es/render/index.mjs +118 -40
- package/dist/es/render/svg/use-props.mjs +5 -2
- package/dist/es/render/svg/utils/build-attrs.mjs +3 -5
- package/dist/es/render/svg/utils/create-render-state.mjs +4 -1
- package/dist/es/render/svg/visual-element.mjs +8 -4
- package/dist/es/render/utils/animation-state.mjs +12 -9
- package/dist/es/render/utils/animation.mjs +14 -8
- package/dist/es/render/utils/is-controlling-variants.mjs +22 -0
- package/dist/es/render/utils/is-variant-label.mjs +8 -0
- package/dist/es/render/utils/motion-values.mjs +3 -3
- package/dist/es/render/utils/resolve-dynamic-variants.mjs +24 -0
- package/dist/es/render/utils/resolve-variants.mjs +26 -0
- package/dist/es/render/utils/setters.mjs +12 -9
- package/dist/es/utils/reduced-motion/index.mjs +19 -0
- package/dist/es/utils/reduced-motion/state.mjs +5 -0
- package/dist/es/utils/reduced-motion/use-reduced-motion-config.mjs +19 -0
- package/dist/es/utils/reduced-motion/use-reduced-motion.mjs +43 -0
- package/dist/es/utils/transform.mjs +4 -1
- package/dist/es/utils/use-in-view.mjs +1 -2
- package/dist/es/value/index.mjs +1 -1
- package/dist/es/value/use-scroll.mjs +6 -4
- package/dist/es/value/use-spring.mjs +7 -1
- package/dist/es/value/use-will-change/index.mjs +4 -4
- package/dist/es/value/utils/is-motion-value.mjs +1 -3
- package/dist/framer-motion.dev.js +806 -670
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +60 -54
- package/dist/projection.dev.js +402 -213
- package/dist/size-rollup-dom-animation-assets.js +1 -0
- package/dist/size-rollup-dom-animation-m.js +1 -0
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max-assets.js +1 -0
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/dist/size-rollup-motion.js +1 -0
- package/dist/size-webpack-dom-animation.js +1 -1
- package/dist/size-webpack-dom-max.js +1 -1
- package/dist/size-webpack-m.js +1 -1
- package/dist/three-entry.d.ts +41 -22
- package/package.json +12 -8
- package/dist/es/motion/features/use-features.mjs +0 -40
- package/dist/es/motion/features/use-projection.mjs +0 -33
- package/dist/es/render/utils/variants.mjs +0 -73
- package/dist/es/utils/use-reduced-motion.mjs +0 -73
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" ||
|
|
134
|
+
return typeof v === "string" || Array.isArray(v);
|
|
294
135
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
function getCurrent(visualElement) {
|
|
299
|
-
const current = {};
|
|
300
|
-
visualElement.forEachValue((value, key) => (current[key] = value.get()));
|
|
301
|
-
return current;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Creates an object containing the latest velocity of every MotionValue on a VisualElement
|
|
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,41 @@ 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
|
+
"rotateZ",
|
|
487
|
+
"skew",
|
|
488
|
+
"skewX",
|
|
489
|
+
"skewY",
|
|
490
|
+
];
|
|
674
491
|
/**
|
|
675
492
|
* A quick lookup for transform props.
|
|
676
493
|
*/
|
|
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
|
-
}
|
|
494
|
+
const transformProps = new Set(transformPropOrder);
|
|
688
495
|
|
|
689
496
|
function isForcedMotionValue(key, { layout, layoutId }) {
|
|
690
|
-
return (
|
|
691
|
-
|
|
497
|
+
return (transformProps.has(key) ||
|
|
498
|
+
key.startsWith("origin") ||
|
|
692
499
|
((layout || layoutId !== undefined) &&
|
|
693
500
|
(!!scaleCorrectors[key] || key === "opacity")));
|
|
694
501
|
}
|
|
695
502
|
|
|
696
|
-
const isMotionValue = (value) =>
|
|
697
|
-
return Boolean(value !== null && typeof value === "object" && value.getVelocity);
|
|
698
|
-
};
|
|
503
|
+
const isMotionValue = (value) => value === undefined ? false : !!value.getVelocity;
|
|
699
504
|
|
|
700
505
|
const translateAlias = {
|
|
701
506
|
x: "translateX",
|
|
@@ -703,6 +508,10 @@ const translateAlias = {
|
|
|
703
508
|
z: "translateZ",
|
|
704
509
|
transformPerspective: "perspective",
|
|
705
510
|
};
|
|
511
|
+
/**
|
|
512
|
+
* A function to use with Array.sort to sort transform keys by their default order.
|
|
513
|
+
*/
|
|
514
|
+
const sortTransformProps = (a, b) => transformPropOrder.indexOf(a) - transformPropOrder.indexOf(b);
|
|
706
515
|
/**
|
|
707
516
|
* Build a CSS transform style from individual x/y/scale etc properties.
|
|
708
517
|
*
|
|
@@ -714,18 +523,11 @@ function buildTransform({ transform, transformKeys }, { enableHardwareAccelerati
|
|
|
714
523
|
let transformString = "";
|
|
715
524
|
// Transform keys into their default order - this will determine the output order.
|
|
716
525
|
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
526
|
// Loop over each transform and build them into transformString
|
|
721
|
-
const
|
|
722
|
-
for (let i = 0; i < numTransformKeys; i++) {
|
|
723
|
-
const key = transformKeys[i];
|
|
527
|
+
for (const key of transformKeys) {
|
|
724
528
|
transformString += `${translateAlias[key] || key}(${transform[key]}) `;
|
|
725
|
-
if (key === "z")
|
|
726
|
-
transformHasZ = true;
|
|
727
529
|
}
|
|
728
|
-
if (
|
|
530
|
+
if (enableHardwareAcceleration && !transform.z) {
|
|
729
531
|
transformString += "translateZ(0)";
|
|
730
532
|
}
|
|
731
533
|
transformString = transformString.trim();
|
|
@@ -739,13 +541,6 @@ function buildTransform({ transform, transformKeys }, { enableHardwareAccelerati
|
|
|
739
541
|
}
|
|
740
542
|
return transformString;
|
|
741
543
|
}
|
|
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
544
|
|
|
750
545
|
/**
|
|
751
546
|
* Returns true if the provided key is a CSS variable
|
|
@@ -763,7 +558,10 @@ const getValueAsType = (value, type) => {
|
|
|
763
558
|
: value;
|
|
764
559
|
};
|
|
765
560
|
|
|
766
|
-
const int =
|
|
561
|
+
const int = {
|
|
562
|
+
...styleValueTypes.number,
|
|
563
|
+
transform: Math.round,
|
|
564
|
+
};
|
|
767
565
|
|
|
768
566
|
const numberValueTypes = {
|
|
769
567
|
// Border props
|
|
@@ -833,11 +631,7 @@ const numberValueTypes = {
|
|
|
833
631
|
};
|
|
834
632
|
|
|
835
633
|
function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
836
|
-
var _a;
|
|
837
634
|
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
635
|
transformKeys.length = 0;
|
|
842
636
|
// Track whether we encounter any transform or transformOrigin values.
|
|
843
637
|
let hasTransform = false;
|
|
@@ -862,7 +656,7 @@ function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
|
862
656
|
// Convert the value to its default value type, ie 0 -> "0px"
|
|
863
657
|
const valueType = numberValueTypes[key];
|
|
864
658
|
const valueAsType = getValueAsType(value, valueType);
|
|
865
|
-
if (
|
|
659
|
+
if (transformProps.has(key)) {
|
|
866
660
|
// If this is a transform, flag to enable further transform processing
|
|
867
661
|
hasTransform = true;
|
|
868
662
|
transform[key] = valueAsType;
|
|
@@ -871,29 +665,35 @@ function buildHTMLStyles(state, latestValues, options, transformTemplate) {
|
|
|
871
665
|
if (!transformIsNone)
|
|
872
666
|
continue;
|
|
873
667
|
// Otherwise check to see if this is a default transform
|
|
874
|
-
if (value !== (
|
|
668
|
+
if (value !== (valueType.default || 0))
|
|
875
669
|
transformIsNone = false;
|
|
876
670
|
}
|
|
877
|
-
else if (
|
|
878
|
-
transformOrigin[key] = valueAsType;
|
|
671
|
+
else if (key.startsWith("origin")) {
|
|
879
672
|
// If this is a transform origin, flag and enable further transform-origin processing
|
|
880
673
|
hasTransformOrigin = true;
|
|
674
|
+
transformOrigin[key] = valueAsType;
|
|
881
675
|
}
|
|
882
676
|
else {
|
|
883
677
|
style[key] = valueAsType;
|
|
884
678
|
}
|
|
885
679
|
}
|
|
886
|
-
if (hasTransform) {
|
|
680
|
+
if (hasTransform || transformTemplate) {
|
|
887
681
|
style.transform = buildTransform(state, options, transformIsNone, transformTemplate);
|
|
888
682
|
}
|
|
889
|
-
else if (transformTemplate) {
|
|
890
|
-
style.transform = transformTemplate({}, "");
|
|
891
|
-
}
|
|
892
683
|
else if (!latestValues.transform && style.transform) {
|
|
684
|
+
/**
|
|
685
|
+
* If we have previously created a transform but currently don't have any,
|
|
686
|
+
* reset transform style to none.
|
|
687
|
+
*/
|
|
893
688
|
style.transform = "none";
|
|
894
689
|
}
|
|
690
|
+
/**
|
|
691
|
+
* Build a transformOrigin style. Uses the same defaults as the browser for
|
|
692
|
+
* undefined origins.
|
|
693
|
+
*/
|
|
895
694
|
if (hasTransformOrigin) {
|
|
896
|
-
|
|
695
|
+
const { originX = "50%", originY = "50%", originZ = 0, } = transformOrigin;
|
|
696
|
+
style.transformOrigin = `${originX} ${originY} ${originZ}`;
|
|
897
697
|
}
|
|
898
698
|
}
|
|
899
699
|
|
|
@@ -916,28 +716,24 @@ function useInitialMotionValues({ transformTemplate }, visualState, isStatic) {
|
|
|
916
716
|
return React.useMemo(() => {
|
|
917
717
|
const state = createHtmlRenderState();
|
|
918
718
|
buildHTMLStyles(state, visualState, { enableHardwareAcceleration: !isStatic }, transformTemplate);
|
|
919
|
-
|
|
920
|
-
return Object.assign(Object.assign({}, vars), style);
|
|
719
|
+
return Object.assign({}, state.vars, state.style);
|
|
921
720
|
}, [visualState]);
|
|
922
721
|
}
|
|
923
722
|
function useStyle(props, visualState, isStatic) {
|
|
924
723
|
const styleProp = props.style || {};
|
|
925
|
-
|
|
724
|
+
const style = {};
|
|
926
725
|
/**
|
|
927
726
|
* Copy non-Motion Values straight into style
|
|
928
727
|
*/
|
|
929
728
|
copyRawValuesOnly(style, styleProp, props);
|
|
930
729
|
Object.assign(style, useInitialMotionValues(props, visualState, isStatic));
|
|
931
|
-
|
|
932
|
-
style = props.transformValues(style);
|
|
933
|
-
}
|
|
934
|
-
return style;
|
|
730
|
+
return props.transformValues ? props.transformValues(style) : style;
|
|
935
731
|
}
|
|
936
732
|
function useHTMLProps(props, visualState, isStatic) {
|
|
937
733
|
// The `any` isn't ideal but it is the type of createElement props argument
|
|
938
734
|
const htmlProps = {};
|
|
939
735
|
const style = useStyle(props, visualState, isStatic);
|
|
940
|
-
if (
|
|
736
|
+
if (props.drag && props.dragListener !== false) {
|
|
941
737
|
// Disable the ghost element when a user drags
|
|
942
738
|
htmlProps.draggable = false;
|
|
943
739
|
// Disable text selection
|
|
@@ -955,6 +751,24 @@ function useHTMLProps(props, visualState, isStatic) {
|
|
|
955
751
|
return htmlProps;
|
|
956
752
|
}
|
|
957
753
|
|
|
754
|
+
const animationProps = [
|
|
755
|
+
"animate",
|
|
756
|
+
"exit",
|
|
757
|
+
"variants",
|
|
758
|
+
"whileHover",
|
|
759
|
+
"whileTap",
|
|
760
|
+
"whileFocus",
|
|
761
|
+
"whileDrag",
|
|
762
|
+
"whileInView",
|
|
763
|
+
];
|
|
764
|
+
const tapProps = ["whileTap", "onTap", "onTapStart", "onTapCancel"];
|
|
765
|
+
const panProps = ["onPan", "onPanStart", "onPanSessionStart", "onPanEnd"];
|
|
766
|
+
const inViewProps = [
|
|
767
|
+
"whileInView",
|
|
768
|
+
"onViewportEnter",
|
|
769
|
+
"onViewportLeave",
|
|
770
|
+
"viewport",
|
|
771
|
+
];
|
|
958
772
|
/**
|
|
959
773
|
* A list of all valid MotionProps.
|
|
960
774
|
*
|
|
@@ -963,8 +777,6 @@ function useHTMLProps(props, visualState, isStatic) {
|
|
|
963
777
|
*/
|
|
964
778
|
const validMotionProps = new Set([
|
|
965
779
|
"initial",
|
|
966
|
-
"animate",
|
|
967
|
-
"exit",
|
|
968
780
|
"style",
|
|
969
781
|
"variants",
|
|
970
782
|
"transition",
|
|
@@ -1000,24 +812,13 @@ const validMotionProps = new Set([
|
|
|
1000
812
|
"dragMomentum",
|
|
1001
813
|
"dragPropagation",
|
|
1002
814
|
"dragTransition",
|
|
1003
|
-
"whileDrag",
|
|
1004
|
-
"onPan",
|
|
1005
|
-
"onPanStart",
|
|
1006
|
-
"onPanEnd",
|
|
1007
|
-
"onPanSessionStart",
|
|
1008
|
-
"onTap",
|
|
1009
|
-
"onTapStart",
|
|
1010
|
-
"onTapCancel",
|
|
1011
815
|
"onHoverStart",
|
|
1012
816
|
"onHoverEnd",
|
|
1013
|
-
"whileFocus",
|
|
1014
|
-
"whileTap",
|
|
1015
|
-
"whileHover",
|
|
1016
|
-
"whileInView",
|
|
1017
|
-
"onViewportEnter",
|
|
1018
|
-
"onViewportLeave",
|
|
1019
|
-
"viewport",
|
|
1020
817
|
"layoutScroll",
|
|
818
|
+
...inViewProps,
|
|
819
|
+
...tapProps,
|
|
820
|
+
...animationProps,
|
|
821
|
+
...panProps,
|
|
1021
822
|
]);
|
|
1022
823
|
/**
|
|
1023
824
|
* Check whether a prop name is a valid `MotionProp` key.
|
|
@@ -1123,10 +924,9 @@ function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true
|
|
|
1123
924
|
/**
|
|
1124
925
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
1125
926
|
*/
|
|
1126
|
-
function buildSVGAttrs(state,
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
latest = tslib.__rest(_a, ["attrX", "attrY", "originX", "originY", "pathLength", "pathSpacing", "pathOffset"]);
|
|
927
|
+
function buildSVGAttrs(state, { attrX, attrY, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0,
|
|
928
|
+
// This is object creation, which we try to avoid per-frame.
|
|
929
|
+
...latest }, options, transformTemplate) {
|
|
1130
930
|
buildHTMLStyles(state, latest, options, transformTemplate);
|
|
1131
931
|
state.attrs = state.style;
|
|
1132
932
|
state.style = {};
|
|
@@ -1156,18 +956,24 @@ function buildSVGAttrs(state, _a, options, transformTemplate) {
|
|
|
1156
956
|
}
|
|
1157
957
|
}
|
|
1158
958
|
|
|
1159
|
-
const createSvgRenderState = () => (
|
|
959
|
+
const createSvgRenderState = () => ({
|
|
960
|
+
...createHtmlRenderState(),
|
|
961
|
+
attrs: {},
|
|
962
|
+
});
|
|
1160
963
|
|
|
1161
964
|
function useSVGProps(props, visualState) {
|
|
1162
965
|
const visualProps = React.useMemo(() => {
|
|
1163
966
|
const state = createSvgRenderState();
|
|
1164
967
|
buildSVGAttrs(state, visualState, { enableHardwareAcceleration: false }, props.transformTemplate);
|
|
1165
|
-
return
|
|
968
|
+
return {
|
|
969
|
+
...state.attrs,
|
|
970
|
+
style: { ...state.style },
|
|
971
|
+
};
|
|
1166
972
|
}, [visualState]);
|
|
1167
973
|
if (props.style) {
|
|
1168
974
|
const rawStyles = {};
|
|
1169
975
|
copyRawValuesOnly(rawStyles, props.style, props);
|
|
1170
|
-
visualProps.style =
|
|
976
|
+
visualProps.style = { ...rawStyles, ...visualProps.style };
|
|
1171
977
|
}
|
|
1172
978
|
return visualProps;
|
|
1173
979
|
}
|
|
@@ -1179,7 +985,11 @@ function createUseRender(forwardMotionProps = false) {
|
|
|
1179
985
|
: useHTMLProps;
|
|
1180
986
|
const visualProps = useVisualProps(props, latestValues, isStatic);
|
|
1181
987
|
const filteredProps = filterProps(props, typeof Component === "string", forwardMotionProps);
|
|
1182
|
-
const elementProps =
|
|
988
|
+
const elementProps = {
|
|
989
|
+
...filteredProps,
|
|
990
|
+
...visualProps,
|
|
991
|
+
ref,
|
|
992
|
+
};
|
|
1183
993
|
if (projectionId) {
|
|
1184
994
|
elementProps["data-projection-id"] = projectionId;
|
|
1185
995
|
}
|
|
@@ -1188,12 +998,10 @@ function createUseRender(forwardMotionProps = false) {
|
|
|
1188
998
|
return useRender;
|
|
1189
999
|
}
|
|
1190
1000
|
|
|
1191
|
-
const CAMEL_CASE_PATTERN = /([a-z])([A-Z])/g;
|
|
1192
|
-
const REPLACE_TEMPLATE = "$1-$2";
|
|
1193
1001
|
/**
|
|
1194
1002
|
* Convert camelCase to dash-case properties.
|
|
1195
1003
|
*/
|
|
1196
|
-
const camelToDash = (str) => str.replace(
|
|
1004
|
+
const camelToDash = (str) => str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
1197
1005
|
|
|
1198
1006
|
function renderHTML(element, { style, vars }, styleProp, projection) {
|
|
1199
1007
|
Object.assign(element.style, style, projection && projection.getProjectionStyles(styleProp));
|
|
@@ -1258,8 +1066,29 @@ function scrapeMotionValuesFromProps(props) {
|
|
|
1258
1066
|
return newValues;
|
|
1259
1067
|
}
|
|
1260
1068
|
|
|
1261
|
-
function
|
|
1262
|
-
|
|
1069
|
+
function resolveVariantFromProps(props, definition, custom, currentValues = {}, currentVelocity = {}) {
|
|
1070
|
+
/**
|
|
1071
|
+
* If the variant definition is a function, resolve.
|
|
1072
|
+
*/
|
|
1073
|
+
if (typeof definition === "function") {
|
|
1074
|
+
definition = definition(custom !== undefined ? custom : props.custom, currentValues, currentVelocity);
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* If the variant definition is a variant label, or
|
|
1078
|
+
* the function returned a variant label, resolve.
|
|
1079
|
+
*/
|
|
1080
|
+
if (typeof definition === "string") {
|
|
1081
|
+
definition = props.variants && props.variants[definition];
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* At this point we've resolved both functions and variant labels,
|
|
1085
|
+
* but the resolved variant label might itself have been a function.
|
|
1086
|
+
* If so, resolve. This can only have returned a valid target object.
|
|
1087
|
+
*/
|
|
1088
|
+
if (typeof definition === "function") {
|
|
1089
|
+
definition = definition(custom !== undefined ? custom : props.custom, currentValues, currentVelocity);
|
|
1090
|
+
}
|
|
1091
|
+
return definition;
|
|
1263
1092
|
}
|
|
1264
1093
|
|
|
1265
1094
|
const isKeyframesTarget = (v) => {
|
|
@@ -1299,29 +1128,32 @@ function makeState({ scrapeMotionValuesFromProps, createRenderState, onMount, },
|
|
|
1299
1128
|
const makeUseVisualState = (config) => (props, isStatic) => {
|
|
1300
1129
|
const context = React.useContext(MotionContext);
|
|
1301
1130
|
const presenceContext = React.useContext(PresenceContext);
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
: useConstant(() => makeState(config, props, context, presenceContext));
|
|
1131
|
+
const make = () => makeState(config, props, context, presenceContext);
|
|
1132
|
+
return isStatic ? make() : useConstant(make);
|
|
1305
1133
|
};
|
|
1306
1134
|
function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
1307
1135
|
const values = {};
|
|
1308
|
-
const blockInitialAnimation = (presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.initial) === false;
|
|
1309
1136
|
const motionValues = scrapeMotionValues(props);
|
|
1310
1137
|
for (const key in motionValues) {
|
|
1311
1138
|
values[key] = resolveMotionValue(motionValues[key]);
|
|
1312
1139
|
}
|
|
1313
1140
|
let { initial, animate } = props;
|
|
1314
|
-
const isControllingVariants =
|
|
1315
|
-
const isVariantNode =
|
|
1141
|
+
const isControllingVariants$1 = isControllingVariants(props);
|
|
1142
|
+
const isVariantNode$1 = isVariantNode(props);
|
|
1316
1143
|
if (context &&
|
|
1317
|
-
isVariantNode &&
|
|
1318
|
-
!isControllingVariants &&
|
|
1144
|
+
isVariantNode$1 &&
|
|
1145
|
+
!isControllingVariants$1 &&
|
|
1319
1146
|
props.inherit !== false) {
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1147
|
+
if (initial === undefined)
|
|
1148
|
+
initial = context.initial;
|
|
1149
|
+
if (animate === undefined)
|
|
1150
|
+
animate = context.animate;
|
|
1151
|
+
}
|
|
1152
|
+
let isInitialAnimationBlocked = presenceContext
|
|
1153
|
+
? presenceContext.initial === false
|
|
1154
|
+
: false;
|
|
1155
|
+
isInitialAnimationBlocked = isInitialAnimationBlocked || initial === false;
|
|
1156
|
+
const variantToSet = isInitialAnimationBlocked ? animate : initial;
|
|
1325
1157
|
if (variantToSet &&
|
|
1326
1158
|
typeof variantToSet !== "boolean" &&
|
|
1327
1159
|
!isAnimationControls(variantToSet)) {
|
|
@@ -1330,7 +1162,7 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
|
1330
1162
|
const resolved = resolveVariantFromProps(props, definition);
|
|
1331
1163
|
if (!resolved)
|
|
1332
1164
|
return;
|
|
1333
|
-
const { transitionEnd, transition
|
|
1165
|
+
const { transitionEnd, transition, ...target } = resolved;
|
|
1334
1166
|
for (const key in target) {
|
|
1335
1167
|
let valueTarget = target[key];
|
|
1336
1168
|
if (Array.isArray(valueTarget)) {
|
|
@@ -1338,7 +1170,7 @@ function makeLatestValues(props, context, presenceContext, scrapeMotionValues) {
|
|
|
1338
1170
|
* Take final keyframe if the initial animation is blocked because
|
|
1339
1171
|
* we want to initialise at the end of that blocked animation.
|
|
1340
1172
|
*/
|
|
1341
|
-
const index =
|
|
1173
|
+
const index = isInitialAnimationBlocked
|
|
1342
1174
|
? valueTarget.length - 1
|
|
1343
1175
|
: 0;
|
|
1344
1176
|
valueTarget = valueTarget[index];
|
|
@@ -1392,9 +1224,14 @@ function createDomMotionConfig(Component, { forwardMotionProps = false }, preloa
|
|
|
1392
1224
|
const baseConfig = isSVGComponent(Component)
|
|
1393
1225
|
? svgMotionConfig
|
|
1394
1226
|
: htmlMotionConfig;
|
|
1395
|
-
return
|
|
1227
|
+
return {
|
|
1228
|
+
...baseConfig,
|
|
1229
|
+
preloadedFeatures,
|
|
1230
|
+
useRender: createUseRender(forwardMotionProps),
|
|
1231
|
+
createVisualElement,
|
|
1396
1232
|
projectionNodeConstructor,
|
|
1397
|
-
Component
|
|
1233
|
+
Component,
|
|
1234
|
+
};
|
|
1398
1235
|
}
|
|
1399
1236
|
|
|
1400
1237
|
exports.AnimationType = void 0;
|
|
@@ -1449,13 +1286,12 @@ function useDomEvent(ref, eventName, handler, options) {
|
|
|
1449
1286
|
* @internal
|
|
1450
1287
|
*/
|
|
1451
1288
|
function useFocusGesture({ whileFocus, visualElement }) {
|
|
1289
|
+
const { animationState } = visualElement;
|
|
1452
1290
|
const onFocus = () => {
|
|
1453
|
-
|
|
1454
|
-
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(exports.AnimationType.Focus, true);
|
|
1291
|
+
animationState && animationState.setActive(exports.AnimationType.Focus, true);
|
|
1455
1292
|
};
|
|
1456
1293
|
const onBlur = () => {
|
|
1457
|
-
|
|
1458
|
-
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(exports.AnimationType.Focus, false);
|
|
1294
|
+
animationState && animationState.setActive(exports.AnimationType.Focus, false);
|
|
1459
1295
|
};
|
|
1460
1296
|
useDomEvent(visualElement, "focus", whileFocus ? onFocus : undefined);
|
|
1461
1297
|
useDomEvent(visualElement, "blur", whileFocus ? onBlur : undefined);
|
|
@@ -1610,14 +1446,15 @@ function isDragActive() {
|
|
|
1610
1446
|
|
|
1611
1447
|
function createHoverEvent(visualElement, isActive, callback) {
|
|
1612
1448
|
return (event, info) => {
|
|
1613
|
-
var _a;
|
|
1614
1449
|
if (!isMouseEvent(event) || isDragActive())
|
|
1615
1450
|
return;
|
|
1616
1451
|
/**
|
|
1617
1452
|
* Ensure we trigger animations before firing event callback
|
|
1618
1453
|
*/
|
|
1619
|
-
(
|
|
1620
|
-
|
|
1454
|
+
if (visualElement.animationState) {
|
|
1455
|
+
visualElement.animationState.setActive(exports.AnimationType.Hover, isActive);
|
|
1456
|
+
}
|
|
1457
|
+
callback && callback(event, info);
|
|
1621
1458
|
};
|
|
1622
1459
|
}
|
|
1623
1460
|
function useHoverGesture({ onHoverStart, onHoverEnd, whileHover, visualElement, }) {
|
|
@@ -1667,15 +1504,14 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
|
|
|
1667
1504
|
passive: !(onTapStart || onTap || onTapCancel || onPointerDown),
|
|
1668
1505
|
};
|
|
1669
1506
|
function removePointerEndListener() {
|
|
1670
|
-
|
|
1671
|
-
(_a = cancelPointerEndListeners.current) === null || _a === void 0 ? void 0 : _a.call(cancelPointerEndListeners);
|
|
1507
|
+
cancelPointerEndListeners.current && cancelPointerEndListeners.current();
|
|
1672
1508
|
cancelPointerEndListeners.current = null;
|
|
1673
1509
|
}
|
|
1674
1510
|
function checkPointerEnd() {
|
|
1675
|
-
var _a;
|
|
1676
1511
|
removePointerEndListener();
|
|
1677
1512
|
isPressing.current = false;
|
|
1678
|
-
|
|
1513
|
+
visualElement.animationState &&
|
|
1514
|
+
visualElement.animationState.setActive(exports.AnimationType.Tap, false);
|
|
1679
1515
|
return !isDragActive();
|
|
1680
1516
|
}
|
|
1681
1517
|
function onPointerUp(event, info) {
|
|
@@ -1686,16 +1522,15 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
|
|
|
1686
1522
|
* as, or a child of, this component's element
|
|
1687
1523
|
*/
|
|
1688
1524
|
!isNodeOrChild(visualElement.getInstance(), event.target)
|
|
1689
|
-
? onTapCancel
|
|
1690
|
-
: onTap
|
|
1525
|
+
? onTapCancel && onTapCancel(event, info)
|
|
1526
|
+
: onTap && onTap(event, info);
|
|
1691
1527
|
}
|
|
1692
1528
|
function onPointerCancel(event, info) {
|
|
1693
1529
|
if (!checkPointerEnd())
|
|
1694
1530
|
return;
|
|
1695
|
-
onTapCancel
|
|
1531
|
+
onTapCancel && onTapCancel(event, info);
|
|
1696
1532
|
}
|
|
1697
1533
|
function onPointerDown(event, info) {
|
|
1698
|
-
var _a;
|
|
1699
1534
|
removePointerEndListener();
|
|
1700
1535
|
if (isPressing.current)
|
|
1701
1536
|
return;
|
|
@@ -1704,13 +1539,22 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
|
|
|
1704
1539
|
/**
|
|
1705
1540
|
* Ensure we trigger animations before firing event callback
|
|
1706
1541
|
*/
|
|
1707
|
-
|
|
1708
|
-
|
|
1542
|
+
visualElement.animationState &&
|
|
1543
|
+
visualElement.animationState.setActive(exports.AnimationType.Tap, true);
|
|
1544
|
+
onTapStart && onTapStart(event, info);
|
|
1709
1545
|
}
|
|
1710
1546
|
usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined, eventOptions);
|
|
1711
1547
|
useUnmountEffect(removePointerEndListener);
|
|
1712
1548
|
}
|
|
1713
1549
|
|
|
1550
|
+
/**
|
|
1551
|
+
* Browser-safe usage of process
|
|
1552
|
+
*/
|
|
1553
|
+
const defaultEnvironment = "production";
|
|
1554
|
+
const env = typeof process === "undefined" || process.env === undefined
|
|
1555
|
+
? defaultEnvironment
|
|
1556
|
+
: process.env.NODE_ENV || defaultEnvironment;
|
|
1557
|
+
|
|
1714
1558
|
const warned = new Set();
|
|
1715
1559
|
function warnOnce(condition, message, element) {
|
|
1716
1560
|
if (condition || warned.has(message))
|
|
@@ -1734,14 +1578,13 @@ const observerCallbacks = new WeakMap();
|
|
|
1734
1578
|
*/
|
|
1735
1579
|
const observers = new WeakMap();
|
|
1736
1580
|
const fireObserverCallback = (entry) => {
|
|
1737
|
-
|
|
1738
|
-
|
|
1581
|
+
const callback = observerCallbacks.get(entry.target);
|
|
1582
|
+
callback && callback(entry);
|
|
1739
1583
|
};
|
|
1740
1584
|
const fireAllObserverCallbacks = (entries) => {
|
|
1741
1585
|
entries.forEach(fireObserverCallback);
|
|
1742
1586
|
};
|
|
1743
|
-
function initIntersectionObserver(
|
|
1744
|
-
var { root } = _a, options = tslib.__rest(_a, ["root"]);
|
|
1587
|
+
function initIntersectionObserver({ root, ...options }) {
|
|
1745
1588
|
const lookupRoot = root || document;
|
|
1746
1589
|
/**
|
|
1747
1590
|
* If we don't have an observer lookup map for this root, create one.
|
|
@@ -1756,7 +1599,7 @@ function initIntersectionObserver(_a) {
|
|
|
1756
1599
|
* create one.
|
|
1757
1600
|
*/
|
|
1758
1601
|
if (!rootObservers[key]) {
|
|
1759
|
-
rootObservers[key] = new IntersectionObserver(fireAllObserverCallbacks,
|
|
1602
|
+
rootObservers[key] = new IntersectionObserver(fireAllObserverCallbacks, { root, ...options });
|
|
1760
1603
|
}
|
|
1761
1604
|
return rootObservers[key];
|
|
1762
1605
|
}
|
|
@@ -1797,7 +1640,6 @@ function useIntersectionObserver(shouldObserve, state, visualElement, { root, ma
|
|
|
1797
1640
|
threshold: typeof amount === "number" ? amount : thresholdNames[amount],
|
|
1798
1641
|
};
|
|
1799
1642
|
const intersectionCallback = (entry) => {
|
|
1800
|
-
var _a;
|
|
1801
1643
|
const { isIntersecting } = entry;
|
|
1802
1644
|
/**
|
|
1803
1645
|
* If there's been no change in the viewport state, early return.
|
|
@@ -1815,7 +1657,9 @@ function useIntersectionObserver(shouldObserve, state, visualElement, { root, ma
|
|
|
1815
1657
|
else if (isIntersecting) {
|
|
1816
1658
|
state.hasEnteredView = true;
|
|
1817
1659
|
}
|
|
1818
|
-
(
|
|
1660
|
+
if (visualElement.animationState) {
|
|
1661
|
+
visualElement.animationState.setActive(exports.AnimationType.InView, isIntersecting);
|
|
1662
|
+
}
|
|
1819
1663
|
/**
|
|
1820
1664
|
* Use the latest committed props rather than the ones in scope
|
|
1821
1665
|
* when this observer is created
|
|
@@ -1824,7 +1668,7 @@ function useIntersectionObserver(shouldObserve, state, visualElement, { root, ma
|
|
|
1824
1668
|
const callback = isIntersecting
|
|
1825
1669
|
? props.onViewportEnter
|
|
1826
1670
|
: props.onViewportLeave;
|
|
1827
|
-
callback
|
|
1671
|
+
callback && callback(entry);
|
|
1828
1672
|
};
|
|
1829
1673
|
return observeIntersection(visualElement.getInstance(), options, intersectionCallback);
|
|
1830
1674
|
}, [shouldObserve, root, rootMargin, amount]);
|
|
@@ -1850,11 +1694,12 @@ function useMissingIntersectionObserver(shouldObserve, state, visualElement, { f
|
|
|
1850
1694
|
* is preferred to changing the behaviour of the animation state.
|
|
1851
1695
|
*/
|
|
1852
1696
|
requestAnimationFrame(() => {
|
|
1853
|
-
var _a;
|
|
1854
1697
|
state.hasEnteredView = true;
|
|
1855
1698
|
const { onViewportEnter } = visualElement.getProps();
|
|
1856
|
-
onViewportEnter
|
|
1857
|
-
(
|
|
1699
|
+
onViewportEnter && onViewportEnter(null);
|
|
1700
|
+
if (visualElement.animationState) {
|
|
1701
|
+
visualElement.animationState.setActive(exports.AnimationType.InView, true);
|
|
1702
|
+
}
|
|
1858
1703
|
});
|
|
1859
1704
|
}, [shouldObserve]);
|
|
1860
1705
|
}
|
|
@@ -1904,7 +1749,7 @@ function usePresence() {
|
|
|
1904
1749
|
// Replace with useId when released in React
|
|
1905
1750
|
const id = React.useId();
|
|
1906
1751
|
React.useEffect(() => register(id), []);
|
|
1907
|
-
const safeToRemove = () => onExitComplete
|
|
1752
|
+
const safeToRemove = () => onExitComplete && onExitComplete(id);
|
|
1908
1753
|
return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
|
|
1909
1754
|
}
|
|
1910
1755
|
/**
|
|
@@ -2063,17 +1908,29 @@ const getDefaultTransition = (valueKey, to) => {
|
|
|
2063
1908
|
transitionFactory =
|
|
2064
1909
|
defaultTransitions[valueKey] || defaultTransitions.default;
|
|
2065
1910
|
}
|
|
2066
|
-
return
|
|
1911
|
+
return { to, ...transitionFactory(to) };
|
|
2067
1912
|
};
|
|
2068
1913
|
|
|
2069
1914
|
/**
|
|
2070
1915
|
* A map of default value types for common values
|
|
2071
1916
|
*/
|
|
2072
|
-
const defaultValueTypes =
|
|
1917
|
+
const defaultValueTypes = {
|
|
1918
|
+
...numberValueTypes,
|
|
2073
1919
|
// Color props
|
|
2074
|
-
color: styleValueTypes.color,
|
|
1920
|
+
color: styleValueTypes.color,
|
|
1921
|
+
backgroundColor: styleValueTypes.color,
|
|
1922
|
+
outlineColor: styleValueTypes.color,
|
|
1923
|
+
fill: styleValueTypes.color,
|
|
1924
|
+
stroke: styleValueTypes.color,
|
|
2075
1925
|
// Border props
|
|
2076
|
-
borderColor: styleValueTypes.color,
|
|
1926
|
+
borderColor: styleValueTypes.color,
|
|
1927
|
+
borderTopColor: styleValueTypes.color,
|
|
1928
|
+
borderRightColor: styleValueTypes.color,
|
|
1929
|
+
borderBottomColor: styleValueTypes.color,
|
|
1930
|
+
borderLeftColor: styleValueTypes.color,
|
|
1931
|
+
filter: styleValueTypes.filter,
|
|
1932
|
+
WebkitFilter: styleValueTypes.filter,
|
|
1933
|
+
};
|
|
2077
1934
|
/**
|
|
2078
1935
|
* Gets the default ValueType for the provided value key
|
|
2079
1936
|
*/
|
|
@@ -2097,17 +1954,15 @@ const instantAnimationState = {
|
|
|
2097
1954
|
* This filters out orchestration options and returns true
|
|
2098
1955
|
* if any options are left.
|
|
2099
1956
|
*/
|
|
2100
|
-
function isTransitionDefined(
|
|
2101
|
-
var transition = tslib.__rest(_a, ["when", "delay", "delayChildren", "staggerChildren", "staggerDirection", "repeat", "repeatType", "repeatDelay", "from"]);
|
|
1957
|
+
function isTransitionDefined({ when, delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
|
|
2102
1958
|
return !!Object.keys(transition).length;
|
|
2103
1959
|
}
|
|
2104
1960
|
let legacyRepeatWarning = false;
|
|
2105
1961
|
/**
|
|
2106
1962
|
* Convert Framer Motion's Transition type into Popmotion-compatible options.
|
|
2107
1963
|
*/
|
|
2108
|
-
function convertTransitionToAnimationOptions(
|
|
2109
|
-
|
|
2110
|
-
const options = Object.assign({}, transition);
|
|
1964
|
+
function convertTransitionToAnimationOptions({ ease, times, yoyo, flip, loop, ...transition }) {
|
|
1965
|
+
const options = { ...transition };
|
|
2111
1966
|
if (times)
|
|
2112
1967
|
options["offset"] = times;
|
|
2113
1968
|
/**
|
|
@@ -2172,26 +2027,30 @@ function hydrateKeyframes(options) {
|
|
|
2172
2027
|
return options;
|
|
2173
2028
|
}
|
|
2174
2029
|
function getPopmotionAnimationOptions(transition, options, key) {
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
(_a = transition.duration) !== null && _a !== void 0 ? _a : (transition.duration = 0.8);
|
|
2030
|
+
if (Array.isArray(options.to) && transition.duration === undefined) {
|
|
2031
|
+
transition.duration = 0.8;
|
|
2178
2032
|
}
|
|
2179
2033
|
hydrateKeyframes(options);
|
|
2180
2034
|
/**
|
|
2181
2035
|
* Get a default transition if none is determined to be defined.
|
|
2182
2036
|
*/
|
|
2183
2037
|
if (!isTransitionDefined(transition)) {
|
|
2184
|
-
transition =
|
|
2038
|
+
transition = {
|
|
2039
|
+
...transition,
|
|
2040
|
+
...getDefaultTransition(key, options.to),
|
|
2041
|
+
};
|
|
2185
2042
|
}
|
|
2186
|
-
return
|
|
2043
|
+
return {
|
|
2044
|
+
...options,
|
|
2045
|
+
...convertTransitionToAnimationOptions(transition),
|
|
2046
|
+
};
|
|
2187
2047
|
}
|
|
2188
2048
|
/**
|
|
2189
2049
|
*
|
|
2190
2050
|
*/
|
|
2191
2051
|
function getAnimation(key, value, target, transition, onComplete) {
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
let origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
|
|
2052
|
+
const valueTransition = getValueTransition(transition, key) || {};
|
|
2053
|
+
let origin = valueTransition.from !== undefined ? valueTransition.from : value.get();
|
|
2195
2054
|
const isTargetAnimatable = isAnimatable(key, target);
|
|
2196
2055
|
if (origin === "none" && isTargetAnimatable && typeof target === "string") {
|
|
2197
2056
|
/**
|
|
@@ -2220,24 +2079,25 @@ function getAnimation(key, value, target, transition, onComplete) {
|
|
|
2220
2079
|
};
|
|
2221
2080
|
return valueTransition.type === "inertia" ||
|
|
2222
2081
|
valueTransition.type === "decay"
|
|
2223
|
-
? popmotion.inertia(
|
|
2224
|
-
: popmotion.animate(
|
|
2225
|
-
|
|
2082
|
+
? popmotion.inertia({ ...options, ...valueTransition })
|
|
2083
|
+
: popmotion.animate({
|
|
2084
|
+
...getPopmotionAnimationOptions(valueTransition, options, key),
|
|
2085
|
+
onUpdate: (v) => {
|
|
2226
2086
|
options.onUpdate(v);
|
|
2227
|
-
|
|
2228
|
-
},
|
|
2229
|
-
|
|
2087
|
+
valueTransition.onUpdate && valueTransition.onUpdate(v);
|
|
2088
|
+
},
|
|
2089
|
+
onComplete: () => {
|
|
2230
2090
|
options.onComplete();
|
|
2231
|
-
|
|
2232
|
-
}
|
|
2091
|
+
valueTransition.onComplete && valueTransition.onComplete();
|
|
2092
|
+
},
|
|
2093
|
+
});
|
|
2233
2094
|
}
|
|
2234
2095
|
function set() {
|
|
2235
|
-
var _a, _b;
|
|
2236
2096
|
const finalTarget = resolveFinalValueInKeyframes(target);
|
|
2237
2097
|
value.set(finalTarget);
|
|
2238
2098
|
onComplete();
|
|
2239
|
-
|
|
2240
|
-
|
|
2099
|
+
valueTransition.onUpdate && valueTransition.onUpdate(finalTarget);
|
|
2100
|
+
valueTransition.onComplete && valueTransition.onComplete();
|
|
2241
2101
|
return { stop: () => { } };
|
|
2242
2102
|
}
|
|
2243
2103
|
return !isOriginAnimatable ||
|
|
@@ -2282,7 +2142,7 @@ function startAnimation(key, value, target, transition = {}) {
|
|
|
2282
2142
|
}
|
|
2283
2143
|
return () => {
|
|
2284
2144
|
clearTimeout(delayTimer);
|
|
2285
|
-
controls
|
|
2145
|
+
controls && controls.stop();
|
|
2286
2146
|
};
|
|
2287
2147
|
});
|
|
2288
2148
|
}
|
|
@@ -2376,7 +2236,7 @@ class MotionValue {
|
|
|
2376
2236
|
* This will be replaced by the build step with the latest version number.
|
|
2377
2237
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
2378
2238
|
*/
|
|
2379
|
-
this.version = "7.
|
|
2239
|
+
this.version = "7.3.1";
|
|
2380
2240
|
/**
|
|
2381
2241
|
* Duration, in milliseconds, since last updating frame.
|
|
2382
2242
|
*
|
|
@@ -2685,6 +2545,27 @@ const valueTypes = [...dimensionValueTypes, styleValueTypes.color, styleValueTyp
|
|
|
2685
2545
|
*/
|
|
2686
2546
|
const findValueType = (v) => valueTypes.find(testValueType(v));
|
|
2687
2547
|
|
|
2548
|
+
/**
|
|
2549
|
+
* Creates an object containing the latest state of every MotionValue on a VisualElement
|
|
2550
|
+
*/
|
|
2551
|
+
function getCurrent(visualElement) {
|
|
2552
|
+
const current = {};
|
|
2553
|
+
visualElement.forEachValue((value, key) => (current[key] = value.get()));
|
|
2554
|
+
return current;
|
|
2555
|
+
}
|
|
2556
|
+
/**
|
|
2557
|
+
* Creates an object containing the latest velocity of every MotionValue on a VisualElement
|
|
2558
|
+
*/
|
|
2559
|
+
function getVelocity$1(visualElement) {
|
|
2560
|
+
const velocity = {};
|
|
2561
|
+
visualElement.forEachValue((value, key) => (velocity[key] = value.getVelocity()));
|
|
2562
|
+
return velocity;
|
|
2563
|
+
}
|
|
2564
|
+
function resolveVariant(visualElement, definition, custom) {
|
|
2565
|
+
const props = visualElement.getProps();
|
|
2566
|
+
return resolveVariantFromProps(props, definition, custom !== undefined ? custom : props.custom, getCurrent(visualElement), getVelocity$1(visualElement));
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2688
2569
|
/**
|
|
2689
2570
|
* Set VisualElement's MotionValue, creating a new MotionValue for it if
|
|
2690
2571
|
* it doesn't exist.
|
|
@@ -2699,8 +2580,8 @@ function setMotionValue(visualElement, key, value) {
|
|
|
2699
2580
|
}
|
|
2700
2581
|
function setTarget(visualElement, definition) {
|
|
2701
2582
|
const resolved = resolveVariant(visualElement, definition);
|
|
2702
|
-
let
|
|
2703
|
-
target =
|
|
2583
|
+
let { transitionEnd = {}, transition = {}, ...target } = resolved ? visualElement.makeTargetAnimatable(resolved, false) : {};
|
|
2584
|
+
target = { ...target, ...transitionEnd };
|
|
2704
2585
|
for (const key in target) {
|
|
2705
2586
|
const value = resolveFinalValueInKeyframes(target[key]);
|
|
2706
2587
|
setMotionValue(visualElement, key, value);
|
|
@@ -2729,8 +2610,7 @@ function setValues(visualElement, definition) {
|
|
|
2729
2610
|
}
|
|
2730
2611
|
}
|
|
2731
2612
|
function checkTargetForNewValues(visualElement, target, origin) {
|
|
2732
|
-
var _a, _b
|
|
2733
|
-
var _d;
|
|
2613
|
+
var _a, _b;
|
|
2734
2614
|
const newValueKeys = Object.keys(target).filter((key) => !visualElement.hasValue(key));
|
|
2735
2615
|
const numNewValues = newValueKeys.length;
|
|
2736
2616
|
if (!numNewValues)
|
|
@@ -2769,7 +2649,9 @@ function checkTargetForNewValues(visualElement, target, origin) {
|
|
|
2769
2649
|
value = getAnimatableNone(key, targetValue);
|
|
2770
2650
|
}
|
|
2771
2651
|
visualElement.addValue(key, motionValue(value));
|
|
2772
|
-
|
|
2652
|
+
if (origin[key] === undefined) {
|
|
2653
|
+
origin[key] = value;
|
|
2654
|
+
}
|
|
2773
2655
|
visualElement.setBaseTarget(key, value);
|
|
2774
2656
|
}
|
|
2775
2657
|
}
|
|
@@ -2780,11 +2662,14 @@ function getOriginFromTransition(key, transition) {
|
|
|
2780
2662
|
return valueTransition.from;
|
|
2781
2663
|
}
|
|
2782
2664
|
function getOrigin(target, transition, visualElement) {
|
|
2783
|
-
var _a
|
|
2665
|
+
var _a;
|
|
2784
2666
|
const origin = {};
|
|
2785
2667
|
for (const key in target) {
|
|
2668
|
+
const transitionOrigin = getOriginFromTransition(key, transition);
|
|
2786
2669
|
origin[key] =
|
|
2787
|
-
|
|
2670
|
+
transitionOrigin !== undefined
|
|
2671
|
+
? transitionOrigin
|
|
2672
|
+
: (_a = visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.get();
|
|
2788
2673
|
}
|
|
2789
2674
|
return origin;
|
|
2790
2675
|
}
|
|
@@ -2855,7 +2740,7 @@ function animateVariant(visualElement, variant, options = {}) {
|
|
|
2855
2740
|
*/
|
|
2856
2741
|
function animateTarget(visualElement, definition, { delay = 0, transitionOverride, type } = {}) {
|
|
2857
2742
|
var _a;
|
|
2858
|
-
let
|
|
2743
|
+
let { transition = visualElement.getDefaultTransition(), transitionEnd, ...target } = visualElement.makeTargetAnimatable(definition);
|
|
2859
2744
|
const willChange = visualElement.getValue("willChange");
|
|
2860
2745
|
if (transitionOverride)
|
|
2861
2746
|
transition = transitionOverride;
|
|
@@ -2870,12 +2755,16 @@ function animateTarget(visualElement, definition, { delay = 0, transitionOverrid
|
|
|
2870
2755
|
shouldBlockAnimation(animationTypeState, key))) {
|
|
2871
2756
|
continue;
|
|
2872
2757
|
}
|
|
2873
|
-
let valueTransition =
|
|
2758
|
+
let valueTransition = { delay, ...transition };
|
|
2874
2759
|
/**
|
|
2875
2760
|
* Make animation instant if this is a transform prop and we should reduce motion.
|
|
2876
2761
|
*/
|
|
2877
|
-
if (visualElement.shouldReduceMotion &&
|
|
2878
|
-
valueTransition =
|
|
2762
|
+
if (visualElement.shouldReduceMotion && transformProps.has(key)) {
|
|
2763
|
+
valueTransition = {
|
|
2764
|
+
...valueTransition,
|
|
2765
|
+
type: false,
|
|
2766
|
+
delay: 0,
|
|
2767
|
+
};
|
|
2879
2768
|
}
|
|
2880
2769
|
let animation = startAnimation(key, value, valueTarget, valueTransition);
|
|
2881
2770
|
if (isWillChangeMotionValue(willChange)) {
|
|
@@ -2897,7 +2786,10 @@ function animateChildren(visualElement, variant, delayChildren = 0, staggerChild
|
|
|
2897
2786
|
Array.from(visualElement.variantChildren)
|
|
2898
2787
|
.sort(sortByTreeOrder)
|
|
2899
2788
|
.forEach((child, i) => {
|
|
2900
|
-
animations.push(animateVariant(child, variant,
|
|
2789
|
+
animations.push(animateVariant(child, variant, {
|
|
2790
|
+
...options,
|
|
2791
|
+
delay: delayChildren + generateStaggerDuration(i),
|
|
2792
|
+
}).then(() => child.notifyAnimationComplete(variant)));
|
|
2901
2793
|
});
|
|
2902
2794
|
return Promise.all(animations);
|
|
2903
2795
|
}
|
|
@@ -2944,8 +2836,8 @@ function createAnimationState(visualElement) {
|
|
|
2944
2836
|
const buildResolvedTypeValues = (acc, definition) => {
|
|
2945
2837
|
const resolved = resolveVariant(visualElement, definition);
|
|
2946
2838
|
if (resolved) {
|
|
2947
|
-
const { transition, transitionEnd
|
|
2948
|
-
acc =
|
|
2839
|
+
const { transition, transitionEnd, ...target } = resolved;
|
|
2840
|
+
acc = { ...acc, ...target, ...transitionEnd };
|
|
2949
2841
|
}
|
|
2950
2842
|
return acc;
|
|
2951
2843
|
};
|
|
@@ -3028,7 +2920,7 @@ function createAnimationState(visualElement) {
|
|
|
3028
2920
|
* Set all encountered keys so far as the protected keys for this type. This will
|
|
3029
2921
|
* be any key that has been animated or otherwise handled by active, higher-priortiy types.
|
|
3030
2922
|
*/
|
|
3031
|
-
typeState.protectedKeys =
|
|
2923
|
+
typeState.protectedKeys = { ...encounteredKeys };
|
|
3032
2924
|
// Check if we can skip analysing this prop early
|
|
3033
2925
|
if (
|
|
3034
2926
|
// If it isn't active and hasn't *just* been set as inactive
|
|
@@ -3076,7 +2968,10 @@ function createAnimationState(visualElement) {
|
|
|
3076
2968
|
* needs adding to the type's protectedKeys list.
|
|
3077
2969
|
*/
|
|
3078
2970
|
const { prevResolvedValues = {} } = typeState;
|
|
3079
|
-
const allKeys =
|
|
2971
|
+
const allKeys = {
|
|
2972
|
+
...prevResolvedValues,
|
|
2973
|
+
...resolvedValues,
|
|
2974
|
+
};
|
|
3080
2975
|
const markToAnimate = (key) => {
|
|
3081
2976
|
shouldAnimateType = true;
|
|
3082
2977
|
removedKeys.delete(key);
|
|
@@ -3142,7 +3037,7 @@ function createAnimationState(visualElement) {
|
|
|
3142
3037
|
*
|
|
3143
3038
|
*/
|
|
3144
3039
|
if (typeState.isActive) {
|
|
3145
|
-
encounteredKeys =
|
|
3040
|
+
encounteredKeys = { ...encounteredKeys, ...resolvedValues };
|
|
3146
3041
|
}
|
|
3147
3042
|
if (isInitialRender && visualElement.blockInitialAnimation) {
|
|
3148
3043
|
shouldAnimateType = false;
|
|
@@ -3155,7 +3050,7 @@ function createAnimationState(visualElement) {
|
|
|
3155
3050
|
if (shouldAnimateType && !isInherited) {
|
|
3156
3051
|
animations.push(...definitionList.map((animation) => ({
|
|
3157
3052
|
animation: animation,
|
|
3158
|
-
options:
|
|
3053
|
+
options: { type, ...options },
|
|
3159
3054
|
})));
|
|
3160
3055
|
}
|
|
3161
3056
|
}
|
|
@@ -3211,7 +3106,7 @@ function checkVariantsDidChange(prev, next) {
|
|
|
3211
3106
|
if (typeof next === "string") {
|
|
3212
3107
|
return next !== prev;
|
|
3213
3108
|
}
|
|
3214
|
-
else if (
|
|
3109
|
+
else if (Array.isArray(next)) {
|
|
3215
3110
|
return !shallowCompare(next, prev);
|
|
3216
3111
|
}
|
|
3217
3112
|
return false;
|
|
@@ -3256,10 +3151,15 @@ const animations = {
|
|
|
3256
3151
|
const [isPresent, safeToRemove] = usePresence();
|
|
3257
3152
|
const presenceContext = React.useContext(PresenceContext);
|
|
3258
3153
|
React.useEffect(() => {
|
|
3259
|
-
var _a, _b;
|
|
3260
3154
|
visualElement.isPresent = isPresent;
|
|
3261
|
-
const animation =
|
|
3262
|
-
|
|
3155
|
+
const animation = visualElement.animationState &&
|
|
3156
|
+
visualElement.animationState.setActive(exports.AnimationType.Exit, !isPresent, {
|
|
3157
|
+
custom: (presenceContext && presenceContext.custom) ||
|
|
3158
|
+
custom,
|
|
3159
|
+
});
|
|
3160
|
+
if (animation && !isPresent) {
|
|
3161
|
+
animation.then(safeToRemove);
|
|
3162
|
+
}
|
|
3263
3163
|
}, [isPresent]);
|
|
3264
3164
|
}),
|
|
3265
3165
|
};
|
|
@@ -3298,7 +3198,7 @@ class PanSession {
|
|
|
3298
3198
|
return;
|
|
3299
3199
|
const { point } = info;
|
|
3300
3200
|
const { timestamp } = sync.getFrameData();
|
|
3301
|
-
this.history.push(
|
|
3201
|
+
this.history.push({ ...point, timestamp });
|
|
3302
3202
|
const { onStart, onMove } = this.handlers;
|
|
3303
3203
|
if (!isPanStarted) {
|
|
3304
3204
|
onStart && onStart(this.lastMoveEvent, info);
|
|
@@ -3335,7 +3235,7 @@ class PanSession {
|
|
|
3335
3235
|
const initialInfo = transformPoint(info, this.transformPagePoint);
|
|
3336
3236
|
const { point } = initialInfo;
|
|
3337
3237
|
const { timestamp } = sync.getFrameData();
|
|
3338
|
-
this.history = [
|
|
3238
|
+
this.history = [{ ...point, timestamp }];
|
|
3339
3239
|
const { onSessionStart } = handlers;
|
|
3340
3240
|
onSessionStart &&
|
|
3341
3241
|
onSessionStart(event, getPanInfo(initialInfo, this.history));
|
|
@@ -3980,8 +3880,17 @@ class VisualElementDragControls {
|
|
|
3980
3880
|
*/
|
|
3981
3881
|
const bounceStiffness = dragElastic ? 200 : 1000000;
|
|
3982
3882
|
const bounceDamping = dragElastic ? 40 : 10000000;
|
|
3983
|
-
const inertia =
|
|
3984
|
-
|
|
3883
|
+
const inertia = {
|
|
3884
|
+
type: "inertia",
|
|
3885
|
+
velocity: dragMomentum ? velocity[axis] : 0,
|
|
3886
|
+
bounceStiffness,
|
|
3887
|
+
bounceDamping,
|
|
3888
|
+
timeConstant: 750,
|
|
3889
|
+
restDelta: 1,
|
|
3890
|
+
restSpeed: 10,
|
|
3891
|
+
...dragTransition,
|
|
3892
|
+
...transition,
|
|
3893
|
+
};
|
|
3985
3894
|
// If we're not animating on an externally-provided `MotionValue` we can use the
|
|
3986
3895
|
// component's animation controls which will handle interactions with whileHover (etc),
|
|
3987
3896
|
// otherwise we just have to animate the `MotionValue` itself.
|
|
@@ -4133,12 +4042,15 @@ class VisualElementDragControls {
|
|
|
4133
4042
|
getProps() {
|
|
4134
4043
|
const props = this.visualElement.getProps();
|
|
4135
4044
|
const { drag = false, dragDirectionLock = false, dragPropagation = false, dragConstraints = false, dragElastic = defaultElastic, dragMomentum = true, } = props;
|
|
4136
|
-
return
|
|
4045
|
+
return {
|
|
4046
|
+
...props,
|
|
4047
|
+
drag,
|
|
4137
4048
|
dragDirectionLock,
|
|
4138
4049
|
dragPropagation,
|
|
4139
4050
|
dragConstraints,
|
|
4140
4051
|
dragElastic,
|
|
4141
|
-
dragMomentum
|
|
4052
|
+
dragMomentum,
|
|
4053
|
+
};
|
|
4142
4054
|
}
|
|
4143
4055
|
}
|
|
4144
4056
|
function shouldDrag(direction, drag, currentDirection) {
|
|
@@ -4222,6 +4134,25 @@ const drag = {
|
|
|
4222
4134
|
drag: makeRenderlessComponent(useDrag),
|
|
4223
4135
|
};
|
|
4224
4136
|
|
|
4137
|
+
// Does this device prefer reduced motion? Returns `null` server-side.
|
|
4138
|
+
const prefersReducedMotion = { current: null };
|
|
4139
|
+
const hasReducedMotionListener = { current: false };
|
|
4140
|
+
|
|
4141
|
+
function initPrefersReducedMotion() {
|
|
4142
|
+
hasReducedMotionListener.current = true;
|
|
4143
|
+
if (!isBrowser)
|
|
4144
|
+
return;
|
|
4145
|
+
if (window.matchMedia) {
|
|
4146
|
+
const motionMediaQuery = window.matchMedia("(prefers-reduced-motion)");
|
|
4147
|
+
const setReducedMotionPreferences = () => (prefersReducedMotion.current = motionMediaQuery.matches);
|
|
4148
|
+
motionMediaQuery.addListener(setReducedMotionPreferences);
|
|
4149
|
+
setReducedMotionPreferences();
|
|
4150
|
+
}
|
|
4151
|
+
else {
|
|
4152
|
+
prefersReducedMotion.current = false;
|
|
4153
|
+
}
|
|
4154
|
+
}
|
|
4155
|
+
|
|
4225
4156
|
const names = [
|
|
4226
4157
|
"LayoutMeasure",
|
|
4227
4158
|
"BeforeLayoutMeasure",
|
|
@@ -4263,7 +4194,6 @@ function createLifecycles() {
|
|
|
4263
4194
|
}
|
|
4264
4195
|
|
|
4265
4196
|
function updateMotionValuesFromProps(element, next, prev) {
|
|
4266
|
-
var _a;
|
|
4267
4197
|
const { willChange } = next;
|
|
4268
4198
|
for (const key in next) {
|
|
4269
4199
|
const nextValue = next[key];
|
|
@@ -4282,7 +4212,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
4282
4212
|
* and warn against mismatches.
|
|
4283
4213
|
*/
|
|
4284
4214
|
if (process.env.NODE_ENV === "development") {
|
|
4285
|
-
warnOnce(nextValue.version === "7.
|
|
4215
|
+
warnOnce(nextValue.version === "7.3.1", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.3.1 may not work as expected.`);
|
|
4286
4216
|
}
|
|
4287
4217
|
}
|
|
4288
4218
|
else if (isMotionValue(prevValue)) {
|
|
@@ -4307,7 +4237,8 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
4307
4237
|
!existingValue.hasAnimated && existingValue.set(nextValue);
|
|
4308
4238
|
}
|
|
4309
4239
|
else {
|
|
4310
|
-
|
|
4240
|
+
const latestValue = element.getStaticValue(key);
|
|
4241
|
+
element.addValue(key, motionValue(latestValue !== undefined ? latestValue : nextValue));
|
|
4311
4242
|
}
|
|
4312
4243
|
}
|
|
4313
4244
|
}
|
|
@@ -4319,7 +4250,9 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
4319
4250
|
return next;
|
|
4320
4251
|
}
|
|
4321
4252
|
|
|
4322
|
-
const
|
|
4253
|
+
const featureNames = Object.keys(featureDefinitions);
|
|
4254
|
+
const numFeatures = featureNames.length;
|
|
4255
|
+
const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatable, measureViewportBox, render: renderInstance, readValueFromInstance, removeValueFromRenderState, sortNodePosition, scrapeMotionValuesFromProps, }) => ({ parent, props, presenceId, blockInitialAnimation, visualState, reducedMotionConfig, }, options = {}) => {
|
|
4323
4256
|
let isMounted = false;
|
|
4324
4257
|
const { latestValues, renderState } = visualState;
|
|
4325
4258
|
/**
|
|
@@ -4355,7 +4288,9 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4355
4288
|
* When values are removed from all animation props we need to search
|
|
4356
4289
|
* for a fallback value to animate to. These values are tracked in baseTarget.
|
|
4357
4290
|
*/
|
|
4358
|
-
const baseTarget =
|
|
4291
|
+
const baseTarget = {
|
|
4292
|
+
...latestValues,
|
|
4293
|
+
};
|
|
4359
4294
|
// Internal methods ========================
|
|
4360
4295
|
/**
|
|
4361
4296
|
* On mount, this will be hydrated with a callback to disconnect
|
|
@@ -4402,7 +4337,7 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4402
4337
|
* Doing so will break some tests but this isn't neccessarily a breaking change,
|
|
4403
4338
|
* more a reflection of the test.
|
|
4404
4339
|
*/
|
|
4405
|
-
const
|
|
4340
|
+
const { willChange, ...initialMotionValues } = scrapeMotionValuesFromProps(props);
|
|
4406
4341
|
for (const key in initialMotionValues) {
|
|
4407
4342
|
const value = initialMotionValues[key];
|
|
4408
4343
|
if (latestValues[key] !== undefined && isMotionValue(value)) {
|
|
@@ -4415,36 +4350,39 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4415
4350
|
/**
|
|
4416
4351
|
* Determine what role this visual element should take in the variant tree.
|
|
4417
4352
|
*/
|
|
4418
|
-
const isControllingVariants =
|
|
4419
|
-
const isVariantNode =
|
|
4420
|
-
const element =
|
|
4353
|
+
const isControllingVariants$1 = isControllingVariants(props);
|
|
4354
|
+
const isVariantNode$1 = isVariantNode(props);
|
|
4355
|
+
const element = {
|
|
4356
|
+
treeType,
|
|
4421
4357
|
/**
|
|
4422
4358
|
* This is a mirror of the internal instance prop, which keeps
|
|
4423
4359
|
* VisualElement type-compatible with React's RefObject.
|
|
4424
4360
|
*/
|
|
4425
|
-
current: null,
|
|
4361
|
+
current: null,
|
|
4426
4362
|
/**
|
|
4427
4363
|
* The depth of this visual element within the visual element tree.
|
|
4428
4364
|
*/
|
|
4429
|
-
depth: parent ? parent.depth + 1 : 0,
|
|
4365
|
+
depth: parent ? parent.depth + 1 : 0,
|
|
4366
|
+
parent,
|
|
4367
|
+
children: new Set(),
|
|
4430
4368
|
/**
|
|
4431
4369
|
*
|
|
4432
4370
|
*/
|
|
4433
4371
|
presenceId,
|
|
4434
|
-
shouldReduceMotion,
|
|
4372
|
+
shouldReduceMotion: null,
|
|
4435
4373
|
/**
|
|
4436
4374
|
* If this component is part of the variant tree, it should track
|
|
4437
4375
|
* any children that are also part of the tree. This is essentially
|
|
4438
4376
|
* a shadow tree to simplify logic around how to stagger over children.
|
|
4439
4377
|
*/
|
|
4440
|
-
variantChildren: isVariantNode ? new Set() : undefined,
|
|
4378
|
+
variantChildren: isVariantNode$1 ? new Set() : undefined,
|
|
4441
4379
|
/**
|
|
4442
4380
|
* Whether this instance is visible. This can be changed imperatively
|
|
4443
4381
|
* by the projection tree, is analogous to CSS's visibility in that
|
|
4444
4382
|
* hidden elements should take up layout, and needs enacting by the configured
|
|
4445
4383
|
* render function.
|
|
4446
4384
|
*/
|
|
4447
|
-
isVisible: undefined,
|
|
4385
|
+
isVisible: undefined,
|
|
4448
4386
|
/**
|
|
4449
4387
|
* Normally, if a component is controlled by a parent's variants, it can
|
|
4450
4388
|
* rely on that ancestor to trigger animations further down the tree.
|
|
@@ -4453,27 +4391,37 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4453
4391
|
*
|
|
4454
4392
|
* TODO: This might be better replaced with a method isParentMounted
|
|
4455
4393
|
*/
|
|
4456
|
-
manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
|
|
4394
|
+
manuallyAnimateOnMount: Boolean(parent === null || parent === void 0 ? void 0 : parent.isMounted()),
|
|
4457
4395
|
/**
|
|
4458
4396
|
* This can be set by AnimatePresence to force components that mount
|
|
4459
4397
|
* at the same time as it to mount as if they have initial={false} set.
|
|
4460
4398
|
*/
|
|
4461
|
-
blockInitialAnimation,
|
|
4399
|
+
blockInitialAnimation,
|
|
4462
4400
|
/**
|
|
4463
4401
|
* Determine whether this component has mounted yet. This is mostly used
|
|
4464
4402
|
* by variant children to determine whether they need to trigger their
|
|
4465
4403
|
* own animations on mount.
|
|
4466
4404
|
*/
|
|
4467
|
-
isMounted: () => Boolean(instance),
|
|
4405
|
+
isMounted: () => Boolean(instance),
|
|
4406
|
+
mount(newInstance) {
|
|
4468
4407
|
isMounted = true;
|
|
4469
4408
|
instance = element.current = newInstance;
|
|
4470
4409
|
if (element.projection) {
|
|
4471
4410
|
element.projection.mount(newInstance);
|
|
4472
4411
|
}
|
|
4473
|
-
if (isVariantNode && parent && !isControllingVariants) {
|
|
4412
|
+
if (isVariantNode$1 && parent && !isControllingVariants$1) {
|
|
4474
4413
|
removeFromVariantTree = parent === null || parent === void 0 ? void 0 : parent.addVariantChild(element);
|
|
4475
4414
|
}
|
|
4476
4415
|
values.forEach((value, key) => bindToMotionValue(key, value));
|
|
4416
|
+
if (!hasReducedMotionListener.current) {
|
|
4417
|
+
initPrefersReducedMotion();
|
|
4418
|
+
}
|
|
4419
|
+
element.shouldReduceMotion =
|
|
4420
|
+
reducedMotionConfig === "never"
|
|
4421
|
+
? false
|
|
4422
|
+
: reducedMotionConfig === "always"
|
|
4423
|
+
? true
|
|
4424
|
+
: prefersReducedMotion.current;
|
|
4477
4425
|
parent === null || parent === void 0 ? void 0 : parent.children.add(element);
|
|
4478
4426
|
element.setProps(props);
|
|
4479
4427
|
},
|
|
@@ -4492,6 +4440,55 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4492
4440
|
instance = undefined;
|
|
4493
4441
|
isMounted = false;
|
|
4494
4442
|
},
|
|
4443
|
+
loadFeatures(renderedProps, isStrict, preloadedFeatures, projectionId, ProjectionNodeConstructor, initialLayoutGroupConfig) {
|
|
4444
|
+
const features = [];
|
|
4445
|
+
/**
|
|
4446
|
+
* If we're in development mode, check to make sure we're not rendering a motion component
|
|
4447
|
+
* as a child of LazyMotion, as this will break the file-size benefits of using it.
|
|
4448
|
+
*/
|
|
4449
|
+
if (env !== "production" && preloadedFeatures && isStrict) {
|
|
4450
|
+
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.");
|
|
4451
|
+
}
|
|
4452
|
+
for (let i = 0; i < numFeatures; i++) {
|
|
4453
|
+
const name = featureNames[i];
|
|
4454
|
+
const { isEnabled, Component } = featureDefinitions[name];
|
|
4455
|
+
/**
|
|
4456
|
+
* It might be possible in the future to use this moment to
|
|
4457
|
+
* dynamically request functionality. In initial tests this
|
|
4458
|
+
* was producing a lot of duplication amongst bundles.
|
|
4459
|
+
*/
|
|
4460
|
+
if (isEnabled(props) && Component) {
|
|
4461
|
+
features.push(React.createElement(Component, {
|
|
4462
|
+
key: name,
|
|
4463
|
+
...renderedProps,
|
|
4464
|
+
visualElement: element,
|
|
4465
|
+
}));
|
|
4466
|
+
}
|
|
4467
|
+
}
|
|
4468
|
+
if (!element.projection && ProjectionNodeConstructor) {
|
|
4469
|
+
element.projection = new ProjectionNodeConstructor(projectionId, element.getLatestValues(), parent && parent.projection);
|
|
4470
|
+
const { layoutId, layout, drag, dragConstraints, layoutScroll, } = renderedProps;
|
|
4471
|
+
element.projection.setOptions({
|
|
4472
|
+
layoutId,
|
|
4473
|
+
layout,
|
|
4474
|
+
alwaysMeasureLayout: Boolean(drag) ||
|
|
4475
|
+
(dragConstraints && isRefObject(dragConstraints)),
|
|
4476
|
+
visualElement: element,
|
|
4477
|
+
scheduleRender: () => element.scheduleRender(),
|
|
4478
|
+
/**
|
|
4479
|
+
* TODO: Update options in an effect. This could be tricky as it'll be too late
|
|
4480
|
+
* to update by the time layout animations run.
|
|
4481
|
+
* We also need to fix this safeToRemove by linking it up to the one returned by usePresence,
|
|
4482
|
+
* ensuring it gets called if there's no potential layout animations.
|
|
4483
|
+
*
|
|
4484
|
+
*/
|
|
4485
|
+
animationType: typeof layout === "string" ? layout : "both",
|
|
4486
|
+
initialPromotionConfig: initialLayoutGroupConfig,
|
|
4487
|
+
layoutScroll,
|
|
4488
|
+
});
|
|
4489
|
+
}
|
|
4490
|
+
return features;
|
|
4491
|
+
},
|
|
4495
4492
|
/**
|
|
4496
4493
|
* Add a child visual element to our set of children.
|
|
4497
4494
|
*/
|
|
@@ -4510,30 +4507,31 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4510
4507
|
if (!sortNodePosition || treeType !== other.treeType)
|
|
4511
4508
|
return 0;
|
|
4512
4509
|
return sortNodePosition(element.getInstance(), other.getInstance());
|
|
4513
|
-
},
|
|
4510
|
+
},
|
|
4514
4511
|
/**
|
|
4515
4512
|
* Returns the closest variant node in the tree starting from
|
|
4516
4513
|
* this visual element.
|
|
4517
4514
|
*/
|
|
4518
|
-
getClosestVariantNode: () => isVariantNode ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
|
|
4515
|
+
getClosestVariantNode: () => isVariantNode$1 ? element : parent === null || parent === void 0 ? void 0 : parent.getClosestVariantNode(),
|
|
4519
4516
|
/**
|
|
4520
4517
|
* Expose the latest layoutId prop.
|
|
4521
4518
|
*/
|
|
4522
|
-
getLayoutId: () => props.layoutId,
|
|
4519
|
+
getLayoutId: () => props.layoutId,
|
|
4523
4520
|
/**
|
|
4524
4521
|
* Returns the current instance.
|
|
4525
4522
|
*/
|
|
4526
|
-
getInstance: () => instance,
|
|
4523
|
+
getInstance: () => instance,
|
|
4527
4524
|
/**
|
|
4528
4525
|
* Get/set the latest static values.
|
|
4529
4526
|
*/
|
|
4530
|
-
getStaticValue: (key) => latestValues[key],
|
|
4527
|
+
getStaticValue: (key) => latestValues[key],
|
|
4528
|
+
setStaticValue: (key, value) => (latestValues[key] = value),
|
|
4531
4529
|
/**
|
|
4532
4530
|
* Returns the latest motion value state. Currently only used to take
|
|
4533
4531
|
* a snapshot of the visual element - perhaps this can return the whole
|
|
4534
4532
|
* visual state
|
|
4535
4533
|
*/
|
|
4536
|
-
getLatestValues: () => latestValues,
|
|
4534
|
+
getLatestValues: () => latestValues,
|
|
4537
4535
|
/**
|
|
4538
4536
|
* Set the visiblity of the visual element. If it's changed, schedule
|
|
4539
4537
|
* a render to reflect these changes.
|
|
@@ -4584,11 +4582,11 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4584
4582
|
valueSubscriptions.delete(key);
|
|
4585
4583
|
delete latestValues[key];
|
|
4586
4584
|
removeValueFromRenderState(key, renderState);
|
|
4587
|
-
},
|
|
4585
|
+
},
|
|
4588
4586
|
/**
|
|
4589
4587
|
* Check whether we have a motion value for this key
|
|
4590
4588
|
*/
|
|
4591
|
-
hasValue: (key) => values.has(key),
|
|
4589
|
+
hasValue: (key) => values.has(key),
|
|
4592
4590
|
/**
|
|
4593
4591
|
* Get a motion value for this key. If called with a default
|
|
4594
4592
|
* value, we'll create one if none exists.
|
|
@@ -4600,20 +4598,19 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4600
4598
|
element.addValue(key, value);
|
|
4601
4599
|
}
|
|
4602
4600
|
return value;
|
|
4603
|
-
},
|
|
4601
|
+
},
|
|
4604
4602
|
/**
|
|
4605
4603
|
* Iterate over our motion values.
|
|
4606
4604
|
*/
|
|
4607
|
-
forEachValue: (callback) => values.forEach(callback),
|
|
4605
|
+
forEachValue: (callback) => values.forEach(callback),
|
|
4608
4606
|
/**
|
|
4609
4607
|
* If we're trying to animate to a previously unencountered value,
|
|
4610
4608
|
* we need to check for it in our state and as a last resort read it
|
|
4611
4609
|
* directly from the instance (which might have performance implications).
|
|
4612
4610
|
*/
|
|
4613
|
-
readValue: (key) =>
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
},
|
|
4611
|
+
readValue: (key) => latestValues[key] !== undefined
|
|
4612
|
+
? latestValues[key]
|
|
4613
|
+
: readValueFromInstance(instance, key, options),
|
|
4617
4614
|
/**
|
|
4618
4615
|
* Set the base target to later animate back to. This is currently
|
|
4619
4616
|
* only hydrated on creation and when we first read a value.
|
|
@@ -4632,7 +4629,9 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4632
4629
|
return target;
|
|
4633
4630
|
}
|
|
4634
4631
|
return baseTarget[key];
|
|
4635
|
-
}
|
|
4632
|
+
},
|
|
4633
|
+
// Lifecyles ========================
|
|
4634
|
+
...lifecycles,
|
|
4636
4635
|
/**
|
|
4637
4636
|
* Build the renderer state based on the latest visual state.
|
|
4638
4637
|
*/
|
|
@@ -4645,14 +4644,14 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4645
4644
|
*/
|
|
4646
4645
|
scheduleRender() {
|
|
4647
4646
|
sync__default["default"].render(render, false, true);
|
|
4648
|
-
},
|
|
4647
|
+
},
|
|
4649
4648
|
/**
|
|
4650
4649
|
* Synchronously fire render. It's prefered that we batch renders but
|
|
4651
4650
|
* in many circumstances, like layout measurement, we need to run this
|
|
4652
4651
|
* synchronously. However in those instances other measures should be taken
|
|
4653
4652
|
* to batch reads/writes.
|
|
4654
4653
|
*/
|
|
4655
|
-
syncRender: render,
|
|
4654
|
+
syncRender: render,
|
|
4656
4655
|
/**
|
|
4657
4656
|
* Update the provided props. Ensure any newly-added motion values are
|
|
4658
4657
|
* added to our map, old ones removed, and listeners updated.
|
|
@@ -4664,25 +4663,27 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4664
4663
|
props = newProps;
|
|
4665
4664
|
lifecycles.updatePropListeners(newProps);
|
|
4666
4665
|
prevMotionValues = updateMotionValuesFromProps(element, scrapeMotionValuesFromProps(props), prevMotionValues);
|
|
4667
|
-
},
|
|
4666
|
+
},
|
|
4667
|
+
getProps: () => props,
|
|
4668
4668
|
// Variants ==============================
|
|
4669
4669
|
/**
|
|
4670
4670
|
* Returns the variant definition with a given name.
|
|
4671
4671
|
*/
|
|
4672
|
-
getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
4672
|
+
getVariant: (name) => { var _a; return (_a = props.variants) === null || _a === void 0 ? void 0 : _a[name]; },
|
|
4673
4673
|
/**
|
|
4674
4674
|
* Returns the defined default transition on this component.
|
|
4675
4675
|
*/
|
|
4676
|
-
getDefaultTransition: () => props.transition,
|
|
4676
|
+
getDefaultTransition: () => props.transition,
|
|
4677
|
+
getTransformPagePoint: () => {
|
|
4677
4678
|
return props.transformPagePoint;
|
|
4678
|
-
},
|
|
4679
|
+
},
|
|
4679
4680
|
/**
|
|
4680
4681
|
* Used by child variant nodes to get the closest ancestor variant props.
|
|
4681
4682
|
*/
|
|
4682
4683
|
getVariantContext(startAtParent = false) {
|
|
4683
4684
|
if (startAtParent)
|
|
4684
4685
|
return parent === null || parent === void 0 ? void 0 : parent.getVariantContext();
|
|
4685
|
-
if (!isControllingVariants) {
|
|
4686
|
+
if (!isControllingVariants$1) {
|
|
4686
4687
|
const context = (parent === null || parent === void 0 ? void 0 : parent.getVariantContext()) || {};
|
|
4687
4688
|
if (props.initial !== undefined) {
|
|
4688
4689
|
context.initial = props.initial;
|
|
@@ -4698,7 +4699,8 @@ const visualElement = ({ treeType = "", build, getBaseTarget, makeTargetAnimatab
|
|
|
4698
4699
|
}
|
|
4699
4700
|
}
|
|
4700
4701
|
return context;
|
|
4701
|
-
}
|
|
4702
|
+
},
|
|
4703
|
+
};
|
|
4702
4704
|
return element;
|
|
4703
4705
|
};
|
|
4704
4706
|
const variantProps = ["initial", ...variantPriorityOrder];
|
|
@@ -4749,16 +4751,14 @@ function getVariableValue(current, element, depth = 1) {
|
|
|
4749
4751
|
*
|
|
4750
4752
|
* @internal
|
|
4751
4753
|
*/
|
|
4752
|
-
function resolveCSSVariables(visualElement,
|
|
4753
|
-
var _b;
|
|
4754
|
-
var target = tslib.__rest(_a, []);
|
|
4754
|
+
function resolveCSSVariables(visualElement, { ...target }, transitionEnd) {
|
|
4755
4755
|
const element = visualElement.getInstance();
|
|
4756
4756
|
if (!(element instanceof Element))
|
|
4757
4757
|
return { target, transitionEnd };
|
|
4758
4758
|
// If `transitionEnd` isn't `undefined`, clone it. We could clone `target` and `transitionEnd`
|
|
4759
4759
|
// only if they change but I think this reads clearer and this isn't a performance-critical path.
|
|
4760
4760
|
if (transitionEnd) {
|
|
4761
|
-
transitionEnd =
|
|
4761
|
+
transitionEnd = { ...transitionEnd };
|
|
4762
4762
|
}
|
|
4763
4763
|
// Go through existing `MotionValue`s and ensure any existing CSS variables are resolved
|
|
4764
4764
|
visualElement.forEachValue((value) => {
|
|
@@ -4783,8 +4783,9 @@ function resolveCSSVariables(visualElement, _a, transitionEnd) {
|
|
|
4783
4783
|
// If the user hasn't already set this key on `transitionEnd`, set it to the unresolved
|
|
4784
4784
|
// CSS variable. This will ensure that after the animation the component will reflect
|
|
4785
4785
|
// changes in the value of the CSS variable.
|
|
4786
|
-
if (transitionEnd)
|
|
4787
|
-
|
|
4786
|
+
if (transitionEnd && transitionEnd[key] === undefined) {
|
|
4787
|
+
transitionEnd[key] = current;
|
|
4788
|
+
}
|
|
4788
4789
|
}
|
|
4789
4790
|
return { target, transitionEnd };
|
|
4790
4791
|
}
|
|
@@ -4838,7 +4839,7 @@ const getTranslateFromMatrix = (pos2, pos3) => (_bbox, { transform }) => {
|
|
|
4838
4839
|
}
|
|
4839
4840
|
};
|
|
4840
4841
|
const transformKeys = new Set(["x", "y", "z"]);
|
|
4841
|
-
const nonTranslationalTransformKeys =
|
|
4842
|
+
const nonTranslationalTransformKeys = transformPropOrder.filter((key) => !transformKeys.has(key));
|
|
4842
4843
|
function removeNonTranslationalTransform(visualElement) {
|
|
4843
4844
|
const removedTransforms = [];
|
|
4844
4845
|
nonTranslationalTransformKeys.forEach((key) => {
|
|
@@ -4895,8 +4896,8 @@ const convertChangedValueTypes = (target, visualElement, changedKeys) => {
|
|
|
4895
4896
|
return target;
|
|
4896
4897
|
};
|
|
4897
4898
|
const checkAndConvertChangedValueTypes = (visualElement, target, origin = {}, transitionEnd = {}) => {
|
|
4898
|
-
target =
|
|
4899
|
-
transitionEnd =
|
|
4899
|
+
target = { ...target };
|
|
4900
|
+
transitionEnd = { ...transitionEnd };
|
|
4900
4901
|
const targetPositionalKeys = Object.keys(target).filter(isPositionalKey);
|
|
4901
4902
|
// We want to remove any transform values that could affect the element's bounding box before
|
|
4902
4903
|
// it's measured. We'll reapply these later.
|
|
@@ -5031,7 +5032,7 @@ function getComputedStyle$1(element) {
|
|
|
5031
5032
|
const htmlConfig = {
|
|
5032
5033
|
treeType: "dom",
|
|
5033
5034
|
readValueFromInstance(domElement, key) {
|
|
5034
|
-
if (
|
|
5035
|
+
if (transformProps.has(key)) {
|
|
5035
5036
|
const defaultType = getDefaultValueType(key);
|
|
5036
5037
|
return defaultType ? defaultType.default || 0 : 0;
|
|
5037
5038
|
}
|
|
@@ -5084,10 +5085,7 @@ const htmlConfig = {
|
|
|
5084
5085
|
* Ensure that HTML and Framer-specific value types like `px`->`%` and `Color`
|
|
5085
5086
|
* can be animated by Motion.
|
|
5086
5087
|
*/
|
|
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; }
|
|
5088
|
+
makeTargetAnimatable(element, { transition, transitionEnd, ...target }, { transformValues }, isMounted = true) {
|
|
5091
5089
|
let origin = getOrigin(target, transition || {}, element);
|
|
5092
5090
|
/**
|
|
5093
5091
|
* If Framer has provided a function to convert `Color` etc value types, convert them
|
|
@@ -5106,8 +5104,11 @@ const htmlConfig = {
|
|
|
5106
5104
|
transitionEnd = parsed.transitionEnd;
|
|
5107
5105
|
target = parsed.target;
|
|
5108
5106
|
}
|
|
5109
|
-
return
|
|
5110
|
-
|
|
5107
|
+
return {
|
|
5108
|
+
transition,
|
|
5109
|
+
transitionEnd,
|
|
5110
|
+
...target,
|
|
5111
|
+
};
|
|
5111
5112
|
},
|
|
5112
5113
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps$1,
|
|
5113
5114
|
build(element, renderState, latestValues, options, props) {
|
|
@@ -5122,12 +5123,14 @@ const htmlConfig = {
|
|
|
5122
5123
|
};
|
|
5123
5124
|
const htmlVisualElement = visualElement(htmlConfig);
|
|
5124
5125
|
|
|
5125
|
-
const svgVisualElement = visualElement(
|
|
5126
|
+
const svgVisualElement = visualElement({
|
|
5127
|
+
...htmlConfig,
|
|
5128
|
+
getBaseTarget(props, key) {
|
|
5126
5129
|
return props[key];
|
|
5127
5130
|
},
|
|
5128
5131
|
readValueFromInstance(domElement, key) {
|
|
5129
5132
|
var _a;
|
|
5130
|
-
if (
|
|
5133
|
+
if (transformProps.has(key)) {
|
|
5131
5134
|
return ((_a = getDefaultValueType(key)) === null || _a === void 0 ? void 0 : _a.default) || 0;
|
|
5132
5135
|
}
|
|
5133
5136
|
key = !camelCaseAttributes.has(key) ? camelToDash(key) : key;
|
|
@@ -5136,7 +5139,9 @@ const svgVisualElement = visualElement(Object.assign(Object.assign({}, htmlConfi
|
|
|
5136
5139
|
scrapeMotionValuesFromProps,
|
|
5137
5140
|
build(_element, renderState, latestValues, options, props) {
|
|
5138
5141
|
buildSVGAttrs(renderState, latestValues, options, props.transformTemplate);
|
|
5139
|
-
},
|
|
5142
|
+
},
|
|
5143
|
+
render: renderSVG,
|
|
5144
|
+
});
|
|
5140
5145
|
|
|
5141
5146
|
const createDomVisualElement = (Component, options) => {
|
|
5142
5147
|
return isSVGComponent(Component)
|
|
@@ -5245,16 +5250,19 @@ class MeasureLayoutWithContext extends React__default["default"].Component {
|
|
|
5245
5250
|
const { projection } = visualElement;
|
|
5246
5251
|
addScaleCorrector(defaultScaleCorrectors);
|
|
5247
5252
|
if (projection) {
|
|
5248
|
-
if (layoutGroup
|
|
5253
|
+
if (layoutGroup.group)
|
|
5249
5254
|
layoutGroup.group.add(projection);
|
|
5250
|
-
if (
|
|
5255
|
+
if (switchLayoutGroup && switchLayoutGroup.register && layoutId) {
|
|
5251
5256
|
switchLayoutGroup.register(projection);
|
|
5252
5257
|
}
|
|
5253
5258
|
projection.root.didUpdate();
|
|
5254
5259
|
projection.addEventListener("animationComplete", () => {
|
|
5255
5260
|
this.safeToRemove();
|
|
5256
5261
|
});
|
|
5257
|
-
projection.setOptions(
|
|
5262
|
+
projection.setOptions({
|
|
5263
|
+
...projection.options,
|
|
5264
|
+
onExitComplete: () => this.safeToRemove(),
|
|
5265
|
+
});
|
|
5258
5266
|
}
|
|
5259
5267
|
globalProjectionState.hasEverUpdated = true;
|
|
5260
5268
|
}
|
|
@@ -5330,15 +5338,18 @@ class MeasureLayoutWithContext extends React__default["default"].Component {
|
|
|
5330
5338
|
function MeasureLayout(props) {
|
|
5331
5339
|
const [isPresent, safeToRemove] = usePresence();
|
|
5332
5340
|
const layoutGroup = React.useContext(LayoutGroupContext);
|
|
5333
|
-
return (React__default["default"].createElement(MeasureLayoutWithContext,
|
|
5341
|
+
return (React__default["default"].createElement(MeasureLayoutWithContext, { ...props, layoutGroup: layoutGroup, switchLayoutGroup: React.useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove }));
|
|
5334
5342
|
}
|
|
5335
5343
|
const defaultScaleCorrectors = {
|
|
5336
|
-
borderRadius:
|
|
5344
|
+
borderRadius: {
|
|
5345
|
+
...correctBorderRadius,
|
|
5346
|
+
applyTo: [
|
|
5337
5347
|
"borderTopLeftRadius",
|
|
5338
5348
|
"borderTopRightRadius",
|
|
5339
5349
|
"borderBottomLeftRadius",
|
|
5340
5350
|
"borderBottomRightRadius",
|
|
5341
|
-
]
|
|
5351
|
+
],
|
|
5352
|
+
},
|
|
5342
5353
|
borderTopLeftRadius: correctBorderRadius,
|
|
5343
5354
|
borderTopRightRadius: correctBorderRadius,
|
|
5344
5355
|
borderBottomLeftRadius: correctBorderRadius,
|
|
@@ -5553,6 +5564,12 @@ function boxEquals(a, b) {
|
|
|
5553
5564
|
a.y.min === b.y.min &&
|
|
5554
5565
|
a.y.max === b.y.max);
|
|
5555
5566
|
}
|
|
5567
|
+
function aspectRatio(box) {
|
|
5568
|
+
return calcLength(box.x) / calcLength(box.y);
|
|
5569
|
+
}
|
|
5570
|
+
function isCloseTo(a, b, max = 0.01) {
|
|
5571
|
+
return popmotion.distance(a, b) <= max;
|
|
5572
|
+
}
|
|
5556
5573
|
|
|
5557
5574
|
class NodeStack {
|
|
5558
5575
|
constructor() {
|
|
@@ -5719,6 +5736,7 @@ class FlatTree {
|
|
|
5719
5736
|
}
|
|
5720
5737
|
}
|
|
5721
5738
|
|
|
5739
|
+
const transformAxes = ["", "X", "Y", "Z"];
|
|
5722
5740
|
/**
|
|
5723
5741
|
* We use 1000 as the animation target as 0-1000 maps better to pixels than 0-1
|
|
5724
5742
|
* which has a noticeable difference in spring animations
|
|
@@ -5910,7 +5928,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
5910
5928
|
this.resumingFrom.resumingFrom = undefined;
|
|
5911
5929
|
}
|
|
5912
5930
|
this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
|
|
5913
|
-
const animationOptions =
|
|
5931
|
+
const animationOptions = {
|
|
5932
|
+
...getValueTransition(layoutTransition, "layout"),
|
|
5933
|
+
onPlay: onLayoutAnimationStart,
|
|
5934
|
+
onComplete: onLayoutAnimationComplete,
|
|
5935
|
+
};
|
|
5914
5936
|
if (visualElement.shouldReduceMotion) {
|
|
5915
5937
|
animationOptions.delay = 0;
|
|
5916
5938
|
animationOptions.type = false;
|
|
@@ -6233,8 +6255,11 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6233
6255
|
this.root.scheduleUpdateProjection();
|
|
6234
6256
|
}
|
|
6235
6257
|
setOptions(options) {
|
|
6236
|
-
|
|
6237
|
-
|
|
6258
|
+
this.options = {
|
|
6259
|
+
...this.options,
|
|
6260
|
+
...options,
|
|
6261
|
+
crossfade: options.crossfade !== undefined ? options.crossfade : true,
|
|
6262
|
+
};
|
|
6238
6263
|
}
|
|
6239
6264
|
clearMeasurements() {
|
|
6240
6265
|
this.scroll = undefined;
|
|
@@ -6416,7 +6441,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6416
6441
|
var _a;
|
|
6417
6442
|
const snapshot = this.snapshot;
|
|
6418
6443
|
const snapshotLatestValues = (snapshot === null || snapshot === void 0 ? void 0 : snapshot.latestValues) || {};
|
|
6419
|
-
const mixedValues =
|
|
6444
|
+
const mixedValues = { ...this.latestValues };
|
|
6420
6445
|
const targetDelta = createDelta();
|
|
6421
6446
|
this.relativeTarget = this.relativeTargetOrigin = undefined;
|
|
6422
6447
|
this.attemptToResolveRelativeTarget = !hasOnlyRelativeTargetChanged;
|
|
@@ -6469,15 +6494,19 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6469
6494
|
*/
|
|
6470
6495
|
this.pendingAnimation = sync__default["default"].update(() => {
|
|
6471
6496
|
globalProjectionState.hasAnimatedSinceResize = true;
|
|
6472
|
-
this.currentAnimation = animate(0, animationTarget,
|
|
6497
|
+
this.currentAnimation = animate(0, animationTarget, {
|
|
6498
|
+
...options,
|
|
6499
|
+
onUpdate: (latest) => {
|
|
6473
6500
|
var _a;
|
|
6474
6501
|
this.mixTargetDelta(latest);
|
|
6475
6502
|
(_a = options.onUpdate) === null || _a === void 0 ? void 0 : _a.call(options, latest);
|
|
6476
|
-
},
|
|
6503
|
+
},
|
|
6504
|
+
onComplete: () => {
|
|
6477
6505
|
var _a;
|
|
6478
6506
|
(_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
6479
6507
|
this.completeAnimation();
|
|
6480
|
-
}
|
|
6508
|
+
},
|
|
6509
|
+
});
|
|
6481
6510
|
if (this.resumingFrom) {
|
|
6482
6511
|
this.resumingFrom.currentAnimation = this.currentAnimation;
|
|
6483
6512
|
}
|
|
@@ -6506,9 +6535,27 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6506
6535
|
this.completeAnimation();
|
|
6507
6536
|
}
|
|
6508
6537
|
applyTransformsToTarget() {
|
|
6509
|
-
const
|
|
6538
|
+
const lead = this.getLead();
|
|
6539
|
+
let { targetWithTransforms, target, layout, latestValues } = lead;
|
|
6510
6540
|
if (!targetWithTransforms || !target || !layout)
|
|
6511
6541
|
return;
|
|
6542
|
+
/**
|
|
6543
|
+
* If we're only animating position, and this element isn't the lead element,
|
|
6544
|
+
* then instead of projecting into the lead box we instead want to calculate
|
|
6545
|
+
* a new target that aligns the two boxes but maintains the layout shape.
|
|
6546
|
+
*/
|
|
6547
|
+
if (this !== lead &&
|
|
6548
|
+
this.layout &&
|
|
6549
|
+
layout &&
|
|
6550
|
+
shouldAnimatePositionOnly(this.options.animationType, this.layout.actual, layout.actual)) {
|
|
6551
|
+
target = this.target || createBox();
|
|
6552
|
+
const xLength = calcLength(this.layout.actual.x);
|
|
6553
|
+
target.x.min = lead.target.x.min;
|
|
6554
|
+
target.x.max = target.x.min + xLength;
|
|
6555
|
+
const yLength = calcLength(this.layout.actual.y);
|
|
6556
|
+
target.y.min = lead.target.y.min;
|
|
6557
|
+
target.y.max = target.y.min + yLength;
|
|
6558
|
+
}
|
|
6512
6559
|
copyBoxInto(targetWithTransforms, target);
|
|
6513
6560
|
/**
|
|
6514
6561
|
* Apply the latest user-set transforms to the targetBox to produce the targetBoxFinal.
|
|
@@ -6612,7 +6659,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6612
6659
|
visualElement.scheduleRender();
|
|
6613
6660
|
}
|
|
6614
6661
|
getProjectionStyles(styleProp = {}) {
|
|
6615
|
-
var _a, _b, _c
|
|
6662
|
+
var _a, _b, _c;
|
|
6616
6663
|
// TODO: Return lifecycle-persistent object
|
|
6617
6664
|
const styles = {};
|
|
6618
6665
|
if (!this.instance || this.isSVG)
|
|
@@ -6638,7 +6685,10 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6638
6685
|
if (!this.projectionDelta || !this.layout || !lead.target) {
|
|
6639
6686
|
const emptyStyles = {};
|
|
6640
6687
|
if (this.options.layoutId) {
|
|
6641
|
-
emptyStyles.opacity =
|
|
6688
|
+
emptyStyles.opacity =
|
|
6689
|
+
this.latestValues.opacity !== undefined
|
|
6690
|
+
? this.latestValues.opacity
|
|
6691
|
+
: 1;
|
|
6642
6692
|
emptyStyles.pointerEvents =
|
|
6643
6693
|
resolveMotionValue(styleProp.pointerEvents) || "";
|
|
6644
6694
|
}
|
|
@@ -6665,7 +6715,7 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6665
6715
|
*/
|
|
6666
6716
|
styles.opacity =
|
|
6667
6717
|
lead === this
|
|
6668
|
-
? (
|
|
6718
|
+
? (_c = (_b = valuesToRender.opacity) !== null && _b !== void 0 ? _b : this.latestValues.opacity) !== null && _c !== void 0 ? _c : 1
|
|
6669
6719
|
: this.preserveOpacity
|
|
6670
6720
|
? this.latestValues.opacity
|
|
6671
6721
|
: valuesToRender.opacityExit;
|
|
@@ -6677,8 +6727,12 @@ function createProjectionNode({ attachResizeListener, defaultParent, measureScro
|
|
|
6677
6727
|
*/
|
|
6678
6728
|
styles.opacity =
|
|
6679
6729
|
lead === this
|
|
6680
|
-
?
|
|
6681
|
-
|
|
6730
|
+
? valuesToRender.opacity !== undefined
|
|
6731
|
+
? valuesToRender.opacity
|
|
6732
|
+
: ""
|
|
6733
|
+
: valuesToRender.opacityExit !== undefined
|
|
6734
|
+
? valuesToRender.opacityExit
|
|
6735
|
+
: 0;
|
|
6682
6736
|
}
|
|
6683
6737
|
/**
|
|
6684
6738
|
* Apply scale correction
|
|
@@ -6726,16 +6780,17 @@ function updateLayout(node) {
|
|
|
6726
6780
|
node.updateLayout();
|
|
6727
6781
|
}
|
|
6728
6782
|
function notifyLayoutUpdate(node) {
|
|
6729
|
-
var _a, _b, _c
|
|
6730
|
-
const snapshot = (
|
|
6783
|
+
var _a, _b, _c;
|
|
6784
|
+
const snapshot = ((_a = node.resumeFrom) === null || _a === void 0 ? void 0 : _a.snapshot) || node.snapshot;
|
|
6731
6785
|
if (node.isLead() &&
|
|
6732
6786
|
node.layout &&
|
|
6733
6787
|
snapshot &&
|
|
6734
6788
|
node.hasListeners("didUpdate")) {
|
|
6735
6789
|
const { actual: layout, measured: measuredLayout } = node.layout;
|
|
6790
|
+
const { animationType } = node.options;
|
|
6736
6791
|
// TODO Maybe we want to also resize the layout snapshot so we don't trigger
|
|
6737
6792
|
// animations for instance if layout="size" and an element has only changed position
|
|
6738
|
-
if (
|
|
6793
|
+
if (animationType === "size") {
|
|
6739
6794
|
eachAxis((axis) => {
|
|
6740
6795
|
const axisSnapshot = snapshot.isShared
|
|
6741
6796
|
? snapshot.measured[axis]
|
|
@@ -6745,7 +6800,7 @@ function notifyLayoutUpdate(node) {
|
|
|
6745
6800
|
axisSnapshot.max = axisSnapshot.min + length;
|
|
6746
6801
|
});
|
|
6747
6802
|
}
|
|
6748
|
-
else if (
|
|
6803
|
+
else if (shouldAnimatePositionOnly(animationType, snapshot.layout, layout)) {
|
|
6749
6804
|
eachAxis((axis) => {
|
|
6750
6805
|
const axisSnapshot = snapshot.isShared
|
|
6751
6806
|
? snapshot.measured[axis]
|
|
@@ -6794,7 +6849,7 @@ function notifyLayoutUpdate(node) {
|
|
|
6794
6849
|
});
|
|
6795
6850
|
}
|
|
6796
6851
|
else if (node.isLead()) {
|
|
6797
|
-
(
|
|
6852
|
+
(_c = (_b = node.options).onExitComplete) === null || _c === void 0 ? void 0 : _c.call(_b);
|
|
6798
6853
|
}
|
|
6799
6854
|
/**
|
|
6800
6855
|
* Clearing transition
|
|
@@ -6878,6 +6933,11 @@ function roundBox(box) {
|
|
|
6878
6933
|
roundAxis(box.x);
|
|
6879
6934
|
roundAxis(box.y);
|
|
6880
6935
|
}
|
|
6936
|
+
function shouldAnimatePositionOnly(animationType, snapshot, layout) {
|
|
6937
|
+
return (animationType === "position" ||
|
|
6938
|
+
(animationType === "preserve-aspect" &&
|
|
6939
|
+
!isCloseTo(aspectRatio(snapshot), aspectRatio(layout))));
|
|
6940
|
+
}
|
|
6881
6941
|
|
|
6882
6942
|
const DocumentProjectionNode = createProjectionNode({
|
|
6883
6943
|
attachResizeListener: (ref, notify) => addDomEvent(ref, "resize", notify),
|
|
@@ -6906,12 +6966,17 @@ const HTMLProjectionNode = createProjectionNode({
|
|
|
6906
6966
|
return rootProjectionNode.current;
|
|
6907
6967
|
},
|
|
6908
6968
|
resetTransform: (instance, value) => {
|
|
6909
|
-
instance.style.transform = value !==
|
|
6969
|
+
instance.style.transform = value !== undefined ? value : "none";
|
|
6910
6970
|
},
|
|
6911
6971
|
checkIsScrollRoot: (instance) => Boolean(window.getComputedStyle(instance).position === "fixed"),
|
|
6912
6972
|
});
|
|
6913
6973
|
|
|
6914
|
-
const featureBundle =
|
|
6974
|
+
const featureBundle = {
|
|
6975
|
+
...animations,
|
|
6976
|
+
...gestureAnimations,
|
|
6977
|
+
...drag,
|
|
6978
|
+
...layoutFeatures,
|
|
6979
|
+
};
|
|
6915
6980
|
/**
|
|
6916
6981
|
* HTML & SVG components, optimised for use with gestures and animation. These can be used as
|
|
6917
6982
|
* drop-in replacements for any HTML & SVG component, all CSS & SVG properties are supported.
|
|
@@ -7011,14 +7076,14 @@ function PopChild({ children, isPresent }) {
|
|
|
7011
7076
|
* styles set via the style prop.
|
|
7012
7077
|
*/
|
|
7013
7078
|
React.useInsertionEffect(() => {
|
|
7014
|
-
var _a;
|
|
7015
7079
|
const { width, height, top, left } = size.current;
|
|
7016
7080
|
if (isPresent || !ref.current || !width || !height)
|
|
7017
7081
|
return;
|
|
7018
7082
|
ref.current.dataset.motionPopId = id;
|
|
7019
7083
|
const style = document.createElement("style");
|
|
7020
7084
|
document.head.appendChild(style);
|
|
7021
|
-
(
|
|
7085
|
+
if (style.sheet) {
|
|
7086
|
+
style.sheet.insertRule(`
|
|
7022
7087
|
[data-motion-pop-id="${id}"] {
|
|
7023
7088
|
position: absolute !important;
|
|
7024
7089
|
width: ${width}px !important;
|
|
@@ -7027,6 +7092,7 @@ function PopChild({ children, isPresent }) {
|
|
|
7027
7092
|
left: ${left}px !important;
|
|
7028
7093
|
}
|
|
7029
7094
|
`);
|
|
7095
|
+
}
|
|
7030
7096
|
return () => {
|
|
7031
7097
|
document.head.removeChild(style);
|
|
7032
7098
|
};
|
|
@@ -7048,7 +7114,7 @@ const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, p
|
|
|
7048
7114
|
if (!isComplete)
|
|
7049
7115
|
return; // can stop searching when any is incomplete
|
|
7050
7116
|
}
|
|
7051
|
-
onExitComplete
|
|
7117
|
+
onExitComplete && onExitComplete();
|
|
7052
7118
|
},
|
|
7053
7119
|
register: (childId) => {
|
|
7054
7120
|
presenceChildren.set(childId, false);
|
|
@@ -7069,7 +7135,10 @@ const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, p
|
|
|
7069
7135
|
* component immediately.
|
|
7070
7136
|
*/
|
|
7071
7137
|
React__namespace.useEffect(() => {
|
|
7072
|
-
!isPresent &&
|
|
7138
|
+
!isPresent &&
|
|
7139
|
+
!presenceChildren.size &&
|
|
7140
|
+
onExitComplete &&
|
|
7141
|
+
onExitComplete();
|
|
7073
7142
|
}, [isPresent]);
|
|
7074
7143
|
if (mode === "popLayout") {
|
|
7075
7144
|
children = React__namespace.createElement(PopChild, { isPresent: isPresent }, children);
|
|
@@ -7257,8 +7326,7 @@ function nodeGroup() {
|
|
|
7257
7326
|
|
|
7258
7327
|
const shouldInheritGroup = (inherit) => inherit === true;
|
|
7259
7328
|
const shouldInheritId = (inherit) => shouldInheritGroup(inherit === true) || inherit === "id";
|
|
7260
|
-
const LayoutGroup = ({ children, id, inheritId, inherit = true
|
|
7261
|
-
var _a, _b;
|
|
7329
|
+
const LayoutGroup = ({ children, id, inheritId, inherit = true }) => {
|
|
7262
7330
|
// Maintain backwards-compatibility with inheritId until 7.0
|
|
7263
7331
|
if (inheritId !== undefined)
|
|
7264
7332
|
inherit = inheritId;
|
|
@@ -7266,7 +7334,7 @@ const LayoutGroup = ({ children, id, inheritId, inherit = true, }) => {
|
|
|
7266
7334
|
const deprecatedLayoutGroupContext = React.useContext(DeprecatedLayoutGroupContext);
|
|
7267
7335
|
const [forceRender, key] = useForceUpdate();
|
|
7268
7336
|
const context = React.useRef(null);
|
|
7269
|
-
const upstreamId =
|
|
7337
|
+
const upstreamId = layoutGroupContext.id || deprecatedLayoutGroupContext;
|
|
7270
7338
|
if (context.current === null) {
|
|
7271
7339
|
if (shouldInheritId(inherit) && upstreamId) {
|
|
7272
7340
|
id = id ? upstreamId + "-" + id : upstreamId;
|
|
@@ -7274,11 +7342,11 @@ const LayoutGroup = ({ children, id, inheritId, inherit = true, }) => {
|
|
|
7274
7342
|
context.current = {
|
|
7275
7343
|
id,
|
|
7276
7344
|
group: shouldInheritGroup(inherit)
|
|
7277
|
-
?
|
|
7345
|
+
? layoutGroupContext.group || nodeGroup()
|
|
7278
7346
|
: nodeGroup(),
|
|
7279
7347
|
};
|
|
7280
7348
|
}
|
|
7281
|
-
const memoizedContext = React.useMemo(() => (
|
|
7349
|
+
const memoizedContext = React.useMemo(() => ({ ...context.current, forceRender }), [key]);
|
|
7282
7350
|
return (React__namespace.createElement(LayoutGroupContext.Provider, { value: memoizedContext }, children));
|
|
7283
7351
|
};
|
|
7284
7352
|
|
|
@@ -7307,13 +7375,12 @@ const AnimateSharedLayout = ({ children, }) => {
|
|
|
7307
7375
|
*
|
|
7308
7376
|
* @public
|
|
7309
7377
|
*/
|
|
7310
|
-
function MotionConfig(
|
|
7311
|
-
var { children, isValidProp } = _a, config = tslib.__rest(_a, ["children", "isValidProp"]);
|
|
7378
|
+
function MotionConfig({ children, isValidProp, ...config }) {
|
|
7312
7379
|
isValidProp && loadExternalIsValidProp(isValidProp);
|
|
7313
7380
|
/**
|
|
7314
7381
|
* Inherit props from any parent MotionConfig components
|
|
7315
7382
|
*/
|
|
7316
|
-
config =
|
|
7383
|
+
config = { ...React.useContext(MotionConfigContext), ...config };
|
|
7317
7384
|
/**
|
|
7318
7385
|
* Don't allow isStatic to change between renders as it affects how many hooks
|
|
7319
7386
|
* motion components fire.
|
|
@@ -7369,14 +7436,13 @@ function LazyMotion({ children, features, strict = false }) {
|
|
|
7369
7436
|
* If this is a synchronous load, load features immediately
|
|
7370
7437
|
*/
|
|
7371
7438
|
if (!isLazyBundle(features)) {
|
|
7372
|
-
const { renderer
|
|
7439
|
+
const { renderer, ...loadedFeatures } = features;
|
|
7373
7440
|
loadedRenderer.current = renderer;
|
|
7374
7441
|
loadFeatures(loadedFeatures);
|
|
7375
7442
|
}
|
|
7376
7443
|
React.useEffect(() => {
|
|
7377
7444
|
if (isLazyBundle(features)) {
|
|
7378
|
-
features().then((
|
|
7379
|
-
var { renderer } = _a, loadedFeatures = tslib.__rest(_a, ["renderer"]);
|
|
7445
|
+
features().then(({ renderer, ...loadedFeatures }) => {
|
|
7380
7446
|
loadFeatures(loadedFeatures);
|
|
7381
7447
|
loadedRenderer.current = renderer;
|
|
7382
7448
|
setIsLoaded(true);
|
|
@@ -7411,8 +7477,7 @@ function checkReorder(order, value, offset, velocity) {
|
|
|
7411
7477
|
return order;
|
|
7412
7478
|
}
|
|
7413
7479
|
|
|
7414
|
-
function ReorderGroup(
|
|
7415
|
-
var { children, as = "ul", axis = "y", onReorder, values } = _a, props = tslib.__rest(_a, ["children", "as", "axis", "onReorder", "values"]);
|
|
7480
|
+
function ReorderGroup({ children, as = "ul", axis = "y", onReorder, values, ...props }, externalRef) {
|
|
7416
7481
|
const Component = useConstant(() => motion(as));
|
|
7417
7482
|
const order = [];
|
|
7418
7483
|
const isReordering = React.useRef(false);
|
|
@@ -7444,7 +7509,7 @@ function ReorderGroup(_a, externalRef) {
|
|
|
7444
7509
|
React.useEffect(() => {
|
|
7445
7510
|
isReordering.current = false;
|
|
7446
7511
|
});
|
|
7447
|
-
return (React__namespace.createElement(Component,
|
|
7512
|
+
return (React__namespace.createElement(Component, { ...props, ref: externalRef },
|
|
7448
7513
|
React__namespace.createElement(ReorderContext.Provider, { value: context }, children)));
|
|
7449
7514
|
}
|
|
7450
7515
|
const Group = React.forwardRef(ReorderGroup);
|
|
@@ -7498,7 +7563,10 @@ function transform(...args) {
|
|
|
7498
7563
|
const inputRange = args[1 + argOffset];
|
|
7499
7564
|
const outputRange = args[2 + argOffset];
|
|
7500
7565
|
const options = args[3 + argOffset];
|
|
7501
|
-
const interpolator = popmotion.interpolate(inputRange, outputRange,
|
|
7566
|
+
const interpolator = popmotion.interpolate(inputRange, outputRange, {
|
|
7567
|
+
mixer: getMixer(outputRange[0]),
|
|
7568
|
+
...options,
|
|
7569
|
+
});
|
|
7502
7570
|
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
7503
7571
|
}
|
|
7504
7572
|
|
|
@@ -7563,13 +7631,12 @@ function useListTransform(values, transformer) {
|
|
|
7563
7631
|
function useDefaultMotionValue(value, defaultValue = 0) {
|
|
7564
7632
|
return isMotionValue(value) ? value : useMotionValue(defaultValue);
|
|
7565
7633
|
}
|
|
7566
|
-
function ReorderItem(
|
|
7567
|
-
var { children, style, value, as = "li", onDrag, layout = true } = _a, props = tslib.__rest(_a, ["children", "style", "value", "as", "onDrag", "layout"]);
|
|
7634
|
+
function ReorderItem({ children, style = {}, value, as = "li", onDrag, layout = true, ...props }, externalRef) {
|
|
7568
7635
|
const Component = useConstant(() => motion(as));
|
|
7569
7636
|
const context = React.useContext(ReorderContext);
|
|
7570
7637
|
const point = {
|
|
7571
|
-
x: useDefaultMotionValue(style
|
|
7572
|
-
y: useDefaultMotionValue(style
|
|
7638
|
+
x: useDefaultMotionValue(style.x),
|
|
7639
|
+
y: useDefaultMotionValue(style.y),
|
|
7573
7640
|
};
|
|
7574
7641
|
const zIndex = useTransform([point.x, point.y], ([latestX, latestY]) => latestX || latestY ? 1 : "unset");
|
|
7575
7642
|
const measuredLayout = React.useRef(null);
|
|
@@ -7578,14 +7645,14 @@ function ReorderItem(_a, externalRef) {
|
|
|
7578
7645
|
React.useEffect(() => {
|
|
7579
7646
|
registerItem(value, measuredLayout.current);
|
|
7580
7647
|
}, [context]);
|
|
7581
|
-
return (React__namespace.createElement(Component,
|
|
7648
|
+
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
7649
|
const { velocity } = gesturePoint;
|
|
7583
7650
|
velocity[axis] &&
|
|
7584
7651
|
updateOrder(value, point[axis].get(), velocity[axis]);
|
|
7585
|
-
onDrag
|
|
7652
|
+
onDrag && onDrag(event, gesturePoint);
|
|
7586
7653
|
}, onLayoutMeasure: (measured) => {
|
|
7587
7654
|
measuredLayout.current = measured;
|
|
7588
|
-
}, ref: externalRef }
|
|
7655
|
+
}, ref: externalRef }, children));
|
|
7589
7656
|
}
|
|
7590
7657
|
const Item = React.forwardRef(ReorderItem);
|
|
7591
7658
|
|
|
@@ -7597,12 +7664,21 @@ const Reorder = {
|
|
|
7597
7664
|
/**
|
|
7598
7665
|
* @public
|
|
7599
7666
|
*/
|
|
7600
|
-
const domAnimation =
|
|
7667
|
+
const domAnimation = {
|
|
7668
|
+
renderer: createDomVisualElement,
|
|
7669
|
+
...animations,
|
|
7670
|
+
...gestureAnimations,
|
|
7671
|
+
};
|
|
7601
7672
|
|
|
7602
7673
|
/**
|
|
7603
7674
|
* @public
|
|
7604
7675
|
*/
|
|
7605
|
-
const domMax =
|
|
7676
|
+
const domMax = {
|
|
7677
|
+
...domAnimation,
|
|
7678
|
+
...drag,
|
|
7679
|
+
...layoutFeatures,
|
|
7680
|
+
projectionNodeConstructor: HTMLProjectionNode,
|
|
7681
|
+
};
|
|
7606
7682
|
|
|
7607
7683
|
/**
|
|
7608
7684
|
* Combine multiple motion values into a new one using a string template literal.
|
|
@@ -7678,7 +7754,13 @@ function useSpring(source, config = {}) {
|
|
|
7678
7754
|
if (activeSpringAnimation.current) {
|
|
7679
7755
|
activeSpringAnimation.current.stop();
|
|
7680
7756
|
}
|
|
7681
|
-
activeSpringAnimation.current = popmotion.animate(
|
|
7757
|
+
activeSpringAnimation.current = popmotion.animate({
|
|
7758
|
+
from: value.get(),
|
|
7759
|
+
to: v,
|
|
7760
|
+
velocity: value.getVelocity(),
|
|
7761
|
+
...config,
|
|
7762
|
+
onUpdate: set,
|
|
7763
|
+
});
|
|
7682
7764
|
return value.get();
|
|
7683
7765
|
});
|
|
7684
7766
|
}, [JSON.stringify(config)]);
|
|
@@ -7713,8 +7795,7 @@ const createScrollMotionValues = () => ({
|
|
|
7713
7795
|
scrollXProgress: motionValue(0),
|
|
7714
7796
|
scrollYProgress: motionValue(0),
|
|
7715
7797
|
});
|
|
7716
|
-
function useScroll(
|
|
7717
|
-
var { container, target } = _a, options = tslib.__rest(_a, ["container", "target"]);
|
|
7798
|
+
function useScroll({ container, target, ...options } = {}) {
|
|
7718
7799
|
const values = useConstant(createScrollMotionValues);
|
|
7719
7800
|
useIsomorphicLayoutEffect(() => {
|
|
7720
7801
|
return dom.scroll(({ x, y }) => {
|
|
@@ -7722,7 +7803,11 @@ function useScroll(_a = {}) {
|
|
|
7722
7803
|
values.scrollXProgress.set(x.progress);
|
|
7723
7804
|
values.scrollY.set(y.current);
|
|
7724
7805
|
values.scrollYProgress.set(y.progress);
|
|
7725
|
-
},
|
|
7806
|
+
}, {
|
|
7807
|
+
...options,
|
|
7808
|
+
container: (container === null || container === void 0 ? void 0 : container.current) || undefined,
|
|
7809
|
+
target: (target === null || target === void 0 ? void 0 : target.current) || undefined,
|
|
7810
|
+
});
|
|
7726
7811
|
}, []);
|
|
7727
7812
|
return values;
|
|
7728
7813
|
}
|
|
@@ -7773,11 +7858,11 @@ class WillChangeMotionValue extends MotionValue {
|
|
|
7773
7858
|
}
|
|
7774
7859
|
add(name) {
|
|
7775
7860
|
let memberName;
|
|
7776
|
-
if (
|
|
7861
|
+
if (transformProps.has(name)) {
|
|
7777
7862
|
this.transforms.add(name);
|
|
7778
7863
|
memberName = "transform";
|
|
7779
7864
|
}
|
|
7780
|
-
else if (!
|
|
7865
|
+
else if (!name.startsWith("origin") &&
|
|
7781
7866
|
!isCSSVariable$1(name) &&
|
|
7782
7867
|
name !== "willChange") {
|
|
7783
7868
|
memberName = camelToDash(name);
|
|
@@ -7788,7 +7873,7 @@ class WillChangeMotionValue extends MotionValue {
|
|
|
7788
7873
|
}
|
|
7789
7874
|
}
|
|
7790
7875
|
remove(name) {
|
|
7791
|
-
if (
|
|
7876
|
+
if (transformProps.has(name)) {
|
|
7792
7877
|
this.transforms.delete(name);
|
|
7793
7878
|
if (!this.transforms.size) {
|
|
7794
7879
|
removeItem(this.members, "transform");
|
|
@@ -7807,6 +7892,58 @@ function useWillChange() {
|
|
|
7807
7892
|
return useConstant(() => new WillChangeMotionValue("auto"));
|
|
7808
7893
|
}
|
|
7809
7894
|
|
|
7895
|
+
/**
|
|
7896
|
+
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
7897
|
+
*
|
|
7898
|
+
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
7899
|
+
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
7900
|
+
*
|
|
7901
|
+
* It will actively respond to changes and re-render your components with the latest setting.
|
|
7902
|
+
*
|
|
7903
|
+
* ```jsx
|
|
7904
|
+
* export function Sidebar({ isOpen }) {
|
|
7905
|
+
* const shouldReduceMotion = useReducedMotion()
|
|
7906
|
+
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
7907
|
+
*
|
|
7908
|
+
* return (
|
|
7909
|
+
* <motion.div animate={{
|
|
7910
|
+
* opacity: isOpen ? 1 : 0,
|
|
7911
|
+
* x: isOpen ? 0 : closedX
|
|
7912
|
+
* }} />
|
|
7913
|
+
* )
|
|
7914
|
+
* }
|
|
7915
|
+
* ```
|
|
7916
|
+
*
|
|
7917
|
+
* @return boolean
|
|
7918
|
+
*
|
|
7919
|
+
* @public
|
|
7920
|
+
*/
|
|
7921
|
+
function useReducedMotion() {
|
|
7922
|
+
/**
|
|
7923
|
+
* Lazy initialisation of prefersReducedMotion
|
|
7924
|
+
*/
|
|
7925
|
+
!hasReducedMotionListener.current && initPrefersReducedMotion();
|
|
7926
|
+
const [shouldReduceMotion] = React.useState(prefersReducedMotion.current);
|
|
7927
|
+
/**
|
|
7928
|
+
* TODO See if people miss automatically updating shouldReduceMotion setting
|
|
7929
|
+
*/
|
|
7930
|
+
return shouldReduceMotion;
|
|
7931
|
+
}
|
|
7932
|
+
|
|
7933
|
+
function useReducedMotionConfig() {
|
|
7934
|
+
const reducedMotionPreference = useReducedMotion();
|
|
7935
|
+
const { reducedMotion } = React.useContext(MotionConfigContext);
|
|
7936
|
+
if (reducedMotion === "never") {
|
|
7937
|
+
return false;
|
|
7938
|
+
}
|
|
7939
|
+
else if (reducedMotion === "always") {
|
|
7940
|
+
return true;
|
|
7941
|
+
}
|
|
7942
|
+
else {
|
|
7943
|
+
return reducedMotionPreference;
|
|
7944
|
+
}
|
|
7945
|
+
}
|
|
7946
|
+
|
|
7810
7947
|
/**
|
|
7811
7948
|
* @public
|
|
7812
7949
|
*/
|
|
@@ -7961,7 +8098,6 @@ function useCycle(...items) {
|
|
|
7961
8098
|
function useInView(ref, { root, margin, amount, once = false } = {}) {
|
|
7962
8099
|
const [isInView, setInView] = React.useState(false);
|
|
7963
8100
|
React.useEffect(() => {
|
|
7964
|
-
var _a;
|
|
7965
8101
|
if (!ref.current || (once && isInView))
|
|
7966
8102
|
return;
|
|
7967
8103
|
const onEnter = () => {
|
|
@@ -7969,7 +8105,7 @@ function useInView(ref, { root, margin, amount, once = false } = {}) {
|
|
|
7969
8105
|
return once ? undefined : () => setInView(false);
|
|
7970
8106
|
};
|
|
7971
8107
|
const options = {
|
|
7972
|
-
root: (
|
|
8108
|
+
root: (root && root.current) || undefined,
|
|
7973
8109
|
margin,
|
|
7974
8110
|
amount: amount === "some" ? "any" : amount,
|
|
7975
8111
|
};
|
|
@@ -8066,12 +8202,12 @@ function useDragControls() {
|
|
|
8066
8202
|
function useInstantLayoutTransition() {
|
|
8067
8203
|
return startTransition;
|
|
8068
8204
|
}
|
|
8069
|
-
function startTransition(
|
|
8205
|
+
function startTransition(callback) {
|
|
8070
8206
|
if (!rootProjectionNode.current)
|
|
8071
8207
|
return;
|
|
8072
8208
|
rootProjectionNode.current.isUpdating = false;
|
|
8073
8209
|
rootProjectionNode.current.blockUpdate();
|
|
8074
|
-
|
|
8210
|
+
callback && callback();
|
|
8075
8211
|
}
|
|
8076
8212
|
|
|
8077
8213
|
function useInstantTransition() {
|
|
@@ -8114,11 +8250,10 @@ const stateVisualElement = visualElement({
|
|
|
8114
8250
|
readValueFromInstance(_state, key, options) {
|
|
8115
8251
|
return options.initialState[key] || 0;
|
|
8116
8252
|
},
|
|
8117
|
-
makeTargetAnimatable(element,
|
|
8118
|
-
var { transition, transitionEnd } = _a, target = tslib.__rest(_a, ["transition", "transitionEnd"]);
|
|
8253
|
+
makeTargetAnimatable(element, { transition, transitionEnd, ...target }) {
|
|
8119
8254
|
const origin = getOrigin(target, transition || {}, element);
|
|
8120
8255
|
checkTargetForNewValues(element, target, origin);
|
|
8121
|
-
return
|
|
8256
|
+
return { transition, transitionEnd, ...target };
|
|
8122
8257
|
},
|
|
8123
8258
|
});
|
|
8124
8259
|
const useVisualState = makeUseVisualState({
|
|
@@ -8140,7 +8275,7 @@ function useAnimatedState(initialState) {
|
|
|
8140
8275
|
React.useEffect(() => {
|
|
8141
8276
|
element.setProps({
|
|
8142
8277
|
onUpdate: (v) => {
|
|
8143
|
-
setAnimationState(
|
|
8278
|
+
setAnimationState({ ...v });
|
|
8144
8279
|
},
|
|
8145
8280
|
});
|
|
8146
8281
|
}, [setAnimationState, element]);
|