@humanspeak/svelte-virtual-list 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SvelteVirtualList.svelte +10 -14
- package/dist/utils/virtualList.d.ts +33 -15
- package/dist/utils/virtualList.js +18 -15
- package/package.json +5 -5
|
@@ -167,8 +167,7 @@
|
|
|
167
167
|
calculateVisibleRange,
|
|
168
168
|
clampValue,
|
|
169
169
|
updateHeightAndScroll as utilsUpdateHeightAndScroll,
|
|
170
|
-
getScrollOffsetForIndex
|
|
171
|
-
buildBlockSums
|
|
170
|
+
getScrollOffsetForIndex
|
|
172
171
|
} from './utils/virtualList.js'
|
|
173
172
|
import { createDebugInfo, shouldShowDebugInfo } from './utils/virtualListDebug.js'
|
|
174
173
|
import { calculateScrollTarget } from './utils/scrollCalculation.js'
|
|
@@ -260,7 +259,7 @@
|
|
|
260
259
|
const est = heightManager.averageHeight
|
|
261
260
|
const maxScrollTop = Math.max(0, totalHeight - (height || 0))
|
|
262
261
|
// Offset from start to anchored item
|
|
263
|
-
const blockSums =
|
|
262
|
+
const blockSums = heightManager.getBlockSums()
|
|
264
263
|
const offsetToIndex = getScrollOffsetForIndex(cache, est, anchorIndex, blockSums)
|
|
265
264
|
const currentTop = heightManager.viewport.scrollTop
|
|
266
265
|
let offsetWithin: number
|
|
@@ -286,7 +285,7 @@
|
|
|
286
285
|
if (!pendingAnchorReconcile) return
|
|
287
286
|
const cache = heightManager.getHeightCache()
|
|
288
287
|
const est = heightManager.averageHeight
|
|
289
|
-
const blockSums =
|
|
288
|
+
const blockSums = heightManager.getBlockSums()
|
|
290
289
|
const offsetToIndex = getScrollOffsetForIndex(
|
|
291
290
|
cache,
|
|
292
291
|
est,
|
|
@@ -999,19 +998,16 @@
|
|
|
999
998
|
}
|
|
1000
999
|
}
|
|
1001
1000
|
|
|
1002
|
-
lastVisibleRange = calculateVisibleRange(
|
|
1003
|
-
heightManager.scrollTop,
|
|
1001
|
+
lastVisibleRange = calculateVisibleRange({
|
|
1002
|
+
scrollTop: heightManager.scrollTop,
|
|
1004
1003
|
viewportHeight,
|
|
1005
|
-
heightManager.averageHeight,
|
|
1006
|
-
items.length,
|
|
1004
|
+
itemHeight: heightManager.averageHeight,
|
|
1005
|
+
totalItems: items.length,
|
|
1007
1006
|
bufferSize,
|
|
1008
1007
|
mode,
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
totalHeight,
|
|
1013
|
-
heightManager.getHeightCache()
|
|
1014
|
-
)
|
|
1008
|
+
totalContentHeight: totalHeight,
|
|
1009
|
+
heightCache: heightManager.getHeightCache()
|
|
1010
|
+
})
|
|
1015
1011
|
|
|
1016
1012
|
return lastVisibleRange
|
|
1017
1013
|
})
|
|
@@ -49,27 +49,45 @@ export declare const clampValue: (value: number, min: number, max: number) => nu
|
|
|
49
49
|
* @returns {number} The maximum scroll position in pixels
|
|
50
50
|
*/
|
|
51
51
|
export declare const calculateScrollPosition: (totalItems: number, itemHeight: number, containerHeight: number) => number;
|
|
52
|
+
/** Options for {@link calculateVisibleRange}. */
|
|
53
|
+
export interface VisibleRangeOptions {
|
|
54
|
+
scrollTop: number;
|
|
55
|
+
viewportHeight: number;
|
|
56
|
+
/** Estimated/average item height used as fallback for unmeasured items. */
|
|
57
|
+
itemHeight: number;
|
|
58
|
+
totalItems: number;
|
|
59
|
+
/** Number of extra items to render outside the visible area. */
|
|
60
|
+
bufferSize: number;
|
|
61
|
+
mode: SvelteVirtualListMode;
|
|
62
|
+
/** Pre-calculated total content height; defaults to `totalItems * itemHeight`. */
|
|
63
|
+
totalContentHeight?: number;
|
|
64
|
+
/** Measured item heights keyed by index; used in topToBottom mode to walk actual heights instead of dividing by average. */
|
|
65
|
+
heightCache?: Record<number, number>;
|
|
66
|
+
}
|
|
52
67
|
/**
|
|
53
68
|
* Determines the range of items that should be rendered in the virtual list.
|
|
54
69
|
*
|
|
55
|
-
*
|
|
56
|
-
* viewport size, and scroll direction.
|
|
70
|
+
* Calculates which items should be visible based on the current scroll position,
|
|
71
|
+
* viewport size, and scroll direction. Includes a buffer zone to enable smooth scrolling
|
|
57
72
|
* and prevent visible gaps during rapid scroll movements.
|
|
58
73
|
*
|
|
59
|
-
* @param
|
|
60
|
-
* @
|
|
61
|
-
*
|
|
62
|
-
* @
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
74
|
+
* @param options - Inputs used to compute the visible range (see {@link VisibleRangeOptions}).
|
|
75
|
+
* @returns Range of indices to render.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const range = calculateVisibleRange({
|
|
80
|
+
* scrollTop: 200,
|
|
81
|
+
* viewportHeight: 400,
|
|
82
|
+
* itemHeight: 40,
|
|
83
|
+
* totalItems: 1000,
|
|
84
|
+
* bufferSize: 2,
|
|
85
|
+
* mode: 'topToBottom'
|
|
86
|
+
* })
|
|
87
|
+
* // range => { start: 3, end: 15 }
|
|
88
|
+
* ```
|
|
71
89
|
*/
|
|
72
|
-
export declare const calculateVisibleRange: (scrollTop
|
|
90
|
+
export declare const calculateVisibleRange: ({ scrollTop, viewportHeight, itemHeight, totalItems, bufferSize, mode, totalContentHeight, heightCache }: VisibleRangeOptions) => SvelteVirtualListPreviousVisibleRange;
|
|
73
91
|
/**
|
|
74
92
|
* Calculates the CSS transform value for positioning the virtual list items.
|
|
75
93
|
*
|
|
@@ -56,24 +56,27 @@ export const calculateScrollPosition = (totalItems, itemHeight, containerHeight)
|
|
|
56
56
|
/**
|
|
57
57
|
* Determines the range of items that should be rendered in the virtual list.
|
|
58
58
|
*
|
|
59
|
-
*
|
|
60
|
-
* viewport size, and scroll direction.
|
|
59
|
+
* Calculates which items should be visible based on the current scroll position,
|
|
60
|
+
* viewport size, and scroll direction. Includes a buffer zone to enable smooth scrolling
|
|
61
61
|
* and prevent visible gaps during rapid scroll movements.
|
|
62
62
|
*
|
|
63
|
-
* @param
|
|
64
|
-
* @
|
|
65
|
-
*
|
|
66
|
-
* @
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
63
|
+
* @param options - Inputs used to compute the visible range (see {@link VisibleRangeOptions}).
|
|
64
|
+
* @returns Range of indices to render.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const range = calculateVisibleRange({
|
|
69
|
+
* scrollTop: 200,
|
|
70
|
+
* viewportHeight: 400,
|
|
71
|
+
* itemHeight: 40,
|
|
72
|
+
* totalItems: 1000,
|
|
73
|
+
* bufferSize: 2,
|
|
74
|
+
* mode: 'topToBottom'
|
|
75
|
+
* })
|
|
76
|
+
* // range => { start: 3, end: 15 }
|
|
77
|
+
* ```
|
|
75
78
|
*/
|
|
76
|
-
export const calculateVisibleRange = (scrollTop, viewportHeight, itemHeight, totalItems, bufferSize, mode,
|
|
79
|
+
export const calculateVisibleRange = ({ scrollTop, viewportHeight, itemHeight, totalItems, bufferSize, mode, totalContentHeight, heightCache }) => {
|
|
77
80
|
if (mode === 'bottomToTop') {
|
|
78
81
|
const visibleCount = Math.ceil(viewportHeight / itemHeight) + 1;
|
|
79
82
|
// In bottomToTop mode, scrollTop represents distance from the total content end
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@humanspeak/svelte-virtual-list",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "A lightweight, high-performance virtual list component for Svelte 5 that renders large datasets with minimal memory usage. Features include dynamic height support, smooth scrolling, TypeScript support, and efficient DOM recycling. Ideal for infinite scrolling lists, data tables, chat interfaces, and any application requiring the rendering of thousands of items without compromising performance. Zero dependencies and fully customizable.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"svelte",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"@testing-library/svelte": "^5.3.1",
|
|
74
74
|
"@testing-library/user-event": "^14.6.1",
|
|
75
75
|
"@types/node": "^25.5.0",
|
|
76
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
77
|
-
"@typescript-eslint/parser": "^8.
|
|
76
|
+
"@typescript-eslint/eslint-plugin": "^8.58.0",
|
|
77
|
+
"@typescript-eslint/parser": "^8.58.0",
|
|
78
78
|
"@vitest/coverage-v8": "^4.1.2",
|
|
79
79
|
"eslint": "^10.1.0",
|
|
80
80
|
"eslint-config-prettier": "^10.1.8",
|
|
@@ -90,12 +90,12 @@
|
|
|
90
90
|
"prettier-plugin-svelte": "^3.5.1",
|
|
91
91
|
"prettier-plugin-tailwindcss": "^0.7.2",
|
|
92
92
|
"publint": "^0.3.18",
|
|
93
|
-
"svelte": "^5.55.
|
|
93
|
+
"svelte": "^5.55.1",
|
|
94
94
|
"svelte-check": "^4.4.5",
|
|
95
95
|
"tailwindcss": "^4.2.2",
|
|
96
96
|
"tw-animate-css": "^1.4.0",
|
|
97
97
|
"typescript": "^5.9.3",
|
|
98
|
-
"typescript-eslint": "^8.
|
|
98
|
+
"typescript-eslint": "^8.58.0",
|
|
99
99
|
"vite": "^8.0.3",
|
|
100
100
|
"vitest": "^4.1.2"
|
|
101
101
|
},
|