virtua 0.36.2 → 0.37.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/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1 -1
- package/lib/index.mjs.map +1 -1
- package/lib/react/VList.d.ts +1 -1
- package/lib/react/Virtualizer.d.ts +17 -10
- package/lib/react/WindowVirtualizer.d.ts +13 -6
- package/lib/solid/VList.d.ts +1 -1
- package/lib/solid/Virtualizer.d.ts +13 -6
- package/lib/solid/WindowVirtualizer.d.ts +22 -6
- package/lib/solid/index.d.ts +1 -1
- package/lib/solid/index.js +1 -1
- package/lib/solid/index.js.map +1 -1
- package/lib/solid/index.mjs +1 -1
- package/lib/solid/index.mjs.map +1 -1
- package/lib/svelte/VList.svelte +12 -2
- package/lib/svelte/VList.svelte.d.ts +4 -0
- package/lib/svelte/VList.type.d.ts +1 -1
- package/lib/svelte/Virtualizer.svelte +23 -29
- package/lib/svelte/Virtualizer.svelte.d.ts +4 -0
- package/lib/svelte/Virtualizer.type.d.ts +18 -6
- package/lib/svelte/WindowVirtualizer.svelte +24 -29
- package/lib/svelte/WindowVirtualizer.svelte.d.ts +4 -1
- package/lib/svelte/WindowVirtualizer.type.d.ts +16 -4
- package/lib/svelte/WindowVirtualizer.type.js +0 -9
- package/lib/svelte/core.d.ts +39 -31
- package/lib/svelte/core.js +1 -1
- package/lib/vue/VList.d.ts +2 -16
- package/lib/vue/Virtualizer.d.ts +15 -16
- package/lib/vue/WindowVirtualizer.d.ts +18 -16
- package/lib/vue/index.js +1 -1
- package/lib/vue/index.js.map +1 -1
- package/lib/vue/index.mjs +1 -1
- package/lib/vue/index.mjs.map +1 -1
- package/package.json +15 -15
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
<script lang="ts" generics="T">
|
|
2
2
|
import { onMount, onDestroy } from "svelte";
|
|
3
3
|
import {
|
|
4
|
-
SCROLL_IDLE,
|
|
5
4
|
type StateVersion,
|
|
6
|
-
getOverscanedRange,
|
|
7
5
|
CHANGE_ITEM_LENGTH,
|
|
8
6
|
createVirtualizer,
|
|
9
7
|
FIX_SCROLL_JUMP,
|
|
10
8
|
GET_ITEM_OFFSET,
|
|
11
9
|
GET_JUMP_COUNT,
|
|
12
10
|
GET_RANGE,
|
|
13
|
-
|
|
11
|
+
GET_IS_SCROLLING,
|
|
14
12
|
GET_SCROLL_OFFSET,
|
|
15
13
|
GET_SCROLL_SIZE,
|
|
16
14
|
GET_TOTAL_SIZE,
|
|
@@ -25,6 +23,9 @@
|
|
|
25
23
|
CHANGE_START_MARGIN,
|
|
26
24
|
GET_START_SPACER_SIZE,
|
|
27
25
|
GET_ITEMS_LENGTH,
|
|
26
|
+
GET_ITEM_SIZE,
|
|
27
|
+
GET_START_INDEX,
|
|
28
|
+
GET_END_INDEX,
|
|
28
29
|
} from "./core";
|
|
29
30
|
import { defaultGetKey, styleToString } from "./utils";
|
|
30
31
|
import ListItem from "./ListItem.svelte";
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
as = "div",
|
|
39
40
|
item: itemAs,
|
|
40
41
|
scrollRef,
|
|
41
|
-
overscan
|
|
42
|
+
overscan,
|
|
42
43
|
itemSize,
|
|
43
44
|
shift = false,
|
|
44
45
|
horizontal = false,
|
|
@@ -46,12 +47,12 @@
|
|
|
46
47
|
children,
|
|
47
48
|
onscroll,
|
|
48
49
|
onscrollend,
|
|
49
|
-
onrangechange,
|
|
50
50
|
}: Props = $props();
|
|
51
51
|
|
|
52
52
|
const virtualizer = createVirtualizer(
|
|
53
53
|
data.length,
|
|
54
54
|
itemSize,
|
|
55
|
+
overscan,
|
|
55
56
|
horizontal,
|
|
56
57
|
(v) => {
|
|
57
58
|
rerender = v;
|
|
@@ -69,20 +70,9 @@
|
|
|
69
70
|
let rerender: StateVersion = $state([]);
|
|
70
71
|
|
|
71
72
|
let range = $derived(rerender && virtualizer[GET_RANGE]());
|
|
72
|
-
let
|
|
73
|
-
rerender && virtualizer[GET_SCROLL_DIRECTION]()
|
|
74
|
-
);
|
|
73
|
+
let isScrolling = $derived(rerender && virtualizer[GET_IS_SCROLLING]());
|
|
75
74
|
let totalSize = $derived(rerender && virtualizer[GET_TOTAL_SIZE]());
|
|
76
75
|
let jumpCount = $derived(rerender && virtualizer[GET_JUMP_COUNT]());
|
|
77
|
-
let extendedRange = $derived(
|
|
78
|
-
getOverscanedRange(
|
|
79
|
-
range[0],
|
|
80
|
-
range[1],
|
|
81
|
-
overscan,
|
|
82
|
-
scrollDirection,
|
|
83
|
-
data.length
|
|
84
|
-
)
|
|
85
|
-
);
|
|
86
76
|
|
|
87
77
|
onMount(() => {
|
|
88
78
|
if (scrollRef) {
|
|
@@ -114,14 +104,6 @@
|
|
|
114
104
|
virtualizer[FIX_SCROLL_JUMP]();
|
|
115
105
|
});
|
|
116
106
|
|
|
117
|
-
let prevRange: typeof range | undefined;
|
|
118
|
-
$effect(() => {
|
|
119
|
-
if (prevRange && prevRange[0] === range[0] && prevRange[1] === range[1])
|
|
120
|
-
return;
|
|
121
|
-
prevRange = range;
|
|
122
|
-
onrangechange && onrangechange(range[0], range[1]);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
107
|
export const getScrollOffset = virtualizer[
|
|
126
108
|
GET_SCROLL_OFFSET
|
|
127
109
|
] satisfies VirtualizerHandle["getScrollOffset"] as VirtualizerHandle["getScrollOffset"];
|
|
@@ -131,6 +113,18 @@
|
|
|
131
113
|
export const getViewportSize = virtualizer[
|
|
132
114
|
GET_VIEWPORT_SIZE
|
|
133
115
|
] satisfies VirtualizerHandle["getViewportSize"] as VirtualizerHandle["getViewportSize"];
|
|
116
|
+
export const getStartIndex = virtualizer[
|
|
117
|
+
GET_START_INDEX
|
|
118
|
+
] satisfies VirtualizerHandle["getStartIndex"] as VirtualizerHandle["getStartIndex"];
|
|
119
|
+
export const getEndIndex = virtualizer[
|
|
120
|
+
GET_END_INDEX
|
|
121
|
+
] satisfies VirtualizerHandle["getEndIndex"] as VirtualizerHandle["getEndIndex"];
|
|
122
|
+
export const getItemOffset = virtualizer[
|
|
123
|
+
GET_ITEM_OFFSET
|
|
124
|
+
] satisfies VirtualizerHandle["getItemOffset"] as VirtualizerHandle["getItemOffset"];
|
|
125
|
+
export const getItemSize = virtualizer[
|
|
126
|
+
GET_ITEM_SIZE
|
|
127
|
+
] satisfies VirtualizerHandle["getItemSize"] as VirtualizerHandle["getItemSize"];
|
|
134
128
|
export const scrollToIndex = virtualizer[
|
|
135
129
|
SCROLL_TO_INDEX
|
|
136
130
|
] satisfies VirtualizerHandle["scrollToIndex"] as VirtualizerHandle["scrollToIndex"];
|
|
@@ -142,7 +136,7 @@
|
|
|
142
136
|
] satisfies VirtualizerHandle["scrollBy"] as VirtualizerHandle["scrollBy"];
|
|
143
137
|
|
|
144
138
|
let items = $derived.by(() => {
|
|
145
|
-
const [startIndex, endIndex] =
|
|
139
|
+
const [startIndex, endIndex] = range;
|
|
146
140
|
const newItems: T[] = [];
|
|
147
141
|
for (let i = startIndex, j = endIndex; i <= j; i++) {
|
|
148
142
|
newItems.push(data[i]!);
|
|
@@ -159,7 +153,7 @@
|
|
|
159
153
|
visibility: "hidden", // TODO replace with other optimization methods
|
|
160
154
|
width: horizontal ? totalSize + "px" : "100%",
|
|
161
155
|
height: horizontal ? "100%" : totalSize + "px",
|
|
162
|
-
"pointer-events":
|
|
156
|
+
"pointer-events": isScrolling ? "none" : undefined,
|
|
163
157
|
})
|
|
164
158
|
);
|
|
165
159
|
</script>
|
|
@@ -169,8 +163,8 @@
|
|
|
169
163
|
Customizable list virtualizer for advanced usage. See {@link VirtualizerProps} and {@link VirtualizerHandle}.
|
|
170
164
|
-->
|
|
171
165
|
<svelte:element this={as} bind:this={containerRef} style={containerStyle}>
|
|
172
|
-
{#each items as item, i (getKey(item, i +
|
|
173
|
-
{@const index = i +
|
|
166
|
+
{#each items as item, i (getKey(item, i + range[0]))}
|
|
167
|
+
{@const index = i + range[0]}
|
|
174
168
|
<ListItem
|
|
175
169
|
{children}
|
|
176
170
|
{item}
|
|
@@ -8,6 +8,10 @@ declare class __sveltets_Render<T> {
|
|
|
8
8
|
getScrollOffset: () => number;
|
|
9
9
|
getScrollSize: () => number;
|
|
10
10
|
getViewportSize: () => number;
|
|
11
|
+
getStartIndex: () => number;
|
|
12
|
+
getEndIndex: () => number;
|
|
13
|
+
getItemOffset: (index: number) => number;
|
|
14
|
+
getItemSize: (index: number) => number;
|
|
11
15
|
scrollToIndex: (index: number, opts?: import("../core/types").ScrollToIndexOpts) => void;
|
|
12
16
|
scrollTo: (offset: number) => void;
|
|
13
17
|
scrollBy: (offset: number) => void;
|
|
@@ -66,12 +66,6 @@ export interface VirtualizerProps<T> {
|
|
|
66
66
|
* Callback invoked when scrolling stops.
|
|
67
67
|
*/
|
|
68
68
|
onscrollend?: () => void;
|
|
69
|
-
/**
|
|
70
|
-
* Callback invoked when visible items range changes.
|
|
71
|
-
* @param startIndex The start index of viewable items.
|
|
72
|
-
* @param endIndex The end index of viewable items.
|
|
73
|
-
*/
|
|
74
|
-
onrangechange?: (startIndex: number, endIndex: number) => void;
|
|
75
69
|
}
|
|
76
70
|
/**
|
|
77
71
|
* Methods of {@link Virtualizer}.
|
|
@@ -89,6 +83,24 @@ export interface VirtualizerHandle {
|
|
|
89
83
|
* Get current offsetHeight, or offsetWidth if horizontal: true.
|
|
90
84
|
*/
|
|
91
85
|
getViewportSize: () => number;
|
|
86
|
+
/**
|
|
87
|
+
* Get the start index of visible range of items.
|
|
88
|
+
*/
|
|
89
|
+
getStartIndex: () => number;
|
|
90
|
+
/**
|
|
91
|
+
* Get the end index of visible range of items.
|
|
92
|
+
*/
|
|
93
|
+
getEndIndex: () => number;
|
|
94
|
+
/**
|
|
95
|
+
* Get item offset from start.
|
|
96
|
+
* @param index index of item
|
|
97
|
+
*/
|
|
98
|
+
getItemOffset(index: number): number;
|
|
99
|
+
/**
|
|
100
|
+
* Get item size.
|
|
101
|
+
* @param index index of item
|
|
102
|
+
*/
|
|
103
|
+
getItemSize(index: number): number;
|
|
92
104
|
/**
|
|
93
105
|
* Scroll to the item specified by index.
|
|
94
106
|
* @param index index of item
|
|
@@ -1,48 +1,55 @@
|
|
|
1
1
|
<script lang="ts" generics="T">
|
|
2
2
|
import { onMount, onDestroy } from "svelte";
|
|
3
3
|
import {
|
|
4
|
-
SCROLL_IDLE,
|
|
5
4
|
type StateVersion,
|
|
6
|
-
getOverscanedRange,
|
|
7
5
|
CHANGE_ITEM_LENGTH,
|
|
8
6
|
createWindowVirtualizer,
|
|
9
7
|
FIX_SCROLL_JUMP,
|
|
10
8
|
GET_ITEM_OFFSET,
|
|
11
9
|
GET_JUMP_COUNT,
|
|
12
10
|
GET_RANGE,
|
|
13
|
-
|
|
11
|
+
GET_IS_SCROLLING,
|
|
14
12
|
GET_TOTAL_SIZE,
|
|
15
13
|
IS_ITEM_HIDDEN,
|
|
16
14
|
OBSERVE_ITEM_RESIZE,
|
|
17
15
|
ON_MOUNT,
|
|
18
16
|
ON_UN_MOUNT,
|
|
19
17
|
GET_ITEMS_LENGTH,
|
|
18
|
+
GET_START_INDEX,
|
|
19
|
+
GET_END_INDEX,
|
|
20
20
|
} from "./core";
|
|
21
21
|
import { defaultGetKey, styleToString } from "./utils";
|
|
22
22
|
import ListItem from "./ListItem.svelte";
|
|
23
|
-
import type {
|
|
23
|
+
import type {
|
|
24
|
+
WindowVirtualizerHandle,
|
|
25
|
+
WindowVirtualizerProps,
|
|
26
|
+
} from "./WindowVirtualizer.type";
|
|
24
27
|
|
|
25
28
|
interface Props extends WindowVirtualizerProps<T> {}
|
|
26
29
|
|
|
27
30
|
let {
|
|
28
31
|
data,
|
|
29
32
|
getKey = defaultGetKey,
|
|
30
|
-
overscan
|
|
33
|
+
overscan,
|
|
31
34
|
itemSize,
|
|
32
35
|
shift = false,
|
|
33
36
|
horizontal = false,
|
|
34
37
|
children,
|
|
38
|
+
onscroll,
|
|
35
39
|
onscrollend,
|
|
36
|
-
onrangechange,
|
|
37
40
|
}: Props = $props();
|
|
38
41
|
|
|
39
42
|
const virtualizer = createWindowVirtualizer(
|
|
40
43
|
data.length,
|
|
41
44
|
itemSize,
|
|
45
|
+
overscan,
|
|
42
46
|
horizontal,
|
|
43
47
|
(v) => {
|
|
44
48
|
rerender = v;
|
|
45
49
|
},
|
|
50
|
+
(offset) => {
|
|
51
|
+
onscroll && onscroll(offset);
|
|
52
|
+
},
|
|
46
53
|
() => {
|
|
47
54
|
onscrollend && onscrollend();
|
|
48
55
|
}
|
|
@@ -53,20 +60,9 @@
|
|
|
53
60
|
let rerender: StateVersion = $state([]);
|
|
54
61
|
|
|
55
62
|
let range = $derived(rerender && virtualizer[GET_RANGE]());
|
|
56
|
-
let
|
|
57
|
-
rerender && virtualizer[GET_SCROLL_DIRECTION]()
|
|
58
|
-
);
|
|
63
|
+
let isScrolling = $derived(rerender && virtualizer[GET_IS_SCROLLING]());
|
|
59
64
|
let totalSize = $derived(rerender && virtualizer[GET_TOTAL_SIZE]());
|
|
60
65
|
let jumpCount = $derived(rerender && virtualizer[GET_JUMP_COUNT]());
|
|
61
|
-
let extendedRange = $derived(
|
|
62
|
-
getOverscanedRange(
|
|
63
|
-
range[0],
|
|
64
|
-
range[1],
|
|
65
|
-
overscan,
|
|
66
|
-
scrollDirection,
|
|
67
|
-
data.length
|
|
68
|
-
)
|
|
69
|
-
);
|
|
70
66
|
|
|
71
67
|
onMount(() => {
|
|
72
68
|
virtualizer[ON_MOUNT](containerRef!);
|
|
@@ -88,16 +84,15 @@
|
|
|
88
84
|
virtualizer[FIX_SCROLL_JUMP]();
|
|
89
85
|
});
|
|
90
86
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
});
|
|
87
|
+
export const getStartIndex = virtualizer[
|
|
88
|
+
GET_START_INDEX
|
|
89
|
+
] satisfies WindowVirtualizerHandle["getStartIndex"] as WindowVirtualizerHandle["getStartIndex"];
|
|
90
|
+
export const getEndIndex = virtualizer[
|
|
91
|
+
GET_END_INDEX
|
|
92
|
+
] satisfies WindowVirtualizerHandle["getEndIndex"] as WindowVirtualizerHandle["getEndIndex"];
|
|
98
93
|
|
|
99
94
|
let items = $derived.by(() => {
|
|
100
|
-
const [startIndex, endIndex] =
|
|
95
|
+
const [startIndex, endIndex] = range;
|
|
101
96
|
const newItems: T[] = [];
|
|
102
97
|
for (let i = startIndex, j = endIndex; i <= j; i++) {
|
|
103
98
|
newItems.push(data[i]!);
|
|
@@ -114,7 +109,7 @@
|
|
|
114
109
|
visibility: "hidden", // TODO replace with other optimization methods
|
|
115
110
|
width: horizontal ? totalSize + "px" : "100%",
|
|
116
111
|
height: horizontal ? "100%" : totalSize + "px",
|
|
117
|
-
"pointer-events":
|
|
112
|
+
"pointer-events": isScrolling ? "none" : undefined,
|
|
118
113
|
})
|
|
119
114
|
);
|
|
120
115
|
</script>
|
|
@@ -124,8 +119,8 @@
|
|
|
124
119
|
{@link Virtualizer} controlled by the window scrolling. See {@link WindowVirtualizerProps} and {@link WindowVirtualizerHandle}.
|
|
125
120
|
-->
|
|
126
121
|
<div bind:this={containerRef} style={containerStyle}>
|
|
127
|
-
{#each items as item, i (getKey(item, i +
|
|
128
|
-
{@const index = i +
|
|
122
|
+
{#each items as item, i (getKey(item, i + range[0]))}
|
|
123
|
+
{@const index = i + range[0]}
|
|
129
124
|
<ListItem
|
|
130
125
|
{children}
|
|
131
126
|
{item}
|
|
@@ -4,7 +4,10 @@ declare class __sveltets_Render<T> {
|
|
|
4
4
|
events(): {};
|
|
5
5
|
slots(): {};
|
|
6
6
|
bindings(): "";
|
|
7
|
-
exports(): {
|
|
7
|
+
exports(): {
|
|
8
|
+
getStartIndex: () => number;
|
|
9
|
+
getEndIndex: () => number;
|
|
10
|
+
};
|
|
8
11
|
}
|
|
9
12
|
interface $$IsomorphicComponent {
|
|
10
13
|
new <T>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
@@ -37,14 +37,26 @@ export interface WindowVirtualizerProps<T> {
|
|
|
37
37
|
* If true, rendered as a horizontally scrollable list. Otherwise rendered as a vertically scrollable list.
|
|
38
38
|
*/
|
|
39
39
|
horizontal?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Callback invoked whenever scroll offset changes.
|
|
42
|
+
* @param offset Current scrollTop, or scrollLeft if horizontal: true.
|
|
43
|
+
*/
|
|
44
|
+
onscroll?: (offset: number) => void;
|
|
40
45
|
/**
|
|
41
46
|
* Callback invoked when scrolling stops.
|
|
42
47
|
*/
|
|
43
48
|
onscrollend?: () => void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Methods of {@link WindowVirtualizer}.
|
|
52
|
+
*/
|
|
53
|
+
export interface WindowVirtualizerHandle {
|
|
54
|
+
/**
|
|
55
|
+
* Get the start index of visible range of items.
|
|
56
|
+
*/
|
|
57
|
+
getStartIndex: () => number;
|
|
44
58
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @param startIndex The start index of viewable items.
|
|
47
|
-
* @param endIndex The end index of viewable items.
|
|
59
|
+
* Get the end index of visible range of items.
|
|
48
60
|
*/
|
|
49
|
-
|
|
61
|
+
getEndIndex: () => number;
|
|
50
62
|
}
|
package/lib/svelte/core.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
import { type StateVersion } from "../core/store";
|
|
3
|
-
export {
|
|
3
|
+
export { type StateVersion } from "../core/store";
|
|
4
4
|
export { isRTLDocument } from "../core/environment";
|
|
5
5
|
export type { ItemResizeObserver } from "../core/resizer";
|
|
6
6
|
export declare const ON_MOUNT = 0;
|
|
@@ -9,63 +9,71 @@ export declare const GET_RANGE = 2;
|
|
|
9
9
|
export declare const GET_TOTAL_SIZE = 3;
|
|
10
10
|
export declare const GET_VIEWPORT_SIZE = 4;
|
|
11
11
|
export declare const GET_SCROLL_OFFSET = 5;
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const GET_IS_SCROLLING = 6;
|
|
13
13
|
export declare const GET_JUMP_COUNT = 7;
|
|
14
14
|
export declare const GET_ITEM_OFFSET = 8;
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
25
|
-
export declare const
|
|
15
|
+
export declare const GET_ITEM_SIZE = 9;
|
|
16
|
+
export declare const IS_ITEM_HIDDEN = 10;
|
|
17
|
+
export declare const GET_ITEMS_LENGTH = 11;
|
|
18
|
+
export declare const GET_START_SPACER_SIZE = 12;
|
|
19
|
+
export declare const OBSERVE_ITEM_RESIZE = 13;
|
|
20
|
+
export declare const FIX_SCROLL_JUMP = 14;
|
|
21
|
+
export declare const CHANGE_ITEM_LENGTH = 15;
|
|
22
|
+
export declare const CHANGE_START_MARGIN = 16;
|
|
23
|
+
export declare const GET_SCROLL_SIZE = 17;
|
|
24
|
+
export declare const SCROLL_TO = 18;
|
|
25
|
+
export declare const SCROLL_BY = 19;
|
|
26
|
+
export declare const SCROLL_TO_INDEX = 20;
|
|
27
|
+
export declare const GET_START_INDEX = 21;
|
|
28
|
+
export declare const GET_END_INDEX = 22;
|
|
26
29
|
/**
|
|
27
30
|
* This function is workaround for terser minification.
|
|
28
31
|
* Svelte doesn't seem to have a good way to modify and print its AST.
|
|
29
32
|
*/
|
|
30
|
-
export declare const createVirtualizer: (count: number, itemSize: number | undefined, horizontal: boolean, onUpdate: (v: StateVersion) => void, onScroll: (offset: number) => void, onScrollEnd: () => void) => {
|
|
33
|
+
export declare const createVirtualizer: (count: number, itemSize: number | undefined, overscan: number | undefined, horizontal: boolean, onUpdate: (v: StateVersion) => void, onScroll: (offset: number) => void, onScrollEnd: () => void) => {
|
|
31
34
|
0: (scrollable: HTMLElement) => void;
|
|
32
35
|
1: () => void;
|
|
33
36
|
2: () => import("../core/types").ItemsRange;
|
|
34
37
|
3: () => number;
|
|
35
38
|
4: () => number;
|
|
36
39
|
5: () => number;
|
|
37
|
-
6: () =>
|
|
40
|
+
6: () => boolean;
|
|
38
41
|
7: () => number;
|
|
39
42
|
8: (index: number) => number;
|
|
40
|
-
9: (index: number) =>
|
|
41
|
-
10: () =>
|
|
43
|
+
9: (index: number) => number;
|
|
44
|
+
10: (index: number) => boolean;
|
|
42
45
|
11: () => number;
|
|
43
|
-
12:
|
|
44
|
-
13: ()
|
|
45
|
-
14: (
|
|
46
|
-
15: (
|
|
47
|
-
16: () =>
|
|
48
|
-
17: (
|
|
46
|
+
12: () => number;
|
|
47
|
+
13: import("./core").ItemResizeObserver;
|
|
48
|
+
14: () => void;
|
|
49
|
+
15: (len: number, shift?: boolean) => void;
|
|
50
|
+
16: (value: number) => void;
|
|
51
|
+
17: () => number;
|
|
49
52
|
18: (offset: number) => void;
|
|
50
|
-
19: (
|
|
53
|
+
19: (offset: number) => void;
|
|
54
|
+
20: (index: number, opts?: import("..").ScrollToIndexOpts) => void;
|
|
55
|
+
21: () => number;
|
|
56
|
+
22: () => number;
|
|
51
57
|
};
|
|
52
58
|
/**
|
|
53
59
|
* This function is workaround for terser minification.
|
|
54
60
|
* Svelte doesn't seem to have a good way to modify and print its AST.
|
|
55
61
|
*/
|
|
56
|
-
export declare const createWindowVirtualizer: (count: number, itemSize: number | undefined, horizontal: boolean, onUpdate: (v: StateVersion) => void, onScrollEnd: () => void) => {
|
|
62
|
+
export declare const createWindowVirtualizer: (count: number, itemSize: number | undefined, overscan: number | undefined, horizontal: boolean, onUpdate: (v: StateVersion) => void, onScroll: (offset: number) => void, onScrollEnd: () => void) => {
|
|
57
63
|
0: (scrollable: HTMLElement) => void;
|
|
58
64
|
1: () => void;
|
|
59
65
|
2: () => import("../core/types").ItemsRange;
|
|
60
66
|
3: () => number;
|
|
61
67
|
4: () => number;
|
|
62
68
|
5: () => number;
|
|
63
|
-
6: () =>
|
|
69
|
+
6: () => boolean;
|
|
64
70
|
7: () => number;
|
|
65
71
|
8: (index: number) => number;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
10: (index: number) => boolean;
|
|
73
|
+
11: () => number;
|
|
74
|
+
13: import("./core").ItemResizeObserver;
|
|
75
|
+
14: () => void;
|
|
76
|
+
15: (len: number, shift?: boolean) => void;
|
|
77
|
+
21: () => number;
|
|
78
|
+
22: () => number;
|
|
71
79
|
};
|
package/lib/svelte/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=null,{min:t,max:
|
|
1
|
+
const e=null,{min:t,max:r,abs:o,floor:n}=Math,s=setTimeout,c=(e,o,n)=>t(n,r(o,e)),i="function"==typeof queueMicrotask?queueMicrotask:e=>{Promise.resolve().then(e)},l=e=>{let t,r;return()=>(t||(t=!0,r=e()),r)},u=-1,a=(e,t,r)=>{const o=r?"unshift":"push";for(let r=0;r<t;r++)e[o](u);return e},f=(e,t)=>{const r=e.t[t];return r===u?e.o:r},_=(e,r,o)=>{const n=e.t[r]===u;return e.t[r]=o,e.i=t(r,e.i),n},d=(e,t)=>{if(!e.l)return 0;if(e.i>=t)return e.u[t];e.i<0&&(e.u[0]=0,e.i=0);let r=e.i,o=e.u[r];for(;r<t;)o+=f(e,r),e.u[++r]=o;return e.i=t,o},h=(e,t,r=0,o=e.l-1)=>{for(;r<=o;){const s=n((r+o)/2),c=d(e,s);if(c<=t){if(c+f(e,s)>t)return s;r=s+1}else o=s-1}return c(r,0,e.l-1)},p=(e,r,o)=>{const n=r-e.l;return e.i=o?-1:t(r-1,e.i),e.l=r,n>0?(a(e.u,n),a(e.t,n,o),e.o*n):(e.u.splice(n),(o?e.t.splice(0,-n):e.t.splice(n)).reduce(((t,r)=>t-(r===u?e.o:r)),0))},g="undefined"!=typeof window,m=()=>document.documentElement,v=e=>e.ownerDocument,b=e=>e.defaultView,w=/*#__PURE__*/l((()=>!!g&&"rtl"===getComputedStyle(m()).direction)),S=/*#__PURE__*/l((()=>/iP(hone|od|ad)/.test(navigator.userAgent))),I=/*#__PURE__*/l((()=>"scrollBehavior"in m().style)),k=(n,s=40,c=4,i=0,l,g=!1)=>{let m=!!i,v=[],b=0,w=0,I=0,k=0,x=0,y=0,z=0,T=0,R=0,J=m?[0,r(i-1,0)]:e,M=[0,0],C=0;const L=((e,t)=>({o:t,t:a([],e),l:e,i:-1,u:a([],e)}))(n,s),O=new Set,P=()=>I-w,W=()=>P()+y+x,q=e=>((e,r,o,n)=>{if(n=t(n,e.l-1),d(e,n)<=r){const t=h(e,r+o,n);return[h(e,r,n,t),t]}{const t=h(e,r,void 0,n);return[t,h(e,r+o,t)]}})(L,e,b,M[0]),B=()=>(e=>e.l?d(e,e.l-1)+f(e,e.l-1):0)(L),U=e=>d(L,e)-y,V=e=>f(L,e),X=e=>{e&&(S()&&0!==T?y+=e:(x+=e,k++))};return{_:()=>v,h:()=>(e=>[e.t.slice(),e.o])(L),p:()=>{if(z)return M;let[e,o]=q(r(0,W()));return J&&(e=t(e,J[0]),o=r(o,J[1])),1!==T&&(e-=r(0,c)),2!==T&&(o+=r(0,c)),M=[r(e,0),t(o,L.l-1)]},m:()=>h(L,W()),v:()=>h(L,W()+b),S:e=>L.t[e]===u,I:()=>!!J&&L.t.slice(r(0,J[0]-1),t(L.l-1,J[1]+1)+1).includes(u),k:U,T:V,R:()=>L.l,J:()=>I,M:()=>0!==T,C:()=>b,L:()=>w,O:B,P:()=>k,W:()=>(z=x,x=0,[z,2===R||P()+b>=B()]),q:(e,t)=>{const r=[e,t];return O.add(r),()=>{O.delete(r)}},B:(t,n)=>{let s,c,i=0;switch(t){case 1:{const t=z;z=0;const r=n-I,s=o(r);t&&s<o(t)+1||0!==R||(T=r<0?2:1),m&&(J=e,m=!1),I=n,i=4;const l=P();l>=-b&&l<=B()&&(i+=1,c=s>b);break}case 2:i=8,0!==T&&(s=!0,i+=1),T=0,R=0,J=e;break;case 3:{const e=n.filter((([e,t])=>L.t[e]!==t));if(!e.length)break;X(e.reduce(((e,[t,r])=>((2===R||(J?t<J[0]:U(t)+(0===T&&0===R?V(t):0)<P()))&&(e+=r-V(t)),e)),0));for(const[t,r]of e){const e=V(t),o=_(L,t,r);g&&(C+=o?r:r-e)}g&&b&&C>b&&(X(((e,t)=>{let o=0;const n=e.t.filter(((e,r)=>{const n=e!==u;return n&&r<t&&o++,n})),s=e.o;return e.i=-1,((e.o=(e=>{const t=(e=>[...e].sort(((e,t)=>e-t)))(e),r=e.length/2|0;return t.length%2==0?(t[r-1]+t[r])/2:t[r]})(n))-s)*r(t-o,0)})(L,h(L,W()))),g=!1),i=3,c=!0;break}case 4:b!==n&&(b=n,i=3);break;case 5:n[1]?(X(p(L,n[0],!0)),R=2,i=1):p(L,n[0]);break;case 6:w=n;break;case 7:R=1;break;case 8:J=q(n),i=1}i&&(v=[],s&&y&&(x+=y,y=0,k++),O.forEach((([e,t])=>{i&e&&t(c)})))}}},x=e=>{let t;return{U(r){(t||(t=new(b(v(r)).ResizeObserver)(e))).observe(r)},V(e){t.unobserve(e)},X(){t&&t.disconnect()}}},y=(e,t)=>t&&w()?-e:e,z=(t,r,o,n,c,i)=>{const l=Date.now;let u=0,a=!1,f=!1,_=!1,d=!1;const h=(()=>{let r;const o=()=>{r!=e&&clearTimeout(r)},n=()=>{o(),r=s((()=>{r=e,(()=>{if(a||f)return a=!1,void h();_=!1,t.B(2)})()}),150)};return n.Y=o,n})(),p=()=>{u=l(),_&&(d=!0),i&&t.B(6,i()),t.B(1,n()),h()},g=e=>{if(a||!t.M()||e.ctrlKey)return;const r=l()-u;150>r&&50<r&&(o?e.deltaX:e.deltaY)&&(a=!0)},m=()=>{f=!0,_=d=!1},v=()=>{f=!1,S()&&(_=!0)};return r.addEventListener("scroll",p),r.addEventListener("wheel",g,{passive:!0}),r.addEventListener("touchstart",m,{passive:!0}),r.addEventListener("touchend",v,{passive:!0}),{X:()=>{r.removeEventListener("scroll",p),r.removeEventListener("wheel",g),r.removeEventListener("touchstart",m),r.removeEventListener("touchend",v),h.Y()},D:()=>{const[e,r]=t.W();e&&(c(y(e,o),r,d),d=!1,r&&t.C()>t.O()&&t.B(1,n()))}}},T=0,R=1,J=2,M=3,C=4,L=5,O=6,P=7,W=8,q=9,B=10,U=11,V=12,X=13,Y=14,D=15,E=16,F=17,H=18,j=19,A=20,G=21,K=22,N=(t,o,n,l,u,a,f)=>{const _=k(t,o,n,void 0,0,!o),d=((t,r)=>{let o;const n=r?"width":"height",s=new WeakMap,c=x((r=>{const c=[];for(const{target:i,contentRect:l}of r)if(i.offsetParent)if(i===o)t.B(4,l[n]);else{const t=s.get(i);t!=e&&c.push([t,l[n]])}c.length&&t.B(3,c)}));return{F(e){c.U(o=e)},H:(e,t)=>(s.set(e,t),c.U(e),()=>{s.delete(e),c.V(e)}),X:c.X}})(_,l),h=((e,t)=>{let r,o,n;const l=t?"scrollLeft":"scrollTop",u=t?"overflowX":"overflowY",a=async(o,c)=>{if(!r)return void i((()=>a(o,c)));n&&n();const u=()=>{let t;return[new Promise(((r,o)=>{t=r,n=o,(e=>!!e.C())(e)&&s(o,150)})),e.q(2,(()=>{t&&t()}))]};if(c&&I()){for(;e.B(8,o()),e.I();){const[e,t]=u();try{await e}catch(e){return}finally{t()}}r.scrollTo({[t?"left":"top"]:y(o(),t),behavior:"smooth"})}else for(;;){const[n,s]=u();try{r[l]=y(o(),t),e.B(7),await n}catch(e){return}finally{s()}}};return{U(c){r=c,o=z(e,c,t,(()=>y(c[l],t)),((t,r,o)=>{if(o){const e=c.style,t=e[u];e[u]="hidden",s((()=>{e[u]=t}))}r?(c[l]=e.J()+t,n&&n()):c[l]+=t}))},X(){o&&o.X()},j(e){a((()=>e))},A(t){t+=e.J(),a((()=>t))},G(t,{align:r,smooth:o,offset:n=0}={}){if(t=c(t,0,e.R()-1),"nearest"===r){const o=e.k(t),n=e.J();if(o<n)r="start";else{if(!(o+e.T(t)>n+e.C()))return;r="end"}}a((()=>n+e.L()+e.k(t)+("end"===r?e.T(t)-e.C():"center"===r?(e.T(t)-e.C())/2:0)),o)},D:()=>{o&&o.D()}}})(_,l),p=_.q(1,(()=>{u(_._())})),g=_.q(4,(()=>{a(_.J())})),m=_.q(8,(()=>{f()}));return{[T]:e=>{d.F(e),h.U(e)},[R]:()=>{p(),g(),m(),d.X(),h.X()},[J]:_.p,[M]:_.O,[C]:_.C,[L]:_.J,[O]:_.M,[P]:_.P,[W]:_.k,[q]:_.T,[B]:_.S,[U]:_.R,[V]:_.L,[X]:d.H,[Y]:h.D,[D]:(e,t)=>{_.B(5,[e,t])},[E]:e=>{_.B(6,e)},[F]:()=>(e=>r(e.O(),e.C()))(_),[H]:h.j,[j]:h.A,[A]:h.G,[G]:_.m,[K]:_.v}},Q=(t,r,o,n,s,c,i)=>{const l=k(t,r,o,void 0,0,!r),u=((t,r)=>{const o=r?"width":"height",n=r?"innerWidth":"innerHeight",s=new WeakMap,c=x((r=>{const n=[];for(const{target:t,contentRect:c}of r){if(!t.offsetParent)continue;const r=s.get(t);r!=e&&n.push([r,c[o]])}n.length&&t.B(3,n)}));let i;return{F(e){const r=b(v(e)),o=()=>{t.B(4,r[n])};r.addEventListener("resize",o),o(),i=()=>{r.removeEventListener("resize",o)}},H:(e,t)=>(s.set(e,t),c.U(e),()=>{s.delete(e),c.V(e)}),X(){i&&i(),c.X()}}})(l,n),a=((e,t)=>{let r;return{U(o){const n=t?"scrollX":"scrollY",s=v(o),c=b(s),i=s.body,l=(e,t,r,o=0)=>{const n=r?"offsetLeft":"offsetTop",s=o+(r&&w()?c.innerWidth-e[n]-e.offsetWidth:e[n]),i=e.offsetParent;return e!==t&&i?l(i,t,r,s):s};r=z(e,c,t,(()=>y(c[n],t)),((r,o)=>{o?c.scroll({[t?"left":"top"]:e.J()+r}):c.scrollBy(t?r:0,t?0:r)}),(()=>l(o,i,t)))},X(){r&&r.X()},D:()=>{r&&r.D()}}})(l,n),f=l.q(1,(()=>{s(l._())})),_=l.q(4,(()=>{c(l.J())})),d=l.q(8,(()=>{i()}));return{[T]:e=>{u.F(e),a.U(e)},[R]:()=>{f(),_(),d(),u.X(),a.X()},[J]:l.p,[M]:l.O,[C]:l.C,[L]:l.J,[O]:l.M,[P]:l.P,[W]:l.k,[B]:l.S,[U]:l.R,[X]:u.H,[Y]:a.D,[D]:(e,t)=>{l.B(5,[e,t])},[G]:l.m,[K]:l.v}};export{D as CHANGE_ITEM_LENGTH,E as CHANGE_START_MARGIN,Y as FIX_SCROLL_JUMP,K as GET_END_INDEX,O as GET_IS_SCROLLING,U as GET_ITEMS_LENGTH,W as GET_ITEM_OFFSET,q as GET_ITEM_SIZE,P as GET_JUMP_COUNT,J as GET_RANGE,L as GET_SCROLL_OFFSET,F as GET_SCROLL_SIZE,G as GET_START_INDEX,V as GET_START_SPACER_SIZE,M as GET_TOTAL_SIZE,C as GET_VIEWPORT_SIZE,B as IS_ITEM_HIDDEN,X as OBSERVE_ITEM_RESIZE,T as ON_MOUNT,R as ON_UN_MOUNT,j as SCROLL_BY,H as SCROLL_TO,A as SCROLL_TO_INDEX,N as createVirtualizer,Q as createWindowVirtualizer,w as isRTLDocument};
|
package/lib/vue/VList.d.ts
CHANGED
|
@@ -15,10 +15,7 @@ export declare const VList: import("vue").DefineComponent<{
|
|
|
15
15
|
* Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.
|
|
16
16
|
* @defaultValue 4
|
|
17
17
|
*/
|
|
18
|
-
overscan:
|
|
19
|
-
type: NumberConstructor;
|
|
20
|
-
default: number;
|
|
21
|
-
};
|
|
18
|
+
overscan: NumberConstructor;
|
|
22
19
|
/**
|
|
23
20
|
* Item size hint for unmeasured items. It will help to reduce scroll jump when items are measured if used properly.
|
|
24
21
|
*
|
|
@@ -48,12 +45,6 @@ export declare const VList: import("vue").DefineComponent<{
|
|
|
48
45
|
* Callback invoked when scrolling stops.
|
|
49
46
|
*/
|
|
50
47
|
scrollEnd: () => void;
|
|
51
|
-
/**
|
|
52
|
-
* Callback invoked when visible items range changes.
|
|
53
|
-
* @param startIndex The start index of viewable items.
|
|
54
|
-
* @param endIndex The end index of viewable items.
|
|
55
|
-
*/
|
|
56
|
-
rangeChange: (startIndex: number, endIndex: number) => void;
|
|
57
48
|
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
58
49
|
/**
|
|
59
50
|
* The data items rendered by this component.
|
|
@@ -66,10 +57,7 @@ export declare const VList: import("vue").DefineComponent<{
|
|
|
66
57
|
* Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.
|
|
67
58
|
* @defaultValue 4
|
|
68
59
|
*/
|
|
69
|
-
overscan:
|
|
70
|
-
type: NumberConstructor;
|
|
71
|
-
default: number;
|
|
72
|
-
};
|
|
60
|
+
overscan: NumberConstructor;
|
|
73
61
|
/**
|
|
74
62
|
* Item size hint for unmeasured items. It will help to reduce scroll jump when items are measured if used properly.
|
|
75
63
|
*
|
|
@@ -92,10 +80,8 @@ export declare const VList: import("vue").DefineComponent<{
|
|
|
92
80
|
}>> & {
|
|
93
81
|
onScroll?: ((offset: number) => any) | undefined;
|
|
94
82
|
onScrollEnd?: (() => any) | undefined;
|
|
95
|
-
onRangeChange?: ((startIndex: number, endIndex: number) => any) | undefined;
|
|
96
83
|
}, {
|
|
97
84
|
shift: boolean;
|
|
98
|
-
overscan: number;
|
|
99
85
|
horizontal: boolean;
|
|
100
86
|
}, SlotsType<{
|
|
101
87
|
default: (arg: {
|
package/lib/vue/Virtualizer.d.ts
CHANGED
|
@@ -14,11 +14,24 @@ export interface VirtualizerHandle {
|
|
|
14
14
|
* Get current offsetHeight, or offsetWidth if horizontal: true.
|
|
15
15
|
*/
|
|
16
16
|
readonly viewportSize: number;
|
|
17
|
+
/**
|
|
18
|
+
* Get the start index of visible range of items.
|
|
19
|
+
*/
|
|
20
|
+
readonly startIndex: number;
|
|
21
|
+
/**
|
|
22
|
+
* Get the end index of visible range of items.
|
|
23
|
+
*/
|
|
24
|
+
readonly endIndex: number;
|
|
17
25
|
/**
|
|
18
26
|
* Get item offset from start.
|
|
19
27
|
* @param index index of item
|
|
20
28
|
*/
|
|
21
29
|
getItemOffset(index: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Get item size.
|
|
32
|
+
* @param index index of item
|
|
33
|
+
*/
|
|
34
|
+
getItemSize(index: number): number;
|
|
22
35
|
/**
|
|
23
36
|
* Scroll to the item specified by index.
|
|
24
37
|
* @param index index of item
|
|
@@ -48,10 +61,7 @@ export declare const Virtualizer: import("vue").DefineComponent<{
|
|
|
48
61
|
* Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.
|
|
49
62
|
* @defaultValue 4
|
|
50
63
|
*/
|
|
51
|
-
overscan:
|
|
52
|
-
type: NumberConstructor;
|
|
53
|
-
default: number;
|
|
54
|
-
};
|
|
64
|
+
overscan: NumberConstructor;
|
|
55
65
|
/**
|
|
56
66
|
* Item size hint for unmeasured items. It will help to reduce scroll jump when items are measured if used properly.
|
|
57
67
|
*
|
|
@@ -108,12 +118,6 @@ export declare const Virtualizer: import("vue").DefineComponent<{
|
|
|
108
118
|
* Callback invoked when scrolling stops.
|
|
109
119
|
*/
|
|
110
120
|
scrollEnd: () => void;
|
|
111
|
-
/**
|
|
112
|
-
* Callback invoked when visible items range changes.
|
|
113
|
-
* @param startIndex The start index of viewable items.
|
|
114
|
-
* @param endIndex The end index of viewable items.
|
|
115
|
-
*/
|
|
116
|
-
rangeChange: (startIndex: number, endIndex: number) => void;
|
|
117
121
|
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
118
122
|
/**
|
|
119
123
|
* The data items rendered by this component.
|
|
@@ -126,10 +130,7 @@ export declare const Virtualizer: import("vue").DefineComponent<{
|
|
|
126
130
|
* Number of items to render above/below the visible bounds of the list. You can increase to avoid showing blank items in fast scrolling.
|
|
127
131
|
* @defaultValue 4
|
|
128
132
|
*/
|
|
129
|
-
overscan:
|
|
130
|
-
type: NumberConstructor;
|
|
131
|
-
default: number;
|
|
132
|
-
};
|
|
133
|
+
overscan: NumberConstructor;
|
|
133
134
|
/**
|
|
134
135
|
* Item size hint for unmeasured items. It will help to reduce scroll jump when items are measured if used properly.
|
|
135
136
|
*
|
|
@@ -179,10 +180,8 @@ export declare const Virtualizer: import("vue").DefineComponent<{
|
|
|
179
180
|
}>> & {
|
|
180
181
|
onScroll?: ((offset: number) => any) | undefined;
|
|
181
182
|
onScrollEnd?: (() => any) | undefined;
|
|
182
|
-
onRangeChange?: ((startIndex: number, endIndex: number) => any) | undefined;
|
|
183
183
|
}, {
|
|
184
184
|
shift: boolean;
|
|
185
|
-
overscan: number;
|
|
186
185
|
horizontal: boolean;
|
|
187
186
|
startMargin: number;
|
|
188
187
|
as: keyof import("vue").IntrinsicElementAttributes;
|