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
|
@@ -4,12 +4,11 @@ import { makeUseVisualState } from '../../motion/utils/use-visual-state.mjs';
|
|
|
4
4
|
import { createSvgRenderState } from './utils/create-render-state.mjs';
|
|
5
5
|
import { buildSVGAttrs } from './utils/build-attrs.mjs';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const svgMotionConfig = {
|
|
8
8
|
useVisualState: makeUseVisualState({
|
|
9
9
|
scrapeMotionValuesFromProps: scrapeMotionValuesFromProps,
|
|
10
10
|
createRenderState: createSvgRenderState,
|
|
11
|
-
onMount:
|
|
12
|
-
var renderState = _a.renderState, latestValues = _a.latestValues;
|
|
11
|
+
onMount: (props, instance, { renderState, latestValues }) => {
|
|
13
12
|
try {
|
|
14
13
|
renderState.dimensions =
|
|
15
14
|
typeof instance.getBBox ===
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { useMemo } from 'react';
|
|
3
2
|
import { copyRawValuesOnly } from '../html/use-props.mjs';
|
|
4
3
|
import { buildSVGAttrs } from './utils/build-attrs.mjs';
|
|
5
4
|
import { createSvgRenderState } from './utils/create-render-state.mjs';
|
|
6
5
|
|
|
7
6
|
function useSVGProps(props, visualState) {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const visualProps = useMemo(() => {
|
|
8
|
+
const state = createSvgRenderState();
|
|
10
9
|
buildSVGAttrs(state, visualState, { enableHardwareAcceleration: false }, props.transformTemplate);
|
|
11
|
-
return
|
|
10
|
+
return Object.assign(Object.assign({}, state.attrs), { style: Object.assign({}, state.style) });
|
|
12
11
|
}, [visualState]);
|
|
13
12
|
if (props.style) {
|
|
14
|
-
|
|
13
|
+
const rawStyles = {};
|
|
15
14
|
copyRawValuesOnly(rawStyles, props.style, props);
|
|
16
|
-
visualProps.style =
|
|
15
|
+
visualProps.style = Object.assign(Object.assign({}, rawStyles), visualProps.style);
|
|
17
16
|
}
|
|
18
17
|
return visualProps;
|
|
19
18
|
}
|
|
@@ -7,13 +7,13 @@ import { buildSVGPath } from './path.mjs';
|
|
|
7
7
|
* Build SVG visual attrbutes, like cx and style.transform
|
|
8
8
|
*/
|
|
9
9
|
function buildSVGAttrs(state, _a, options, transformTemplate) {
|
|
10
|
-
var
|
|
10
|
+
var { attrX, attrY, originX, originY, pathLength, pathSpacing = 1, pathOffset = 0 } = _a,
|
|
11
11
|
// This is object creation, which we try to avoid per-frame.
|
|
12
12
|
latest = __rest(_a, ["attrX", "attrY", "originX", "originY", "pathLength", "pathSpacing", "pathOffset"]);
|
|
13
13
|
buildHTMLStyles(state, latest, options, transformTemplate);
|
|
14
14
|
state.attrs = state.style;
|
|
15
15
|
state.style = {};
|
|
16
|
-
|
|
16
|
+
const { attrs, style, dimensions } = state;
|
|
17
17
|
/**
|
|
18
18
|
* However, we apply transforms as CSS transforms. So if we detect a transform we take it from attrs
|
|
19
19
|
* and copy it into style.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { createHtmlRenderState } from '../../html/utils/create-render-state.mjs';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
const createSvgRenderState = () => (Object.assign(Object.assign({}, createHtmlRenderState()), { attrs: {} }));
|
|
5
4
|
|
|
6
5
|
export { createSvgRenderState };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { px } from 'style-value-types';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const dashKeys = {
|
|
4
4
|
offset: "stroke-dashoffset",
|
|
5
5
|
array: "stroke-dasharray",
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
const camelKeys = {
|
|
8
8
|
offset: "strokeDashoffset",
|
|
9
9
|
array: "strokeDasharray",
|
|
10
10
|
};
|
|
@@ -15,21 +15,18 @@ var camelKeys = {
|
|
|
15
15
|
*
|
|
16
16
|
* This function is mutative to reduce per-frame GC.
|
|
17
17
|
*/
|
|
18
|
-
function buildSVGPath(attrs, length, spacing, offset, useDashCase) {
|
|
19
|
-
if (spacing === void 0) { spacing = 1; }
|
|
20
|
-
if (offset === void 0) { offset = 0; }
|
|
21
|
-
if (useDashCase === void 0) { useDashCase = true; }
|
|
18
|
+
function buildSVGPath(attrs, length, spacing = 1, offset = 0, useDashCase = true) {
|
|
22
19
|
// Normalise path length by setting SVG attribute pathLength to 1
|
|
23
20
|
attrs.pathLength = 1;
|
|
24
21
|
// We use dash case when setting attributes directly to the DOM node and camel case
|
|
25
22
|
// when defining props on a React component.
|
|
26
|
-
|
|
23
|
+
const keys = useDashCase ? dashKeys : camelKeys;
|
|
27
24
|
// Build the dash offset
|
|
28
25
|
attrs[keys.offset] = px.transform(-offset);
|
|
29
26
|
// Build the dash array
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
attrs[keys.array] =
|
|
27
|
+
const pathLength = px.transform(length);
|
|
28
|
+
const pathSpacing = px.transform(spacing);
|
|
29
|
+
attrs[keys.array] = `${pathLength} ${pathSpacing}`;
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
export { buildSVGPath };
|
|
@@ -4,7 +4,7 @@ import { camelCaseAttributes } from './camel-case-attrs.mjs';
|
|
|
4
4
|
|
|
5
5
|
function renderSVG(element, renderState, _styleProp, projection) {
|
|
6
6
|
renderHTML(element, renderState, undefined, projection);
|
|
7
|
-
for (
|
|
7
|
+
for (const key in renderState.attrs) {
|
|
8
8
|
element.setAttribute(!camelCaseAttributes.has(key) ? camelToDash(key) : key, renderState.attrs[key]);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -2,10 +2,10 @@ import { isMotionValue } from '../../../value/utils/is-motion-value.mjs';
|
|
|
2
2
|
import { scrapeMotionValuesFromProps as scrapeMotionValuesFromProps$1 } from '../../html/utils/scrape-motion-values.mjs';
|
|
3
3
|
|
|
4
4
|
function scrapeMotionValuesFromProps(props) {
|
|
5
|
-
|
|
6
|
-
for (
|
|
5
|
+
const newValues = scrapeMotionValuesFromProps$1(props);
|
|
6
|
+
for (const key in props) {
|
|
7
7
|
if (isMotionValue(props[key])) {
|
|
8
|
-
|
|
8
|
+
const targetKey = key === "x" || key === "y" ? "attr" + key.toUpperCase() : key;
|
|
9
9
|
newValues[targetKey] = props[key];
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -10,9 +10,9 @@ function calcOrigin(origin, offset, size) {
|
|
|
10
10
|
* so we use the measured dimensions of the SVG to reconcile these.
|
|
11
11
|
*/
|
|
12
12
|
function calcSVGTransformOrigin(dimensions, originX, originY) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
13
|
+
const pxOriginX = calcOrigin(originX, dimensions.x, dimensions.width);
|
|
14
|
+
const pxOriginY = calcOrigin(originY, dimensions.y, dimensions.height);
|
|
15
|
+
return `${pxOriginX} ${pxOriginY}`;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export { calcSVGTransformOrigin };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { visualElement } from '../index.mjs';
|
|
3
2
|
import { scrapeMotionValuesFromProps } from './utils/scrape-motion-values.mjs';
|
|
4
3
|
import { htmlConfig } from '../html/visual-element.mjs';
|
|
@@ -9,16 +8,19 @@ import { isTransformProp } from '../html/utils/transform.mjs';
|
|
|
9
8
|
import { renderSVG } from './utils/render.mjs';
|
|
10
9
|
import { getDefaultValueType } from '../dom/value-types/defaults.mjs';
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
const svgVisualElement = visualElement(Object.assign(Object.assign({}, htmlConfig), { getBaseTarget(props, key) {
|
|
13
12
|
return props[key];
|
|
14
|
-
},
|
|
13
|
+
},
|
|
14
|
+
readValueFromInstance(domElement, key) {
|
|
15
15
|
var _a;
|
|
16
16
|
if (isTransformProp(key)) {
|
|
17
17
|
return ((_a = getDefaultValueType(key)) === null || _a === void 0 ? void 0 : _a.default) || 0;
|
|
18
18
|
}
|
|
19
19
|
key = !camelCaseAttributes.has(key) ? camelToDash(key) : key;
|
|
20
20
|
return domElement.getAttribute(key);
|
|
21
|
-
},
|
|
21
|
+
},
|
|
22
|
+
scrapeMotionValuesFromProps,
|
|
23
|
+
build(_element, renderState, latestValues, options, props) {
|
|
22
24
|
buildSVGAttrs(renderState, latestValues, options, props.transformTemplate);
|
|
23
25
|
}, render: renderSVG }));
|
|
24
26
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __rest } from 'tslib';
|
|
2
2
|
import { isAnimationControls } from '../../animation/utils/is-animation-controls.mjs';
|
|
3
3
|
import { isKeyframesTarget } from '../../animation/utils/is-keyframes-target.mjs';
|
|
4
4
|
import { shallowCompare } from '../../utils/shallow-compare.mjs';
|
|
@@ -6,7 +6,7 @@ import { animateVisualElement } from './animation.mjs';
|
|
|
6
6
|
import { AnimationType } from './types.mjs';
|
|
7
7
|
import { isVariantLabels, resolveVariant, isVariantLabel } from './variants.mjs';
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const variantPriorityOrder = [
|
|
10
10
|
AnimationType.Animate,
|
|
11
11
|
AnimationType.InView,
|
|
12
12
|
AnimationType.Focus,
|
|
@@ -15,36 +15,27 @@ var variantPriorityOrder = [
|
|
|
15
15
|
AnimationType.Drag,
|
|
16
16
|
AnimationType.Exit,
|
|
17
17
|
];
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const reversePriorityOrder = [...variantPriorityOrder].reverse();
|
|
19
|
+
const numAnimationTypes = variantPriorityOrder.length;
|
|
20
20
|
function animateList(visualElement) {
|
|
21
|
-
return
|
|
22
|
-
return Promise.all(animations.map(function (_a) {
|
|
23
|
-
var animation = _a.animation, options = _a.options;
|
|
24
|
-
return animateVisualElement(visualElement, animation, options);
|
|
25
|
-
}));
|
|
26
|
-
};
|
|
21
|
+
return (animations) => Promise.all(animations.map(({ animation, options }) => animateVisualElement(visualElement, animation, options)));
|
|
27
22
|
}
|
|
28
23
|
function createAnimationState(visualElement) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var isInitialRender = true;
|
|
24
|
+
let animate = animateList(visualElement);
|
|
25
|
+
const state = createState();
|
|
26
|
+
let isInitialRender = true;
|
|
33
27
|
/**
|
|
34
28
|
* This function will be used to reduce the animation definitions for
|
|
35
29
|
* each active animation type into an object of resolved values for it.
|
|
36
30
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
const buildResolvedTypeValues = (acc, definition) => {
|
|
32
|
+
const resolved = resolveVariant(visualElement, definition);
|
|
39
33
|
if (resolved) {
|
|
40
|
-
|
|
41
|
-
acc =
|
|
34
|
+
const { transition, transitionEnd } = resolved, target = __rest(resolved, ["transition", "transitionEnd"]);
|
|
35
|
+
acc = Object.assign(Object.assign(Object.assign({}, acc), target), transitionEnd);
|
|
42
36
|
}
|
|
43
37
|
return acc;
|
|
44
38
|
};
|
|
45
|
-
function isAnimated(key) {
|
|
46
|
-
return allAnimatedKeys[key] !== undefined;
|
|
47
|
-
}
|
|
48
39
|
/**
|
|
49
40
|
* This just allows us to inject mocked animation functions
|
|
50
41
|
* @internal
|
|
@@ -64,39 +55,45 @@ function createAnimationState(visualElement) {
|
|
|
64
55
|
*/
|
|
65
56
|
function animateChanges(options, changedActiveType) {
|
|
66
57
|
var _a;
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
const props = visualElement.getProps();
|
|
59
|
+
const context = visualElement.getVariantContext(true) || {};
|
|
69
60
|
/**
|
|
70
61
|
* A list of animations that we'll build into as we iterate through the animation
|
|
71
62
|
* types. This will get executed at the end of the function.
|
|
72
63
|
*/
|
|
73
|
-
|
|
64
|
+
const animations = [];
|
|
74
65
|
/**
|
|
75
66
|
* Keep track of which values have been removed. Then, as we hit lower priority
|
|
76
67
|
* animation types, we can check if they contain removed values and animate to that.
|
|
77
68
|
*/
|
|
78
|
-
|
|
69
|
+
const removedKeys = new Set();
|
|
79
70
|
/**
|
|
80
71
|
* A dictionary of all encountered keys. This is an object to let us build into and
|
|
81
72
|
* copy it without iteration. Each time we hit an animation type we set its protected
|
|
82
73
|
* keys - the keys its not allowed to animate - to the latest version of this object.
|
|
83
74
|
*/
|
|
84
|
-
|
|
75
|
+
let encounteredKeys = {};
|
|
85
76
|
/**
|
|
86
77
|
* If a variant has been removed at a given index, and this component is controlling
|
|
87
78
|
* variant animations, we want to ensure lower-priority variants are forced to animate.
|
|
88
79
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
80
|
+
let removedVariantIndex = Infinity;
|
|
81
|
+
/**
|
|
82
|
+
* Iterate through all animation types in reverse priority order. For each, we want to
|
|
83
|
+
* detect which values it's handling and whether or not they've changed (and therefore
|
|
84
|
+
* need to be animated). If any values have been removed, we want to detect those in
|
|
85
|
+
* lower priority props and flag for animation.
|
|
86
|
+
*/
|
|
87
|
+
for (let i = 0; i < numAnimationTypes; i++) {
|
|
88
|
+
const type = reversePriorityOrder[i];
|
|
89
|
+
const typeState = state[type];
|
|
90
|
+
const prop = (_a = props[type]) !== null && _a !== void 0 ? _a : context[type];
|
|
91
|
+
const propIsVariant = isVariantLabel(prop);
|
|
95
92
|
/**
|
|
96
93
|
* If this type has *just* changed isActive status, set activeDelta
|
|
97
94
|
* to that status. Otherwise set to null.
|
|
98
95
|
*/
|
|
99
|
-
|
|
96
|
+
const activeDelta = type === changedActiveType ? typeState.isActive : null;
|
|
100
97
|
if (activeDelta === false)
|
|
101
98
|
removedVariantIndex = i;
|
|
102
99
|
/**
|
|
@@ -105,7 +102,7 @@ function createAnimationState(visualElement) {
|
|
|
105
102
|
*
|
|
106
103
|
* TODO: Can probably change this to a !isControllingVariants check
|
|
107
104
|
*/
|
|
108
|
-
|
|
105
|
+
let isInherited = prop === context[type] && prop !== props[type] && propIsVariant;
|
|
109
106
|
/**
|
|
110
107
|
*
|
|
111
108
|
*/
|
|
@@ -118,7 +115,7 @@ function createAnimationState(visualElement) {
|
|
|
118
115
|
* Set all encountered keys so far as the protected keys for this type. This will
|
|
119
116
|
* be any key that has been animated or otherwise handled by active, higher-priortiy types.
|
|
120
117
|
*/
|
|
121
|
-
typeState.protectedKeys =
|
|
118
|
+
typeState.protectedKeys = Object.assign({}, encounteredKeys);
|
|
122
119
|
// Check if we can skip analysing this prop early
|
|
123
120
|
if (
|
|
124
121
|
// If it isn't active and hasn't *just* been set as inactive
|
|
@@ -128,15 +125,15 @@ function createAnimationState(visualElement) {
|
|
|
128
125
|
// Or if the prop doesn't define an animation
|
|
129
126
|
isAnimationControls(prop) ||
|
|
130
127
|
typeof prop === "boolean") {
|
|
131
|
-
|
|
128
|
+
continue;
|
|
132
129
|
}
|
|
133
130
|
/**
|
|
134
131
|
* As we go look through the values defined on this type, if we detect
|
|
135
132
|
* a changed value or a value that was removed in a higher priority, we set
|
|
136
133
|
* this to true and add this prop to the animation list.
|
|
137
134
|
*/
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
const variantDidChange = checkVariantsDidChange(typeState.prevProp, prop);
|
|
136
|
+
let shouldAnimateType = variantDidChange ||
|
|
140
137
|
// If we're making this variant active, we want to always make it active
|
|
141
138
|
(type === changedActiveType &&
|
|
142
139
|
typeState.isActive &&
|
|
@@ -148,12 +145,12 @@ function createAnimationState(visualElement) {
|
|
|
148
145
|
* As animations can be set as variant lists, variants or target objects, we
|
|
149
146
|
* coerce everything to an array if it isn't one already
|
|
150
147
|
*/
|
|
151
|
-
|
|
148
|
+
const definitionList = Array.isArray(prop) ? prop : [prop];
|
|
152
149
|
/**
|
|
153
150
|
* Build an object of all the resolved values. We'll use this in the subsequent
|
|
154
151
|
* animateChanges calls to determine whether a value has changed.
|
|
155
152
|
*/
|
|
156
|
-
|
|
153
|
+
let resolvedValues = definitionList.reduce(buildResolvedTypeValues, {});
|
|
157
154
|
if (activeDelta === false)
|
|
158
155
|
resolvedValues = {};
|
|
159
156
|
/**
|
|
@@ -165,16 +162,16 @@ function createAnimationState(visualElement) {
|
|
|
165
162
|
* 4. If it hasn't been removed in a higher priority but hasn't changed, and
|
|
166
163
|
* needs adding to the type's protectedKeys list.
|
|
167
164
|
*/
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
const { prevResolvedValues = {} } = typeState;
|
|
166
|
+
const allKeys = Object.assign(Object.assign({}, prevResolvedValues), resolvedValues);
|
|
167
|
+
const markToAnimate = (key) => {
|
|
171
168
|
shouldAnimateType = true;
|
|
172
169
|
removedKeys.delete(key);
|
|
173
170
|
typeState.needsAnimating[key] = true;
|
|
174
171
|
};
|
|
175
|
-
for (
|
|
176
|
-
|
|
177
|
-
|
|
172
|
+
for (const key in allKeys) {
|
|
173
|
+
const next = resolvedValues[key];
|
|
174
|
+
const prev = prevResolvedValues[key];
|
|
178
175
|
// If we've already handled this we can just skip ahead
|
|
179
176
|
if (encounteredKeys.hasOwnProperty(key))
|
|
180
177
|
continue;
|
|
@@ -232,7 +229,7 @@ function createAnimationState(visualElement) {
|
|
|
232
229
|
*
|
|
233
230
|
*/
|
|
234
231
|
if (typeState.isActive) {
|
|
235
|
-
encounteredKeys =
|
|
232
|
+
encounteredKeys = Object.assign(Object.assign({}, encounteredKeys), resolvedValues);
|
|
236
233
|
}
|
|
237
234
|
if (isInitialRender && visualElement.blockInitialAnimation) {
|
|
238
235
|
shouldAnimateType = false;
|
|
@@ -243,38 +240,28 @@ function createAnimationState(visualElement) {
|
|
|
243
240
|
* by removed values?
|
|
244
241
|
*/
|
|
245
242
|
if (shouldAnimateType && !isInherited) {
|
|
246
|
-
animations.push
|
|
243
|
+
animations.push(...definitionList.map((animation) => ({
|
|
247
244
|
animation: animation,
|
|
248
|
-
options:
|
|
249
|
-
})
|
|
245
|
+
options: Object.assign({ type }, options),
|
|
246
|
+
})));
|
|
250
247
|
}
|
|
251
|
-
};
|
|
252
|
-
/**
|
|
253
|
-
* Iterate through all animation types in reverse priority order. For each, we want to
|
|
254
|
-
* detect which values it's handling and whether or not they've changed (and therefore
|
|
255
|
-
* need to be animated). If any values have been removed, we want to detect those in
|
|
256
|
-
* lower priority props and flag for animation.
|
|
257
|
-
*/
|
|
258
|
-
for (var i = 0; i < numAnimationTypes; i++) {
|
|
259
|
-
_loop_1(i);
|
|
260
248
|
}
|
|
261
|
-
allAnimatedKeys = __assign({}, encounteredKeys);
|
|
262
249
|
/**
|
|
263
250
|
* If there are some removed value that haven't been dealt with,
|
|
264
251
|
* we need to create a new animation that falls back either to the value
|
|
265
252
|
* defined in the style prop, or the last read value.
|
|
266
253
|
*/
|
|
267
254
|
if (removedKeys.size) {
|
|
268
|
-
|
|
269
|
-
removedKeys.forEach(
|
|
270
|
-
|
|
255
|
+
const fallbackAnimation = {};
|
|
256
|
+
removedKeys.forEach((key) => {
|
|
257
|
+
const fallbackTarget = visualElement.getBaseTarget(key);
|
|
271
258
|
if (fallbackTarget !== undefined) {
|
|
272
|
-
|
|
259
|
+
fallbackAnimation[key] = fallbackTarget;
|
|
273
260
|
}
|
|
274
261
|
});
|
|
275
|
-
animations.push({ animation:
|
|
262
|
+
animations.push({ animation: fallbackAnimation });
|
|
276
263
|
}
|
|
277
|
-
|
|
264
|
+
let shouldAnimate = Boolean(animations.length);
|
|
278
265
|
if (isInitialRender &&
|
|
279
266
|
props.initial === false &&
|
|
280
267
|
!visualElement.manuallyAnimateOnMount) {
|
|
@@ -292,20 +279,19 @@ function createAnimationState(visualElement) {
|
|
|
292
279
|
if (state[type].isActive === isActive)
|
|
293
280
|
return Promise.resolve();
|
|
294
281
|
// Propagate active change to children
|
|
295
|
-
(_a = visualElement.variantChildren) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
282
|
+
(_a = visualElement.variantChildren) === null || _a === void 0 ? void 0 : _a.forEach((child) => { var _a; return (_a = child.animationState) === null || _a === void 0 ? void 0 : _a.setActive(type, isActive); });
|
|
296
283
|
state[type].isActive = isActive;
|
|
297
|
-
|
|
298
|
-
for (
|
|
284
|
+
const animations = animateChanges(options, type);
|
|
285
|
+
for (const key in state) {
|
|
299
286
|
state[key].protectedKeys = {};
|
|
300
287
|
}
|
|
301
288
|
return animations;
|
|
302
289
|
}
|
|
303
290
|
return {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
getState: function () { return state; },
|
|
291
|
+
animateChanges,
|
|
292
|
+
setActive,
|
|
293
|
+
setAnimateFunction,
|
|
294
|
+
getState: () => state,
|
|
309
295
|
};
|
|
310
296
|
}
|
|
311
297
|
function checkVariantsDidChange(prev, next) {
|
|
@@ -317,26 +303,24 @@ function checkVariantsDidChange(prev, next) {
|
|
|
317
303
|
}
|
|
318
304
|
return false;
|
|
319
305
|
}
|
|
320
|
-
function createTypeState(isActive) {
|
|
321
|
-
if (isActive === void 0) { isActive = false; }
|
|
306
|
+
function createTypeState(isActive = false) {
|
|
322
307
|
return {
|
|
323
|
-
isActive
|
|
308
|
+
isActive,
|
|
324
309
|
protectedKeys: {},
|
|
325
310
|
needsAnimating: {},
|
|
326
311
|
prevResolvedValues: {},
|
|
327
312
|
};
|
|
328
313
|
}
|
|
329
314
|
function createState() {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
_a;
|
|
315
|
+
return {
|
|
316
|
+
[AnimationType.Animate]: createTypeState(true),
|
|
317
|
+
[AnimationType.InView]: createTypeState(),
|
|
318
|
+
[AnimationType.Hover]: createTypeState(),
|
|
319
|
+
[AnimationType.Tap]: createTypeState(),
|
|
320
|
+
[AnimationType.Drag]: createTypeState(),
|
|
321
|
+
[AnimationType.Focus]: createTypeState(),
|
|
322
|
+
[AnimationType.Exit]: createTypeState(),
|
|
323
|
+
};
|
|
340
324
|
}
|
|
341
325
|
|
|
342
326
|
export { checkVariantsDidChange, createAnimationState, variantPriorityOrder };
|