@msobiecki/react-marauders-path 1.24.1 → 1.24.2
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 +3 -3
- package/dist/index.es.js +0 -761
- /package/dist/{index.es.d.ts → index.d.ts} +0 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { useRef as a, useCallback as l, useEffect as F } from "react";
|
|
2
|
+
import { invokePinchAction as A } from "./invoke-pinch-action.js";
|
|
3
|
+
const S = {
|
|
4
|
+
eventPointerTypes: ["touch"],
|
|
5
|
+
eventCapture: !1,
|
|
6
|
+
eventOnce: !1,
|
|
7
|
+
eventStopImmediatePropagation: !1,
|
|
8
|
+
threshold: 0,
|
|
9
|
+
container: { current: null },
|
|
10
|
+
raf: !1
|
|
11
|
+
}, x = (f, C = {}) => {
|
|
12
|
+
const {
|
|
13
|
+
eventPointerTypes: I,
|
|
14
|
+
eventCapture: u,
|
|
15
|
+
eventOnce: v,
|
|
16
|
+
eventStopImmediatePropagation: m,
|
|
17
|
+
threshold: L,
|
|
18
|
+
container: R,
|
|
19
|
+
raf: y
|
|
20
|
+
} = { ...S, ...C }, p = a(null), s = a(null), d = a(null), g = a(null), D = a(null), i = a({
|
|
21
|
+
pointers: /* @__PURE__ */ new Map(),
|
|
22
|
+
startDistance: 0,
|
|
23
|
+
lastDistance: 0,
|
|
24
|
+
active: !1
|
|
25
|
+
}), h = l(() => {
|
|
26
|
+
s.current?.abort();
|
|
27
|
+
}, []), E = l(() => {
|
|
28
|
+
d.current = null;
|
|
29
|
+
const t = g.current, e = D.current;
|
|
30
|
+
!t || !e || (A(e, t, f, {
|
|
31
|
+
stopImmediate: m,
|
|
32
|
+
once: v,
|
|
33
|
+
onOnce: () => h()
|
|
34
|
+
}), g.current = null, D.current = null);
|
|
35
|
+
}, [
|
|
36
|
+
f,
|
|
37
|
+
m,
|
|
38
|
+
v,
|
|
39
|
+
h
|
|
40
|
+
]), M = l(
|
|
41
|
+
(t) => {
|
|
42
|
+
if (!I.includes(t.pointerType))
|
|
43
|
+
return;
|
|
44
|
+
const e = i.current;
|
|
45
|
+
if (e.pointers.set(t.pointerId, t), e.pointers.size === 2) {
|
|
46
|
+
const [c, o] = [...e.pointers.values()], n = o.clientX - c.clientX, P = o.clientY - c.clientY, r = Math.hypot(n, P);
|
|
47
|
+
e.startDistance = r, e.lastDistance = r, e.active = !0;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
[I]
|
|
51
|
+
), X = l(
|
|
52
|
+
(t) => {
|
|
53
|
+
const e = i.current;
|
|
54
|
+
if (!e.active || !e.pointers.has(t.pointerId) || (e.pointers.set(t.pointerId, t), e.pointers.size < 2)) return;
|
|
55
|
+
const [c, o] = [...e.pointers.values()], n = o.clientX - c.clientX, P = o.clientY - c.clientY, r = Math.hypot(n, P), T = r - e.lastDistance, O = r - e.startDistance;
|
|
56
|
+
if (Math.abs(O) < L) return;
|
|
57
|
+
const z = r / e.startDistance, b = {
|
|
58
|
+
distance: r,
|
|
59
|
+
delta: T,
|
|
60
|
+
totalDelta: O,
|
|
61
|
+
scale: z
|
|
62
|
+
};
|
|
63
|
+
if (e.lastDistance = r, !y) {
|
|
64
|
+
A(t, b, f, {
|
|
65
|
+
stopImmediate: m,
|
|
66
|
+
once: v,
|
|
67
|
+
onOnce: () => h()
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
g.current = b, D.current = t, d.current === null && (d.current = requestAnimationFrame(E));
|
|
72
|
+
},
|
|
73
|
+
[
|
|
74
|
+
L,
|
|
75
|
+
y,
|
|
76
|
+
f,
|
|
77
|
+
m,
|
|
78
|
+
v,
|
|
79
|
+
h,
|
|
80
|
+
E
|
|
81
|
+
]
|
|
82
|
+
), Y = l((t) => {
|
|
83
|
+
const e = i.current;
|
|
84
|
+
e.pointers.delete(t.pointerId), e.pointers.size < 2 && (e.active = !1, e.startDistance = 0, e.lastDistance = 0);
|
|
85
|
+
}, []), w = l((t) => {
|
|
86
|
+
const e = i.current;
|
|
87
|
+
e.pointers.delete(t.pointerId), e.active = !1;
|
|
88
|
+
}, []);
|
|
89
|
+
F(() => {
|
|
90
|
+
p.current = R?.current ?? globalThis, s.current = new AbortController();
|
|
91
|
+
const t = (n) => M(n), e = (n) => X(n), c = (n) => Y(n), o = (n) => w(n);
|
|
92
|
+
return p.current.addEventListener(
|
|
93
|
+
"pointerdown",
|
|
94
|
+
t,
|
|
95
|
+
{
|
|
96
|
+
capture: u,
|
|
97
|
+
signal: s.current.signal
|
|
98
|
+
}
|
|
99
|
+
), p.current.addEventListener(
|
|
100
|
+
"pointermove",
|
|
101
|
+
e,
|
|
102
|
+
{
|
|
103
|
+
capture: u,
|
|
104
|
+
signal: s.current.signal
|
|
105
|
+
}
|
|
106
|
+
), p.current.addEventListener("pointerup", c, {
|
|
107
|
+
capture: u,
|
|
108
|
+
signal: s.current.signal
|
|
109
|
+
}), p.current.addEventListener(
|
|
110
|
+
"pointercancel",
|
|
111
|
+
o,
|
|
112
|
+
{
|
|
113
|
+
capture: u,
|
|
114
|
+
signal: s.current.signal
|
|
115
|
+
}
|
|
116
|
+
), () => {
|
|
117
|
+
s.current?.abort(), i.current.active = !1, i.current.pointers.clear(), d.current !== null && cancelAnimationFrame(d.current);
|
|
118
|
+
};
|
|
119
|
+
}, [
|
|
120
|
+
R,
|
|
121
|
+
u,
|
|
122
|
+
M,
|
|
123
|
+
X,
|
|
124
|
+
Y,
|
|
125
|
+
w
|
|
126
|
+
]);
|
|
127
|
+
};
|
|
128
|
+
export {
|
|
129
|
+
x as default
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=use-pinch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-pinch.js","sources":["../../src/use-pinch/use-pinch.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from \"react\";\nimport {\n PinchState,\n PinchData,\n UsePinchCallback,\n UsePinchOptions,\n PinchOptions,\n PinchEventPointerType,\n} from \"./use-pinch.types\";\nimport { invokePinchAction } from \"./invoke-pinch-action\";\n\nconst defaultOptions: PinchOptions = {\n eventPointerTypes: [\"touch\"],\n eventCapture: false,\n eventOnce: false,\n eventStopImmediatePropagation: false,\n threshold: 0,\n container: { current: null },\n raf: false,\n};\n\nconst usePinch = (\n pinchCallback: UsePinchCallback,\n options: UsePinchOptions = {},\n) => {\n const {\n eventPointerTypes,\n eventCapture,\n eventOnce,\n eventStopImmediatePropagation,\n threshold,\n container,\n raf,\n } = { ...defaultOptions, ...options };\n\n const targetReference = useRef<EventTarget | null>(null);\n const abortControllerReference = useRef<AbortController | null>(null);\n\n const frameReference = useRef<number | null>(null);\n const pendingDataReference = useRef<PinchData | null>(null);\n const pendingEventReference = useRef<PointerEvent | null>(null);\n\n const pinchStateReference = useRef<PinchState>({\n pointers: new Map(),\n startDistance: 0,\n lastDistance: 0,\n active: false,\n });\n\n const destroyListener = useCallback(() => {\n abortControllerReference.current?.abort();\n }, []);\n\n const flushFrame = useCallback(() => {\n frameReference.current = null;\n\n const data = pendingDataReference.current;\n const event = pendingEventReference.current;\n\n if (!data || !event) return;\n\n invokePinchAction(event, data, pinchCallback, {\n stopImmediate: eventStopImmediatePropagation,\n once: eventOnce,\n onOnce: () => destroyListener(),\n });\n\n pendingDataReference.current = null;\n pendingEventReference.current = null;\n }, [\n pinchCallback,\n eventStopImmediatePropagation,\n eventOnce,\n destroyListener,\n ]);\n\n const handlePointerDown = useCallback(\n (event: PointerEvent) => {\n if (\n !eventPointerTypes.includes(event.pointerType as PinchEventPointerType)\n ) {\n return;\n }\n\n const state = pinchStateReference.current;\n\n state.pointers.set(event.pointerId, event);\n\n if (state.pointers.size === 2) {\n const [pointer1, pointer2] = [...state.pointers.values()];\n\n const deltaX = pointer2.clientX - pointer1.clientX;\n const deltaY = pointer2.clientY - pointer1.clientY;\n\n const distance = Math.hypot(deltaX, deltaY);\n\n state.startDistance = distance;\n state.lastDistance = distance;\n state.active = true;\n }\n },\n [eventPointerTypes],\n );\n\n const handlePointerMove = useCallback(\n (event: PointerEvent) => {\n const state = pinchStateReference.current;\n if (!state.active) return;\n\n if (!state.pointers.has(event.pointerId)) return;\n\n state.pointers.set(event.pointerId, event);\n\n if (state.pointers.size < 2) return;\n\n const [pointer1, pointer2] = [...state.pointers.values()];\n\n const deltaX = pointer2.clientX - pointer1.clientX;\n const deltaY = pointer2.clientY - pointer1.clientY;\n\n const distance = Math.hypot(deltaX, deltaY);\n\n const delta = distance - state.lastDistance;\n const totalDelta = distance - state.startDistance;\n\n if (Math.abs(totalDelta) < threshold) return;\n\n const scale = distance / state.startDistance;\n\n const data: PinchData = {\n distance,\n delta,\n totalDelta,\n scale,\n };\n\n state.lastDistance = distance;\n\n if (!raf) {\n invokePinchAction(event, data, pinchCallback, {\n stopImmediate: eventStopImmediatePropagation,\n once: eventOnce,\n onOnce: () => destroyListener(),\n });\n return;\n }\n\n pendingDataReference.current = data;\n pendingEventReference.current = event;\n\n if (frameReference.current === null) {\n frameReference.current = requestAnimationFrame(flushFrame);\n }\n },\n [\n threshold,\n raf,\n pinchCallback,\n eventStopImmediatePropagation,\n eventOnce,\n destroyListener,\n flushFrame,\n ],\n );\n\n const handlePointerUp = useCallback((event: PointerEvent) => {\n const state = pinchStateReference.current;\n\n state.pointers.delete(event.pointerId);\n\n if (state.pointers.size < 2) {\n state.active = false;\n state.startDistance = 0;\n state.lastDistance = 0;\n }\n }, []);\n\n const handlePointerCancel = useCallback((event: PointerEvent) => {\n const state = pinchStateReference.current;\n\n state.pointers.delete(event.pointerId);\n state.active = false;\n }, []);\n\n useEffect(() => {\n targetReference.current = container?.current ?? globalThis;\n abortControllerReference.current = new AbortController();\n\n const pointerDownListener = (event: Event) =>\n handlePointerDown(event as PointerEvent);\n\n const pointerMoveListener = (event: Event) =>\n handlePointerMove(event as PointerEvent);\n\n const pointerUpListener = (event: Event) =>\n handlePointerUp(event as PointerEvent);\n\n const pointerCancelListener = (event: Event) =>\n handlePointerCancel(event as PointerEvent);\n\n targetReference.current.addEventListener(\n \"pointerdown\",\n pointerDownListener,\n {\n capture: eventCapture,\n signal: abortControllerReference.current.signal,\n },\n );\n\n targetReference.current.addEventListener(\n \"pointermove\",\n pointerMoveListener,\n {\n capture: eventCapture,\n signal: abortControllerReference.current.signal,\n },\n );\n\n targetReference.current.addEventListener(\"pointerup\", pointerUpListener, {\n capture: eventCapture,\n signal: abortControllerReference.current.signal,\n });\n\n targetReference.current.addEventListener(\n \"pointercancel\",\n pointerCancelListener,\n {\n capture: eventCapture,\n signal: abortControllerReference.current.signal,\n },\n );\n\n return () => {\n abortControllerReference.current?.abort();\n pinchStateReference.current.active = false;\n pinchStateReference.current.pointers.clear();\n\n if (frameReference.current !== null) {\n cancelAnimationFrame(frameReference.current);\n }\n };\n }, [\n container,\n eventCapture,\n handlePointerDown,\n handlePointerMove,\n handlePointerUp,\n handlePointerCancel,\n ]);\n};\n\nexport default usePinch;\n"],"names":["defaultOptions","usePinch","pinchCallback","options","eventPointerTypes","eventCapture","eventOnce","eventStopImmediatePropagation","threshold","container","raf","targetReference","useRef","abortControllerReference","frameReference","pendingDataReference","pendingEventReference","pinchStateReference","destroyListener","useCallback","flushFrame","data","event","invokePinchAction","handlePointerDown","state","pointer1","pointer2","deltaX","deltaY","distance","handlePointerMove","delta","totalDelta","scale","handlePointerUp","handlePointerCancel","useEffect","pointerDownListener","pointerMoveListener","pointerUpListener","pointerCancelListener"],"mappings":";;AAWA,MAAMA,IAA+B;AAAA,EACnC,mBAAmB,CAAC,OAAO;AAAA,EAC3B,cAAc;AAAA,EACd,WAAW;AAAA,EACX,+BAA+B;AAAA,EAC/B,WAAW;AAAA,EACX,WAAW,EAAE,SAAS,KAAA;AAAA,EACtB,KAAK;AACP,GAEMC,IAAW,CACfC,GACAC,IAA2B,OACxB;AACH,QAAM;AAAA,IACJ,mBAAAC;AAAA,IACA,cAAAC;AAAA,IACA,WAAAC;AAAA,IACA,+BAAAC;AAAA,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EAAoB,QAAQ,SAAS,IACrCA,EAAoB,QAAQ,SAAS,MAAA,GAEjCH,EAAe,YAAY,QAC7B,qBAAqBA,EAAe,OAAO;AAAA,IAE/C;AAAA,EACF,GAAG;AAAA,IACDL;AAAA,IACAJ;AAAA,IACAmB;AAAA,IACAO;AAAA,IACAI;AAAA,IACAC;AAAA,EAAA,CACD;AACH;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-pinch.types.js","sources":["../../src/use-pinch/use-pinch.types.ts"],"sourcesContent":["export interface PinchState {\n pointers: Map<number, PointerEvent>;\n startDistance: number;\n lastDistance: number;\n active: boolean;\n}\n\nexport const PinchEventPointerTypes = {\n Touch: \"touch\",\n Mouse: \"mouse\",\n Pen: \"pen\",\n} as const;\n\nexport type PinchEventPointerType =\n (typeof PinchEventPointerTypes)[keyof typeof PinchEventPointerTypes];\n\nexport interface PinchOptions {\n eventPointerTypes: PinchEventPointerType[];\n eventCapture: boolean;\n eventOnce: boolean;\n eventStopImmediatePropagation: boolean;\n threshold: number;\n container: { current: HTMLElement | null };\n raf: boolean;\n}\n\nexport interface PinchData {\n distance: number;\n delta: number;\n totalDelta: number;\n scale: number;\n}\n\nexport type UsePinchCallback =\n | ((event: PointerEvent, data: PinchData) => boolean)\n | ((event: PointerEvent, data: PinchData) => void);\n\nexport type UsePinchOptions = Partial<PinchOptions>;\n"],"names":["PinchEventPointerTypes"],"mappings":"AAOO,MAAMA,IAAyB;AAAA,EACpC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,KAAK;AACP;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoke-swipe-action.js","sources":["../../src/use-swipe/invoke-swipe-action.ts"],"sourcesContent":["import { SwipeData, SwipeDirection } from \"./use-swipe.types\";\n\n/**\n * Invokes a swipe action callback with optional event modifications.\n *\n * Handles swipe event processing including preventing default behavior,\n * stopping immediate propagation, and managing one-time event handlers.\n *\n * @param {PointerEvent} event - The swipe event\n * @param {SwipeData} data - The normalized swipe data\n * @param {Function} callback - Function to invoke with (event, data). Return true to prevent default.\n * @param {Object} options - Action options\n * @param {boolean} [options.stopImmediate=false] - Whether to stop immediate propagation\n * @param {boolean} [options.once=false] - Whether this is a one-time event\n * @param {Function} [options.onOnce] - Callback to invoke when one-time event fires\n *\n * @example\n * invokeSwipeAction(event, data, (e, d) => {\n * console.log(`Swipe moved: ${d.x}, ${d.y}, ${d.z}`);\n * return true; // Prevent default\n * }, { stopImmediate: true });\n */\nexport const invokeSwipeAction = (\n event: PointerEvent,\n direction: SwipeDirection,\n data: SwipeData,\n callback:\n | ((\n event: PointerEvent,\n direction: SwipeDirection,\n data: SwipeData,\n ) => boolean)\n | ((\n event: PointerEvent,\n direction: SwipeDirection,\n data: SwipeData,\n ) => void),\n options: {\n stopImmediate?: boolean;\n once?: boolean;\n onOnce?: () => void;\n },\n) => {\n if (options.stopImmediate) {\n event.stopImmediatePropagation();\n }\n\n const shouldPrevent = callback(event, direction, data);\n if (shouldPrevent) {\n event.preventDefault();\n }\n\n if (options.once) {\n options.onOnce?.();\n }\n};\n"],"names":["invokeSwipeAction","event","direction","data","callback","options"],"mappings":"AAsBO,MAAMA,IAAoB,CAC/BC,GACAC,GACAC,GACAC,GAWAC,MAKG;AACH,EAAIA,EAAQ,iBACVJ,EAAM,yBAAA,GAGcG,EAASH,GAAOC,GAAWC,CAAI,KAEnDF,EAAM,eAAA,GAGJI,EAAQ,QACVA,EAAQ,SAAA;AAEZ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-swipe-direction.js","sources":["../../src/use-swipe/parse-swipe-direction.ts"],"sourcesContent":["import { SwipeDirection } from \"./use-swipe.types\";\n\n/**\n * Parses the swipe direction schema into an array of swipe directions.\n *\n * Converts a single SwipeDirection or an array of SwipeDirections into a consistent array format.\n * This allows the useSwipe hook to uniformly handle both single and multiple direction schemas.\n *\n * @param {SwipeDirection | SwipeDirection[]} input - The swipe direction(s) to parse\n * @returns {SwipeDirection[]} An array of swipe directions\n *\n * @example\n * parseSwipeDirection('left') // ['left']\n * parseSwipeDirection(['left', 'up']) // ['left', 'up']\n */\nexport const parseSwipeDirection = (\n input: SwipeDirection | SwipeDirection[],\n): SwipeDirection[] => {\n return Array.isArray(input) ? input : [input];\n};\n"],"names":["parseSwipeDirection","input"],"mappings":"AAeO,MAAMA,IAAsB,CACjCC,MAEO,MAAM,QAAQA,CAAK,IAAIA,IAAQ,CAACA,CAAK;"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { useRef as p, useCallback as i, useEffect as O } from "react";
|
|
2
|
+
import { SwipeDirections as n } from "./use-swipe.types.js";
|
|
3
|
+
import { parseSwipeDirection as I } from "./parse-swipe-direction.js";
|
|
4
|
+
import { invokeSwipeAction as M } from "./invoke-swipe-action.js";
|
|
5
|
+
const A = {
|
|
6
|
+
eventPointerTypes: ["touch", "mouse", "pen"],
|
|
7
|
+
eventCapture: !1,
|
|
8
|
+
eventOnce: !1,
|
|
9
|
+
eventStopImmediatePropagation: !1,
|
|
10
|
+
threshold: 50,
|
|
11
|
+
velocity: 0.3,
|
|
12
|
+
container: { current: null }
|
|
13
|
+
}, H = (d, m, U = {}) => {
|
|
14
|
+
const {
|
|
15
|
+
eventPointerTypes: s,
|
|
16
|
+
eventCapture: a,
|
|
17
|
+
eventOnce: h,
|
|
18
|
+
eventStopImmediatePropagation: v,
|
|
19
|
+
threshold: w,
|
|
20
|
+
velocity: g,
|
|
21
|
+
container: y
|
|
22
|
+
} = { ...A, ...U }, D = p([]), u = p(null), c = p(null), l = p({
|
|
23
|
+
startX: 0,
|
|
24
|
+
startY: 0,
|
|
25
|
+
startTime: 0,
|
|
26
|
+
active: !1
|
|
27
|
+
}), b = i(() => {
|
|
28
|
+
c.current?.abort();
|
|
29
|
+
}, []), L = i(
|
|
30
|
+
(e, t) => {
|
|
31
|
+
const o = Math.abs(e), r = Math.abs(t);
|
|
32
|
+
return o > r ? e > 0 ? n.Right : n.Left : t > 0 ? n.Down : n.Up;
|
|
33
|
+
},
|
|
34
|
+
[]
|
|
35
|
+
), P = i((e) => {
|
|
36
|
+
const t = D.current;
|
|
37
|
+
return t.includes(n.Both) || t.includes(n.Horizontal) && (e === n.Left || e === n.Right) || t.includes(n.Vertical) && (e === n.Up || e === n.Down) ? !0 : t.includes(e);
|
|
38
|
+
}, []), S = i(
|
|
39
|
+
(e) => {
|
|
40
|
+
e.isPrimary && s.includes(e.pointerType) && (l.current = {
|
|
41
|
+
startX: e.clientX,
|
|
42
|
+
startY: e.clientY,
|
|
43
|
+
startTime: Date.now(),
|
|
44
|
+
active: !0
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
[s]
|
|
48
|
+
), T = i(
|
|
49
|
+
(e) => {
|
|
50
|
+
const t = l.current;
|
|
51
|
+
if (!t.active)
|
|
52
|
+
return;
|
|
53
|
+
t.active = !1;
|
|
54
|
+
const o = Date.now() - t.startTime;
|
|
55
|
+
if (o === 0)
|
|
56
|
+
return;
|
|
57
|
+
const r = e.clientX - t.startX, f = e.clientY - t.startY, X = Math.hypot(r, f), Y = X / o;
|
|
58
|
+
if (X < w || Y < g)
|
|
59
|
+
return;
|
|
60
|
+
const E = L(r, f);
|
|
61
|
+
if (!P(E))
|
|
62
|
+
return;
|
|
63
|
+
M(e, E, {
|
|
64
|
+
deltaX: r,
|
|
65
|
+
deltaY: f,
|
|
66
|
+
velocity: Y,
|
|
67
|
+
duration: o
|
|
68
|
+
}, m, {
|
|
69
|
+
stopImmediate: v,
|
|
70
|
+
once: h,
|
|
71
|
+
onOnce: () => {
|
|
72
|
+
b();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
[
|
|
77
|
+
w,
|
|
78
|
+
g,
|
|
79
|
+
L,
|
|
80
|
+
P,
|
|
81
|
+
m,
|
|
82
|
+
h,
|
|
83
|
+
v,
|
|
84
|
+
b
|
|
85
|
+
]
|
|
86
|
+
), R = i(
|
|
87
|
+
(e) => {
|
|
88
|
+
e.isPrimary && s.includes(e.pointerType) && T(e);
|
|
89
|
+
},
|
|
90
|
+
[T, s]
|
|
91
|
+
), C = i(() => {
|
|
92
|
+
l.current.active = !1;
|
|
93
|
+
}, []);
|
|
94
|
+
O(() => {
|
|
95
|
+
D.current = I(d);
|
|
96
|
+
}, [d]), O(() => {
|
|
97
|
+
u.current = y?.current ?? globalThis, c.current = new AbortController();
|
|
98
|
+
const e = (r) => S(r);
|
|
99
|
+
u.current.addEventListener(
|
|
100
|
+
"pointerdown",
|
|
101
|
+
e,
|
|
102
|
+
{
|
|
103
|
+
capture: a,
|
|
104
|
+
signal: c.current.signal
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
const t = (r) => R(r);
|
|
108
|
+
u.current.addEventListener("pointerup", t, {
|
|
109
|
+
capture: a,
|
|
110
|
+
signal: c.current.signal
|
|
111
|
+
});
|
|
112
|
+
const o = () => C();
|
|
113
|
+
return u.current.addEventListener(
|
|
114
|
+
"pointercancel",
|
|
115
|
+
o,
|
|
116
|
+
{
|
|
117
|
+
capture: a,
|
|
118
|
+
signal: c.current.signal
|
|
119
|
+
}
|
|
120
|
+
), () => {
|
|
121
|
+
c.current?.abort(), l.current.active = !1;
|
|
122
|
+
};
|
|
123
|
+
}, [
|
|
124
|
+
y,
|
|
125
|
+
a,
|
|
126
|
+
S,
|
|
127
|
+
R,
|
|
128
|
+
C
|
|
129
|
+
]);
|
|
130
|
+
};
|
|
131
|
+
export {
|
|
132
|
+
H as default
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=use-swipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-swipe.js","sources":["../../src/use-swipe/use-swipe.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from \"react\";\nimport {\n SwipeDirection,\n SwipeState,\n SwipeData,\n UseSwipeSchema,\n UseSwipeOptions,\n UseSwipeCallback,\n SwipeOptions,\n SwipeDirections,\n SwipeEventPointerType,\n} from \"./use-swipe.types\";\nimport { parseSwipeDirection } from \"./parse-swipe-direction\";\nimport { invokeSwipeAction } from \"./invoke-swipe-action\";\n\nconst defaultOptions: SwipeOptions = {\n eventPointerTypes: [\"touch\", \"mouse\", \"pen\"],\n eventCapture: false,\n eventOnce: false,\n eventStopImmediatePropagation: false,\n threshold: 50,\n velocity: 0.3,\n container: { current: null },\n};\n\nconst useSwipe = (\n swipe: UseSwipeSchema,\n swipeCallback: UseSwipeCallback,\n options: UseSwipeOptions = {},\n) => {\n const {\n eventPointerTypes,\n eventCapture,\n eventOnce,\n eventStopImmediatePropagation,\n threshold,\n velocity,\n container,\n } = { ...defaultOptions, ...options };\n\n const allowedDirectionsReference = useRef<SwipeDirection[]>([]);\n const targetReference = useRef<EventTarget | null>(null);\n const abortControllerReference = useRef<AbortController | null>(null);\n\n const swipeStateReference = useRef<SwipeState>({\n startX: 0,\n startY: 0,\n startTime: 0,\n active: false,\n });\n\n const destroyListener = useCallback(() => {\n abortControllerReference.current?.abort();\n }, []);\n\n const resolveDirection = useCallback(\n (deltaX: number, deltaY: number): SwipeDirection => {\n const absX = Math.abs(deltaX);\n const absY = Math.abs(deltaY);\n\n if (absX > absY) {\n return deltaX > 0 ? SwipeDirections.Right : SwipeDirections.Left;\n }\n\n return deltaY > 0 ? SwipeDirections.Down : SwipeDirections.Up;\n },\n [],\n );\n\n const matchesSchema = useCallback((direction: SwipeDirection): boolean => {\n const allowed = allowedDirectionsReference.current;\n\n if (allowed.includes(SwipeDirections.Both)) {\n return true;\n }\n\n if (\n allowed.includes(SwipeDirections.Horizontal) &&\n (direction === SwipeDirections.Left ||\n direction === SwipeDirections.Right)\n ) {\n return true;\n }\n\n if (\n allowed.includes(SwipeDirections.Vertical) &&\n (direction === SwipeDirections.Up || direction === SwipeDirections.Down)\n ) {\n return true;\n }\n\n return allowed.includes(direction);\n }, []);\n\n const handlePointerDown = useCallback(\n (event: PointerEvent) => {\n if (!event.isPrimary) {\n return;\n }\n\n if (\n !eventPointerTypes.includes(event.pointerType as SwipeEventPointerType)\n ) {\n return;\n }\n\n swipeStateReference.current = {\n startX: event.clientX,\n startY: event.clientY,\n startTime: Date.now(),\n active: true,\n };\n },\n [eventPointerTypes],\n );\n\n const endSwipe = useCallback(\n (event: PointerEvent) => {\n const state = swipeStateReference.current;\n if (!state.active) {\n return;\n }\n\n state.active = false;\n\n const duration = Date.now() - state.startTime;\n\n if (duration === 0) {\n return;\n }\n\n const deltaX = event.clientX - state.startX;\n const deltaY = event.clientY - state.startY;\n\n const distance = Math.hypot(deltaX, deltaY);\n\n const computedVelocity = distance / duration;\n\n if (distance < threshold) {\n return;\n }\n if (computedVelocity < velocity) {\n return;\n }\n\n const direction = resolveDirection(deltaX, deltaY);\n if (!matchesSchema(direction)) {\n return;\n }\n\n const data: SwipeData = {\n deltaX,\n deltaY,\n velocity: computedVelocity,\n duration,\n };\n\n invokeSwipeAction(event, direction, data, swipeCallback, {\n stopImmediate: eventStopImmediatePropagation,\n once: eventOnce,\n onOnce: () => {\n destroyListener();\n },\n });\n },\n [\n threshold,\n velocity,\n resolveDirection,\n matchesSchema,\n swipeCallback,\n eventOnce,\n eventStopImmediatePropagation,\n destroyListener,\n ],\n );\n\n const handlePointerUp = useCallback(\n (event: PointerEvent) => {\n if (!event.isPrimary) {\n return;\n }\n if (\n !eventPointerTypes.includes(event.pointerType as SwipeEventPointerType)\n ) {\n return;\n }\n endSwipe(event);\n },\n [endSwipe, eventPointerTypes],\n );\n\n const handlePointerCancel = useCallback(() => {\n swipeStateReference.current.active = false;\n }, []);\n\n useEffect(() => {\n allowedDirectionsReference.current = parseSwipeDirection(swipe);\n }, [swipe]);\n\n useEffect(() => {\n targetReference.current = container?.current ?? globalThis;\n abortControllerReference.current = new AbortController();\n\n const pointerDownListener = (event: Event) =>\n handlePointerDown(event as PointerEvent);\n\n targetReference.current.addEventListener(\n \"pointerdown\",\n pointerDownListener,\n {\n capture: eventCapture,\n signal: abortControllerReference.current.signal,\n },\n );\n\n const pointerUpListener = (event: Event) =>\n handlePointerUp(event as PointerEvent);\n\n targetReference.current.addEventListener(\"pointerup\", pointerUpListener, {\n capture: eventCapture,\n signal: abortControllerReference.current.signal,\n });\n\n const pointerCancelListener = () => handlePointerCancel();\n\n targetReference.current.addEventListener(\n \"pointercancel\",\n pointerCancelListener,\n {\n capture: eventCapture,\n signal: abortControllerReference.current.signal,\n },\n );\n\n return () => {\n abortControllerReference.current?.abort();\n swipeStateReference.current.active = false;\n };\n }, [\n container,\n eventCapture,\n handlePointerDown,\n handlePointerUp,\n handlePointerCancel,\n ]);\n};\n\nexport default useSwipe;\n"],"names":["defaultOptions","useSwipe","swipe","swipeCallback","options","eventPointerTypes","eventCapture","eventOnce","eventStopImmediatePropagation","threshold","velocity","container","allowedDirectionsReference","useRef","targetReference","abortControllerReference","swipeStateReference","destroyListener","useCallback","resolveDirection","deltaX","deltaY","absX","absY","SwipeDirections","matchesSchema","direction","allowed","handlePointerDown","event","endSwipe","state","duration","distance","computedVelocity","invokeSwipeAction","handlePointerUp","handlePointerCancel","useEffect","parseSwipeDirection","pointerDownListener","pointerUpListener","pointerCancelListener"],"mappings":";;;;AAeA,MAAMA,IAA+B;AAAA,EACnC,mBAAmB,CAAC,SAAS,SAAS,KAAK;AAAA,EAC3C,cAAc;AAAA,EACd,WAAW;AAAA,EACX,+BAA+B;AAAA,EAC/B,WAAW;AAAA,EACX,UAAU;AAAA,EACV,WAAW,EAAE,SAAS,KAAA;AACxB,GAEMC,IAAW,CACfC,GACAC,GACAC,IAA2B,CAAA,MACxB;AACH,QAAM;AAAA,IACJ,mBAAAC;AAAA,IACA,cAAAC;AAAA,IACA,WAAAC;AAAA,IACA,+BAAAC;AAAA,IACA,WAAAC;AAAA,IACA,UAAAC;AAAA,IACA,WAAAC;AAAA,EAAA,IACE,EAAE,GAAGX,GAAgB,GAAGI,EAAA,GAEtBQ,IAA6BC,EAAyB,EAAE,GACxDC,IAAkBD,EAA2B,IAAI,GACjDE,IA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AAEzC,IAAAf,EAAgB,QAAQ;AAAA,MACtB;AAAA,MACA0B;AAAA,MACA;AAAA,QACE,SAASlC;AAAA,QACT,QAAQS,EAAyB,QAAQ;AAAA,MAAA;AAAA,IAC3C;AAGF,UAAM0B,IAAoB,CAACZ,MACzBO,EAAgBP,CAAqB;AAEvC,IAAAf,EAAgB,QAAQ,iBAAiB,aAAa2B,GAAmB;AAAA,MACvE,SAASnC;AAAA,MACT,QAAQS,EAAyB,QAAQ;AAAA,IAAA,CAC1C;AAED,UAAM2B,IAAwB,MAAML,EAAA;AAEpC,WAAAvB,EAAgB,QAAQ;AAAA,MACtB;AAAA,MACA4B;AAAA,MACA;AAAA,QACE,SAASpC;AAAA,QACT,QAAQS,EAAyB,QAAQ;AAAA,MAAA;AAAA,IAC3C,GAGK,MAAM;AACX,MAAAA,EAAyB,SAAS,MAAA,GAClCC,EAAoB,QAAQ,SAAS;AAAA,IACvC;AAAA,EACF,GAAG;AAAA,IACDL;AAAA,IACAL;AAAA,IACAsB;AAAA,IACAQ;AAAA,IACAC;AAAA,EAAA,CACD;AACH;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const o = {
|
|
2
|
+
Left: "left",
|
|
3
|
+
Right: "right",
|
|
4
|
+
Up: "up",
|
|
5
|
+
Down: "down",
|
|
6
|
+
Horizontal: "horizontal",
|
|
7
|
+
Vertical: "vertical",
|
|
8
|
+
Both: "both"
|
|
9
|
+
}, t = {
|
|
10
|
+
Touch: "touch",
|
|
11
|
+
Mouse: "mouse",
|
|
12
|
+
Pen: "pen"
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
o as SwipeDirections,
|
|
16
|
+
t as SwipeEventPointerTypes
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=use-swipe.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-swipe.types.js","sources":["../../src/use-swipe/use-swipe.types.ts"],"sourcesContent":["export const SwipeDirections = {\n Left: \"left\",\n Right: \"right\",\n Up: \"up\",\n Down: \"down\",\n Horizontal: \"horizontal\",\n Vertical: \"vertical\",\n Both: \"both\",\n} as const;\n\nexport type SwipeDirection =\n (typeof SwipeDirections)[keyof typeof SwipeDirections];\n\nexport interface SwipeState {\n startX: number;\n startY: number;\n startTime: number;\n active: boolean;\n}\n\nexport const SwipeEventPointerTypes = {\n Touch: \"touch\",\n Mouse: \"mouse\",\n Pen: \"pen\",\n} as const;\n\nexport type SwipeEventPointerType =\n (typeof SwipeEventPointerTypes)[keyof typeof SwipeEventPointerTypes];\n\nexport interface SwipeOptions {\n eventPointerTypes: SwipeEventPointerType[];\n eventCapture: boolean;\n eventOnce: boolean;\n eventStopImmediatePropagation: boolean;\n threshold: number;\n velocity: number;\n container: { current: HTMLElement | null };\n}\n\nexport interface SwipeData {\n deltaX: number;\n deltaY: number;\n velocity: number;\n duration: number;\n}\n\nexport type UseSwipeSchema = SwipeDirection | SwipeDirection[];\n\nexport type UseSwipeCallback =\n | ((\n event: PointerEvent,\n direction: SwipeDirection,\n data: SwipeData,\n ...properties: unknown[]\n ) => boolean)\n | ((\n event: PointerEvent,\n direction: SwipeDirection,\n data: SwipeData,\n ...properties: unknown[]\n ) => void);\n\nexport type UseSwipeOptions = Partial<SwipeOptions>;\n"],"names":["SwipeDirections","SwipeEventPointerTypes"],"mappings":"AAAO,MAAMA,IAAkB;AAAA,EAC7B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,UAAU;AAAA,EACV,MAAM;AACR,GAYaC,IAAyB;AAAA,EACpC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,KAAK;AACP;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoke-wheel-action.js","sources":["../../src/use-wheel/invoke-wheel-action.ts"],"sourcesContent":["import { WheelData } from \"./use-wheel.types\";\n\n/**\n * Invokes a wheel action callback with optional event modifications.\n *\n * Handles wheel event processing including preventing default behavior,\n * stopping immediate propagation, and managing one-time event handlers.\n *\n * @param {WheelEvent} event - The wheel event\n * @param {WheelData} delta - The normalized wheel delta\n * @param {Function} callback - Function to invoke with (event, delta). Return true to prevent default.\n * @param {Object} options - Action options\n * @param {boolean} [options.stopImmediate=false] - Whether to stop immediate propagation\n * @param {boolean} [options.once=false] - Whether this is a one-time event\n * @param {Function} [options.onOnce] - Callback to invoke when one-time event fires\n *\n * @example\n * invokeWheelAction(event, delta, (e, d) => {\n * console.log(`Wheel moved: ${d.x}, ${d.y}, ${d.z}`);\n * return true; // Prevent default\n * }, { stopImmediate: true });\n */\nexport const invokeWheelAction = (\n event: WheelEvent,\n data: WheelData,\n callback:\n | ((event: WheelEvent, data: WheelData) => boolean)\n | ((event: WheelEvent, data: WheelData) => void),\n options: {\n stopImmediate?: boolean;\n once?: boolean;\n onOnce?: () => void;\n },\n) => {\n if (options.stopImmediate) {\n event.stopImmediatePropagation();\n }\n\n const shouldPrevent = callback(event, data);\n if (shouldPrevent) {\n event.preventDefault();\n }\n\n if (options.once) {\n options.onOnce?.();\n }\n};\n"],"names":["invokeWheelAction","event","data","callback","options"],"mappings":"AAsBO,MAAMA,IAAoB,CAC/BC,GACAC,GACAC,GAGAC,MAKG;AACH,EAAIA,EAAQ,iBACVH,EAAM,yBAAA,GAGcE,EAASF,GAAOC,CAAI,KAExCD,EAAM,eAAA,GAGJG,EAAQ,QACVA,EAAQ,SAAA;AAEZ;"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useRef as r, useCallback as d, useEffect as L } from "react";
|
|
2
|
+
import { invokeWheelAction as A } from "./invoke-wheel-action.js";
|
|
3
|
+
const E = {
|
|
4
|
+
eventPassive: !0,
|
|
5
|
+
eventCapture: !1,
|
|
6
|
+
eventOnce: !1,
|
|
7
|
+
eventStopImmediatePropagation: !1,
|
|
8
|
+
container: { current: null },
|
|
9
|
+
raf: !1
|
|
10
|
+
}, h = (o, I = E) => {
|
|
11
|
+
const {
|
|
12
|
+
eventPassive: f,
|
|
13
|
+
eventCapture: m,
|
|
14
|
+
eventOnce: a,
|
|
15
|
+
eventStopImmediatePropagation: c,
|
|
16
|
+
container: p,
|
|
17
|
+
raf: v
|
|
18
|
+
} = { ...E, ...I }, g = r(null), u = r(null), t = r(null), s = r(null), i = r(null), l = d(() => {
|
|
19
|
+
u.current?.abort();
|
|
20
|
+
}, []), R = d(() => {
|
|
21
|
+
t.current = null;
|
|
22
|
+
const e = s.current, n = i.current;
|
|
23
|
+
!e || !n || (A(n, e, o, {
|
|
24
|
+
stopImmediate: c,
|
|
25
|
+
once: a,
|
|
26
|
+
onOnce: () => {
|
|
27
|
+
l();
|
|
28
|
+
}
|
|
29
|
+
}), s.current = null, i.current = null);
|
|
30
|
+
}, [
|
|
31
|
+
o,
|
|
32
|
+
c,
|
|
33
|
+
a,
|
|
34
|
+
l
|
|
35
|
+
]), O = d(
|
|
36
|
+
(e) => {
|
|
37
|
+
const n = {
|
|
38
|
+
deltaX: e.deltaX,
|
|
39
|
+
deltaY: e.deltaY,
|
|
40
|
+
deltaZ: e.deltaZ,
|
|
41
|
+
deltaMode: e.deltaMode
|
|
42
|
+
};
|
|
43
|
+
if (!v) {
|
|
44
|
+
A(e, n, o, {
|
|
45
|
+
stopImmediate: c,
|
|
46
|
+
once: a,
|
|
47
|
+
onOnce: () => {
|
|
48
|
+
l();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
s.current = n, i.current = e, t.current === null && (t.current = requestAnimationFrame(R));
|
|
54
|
+
},
|
|
55
|
+
[
|
|
56
|
+
v,
|
|
57
|
+
o,
|
|
58
|
+
c,
|
|
59
|
+
a,
|
|
60
|
+
l,
|
|
61
|
+
R
|
|
62
|
+
]
|
|
63
|
+
);
|
|
64
|
+
L(() => {
|
|
65
|
+
g.current = p?.current ?? globalThis, u.current = new AbortController();
|
|
66
|
+
const e = (n) => O(n);
|
|
67
|
+
return g.current.addEventListener("wheel", e, {
|
|
68
|
+
passive: f,
|
|
69
|
+
capture: m,
|
|
70
|
+
signal: u.current.signal
|
|
71
|
+
}), () => {
|
|
72
|
+
u.current?.abort(), t.current !== null && cancelAnimationFrame(t.current);
|
|
73
|
+
};
|
|
74
|
+
}, [p, f, m, O]);
|
|
75
|
+
};
|
|
76
|
+
export {
|
|
77
|
+
h as default
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=use-wheel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-wheel.js","sources":["../../src/use-wheel/use-wheel.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from \"react\";\nimport {\n UseWheelCallback,\n UseWheelOptions,\n WheelData,\n WheelOptions,\n} from \"./use-wheel.types\";\nimport { invokeWheelAction } from \"./invoke-wheel-action\";\n\nconst defaultOptions: WheelOptions = {\n eventPassive: true,\n eventCapture: false,\n eventOnce: false,\n eventStopImmediatePropagation: false,\n container: { current: null },\n raf: false,\n};\n\nconst useWheel = (\n wheelCallback: UseWheelCallback,\n options: UseWheelOptions = defaultOptions,\n) => {\n const {\n eventPassive,\n eventCapture,\n eventOnce,\n eventStopImmediatePropagation,\n container,\n raf,\n } = { ...defaultOptions, ...options };\n\n const targetReference = useRef<EventTarget | null>(null);\n const abortControllerReference = useRef<AbortController | null>(null);\n\n const frameReference = useRef<number | null>(null);\n const pendingDataReference = useRef<WheelData | null>(null);\n const pendingEventReference = useRef<WheelEvent | null>(null);\n\n const destroyListener = useCallback(() => {\n abortControllerReference.current?.abort();\n }, []);\n\n const flushFrame = useCallback(() => {\n frameReference.current = null;\n\n const data = pendingDataReference.current;\n const event = pendingEventReference.current;\n\n if (!data || !event) return;\n\n invokeWheelAction(event, data, wheelCallback, {\n stopImmediate: eventStopImmediatePropagation,\n once: eventOnce,\n onOnce: () => {\n destroyListener();\n },\n });\n\n pendingDataReference.current = null;\n pendingEventReference.current = null;\n }, [\n wheelCallback,\n eventStopImmediatePropagation,\n eventOnce,\n destroyListener,\n ]);\n\n const handleEventListener = useCallback(\n (event: WheelEvent) => {\n const delta: WheelData = {\n deltaX: event.deltaX,\n deltaY: event.deltaY,\n deltaZ: event.deltaZ,\n deltaMode: event.deltaMode,\n };\n\n if (!raf) {\n invokeWheelAction(event, delta, wheelCallback, {\n stopImmediate: eventStopImmediatePropagation,\n once: eventOnce,\n onOnce: () => {\n destroyListener();\n },\n });\n return;\n }\n\n pendingDataReference.current = delta;\n pendingEventReference.current = event;\n\n if (frameReference.current === null) {\n frameReference.current = requestAnimationFrame(flushFrame);\n }\n },\n [\n raf,\n wheelCallback,\n eventStopImmediatePropagation,\n eventOnce,\n destroyListener,\n flushFrame,\n ],\n );\n\n useEffect(() => {\n targetReference.current = container?.current ?? globalThis;\n abortControllerReference.current = new AbortController();\n\n const eventListener = (event: Event) =>\n handleEventListener(event as WheelEvent);\n\n targetReference.current.addEventListener(\"wheel\", eventListener, {\n passive: eventPassive,\n capture: eventCapture,\n signal: abortControllerReference.current.signal,\n });\n\n return () => {\n abortControllerReference.current?.abort();\n\n if (frameReference.current !== null) {\n cancelAnimationFrame(frameReference.current);\n }\n };\n }, [container, eventPassive, eventCapture, handleEventListener]);\n};\n\nexport default useWheel;\n"],"names":["defaultOptions","useWheel","wheelCallback","options","eventPassive","eventCapture","eventOnce","eventStopImmediatePropagation","container","raf","targetReference","useRef","abortControllerReference","frameReference","pendingDataReference","pendingEventReference","destroyListener","useCallback","flushFrame","data","event","invokeWheelAction","handleEventListener","delta","useEffect","eventListener"],"mappings":";;AASA,MAAMA,IAA+B;AAAA,EACnC,cAAc;AAAA,EACd,cAAc;AAAA,EACd,WAAW;AAAA,EACX,+BAA+B;AAAA,EAC/B,WAAW,EAAE,SAAS,KAAA;AAAA,EACtB,KAAK;AACP,GAEMC,IAAW,CACfC,GACAC,IAA2BH,MACxB;AACH,QAAM;AAAA,IACJ,cAAAI;AAAA,IACA,cAAAC;AAAA,IACA,WAAAC;AAAA,IACA,+BAA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A;AAAA,MACET;AAAA,MACAP;AAAA,MACAK;AAAA,MACAD;AAAA,MACAU;AAAA,MACAE;AAAA,IAAA;AAAA,EACF;AAGF,EAAAM,EAAU,MAAM;AACd,IAAAd,EAAgB,UAAUF,GAAW,WAAW,YAChDI,EAAyB,UAAU,IAAI,gBAAA;AAEvC,UAAMa,IAAgB,CAACL,MACrBE,EAAoBF,CAAmB;AAEzC,WAAAV,EAAgB,QAAQ,iBAAiB,SAASe,GAAe;AAAA,MAC/D,SAASrB;AAAA,MACT,SAASC;AAAA,MACT,QAAQO,EAAyB,QAAQ;AAAA,IAAA,CAC1C,GAEM,MAAM;AACX,MAAAA,EAAyB,SAAS,MAAA,GAE9BC,EAAe,YAAY,QAC7B,qBAAqBA,EAAe,OAAO;AAAA,IAE/C;AAAA,EACF,GAAG,CAACL,GAAWJ,GAAcC,GAAciB,CAAmB,CAAC;AACjE;"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@msobiecki/react-marauders-path",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.17.1"
|
|
7
7
|
},
|
|
8
|
-
"module": "dist/index.
|
|
9
|
-
"types": "dist/index.
|
|
8
|
+
"module": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist"
|
|
12
12
|
],
|