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 { useState, useEffect } from 'react';
|
|
3
2
|
import { useConstant } from '../utils/use-constant.mjs';
|
|
4
3
|
import { getOrigin, checkTargetForNewValues } from '../render/utils/setters.mjs';
|
|
@@ -19,11 +18,10 @@ const stateVisualElement = visualElement({
|
|
|
19
18
|
readValueFromInstance(_state, key, options) {
|
|
20
19
|
return options.initialState[key] || 0;
|
|
21
20
|
},
|
|
22
|
-
makeTargetAnimatable(element,
|
|
23
|
-
var { transition, transitionEnd } = _a, target = __rest(_a, ["transition", "transitionEnd"]);
|
|
21
|
+
makeTargetAnimatable(element, { transition, transitionEnd, ...target }) {
|
|
24
22
|
const origin = getOrigin(target, transition || {}, element);
|
|
25
23
|
checkTargetForNewValues(element, target, origin);
|
|
26
|
-
return
|
|
24
|
+
return { transition, transitionEnd, ...target };
|
|
27
25
|
},
|
|
28
26
|
});
|
|
29
27
|
const useVisualState = makeUseVisualState({
|
|
@@ -45,7 +43,7 @@ function useAnimatedState(initialState) {
|
|
|
45
43
|
useEffect(() => {
|
|
46
44
|
element.setProps({
|
|
47
45
|
onUpdate: (v) => {
|
|
48
|
-
setAnimationState(
|
|
46
|
+
setAnimationState({ ...v });
|
|
49
47
|
},
|
|
50
48
|
});
|
|
51
49
|
}, [setAnimationState, element]);
|
|
@@ -47,7 +47,7 @@ const getDefaultTransition = (valueKey, to) => {
|
|
|
47
47
|
transitionFactory =
|
|
48
48
|
defaultTransitions[valueKey] || defaultTransitions.default;
|
|
49
49
|
}
|
|
50
|
-
return
|
|
50
|
+
return { to, ...transitionFactory(to) };
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
export { criticallyDampedSpring, getDefaultTransition, linearTween, underDampedSpring };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import { inertia, animate } from 'popmotion';
|
|
3
2
|
import { secondsToMilliseconds } from '../../utils/time-conversion.mjs';
|
|
4
3
|
import { isEasingArray, easingDefinitionToFunction } from './easing.mjs';
|
|
@@ -14,17 +13,15 @@ import { resolveFinalValueInKeyframes } from '../../utils/resolve-value.mjs';
|
|
|
14
13
|
* This filters out orchestration options and returns true
|
|
15
14
|
* if any options are left.
|
|
16
15
|
*/
|
|
17
|
-
function isTransitionDefined(
|
|
18
|
-
var transition = __rest(_a, ["when", "delay", "delayChildren", "staggerChildren", "staggerDirection", "repeat", "repeatType", "repeatDelay", "from"]);
|
|
16
|
+
function isTransitionDefined({ when, delay, delayChildren, staggerChildren, staggerDirection, repeat, repeatType, repeatDelay, from, ...transition }) {
|
|
19
17
|
return !!Object.keys(transition).length;
|
|
20
18
|
}
|
|
21
19
|
let legacyRepeatWarning = false;
|
|
22
20
|
/**
|
|
23
21
|
* Convert Framer Motion's Transition type into Popmotion-compatible options.
|
|
24
22
|
*/
|
|
25
|
-
function convertTransitionToAnimationOptions(
|
|
26
|
-
|
|
27
|
-
const options = Object.assign({}, transition);
|
|
23
|
+
function convertTransitionToAnimationOptions({ ease, times, yoyo, flip, loop, ...transition }) {
|
|
24
|
+
const options = { ...transition };
|
|
28
25
|
if (times)
|
|
29
26
|
options["offset"] = times;
|
|
30
27
|
/**
|
|
@@ -89,26 +86,30 @@ function hydrateKeyframes(options) {
|
|
|
89
86
|
return options;
|
|
90
87
|
}
|
|
91
88
|
function getPopmotionAnimationOptions(transition, options, key) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
(_a = transition.duration) !== null && _a !== void 0 ? _a : (transition.duration = 0.8);
|
|
89
|
+
if (Array.isArray(options.to) && transition.duration === undefined) {
|
|
90
|
+
transition.duration = 0.8;
|
|
95
91
|
}
|
|
96
92
|
hydrateKeyframes(options);
|
|
97
93
|
/**
|
|
98
94
|
* Get a default transition if none is determined to be defined.
|
|
99
95
|
*/
|
|
100
96
|
if (!isTransitionDefined(transition)) {
|
|
101
|
-
transition =
|
|
97
|
+
transition = {
|
|
98
|
+
...transition,
|
|
99
|
+
...getDefaultTransition(key, options.to),
|
|
100
|
+
};
|
|
102
101
|
}
|
|
103
|
-
return
|
|
102
|
+
return {
|
|
103
|
+
...options,
|
|
104
|
+
...convertTransitionToAnimationOptions(transition),
|
|
105
|
+
};
|
|
104
106
|
}
|
|
105
107
|
/**
|
|
106
108
|
*
|
|
107
109
|
*/
|
|
108
110
|
function getAnimation(key, value, target, transition, onComplete) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
let origin = (_a = valueTransition.from) !== null && _a !== void 0 ? _a : value.get();
|
|
111
|
+
const valueTransition = getValueTransition(transition, key) || {};
|
|
112
|
+
let origin = valueTransition.from !== undefined ? valueTransition.from : value.get();
|
|
112
113
|
const isTargetAnimatable = isAnimatable(key, target);
|
|
113
114
|
if (origin === "none" && isTargetAnimatable && typeof target === "string") {
|
|
114
115
|
/**
|
|
@@ -137,24 +138,25 @@ function getAnimation(key, value, target, transition, onComplete) {
|
|
|
137
138
|
};
|
|
138
139
|
return valueTransition.type === "inertia" ||
|
|
139
140
|
valueTransition.type === "decay"
|
|
140
|
-
? inertia(
|
|
141
|
-
: animate(
|
|
142
|
-
|
|
141
|
+
? inertia({ ...options, ...valueTransition })
|
|
142
|
+
: animate({
|
|
143
|
+
...getPopmotionAnimationOptions(valueTransition, options, key),
|
|
144
|
+
onUpdate: (v) => {
|
|
143
145
|
options.onUpdate(v);
|
|
144
|
-
|
|
145
|
-
},
|
|
146
|
-
|
|
146
|
+
valueTransition.onUpdate && valueTransition.onUpdate(v);
|
|
147
|
+
},
|
|
148
|
+
onComplete: () => {
|
|
147
149
|
options.onComplete();
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
+
valueTransition.onComplete && valueTransition.onComplete();
|
|
151
|
+
},
|
|
152
|
+
});
|
|
150
153
|
}
|
|
151
154
|
function set() {
|
|
152
|
-
var _a, _b;
|
|
153
155
|
const finalTarget = resolveFinalValueInKeyframes(target);
|
|
154
156
|
value.set(finalTarget);
|
|
155
157
|
onComplete();
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
valueTransition.onUpdate && valueTransition.onUpdate(finalTarget);
|
|
159
|
+
valueTransition.onComplete && valueTransition.onComplete();
|
|
158
160
|
return { stop: () => { } };
|
|
159
161
|
}
|
|
160
162
|
return !isOriginAnimatable ||
|
|
@@ -199,7 +201,7 @@ function startAnimation(key, value, target, transition = {}) {
|
|
|
199
201
|
}
|
|
200
202
|
return () => {
|
|
201
203
|
clearTimeout(delayTimer);
|
|
202
|
-
controls
|
|
204
|
+
controls && controls.stop();
|
|
203
205
|
};
|
|
204
206
|
});
|
|
205
207
|
}
|
|
@@ -44,14 +44,14 @@ function PopChild({ children, isPresent }) {
|
|
|
44
44
|
* styles set via the style prop.
|
|
45
45
|
*/
|
|
46
46
|
useInsertionEffect(() => {
|
|
47
|
-
var _a;
|
|
48
47
|
const { width, height, top, left } = size.current;
|
|
49
48
|
if (isPresent || !ref.current || !width || !height)
|
|
50
49
|
return;
|
|
51
50
|
ref.current.dataset.motionPopId = id;
|
|
52
51
|
const style = document.createElement("style");
|
|
53
52
|
document.head.appendChild(style);
|
|
54
|
-
(
|
|
53
|
+
if (style.sheet) {
|
|
54
|
+
style.sheet.insertRule(`
|
|
55
55
|
[data-motion-pop-id="${id}"] {
|
|
56
56
|
position: absolute !important;
|
|
57
57
|
width: ${width}px !important;
|
|
@@ -60,6 +60,7 @@ function PopChild({ children, isPresent }) {
|
|
|
60
60
|
left: ${left}px !important;
|
|
61
61
|
}
|
|
62
62
|
`);
|
|
63
|
+
}
|
|
63
64
|
return () => {
|
|
64
65
|
document.head.removeChild(style);
|
|
65
66
|
};
|
|
@@ -18,7 +18,7 @@ const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, p
|
|
|
18
18
|
if (!isComplete)
|
|
19
19
|
return; // can stop searching when any is incomplete
|
|
20
20
|
}
|
|
21
|
-
onExitComplete
|
|
21
|
+
onExitComplete && onExitComplete();
|
|
22
22
|
},
|
|
23
23
|
register: (childId) => {
|
|
24
24
|
presenceChildren.set(childId, false);
|
|
@@ -39,7 +39,10 @@ const PresenceChild = ({ children, initial, isPresent, onExitComplete, custom, p
|
|
|
39
39
|
* component immediately.
|
|
40
40
|
*/
|
|
41
41
|
React.useEffect(() => {
|
|
42
|
-
!isPresent &&
|
|
42
|
+
!isPresent &&
|
|
43
|
+
!presenceChildren.size &&
|
|
44
|
+
onExitComplete &&
|
|
45
|
+
onExitComplete();
|
|
43
46
|
}, [isPresent]);
|
|
44
47
|
if (mode === "popLayout") {
|
|
45
48
|
children = React.createElement(PopChild, { isPresent: isPresent }, children);
|
|
@@ -34,7 +34,7 @@ function usePresence() {
|
|
|
34
34
|
// Replace with useId when released in React
|
|
35
35
|
const id = useId();
|
|
36
36
|
useEffect(() => register(id), []);
|
|
37
|
-
const safeToRemove = () => onExitComplete
|
|
37
|
+
const safeToRemove = () => onExitComplete && onExitComplete(id);
|
|
38
38
|
return !isPresent && onExitComplete ? [false, safeToRemove] : [true];
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
@@ -7,8 +7,7 @@ import { nodeGroup } from '../../projection/node/group.mjs';
|
|
|
7
7
|
|
|
8
8
|
const shouldInheritGroup = (inherit) => inherit === true;
|
|
9
9
|
const shouldInheritId = (inherit) => shouldInheritGroup(inherit === true) || inherit === "id";
|
|
10
|
-
const LayoutGroup = ({ children, id, inheritId, inherit = true
|
|
11
|
-
var _a, _b;
|
|
10
|
+
const LayoutGroup = ({ children, id, inheritId, inherit = true }) => {
|
|
12
11
|
// Maintain backwards-compatibility with inheritId until 7.0
|
|
13
12
|
if (inheritId !== undefined)
|
|
14
13
|
inherit = inheritId;
|
|
@@ -16,7 +15,7 @@ const LayoutGroup = ({ children, id, inheritId, inherit = true, }) => {
|
|
|
16
15
|
const deprecatedLayoutGroupContext = useContext(DeprecatedLayoutGroupContext);
|
|
17
16
|
const [forceRender, key] = useForceUpdate();
|
|
18
17
|
const context = useRef(null);
|
|
19
|
-
const upstreamId =
|
|
18
|
+
const upstreamId = layoutGroupContext.id || deprecatedLayoutGroupContext;
|
|
20
19
|
if (context.current === null) {
|
|
21
20
|
if (shouldInheritId(inherit) && upstreamId) {
|
|
22
21
|
id = id ? upstreamId + "-" + id : upstreamId;
|
|
@@ -24,11 +23,11 @@ const LayoutGroup = ({ children, id, inheritId, inherit = true, }) => {
|
|
|
24
23
|
context.current = {
|
|
25
24
|
id,
|
|
26
25
|
group: shouldInheritGroup(inherit)
|
|
27
|
-
?
|
|
26
|
+
? layoutGroupContext.group || nodeGroup()
|
|
28
27
|
: nodeGroup(),
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
|
-
const memoizedContext = useMemo(() => (
|
|
30
|
+
const memoizedContext = useMemo(() => ({ ...context.current, forceRender }), [key]);
|
|
32
31
|
return (React.createElement(LayoutGroupContext.Provider, { value: memoizedContext }, children));
|
|
33
32
|
};
|
|
34
33
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useState, useRef, useEffect } from 'react';
|
|
4
3
|
import { LazyContext } from '../../context/LazyContext.mjs';
|
|
5
|
-
import { loadFeatures } from '../../motion/features/
|
|
4
|
+
import { loadFeatures } from '../../motion/features/load-features.mjs';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Used in conjunction with the `m` component to reduce bundle size.
|
|
@@ -46,14 +45,13 @@ function LazyMotion({ children, features, strict = false }) {
|
|
|
46
45
|
* If this is a synchronous load, load features immediately
|
|
47
46
|
*/
|
|
48
47
|
if (!isLazyBundle(features)) {
|
|
49
|
-
const { renderer
|
|
48
|
+
const { renderer, ...loadedFeatures } = features;
|
|
50
49
|
loadedRenderer.current = renderer;
|
|
51
50
|
loadFeatures(loadedFeatures);
|
|
52
51
|
}
|
|
53
52
|
useEffect(() => {
|
|
54
53
|
if (isLazyBundle(features)) {
|
|
55
|
-
features().then((
|
|
56
|
-
var { renderer } = _a, loadedFeatures = __rest(_a, ["renderer"]);
|
|
54
|
+
features().then(({ renderer, ...loadedFeatures }) => {
|
|
57
55
|
loadFeatures(loadedFeatures);
|
|
58
56
|
loadedRenderer.current = renderer;
|
|
59
57
|
setIsLoaded(true);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useContext, useMemo } from 'react';
|
|
4
3
|
import { MotionConfigContext } from '../../context/MotionConfigContext.mjs';
|
|
@@ -22,13 +21,12 @@ import { useConstant } from '../../utils/use-constant.mjs';
|
|
|
22
21
|
*
|
|
23
22
|
* @public
|
|
24
23
|
*/
|
|
25
|
-
function MotionConfig(
|
|
26
|
-
var { children, isValidProp } = _a, config = __rest(_a, ["children", "isValidProp"]);
|
|
24
|
+
function MotionConfig({ children, isValidProp, ...config }) {
|
|
27
25
|
isValidProp && loadExternalIsValidProp(isValidProp);
|
|
28
26
|
/**
|
|
29
27
|
* Inherit props from any parent MotionConfig components
|
|
30
28
|
*/
|
|
31
|
-
config =
|
|
29
|
+
config = { ...useContext(MotionConfigContext), ...config };
|
|
32
30
|
/**
|
|
33
31
|
* Don't allow isStatic to change between renders as it affects how many hooks
|
|
34
32
|
* motion components fire.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import { invariant } from 'hey-listen';
|
|
3
2
|
import * as React from 'react';
|
|
4
3
|
import { forwardRef, useRef, useEffect } from 'react';
|
|
@@ -7,8 +6,7 @@ import { motion } from '../../render/dom/motion.mjs';
|
|
|
7
6
|
import { useConstant } from '../../utils/use-constant.mjs';
|
|
8
7
|
import { checkReorder } from './utils/check-reorder.mjs';
|
|
9
8
|
|
|
10
|
-
function ReorderGroup(
|
|
11
|
-
var { children, as = "ul", axis = "y", onReorder, values } = _a, props = __rest(_a, ["children", "as", "axis", "onReorder", "values"]);
|
|
9
|
+
function ReorderGroup({ children, as = "ul", axis = "y", onReorder, values, ...props }, externalRef) {
|
|
12
10
|
const Component = useConstant(() => motion(as));
|
|
13
11
|
const order = [];
|
|
14
12
|
const isReordering = useRef(false);
|
|
@@ -40,7 +38,7 @@ function ReorderGroup(_a, externalRef) {
|
|
|
40
38
|
useEffect(() => {
|
|
41
39
|
isReordering.current = false;
|
|
42
40
|
});
|
|
43
|
-
return (React.createElement(Component,
|
|
41
|
+
return (React.createElement(Component, { ...props, ref: externalRef },
|
|
44
42
|
React.createElement(ReorderContext.Provider, { value: context }, children)));
|
|
45
43
|
}
|
|
46
44
|
const Group = forwardRef(ReorderGroup);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __rest } from 'tslib';
|
|
2
1
|
import { invariant } from 'hey-listen';
|
|
3
2
|
import * as React from 'react';
|
|
4
3
|
import { forwardRef, useContext, useRef, useEffect } from 'react';
|
|
@@ -12,13 +11,12 @@ import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
|
|
|
12
11
|
function useDefaultMotionValue(value, defaultValue = 0) {
|
|
13
12
|
return isMotionValue(value) ? value : useMotionValue(defaultValue);
|
|
14
13
|
}
|
|
15
|
-
function ReorderItem(
|
|
16
|
-
var { children, style, value, as = "li", onDrag, layout = true } = _a, props = __rest(_a, ["children", "style", "value", "as", "onDrag", "layout"]);
|
|
14
|
+
function ReorderItem({ children, style = {}, value, as = "li", onDrag, layout = true, ...props }, externalRef) {
|
|
17
15
|
const Component = useConstant(() => motion(as));
|
|
18
16
|
const context = useContext(ReorderContext);
|
|
19
17
|
const point = {
|
|
20
|
-
x: useDefaultMotionValue(style
|
|
21
|
-
y: useDefaultMotionValue(style
|
|
18
|
+
x: useDefaultMotionValue(style.x),
|
|
19
|
+
y: useDefaultMotionValue(style.y),
|
|
22
20
|
};
|
|
23
21
|
const zIndex = useTransform([point.x, point.y], ([latestX, latestY]) => latestX || latestY ? 1 : "unset");
|
|
24
22
|
const measuredLayout = useRef(null);
|
|
@@ -27,14 +25,14 @@ function ReorderItem(_a, externalRef) {
|
|
|
27
25
|
useEffect(() => {
|
|
28
26
|
registerItem(value, measuredLayout.current);
|
|
29
27
|
}, [context]);
|
|
30
|
-
return (React.createElement(Component,
|
|
28
|
+
return (React.createElement(Component, { drag: axis, ...props, dragSnapToOrigin: true, style: { ...style, x: point.x, y: point.y, zIndex }, layout: layout, onDrag: (event, gesturePoint) => {
|
|
31
29
|
const { velocity } = gesturePoint;
|
|
32
30
|
velocity[axis] &&
|
|
33
31
|
updateOrder(value, point[axis].get(), velocity[axis]);
|
|
34
|
-
onDrag
|
|
32
|
+
onDrag && onDrag(event, gesturePoint);
|
|
35
33
|
}, onLayoutMeasure: (measured) => {
|
|
36
34
|
measuredLayout.current = measured;
|
|
37
|
-
}, ref: externalRef }
|
|
35
|
+
}, ref: externalRef }, children));
|
|
38
36
|
}
|
|
39
37
|
const Item = forwardRef(ReorderItem);
|
|
40
38
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isVariantLabel } from '../../render/utils/is-variant-label.mjs';
|
|
2
|
+
import { isControllingVariants } from '../../render/utils/is-controlling-variants.mjs';
|
|
2
3
|
|
|
3
4
|
function getCurrentTreeVariants(props, context) {
|
|
4
|
-
if (
|
|
5
|
+
if (isControllingVariants(props)) {
|
|
5
6
|
const { initial, animate } = props;
|
|
6
7
|
return {
|
|
7
8
|
initial: initial === false || isVariantLabel(initial)
|
|
@@ -39,7 +39,7 @@ class PanSession {
|
|
|
39
39
|
return;
|
|
40
40
|
const { point } = info;
|
|
41
41
|
const { timestamp } = getFrameData();
|
|
42
|
-
this.history.push(
|
|
42
|
+
this.history.push({ ...point, timestamp });
|
|
43
43
|
const { onStart, onMove } = this.handlers;
|
|
44
44
|
if (!isPanStarted) {
|
|
45
45
|
onStart && onStart(this.lastMoveEvent, info);
|
|
@@ -76,7 +76,7 @@ class PanSession {
|
|
|
76
76
|
const initialInfo = transformPoint(info, this.transformPagePoint);
|
|
77
77
|
const { point } = initialInfo;
|
|
78
78
|
const { timestamp } = getFrameData();
|
|
79
|
-
this.history = [
|
|
79
|
+
this.history = [{ ...point, timestamp }];
|
|
80
80
|
const { onSessionStart } = handlers;
|
|
81
81
|
onSessionStart &&
|
|
82
82
|
onSessionStart(event, getPanInfo(initialInfo, this.history));
|
|
@@ -251,8 +251,17 @@ class VisualElementDragControls {
|
|
|
251
251
|
*/
|
|
252
252
|
const bounceStiffness = dragElastic ? 200 : 1000000;
|
|
253
253
|
const bounceDamping = dragElastic ? 40 : 10000000;
|
|
254
|
-
const inertia =
|
|
255
|
-
|
|
254
|
+
const inertia = {
|
|
255
|
+
type: "inertia",
|
|
256
|
+
velocity: dragMomentum ? velocity[axis] : 0,
|
|
257
|
+
bounceStiffness,
|
|
258
|
+
bounceDamping,
|
|
259
|
+
timeConstant: 750,
|
|
260
|
+
restDelta: 1,
|
|
261
|
+
restSpeed: 10,
|
|
262
|
+
...dragTransition,
|
|
263
|
+
...transition,
|
|
264
|
+
};
|
|
256
265
|
// If we're not animating on an externally-provided `MotionValue` we can use the
|
|
257
266
|
// component's animation controls which will handle interactions with whileHover (etc),
|
|
258
267
|
// otherwise we just have to animate the `MotionValue` itself.
|
|
@@ -404,12 +413,15 @@ class VisualElementDragControls {
|
|
|
404
413
|
getProps() {
|
|
405
414
|
const props = this.visualElement.getProps();
|
|
406
415
|
const { drag = false, dragDirectionLock = false, dragPropagation = false, dragConstraints = false, dragElastic = defaultElastic, dragMomentum = true, } = props;
|
|
407
|
-
return
|
|
416
|
+
return {
|
|
417
|
+
...props,
|
|
418
|
+
drag,
|
|
408
419
|
dragDirectionLock,
|
|
409
420
|
dragPropagation,
|
|
410
421
|
dragConstraints,
|
|
411
422
|
dragElastic,
|
|
412
|
-
dragMomentum
|
|
423
|
+
dragMomentum,
|
|
424
|
+
};
|
|
413
425
|
}
|
|
414
426
|
}
|
|
415
427
|
function shouldDrag(direction, drag, currentDirection) {
|
|
@@ -8,13 +8,12 @@ import { useDomEvent } from '../events/use-dom-event.mjs';
|
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
10
|
function useFocusGesture({ whileFocus, visualElement }) {
|
|
11
|
+
const { animationState } = visualElement;
|
|
11
12
|
const onFocus = () => {
|
|
12
|
-
|
|
13
|
-
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Focus, true);
|
|
13
|
+
animationState && animationState.setActive(AnimationType.Focus, true);
|
|
14
14
|
};
|
|
15
15
|
const onBlur = () => {
|
|
16
|
-
|
|
17
|
-
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Focus, false);
|
|
16
|
+
animationState && animationState.setActive(AnimationType.Focus, false);
|
|
18
17
|
};
|
|
19
18
|
useDomEvent(visualElement, "focus", whileFocus ? onFocus : undefined);
|
|
20
19
|
useDomEvent(visualElement, "blur", whileFocus ? onBlur : undefined);
|
|
@@ -5,14 +5,15 @@ import { isDragActive } from './drag/utils/lock.mjs';
|
|
|
5
5
|
|
|
6
6
|
function createHoverEvent(visualElement, isActive, callback) {
|
|
7
7
|
return (event, info) => {
|
|
8
|
-
var _a;
|
|
9
8
|
if (!isMouseEvent(event) || isDragActive())
|
|
10
9
|
return;
|
|
11
10
|
/**
|
|
12
11
|
* Ensure we trigger animations before firing event callback
|
|
13
12
|
*/
|
|
14
|
-
(
|
|
15
|
-
|
|
13
|
+
if (visualElement.animationState) {
|
|
14
|
+
visualElement.animationState.setActive(AnimationType.Hover, isActive);
|
|
15
|
+
}
|
|
16
|
+
callback && callback(event, info);
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
19
|
function useHoverGesture({ onHoverStart, onHoverEnd, whileHover, visualElement, }) {
|
|
@@ -21,15 +21,14 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
|
|
|
21
21
|
passive: !(onTapStart || onTap || onTapCancel || onPointerDown),
|
|
22
22
|
};
|
|
23
23
|
function removePointerEndListener() {
|
|
24
|
-
|
|
25
|
-
(_a = cancelPointerEndListeners.current) === null || _a === void 0 ? void 0 : _a.call(cancelPointerEndListeners);
|
|
24
|
+
cancelPointerEndListeners.current && cancelPointerEndListeners.current();
|
|
26
25
|
cancelPointerEndListeners.current = null;
|
|
27
26
|
}
|
|
28
27
|
function checkPointerEnd() {
|
|
29
|
-
var _a;
|
|
30
28
|
removePointerEndListener();
|
|
31
29
|
isPressing.current = false;
|
|
32
|
-
|
|
30
|
+
visualElement.animationState &&
|
|
31
|
+
visualElement.animationState.setActive(AnimationType.Tap, false);
|
|
33
32
|
return !isDragActive();
|
|
34
33
|
}
|
|
35
34
|
function onPointerUp(event, info) {
|
|
@@ -40,16 +39,15 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
|
|
|
40
39
|
* as, or a child of, this component's element
|
|
41
40
|
*/
|
|
42
41
|
!isNodeOrChild(visualElement.getInstance(), event.target)
|
|
43
|
-
? onTapCancel
|
|
44
|
-
: onTap
|
|
42
|
+
? onTapCancel && onTapCancel(event, info)
|
|
43
|
+
: onTap && onTap(event, info);
|
|
45
44
|
}
|
|
46
45
|
function onPointerCancel(event, info) {
|
|
47
46
|
if (!checkPointerEnd())
|
|
48
47
|
return;
|
|
49
|
-
onTapCancel
|
|
48
|
+
onTapCancel && onTapCancel(event, info);
|
|
50
49
|
}
|
|
51
50
|
function onPointerDown(event, info) {
|
|
52
|
-
var _a;
|
|
53
51
|
removePointerEndListener();
|
|
54
52
|
if (isPressing.current)
|
|
55
53
|
return;
|
|
@@ -58,8 +56,9 @@ function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement
|
|
|
58
56
|
/**
|
|
59
57
|
* Ensure we trigger animations before firing event callback
|
|
60
58
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
visualElement.animationState &&
|
|
60
|
+
visualElement.animationState.setActive(AnimationType.Tap, true);
|
|
61
|
+
onTapStart && onTapStart(event, info);
|
|
63
62
|
}
|
|
64
63
|
usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined, eventOptions);
|
|
65
64
|
useUnmountEffect(removePointerEndListener);
|
package/dist/es/index.mjs
CHANGED
|
@@ -20,7 +20,8 @@ export { useElementScroll } from './value/scroll/use-element-scroll.mjs';
|
|
|
20
20
|
export { useViewportScroll } from './value/scroll/use-viewport-scroll.mjs';
|
|
21
21
|
export { useTime } from './value/use-time.mjs';
|
|
22
22
|
export { useWillChange } from './value/use-will-change/index.mjs';
|
|
23
|
-
export { useReducedMotion
|
|
23
|
+
export { useReducedMotion } from './utils/reduced-motion/use-reduced-motion.mjs';
|
|
24
|
+
export { useReducedMotionConfig } from './utils/reduced-motion/use-reduced-motion-config.mjs';
|
|
24
25
|
export { animationControls } from './animation/animation-controls.mjs';
|
|
25
26
|
export { useAnimation, useAnimationControls } from './animation/use-animation.mjs';
|
|
26
27
|
export { useAnimationFrame } from './utils/use-animation-frame.mjs';
|
|
@@ -26,10 +26,15 @@ const animations = {
|
|
|
26
26
|
const [isPresent, safeToRemove] = usePresence();
|
|
27
27
|
const presenceContext = useContext(PresenceContext);
|
|
28
28
|
useEffect(() => {
|
|
29
|
-
var _a, _b;
|
|
30
29
|
visualElement.isPresent = isPresent;
|
|
31
|
-
const animation =
|
|
32
|
-
|
|
30
|
+
const animation = visualElement.animationState &&
|
|
31
|
+
visualElement.animationState.setActive(AnimationType.Exit, !isPresent, {
|
|
32
|
+
custom: (presenceContext && presenceContext.custom) ||
|
|
33
|
+
custom,
|
|
34
|
+
});
|
|
35
|
+
if (animation && !isPresent) {
|
|
36
|
+
animation.then(safeToRemove);
|
|
37
|
+
}
|
|
33
38
|
}, [isPresent]);
|
|
34
39
|
}),
|
|
35
40
|
};
|
|
@@ -30,17 +30,5 @@ const featureDefinitions = {
|
|
|
30
30
|
"onViewportLeave",
|
|
31
31
|
]),
|
|
32
32
|
};
|
|
33
|
-
function loadFeatures(features) {
|
|
34
|
-
for (const key in features) {
|
|
35
|
-
if (features[key] === null)
|
|
36
|
-
continue;
|
|
37
|
-
if (key === "projectionNodeConstructor") {
|
|
38
|
-
featureDefinitions.projectionNodeConstructor = features[key];
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
featureDefinitions[key].Component = features[key];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
33
|
|
|
46
|
-
export { featureDefinitions
|
|
34
|
+
export { featureDefinitions };
|
|
@@ -19,16 +19,19 @@ class MeasureLayoutWithContext extends React__default.Component {
|
|
|
19
19
|
const { projection } = visualElement;
|
|
20
20
|
addScaleCorrector(defaultScaleCorrectors);
|
|
21
21
|
if (projection) {
|
|
22
|
-
if (layoutGroup
|
|
22
|
+
if (layoutGroup.group)
|
|
23
23
|
layoutGroup.group.add(projection);
|
|
24
|
-
if (
|
|
24
|
+
if (switchLayoutGroup && switchLayoutGroup.register && layoutId) {
|
|
25
25
|
switchLayoutGroup.register(projection);
|
|
26
26
|
}
|
|
27
27
|
projection.root.didUpdate();
|
|
28
28
|
projection.addEventListener("animationComplete", () => {
|
|
29
29
|
this.safeToRemove();
|
|
30
30
|
});
|
|
31
|
-
projection.setOptions(
|
|
31
|
+
projection.setOptions({
|
|
32
|
+
...projection.options,
|
|
33
|
+
onExitComplete: () => this.safeToRemove(),
|
|
34
|
+
});
|
|
32
35
|
}
|
|
33
36
|
globalProjectionState.hasEverUpdated = true;
|
|
34
37
|
}
|
|
@@ -104,15 +107,18 @@ class MeasureLayoutWithContext extends React__default.Component {
|
|
|
104
107
|
function MeasureLayout(props) {
|
|
105
108
|
const [isPresent, safeToRemove] = usePresence();
|
|
106
109
|
const layoutGroup = useContext(LayoutGroupContext);
|
|
107
|
-
return (React__default.createElement(MeasureLayoutWithContext,
|
|
110
|
+
return (React__default.createElement(MeasureLayoutWithContext, { ...props, layoutGroup: layoutGroup, switchLayoutGroup: useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove }));
|
|
108
111
|
}
|
|
109
112
|
const defaultScaleCorrectors = {
|
|
110
|
-
borderRadius:
|
|
113
|
+
borderRadius: {
|
|
114
|
+
...correctBorderRadius,
|
|
115
|
+
applyTo: [
|
|
111
116
|
"borderTopLeftRadius",
|
|
112
117
|
"borderTopRightRadius",
|
|
113
118
|
"borderBottomLeftRadius",
|
|
114
119
|
"borderBottomRightRadius",
|
|
115
|
-
]
|
|
120
|
+
],
|
|
121
|
+
},
|
|
116
122
|
borderTopLeftRadius: correctBorderRadius,
|
|
117
123
|
borderTopRightRadius: correctBorderRadius,
|
|
118
124
|
borderBottomLeftRadius: correctBorderRadius,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { featureDefinitions } from './definitions.mjs';
|
|
2
|
+
|
|
3
|
+
function loadFeatures(features) {
|
|
4
|
+
for (const key in features) {
|
|
5
|
+
if (key === "projectionNodeConstructor") {
|
|
6
|
+
featureDefinitions.projectionNodeConstructor = features[key];
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
featureDefinitions[key].Component = features[key];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { loadFeatures };
|