gesture-kit-core 1.0.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.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # gesture-kit-core
2
+
3
+ Core types, utilities, and gesture composition for the Gesture Kit ecosystem.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install gesture-kit-core
9
+ ```
10
+
11
+ ### Peer Dependencies
12
+
13
+ ```bash
14
+ npm install react-native-gesture-handler
15
+ ```
16
+
17
+ ## What's Included
18
+
19
+ - **Types**: `GestureState`, `BaseGestureEvent`, `TapEvent`, `PanEvent`, `PinchEvent`, `RotationEvent`, etc.
20
+ - **GestureComposer**: A declarative component for composing multiple gestures.
21
+ - **createGestureComponent**: Factory function for creating custom gesture components.
22
+ - **Utilities**: `composeGestures`, `detectSwipeDirection`, `matchesDirection`, `magnitude`.
23
+
24
+ ## Usage
25
+
26
+ ```tsx
27
+ import { GestureComposer, composeGestures } from 'gesture-kit-core';
28
+ import type { TapEvent, PanEvent } from 'gesture-kit-core';
29
+ ```
30
+
31
+ ## License
32
+
33
+ MIT
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare const GestureComposer: React.FC<{
3
+ children: React.ReactNode;
4
+ }>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GestureComposer = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const GestureComposer = ({ children }) => {
9
+ return react_1.default.createElement(react_1.default.Fragment, null, children);
10
+ };
11
+ exports.GestureComposer = GestureComposer;
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare function createGestureComponent<T>(name: string): React.FC<T & {
3
+ children?: React.ReactNode;
4
+ }>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createGestureComponent = createGestureComponent;
7
+ const react_1 = __importDefault(require("react"));
8
+ function createGestureComponent(name) {
9
+ const Component = ({ children }) => {
10
+ return react_1.default.createElement(react_1.default.Fragment, null, children);
11
+ };
12
+ Component.displayName = name;
13
+ return Component;
14
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * gesture-kit-core
3
+ *
4
+ * Core types, utilities, and composition for gesture-kit.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ export * from './types';
9
+ export { GestureComposer, GestureComposer as Gesture } from './core/GestureComposer';
10
+ export { createGestureComponent } from './core/createGestureComponent';
11
+ export { detectSwipeDirection, matchesDirection, magnitude } from './utils/direction';
12
+ export { composeGestures } from './utils/compose';
13
+ export type { AnyGesture } from './utils/compose';
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * gesture-kit-core
4
+ *
5
+ * Core types, utilities, and composition for gesture-kit.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.composeGestures = exports.magnitude = exports.matchesDirection = exports.detectSwipeDirection = exports.createGestureComponent = exports.Gesture = exports.GestureComposer = void 0;
25
+ // ─── Types ──────────────────────────────────────────────────────────
26
+ __exportStar(require("./types"), exports);
27
+ // ─── Core ───────────────────────────────────────────────────────────
28
+ var GestureComposer_1 = require("./core/GestureComposer");
29
+ Object.defineProperty(exports, "GestureComposer", { enumerable: true, get: function () { return GestureComposer_1.GestureComposer; } });
30
+ Object.defineProperty(exports, "Gesture", { enumerable: true, get: function () { return GestureComposer_1.GestureComposer; } });
31
+ var createGestureComponent_1 = require("./core/createGestureComponent");
32
+ Object.defineProperty(exports, "createGestureComponent", { enumerable: true, get: function () { return createGestureComponent_1.createGestureComponent; } });
33
+ // ─── Utilities ──────────────────────────────────────────────────────
34
+ var direction_1 = require("./utils/direction");
35
+ Object.defineProperty(exports, "detectSwipeDirection", { enumerable: true, get: function () { return direction_1.detectSwipeDirection; } });
36
+ Object.defineProperty(exports, "matchesDirection", { enumerable: true, get: function () { return direction_1.matchesDirection; } });
37
+ Object.defineProperty(exports, "magnitude", { enumerable: true, get: function () { return direction_1.magnitude; } });
38
+ var compose_1 = require("./utils/compose");
39
+ Object.defineProperty(exports, "composeGestures", { enumerable: true, get: function () { return compose_1.composeGestures; } });
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Core gesture types and interfaces for react-native-gesture-kit.
3
+ *
4
+ * @module types/gestures
5
+ */
6
+ /** All possible states of a gesture recognizer */
7
+ export declare enum GestureState {
8
+ UNDETERMINED = 0,
9
+ BEGAN = 1,
10
+ ACTIVE = 2,
11
+ END = 3,
12
+ CANCELLED = 4,
13
+ FAILED = 5
14
+ }
15
+ /** Swipe direction */
16
+ export type SwipeDirection = 'left' | 'right' | 'up' | 'down';
17
+ /** Fling direction using RNGH's direction constants */
18
+ export type FlingDirection = 'left' | 'right' | 'up' | 'down';
19
+ /** Gesture composition priority strategy */
20
+ export type GesturePriority = 'simultaneous' | 'exclusive' | 'race';
21
+ /** 2D point */
22
+ export interface Point {
23
+ x: number;
24
+ y: number;
25
+ }
26
+ /** Velocity vector */
27
+ export interface Velocity {
28
+ x: number;
29
+ y: number;
30
+ }
31
+ /** Base event shared by all gestures */
32
+ export interface BaseGestureEvent {
33
+ /** Absolute X position on screen */
34
+ absoluteX: number;
35
+ /** Absolute Y position on screen */
36
+ absoluteY: number;
37
+ /** X position relative to the handler view */
38
+ x: number;
39
+ /** Y position relative to the handler view */
40
+ y: number;
41
+ }
42
+ /** Tap event payload */
43
+ export interface TapEvent extends BaseGestureEvent {
44
+ /** Number of taps detected */
45
+ numberOfTaps: number;
46
+ }
47
+ /** Long press event payload */
48
+ export interface LongPressEvent extends BaseGestureEvent {
49
+ /** Duration of the long press in ms */
50
+ duration: number;
51
+ }
52
+ /** Pan event payload */
53
+ export interface PanEvent extends BaseGestureEvent {
54
+ /** Translation from the starting point */
55
+ translationX: number;
56
+ translationY: number;
57
+ /** Current velocity */
58
+ velocityX: number;
59
+ velocityY: number;
60
+ }
61
+ /** Swipe event payload */
62
+ export interface SwipeEvent extends BaseGestureEvent {
63
+ /** Detected swipe direction */
64
+ direction: SwipeDirection;
65
+ /** Swipe velocity */
66
+ velocity: number;
67
+ /** Translation distance */
68
+ distance: number;
69
+ }
70
+ /** Pinch event payload */
71
+ export interface PinchEvent extends BaseGestureEvent {
72
+ /** Current scale factor */
73
+ scale: number;
74
+ /** Velocity of the pinch */
75
+ velocity: number;
76
+ /** Focal point of the pinch */
77
+ focalX: number;
78
+ focalY: number;
79
+ }
80
+ /** Rotation event payload */
81
+ export interface RotationEvent extends BaseGestureEvent {
82
+ /** Current rotation in radians */
83
+ rotation: number;
84
+ /** Angular velocity */
85
+ velocity: number;
86
+ /** Anchor point */
87
+ anchorX: number;
88
+ anchorY: number;
89
+ }
90
+ /** Fling event payload */
91
+ export interface FlingEvent extends BaseGestureEvent {
92
+ /** Direction of the fling */
93
+ direction: FlingDirection;
94
+ }
95
+ /** Common props shared by all gesture components */
96
+ export interface BaseGestureProps {
97
+ /** Whether the gesture is enabled */
98
+ enabled?: boolean;
99
+ /** Children to wrap */
100
+ children: React.ReactNode;
101
+ }
102
+ /** TapGesture component props */
103
+ export interface TapGestureProps extends BaseGestureProps {
104
+ /** Callback when tap is detected */
105
+ onTap: (event: TapEvent) => void;
106
+ /** Number of required taps (default: 1) */
107
+ numberOfTaps?: number;
108
+ /** Maximum duration of a tap in ms */
109
+ maxDuration?: number;
110
+ /** Maximum distance finger can travel */
111
+ maxDistance?: number;
112
+ }
113
+ /** DoubleTapGesture component props */
114
+ export interface DoubleTapGestureProps extends BaseGestureProps {
115
+ /** Callback when double tap is detected */
116
+ onDoubleTap: (event: TapEvent) => void;
117
+ /** Maximum delay between taps in ms */
118
+ maxDelay?: number;
119
+ /** Maximum distance between taps */
120
+ maxDistance?: number;
121
+ }
122
+ /** LongPressGesture component props */
123
+ export interface LongPressGestureProps extends BaseGestureProps {
124
+ /** Callback when long press is detected */
125
+ onLongPress: (event: LongPressEvent) => void;
126
+ /** Callback when press begins */
127
+ onPressIn?: (event: LongPressEvent) => void;
128
+ /** Callback when press ends */
129
+ onPressOut?: (event: LongPressEvent) => void;
130
+ /** Minimum duration to trigger (default: 500ms) */
131
+ minDuration?: number;
132
+ /** Maximum distance finger can travel */
133
+ maxDistance?: number;
134
+ }
135
+ /** SwipeGesture component props */
136
+ export interface SwipeGestureProps extends BaseGestureProps {
137
+ /** Callback when swipe is detected */
138
+ onSwipe: (event: SwipeEvent) => void;
139
+ /** Required swipe direction (any if omitted) */
140
+ direction?: SwipeDirection;
141
+ /** Minimum distance to qualify as swipe (default: 50) */
142
+ threshold?: number;
143
+ /** Minimum velocity to qualify (default: 300) */
144
+ velocityThreshold?: number;
145
+ }
146
+ /** PanGesture component props */
147
+ export interface PanGestureProps extends BaseGestureProps {
148
+ /** Callback when pan starts */
149
+ onPanStart?: (event: PanEvent) => void;
150
+ /** Callback during panning */
151
+ onPanMove?: (event: PanEvent) => void;
152
+ /** Callback when pan ends */
153
+ onPanEnd?: (event: PanEvent) => void;
154
+ /** Minimum distance to activate (default: 10) */
155
+ minDistance?: number;
156
+ /** Minimum number of pointers */
157
+ minPointers?: number;
158
+ /** Maximum number of pointers */
159
+ maxPointers?: number;
160
+ }
161
+ /** PinchGesture component props */
162
+ export interface PinchGestureProps extends BaseGestureProps {
163
+ /** Callback when pinch starts */
164
+ onPinchStart?: (event: PinchEvent) => void;
165
+ /** Callback during pinching */
166
+ onPinch?: (event: PinchEvent) => void;
167
+ /** Callback when pinch ends */
168
+ onPinchEnd?: (event: PinchEvent) => void;
169
+ }
170
+ /** RotationGesture component props */
171
+ export interface RotationGestureProps extends BaseGestureProps {
172
+ /** Callback when rotation starts */
173
+ onRotationStart?: (event: RotationEvent) => void;
174
+ /** Callback during rotation */
175
+ onRotation?: (event: RotationEvent) => void;
176
+ /** Callback when rotation ends */
177
+ onRotationEnd?: (event: RotationEvent) => void;
178
+ }
179
+ /** FlingGesture component props */
180
+ export interface FlingGestureProps extends BaseGestureProps {
181
+ /** Callback when fling is detected */
182
+ onFling: (event: FlingEvent) => void;
183
+ /** Required fling direction */
184
+ direction?: FlingDirection;
185
+ /** Number of required touching pointers (default: 1) */
186
+ numberOfPointers?: number;
187
+ }
188
+ /** Props for the <Gesture> composer component */
189
+ export interface GestureComposerProps extends BaseGestureProps {
190
+ /** Enable tap gesture */
191
+ tap?: boolean;
192
+ /** Enable double tap gesture */
193
+ doubleTap?: boolean;
194
+ /** Enable long press gesture */
195
+ longPress?: boolean;
196
+ /** Enable swipe gesture — pass true for any direction, or a specific direction */
197
+ swipe?: boolean | SwipeDirection;
198
+ /** Enable pan gesture */
199
+ pan?: boolean;
200
+ /** Enable pinch gesture */
201
+ pinch?: boolean;
202
+ /** Enable rotation gesture */
203
+ rotate?: boolean;
204
+ /** Enable fling gesture — pass true for any direction, or a specific direction */
205
+ fling?: boolean | FlingDirection;
206
+ /** How to compose multiple gestures */
207
+ priority?: GesturePriority;
208
+ onTap?: (event: TapEvent) => void;
209
+ onDoubleTap?: (event: TapEvent) => void;
210
+ onLongPress?: (event: LongPressEvent) => void;
211
+ onSwipe?: (event: SwipeEvent) => void;
212
+ onPanStart?: (event: PanEvent) => void;
213
+ onPanMove?: (event: PanEvent) => void;
214
+ onPanEnd?: (event: PanEvent) => void;
215
+ onPinchStart?: (event: PinchEvent) => void;
216
+ onPinch?: (event: PinchEvent) => void;
217
+ onPinchEnd?: (event: PinchEvent) => void;
218
+ onRotationStart?: (event: RotationEvent) => void;
219
+ onRotation?: (event: RotationEvent) => void;
220
+ onRotationEnd?: (event: RotationEvent) => void;
221
+ onFling?: (event: FlingEvent) => void;
222
+ }
223
+ /** Options for useTap hook */
224
+ export interface UseTapOptions {
225
+ onTap: (event: TapEvent) => void;
226
+ numberOfTaps?: number;
227
+ maxDuration?: number;
228
+ maxDistance?: number;
229
+ enabled?: boolean;
230
+ }
231
+ /** Options for useDoubleTap hook */
232
+ export interface UseDoubleTapOptions {
233
+ onDoubleTap: (event: TapEvent) => void;
234
+ maxDelay?: number;
235
+ maxDistance?: number;
236
+ enabled?: boolean;
237
+ }
238
+ /** Options for useLongPress hook */
239
+ export interface UseLongPressOptions {
240
+ onLongPress: (event: LongPressEvent) => void;
241
+ onPressIn?: (event: LongPressEvent) => void;
242
+ onPressOut?: (event: LongPressEvent) => void;
243
+ minDuration?: number;
244
+ maxDistance?: number;
245
+ enabled?: boolean;
246
+ }
247
+ /** Options for useSwipe hook */
248
+ export interface UseSwipeOptions {
249
+ onSwipe: (event: SwipeEvent) => void;
250
+ direction?: SwipeDirection;
251
+ threshold?: number;
252
+ velocityThreshold?: number;
253
+ enabled?: boolean;
254
+ }
255
+ /** Options for usePan hook */
256
+ export interface UsePanOptions {
257
+ onPanStart?: (event: PanEvent) => void;
258
+ onPanMove?: (event: PanEvent) => void;
259
+ onPanEnd?: (event: PanEvent) => void;
260
+ minDistance?: number;
261
+ minPointers?: number;
262
+ maxPointers?: number;
263
+ enabled?: boolean;
264
+ }
265
+ /** Options for usePinch hook */
266
+ export interface UsePinchOptions {
267
+ onPinchStart?: (event: PinchEvent) => void;
268
+ onPinch?: (event: PinchEvent) => void;
269
+ onPinchEnd?: (event: PinchEvent) => void;
270
+ enabled?: boolean;
271
+ }
272
+ /** Options for useRotation hook */
273
+ export interface UseRotationOptions {
274
+ onRotationStart?: (event: RotationEvent) => void;
275
+ onRotation?: (event: RotationEvent) => void;
276
+ onRotationEnd?: (event: RotationEvent) => void;
277
+ enabled?: boolean;
278
+ }
279
+ /** Options for useFling hook */
280
+ export interface UseFlingOptions {
281
+ onFling: (event: FlingEvent) => void;
282
+ direction?: FlingDirection;
283
+ numberOfPointers?: number;
284
+ enabled?: boolean;
285
+ }
286
+ /** Options for useGesture (composer) hook */
287
+ export interface UseGestureOptions {
288
+ tap?: UseTapOptions;
289
+ doubleTap?: UseDoubleTapOptions;
290
+ longPress?: UseLongPressOptions;
291
+ swipe?: UseSwipeOptions;
292
+ pan?: UsePanOptions;
293
+ pinch?: UsePinchOptions;
294
+ rotation?: UseRotationOptions;
295
+ fling?: UseFlingOptions;
296
+ priority?: GesturePriority;
297
+ }
298
+ /** Configuration for createGestureComponent factory */
299
+ export interface GestureComponentConfig<P> {
300
+ /** Display name of the component */
301
+ name: string;
302
+ /** Function that creates a RNGH gesture from the component props */
303
+ createGesture: (props: P) => import('react-native-gesture-handler').GestureType;
304
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Core gesture types and interfaces for react-native-gesture-kit.
4
+ *
5
+ * @module types/gestures
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.GestureState = void 0;
9
+ // ─── Enums ────────────────────────────────────────────────────────────────────
10
+ /** All possible states of a gesture recognizer */
11
+ var GestureState;
12
+ (function (GestureState) {
13
+ GestureState[GestureState["UNDETERMINED"] = 0] = "UNDETERMINED";
14
+ GestureState[GestureState["BEGAN"] = 1] = "BEGAN";
15
+ GestureState[GestureState["ACTIVE"] = 2] = "ACTIVE";
16
+ GestureState[GestureState["END"] = 3] = "END";
17
+ GestureState[GestureState["CANCELLED"] = 4] = "CANCELLED";
18
+ GestureState[GestureState["FAILED"] = 5] = "FAILED";
19
+ })(GestureState || (exports.GestureState = GestureState = {}));
@@ -0,0 +1,55 @@
1
+ export interface BaseGestureEvent {
2
+ [key: string]: any;
3
+ }
4
+ export interface BaseGestureProps {
5
+ [key: string]: any;
6
+ }
7
+ export interface UseTapOptions {
8
+ [key: string]: any;
9
+ }
10
+ export interface TapEvent {
11
+ [key: string]: any;
12
+ }
13
+ export interface UseDoubleTapOptions {
14
+ [key: string]: any;
15
+ }
16
+ export interface UseTripleTapOptions {
17
+ [key: string]: any;
18
+ }
19
+ export interface UseQuadTapOptions {
20
+ [key: string]: any;
21
+ }
22
+ export interface UseLongPressOptions {
23
+ [key: string]: any;
24
+ }
25
+ export interface LongPressEvent {
26
+ [key: string]: any;
27
+ }
28
+ export interface UseVeryLongPressOptions {
29
+ [key: string]: any;
30
+ }
31
+ export interface UsePressForceOptions {
32
+ [key: string]: any;
33
+ }
34
+ export interface PressForceEvent {
35
+ [key: string]: any;
36
+ }
37
+ export interface UseTapAndHoldOptions {
38
+ [key: string]: any;
39
+ }
40
+ export interface UseTapCancelOptions {
41
+ [key: string]: any;
42
+ }
43
+ export type SwipeDirection = 'up' | 'down' | 'left' | 'right';
44
+ export interface PanEvent {
45
+ [key: string]: any;
46
+ }
47
+ export interface SwipeEvent {
48
+ [key: string]: any;
49
+ }
50
+ export interface UsePanOptions {
51
+ [key: string]: any;
52
+ }
53
+ export interface PinchEvent {
54
+ [key: string]: any;
55
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export type AnyGesture = any;
2
+ export declare function composeGestures(...gestures: AnyGesture[]): any[];
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.composeGestures = composeGestures;
4
+ function composeGestures(...gestures) {
5
+ return gestures;
6
+ }
@@ -0,0 +1,3 @@
1
+ export declare function detectSwipeDirection(dx: number, dy: number): "left" | "right";
2
+ export declare function matchesDirection(dir: string, expected: string): boolean;
3
+ export declare function magnitude(dx: number, dy: number): number;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectSwipeDirection = detectSwipeDirection;
4
+ exports.matchesDirection = matchesDirection;
5
+ exports.magnitude = magnitude;
6
+ function detectSwipeDirection(dx, dy) {
7
+ return dx > 0 ? 'right' : 'left';
8
+ }
9
+ function matchesDirection(dir, expected) {
10
+ return dir === expected;
11
+ }
12
+ function magnitude(dx, dy) {
13
+ return Math.sqrt(dx * dx + dy * dy);
14
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "gesture-kit-core",
3
+ "version": "1.0.0",
4
+ "description": "Core types, utilities, and composition for gesture-kit",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": ["dist", "README.md"],
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "prepare": "npm run build",
11
+ "typecheck": "tsc --noEmit"
12
+ },
13
+ "peerDependencies": {
14
+ "react": ">=18.0.0",
15
+ "react-native": ">=0.71.0",
16
+ "react-native-gesture-handler": ">=2.10.0"
17
+ },
18
+ "peerDependenciesMeta": {
19
+ "react-native-reanimated": {
20
+ "optional": true
21
+ }
22
+ },
23
+ "devDependencies": {
24
+ "@types/react": "^18.2.0",
25
+ "react": "^18.2.0",
26
+ "react-native": "^0.73.11",
27
+ "react-native-gesture-handler": "^2.30.0",
28
+ "typescript": "^5.9.3"
29
+ },
30
+ "keywords": ["react-native", "gesture", "core", "types"],
31
+ "license": "MIT"
32
+ }