zidane-ui 9.2.3 → 9.3.1
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/adapters/live.d.ts +6 -0
- package/dist/adapters/live.js +16 -8
- package/dist/adapters/server-composer-host.js +22 -9
- package/dist/adapters/server-host.js +143 -18
- package/dist/adapters/server-media.d.ts +9 -1
- package/dist/adapters/server-media.js +14 -1
- package/dist/chat/HostTranscript.d.ts +0 -12
- package/dist/chat/HostTranscript.js +6 -1
- package/dist/chat/SessionStreamsProvider.d.ts +8 -0
- package/dist/chat/SessionStreamsProvider.js +11 -2
- package/dist/chat/Transcript.d.ts +20 -11
- package/dist/chat/Transcript.js +326 -160
- package/dist/chat/composer/ComposerEditor.js +1 -1
- package/dist/chat/headless/host.d.ts +43 -7
- package/dist/chat/headless/index.d.ts +7 -6
- package/dist/chat/headless/index.js +10 -9
- package/dist/chat/headless/labels.d.ts +17 -0
- package/dist/chat/headless/labels.js +17 -0
- package/dist/chat/headless/markdown-chunks.d.ts +2 -1
- package/dist/chat/headless/markdown-chunks.js +12 -20
- package/dist/chat/headless/markdown-scan.d.ts +66 -0
- package/dist/chat/headless/markdown-scan.js +124 -0
- package/dist/chat/headless/markdown-stream.d.ts +64 -0
- package/dist/chat/headless/markdown-stream.js +143 -0
- package/dist/chat/headless/output-pager.d.ts +68 -0
- package/dist/chat/headless/output-pager.js +113 -0
- package/dist/chat/headless/session-list.d.ts +10 -0
- package/dist/chat/headless/sidebar/activity.d.ts +14 -0
- package/dist/chat/headless/sidebar/activity.js +32 -0
- package/dist/chat/headless/sidebar/directory.d.ts +9 -1
- package/dist/chat/headless/sidebar/directory.js +10 -50
- package/dist/chat/headless/sidebar/labels.d.ts +11 -1
- package/dist/chat/headless/sidebar/prewarm.d.ts +68 -0
- package/dist/chat/headless/sidebar/prewarm.js +114 -0
- package/dist/chat/headless/streams/actions.d.ts +2 -0
- package/dist/chat/headless/streams/actions.js +1 -0
- package/dist/chat/headless/streams/event-bytes.d.ts +6 -0
- package/dist/chat/headless/streams/event-bytes.js +34 -0
- package/dist/chat/headless/streams/live-events.d.ts +25 -1
- package/dist/chat/headless/streams/live-events.js +53 -2
- package/dist/chat/headless/streams/selectors.d.ts +3 -0
- package/dist/chat/headless/streams/selectors.js +8 -1
- package/dist/chat/headless/streams/session-streams.d.ts +15 -3
- package/dist/chat/headless/streams/session-streams.js +31 -3
- package/dist/chat/headless/streams/store.d.ts +24 -1
- package/dist/chat/headless/streams/store.js +51 -26
- package/dist/chat/headless/streams/transcript-map.d.ts +57 -0
- package/dist/chat/headless/streams/transcript-map.js +88 -0
- package/dist/chat/headless/streams/transcript.d.ts +4 -2
- package/dist/chat/headless/streams/transcript.js +19 -7
- package/dist/chat/headless/transcript/batch.js +5 -1
- package/dist/chat/headless/transcript/blob-media.d.ts +15 -0
- package/dist/chat/headless/transcript/blob-media.js +23 -0
- package/dist/chat/headless/transcript/collapse.d.ts +10 -0
- package/dist/chat/headless/transcript/collapse.js +32 -6
- package/dist/chat/headless/transcript/derive.d.ts +98 -0
- package/dist/chat/headless/transcript/derive.js +89 -0
- package/dist/chat/headless/transcript/exchange-media.d.ts +3 -1
- package/dist/chat/headless/transcript/exchange-media.js +8 -5
- package/dist/chat/headless/transcript/fold-attachments.d.ts +2 -0
- package/dist/chat/headless/transcript/fold-attachments.js +3 -2
- package/dist/chat/headless/transcript/fold.d.ts +2 -1
- package/dist/chat/headless/transcript/fold.js +16 -6
- package/dist/chat/headless/transcript/incremental.d.ts +53 -0
- package/dist/chat/headless/transcript/incremental.js +181 -0
- package/dist/chat/headless/transcript/index.d.ts +2 -2
- package/dist/chat/headless/transcript/index.js +2 -2
- package/dist/chat/headless/transcript/nesting.js +2 -1
- package/dist/chat/headless/transcript/rail.d.ts +50 -1
- package/dist/chat/headless/transcript/rail.js +165 -23
- package/dist/chat/headless/transcript/rows.d.ts +5 -1
- package/dist/chat/headless/transcript/run-failures.js +2 -1
- package/dist/chat/headless/transcript/seams.d.ts +78 -0
- package/dist/chat/headless/transcript/seams.js +116 -0
- package/dist/chat/headless/transcript/tool-media.d.ts +6 -7
- package/dist/chat/headless/transcript/tool-media.js +27 -9
- package/dist/chat/index.d.ts +8 -7
- package/dist/chat/index.js +17 -16
- package/dist/chat/sidebar/SidebarFooter.d.ts +8 -5
- package/dist/chat/sidebar/SidebarFooter.js +6 -6
- package/dist/chat/testing/contract.d.ts +5 -3
- package/dist/chat/testing/contract.js +66 -1
- package/dist/chat/transcript/DiffLines.d.ts +6 -1
- package/dist/chat/transcript/DiffLines.js +35 -20
- package/dist/chat/transcript/EditDiffBlock.d.ts +5 -1
- package/dist/chat/transcript/EditDiffBlock.js +89 -30
- package/dist/chat/transcript/LazyRow.d.ts +40 -40
- package/dist/chat/transcript/LazyRow.js +101 -149
- package/dist/chat/transcript/MermaidDiagram.js +2 -1
- package/dist/chat/transcript/SubagentBlock.js +3 -2
- package/dist/chat/transcript/TranscriptRail.d.ts +25 -2
- package/dist/chat/transcript/TranscriptRail.js +175 -17
- package/dist/chat/transcript/TranscriptRow.d.ts +4 -7
- package/dist/chat/transcript/TranscriptRow.js +4 -3
- package/dist/chat/transcript/actions.d.ts +37 -1
- package/dist/chat/transcript/actions.js +27 -1
- package/dist/chat/transcript/clipped-output.d.ts +58 -0
- package/dist/chat/transcript/clipped-output.js +131 -0
- package/dist/chat/transcript/fold-attachments.js +10 -5
- package/dist/chat/transcript/fold-worker.js +3 -2
- package/dist/chat/transcript/fold.js +2 -1
- package/dist/chat/transcript/index.d.ts +10 -9
- package/dist/chat/transcript/index.js +9 -8
- package/dist/chat/transcript/markdown-cache.d.ts +7 -1
- package/dist/chat/transcript/markdown-cache.js +12 -1
- package/dist/chat/transcript/markdown.js +116 -54
- package/dist/chat/transcript/media-gallery.d.ts +3 -2
- package/dist/chat/transcript/media-gallery.js +10 -7
- package/dist/chat/transcript/notices.js +2 -1
- package/dist/chat/transcript/prompt.js +6 -4
- package/dist/chat/transcript/prose.js +2 -1
- package/dist/chat/transcript/root-items.d.ts +96 -0
- package/dist/chat/transcript/root-items.js +180 -0
- package/dist/chat/transcript/row-mount.d.ts +165 -0
- package/dist/chat/transcript/row-mount.js +498 -0
- package/dist/chat/transcript/row-parking.d.ts +125 -0
- package/dist/chat/transcript/row-parking.js +135 -0
- package/dist/chat/transcript/row-ui-state.d.ts +37 -0
- package/dist/chat/transcript/row-ui-state.js +53 -0
- package/dist/chat/transcript/run-rows.js +3 -2
- package/dist/chat/transcript/script-input.d.ts +1 -1
- package/dist/chat/transcript/tasks.js +3 -2
- package/dist/chat/transcript/tool-media.d.ts +4 -2
- package/dist/chat/transcript/tool-media.js +15 -7
- package/dist/chat/transcript/tool-parts.d.ts +27 -4
- package/dist/chat/transcript/tool-parts.js +31 -5
- package/dist/chat/transcript/tool-payload.js +26 -11
- package/dist/chat/transcript/tool-row.d.ts +2 -1
- package/dist/chat/transcript/tool-row.js +38 -19
- package/dist/chat/transcript/use-transcript-rows.d.ts +24 -7
- package/dist/chat/transcript/use-transcript-rows.js +28 -46
- package/dist/chat/transcript/useStickToBottom.js +2 -3
- package/dist/chat/transcript/useTranscriptSearch.js +30 -14
- package/dist/chat/transcript/view-scope.d.ts +26 -6
- package/dist/chat/transcript/view-scope.js +106 -20
- package/dist/dist/{index-E1Z0aPmi.d.ts → index-C6-t1SS9.d.ts} +2 -1
- package/dist/dist/index.d.ts +1 -1
- package/dist/session/SessionHeader.js +1 -0
- package/dist/settings/headless/fixture-performance.js +4 -2
- package/dist/settings/headless/performance.d.ts +4 -0
- package/dist/settings/headless/search.d.ts +1 -1
- package/dist/settings/sections/performance/PerformanceSection.js +8 -1
- package/dist/settings/sections/performance/labels.d.ts +2 -0
- package/dist/settings/sections/performance/labels.js +2 -0
- package/dist/styles.css +33 -2
- package/dist/views/headless/answers.d.ts +8 -2
- package/dist/views/headless/answers.js +58 -1
- package/dist/views/headless/placement.d.ts +78 -0
- package/dist/views/headless/placement.js +154 -44
- package/package.json +2 -2
- package/src/styles/transcript.css +33 -2
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
import { scrollRootOf } from "../../hooks/useNearViewport.js";
|
|
2
|
+
import { createRecentMap } from "./recent-map.js";
|
|
3
|
+
import { PARK_IDLE_MS, idleWait, keepsSize, parkCandidates, parkPlan, pumpOrder } from "./row-parking.js";
|
|
4
|
+
import { createContext } from "react";
|
|
5
|
+
import { flushSync } from "react-dom";
|
|
6
|
+
// src/chat/transcript/row-mount.ts
|
|
7
|
+
/** Far enough ahead that a fast flick finds rows mounted before they arrive. */
|
|
8
|
+
const MARGIN = "2500px 0px";
|
|
9
|
+
/** Within this, a row mounts right away (and, without state events, counts as rendered). */
|
|
10
|
+
const NEAR_MARGIN = "100% 0px";
|
|
11
|
+
/** Main-thread time a frame may spend mounting rows ahead of the view. */
|
|
12
|
+
const BUDGET_MS = 6;
|
|
13
|
+
/** Rows parked per commit inside a slice. */
|
|
14
|
+
const PARK_BATCH = 8;
|
|
15
|
+
/** Measured heights by session and row, across mounts and transcripts. */
|
|
16
|
+
const SIZES = createRecentMap(3e4);
|
|
17
|
+
/** Per scroll container: its transcript's mounter (see {@link revealRow}). */
|
|
18
|
+
const mounters = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
function hasCvEvents() {
|
|
20
|
+
return typeof window !== "undefined" && "ContentVisibilityAutoStateChangeEvent" in window;
|
|
21
|
+
}
|
|
22
|
+
function requestIdle(cb) {
|
|
23
|
+
if (typeof requestIdleCallback === "function") requestIdleCallback(cb, { timeout: 1e3 });
|
|
24
|
+
else setTimeout(cb, 0);
|
|
25
|
+
}
|
|
26
|
+
/** Keys that scroll the view (they count as the reader scrolling). */
|
|
27
|
+
const SCROLL_KEYS = /* @__PURE__ */ new Set([
|
|
28
|
+
"ArrowUp",
|
|
29
|
+
"ArrowDown",
|
|
30
|
+
"PageUp",
|
|
31
|
+
"PageDown",
|
|
32
|
+
"Home",
|
|
33
|
+
"End",
|
|
34
|
+
" "
|
|
35
|
+
]);
|
|
36
|
+
/** One transcript's root rows: what mounts, what parks, and their heights. */
|
|
37
|
+
var RowMounter = class {
|
|
38
|
+
scope = void 0;
|
|
39
|
+
slots = /* @__PURE__ */ new Map();
|
|
40
|
+
byEl = /* @__PURE__ */ new WeakMap();
|
|
41
|
+
/** The last phase of each key in this transcript: a wrapper made again starts from it. */
|
|
42
|
+
phases = /* @__PURE__ */ new Map();
|
|
43
|
+
eager = /* @__PURE__ */ new Set();
|
|
44
|
+
live = /* @__PURE__ */ new Set();
|
|
45
|
+
held = /* @__PURE__ */ new Set();
|
|
46
|
+
all = false;
|
|
47
|
+
reveals = [];
|
|
48
|
+
skipped = /* @__PURE__ */ new WeakMap();
|
|
49
|
+
/** Each mounted row's height as last laid out (its ResizeObserver entry): what a parked placeholder keeps. */
|
|
50
|
+
boxes = /* @__PURE__ */ new WeakMap();
|
|
51
|
+
near = /* @__PURE__ */ new WeakSet();
|
|
52
|
+
queue = /* @__PURE__ */ new Map();
|
|
53
|
+
mountedCount = 0;
|
|
54
|
+
timeline = null;
|
|
55
|
+
scroller = null;
|
|
56
|
+
far = null;
|
|
57
|
+
close = null;
|
|
58
|
+
ro = null;
|
|
59
|
+
cvEvents = hasCvEvents();
|
|
60
|
+
io = typeof IntersectionObserver !== "undefined";
|
|
61
|
+
pumpScheduled = false;
|
|
62
|
+
lastActivity = -Infinity;
|
|
63
|
+
direction = 0;
|
|
64
|
+
lastTop = 0;
|
|
65
|
+
parkTimer = null;
|
|
66
|
+
/** Rows mounted since the last parking pass found the transcript within budget. */
|
|
67
|
+
dirty = false;
|
|
68
|
+
parking = false;
|
|
69
|
+
detach = null;
|
|
70
|
+
/**
|
|
71
|
+
* The transcript shows `scope` (a session): another one forgets this one's phases and jumps.
|
|
72
|
+
*
|
|
73
|
+
* @param scope - The session shown.
|
|
74
|
+
*/
|
|
75
|
+
reset(scope) {
|
|
76
|
+
if (Object.is(scope, this.scope)) return;
|
|
77
|
+
this.scope = scope;
|
|
78
|
+
this.phases.clear();
|
|
79
|
+
this.reveals = [];
|
|
80
|
+
}
|
|
81
|
+
sizeKey(key) {
|
|
82
|
+
return `${String(this.scope)}\u0000${key}`;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The row's last true height, if it was ever measured rendered.
|
|
86
|
+
*
|
|
87
|
+
* @param key - The row's key.
|
|
88
|
+
*/
|
|
89
|
+
sizeOf(key) {
|
|
90
|
+
return SIZES.get(this.sizeKey(key));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* What the render holds as the tail (mounts with its first render) and the live exchange (never parks).
|
|
94
|
+
*
|
|
95
|
+
* @param eager - The tail's keys.
|
|
96
|
+
* @param live - The open exchange's keys.
|
|
97
|
+
*/
|
|
98
|
+
setTail(eager, live) {
|
|
99
|
+
this.eager = eager;
|
|
100
|
+
this.live = live;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* How a new wrapper for `key` starts.
|
|
104
|
+
*
|
|
105
|
+
* @param key - The row's key.
|
|
106
|
+
*/
|
|
107
|
+
start(key) {
|
|
108
|
+
const last = this.phases.get(key);
|
|
109
|
+
const eager = this.eager.has(key);
|
|
110
|
+
return {
|
|
111
|
+
mounted: !this.io || this.all || this.held.has(key) || eager || last === "mounted",
|
|
112
|
+
eager,
|
|
113
|
+
seen: last !== void 0
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Rows to mount wherever they are and keep mounted while held (a search's matches, the select cursor's turn).
|
|
118
|
+
* Call it from a layout effect: the rows render before the next paint.
|
|
119
|
+
*
|
|
120
|
+
* @param keys - The held rows.
|
|
121
|
+
* @param all - Every row (a search with no needle to narrow it).
|
|
122
|
+
*/
|
|
123
|
+
hold(keys, all) {
|
|
124
|
+
this.held = new Set(keys);
|
|
125
|
+
this.all = all;
|
|
126
|
+
const mount = all ? [...this.slots.values()] : keys.map((key) => this.slots.get(key)).filter((s) => s !== void 0);
|
|
127
|
+
for (const slot of mount) if (slot.phase !== "mounted") this.transition(slot, "mounted", false);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Mounts the row `key` now, wherever it is, and holds it a while (the last few jumps). Call it outside React's
|
|
131
|
+
* render and effects: it commits synchronously.
|
|
132
|
+
*
|
|
133
|
+
* @param key - The row's key.
|
|
134
|
+
* @returns Its wrapper, or null when this transcript has no such row.
|
|
135
|
+
*/
|
|
136
|
+
reveal(key) {
|
|
137
|
+
const slot = this.slots.get(key);
|
|
138
|
+
if (!slot) return null;
|
|
139
|
+
this.reveals = [...this.reveals.filter((k) => k !== key), key].slice(-4);
|
|
140
|
+
if (slot.phase !== "mounted") flushSync(() => this.transition(slot, "mounted", false));
|
|
141
|
+
return slot.el;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Mounts the rows within `px` above and below the root row holding `el` (by their heights now), so a jump to
|
|
145
|
+
* `el` lands among rows at their real heights: mounted after it, they would move it. The rows render with the
|
|
146
|
+
* next commit.
|
|
147
|
+
*
|
|
148
|
+
* @param el - An element inside a root row.
|
|
149
|
+
* @param px - How far each way.
|
|
150
|
+
* @returns Whether any row was not mounted.
|
|
151
|
+
*/
|
|
152
|
+
mountAround(el, px) {
|
|
153
|
+
const timeline = this.timeline;
|
|
154
|
+
let row = el;
|
|
155
|
+
while (row && row.parentElement !== timeline) row = row.parentElement;
|
|
156
|
+
if (!row || !timeline) return false;
|
|
157
|
+
const heightOf = (node) => {
|
|
158
|
+
const slot = this.byEl.get(node);
|
|
159
|
+
if (!slot) return 0;
|
|
160
|
+
return slot.phase === "mounted" ? this.boxes.get(node) ?? 0 : Number.parseFloat(slot.el.style.height) || 0;
|
|
161
|
+
};
|
|
162
|
+
const wake = [];
|
|
163
|
+
for (const step of ["previousElementSibling", "nextElementSibling"]) {
|
|
164
|
+
let room = px;
|
|
165
|
+
for (let node = row[step]; node && room > 0; node = node[step]) {
|
|
166
|
+
const slot = this.byEl.get(node);
|
|
167
|
+
if (slot && slot.phase !== "mounted") wake.push(slot);
|
|
168
|
+
room -= heightOf(node);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
for (const slot of wake) this.transition(slot, "mounted", false);
|
|
172
|
+
return wake.length > 0;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* A wrapper arrived (its layout effect): observe it, and queue it if it has not mounted.
|
|
176
|
+
*
|
|
177
|
+
* @param slot - The wrapper.
|
|
178
|
+
* @returns The stop.
|
|
179
|
+
*/
|
|
180
|
+
register(slot) {
|
|
181
|
+
this.ensure(slot.el);
|
|
182
|
+
this.slots.set(slot.key, slot);
|
|
183
|
+
this.byEl.set(slot.el, slot);
|
|
184
|
+
this.phases.set(slot.key, slot.phase);
|
|
185
|
+
if (slot.phase === "mounted") this.mounted(slot);
|
|
186
|
+
else this.observeApproach(slot);
|
|
187
|
+
if (!this.cvEvents) this.close?.observe(slot.el);
|
|
188
|
+
return () => {
|
|
189
|
+
if (this.slots.get(slot.key) === slot) this.slots.delete(slot.key);
|
|
190
|
+
if (slot.phase === "mounted") this.mountedCount--;
|
|
191
|
+
this.queue.delete(slot.el);
|
|
192
|
+
this.far?.unobserve(slot.el);
|
|
193
|
+
this.close?.unobserve(slot.el);
|
|
194
|
+
this.ro?.unobserve(slot.el);
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/** Stops observing (the transcript unmounted). */
|
|
198
|
+
dispose() {
|
|
199
|
+
this.detach?.();
|
|
200
|
+
this.detach = null;
|
|
201
|
+
}
|
|
202
|
+
ensure(el) {
|
|
203
|
+
if (this.detach) return;
|
|
204
|
+
const timeline = el.parentElement;
|
|
205
|
+
const scroller = scrollRootOf(el);
|
|
206
|
+
this.timeline = timeline;
|
|
207
|
+
this.scroller = scroller;
|
|
208
|
+
if (typeof ResizeObserver !== "undefined") this.ro = new ResizeObserver((entries) => this.onResize(entries));
|
|
209
|
+
if (this.io) {
|
|
210
|
+
this.far = new IntersectionObserver((entries) => this.onFar(entries), {
|
|
211
|
+
root: scroller,
|
|
212
|
+
rootMargin: MARGIN
|
|
213
|
+
});
|
|
214
|
+
this.close = new IntersectionObserver((entries) => this.onNear(entries), {
|
|
215
|
+
root: scroller,
|
|
216
|
+
rootMargin: NEAR_MARGIN
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
const onCv = (e) => this.onCvState(e);
|
|
220
|
+
const activity = () => {
|
|
221
|
+
this.lastActivity = performance.now();
|
|
222
|
+
};
|
|
223
|
+
const onKey = (e) => {
|
|
224
|
+
if (SCROLL_KEYS.has(e.key)) activity();
|
|
225
|
+
};
|
|
226
|
+
const onScroll = () => {
|
|
227
|
+
const sc = this.scroller;
|
|
228
|
+
if (!sc) return;
|
|
229
|
+
const top = sc.scrollTop;
|
|
230
|
+
if (top !== this.lastTop) this.direction = Math.sign(top - this.lastTop);
|
|
231
|
+
this.lastTop = top;
|
|
232
|
+
if (sc.scrollHeight - top - sc.clientHeight > 2) activity();
|
|
233
|
+
};
|
|
234
|
+
timeline?.addEventListener("contentvisibilityautostatechange", onCv, true);
|
|
235
|
+
const target = scroller ?? (typeof window !== "undefined" ? window : null);
|
|
236
|
+
target?.addEventListener("scroll", onScroll, { passive: true });
|
|
237
|
+
for (const type of [
|
|
238
|
+
"wheel",
|
|
239
|
+
"touchstart",
|
|
240
|
+
"touchmove",
|
|
241
|
+
"pointerdown"
|
|
242
|
+
]) target?.addEventListener(type, activity, { passive: true });
|
|
243
|
+
if (typeof window !== "undefined") window.addEventListener("keydown", onKey, true);
|
|
244
|
+
if (scroller) mounters.set(scroller, this);
|
|
245
|
+
this.detach = () => {
|
|
246
|
+
timeline?.removeEventListener("contentvisibilityautostatechange", onCv, true);
|
|
247
|
+
target?.removeEventListener("scroll", onScroll);
|
|
248
|
+
for (const type of [
|
|
249
|
+
"wheel",
|
|
250
|
+
"touchstart",
|
|
251
|
+
"touchmove",
|
|
252
|
+
"pointerdown"
|
|
253
|
+
]) target?.removeEventListener(type, activity);
|
|
254
|
+
if (typeof window !== "undefined") window.removeEventListener("keydown", onKey, true);
|
|
255
|
+
if (scroller && mounters.get(scroller) === this) mounters.delete(scroller);
|
|
256
|
+
this.far?.disconnect();
|
|
257
|
+
this.close?.disconnect();
|
|
258
|
+
this.ro?.disconnect();
|
|
259
|
+
this.far = this.close = this.ro = null;
|
|
260
|
+
this.queue.clear();
|
|
261
|
+
if (this.parkTimer) clearTimeout(this.parkTimer);
|
|
262
|
+
this.parkTimer = null;
|
|
263
|
+
this.timeline = this.scroller = null;
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
observeApproach(slot) {
|
|
267
|
+
this.far?.observe(slot.el);
|
|
268
|
+
if (this.cvEvents) this.close?.observe(slot.el);
|
|
269
|
+
}
|
|
270
|
+
mounted(slot) {
|
|
271
|
+
this.mountedCount++;
|
|
272
|
+
this.ro?.observe(slot.el);
|
|
273
|
+
this.far?.unobserve(slot.el);
|
|
274
|
+
if (this.cvEvents) this.close?.unobserve(slot.el);
|
|
275
|
+
this.queue.delete(slot.el);
|
|
276
|
+
this.dirty = true;
|
|
277
|
+
this.scheduleParking();
|
|
278
|
+
}
|
|
279
|
+
/** Moves a row to `phase` and renders it there. */
|
|
280
|
+
transition(slot, phase, background, parkedPx) {
|
|
281
|
+
if (slot.phase === phase) return;
|
|
282
|
+
const was = slot.phase;
|
|
283
|
+
slot.phase = phase;
|
|
284
|
+
this.phases.set(slot.key, phase);
|
|
285
|
+
if (phase === "mounted") this.mounted(slot);
|
|
286
|
+
else if (was === "mounted") {
|
|
287
|
+
this.mountedCount--;
|
|
288
|
+
this.ro?.unobserve(slot.el);
|
|
289
|
+
this.observeApproach(slot);
|
|
290
|
+
}
|
|
291
|
+
slot.set(phase, background, parkedPx);
|
|
292
|
+
}
|
|
293
|
+
onFar(entries) {
|
|
294
|
+
for (const entry of entries) {
|
|
295
|
+
const slot = this.byEl.get(entry.target);
|
|
296
|
+
if (entry.isIntersecting && slot && slot.phase !== "mounted") this.queue.set(entry.target, slot);
|
|
297
|
+
else if (!entry.isIntersecting) this.queue.delete(entry.target);
|
|
298
|
+
}
|
|
299
|
+
this.schedulePump();
|
|
300
|
+
}
|
|
301
|
+
onNear(entries) {
|
|
302
|
+
const now = [];
|
|
303
|
+
for (const entry of entries) {
|
|
304
|
+
const slot = this.byEl.get(entry.target);
|
|
305
|
+
if (!slot) continue;
|
|
306
|
+
if (!this.cvEvents) {
|
|
307
|
+
if (entry.isIntersecting) {
|
|
308
|
+
this.near.add(entry.target);
|
|
309
|
+
this.remeasure(slot);
|
|
310
|
+
} else this.near.delete(entry.target);
|
|
311
|
+
}
|
|
312
|
+
if (entry.isIntersecting && slot.phase !== "mounted") now.push(slot);
|
|
313
|
+
}
|
|
314
|
+
if (now.length > 0) flushSync(() => now.forEach((slot) => this.transition(slot, "mounted", false)));
|
|
315
|
+
}
|
|
316
|
+
onCvState(e) {
|
|
317
|
+
const slot = this.byEl.get(e.target);
|
|
318
|
+
if (!slot) return;
|
|
319
|
+
const skipped = e.skipped;
|
|
320
|
+
this.skipped.set(slot.el, skipped);
|
|
321
|
+
if (!skipped) this.remeasure(slot);
|
|
322
|
+
}
|
|
323
|
+
/** Observing again reports the row's size now: a row just rendered may have kept its placeholder's. */
|
|
324
|
+
remeasure(slot) {
|
|
325
|
+
if (slot.phase !== "mounted") return;
|
|
326
|
+
this.ro?.unobserve(slot.el);
|
|
327
|
+
this.ro?.observe(slot.el);
|
|
328
|
+
}
|
|
329
|
+
onResize(entries) {
|
|
330
|
+
for (const entry of entries) {
|
|
331
|
+
const slot = this.byEl.get(entry.target);
|
|
332
|
+
if (!slot) continue;
|
|
333
|
+
const size = entry.borderBoxSize?.[0]?.blockSize ?? slot.el.getBoundingClientRect().height;
|
|
334
|
+
this.boxes.set(slot.el, size);
|
|
335
|
+
if (!keepsSize({
|
|
336
|
+
mounted: slot.phase === "mounted",
|
|
337
|
+
cv: slot.cv,
|
|
338
|
+
skipped: this.skipped.get(slot.el) ?? null,
|
|
339
|
+
cvEvents: this.cvEvents,
|
|
340
|
+
nearView: this.near.has(slot.el)
|
|
341
|
+
})) continue;
|
|
342
|
+
if (size > 0) SIZES.set(this.sizeKey(slot.key), size);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
schedulePump() {
|
|
346
|
+
if (this.pumpScheduled || this.queue.size === 0) return;
|
|
347
|
+
this.pumpScheduled = true;
|
|
348
|
+
requestAnimationFrame(() => setTimeout(() => this.pump(), 0));
|
|
349
|
+
}
|
|
350
|
+
pump() {
|
|
351
|
+
this.pumpScheduled = false;
|
|
352
|
+
const rect = this.scroller?.getBoundingClientRect();
|
|
353
|
+
const [top, bottom] = rect ? [rect.top, rect.bottom] : [0, window.innerHeight];
|
|
354
|
+
const queued = [];
|
|
355
|
+
for (const [el, slot] of this.queue) {
|
|
356
|
+
if (!el.isConnected || slot.phase === "mounted") {
|
|
357
|
+
this.queue.delete(el);
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
const r = el.getBoundingClientRect();
|
|
361
|
+
const distance = r.bottom >= top && r.top <= bottom ? 0 : r.top > bottom ? r.top - bottom : top - r.bottom;
|
|
362
|
+
const ahead = this.direction === 0 || (this.direction < 0 ? r.bottom <= top : r.top >= bottom);
|
|
363
|
+
queued.push({
|
|
364
|
+
row: slot,
|
|
365
|
+
distance,
|
|
366
|
+
ahead
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
const { now, later } = pumpOrder(queued, bottom - top);
|
|
370
|
+
if (now.length > 0) flushSync(() => now.forEach((slot) => this.transition(slot, "mounted", false)));
|
|
371
|
+
const start = performance.now();
|
|
372
|
+
for (const slot of later) {
|
|
373
|
+
if (performance.now() - start > BUDGET_MS) break;
|
|
374
|
+
flushSync(() => this.transition(slot, "mounted", true));
|
|
375
|
+
}
|
|
376
|
+
this.schedulePump();
|
|
377
|
+
}
|
|
378
|
+
scheduleParking(delay = PARK_IDLE_MS) {
|
|
379
|
+
if (this.parkTimer !== null || this.parking || !this.timeline) return;
|
|
380
|
+
this.parkTimer = setTimeout(() => {
|
|
381
|
+
this.parkTimer = null;
|
|
382
|
+
this.whenIdle();
|
|
383
|
+
}, delay);
|
|
384
|
+
}
|
|
385
|
+
whenIdle() {
|
|
386
|
+
if (!this.dirty || !this.timeline) return;
|
|
387
|
+
const wait = idleWait(this.lastActivity, performance.now());
|
|
388
|
+
if (wait > 0) {
|
|
389
|
+
this.scheduleParking(wait);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
this.parking = true;
|
|
393
|
+
requestIdle(() => this.parkPass());
|
|
394
|
+
}
|
|
395
|
+
/** Whether a row must stay mounted now, wherever it is. */
|
|
396
|
+
isHeld(slot) {
|
|
397
|
+
if (this.all || this.held.has(slot.key) || this.live.has(slot.key) || this.eager.has(slot.key) || this.reveals.includes(slot.key)) return true;
|
|
398
|
+
const active = typeof document !== "undefined" ? document.activeElement : null;
|
|
399
|
+
if (active && active !== document.body && slot.el.contains(active)) return true;
|
|
400
|
+
const sel = typeof document !== "undefined" ? document.getSelection() : null;
|
|
401
|
+
return !!sel && !sel.isCollapsed && sel.rangeCount > 0 && sel.containsNode(slot.el, true);
|
|
402
|
+
}
|
|
403
|
+
/** One parking pass: plan on a clean layout, then park the plan in idle slices while the reader holds still. */
|
|
404
|
+
parkPass() {
|
|
405
|
+
const timeline = this.timeline;
|
|
406
|
+
const sc = this.scroller;
|
|
407
|
+
const began = this.lastActivity;
|
|
408
|
+
if (!timeline || !sc) {
|
|
409
|
+
this.parking = false;
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const nodes = timeline.getElementsByTagName("*").length;
|
|
413
|
+
const rows = [];
|
|
414
|
+
for (const slot of this.slots.values()) {
|
|
415
|
+
if (slot.phase !== "mounted" || slot.el.parentElement !== timeline) continue;
|
|
416
|
+
const top = slot.el.offsetTop;
|
|
417
|
+
rows.push({
|
|
418
|
+
key: slot.key,
|
|
419
|
+
top,
|
|
420
|
+
bottom: top + slot.el.offsetHeight,
|
|
421
|
+
held: this.isHeld(slot)
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
const scRect = sc.getBoundingClientRect();
|
|
425
|
+
const origin = timeline.getBoundingClientRect().top - scRect.top + sc.scrollTop;
|
|
426
|
+
const viewTop = sc.scrollTop - origin;
|
|
427
|
+
const view = {
|
|
428
|
+
top: viewTop,
|
|
429
|
+
bottom: viewTop + sc.clientHeight,
|
|
430
|
+
contentBottom: timeline.offsetHeight
|
|
431
|
+
};
|
|
432
|
+
const plan = parkPlan(parkCandidates(rows, view), this.mountedCount, nodes, (key) => (this.slots.get(key)?.el.getElementsByTagName("*").length ?? 0) + 1);
|
|
433
|
+
if (plan.length === 0) {
|
|
434
|
+
this.parking = false;
|
|
435
|
+
this.dirty = false;
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
let at = 0;
|
|
439
|
+
const slice = () => {
|
|
440
|
+
if (this.lastActivity !== began || !this.timeline) {
|
|
441
|
+
this.parking = false;
|
|
442
|
+
this.scheduleParking();
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const start = performance.now();
|
|
446
|
+
while (at < plan.length && performance.now() - start < 4) {
|
|
447
|
+
const batch = plan.slice(at, at + PARK_BATCH).map((key) => this.slots.get(key)).filter((s) => s !== void 0 && s.phase === "mounted" && this.boxes.has(s.el) && !this.isHeld(s));
|
|
448
|
+
at += PARK_BATCH;
|
|
449
|
+
flushSync(() => batch.forEach((slot) => this.transition(slot, "parked", false, this.boxes.get(slot.el))));
|
|
450
|
+
}
|
|
451
|
+
if (at < plan.length) {
|
|
452
|
+
requestIdle(slice);
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
this.parking = false;
|
|
456
|
+
this.dirty = true;
|
|
457
|
+
this.scheduleParking();
|
|
458
|
+
};
|
|
459
|
+
slice();
|
|
460
|
+
}
|
|
461
|
+
/** Counts for tests and the perf harness. */
|
|
462
|
+
stats() {
|
|
463
|
+
let parked = 0;
|
|
464
|
+
for (const slot of this.slots.values()) if (slot.phase === "parked") parked++;
|
|
465
|
+
return {
|
|
466
|
+
mounted: this.mountedCount,
|
|
467
|
+
parked,
|
|
468
|
+
rows: this.slots.size
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
/** The mounter of the transcript around a row wrapper; null outside one (every row mounts). */
|
|
473
|
+
const RowMountContext = createContext(null);
|
|
474
|
+
/**
|
|
475
|
+
* Mounts the transcript rows within `px` above and below the root row holding `el` (`RowMounter.mountAround`).
|
|
476
|
+
*
|
|
477
|
+
* @param scroller - The transcript's scroll container.
|
|
478
|
+
* @param el - An element inside a root row.
|
|
479
|
+
* @param px - How far each way.
|
|
480
|
+
* @returns Whether any row was not mounted (they render with the next commit).
|
|
481
|
+
*/
|
|
482
|
+
function mountAround(scroller, el, px) {
|
|
483
|
+
return mounters.get(scroller)?.mountAround(el, px) ?? false;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* The element of the transcript row `id` under `scroller`, mounting its content first if it has not mounted (a jump
|
|
487
|
+
* to a turn, a view put back where it was). Call it outside React's render and effects: it commits synchronously.
|
|
488
|
+
*
|
|
489
|
+
* @param scroller - The transcript's scroll container.
|
|
490
|
+
* @param id - The row's id (a root row's, or a worker block's).
|
|
491
|
+
* @returns The row's element, or null when no transcript there has it.
|
|
492
|
+
*/
|
|
493
|
+
function revealRow(scroller, id) {
|
|
494
|
+
const wrapper = mounters.get(scroller)?.reveal(id) ?? null;
|
|
495
|
+
const selector = `[data-row="${id.replace(/["\\]/g, (c) => `\\${c}`)}"]`;
|
|
496
|
+
return scroller.querySelector(selector) ?? wrapper;
|
|
497
|
+
}
|
|
498
|
+
export { RowMountContext, RowMounter, mountAround, revealRow };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure rules of how transcript rows mount (`row-mount.ts`), numbers in
|
|
3
|
+
* and decisions out, so a test drives them without a layout:
|
|
4
|
+
*
|
|
5
|
+
* - which queued row mounts first (`pumpOrder`): the nearest, the rows
|
|
6
|
+
* ahead of the scroll before the rows behind it;
|
|
7
|
+
* - when a row's measured height is its true height (`keepsSize`): only
|
|
8
|
+
* while it is mounted and rendered, never while `content-visibility`
|
|
9
|
+
* skips it (it then reports its placeholder size);
|
|
10
|
+
* - which mounted rows park when the transcript holds too many
|
|
11
|
+
* (`parkCandidates`, `parkPlan`): only past a budget, only far from the
|
|
12
|
+
* view, never a held row nor the bottom of the transcript, farthest first.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Mounted root rows past which far rows park, once the reader is idle. The DOM nodes are the real cost: this
|
|
16
|
+
* bounds a transcript of light rows (compact density's folds, ~17 nodes a row), whose nodes stay under theirs.
|
|
17
|
+
*/
|
|
18
|
+
export declare const PARK_MAX_ROWS = 1500;
|
|
19
|
+
/** DOM nodes under the timeline past which far rows park. */
|
|
20
|
+
export declare const PARK_MAX_NODES = 25000;
|
|
21
|
+
/** Parking goes down to this share of each budget, so one pass holds for a while. */
|
|
22
|
+
export declare const PARK_TARGET = 0.8;
|
|
23
|
+
/** A row parks only when it is farther than this many view heights from the view. */
|
|
24
|
+
export declare const PARK_FAR_VIEWS = 12;
|
|
25
|
+
/** The transcript's last view heights never park: where a live run lands and the reader returns. */
|
|
26
|
+
export declare const PARK_KEEP_BOTTOM_VIEWS = 3;
|
|
27
|
+
/** How long the reader holds still (no scroll, wheel, touch or key) before parking runs. */
|
|
28
|
+
export declare const PARK_IDLE_MS = 1000;
|
|
29
|
+
/** Main-thread time one slice of parking may take. */
|
|
30
|
+
export declare const PARK_SLICE_MS = 4;
|
|
31
|
+
/** What the transcript knows about a row when its size is reported. */
|
|
32
|
+
export interface SizeSample {
|
|
33
|
+
/** Its content is mounted (not a placeholder, not parked). */
|
|
34
|
+
mounted: boolean;
|
|
35
|
+
/** It is a `content-visibility: auto` row (a plain box is always rendered). */
|
|
36
|
+
cv: boolean;
|
|
37
|
+
/** What the last `contentvisibilityautostatechange` said (`skipped`); null before the first. */
|
|
38
|
+
skipped: boolean | null;
|
|
39
|
+
/** The browser reports `content-visibility` state changes. */
|
|
40
|
+
cvEvents: boolean;
|
|
41
|
+
/** Within a view height of the view (the fallback without state events). */
|
|
42
|
+
nearView: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether a row's reported height is its true height, to keep by its id.
|
|
46
|
+
*
|
|
47
|
+
* @param s - The {@link SizeSample}.
|
|
48
|
+
*/
|
|
49
|
+
export declare function keepsSize(s: SizeSample): boolean;
|
|
50
|
+
/** A row waiting to mount, and where it is. */
|
|
51
|
+
export interface QueuedRow<T> {
|
|
52
|
+
row: T;
|
|
53
|
+
/** Px between the row and the view (0: in it). */
|
|
54
|
+
distance: number;
|
|
55
|
+
/** The row lies in the direction the view is scrolling (or the view is still). */
|
|
56
|
+
ahead: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The order queued rows mount in: within a view height of the view first (at once), then the rest, nearest first,
|
|
60
|
+
* the rows ahead of the scroll before those behind it.
|
|
61
|
+
*
|
|
62
|
+
* @param queued - The rows and their distances.
|
|
63
|
+
* @param viewPx - The view's height.
|
|
64
|
+
* @returns The rows to mount now, and the rest in order.
|
|
65
|
+
*/
|
|
66
|
+
export declare function pumpOrder<T>(queued: readonly QueuedRow<T>[], viewPx: number): {
|
|
67
|
+
now: T[];
|
|
68
|
+
later: T[];
|
|
69
|
+
};
|
|
70
|
+
/** How many rows and DOM nodes the transcript may hold before far rows park. */
|
|
71
|
+
export interface ParkBudget {
|
|
72
|
+
rows: number;
|
|
73
|
+
nodes: number;
|
|
74
|
+
}
|
|
75
|
+
/** The default budget. */
|
|
76
|
+
export declare const PARK_BUDGET: ParkBudget;
|
|
77
|
+
/**
|
|
78
|
+
* Whether the transcript holds more than its budget.
|
|
79
|
+
*
|
|
80
|
+
* @param mounted - Mounted root rows.
|
|
81
|
+
* @param nodes - DOM nodes under the timeline.
|
|
82
|
+
* @param budget - The budget.
|
|
83
|
+
*/
|
|
84
|
+
export declare function overBudget(mounted: number, nodes: number, budget?: ParkBudget): boolean;
|
|
85
|
+
/** A mounted root row, in the timeline's coordinates. */
|
|
86
|
+
export interface MountedRow {
|
|
87
|
+
key: string;
|
|
88
|
+
top: number;
|
|
89
|
+
bottom: number;
|
|
90
|
+
/** Must stay mounted: a search holds it, it has the focus or the selection, a jump revealed it, it is live. */
|
|
91
|
+
held: boolean;
|
|
92
|
+
}
|
|
93
|
+
/** The view, in the timeline's coordinates. */
|
|
94
|
+
export interface ParkView {
|
|
95
|
+
top: number;
|
|
96
|
+
bottom: number;
|
|
97
|
+
/** The timeline's height. */
|
|
98
|
+
contentBottom: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The mounted rows that may park, farthest from the view first: not held, farther than {@link PARK_FAR_VIEWS} view
|
|
102
|
+
* heights from the view, and above the transcript's last {@link PARK_KEEP_BOTTOM_VIEWS} view heights.
|
|
103
|
+
*
|
|
104
|
+
* @param rows - The mounted root rows.
|
|
105
|
+
* @param view - The view.
|
|
106
|
+
*/
|
|
107
|
+
export declare function parkCandidates(rows: readonly MountedRow[], view: ParkView): string[];
|
|
108
|
+
/**
|
|
109
|
+
* Which candidates to park: none while within the budget; past it, the first ones until the transcript is back
|
|
110
|
+
* under {@link PARK_TARGET} of the budget (or the candidates run out).
|
|
111
|
+
*
|
|
112
|
+
* @param candidates - From {@link parkCandidates}, farthest first.
|
|
113
|
+
* @param mounted - Mounted root rows.
|
|
114
|
+
* @param nodes - DOM nodes under the timeline.
|
|
115
|
+
* @param nodesOf - The DOM nodes a row holds (read only for the rows this plan reaches).
|
|
116
|
+
* @param budget - The budget.
|
|
117
|
+
*/
|
|
118
|
+
export declare function parkPlan(candidates: readonly string[], mounted: number, nodes: number, nodesOf: (key: string) => number, budget?: ParkBudget): string[];
|
|
119
|
+
/**
|
|
120
|
+
* How long to wait before the reader counts as idle (0: idle now).
|
|
121
|
+
*
|
|
122
|
+
* @param lastActivity - When the reader last scrolled, wheeled, touched or pressed a key (ms).
|
|
123
|
+
* @param now - Now (ms).
|
|
124
|
+
*/
|
|
125
|
+
export declare function idleWait(lastActivity: number, now: number): number;
|