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