@hanzogui/react-native-use-responder-events 2.0.0

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 (74) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/ResponderSystem.cjs +251 -0
  3. package/dist/cjs/ResponderSystem.native.js +253 -0
  4. package/dist/cjs/ResponderSystem.native.js.map +1 -0
  5. package/dist/cjs/ResponderTouchHistoryStore.cjs +112 -0
  6. package/dist/cjs/ResponderTouchHistoryStore.native.js +156 -0
  7. package/dist/cjs/ResponderTouchHistoryStore.native.js.map +1 -0
  8. package/dist/cjs/createResponderEvent.cjs +135 -0
  9. package/dist/cjs/createResponderEvent.native.js +140 -0
  10. package/dist/cjs/createResponderEvent.native.js.map +1 -0
  11. package/dist/cjs/index.cjs +18 -0
  12. package/dist/cjs/index.native.js +21 -0
  13. package/dist/cjs/index.native.js.map +1 -0
  14. package/dist/cjs/types.cjs +76 -0
  15. package/dist/cjs/types.native.js +79 -0
  16. package/dist/cjs/types.native.js.map +1 -0
  17. package/dist/cjs/useResponderEvents.cjs +95 -0
  18. package/dist/cjs/useResponderEvents.native.js +102 -0
  19. package/dist/cjs/useResponderEvents.native.js.map +1 -0
  20. package/dist/cjs/utils.cjs +126 -0
  21. package/dist/cjs/utils.native.js +126 -0
  22. package/dist/cjs/utils.native.js.map +1 -0
  23. package/dist/esm/ResponderSystem.mjs +224 -0
  24. package/dist/esm/ResponderSystem.mjs.map +1 -0
  25. package/dist/esm/ResponderSystem.native.js +223 -0
  26. package/dist/esm/ResponderSystem.native.js.map +1 -0
  27. package/dist/esm/ResponderTouchHistoryStore.mjs +89 -0
  28. package/dist/esm/ResponderTouchHistoryStore.mjs.map +1 -0
  29. package/dist/esm/ResponderTouchHistoryStore.native.js +130 -0
  30. package/dist/esm/ResponderTouchHistoryStore.native.js.map +1 -0
  31. package/dist/esm/createResponderEvent.mjs +112 -0
  32. package/dist/esm/createResponderEvent.mjs.map +1 -0
  33. package/dist/esm/createResponderEvent.native.js +114 -0
  34. package/dist/esm/createResponderEvent.native.js.map +1 -0
  35. package/dist/esm/index.js +2 -0
  36. package/dist/esm/index.js.map +1 -0
  37. package/dist/esm/index.mjs +2 -0
  38. package/dist/esm/index.mjs.map +1 -0
  39. package/dist/esm/index.native.js +2 -0
  40. package/dist/esm/index.native.js.map +1 -0
  41. package/dist/esm/types.mjs +34 -0
  42. package/dist/esm/types.mjs.map +1 -0
  43. package/dist/esm/types.native.js +34 -0
  44. package/dist/esm/types.native.js.map +1 -0
  45. package/dist/esm/useResponderEvents.mjs +59 -0
  46. package/dist/esm/useResponderEvents.mjs.map +1 -0
  47. package/dist/esm/useResponderEvents.native.js +63 -0
  48. package/dist/esm/useResponderEvents.native.js.map +1 -0
  49. package/dist/esm/utils.mjs +95 -0
  50. package/dist/esm/utils.mjs.map +1 -0
  51. package/dist/esm/utils.native.js +92 -0
  52. package/dist/esm/utils.native.js.map +1 -0
  53. package/package.json +42 -0
  54. package/src/ResponderSystem.ts +555 -0
  55. package/src/ResponderTouchHistoryStore.ts +211 -0
  56. package/src/createResponderEvent.ts +190 -0
  57. package/src/index.ts +1 -0
  58. package/src/types.ts +78 -0
  59. package/src/useResponderEvents.ts +107 -0
  60. package/src/utils.ts +196 -0
  61. package/types/ResponderSystem.d.ts +47 -0
  62. package/types/ResponderSystem.d.ts.map +1 -0
  63. package/types/ResponderTouchHistoryStore.d.ts +37 -0
  64. package/types/ResponderTouchHistoryStore.d.ts.map +1 -0
  65. package/types/createResponderEvent.d.ts +36 -0
  66. package/types/createResponderEvent.d.ts.map +1 -0
  67. package/types/index.d.ts +2 -0
  68. package/types/index.d.ts.map +1 -0
  69. package/types/types.d.ts +52 -0
  70. package/types/types.d.ts.map +1 -0
  71. package/types/useResponderEvents.d.ts +10 -0
  72. package/types/useResponderEvents.d.ts.map +1 -0
  73. package/types/utils.d.ts +38 -0
  74. package/types/utils.d.ts.map +1 -0
