@ai-matrx/rich-content 0.2.4 → 0.2.6

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 (381) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/code-block/CodeBlock.d.ts +44 -0
  3. package/dist/code-block/CodeBlock.js +449 -0
  4. package/dist/code-block/CodeBlockHeader.d.ts +63 -0
  5. package/dist/code-block/CodeBlockHeader.js +472 -0
  6. package/dist/code-block/CodeEditorLoading.d.ts +3 -0
  7. package/dist/code-block/CodeEditorLoading.js +34 -0
  8. package/dist/code-block/LanguageDisplay.d.ts +28 -0
  9. package/dist/code-block/LanguageDisplay.js +279 -0
  10. package/dist/code-block/SmallCodeEditor.d.ts +30 -0
  11. package/dist/code-block/SmallCodeEditor.js +22 -0
  12. package/dist/code-block/StickyButtons.d.ts +35 -0
  13. package/dist/code-block/StickyButtons.js +88 -0
  14. package/dist/code-block/highlight/ShikiCodeView.d.ts +26 -0
  15. package/dist/code-block/highlight/ShikiCodeView.js +134 -0
  16. package/dist/code-block/highlight/shiki-highlighter.d.ts +14 -0
  17. package/dist/code-block/highlight/shiki-highlighter.js +126 -0
  18. package/dist/code-block/highlight/useHighlightedLines.d.ts +18 -0
  19. package/dist/code-block/highlight/useHighlightedLines.js +142 -0
  20. package/dist/code-block/sticky-inset.d.ts +6 -0
  21. package/dist/code-block/sticky-inset.js +10 -0
  22. package/dist/display/block-interaction.d.ts +33 -0
  23. package/dist/display/block-interaction.js +13 -0
  24. package/dist/display/blocks/ChatCollapsibleWrapper.d.ts +13 -0
  25. package/dist/display/blocks/ChatCollapsibleWrapper.js +56 -0
  26. package/dist/display/blocks/buildMediaSource.d.ts +25 -0
  27. package/dist/display/blocks/buildMediaSource.js +43 -0
  28. package/dist/display/blocks/canvas-adaptive.d.ts +118 -0
  29. package/dist/display/blocks/canvas-adaptive.js +127 -0
  30. package/dist/display/blocks/canvas-fit.d.ts +24 -0
  31. package/dist/display/blocks/canvas-fit.js +19 -0
  32. package/dist/display/blocks/chart/ChartBlock.d.ts +8 -0
  33. package/dist/display/blocks/chart/ChartBlock.js +125 -0
  34. package/dist/display/blocks/chart/ChartCanvas.d.ts +18 -0
  35. package/dist/display/blocks/chart/ChartCanvas.js +159 -0
  36. package/dist/display/blocks/chart/TableChart.d.ts +25 -0
  37. package/dist/display/blocks/chart/TableChart.js +97 -0
  38. package/dist/display/blocks/chart/chart-spec.d.ts +39 -0
  39. package/dist/display/blocks/chart/chart-spec.js +128 -0
  40. package/dist/display/blocks/chart/labels.d.ts +20 -0
  41. package/dist/display/blocks/chart/labels.js +7 -0
  42. package/dist/display/blocks/chart/table-chart.d.ts +37 -0
  43. package/dist/display/blocks/chart/table-chart.js +231 -0
  44. package/dist/display/blocks/common/BlockHeaderWrapper.d.ts +56 -0
  45. package/dist/display/blocks/common/BlockHeaderWrapper.js +310 -0
  46. package/dist/display/blocks/common/ContentBlockWrapper.d.ts +40 -0
  47. package/dist/display/blocks/common/ContentBlockWrapper.js +214 -0
  48. package/dist/display/blocks/common/SandboxedHtml.d.ts +27 -0
  49. package/dist/display/blocks/common/SandboxedHtml.js +26 -0
  50. package/dist/display/blocks/diagram/DiagramLoadingVisualization.d.ts +6 -0
  51. package/dist/display/blocks/diagram/DiagramLoadingVisualization.js +190 -0
  52. package/dist/display/blocks/diagram/InteractiveDiagramBlock.d.ts +51 -0
  53. package/dist/display/blocks/diagram/InteractiveDiagramBlock.js +2415 -0
  54. package/dist/display/blocks/diagram/diagram-printer.d.ts +16 -0
  55. package/dist/display/blocks/diagram/diagram-printer.js +294 -0
  56. package/dist/display/blocks/diagram/diagram-visual-defaults.d.ts +116 -0
  57. package/dist/display/blocks/diagram/diagram-visual-defaults.js +400 -0
  58. package/dist/display/blocks/diagram/layout-utils.d.ts +90 -0
  59. package/dist/display/blocks/diagram/layout-utils.js +347 -0
  60. package/dist/display/blocks/diagram/parseDiagramJSON.d.ts +105 -0
  61. package/dist/display/blocks/diagram/parseDiagramJSON.js +296 -0
  62. package/dist/display/blocks/diagram/presentation-direction.d.ts +29 -0
  63. package/dist/display/blocks/diagram/presentation-direction.js +19 -0
  64. package/dist/display/blocks/diagram/ui-utils.d.ts +1 -0
  65. package/dist/display/blocks/diagram/ui-utils.js +18 -0
  66. package/dist/display/blocks/diff/DiffBlock.d.ts +10 -0
  67. package/dist/display/blocks/diff/DiffBlock.js +119 -0
  68. package/dist/display/blocks/diff/DiffCanvas.d.ts +15 -0
  69. package/dist/display/blocks/diff/DiffCanvas.js +20 -0
  70. package/dist/display/blocks/generic/GenericStructuredBlock.d.ts +24 -0
  71. package/dist/display/blocks/generic/GenericStructuredBlock.js +53 -0
  72. package/dist/display/blocks/generic/StructuredValueTabs.d.ts +21 -0
  73. package/dist/display/blocks/generic/StructuredValueTabs.js +124 -0
  74. package/dist/display/blocks/generic/tile-actions-slot.d.ts +39 -0
  75. package/dist/display/blocks/generic/tile-actions-slot.js +33 -0
  76. package/dist/display/blocks/images/ImageBlock.d.ts +8 -0
  77. package/dist/display/blocks/images/ImageBlock.js +265 -0
  78. package/dist/display/blocks/json/JsonBlock.d.ts +34 -0
  79. package/dist/display/blocks/json/JsonBlock.js +562 -0
  80. package/dist/display/blocks/json/JsonTableView.d.ts +10 -0
  81. package/dist/display/blocks/json/JsonTableView.js +173 -0
  82. package/dist/display/blocks/json/json-compact-stringify.d.ts +25 -0
  83. package/dist/display/blocks/json/json-compact-stringify.js +52 -0
  84. package/dist/display/blocks/json/json-tabular-utils.d.ts +65 -0
  85. package/dist/display/blocks/json/json-tabular-utils.js +121 -0
  86. package/dist/display/blocks/links/LinkComponent.d.ts +6 -0
  87. package/dist/display/blocks/links/LinkComponent.js +373 -0
  88. package/dist/display/blocks/links/LinkComponentWithFetch.d.ts +1 -0
  89. package/dist/display/blocks/links/LinkComponentWithFetch.js +0 -0
  90. package/dist/display/blocks/markdown/MarkdownKindBlock.d.ts +48 -0
  91. package/dist/display/blocks/markdown/MarkdownKindBlock.js +52 -0
  92. package/dist/display/blocks/markdown-preview/MarkdownPreviewBlock.d.ts +17 -0
  93. package/dist/display/blocks/markdown-preview/MarkdownPreviewBlock.js +70 -0
  94. package/dist/display/blocks/mermaid/MermaidBlock.d.ts +19 -0
  95. package/dist/display/blocks/mermaid/MermaidBlock.js +386 -0
  96. package/dist/display/blocks/search-replace/SearchReplaceBlock.d.ts +50 -0
  97. package/dist/display/blocks/search-replace/SearchReplaceBlock.js +71 -0
  98. package/dist/display/blocks/svg/SvgBlock.d.ts +8 -0
  99. package/dist/display/blocks/svg/SvgBlock.js +126 -0
  100. package/dist/display/blocks/table/StreamingTableRenderer.d.ts +53 -0
  101. package/dist/display/blocks/table/StreamingTableRenderer.js +907 -0
  102. package/dist/display/blocks/table/TableRenderPathDiagnostic.d.ts +21 -0
  103. package/dist/display/blocks/table/TableRenderPathDiagnostic.js +79 -0
  104. package/dist/display/blocks/thinking-reasoning/ConsolidatedReasoningVisualization.d.ts +14 -0
  105. package/dist/display/blocks/thinking-reasoning/ConsolidatedReasoningVisualization.js +15 -0
  106. package/dist/display/blocks/thinking-reasoning/ReasoningVisualization.d.ts +13 -0
  107. package/dist/display/blocks/thinking-reasoning/ReasoningVisualization.js +19 -0
  108. package/dist/display/blocks/thinking-reasoning/ThinkingTrace.d.ts +30 -0
  109. package/dist/display/blocks/thinking-reasoning/ThinkingTrace.js +75 -0
  110. package/dist/display/blocks/thinking-reasoning/ThinkingTraceMarkdown.d.ts +13 -0
  111. package/dist/display/blocks/thinking-reasoning/ThinkingTraceMarkdown.js +48 -0
  112. package/dist/display/blocks/thinking-reasoning/ThinkingVisualization.d.ts +12 -0
  113. package/dist/display/blocks/thinking-reasoning/ThinkingVisualization.js +19 -0
  114. package/dist/display/blocks/toml/TomlBlock.d.ts +7 -0
  115. package/dist/display/blocks/toml/TomlBlock.js +167 -0
  116. package/dist/display/blocks/tree/TreeBlock.d.ts +7 -0
  117. package/dist/display/blocks/tree/TreeBlock.js +163 -0
  118. package/dist/display/blocks/xml/XmlBlock.d.ts +23 -0
  119. package/dist/display/blocks/xml/XmlBlock.js +197 -0
  120. package/dist/display/blocks/xml/readXmlTag.d.ts +1 -0
  121. package/dist/display/blocks/xml/readXmlTag.js +1 -0
  122. package/dist/display/blocks/xml/xml-tokenize.d.ts +13 -0
  123. package/dist/display/blocks/xml/xml-tokenize.js +169 -0
  124. package/dist/display/blocks/yaml/YamlBlock.d.ts +7 -0
  125. package/dist/display/blocks/yaml/YamlBlock.js +191 -0
  126. package/dist/display/chat-markdown/BasicMarkdownContent.d.ts +29 -0
  127. package/dist/display/chat-markdown/BasicMarkdownContent.js +122 -0
  128. package/dist/display/chat-markdown/BlockRenderingContext.d.ts +23 -0
  129. package/dist/display/chat-markdown/BlockRenderingContext.js +17 -0
  130. package/dist/display/chat-markdown/ConfigurableMarkdownContent.d.ts +172 -0
  131. package/dist/display/chat-markdown/ConfigurableMarkdownContent.js +649 -0
  132. package/dist/display/chat-markdown/InlineCodeSnippet.d.ts +19 -0
  133. package/dist/display/chat-markdown/InlineCodeSnippet.js +146 -0
  134. package/dist/display/chat-markdown/InlineCodeSnippetKindGate.d.ts +11 -0
  135. package/dist/display/chat-markdown/InlineCodeSnippetKindGate.js +9 -0
  136. package/dist/display/chat-markdown/KindTextGate.d.ts +31 -0
  137. package/dist/display/chat-markdown/KindTextGate.js +60 -0
  138. package/dist/display/chat-markdown/QuestionnaireLoadingVisualization.d.ts +6 -0
  139. package/dist/display/chat-markdown/QuestionnaireLoadingVisualization.js +92 -0
  140. package/dist/display/chat-markdown/block-registry/BlockComponentRegistry.d.ts +72 -0
  141. package/dist/display/chat-markdown/block-registry/BlockComponentRegistry.js +94 -0
  142. package/dist/display/chat-markdown/block-registry/BlockRenderer.d.ts +126 -0
  143. package/dist/display/chat-markdown/block-registry/BlockRenderer.js +473 -0
  144. package/dist/display/chat-markdown/block-registry/block-dispatch.d.ts +410 -0
  145. package/dist/display/chat-markdown/block-registry/block-dispatch.js +495 -0
  146. package/dist/display/chat-markdown/block-registry/json-parse-utils.d.ts +13 -0
  147. package/dist/display/chat-markdown/block-registry/json-parse-utils.js +236 -0
  148. package/dist/display/chat-markdown/constants.d.ts +14 -0
  149. package/dist/display/chat-markdown/constants.js +317 -0
  150. package/dist/display/chat-markdown/diff-blocks/DiffCollapsible.d.ts +31 -0
  151. package/dist/display/chat-markdown/diff-blocks/DiffCollapsible.js +62 -0
  152. package/dist/display/chat-markdown/diff-blocks/DiffLoadingIndicator.d.ts +12 -0
  153. package/dist/display/chat-markdown/diff-blocks/DiffLoadingIndicator.js +18 -0
  154. package/dist/display/chat-markdown/diff-blocks/StreamingDiffBlock.d.ts +22 -0
  155. package/dist/display/chat-markdown/diff-blocks/StreamingDiffBlock.js +130 -0
  156. package/dist/display/chat-markdown/diff-blocks/diff-style-registry.d.ts +21 -0
  157. package/dist/display/chat-markdown/diff-blocks/diff-style-registry.js +91 -0
  158. package/dist/display/chat-markdown/diff-blocks/renderers/SearchReplaceDiffRenderer.d.ts +26 -0
  159. package/dist/display/chat-markdown/diff-blocks/renderers/SearchReplaceDiffRenderer.js +186 -0
  160. package/dist/display/chat-markdown/diff-blocks/types.d.ts +56 -0
  161. package/dist/display/chat-markdown/diff-blocks/types.js +0 -0
  162. package/dist/display/chat-markdown/internal-handlers/BlockFallback.d.ts +20 -0
  163. package/dist/display/chat-markdown/internal-handlers/BlockFallback.js +83 -0
  164. package/dist/display/chat-markdown/internal-handlers/InlineStatusIndicator.d.ts +4 -0
  165. package/dist/display/chat-markdown/internal-handlers/InlineStatusIndicator.js +16 -0
  166. package/dist/display/chat-markdown/internal-handlers/MarkdownErrorBoundary.d.ts +17 -0
  167. package/dist/display/chat-markdown/internal-handlers/MarkdownErrorBoundary.js +40 -0
  168. package/dist/display/chat-markdown/internal-handlers/PlainTextFallback.d.ts +8 -0
  169. package/dist/display/chat-markdown/internal-handlers/PlainTextFallback.js +91 -0
  170. package/dist/display/chat-markdown/internal-handlers/SafeBlockRenderer.d.ts +20 -0
  171. package/dist/display/chat-markdown/internal-handlers/SafeBlockRenderer.js +72 -0
  172. package/dist/display/chat-markdown/kind-source-view.d.ts +14 -0
  173. package/dist/display/chat-markdown/kind-source-view.js +14 -0
  174. package/dist/display/chat-markdown/matrx-variables/MatrxVariableInline.d.ts +28 -0
  175. package/dist/display/chat-markdown/matrx-variables/MatrxVariableInline.js +65 -0
  176. package/dist/display/chat-markdown/progressive-mount.d.ts +18 -0
  177. package/dist/display/chat-markdown/progressive-mount.js +90 -0
  178. package/dist/display/chat-markdown/render-block-to-content-block.d.ts +31 -0
  179. package/dist/display/chat-markdown/render-block-to-content-block.js +32 -0
  180. package/dist/display/chat-markdown/settle-stream-blocks.d.ts +50 -0
  181. package/dist/display/chat-markdown/settle-stream-blocks.js +26 -0
  182. package/dist/display/chat-markdown/stable-blocks.d.ts +15 -0
  183. package/dist/display/chat-markdown/stable-blocks.js +54 -0
  184. package/dist/display/chat-markdown/types.d.ts +11 -0
  185. package/dist/display/chat-markdown/types.js +26 -0
  186. package/dist/display/specimen/SpecimenContext.d.ts +26 -0
  187. package/dist/display/specimen/SpecimenContext.js +64 -0
  188. package/dist/display/tables/MarkdownTable.d.ts +23 -0
  189. package/dist/display/tables/MarkdownTable.js +769 -0
  190. package/dist/display/tables/MarkdownTableScrollArea.d.ts +12 -0
  191. package/dist/display/tables/MarkdownTableScrollArea.js +92 -0
  192. package/dist/display/tables/SendToGoogleSheetButton.d.ts +19 -0
  193. package/dist/display/tables/SendToGoogleSheetButton.js +93 -0
  194. package/dist/display/tables/SendToWorkbookButton.d.ts +24 -0
  195. package/dist/display/tables/SendToWorkbookButton.js +93 -0
  196. package/dist/display/tables/TableSaveToMenu.d.ts +16 -0
  197. package/dist/display/tables/TableSaveToMenu.js +98 -0
  198. package/dist/display/tables/TableWithSeparatedControls.d.ts +22 -0
  199. package/dist/display/tables/TableWithSeparatedControls.js +574 -0
  200. package/dist/display/tables/ViewTableModal.d.ts +14 -0
  201. package/dist/display/tables/ViewTableModal.js +67 -0
  202. package/dist/display/tables/editing/ColumnActionsMenu.d.ts +16 -0
  203. package/dist/display/tables/editing/ColumnActionsMenu.js +80 -0
  204. package/dist/display/tables/editing/RowActionsMenu.d.ts +16 -0
  205. package/dist/display/tables/editing/RowActionsMenu.js +80 -0
  206. package/dist/display/tables/editing/TableEditToolbar.d.ts +15 -0
  207. package/dist/display/tables/editing/TableEditToolbar.js +63 -0
  208. package/dist/display/tables/editing/tableMutations.d.ts +50 -0
  209. package/dist/display/tables/editing/tableMutations.js +148 -0
  210. package/dist/display/tables/editing/useDoubleClickEdit.d.ts +43 -0
  211. package/dist/display/tables/editing/useDoubleClickEdit.js +51 -0
  212. package/dist/display/tables/editing/useTableUndo.d.ts +25 -0
  213. package/dist/display/tables/editing/useTableUndo.js +17 -0
  214. package/dist/display/tables/table-action-row.d.ts +8 -0
  215. package/dist/display/tables/table-action-row.js +31 -0
  216. package/dist/display/tables/table-viewer.d.ts +13 -0
  217. package/dist/display/tables/table-viewer.js +18 -0
  218. package/dist/host/ErrorActions.d.ts +1 -1
  219. package/dist/host/ErrorNotice.d.ts +10 -0
  220. package/dist/host/ErrorNotice.js +19 -0
  221. package/dist/host/app-bindings.d.ts +155 -0
  222. package/dist/host/app-bindings.js +160 -0
  223. package/dist/host/diagnostics.d.ts +2 -2
  224. package/dist/host/diagnostics.js +2 -1
  225. package/dist/host/tables.d.ts +1 -6
  226. package/dist/host/types.d.ts +14 -7
  227. package/dist/levels/RichContent.d.ts +3 -0
  228. package/dist/levels/RichContent.js +102 -0
  229. package/dist/levels/RichContentInline.d.ts +28 -0
  230. package/dist/levels/RichContentInline.js +61 -0
  231. package/dist/levels/RichContentPreview.d.ts +12 -0
  232. package/dist/levels/RichContentPreview.js +39 -0
  233. package/dist/levels/RichContentStandardImpl.d.ts +12 -0
  234. package/dist/levels/RichContentStandardImpl.js +27 -0
  235. package/dist/levels/RichContentStaticProse.d.ts +46 -0
  236. package/dist/levels/RichContentStaticProse.js +100 -0
  237. package/dist/levels/depth.d.ts +18 -0
  238. package/dist/levels/depth.js +32 -0
  239. package/dist/levels/prose/inline-level-elements.d.ts +19 -0
  240. package/dist/levels/prose/inline-level-elements.js +103 -0
  241. package/dist/levels/prose/prose-block-elements.d.ts +25 -0
  242. package/dist/levels/prose/prose-block-elements.js +313 -0
  243. package/dist/levels/prose/prose-inline-elements.d.ts +13 -0
  244. package/dist/levels/prose/prose-inline-elements.js +143 -0
  245. package/dist/levels/prose/prose-prepare.d.ts +50 -0
  246. package/dist/levels/prose/prose-prepare.js +246 -0
  247. package/dist/levels/prose/remote-image-policy.d.ts +34 -0
  248. package/dist/levels/prose/remote-image-policy.js +153 -0
  249. package/dist/levels/prose/variant-root.d.ts +9 -0
  250. package/dist/levels/prose/variant-root.js +34 -0
  251. package/dist/levels/rich-content-types.d.ts +93 -0
  252. package/dist/levels/rich-content-types.js +4 -0
  253. package/dist/levels/server/DelimiterViolationReport.d.ts +7 -0
  254. package/dist/levels/server/DelimiterViolationReport.js +24 -0
  255. package/dist/levels/server/RichContentServer.d.ts +27 -0
  256. package/dist/levels/server/RichContentServer.js +97 -0
  257. package/dist/levels/standard/NestedRichContent.d.ts +7 -0
  258. package/dist/levels/standard/NestedRichContent.js +70 -0
  259. package/dist/levels/standard/StandardBlocks.d.ts +13 -0
  260. package/dist/levels/standard/StandardBlocks.js +239 -0
  261. package/dist/levels/standard/StandardKindRegion.d.ts +14 -0
  262. package/dist/levels/standard/StandardKindRegion.js +69 -0
  263. package/dist/levels/standard/standard-kind-region.d.ts +19 -0
  264. package/dist/levels/standard/standard-kind-region.js +21 -0
  265. package/dist/levels/standard/static-standard.d.ts +23 -0
  266. package/dist/levels/standard/static-standard.js +187 -0
  267. package/dist/levels/standard/stream-holdback.d.ts +2 -0
  268. package/dist/levels/standard/stream-holdback.js +77 -0
  269. package/dist/mermaid/MermaidFullscreen.d.ts +17 -0
  270. package/dist/mermaid/MermaidFullscreen.js +71 -0
  271. package/dist/mermaid/MermaidRenderer.d.ts +20 -0
  272. package/dist/mermaid/MermaidRenderer.js +267 -0
  273. package/dist/mermaid/MermaidView.d.ts +27 -0
  274. package/dist/mermaid/MermaidView.js +68 -0
  275. package/dist/mermaid/MermaidViewport.d.ts +75 -0
  276. package/dist/mermaid/MermaidViewport.js +286 -0
  277. package/dist/mermaid/adapters/er.d.ts +10 -0
  278. package/dist/mermaid/adapters/er.js +205 -0
  279. package/dist/mermaid/adapters/flowchart.d.ts +17 -0
  280. package/dist/mermaid/adapters/flowchart.js +634 -0
  281. package/dist/mermaid/adapters/journey.d.ts +9 -0
  282. package/dist/mermaid/adapters/journey.js +207 -0
  283. package/dist/mermaid/adapters/mindmap.d.ts +12 -0
  284. package/dist/mermaid/adapters/mindmap.js +252 -0
  285. package/dist/mermaid/adapters/pie.d.ts +7 -0
  286. package/dist/mermaid/adapters/pie.js +172 -0
  287. package/dist/mermaid/adapters/quadrant.d.ts +8 -0
  288. package/dist/mermaid/adapters/quadrant.js +231 -0
  289. package/dist/mermaid/adapters/register.d.ts +7 -0
  290. package/dist/mermaid/adapters/register.js +19 -0
  291. package/dist/mermaid/adapters/sequence.d.ts +8 -0
  292. package/dist/mermaid/adapters/sequence.js +251 -0
  293. package/dist/mermaid/adapters/state.d.ts +12 -0
  294. package/dist/mermaid/adapters/state.js +245 -0
  295. package/dist/mermaid/adapters/timeline.d.ts +8 -0
  296. package/dist/mermaid/adapters/timeline.js +245 -0
  297. package/dist/mermaid/catalog.d.ts +33 -0
  298. package/dist/mermaid/catalog.js +202 -0
  299. package/dist/mermaid/diagram-type.d.ts +39 -0
  300. package/dist/mermaid/diagram-type.js +89 -0
  301. package/dist/mermaid/export.d.ts +21 -0
  302. package/dist/mermaid/export.js +112 -0
  303. package/dist/mermaid/extract-fence.d.ts +15 -0
  304. package/dist/mermaid/extract-fence.js +22 -0
  305. package/dist/mermaid/lazy-draw.d.ts +40 -0
  306. package/dist/mermaid/lazy-draw.js +168 -0
  307. package/dist/mermaid/model/adapter.d.ts +28 -0
  308. package/dist/mermaid/model/adapter.js +16 -0
  309. package/dist/mermaid/model/ops.d.ts +282 -0
  310. package/dist/mermaid/model/ops.js +9 -0
  311. package/dist/mermaid/model/round-trip.d.ts +22 -0
  312. package/dist/mermaid/model/round-trip.js +45 -0
  313. package/dist/mermaid/model/types.d.ts +271 -0
  314. package/dist/mermaid/model/types.js +0 -0
  315. package/dist/mermaid/print-render.d.ts +9 -0
  316. package/dist/mermaid/print-render.js +39 -0
  317. package/dist/mermaid/runtime.d.ts +25 -0
  318. package/dist/mermaid/runtime.js +183 -0
  319. package/dist/mermaid/sanitize.d.ts +46 -0
  320. package/dist/mermaid/sanitize.js +234 -0
  321. package/dist/mermaid/types.d.ts +43 -0
  322. package/dist/mermaid/types.js +21 -0
  323. package/dist/mermaid/view/ViewModePane.d.ts +24 -0
  324. package/dist/mermaid/view/ViewModePane.js +9 -0
  325. package/dist/utils/client-lazy.d.ts +1 -1
  326. package/dist/utils/client-lazy.js +4 -1
  327. package/dist/utils/lifted/DiffView.d.ts +10 -0
  328. package/dist/utils/lifted/DiffView.js +26 -0
  329. package/dist/utils/lifted/IconButton.d.ts +24 -0
  330. package/dist/utils/lifted/IconButton.js +43 -0
  331. package/dist/utils/lifted/MatrxMiniLoader.d.ts +1 -0
  332. package/dist/utils/lifted/MatrxMiniLoader.js +8 -0
  333. package/dist/utils/lifted/ShimmerText.d.ts +5 -0
  334. package/dist/utils/lifted/ShimmerText.js +21 -0
  335. package/dist/utils/lifted/SuspenseLoader.d.ts +16 -0
  336. package/dist/utils/lifted/SuspenseLoader.js +42 -0
  337. package/dist/utils/lifted/Tooltip.d.ts +20 -0
  338. package/dist/utils/lifted/Tooltip.js +52 -0
  339. package/dist/utils/lifted/artifactId.d.ts +34 -0
  340. package/dist/utils/lifted/artifactId.js +15 -0
  341. package/dist/utils/lifted/canvasContent.d.ts +63 -0
  342. package/dist/utils/lifted/canvasContent.js +98 -0
  343. package/dist/utils/lifted/captureReactError.d.ts +24 -0
  344. package/dist/utils/lifted/captureReactError.js +28 -0
  345. package/dist/utils/lifted/chunk-load-recovery.d.ts +25 -0
  346. package/dist/utils/lifted/chunk-load-recovery.js +36 -0
  347. package/dist/utils/lifted/code-editor-agent-types.d.ts +6 -0
  348. package/dist/utils/lifted/code-editor-agent-types.js +0 -0
  349. package/dist/utils/lifted/code-editor-agents.d.ts +39 -0
  350. package/dist/utils/lifted/code-editor-agents.js +52 -0
  351. package/dist/utils/lifted/code-language-extension.d.ts +1 -0
  352. package/dist/utils/lifted/code-language-extension.js +60 -0
  353. package/dist/utils/lifted/custom-icons.d.ts +16 -0
  354. package/dist/utils/lifted/custom-icons.js +47 -0
  355. package/dist/utils/lifted/durability.d.ts +16 -0
  356. package/dist/utils/lifted/durability.js +45 -0
  357. package/dist/utils/lifted/errors.d.ts +30 -0
  358. package/dist/utils/lifted/errors.js +29 -0
  359. package/dist/utils/lifted/html-document.d.ts +1 -0
  360. package/dist/utils/lifted/html-document.js +12 -0
  361. package/dist/utils/lifted/languageOptions.d.ts +9 -0
  362. package/dist/utils/lifted/languageOptions.js +52 -0
  363. package/dist/utils/lifted/languages.d.ts +34 -0
  364. package/dist/utils/lifted/languages.js +175 -0
  365. package/dist/utils/lifted/loading-spinner.d.ts +18 -0
  366. package/dist/utils/lifted/loading-spinner.js +200 -0
  367. package/dist/utils/lifted/media-refs.d.ts +13 -0
  368. package/dist/utils/lifted/media-refs.js +27 -0
  369. package/dist/utils/lifted/scroll-root.d.ts +1 -0
  370. package/dist/utils/lifted/scroll-root.js +25 -0
  371. package/dist/utils/lifted/syntax-themes.d.ts +32 -0
  372. package/dist/utils/lifted/syntax-themes.js +100 -0
  373. package/dist/utils/lifted/url-utm.d.ts +24 -0
  374. package/dist/utils/lifted/url-utm.js +66 -0
  375. package/dist/utils/lifted/use-is-mounted.d.ts +24 -0
  376. package/dist/utils/lifted/use-is-mounted.js +21 -0
  377. package/dist/utils/lifted/useToastManager.d.ts +1 -0
  378. package/dist/utils/lifted/useToastManager.js +7 -0
  379. package/dist/utils/report-kind-at-raw-renderer.d.ts +19 -0
  380. package/dist/utils/report-kind-at-raw-renderer.js +32 -0
  381. package/package.json +32 -3
