framer-motion 11.13.5 → 11.14.1

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/README.md CHANGED
@@ -15,9 +15,6 @@
15
15
  <a href="https://twitter.com/motiondotdev" target="_blank">
16
16
  <img src="https://img.shields.io/twitter/follow/framer.svg?style=social&label=Follow" />
17
17
  </a>
18
- <a href="https://discord.gg/DfkSpYe" target="_blank">
19
- <img src="https://img.shields.io/discord/308323056592486420.svg?logo=discord&logoColor=white" alt="Chat on Discord">
20
- </a>
21
18
  </p>
22
19
 
23
20
  <br>
@@ -73,7 +70,7 @@ export function Component({ isVisible }) {
73
70
 
74
71
  ### 💎 Contribute
75
72
 
76
- - Want to contribute to Motion? Our [contributing guide](https://github.com/framer/motion/blob/master/CONTRIBUTING.md) has you covered.
73
+ - Want to contribute to Motion? Our [contributing guide](https://github.com/motiondivision/motion/blob/master/CONTRIBUTING.md) has you covered.
77
74
 
78
75
  ### 👩🏻‍⚖️ License
79
76
 
@@ -3333,7 +3333,7 @@ class MotionValue {
3333
3333
  * This will be replaced by the build step with the latest version number.
3334
3334
  * When MotionValues are provided to motion components, warn if versions are mixed.
3335
3335
  */
3336
- this.version = "11.13.5";
3336
+ this.version = "11.14.1";
3337
3337
  /**
3338
3338
  * Tracks whether this value can output a velocity. Currently this is only true
3339
3339
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -4239,23 +4239,6 @@ const animations = {
4239
4239
  },
4240
4240
  };
4241
4241
 
4242
- const isPrimaryPointer = (event) => {
4243
- if (event.pointerType === "mouse") {
4244
- return typeof event.button !== "number" || event.button <= 0;
4245
- }
4246
- else {
4247
- /**
4248
- * isPrimary is true for all mice buttons, whereas every touch point
4249
- * is regarded as its own input. So subsequent concurrent touch points
4250
- * will be false.
4251
- *
4252
- * Specifically match against false here as incomplete versions of
4253
- * PointerEvents in very old browser might have it set as undefined.
4254
- */
4255
- return event.isPrimary !== false;
4256
- }
4257
- };
4258
-
4259
4242
  function extractEventInfo(event) {
4260
4243
  return {
4261
4244
  point: {
@@ -4265,7 +4248,7 @@ function extractEventInfo(event) {
4265
4248
  };
4266
4249
  }
4267
4250
  const addPointerInfo = (handler) => {
4268
- return (event) => isPrimaryPointer(event) && handler(event, extractEventInfo(event));
4251
+ return (event) => motionDom.isPrimaryPointer(event) && handler(event, extractEventInfo(event));
4269
4252
  };
4270
4253
 
4271
4254
  function addDomEvent(target, eventName, handler, options = { passive: true }) {
@@ -4289,7 +4272,7 @@ function distance2D(a, b) {
4289
4272
  * @internal
4290
4273
  */
4291
4274
  class PanSession {
4292
- constructor(event, handlers, { transformPagePoint, contextWindow, dragSnapToOrigin = false } = {}) {
4275
+ constructor(event, handlers, { transformPagePoint, contextWindow, dragSnapToOrigin = false, } = {}) {
4293
4276
  /**
4294
4277
  * @internal
4295
4278
  */
@@ -4353,7 +4336,7 @@ class PanSession {
4353
4336
  onSessionEnd && onSessionEnd(event, panInfo);
4354
4337
  };
4355
4338
  // If we have more than one touch, don't start detecting this gesture
4356
- if (!isPrimaryPointer(event))
4339
+ if (!motionDom.isPrimaryPointer(event))
4357
4340
  return;
4358
4341
  this.dragSnapToOrigin = dragSnapToOrigin;
4359
4342
  this.handlers = handlers;
@@ -4815,7 +4798,7 @@ function measurePageBox(element, rootProjectionNode, transformPagePoint) {
4815
4798
  return viewportBox;
4816
4799
  }
4817
4800
 
4818
- // Fixes https://github.com/framer/motion/issues/2270
4801
+ // Fixes https://github.com/motiondivision/motion/issues/2270
4819
4802
  const getContextWindow = ({ current }) => {
4820
4803
  return current ? current.ownerDocument.defaultView : null;
4821
4804
  };
@@ -5857,7 +5840,7 @@ function updateMotionValuesFromProps(element, next, prev) {
5857
5840
  * and warn against mismatches.
5858
5841
  */
5859
5842
  if (process.env.NODE_ENV === "development") {
5860
- warnOnce(nextValue.version === "11.13.5", `Attempting to mix Motion versions ${nextValue.version} with 11.13.5 may not work as expected.`);
5843
+ warnOnce(nextValue.version === "11.14.1", `Attempting to mix Motion versions ${nextValue.version} with 11.14.1 may not work as expected.`);
5861
5844
  }
5862
5845
  }
5863
5846
  else if (isMotionValue(prevValue)) {
@@ -8653,142 +8636,28 @@ class FocusGesture extends Feature {
8653
8636
  unmount() { }
8654
8637
  }
8655
8638
 
8656
- /**
8657
- * Recursively traverse up the tree to check whether the provided child node
8658
- * is the parent or a descendant of it.
8659
- *
8660
- * @param parent - Element to find
8661
- * @param child - Element to test against parent
8662
- */
8663
- const isNodeOrChild = (parent, child) => {
8664
- if (!child) {
8665
- return false;
8666
- }
8667
- else if (parent === child) {
8668
- return true;
8639
+ function handlePressEvent(node, event, lifecycle) {
8640
+ const { props } = node;
8641
+ if (node.animationState && props.whileTap) {
8642
+ node.animationState.setActive("whileTap", lifecycle === "Start");
8669
8643
  }
8670
- else {
8671
- return isNodeOrChild(parent, child.parentElement);
8644
+ const eventName = ("onTap" + (lifecycle === "End" ? "" : lifecycle));
8645
+ const callback = props[eventName];
8646
+ if (callback) {
8647
+ frame.postRender(() => callback(event, extractEventInfo(event)));
8672
8648
  }
8673
- };
8674
-
8675
- function fireSyntheticPointerEvent(name, handler) {
8676
- if (!handler)
8677
- return;
8678
- const syntheticPointerEvent = new PointerEvent("pointer" + name);
8679
- handler(syntheticPointerEvent, extractEventInfo(syntheticPointerEvent));
8680
8649
  }
8681
8650
  class PressGesture extends Feature {
8682
- constructor() {
8683
- super(...arguments);
8684
- this.removeStartListeners = motionUtils.noop;
8685
- this.removeEndListeners = motionUtils.noop;
8686
- this.removeAccessibleListeners = motionUtils.noop;
8687
- this.startPointerPress = (startEvent, startInfo) => {
8688
- if (this.isPressing)
8689
- return;
8690
- this.removeEndListeners();
8691
- const props = this.node.getProps();
8692
- const endPointerPress = (endEvent, endInfo) => {
8693
- if (!this.checkPressEnd())
8694
- return;
8695
- const { onTap, onTapCancel, globalTapTarget } = this.node.getProps();
8696
- /**
8697
- * We only count this as a tap gesture if the event.target is the same
8698
- * as, or a child of, this component's element
8699
- */
8700
- const handler = !globalTapTarget &&
8701
- !isNodeOrChild(this.node.current, endEvent.target)
8702
- ? onTapCancel
8703
- : onTap;
8704
- if (handler) {
8705
- frame.update(() => handler(endEvent, endInfo));
8706
- }
8707
- };
8708
- const removePointerUpListener = addPointerEvent(window, "pointerup", endPointerPress, {
8709
- passive: !(props.onTap || props["onPointerUp"]),
8710
- });
8711
- const removePointerCancelListener = addPointerEvent(window, "pointercancel", (cancelEvent, cancelInfo) => this.cancelPress(cancelEvent, cancelInfo), {
8712
- passive: !(props.onTapCancel ||
8713
- props["onPointerCancel"]),
8714
- });
8715
- this.removeEndListeners = pipe(removePointerUpListener, removePointerCancelListener);
8716
- this.startPress(startEvent, startInfo);
8717
- };
8718
- this.startAccessiblePress = () => {
8719
- const handleKeydown = (keydownEvent) => {
8720
- if (keydownEvent.key !== "Enter" || this.isPressing)
8721
- return;
8722
- const handleKeyup = (keyupEvent) => {
8723
- if (keyupEvent.key !== "Enter" || !this.checkPressEnd())
8724
- return;
8725
- fireSyntheticPointerEvent("up", (event, info) => {
8726
- const { onTap } = this.node.getProps();
8727
- if (onTap) {
8728
- frame.postRender(() => onTap(event, info));
8729
- }
8730
- });
8731
- };
8732
- this.removeEndListeners();
8733
- this.removeEndListeners = addDomEvent(this.node.current, "keyup", handleKeyup);
8734
- fireSyntheticPointerEvent("down", (event, info) => {
8735
- this.startPress(event, info);
8736
- });
8737
- };
8738
- const removeKeydownListener = addDomEvent(this.node.current, "keydown", handleKeydown);
8739
- const handleBlur = () => {
8740
- if (!this.isPressing)
8741
- return;
8742
- fireSyntheticPointerEvent("cancel", (cancelEvent, cancelInfo) => this.cancelPress(cancelEvent, cancelInfo));
8743
- };
8744
- const removeBlurListener = addDomEvent(this.node.current, "blur", handleBlur);
8745
- this.removeAccessibleListeners = pipe(removeKeydownListener, removeBlurListener);
8746
- };
8747
- }
8748
- startPress(event, info) {
8749
- this.isPressing = true;
8750
- const { onTapStart, whileTap } = this.node.getProps();
8751
- /**
8752
- * Ensure we trigger animations before firing event callback
8753
- */
8754
- if (whileTap && this.node.animationState) {
8755
- this.node.animationState.setActive("whileTap", true);
8756
- }
8757
- if (onTapStart) {
8758
- frame.postRender(() => onTapStart(event, info));
8759
- }
8760
- }
8761
- checkPressEnd() {
8762
- this.removeEndListeners();
8763
- this.isPressing = false;
8764
- const props = this.node.getProps();
8765
- if (props.whileTap && this.node.animationState) {
8766
- this.node.animationState.setActive("whileTap", false);
8767
- }
8768
- return !motionDom.isDragActive();
8769
- }
8770
- cancelPress(event, info) {
8771
- if (!this.checkPressEnd())
8772
- return;
8773
- const { onTapCancel } = this.node.getProps();
8774
- if (onTapCancel) {
8775
- frame.postRender(() => onTapCancel(event, info));
8776
- }
8777
- }
8778
8651
  mount() {
8779
- const props = this.node.getProps();
8780
- const removePointerListener = addPointerEvent(props.globalTapTarget ? window : this.node.current, "pointerdown", this.startPointerPress, {
8781
- passive: !(props.onTapStart ||
8782
- props["onPointerStart"]),
8783
- });
8784
- const removeFocusListener = addDomEvent(this.node.current, "focus", this.startAccessiblePress);
8785
- this.removeStartListeners = pipe(removePointerListener, removeFocusListener);
8786
- }
8787
- unmount() {
8788
- this.removeStartListeners();
8789
- this.removeEndListeners();
8790
- this.removeAccessibleListeners();
8652
+ const { current } = this.node;
8653
+ if (!current)
8654
+ return;
8655
+ this.unmount = motionDom.press(current, (startEvent) => {
8656
+ handlePressEvent(this.node, startEvent, "Start");
8657
+ return (endEvent, { success }) => handlePressEvent(this.node, endEvent, success ? "End" : "Cancel");
8658
+ }, { useGlobalTarget: this.node.props.globalTapTarget });
8791
8659
  }
8660
+ unmount() { }
8792
8661
  }
8793
8662
 
8794
8663
  /**
package/dist/cjs/dom.js CHANGED
@@ -280,7 +280,7 @@ class MotionValue {
280
280
  * This will be replaced by the build step with the latest version number.
281
281
  * When MotionValues are provided to motion components, warn if versions are mixed.
282
282
  */
283
- this.version = "11.13.5";
283
+ this.version = "11.14.1";
284
284
  /**
285
285
  * Tracks whether this value can output a velocity. Currently this is only true
286
286
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -4117,7 +4117,7 @@ function updateMotionValuesFromProps(element, next, prev) {
4117
4117
  * and warn against mismatches.
4118
4118
  */
4119
4119
  if (process.env.NODE_ENV === "development") {
4120
- warnOnce(nextValue.version === "11.13.5", `Attempting to mix Motion versions ${nextValue.version} with 11.13.5 may not work as expected.`);
4120
+ warnOnce(nextValue.version === "11.14.1", `Attempting to mix Motion versions ${nextValue.version} with 11.14.1 may not work as expected.`);
4121
4121
  }
4122
4122
  }
4123
4123
  else if (isMotionValue(prevValue)) {
package/dist/cjs/index.js CHANGED
@@ -3416,7 +3416,7 @@ class MotionValue {
3416
3416
  * This will be replaced by the build step with the latest version number.
3417
3417
  * When MotionValues are provided to motion components, warn if versions are mixed.
3418
3418
  */
3419
- this.version = "11.13.5";
3419
+ this.version = "11.14.1";
3420
3420
  /**
3421
3421
  * Tracks whether this value can output a velocity. Currently this is only true
3422
3422
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -4325,23 +4325,6 @@ const animations = {
4325
4325
  },
4326
4326
  };
4327
4327
 
4328
- const isPrimaryPointer = (event) => {
4329
- if (event.pointerType === "mouse") {
4330
- return typeof event.button !== "number" || event.button <= 0;
4331
- }
4332
- else {
4333
- /**
4334
- * isPrimary is true for all mice buttons, whereas every touch point
4335
- * is regarded as its own input. So subsequent concurrent touch points
4336
- * will be false.
4337
- *
4338
- * Specifically match against false here as incomplete versions of
4339
- * PointerEvents in very old browser might have it set as undefined.
4340
- */
4341
- return event.isPrimary !== false;
4342
- }
4343
- };
4344
-
4345
4328
  function extractEventInfo(event) {
4346
4329
  return {
4347
4330
  point: {
@@ -4351,7 +4334,7 @@ function extractEventInfo(event) {
4351
4334
  };
4352
4335
  }
4353
4336
  const addPointerInfo = (handler) => {
4354
- return (event) => isPrimaryPointer(event) && handler(event, extractEventInfo(event));
4337
+ return (event) => motionDom.isPrimaryPointer(event) && handler(event, extractEventInfo(event));
4355
4338
  };
4356
4339
 
4357
4340
  function addDomEvent(target, eventName, handler, options = { passive: true }) {
@@ -4375,7 +4358,7 @@ function distance2D(a, b) {
4375
4358
  * @internal
4376
4359
  */
4377
4360
  class PanSession {
4378
- constructor(event, handlers, { transformPagePoint, contextWindow, dragSnapToOrigin = false } = {}) {
4361
+ constructor(event, handlers, { transformPagePoint, contextWindow, dragSnapToOrigin = false, } = {}) {
4379
4362
  /**
4380
4363
  * @internal
4381
4364
  */
@@ -4439,7 +4422,7 @@ class PanSession {
4439
4422
  onSessionEnd && onSessionEnd(event, panInfo);
4440
4423
  };
4441
4424
  // If we have more than one touch, don't start detecting this gesture
4442
- if (!isPrimaryPointer(event))
4425
+ if (!motionDom.isPrimaryPointer(event))
4443
4426
  return;
4444
4427
  this.dragSnapToOrigin = dragSnapToOrigin;
4445
4428
  this.handlers = handlers;
@@ -4901,7 +4884,7 @@ function measurePageBox(element, rootProjectionNode, transformPagePoint) {
4901
4884
  return viewportBox;
4902
4885
  }
4903
4886
 
4904
- // Fixes https://github.com/framer/motion/issues/2270
4887
+ // Fixes https://github.com/motiondivision/motion/issues/2270
4905
4888
  const getContextWindow = ({ current }) => {
4906
4889
  return current ? current.ownerDocument.defaultView : null;
4907
4890
  };
@@ -6260,7 +6243,7 @@ function updateMotionValuesFromProps(element, next, prev) {
6260
6243
  * and warn against mismatches.
6261
6244
  */
6262
6245
  if (process.env.NODE_ENV === "development") {
6263
- warnOnce(nextValue.version === "11.13.5", `Attempting to mix Motion versions ${nextValue.version} with 11.13.5 may not work as expected.`);
6246
+ warnOnce(nextValue.version === "11.14.1", `Attempting to mix Motion versions ${nextValue.version} with 11.14.1 may not work as expected.`);
6264
6247
  }
6265
6248
  }
6266
6249
  else if (isMotionValue(prevValue)) {
@@ -10137,142 +10120,28 @@ class FocusGesture extends Feature {
10137
10120
  unmount() { }
10138
10121
  }
10139
10122
 
10140
- /**
10141
- * Recursively traverse up the tree to check whether the provided child node
10142
- * is the parent or a descendant of it.
10143
- *
10144
- * @param parent - Element to find
10145
- * @param child - Element to test against parent
10146
- */
10147
- const isNodeOrChild = (parent, child) => {
10148
- if (!child) {
10149
- return false;
10150
- }
10151
- else if (parent === child) {
10152
- return true;
10123
+ function handlePressEvent(node, event, lifecycle) {
10124
+ const { props } = node;
10125
+ if (node.animationState && props.whileTap) {
10126
+ node.animationState.setActive("whileTap", lifecycle === "Start");
10153
10127
  }
10154
- else {
10155
- return isNodeOrChild(parent, child.parentElement);
10128
+ const eventName = ("onTap" + (lifecycle === "End" ? "" : lifecycle));
10129
+ const callback = props[eventName];
10130
+ if (callback) {
10131
+ frame.postRender(() => callback(event, extractEventInfo(event)));
10156
10132
  }
10157
- };
10158
-
10159
- function fireSyntheticPointerEvent(name, handler) {
10160
- if (!handler)
10161
- return;
10162
- const syntheticPointerEvent = new PointerEvent("pointer" + name);
10163
- handler(syntheticPointerEvent, extractEventInfo(syntheticPointerEvent));
10164
10133
  }
10165
10134
  class PressGesture extends Feature {
10166
- constructor() {
10167
- super(...arguments);
10168
- this.removeStartListeners = motionUtils.noop;
10169
- this.removeEndListeners = motionUtils.noop;
10170
- this.removeAccessibleListeners = motionUtils.noop;
10171
- this.startPointerPress = (startEvent, startInfo) => {
10172
- if (this.isPressing)
10173
- return;
10174
- this.removeEndListeners();
10175
- const props = this.node.getProps();
10176
- const endPointerPress = (endEvent, endInfo) => {
10177
- if (!this.checkPressEnd())
10178
- return;
10179
- const { onTap, onTapCancel, globalTapTarget } = this.node.getProps();
10180
- /**
10181
- * We only count this as a tap gesture if the event.target is the same
10182
- * as, or a child of, this component's element
10183
- */
10184
- const handler = !globalTapTarget &&
10185
- !isNodeOrChild(this.node.current, endEvent.target)
10186
- ? onTapCancel
10187
- : onTap;
10188
- if (handler) {
10189
- frame.update(() => handler(endEvent, endInfo));
10190
- }
10191
- };
10192
- const removePointerUpListener = addPointerEvent(window, "pointerup", endPointerPress, {
10193
- passive: !(props.onTap || props["onPointerUp"]),
10194
- });
10195
- const removePointerCancelListener = addPointerEvent(window, "pointercancel", (cancelEvent, cancelInfo) => this.cancelPress(cancelEvent, cancelInfo), {
10196
- passive: !(props.onTapCancel ||
10197
- props["onPointerCancel"]),
10198
- });
10199
- this.removeEndListeners = pipe(removePointerUpListener, removePointerCancelListener);
10200
- this.startPress(startEvent, startInfo);
10201
- };
10202
- this.startAccessiblePress = () => {
10203
- const handleKeydown = (keydownEvent) => {
10204
- if (keydownEvent.key !== "Enter" || this.isPressing)
10205
- return;
10206
- const handleKeyup = (keyupEvent) => {
10207
- if (keyupEvent.key !== "Enter" || !this.checkPressEnd())
10208
- return;
10209
- fireSyntheticPointerEvent("up", (event, info) => {
10210
- const { onTap } = this.node.getProps();
10211
- if (onTap) {
10212
- frame.postRender(() => onTap(event, info));
10213
- }
10214
- });
10215
- };
10216
- this.removeEndListeners();
10217
- this.removeEndListeners = addDomEvent(this.node.current, "keyup", handleKeyup);
10218
- fireSyntheticPointerEvent("down", (event, info) => {
10219
- this.startPress(event, info);
10220
- });
10221
- };
10222
- const removeKeydownListener = addDomEvent(this.node.current, "keydown", handleKeydown);
10223
- const handleBlur = () => {
10224
- if (!this.isPressing)
10225
- return;
10226
- fireSyntheticPointerEvent("cancel", (cancelEvent, cancelInfo) => this.cancelPress(cancelEvent, cancelInfo));
10227
- };
10228
- const removeBlurListener = addDomEvent(this.node.current, "blur", handleBlur);
10229
- this.removeAccessibleListeners = pipe(removeKeydownListener, removeBlurListener);
10230
- };
10231
- }
10232
- startPress(event, info) {
10233
- this.isPressing = true;
10234
- const { onTapStart, whileTap } = this.node.getProps();
10235
- /**
10236
- * Ensure we trigger animations before firing event callback
10237
- */
10238
- if (whileTap && this.node.animationState) {
10239
- this.node.animationState.setActive("whileTap", true);
10240
- }
10241
- if (onTapStart) {
10242
- frame.postRender(() => onTapStart(event, info));
10243
- }
10244
- }
10245
- checkPressEnd() {
10246
- this.removeEndListeners();
10247
- this.isPressing = false;
10248
- const props = this.node.getProps();
10249
- if (props.whileTap && this.node.animationState) {
10250
- this.node.animationState.setActive("whileTap", false);
10251
- }
10252
- return !motionDom.isDragActive();
10253
- }
10254
- cancelPress(event, info) {
10255
- if (!this.checkPressEnd())
10256
- return;
10257
- const { onTapCancel } = this.node.getProps();
10258
- if (onTapCancel) {
10259
- frame.postRender(() => onTapCancel(event, info));
10260
- }
10261
- }
10262
10135
  mount() {
10263
- const props = this.node.getProps();
10264
- const removePointerListener = addPointerEvent(props.globalTapTarget ? window : this.node.current, "pointerdown", this.startPointerPress, {
10265
- passive: !(props.onTapStart ||
10266
- props["onPointerStart"]),
10267
- });
10268
- const removeFocusListener = addDomEvent(this.node.current, "focus", this.startAccessiblePress);
10269
- this.removeStartListeners = pipe(removePointerListener, removeFocusListener);
10270
- }
10271
- unmount() {
10272
- this.removeStartListeners();
10273
- this.removeEndListeners();
10274
- this.removeAccessibleListeners();
10136
+ const { current } = this.node;
10137
+ if (!current)
10138
+ return;
10139
+ this.unmount = motionDom.press(current, (startEvent) => {
10140
+ handlePressEvent(this.node, startEvent, "Start");
10141
+ return (endEvent, { success }) => handlePressEvent(this.node, endEvent, success ? "End" : "Cancel");
10142
+ }, { useGlobalTarget: this.node.props.globalTapTarget });
10275
10143
  }
10144
+ unmount() { }
10276
10145
  }
10277
10146
 
10278
10147
  /**