diff --git a/TEST.md b/TEST.md index 277f788..a8f4ae5 100644 --- a/TEST.md +++ b/TEST.md @@ -3,12 +3,12 @@ ## 基准测试 (Benchmark) *测试环境: Playwright / Chromium* -| 指标 | v1.0.0 | v1.0.1 | v1.0.3 | -| :--- | :--- | :--- | :--- | -| **FastList Render & Scroll (10k items)** | ~535ms | ~473ms | ~1513ms | -| **FastGroupedList Render & Scroll (10k)** | ~705ms | ~51ms | ~51ms | -| **FastTree Render & Scroll (10k items)** | ~927ms | ~50ms | ~51ms | -| **CollapseTree Render & Scroll (1.2k)** | ~51ms | ~50ms | ~50ms | +| 指标 | v1.0.0 | v1.0.1 | v1.0.3 | v1.0.4 | +| :--- | :--- | :--- | :--- | :--- | +| **FastList Render & Scroll (10k items)** | ~535ms | ~473ms | ~1513ms | ~54ms | +| **FastGroupedList Render & Scroll (10k)** | ~705ms | ~51ms | ~51ms | ~1550ms | +| **FastTree Render & Scroll (10k items)** | ~927ms | ~50ms | ~51ms | ~1560ms | +| **CollapseTree Render & Scroll (1.2k)** | ~51ms | ~50ms | ~50ms | ~51ms | ## 测试覆盖 (Coverage) - [x] HTTP Request (GET/POST) diff --git a/package.json b/package.json index 3576511..639702b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name": "@web/base", - "version": "1.0.3", - "type": "module", + "version": "1.0.4", "type": "module", "main": "dist/base.js", "module": "dist/base.js", "files": [ diff --git a/src/list.js b/src/list.js index 9d0e68d..c43420b 100644 --- a/src/list.js +++ b/src/list.js @@ -43,25 +43,28 @@ export const VirtualScroll = () => { }, calc: (container, list) => { if (!listInited || !list) return null; - const size = list.length, visibleCount = Math.ceil((container.clientHeight || 100) / (avg.get() || 32)); + const size = list.length, visibleCount = Math.max(10, Math.ceil((container.clientHeight || 100) / (avg.get() || 32))); let prev = padTop + topMargin + rowGap, post = 0, status = 0, listStartIndex = 0, listEndIndex = 0; + const scrollTop = container.scrollTop; + for (let i = 0; i < size; i++) { if (status === 0) { const gh = groupHeights.get(i); - if (gh && prev + gh < container.scrollTop) { prev += gh; i += Math.min(groupItemCount, size - i) - 1; } + if (gh && prev + gh < scrollTop && i + groupItemCount <= size) { prev += gh; i += groupItemCount - 1; } else { const ih = itemHeights.get(i); - if (prev + ih < container.scrollTop) prev += ih; + if (prev + ih < scrollTop && i < size - 1) prev += ih; else { - status = 1; let visibleStartIndex = Math.max(0, i); + status = 1; let visibleStartIndex = i; listStartIndex = Math.max(0, visibleStartIndex - visibleCount); listEndIndex = Math.min(listStartIndex + visibleCount * 3, size); i = listEndIndex - 1; for (let j = listStartIndex; j < visibleStartIndex; j++) prev -= itemHeights.get(j); } } - } else if (status === 1) { + } else { const gh = groupHeights.get(i); - if (gh) { post += gh; i += groupItemCount - 1; } else post += itemHeights.get(i); + if (gh && i + groupItemCount <= size) { post += gh; i += groupItemCount - 1; } + else post += itemHeights.get(i); } } return { prevHeight: Math.max(0, prev - padTop - topMargin - rowGap), postHeight: post, renderedList: list.slice(listStartIndex, listEndIndex), listStartIndex }; diff --git a/test/index.html b/test/index.html index 0c079d0..0531422 100644 --- a/test/index.html +++ b/test/index.html @@ -28,17 +28,29 @@ }
- - - - - - - - +
+
Fast List (Variable Height)
+ + + +
+
+
Fast Grouped List
+ + +
+
+
Fast Tree List
+ +
+
+
Normal Tree List (Collapsible)
+ + +