mtrl-addons 0.2.2 → 0.2.4

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 (129) hide show
  1. package/{src/components/index.ts → dist/components/index.d.ts} +0 -2
  2. package/dist/components/vlist/config.d.ts +86 -0
  3. package/{src/components/vlist/constants.ts → dist/components/vlist/constants.d.ts} +10 -11
  4. package/dist/components/vlist/features/api.d.ts +7 -0
  5. package/{src/components/vlist/features/index.ts → dist/components/vlist/features/index.d.ts} +0 -2
  6. package/dist/components/vlist/features/selection.d.ts +6 -0
  7. package/dist/components/vlist/features/viewport.d.ts +9 -0
  8. package/dist/components/vlist/features.d.ts +31 -0
  9. package/{src/components/vlist/index.ts → dist/components/vlist/index.d.ts} +1 -10
  10. package/dist/components/vlist/types.d.ts +596 -0
  11. package/dist/components/vlist/vlist.d.ts +29 -0
  12. package/dist/core/compose/features/gestures/index.d.ts +86 -0
  13. package/dist/core/compose/features/gestures/longpress.d.ts +85 -0
  14. package/dist/core/compose/features/gestures/pan.d.ts +108 -0
  15. package/dist/core/compose/features/gestures/pinch.d.ts +111 -0
  16. package/dist/core/compose/features/gestures/rotate.d.ts +111 -0
  17. package/dist/core/compose/features/gestures/swipe.d.ts +149 -0
  18. package/dist/core/compose/features/gestures/tap.d.ts +79 -0
  19. package/{src/core/compose/features/index.ts → dist/core/compose/features/index.d.ts} +1 -2
  20. package/{src/core/compose/index.ts → dist/core/compose/index.d.ts} +2 -11
  21. package/{src/core/gestures/index.ts → dist/core/gestures/index.d.ts} +1 -20
  22. package/dist/core/gestures/longpress.d.ts +23 -0
  23. package/dist/core/gestures/manager.d.ts +14 -0
  24. package/dist/core/gestures/pan.d.ts +12 -0
  25. package/dist/core/gestures/pinch.d.ts +14 -0
  26. package/dist/core/gestures/rotate.d.ts +14 -0
  27. package/dist/core/gestures/swipe.d.ts +20 -0
  28. package/dist/core/gestures/tap.d.ts +12 -0
  29. package/dist/core/gestures/types.d.ts +320 -0
  30. package/dist/core/gestures/utils.d.ts +57 -0
  31. package/dist/core/index.d.ts +13 -0
  32. package/dist/core/layout/config.d.ts +33 -0
  33. package/dist/core/layout/index.d.ts +51 -0
  34. package/dist/core/layout/jsx.d.ts +65 -0
  35. package/dist/core/layout/schema.d.ts +112 -0
  36. package/dist/core/layout/types.d.ts +69 -0
  37. package/dist/core/viewport/constants.d.ts +105 -0
  38. package/dist/core/viewport/features/base.d.ts +14 -0
  39. package/dist/core/viewport/features/collection.d.ts +41 -0
  40. package/dist/core/viewport/features/events.d.ts +13 -0
  41. package/{src/core/viewport/features/index.ts → dist/core/viewport/features/index.d.ts} +0 -7
  42. package/dist/core/viewport/features/item-size.d.ts +30 -0
  43. package/dist/core/viewport/features/loading.d.ts +34 -0
  44. package/dist/core/viewport/features/momentum.d.ts +17 -0
  45. package/dist/core/viewport/features/performance.d.ts +53 -0
  46. package/dist/core/viewport/features/placeholders.d.ts +38 -0
  47. package/dist/core/viewport/features/rendering.d.ts +16 -0
  48. package/dist/core/viewport/features/scrollbar.d.ts +26 -0
  49. package/dist/core/viewport/features/scrolling.d.ts +16 -0
  50. package/dist/core/viewport/features/utils.d.ts +43 -0
  51. package/dist/core/viewport/features/virtual.d.ts +18 -0
  52. package/{src/core/viewport/index.ts → dist/core/viewport/index.d.ts} +1 -17
  53. package/dist/core/viewport/types.d.ts +96 -0
  54. package/dist/core/viewport/utils/speed-tracker.d.ts +22 -0
  55. package/dist/core/viewport/viewport.d.ts +11 -0
  56. package/{src/index.ts → dist/index.d.ts} +0 -4
  57. package/dist/index.js +5143 -0
  58. package/dist/index.mjs +5111 -0
  59. package/dist/styles.css +254 -0
  60. package/dist/styles.css.map +1 -0
  61. package/package.json +16 -2
  62. package/.cursorrules +0 -117
  63. package/AI.md +0 -39
  64. package/CLAUDE.md +0 -882
  65. package/build.js +0 -377
  66. package/index.ts +0 -7
  67. package/scripts/analyze-orphaned-functions.ts +0 -387
  68. package/scripts/debug/vlist-selection.ts +0 -121
  69. package/src/components/vlist/config.ts +0 -323
  70. package/src/components/vlist/features/api.ts +0 -626
  71. package/src/components/vlist/features/selection.ts +0 -436
  72. package/src/components/vlist/features/viewport.ts +0 -59
  73. package/src/components/vlist/features.ts +0 -112
  74. package/src/components/vlist/types.ts +0 -723
  75. package/src/components/vlist/vlist.ts +0 -92
  76. package/src/core/compose/features/gestures/index.ts +0 -227
  77. package/src/core/compose/features/gestures/longpress.ts +0 -383
  78. package/src/core/compose/features/gestures/pan.ts +0 -424
  79. package/src/core/compose/features/gestures/pinch.ts +0 -475
  80. package/src/core/compose/features/gestures/rotate.ts +0 -485
  81. package/src/core/compose/features/gestures/swipe.ts +0 -492
  82. package/src/core/compose/features/gestures/tap.ts +0 -334
  83. package/src/core/gestures/longpress.ts +0 -68
  84. package/src/core/gestures/manager.ts +0 -418
  85. package/src/core/gestures/pan.ts +0 -48
  86. package/src/core/gestures/pinch.ts +0 -58
  87. package/src/core/gestures/rotate.ts +0 -58
  88. package/src/core/gestures/swipe.ts +0 -66
  89. package/src/core/gestures/tap.ts +0 -45
  90. package/src/core/gestures/types.ts +0 -387
  91. package/src/core/gestures/utils.ts +0 -128
  92. package/src/core/index.ts +0 -43
  93. package/src/core/layout/config.ts +0 -102
  94. package/src/core/layout/index.ts +0 -168
  95. package/src/core/layout/jsx.ts +0 -174
  96. package/src/core/layout/schema.ts +0 -1044
  97. package/src/core/layout/types.ts +0 -95
  98. package/src/core/viewport/constants.ts +0 -145
  99. package/src/core/viewport/features/base.ts +0 -73
  100. package/src/core/viewport/features/collection.ts +0 -1182
  101. package/src/core/viewport/features/events.ts +0 -130
  102. package/src/core/viewport/features/item-size.ts +0 -271
  103. package/src/core/viewport/features/loading.ts +0 -263
  104. package/src/core/viewport/features/momentum.ts +0 -269
  105. package/src/core/viewport/features/performance.ts +0 -161
  106. package/src/core/viewport/features/placeholders.ts +0 -335
  107. package/src/core/viewport/features/rendering.ts +0 -962
  108. package/src/core/viewport/features/scrollbar.ts +0 -434
  109. package/src/core/viewport/features/scrolling.ts +0 -634
  110. package/src/core/viewport/features/utils.ts +0 -94
  111. package/src/core/viewport/features/virtual.ts +0 -525
  112. package/src/core/viewport/types.ts +0 -133
  113. package/src/core/viewport/utils/speed-tracker.ts +0 -79
  114. package/src/core/viewport/viewport.ts +0 -265
  115. package/test/benchmarks/layout/advanced.test.ts +0 -656
  116. package/test/benchmarks/layout/comparison.test.ts +0 -519
  117. package/test/benchmarks/layout/performance-comparison.test.ts +0 -274
  118. package/test/benchmarks/layout/real-components.test.ts +0 -733
  119. package/test/benchmarks/layout/simple.test.ts +0 -321
  120. package/test/benchmarks/layout/stress.test.ts +0 -990
  121. package/test/collection/basic.test.ts +0 -304
  122. package/test/components/vlist-selection.test.ts +0 -240
  123. package/test/components/vlist.test.ts +0 -63
  124. package/test/core/collection/adapter.test.ts +0 -161
  125. package/test/core/collection/collection.test.ts +0 -394
  126. package/test/core/layout/layout.test.ts +0 -201
  127. package/test/utils/dom-helpers.ts +0 -275
  128. package/test/utils/performance-helpers.ts +0 -392
  129. package/tsconfig.json +0 -20
