lazy-render-virtual-scroll 1.0.1 → 1.0.2

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.
@@ -1,98 +0,0 @@
1
- import { WindowManager } from '../src/core/WindowManager';
2
-
3
- // Simple test runner for Node.js
4
- function describe(name: string, fn: () => void) {
5
- console.log(`\nDESCRIBE: ${name}`);
6
- fn();
7
- }
8
-
9
- function test(name: string, fn: () => void | Promise<void>) {
10
- console.log(` TEST: ${name}`);
11
-
12
- try {
13
- const result = fn();
14
- if (result instanceof Promise) {
15
- result.then(() => console.log(' PASS'))
16
- .catch(err => console.error(` FAIL: ${err.message}`));
17
- } else {
18
- console.log(' PASS');
19
- }
20
- } catch (err) {
21
- console.error(` FAIL: ${(err as Error).message}`);
22
- }
23
- }
24
-
25
- function expect(actual: any) {
26
- return {
27
- toBe: (expected: any) => {
28
- if (actual !== expected) {
29
- throw new Error(`Expected ${actual} to be ${expected}`);
30
- }
31
- },
32
- toBeGreaterThanOrEqual: (expected: number) => {
33
- if (!(actual >= expected)) {
34
- throw new Error(`Expected ${actual} to be greater than or equal to ${expected}`);
35
- }
36
- },
37
- toBeGreaterThan: (expected: number) => {
38
- if (!(actual > expected)) {
39
- throw new Error(`Expected ${actual} to be greater than ${expected}`);
40
- }
41
- }
42
- };
43
- }
44
-
45
- describe('WindowManager', () => {
46
- let windowManager: WindowManager;
47
-
48
- beforeEach(() => {
49
- windowManager = new WindowManager(50, 200, 2); // itemHeight: 50, viewportHeight: 200, bufferSize: 2
50
- });
51
-
52
- test('should calculate visible range correctly with zero scroll', () => {
53
- const range = windowManager.calculateVisibleRange(0);
54
-
55
- expect(range.start).toBeGreaterThanOrEqual(0);
56
- expect(range.end).toBeGreaterThan(0);
57
- // With viewport of 200 and item height of 50, we can fit 4 items
58
- // Plus buffer of 2, so end should be at least 6
59
- expect(range.end).toBeGreaterThanOrEqual(4); // 4 items in viewport + buffer
60
- });
61
-
62
- test('should calculate visible range correctly with middle scroll', () => {
63
- const range = windowManager.calculateVisibleRange(100); // scrolled down 100px
64
-
65
- // With item height of 50, scroll of 100 means we're at item index 2
66
- // So visible range should start around index 0 (with negative buffer) or 0 (clamped)
67
- expect(range.start).toBeGreaterThanOrEqual(0);
68
- expect(range.end).toBeGreaterThan(range.start);
69
- });
70
-
71
- test('should calculate visible range correctly with large scroll', () => {
72
- const range = windowManager.calculateVisibleRange(1000); // scrolled way down
73
-
74
- expect(range.start).toBeGreaterThan(10); // Should be showing items much further down
75
- expect(range.end).toBeGreaterThan(range.start);
76
- });
77
-
78
- test('should update viewport height', () => {
79
- windowManager.updateViewportHeight(400); // Double the viewport height
80
-
81
- const range = windowManager.calculateVisibleRange(0);
82
- // With larger viewport, we should see more items
83
- expect(range.end).toBeGreaterThan(8); // Should see more than 4 items now
84
- });
85
-
86
- test('should update item height', () => {
87
- windowManager.updateItemHeight(25); // Half the item height
88
-
89
- const range = windowManager.calculateVisibleRange(0);
90
- // With smaller items, we should see more items in the same viewport
91
- expect(range.end).toBeGreaterThan(8); // Should see more items with smaller height
92
- });
93
- });
94
-
95
- // Define beforeEach for compatibility
96
- function beforeEach(fn: () => void) {
97
- fn();
98
- }
package/tsconfig.json DELETED
@@ -1,33 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2018",
4
- "lib": ["DOM", "ES2018"],
5
- "module": "ESNext",
6
- "moduleResolution": "node",
7
- "declaration": true,
8
- "declarationMap": true,
9
- "sourceMap": true,
10
- "outDir": "./dist",
11
- "rootDir": "./src",
12
- "strict": true,
13
- "esModuleInterop": true,
14
- "skipLibCheck": true,
15
- "forceConsistentCasingInFileNames": true,
16
- "jsx": "react-jsx",
17
- "allowSyntheticDefaultImports": true,
18
- "resolveJsonModule": true,
19
- "noImplicitAny": true,
20
- "noImplicitReturns": true,
21
- "noFallthroughCasesInSwitch": true,
22
- "noUncheckedIndexedAccess": true,
23
- "types": ["node"]
24
- },
25
- "include": [
26
- "src/**/*"
27
- ],
28
- "exclude": [
29
- "node_modules",
30
- "dist",
31
- "test"
32
- ]
33
- }