@epoch32/visage 1.1.3 → 1.1.4
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/dist/api/index.js +55 -4085
- package/dist/charts/index.js +48 -2806
- package/dist/devtools/index.js +18 -4771
- package/dist/dom/index.js +32 -1639
- package/dist/form/index.js +13 -1498
- package/dist/index-061jf06a.js +848 -0
- package/dist/index-0madxn60.js +442 -0
- package/dist/index-1xtrtz1t.js +256 -0
- package/dist/index-2zz0g2n2.js +212 -0
- package/dist/index-5s255b3w.js +303 -0
- package/dist/index-6kfe1nr4.js +1179 -0
- package/dist/index-8czhpea8.js +338 -0
- package/dist/index-8x8xz80v.js +727 -0
- package/dist/index-921pn75b.js +0 -0
- package/dist/index-965ryh36.js +537 -0
- package/dist/index-9fvarkrx.js +98 -0
- package/dist/index-a4xns6cc.js +219 -0
- package/dist/index-b5wc752a.js +1696 -0
- package/dist/index-df5e614s.js +334 -0
- package/dist/index-dyvgtp43.js +1094 -0
- package/dist/index-grhdtcb5.js +234 -0
- package/dist/index-h6tjqk6e.js +158 -0
- package/dist/index-js199er4.js +101 -0
- package/dist/index-x2rs3vab.js +124 -0
- package/dist/index-y9bq7h9g.js +1162 -0
- package/dist/index-zr6cvset.js +2092 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +458 -11920
- package/dist/jsx-runtime/index.js +13 -1719
- package/dist/query/index.js +47 -2505
- package/dist/router/index.js +25 -1945
- package/dist/rpc/index.js +39 -3567
- package/dist/server/index.js +11 -1256
- package/dist/signals/index.js +52 -1160
- package/dist/style/index.js +77 -2429
- package/dist/template/index.js +7 -1232
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +150 -4249
- package/dist/ui/tabs.d.ts +23 -1
- package/dist/virtual/index.js +12 -2044
- package/dist/vite/index.js +5 -744
- package/package.json +2 -2
- package/src/dom/render.ts +20 -7
- package/src/index.ts +2 -0
- package/src/signals/computed.ts +19 -12
- package/src/signals/effect.ts +7 -7
- package/src/signals/signal.ts +16 -12
- package/src/signals/system.ts +50 -21
- package/src/ui/index.ts +2 -0
- package/src/ui/tabs.tsx +211 -10
- package/src/ui/utils.ts +1 -3
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed2,
|
|
3
|
+
onCleanup2,
|
|
4
|
+
effect2,
|
|
5
|
+
signal2
|
|
6
|
+
} from "./index-6kfe1nr4.js";
|
|
7
|
+
import {
|
|
8
|
+
For2
|
|
9
|
+
} from "./index-5s255b3w.js";
|
|
10
|
+
import {
|
|
11
|
+
jsx2
|
|
12
|
+
} from "./index-9fvarkrx.js";
|
|
13
|
+
|
|
14
|
+
// src/virtual/virtualizer.ts
|
|
15
|
+
function createVirtualizer2(options) {
|
|
16
|
+
const overscan = options.overscan ?? 3;
|
|
17
|
+
const isHorizontal = Boolean(options.horizontal);
|
|
18
|
+
const getCount = () => typeof options.count === "function" ? options.count() : options.count;
|
|
19
|
+
const getItemHeight = typeof options.itemHeight === "function" ? options.itemHeight : () => options.itemHeight;
|
|
20
|
+
const scrollOffset = signal2(0);
|
|
21
|
+
const containerSize = signal2(options.initialSize ?? 400);
|
|
22
|
+
const dynamicSizeCache = new Map;
|
|
23
|
+
const getItemSize = (index) => {
|
|
24
|
+
const cached = dynamicSizeCache.get(index);
|
|
25
|
+
if (cached !== undefined)
|
|
26
|
+
return cached;
|
|
27
|
+
return getItemHeight(index);
|
|
28
|
+
};
|
|
29
|
+
const totalSize = computed2(() => {
|
|
30
|
+
const count = getCount();
|
|
31
|
+
if (typeof options.itemHeight === "number" && dynamicSizeCache.size === 0) {
|
|
32
|
+
return count * options.itemHeight;
|
|
33
|
+
}
|
|
34
|
+
let total = 0;
|
|
35
|
+
for (let i = 0;i < count; i++) {
|
|
36
|
+
total += getItemSize(i);
|
|
37
|
+
}
|
|
38
|
+
return total;
|
|
39
|
+
});
|
|
40
|
+
const getOffsetForIndex = (targetIndex) => {
|
|
41
|
+
if (typeof options.itemHeight === "number" && dynamicSizeCache.size === 0) {
|
|
42
|
+
return targetIndex * options.itemHeight;
|
|
43
|
+
}
|
|
44
|
+
let offset = 0;
|
|
45
|
+
for (let i = 0;i < targetIndex; i++) {
|
|
46
|
+
offset += getItemSize(i);
|
|
47
|
+
}
|
|
48
|
+
return offset;
|
|
49
|
+
};
|
|
50
|
+
const findIndexAtOffset = (offset) => {
|
|
51
|
+
const count = getCount();
|
|
52
|
+
if (count === 0)
|
|
53
|
+
return 0;
|
|
54
|
+
if (typeof options.itemHeight === "number" && dynamicSizeCache.size === 0) {
|
|
55
|
+
const idx = Math.floor(offset / options.itemHeight);
|
|
56
|
+
return Math.max(0, Math.min(count - 1, idx));
|
|
57
|
+
}
|
|
58
|
+
let low = 0;
|
|
59
|
+
let high = count - 1;
|
|
60
|
+
while (low <= high) {
|
|
61
|
+
const mid = low + high >> 1;
|
|
62
|
+
const midStart = getOffsetForIndex(mid);
|
|
63
|
+
const midEnd = midStart + getItemSize(mid);
|
|
64
|
+
if (offset < midStart) {
|
|
65
|
+
high = mid - 1;
|
|
66
|
+
} else if (offset >= midEnd) {
|
|
67
|
+
low = mid + 1;
|
|
68
|
+
} else {
|
|
69
|
+
return mid;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return Math.max(0, Math.min(count - 1, low));
|
|
73
|
+
};
|
|
74
|
+
const startIndex = computed2(() => {
|
|
75
|
+
const offset = scrollOffset();
|
|
76
|
+
const rawStart = findIndexAtOffset(offset);
|
|
77
|
+
return Math.max(0, rawStart - overscan);
|
|
78
|
+
});
|
|
79
|
+
const endIndex = computed2(() => {
|
|
80
|
+
const count = getCount();
|
|
81
|
+
if (count === 0)
|
|
82
|
+
return 0;
|
|
83
|
+
const endOffset = scrollOffset() + (containerSize() || 500);
|
|
84
|
+
const rawEnd = findIndexAtOffset(endOffset);
|
|
85
|
+
return Math.min(count - 1, rawEnd + overscan);
|
|
86
|
+
});
|
|
87
|
+
const itemCache = new Map;
|
|
88
|
+
const virtualItems = computed2(() => {
|
|
89
|
+
const count = getCount();
|
|
90
|
+
if (count === 0)
|
|
91
|
+
return [];
|
|
92
|
+
const start = startIndex();
|
|
93
|
+
const end = endIndex();
|
|
94
|
+
const items = [];
|
|
95
|
+
let currentStart = getOffsetForIndex(start);
|
|
96
|
+
for (let i = start;i <= end; i++) {
|
|
97
|
+
const size = getItemSize(i);
|
|
98
|
+
let item = itemCache.get(i);
|
|
99
|
+
if (!item || item.start !== currentStart || item.size !== size) {
|
|
100
|
+
item = {
|
|
101
|
+
index: i,
|
|
102
|
+
start: currentStart,
|
|
103
|
+
size,
|
|
104
|
+
end: currentStart + size,
|
|
105
|
+
key: i
|
|
106
|
+
};
|
|
107
|
+
itemCache.set(i, item);
|
|
108
|
+
}
|
|
109
|
+
items.push(item);
|
|
110
|
+
currentStart += size;
|
|
111
|
+
}
|
|
112
|
+
return items;
|
|
113
|
+
});
|
|
114
|
+
effect2(() => {
|
|
115
|
+
const el = options.getScrollElement();
|
|
116
|
+
if (!el || typeof el.addEventListener !== "function")
|
|
117
|
+
return;
|
|
118
|
+
const handleScroll = () => {
|
|
119
|
+
const offset = isHorizontal ? el.scrollLeft : el.scrollTop;
|
|
120
|
+
scrollOffset.set(offset);
|
|
121
|
+
};
|
|
122
|
+
const handleResize = () => {
|
|
123
|
+
const size = isHorizontal ? el.clientWidth : el.clientHeight;
|
|
124
|
+
if (size > 0) {
|
|
125
|
+
containerSize.set(size);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
handleResize();
|
|
129
|
+
handleScroll();
|
|
130
|
+
el.addEventListener("scroll", handleScroll, { passive: true });
|
|
131
|
+
let resizeObserver;
|
|
132
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
133
|
+
resizeObserver = new ResizeObserver(() => {
|
|
134
|
+
handleResize();
|
|
135
|
+
});
|
|
136
|
+
resizeObserver.observe(el);
|
|
137
|
+
}
|
|
138
|
+
onCleanup2(() => {
|
|
139
|
+
el.removeEventListener("scroll", handleScroll);
|
|
140
|
+
if (resizeObserver) {
|
|
141
|
+
resizeObserver.disconnect();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
const scrollToIndex = (index, scrollOpts) => {
|
|
146
|
+
const el = options.getScrollElement();
|
|
147
|
+
if (!el)
|
|
148
|
+
return;
|
|
149
|
+
const align = scrollOpts?.align ?? "auto";
|
|
150
|
+
const itemStart = getOffsetForIndex(index);
|
|
151
|
+
const itemSize = getItemSize(index);
|
|
152
|
+
const itemEnd = itemStart + itemSize;
|
|
153
|
+
const currentScroll = scrollOffset();
|
|
154
|
+
const cSize = containerSize();
|
|
155
|
+
let targetOffset = itemStart;
|
|
156
|
+
if (align === "start") {
|
|
157
|
+
targetOffset = itemStart;
|
|
158
|
+
} else if (align === "end") {
|
|
159
|
+
targetOffset = itemEnd - cSize;
|
|
160
|
+
} else if (align === "center") {
|
|
161
|
+
targetOffset = itemStart - (cSize - itemSize) / 2;
|
|
162
|
+
} else {
|
|
163
|
+
if (itemStart < currentScroll) {
|
|
164
|
+
targetOffset = itemStart;
|
|
165
|
+
} else if (itemEnd > currentScroll + cSize) {
|
|
166
|
+
targetOffset = itemEnd - cSize;
|
|
167
|
+
} else {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
targetOffset = Math.max(0, targetOffset);
|
|
172
|
+
if (isHorizontal) {
|
|
173
|
+
el.scrollLeft = targetOffset;
|
|
174
|
+
} else {
|
|
175
|
+
el.scrollTop = targetOffset;
|
|
176
|
+
}
|
|
177
|
+
scrollOffset.set(targetOffset);
|
|
178
|
+
};
|
|
179
|
+
const scrollToOffset = (offset) => {
|
|
180
|
+
const el = options.getScrollElement();
|
|
181
|
+
if (el) {
|
|
182
|
+
if (isHorizontal) {
|
|
183
|
+
el.scrollLeft = offset;
|
|
184
|
+
} else {
|
|
185
|
+
el.scrollTop = offset;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
scrollOffset.set(offset);
|
|
189
|
+
};
|
|
190
|
+
const measureElement = (element, index) => {
|
|
191
|
+
if (!element)
|
|
192
|
+
return;
|
|
193
|
+
const measuredSize = isHorizontal ? element.getBoundingClientRect().width : element.getBoundingClientRect().height;
|
|
194
|
+
if (measuredSize > 0 && dynamicSizeCache.get(index) !== measuredSize) {
|
|
195
|
+
dynamicSizeCache.set(index, measuredSize);
|
|
196
|
+
scrollOffset.update((o) => o);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
virtualItems,
|
|
201
|
+
totalSize,
|
|
202
|
+
scrollOffset,
|
|
203
|
+
containerSize,
|
|
204
|
+
startIndex,
|
|
205
|
+
endIndex,
|
|
206
|
+
scrollToIndex,
|
|
207
|
+
scrollToOffset,
|
|
208
|
+
measureElement
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/virtual/virtual-list.tsx
|
|
213
|
+
function VirtualList2(props) {
|
|
214
|
+
const scrollElement = signal2(null);
|
|
215
|
+
const getItems = () => typeof props.each === "function" ? props.each() : props.each;
|
|
216
|
+
const count = computed2(() => getItems().length);
|
|
217
|
+
const parsedHeight = typeof props.height === "number" ? props.height : Number.parseInt(String(props.height || 400), 10) || 400;
|
|
218
|
+
const virtualizer = createVirtualizer2({
|
|
219
|
+
count,
|
|
220
|
+
itemHeight: props.itemHeight,
|
|
221
|
+
overscan: props.overscan ?? 3,
|
|
222
|
+
initialSize: parsedHeight,
|
|
223
|
+
getScrollElement: () => scrollElement()
|
|
224
|
+
});
|
|
225
|
+
const containerHeight = typeof props.height === "number" ? `${props.height}px` : props.height ?? "400px";
|
|
226
|
+
const containerWidth = typeof props.width === "number" ? `${props.width}px` : props.width ?? "100%";
|
|
227
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
228
|
+
ref: (el) => {
|
|
229
|
+
scrollElement.set(el);
|
|
230
|
+
},
|
|
231
|
+
class: props.class,
|
|
232
|
+
style: () => {
|
|
233
|
+
const customStyle = typeof props.style === "function" ? props.style() : props.style || {};
|
|
234
|
+
return {
|
|
235
|
+
overflowY: "auto",
|
|
236
|
+
overflowX: "hidden",
|
|
237
|
+
position: "relative",
|
|
238
|
+
height: containerHeight,
|
|
239
|
+
width: containerWidth,
|
|
240
|
+
WebkitOverflowScrolling: "touch",
|
|
241
|
+
...customStyle
|
|
242
|
+
};
|
|
243
|
+
},
|
|
244
|
+
children: /* @__PURE__ */ jsx2("div", {
|
|
245
|
+
style: () => ({
|
|
246
|
+
height: `${virtualizer.totalSize()}px`,
|
|
247
|
+
width: "100%",
|
|
248
|
+
position: "relative",
|
|
249
|
+
pointerEvents: "none"
|
|
250
|
+
}),
|
|
251
|
+
children: /* @__PURE__ */ jsx2(For2, {
|
|
252
|
+
each: () => virtualizer.virtualItems(),
|
|
253
|
+
children: (vItem) => {
|
|
254
|
+
const itemData = computed2(() => getItems()[vItem.index]);
|
|
255
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
256
|
+
style: () => ({
|
|
257
|
+
position: "absolute",
|
|
258
|
+
top: 0,
|
|
259
|
+
left: 0,
|
|
260
|
+
width: "100%",
|
|
261
|
+
height: `${vItem.size}px`,
|
|
262
|
+
transform: `translateY(${vItem.start}px)`,
|
|
263
|
+
pointerEvents: "auto",
|
|
264
|
+
willChange: "transform"
|
|
265
|
+
}),
|
|
266
|
+
children: props.children(itemData(), () => vItem.index)
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
})
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function VirtualGrid2(props) {
|
|
274
|
+
const scrollElement = signal2(null);
|
|
275
|
+
const getData = () => typeof props.data === "function" ? props.data() : props.data;
|
|
276
|
+
const rowCount = computed2(() => getData().length);
|
|
277
|
+
const colCount = computed2(() => {
|
|
278
|
+
const d = getData();
|
|
279
|
+
return d[0] ? d[0].length : 0;
|
|
280
|
+
});
|
|
281
|
+
const rowVirtualizer = createVirtualizer2({
|
|
282
|
+
count: rowCount,
|
|
283
|
+
itemHeight: props.rowHeight,
|
|
284
|
+
overscan: props.overscan ?? 3,
|
|
285
|
+
getScrollElement: () => scrollElement()
|
|
286
|
+
});
|
|
287
|
+
const colVirtualizer = createVirtualizer2({
|
|
288
|
+
count: colCount,
|
|
289
|
+
itemHeight: props.columnWidth,
|
|
290
|
+
overscan: props.overscan ?? 3,
|
|
291
|
+
horizontal: true,
|
|
292
|
+
getScrollElement: () => scrollElement()
|
|
293
|
+
});
|
|
294
|
+
const containerHeight = typeof props.height === "number" ? `${props.height}px` : props.height ?? "400px";
|
|
295
|
+
const containerWidth = typeof props.width === "number" ? `${props.width}px` : props.width ?? "100%";
|
|
296
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
297
|
+
ref: (el) => {
|
|
298
|
+
scrollElement.set(el);
|
|
299
|
+
},
|
|
300
|
+
style: {
|
|
301
|
+
overflow: "auto",
|
|
302
|
+
position: "relative",
|
|
303
|
+
height: containerHeight,
|
|
304
|
+
width: containerWidth,
|
|
305
|
+
WebkitOverflowScrolling: "touch"
|
|
306
|
+
},
|
|
307
|
+
children: /* @__PURE__ */ jsx2("div", {
|
|
308
|
+
style: () => ({
|
|
309
|
+
height: `${rowVirtualizer.totalSize()}px`,
|
|
310
|
+
width: `${colVirtualizer.totalSize()}px`,
|
|
311
|
+
position: "relative"
|
|
312
|
+
}),
|
|
313
|
+
children: /* @__PURE__ */ jsx2(For2, {
|
|
314
|
+
each: () => rowVirtualizer.virtualItems(),
|
|
315
|
+
children: (r) => /* @__PURE__ */ jsx2(For2, {
|
|
316
|
+
each: () => colVirtualizer.virtualItems(),
|
|
317
|
+
children: (c) => {
|
|
318
|
+
const rowData = getData()[r.index];
|
|
319
|
+
const item = rowData ? rowData[c.index] : undefined;
|
|
320
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
321
|
+
style: () => ({
|
|
322
|
+
position: "absolute",
|
|
323
|
+
top: 0,
|
|
324
|
+
left: 0,
|
|
325
|
+
width: `${c.size}px`,
|
|
326
|
+
height: `${r.size}px`,
|
|
327
|
+
transform: `translate(${c.start}px, ${r.start}px)`,
|
|
328
|
+
willChange: "transform"
|
|
329
|
+
}),
|
|
330
|
+
children: props.children(item, r.index, c.index)
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
})
|
|
334
|
+
})
|
|
335
|
+
})
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
export { createVirtualizer2, VirtualList2, VirtualGrid2 };
|