virtua 0.46.6 → 0.47.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/core/index.cjs +1 -1
- package/lib/core/index.cjs.map +1 -1
- package/lib/core/index.js +1 -1
- package/lib/core/index.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/react/VGrid.d.ts +31 -21
- package/lib/react/VList.d.ts +3 -3
- package/lib/react/Virtualizer.d.ts +6 -9
- package/lib/react/WindowVirtualizer.d.ts +22 -7
- package/lib/react/types.d.ts +1 -1
- package/lib/solid/VList.d.ts +3 -3
- package/lib/solid/Virtualizer.d.ts +5 -8
- package/lib/solid/WindowVirtualizer.d.ts +21 -6
- package/lib/solid/index.cjs +1 -1
- package/lib/solid/index.cjs.map +1 -1
- package/lib/solid/index.js +1 -1
- package/lib/solid/index.js.map +1 -1
- package/lib/solid/index.jsx +50 -32
- package/lib/solid/index.jsx.map +1 -1
- package/lib/solid/types.d.ts +1 -1
- package/lib/svelte/VList.svelte +8 -4
- package/lib/svelte/VList.type.d.ts +1 -1
- package/lib/svelte/Virtualizer.svelte +6 -5
- package/lib/svelte/Virtualizer.type.d.ts +14 -7
- package/lib/svelte/WindowVirtualizer.svelte +14 -5
- package/lib/svelte/WindowVirtualizer.type.d.ts +30 -5
- package/lib/vue/VList.d.ts +16 -3
- package/lib/vue/Virtualizer.d.ts +22 -9
- package/lib/vue/WindowVirtualizer.d.ts +37 -6
- package/lib/vue/index.cjs +1 -1
- package/lib/vue/index.cjs.map +1 -1
- package/lib/vue/index.js +1 -1
- package/lib/vue/index.js.map +1 -1
- package/lib/vue/utils.d.ts +1 -1
- package/package.json +1 -1
package/lib/svelte/VList.svelte
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
shift,
|
|
14
14
|
horizontal,
|
|
15
15
|
keepMounted,
|
|
16
|
+
cache,
|
|
16
17
|
children,
|
|
17
18
|
onscroll,
|
|
18
19
|
onscrollend,
|
|
@@ -21,16 +22,18 @@
|
|
|
21
22
|
|
|
22
23
|
let ref: Virtualizer<T> = $state()!;
|
|
23
24
|
|
|
25
|
+
export const getCache = (() =>
|
|
26
|
+
ref.getCache()) satisfies VListHandle["getCache"] as VListHandle["getCache"];
|
|
24
27
|
export const getScrollOffset = (() =>
|
|
25
28
|
ref.getScrollOffset()) satisfies VListHandle["getScrollOffset"] as VListHandle["getScrollOffset"];
|
|
26
29
|
export const getScrollSize = (() =>
|
|
27
30
|
ref.getScrollSize()) satisfies VListHandle["getScrollSize"] as VListHandle["getScrollSize"];
|
|
28
31
|
export const getViewportSize = (() =>
|
|
29
32
|
ref.getViewportSize()) satisfies VListHandle["getViewportSize"] as VListHandle["getViewportSize"];
|
|
30
|
-
export const
|
|
31
|
-
ref.
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
export const findItemIndex = ((...args) =>
|
|
34
|
+
ref.findItemIndex(
|
|
35
|
+
...args
|
|
36
|
+
)) satisfies VListHandle["findItemIndex"] as VListHandle["findItemIndex"];
|
|
34
37
|
export const getItemOffset = ((...args) =>
|
|
35
38
|
ref.getItemOffset(
|
|
36
39
|
...args
|
|
@@ -76,6 +79,7 @@
|
|
|
76
79
|
{shift}
|
|
77
80
|
{horizontal}
|
|
78
81
|
{keepMounted}
|
|
82
|
+
{cache}
|
|
79
83
|
{onscroll}
|
|
80
84
|
{onscrollend}
|
|
81
85
|
/>
|
|
@@ -3,7 +3,7 @@ import type { VirtualizerHandle, VirtualizerProps } from "./Virtualizer.type.js"
|
|
|
3
3
|
/**
|
|
4
4
|
* Props of {@link VList}.
|
|
5
5
|
*/
|
|
6
|
-
export interface VListProps<T> extends Pick<VirtualizerProps<T>, "data" | "getKey" | "bufferSize" | "itemSize" | "shift" | "horizontal" | "children" | "onscroll" | "onscrollend" | "keepMounted">, ViewportComponentAttributes {
|
|
6
|
+
export interface VListProps<T> extends Pick<VirtualizerProps<T>, "data" | "getKey" | "bufferSize" | "itemSize" | "shift" | "horizontal" | "children" | "onscroll" | "onscrollend" | "keepMounted" | "cache">, ViewportComponentAttributes {
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Methods of {@link VList}.
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
shift = false,
|
|
33
33
|
horizontal = false,
|
|
34
34
|
keepMounted,
|
|
35
|
+
cache,
|
|
35
36
|
startMargin = 0,
|
|
36
37
|
children,
|
|
37
38
|
onscroll,
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
data.length,
|
|
43
44
|
itemSize,
|
|
44
45
|
undefined,
|
|
45
|
-
|
|
46
|
+
cache,
|
|
46
47
|
!itemSize
|
|
47
48
|
);
|
|
48
49
|
const resizer = createResizer(store, horizontal);
|
|
@@ -104,6 +105,8 @@
|
|
|
104
105
|
scroller.$fixScrollJump();
|
|
105
106
|
});
|
|
106
107
|
|
|
108
|
+
export const getCache =
|
|
109
|
+
store.$getCacheSnapshot satisfies VirtualizerHandle["getCache"] as VirtualizerHandle["getCache"];
|
|
107
110
|
export const getScrollOffset =
|
|
108
111
|
store.$getScrollOffset satisfies VirtualizerHandle["getScrollOffset"] as VirtualizerHandle["getScrollOffset"];
|
|
109
112
|
export const getScrollSize = (() =>
|
|
@@ -112,10 +115,8 @@
|
|
|
112
115
|
)) satisfies VirtualizerHandle["getScrollSize"] as VirtualizerHandle["getScrollSize"];
|
|
113
116
|
export const getViewportSize =
|
|
114
117
|
store.$getViewportSize satisfies VirtualizerHandle["getViewportSize"] as VirtualizerHandle["getViewportSize"];
|
|
115
|
-
export const
|
|
116
|
-
store.$
|
|
117
|
-
export const findEndIndex =
|
|
118
|
-
store.$findEndIndex satisfies VirtualizerHandle["findEndIndex"] as VirtualizerHandle["findEndIndex"];
|
|
118
|
+
export const findItemIndex =
|
|
119
|
+
store.$findItemIndex satisfies VirtualizerHandle["findItemIndex"] as VirtualizerHandle["findItemIndex"];
|
|
119
120
|
export const getItemOffset =
|
|
120
121
|
store.$getItemOffset satisfies VirtualizerHandle["getItemOffset"] as VirtualizerHandle["getItemOffset"];
|
|
121
122
|
export const getItemSize =
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Snippet } from "svelte";
|
|
2
2
|
import type { SvelteHTMLElements } from "svelte/elements";
|
|
3
|
-
import { type ScrollToIndexOpts } from "../core/index.js";
|
|
3
|
+
import { type CacheSnapshot, type ScrollToIndexOpts } from "../core/index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Props of {@link Virtualizer}.
|
|
6
6
|
*/
|
|
@@ -56,6 +56,12 @@ export interface VirtualizerProps<T> {
|
|
|
56
56
|
* List of indexes that should be always mounted, even when off screen.
|
|
57
57
|
*/
|
|
58
58
|
keepMounted?: readonly number[];
|
|
59
|
+
/**
|
|
60
|
+
* You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VirtualizerHandle.getCache}.
|
|
61
|
+
*
|
|
62
|
+
* **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**
|
|
63
|
+
*/
|
|
64
|
+
cache?: CacheSnapshot;
|
|
59
65
|
/**
|
|
60
66
|
* The offset to the scrollable parent before virtualizer in pixels. If you put an element before virtualizer, you have to set its height to this prop.
|
|
61
67
|
*/
|
|
@@ -74,6 +80,10 @@ export interface VirtualizerProps<T> {
|
|
|
74
80
|
* Methods of {@link Virtualizer}.
|
|
75
81
|
*/
|
|
76
82
|
export interface VirtualizerHandle {
|
|
83
|
+
/**
|
|
84
|
+
* Get current {@link CacheSnapshot}.
|
|
85
|
+
*/
|
|
86
|
+
getCache: () => CacheSnapshot;
|
|
77
87
|
/**
|
|
78
88
|
* Get current scrollTop, or scrollLeft if horizontal: true.
|
|
79
89
|
*/
|
|
@@ -87,13 +97,10 @@ export interface VirtualizerHandle {
|
|
|
87
97
|
*/
|
|
88
98
|
getViewportSize: () => number;
|
|
89
99
|
/**
|
|
90
|
-
* Find
|
|
91
|
-
|
|
92
|
-
findStartIndex: () => number;
|
|
93
|
-
/**
|
|
94
|
-
* Find the end index of visible range of items.
|
|
100
|
+
* Find nearest item index from offset.
|
|
101
|
+
* @param offset offset in pixels from the start of the scroll container
|
|
95
102
|
*/
|
|
96
|
-
|
|
103
|
+
findItemIndex: (offset: number) => number;
|
|
97
104
|
/**
|
|
98
105
|
* Get item offset from start.
|
|
99
106
|
* @param index index of item
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
itemSize,
|
|
28
28
|
shift = false,
|
|
29
29
|
horizontal = false,
|
|
30
|
+
cache,
|
|
30
31
|
children,
|
|
31
32
|
onscroll,
|
|
32
33
|
onscrollend,
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
data.length,
|
|
37
38
|
itemSize,
|
|
38
39
|
undefined,
|
|
39
|
-
|
|
40
|
+
cache,
|
|
40
41
|
!itemSize
|
|
41
42
|
);
|
|
42
43
|
const resizer = createWindowResizer(store, horizontal);
|
|
@@ -83,10 +84,18 @@
|
|
|
83
84
|
scroller.$fixScrollJump();
|
|
84
85
|
});
|
|
85
86
|
|
|
86
|
-
export const
|
|
87
|
-
store.$
|
|
88
|
-
export const
|
|
89
|
-
store.$
|
|
87
|
+
export const getCache =
|
|
88
|
+
store.$getCacheSnapshot satisfies WindowVirtualizerHandle["getCache"] as WindowVirtualizerHandle["getCache"];
|
|
89
|
+
export const getScrollOffset =
|
|
90
|
+
store.$getScrollOffset satisfies WindowVirtualizerHandle["getScrollOffset"] as WindowVirtualizerHandle["getScrollOffset"];
|
|
91
|
+
export const getViewportSize =
|
|
92
|
+
store.$getViewportSize satisfies WindowVirtualizerHandle["getViewportSize"] as WindowVirtualizerHandle["getViewportSize"];
|
|
93
|
+
export const findItemIndex =
|
|
94
|
+
store.$findItemIndex satisfies WindowVirtualizerHandle["findItemIndex"] as WindowVirtualizerHandle["findItemIndex"];
|
|
95
|
+
export const getItemOffset =
|
|
96
|
+
store.$getItemOffset satisfies WindowVirtualizerHandle["getItemOffset"] as WindowVirtualizerHandle["getItemOffset"];
|
|
97
|
+
export const getItemSize =
|
|
98
|
+
store.$getItemSize satisfies WindowVirtualizerHandle["getItemSize"] as WindowVirtualizerHandle["getItemSize"];
|
|
90
99
|
export const scrollToIndex =
|
|
91
100
|
scroller.$scrollToIndex satisfies WindowVirtualizerHandle["scrollToIndex"] as WindowVirtualizerHandle["scrollToIndex"];
|
|
92
101
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Snippet } from "svelte";
|
|
2
|
-
import { type ScrollToIndexOpts } from "../core/index.js";
|
|
2
|
+
import { type CacheSnapshot, type ScrollToIndexOpts } from "../core/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Props of {@link WindowVirtualizer}.
|
|
5
5
|
*/
|
|
@@ -37,6 +37,12 @@ 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
|
+
* You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link WindowVirtualizerHandle.getCache}.
|
|
42
|
+
*
|
|
43
|
+
* **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**
|
|
44
|
+
*/
|
|
45
|
+
cache?: CacheSnapshot;
|
|
40
46
|
/**
|
|
41
47
|
* Callback invoked whenever scroll offset changes.
|
|
42
48
|
*/
|
|
@@ -51,13 +57,32 @@ export interface WindowVirtualizerProps<T> {
|
|
|
51
57
|
*/
|
|
52
58
|
export interface WindowVirtualizerHandle {
|
|
53
59
|
/**
|
|
54
|
-
*
|
|
60
|
+
* Get current {@link CacheSnapshot}.
|
|
61
|
+
*/
|
|
62
|
+
getCache: () => CacheSnapshot;
|
|
63
|
+
/**
|
|
64
|
+
* Get current scrollTop, or scrollLeft if horizontal: true.
|
|
65
|
+
*/
|
|
66
|
+
getScrollOffset: () => number;
|
|
67
|
+
/**
|
|
68
|
+
* Get current offsetHeight, or offsetWidth if horizontal: true.
|
|
55
69
|
*/
|
|
56
|
-
|
|
70
|
+
getViewportSize: () => number;
|
|
57
71
|
/**
|
|
58
|
-
* Find
|
|
72
|
+
* Find nearest item index from offset.
|
|
73
|
+
* @param offset offset in pixels from the start of the scroll container
|
|
74
|
+
*/
|
|
75
|
+
findItemIndex: (offset: number) => number;
|
|
76
|
+
/**
|
|
77
|
+
* Get item offset from start.
|
|
78
|
+
* @param index index of item
|
|
79
|
+
*/
|
|
80
|
+
getItemOffset(index: number): number;
|
|
81
|
+
/**
|
|
82
|
+
* Get item size.
|
|
83
|
+
* @param index index of item
|
|
59
84
|
*/
|
|
60
|
-
|
|
85
|
+
getItemSize(index: number): number;
|
|
61
86
|
/**
|
|
62
87
|
* Scroll to the item specified by index.
|
|
63
88
|
* @param index index of item
|
package/lib/vue/VList.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/** @jsxImportSource vue */
|
|
2
|
-
import { ComponentOptionsMixin, SlotsType, VNode, PropType } from "vue";
|
|
3
|
-
import { VirtualizerHandle } from "./Virtualizer.js";
|
|
4
|
-
import { ItemProps } from "./utils.js";
|
|
2
|
+
import { type ComponentOptionsMixin, type SlotsType, type VNode, type PropType } from "vue";
|
|
3
|
+
import { type VirtualizerHandle } from "./Virtualizer.js";
|
|
4
|
+
import { type ItemProps } from "./utils.js";
|
|
5
|
+
import { type CacheSnapshot } from "../core/index.js";
|
|
5
6
|
interface VListHandle extends VirtualizerHandle {
|
|
6
7
|
}
|
|
7
8
|
export declare const VList: import("vue").DefineComponent<{
|
|
@@ -46,6 +47,12 @@ export declare const VList: import("vue").DefineComponent<{
|
|
|
46
47
|
* List of indexes that should be always mounted, even when off screen.
|
|
47
48
|
*/
|
|
48
49
|
keepMounted: PropType<readonly number[]>;
|
|
50
|
+
/**
|
|
51
|
+
* You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VirtualizerHandle.cache}.
|
|
52
|
+
*
|
|
53
|
+
* **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**
|
|
54
|
+
*/
|
|
55
|
+
cache: PropType<CacheSnapshot>;
|
|
49
56
|
}, VListHandle, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
50
57
|
/**
|
|
51
58
|
* Callback invoked whenever scroll offset changes.
|
|
@@ -98,6 +105,12 @@ export declare const VList: import("vue").DefineComponent<{
|
|
|
98
105
|
* List of indexes that should be always mounted, even when off screen.
|
|
99
106
|
*/
|
|
100
107
|
keepMounted: PropType<readonly number[]>;
|
|
108
|
+
/**
|
|
109
|
+
* You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VirtualizerHandle.cache}.
|
|
110
|
+
*
|
|
111
|
+
* **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**
|
|
112
|
+
*/
|
|
113
|
+
cache: PropType<CacheSnapshot>;
|
|
101
114
|
}>> & {
|
|
102
115
|
onScroll?: ((offset: number) => any) | undefined;
|
|
103
116
|
onScrollEnd?: (() => any) | undefined;
|
package/lib/vue/Virtualizer.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/** @jsxImportSource vue */
|
|
2
|
-
import { VNode, ComponentOptionsMixin, SlotsType, PropType, NativeElements } from "vue";
|
|
3
|
-
import { ScrollToIndexOpts } from "../core/index.js";
|
|
4
|
-
import { ItemProps } from "./utils.js";
|
|
2
|
+
import { type VNode, type ComponentOptionsMixin, type SlotsType, type PropType, type NativeElements } from "vue";
|
|
3
|
+
import { type ScrollToIndexOpts, type CacheSnapshot } from "../core/index.js";
|
|
4
|
+
import { type ItemProps } from "./utils.js";
|
|
5
5
|
export interface VirtualizerHandle {
|
|
6
|
+
/**
|
|
7
|
+
* Get current {@link CacheSnapshot}.
|
|
8
|
+
*/
|
|
9
|
+
readonly cache: CacheSnapshot;
|
|
6
10
|
/**
|
|
7
11
|
* Get current scrollTop, or scrollLeft if horizontal: true.
|
|
8
12
|
*/
|
|
@@ -16,13 +20,10 @@ export interface VirtualizerHandle {
|
|
|
16
20
|
*/
|
|
17
21
|
readonly viewportSize: number;
|
|
18
22
|
/**
|
|
19
|
-
* Find
|
|
23
|
+
* Find nearest item index from offset.
|
|
24
|
+
* @param offset offset in pixels from the start of the scroll container
|
|
20
25
|
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Find the end index of visible range of items.
|
|
24
|
-
*/
|
|
25
|
-
findEndIndex: () => number;
|
|
26
|
+
findItemIndex: (offset: number) => number;
|
|
26
27
|
/**
|
|
27
28
|
* Get item offset from start.
|
|
28
29
|
* @param index index of item
|
|
@@ -119,6 +120,12 @@ export declare const Virtualizer: import("vue").DefineComponent<{
|
|
|
119
120
|
* List of indexes that should be always mounted, even when off screen.
|
|
120
121
|
*/
|
|
121
122
|
keepMounted: PropType<readonly number[]>;
|
|
123
|
+
/**
|
|
124
|
+
* You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VirtualizerHandle.cache}.
|
|
125
|
+
*
|
|
126
|
+
* **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**
|
|
127
|
+
*/
|
|
128
|
+
cache: PropType<CacheSnapshot>;
|
|
122
129
|
}, VirtualizerHandle, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
123
130
|
/**
|
|
124
131
|
* Callback invoked whenever scroll offset changes.
|
|
@@ -198,6 +205,12 @@ export declare const Virtualizer: import("vue").DefineComponent<{
|
|
|
198
205
|
* List of indexes that should be always mounted, even when off screen.
|
|
199
206
|
*/
|
|
200
207
|
keepMounted: PropType<readonly number[]>;
|
|
208
|
+
/**
|
|
209
|
+
* You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link VirtualizerHandle.cache}.
|
|
210
|
+
*
|
|
211
|
+
* **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**
|
|
212
|
+
*/
|
|
213
|
+
cache: PropType<CacheSnapshot>;
|
|
201
214
|
}>> & {
|
|
202
215
|
onScroll?: ((offset: number) => any) | undefined;
|
|
203
216
|
onScrollEnd?: (() => any) | undefined;
|
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
/** @jsxImportSource vue */
|
|
2
|
-
import { VNode, ComponentOptionsMixin, SlotsType, PropType, NativeElements } from "vue";
|
|
3
|
-
import { ScrollToIndexOpts } from "../core/index.js";
|
|
2
|
+
import { type VNode, type ComponentOptionsMixin, type SlotsType, type PropType, type NativeElements } from "vue";
|
|
3
|
+
import { type ScrollToIndexOpts, type CacheSnapshot } from "../core/index.js";
|
|
4
4
|
export interface WindowVirtualizerHandle {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Get current {@link CacheSnapshot}.
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
readonly cache: CacheSnapshot;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Get current scrollTop, or scrollLeft if horizontal: true.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
readonly scrollOffset: number;
|
|
13
|
+
/**
|
|
14
|
+
* Get current offsetHeight, or offsetWidth if horizontal: true.
|
|
15
|
+
*/
|
|
16
|
+
readonly viewportSize: number;
|
|
17
|
+
/**
|
|
18
|
+
* Find nearest item index from offset.
|
|
19
|
+
* @param offset offset in pixels from the start of the scroll container
|
|
20
|
+
*/
|
|
21
|
+
findItemIndex: (offset: number) => number;
|
|
22
|
+
/**
|
|
23
|
+
* Get item offset from start.
|
|
24
|
+
* @param index index of item
|
|
25
|
+
*/
|
|
26
|
+
getItemOffset(index: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Get item size.
|
|
29
|
+
* @param index index of item
|
|
30
|
+
*/
|
|
31
|
+
getItemSize(index: number): number;
|
|
13
32
|
/**
|
|
14
33
|
* Scroll to the item specified by index.
|
|
15
34
|
* @param index index of item
|
|
@@ -61,6 +80,12 @@ export declare const WindowVirtualizer: import("vue").DefineComponent<{
|
|
|
61
80
|
type: PropType<keyof NativeElements>;
|
|
62
81
|
default: string;
|
|
63
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link WindowVirtualizerHandle.cache}.
|
|
85
|
+
*
|
|
86
|
+
* **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**
|
|
87
|
+
*/
|
|
88
|
+
cache: PropType<CacheSnapshot>;
|
|
64
89
|
}, void, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
|
|
65
90
|
/**
|
|
66
91
|
* Callback invoked whenever scroll offset changes.
|
|
@@ -114,6 +139,12 @@ export declare const WindowVirtualizer: import("vue").DefineComponent<{
|
|
|
114
139
|
type: PropType<keyof NativeElements>;
|
|
115
140
|
default: string;
|
|
116
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* You can restore cache by passing a {@link CacheSnapshot} on mount. This is useful when you want to restore scroll position after navigation. The snapshot can be obtained from {@link WindowVirtualizerHandle.cache}.
|
|
144
|
+
*
|
|
145
|
+
* **The length of items should be the same as when you take the snapshot, otherwise restoration may not work as expected.**
|
|
146
|
+
*/
|
|
147
|
+
cache: PropType<CacheSnapshot>;
|
|
117
148
|
}>> & {
|
|
118
149
|
onScroll?: (() => any) | undefined;
|
|
119
150
|
onScrollEnd?: (() => any) | undefined;
|
package/lib/vue/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("vue");const t=null,{min:r,max:o,abs:n,floor:s}=Math,i=(e,t,n)=>r(n,o(t,e)),l=e=>[...e].sort(((e,t)=>e-t)),c="function"==typeof queueMicrotask?queueMicrotask:e=>{Promise.resolve().then(e)},a=()=>{let e;return[new Promise((t=>{e=t})),e]},u=e=>{let t;return()=>(e&&(t=e(),e=void 0),t)},f=(e,t,r)=>{const o=r?"unshift":"push";for(let r=0;r<t;r++)e[o](-1);return e},d=(e,t)=>{const r=e.t[t];return-1===r?e.o:r},p=(e,t,o)=>{const n=-1===e.t[t];return e.t[t]=o,e.i=r(t,e.i),n},m=(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+=d(e,r),e.u[++r]=o;return e.i=t,o},h=(e,t,r=0,o=e.l-1)=>{for(;r<=o;){const n=s((r+o)/2);if(m(e,n)<=t){if(m(e,n+1)>t)return n;r=n+1}else o=n-1}return i(r,0,e.l-1)},_=(e,t,o)=>{const n=t-e.l;return e.i=o?-1:r(t-1,e.i),e.l=t,n>0?(f(e.u,n),f(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-(-1===r?e.o:r)),0))},b="undefined"!=typeof window,v=()=>document.documentElement,S=e=>e.ownerDocument,y=e=>e.defaultView,g=/*#__PURE__*/u((()=>!!b&&"rtl"===getComputedStyle(v()).direction)),z=/*#__PURE__*/u((()=>!!/iP(hone|od|ad)/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>0)),x=/*#__PURE__*/u((()=>"scrollBehavior"in v().style)),$=(e,s=40,i=0,c,a=!1)=>{let u=!!i,b=1,v=0,S=0,y=0,g=0,x=0,$=0,w=0,I=0,k=t,O=[0,u?o(i-1,0):-1],j=0;const E=((e,t)=>({o:t,t:f([],e),l:e,i:-1,u:f([],e+1)}))(e,s),q=new Set,T=()=>y-S,B=()=>T()+x+g,M=(e,t)=>((e,t,o,n)=>{if(n=r(n,e.l-1),m(e,n)<=t){const r=h(e,o,n);return[h(e,t,n,r),r]}{const r=h(e,t,void 0,n);return[r,h(e,o,r)]}})(E,e,t,O[0]),N=()=>m(E,E.l),P=e=>m(E,e)-x,R=e=>d(E,e),A=(e,t=-1)=>E.t[e]===t,H=e=>{e&&(z()&&0!==w||k&&1===I?x+=e:g+=e)};return{p:()=>{q.clear()},m:()=>b,h:()=>(e=>[e.t.slice(),e.o])(E),v:(e=200)=>{if(!v||u)return O;let t,n;if($)[t,n]=O;else{let s=o(0,B()),i=s+v;a||(e=o(0,e),1!==w&&(s-=e),2!==w&&(i+=e)),[t,n]=O=M(o(0,s),o(0,i)),k&&(t=r(t,k[0]),n=o(n,k[1]))}return[o(t,0),r(n,E.l-1)]},S:()=>h(E,B()),I:()=>h(E,B()+v),k:A,O:P,j:R,q:()=>E.l,T:()=>y,B:()=>0!==w,M:()=>v,N:()=>S,P:N,R:()=>($=g,g=0,[$,2===I]),A:(e,t)=>{const r=[e,t];return q.add(r),()=>{q.delete(r)}},H:(e,r)=>{let s,i,c=0;switch(e){case 1:{if(r===y&&0===I)break;const e=$;$=0;const t=r-y,o=n(t);e&&o<n(e)+1||0!==I||(w=t<0?2:1),u&&(u=!1),y=r,c=4;const s=T();s>=-v&&s<=N()&&(c+=1,i=o>v);break}case 2:c=8,0!==w&&(s=!0,c+=1),w=0,I=0,k=t;break;case 3:{const e=r.filter((([e,t])=>!A(e,t)));if(!e.length)break;H(e.reduce(((e,[t,r])=>((2===I||(k&&1===I?t<k[0]:P(t+(0===w&&0===I?1:0))<T()))&&(e+=r-R(t)),e)),0));for(const[t,r]of e){const e=R(t),o=p(E,t,r);a&&(j+=o?r:r-e)}a&&v&&j>v&&(H(((e,t)=>{let r=0;const n=[];e.t.forEach(((e,o)=>{-1!==e&&(n.push(e),o<t&&r++)})),e.i=-1;const s=l(n),i=s.length,c=i/2|0,a=i%2==0?(s[c-1]+s[c])/2:s[c],u=e.o;return((e.o=a)-u)*o(t-r,0)})(E,h(E,B()))),a=!1),c=3,i=!0;break}case 4:v!==r&&(v||(i=!0),v=r,c=3);break;case 5:r[1]?(H(_(E,r[0],!0)),I=2,c=1):(_(E,r[0]),c=1);break;case 6:S=r;break;case 7:I=1;break;case 8:k=M(r,r+v),c=1}c&&(b=1+(2147483647&b),s&&x&&(g+=x,x=0),q.forEach((([e,t])=>{c&e&&t(i)})))}}},w=setTimeout,I=(e,t)=>t&&g()?-e:e,k=(e,r,o,n,s,i)=>{const l=Date.now;let c=0,a=!1,u=!1,f=!1,d=!1;const p=(()=>{let r;const o=()=>{r!=t&&clearTimeout(r)},n=()=>{o(),r=w((()=>{r=t,(()=>{if(a||u)return a=!1,void p();f=!1,e.H(2)})()}),150)};return n.V=o,n})(),m=()=>{c=l(),f&&(d=!0),i&&e.H(6,i()),e.H(1,n()),p()},h=t=>{if(a||!e.B()||t.ctrlKey)return;const r=l()-c;150>r&&50<r&&(o?t.deltaX:t.deltaY)&&(a=!0)},_=()=>{u=!0,f=d=!1},b=()=>{u=!1,z()&&(f=!0)};return r.addEventListener("scroll",m),r.addEventListener("wheel",h,{passive:!0}),r.addEventListener("touchstart",_,{passive:!0}),r.addEventListener("touchend",b,{passive:!0}),{C:()=>{r.removeEventListener("scroll",m),r.removeEventListener("wheel",h),r.removeEventListener("touchstart",_),r.removeEventListener("touchend",b),p.V()},F:()=>{const[t,r]=e.R();t&&(s(I(t,o),r,d),d=!1,r&&e.M()>e.P()&&e.H(1,n()))}}},O=(e,t,r)=>{let o;return[async(n,s)=>{if(!await t())return;o&&o();const i=()=>{const[t,r]=a();return o=()=>{r(!1)},e.M()&&w(o,150),[t,e.A(2,(()=>{r(!0)}))]};if(s&&x())e.H(8,n()),c((async()=>{for(;;){let t=!0;for(let[r,o]=e.v();r<=o;r++)if(e.k(r)){t=!1;break}if(t)break;const[r,o]=i();try{if(!await r)return}finally{o()}}e.H(7),r(n(),s)}));else for(;;){const[t,o]=i();try{if(e.H(7),r(n()),!await t)return}finally{o()}}},()=>{o&&o()}]},j=e=>{let t;return{J(r){(t||(t=new(y(S(r)).ResizeObserver)(e))).observe(r)},L(e){t.unobserve(e)},C(){t&&t.disconnect()}}},E=/*#__PURE__*/e.defineComponent({props:{W:{type:Object,required:!0},X:{type:Object,required:!0},Y:{type:Object,required:!0},D:{type:Function,required:!0},U:{type:Number,required:!0},G:{type:Boolean},K:{type:Boolean},Z:{type:String,required:!0},ee:Object},setup(t){const r=e.ref(),o=e.computed((()=>t.W.value&&t.X.O(t.U))),n=e.computed((()=>t.W.value&&t.X.k(t.U)));return e.watch((()=>r.value&&t.U),((e,o,n)=>{n(t.D(r.value,t.U))}),{flush:"post"}),()=>{var s;const{Y:i,G:l,K:c,Z:a}=t,u=n.value,{style:f,...d}=null!==(s=t.ee)&&void 0!==s?s:{},p={contain:"layout style",position:u&&c?void 0:"absolute",[l?"height":"width"]:"100%",[l?"top":"left"]:"0px",[l?g()?"right":"left":"top"]:o.value+"px",visibility:!u||c?void 0:"hidden",...f};return l&&(p.display="inline-flex"),e.createVNode(a,e.mergeProps({ref:r,style:p},d),"function"==typeof(m=i)||"[object Object]"===Object.prototype.toString.call(m)&&!e.isVNode(m)?i:{default:()=>[i],_:2},16,["style"]);var m}}}),q=(e,t)=>{const r=e.key;return null!=r?r:"_"+t},T=(e,t)=>e[0]===t[0]&&e[1]===t[1],B={data:{type:Array,required:!0},bufferSize:Number,itemSize:Number,shift:Boolean,horizontal:Boolean,startMargin:{type:Number,default:0},ssrCount:Number,scrollRef:Object,as:{type:String,default:"div"},item:{type:String,default:"div"},itemProps:Function,keepMounted:Array},M=/*#__PURE__*/e.defineComponent({props:B,emits:["scroll","scrollEnd"],setup(r,{emit:n,expose:s,slots:c}){let u=!!r.ssrCount;const f=r.horizontal,d=e.ref(),p=$(r.data.length,r.itemSize,r.ssrCount,0,!r.itemSize),m=((e,r)=>{let o;const n=r?"width":"height",s=new WeakMap,i=j((r=>{const i=[];for(const{target:l,contentRect:c}of r)if(l.offsetParent)if(l===o)e.H(4,c[n]);else{const e=s.get(l);e!=t&&i.push([e,c[n]])}i.length&&e.H(3,i)}));return{te(e){i.J(o=e)},re:(e,t)=>(s.set(e,t),i.J(e),()=>{s.delete(e),i.L(e)}),p:i.C}})(p,f),h=((e,t)=>{let r,o,n=a();const s=t?"scrollLeft":"scrollTop",l=t?"overflowX":"overflowY",[c,u]=O(e,(()=>n[0]),((e,o)=>{e=I(e,t),o?r.scrollTo({[t?"left":"top"]:e,behavior:"smooth"}):r[s]=e}));return{oe(i){r=i,o=k(e,i,t,(()=>I(i[s],t)),((t,r,o)=>{if(o){const e=i.style,t=e[l];e[l]="hidden",w((()=>{e[l]=t}))}i[s]=e.T()+t,r&&u()})),n[1](!0)},p(){o&&o.C(),n[1](!1),n=a()},ne(e){c((()=>e))},se(t){t+=e.T(),c((()=>t))},ie(t,{align:r,smooth:o,offset:n=0}={}){if(t=i(t,0,e.q()-1),"nearest"===r){const o=e.O(t),n=e.T();if(o<n)r="start";else{if(!(o+e.j(t)>n+e.M()))return;r="end"}}c((()=>n+e.N()+e.O(t)+("end"===r?e.j(t)-e.M():"center"===r?(e.j(t)-e.M())/2:0)),o)},le:()=>{o&&o.F()}}})(p,f),_=e.ref(p.m());p.A(1,(()=>{_.value=p.m()})),p.A(4,(()=>{n("scroll",p.T())})),p.A(8,(()=>{n("scrollEnd")}));const b=e.computed((e=>{_.value;const t=p.v(r.bufferSize);return e&&T(e,t)?e:t})),v=e.computed((()=>_.value&&p.B())),S=e.computed((()=>_.value&&p.P()));return e.onMounted((()=>{u=!1;const t=requestAnimationFrame((()=>{const e=e=>{m.te(e),h.oe(e)};r.scrollRef?e(r.scrollRef):e(d.value.parentElement)}));e.onUnmounted((()=>{cancelAnimationFrame(t)}))})),e.onUnmounted((()=>{p.p(),m.p(),h.p()})),e.watch((()=>r.data.length),(e=>{p.H(5,[e,r.shift])})),e.watch((()=>r.startMargin),(e=>{p.H(6,e)}),{immediate:!0}),e.watch([_],(()=>{h.le()}),{flush:"post"}),s({get scrollOffset(){return p.T()},get scrollSize(){return(e=>o(e.P(),e.M()))(p)},get viewportSize(){return p.M()},findStartIndex:p.S,findEndIndex:p.I,getItemOffset:p.O,getItemSize:p.j,scrollToIndex:h.ie,scrollTo:h.ne,scrollBy:h.se}),()=>{const t=r.as,o=r.item,n=S.value,s=[],i=t=>{var n;const s=c.default({item:r.data[t],index:t})[0];return e.createVNode(E,{key:q(s,t),W:_,X:p,D:m.re,U:t,Y:s,G:f,K:u,Z:o,ee:null===(n=r.itemProps)||void 0===n?void 0:n.call(r,{item:r.data[t],index:t})},null,8,["_stateVersion","_store","_resizer","_index","_children","_isHorizontal","_isSSR","_as","_itemProps"])};if(r.keepMounted){const e=new Set(r.keepMounted);for(let[t,r]=b.value;t<=r;t++)e.add(t);l([...e]).forEach((e=>{s.push(i(e))}))}else for(let[e,t]=b.value;e<=t;e++)s.push(i(e));return e.createVNode(t,{ref:d,style:{contain:"size style",overflowAnchor:"none",flex:"none",position:"relative",width:f?n+"px":"100%",height:f?"100%":n+"px",pointerEvents:v.value?"none":void 0}},"function"==typeof(a=s)||"[object Object]"===Object.prototype.toString.call(a)&&!e.isVNode(a)?s:{default:()=>[s],_:2},8,["style"]);var a}}}),N={data:{type:Array,required:!0},bufferSize:Number,itemSize:Number,shift:Boolean,horizontal:Boolean,ssrCount:Number,itemProps:Function,keepMounted:Array},P=/*#__PURE__*/e.defineComponent({props:N,emits:["scroll","scrollEnd"],setup(t,{emit:r,expose:o,slots:n}){const s=t.horizontal,i=e=>{r("scroll",e)},l=()=>{r("scrollEnd")},c=e.ref();return o({get scrollOffset(){return c.value.scrollOffset},get scrollSize(){return c.value.scrollSize},get viewportSize(){return c.value.viewportSize},findStartIndex:(...e)=>c.value.findStartIndex(...e),findEndIndex:(...e)=>c.value.findEndIndex(...e),getItemOffset:(...e)=>c.value.getItemOffset(...e),getItemSize:(...e)=>c.value.getItemSize(...e),scrollToIndex:(...e)=>c.value.scrollToIndex(...e),scrollTo:(...e)=>c.value.scrollTo(...e),scrollBy:(...e)=>c.value.scrollBy(...e)}),()=>{return e.createVNode("div",{style:{display:s?"inline-block":"block",[s?"overflowX":"overflowY"]:"auto",contain:"strict",width:"100%",height:"100%"}},[e.createVNode(M,{ref:c,data:t.data,bufferSize:t.bufferSize,itemSize:t.itemSize,itemProps:t.itemProps,shift:t.shift,ssrCount:t.ssrCount,horizontal:s,keepMounted:t.keepMounted,onScroll:i,onScrollEnd:l},(r=n,"function"==typeof r||"[object Object]"===Object.prototype.toString.call(r)&&!e.isVNode(r)?n:{default:()=>[n],_:2}),8,["data","bufferSize","itemSize","itemProps","shift","ssrCount","horizontal","keepMounted","onScroll","onScrollEnd"])],4);var r}}}),R={data:{type:Array,required:!0},bufferSize:Number,itemSize:Number,shift:Boolean,horizontal:Boolean,as:{type:String,default:"div"},item:{type:String,default:"div"}},A=/*#__PURE__*/e.defineComponent({props:R,emits:["scroll","scrollEnd"],setup(r,{emit:o,slots:n,expose:s}){const l=r.horizontal,u=e.ref(),f=$(r.data.length,r.itemSize,void 0,0,!r.itemSize),d=((e,r)=>{const o=r?"width":"height",n=r?"innerWidth":"innerHeight",s=new WeakMap,i=j((r=>{const n=[];for(const{target:e,contentRect:i}of r){if(!e.offsetParent)continue;const r=s.get(e);r!=t&&n.push([r,i[o]])}n.length&&e.H(3,n)}));let l;return{te(t){const r=y(S(t)),o=()=>{e.H(4,r[n])};r.addEventListener("resize",o),c(o),l=()=>{r.removeEventListener("resize",o)}},re:(e,t)=>(s.set(e,t),i.J(e),()=>{s.delete(e),i.L(e)}),p(){l&&l(),i.C()}}})(f,l),p=((e,t)=>{let r,o,n=a();const s=t?"left":"top",[l]=O(e,(()=>n[0]),((e,o)=>{e=I(e,t);const n=y(S(r));o?n.scroll({[s]:e,behavior:"smooth"}):n.scroll({[s]:e})})),c=(e,t,r,o,n=0)=>{const s=o?"offsetLeft":"offsetTop",i=n+(o&&g()?r.innerWidth-e[s]-e.offsetWidth:e[s]),l=e.offsetParent;return e!==t&&l?c(l,t,r,o,i):i};return{oe(i){r=i;const l=t?"scrollX":"scrollY",a=S(i),u=y(a);o=k(e,u,t,(()=>I(u[l],t)),((t,r)=>{r?u.scroll({[s]:e.T()+t}):u.scrollBy({[s]:t})}),(()=>c(i,a.body,u,t))),n[1](!0)},p(){o&&o.C(),r=void 0,n[1](!1),n=a()},le:()=>{o&&o.F()},ie(o,{align:n,smooth:s,offset:a=0}={}){if(!r)return;if(o=i(o,0,e.q()-1),"nearest"===n){const t=e.O(o),r=e.T();if(t<r)n="start";else{if(!(t+e.j(o)>r+e.M()))return;n="end"}}const u=S(r),f=y(u),d=u.documentElement,p=()=>e.M()-(t?d.clientWidth:d.clientHeight);l((()=>a+c(r,u.body,f,t)+e.O(o)+("end"===n?e.j(o)-(e.M()-p()):"center"===n?(e.j(o)-(e.M()-p()))/2:0)),s)}}})(f,l),m=e.ref(f.m());f.A(1,(()=>{m.value=f.m()})),f.A(4,(()=>{o("scroll")})),f.A(8,(()=>{o("scrollEnd")}));const h=e.computed((e=>{m.value;const t=f.v(r.bufferSize);return e&&T(e,t)?e:t})),_=e.computed((()=>m.value&&f.B())),b=e.computed((()=>m.value&&f.P()));return e.onMounted((()=>{const e=u.value;e&&(d.te(e),p.oe(e))})),e.onUnmounted((()=>{f.p(),d.p(),p.p()})),e.watch((()=>r.data.length),(e=>{f.H(5,[e,r.shift])})),e.watch([m],(()=>{p.le()}),{flush:"post"}),s({findStartIndex:f.S,findEndIndex:f.I,scrollToIndex:p.ie}),()=>{const t=r.as,o=r.item,s=b.value,i=[];for(let[t,s]=h.value;t<=s;t++){const s=n.default({item:r.data[t],index:t})[0];i.push(e.createVNode(E,{key:q(s,t),W:m,X:f,D:d.re,U:t,Y:s,G:l,Z:o},null,8,["_stateVersion","_store","_resizer","_index","_children","_isHorizontal","_as"]))}return e.createVNode(t,{ref:u,style:{contain:"size style",overflowAnchor:"none",flex:"none",position:"relative",width:l?s+"px":"100%",height:l?"100%":s+"px",pointerEvents:_.value?"none":void 0}},"function"==typeof(c=i)||"[object Object]"===Object.prototype.toString.call(c)&&!e.isVNode(c)?i:{default:()=>[i],_:2},8,["style"]);var c}}});exports.VList=P,exports.Virtualizer=M,exports.WindowVirtualizer=A;
|
|
1
|
+
var e=require("vue");const t=null,{min:r,max:o,abs:n,floor:s}=Math,i=(e,t,n)=>r(n,o(t,e)),l=e=>[...e].sort(((e,t)=>e-t)),c="function"==typeof queueMicrotask?queueMicrotask:e=>{Promise.resolve().then(e)},a=()=>{let e;return[new Promise((t=>{e=t})),e]},u=e=>{let t;return()=>(e&&(t=e(),e=void 0),t)},f=(e,t,r)=>{const o=r?"unshift":"push";for(let r=0;r<t;r++)e[o](-1);return e},d=(e,t)=>{const r=e.t[t];return-1===r?e.o:r},p=(e,t,o)=>{const n=-1===e.t[t];return e.t[t]=o,e.i=r(t,e.i),n},h=(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+=d(e,r),e.u[++r]=o;return e.i=t,o},m=(e,t,r=0,o=e.l-1)=>{let n=r;for(;r<=o;){const i=s((r+o)/2);h(e,i)<=t?(n=i,r=i+1):o=i-1}return i(n,0,e.l-1)},b=(e,t,o)=>{const n=t-e.l;return e.i=o?-1:r(t-1,e.i),e.l=t,n>0?(f(e.u,n),f(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-(-1===r?e.o:r)),0))},_="undefined"!=typeof window,v=()=>document.documentElement,g=e=>e.ownerDocument,y=e=>e.defaultView,S=/*#__PURE__*/u((()=>!!_&&"rtl"===getComputedStyle(v()).direction)),z=/*#__PURE__*/u((()=>!!/iP(hone|od|ad)/.test(navigator.userAgent)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>0)),x=/*#__PURE__*/u((()=>"scrollBehavior"in v().style)),$=(e,s=40,i=0,c,a=!1)=>{let u=!!i,_=1,v=0,g=0,y=0,S=0,x=0,$=0,w=0,I=0,O=t,k=[0,u?o(i-1,0):-1],j=0;const q=((e,t,n)=>({o:t,t:n?f(n.slice(0,r(e,n.length)),o(0,e-n.length)):f([],e),l:e,i:-1,u:f([],e+1)}))(e,c?c[1]:s,c&&c[0]),T=new Set,B=()=>y-g,M=()=>B()+x+S,E=(e,t)=>((e,t,o,n)=>{if(n=r(n,e.l-1),h(e,n)<=t){const r=m(e,o,n);return[m(e,t,n,r),r]}{const r=m(e,t,void 0,n);return[r,m(e,o,r)]}})(q,e,t,k[0]),N=()=>h(q,q.l),P=e=>h(q,e)-x,R=e=>d(q,e),A=(e,t=-1)=>q.t[e]===t,H=e=>{e&&(z()&&0!==w||O&&1===I?x+=e:S+=e)};return{p:()=>{T.clear()},h:()=>_,m:()=>(e=>[e.t.slice(),e.o])(q),v:(e=200)=>{if(!v||u)return k;let t,n;if($)[t,n]=k;else{let s=o(0,M()),i=s+v;a||(e=o(0,e),1!==w&&(s-=e),2!==w&&(i+=e)),[t,n]=k=E(o(0,s),o(0,i)),O&&(t=r(t,O[0]),n=o(n,O[1]))}return[o(t,0),r(n,q.l-1)]},S:e=>m(q,e-g),I:A,O:P,k:R,j:()=>q.l,q:()=>y,T:()=>0!==w,B:()=>v,M:()=>g,N,P:()=>($=S,S=0,[$,2===I]),R:(e,t)=>{const r=[e,t];return T.add(r),()=>{T.delete(r)}},A:(e,r)=>{let s,i,c=0;switch(e){case 1:{if(r===y&&0===I)break;const e=$;$=0;const t=r-y,o=n(t);e&&o<n(e)+1||0!==I||(w=t<0?2:1),u&&(u=!1),y=r,c=4;const s=B();s>=-v&&s<=N()&&(c+=1,i=o>v);break}case 2:c=8,0!==w&&(s=!0,c+=1),w=0,I=0,O=t;break;case 3:{const e=r.filter((([e,t])=>!A(e,t)));if(!e.length)break;H(e.reduce(((e,[t,r])=>((2===I||(O&&1===I?t<O[0]:P(t+(0===w&&0===I?1:0))<B()))&&(e+=r-R(t)),e)),0));for(const[t,r]of e){const e=R(t),o=p(q,t,r);a&&(j+=o?r:r-e)}a&&v&&j>v&&(H(((e,t)=>{let r=0;const n=[];e.t.forEach(((e,o)=>{-1!==e&&(n.push(e),o<t&&r++)})),e.i=-1;const s=l(n),i=s.length,c=i/2|0,a=i%2==0?(s[c-1]+s[c])/2:s[c],u=e.o;return((e.o=a)-u)*o(t-r,0)})(q,m(q,M()))),a=!1),c=3,i=!0;break}case 4:v!==r&&(v||(i=!0),v=r,c=3);break;case 5:r[1]?(H(b(q,r[0],!0)),I=2,c=1):(b(q,r[0]),c=1);break;case 6:g=r;break;case 7:I=1;break;case 8:O=E(r,r+v),c=1}c&&(_=1+(2147483647&_),s&&x&&(S+=x,x=0),T.forEach((([e,t])=>{c&e&&t(i)})))}}},w=setTimeout,I=(e,t)=>t&&S()?-e:e,O=(e,r,o,n,s,i)=>{const l=Date.now;let c=0,a=!1,u=!1,f=!1,d=!1;const p=(()=>{let r;const o=()=>{r!=t&&clearTimeout(r)},n=()=>{o(),r=w((()=>{r=t,(()=>{if(a||u)return a=!1,void p();f=!1,e.A(2)})()}),150)};return n.H=o,n})(),h=()=>{c=l(),f&&(d=!0),i&&e.A(6,i()),e.A(1,n()),p()},m=t=>{if(a||!e.T()||t.ctrlKey)return;const r=l()-c;150>r&&50<r&&(o?t.deltaX:t.deltaY)&&(a=!0)},b=()=>{u=!0,f=d=!1},_=()=>{u=!1,z()&&(f=!0)};return r.addEventListener("scroll",h),r.addEventListener("wheel",m,{passive:!0}),r.addEventListener("touchstart",b,{passive:!0}),r.addEventListener("touchend",_,{passive:!0}),{V:()=>{r.removeEventListener("scroll",h),r.removeEventListener("wheel",m),r.removeEventListener("touchstart",b),r.removeEventListener("touchend",_),p.H()},C:()=>{const[t,r]=e.P();t&&(s(I(t,o),r,d),d=!1,r&&e.B()>e.N()&&e.A(1,n()))}}},k=(e,t,r)=>{let o;return[async(n,s)=>{if(!await t())return;o&&o();const i=()=>{const[t,r]=a();return o=()=>{r(!1)},e.B()&&w(o,150),[t,e.R(2,(()=>{r(!0)}))]};if(s&&x())e.A(8,n()),c((async()=>{for(;;){let t=!0;for(let[r,o]=e.v();r<=o;r++)if(e.I(r)){t=!1;break}if(t)break;const[r,o]=i();try{if(!await r)return}finally{o()}}e.A(7),r(n(),s)}));else for(;;){const[t,o]=i();try{if(e.A(7),r(n()),!await t)return}finally{o()}}},()=>{o&&o()}]},j=e=>{let t;return{F(r){(t||(t=new(y(g(r)).ResizeObserver)(e))).observe(r)},J(e){t.unobserve(e)},V(){t&&t.disconnect()}}},q=/*#__PURE__*/e.defineComponent({props:{L:{type:Object,required:!0},W:{type:Object,required:!0},X:{type:Object,required:!0},Y:{type:Function,required:!0},D:{type:Number,required:!0},U:{type:Boolean},G:{type:Boolean},K:{type:String,required:!0},Z:Object},setup(t){const r=e.ref(),o=e.computed((()=>t.L.value&&t.W.O(t.D))),n=e.computed((()=>t.L.value&&t.W.I(t.D)));return e.watch((()=>r.value&&t.D),((e,o,n)=>{n(t.Y(r.value,t.D))}),{flush:"post"}),()=>{var s;const{X:i,U:l,G:c,K:a}=t,u=n.value,{style:f,...d}=null!==(s=t.Z)&&void 0!==s?s:{},p={contain:"layout style",position:u&&c?void 0:"absolute",[l?"height":"width"]:"100%",[l?"top":"left"]:"0px",[l?S()?"right":"left":"top"]:o.value+"px",visibility:!u||c?void 0:"hidden",...f};return l&&(p.display="inline-flex"),e.createVNode(a,e.mergeProps({ref:r,style:p},d),"function"==typeof(h=i)||"[object Object]"===Object.prototype.toString.call(h)&&!e.isVNode(h)?i:{default:()=>[i],_:2},16,["style"]);var h}}}),T=(e,t)=>{const r=e.key;return null!=r?r:"_"+t},B=(e,t)=>e[0]===t[0]&&e[1]===t[1],M={data:{type:Array,required:!0},bufferSize:Number,itemSize:Number,shift:Boolean,horizontal:Boolean,startMargin:{type:Number,default:0},ssrCount:Number,scrollRef:Object,as:{type:String,default:"div"},item:{type:String,default:"div"},itemProps:Function,keepMounted:Array,cache:Object},E=/*#__PURE__*/e.defineComponent({props:M,emits:["scroll","scrollEnd"],setup(r,{emit:n,expose:s,slots:c}){let u=!!r.ssrCount;const f=r.horizontal,d=e.ref(),p=$(r.data.length,r.itemSize,r.ssrCount,r.cache,!r.itemSize),h=((e,r)=>{let o;const n=r?"width":"height",s=new WeakMap,i=j((r=>{const i=[];for(const{target:l,contentRect:c}of r)if(l.offsetParent)if(l===o)e.A(4,c[n]);else{const e=s.get(l);e!=t&&i.push([e,c[n]])}i.length&&e.A(3,i)}));return{ee(e){i.F(o=e)},te:(e,t)=>(s.set(e,t),i.F(e),()=>{s.delete(e),i.J(e)}),p:i.V}})(p,f),m=((e,t)=>{let r,o,n=a();const s=t?"scrollLeft":"scrollTop",l=t?"overflowX":"overflowY",[c,u]=k(e,(()=>n[0]),((e,o)=>{e=I(e,t),o?r.scrollTo({[t?"left":"top"]:e,behavior:"smooth"}):r[s]=e}));return{re(i){r=i,o=O(e,i,t,(()=>I(i[s],t)),((t,r,o)=>{if(o){const e=i.style,t=e[l];e[l]="hidden",w((()=>{e[l]=t}))}i[s]=e.q()+t,r&&u()})),n[1](!0)},p(){o&&o.V(),n[1](!1),n=a()},oe(e){c((()=>e))},ne(t){t+=e.q(),c((()=>t))},se(t,{align:r,smooth:o,offset:n=0}={}){if(t=i(t,0,e.j()-1),"nearest"===r){const o=e.O(t),n=e.q();if(o<n)r="start";else{if(!(o+e.k(t)>n+e.B()))return;r="end"}}c((()=>n+e.M()+e.O(t)+("end"===r?e.k(t)-e.B():"center"===r?(e.k(t)-e.B())/2:0)),o)},ie:()=>{o&&o.C()}}})(p,f),b=e.ref(p.h());p.R(1,(()=>{b.value=p.h()})),p.R(4,(()=>{n("scroll",p.q())})),p.R(8,(()=>{n("scrollEnd")}));const _=e.computed((e=>{b.value;const t=p.v(r.bufferSize);return e&&B(e,t)?e:t})),v=e.computed((()=>b.value&&p.T())),g=e.computed((()=>b.value&&p.N()));return e.onMounted((()=>{u=!1;const t=requestAnimationFrame((()=>{const e=e=>{h.ee(e),m.re(e)};r.scrollRef?e(r.scrollRef):e(d.value.parentElement)}));e.onUnmounted((()=>{cancelAnimationFrame(t)}))})),e.onUnmounted((()=>{p.p(),h.p(),m.p()})),e.watch((()=>r.data.length),(e=>{p.A(5,[e,r.shift])})),e.watch((()=>r.startMargin),(e=>{p.A(6,e)}),{immediate:!0}),e.watch([b],(()=>{m.ie()}),{flush:"post"}),s({get cache(){return p.m()},get scrollOffset(){return p.q()},get scrollSize(){return(e=>o(e.N(),e.B()))(p)},get viewportSize(){return p.B()},findItemIndex:p.S,getItemOffset:p.O,getItemSize:p.k,scrollToIndex:m.se,scrollTo:m.oe,scrollBy:m.ne}),()=>{const t=r.as,o=r.item,n=g.value,s=[],i=t=>{var n;const s=c.default({item:r.data[t],index:t})[0];return e.createVNode(q,{key:T(s,t),L:b,W:p,Y:h.te,D:t,X:s,U:f,G:u,K:o,Z:null===(n=r.itemProps)||void 0===n?void 0:n.call(r,{item:r.data[t],index:t})},null,8,["_stateVersion","_store","_resizer","_index","_children","_isHorizontal","_isSSR","_as","_itemProps"])};if(r.keepMounted){const e=new Set(r.keepMounted);for(let[t,r]=_.value;t<=r;t++)e.add(t);l([...e]).forEach((e=>{s.push(i(e))}))}else for(let[e,t]=_.value;e<=t;e++)s.push(i(e));return e.createVNode(t,{ref:d,style:{contain:"size style",overflowAnchor:"none",flex:"none",position:"relative",width:f?n+"px":"100%",height:f?"100%":n+"px",pointerEvents:v.value?"none":void 0}},"function"==typeof(a=s)||"[object Object]"===Object.prototype.toString.call(a)&&!e.isVNode(a)?s:{default:()=>[s],_:2},8,["style"]);var a}}}),N={data:{type:Array,required:!0},bufferSize:Number,itemSize:Number,shift:Boolean,horizontal:Boolean,ssrCount:Number,itemProps:Function,keepMounted:Array,cache:Object},P=/*#__PURE__*/e.defineComponent({props:N,emits:["scroll","scrollEnd"],setup(t,{emit:r,expose:o,slots:n}){const s=t.horizontal,i=e=>{r("scroll",e)},l=()=>{r("scrollEnd")},c=e.ref();return o({get cache(){return c.value.cache},get scrollOffset(){return c.value.scrollOffset},get scrollSize(){return c.value.scrollSize},get viewportSize(){return c.value.viewportSize},findItemIndex:(...e)=>c.value.findItemIndex(...e),getItemOffset:(...e)=>c.value.getItemOffset(...e),getItemSize:(...e)=>c.value.getItemSize(...e),scrollToIndex:(...e)=>c.value.scrollToIndex(...e),scrollTo:(...e)=>c.value.scrollTo(...e),scrollBy:(...e)=>c.value.scrollBy(...e)}),()=>{return e.createVNode("div",{style:{display:s?"inline-block":"block",[s?"overflowX":"overflowY"]:"auto",contain:"strict",width:"100%",height:"100%"}},[e.createVNode(E,{ref:c,data:t.data,bufferSize:t.bufferSize,itemSize:t.itemSize,itemProps:t.itemProps,shift:t.shift,ssrCount:t.ssrCount,horizontal:s,keepMounted:t.keepMounted,cache:t.cache,onScroll:i,onScrollEnd:l},(r=n,"function"==typeof r||"[object Object]"===Object.prototype.toString.call(r)&&!e.isVNode(r)?n:{default:()=>[n],_:2}),8,["data","bufferSize","itemSize","itemProps","shift","ssrCount","horizontal","keepMounted","cache","onScroll","onScrollEnd"])],4);var r}}}),R={data:{type:Array,required:!0},bufferSize:Number,itemSize:Number,shift:Boolean,horizontal:Boolean,as:{type:String,default:"div"},item:{type:String,default:"div"},cache:Object},A=/*#__PURE__*/e.defineComponent({props:R,emits:["scroll","scrollEnd"],setup(r,{emit:o,slots:n,expose:s}){const l=r.horizontal,u=e.ref(),f=$(r.data.length,r.itemSize,void 0,r.cache,!r.itemSize),d=((e,r)=>{const o=r?"width":"height",n=r?"innerWidth":"innerHeight",s=new WeakMap,i=j((r=>{const n=[];for(const{target:e,contentRect:i}of r){if(!e.offsetParent)continue;const r=s.get(e);r!=t&&n.push([r,i[o]])}n.length&&e.A(3,n)}));let l;return{ee(t){const r=y(g(t)),o=()=>{e.A(4,r[n])};r.addEventListener("resize",o),c(o),l=()=>{r.removeEventListener("resize",o)}},te:(e,t)=>(s.set(e,t),i.F(e),()=>{s.delete(e),i.J(e)}),p(){l&&l(),i.V()}}})(f,l),p=((e,t)=>{let r,o,n=a();const s=t?"left":"top",[l]=k(e,(()=>n[0]),((e,o)=>{e=I(e,t);const n=y(g(r));o?n.scroll({[s]:e,behavior:"smooth"}):n.scroll({[s]:e})})),c=(e,t,r,o,n=0)=>{const s=o?"offsetLeft":"offsetTop",i=n+(o&&S()?r.innerWidth-e[s]-e.offsetWidth:e[s]),l=e.offsetParent;return e!==t&&l?c(l,t,r,o,i):i};return{re(i){r=i;const l=t?"scrollX":"scrollY",a=g(i),u=y(a);o=O(e,u,t,(()=>I(u[l],t)),((t,r)=>{r?u.scroll({[s]:e.q()+t}):u.scrollBy({[s]:t})}),(()=>c(i,a.body,u,t))),n[1](!0)},p(){o&&o.V(),r=void 0,n[1](!1),n=a()},ie:()=>{o&&o.C()},se(o,{align:n,smooth:s,offset:a=0}={}){if(!r)return;if(o=i(o,0,e.j()-1),"nearest"===n){const t=e.O(o),r=e.q();if(t<r)n="start";else{if(!(t+e.k(o)>r+e.B()))return;n="end"}}const u=g(r),f=y(u),d=u.documentElement,p=()=>e.B()-(t?d.clientWidth:d.clientHeight);l((()=>a+c(r,u.body,f,t)+e.O(o)+("end"===n?e.k(o)-(e.B()-p()):"center"===n?(e.k(o)-(e.B()-p()))/2:0)),s)}}})(f,l),h=e.ref(f.h());f.R(1,(()=>{h.value=f.h()})),f.R(4,(()=>{o("scroll")})),f.R(8,(()=>{o("scrollEnd")}));const m=e.computed((e=>{h.value;const t=f.v(r.bufferSize);return e&&B(e,t)?e:t})),b=e.computed((()=>h.value&&f.T())),_=e.computed((()=>h.value&&f.N()));return e.onMounted((()=>{const e=u.value;e&&(d.ee(e),p.re(e))})),e.onUnmounted((()=>{f.p(),d.p(),p.p()})),e.watch((()=>r.data.length),(e=>{f.A(5,[e,r.shift])})),e.watch([h],(()=>{p.ie()}),{flush:"post"}),s({get cache(){return f.m()},get scrollOffset(){return f.q()},get viewportSize(){return f.B()},findItemIndex:f.S,getItemOffset:f.O,getItemSize:f.k,scrollToIndex:p.se}),()=>{const t=r.as,o=r.item,s=_.value,i=[];for(let[t,s]=m.value;t<=s;t++){const s=n.default({item:r.data[t],index:t})[0];i.push(e.createVNode(q,{key:T(s,t),L:h,W:f,Y:d.te,D:t,X:s,U:l,K:o},null,8,["_stateVersion","_store","_resizer","_index","_children","_isHorizontal","_as"]))}return e.createVNode(t,{ref:u,style:{contain:"size style",overflowAnchor:"none",flex:"none",position:"relative",width:l?s+"px":"100%",height:l?"100%":s+"px",pointerEvents:b.value?"none":void 0}},"function"==typeof(c=i)||"[object Object]"===Object.prototype.toString.call(c)&&!e.isVNode(c)?i:{default:()=>[i],_:2},8,["style"]);var c}}});exports.VList=P,exports.Virtualizer=E,exports.WindowVirtualizer=A;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|