@deepseek-ai/dsh-client-ui-primitives 0.2.2-rc.1 → 0.2.2-rc.2

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 (412) hide show
  1. package/README.i18n.yaml +16 -16
  2. package/README.md +21 -14
  3. package/README.zh.md +21 -14
  4. package/lib/HoverCard.module.css +8 -3
  5. package/lib/JsonTree.module.css +7 -17
  6. package/lib/Menu.module.css +157 -37
  7. package/lib/Modal.module.css +16 -0
  8. package/lib/QuotePreview.module.css +37 -0
  9. package/lib/RiskConfirmation.module.css +11 -37
  10. package/lib/Toast.module.css +2 -3
  11. package/lib/Tooltip.module.css +2 -1
  12. package/lib/index.js +1447 -776
  13. package/lib/index.js.map +1 -0
  14. package/lib/markdown/CodeBlock.module.css +64 -0
  15. package/lib/markdown/MarkdownText.module.css +20 -1
  16. package/lib/types/AnimatedRows.d.ts +3 -0
  17. package/lib/types/AnimatedRows.d.ts.map +1 -0
  18. package/lib/types/AnimatedRows.js.map +1 -0
  19. package/lib/types/BrandWordmark.d.ts.map +1 -0
  20. package/lib/types/BrandWordmark.js.map +1 -0
  21. package/lib/types/Button.d.ts.map +1 -0
  22. package/lib/types/Button.js.map +1 -0
  23. package/lib/types/Checkbox.d.ts +3 -1
  24. package/lib/types/Checkbox.d.ts.map +1 -0
  25. package/lib/types/Checkbox.js.map +1 -0
  26. package/lib/types/CodeFileIcon.d.ts.map +1 -0
  27. package/lib/types/CodeFileIcon.js.map +1 -0
  28. package/lib/types/CodeToolbar.d.ts.map +1 -0
  29. package/lib/types/CodeToolbar.js.map +1 -0
  30. package/lib/types/CommandText.d.ts.map +1 -0
  31. package/lib/types/CommandText.js.map +1 -0
  32. package/lib/types/ConfigField.d.ts.map +1 -0
  33. package/lib/types/ConfigField.js.map +1 -0
  34. package/lib/types/ConnectionIndicator.d.ts.map +1 -0
  35. package/lib/types/ConnectionIndicator.js.map +1 -0
  36. package/lib/types/DetailDocument.d.ts.map +1 -0
  37. package/lib/types/DetailDocument.js.map +1 -0
  38. package/lib/types/DiffBlock.d.ts.map +1 -0
  39. package/lib/types/DiffBlock.js.map +1 -0
  40. package/lib/types/DisclosureRow.d.ts.map +1 -0
  41. package/lib/types/DisclosureRow.js.map +1 -0
  42. package/lib/types/DraggableImage.d.ts.map +1 -0
  43. package/lib/types/DraggableImage.js.map +1 -0
  44. package/lib/types/FileTypeIcon.d.ts.map +1 -0
  45. package/lib/types/FileTypeIcon.js.map +1 -0
  46. package/lib/types/FishLogo.d.ts.map +1 -0
  47. package/lib/types/FishLogo.js.map +1 -0
  48. package/lib/types/FoldToggle.d.ts.map +1 -0
  49. package/lib/types/FoldToggle.js.map +1 -0
  50. package/lib/types/HoverCard.d.ts.map +1 -0
  51. package/lib/types/HoverCard.js.map +1 -0
  52. package/lib/types/HoverCardGroup.d.ts.map +1 -0
  53. package/lib/types/HoverCardGroup.js.map +1 -0
  54. package/lib/types/ImageLightbox.d.ts.map +1 -0
  55. package/lib/types/ImageLightbox.js.map +1 -0
  56. package/lib/types/ImagePreview.d.ts.map +1 -0
  57. package/lib/types/ImagePreview.js.map +1 -0
  58. package/lib/types/InlineEditor.d.ts.map +1 -0
  59. package/lib/types/InlineEditor.js.map +1 -0
  60. package/lib/types/Input.d.ts.map +1 -0
  61. package/lib/types/Input.js.map +1 -0
  62. package/lib/types/JsonTree.d.ts.map +1 -0
  63. package/lib/types/JsonTree.js.map +1 -0
  64. package/lib/types/LinkIcon.d.ts.map +1 -0
  65. package/lib/types/LinkIcon.js.map +1 -0
  66. package/lib/types/Menu.d.ts +26 -14
  67. package/lib/types/Menu.d.ts.map +1 -0
  68. package/lib/types/Menu.js.map +1 -0
  69. package/lib/types/MenuGroup.d.ts.map +1 -0
  70. package/lib/types/MenuGroup.js.map +1 -0
  71. package/lib/types/MenuRow.d.ts +37 -0
  72. package/lib/types/MenuRow.d.ts.map +1 -0
  73. package/lib/types/MenuRow.js.map +1 -0
  74. package/lib/types/MenuSurface.d.ts.map +1 -0
  75. package/lib/types/MenuSurface.js.map +1 -0
  76. package/lib/types/Modal.d.ts +3 -1
  77. package/lib/types/Modal.d.ts.map +1 -0
  78. package/lib/types/Modal.js.map +1 -0
  79. package/lib/types/PathLabel.d.ts.map +1 -0
  80. package/lib/types/PathLabel.js.map +1 -0
  81. package/lib/types/PermissionIcon.d.ts.map +1 -0
  82. package/lib/types/PermissionIcon.js.map +1 -0
  83. package/lib/types/Pill.d.ts.map +1 -0
  84. package/lib/types/Pill.js.map +1 -0
  85. package/lib/types/QuotePreview.d.ts +17 -4
  86. package/lib/types/QuotePreview.d.ts.map +1 -0
  87. package/lib/types/QuotePreview.js.map +1 -0
  88. package/lib/types/ReadBlock.d.ts.map +1 -0
  89. package/lib/types/ReadBlock.js.map +1 -0
  90. package/lib/types/ReferenceIcon.d.ts.map +1 -0
  91. package/lib/types/ReferenceIcon.js.map +1 -0
  92. package/lib/types/RiskConfirmation.d.ts.map +1 -0
  93. package/lib/types/RiskConfirmation.js.map +1 -0
  94. package/lib/types/SearchBlock.d.ts.map +1 -0
  95. package/lib/types/SearchBlock.js.map +1 -0
  96. package/lib/types/SegmentedControl.d.ts.map +1 -0
  97. package/lib/types/SegmentedControl.js.map +1 -0
  98. package/lib/types/SegmentedTabs.d.ts.map +1 -0
  99. package/lib/types/SegmentedTabs.js.map +1 -0
  100. package/lib/types/ShortcutKeys.d.ts.map +1 -0
  101. package/lib/types/ShortcutKeys.js.map +1 -0
  102. package/lib/types/SiteGlyph.d.ts.map +1 -0
  103. package/lib/types/SiteGlyph.js.map +1 -0
  104. package/lib/types/StateDot.d.ts.map +1 -0
  105. package/lib/types/StateDot.js.map +1 -0
  106. package/lib/types/SubmenuPanel.d.ts +19 -0
  107. package/lib/types/SubmenuPanel.d.ts.map +1 -0
  108. package/lib/types/SubmenuPanel.js.map +1 -0
  109. package/lib/types/Switch.d.ts.map +1 -0
  110. package/lib/types/Switch.js.map +1 -0
  111. package/lib/types/Tag.d.ts.map +1 -0
  112. package/lib/types/Tag.js.map +1 -0
  113. package/lib/types/TerminalBlock.d.ts.map +1 -0
  114. package/lib/types/TerminalBlock.js.map +1 -0
  115. package/lib/types/TextShimmer.d.ts.map +1 -0
  116. package/lib/types/TextShimmer.js.map +1 -0
  117. package/lib/types/Toast.d.ts.map +1 -0
  118. package/lib/types/Toast.js.map +1 -0
  119. package/lib/types/Tooltip.d.ts.map +1 -0
  120. package/lib/types/Tooltip.js.map +1 -0
  121. package/lib/types/UserMessageBubble.d.ts.map +1 -0
  122. package/lib/types/UserMessageBubble.js.map +1 -0
  123. package/lib/types/WebBlock.d.ts.map +1 -0
  124. package/lib/types/WebBlock.js.map +1 -0
  125. package/lib/types/ZoomControls.d.ts.map +1 -0
  126. package/lib/types/ZoomControls.js.map +1 -0
  127. package/lib/types/ansi.d.ts.map +1 -0
  128. package/lib/types/ansi.js.map +1 -0
  129. package/lib/types/clipboard.d.ts.map +1 -0
  130. package/lib/types/clipboard.js.map +1 -0
  131. package/lib/types/code-file-icon-artwork.d.ts.map +1 -0
  132. package/lib/types/code-file-icon-artwork.js.map +1 -0
  133. package/lib/types/code-file-types.d.ts.map +1 -0
  134. package/lib/types/code-file-types.js.map +1 -0
  135. package/lib/types/code-highlighting.d.ts.map +1 -0
  136. package/lib/types/code-highlighting.js.map +1 -0
  137. package/lib/types/darwin-desktop.d.ts.map +1 -0
  138. package/lib/types/darwin-desktop.js.map +1 -0
  139. package/lib/types/document-zoom.d.ts.map +1 -0
  140. package/lib/types/document-zoom.js.map +1 -0
  141. package/lib/types/file-drag-actions.d.ts.map +1 -0
  142. package/lib/types/file-drag-actions.js.map +1 -0
  143. package/lib/types/file-size.d.ts.map +1 -0
  144. package/lib/types/file-size.js.map +1 -0
  145. package/lib/types/focus.d.ts.map +1 -0
  146. package/lib/types/focus.js.map +1 -0
  147. package/lib/types/guide-artwork.d.ts.map +1 -0
  148. package/lib/types/guide-artwork.js.map +1 -0
  149. package/lib/types/head-tail-cap.d.ts.map +1 -0
  150. package/lib/types/head-tail-cap.js.map +1 -0
  151. package/lib/types/icons/artwork.d.ts +12 -0
  152. package/lib/types/icons/artwork.d.ts.map +1 -0
  153. package/lib/types/icons/artwork.js.map +1 -0
  154. package/lib/types/icons/index.d.ts +12 -0
  155. package/lib/types/icons/index.d.ts.map +1 -0
  156. package/lib/types/icons/index.js.map +1 -0
  157. package/lib/types/icons/props.d.ts.map +1 -0
  158. package/lib/types/icons/props.js.map +1 -0
  159. package/lib/types/icons/shared-artwork.d.ts.map +1 -0
  160. package/lib/types/icons/shared-artwork.js.map +1 -0
  161. package/lib/types/image-drag.d.ts.map +1 -0
  162. package/lib/types/image-drag.js.map +1 -0
  163. package/lib/types/index.d.ts +5 -4
  164. package/lib/types/index.d.ts.map +1 -0
  165. package/lib/types/index.js.map +1 -0
  166. package/lib/types/input-modality.d.ts.map +1 -0
  167. package/lib/types/input-modality.js.map +1 -0
  168. package/lib/types/keyboard-composition.d.ts.map +1 -0
  169. package/lib/types/keyboard-composition.js.map +1 -0
  170. package/lib/types/markdown/CodeBlock.d.ts +8 -1
  171. package/lib/types/markdown/CodeBlock.d.ts.map +1 -0
  172. package/lib/types/markdown/CodeBlock.js.map +1 -0
  173. package/lib/types/markdown/FenceBlocks.d.ts +31 -0
  174. package/lib/types/markdown/FenceBlocks.d.ts.map +1 -0
  175. package/lib/types/markdown/FenceBlocks.js.map +1 -0
  176. package/lib/types/markdown/JsonBlock.d.ts.map +1 -0
  177. package/lib/types/markdown/JsonBlock.js.map +1 -0
  178. package/lib/types/markdown/MarkdownDelegate.d.ts +23 -1
  179. package/lib/types/markdown/MarkdownDelegate.d.ts.map +1 -0
  180. package/lib/types/markdown/MarkdownDelegate.js.map +1 -0
  181. package/lib/types/markdown/MarkdownText.d.ts +2 -0
  182. package/lib/types/markdown/MarkdownText.d.ts.map +1 -0
  183. package/lib/types/markdown/MarkdownText.js.map +1 -0
  184. package/lib/types/markdown/cjkFriendlyStrong.d.ts.map +1 -0
  185. package/lib/types/markdown/cjkFriendlyStrong.js.map +1 -0
  186. package/lib/types/markdown/copy-tex.d.ts +14 -0
  187. package/lib/types/markdown/copy-tex.d.ts.map +1 -0
  188. package/lib/types/markdown/copy-tex.js.map +1 -0
  189. package/lib/types/markdown/diff-fence.d.ts +58 -0
  190. package/lib/types/markdown/diff-fence.d.ts.map +1 -0
  191. package/lib/types/markdown/diff-fence.js.map +1 -0
  192. package/lib/types/markdown/file-link.d.ts.map +1 -0
  193. package/lib/types/markdown/file-link.js.map +1 -0
  194. package/lib/types/markdown/highlight.d.ts +18 -0
  195. package/lib/types/markdown/highlight.d.ts.map +1 -0
  196. package/lib/types/markdown/highlight.js.map +1 -0
  197. package/lib/types/markdown/incremental.d.ts.map +1 -0
  198. package/lib/types/markdown/incremental.js.map +1 -0
  199. package/lib/types/markdown/katex.d.ts.map +1 -0
  200. package/lib/types/markdown/katex.js.map +1 -0
  201. package/lib/types/markdown/local-image-syntax.d.ts.map +1 -0
  202. package/lib/types/markdown/local-image-syntax.js.map +1 -0
  203. package/lib/types/markdown/mathCompatibility.d.ts.map +1 -0
  204. package/lib/types/markdown/mathCompatibility.js.map +1 -0
  205. package/lib/types/markdown/parse.d.ts.map +1 -0
  206. package/lib/types/markdown/parse.js.map +1 -0
  207. package/lib/types/markdown/plain-text.d.ts.map +1 -0
  208. package/lib/types/markdown/plain-text.js.map +1 -0
  209. package/lib/types/markdown/quote-text.d.ts.map +1 -0
  210. package/lib/types/markdown/quote-text.js.map +1 -0
  211. package/lib/types/markdown/render.d.ts.map +1 -0
  212. package/lib/types/markdown/render.js.map +1 -0
  213. package/lib/types/markdown/useViewportHighlighting.d.ts.map +1 -0
  214. package/lib/types/markdown/useViewportHighlighting.js.map +1 -0
  215. package/lib/types/markdown/windows-path-destinations.d.ts.map +1 -0
  216. package/lib/types/markdown/windows-path-destinations.js.map +1 -0
  217. package/lib/types/menu-submenu-position.d.ts +15 -0
  218. package/lib/types/menu-submenu-position.d.ts.map +1 -0
  219. package/lib/types/menu-submenu-position.js.map +1 -0
  220. package/lib/types/overlay-top-margin.d.ts.map +1 -0
  221. package/lib/types/overlay-top-margin.js.map +1 -0
  222. package/lib/types/plugin-artwork.d.ts.map +1 -0
  223. package/lib/types/plugin-artwork.js.map +1 -0
  224. package/lib/types/pointer-grace.d.ts.map +1 -0
  225. package/lib/types/pointer-grace.js.map +1 -0
  226. package/lib/types/rank-by-name.d.ts.map +1 -0
  227. package/lib/types/rank-by-name.js.map +1 -0
  228. package/lib/types/relative-time.d.ts.map +1 -0
  229. package/lib/types/relative-time.js.map +1 -0
  230. package/lib/types/settings-form/SettingsForm.d.ts.map +1 -0
  231. package/lib/types/settings-form/SettingsForm.js.map +1 -0
  232. package/lib/types/settings-form/fields.d.ts.map +1 -0
  233. package/lib/types/settings-form/fields.js.map +1 -0
  234. package/lib/types/settings-form/form-model.d.ts.map +1 -0
  235. package/lib/types/settings-form/form-model.js.map +1 -0
  236. package/lib/types/tooltip-placement.d.ts.map +1 -0
  237. package/lib/types/tooltip-placement.js.map +1 -0
  238. package/lib/types/use-clipboard-copy.d.ts.map +1 -0
  239. package/lib/types/use-clipboard-copy.js.map +1 -0
  240. package/lib/types/useAnchoredMaxHeight.d.ts.map +1 -0
  241. package/lib/types/useAnchoredMaxHeight.js.map +1 -0
  242. package/lib/types/useDismissOnOutsidePointer.d.ts.map +1 -0
  243. package/lib/types/useDismissOnOutsidePointer.js.map +1 -0
  244. package/lib/types/useMenuSubmenu.d.ts +43 -0
  245. package/lib/types/useMenuSubmenu.d.ts.map +1 -0
  246. package/lib/types/useMenuSubmenu.js.map +1 -0
  247. package/lib/types/useModalLayer.d.ts.map +1 -0
  248. package/lib/types/useModalLayer.js.map +1 -0
  249. package/lib/types/useRowDragPreview.d.ts.map +1 -0
  250. package/lib/types/useRowDragPreview.js.map +1 -0
  251. package/lib/types/user-text.d.ts.map +1 -0
  252. package/lib/types/user-text.js.map +1 -0
  253. package/package.json +9 -6
  254. package/src/AnimatedRows.module.css +7 -0
  255. package/src/AnimatedRows.tsx +195 -0
  256. package/src/BrandWordmark.tsx +59 -0
  257. package/src/Button.module.css +84 -0
  258. package/src/Button.tsx +36 -0
  259. package/src/Checkbox.module.css +28 -0
  260. package/src/Checkbox.tsx +34 -0
  261. package/src/CodeCard.module.css +85 -0
  262. package/src/CodeFileIcon.tsx +28 -0
  263. package/src/CodeToolbar.tsx +62 -0
  264. package/src/CommandText.module.css +12 -0
  265. package/src/CommandText.tsx +46 -0
  266. package/src/ConfigField.module.css +12 -0
  267. package/src/ConfigField.tsx +53 -0
  268. package/src/ConnectionIndicator.module.css +120 -0
  269. package/src/ConnectionIndicator.tsx +103 -0
  270. package/src/DetailDocument.module.css +67 -0
  271. package/src/DetailDocument.tsx +120 -0
  272. package/src/DiffBlock.module.css +82 -0
  273. package/src/DiffBlock.tsx +221 -0
  274. package/src/DisclosureRow.module.css +115 -0
  275. package/src/DisclosureRow.tsx +124 -0
  276. package/src/DraggableImage.tsx +26 -0
  277. package/src/FileTypeIcon.module.css +50 -0
  278. package/src/FileTypeIcon.tsx +285 -0
  279. package/src/FishLogo.tsx +28 -0
  280. package/src/FoldToggle.tsx +33 -0
  281. package/src/HoverCard.module.css +108 -0
  282. package/src/HoverCard.tsx +356 -0
  283. package/src/HoverCardGroup.tsx +77 -0
  284. package/src/ImageLightbox.module.css +54 -0
  285. package/src/ImageLightbox.tsx +72 -0
  286. package/src/ImagePreview.module.css +24 -0
  287. package/src/ImagePreview.tsx +36 -0
  288. package/src/InlineEditor.module.css +23 -0
  289. package/src/InlineEditor.tsx +69 -0
  290. package/src/Input.module.css +38 -0
  291. package/src/Input.tsx +24 -0
  292. package/src/JsonTree.module.css +371 -0
  293. package/src/JsonTree.tsx +850 -0
  294. package/src/LinkIcon.tsx +118 -0
  295. package/src/Menu.module.css +443 -0
  296. package/src/Menu.tsx +553 -0
  297. package/src/MenuGroup.module.css +37 -0
  298. package/src/MenuGroup.tsx +103 -0
  299. package/src/MenuRow.tsx +89 -0
  300. package/src/MenuSurface.module.css +65 -0
  301. package/src/MenuSurface.tsx +54 -0
  302. package/src/Modal.module.css +147 -0
  303. package/src/Modal.tsx +96 -0
  304. package/src/PathLabel.module.css +28 -0
  305. package/src/PathLabel.tsx +41 -0
  306. package/src/PermissionIcon.tsx +119 -0
  307. package/src/Pill.module.css +30 -0
  308. package/src/Pill.tsx +36 -0
  309. package/src/QuotePreview.module.css +138 -0
  310. package/src/QuotePreview.tsx +133 -0
  311. package/src/ReadBlock.module.css +45 -0
  312. package/src/ReadBlock.tsx +151 -0
  313. package/src/ReferenceIcon.tsx +49 -0
  314. package/src/RiskConfirmation.module.css +47 -0
  315. package/src/RiskConfirmation.tsx +79 -0
  316. package/src/RowDragPreview.module.css +12 -0
  317. package/src/SearchBlock.module.css +114 -0
  318. package/src/SearchBlock.tsx +281 -0
  319. package/src/SegmentedControl.module.css +81 -0
  320. package/src/SegmentedControl.tsx +140 -0
  321. package/src/SegmentedTabs.module.css +77 -0
  322. package/src/SegmentedTabs.tsx +84 -0
  323. package/src/ShortcutKeys.module.css +33 -0
  324. package/src/ShortcutKeys.tsx +12 -0
  325. package/src/SiteGlyph.tsx +149 -0
  326. package/src/StateDot.module.css +100 -0
  327. package/src/StateDot.tsx +77 -0
  328. package/src/SubmenuPanel.tsx +51 -0
  329. package/src/Switch.module.css +49 -0
  330. package/src/Switch.tsx +42 -0
  331. package/src/Tag.module.css +57 -0
  332. package/src/Tag.tsx +42 -0
  333. package/src/TerminalBlock.module.css +207 -0
  334. package/src/TerminalBlock.tsx +294 -0
  335. package/src/TextShimmer.module.css +88 -0
  336. package/src/TextShimmer.tsx +58 -0
  337. package/src/Toast.module.css +102 -0
  338. package/src/Toast.tsx +101 -0
  339. package/src/Tooltip.module.css +68 -0
  340. package/src/Tooltip.tsx +273 -0
  341. package/src/UserMessageBubble.module.css +11 -0
  342. package/src/UserMessageBubble.tsx +16 -0
  343. package/src/WebBlock.module.css +153 -0
  344. package/src/WebBlock.tsx +196 -0
  345. package/src/ZoomControls.module.css +54 -0
  346. package/src/ZoomControls.tsx +92 -0
  347. package/src/ansi.ts +447 -0
  348. package/src/clipboard.ts +47 -0
  349. package/src/code-file-icon-artwork.manifest.json +71 -0
  350. package/src/code-file-icon-artwork.ts +60 -0
  351. package/src/code-file-types.ts +340 -0
  352. package/src/code-highlighting.ts +25 -0
  353. package/src/css-modules.d.ts +6 -0
  354. package/src/darwin-desktop.ts +11 -0
  355. package/src/document-zoom.ts +12 -0
  356. package/src/file-drag-actions.ts +29 -0
  357. package/src/file-size.ts +16 -0
  358. package/src/focus.ts +44 -0
  359. package/src/guide-artwork.tsx +32 -0
  360. package/src/head-tail-cap.ts +27 -0
  361. package/src/icons/artwork.ts +156 -0
  362. package/src/icons/index.tsx +634 -0
  363. package/src/icons/props.ts +8 -0
  364. package/src/icons/shared-artwork.tsx +71 -0
  365. package/src/image-drag.ts +84 -0
  366. package/src/index.ts +142 -0
  367. package/src/input-modality.ts +59 -0
  368. package/src/keyboard-composition.ts +36 -0
  369. package/src/markdown/CodeBlock.module.css +209 -0
  370. package/src/markdown/CodeBlock.tsx +268 -0
  371. package/src/markdown/FenceBlocks.tsx +51 -0
  372. package/src/markdown/JsonBlock.module.css +34 -0
  373. package/src/markdown/JsonBlock.tsx +36 -0
  374. package/src/markdown/MarkdownDelegate.tsx +102 -0
  375. package/src/markdown/MarkdownText.module.css +511 -0
  376. package/src/markdown/MarkdownText.tsx +218 -0
  377. package/src/markdown/cjkFriendlyStrong.ts +83 -0
  378. package/src/markdown/copy-tex.ts +53 -0
  379. package/src/markdown/diff-fence.ts +212 -0
  380. package/src/markdown/file-link.ts +45 -0
  381. package/src/markdown/highlight.ts +689 -0
  382. package/src/markdown/incremental.ts +360 -0
  383. package/src/markdown/katex.tsx +90 -0
  384. package/src/markdown/local-image-syntax.ts +29 -0
  385. package/src/markdown/mathCompatibility.ts +349 -0
  386. package/src/markdown/parse.ts +49 -0
  387. package/src/markdown/plain-text.ts +121 -0
  388. package/src/markdown/quote-text.ts +10 -0
  389. package/src/markdown/render.tsx +834 -0
  390. package/src/markdown/useViewportHighlighting.ts +72 -0
  391. package/src/markdown/windows-path-destinations.ts +34 -0
  392. package/src/menu-submenu-position.ts +20 -0
  393. package/src/overlay-top-margin.ts +18 -0
  394. package/src/plugin-artwork.tsx +110 -0
  395. package/src/pointer-grace.ts +47 -0
  396. package/src/rank-by-name.ts +93 -0
  397. package/src/relative-time.ts +36 -0
  398. package/src/settings-form/SettingsForm.module.css +53 -0
  399. package/src/settings-form/SettingsForm.tsx +74 -0
  400. package/src/settings-form/fields.module.css +153 -0
  401. package/src/settings-form/fields.tsx +151 -0
  402. package/src/settings-form/form-model.ts +393 -0
  403. package/src/tooltip-placement.ts +60 -0
  404. package/src/use-clipboard-copy.ts +44 -0
  405. package/src/useAnchoredMaxHeight.ts +45 -0
  406. package/src/useDismissOnOutsidePointer.ts +34 -0
  407. package/src/useMenuSubmenu.ts +182 -0
  408. package/src/useModalLayer.ts +108 -0
  409. package/src/useRowDragPreview.ts +76 -0
  410. package/src/user-text.module.css +46 -0
  411. package/src/user-text.tsx +67 -0
  412. package/lib/types/useAnchoredPosition.d.ts +0 -36
