@vetta-org/theme-ui 0.1.1 → 0.2.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.
Files changed (340) hide show
  1. package/package.json +740 -20
  2. package/src/action-approval/AppearanceActionPickerView.tsx +2 -78
  3. package/src/action-approval/AppearanceApprovalDrawerView.tsx +2 -9
  4. package/src/action-approval/BatchTasksApprovalFrameView.tsx +4 -1
  5. package/src/action-approval/GenericActionApprovalView.tsx +2 -9
  6. package/src/action-approval/ManageActionApprovalFrameView.tsx +4 -1
  7. package/src/action-approval/NavigationOpenApprovalView.tsx +2 -9
  8. package/src/action-approval/SchedulerActionApprovalDialogView.tsx +3 -1
  9. package/src/action-approval/SchedulerEditApprovalDrawerView.tsx +3 -10
  10. package/src/action-approval/index.ts +0 -1
  11. package/src/activity/ActivityPanel.tsx +13 -10
  12. package/src/activity/ActivityPanelFrame.test.tsx +32 -0
  13. package/src/activity/ActivityPanelFrame.tsx +3 -2
  14. package/src/activity/BackgroundTasksTabPanelView.tsx +1 -1
  15. package/src/activity/BrowserPanelView.tsx +48 -49
  16. package/src/activity/CodePreview.tsx +15 -1
  17. package/src/activity/DebugTabPanelView.tsx +1 -1
  18. package/src/activity/MarkdownPreviewView.test.tsx +53 -0
  19. package/src/activity/MarkdownPreviewView.tsx +135 -62
  20. package/src/activity/PluginTabPickerView.tsx +5 -3
  21. package/src/activity/PortsTabPanelView.tsx +911 -0
  22. package/src/activity/ToolCallsSubTabView.tsx +1 -1
  23. package/src/activity/WorkflowTabPanelView.tsx +1 -1
  24. package/src/activity/index.ts +9 -0
  25. package/src/app/AppBackground.tsx +1 -1
  26. package/src/app/AppBootLoadingView.tsx +4 -2
  27. package/src/app-shell/DefaultWindowControls.tsx +1 -1
  28. package/src/app-shell/PageHeaderActionGroup.tsx +1 -1
  29. package/src/app-shell/PageHeaderContent.tsx +36 -7
  30. package/src/app-shell/PageHeaderFrame.tsx +15 -3
  31. package/src/app-shell/PageHeaderSidebarTrigger.tsx +1 -1
  32. package/src/app-shell/PageHeaderTitle.tsx +1 -1
  33. package/src/app-shell/WindowControlButton.tsx +1 -1
  34. package/src/app-shell/header-crowding.test.ts +62 -0
  35. package/src/app-shell/header-crowding.tsx +137 -0
  36. package/src/appearance/BackgroundImageFrame.tsx +1 -1
  37. package/src/appearance/CenterSliceImageFrame.tsx +1 -1
  38. package/src/appearance/CornerImageFrame.tsx +1 -1
  39. package/src/appearance/HorizontalSliceImageFrame.tsx +1 -1
  40. package/src/appearance/NineSliceImageFrame.tsx +1 -1
  41. package/src/appearance/ThemeSurface.tsx +1 -1
  42. package/src/batch-tasks/BatchProjectFoldersFieldView.tsx +2 -1
  43. package/src/batch-tasks/BatchTaskProjectActionsView.test.tsx +97 -0
  44. package/src/batch-tasks/BatchTaskProjectActionsView.tsx +45 -35
  45. package/src/batch-tasks/batchTaskUi.tsx +0 -29
  46. package/src/bottom-panel/BottomPanelView.test.tsx +43 -0
  47. package/src/bottom-panel/BottomPanelView.tsx +222 -0
  48. package/src/bottom-panel/index.ts +26 -0
  49. package/src/chat/AgentAvatarView.tsx +1 -1
  50. package/src/chat/AnnotationViews.tsx +107 -0
  51. package/src/chat/AskUserQuestionView.tsx +18 -11
  52. package/src/chat/AssistantMessageView.tsx +48 -13
  53. package/src/chat/AtPanelView.test.tsx +61 -0
  54. package/src/chat/AtPanelView.tsx +63 -38
  55. package/src/chat/BashTerminalCard.tsx +1 -2
  56. package/src/chat/ChatHeaderActionsView.tsx +74 -18
  57. package/src/chat/CompactionStepView.test.tsx +34 -0
  58. package/src/chat/CompactionStepView.tsx +85 -0
  59. package/src/chat/ContextRingView.test.tsx +81 -0
  60. package/src/chat/ContextRingView.tsx +78 -62
  61. package/src/chat/ExecutionModeSelectorView.tsx +20 -5
  62. package/src/chat/HeaderActionBarView.tsx +806 -0
  63. package/src/chat/HeaderActionOverflowMenu.tsx +128 -0
  64. package/src/chat/InlineModelPicker.test.tsx +81 -0
  65. package/src/chat/InlineModelPicker.tsx +201 -0
  66. package/src/chat/InlineTokenChip.tsx +2 -68
  67. package/src/chat/InputBarBackground.tsx +1 -1
  68. package/src/chat/InputBarPlaceholder.tsx +26 -3
  69. package/src/chat/LiveThinkingView.tsx +51 -37
  70. package/src/chat/MessageBoundaryViews.tsx +21 -0
  71. package/src/chat/MessageFeedContext.tsx +13 -5
  72. package/src/chat/MessageFeedLayoutView.tsx +29 -3
  73. package/src/chat/MessageFeedView.test.tsx +81 -0
  74. package/src/chat/MessageFeedView.tsx +72 -152
  75. package/src/chat/MessageInputView.tsx +6 -2
  76. package/src/chat/MessageLayoutView.tsx +1 -1
  77. package/src/chat/MessageSelectionContextMenuView.tsx +4 -1
  78. package/src/chat/MessageTimelineView.tsx +1 -1
  79. package/src/chat/MessageView.tsx +1 -1
  80. package/src/chat/MessageVisualView.tsx +1 -1
  81. package/src/chat/ModelConfiguration.tsx +283 -0
  82. package/src/chat/ModelSelectorTrigger.tsx +63 -0
  83. package/src/chat/ModelSelectorView.tsx +1037 -223
  84. package/src/chat/NewSession.ts +1 -37
  85. package/src/chat/NewSessionPicker.tsx +3 -2
  86. package/src/chat/ProjectSelectorView.tsx +3 -2
  87. package/src/chat/ReasoningStepSlider.tsx +61 -0
  88. package/src/chat/RemoteSessionBadgeView.tsx +24 -0
  89. package/src/chat/SkillPromptAreaView.tsx +5 -19
  90. package/src/chat/TeamMemberReplyCardView.test.tsx +33 -0
  91. package/src/chat/TeamMemberReplyCardView.tsx +133 -0
  92. package/src/chat/TextBlockView.tsx +7 -770
  93. package/src/chat/TodoProgress.tsx +25 -53
  94. package/src/chat/TodoStatusBarView.tsx +14 -5
  95. package/src/chat/UserMessageView.tsx +113 -33
  96. package/src/chat/header-action-narrow.test.ts +21 -0
  97. package/src/chat/header-action-narrow.ts +38 -0
  98. package/src/chat/index.ts +33 -27
  99. package/src/chat/markdown-link.ts +7 -279
  100. package/src/chat/message-feed-fade.css +80 -0
  101. package/src/chat/message-feed-fade.test.tsx +75 -0
  102. package/src/chat/send-button.css +4 -22
  103. package/src/chat/streaming-reveal.test.ts +218 -0
  104. package/src/chat/streaming-reveal.ts +13 -0
  105. package/src/file-explorer/ConfirmDeleteDialogView.tsx +2 -1
  106. package/src/file-explorer/FileContextMenuView.tsx +44 -11
  107. package/src/file-explorer/FileExplorerSettingsView.tsx +97 -0
  108. package/src/file-explorer/FileTreeCreateRow.tsx +1 -1
  109. package/src/file-explorer/FileTreeNodeView.tsx +59 -18
  110. package/src/file-explorer/FileTreeView.tsx +236 -129
  111. package/src/file-explorer/file-tree-dom.ts +23 -0
  112. package/src/file-explorer/file-tree-rows.test.ts +74 -0
  113. package/src/file-explorer/file-tree-rows.ts +168 -0
  114. package/src/file-explorer/index.ts +17 -0
  115. package/src/file-explorer/types.ts +3 -0
  116. package/src/file-explorer/useFileTreeMarqueeSelection.ts +24 -16
  117. package/src/file-preview/FilePreviewDialogView.tsx +2 -2
  118. package/src/file-preview/FilePreviewView.tsx +12 -2
  119. package/src/file-preview/ReadonlyCodeView.tsx +46 -0
  120. package/src/file-preview/TextFileEditorView.tsx +2 -1
  121. package/src/file-preview/syntax-tokens.css +1 -1
  122. package/src/image-assets.d.ts +4 -0
  123. package/src/index.ts +1 -0
  124. package/src/knowledge/KnowledgeHowItWorksDialogView.tsx +1 -1
  125. package/src/layout/AppFrame.tsx +3 -2
  126. package/src/layout/MainContentFrame.tsx +7 -2
  127. package/src/layout/ResizeHandle.tsx +68 -17
  128. package/src/layout/SidebarDock.tsx +75 -19
  129. package/src/layout/SidebarOverlay.tsx +1 -1
  130. package/src/layout/index.ts +1 -1
  131. package/src/layout/resize-handle-axis.test.ts +51 -0
  132. package/src/live-indicators.test.ts +43 -0
  133. package/src/markdown/CodeBlock.tsx +123 -0
  134. package/src/markdown/FileLinkBadge.tsx +77 -0
  135. package/src/markdown/InlineTokenChip.tsx +68 -0
  136. package/src/markdown/MarkdownContent.tsx +418 -0
  137. package/src/markdown/MarkdownImage.tsx +41 -0
  138. package/src/markdown/MathFormula.tsx +46 -0
  139. package/src/markdown/MermaidBlock.tsx +82 -0
  140. package/src/markdown/RichCodeBlock.tsx +127 -0
  141. package/src/markdown/SvgPreview.tsx +45 -0
  142. package/src/markdown/WebsiteIcon.tsx +94 -0
  143. package/src/markdown/builtin-renderers.tsx +43 -0
  144. package/src/markdown/definition.tsx +49 -0
  145. package/src/markdown/host.tsx +18 -0
  146. package/src/markdown/image-actions.ts +29 -0
  147. package/src/markdown/index.ts +12 -0
  148. package/src/markdown/inline-tokens.ts +187 -0
  149. package/src/markdown/markdown-link.ts +279 -0
  150. package/src/markdown/math-client.ts +116 -0
  151. package/src/markdown/math-render.ts +23 -0
  152. package/src/markdown/math-syntax.ts +80 -0
  153. package/src/markdown/math.worker.ts +16 -0
  154. package/src/markdown/nodes.ts +15 -0
  155. package/src/markdown/preview-policy.test.ts +31 -0
  156. package/src/markdown/preview-policy.ts +76 -0
  157. package/src/markdown/progressive-chunks.test.ts +43 -0
  158. package/src/markdown/progressive-chunks.ts +58 -0
  159. package/src/markdown/rich-labels.ts +55 -0
  160. package/src/markdown/rich-syntax.ts +93 -0
  161. package/src/markdown/stable-blocks.test.ts +90 -0
  162. package/src/markdown/stable-blocks.ts +124 -0
  163. package/src/markdown/streaming-reveal.ts +297 -0
  164. package/src/markdown/streaming.test.ts +57 -0
  165. package/src/markdown/streaming.ts +211 -0
  166. package/src/markdown/use-render-snapshot.ts +24 -0
  167. package/src/markdown/use-rich-visibility.ts +24 -0
  168. package/src/overlays/CommandMenuRow.tsx +77 -17
  169. package/src/overlays/CommandMenuView.tsx +163 -118
  170. package/src/overlays/ConfirmDialogView.tsx +25 -20
  171. package/src/overlays/DiagnosticsExportDialogView.tsx +236 -0
  172. package/src/overlays/MagpieHandoverDialogView.tsx +217 -0
  173. package/src/overlays/ReleaseNoteMarkdown.test.tsx +24 -0
  174. package/src/overlays/ReleaseNoteMarkdown.tsx +55 -0
  175. package/src/overlays/SplashOptionRow.tsx +46 -0
  176. package/src/overlays/SplashPanel.tsx +85 -0
  177. package/src/overlays/SplashParts.tsx +217 -0
  178. package/src/overlays/UpdateCheckerView.tsx +34 -18
  179. package/src/overlays/UpdateRestartDialogView.tsx +203 -53
  180. package/src/overlays/assets/diagnostics-banner.webp +0 -0
  181. package/src/overlays/command-menu-types.ts +15 -1
  182. package/src/overlays/command-menu.css +1 -20
  183. package/src/overlays/index.ts +26 -1
  184. package/src/plugin-ui/index.ts +10 -0
  185. package/src/project/ConversationTagDotsView.tsx +1 -1
  186. package/src/project/ConversationTagEditorDialogView.tsx +4 -1
  187. package/src/project/DefaultConversationSectionView.tsx +15 -24
  188. package/src/project/DefaultSessionListView.tsx +5 -31
  189. package/src/project/DefaultSessionRowView.tsx +114 -55
  190. package/src/project/ManageSessionsSplashView.tsx +439 -0
  191. package/src/project/NewProjectDialogView.tsx +3 -10
  192. package/src/project/ProjectContextMenuView.tsx +30 -139
  193. package/src/project/ProjectDetailPageView.test.tsx +140 -0
  194. package/src/project/ProjectDetailPageView.tsx +372 -165
  195. package/src/project/ProjectGroupView.tsx +1 -1
  196. package/src/project/ProjectRowView.tsx +29 -12
  197. package/src/project/ProjectSessionsView.tsx +25 -47
  198. package/src/project/QuickScrollOverlay.tsx +1 -1
  199. package/src/project/SessionContextMenuView.tsx +15 -7
  200. package/src/project/SessionRowMoreButton.tsx +50 -0
  201. package/src/project/SessionRowView.tsx +106 -63
  202. package/src/project/SessionTitleMarquee.tsx +54 -0
  203. package/src/project/SidebarProjectDisclosure.tsx +60 -0
  204. package/src/project/SidebarProjectsSectionView.tsx +6 -1
  205. package/src/project/index.ts +12 -0
  206. package/src/project/session-row-transition.ts +9 -0
  207. package/src/project/types.ts +4 -2
  208. package/src/project/useActiveSessionAutoScroll.ts +10 -4
  209. package/src/registry.ts +0 -2
  210. package/src/scheduler/AutomationDetailPaneView.tsx +68 -0
  211. package/src/scheduler/AutomationPageView.tsx +118 -121
  212. package/src/scheduler/ExecutionHistoryView.tsx +7 -5
  213. package/src/scheduler/TaskListView.tsx +52 -201
  214. package/src/scheduler/index.ts +7 -12
  215. package/src/settings/AppshotSettingsView.tsx +0 -1
  216. package/src/settings/ArchivedProjectsSettingsView.tsx +122 -1
  217. package/src/settings/BuiltinMcpSectionView.tsx +1 -1
  218. package/src/settings/EnvironmentGitRowView.tsx +156 -0
  219. package/src/settings/EnvironmentSettingsView.tsx +25 -3
  220. package/src/settings/GeneralSettingsView.tsx +18 -24
  221. package/src/settings/ImChannelGuideDialogView.tsx +2 -2
  222. package/src/settings/ImFeishuDialogView.tsx +1 -1
  223. package/src/settings/ImLegacyImportBannerView.tsx +1 -1
  224. package/src/settings/ImLogDrawerView.tsx +2 -1
  225. package/src/settings/JsonConfigInputView.tsx +171 -0
  226. package/src/settings/LauncherSettingsView.test.tsx +95 -0
  227. package/src/settings/LauncherSettingsView.tsx +273 -0
  228. package/src/settings/ModelsFetchedModelsDrawerView.tsx +292 -0
  229. package/src/settings/ModelsProvidersSectionView.tsx +26 -23
  230. package/src/settings/MotionSelect.tsx +9 -7
  231. package/src/settings/NotificationSettingsView.tsx +79 -0
  232. package/src/settings/PermissionsSettingsView.tsx +3 -7
  233. package/src/settings/PetActionGalleryView.test.tsx +163 -0
  234. package/src/settings/PetActionGalleryView.tsx +216 -0
  235. package/src/settings/PetSettingsView.test.tsx +117 -0
  236. package/src/settings/PetSettingsView.tsx +86 -22
  237. package/src/settings/PresetProviderModelsListView.tsx +141 -24
  238. package/src/settings/PresetProviderRowView.tsx +147 -185
  239. package/src/settings/ProxySettingsSectionView.tsx +182 -0
  240. package/src/settings/QrBindDialogView.tsx +1 -1
  241. package/src/settings/RemoteMcpSectionView.tsx +1 -1
  242. package/src/settings/SettingChrome.tsx +2 -2
  243. package/src/settings/SettingsAiAssistButtonView.tsx +9 -119
  244. package/src/settings/SettingsFormFields.tsx +4 -7
  245. package/src/settings/SettingsSidebarView.tsx +64 -3
  246. package/src/settings/ShortcutRecorderView.test.tsx +108 -0
  247. package/src/settings/ShortcutRecorderView.tsx +15 -9
  248. package/src/settings/ShortcutsSettingsView.tsx +1 -5
  249. package/src/settings/SpaceEditorDialogView.tsx +158 -0
  250. package/src/settings/SpacesSettingsView.tsx +150 -0
  251. package/src/settings/WebhookEndpointListView.tsx +4 -5
  252. package/src/settings/assets/space-editor-illustration.webp +0 -0
  253. package/src/settings/index.ts +59 -68
  254. package/src/shared/ActivityStatusDot.tsx +69 -0
  255. package/src/shared/AvatarStackView.tsx +13 -13
  256. package/src/shared/BotAvatar.tsx +11 -9
  257. package/src/shared/CodeBlockCopyButton.tsx +1 -1
  258. package/src/shared/ContextMenuView.tsx +4 -11
  259. package/src/shared/MarkdownTable.tsx +2 -2
  260. package/src/shared/SegmentedControl.test.tsx +68 -0
  261. package/src/shared/SegmentedControl.tsx +10 -2
  262. package/src/shared/SyntaxHighlightedCode.tsx +0 -0
  263. package/src/shared/TabBar.outline.test.tsx +59 -0
  264. package/src/shared/TabBar.tsx +23 -18
  265. package/src/shared/VettaKbd.test.tsx +52 -0
  266. package/src/shared/VettaKbd.tsx +100 -0
  267. package/src/shared/connected-tab-outline.test.ts +2 -2
  268. package/src/shared/connected-tab-outline.ts +2 -1
  269. package/src/shared/index.ts +7 -0
  270. package/src/shared/kbd-keys.test.ts +61 -0
  271. package/src/shared/kbd-keys.ts +253 -0
  272. package/src/shared/platform.ts +9 -0
  273. package/src/shared/provider-icon/icons.ts +4 -2
  274. package/src/shared/provider-icon/index.tsx +1 -1
  275. package/src/shared/provider-icon/magpie.svg +1 -0
  276. package/src/sidebar/AddProjectMenuTriggerView.tsx +33 -24
  277. package/src/sidebar/DefaultSidebar.tsx +3 -1
  278. package/src/sidebar/MessageCenterDialogView.tsx +3 -2
  279. package/src/sidebar/MessageCenterEmptyState.tsx +1 -1
  280. package/src/sidebar/MessageCenterTabs.tsx +1 -1
  281. package/src/sidebar/MessageCenterToolbarButton.tsx +1 -1
  282. package/src/sidebar/MessageCenterTriggerView.tsx +2 -2
  283. package/src/sidebar/ProjectsPanelEmptyState.tsx +26 -7
  284. package/src/sidebar/SessionStatusIcon.tsx +16 -1
  285. package/src/sidebar/SettingsMenuThemeSection.tsx +1 -1
  286. package/src/sidebar/SettingsMenuTriggerView.test.tsx +42 -0
  287. package/src/sidebar/SettingsMenuTriggerView.tsx +29 -50
  288. package/src/sidebar/ShowMoreSessionsButton.tsx +1 -1
  289. package/src/sidebar/SidebarFilterSelectView.tsx +8 -16
  290. package/src/sidebar/SidebarNavBadgeView.tsx +1 -1
  291. package/src/sidebar/SidebarNavIcon.tsx +1 -1
  292. package/src/sidebar/SidebarNavItemButton.tsx +1 -1
  293. package/src/sidebar/SidebarNavMorePanel.tsx +19 -7
  294. package/src/sidebar/SidebarNavigation.tsx +24 -15
  295. package/src/sidebar/SidebarPanel.tsx +11 -2
  296. package/src/sidebar/SidebarSectionActionButton.test.tsx +91 -0
  297. package/src/sidebar/SidebarSectionActionButton.tsx +52 -0
  298. package/src/sidebar/SidebarSectionTriggerLabel.tsx +20 -0
  299. package/src/sidebar/SidebarTopBar.tsx +10 -7
  300. package/src/sidebar/WaitingPulseBadge.tsx +19 -0
  301. package/src/sidebar/index.ts +1 -16
  302. package/src/skills/index.ts +0 -19
  303. package/src/skills/skill-icon.tsx +4 -8
  304. package/src/styles.css +26 -6
  305. package/src/chat/DefaultSceneCarousel.tsx +0 -113
  306. package/src/chat/SceneCard.tsx +0 -138
  307. package/src/scheduler/HistoryDrawerView.tsx +0 -149
  308. package/src/scheduler/TaskFormDialogView.tsx +0 -60
  309. package/src/settings/AchievementNavigationButtonView.tsx +0 -90
  310. package/src/settings/AchievementPromotionDialogView.tsx +0 -91
  311. package/src/settings/AchievementSettingsView.tsx +0 -44
  312. package/src/settings/PetBubbleStylePreviewView.tsx +0 -44
  313. package/src/settings/QuickPanelSettingsSectionView.tsx +0 -66
  314. package/src/settings/SubscriptionActionsView.tsx +0 -63
  315. package/src/settings/SubscriptionCardsView.tsx +0 -212
  316. package/src/settings/TeamDetailView.tsx +0 -148
  317. package/src/settings/TeamDialogsView.tsx +0 -151
  318. package/src/settings/TeamListView.tsx +0 -57
  319. package/src/settings/TeamSettingsView.tsx +0 -51
  320. package/src/settings/TokenActivityChartView.tsx +0 -286
  321. package/src/settings/UsageStatsView.tsx +0 -101
  322. package/src/settings/achievements/AchievementCurtains.tsx +0 -50
  323. package/src/settings/achievements/AchievementPromotionBadge3D.tsx +0 -350
  324. package/src/settings/achievements/AchievementPromotionConfetti.tsx +0 -71
  325. package/src/settings/achievements/AchievementTitle.tsx +0 -52
  326. package/src/settings/achievements/index.ts +0 -13
  327. package/src/settings/shouldCloseEmptyApiKeyEditor.test.ts +0 -135
  328. package/src/settings/shouldCloseEmptyApiKeyEditor.ts +0 -40
  329. package/src/settings/token-activity.test.ts +0 -195
  330. package/src/settings/token-activity.ts +0 -320
  331. package/src/sidebar/AddProjectMenuItem.tsx +0 -21
  332. package/src/sidebar/AddProjectMenuPopoverView.tsx +0 -52
  333. package/src/sidebar/NotificationMessageListView.tsx +0 -136
  334. package/src/sidebar/SettingsMenuAccountSection.tsx +0 -32
  335. package/src/sidebar/SettingsMenuQuotaSection.tsx +0 -45
  336. package/src/skills/SceneCardView.tsx +0 -194
  337. package/src/skills/SkillCardView.tsx +0 -186
  338. package/src/skills/SkillDetailDialogView.tsx +0 -138
  339. package/src/skills/SkillTagGroupView.tsx +0 -56
  340. package/src/skills/SkillToggleSwitch.tsx +0 -31
