@oxog/scrollex 1.0.3 → 1.1.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.
@@ -1,530 +1,6 @@
1
- /**
2
- * Represents a virtualized item with position and size information.
3
- */
4
- interface VirtualItem {
5
- /** Index of the item in the data array */
6
- index: number;
7
- /** Unique key for React reconciliation */
8
- key: string | number;
9
- /** Offset from the start of the scroll container (px) */
10
- start: number;
11
- /** End position (start + size) */
12
- end: number;
13
- /** Size of the item (height for vertical, width for horizontal) */
14
- size: number;
15
- /** Lane/column index for grid and masonry layouts */
16
- lane: number;
17
- }
18
- /**
19
- * Represents the visible range of items.
20
- */
21
- interface Range {
22
- /** First visible item index */
23
- startIndex: number;
24
- /** Last visible item index */
25
- endIndex: number;
26
- /** First rendered item index (including overscan) */
27
- overscanStartIndex: number;
28
- /** Last rendered item index (including overscan) */
29
- overscanEndIndex: number;
30
- /** Alias for startIndex */
31
- start?: number;
32
- /** Alias for endIndex */
33
- end?: number;
34
- }
35
- /**
36
- * Represents scroll position in both axes.
37
- */
38
- interface ScrollPosition {
39
- scrollTop: number;
40
- scrollLeft: number;
41
- /** Normalized offset (scrollTop for vertical, scrollLeft for horizontal) */
42
- offset?: number;
43
- /** Scroll percentage (0-1) */
44
- percentage?: number;
45
- }
46
- /**
47
- * Represents the viewport dimensions.
48
- */
49
- interface Viewport {
50
- /** Visible width of the container */
51
- width: number;
52
- /** Visible height of the container */
53
- height: number;
54
- /** Total scrollable height */
55
- scrollHeight: number;
56
- /** Total scrollable width */
57
- scrollWidth: number;
58
- }
59
- /**
60
- * Scroll direction.
61
- */
62
- type ScrollDirection = 'up' | 'down' | 'left' | 'right' | 'none';
63
- /**
64
- * Scroll behavior.
65
- */
66
- type ScrollBehavior = 'auto' | 'smooth';
67
- /**
68
- * Alignment options for scrollToIndex.
69
- */
70
- type ScrollAlignment = 'start' | 'center' | 'end' | 'auto';
71
- /**
72
- * Scroll event payload.
73
- */
74
- interface ScrollEvent {
75
- type: 'scroll';
76
- scrollTop: number;
77
- scrollLeft: number;
78
- deltaY: number;
79
- deltaX: number;
80
- direction: ScrollDirection;
81
- timestamp: number;
82
- }
83
- /**
84
- * Scroll start event payload.
85
- */
86
- interface ScrollStartEvent {
87
- type: 'scroll-start';
88
- scrollTop: number;
89
- scrollLeft: number;
90
- timestamp: number;
91
- }
92
- /**
93
- * Scroll end event payload.
94
- */
95
- interface ScrollEndEvent {
96
- type: 'scroll-end';
97
- scrollTop: number;
98
- scrollLeft: number;
99
- timestamp: number;
100
- }
101
- /**
102
- * Visible range change event payload.
103
- */
104
- interface VisibleRangeChangeEvent {
105
- type: 'visible-range-change';
106
- range: Range;
107
- previousRange: Range | null;
108
- }
109
- /**
110
- * Item measured event payload.
111
- */
112
- interface ItemMeasuredEvent {
113
- type: 'item-measured';
114
- index: number;
115
- height: number;
116
- previousHeight: number | undefined;
117
- }
118
- /**
119
- * Resize event payload.
120
- */
121
- interface ResizeEvent {
122
- type: 'resize';
123
- viewport: Viewport;
124
- previousViewport: Viewport | null;
125
- }
126
- /**
127
- * Load more event payload.
128
- */
129
- interface LoadMoreEvent {
130
- type: 'load-more';
131
- direction: 'forward' | 'backward';
132
- }
133
- /**
134
- * Items change event payload.
135
- */
136
- interface ItemsChangeEvent {
137
- type: 'items-change';
138
- count: number;
139
- previousCount: number;
140
- }
141
- /**
142
- * Union of all kernel events.
143
- */
144
- type KernelEvent = ScrollEvent | ScrollStartEvent | ScrollEndEvent | VisibleRangeChangeEvent | ItemMeasuredEvent | ResizeEvent | LoadMoreEvent | ItemsChangeEvent;
145
- /**
146
- * Event handler function type.
147
- */
148
- type EventHandler<T = KernelEvent> = (event: T) => void;
149
- /**
150
- * Unsubscribe function returned by event subscriptions.
151
- */
152
- type Unsubscribe = () => void;
153
- /**
154
- * Options for scroll operations.
155
- */
156
- interface ScrollOptions {
157
- /** Scroll behavior */
158
- behavior?: ScrollBehavior;
159
- /** Duration for smooth scroll (ms) */
160
- duration?: number;
161
- /** Easing function for smooth scroll */
162
- easing?: EasingFunction;
163
- }
164
- /**
165
- * Options for scrollToIndex operations.
166
- */
167
- interface ScrollToIndexOptions extends ScrollOptions {
168
- /** Alignment of the item in the viewport */
169
- align?: ScrollAlignment;
170
- /** Additional offset (px) */
171
- offset?: number;
172
- }
173
- /**
174
- * Easing function type.
175
- */
176
- type EasingFunction = (t: number) => number;
177
- /**
178
- * Plugin type - core plugins are always loaded, optional are loaded on demand.
179
- */
180
- type PluginType = 'core' | 'optional';
181
- /**
182
- * Plugin hooks interface.
183
- */
184
- interface PluginHooks {
185
- /** Called on scroll */
186
- onScroll?: (event: ScrollEvent) => void;
187
- /** Called when scroll starts */
188
- onScrollStart?: (event: ScrollStartEvent) => void;
189
- /** Called when scroll ends */
190
- onScrollEnd?: (event: ScrollEndEvent) => void;
191
- /** Called when visible range changes */
192
- onVisibleRangeChange?: (range: Range, previousRange: Range | null) => void;
193
- /** Called when an item is measured */
194
- onItemMeasured?: (index: number, height: number) => void;
195
- /** Called on viewport resize */
196
- onResize?: (viewport: Viewport) => void;
197
- /** Called when load more is triggered */
198
- onLoadMore?: (direction: 'forward' | 'backward') => void;
199
- /** Called when item count changes */
200
- onItemsChange?: (count: number, previousCount: number) => void;
201
- }
202
- /**
203
- * Plugin metadata.
204
- */
205
- interface PluginInfo {
206
- name: string;
207
- version: string;
208
- type: PluginType;
209
- enabled: boolean;
210
- }
211
- /**
212
- * Plugin interface.
213
- */
214
- interface Plugin {
215
- /** Unique plugin name */
216
- name: string;
217
- /** Plugin version */
218
- version: string;
219
- /** Plugin type (core or optional) */
220
- type: PluginType;
221
- /** Install plugin into kernel (required: the registry rejects a plugin without it) */
222
- install(kernel: Kernel): void;
223
- /** Uninstall plugin (required: the registry rejects a plugin without it) */
224
- uninstall(): void;
225
- /** Plugin hooks */
226
- hooks?: PluginHooks;
227
- /** Public API exposed by the plugin */
228
- api?: any;
229
- }
230
- /**
231
- * Kernel configuration options.
232
- */
233
- interface KernelOptions {
234
- /** Total number of items */
235
- itemCount: number;
236
- /** Estimated height of items (used before measurement) */
237
- estimatedItemHeight: number;
238
- /** Number of extra items to render outside viewport */
239
- overscan: number;
240
- /** Scroll direction */
241
- direction: 'vertical' | 'horizontal';
242
- /** Function to get item key */
243
- getItemKey?: (index: number) => string | number;
244
- /** Space before the first item (px): item offsets, the total size and scrollToIndex include it (default 0) */
245
- paddingStart?: number;
246
- }
247
- /**
248
- * Kernel interface - the core of the virtualization engine.
249
- */
250
- interface Kernel {
251
- /** Register a plugin */
252
- register(plugin: Plugin): void;
253
- /** Unregister a plugin by name */
254
- unregister(pluginName: string): void;
255
- /** Get a plugin by name */
256
- getPlugin<T extends Plugin>(name: string): T | undefined;
257
- /** List all registered plugins */
258
- listPlugins(): PluginInfo[];
259
- /** Get current scroll position */
260
- getScrollPosition(): ScrollPosition;
261
- /** Set scroll position directly */
262
- setScrollPosition(position: Partial<ScrollPosition>): void;
263
- /** Scroll to offset */
264
- scrollTo(offset: number, options?: ScrollOptions): void;
265
- /** Scroll to item index */
266
- scrollToIndex(index: number, options?: ScrollToIndexOptions): void;
267
- /** Get viewport dimensions */
268
- getViewport(): Viewport;
269
- /** Get visible range */
270
- getVisibleRange(): Range;
271
- /** Get render range (including overscan) */
272
- getRenderRange(): Range;
273
- /** Measure an item's size */
274
- measureItem(index: number, size: number): void;
275
- /** Get cached height for an item */
276
- getCachedHeight(index: number): number | undefined;
277
- /** Invalidate measurement for an item */
278
- invalidateMeasurement(index: number): void;
279
- /** Invalidate all measurements */
280
- invalidateAllMeasurements(): void;
281
- /** Get estimated item height */
282
- getEstimatedHeight(): number;
283
- /** Get item offset */
284
- getItemOffset(index: number): number;
285
- /** Emit an event */
286
- emit(event: KernelEvent): void;
287
- /** Subscribe to an event type; the handler receives that event's payload */
288
- on<K extends KernelEvent['type']>(eventType: K, handler: EventHandler<Extract<KernelEvent, {
289
- type: K;
290
- }>>): Unsubscribe;
291
- on<T extends KernelEvent>(eventType: T['type'], handler: EventHandler<T>): Unsubscribe;
292
- /** Unsubscribe from an event type */
293
- off<K extends KernelEvent['type']>(eventType: K, handler: EventHandler<Extract<KernelEvent, {
294
- type: K;
295
- }>>): void;
296
- off<T extends KernelEvent>(eventType: T['type'], handler: EventHandler<T>): void;
297
- /** Update kernel configuration */
298
- configure(options: Partial<KernelOptions>): void;
299
- /** Get current configuration */
300
- getOptions(): KernelOptions;
301
- /** Check if currently scrolling */
302
- isScrolling(): boolean;
303
- /** Get item count */
304
- getItemCount(): number;
305
- /** Get total scroll size */
306
- getTotalSize(): number;
307
- /** Attach to a container element */
308
- attach(container: HTMLElement): void;
309
- /** Detach from container */
310
- detach(): void;
311
- /** Destroy the kernel */
312
- destroy(): void;
313
- }
314
- /**
315
- * Gap configuration for grid layouts.
316
- */
317
- interface GridGap {
318
- x: number;
319
- y: number;
320
- }
321
-
322
- /**
323
- * List renderer plugin options.
324
- */
325
- interface ListRendererOptions {
326
- /** Get item key for React reconciliation */
327
- getItemKey?: (index: number) => string | number;
328
- }
329
- /**
330
- * List renderer plugin API.
331
- */
332
- interface ListRendererAPI {
333
- /** Get virtual items to render */
334
- getVirtualItems(): VirtualItem[];
335
- /** Get total scroll height */
336
- getTotalHeight(): number;
337
- /** Get start offset (for positioning) */
338
- getStartOffset(): number;
339
- /** Get end offset */
340
- getEndOffset(): number;
341
- /** Check if an item is visible */
342
- isItemVisible(index: number): boolean;
343
- /** Force recalculation */
344
- recalculate(): void;
345
- }
346
- /**
347
- * Creates a list renderer plugin.
348
- * This is the core virtualization engine for list rendering.
349
- *
350
- * @param options - Plugin options
351
- * @returns Plugin instance
352
- */
353
- declare function listRendererPlugin(options?: ListRendererOptions): Plugin;
354
-
355
- /**
356
- * Grid renderer plugin options.
357
- */
358
- interface GridRendererOptions {
359
- /** Number of columns or 'auto' for responsive */
360
- columns: number | 'auto';
361
- /** Minimum column width for auto columns */
362
- minColumnWidth?: number;
363
- /** Row height */
364
- rowHeight: number;
365
- /** Gap between items */
366
- gap?: number | GridGap;
367
- /** Get item key for React reconciliation */
368
- getItemKey?: (index: number) => string | number;
369
- /** Width the columns share, when it is not the viewport width (the content box of a padded container) */
370
- getContainerWidth?: () => number | undefined;
371
- }
372
- /**
373
- * Grid renderer plugin API.
374
- */
375
- interface GridRendererAPI {
376
- /** Get virtual items to render */
377
- getVirtualItems(): VirtualItem[];
378
- /** Get total scroll height */
379
- getTotalHeight(): number;
380
- /** Get number of columns */
381
- getColumnCount(): number;
382
- /** Get column width */
383
- getColumnWidth(): number;
384
- /** Get number of items per row */
385
- getItemsPerRow(): number;
386
- /** Get row count */
387
- getRowCount(): number;
388
- /** Force recalculation */
389
- recalculate(): void;
390
- }
391
- /**
392
- * Creates a grid renderer plugin.
393
- * Handles multi-column grid virtualization.
394
- *
395
- * @param options - Plugin options
396
- * @returns Plugin instance
397
- */
398
- declare function gridRendererPlugin(options: GridRendererOptions): Plugin;
399
-
400
- /**
401
- * Auto measurer plugin options.
402
- */
403
- interface AutoMeasurerOptions {
404
- /** Estimated item height for initial layout */
405
- estimatedItemHeight?: number;
406
- /** Whether to re-measure when item content resizes */
407
- measureOnResize?: boolean;
408
- /** Debounce time for resize measurements (ms) */
409
- debounceMs?: number;
410
- }
411
- /**
412
- * Auto measurer plugin API.
413
- */
414
- interface AutoMeasurerAPI {
415
- /** Measure an element and update cache */
416
- measureElement(index: number, element: HTMLElement): number;
417
- /** Get cached size for an index */
418
- getCachedSize(index: number): number | undefined;
419
- /** Invalidate measurement for an index */
420
- invalidate(index: number): void;
421
- /** Invalidate all measurements */
422
- invalidateAll(): void;
423
- /** Get the measurement cache */
424
- getMeasurementCache(): Map<number, number>;
425
- /** Observe an element for size changes */
426
- observe(index: number, element: HTMLElement): void;
427
- /** Stop observing an element */
428
- unobserve(element: HTMLElement): void;
429
- }
430
- /**
431
- * Creates an auto measurer plugin.
432
- * Handles automatic measurement of variable height items.
433
- *
434
- * @param options - Plugin options
435
- * @returns Plugin instance
436
- */
437
- declare function autoMeasurerPlugin(options?: AutoMeasurerOptions): Plugin;
438
-
439
- /**
440
- * Load direction.
441
- */
442
- type LoadDirection = 'forward' | 'backward';
443
- /**
444
- * Infinite loader plugin options.
445
- */
446
- interface InfiniteLoaderOptions {
447
- /** Pixels from edge to trigger load */
448
- threshold?: number;
449
- /** Items from edge to trigger load */
450
- thresholdItems?: number;
451
- /** Direction to load more */
452
- direction?: LoadDirection | 'both';
453
- /** Callback when more items should be loaded */
454
- onLoadMore: (direction: LoadDirection) => void | Promise<void>;
455
- }
456
- /**
457
- * Infinite loader plugin API.
458
- */
459
- interface InfiniteLoaderAPI {
460
- /** Check if currently loading */
461
- isLoading(): boolean;
462
- /** Set loading state */
463
- setLoading(loading: boolean): void;
464
- /** Check if there are more items to load */
465
- hasMore(): boolean;
466
- /** Set whether there are more items */
467
- setHasMore(hasMore: boolean): void;
468
- /** Check if can load forward */
469
- hasMoreForward(): boolean;
470
- /** Set whether can load forward */
471
- setHasMoreForward(hasMore: boolean): void;
472
- /** Check if can load backward */
473
- hasMoreBackward(): boolean;
474
- /** Set whether can load backward */
475
- setHasMoreBackward(hasMore: boolean): void;
476
- /** Reset loading state */
477
- reset(): void;
478
- /** Trigger load manually */
479
- triggerLoad(direction: LoadDirection): void;
480
- }
481
- /**
482
- * Creates an infinite loader plugin.
483
- * Handles infinite scroll detection and triggering.
484
- *
485
- * @param options - Plugin options
486
- * @returns Plugin instance
487
- */
488
- declare function infiniteLoaderPlugin(options: InfiniteLoaderOptions): Plugin;
489
-
490
- /**
491
- * Scroll controller plugin options.
492
- */
493
- interface ScrollControllerOptions {
494
- /** Default scroll duration (ms) */
495
- defaultDuration?: number;
496
- /** Default easing function */
497
- defaultEasing?: EasingFunction;
498
- }
499
- /**
500
- * Scroll controller plugin API.
501
- */
502
- interface ScrollControllerAPI {
503
- /** Scroll to an offset */
504
- scrollTo(offset: number, options?: ScrollOptions): void;
505
- /** Scroll to an item index */
506
- scrollToIndex(index: number, options?: ScrollToIndexOptions): void;
507
- /** Scroll to the top */
508
- scrollToTop(options?: ScrollOptions): void;
509
- /** Scroll to the bottom */
510
- scrollToBottom(options?: ScrollOptions): void;
511
- /** Get current scroll position */
512
- getScrollPosition(): ScrollPosition;
513
- /** Check if currently scrolling */
514
- isScrolling(): boolean;
515
- /** Check if animation is in progress */
516
- isAnimating(): boolean;
517
- /** Stop current scroll animation */
518
- stopAnimation(): void;
519
- }
520
- /**
521
- * Creates a scroll controller plugin.
522
- * Provides programmatic scroll control with smooth animations.
523
- *
524
- * @param options - Plugin options
525
- * @returns Plugin instance
526
- */
527
- declare function scrollControllerPlugin(options?: ScrollControllerOptions): Plugin;
1
+ import { VirtualItem, Plugin, ScrollPosition, Range } from '../index.cjs';
2
+ export { A as AutoMeasurerAPI, j as AutoMeasurerOptions, n as GridRendererAPI, o as GridRendererOptions, I as InfiniteLoaderAPI, p as InfiniteLoaderOptions, L as ListRendererAPI, u as ListRendererOptions, v as LoadDirection, H as ScrollControllerAPI, J as ScrollControllerOptions, a1 as autoMeasurerPlugin, a2 as gridRendererPlugin, a3 as infiniteLoaderPlugin, a4 as listRendererPlugin, a5 as scrollControllerPlugin } from '../scroll-controller-D5AV1E2p.cjs';
3
+ import 'react';
528
4
 
