@ai-matrx/rich-content 0.2.4 → 0.2.7

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 +25 -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 +48 -10
@@ -0,0 +1,207 @@
1
+ import { splitFrontmatter } from "../diagram-type.js";
2
+ import { MermaidOpError } from "../model/ops.js";
3
+ const TASK_RE = /^(.+?)\s*:\s*([0-9]+(?:\.[0-9]+)?)\s*(?::\s*(.*))?$/;
4
+ function parse(source) {
5
+ const { bodyStartIndex, lines } = splitFrontmatter(source);
6
+ const doc = {
7
+ kind: "journey",
8
+ diagramType: "journey",
9
+ frontmatter: lines.slice(0, bodyStartIndex),
10
+ sourceLines: [],
11
+ warnings: [],
12
+ sections: []
13
+ };
14
+ let headerSeen = false;
15
+ let counter = 0;
16
+ let sectionCounter = 0;
17
+ let currentSection = null;
18
+ const implicitSection = () => {
19
+ if (!currentSection) {
20
+ currentSection = { id: `sec${++sectionCounter}`, tasks: [] };
21
+ doc.sections.push(currentSection);
22
+ }
23
+ return currentSection;
24
+ };
25
+ for (const rawLine of lines.slice(bodyStartIndex)) {
26
+ const trimmed = rawLine.trim();
27
+ if (!trimmed || trimmed.startsWith("%%")) {
28
+ doc.sourceLines.push({ text: rawLine });
29
+ continue;
30
+ }
31
+ if (!headerSeen) {
32
+ if (!/^journey\s*$/.test(trimmed)) {
33
+ return { status: "code-only", reason: "unrecognized journey header", diagnostics: [] };
34
+ }
35
+ headerSeen = true;
36
+ doc.sourceLines.push({ text: rawLine, ref: { entity: "header", id: "header" } });
37
+ continue;
38
+ }
39
+ const title = /^title\s+(.+)$/.exec(trimmed);
40
+ if (title && doc.title === void 0) {
41
+ doc.title = title[1].trim();
42
+ doc.sourceLines.push({ text: rawLine, ref: { entity: "title", id: "title" } });
43
+ continue;
44
+ }
45
+ const section = /^section\s+(.+)$/.exec(trimmed);
46
+ if (section) {
47
+ currentSection = { id: `sec${++sectionCounter}`, title: section[1].trim(), tasks: [], raw: rawLine };
48
+ doc.sections.push(currentSection);
49
+ doc.sourceLines.push({ text: rawLine, ref: { entity: "section", id: currentSection.id } });
50
+ continue;
51
+ }
52
+ const task = TASK_RE.exec(trimmed);
53
+ if (task) {
54
+ const actors = (task[3] ?? "").split(",").map((a) => a.trim()).filter(Boolean);
55
+ const t = {
56
+ id: `j${++counter}`,
57
+ name: task[1].trim(),
58
+ score: Number(task[2]),
59
+ actors,
60
+ raw: rawLine
61
+ };
62
+ implicitSection().tasks.push(t);
63
+ doc.sourceLines.push({ text: rawLine, ref: { entity: "task", id: t.id } });
64
+ continue;
65
+ }
66
+ return {
67
+ status: "code-only",
68
+ reason: `unrecognized statement: "${trimmed.slice(0, 40)}"`,
69
+ diagnostics: []
70
+ };
71
+ }
72
+ if (!headerSeen) {
73
+ return { status: "invalid", diagnostics: [{ line: 1, message: "missing journey header", severity: "error" }] };
74
+ }
75
+ return { status: "ok", doc };
76
+ }
77
+ function taskLine(task) {
78
+ const actors = task.actors.length > 0 ? `: ${task.actors.join(", ")}` : "";
79
+ return `${task.name}: ${task.score}${actors}`;
80
+ }
81
+ function serialize(doc) {
82
+ const jdoc = doc;
83
+ const out = [...doc.frontmatter];
84
+ if (jdoc.regenerateAll) {
85
+ const comments = doc.sourceLines.filter((l) => !l.ref && l.text.trim().startsWith("%%")).map((l) => l.text);
86
+ out.push("journey", ...comments);
87
+ if (doc.title !== void 0) out.push(` title ${doc.title}`);
88
+ for (const section of doc.sections) {
89
+ if (section.title !== void 0) out.push(` section ${section.title}`);
90
+ for (const task of section.tasks) out.push(` ${taskLine(task)}`);
91
+ }
92
+ return out.join("\n");
93
+ }
94
+ const taskById = /* @__PURE__ */ new Map();
95
+ const sectionById = /* @__PURE__ */ new Map();
96
+ for (const section of doc.sections) {
97
+ sectionById.set(section.id, section);
98
+ for (const task of section.tasks) taskById.set(task.id, task);
99
+ }
100
+ for (const line of doc.sourceLines) {
101
+ const indent = /^(\s*)/.exec(line.text)?.[1] ?? "";
102
+ if (!line.ref) {
103
+ out.push(line.text);
104
+ continue;
105
+ }
106
+ switch (line.ref.entity) {
107
+ case "title":
108
+ if (doc.title === void 0) break;
109
+ out.push(jdoc.dirtyTitle ? `${indent}title ${doc.title}` : line.text);
110
+ break;
111
+ case "section": {
112
+ const section = sectionById.get(line.ref.id);
113
+ if (!section) break;
114
+ out.push(section.dirty ? `${indent}section ${section.title ?? ""}` : line.text);
115
+ break;
116
+ }
117
+ case "task": {
118
+ const task = taskById.get(line.ref.id);
119
+ if (!task) break;
120
+ out.push(task.dirty ? `${indent}${taskLine(task)}` : line.text);
121
+ break;
122
+ }
123
+ default:
124
+ out.push(line.text);
125
+ }
126
+ }
127
+ return out.join("\n");
128
+ }
129
+ function applyOp(doc, op) {
130
+ const next = structuredClone(doc);
131
+ const jop = op;
132
+ const findTask = (id) => {
133
+ for (const section of next.sections) {
134
+ const task = section.tasks.find((t) => t.id === id);
135
+ if (task) return task;
136
+ }
137
+ throw new MermaidOpError("That task no longer exists");
138
+ };
139
+ const findSection = (id) => {
140
+ const s = next.sections.find((x) => x.id === id);
141
+ if (!s) throw new MermaidOpError("That section no longer exists");
142
+ return s;
143
+ };
144
+ switch (jop.type) {
145
+ case "setTitle": {
146
+ next.title = jop.title || void 0;
147
+ next.dirtyTitle = true;
148
+ if (!next.sourceLines.some((l) => l.ref?.entity === "title")) next.regenerateAll = true;
149
+ return next;
150
+ }
151
+ case "addSection": {
152
+ next.sections.push({ id: `sec_a${next.sections.length + 1}`, title: jop.title, tasks: [] });
153
+ next.regenerateAll = true;
154
+ return next;
155
+ }
156
+ case "renameSection": {
157
+ const s = findSection(jop.id);
158
+ s.title = jop.title;
159
+ s.dirty = true;
160
+ return next;
161
+ }
162
+ case "deleteSection": {
163
+ findSection(jop.id);
164
+ next.sections = next.sections.filter((s) => s.id !== jop.id);
165
+ next.regenerateAll = true;
166
+ return next;
167
+ }
168
+ case "addTask": {
169
+ const s = findSection(jop.sectionId);
170
+ s.tasks.push({
171
+ id: `j_a${s.tasks.length + 1}`,
172
+ name: jop.name,
173
+ score: jop.score ?? 3,
174
+ actors: jop.actors ?? []
175
+ });
176
+ next.regenerateAll = true;
177
+ return next;
178
+ }
179
+ case "editTask": {
180
+ const task = findTask(jop.id);
181
+ if (jop.name !== void 0) task.name = jop.name;
182
+ if (jop.score !== void 0) task.score = jop.score;
183
+ if (jop.actors !== void 0) task.actors = jop.actors;
184
+ task.dirty = true;
185
+ return next;
186
+ }
187
+ case "deleteTask": {
188
+ findTask(jop.id);
189
+ for (const section of next.sections) {
190
+ section.tasks = section.tasks.filter((t) => t.id !== jop.id);
191
+ }
192
+ return next;
193
+ }
194
+ default:
195
+ throw new MermaidOpError("Unsupported operation for journeys");
196
+ }
197
+ }
198
+ const journeyAdapter = {
199
+ diagramType: "journey",
200
+ parse,
201
+ serialize,
202
+ applyOp,
203
+ vocabulary: { node: "Task", addNode: "Add task" }
204
+ };
205
+ export {
206
+ journeyAdapter
207
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Mindmap adapter — indentation-tree parse / serialize / ops.
3
+ *
4
+ * Label edits regenerate single lines in place. Structural ops (add / delete /
5
+ * indent / outdent / move) regenerate the whole tree body with normalized
6
+ * 2-space indentation — content-preserving (labels, shapes, ::icon decorators
7
+ * and comments are all re-emitted), formatting-normalizing, and only ever
8
+ * after the fidelity gate has passed on the untouched document.
9
+ */
10
+ import type { MermaidAdapter } from "../model/adapter.js";
11
+ import type { MindmapDoc } from "../model/types.js";
12
+ export declare const mindmapAdapter: MermaidAdapter<MindmapDoc>;
@@ -0,0 +1,252 @@
1
+ import { splitFrontmatter } from "../diagram-type.js";
2
+ import { MermaidOpError } from "../model/ops.js";
3
+ const SHAPE_WRAPPERS = [
4
+ ["bang", "))", "(("],
5
+ ["circle", "((", "))"],
6
+ ["cloud", ")", "("],
7
+ ["hexagon", "{{", "}}"],
8
+ ["square", "[", "]"],
9
+ ["rounded", "(", ")"]
10
+ ];
11
+ function parseToken(token) {
12
+ const idMatch = /^([A-Za-z][A-Za-z0-9_-]*)(?=\(|\[|\)|\{)/.exec(token);
13
+ const declId = idMatch?.[1];
14
+ const rest = declId ? token.slice(declId.length) : token;
15
+ for (const [shape, open, close] of SHAPE_WRAPPERS) {
16
+ if (rest.startsWith(open) && rest.endsWith(close) && rest.length > open.length + close.length - 1) {
17
+ return { declId, label: rest.slice(open.length, rest.length - close.length).trim(), shape };
18
+ }
19
+ }
20
+ return { label: token.trim(), shape: "default" };
21
+ }
22
+ function wrapToken(node) {
23
+ const id = node.declId ?? "";
24
+ for (const [shape, open, close] of SHAPE_WRAPPERS) {
25
+ if (shape === node.shape) return `${id}${open}${node.label}${close}`;
26
+ }
27
+ return node.label;
28
+ }
29
+ function parse(source) {
30
+ const { bodyStartIndex, lines } = splitFrontmatter(source);
31
+ const frontmatter = lines.slice(0, bodyStartIndex);
32
+ const body = lines.slice(bodyStartIndex);
33
+ const doc = {
34
+ kind: "mindmap",
35
+ diagramType: "mindmap",
36
+ frontmatter,
37
+ sourceLines: [],
38
+ warnings: [],
39
+ root: { id: "m0", label: "", shape: "default", decorators: [], children: [] }
40
+ };
41
+ let headerSeen = false;
42
+ let counter = 0;
43
+ const stack = [];
44
+ let rootSet = false;
45
+ for (let li = 0; li < body.length; li++) {
46
+ const rawLine = body[li];
47
+ const trimmed = rawLine.trim();
48
+ if (!trimmed || trimmed.startsWith("%%")) {
49
+ doc.sourceLines.push({ text: rawLine });
50
+ continue;
51
+ }
52
+ if (!headerSeen) {
53
+ if (!/^mindmap\s*$/.test(trimmed)) {
54
+ return { status: "code-only", reason: "unrecognized mindmap header", diagnostics: [] };
55
+ }
56
+ headerSeen = true;
57
+ doc.sourceLines.push({ text: rawLine, ref: { entity: "header", id: "header" } });
58
+ continue;
59
+ }
60
+ if (trimmed.startsWith("::icon")) {
61
+ const owner = stack[stack.length - 1];
62
+ if (!owner) {
63
+ return { status: "code-only", reason: "icon decorator before any node", diagnostics: [] };
64
+ }
65
+ owner.decorators.push(trimmed);
66
+ doc.sourceLines.push({ text: rawLine, ref: { entity: "decorator", id: owner.id } });
67
+ continue;
68
+ }
69
+ const indent = (/^(\s*)/.exec(rawLine)?.[1] ?? "").length;
70
+ const token = parseToken(trimmed);
71
+ const node = {
72
+ id: `m${++counter}`,
73
+ label: token.label,
74
+ shape: token.shape,
75
+ declId: token.declId,
76
+ decorators: [],
77
+ children: [],
78
+ raw: rawLine,
79
+ indent
80
+ };
81
+ while (stack.length > 0 && (stack[stack.length - 1].indent ?? 0) >= indent) {
82
+ stack.pop();
83
+ }
84
+ if (stack.length === 0) {
85
+ if (rootSet) {
86
+ return { status: "code-only", reason: "mindmaps support a single root", diagnostics: [] };
87
+ }
88
+ doc.root = node;
89
+ rootSet = true;
90
+ } else {
91
+ stack[stack.length - 1].children.push(node);
92
+ }
93
+ stack.push(node);
94
+ doc.sourceLines.push({ text: rawLine, ref: { entity: "node", id: node.id } });
95
+ }
96
+ if (!headerSeen || !rootSet) {
97
+ return {
98
+ status: "invalid",
99
+ diagnostics: [{ line: 1, message: "missing mindmap content", severity: "error" }]
100
+ };
101
+ }
102
+ return { status: "ok", doc };
103
+ }
104
+ function collectNodes(root) {
105
+ const map = /* @__PURE__ */ new Map();
106
+ const walk = (n) => {
107
+ map.set(n.id, n);
108
+ n.children.forEach((c) => walk(c));
109
+ };
110
+ walk(root);
111
+ return map;
112
+ }
113
+ function findParent(root, id) {
114
+ let found = null;
115
+ const walk = (n) => {
116
+ for (const c of n.children) {
117
+ if (c.id === id) found = n;
118
+ walk(c);
119
+ }
120
+ };
121
+ walk(root);
122
+ return found;
123
+ }
124
+ function serialize(doc) {
125
+ const out = [...doc.frontmatter];
126
+ const nodeById = collectNodes(doc.root);
127
+ if (doc.regenerateAll) {
128
+ const comments = doc.sourceLines.filter((l) => !l.ref && l.text.trim().startsWith("%%")).map((l) => l.text);
129
+ const headerLine = doc.sourceLines.find((l) => l.ref?.entity === "header")?.text ?? "mindmap";
130
+ out.push(headerLine, ...comments);
131
+ const emit = (node, depth) => {
132
+ const indent = " ".repeat(depth + 1);
133
+ out.push(`${indent}${wrapToken(node)}`);
134
+ for (const d of node.decorators) out.push(`${indent}${d}`);
135
+ node.children.forEach((c) => emit(c, depth + 1));
136
+ };
137
+ emit(doc.root, 0);
138
+ return out.join("\n");
139
+ }
140
+ for (const line of doc.sourceLines) {
141
+ if (!line.ref) {
142
+ out.push(line.text);
143
+ continue;
144
+ }
145
+ if (line.ref.entity === "node") {
146
+ const node = nodeById.get(line.ref.id);
147
+ if (!node) continue;
148
+ const indent = /^(\s*)/.exec(line.text)?.[1] ?? "";
149
+ out.push(node.dirty ? `${indent}${wrapToken(node)}` : line.text);
150
+ continue;
151
+ }
152
+ out.push(line.text);
153
+ }
154
+ return out.join("\n");
155
+ }
156
+ function applyOp(doc, op) {
157
+ const next = structuredClone(doc);
158
+ const mop = op;
159
+ const root = next.root;
160
+ const nodeById = collectNodes(root);
161
+ const get = (id) => {
162
+ const n = nodeById.get(id);
163
+ if (!n) throw new MermaidOpError("That topic no longer exists");
164
+ return n;
165
+ };
166
+ let counter = nodeById.size;
167
+ switch (mop.type) {
168
+ case "renameNode": {
169
+ const n = get(mop.id);
170
+ n.label = mop.label;
171
+ n.dirty = true;
172
+ return next;
173
+ }
174
+ case "setShape": {
175
+ const n = get(mop.id);
176
+ n.shape = mop.shape;
177
+ n.dirty = true;
178
+ return next;
179
+ }
180
+ case "addChild": {
181
+ const parent = get(mop.parentId);
182
+ parent.children.push({
183
+ id: `m_a${++counter}`,
184
+ label: mop.label,
185
+ shape: "default",
186
+ decorators: [],
187
+ children: []
188
+ });
189
+ next.regenerateAll = true;
190
+ return next;
191
+ }
192
+ case "deleteNode": {
193
+ if (mop.id === root.id) throw new MermaidOpError("The central idea can't be deleted");
194
+ const parent = findParent(root, mop.id);
195
+ if (!parent) throw new MermaidOpError("That topic no longer exists");
196
+ parent.children = parent.children.filter((c) => c.id !== mop.id);
197
+ next.regenerateAll = true;
198
+ return next;
199
+ }
200
+ case "indent": {
201
+ const parent = findParent(root, mop.id);
202
+ if (!parent) throw new MermaidOpError("That topic no longer exists");
203
+ const idx = parent.children.findIndex((c) => c.id === mop.id);
204
+ if (idx <= 0) throw new MermaidOpError("Nothing above to nest under");
205
+ const node = parent.children[idx];
206
+ parent.children.splice(idx, 1);
207
+ parent.children[idx - 1].children.push(node);
208
+ next.regenerateAll = true;
209
+ return next;
210
+ }
211
+ case "outdent": {
212
+ const parent = findParent(root, mop.id);
213
+ if (!parent) throw new MermaidOpError("That topic no longer exists");
214
+ if (parent.id === root.id) throw new MermaidOpError("Already at the top level");
215
+ const grandparent = findParent(root, parent.id);
216
+ if (!grandparent) throw new MermaidOpError("Already at the top level");
217
+ const idx = parent.children.findIndex((c) => c.id === mop.id);
218
+ const node = parent.children[idx];
219
+ parent.children.splice(idx, 1);
220
+ const parentIdx = grandparent.children.findIndex((c) => c.id === parent.id);
221
+ grandparent.children.splice(parentIdx + 1, 0, node);
222
+ next.regenerateAll = true;
223
+ return next;
224
+ }
225
+ case "moveBefore": {
226
+ const parent = findParent(root, mop.id);
227
+ const siblingParent = findParent(root, mop.siblingId);
228
+ if (!parent || !siblingParent || parent.id !== siblingParent.id) {
229
+ throw new MermaidOpError("Topics can only be reordered among siblings");
230
+ }
231
+ const node = parent.children.find((c) => c.id === mop.id);
232
+ if (!node) throw new MermaidOpError("That topic no longer exists");
233
+ parent.children = parent.children.filter((c) => c.id !== mop.id);
234
+ const target = parent.children.findIndex((c) => c.id === mop.siblingId);
235
+ parent.children.splice(target, 0, node);
236
+ next.regenerateAll = true;
237
+ return next;
238
+ }
239
+ default:
240
+ throw new MermaidOpError("Unsupported operation for mind maps");
241
+ }
242
+ }
243
+ const mindmapAdapter = {
244
+ diagramType: "mindmap",
245
+ parse,
246
+ serialize,
247
+ applyOp,
248
+ vocabulary: { node: "Topic", addNode: "Add topic" }
249
+ };
250
+ export {
251
+ mindmapAdapter
252
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Pie adapter — the simplest grammar: header (+showData/title), title line,
3
+ * `"label" : value` slices. All edits are per-line; new slices append.
4
+ */
5
+ import type { MermaidAdapter } from "../model/adapter.js";
6
+ import type { PieDoc } from "../model/types.js";
7
+ export declare const pieAdapter: MermaidAdapter<PieDoc>;
@@ -0,0 +1,172 @@
1
+ import { splitFrontmatter } from "../diagram-type.js";
2
+ import { MermaidOpError } from "../model/ops.js";
3
+ const HEADER_RE = /^pie(\s+showData)?(?:\s+title\s+(.+))?\s*$/;
4
+ const TITLE_RE = /^title\s+(.+)$/;
5
+ const SLICE_RE = /^"([^"]*)"\s*:\s*([0-9]+(?:\.[0-9]+)?)\s*$/;
6
+ const SLICE_UNQUOTED_RE = /^([^:"]+?)\s*:\s*([0-9]+(?:\.[0-9]+)?)\s*$/;
7
+ function parse(source) {
8
+ const { bodyStartIndex, lines } = splitFrontmatter(source);
9
+ const doc = {
10
+ kind: "pie",
11
+ diagramType: "pie",
12
+ frontmatter: lines.slice(0, bodyStartIndex),
13
+ sourceLines: [],
14
+ warnings: [],
15
+ showData: false,
16
+ slices: []
17
+ };
18
+ let headerSeen = false;
19
+ let counter = 0;
20
+ for (const rawLine of lines.slice(bodyStartIndex)) {
21
+ const trimmed = rawLine.trim();
22
+ if (!trimmed || trimmed.startsWith("%%")) {
23
+ doc.sourceLines.push({ text: rawLine });
24
+ continue;
25
+ }
26
+ if (!headerSeen) {
27
+ const header = HEADER_RE.exec(trimmed);
28
+ if (!header) return { status: "code-only", reason: "unrecognized pie header", diagnostics: [] };
29
+ headerSeen = true;
30
+ doc.showData = Boolean(header[1]);
31
+ if (header[2]) {
32
+ doc.title = header[2].trim().replace(/^"|"$/g, "");
33
+ doc.headerTitle = true;
34
+ }
35
+ doc.sourceLines.push({ text: rawLine, ref: { entity: "header", id: "header" } });
36
+ continue;
37
+ }
38
+ const title = TITLE_RE.exec(trimmed);
39
+ if (title && doc.title === void 0) {
40
+ doc.title = title[1].trim().replace(/^"|"$/g, "");
41
+ doc.sourceLines.push({ text: rawLine, ref: { entity: "title", id: "title" } });
42
+ continue;
43
+ }
44
+ const slice = SLICE_RE.exec(trimmed) ?? SLICE_UNQUOTED_RE.exec(trimmed);
45
+ if (slice) {
46
+ const s = {
47
+ id: `p${++counter}`,
48
+ label: slice[1].trim(),
49
+ value: Number(slice[2]),
50
+ raw: rawLine
51
+ };
52
+ doc.slices.push(s);
53
+ doc.sourceLines.push({ text: rawLine, ref: { entity: "slice", id: s.id } });
54
+ continue;
55
+ }
56
+ return {
57
+ status: "code-only",
58
+ reason: `unrecognized statement: "${trimmed.slice(0, 40)}"`,
59
+ diagnostics: []
60
+ };
61
+ }
62
+ if (!headerSeen) {
63
+ return { status: "invalid", diagnostics: [{ line: 1, message: "missing pie header", severity: "error" }] };
64
+ }
65
+ return { status: "ok", doc };
66
+ }
67
+ function sliceLine(slice) {
68
+ return `"${slice.label.replace(/"/g, "'")}" : ${slice.value}`;
69
+ }
70
+ function headerLine(doc) {
71
+ const parts = ["pie"];
72
+ if (doc.showData) parts.push("showData");
73
+ if (doc.headerTitle && doc.title) parts.push(`title ${doc.title}`);
74
+ return parts.join(" ");
75
+ }
76
+ function serialize(doc) {
77
+ const pdoc = doc;
78
+ const out = [...doc.frontmatter];
79
+ const sliceById = new Map(doc.slices.map((s) => [s.id, s]));
80
+ const emitted = /* @__PURE__ */ new Set();
81
+ let headerEmitted = false;
82
+ for (const line of doc.sourceLines) {
83
+ const indent = /^(\s*)/.exec(line.text)?.[1] ?? "";
84
+ if (!line.ref) {
85
+ out.push(line.text);
86
+ continue;
87
+ }
88
+ switch (line.ref.entity) {
89
+ case "header":
90
+ headerEmitted = true;
91
+ out.push(pdoc.dirtyHeader ? `${indent}${headerLine(pdoc)}` : line.text);
92
+ break;
93
+ case "title":
94
+ if (pdoc.title === void 0) break;
95
+ out.push(pdoc.dirtyTitle ? `${indent}title ${pdoc.title}` : line.text);
96
+ break;
97
+ case "slice": {
98
+ const slice = sliceById.get(line.ref.id);
99
+ if (!slice) break;
100
+ emitted.add(slice.id);
101
+ out.push(slice.dirty ? `${indent}${sliceLine(slice)}` : line.text);
102
+ break;
103
+ }
104
+ default:
105
+ out.push(line.text);
106
+ }
107
+ }
108
+ const additions = [];
109
+ if (pdoc.title !== void 0 && !pdoc.headerTitle && !doc.sourceLines.some((l) => l.ref?.entity === "title")) {
110
+ const headerIndex = out.findIndex((l) => /^\s*pie\b/.test(l));
111
+ if (headerIndex >= 0) out.splice(headerIndex + 1, 0, ` title ${pdoc.title}`);
112
+ }
113
+ for (const slice of doc.slices) {
114
+ if (!emitted.has(slice.id) && !slice.raw) additions.push(` ${sliceLine(slice)}`);
115
+ }
116
+ void headerEmitted;
117
+ return [...out, ...additions].join("\n");
118
+ }
119
+ function applyOp(doc, op) {
120
+ const next = structuredClone(doc);
121
+ const pop = op;
122
+ const slice = (id) => {
123
+ const s = next.slices.find((x) => x.id === id);
124
+ if (!s) throw new MermaidOpError("That slice no longer exists");
125
+ return s;
126
+ };
127
+ switch (pop.type) {
128
+ case "setTitle": {
129
+ next.title = pop.title || void 0;
130
+ if (next.headerTitle) next.dirtyHeader = true;
131
+ else next.dirtyTitle = true;
132
+ return next;
133
+ }
134
+ case "setShowData": {
135
+ next.showData = pop.enabled;
136
+ next.dirtyHeader = true;
137
+ return next;
138
+ }
139
+ case "addSlice": {
140
+ next.slices.push({
141
+ id: `p_a${next.slices.length + 1}`,
142
+ label: pop.label,
143
+ value: pop.value
144
+ });
145
+ return next;
146
+ }
147
+ case "editSlice": {
148
+ const s = slice(pop.id);
149
+ if (pop.label !== void 0) s.label = pop.label;
150
+ if (pop.value !== void 0) s.value = pop.value;
151
+ s.dirty = true;
152
+ return next;
153
+ }
154
+ case "deleteSlice": {
155
+ slice(pop.id);
156
+ next.slices = next.slices.filter((s) => s.id !== pop.id);
157
+ return next;
158
+ }
159
+ default:
160
+ throw new MermaidOpError("Unsupported operation for pie charts");
161
+ }
162
+ }
163
+ const pieAdapter = {
164
+ diagramType: "pie",
165
+ parse,
166
+ serialize,
167
+ applyOp,
168
+ vocabulary: { node: "Slice", addNode: "Add slice" }
169
+ };
170
+ export {
171
+ pieAdapter
172
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Quadrant chart adapter. Singletons (title, x-axis, y-axis, quadrant-1..4) and
3
+ * points (`Label: [x, y]`). Edits are per-line; a singleton set for the first
4
+ * time is inserted after the header; points append. Lossless by construction.
5
+ */
6
+ import type { MermaidAdapter } from "../model/adapter.js";
7
+ import type { QuadrantDoc } from "../model/types.js";
8
+ export declare const quadrantAdapter: MermaidAdapter<QuadrantDoc>;