@msobiecki/react-marauders-path 1.24.3 → 1.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +142 -7
  2. package/dist/index.d.ts +100 -0
  3. package/dist/index.js +29 -17
  4. package/dist/index.js.map +1 -1
  5. package/dist/use-double-tap/invoke-double-tap-action.js +7 -0
  6. package/dist/use-double-tap/invoke-double-tap-action.js.map +1 -0
  7. package/dist/use-double-tap/use-double-tap.js +77 -0
  8. package/dist/use-double-tap/use-double-tap.js.map +1 -0
  9. package/dist/use-double-tap/use-double-tap.types.js +9 -0
  10. package/dist/use-double-tap/use-double-tap.types.js.map +1 -0
  11. package/dist/use-drag/use-drag.js +68 -70
  12. package/dist/use-drag/use-drag.js.map +1 -1
  13. package/dist/use-key/use-key.js +96 -104
  14. package/dist/use-key/use-key.js.map +1 -1
  15. package/dist/use-pinch/use-pinch.js +77 -79
  16. package/dist/use-pinch/use-pinch.js.map +1 -1
  17. package/dist/use-press/invoke-press-action.js +7 -0
  18. package/dist/use-press/invoke-press-action.js.map +1 -0
  19. package/dist/use-press/use-press.js +98 -0
  20. package/dist/use-press/use-press.js.map +1 -0
  21. package/dist/use-press/use-press.types.js +9 -0
  22. package/dist/use-press/use-press.types.js.map +1 -0
  23. package/dist/use-swipe/use-swipe.js +61 -68
  24. package/dist/use-swipe/use-swipe.js.map +1 -1
  25. package/dist/use-tap/invoke-tap-action.js +7 -0
  26. package/dist/use-tap/invoke-tap-action.js.map +1 -0
  27. package/dist/use-tap/use-tap.js +94 -0
  28. package/dist/use-tap/use-tap.js.map +1 -0
  29. package/dist/use-tap/use-tap.types.js +9 -0
  30. package/dist/use-tap/use-tap.types.js.map +1 -0
  31. package/dist/use-wheel/use-wheel.js +33 -47
  32. package/dist/use-wheel/use-wheel.js.map +1 -1
  33. package/package.json +1 -1
