@pixelium/web-vue 0.0.2 → 0.0.3-beta
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 +42 -0
- package/README.zh.md +6 -3
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/coverage-final.json +106 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +926 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/font.css +1 -1
- package/dist/index.d.ts +1593 -248
- package/dist/normalize.css +2 -0
- package/dist/pixelium-vue-icon-hn.cjs +1 -1
- package/dist/pixelium-vue-icon-hn.css +2 -1
- package/dist/pixelium-vue-icon-hn.js +8533 -8154
- package/dist/pixelium-vue-icon-hn.umd.cjs +1 -1
- package/dist/pixelium-vue-icon-pa.cjs +1 -1
- package/dist/pixelium-vue-icon-pa.css +2 -1
- package/dist/pixelium-vue-icon-pa.js +10625 -10143
- package/dist/pixelium-vue-icon-pa.umd.cjs +1 -1
- package/dist/pixelium-vue.cjs +2 -2
- package/dist/pixelium-vue.css +2 -1
- package/dist/pixelium-vue.js +7402 -5852
- package/dist/pixelium-vue.umd.cjs +2 -2
- package/es/aside/index.js +46 -151
- package/es/auto-complete/draw.d.ts +1 -1
- package/es/auto-complete/draw.js +26 -51
- package/es/auto-complete/index.css +92 -32
- package/es/auto-complete/index.d.ts +12 -15
- package/es/auto-complete/index.js +338 -400
- package/es/auto-complete/type.d.ts +25 -13
- package/es/avatar/css.js +2 -0
- package/es/avatar/draw.d.ts +2 -0
- package/es/avatar/draw.js +11 -0
- package/es/avatar/index.css +49 -0
- package/es/avatar/index.d.ts +15 -0
- package/es/avatar/index.js +110 -0
- package/es/avatar/type.d.ts +34 -0
- package/es/button/draw.d.ts +4 -4
- package/es/button/draw.js +213 -297
- package/es/button/index.css +40 -30
- package/es/button/index.d.ts +0 -4
- package/es/button/index.js +230 -256
- package/es/button/type.d.ts +3 -3
- package/es/button-group/index.css +0 -3
- package/es/button-group/index.d.ts +1 -2
- package/es/button-group/index.js +59 -31
- package/es/button-group/type.d.ts +21 -4
- package/es/checkbox/css.js +2 -0
- package/es/checkbox/draw.d.ts +4 -0
- package/es/checkbox/draw.js +46 -0
- package/es/checkbox/index.css +85 -0
- package/es/checkbox/index.d.ts +31 -0
- package/es/checkbox/index.js +206 -0
- package/es/checkbox/type.d.ts +88 -0
- package/es/checkbox-group/css.js +2 -0
- package/es/checkbox-group/index.css +20 -0
- package/es/checkbox-group/index.d.ts +23 -0
- package/es/checkbox-group/index.js +84 -0
- package/es/checkbox-group/type.d.ts +78 -0
- package/es/col/index.d.ts +2 -2
- package/es/col/index.js +43 -58
- package/es/container/index.js +18 -31
- package/es/divider/index.js +39 -53
- package/es/empty/index.css +4 -4
- package/es/empty/index.js +16 -71
- package/es/entry.js +102 -0
- package/es/footer/index.js +31 -40
- package/es/form/css.js +1 -0
- package/es/form/index.d.ts +27 -0
- package/es/form/index.js +125 -0
- package/es/form/type.d.ts +238 -0
- package/es/form/use-form.d.ts +4 -0
- package/es/form/use-form.js +48 -0
- package/es/form-item/css.js +2 -0
- package/es/form-item/index.css +77 -0
- package/es/form-item/index.d.ts +37 -0
- package/es/form-item/index.js +318 -0
- package/es/form-item/type.d.ts +96 -0
- package/es/grid/index.js +56 -75
- package/es/grid-item/css.js +0 -1
- package/es/grid-item/index.d.ts +1 -1
- package/es/grid-item/index.js +85 -121
- package/es/header/index.js +31 -40
- package/es/icon/index.js +44 -55
- package/es/icons/css-hn.js +0 -1
- package/es/icons/css-pa.js +0 -1
- package/es/icons/icon-hn.js +10337 -15986
- package/es/icons/icon-pa.js +12573 -17447
- package/es/image/css.js +2 -0
- package/es/image/index.css +69 -0
- package/es/image/index.d.ts +35 -0
- package/es/image/index.js +199 -0
- package/es/image/type.d.ts +126 -0
- package/es/index.css +1 -515
- package/es/index.d.ts +22 -2
- package/es/index.js +143 -123
- package/es/input/draw.d.ts +1 -1
- package/es/input/draw.js +26 -51
- package/es/input/index.css +85 -33
- package/es/input/index.d.ts +9 -16
- package/es/input/index.js +319 -423
- package/es/input/type.d.ts +3 -3
- package/es/input-group/index.css +0 -1
- package/es/input-group/index.d.ts +2 -2
- package/es/input-group/index.js +66 -37
- package/es/input-group/type.d.ts +16 -4
- package/es/input-group-label/draw.d.ts +1 -1
- package/es/input-group-label/draw.js +26 -51
- package/es/input-group-label/index.css +33 -22
- package/es/input-group-label/index.d.ts +1 -4
- package/es/input-group-label/index.js +104 -127
- package/es/input-group-label/type.d.ts +3 -3
- package/es/input-number/draw.d.ts +1 -1
- package/es/input-number/draw.js +26 -51
- package/es/input-number/index.css +90 -35
- package/es/input-number/index.d.ts +9 -16
- package/es/input-number/index.js +428 -536
- package/es/input-number/type.d.ts +3 -3
- package/es/input-tag/draw.d.ts +1 -1
- package/es/input-tag/draw.js +26 -48
- package/es/input-tag/index.css +100 -33
- package/es/input-tag/index.d.ts +7 -13
- package/es/input-tag/index.js +442 -467
- package/es/input-tag/type.d.ts +24 -13
- package/es/link/index.js +75 -106
- package/es/main/index.js +11 -15
- package/es/mask/index.js +94 -115
- package/es/message/index.css +1 -1
- package/es/message/index.js +168 -346
- package/es/message-box/css.js +1 -1
- package/es/message-box/index.js +98 -114
- package/es/message-box/message-box-wrapped.js +33 -46
- package/es/message-box/message-box.js +79 -111
- package/es/option-list/index.css +13 -13
- package/es/option-list/index.d.ts +4 -31
- package/es/option-list/index.js +99 -167
- package/es/option-list/type.d.ts +5 -1
- package/es/pixelate/pixel.d.ts +5 -0
- package/es/pixelate/pixel.js +70 -0
- package/es/pixelate/pixelate.worker.d.ts +1 -0
- package/es/popover/index.d.ts +13 -99
- package/es/popover/index.js +75 -238
- package/es/popover/type.d.ts +7 -2
- package/es/popup/css.js +1 -0
- package/es/popup/index.d.ts +210 -0
- package/es/popup/index.js +203 -0
- package/es/popup/type.d.ts +105 -0
- package/es/popup-content/draw.d.ts +2 -2
- package/es/popup-content/draw.js +98 -143
- package/es/popup-content/index.css +11 -11
- package/es/popup-content/index.d.ts +1 -0
- package/es/popup-content/index.js +253 -1576
- package/es/popup-content/type.d.ts +1 -0
- package/es/popup-trigger/index.d.ts +8 -2
- package/es/popup-trigger/index.js +122 -95
- package/es/popup-trigger/type.d.ts +4 -1
- package/es/popup-wrapper/css.js +2 -0
- package/es/popup-wrapper/index.css +14 -0
- package/es/popup-wrapper/index.d.ts +18 -0
- package/es/popup-wrapper/index.js +67 -0
- package/es/popup-wrapper/type.d.ts +9 -0
- package/es/radio/css.js +1 -0
- package/es/radio/draw.d.ts +4 -0
- package/es/radio/draw.js +47 -0
- package/es/radio/index.d.ts +30 -0
- package/es/radio/index.js +190 -0
- package/es/radio/style.css +73 -0
- package/es/radio/type.d.ts +76 -0
- package/es/radio-group/css.js +2 -0
- package/es/radio-group/index.css +20 -0
- package/es/radio-group/index.d.ts +23 -0
- package/es/radio-group/index.js +77 -0
- package/es/radio-group/type.d.ts +77 -0
- package/es/row/index.js +56 -70
- package/es/select/draw.d.ts +1 -1
- package/es/select/draw.js +26 -51
- package/es/select/index.css +118 -36
- package/es/select/index.d.ts +14 -16
- package/es/select/index.js +625 -672
- package/es/select/type.d.ts +60 -25
- package/es/share/const/event-bus-key.js +1 -6
- package/es/share/const/index.d.ts +4 -0
- package/es/share/const/index.js +22 -24
- package/es/share/const/provide-key.d.ts +5 -0
- package/es/share/const/provide-key.js +6 -5
- package/es/share/const/style.d.ts +6 -0
- package/es/share/const/style.js +7 -0
- package/es/share/hook/use-cancelable-delay.d.ts +1 -0
- package/es/share/hook/use-cancelable-delay.js +42 -0
- package/es/share/hook/use-click-outside-listener.d.ts +1 -1
- package/es/share/hook/use-click-outside-listener.js +28 -41
- package/es/share/hook/use-composition.js +17 -15
- package/es/share/hook/use-controlled-mode.d.ts +3 -3
- package/es/share/hook/use-controlled-mode.js +20 -23
- package/es/share/hook/use-dark-mode.js +51 -65
- package/es/share/hook/use-index-of-children.d.ts +2 -1
- package/es/share/hook/use-index-of-children.js +47 -45
- package/es/share/hook/use-lazy-load.d.ts +10 -0
- package/es/share/hook/use-lazy-load.js +133 -0
- package/es/share/hook/use-props-detect.d.ts +2 -0
- package/es/share/hook/use-resize-observer.d.ts +1 -2
- package/es/share/hook/use-resize-observer.js +28 -20
- package/es/share/hook/use-screen-width.js +27 -36
- package/es/share/hook/use-smooth-transition.d.ts +2 -0
- package/es/share/hook/use-smooth-transition.js +65 -0
- package/es/share/hook/use-textarea-height.js +86 -92
- package/es/share/hook/use-theme-mode.js +41 -42
- package/es/share/hook/use-transition-end.d.ts +2 -0
- package/es/share/hook/use-transition-end.js +12 -0
- package/es/share/hook/use-watch-global-css-var.js +12 -16
- package/es/share/hook/use-window-resize-listener.d.ts +1 -0
- package/es/share/hook/use-window-resize-listener.js +15 -0
- package/es/share/hook/use-z-index.js +30 -27
- package/es/share/type/index.d.ts +18 -3
- package/es/share/util/color.d.ts +5 -3
- package/es/share/util/color.js +156 -149
- package/es/share/util/common.d.ts +7 -2
- package/es/share/util/common.js +127 -65
- package/es/share/util/console.d.ts +3 -3
- package/es/share/util/console.js +10 -7
- package/es/share/util/dom.d.ts +19 -0
- package/es/share/util/dom.js +88 -0
- package/es/share/util/env.d.ts +1 -0
- package/es/share/util/env.js +5 -4
- package/es/share/util/event-bus.js +3 -20
- package/es/share/util/lru-cache.js +29 -33
- package/es/share/util/pixel.d.ts +4 -0
- package/es/share/util/plot.d.ts +8 -3
- package/es/share/util/plot.js +457 -229
- package/es/share/util/reactivity.d.ts +8 -0
- package/es/share/util/reactivity.js +23 -0
- package/es/share/util/render.js +31 -41
- package/es/share/util/theme.d.ts +3 -0
- package/es/share/util/theme.js +77 -57
- package/es/slider/css.js +2 -0
- package/es/slider/draw.d.ts +25 -0
- package/es/slider/draw.js +113 -0
- package/es/slider/index.css +119 -0
- package/es/slider/index.d.ts +66 -0
- package/es/slider/index.js +503 -0
- package/es/slider/type.d.ts +162 -0
- package/es/slider/util.d.ts +37 -0
- package/es/slider/util.js +130 -0
- package/es/space/index.css +24 -29
- package/es/space/index.js +73 -97
- package/es/spin/index.css +18 -17
- package/es/spin/index.js +72 -102
- package/es/spin/type.d.ts +11 -5
- package/es/switch/css.js +2 -0
- package/es/switch/draw.d.ts +2 -0
- package/es/switch/draw.js +18 -0
- package/es/switch/index.css +121 -0
- package/es/switch/index.d.ts +42 -0
- package/es/switch/index.js +259 -0
- package/es/switch/type.d.ts +133 -0
- package/es/tag/draw.d.ts +2 -2
- package/es/tag/draw.js +80 -127
- package/es/tag/index.css +38 -22
- package/es/tag/index.d.ts +2 -2
- package/es/tag/index.js +121 -190
- package/es/tag/type.d.ts +3 -3
- package/es/text-outline/css.js +2 -0
- package/es/text-outline/index.css +4 -0
- package/es/text-outline/index.d.ts +17 -0
- package/es/text-outline/index.js +33 -0
- package/es/text-outline/type.d.ts +23 -0
- package/es/textarea/draw.js +9 -11
- package/es/textarea/index.css +37 -23
- package/es/textarea/index.d.ts +8 -14
- package/es/textarea/index.js +274 -262
- package/es/tooltip/index.d.ts +100 -4
- package/es/tooltip/index.js +70 -226
- package/es/tooltip/type.d.ts +7 -2
- package/es/vendor.js +504 -0
- package/es/virtual-list/css.js +2 -0
- package/es/virtual-list/index.css +25 -0
- package/es/virtual-list/index.d.ts +11 -0
- package/es/virtual-list/index.js +313 -0
- package/es/virtual-list/type.d.ts +26 -0
- package/package.json +10 -16
- package/es/grid-item/index.css +0 -0
- /package/es/message-box/{message-box.css → index.css} +0 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import './css.js'
|
|
2
|
+
import { B as y } from "../vendor.js";
|
|
3
|
+
import { n as inVitest } from "../share/util/env.js";
|
|
4
|
+
import { t as useResizeObserver } from "../share/hook/use-resize-observer.js";
|
|
5
|
+
import { Fragment, computed, createVNode, defineComponent, getCurrentInstance, nextTick, onMounted, ref, shallowRef, watch, withScopeId } from "vue";
|
|
6
|
+
var MIN_CHUNK_SIZE = 1e3;
|
|
7
|
+
var virtual_list_default = /* @__PURE__ */ defineComponent({
|
|
8
|
+
name: "VirtualList",
|
|
9
|
+
__name: "index",
|
|
10
|
+
props: {
|
|
11
|
+
list: { default: () => [] },
|
|
12
|
+
fixedHeight: {
|
|
13
|
+
type: Boolean,
|
|
14
|
+
default: false
|
|
15
|
+
},
|
|
16
|
+
estimatedHeight: { default: 28 },
|
|
17
|
+
buffer: { default: 10 }
|
|
18
|
+
},
|
|
19
|
+
setup(__props) {
|
|
20
|
+
const props = __props;
|
|
21
|
+
const containerRef = shallowRef(null);
|
|
22
|
+
const scrollAreaRef = shallowRef(null);
|
|
23
|
+
const contentRef = shallowRef(null);
|
|
24
|
+
const scrollTop = ref(0);
|
|
25
|
+
const totalHeight = ref(0);
|
|
26
|
+
const chunks = ref([]);
|
|
27
|
+
const blockPrefixHeights = ref([]);
|
|
28
|
+
const itemSizes = ref([]);
|
|
29
|
+
const maxListLength = ref(props.list.length);
|
|
30
|
+
const initChunks = () => {
|
|
31
|
+
const newChunks = [];
|
|
32
|
+
const totalCount = props.list.length;
|
|
33
|
+
const chunkSize = Math.max(MIN_CHUNK_SIZE, Math.ceil(Math.sqrt(totalCount)));
|
|
34
|
+
for (let i = 0; i < totalCount; i += chunkSize) {
|
|
35
|
+
const start = i;
|
|
36
|
+
const end = Math.min(i + chunkSize - 1, totalCount - 1);
|
|
37
|
+
const localPrefix = new Float64Array(end - start + 1);
|
|
38
|
+
let sum = 0;
|
|
39
|
+
for (let j = start; j <= end; j++) {
|
|
40
|
+
sum += props.estimatedHeight;
|
|
41
|
+
localPrefix[j - start] = sum;
|
|
42
|
+
}
|
|
43
|
+
newChunks.push({
|
|
44
|
+
startIndex: start,
|
|
45
|
+
endIndex: end,
|
|
46
|
+
localPrefix,
|
|
47
|
+
totalHeight: sum
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
chunks.value = newChunks;
|
|
51
|
+
updateBlockPrefixHeights();
|
|
52
|
+
};
|
|
53
|
+
const updateChunksWhenIncrease = (currentLength) => {
|
|
54
|
+
let resLength = currentLength - maxListLength.value;
|
|
55
|
+
maxListLength.value = currentLength;
|
|
56
|
+
const chunkSize = Math.max(MIN_CHUNK_SIZE, Math.ceil(Math.sqrt(currentLength)));
|
|
57
|
+
const chunk = chunks.value[chunks.value.length - 1];
|
|
58
|
+
const currentLen = chunk.endIndex - chunk.startIndex + 1;
|
|
59
|
+
if (currentLen < chunkSize) {
|
|
60
|
+
let sum = chunk.totalHeight;
|
|
61
|
+
const nextLen = currentLen + resLength >= chunkSize ? chunkSize : currentLen + resLength;
|
|
62
|
+
chunk.endIndex = chunk.startIndex + nextLen - 1;
|
|
63
|
+
const preLocalPrefix = chunk.localPrefix;
|
|
64
|
+
chunk.localPrefix = new Float64Array(chunkSize);
|
|
65
|
+
chunk.localPrefix.set(preLocalPrefix, 0);
|
|
66
|
+
for (let i = preLocalPrefix.length; i < chunk.localPrefix.length; i++) {
|
|
67
|
+
sum += props.estimatedHeight;
|
|
68
|
+
chunk.localPrefix[i] = sum;
|
|
69
|
+
}
|
|
70
|
+
chunk.totalHeight = sum;
|
|
71
|
+
resLength = Math.max(0, resLength - chunkSize + currentLen);
|
|
72
|
+
}
|
|
73
|
+
while (resLength > 0) {
|
|
74
|
+
const start = Math.min(chunks.value[chunks.value.length - 1].endIndex + 1, currentLength - 1);
|
|
75
|
+
const end = Math.min(start + chunkSize - 1, currentLength - 1);
|
|
76
|
+
const localPrefix = new Float64Array(end - start + 1);
|
|
77
|
+
let sum = 0;
|
|
78
|
+
for (let j = start; j <= end; j++) {
|
|
79
|
+
sum += props.estimatedHeight;
|
|
80
|
+
localPrefix[j - start] = sum;
|
|
81
|
+
}
|
|
82
|
+
chunks.value.push({
|
|
83
|
+
startIndex: start,
|
|
84
|
+
endIndex: end,
|
|
85
|
+
localPrefix,
|
|
86
|
+
totalHeight: sum
|
|
87
|
+
});
|
|
88
|
+
resLength -= end - start + 1;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const updateChunks = (currentLength) => {
|
|
92
|
+
if (currentLength > maxListLength.value) updateChunksWhenIncrease(currentLength);
|
|
93
|
+
updateBlockPrefixHeights();
|
|
94
|
+
};
|
|
95
|
+
const updateBlockPrefixHeights = () => {
|
|
96
|
+
const prefix = [];
|
|
97
|
+
let sum = 0;
|
|
98
|
+
let elementCount = 0;
|
|
99
|
+
const maxLength = props.list.length;
|
|
100
|
+
for (const chunk of chunks.value) {
|
|
101
|
+
const chunkSize = chunk.endIndex - chunk.startIndex + 1;
|
|
102
|
+
if (maxLength > 0 && elementCount >= maxLength) break;
|
|
103
|
+
if (maxLength > 0 && elementCount + chunkSize > maxLength) {
|
|
104
|
+
const remaining = maxLength - elementCount;
|
|
105
|
+
if (chunk.localPrefix && remaining > 0 && remaining <= chunk.localPrefix.length) {
|
|
106
|
+
sum += chunk.localPrefix[remaining - 1];
|
|
107
|
+
prefix.push(sum);
|
|
108
|
+
elementCount = maxLength;
|
|
109
|
+
break;
|
|
110
|
+
} else break;
|
|
111
|
+
}
|
|
112
|
+
sum += chunk.totalHeight;
|
|
113
|
+
prefix.push(sum);
|
|
114
|
+
elementCount += chunkSize;
|
|
115
|
+
}
|
|
116
|
+
blockPrefixHeights.value = prefix;
|
|
117
|
+
totalHeight.value = prefix.at(-1) || 0;
|
|
118
|
+
};
|
|
119
|
+
const findChunkByIndex = (index) => {
|
|
120
|
+
if (chunks.value.length === 0) return null;
|
|
121
|
+
let left = 0;
|
|
122
|
+
let right = chunks.value.length - 1;
|
|
123
|
+
while (left <= right) {
|
|
124
|
+
const mid = Math.floor((left + right) / 2);
|
|
125
|
+
const chunk = chunks.value[mid];
|
|
126
|
+
if (index >= chunk.startIndex && index <= chunk.endIndex) return chunk;
|
|
127
|
+
else if (index < chunk.startIndex) right = mid - 1;
|
|
128
|
+
else left = mid + 1;
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
};
|
|
132
|
+
const getItemHeight = (index) => {
|
|
133
|
+
if (props.fixedHeight) return props.estimatedHeight;
|
|
134
|
+
return itemSizes.value[index] ?? props.estimatedHeight;
|
|
135
|
+
};
|
|
136
|
+
const getAccumulatedHeight = (index) => {
|
|
137
|
+
if (index < 0) return 0;
|
|
138
|
+
const chunk = findChunkByIndex(index);
|
|
139
|
+
if (!chunk) return 0;
|
|
140
|
+
const prevChunksHeight = chunk.startIndex === 0 ? 0 : blockPrefixHeights.value[chunks.value.indexOf(chunk) - 1] || 0;
|
|
141
|
+
const withinChunkIndex = index - chunk.startIndex;
|
|
142
|
+
return prevChunksHeight + chunk.localPrefix[withinChunkIndex];
|
|
143
|
+
};
|
|
144
|
+
const findNearestItemIndex = (scrollPosition) => {
|
|
145
|
+
if (props.fixedHeight) return Math.floor(scrollPosition / props.estimatedHeight);
|
|
146
|
+
if (chunks.value.length === 0) return 0;
|
|
147
|
+
let chunkIndex = blockPrefixHeights.value.length - 1;
|
|
148
|
+
let left = 0;
|
|
149
|
+
let right = blockPrefixHeights.value.length - 1;
|
|
150
|
+
while (left <= right) {
|
|
151
|
+
const mid = Math.floor((left + right) / 2);
|
|
152
|
+
if (blockPrefixHeights.value[mid] > scrollPosition) {
|
|
153
|
+
chunkIndex = mid;
|
|
154
|
+
right = mid - 1;
|
|
155
|
+
} else left = mid + 1;
|
|
156
|
+
}
|
|
157
|
+
const targetChunk = chunks.value[chunkIndex];
|
|
158
|
+
const scrollInChunk = scrollPosition - (chunkIndex === 0 ? 0 : blockPrefixHeights.value[chunkIndex - 1] || 0);
|
|
159
|
+
left = 0;
|
|
160
|
+
right = targetChunk.localPrefix.length - 1;
|
|
161
|
+
let resInChunk = 0;
|
|
162
|
+
while (left <= right) {
|
|
163
|
+
const mid = Math.floor((left + right) / 2);
|
|
164
|
+
if (targetChunk.localPrefix[mid] > scrollInChunk) {
|
|
165
|
+
resInChunk = mid;
|
|
166
|
+
right = mid - 1;
|
|
167
|
+
} else left = mid + 1;
|
|
168
|
+
}
|
|
169
|
+
return targetChunk.startIndex + resInChunk;
|
|
170
|
+
};
|
|
171
|
+
const calcVisibleRange = () => {
|
|
172
|
+
if (!containerRef.value) return {
|
|
173
|
+
start: 0,
|
|
174
|
+
end: 0
|
|
175
|
+
};
|
|
176
|
+
const containerHeight = containerRef.value.clientHeight;
|
|
177
|
+
const start = findNearestItemIndex(scrollTop.value);
|
|
178
|
+
let end = start;
|
|
179
|
+
let accumulatedHeight = 0;
|
|
180
|
+
let endPoint = props.list.length;
|
|
181
|
+
let overFlag = false;
|
|
182
|
+
while (end < endPoint) {
|
|
183
|
+
const itemHeight = getItemHeight(end);
|
|
184
|
+
accumulatedHeight += itemHeight;
|
|
185
|
+
if (accumulatedHeight > containerHeight && !overFlag) {
|
|
186
|
+
endPoint = end + props.buffer + 1;
|
|
187
|
+
overFlag = true;
|
|
188
|
+
}
|
|
189
|
+
end++;
|
|
190
|
+
}
|
|
191
|
+
end = Math.min(end, props.list.length);
|
|
192
|
+
return {
|
|
193
|
+
start: Math.max(0, start - props.buffer),
|
|
194
|
+
end
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
const visibleRange = ref(calcVisibleRange());
|
|
198
|
+
watch([
|
|
199
|
+
scrollTop,
|
|
200
|
+
() => props.buffer,
|
|
201
|
+
() => props.list.length,
|
|
202
|
+
() => props.fixedHeight,
|
|
203
|
+
blockPrefixHeights
|
|
204
|
+
], () => {
|
|
205
|
+
visibleRange.value = calcVisibleRange();
|
|
206
|
+
});
|
|
207
|
+
const contentOffset = computed(() => {
|
|
208
|
+
const { start } = visibleRange.value;
|
|
209
|
+
return getAccumulatedHeight(start - 1);
|
|
210
|
+
});
|
|
211
|
+
const updateItemSizes = () => {
|
|
212
|
+
if (!contentRef.value) return;
|
|
213
|
+
if (contentRef.value.offsetHeight === 0 && !inVitest()) return;
|
|
214
|
+
if (props.fixedHeight) return;
|
|
215
|
+
const items = contentRef.value.children;
|
|
216
|
+
const { start } = visibleRange.value;
|
|
217
|
+
let hasChange = false;
|
|
218
|
+
for (let i = 0; i < items.length; i++) {
|
|
219
|
+
const itemIndex = start + i;
|
|
220
|
+
if (itemIndex >= props.list.length) break;
|
|
221
|
+
const itemHeight = inVitest() ? 40 : items[i].offsetHeight;
|
|
222
|
+
if (itemSizes.value[itemIndex] !== itemHeight) {
|
|
223
|
+
itemSizes.value[itemIndex] = itemHeight;
|
|
224
|
+
hasChange = true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (hasChange) {
|
|
228
|
+
const { start: visibleStart, end: visibleEnd } = visibleRange.value;
|
|
229
|
+
const startChunk = findChunkByIndex(visibleStart);
|
|
230
|
+
const endChunk = findChunkByIndex(visibleEnd);
|
|
231
|
+
if (!startChunk || !endChunk) return;
|
|
232
|
+
const startChunkIdx = chunks.value.indexOf(startChunk);
|
|
233
|
+
const endChunkIdx = chunks.value.indexOf(endChunk);
|
|
234
|
+
for (let cIdx = startChunkIdx; cIdx <= endChunkIdx; cIdx++) {
|
|
235
|
+
const chunk = chunks.value[cIdx];
|
|
236
|
+
let sum = 0;
|
|
237
|
+
for (let i = chunk.startIndex; i <= chunk.endIndex; i++) {
|
|
238
|
+
sum += getItemHeight(i);
|
|
239
|
+
chunk.localPrefix[i - chunk.startIndex] = sum;
|
|
240
|
+
}
|
|
241
|
+
chunk.totalHeight = sum;
|
|
242
|
+
}
|
|
243
|
+
updateBlockPrefixHeights();
|
|
244
|
+
visibleRange.value = calcVisibleRange();
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const handleScroll = (e) => {
|
|
248
|
+
scrollTop.value = e.target.scrollTop;
|
|
249
|
+
};
|
|
250
|
+
onMounted(() => {
|
|
251
|
+
initChunks();
|
|
252
|
+
nextTick(() => {
|
|
253
|
+
updateItemSizes();
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
const watchFn = () => {
|
|
257
|
+
updateChunks(props.list.length);
|
|
258
|
+
nextTick(() => {
|
|
259
|
+
updateItemSizes();
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
watch(() => props.list.length, watchFn);
|
|
263
|
+
watch(visibleRange, () => {
|
|
264
|
+
nextTick(() => {
|
|
265
|
+
updateItemSizes();
|
|
266
|
+
});
|
|
267
|
+
}, { deep: true });
|
|
268
|
+
useResizeObserver(containerRef, () => {
|
|
269
|
+
nextTick(() => {
|
|
270
|
+
visibleRange.value = calcVisibleRange();
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
const instance = getCurrentInstance();
|
|
274
|
+
return () => {
|
|
275
|
+
const { start, end } = visibleRange.value;
|
|
276
|
+
const visibleItems = props.list.slice(start, end + 1);
|
|
277
|
+
const scopeId = instance === null || instance === void 0 ? void 0 : instance.vnode.scopeId;
|
|
278
|
+
const placeholderHeight = totalHeight.value || props.list.length * props.estimatedHeight;
|
|
279
|
+
const render$1 = () => createVNode("div", {
|
|
280
|
+
"ref": containerRef,
|
|
281
|
+
"class": "px-virtual-list"
|
|
282
|
+
}, [createVNode("div", {
|
|
283
|
+
"ref": scrollAreaRef,
|
|
284
|
+
"class": "px-virtual-list-scroll-area",
|
|
285
|
+
"onScroll": handleScroll
|
|
286
|
+
}, [createVNode("div", {
|
|
287
|
+
"class": { "px-virtual-list-content": props.fixedHeight },
|
|
288
|
+
"style": { maxHeight: props.fixedHeight ? `${placeholderHeight}px` : void 0 }
|
|
289
|
+
}, [createVNode("div", {
|
|
290
|
+
"class": "px-virtual-list-placeholder",
|
|
291
|
+
"style": { height: `${placeholderHeight}px` }
|
|
292
|
+
}, null), createVNode("div", {
|
|
293
|
+
"ref": contentRef,
|
|
294
|
+
"class": "px-virtual-list-item",
|
|
295
|
+
"style": { transform: `translateY(${contentOffset.value}px)` }
|
|
296
|
+
}, [visibleItems.map((item, index) => {
|
|
297
|
+
const itemIndex = start + index;
|
|
298
|
+
const key = item.key ?? itemIndex;
|
|
299
|
+
const renderResult = item.render;
|
|
300
|
+
let content;
|
|
301
|
+
if (y(renderResult)) content = createVNode("div", null, [renderResult]);
|
|
302
|
+
else {
|
|
303
|
+
const renderReturn = renderResult();
|
|
304
|
+
if (y(renderReturn)) content = createVNode("div", null, [renderReturn]);
|
|
305
|
+
else content = renderReturn;
|
|
306
|
+
}
|
|
307
|
+
return createVNode(Fragment, { "key": key }, [content]);
|
|
308
|
+
})])])])]);
|
|
309
|
+
return scopeId ? withScopeId(scopeId)(render$1)() : render$1();
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
export { virtual_list_default as t };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ValidContent } from '../share/type';
|
|
2
|
+
export type VirtualListProps = {
|
|
3
|
+
/**
|
|
4
|
+
* @property {{ render: ValidContent; key?: string | number | symbol }[]} [list]
|
|
5
|
+
* @version 0.0.3
|
|
6
|
+
*/
|
|
7
|
+
list?: {
|
|
8
|
+
render: ValidContent;
|
|
9
|
+
key?: string | number | symbol;
|
|
10
|
+
}[];
|
|
11
|
+
/**
|
|
12
|
+
* @property {boolean} [fixedHeight=false]
|
|
13
|
+
* @version 0.0.3
|
|
14
|
+
*/
|
|
15
|
+
fixedHeight?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* @property {number} [estimatedHeight=28]
|
|
18
|
+
* @version 0.0.3
|
|
19
|
+
*/
|
|
20
|
+
estimatedHeight?: number;
|
|
21
|
+
/**
|
|
22
|
+
* @property {number} [buffer=10]
|
|
23
|
+
* @version 0.0.3
|
|
24
|
+
*/
|
|
25
|
+
buffer?: number;
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixelium/web-vue",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-beta",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/pixelium-vue.js",
|
|
6
6
|
"exports": {
|
|
@@ -42,36 +42,30 @@
|
|
|
42
42
|
"lint": "oxlint lib",
|
|
43
43
|
"lint:fix": "oxlint ./ --fix && prettier ./ --write",
|
|
44
44
|
"preview": "vite preview",
|
|
45
|
-
"release": "npm run build && npm publish --access public",
|
|
46
|
-
"release:dry-run": "npm run build && npm publish --dry-run"
|
|
45
|
+
"release": "npm run test && npm run build && npm publish --access public",
|
|
46
|
+
"release:dry-run": "npm run build && npm publish --dry-run",
|
|
47
|
+
"test": "vitest run --config ./script/vite.config.vue.ts --coverage",
|
|
48
|
+
"test:watch": "vitest --config ./script/vite.config.vue.ts --coverage"
|
|
47
49
|
},
|
|
48
50
|
"peerDependencies": {
|
|
49
51
|
"vue": "^3.5.17"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
54
|
"@hackernoon/pixel-icon-library": "^1.0.6",
|
|
53
|
-
"@
|
|
54
|
-
"@vitejs/plugin-vue": "^6.0.0",
|
|
55
|
+
"@vitejs/plugin-vue": "^6.0.1",
|
|
55
56
|
"@vitejs/plugin-vue-jsx": "^5.1.1",
|
|
56
|
-
"dts-bundle-generator": "^9.5.1",
|
|
57
|
-
"esbuild": "^0.25.9",
|
|
58
|
-
"execa": "^9.6.0",
|
|
59
57
|
"less": "^4.4.0",
|
|
60
|
-
"oxlint": "^1.12.0",
|
|
61
58
|
"pixelarticons": "^1.8.1",
|
|
62
|
-
"prettier": "^3.6.2",
|
|
63
|
-
"rimraf": "^6.0.1",
|
|
64
59
|
"svgo": "^4.0.0",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"vue-macros": "3.0.0-beta.23",
|
|
68
|
-
"vue-tsc": "3.0.6"
|
|
60
|
+
"vite": "npm:rolldown-vite@latest",
|
|
61
|
+
"vue-macros": "3.0.0-beta.23"
|
|
69
62
|
},
|
|
70
63
|
"dependencies": {
|
|
71
64
|
"@floating-ui/dom": "^1.7.4",
|
|
72
65
|
"mitt": "^3.0.1",
|
|
66
|
+
"modern-normalize": "^3.0.1",
|
|
73
67
|
"nanoid": "^5.1.5",
|
|
74
|
-
"parsnip-kit": "^0.0.
|
|
68
|
+
"parsnip-kit": "^0.0.6"
|
|
75
69
|
},
|
|
76
70
|
"repository": {
|
|
77
71
|
"type": "git",
|
package/es/grid-item/index.css
DELETED
|
File without changes
|
|
File without changes
|