@@ -0,0 +1,271 @@
1
+ /**
2
+ * MermaidDocModel — typed structured documents parsed from mermaid DSL.
3
+ *
4
+ * The DSL string is ALWAYS the single source of truth; docs are derived,
5
+ * edited via operations, and serialized back. Every entity banks its original
6
+ * source line in `raw`; untouched entities re-emit `raw` verbatim so an edit
7
+ * to one node produces a minimal diff and never reformats the user's file.
8
+ *
9
+ * Anything an adapter recognizes but cannot structurally edit (classDef,
10
+ * linkStyle, click, style, accTitle, init directives, comments) is banked as
11
+ * a PassthroughSegment with a positional anchor and re-emitted on serialize.
12
+ * Anything an adapter does NOT recognize forces `code-only` — guessing would
13
+ * risk silent content destruction, which is structurally forbidden here.
14
+ */
15
+ import type { MermaidDiagramType } from "../diagram-type.js";
16
+ export interface Diagnostic {
17
+ line: number;
18
+ message: string;
19
+ severity: "error" | "warning";
20
+ }
21
+ /**
22
+ * One body line of the original source. Lines bound to an entity (`ref`) are
23
+ * re-emitted from `text` verbatim unless that entity is dirty (regenerate) or
24
+ * gone (skip). Unbound lines (comments, classDef, blanks, style, click, …)
25
+ * always re-emit verbatim — that is what makes round-trip lossless by
26
+ * construction.
27
+ */
28
+ export interface SourceLine {
29
+ text: string;
30
+ ref?: {
31
+ entity: string;
32
+ id: string;
33
+ };
34
+ }
35
+ interface DocBase {
36
+ diagramType: MermaidDiagramType;
37
+ /** YAML frontmatter block (--- … ---), verbatim lines, empty when absent. */
38
+ frontmatter: string[];
39
+ /** Ordered body lines (everything after frontmatter). */
40
+ sourceLines: SourceLine[];
41
+ warnings: Diagnostic[];
42
+ }
43
+ export type FlowDirection = "TB" | "TD" | "LR" | "RL" | "BT";
44
+ export type FlowShape = "rect" | "rounded" | "stadium" | "diamond" | "circle" | "hexagon" | "subroutine" | "cylinder";
45
+ export type FlowEdgeStyle = "arrow" | "open" | "dotted" | "thick";
46
+ export interface FlowNode {
47
+ id: string;
48
+ label: string;
49
+ shape: FlowShape;
50
+ /** Palette key from the adapter-owned classDef palette (visual color). */
51
+ paletteKey?: string;
52
+ /** Non-palette :::classes on the declaration, re-emitted on regeneration. */
53
+ extraClasses?: string[];
54
+ /** Original declaration line; absent for nodes declared inline in edges. */
55
+ raw?: string;
56
+ dirty?: boolean;
57
+ /** Created by an edit op (no source line) — serializer appends a decl. */
58
+ added?: boolean;
59
+ }
60
+ export interface FlowEdge {
61
+ id: string;
62
+ from: string;
63
+ to: string;
64
+ label?: string;
65
+ style: FlowEdgeStyle;
66
+ /** True when this edge's source line also declares the from/to node inline
67
+ * (e.g. `A[Start] --> B{X}`) — regeneration must re-emit those decls. */
68
+ inlineFrom?: boolean;
69
+ inlineTo?: boolean;
70
+ raw?: string;
71
+ dirty?: boolean;
72
+ added?: boolean;
73
+ }
74
+ export interface FlowSubgraph {
75
+ id: string;
76
+ title: string;
77
+ nodeIds: string[];
78
+ raw?: string;
79
+ }
80
+ export interface FlowchartDoc extends DocBase {
81
+ kind: "flowchart";
82
+ direction: FlowDirection;
83
+ nodes: FlowNode[];
84
+ edges: FlowEdge[];
85
+ subgraphs: FlowSubgraph[];
86
+ /** Lines declaring several edges at once (chains / & fanout):
87
+ * sourceLine ref {entity:"edgeGroup", id} → member edge ids. */
88
+ edgeGroups: Record<string, string[]>;
89
+ }
90
+ export type MindmapShape = "default" | "square" | "rounded" | "circle" | "cloud" | "bang" | "hexagon";
91
+ export interface MindmapNode {
92
+ id: string;
93
+ label: string;
94
+ shape: MindmapShape;
95
+ /** ::icon(...) decorator line(s) attached to this node, verbatim. */
96
+ decorators: string[];
97
+ children: MindmapNode[];
98
+ raw?: string;
99
+ dirty?: boolean;
100
+ }
101
+ export interface MindmapDoc extends DocBase {
102
+ kind: "mindmap";
103
+ root: MindmapNode;
104
+ /** Structural ops (indent/outdent/move) regenerate the whole tree body —
105
+ * content-preserving, formatting-normalizing. Set by applyOp. */
106
+ regenerateAll?: boolean;
107
+ }
108
+ export type SequenceArrow = "->>" | "-->>" | "->" | "-->" | "-x" | "--x" | "-)" | "--)";
109
+ export interface SequenceParticipant {
110
+ id: string;
111
+ alias?: string;
112
+ isActor: boolean;
113
+ raw?: string;
114
+ dirty?: boolean;
115
+ }
116
+ export type SequenceItem = {
117
+ kind: "message";
118
+ id: string;
119
+ from: string;
120
+ to: string;
121
+ text: string;
122
+ arrow: SequenceArrow;
123
+ raw?: string;
124
+ dirty?: boolean;
125
+ } | {
126
+ /** Notes, loops, alt/opt/par blocks, activations — locked rows, verbatim. */
127
+ kind: "passthrough";
128
+ id: string;
129
+ raw: string;
130
+ };
131
+ export interface SequenceDoc extends DocBase {
132
+ kind: "sequence";
133
+ autonumber: boolean;
134
+ participants: SequenceParticipant[];
135
+ items: SequenceItem[];
136
+ }
137
+ export interface PieSlice {
138
+ id: string;
139
+ label: string;
140
+ value: number;
141
+ raw?: string;
142
+ dirty?: boolean;
143
+ }
144
+ export interface PieDoc extends DocBase {
145
+ kind: "pie";
146
+ title?: string;
147
+ showData: boolean;
148
+ slices: PieSlice[];
149
+ }
150
+ export interface TimelineRow {
151
+ id: string;
152
+ period: string;
153
+ events: string[];
154
+ raw?: string;
155
+ dirty?: boolean;
156
+ }
157
+ export interface TimelineSection {
158
+ id: string;
159
+ /** undefined = the implicit section before any `section` line. */
160
+ title?: string;
161
+ rows: TimelineRow[];
162
+ raw?: string;
163
+ dirty?: boolean;
164
+ }
165
+ export interface TimelineDoc extends DocBase {
166
+ kind: "timeline";
167
+ title?: string;
168
+ sections: TimelineSection[];
169
+ }
170
+ export interface JourneyTask {
171
+ id: string;
172
+ name: string;
173
+ /** Satisfaction score, conventionally 1-5. */
174
+ score: number;
175
+ /** Actor names assigned to the task (comma-separated in source). */
176
+ actors: string[];
177
+ raw?: string;
178
+ dirty?: boolean;
179
+ }
180
+ export interface JourneySection {
181
+ id: string;
182
+ /** undefined = the implicit section before any `section` line. */
183
+ title?: string;
184
+ tasks: JourneyTask[];
185
+ raw?: string;
186
+ dirty?: boolean;
187
+ }
188
+ export interface JourneyDoc extends DocBase {
189
+ kind: "journey";
190
+ title?: string;
191
+ sections: JourneySection[];
192
+ }
193
+ export interface QuadrantPoint {
194
+ id: string;
195
+ label: string;
196
+ x: number;
197
+ y: number;
198
+ raw?: string;
199
+ dirty?: boolean;
200
+ }
201
+ export interface QuadrantDoc extends DocBase {
202
+ kind: "quadrant";
203
+ title?: string;
204
+ /** Axis labels: "Low --> High" forms, stored verbatim of the text portion. */
205
+ xAxis?: string;
206
+ yAxis?: string;
207
+ /** quadrant-1..4 labels (top-right, top-left, bottom-left, bottom-right). */
208
+ quadrantLabels: (string | undefined)[];
209
+ points: QuadrantPoint[];
210
+ }
211
+ export interface StateNode {
212
+ id: string;
213
+ /** Optional human description (from `id : desc` or `state "desc" as id`). */
214
+ description?: string;
215
+ raw?: string;
216
+ dirty?: boolean;
217
+ added?: boolean;
218
+ }
219
+ export interface StateTransition {
220
+ id: string;
221
+ from: string;
222
+ to: string;
223
+ label?: string;
224
+ raw?: string;
225
+ dirty?: boolean;
226
+ added?: boolean;
227
+ }
228
+ export interface StateDoc extends DocBase {
229
+ kind: "state";
230
+ /** stateDiagram (v1) vs stateDiagram-v2 — preserved verbatim. */
231
+ header: string;
232
+ states: StateNode[];
233
+ transitions: StateTransition[];
234
+ }
235
+ /** Mermaid ER cardinality token (as written next to the entity). */
236
+ export type ErCardinality = "|o" | "||" | "}o" | "}|" | "o|" | "o{" | "|{";
237
+ export interface ErRelationship {
238
+ id: string;
239
+ left: string;
240
+ right: string;
241
+ leftCard: string;
242
+ rightCard: string;
243
+ identifying: boolean;
244
+ label: string;
245
+ raw?: string;
246
+ dirty?: boolean;
247
+ added?: boolean;
248
+ }
249
+ export interface ErEntity {
250
+ id: string;
251
+ /** Whole `NAME { … }` attribute block, verbatim lines (header..close). */
252
+ blockRaw?: string[];
253
+ }
254
+ export interface ErDoc extends DocBase {
255
+ kind: "er";
256
+ entities: ErEntity[];
257
+ relationships: ErRelationship[];
258
+ }
259
+ export type MermaidDoc = FlowchartDoc | MindmapDoc | SequenceDoc | PieDoc | TimelineDoc | JourneyDoc | QuadrantDoc | StateDoc | ErDoc;
260
+ export type ParseOutcome = {
261
+ status: "ok";
262
+ doc: MermaidDoc;
263
+ } | {
264
+ status: "code-only";
265
+ reason: string;
266
+ diagnostics: Diagnostic[];
267
+ } | {
268
+ status: "invalid";
269
+ diagnostics: Diagnostic[];
270
+ };
271
+ export {};
File without changes
@@ -0,0 +1,9 @@
1
+ /** The source of every ```mermaid fence, as the print package will hand it back. */
2
+ export declare function mermaidFenceSources(markdown: string): string[];
3
+ export interface PrintedDiagrams {
4
+ /** SVG by fence source. */
5
+ pictures: Map<string, string>;
6
+ /** Fences that could not be drawn (they print as source). */
7
+ failed: number;
8
+ }
9
+ export declare function drawMermaidForPrint(markdown: string): Promise<PrintedDiagrams>;
@@ -0,0 +1,39 @@
1
+ import { renderMermaid } from "./runtime.js";
2
+ const PRINT_OPTIONS = { theme: "default", look: "classic", layout: "dagre" };
3
+ function mermaidFenceSources(markdown) {
4
+ const out = [];
5
+ const lines = markdown.split("\n");
6
+ for (let i = 0; i < lines.length; i++) {
7
+ const open = /^(\s*)(`{3,}|~{3,})\s*mermaid\b[^`]*$/.exec(lines[i]);
8
+ if (!open) continue;
9
+ const marker = open[2];
10
+ const indent = open[1].length;
11
+ const body = [];
12
+ let j = i + 1;
13
+ for (; j < lines.length; j++) {
14
+ const close = /^\s*(`{3,}|~{3,})\s*$/.exec(lines[j]);
15
+ if (close && close[1][0] === marker[0] && close[1].length >= marker.length) break;
16
+ body.push(lines[j]);
17
+ }
18
+ out.push(body.map((l) => l.slice(Math.min(indent, l.length - l.trimStart().length))).join("\n"));
19
+ i = j;
20
+ }
21
+ return out;
22
+ }
23
+ async function drawMermaidForPrint(markdown) {
24
+ const pictures = /* @__PURE__ */ new Map();
25
+ let failed = 0;
26
+ for (const source of new Set(mermaidFenceSources(markdown))) {
27
+ try {
28
+ const { svg } = await renderMermaid(source, PRINT_OPTIONS);
29
+ pictures.set(source, svg);
30
+ } catch {
31
+ failed++;
32
+ }
33
+ }
34
+ return { pictures, failed };
35
+ }
36
+ export {
37
+ drawMermaidForPrint,
38
+ mermaidFenceSources
39
+ };
@@ -0,0 +1,25 @@
1
+ import { type MermaidRenderOptions } from "./types.js";
2
+ export declare class MermaidRenderSupersededError extends Error {
3
+ constructor();
4
+ }
5
+ export declare function pieThemeVariables(theme: MermaidRenderOptions["theme"]): Record<string, string> | undefined;
6
+ /** Fire-and-forget warmup — call when a mermaid block mounts mid-stream. */
7
+ export declare function preloadMermaid(): void;
8
+ export declare function isElkAvailable(): boolean;
9
+ /**
10
+ * Parse-only validation. Returns ok=false (never throws) on invalid source.
11
+ */
12
+ export declare function validateMermaid(source: string): Promise<{
13
+ ok: boolean;
14
+ error?: string;
15
+ }>;
16
+ /**
17
+ * Serialized render — mermaid.render is async AND reads global config; two
18
+ * concurrent renders with different options would corrupt each other. A
19
+ * failed render must not poison the chain for the next caller.
20
+ */
21
+ export declare function renderMermaid(source: string, opts: MermaidRenderOptions, consumerId?: string): Promise<{
22
+ svg: string;
23
+ }>;
24
+ /** Mark a mounted renderer's queued work stale before its next debounce fires. */
25
+ export declare function supersedeMermaidRender(consumerId: string): void;
@@ -0,0 +1,183 @@
1
+ "use client";
2
+ import { announceBareHost, hostCapability } from "../host/registry.js";
3
+ import { humanizeMermaidError } from "./sanitize.js";
4
+ import { renderOptionsKey } from "./types.js";
5
+ console.log(
6
+ "%c[MERMAID IMPORT TEST] components/mermaid/runtime.ts",
7
+ "color: #fff; background: #7c3aed; font-weight: bold; padding: 2px 6px; border-radius: 3px;"
8
+ );
9
+ let mermaidPromise = null;
10
+ let elkPromise = null;
11
+ let elkRegistered = false;
12
+ let lastConfigKey = "";
13
+ let renderChain = Promise.resolve();
14
+ let idCounter = 0;
15
+ const MAX_RENDER_CACHE_ENTRIES = 12;
16
+ const renderCache = /* @__PURE__ */ new Map();
17
+ const inFlightRenders = /* @__PURE__ */ new Map();
18
+ const latestRenderByConsumer = /* @__PURE__ */ new Map();
19
+ class MermaidRenderSupersededError extends Error {
20
+ constructor() {
21
+ super("Mermaid render superseded by newer source");
22
+ this.name = "MermaidRenderSupersededError";
23
+ }
24
+ }
25
+ function baseConfig() {
26
+ return {
27
+ startOnLoad: false,
28
+ securityLevel: "strict",
29
+ // Plain-SVG labels (no <foreignObject>) so PNG export via canvas never
30
+ // taints and Safari rasterization works.
31
+ flowchart: { htmlLabels: false },
32
+ fontFamily: "inherit"
33
+ };
34
+ }
35
+ const PIE_PALETTE = {
36
+ default: ["#2a78d6", "#eb6834", "#1baf7a", "#eda100", "#e87ba4", "#008300", "#4a3aa7", "#e34948"],
37
+ dark: ["#3987e5", "#d95926", "#199e70", "#c98500", "#d55181", "#008300", "#9085e9", "#e66767"]
38
+ };
39
+ function pieThemeVariables(theme) {
40
+ if (theme !== "default" && theme !== "dark") return void 0;
41
+ const slices = PIE_PALETTE[theme];
42
+ const vars = {
43
+ pieSectionTextColor: "#ffffff",
44
+ pieStrokeColor: theme === "dark" ? "#262626" : "#ffffff",
45
+ pieStrokeWidth: "2px",
46
+ pieOuterStrokeWidth: "0px",
47
+ pieOpacity: "1"
48
+ };
49
+ for (let i = 0; i < 12; i++) vars[`pie${i + 1}`] = slices[i % slices.length];
50
+ return vars;
51
+ }
52
+ async function getMermaid() {
53
+ if (!mermaidPromise) {
54
+ mermaidPromise = (async () => {
55
+ const load = hostCapability("loadMermaid");
56
+ if (!load) {
57
+ announceBareHost("loadMermaid", "diagrams show their source");
58
+ throw new Error("This app has no diagram renderer installed.");
59
+ }
60
+ const mermaid = await load();
61
+ mermaid.initialize(baseConfig());
62
+ lastConfigKey = "";
63
+ return mermaid;
64
+ })();
65
+ }
66
+ return mermaidPromise;
67
+ }
68
+ async function ensureElk(mermaid) {
69
+ if (elkRegistered) return true;
70
+ if (!elkPromise) {
71
+ const loadElk = hostCapability("loadMermaidElk");
72
+ elkPromise = (loadElk ? loadElk() : Promise.reject(new Error("no ELK layout from the host"))).then((elk) => {
73
+ mermaid.registerLayoutLoaders(elk);
74
+ elkRegistered = true;
75
+ return true;
76
+ }).catch((err) => {
77
+ console.warn(
78
+ "[MermaidRuntime] ELK layout plugin failed to load; dagre only",
79
+ err
80
+ );
81
+ return false;
82
+ });
83
+ }
84
+ return elkPromise;
85
+ }
86
+ function preloadMermaid() {
87
+ if (typeof window === "undefined") return;
88
+ void getMermaid().catch(() => {
89
+ });
90
+ }
91
+ function isElkAvailable() {
92
+ return elkRegistered;
93
+ }
94
+ async function validateMermaid(source) {
95
+ try {
96
+ const mermaid = await getMermaid();
97
+ const result = await mermaid.parse(source, { suppressErrors: true });
98
+ return result === false ? { ok: false } : { ok: true };
99
+ } catch (err) {
100
+ const raw = err instanceof Error ? err.message : String(err);
101
+ console.warn(
102
+ "[MermaidRuntime] mermaid.parse threw (not a clean parse failure):",
103
+ err
104
+ );
105
+ return { ok: false, error: humanizeMermaidError(raw) };
106
+ }
107
+ }
108
+ async function applyOptions(mermaid, opts) {
109
+ const layout = opts.layout === "elk" && !await ensureElk(mermaid) ? "dagre" : opts.layout;
110
+ const key = renderOptionsKey({ ...opts, layout });
111
+ if (key === lastConfigKey) return;
112
+ mermaid.initialize({
113
+ ...baseConfig(),
114
+ theme: opts.theme,
115
+ look: opts.look,
116
+ layout,
117
+ themeVariables: pieThemeVariables(opts.theme),
118
+ pie: { legendPosition: opts.pieLegend ?? "right" }
119
+ });
120
+ lastConfigKey = key;
121
+ }
122
+ async function doRender(source, opts) {
123
+ const mermaid = await getMermaid();
124
+ await applyOptions(mermaid, opts);
125
+ const id = `mmd-${++idCounter}`;
126
+ try {
127
+ const { svg } = await mermaid.render(id, source);
128
+ return { svg };
129
+ } catch (err) {
130
+ document.getElementById(id)?.remove();
131
+ document.getElementById(`d${id}`)?.remove();
132
+ throw err;
133
+ }
134
+ }
135
+ function renderMermaid(source, opts, consumerId) {
136
+ const cacheKey = `${renderOptionsKey(opts)}\0${source}`;
137
+ if (consumerId) latestRenderByConsumer.set(consumerId, cacheKey);
138
+ const cached = renderCache.get(cacheKey);
139
+ if (cached) {
140
+ renderCache.delete(cacheKey);
141
+ renderCache.set(cacheKey, cached);
142
+ return Promise.resolve(cached);
143
+ }
144
+ const inFlight = inFlightRenders.get(cacheKey);
145
+ if (inFlight) {
146
+ inFlight.consumers.add(consumerId ?? null);
147
+ return inFlight.promise;
148
+ }
149
+ const consumers = /* @__PURE__ */ new Set([consumerId ?? null]);
150
+ const task = renderChain.then(() => {
151
+ const stillWanted = [...consumers].some(
152
+ (id) => id === null || latestRenderByConsumer.get(id) === cacheKey
153
+ );
154
+ if (!stillWanted) throw new MermaidRenderSupersededError();
155
+ return doRender(source, opts);
156
+ }).then((result) => {
157
+ renderCache.set(cacheKey, result);
158
+ while (renderCache.size > MAX_RENDER_CACHE_ENTRIES) {
159
+ const oldestKey = renderCache.keys().next().value;
160
+ if (oldestKey === void 0) break;
161
+ renderCache.delete(oldestKey);
162
+ }
163
+ return result;
164
+ }).finally(() => {
165
+ inFlightRenders.delete(cacheKey);
166
+ });
167
+ inFlightRenders.set(cacheKey, { promise: task, consumers });
168
+ renderChain = task.catch(() => {
169
+ });
170
+ return task;
171
+ }
172
+ function supersedeMermaidRender(consumerId) {
173
+ latestRenderByConsumer.delete(consumerId);
174
+ }
175
+ export {
176
+ MermaidRenderSupersededError,
177
+ isElkAvailable,
178
+ pieThemeVariables,
179
+ preloadMermaid,
180
+ renderMermaid,
181
+ supersedeMermaidRender,
182
+ validateMermaid
183
+ };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The forgiving ladder — progressive auto-repair of LLM-generated mermaid.
3
+ *
4
+ * Contract:
5
+ * - Pure and mermaid-free: the validator is injected, so this module is unit
6
+ * testable and never drags the engine into a bundle.
7
+ * - The ORIGINAL source is never destroyed — callers render the fixed source
8
+ * but copy/export the original. Fixes are reported, not silent.
9
+ * - Recovery SCREAMS (console.warn) — a fixer firing means an agent emitted
10
+ * broken syntax, which is a real upstream defect we want visible.
11
+ * - Streaming mode runs only the lossless Stage A normalizers: partial text
12
+ * is EXPECTED to fail validation, so heavy per-rule work is skipped and the
13
+ * caller keeps its last-good render.
14
+ */
15
+ export interface MermaidFix {
16
+ rule: string;
17
+ detail: string;
18
+ }
19
+ export interface LadderResult {
20
+ /** The source that validated (fixed), or the best-effort source if invalid. */
21
+ source: string;
22
+ valid: boolean;
23
+ fixes: MermaidFix[];
24
+ /** The engine's parse error message when invalid after all fixers. */
25
+ error?: string;
26
+ }
27
+ export type MermaidValidator = (source: string) => Promise<{
28
+ ok: boolean;
29
+ error?: string;
30
+ }>;
31
+ /**
32
+ * Turn an engine error into something a human can act on. Mermaid (and the
33
+ * libraries under it) sometimes throw raw JS runtime errors — most notoriously
34
+ * a `Converting circular structure to JSON … __reactFiber …` TypeError that
35
+ * carries a live DOM node — instead of a parse message. Those say nothing
36
+ * useful to the reader, so we replace them with a clear line. The raw text is
37
+ * still logged at the call site for debugging.
38
+ */
39
+ export declare function humanizeMermaidError(raw?: string): string | undefined;
40
+ /**
41
+ * Run the ladder: raw → Stage A normalizers → per-rule Stage B fixers,
42
+ * validating cumulatively, until the source parses or every rule is spent.
43
+ */
44
+ export declare function parseWithLadder(raw: string, validate: MermaidValidator, opts: {
45
+ streaming: boolean;
46
+ }): Promise<LadderResult>;