tekiyo-physics 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/dist/index.cjs +1916 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +846 -0
- package/dist/index.js +1916 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,846 @@
|
|
|
1
|
+
import { default as default_2 } from 'react';
|
|
2
|
+
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
export declare interface Bounds {
|
|
5
|
+
left?: number;
|
|
6
|
+
right?: number;
|
|
7
|
+
top?: number;
|
|
8
|
+
bottom?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Premium card component with physics-based interactions
|
|
13
|
+
* Features lift on hover, press feedback, and optional glassmorphism
|
|
14
|
+
*/
|
|
15
|
+
export declare const Card: default_2.ForwardRefExoticComponent<CardProps & default_2.RefAttributes<HTMLDivElement>>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Default card styles (optional, can be applied via className)
|
|
19
|
+
*/
|
|
20
|
+
export declare const cardBaseStyles: default_2.CSSProperties;
|
|
21
|
+
|
|
22
|
+
export declare interface CardProps {
|
|
23
|
+
children: default_2.ReactNode;
|
|
24
|
+
/** Enable hover lift effect (default: true) */
|
|
25
|
+
lift?: boolean;
|
|
26
|
+
/** Enable press feedback (default: true) */
|
|
27
|
+
pressable?: boolean;
|
|
28
|
+
/** Scale on lift (overrides context) */
|
|
29
|
+
liftScale?: number;
|
|
30
|
+
/** Scale reduction on press (default: 0.98) */
|
|
31
|
+
pressScale?: number;
|
|
32
|
+
/** Enable glassmorphism background */
|
|
33
|
+
glass?: boolean;
|
|
34
|
+
/** Glass blur intensity (default: 20) */
|
|
35
|
+
glassBlur?: number;
|
|
36
|
+
/** Spring configuration override */
|
|
37
|
+
springConfig?: Partial<SpringConfig>;
|
|
38
|
+
/** Additional class name */
|
|
39
|
+
className?: string;
|
|
40
|
+
/** Additional inline styles */
|
|
41
|
+
style?: default_2.CSSProperties;
|
|
42
|
+
/** Click handler */
|
|
43
|
+
onClick?: (e: default_2.MouseEvent) => void;
|
|
44
|
+
/** Callback when hover state changes */
|
|
45
|
+
onHover?: (isHovered: boolean) => void;
|
|
46
|
+
/** Callback when press state changes */
|
|
47
|
+
onPress?: (isPressed: boolean) => void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Combine lift style with other transforms
|
|
52
|
+
*/
|
|
53
|
+
export declare function combineLiftStyle(baseStyle: React.CSSProperties, liftStyle: React.CSSProperties): React.CSSProperties;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Combine stretch with position transform
|
|
57
|
+
*/
|
|
58
|
+
export declare function combineStretchStyle(positionStyle: React.CSSProperties, stretchStyle: React.CSSProperties): React.CSSProperties;
|
|
59
|
+
|
|
60
|
+
export declare const DEFAULT_FRICTION_CONFIG: FrictionConfig;
|
|
61
|
+
|
|
62
|
+
export declare const DEFAULT_SPRING_CONFIG: SpringConfig;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Draggable component with physics-based motion
|
|
66
|
+
* Combines drag, lift, and stretch effects
|
|
67
|
+
*/
|
|
68
|
+
export declare const Draggable: default_2.ForwardRefExoticComponent<DraggableProps & default_2.RefAttributes<HTMLDivElement>>;
|
|
69
|
+
|
|
70
|
+
export declare interface DraggableProps {
|
|
71
|
+
children: default_2.ReactNode;
|
|
72
|
+
/** Initial position */
|
|
73
|
+
initial?: {
|
|
74
|
+
x: number;
|
|
75
|
+
y: number;
|
|
76
|
+
};
|
|
77
|
+
/** Movement bounds */
|
|
78
|
+
bounds?: Bounds;
|
|
79
|
+
/** Enable rubber band at bounds (default: true) */
|
|
80
|
+
rubberBand?: boolean;
|
|
81
|
+
/** Enable momentum after release (default: true) */
|
|
82
|
+
momentum?: boolean;
|
|
83
|
+
/** Enable lift effect on drag (default: true) */
|
|
84
|
+
lift?: boolean;
|
|
85
|
+
/** Enable velocity stretch (default: true) */
|
|
86
|
+
stretch?: boolean;
|
|
87
|
+
/** Snap points after release */
|
|
88
|
+
snapTo?: {
|
|
89
|
+
x: number;
|
|
90
|
+
y: number;
|
|
91
|
+
}[];
|
|
92
|
+
/** Lock to axis */
|
|
93
|
+
axis?: 'x' | 'y' | 'both';
|
|
94
|
+
/** Spring configuration override */
|
|
95
|
+
springConfig?: Partial<SpringConfig>;
|
|
96
|
+
/** Additional class name */
|
|
97
|
+
className?: string;
|
|
98
|
+
/** Additional inline styles */
|
|
99
|
+
style?: default_2.CSSProperties;
|
|
100
|
+
/** Callback on drag start */
|
|
101
|
+
onDragStart?: (position: {
|
|
102
|
+
x: number;
|
|
103
|
+
y: number;
|
|
104
|
+
}) => void;
|
|
105
|
+
/** Callback during drag */
|
|
106
|
+
onDrag?: (position: {
|
|
107
|
+
x: number;
|
|
108
|
+
y: number;
|
|
109
|
+
}) => void;
|
|
110
|
+
/** Callback on drag end */
|
|
111
|
+
onDragEnd?: (position: {
|
|
112
|
+
x: number;
|
|
113
|
+
y: number;
|
|
114
|
+
}, velocity: {
|
|
115
|
+
x: number;
|
|
116
|
+
y: number;
|
|
117
|
+
}) => void;
|
|
118
|
+
/** Callback when animation settles */
|
|
119
|
+
onRest?: (position: {
|
|
120
|
+
x: number;
|
|
121
|
+
y: number;
|
|
122
|
+
}) => void;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export declare interface FrictionConfig {
|
|
126
|
+
/** Friction coefficient (0.9-0.99, higher = less friction) */
|
|
127
|
+
decay: number;
|
|
128
|
+
/** Minimum velocity before stopping (default: 0.1) */
|
|
129
|
+
stopThreshold: number;
|
|
130
|
+
/** Maximum velocity cap (default: 5000 px/s) */
|
|
131
|
+
maxVelocity: number;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export declare function generatePhysicsId(prefix?: string): string;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Gentle preset
|
|
138
|
+
* Soft, forgiving, approachable
|
|
139
|
+
* For friendly, accessible interfaces
|
|
140
|
+
*/
|
|
141
|
+
export declare const gentle: PhysicsPreset;
|
|
142
|
+
|
|
143
|
+
export declare interface GestureBindings {
|
|
144
|
+
onPointerDown: (e: React.PointerEvent) => void;
|
|
145
|
+
onPointerEnter: (e: React.PointerEvent) => void;
|
|
146
|
+
onPointerLeave: (e: React.PointerEvent) => void;
|
|
147
|
+
onFocus: (e: React.FocusEvent) => void;
|
|
148
|
+
onBlur: (e: React.FocusEvent) => void;
|
|
149
|
+
style: React.CSSProperties;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export declare interface GestureHandlers {
|
|
153
|
+
onDragStart?: (state: GestureState) => void;
|
|
154
|
+
onDrag?: (state: GestureState) => void;
|
|
155
|
+
onDragEnd?: (state: GestureState) => void;
|
|
156
|
+
onFlick?: (state: GestureState & {
|
|
157
|
+
flickVelocity: Vector2;
|
|
158
|
+
}) => void;
|
|
159
|
+
onHover?: (hovering: boolean) => void;
|
|
160
|
+
onFocus?: (focused: boolean) => void;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export declare interface GestureState {
|
|
164
|
+
/** Current position relative to element */
|
|
165
|
+
position: Vector2;
|
|
166
|
+
/** Delta from last event */
|
|
167
|
+
delta: Vector2;
|
|
168
|
+
/** Delta from start of gesture */
|
|
169
|
+
offset: Vector2;
|
|
170
|
+
/** Current velocity in px/s */
|
|
171
|
+
velocity: Vector2;
|
|
172
|
+
/** Dominant movement direction */
|
|
173
|
+
direction: 'up' | 'down' | 'left' | 'right' | 'none';
|
|
174
|
+
/** Whether gesture is currently active */
|
|
175
|
+
active: boolean;
|
|
176
|
+
/** Whether this is first event of gesture */
|
|
177
|
+
first: boolean;
|
|
178
|
+
/** Whether this is last event of gesture */
|
|
179
|
+
last: boolean;
|
|
180
|
+
/** Original event */
|
|
181
|
+
event: PointerEvent;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get friction config from preset name
|
|
186
|
+
*/
|
|
187
|
+
export declare function getFrictionConfig(preset: string | FrictionConfig): FrictionConfig;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Get a preset by name
|
|
191
|
+
*/
|
|
192
|
+
export declare function getPreset(name: string): PhysicsPreset | undefined;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Get spring config from preset name
|
|
196
|
+
*/
|
|
197
|
+
export declare function getSpringConfig(preset: string | SpringConfig): SpringConfig;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* iOS-like feel
|
|
201
|
+
* Smooth, natural, slightly bouncy response
|
|
202
|
+
* Premium Apple-style interactions
|
|
203
|
+
*/
|
|
204
|
+
export declare const ios: PhysicsPreset;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Momentum system with exponential friction decay
|
|
208
|
+
* Provides natural deceleration after flick gestures
|
|
209
|
+
*/
|
|
210
|
+
export declare class Momentum {
|
|
211
|
+
private position;
|
|
212
|
+
private velocity;
|
|
213
|
+
private config;
|
|
214
|
+
private isActive;
|
|
215
|
+
constructor(initialPosition?: Vector2, config?: Partial<FrictionConfig>);
|
|
216
|
+
/**
|
|
217
|
+
* Start momentum with initial velocity
|
|
218
|
+
*/
|
|
219
|
+
start(position: Vector2, velocity: Vector2): void;
|
|
220
|
+
/**
|
|
221
|
+
* Stop momentum immediately
|
|
222
|
+
*/
|
|
223
|
+
stop(): void;
|
|
224
|
+
/**
|
|
225
|
+
* Update momentum simulation
|
|
226
|
+
* @param deltaTime Time in seconds
|
|
227
|
+
*/
|
|
228
|
+
step(deltaTime: number): {
|
|
229
|
+
position: Vector2;
|
|
230
|
+
velocity: Vector2;
|
|
231
|
+
isActive: boolean;
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Apply rubber band effect at boundaries
|
|
235
|
+
*/
|
|
236
|
+
applyRubberBand(bounds: {
|
|
237
|
+
min: Vector2;
|
|
238
|
+
max: Vector2;
|
|
239
|
+
}, rubberBandFactor?: number): void;
|
|
240
|
+
getPosition(): Vector2;
|
|
241
|
+
getVelocity(): Vector2;
|
|
242
|
+
getIsActive(): boolean;
|
|
243
|
+
setPosition(position: Vector2): void;
|
|
244
|
+
updateConfig(config: Partial<FrictionConfig>): void;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 1D Momentum for single-axis motion
|
|
249
|
+
*/
|
|
250
|
+
export declare class Momentum1D {
|
|
251
|
+
private position;
|
|
252
|
+
private velocity;
|
|
253
|
+
private config;
|
|
254
|
+
private isActive;
|
|
255
|
+
constructor(initialPosition?: number, config?: Partial<FrictionConfig>);
|
|
256
|
+
start(position: number, velocity: number): void;
|
|
257
|
+
stop(): void;
|
|
258
|
+
step(deltaTime: number): {
|
|
259
|
+
position: number;
|
|
260
|
+
velocity: number;
|
|
261
|
+
isActive: boolean;
|
|
262
|
+
};
|
|
263
|
+
getPosition(): number;
|
|
264
|
+
setPosition(position: number): void;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export declare interface PhysicsContextValue {
|
|
268
|
+
spring: SpringConfig;
|
|
269
|
+
friction: FrictionConfig;
|
|
270
|
+
stretch: {
|
|
271
|
+
intensity: number;
|
|
272
|
+
maxVelocity: number;
|
|
273
|
+
};
|
|
274
|
+
lift: {
|
|
275
|
+
scale: number;
|
|
276
|
+
shadowIntensity: number;
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export declare const PhysicsEngine: PhysicsEngineCore;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Central physics engine with shared RAF loop
|
|
284
|
+
* Manages all physics simulations efficiently
|
|
285
|
+
*/
|
|
286
|
+
declare class PhysicsEngineCore {
|
|
287
|
+
private bodies;
|
|
288
|
+
private rafId;
|
|
289
|
+
private lastTime;
|
|
290
|
+
private isRunning;
|
|
291
|
+
private readonly maxDelta;
|
|
292
|
+
/**
|
|
293
|
+
* Register a physics body to receive updates
|
|
294
|
+
*/
|
|
295
|
+
register(id: string, update: UpdateCallback, priority?: number): void;
|
|
296
|
+
/**
|
|
297
|
+
* Unregister a physics body
|
|
298
|
+
*/
|
|
299
|
+
unregister(id: string): void;
|
|
300
|
+
/**
|
|
301
|
+
* Check if a body is registered
|
|
302
|
+
*/
|
|
303
|
+
has(id: string): boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Start the physics loop
|
|
306
|
+
*/
|
|
307
|
+
private start;
|
|
308
|
+
/**
|
|
309
|
+
* Stop the physics loop
|
|
310
|
+
*/
|
|
311
|
+
private stop;
|
|
312
|
+
/**
|
|
313
|
+
* Main RAF loop
|
|
314
|
+
*/
|
|
315
|
+
private loop;
|
|
316
|
+
/**
|
|
317
|
+
* Get current number of active bodies
|
|
318
|
+
*/
|
|
319
|
+
getActiveCount(): number;
|
|
320
|
+
/**
|
|
321
|
+
* Check if engine is running
|
|
322
|
+
*/
|
|
323
|
+
getIsRunning(): boolean;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export declare interface PhysicsPreset {
|
|
327
|
+
name: string;
|
|
328
|
+
description: string;
|
|
329
|
+
spring: SpringConfig;
|
|
330
|
+
friction: FrictionConfig;
|
|
331
|
+
stretch: {
|
|
332
|
+
intensity: number;
|
|
333
|
+
maxVelocity: number;
|
|
334
|
+
};
|
|
335
|
+
lift: {
|
|
336
|
+
scale: number;
|
|
337
|
+
shadowIntensity: number;
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Provider for global physics configuration
|
|
343
|
+
* Wrap your app or component tree to set defaults
|
|
344
|
+
*/
|
|
345
|
+
export declare function PhysicsProvider({ children, preset, spring, friction, stretch, lift, }: PhysicsProviderProps): JSX_2.Element;
|
|
346
|
+
|
|
347
|
+
export declare interface PhysicsProviderProps {
|
|
348
|
+
children: default_2.ReactNode;
|
|
349
|
+
/** Preset name or custom configuration */
|
|
350
|
+
preset?: keyof typeof presets | PhysicsPreset;
|
|
351
|
+
/** Override spring config */
|
|
352
|
+
spring?: Partial<SpringConfig>;
|
|
353
|
+
/** Override friction config */
|
|
354
|
+
friction?: Partial<FrictionConfig>;
|
|
355
|
+
/** Override stretch config */
|
|
356
|
+
stretch?: Partial<{
|
|
357
|
+
intensity: number;
|
|
358
|
+
maxVelocity: number;
|
|
359
|
+
}>;
|
|
360
|
+
/** Override lift config */
|
|
361
|
+
lift?: Partial<{
|
|
362
|
+
scale: number;
|
|
363
|
+
shadowIntensity: number;
|
|
364
|
+
}>;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export declare const presets: Record<string, PhysicsPreset>;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Smooth preset
|
|
371
|
+
* Slow, deliberate, luxurious feel
|
|
372
|
+
* For premium, elegant interfaces
|
|
373
|
+
*/
|
|
374
|
+
export declare const smooth: PhysicsPreset;
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Snappy preset
|
|
378
|
+
* Ultra-responsive, minimal lag
|
|
379
|
+
* For UI that needs to feel instant
|
|
380
|
+
*/
|
|
381
|
+
export declare const snappy: PhysicsPreset;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Spring physics simulation using semi-implicit Euler integration
|
|
385
|
+
* Provides smooth, natural motion without overshoot
|
|
386
|
+
*/
|
|
387
|
+
export declare class Spring {
|
|
388
|
+
private position;
|
|
389
|
+
private velocity;
|
|
390
|
+
private target;
|
|
391
|
+
private config;
|
|
392
|
+
constructor(initialPosition?: Vector2, config?: Partial<SpringConfig>);
|
|
393
|
+
setTarget(target: Vector2): void;
|
|
394
|
+
setPosition(position: Vector2): void;
|
|
395
|
+
setVelocity(velocity: Vector2): void;
|
|
396
|
+
updateConfig(config: Partial<SpringConfig>): void;
|
|
397
|
+
/**
|
|
398
|
+
* Advance the spring simulation by deltaTime seconds
|
|
399
|
+
* Uses semi-implicit Euler for stability
|
|
400
|
+
*/
|
|
401
|
+
step(deltaTime: number): SpringState;
|
|
402
|
+
getState(): SpringState;
|
|
403
|
+
/**
|
|
404
|
+
* Immediately snap to target
|
|
405
|
+
*/
|
|
406
|
+
snapToTarget(): void;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* 1D Spring for single-value animations (scale, opacity, etc.)
|
|
411
|
+
*/
|
|
412
|
+
export declare class Spring1D {
|
|
413
|
+
private position;
|
|
414
|
+
private velocity;
|
|
415
|
+
private target;
|
|
416
|
+
private config;
|
|
417
|
+
constructor(initialValue?: number, config?: Partial<SpringConfig>);
|
|
418
|
+
setTarget(target: number): void;
|
|
419
|
+
setPosition(position: number): void;
|
|
420
|
+
setVelocity(velocity: number): void;
|
|
421
|
+
step(deltaTime: number): {
|
|
422
|
+
value: number;
|
|
423
|
+
velocity: number;
|
|
424
|
+
isSettled: boolean;
|
|
425
|
+
};
|
|
426
|
+
getValue(): number;
|
|
427
|
+
snapToTarget(): void;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export declare interface SpringConfig {
|
|
431
|
+
/** Force pulling toward target (100-500, default: 170) */
|
|
432
|
+
tension: number;
|
|
433
|
+
/** Resistance to motion (10-50, default: 26) */
|
|
434
|
+
friction: number;
|
|
435
|
+
/** Virtual mass affecting inertia (0.5-3, default: 1) */
|
|
436
|
+
mass: number;
|
|
437
|
+
/** Threshold to consider animation complete (default: 0.01) */
|
|
438
|
+
precision: number;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export declare interface SpringState {
|
|
442
|
+
position: Vector2;
|
|
443
|
+
velocity: Vector2;
|
|
444
|
+
target: Vector2;
|
|
445
|
+
isSettled: boolean;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Stiff preset
|
|
450
|
+
* Minimal overshoot, direct response
|
|
451
|
+
* For precision interfaces
|
|
452
|
+
*/
|
|
453
|
+
export declare const stiff: PhysicsPreset;
|
|
454
|
+
|
|
455
|
+
declare type UpdateCallback = (deltaTime: number) => void;
|
|
456
|
+
|
|
457
|
+
export declare function useDrag(options?: UseDragOptions): UseDragReturn;
|
|
458
|
+
|
|
459
|
+
export declare interface UseDragOptions {
|
|
460
|
+
/** Initial position */
|
|
461
|
+
initial?: {
|
|
462
|
+
x: number;
|
|
463
|
+
y: number;
|
|
464
|
+
};
|
|
465
|
+
/** Movement bounds */
|
|
466
|
+
bounds?: Bounds;
|
|
467
|
+
/** Enable rubber band effect at bounds (default: true) */
|
|
468
|
+
rubberBand?: boolean;
|
|
469
|
+
/** Rubber band resistance (0-1, default: 0.55) */
|
|
470
|
+
rubberBandFactor?: number;
|
|
471
|
+
/** Enable momentum after release (default: true) */
|
|
472
|
+
momentum?: boolean;
|
|
473
|
+
/** Snap to positions after release */
|
|
474
|
+
snapTo?: {
|
|
475
|
+
x: number;
|
|
476
|
+
y: number;
|
|
477
|
+
}[];
|
|
478
|
+
/** Snap threshold distance (default: 50) */
|
|
479
|
+
snapThreshold?: number;
|
|
480
|
+
/** Lock to single axis */
|
|
481
|
+
axis?: 'x' | 'y' | 'both';
|
|
482
|
+
/** Spring configuration for snap */
|
|
483
|
+
springConfig?: Partial<SpringConfig>;
|
|
484
|
+
/** Friction configuration for momentum */
|
|
485
|
+
frictionConfig?: Partial<FrictionConfig>;
|
|
486
|
+
/** Callback on drag start */
|
|
487
|
+
onDragStart?: (position: Vector2) => void;
|
|
488
|
+
/** Callback during drag */
|
|
489
|
+
onDrag?: (position: Vector2) => void;
|
|
490
|
+
/** Callback on drag end */
|
|
491
|
+
onDragEnd?: (position: Vector2, velocity: Vector2) => void;
|
|
492
|
+
/** Callback when settled */
|
|
493
|
+
onRest?: (position: Vector2) => void;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export declare interface UseDragReturn {
|
|
497
|
+
/** Current x position */
|
|
498
|
+
x: number;
|
|
499
|
+
/** Current y position */
|
|
500
|
+
y: number;
|
|
501
|
+
/** Whether currently dragging */
|
|
502
|
+
isDragging: boolean;
|
|
503
|
+
/** Whether momentum is active */
|
|
504
|
+
isMomentum: boolean;
|
|
505
|
+
/** CSS style object */
|
|
506
|
+
style: React.CSSProperties;
|
|
507
|
+
/** Bind to element */
|
|
508
|
+
bind: {
|
|
509
|
+
onPointerDown: (e: React.PointerEvent) => void;
|
|
510
|
+
style: React.CSSProperties;
|
|
511
|
+
};
|
|
512
|
+
/** Set position programmatically */
|
|
513
|
+
setPosition: (position: {
|
|
514
|
+
x: number;
|
|
515
|
+
y: number;
|
|
516
|
+
}) => void;
|
|
517
|
+
/** Snap to position with spring */
|
|
518
|
+
snapToPosition: (position: {
|
|
519
|
+
x: number;
|
|
520
|
+
y: number;
|
|
521
|
+
}) => void;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
export declare function useFlick(options?: UseFlickOptions): UseFlickReturn;
|
|
525
|
+
|
|
526
|
+
export declare interface UseFlickOptions {
|
|
527
|
+
/** Initial position */
|
|
528
|
+
initial?: {
|
|
529
|
+
x: number;
|
|
530
|
+
y: number;
|
|
531
|
+
};
|
|
532
|
+
/** Minimum velocity to trigger flick (default: 500 px/s) */
|
|
533
|
+
threshold?: number;
|
|
534
|
+
/** Friction configuration */
|
|
535
|
+
friction?: Partial<FrictionConfig>;
|
|
536
|
+
/** Lock to single axis */
|
|
537
|
+
axis?: 'x' | 'y' | 'both';
|
|
538
|
+
/** Callback when flick starts */
|
|
539
|
+
onFlickStart?: (velocity: Vector2) => void;
|
|
540
|
+
/** Callback during flick momentum */
|
|
541
|
+
onFlick?: (position: Vector2, velocity: Vector2) => void;
|
|
542
|
+
/** Callback when flick ends */
|
|
543
|
+
onFlickEnd?: (position: Vector2) => void;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export declare interface UseFlickReturn {
|
|
547
|
+
/** Current x position */
|
|
548
|
+
x: number;
|
|
549
|
+
/** Current y position */
|
|
550
|
+
y: number;
|
|
551
|
+
/** Whether flick momentum is active */
|
|
552
|
+
isFlicking: boolean;
|
|
553
|
+
/** Current velocity */
|
|
554
|
+
velocity: Vector2;
|
|
555
|
+
/** CSS style object */
|
|
556
|
+
style: React.CSSProperties;
|
|
557
|
+
/** Trigger a flick with given velocity */
|
|
558
|
+
flick: (velocity: {
|
|
559
|
+
x: number;
|
|
560
|
+
y: number;
|
|
561
|
+
}) => void;
|
|
562
|
+
/** Stop current flick */
|
|
563
|
+
stop: () => void;
|
|
564
|
+
/** Set position (stops any active flick) */
|
|
565
|
+
setPosition: (position: {
|
|
566
|
+
x: number;
|
|
567
|
+
y: number;
|
|
568
|
+
}) => void;
|
|
569
|
+
/** Record position sample for velocity tracking */
|
|
570
|
+
recordSample: (position: {
|
|
571
|
+
x: number;
|
|
572
|
+
y: number;
|
|
573
|
+
}) => void;
|
|
574
|
+
/** Get current velocity from samples */
|
|
575
|
+
getCurrentVelocity: () => Vector2;
|
|
576
|
+
/** Release with current velocity (triggers flick if above threshold) */
|
|
577
|
+
release: (position: {
|
|
578
|
+
x: number;
|
|
579
|
+
y: number;
|
|
580
|
+
}) => boolean;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Hook to get friction config from context
|
|
585
|
+
*/
|
|
586
|
+
export declare function useFrictionConfig(): Partial<FrictionConfig>;
|
|
587
|
+
|
|
588
|
+
export declare function useGesture(options: UseGestureOptions): GestureBindings;
|
|
589
|
+
|
|
590
|
+
export declare interface UseGestureOptions extends GestureHandlers {
|
|
591
|
+
/** Minimum distance before drag starts (default: 3) */
|
|
592
|
+
threshold?: number;
|
|
593
|
+
/** Minimum velocity for flick detection (default: 500 px/s) */
|
|
594
|
+
flickThreshold?: number;
|
|
595
|
+
/** Enable touch action prevention */
|
|
596
|
+
preventTouch?: boolean;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
export declare function useLift(options?: UseLiftOptions): UseLiftReturn;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Hook to get lift config from context
|
|
603
|
+
*/
|
|
604
|
+
export declare function useLiftConfig(): {
|
|
605
|
+
scale: number;
|
|
606
|
+
shadowIntensity: number;
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
export declare interface UseLiftOptions {
|
|
610
|
+
/** When to activate lift effect */
|
|
611
|
+
trigger?: 'hover' | 'drag' | 'focus' | 'active';
|
|
612
|
+
/** Scale factor when lifted (default: 1.03) */
|
|
613
|
+
scale?: number;
|
|
614
|
+
/** Enable dynamic shadow (default: true) */
|
|
615
|
+
shadow?: boolean;
|
|
616
|
+
/** Shadow intensity multiplier (default: 1) */
|
|
617
|
+
shadowIntensity?: number;
|
|
618
|
+
/** Spring configuration */
|
|
619
|
+
springConfig?: Partial<SpringConfig>;
|
|
620
|
+
/** Callback when lift state changes */
|
|
621
|
+
onLift?: (isLifted: boolean) => void;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export declare interface UseLiftReturn {
|
|
625
|
+
/** Whether element is currently lifted */
|
|
626
|
+
isLifted: boolean;
|
|
627
|
+
/** Current scale value */
|
|
628
|
+
scale: number;
|
|
629
|
+
/** CSS style object */
|
|
630
|
+
style: React.CSSProperties;
|
|
631
|
+
/** Event handlers to bind */
|
|
632
|
+
bind: {
|
|
633
|
+
onPointerEnter?: () => void;
|
|
634
|
+
onPointerLeave?: () => void;
|
|
635
|
+
onPointerDown?: () => void;
|
|
636
|
+
onPointerUp?: () => void;
|
|
637
|
+
onFocus?: () => void;
|
|
638
|
+
onBlur?: () => void;
|
|
639
|
+
};
|
|
640
|
+
/** Manually set lift state */
|
|
641
|
+
setLifted: (lifted: boolean) => void;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Hook to get spring config from context
|
|
646
|
+
*/
|
|
647
|
+
export declare function usePhysicsConfig(): Partial<SpringConfig>;
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Hook to access physics configuration
|
|
651
|
+
*/
|
|
652
|
+
export declare function usePhysicsContext(): PhysicsContextValue;
|
|
653
|
+
|
|
654
|
+
export declare function useSpring(options: UseSpringOptions): UseSpringReturn;
|
|
655
|
+
|
|
656
|
+
export declare function useSpring1D(options: UseSpring1DOptions): {
|
|
657
|
+
value: number;
|
|
658
|
+
isAnimating: boolean;
|
|
659
|
+
isSettled: boolean;
|
|
660
|
+
setTarget: (target: number) => void;
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* 1D Spring hook for single values (scale, opacity, rotation, etc.)
|
|
665
|
+
*/
|
|
666
|
+
export declare interface UseSpring1DOptions {
|
|
667
|
+
from?: number;
|
|
668
|
+
to: number;
|
|
669
|
+
config?: Partial<SpringConfig>;
|
|
670
|
+
onRest?: () => void;
|
|
671
|
+
immediate?: boolean;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
export declare interface UseSpringOptions {
|
|
675
|
+
/** Initial position */
|
|
676
|
+
from?: {
|
|
677
|
+
x: number;
|
|
678
|
+
y: number;
|
|
679
|
+
};
|
|
680
|
+
/** Target position */
|
|
681
|
+
to: {
|
|
682
|
+
x: number;
|
|
683
|
+
y: number;
|
|
684
|
+
};
|
|
685
|
+
/** Spring configuration or preset name */
|
|
686
|
+
config?: Partial<SpringConfig> | 'ios' | 'snappy' | 'smooth';
|
|
687
|
+
/** Callback when animation completes */
|
|
688
|
+
onRest?: () => void;
|
|
689
|
+
/** Start immediately (default: true) */
|
|
690
|
+
immediate?: boolean;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
export declare interface UseSpringReturn {
|
|
694
|
+
/** Current x position */
|
|
695
|
+
x: number;
|
|
696
|
+
/** Current y position */
|
|
697
|
+
y: number;
|
|
698
|
+
/** CSS style object ready to apply */
|
|
699
|
+
style: React.CSSProperties;
|
|
700
|
+
/** Whether animation is currently running */
|
|
701
|
+
isAnimating: boolean;
|
|
702
|
+
/** Whether animation has reached target */
|
|
703
|
+
isSettled: boolean;
|
|
704
|
+
/** Set new target position */
|
|
705
|
+
setTarget: (target: {
|
|
706
|
+
x: number;
|
|
707
|
+
y: number;
|
|
708
|
+
}) => void;
|
|
709
|
+
/** Immediately snap to position */
|
|
710
|
+
snapTo: (position: {
|
|
711
|
+
x: number;
|
|
712
|
+
y: number;
|
|
713
|
+
}) => void;
|
|
714
|
+
/** Add impulse velocity */
|
|
715
|
+
impulse: (velocity: {
|
|
716
|
+
x: number;
|
|
717
|
+
y: number;
|
|
718
|
+
}) => void;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* Calculate stretch deformation based on velocity
|
|
723
|
+
* Subtle, directional stretch - never cartoon-like
|
|
724
|
+
*/
|
|
725
|
+
export declare function useStretch(options: UseStretchOptions): UseStretchReturn;
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Hook to get stretch config from context
|
|
729
|
+
*/
|
|
730
|
+
export declare function useStretchConfig(): {
|
|
731
|
+
intensity: number;
|
|
732
|
+
maxVelocity: number;
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
export declare interface UseStretchOptions {
|
|
736
|
+
/** Current velocity vector */
|
|
737
|
+
velocity: Vector2 | {
|
|
738
|
+
x: number;
|
|
739
|
+
y: number;
|
|
740
|
+
};
|
|
741
|
+
/** Axis to apply stretch ('x', 'y', or 'both') */
|
|
742
|
+
axis?: 'x' | 'y' | 'both';
|
|
743
|
+
/** Maximum stretch intensity (0-0.3, default: 0.12) */
|
|
744
|
+
intensity?: number;
|
|
745
|
+
/** Velocity at which max stretch is reached (default: 2000) */
|
|
746
|
+
maxVelocity?: number;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
export declare interface UseStretchReturn {
|
|
750
|
+
/** Scale X value */
|
|
751
|
+
scaleX: number;
|
|
752
|
+
/** Scale Y value */
|
|
753
|
+
scaleY: number;
|
|
754
|
+
/** CSS style object with transform */
|
|
755
|
+
style: React.CSSProperties;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Immutable 2D vector class for physics calculations
|
|
760
|
+
*/
|
|
761
|
+
export declare class Vector2 {
|
|
762
|
+
readonly x: number;
|
|
763
|
+
readonly y: number;
|
|
764
|
+
constructor(x?: number, y?: number);
|
|
765
|
+
static zero(): Vector2;
|
|
766
|
+
static from(x: number, y: number): Vector2;
|
|
767
|
+
static fromObject(obj: {
|
|
768
|
+
x: number;
|
|
769
|
+
y: number;
|
|
770
|
+
}): Vector2;
|
|
771
|
+
add(other: Vector2): Vector2;
|
|
772
|
+
subtract(other: Vector2): Vector2;
|
|
773
|
+
multiply(scalar: number): Vector2;
|
|
774
|
+
divide(scalar: number): Vector2;
|
|
775
|
+
get magnitude(): number;
|
|
776
|
+
get magnitudeSquared(): number;
|
|
777
|
+
normalize(): Vector2;
|
|
778
|
+
clamp(maxMagnitude: number): Vector2;
|
|
779
|
+
clampComponents(min: Vector2, max: Vector2): Vector2;
|
|
780
|
+
lerp(target: Vector2, t: number): Vector2;
|
|
781
|
+
dot(other: Vector2): number;
|
|
782
|
+
distanceTo(other: Vector2): number;
|
|
783
|
+
equals(other: Vector2, epsilon?: number): boolean;
|
|
784
|
+
isZero(epsilon?: number): boolean;
|
|
785
|
+
negate(): Vector2;
|
|
786
|
+
abs(): Vector2;
|
|
787
|
+
toObject(): {
|
|
788
|
+
x: number;
|
|
789
|
+
y: number;
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* Velocity tracker using circular buffer for smooth velocity estimation
|
|
795
|
+
* Calculates average velocity from recent position history
|
|
796
|
+
*/
|
|
797
|
+
export declare class VelocityTracker {
|
|
798
|
+
private samples;
|
|
799
|
+
private maxSamples;
|
|
800
|
+
private maxAge;
|
|
801
|
+
constructor(maxSamples?: number, maxAge?: number);
|
|
802
|
+
/**
|
|
803
|
+
* Record a position sample
|
|
804
|
+
*/
|
|
805
|
+
addSample(position: Vector2, timestamp?: number): void;
|
|
806
|
+
/**
|
|
807
|
+
* Calculate current velocity from sample history
|
|
808
|
+
* Returns smoothed velocity vector in pixels per second
|
|
809
|
+
*/
|
|
810
|
+
getVelocity(): Vector2;
|
|
811
|
+
/**
|
|
812
|
+
* Get velocity magnitude in pixels per second
|
|
813
|
+
*/
|
|
814
|
+
getSpeed(): number;
|
|
815
|
+
/**
|
|
816
|
+
* Check if current velocity qualifies as a flick gesture
|
|
817
|
+
*/
|
|
818
|
+
isFlick(threshold?: number): boolean;
|
|
819
|
+
/**
|
|
820
|
+
* Get dominant direction of movement
|
|
821
|
+
*/
|
|
822
|
+
getDirection(): 'up' | 'down' | 'left' | 'right' | 'none';
|
|
823
|
+
/**
|
|
824
|
+
* Clear all samples
|
|
825
|
+
*/
|
|
826
|
+
reset(): void;
|
|
827
|
+
/**
|
|
828
|
+
* Get the last recorded position
|
|
829
|
+
*/
|
|
830
|
+
getLastPosition(): Vector2 | null;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* 1D velocity tracker for single-axis motion
|
|
835
|
+
*/
|
|
836
|
+
export declare class VelocityTracker1D {
|
|
837
|
+
private samples;
|
|
838
|
+
private maxSamples;
|
|
839
|
+
private maxAge;
|
|
840
|
+
constructor(maxSamples?: number, maxAge?: number);
|
|
841
|
+
addSample(value: number, timestamp?: number): void;
|
|
842
|
+
getVelocity(): number;
|
|
843
|
+
reset(): void;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
export { }
|