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,9 +1,8 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
|
|
3
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
4
|
-
if (options === void 0) { options = { passive: true }; }
|
|
3
|
+
function addDomEvent(target, eventName, handler, options = { passive: true }) {
|
|
5
4
|
target.addEventListener(eventName, handler, options);
|
|
6
|
-
return
|
|
5
|
+
return () => target.removeEventListener(eventName, handler);
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
9
8
|
* Attaches an event listener directly to the provided DOM element.
|
|
@@ -27,8 +26,8 @@ function addDomEvent(target, eventName, handler, options) {
|
|
|
27
26
|
* @public
|
|
28
27
|
*/
|
|
29
28
|
function useDomEvent(ref, eventName, handler, options) {
|
|
30
|
-
useEffect(
|
|
31
|
-
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const element = ref.current;
|
|
32
31
|
if (handler && element) {
|
|
33
32
|
return addDomEvent(element, eventName, handler, options);
|
|
34
33
|
}
|
|
@@ -2,7 +2,7 @@ import { addDomEvent, useDomEvent } from './use-dom-event.mjs';
|
|
|
2
2
|
import { wrapHandler } from './event-info.mjs';
|
|
3
3
|
import { supportsPointerEvents, supportsTouchEvents, supportsMouseEvents } from './utils.mjs';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const mouseEventNames = {
|
|
6
6
|
pointerdown: "mousedown",
|
|
7
7
|
pointermove: "mousemove",
|
|
8
8
|
pointerup: "mouseup",
|
|
@@ -12,7 +12,7 @@ var mouseEventNames = {
|
|
|
12
12
|
pointerenter: "mouseenter",
|
|
13
13
|
pointerleave: "mouseleave",
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
const touchEventNames = {
|
|
16
16
|
pointerdown: "touchstart",
|
|
17
17
|
pointermove: "touchmove",
|
|
18
18
|
pointerup: "touchend",
|
package/dist/es/events/utils.mjs
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { isBrowser } from '../utils/is-browser.mjs';
|
|
2
2
|
|
|
3
3
|
// We check for event support via functions in case they've been mocked by a testing suite.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var supportsTouchEvents = function () {
|
|
8
|
-
return isBrowser && window.ontouchstart === null;
|
|
9
|
-
};
|
|
10
|
-
var supportsMouseEvents = function () {
|
|
11
|
-
return isBrowser && window.onmousedown === null;
|
|
12
|
-
};
|
|
4
|
+
const supportsPointerEvents = () => isBrowser && window.onpointerdown === null;
|
|
5
|
+
const supportsTouchEvents = () => isBrowser && window.ontouchstart === null;
|
|
6
|
+
const supportsMouseEvents = () => isBrowser && window.onmousedown === null;
|
|
13
7
|
|
|
14
8
|
export { supportsMouseEvents, supportsPointerEvents, supportsTouchEvents };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { __assign } from 'tslib';
|
|
2
1
|
import { isMouseEvent, isTouchEvent } from './utils/event-type.mjs';
|
|
3
2
|
import { extractEventInfo } from '../events/event-info.mjs';
|
|
4
3
|
import sync, { getFrameData, cancelSync } from 'framesync';
|
|
@@ -9,10 +8,8 @@ import { distance, pipe } from 'popmotion';
|
|
|
9
8
|
/**
|
|
10
9
|
* @internal
|
|
11
10
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _b = _a === void 0 ? {} : _a, transformPagePoint = _b.transformPagePoint;
|
|
15
|
-
var _this = this;
|
|
11
|
+
class PanSession {
|
|
12
|
+
constructor(event, handlers, { transformPagePoint } = {}) {
|
|
16
13
|
/**
|
|
17
14
|
* @internal
|
|
18
15
|
*/
|
|
@@ -29,43 +26,43 @@ var PanSession = /** @class */ (function () {
|
|
|
29
26
|
* @internal
|
|
30
27
|
*/
|
|
31
28
|
this.handlers = {};
|
|
32
|
-
this.updatePoint =
|
|
33
|
-
if (!(
|
|
29
|
+
this.updatePoint = () => {
|
|
30
|
+
if (!(this.lastMoveEvent && this.lastMoveEventInfo))
|
|
34
31
|
return;
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const info = getPanInfo(this.lastMoveEventInfo, this.history);
|
|
33
|
+
const isPanStarted = this.startEvent !== null;
|
|
37
34
|
// Only start panning if the offset is larger than 3 pixels. If we make it
|
|
38
35
|
// any larger than this we'll want to reset the pointer history
|
|
39
36
|
// on the first update to avoid visual snapping to the cursoe.
|
|
40
|
-
|
|
37
|
+
const isDistancePastThreshold = distance(info.offset, { x: 0, y: 0 }) >= 3;
|
|
41
38
|
if (!isPanStarted && !isDistancePastThreshold)
|
|
42
39
|
return;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
const { point } = info;
|
|
41
|
+
const { timestamp } = getFrameData();
|
|
42
|
+
this.history.push(Object.assign(Object.assign({}, point), { timestamp }));
|
|
43
|
+
const { onStart, onMove } = this.handlers;
|
|
47
44
|
if (!isPanStarted) {
|
|
48
|
-
onStart && onStart(
|
|
49
|
-
|
|
45
|
+
onStart && onStart(this.lastMoveEvent, info);
|
|
46
|
+
this.startEvent = this.lastMoveEvent;
|
|
50
47
|
}
|
|
51
|
-
onMove && onMove(
|
|
48
|
+
onMove && onMove(this.lastMoveEvent, info);
|
|
52
49
|
};
|
|
53
|
-
this.handlePointerMove =
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
this.handlePointerMove = (event, info) => {
|
|
51
|
+
this.lastMoveEvent = event;
|
|
52
|
+
this.lastMoveEventInfo = transformPoint(info, this.transformPagePoint);
|
|
56
53
|
// Because Safari doesn't trigger mouseup events when it's above a `<select>`
|
|
57
54
|
if (isMouseEvent(event) && event.buttons === 0) {
|
|
58
|
-
|
|
55
|
+
this.handlePointerUp(event, info);
|
|
59
56
|
return;
|
|
60
57
|
}
|
|
61
58
|
// Throttle mouse move event to once per frame
|
|
62
|
-
sync.update(
|
|
59
|
+
sync.update(this.updatePoint, true);
|
|
63
60
|
};
|
|
64
|
-
this.handlePointerUp =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (
|
|
61
|
+
this.handlePointerUp = (event, info) => {
|
|
62
|
+
this.end();
|
|
63
|
+
const { onEnd, onSessionEnd } = this.handlers;
|
|
64
|
+
const panInfo = getPanInfo(transformPoint(info, this.transformPagePoint), this.history);
|
|
65
|
+
if (this.startEvent && onEnd) {
|
|
69
66
|
onEnd(event, panInfo);
|
|
70
67
|
}
|
|
71
68
|
onSessionEnd && onSessionEnd(event, panInfo);
|
|
@@ -75,35 +72,33 @@ var PanSession = /** @class */ (function () {
|
|
|
75
72
|
return;
|
|
76
73
|
this.handlers = handlers;
|
|
77
74
|
this.transformPagePoint = transformPagePoint;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.history = [
|
|
83
|
-
|
|
75
|
+
const info = extractEventInfo(event);
|
|
76
|
+
const initialInfo = transformPoint(info, this.transformPagePoint);
|
|
77
|
+
const { point } = initialInfo;
|
|
78
|
+
const { timestamp } = getFrameData();
|
|
79
|
+
this.history = [Object.assign(Object.assign({}, point), { timestamp })];
|
|
80
|
+
const { onSessionStart } = handlers;
|
|
84
81
|
onSessionStart &&
|
|
85
82
|
onSessionStart(event, getPanInfo(initialInfo, this.history));
|
|
86
83
|
this.removeListeners = pipe(addPointerEvent(window, "pointermove", this.handlePointerMove), addPointerEvent(window, "pointerup", this.handlePointerUp), addPointerEvent(window, "pointercancel", this.handlePointerUp));
|
|
87
84
|
}
|
|
88
|
-
|
|
85
|
+
updateHandlers(handlers) {
|
|
89
86
|
this.handlers = handlers;
|
|
90
|
-
}
|
|
91
|
-
|
|
87
|
+
}
|
|
88
|
+
end() {
|
|
92
89
|
this.removeListeners && this.removeListeners();
|
|
93
90
|
cancelSync.update(this.updatePoint);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
}());
|
|
91
|
+
}
|
|
92
|
+
}
|
|
97
93
|
function transformPoint(info, transformPagePoint) {
|
|
98
94
|
return transformPagePoint ? { point: transformPagePoint(info.point) } : info;
|
|
99
95
|
}
|
|
100
96
|
function subtractPoint(a, b) {
|
|
101
97
|
return { x: a.x - b.x, y: a.y - b.y };
|
|
102
98
|
}
|
|
103
|
-
function getPanInfo(
|
|
104
|
-
var point = _a.point;
|
|
99
|
+
function getPanInfo({ point }, history) {
|
|
105
100
|
return {
|
|
106
|
-
point
|
|
101
|
+
point,
|
|
107
102
|
delta: subtractPoint(point, lastDevicePoint(history)),
|
|
108
103
|
offset: subtractPoint(point, startDevicePoint(history)),
|
|
109
104
|
velocity: getVelocity(history, 0.1),
|
|
@@ -119,9 +114,9 @@ function getVelocity(history, timeDelta) {
|
|
|
119
114
|
if (history.length < 2) {
|
|
120
115
|
return { x: 0, y: 0 };
|
|
121
116
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
117
|
+
let i = history.length - 1;
|
|
118
|
+
let timestampedPoint = null;
|
|
119
|
+
const lastPoint = lastDevicePoint(history);
|
|
125
120
|
while (i >= 0) {
|
|
126
121
|
timestampedPoint = history[i];
|
|
127
122
|
if (lastPoint.timestamp - timestampedPoint.timestamp >
|
|
@@ -133,11 +128,11 @@ function getVelocity(history, timeDelta) {
|
|
|
133
128
|
if (!timestampedPoint) {
|
|
134
129
|
return { x: 0, y: 0 };
|
|
135
130
|
}
|
|
136
|
-
|
|
131
|
+
const time = (lastPoint.timestamp - timestampedPoint.timestamp) / 1000;
|
|
137
132
|
if (time === 0) {
|
|
138
133
|
return { x: 0, y: 0 };
|
|
139
134
|
}
|
|
140
|
-
|
|
135
|
+
const currentVelocity = {
|
|
141
136
|
x: (lastPoint.x - timestampedPoint.x) / time,
|
|
142
137
|
y: (lastPoint.y - timestampedPoint.y) / time,
|
|
143
138
|
};
|