@@ -0,0 +1,58 @@
1
+ /** Below this size a document renders in one pass; above it, section by section. */
2
+ export const PROGRESSIVE_MARKDOWN_THRESHOLD = 40_000;
3
+ /** Each chunk takes roughly a frame or two to parse and render. */
4
+ const TARGET_CHUNK_CHARACTERS = 12_000;
5
+
6
+ const FENCE_RE = /^ {0,3}(`{3,}|~{3,})/;
7
+ const ATX_HEADING_RE = /^ {0,3}#{1,6}(\s|$)/;
8
+ const FOOTNOTE_DEFINITION_RE = /^ {0,3}\[\^[^\]]+\]:/m;
9
+ const LINK_DEFINITION_RE = /^ {0,3}\[[^\]^][^\]]*\]:\s*\S/;
10
+
11
+ /**
12
+ * Splits a large Markdown document into independently renderable chunks, cutting only
13
+ * before an ATX heading that follows a blank line outside fenced code. A heading always
14
+ * starts a new block, so no list, quote, table or paragraph spans two chunks.
15
+ *
16
+ * Link reference definitions apply document-wide, so they are repeated at the end of every
17
+ * chunk (they render nothing). Footnotes collect into one section per render, so a document
18
+ * that defines any is never split.
19
+ */
20
+ export function splitMarkdownForProgressiveRender(markdown: string): string[] {
21
+ if (markdown.length <= PROGRESSIVE_MARKDOWN_THRESHOLD || FOOTNOTE_DEFINITION_RE.test(markdown)) {
22
+ return [markdown];
23
+ }
24
+ const lines = markdown.split("\n");
25
+ const chunks: string[] = [];
26
+ const definitions: string[] = [];
27
+ let current: string[] = [];
28
+ let currentLength = 0;
29
+ let fence: string | null = null;
30
+ for (let index = 0; index < lines.length; index++) {
31
+ const line = lines[index] ?? "";
32
+ const fenceMatch = FENCE_RE.exec(line);
33
+ if (fence === null) {
34
+ if (fenceMatch?.[1]) {
35
+ fence = fenceMatch[1];
36
+ } else if (
37
+ ATX_HEADING_RE.test(line) &&
38
+ index > 0 &&
39
+ (lines[index - 1] ?? "").trim() === "" &&
40
+ currentLength >= TARGET_CHUNK_CHARACTERS
41
+ ) {
42
+ chunks.push(current.join("\n"));
43
+ current = [];
44
+ currentLength = 0;
45
+ } else if (LINK_DEFINITION_RE.test(line)) {
46
+ definitions.push(line);
47
+ }
48
+ } else if (fenceMatch?.[1] && fenceMatch[1][0] === fence[0] && fenceMatch[1].length >= fence.length) {
49
+ fence = null;
50
+ }
51
+ current.push(line);
52
+ currentLength += line.length + 1;
53
+ }
54
+ if (current.length > 0) chunks.push(current.join("\n"));
55
+ if (definitions.length === 0 || chunks.length === 1) return chunks;
56
+ const shared = `\n\n${definitions.join("\n")}\n`;
57
+ return chunks.map((chunk) => `${chunk}${shared}`);
58
+ }
@@ -0,0 +1,55 @@
1
+ import type { FileLinkMenuLabels } from "./FileLinkBadge";
2
+
3
+ export interface RichContentLabels {
4
+ preview: string;
5
+ source: string;
6
+ run: string;
7
+ stop: string;
8
+ waiting: string;
9
+ paused: string;
10
+ tooLarge: string;
11
+ failed: string;
12
+ staticHtml: string;
13
+ running: string;
14
+ svg: string;
15
+ html: string;
16
+ loading?: string;
17
+ retry?: string;
18
+ enlarge?: string;
19
+ copyImage?: string;
20
+ save?: string;
21
+ diagram?: string;
22
+ imageFailed?: string;
23
+ actionFailed?: string;
24
+ }
25
+
26
+ export const defaultRichContentLabels: RichContentLabels = {
27
+ preview: "Preview",
28
+ source: "Source",
29
+ run: "Run JavaScript",
30
+ stop: "Stop",
31
+ waiting: "Preview will appear when generation finishes.",
32
+ paused: "Preview paused. Run again to restart the page.",
33
+ tooLarge: "This content is too large to preview. You can still view and copy its source.",
34
+ failed: "Could not render this content. Its source is shown instead.",
35
+ staticHtml: "Static preview. Run JavaScript to enable interactions; external resources are blocked.",
36
+ running: "Interactive preview. Automatically stops after 30 seconds.",
37
+ svg: "SVG preview",
38
+ html: "HTML preview",
39
+ loading: "Loading preview…",
40
+ retry: "Retry",
41
+ enlarge: "Enlarge",
42
+ copyImage: "Copy image",
43
+ save: "Save",
44
+ diagram: "Diagram",
45
+ imageFailed: "Could not load image.",
46
+ actionFailed: "Could not complete this action. Try again.",
47
+ };
48
+
49
+ export interface MarkdownLabels {
50
+ copy: string;
51
+ copied: string;
52
+ /** 文件徽标右键菜单文案;缺省时不出菜单。 */
53
+ fileLink?: FileLinkMenuLabels;
54
+ rich?: RichContentLabels;
55
+ }
@@ -0,0 +1,93 @@
1
+ import remarkMath from "remark-math";
2
+ import { remarkMathAliases } from "./math-syntax";
3
+
4
+ interface MarkdownNode {
5
+ type: string;
6
+ value?: string;
7
+ lang?: string;
8
+ children?: MarkdownNode[];
9
+ position?: { start: { offset?: number }; end: { offset?: number } };
10
+ data?: { hName: string; hProperties: Record<string, string> };
11
+ }
12
+
13
+ /** Keep raw markup out of the host DOM. Only standalone HTML and complete SVG become previews. */
14
+ export function remarkRichMarkup() {
15
+ return (tree: MarkdownNode, file: { value: unknown }): void => {
16
+ const markdown = String(file.value);
17
+ function visit(parent: MarkdownNode) {
18
+ const children = parent.children;
19
+ if (!children) return;
20
+ for (let index = 0; index < children.length; index++) {
21
+ const node = children[index];
22
+ if (node.type === "inlineMath") {
23
+ const start = node.position?.start.offset;
24
+ const end = node.position?.end.offset;
25
+ const raw = start === undefined || end === undefined ? "" : markdown.slice(start, end);
26
+ // Single-dollar delimiters follow the common no-whitespace/no-following-digit rule.
27
+ if (
28
+ /^\$(?!\$)/.test(raw) &&
29
+ (/^\$\s|\s\$$/.test(raw) || /\d/.test(markdown[end ?? markdown.length] ?? ""))
30
+ ) {
31
+ children[index] = { type: "text", value: raw, position: node.position };
32
+ continue;
33
+ }
34
+ }
35
+ if (node.type !== "html") {
36
+ visit(node);
37
+ continue;
38
+ }
39
+ const source = node.value ?? "";
40
+ if (parent.type === "root" && /^\s*(?:<!doctype\s+html|<html[\s>])/i.test(source)) {
41
+ const start = node.position?.start.offset;
42
+ if (start !== undefined) {
43
+ const rest = markdown.slice(start);
44
+ const closing = /<\/html\s*>/i.exec(rest);
45
+ if (closing) {
46
+ const end = start + closing.index + closing[0].length;
47
+ let count = 1;
48
+ while (
49
+ index + count < children.length &&
50
+ (children[index + count].position?.start.offset ?? end) < end
51
+ )
52
+ count++;
53
+ const through = children[index + count - 1].position?.end.offset ?? end;
54
+ children.splice(index, count, {
55
+ type: "code",
56
+ lang: "html",
57
+ value: markdown.slice(start, through),
58
+ });
59
+ continue;
60
+ }
61
+ }
62
+ }
63
+ if (/^\s*<svg[\s>]/i.test(source)) {
64
+ const start = node.position?.start.offset;
65
+ if (start === undefined) continue;
66
+ const closing = /<\/svg\s*>/i.exec(markdown.slice(start));
67
+ if (!closing) continue;
68
+ const end = start + closing.index + closing[0].length;
69
+ let count = 1;
70
+ while (index + count < children.length && (children[index + count].position?.start.offset ?? end) < end)
71
+ count++;
72
+ // Slice the source once: text inside SVG may have been parsed as Markdown,
73
+ // and rescanning an ever-growing concatenation would be quadratic.
74
+ if ((children[index + count - 1].position?.end.offset ?? 0) <= end) {
75
+ children.splice(index, count, {
76
+ type: "richSvg",
77
+ data: { hName: "vetta-svg", hProperties: { source: markdown.slice(start, end) } },
78
+ children: [],
79
+ });
80
+ }
81
+ } else if (
82
+ parent.type === "root" &&
83
+ /^\s*(?:<!doctype\s+html|<(?:html|div|section|article|main|style|table|body|head)[\s>])/i.test(source)
84
+ ) {
85
+ children[index] = { type: "code", lang: "html", value: source };
86
+ }
87
+ }
88
+ }
89
+ visit(tree);
90
+ };
91
+ }
92
+
93
+ export const richRemarkPlugins = [remarkMath, remarkMathAliases, remarkRichMarkup];
@@ -0,0 +1,90 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { splitStableMarkdownBlocks } from "./stable-blocks";
3
+
4
+ describe("splitStableMarkdownBlocks", () => {
5
+ it.each(["$$\n```\nformula\n```\n$$", "<html>\n```\npage\n```\n</html>"])(
6
+ "rich blocks preserve parser context and previously frozen prefixes: %s",
7
+ (rich) => {
8
+ const prefix = "```ts\nconst x = 1;\n```\n";
9
+ const text = `${prefix}\n${rich}\nAfter`;
10
+ expect(splitStableMarkdownBlocks(text)).toEqual({ committed: [prefix], tail: `\n${rich}\nAfter` });
11
+ },
12
+ );
13
+ it("空文本没有已提交块", () => {
14
+ expect(splitStableMarkdownBlocks("")).toEqual({ committed: [], tail: "" });
15
+ });
16
+
17
+ it("只有一段未结束的段落全部留在 tail", () => {
18
+ expect(splitStableMarkdownBlocks("Hello there")).toEqual({
19
+ committed: [],
20
+ tail: "Hello there",
21
+ });
22
+ });
23
+
24
+ it("空行不提交段落,避免拆开松散列表和缩进代码", () => {
25
+ const text = "First paragraph.\n\nSecond";
26
+ expect(splitStableMarkdownBlocks(text)).toEqual({ committed: [], tail: text });
27
+ });
28
+
29
+ it("松散有序列表整段留在 tail", () => {
30
+ const text = "1. foo\n\n2. bar\n";
31
+ expect(splitStableMarkdownBlocks(text)).toEqual({ committed: [], tail: text });
32
+ });
33
+
34
+ it("闭合围栏后面没有正文时整块留在 tail", () => {
35
+ const fence = "```js\nconst a = 1;\n```";
36
+ expect(splitStableMarkdownBlocks(fence)).toEqual({ committed: [], tail: fence });
37
+ });
38
+
39
+ it("闭合围栏后面还有正文时提交围栏", () => {
40
+ const text = "```js\nconst a = 1;\n```\n\nmore";
41
+ expect(splitStableMarkdownBlocks(text)).toEqual({
42
+ committed: ["```js\nconst a = 1;\n```\n"],
43
+ tail: "\nmore",
44
+ });
45
+ });
46
+
47
+ it("未闭合围栏整段留在 tail,即使中间有空行", () => {
48
+ const text = "```js\nconst a = 1;\n\nconst b = 2;\n";
49
+ expect(splitStableMarkdownBlocks(text)).toEqual({ committed: [], tail: text });
50
+ });
51
+
52
+ it("围栏闭合行后若还有非空白字符则不算闭合", () => {
53
+ const text = "```js\nconst a = 1;\n``` notclose\nstill in fence";
54
+ expect(splitStableMarkdownBlocks(text)).toEqual({ committed: [], tail: text });
55
+ });
56
+
57
+ it("info string 含反引号的行不能当作开围栏", () => {
58
+ const text = "```js`oops\nnot a fence";
59
+ expect(splitStableMarkdownBlocks(text)).toEqual({ committed: [], tail: text });
60
+ });
61
+
62
+ it("波浪线围栏的 info string 允许含波浪线", () => {
63
+ const text = "~~~ a~b\ncode\n~~~\n\nafter";
64
+ expect(splitStableMarkdownBlocks(text)).toEqual({
65
+ committed: ["~~~ a~b\ncode\n~~~\n"],
66
+ tail: "\nafter",
67
+ });
68
+ });
69
+
70
+ it("波浪线围栏与反引号围栏互不闭合", () => {
71
+ const text = "~~~\ncode\n```\nstill\n~~~\n\nafter";
72
+ expect(splitStableMarkdownBlocks(text)).toEqual({
73
+ committed: ["~~~\ncode\n```\nstill\n~~~\n"],
74
+ tail: "\nafter",
75
+ });
76
+ });
77
+
78
+ it("列表项里的缩进围栏不提交,避免把有序列表拆成两份文档", () => {
79
+ const text = "1. first\n ```js\n x\n ```\n2. second\n";
80
+ expect(splitStableMarkdownBlocks(text)).toEqual({ committed: [], tail: text });
81
+ });
82
+
83
+ it("CRLF 闭合行仍能提交顶层围栏", () => {
84
+ const text = "```js\r\nconst a = 1;\r\n```\r\n\r\nmore";
85
+ expect(splitStableMarkdownBlocks(text)).toEqual({
86
+ committed: ["```js\r\nconst a = 1;\r\n```\r\n"],
87
+ tail: "\r\nmore",
88
+ });
89
+ });
90
+ });
@@ -0,0 +1,124 @@
1
+ export interface StableMarkdownSplit {
2
+ readonly committed: readonly string[];
3
+ readonly tail: string;
4
+ }
5
+
6
+ interface FenceMarker {
7
+ readonly char: "`" | "~";
8
+ readonly len: number;
9
+ readonly markerEnd: number;
10
+ readonly indent: number;
11
+ }
12
+
13
+ function stripLineEnding(line: string): string {
14
+ return line.endsWith("\r") ? line.slice(0, -1) : line;
15
+ }
16
+
17
+ function readFenceMarker(line: string): FenceMarker | null {
18
+ let index = 0;
19
+ while (index < 3 && line[index] === " ") index += 1;
20
+ const char = line[index];
21
+ if (char !== "`" && char !== "~") return null;
22
+ let len = 0;
23
+ while (line[index + len] === char) len += 1;
24
+ if (len < 3) return null;
25
+ return { char, len, indent: index, markerEnd: index + len };
26
+ }
27
+
28
+ function isFenceOpeningLine(line: string): FenceMarker | null {
29
+ const fence = readFenceMarker(line);
30
+ if (!fence) return null;
31
+ // CommonMark:只有反引号围栏的 info string 不能含反引号,波浪线围栏的 info string 可以含 `~`。
32
+ if (fence.char === "`" && line.includes("`", fence.markerEnd)) return null;
33
+ return fence;
34
+ }
35
+
36
+ function isFenceClosingLine(line: string, fenceChar: FenceMarker["char"], fenceLen: number): boolean {
37
+ const fence = readFenceMarker(line);
38
+ if (!fence || fence.char !== fenceChar || fence.len < fenceLen) return false;
39
+ for (let index = fence.markerEnd; index < line.length; index += 1) {
40
+ const char = line[index];
41
+ if (char !== " " && char !== "\t") return false;
42
+ }
43
+ return true;
44
+ }
45
+
46
+ /**
47
+ * Split append-only markdown so completed top-level fenced blocks can be frozen.
48
+ *
49
+ * Only an unindented closed code fence followed by more text is committed.
50
+ * Indented fences stay in the tail so list items that wrap a code block are not
51
+ * split into two documents (the second list would restart at 1). Blank lines
52
+ * are not terminators. Because only whole top-level fences are committed, the
53
+ * committed blocks of a prefix are a prefix of the committed blocks of any
54
+ * append-only extension, so the caller keeps the split after streaming ends
55
+ * instead of re-parsing the whole document (which would remount every node).
56
+ */
57
+ export function splitStableMarkdownBlocks(text: string): StableMarkdownSplit {
58
+ if (text.length === 0) return { committed: [], tail: "" };
59
+
60
+ const committed: string[] = [];
61
+ let start = 0;
62
+ let index = 0;
63
+ let inFence = false;
64
+ let fenceChar: FenceMarker["char"] = "`";
65
+ let fenceLen = 0;
66
+ let commitOnClose = false;
67
+ let literalEnd: RegExp | null = null;
68
+
69
+ const commitThrough = (end: number): void => {
70
+ if (end <= start || end > text.length) return;
71
+ const block = text.slice(start, end);
72
+ if (block.trim().length === 0) {
73
+ start = end;
74
+ return;
75
+ }
76
+ committed.push(block);
77
+ start = end;
78
+ };
79
+
80
+ while (index < text.length) {
81
+ const lineStart = index;
82
+ const newline = text.indexOf("\n", index);
83
+ const lineEnd = newline === -1 ? text.length : newline + 1;
84
+ const line = stripLineEnding(text.slice(lineStart, newline === -1 ? text.length : newline));
85
+
86
+ if (inFence) {
87
+ if (isFenceClosingLine(line, fenceChar, fenceLen)) {
88
+ inFence = false;
89
+ if (commitOnClose && lineEnd < text.length) commitThrough(lineEnd);
90
+ commitOnClose = false;
91
+ }
92
+ index = lineEnd;
93
+ continue;
94
+ }
95
+
96
+ // Do not freeze fence-looking text inside raw documents or display formulas.
97
+ // Track this while scanning so previously committed prefixes remain stable.
98
+ if (literalEnd) {
99
+ if (literalEnd.test(line)) literalEnd = null;
100
+ index = lineEnd;
101
+ continue;
102
+ }
103
+ const math = /^ {0,3}(\${2,})\s*$/.exec(line);
104
+ const html = /^ {0,3}<(svg|html|script|style|div|section|article|table|body|head)(?:\s|>)/i.exec(line);
105
+ if (math || html || /^ {0,3}<!doctype\s+html/i.test(line)) {
106
+ literalEnd = math
107
+ ? new RegExp(`^ {0,3}\\${"$"}{${math[1].length},}\\s*$`)
108
+ : new RegExp(`</${html?.[1] ?? "html"}\\s*>`, "i");
109
+ if (!math && literalEnd.test(line)) literalEnd = null;
110
+ index = lineEnd;
111
+ continue;
112
+ }
113
+ const opening = isFenceOpeningLine(line);
114
+ if (opening) {
115
+ inFence = true;
116
+ fenceChar = opening.char;
117
+ fenceLen = opening.len;
118
+ commitOnClose = opening.indent === 0;
119
+ }
120
+ index = lineEnd;
121
+ }
122
+
123
+ return { committed, tail: text.slice(start) };
124
+ }