529
5
  /**
530
6
  * Masonry renderer plugin options.
@@ -1158,5 +634,5 @@ interface DebugPanelOverlayProps {
1158
634
  */
1159
635
  declare function DebugPanelOverlay({ plugin, className, style, }: DebugPanelOverlayProps): React.ReactElement | null;
1160
636
 
1161
- export { DebugPanelOverlay, autoMeasurerPlugin, bidirectional, debugPanel, dragToReorder, gridRendererPlugin, infiniteLoaderPlugin, keyboardNav, listRendererPlugin, masonryRenderer, scrollControllerPlugin, scrollRestoration, stickyHeaders };
1162
- export type { AutoMeasurerAPI, AutoMeasurerOptions, BidirectionalAPI, BidirectionalOptions, DebugPanelAPI, DebugPanelOptions, DebugPanelOverlayProps, DebugPanelPosition, DebugPanelState, DebugPanelTab, DebugPanelTheme, DragAxis, DragEventLike, DragHandleProps, DragToReorderAPI, DragToReorderOptions, DropIndicatorStyle, EventLogEntry, GridRendererAPI, GridRendererOptions, InfiniteLoaderAPI, InfiniteLoaderOptions, KeyboardNavAPI, KeyboardNavOptions, KeyboardNavOrientation, ListRendererAPI, ListRendererOptions, LoadDirection, MasonryRendererAPI, MasonryRendererOptions, PerformanceStats, SavedScrollState, ScrollControllerAPI, ScrollControllerOptions, ScrollRestorationAPI, ScrollRestorationOptions, ScrollRestorationStorage, StickyHeadersAPI, StickyHeadersOptions };
637
+ export { DebugPanelOverlay, bidirectional, debugPanel, dragToReorder, keyboardNav, masonryRenderer, scrollRestoration, stickyHeaders };
638
+ export type { BidirectionalAPI, BidirectionalOptions, DebugPanelAPI, DebugPanelOptions, DebugPanelOverlayProps, DebugPanelPosition, DebugPanelState, DebugPanelTab, DebugPanelTheme, DragAxis, DragEventLike, DragHandleProps, DragToReorderAPI, DragToReorderOptions, DropIndicatorStyle, EventLogEntry, KeyboardNavAPI, KeyboardNavOptions, KeyboardNavOrientation, MasonryRendererAPI, MasonryRendererOptions, PerformanceStats, SavedScrollState, ScrollRestorationAPI, ScrollRestorationOptions, ScrollRestorationStorage, StickyHeadersAPI, StickyHeadersOptions };