framer-motion 6.3.5 → 6.3.7

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 CHANGED
@@ -470,6 +470,11 @@ var MotionValue = /** @class */ (function () {
470
470
  */
471
471
  function MotionValue(init) {
472
472
  var _this = this;
473
+ /**
474
+ * This will be replaced by the build step with the latest version number.
475
+ * When MotionValues are provided to motion components, warn if versions are mixed.
476
+ */
477
+ this.version = "6.3.7";
473
478
  /**
474
479
  * Duration, in milliseconds, since last updating frame.
475
480
  *
@@ -3884,8 +3889,9 @@ exports.AnimationType = void 0;
3884
3889
  })(exports.AnimationType || (exports.AnimationType = {}));
3885
3890
 
3886
3891
  function addDomEvent(target, eventName, handler, options) {
3892
+ if (options === void 0) { options = { passive: true }; }
3887
3893
  target.addEventListener(eventName, handler, options);
3888
- return function () { return target.removeEventListener(eventName, handler, options); };
3894
+ return function () { return target.removeEventListener(eventName, handler); };
3889
3895
  }
3890
3896
  /**
3891
3897
  * Attaches an event listener directly to the provided DOM element.
@@ -4112,10 +4118,10 @@ function useHoverGesture(_a) {
4112
4118
  var onHoverStart = _a.onHoverStart, onHoverEnd = _a.onHoverEnd, whileHover = _a.whileHover, visualElement = _a.visualElement;
4113
4119
  usePointerEvent(visualElement, "pointerenter", onHoverStart || whileHover
4114
4120
  ? createHoverEvent(visualElement, true, onHoverStart)
4115
- : undefined);
4121
+ : undefined, { passive: !onHoverStart });
4116
4122
  usePointerEvent(visualElement, "pointerleave", onHoverEnd || whileHover
4117
4123
  ? createHoverEvent(visualElement, false, onHoverEnd)
4118
- : undefined);
4124
+ : undefined, { passive: !onHoverEnd });
4119
4125
  }
4120
4126
 
4121
4127
  /**
@@ -4150,6 +4156,12 @@ function useTapGesture(_a) {
4150
4156
  var hasPressListeners = onTap || onTapStart || onTapCancel || whileTap;
4151
4157
  var isPressing = React.useRef(false);
4152
4158
  var cancelPointerEndListeners = React.useRef(null);
4159
+ /**
4160
+ * Only set listener to passive if there are no external listeners.
4161
+ */
4162
+ var eventOptions = {
4163
+ passive: !(onTapStart || onTap || onTapCancel || onPointerDown),
4164
+ };
4153
4165
  function removePointerEndListener() {
4154
4166
  var _a;
4155
4167
  (_a = cancelPointerEndListeners.current) === null || _a === void 0 ? void 0 : _a.call(cancelPointerEndListeners);
@@ -4184,14 +4196,14 @@ function useTapGesture(_a) {
4184
4196
  if (isPressing.current)
4185
4197
  return;
4186
4198
  isPressing.current = true;
4187
- cancelPointerEndListeners.current = popmotion.pipe(addPointerEvent(window, "pointerup", onPointerUp), addPointerEvent(window, "pointercancel", onPointerCancel));
4199
+ cancelPointerEndListeners.current = popmotion.pipe(addPointerEvent(window, "pointerup", onPointerUp, eventOptions), addPointerEvent(window, "pointercancel", onPointerCancel, eventOptions));
4188
4200
  /**
4189
4201
  * Ensure we trigger animations before firing event callback
4190
4202
  */
4191
4203
  (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(exports.AnimationType.Tap, true);
4192
4204
  onTapStart === null || onTapStart === void 0 ? void 0 : onTapStart(event, info);
4193
4205
  }
4194
- usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined);
4206
+ usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined, eventOptions);
4195
4207
  useUnmountEffect(removePointerEndListener);
4196
4208
  }
4197
4209
 
@@ -5783,7 +5795,7 @@ var VisualElementDragControls = /** @class */ (function () {
5783
5795
  * constraints as the window resizes.
5784
5796
  */
5785
5797
  var stopResizeListener = addDomEvent(window, "resize", function () {
5786
- _this.scalePositionWithinConstraints();
5798
+ return _this.scalePositionWithinConstraints();
5787
5799
  });
5788
5800
  /**
5789
5801
  * If the element's layout changes, calculate the delta and apply that to
@@ -5955,6 +5967,13 @@ function updateMotionValuesFromProps(element, next, prev) {
5955
5967
  * to our visual element's motion value map.
5956
5968
  */
5957
5969
  element.addValue(key, nextValue);
5970
+ /**
5971
+ * Check the version of the incoming motion value with this version
5972
+ * and warn against mismatches.
5973
+ */
5974
+ if (process.env.NODE_ENV === "development") {
5975
+ warnOnce(nextValue.version !== "6.3.7", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.3.7 may not work as expected."));
5976
+ }
5958
5977
  }
5959
5978
  else if (isMotionValue(prevValue)) {
5960
5979
  /**
@@ -7056,10 +7075,7 @@ var layoutFeatures = {
7056
7075
  };
7057
7076
 
7058
7077
  var DocumentProjectionNode = createProjectionNode({
7059
- attachResizeListener: function (ref, notify) {
7060
- ref.addEventListener("resize", notify, { passive: true });
7061
- return function () { return ref.removeEventListener("resize", notify); };
7062
- },
7078
+ attachResizeListener: function (ref, notify) { return addDomEvent(ref, "resize", notify); },
7063
7079
  measureScroll: function () { return ({
7064
7080
  x: document.documentElement.scrollLeft || document.body.scrollLeft,
7065
7081
  y: document.documentElement.scrollTop || document.body.scrollTop,
@@ -7915,7 +7931,7 @@ function useElementScroll(ref) {
7915
7931
  if (!element)
7916
7932
  return;
7917
7933
  var updateScrollValues = createScrollUpdater(values, getElementScrollOffsets(element));
7918
- var scrollListener = addDomEvent(element, "scroll", updateScrollValues, { passive: true });
7934
+ var scrollListener = addDomEvent(element, "scroll", updateScrollValues);
7919
7935
  var resizeListener = addDomEvent(element, "resize", updateScrollValues);
7920
7936
  return function () {
7921
7937
  scrollListener && scrollListener();
@@ -7938,7 +7954,7 @@ var hasListeners = false;
7938
7954
  function addEventListeners() {
7939
7955
  hasListeners = true;
7940
7956
  var updateScrollValues = createScrollUpdater(viewportScrollValues, getViewportScrollOffsets);
7941
- addDomEvent(window, "scroll", updateScrollValues, { passive: true });
7957
+ addDomEvent(window, "scroll", updateScrollValues);
7942
7958
  addDomEvent(window, "resize", updateScrollValues);
7943
7959
  }
7944
7960
  /**
@@ -1,8 +1,9 @@
1
1
  import { useEffect } from 'react';
2
2
 
3
3
  function addDomEvent(target, eventName, handler, options) {
4
+ if (options === void 0) { options = { passive: true }; }
4
5
  target.addEventListener(eventName, handler, options);
5
- return function () { return target.removeEventListener(eventName, handler, options); };
6
+ return function () { return target.removeEventListener(eventName, handler); };
6
7
  }
7
8
  /**
8
9
  * Attaches an event listener directly to the provided DOM element.
@@ -388,7 +388,7 @@ var VisualElementDragControls = /** @class */ (function () {
388
388
  * constraints as the window resizes.
389
389
  */
390
390
  var stopResizeListener = addDomEvent(window, "resize", function () {
391
- _this.scalePositionWithinConstraints();
391
+ return _this.scalePositionWithinConstraints();
392
392
  });
393
393
  /**
394
394
  * If the element's layout changes, calculate the delta and apply that to
@@ -19,10 +19,10 @@ function useHoverGesture(_a) {
19
19
  var onHoverStart = _a.onHoverStart, onHoverEnd = _a.onHoverEnd, whileHover = _a.whileHover, visualElement = _a.visualElement;
20
20
  usePointerEvent(visualElement, "pointerenter", onHoverStart || whileHover
21
21
  ? createHoverEvent(visualElement, true, onHoverStart)
22
- : undefined);
22
+ : undefined, { passive: !onHoverStart });
23
23
  usePointerEvent(visualElement, "pointerleave", onHoverEnd || whileHover
24
24
  ? createHoverEvent(visualElement, false, onHoverEnd)
25
- : undefined);
25
+ : undefined, { passive: !onHoverEnd });
26
26
  }
27
27
 
28
28
  export { useHoverGesture };
@@ -15,6 +15,12 @@ function useTapGesture(_a) {
15
15
  var hasPressListeners = onTap || onTapStart || onTapCancel || whileTap;
16
16
  var isPressing = useRef(false);
17
17
  var cancelPointerEndListeners = useRef(null);
18
+ /**
19
+ * Only set listener to passive if there are no external listeners.
20
+ */
21
+ var eventOptions = {
22
+ passive: !(onTapStart || onTap || onTapCancel || onPointerDown),
23
+ };
18
24
  function removePointerEndListener() {
19
25
  var _a;
20
26
  (_a = cancelPointerEndListeners.current) === null || _a === void 0 ? void 0 : _a.call(cancelPointerEndListeners);
@@ -49,14 +55,14 @@ function useTapGesture(_a) {
49
55
  if (isPressing.current)
50
56
  return;
51
57
  isPressing.current = true;
52
- cancelPointerEndListeners.current = pipe(addPointerEvent(window, "pointerup", onPointerUp), addPointerEvent(window, "pointercancel", onPointerCancel));
58
+ cancelPointerEndListeners.current = pipe(addPointerEvent(window, "pointerup", onPointerUp, eventOptions), addPointerEvent(window, "pointercancel", onPointerCancel, eventOptions));
53
59
  /**
54
60
  * Ensure we trigger animations before firing event callback
55
61
  */
56
62
  (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(AnimationType.Tap, true);
57
63
  onTapStart === null || onTapStart === void 0 ? void 0 : onTapStart(event, info);
58
64
  }
59
- usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined);
65
+ usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined, eventOptions);
60
66
  useUnmountEffect(removePointerEndListener);
61
67
  }
62
68
 
@@ -1,10 +1,8 @@
1
1
  import { createProjectionNode } from './create-projection-node.mjs';
2
+ import { addDomEvent } from '../../events/use-dom-event.mjs';
2
3
 
3
4
  var DocumentProjectionNode = createProjectionNode({
4
- attachResizeListener: function (ref, notify) {
5
- ref.addEventListener("resize", notify, { passive: true });
6
- return function () { return ref.removeEventListener("resize", notify); };
7
- },
5
+ attachResizeListener: function (ref, notify) { return addDomEvent(ref, "resize", notify); },
8
6
  measureScroll: function () { return ({
9
7
  x: document.documentElement.scrollLeft || document.body.scrollLeft,
10
8
  y: document.documentElement.scrollTop || document.body.scrollTop,
@@ -1,3 +1,4 @@
1
+ import { warnOnce } from '../../utils/warn-once.mjs';
1
2
  import { motionValue } from '../../value/index.mjs';
2
3
  import { isMotionValue } from '../../value/utils/is-motion-value.mjs';
3
4
 
@@ -12,6 +13,13 @@ function updateMotionValuesFromProps(element, next, prev) {
12
13
  * to our visual element's motion value map.
13
14
  */
14
15
  element.addValue(key, nextValue);
16
+ /**
17
+ * Check the version of the incoming motion value with this version
18
+ * and warn against mismatches.
19
+ */
20
+ if (process.env.NODE_ENV === "development") {
21
+ warnOnce(nextValue.version !== "6.3.7", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.3.7 may not work as expected."));
22
+ }
15
23
  }
16
24
  else if (isMotionValue(prevValue)) {
17
25
  /**
@@ -21,6 +21,11 @@ var MotionValue = /** @class */ (function () {
21
21
  */
22
22
  function MotionValue(init) {
23
23
  var _this = this;
24
+ /**
25
+ * This will be replaced by the build step with the latest version number.
26
+ * When MotionValues are provided to motion components, warn if versions are mixed.
27
+ */
28
+ this.version = "6.3.7";
24
29
  /**
25
30
  * Duration, in milliseconds, since last updating frame.
26
31
  *
@@ -45,7 +45,7 @@ function useElementScroll(ref) {
45
45
  if (!element)
46
46
  return;
47
47
  var updateScrollValues = createScrollUpdater(values, getElementScrollOffsets(element));
48
- var scrollListener = addDomEvent(element, "scroll", updateScrollValues, { passive: true });
48
+ var scrollListener = addDomEvent(element, "scroll", updateScrollValues);
49
49
  var resizeListener = addDomEvent(element, "resize", updateScrollValues);
50
50
  return function () {
51
51
  scrollListener && scrollListener();
@@ -15,7 +15,7 @@ var hasListeners = false;
15
15
  function addEventListeners() {
16
16
  hasListeners = true;
17
17
  var updateScrollValues = createScrollUpdater(viewportScrollValues, getViewportScrollOffsets);
18
- addDomEvent(window, "scroll", updateScrollValues, { passive: true });
18
+ addDomEvent(window, "scroll", updateScrollValues);
19
19
  addDomEvent(window, "resize", updateScrollValues);
20
20
  }
21
21
  /**
@@ -1695,6 +1695,11 @@
1695
1695
  */
1696
1696
  function MotionValue(init) {
1697
1697
  var _this = this;
1698
+ /**
1699
+ * This will be replaced by the build step with the latest version number.
1700
+ * When MotionValues are provided to motion components, warn if versions are mixed.
1701
+ */
1702
+ this.version = "6.3.7";
1698
1703
  /**
1699
1704
  * Duration, in milliseconds, since last updating frame.
1700
1705
  *
@@ -5109,8 +5114,9 @@
5109
5114
  })(exports.AnimationType || (exports.AnimationType = {}));
5110
5115
 
5111
5116
  function addDomEvent(target, eventName, handler, options) {
5117
+ if (options === void 0) { options = { passive: true }; }
5112
5118
  target.addEventListener(eventName, handler, options);
5113
- return function () { return target.removeEventListener(eventName, handler, options); };
5119
+ return function () { return target.removeEventListener(eventName, handler); };
5114
5120
  }
5115
5121
  /**
5116
5122
  * Attaches an event listener directly to the provided DOM element.
@@ -5337,10 +5343,10 @@
5337
5343
  var onHoverStart = _a.onHoverStart, onHoverEnd = _a.onHoverEnd, whileHover = _a.whileHover, visualElement = _a.visualElement;
5338
5344
  usePointerEvent(visualElement, "pointerenter", onHoverStart || whileHover
5339
5345
  ? createHoverEvent(visualElement, true, onHoverStart)
5340
- : undefined);
5346
+ : undefined, { passive: !onHoverStart });
5341
5347
  usePointerEvent(visualElement, "pointerleave", onHoverEnd || whileHover
5342
5348
  ? createHoverEvent(visualElement, false, onHoverEnd)
5343
- : undefined);
5349
+ : undefined, { passive: !onHoverEnd });
5344
5350
  }
5345
5351
 
5346
5352
  /**
@@ -5375,6 +5381,12 @@
5375
5381
  var hasPressListeners = onTap || onTapStart || onTapCancel || whileTap;
5376
5382
  var isPressing = React.useRef(false);
5377
5383
  var cancelPointerEndListeners = React.useRef(null);
5384
+ /**
5385
+ * Only set listener to passive if there are no external listeners.
5386
+ */
5387
+ var eventOptions = {
5388
+ passive: !(onTapStart || onTap || onTapCancel || onPointerDown),
5389
+ };
5378
5390
  function removePointerEndListener() {
5379
5391
  var _a;
5380
5392
  (_a = cancelPointerEndListeners.current) === null || _a === void 0 ? void 0 : _a.call(cancelPointerEndListeners);
@@ -5409,14 +5421,14 @@
5409
5421
  if (isPressing.current)
5410
5422
  return;
5411
5423
  isPressing.current = true;
5412
- cancelPointerEndListeners.current = pipe(addPointerEvent(window, "pointerup", onPointerUp), addPointerEvent(window, "pointercancel", onPointerCancel));
5424
+ cancelPointerEndListeners.current = pipe(addPointerEvent(window, "pointerup", onPointerUp, eventOptions), addPointerEvent(window, "pointercancel", onPointerCancel, eventOptions));
5413
5425
  /**
5414
5426
  * Ensure we trigger animations before firing event callback
5415
5427
  */
5416
5428
  (_a = visualElement.animationState) === null || _a === void 0 ? void 0 : _a.setActive(exports.AnimationType.Tap, true);
5417
5429
  onTapStart === null || onTapStart === void 0 ? void 0 : onTapStart(event, info);
5418
5430
  }
5419
- usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined);
5431
+ usePointerEvent(visualElement, "pointerdown", hasPressListeners ? onPointerDown : undefined, eventOptions);
5420
5432
  useUnmountEffect(removePointerEndListener);
5421
5433
  }
5422
5434
 
@@ -7008,7 +7020,7 @@
7008
7020
  * constraints as the window resizes.
7009
7021
  */
7010
7022
  var stopResizeListener = addDomEvent(window, "resize", function () {
7011
- _this.scalePositionWithinConstraints();
7023
+ return _this.scalePositionWithinConstraints();
7012
7024
  });
7013
7025
  /**
7014
7026
  * If the element's layout changes, calculate the delta and apply that to
@@ -7180,6 +7192,13 @@
7180
7192
  * to our visual element's motion value map.
7181
7193
  */
7182
7194
  element.addValue(key, nextValue);
7195
+ /**
7196
+ * Check the version of the incoming motion value with this version
7197
+ * and warn against mismatches.
7198
+ */
7199
+ {
7200
+ warnOnce(nextValue.version !== "6.3.7", "Attempting to mix Framer Motion versions ".concat(nextValue.version, " with 6.3.7 may not work as expected."));
7201
+ }
7183
7202
  }
7184
7203
  else if (isMotionValue(prevValue)) {
7185
7204
  /**
@@ -8281,10 +8300,7 @@
8281
8300
  };
8282
8301
 
8283
8302
  var DocumentProjectionNode = createProjectionNode({
8284
- attachResizeListener: function (ref, notify) {
8285
- ref.addEventListener("resize", notify, { passive: true });
8286
- return function () { return ref.removeEventListener("resize", notify); };
8287
- },
8303
+ attachResizeListener: function (ref, notify) { return addDomEvent(ref, "resize", notify); },
8288
8304
  measureScroll: function () { return ({
8289
8305
  x: document.documentElement.scrollLeft || document.body.scrollLeft,
8290
8306
  y: document.documentElement.scrollTop || document.body.scrollTop,
@@ -9139,7 +9155,7 @@
9139
9155
  if (!element)
9140
9156
  return;
9141
9157
  var updateScrollValues = createScrollUpdater(values, getElementScrollOffsets(element));
9142
- var scrollListener = addDomEvent(element, "scroll", updateScrollValues, { passive: true });
9158
+ var scrollListener = addDomEvent(element, "scroll", updateScrollValues);
9143
9159
  var resizeListener = addDomEvent(element, "resize", updateScrollValues);
9144
9160
  return function () {
9145
9161
  scrollListener && scrollListener();
@@ -9162,7 +9178,7 @@
9162
9178
  function addEventListeners() {
9163
9179
  hasListeners = true;
9164
9180
  var updateScrollValues = createScrollUpdater(viewportScrollValues, getViewportScrollOffsets);
9165
- addDomEvent(window, "scroll", updateScrollValues, { passive: true });
9181
+ addDomEvent(window, "scroll", updateScrollValues);
9166
9182
  addDomEvent(window, "resize", updateScrollValues);
9167
9183
  }
9168
9184
  /**