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,22 +1,17 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { interpolate } from 'popmotion';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
const isCustomValueType = (v) => {
|
|
5
4
|
return typeof v === "object" && v.mix;
|
|
6
5
|
};
|
|
7
|
-
|
|
8
|
-
function transform() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var inputRange = args[1 + argOffset];
|
|
17
|
-
var outputRange = args[2 + argOffset];
|
|
18
|
-
var options = args[3 + argOffset];
|
|
19
|
-
var interpolator = interpolate(inputRange, outputRange, __assign({ mixer: getMixer(outputRange[0]) }, options));
|
|
6
|
+
const getMixer = (v) => (isCustomValueType(v) ? v.mix : undefined);
|
|
7
|
+
function transform(...args) {
|
|
8
|
+
const useImmediate = !Array.isArray(args[0]);
|
|
9
|
+
const argOffset = useImmediate ? 0 : -1;
|
|
10
|
+
const inputValue = args[0 + argOffset];
|
|
11
|
+
const inputRange = args[1 + argOffset];
|
|
12
|
+
const outputRange = args[2 + argOffset];
|
|
13
|
+
const options = args[3 + argOffset];
|
|
14
|
+
const interpolator = interpolate(inputRange, outputRange, Object.assign({ mixer: getMixer(outputRange[0]) }, options));
|
|
20
15
|
return useImmediate ? interpolator(inputValue) : interpolator;
|
|
21
16
|
}
|
|
22
17
|
|
|
@@ -3,19 +3,18 @@ import { useRef, useContext, useEffect } from 'react';
|
|
|
3
3
|
import { MotionConfigContext } from '../context/MotionConfigContext.mjs';
|
|
4
4
|
|
|
5
5
|
function useAnimationFrame(callback) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
useEffect(
|
|
6
|
+
const initialTimestamp = useRef(0);
|
|
7
|
+
const { isStatic } = useContext(MotionConfigContext);
|
|
8
|
+
useEffect(() => {
|
|
9
9
|
if (isStatic)
|
|
10
10
|
return;
|
|
11
|
-
|
|
12
|
-
var timestamp = _a.timestamp;
|
|
11
|
+
const provideTimeSinceStart = ({ timestamp }) => {
|
|
13
12
|
if (!initialTimestamp.current)
|
|
14
13
|
initialTimestamp.current = timestamp;
|
|
15
14
|
callback(timestamp - initialTimestamp.current);
|
|
16
15
|
};
|
|
17
16
|
sync.update(provideTimeSinceStart, true);
|
|
18
|
-
return
|
|
17
|
+
return () => cancelSync.update(provideTimeSinceStart);
|
|
19
18
|
}, [callback]);
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __read, __spreadArray } from 'tslib';
|
|
2
1
|
import { wrap } from 'popmotion';
|
|
3
2
|
import { useRef, useState, useCallback } from 'react';
|
|
4
3
|
|
|
@@ -28,20 +27,20 @@ import { useRef, useState, useCallback } from 'react';
|
|
|
28
27
|
*
|
|
29
28
|
* @public
|
|
30
29
|
*/
|
|
31
|
-
function useCycle() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
var index = useRef(0);
|
|
37
|
-
var _a = __read(useState(items[index.current]), 2), item = _a[0], setItem = _a[1];
|
|
38
|
-
var runCycle = useCallback(function (next) {
|
|
30
|
+
function useCycle(...items) {
|
|
31
|
+
const index = useRef(0);
|
|
32
|
+
const [item, setItem] = useState(items[index.current]);
|
|
33
|
+
const runCycle = useCallback((next) => {
|
|
39
34
|
index.current =
|
|
40
35
|
typeof next !== "number"
|
|
41
36
|
? wrap(0, items.length, index.current + 1)
|
|
42
37
|
: next;
|
|
43
38
|
setItem(items[index.current]);
|
|
44
|
-
},
|
|
39
|
+
},
|
|
40
|
+
// The array will change on each call, but by putting items.length at
|
|
41
|
+
// the front of this array, we guarantee the dependency comparison will match up
|
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
|
+
[items.length, ...items]);
|
|
45
44
|
return [item, runCycle];
|
|
46
45
|
}
|
|
47
46
|
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import { __read } from 'tslib';
|
|
2
1
|
import sync from 'framesync';
|
|
3
2
|
import { useState, useCallback } from 'react';
|
|
4
3
|
import { useIsMounted } from './use-is-mounted.mjs';
|
|
5
4
|
|
|
6
5
|
function useForceUpdate() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const isMounted = useIsMounted();
|
|
7
|
+
const [forcedRenderCount, setForcedRenderCount] = useState(0);
|
|
8
|
+
const forceRender = useCallback(() => {
|
|
10
9
|
isMounted.current && setForcedRenderCount(forcedRenderCount + 1);
|
|
11
10
|
}, [forcedRenderCount]);
|
|
12
11
|
/**
|
|
13
12
|
* Defer this to the end of the next animation frame in case there are multiple
|
|
14
13
|
* synchronous calls.
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
const deferredForceRender = useCallback(() => sync.postRender(forceRender), [forceRender]);
|
|
17
16
|
return [deferredForceRender, forcedRenderCount];
|
|
18
17
|
}
|
|
19
18
|
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { __read } from 'tslib';
|
|
2
1
|
import { useState, useEffect } from 'react';
|
|
3
2
|
import { inView } from '@motionone/dom';
|
|
4
3
|
|
|
5
|
-
function useInView(ref,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
useEffect(function () {
|
|
4
|
+
function useInView(ref, { root, margin, amount, once = false } = {}) {
|
|
5
|
+
const [isInView, setInView] = useState(false);
|
|
6
|
+
useEffect(() => {
|
|
9
7
|
var _a;
|
|
10
8
|
if (!ref.current || (once && isInView))
|
|
11
9
|
return;
|
|
12
|
-
|
|
10
|
+
const onEnter = () => {
|
|
13
11
|
setInView(true);
|
|
14
|
-
return once ? undefined :
|
|
12
|
+
return once ? undefined : () => setInView(false);
|
|
15
13
|
};
|
|
16
|
-
|
|
14
|
+
const options = {
|
|
17
15
|
root: (_a = root === null || root === void 0 ? void 0 : root.current) !== null && _a !== void 0 ? _a : undefined,
|
|
18
|
-
margin
|
|
16
|
+
margin,
|
|
19
17
|
amount: amount === "some" ? "any" : amount,
|
|
20
18
|
};
|
|
21
19
|
return inView(ref.current, onEnter, options);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __read } from 'tslib';
|
|
2
1
|
import sync from 'framesync';
|
|
3
2
|
import { useEffect } from 'react';
|
|
4
3
|
import { useInstantLayoutTransition } from '../projection/use-instant-layout-transition.mjs';
|
|
@@ -6,18 +5,16 @@ import { useForceUpdate } from './use-force-update.mjs';
|
|
|
6
5
|
import { instantAnimationState } from './use-instant-transition-state.mjs';
|
|
7
6
|
|
|
8
7
|
function useInstantTransition() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
useEffect(
|
|
8
|
+
const [forceUpdate, forcedRenderCount] = useForceUpdate();
|
|
9
|
+
const startInstantLayoutTransition = useInstantLayoutTransition();
|
|
10
|
+
useEffect(() => {
|
|
12
11
|
/**
|
|
13
12
|
* Unblock after two animation frames, otherwise this will unblock too soon.
|
|
14
13
|
*/
|
|
15
|
-
sync.postRender(
|
|
16
|
-
return sync.postRender(function () { return (instantAnimationState.current = false); });
|
|
17
|
-
});
|
|
14
|
+
sync.postRender(() => sync.postRender(() => (instantAnimationState.current = false)));
|
|
18
15
|
}, [forcedRenderCount]);
|
|
19
|
-
return
|
|
20
|
-
startInstantLayoutTransition(
|
|
16
|
+
return (callback) => {
|
|
17
|
+
startInstantLayoutTransition(() => {
|
|
21
18
|
instantAnimationState.current = true;
|
|
22
19
|
forceUpdate();
|
|
23
20
|
callback();
|
|
@@ -2,10 +2,10 @@ import { useRef } from 'react';
|
|
|
2
2
|
import { useIsomorphicLayoutEffect } from './use-isomorphic-effect.mjs';
|
|
3
3
|
|
|
4
4
|
function useIsMounted() {
|
|
5
|
-
|
|
6
|
-
useIsomorphicLayoutEffect(
|
|
5
|
+
const isMounted = useRef(false);
|
|
6
|
+
useIsomorphicLayoutEffect(() => {
|
|
7
7
|
isMounted.current = true;
|
|
8
|
-
return
|
|
8
|
+
return () => {
|
|
9
9
|
isMounted.current = false;
|
|
10
10
|
};
|
|
11
11
|
}, []);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useLayoutEffect, useEffect } from 'react';
|
|
2
2
|
import { isBrowser } from './is-browser.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect;
|
|
5
5
|
|
|
6
6
|
export { useIsomorphicLayoutEffect };
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import { __read } from 'tslib';
|
|
2
1
|
import { useState, useContext } from 'react';
|
|
3
2
|
import { MotionConfigContext } from '../context/MotionConfigContext.mjs';
|
|
4
3
|
import { isBrowser } from './is-browser.mjs';
|
|
5
4
|
|
|
6
5
|
// Does this device prefer reduced motion? Returns `null` server-side.
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const prefersReducedMotion = { current: null };
|
|
7
|
+
let hasDetected = false;
|
|
9
8
|
function initPrefersReducedMotion() {
|
|
10
9
|
hasDetected = true;
|
|
11
10
|
if (!isBrowser)
|
|
12
11
|
return;
|
|
13
12
|
if (window.matchMedia) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
motionMediaQuery_1.addListener(setReducedMotionPreferences);
|
|
13
|
+
const motionMediaQuery = window.matchMedia("(prefers-reduced-motion)");
|
|
14
|
+
const setReducedMotionPreferences = () => (prefersReducedMotion.current = motionMediaQuery.matches);
|
|
15
|
+
motionMediaQuery.addListener(setReducedMotionPreferences);
|
|
19
16
|
setReducedMotionPreferences();
|
|
20
17
|
}
|
|
21
18
|
else {
|
|
@@ -53,15 +50,15 @@ function useReducedMotion() {
|
|
|
53
50
|
* Lazy initialisation of prefersReducedMotion
|
|
54
51
|
*/
|
|
55
52
|
!hasDetected && initPrefersReducedMotion();
|
|
56
|
-
|
|
53
|
+
const [shouldReduceMotion] = useState(prefersReducedMotion.current);
|
|
57
54
|
/**
|
|
58
55
|
* TODO See if people miss automatically updating shouldReduceMotion setting
|
|
59
56
|
*/
|
|
60
57
|
return shouldReduceMotion;
|
|
61
58
|
}
|
|
62
59
|
function useReducedMotionConfig() {
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
const reducedMotionPreference = useReducedMotion();
|
|
61
|
+
const { reducedMotion } = useContext(MotionConfigContext);
|
|
65
62
|
if (reducedMotion === "never") {
|
|
66
63
|
return false;
|
|
67
64
|
}
|
package/dist/es/value/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import sync, { getFrameData } from 'framesync';
|
|
|
2
2
|
import { velocityPerSecond } from 'popmotion';
|
|
3
3
|
import { SubscriptionManager } from '../utils/subscription-manager.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const isFloat = (value) => {
|
|
6
6
|
return !isNaN(parseFloat(value));
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
@@ -10,7 +10,7 @@ var isFloat = function (value) {
|
|
|
10
10
|
*
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
class MotionValue {
|
|
14
14
|
/**
|
|
15
15
|
* @param init - The initiating value
|
|
16
16
|
* @param config - Optional configuration options
|
|
@@ -19,13 +19,12 @@ var MotionValue = /** @class */ (function () {
|
|
|
19
19
|
*
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
var _this = this;
|
|
22
|
+
constructor(init) {
|
|
24
23
|
/**
|
|
25
24
|
* This will be replaced by the build step with the latest version number.
|
|
26
25
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
27
26
|
*/
|
|
28
|
-
this.version = "7.
|
|
27
|
+
this.version = "7.1.2";
|
|
29
28
|
/**
|
|
30
29
|
* Duration, in milliseconds, since last updating frame.
|
|
31
30
|
*
|
|
@@ -64,28 +63,27 @@ var MotionValue = /** @class */ (function () {
|
|
|
64
63
|
* @internal
|
|
65
64
|
*/
|
|
66
65
|
this.canTrackVelocity = false;
|
|
67
|
-
this.updateAndNotify =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
_this.current = v;
|
|
66
|
+
this.updateAndNotify = (v, render = true) => {
|
|
67
|
+
this.prev = this.current;
|
|
68
|
+
this.current = v;
|
|
71
69
|
// Update timestamp
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
sync.postRender(
|
|
70
|
+
const { delta, timestamp } = getFrameData();
|
|
71
|
+
if (this.lastUpdated !== timestamp) {
|
|
72
|
+
this.timeDelta = delta;
|
|
73
|
+
this.lastUpdated = timestamp;
|
|
74
|
+
sync.postRender(this.scheduleVelocityCheck);
|
|
77
75
|
}
|
|
78
76
|
// Update update subscribers
|
|
79
|
-
if (
|
|
80
|
-
|
|
77
|
+
if (this.prev !== this.current) {
|
|
78
|
+
this.updateSubscribers.notify(this.current);
|
|
81
79
|
}
|
|
82
80
|
// Update velocity subscribers
|
|
83
|
-
if (
|
|
84
|
-
|
|
81
|
+
if (this.velocityUpdateSubscribers.getSize()) {
|
|
82
|
+
this.velocityUpdateSubscribers.notify(this.getVelocity());
|
|
85
83
|
}
|
|
86
84
|
// Update render subscribers
|
|
87
85
|
if (render) {
|
|
88
|
-
|
|
86
|
+
this.renderSubscribers.notify(this.current);
|
|
89
87
|
}
|
|
90
88
|
};
|
|
91
89
|
/**
|
|
@@ -96,7 +94,7 @@ var MotionValue = /** @class */ (function () {
|
|
|
96
94
|
*
|
|
97
95
|
* @internal
|
|
98
96
|
*/
|
|
99
|
-
this.scheduleVelocityCheck =
|
|
97
|
+
this.scheduleVelocityCheck = () => sync.postRender(this.velocityCheck);
|
|
100
98
|
/**
|
|
101
99
|
* Updates `prev` with `current` if the value hasn't been updated this frame.
|
|
102
100
|
* This ensures velocity calculations return `0`.
|
|
@@ -106,11 +104,10 @@ var MotionValue = /** @class */ (function () {
|
|
|
106
104
|
*
|
|
107
105
|
* @internal
|
|
108
106
|
*/
|
|
109
|
-
this.velocityCheck =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
_this.velocityUpdateSubscribers.notify(_this.getVelocity());
|
|
107
|
+
this.velocityCheck = ({ timestamp }) => {
|
|
108
|
+
if (timestamp !== this.lastUpdated) {
|
|
109
|
+
this.prev = this.current;
|
|
110
|
+
this.velocityUpdateSubscribers.notify(this.getVelocity());
|
|
114
111
|
}
|
|
115
112
|
};
|
|
116
113
|
this.hasAnimated = false;
|
|
@@ -165,12 +162,12 @@ var MotionValue = /** @class */ (function () {
|
|
|
165
162
|
*
|
|
166
163
|
* @public
|
|
167
164
|
*/
|
|
168
|
-
|
|
165
|
+
onChange(subscription) {
|
|
169
166
|
return this.updateSubscribers.add(subscription);
|
|
170
|
-
}
|
|
171
|
-
|
|
167
|
+
}
|
|
168
|
+
clearListeners() {
|
|
172
169
|
this.updateSubscribers.clear();
|
|
173
|
-
}
|
|
170
|
+
}
|
|
174
171
|
/**
|
|
175
172
|
* Adds a function that will be notified when the `MotionValue` requests a render.
|
|
176
173
|
*
|
|
@@ -179,19 +176,19 @@ var MotionValue = /** @class */ (function () {
|
|
|
179
176
|
*
|
|
180
177
|
* @internal
|
|
181
178
|
*/
|
|
182
|
-
|
|
179
|
+
onRenderRequest(subscription) {
|
|
183
180
|
// Render immediately
|
|
184
181
|
subscription(this.get());
|
|
185
182
|
return this.renderSubscribers.add(subscription);
|
|
186
|
-
}
|
|
183
|
+
}
|
|
187
184
|
/**
|
|
188
185
|
* Attaches a passive effect to the `MotionValue`.
|
|
189
186
|
*
|
|
190
187
|
* @internal
|
|
191
188
|
*/
|
|
192
|
-
|
|
189
|
+
attach(passiveEffect) {
|
|
193
190
|
this.passiveEffect = passiveEffect;
|
|
194
|
-
}
|
|
191
|
+
}
|
|
195
192
|
/**
|
|
196
193
|
* Sets the state of the `MotionValue`.
|
|
197
194
|
*
|
|
@@ -207,15 +204,14 @@ var MotionValue = /** @class */ (function () {
|
|
|
207
204
|
*
|
|
208
205
|
* @public
|
|
209
206
|
*/
|
|
210
|
-
|
|
211
|
-
if (render === void 0) { render = true; }
|
|
207
|
+
set(v, render = true) {
|
|
212
208
|
if (!render || !this.passiveEffect) {
|
|
213
209
|
this.updateAndNotify(v, render);
|
|
214
210
|
}
|
|
215
211
|
else {
|
|
216
212
|
this.passiveEffect(v, this.updateAndNotify);
|
|
217
213
|
}
|
|
218
|
-
}
|
|
214
|
+
}
|
|
219
215
|
/**
|
|
220
216
|
* Returns the latest state of `MotionValue`
|
|
221
217
|
*
|
|
@@ -223,15 +219,15 @@ var MotionValue = /** @class */ (function () {
|
|
|
223
219
|
*
|
|
224
220
|
* @public
|
|
225
221
|
*/
|
|
226
|
-
|
|
222
|
+
get() {
|
|
227
223
|
return this.current;
|
|
228
|
-
}
|
|
224
|
+
}
|
|
229
225
|
/**
|
|
230
226
|
* @public
|
|
231
227
|
*/
|
|
232
|
-
|
|
228
|
+
getPrevious() {
|
|
233
229
|
return this.prev;
|
|
234
|
-
}
|
|
230
|
+
}
|
|
235
231
|
/**
|
|
236
232
|
* Returns the latest velocity of `MotionValue`
|
|
237
233
|
*
|
|
@@ -239,14 +235,14 @@ var MotionValue = /** @class */ (function () {
|
|
|
239
235
|
*
|
|
240
236
|
* @public
|
|
241
237
|
*/
|
|
242
|
-
|
|
238
|
+
getVelocity() {
|
|
243
239
|
// This could be isFloat(this.prev) && isFloat(this.current), but that would be wasteful
|
|
244
240
|
return this.canTrackVelocity
|
|
245
241
|
? // These casts could be avoided if parseFloat would be typed better
|
|
246
242
|
velocityPerSecond(parseFloat(this.current) -
|
|
247
243
|
parseFloat(this.prev), this.timeDelta)
|
|
248
244
|
: 0;
|
|
249
|
-
}
|
|
245
|
+
}
|
|
250
246
|
/**
|
|
251
247
|
* Registers a new animation to control this `MotionValue`. Only one
|
|
252
248
|
* animation can drive a `MotionValue` at one time.
|
|
@@ -259,35 +255,34 @@ var MotionValue = /** @class */ (function () {
|
|
|
259
255
|
*
|
|
260
256
|
* @internal
|
|
261
257
|
*/
|
|
262
|
-
|
|
263
|
-
var _this = this;
|
|
258
|
+
start(animation) {
|
|
264
259
|
this.stop();
|
|
265
|
-
return new Promise(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}).then(
|
|
269
|
-
}
|
|
260
|
+
return new Promise((resolve) => {
|
|
261
|
+
this.hasAnimated = true;
|
|
262
|
+
this.stopAnimation = animation(resolve);
|
|
263
|
+
}).then(() => this.clearAnimation());
|
|
264
|
+
}
|
|
270
265
|
/**
|
|
271
266
|
* Stop the currently active animation.
|
|
272
267
|
*
|
|
273
268
|
* @public
|
|
274
269
|
*/
|
|
275
|
-
|
|
270
|
+
stop() {
|
|
276
271
|
if (this.stopAnimation)
|
|
277
272
|
this.stopAnimation();
|
|
278
273
|
this.clearAnimation();
|
|
279
|
-
}
|
|
274
|
+
}
|
|
280
275
|
/**
|
|
281
276
|
* Returns `true` if this value is currently animating.
|
|
282
277
|
*
|
|
283
278
|
* @public
|
|
284
279
|
*/
|
|
285
|
-
|
|
280
|
+
isAnimating() {
|
|
286
281
|
return !!this.stopAnimation;
|
|
287
|
-
}
|
|
288
|
-
|
|
282
|
+
}
|
|
283
|
+
clearAnimation() {
|
|
289
284
|
this.stopAnimation = null;
|
|
290
|
-
}
|
|
285
|
+
}
|
|
291
286
|
/**
|
|
292
287
|
* Destroy and clean up subscribers to this `MotionValue`.
|
|
293
288
|
*
|
|
@@ -297,13 +292,12 @@ var MotionValue = /** @class */ (function () {
|
|
|
297
292
|
*
|
|
298
293
|
* @public
|
|
299
294
|
*/
|
|
300
|
-
|
|
295
|
+
destroy() {
|
|
301
296
|
this.updateSubscribers.clear();
|
|
302
297
|
this.renderSubscribers.clear();
|
|
303
298
|
this.stop();
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
}());
|
|
299
|
+
}
|
|
300
|
+
}
|
|
307
301
|
function motionValue(init) {
|
|
308
302
|
return new MotionValue(init);
|
|
309
303
|
}
|
|
@@ -6,14 +6,14 @@ function useCombineMotionValues(values, combineValues) {
|
|
|
6
6
|
/**
|
|
7
7
|
* Initialise the returned motion value. This remains the same between renders.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
const value = useMotionValue(combineValues());
|
|
10
10
|
/**
|
|
11
11
|
* Create a function that will update the template motion value with the latest values.
|
|
12
12
|
* This is pre-bound so whenever a motion value updates it can schedule its
|
|
13
13
|
* execution in Framesync. If it's already been scheduled it won't be fired twice
|
|
14
14
|
* in a single frame.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
const updateValue = () => value.set(combineValues());
|
|
17
17
|
/**
|
|
18
18
|
* Synchronously update the motion value with the latest values during the render.
|
|
19
19
|
* This ensures that within a React render, the styles applied to the DOM are up-to-date.
|
|
@@ -23,7 +23,7 @@ function useCombineMotionValues(values, combineValues) {
|
|
|
23
23
|
* Subscribe to all motion values found within the template. Whenever any of them change,
|
|
24
24
|
* schedule an update.
|
|
25
25
|
*/
|
|
26
|
-
useMultiOnChange(values,
|
|
26
|
+
useMultiOnChange(values, () => sync.update(updateValue, false, true));
|
|
27
27
|
return value;
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -6,11 +6,9 @@ import { useVisualElementContext } from '../context/MotionContext/index.mjs';
|
|
|
6
6
|
// Keep things reasonable and avoid scale: Infinity. In practise we might need
|
|
7
7
|
// to add another value, opacity, that could interpolate scaleX/Y [0,0.01] => [0,1]
|
|
8
8
|
// to simply hide content at unreasonable scales.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
var hasWarned = false;
|
|
9
|
+
const maxScale = 100000;
|
|
10
|
+
const invertScale = (scale) => scale > 0.001 ? 1 / scale : maxScale;
|
|
11
|
+
let hasWarned = false;
|
|
14
12
|
/**
|
|
15
13
|
* Returns a `MotionValue` each for `scaleX` and `scaleY` that update with the inverse
|
|
16
14
|
* of their respective parent scales.
|
|
@@ -31,9 +29,9 @@ var hasWarned = false;
|
|
|
31
29
|
* @deprecated
|
|
32
30
|
*/
|
|
33
31
|
function useInvertedScale(scale) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
let parentScaleX = useMotionValue(1);
|
|
33
|
+
let parentScaleY = useMotionValue(1);
|
|
34
|
+
const visualElement = useVisualElementContext();
|
|
37
35
|
invariant(!!(scale || visualElement), "If no scale values are provided, useInvertedScale must be used within a child of another motion component.");
|
|
38
36
|
warning(hasWarned, "useInvertedScale is deprecated and will be removed in 3.0. Use the layout prop instead.");
|
|
39
37
|
hasWarned = true;
|
|
@@ -45,9 +43,9 @@ function useInvertedScale(scale) {
|
|
|
45
43
|
parentScaleX = visualElement.getValue("scaleX", 1);
|
|
46
44
|
parentScaleY = visualElement.getValue("scaleY", 1);
|
|
47
45
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return { scaleX
|
|
46
|
+
const scaleX = useTransform(parentScaleX, invertScale);
|
|
47
|
+
const scaleY = useTransform(parentScaleY, invertScale);
|
|
48
|
+
return { scaleX, scaleY };
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
export { invertScale, useInvertedScale };
|
|
@@ -22,20 +22,16 @@ import { useCombineMotionValues } from './use-combine-values.mjs';
|
|
|
22
22
|
*
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
|
-
function useMotionTemplate(fragments) {
|
|
26
|
-
var values = [];
|
|
27
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
28
|
-
values[_i - 1] = arguments[_i];
|
|
29
|
-
}
|
|
25
|
+
function useMotionTemplate(fragments, ...values) {
|
|
30
26
|
/**
|
|
31
27
|
* Create a function that will build a string from the latest motion values.
|
|
32
28
|
*/
|
|
33
|
-
|
|
29
|
+
const numFragments = fragments.length;
|
|
34
30
|
function buildValue() {
|
|
35
|
-
|
|
36
|
-
for (
|
|
31
|
+
let output = ``;
|
|
32
|
+
for (let i = 0; i < numFragments; i++) {
|
|
37
33
|
output += fragments[i];
|
|
38
|
-
|
|
34
|
+
const value = values[i];
|
|
39
35
|
if (value)
|
|
40
36
|
output += values[i].get();
|
|
41
37
|
}
|