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
|
@@ -1,37 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __rest } from 'tslib';
|
|
2
2
|
import { startAnimation } from '../../animation/utils/transitions.mjs';
|
|
3
3
|
import { setTarget } from './setters.mjs';
|
|
4
4
|
import { resolveVariant } from './variants.mjs';
|
|
5
5
|
import { isTransformProp } from '../html/utils/transform.mjs';
|
|
6
|
+
import { isWillChangeMotionValue } from '../../value/use-will-change/is.mjs';
|
|
6
7
|
|
|
7
|
-
function animateVisualElement(visualElement, definition, options) {
|
|
8
|
-
if (options === void 0) { options = {}; }
|
|
8
|
+
function animateVisualElement(visualElement, definition, options = {}) {
|
|
9
9
|
visualElement.notifyAnimationStart(definition);
|
|
10
|
-
|
|
10
|
+
let animation;
|
|
11
11
|
if (Array.isArray(definition)) {
|
|
12
|
-
|
|
13
|
-
return animateVariant(visualElement, variant, options);
|
|
14
|
-
});
|
|
12
|
+
const animations = definition.map((variant) => animateVariant(visualElement, variant, options));
|
|
15
13
|
animation = Promise.all(animations);
|
|
16
14
|
}
|
|
17
15
|
else if (typeof definition === "string") {
|
|
18
16
|
animation = animateVariant(visualElement, definition, options);
|
|
19
17
|
}
|
|
20
18
|
else {
|
|
21
|
-
|
|
19
|
+
const resolvedDefinition = typeof definition === "function"
|
|
22
20
|
? resolveVariant(visualElement, definition, options.custom)
|
|
23
21
|
: definition;
|
|
24
22
|
animation = animateTarget(visualElement, resolvedDefinition, options);
|
|
25
23
|
}
|
|
26
|
-
return animation.then(
|
|
27
|
-
return visualElement.notifyAnimationComplete(definition);
|
|
28
|
-
});
|
|
24
|
+
return animation.then(() => visualElement.notifyAnimationComplete(definition));
|
|
29
25
|
}
|
|
30
|
-
function animateVariant(visualElement, variant, options) {
|
|
26
|
+
function animateVariant(visualElement, variant, options = {}) {
|
|
31
27
|
var _a;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var _b = (resolved || {}).transition, transition = _b === void 0 ? visualElement.getDefaultTransition() || {} : _b;
|
|
28
|
+
const resolved = resolveVariant(visualElement, variant, options.custom);
|
|
29
|
+
let { transition = visualElement.getDefaultTransition() || {} } = resolved || {};
|
|
35
30
|
if (options.transitionOverride) {
|
|
36
31
|
transition = options.transitionOverride;
|
|
37
32
|
}
|
|
@@ -39,29 +34,28 @@ function animateVariant(visualElement, variant, options) {
|
|
|
39
34
|
* If we have a variant, create a callback that runs it as an animation.
|
|
40
35
|
* Otherwise, we resolve a Promise immediately for a composable no-op.
|
|
41
36
|
*/
|
|
42
|
-
|
|
43
|
-
?
|
|
44
|
-
:
|
|
37
|
+
const getAnimation = resolved
|
|
38
|
+
? () => animateTarget(visualElement, resolved, options)
|
|
39
|
+
: () => Promise.resolve();
|
|
45
40
|
/**
|
|
46
41
|
* If we have children, create a callback that runs all their animations.
|
|
47
42
|
* Otherwise, we resolve a Promise immediately for a composable no-op.
|
|
48
43
|
*/
|
|
49
|
-
|
|
50
|
-
?
|
|
51
|
-
|
|
52
|
-
var _a = transition.delayChildren, delayChildren = _a === void 0 ? 0 : _a, staggerChildren = transition.staggerChildren, staggerDirection = transition.staggerDirection;
|
|
44
|
+
const getChildAnimations = ((_a = visualElement.variantChildren) === null || _a === void 0 ? void 0 : _a.size)
|
|
45
|
+
? (forwardDelay = 0) => {
|
|
46
|
+
const { delayChildren = 0, staggerChildren, staggerDirection, } = transition;
|
|
53
47
|
return animateChildren(visualElement, variant, delayChildren + forwardDelay, staggerChildren, staggerDirection, options);
|
|
54
48
|
}
|
|
55
|
-
:
|
|
49
|
+
: () => Promise.resolve();
|
|
56
50
|
/**
|
|
57
51
|
* If the transition explicitly defines a "when" option, we need to resolve either
|
|
58
52
|
* this animation or all children animations before playing the other.
|
|
59
53
|
*/
|
|
60
|
-
|
|
54
|
+
const { when } = transition;
|
|
61
55
|
if (when) {
|
|
62
|
-
|
|
56
|
+
const [first, last] = when === "beforeChildren"
|
|
63
57
|
? [getAnimation, getChildAnimations]
|
|
64
|
-
: [getChildAnimations, getAnimation]
|
|
58
|
+
: [getChildAnimations, getAnimation];
|
|
65
59
|
return first().then(last);
|
|
66
60
|
}
|
|
67
61
|
else {
|
|
@@ -71,61 +65,56 @@ function animateVariant(visualElement, variant, options) {
|
|
|
71
65
|
/**
|
|
72
66
|
* @internal
|
|
73
67
|
*/
|
|
74
|
-
function animateTarget(visualElement, definition,
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
function animateTarget(visualElement, definition, { delay = 0, transitionOverride, type } = {}) {
|
|
69
|
+
var _a;
|
|
70
|
+
let _b = visualElement.makeTargetAnimatable(definition), { transition = visualElement.getDefaultTransition(), transitionEnd } = _b, target = __rest(_b, ["transition", "transitionEnd"]);
|
|
71
|
+
const willChange = visualElement.getValue("willChange");
|
|
78
72
|
if (transitionOverride)
|
|
79
73
|
transition = transitionOverride;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
for (
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
const animations = [];
|
|
75
|
+
const animationTypeState = type && ((_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.getState()[type]);
|
|
76
|
+
for (const key in target) {
|
|
77
|
+
const value = visualElement.getValue(key);
|
|
78
|
+
const valueTarget = target[key];
|
|
85
79
|
if (!value ||
|
|
86
80
|
valueTarget === undefined ||
|
|
87
81
|
(animationTypeState &&
|
|
88
82
|
shouldBlockAnimation(animationTypeState, key))) {
|
|
89
83
|
continue;
|
|
90
84
|
}
|
|
91
|
-
|
|
85
|
+
let valueTransition = Object.assign({ delay }, transition);
|
|
92
86
|
/**
|
|
93
87
|
* Make animation instant if this is a transform prop and we should reduce motion.
|
|
94
88
|
*/
|
|
95
89
|
if (visualElement.shouldReduceMotion && isTransformProp(key)) {
|
|
96
|
-
valueTransition =
|
|
90
|
+
valueTransition = Object.assign(Object.assign({}, valueTransition), { type: false, delay: 0 });
|
|
91
|
+
}
|
|
92
|
+
let animation = startAnimation(key, value, valueTarget, valueTransition);
|
|
93
|
+
if (isWillChangeMotionValue(willChange)) {
|
|
94
|
+
willChange.add(key);
|
|
95
|
+
animation = animation.then(() => willChange.remove(key));
|
|
97
96
|
}
|
|
98
|
-
var animation = startAnimation(key, value, valueTarget, valueTransition);
|
|
99
97
|
animations.push(animation);
|
|
100
98
|
}
|
|
101
|
-
return Promise.all(animations).then(
|
|
99
|
+
return Promise.all(animations).then(() => {
|
|
102
100
|
transitionEnd && setTarget(visualElement, transitionEnd);
|
|
103
101
|
});
|
|
104
102
|
}
|
|
105
|
-
function animateChildren(visualElement, variant, delayChildren, staggerChildren, staggerDirection, options) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
var generateStaggerDuration = staggerDirection === 1
|
|
112
|
-
? function (i) {
|
|
113
|
-
if (i === void 0) { i = 0; }
|
|
114
|
-
return i * staggerChildren;
|
|
115
|
-
}
|
|
116
|
-
: function (i) {
|
|
117
|
-
if (i === void 0) { i = 0; }
|
|
118
|
-
return maxStaggerDuration - i * staggerChildren;
|
|
119
|
-
};
|
|
103
|
+
function animateChildren(visualElement, variant, delayChildren = 0, staggerChildren = 0, staggerDirection = 1, options) {
|
|
104
|
+
const animations = [];
|
|
105
|
+
const maxStaggerDuration = (visualElement.variantChildren.size - 1) * staggerChildren;
|
|
106
|
+
const generateStaggerDuration = staggerDirection === 1
|
|
107
|
+
? (i = 0) => i * staggerChildren
|
|
108
|
+
: (i = 0) => maxStaggerDuration - i * staggerChildren;
|
|
120
109
|
Array.from(visualElement.variantChildren)
|
|
121
110
|
.sort(sortByTreeOrder)
|
|
122
|
-
.forEach(
|
|
123
|
-
animations.push(animateVariant(child, variant,
|
|
111
|
+
.forEach((child, i) => {
|
|
112
|
+
animations.push(animateVariant(child, variant, Object.assign(Object.assign({}, options), { delay: delayChildren + generateStaggerDuration(i) })).then(() => child.notifyAnimationComplete(variant)));
|
|
124
113
|
});
|
|
125
114
|
return Promise.all(animations);
|
|
126
115
|
}
|
|
127
116
|
function stopAnimation(visualElement) {
|
|
128
|
-
visualElement.forEachValue(
|
|
117
|
+
visualElement.forEachValue((value) => value.stop());
|
|
129
118
|
}
|
|
130
119
|
function sortByTreeOrder(a, b) {
|
|
131
120
|
return a.sortNodePosition(b);
|
|
@@ -136,9 +125,8 @@ function sortByTreeOrder(a, b) {
|
|
|
136
125
|
* posed problems if an animation was triggered by afterChildren and protectedKeys
|
|
137
126
|
* had been set to true in the meantime.
|
|
138
127
|
*/
|
|
139
|
-
function shouldBlockAnimation(
|
|
140
|
-
|
|
141
|
-
var shouldBlock = protectedKeys.hasOwnProperty(key) && needsAnimating[key] !== true;
|
|
128
|
+
function shouldBlockAnimation({ protectedKeys, needsAnimating }, key) {
|
|
129
|
+
const shouldBlock = protectedKeys.hasOwnProperty(key) && needsAnimating[key] !== true;
|
|
142
130
|
needsAnimating[key] = false;
|
|
143
131
|
return shouldBlock;
|
|
144
132
|
}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { addUniqueItem, removeItem } from '../../utils/array.mjs';
|
|
2
2
|
import { compareByDepth } from './compare-by-depth.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class FlatTree {
|
|
5
|
+
constructor() {
|
|
6
6
|
this.children = [];
|
|
7
7
|
this.isDirty = false;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
add(child) {
|
|
10
10
|
addUniqueItem(this.children, child);
|
|
11
11
|
this.isDirty = true;
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
}
|
|
13
|
+
remove(child) {
|
|
14
14
|
removeItem(this.children, child);
|
|
15
15
|
this.isDirty = true;
|
|
16
|
-
}
|
|
17
|
-
|
|
16
|
+
}
|
|
17
|
+
forEach(callback) {
|
|
18
18
|
this.isDirty && this.children.sort(compareByDepth);
|
|
19
19
|
this.isDirty = false;
|
|
20
20
|
this.children.forEach(callback);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
24
23
|
|
|
25
24
|
export { FlatTree };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { __spreadArray, __read } from 'tslib';
|
|
2
1
|
import { SubscriptionManager } from '../../utils/subscription-manager.mjs';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
const names = [
|
|
5
4
|
"LayoutMeasure",
|
|
6
5
|
"BeforeLayoutMeasure",
|
|
7
6
|
"LayoutUpdate",
|
|
@@ -16,15 +15,15 @@ var names = [
|
|
|
16
15
|
"Unmount",
|
|
17
16
|
];
|
|
18
17
|
function createLifecycles() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
clearAllListeners:
|
|
23
|
-
updatePropListeners:
|
|
24
|
-
names.forEach(
|
|
18
|
+
const managers = names.map(() => new SubscriptionManager());
|
|
19
|
+
const propSubscriptions = {};
|
|
20
|
+
const lifecycles = {
|
|
21
|
+
clearAllListeners: () => managers.forEach((manager) => manager.clear()),
|
|
22
|
+
updatePropListeners: (props) => {
|
|
23
|
+
names.forEach((name) => {
|
|
25
24
|
var _a;
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const on = "on" + name;
|
|
26
|
+
const propListener = props[on];
|
|
28
27
|
// Unsubscribe existing subscription
|
|
29
28
|
(_a = propSubscriptions[name]) === null || _a === void 0 ? void 0 : _a.call(propSubscriptions);
|
|
30
29
|
// Add new subscription
|
|
@@ -34,15 +33,9 @@ function createLifecycles() {
|
|
|
34
33
|
});
|
|
35
34
|
},
|
|
36
35
|
};
|
|
37
|
-
managers.forEach(
|
|
38
|
-
lifecycles["on" + names[i]] =
|
|
39
|
-
lifecycles["notify" + names[i]] =
|
|
40
|
-
var args = [];
|
|
41
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
42
|
-
args[_i] = arguments[_i];
|
|
43
|
-
}
|
|
44
|
-
return manager.notify.apply(manager, __spreadArray([], __read(args), false));
|
|
45
|
-
};
|
|
36
|
+
managers.forEach((manager, i) => {
|
|
37
|
+
lifecycles["on" + names[i]] = (handler) => manager.add(handler);
|
|
38
|
+
lifecycles["notify" + names[i]] = (...args) => manager.notify(...args);
|
|
46
39
|
});
|
|
47
40
|
return lifecycles;
|
|
48
41
|
}
|
|
@@ -1,32 +1,40 @@
|
|
|
1
|
+
import { isWillChangeMotionValue } from '../../value/use-will-change/is.mjs';
|
|
1
2
|
import { warnOnce } from '../../utils/warn-once.mjs';
|
|
2
3
|
import { motionValue } from '../../value/index.mjs';
|
|
3
4
|
import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
|
|
4
5
|
|
|
5
6
|
function updateMotionValuesFromProps(element, next, prev) {
|
|
6
7
|
var _a;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const { willChange } = next;
|
|
9
|
+
for (const key in next) {
|
|
10
|
+
const nextValue = next[key];
|
|
11
|
+
const prevValue = prev[key];
|
|
10
12
|
if (isMotionValue(nextValue)) {
|
|
11
13
|
/**
|
|
12
14
|
* If this is a motion value found in props or style, we want to add it
|
|
13
15
|
* to our visual element's motion value map.
|
|
14
16
|
*/
|
|
15
17
|
element.addValue(key, nextValue);
|
|
18
|
+
if (isWillChangeMotionValue(willChange)) {
|
|
19
|
+
willChange.add(key);
|
|
20
|
+
}
|
|
16
21
|
/**
|
|
17
22
|
* Check the version of the incoming motion value with this version
|
|
18
23
|
* and warn against mismatches.
|
|
19
24
|
*/
|
|
20
25
|
if (process.env.NODE_ENV === "development") {
|
|
21
|
-
warnOnce(nextValue.version === "7.
|
|
26
|
+
warnOnce(nextValue.version === "7.1.2", `Attempting to mix Framer Motion versions ${nextValue.version} with 7.1.2 may not work as expected.`);
|
|
22
27
|
}
|
|
23
28
|
}
|
|
24
29
|
else if (isMotionValue(prevValue)) {
|
|
25
30
|
/**
|
|
26
|
-
* If we're swapping
|
|
27
|
-
* from that
|
|
31
|
+
* If we're swapping from a motion value to a static value,
|
|
32
|
+
* create a new motion value from that
|
|
28
33
|
*/
|
|
29
34
|
element.addValue(key, motionValue(nextValue));
|
|
35
|
+
if (isWillChangeMotionValue(willChange)) {
|
|
36
|
+
willChange.remove(key);
|
|
37
|
+
}
|
|
30
38
|
}
|
|
31
39
|
else if (prevValue !== nextValue) {
|
|
32
40
|
/**
|
|
@@ -35,7 +43,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
35
43
|
* not handling the value with our animation state.
|
|
36
44
|
*/
|
|
37
45
|
if (element.hasValue(key)) {
|
|
38
|
-
|
|
46
|
+
const existingValue = element.getValue(key);
|
|
39
47
|
// TODO: Only update values that aren't being animated or even looked at
|
|
40
48
|
!existingValue.hasAnimated && existingValue.set(nextValue);
|
|
41
49
|
}
|
|
@@ -45,7 +53,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
45
53
|
}
|
|
46
54
|
}
|
|
47
55
|
// Handle removed values
|
|
48
|
-
for (
|
|
56
|
+
for (const key in prev) {
|
|
49
57
|
if (next[key] === undefined)
|
|
50
58
|
element.removeValue(key);
|
|
51
59
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __rest
|
|
1
|
+
import { __rest } from 'tslib';
|
|
2
2
|
import { complex } from 'style-value-types';
|
|
3
3
|
import { isNumericalString } from '../../utils/is-numerical-string.mjs';
|
|
4
4
|
import { isZeroValueString } from '../../utils/is-zero-value-string.mjs';
|
|
@@ -21,21 +21,21 @@ function setMotionValue(visualElement, key, value) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
function setTarget(visualElement, definition) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
target =
|
|
27
|
-
for (
|
|
28
|
-
|
|
24
|
+
const resolved = resolveVariant(visualElement, definition);
|
|
25
|
+
let _a = resolved ? visualElement.makeTargetAnimatable(resolved, false) : {}, { transitionEnd = {}, transition = {} } = _a, target = __rest(_a, ["transitionEnd", "transition"]);
|
|
26
|
+
target = Object.assign(Object.assign({}, target), transitionEnd);
|
|
27
|
+
for (const key in target) {
|
|
28
|
+
const value = resolveFinalValueInKeyframes(target[key]);
|
|
29
29
|
setMotionValue(visualElement, key, value);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
function setVariants(visualElement, variantLabels) {
|
|
33
|
-
|
|
34
|
-
reversedLabels.forEach(
|
|
33
|
+
const reversedLabels = [...variantLabels].reverse();
|
|
34
|
+
reversedLabels.forEach((key) => {
|
|
35
35
|
var _a;
|
|
36
|
-
|
|
36
|
+
const variant = visualElement.getVariant(key);
|
|
37
37
|
variant && setTarget(visualElement, variant);
|
|
38
|
-
(_a = visualElement.variantChildren) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
38
|
+
(_a = visualElement.variantChildren) === null || _a === void 0 ? void 0 : _a.forEach((child) => {
|
|
39
39
|
setVariants(child, variantLabels);
|
|
40
40
|
});
|
|
41
41
|
});
|
|
@@ -54,14 +54,14 @@ function setValues(visualElement, definition) {
|
|
|
54
54
|
function checkTargetForNewValues(visualElement, target, origin) {
|
|
55
55
|
var _a, _b, _c;
|
|
56
56
|
var _d;
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
const newValueKeys = Object.keys(target).filter((key) => !visualElement.hasValue(key));
|
|
58
|
+
const numNewValues = newValueKeys.length;
|
|
59
59
|
if (!numNewValues)
|
|
60
60
|
return;
|
|
61
|
-
for (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
for (let i = 0; i < numNewValues; i++) {
|
|
62
|
+
const key = newValueKeys[i];
|
|
63
|
+
const targetValue = target[key];
|
|
64
|
+
let value = null;
|
|
65
65
|
/**
|
|
66
66
|
* If the target is a series of keyframes, we can use the first value
|
|
67
67
|
* in the array. If this first value is null, we'll still need to read from the DOM.
|
|
@@ -99,13 +99,13 @@ function checkTargetForNewValues(visualElement, target, origin) {
|
|
|
99
99
|
function getOriginFromTransition(key, transition) {
|
|
100
100
|
if (!transition)
|
|
101
101
|
return;
|
|
102
|
-
|
|
102
|
+
const valueTransition = transition[key] || transition["default"] || transition;
|
|
103
103
|
return valueTransition.from;
|
|
104
104
|
}
|
|
105
105
|
function getOrigin(target, transition, visualElement) {
|
|
106
106
|
var _a, _b;
|
|
107
|
-
|
|
108
|
-
for (
|
|
107
|
+
const origin = {};
|
|
108
|
+
for (const key in target) {
|
|
109
109
|
origin[key] =
|
|
110
110
|
(_a = getOriginFromTransition(key, transition)) !== null && _a !== void 0 ? _a : (_b = visualElement.getValue(key)) === null || _b === void 0 ? void 0 : _b.get();
|
|
111
111
|
}
|
|
@@ -14,22 +14,20 @@ function isVariantLabel(v) {
|
|
|
14
14
|
* Creates an object containing the latest state of every MotionValue on a VisualElement
|
|
15
15
|
*/
|
|
16
16
|
function getCurrent(visualElement) {
|
|
17
|
-
|
|
18
|
-
visualElement.forEachValue(
|
|
17
|
+
const current = {};
|
|
18
|
+
visualElement.forEachValue((value, key) => (current[key] = value.get()));
|
|
19
19
|
return current;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Creates an object containing the latest velocity of every MotionValue on a VisualElement
|
|
23
23
|
*/
|
|
24
24
|
function getVelocity(visualElement) {
|
|
25
|
-
|
|
26
|
-
visualElement.forEachValue(
|
|
25
|
+
const velocity = {};
|
|
26
|
+
visualElement.forEachValue((value, key) => (velocity[key] = value.getVelocity()));
|
|
27
27
|
return velocity;
|
|
28
28
|
}
|
|
29
|
-
function resolveVariantFromProps(props, definition, custom, currentValues, currentVelocity) {
|
|
29
|
+
function resolveVariantFromProps(props, definition, custom, currentValues = {}, currentVelocity = {}) {
|
|
30
30
|
var _a;
|
|
31
|
-
if (currentValues === void 0) { currentValues = {}; }
|
|
32
|
-
if (currentVelocity === void 0) { currentVelocity = {}; }
|
|
33
31
|
/**
|
|
34
32
|
* If the variant definition is a function, resolve.
|
|
35
33
|
*/
|
|
@@ -54,7 +52,7 @@ function resolveVariantFromProps(props, definition, custom, currentValues, curre
|
|
|
54
52
|
return definition;
|
|
55
53
|
}
|
|
56
54
|
function resolveVariant(visualElement, definition, custom) {
|
|
57
|
-
|
|
55
|
+
const props = visualElement.getProps();
|
|
58
56
|
return resolveVariantFromProps(props, definition, custom !== null && custom !== void 0 ? custom : props.custom, getCurrent(visualElement), getVelocity(visualElement));
|
|
59
57
|
}
|
|
60
58
|
function checkIfControllingVariants(props) {
|
package/dist/es/utils/array.mjs
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import { __read } from 'tslib';
|
|
2
|
-
|
|
3
1
|
function addUniqueItem(arr, item) {
|
|
4
|
-
arr.indexOf(item) === -1
|
|
2
|
+
if (arr.indexOf(item) === -1)
|
|
3
|
+
arr.push(item);
|
|
5
4
|
}
|
|
6
5
|
function removeItem(arr, item) {
|
|
7
|
-
|
|
8
|
-
index > -1
|
|
6
|
+
const index = arr.indexOf(item);
|
|
7
|
+
if (index > -1)
|
|
8
|
+
arr.splice(index, 1);
|
|
9
9
|
}
|
|
10
10
|
// Adapted from array-move
|
|
11
|
-
function moveItem(
|
|
12
|
-
|
|
13
|
-
var startIndex = fromIndex < 0 ? arr.length + fromIndex : fromIndex;
|
|
11
|
+
function moveItem([...arr], fromIndex, toIndex) {
|
|
12
|
+
const startIndex = fromIndex < 0 ? arr.length + fromIndex : fromIndex;
|
|
14
13
|
if (startIndex >= 0 && startIndex < arr.length) {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const endIndex = toIndex < 0 ? arr.length + toIndex : toIndex;
|
|
15
|
+
const [item] = arr.splice(fromIndex, 1);
|
|
17
16
|
arr.splice(endIndex, 0, item);
|
|
18
17
|
}
|
|
19
18
|
return arr;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Check if value is a numerical string, ie a string that is purely a number eg "100" or "-100.1"
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
const isNumericalString = (v) => /^\-?\d*\.?\d+$/.test(v);
|
|
5
5
|
|
|
6
6
|
export { isNumericalString };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Browser-safe usage of process
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const defaultEnvironment = "production";
|
|
5
|
+
const env = typeof process === "undefined" || process.env === undefined
|
|
6
6
|
? defaultEnvironment
|
|
7
7
|
: process.env.NODE_ENV || defaultEnvironment;
|
|
8
8
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isKeyframesTarget } from '../animation/utils/is-keyframes-target.mjs';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const isCustomValue = (v) => {
|
|
4
4
|
return Boolean(v && typeof v === "object" && v.mix && v.toValue);
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
const resolveFinalValueInKeyframes = (v) => {
|
|
7
7
|
// TODO maybe throw if v.length - 1 is placeholder token?
|
|
8
8
|
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
|
|
9
9
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
function shallowCompare(next, prev) {
|
|
2
2
|
if (!Array.isArray(prev))
|
|
3
3
|
return false;
|
|
4
|
-
|
|
4
|
+
const prevLength = prev.length;
|
|
5
5
|
if (prevLength !== next.length)
|
|
6
6
|
return false;
|
|
7
|
-
for (
|
|
7
|
+
for (let i = 0; i < prevLength; i++) {
|
|
8
8
|
if (prev[i] !== next[i])
|
|
9
9
|
return false;
|
|
10
10
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { addUniqueItem, removeItem } from './array.mjs';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
class SubscriptionManager {
|
|
4
|
+
constructor() {
|
|
5
5
|
this.subscriptions = [];
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
var _this = this;
|
|
7
|
+
add(handler) {
|
|
9
8
|
addUniqueItem(this.subscriptions, handler);
|
|
10
|
-
return
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
return () => removeItem(this.subscriptions, handler);
|
|
10
|
+
}
|
|
11
|
+
notify(a, b, c) {
|
|
12
|
+
const numSubscriptions = this.subscriptions.length;
|
|
14
13
|
if (!numSubscriptions)
|
|
15
14
|
return;
|
|
16
15
|
if (numSubscriptions === 1) {
|
|
@@ -20,23 +19,22 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
20
19
|
this.subscriptions[0](a, b, c);
|
|
21
20
|
}
|
|
22
21
|
else {
|
|
23
|
-
for (
|
|
22
|
+
for (let i = 0; i < numSubscriptions; i++) {
|
|
24
23
|
/**
|
|
25
24
|
* Check whether the handler exists before firing as it's possible
|
|
26
25
|
* the subscriptions were modified during this loop running.
|
|
27
26
|
*/
|
|
28
|
-
|
|
27
|
+
const handler = this.subscriptions[i];
|
|
29
28
|
handler && handler(a, b, c);
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
|
-
}
|
|
33
|
-
|
|
31
|
+
}
|
|
32
|
+
getSize() {
|
|
34
33
|
return this.subscriptions.length;
|
|
35
|
-
}
|
|
36
|
-
|
|
34
|
+
}
|
|
35
|
+
clear() {
|
|
37
36
|
this.subscriptions.length = 0;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
}());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
41
39
|
|
|
42
40
|
export { SubscriptionManager };
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* @param seconds - Time in seconds.
|
|
5
5
|
* @return milliseconds - Converted time in milliseconds.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
const secondsToMilliseconds = (seconds) => seconds * 1000;
|
|
8
8
|
|
|
9
9
|
export { secondsToMilliseconds };
|