@pdanpdan/virtual-scroll 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +182 -88
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +100 -35
- package/dist/index.js +1 -823
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +902 -0
- package/dist/index.mjs.map +1 -0
- package/dist/virtual-scroll.css +2 -0
- package/package.json +9 -6
- package/src/components/VirtualScroll.test.ts +397 -329
- package/src/components/VirtualScroll.vue +107 -25
- package/src/composables/useVirtualScroll.test.ts +1029 -255
- package/src/composables/useVirtualScroll.ts +176 -88
- package/src/utils/fenwick-tree.test.ts +80 -65
- package/dist/index.css +0 -2
|
@@ -3,84 +3,99 @@ import { describe, expect, it } from 'vitest';
|
|
|
3
3
|
import { FenwickTree } from './fenwick-tree';
|
|
4
4
|
|
|
5
5
|
describe('fenwickTree', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
describe('initialization', () => {
|
|
7
|
+
it('should initialize with correct size', () => {
|
|
8
|
+
const tree = new FenwickTree(5);
|
|
9
|
+
expect(tree.query(5)).toBe(0);
|
|
10
|
+
expect(tree.length).toBe(5);
|
|
11
|
+
});
|
|
9
12
|
});
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
describe('query and update', () => {
|
|
15
|
+
it('should update and query values', () => {
|
|
16
|
+
const tree = new FenwickTree(5);
|
|
17
|
+
tree.update(0, 10);
|
|
18
|
+
tree.update(1, 20);
|
|
19
|
+
tree.update(2, 30);
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
expect(tree.query(0)).toBe(0);
|
|
22
|
+
expect(tree.query(1)).toBe(10);
|
|
23
|
+
expect(tree.query(2)).toBe(30);
|
|
24
|
+
expect(tree.query(3)).toBe(60);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should handle updates to existing indices', () => {
|
|
28
|
+
const tree = new FenwickTree(3);
|
|
29
|
+
tree.update(1, 10);
|
|
30
|
+
expect(tree.query(2)).toBe(10);
|
|
31
|
+
tree.update(1, 5); // Add 5 to index 1
|
|
32
|
+
expect(tree.query(2)).toBe(15);
|
|
33
|
+
});
|
|
22
34
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
it('should ignore updates for out of bounds indices', () => {
|
|
36
|
+
const tree = new FenwickTree(5);
|
|
37
|
+
tree.update(-1, 10);
|
|
38
|
+
tree.update(5, 10);
|
|
39
|
+
expect(tree.query(5)).toBe(0);
|
|
40
|
+
});
|
|
29
41
|
});
|
|
30
42
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
describe('search and bounds', () => {
|
|
44
|
+
it('should find lower bound correctly', () => {
|
|
45
|
+
const tree = new FenwickTree(5);
|
|
46
|
+
tree.update(0, 10); // sum up to 1: 10
|
|
47
|
+
tree.update(1, 10); // sum up to 2: 20
|
|
48
|
+
tree.update(2, 10); // sum up to 3: 30
|
|
36
49
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
expect(tree.findLowerBound(5)).toBe(0);
|
|
51
|
+
expect(tree.findLowerBound(15)).toBe(1);
|
|
52
|
+
expect(tree.findLowerBound(25)).toBe(2);
|
|
53
|
+
expect(tree.findLowerBound(35)).toBe(5); // Returns size when not found
|
|
54
|
+
});
|
|
41
55
|
});
|
|
42
56
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
describe('rebuild and resize', () => {
|
|
58
|
+
it('should set and rebuild correctly', () => {
|
|
59
|
+
const tree = new FenwickTree(5);
|
|
60
|
+
tree.set(0, 10);
|
|
61
|
+
tree.set(1, 20);
|
|
62
|
+
tree.set(2, 30);
|
|
63
|
+
tree.set(-1, 40); // ignore
|
|
64
|
+
tree.set(5, 50); // ignore
|
|
65
|
+
expect(tree.query(3)).toBe(0); // not rebuilt yet
|
|
66
|
+
tree.rebuild();
|
|
67
|
+
expect(tree.query(3)).toBe(60);
|
|
68
|
+
});
|
|
51
69
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
70
|
+
it('should resize and preserve existing values', () => {
|
|
71
|
+
const tree = new FenwickTree(5);
|
|
72
|
+
tree.update(0, 10);
|
|
73
|
+
tree.resize(10);
|
|
74
|
+
expect(tree.query(1)).toBe(10);
|
|
75
|
+
expect(tree.query(10)).toBe(10);
|
|
76
|
+
tree.resize(10); // same size
|
|
77
|
+
});
|
|
57
78
|
});
|
|
58
79
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
tree.rebuild();
|
|
68
|
-
expect(tree.query(3)).toBe(60);
|
|
69
|
-
});
|
|
80
|
+
describe('values access', () => {
|
|
81
|
+
it('should return the individual value at an index', () => {
|
|
82
|
+
const tree = new FenwickTree(3);
|
|
83
|
+
tree.update(0, 10);
|
|
84
|
+
expect(tree.get(0)).toBe(10);
|
|
85
|
+
expect(tree.get(-1)).toBe(0);
|
|
86
|
+
expect(tree.get(10)).toBe(0);
|
|
87
|
+
});
|
|
70
88
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
expect(tree.get(0)).toBe(10);
|
|
82
|
-
expect(tree.get(-1)).toBe(0);
|
|
83
|
-
expect(tree.get(10)).toBe(0);
|
|
89
|
+
it('should return the underlying values array', () => {
|
|
90
|
+
const tree = new FenwickTree(3);
|
|
91
|
+
tree.update(0, 10);
|
|
92
|
+
tree.update(1, 20);
|
|
93
|
+
const values = tree.getValues();
|
|
94
|
+
expect(values).toBeInstanceOf(Float64Array);
|
|
95
|
+
expect(values[ 0 ]).toBe(10);
|
|
96
|
+
expect(values[ 1 ]).toBe(20);
|
|
97
|
+
expect(values[ 2 ]).toBe(0);
|
|
98
|
+
});
|
|
84
99
|
});
|
|
85
100
|
|
|
86
101
|
describe('shift', () => {
|
package/dist/index.css
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
.virtual-scroll-container[data-v-8d960026]{outline-offset:1px;block-size:100%;inline-size:100%;position:relative}.virtual-scroll-container[data-v-8d960026]:not(.virtual-scroll--window){overscroll-behavior:contain;overflow:auto}.virtual-scroll-container.virtual-scroll--table[data-v-8d960026]{display:block}.virtual-scroll--horizontal[data-v-8d960026]{white-space:nowrap}.virtual-scroll-wrapper[data-v-8d960026]{contain:layout;position:relative}:where(.virtual-scroll--hydrated>.virtual-scroll-wrapper>.virtual-scroll-item[data-v-8d960026]){position:absolute;inset-block-start:0;inset-inline-start:0}.virtual-scroll-item[data-v-8d960026]{box-sizing:border-box;will-change:transform}.virtual-scroll-item:where(.virtual-scroll--debug)[data-v-8d960026]{background-color:#ff00000d;outline:1px dashed #ff000080}.virtual-scroll-item:where(.virtual-scroll--debug)[data-v-8d960026]:where(:hover){z-index:100;background-color:#ff00001a}.virtual-scroll-debug-info[data-v-8d960026]{color:#fff;pointer-events:none;z-index:100;background:#000000b3;border-radius:4px;padding:2px 4px;font-family:monospace;font-size:10px;position:absolute;inset-block-start:2px;inset-inline-end:2px}.virtual-scroll-spacer[data-v-8d960026]{pointer-events:none}.virtual-scroll-header[data-v-8d960026],.virtual-scroll-footer[data-v-8d960026]{z-index:20;position:relative}.virtual-scroll--sticky[data-v-8d960026]{position:sticky}.virtual-scroll--sticky[data-v-8d960026]:where(.virtual-scroll-header){box-sizing:border-box;min-inline-size:100%;inset-block-start:0;inset-inline-start:0}.virtual-scroll--sticky[data-v-8d960026]:where(.virtual-scroll-footer){box-sizing:border-box;min-inline-size:100%;inset-block-end:0;inset-inline-start:0}.virtual-scroll--sticky[data-v-8d960026]:where(.virtual-scroll-item){z-index:10}:is(tbody.virtual-scroll-wrapper,thead.virtual-scroll-header,tfoot.virtual-scroll-footer)[data-v-8d960026]{min-inline-size:100%;display:inline-flex}:is(tbody.virtual-scroll-wrapper,thead.virtual-scroll-header,tfoot.virtual-scroll-footer)[data-v-8d960026]>tr{min-inline-size:100%;display:inline-flex}:is(tbody.virtual-scroll-wrapper,thead.virtual-scroll-header,tfoot.virtual-scroll-footer)[data-v-8d960026]>tr>:is(td,th){align-items:center;display:inline-block}
|
|
2
|
-
/*$vite$:1*/
|