framer-motion 7.0.3 → 7.1.2
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 +2090 -2304
- package/dist/es/animation/animate.mjs +4 -5
- package/dist/es/animation/animation-controls.mjs +22 -24
- package/dist/es/animation/use-animated-state.mjs +23 -25
- package/dist/es/animation/use-animation.mjs +2 -2
- package/dist/es/animation/utils/default-transitions.mjs +13 -14
- package/dist/es/animation/utils/easing.mjs +20 -21
- package/dist/es/animation/utils/is-animatable.mjs +1 -1
- package/dist/es/animation/utils/is-keyframes-target.mjs +1 -1
- package/dist/es/animation/utils/transitions.mjs +30 -31
- package/dist/es/components/AnimatePresence/PresenceChild.mjs +18 -31
- package/dist/es/components/AnimatePresence/index.mjs +33 -35
- package/dist/es/components/AnimatePresence/use-presence.mjs +5 -5
- package/dist/es/components/AnimateSharedLayout.mjs +4 -5
- package/dist/es/components/LayoutGroup/index.mjs +12 -16
- package/dist/es/components/LazyMotion/index.mjs +9 -10
- package/dist/es/components/MotionConfig/index.mjs +5 -5
- package/dist/es/components/Reorder/Group.mjs +16 -16
- package/dist/es/components/Reorder/Item.mjs +14 -18
- package/dist/es/components/Reorder/index.mjs +3 -3
- package/dist/es/components/Reorder/utils/check-reorder.mjs +6 -6
- package/dist/es/context/DeprecatedLayoutGroupContext.mjs +1 -1
- package/dist/es/context/LayoutGroupContext.mjs +1 -1
- package/dist/es/context/LazyContext.mjs +1 -1
- package/dist/es/context/MotionConfigContext.mjs +2 -2
- package/dist/es/context/MotionContext/create.mjs +2 -2
- package/dist/es/context/MotionContext/index.mjs +1 -1
- package/dist/es/context/MotionContext/utils.mjs +1 -1
- package/dist/es/context/PresenceContext.mjs +1 -1
- package/dist/es/context/ReorderContext.mjs +1 -1
- package/dist/es/context/SwitchLayoutGroupContext.mjs +1 -1
- package/dist/es/events/event-info.mjs +11 -17
- package/dist/es/events/use-dom-event.mjs +4 -5
- package/dist/es/events/use-pointer-event.mjs +2 -2
- package/dist/es/events/utils.mjs +3 -9
- package/dist/es/gestures/PanSession.mjs +42 -47
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +147 -157
- package/dist/es/gestures/drag/use-drag-controls.mjs +10 -12
- package/dist/es/gestures/drag/use-drag.mjs +4 -4
- package/dist/es/gestures/drag/utils/constraints.mjs +12 -17
- package/dist/es/gestures/drag/utils/lock.mjs +17 -17
- package/dist/es/gestures/use-focus-gesture.mjs +3 -4
- package/dist/es/gestures/use-hover-gesture.mjs +2 -3
- package/dist/es/gestures/use-pan-gesture.mjs +9 -10
- package/dist/es/gestures/use-tap-gesture.mjs +5 -6
- package/dist/es/gestures/utils/event-type.mjs +1 -1
- package/dist/es/gestures/utils/is-node-or-child.mjs +1 -1
- package/dist/es/index.mjs +1 -0
- package/dist/es/motion/features/animations.mjs +9 -11
- package/dist/es/motion/features/definitions.mjs +5 -5
- package/dist/es/motion/features/drag.mjs +1 -1
- package/dist/es/motion/features/gestures.mjs +1 -1
- package/dist/es/motion/features/layout/MeasureLayout.mjs +32 -40
- package/dist/es/motion/features/layout/index.mjs +1 -1
- package/dist/es/motion/features/use-features.mjs +8 -9
- package/dist/es/motion/features/use-projection.mjs +10 -11
- package/dist/es/motion/features/viewport/observers.mjs +12 -12
- package/dist/es/motion/features/viewport/use-viewport.mjs +17 -20
- package/dist/es/motion/index.mjs +13 -16
- package/dist/es/motion/utils/VisualElementHandler.mjs +10 -16
- package/dist/es/motion/utils/is-forced-motion-value.mjs +1 -2
- package/dist/es/motion/utils/make-renderless-component.mjs +2 -2
- package/dist/es/motion/utils/use-motion-ref.mjs +1 -1
- package/dist/es/motion/utils/use-visual-element.mjs +13 -13
- package/dist/es/motion/utils/use-visual-state.mjs +26 -31
- package/dist/es/motion/utils/valid-prop.mjs +1 -1
- package/dist/es/projection/animation/mix-values.mjs +12 -16
- package/dist/es/projection/geometry/conversion.mjs +4 -6
- package/dist/es/projection/geometry/delta-apply.mjs +14 -20
- package/dist/es/projection/geometry/delta-calc.mjs +2 -5
- package/dist/es/projection/geometry/delta-remove.mjs +6 -13
- package/dist/es/projection/geometry/models.mjs +7 -7
- package/dist/es/projection/node/DocumentProjectionNode.mjs +5 -5
- package/dist/es/projection/node/HTMLProjectionNode.mjs +8 -10
- package/dist/es/projection/node/create-projection-node.mjs +283 -307
- package/dist/es/projection/node/group.mjs +6 -8
- package/dist/es/projection/node/id.mjs +2 -2
- package/dist/es/projection/node/state.mjs +1 -1
- package/dist/es/projection/shared/stack.mjs +26 -27
- package/dist/es/projection/styles/scale-border-radius.mjs +5 -5
- package/dist/es/projection/styles/scale-box-shadow.mjs +18 -19
- package/dist/es/projection/styles/scale-correction.mjs +1 -1
- package/dist/es/projection/styles/transform.mjs +12 -12
- package/dist/es/projection/use-reset-projection.mjs +2 -2
- package/dist/es/projection/utils/has-transform.mjs +1 -2
- package/dist/es/projection/utils/measure.mjs +2 -2
- package/dist/es/render/dom/create-visual-element.mjs +1 -1
- package/dist/es/render/dom/features-animation.mjs +1 -2
- package/dist/es/render/dom/features-max.mjs +1 -2
- package/dist/es/render/dom/motion-minimal.mjs +1 -1
- package/dist/es/render/dom/motion-proxy.mjs +3 -4
- package/dist/es/render/dom/motion.mjs +2 -5
- package/dist/es/render/dom/use-render.mjs +6 -9
- package/dist/es/render/dom/utils/camel-to-dash.mjs +3 -5
- package/dist/es/render/dom/utils/create-config.mjs +5 -5
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +19 -20
- package/dist/es/render/dom/utils/filter-props.mjs +4 -6
- package/dist/es/render/dom/utils/parse-dom-variant.mjs +2 -2
- package/dist/es/render/dom/utils/unit-conversion.mjs +68 -99
- package/dist/es/render/dom/value-types/animatable-none.mjs +1 -1
- package/dist/es/render/dom/value-types/defaults.mjs +4 -5
- package/dist/es/render/dom/value-types/dimensions.mjs +2 -4
- package/dist/es/render/dom/value-types/find.mjs +2 -3
- package/dist/es/render/dom/value-types/get-as-type.mjs +1 -1
- package/dist/es/render/dom/value-types/number.mjs +2 -2
- package/dist/es/render/dom/value-types/test.mjs +1 -1
- package/dist/es/render/dom/value-types/type-auto.mjs +3 -3
- package/dist/es/render/dom/value-types/type-int.mjs +1 -2
- package/dist/es/render/html/config-motion.mjs +1 -1
- package/dist/es/render/html/use-props.mjs +11 -13
- package/dist/es/render/html/utils/build-styles.mjs +8 -8
- package/dist/es/render/html/utils/build-transform.mjs +11 -16
- package/dist/es/render/html/utils/create-render-state.mjs +2 -2
- package/dist/es/render/html/utils/render.mjs +2 -3
- package/dist/es/render/html/utils/scrape-motion-values.mjs +3 -3
- package/dist/es/render/html/utils/transform.mjs +6 -10
- package/dist/es/render/html/visual-element.mjs +22 -23
- package/dist/es/render/index.mjs +359 -364
- package/dist/es/render/svg/config-motion.mjs +2 -3
- package/dist/es/render/svg/lowercase-elements.mjs +1 -1
- package/dist/es/render/svg/use-props.mjs +5 -6
- package/dist/es/render/svg/utils/build-attrs.mjs +2 -2
- package/dist/es/render/svg/utils/camel-case-attrs.mjs +1 -1
- package/dist/es/render/svg/utils/create-render-state.mjs +1 -2
- package/dist/es/render/svg/utils/path.mjs +7 -10
- package/dist/es/render/svg/utils/render.mjs +1 -1
- package/dist/es/render/svg/utils/scrape-motion-values.mjs +3 -3
- package/dist/es/render/svg/utils/transform-origin.mjs +3 -3
- package/dist/es/render/svg/visual-element.mjs +6 -4
- package/dist/es/render/utils/animation-state.mjs +71 -87
- package/dist/es/render/utils/animation.mjs +48 -60
- package/dist/es/render/utils/compare-by-depth.mjs +1 -3
- package/dist/es/render/utils/flat-tree.mjs +9 -10
- package/dist/es/render/utils/lifecycles.mjs +12 -19
- package/dist/es/render/utils/motion-values.mjs +16 -8
- package/dist/es/render/utils/setters.mjs +19 -19
- package/dist/es/render/utils/variants.mjs +6 -8
- package/dist/es/utils/array.mjs +9 -10
- package/dist/es/utils/is-browser.mjs +1 -1
- package/dist/es/utils/is-numerical-string.mjs +1 -1
- package/dist/es/utils/is-zero-value-string.mjs +1 -1
- package/dist/es/utils/process.mjs +2 -2
- package/dist/es/utils/resolve-value.mjs +2 -2
- package/dist/es/utils/shallow-compare.mjs +2 -2
- package/dist/es/utils/subscription-manager.mjs +15 -17
- package/dist/es/utils/time-conversion.mjs +1 -1
- package/dist/es/utils/transform.mjs +10 -15
- package/dist/es/utils/use-animation-frame.mjs +5 -6
- package/dist/es/utils/use-constant.mjs +1 -1
- package/dist/es/utils/use-cycle.mjs +9 -10
- package/dist/es/utils/use-force-update.mjs +4 -5
- package/dist/es/utils/use-in-view.mjs +7 -9
- package/dist/es/utils/use-instant-transition-state.mjs +1 -1
- package/dist/es/utils/use-instant-transition.mjs +6 -9
- package/dist/es/utils/use-is-mounted.mjs +3 -3
- package/dist/es/utils/use-isomorphic-effect.mjs +1 -1
- package/dist/es/utils/use-reduced-motion.mjs +8 -11
- package/dist/es/utils/use-unmount-effect.mjs +1 -1
- package/dist/es/utils/warn-once.mjs +1 -1
- package/dist/es/value/index.mjs +53 -59
- package/dist/es/value/use-combine-values.mjs +3 -3
- package/dist/es/value/use-inverted-scale.mjs +9 -11
- package/dist/es/value/use-motion-template.mjs +5 -9
- package/dist/es/value/use-motion-value.mjs +4 -5
- package/dist/es/value/use-on-change.mjs +4 -4
- package/dist/es/value/use-scroll.mjs +9 -11
- package/dist/es/value/use-spring.mjs +8 -10
- package/dist/es/value/use-time.mjs +2 -2
- package/dist/es/value/use-transform.mjs +6 -10
- package/dist/es/value/use-velocity.mjs +3 -3
- package/dist/es/value/use-will-change/index.mjs +50 -0
- package/dist/es/value/use-will-change/is.mjs +7 -0
- package/dist/es/value/utils/is-motion-value.mjs +1 -1
- package/dist/es/value/utils/resolve-motion-value.mjs +1 -1
- package/dist/framer-motion.dev.js +2134 -2414
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/projection.dev.js +1154 -1300
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- 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 +0 -1
- package/package.json +12 -12
|
@@ -29,13 +29,12 @@ import { startAnimation } from './utils/transitions.mjs';
|
|
|
29
29
|
*
|
|
30
30
|
* @public
|
|
31
31
|
*/
|
|
32
|
-
function animate(from, to, transition) {
|
|
33
|
-
|
|
34
|
-
var value = isMotionValue(from) ? from : motionValue(from);
|
|
32
|
+
function animate(from, to, transition = {}) {
|
|
33
|
+
const value = isMotionValue(from) ? from : motionValue(from);
|
|
35
34
|
startAnimation("", value, to, transition);
|
|
36
35
|
return {
|
|
37
|
-
stop:
|
|
38
|
-
isAnimating:
|
|
36
|
+
stop: () => value.stop(),
|
|
37
|
+
isAnimating: () => value.isAnimating(),
|
|
39
38
|
};
|
|
40
39
|
}
|
|
41
40
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __spreadArray, __read } from 'tslib';
|
|
2
1
|
import { invariant } from 'hey-listen';
|
|
3
2
|
import { stopAnimation, animateVisualElement } from '../render/utils/animation.mjs';
|
|
4
3
|
import { setValues } from '../render/utils/setters.mjs';
|
|
@@ -10,22 +9,22 @@ function animationControls() {
|
|
|
10
9
|
/**
|
|
11
10
|
* Track whether the host component has mounted.
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
let hasMounted = false;
|
|
14
13
|
/**
|
|
15
14
|
* Pending animations that are started before a component is mounted.
|
|
16
15
|
* TODO: Remove this as animations should only run in effects
|
|
17
16
|
*/
|
|
18
|
-
|
|
17
|
+
const pendingAnimations = [];
|
|
19
18
|
/**
|
|
20
19
|
* A collection of linked component animation controls.
|
|
21
20
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
subscribe
|
|
21
|
+
const subscribers = new Set();
|
|
22
|
+
const controls = {
|
|
23
|
+
subscribe(visualElement) {
|
|
25
24
|
subscribers.add(visualElement);
|
|
26
|
-
return
|
|
25
|
+
return () => void subscribers.delete(visualElement);
|
|
27
26
|
},
|
|
28
|
-
start
|
|
27
|
+
start(definition, transitionOverride) {
|
|
29
28
|
/**
|
|
30
29
|
* TODO: We only perform this hasMounted check because in Framer we used to
|
|
31
30
|
* encourage the ability to start an animation within the render phase. This
|
|
@@ -33,41 +32,40 @@ function animationControls() {
|
|
|
33
32
|
* we can ditch this.
|
|
34
33
|
*/
|
|
35
34
|
if (hasMounted) {
|
|
36
|
-
|
|
37
|
-
subscribers.forEach(
|
|
38
|
-
|
|
39
|
-
transitionOverride
|
|
35
|
+
const animations = [];
|
|
36
|
+
subscribers.forEach((visualElement) => {
|
|
37
|
+
animations.push(animateVisualElement(visualElement, definition, {
|
|
38
|
+
transitionOverride,
|
|
40
39
|
}));
|
|
41
40
|
});
|
|
42
|
-
return Promise.all(
|
|
41
|
+
return Promise.all(animations);
|
|
43
42
|
}
|
|
44
43
|
else {
|
|
45
|
-
return new Promise(
|
|
44
|
+
return new Promise((resolve) => {
|
|
46
45
|
pendingAnimations.push({
|
|
47
46
|
animation: [definition, transitionOverride],
|
|
48
|
-
resolve
|
|
47
|
+
resolve,
|
|
49
48
|
});
|
|
50
49
|
});
|
|
51
50
|
}
|
|
52
51
|
},
|
|
53
|
-
set
|
|
52
|
+
set(definition) {
|
|
54
53
|
invariant(hasMounted, "controls.set() should only be called after a component has mounted. Consider calling within a useEffect hook.");
|
|
55
|
-
return subscribers.forEach(
|
|
54
|
+
return subscribers.forEach((visualElement) => {
|
|
56
55
|
setValues(visualElement, definition);
|
|
57
56
|
});
|
|
58
57
|
},
|
|
59
|
-
stop
|
|
60
|
-
subscribers.forEach(
|
|
58
|
+
stop() {
|
|
59
|
+
subscribers.forEach((visualElement) => {
|
|
61
60
|
stopAnimation(visualElement);
|
|
62
61
|
});
|
|
63
62
|
},
|
|
64
|
-
mount
|
|
63
|
+
mount() {
|
|
65
64
|
hasMounted = true;
|
|
66
|
-
pendingAnimations.forEach(
|
|
67
|
-
|
|
68
|
-
controls.start.apply(controls, __spreadArray([], __read(animation), false)).then(resolve);
|
|
65
|
+
pendingAnimations.forEach(({ animation, resolve }) => {
|
|
66
|
+
controls.start(...animation).then(resolve);
|
|
69
67
|
});
|
|
70
|
-
return
|
|
68
|
+
return () => {
|
|
71
69
|
hasMounted = false;
|
|
72
70
|
controls.stop();
|
|
73
71
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __rest
|
|
1
|
+
import { __rest } from 'tslib';
|
|
2
2
|
import { useState, useEffect } from 'react';
|
|
3
3
|
import { useConstant } from '../utils/use-constant.mjs';
|
|
4
4
|
import { getOrigin, checkTargetForNewValues } from '../render/utils/setters.mjs';
|
|
@@ -7,26 +7,26 @@ import { animateVisualElement } from '../render/utils/animation.mjs';
|
|
|
7
7
|
import { makeUseVisualState } from '../motion/utils/use-visual-state.mjs';
|
|
8
8
|
import { createBox } from '../projection/geometry/models.mjs';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
build
|
|
10
|
+
const createObject = () => ({});
|
|
11
|
+
const stateVisualElement = visualElement({
|
|
12
|
+
build() { },
|
|
13
13
|
measureViewportBox: createBox,
|
|
14
|
-
resetTransform
|
|
15
|
-
restoreTransform
|
|
16
|
-
removeValueFromRenderState
|
|
17
|
-
render
|
|
14
|
+
resetTransform() { },
|
|
15
|
+
restoreTransform() { },
|
|
16
|
+
removeValueFromRenderState() { },
|
|
17
|
+
render() { },
|
|
18
18
|
scrapeMotionValuesFromProps: createObject,
|
|
19
|
-
readValueFromInstance
|
|
19
|
+
readValueFromInstance(_state, key, options) {
|
|
20
20
|
return options.initialState[key] || 0;
|
|
21
21
|
},
|
|
22
|
-
makeTargetAnimatable
|
|
23
|
-
var
|
|
24
|
-
|
|
22
|
+
makeTargetAnimatable(element, _a) {
|
|
23
|
+
var { transition, transitionEnd } = _a, target = __rest(_a, ["transition", "transitionEnd"]);
|
|
24
|
+
const origin = getOrigin(target, transition || {}, element);
|
|
25
25
|
checkTargetForNewValues(element, target, origin);
|
|
26
|
-
return
|
|
26
|
+
return Object.assign({ transition, transitionEnd }, target);
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
|
-
|
|
29
|
+
const useVisualState = makeUseVisualState({
|
|
30
30
|
scrapeMotionValuesFromProps: createObject,
|
|
31
31
|
createRenderState: createObject,
|
|
32
32
|
});
|
|
@@ -35,25 +35,23 @@ var useVisualState = makeUseVisualState({
|
|
|
35
35
|
* on any version.
|
|
36
36
|
*/
|
|
37
37
|
function useAnimatedState(initialState) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
});
|
|
43
|
-
useEffect(function () {
|
|
38
|
+
const [animationState, setAnimationState] = useState(initialState);
|
|
39
|
+
const visualState = useVisualState({}, false);
|
|
40
|
+
const element = useConstant(() => stateVisualElement({ props: {}, visualState }, { initialState }));
|
|
41
|
+
useEffect(() => {
|
|
44
42
|
element.mount({});
|
|
45
43
|
return element.unmount;
|
|
46
44
|
}, [element]);
|
|
47
|
-
useEffect(
|
|
45
|
+
useEffect(() => {
|
|
48
46
|
element.setProps({
|
|
49
|
-
onUpdate:
|
|
50
|
-
setAnimationState(
|
|
47
|
+
onUpdate: (v) => {
|
|
48
|
+
setAnimationState(Object.assign({}, v));
|
|
51
49
|
},
|
|
52
50
|
});
|
|
53
51
|
}, [setAnimationState, element]);
|
|
54
|
-
|
|
52
|
+
const startAnimation = useConstant(() => (animationDefinition) => {
|
|
55
53
|
return animateVisualElement(element, animationDefinition);
|
|
56
|
-
}
|
|
54
|
+
});
|
|
57
55
|
return [animationState, startAnimation];
|
|
58
56
|
}
|
|
59
57
|
|
|
@@ -32,10 +32,10 @@ import { useConstant } from '../utils/use-constant.mjs';
|
|
|
32
32
|
* @public
|
|
33
33
|
*/
|
|
34
34
|
function useAnimationControls() {
|
|
35
|
-
|
|
35
|
+
const controls = useConstant(animationControls);
|
|
36
36
|
useEffect(controls.mount, []);
|
|
37
37
|
return controls;
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
const useAnimation = useAnimationControls;
|
|
40
40
|
|
|
41
41
|
export { useAnimation, useAnimationControls };
|
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { isKeyframesTarget } from './is-keyframes-target.mjs';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
const underDampedSpring = () => ({
|
|
5
4
|
type: "spring",
|
|
6
5
|
stiffness: 500,
|
|
7
6
|
damping: 25,
|
|
8
7
|
restSpeed: 10,
|
|
9
|
-
});
|
|
10
|
-
|
|
8
|
+
});
|
|
9
|
+
const criticallyDampedSpring = (to) => ({
|
|
11
10
|
type: "spring",
|
|
12
11
|
stiffness: 550,
|
|
13
12
|
damping: to === 0 ? 2 * Math.sqrt(550) : 30,
|
|
14
13
|
restSpeed: 10,
|
|
15
|
-
});
|
|
16
|
-
|
|
14
|
+
});
|
|
15
|
+
const linearTween = () => ({
|
|
17
16
|
type: "keyframes",
|
|
18
17
|
ease: "linear",
|
|
19
18
|
duration: 0.3,
|
|
20
|
-
});
|
|
21
|
-
|
|
19
|
+
});
|
|
20
|
+
const keyframes = (values) => ({
|
|
22
21
|
type: "keyframes",
|
|
23
22
|
duration: 0.8,
|
|
24
|
-
values
|
|
25
|
-
});
|
|
26
|
-
|
|
23
|
+
values,
|
|
24
|
+
});
|
|
25
|
+
const defaultTransitions = {
|
|
27
26
|
x: underDampedSpring,
|
|
28
27
|
y: underDampedSpring,
|
|
29
28
|
z: underDampedSpring,
|
|
@@ -39,8 +38,8 @@ var defaultTransitions = {
|
|
|
39
38
|
color: linearTween,
|
|
40
39
|
default: criticallyDampedSpring,
|
|
41
40
|
};
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const getDefaultTransition = (valueKey, to) => {
|
|
42
|
+
let transitionFactory;
|
|
44
43
|
if (isKeyframesTarget(to)) {
|
|
45
44
|
transitionFactory = keyframes;
|
|
46
45
|
}
|
|
@@ -48,7 +47,7 @@ var getDefaultTransition = function (valueKey, to) {
|
|
|
48
47
|
transitionFactory =
|
|
49
48
|
defaultTransitions[valueKey] || defaultTransitions.default;
|
|
50
49
|
}
|
|
51
|
-
return
|
|
50
|
+
return Object.assign({ to }, transitionFactory(to));
|
|
52
51
|
};
|
|
53
52
|
|
|
54
53
|
export { criticallyDampedSpring, getDefaultTransition, linearTween, underDampedSpring };
|
|
@@ -1,38 +1,37 @@
|
|
|
1
|
-
import { __read } from 'tslib';
|
|
2
1
|
import { invariant } from 'hey-listen';
|
|
3
2
|
import { cubicBezier, linear, easeIn, easeInOut, easeOut, circIn, circInOut, circOut, backIn, backInOut, backOut, anticipate, bounceIn, bounceInOut, bounceOut } from 'popmotion';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
linear
|
|
7
|
-
easeIn
|
|
8
|
-
easeInOut
|
|
9
|
-
easeOut
|
|
10
|
-
circIn
|
|
11
|
-
circInOut
|
|
12
|
-
circOut
|
|
13
|
-
backIn
|
|
14
|
-
backInOut
|
|
15
|
-
backOut
|
|
16
|
-
anticipate
|
|
17
|
-
bounceIn
|
|
18
|
-
bounceInOut
|
|
19
|
-
bounceOut
|
|
4
|
+
const easingLookup = {
|
|
5
|
+
linear,
|
|
6
|
+
easeIn,
|
|
7
|
+
easeInOut,
|
|
8
|
+
easeOut,
|
|
9
|
+
circIn,
|
|
10
|
+
circInOut,
|
|
11
|
+
circOut,
|
|
12
|
+
backIn,
|
|
13
|
+
backInOut,
|
|
14
|
+
backOut,
|
|
15
|
+
anticipate,
|
|
16
|
+
bounceIn,
|
|
17
|
+
bounceInOut,
|
|
18
|
+
bounceOut,
|
|
20
19
|
};
|
|
21
|
-
|
|
20
|
+
const easingDefinitionToFunction = (definition) => {
|
|
22
21
|
if (Array.isArray(definition)) {
|
|
23
22
|
// If cubic bezier definition, create bezier curve
|
|
24
|
-
invariant(definition.length === 4,
|
|
25
|
-
|
|
23
|
+
invariant(definition.length === 4, `Cubic bezier arrays must contain four numerical values.`);
|
|
24
|
+
const [x1, y1, x2, y2] = definition;
|
|
26
25
|
return cubicBezier(x1, y1, x2, y2);
|
|
27
26
|
}
|
|
28
27
|
else if (typeof definition === "string") {
|
|
29
28
|
// Else lookup from table
|
|
30
|
-
invariant(easingLookup[definition] !== undefined,
|
|
29
|
+
invariant(easingLookup[definition] !== undefined, `Invalid easing type '${definition}'`);
|
|
31
30
|
return easingLookup[definition];
|
|
32
31
|
}
|
|
33
32
|
return definition;
|
|
34
33
|
};
|
|
35
|
-
|
|
34
|
+
const isEasingArray = (ease) => {
|
|
36
35
|
return Array.isArray(ease) && typeof ease[0] !== "number";
|
|
37
36
|
};
|
|
38
37
|
|
|
@@ -9,7 +9,7 @@ import { complex } from 'style-value-types';
|
|
|
9
9
|
*
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
const isAnimatable = (key, value) => {
|
|
13
13
|
// If the list of keys tat might be non-animatable grows, replace with Set
|
|
14
14
|
if (key === "zIndex")
|
|
15
15
|
return false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __rest } from 'tslib';
|
|
2
2
|
import { inertia, animate } from 'popmotion';
|
|
3
3
|
import { secondsToMilliseconds } from '../../utils/time-conversion.mjs';
|
|
4
4
|
import { isEasingArray, easingDefinitionToFunction } from './easing.mjs';
|
|
@@ -15,16 +15,16 @@ import { resolveFinalValueInKeyframes } from '../../utils/resolve-value.mjs';
|
|
|
15
15
|
* if any options are left.
|
|
16
16
|
*/
|
|
17
17
|
function isTransitionDefined(_a) {
|
|
18
|
-
|
|
18
|
+
var transition = __rest(_a, ["when", "delay", "delayChildren", "staggerChildren", "staggerDirection", "repeat", "repeatType", "repeatDelay", "from"]);
|
|
19
19
|
return !!Object.keys(transition).length;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
let legacyRepeatWarning = false;
|
|
22
22
|
/**
|
|
23
23
|
* Convert Framer Motion's Transition type into Popmotion-compatible options.
|
|
24
24
|
*/
|
|
25
25
|
function convertTransitionToAnimationOptions(_a) {
|
|
26
|
-
var
|
|
27
|
-
|
|
26
|
+
var { ease, times, yoyo, flip, loop } = _a, transition = __rest(_a, ["ease", "times", "yoyo", "flip", "loop"]);
|
|
27
|
+
const options = Object.assign({}, transition);
|
|
28
28
|
if (times)
|
|
29
29
|
options["offset"] = times;
|
|
30
30
|
/**
|
|
@@ -78,12 +78,12 @@ function convertTransitionToAnimationOptions(_a) {
|
|
|
78
78
|
*/
|
|
79
79
|
function getDelayFromTransition(transition, key) {
|
|
80
80
|
var _a, _b;
|
|
81
|
-
|
|
81
|
+
const valueTransition = getValueTransition(transition, key) || {};
|
|
82
82
|
return (_b = (_a = valueTransition.delay) !== null && _a !== void 0 ? _a : transition.delay) !== null && _b !== void 0 ? _b : 0;
|
|
83
83
|
}
|
|
84
84
|
function hydrateKeyframes(options) {
|
|
85
85
|
if (Array.isArray(options.to) && options.to[0] === null) {
|
|
86
|
-
options.to =
|
|
86
|
+
options.to = [...options.to];
|
|
87
87
|
options.to[0] = options.from;
|
|
88
88
|
}
|
|
89
89
|
return options;
|
|
@@ -98,18 +98,18 @@ function getPopmotionAnimationOptions(transition, options, key) {
|
|
|
98
98
|
* Get a default transition if none is determined to be defined.
|
|
99
99
|
*/
|
|
100
100
|
if (!isTransitionDefined(transition)) {
|
|
101
|
-
transition =
|
|
101
|
+
transition = Object.assign(Object.assign({}, transition), getDefaultTransition(key, options.to));
|
|
102
102
|
}
|
|
103
|
-
return
|
|
103
|
+
return Object.assign(Object.assign({}, options), convertTransitionToAnimationOptions(transition));
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
*
|
|
107
107
|
*/
|
|
108
108
|
function getAnimation(key, value, target, transition, onComplete) {
|
|
109
109
|
var _a;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
const valueTransition = getValueTransition(transition, key);
|
|
111
|
+
let origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
|
|
112
|
+
const isTargetAnimatable = isAnimatable(key, target);
|
|
113
113
|
if (origin === "none" && isTargetAnimatable && typeof target === "string") {
|
|
114
114
|
/**
|
|
115
115
|
* If we're trying to animate from "none", try and get an animatable version
|
|
@@ -125,24 +125,24 @@ function getAnimation(key, value, target, transition, onComplete) {
|
|
|
125
125
|
typeof origin === "string") {
|
|
126
126
|
target = getZeroUnit(origin);
|
|
127
127
|
}
|
|
128
|
-
|
|
129
|
-
warning(isOriginAnimatable === isTargetAnimatable,
|
|
128
|
+
const isOriginAnimatable = isAnimatable(key, origin);
|
|
129
|
+
warning(isOriginAnimatable === isTargetAnimatable, `You are trying to animate ${key} from "${origin}" to "${target}". ${origin} is not an animatable value - to enable this animation set ${origin} to a value animatable to ${target} via the \`style\` property.`);
|
|
130
130
|
function start() {
|
|
131
|
-
|
|
131
|
+
const options = {
|
|
132
132
|
from: origin,
|
|
133
133
|
to: target,
|
|
134
134
|
velocity: value.getVelocity(),
|
|
135
|
-
onComplete
|
|
136
|
-
onUpdate:
|
|
135
|
+
onComplete,
|
|
136
|
+
onUpdate: (v) => value.set(v),
|
|
137
137
|
};
|
|
138
138
|
return valueTransition.type === "inertia" ||
|
|
139
139
|
valueTransition.type === "decay"
|
|
140
|
-
? inertia(
|
|
141
|
-
: animate(
|
|
140
|
+
? inertia(Object.assign(Object.assign({}, options), valueTransition))
|
|
141
|
+
: animate(Object.assign(Object.assign({}, getPopmotionAnimationOptions(valueTransition, options, key)), { onUpdate: (v) => {
|
|
142
142
|
var _a;
|
|
143
143
|
options.onUpdate(v);
|
|
144
144
|
(_a = valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, v);
|
|
145
|
-
}, onComplete:
|
|
145
|
+
}, onComplete: () => {
|
|
146
146
|
var _a;
|
|
147
147
|
options.onComplete();
|
|
148
148
|
(_a = valueTransition.onComplete) === null || _a === void 0 ? void 0 : _a.call(valueTransition);
|
|
@@ -150,12 +150,12 @@ function getAnimation(key, value, target, transition, onComplete) {
|
|
|
150
150
|
}
|
|
151
151
|
function set() {
|
|
152
152
|
var _a, _b;
|
|
153
|
-
|
|
153
|
+
const finalTarget = resolveFinalValueInKeyframes(target);
|
|
154
154
|
value.set(finalTarget);
|
|
155
155
|
onComplete();
|
|
156
156
|
(_a = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onUpdate) === null || _a === void 0 ? void 0 : _a.call(valueTransition, finalTarget);
|
|
157
157
|
(_b = valueTransition === null || valueTransition === void 0 ? void 0 : valueTransition.onComplete) === null || _b === void 0 ? void 0 : _b.call(valueTransition);
|
|
158
|
-
return { stop:
|
|
158
|
+
return { stop: () => { } };
|
|
159
159
|
}
|
|
160
160
|
return !isOriginAnimatable ||
|
|
161
161
|
!isTargetAnimatable ||
|
|
@@ -181,24 +181,23 @@ function getValueTransition(transition, key) {
|
|
|
181
181
|
* Start animation on a MotionValue. This function is an interface between
|
|
182
182
|
* Framer Motion and Popmotion
|
|
183
183
|
*/
|
|
184
|
-
function startAnimation(key, value, target, transition) {
|
|
185
|
-
if (transition === void 0) { transition = {}; }
|
|
184
|
+
function startAnimation(key, value, target, transition = {}) {
|
|
186
185
|
if (instantAnimationState.current) {
|
|
187
186
|
transition = { type: false };
|
|
188
187
|
}
|
|
189
|
-
return value.start(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
188
|
+
return value.start((onComplete) => {
|
|
189
|
+
let delayTimer;
|
|
190
|
+
let controls;
|
|
191
|
+
const animation = getAnimation(key, value, target, transition, onComplete);
|
|
192
|
+
const delay = getDelayFromTransition(transition, key);
|
|
193
|
+
const start = () => (controls = animation());
|
|
195
194
|
if (delay) {
|
|
196
195
|
delayTimer = window.setTimeout(start, secondsToMilliseconds(delay));
|
|
197
196
|
}
|
|
198
197
|
else {
|
|
199
198
|
start();
|
|
200
199
|
}
|
|
201
|
-
return
|
|
200
|
+
return () => {
|
|
202
201
|
clearTimeout(delayTimer);
|
|
203
202
|
controls === null || controls === void 0 ? void 0 : controls.stop();
|
|
204
203
|
};
|
|
@@ -1,56 +1,43 @@
|
|
|
1
|
-
import { __values } from 'tslib';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useId, useMemo } from 'react';
|
|
4
3
|
import { PresenceContext } from '../../context/PresenceContext.mjs';
|
|
5
4
|
import { useConstant } from '../../utils/use-constant.mjs';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
onExitComplete: function (childId) {
|
|
17
|
-
var e_1, _a;
|
|
6
|
+
const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, presenceAffectsLayout, }) => {
|
|
7
|
+
const presenceChildren = useConstant(newChildrenMap);
|
|
8
|
+
const id = useId();
|
|
9
|
+
const context = useMemo(() => ({
|
|
10
|
+
id,
|
|
11
|
+
initial,
|
|
12
|
+
isPresent,
|
|
13
|
+
custom,
|
|
14
|
+
onExitComplete: (childId) => {
|
|
18
15
|
presenceChildren.set(childId, true);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!isComplete)
|
|
23
|
-
return; // can stop searching when any is incomplete
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
27
|
-
finally {
|
|
28
|
-
try {
|
|
29
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
30
|
-
}
|
|
31
|
-
finally { if (e_1) throw e_1.error; }
|
|
16
|
+
for (const isComplete of presenceChildren.values()) {
|
|
17
|
+
if (!isComplete)
|
|
18
|
+
return; // can stop searching when any is incomplete
|
|
32
19
|
}
|
|
33
20
|
onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete();
|
|
34
21
|
},
|
|
35
|
-
register:
|
|
22
|
+
register: (childId) => {
|
|
36
23
|
presenceChildren.set(childId, false);
|
|
37
|
-
return
|
|
24
|
+
return () => presenceChildren.delete(childId);
|
|
38
25
|
},
|
|
39
|
-
})
|
|
26
|
+
}),
|
|
40
27
|
/**
|
|
41
28
|
* If the presence of a child affects the layout of the components around it,
|
|
42
29
|
* we want to make a new context value to ensure they get re-rendered
|
|
43
30
|
* so they can detect that layout change.
|
|
44
31
|
*/
|
|
45
32
|
presenceAffectsLayout ? undefined : [isPresent]);
|
|
46
|
-
useMemo(
|
|
47
|
-
presenceChildren.forEach(
|
|
33
|
+
useMemo(() => {
|
|
34
|
+
presenceChildren.forEach((_, key) => presenceChildren.set(key, false));
|
|
48
35
|
}, [isPresent]);
|
|
49
36
|
/**
|
|
50
37
|
* If there's no `motion` components to fire exit animations, we want to remove this
|
|
51
38
|
* component immediately.
|
|
52
39
|
*/
|
|
53
|
-
React.useEffect(
|
|
40
|
+
React.useEffect(() => {
|
|
54
41
|
!isPresent && !presenceChildren.size && (onExitComplete === null || onExitComplete === void 0 ? void 0 : onExitComplete());
|
|
55
42
|
}, [isPresent]);
|
|
56
43
|
return (React.createElement(PresenceContext.Provider, { value: context }, children));
|