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.
Files changed (48) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +1 -4
  3. package/dist/cjs/index.js +10 -10
  4. package/dist/cjs/react-client.js +194 -168
  5. package/dist/es/framer-motion/dist/es/events/event-info.mjs +1 -1
  6. package/dist/es/framer-motion/dist/es/gestures/pan/PanSession.mjs +2 -2
  7. package/dist/es/framer-motion/dist/es/gestures/press.mjs +20 -121
  8. package/dist/es/framer-motion/dist/es/render/utils/motion-values.mjs +1 -1
  9. package/dist/es/framer-motion/dist/es/utils/get-context-window.mjs +1 -1
  10. package/dist/es/framer-motion/dist/es/value/index.mjs +1 -1
  11. package/dist/es/motion-dom/dist/es/gestures/hover.mjs +4 -9
  12. package/dist/es/motion-dom/dist/es/gestures/press/index.mjs +75 -0
  13. package/dist/es/motion-dom/dist/es/gestures/press/utils/is-keyboard-accessible.mjs +12 -0
  14. package/dist/es/motion-dom/dist/es/gestures/press/utils/keyboard.mjs +38 -0
  15. package/dist/es/motion-dom/dist/es/gestures/press/utils/state.mjs +3 -0
  16. package/dist/es/motion-dom/dist/es/gestures/utils/setup.mjs +15 -0
  17. package/dist/motion.dev.js +10 -10
  18. package/dist/motion.js +1 -1
  19. package/package.json +6 -6
  20. package/.turbo/turbo-build.log +0 -45
  21. package/lib/index.js +0 -2
  22. package/lib/index.js.map +0 -1
  23. package/lib/mini.js +0 -2
  24. package/lib/mini.js.map +0 -1
  25. package/lib/react-client.js +0 -3
  26. package/lib/react-client.js.map +0 -1
  27. package/lib/react-m.js +0 -3
  28. package/lib/react-m.js.map +0 -1
  29. package/lib/react-mini.js +0 -3
  30. package/lib/react-mini.js.map +0 -1
  31. package/lib/react.js +0 -3
  32. package/lib/react.js.map +0 -1
  33. package/rollup.config.mjs +0 -210
  34. package/src/index.ts +0 -1
  35. package/src/mini.ts +0 -1
  36. package/src/react-client.ts +0 -3
  37. package/src/react-m.ts +0 -3
  38. package/src/react-mini.ts +0 -3
  39. package/src/react.ts +0 -3
  40. package/tsconfig.json +0 -25
  41. package/types/index.d.ts +0 -1
  42. package/types/mini.d.ts +0 -1
  43. package/types/react-client.d.ts +0 -1
  44. package/types/react-m.d.ts +0 -1
  45. package/types/react-mini.d.ts +0 -1
  46. package/types/react.d.ts +0 -1
  47. /package/dist/es/{framer-motion → motion-dom}/dist/es/gestures/utils/is-node-or-child.mjs +0 -0
  48. /package/dist/es/{framer-motion/dist/es/events → motion-dom/dist/es/gestures}/utils/is-primary-pointer.mjs +0 -0
@@ -1,131 +1,30 @@
1
- import { extractEventInfo } from '../events/event-info.mjs';
2
- import { addDomEvent } from '../events/add-dom-event.mjs';
3
- import { addPointerEvent } from '../events/add-pointer-event.mjs';
4
1
  import { Feature } from '../motion/features/Feature.mjs';
5
- import { pipe } from '../utils/pipe.mjs';
6
- import { isDragActive } from '../../../../motion-dom/dist/es/gestures/drag/state/is-active.mjs';
7
- import { isNodeOrChild } from './utils/is-node-or-child.mjs';
8
- import '../../../../motion-utils/dist/es/errors.mjs';
9
- import { noop } from '../../../../motion-utils/dist/es/noop.mjs';
2
+ import { press } from '../../../../motion-dom/dist/es/gestures/press/index.mjs';
3
+ import { extractEventInfo } from '../events/event-info.mjs';
10
4
  import { frame } from '../frameloop/frame.mjs';
11
5
 
