mtrl-addons 0.1.1 → 0.2.1
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/build.js +139 -108
- package/package.json +13 -4
- package/scripts/debug/vlist-selection.ts +121 -0
- package/src/components/index.ts +5 -41
- package/src/components/{list → vlist}/config.ts +66 -95
- package/src/components/vlist/constants.ts +23 -0
- package/src/components/vlist/features/api.ts +322 -0
- package/src/components/vlist/features/index.ts +10 -0
- package/src/components/vlist/features/selection.ts +444 -0
- package/src/components/vlist/features/viewport.ts +65 -0
- package/src/components/vlist/index.ts +16 -0
- package/src/components/{list → vlist}/types.ts +104 -26
- package/src/components/vlist/vlist.ts +92 -0
- package/src/core/compose/features/gestures/index.ts +227 -0
- package/src/core/compose/features/gestures/longpress.ts +383 -0
- package/src/core/compose/features/gestures/pan.ts +424 -0
- package/src/core/compose/features/gestures/pinch.ts +475 -0
- package/src/core/compose/features/gestures/rotate.ts +485 -0
- package/src/core/compose/features/gestures/swipe.ts +492 -0
- package/src/core/compose/features/gestures/tap.ts +334 -0
- package/src/core/compose/features/index.ts +2 -38
- package/src/core/compose/index.ts +13 -29
- package/src/core/gestures/index.ts +31 -0
- package/src/core/gestures/longpress.ts +68 -0
- package/src/core/gestures/manager.ts +418 -0
- package/src/core/gestures/pan.ts +48 -0
- package/src/core/gestures/pinch.ts +58 -0
- package/src/core/gestures/rotate.ts +58 -0
- package/src/core/gestures/swipe.ts +66 -0
- package/src/core/gestures/tap.ts +45 -0
- package/src/core/gestures/types.ts +387 -0
- package/src/core/gestures/utils.ts +128 -0
- package/src/core/index.ts +27 -151
- package/src/core/layout/schema.ts +73 -35
- package/src/core/layout/types.ts +5 -2
- package/src/core/viewport/constants.ts +140 -0
- package/src/core/viewport/features/base.ts +73 -0
- package/src/core/viewport/features/collection.ts +882 -0
- package/src/core/viewport/features/events.ts +130 -0
- package/src/core/viewport/features/index.ts +20 -0
- package/src/core/{list-manager/features/viewport → viewport/features}/item-size.ts +27 -30
- package/src/core/{list-manager/features/viewport → viewport/features}/loading.ts +4 -4
- package/src/core/viewport/features/momentum.ts +260 -0
- package/src/core/viewport/features/placeholders.ts +335 -0
- package/src/core/viewport/features/rendering.ts +568 -0
- package/src/core/viewport/features/scrollbar.ts +434 -0
- package/src/core/viewport/features/scrolling.ts +618 -0
- package/src/core/viewport/features/utils.ts +88 -0
- package/src/core/viewport/features/virtual.ts +384 -0
- package/src/core/viewport/index.ts +31 -0
- package/src/core/viewport/types.ts +133 -0
- package/src/core/viewport/utils/speed-tracker.ts +79 -0
- package/src/core/viewport/viewport.ts +246 -0
- package/src/index.ts +0 -7
- package/src/styles/components/_vlist.scss +331 -0
- package/src/styles/index.scss +1 -1
- package/test/components/vlist-selection.test.ts +240 -0
- package/test/components/vlist.test.ts +63 -0
- package/test/core/collection/adapter.test.ts +161 -0
- package/bun.lock +0 -792
- package/src/components/list/api.ts +0 -314
- package/src/components/list/constants.ts +0 -56
- package/src/components/list/features/api.ts +0 -428
- package/src/components/list/features/index.ts +0 -31
- package/src/components/list/features/list-manager.ts +0 -502
- package/src/components/list/index.ts +0 -39
- package/src/components/list/list.ts +0 -234
- package/src/core/collection/base-collection.ts +0 -100
- package/src/core/collection/collection-composer.ts +0 -178
- package/src/core/collection/collection.ts +0 -745
- package/src/core/collection/constants.ts +0 -172
- package/src/core/collection/events.ts +0 -428
- package/src/core/collection/features/api/loading.ts +0 -279
- package/src/core/collection/features/operations/data-operations.ts +0 -147
- package/src/core/collection/index.ts +0 -104
- package/src/core/collection/state.ts +0 -497
- package/src/core/collection/types.ts +0 -404
- package/src/core/compose/features/collection.ts +0 -119
- package/src/core/compose/features/selection.ts +0 -213
- package/src/core/compose/features/styling.ts +0 -108
- package/src/core/list-manager/api.ts +0 -599
- package/src/core/list-manager/config.ts +0 -593
- package/src/core/list-manager/constants.ts +0 -268
- package/src/core/list-manager/features/api.ts +0 -58
- package/src/core/list-manager/features/collection/collection.ts +0 -705
- package/src/core/list-manager/features/collection/index.ts +0 -17
- package/src/core/list-manager/features/viewport/constants.ts +0 -42
- package/src/core/list-manager/features/viewport/index.ts +0 -16
- package/src/core/list-manager/features/viewport/placeholders.ts +0 -281
- package/src/core/list-manager/features/viewport/rendering.ts +0 -575
- package/src/core/list-manager/features/viewport/scrollbar.ts +0 -495
- package/src/core/list-manager/features/viewport/scrolling.ts +0 -795
- package/src/core/list-manager/features/viewport/template.ts +0 -220
- package/src/core/list-manager/features/viewport/viewport.ts +0 -654
- package/src/core/list-manager/features/viewport/virtual.ts +0 -309
- package/src/core/list-manager/index.ts +0 -279
- package/src/core/list-manager/list-manager.ts +0 -206
- package/src/core/list-manager/types.ts +0 -439
- package/src/core/list-manager/utils/calculations.ts +0 -290
- package/src/core/list-manager/utils/range-calculator.ts +0 -349
- package/src/core/list-manager/utils/speed-tracker.ts +0 -273
- package/src/styles/components/_list.scss +0 -244
- package/src/types/mtrl.d.ts +0 -6
- package/test/components/list.test.ts +0 -256
- package/test/core/collection/failed-ranges.test.ts +0 -270
- package/test/core/compose/features.test.ts +0 -183
- package/test/core/list-manager/features/collection.test.ts +0 -704
- package/test/core/list-manager/features/viewport.test.ts +0 -698
- package/test/core/list-manager/list-manager.test.ts +0 -593
- package/test/core/list-manager/utils/calculations.test.ts +0 -433
- package/test/core/list-manager/utils/range-calculator.test.ts +0 -569
- package/test/core/list-manager/utils/speed-tracker.test.ts +0 -530
- package/tsconfig.build.json +0 -14
- /package/src/components/{list → vlist}/features.ts +0 -0
- /package/src/core/{compose → viewport}/features/performance.ts +0 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
// src/core/gestures/types.ts
|
|
2
|
+
/**
|
|
3
|
+
* @module core/gestures
|
|
4
|
+
* @description Type definitions for the gesture system
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Types of gestures supported by the system
|
|
9
|
+
*/
|
|
10
|
+
export enum GESTURE_TYPES {
|
|
11
|
+
TAP = 'tap',
|
|
12
|
+
SWIPE = 'swipe',
|
|
13
|
+
SWIPE_LEFT = 'swipeleft',
|
|
14
|
+
SWIPE_RIGHT = 'swiperight',
|
|
15
|
+
SWIPE_UP = 'swipeup',
|
|
16
|
+
SWIPE_DOWN = 'swipedown',
|
|
17
|
+
PINCH = 'pinch',
|
|
18
|
+
ROTATE = 'rotate',
|
|
19
|
+
LONG_PRESS = 'longpress',
|
|
20
|
+
PAN = 'pan'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Direction of swipe gestures
|
|
25
|
+
*/
|
|
26
|
+
export enum SWIPE_DIRECTIONS {
|
|
27
|
+
UP = 'up',
|
|
28
|
+
DOWN = 'down',
|
|
29
|
+
LEFT = 'left',
|
|
30
|
+
RIGHT = 'right'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Configuration options for gesture recognition
|
|
35
|
+
*/
|
|
36
|
+
export interface GestureConfig {
|
|
37
|
+
/**
|
|
38
|
+
* Minimum distance (in pixels) to recognize a swipe
|
|
39
|
+
* @default 30
|
|
40
|
+
*/
|
|
41
|
+
swipeThreshold?: number;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Maximum time (in ms) in which a swipe must be completed
|
|
45
|
+
* @default 300
|
|
46
|
+
*/
|
|
47
|
+
swipeTimeThreshold?: number;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Time (in ms) to recognize a long press
|
|
51
|
+
* @default 500
|
|
52
|
+
*/
|
|
53
|
+
longPressTime?: number;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Distance threshold (in pixels) for tap recognition
|
|
57
|
+
* @default 10
|
|
58
|
+
*/
|
|
59
|
+
tapDistanceThreshold?: number;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Whether to prevent default behaviors on touch events
|
|
63
|
+
* @default true
|
|
64
|
+
*/
|
|
65
|
+
preventDefault?: boolean;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Whether to stop event propagation
|
|
69
|
+
* @default false
|
|
70
|
+
*/
|
|
71
|
+
stopPropagation?: boolean;
|
|
72
|
+
|
|
73
|
+
[key: string]: any;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Base gesture event data
|
|
78
|
+
*/
|
|
79
|
+
export interface GestureEvent {
|
|
80
|
+
/**
|
|
81
|
+
* Type of the gesture
|
|
82
|
+
*/
|
|
83
|
+
type: string;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Original DOM event
|
|
87
|
+
*/
|
|
88
|
+
originalEvent: Event;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Element the gesture was triggered on
|
|
92
|
+
*/
|
|
93
|
+
target: EventTarget;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Timestamp when the gesture started
|
|
97
|
+
*/
|
|
98
|
+
startTime: number;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Timestamp when the gesture ended
|
|
102
|
+
*/
|
|
103
|
+
endTime: number;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Gesture duration in milliseconds
|
|
107
|
+
*/
|
|
108
|
+
duration: number;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Whether default behavior was prevented
|
|
112
|
+
*/
|
|
113
|
+
defaultPrevented: boolean;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Prevent default behavior
|
|
117
|
+
*/
|
|
118
|
+
preventDefault: () => void;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Stop event propagation
|
|
122
|
+
*/
|
|
123
|
+
stopPropagation: () => void;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Tap gesture event data
|
|
128
|
+
*/
|
|
129
|
+
export interface TapEvent extends GestureEvent {
|
|
130
|
+
type: 'tap';
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Number of taps (for double tap detection)
|
|
134
|
+
*/
|
|
135
|
+
count: number;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* X position of the tap
|
|
139
|
+
*/
|
|
140
|
+
x: number;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Y position of the tap
|
|
144
|
+
*/
|
|
145
|
+
y: number;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Swipe gesture event data
|
|
150
|
+
*/
|
|
151
|
+
export interface SwipeEvent extends GestureEvent {
|
|
152
|
+
type: 'swipe' | 'swipeleft' | 'swiperight' | 'swipeup' | 'swipedown';
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Direction of the swipe
|
|
156
|
+
*/
|
|
157
|
+
direction: 'up' | 'down' | 'left' | 'right';
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Distance swiped in the X direction
|
|
161
|
+
*/
|
|
162
|
+
deltaX: number;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Distance swiped in the Y direction
|
|
166
|
+
*/
|
|
167
|
+
deltaY: number;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Total distance swiped
|
|
171
|
+
*/
|
|
172
|
+
distance: number;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Velocity of the swipe in pixels per millisecond
|
|
176
|
+
*/
|
|
177
|
+
velocity: number;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Start X position
|
|
181
|
+
*/
|
|
182
|
+
startX: number;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Start Y position
|
|
186
|
+
*/
|
|
187
|
+
startY: number;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* End X position
|
|
191
|
+
*/
|
|
192
|
+
endX: number;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* End Y position
|
|
196
|
+
*/
|
|
197
|
+
endY: number;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Long press gesture event data
|
|
202
|
+
*/
|
|
203
|
+
export interface LongPressEvent extends GestureEvent {
|
|
204
|
+
type: 'longpress';
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* X position of the long press
|
|
208
|
+
*/
|
|
209
|
+
x: number;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Y position of the long press
|
|
213
|
+
*/
|
|
214
|
+
y: number;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Pinch gesture event data
|
|
219
|
+
*/
|
|
220
|
+
export interface PinchEvent extends GestureEvent {
|
|
221
|
+
type: 'pinch';
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Scale factor of the pinch (>1 for zoom in, <1 for zoom out)
|
|
225
|
+
*/
|
|
226
|
+
scale: number;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Center X position of the pinch
|
|
230
|
+
*/
|
|
231
|
+
centerX: number;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Center Y position of the pinch
|
|
235
|
+
*/
|
|
236
|
+
centerY: number;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Rotate gesture event data
|
|
241
|
+
*/
|
|
242
|
+
export interface RotateEvent extends GestureEvent {
|
|
243
|
+
type: 'rotate';
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Rotation angle in degrees
|
|
247
|
+
*/
|
|
248
|
+
rotation: number;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Center X position of the rotation
|
|
252
|
+
*/
|
|
253
|
+
centerX: number;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Center Y position of the rotation
|
|
257
|
+
*/
|
|
258
|
+
centerY: number;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Pan gesture event data
|
|
263
|
+
*/
|
|
264
|
+
export interface PanEvent extends GestureEvent {
|
|
265
|
+
type: 'pan';
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Distance panned in the X direction
|
|
269
|
+
*/
|
|
270
|
+
deltaX: number;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Distance panned in the Y direction
|
|
274
|
+
*/
|
|
275
|
+
deltaY: number;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Start X position
|
|
279
|
+
*/
|
|
280
|
+
startX: number;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Start Y position
|
|
284
|
+
*/
|
|
285
|
+
startY: number;
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Current X position
|
|
289
|
+
*/
|
|
290
|
+
currentX: number;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Current Y position
|
|
294
|
+
*/
|
|
295
|
+
currentY: number;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Union type of all gesture events
|
|
300
|
+
*/
|
|
301
|
+
export type AnyGestureEvent =
|
|
302
|
+
| TapEvent
|
|
303
|
+
| SwipeEvent
|
|
304
|
+
| LongPressEvent
|
|
305
|
+
| PinchEvent
|
|
306
|
+
| RotateEvent
|
|
307
|
+
| PanEvent;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Handler for gesture events
|
|
311
|
+
*/
|
|
312
|
+
export type GestureHandler = (event: AnyGestureEvent) => void;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Gesture state for tracking touch interactions
|
|
316
|
+
*/
|
|
317
|
+
export interface GestureState {
|
|
318
|
+
active: boolean;
|
|
319
|
+
startTime: number;
|
|
320
|
+
startX: number;
|
|
321
|
+
startY: number;
|
|
322
|
+
lastX: number;
|
|
323
|
+
lastY: number;
|
|
324
|
+
currentX: number;
|
|
325
|
+
currentY: number;
|
|
326
|
+
touchCount: number;
|
|
327
|
+
longPressTimer: number | null;
|
|
328
|
+
startDistance: number;
|
|
329
|
+
startAngle: number;
|
|
330
|
+
lastTapTime: number;
|
|
331
|
+
tapCount: number;
|
|
332
|
+
target: EventTarget | null;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Context for gesture detection
|
|
337
|
+
*/
|
|
338
|
+
export interface GestureDetectionContext {
|
|
339
|
+
state: GestureState;
|
|
340
|
+
options: Required<GestureConfig>;
|
|
341
|
+
originalEvent: Event;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Gesture manager interface
|
|
346
|
+
*/
|
|
347
|
+
export interface GestureManager {
|
|
348
|
+
/**
|
|
349
|
+
* Add an event listener for a gesture
|
|
350
|
+
* @param eventType - Gesture type
|
|
351
|
+
* @param handler - Event handler
|
|
352
|
+
* @returns Gesture manager for chaining
|
|
353
|
+
*/
|
|
354
|
+
on: (eventType: string, handler: GestureHandler) => GestureManager;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Remove an event listener for a gesture
|
|
358
|
+
* @param eventType - Gesture type
|
|
359
|
+
* @param handler - Event handler
|
|
360
|
+
* @returns Gesture manager for chaining
|
|
361
|
+
*/
|
|
362
|
+
off: (eventType: string, handler: GestureHandler) => GestureManager;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Check if a gesture is supported on the current device
|
|
366
|
+
* @param gestureType - Type of gesture to check
|
|
367
|
+
* @returns Whether the gesture is supported
|
|
368
|
+
*/
|
|
369
|
+
isSupported: (gestureType: string) => boolean;
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Enable gesture recognition
|
|
373
|
+
* @returns Gesture manager for chaining
|
|
374
|
+
*/
|
|
375
|
+
enable: () => GestureManager;
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Disable gesture recognition
|
|
379
|
+
* @returns Gesture manager for chaining
|
|
380
|
+
*/
|
|
381
|
+
disable: () => GestureManager;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Clean up event listeners
|
|
385
|
+
*/
|
|
386
|
+
destroy: () => void;
|
|
387
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// src/core/gestures/utils.ts
|
|
2
|
+
/**
|
|
3
|
+
* @module core/gestures
|
|
4
|
+
* @description Utility functions for gesture detection
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { GestureEvent, GestureState } from "./types";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Calculate distance between two points
|
|
11
|
+
*
|
|
12
|
+
* @param x1 - X coordinate of first point
|
|
13
|
+
* @param y1 - Y coordinate of first point
|
|
14
|
+
* @param x2 - X coordinate of second point
|
|
15
|
+
* @param y2 - Y coordinate of second point
|
|
16
|
+
* @returns Distance between the points
|
|
17
|
+
*/
|
|
18
|
+
export function getDistance(
|
|
19
|
+
x1: number,
|
|
20
|
+
y1: number,
|
|
21
|
+
x2: number,
|
|
22
|
+
y2: number
|
|
23
|
+
): number {
|
|
24
|
+
return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Calculate angle between two points in degrees (0-360)
|
|
29
|
+
*
|
|
30
|
+
* @param x1 - X coordinate of first point
|
|
31
|
+
* @param y1 - Y coordinate of first point
|
|
32
|
+
* @param x2 - X coordinate of second point
|
|
33
|
+
* @param y2 - Y coordinate of second point
|
|
34
|
+
* @returns Angle in degrees
|
|
35
|
+
*/
|
|
36
|
+
export function getAngle(
|
|
37
|
+
x1: number,
|
|
38
|
+
y1: number,
|
|
39
|
+
x2: number,
|
|
40
|
+
y2: number
|
|
41
|
+
): number {
|
|
42
|
+
const angle = (Math.atan2(y2 - y1, x2 - x1) * 180) / Math.PI;
|
|
43
|
+
return angle < 0 ? angle + 360 : angle;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create a base gesture event
|
|
48
|
+
*
|
|
49
|
+
* @param type - Type of gesture
|
|
50
|
+
* @param originalEvent - Original DOM event
|
|
51
|
+
* @param state - Current gesture state
|
|
52
|
+
* @returns Base gesture event object
|
|
53
|
+
*/
|
|
54
|
+
export function createGestureEvent(
|
|
55
|
+
type: string,
|
|
56
|
+
originalEvent: Event,
|
|
57
|
+
state: GestureState
|
|
58
|
+
): GestureEvent {
|
|
59
|
+
const endTime = Date.now();
|
|
60
|
+
let defaultPrevented = false;
|
|
61
|
+
|
|
62
|
+
const event: GestureEvent = {
|
|
63
|
+
type,
|
|
64
|
+
originalEvent,
|
|
65
|
+
target:
|
|
66
|
+
(state.target as EventTarget) || (originalEvent.target as EventTarget),
|
|
67
|
+
startTime: state.startTime,
|
|
68
|
+
endTime,
|
|
69
|
+
duration: endTime - state.startTime,
|
|
70
|
+
defaultPrevented,
|
|
71
|
+
preventDefault: () => {
|
|
72
|
+
defaultPrevented = true;
|
|
73
|
+
event.defaultPrevented = true;
|
|
74
|
+
if (originalEvent.cancelable) {
|
|
75
|
+
originalEvent.preventDefault();
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
stopPropagation: () => {
|
|
79
|
+
originalEvent.stopPropagation();
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return event;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Detect if the device supports touch events
|
|
88
|
+
*
|
|
89
|
+
* @returns Whether touch is supported
|
|
90
|
+
*/
|
|
91
|
+
export function hasTouchSupport(): boolean {
|
|
92
|
+
const maxPoints = (navigator as any).maxTouchPoints;
|
|
93
|
+
return (
|
|
94
|
+
"ontouchstart" in window || (typeof maxPoints === "number" && maxPoints > 0)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Detect if the device supports pointer events
|
|
100
|
+
*
|
|
101
|
+
* @returns Whether pointer events are supported
|
|
102
|
+
*/
|
|
103
|
+
export function hasPointerSupport(): boolean {
|
|
104
|
+
return !!window.PointerEvent;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Extract normalized touch coordinates from an event
|
|
109
|
+
* Works with mouse events, touch events and pointer events
|
|
110
|
+
*
|
|
111
|
+
* @param e - DOM event
|
|
112
|
+
* @returns Object with clientX and clientY coordinates
|
|
113
|
+
*/
|
|
114
|
+
export function getTouchCoordinates(
|
|
115
|
+
e: MouseEvent | TouchEvent | PointerEvent
|
|
116
|
+
): { clientX: number; clientY: number } {
|
|
117
|
+
if ("touches" in e && Array.isArray(e.touches) && e.touches.length > 0) {
|
|
118
|
+
return {
|
|
119
|
+
clientX: e.touches[0].clientX,
|
|
120
|
+
clientY: e.touches[0].clientY,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
clientX: (e as MouseEvent | PointerEvent).clientX,
|
|
126
|
+
clientY: (e as MouseEvent | PointerEvent).clientY,
|
|
127
|
+
};
|
|
128
|
+
}
|
package/src/core/index.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Core Module Exports
|
|
3
|
+
*
|
|
4
|
+
* Central export point for all core functionality
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
export { createCollection, createDataCollection } from "./collection";
|
|
8
|
-
export type { Collection, DataCollection } from "./collection";
|
|
7
|
+
export * from "./compose";
|
|
9
8
|
|
|
10
9
|
// Layout system
|
|
11
10
|
export {
|
|
@@ -13,155 +12,32 @@ export {
|
|
|
13
12
|
applyLayoutClasses,
|
|
14
13
|
cleanupLayoutClasses,
|
|
15
14
|
} from "./layout";
|
|
16
|
-
export type {
|
|
15
|
+
export type { LayoutConfig } from "./layout/types";
|
|
17
16
|
|
|
18
|
-
//
|
|
19
|
-
export {
|
|
20
|
-
createListManager,
|
|
21
|
-
createCustomListManager,
|
|
22
|
-
withViewport,
|
|
23
|
-
withCollection,
|
|
24
|
-
withPlaceholders,
|
|
25
|
-
} from "./list-manager";
|
|
26
|
-
|
|
27
|
-
// Compose system
|
|
28
|
-
export {
|
|
29
|
-
pipe,
|
|
30
|
-
createBase,
|
|
31
|
-
withElement,
|
|
32
|
-
withEvents,
|
|
33
|
-
withLifecycle,
|
|
34
|
-
withCollection as withCompose,
|
|
35
|
-
withStyling,
|
|
36
|
-
withSelection,
|
|
37
|
-
withPerformance,
|
|
38
|
-
} from "./compose";
|
|
39
|
-
|
|
40
|
-
// Types
|
|
17
|
+
// Viewport system
|
|
18
|
+
export { createViewport } from "./viewport";
|
|
41
19
|
export type {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
ViewportFeature,
|
|
46
|
-
CollectionFeature,
|
|
20
|
+
ViewportConfig,
|
|
21
|
+
ViewportComponent,
|
|
22
|
+
ViewportContext,
|
|
47
23
|
ItemRange,
|
|
48
24
|
ViewportInfo,
|
|
49
|
-
|
|
50
|
-
} from "./list-manager/types";
|
|
51
|
-
|
|
52
|
-
export type {
|
|
53
|
-
CollectionConfig,
|
|
54
|
-
CollectionComponent,
|
|
55
|
-
StylingConfig,
|
|
56
|
-
StylingComponent,
|
|
57
|
-
SelectionConfig,
|
|
58
|
-
SelectionComponent,
|
|
59
|
-
SelectableItem,
|
|
60
|
-
PerformanceConfig,
|
|
61
|
-
PerformanceComponent,
|
|
62
|
-
PerformanceMetrics,
|
|
63
|
-
} from "./compose/features";
|
|
25
|
+
} from "./viewport/types";
|
|
64
26
|
|
|
65
|
-
|
|
66
|
-
export
|
|
67
|
-
export type { PlaceholdersComponent } from "./list-manager/features/viewport";
|
|
68
|
-
|
|
69
|
-
export type { ViewportConfig } from "./list-manager/features/viewport";
|
|
70
|
-
export type { CollectionConfig as CollectionEnhancerConfig } from "./list-manager/features/collection";
|
|
71
|
-
export type { PlaceholdersConfig } from "./list-manager/features/viewport";
|
|
72
|
-
|
|
73
|
-
// Configuration types
|
|
74
|
-
export type { Collection as CollectionInterface } from "./collection";
|
|
75
|
-
export type { Layout as LayoutInterface } from "./layout";
|
|
76
|
-
|
|
77
|
-
// Collection types
|
|
27
|
+
// Gesture system
|
|
28
|
+
export { createGestureManager } from "./gestures";
|
|
78
29
|
export type {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
CollectionDestroyConfig,
|
|
94
|
-
CollectionSetItemsConfig,
|
|
95
|
-
CollectionSetTotalItemsConfig,
|
|
96
|
-
CollectionSetLoadingConfig,
|
|
97
|
-
CollectionSetErrorConfig,
|
|
98
|
-
CollectionSetCacheConfig,
|
|
99
|
-
CollectionSetEventHandlersConfig,
|
|
100
|
-
CollectionGetItemsConfig,
|
|
101
|
-
CollectionGetTotalItemsConfig,
|
|
102
|
-
CollectionGetLoadingConfig,
|
|
103
|
-
CollectionGetErrorConfig,
|
|
104
|
-
CollectionGetCacheConfig,
|
|
105
|
-
CollectionGetEventHandlersConfig,
|
|
106
|
-
CollectionLoadConfig,
|
|
107
|
-
CollectionLoadMoreConfig,
|
|
108
|
-
CollectionReloadConfig,
|
|
109
|
-
CollectionUpdateItemConfig,
|
|
110
|
-
CollectionUpdateItemsConfig,
|
|
111
|
-
CollectionUpdateTotalItemsConfig,
|
|
112
|
-
CollectionUpdateLoadingConfig,
|
|
113
|
-
CollectionUpdateErrorConfig,
|
|
114
|
-
CollectionUpdateCacheConfig,
|
|
115
|
-
CollectionUpdateEventHandlersConfig,
|
|
116
|
-
CollectionClearConfig,
|
|
117
|
-
CollectionClearCacheConfig,
|
|
118
|
-
CollectionClearItemsConfig,
|
|
119
|
-
CollectionClearErrorConfig,
|
|
120
|
-
CollectionClearLoadingConfig,
|
|
121
|
-
CollectionClearEventHandlersConfig,
|
|
122
|
-
CollectionDestroyAllConfig,
|
|
123
|
-
CollectionDestroyAllCacheConfig,
|
|
124
|
-
CollectionDestroyAllItemsConfig,
|
|
125
|
-
CollectionDestroyAllErrorConfig,
|
|
126
|
-
CollectionDestroyAllLoadingConfig,
|
|
127
|
-
CollectionDestroyAllEventHandlersConfig,
|
|
128
|
-
} from "./collection";
|
|
129
|
-
|
|
130
|
-
// Layout types
|
|
131
|
-
export type {
|
|
132
|
-
LayoutData,
|
|
133
|
-
LayoutElement,
|
|
134
|
-
LayoutElementData,
|
|
135
|
-
LayoutArrayConfig,
|
|
136
|
-
LayoutConfig as LayoutTypeConfig,
|
|
137
|
-
LayoutCreateConfig,
|
|
138
|
-
LayoutUpdateConfig,
|
|
139
|
-
LayoutDestroyConfig,
|
|
140
|
-
LayoutSetDataConfig,
|
|
141
|
-
LayoutSetElementConfig,
|
|
142
|
-
LayoutSetElementDataConfig,
|
|
143
|
-
LayoutSetArrayConfig,
|
|
144
|
-
LayoutSetConfigConfig,
|
|
145
|
-
LayoutGetDataConfig,
|
|
146
|
-
LayoutGetElementConfig,
|
|
147
|
-
LayoutGetElementDataConfig,
|
|
148
|
-
LayoutGetArrayConfig,
|
|
149
|
-
LayoutGetConfigConfig,
|
|
150
|
-
LayoutRenderConfig,
|
|
151
|
-
LayoutRenderElementConfig,
|
|
152
|
-
LayoutRenderElementDataConfig,
|
|
153
|
-
LayoutRenderArrayConfig,
|
|
154
|
-
LayoutRenderConfigConfig,
|
|
155
|
-
LayoutClearConfig,
|
|
156
|
-
LayoutClearDataConfig,
|
|
157
|
-
LayoutClearElementConfig,
|
|
158
|
-
LayoutClearElementDataConfig,
|
|
159
|
-
LayoutClearArrayConfig,
|
|
160
|
-
LayoutClearConfigConfig,
|
|
161
|
-
LayoutDestroyAllConfig,
|
|
162
|
-
LayoutDestroyAllDataConfig,
|
|
163
|
-
LayoutDestroyAllElementConfig,
|
|
164
|
-
LayoutDestroyAllElementDataConfig,
|
|
165
|
-
LayoutDestroyAllArrayConfig,
|
|
166
|
-
LayoutDestroyAllConfigConfig,
|
|
167
|
-
} from "./layout";
|
|
30
|
+
GestureManager,
|
|
31
|
+
GestureConfig,
|
|
32
|
+
GestureEvent,
|
|
33
|
+
TapEvent,
|
|
34
|
+
SwipeEvent,
|
|
35
|
+
LongPressEvent,
|
|
36
|
+
PinchEvent,
|
|
37
|
+
RotateEvent,
|
|
38
|
+
PanEvent,
|
|
39
|
+
AnyGestureEvent,
|
|
40
|
+
GestureHandler,
|
|
41
|
+
} from "./gestures";
|
|
42
|
+
|
|
43
|
+
export * from "./compose";
|