motion-dom 11.14.0 → 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 (62) hide show
  1. package/LICENSE.md +1 -1
  2. package/package.json +5 -2
  3. package/.turbo/turbo-build.log +0 -9
  4. package/lib/gestures/drag/state/is-active.js +0 -8
  5. package/lib/gestures/drag/state/is-active.js.map +0 -1
  6. package/lib/gestures/drag/state/set-active.js +0 -26
  7. package/lib/gestures/drag/state/set-active.js.map +0 -1
  8. package/lib/gestures/hover.js +0 -39
  9. package/lib/gestures/hover.js.map +0 -1
  10. package/lib/gestures/press/index.js +0 -73
  11. package/lib/gestures/press/index.js.map +0 -1
  12. package/lib/gestures/press/types.js +0 -2
  13. package/lib/gestures/press/types.js.map +0 -1
  14. package/lib/gestures/press/utils/is-keyboard-accessible.js +0 -11
  15. package/lib/gestures/press/utils/is-keyboard-accessible.js.map +0 -1
  16. package/lib/gestures/press/utils/keyboard.js +0 -36
  17. package/lib/gestures/press/utils/keyboard.js.map +0 -1
  18. package/lib/gestures/press/utils/state.js +0 -2
  19. package/lib/gestures/press/utils/state.js.map +0 -1
  20. package/lib/gestures/types.js +0 -2
  21. package/lib/gestures/types.js.map +0 -1
  22. package/lib/gestures/utils/is-node-or-child.js +0 -19
  23. package/lib/gestures/utils/is-node-or-child.js.map +0 -1
  24. package/lib/gestures/utils/is-primary-pointer.js +0 -17
  25. package/lib/gestures/utils/is-primary-pointer.js.map +0 -1
  26. package/lib/gestures/utils/setup.js +0 -13
  27. package/lib/gestures/utils/setup.js.map +0 -1
  28. package/lib/index.js +0 -10
  29. package/lib/index.js.map +0 -1
  30. package/lib/utils/resolve-elements.js +0 -21
  31. package/lib/utils/resolve-elements.js.map +0 -1
  32. package/rollup.config.mjs +0 -94
  33. package/src/gestures/drag/state/is-active.ts +0 -8
  34. package/src/gestures/drag/state/set-active.ts +0 -23
  35. package/src/gestures/hover.ts +0 -70
  36. package/src/gestures/press/index.ts +0 -109
  37. package/src/gestures/press/types.ts +0 -10
  38. package/src/gestures/press/utils/is-keyboard-accessible.ts +0 -11
  39. package/src/gestures/press/utils/keyboard.ts +0 -51
  40. package/src/gestures/press/utils/state.ts +0 -1
  41. package/src/gestures/types.ts +0 -21
  42. package/src/gestures/utils/__tests__/is-primary-pointer.test.ts +0 -48
  43. package/src/gestures/utils/is-node-or-child.ts +0 -19
  44. package/src/gestures/utils/is-primary-pointer.ts +0 -15
  45. package/src/gestures/utils/setup.ts +0 -23
  46. package/src/index.ts +0 -10
  47. package/src/utils/resolve-elements.ts +0 -47
  48. package/tsconfig.json +0 -25
  49. package/types/gestures/drag/state/is-active.d.ts +0 -5
  50. package/types/gestures/drag/state/set-active.d.ts +0 -1
  51. package/types/gestures/hover.d.ts +0 -25
  52. package/types/gestures/press/index.d.ts +0 -26
  53. package/types/gestures/press/types.d.ts +0 -5
  54. package/types/gestures/press/utils/is-keyboard-accessible.d.ts +0 -1
  55. package/types/gestures/press/utils/keyboard.d.ts +0 -1
  56. package/types/gestures/press/utils/state.d.ts +0 -1
  57. package/types/gestures/types.d.ts +0 -20
  58. package/types/gestures/utils/is-node-or-child.d.ts +0 -8
  59. package/types/gestures/utils/is-primary-pointer.d.ts +0 -1
  60. package/types/gestures/utils/setup.d.ts +0 -3
  61. package/types/index.d.ts +0 -9
  62. package/types/utils/resolve-elements.d.ts +0 -12
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 [Framer](https://www.framer.com?utm_source=motion-license) B.V.
3
+ Copyright (c) 2024 [Motion](https://motion.dev) B.V.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "motion-dom",
3
- "version": "11.14.0",
3
+ "version": "11.14.1",
4
+ "author": "Matt Perry",
5
+ "license": "MIT",
6
+ "repository": "https://github.com/motiondivision/motion",
4
7
  "main": "./lib/index.js",
5
8
  "types": "./types/index.d.ts",
6
9
  "module": "./lib/index.js",
@@ -23,5 +26,5 @@
23
26
  "build": "yarn clean && tsc -p . && rollup -c",
24
27
  "dev": "concurrently -c blue,red -n tsc,rollup --kill-others \"tsc --watch -p . --preserveWatchOutput\" \"rollup --config --watch --no-watch.clearScreen\""
25
28
  },
26
- "gitHead": "9d50c4ee2443802c9ca392d8f58db0146ab83983"
29
+ "gitHead": "6cd8bda421eb6067412d589a66ee47bedefbd597"
27
30
  }
