framer-motion 6.1.0 → 6.2.0
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 +87 -58
- package/dist/es/context/MotionConfigContext.mjs +1 -0
- package/dist/es/motion/utils/use-visual-element.mjs +3 -0
- package/dist/es/projection/node/create-projection-node.mjs +6 -1
- package/dist/es/render/index.mjs +2 -2
- package/dist/es/render/utils/animation.mjs +9 -1
- package/dist/es/utils/use-reduced-motion.mjs +23 -10
- package/dist/framer-motion.dev.js +87 -58
- package/dist/framer-motion.js +1 -1
- package/dist/projection.dev.js +8 -3
- 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/package.json +8 -8
- package/types/context/MotionConfigContext.d.ts +7 -0
- package/types/render/html/visual-element.d.ts +1 -1
- package/types/render/index.d.ts +1 -1
- package/types/render/svg/visual-element.d.ts +1 -1
- package/types/render/types.d.ts +2 -0
- package/types/utils/use-reduced-motion.d.ts +1 -0
package/dist/cjs/index.js
CHANGED
|
@@ -120,6 +120,7 @@ function useFeatures(props, visualElement, preloadedFeatures) {
|
|
|
120
120
|
var MotionConfigContext = React.createContext({
|
|
121
121
|
transformPagePoint: function (p) { return p; },
|
|
122
122
|
isStatic: false,
|
|
123
|
+
reducedMotion: "never",
|
|
123
124
|
});
|
|
124
125
|
|
|
125
126
|
var MotionContext = React.createContext({});
|
|
@@ -136,10 +137,79 @@ var isBrowser = typeof window !== "undefined";
|
|
|
136
137
|
|
|
137
138
|
var useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : React.useEffect;
|
|
138
139
|
|
|
140
|
+
// Does this device prefer reduced motion? Returns `null` server-side.
|
|
141
|
+
var prefersReducedMotion = { current: null };
|
|
142
|
+
function initPrefersReducedMotion() {
|
|
143
|
+
if (typeof window === "undefined")
|
|
144
|
+
return;
|
|
145
|
+
if (window.matchMedia) {
|
|
146
|
+
var motionMediaQuery_1 = window.matchMedia("(prefers-reduced-motion)");
|
|
147
|
+
var setReducedMotionPreferences = function () {
|
|
148
|
+
return (prefersReducedMotion.current = motionMediaQuery_1.matches);
|
|
149
|
+
};
|
|
150
|
+
motionMediaQuery_1.addListener(setReducedMotionPreferences);
|
|
151
|
+
setReducedMotionPreferences();
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
prefersReducedMotion.current = false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
159
|
+
*
|
|
160
|
+
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
161
|
+
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
162
|
+
*
|
|
163
|
+
* It will actively respond to changes and re-render your components with the latest setting.
|
|
164
|
+
*
|
|
165
|
+
* ```jsx
|
|
166
|
+
* export function Sidebar({ isOpen }) {
|
|
167
|
+
* const shouldReduceMotion = useReducedMotion()
|
|
168
|
+
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
169
|
+
*
|
|
170
|
+
* return (
|
|
171
|
+
* <motion.div animate={{
|
|
172
|
+
* opacity: isOpen ? 1 : 0,
|
|
173
|
+
* x: isOpen ? 0 : closedX
|
|
174
|
+
* }} />
|
|
175
|
+
* )
|
|
176
|
+
* }
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @return boolean
|
|
180
|
+
*
|
|
181
|
+
* @public
|
|
182
|
+
*/
|
|
183
|
+
function useReducedMotion() {
|
|
184
|
+
/**
|
|
185
|
+
* Lazy initialisation of prefersReducedMotion
|
|
186
|
+
*/
|
|
187
|
+
!prefersReducedMotion && initPrefersReducedMotion();
|
|
188
|
+
var _a = tslib.__read(React.useState(prefersReducedMotion.current), 1), shouldReduceMotion = _a[0];
|
|
189
|
+
/**
|
|
190
|
+
* TODO See if people miss automatically updating shouldReduceMotion setting
|
|
191
|
+
*/
|
|
192
|
+
return shouldReduceMotion;
|
|
193
|
+
}
|
|
194
|
+
function useReducedMotionConfig() {
|
|
195
|
+
var reducedMotionPreference = useReducedMotion();
|
|
196
|
+
var reducedMotion = React.useContext(MotionConfigContext).reducedMotion;
|
|
197
|
+
if (reducedMotion === "never") {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
else if (reducedMotion === "always") {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return reducedMotionPreference;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
139
208
|
function useVisualElement(Component, visualState, props, createVisualElement) {
|
|
140
209
|
var lazyContext = React.useContext(LazyContext);
|
|
141
210
|
var parent = useVisualElementContext();
|
|
142
211
|
var presenceContext = React.useContext(PresenceContext);
|
|
212
|
+
var shouldReduceMotion = useReducedMotionConfig();
|
|
143
213
|
var visualElementRef = React.useRef(undefined);
|
|
144
214
|
/**
|
|
145
215
|
* If we haven't preloaded a renderer, check to see if we have one lazy-loaded
|
|
@@ -153,6 +223,7 @@ function useVisualElement(Component, visualState, props, createVisualElement) {
|
|
|
153
223
|
props: props,
|
|
154
224
|
presenceId: presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.id,
|
|
155
225
|
blockInitialAnimation: (presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.initial) === false,
|
|
226
|
+
shouldReduceMotion: shouldReduceMotion,
|
|
156
227
|
});
|
|
157
228
|
}
|
|
158
229
|
var visualElement = visualElementRef.current;
|
|
@@ -1943,7 +2014,12 @@ function createProjectionNode(_a) {
|
|
|
1943
2014
|
_this.resumingFrom.resumingFrom = undefined;
|
|
1944
2015
|
}
|
|
1945
2016
|
_this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
|
|
1946
|
-
|
|
2017
|
+
var animationOptions = tslib.__assign(tslib.__assign({}, getValueTransition(layoutTransition, "layout")), { onComplete: onLayoutAnimationComplete });
|
|
2018
|
+
if (visualElement.shouldReduceMotion) {
|
|
2019
|
+
animationOptions.delay = 0;
|
|
2020
|
+
animationOptions.type = false;
|
|
2021
|
+
}
|
|
2022
|
+
_this.startAnimation(animationOptions);
|
|
1947
2023
|
}
|
|
1948
2024
|
else {
|
|
1949
2025
|
_this.isLead() && ((_f = (_e = _this.options).onExitComplete) === null || _f === void 0 ? void 0 : _f.call(_e));
|
|
@@ -4572,7 +4648,14 @@ function animateTarget(visualElement, definition, _a) {
|
|
|
4572
4648
|
shouldBlockAnimation(animationTypeState, key))) {
|
|
4573
4649
|
continue;
|
|
4574
4650
|
}
|
|
4575
|
-
var
|
|
4651
|
+
var valueTransition = tslib.__assign({ delay: delay }, transition);
|
|
4652
|
+
/**
|
|
4653
|
+
* Make animation instant if this is a transform prop and we should reduce motion.
|
|
4654
|
+
*/
|
|
4655
|
+
if (visualElement.shouldReduceMotion && isTransformProp(key)) {
|
|
4656
|
+
valueTransition = tslib.__assign(tslib.__assign({}, valueTransition), { type: false, delay: 0 });
|
|
4657
|
+
}
|
|
4658
|
+
var animation = startAnimation(key, value, valueTarget, valueTransition);
|
|
4576
4659
|
animations.push(animation);
|
|
4577
4660
|
}
|
|
4578
4661
|
return Promise.all(animations).then(function () {
|
|
@@ -5870,7 +5953,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
5870
5953
|
var visualElement = function (_a) {
|
|
5871
5954
|
var _b = _a.treeType, treeType = _b === void 0 ? "" : _b, build = _a.build, getBaseTarget = _a.getBaseTarget, makeTargetAnimatable = _a.makeTargetAnimatable, measureViewportBox = _a.measureViewportBox, renderInstance = _a.render, readValueFromInstance = _a.readValueFromInstance, removeValueFromRenderState = _a.removeValueFromRenderState, sortNodePosition = _a.sortNodePosition, scrapeMotionValuesFromProps = _a.scrapeMotionValuesFromProps;
|
|
5872
5955
|
return function (_a, options) {
|
|
5873
|
-
var parent = _a.parent, props = _a.props, presenceId = _a.presenceId, blockInitialAnimation = _a.blockInitialAnimation, visualState = _a.visualState;
|
|
5956
|
+
var parent = _a.parent, props = _a.props, presenceId = _a.presenceId, blockInitialAnimation = _a.blockInitialAnimation, visualState = _a.visualState, shouldReduceMotion = _a.shouldReduceMotion;
|
|
5874
5957
|
if (options === void 0) { options = {}; }
|
|
5875
5958
|
var isMounted = false;
|
|
5876
5959
|
var latestValues = visualState.latestValues, renderState = visualState.renderState;
|
|
@@ -5979,7 +6062,7 @@ var visualElement = function (_a) {
|
|
|
5979
6062
|
/**
|
|
5980
6063
|
*
|
|
5981
6064
|
*/
|
|
5982
|
-
presenceId: presenceId,
|
|
6065
|
+
presenceId: presenceId, shouldReduceMotion: shouldReduceMotion,
|
|
5983
6066
|
/**
|
|
5984
6067
|
* If this component is part of the variant tree, it should track
|
|
5985
6068
|
* any children that are also part of the tree. This is essentially
|
|
@@ -7875,60 +7958,6 @@ function useTime() {
|
|
|
7875
7958
|
return time;
|
|
7876
7959
|
}
|
|
7877
7960
|
|
|
7878
|
-
// Does this device prefer reduced motion? Returns `null` server-side.
|
|
7879
|
-
var prefersReducedMotion;
|
|
7880
|
-
function initPrefersReducedMotion() {
|
|
7881
|
-
prefersReducedMotion = motionValue(null);
|
|
7882
|
-
if (typeof window === "undefined")
|
|
7883
|
-
return;
|
|
7884
|
-
if (window.matchMedia) {
|
|
7885
|
-
var motionMediaQuery_1 = window.matchMedia("(prefers-reduced-motion)");
|
|
7886
|
-
var setReducedMotionPreferences = function () {
|
|
7887
|
-
return prefersReducedMotion.set(motionMediaQuery_1.matches);
|
|
7888
|
-
};
|
|
7889
|
-
motionMediaQuery_1.addListener(setReducedMotionPreferences);
|
|
7890
|
-
setReducedMotionPreferences();
|
|
7891
|
-
}
|
|
7892
|
-
else {
|
|
7893
|
-
prefersReducedMotion.set(false);
|
|
7894
|
-
}
|
|
7895
|
-
}
|
|
7896
|
-
/**
|
|
7897
|
-
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
7898
|
-
*
|
|
7899
|
-
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
7900
|
-
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
7901
|
-
*
|
|
7902
|
-
* It will actively respond to changes and re-render your components with the latest setting.
|
|
7903
|
-
*
|
|
7904
|
-
* ```jsx
|
|
7905
|
-
* export function Sidebar({ isOpen }) {
|
|
7906
|
-
* const shouldReduceMotion = useReducedMotion()
|
|
7907
|
-
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
7908
|
-
*
|
|
7909
|
-
* return (
|
|
7910
|
-
* <motion.div animate={{
|
|
7911
|
-
* opacity: isOpen ? 1 : 0,
|
|
7912
|
-
* x: isOpen ? 0 : closedX
|
|
7913
|
-
* }} />
|
|
7914
|
-
* )
|
|
7915
|
-
* }
|
|
7916
|
-
* ```
|
|
7917
|
-
*
|
|
7918
|
-
* @return boolean
|
|
7919
|
-
*
|
|
7920
|
-
* @public
|
|
7921
|
-
*/
|
|
7922
|
-
function useReducedMotion() {
|
|
7923
|
-
/**
|
|
7924
|
-
* Lazy initialisation of prefersReducedMotion
|
|
7925
|
-
*/
|
|
7926
|
-
!prefersReducedMotion && initPrefersReducedMotion();
|
|
7927
|
-
var _a = tslib.__read(React.useState(prefersReducedMotion.get()), 2), shouldReduceMotion = _a[0], setShouldReduceMotion = _a[1];
|
|
7928
|
-
useOnChange(prefersReducedMotion, setShouldReduceMotion);
|
|
7929
|
-
return shouldReduceMotion;
|
|
7930
|
-
}
|
|
7931
|
-
|
|
7932
7961
|
/**
|
|
7933
7962
|
* @public
|
|
7934
7963
|
*/
|
|
@@ -3,11 +3,13 @@ import { PresenceContext } from '../../context/PresenceContext.mjs';
|
|
|
3
3
|
import { useVisualElementContext } from '../../context/MotionContext/index.mjs';
|
|
4
4
|
import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
|
|
5
5
|
import { LazyContext } from '../../context/LazyContext.mjs';
|
|
6
|
+
import { useReducedMotionConfig } from '../../utils/use-reduced-motion.mjs';
|
|
6
7
|
|
|
7
8
|
function useVisualElement(Component, visualState, props, createVisualElement) {
|
|
8
9
|
var lazyContext = useContext(LazyContext);
|
|
9
10
|
var parent = useVisualElementContext();
|
|
10
11
|
var presenceContext = useContext(PresenceContext);
|
|
12
|
+
var shouldReduceMotion = useReducedMotionConfig();
|
|
11
13
|
var visualElementRef = useRef(undefined);
|
|
12
14
|
/**
|
|
13
15
|
* If we haven't preloaded a renderer, check to see if we have one lazy-loaded
|
|
@@ -21,6 +23,7 @@ function useVisualElement(Component, visualState, props, createVisualElement) {
|
|
|
21
23
|
props: props,
|
|
22
24
|
presenceId: presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.id,
|
|
23
25
|
blockInitialAnimation: (presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.initial) === false,
|
|
26
|
+
shouldReduceMotion: shouldReduceMotion,
|
|
24
27
|
});
|
|
25
28
|
}
|
|
26
29
|
var visualElement = visualElementRef.current;
|
|
@@ -244,7 +244,12 @@ function createProjectionNode(_a) {
|
|
|
244
244
|
_this.resumingFrom.resumingFrom = undefined;
|
|
245
245
|
}
|
|
246
246
|
_this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
|
|
247
|
-
|
|
247
|
+
var animationOptions = __assign(__assign({}, getValueTransition(layoutTransition, "layout")), { onComplete: onLayoutAnimationComplete });
|
|
248
|
+
if (visualElement.shouldReduceMotion) {
|
|
249
|
+
animationOptions.delay = 0;
|
|
250
|
+
animationOptions.type = false;
|
|
251
|
+
}
|
|
252
|
+
_this.startAnimation(animationOptions);
|
|
248
253
|
}
|
|
249
254
|
else {
|
|
250
255
|
_this.isLead() && ((_f = (_e = _this.options).onExitComplete) === null || _f === void 0 ? void 0 : _f.call(_e));
|
package/dist/es/render/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import { checkIfControllingVariants, checkIfVariantNode, isVariantLabel } from '
|
|
|
10
10
|
var visualElement = function (_a) {
|
|
11
11
|
var _b = _a.treeType, treeType = _b === void 0 ? "" : _b, build = _a.build, getBaseTarget = _a.getBaseTarget, makeTargetAnimatable = _a.makeTargetAnimatable, measureViewportBox = _a.measureViewportBox, renderInstance = _a.render, readValueFromInstance = _a.readValueFromInstance, removeValueFromRenderState = _a.removeValueFromRenderState, sortNodePosition = _a.sortNodePosition, scrapeMotionValuesFromProps = _a.scrapeMotionValuesFromProps;
|
|
12
12
|
return function (_a, options) {
|
|
13
|
-
var parent = _a.parent, props = _a.props, presenceId = _a.presenceId, blockInitialAnimation = _a.blockInitialAnimation, visualState = _a.visualState;
|
|
13
|
+
var parent = _a.parent, props = _a.props, presenceId = _a.presenceId, blockInitialAnimation = _a.blockInitialAnimation, visualState = _a.visualState, shouldReduceMotion = _a.shouldReduceMotion;
|
|
14
14
|
if (options === void 0) { options = {}; }
|
|
15
15
|
var isMounted = false;
|
|
16
16
|
var latestValues = visualState.latestValues, renderState = visualState.renderState;
|
|
@@ -119,7 +119,7 @@ var visualElement = function (_a) {
|
|
|
119
119
|
/**
|
|
120
120
|
*
|
|
121
121
|
*/
|
|
122
|
-
presenceId: presenceId,
|
|
122
|
+
presenceId: presenceId, shouldReduceMotion: shouldReduceMotion,
|
|
123
123
|
/**
|
|
124
124
|
* If this component is part of the variant tree, it should track
|
|
125
125
|
* any children that are also part of the tree. This is essentially
|
|
@@ -2,6 +2,7 @@ import { __read, __rest, __assign } 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
|
+
import { isTransformProp } from '../html/utils/transform.mjs';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @internal
|
|
@@ -90,7 +91,14 @@ function animateTarget(visualElement, definition, _a) {
|
|
|
90
91
|
shouldBlockAnimation(animationTypeState, key))) {
|
|
91
92
|
continue;
|
|
92
93
|
}
|
|
93
|
-
var
|
|
94
|
+
var valueTransition = __assign({ delay: delay }, transition);
|
|
95
|
+
/**
|
|
96
|
+
* Make animation instant if this is a transform prop and we should reduce motion.
|
|
97
|
+
*/
|
|
98
|
+
if (visualElement.shouldReduceMotion && isTransformProp(key)) {
|
|
99
|
+
valueTransition = __assign(__assign({}, valueTransition), { type: false, delay: 0 });
|
|
100
|
+
}
|
|
101
|
+
var animation = startAnimation(key, value, valueTarget, valueTransition);
|
|
94
102
|
animations.push(animation);
|
|
95
103
|
}
|
|
96
104
|
return Promise.all(animations).then(function () {
|
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { __read } from 'tslib';
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import { useOnChange } from '../value/use-on-change.mjs';
|
|
2
|
+
import { useState, useContext } from 'react';
|
|
3
|
+
import { MotionConfigContext } from '../context/MotionConfigContext.mjs';
|
|
5
4
|
|
|
6
5
|
// Does this device prefer reduced motion? Returns `null` server-side.
|
|
7
|
-
var prefersReducedMotion;
|
|
6
|
+
var prefersReducedMotion = { current: null };
|
|
8
7
|
function initPrefersReducedMotion() {
|
|
9
|
-
prefersReducedMotion = motionValue(null);
|
|
10
8
|
if (typeof window === "undefined")
|
|
11
9
|
return;
|
|
12
10
|
if (window.matchMedia) {
|
|
13
11
|
var motionMediaQuery_1 = window.matchMedia("(prefers-reduced-motion)");
|
|
14
12
|
var setReducedMotionPreferences = function () {
|
|
15
|
-
return prefersReducedMotion.
|
|
13
|
+
return (prefersReducedMotion.current = motionMediaQuery_1.matches);
|
|
16
14
|
};
|
|
17
15
|
motionMediaQuery_1.addListener(setReducedMotionPreferences);
|
|
18
16
|
setReducedMotionPreferences();
|
|
19
17
|
}
|
|
20
18
|
else {
|
|
21
|
-
prefersReducedMotion.
|
|
19
|
+
prefersReducedMotion.current = false;
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
22
|
/**
|
|
@@ -52,9 +50,24 @@ function useReducedMotion() {
|
|
|
52
50
|
* Lazy initialisation of prefersReducedMotion
|
|
53
51
|
*/
|
|
54
52
|
!prefersReducedMotion && initPrefersReducedMotion();
|
|
55
|
-
var _a = __read(useState(prefersReducedMotion.
|
|
56
|
-
|
|
53
|
+
var _a = __read(useState(prefersReducedMotion.current), 1), shouldReduceMotion = _a[0];
|
|
54
|
+
/**
|
|
55
|
+
* TODO See if people miss automatically updating shouldReduceMotion setting
|
|
56
|
+
*/
|
|
57
57
|
return shouldReduceMotion;
|
|
58
58
|
}
|
|
59
|
+
function useReducedMotionConfig() {
|
|
60
|
+
var reducedMotionPreference = useReducedMotion();
|
|
61
|
+
var reducedMotion = useContext(MotionConfigContext).reducedMotion;
|
|
62
|
+
if (reducedMotion === "never") {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
else if (reducedMotion === "always") {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return reducedMotionPreference;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
59
72
|
|
|
60
|
-
export { useReducedMotion };
|
|
73
|
+
export { useReducedMotion, useReducedMotionConfig };
|
|
@@ -221,6 +221,7 @@
|
|
|
221
221
|
var MotionConfigContext = React.createContext({
|
|
222
222
|
transformPagePoint: function (p) { return p; },
|
|
223
223
|
isStatic: false,
|
|
224
|
+
reducedMotion: "never",
|
|
224
225
|
});
|
|
225
226
|
|
|
226
227
|
var MotionContext = React.createContext({});
|
|
@@ -237,10 +238,79 @@
|
|
|
237
238
|
|
|
238
239
|
var useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : React.useEffect;
|
|
239
240
|
|
|
241
|
+
// Does this device prefer reduced motion? Returns `null` server-side.
|
|
242
|
+
var prefersReducedMotion = { current: null };
|
|
243
|
+
function initPrefersReducedMotion() {
|
|
244
|
+
if (typeof window === "undefined")
|
|
245
|
+
return;
|
|
246
|
+
if (window.matchMedia) {
|
|
247
|
+
var motionMediaQuery_1 = window.matchMedia("(prefers-reduced-motion)");
|
|
248
|
+
var setReducedMotionPreferences = function () {
|
|
249
|
+
return (prefersReducedMotion.current = motionMediaQuery_1.matches);
|
|
250
|
+
};
|
|
251
|
+
motionMediaQuery_1.addListener(setReducedMotionPreferences);
|
|
252
|
+
setReducedMotionPreferences();
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
prefersReducedMotion.current = false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
260
|
+
*
|
|
261
|
+
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
262
|
+
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
263
|
+
*
|
|
264
|
+
* It will actively respond to changes and re-render your components with the latest setting.
|
|
265
|
+
*
|
|
266
|
+
* ```jsx
|
|
267
|
+
* export function Sidebar({ isOpen }) {
|
|
268
|
+
* const shouldReduceMotion = useReducedMotion()
|
|
269
|
+
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
270
|
+
*
|
|
271
|
+
* return (
|
|
272
|
+
* <motion.div animate={{
|
|
273
|
+
* opacity: isOpen ? 1 : 0,
|
|
274
|
+
* x: isOpen ? 0 : closedX
|
|
275
|
+
* }} />
|
|
276
|
+
* )
|
|
277
|
+
* }
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @return boolean
|
|
281
|
+
*
|
|
282
|
+
* @public
|
|
283
|
+
*/
|
|
284
|
+
function useReducedMotion() {
|
|
285
|
+
/**
|
|
286
|
+
* Lazy initialisation of prefersReducedMotion
|
|
287
|
+
*/
|
|
288
|
+
!prefersReducedMotion && initPrefersReducedMotion();
|
|
289
|
+
var _a = __read(React.useState(prefersReducedMotion.current), 1), shouldReduceMotion = _a[0];
|
|
290
|
+
/**
|
|
291
|
+
* TODO See if people miss automatically updating shouldReduceMotion setting
|
|
292
|
+
*/
|
|
293
|
+
return shouldReduceMotion;
|
|
294
|
+
}
|
|
295
|
+
function useReducedMotionConfig() {
|
|
296
|
+
var reducedMotionPreference = useReducedMotion();
|
|
297
|
+
var reducedMotion = React.useContext(MotionConfigContext).reducedMotion;
|
|
298
|
+
if (reducedMotion === "never") {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
else if (reducedMotion === "always") {
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
return reducedMotionPreference;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
240
309
|
function useVisualElement(Component, visualState, props, createVisualElement) {
|
|
241
310
|
var lazyContext = React.useContext(LazyContext);
|
|
242
311
|
var parent = useVisualElementContext();
|
|
243
312
|
var presenceContext = React.useContext(PresenceContext);
|
|
313
|
+
var shouldReduceMotion = useReducedMotionConfig();
|
|
244
314
|
var visualElementRef = React.useRef(undefined);
|
|
245
315
|
/**
|
|
246
316
|
* If we haven't preloaded a renderer, check to see if we have one lazy-loaded
|
|
@@ -254,6 +324,7 @@
|
|
|
254
324
|
props: props,
|
|
255
325
|
presenceId: presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.id,
|
|
256
326
|
blockInitialAnimation: (presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.initial) === false,
|
|
327
|
+
shouldReduceMotion: shouldReduceMotion,
|
|
257
328
|
});
|
|
258
329
|
}
|
|
259
330
|
var visualElement = visualElementRef.current;
|
|
@@ -3176,7 +3247,12 @@
|
|
|
3176
3247
|
_this.resumingFrom.resumingFrom = undefined;
|
|
3177
3248
|
}
|
|
3178
3249
|
_this.setAnimationOrigin(delta, hasOnlyRelativeTargetChanged);
|
|
3179
|
-
|
|
3250
|
+
var animationOptions = __assign(__assign({}, getValueTransition(layoutTransition, "layout")), { onComplete: onLayoutAnimationComplete });
|
|
3251
|
+
if (visualElement.shouldReduceMotion) {
|
|
3252
|
+
animationOptions.delay = 0;
|
|
3253
|
+
animationOptions.type = false;
|
|
3254
|
+
}
|
|
3255
|
+
_this.startAnimation(animationOptions);
|
|
3180
3256
|
}
|
|
3181
3257
|
else {
|
|
3182
3258
|
_this.isLead() && ((_f = (_e = _this.options).onExitComplete) === null || _f === void 0 ? void 0 : _f.call(_e));
|
|
@@ -5805,7 +5881,14 @@
|
|
|
5805
5881
|
shouldBlockAnimation(animationTypeState, key))) {
|
|
5806
5882
|
continue;
|
|
5807
5883
|
}
|
|
5808
|
-
var
|
|
5884
|
+
var valueTransition = __assign({ delay: delay }, transition);
|
|
5885
|
+
/**
|
|
5886
|
+
* Make animation instant if this is a transform prop and we should reduce motion.
|
|
5887
|
+
*/
|
|
5888
|
+
if (visualElement.shouldReduceMotion && isTransformProp(key)) {
|
|
5889
|
+
valueTransition = __assign(__assign({}, valueTransition), { type: false, delay: 0 });
|
|
5890
|
+
}
|
|
5891
|
+
var animation = startAnimation(key, value, valueTarget, valueTransition);
|
|
5809
5892
|
animations.push(animation);
|
|
5810
5893
|
}
|
|
5811
5894
|
return Promise.all(animations).then(function () {
|
|
@@ -7103,7 +7186,7 @@
|
|
|
7103
7186
|
var visualElement = function (_a) {
|
|
7104
7187
|
var _b = _a.treeType, treeType = _b === void 0 ? "" : _b, build = _a.build, getBaseTarget = _a.getBaseTarget, makeTargetAnimatable = _a.makeTargetAnimatable, measureViewportBox = _a.measureViewportBox, renderInstance = _a.render, readValueFromInstance = _a.readValueFromInstance, removeValueFromRenderState = _a.removeValueFromRenderState, sortNodePosition = _a.sortNodePosition, scrapeMotionValuesFromProps = _a.scrapeMotionValuesFromProps;
|
|
7105
7188
|
return function (_a, options) {
|
|
7106
|
-
var parent = _a.parent, props = _a.props, presenceId = _a.presenceId, blockInitialAnimation = _a.blockInitialAnimation, visualState = _a.visualState;
|
|
7189
|
+
var parent = _a.parent, props = _a.props, presenceId = _a.presenceId, blockInitialAnimation = _a.blockInitialAnimation, visualState = _a.visualState, shouldReduceMotion = _a.shouldReduceMotion;
|
|
7107
7190
|
if (options === void 0) { options = {}; }
|
|
7108
7191
|
var isMounted = false;
|
|
7109
7192
|
var latestValues = visualState.latestValues, renderState = visualState.renderState;
|
|
@@ -7212,7 +7295,7 @@
|
|
|
7212
7295
|
/**
|
|
7213
7296
|
*
|
|
7214
7297
|
*/
|
|
7215
|
-
presenceId: presenceId,
|
|
7298
|
+
presenceId: presenceId, shouldReduceMotion: shouldReduceMotion,
|
|
7216
7299
|
/**
|
|
7217
7300
|
* If this component is part of the variant tree, it should track
|
|
7218
7301
|
* any children that are also part of the tree. This is essentially
|
|
@@ -9107,60 +9190,6 @@
|
|
|
9107
9190
|
return time;
|
|
9108
9191
|
}
|
|
9109
9192
|
|
|
9110
|
-
// Does this device prefer reduced motion? Returns `null` server-side.
|
|
9111
|
-
var prefersReducedMotion;
|
|
9112
|
-
function initPrefersReducedMotion() {
|
|
9113
|
-
prefersReducedMotion = motionValue(null);
|
|
9114
|
-
if (typeof window === "undefined")
|
|
9115
|
-
return;
|
|
9116
|
-
if (window.matchMedia) {
|
|
9117
|
-
var motionMediaQuery_1 = window.matchMedia("(prefers-reduced-motion)");
|
|
9118
|
-
var setReducedMotionPreferences = function () {
|
|
9119
|
-
return prefersReducedMotion.set(motionMediaQuery_1.matches);
|
|
9120
|
-
};
|
|
9121
|
-
motionMediaQuery_1.addListener(setReducedMotionPreferences);
|
|
9122
|
-
setReducedMotionPreferences();
|
|
9123
|
-
}
|
|
9124
|
-
else {
|
|
9125
|
-
prefersReducedMotion.set(false);
|
|
9126
|
-
}
|
|
9127
|
-
}
|
|
9128
|
-
/**
|
|
9129
|
-
* A hook that returns `true` if we should be using reduced motion based on the current device's Reduced Motion setting.
|
|
9130
|
-
*
|
|
9131
|
-
* This can be used to implement changes to your UI based on Reduced Motion. For instance, replacing motion-sickness inducing
|
|
9132
|
-
* `x`/`y` animations with `opacity`, disabling the autoplay of background videos, or turning off parallax motion.
|
|
9133
|
-
*
|
|
9134
|
-
* It will actively respond to changes and re-render your components with the latest setting.
|
|
9135
|
-
*
|
|
9136
|
-
* ```jsx
|
|
9137
|
-
* export function Sidebar({ isOpen }) {
|
|
9138
|
-
* const shouldReduceMotion = useReducedMotion()
|
|
9139
|
-
* const closedX = shouldReduceMotion ? 0 : "-100%"
|
|
9140
|
-
*
|
|
9141
|
-
* return (
|
|
9142
|
-
* <motion.div animate={{
|
|
9143
|
-
* opacity: isOpen ? 1 : 0,
|
|
9144
|
-
* x: isOpen ? 0 : closedX
|
|
9145
|
-
* }} />
|
|
9146
|
-
* )
|
|
9147
|
-
* }
|
|
9148
|
-
* ```
|
|
9149
|
-
*
|
|
9150
|
-
* @return boolean
|
|
9151
|
-
*
|
|
9152
|
-
* @public
|
|
9153
|
-
*/
|
|
9154
|
-
function useReducedMotion() {
|
|
9155
|
-
/**
|
|
9156
|
-
* Lazy initialisation of prefersReducedMotion
|
|
9157
|
-
*/
|
|
9158
|
-
!prefersReducedMotion && initPrefersReducedMotion();
|
|
9159
|
-
var _a = __read(React.useState(prefersReducedMotion.get()), 2), shouldReduceMotion = _a[0], setShouldReduceMotion = _a[1];
|
|
9160
|
-
useOnChange(prefersReducedMotion, setShouldReduceMotion);
|
|
9161
|
-
return shouldReduceMotion;
|
|
9162
|
-
}
|
|
9163
|
-
|
|
9164
9193
|
/**
|
|
9165
9194
|
* @public
|
|
9166
9195
|
*/
|