@@ -1,424 +0,0 @@
1
- // src/core/compose/features/gestures/pan.ts
2
- /**
3
- * @module core/compose/features/gestures
4
- * @description Adds pan gesture recognition to components
5
- */
6
-
7
- import type { BaseComponent, ElementComponent } from "mtrl";
8
- import { PanEvent, GestureHandler } from "../../../gestures";
9
- import { hasLifecycle, hasEmit } from "mtrl";
10
-
11
- /**
12
- * Configuration for pan gesture feature
13
- */
14
- export interface PanGestureConfig {
15
- /**
16
- * Whether to prevent default behaviors on touch events
17
- * @default true
18
- */
19
- preventDefault?: boolean;
20
-
21
- /**
22
- * Handler for pan start (first movement)
23
- */
24
- onPanStart?: GestureHandler;
25
-
26
- /**
27
- * Handler for pan move (continuous updates during pan)
28
- */
29
- onPan?: GestureHandler;
30
-
31
- /**
32
- * Handler for pan end (touch/mouse release)
33
- */
34
- onPanEnd?: GestureHandler;
35
-
36
- /**
37
- * Whether to enable pan recognition immediately
38
- * @default true
39
- */
40
- enabled?: boolean;
41
-
42
- [key: string]: any;
43
- }
44
-
45
- /**
46
- * Extend the PanEvent interface to support our custom event types
47
- */
48
- interface ExtendedPanEvent extends Omit<PanEvent, "type"> {
49
- type: "pan" | "panstart" | "panend";
50
- }
51
-
52
- /**
53
- * Component with pan gesture recognition capabilities
54
- */
55
- export interface PanGestureComponent extends BaseComponent {
56
- /**
57
- * Add a handler for pan start
58
- * @param handler - Event handler function
59
- * @returns Component for chaining
60
- */
61
- onPanStart: (handler: (event: PanEvent) => void) => PanGestureComponent;
62
-
63
- /**
64
- * Add a handler for pan move (continuous updates)
65
- * @param handler - Event handler function
66
- * @returns Component for chaining
67
- */
68
- onPan: (handler: (event: PanEvent) => void) => PanGestureComponent;
69
-
70
- /**
71
- * Add a handler for pan end
72
- * @param handler - Event handler function
73
- * @returns Component for chaining
74
- */
75
- onPanEnd: (handler: (event: PanEvent) => void) => PanGestureComponent;
76
-
77
- /**
78
- * Remove a pan start handler
79
- * @param handler - Event handler function
80
- * @returns Component for chaining
81
- */
82
- offPanStart: (handler: (event: PanEvent) => void) => PanGestureComponent;
83
-
84
- /**
85
- * Remove a pan move handler
86
- * @param handler - Event handler function
87
- * @returns Component for chaining
88
- */
89
- offPan: (handler: (event: PanEvent) => void) => PanGestureComponent;
90
-
91
- /**
92
- * Remove a pan end handler
93
- * @param handler - Event handler function
94
- * @returns Component for chaining
95
- */
96
- offPanEnd: (handler: (event: PanEvent) => void) => PanGestureComponent;
97
-
98
- /**
99
- * Enable pan recognition
100
- * @returns Component for chaining
101
- */
102
- enablePan: () => PanGestureComponent;
103
-
104
- /**
105
- * Disable pan recognition
106
- * @returns Component for chaining
107
- */
108
- disablePan: () => PanGestureComponent;
109
- }
110
-
111
- /**
112
- * Adds pan gesture recognition to a component.
113
- * This is a lightweight alternative to the full gesture system,
114
- * focused only on pan detection.
115
- *
116
- * @param config - Configuration object containing pan settings
117
- * @returns Function that enhances a component with pan capabilities
118
- *
119
- * @example
120
- * ```ts
121
- * // Add pan gesture recognition to a component
122
- * const component = pipe(
123
- * createBase,
124
- * withElement(...),
125
- * withPanGesture({
126
- * onPanStart: (e) => startDrag(e),
127
- * onPan: (e) => updateDragPosition(e),
128
- * onPanEnd: (e) => endDrag(e)
129
- * })
130
- * )(config);
131
- * ```
132
- */
133
- export const withPanGesture =
134
- (config: PanGestureConfig = {}) =>
135
- <C extends ElementComponent>(component: C): C & PanGestureComponent => {
136
- if (!component.element) {
137
- console.warn("Cannot add pan gesture recognition: missing element");
138
- return component as C & PanGestureComponent;
139
- }
140
-
141
- // Default configuration
142
- const {
143
- preventDefault = true,
144
- onPanStart,
145
- onPan,
146
- onPanEnd,
147
- enabled = true,
148
- } = config;
149
-
150
- // Event handlers storage by pan phase
151
- const handlers = {
152
- panstart: new Set<(event: PanEvent) => void>(),
153
- pan: new Set<(event: PanEvent) => void>(),
154
- panend: new Set<(event: PanEvent) => void>(),
155
- };
156
-
157
- // Add initial handlers if provided
158
- if (onPanStart)
159
- handlers.panstart.add(onPanStart as (event: PanEvent) => void);
160
- if (onPan) handlers.pan.add(onPan as (event: PanEvent) => void);
161
- if (onPanEnd) handlers.panend.add(onPanEnd as (event: PanEvent) => void);
162
-
163
- // Gesture state for tracking
164
- let startX = 0;
165
- let startY = 0;
166
- let lastX = 0;
167
- let lastY = 0;
168
- let currentX = 0;
169
- let currentY = 0;
170
- let active = false;
171
- let isPanning = false;
172
- let startTime = 0;
173
- let isEnabled = enabled;
174
-
175
- /**
176
- * Create a pan event with the current state
177
- */
178
- const createPanEvent = (
179
- e: MouseEvent | TouchEvent,
180
- type: "panstart" | "pan" | "panend"
181
- ): ExtendedPanEvent => {
182
- const event: ExtendedPanEvent = {
183
- type,
184
- originalEvent: e,
185
- target: e.target!,
186
- startTime,
187
- endTime: Date.now(),
188
- duration: Date.now() - startTime,
189
- defaultPrevented: false,
190
- preventDefault: () => {
191
- event.defaultPrevented = true;
192
- if (e.cancelable) {
193
- e.preventDefault();
194
- }
195
- },
196
- stopPropagation: () => {
197
- e.stopPropagation();
198
- },
199
- deltaX: currentX - startX,
200
- deltaY: currentY - startY,
201
- startX,
202
- startY,
203
- currentX,
204
- currentY,
205
- };
206
- return event;
207
- };
208
-
209
- /**
210
- * Dispatch a pan event to all registered handlers
211
- */
212
- const dispatchPan = (
213
- e: MouseEvent | TouchEvent,
214
- type: "panstart" | "pan" | "panend"
215
- ): void => {
216
- const extendedPanEvent = createPanEvent(e, type);
217
-
218
- // Call each handler for this phase
219
- handlers[type].forEach((handler) => {
220
- try {
221
- // Type assertion for the handler call - we're deliberately passing our extended event
222
- handler(extendedPanEvent as unknown as PanEvent);
223
- } catch (error) {
224
- console.error(`Error in ${type} handler:`, error);
225
- }
226
- });
227
-
228
- // Forward to component's event system if available
229
- if (hasEmit(component)) {
230
- component.emit(type, extendedPanEvent);
231
- }
232
-
233
- // Apply preventDefault if configured
234
- if (preventDefault && !extendedPanEvent.defaultPrevented) {
235
- extendedPanEvent.preventDefault();
236
- }
237
- };
238
-
239
- /**
240
- * Handle touch/mouse start
241
- */
242
- const handleStart = (e: MouseEvent | TouchEvent): void => {
243
- if (!isEnabled) return;
244
-
245
- const touch = "touches" in e ? e.touches[0] : e;
246
-
247
- startX = lastX = currentX = touch.clientX;
248
- startY = lastY = currentY = touch.clientY;
249
- startTime = Date.now();
250
- active = true;
251
- isPanning = false;
252
- };
253
-
254
- /**
255
- * Handle touch/mouse move
256
- */
257
- const handleMove = (e: MouseEvent | TouchEvent): void => {
258
- if (!active || !isEnabled) return;
259
-
260
- const touch = "touches" in e ? e.touches[0] : e;
261
-
262
- // Update position
263
- lastX = currentX;
264
- lastY = currentY;
265
- currentX = touch.clientX;
266
- currentY = touch.clientY;
267
-
268
- // Calculate movement delta
269
- const moveDeltaX = currentX - lastX;
270
- const moveDeltaY = currentY - lastY;
271
- const moveDelta = Math.sqrt(
272
- moveDeltaX * moveDeltaX + moveDeltaY * moveDeltaY
273
- );
274
-
275
- // Detect significant movement
276
- if (moveDelta > 0) {
277
- // If this is the first significant movement, trigger panstart
278
- if (!isPanning) {
279
- isPanning = true;
280
- dispatchPan(e, "panstart");
281
- }
282
-
283
- // Then trigger the continuous pan event
284
- dispatchPan(e, "pan");
285
- }
286
- };
287
-
288
- /**
289
- * Handle touch/mouse end
290
- */
291
- const handleEnd = (e: MouseEvent | TouchEvent): void => {
292
- if (!active || !isEnabled) return;
293
-
294
- // If we were panning, trigger the panend event
295
- if (isPanning) {
296
- dispatchPan(e, "panend");
297
- }
298
-
299
- active = false;
300
- isPanning = false;
301
- };
302
-
303
- /**
304
- * Handle touch/mouse cancel
305
- */
306
- const handleCancel = (e: MouseEvent | TouchEvent): void => {
307
- if (!active || !isEnabled) return;
308
-
309
- // If we were panning, trigger the panend event
310
- if (isPanning) {
311
- dispatchPan(e, "panend");
312
- }
313
-
314
- active = false;
315
- isPanning = false;
316
- };
317
-
318
- // Event listeners dictionary
319
- const eventListeners: Record<string, EventListener> = {
320
- mousedown: handleStart as EventListener,
321
- mousemove: handleMove as EventListener,
322
- mouseup: handleEnd as EventListener,
323
- mouseleave: handleCancel as EventListener,
324
- touchstart: handleStart as EventListener,
325
- touchmove: handleMove as EventListener,
326
- touchend: handleEnd as EventListener,
327
- touchcancel: handleCancel as EventListener,
328
- };
329
-
330
- /**
331
- * Add event listeners to element
332
- */
333
- const setupEventListeners = (): void => {
334
- Object.entries(eventListeners).forEach(([event, listener]) => {
335
- component.element.addEventListener(event, listener, {
336
- passive: !preventDefault,
337
- });
338
- });
339
- };
340
-
341
- /**
342
- * Remove event listeners from element
343
- */
344
- const removeEventListeners = (): void => {
345
- Object.entries(eventListeners).forEach(([event, listener]) => {
346
- component.element.removeEventListener(event, listener);
347
- });
348
- };
349
-
350
- // Setup listeners if initially enabled
351
- if (isEnabled) {
352
- setupEventListeners();
353
- }
354
-
355
- // Handle lifecycle integration
356
- if (hasLifecycle(component)) {
357
- const originalDestroy = component.lifecycle.destroy;
358
-
359
- component.lifecycle.destroy = () => {
360
- // Clean up event listeners
361
- removeEventListeners();
362
-
363
- // Clear handlers
364
- Object.values(handlers).forEach((handlerSet) => handlerSet.clear());
365
-
366
- // Call original destroy method
367
- originalDestroy.call(component.lifecycle);
368
- };
369
- }
370
-
371
- // Create enhanced component
372
- return {
373
- ...component,
374
-
375
- // Add handler methods
376
- onPanStart(handler: (event: PanEvent) => void) {
377
- handlers.panstart.add(handler);
378
- return this;
379
- },
380
-
381
- onPan(handler: (event: PanEvent) => void) {
382
- handlers.pan.add(handler);
383
- return this;
384
- },
385
-
386
- onPanEnd(handler: (event: PanEvent) => void) {
387
- handlers.panend.add(handler);
388
- return this;
389
- },
390
-
391
- // Remove handler methods
392
- offPanStart(handler: (event: PanEvent) => void) {
393
- handlers.panstart.delete(handler);
394
- return this;
395
- },
396
-
397
- offPan(handler: (event: PanEvent) => void) {
398
- handlers.pan.delete(handler);
399
- return this;
400
- },
401
-
402
- offPanEnd(handler: (event: PanEvent) => void) {
403
- handlers.panend.delete(handler);
404
- return this;
405
- },
406
-
407
- // Enable/disable methods
408
- enablePan() {
409
- if (!isEnabled) {
410
- isEnabled = true;
411
- setupEventListeners();
412
- }
413
- return this;
414
- },
415
-
416
- disablePan() {
417
- if (isEnabled) {
418
- isEnabled = false;
419
- removeEventListeners();
420
- }
421
- return this;
422
- },
423
- };
424
- };