@@ -0,0 +1,95 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf,
6
+ __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ },
20
+ __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")),
21
+ __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
27
+ value: mod,
28
+ enumerable: !0
29
+ }) : target, mod)),
30
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
31
+ value: !0
32
+ }), mod);
33
+ var useResponderEvents_exports = {};
34
+ __export(useResponderEvents_exports, {
35
+ getResponderConfigIfDefined: () => getResponderConfigIfDefined,
36
+ useResponderEvents: () => useResponderEvents
37
+ });
38
+ module.exports = __toCommonJS(useResponderEvents_exports);
39
+ var React = __toESM(require("react"), 1),
40
+ ResponderSystem = __toESM(require("./ResponderSystem.cjs"), 1);
41
+ __reExport(useResponderEvents_exports, require("./utils.cjs"), module.exports);
42
+ const emptyObject = {},
43
+ Attached = /* @__PURE__ */new WeakMap(),
44
+ Ids = /* @__PURE__ */new WeakMap();
45
+ function useResponderEvents(hostRef, configIn = emptyObject) {
46
+ const config = getResponderConfigIfDefined(configIn),
47
+ node = hostRef?.current?.host || hostRef?.current;
48
+ React.useEffect(() => {
49
+ if (config === emptyObject) return;
50
+ ResponderSystem.attachListeners(), Ids.has(hostRef) || Ids.set(hostRef, `${Math.random()}`);
51
+ const id = Ids.get(hostRef);
52
+ return ResponderSystem.addNode(id, node, config), Attached.set(hostRef, !0), () => {
53
+ ResponderSystem.removeNode(node), Attached.set(hostRef, !1);
54
+ };
55
+ }, [config, hostRef]), process.env.NODE_ENV === "development" && (React.useDebugValue({
56
+ isResponder: node === ResponderSystem.getResponderNode()
57
+ }), React.useDebugValue(config));
58
+ }
59
+ function getResponderConfigIfDefined({
60
+ onMoveShouldSetResponder,
61
+ onMoveShouldSetResponderCapture,
62
+ onResponderEnd,
63
+ onResponderGrant,
64
+ onResponderMove,
65
+ onResponderReject,
66
+ onResponderRelease,
67
+ onResponderStart,
68
+ onResponderTerminate,
69
+ onResponderTerminationRequest,
70
+ onScrollShouldSetResponder,
71
+ onScrollShouldSetResponderCapture,
72
+ onSelectionChangeShouldSetResponder,
73
+ onSelectionChangeShouldSetResponderCapture,
74
+ onStartShouldSetResponder,
75
+ onStartShouldSetResponderCapture
76
+ }) {
77
+ return onMoveShouldSetResponder || onMoveShouldSetResponderCapture || onResponderEnd || onResponderGrant || onResponderMove || onResponderReject || onResponderRelease || onResponderStart || onResponderTerminate || onResponderTerminationRequest || onScrollShouldSetResponder || onScrollShouldSetResponderCapture || onSelectionChangeShouldSetResponder || onSelectionChangeShouldSetResponderCapture || onStartShouldSetResponder || onStartShouldSetResponderCapture ? {
78
+ onMoveShouldSetResponder,
79
+ onMoveShouldSetResponderCapture,
80
+ onResponderEnd,
81
+ onResponderGrant,
82
+ onResponderMove,
83
+ onResponderReject,
84
+ onResponderRelease,
85
+ onResponderStart,
86
+ onResponderTerminate,
87
+ onResponderTerminationRequest,
88
+ onScrollShouldSetResponder,
89
+ onScrollShouldSetResponderCapture,
90
+ onSelectionChangeShouldSetResponder,
91
+ onSelectionChangeShouldSetResponderCapture,
92
+ onStartShouldSetResponder,
93
+ onStartShouldSetResponderCapture
94
+ } : emptyObject;
95
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf,
8
+ __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: !0
13
+ });
14
+ },
15
+ __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ return to;
21
+ },
22
+ __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")),
23
+ __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
29
+ value: mod,
30
+ enumerable: !0
31
+ }) : target, mod)),
32
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
33
+ value: !0
34
+ }), mod);
35
+ var useResponderEvents_exports = {};
36
+ __export(useResponderEvents_exports, {
37
+ getResponderConfigIfDefined: () => getResponderConfigIfDefined,
38
+ useResponderEvents: () => useResponderEvents
39
+ });
40
+ module.exports = __toCommonJS(useResponderEvents_exports);
41
+ var React = __toESM(require("react"), 1),
42
+ ResponderSystem = __toESM(require("./ResponderSystem.native.js"), 1);
43
+ __reExport(useResponderEvents_exports, require("./utils.native.js"), module.exports);
44
+ var emptyObject = {},
45
+ Attached = /* @__PURE__ */new WeakMap(),
46
+ Ids = /* @__PURE__ */new WeakMap();
47
+ function useResponderEvents(hostRef) {
48
+ var configIn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : emptyObject,
49
+ _hostRef_current,
50
+ config = getResponderConfigIfDefined(configIn),
51
+ node = (hostRef == null || (_hostRef_current = hostRef.current) === null || _hostRef_current === void 0 ? void 0 : _hostRef_current.host) || hostRef?.current;
52
+ React.useEffect(function () {
53
+ if (config !== emptyObject) {
54
+ ResponderSystem.attachListeners(), Ids.has(hostRef) || Ids.set(hostRef, `${Math.random()}`);
55
+ var id = Ids.get(hostRef);
56
+ return ResponderSystem.addNode(id, node, config), Attached.set(hostRef, !0), function () {
57
+ ResponderSystem.removeNode(node), Attached.set(hostRef, !1);
58
+ };
59
+ }
60
+ }, [config, hostRef]), process.env.NODE_ENV === "development" && (React.useDebugValue({
61
+ isResponder: node === ResponderSystem.getResponderNode()
62
+ }), React.useDebugValue(config));
63
+ }
64
+ function getResponderConfigIfDefined(param) {
65
+ var {
66
+ onMoveShouldSetResponder,
67
+ onMoveShouldSetResponderCapture,
68
+ onResponderEnd,
69
+ onResponderGrant,
70
+ onResponderMove,
71
+ onResponderReject,
72
+ onResponderRelease,
73
+ onResponderStart,
74
+ onResponderTerminate,
75
+ onResponderTerminationRequest,
76
+ onScrollShouldSetResponder,
77
+ onScrollShouldSetResponderCapture,
78
+ onSelectionChangeShouldSetResponder,
79
+ onSelectionChangeShouldSetResponderCapture,
80
+ onStartShouldSetResponder,
81
+ onStartShouldSetResponderCapture
82
+ } = param;
83
+ return onMoveShouldSetResponder || onMoveShouldSetResponderCapture || onResponderEnd || onResponderGrant || onResponderMove || onResponderReject || onResponderRelease || onResponderStart || onResponderTerminate || onResponderTerminationRequest || onScrollShouldSetResponder || onScrollShouldSetResponderCapture || onSelectionChangeShouldSetResponder || onSelectionChangeShouldSetResponderCapture || onStartShouldSetResponder || onStartShouldSetResponderCapture ? {
84
+ onMoveShouldSetResponder,
85
+ onMoveShouldSetResponderCapture,
86
+ onResponderEnd,
87
+ onResponderGrant,
88
+ onResponderMove,
89
+ onResponderReject,
90
+ onResponderRelease,
91
+ onResponderStart,
92
+ onResponderTerminate,
93
+ onResponderTerminationRequest,
94
+ onScrollShouldSetResponder,
95
+ onScrollShouldSetResponderCapture,
96
+ onSelectionChangeShouldSetResponder,
97
+ onSelectionChangeShouldSetResponderCapture,
98
+ onStartShouldSetResponder,
99
+ onStartShouldSetResponderCapture
100
+ } : emptyObject;
101
+ }
102
+ //# sourceMappingURL=useResponderEvents.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useResponderEvents_exports","__export","getResponderConfigIfDefined","useResponderEvents","module","exports","React","__toESM","require","ResponderSystem","__reExport","emptyObject","Attached","WeakMap","Ids","hostRef","configIn","arguments","length","_hostRef_current","config","node","current","host","useEffect","attachListeners","has","set","Math","random","id","get","addNode","removeNode","process","env","NODE_ENV","useDebugValue","isResponder","getResponderNode","param","onMoveShouldSetResponder","onMoveShouldSetResponderCapture","onResponderEnd","onResponderGrant","onResponderMove","onResponderReject","onResponderRelease","onResponderStart","onResponderTerminate","onResponderTerminationRequest","onScrollShouldSetResponder","onScrollShouldSetResponderCapture","onSelectionChangeShouldSetResponder","onSelectionChangeShouldSetResponderCapture","onStartShouldSetResponder","onStartShouldSetResponderCapture"],"sources":["../../src/useResponderEvents.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,0BAAA;AAAA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LK,MAAA,EAEOL,OAAS,CACd,GAAAmB,OAAA,CAAAC,GAAA,CAAAC,QAAA,uBAAA9B,KAAA,CAAA+B,aAAA;IACAC,WAAA,EAAAjB,IAAA,KAAAZ,eAAA,CAAA8B,gBAAA;EACA,IAAAjC,KAAA,CAAA+B,aAAA,CAAAjB,MAAA;AAAA;AACA,SACAlB,4BAAAsC,KAAA;EACA;IAAAC,wBAAA;IAAAC,+BAAA;IAAAC,cAAA;IAAAC,gBAAA;IAAAC,eAAA;IAAAC,iBAAA;IAAAC,kBAAA;IAAAC,gBAAA;IAAAC,oBAAA;IAAAC,6BAAA;IAAAC,0BAAA;IAAAC,iCAAA;IAAAC,mCAAA;IAAAC,0CAAA;IAAAC,yBAAA;IAAAC;EAAA,IAAAhB,KAAA;EACA,OAAAC,wBAAA,IAAAC,+BAAA,IAAAC,cAAA,IAAAC,gBAAA,IAAAC,eAAA,IAAAC,iBAAA,IAAAC,kBAAA,IAAAC,gBAAA,IAAAC,oBAAA,IAAAC,6BAAA,IAAAC,0BAAA,IAAAC,iCAAA,IAAAC,mCAAA,IAAAC,0CAAA,IAAAC,yBAAA,IAAAC,gCAAA;IACAf,wBAAA;IACAC,+BAAA;IACAC,cAAA;IACAC,gBAAA;IACAC,eAAA;IACAC,iBAAA;IACAC,kBAAA;IACAC,gBAAA;IACAC,oBAAA;IACmEC,6BAAA;IACnEC,0BAAO;IAiBDC,iCAAA;IACAC,mCAAA;IACAC,0CAAA;IACAC,yBAAA;IACAC;EAAA,IACA7C,WAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,126 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
21
+ var utils_exports = {};
22
+ __export(utils_exports, {
23
+ canUseDOM: () => canUseDOM,
24
+ getBoundingClientRect: () => getBoundingClientRect,
25
+ getLowestCommonAncestor: () => getLowestCommonAncestor,
26
+ getResponderPaths: () => getResponderPaths,
27
+ hasTargetTouches: () => hasTargetTouches,
28
+ hasValidSelection: () => hasValidSelection,
29
+ isPrimaryPointerDown: () => isPrimaryPointerDown,
30
+ isSelectionValid: () => isSelectionValid,
31
+ setResponderId: () => setResponderId
32
+ });
33
+ module.exports = __toCommonJS(utils_exports);
34
+ const keyName = "__reactResponderId",
35
+ canUseDOM = !!(typeof window < "u" && window.document && window.document.createElement),
36
+ getBoundingClientRect = node => {
37
+ if (node && node.nodeType === 1 && node.getBoundingClientRect) return node.getBoundingClientRect();
38
+ };
39
+ function getEventPath(domEvent) {
40
+ if (domEvent.type === "selectionchange") {
41
+ const target = window.getSelection()?.anchorNode;
42
+ return composedPathFallback(target);
43
+ }
44
+ return domEvent.composedPath != null ? domEvent.composedPath() : composedPathFallback(domEvent.target);
45
+ }
46
+ function composedPathFallback(target) {
47
+ const path = [];
48
+ for (; target != null && target !== document.body;) path.push(target), target = target.parentNode;
49
+ return path;
50
+ }
51
+ function getResponderId(node) {
52
+ return node != null ? node[keyName] : null;
53
+ }
54
+ function setResponderId(node, id) {
55
+ node != null && (node[keyName] = id);
56
+ }
57
+ function getResponderPaths(domEvent) {
58
+ const idPath = [],
59
+ nodePath = [],
60
+ eventPath = getEventPath(domEvent);
61
+ for (let i = 0; i < eventPath.length; i++) {
62
+ const node = eventPath[i],
63
+ id = getResponderId(node);
64
+ id != null && (idPath.push(id), nodePath.push(node));
65
+ }
66
+ return {
67
+ idPath,
68
+ nodePath
69
+ };
70
+ }
71
+ function getLowestCommonAncestor(pathA, pathB) {
72
+ let pathALength = pathA.length,
73
+ pathBLength = pathB.length;
74
+ if (
75
+ // If either path is empty
76
+ pathALength === 0 || pathBLength === 0 ||
77
+ // If the last elements aren't the same there can't be a common ancestor
78
+ // that is connected to the responder system
79
+ pathA[pathALength - 1] !== pathB[pathBLength - 1]) return null;
80
+ let itemA = pathA[0],
81
+ indexA = 0,
82
+ itemB = pathB[0],
83
+ indexB = 0;
84
+ pathALength - pathBLength > 0 && (indexA = pathALength - pathBLength, itemA = pathA[indexA], pathALength = pathBLength), pathBLength - pathALength > 0 && (indexB = pathBLength - pathALength, itemB = pathB[indexB], pathBLength = pathALength);
85
+ let depth = pathALength;
86
+ for (; depth--;) {
87
+ if (itemA === itemB) return itemA;
88
+ itemA = pathA[indexA++], itemB = pathB[indexB++];
89
+ }
90
+ return null;
91
+ }
92
+ function hasTargetTouches(target, touches) {
93
+ if (!touches || touches.length === 0) return !1;
94
+ for (let i = 0; i < touches.length; i++) {
95
+ const node = touches[i].target;
96
+ if (node != null && target.contains(node)) return !0;
97
+ }
98
+ return !1;
99
+ }
100
+ function hasValidSelection(domEvent) {
101
+ return domEvent.type === "selectionchange" ? isSelectionValid() : domEvent.type === "select";
102
+ }
103
+ function isPrimaryPointerDown(domEvent) {
104
+ const {
105
+ altKey,
106
+ button,
107
+ buttons,
108
+ ctrlKey,
109
+ type
110
+ } = domEvent,
111
+ isTouch = type === "touchstart" || type === "touchmove",
112
+ isPrimaryMouseDown = type === "mousedown" && (button === 0 || buttons === 1),
113
+ isPrimaryMouseMove = type === "mousemove" && buttons === 1,
114
+ noModifiers = altKey === !1 && ctrlKey === !1;
115
+ return !!(isTouch || isPrimaryMouseDown && noModifiers || isPrimaryMouseMove && noModifiers);
116
+ }
117
+ function isSelectionValid() {
118
+ const selection = window.getSelection();
119
+ if (!selection) return !1;
120
+ const string = selection.toString(),
121
+ anchorNode = selection.anchorNode,
122
+ focusNode = selection.focusNode,
123
+ isTextNode = anchorNode && anchorNode.nodeType === window.Node.TEXT_NODE || focusNode && focusNode.nodeType === window.Node.TEXT_NODE;
124
+ return string.length >= 1 && string !== `
125
+ ` && !!isTextNode;
126
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: !0
22
+ }), mod);
23
+ var utils_exports = {};
24
+ __export(utils_exports, {
25
+ canUseDOM: () => canUseDOM,
26
+ getBoundingClientRect: () => getBoundingClientRect,
27
+ getLowestCommonAncestor: () => getLowestCommonAncestor,
28
+ getResponderPaths: () => getResponderPaths,
29
+ hasTargetTouches: () => hasTargetTouches,
30
+ hasValidSelection: () => hasValidSelection,
31
+ isPrimaryPointerDown: () => isPrimaryPointerDown,
32
+ isSelectionValid: () => isSelectionValid,
33
+ setResponderId: () => setResponderId
34
+ });
35
+ module.exports = __toCommonJS(utils_exports);
36
+ var keyName = "__reactResponderId",
37
+ canUseDOM = !!(typeof window < "u" && window.document && window.document.createElement),
38
+ getBoundingClientRect = function (node) {
39
+ if (node && node.nodeType === 1 && node.getBoundingClientRect) return node.getBoundingClientRect();
40
+ };
41
+ function getEventPath(domEvent) {
42
+ if (domEvent.type === "selectionchange") {
43
+ var _window_getSelection,
44
+ target = (_window_getSelection = window.getSelection()) === null || _window_getSelection === void 0 ? void 0 : _window_getSelection.anchorNode;
45
+ return composedPathFallback(target);
46
+ }
47
+ var path = domEvent.composedPath != null ? domEvent.composedPath() : composedPathFallback(domEvent.target);
48
+ return path;
49
+ }
50
+ function composedPathFallback(target) {
51
+ for (var path = []; target != null && target !== document.body;) path.push(target), target = target.parentNode;
52
+ return path;
53
+ }
54
+ function getResponderId(node) {
55
+ return node != null ? node[keyName] : null;
56
+ }
57
+ function setResponderId(node, id) {
58
+ node != null && (node[keyName] = id);
59
+ }
60
+ function getResponderPaths(domEvent) {
61
+ for (var idPath = [], nodePath = [], eventPath = getEventPath(domEvent), i = 0; i < eventPath.length; i++) {
62
+ var node = eventPath[i],
63
+ id = getResponderId(node);
64
+ id != null && (idPath.push(id), nodePath.push(node));
65
+ }
66
+ return {
67
+ idPath,
68
+ nodePath
69
+ };
70
+ }
71
+ function getLowestCommonAncestor(pathA, pathB) {
72
+ var pathALength = pathA.length,
73
+ pathBLength = pathB.length;
74
+ if (
75
+ // If either path is empty
76
+ pathALength === 0 || pathBLength === 0 ||
77
+ // If the last elements aren't the same there can't be a common ancestor
78
+ // that is connected to the responder system
79
+ pathA[pathALength - 1] !== pathB[pathBLength - 1]) return null;
80
+ var itemA = pathA[0],
81
+ indexA = 0,
82
+ itemB = pathB[0],
83
+ indexB = 0;
84
+ pathALength - pathBLength > 0 && (indexA = pathALength - pathBLength, itemA = pathA[indexA], pathALength = pathBLength), pathBLength - pathALength > 0 && (indexB = pathBLength - pathALength, itemB = pathB[indexB], pathBLength = pathALength);
85
+ for (var depth = pathALength; depth--;) {
86
+ if (itemA === itemB) return itemA;
87
+ itemA = pathA[indexA++], itemB = pathB[indexB++];
88
+ }
89
+ return null;
90
+ }
91
+ function hasTargetTouches(target, touches) {
92
+ if (!touches || touches.length === 0) return !1;
93
+ for (var i = 0; i < touches.length; i++) {
94
+ var node = touches[i].target;
95
+ if (node != null && target.contains(node)) return !0;
96
+ }
97
+ return !1;
98
+ }
99
+ function hasValidSelection(domEvent) {
100
+ return domEvent.type === "selectionchange" ? isSelectionValid() : domEvent.type === "select";
101
+ }
102
+ function isPrimaryPointerDown(domEvent) {
103
+ var {
104
+ altKey,
105
+ button,
106
+ buttons,
107
+ ctrlKey,
108
+ type
109
+ } = domEvent,
110
+ isTouch = type === "touchstart" || type === "touchmove",
111
+ isPrimaryMouseDown = type === "mousedown" && (button === 0 || buttons === 1),
112
+ isPrimaryMouseMove = type === "mousemove" && buttons === 1,
113
+ noModifiers = altKey === !1 && ctrlKey === !1;
114
+ return !!(isTouch || isPrimaryMouseDown && noModifiers || isPrimaryMouseMove && noModifiers);
115
+ }
116
+ function isSelectionValid() {
117
+ var selection = window.getSelection();
118
+ if (!selection) return !1;
119
+ var string = selection.toString(),
120
+ anchorNode = selection.anchorNode,
121
+ focusNode = selection.focusNode,
122
+ isTextNode = anchorNode && anchorNode.nodeType === window.Node.TEXT_NODE || focusNode && focusNode.nodeType === window.Node.TEXT_NODE;
123
+ return string.length >= 1 && string !== `
124
+ ` && !!isTextNode;
125
+ }
126
+ //# sourceMappingURL=utils.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","utils_exports","__export","canUseDOM","getBoundingClientRect","getLowestCommonAncestor","getResponderPaths","hasTargetTouches","hasValidSelection","isPrimaryPointerDown","isSelectionValid","setResponderId","module","exports","keyName","window","document","createElement","node","nodeType","getEventPath","domEvent","type","_window_getSelection","target","getSelection","anchorNode","composedPathFallback","path","composedPath","body","push","parentNode","getResponderId","id","idPath","nodePath","eventPath","i","length","pathA","pathB","pathALength","pathBLength","itemA","indexA","itemB","indexB","depth","touches","contains","altKey","button","buttons","ctrlKey","isTouch","isPrimaryMouseDown","isPrimaryMouseMove","noModifiers","selection","string","toString","focusNode","isTextNode","Node","TEXT_NODE"],"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