12
- function fireSyntheticPointerEvent(name, handler) {
13
- if (!handler)
14
- return;
15
- const syntheticPointerEvent = new PointerEvent("pointer" + name);
16
- handler(syntheticPointerEvent, extractEventInfo(syntheticPointerEvent));
17
- }
18
- class PressGesture extends Feature {
19
- constructor() {
20
- super(...arguments);
21
- this.removeStartListeners = noop;
22
- this.removeEndListeners = noop;
23
- this.removeAccessibleListeners = noop;
24
- this.startPointerPress = (startEvent, startInfo) => {
25
- if (this.isPressing)
26
- return;
27
- this.removeEndListeners();
28
- const props = this.node.getProps();
29
- const endPointerPress = (endEvent, endInfo) => {
30
- if (!this.checkPressEnd())
31
- return;
32
- const { onTap, onTapCancel, globalTapTarget } = this.node.getProps();
33
- /**
34
- * We only count this as a tap gesture if the event.target is the same
35
- * as, or a child of, this component's element
36
- */
37
- const handler = !globalTapTarget &&
38
- !isNodeOrChild(this.node.current, endEvent.target)
39
- ? onTapCancel
40
- : onTap;
41
- if (handler) {
42
- frame.update(() => handler(endEvent, endInfo));
43
- }
44
- };
45
- const removePointerUpListener = addPointerEvent(window, "pointerup", endPointerPress, {
46
- passive: !(props.onTap || props["onPointerUp"]),
47
- });
48
- const removePointerCancelListener = addPointerEvent(window, "pointercancel", (cancelEvent, cancelInfo) => this.cancelPress(cancelEvent, cancelInfo), {
49
- passive: !(props.onTapCancel ||
50
- props["onPointerCancel"]),
51
- });
52
- this.removeEndListeners = pipe(removePointerUpListener, removePointerCancelListener);
53
- this.startPress(startEvent, startInfo);
54
- };
55
- this.startAccessiblePress = () => {
56
- const handleKeydown = (keydownEvent) => {
57
- if (keydownEvent.key !== "Enter" || this.isPressing)
58
- return;
59
- const handleKeyup = (keyupEvent) => {
60
- if (keyupEvent.key !== "Enter" || !this.checkPressEnd())
61
- return;
62
- fireSyntheticPointerEvent("up", (event, info) => {
63
- const { onTap } = this.node.getProps();
64
- if (onTap) {
65
- frame.postRender(() => onTap(event, info));
66
- }
67
- });
68
- };
69
- this.removeEndListeners();
70
- this.removeEndListeners = addDomEvent(this.node.current, "keyup", handleKeyup);
71
- fireSyntheticPointerEvent("down", (event, info) => {
72
- this.startPress(event, info);
73
- });
74
- };
75
- const removeKeydownListener = addDomEvent(this.node.current, "keydown", handleKeydown);
76
- const handleBlur = () => {
77
- if (!this.isPressing)
78
- return;
79
- fireSyntheticPointerEvent("cancel", (cancelEvent, cancelInfo) => this.cancelPress(cancelEvent, cancelInfo));
80
- };
81
- const removeBlurListener = addDomEvent(this.node.current, "blur", handleBlur);
82
- this.removeAccessibleListeners = pipe(removeKeydownListener, removeBlurListener);
83
- };
84
- }
85
- startPress(event, info) {
86
- this.isPressing = true;
87
- const { onTapStart, whileTap } = this.node.getProps();
88
- /**
89
- * Ensure we trigger animations before firing event callback
90
- */
91
- if (whileTap && this.node.animationState) {
92
- this.node.animationState.setActive("whileTap", true);
93
- }
94
- if (onTapStart) {
95
- frame.postRender(() => onTapStart(event, info));
96
- }
6
+ function handlePressEvent(node, event, lifecycle) {
7
+ const { props } = node;
8
+ if (node.animationState && props.whileTap) {
9
+ node.animationState.setActive("whileTap", lifecycle === "Start");
97
10
  }
98
- checkPressEnd() {
99
- this.removeEndListeners();
100
- this.isPressing = false;
101
- const props = this.node.getProps();
102
- if (props.whileTap && this.node.animationState) {
103
- this.node.animationState.setActive("whileTap", false);
104
- }
105
- return !isDragActive();
106
- }
107
- cancelPress(event, info) {
108
- if (!this.checkPressEnd())
109
- return;
110
- const { onTapCancel } = this.node.getProps();
111
- if (onTapCancel) {
112
- frame.postRender(() => onTapCancel(event, info));
113
- }
11
+ const eventName = ("onTap" + (lifecycle === "End" ? "" : lifecycle));
12
+ const callback = props[eventName];
13
+ if (callback) {
14
+ frame.postRender(() => callback(event, extractEventInfo(event)));
114
15
  }
16
+ }
17
+ class PressGesture extends Feature {
115
18
  mount() {
116
- const props = this.node.getProps();
117
- const removePointerListener = addPointerEvent(props.globalTapTarget ? window : this.node.current, "pointerdown", this.startPointerPress, {
118
- passive: !(props.onTapStart ||
119
- props["onPointerStart"]),
120
- });
121
- const removeFocusListener = addDomEvent(this.node.current, "focus", this.startAccessiblePress);
122
- this.removeStartListeners = pipe(removePointerListener, removeFocusListener);
123
- }
124
- unmount() {
125
- this.removeStartListeners();
126
- this.removeEndListeners();
127
- this.removeAccessibleListeners();
19
+ const { current } = this.node;
20
+ if (!current)
21
+ return;
22
+ this.unmount = press(current, (startEvent) => {
23
+ handlePressEvent(this.node, startEvent, "Start");
24
+ return (endEvent, { success }) => handlePressEvent(this.node, endEvent, success ? "End" : "Cancel");
25
+ }, { useGlobalTarget: this.node.props.globalTapTarget });
128
26
  }
27
+ unmount() { }
129
28
  }
130
29
 
131
30
  export { PressGesture };
@@ -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 === "11.13.5", `Attempting to mix Motion versions ${nextValue.version} with 11.13.5 may not work as expected.`);
20
+ warnOnce(nextValue.version === "11.14.1", `Attempting to mix Motion versions ${nextValue.version} with 11.14.1 may not work as expected.`);
21
21
  }
22
22
  }