@@ -1,8 +1,8 @@
1
- import { useRef as p, useCallback as i, useEffect as O } from "react";
1
+ import { useRef as f, useCallback as i, useEffect as Y } from "react";
2
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 = {
3
+ import { parseSwipeDirection as U } from "./parse-swipe-direction.js";
4
+ import { invokeSwipeAction as I } from "./invoke-swipe-action.js";
5
+ const M = {
6
6
  eventPointerTypes: ["touch", "mouse", "pen"],
7
7
  eventCapture: !1,
8
8
  eventOnce: !1,
@@ -10,125 +10,118 @@ const A = {
10
10
  threshold: 50,
11
11
  velocity: 0.3,
12
12
  container: { current: null }
13
- }, H = (d, m, U = {}) => {
13
+ }, B = (d, m, O = {}) => {
14
14
  const {
15
15
  eventPointerTypes: s,
16
16
  eventCapture: a,
17
17
  eventOnce: h,
18
18
  eventStopImmediatePropagation: v,
19
19
  threshold: w,
20
- velocity: g,
21
- container: y
22
- } = { ...A, ...U }, D = p([]), u = p(null), c = p(null), l = p({
20
+ velocity: y,
21
+ container: P
22
+ } = { ...M, ...O }, D = f([]), u = f(null), l = f(null), p = f({
23
23
  startX: 0,
24
24
  startY: 0,
25
25
  startTime: 0,
26
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;
27
+ }), b = i(
28
+ (t, e) => {
29
+ const o = Math.abs(t), c = Math.abs(e);
30
+ return o > c ? t > 0 ? n.Right : n.Left : e > 0 ? n.Down : n.Up;
33
31
  },
34
32
  []
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,
33
+ ), S = i((t) => {
34
+ const e = D.current;
35
+ return e.includes(n.Both) || e.includes(n.Horizontal) && (t === n.Left || t === n.Right) || e.includes(n.Vertical) && (t === n.Up || t === n.Down) ? !0 : e.includes(t);
36
+ }, []), L = i(
37
+ (t) => {
38
+ t.isPrimary && s.includes(t.pointerType) && (p.current = {
39
+ startX: t.clientX,
40
+ startY: t.clientY,
43
41
  startTime: Date.now(),
44
42
  active: !0
45
43
  });
46
44
  },
47
45
  [s]
48
46
  ), T = i(
49
- (e) => {
50
- const t = l.current;
51
- if (!t.active)
47
+ (t) => {
48
+ const e = p.current;
49
+ if (!e.active)
52
50
  return;
53
- t.active = !1;
54
- const o = Date.now() - t.startTime;
51
+ e.active = !1;
52
+ const o = Date.now() - e.startTime;
55
53
  if (o === 0)
56
54
  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)
55
+ const c = t.clientX - e.startX, r = t.clientY - e.startY, C = Math.hypot(c, r), E = C / o;
56
+ if (C < w || E < y)
59
57
  return;
60
- const E = L(r, f);
61
- if (!P(E))
58
+ const X = b(c, r);
59
+ if (!S(X))
62
60
  return;
63
- M(e, E, {
64
- deltaX: r,
65
- deltaY: f,
66
- velocity: Y,
61
+ I(t, X, {
62
+ deltaX: c,
63
+ deltaY: r,
64
+ velocity: E,
67
65
  duration: o
68
66
  }, m, {
69
67
  stopImmediate: v,
70
68
  once: h,
71
69
  onOnce: () => {
72
- b();
70
+ l.current?.abort();
73
71
  }
74
72
  });
75
73
  },
76
74
  [
77
75
  w,
78
- g,
79
- L,
80
- P,
76
+ y,
77
+ b,
78
+ S,
81
79
  m,
82
80
  h,
83
- v,
84
- b
81
+ v
85
82
  ]
86
- ), R = i(
87
- (e) => {
88
- e.isPrimary && s.includes(e.pointerType) && T(e);
83
+ ), g = i(
84
+ (t) => {
85
+ t.isPrimary && s.includes(t.pointerType) && T(t);
89
86
  },
90
87
  [T, s]
91
- ), C = i(() => {
92
- l.current.active = !1;
88
+ ), R = i(() => {
89
+ p.current.active = !1;
93
90
  }, []);
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(
91
+ Y(() => {
92
+ D.current = U(d);
93
+ }, [d]), Y(() => {
94
+ u.current = P?.current ?? globalThis, l.current = new AbortController();
95
+ const { signal: t } = l.current, e = (r) => r instanceof PointerEvent && L(r), o = (r) => r instanceof PointerEvent && g(r), c = () => R();
96
+ return u.current.addEventListener(
100
97
  "pointerdown",
101
98
  e,
102
99
  {
103
100
  capture: a,
104
- signal: c.current.signal
101
+ signal: t
105
102
  }
106
- );
107
- const t = (r) => R(r);
108
- u.current.addEventListener("pointerup", t, {
103
+ ), u.current.addEventListener("pointerup", o, {
109
104
  capture: a,
110
- signal: c.current.signal
111
- });
112
- const o = () => C();
113
- return u.current.addEventListener(
105
+ signal: t
106
+ }), u.current.addEventListener(
114
107
  "pointercancel",
115
- o,
108
+ c,
116
109
  {
117
110
  capture: a,
118
- signal: c.current.signal
111
+ signal: t
119
112
  }
120
113
  ), () => {
121
- c.current?.abort(), l.current.active = !1;
114
+ l.current?.abort(), p.current.active = !1;
122
115
  };
123
116
  }, [
124
- y,
117
+ P,
125
118
  a,
126
- S,
127
- R,
128
- C
119
+ L,
120
+ g,
121
+ R
129
122
  ]);
130
123
  };
131
124
  export {
132
- H as default
125
+ B as default
133
126
  };
134
127
  //# sourceMappingURL=use-swipe.js.map
@@ -1 +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,IAA2BF,EAA+B,IAAI,GAE9DG,IAAsBH,E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tB;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;"}
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 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 abortControllerReference.current?.abort();\n },\n });\n },\n [\n threshold,\n velocity,\n resolveDirection,\n matchesSchema,\n swipeCallback,\n eventOnce,\n eventStopImmediatePropagation,\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 const { signal } = abortControllerReference.current;\n\n const pointerDownListener = (event: Event) =>\n event instanceof PointerEvent && handlePointerDown(event);\n\n const pointerUpListener = (event: Event) =>\n event instanceof PointerEvent && handlePointerUp(event);\n\n const pointerCancelListener = () => handlePointerCancel();\n\n targetReference.current.addEventListener(\n \"pointerdown\",\n pointerDownListener,\n {\n capture: eventCapture,\n signal,\n },\n );\n\n targetReference.current.addEventListener(\"pointerup\", pointerUpListener, {\n capture: eventCapture,\n signal,\n });\n\n targetReference.current.addEventListener(\n \"pointercancel\",\n pointerCancelListener,\n {\n capture: eventCapture,\n signal,\n },\n );\n\n return () => {\n abortControllerReference.current?.abort();\n\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","resolveDirection","useCallback","deltaX","deltaY","absX","absY","SwipeDirections","matchesSchema","direction","allowed","handlePointerDown","event","endSwipe","state","duration","distance","computedVelocity","invokeSwipeAction","handlePointerUp","handlePointerCancel","useEffect","parseSwipeDirection","signal","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,IAA2BF,EAA+B,IAAI,GAE9DG,IAAsBH,EAAmB;AAAA,IAC7C,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,QAAQ;AAAA,EAAA,CACT,GAEKI,IAAmBC;AAAA,IACvB,CAACC,GAAgBC,MAAmC;AAClD,YAAMC,IAAO,KAAK,IAAIF,CAAM,GACtBG,IAAO,KAAK,IAAIF,CAAM;AAE5B,aAAIC,IAAOC,IACFH,IAAS,IAAII,EAAgB,QAAQA,EAAgB,OAGvDH,IAAS,IAAIG,EAAgB,OAAOA,EAAgB;AAAA,IAC7D;AAAA,IACA,CAAA;AAAA,EAAC,GAGGC,IAAgBN,EAAY,CAACO,MAAuC;AACxE,UAAMC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AElCC,EAAoB,QAAQ,SAAS;AAAA,IACvC;AAAA,EACF,GAAG;AAAA,IACDL;AAAA,IACAL;AAAA,IACAqB;AAAA,IACAQ;AAAA,IACAC;AAAA,EAAA,CACD;AACH;"}
@@ -0,0 +1,7 @@
1
+ const i = (e, t, n, o) => {
2
+ o.stopImmediate && e.stopImmediatePropagation(), n(e, t) && e.preventDefault(), o.once && o.onOnce?.();
3
+ };
4
+ export {
5
+ i as invokeTapAction
6
+ };
7
+ //# sourceMappingURL=invoke-tap-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke-tap-action.js","sources":["../../src/use-tap/invoke-tap-action.ts"],"sourcesContent":["import { TapData } from \"./use-tap.types\";\n\n/**\n * Invokes a tap action callback with optional event modifications.\n *\n * Handles tap event processing including preventing default behavior,\n * stopping immediate propagation, and managing one-time event handlers.\n *\n * @param {PointerEvent} event - The tap event\n * @param {TapData} data - The normalized tap 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 * invokeTapAction(event, data, (e, d) => {\n * console.log(`Tap at: ${d.x}, ${d.y}`);\n * return true; // Prevent default\n * }, { stopImmediate: true });\n */\nexport const invokeTapAction = (\n event: PointerEvent,\n data: TapData,\n callback:\n | ((event: PointerEvent, data: TapData) => boolean)\n | ((event: PointerEvent, data: TapData) => 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":["invokeTapAction","event","data","callback","options"],"mappings":"AAsBO,MAAMA,IAAkB,CAC7BC,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,94 @@
1
+ import { useRef as u, useCallback as l, useEffect as C } from "react";
2
+ import { invokeTapAction as D } from "./invoke-tap-action.js";
3
+ const L = {
4
+ eventPointerTypes: ["touch", "mouse", "pen"],
5
+ eventCapture: !1,
6
+ eventOnce: !1,
7
+ eventStopImmediatePropagation: !1,
8
+ threshold: 8,
9
+ maxDuration: 250,
10
+ container: { current: null }
11
+ }, x = (p, X = {}) => {
12
+ const {
13
+ eventPointerTypes: f,
14
+ eventCapture: r,
15
+ eventOnce: d,
16
+ eventStopImmediatePropagation: m,
17
+ threshold: P,
18
+ maxDuration: h,
19
+ container: v
20
+ } = { ...L, ...X }, o = u(null), a = u(null), c = u({
21
+ startX: 0,
22
+ startY: 0,
23
+ startTime: 0,
24
+ active: !1
25
+ }), T = l(
26
+ (t) => {
27
+ t.isPrimary && f.includes(t.pointerType) && (c.current = {
28
+ startX: t.clientX,
29
+ startY: t.clientY,
30
+ startTime: Date.now(),
31
+ active: !0
32
+ });
33
+ },
34
+ [f]
35
+ ), y = l(
36
+ (t) => {
37
+ const n = c.current;
38
+ if (!n.active || !t.isPrimary)
39
+ return;
40
+ n.active = !1;
41
+ const i = t.clientX - n.startX, s = t.clientY - n.startY, e = Math.hypot(i, s), Y = Date.now() - n.startTime;
42
+ if (e > P || Y > h)
43
+ return;
44
+ const w = {
45
+ x: t.clientX,
46
+ y: t.clientY
47
+ };
48
+ D(t, w, p, {
49
+ stopImmediate: m,
50
+ once: d,
51
+ onOnce: () => {
52
+ a.current?.abort();
53
+ }
54
+ });
55
+ },
56
+ [
57
+ p,
58
+ P,
59
+ h,
60
+ d,
61
+ m
62
+ ]
63
+ ), E = l(() => {
64
+ c.current.active = !1;
65
+ }, []);
66
+ C(() => {
67
+ o.current = v?.current ?? globalThis, a.current = new AbortController();
68
+ const { signal: t } = a.current, n = (e) => e instanceof PointerEvent && T(e), i = (e) => e instanceof PointerEvent && y(e), s = (e) => e instanceof PointerEvent && E();
69
+ return o.current.addEventListener(
70
+ "pointerdown",
71
+ n,
72
+ { capture: r, signal: t }
73
+ ), o.current.addEventListener("pointerup", i, {
74
+ capture: r,
75
+ signal: t
76
+ }), o.current.addEventListener(
77
+ "pointercancel",
78
+ s,
79
+ { capture: r, signal: t }
80
+ ), () => {
81
+ a.current?.abort(), c.current.active = !1;
82
+ };
83
+ }, [
84
+ v,
85
+ r,
86
+ T,
87
+ y,
88
+ E
89
+ ]);
90
+ };
91
+ export {
92
+ x as default
93
+ };
94
+ //# sourceMappingURL=use-tap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-tap.js","sources":["../../src/use-tap/use-tap.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from \"react\";\nimport {\n TapOptions,\n UseTapCallback,\n UseTapOptions,\n TapEventPointerType,\n TapState,\n TapData,\n} from \"./use-tap.types\";\nimport { invokeTapAction } from \"./invoke-tap-action\";\n\nconst defaultOptions: TapOptions = {\n eventPointerTypes: [\"touch\", \"mouse\", \"pen\"],\n eventCapture: false,\n eventOnce: false,\n eventStopImmediatePropagation: false,\n threshold: 8,\n maxDuration: 250,\n container: { current: null },\n};\n\nconst useTap = (tapCallback: UseTapCallback, options: UseTapOptions = {}) => {\n const {\n eventPointerTypes,\n eventCapture,\n eventOnce,\n eventStopImmediatePropagation,\n threshold,\n maxDuration,\n container,\n } = { ...defaultOptions, ...options };\n\n const targetReference = useRef<EventTarget | null>(null);\n const abortControllerReference = useRef<AbortController | null>(null);\n\n const tapStateReference = useRef<TapState>({\n startX: 0,\n startY: 0,\n startTime: 0,\n active: false,\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 TapEventPointerType)\n ) {\n return;\n }\n\n tapStateReference.current = {\n startX: event.clientX,\n startY: event.clientY,\n startTime: Date.now(),\n active: true,\n };\n },\n [eventPointerTypes],\n );\n\n const handlePointerUp = useCallback(\n (event: PointerEvent) => {\n const state = tapStateReference.current;\n if (!state.active) {\n return;\n }\n if (!event.isPrimary) {\n return;\n }\n\n state.active = false;\n\n const deltaX = event.clientX - state.startX;\n const deltaY = event.clientY - state.startY;\n\n const distance = Math.hypot(deltaX, deltaY);\n const duration = Date.now() - state.startTime;\n\n if (distance > threshold) {\n return;\n }\n if (duration > maxDuration) {\n return;\n }\n\n const data: TapData = {\n x: event.clientX,\n y: event.clientY,\n };\n\n invokeTapAction(event, data, tapCallback, {\n stopImmediate: eventStopImmediatePropagation,\n once: eventOnce,\n onOnce: () => {\n abortControllerReference.current?.abort();\n },\n });\n },\n [\n tapCallback,\n threshold,\n maxDuration,\n eventOnce,\n eventStopImmediatePropagation,\n ],\n );\n\n const handlePointerCancel = useCallback(() => {\n tapStateReference.current.active = false;\n }, []);\n\n useEffect(() => {\n targetReference.current = container?.current ?? globalThis;\n abortControllerReference.current = new AbortController();\n const { signal } = abortControllerReference.current;\n\n const pointerDownListener = (event: Event) =>\n event instanceof PointerEvent && handlePointerDown(event);\n\n const pointerUpListener = (event: Event) =>\n event instanceof PointerEvent && handlePointerUp(event);\n\n const pointerCancelListener = (event: Event) =>\n event instanceof PointerEvent && handlePointerCancel();\n\n targetReference.current.addEventListener(\n \"pointerdown\",\n pointerDownListener,\n { capture: eventCapture, signal },\n );\n\n targetReference.current.addEventListener(\"pointerup\", pointerUpListener, {\n capture: eventCapture,\n signal,\n });\n\n targetReference.current.addEventListener(\n \"pointercancel\",\n pointerCancelListener,\n { capture: eventCapture, signal },\n );\n\n return () => {\n abortControllerReference.current?.abort();\n\n tapStateReference.current.active = false;\n };\n }, [\n container,\n eventCapture,\n handlePointerDown,\n handlePointerUp,\n handlePointerCancel,\n ]);\n};\n\nexport default useTap;\n"],"names":["defaultOptions","useTap","tapCallback","options","eventPointerTypes","eventCapture","eventOnce","eventStopImmediatePropagation","threshold","maxDuration","container","targetReference","useRef","abortControllerReference","tapStateReference","handlePointerDown","useCallback","event","handlePointerUp","state","deltaX","deltaY","distance","duration","data","invokeTapAction","handlePointerCancel","useEffect","signal","pointerDownListener","pointerUpListener","pointerCancelListener"],"mappings":";;AAWA,MAAMA,IAA6B;AAAA,EACjC,mBAAmB,CAAC,SAAS,SAAS,KAAK;AAAA,EAC3C,cAAc;AAAA,EACd,WAAW;AAAA,EACX,+BAA+B;AAAA,EAC/B,WAAW;AAAA,EACX,aAAa;AAAA,EACb,WAAW,EAAE,SAAS,KAAA;AACxB,GAEMC,IAAS,CAACC,GAA6BC,IAAyB,OAAO;AAC3E,QAAM;AAAA,IACJ,mBAAAC;AAAA,IACA,cAAAC;AAAA,IACA,WAAAC;AAAA,IACA,+BAAAC;AAAA,IACA,WAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,EAAA,IACE,EAAE,GAAGV,GAAgB,GAAGG,EAAA,GAEtBQ,IAAkBC,EAA2B,IAAI,GACjDC,IAA2BD,EAA+B,IAAI,GAE9DE,IAAoBF,EAAiB;AAAA,IACzC,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,QAAQ;AAAA,EAAA,CACT,GAEKG,IAAoBC;AAAA,IACxB,CAACC,MAAwB;AACvB,MAAKA,EAAM,aAKRb,EAAkB,SAASa,EAAM,WAAkC,MAKtEH,EAAkB,UAAU;AAAA,QAC1B,QAAQG,EAAM;AAAA,QACd,QAAQA,EAAM;AAAA,QACd,WAAW,KAAK,IAAA;AAAA,QAChB,QAAQ;AAAA,MAAA;AAAA,IAEZ;AAAA,IACA,CAACb,CAAiB;AAAA,EAAA,GAGdc,IAAkBF;AAAA,IACtB,CAACC,MAAwB;AACvB,YAAME,IAAQL,EAAkB;AAIhC,UAHI,CAACK,EAAM,UAGP,CAACF,EAAM;AACT;AAGF,MAAAE,EAAM,SAAS;AAEf,YAAMC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Ac,QAAAuB,EAAA;AAAA,IAAO,GAG3B,MAAM;AACX,MAAAf,EAAyB,SAAS,MAAA,GAElCC,EAAkB,QAAQ,SAAS;AAAA,IACrC;AAAA,EACF,GAAG;AAAA,IACDJ;AAAA,IACAL;AAAA,IACAU;AAAA,IACAG;AAAA,IACAQ;AAAA,EAAA,CACD;AACH;"}
@@ -0,0 +1,9 @@
1
+ const e = {
2
+ Touch: "touch",
3
+ Mouse: "mouse",
4
+ Pen: "pen"
5
+ };
6
+ export {
7
+ e as TapEventPointerTypes
8
+ };
9
+ //# sourceMappingURL=use-tap.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-tap.types.js","sources":["../../src/use-tap/use-tap.types.ts"],"sourcesContent":["export interface TapState {\n startX: number;\n startY: number;\n startTime: number;\n active: boolean;\n}\n\nexport const TapEventPointerTypes = {\n Touch: \"touch\",\n Mouse: \"mouse\",\n Pen: \"pen\",\n} as const;\n\nexport type TapEventPointerType =\n (typeof TapEventPointerTypes)[keyof typeof TapEventPointerTypes];\n\nexport interface TapData {\n x: number;\n y: number;\n}\n\nexport interface TapOptions {\n eventPointerTypes: TapEventPointerType[];\n eventCapture: boolean;\n eventOnce: boolean;\n eventStopImmediatePropagation: boolean;\n threshold: number;\n maxDuration: number;\n container: { current: EventTarget | null };\n}\n\nexport type UseTapCallback =\n | ((event: PointerEvent, data: TapData) => boolean)\n | ((event: PointerEvent, data: TapData) => void);\n\nexport type UseTapOptions = Partial<TapOptions>;\n"],"names":["TapEventPointerTypes"],"mappings":"AAOO,MAAMA,IAAuB;AAAA,EAClC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,KAAK;AACP;"}
@@ -1,38 +1,31 @@
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 = {
1
+ import { useRef as c, useCallback as R, useEffect as I } from "react";
2
+ import { invokeWheelAction as O } from "./invoke-wheel-action.js";
3
+ const b = {
4
4
  eventPassive: !0,
5
5
  eventCapture: !1,
6
6
  eventOnce: !1,
7
7
  eventStopImmediatePropagation: !1,
8
8
  container: { current: null },
9
9
  raf: !1
10
- }, h = (o, I = E) => {
10
+ }, F = (o, A = b) => {
11
11
  const {
12
- eventPassive: f,
13
- eventCapture: m,
12
+ eventPassive: i,
13
+ eventCapture: f,
14
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,
15
+ eventStopImmediatePropagation: u,
16
+ container: d,
17
+ raf: m
18
+ } = { ...b, ...A }, p = c(null), t = c(null), r = c(null), l = c(null), s = c(null), v = R(() => {
19
+ r.current = null;
20
+ const e = l.current, n = s.current;
21
+ !e || !n || (O(n, e, o, {
22
+ stopImmediate: u,
25
23
  once: a,
26
24
  onOnce: () => {
27
- l();
25
+ t.current?.abort();
28
26
  }
29
- }), s.current = null, i.current = null);
30
- }, [
31
- o,
32
- c,
33
- a,
34
- l
35
- ]), O = d(
27
+ }), l.current = null, s.current = null);
28
+ }, [o, u, a]), g = R(
36
29
  (e) => {
37
30
  const n = {
38
31
  deltaX: e.deltaX,
@@ -40,40 +33,33 @@ const E = {
40
33
  deltaZ: e.deltaZ,
41
34
  deltaMode: e.deltaMode
42
35
  };
43
- if (!v) {
44
- A(e, n, o, {
45
- stopImmediate: c,
36
+ if (!m) {
37
+ O(e, n, o, {
38
+ stopImmediate: u,
46
39
  once: a,
47
40
  onOnce: () => {
48
- l();
41
+ t.current?.abort();
49
42
  }
50
43
  });
51
44
  return;
52
45
  }
53
- s.current = n, i.current = e, t.current === null && (t.current = requestAnimationFrame(R));
46
+ l.current = n, s.current = e, r.current === null && (r.current = requestAnimationFrame(v));
54
47
  },
55
- [
56
- v,
57
- o,
58
- c,
59
- a,
60
- l,
61
- R
62
- ]
48
+ [m, o, u, a, v]
63
49
  );
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
50
+ I(() => {
51
+ p.current = d?.current ?? globalThis, t.current = new AbortController();
52
+ const { signal: e } = t.current, n = (E) => g(E);
53
+ return p.current.addEventListener("wheel", n, {
54
+ passive: i,
55
+ capture: f,
56
+ signal: e
71
57
  }), () => {
72
- u.current?.abort(), t.current !== null && cancelAnimationFrame(t.current);
58
+ t.current?.abort(), r.current !== null && cancelAnimationFrame(r.current);
73
59
  };
74
- }, [p, f, m, O]);
60
+ }, [d, i, f, g]);
75
61
  };
76
62
  export {
77
- h as default
63
+ F as default
78
64
  };
79
65
  //# sourceMappingURL=use-wheel.js.map
@@ -1 +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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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;"}
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 flushFrame = useCallback(() => {\n frameReference.current = null;\n\n const data = pendingDataReference.current;\n const event = pendingEventReference.current;\n\n if (!data || !event) {\n return;\n }\n\n invokeWheelAction(event, data, wheelCallback, {\n stopImmediate: eventStopImmediatePropagation,\n once: eventOnce,\n onOnce: () => {\n abortControllerReference.current?.abort();\n },\n });\n\n pendingDataReference.current = null;\n pendingEventReference.current = null;\n }, [wheelCallback, eventStopImmediatePropagation, eventOnce]);\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 abortControllerReference.current?.abort();\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 [raf, wheelCallback, eventStopImmediatePropagation, eventOnce, flushFrame],\n );\n\n useEffect(() => {\n targetReference.current = container?.current ?? globalThis;\n abortControllerReference.current = new AbortController();\n const { signal } = abortControllerReference.current;\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,\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","flushFrame","useCallback","data","event","invokeWheelAction","handleEventListener","delta","useEffect","signal","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,+BAAAC;AAAA,IACA,WAAAC;AAAA,IACA,KAAAC;AAAA,EAAA,IACE,EAAE,GAAGT,GAAgB,GAAGG,EAAA,GAEtBO,IAAkBC,EAA2B,IAAI,GACjDC,IAA2BD,EAA+B,IAAI,GAE9DE,IAAiBF,EAAsB,IAAI,GAC3CG,IAAuBH,EAAyB,IAAI,GACpDI,IAAwBJ,EAA0B,IAAI,GAEtDK,IAAaC,EAAY,MAAM;AACnC,IAAAJ,EAAe,UAAU;AAEzB,UAAMK,IAAOJ,EAAqB,SAC5BK,IAAQJ,EAAsB;AAEpC,IAAI,CAACG,KAAQ,CAACC,MAIdC,EAAkBD,GAAOD,GAAMhB,GAAe;AAAA,MAC5C,eAAeK;AAAA,MACf,MAAMD;AAAA,MACN,QAAQ,MAAM;AACZ,QAAAM,EAAyB,SAAS,MAAA;AAAA,MACpC;AAAA,IAAA,CACD,GAEDE,EAAqB,UAAU,MAC/BC,EAAsB,UAAU;AAAA,EAClC,GAAG,CAACb,GAAeK,GAA+BD,CAAS,CAAC,GAEtDe,IAAsBJ;AAAA,IAC1B,CAACE,MAAsB;AACrB,YAAMG,IAAmB;AAAA,QACvB,QAAQH,EAAM;AAAA,QACd,QAAQA,EAAM;AAAA,QACd,QAAQA,EAAM;AAAA,QACd,WAAWA,EAAM;AAAA,MAAA;AAGnB,UAAI,CAACV,GAAK;AACR,QAAAW,EAAkBD,GAAOG,GAAOpB,GAAe;AAAA,UAC7C,eAAeK;AAAA,UACf,MAAMD;AAAA,UACN,QAAQ,MAAM;AACZ,YAAAM,EAAyB,SAAS,MAAA;AAAA,UACpC;AAAA,QAAA,CACD;AACD;AAAA,MACF;AAEA,MAAAE,EAAqB,UAAUQ,GAC/BP,EAAsB,UAAUI,GAE5BN,EAAe,YAAY,SAC7BA,EAAe,UAAU,sBAAsBG,CAAU;AAAA,IAE7D;AAAA,IACA,CAACP,GAAKP,GAAeK,GAA+BD,GAAWU,CAAU;AAAA,EAAA;AAG3E,EAAAO,EAAU,MAAM;AACd,IAAAb,EAAgB,UAAUF,GAAW,WAAW,YAChDI,EAAyB,UAAU,IAAI,gBAAA;AACvC,UAAM,EAAE,QAAAY,MAAWZ,EAAyB,SAEtCa,IAAgB,CAACN,MACrBE,EAAoBF,CAAmB;AAEzC,WAAAT,EAAgB,QAAQ,iBAAiB,SAASe,GAAe;AAAA,MAC/D,SAASrB;AAAA,MACT,SAASC;AAAA,MACT,QAAAmB;AAAA,IAAA,CACD,GAEM,MAAM;AACX,MAAAZ,EAAyB,SAAS,MAAA,GAE9BC,EAAe,YAAY,QAC7B,qBAAqBA,EAAe,OAAO;AAAA,IAE/C;AAAA,EACF,GAAG,CAACL,GAAWJ,GAAcC,GAAcgB,CAAmB,CAAC;AACjE;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msobiecki/react-marauders-path",
3
- "version": "1.24.3",
3
+ "version": "1.25.0",
4
4
  "private": false,
5
5
  "description": "A lightweight, type-safe React library for handling keyboard, wheel, swipe, drag, and pinch events. Perfect for games, interactive applications, and input-driven interfaces.",
6
6
  "keywords": [