@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,133 @@
1
+ import { c as SizeIndex, p as Range } from "./grid-BzP7CurM.js";
2
+ import { ItemTrack } from "@bevelo/runtime/geometry";
3
+ /**
4
+ * What an extractor is told about the frame.
5
+ *
6
+ * `count` is passed as well as the range because the interesting extras are usually at the
7
+ * edges — index 0, the last index — and an extractor that only saw the range would have to
8
+ * be closed over the data instead, which is the stale-count bug this avoids.
9
+ */
10
+ interface ExtractContext {
11
+ readonly range: Range;
12
+ readonly count: number;
13
+ }
14
+ /**
15
+ * A policy over the window: the indices to render, in any order.
16
+ *
17
+ * Duplicates are removed and the result is sorted before use, so an extractor may union its
18
+ * extras with the window's indices without de-duplicating by hand — which is exactly what
19
+ * {@link withStickyIndices} does.
20
+ */
21
+ type RangeExtractor = (context: ExtractContext) => readonly number[];
22
+ /** The window's own indices: `start` to `end - 1`. */
23
+ declare function defaultRangeExtractor({ range }: ExtractContext): readonly number[];
24
+ /**
25
+ * An extractor that renders the window plus a fixed set of indices, wherever they are.
26
+ *
27
+ * This is the sticky-header case: row 0 scrolls out of the window but must stay mounted to
28
+ * be pinned, and every other renderer of the window would have dropped it. The sticky
29
+ * indices are not repositioned — a pinned row is positioned by its host, and pre-clamping
30
+ * them into the window would fight the pin.
31
+ *
32
+ * Out-of-range and non-integer sticky indices are dropped rather than rendering a row for
33
+ * an item that does not exist; a negative or NaN index arrives from a config that went
34
+ * stale between renders, not from a host that meant it. Answers are normalised, so a pinned
35
+ * row the window has already reached appears once.
36
+ */
37
+ declare function withStickyIndices(sticky: readonly number[]): RangeExtractor;
38
+ /**
39
+ * An extractor that always includes the given indices when they exist, and otherwise
40
+ * behaves as the default. Same as {@link withStickyIndices} with a shorter name for the
41
+ * common "keep these mounted" use: a focused row, a row holding an open editor.
42
+ */
43
+ declare const keepMounted: typeof withStickyIndices;
44
+ /**
45
+ * Normalises an extractor's answer: in-range integers, ascending, de-duplicated.
46
+ *
47
+ * A host's extractor is arbitrary code over arbitrary data, so the renderer cannot assume
48
+ * anything about its answer. The alternative — trusting it — turns one bad index into a
49
+ * row for an item that does not exist, and that shows up as a crash inside a component
50
+ * rather than as a wrong window here.
51
+ */
52
+ declare function normalizeIndices(indices: readonly number[], count: number): readonly number[];
53
+ /** Options for {@link createSheetSizeIndex}. */
54
+ interface SheetSizeIndexOptions {
55
+ readonly count: number;
56
+ readonly defaultSize: number;
57
+ readonly sizes?: ((index: number) => number | undefined) | undefined;
58
+ }
59
+ /** Dynamic prefix-sum size index for spreadsheets with structural row/column edits. */
60
+ interface SheetSizeIndex extends SizeIndex {
61
+ readonly defaultSize: number;
62
+ insert(at: number, count: number, sizes?: readonly (number | undefined)[]): void;
63
+ remove(at: number, count: number): void;
64
+ move(from: number, to: number, count?: number): void;
65
+ }
66
+ /** Creates a mutable prefix-sum index with incremental structural updates. */
67
+ declare function createSheetSizeIndex(options: SheetSizeIndexOptions): SheetSizeIndex;
68
+ /**
69
+ * Where an item lands in the view when a scroll brings it in. `auto` scrolls only when the
70
+ * item is not fully visible, by the smallest distance.
71
+ * @stable — follows semver.
72
+ */
73
+ type VirtualizerAlign = "start" | "center" | "end" | "auto";
74
+ /**
75
+ * @experimental — may change in any minor release.
76
+ * The entry under the view's start edge, by key, and how far into it the edge sits. A key
77
+ * survives a prepend that shifts every index.
78
+ */
79
+ interface Anchor {
80
+ readonly key: string;
81
+ readonly within: number;
82
+ }
83
+ /**
84
+ * @experimental — may change in any minor release.
85
+ * The visible extent along the list's axis: `start` is the scroll offset minus the scroll
86
+ * margin, `size` the viewport extent.
87
+ */
88
+ interface View {
89
+ readonly start: number;
90
+ readonly size: number;
91
+ }
92
+ /**
93
+ * @experimental — may change in any minor release.
94
+ * The anchor for `view`: the entry at its start edge. Null when the index is empty.
95
+ */
96
+ declare function captureAnchor(index: SizeIndex, keyAt: (i: number) => string, view: View): Anchor | null;
97
+ /**
98
+ * @experimental — may change in any minor release.
99
+ * New scroll start that puts anchor.key back where it was; null when the key is gone.
100
+ */
101
+ declare function restoreAnchor(anchor: Anchor, index: SizeIndex, indexOf: (key: string) => number): number | null;
102
+ /**
103
+ * @experimental — may change in any minor release.
104
+ * Follow the new end when the view was at the end before the change, else restore the anchor.
105
+ * `mode: "start"` never follows. A missing anchor or key keeps `view.start`. The answer is
106
+ * clamped to the scrollable range.
107
+ */
108
+ declare function anchoredStart(input: {
109
+ mode: "start" | "end";
110
+ wasAtEnd: boolean;
111
+ anchor: Anchor | null;
112
+ index: SizeIndex;
113
+ view: View;
114
+ indexOf: (key: string) => number;
115
+ }): number;
116
+ /**
117
+ * @experimental — may change in any minor release.
118
+ * The view start that shows entry `i` with `align`. `padding` is the part of the view that
119
+ * sticky chrome covers at each edge, so alignment keeps the entry clear of it. An entry larger
120
+ * than the uncovered view aligns to its start under `auto`. Clamped to the scrollable range.
121
+ */
122
+ declare function alignedOffset(index: SizeIndex, i: number, align: VirtualizerAlign, view: View, padding: {
123
+ start: number;
124
+ end: number;
125
+ }): number;
126
+ /**
127
+ * @experimental — may change in any minor release.
128
+ * A SizeIndex plus keys seen as an ItemTrack. The index holds one entry per row of `lanes`
129
+ * slots; `keyAt` and `indexOf` answer per slot. `count` defaults to every row full, and
130
+ * `sizeOf` to the row's size, for a caller that keeps per-slot sizes elsewhere.
131
+ */
132
+ declare function trackOf(index: SizeIndex, keyAt: (i: number) => string, indexOf: (key: string) => number, lanes: number, version: number, count?: number, sizeOf?: (i: number) => number): ItemTrack;
133
+ export { withStickyIndices as _, anchoredStart as a, trackOf as c, createSheetSizeIndex as d, ExtractContext as f, normalizeIndices as g, keepMounted as h, alignedOffset as i, SheetSizeIndex as l, defaultRangeExtractor as m, View as n, captureAnchor as o, RangeExtractor as p, VirtualizerAlign as r, restoreAnchor as s, Anchor as t, SheetSizeIndexOptions as u };
@@ -0,0 +1,133 @@
1
+ import { c as SizeIndex, p as Range } from "./grid-BzP7CurM.cjs";
2
+ import { ItemTrack } from "@bevelo/runtime/geometry";
3
+ /**
4
+ * What an extractor is told about the frame.
5
+ *
6
+ * `count` is passed as well as the range because the interesting extras are usually at the
7
+ * edges — index 0, the last index — and an extractor that only saw the range would have to
8
+ * be closed over the data instead, which is the stale-count bug this avoids.
9
+ */
10
+ interface ExtractContext {
11
+ readonly range: Range;
12
+ readonly count: number;
13
+ }
14
+ /**
15
+ * A policy over the window: the indices to render, in any order.
16
+ *
17
+ * Duplicates are removed and the result is sorted before use, so an extractor may union its
18
+ * extras with the window's indices without de-duplicating by hand — which is exactly what
19
+ * {@link withStickyIndices} does.
20
+ */
21
+ type RangeExtractor = (context: ExtractContext) => readonly number[];
22
+ /** The window's own indices: `start` to `end - 1`. */
23
+ declare function defaultRangeExtractor({ range }: ExtractContext): readonly number[];
24
+ /**
25
+ * An extractor that renders the window plus a fixed set of indices, wherever they are.
26
+ *
27
+ * This is the sticky-header case: row 0 scrolls out of the window but must stay mounted to
28
+ * be pinned, and every other renderer of the window would have dropped it. The sticky
29
+ * indices are not repositioned — a pinned row is positioned by its host, and pre-clamping
30
+ * them into the window would fight the pin.
31
+ *
32
+ * Out-of-range and non-integer sticky indices are dropped rather than rendering a row for
33
+ * an item that does not exist; a negative or NaN index arrives from a config that went
34
+ * stale between renders, not from a host that meant it. Answers are normalised, so a pinned
35
+ * row the window has already reached appears once.
36
+ */
37
+ declare function withStickyIndices(sticky: readonly number[]): RangeExtractor;
38
+ /**
39
+ * An extractor that always includes the given indices when they exist, and otherwise
40
+ * behaves as the default. Same as {@link withStickyIndices} with a shorter name for the
41
+ * common "keep these mounted" use: a focused row, a row holding an open editor.
42
+ */
43
+ declare const keepMounted: typeof withStickyIndices;
44
+ /**
45
+ * Normalises an extractor's answer: in-range integers, ascending, de-duplicated.
46
+ *
47
+ * A host's extractor is arbitrary code over arbitrary data, so the renderer cannot assume
48
+ * anything about its answer. The alternative — trusting it — turns one bad index into a
49
+ * row for an item that does not exist, and that shows up as a crash inside a component
50
+ * rather than as a wrong window here.
51
+ */
52
+ declare function normalizeIndices(indices: readonly number[], count: number): readonly number[];
53
+ /** Options for {@link createSheetSizeIndex}. */
54
+ interface SheetSizeIndexOptions {
55
+ readonly count: number;
56
+ readonly defaultSize: number;
57
+ readonly sizes?: ((index: number) => number | undefined) | undefined;
58
+ }
59
+ /** Dynamic prefix-sum size index for spreadsheets with structural row/column edits. */
60
+ interface SheetSizeIndex extends SizeIndex {
61
+ readonly defaultSize: number;
62
+ insert(at: number, count: number, sizes?: readonly (number | undefined)[]): void;
63
+ remove(at: number, count: number): void;
64
+ move(from: number, to: number, count?: number): void;
65
+ }
66
+ /** Creates a mutable prefix-sum index with incremental structural updates. */
67
+ declare function createSheetSizeIndex(options: SheetSizeIndexOptions): SheetSizeIndex;
68
+ /**
69
+ * Where an item lands in the view when a scroll brings it in. `auto` scrolls only when the
70
+ * item is not fully visible, by the smallest distance.
71
+ * @stable — follows semver.
72
+ */
73
+ type VirtualizerAlign = "start" | "center" | "end" | "auto";
74
+ /**
75
+ * @experimental — may change in any minor release.
76
+ * The entry under the view's start edge, by key, and how far into it the edge sits. A key
77
+ * survives a prepend that shifts every index.
78
+ */
79
+ interface Anchor {
80
+ readonly key: string;
81
+ readonly within: number;
82
+ }
83
+ /**
84
+ * @experimental — may change in any minor release.
85
+ * The visible extent along the list's axis: `start` is the scroll offset minus the scroll
86
+ * margin, `size` the viewport extent.
87
+ */
88
+ interface View {
89
+ readonly start: number;
90
+ readonly size: number;
91
+ }
92
+ /**
93
+ * @experimental — may change in any minor release.
94
+ * The anchor for `view`: the entry at its start edge. Null when the index is empty.
95
+ */
96
+ declare function captureAnchor(index: SizeIndex, keyAt: (i: number) => string, view: View): Anchor | null;
97
+ /**
98
+ * @experimental — may change in any minor release.
99
+ * New scroll start that puts anchor.key back where it was; null when the key is gone.
100
+ */
101
+ declare function restoreAnchor(anchor: Anchor, index: SizeIndex, indexOf: (key: string) => number): number | null;
102
+ /**
103
+ * @experimental — may change in any minor release.
104
+ * Follow the new end when the view was at the end before the change, else restore the anchor.
105
+ * `mode: "start"` never follows. A missing anchor or key keeps `view.start`. The answer is
106
+ * clamped to the scrollable range.
107
+ */
108
+ declare function anchoredStart(input: {
109
+ mode: "start" | "end";
110
+ wasAtEnd: boolean;
111
+ anchor: Anchor | null;
112
+ index: SizeIndex;
113
+ view: View;
114
+ indexOf: (key: string) => number;
115
+ }): number;
116
+ /**
117
+ * @experimental — may change in any minor release.
118
+ * The view start that shows entry `i` with `align`. `padding` is the part of the view that
119
+ * sticky chrome covers at each edge, so alignment keeps the entry clear of it. An entry larger
120
+ * than the uncovered view aligns to its start under `auto`. Clamped to the scrollable range.
121
+ */
122
+ declare function alignedOffset(index: SizeIndex, i: number, align: VirtualizerAlign, view: View, padding: {
123
+ start: number;
124
+ end: number;
125
+ }): number;
126
+ /**
127
+ * @experimental — may change in any minor release.
128
+ * A SizeIndex plus keys seen as an ItemTrack. The index holds one entry per row of `lanes`
129
+ * slots; `keyAt` and `indexOf` answer per slot. `count` defaults to every row full, and
130
+ * `sizeOf` to the row's size, for a caller that keeps per-slot sizes elsewhere.
131
+ */
132
+ declare function trackOf(index: SizeIndex, keyAt: (i: number) => string, indexOf: (key: string) => number, lanes: number, version: number, count?: number, sizeOf?: (i: number) => number): ItemTrack;
133
+ export { withStickyIndices as _, anchoredStart as a, trackOf as c, createSheetSizeIndex as d, ExtractContext as f, normalizeIndices as g, keepMounted as h, alignedOffset as i, SheetSizeIndex as l, defaultRangeExtractor as m, View as n, captureAnchor as o, RangeExtractor as p, VirtualizerAlign as r, restoreAnchor as s, Anchor as t, SheetSizeIndexOptions as u };