23
23
  else if (isMotionValue(prevValue)) {
@@ -1,4 +1,4 @@
1
- // Fixes https://github.com/framer/motion/issues/2270
1
+ // Fixes https://github.com/motiondivision/motion/issues/2270
2
2
  const getContextWindow = ({ current }) => {
3
3
  return current ? current.ownerDocument.defaultView : null;
4
4
  };
@@ -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 = "11.13.5";
37
+ this.version = "11.14.1";
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
@@ -1,5 +1,5 @@
1
- import { resolveElements } from '../utils/resolve-elements.mjs';
2
1
  import { isDragActive } from './drag/state/is-active.mjs';
2
+ import { setupGesture } from './utils/setup.mjs';
3
3
 
4
4
  /**
5
5
  * Filter out events that are not pointer events, or are triggering
@@ -20,12 +20,7 @@ function filterEvents(callback) {
20
20
  * @public
21
21
  */
22
22
  function hover(elementOrSelector, onHoverStart, options = {}) {
23
- const gestureAbortController = new AbortController();
24
- const eventOptions = {
25
- passive: true,
26
- ...options,
27
- signal: gestureAbortController.signal,
28
- };
23
+ const [elements, eventOptions, cancel] = setupGesture(elementOrSelector, options);
29
24
  const onPointerEnter = filterEvents((enterEvent) => {
30
25
  const { target } = enterEvent;
31
26
  const onHoverEnd = onHoverStart(enterEvent);
@@ -37,10 +32,10 @@ function hover(elementOrSelector, onHoverStart, options = {}) {
37
32
  });
38
33
  target.addEventListener("pointerleave", onPointerLeave, eventOptions);
39
34
  });
40
- resolveElements(elementOrSelector).forEach((element) => {
35
+ elements.forEach((element) => {
41
36
  element.addEventListener("pointerenter", onPointerEnter, eventOptions);
42
37
  });
43
- return () => gestureAbortController.abort();
38
+ return cancel;
44
39
  }
45
40
 
46
41
  export { hover };
@@ -0,0 +1,75 @@
1
+ import { isDragActive } from '../drag/state/is-active.mjs';
2
+ import { isPrimaryPointer } from '../utils/is-primary-pointer.mjs';
3
+ import { setupGesture } from '../utils/setup.mjs';
4
+ import { enableKeyboardPress } from './utils/keyboard.mjs';
5
+ import { isElementKeyboardAccessible } from './utils/is-keyboard-accessible.mjs';
6
+ import { isNodeOrChild } from '../utils/is-node-or-child.mjs';
7
+ import { isPressing } from './utils/state.mjs';
8
+
9
+ /**
10
+ * Filter out events that are not primary pointer events, or are triggering
11
+ * while a Motion gesture is active.
12
+ */
13
+ function isValidPressEvent(event) {
14
+ return isPrimaryPointer(event) && !isDragActive();
15
+ }
16
+ /**
17
+ * Create a press gesture.
18
+ *
19
+ * Press is different to `"pointerdown"`, `"pointerup"` in that it
20
+ * automatically filters out secondary pointer events like right
21
+ * click and multitouch.
22
+ *
23
+ * It also adds accessibility support for keyboards, where
24
+ * an element with a press gesture will receive focus and
25
+ * trigger on Enter `"keydown"` and `"keyup"` events.
26
+ *
27
+ * This is different to a browser's `"click"` event, which does
28
+ * respond to keyboards but only for the `"click"` itself, rather
29
+ * than the press start and end/cancel. The element also needs
30
+ * to be focusable for this to work, whereas a press gesture will
31
+ * make an element focusable by default.
32
+ *
33
+ * @public
34
+ */
35
+ function press(elementOrSelector, onPressStart, options = {}) {
36
+ const [elements, eventOptions, cancelEvents] = setupGesture(elementOrSelector, options);
37
+ const startPress = (startEvent) => {
38
+ const element = startEvent.currentTarget;
39
+ if (!isValidPressEvent(startEvent) || isPressing.has(element))
40
+ return;
41
+ isPressing.add(element);
42
+ const onPressEnd = onPressStart(startEvent);
43
+ const onPointerEnd = (endEvent, success) => {
44
+ window.removeEventListener("pointerup", onPointerUp);
45
+ window.removeEventListener("pointercancel", onPointerCancel);
46
+ if (!isValidPressEvent(endEvent) || !isPressing.has(element)) {
47
+ return;
48
+ }
49
+ isPressing.delete(element);
50
+ if (onPressEnd) {
51
+ onPressEnd(endEvent, { success });
52
+ }
53
+ };
54
+ const onPointerUp = (upEvent) => {
55
+ onPointerEnd(upEvent, options.useGlobalTarget ||
56
+ isNodeOrChild(element, upEvent.target));
57
+ };
58
+ const onPointerCancel = (cancelEvent) => {
59
+ onPointerEnd(cancelEvent, false);
60
+ };
61
+ window.addEventListener("pointerup", onPointerUp, eventOptions);
62
+ window.addEventListener("pointercancel", onPointerCancel, eventOptions);
63
+ };
64
+ elements.forEach((element) => {
65
+ if (!isElementKeyboardAccessible(element)) {
66
+ element.tabIndex = 0;
67
+ }
68
+ const target = options.useGlobalTarget ? window : element;
69
+ target.addEventListener("pointerdown", startPress, eventOptions);
70
+ element.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions), eventOptions);
71
+ });
72
+ return cancelEvents;
73
+ }
74
+
75
+ export { press };
@@ -0,0 +1,12 @@
1
+ const focusableElements = new Set([
2
+ "BUTTON",
3
+ "INPUT",
4
+ "SELECT",
5
+ "TEXTAREA",
6
+ "A",
7
+ ]);
8
+ function isElementKeyboardAccessible(element) {
9
+ return focusableElements.has(element.tagName) || element.tabIndex !== -1;
10
+ }
11
+
12
+ export { isElementKeyboardAccessible };
@@ -0,0 +1,38 @@
1
+ import { isPressing } from './state.mjs';
2
+
3
+ /**
4
+ * Filter out events that are not "Enter" keys.
5
+ */
6
+ function filterEvents(callback) {
7
+ return (event) => {
8
+ if (event.key !== "Enter")
9
+ return;
10
+ callback(event);
11
+ };
12
+ }
13
+ function firePointerEvent(target, type) {
14
+ target.dispatchEvent(new PointerEvent("pointer" + type, { isPrimary: true, bubbles: true }));
15
+ }
16
+ const enableKeyboardPress = (focusEvent, eventOptions) => {
17
+ const element = focusEvent.currentTarget;
18
+ if (!element)
19
+ return;
20
+ const handleKeydown = filterEvents(() => {
21
+ if (isPressing.has(element))
22
+ return;
23
+ firePointerEvent(element, "down");
24
+ const handleKeyup = filterEvents(() => {
25
+ firePointerEvent(element, "up");
26
+ });
27
+ const handleBlur = () => firePointerEvent(element, "cancel");
28
+ element.addEventListener("keyup", handleKeyup, eventOptions);
29
+ element.addEventListener("blur", handleBlur, eventOptions);
30
+ });
31
+ element.addEventListener("keydown", handleKeydown, eventOptions);
32
+ /**
33
+ * Add an event listener that fires on blur to remove the keydown events.
34
+ */
35
+ element.addEventListener("blur", () => element.removeEventListener("keydown", handleKeydown), eventOptions);
36
+ };
37
+
38
+ export { enableKeyboardPress };
@@ -0,0 +1,3 @@
1
+ const isPressing = new WeakSet();
2
+
3
+ export { isPressing };
@@ -0,0 +1,15 @@
1
+ import { resolveElements } from '../../utils/resolve-elements.mjs';
2
+
3
+ function setupGesture(elementOrSelector, options) {
4
+ const elements = resolveElements(elementOrSelector);
5
+ const gestureAbortController = new AbortController();
6
+ const eventOptions = {
7
+ passive: true,
8
+ ...options,
9
+ signal: gestureAbortController.signal,
10
+ };
11
+ const cancel = () => gestureAbortController.abort();
12
+ return [elements, eventOptions, cancel];
13
+ }
14
+
15
+ export { setupGesture };
@@ -21,6 +21,14 @@
21
21
  };
