@msobiecki/react-marauders-path 1.22.0 → 1.24.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 (2) hide show
  1. package/README.md +51 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![License](https://img.shields.io/badge/license-%20%20GNU%20GPLv3%20-green.svg)](https://github.com/msobiecki/react-marauders-path/blob/master/LICENSE)
4
4
 
5
- A lightweight, type-safe React library for handling keyboard, wheel, swipe, and drag events. Perfect for games, interactive applications, and input-driven interfaces.
5
+ 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
 
7
7
  ![react-marauders-path](./docs/images/logotype.png)
8
8
 
@@ -12,6 +12,7 @@ A lightweight, type-safe React library for handling keyboard, wheel, swipe, and
12
12
  - 🎡 **Wheel Event Handling** - Track wheel, delta values with optional `requestAnimationFrame` batching for smoother updates
13
13
  - 🖐️ **Swipe Gesture Handling** - Detect directional swipes with configurable distance and velocity with pointer type filtering
14
14
  - 🖱️ **Drag Event Handling** - Track movement, delta values, duration, start/end positions with pointer type filtering and optional `requestAnimationFrame` batching for smoother updates
15
+ - 🤏 **Pinch Gesture Handling** - Track two-finger distance, delta, and scale with pointer type filtering and optional `requestAnimationFrame` batching for smoother updates
15
16
 
16
17
  ## Installation
17
18
 
@@ -122,11 +123,25 @@ function MyComponent() {
122
123
  }
123
124
  ```
124
125
 
126
+ ### Pinch Event Hook
127
+
128
+ ```typescript
129
+ import { usePinch } from '@msobiecki/react-marauders-path';
130
+
131
+ function MyComponent() {
132
+ usePinch((event, data) => {
133
+ console.log(`Pinch scale: ${data.scale}, delta: ${data.delta}`);
134
+ });
135
+
136
+ return <div>Pinch to zoom</div>;
137
+ }
138
+ ```
139
+
125
140
  ## API
126
141
 
127
142
  ### `useKey(keyEvent, callback, options?)`
128
143
 
129
- Main hook for keyboard event handling.
144
+ Hook for keyboard event handling with support for single keys, combinations, and sequences.
130
145
 
131
146
  **Parameters:**
132
147
 
@@ -256,6 +271,40 @@ interface DragData {
256
271
  }
257
272
  ```
258
273
 
274
+ ### `usePinch(callback, options?)`
275
+
276
+ Hook for handling two-pointer pinch gestures with distance and scale tracking.
277
+
278
+ **Parameters:**
279
+
280
+ - `callback: (event: PointerEvent, data: PinchData) => void | boolean` - Called when pinch event occurs
281
+ - `options?: UsePinchOptions` - Optional configuration
282
+
283
+ **Options:**
284
+
285
+ ```typescript
286
+ interface UsePinchOptions {
287
+ eventPointerTypes?: Array<"touch" | "mouse" | "pen">; // Default: ["touch"]
288
+ eventCapture?: boolean; // Default: false
289
+ eventOnce?: boolean; // Default: false
290
+ eventStopImmediatePropagation?: boolean; // Default: false
291
+ threshold?: number; // Default: 0 (px) - Minimum pinch distance change
292
+ container?: RefObject<HTMLElement>; // Default: window
293
+ raf?: boolean; // Default: false - Use requestAnimationFrame for batching
294
+ }
295
+ ```
296
+
297
+ **Pinch Data:**
298
+
299
+ ```typescript
300
+ interface PinchData {
301
+ distance: number; // Current distance between active pointers
302
+ delta: number; // Distance change since previous pinch update
303
+ totalDelta: number; // Distance change since pinch start
304
+ scale: number; // Current scale ratio (distance / startDistance)
305
+ }
306
+ ```
307
+
259
308
  ## Advanced Examples
260
309
 
261
310
  ### Using Options for Event Type and Propagation Control
@@ -370,7 +419,6 @@ npm run lint
370
419
  - 🚧 **`useTap`** – single tap / click
371
420
  - 🚧 **`useDoubleTap`** – quick double tap
372
421
  - 🚧 **`usePress`** – press and hold (longPress)
373
- - 🚧 **`usePinch`** – two-finger pinch / zoom
374
422
 
375
423
  ### Pointer / Mouse Hooks (Unified)
376
424
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msobiecki/react-marauders-path",
3
- "version": "1.22.0",
3
+ "version": "1.24.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=22.17.1"