@pdanpdan/virtual-scroll 0.5.0 → 0.6.1
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 +73 -174
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +192 -348
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1691 -2198
- package/dist/index.mjs.map +1 -1
- package/dist/virtual-scroll.css +2 -1
- package/package.json +4 -2
- package/src/components/VirtualScroll.vue +25 -55
- package/src/composables/useVirtualScroll.ts +81 -145
- package/src/composables/useVirtualScrollbar.ts +5 -0
- package/src/index.ts +7 -0
- package/src/types.ts +132 -170
- package/src/utils/scroll.ts +31 -0
- package/src/utils/virtual-scroll-logic.ts +82 -49
- package/src/components/VirtualScroll.test.ts +0 -2332
- package/src/components/VirtualScrollbar.test.ts +0 -174
- package/src/composables/useVirtualScroll.test.ts +0 -1627
- package/src/composables/useVirtualScrollbar.test.ts +0 -526
- package/src/utils/fenwick-tree.test.ts +0 -134
- package/src/utils/scroll.test.ts +0 -174
- package/src/utils/virtual-scroll-logic.test.ts +0 -2850
package/src/utils/scroll.test.ts
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
|
|
3
|
-
import { getPaddingX, getPaddingY, isBody, isElement, isScrollableElement, isScrollToIndexOptions, isWindow, isWindowLike } from './scroll';
|
|
4
|
-
|
|
5
|
-
describe('scroll utils', () => {
|
|
6
|
-
describe('element type guards', () => {
|
|
7
|
-
describe('iswindow', () => {
|
|
8
|
-
it('returns true for null', () => {
|
|
9
|
-
expect(isWindow(null)).toBe(true);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('returns true for window object', () => {
|
|
13
|
-
expect(isWindow(window)).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('returns true for document.documentelement object', () => {
|
|
17
|
-
expect(isWindow(document.documentElement)).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('returns false for an element', () => {
|
|
21
|
-
const el = document.createElement('div');
|
|
22
|
-
expect(isWindow(el)).toBe(false);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('returns false for undefined', () => {
|
|
26
|
-
expect(isWindow(undefined)).toBe(false);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('isbody', () => {
|
|
31
|
-
it('returns true for document.body', () => {
|
|
32
|
-
expect(isBody(document.body)).toBe(true);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('returns false for null', () => {
|
|
36
|
-
expect(isBody(null)).toBe(false);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('returns false for undefined', () => {
|
|
40
|
-
expect(isBody(undefined)).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('returns false for a string', () => {
|
|
44
|
-
// @ts-expect-error testing invalid input
|
|
45
|
-
expect(isBody('not an object')).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('returns false for a plain object', () => {
|
|
49
|
-
// @ts-expect-error testing invalid input
|
|
50
|
-
expect(isBody({})).toBe(false);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('returns false for a div', () => {
|
|
54
|
-
const el = document.createElement('div');
|
|
55
|
-
expect(isBody(el)).toBe(false);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('returns false for window', () => {
|
|
59
|
-
expect(isBody(window)).toBe(false);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('returns false for document.documentelement', () => {
|
|
63
|
-
expect(isBody(document.documentElement)).toBe(false);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('iswindowlike', () => {
|
|
68
|
-
it('returns true for window', () => {
|
|
69
|
-
expect(isWindowLike(window)).toBe(true);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('returns true for document.documentelement', () => {
|
|
73
|
-
expect(isWindowLike(document.documentElement)).toBe(true);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('returns true for body', () => {
|
|
77
|
-
expect(isWindowLike(document.body)).toBe(true);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('returns true for null', () => {
|
|
81
|
-
expect(isWindowLike(null)).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('returns false for a div', () => {
|
|
85
|
-
const el = document.createElement('div');
|
|
86
|
-
expect(isWindowLike(el)).toBe(false);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe('iselement', () => {
|
|
91
|
-
it('returns true for a div', () => {
|
|
92
|
-
const el = document.createElement('div');
|
|
93
|
-
expect(isElement(el)).toBe(true);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('returns true for document.documentelement', () => {
|
|
97
|
-
expect(isElement(document.documentElement)).toBe(true);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('returns false for window', () => {
|
|
101
|
-
expect(isElement(window)).toBe(false);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('returns false for null', () => {
|
|
105
|
-
expect(isElement(null)).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('isscrollableelement', () => {
|
|
110
|
-
it('returns true for a div', () => {
|
|
111
|
-
const el = document.createElement('div');
|
|
112
|
-
expect(isScrollableElement(el)).toBe(true);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('returns false for null', () => {
|
|
116
|
-
expect(isScrollableElement(null)).toBe(false);
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('options type guards', () => {
|
|
122
|
-
describe('isscrolltoindexoptions', () => {
|
|
123
|
-
it('returns true for valid options', () => {
|
|
124
|
-
expect(isScrollToIndexOptions({ align: 'start' })).toBe(true);
|
|
125
|
-
expect(isScrollToIndexOptions({ behavior: 'smooth' })).toBe(true);
|
|
126
|
-
expect(isScrollToIndexOptions({ isCorrection: true })).toBe(true);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('returns false for other values', () => {
|
|
130
|
-
expect(isScrollToIndexOptions(null)).toBe(false);
|
|
131
|
-
expect(isScrollToIndexOptions('start')).toBe(false);
|
|
132
|
-
expect(isScrollToIndexOptions({})).toBe(false);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe('padding utilities', () => {
|
|
138
|
-
describe('getpaddingx', () => {
|
|
139
|
-
it('handles numeric padding', () => {
|
|
140
|
-
expect(getPaddingX(10, 'horizontal')).toBe(10);
|
|
141
|
-
expect(getPaddingX(10, 'both')).toBe(10);
|
|
142
|
-
expect(getPaddingX(10, 'vertical')).toBe(0);
|
|
143
|
-
expect(getPaddingX(0, 'horizontal')).toBe(0);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('handles object padding', () => {
|
|
147
|
-
expect(getPaddingX({ x: 15 }, 'vertical')).toBe(15);
|
|
148
|
-
expect(getPaddingX({ y: 20 }, 'horizontal')).toBe(0);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('returns 0 for undefined', () => {
|
|
152
|
-
expect(getPaddingX(undefined)).toBe(0);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe('getpaddingy', () => {
|
|
157
|
-
it('handles numeric padding', () => {
|
|
158
|
-
expect(getPaddingY(10, 'vertical')).toBe(10);
|
|
159
|
-
expect(getPaddingY(10, 'both')).toBe(10);
|
|
160
|
-
expect(getPaddingY(10, 'horizontal')).toBe(0);
|
|
161
|
-
expect(getPaddingY(0, 'vertical')).toBe(0);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('handles object padding', () => {
|
|
165
|
-
expect(getPaddingY({ y: 15 }, 'horizontal')).toBe(15);
|
|
166
|
-
expect(getPaddingY({ x: 20 }, 'vertical')).toBe(0);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('returns 0 for undefined', () => {
|
|
170
|
-
expect(getPaddingY(undefined)).toBe(0);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
});
|