@@ -1,9 +0,0 @@
1
- 
2
- lib/index.js → dist/cjs...
3
- created dist/cjs in 34ms
4
- 
5
- lib/index.js → dist/es...
6
- created dist/es in 20ms
7
- 
8
- types/index.d.ts → dist/index.d.ts...
9
- created dist/index.d.ts in 25ms
@@ -1,8 +0,0 @@
1
- export const isDragging = {
2
- x: false,
3
- y: false,
4
- };
5
- export function isDragActive() {
6
- return isDragging.x || isDragging.y;
7
- }
8
- //# sourceMappingURL=is-active.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-active.js","sourceRoot":"","sources":["../../../../src/gestures/drag/state/is-active.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;IACtB,CAAC,EAAE,KAAK;IACR,CAAC,EAAE,KAAK;CACX,CAAA;AAED,MAAM,UAAU,YAAY;IACxB,OAAO,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAA;AACvC,CAAC"}
@@ -1,26 +0,0 @@
1
- import { isDragging } from "./is-active";
2
- export function setDragLock(axis) {
3
- if (axis === "x" || axis === "y") {
4
- if (isDragging[axis]) {
5
- return null;
6
- }
7
- else {
8
- isDragging[axis] = true;
9
- return () => {
10
- isDragging[axis] = false;
11
- };
12
- }
13
- }
14
- else {
15
- if (isDragging.x || isDragging.y) {
16
- return null;
17
- }
18
- else {
19
- isDragging.x = isDragging.y = true;
20
- return () => {
21
- isDragging.x = isDragging.y = false;
22
- };
23
- }
24
- }
25
- }
26
- //# sourceMappingURL=set-active.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"set-active.js","sourceRoot":"","sources":["../../../../src/gestures/drag/state/set-active.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,MAAM,UAAU,WAAW,CAAC,IAA2C;IACnE,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;QAC/B,IAAI,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACnB,OAAO,IAAI,CAAA;QACf,CAAC;aAAM,CAAC;YACJ,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;YACvB,OAAO,GAAG,EAAE;gBACR,UAAU,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;YAC5B,CAAC,CAAA;QACL,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,IAAI,UAAU,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAA;QACf,CAAC;aAAM,CAAC;YACJ,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,IAAI,CAAA;YAClC,OAAO,GAAG,EAAE;gBACR,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,KAAK,CAAA;YACvC,CAAC,CAAA;QACL,CAAC;IACL,CAAC;AACL,CAAC"}
@@ -1,39 +0,0 @@
1
- import { isDragActive } from "./drag/state/is-active";
2
- import { setupGesture } from "./utils/setup";
3
- /**
4
- * Filter out events that are not pointer events, or are triggering
5
- * while a Motion gesture is active.
6
- */
7
- function filterEvents(callback) {
8
- return (event) => {
9
- if (event.pointerType === "touch" || isDragActive())
10
- return;
11
- callback(event);
12
- };
13
- }
14
- /**
15
- * Create a hover gesture. hover() is different to .addEventListener("pointerenter")
16
- * in that it has an easier syntax, filters out polyfilled touch events, interoperates
17
- * with drag gestures, and automatically removes the "pointerennd" event listener when the hover ends.
18
- *
19
- * @public
20
- */
21
- export function hover(elementOrSelector, onHoverStart, options = {}) {
22
- const [elements, eventOptions, cancel] = setupGesture(elementOrSelector, options);
23
- const onPointerEnter = filterEvents((enterEvent) => {
24
- const { target } = enterEvent;
25
- const onHoverEnd = onHoverStart(enterEvent);
26
- if (!onHoverEnd || !target)
27
- return;
28
- const onPointerLeave = filterEvents((leaveEvent) => {
29
- onHoverEnd(leaveEvent);
30
- target.removeEventListener("pointerleave", onPointerLeave);
31
- });
32
- target.addEventListener("pointerleave", onPointerLeave, eventOptions);
33
- });
34
- elements.forEach((element) => {
35
- element.addEventListener("pointerenter", onPointerEnter, eventOptions);
36
- });
37
- return cancel;
38
- }
39
- //# sourceMappingURL=hover.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hover.js","sourceRoot":"","sources":["../../src/gestures/hover.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAmB5C;;;GAGG;AACH,SAAS,YAAY,CAAC,QAA2B;IAC7C,OAAO,CAAC,KAAmB,EAAE,EAAE;QAC3B,IAAI,KAAK,CAAC,WAAW,KAAK,OAAO,IAAI,YAAY,EAAE;YAAE,OAAM;QAC3D,QAAQ,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC,CAAA;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,KAAK,CACjB,iBAAoC,EACpC,YAA+B,EAC/B,UAAwB,EAAE;IAE1B,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,GAAG,YAAY,CACjD,iBAAiB,EACjB,OAAO,CACV,CAAA;IAED,MAAM,cAAc,GAAG,YAAY,CAAC,CAAC,UAAwB,EAAE,EAAE;QAC7D,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAA;QAC7B,MAAM,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC,CAAA;QAE3C,IAAI,CAAC,UAAU,IAAI,CAAC,MAAM;YAAE,OAAM;QAElC,MAAM,cAAc,GAAG,YAAY,CAAC,CAAC,UAAwB,EAAE,EAAE;YAC7D,UAAU,CAAC,UAAU,CAAC,CAAA;YACtB,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,cAAc,CAAC,CAAA;QAC9D,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,cAAc,EAAE,YAAY,CAAC,CAAA;IACzE,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACzB,OAAO,CAAC,gBAAgB,CAAC,cAAc,EAAE,cAAc,EAAE,YAAY,CAAC,CAAA;IAC1E,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACjB,CAAC"}
@@ -1,73 +0,0 @@
1
- import { isDragActive } from "../drag/state/is-active";
2
- import { isPrimaryPointer } from "../utils/is-primary-pointer";
3
- import { setupGesture } from "../utils/setup";
4
- import { enableKeyboardPress } from "./utils/keyboard";
5
- import { isElementKeyboardAccessible } from "./utils/is-keyboard-accessible";
6
- import { isNodeOrChild } from "../utils/is-node-or-child";
7
- import { isPressing } from "./utils/state";
8
- /**
9
- * Filter out events that are not primary pointer events, or are triggering
10
- * while a Motion gesture is active.
11
- */
12
- function isValidPressEvent(event) {
13
- return isPrimaryPointer(event) && !isDragActive();
14
- }
15
- /**
16
- * Create a press gesture.
17
- *
18
- * Press is different to `"pointerdown"`, `"pointerup"` in that it
19
- * automatically filters out secondary pointer events like right
20
- * click and multitouch.
21
- *
22
- * It also adds accessibility support for keyboards, where
23
- * an element with a press gesture will receive focus and
24
- * trigger on Enter `"keydown"` and `"keyup"` events.
25
- *
26
- * This is different to a browser's `"click"` event, which does
27
- * respond to keyboards but only for the `"click"` itself, rather
28
- * than the press start and end/cancel. The element also needs
29
- * to be focusable for this to work, whereas a press gesture will
30
- * make an element focusable by default.
31
- *
32
- * @public
33
- */
34
- export function press(elementOrSelector, onPressStart, options = {}) {
35
- const [elements, eventOptions, cancelEvents] = setupGesture(elementOrSelector, options);
36
- const startPress = (startEvent) => {
37
- const element = startEvent.currentTarget;
38
- if (!isValidPressEvent(startEvent) || isPressing.has(element))
39
- return;
40
- isPressing.add(element);
41
- const onPressEnd = onPressStart(startEvent);
42
- const onPointerEnd = (endEvent, success) => {
43
- window.removeEventListener("pointerup", onPointerUp);
44
- window.removeEventListener("pointercancel", onPointerCancel);
45
- if (!isValidPressEvent(endEvent) || !isPressing.has(element)) {
46
- return;
47
- }
48
- isPressing.delete(element);
49
- if (onPressEnd) {
50
- onPressEnd(endEvent, { success });
51
- }
52
- };
53
- const onPointerUp = (upEvent) => {
54
- onPointerEnd(upEvent, options.useGlobalTarget ||
55
- isNodeOrChild(element, upEvent.target));
56
- };
57
- const onPointerCancel = (cancelEvent) => {
58
- onPointerEnd(cancelEvent, false);
59
- };
60
- window.addEventListener("pointerup", onPointerUp, eventOptions);
61
- window.addEventListener("pointercancel", onPointerCancel, eventOptions);
62
- };
63
- elements.forEach((element) => {
64
- if (!isElementKeyboardAccessible(element)) {
65
- element.tabIndex = 0;
66
- }
67
- const target = options.useGlobalTarget ? window : element;
68
- target.addEventListener("pointerdown", startPress, eventOptions);
69
- element.addEventListener("focus", (event) => enableKeyboardPress(event, eventOptions), eventOptions);
70
- });
71
- return cancelEvents;
72
- }
73
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/gestures/press/index.ts"],"names":[],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/gestures/press/types.ts"],"names":[],"mappings":""}
@@ -1,11 +0,0 @@
1
- const focusableElements = new Set([
2
- "BUTTON",
3
- "INPUT",
4
- "SELECT",
5
- "TEXTAREA",
6
- "A",
7
- ]);
8
- export function isElementKeyboardAccessible(element) {
9
- return focusableElements.has(element.tagName) || element.tabIndex !== -1;
10
- }
11
- //# sourceMappingURL=is-keyboard-accessible.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-keyboard-accessible.js","sourceRoot":"","sources":["../../../../src/gestures/press/utils/is-keyboard-accessible.ts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAC9B,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,UAAU;IACV,GAAG;CACN,CAAC,CAAA;AAEF,MAAM,UAAU,2BAA2B,CAAC,OAAoB;IAC5D,OAAO,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAA;AAC5E,CAAC"}
@@ -1,36 +0,0 @@
1
- import { isPressing } from "./state";
2
- /**
3
- * Filter out events that are not "Enter" keys.
4
- */
5
- function filterEvents(callback) {
6
- return (event) => {
7
- if (event.key !== "Enter")
8
- return;
9
- callback(event);
10
- };
11
- }
12
- function firePointerEvent(target, type) {
13
- target.dispatchEvent(new PointerEvent("pointer" + type, { isPrimary: true, bubbles: true }));
14
- }
15
- export const enableKeyboardPress = (focusEvent, eventOptions) => {
16
- const element = focusEvent.currentTarget;
17
- if (!element)
18
- return;
19
- const handleKeydown = filterEvents(() => {
20
- if (isPressing.has(element))
21
- return;
22
- firePointerEvent(element, "down");
23
- const handleKeyup = filterEvents(() => {
24
- firePointerEvent(element, "up");
25
- });
26
- const handleBlur = () => firePointerEvent(element, "cancel");
27
- element.addEventListener("keyup", handleKeyup, eventOptions);
28
- element.addEventListener("blur", handleBlur, eventOptions);
29
- });
30
- element.addEventListener("keydown", handleKeydown, eventOptions);
31
- /**
32
- * Add an event listener that fires on blur to remove the keydown events.
33
- */
34
- element.addEventListener("blur", () => element.removeEventListener("keydown", handleKeydown), eventOptions);
35
- };
36
- //# sourceMappingURL=keyboard.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keyboard.js","sourceRoot":"","sources":["../../../../src/gestures/press/utils/keyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEpC;;GAEG;AACH,SAAS,YAAY,CAAC,QAAwC;IAC1D,OAAO,CAAC,KAAoB,EAAE,EAAE;QAC5B,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO;YAAE,OAAM;QACjC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC,CAAA;AACL,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAmB,EAAE,IAA8B;IACzE,MAAM,CAAC,aAAa,CAChB,IAAI,YAAY,CAAC,SAAS,GAAG,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CACzE,CAAA;AACL,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAC/B,UAAsB,EACtB,YAAqC,EACvC,EAAE;IACA,MAAM,OAAO,GAAG,UAAU,CAAC,aAA4B,CAAA;IACvD,IAAI,CAAC,OAAO;QAAE,OAAM;IAEpB,MAAM,aAAa,GAAG,YAAY,CAAC,GAAG,EAAE;QACpC,IAAI,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE,OAAM;QAEnC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAEjC,MAAM,WAAW,GAAG,YAAY,CAAC,GAAG,EAAE;YAClC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACnC,CAAC,CAAC,CAAA;QAEF,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QAE5D,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC,CAAA;QAC5D,OAAO,CAAC,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,CAAC,CAAA;IAC9D,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,EAAE,YAAY,CAAC,CAAA;IAEhE;;OAEG;IACH,OAAO,CAAC,gBAAgB,CACpB,MAAM,EACN,GAAG,EAAE,CAAC,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,EAC3D,YAAY,CACf,CAAA;AACL,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export const isPressing = new WeakSet();
2
- //# sourceMappingURL=state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../../../../src/gestures/press/utils/state.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,OAAO,EAAW,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/gestures/types.ts"],"names":[],"mappings":""}
@@ -1,19 +0,0 @@
1
- /**
2
- * Recursively traverse up the tree to check whether the provided child node
3
- * is the parent or a descendant of it.
4
- *
5
- * @param parent - Element to find
6
- * @param child - Element to test against parent
7
- */
8
- export const isNodeOrChild = (parent, child) => {
9
- if (!child) {
10
- return false;
11
- }
12
- else if (parent === child) {
13
- return true;
14
- }
15
- else {
16
- return isNodeOrChild(parent, child.parentElement);
17
- }
18
- };
19
- //# sourceMappingURL=is-node-or-child.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-node-or-child.js","sourceRoot":"","sources":["../../../src/gestures/utils/is-node-or-child.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CACzB,MAAsB,EACtB,KAAsB,EACf,EAAE;IACT,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,OAAO,KAAK,CAAA;IAChB,CAAC;SAAM,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAA;IACf,CAAC;SAAM,CAAC;QACJ,OAAO,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACrD,CAAC;AACL,CAAC,CAAA"}
@@ -1,17 +0,0 @@
1
- export const isPrimaryPointer = (event) => {
2
- if (event.pointerType === "mouse") {
3
- return typeof event.button !== "number" || event.button <= 0;
4
- }
5
- else {
6
- /**
7
- * isPrimary is true for all mice buttons, whereas every touch point
8
- * is regarded as its own input. So subsequent concurrent touch points
9
- * will be false.
10
- *
11
- * Specifically match against false here as incomplete versions of
12
- * PointerEvents in very old browser might have it set as undefined.
13
- */
14
- return event.isPrimary !== false;
15
- }
16
- };
17
- //# sourceMappingURL=is-primary-pointer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-primary-pointer.js","sourceRoot":"","sources":["../../../src/gestures/utils/is-primary-pointer.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAmB,EAAE,EAAE;IACpD,IAAI,KAAK,CAAC,WAAW,KAAK,OAAO,EAAE,CAAC;QAChC,OAAO,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,CAAA;IAChE,CAAC;SAAM,CAAC;QACJ;;;;;;;WAOG;QACH,OAAO,KAAK,CAAC,SAAS,KAAK,KAAK,CAAA;IACpC,CAAC;AACL,CAAC,CAAA"}
@@ -1,13 +0,0 @@
1
- import { resolveElements, } from "../../utils/resolve-elements";
2
- export function setupGesture(elementOrSelector, options) {
3
- const elements = resolveElements(elementOrSelector);
4
- const gestureAbortController = new AbortController();
5
- const eventOptions = {
6
- passive: true,
7
- ...options,
8
- signal: gestureAbortController.signal,
9
- };
10
- const cancel = () => gestureAbortController.abort();
11
- return [elements, eventOptions, cancel];
12
- }
13
- //# sourceMappingURL=setup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../src/gestures/utils/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,eAAe,GAClB,MAAM,8BAA8B,CAAA;AAErC,MAAM,UAAU,YAAY,CACxB,iBAAoC,EACpC,OAAqB;IAErB,MAAM,QAAQ,GAAG,eAAe,CAAC,iBAAiB,CAAC,CAAA;IAEnD,MAAM,sBAAsB,GAAG,IAAI,eAAe,EAAE,CAAA;IAEpD,MAAM,YAAY,GAAG;QACjB,OAAO,EAAE,IAAI;QACb,GAAG,OAAO;QACV,MAAM,EAAE,sBAAsB,CAAC,MAAM;KACxC,CAAA;IAED,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,sBAAsB,CAAC,KAAK,EAAE,CAAA;IAEnD,OAAO,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,CAAA;AAC3C,CAAC"}
package/lib/index.js DELETED
@@ -1,10 +0,0 @@
1
- export * from "./gestures/hover";
2
- export * from "./gestures/press";
3
- export * from "./gestures/press/types";
4
- export * from "./gestures/types";
5
- export * from "./utils/resolve-elements";
6
- export * from "./gestures/drag/state/is-active";
7
- export * from "./gestures/drag/state/set-active";
8
- export * from "./gestures/utils/is-primary-pointer";
9
- export * from "./gestures/utils/is-node-or-child";
10
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA;AAEhC,cAAc,0BAA0B,CAAA;AACxC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kCAAkC,CAAA;AAChD,cAAc,qCAAqC,CAAA;AACnD,cAAc,mCAAmC,CAAA"}
@@ -1,21 +0,0 @@
1
- export function resolveElements(elementOrSelector, scope, selectorCache) {
2
- var _a;
3
- if (elementOrSelector instanceof Element) {
4
- return [elementOrSelector];
5
- }
6
- else if (typeof elementOrSelector === "string") {
7
- let root = document;
8
- if (scope) {
9
- // TODO: Refactor to utils package
10
- // invariant(
11
- // Boolean(scope.current),
12
- // "Scope provided, but no element detected."
13
- // )
14
- root = scope.current;
15
- }
16
- const elements = (_a = selectorCache === null || selectorCache === void 0 ? void 0 : selectorCache[elementOrSelector]) !== null && _a !== void 0 ? _a : root.querySelectorAll(elementOrSelector);
17
- return elements ? Array.from(elements) : [];
18
- }
19
- return Array.from(elementOrSelector);
20
- }
21
- //# sourceMappingURL=resolve-elements.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve-elements.js","sourceRoot":"","sources":["../../src/utils/resolve-elements.ts"],"names":[],"mappings":"AAmBA,MAAM,UAAU,eAAe,CAC3B,iBAAoC,EACpC,KAAsB,EACtB,aAA6B;;IAE7B,IAAI,iBAAiB,YAAY,OAAO,EAAE,CAAC;QACvC,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAC9B,CAAC;SAAM,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;QAC/C,IAAI,IAAI,GAAyB,QAAQ,CAAA;QAEzC,IAAI,KAAK,EAAE,CAAC;YACR,kCAAkC;YAClC,aAAa;YACb,8BAA8B;YAC9B,iDAAiD;YACjD,IAAI;YACJ,IAAI,GAAG,KAAK,CAAC,OAAO,CAAA;QACxB,CAAC;QAED,MAAM,QAAQ,GACV,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAG,iBAAiB,CAAC,mCAClC,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAA;QAE5C,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC/C,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;AACxC,CAAC"}
package/rollup.config.mjs DELETED
@@ -1,94 +0,0 @@
1
- import resolve from "@rollup/plugin-node-resolve"
2
- import replace from "@rollup/plugin-replace"
3
- import dts from "rollup-plugin-dts"
4
- import pkg from "./package.json" with { type: "json"}
5
- import tsconfig from "./tsconfig.json" with { type: "json" }
6
- import preserveDirectives from "rollup-plugin-preserve-directives";
7
-
8
- const config = {
9
- input: "lib/index.js",
10
- }
11
-
12
- export const replaceSettings = (env) => {
13
- const replaceConfig = env
14
- ? {
15
- "process.env.NODE_ENV": JSON.stringify(env),
16
- preventAssignment: false,
17
- }
18
- : {
19
- preventAssignment: false,
20
- }
21
-
22
- replaceConfig.__VERSION__ = `${pkg.version}`
23
-
24
- return replace(replaceConfig)
25
- }
26
-
27
- const external = [
28
- ...Object.keys(pkg.dependencies || {}),
29
- ...Object.keys(pkg.peerDependencies || {}),
30
- ...Object.keys(pkg.optionalDependencies || {}),
31
- "react/jsx-runtime",
32
- ]
33
-
34
- const cjs = Object.assign({}, config, {
35
- input: "lib/index.js",
36
- output: {
37
- entryFileNames: `[name].js`,
38
- dir: "dist/cjs",
39
- format: "cjs",
40
- exports: "named",
41
- esModule: true
42
- },
43
- plugins: [resolve(), replaceSettings()],
44
- external,
45
- onwarn(warning, warn) {
46
- if (warning.code === 'MODULE_LEVEL_DIRECTIVE') {
47
- return
48
- }
49
- warn(warning)
50
- }
51
- })
52
-
53
-
54
- export const es = Object.assign({}, config, {
55
- input: ["lib/index.js"],
56
- output: {
57
- entryFileNames: "[name].mjs",
58
- format: "es",
59
- exports: "named",
60
- preserveModules: true,
61
- dir: "dist/es",
62
- },
63
- plugins: [resolve(), replaceSettings(), preserveDirectives()],
64
- external,
65
- onwarn(warning, warn) {
66
- if (warning.code === 'MODULE_LEVEL_DIRECTIVE') {
67
- return
68
- }
69
- warn(warning)
70
- }
71
- })
72
-
73
- const typePlugins = [dts({compilerOptions: {...tsconfig, baseUrl:"types"}})]
74
-
75
- function createTypes(input, file) {
76
- return {
77
- input,
78
- output: {
79
- format: "es",
80
- file: file,
81
- },
82
- plugins: typePlugins,
83
- }
84
- }
85
-
86
-
87
- const types = createTypes("types/index.d.ts", "dist/index.d.ts")
88
-
89
- // eslint-disable-next-line import/no-default-export
90
- export default [
91
- cjs,
92
- es,
93
- types,
94
- ]
@@ -1,8 +0,0 @@
1
- export const isDragging = {
2
- x: false,
3
- y: false,
4
- }
5
-
6
- export function isDragActive() {
7
- return isDragging.x || isDragging.y
8
- }
@@ -1,23 +0,0 @@
1
- import { isDragging } from "./is-active"
2
-
3
- export function setDragLock(axis: boolean | "x" | "y" | "lockDirection") {
4
- if (axis === "x" || axis === "y") {
5
- if (isDragging[axis]) {
6
- return null
7
- } else {
8
- isDragging[axis] = true
9
- return () => {
10
- isDragging[axis] = false
11
- }
12
- }
13
- } else {
14
- if (isDragging.x || isDragging.y) {
15
- return null
16
- } else {
17
- isDragging.x = isDragging.y = true
18
- return () => {
19
- isDragging.x = isDragging.y = false
20
- }
21
- }
22
- }
23
- }
@@ -1,70 +0,0 @@
1
- import { ElementOrSelector } from "../utils/resolve-elements"
2
- import { isDragActive } from "./drag/state/is-active"
3
- import { EventOptions } from "./types"
4
- import { setupGesture } from "./utils/setup"
5
-
6
- /**
7
- * A function to be called when a hover gesture starts.
8
- *
9
- * This function can optionally return a function that will be called
10
- * when the hover gesture ends.
11
- *
12
- * @public
13
- */
14
- export type OnHoverStartEvent = (event: PointerEvent) => void | OnHoverEndEvent
15
-
16
- /**
17
- * A function to be called when a hover gesture ends.
18
- *
19
- * @public
20
- */
21
- export type OnHoverEndEvent = (event: PointerEvent) => void
22
-
23
- /**
24
- * Filter out events that are not pointer events, or are triggering
25
- * while a Motion gesture is active.
26
- */
27
- function filterEvents(callback: OnHoverStartEvent) {
28
- return (event: PointerEvent) => {
29
- if (event.pointerType === "touch" || isDragActive()) return
30
- callback(event)
31
- }
32
- }
33
-
34
- /**
35
- * Create a hover gesture. hover() is different to .addEventListener("pointerenter")
36
- * in that it has an easier syntax, filters out polyfilled touch events, interoperates
37
- * with drag gestures, and automatically removes the "pointerennd" event listener when the hover ends.
38
- *
39
- * @public
40
- */
41
- export function hover(
42
- elementOrSelector: ElementOrSelector,
43
- onHoverStart: OnHoverStartEvent,
44
- options: EventOptions = {}
45
- ): VoidFunction {
46
- const [elements, eventOptions, cancel] = setupGesture(
47
- elementOrSelector,
48
- options
49
- )
50
-
51
- const onPointerEnter = filterEvents((enterEvent: PointerEvent) => {
52
- const { target } = enterEvent
53
- const onHoverEnd = onHoverStart(enterEvent)
54
-
55
- if (!onHoverEnd || !target) return
56
-
57
- const onPointerLeave = filterEvents((leaveEvent: PointerEvent) => {
58
- onHoverEnd(leaveEvent)
59
- target.removeEventListener("pointerleave", onPointerLeave)
60
- })
61
-
62
- target.addEventListener("pointerleave", onPointerLeave, eventOptions)
63
- })
64
-
65
- elements.forEach((element) => {
66
- element.addEventListener("pointerenter", onPointerEnter, eventOptions)
67
- })
68
-
69
- return cancel
70
- }
@@ -1,109 +0,0 @@
1
- import { ElementOrSelector } from "../../utils/resolve-elements"
2
- import { isDragActive } from "../drag/state/is-active"
3
- import { EventOptions } from "../types"
4
- import { isPrimaryPointer } from "../utils/is-primary-pointer"
5
- import { setupGesture } from "../utils/setup"
6
- import { enableKeyboardPress } from "./utils/keyboard"
7
- import { OnPressStartEvent } from "./types"
8
- import { isElementKeyboardAccessible } from "./utils/is-keyboard-accessible"
9
- import { isNodeOrChild } from "../utils/is-node-or-child"
10
- import { isPressing } from "./utils/state"
11
-
12
- /**
13
- * Filter out events that are not primary pointer events, or are triggering
14
- * while a Motion gesture is active.
15
- */
16
- function isValidPressEvent(event: PointerEvent) {
17
- return isPrimaryPointer(event) && !isDragActive()
18
- }
19
-
20
- export interface PointerEventOptions extends EventOptions {
21
- useGlobalTarget?: boolean
22
- }
23
-
24
- /**
25
- * Create a press gesture.
26
- *
27
- * Press is different to `"pointerdown"`, `"pointerup"` in that it
28
- * automatically filters out secondary pointer events like right
29
- * click and multitouch.
30
- *
31
- * It also adds accessibility support for keyboards, where
32
- * an element with a press gesture will receive focus and
33
- * trigger on Enter `"keydown"` and `"keyup"` events.
34
- *
35
- * This is different to a browser's `"click"` event, which does
36
- * respond to keyboards but only for the `"click"` itself, rather
37
- * than the press start and end/cancel. The element also needs
38
- * to be focusable for this to work, whereas a press gesture will
39
- * make an element focusable by default.
40
- *
41
- * @public
42
- */
43
- export function press(
44
- elementOrSelector: ElementOrSelector,
45
- onPressStart: OnPressStartEvent,
46
- options: PointerEventOptions = {}
47
- ): VoidFunction {
48
- const [elements, eventOptions, cancelEvents] = setupGesture(
49
- elementOrSelector,
50
- options
51
- )
52
-
53
- const startPress = (startEvent: PointerEvent) => {
54
- const element = startEvent.currentTarget as Element
55
-
56
- if (!isValidPressEvent(startEvent) || isPressing.has(element)) return
57
-
58
- isPressing.add(element)
59
-
60
- const onPressEnd = onPressStart(startEvent)
61
-
62
- const onPointerEnd = (endEvent: PointerEvent, success: boolean) => {
63
- window.removeEventListener("pointerup", onPointerUp)
64
- window.removeEventListener("pointercancel", onPointerCancel)
65
-
66
- if (!isValidPressEvent(endEvent) || !isPressing.has(element)) {
67
- return
68
- }
69
-
70
- isPressing.delete(element)
71
-
72
- if (onPressEnd) {
73
- onPressEnd(endEvent, { success })
74
- }
75
- }
76
-
77
- const onPointerUp = (upEvent: PointerEvent) => {
78
- onPointerEnd(
79
- upEvent,
80
- options.useGlobalTarget ||
81
- isNodeOrChild(element, upEvent.target as Element)
82
- )
83
- }
84
-
85
- const onPointerCancel = (cancelEvent: PointerEvent) => {
86
- onPointerEnd(cancelEvent, false)
87
- }
88
-
89
- window.addEventListener("pointerup", onPointerUp, eventOptions)
90
- window.addEventListener("pointercancel", onPointerCancel, eventOptions)
91
- }
92
-
93
- elements.forEach((element: HTMLElement) => {
94
- if (!isElementKeyboardAccessible(element)) {
95
- element.tabIndex = 0
96
- }
97
-
98
- const target = options.useGlobalTarget ? window : element
99
- target.addEventListener("pointerdown", startPress, eventOptions)
100
-
101
- element.addEventListener(
102
- "focus",
103
- (event) => enableKeyboardPress(event, eventOptions),
104
- eventOptions
105
- )
106
- })
107
-
108
- return cancelEvents
109
- }
@@ -1,10 +0,0 @@
1
- export interface PressGestureInfo {
2
- success: boolean
3
- }
4
-
5
- export type OnPressEndEvent = (
6
- event: PointerEvent,
7
- info: PressGestureInfo
8
- ) => void
9
-
10
- export type OnPressStartEvent = (event: PointerEvent) => OnPressEndEvent | void
@@ -1,11 +0,0 @@
1
- const focusableElements = new Set([
2
- "BUTTON",
3
- "INPUT",
4
- "SELECT",
5
- "TEXTAREA",
6
- "A",
7
- ])
8
-
9
- export function isElementKeyboardAccessible(element: HTMLElement) {
10
- return focusableElements.has(element.tagName) || element.tabIndex !== -1
11
- }
@@ -1,51 +0,0 @@
1
- import { isPressing } from "./state"
2
-
3
- /**
4
- * Filter out events that are not "Enter" keys.
5
- */
6
- function filterEvents(callback: (event: KeyboardEvent) => void) {
7
- return (event: KeyboardEvent) => {
8
- if (event.key !== "Enter") return
9
- callback(event)
10
- }
11
- }
12
-
13
- function firePointerEvent(target: EventTarget, type: "down" | "up" | "cancel") {
14
- target.dispatchEvent(
15
- new PointerEvent("pointer" + type, { isPrimary: true, bubbles: true })
16
- )
17
- }
18
-
19
- export const enableKeyboardPress = (
20
- focusEvent: FocusEvent,
21
- eventOptions: AddEventListenerOptions
22
- ) => {
23
- const element = focusEvent.currentTarget as HTMLElement
24
- if (!element) return
25
-
26
- const handleKeydown = filterEvents(() => {
27
- if (isPressing.has(element)) return
28
-
29
- firePointerEvent(element, "down")
30
-
31
- const handleKeyup = filterEvents(() => {
32
- firePointerEvent(element, "up")
33
- })
34
-
35
- const handleBlur = () => firePointerEvent(element, "cancel")
36
-
37
- element.addEventListener("keyup", handleKeyup, eventOptions)
38
- element.addEventListener("blur", handleBlur, eventOptions)
39
- })
40
-
41
- element.addEventListener("keydown", handleKeydown, eventOptions)
42
-
43
- /**
44
- * Add an event listener that fires on blur to remove the keydown events.
45
- */
46
- element.addEventListener(
47
- "blur",
48
- () => element.removeEventListener("keydown", handleKeydown),
49
- eventOptions
50
- )
51
- }
@@ -1 +0,0 @@
1
- export const isPressing = new WeakSet<Element>()
@@ -1,21 +0,0 @@
1
- /**
2
- * Options for the hover gesture.
3
- *
4
- * @public
5
- */
6
- export interface EventOptions {
7
- /**
8
- * Use passive event listeners. Doing so allows the browser to optimize
9
- * scrolling performance by not allowing the use of `preventDefault()`.
10
- *
11
- * @default true
12
- */
13
- passive?: boolean
14
-
15
- /**
16
- * Remove the event listener after the first event.
17
- *
18
- * @default false
19
- */
20
- once?: boolean
21
- }
@@ -1,48 +0,0 @@
1
- import { isPrimaryPointer } from "../is-primary-pointer"
2
-
3
- describe("isPrimaryPointer", () => {
4
- test("Identifies primary pointer", () => {
5
- expect(
6
- isPrimaryPointer({
7
- button: 1,
8
- isPrimary: true,
9
- pointerType: "mouse",
10
- } as any)
11
- ).toEqual(false)
12
- expect(
13
- isPrimaryPointer({
14
- button: 1,
15
- isPrimary: true,
16
- pointerType: "touch",
17
- } as any)
18
- ).toEqual(true)
19
- expect(
20
- isPrimaryPointer({
21
- button: 0,
22
- isPrimary: true,
23
- pointerType: "mouse",
24
- } as any)
25
- ).toEqual(true)
26
- expect(
27
- isPrimaryPointer({
28
- button: -1,
29
- isPrimary: false,
30
- pointerType: "mouse",
31
- } as any)
32
- ).toEqual(true)
33
- expect(
34
- isPrimaryPointer({
35
- button: undefined,
36
- isPrimary: false,
37
- pointerType: "mouse",
38
- } as any)
39
- ).toEqual(true)
40
- expect(
41
- isPrimaryPointer({
42
- button: null,
43
- isPrimary: false,
44
- pointerType: "mouse",
45
- } as any)
46
- ).toEqual(true)
47
- })
48
- })
@@ -1,19 +0,0 @@
1
- /**
2
- * Recursively traverse up the tree to check whether the provided child node
3
- * is the parent or a descendant of it.
4
- *
5
- * @param parent - Element to find
6
- * @param child - Element to test against parent
7
- */
8
- export const isNodeOrChild = (
9
- parent: Element | null,
10
- child?: Element | null
11
- ): boolean => {
12
- if (!child) {
13
- return false
14
- } else if (parent === child) {
15
- return true
16
- } else {
17
- return isNodeOrChild(parent, child.parentElement)
18
- }
19
- }
@@ -1,15 +0,0 @@
1
- export const isPrimaryPointer = (event: PointerEvent) => {
2
- if (event.pointerType === "mouse") {
3
- return typeof event.button !== "number" || event.button <= 0
4
- } else {
5
- /**
6
- * isPrimary is true for all mice buttons, whereas every touch point
7
- * is regarded as its own input. So subsequent concurrent touch points
8
- * will be false.
9
- *
10
- * Specifically match against false here as incomplete versions of
11
- * PointerEvents in very old browser might have it set as undefined.
12
- */
13
- return event.isPrimary !== false
14
- }
15
- }
@@ -1,23 +0,0 @@
1
- import {
2
- ElementOrSelector,
3
- resolveElements,
4
- } from "../../utils/resolve-elements"
5
- import { EventOptions } from "../types"
6
- export function setupGesture(
7
- elementOrSelector: ElementOrSelector,
8
- options: EventOptions
9
- ): [Element[], AddEventListenerOptions, VoidFunction] {
10
- const elements = resolveElements(elementOrSelector)
11
-
12
- const gestureAbortController = new AbortController()
13
-
14
- const eventOptions = {
15
- passive: true,
16
- ...options,
17
- signal: gestureAbortController.signal,
18
- }
19
-
20
- const cancel = () => gestureAbortController.abort()
21
-
22
- return [elements, eventOptions, cancel]
23
- }
package/src/index.ts DELETED
@@ -1,10 +0,0 @@
1
- export * from "./gestures/hover"
2
- export * from "./gestures/press"
3
- export * from "./gestures/press/types"
4
- export * from "./gestures/types"
5
-
6
- export * from "./utils/resolve-elements"
7
- export * from "./gestures/drag/state/is-active"
8
- export * from "./gestures/drag/state/set-active"
9
- export * from "./gestures/utils/is-primary-pointer"
10
- export * from "./gestures/utils/is-node-or-child"
@@ -1,47 +0,0 @@
1
- export type ElementOrSelector =
2
- | Element
3
- | Element[]
4
- | NodeListOf<Element>
5
- | string
6
-
7
- export interface WithQuerySelectorAll {
8
- querySelectorAll: Element["querySelectorAll"]
9
- }
10
-
11
- export interface AnimationScope<T = any> {
12
- readonly current: T
13
- animations: any[] // TODO: Refactor to types package AnimationPlaybackControls[]
14
- }
15
-
16
- export interface SelectorCache {
17
- [key: string]: NodeListOf<Element>
18
- }
19
-
20
- export function resolveElements(
21
- elementOrSelector: ElementOrSelector,
22
- scope?: AnimationScope,
23
- selectorCache?: SelectorCache
24
- ): Element[] {
25
- if (elementOrSelector instanceof Element) {
26
- return [elementOrSelector]
27
- } else if (typeof elementOrSelector === "string") {
28
- let root: WithQuerySelectorAll = document
29
-
30
- if (scope) {
31
- // TODO: Refactor to utils package
32
- // invariant(
33
- // Boolean(scope.current),
34
- // "Scope provided, but no element detected."
35
- // )
36
- root = scope.current
37
- }
38
-
39
- const elements =
40
- selectorCache?.[elementOrSelector] ??
41
- root.querySelectorAll(elementOrSelector)
42
-
43
- return elements ? Array.from(elements) : []
44
- }
45
-
46
- return Array.from(elementOrSelector)
47
- }
package/tsconfig.json DELETED
@@ -1,25 +0,0 @@
1
- {
2
- "extends": "config/tsconfig.json",
3
- "filesGlob": ["./src/**/*.ts"],
4
- "exclude": [
5
- "node_modules",
6
- "build",
7
- "**/__tests__/*",
8
- "jest.setup.tsx",
9
- "dev",
10
- "types",
11
- "dev/examples.framer",
12
- "test",
13
- "skins",
14
- "dist",
15
- "temp",
16
- "api",
17
- "cypress"
18
- ],
19
- "compilerOptions": {
20
- "baseUrl": "src",
21
- "declarationDir": "types",
22
- "outDir": "lib",
23
- "rootDir": "src"
24
- }
25
- }
@@ -1,5 +0,0 @@
1
- export declare const isDragging: {
2
- x: boolean;
3
- y: boolean;
4
- };
5
- export declare function isDragActive(): boolean;
@@ -1 +0,0 @@
1
- export declare function setDragLock(axis: boolean | "x" | "y" | "lockDirection"): (() => void) | null;
@@ -1,25 +0,0 @@
1
- import { ElementOrSelector } from "../utils/resolve-elements";
2
- import { EventOptions } from "./types";
3
- /**
4
- * A function to be called when a hover gesture starts.
5
- *
6
- * This function can optionally return a function that will be called
7
- * when the hover gesture ends.
8
- *
9
- * @public
10
- */
11
- export type OnHoverStartEvent = (event: PointerEvent) => void | OnHoverEndEvent;
12
- /**
13
- * A function to be called when a hover gesture ends.
14
- *
15
- * @public
16
- */
17
- export type OnHoverEndEvent = (event: PointerEvent) => void;
18
- /**
19
- * Create a hover gesture. hover() is different to .addEventListener("pointerenter")
20
- * in that it has an easier syntax, filters out polyfilled touch events, interoperates
21
- * with drag gestures, and automatically removes the "pointerennd" event listener when the hover ends.
22
- *
23
- * @public
24
- */
25
- export declare function hover(elementOrSelector: ElementOrSelector, onHoverStart: OnHoverStartEvent, options?: EventOptions): VoidFunction;
@@ -1,26 +0,0 @@
1
- import { ElementOrSelector } from "../../utils/resolve-elements";
2
- import { EventOptions } from "../types";
3
- import { OnPressStartEvent } from "./types";
4
- export interface PointerEventOptions extends EventOptions {
5
- useGlobalTarget?: boolean;
6
- }
7
- /**
8
- * Create a press gesture.
9
- *
10
- * Press is different to `"pointerdown"`, `"pointerup"` in that it
11
- * automatically filters out secondary pointer events like right
12
- * click and multitouch.
13
- *
14
- * It also adds accessibility support for keyboards, where
15
- * an element with a press gesture will receive focus and
16
- * trigger on Enter `"keydown"` and `"keyup"` events.
17
- *
18
- * This is different to a browser's `"click"` event, which does
19
- * respond to keyboards but only for the `"click"` itself, rather
20
- * than the press start and end/cancel. The element also needs
21
- * to be focusable for this to work, whereas a press gesture will
22
- * make an element focusable by default.
23
- *
24
- * @public
25
- */
26
- export declare function press(elementOrSelector: ElementOrSelector, onPressStart: OnPressStartEvent, options?: PointerEventOptions): VoidFunction;
@@ -1,5 +0,0 @@
1
- export interface PressGestureInfo {
2
- success: boolean;
3
- }
4
- export type OnPressEndEvent = (event: PointerEvent, info: PressGestureInfo) => void;
5
- export type OnPressStartEvent = (event: PointerEvent) => OnPressEndEvent | void;
@@ -1 +0,0 @@
1
- export declare function isElementKeyboardAccessible(element: HTMLElement): boolean;
@@ -1 +0,0 @@
1
- export declare const enableKeyboardPress: (focusEvent: FocusEvent, eventOptions: AddEventListenerOptions) => void;
@@ -1 +0,0 @@
1
- export declare const isPressing: WeakSet<Element>;
@@ -1,20 +0,0 @@
1
- /**
2
- * Options for the hover gesture.
3
- *
4
- * @public
5
- */
6
- export interface EventOptions {
7
- /**
8
- * Use passive event listeners. Doing so allows the browser to optimize
9
- * scrolling performance by not allowing the use of `preventDefault()`.
10
- *
11
- * @default true
12
- */
13
- passive?: boolean;
14
- /**
15
- * Remove the event listener after the first event.
16
- *
17
- * @default false
18
- */
19
- once?: boolean;
20
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Recursively traverse up the tree to check whether the provided child node
3
- * is the parent or a descendant of it.
4
- *
5
- * @param parent - Element to find
6
- * @param child - Element to test against parent
7
- */
8
- export declare const isNodeOrChild: (parent: Element | null, child?: Element | null) => boolean;
@@ -1 +0,0 @@
1
- export declare const isPrimaryPointer: (event: PointerEvent) => boolean;
@@ -1,3 +0,0 @@
1
- import { ElementOrSelector } from "../../utils/resolve-elements";
2
- import { EventOptions } from "../types";
3
- export declare function setupGesture(elementOrSelector: ElementOrSelector, options: EventOptions): [Element[], AddEventListenerOptions, VoidFunction];
package/types/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export * from "./gestures/hover";
2
- export * from "./gestures/press";
3
- export * from "./gestures/press/types";
4
- export * from "./gestures/types";
5
- export * from "./utils/resolve-elements";
6
- export * from "./gestures/drag/state/is-active";
7
- export * from "./gestures/drag/state/set-active";
8
- export * from "./gestures/utils/is-primary-pointer";
9
- export * from "./gestures/utils/is-node-or-child";
@@ -1,12 +0,0 @@
1
- export type ElementOrSelector = Element | Element[] | NodeListOf<Element> | string;
2
- export interface WithQuerySelectorAll {
3
- querySelectorAll: Element["querySelectorAll"];
4
- }
5
- export interface AnimationScope<T = any> {
6
- readonly current: T;
7
- animations: any[];
8
- }
9
- export interface SelectorCache {
10
- [key: string]: NodeListOf<Element>;
11
- }
12
- export declare function resolveElements(elementOrSelector: ElementOrSelector, scope?: AnimationScope, selectorCache?: SelectorCache): Element[];