@msobiecki/react-marauders-path 1.24.1 → 1.24.3
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/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/use-drag/invoke-drag-action.js +7 -0
- package/dist/use-drag/invoke-drag-action.js.map +1 -0
- package/dist/use-drag/use-drag.js +141 -0
- package/dist/use-drag/use-drag.js.map +1 -0
- package/dist/use-drag/use-drag.types.js +9 -0
- package/dist/use-drag/use-drag.types.js.map +1 -0
- package/dist/use-key/event-guards.js +5 -0
- package/dist/use-key/event-guards.js.map +1 -0
- package/dist/use-key/invoke-key-action.js +7 -0
- package/dist/use-key/invoke-key-action.js.map +1 -0
- package/dist/use-key/normalize-key.js +43 -0
- package/dist/use-key/normalize-key.js.map +1 -0
- package/dist/use-key/parse-key-sequences.js +16 -0
- package/dist/use-key/parse-key-sequences.js.map +1 -0
- package/dist/use-key/sequence-state.js +25 -0
- package/dist/use-key/sequence-state.js.map +1 -0
- package/dist/use-key/use-key.js +206 -0
- package/dist/use-key/use-key.js.map +1 -0
- package/dist/use-key/use-key.types.js +8 -0
- package/dist/use-key/use-key.types.js.map +1 -0
- package/dist/use-pinch/invoke-pinch-action.js +7 -0
- package/dist/use-pinch/invoke-pinch-action.js.map +1 -0
- package/dist/use-pinch/use-pinch.js +131 -0
- package/dist/use-pinch/use-pinch.js.map +1 -0
- package/dist/use-pinch/use-pinch.types.js +9 -0
- package/dist/use-pinch/use-pinch.types.js.map +1 -0
- package/dist/use-swipe/invoke-swipe-action.js +7 -0
- package/dist/use-swipe/invoke-swipe-action.js.map +1 -0
- package/dist/use-swipe/parse-swipe-direction.js +5 -0
- package/dist/use-swipe/parse-swipe-direction.js.map +1 -0
- package/dist/use-swipe/use-swipe.js +134 -0
- package/dist/use-swipe/use-swipe.js.map +1 -0
- package/dist/use-swipe/use-swipe.types.js +18 -0
- package/dist/use-swipe/use-swipe.types.js.map +1 -0
- package/dist/use-wheel/invoke-wheel-action.js +7 -0
- package/dist/use-wheel/invoke-wheel-action.js.map +1 -0
- package/dist/use-wheel/use-wheel.js +79 -0
- package/dist/use-wheel/use-wheel.js.map +1 -0
- package/package.json +24 -3
- package/dist/index.es.js +0 -761
- /package/dist/{index.es.d.ts → index.d.ts} +0 -0
package/dist/index.es.js
DELETED
|
@@ -1,761 +0,0 @@
|
|
|
1
|
-
import { useRef as E, useCallback as u, useEffect as x } from "react";
|
|
2
|
-
const k = (n, s, c, r) => {
|
|
3
|
-
r.stopImmediate && n.stopImmediatePropagation(), c(n, s) && n.preventDefault(), r.once && r.onOnce?.();
|
|
4
|
-
}, Z = {
|
|
5
|
-
eventPointerTypes: ["touch", "mouse", "pen"],
|
|
6
|
-
eventCapture: !1,
|
|
7
|
-
eventOnce: !1,
|
|
8
|
-
eventStopImmediatePropagation: !1,
|
|
9
|
-
threshold: 0,
|
|
10
|
-
container: { current: null },
|
|
11
|
-
raf: !1
|
|
12
|
-
}, ie = (n, s = {}) => {
|
|
13
|
-
const {
|
|
14
|
-
eventPointerTypes: c,
|
|
15
|
-
eventCapture: r,
|
|
16
|
-
eventOnce: a,
|
|
17
|
-
eventStopImmediatePropagation: p,
|
|
18
|
-
threshold: f,
|
|
19
|
-
container: R,
|
|
20
|
-
raf: O
|
|
21
|
-
} = { ...Z, ...s }, T = E(null), m = E(null), y = E(null), h = E(null), A = E(null), d = E({
|
|
22
|
-
startX: 0,
|
|
23
|
-
startY: 0,
|
|
24
|
-
lastX: 0,
|
|
25
|
-
lastY: 0,
|
|
26
|
-
startTime: 0,
|
|
27
|
-
active: !1
|
|
28
|
-
}), S = u(() => {
|
|
29
|
-
m.current?.abort();
|
|
30
|
-
}, []), L = u(() => {
|
|
31
|
-
y.current = null;
|
|
32
|
-
const e = h.current, t = A.current;
|
|
33
|
-
!e || !t || (k(t, e, n, {
|
|
34
|
-
stopImmediate: p,
|
|
35
|
-
once: a,
|
|
36
|
-
onOnce: () => {
|
|
37
|
-
S();
|
|
38
|
-
}
|
|
39
|
-
}), h.current = null, A.current = null);
|
|
40
|
-
}, [n, p, a, S]), g = u(
|
|
41
|
-
(e) => {
|
|
42
|
-
e.isPrimary && c.includes(e.pointerType) && (d.current = {
|
|
43
|
-
startX: e.clientX,
|
|
44
|
-
startY: e.clientY,
|
|
45
|
-
lastX: e.clientX,
|
|
46
|
-
lastY: e.clientY,
|
|
47
|
-
startTime: Date.now(),
|
|
48
|
-
active: !0
|
|
49
|
-
});
|
|
50
|
-
},
|
|
51
|
-
[c]
|
|
52
|
-
), Y = u(
|
|
53
|
-
(e) => {
|
|
54
|
-
const t = d.current;
|
|
55
|
-
if (!t.active || !e.isPrimary || !c.includes(e.pointerType))
|
|
56
|
-
return;
|
|
57
|
-
const D = e.clientX - t.startX, P = e.clientY - t.startY, v = e.clientX - t.lastX, M = e.clientY - t.lastY;
|
|
58
|
-
if (Math.hypot(D, P) < f) return;
|
|
59
|
-
const i = Date.now() - t.startTime, l = {
|
|
60
|
-
deltaX: D,
|
|
61
|
-
deltaY: P,
|
|
62
|
-
movementX: v,
|
|
63
|
-
movementY: M,
|
|
64
|
-
duration: i,
|
|
65
|
-
startX: t.startX,
|
|
66
|
-
startY: t.startY,
|
|
67
|
-
endX: e.clientX,
|
|
68
|
-
endY: e.clientY
|
|
69
|
-
};
|
|
70
|
-
if (t.lastX = e.clientX, t.lastY = e.clientY, !O) {
|
|
71
|
-
k(e, l, n, {
|
|
72
|
-
stopImmediate: p,
|
|
73
|
-
once: a,
|
|
74
|
-
onOnce: () => {
|
|
75
|
-
S();
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
h.current = l, A.current = e, y.current === null && (y.current = requestAnimationFrame(L));
|
|
81
|
-
},
|
|
82
|
-
[
|
|
83
|
-
c,
|
|
84
|
-
f,
|
|
85
|
-
O,
|
|
86
|
-
n,
|
|
87
|
-
p,
|
|
88
|
-
a,
|
|
89
|
-
S,
|
|
90
|
-
L
|
|
91
|
-
]
|
|
92
|
-
), X = u(
|
|
93
|
-
(e) => {
|
|
94
|
-
e.isPrimary && c.includes(e.pointerType) && (d.current.active = !1);
|
|
95
|
-
},
|
|
96
|
-
[c]
|
|
97
|
-
), K = u(() => {
|
|
98
|
-
d.current.active = !1;
|
|
99
|
-
}, []);
|
|
100
|
-
x(() => {
|
|
101
|
-
T.current = R?.current ?? globalThis, m.current = new AbortController();
|
|
102
|
-
const e = (v) => g(v), t = (v) => Y(v), D = (v) => X(v), P = () => K();
|
|
103
|
-
return T.current.addEventListener(
|
|
104
|
-
"pointerdown",
|
|
105
|
-
e,
|
|
106
|
-
{
|
|
107
|
-
capture: r,
|
|
108
|
-
signal: m.current.signal
|
|
109
|
-
}
|
|
110
|
-
), T.current.addEventListener(
|
|
111
|
-
"pointermove",
|
|
112
|
-
t,
|
|
113
|
-
{
|
|
114
|
-
capture: r,
|
|
115
|
-
signal: m.current.signal
|
|
116
|
-
}
|
|
117
|
-
), T.current.addEventListener("pointerup", D, {
|
|
118
|
-
capture: r,
|
|
119
|
-
signal: m.current.signal
|
|
120
|
-
}), T.current.addEventListener(
|
|
121
|
-
"pointercancel",
|
|
122
|
-
P,
|
|
123
|
-
{
|
|
124
|
-
capture: r,
|
|
125
|
-
signal: m.current.signal
|
|
126
|
-
}
|
|
127
|
-
), () => {
|
|
128
|
-
m.current?.abort(), d.current.active = !1, y.current !== null && cancelAnimationFrame(y.current);
|
|
129
|
-
};
|
|
130
|
-
}, [
|
|
131
|
-
R,
|
|
132
|
-
r,
|
|
133
|
-
g,
|
|
134
|
-
Y,
|
|
135
|
-
X,
|
|
136
|
-
K
|
|
137
|
-
]);
|
|
138
|
-
}, ue = {
|
|
139
|
-
Touch: "touch",
|
|
140
|
-
Mouse: "mouse",
|
|
141
|
-
Pen: "pen"
|
|
142
|
-
}, F = {
|
|
143
|
-
KeyUp: "keyup",
|
|
144
|
-
KeyDown: "keydown"
|
|
145
|
-
}, U = {
|
|
146
|
-
ENTER: "Enter",
|
|
147
|
-
ESC: "Escape",
|
|
148
|
-
ESCAPE: "Escape",
|
|
149
|
-
SPACE: "Space",
|
|
150
|
-
TAB: "Tab",
|
|
151
|
-
SHIFT: "Shift",
|
|
152
|
-
CONTROL: "Control",
|
|
153
|
-
CTRL: "Control",
|
|
154
|
-
ALT: "Alt",
|
|
155
|
-
META: "Meta",
|
|
156
|
-
ARROWUP: "ArrowUp",
|
|
157
|
-
ARROWDOWN: "ArrowDown",
|
|
158
|
-
ARROWLEFT: "ArrowLeft",
|
|
159
|
-
ARROWRIGHT: "ArrowRight",
|
|
160
|
-
BACKSPACE: "Backspace",
|
|
161
|
-
DELETE: "Delete",
|
|
162
|
-
DEL: "Delete",
|
|
163
|
-
INSERT: "Insert",
|
|
164
|
-
HOME: "Home",
|
|
165
|
-
END: "End",
|
|
166
|
-
PAGEUP: "PageUp",
|
|
167
|
-
PAGEDOWN: "PageDown",
|
|
168
|
-
CONTEXTMENU: "ContextMenu",
|
|
169
|
-
CAPSLOCK: "CapsLock",
|
|
170
|
-
NUMLOCK: "NumLock",
|
|
171
|
-
SCROLLLOCK: "ScrollLock",
|
|
172
|
-
ANY: "Any"
|
|
173
|
-
// Special key to match any key in sequences
|
|
174
|
-
}, _ = (n) => {
|
|
175
|
-
if (!n)
|
|
176
|
-
return n;
|
|
177
|
-
const s = n.trim(), c = s.toUpperCase();
|
|
178
|
-
return c in U ? U[c] : s.length === 1 ? s.toLowerCase() : s[0].toUpperCase() + s.slice(1).toLowerCase();
|
|
179
|
-
}, J = (n) => n.split(" ").filter(Boolean).map(
|
|
180
|
-
(s) => s.split("+").map((c) => _(c)).join("+")
|
|
181
|
-
).join(" "), Q = (n) => (Array.isArray(n) ? n : [n]).map((c) => {
|
|
182
|
-
const r = J(c), p = r.split(" ").filter((f) => f.length > 0).map(
|
|
183
|
-
(f) => f.includes("+") ? f.split("+") : f
|
|
184
|
-
);
|
|
185
|
-
return {
|
|
186
|
-
key: r,
|
|
187
|
-
chord: p,
|
|
188
|
-
index: 0,
|
|
189
|
-
sequenceTimeout: null
|
|
190
|
-
};
|
|
191
|
-
}), ee = (n, s) => {
|
|
192
|
-
const c = { ...n, index: 0, sequenceTimeout: null };
|
|
193
|
-
return n.sequenceTimeout && clearTimeout(n.sequenceTimeout), s.map(
|
|
194
|
-
(r) => r === n ? c : r
|
|
195
|
-
);
|
|
196
|
-
}, B = (n, s, c, r) => {
|
|
197
|
-
const a = {
|
|
198
|
-
...n,
|
|
199
|
-
index: n.index + 1,
|
|
200
|
-
sequenceTimeout: n.sequenceTimeout
|
|
201
|
-
};
|
|
202
|
-
c && (a.sequenceTimeout && clearTimeout(a.sequenceTimeout), a.sequenceTimeout = setTimeout(
|
|
203
|
-
() => r(a),
|
|
204
|
-
c
|
|
205
|
-
));
|
|
206
|
-
const p = s.map(
|
|
207
|
-
(f) => f === n ? a : f
|
|
208
|
-
);
|
|
209
|
-
return [a, p];
|
|
210
|
-
}, q = (n, s, c, r) => {
|
|
211
|
-
r.stopImmediate && n.stopImmediatePropagation(), c(n, s) && n.preventDefault(), r.once && r.onOnce?.();
|
|
212
|
-
}, te = (n, s) => !(!s.repeat && n.repeat), $ = {
|
|
213
|
-
eventType: F.KeyUp,
|
|
214
|
-
eventRepeat: !1,
|
|
215
|
-
eventCapture: !1,
|
|
216
|
-
eventOnce: !1,
|
|
217
|
-
eventStopImmediatePropagation: !1,
|
|
218
|
-
sequenceThreshold: 1e3,
|
|
219
|
-
combinationThreshold: 200,
|
|
220
|
-
container: { current: null }
|
|
221
|
-
}, le = (n, s, c = $) => {
|
|
222
|
-
const {
|
|
223
|
-
eventType: r,
|
|
224
|
-
eventRepeat: a,
|
|
225
|
-
eventCapture: p,
|
|
226
|
-
eventOnce: f,
|
|
227
|
-
eventStopImmediatePropagation: R,
|
|
228
|
-
sequenceThreshold: O,
|
|
229
|
-
combinationThreshold: T,
|
|
230
|
-
container: m
|
|
231
|
-
} = { ...$, ...c }, y = E(null), h = E(null), A = E({
|
|
232
|
-
activeKeys: /* @__PURE__ */ new Map()
|
|
233
|
-
}), d = E([]), S = u(() => {
|
|
234
|
-
h.current && h.current.abort();
|
|
235
|
-
}, []), L = u(() => {
|
|
236
|
-
A.current.activeKeys.clear();
|
|
237
|
-
}, []), g = u((o) => {
|
|
238
|
-
d.current = ee(
|
|
239
|
-
o,
|
|
240
|
-
d.current
|
|
241
|
-
);
|
|
242
|
-
}, []), Y = u(
|
|
243
|
-
(o) => te(o, {
|
|
244
|
-
repeat: a
|
|
245
|
-
}),
|
|
246
|
-
[a]
|
|
247
|
-
), X = u((o) => {
|
|
248
|
-
const i = o.key === " " ? U.SPACE : o.key;
|
|
249
|
-
A.current.activeKeys.set(i, {
|
|
250
|
-
pressedAt: Date.now()
|
|
251
|
-
});
|
|
252
|
-
}, []), K = u((o) => {
|
|
253
|
-
const i = o.key === " " ? U.SPACE : o.key, l = A.current.activeKeys.get(i);
|
|
254
|
-
l && (l.releasedAt = Date.now());
|
|
255
|
-
}, []), e = u(() => {
|
|
256
|
-
const o = Date.now(), i = A.current;
|
|
257
|
-
[...i.activeKeys.entries()].forEach(([l, w]) => {
|
|
258
|
-
r === F.KeyDown ? w.releasedAt && i.activeKeys.delete(l) : w.releasedAt && o - w.releasedAt > T && i.activeKeys.delete(l);
|
|
259
|
-
});
|
|
260
|
-
}, [r, T]), t = u(
|
|
261
|
-
(o, i) => {
|
|
262
|
-
if (r === F.KeyDown)
|
|
263
|
-
return i.size === o.length && o.every((l) => l === U.ANY ? i.size > 0 : i.has(l));
|
|
264
|
-
if (r === F.KeyUp) {
|
|
265
|
-
const l = o.map((C) => {
|
|
266
|
-
if (C === U.ANY) {
|
|
267
|
-
const H = [...i.entries()].at(-1);
|
|
268
|
-
return H ? H[1] : void 0;
|
|
269
|
-
}
|
|
270
|
-
return i.get(C);
|
|
271
|
-
});
|
|
272
|
-
if (l.some((C) => !C?.releasedAt))
|
|
273
|
-
return !1;
|
|
274
|
-
const w = l.map((C) => C?.pressedAt).filter((C) => C !== void 0), I = l.map((C) => C?.releasedAt).filter((C) => C !== void 0), N = Math.min(...I), W = Math.max(...I);
|
|
275
|
-
return !(Math.max(...w) > N || W - N > T);
|
|
276
|
-
}
|
|
277
|
-
return !1;
|
|
278
|
-
},
|
|
279
|
-
[r, T]
|
|
280
|
-
), D = u(
|
|
281
|
-
(o, i) => {
|
|
282
|
-
const l = i.chord[0];
|
|
283
|
-
if (Array.isArray(l)) {
|
|
284
|
-
const { activeKeys: I } = A.current;
|
|
285
|
-
if (!t(l, I))
|
|
286
|
-
return;
|
|
287
|
-
q(o, i.key, s, {
|
|
288
|
-
stopImmediate: R,
|
|
289
|
-
once: f,
|
|
290
|
-
onOnce: () => {
|
|
291
|
-
S();
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const w = o.key === " " ? U.SPACE : o.key;
|
|
297
|
-
l !== U.ANY && l !== w || q(o, i.key, s, {
|
|
298
|
-
stopImmediate: R,
|
|
299
|
-
once: f,
|
|
300
|
-
onOnce: () => {
|
|
301
|
-
S();
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
},
|
|
305
|
-
[
|
|
306
|
-
R,
|
|
307
|
-
f,
|
|
308
|
-
s,
|
|
309
|
-
t,
|
|
310
|
-
S
|
|
311
|
-
]
|
|
312
|
-
), P = u(
|
|
313
|
-
(o, i) => {
|
|
314
|
-
const l = i.chord[i.index];
|
|
315
|
-
if (Array.isArray(l)) {
|
|
316
|
-
const { activeKeys: W } = A.current;
|
|
317
|
-
if (!t(l, W))
|
|
318
|
-
return;
|
|
319
|
-
const [z, C] = B(
|
|
320
|
-
i,
|
|
321
|
-
d.current,
|
|
322
|
-
O,
|
|
323
|
-
g
|
|
324
|
-
);
|
|
325
|
-
d.current = C, z.index === z.chord.length && (q(o, z.key, s, {
|
|
326
|
-
stopImmediate: R,
|
|
327
|
-
once: f,
|
|
328
|
-
onOnce: () => {
|
|
329
|
-
S();
|
|
330
|
-
}
|
|
331
|
-
}), g(z));
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
const w = o.key === " " ? U.SPACE : o.key;
|
|
335
|
-
if (l !== U.ANY && l !== w) {
|
|
336
|
-
g(i);
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
const [I, N] = B(
|
|
340
|
-
i,
|
|
341
|
-
d.current,
|
|
342
|
-
O,
|
|
343
|
-
g
|
|
344
|
-
);
|
|
345
|
-
d.current = N, I.index === I.chord.length && (q(o, I.key, s, {
|
|
346
|
-
stopImmediate: R,
|
|
347
|
-
once: f,
|
|
348
|
-
onOnce: () => {
|
|
349
|
-
S();
|
|
350
|
-
}
|
|
351
|
-
}), g(I));
|
|
352
|
-
},
|
|
353
|
-
[
|
|
354
|
-
f,
|
|
355
|
-
R,
|
|
356
|
-
O,
|
|
357
|
-
s,
|
|
358
|
-
g,
|
|
359
|
-
t,
|
|
360
|
-
S
|
|
361
|
-
]
|
|
362
|
-
), v = u(
|
|
363
|
-
(o) => {
|
|
364
|
-
d.current.forEach((i) => {
|
|
365
|
-
i.chord.length === 1 ? D(o, i) : P(o, i);
|
|
366
|
-
});
|
|
367
|
-
},
|
|
368
|
-
[D, P]
|
|
369
|
-
), M = u(
|
|
370
|
-
(o) => {
|
|
371
|
-
Y(o) && (e(), v(o));
|
|
372
|
-
},
|
|
373
|
-
[Y, e, v]
|
|
374
|
-
);
|
|
375
|
-
x(() => {
|
|
376
|
-
d.current = Q(n);
|
|
377
|
-
}, [n]), x(() => {
|
|
378
|
-
y.current = m?.current ?? globalThis, h.current = new AbortController();
|
|
379
|
-
const o = (w) => X(w);
|
|
380
|
-
y.current.addEventListener("keydown", o, {
|
|
381
|
-
capture: p,
|
|
382
|
-
signal: h.current.signal
|
|
383
|
-
});
|
|
384
|
-
const i = (w) => K(w);
|
|
385
|
-
y.current.addEventListener("keyup", i, {
|
|
386
|
-
capture: p,
|
|
387
|
-
signal: h.current.signal
|
|
388
|
-
});
|
|
389
|
-
const l = (w) => M(w);
|
|
390
|
-
return y.current.addEventListener(r, l, {
|
|
391
|
-
capture: p,
|
|
392
|
-
signal: h.current.signal
|
|
393
|
-
}), () => {
|
|
394
|
-
h.current?.abort(), L(), d.current.forEach((w) => g(w));
|
|
395
|
-
};
|
|
396
|
-
}, [
|
|
397
|
-
r,
|
|
398
|
-
p,
|
|
399
|
-
m,
|
|
400
|
-
X,
|
|
401
|
-
K,
|
|
402
|
-
M,
|
|
403
|
-
L,
|
|
404
|
-
g
|
|
405
|
-
]);
|
|
406
|
-
}, G = (n, s, c, r) => {
|
|
407
|
-
r.stopImmediate && n.stopImmediatePropagation(), c(n, s) && n.preventDefault(), r.once && r.onOnce?.();
|
|
408
|
-
}, ne = {
|
|
409
|
-
eventPointerTypes: ["touch"],
|
|
410
|
-
eventCapture: !1,
|
|
411
|
-
eventOnce: !1,
|
|
412
|
-
eventStopImmediatePropagation: !1,
|
|
413
|
-
threshold: 0,
|
|
414
|
-
container: { current: null },
|
|
415
|
-
raf: !1
|
|
416
|
-
}, de = (n, s = {}) => {
|
|
417
|
-
const {
|
|
418
|
-
eventPointerTypes: c,
|
|
419
|
-
eventCapture: r,
|
|
420
|
-
eventOnce: a,
|
|
421
|
-
eventStopImmediatePropagation: p,
|
|
422
|
-
threshold: f,
|
|
423
|
-
container: R,
|
|
424
|
-
raf: O
|
|
425
|
-
} = { ...ne, ...s }, T = E(null), m = E(null), y = E(null), h = E(null), A = E(null), d = E({
|
|
426
|
-
pointers: /* @__PURE__ */ new Map(),
|
|
427
|
-
startDistance: 0,
|
|
428
|
-
lastDistance: 0,
|
|
429
|
-
active: !1
|
|
430
|
-
}), S = u(() => {
|
|
431
|
-
m.current?.abort();
|
|
432
|
-
}, []), L = u(() => {
|
|
433
|
-
y.current = null;
|
|
434
|
-
const e = h.current, t = A.current;
|
|
435
|
-
!e || !t || (G(t, e, n, {
|
|
436
|
-
stopImmediate: p,
|
|
437
|
-
once: a,
|
|
438
|
-
onOnce: () => S()
|
|
439
|
-
}), h.current = null, A.current = null);
|
|
440
|
-
}, [
|
|
441
|
-
n,
|
|
442
|
-
p,
|
|
443
|
-
a,
|
|
444
|
-
S
|
|
445
|
-
]), g = u(
|
|
446
|
-
(e) => {
|
|
447
|
-
if (!c.includes(e.pointerType))
|
|
448
|
-
return;
|
|
449
|
-
const t = d.current;
|
|
450
|
-
if (t.pointers.set(e.pointerId, e), t.pointers.size === 2) {
|
|
451
|
-
const [D, P] = [...t.pointers.values()], v = P.clientX - D.clientX, M = P.clientY - D.clientY, o = Math.hypot(v, M);
|
|
452
|
-
t.startDistance = o, t.lastDistance = o, t.active = !0;
|
|
453
|
-
}
|
|
454
|
-
},
|
|
455
|
-
[c]
|
|
456
|
-
), Y = u(
|
|
457
|
-
(e) => {
|
|
458
|
-
const t = d.current;
|
|
459
|
-
if (!t.active || !t.pointers.has(e.pointerId) || (t.pointers.set(e.pointerId, e), t.pointers.size < 2)) return;
|
|
460
|
-
const [D, P] = [...t.pointers.values()], v = P.clientX - D.clientX, M = P.clientY - D.clientY, o = Math.hypot(v, M), i = o - t.lastDistance, l = o - t.startDistance;
|
|
461
|
-
if (Math.abs(l) < f) return;
|
|
462
|
-
const w = o / t.startDistance, I = {
|
|
463
|
-
distance: o,
|
|
464
|
-
delta: i,
|
|
465
|
-
totalDelta: l,
|
|
466
|
-
scale: w
|
|
467
|
-
};
|
|
468
|
-
if (t.lastDistance = o, !O) {
|
|
469
|
-
G(e, I, n, {
|
|
470
|
-
stopImmediate: p,
|
|
471
|
-
once: a,
|
|
472
|
-
onOnce: () => S()
|
|
473
|
-
});
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
h.current = I, A.current = e, y.current === null && (y.current = requestAnimationFrame(L));
|
|
477
|
-
},
|
|
478
|
-
[
|
|
479
|
-
f,
|
|
480
|
-
O,
|
|
481
|
-
n,
|
|
482
|
-
p,
|
|
483
|
-
a,
|
|
484
|
-
S,
|
|
485
|
-
L
|
|
486
|
-
]
|
|
487
|
-
), X = u((e) => {
|
|
488
|
-
const t = d.current;
|
|
489
|
-
t.pointers.delete(e.pointerId), t.pointers.size < 2 && (t.active = !1, t.startDistance = 0, t.lastDistance = 0);
|
|
490
|
-
}, []), K = u((e) => {
|
|
491
|
-
const t = d.current;
|
|
492
|
-
t.pointers.delete(e.pointerId), t.active = !1;
|
|
493
|
-
}, []);
|
|
494
|
-
x(() => {
|
|
495
|
-
T.current = R?.current ?? globalThis, m.current = new AbortController();
|
|
496
|
-
const e = (v) => g(v), t = (v) => Y(v), D = (v) => X(v), P = (v) => K(v);
|
|
497
|
-
return T.current.addEventListener(
|
|
498
|
-
"pointerdown",
|
|
499
|
-
e,
|
|
500
|
-
{
|
|
501
|
-
capture: r,
|
|
502
|
-
signal: m.current.signal
|
|
503
|
-
}
|
|
504
|
-
), T.current.addEventListener(
|
|
505
|
-
"pointermove",
|
|
506
|
-
t,
|
|
507
|
-
{
|
|
508
|
-
capture: r,
|
|
509
|
-
signal: m.current.signal
|
|
510
|
-
}
|
|
511
|
-
), T.current.addEventListener("pointerup", D, {
|
|
512
|
-
capture: r,
|
|
513
|
-
signal: m.current.signal
|
|
514
|
-
}), T.current.addEventListener(
|
|
515
|
-
"pointercancel",
|
|
516
|
-
P,
|
|
517
|
-
{
|
|
518
|
-
capture: r,
|
|
519
|
-
signal: m.current.signal
|
|
520
|
-
}
|
|
521
|
-
), () => {
|
|
522
|
-
m.current?.abort(), d.current.active = !1, d.current.pointers.clear(), y.current !== null && cancelAnimationFrame(y.current);
|
|
523
|
-
};
|
|
524
|
-
}, [
|
|
525
|
-
R,
|
|
526
|
-
r,
|
|
527
|
-
g,
|
|
528
|
-
Y,
|
|
529
|
-
X,
|
|
530
|
-
K
|
|
531
|
-
]);
|
|
532
|
-
}, pe = {
|
|
533
|
-
Touch: "touch",
|
|
534
|
-
Mouse: "mouse",
|
|
535
|
-
Pen: "pen"
|
|
536
|
-
}, b = {
|
|
537
|
-
Left: "left",
|
|
538
|
-
Right: "right",
|
|
539
|
-
Up: "up",
|
|
540
|
-
Down: "down",
|
|
541
|
-
Horizontal: "horizontal",
|
|
542
|
-
Vertical: "vertical",
|
|
543
|
-
Both: "both"
|
|
544
|
-
}, fe = {
|
|
545
|
-
Touch: "touch",
|
|
546
|
-
Mouse: "mouse",
|
|
547
|
-
Pen: "pen"
|
|
548
|
-
}, re = (n) => Array.isArray(n) ? n : [n], oe = (n, s, c, r, a) => {
|
|
549
|
-
a.stopImmediate && n.stopImmediatePropagation(), r(n, s, c) && n.preventDefault(), a.once && a.onOnce?.();
|
|
550
|
-
}, se = {
|
|
551
|
-
eventPointerTypes: ["touch", "mouse", "pen"],
|
|
552
|
-
eventCapture: !1,
|
|
553
|
-
eventOnce: !1,
|
|
554
|
-
eventStopImmediatePropagation: !1,
|
|
555
|
-
threshold: 50,
|
|
556
|
-
velocity: 0.3,
|
|
557
|
-
container: { current: null }
|
|
558
|
-
}, me = (n, s, c = {}) => {
|
|
559
|
-
const {
|
|
560
|
-
eventPointerTypes: r,
|
|
561
|
-
eventCapture: a,
|
|
562
|
-
eventOnce: p,
|
|
563
|
-
eventStopImmediatePropagation: f,
|
|
564
|
-
threshold: R,
|
|
565
|
-
velocity: O,
|
|
566
|
-
container: T
|
|
567
|
-
} = { ...se, ...c }, m = E([]), y = E(null), h = E(null), A = E({
|
|
568
|
-
startX: 0,
|
|
569
|
-
startY: 0,
|
|
570
|
-
startTime: 0,
|
|
571
|
-
active: !1
|
|
572
|
-
}), d = u(() => {
|
|
573
|
-
h.current?.abort();
|
|
574
|
-
}, []), S = u(
|
|
575
|
-
(e, t) => {
|
|
576
|
-
const D = Math.abs(e), P = Math.abs(t);
|
|
577
|
-
return D > P ? e > 0 ? b.Right : b.Left : t > 0 ? b.Down : b.Up;
|
|
578
|
-
},
|
|
579
|
-
[]
|
|
580
|
-
), L = u((e) => {
|
|
581
|
-
const t = m.current;
|
|
582
|
-
return t.includes(b.Both) || t.includes(b.Horizontal) && (e === b.Left || e === b.Right) || t.includes(b.Vertical) && (e === b.Up || e === b.Down) ? !0 : t.includes(e);
|
|
583
|
-
}, []), g = u(
|
|
584
|
-
(e) => {
|
|
585
|
-
e.isPrimary && r.includes(e.pointerType) && (A.current = {
|
|
586
|
-
startX: e.clientX,
|
|
587
|
-
startY: e.clientY,
|
|
588
|
-
startTime: Date.now(),
|
|
589
|
-
active: !0
|
|
590
|
-
});
|
|
591
|
-
},
|
|
592
|
-
[r]
|
|
593
|
-
), Y = u(
|
|
594
|
-
(e) => {
|
|
595
|
-
const t = A.current;
|
|
596
|
-
if (!t.active)
|
|
597
|
-
return;
|
|
598
|
-
t.active = !1;
|
|
599
|
-
const D = Date.now() - t.startTime;
|
|
600
|
-
if (D === 0)
|
|
601
|
-
return;
|
|
602
|
-
const P = e.clientX - t.startX, v = e.clientY - t.startY, M = Math.hypot(P, v), o = M / D;
|
|
603
|
-
if (M < R || o < O)
|
|
604
|
-
return;
|
|
605
|
-
const i = S(P, v);
|
|
606
|
-
if (!L(i))
|
|
607
|
-
return;
|
|
608
|
-
oe(e, i, {
|
|
609
|
-
deltaX: P,
|
|
610
|
-
deltaY: v,
|
|
611
|
-
velocity: o,
|
|
612
|
-
duration: D
|
|
613
|
-
}, s, {
|
|
614
|
-
stopImmediate: f,
|
|
615
|
-
once: p,
|
|
616
|
-
onOnce: () => {
|
|
617
|
-
d();
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
},
|
|
621
|
-
[
|
|
622
|
-
R,
|
|
623
|
-
O,
|
|
624
|
-
S,
|
|
625
|
-
L,
|
|
626
|
-
s,
|
|
627
|
-
p,
|
|
628
|
-
f,
|
|
629
|
-
d
|
|
630
|
-
]
|
|
631
|
-
), X = u(
|
|
632
|
-
(e) => {
|
|
633
|
-
e.isPrimary && r.includes(e.pointerType) && Y(e);
|
|
634
|
-
},
|
|
635
|
-
[Y, r]
|
|
636
|
-
), K = u(() => {
|
|
637
|
-
A.current.active = !1;
|
|
638
|
-
}, []);
|
|
639
|
-
x(() => {
|
|
640
|
-
m.current = re(n);
|
|
641
|
-
}, [n]), x(() => {
|
|
642
|
-
y.current = T?.current ?? globalThis, h.current = new AbortController();
|
|
643
|
-
const e = (P) => g(P);
|
|
644
|
-
y.current.addEventListener(
|
|
645
|
-
"pointerdown",
|
|
646
|
-
e,
|
|
647
|
-
{
|
|
648
|
-
capture: a,
|
|
649
|
-
signal: h.current.signal
|
|
650
|
-
}
|
|
651
|
-
);
|
|
652
|
-
const t = (P) => X(P);
|
|
653
|
-
y.current.addEventListener("pointerup", t, {
|
|
654
|
-
capture: a,
|
|
655
|
-
signal: h.current.signal
|
|
656
|
-
});
|
|
657
|
-
const D = () => K();
|
|
658
|
-
return y.current.addEventListener(
|
|
659
|
-
"pointercancel",
|
|
660
|
-
D,
|
|
661
|
-
{
|
|
662
|
-
capture: a,
|
|
663
|
-
signal: h.current.signal
|
|
664
|
-
}
|
|
665
|
-
), () => {
|
|
666
|
-
h.current?.abort(), A.current.active = !1;
|
|
667
|
-
};
|
|
668
|
-
}, [
|
|
669
|
-
T,
|
|
670
|
-
a,
|
|
671
|
-
g,
|
|
672
|
-
X,
|
|
673
|
-
K
|
|
674
|
-
]);
|
|
675
|
-
}, V = (n, s, c, r) => {
|
|
676
|
-
r.stopImmediate && n.stopImmediatePropagation(), c(n, s) && n.preventDefault(), r.once && r.onOnce?.();
|
|
677
|
-
}, j = {
|
|
678
|
-
eventPassive: !0,
|
|
679
|
-
eventCapture: !1,
|
|
680
|
-
eventOnce: !1,
|
|
681
|
-
eventStopImmediatePropagation: !1,
|
|
682
|
-
container: { current: null },
|
|
683
|
-
raf: !1
|
|
684
|
-
}, he = (n, s = j) => {
|
|
685
|
-
const {
|
|
686
|
-
eventPassive: c,
|
|
687
|
-
eventCapture: r,
|
|
688
|
-
eventOnce: a,
|
|
689
|
-
eventStopImmediatePropagation: p,
|
|
690
|
-
container: f,
|
|
691
|
-
raf: R
|
|
692
|
-
} = { ...j, ...s }, O = E(null), T = E(null), m = E(null), y = E(null), h = E(null), A = u(() => {
|
|
693
|
-
T.current?.abort();
|
|
694
|
-
}, []), d = u(() => {
|
|
695
|
-
m.current = null;
|
|
696
|
-
const L = y.current, g = h.current;
|
|
697
|
-
!L || !g || (V(g, L, n, {
|
|
698
|
-
stopImmediate: p,
|
|
699
|
-
once: a,
|
|
700
|
-
onOnce: () => {
|
|
701
|
-
A();
|
|
702
|
-
}
|
|
703
|
-
}), y.current = null, h.current = null);
|
|
704
|
-
}, [
|
|
705
|
-
n,
|
|
706
|
-
p,
|
|
707
|
-
a,
|
|
708
|
-
A
|
|
709
|
-
]), S = u(
|
|
710
|
-
(L) => {
|
|
711
|
-
const g = {
|
|
712
|
-
deltaX: L.deltaX,
|
|
713
|
-
deltaY: L.deltaY,
|
|
714
|
-
deltaZ: L.deltaZ,
|
|
715
|
-
deltaMode: L.deltaMode
|
|
716
|
-
};
|
|
717
|
-
if (!R) {
|
|
718
|
-
V(L, g, n, {
|
|
719
|
-
stopImmediate: p,
|
|
720
|
-
once: a,
|
|
721
|
-
onOnce: () => {
|
|
722
|
-
A();
|
|
723
|
-
}
|
|
724
|
-
});
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
727
|
-
y.current = g, h.current = L, m.current === null && (m.current = requestAnimationFrame(d));
|
|
728
|
-
},
|
|
729
|
-
[
|
|
730
|
-
R,
|
|
731
|
-
n,
|
|
732
|
-
p,
|
|
733
|
-
a,
|
|
734
|
-
A,
|
|
735
|
-
d
|
|
736
|
-
]
|
|
737
|
-
);
|
|
738
|
-
x(() => {
|
|
739
|
-
O.current = f?.current ?? globalThis, T.current = new AbortController();
|
|
740
|
-
const L = (g) => S(g);
|
|
741
|
-
return O.current.addEventListener("wheel", L, {
|
|
742
|
-
passive: c,
|
|
743
|
-
capture: r,
|
|
744
|
-
signal: T.current.signal
|
|
745
|
-
}), () => {
|
|
746
|
-
T.current?.abort(), m.current !== null && cancelAnimationFrame(m.current);
|
|
747
|
-
};
|
|
748
|
-
}, [f, c, r, S]);
|
|
749
|
-
};
|
|
750
|
-
export {
|
|
751
|
-
ue as DragEventPointerTypes,
|
|
752
|
-
F as KeyEventTypes,
|
|
753
|
-
pe as PinchEventPointerTypes,
|
|
754
|
-
b as SwipeDirections,
|
|
755
|
-
fe as SwipeEventPointerTypes,
|
|
756
|
-
ie as useDrag,
|
|
757
|
-
le as useKey,
|
|
758
|
-
de as usePinch,
|
|
759
|
-
me as useSwipe,
|
|
760
|
-
he as useWheel
|
|
761
|
-
};
|