@floor/vlist 0.5.8 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +787 -611
- package/dist/async/index.js +1 -0
- package/dist/builder/context.d.ts +3 -3
- package/dist/builder/context.d.ts.map +1 -1
- package/dist/builder/core.d.ts +1 -1
- package/dist/builder/core.d.ts.map +1 -1
- package/dist/builder/types.d.ts +3 -3
- package/dist/builder/types.d.ts.map +1 -1
- package/dist/core/full.d.ts +22 -0
- package/dist/core/full.d.ts.map +1 -0
- package/dist/core/lite.d.ts +129 -0
- package/dist/core/lite.d.ts.map +1 -0
- package/dist/core/minimal.d.ts +104 -0
- package/dist/core/minimal.d.ts.map +1 -0
- package/dist/features/async/index.d.ts +9 -0
- package/dist/features/async/index.d.ts.map +1 -0
- package/dist/features/async/manager.d.ts +103 -0
- package/dist/features/async/manager.d.ts.map +1 -0
- package/dist/features/async/placeholder.d.ts +62 -0
- package/dist/features/async/placeholder.d.ts.map +1 -0
- package/dist/features/async/plugin.d.ts +60 -0
- package/dist/features/async/plugin.d.ts.map +1 -0
- package/dist/features/async/sparse.d.ts +91 -0
- package/dist/features/async/sparse.d.ts.map +1 -0
- package/dist/features/grid/index.d.ts +9 -0
- package/dist/features/grid/index.d.ts.map +1 -0
- package/dist/features/grid/layout.d.ts +29 -0
- package/dist/features/grid/layout.d.ts.map +1 -0
- package/dist/features/grid/plugin.d.ts +48 -0
- package/dist/features/grid/plugin.d.ts.map +1 -0
- package/dist/features/grid/renderer.d.ts +55 -0
- package/dist/features/grid/renderer.d.ts.map +1 -0
- package/dist/features/grid/types.d.ts +71 -0
- package/dist/features/grid/types.d.ts.map +1 -0
- package/dist/features/page/index.d.ts +8 -0
- package/dist/features/page/index.d.ts.map +1 -0
- package/dist/features/page/plugin.d.ts +53 -0
- package/dist/features/page/plugin.d.ts.map +1 -0
- package/dist/features/scale/index.d.ts +10 -0
- package/dist/features/scale/index.d.ts.map +1 -0
- package/dist/features/scale/plugin.d.ts +42 -0
- package/dist/features/scale/plugin.d.ts.map +1 -0
- package/dist/features/scrollbar/controller.d.ts +121 -0
- package/dist/features/scrollbar/controller.d.ts.map +1 -0
- package/dist/features/scrollbar/index.d.ts +8 -0
- package/dist/features/scrollbar/index.d.ts.map +1 -0
- package/dist/features/scrollbar/plugin.d.ts +60 -0
- package/dist/features/scrollbar/plugin.d.ts.map +1 -0
- package/dist/features/scrollbar/scrollbar.d.ts +73 -0
- package/dist/features/scrollbar/scrollbar.d.ts.map +1 -0
- package/dist/features/sections/index.d.ts +10 -0
- package/dist/features/sections/index.d.ts.map +1 -0
- package/dist/features/sections/layout.d.ts +46 -0
- package/dist/features/sections/layout.d.ts.map +1 -0
- package/dist/features/sections/plugin.d.ts +64 -0
- package/dist/features/sections/plugin.d.ts.map +1 -0
- package/dist/features/sections/sticky.d.ts +33 -0
- package/dist/features/sections/sticky.d.ts.map +1 -0
- package/dist/features/sections/types.d.ts +86 -0
- package/dist/features/sections/types.d.ts.map +1 -0
- package/dist/features/selection/index.d.ts +7 -0
- package/dist/features/selection/index.d.ts.map +1 -0
- package/dist/features/selection/plugin.d.ts +44 -0
- package/dist/features/selection/plugin.d.ts.map +1 -0
- package/dist/features/selection/state.d.ts +102 -0
- package/dist/features/selection/state.d.ts.map +1 -0
- package/dist/features/snapshots/index.d.ts +8 -0
- package/dist/features/snapshots/index.d.ts.map +1 -0
- package/dist/features/snapshots/plugin.d.ts +44 -0
- package/dist/features/snapshots/plugin.d.ts.map +1 -0
- package/dist/grid/index.js +1 -1
- package/dist/index.d.ts +17 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/page/index.js +1 -0
- package/dist/react/index.js +1 -1
- package/dist/rendering/heights.d.ts +63 -0
- package/dist/rendering/heights.d.ts.map +1 -0
- package/dist/rendering/index.d.ts +9 -0
- package/dist/rendering/index.d.ts.map +1 -0
- package/dist/rendering/renderer.d.ts +103 -0
- package/dist/rendering/renderer.d.ts.map +1 -0
- package/dist/rendering/scale.d.ts +116 -0
- package/dist/rendering/scale.d.ts.map +1 -0
- package/dist/rendering/viewport.d.ts +139 -0
- package/dist/rendering/viewport.d.ts.map +1 -0
- package/dist/scale/index.js +1 -0
- package/dist/scrollbar/index.js +1 -0
- package/dist/sections/index.js +1 -0
- package/dist/selection/index.js +1 -1
- package/dist/svelte/index.js +1 -1
- package/dist/vue/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist/data - Builder Plugin
|
|
3
|
+
* Wraps async data loading with sparse storage into a VListPlugin for the composable builder.
|
|
4
|
+
*
|
|
5
|
+
* Priority: 20 (runs before scrollbar and selection, after grid/groups)
|
|
6
|
+
*
|
|
7
|
+
* What it wires:
|
|
8
|
+
* - Replaces data manager — swaps the simple in-memory store with sparse storage
|
|
9
|
+
* - Scroll boundary detection — triggers loadMore() near the bottom (or top in reverse)
|
|
10
|
+
* - Velocity-aware loading — skips data fetching during fast scrolling, loads on idle
|
|
11
|
+
* - Placeholder generation — creates skeleton items for unloaded ranges
|
|
12
|
+
* - Request deduplication — prevents duplicate fetches for the same range
|
|
13
|
+
* - Idle handler — loads any pending ranges when scrolling stops
|
|
14
|
+
*
|
|
15
|
+
* Added methods: reload
|
|
16
|
+
* Added events: load:start, load:end, error
|
|
17
|
+
*/
|
|
18
|
+
import type { VListItem, VListAdapter } from "../../types";
|
|
19
|
+
import type { VListPlugin } from "../../builder/types";
|
|
20
|
+
/** Data plugin configuration */
|
|
21
|
+
export interface DataPluginConfig<T extends VListItem = VListItem> {
|
|
22
|
+
/** Async data source (required) */
|
|
23
|
+
adapter: VListAdapter<T>;
|
|
24
|
+
/** Loading behavior configuration */
|
|
25
|
+
loading?: {
|
|
26
|
+
/** Velocity threshold above which data loading is skipped (px/ms). Default: 25 */
|
|
27
|
+
cancelThreshold?: number;
|
|
28
|
+
/** Velocity threshold for preloading (px/ms). Default: 2 */
|
|
29
|
+
preloadThreshold?: number;
|
|
30
|
+
/** Number of items to preload in scroll direction. Default: 50 */
|
|
31
|
+
preloadAhead?: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a data plugin for the builder.
|
|
36
|
+
*
|
|
37
|
+
* Adds async data loading with sparse storage, placeholders, and infinite scroll.
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { vlist } from 'vlist/builder'
|
|
41
|
+
* import { withData } from 'vlist/data'
|
|
42
|
+
*
|
|
43
|
+
* const list = vlist({
|
|
44
|
+
* container: '#app',
|
|
45
|
+
* item: { height: 48, template: renderItem },
|
|
46
|
+
* })
|
|
47
|
+
* .use(withData({
|
|
48
|
+
* adapter: {
|
|
49
|
+
* read: async ({ offset, limit }) => {
|
|
50
|
+
* const res = await fetch(`/api/items?offset=${offset}&limit=${limit}`)
|
|
51
|
+
* const data = await res.json()
|
|
52
|
+
* return { items: data.items, total: data.total, hasMore: data.hasMore }
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* }))
|
|
56
|
+
* .build()
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const withAsync: <T extends VListItem = VListItem>(config: DataPluginConfig<T>) => VListPlugin<T>;
|
|
60
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/features/async/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAS,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,qBAAqB,CAAC;AAiBvE,gCAAgC;AAChC,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC/D,mCAAmC;IACnC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAEzB,qCAAqC;IACrC,OAAO,CAAC,EAAE;QACR,kFAAkF;QAClF,eAAe,CAAC,EAAE,MAAM,CAAC;QAEzB,4DAA4D;QAC5D,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAE1B,kEAAkE;QAClE,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAMD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,SAAS,GAAG,SAAS,EACvD,QAAQ,gBAAgB,CAAC,CAAC,CAAC,KAC1B,WAAW,CAAC,CAAC,CAiOf,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist - Sparse Storage
|
|
3
|
+
* Efficient storage for million+ item virtual lists
|
|
4
|
+
*/
|
|
5
|
+
import type { VListItem, Range } from "../../types";
|
|
6
|
+
/** Configuration for sparse storage */
|
|
7
|
+
export interface SparseStorageConfig {
|
|
8
|
+
/** Number of items per chunk (default: 100) */
|
|
9
|
+
chunkSize?: number;
|
|
10
|
+
/** Maximum items to keep in memory (default: 5000) */
|
|
11
|
+
maxCachedItems?: number;
|
|
12
|
+
/** Extra items to keep around visible range during eviction (default: 200) */
|
|
13
|
+
evictionBuffer?: number;
|
|
14
|
+
/** Callback when items are evicted */
|
|
15
|
+
onEvict?: (evictedCount: number, evictedRanges: number[]) => void;
|
|
16
|
+
}
|
|
17
|
+
/** Storage statistics */
|
|
18
|
+
export interface SparseStorageStats {
|
|
19
|
+
/** Total items declared (may be larger than loaded) */
|
|
20
|
+
totalItems: number;
|
|
21
|
+
/** Number of items currently in memory */
|
|
22
|
+
cachedItems: number;
|
|
23
|
+
/** Number of chunks in memory */
|
|
24
|
+
cachedChunks: number;
|
|
25
|
+
/** Chunk size */
|
|
26
|
+
chunkSize: number;
|
|
27
|
+
/** Maximum cached items allowed */
|
|
28
|
+
maxCachedItems: number;
|
|
29
|
+
/** Memory efficiency (cachedItems / totalItems) */
|
|
30
|
+
memoryEfficiency: number;
|
|
31
|
+
}
|
|
32
|
+
/** Sparse storage instance */
|
|
33
|
+
export interface SparseStorage<T extends VListItem = VListItem> {
|
|
34
|
+
readonly chunkSize: number;
|
|
35
|
+
readonly maxCachedItems: number;
|
|
36
|
+
/** Get total item count */
|
|
37
|
+
getTotal: () => number;
|
|
38
|
+
/** Set total item count (for virtual scrolling height) */
|
|
39
|
+
setTotal: (total: number) => void;
|
|
40
|
+
/** Get item at index (undefined if not loaded) */
|
|
41
|
+
get: (index: number) => T | undefined;
|
|
42
|
+
/** Check if item at index is loaded */
|
|
43
|
+
has: (index: number) => boolean;
|
|
44
|
+
/** Set item at index */
|
|
45
|
+
set: (index: number, item: T) => void;
|
|
46
|
+
/** Set multiple items starting at offset */
|
|
47
|
+
setRange: (offset: number, items: T[]) => void;
|
|
48
|
+
/** Delete item at index */
|
|
49
|
+
delete: (index: number) => boolean;
|
|
50
|
+
/** Get items in range (includes undefined for unloaded) */
|
|
51
|
+
getRange: (start: number, end: number) => (T | undefined)[];
|
|
52
|
+
/** Check if range is fully loaded */
|
|
53
|
+
isRangeLoaded: (start: number, end: number) => boolean;
|
|
54
|
+
/** Get loaded ranges */
|
|
55
|
+
getLoadedRanges: () => Range[];
|
|
56
|
+
/** Find unloaded ranges within a given range */
|
|
57
|
+
findUnloadedRanges: (start: number, end: number) => Range[];
|
|
58
|
+
/** Get chunk index for item index */
|
|
59
|
+
getChunkIndex: (itemIndex: number) => number;
|
|
60
|
+
/** Check if chunk is loaded */
|
|
61
|
+
isChunkLoaded: (chunkIndex: number) => boolean;
|
|
62
|
+
/** Mark chunk as accessed (for LRU) */
|
|
63
|
+
touchChunk: (chunkIndex: number) => void;
|
|
64
|
+
/** Mark all chunks in a range as accessed with a single Date.now() call */
|
|
65
|
+
touchChunksForRange: (start: number, end: number) => void;
|
|
66
|
+
/** Evict chunks far from visible range */
|
|
67
|
+
evictDistant: (visibleStart: number, visibleEnd: number) => number;
|
|
68
|
+
/** Force eviction to meet memory limit */
|
|
69
|
+
evictToLimit: () => number;
|
|
70
|
+
/** Get storage statistics */
|
|
71
|
+
getStats: () => SparseStorageStats;
|
|
72
|
+
/** Get cached item count */
|
|
73
|
+
getCachedCount: () => number;
|
|
74
|
+
/** Clear all data */
|
|
75
|
+
clear: () => void;
|
|
76
|
+
/** Reset to initial state */
|
|
77
|
+
reset: () => void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create sparse storage for efficient large list handling
|
|
81
|
+
*/
|
|
82
|
+
export declare const createSparseStorage: <T extends VListItem = VListItem>(config?: SparseStorageConfig) => SparseStorage<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Merge adjacent/overlapping ranges
|
|
85
|
+
*/
|
|
86
|
+
export declare const mergeRanges: (ranges: Range[]) => Range[];
|
|
87
|
+
/**
|
|
88
|
+
* Calculate ranges that need to be loaded
|
|
89
|
+
*/
|
|
90
|
+
export declare const calculateMissingRanges: (needed: Range, loaded: Range[], chunkSize: number) => Range[];
|
|
91
|
+
//# sourceMappingURL=sparse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sparse.d.ts","sourceRoot":"","sources":["../../../src/features/async/sparse.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAMpD,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IAClC,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,sDAAsD;IACtD,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,8EAA8E;IAC9E,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,sCAAsC;IACtC,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CACnE;AAcD,yBAAyB;AACzB,MAAM,WAAW,kBAAkB;IACjC,uDAA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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist - Grid Domain
|
|
3
|
+
* 2D grid/card layout with virtualized rows
|
|
4
|
+
*/
|
|
5
|
+
export { withGrid, type GridPluginConfig } from "./plugin";
|
|
6
|
+
export { createGridLayout } from "./layout";
|
|
7
|
+
export { createGridRenderer, type GridRenderer } from "./renderer";
|
|
8
|
+
export type { GridConfig, GridLayout, GridPosition, ItemRange } from "./types";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/grid/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,QAAQ,EAAE,KAAK,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C,OAAO,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAGnE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist - Grid Layout
|
|
3
|
+
* Pure O(1) calculations for mapping between flat item indices and grid positions.
|
|
4
|
+
*
|
|
5
|
+
* The grid transforms a flat list into rows:
|
|
6
|
+
* Items: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
7
|
+
* Grid (columns=4):
|
|
8
|
+
* Row 0: [0, 1, 2, 3]
|
|
9
|
+
* Row 1: [4, 5, 6, 7]
|
|
10
|
+
* Row 2: [8, 9] ← partially filled last row
|
|
11
|
+
*
|
|
12
|
+
* All operations are O(1) — integer division and modulo only.
|
|
13
|
+
*/
|
|
14
|
+
import type { GridConfig, GridLayout } from "./types";
|
|
15
|
+
/**
|
|
16
|
+
* Extended grid config with optional groups support
|
|
17
|
+
*/
|
|
18
|
+
export interface GridConfigWithGroups extends GridConfig {
|
|
19
|
+
/** Optional: check if an item index is a group header (for groups-aware layout) */
|
|
20
|
+
isHeaderFn?: (index: number) => boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create a GridLayout instance.
|
|
24
|
+
*
|
|
25
|
+
* @param config - Grid configuration (columns, gap, optional isHeaderFn)
|
|
26
|
+
* @returns GridLayout with O(1) mapping functions (or groups-aware if isHeaderFn provided)
|
|
27
|
+
*/
|
|
28
|
+
export declare const createGridLayout: (config: GridConfigWithGroups) => GridLayout;
|
|
29
|
+
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/features/grid/layout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAA2B,MAAM,SAAS,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,UAAU;IACtD,mFAAmF;IACnF,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;CACzC;AAMD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,oBAAoB,KAAG,UA4R/D,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist/grid - Builder Plugin
|
|
3
|
+
* Switches from list layout to a 2D grid with configurable columns and gap.
|
|
4
|
+
*
|
|
5
|
+
* Priority: 10 (runs first — replaces the renderer before anything else renders)
|
|
6
|
+
*
|
|
7
|
+
* What it wires:
|
|
8
|
+
* - Replaces renderer — swaps the list renderer with a grid renderer
|
|
9
|
+
* - Redefines virtual total — the virtualizer sees rows, not items
|
|
10
|
+
* - Column width calculation — recalculated on resize
|
|
11
|
+
* - Item positioning — each item gets translateX (column) and translateY (row)
|
|
12
|
+
* - CSS class — adds .vlist--grid to the root element
|
|
13
|
+
*
|
|
14
|
+
* Restrictions:
|
|
15
|
+
* - Cannot be combined with direction: 'horizontal'
|
|
16
|
+
* - Cannot be combined with reverse: true
|
|
17
|
+
*
|
|
18
|
+
* Can be combined with withGroups for grouped 2D layouts.
|
|
19
|
+
*/
|
|
20
|
+
import type { VListItem } from "../../types";
|
|
21
|
+
import type { VListPlugin } from "../../builder/types";
|
|
22
|
+
/** Grid plugin configuration */
|
|
23
|
+
export interface GridPluginConfig {
|
|
24
|
+
/** Number of columns (required, >= 1) */
|
|
25
|
+
columns: number;
|
|
26
|
+
/** Gap between items in pixels (default: 0) */
|
|
27
|
+
gap?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create a grid plugin for the builder.
|
|
31
|
+
*
|
|
32
|
+
* Switches from list layout to a 2D grid with configurable columns and gap.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { vlist } from 'vlist/builder'
|
|
36
|
+
* import { withGrid } from 'vlist/grid'
|
|
37
|
+
*
|
|
38
|
+
* const gallery = vlist({
|
|
39
|
+
* container: '#gallery',
|
|
40
|
+
* item: { height: 200, template: renderPhoto },
|
|
41
|
+
* items: photos,
|
|
42
|
+
* })
|
|
43
|
+
* .use(withGrid({ columns: 4, gap: 8 }))
|
|
44
|
+
* .build()
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare const withGrid: <T extends VListItem = VListItem>(config: GridPluginConfig) => VListPlugin<T>;
|
|
48
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/features/grid/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,qBAAqB,CAAC;AAUvE,gCAAgC;AAChC,MAAM,WAAW,gBAAgB;IAC/B,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAEhB,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,SAAS,GAAG,SAAS,EACtD,QAAQ,gBAAgB,KACvB,WAAW,CAAC,CAAC,CA4Zf,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist - Grid Renderer
|
|
3
|
+
* Renders items in a 2D grid layout within the virtual scroll container.
|
|
4
|
+
*
|
|
5
|
+
* Extends the base renderer pattern but positions items using both
|
|
6
|
+
* row offsets (translateY from the height cache) and column offsets
|
|
7
|
+
* (translateX calculated from column index and container width).
|
|
8
|
+
*
|
|
9
|
+
* Key differences from the list renderer:
|
|
10
|
+
* - Items are positioned with translate(x, y) instead of just translateY(y)
|
|
11
|
+
* - Item width is set to columnWidth (containerWidth / columns - gaps)
|
|
12
|
+
* - The "index" in the rendered map is the FLAT ITEM INDEX (not row index)
|
|
13
|
+
* - Row offsets come from the height cache (which operates on row indices)
|
|
14
|
+
* - Column offsets are calculated from itemIndex % columns
|
|
15
|
+
*/
|
|
16
|
+
import type { VListItem, ItemTemplate, Range } from "../../types";
|
|
17
|
+
import type { HeightCache } from "../../rendering/heights";
|
|
18
|
+
import type { CompressionContext } from "../../rendering/renderer";
|
|
19
|
+
import type { GridLayout } from "./types";
|
|
20
|
+
/** Grid renderer instance */
|
|
21
|
+
export interface GridRenderer<T extends VListItem = VListItem> {
|
|
22
|
+
/** Render items for a flat item range, positioned in a 2D grid */
|
|
23
|
+
render: (items: T[], range: Range, selectedIds: Set<string | number>, focusedIndex: number, compressionCtx?: CompressionContext) => void;
|
|
24
|
+
/** Update item positions (for compressed scrolling) */
|
|
25
|
+
updatePositions: (compressionCtx: CompressionContext) => void;
|
|
26
|
+
/** Update a single item */
|
|
27
|
+
updateItem: (index: number, item: T, isSelected: boolean, isFocused: boolean) => void;
|
|
28
|
+
/** Update only CSS classes on a rendered item (no template re-evaluation) */
|
|
29
|
+
updateItemClasses: (index: number, isSelected: boolean, isFocused: boolean) => void;
|
|
30
|
+
/** Get rendered item element by flat item index */
|
|
31
|
+
getElement: (index: number) => HTMLElement | undefined;
|
|
32
|
+
/** Update container width (call on resize) */
|
|
33
|
+
updateContainerWidth: (width: number) => void;
|
|
34
|
+
/** Clear all rendered items */
|
|
35
|
+
clear: () => void;
|
|
36
|
+
/** Destroy renderer and cleanup */
|
|
37
|
+
destroy: () => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a grid renderer for managing DOM elements in a 2D layout.
|
|
41
|
+
*
|
|
42
|
+
* The grid renderer receives flat item ranges (not row ranges) and
|
|
43
|
+
* positions each item at the correct (row, col) coordinate.
|
|
44
|
+
*
|
|
45
|
+
* @param itemsContainer - The DOM element that holds rendered items
|
|
46
|
+
* @param template - Item template function
|
|
47
|
+
* @param heightCache - Height cache operating on ROW indices
|
|
48
|
+
* @param gridLayout - Grid layout for row/col calculations
|
|
49
|
+
* @param classPrefix - CSS class prefix
|
|
50
|
+
* @param initialContainerWidth - Initial container width for column sizing
|
|
51
|
+
* @param totalItemsGetter - Optional getter for total item count (for aria-setsize)
|
|
52
|
+
* @param ariaIdPrefix - Optional unique prefix for element IDs (for aria-activedescendant)
|
|
53
|
+
*/
|
|
54
|
+
export declare const createGridRenderer: <T extends VListItem = VListItem>(itemsContainer: HTMLElement, template: ItemTemplate<T>, heightCache: HeightCache, gridLayout: GridLayout, classPrefix: string, initialContainerWidth: number, totalItemsGetter?: () => number, ariaIdPrefix?: string) => GridRenderer<T>;
|
|
55
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../../src/features/grid/renderer.ts"],"names":[],"mappings":"AAAA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AAkB,GAAI,CAAC,SAAS,SAAS,GAAG,SAAS,EAChE,gBAAgB,WAAW,EAC3B,UAAU,YAAY,CAAC,CAAC,CAAC,EACzB,aAAa,WAAW,EACxB,YAAY,UAAU,EACtB,aAAa,MAAM,EACnB,uBAAuB,MAAM,EAC7B,mBAAmB,MAAM,MAAM,EAC/B,eAAe,MAAM,KACpB,YAAY,CAAC,CAAC,CAmahB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist - Grid Types
|
|
3
|
+
* Types for grid/card layout mode
|
|
4
|
+
*
|
|
5
|
+
* Grid layout transforms a flat list of items into a 2D grid where:
|
|
6
|
+
* - Virtualization operates on ROWS (not individual items)
|
|
7
|
+
* - Each row contains `columns` items side by side
|
|
8
|
+
* - Items are positioned using row/column coordinates
|
|
9
|
+
* - Compression applies to row count, not item count
|
|
10
|
+
*/
|
|
11
|
+
import type { GridConfig } from "../../types";
|
|
12
|
+
export type { GridConfig };
|
|
13
|
+
/** Row/column position of an item */
|
|
14
|
+
export interface GridPosition {
|
|
15
|
+
/** Row index (0-based) */
|
|
16
|
+
row: number;
|
|
17
|
+
/** Column index (0-based) */
|
|
18
|
+
col: number;
|
|
19
|
+
}
|
|
20
|
+
/** Flat item range corresponding to a row range */
|
|
21
|
+
export interface ItemRange {
|
|
22
|
+
/** First item index (inclusive) */
|
|
23
|
+
start: number;
|
|
24
|
+
/** Last item index (inclusive) */
|
|
25
|
+
end: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* GridLayout — maps between flat item indices and row/column positions.
|
|
29
|
+
*
|
|
30
|
+
* The virtualizer sees "rows" as its unit of work. Each row contains
|
|
31
|
+
* up to `columns` items. The last row may be partially filled.
|
|
32
|
+
*
|
|
33
|
+
* All operations are O(1) — just integer division and modulo.
|
|
34
|
+
*/
|
|
35
|
+
export interface GridLayout {
|
|
36
|
+
/** Number of columns */
|
|
37
|
+
readonly columns: number;
|
|
38
|
+
/** Gap between items in pixels */
|
|
39
|
+
readonly gap: number;
|
|
40
|
+
/** Update grid configuration without recreating the layout */
|
|
41
|
+
update: (config: Partial<GridConfig>) => void;
|
|
42
|
+
/** Get total number of rows for a given item count */
|
|
43
|
+
getTotalRows: (totalItems: number) => number;
|
|
44
|
+
/** Get the row/col position for a flat item index */
|
|
45
|
+
getPosition: (itemIndex: number) => GridPosition;
|
|
46
|
+
/** Get the row index for a flat item index */
|
|
47
|
+
getRow: (itemIndex: number) => number;
|
|
48
|
+
/** Get the column index for a flat item index */
|
|
49
|
+
getCol: (itemIndex: number) => number;
|
|
50
|
+
/**
|
|
51
|
+
* Get the flat item range for a range of rows.
|
|
52
|
+
* The last row may be partially filled (end is clamped to totalItems - 1).
|
|
53
|
+
*/
|
|
54
|
+
getItemRange: (rowStart: number, rowEnd: number, totalItems: number) => ItemRange;
|
|
55
|
+
/**
|
|
56
|
+
* Get the flat item index from a row and column.
|
|
57
|
+
* Returns -1 if out of bounds.
|
|
58
|
+
*/
|
|
59
|
+
getItemIndex: (row: number, col: number, totalItems: number) => number;
|
|
60
|
+
/**
|
|
61
|
+
* Calculate column width given container width.
|
|
62
|
+
* Accounts for gaps: width = (containerWidth - (columns - 1) * gap) / columns
|
|
63
|
+
*/
|
|
64
|
+
getColumnWidth: (containerWidth: number) => number;
|
|
65
|
+
/**
|
|
66
|
+
* Calculate the X offset for a column index.
|
|
67
|
+
* offset = col * (columnWidth + gap)
|
|
68
|
+
*/
|
|
69
|
+
getColumnOffset: (col: number, containerWidth: number) => number;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/features/grid/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG9C,YAAY,EAAE,UAAU,EAAE,CAAC;AAM3B,qCAAqC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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/page/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist/window - Window Scroll Mode Plugin
|
|
3
|
+
*
|
|
4
|
+
* Enables the list to scroll with the page instead of in its own container.
|
|
5
|
+
* Useful for infinite feeds, full-page lists, and chat UIs that integrate
|
|
6
|
+
* with page scroll.
|
|
7
|
+
*
|
|
8
|
+
* Priority: 5 (runs early, before other plugins that depend on scroll)
|
|
9
|
+
*
|
|
10
|
+
* What it does:
|
|
11
|
+
* - Uses window as scroll target instead of viewport element
|
|
12
|
+
* - Calculates scroll position relative to document
|
|
13
|
+
* - Uses window.innerWidth/innerHeight for container dimensions
|
|
14
|
+
* - Listens to window resize events instead of ResizeObserver
|
|
15
|
+
* - Adjusts DOM styles (overflow: visible, height: auto)
|
|
16
|
+
*
|
|
17
|
+
* Bundle impact: ~0.3 KB gzipped when used
|
|
18
|
+
*/
|
|
19
|
+
import type { VListItem } from "../../types";
|
|
20
|
+
import type { VListPlugin } from "../../builder/types";
|
|
21
|
+
/**
|
|
22
|
+
* Create a window scroll mode plugin.
|
|
23
|
+
*
|
|
24
|
+
* Use this when you want your list to scroll with the page instead of
|
|
25
|
+
* in a fixed-height container.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { vlist } from 'vlist/builder'
|
|
30
|
+
* import { withWindow } from 'vlist/window'
|
|
31
|
+
*
|
|
32
|
+
* const feed = vlist({
|
|
33
|
+
* container: '#infinite-feed',
|
|
34
|
+
* item: { height: 200, template: renderPost },
|
|
35
|
+
* items: posts
|
|
36
|
+
* })
|
|
37
|
+
* .use(withWindow())
|
|
38
|
+
* .build()
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example Horizontal window scrolling
|
|
42
|
+
* ```ts
|
|
43
|
+
* const timeline = vlist({
|
|
44
|
+
* container: '#timeline',
|
|
45
|
+
* item: { height: 100, template: renderEvent },
|
|
46
|
+
* direction: 'horizontal'
|
|
47
|
+
* })
|
|
48
|
+
* .use(withWindow())
|
|
49
|
+
* .build()
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const withPage: <T extends VListItem = VListItem>() => VListPlugin<T>;
|
|
53
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/features/page/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,qBAAqB,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,QAAQ,GACnB,CAAC,SAAS,SAAS,GAAG,SAAS,OAC5B,WAAW,CAAC,CAAC,CA6HjB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist - Compression Sub-module
|
|
3
|
+
* Re-exports compression utilities for tree-shakeable imports
|
|
4
|
+
*
|
|
5
|
+
* Usage: import { getCompressionInfo } from 'vlist/compression'
|
|
6
|
+
* Usage: import { withScale } from 'vlist/compression'
|
|
7
|
+
*/
|
|
8
|
+
export { MAX_VIRTUAL_HEIGHT, getCompressionState, needsCompression, getMaxItemsWithoutCompression, getCompressionInfo, calculateCompressedVisibleRange, calculateCompressedRenderRange, calculateCompressedItemPosition, calculateCompressedScrollToIndex, calculateIndexFromScrollPosition, type CompressionState, } from "../../rendering/scale";
|
|
9
|
+
export { withScale } from "./plugin";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/scale/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,6BAA6B,EAC7B,kBAAkB,EAClB,+BAA+B,EAC/B,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,EAChC,gCAAgC,EAChC,KAAK,gBAAgB,GACtB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist/compression - Builder Plugin
|
|
3
|
+
* Enables support for lists with 1M+ items by compressing the scroll space
|
|
4
|
+
* when the total height exceeds the browser's ~16.7M pixel limit.
|
|
5
|
+
*
|
|
6
|
+
* Priority: 20 (runs before scrollbar, after grid/groups)
|
|
7
|
+
*
|
|
8
|
+
* What it wires:
|
|
9
|
+
* - Scroll mode switch — transitions from native to compressed scrolling when needed
|
|
10
|
+
* - Scroll position mapping — maps compressed scroll positions to item indices
|
|
11
|
+
* - Item positioning — positions items relative to viewport in compressed mode
|
|
12
|
+
* - Custom scrollbar fallback — forces custom scrollbar in compressed mode
|
|
13
|
+
* - Near-bottom interpolation — smooth blending near the end of the list
|
|
14
|
+
* - Cached compression state — recalculates only when total item count changes
|
|
15
|
+
*
|
|
16
|
+
* No configuration needed — compression activates automatically when the total
|
|
17
|
+
* height exceeds the browser limit, and deactivates when items are removed.
|
|
18
|
+
*/
|
|
19
|
+
import type { VListItem } from "../../types";
|
|
20
|
+
import type { VListPlugin } from "../../builder/types";
|
|
21
|
+
/**
|
|
22
|
+
* Create a compression plugin for the builder.
|
|
23
|
+
*
|
|
24
|
+
* Enables support for lists with 1M+ items. No configuration needed —
|
|
25
|
+
* compression activates automatically when the total height exceeds
|
|
26
|
+
* the browser's ~16.7M pixel limit.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { vlist } from 'vlist/builder'
|
|
30
|
+
* import { withCompression } from 'vlist/compression'
|
|
31
|
+
*
|
|
32
|
+
* const list = vlist({
|
|
33
|
+
* container: '#app',
|
|
34
|
+
* item: { height: 48, template: renderItem },
|
|
35
|
+
* items: millionItems,
|
|
36
|
+
* })
|
|
37
|
+
* .use(withCompression())
|
|
38
|
+
* .build()
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare const withScale: <T extends VListItem = VListItem>() => VListPlugin<T>;
|
|
42
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/features/scale/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAkB,MAAM,qBAAqB,CAAC;AAevE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,SAAS,GACpB,CAAC,SAAS,SAAS,GAAG,SAAS,OAC5B,WAAW,CAAC,CAAC,CA2QjB,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vlist - Scroll Controller
|
|
3
|
+
* Handles both native scrolling and manual wheel-based scrolling for compressed lists
|
|
4
|
+
*
|
|
5
|
+
* When compression is active (large lists exceeding browser height limits),
|
|
6
|
+
* we switch from native scrolling to manual wheel event handling.
|
|
7
|
+
* This allows smooth scrolling through millions of items.
|
|
8
|
+
*/
|
|
9
|
+
import type { CompressionState } from "../../rendering/scale";
|
|
10
|
+
/** Scroll direction */
|
|
11
|
+
export type ScrollDirection = "up" | "down";
|
|
12
|
+
/** Scroll event data */
|
|
13
|
+
export interface ScrollEventData {
|
|
14
|
+
scrollTop: number;
|
|
15
|
+
direction: ScrollDirection;
|
|
16
|
+
velocity: number;
|
|
17
|
+
}
|
|
18
|
+
/** Scroll controller configuration */
|
|
19
|
+
export interface ScrollControllerConfig {
|
|
20
|
+
/** Enable compressed scroll mode (manual wheel handling) */
|
|
21
|
+
compressed?: boolean;
|
|
22
|
+
/** Compression state for calculating bounds */
|
|
23
|
+
compression?: CompressionState;
|
|
24
|
+
/**
|
|
25
|
+
* External scroll element for window/document scrolling.
|
|
26
|
+
* When set, the controller listens to this element's scroll events
|
|
27
|
+
* and computes list-relative positions from the viewport's bounding rect.
|
|
28
|
+
*/
|
|
29
|
+
scrollElement?: Window;
|
|
30
|
+
/** Allow mouse wheel to scroll (default: true) */
|
|
31
|
+
wheel?: boolean;
|
|
32
|
+
/** Wheel sensitivity multiplier (default: 1) */
|
|
33
|
+
sensitivity?: number;
|
|
34
|
+
/** Enable smooth scrolling interpolation */
|
|
35
|
+
smoothing?: boolean;
|
|
36
|
+
/** Scroll idle detection timeout in ms (default: 150) */
|
|
37
|
+
idleTimeout?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Enable horizontal scrolling mode.
|
|
40
|
+
* When true, the controller reads scrollLeft instead of scrollTop,
|
|
41
|
+
* uses clientWidth instead of clientHeight, and maps wheel deltaX.
|
|
42
|
+
*/
|
|
43
|
+
horizontal?: boolean;
|
|
44
|
+
/** Callback when scroll position changes */
|
|
45
|
+
onScroll?: (data: ScrollEventData) => void;
|
|
46
|
+
/** Callback when scrolling becomes idle */
|
|
47
|
+
onIdle?: () => void;
|
|
48
|
+
}
|
|
49
|
+
/** Scroll controller instance */
|
|
50
|
+
export interface ScrollController {
|
|
51
|
+
/** Get current scroll position */
|
|
52
|
+
getScrollTop: () => number;
|
|
53
|
+
/** Set scroll position */
|
|
54
|
+
scrollTo: (position: number, smooth?: boolean) => void;
|
|
55
|
+
/** Scroll by delta */
|
|
56
|
+
scrollBy: (delta: number) => void;
|
|
57
|
+
/** Check if at top */
|
|
58
|
+
isAtTop: () => boolean;
|
|
59
|
+
/** Check if at bottom */
|
|
60
|
+
isAtBottom: (threshold?: number) => boolean;
|
|
61
|
+
/** Get scroll percentage (0-1) */
|
|
62
|
+
getScrollPercentage: () => number;
|
|
63
|
+
/** Get current scroll velocity (px/ms, absolute value) */
|
|
64
|
+
getVelocity: () => number;
|
|
65
|
+
/**
|
|
66
|
+
* Check if the velocity tracker is actively tracking with enough samples.
|
|
67
|
+
* Returns false during ramp-up (first few frames of a new scroll gesture)
|
|
68
|
+
* when the tracker doesn't have enough samples yet.
|
|
69
|
+
*/
|
|
70
|
+
isTracking: () => boolean;
|
|
71
|
+
/** Check if currently scrolling */
|
|
72
|
+
isScrolling: () => boolean;
|
|
73
|
+
/** Update configuration (e.g., when compression state changes) */
|
|
74
|
+
updateConfig: (config: Partial<ScrollControllerConfig>) => void;
|
|
75
|
+
/** Enable compressed mode */
|
|
76
|
+
enableCompression: (compression: CompressionState) => void;
|
|
77
|
+
/** Disable compressed mode (revert to native scroll) */
|
|
78
|
+
disableCompression: () => void;
|
|
79
|
+
/** Check if compressed mode is active */
|
|
80
|
+
isCompressed: () => boolean;
|
|
81
|
+
/** Check if in window scroll mode */
|
|
82
|
+
isWindowMode: () => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Update the container height used for scroll calculations.
|
|
85
|
+
* In window mode, call this when the window resizes.
|
|
86
|
+
*/
|
|
87
|
+
updateContainerHeight: (height: number) => void;
|
|
88
|
+
/** Destroy and cleanup */
|
|
89
|
+
destroy: () => void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create a scroll controller for a viewport element
|
|
93
|
+
*
|
|
94
|
+
* Supports two modes:
|
|
95
|
+
* 1. Native scrolling (default) - uses browser's built-in scroll
|
|
96
|
+
* 2. Compressed scrolling - manual wheel handling for large lists
|
|
97
|
+
*/
|
|
98
|
+
export declare const createScrollController: (viewport: HTMLElement, config?: ScrollControllerConfig) => ScrollController;
|
|
99
|
+
/**
|
|
100
|
+
* Throttle scroll handler using requestAnimationFrame
|
|
101
|
+
*/
|
|
102
|
+
export declare const rafThrottle: <T extends (...args: any[]) => void>(fn: T) => ((...args: Parameters<T>) => void) & {
|
|
103
|
+
cancel: () => void;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Check if scroll position is at bottom
|
|
107
|
+
*/
|
|
108
|
+
export declare const isAtBottom: (scrollTop: number, scrollHeight: number, clientHeight: number, threshold?: number) => boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Check if scroll position is at top
|
|
111
|
+
*/
|
|
112
|
+
export declare const isAtTop: (scrollTop: number, threshold?: number) => boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Get scroll percentage (0-1)
|
|
115
|
+
*/
|
|
116
|
+
export declare const getScrollPercentage: (scrollTop: number, scrollHeight: number, clientHeight: number) => number;
|
|
117
|
+
/**
|
|
118
|
+
* Check if a range is visible in the scroll viewport
|
|
119
|
+
*/
|
|
120
|
+
export declare const isRangeVisible: (rangeStart: number, rangeEnd: number, visibleStart: number, visibleEnd: number) => boolean;
|
|
121
|
+
//# sourceMappingURL=controller.d.ts.map
|