22
22
  }
23
23
 
24
+ const isDragging = {
25
+ x: false,
26
+ y: false,
27
+ };
28
+ function isDragActive() {
29
+ return isDragging.y;
30
+ }
31
+
24
32
  function resolveElements(elementOrSelector, scope, selectorCache) {
25
33
  var _a;
26
34
  if (elementOrSelector instanceof Element) {
@@ -42,14 +50,6 @@
42
50
  return Array.from(elementOrSelector);
43
51
  }
44
52
 
45
- const isDragging = {
46
- x: false,
47
- y: false,
48
- };
49
- function isDragActive() {
50
- return isDragging.y;
51
- }
52
-
53
53
  function addUniqueItem(arr, item) {
54
54
  if (arr.indexOf(item) === -1)
55
55
  arr.push(item);
@@ -325,7 +325,7 @@
325
325
  * This will be replaced by the build step with the latest version number.
326
326
  * When MotionValues are provided to motion components, warn if versions are mixed.
327
327
  */
328
- this.version = "11.13.5";
328
+ this.version = "11.14.1";
329
329
  /**
330
330
  * Tracks whether this value can output a velocity. Currently this is only true
331
331
  * if the value is numerical, but we might be able to widen the scope here and support
@@ -4162,7 +4162,7 @@
4162
4162
  * and warn against mismatches.
4163
4163
  */
4164
4164
  {
4165
- warnOnce(nextValue.version === "11.13.5", `Attempting to mix Motion versions ${nextValue.version} with 11.13.5 may not work as expected.`);
4165
+ warnOnce(nextValue.version === "11.14.1", `Attempting to mix Motion versions ${nextValue.version} with 11.14.1 may not work as expected.`);
4166
4166
  }
4167
4167
  }
4168
4168
  else if (isMotionValue(prevValue)) {