@tamagui/react-native-use-responder-events 1.0.1-beta.194
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/PressResponder.js +373 -0
- package/dist/cjs/PressResponder.js.map +7 -0
- package/dist/cjs/ResponderSystem.js +365 -0
- package/dist/cjs/ResponderSystem.js.map +7 -0
- package/dist/cjs/ResponderTouchHistoryStore.js +184 -0
- package/dist/cjs/ResponderTouchHistoryStore.js.map +7 -0
- package/dist/cjs/createResponderEvent.js +152 -0
- package/dist/cjs/createResponderEvent.js.map +7 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/types.js +98 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/useResponderEvents.js +76 -0
- package/dist/cjs/useResponderEvents.js.map +7 -0
- package/dist/cjs/utils.js +169 -0
- package/dist/cjs/utils.js.map +7 -0
- package/dist/esm/PressResponder.js +349 -0
- package/dist/esm/PressResponder.js.map +7 -0
- package/dist/esm/ResponderSystem.js +338 -0
- package/dist/esm/ResponderSystem.js.map +7 -0
- package/dist/esm/ResponderTouchHistoryStore.js +160 -0
- package/dist/esm/ResponderTouchHistoryStore.js.map +7 -0
- package/dist/esm/createResponderEvent.js +130 -0
- package/dist/esm/createResponderEvent.js.map +7 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/types.js +55 -0
- package/dist/esm/types.js.map +7 -0
- package/dist/esm/useResponderEvents.js +45 -0
- package/dist/esm/useResponderEvents.js.map +7 -0
- package/dist/esm/utils.js +137 -0
- package/dist/esm/utils.js.map +7 -0
- package/package.json +30 -0
- package/src/ResponderSystem.ts +531 -0
- package/src/ResponderTouchHistoryStore.ts +213 -0
- package/src/createResponderEvent.ts +187 -0
- package/src/index.ts +1 -0
- package/src/types.ts +78 -0
- package/src/useResponderEvents.ts +72 -0
- package/src/utils.ts +192 -0
- package/types/PressResponder.d.ts +92 -0
- package/types/ResponderSystem.d.ts +47 -0
- package/types/ResponderTouchHistoryStore.d.ts +37 -0
- package/types/createResponderEvent.d.ts +36 -0
- package/types/index.d.ts +2 -0
- package/types/types.d.ts +52 -0
- package/types/useResponderEvents.d.ts +9 -0
- package/types/utils.d.ts +38 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var createResponderEvent_exports = {};
|
|
20
|
+
__export(createResponderEvent_exports, {
|
|
21
|
+
default: () => createResponderEvent
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(createResponderEvent_exports);
|
|
24
|
+
var import_utils = require("./utils");
|
|
25
|
+
const emptyFunction = () => {
|
|
26
|
+
};
|
|
27
|
+
const emptyObject = {};
|
|
28
|
+
const emptyArray = [];
|
|
29
|
+
function normalizeIdentifier(identifier) {
|
|
30
|
+
return identifier > 20 ? identifier % 20 : identifier;
|
|
31
|
+
}
|
|
32
|
+
function createResponderEvent(domEvent, responderTouchHistoryStore) {
|
|
33
|
+
let rect;
|
|
34
|
+
let propagationWasStopped = false;
|
|
35
|
+
let changedTouches;
|
|
36
|
+
let touches;
|
|
37
|
+
const domEventChangedTouches = domEvent.changedTouches;
|
|
38
|
+
const domEventType = domEvent.type;
|
|
39
|
+
const metaKey = domEvent.metaKey === true;
|
|
40
|
+
const shiftKey = domEvent.shiftKey === true;
|
|
41
|
+
const force = domEventChangedTouches && domEventChangedTouches[0].force || 0;
|
|
42
|
+
const identifier = normalizeIdentifier(
|
|
43
|
+
domEventChangedTouches && domEventChangedTouches[0].identifier || 0
|
|
44
|
+
);
|
|
45
|
+
const clientX = domEventChangedTouches && domEventChangedTouches[0].clientX || domEvent.clientX;
|
|
46
|
+
const clientY = domEventChangedTouches && domEventChangedTouches[0].clientY || domEvent.clientY;
|
|
47
|
+
const pageX = domEventChangedTouches && domEventChangedTouches[0].pageX || domEvent.pageX;
|
|
48
|
+
const pageY = domEventChangedTouches && domEventChangedTouches[0].pageY || domEvent.pageY;
|
|
49
|
+
const preventDefault = typeof domEvent.preventDefault === "function" ? domEvent.preventDefault.bind(domEvent) : emptyFunction;
|
|
50
|
+
const timestamp = domEvent.timeStamp;
|
|
51
|
+
function normalizeTouches(touches2) {
|
|
52
|
+
return Array.prototype.slice.call(touches2).map((touch) => {
|
|
53
|
+
return {
|
|
54
|
+
force: touch.force,
|
|
55
|
+
identifier: normalizeIdentifier(touch.identifier),
|
|
56
|
+
get locationX() {
|
|
57
|
+
return locationX(touch.clientX);
|
|
58
|
+
},
|
|
59
|
+
get locationY() {
|
|
60
|
+
return locationY(touch.clientY);
|
|
61
|
+
},
|
|
62
|
+
pageX: touch.pageX,
|
|
63
|
+
pageY: touch.pageY,
|
|
64
|
+
target: touch.target,
|
|
65
|
+
timestamp
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (domEventChangedTouches != null) {
|
|
70
|
+
changedTouches = normalizeTouches(domEventChangedTouches);
|
|
71
|
+
touches = normalizeTouches(domEvent.touches);
|
|
72
|
+
} else {
|
|
73
|
+
const emulatedTouches = [
|
|
74
|
+
{
|
|
75
|
+
force,
|
|
76
|
+
identifier,
|
|
77
|
+
get locationX() {
|
|
78
|
+
return locationX(clientX);
|
|
79
|
+
},
|
|
80
|
+
get locationY() {
|
|
81
|
+
return locationY(clientY);
|
|
82
|
+
},
|
|
83
|
+
pageX,
|
|
84
|
+
pageY,
|
|
85
|
+
target: domEvent.target,
|
|
86
|
+
timestamp
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
changedTouches = emulatedTouches;
|
|
90
|
+
touches = domEventType === "mouseup" || domEventType === "dragstart" ? emptyArray : emulatedTouches;
|
|
91
|
+
}
|
|
92
|
+
const responderEvent = {
|
|
93
|
+
bubbles: true,
|
|
94
|
+
cancelable: true,
|
|
95
|
+
currentTarget: null,
|
|
96
|
+
defaultPrevented: domEvent.defaultPrevented,
|
|
97
|
+
dispatchConfig: emptyObject,
|
|
98
|
+
eventPhase: domEvent.eventPhase,
|
|
99
|
+
isDefaultPrevented() {
|
|
100
|
+
return domEvent.defaultPrevented;
|
|
101
|
+
},
|
|
102
|
+
isPropagationStopped() {
|
|
103
|
+
return propagationWasStopped;
|
|
104
|
+
},
|
|
105
|
+
isTrusted: domEvent.isTrusted,
|
|
106
|
+
nativeEvent: {
|
|
107
|
+
altKey: false,
|
|
108
|
+
ctrlKey: false,
|
|
109
|
+
metaKey,
|
|
110
|
+
shiftKey,
|
|
111
|
+
changedTouches,
|
|
112
|
+
force,
|
|
113
|
+
identifier,
|
|
114
|
+
get locationX() {
|
|
115
|
+
return locationX(clientX);
|
|
116
|
+
},
|
|
117
|
+
get locationY() {
|
|
118
|
+
return locationY(clientY);
|
|
119
|
+
},
|
|
120
|
+
pageX,
|
|
121
|
+
pageY,
|
|
122
|
+
target: domEvent.target,
|
|
123
|
+
timestamp,
|
|
124
|
+
touches,
|
|
125
|
+
type: domEventType
|
|
126
|
+
},
|
|
127
|
+
persist: emptyFunction,
|
|
128
|
+
preventDefault,
|
|
129
|
+
stopPropagation() {
|
|
130
|
+
propagationWasStopped = true;
|
|
131
|
+
},
|
|
132
|
+
target: domEvent.target,
|
|
133
|
+
timeStamp: timestamp,
|
|
134
|
+
touchHistory: responderTouchHistoryStore.touchHistory
|
|
135
|
+
};
|
|
136
|
+
function locationX(x) {
|
|
137
|
+
rect = rect || (0, import_utils.getBoundingClientRect)(responderEvent.currentTarget);
|
|
138
|
+
if (rect) {
|
|
139
|
+
return x - rect.left;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function locationY(y) {
|
|
143
|
+
rect = rect || (0, import_utils.getBoundingClientRect)(responderEvent.currentTarget);
|
|
144
|
+
if (rect) {
|
|
145
|
+
return y - rect.top;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return responderEvent;
|
|
149
|
+
}
|
|
150
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
151
|
+
0 && (module.exports = {});
|
|
152
|
+
//# sourceMappingURL=createResponderEvent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/createResponderEvent.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Nicolas Gallagher\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { ResponderTouchHistoryStore, TouchHistory } from './ResponderTouchHistoryStore'\nimport { getBoundingClientRect } from './utils'\n\nexport type ResponderEvent = {\n bubbles: boolean\n cancelable: boolean\n currentTarget: any\n defaultPrevented: boolean | null\n dispatchConfig: {\n registrationName?: string\n phasedRegistrationNames?: {\n bubbled: string\n captured: string\n }\n }\n eventPhase: number | null\n isDefaultPrevented: () => boolean\n isPropagationStopped: () => boolean\n isTrusted: boolean | null\n preventDefault: () => void\n stopPropagation: () => void\n nativeEvent: TouchEvent\n persist: () => void\n target: any | null\n timeStamp: number\n touchHistory: TouchHistory\n}\n\nconst emptyFunction = () => {}\nconst emptyObject = {}\nconst emptyArray = []\n\n/**\n * Safari produces very large identifiers that would cause the `touchBank` array\n * length to be so large as to crash the browser, if not normalized like this.\n * In the future the `touchBank` should use an object/map instead.\n */\nfunction normalizeIdentifier(identifier) {\n return identifier > 20 ? identifier % 20 : identifier\n}\n\n/**\n * Converts a native DOM event to a ResponderEvent.\n * Mouse events are transformed into fake touch events.\n */\nexport default function createResponderEvent(\n domEvent: any,\n responderTouchHistoryStore: ResponderTouchHistoryStore\n): ResponderEvent {\n let rect\n let propagationWasStopped = false\n let changedTouches\n let touches\n\n const domEventChangedTouches = domEvent.changedTouches\n const domEventType = domEvent.type\n\n const metaKey = domEvent.metaKey === true\n const shiftKey = domEvent.shiftKey === true\n const force = (domEventChangedTouches && domEventChangedTouches[0].force) || 0\n const identifier = normalizeIdentifier(\n (domEventChangedTouches && domEventChangedTouches[0].identifier) || 0\n )\n const clientX = (domEventChangedTouches && domEventChangedTouches[0].clientX) || domEvent.clientX\n const clientY = (domEventChangedTouches && domEventChangedTouches[0].clientY) || domEvent.clientY\n const pageX = (domEventChangedTouches && domEventChangedTouches[0].pageX) || domEvent.pageX\n const pageY = (domEventChangedTouches && domEventChangedTouches[0].pageY) || domEvent.pageY\n const preventDefault =\n typeof domEvent.preventDefault === 'function'\n ? domEvent.preventDefault.bind(domEvent)\n : emptyFunction\n const timestamp = domEvent.timeStamp\n\n function normalizeTouches(touches) {\n return Array.prototype.slice.call(touches).map((touch) => {\n return {\n force: touch.force,\n identifier: normalizeIdentifier(touch.identifier),\n get locationX() {\n return locationX(touch.clientX)\n },\n get locationY() {\n return locationY(touch.clientY)\n },\n pageX: touch.pageX,\n pageY: touch.pageY,\n target: touch.target,\n timestamp,\n }\n })\n }\n\n if (domEventChangedTouches != null) {\n changedTouches = normalizeTouches(domEventChangedTouches)\n touches = normalizeTouches(domEvent.touches)\n } else {\n const emulatedTouches = [\n {\n force,\n identifier,\n get locationX() {\n return locationX(clientX)\n },\n get locationY() {\n return locationY(clientY)\n },\n pageX,\n pageY,\n target: domEvent.target,\n timestamp,\n },\n ]\n changedTouches = emulatedTouches\n touches =\n domEventType === 'mouseup' || domEventType === 'dragstart' ? emptyArray : emulatedTouches\n }\n\n const responderEvent = {\n bubbles: true,\n cancelable: true,\n // `currentTarget` is set before dispatch\n currentTarget: null,\n defaultPrevented: domEvent.defaultPrevented,\n dispatchConfig: emptyObject,\n eventPhase: domEvent.eventPhase,\n isDefaultPrevented() {\n return domEvent.defaultPrevented\n },\n isPropagationStopped() {\n return propagationWasStopped\n },\n isTrusted: domEvent.isTrusted,\n nativeEvent: {\n altKey: false,\n ctrlKey: false,\n metaKey,\n shiftKey,\n changedTouches,\n force,\n identifier,\n get locationX() {\n return locationX(clientX)\n },\n get locationY() {\n return locationY(clientY)\n },\n pageX,\n pageY,\n target: domEvent.target,\n timestamp,\n touches,\n type: domEventType,\n },\n persist: emptyFunction,\n preventDefault,\n stopPropagation() {\n propagationWasStopped = true\n },\n target: domEvent.target,\n timeStamp: timestamp,\n touchHistory: responderTouchHistoryStore.touchHistory,\n }\n\n // Using getters and functions serves two purposes:\n // 1) The value of `currentTarget` is not initially available.\n // 2) Measuring the clientRect may cause layout jank and should only be done on-demand.\n function locationX(x) {\n rect = rect || getBoundingClientRect(responderEvent.currentTarget)\n if (rect) {\n return x - rect.left\n }\n }\n function locationY(y) {\n rect = rect || getBoundingClientRect(responderEvent.currentTarget)\n if (rect) {\n return y - rect.top\n }\n }\n\n return responderEvent as any\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,mBAAsC;AA2BtC,MAAM,gBAAgB,MAAM;AAAC;AAC7B,MAAM,cAAc,CAAC;AACrB,MAAM,aAAa,CAAC;AAOpB,SAAS,oBAAoB,YAAY;AACvC,SAAO,aAAa,KAAK,aAAa,KAAK;AAC7C;AAMe,SAAR,qBACL,UACA,4BACgB;AAChB,MAAI;AACJ,MAAI,wBAAwB;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7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./useResponderEvents"), module.exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var types_exports = {};
|
|
20
|
+
__export(types_exports, {
|
|
21
|
+
BLUR: () => BLUR,
|
|
22
|
+
CONTEXT_MENU: () => CONTEXT_MENU,
|
|
23
|
+
FOCUS_OUT: () => FOCUS_OUT,
|
|
24
|
+
MOUSE_CANCEL: () => MOUSE_CANCEL,
|
|
25
|
+
MOUSE_DOWN: () => MOUSE_DOWN,
|
|
26
|
+
MOUSE_MOVE: () => MOUSE_MOVE,
|
|
27
|
+
MOUSE_UP: () => MOUSE_UP,
|
|
28
|
+
SCROLL: () => SCROLL,
|
|
29
|
+
SELECT: () => SELECT,
|
|
30
|
+
SELECTION_CHANGE: () => SELECTION_CHANGE,
|
|
31
|
+
TOUCH_CANCEL: () => TOUCH_CANCEL,
|
|
32
|
+
TOUCH_END: () => TOUCH_END,
|
|
33
|
+
TOUCH_MOVE: () => TOUCH_MOVE,
|
|
34
|
+
TOUCH_START: () => TOUCH_START,
|
|
35
|
+
isCancelish: () => isCancelish,
|
|
36
|
+
isEndish: () => isEndish,
|
|
37
|
+
isMoveish: () => isMoveish,
|
|
38
|
+
isScroll: () => isScroll,
|
|
39
|
+
isSelectionChange: () => isSelectionChange,
|
|
40
|
+
isStartish: () => isStartish
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(types_exports);
|
|
43
|
+
const BLUR = "blur";
|
|
44
|
+
const CONTEXT_MENU = "contextmenu";
|
|
45
|
+
const FOCUS_OUT = "focusout";
|
|
46
|
+
const MOUSE_DOWN = "mousedown";
|
|
47
|
+
const MOUSE_MOVE = "mousemove";
|
|
48
|
+
const MOUSE_UP = "mouseup";
|
|
49
|
+
const MOUSE_CANCEL = "dragstart";
|
|
50
|
+
const TOUCH_START = "touchstart";
|
|
51
|
+
const TOUCH_MOVE = "touchmove";
|
|
52
|
+
const TOUCH_END = "touchend";
|
|
53
|
+
const TOUCH_CANCEL = "touchcancel";
|
|
54
|
+
const SCROLL = "scroll";
|
|
55
|
+
const SELECT = "select";
|
|
56
|
+
const SELECTION_CHANGE = "selectionchange";
|
|
57
|
+
function isStartish(eventType) {
|
|
58
|
+
return eventType === TOUCH_START || eventType === MOUSE_DOWN;
|
|
59
|
+
}
|
|
60
|
+
function isMoveish(eventType) {
|
|
61
|
+
return eventType === TOUCH_MOVE || eventType === MOUSE_MOVE;
|
|
62
|
+
}
|
|
63
|
+
function isEndish(eventType) {
|
|
64
|
+
return eventType === TOUCH_END || eventType === MOUSE_UP || isCancelish(eventType);
|
|
65
|
+
}
|
|
66
|
+
function isCancelish(eventType) {
|
|
67
|
+
return eventType === TOUCH_CANCEL || eventType === MOUSE_CANCEL;
|
|
68
|
+
}
|
|
69
|
+
function isScroll(eventType) {
|
|
70
|
+
return eventType === SCROLL;
|
|
71
|
+
}
|
|
72
|
+
function isSelectionChange(eventType) {
|
|
73
|
+
return eventType === SELECT || eventType === SELECTION_CHANGE;
|
|
74
|
+
}
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
77
|
+
BLUR,
|
|
78
|
+
CONTEXT_MENU,
|
|
79
|
+
FOCUS_OUT,
|
|
80
|
+
MOUSE_CANCEL,
|
|
81
|
+
MOUSE_DOWN,
|
|
82
|
+
MOUSE_MOVE,
|
|
83
|
+
MOUSE_UP,
|
|
84
|
+
SCROLL,
|
|
85
|
+
SELECT,
|
|
86
|
+
SELECTION_CHANGE,
|
|
87
|
+
TOUCH_CANCEL,
|
|
88
|
+
TOUCH_END,
|
|
89
|
+
TOUCH_MOVE,
|
|
90
|
+
TOUCH_START,
|
|
91
|
+
isCancelish,
|
|
92
|
+
isEndish,
|
|
93
|
+
isMoveish,
|
|
94
|
+
isScroll,
|
|
95
|
+
isSelectionChange,
|
|
96
|
+
isStartish
|
|
97
|
+
});
|
|
98
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Nicolas Gallagher\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nexport type Touch = {\n force: number\n identifier: number\n // The locationX and locationY properties are non-standard additions\n locationX: any\n locationY: any\n pageX: number\n pageY: number\n target: any\n // Touches in a list have a timestamp property\n timestamp: number\n}\n\nexport type TouchEvent = {\n altKey: boolean\n ctrlKey: boolean\n metaKey: boolean\n shiftKey: boolean\n // TouchList is an array in the Responder system\n changedTouches: Array<Touch>\n force: number\n // React Native adds properties to the \"nativeEvent that are usually only found on W3C Touches \u203E\\_(\u30C4)_/\u203E\n identifier: number\n locationX: any\n locationY: any\n pageX: number\n pageY: number\n target: any\n // The timestamp has a lowercase \"s\" in the Responder system\n timestamp: number\n // TouchList is an array in the Responder system\n touches: Array<Touch>\n}\n\nexport const BLUR = 'blur'\nexport const CONTEXT_MENU = 'contextmenu'\nexport const FOCUS_OUT = 'focusout'\nexport const MOUSE_DOWN = 'mousedown'\nexport const MOUSE_MOVE = 'mousemove'\nexport const MOUSE_UP = 'mouseup'\nexport const MOUSE_CANCEL = 'dragstart'\nexport const TOUCH_START = 'touchstart'\nexport const TOUCH_MOVE = 'touchmove'\nexport const TOUCH_END = 'touchend'\nexport const TOUCH_CANCEL = 'touchcancel'\nexport const SCROLL = 'scroll'\nexport const SELECT = 'select'\nexport const SELECTION_CHANGE = 'selectionchange'\n\nexport function isStartish(eventType: unknown): boolean {\n return eventType === TOUCH_START || eventType === MOUSE_DOWN\n}\n\nexport function isMoveish(eventType: unknown): boolean {\n return eventType === TOUCH_MOVE || eventType === MOUSE_MOVE\n}\n\nexport function isEndish(eventType: unknown): boolean {\n return eventType === TOUCH_END || eventType === MOUSE_UP || isCancelish(eventType)\n}\n\nexport function isCancelish(eventType: unknown): boolean {\n return eventType === TOUCH_CANCEL || eventType === MOUSE_CANCEL\n}\n\nexport function isScroll(eventType: unknown): boolean {\n return eventType === SCROLL\n}\n\nexport function isSelectionChange(eventType: unknown): boolean {\n return eventType === SELECT || eventType === SELECTION_CHANGE\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwCO,MAAM,OAAO;AACb,MAAM,eAAe;AACrB,MAAM,YAAY;AAClB,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,MAAM,WAAW;AACjB,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,aAAa;AACnB,MAAM,YAAY;AAClB,MAAM,eAAe;AACrB,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,mBAAmB;AAEzB,SAAS,WAAW,WAA6B;AACtD,SAAO,cAAc,eAAe,cAAc;AACpD;AAEO,SAAS,UAAU,WAA6B;AACrD,SAAO,cAAc,cAAc,cAAc;AACnD;AAEO,SAAS,SAAS,WAA6B;AACpD,SAAO,cAAc,aAAa,cAAc,YAAY,YAAY,SAAS;AACnF;AAEO,SAAS,YAAY,WAA6B;AACvD,SAAO,cAAc,gBAAgB,cAAc;AACrD;AAEO,SAAS,SAAS,WAA6B;AACpD,SAAO,cAAc;AACvB;AAEO,SAAS,kBAAkB,WAA6B;AAC7D,SAAO,cAAc,UAAU,cAAc;AAC/C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var useResponderEvents_exports = {};
|
|
27
|
+
__export(useResponderEvents_exports, {
|
|
28
|
+
useResponderEvents: () => useResponderEvents
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(useResponderEvents_exports);
|
|
31
|
+
var React = __toESM(require("react"));
|
|
32
|
+
var ResponderSystem = __toESM(require("./ResponderSystem"));
|
|
33
|
+
__reExport(useResponderEvents_exports, require("./utils"), module.exports);
|
|
34
|
+
const emptyObject = {};
|
|
35
|
+
function useResponderEvents(hostRef, config = emptyObject) {
|
|
36
|
+
const id = React.useId();
|
|
37
|
+
const isAttachedRef = React.useRef(false);
|
|
38
|
+
React.useEffect(() => {
|
|
39
|
+
ResponderSystem.attachListeners();
|
|
40
|
+
return () => {
|
|
41
|
+
ResponderSystem.removeNode(id);
|
|
42
|
+
};
|
|
43
|
+
}, [id]);
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
const {
|
|
46
|
+
onMoveShouldSetResponder,
|
|
47
|
+
onMoveShouldSetResponderCapture,
|
|
48
|
+
onScrollShouldSetResponder,
|
|
49
|
+
onScrollShouldSetResponderCapture,
|
|
50
|
+
onSelectionChangeShouldSetResponder,
|
|
51
|
+
onSelectionChangeShouldSetResponderCapture,
|
|
52
|
+
onStartShouldSetResponder,
|
|
53
|
+
onStartShouldSetResponderCapture
|
|
54
|
+
} = config;
|
|
55
|
+
const requiresResponderSystem = onMoveShouldSetResponder != null || onMoveShouldSetResponderCapture != null || onScrollShouldSetResponder != null || onScrollShouldSetResponderCapture != null || onSelectionChangeShouldSetResponder != null || onSelectionChangeShouldSetResponderCapture != null || onStartShouldSetResponder != null || onStartShouldSetResponderCapture != null;
|
|
56
|
+
const node = hostRef.current;
|
|
57
|
+
if (requiresResponderSystem) {
|
|
58
|
+
ResponderSystem.addNode(id, node, config);
|
|
59
|
+
isAttachedRef.current = true;
|
|
60
|
+
} else if (isAttachedRef.current) {
|
|
61
|
+
ResponderSystem.removeNode(id);
|
|
62
|
+
isAttachedRef.current = false;
|
|
63
|
+
}
|
|
64
|
+
}, [config, hostRef, id]);
|
|
65
|
+
if (process.env.NODE_ENV === "development") {
|
|
66
|
+
React.useDebugValue({
|
|
67
|
+
isResponder: hostRef.current === ResponderSystem.getResponderNode()
|
|
68
|
+
});
|
|
69
|
+
React.useDebugValue(config);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
+
0 && (module.exports = {
|
|
74
|
+
useResponderEvents
|
|
75
|
+
});
|
|
76
|
+
//# sourceMappingURL=useResponderEvents.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/useResponderEvents.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Nicolas Gallagher\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport * as React from 'react'\n\nimport * as ResponderSystem from './ResponderSystem'\n\nexport * from './utils'\n\nconst emptyObject = {}\n\nexport function useResponderEvents(\n hostRef: any,\n config: ResponderSystem.ResponderConfig = emptyObject\n) {\n const id = React.useId()\n const isAttachedRef = React.useRef(false)\n\n // This is a separate effects so it doesn't run when the config changes.\n // On initial mount, attach global listeners if needed.\n // On unmount, remove node potentially attached to the Responder System.\n React.useEffect(() => {\n ResponderSystem.attachListeners()\n return () => {\n ResponderSystem.removeNode(id)\n }\n }, [id])\n\n // Register and unregister with the Responder System as necessary\n React.useEffect(() => {\n const {\n onMoveShouldSetResponder,\n onMoveShouldSetResponderCapture,\n onScrollShouldSetResponder,\n onScrollShouldSetResponderCapture,\n onSelectionChangeShouldSetResponder,\n onSelectionChangeShouldSetResponderCapture,\n onStartShouldSetResponder,\n onStartShouldSetResponderCapture,\n } = config\n\n const requiresResponderSystem =\n onMoveShouldSetResponder != null ||\n onMoveShouldSetResponderCapture != null ||\n onScrollShouldSetResponder != null ||\n onScrollShouldSetResponderCapture != null ||\n onSelectionChangeShouldSetResponder != null ||\n onSelectionChangeShouldSetResponderCapture != null ||\n onStartShouldSetResponder != null ||\n onStartShouldSetResponderCapture != null\n\n const node = hostRef.current\n\n if (requiresResponderSystem) {\n ResponderSystem.addNode(id, node, config)\n isAttachedRef.current = true\n } else if (isAttachedRef.current) {\n ResponderSystem.removeNode(id)\n isAttachedRef.current = false\n }\n }, [config, hostRef, id])\n\n if (process.env.NODE_ENV === 'development') {\n React.useDebugValue({\n isResponder: hostRef.current === ResponderSystem.getResponderNode(),\n })\n React.useDebugValue(config)\n }\n}\n"],
|
|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Descriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
canUseDOM: () => canUseDOM,
|
|
22
|
+
getBoundingClientRect: () => getBoundingClientRect,
|
|
23
|
+
getLowestCommonAncestor: () => getLowestCommonAncestor,
|
|
24
|
+
getResponderPaths: () => getResponderPaths,
|
|
25
|
+
hasTargetTouches: () => hasTargetTouches,
|
|
26
|
+
hasValidSelection: () => hasValidSelection,
|
|
27
|
+
isPrimaryPointerDown: () => isPrimaryPointerDown,
|
|
28
|
+
isSelectionValid: () => isSelectionValid,
|
|
29
|
+
setResponderId: () => setResponderId
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(utils_exports);
|
|
32
|
+
const keyName = "__reactResponderId";
|
|
33
|
+
const canUseDOM = !!(typeof window !== "undefined" && window.document && window.document.createElement);
|
|
34
|
+
const getBoundingClientRect = (node) => {
|
|
35
|
+
if (!node)
|
|
36
|
+
return;
|
|
37
|
+
if (node.nodeType !== 1)
|
|
38
|
+
return;
|
|
39
|
+
if (node.getBoundingClientRect) {
|
|
40
|
+
return node.getBoundingClientRect();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
function getEventPath(domEvent) {
|
|
44
|
+
var _a;
|
|
45
|
+
if (domEvent.type === "selectionchange") {
|
|
46
|
+
const target = (_a = window.getSelection()) == null ? void 0 : _a.anchorNode;
|
|
47
|
+
return composedPathFallback(target);
|
|
48
|
+
} else {
|
|
49
|
+
const path = domEvent.composedPath != null ? domEvent.composedPath() : composedPathFallback(domEvent.target);
|
|
50
|
+
return path;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function composedPathFallback(target) {
|
|
54
|
+
const path = [];
|
|
55
|
+
while (target != null && target !== document.body) {
|
|
56
|
+
path.push(target);
|
|
57
|
+
target = target.parentNode;
|
|
58
|
+
}
|
|
59
|
+
return path;
|
|
60
|
+
}
|
|
61
|
+
function getResponderId(node) {
|
|
62
|
+
if (node != null) {
|
|
63
|
+
return node[keyName];
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
function setResponderId(node, id) {
|
|
68
|
+
if (node != null) {
|
|
69
|
+
node[keyName] = id;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function getResponderPaths(domEvent) {
|
|
73
|
+
const idPath = [];
|
|
74
|
+
const nodePath = [];
|
|
75
|
+
const eventPath = getEventPath(domEvent);
|
|
76
|
+
for (let i = 0; i < eventPath.length; i++) {
|
|
77
|
+
const node = eventPath[i];
|
|
78
|
+
const id = getResponderId(node);
|
|
79
|
+
if (id != null) {
|
|
80
|
+
idPath.push(id);
|
|
81
|
+
nodePath.push(node);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { idPath, nodePath };
|
|
85
|
+
}
|
|
86
|
+
function getLowestCommonAncestor(pathA, pathB) {
|
|
87
|
+
let pathALength = pathA.length;
|
|
88
|
+
let pathBLength = pathB.length;
|
|
89
|
+
if (pathALength === 0 || pathBLength === 0 || pathA[pathALength - 1] !== pathB[pathBLength - 1]) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
let itemA = pathA[0];
|
|
93
|
+
let indexA = 0;
|
|
94
|
+
let itemB = pathB[0];
|
|
95
|
+
let indexB = 0;
|
|
96
|
+
if (pathALength - pathBLength > 0) {
|
|
97
|
+
indexA = pathALength - pathBLength;
|
|
98
|
+
itemA = pathA[indexA];
|
|
99
|
+
pathALength = pathBLength;
|
|
100
|
+
}
|
|
101
|
+
if (pathBLength - pathALength > 0) {
|
|
102
|
+
indexB = pathBLength - pathALength;
|
|
103
|
+
itemB = pathB[indexB];
|
|
104
|
+
pathBLength = pathALength;
|
|
105
|
+
}
|
|
106
|
+
let depth = pathALength;
|
|
107
|
+
while (depth--) {
|
|
108
|
+
if (itemA === itemB) {
|
|
109
|
+
return itemA;
|
|
110
|
+
}
|
|
111
|
+
itemA = pathA[indexA++];
|
|
112
|
+
itemB = pathB[indexB++];
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
function hasTargetTouches(target, touches) {
|
|
117
|
+
if (!touches || touches.length === 0) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
for (let i = 0; i < touches.length; i++) {
|
|
121
|
+
const node = touches[i].target;
|
|
122
|
+
if (node != null) {
|
|
123
|
+
if (target.contains(node)) {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
function hasValidSelection(domEvent) {
|
|
131
|
+
if (domEvent.type === "selectionchange") {
|
|
132
|
+
return isSelectionValid();
|
|
133
|
+
}
|
|
134
|
+
return domEvent.type === "select";
|
|
135
|
+
}
|
|
136
|
+
function isPrimaryPointerDown(domEvent) {
|
|
137
|
+
const { altKey, button, buttons, ctrlKey, type } = domEvent;
|
|
138
|
+
const isTouch = type === "touchstart" || type === "touchmove";
|
|
139
|
+
const isPrimaryMouseDown = type === "mousedown" && (button === 0 || buttons === 1);
|
|
140
|
+
const isPrimaryMouseMove = type === "mousemove" && buttons === 1;
|
|
141
|
+
const noModifiers = altKey === false && ctrlKey === false;
|
|
142
|
+
if (isTouch || isPrimaryMouseDown && noModifiers || isPrimaryMouseMove && noModifiers) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
function isSelectionValid() {
|
|
148
|
+
const selection = window.getSelection();
|
|
149
|
+
if (!selection)
|
|
150
|
+
return false;
|
|
151
|
+
const string = selection.toString();
|
|
152
|
+
const anchorNode = selection.anchorNode;
|
|
153
|
+
const focusNode = selection.focusNode;
|
|
154
|
+
const isTextNode = anchorNode && anchorNode.nodeType === window.Node.TEXT_NODE || focusNode && focusNode.nodeType === window.Node.TEXT_NODE;
|
|
155
|
+
return string.length >= 1 && string !== "\n" && !!isTextNode;
|
|
156
|
+
}
|
|
157
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
158
|
+
0 && (module.exports = {
|
|
159
|
+
canUseDOM,
|
|
160
|
+
getBoundingClientRect,
|
|
161
|
+
getLowestCommonAncestor,
|
|
162
|
+
getResponderPaths,
|
|
163
|
+
hasTargetTouches,
|
|
164
|
+
hasValidSelection,
|
|
165
|
+
isPrimaryPointerDown,
|
|
166
|
+
isSelectionValid,
|
|
167
|
+
setResponderId
|
|
168
|
+
});
|
|
169
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Nicolas Gallagher\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nconst keyName = '__reactResponderId'\n\nexport const canUseDOM = !!(\n typeof window !== 'undefined' &&\n window.document &&\n window.document.createElement\n)\n\nexport const getBoundingClientRect = (node: HTMLElement | null): void | DOMRect => {\n if (!node) return\n if (node.nodeType !== 1) return\n if (node.getBoundingClientRect) {\n return node.getBoundingClientRect()\n }\n}\n\nfunction getEventPath(domEvent: any): Array<any> {\n // The 'selectionchange' event always has the 'document' as the target.\n // Use the anchor node as the initial target to reconstruct a path.\n // (We actually only need the first \"responder\" node in practice.)\n if (domEvent.type === 'selectionchange') {\n const target = window.getSelection()?.anchorNode\n return composedPathFallback(target)\n } else {\n const path =\n domEvent.composedPath != null\n ? domEvent.composedPath()\n : composedPathFallback(domEvent.target)\n return path\n }\n}\n\nfunction composedPathFallback(target: any): Array<any> {\n const path: any[] = []\n while (target != null && target !== document.body) {\n path.push(target)\n target = target.parentNode\n }\n return path\n}\n\n/**\n * Retrieve the responderId from a host node\n */\nfunction getResponderId(node: any): number | null {\n if (node != null) {\n return node[keyName]\n }\n return null\n}\n\n/**\n * Store the responderId on a host node\n */\nexport function setResponderId(node: any, id: number) {\n if (node != null) {\n node[keyName] = id\n }\n}\n\n/**\n * Filter the event path to contain only the nodes attached to the responder system\n */\nexport function getResponderPaths(domEvent: any): {\n idPath: Array<number>\n nodePath: Array<any>\n} {\n const idPath: any[] = []\n const nodePath: any[] = []\n const eventPath = getEventPath(domEvent)\n for (let i = 0; i < eventPath.length; i++) {\n const node = eventPath[i]\n const id = getResponderId(node)\n if (id != null) {\n idPath.push(id)\n nodePath.push(node)\n }\n }\n return { idPath, nodePath }\n}\n\n/**\n * Walk the paths and find the first common ancestor\n */\nexport function getLowestCommonAncestor(pathA: Array<any>, pathB: Array<any>): any {\n let pathALength = pathA.length\n let pathBLength = pathB.length\n if (\n // If either path is empty\n pathALength === 0 ||\n pathBLength === 0 ||\n // If the last elements aren't the same there can't be a common ancestor\n // that is connected to the responder system\n pathA[pathALength - 1] !== pathB[pathBLength - 1]\n ) {\n return null\n }\n\n let itemA = pathA[0]\n let indexA = 0\n let itemB = pathB[0]\n let indexB = 0\n\n // If A is deeper, skip indices that can't match.\n if (pathALength - pathBLength > 0) {\n indexA = pathALength - pathBLength\n itemA = pathA[indexA]\n pathALength = pathBLength\n }\n\n // If B is deeper, skip indices that can't match\n if (pathBLength - pathALength > 0) {\n indexB = pathBLength - pathALength\n itemB = pathB[indexB]\n pathBLength = pathALength\n }\n\n // Walk in lockstep until a match is found\n let depth = pathALength\n while (depth--) {\n if (itemA === itemB) {\n return itemA\n }\n itemA = pathA[indexA++]\n itemB = pathB[indexB++]\n }\n return null\n}\n\n/**\n * Determine whether any of the active touches are within the current responder.\n * This cannot rely on W3C `targetTouches`, as neither IE11 nor Safari implement it.\n */\nexport function hasTargetTouches(target: any, touches: any): boolean {\n if (!touches || touches.length === 0) {\n return false\n }\n for (let i = 0; i < touches.length; i++) {\n const node = touches[i].target\n if (node != null) {\n if (target.contains(node)) {\n return true\n }\n }\n }\n return false\n}\n\n/**\n * Ignore 'selectionchange' events that don't correspond with a person's intent to\n * select text.\n */\nexport function hasValidSelection(domEvent: any): boolean {\n if (domEvent.type === 'selectionchange') {\n return isSelectionValid()\n }\n return domEvent.type === 'select'\n}\n\n/**\n * Events are only valid if the primary button was used without specific modifier keys.\n */\nexport function isPrimaryPointerDown(domEvent: any): boolean {\n const { altKey, button, buttons, ctrlKey, type } = domEvent\n const isTouch = type === 'touchstart' || type === 'touchmove'\n const isPrimaryMouseDown = type === 'mousedown' && (button === 0 || buttons === 1)\n const isPrimaryMouseMove = type === 'mousemove' && buttons === 1\n const noModifiers = altKey === false && ctrlKey === false\n\n if (isTouch || (isPrimaryMouseDown && noModifiers) || (isPrimaryMouseMove && noModifiers)) {\n return true\n }\n return false\n}\n\nexport function isSelectionValid(): boolean {\n const selection = window.getSelection()\n if (!selection) return false\n const string = selection.toString()\n const anchorNode = selection.anchorNode\n const focusNode = selection.focusNode\n const isTextNode =\n (anchorNode && anchorNode.nodeType === window.Node.TEXT_NODE) ||\n (focusNode && focusNode.nodeType === window.Node.TEXT_NODE)\n return string.length >= 1 && string !== '\\n' && !!isTextNode\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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