@bevelo/virtual 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +49 -2
- package/dist/grid-BzP7CurM.d.cts +264 -0
- package/dist/grid-BzP7CurM.d.ts +264 -0
- package/dist/index-B0Ml3oq4.d.ts +133 -0
- package/dist/index-D_M9i1VO.d.cts +133 -0
- package/dist/live/index.cjs +537 -0
- package/dist/live/index.d.cts +110 -0
- package/dist/live/index.d.ts +110 -0
- package/dist/live/index.js +514 -0
- package/dist/measure-CtFm4neI.js +419 -0
- package/dist/measure-Dg1HYDei.cjs +472 -0
- package/dist/pure/headers.cjs +248 -0
- package/dist/pure/headers.d.cts +173 -0
- package/dist/pure/headers.d.ts +173 -0
- package/dist/pure/headers.js +242 -0
- package/dist/pure/index.cjs +19 -0
- package/dist/pure/index.d.cts +3 -0
- package/dist/pure/index.d.ts +3 -0
- package/dist/pure/index.js +3 -0
- package/dist/pure-WJ6pwZC6.cjs +514 -0
- package/dist/pure-jv1Ox9rG.js +443 -0
- package/package.json +48 -3
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import { a as clampIndex, i as computeRange, l as sanitizeSize, n as toRangeIndex, o as isSize, s as normalizeCount } from "./measure-CtFm4neI.js";
|
|
2
|
+
// src/pure/extract.ts
|
|
3
|
+
/** The window's own indices: `start` to `end - 1`. */
|
|
4
|
+
function defaultRangeExtractor({ range }) {
|
|
5
|
+
const out = [];
|
|
6
|
+
for (let index = range.start; index < range.end; index += 1) out.push(index);
|
|
7
|
+
return out;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* An extractor that renders the window plus a fixed set of indices, wherever they are.
|
|
11
|
+
*
|
|
12
|
+
* This is the sticky-header case: row 0 scrolls out of the window but must stay mounted to
|
|
13
|
+
* be pinned, and every other renderer of the window would have dropped it. The sticky
|
|
14
|
+
* indices are not repositioned — a pinned row is positioned by its host, and pre-clamping
|
|
15
|
+
* them into the window would fight the pin.
|
|
16
|
+
*
|
|
17
|
+
* Out-of-range and non-integer sticky indices are dropped rather than rendering a row for
|
|
18
|
+
* an item that does not exist; a negative or NaN index arrives from a config that went
|
|
19
|
+
* stale between renders, not from a host that meant it. Answers are normalised, so a pinned
|
|
20
|
+
* row the window has already reached appears once.
|
|
21
|
+
*/
|
|
22
|
+
function withStickyIndices(sticky) {
|
|
23
|
+
const pinned = sticky.filter((index) => Number.isInteger(index) && index >= 0);
|
|
24
|
+
return (context) => {
|
|
25
|
+
const count = Math.max(0, Math.floor(context.count));
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const index of pinned) if (index < count) out.push(index);
|
|
28
|
+
for (let index = context.range.start; index < context.range.end; index += 1) out.push(index);
|
|
29
|
+
return normalizeIndices(out, count);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* An extractor that always includes the given indices when they exist, and otherwise
|
|
34
|
+
* behaves as the default. Same as {@link withStickyIndices} with a shorter name for the
|
|
35
|
+
* common "keep these mounted" use: a focused row, a row holding an open editor.
|
|
36
|
+
*/
|
|
37
|
+
const keepMounted = withStickyIndices;
|
|
38
|
+
/**
|
|
39
|
+
* Normalises an extractor's answer: in-range integers, ascending, de-duplicated.
|
|
40
|
+
*
|
|
41
|
+
* A host's extractor is arbitrary code over arbitrary data, so the renderer cannot assume
|
|
42
|
+
* anything about its answer. The alternative — trusting it — turns one bad index into a
|
|
43
|
+
* row for an item that does not exist, and that shows up as a crash inside a component
|
|
44
|
+
* rather than as a wrong window here.
|
|
45
|
+
*/
|
|
46
|
+
function normalizeIndices(indices, count) {
|
|
47
|
+
const limit = Math.max(0, Math.floor(count));
|
|
48
|
+
const seen = /* @__PURE__ */ new Set();
|
|
49
|
+
for (const index of indices) {
|
|
50
|
+
if (!Number.isInteger(index) || index < 0 || index >= limit) continue;
|
|
51
|
+
seen.add(index);
|
|
52
|
+
}
|
|
53
|
+
if (seen.size === 0) return [];
|
|
54
|
+
return [...seen].sort((left, right) => left - right);
|
|
55
|
+
}
|
|
56
|
+
// src/pure/grid.ts
|
|
57
|
+
/**
|
|
58
|
+
* Two-dimensional windowing: a grid that scrolls both ways.
|
|
59
|
+
*
|
|
60
|
+
* A one-axis virtualizer leaves the other axis to the host, so a spreadsheet with 50,000
|
|
61
|
+
* columns and 50,000 rows gets a row window and a 50,000-cell row. This module windows both, from the same range maths as `computeRange`, and it accepts the same
|
|
62
|
+
* prefix-sum index — so a scroll frame on a 50,000 × 50,000 grid costs O(log n) per axis,
|
|
63
|
+
* exactly what one list costs, not the product.
|
|
64
|
+
*
|
|
65
|
+
* It composes rather than reimplements: both bands are `computeRange` with a swapped
|
|
66
|
+
* estimate, so a fix to the range maths reaches the grid, and a grid satisfies the same
|
|
67
|
+
* conformance rules as a list.
|
|
68
|
+
*
|
|
69
|
+
* @stable — follows semver.
|
|
70
|
+
*/
|
|
71
|
+
/**
|
|
72
|
+
* Computes the band of a grid to render.
|
|
73
|
+
*
|
|
74
|
+
* The two axes are independent — a row's height does not depend on which columns are
|
|
75
|
+
* visible — so each runs its own window and the cost is the sum of the two, never the
|
|
76
|
+
* product. Frozen rows and columns are reported separately because they are painted at
|
|
77
|
+
* their natural offsets rather than at the window's: that is what "frozen" means, and it is
|
|
78
|
+
* why a renderer cannot simply union them into the window.
|
|
79
|
+
*/
|
|
80
|
+
function gridWindow(options) {
|
|
81
|
+
const rowCount = normalizeCount(options.rowCount);
|
|
82
|
+
const columnCount = normalizeCount(options.columnCount);
|
|
83
|
+
const frozenRowCount = clampFrozen(options.frozen?.rows, rowCount);
|
|
84
|
+
const frozenColumnCount = clampFrozen(options.frozen?.columns, columnCount);
|
|
85
|
+
const rowEstimate = sizeReader(options.rowSize);
|
|
86
|
+
const columnEstimate = sizeReader(options.columnSize);
|
|
87
|
+
const shared = {
|
|
88
|
+
...options.overscan === void 0 ? {} : { overscan: options.overscan },
|
|
89
|
+
...options.scrollMargin === void 0 ? {} : { scrollMargin: options.scrollMargin }
|
|
90
|
+
};
|
|
91
|
+
const rows = computeRange({
|
|
92
|
+
count: rowCount,
|
|
93
|
+
scroll: options.scrollTop,
|
|
94
|
+
viewport: options.viewportHeight,
|
|
95
|
+
estimate: rowEstimate,
|
|
96
|
+
...shared,
|
|
97
|
+
...options.measuredRow === void 0 ? {} : { measured: options.measuredRow },
|
|
98
|
+
...options.rowIndex === void 0 ? {} : { index: asRangeIndex(options.rowIndex) }
|
|
99
|
+
});
|
|
100
|
+
const columns = computeRange({
|
|
101
|
+
count: columnCount,
|
|
102
|
+
scroll: options.scrollLeft,
|
|
103
|
+
viewport: options.viewportWidth,
|
|
104
|
+
estimate: columnEstimate,
|
|
105
|
+
...options.overscan === void 0 ? {} : { overscan: options.overscan },
|
|
106
|
+
...options.measuredColumn === void 0 ? {} : { measured: options.measuredColumn },
|
|
107
|
+
...options.columnIndex === void 0 ? {} : { index: asRangeIndex(options.columnIndex) }
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
rows,
|
|
111
|
+
columns,
|
|
112
|
+
frozenRows: indicesBelow(frozenRowCount, rows.start),
|
|
113
|
+
frozenColumns: indicesBelow(frozenColumnCount, columns.start)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The cells of a window, row-major, with their offsets.
|
|
118
|
+
*
|
|
119
|
+
* A generator: a host that draws only what its own clipping lets through stops early and
|
|
120
|
+
* never pays for the rest. The offsets come from the caller's size source rather than from
|
|
121
|
+
* the window, because a window reports the band's edges and not every cell's position.
|
|
122
|
+
*/
|
|
123
|
+
function* gridCells(grid, rows, columns) {
|
|
124
|
+
for (let row = grid.rows.start; row < grid.rows.end; row += 1) {
|
|
125
|
+
const y = rows.offsetOf(row);
|
|
126
|
+
const height = rows.sizeOf(row);
|
|
127
|
+
for (let column = grid.columns.start; column < grid.columns.end; column += 1) yield {
|
|
128
|
+
row,
|
|
129
|
+
column,
|
|
130
|
+
y,
|
|
131
|
+
x: columns.offsetOf(column),
|
|
132
|
+
height,
|
|
133
|
+
width: columns.sizeOf(column)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** A size is a number or a per-index reader; normalised to a reader. */
|
|
138
|
+
function sizeReader(size) {
|
|
139
|
+
return typeof size === "function" ? size : () => size;
|
|
140
|
+
}
|
|
141
|
+
/** Either index shape, as the range layer's. Detected by `total`, the one member they differ on. */
|
|
142
|
+
function asRangeIndex(index) {
|
|
143
|
+
return typeof index.total === "function" ? toRangeIndex(index) : index;
|
|
144
|
+
}
|
|
145
|
+
/** Freeze counts are whole and non-negative; Infinity means "every row or column". */
|
|
146
|
+
function clampFrozen(value, count) {
|
|
147
|
+
if (value === void 0) return 0;
|
|
148
|
+
if (value === Infinity) return count;
|
|
149
|
+
if (!Number.isFinite(value) || value <= 0) return 0;
|
|
150
|
+
return Math.min(Math.floor(value), count);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The frozen indices that are still above/left of the window.
|
|
154
|
+
*
|
|
155
|
+
* Once the window has scrolled to include a frozen row, painting it twice is the bug this
|
|
156
|
+
* filter prevents: the window owns it, and the window's own translate places it correctly.
|
|
157
|
+
*/
|
|
158
|
+
function indicesBelow(limit, windowStart) {
|
|
159
|
+
const top = Math.min(limit, Math.max(0, windowStart));
|
|
160
|
+
const out = [];
|
|
161
|
+
for (let index = 0; index < top; index += 1) out.push(index);
|
|
162
|
+
return out;
|
|
163
|
+
}
|
|
164
|
+
// src/pure/sheet-index.ts
|
|
165
|
+
/** Creates a mutable prefix-sum index with incremental structural updates. */
|
|
166
|
+
function createSheetSizeIndex(options) {
|
|
167
|
+
let sizeCount = normalizeCount(options.count);
|
|
168
|
+
const defaultSz = sanitizeSize(options.defaultSize);
|
|
169
|
+
let cap = Math.max(16, sizeCount);
|
|
170
|
+
let sizes = new Float64Array(cap);
|
|
171
|
+
let measured = new Uint8Array(cap);
|
|
172
|
+
let tree = new Float64Array(cap + 1);
|
|
173
|
+
let runningTotal = 0;
|
|
174
|
+
let maxBit = 0;
|
|
175
|
+
if (options.sizes === void 0) sizes.fill(defaultSz, 0, sizeCount);
|
|
176
|
+
else for (let i = 0; i < sizeCount; i += 1) {
|
|
177
|
+
const s = options.sizes(i);
|
|
178
|
+
if (isSize(s)) {
|
|
179
|
+
sizes[i] = s;
|
|
180
|
+
measured[i] = 1;
|
|
181
|
+
} else sizes[i] = defaultSz;
|
|
182
|
+
}
|
|
183
|
+
const rebuildTree = () => {
|
|
184
|
+
let total = 0;
|
|
185
|
+
for (let i = 1; i <= sizeCount; i += 1) {
|
|
186
|
+
const v = sizes[i - 1] ?? 0;
|
|
187
|
+
tree[i] = v;
|
|
188
|
+
total += v;
|
|
189
|
+
}
|
|
190
|
+
for (let i = 1; i <= sizeCount; i += 1) {
|
|
191
|
+
const parent = i + (i & -i);
|
|
192
|
+
if (parent <= sizeCount) tree[parent] = (tree[parent] ?? 0) + (tree[i] ?? 0);
|
|
193
|
+
}
|
|
194
|
+
runningTotal = total;
|
|
195
|
+
maxBit = sizeCount > 0 ? 1 << 31 - Math.clz32(sizeCount) : 0;
|
|
196
|
+
};
|
|
197
|
+
rebuildTree();
|
|
198
|
+
const ensureCapacity = (needed) => {
|
|
199
|
+
if (needed <= cap) return;
|
|
200
|
+
while (cap < needed) cap *= 2;
|
|
201
|
+
const nextSizes = new Float64Array(cap);
|
|
202
|
+
nextSizes.set(sizes.subarray(0, sizeCount));
|
|
203
|
+
sizes = nextSizes;
|
|
204
|
+
const nextMeasured = new Uint8Array(cap);
|
|
205
|
+
nextMeasured.set(measured.subarray(0, sizeCount));
|
|
206
|
+
measured = nextMeasured;
|
|
207
|
+
tree = new Float64Array(cap + 1);
|
|
208
|
+
};
|
|
209
|
+
const add = (index, delta) => {
|
|
210
|
+
for (let node = index + 1; node <= sizeCount; node += node & -node) tree[node] = (tree[node] ?? 0) + delta;
|
|
211
|
+
};
|
|
212
|
+
const prefix = (length) => {
|
|
213
|
+
let sum = 0;
|
|
214
|
+
for (let node = length; node > 0; node -= node & -node) sum += tree[node] ?? 0;
|
|
215
|
+
return sum;
|
|
216
|
+
};
|
|
217
|
+
const inRange = (index) => Number.isInteger(index) && index >= 0 && index < sizeCount;
|
|
218
|
+
return {
|
|
219
|
+
get count() {
|
|
220
|
+
return sizeCount;
|
|
221
|
+
},
|
|
222
|
+
defaultSize: defaultSz,
|
|
223
|
+
set(index, size) {
|
|
224
|
+
if (!inRange(index) || !isSize(size)) return;
|
|
225
|
+
const previous = sizes[index] ?? 0;
|
|
226
|
+
measured[index] = 1;
|
|
227
|
+
if (previous === size) return;
|
|
228
|
+
sizes[index] = size;
|
|
229
|
+
const delta = size - previous;
|
|
230
|
+
add(index, delta);
|
|
231
|
+
runningTotal = Math.max(0, runningTotal + delta);
|
|
232
|
+
},
|
|
233
|
+
reset(index) {
|
|
234
|
+
if (!inRange(index) || measured[index] === 0) return;
|
|
235
|
+
const previous = sizes[index] ?? 0;
|
|
236
|
+
measured[index] = 0;
|
|
237
|
+
sizes[index] = defaultSz;
|
|
238
|
+
const delta = defaultSz - previous;
|
|
239
|
+
if (delta !== 0) {
|
|
240
|
+
add(index, delta);
|
|
241
|
+
runningTotal = Math.max(0, runningTotal + delta);
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
sizeOf(index) {
|
|
245
|
+
if (sizeCount === 0) return 0;
|
|
246
|
+
return sizes[clampIndex(index, sizeCount)] ?? 0;
|
|
247
|
+
},
|
|
248
|
+
total() {
|
|
249
|
+
return runningTotal > 0 ? runningTotal : 0;
|
|
250
|
+
},
|
|
251
|
+
clear() {
|
|
252
|
+
measured.fill(0, 0, sizeCount);
|
|
253
|
+
sizes.fill(defaultSz, 0, sizeCount);
|
|
254
|
+
rebuildTree();
|
|
255
|
+
},
|
|
256
|
+
hasMeasured(index) {
|
|
257
|
+
return inRange(index) && measured[index] === 1;
|
|
258
|
+
},
|
|
259
|
+
offsetOf(index) {
|
|
260
|
+
if (sizeCount === 0) return 0;
|
|
261
|
+
if (Number.isNaN(index) || index <= 0) return 0;
|
|
262
|
+
if (index >= sizeCount) return runningTotal > 0 ? runningTotal : 0;
|
|
263
|
+
const value = prefix(Math.floor(index));
|
|
264
|
+
return value > 0 ? value : 0;
|
|
265
|
+
},
|
|
266
|
+
indexAt(offset) {
|
|
267
|
+
if (sizeCount === 0) return -1;
|
|
268
|
+
if (Number.isNaN(offset) || offset <= 0 || offset === Number.NEGATIVE_INFINITY) return 0;
|
|
269
|
+
if (offset === Number.POSITIVE_INFINITY || offset >= runningTotal) return sizeCount - 1;
|
|
270
|
+
let index = 0;
|
|
271
|
+
let remaining = offset;
|
|
272
|
+
for (let bit = maxBit; bit > 0; bit >>>= 1) {
|
|
273
|
+
const next = index + bit;
|
|
274
|
+
if (next <= sizeCount) {
|
|
275
|
+
const value = tree[next];
|
|
276
|
+
if (value <= remaining) {
|
|
277
|
+
index = next;
|
|
278
|
+
remaining -= value;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return Math.min(index, sizeCount - 1);
|
|
283
|
+
},
|
|
284
|
+
lowerBound(offset) {
|
|
285
|
+
if (sizeCount === 0 || Number.isNaN(offset) || offset <= 0 || offset === Number.NEGATIVE_INFINITY) return 0;
|
|
286
|
+
if (offset === Number.POSITIVE_INFINITY || offset > (runningTotal > 0 ? runningTotal : 0)) return sizeCount;
|
|
287
|
+
let index = 0;
|
|
288
|
+
let remaining = offset;
|
|
289
|
+
for (let bit = maxBit; bit > 0; bit >>>= 1) {
|
|
290
|
+
const next = index + bit;
|
|
291
|
+
if (next <= sizeCount) {
|
|
292
|
+
const value = tree[next];
|
|
293
|
+
if (value < remaining) {
|
|
294
|
+
index = next;
|
|
295
|
+
remaining -= value;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return Math.min(index + 1, sizeCount);
|
|
300
|
+
},
|
|
301
|
+
insert(at, count, insertSizes) {
|
|
302
|
+
const n = normalizeCount(count);
|
|
303
|
+
if (n === 0) return;
|
|
304
|
+
const pos = Number.isNaN(at) || at <= 0 ? 0 : Math.min(sizeCount, Math.floor(at));
|
|
305
|
+
ensureCapacity(sizeCount + n);
|
|
306
|
+
if (pos < sizeCount) {
|
|
307
|
+
sizes.copyWithin(pos + n, pos, sizeCount);
|
|
308
|
+
measured.copyWithin(pos + n, pos, sizeCount);
|
|
309
|
+
}
|
|
310
|
+
for (let k = 0; k < n; k += 1) {
|
|
311
|
+
const v = insertSizes?.[k];
|
|
312
|
+
if (isSize(v)) {
|
|
313
|
+
sizes[pos + k] = v;
|
|
314
|
+
measured[pos + k] = 1;
|
|
315
|
+
} else {
|
|
316
|
+
sizes[pos + k] = defaultSz;
|
|
317
|
+
measured[pos + k] = 0;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
sizeCount += n;
|
|
321
|
+
rebuildTree();
|
|
322
|
+
},
|
|
323
|
+
remove(at, count) {
|
|
324
|
+
const n = normalizeCount(count);
|
|
325
|
+
if (n === 0 || sizeCount === 0) return;
|
|
326
|
+
const start = Number.isNaN(at) || at <= 0 ? 0 : Math.min(sizeCount, Math.floor(at));
|
|
327
|
+
const end = Math.min(sizeCount, start + n);
|
|
328
|
+
const removed = end - start;
|
|
329
|
+
if (removed <= 0) return;
|
|
330
|
+
if (end < sizeCount) {
|
|
331
|
+
sizes.copyWithin(start, end, sizeCount);
|
|
332
|
+
measured.copyWithin(start, end, sizeCount);
|
|
333
|
+
}
|
|
334
|
+
sizeCount -= removed;
|
|
335
|
+
rebuildTree();
|
|
336
|
+
},
|
|
337
|
+
move(from, to, count = 1) {
|
|
338
|
+
const len = normalizeCount(count);
|
|
339
|
+
if (len === 0 || sizeCount <= 1) return;
|
|
340
|
+
const src = clampIndex(from, sizeCount);
|
|
341
|
+
const actualLen = Math.min(len, sizeCount - src);
|
|
342
|
+
if (actualLen <= 0) return;
|
|
343
|
+
const dst = Number.isNaN(to) || to <= 0 ? 0 : Math.min(sizeCount - actualLen, Math.floor(to));
|
|
344
|
+
if (dst === src) return;
|
|
345
|
+
const savedSizes = sizes.slice(src, src + actualLen);
|
|
346
|
+
const savedMeasured = measured.slice(src, src + actualLen);
|
|
347
|
+
if (dst < src) {
|
|
348
|
+
sizes.copyWithin(dst + actualLen, dst, src);
|
|
349
|
+
measured.copyWithin(dst + actualLen, dst, src);
|
|
350
|
+
} else {
|
|
351
|
+
sizes.copyWithin(src, src + actualLen, dst + actualLen);
|
|
352
|
+
measured.copyWithin(src, src + actualLen, dst + actualLen);
|
|
353
|
+
}
|
|
354
|
+
sizes.set(savedSizes, dst);
|
|
355
|
+
measured.set(savedMeasured, dst);
|
|
356
|
+
rebuildTree();
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
// src/pure/anchor.ts
|
|
361
|
+
/**
|
|
362
|
+
* @experimental — may change in any minor release.
|
|
363
|
+
* The anchor for `view`: the entry at its start edge. Null when the index is empty.
|
|
364
|
+
*/
|
|
365
|
+
function captureAnchor(index, keyAt, view) {
|
|
366
|
+
const at = index.indexAt(Math.max(0, view.start));
|
|
367
|
+
if (at < 0) return null;
|
|
368
|
+
return {
|
|
369
|
+
key: keyAt(at),
|
|
370
|
+
within: view.start - index.offsetOf(at)
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* @experimental — may change in any minor release.
|
|
375
|
+
* New scroll start that puts anchor.key back where it was; null when the key is gone.
|
|
376
|
+
*/
|
|
377
|
+
function restoreAnchor(anchor, index, indexOf) {
|
|
378
|
+
const at = indexOf(anchor.key);
|
|
379
|
+
if (at < 0 || at >= index.count) return null;
|
|
380
|
+
return index.offsetOf(at) + anchor.within;
|
|
381
|
+
}
|
|
382
|
+
/** The largest start that still fills the view. */
|
|
383
|
+
function maxStart(index, view) {
|
|
384
|
+
return Math.max(0, index.total() - view.size);
|
|
385
|
+
}
|
|
386
|
+
function clampStart(start, index, view) {
|
|
387
|
+
return Math.min(Math.max(0, start), maxStart(index, view));
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* @experimental — may change in any minor release.
|
|
391
|
+
* Follow the new end when the view was at the end before the change, else restore the anchor.
|
|
392
|
+
* `mode: "start"` never follows. A missing anchor or key keeps `view.start`. The answer is
|
|
393
|
+
* clamped to the scrollable range.
|
|
394
|
+
*/
|
|
395
|
+
function anchoredStart(input) {
|
|
396
|
+
const { index, view } = input;
|
|
397
|
+
if (input.mode === "end" && input.wasAtEnd) return maxStart(index, view);
|
|
398
|
+
return clampStart((input.anchor === null ? null : restoreAnchor(input.anchor, index, input.indexOf)) ?? view.start, index, view);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* @experimental — may change in any minor release.
|
|
402
|
+
* The view start that shows entry `i` with `align`. `padding` is the part of the view that
|
|
403
|
+
* sticky chrome covers at each edge, so alignment keeps the entry clear of it. An entry larger
|
|
404
|
+
* than the uncovered view aligns to its start under `auto`. Clamped to the scrollable range.
|
|
405
|
+
*/
|
|
406
|
+
function alignedOffset(index, i, align, view, padding) {
|
|
407
|
+
if (index.count === 0) return 0;
|
|
408
|
+
const start = index.offsetOf(i);
|
|
409
|
+
const size = index.sizeOf(i);
|
|
410
|
+
const room = Math.max(0, view.size - padding.start - padding.end);
|
|
411
|
+
const toStart = start - padding.start;
|
|
412
|
+
const toEnd = start + size - (view.size - padding.end);
|
|
413
|
+
let target;
|
|
414
|
+
if (align === "start") target = toStart;
|
|
415
|
+
else if (align === "end") target = toEnd;
|
|
416
|
+
else if (align === "center") target = start + size / 2 - padding.start - room / 2;
|
|
417
|
+
else if (start >= view.start + padding.start && start + size <= view.start + view.size - padding.end) target = view.start;
|
|
418
|
+
else target = start < view.start + padding.start || size > room ? toStart : toEnd;
|
|
419
|
+
return clampStart(target, index, view);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* @experimental — may change in any minor release.
|
|
423
|
+
* A SizeIndex plus keys seen as an ItemTrack. The index holds one entry per row of `lanes`
|
|
424
|
+
* slots; `keyAt` and `indexOf` answer per slot. `count` defaults to every row full, and
|
|
425
|
+
* `sizeOf` to the row's size, for a caller that keeps per-slot sizes elsewhere.
|
|
426
|
+
*/
|
|
427
|
+
function trackOf(index, keyAt, indexOf, lanes, version, count = index.count * lanes, sizeOf = (i) => index.sizeOf(Math.floor(i / lanes))) {
|
|
428
|
+
return {
|
|
429
|
+
count,
|
|
430
|
+
lanes,
|
|
431
|
+
total: index.total(),
|
|
432
|
+
version,
|
|
433
|
+
keyAt(i) {
|
|
434
|
+
if (!Number.isInteger(i) || i < 0 || i >= count) throw new RangeError("track slot " + i + " is outside [0, " + count + ")");
|
|
435
|
+
return keyAt(i);
|
|
436
|
+
},
|
|
437
|
+
indexOf,
|
|
438
|
+
startOf: (i) => index.offsetOf(Math.floor(i / lanes)),
|
|
439
|
+
sizeOf,
|
|
440
|
+
indexAt: (offset) => count === 0 ? -1 : Math.min(count - 1, index.indexAt(offset) * lanes)
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
export { trackOf as a, gridWindow as c, normalizeIndices as d, withStickyIndices as f, restoreAnchor as i, defaultRangeExtractor as l, anchoredStart as n, createSheetSizeIndex as o, captureAnchor as r, gridCells as s, alignedOffset as t, keepMounted as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bevelo/virtual",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Virtualisation: range maths with variable sizes, keyed measurement and anchoring, bound to a runtime scroller.",
|
|
6
|
+
"main": "./dist/live/index.cjs",
|
|
7
|
+
"module": "./dist/live/index.js",
|
|
8
|
+
"types": "./dist/live/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/live/index.d.ts",
|
|
12
|
+
"import": "./dist/live/index.js",
|
|
13
|
+
"require": "./dist/live/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./core": {
|
|
16
|
+
"types": "./dist/pure/index.d.ts",
|
|
17
|
+
"import": "./dist/pure/index.js",
|
|
18
|
+
"require": "./dist/pure/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./headers": {
|
|
21
|
+
"types": "./dist/pure/headers.d.ts",
|
|
22
|
+
"import": "./dist/pure/headers.js",
|
|
23
|
+
"require": "./dist/pure/headers.cjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@bevelo/runtime": "0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"homepage": "https://github.com/bevelo/bevelo#readme",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/bevelo/bevelo/issues"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/bevelo/bevelo.git",
|
|
41
|
+
"directory": "packages/virtual"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "vp pack",
|
|
48
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
49
|
+
"test": "vp test run"
|
|
50
|
+
}
|
|
6
51
|
}
|