@@ -0,0 +1,834 @@
1
+ /**
2
+ * Direct mdast→React markdown renderer. Replaces the react-markdown /
3
+ * remark-rehype pipeline with one switch over parsed nodes so streaming can
4
+ * cache frozen blocks as React elements; the rendered DOM is pinned
5
+ * byte-for-byte by `tests/fixtures/markdown-dom` and must not drift.
6
+ *
7
+ * External links reject executable and embedded-document protocols; settled
8
+ * local file links use an explicit owner callback. Images additionally require
9
+ * absolute HTTP(S), raw HTML renders as literal text (no HTML enters the
10
+ * DOM), and KaTeX runs without trusted commands. Fragment-only URLs are not
11
+ * absolute, so footnote references and back-references render as plain
12
+ * text rather than in-page links.
13
+ *
14
+ * Merge-extensible node unions fall through the documented default (render
15
+ * nothing) rather than ending in assertNever: grammars registered elsewhere
16
+ * may add node types this renderer has no mapping for.
17
+ */
18
+
19
+ import type { HTMLAttributes } from 'react'
20
+ import { Fragment, createElement, useCallback, useState } from 'react'
21
+ import type { Key, ReactNode } from 'react'
22
+ import clsx from 'clsx'
23
+ import type * as Md from 'mdast'
24
+ import type {} from 'mdast-util-math'
25
+ import { normalizeUri } from 'micromark-util-sanitize-uri'
26
+ import type { CodeToolbarLabels } from '../CodeToolbar.tsx'
27
+ import { FenceCodeBlock, FenceMathBlock } from './FenceBlocks.tsx'
28
+ import { isExplicitFilePath, parseFileLink } from './file-link.ts'
29
+ import { renderTexToReact } from './katex.tsx'
30
+ import { LinkIconMedium, classifyLinkPath } from '../LinkIcon.tsx'
31
+ import { useMarkdownDelegate } from './MarkdownDelegate.tsx'
32
+ import { HoverCard } from '../HoverCard.tsx'
33
+ import { DraggableImage } from '../DraggableImage.tsx'
34
+ import { ImageLightbox } from '../ImageLightbox.tsx'
35
+ import { ImagePreview } from '../ImagePreview.tsx'
36
+ import type { PositionedBlock } from './incremental.ts'
37
+ import css from './MarkdownText.module.css'
38
+
39
+ /** Copy-button labels forwarded to fence CodeBlocks (this package is cordis-free, so copy arrives via props). */
40
+ export interface MarkdownCodeLabels {
41
+ /** Copy-button idle label. */
42
+ copyLabel: string
43
+ /** Copy-button label during the post-copy confirmation window. */
44
+ copiedLabel: string
45
+ /** Shared card controls; omitted for custom toolbar layouts. */
46
+ toolbarLabels?: CodeToolbarLabels | undefined
47
+ }
48
+
49
+ /** Localized chrome for a Markdown document. */
50
+ export interface MarkdownLabels {
51
+ code: MarkdownCodeLabels
52
+ footnotes: string
53
+ }
54
+
55
+ function sanitizeUrl(url: string): string {
56
+ if (isExplicitFilePath(url)) return ''
57
+ try {
58
+ switch (new URL(url).protocol) {
59
+ case 'javascript:':
60
+ case 'vbscript:':
61
+ case 'data:':
62
+ case 'blob:':
63
+ return ''
64
+ default:
65
+ return url
66
+ }
67
+ } catch {
68
+ // Relative and otherwise unparsable destinations are disallowed alongside
69
+ // disallowed protocols; new URL() has no other failure mode for strings.
70
+ return ''
71
+ }
72
+ }
73
+
74
+ function remoteImageUrl(url: string): string | undefined {
75
+ try {
76
+ const protocol = new URL(url).protocol
77
+ return protocol === 'http:' || protocol === 'https:' ? url : undefined
78
+ } catch {
79
+ // Same single failure mode as above: not an absolute URL.
80
+ return undefined
81
+ }
82
+ }
83
+
84
+ /** Authenticated Host media routes as the Desktop application addresses them. */
85
+ const DESKTOP_MEDIA_ROUTES = [
86
+ 'dsh-app://app/api/file?', 'dsh-app://app/api/plugin-market/detail-file?', 'dsh-app://app/api/plugin-manager/detail-file?',
87
+ ]
88
+
89
+ /** Rewritten images may use Web media protocols or the Desktop application's media routes. */
90
+ function vocabularyImageUrl(url: string): string | undefined {
91
+ try {
92
+ const protocol = new URL(url).protocol
93
+ return protocol === 'http:' || protocol === 'https:' || protocol === 'blob:' || protocol === 'data:'
94
+ || DESKTOP_MEDIA_ROUTES.some(route => url.startsWith(route))
95
+ ? url
96
+ : undefined
97
+ } catch {
98
+ // A vocabulary result must be an absolute URL; anything else stays a miss.
99
+ return undefined
100
+ }
101
+ }
102
+
103
+ /**
104
+ * The displayable source for one image destination: absolute HTTP(S) as
105
+ * authored, otherwise the context's local-path vocabulary when it vouches for
106
+ * the destination. Either miss leaves the authored fallback (alt text) to the
107
+ * caller.
108
+ * @param url - The authored markdown destination.
109
+ * @param pathImages - Rewriting vocabulary, when the render pass has one.
110
+ * @param load - The mounted image's load number for rewritten URLs.
111
+ * @returns The displayable image URL, or undefined.
112
+ */
113
+ function imageSource(url: string, pathImages: MarkdownPathImages | undefined, load: number): string | undefined {
114
+ const remote = remoteImageUrl(sanitizeUrl(normalizeUri(url)))
115
+ if (remote !== undefined) return remote
116
+ const rewritten = pathImages?.resolve(url)
117
+ const allowed = rewritten === undefined ? undefined : vocabularyImageUrl(rewritten)
118
+ return allowed === undefined ? undefined : freshImageUrl(allowed, load)
119
+ }
120
+
121
+ // A module counter, not useId: useId derives from tree position, so images at
122
+ // the same position in two sessions would share a URL.
123
+ let imageLoads = 0
124
+ const nextImageLoad = (): number => ++imageLoads
125
+
126
+ /**
127
+ * Tag a Host file-route image URL with its mount's load number. Browsers reuse
128
+ * a same-URL image within one document despite `no-store`, so without the tag
129
+ * a newly rendered image of a rewritten file would show the earlier bytes.
130
+ * @param url - Absolute resolved image URL; URLs outside the `api/file` route stay unchanged.
131
+ * @param load - Number allocated once per mounted image or file link.
132
+ * @returns The URL with a `load` query parameter, or the unchanged URL.
133
+ */
134
+ function freshImageUrl(url: string, load: number): string {
135
+ let fresh: URL
136
+ try { fresh = new URL(url) }
137
+ catch { return url } // Only an unparsable owner-supplied URL throws; it is emitted as before.
138
+ if (!fresh.pathname.endsWith('/api/file')) return url
139
+ // Appending preserves the resolver's existing query encoding.
140
+ fresh.search = `${fresh.search === '' ? '?' : `${fresh.search}&`}load=${load}`
141
+ return fresh.href
142
+ }
143
+
144
+ /** Link/image reference targets collected from a document (first definition per identifier wins, as in CommonMark). */
145
+ export interface ReferenceTargets {
146
+ /** Link/image definitions keyed by upper-cased identifier. */
147
+ definitions: Map<string, Md.Definition>
148
+ /** Footnote definitions keyed by upper-cased identifier. */
149
+ footnotes: Map<string, Md.FootnoteDefinition>
150
+ }
151
+
152
+ /**
153
+ * Create an empty {@link ReferenceTargets}.
154
+ * @returns Fresh empty maps.
155
+ */
156
+ export function createReferenceTargets(): ReferenceTargets {
157
+ return { definitions: new Map(), footnotes: new Map() }
158
+ }
159
+
160
+ /**
161
+ * Record every definition and footnote definition under `nodes` into
162
+ * `targets`, depth-first, keeping the first definition per identifier.
163
+ * @param nodes - Subtrees to walk (top-level blocks or any nested children).
164
+ * @param targets - Accumulator, typically shared across incremental segments.
165
+ */
166
+ export function collectReferenceTargets(
167
+ nodes: readonly Md.RootContent[],
168
+ targets: ReferenceTargets,
169
+ ): void {
170
+ for (const node of nodes) {
171
+ if (node.type === 'definition') {
172
+ const id = node.identifier.toUpperCase()
173
+ if (!targets.definitions.has(id)) targets.definitions.set(id, node)
174
+ } else if (node.type === 'footnoteDefinition') {
175
+ const id = node.identifier.toUpperCase()
176
+ if (!targets.footnotes.has(id)) targets.footnotes.set(id, node)
177
+ }
178
+ if ('children' in node) collectReferenceTargets(node.children, targets)
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Local-path image vocabulary for image destinations: the owner maps an
184
+ * authored destination that fails the remote-URL allowlist (an absolute local
185
+ * file path, for example) to a displayable URL it can vouch for. Absent
186
+ * wherever no such vocabulary exists, authored local destinations keep their
187
+ * documented fallback (the image's alt text). Rewritten destinations must be
188
+ * absolute; the renderer re-checks their protocol before emitting them.
189
+ */
190
+ export interface MarkdownPathImages {
191
+ /**
192
+ * Resolve one authored image destination.
193
+ * @param value - The destination exactly as the markdown author wrote it.
194
+ * @returns A displayable absolute URL, or undefined when the destination
195
+ * names no displayable image — it then stays inert alt text. The renderer
196
+ * appends a per-mount `load` query parameter to `api/file` route results.
197
+ */
198
+ resolve(value: string): string | undefined
199
+ }
200
+
201
+ /**
202
+ * File-mention affordance for inline code: the owner resolves an authored
203
+ * token to the file it names, using its own vocabulary of real files — the
204
+ * renderer never guesses at what looks like a path.
205
+ */
206
+ export interface MarkdownFileMentions {
207
+ /**
208
+ * Resolve one inline-code token.
209
+ * @param value - The authored token, exactly as written.
210
+ * @returns The opener with its accessible label and full-path title, or
211
+ * undefined when the token names no known file — it then stays inert code.
212
+ */
213
+ resolve(value: string): {
214
+ open: () => void
215
+ contextMenuProps?: Pick<HTMLAttributes<HTMLElement>, 'onContextMenu' | 'onKeyDown' | 'tabIndex'>
216
+ label: string
217
+ title: string
218
+ } | undefined
219
+ }
220
+
221
+ /**
222
+ * One render pass's state: immutable options and targets plus the footnote
223
+ * numbering accumulated in document order while references render.
224
+ */
225
+ export interface MarkdownRenderContext {
226
+ /** Streaming arm: fences highlight incrementally as they grow; TeX (including ```math fences) stays literal until the settled pass. */
227
+ readonly streaming: boolean
228
+ /** Localized fence copy-button labels. */
229
+ readonly labels: MarkdownLabels
230
+ /** Inside a blockquote's children: tables there always fill the quote's width. */
231
+ readonly inBlockquote?: boolean
232
+ /** Inline-code file mentions; absent wherever no opener vocabulary exists. */
233
+ readonly fileMentions: MarkdownFileMentions | undefined
234
+ /** Local-path image vocabulary; absent wherever no rewriting owner exists. */
235
+ readonly pathImages: MarkdownPathImages | undefined
236
+ /** Raw HTML renders nothing instead of literal text. */
237
+ readonly omitHtml: boolean
238
+ /** Inside an anchor's children: interactive mentions must not nest there. */
239
+ readonly inLink?: boolean
240
+ /** Reference targets visible to this pass. */
241
+ readonly targets: ReferenceTargets
242
+ /** Footnote identifiers in first-reference order; a footnote's number is its 1-based index here. */
243
+ readonly footnoteOrder: string[]
244
+ /** References rendered per identifier; drives the section's back-reference count. */
245
+ readonly footnoteCounts: Map<string, number>
246
+ }
247
+
248
+ /**
249
+ * Render top-level blocks. Nodes that render nothing (definitions, unmapped
250
+ * types) are dropped rather than kept as null placeholders, matching the
251
+ * replaced pipeline's child lists so separator newlines land identically.
252
+ * @param blocks - Blocks with their stream-stable render keys.
253
+ * @param context - The pass state; footnote numbering mutates in document order.
254
+ * @returns One React node per rendered block.
255
+ */
256
+ export function renderBlocks(
257
+ blocks: readonly PositionedBlock[],
258
+ context: MarkdownRenderContext,
259
+ ): ReactNode[] {
260
+ return blocks
261
+ .map(block => renderNode(block.node, block.key, context))
262
+ .filter(element => element !== null)
263
+ }
264
+
265
+ /**
266
+ * Interleave the newline text nodes the replaced pipeline emitted between
267
+ * block-level children. They are invisible between elements but coalesce
268
+ * into adjacent literal raw-HTML text, where the DOM parity fixtures pin
269
+ * them.
270
+ * @param elements - Rendered block children with empty renders already dropped.
271
+ * @param edges - Also emit the leading and trailing newline (hast's loose wrap).
272
+ * @returns The interleaved children.
273
+ */
274
+ export function wrapBlockChildren(elements: readonly ReactNode[], edges: boolean): ReactNode[] {
275
+ const wrapped: ReactNode[] = []
276
+ for (const element of elements) {
277
+ if (edges || wrapped.length > 0) wrapped.push('\n')
278
+ wrapped.push(element)
279
+ }
280
+ if (edges && elements.length > 0) wrapped.push('\n')
281
+ return wrapped
282
+ }
283
+
284
+ /**
285
+ * A block child rendered for a parent that must tell paragraphs apart from
286
+ * other blocks (list items unwrap them when tight; footnote bodies receive
287
+ * their back-references inside the trailing paragraph).
288
+ */
289
+ type BlockEntry = { paragraph: ReactNode[] } | { element: ReactNode }
290
+
291
+ /** Render container children into {@link BlockEntry} values, dropping empty renders. */
292
+ function renderBlockEntries(
293
+ blocks: readonly Md.RootContent[],
294
+ context: MarkdownRenderContext,
295
+ ): BlockEntry[] {
296
+ const entries: BlockEntry[] = []
297
+ for (const [index, block] of blocks.entries()) {
298
+ if (block.type === 'paragraph') {
299
+ entries.push({ paragraph: renderChildren(block.children, context) })
300
+ } else {
301
+ const element = renderNode(block, index, context)
302
+ if (element !== null) entries.push({ element })
303
+ }
304
+ }
305
+ return entries
306
+ }
307
+
308
+ function renderChildren(
309
+ nodes: readonly Md.RootContent[],
310
+ context: MarkdownRenderContext,
311
+ ): ReactNode[] {
312
+ return nodes.map((node, index) => renderNode(node, index, context))
313
+ }
314
+
315
+ function renderNode(node: Md.RootContent, key: Key, context: MarkdownRenderContext): ReactNode {
316
+ switch (node.type) {
317
+ case 'text':
318
+ return node.value
319
+ case 'paragraph':
320
+ return <p key={key}>{renderChildren(node.children, context)}</p>
321
+ case 'heading':
322
+ return createElement(`h${node.depth}`, { key }, ...renderChildren(node.children, context))
323
+ case 'blockquote':
324
+ return (
325
+ <blockquote key={key}>
326
+ {wrapBlockChildren(
327
+ renderChildren(node.children, { ...context, inBlockquote: true }).filter(child => child !== null),
328
+ true,
329
+ )}
330
+ </blockquote>
331
+ )
332
+ case 'thematicBreak':
333
+ return <hr key={key} />
334
+ case 'break':
335
+ // The replaced pipeline emitted a newline text node after each <br>.
336
+ return <Fragment key={key}><br />{'\n'}</Fragment>
337
+ case 'strong':
338
+ return <strong key={key}>{renderChildren(node.children, context)}</strong>
339
+ case 'emphasis':
340
+ return <em key={key}>{renderChildren(node.children, context)}</em>
341
+ case 'delete':
342
+ return <del key={key}>{renderChildren(node.children, context)}</del>
343
+ case 'inlineCode': {
344
+ // Parity with mdast-util-to-hast: inline code renders line endings as spaces.
345
+ const value = node.value.replace(/\r?\n|\r/g, ' ')
346
+ // An inline-code token that is entirely an absolute HTTP(S) URL keeps
347
+ // its code chrome and gains the same safe external anchor as a link;
348
+ // commands, partial URLs, and other schemes stay inert. The value is
349
+ // authored text, not a parsed destination, so no normalizeUri: port,
350
+ // path, and query render unchanged.
351
+ const href = inlineCodeHttpUrl(value)
352
+ if (href !== undefined) return <code key={key}>{renderSafeLink(href, [value], 'link')}</code>
353
+ // A token the owner's file-mention vocabulary recognizes opens that
354
+ // file; the resolver, not this renderer, decides what names a file.
355
+ // Inside an anchor the token stays inert — a button cannot nest there.
356
+ const mention = context.inLink === true ? undefined : context.fileMentions?.resolve(value)
357
+ if (mention !== undefined) {
358
+ return (
359
+ <code key={key}>
360
+ <button
361
+ type="button"
362
+ className={css.fileMention}
363
+ title={mention.title}
364
+ aria-label={mention.label}
365
+ onClick={mention.open}
366
+ {...mention.contextMenuProps}
367
+ >
368
+ <LinkIconMedium kind={classifyLinkPath(value)} className={css.linkIcon} />
369
+ {value}
370
+ </button>
371
+ </code>
372
+ )
373
+ }
374
+ return <code key={key}>{value}</code>
375
+ }
376
+ case 'html':
377
+ // No HTML parser enters the pipeline: raw HTML is literal text, or nothing where the owner omits it.
378
+ return context.omitHtml ? null : node.value
379
+ case 'code':
380
+ return renderCode(node, key, context)
381
+ case 'math':
382
+ return <Fragment key={key}>{renderTexToReact(node.value, true)}</Fragment>
383
+ case 'inlineMath':
384
+ return <Fragment key={key}>{renderTexToReact(node.value, false)}</Fragment>
385
+ case 'list':
386
+ return renderList(node, key, context)
387
+ case 'listItem':
388
+ // Reachable only in hand-built trees: the grammar emits items inside lists.
389
+ return renderListItem(node, listItemLoose(node), key, context)
390
+ case 'table':
391
+ return renderTable(node, key, context)
392
+ case 'link':
393
+ return renderAnchor(
394
+ node.url, renderChildren(node.children, { ...context, inLink: true }), key,
395
+ !anchorWrapsOnlyImages(node.children), context.streaming,
396
+ )
397
+ case 'linkReference':
398
+ return renderLinkReference(node, key, context)
399
+ case 'image':
400
+ return renderImage(node.url, node.alt ?? '', key, context)
401
+ case 'imageReference':
402
+ return renderImageReference(node, key, context)
403
+ case 'footnoteReference':
404
+ return renderFootnoteReference(node, key, context)
405
+ case 'definition':
406
+ case 'footnoteDefinition':
407
+ // Targets render elsewhere: definitions resolve references in place;
408
+ // footnote bodies render in the trailing section.
409
+ return null
410
+ default:
411
+ // Documented default for the merge-extensible union: node types without
412
+ // a mapping (tableRow/tableCell outside a table, frontmatter, future
413
+ // grammar contributions) render nothing.
414
+ return null
415
+ }
416
+ }
417
+
418
+ function renderCode(node: Md.Code, key: Key, context: MarkdownRenderContext): ReactNode {
419
+ const language = node.lang ?? undefined
420
+ if (node.value === '') {
421
+ // Parity: the replaced pipeline kept the stock <pre> for an empty fence.
422
+ return (
423
+ <pre key={key}>
424
+ <code className={language === undefined ? undefined : `language-${language}`} />
425
+ </pre>
426
+ )
427
+ }
428
+ // The replaced pipeline recovered the grammar id from the hast class with
429
+ // /language-([\w-]+)/, which truncates at the first non-word character.
430
+ const lang = language === undefined ? undefined : /^[\w-]+/.exec(language)?.[0]
431
+ // Streaming keys are source offsets, stable while the fence grows, so the
432
+ // block instance (and its incremental highlight session) survives every
433
+ // chunk. A fence whose info string is still mid-chunk has no content yet and
434
+ // took the empty-fence arm above, so `lang` here is final.
435
+ if (lang === undefined) {
436
+ return <FenceCodeBlock key={key} code={node.value} streaming={context.streaming} labels={context.labels.code} />
437
+ }
438
+ return (
439
+ <MarkdownFenceSeat
440
+ key={key} lang={lang} meta={node.meta ?? undefined} code={node.value} streaming={context.streaming} labels={context.labels.code}
441
+ />
442
+ )
443
+ }
444
+
445
+ /**
446
+ * One fence whose language is final: the delegate's renderer when the owner
447
+ * supplies one, otherwise the built-in math and code blocks. Reading the
448
+ * delegate in this Component rather than in the render pass lets cached
449
+ * streaming elements follow a provider change.
450
+ */
451
+ function MarkdownFenceSeat({ lang, meta, code, streaming, labels }: {
452
+ readonly lang: string
453
+ readonly meta: string | undefined
454
+ readonly code: string
455
+ readonly streaming: boolean
456
+ readonly labels: MarkdownCodeLabels
457
+ }): ReactNode {
458
+ const { renderCode } = useMarkdownDelegate()
459
+ if (renderCode !== undefined) {
460
+ // The seat box spaces the fence among its siblings, so the delegate's blocks carry no margins of their own.
461
+ return <div className={css.fenceSeat}>{renderCode({ lang: lang.toLowerCase(), code, streaming, meta })}</div>
462
+ }
463
+ // ```math fences render as display TeX once settled; while streaming they stay literal.
464
+ if (!streaming && lang === 'math') return <FenceMathBlock code={code} />
465
+ return <FenceCodeBlock lang={lang} code={code} streaming={streaming} labels={labels} />
466
+ }
467
+
468
+ /** A list is loose when it or any of its items is spread; every item then keeps its paragraphs. */
469
+ function listLoose(list: Md.List): boolean {
470
+ return (list.spread ?? false) || list.children.some(listItemLoose)
471
+ }
472
+
473
+ function listItemLoose(item: Md.ListItem): boolean {
474
+ return item.spread ?? item.children.length > 1
475
+ }
476
+
477
+ function renderList(node: Md.List, key: Key, context: MarkdownRenderContext): ReactNode {
478
+ const loose = listLoose(node)
479
+ const properties: { start?: number; className?: string } = {}
480
+ if (typeof node.start === 'number' && node.start !== 1) properties.start = node.start
481
+ if (node.children.some(item => typeof item.checked === 'boolean')) {
482
+ properties.className = 'contains-task-list'
483
+ }
484
+ return createElement(
485
+ node.ordered === true ? 'ol' : 'ul',
486
+ { key, ...properties },
487
+ ...node.children.map((item, index) => renderListItem(item, loose, index, context)),
488
+ )
489
+ }
490
+
491
+ function renderListItem(
492
+ item: Md.ListItem,
493
+ loose: boolean,
494
+ key: Key,
495
+ context: MarkdownRenderContext,
496
+ ): ReactNode {
497
+ const entries = renderBlockEntries(item.children, context)
498
+ const task = typeof item.checked === 'boolean'
499
+ if (task) {
500
+ const checkbox = <input key="task-checkbox" type="checkbox" checked={item.checked === true} disabled />
501
+ const head = entries[0]
502
+ if (head !== undefined && 'paragraph' in head) {
503
+ head.paragraph = head.paragraph.length > 0 ? [checkbox, ' ', ...head.paragraph] : [checkbox]
504
+ } else {
505
+ entries.unshift({ paragraph: [checkbox] })
506
+ }
507
+ }
508
+ // Newline placement and tight-paragraph unwrapping mirror
509
+ // mdast-util-to-hast's list-item handler: a newline before every child
510
+ // except a tight leading paragraph, and after a trailing non-paragraph
511
+ // (or any trailing child when loose).
512
+ const parts: ReactNode[] = []
513
+ for (const [index, entry] of entries.entries()) {
514
+ const isParagraph = 'paragraph' in entry
515
+ if (loose || index !== 0 || !isParagraph) parts.push('\n')
516
+ if (!isParagraph) parts.push(entry.element)
517
+ else if (loose) parts.push(<p key={`p-${index}`}>{entry.paragraph}</p>)
518
+ else parts.push(<Fragment key={`p-${index}`}>{entry.paragraph}</Fragment>)
519
+ }
520
+ const tail = entries[entries.length - 1]
521
+ if (tail !== undefined && (loose || !('paragraph' in tail))) parts.push('\n')
522
+ return (
523
+ <li key={key} className={task ? 'task-list-item' : undefined}>
524
+ {parts}
525
+ </li>
526
+ )
527
+ }
528
+
529
+ function renderTable(node: Md.Table, key: Key, context: MarkdownRenderContext): ReactNode {
530
+ const align = node.align ?? null
531
+ const [headRow, ...bodyRows] = node.children
532
+ const columns = align === null ? headRow?.children.length ?? 0 : align.length
533
+ // Four or more columns read as a comparison matrix: the block keeps the
534
+ // table at natural width and exposes the stable `md-table-wide` hook so a
535
+ // hosting layout (the chat transcript) can widen it past the message
536
+ // column. Narrower tables — and any table inside a blockquote — fill the
537
+ // column and wrap instead (deepsuite chat TableWrapper parity).
538
+ const wide = columns >= 4 && context.inBlockquote !== true
539
+ return (
540
+ // On hover-capable inputs, wide tables rest with overflow-x hidden (the
541
+ // hover-revealed bar in MarkdownText.module.css), dropping Chromium's implicit scroller
542
+ // focusability — the explicit tabindex keeps them keyboard-reachable,
543
+ // and :focus-visible restores scrolling.
544
+ <div
545
+ key={key}
546
+ className={clsx(css.tableScroll, wide ? 'md-table-wide' : css.tableFill)}
547
+ tabIndex={wide ? 0 : undefined}
548
+ >
549
+ <table>
550
+ {headRow !== undefined && <thead>{renderTableRow(headRow, 'th', align, 0, context)}</thead>}
551
+ {bodyRows.length > 0 && (
552
+ <tbody>
553
+ {bodyRows.map((row, index) => renderTableRow(row, 'td', align, index + 1, context))}
554
+ </tbody>
555
+ )}
556
+ </table>
557
+ </div>
558
+ )
559
+ }
560
+
561
+ function renderTableRow(
562
+ row: Md.TableRow,
563
+ cellTag: 'th' | 'td',
564
+ align: readonly Md.AlignType[] | null,
565
+ key: Key,
566
+ context: MarkdownRenderContext,
567
+ ): ReactNode {
568
+ // With column alignment present, every row renders exactly one cell per
569
+ // column, padding or truncating the row (mdast-util-to-hast parity).
570
+ const length = align === null ? row.children.length : align.length
571
+ const cells: ReactNode[] = []
572
+ for (let index = 0; index < length; index++) {
573
+ const cell = row.children[index]
574
+ const alignValue = align?.[index]
575
+ cells.push(createElement(
576
+ cellTag,
577
+ // hast-util-to-jsx-runtime's default tableCellAlignToStyle turned the
578
+ // deprecated align attribute into an inline style; keep that DOM.
579
+ { key: index, style: alignValue == null ? undefined : { textAlign: alignValue } },
580
+ ...(cell === undefined ? [] : renderChildren(cell.children, context)),
581
+ ))
582
+ }
583
+ return <tr key={key}>{cells}</tr>
584
+ }
585
+
586
+ /**
587
+ * True when an anchor's markdown children are all images, so the anchor is a
588
+ * clickable picture (badge, thumbnail): the leading URL glyph would dangle
589
+ * beside the image instead of leading link text, so those anchors skip it.
590
+ */
591
+ function anchorWrapsOnlyImages(children: Md.PhrasingContent[]): boolean {
592
+ return children.length > 0 && children.every(child => child.type === 'image' || child.type === 'imageReference')
593
+ }
594
+
595
+ /** Anchor over a safe absolute href, with optional owner navigation for HTTP(S). */
596
+ function renderSafeLink(href: string, children: ReactNode[], key: Key, glyph = true): ReactNode {
597
+ const safeHref = sanitizeUrl(href)
598
+ if (safeHref === '') return <Fragment key={key}>{children}</Fragment>
599
+ return <MarkdownAnchor key={key} href={safeHref} glyph={glyph}>{children}</MarkdownAnchor>
600
+ }
601
+
602
+ function MarkdownAnchor({ href, glyph, children }: {
603
+ readonly href: string
604
+ readonly glyph: boolean
605
+ readonly children: ReactNode[]
606
+ }): ReactNode {
607
+ const { openExternalLink, getTriggerProps } = useMarkdownDelegate()
608
+ const external = ['http:', 'https:'].includes(new URL(href).protocol)
609
+ const open = external ? openExternalLink : undefined
610
+ return (
611
+ <a
612
+ href={href}
613
+ {...external ? getTriggerProps?.({ kind: 'url', url: href }) : {}}
614
+ {...(external ? { target: '_blank', rel: 'noopener noreferrer' } : {})}
615
+ onClick={open === undefined ? undefined : (event) => {
616
+ if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return
617
+ event.preventDefault()
618
+ open(href)
619
+ }}
620
+ >
621
+ {glyph && <LinkIconMedium kind="url" href={href} className={css.linkIcon} />}
622
+ {children}
623
+ </a>
624
+ )
625
+ }
626
+
627
+ /** Local destinations use the scoped file delegate after settlement. */
628
+ function renderAnchor(url: string, children: ReactNode[], key: Key, glyph = true, streaming = false): ReactNode {
629
+ const file = parseFileLink(url)
630
+ if (file !== undefined) {
631
+ if (streaming) return <Fragment key={key}>{children}</Fragment>
632
+ return <MarkdownFileLink key={key} file={file} glyph={glyph}>{children}</MarkdownFileLink>
633
+ }
634
+ return renderSafeLink(normalizeUri(url), children, key, glyph)
635
+ }
636
+
637
+ function MarkdownFileLink({ file, glyph, children }: {
638
+ readonly file: { path: string; line?: number }
639
+ readonly glyph: boolean
640
+ readonly children: ReactNode[]
641
+ }): ReactNode {
642
+ const { openFile, fileImages, getTriggerProps } = useMarkdownDelegate()
643
+ const [load] = useState(nextImageLoad)
644
+ if (openFile === undefined) return <>{children}</>
645
+ // Pure-image anchors already contain their preview and keep one navigation target.
646
+ const preview = glyph && classifyLinkPath(file.path) === 'image' ? fileImages : undefined
647
+ const resolved = preview?.resolve(file.path)
648
+ const src = resolved === undefined ? undefined : freshImageUrl(resolved, load)
649
+ const anchor = (
650
+ <button
651
+ type="button"
652
+ className={clsx(css.fileMention, css.fileLink)}
653
+ title={src === undefined ? file.path : undefined}
654
+ {...getTriggerProps?.({ kind: 'file', ...file })}
655
+ onClick={() => { openFile(file.path, file.line === undefined ? undefined : { line: file.line }) }}
656
+ >
657
+ {glyph && <LinkIconMedium kind={classifyLinkPath(file.path)} className={css.linkIcon} />}
658
+ {children}
659
+ </button>
660
+ )
661
+ if (src === undefined || preview === undefined) return anchor
662
+ return <HoverCard inline anchor={anchor}
663
+ content={<>
664
+ <ImagePreview src={src} alt={file.path} loadingLabel={preview.labels.loading} failedLabel={preview.labels.failed} />
665
+ <span className={css.previewName}>{file.path.split(/[\\/]/u).pop()}</span>
666
+ </>} />
667
+ }
668
+
669
+ /**
670
+ * The complete inline-code value when it is exactly an absolute HTTP(S) URL
671
+ * (no surrounding whitespace); anything else stays inert code.
672
+ */
673
+ function inlineCodeHttpUrl(value: string): string | undefined {
674
+ if (value.trim() !== value) return undefined
675
+ try {
676
+ const protocol = new URL(value).protocol
677
+ return protocol === 'http:' || protocol === 'https:' ? value : undefined
678
+ } catch {
679
+ // Not an absolute URL at all — the only way new URL() rejects a string.
680
+ return undefined
681
+ }
682
+ }
683
+
684
+ function renderImage(url: string, alt: string, key: Key, context: MarkdownRenderContext): ReactNode {
685
+ return <MarkdownImage key={`${key}:${url}`} destination={url} alt={alt}
686
+ pathImages={context.pathImages} streaming={context.streaming} inLink={context.inLink === true} />
687
+ }
688
+
689
+ function MarkdownImage({ destination, alt, pathImages, streaming, inLink }: {
690
+ destination: string
691
+ alt: string
692
+ pathImages: MarkdownPathImages | undefined
693
+ streaming: boolean
694
+ inLink: boolean
695
+ }): ReactNode {
696
+ const { fileImages } = useMarkdownDelegate()
697
+ const [load] = useState(nextImageLoad)
698
+ const file = streaming ? undefined : parseFileLink(destination)
699
+ const resolved = file === undefined ? undefined : fileImages?.resolve(file.path)
700
+ const src = resolved === undefined ? imageSource(destination, pathImages, load) : freshImageUrl(resolved, load)
701
+ if (src === undefined) return <span className={css.imageAlt}>{alt}</span>
702
+ return <LoadedMarkdownImage key={src} src={src} alt={alt} destination={destination} preview={inLink ? undefined : fileImages} />
703
+ }
704
+
705
+ function LoadedMarkdownImage({ src, alt, destination, preview }: {
706
+ src: string
707
+ alt: string
708
+ destination: string
709
+ preview: ReturnType<typeof useMarkdownDelegate>['fileImages']
710
+ }): ReactNode {
711
+ const { getTriggerProps } = useMarkdownDelegate()
712
+ const [failed, setFailed] = useState(false)
713
+ const [open, setOpen] = useState(false)
714
+ const close = useCallback(() => { setOpen(false) }, [])
715
+ if (failed) return <span className={css.imageAlt}>{preview === undefined ? '' : `${preview.labels.failed} · `}{alt || destination}</span>
716
+ const file = parseFileLink(destination)
717
+ const contextMenuProps = getTriggerProps?.({ kind: 'image', url: src, ...(file === undefined ? {} : { path: file.path }) })
718
+ const imageProps = { className: css.image, src, alt, onError: () => { setFailed(true) },
719
+ loading: 'lazy' as const, decoding: 'async' as const, referrerPolicy: 'no-referrer' as const }
720
+ if (preview === undefined) return <img {...imageProps} {...contextMenuProps} />
721
+ const localFileName = file?.path.split(/[\\/]/u).at(-1)
722
+ const urlFileName = destination.split('/').at(-1)?.split(/[?#]/u)[0]
723
+ const exportName = localFileName || urlFileName || 'image'
724
+ const img = <DraggableImage
725
+ fileDrag={preview.fileDrag}
726
+ {...imageProps}
727
+ resourceAddress={file === undefined ? undefined : preview.resourceAddress?.(file.path)}
728
+ name={exportName}
729
+ />
730
+ return <>
731
+ <button type="button" className={css.imageButton} title={preview.labels.open}
732
+ {...contextMenuProps}
733
+ aria-label={alt ? `${preview.labels.open}: ${alt}` : preview.labels.open}
734
+ onClick={() => { setOpen(true) }}>{img}</button>
735
+ {open && <ImageLightbox src={src} alt={alt} labels={preview.labels} onClose={close} contextMenuProps={contextMenuProps} />}
736
+ </>
737
+ }
738
+
739
+ /** The bracketed source text a reference reverts to when its definition is missing. */
740
+ function referenceSuffix(node: Md.LinkReference | Md.ImageReference): string {
741
+ if (node.referenceType === 'collapsed') return '][]'
742
+ if (node.referenceType === 'full') return `][${node.label ?? node.identifier}]`
743
+ return ']'
744
+ }
745
+
746
+ function renderLinkReference(
747
+ node: Md.LinkReference,
748
+ key: Key,
749
+ context: MarkdownRenderContext,
750
+ ): ReactNode {
751
+ const definition = context.targets.definitions.get(node.identifier.toUpperCase())
752
+ if (definition === undefined) {
753
+ // The grammar only emits references whose definitions exist somewhere in
754
+ // the same parse, but incremental segments and hand-built trees may still
755
+ // present unresolved ones: revert to the bracketed source text — which is
756
+ // not an anchor, so mentions inside it stay live.
757
+ return <Fragment key={key}>{'['}{renderChildren(node.children, context)}{referenceSuffix(node)}</Fragment>
758
+ }
759
+ const rendered = renderChildren(node.children, { ...context, inLink: true })
760
+ return renderAnchor(definition.url, rendered, key, !anchorWrapsOnlyImages(node.children), context.streaming)
761
+ }
762
+
763
+ function renderImageReference(
764
+ node: Md.ImageReference,
765
+ key: Key,
766
+ context: MarkdownRenderContext,
767
+ ): ReactNode {
768
+ const definition = context.targets.definitions.get(node.identifier.toUpperCase())
769
+ if (definition === undefined) return `![${node.alt ?? ''}${referenceSuffix(node)}`
770
+ return renderImage(definition.url, node.alt ?? '', key, context)
771
+ }
772
+
773
+ function renderFootnoteReference(
774
+ node: Md.FootnoteReference,
775
+ key: Key,
776
+ context: MarkdownRenderContext,
777
+ ): ReactNode {
778
+ const id = node.identifier.toUpperCase()
779
+ const seen = context.footnoteCounts.get(id)
780
+ if (seen === undefined) context.footnoteOrder.push(id)
781
+ context.footnoteCounts.set(id, (seen ?? 0) + 1)
782
+ // The in-page anchor is not an absolute URL, so only the numbered
783
+ // superscript renders (matching the replaced pipeline's unwrapped link).
784
+ return <sup key={key}>{String(context.footnoteOrder.indexOf(id) + 1)}</sup>
785
+ }
786
+
787
+ /**
788
+ * Render the trailing footnote section for every footnote referenced during
789
+ * the pass, in first-reference order, with one plain-text back-reference
790
+ * marker per rendered reference.
791
+ * @param context - The pass state after all blocks rendered.
792
+ * @returns The section, or null when no referenced footnote has a definition.
793
+ */
794
+ export function renderFootnoteSection(context: MarkdownRenderContext): ReactNode | null {
795
+ const items: ReactNode[] = []
796
+ for (const id of context.footnoteOrder) {
797
+ const definition = context.targets.footnotes.get(id)
798
+ if (definition === undefined) continue
799
+ const count = context.footnoteCounts.get(id) ?? 0
800
+ const backrefs: ReactNode[] = []
801
+ for (let reference = 1; reference <= count; reference++) {
802
+ if (backrefs.length > 0) backrefs.push(' ')
803
+ backrefs.push('↩')
804
+ if (reference > 1) backrefs.push(<sup key={`re-${reference}`}>{String(reference)}</sup>)
805
+ }
806
+ const entries = renderBlockEntries(definition.children, context)
807
+ const tail = entries[entries.length - 1]
808
+ const body: ReactNode[] = entries.map((entry, index) => (
809
+ 'paragraph' in entry
810
+ ? (
811
+ <p key={`p-${index}`}>
812
+ {entry.paragraph}
813
+ {entry === tail && <>{' '}{backrefs}</>}
814
+ </p>
815
+ )
816
+ : entry.element
817
+ ))
818
+ // Without a trailing paragraph the back-references join the block list
819
+ // itself (and pick up the wrap newlines), as in the replaced pipeline.
820
+ if (tail === undefined || !('paragraph' in tail)) body.push(...backrefs)
821
+ items.push(
822
+ <li key={id} id={`user-content-fn-${normalizeUri(id.toLowerCase())}`}>
823
+ {wrapBlockChildren(body, true)}
824
+ </li>,
825
+ )
826
+ }
827
+ if (items.length === 0) return null
828
+ return (
829
+ <section key="footnotes" data-footnotes className="footnotes">
830
+ <h2 id="footnote-label" className="sr-only">{context.labels.footnotes}</h2>
831
+ <ol>{items}</ol>
832
+ </section>
833
+ )
834
+ }