framer-motion 7.2.0 → 7.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +762 -627
- package/dist/es/animation/use-animated-state.mjs +3 -5
- package/dist/es/animation/utils/default-transitions.mjs +1 -1
- package/dist/es/animation/utils/transitions.mjs +28 -26
- package/dist/es/components/AnimatePresence/PopChild.mjs +3 -2
- package/dist/es/components/AnimatePresence/PresenceChild.mjs +5 -2
- package/dist/es/components/AnimatePresence/use-presence.mjs +1 -1
- package/dist/es/components/LayoutGroup/index.mjs +4 -5
- package/dist/es/components/LazyMotion/index.mjs +3 -5
- package/dist/es/components/MotionConfig/index.mjs +2 -4
- package/dist/es/components/Reorder/Group.mjs +2 -4
- package/dist/es/components/Reorder/Item.mjs +6 -8
- package/dist/es/context/MotionContext/utils.mjs +3 -2
- package/dist/es/gestures/PanSession.mjs +2 -2
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +16 -4
- package/dist/es/gestures/use-focus-gesture.mjs +3 -4
- package/dist/es/gestures/use-hover-gesture.mjs +4 -3
- package/dist/es/gestures/use-tap-gesture.mjs +9 -10
- package/dist/es/index.mjs +2 -1
- package/dist/es/motion/features/animations.mjs +8 -3
- package/dist/es/motion/features/definitions.mjs +1 -13
- package/dist/es/motion/features/layout/MeasureLayout.mjs +12 -6
- package/dist/es/motion/features/load-features.mjs +14 -0
- package/dist/es/motion/features/viewport/observers.mjs +4 -7
- package/dist/es/motion/features/viewport/use-viewport.mjs +8 -6
- package/dist/es/motion/index.mjs +23 -23
- package/dist/es/motion/utils/VisualElementHandler.mjs +2 -5
- package/dist/es/motion/utils/is-forced-motion-value.mjs +3 -3
- package/dist/es/motion/utils/use-motion-ref.mjs +1 -2
- package/dist/es/motion/utils/use-visual-element.mjs +14 -12
- package/dist/es/motion/utils/use-visual-state.mjs +19 -16
- package/dist/es/motion/utils/valid-prop.mjs +22 -17
- package/dist/es/projection/geometry/utils.mjs +10 -1
- package/dist/es/projection/node/HTMLProjectionNode.mjs +1 -1
- package/dist/es/projection/node/create-projection-node.mjs +62 -20
- package/dist/es/projection/use-instant-layout-transition.mjs +2 -2
- package/dist/es/render/dom/features-animation.mjs +5 -1
- package/dist/es/render/dom/features-max.mjs +6 -1
- package/dist/es/render/dom/motion.mjs +6 -1
- package/dist/es/render/dom/use-render.mjs +5 -1
- package/dist/es/render/dom/utils/camel-to-dash.mjs +1 -3
- package/dist/es/render/dom/utils/create-config.mjs +7 -2
- package/dist/es/render/dom/utils/css-variables-conversion.mjs +5 -7
- package/dist/es/render/dom/utils/unit-conversion.mjs +4 -4
- package/dist/es/render/dom/value-types/defaults.mjs +15 -3
- package/dist/es/render/dom/value-types/type-int.mjs +4 -1
- package/dist/es/render/html/config-motion.mjs +1 -1
- package/dist/es/render/html/use-props.mjs +5 -9
- package/dist/es/render/html/utils/build-styles.mjs +17 -15
- package/dist/es/render/html/utils/build-transform.mjs +8 -18
- package/dist/es/render/html/utils/transform.mjs +21 -30
- package/dist/es/render/html/visual-element.mjs +8 -9
- package/dist/es/render/index.mjs +118 -40
- package/dist/es/render/svg/use-props.mjs +5 -2
- package/dist/es/render/svg/utils/build-attrs.mjs +3 -5
- package/dist/es/render/svg/utils/create-render-state.mjs +4 -1
- package/dist/es/render/svg/visual-element.mjs +8 -4
- package/dist/es/render/utils/animation-state.mjs +12 -9
- package/dist/es/render/utils/animation.mjs +14 -8
- package/dist/es/render/utils/is-controlling-variants.mjs +22 -0
- package/dist/es/render/utils/is-variant-label.mjs +8 -0
- package/dist/es/render/utils/motion-values.mjs +3 -3
- package/dist/es/render/utils/resolve-dynamic-variants.mjs +24 -0
- package/dist/es/render/utils/resolve-variants.mjs +26 -0
- package/dist/es/render/utils/setters.mjs +12 -9
- package/dist/es/utils/reduced-motion/index.mjs +19 -0
- package/dist/es/utils/reduced-motion/state.mjs +5 -0
- package/dist/es/utils/reduced-motion/use-reduced-motion-config.mjs +19 -0
- package/dist/es/utils/reduced-motion/use-reduced-motion.mjs +43 -0
- package/dist/es/utils/transform.mjs +4 -1
- package/dist/es/utils/use-in-view.mjs +1 -2
- package/dist/es/value/index.mjs +1 -1
- package/dist/es/value/use-scroll.mjs +6 -4
- package/dist/es/value/use-spring.mjs +7 -1
- package/dist/es/value/use-will-change/index.mjs +4 -4
- package/dist/es/value/utils/is-motion-value.mjs +1 -3
- package/dist/framer-motion.dev.js +806 -670
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +60 -54
- package/dist/projection.dev.js +402 -213
- package/dist/size-rollup-dom-animation-assets.js +1 -0
- package/dist/size-rollup-dom-animation-m.js +1 -0
- package/dist/size-rollup-dom-animation.js +1 -1
- package/dist/size-rollup-dom-max-assets.js +1 -0
- package/dist/size-rollup-dom-max.js +1 -1
- package/dist/size-rollup-m.js +1 -1
- package/dist/size-rollup-motion.js +1 -0
- package/dist/size-webpack-dom-animation.js +1 -1
- package/dist/size-webpack-dom-max.js +1 -1
- package/dist/size-webpack-m.js +1 -1
- package/dist/three-entry.d.ts +41 -22
- package/package.json +12 -8
- package/dist/es/motion/features/use-features.mjs +0 -40
- package/dist/es/motion/features/use-projection.mjs +0 -33
- package/dist/es/render/utils/variants.mjs +0 -73
- package/dist/es/utils/use-reduced-motion.mjs +0 -73
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import { complex } from 'style-value-types';
|
|
3
2
|
import { isNumericalString } from '../../utils/is-numerical-string.mjs';
|
|
4
3
|
import { isZeroValueString } from '../../utils/is-zero-value-string.mjs';
|
|
@@ -6,7 +5,7 @@ import { resolveFinalValueInKeyframes } from '../../utils/resolve-value.mjs';
|
|
|
6
5
|
import { motionValue } from '../../value/index.mjs';
|
|
7
6
|
import { getAnimatableNone } from '../dom/value-types/animatable-none.mjs';
|
|
8
7
|
import { findValueType } from '../dom/value-types/find.mjs';
|
|
9
|
-
import { resolveVariant } from './variants.mjs';
|
|
8
|
+
import { resolveVariant } from './resolve-dynamic-variants.mjs';
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Set VisualElement's MotionValue, creating a new MotionValue for it if
|
|
@@ -22,8 +21,8 @@ function setMotionValue(visualElement, key, value) {
|
|
|
22
21
|
}
|
|
23
22
|
function setTarget(visualElement, definition) {
|
|
24
23
|
const resolved = resolveVariant(visualElement, definition);
|
|
25
|
-
let
|
|
26
|
-
target =
|
|
24
|
+
let { transitionEnd = {}, transition = {}, ...target } = resolved ? visualElement.makeTargetAnimatable(resolved, false) : {};
|
|
25
|
+
target = { ...target, ...transitionEnd };
|
|
27
26
|
for (const key in target) {
|
|
28
27
|
const value = resolveFinalValueInKeyframes(target[key]);
|
|
29
28
|
setMotionValue(visualElement, key, value);
|
|
@@ -52,8 +51,7 @@ function setValues(visualElement, definition) {
|
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
function checkTargetForNewValues(visualElement, target, origin) {
|
|
55
|
-
var _a, _b
|
|
56
|
-
var _d;
|
|
54
|
+
var _a, _b;
|
|
57
55
|
const newValueKeys = Object.keys(target).filter((key) => !visualElement.hasValue(key));
|
|
58
56
|
const numNewValues = newValueKeys.length;
|
|
59
57
|
if (!numNewValues)
|
|
@@ -92,7 +90,9 @@ function checkTargetForNewValues(visualElement, target, origin) {
|
|
|
92
90
|
value = getAnimatableNone(key, targetValue);
|
|
93
91
|
}
|
|
94
92
|
visualElement.addValue(key, motionValue(value));
|
|
95
|
-
|
|
93
|
+
if (origin[key] === undefined) {
|
|
94
|
+
origin[key] = value;
|
|
95
|
+
}
|
|
96
96
|
visualElement.setBaseTarget(key, value);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -103,11 +103,14 @@ function getOriginFromTransition(key, transition) {
|
|
|
103
103
|
return valueTransition.from;
|
|
104
104
|
}
|
|
105
105
|
function getOrigin(target, transition, visualElement) {
|
|
106
|
-
var _a
|
|
106
|
+
var _a;
|
|
107
107
|
const origin = {};
|
|
108
108
|
for (const key in target) {
|
|
109
|
+
const transitionOrigin = getOriginFromTransition(key, transition);
|
|
109
110
|
origin[key] =
|
|
110
|
-
|
|
111
|
+
transitionOrigin !== undefined
|
|
112
|
+
? transitionOrigin
|
|
113
|
+
: (_a = visualElement.getValue(key)) === null || _a === void 0 ? void 0 : _a.get();
|
|
111
114
|
}
|
|
112
115
|
return origin;
|
|
113
116
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isBrowser } from '../is-browser.mjs';
|
|
2
|
+
import { hasReducedMotionListener, prefersReducedMotion } from './state.mjs';
|
|
3
|
+
|
|
4
|
+
function initPrefersReducedMotion() {
|
|
5
|
+
hasReducedMotionListener.current = true;
|
|
6
|
+
if (!isBrowser)
|
|
7
|
+
return;
|
|
8
|
+
if (window.matchMedia) {
|
|
9
|
+
const motionMediaQuery = window.matchMedia("(prefers-reduced-motion)");
|
|
10
|
+
const setReducedMotionPreferences = () => (prefersReducedMotion.current = motionMediaQuery.matches);
|
|
11
|
+
motionMediaQuery.addListener(setReducedMotionPreferences);
|
|
12
|
+
setReducedMotionPreferences();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
prefersReducedMotion.current = false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { initPrefersReducedMotion };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { MotionConfigContext } from '../../context/MotionConfigContext.mjs';
|
|
3
|
+
import { useReducedMotion } from './use-reduced-motion.mjs';
|
|
4
|
+
|
|
5
|
+
function useReducedMotionConfig() {
|
|
6
|
+
const reducedMotionPreference = useReducedMotion();
|
|
7
|
+
const { reducedMotion } = useContext(MotionConfigContext);
|
|
8
|
+
if (reducedMotion === "never") {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
else if (reducedMotion === "always") {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return reducedMotionPreference;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { useReducedMotionConfig };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { initPrefersReducedMotion } from './index.mjs';
|
|
3
|
+
import { hasReducedMotionListener, prefersReducedMotion } from './state.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
7
|
+
*
|
|
8
|
+
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
9
|
+
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
10
|
+
*
|
|
11
|
+
* It will actively respond to changes and re-render your components with the latest setting.
|
|
12
|
+
*
|
|
13
|
+
* ```jsx
|
|
14
|
+
* export function Sidebar({ isOpen }) {
|
|
15
|
+
* const shouldReduceMotion = useReducedMotion()
|
|
16
|
+
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
17
|
+
*
|
|
18
|
+
* return (
|
|
19
|
+
* <motion.div animate={{
|
|
20
|
+
* opacity: isOpen ? 1 : 0,
|
|
21
|
+
* x: isOpen ? 0 : closedX
|
|
22
|
+
* }} />
|
|
23
|
+
* )
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @return boolean
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
function useReducedMotion() {
|
|
32
|
+
/**
|
|
33
|
+
* Lazy initialisation of prefersReducedMotion
|
|
34
|
+
*/
|
|
35
|
+
!hasReducedMotionListener.current && initPrefersReducedMotion();
|
|
36
|
+
const [shouldReduceMotion] = useState(prefersReducedMotion.current);
|
|
37
|
+
/**
|
|
38
|
+
* TODO See if people miss automatically updating shouldReduceMotion setting
|
|
39
|
+
*/
|
|
40
|
+
return shouldReduceMotion;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { useReducedMotion };
|
|
@@ -11,7 +11,10 @@ function transform(...args) {
|
|
|
11
11
|
const inputRange = args[1 + argOffset];
|
|
12
12
|
const outputRange = args[2 + argOffset];
|
|
13
13
|
const options = args[3 + argOffset];
|
|
14
|
-
const interpolator = interpolate(inputRange, outputRange,
|
|
14
|
+
const interpolator = interpolate(inputRange, outputRange, {
|
|
15
|
+
mixer: getMixer(outputRange[0]),
|
|
16
|
+
...options,
|
|
17
|
+
});
|
|
15
18
|
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
16
19
|
}
|
|
17
20
|
|
|
@@ -4,7 +4,6 @@ import { inView } from '@motionone/dom';
|
|
|
4
4
|
function useInView(ref, { root, margin, amount, once = false } = {}) {
|
|
5
5
|
const [isInView, setInView] = useState(false);
|
|
6
6
|
useEffect(() => {
|
|
7
|
-
var _a;
|
|
8
7
|
if (!ref.current || (once && isInView))
|
|
9
8
|
return;
|
|
10
9
|
const onEnter = () => {
|
|
@@ -12,7 +11,7 @@ function useInView(ref, { root, margin, amount, once = false } = {}) {
|
|
|
12
11
|
return once ? undefined : () => setInView(false);
|
|
13
12
|
};
|
|
14
13
|
const options = {
|
|
15
|
-
root: (
|
|
14
|
+
root: (root && root.current) || undefined,
|
|
16
15
|
margin,
|
|
17
16
|
amount: amount === "some" ? "any" : amount,
|
|
18
17
|
};
|
package/dist/es/value/index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ class MotionValue {
|
|
|
24
24
|
* This will be replaced by the build step with the latest version number.
|
|
25
25
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
26
26
|
*/
|
|
27
|
-
this.version = "7.
|
|
27
|
+
this.version = "7.3.1";
|
|
28
28
|
/**
|
|
29
29
|
* Duration, in milliseconds, since last updating frame.
|
|
30
30
|
*
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import { scroll } from '@motionone/dom';
|
|
3
2
|
import { motionValue } from './index.mjs';
|
|
4
3
|
import { useConstant } from '../utils/use-constant.mjs';
|
|
@@ -10,8 +9,7 @@ const createScrollMotionValues = () => ({
|
|
|
10
9
|
scrollXProgress: motionValue(0),
|
|
11
10
|
scrollYProgress: motionValue(0),
|
|
12
11
|
});
|
|
13
|
-
function useScroll(
|
|
14
|
-
var { container, target } = _a, options = __rest(_a, ["container", "target"]);
|
|
12
|
+
function useScroll({ container, target, ...options } = {}) {
|
|
15
13
|
const values = useConstant(createScrollMotionValues);
|
|
16
14
|
useIsomorphicLayoutEffect(() => {
|
|
17
15
|
return scroll(({ x, y }) => {
|
|
@@ -19,7 +17,11 @@ function useScroll(_a = {}) {
|
|
|
19
17
|
values.scrollXProgress.set(x.progress);
|
|
20
18
|
values.scrollY.set(y.current);
|
|
21
19
|
values.scrollYProgress.set(y.progress);
|
|
22
|
-
},
|
|
20
|
+
}, {
|
|
21
|
+
...options,
|
|
22
|
+
container: (container === null || container === void 0 ? void 0 : container.current) || undefined,
|
|
23
|
+
target: (target === null || target === void 0 ? void 0 : target.current) || undefined,
|
|
24
|
+
});
|
|
23
25
|
}, []);
|
|
24
26
|
return values;
|
|
25
27
|
}
|
|
@@ -39,7 +39,13 @@ function useSpring(source, config = {}) {
|
|
|
39
39
|
if (activeSpringAnimation.current) {
|
|
40
40
|
activeSpringAnimation.current.stop();
|
|
41
41
|
}
|
|
42
|
-
activeSpringAnimation.current = animate(
|
|
42
|
+
activeSpringAnimation.current = animate({
|
|
43
|
+
from: value.get(),
|
|
44
|
+
to: v,
|
|
45
|
+
velocity: value.getVelocity(),
|
|
46
|
+
...config,
|
|
47
|
+
onUpdate: set,
|
|
48
|
+
});
|
|
43
49
|
return value.get();
|
|
44
50
|
});
|
|
45
51
|
}, [JSON.stringify(config)]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isCSSVariable } from '../../render/dom/utils/is-css-variable.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { transformProps } from '../../render/html/utils/transform.mjs';
|
|
3
3
|
import { addUniqueItem, removeItem } from '../../utils/array.mjs';
|
|
4
4
|
import { useConstant } from '../../utils/use-constant.mjs';
|
|
5
5
|
import { MotionValue } from '../index.mjs';
|
|
@@ -13,11 +13,11 @@ class WillChangeMotionValue extends MotionValue {
|
|
|
13
13
|
}
|
|
14
14
|
add(name) {
|
|
15
15
|
let memberName;
|
|
16
|
-
if (
|
|
16
|
+
if (transformProps.has(name)) {
|
|
17
17
|
this.transforms.add(name);
|
|
18
18
|
memberName = "transform";
|
|
19
19
|
}
|
|
20
|
-
else if (!
|
|
20
|
+
else if (!name.startsWith("origin") &&
|
|
21
21
|
!isCSSVariable(name) &&
|
|
22
22
|
name !== "willChange") {
|
|
23
23
|
memberName = camelToDash(name);
|
|
@@ -28,7 +28,7 @@ class WillChangeMotionValue extends MotionValue {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
remove(name) {
|
|
31
|
-
if (
|
|
31
|
+
if (transformProps.has(name)) {
|
|
32
32
|
this.transforms.delete(name);
|
|
33
33
|
if (!this.transforms.size) {
|
|
34
34
|
removeItem(this.members, "transform");
|