framer-motion 7.10.2 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +24 -88
- package/dist/es/events/event-info.mjs +6 -34
- package/dist/es/events/use-pointer-event.mjs +2 -31
- package/dist/es/events/utils/is-primary-pointer.mjs +7 -0
- package/dist/es/gestures/PanSession.mjs +2 -7
- package/dist/es/gestures/drag/VisualElementDragControls.mjs +1 -1
- package/dist/es/gestures/use-hover-gesture.mjs +3 -1
- package/dist/es/motion/utils/use-visual-element.mjs +7 -2
- package/dist/es/render/utils/motion-values.mjs +1 -1
- package/dist/es/value/index.mjs +1 -1
- package/dist/framer-motion.dev.js +24 -88
- package/dist/framer-motion.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/projection.dev.js +2 -2
- package/dist/size-rollup-dom-animation-m.js +1 -1
- 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-rollup-motion.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 +2 -2
- package/package.json +7 -7
- package/dist/es/events/utils.mjs +0 -8
- package/dist/es/gestures/utils/event-type.mjs +0 -13
package/dist/cjs/index.js
CHANGED
|
@@ -80,7 +80,12 @@ function useVisualElement(Component, visualState, props, createVisualElement) {
|
|
|
80
80
|
useIsomorphicLayoutEffect(() => {
|
|
81
81
|
visualElement && visualElement.render();
|
|
82
82
|
});
|
|
83
|
-
|
|
83
|
+
/**
|
|
84
|
+
* If we have optimised appear animations to handoff from, trigger animateChanges
|
|
85
|
+
* from a synchronous useLayoutEffect to ensure there's no flash of incorrectly
|
|
86
|
+
* styled component in the event of a hydration error.
|
|
87
|
+
*/
|
|
88
|
+
useIsomorphicLayoutEffect(() => {
|
|
84
89
|
if (visualElement && visualElement.animationState) {
|
|
85
90
|
visualElement.animationState.animateChanges();
|
|
86
91
|
}
|
|
@@ -1363,99 +1368,32 @@ function useFocusGesture({ whileFocus, visualElement, }) {
|
|
|
1363
1368
|
useDomEvent(visualElement, "blur", whileFocus ? onBlur : undefined);
|
|
1364
1369
|
}
|
|
1365
1370
|
|
|
1366
|
-
function isMouseEvent(event) {
|
|
1367
|
-
// PointerEvent inherits from MouseEvent so we can't use a straight instanceof check.
|
|
1368
|
-
if (typeof PointerEvent !== "undefined" && event instanceof PointerEvent) {
|
|
1369
|
-
return !!(event.pointerType === "mouse");
|
|
1370
|
-
}
|
|
1371
|
-
return event instanceof MouseEvent;
|
|
1372
|
-
}
|
|
1373
|
-
function isTouchEvent(event) {
|
|
1374
|
-
const hasTouches = !!event.touches;
|
|
1375
|
-
return hasTouches;
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
1371
|
/**
|
|
1379
|
-
*
|
|
1380
|
-
*
|
|
1372
|
+
* Specifically match against false here as incomplete versions of
|
|
1373
|
+
* PointerEvents in very old browser might have it set as undefined.
|
|
1381
1374
|
*/
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
const isMouseEvent = event instanceof MouseEvent;
|
|
1385
|
-
const isPrimaryPointer = !isMouseEvent ||
|
|
1386
|
-
(isMouseEvent && event.button === 0);
|
|
1387
|
-
if (isPrimaryPointer) {
|
|
1388
|
-
eventHandler(event);
|
|
1389
|
-
}
|
|
1390
|
-
};
|
|
1391
|
-
}
|
|
1392
|
-
const defaultPagePoint = { pageX: 0, pageY: 0 };
|
|
1393
|
-
function pointFromTouch(e, pointType = "page") {
|
|
1394
|
-
const primaryTouch = e.touches[0] || e.changedTouches[0];
|
|
1395
|
-
const point = primaryTouch || defaultPagePoint;
|
|
1396
|
-
return {
|
|
1397
|
-
x: point[pointType + "X"],
|
|
1398
|
-
y: point[pointType + "Y"],
|
|
1399
|
-
};
|
|
1400
|
-
}
|
|
1401
|
-
function pointFromMouse(point, pointType = "page") {
|
|
1402
|
-
return {
|
|
1403
|
-
x: point[pointType + "X"],
|
|
1404
|
-
y: point[pointType + "Y"],
|
|
1405
|
-
};
|
|
1406
|
-
}
|
|
1375
|
+
const isPrimaryPointer = (event) => event.isPrimary !== false;
|
|
1376
|
+
|
|
1407
1377
|
function extractEventInfo(event, pointType = "page") {
|
|
1408
1378
|
return {
|
|
1409
|
-
point:
|
|
1410
|
-
|
|
1411
|
-
:
|
|
1379
|
+
point: {
|
|
1380
|
+
x: event[pointType + "X"],
|
|
1381
|
+
y: event[pointType + "Y"],
|
|
1382
|
+
},
|
|
1412
1383
|
};
|
|
1413
1384
|
}
|
|
1414
1385
|
const wrapHandler = (handler, shouldFilterPrimaryPointer = false) => {
|
|
1415
1386
|
const listener = (event) => handler(event, extractEventInfo(event));
|
|
1416
1387
|
return shouldFilterPrimaryPointer
|
|
1417
|
-
?
|
|
1388
|
+
? (event) => isPrimaryPointer(event) && listener(event)
|
|
1418
1389
|
: listener;
|
|
1419
1390
|
};
|
|
1420
1391
|
|
|
1421
|
-
// We check for event support via functions in case they've been mocked by a testing suite.
|
|
1422
|
-
const supportsPointerEvents = () => isBrowser && window.onpointerdown === null;
|
|
1423
|
-
const supportsTouchEvents = () => isBrowser && window.ontouchstart === null;
|
|
1424
|
-
const supportsMouseEvents = () => isBrowser && window.onmousedown === null;
|
|
1425
|
-
|
|
1426
|
-
const mouseEventNames = {
|
|
1427
|
-
pointerdown: "mousedown",
|
|
1428
|
-
pointermove: "mousemove",
|
|
1429
|
-
pointerup: "mouseup",
|
|
1430
|
-
pointercancel: "mousecancel",
|
|
1431
|
-
pointerover: "mouseover",
|
|
1432
|
-
pointerout: "mouseout",
|
|
1433
|
-
pointerenter: "mouseenter",
|
|
1434
|
-
pointerleave: "mouseleave",
|
|
1435
|
-
};
|
|
1436
|
-
const touchEventNames = {
|
|
1437
|
-
pointerdown: "touchstart",
|
|
1438
|
-
pointermove: "touchmove",
|
|
1439
|
-
pointerup: "touchend",
|
|
1440
|
-
pointercancel: "touchcancel",
|
|
1441
|
-
};
|
|
1442
|
-
function getPointerEventName(name) {
|
|
1443
|
-
if (supportsPointerEvents()) {
|
|
1444
|
-
return name;
|
|
1445
|
-
}
|
|
1446
|
-
else if (supportsTouchEvents()) {
|
|
1447
|
-
return touchEventNames[name];
|
|
1448
|
-
}
|
|
1449
|
-
else if (supportsMouseEvents()) {
|
|
1450
|
-
return mouseEventNames[name];
|
|
1451
|
-
}
|
|
1452
|
-
return name;
|
|
1453
|
-
}
|
|
1454
1392
|
function addPointerEvent(target, eventName, handler, options) {
|
|
1455
|
-
return addDomEvent(target,
|
|
1393
|
+
return addDomEvent(target, eventName, wrapHandler(handler, eventName === "pointerdown"), options);
|
|
1456
1394
|
}
|
|
1457
1395
|
function usePointerEvent(ref, eventName, handler, options) {
|
|
1458
|
-
return useDomEvent(ref,
|
|
1396
|
+
return useDomEvent(ref, eventName, handler && wrapHandler(handler, eventName === "pointerdown"), options);
|
|
1459
1397
|
}
|
|
1460
1398
|
|
|
1461
1399
|
function createLock(name) {
|
|
@@ -1510,6 +1448,9 @@ function isDragActive() {
|
|
|
1510
1448
|
return false;
|
|
1511
1449
|
}
|
|
1512
1450
|
|
|
1451
|
+
function isMouseEvent(event) {
|
|
1452
|
+
return event.type !== "pen" && event.type !== "touch";
|
|
1453
|
+
}
|
|
1513
1454
|
function createHoverEvent(visualElement, isActive, callback) {
|
|
1514
1455
|
return (event, info) => {
|
|
1515
1456
|
if (!isMouseEvent(event) || isDragActive())
|
|
@@ -2124,7 +2065,7 @@ class MotionValue {
|
|
|
2124
2065
|
* This will be replaced by the build step with the latest version number.
|
|
2125
2066
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
2126
2067
|
*/
|
|
2127
|
-
this.version = "
|
|
2068
|
+
this.version = "8.0.0";
|
|
2128
2069
|
/**
|
|
2129
2070
|
* Duration, in milliseconds, since last updating frame.
|
|
2130
2071
|
*
|
|
@@ -4631,11 +4572,6 @@ class PanSession {
|
|
|
4631
4572
|
this.handlePointerMove = (event, info) => {
|
|
4632
4573
|
this.lastMoveEvent = event;
|
|
4633
4574
|
this.lastMoveEventInfo = transformPoint(info, this.transformPagePoint);
|
|
4634
|
-
// Because Safari doesn't trigger mouseup events when it's above a `<select>`
|
|
4635
|
-
if (isMouseEvent(event) && event.buttons === 0) {
|
|
4636
|
-
this.handlePointerUp(event, info);
|
|
4637
|
-
return;
|
|
4638
|
-
}
|
|
4639
4575
|
// Throttle mouse move event to once per frame
|
|
4640
4576
|
sync.update(this.updatePoint, true);
|
|
4641
4577
|
};
|
|
@@ -4649,7 +4585,7 @@ class PanSession {
|
|
|
4649
4585
|
onSessionEnd && onSessionEnd(event, panInfo);
|
|
4650
4586
|
};
|
|
4651
4587
|
// If we have more than one touch, don't start detecting this gesture
|
|
4652
|
-
if (
|
|
4588
|
+
if (!isPrimaryPointer(event))
|
|
4653
4589
|
return;
|
|
4654
4590
|
this.handlers = handlers;
|
|
4655
4591
|
this.transformPagePoint = transformPagePoint;
|
|
@@ -5086,7 +5022,7 @@ const elementDragControls = new WeakMap();
|
|
|
5086
5022
|
/**
|
|
5087
5023
|
*
|
|
5088
5024
|
*/
|
|
5089
|
-
// let latestPointerEvent:
|
|
5025
|
+
// let latestPointerEvent: PointerEvent
|
|
5090
5026
|
class VisualElementDragControls {
|
|
5091
5027
|
constructor(visualElement) {
|
|
5092
5028
|
// This is a reference to the global drag gesture lock, ensuring only one component
|
|
@@ -5932,7 +5868,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
5932
5868
|
* and warn against mismatches.
|
|
5933
5869
|
*/
|
|
5934
5870
|
if (process.env.NODE_ENV === "development") {
|
|
5935
|
-
warnOnce(nextValue.version === "
|
|
5871
|
+
warnOnce(nextValue.version === "8.0.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 8.0.0 may not work as expected.`);
|
|
5936
5872
|
}
|
|
5937
5873
|
}
|
|
5938
5874
|
else if (isMotionValue(prevValue)) {
|
|
@@ -1,45 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isPrimaryPointer } from './utils/is-primary-pointer.mjs';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Filters out events not attached to the primary pointer (currently left mouse button)
|
|
5
|
-
* @param eventHandler
|
|
6
|
-
*/
|
|
7
|
-
function filterPrimaryPointer(eventHandler) {
|
|
8
|
-
return (event) => {
|
|
9
|
-
const isMouseEvent = event instanceof MouseEvent;
|
|
10
|
-
const isPrimaryPointer = !isMouseEvent ||
|
|
11
|
-
(isMouseEvent && event.button === 0);
|
|
12
|
-
if (isPrimaryPointer) {
|
|
13
|
-
eventHandler(event);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
const defaultPagePoint = { pageX: 0, pageY: 0 };
|
|
18
|
-
function pointFromTouch(e, pointType = "page") {
|
|
19
|
-
const primaryTouch = e.touches[0] || e.changedTouches[0];
|
|
20
|
-
const point = primaryTouch || defaultPagePoint;
|
|
21
|
-
return {
|
|
22
|
-
x: point[pointType + "X"],
|
|
23
|
-
y: point[pointType + "Y"],
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function pointFromMouse(point, pointType = "page") {
|
|
27
|
-
return {
|
|
28
|
-
x: point[pointType + "X"],
|
|
29
|
-
y: point[pointType + "Y"],
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
3
|
function extractEventInfo(event, pointType = "page") {
|
|
33
4
|
return {
|
|
34
|
-
point:
|
|
35
|
-
|
|
36
|
-
:
|
|
5
|
+
point: {
|
|
6
|
+
x: event[pointType + "X"],
|
|
7
|
+
y: event[pointType + "Y"],
|
|
8
|
+
},
|
|
37
9
|
};
|
|
38
10
|
}
|
|
39
11
|
const wrapHandler = (handler, shouldFilterPrimaryPointer = false) => {
|
|
40
12
|
const listener = (event) => handler(event, extractEventInfo(event));
|
|
41
13
|
return shouldFilterPrimaryPointer
|
|
42
|
-
?
|
|
14
|
+
? (event) => isPrimaryPointer(event) && listener(event)
|
|
43
15
|
: listener;
|
|
44
16
|
};
|
|
45
17
|
|
|
@@ -1,40 +1,11 @@
|
|
|
1
1
|
import { addDomEvent, useDomEvent } from './use-dom-event.mjs';
|
|
2
2
|
import { wrapHandler } from './event-info.mjs';
|
|
3
|
-
import { supportsPointerEvents, supportsTouchEvents, supportsMouseEvents } from './utils.mjs';
|
|
4
3
|
|
|
5
|
-
const mouseEventNames = {
|
|
6
|
-
pointerdown: "mousedown",
|
|
7
|
-
pointermove: "mousemove",
|
|
8
|
-
pointerup: "mouseup",
|
|
9
|
-
pointercancel: "mousecancel",
|
|
10
|
-
pointerover: "mouseover",
|
|
11
|
-
pointerout: "mouseout",
|
|
12
|
-
pointerenter: "mouseenter",
|
|
13
|
-
pointerleave: "mouseleave",
|
|
14
|
-
};
|
|
15
|
-
const touchEventNames = {
|
|
16
|
-
pointerdown: "touchstart",
|
|
17
|
-
pointermove: "touchmove",
|
|
18
|
-
pointerup: "touchend",
|
|
19
|
-
pointercancel: "touchcancel",
|
|
20
|
-
};
|
|
21
|
-
function getPointerEventName(name) {
|
|
22
|
-
if (supportsPointerEvents()) {
|
|
23
|
-
return name;
|
|
24
|
-
}
|
|
25
|
-
else if (supportsTouchEvents()) {
|
|
26
|
-
return touchEventNames[name];
|
|
27
|
-
}
|
|
28
|
-
else if (supportsMouseEvents()) {
|
|
29
|
-
return mouseEventNames[name];
|
|
30
|
-
}
|
|
31
|
-
return name;
|
|
32
|
-
}
|
|
33
4
|
function addPointerEvent(target, eventName, handler, options) {
|
|
34
|
-
return addDomEvent(target,
|
|
5
|
+
return addDomEvent(target, eventName, wrapHandler(handler, eventName === "pointerdown"), options);
|
|
35
6
|
}
|
|
36
7
|
function usePointerEvent(ref, eventName, handler, options) {
|
|
37
|
-
return useDomEvent(ref,
|
|
8
|
+
return useDomEvent(ref, eventName, handler && wrapHandler(handler, eventName === "pointerdown"), options);
|
|
38
9
|
}
|
|
39
10
|
|
|
40
11
|
export { addPointerEvent, usePointerEvent };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isMouseEvent, isTouchEvent } from './utils/event-type.mjs';
|
|
2
1
|
import { extractEventInfo } from '../events/event-info.mjs';
|
|
3
2
|
import { sync, cancelSync } from '../frameloop/index.mjs';
|
|
4
3
|
import { secondsToMilliseconds } from '../utils/time-conversion.mjs';
|
|
@@ -6,6 +5,7 @@ import { addPointerEvent } from '../events/use-pointer-event.mjs';
|
|
|
6
5
|
import { pipe } from '../utils/pipe.mjs';
|
|
7
6
|
import { distance2D } from '../utils/distance.mjs';
|
|
8
7
|
import { frameData } from '../frameloop/data.mjs';
|
|
8
|
+
import { isPrimaryPointer } from '../events/utils/is-primary-pointer.mjs';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @internal
|
|
@@ -52,11 +52,6 @@ class PanSession {
|
|
|
52
52
|
this.handlePointerMove = (event, info) => {
|
|
53
53
|
this.lastMoveEvent = event;
|
|
54
54
|
this.lastMoveEventInfo = transformPoint(info, this.transformPagePoint);
|
|
55
|
-
// Because Safari doesn't trigger mouseup events when it's above a `<select>`
|
|
56
|
-
if (isMouseEvent(event) && event.buttons === 0) {
|
|
57
|
-
this.handlePointerUp(event, info);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
55
|
// Throttle mouse move event to once per frame
|
|
61
56
|
sync.update(this.updatePoint, true);
|
|
62
57
|
};
|
|
@@ -70,7 +65,7 @@ class PanSession {
|
|
|
70
65
|
onSessionEnd && onSessionEnd(event, panInfo);
|
|
71
66
|
};
|
|
72
67
|
// If we have more than one touch, don't start detecting this gesture
|
|
73
|
-
if (
|
|
68
|
+
if (!isPrimaryPointer(event))
|
|
74
69
|
return;
|
|
75
70
|
this.handlers = handlers;
|
|
76
71
|
this.transformPagePoint = transformPagePoint;
|
|
@@ -20,7 +20,7 @@ const elementDragControls = new WeakMap();
|
|
|
20
20
|
/**
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
|
-
// let latestPointerEvent:
|
|
23
|
+
// let latestPointerEvent: PointerEvent
|
|
24
24
|
class VisualElementDragControls {
|
|
25
25
|
constructor(visualElement) {
|
|
26
26
|
// This is a reference to the global drag gesture lock, ensuring only one component
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { isMouseEvent } from './utils/event-type.mjs';
|
|
2
1
|
import { AnimationType } from '../render/utils/types.mjs';
|
|
3
2
|
import { usePointerEvent } from '../events/use-pointer-event.mjs';
|
|
4
3
|
import { isDragActive } from './drag/utils/lock.mjs';
|
|
5
4
|
|
|
5
|
+
function isMouseEvent(event) {
|
|
6
|
+
return event.type !== "pen" && event.type !== "touch";
|
|
7
|
+
}
|
|
6
8
|
function createHoverEvent(visualElement, isActive, callback) {
|
|
7
9
|
return (event, info) => {
|
|
8
10
|
if (!isMouseEvent(event) || isDragActive())
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useContext, useRef
|
|
1
|
+
import { useContext, useRef } from 'react';
|
|
2
2
|
import { PresenceContext } from '../../context/PresenceContext.mjs';
|
|
3
3
|
import { useVisualElementContext } from '../../context/MotionContext/index.mjs';
|
|
4
4
|
import { useIsomorphicLayoutEffect } from '../../utils/use-isomorphic-effect.mjs';
|
|
@@ -31,7 +31,12 @@ function useVisualElement(Component, visualState, props, createVisualElement) {
|
|
|
31
31
|
useIsomorphicLayoutEffect(() => {
|
|
32
32
|
visualElement && visualElement.render();
|
|
33
33
|
});
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* If we have optimised appear animations to handoff from, trigger animateChanges
|
|
36
|
+
* from a synchronous useLayoutEffect to ensure there's no flash of incorrectly
|
|
37
|
+
* styled component in the event of a hydration error.
|
|
38
|
+
*/
|
|
39
|
+
useIsomorphicLayoutEffect(() => {
|
|
35
40
|
if (visualElement && visualElement.animationState) {
|
|
36
41
|
visualElement.animationState.animateChanges();
|
|
37
42
|
}
|
|
@@ -22,7 +22,7 @@ function updateMotionValuesFromProps(element, next, prev) {
|
|
|
22
22
|
* and warn against mismatches.
|
|
23
23
|
*/
|
|
24
24
|
if (process.env.NODE_ENV === "development") {
|
|
25
|
-
warnOnce(nextValue.version === "
|
|
25
|
+
warnOnce(nextValue.version === "8.0.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 8.0.0 may not work as expected.`);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
else if (isMotionValue(prevValue)) {
|
package/dist/es/value/index.mjs
CHANGED
|
@@ -25,7 +25,7 @@ class MotionValue {
|
|
|
25
25
|
* This will be replaced by the build step with the latest version number.
|
|
26
26
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
27
27
|
*/
|
|
28
|
-
this.version = "
|
|
28
|
+
this.version = "8.0.0";
|
|
29
29
|
/**
|
|
30
30
|
* Duration, in milliseconds, since last updating frame.
|
|
31
31
|
*
|
|
@@ -78,7 +78,12 @@
|
|
|
78
78
|
useIsomorphicLayoutEffect(() => {
|
|
79
79
|
visualElement && visualElement.render();
|
|
80
80
|
});
|
|
81
|
-
|
|
81
|
+
/**
|
|
82
|
+
* If we have optimised appear animations to handoff from, trigger animateChanges
|
|
83
|
+
* from a synchronous useLayoutEffect to ensure there's no flash of incorrectly
|
|
84
|
+
* styled component in the event of a hydration error.
|
|
85
|
+
*/
|
|
86
|
+
useIsomorphicLayoutEffect(() => {
|
|
82
87
|
if (visualElement && visualElement.animationState) {
|
|
83
88
|
visualElement.animationState.animateChanges();
|
|
84
89
|
}
|
|
@@ -1361,99 +1366,32 @@
|
|
|
1361
1366
|
useDomEvent(visualElement, "blur", whileFocus ? onBlur : undefined);
|
|
1362
1367
|
}
|
|
1363
1368
|
|
|
1364
|
-
function isMouseEvent(event) {
|
|
1365
|
-
// PointerEvent inherits from MouseEvent so we can't use a straight instanceof check.
|
|
1366
|
-
if (typeof PointerEvent !== "undefined" && event instanceof PointerEvent) {
|
|
1367
|
-
return !!(event.pointerType === "mouse");
|
|
1368
|
-
}
|
|
1369
|
-
return event instanceof MouseEvent;
|
|
1370
|
-
}
|
|
1371
|
-
function isTouchEvent(event) {
|
|
1372
|
-
const hasTouches = !!event.touches;
|
|
1373
|
-
return hasTouches;
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
1369
|
/**
|
|
1377
|
-
*
|
|
1378
|
-
*
|
|
1370
|
+
* Specifically match against false here as incomplete versions of
|
|
1371
|
+
* PointerEvents in very old browser might have it set as undefined.
|
|
1379
1372
|
*/
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
const isMouseEvent = event instanceof MouseEvent;
|
|
1383
|
-
const isPrimaryPointer = !isMouseEvent ||
|
|
1384
|
-
(isMouseEvent && event.button === 0);
|
|
1385
|
-
if (isPrimaryPointer) {
|
|
1386
|
-
eventHandler(event);
|
|
1387
|
-
}
|
|
1388
|
-
};
|
|
1389
|
-
}
|
|
1390
|
-
const defaultPagePoint = { pageX: 0, pageY: 0 };
|
|
1391
|
-
function pointFromTouch(e, pointType = "page") {
|
|
1392
|
-
const primaryTouch = e.touches[0] || e.changedTouches[0];
|
|
1393
|
-
const point = primaryTouch || defaultPagePoint;
|
|
1394
|
-
return {
|
|
1395
|
-
x: point[pointType + "X"],
|
|
1396
|
-
y: point[pointType + "Y"],
|
|
1397
|
-
};
|
|
1398
|
-
}
|
|
1399
|
-
function pointFromMouse(point, pointType = "page") {
|
|
1400
|
-
return {
|
|
1401
|
-
x: point[pointType + "X"],
|
|
1402
|
-
y: point[pointType + "Y"],
|
|
1403
|
-
};
|
|
1404
|
-
}
|
|
1373
|
+
const isPrimaryPointer = (event) => event.isPrimary !== false;
|
|
1374
|
+
|
|
1405
1375
|
function extractEventInfo(event, pointType = "page") {
|
|
1406
1376
|
return {
|
|
1407
|
-
point:
|
|
1408
|
-
|
|
1409
|
-
:
|
|
1377
|
+
point: {
|
|
1378
|
+
x: event[pointType + "X"],
|
|
1379
|
+
y: event[pointType + "Y"],
|
|
1380
|
+
},
|
|
1410
1381
|
};
|
|
1411
1382
|
}
|
|
1412
1383
|
const wrapHandler = (handler, shouldFilterPrimaryPointer = false) => {
|
|
1413
1384
|
const listener = (event) => handler(event, extractEventInfo(event));
|
|
1414
1385
|
return shouldFilterPrimaryPointer
|
|
1415
|
-
?
|
|
1386
|
+
? (event) => isPrimaryPointer(event) && listener(event)
|
|
1416
1387
|
: listener;
|
|
1417
1388
|
};
|
|
1418
1389
|
|
|
1419
|
-
// We check for event support via functions in case they've been mocked by a testing suite.
|
|
1420
|
-
const supportsPointerEvents = () => isBrowser && window.onpointerdown === null;
|
|
1421
|
-
const supportsTouchEvents = () => isBrowser && window.ontouchstart === null;
|
|
1422
|
-
const supportsMouseEvents = () => isBrowser && window.onmousedown === null;
|
|
1423
|
-
|
|
1424
|
-
const mouseEventNames = {
|
|
1425
|
-
pointerdown: "mousedown",
|
|
1426
|
-
pointermove: "mousemove",
|
|
1427
|
-
pointerup: "mouseup",
|
|
1428
|
-
pointercancel: "mousecancel",
|
|
1429
|
-
pointerover: "mouseover",
|
|
1430
|
-
pointerout: "mouseout",
|
|
1431
|
-
pointerenter: "mouseenter",
|
|
1432
|
-
pointerleave: "mouseleave",
|
|
1433
|
-
};
|
|
1434
|
-
const touchEventNames = {
|
|
1435
|
-
pointerdown: "touchstart",
|
|
1436
|
-
pointermove: "touchmove",
|
|
1437
|
-
pointerup: "touchend",
|
|
1438
|
-
pointercancel: "touchcancel",
|
|
1439
|
-
};
|
|
1440
|
-
function getPointerEventName(name) {
|
|
1441
|
-
if (supportsPointerEvents()) {
|
|
1442
|
-
return name;
|
|
1443
|
-
}
|
|
1444
|
-
else if (supportsTouchEvents()) {
|
|
1445
|
-
return touchEventNames[name];
|
|
1446
|
-
}
|
|
1447
|
-
else if (supportsMouseEvents()) {
|
|
1448
|
-
return mouseEventNames[name];
|
|
1449
|
-
}
|
|
1450
|
-
return name;
|
|
1451
|
-
}
|
|
1452
1390
|
function addPointerEvent(target, eventName, handler, options) {
|
|
1453
|
-
return addDomEvent(target,
|
|
1391
|
+
return addDomEvent(target, eventName, wrapHandler(handler, eventName === "pointerdown"), options);
|
|
1454
1392
|
}
|
|
1455
1393
|
function usePointerEvent(ref, eventName, handler, options) {
|
|
1456
|
-
return useDomEvent(ref,
|
|
1394
|
+
return useDomEvent(ref, eventName, handler && wrapHandler(handler, eventName === "pointerdown"), options);
|
|
1457
1395
|
}
|
|
1458
1396
|
|
|
1459
1397
|
function createLock(name) {
|
|
@@ -1508,6 +1446,9 @@
|
|
|
1508
1446
|
return false;
|
|
1509
1447
|
}
|
|
1510
1448
|
|
|
1449
|
+
function isMouseEvent(event) {
|
|
1450
|
+
return event.type !== "pen" && event.type !== "touch";
|
|
1451
|
+
}
|
|
1511
1452
|
function createHoverEvent(visualElement, isActive, callback) {
|
|
1512
1453
|
return (event, info) => {
|
|
1513
1454
|
if (!isMouseEvent(event) || isDragActive())
|
|
@@ -2122,7 +2063,7 @@
|
|
|
2122
2063
|
* This will be replaced by the build step with the latest version number.
|
|
2123
2064
|
* When MotionValues are provided to motion components, warn if versions are mixed.
|
|
2124
2065
|
*/
|
|
2125
|
-
this.version = "
|
|
2066
|
+
this.version = "8.0.0";
|
|
2126
2067
|
/**
|
|
2127
2068
|
* Duration, in milliseconds, since last updating frame.
|
|
2128
2069
|
*
|
|
@@ -4644,11 +4585,6 @@
|
|
|
4644
4585
|
this.handlePointerMove = (event, info) => {
|
|
4645
4586
|
this.lastMoveEvent = event;
|
|
4646
4587
|
this.lastMoveEventInfo = transformPoint(info, this.transformPagePoint);
|
|
4647
|
-
// Because Safari doesn't trigger mouseup events when it's above a `<select>`
|
|
4648
|
-
if (isMouseEvent(event) && event.buttons === 0) {
|
|
4649
|
-
this.handlePointerUp(event, info);
|
|
4650
|
-
return;
|
|
4651
|
-
}
|
|
4652
4588
|
// Throttle mouse move event to once per frame
|
|
4653
4589
|
sync.update(this.updatePoint, true);
|
|
4654
4590
|
};
|
|
@@ -4662,7 +4598,7 @@
|
|
|
4662
4598
|
onSessionEnd && onSessionEnd(event, panInfo);
|
|
4663
4599
|
};
|
|
4664
4600
|
// If we have more than one touch, don't start detecting this gesture
|
|
4665
|
-
if (
|
|
4601
|
+
if (!isPrimaryPointer(event))
|
|
4666
4602
|
return;
|
|
4667
4603
|
this.handlers = handlers;
|
|
4668
4604
|
this.transformPagePoint = transformPagePoint;
|
|
@@ -5099,7 +5035,7 @@
|
|
|
5099
5035
|
/**
|
|
5100
5036
|
*
|
|
5101
5037
|
*/
|
|
5102
|
-
// let latestPointerEvent:
|
|
5038
|
+
// let latestPointerEvent: PointerEvent
|
|
5103
5039
|
class VisualElementDragControls {
|
|
5104
5040
|
constructor(visualElement) {
|
|
5105
5041
|
// This is a reference to the global drag gesture lock, ensuring only one component
|
|
@@ -5945,7 +5881,7 @@
|
|
|
5945
5881
|
* and warn against mismatches.
|
|
5946
5882
|
*/
|
|
5947
5883
|
{
|
|
5948
|
-
warnOnce(nextValue.version === "
|
|
5884
|
+
warnOnce(nextValue.version === "8.0.0", `Attempting to mix Framer Motion versions ${nextValue.version} with 8.0.0 may not work as expected.`);
|
|
5949
5885
|
}
|
|
5950
5886
|
}
|
|
5951
5887
|
else if (isMotionValue(prevValue)) {
|