@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.
@@ -0,0 +1,537 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_pure_headers = require("../pure/headers.cjs");
3
+ const require_pure = require("../pure-WJ6pwZC6.cjs");
4
+ const require_measure = require("../measure-Dg1HYDei.cjs");
5
+ let _bevelo_runtime = require("@bevelo/runtime");
6
+ let _bevelo_runtime_scroll = require("@bevelo/runtime/scroll");
7
+ let _bevelo_runtime_store = require("@bevelo/runtime/store");
8
+ // src/live/virtualizer.ts
9
+ /** Frames a goal may chase a moving target before it gives up. */
10
+ const GOAL_FRAMES = 60;
11
+ function resolve(value) {
12
+ return typeof value === "function" ? value() : value;
13
+ }
14
+ function isWindow(target) {
15
+ return target.window === target;
16
+ }
17
+ /**
18
+ * Creates a virtualizer. Without a scroller (a server render, a ref not attached yet) the
19
+ * snapshot is computed from `initialRect` and `initialOffset`; the engine binds to the
20
+ * scroller on the first `update`, `measure` or scroll call that resolves one.
21
+ *
22
+ * The scroller should have `overflow-anchor: none`: the engine keeps the view still itself.
23
+ */
24
+ function createVirtualizer(initial) {
25
+ let opts = initial;
26
+ let axis = "y";
27
+ let lanes = 1;
28
+ let gap = 0;
29
+ let keys = [];
30
+ let keyIndex = null;
31
+ const sizes = /* @__PURE__ */ new Map();
32
+ let index = require_measure.createSizeIndex({
33
+ count: 0,
34
+ estimate: () => 0
35
+ });
36
+ let version = 0;
37
+ let track = null;
38
+ const view = {
39
+ start: 0,
40
+ size: 0
41
+ };
42
+ let margin = 0;
43
+ let marginDirty = true;
44
+ let scrolling = false;
45
+ let shift = 0;
46
+ let follow = false;
47
+ let goal = null;
48
+ let write = null;
49
+ let armedStart = true;
50
+ let armedEnd = true;
51
+ const retained = /* @__PURE__ */ new Map();
52
+ let target = null;
53
+ let scroller = null;
54
+ let frame = null;
55
+ let stopJobs = null;
56
+ const unbind = [];
57
+ let hold = null;
58
+ let disposed = false;
59
+ const observed = /* @__PURE__ */ new Map();
60
+ /** Observed elements whose first size has not arrived yet; a driven scroll waits for them. */
61
+ const unsized = /* @__PURE__ */ new Set();
62
+ let sweepDue = false;
63
+ const store = (0, _bevelo_runtime_store.createStore)((_, next) => next, {
64
+ items: [],
65
+ range: {
66
+ start: 0,
67
+ end: 0,
68
+ offset: 0,
69
+ size: 0,
70
+ total: 0
71
+ },
72
+ total: 0,
73
+ scrolling: false,
74
+ atEnd: true
75
+ });
76
+ const estimateOf = (i) => {
77
+ const e = opts.estimate;
78
+ const size = typeof e === "number" ? e : e(i);
79
+ return Number.isFinite(size) && size >= 0 ? size : 0;
80
+ };
81
+ const itemSize = (i) => sizes.get(keys[i] ?? "") ?? estimateOf(i);
82
+ const rowCount = () => Math.ceil(keys.length / lanes);
83
+ const rowSize = (row) => {
84
+ let tallest = 0;
85
+ for (let i = row * lanes; i < Math.min(keys.length, (row + 1) * lanes); i += 1) tallest = Math.max(tallest, itemSize(i));
86
+ return tallest + (row < rowCount() - 1 ? gap : 0);
87
+ };
88
+ const slotOf = (key) => {
89
+ if (keyIndex === null) {
90
+ keyIndex = /* @__PURE__ */ new Map();
91
+ keys.forEach((k, i) => keyIndex.set(k, i));
92
+ }
93
+ return keyIndex.get(key) ?? -1;
94
+ };
95
+ const rowOfKey = (key) => {
96
+ const slot = slotOf(key);
97
+ return slot < 0 ? -1 : Math.floor(slot / lanes);
98
+ };
99
+ const total = () => index.total();
100
+ const maxStart = () => Math.max(0, total() - view.size);
101
+ const isAtEnd = () => view.start + view.size >= total() - (opts.atEndThreshold ?? 2);
102
+ const anchorOf = () => keys.length === 0 ? null : require_pure.captureAnchor(index, (row) => keys[row * lanes] ?? "", view);
103
+ function readOptions() {
104
+ axis = opts.axis ?? "y";
105
+ const l = opts.lanes ?? 1;
106
+ lanes = Number.isFinite(l) && l >= 1 ? Math.floor(l) : 1;
107
+ gap = Math.max(0, opts.gap ?? 0);
108
+ }
109
+ function nextKeys() {
110
+ const count = Number.isFinite(opts.count) && opts.count > 0 ? Math.floor(opts.count) : 0;
111
+ const next = new Array(count);
112
+ for (let i = 0; i < count; i += 1) next[i] = opts.key(i);
113
+ return next;
114
+ }
115
+ function rebuild(next) {
116
+ keys = next;
117
+ keyIndex = null;
118
+ index = require_measure.createSizeIndex({
119
+ count: rowCount(),
120
+ estimate: rowSize
121
+ });
122
+ version += 1;
123
+ track = null;
124
+ }
125
+ /** Swaps in new keys or layout and moves the view so the anchor key stays at the same pixel. */
126
+ function rekey(next) {
127
+ const anchor = anchorOf();
128
+ const oldSlot = anchor === null ? -1 : rowOfKey(anchor.key) * lanes;
129
+ const oldCount = keys.length;
130
+ const wasAtEnd = isAtEnd();
131
+ readOptions();
132
+ rebuild(next);
133
+ if (oldCount !== next.length) armedStart = armedEnd = true;
134
+ const indexOf = (key) => {
135
+ for (const at of [oldSlot + next.length - oldCount, oldSlot]) if (next[at] === key) return Math.floor(at / lanes);
136
+ return rowOfKey(key);
137
+ };
138
+ const mode = opts.anchor ?? "start";
139
+ if (mode === "end" && wasAtEnd) {
140
+ follow = true;
141
+ view.start = maxStart();
142
+ return;
143
+ }
144
+ const start = require_pure.anchoredStart({
145
+ mode,
146
+ wasAtEnd,
147
+ anchor,
148
+ index,
149
+ view,
150
+ indexOf
151
+ });
152
+ shift += start - view.start;
153
+ view.start = start;
154
+ }
155
+ /**
156
+ * A size arrived for `key`. Growth above the view shifts it. A view resting at the end
157
+ * follows growth there when the list is end-anchored, and in any list when the size is a
158
+ * row's first: that replaces the engine's estimate rather than changing the content, so a
159
+ * reader who reached the end stays there.
160
+ */
161
+ function record(key, size) {
162
+ if (sizes.get(key) === size || !(size >= 0)) return;
163
+ const first = !sizes.has(key);
164
+ sizes.set(key, size);
165
+ const slot = slotOf(key);
166
+ if (slot < 0) return;
167
+ const row = Math.floor(slot / lanes);
168
+ const before = index.sizeOf(row);
169
+ const after = rowSize(row);
170
+ if (after !== before) {
171
+ const above = index.offsetOf(row) < view.start;
172
+ if (follow || isAtEnd() && (first || (opts.anchor ?? "start") === "end")) follow = true;
173
+ else if (above) shift += after - before;
174
+ index.set(row, after);
175
+ version += 1;
176
+ track = null;
177
+ }
178
+ if (frame !== null && scroller !== null) frame.request();
179
+ else publish();
180
+ }
181
+ function snapshotItems(range, count) {
182
+ const extracted = (opts.extract ?? require_pure.defaultRangeExtractor)({
183
+ range,
184
+ count
185
+ });
186
+ const sticky = new Set(require_pure.normalizeIndices(opts.sticky ?? [], count));
187
+ const extra = [];
188
+ for (const key of retained.keys()) {
189
+ const slot = slotOf(key);
190
+ if (slot >= 0) extra.push(slot);
191
+ }
192
+ const base = new Set(require_pure.normalizeIndices([...extracted, ...sticky], count));
193
+ return require_pure.normalizeIndices([...base, ...extra], count).map((i) => {
194
+ const start = index.offsetOf(Math.floor(i / lanes));
195
+ const size = itemSize(i);
196
+ return {
197
+ key: keys[i] ?? "",
198
+ index: i,
199
+ start,
200
+ size,
201
+ end: start + size,
202
+ lane: i % lanes,
203
+ sticky: sticky.has(i),
204
+ retained: !base.has(i)
205
+ };
206
+ });
207
+ }
208
+ function sameItems(a, b) {
209
+ if (a.length !== b.length) return false;
210
+ return a.every((x, i) => {
211
+ const y = b[i];
212
+ return x.key === y.key && x.index === y.index && x.start === y.start && x.size === y.size && x.lane === y.lane && x.sticky === y.sticky && x.retained === y.retained;
213
+ });
214
+ }
215
+ function publish() {
216
+ const count = keys.length;
217
+ const rows = index.count;
218
+ const overscan = Math.max(0, Math.floor(opts.overscan ?? 2));
219
+ const top = Math.min(Math.max(0, view.start), maxStart());
220
+ const first = rows === 0 ? 0 : index.indexAt(top);
221
+ const last = rows === 0 ? 0 : Math.max(first + 1, index.lowerBound(top + view.size));
222
+ const startRow = Math.max(0, first - overscan);
223
+ const endRow = Math.min(rows, last + overscan);
224
+ const offset = index.offsetOf(startRow);
225
+ const range = {
226
+ start: startRow * lanes,
227
+ end: Math.min(count, endRow * lanes),
228
+ offset,
229
+ size: index.offsetOf(endRow) - offset,
230
+ total: total()
231
+ };
232
+ const items = snapshotItems(range, count);
233
+ const previous = store.get();
234
+ const atEnd = isAtEnd();
235
+ const r = previous.range;
236
+ if (!(sameItems(items, previous.items) && r.start === range.start && r.end === range.end && r.offset === range.offset && r.size === range.size && previous.total === range.total && previous.scrolling === scrolling && previous.atEnd === atEnd)) store.dispatch({
237
+ items,
238
+ range,
239
+ total: range.total,
240
+ scrolling,
241
+ atEnd
242
+ });
243
+ if (scroller === null || count === 0) return;
244
+ if (range.start === 0 && armedStart) {
245
+ armedStart = false;
246
+ opts.onReachStart?.();
247
+ }
248
+ if (range.end === count && armedEnd) {
249
+ armedEnd = false;
250
+ opts.onReachEnd?.();
251
+ }
252
+ }
253
+ function readPass() {
254
+ bind();
255
+ if (scroller === null) return;
256
+ if (sweepDue) {
257
+ sweepDue = false;
258
+ for (const [el, off] of observed) if (!el.isConnected) {
259
+ off();
260
+ observed.delete(el);
261
+ unsized.delete(el);
262
+ }
263
+ }
264
+ const offset = scroller.offset();
265
+ const box = scroller.viewport();
266
+ const size = axis === "y" ? box.height : box.width;
267
+ if (size !== view.size) marginDirty = true;
268
+ view.size = size;
269
+ const at = axis === "y" ? offset.y : offset.x;
270
+ if (opts.scrollMargin !== void 0) margin = opts.scrollMargin;
271
+ else if (marginDirty) {
272
+ marginDirty = false;
273
+ const el = resolve(opts.element ?? null);
274
+ if (el === null) margin = 0;
275
+ else {
276
+ const rect = el.getBoundingClientRect();
277
+ margin = (axis === "y" ? rect.top - box.y : rect.left - box.x) + at;
278
+ }
279
+ }
280
+ view.start = at - margin;
281
+ scrolling = (0, _bevelo_runtime_scroll.isScrolling)(scroller.target);
282
+ }
283
+ function computePass() {
284
+ if (scroller === null) return;
285
+ if (follow) {
286
+ follow = false;
287
+ shift = 0;
288
+ view.start = maxStart();
289
+ write = {
290
+ to: view.start,
291
+ behavior: "instant"
292
+ };
293
+ } else if (shift !== 0) {
294
+ view.start += shift;
295
+ shift = 0;
296
+ write = {
297
+ to: view.start,
298
+ behavior: "instant"
299
+ };
300
+ }
301
+ if (goal !== null) chase(goal);
302
+ publish();
303
+ const busy = goal !== null || scrolling;
304
+ if (busy && hold === null) hold = frame.keepAlive();
305
+ if (!busy && hold !== null) {
306
+ hold();
307
+ hold = null;
308
+ }
309
+ }
310
+ /** One frame of a driven scroll: re-aim when the target moved, settle when two frames agree. */
311
+ function chase(g) {
312
+ const to = g.target();
313
+ g.frames += 1;
314
+ if (to === null || g.frames > GOAL_FRAMES) {
315
+ goal = null;
316
+ return;
317
+ }
318
+ if (to === g.last && Math.abs(view.start - to) <= 1 && !awaitingSizes()) {
319
+ goal = null;
320
+ return;
321
+ }
322
+ if (to !== g.last || g.behavior !== "smooth") {
323
+ if (to !== g.last) g.frames = 0;
324
+ g.last = to;
325
+ write = {
326
+ to,
327
+ behavior: g.behavior
328
+ };
329
+ if (g.behavior !== "smooth") view.start = to;
330
+ }
331
+ }
332
+ /** A rendered row is still waiting for its first size: the target may still move. */
333
+ function awaitingSizes() {
334
+ for (const el of unsized) if (el.isConnected) return true;
335
+ return false;
336
+ }
337
+ function writePass() {
338
+ if (write === null || scroller === null) return;
339
+ const to = write.to + margin;
340
+ scroller.scrollTo(axis === "y" ? { y: to } : { x: to }, write.behavior);
341
+ write = null;
342
+ }
343
+ function bind() {
344
+ if (disposed) return;
345
+ const next = resolve(opts.scroller);
346
+ if (next === target) return;
347
+ for (const off of unbind.splice(0)) off();
348
+ target = next;
349
+ scroller = next === null ? null : (0, _bevelo_runtime_scroll.scrollerOf)(next);
350
+ if (next === null || scroller === null) return;
351
+ const doc = isWindow(next) ? next.document : next.ownerDocument;
352
+ const own = opts.frame === void 0;
353
+ frame ??= opts.frame ?? (0, _bevelo_runtime.frameLoopOf)(doc);
354
+ const loop = frame;
355
+ if (stopJobs === null) {
356
+ const jobs = [
357
+ loop.job({
358
+ kind: "read",
359
+ beat: "measure",
360
+ name: "virtualizer-read",
361
+ run: readPass
362
+ }),
363
+ loop.job({
364
+ kind: "compute",
365
+ beat: "intent",
366
+ name: "virtualizer",
367
+ run: computePass
368
+ }),
369
+ loop.job({
370
+ kind: "write",
371
+ beat: "write",
372
+ name: "virtualizer-write",
373
+ run: writePass
374
+ })
375
+ ];
376
+ stopJobs = () => jobs.forEach((stop) => stop());
377
+ }
378
+ const wake = () => {
379
+ marginDirty = true;
380
+ loop.request();
381
+ };
382
+ unbind.push((0, _bevelo_runtime_scroll.onScroll)(next, () => own ? void 0 : loop.request()));
383
+ if (isWindow(next)) {
384
+ next.addEventListener("resize", wake);
385
+ unbind.push(() => next.removeEventListener("resize", wake));
386
+ } else unbind.push((0, _bevelo_runtime_scroll.observeSize)(next, wake));
387
+ const el = resolve(opts.element ?? null);
388
+ if (el !== null) unbind.push((0, _bevelo_runtime_scroll.observeSize)(el, wake));
389
+ marginDirty = true;
390
+ loop.request();
391
+ }
392
+ function aim(target, behavior) {
393
+ goal = {
394
+ target,
395
+ behavior: behavior ?? "auto",
396
+ last: null,
397
+ frames: 0
398
+ };
399
+ bind();
400
+ frame?.request();
401
+ }
402
+ function scrollToKey(key, options = {}) {
403
+ const padding = {
404
+ start: opts.padding?.start ?? 0,
405
+ end: opts.padding?.end ?? 0
406
+ };
407
+ aim(() => {
408
+ const row = rowOfKey(key);
409
+ return row < 0 ? null : require_pure.alignedOffset(index, row, options.align ?? "auto", view, padding);
410
+ }, options.behavior);
411
+ }
412
+ function retain(list) {
413
+ for (const key of list) retained.set(key, (retained.get(key) ?? 0) + 1);
414
+ publish();
415
+ let live = true;
416
+ return () => {
417
+ if (!live) return;
418
+ live = false;
419
+ for (const key of list) {
420
+ const n = (retained.get(key) ?? 1) - 1;
421
+ if (n > 0) retained.set(key, n);
422
+ else retained.delete(key);
423
+ }
424
+ publish();
425
+ };
426
+ }
427
+ const measure = (el) => {
428
+ if (el === null) {
429
+ sweepDue = true;
430
+ frame?.request();
431
+ return;
432
+ }
433
+ if (observed.has(el) || disposed) return;
434
+ if (typeof (el.ownerDocument.defaultView ?? globalThis).ResizeObserver === "function") unsized.add(el);
435
+ observed.set(el, (0, _bevelo_runtime_scroll.observeSize)(el, (size) => {
436
+ unsized.delete(el);
437
+ if (!el.isConnected) return;
438
+ const key = el.getAttribute("data-key");
439
+ if (key !== null) record(key, axis === "y" ? size.height : size.width);
440
+ }));
441
+ bind();
442
+ };
443
+ readOptions();
444
+ rebuild(nextKeys());
445
+ view.size = initial.initialRect === void 0 ? 0 : axis === "y" ? initial.initialRect.height : initial.initialRect.width;
446
+ const first = initial.initialOffset ?? (initial.anchor === "end" ? "end" : 0);
447
+ view.start = first === "end" ? maxStart() : Math.max(0, first);
448
+ publish();
449
+ if (first === "end") aim(() => maxStart(), "instant");
450
+ else if (first > 0) aim(() => first, "instant");
451
+ else bind();
452
+ const source = {
453
+ track() {
454
+ track ??= require_pure.trackOf(index, (i) => keys[i] ?? "", slotOf, lanes, version, keys.length, itemSize);
455
+ return track;
456
+ },
457
+ origin() {
458
+ if (scroller === null) return {
459
+ x: 0,
460
+ y: 0
461
+ };
462
+ const box = scroller.viewport();
463
+ const offset = scroller.offset();
464
+ return axis === "y" ? {
465
+ x: box.x - offset.x,
466
+ y: box.y - offset.y + margin
467
+ } : {
468
+ x: box.x - offset.x + margin,
469
+ y: box.y - offset.y
470
+ };
471
+ },
472
+ retain,
473
+ reveal: (i) => scrollToKey(keys[Math.min(Math.max(0, i), keys.length - 1)] ?? "", { behavior: "instant" })
474
+ };
475
+ return {
476
+ get: store.get,
477
+ subscribe: store.subscribe,
478
+ update(next) {
479
+ if (disposed) return;
480
+ const previous = opts;
481
+ opts = next;
482
+ const keysNext = nextKeys();
483
+ if ((next.lanes ?? 1) !== (previous.lanes ?? 1) || (next.gap ?? 0) !== (previous.gap ?? 0) || typeof next.estimate === "number" && next.estimate !== previous.estimate || (next.axis ?? "y") !== axis || keysNext.length !== keys.length || keysNext.some((k, i) => k !== keys[i])) rekey(keysNext);
484
+ if (next.element !== previous.element) marginDirty = true;
485
+ bind();
486
+ publish();
487
+ frame?.request();
488
+ },
489
+ measure,
490
+ scrollToIndex(i, options) {
491
+ if (keys.length > 0) scrollToKey(keys[Math.min(Math.max(0, Math.floor(i)), keys.length - 1)], options);
492
+ },
493
+ scrollToKey,
494
+ scrollToOffset(offset, options = {}) {
495
+ aim(() => Math.min(Math.max(0, offset), maxStart()), options.behavior);
496
+ },
497
+ scrollToEnd(options = {}) {
498
+ aim(maxStart, options.behavior);
499
+ },
500
+ retain,
501
+ source,
502
+ dispose() {
503
+ if (disposed) return;
504
+ disposed = true;
505
+ for (const off of unbind.splice(0)) off();
506
+ for (const off of observed.values()) off();
507
+ observed.clear();
508
+ unsized.clear();
509
+ stopJobs?.();
510
+ hold?.();
511
+ hold = null;
512
+ }
513
+ };
514
+ }
515
+ exports.DEFAULT_OVERSCAN = require_measure.DEFAULT_OVERSCAN;
516
+ exports.alignedOffset = require_pure.alignedOffset;
517
+ exports.anchoredStart = require_pure.anchoredStart;
518
+ exports.captureAnchor = require_pure.captureAnchor;
519
+ exports.columnWindow = require_pure_headers.columnWindow;
520
+ exports.columnWindowFromIndex = require_pure_headers.columnWindowFromIndex;
521
+ exports.computeRange = require_measure.computeRange;
522
+ exports.createSheetSizeIndex = require_pure.createSheetSizeIndex;
523
+ exports.createSizeIndex = require_measure.createSizeIndex;
524
+ exports.createVirtualizer = createVirtualizer;
525
+ exports.defaultRangeExtractor = require_pure.defaultRangeExtractor;
526
+ exports.gridCells = require_pure.gridCells;
527
+ exports.gridWindow = require_pure.gridWindow;
528
+ exports.groupedHeaders = require_pure_headers.groupedHeaders;
529
+ exports.headerBand = require_pure_headers.headerBand;
530
+ exports.keepMounted = require_pure.keepMounted;
531
+ exports.normalizeIndices = require_pure.normalizeIndices;
532
+ exports.restoreAnchor = require_pure.restoreAnchor;
533
+ exports.stickyColumnOffsets = require_pure_headers.stickyColumnOffsets;
534
+ exports.stickyTrailingColumnOffsets = require_pure_headers.stickyTrailingColumnOffsets;
535
+ exports.toRangeIndex = require_measure.toRangeIndex;
536
+ exports.trackOf = require_pure.trackOf;
537
+ exports.withStickyIndices = require_pure.withStickyIndices;
@@ -0,0 +1,110 @@
1
+ import { _ as withStickyIndices, a as anchoredStart, c as trackOf, d as createSheetSizeIndex, f as ExtractContext, g as normalizeIndices, h as keepMounted, i as alignedOffset, l as SheetSizeIndex, m as defaultRangeExtractor, n as View, o as captureAnchor, p as RangeExtractor, r as VirtualizerAlign, s as restoreAnchor, t as Anchor, u as SheetSizeIndexOptions } from "../index-D_M9i1VO.cjs";
2
+ import { ColumnWindow, ColumnWindowOptions, HeaderBand, HeaderBandOptions, HeaderGroup, HeaderRow, ResolvedHeaderGroup, StickyColumnOffset, StickyColumnWidths, columnWindow, columnWindowFromIndex, groupedHeaders, headerBand, stickyColumnOffsets, stickyTrailingColumnOffsets } from "../pure/headers.cjs";
3
+ import { a as SizeSource, c as SizeIndex, d as toRangeIndex, f as DEFAULT_OVERSCAN, g as computeRange, h as RangeInput, i as GridWindowOptions, l as SizeIndexOptions, m as RangeIndex, n as GridCell, o as gridCells, p as Range, r as GridWindow, s as gridWindow, t as FrozenEdges, u as createSizeIndex } from "../grid-BzP7CurM.cjs";
4
+ import { Axis, Size } from "@bevelo/runtime/geometry";
5
+ import { FrameLoop } from "@bevelo/runtime";
6
+ import { TrackSource } from "@bevelo/runtime/scroll";
7
+ import { ReadableStore } from "@bevelo/runtime/store";
8
+ /** What a virtualizer windows and how. Passed whole to `createVirtualizer` and to every `update`. */
9
+ interface VirtualizerOptions {
10
+ /** Element, window, or a getter resolved lazily (refs). null: not mounted (SSR uses initialRect). */
11
+ readonly scroller: Element | Window | null | (() => Element | Window | null);
12
+ /** The list element when the scroller is an ancestor or the window; scrollMargin is then measured. */
13
+ readonly element?: Element | null | (() => Element | null);
14
+ /** The scroll axis; default "y". */
15
+ readonly axis?: Axis;
16
+ /** How many items the list has. */
17
+ readonly count: number;
18
+ /** The key of item `index`. Sizes and the scroll anchor follow keys, not indexes. */
19
+ readonly key: (index: number) => string;
20
+ /** The size of an item not measured yet. */
21
+ readonly estimate: number | ((index: number) => number);
22
+ /** Equal-width lanes; a row is as tall as its tallest item. Default 1. */
23
+ readonly lanes?: number;
24
+ /** Pixels between rows. */
25
+ readonly gap?: number;
26
+ /** Extra rows rendered on each side of the view; default 2. */
27
+ readonly overscan?: number;
28
+ /** Explicit override of the measured margin: content pixels before the list. */
29
+ readonly scrollMargin?: number;
30
+ /** Parts of the view covered by sticky chrome; scrolls to an item keep it clear of them. */
31
+ readonly padding?: {
32
+ readonly start?: number;
33
+ readonly end?: number;
34
+ };
35
+ /** Indexes always rendered, flagged sticky. */
36
+ readonly sticky?: readonly number[];
37
+ /** Replaces the default extractor; sticky and retained indexes still apply. */
38
+ readonly extract?: RangeExtractor;
39
+ /** "end": start at the end and follow appends and growth while at the end. Default "start". */
40
+ readonly anchor?: "start" | "end";
41
+ /** How close to the end, in px, still counts as at the end; default 2. */
42
+ readonly atEndThreshold?: number;
43
+ /** The viewport size before the scroller can be read (server render, first frame). */
44
+ readonly initialRect?: Size;
45
+ /** The first offset; "end" by default when `anchor` is "end". */
46
+ readonly initialOffset?: number | "end";
47
+ /** Called when index 0 enters the overscan band; re-armed by a count change. */
48
+ readonly onReachStart?: () => void;
49
+ /** Called when the last index enters the overscan band; re-armed by a count change. */
50
+ readonly onReachEnd?: () => void;
51
+ /** The frame loop; default the scroller document's runtime frame. */
52
+ readonly frame?: FrameLoop;
53
+ }
54
+ /** One rendered item. Offsets are list-relative: 0 is the list's start, margin excluded. */
55
+ interface VirtualItem {
56
+ readonly key: string;
57
+ readonly index: number;
58
+ /** Start of the item's row along the axis. */
59
+ readonly start: number;
60
+ readonly size: number;
61
+ readonly end: number;
62
+ readonly lane: number;
63
+ readonly sticky: boolean;
64
+ /** Rendered only because of `retain()`. */
65
+ readonly retained: boolean;
66
+ }
67
+ /** What a frame of the virtualizer renders. */
68
+ interface VirtualSnapshot {
69
+ readonly items: readonly VirtualItem[];
70
+ readonly range: Range;
71
+ /** The list's size along the axis; size its spacer with it. */
72
+ readonly total: number;
73
+ readonly scrolling: boolean;
74
+ readonly atEnd: boolean;
75
+ }
76
+ /** Options of the scroll methods that bring an item into view. */
77
+ interface ScrollToItemOptions {
78
+ readonly align?: VirtualizerAlign;
79
+ readonly behavior?: ScrollBehavior;
80
+ }
81
+ /** The handle `createVirtualizer` returns. */
82
+ interface Virtualizer extends ReadableStore<VirtualSnapshot> {
83
+ /** Idempotent; count or key changes run anchoring. Call it with the latest options on every render. */
84
+ update(options: VirtualizerOptions): void;
85
+ /** Stable ref callback for rendered items; reads `data-key` when a size arrives. */
86
+ readonly measure: (el: Element | null) => void;
87
+ scrollToIndex(index: number, options?: ScrollToItemOptions): void;
88
+ scrollToKey(key: string, options?: ScrollToItemOptions): void;
89
+ /** Scrolls to a list-relative offset. */
90
+ scrollToOffset(offset: number, options?: {
91
+ behavior?: ScrollBehavior;
92
+ }): void;
93
+ scrollToEnd(options?: {
94
+ behavior?: ScrollBehavior;
95
+ }): void;
96
+ /** Keeps these keys rendered until the returned release runs (focus, drag); ref-counted. */
97
+ retain(keys: readonly string[]): () => void;
98
+ /** The track a dnd zone reads: every row, mounted or not. */
99
+ readonly source: TrackSource;
100
+ dispose(): void;
101
+ }
102
+ /**
103
+ * Creates a virtualizer. Without a scroller (a server render, a ref not attached yet) the
104
+ * snapshot is computed from `initialRect` and `initialOffset`; the engine binds to the
105
+ * scroller on the first `update`, `measure` or scroll call that resolves one.
106
+ *
107
+ * The scroller should have `overflow-anchor: none`: the engine keeps the view still itself.
108
+ */
109
+ export declare function createVirtualizer(initial: VirtualizerOptions): Virtualizer;
110
+ export { type Anchor, ColumnWindow, ColumnWindowOptions, DEFAULT_OVERSCAN, type ExtractContext, type FrozenEdges, type GridCell, type GridWindow, type GridWindowOptions, HeaderBand, HeaderBandOptions, HeaderGroup, HeaderRow, type Range, type RangeExtractor, type RangeIndex, type RangeInput, ResolvedHeaderGroup, type ScrollToItemOptions, type SheetSizeIndex, type SheetSizeIndexOptions, type SizeIndex, type SizeIndexOptions, type SizeSource, StickyColumnOffset, StickyColumnWidths, type View, type VirtualItem, type VirtualSnapshot, type Virtualizer, type VirtualizerAlign, type VirtualizerOptions, alignedOffset, anchoredStart, captureAnchor, columnWindow, columnWindowFromIndex, computeRange, createSheetSizeIndex, createSizeIndex, defaultRangeExtractor, gridCells, gridWindow, groupedHeaders, headerBand, keepMounted, normalizeIndices, restoreAnchor, stickyColumnOffsets, stickyTrailingColumnOffsets, toRangeIndex, trackOf, withStickyIndices };