motion 11.11.12 → 11.11.13
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/.turbo/turbo-build.log +14 -11
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/react-client.js +2 -2
- package/dist/es/framer-motion/dist/es/animation/animators/BaseAnimation.mjs +2 -1
- package/dist/es/framer-motion/dist/es/animation/animators/MainThreadAnimation.mjs +5 -1
- package/dist/es/framer-motion/dist/es/animation/hooks/animation-controls.mjs +80 -0
- package/dist/es/framer-motion/dist/es/animation/hooks/use-animate-style.mjs +17 -0
- package/dist/es/framer-motion/dist/es/animation/hooks/use-animate.mjs +17 -0
- package/dist/es/framer-motion/dist/es/animation/hooks/use-animated-state.mjs +64 -0
- package/dist/es/framer-motion/dist/es/animation/hooks/use-animation.mjs +41 -0
- package/dist/es/framer-motion/dist/es/animation/interfaces/motion-value.mjs +8 -0
- package/dist/es/framer-motion/dist/es/animation/optimized-appear/handoff.mjs +40 -0
- package/dist/es/framer-motion/dist/es/animation/optimized-appear/start.mjs +173 -0
- package/dist/es/framer-motion/dist/es/animation/optimized-appear/store-id.mjs +8 -0
- package/dist/es/framer-motion/dist/es/animation/optimized-appear/store.mjs +4 -0
- package/dist/es/framer-motion/dist/es/components/AnimatePresence/PopChild.mjs +77 -0
- package/dist/es/framer-motion/dist/es/components/AnimatePresence/PresenceChild.mjs +61 -0
- package/dist/es/framer-motion/dist/es/components/AnimatePresence/index.mjs +163 -0
- package/dist/es/framer-motion/dist/es/components/AnimatePresence/use-presence.mjs +27 -1
- package/dist/es/framer-motion/dist/es/components/AnimatePresence/utils.mjs +14 -0
- package/dist/es/framer-motion/dist/es/components/AnimateSharedLayout.mjs +15 -0
- package/dist/es/framer-motion/dist/es/components/LayoutGroup/index.mjs +32 -0
- package/dist/es/framer-motion/dist/es/components/LazyMotion/index.mjs +68 -0
- package/dist/es/framer-motion/dist/es/components/MotionConfig/index.mjs +48 -0
- package/dist/es/framer-motion/dist/es/components/Reorder/Group.mjs +53 -0
- package/dist/es/framer-motion/dist/es/components/Reorder/Item.mjs +34 -0
- package/dist/es/framer-motion/dist/es/components/Reorder/namespace.mjs +2 -0
- package/dist/es/framer-motion/dist/es/components/Reorder/utils/check-reorder.mjs +24 -0
- package/dist/es/framer-motion/dist/es/context/DeprecatedLayoutGroupContext.mjs +10 -0
- package/dist/es/framer-motion/dist/es/context/ReorderContext.mjs +6 -0
- package/dist/es/framer-motion/dist/es/events/use-dom-event.mjs +34 -0
- package/dist/es/framer-motion/dist/es/frameloop/batcher.mjs +4 -1
- package/dist/es/framer-motion/dist/es/gestures/drag/use-drag-controls.mjs +88 -0
- package/dist/es/framer-motion/dist/es/motion/utils/is-motion-component.mjs +12 -0
- package/dist/es/framer-motion/dist/es/motion/utils/unwrap-motion-component.mjs +17 -0
- package/dist/es/framer-motion/dist/es/projection/node/group.mjs +24 -0
- package/dist/es/framer-motion/dist/es/projection/use-instant-layout-transition.mjs +14 -0
- package/dist/es/framer-motion/dist/es/projection/use-reset-projection.mjs +14 -0
- package/dist/es/framer-motion/dist/es/render/components/create-proxy.mjs +38 -0
- package/dist/es/framer-motion/dist/es/render/components/m/proxy.mjs +6 -0
- package/dist/es/framer-motion/dist/es/render/components/motion/proxy.mjs +6 -0
- package/dist/es/framer-motion/dist/es/render/dom/features-animation.mjs +14 -0
- package/dist/es/framer-motion/dist/es/render/dom/features-max.mjs +14 -0
- package/dist/es/framer-motion/dist/es/render/dom/features-min.mjs +12 -0
- package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/framer-motion/dist/es/utils/array.mjs +11 -1
- package/dist/es/framer-motion/dist/es/utils/reduced-motion/use-reduced-motion-config.mjs +19 -0
- package/dist/es/framer-motion/dist/es/utils/reduced-motion/use-reduced-motion.mjs +47 -0
- package/dist/es/framer-motion/dist/es/utils/use-animation-frame.mjs +21 -0
- package/dist/es/framer-motion/dist/es/utils/use-cycle.mjs +47 -0
- package/dist/es/framer-motion/dist/es/utils/use-force-update.mjs +19 -0
- package/dist/es/framer-motion/dist/es/utils/use-in-view.mjs +23 -0
- package/dist/es/framer-motion/dist/es/utils/use-instant-transition-state.mjs +5 -0
- package/dist/es/framer-motion/dist/es/utils/use-instant-transition.mjs +41 -0
- package/dist/es/framer-motion/dist/es/utils/use-is-mounted.mjs +15 -0
- package/dist/es/framer-motion/dist/es/utils/use-motion-value-event.mjs +13 -0
- package/dist/es/framer-motion/dist/es/utils/use-unmount-effect.mjs +7 -0
- package/dist/es/framer-motion/dist/es/value/index.mjs +8 -2
- package/dist/es/framer-motion/dist/es/value/scroll/use-element-scroll.mjs +14 -0
- package/dist/es/framer-motion/dist/es/value/scroll/use-viewport-scroll.mjs +14 -0
- package/dist/es/framer-motion/dist/es/value/types/color/rgba.mjs +1 -1
- package/dist/es/framer-motion/dist/es/value/use-combine-values.mjs +37 -0
- package/dist/es/framer-motion/dist/es/value/use-computed.mjs +19 -0
- package/dist/es/framer-motion/dist/es/value/use-inverted-scale.mjs +52 -0
- package/dist/es/framer-motion/dist/es/value/use-motion-template.mjs +45 -0
- package/dist/es/framer-motion/dist/es/value/use-motion-value.mjs +38 -0
- package/dist/es/framer-motion/dist/es/value/use-scroll.mjs +39 -0
- package/dist/es/framer-motion/dist/es/value/use-spring.mjs +85 -0
- package/dist/es/framer-motion/dist/es/value/use-time.mjs +10 -0
- package/dist/es/framer-motion/dist/es/value/use-transform.mjs +29 -0
- package/dist/es/framer-motion/dist/es/value/use-velocity.mjs +35 -0
- package/dist/es/framer-motion/dist/es/value/use-will-change/WillChangeMotionValue.mjs +22 -0
- package/dist/es/framer-motion/dist/es/value/use-will-change/get-will-change-name.mjs +14 -0
- package/dist/es/framer-motion/dist/es/value/use-will-change/index.mjs +8 -0
- package/dist/es/motion/lib/react.mjs +110 -0
- package/dist/motion.dev.js +2 -2
- package/dist/motion.js +1 -1
- package/dist/react.d.ts +1 -0
- package/package.json +17 -17
- package/rollup.config.mjs +12 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
(node:
|
|
1
|
+
(node:6290) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
|
|
2
2
|
(Use `node --trace-warnings ...` to show where the warning was created)
|
|
3
3
|
[36m
|
|
4
4
|
[1mlib/index.js[22m → [1mdist/motion.dev.js[22m...[39m
|
|
5
|
-
[32mcreated [1mdist/motion.dev.js[22m in [
|
|
5
|
+
[32mcreated [1mdist/motion.dev.js[22m in [1m484ms[22m[39m
|
|
6
6
|
[36m
|
|
7
7
|
[1mlib/index.js[22m → [1mdist/motion.js[22m...[39m
|
|
8
|
-
[32mcreated [1mdist/motion.js[22m in [
|
|
8
|
+
[32mcreated [1mdist/motion.js[22m in [1m766ms[22m[39m
|
|
9
9
|
[36m
|
|
10
10
|
[1mlib/index.js[22m → [1mdist/cjs[22m...[39m
|
|
11
|
-
[32mcreated [1mdist/cjs[22m in [
|
|
11
|
+
[32mcreated [1mdist/cjs[22m in [1m218ms[22m[39m
|
|
12
12
|
[36m
|
|
13
13
|
[1mlib/react-client.js[22m → [1mdist/cjs[22m...[39m
|
|
14
|
-
[32mcreated [1mdist/cjs[22m in [
|
|
14
|
+
[32mcreated [1mdist/cjs[22m in [1m323ms[22m[39m
|
|
15
15
|
[36m
|
|
16
16
|
[1mlib/react-m.js[22m → [1mdist/cjs[22m...[39m
|
|
17
|
-
[32mcreated [1mdist/cjs[22m in [
|
|
17
|
+
[32mcreated [1mdist/cjs[22m in [1m85ms[22m[39m
|
|
18
18
|
[36m
|
|
19
|
-
[1mlib/index.js, lib/react-client.js, lib/react-m.js[22m → [1mdist/es[22m...[39m
|
|
20
|
-
[32mcreated [1mdist/es[22m in [
|
|
19
|
+
[1mlib/index.js, lib/react.js, lib/react-client.js, lib/react-m.js[22m → [1mdist/es[22m...[39m
|
|
20
|
+
[32mcreated [1mdist/es[22m in [1m518ms[22m[39m
|
|
21
21
|
[36m
|
|
22
22
|
[1mtypes/index.d.ts[22m → [1mdist/index.d.ts[22m...[39m
|
|
23
|
-
[32mcreated [1mdist/index.d.ts[22m in [
|
|
23
|
+
[32mcreated [1mdist/index.d.ts[22m in [1m9ms[22m[39m
|
|
24
|
+
[36m
|
|
25
|
+
[1mtypes/react.d.ts[22m → [1mdist/react.d.ts[22m...[39m
|
|
26
|
+
[32mcreated [1mdist/react.d.ts[22m in [1m5ms[22m[39m
|
|
24
27
|
[36m
|
|
25
28
|
[1mtypes/react-m.d.ts[22m → [1mdist/react-m.d.ts[22m...[39m
|
|
26
|
-
[32mcreated [1mdist/react-m.d.ts[22m in [
|
|
29
|
+
[32mcreated [1mdist/react-m.d.ts[22m in [1m2ms[22m[39m
|
|
27
30
|
[36m
|
|
28
31
|
[1mtypes/react-client.d.ts[22m → [1mdist/react-client.d.ts[22m...[39m
|
|
29
|
-
[32mcreated [1mdist/react-client.d.ts[22m in [
|
|
32
|
+
[32mcreated [1mdist/react-client.d.ts[22m in [1m1ms[22m[39m
|
package/dist/cjs/index.js
CHANGED
|
@@ -279,7 +279,7 @@ class MotionValue {
|
|
|
279
279
|
* This will be replaced by the build step with the latest version number.
|
|
280
280
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
281
281
|
*/
|
|
282
|
-
this.version = "11.11.
|
|
282
|
+
this.version = "11.11.13";
|
|
283
283
|
/**
|
|
284
284
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
285
285
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -4089,7 +4089,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
4089
4089
|
* and warn against mismatches.
|
|
4090
4090
|
*/
|
|
4091
4091
|
if (process.env.NODE_ENV === "development") {
|
|
4092
|
-
warnOnce(nextValue.version === "11.11.
|
|
4092
|
+
warnOnce(nextValue.version === "11.11.13", `Attempting to mix Motion versions ${nextValue.version} with 11.11.13 may not work as expected.`);
|
|
4093
4093
|
}
|
|
4094
4094
|
}
|
|
4095
4095
|
else if (isMotionValue(prevValue)) {
|
package/dist/cjs/react-client.js
CHANGED
|
@@ -3281,7 +3281,7 @@ class MotionValue {
|
|
|
3281
3281
|
* This will be replaced by the build step with the latest version number.
|
|
3282
3282
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
3283
3283
|
*/
|
|
3284
|
-
this.version = "11.11.
|
|
3284
|
+
this.version = "11.11.13";
|
|
3285
3285
|
/**
|
|
3286
3286
|
* Tracks whether this value can output a velocity. Currently this is only true
|
|
3287
3287
|
* if the value is numerical, but we might be able to widen the scope here and support
|
|
@@ -9024,7 +9024,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
9024
9024
|
* and warn against mismatches.
|
|
9025
9025
|
*/
|
|
9026
9026
|
if (process.env.NODE_ENV === "development") {
|
|
9027
|
-
warnOnce(nextValue.version === "11.11.
|
|
9027
|
+
warnOnce(nextValue.version === "11.11.13", `Attempting to mix Motion versions ${nextValue.version} with 11.11.13 may not work as expected.`);
|
|
9028
9028
|
}
|
|
9029
9029
|
}
|
|
9030
9030
|
else if (isMotionValue(prevValue)) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { time } from '../../frameloop/sync-time.mjs';
|
|
2
2
|
import { flushKeyframeResolvers } from '../../render/utils/KeyframesResolver.mjs';
|
|
3
|
+
import { instantAnimationState } from '../../utils/use-instant-transition-state.mjs';
|
|
3
4
|
import { canAnimate } from './utils/can-animate.mjs';
|
|
4
5
|
import { getFinalKeyframe } from './waapi/utils/get-final-keyframe.mjs';
|
|
5
6
|
|
|
@@ -72,7 +73,7 @@ class BaseAnimation {
|
|
|
72
73
|
*/
|
|
73
74
|
if (!isGenerator && !canAnimate(keyframes, name, type, velocity)) {
|
|
74
75
|
// Finish immediately
|
|
75
|
-
if (!delay) {
|
|
76
|
+
if (instantAnimationState.current || !delay) {
|
|
76
77
|
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(getFinalKeyframe(keyframes, this.options, finalKeyframe));
|
|
77
78
|
onComplete === null || onComplete === void 0 ? void 0 : onComplete();
|
|
78
79
|
this.resolveFinishedPromise();
|
|
@@ -376,5 +376,9 @@ class MainThreadAnimation extends BaseAnimation {
|
|
|
376
376
|
return this.tick(time, true);
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
|
+
// Legacy interface
|
|
380
|
+
function animateValue(options) {
|
|
381
|
+
return new MainThreadAnimation(options);
|
|
382
|
+
}
|
|
379
383
|
|
|
380
|
-
export { MainThreadAnimation };
|
|
384
|
+
export { MainThreadAnimation, animateValue };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { invariant } from '../../utils/errors.mjs';
|
|
2
|
+
import { setTarget } from '../../render/utils/setters.mjs';
|
|
3
|
+
import { animateVisualElement } from '../interfaces/visual-element.mjs';
|
|
4
|
+
|
|
5
|
+
function stopAnimation(visualElement) {
|
|
6
|
+
visualElement.values.forEach((value) => value.stop());
|
|
7
|
+
}
|
|
8
|
+
function setVariants(visualElement, variantLabels) {
|
|
9
|
+
const reversedLabels = [...variantLabels].reverse();
|
|
10
|
+
reversedLabels.forEach((key) => {
|
|
11
|
+
const variant = visualElement.getVariant(key);
|
|
12
|
+
variant && setTarget(visualElement, variant);
|
|
13
|
+
if (visualElement.variantChildren) {
|
|
14
|
+
visualElement.variantChildren.forEach((child) => {
|
|
15
|
+
setVariants(child, variantLabels);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function setValues(visualElement, definition) {
|
|
21
|
+
if (Array.isArray(definition)) {
|
|
22
|
+
return setVariants(visualElement, definition);
|
|
23
|
+
}
|
|
24
|
+
else if (typeof definition === "string") {
|
|
25
|
+
return setVariants(visualElement, [definition]);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
setTarget(visualElement, definition);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
function animationControls() {
|
|
35
|
+
/**
|
|
36
|
+
* Track whether the host component has mounted.
|
|
37
|
+
*/
|
|
38
|
+
let hasMounted = false;
|
|
39
|
+
/**
|
|
40
|
+
* A collection of linked component animation controls.
|
|
41
|
+
*/
|
|
42
|
+
const subscribers = new Set();
|
|
43
|
+
const controls = {
|
|
44
|
+
subscribe(visualElement) {
|
|
45
|
+
subscribers.add(visualElement);
|
|
46
|
+
return () => void subscribers.delete(visualElement);
|
|
47
|
+
},
|
|
48
|
+
start(definition, transitionOverride) {
|
|
49
|
+
invariant(hasMounted, "controls.start() should only be called after a component has mounted. Consider calling within a useEffect hook.");
|
|
50
|
+
const animations = [];
|
|
51
|
+
subscribers.forEach((visualElement) => {
|
|
52
|
+
animations.push(animateVisualElement(visualElement, definition, {
|
|
53
|
+
transitionOverride,
|
|
54
|
+
}));
|
|
55
|
+
});
|
|
56
|
+
return Promise.all(animations);
|
|
57
|
+
},
|
|
58
|
+
set(definition) {
|
|
59
|
+
invariant(hasMounted, "controls.set() should only be called after a component has mounted. Consider calling within a useEffect hook.");
|
|
60
|
+
return subscribers.forEach((visualElement) => {
|
|
61
|
+
setValues(visualElement, definition);
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
stop() {
|
|
65
|
+
subscribers.forEach((visualElement) => {
|
|
66
|
+
stopAnimation(visualElement);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
mount() {
|
|
70
|
+
hasMounted = true;
|
|
71
|
+
return () => {
|
|
72
|
+
hasMounted = false;
|
|
73
|
+
controls.stop();
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
return controls;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { animationControls, setValues };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useConstant } from '../../utils/use-constant.mjs';
|
|
2
|
+
import { useUnmountEffect } from '../../utils/use-unmount-effect.mjs';
|
|
3
|
+
import { createScopedWaapiAnimate } from '../animators/waapi/animate-style.mjs';
|
|
4
|
+
|
|
5
|
+
function useAnimateMini() {
|
|
6
|
+
const scope = useConstant(() => ({
|
|
7
|
+
current: null, // Will be hydrated by React
|
|
8
|
+
animations: [],
|
|
9
|
+
}));
|
|
10
|
+
const animate = useConstant(() => createScopedWaapiAnimate(scope));
|
|
11
|
+
useUnmountEffect(() => {
|
|
12
|
+
scope.animations.forEach((animation) => animation.stop());
|
|
13
|
+
});
|
|
14
|
+
return [scope, animate];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { useAnimateMini };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useConstant } from '../../utils/use-constant.mjs';
|
|
2
|
+
import { useUnmountEffect } from '../../utils/use-unmount-effect.mjs';
|
|
3
|
+
import { createScopedAnimate } from '../animate/index.mjs';
|
|
4
|
+
|
|
5
|
+
function useAnimate() {
|
|
6
|
+
const scope = useConstant(() => ({
|
|
7
|
+
current: null, // Will be hydrated by React
|
|
8
|
+
animations: [],
|
|
9
|
+
}));
|
|
10
|
+
const animate = useConstant(() => createScopedAnimate(scope));
|
|
11
|
+
useUnmountEffect(() => {
|
|
12
|
+
scope.animations.forEach((animation) => animation.stop());
|
|
13
|
+
});
|
|
14
|
+
return [scope, animate];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { useAnimate };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useState, useLayoutEffect } from 'react';
|
|
2
|
+
import { useConstant } from '../../utils/use-constant.mjs';
|
|
3
|
+
import { makeUseVisualState } from '../../motion/utils/use-visual-state.mjs';
|
|
4
|
+
import { createBox } from '../../projection/geometry/models.mjs';
|
|
5
|
+
import { VisualElement } from '../../render/VisualElement.mjs';
|
|
6
|
+
import { animateVisualElement } from '../interfaces/visual-element.mjs';
|
|
7
|
+
|
|
8
|
+
const createObject = () => ({});
|
|
9
|
+
class StateVisualElement extends VisualElement {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.measureInstanceViewportBox = createBox;
|
|
13
|
+
}
|
|
14
|
+
build() { }
|
|
15
|
+
resetTransform() { }
|
|
16
|
+
restoreTransform() { }
|
|
17
|
+
removeValueFromRenderState() { }
|
|
18
|
+
renderInstance() { }
|
|
19
|
+
scrapeMotionValuesFromProps() {
|
|
20
|
+
return createObject();
|
|
21
|
+
}
|
|
22
|
+
getBaseTargetFromProps() {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
readValueFromInstance(_state, key, options) {
|
|
26
|
+
return options.initialState[key] || 0;
|
|
27
|
+
}
|
|
28
|
+
sortInstanceNodePosition() {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const useVisualState = makeUseVisualState({
|
|
33
|
+
scrapeMotionValuesFromProps: createObject,
|
|
34
|
+
createRenderState: createObject,
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* This is not an officially supported API and may be removed
|
|
38
|
+
* on any version.
|
|
39
|
+
*/
|
|
40
|
+
function useAnimatedState(initialState) {
|
|
41
|
+
const [animationState, setAnimationState] = useState(initialState);
|
|
42
|
+
const visualState = useVisualState({}, false);
|
|
43
|
+
const element = useConstant(() => {
|
|
44
|
+
return new StateVisualElement({
|
|
45
|
+
props: {
|
|
46
|
+
onUpdate: (v) => {
|
|
47
|
+
setAnimationState({ ...v });
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
visualState,
|
|
51
|
+
presenceContext: null,
|
|
52
|
+
}, { initialState });
|
|
53
|
+
});
|
|
54
|
+
useLayoutEffect(() => {
|
|
55
|
+
element.mount({});
|
|
56
|
+
return () => element.unmount();
|
|
57
|
+
}, [element]);
|
|
58
|
+
const startAnimation = useConstant(() => (animationDefinition) => {
|
|
59
|
+
return animateVisualElement(element, animationDefinition);
|
|
60
|
+
});
|
|
61
|
+
return [animationState, startAnimation];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { useAnimatedState };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { animationControls } from './animation-controls.mjs';
|
|
2
|
+
import { useConstant } from '../../utils/use-constant.mjs';
|
|
3
|
+
import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates `AnimationControls`, which can be used to manually start, stop
|
|
7
|
+
* and sequence animations on one or more components.
|
|
8
|
+
*
|
|
9
|
+
* The returned `AnimationControls` should be passed to the `animate` property
|
|
10
|
+
* of the components you want to animate.
|
|
11
|
+
*
|
|
12
|
+
* These components can then be animated with the `start` method.
|
|
13
|
+
*
|
|
14
|
+
* ```jsx
|
|
15
|
+
* import * as React from 'react'
|
|
16
|
+
* import { motion, useAnimation } from 'framer-motion'
|
|
17
|
+
*
|
|
18
|
+
* export function MyComponent(props) {
|
|
19
|
+
* const controls = useAnimation()
|
|
20
|
+
*
|
|
21
|
+
* controls.start({
|
|
22
|
+
* x: 100,
|
|
23
|
+
* transition: { duration: 0.5 },
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* return <motion.div animate={controls} />
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @returns Animation controller with `start` and `stop` methods
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
function useAnimationControls() {
|
|
35
|
+
const controls = useConstant(animationControls);
|
|
36
|
+
useIsomorphicLayoutEffect(controls.mount, []);
|
|
37
|
+
return controls;
|
|
38
|
+
}
|
|
39
|
+
const useAnimation = useAnimationControls;
|
|
40
|
+
|
|
41
|
+
export { useAnimation, useAnimationControls };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { secondsToMilliseconds } from '../../utils/time-conversion.mjs';
|
|
2
2
|
import { getDefaultTransition } from '../utils/default-transitions.mjs';
|
|
3
3
|
import { getValueTransition } from '../utils/get-value-transition.mjs';
|
|
4
|
+
import { MotionGlobalConfig } from '../../utils/GlobalConfig.mjs';
|
|
5
|
+
import { instantAnimationState } from '../../utils/use-instant-transition-state.mjs';
|
|
4
6
|
import { getFinalKeyframe } from '../animators/waapi/utils/get-final-keyframe.mjs';
|
|
5
7
|
import { frame } from '../../frameloop/frame.mjs';
|
|
6
8
|
import { AcceleratedAnimation } from '../animators/AcceleratedAnimation.mjs';
|
|
@@ -72,6 +74,12 @@ const animateMotionValue = (name, value, target, transition = {}, element, isHan
|
|
|
72
74
|
shouldSkip = true;
|
|
73
75
|
}
|
|
74
76
|
}
|
|
77
|
+
if (instantAnimationState.current ||
|
|
78
|
+
MotionGlobalConfig.skipAnimations) {
|
|
79
|
+
shouldSkip = true;
|
|
80
|
+
options.duration = 0;
|
|
81
|
+
options.delay = 0;
|
|
82
|
+
}
|
|
75
83
|
/**
|
|
76
84
|
* If we can or must skip creating the animation, and apply only
|
|
77
85
|
* the final keyframe, do so. We also check once keyframes are resolved but
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { appearAnimationStore } from './store.mjs';
|
|
2
|
+
import { appearStoreId } from './store-id.mjs';
|
|
3
|
+
|
|
4
|
+
function handoffOptimizedAppearAnimation(elementId, valueName, frame) {
|
|
5
|
+
var _a;
|
|
6
|
+
const storeId = appearStoreId(elementId, valueName);
|
|
7
|
+
const optimisedAnimation = appearAnimationStore.get(storeId);
|
|
8
|
+
if (!optimisedAnimation) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const { animation, startTime } = optimisedAnimation;
|
|
12
|
+
function cancelAnimation() {
|
|
13
|
+
var _a;
|
|
14
|
+
(_a = window.MotionCancelOptimisedAnimation) === null || _a === void 0 ? void 0 : _a.call(window, elementId, valueName, frame);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* We can cancel the animation once it's finished now that we've synced
|
|
18
|
+
* with Motion.
|
|
19
|
+
*
|
|
20
|
+
* Prefer onfinish over finished as onfinish is backwards compatible with
|
|
21
|
+
* older browsers.
|
|
22
|
+
*/
|
|
23
|
+
animation.onfinish = cancelAnimation;
|
|
24
|
+
if (startTime === null || ((_a = window.MotionHandoffIsComplete) === null || _a === void 0 ? void 0 : _a.call(window, elementId))) {
|
|
25
|
+
/**
|
|
26
|
+
* If the startTime is null, this animation is the Paint Ready detection animation
|
|
27
|
+
* and we can cancel it immediately without handoff.
|
|
28
|
+
*
|
|
29
|
+
* Or if we've already handed off the animation then we're now interrupting it.
|
|
30
|
+
* In which case we need to cancel it.
|
|
31
|
+
*/
|
|
32
|
+
cancelAnimation();
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return startTime;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { handoffOptimizedAppearAnimation };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { appearStoreId } from './store-id.mjs';
|
|
2
|
+
import { startWaapiAnimation } from '../animators/waapi/index.mjs';
|
|
3
|
+
import { optimizedAppearDataId } from './data-id.mjs';
|
|
4
|
+
import { handoffOptimizedAppearAnimation } from './handoff.mjs';
|
|
5
|
+
import { appearAnimationStore, appearComplete } from './store.mjs';
|
|
6
|
+
import { noop } from '../../utils/noop.mjs';
|
|
7
|
+
import { getOptimisedAppearId } from './get-appear-id.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A single time to use across all animations to manually set startTime
|
|
11
|
+
* and ensure they're all in sync.
|
|
12
|
+
*/
|
|
13
|
+
let startFrameTime;
|
|
14
|
+
/**
|
|
15
|
+
* A dummy animation to detect when Chrome is ready to start
|
|
16
|
+
* painting the page and hold off from triggering the real animation
|
|
17
|
+
* until then. We only need one animation to detect paint ready.
|
|
18
|
+
*
|
|
19
|
+
* https://bugs.chromium.org/p/chromium/issues/detail?id=1406850
|
|
20
|
+
*/
|
|
21
|
+
let readyAnimation;
|
|
22
|
+
/**
|
|
23
|
+
* Keep track of animations that were suspended vs cancelled so we
|
|
24
|
+
* can easily resume them when we're done measuring layout.
|
|
25
|
+
*/
|
|
26
|
+
const suspendedAnimations = new Set();
|
|
27
|
+
function resumeSuspendedAnimations() {
|
|
28
|
+
suspendedAnimations.forEach((data) => {
|
|
29
|
+
data.animation.play();
|
|
30
|
+
data.animation.startTime = data.startTime;
|
|
31
|
+
});
|
|
32
|
+
suspendedAnimations.clear();
|
|
33
|
+
}
|
|
34
|
+
function startOptimizedAppearAnimation(element, name, keyframes, options, onReady) {
|
|
35
|
+
// Prevent optimised appear animations if Motion has already started animating.
|
|
36
|
+
if (window.MotionIsMounted) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const id = element.dataset[optimizedAppearDataId];
|
|
40
|
+
if (!id)
|
|
41
|
+
return;
|
|
42
|
+
window.MotionHandoffAnimation = handoffOptimizedAppearAnimation;
|
|
43
|
+
const storeId = appearStoreId(id, name);
|
|
44
|
+
if (!readyAnimation) {
|
|
45
|
+
readyAnimation = startWaapiAnimation(element, name, [keyframes[0], keyframes[0]],
|
|
46
|
+
/**
|
|
47
|
+
* 10 secs is basically just a super-safe duration to give Chrome
|
|
48
|
+
* long enough to get the animation ready.
|
|
49
|
+
*/
|
|
50
|
+
{ duration: 10000, ease: "linear" });
|
|
51
|
+
appearAnimationStore.set(storeId, {
|
|
52
|
+
animation: readyAnimation,
|
|
53
|
+
startTime: null,
|
|
54
|
+
});
|
|
55
|
+
/**
|
|
56
|
+
* If there's no readyAnimation then there's been no instantiation
|
|
57
|
+
* of handoff animations.
|
|
58
|
+
*/
|
|
59
|
+
window.MotionHandoffAnimation = handoffOptimizedAppearAnimation;
|
|
60
|
+
window.MotionHasOptimisedAnimation = (elementId, valueName) => {
|
|
61
|
+
if (!elementId)
|
|
62
|
+
return false;
|
|
63
|
+
/**
|
|
64
|
+
* Keep a map of elementIds that have started animating. We check
|
|
65
|
+
* via ID instead of Element because of hydration errors and
|
|
66
|
+
* pre-hydration checks. We also actively record IDs as they start
|
|
67
|
+
* animating rather than simply checking for data-appear-id as
|
|
68
|
+
* this attrbute might be present but not lead to an animation, for
|
|
69
|
+
* instance if the element's appear animation is on a different
|
|
70
|
+
* breakpoint.
|
|
71
|
+
*/
|
|
72
|
+
if (!valueName) {
|
|
73
|
+
return appearComplete.has(elementId);
|
|
74
|
+
}
|
|
75
|
+
const animationId = appearStoreId(elementId, valueName);
|
|
76
|
+
return Boolean(appearAnimationStore.get(animationId));
|
|
77
|
+
};
|
|
78
|
+
window.MotionHandoffMarkAsComplete = (elementId) => {
|
|
79
|
+
if (appearComplete.has(elementId)) {
|
|
80
|
+
appearComplete.set(elementId, true);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
window.MotionHandoffIsComplete = (elementId) => {
|
|
84
|
+
return appearComplete.get(elementId) === true;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* We only need to cancel transform animations as
|
|
88
|
+
* they're the ones that will interfere with the
|
|
89
|
+
* layout animation measurements.
|
|
90
|
+
*/
|
|
91
|
+
window.MotionCancelOptimisedAnimation = (elementId, valueName, frame, canResume) => {
|
|
92
|
+
const animationId = appearStoreId(elementId, valueName);
|
|
93
|
+
const data = appearAnimationStore.get(animationId);
|
|
94
|
+
if (!data)
|
|
95
|
+
return;
|
|
96
|
+
if (frame && canResume === undefined) {
|
|
97
|
+
/**
|
|
98
|
+
* Wait until the end of the subsequent frame to cancel the animation
|
|
99
|
+
* to ensure we don't remove the animation before the main thread has
|
|
100
|
+
* had a chance to resolve keyframes and render.
|
|
101
|
+
*/
|
|
102
|
+
frame.postRender(() => {
|
|
103
|
+
frame.postRender(() => {
|
|
104
|
+
data.animation.cancel();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
data.animation.cancel();
|
|
110
|
+
}
|
|
111
|
+
if (frame && canResume) {
|
|
112
|
+
suspendedAnimations.add(data);
|
|
113
|
+
frame.render(resumeSuspendedAnimations);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
appearAnimationStore.delete(animationId);
|
|
117
|
+
/**
|
|
118
|
+
* If there are no more animations left, we can remove the cancel function.
|
|
119
|
+
* This will let us know when we can stop checking for conflicting layout animations.
|
|
120
|
+
*/
|
|
121
|
+
if (!appearAnimationStore.size) {
|
|
122
|
+
window.MotionCancelOptimisedAnimation = undefined;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
window.MotionCheckAppearSync = (visualElement, valueName, value) => {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
const appearId = getOptimisedAppearId(visualElement);
|
|
129
|
+
if (!appearId)
|
|
130
|
+
return;
|
|
131
|
+
const valueIsOptimised = (_a = window.MotionHasOptimisedAnimation) === null || _a === void 0 ? void 0 : _a.call(window, appearId, valueName);
|
|
132
|
+
const externalAnimationValue = (_b = visualElement.props.values) === null || _b === void 0 ? void 0 : _b[valueName];
|
|
133
|
+
if (!valueIsOptimised || !externalAnimationValue)
|
|
134
|
+
return;
|
|
135
|
+
const removeSyncCheck = value.on("change", (latestValue) => {
|
|
136
|
+
var _a;
|
|
137
|
+
if (externalAnimationValue.get() !== latestValue) {
|
|
138
|
+
(_a = window.MotionCancelOptimisedAnimation) === null || _a === void 0 ? void 0 : _a.call(window, appearId, valueName);
|
|
139
|
+
removeSyncCheck();
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return removeSyncCheck;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const startAnimation = () => {
|
|
146
|
+
readyAnimation.cancel();
|
|
147
|
+
const appearAnimation = startWaapiAnimation(element, name, keyframes, options);
|
|
148
|
+
/**
|
|
149
|
+
* Record the time of the first started animation. We call performance.now() once
|
|
150
|
+
* here and once in handoff to ensure we're getting
|
|
151
|
+
* close to a frame-locked time. This keeps all animations in sync.
|
|
152
|
+
*/
|
|
153
|
+
if (startFrameTime === undefined) {
|
|
154
|
+
startFrameTime = performance.now();
|
|
155
|
+
}
|
|
156
|
+
appearAnimation.startTime = startFrameTime;
|
|
157
|
+
appearAnimationStore.set(storeId, {
|
|
158
|
+
animation: appearAnimation,
|
|
159
|
+
startTime: startFrameTime,
|
|
160
|
+
});
|
|
161
|
+
if (onReady)
|
|
162
|
+
onReady(appearAnimation);
|
|
163
|
+
};
|
|
164
|
+
appearComplete.set(id, false);
|
|
165
|
+
if (readyAnimation.ready) {
|
|
166
|
+
readyAnimation.ready.then(startAnimation).catch(noop);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
startAnimation();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export { startOptimizedAppearAnimation };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { useId, useRef, useContext, useInsertionEffect } from 'react';
|
|
5
|
+
import { MotionConfigContext } from '../../context/MotionConfigContext.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Measurement functionality has to be within a separate component
|
|
9
|
+
* to leverage snapshot lifecycle.
|
|
10
|
+
*/
|
|
11
|
+
class PopChildMeasure extends React.Component {
|
|
12
|
+
getSnapshotBeforeUpdate(prevProps) {
|
|
13
|
+
const element = this.props.childRef.current;
|
|
14
|
+
if (element && prevProps.isPresent && !this.props.isPresent) {
|
|
15
|
+
const size = this.props.sizeRef.current;
|
|
16
|
+
size.height = element.offsetHeight || 0;
|
|
17
|
+
size.width = element.offsetWidth || 0;
|
|
18
|
+
size.top = element.offsetTop;
|
|
19
|
+
size.left = element.offsetLeft;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Required with getSnapshotBeforeUpdate to stop React complaining.
|
|
25
|
+
*/
|
|
26
|
+
componentDidUpdate() { }
|
|
27
|
+
render() {
|
|
28
|
+
return this.props.children;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function PopChild({ children, isPresent }) {
|
|
32
|
+
const id = useId();
|
|
33
|
+
const ref = useRef(null);
|
|
34
|
+
const size = useRef({
|
|
35
|
+
width: 0,
|
|
36
|
+
height: 0,
|
|
37
|
+
top: 0,
|
|
38
|
+
left: 0,
|
|
39
|
+
});
|
|
40
|
+
const { nonce } = useContext(MotionConfigContext);
|
|
41
|
+
/**
|
|
42
|
+
* We create and inject a style block so we can apply this explicit
|
|
43
|
+
* sizing in a non-destructive manner by just deleting the style block.
|
|
44
|
+
*
|
|
45
|
+
* We can't apply size via render as the measurement happens
|
|
46
|
+
* in getSnapshotBeforeUpdate (post-render), likewise if we apply the
|
|
47
|
+
* styles directly on the DOM node, we might be overwriting
|
|
48
|
+
* styles set via the style prop.
|
|
49
|
+
*/
|
|
50
|
+
useInsertionEffect(() => {
|
|
51
|
+
const { width, height, top, left } = size.current;
|
|
52
|
+
if (isPresent || !ref.current || !width || !height)
|
|
53
|
+
return;
|
|
54
|
+
ref.current.dataset.motionPopId = id;
|
|
55
|
+
const style = document.createElement("style");
|
|
56
|
+
if (nonce)
|
|
57
|
+
style.nonce = nonce;
|
|
58
|
+
document.head.appendChild(style);
|
|
59
|
+
if (style.sheet) {
|
|
60
|
+
style.sheet.insertRule(`
|
|
61
|
+
[data-motion-pop-id="${id}"] {
|
|
62
|
+
position: absolute !important;
|
|
63
|
+
width: ${width}px !important;
|
|
64
|
+
height: ${height}px !important;
|
|
65
|
+
top: ${top}px !important;
|
|
66
|
+
left: ${left}px !important;
|
|
67
|
+
}
|
|
68
|
+
`);
|
|
69
|
+
}
|
|
70
|
+
return () => {
|
|
71
|
+
document.head.removeChild(style);
|
|
72
|
+
};
|
|
73
|
+
}, [isPresent]);
|
|
74
|
+
return (jsx(PopChildMeasure, { isPresent: isPresent, childRef: ref, sizeRef: size, children: React.cloneElement(children, { ref }) }));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { PopChild };
|