framer-motion 12.4.11 → 12.4.12

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.
@@ -1,4 +1,4 @@
1
- import { capturePointer, isPrimaryPointer } from 'motion-dom';
1
+ import { isPrimaryPointer } from 'motion-dom';
2
2
  import { secondsToMilliseconds, millisecondsToSeconds } from 'motion-utils';
3
3
  import { addPointerEvent } from '../../events/add-pointer-event.mjs';
4
4
  import { extractEventInfo } from '../../events/event-info.mjs';
@@ -10,7 +10,7 @@ import { frame, cancelFrame, frameData } from '../../frameloop/frame.mjs';
10
10
  * @internal
11
11
  */
12
12
  class PanSession {
13
- constructor(event, handlers, { transformPagePoint, dragSnapToOrigin = false } = {}) {
13
+ constructor(event, handlers, { transformPagePoint, contextWindow, dragSnapToOrigin = false, } = {}) {
14
14
  /**
15
15
  * @internal
16
16
  */
@@ -27,6 +27,10 @@ class PanSession {
27
27
  * @internal
28
28
  */
29
29
  this.handlers = {};
30
+ /**
31
+ * @internal
32
+ */
33
+ this.contextWindow = window;
30
34
  this.updatePoint = () => {
31
35
  if (!(this.lastMoveEvent && this.lastMoveEventInfo))
32
36
  return;
@@ -49,32 +53,19 @@ class PanSession {
49
53
  onMove && onMove(this.lastMoveEvent, info);
50
54
  };
51
55
  this.handlePointerMove = (event, info) => {
52
- this.index = getElementIndex(event.currentTarget);
53
- if (event.target instanceof Element &&
54
- event.target.hasPointerCapture &&
55
- event.pointerId !== undefined) {
56
- try {
57
- if (!event.target.hasPointerCapture(event.pointerId)) {
58
- return;
59
- }
60
- }
61
- catch (e) { }
62
- }
63
56
  this.lastMoveEvent = event;
64
57
  this.lastMoveEventInfo = transformPoint(info, this.transformPagePoint);
65
58
  // Throttle mouse move event to once per frame
66
59
  frame.update(this.updatePoint, true);
67
60
  };
68
61
  this.handlePointerUp = (event, info) => {
69
- capturePointer(event, "release");
70
62
  this.end();
71
63
  const { onEnd, onSessionEnd, resumeAnimation } = this.handlers;
72
64
  if (this.dragSnapToOrigin)
73
65
  resumeAnimation && resumeAnimation();
74
66
  if (!(this.lastMoveEvent && this.lastMoveEventInfo))
75
67
  return;
76
- const panInfo = getPanInfo(event.type === "pointercancel" ||
77
- event.type === "lostpointercapture"
68
+ const panInfo = getPanInfo(event.type === "pointercancel"
78
69
  ? this.lastMoveEventInfo
79
70
  : transformPoint(info, this.transformPagePoint), this.history);
80
71
  if (this.startEvent && onEnd) {
@@ -88,6 +79,7 @@ class PanSession {
88
79
  this.dragSnapToOrigin = dragSnapToOrigin;
89
80
  this.handlers = handlers;
90
81
  this.transformPagePoint = transformPagePoint;
82
+ this.contextWindow = contextWindow || window;
91
83
  const info = extractEventInfo(event);
92
84
  const initialInfo = transformPoint(info, this.transformPagePoint);
93
85
  const { point } = initialInfo;
@@ -96,20 +88,7 @@ class PanSession {
96
88
  const { onSessionStart } = handlers;
97
89
  onSessionStart &&
98
90
  onSessionStart(event, getPanInfo(initialInfo, this.history));
99
- capturePointer(event, "set");
100
- this.removeListeners = pipe(addPointerEvent(event.currentTarget, "pointermove", this.handlePointerMove), addPointerEvent(event.currentTarget, "pointerup", this.handlePointerUp), addPointerEvent(event.currentTarget, "pointercancel", this.handlePointerUp), addPointerEvent(event.currentTarget, "lostpointercapture", (lostPointerEvent, lostPointerInfo) => {
101
- const index = getElementIndex(lostPointerEvent.currentTarget);
102
- /**
103
- * If the pointer has lost capture because it's moved in the DOM
104
- * then we need to re-capture it.
105
- */
106
- if (index !== this.index) {
107
- capturePointer(lostPointerEvent, "set");
108
- }
109
- else {
110
- this.handlePointerUp(lostPointerEvent, lostPointerInfo);
111
- }
112
- }));
91
+ this.removeListeners = pipe(addPointerEvent(this.contextWindow, "pointermove", this.handlePointerMove), addPointerEvent(this.contextWindow, "pointerup", this.handlePointerUp), addPointerEvent(this.contextWindow, "pointercancel", this.handlePointerUp));
113
92
  }
114
93
  updateHandlers(handlers) {
115
94
  this.handlers = handlers;
@@ -173,10 +152,5 @@ function getVelocity(history, timeDelta) {
173
152
  }
174
153
  return currentVelocity;
175
154
  }
176
- function getElementIndex(element) {
177
- if (!element.parentNode)
178
- return -1;
179
- return Array.from(element.parentNode.children).indexOf(element);
180
- }
181
155
 
182
156
  export { PanSession };
@@ -1,6 +1,7 @@
1
1
  import { noop } from 'motion-utils';
2
2
  import { addPointerEvent } from '../../events/add-pointer-event.mjs';
3
3
  import { Feature } from '../../motion/features/Feature.mjs';
4
+ import { getContextWindow } from '../../utils/get-context-window.mjs';
4
5
  import { PanSession } from './PanSession.mjs';
5
6
  import { frame } from '../../frameloop/frame.mjs';
6
7
 
@@ -17,6 +18,7 @@ class PanGesture extends Feature {
17
18
  onPointerDown(pointerDownEvent) {
18
19
  this.session = new PanSession(pointerDownEvent, this.createPanHandlers(), {
19
20
  transformPagePoint: this.node.getTransformPagePoint(),
21
+ contextWindow: getContextWindow(this.node),
20
22
  });
21
23
  }
22
24
  createPanHandlers() {
@@ -17,7 +17,7 @@ function updateMotionValuesFromProps(element, next, prev) {
17
17
  * and warn against mismatches.
18
18
  */
19
19
  if (process.env.NODE_ENV === "development") {
20
- warnOnce(nextValue.version === "12.4.11", `Attempting to mix Motion versions ${nextValue.version} with 12.4.11 may not work as expected.`);
20
+ warnOnce(nextValue.version === "12.4.12", `Attempting to mix Motion versions ${nextValue.version} with 12.4.12 may not work as expected.`);
21
21
  }
22
22
  }
23
23
  else if (isMotionValue(prevValue)) {
@@ -0,0 +1,6 @@
1
+ // Fixes https://github.com/motiondivision/motion/issues/2270
2
+ const getContextWindow = ({ current }) => {
3
+ return current ? current.ownerDocument.defaultView : null;
4
+ };
5
+
6
+ export { getContextWindow };
@@ -34,7 +34,7 @@ class MotionValue {
34
34
  * This will be replaced by the build step with the latest version number.
35
35
  * When MotionValues are provided to motion components, warn if versions are mixed.
36
36
  */
37
- this.version = "12.4.11";
37
+ this.version = "12.4.12";
38
38
  /**
39
39
  * Tracks whether this value can output a velocity. Currently this is only true
40
40
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -1106,7 +1106,7 @@
1106
1106
  * This will be replaced by the build step with the latest version number.
1107
1107
  * When MotionValues are provided to motion components, warn if versions are mixed.
1108
1108
  */
1109
- this.version = "12.4.11";
1109
+ this.version = "12.4.12";
1110
1110
  /**
1111
1111
  * Tracks whether this value can output a velocity. Currently this is only true
1112
1112
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -5965,7 +5965,7 @@
5965
5965
  * and warn against mismatches.
5966
5966
  */
5967
5967
  {
5968
- warnOnce(nextValue.version === "12.4.11", `Attempting to mix Motion versions ${nextValue.version} with 12.4.11 may not work as expected.`);
5968
+ warnOnce(nextValue.version === "12.4.12", `Attempting to mix Motion versions ${nextValue.version} with 12.4.12 may not work as expected.`);
5969
5969
  }
5970
5970
  }
5971
5971
  else if (isMotionValue(prevValue)) {
@@ -10291,6 +10291,11 @@
10291
10291
  });
10292
10292
  }
10293
10293
 
10294
+ // Fixes https://github.com/motiondivision/motion/issues/2270
10295
+ const getContextWindow = ({ current }) => {
10296
+ return current ? current.ownerDocument.defaultView : null;
10297
+ };
10298
+
10294
10299
  function isRefObject(ref) {
10295
10300
  return (ref &&
10296
10301
  typeof ref === "object" &&
@@ -10301,7 +10306,7 @@
10301
10306
  * @internal
10302
10307
  */
10303
10308
  class PanSession {
10304
- constructor(event, handlers, { transformPagePoint, dragSnapToOrigin = false } = {}) {
10309
+ constructor(event, handlers, { transformPagePoint, contextWindow, dragSnapToOrigin = false, } = {}) {
10305
10310
  /**
10306
10311
  * @internal
10307
10312
  */
@@ -10318,6 +10323,10 @@
10318
10323
  * @internal
10319
10324
  */
10320
10325
  this.handlers = {};
10326
+ /**
10327
+ * @internal
10328
+ */
10329
+ this.contextWindow = window;
10321
10330
  this.updatePoint = () => {
10322
10331
  if (!(this.lastMoveEvent && this.lastMoveEventInfo))
10323
10332
  return;
@@ -10340,32 +10349,19 @@
10340
10349
  onMove && onMove(this.lastMoveEvent, info);
10341
10350
  };
10342
10351
  this.handlePointerMove = (event, info) => {
10343
- this.index = getElementIndex(event.currentTarget);
10344
- if (event.target instanceof Element &&
10345
- event.target.hasPointerCapture &&
10346
- event.pointerId !== undefined) {
10347
- try {
10348
- if (!event.target.hasPointerCapture(event.pointerId)) {
10349
- return;
10350
- }
10351
- }
10352
- catch (e) { }
10353
- }
10354
10352
  this.lastMoveEvent = event;
10355
10353
  this.lastMoveEventInfo = transformPoint(info, this.transformPagePoint);
10356
10354
  // Throttle mouse move event to once per frame
10357
10355
  frame.update(this.updatePoint, true);
10358
10356
  };
10359
10357
  this.handlePointerUp = (event, info) => {
10360
- capturePointer(event, "release");
10361
10358
  this.end();
10362
10359
  const { onEnd, onSessionEnd, resumeAnimation } = this.handlers;
10363
10360
  if (this.dragSnapToOrigin)
10364
10361
  resumeAnimation && resumeAnimation();
10365
10362
  if (!(this.lastMoveEvent && this.lastMoveEventInfo))
10366
10363
  return;
10367
- const panInfo = getPanInfo(event.type === "pointercancel" ||
10368
- event.type === "lostpointercapture"
10364
+ const panInfo = getPanInfo(event.type === "pointercancel"
10369
10365
  ? this.lastMoveEventInfo
10370
10366
  : transformPoint(info, this.transformPagePoint), this.history);
10371
10367
  if (this.startEvent && onEnd) {
@@ -10379,6 +10375,7 @@
10379
10375
  this.dragSnapToOrigin = dragSnapToOrigin;
10380
10376
  this.handlers = handlers;
10381
10377
  this.transformPagePoint = transformPagePoint;
10378
+ this.contextWindow = contextWindow || window;
10382
10379
  const info = extractEventInfo(event);
10383
10380
  const initialInfo = transformPoint(info, this.transformPagePoint);
10384
10381
  const { point } = initialInfo;
@@ -10387,20 +10384,7 @@
10387
10384
  const { onSessionStart } = handlers;
10388
10385
  onSessionStart &&
10389
10386
  onSessionStart(event, getPanInfo(initialInfo, this.history));
10390
- capturePointer(event, "set");
10391
- this.removeListeners = pipe(addPointerEvent(event.currentTarget, "pointermove", this.handlePointerMove), addPointerEvent(event.currentTarget, "pointerup", this.handlePointerUp), addPointerEvent(event.currentTarget, "pointercancel", this.handlePointerUp), addPointerEvent(event.currentTarget, "lostpointercapture", (lostPointerEvent, lostPointerInfo) => {
10392
- const index = getElementIndex(lostPointerEvent.currentTarget);
10393
- /**
10394
- * If the pointer has lost capture because it's moved in the DOM
10395
- * then we need to re-capture it.
10396
- */
10397
- if (index !== this.index) {
10398
- capturePointer(lostPointerEvent, "set");
10399
- }
10400
- else {
10401
- this.handlePointerUp(lostPointerEvent, lostPointerInfo);
10402
- }
10403
- }));
10387
+ this.removeListeners = pipe(addPointerEvent(this.contextWindow, "pointermove", this.handlePointerMove), addPointerEvent(this.contextWindow, "pointerup", this.handlePointerUp), addPointerEvent(this.contextWindow, "pointercancel", this.handlePointerUp));
10404
10388
  }
10405
10389
  updateHandlers(handlers) {
10406
10390
  this.handlers = handlers;
@@ -10464,11 +10448,6 @@
10464
10448
  }
10465
10449
  return currentVelocity;
10466
10450
  }
10467
- function getElementIndex(element) {
10468
- if (!element.parentNode)
10469
- return -1;
10470
- return Array.from(element.parentNode.children).indexOf(element);
10471
- }
10472
10451
 
10473
10452
  /**
10474
10453
  * Apply constraints to a point. These constraints are both physical along an
@@ -10725,6 +10704,7 @@
10725
10704
  }, {
10726
10705
  transformPagePoint: this.visualElement.getTransformPagePoint(),
10727
10706
  dragSnapToOrigin,
10707
+ contextWindow: getContextWindow(this.visualElement),
10728
10708
  });
10729
10709
  }
10730
10710
  stop(event, info) {
@@ -11090,6 +11070,7 @@
11090
11070
  onPointerDown(pointerDownEvent) {
11091
11071
  this.session = new PanSession(pointerDownEvent, this.createPanHandlers(), {
11092
11072
  transformPagePoint: this.node.getTransformPagePoint(),
11073
+ contextWindow: getContextWindow(this.node),
11093
11074
  });
11094
11075
  }
11095
11076
  createPanHandlers() {