@msobiecki/react-marauders-path 1.24.0 → 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.d.ts +276 -0
- 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
|
@@ -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","useEff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AAAY,EAAkBD,GAAOG,GAAOrB,GAAe;AAAA,UAC7C,eAAeK;AAAA,UACf,MAAMD;AAAA,UACN,QAAQ,MAAM;AACZ,YAAAU,EAAA;AAAA,UACF;AAAA,QAAA,CACD;AACD;AAAA,MACF;AAEA,MAAAF,EAAqB,UAAUS,GAC/BR,EAAsB,UAAUK,GAE5BP,EAAe,YAAY,SAC7BA,EAAe,UAAU,sBAAsBK,CAAU;AAAA,IAE7D;AAAA,IACA;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
|
],
|