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,4 +1,3 @@
|
|
|
1
|
-
import { __read } from 'tslib';
|
|
2
1
|
import { mix, progress, clamp } from 'popmotion';
|
|
3
2
|
import { calcLength } from '../../../projection/geometry/delta-calc.mjs';
|
|
4
3
|
|
|
@@ -7,8 +6,7 @@ import { calcLength } from '../../../projection/geometry/delta-calc.mjs';
|
|
|
7
6
|
* axis, and an elastic factor that determines how much to constrain the point
|
|
8
7
|
* by if it does lie outside the defined parameters.
|
|
9
8
|
*/
|
|
10
|
-
function applyConstraints(point,
|
|
11
|
-
var min = _a.min, max = _a.max;
|
|
9
|
+
function applyConstraints(point, { min, max }, elastic) {
|
|
12
10
|
if (min !== undefined && point < min) {
|
|
13
11
|
// If we have a min point defined, and this is outside of that, constrain
|
|
14
12
|
point = elastic ? mix(min, point, elastic.min) : Math.max(point, min);
|
|
@@ -36,8 +34,7 @@ function calcRelativeAxisConstraints(axis, min, max) {
|
|
|
36
34
|
* Calculate constraints in terms of the viewport when
|
|
37
35
|
* defined relatively to the measured bounding box.
|
|
38
36
|
*/
|
|
39
|
-
function calcRelativeConstraints(layoutBox,
|
|
40
|
-
var top = _a.top, left = _a.left, bottom = _a.bottom, right = _a.right;
|
|
37
|
+
function calcRelativeConstraints(layoutBox, { top, left, bottom, right }) {
|
|
41
38
|
return {
|
|
42
39
|
x: calcRelativeAxisConstraints(layoutBox.x, left, right),
|
|
43
40
|
y: calcRelativeAxisConstraints(layoutBox.y, top, bottom),
|
|
@@ -47,16 +44,15 @@ function calcRelativeConstraints(layoutBox, _a) {
|
|
|
47
44
|
* Calculate viewport constraints when defined as another viewport-relative axis
|
|
48
45
|
*/
|
|
49
46
|
function calcViewportAxisConstraints(layoutAxis, constraintsAxis) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var max = constraintsAxis.max - layoutAxis.max;
|
|
47
|
+
let min = constraintsAxis.min - layoutAxis.min;
|
|
48
|
+
let max = constraintsAxis.max - layoutAxis.max;
|
|
53
49
|
// If the constraints axis is actually smaller than the layout axis then we can
|
|
54
50
|
// flip the constraints
|
|
55
51
|
if (constraintsAxis.max - constraintsAxis.min <
|
|
56
52
|
layoutAxis.max - layoutAxis.min) {
|
|
57
|
-
|
|
53
|
+
[min, max] = [max, min];
|
|
58
54
|
}
|
|
59
|
-
return { min
|
|
55
|
+
return { min, max };
|
|
60
56
|
}
|
|
61
57
|
/**
|
|
62
58
|
* Calculate viewport constraints when defined as another viewport-relative box
|
|
@@ -72,9 +68,9 @@ function calcViewportConstraints(layoutBox, constraintsBox) {
|
|
|
72
68
|
* in an asthetically pleasing scale/transform needed to project from source to target.
|
|
73
69
|
*/
|
|
74
70
|
function calcOrigin(source, target) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
let origin = 0.5;
|
|
72
|
+
const sourceLength = calcLength(source);
|
|
73
|
+
const targetLength = calcLength(target);
|
|
78
74
|
if (targetLength > sourceLength) {
|
|
79
75
|
origin = progress(target.min, target.max - sourceLength, source.min);
|
|
80
76
|
}
|
|
@@ -87,7 +83,7 @@ function calcOrigin(source, target) {
|
|
|
87
83
|
* Rebase the calculated viewport constraints relative to the layout.min point.
|
|
88
84
|
*/
|
|
89
85
|
function rebaseAxisConstraints(layout, constraints) {
|
|
90
|
-
|
|
86
|
+
const relativeConstraints = {};
|
|
91
87
|
if (constraints.min !== undefined) {
|
|
92
88
|
relativeConstraints.min = constraints.min - layout.min;
|
|
93
89
|
}
|
|
@@ -96,12 +92,11 @@ function rebaseAxisConstraints(layout, constraints) {
|
|
|
96
92
|
}
|
|
97
93
|
return relativeConstraints;
|
|
98
94
|
}
|
|
99
|
-
|
|
95
|
+
const defaultElastic = 0.35;
|
|
100
96
|
/**
|
|
101
97
|
* Accepts a dragElastic prop and returns resolved elastic values for each axis.
|
|
102
98
|
*/
|
|
103
|
-
function resolveDragElastic(dragElastic) {
|
|
104
|
-
if (dragElastic === void 0) { dragElastic = defaultElastic; }
|
|
99
|
+
function resolveDragElastic(dragElastic = defaultElastic) {
|
|
105
100
|
if (dragElastic === false) {
|
|
106
101
|
dragElastic = 0;
|
|
107
102
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function createLock(name) {
|
|
2
|
-
|
|
3
|
-
return
|
|
4
|
-
|
|
2
|
+
let lock = null;
|
|
3
|
+
return () => {
|
|
4
|
+
const openLock = () => {
|
|
5
5
|
lock = null;
|
|
6
6
|
};
|
|
7
7
|
if (lock === null) {
|
|
@@ -11,10 +11,10 @@ function createLock(name) {
|
|
|
11
11
|
return false;
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const globalHorizontalLock = createLock("dragHorizontal");
|
|
15
|
+
const globalVerticalLock = createLock("dragVertical");
|
|
16
16
|
function getGlobalLock(drag) {
|
|
17
|
-
|
|
17
|
+
let lock = false;
|
|
18
18
|
if (drag === "y") {
|
|
19
19
|
lock = globalVerticalLock();
|
|
20
20
|
}
|
|
@@ -22,20 +22,20 @@ function getGlobalLock(drag) {
|
|
|
22
22
|
lock = globalHorizontalLock();
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
lock =
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
const openHorizontal = globalHorizontalLock();
|
|
26
|
+
const openVertical = globalVerticalLock();
|
|
27
|
+
if (openHorizontal && openVertical) {
|
|
28
|
+
lock = () => {
|
|
29
|
+
openHorizontal();
|
|
30
|
+
openVertical();
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
// Release the locks because we don't use them
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
35
|
+
if (openHorizontal)
|
|
36
|
+
openHorizontal();
|
|
37
|
+
if (openVertical)
|
|
38
|
+
openVertical();
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
return lock;
|
|
@@ -43,7 +43,7 @@ function getGlobalLock(drag) {
|
|
|
43
43
|
function isDragActive() {
|
|
44
44
|
// Check the gesture lock - if we get it, it means no drag gesture is active
|
|
45
45
|
// and we can safely fire the tap gesture.
|
|
46
|
-
|
|
46
|
+
const openGestureLock = getGlobalLock(true);
|
|
47
47
|
if (!openGestureLock)
|
|
48
48
|
return true;
|
|
49
49
|
openGestureLock();
|
|
@@ -7,13 +7,12 @@ import { useDomEvent } from '../events/use-dom-event.mjs';
|
|
|
7
7
|
* @param ref
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
function useFocusGesture(
|
|
11
|
-
|
|
12
|
-
var onFocus = function () {
|
|
10
|
+
function useFocusGesture({ whileFocus, visualElement }) {
|
|
11
|
+
const onFocus = () => {
|
|
13
12
|
var _a;
|
|
14
13
|
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Focus, true);
|
|
15
14
|
};
|
|
16
|
-
|
|
15
|
+
const onBlur = () => {
|
|
17
16
|
var _a;
|
|
18
17
|
(_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Focus, false);
|
|
19
18
|
};
|
|
@@ -4,7 +4,7 @@ import { usePointerEvent } from '../events/use-pointer-event.mjs';
|
|
|
4
4
|
import { isDragActive } from './drag/utils/lock.mjs';
|
|
5
5
|
|
|
6
6
|
function createHoverEvent(visualElement, isActive, callback) {
|
|
7
|
-
return
|
|
7
|
+
return (event, info) => {
|
|
8
8
|
var _a;
|
|
9
9
|
if (!isMouseEvent(event) || isDragActive())
|
|
10
10
|
return;
|
|
@@ -15,8 +15,7 @@ function createHoverEvent(visualElement, isActive, callback) {
|
|
|
15
15
|
callback === null || callback === void 0 ? void 0 : callback(event, info);
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
function useHoverGesture(
|
|
19
|
-
var onHoverStart = _a.onHoverStart, onHoverEnd = _a.onHoverEnd, whileHover = _a.whileHover, visualElement = _a.visualElement;
|
|
18
|
+
function useHoverGesture({ onHoverStart, onHoverEnd, whileHover, visualElement, }) {
|
|
20
19
|
usePointerEvent(visualElement, "pointerenter", onHoverStart || whileHover
|
|
21
20
|
? createHoverEvent(visualElement, true, onHoverStart)
|
|
22
21
|
: undefined, { passive: !onHoverStart });
|
|
@@ -16,32 +16,31 @@ import { PanSession } from './PanSession.mjs';
|
|
|
16
16
|
*
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
|
-
function usePanGesture(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var handlers = {
|
|
19
|
+
function usePanGesture({ onPan, onPanStart, onPanEnd, onPanSessionStart, visualElement, }) {
|
|
20
|
+
const hasPanEvents = onPan || onPanStart || onPanEnd || onPanSessionStart;
|
|
21
|
+
const panSession = useRef(null);
|
|
22
|
+
const { transformPagePoint } = useContext(MotionConfigContext);
|
|
23
|
+
const handlers = {
|
|
25
24
|
onSessionStart: onPanSessionStart,
|
|
26
25
|
onStart: onPanStart,
|
|
27
26
|
onMove: onPan,
|
|
28
|
-
onEnd:
|
|
27
|
+
onEnd: (event, info) => {
|
|
29
28
|
panSession.current = null;
|
|
30
29
|
onPanEnd && onPanEnd(event, info);
|
|
31
30
|
},
|
|
32
31
|
};
|
|
33
|
-
useEffect(
|
|
32
|
+
useEffect(() => {
|
|
34
33
|
if (panSession.current !== null) {
|
|
35
34
|
panSession.current.updateHandlers(handlers);
|
|
36
35
|
}
|
|
37
36
|
});
|
|
38
37
|
function onPointerDown(event) {
|
|
39
38
|
panSession.current = new PanSession(event, handlers, {
|
|
40
|
-
transformPagePoint
|
|
39
|
+
transformPagePoint,
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
42
|
usePointerEvent(visualElement, "pointerdown", hasPanEvents && onPointerDown);
|
|
44
|
-
useUnmountEffect(
|
|
43
|
+
useUnmountEffect(() => panSession.current && panSession.current.end());
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
export { usePanGesture };
|
|
@@ -10,15 +10,14 @@ import { isDragActive } from './drag/utils/lock.mjs';
|
|
|
10
10
|
* @param handlers -
|
|
11
11
|
* @internal
|
|
12
12
|
*/
|
|
13
|
-
function useTapGesture(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var cancelPointerEndListeners = useRef(null);
|
|
13
|
+
function useTapGesture({ onTap, onTapStart, onTapCancel, whileTap, visualElement, }) {
|
|
14
|
+
const hasPressListeners = onTap || onTapStart || onTapCancel || whileTap;
|
|
15
|
+
const isPressing = useRef(false);
|
|
16
|
+
const cancelPointerEndListeners = useRef(null);
|
|
18
17
|
/**
|
|
19
18
|
* Only set listener to passive if there are no external listeners.
|
|
20
19
|
*/
|
|
21
|
-
|
|
20
|
+
const eventOptions = {
|
|
22
21
|
passive: !(onTapStart || onTap || onTapCancel || onPointerDown),
|
|
23
22
|
};
|
|
24
23
|
function removePointerEndListener() {
|
package/dist/es/index.mjs
CHANGED
|
@@ -19,6 +19,7 @@ export { useScroll } from './value/use-scroll.mjs';
|
|
|
19
19
|
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
|
+
export { useWillChange } from './value/use-will-change/index.mjs';
|
|
22
23
|
export { useReducedMotion, useReducedMotionConfig } from './utils/use-reduced-motion.mjs';
|
|
23
24
|
export { animationControls } from './animation/animation-controls.mjs';
|
|
24
25
|
export { useAnimation, useAnimationControls } from './animation/use-animation.mjs';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __read } from 'tslib';
|
|
2
1
|
import { useEffect, useContext } from 'react';
|
|
3
2
|
import { isAnimationControls } from '../../animation/utils/is-animation-controls.mjs';
|
|
4
3
|
import { usePresence } from '../../components/AnimatePresence/use-presence.mjs';
|
|
@@ -7,9 +6,8 @@ import { createAnimationState } from '../../render/utils/animation-state.mjs';
|
|
|
7
6
|
import { AnimationType } from '../../render/utils/types.mjs';
|
|
8
7
|
import { makeRenderlessComponent } from '../utils/make-renderless-component.mjs';
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
animation: makeRenderlessComponent(
|
|
12
|
-
var visualElement = _a.visualElement, animate = _a.animate;
|
|
9
|
+
const animations = {
|
|
10
|
+
animation: makeRenderlessComponent(({ visualElement, animate }) => {
|
|
13
11
|
/**
|
|
14
12
|
* We dynamically generate the AnimationState manager as it contains a reference
|
|
15
13
|
* to the underlying animation library. We only want to load that if we load this,
|
|
@@ -20,17 +18,17 @@ var animations = {
|
|
|
20
18
|
* Subscribe any provided AnimationControls to the component's VisualElement
|
|
21
19
|
*/
|
|
22
20
|
if (isAnimationControls(animate)) {
|
|
23
|
-
useEffect(
|
|
21
|
+
useEffect(() => animate.subscribe(visualElement), [animate]);
|
|
24
22
|
}
|
|
25
23
|
}),
|
|
26
|
-
exit: makeRenderlessComponent(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
useEffect(
|
|
24
|
+
exit: makeRenderlessComponent((props) => {
|
|
25
|
+
const { custom, visualElement } = props;
|
|
26
|
+
const [isPresent, safeToRemove] = usePresence();
|
|
27
|
+
const presenceContext = useContext(PresenceContext);
|
|
28
|
+
useEffect(() => {
|
|
31
29
|
var _a, _b;
|
|
32
30
|
visualElement.isPresent = isPresent;
|
|
33
|
-
|
|
31
|
+
const animation = (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Exit, !isPresent, { custom: (_b = presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.custom) !== null && _b !== void 0 ? _b : custom });
|
|
34
32
|
!isPresent && (animation === null || animation === void 0 ? void 0 : animation.then(safeToRemove));
|
|
35
33
|
}, [isPresent]);
|
|
36
34
|
}),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
isEnabled:
|
|
3
|
-
});
|
|
4
|
-
|
|
1
|
+
const createDefinition = (propNames) => ({
|
|
2
|
+
isEnabled: (props) => propNames.some((name) => !!props[name]),
|
|
3
|
+
});
|
|
4
|
+
const featureDefinitions = {
|
|
5
5
|
measureLayout: createDefinition(["layout", "layoutId", "drag"]),
|
|
6
6
|
animation: createDefinition([
|
|
7
7
|
"animate",
|
|
@@ -31,7 +31,7 @@ var featureDefinitions = {
|
|
|
31
31
|
]),
|
|
32
32
|
};
|
|
33
33
|
function loadFeatures(features) {
|
|
34
|
-
for (
|
|
34
|
+
for (const key in features) {
|
|
35
35
|
if (features[key] === null)
|
|
36
36
|
continue;
|
|
37
37
|
if (key === "projectionNodeConstructor") {
|
|
@@ -2,7 +2,7 @@ import { useDrag } from '../../gestures/drag/use-drag.mjs';
|
|
|
2
2
|
import { usePanGesture } from '../../gestures/use-pan-gesture.mjs';
|
|
3
3
|
import { makeRenderlessComponent } from '../utils/make-renderless-component.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const drag = {
|
|
6
6
|
pan: makeRenderlessComponent(usePanGesture),
|
|
7
7
|
drag: makeRenderlessComponent(useDrag),
|
|
8
8
|
};
|
|
@@ -4,7 +4,7 @@ import { useTapGesture } from '../../gestures/use-tap-gesture.mjs';
|
|
|
4
4
|
import { useViewport } from './viewport/use-viewport.mjs';
|
|
5
5
|
import { makeRenderlessComponent } from '../utils/make-renderless-component.mjs';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const gestureAnimations = {
|
|
8
8
|
inView: makeRenderlessComponent(useViewport),
|
|
9
9
|
tap: makeRenderlessComponent(useTapGesture),
|
|
10
10
|
focus: makeRenderlessComponent(useFocusGesture),
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __extends, __assign, __read } from 'tslib';
|
|
2
1
|
import sync from 'framesync';
|
|
3
2
|
import React__default, { useContext } from 'react';
|
|
4
3
|
import { usePresence } from '../../../components/AnimatePresence/use-presence.mjs';
|
|
@@ -9,20 +8,15 @@ import { correctBorderRadius } from '../../../projection/styles/scale-border-rad
|
|
|
9
8
|
import { correctBoxShadow } from '../../../projection/styles/scale-box-shadow.mjs';
|
|
10
9
|
import { addScaleCorrector } from '../../../projection/styles/scale-correction.mjs';
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
__extends(MeasureLayoutWithContext, _super);
|
|
14
|
-
function MeasureLayoutWithContext() {
|
|
15
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
16
|
-
}
|
|
11
|
+
class MeasureLayoutWithContext extends React__default.Component {
|
|
17
12
|
/**
|
|
18
13
|
* This only mounts projection nodes for components that
|
|
19
14
|
* need measuring, we might want to do it for all components
|
|
20
15
|
* in order to incorporate transforms
|
|
21
16
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var projection = visualElement.projection;
|
|
17
|
+
componentDidMount() {
|
|
18
|
+
const { visualElement, layoutGroup, switchLayoutGroup, layoutId } = this.props;
|
|
19
|
+
const { projection } = visualElement;
|
|
26
20
|
addScaleCorrector(defaultScaleCorrectors);
|
|
27
21
|
if (projection) {
|
|
28
22
|
if (layoutGroup === null || layoutGroup === void 0 ? void 0 : layoutGroup.group)
|
|
@@ -31,17 +25,16 @@ var MeasureLayoutWithContext = /** @class */ (function (_super) {
|
|
|
31
25
|
switchLayoutGroup.register(projection);
|
|
32
26
|
}
|
|
33
27
|
projection.root.didUpdate();
|
|
34
|
-
projection.addEventListener("animationComplete",
|
|
35
|
-
|
|
28
|
+
projection.addEventListener("animationComplete", () => {
|
|
29
|
+
this.safeToRemove();
|
|
36
30
|
});
|
|
37
|
-
projection.setOptions(
|
|
31
|
+
projection.setOptions(Object.assign(Object.assign({}, projection.options), { onExitComplete: () => this.safeToRemove() }));
|
|
38
32
|
}
|
|
39
33
|
globalProjectionState.hasEverUpdated = true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
var projection = visualElement.projection;
|
|
34
|
+
}
|
|
35
|
+
getSnapshotBeforeUpdate(prevProps) {
|
|
36
|
+
const { layoutDependency, visualElement, drag, isPresent } = this.props;
|
|
37
|
+
const projection = visualElement.projection;
|
|
45
38
|
if (!projection)
|
|
46
39
|
return null;
|
|
47
40
|
/**
|
|
@@ -70,28 +63,28 @@ var MeasureLayoutWithContext = /** @class */ (function (_super) {
|
|
|
70
63
|
* it's in charge of the exit animation and therefore should
|
|
71
64
|
* be in charge of the safe to remove. Otherwise we call it here.
|
|
72
65
|
*/
|
|
73
|
-
sync.postRender(
|
|
66
|
+
sync.postRender(() => {
|
|
74
67
|
var _a;
|
|
75
68
|
if (!((_a = projection.getStack()) === null || _a === void 0 ? void 0 : _a.members.length)) {
|
|
76
|
-
|
|
69
|
+
this.safeToRemove();
|
|
77
70
|
}
|
|
78
71
|
});
|
|
79
72
|
}
|
|
80
73
|
}
|
|
81
74
|
return null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
}
|
|
76
|
+
componentDidUpdate() {
|
|
77
|
+
const { projection } = this.props.visualElement;
|
|
85
78
|
if (projection) {
|
|
86
79
|
projection.root.didUpdate();
|
|
87
80
|
if (!projection.currentAnimation && projection.isLead()) {
|
|
88
81
|
this.safeToRemove();
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
}
|
|
85
|
+
componentWillUnmount() {
|
|
86
|
+
const { visualElement, layoutGroup, switchLayoutGroup: promoteContext, } = this.props;
|
|
87
|
+
const { projection } = visualElement;
|
|
95
88
|
if (projection) {
|
|
96
89
|
projection.scheduleCheckAfterUnmount();
|
|
97
90
|
if (layoutGroup === null || layoutGroup === void 0 ? void 0 : layoutGroup.group)
|
|
@@ -99,23 +92,22 @@ var MeasureLayoutWithContext = /** @class */ (function (_super) {
|
|
|
99
92
|
if (promoteContext === null || promoteContext === void 0 ? void 0 : promoteContext.deregister)
|
|
100
93
|
promoteContext.deregister(projection);
|
|
101
94
|
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
95
|
+
}
|
|
96
|
+
safeToRemove() {
|
|
97
|
+
const { safeToRemove } = this.props;
|
|
105
98
|
safeToRemove === null || safeToRemove === void 0 ? void 0 : safeToRemove();
|
|
106
|
-
}
|
|
107
|
-
|
|
99
|
+
}
|
|
100
|
+
render() {
|
|
108
101
|
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
}(React__default.Component));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
112
104
|
function MeasureLayout(props) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return (React__default.createElement(MeasureLayoutWithContext,
|
|
105
|
+
const [isPresent, safeToRemove] = usePresence();
|
|
106
|
+
const layoutGroup = useContext(LayoutGroupContext);
|
|
107
|
+
return (React__default.createElement(MeasureLayoutWithContext, Object.assign({}, props, { layoutGroup: layoutGroup, switchLayoutGroup: useContext(SwitchLayoutGroupContext), isPresent: isPresent, safeToRemove: safeToRemove })));
|
|
116
108
|
}
|
|
117
|
-
|
|
118
|
-
borderRadius:
|
|
109
|
+
const defaultScaleCorrectors = {
|
|
110
|
+
borderRadius: Object.assign(Object.assign({}, correctBorderRadius), { applyTo: [
|
|
119
111
|
"borderTopLeftRadius",
|
|
120
112
|
"borderTopRightRadius",
|
|
121
113
|
"borderBottomLeftRadius",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useContext } from 'react';
|
|
4
3
|
import { env } from '../../utils/process.mjs';
|
|
@@ -6,14 +5,14 @@ import { featureDefinitions } from './definitions.mjs';
|
|
|
6
5
|
import { invariant } from 'hey-listen';
|
|
7
6
|
import { LazyContext } from '../../context/LazyContext.mjs';
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const featureNames = Object.keys(featureDefinitions);
|
|
9
|
+
const numFeatures = featureNames.length;
|
|
11
10
|
/**
|
|
12
11
|
* Load features via renderless components based on the provided MotionProps.
|
|
13
12
|
*/
|
|
14
13
|
function useFeatures(props, visualElement, preloadedFeatures) {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const features = [];
|
|
15
|
+
const lazyContext = useContext(LazyContext);
|
|
17
16
|
if (!visualElement)
|
|
18
17
|
return null;
|
|
19
18
|
/**
|
|
@@ -23,16 +22,16 @@ function useFeatures(props, visualElement, preloadedFeatures) {
|
|
|
23
22
|
if (env !== "production" && preloadedFeatures && lazyContext.strict) {
|
|
24
23
|
invariant(false, "You have rendered a `motion` component within a `LazyMotion` component. This will break tree shaking. Import and render a `m` component instead.");
|
|
25
24
|
}
|
|
26
|
-
for (
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
for (let i = 0; i < numFeatures; i++) {
|
|
26
|
+
const name = featureNames[i];
|
|
27
|
+
const { isEnabled, Component } = featureDefinitions[name];
|
|
29
28
|
/**
|
|
30
29
|
* It might be possible in the future to use this moment to
|
|
31
30
|
* dynamically request functionality. In initial tests this
|
|
32
31
|
* was producing a lot of duplication amongst bundles.
|
|
33
32
|
*/
|
|
34
33
|
if (isEnabled(props) && Component) {
|
|
35
|
-
features.push(React.createElement(Component,
|
|
34
|
+
features.push(React.createElement(Component, Object.assign({ key: name }, props, { visualElement: visualElement })));
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
return features;
|
|
@@ -2,22 +2,21 @@ import { isRefObject } from '../../utils/is-ref-object.mjs';
|
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
import { SwitchLayoutGroupContext } from '../../context/SwitchLayoutGroupContext.mjs';
|
|
4
4
|
|
|
5
|
-
function useProjection(projectionId,
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
var initialPromotionConfig = useContext(SwitchLayoutGroupContext);
|
|
5
|
+
function useProjection(projectionId, { layoutId, layout, drag, dragConstraints, layoutScroll }, visualElement, ProjectionNodeConstructor) {
|
|
6
|
+
var _a;
|
|
7
|
+
const initialPromotionConfig = useContext(SwitchLayoutGroupContext);
|
|
9
8
|
if (!ProjectionNodeConstructor ||
|
|
10
9
|
!visualElement ||
|
|
11
10
|
(visualElement === null || visualElement === void 0 ? void 0 : visualElement.projection)) {
|
|
12
11
|
return;
|
|
13
12
|
}
|
|
14
|
-
visualElement.projection = new ProjectionNodeConstructor(projectionId, visualElement.getLatestValues(), (
|
|
13
|
+
visualElement.projection = new ProjectionNodeConstructor(projectionId, visualElement.getLatestValues(), (_a = visualElement.parent) === null || _a === void 0 ? void 0 : _a.projection);
|
|
15
14
|
visualElement.projection.setOptions({
|
|
16
|
-
layoutId
|
|
17
|
-
layout
|
|
15
|
+
layoutId,
|
|
16
|
+
layout,
|
|
18
17
|
alwaysMeasureLayout: Boolean(drag) || (dragConstraints && isRefObject(dragConstraints)),
|
|
19
|
-
visualElement
|
|
20
|
-
scheduleRender:
|
|
18
|
+
visualElement,
|
|
19
|
+
scheduleRender: () => visualElement.scheduleRender(),
|
|
21
20
|
/**
|
|
22
21
|
* TODO: Update options in an effect. This could be tricky as it'll be too late
|
|
23
22
|
* to update by the time layout animations run.
|
|
@@ -26,8 +25,8 @@ function useProjection(projectionId, _a, visualElement, ProjectionNodeConstructo
|
|
|
26
25
|
*
|
|
27
26
|
*/
|
|
28
27
|
animationType: typeof layout === "string" ? layout : "both",
|
|
29
|
-
initialPromotionConfig
|
|
30
|
-
layoutScroll
|
|
28
|
+
initialPromotionConfig,
|
|
29
|
+
layoutScroll,
|
|
31
30
|
});
|
|
32
31
|
}
|
|
33
32
|
|