@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,127 @@
1
+ import {
2
+ preferredFlowDirection
3
+ } from "@ai-matrx/canvas";
4
+ const CANVAS_TWO_COLUMN_WIDTH = 640;
5
+ function canvasFlow(p) {
6
+ return p ? preferredFlowDirection(p) : null;
7
+ }
8
+ function isWidePane(p) {
9
+ return preferredFlowDirection(p) === "horizontal" && !p.isNarrow && p.width >= CANVAS_TWO_COLUMN_WIDTH;
10
+ }
11
+ const DIAGRAM_READABLE_ZOOM = 0.72;
12
+ function portraitWidthFitViewport(input) {
13
+ const { presentation, bounds, width, height, minZoom, maxZoom, padding } = input;
14
+ if (!presentation || preferredFlowDirection(presentation) !== "vertical") {
15
+ return null;
16
+ }
17
+ if (!(width > 0) || !(height > 0) || !(bounds.width > 0)) return null;
18
+ const usable = width * (1 - padding * 2);
19
+ const widthZoom = Math.max(minZoom, usable / bounds.width);
20
+ const readable = input.readableZoom ?? DIAGRAM_READABLE_ZOOM;
21
+ const zoom = Math.min(maxZoom, Math.max(widthZoom, readable));
22
+ if (zoom <= input.containedZoom) return null;
23
+ const y = height * padding - bounds.y * zoom;
24
+ if (bounds.width * zoom <= usable + 0.5) {
25
+ return { zoom, x: width / 2 - (bounds.x + bounds.width / 2) * zoom, y };
26
+ }
27
+ const anchor = input.firstRank ?? bounds;
28
+ const atRoot = width * padding - anchor.x * zoom;
29
+ const rightmost = width * (1 - padding) - (bounds.x + bounds.width) * zoom;
30
+ return { zoom, x: Math.max(atRoot, rightmost), y };
31
+ }
32
+ function firstRankBounds(nodes, tolerance = 8) {
33
+ if (!nodes.length) return null;
34
+ const top = Math.min(...nodes.map((n) => n.y));
35
+ const rank = nodes.filter((n) => n.y <= top + tolerance);
36
+ const x = Math.min(...rank.map((n) => n.x));
37
+ const y = Math.min(...rank.map((n) => n.y));
38
+ const right = Math.max(...rank.map((n) => n.x + n.width));
39
+ const bottom = Math.max(...rank.map((n) => n.y + n.height));
40
+ return { x, y, width: right - x, height: bottom - y };
41
+ }
42
+ function diagramScrollPans(p) {
43
+ return p !== null && preferredFlowDirection(p) === "vertical";
44
+ }
45
+ function timelineAxis(p) {
46
+ return p && isWidePane(p) ? "horizontal" : "vertical";
47
+ }
48
+ function treeWrapsLines(p) {
49
+ return p !== null && preferredFlowDirection(p) === "vertical";
50
+ }
51
+ function decisionBranchesSideBySide(p) {
52
+ return p !== null && isWidePane(p);
53
+ }
54
+ const CHART_MIN_HEIGHT = 340;
55
+ const CHART_CHROME = 120;
56
+ function chartPaneLayout(p, chartType) {
57
+ if (!p) return null;
58
+ const vertical = preferredFlowDirection(p) === "vertical";
59
+ const narrow = vertical || p.isNarrow;
60
+ const room = Math.max(CHART_MIN_HEIGHT, p.height - CHART_CHROME);
61
+ const wanted = narrow ? p.width * 1.25 : p.width * 0.5625;
62
+ return {
63
+ height: Math.round(Math.min(room, Math.max(CHART_MIN_HEIGHT, wanted))),
64
+ legend: narrow ? "bottom" : "right",
65
+ horizontalBars: vertical && chartType === "bar"
66
+ };
67
+ }
68
+ function slideThumbnailPlacement(p) {
69
+ if (!p) return null;
70
+ return isWidePane(p) ? "side" : "below";
71
+ }
72
+ function fitScale(stage, box) {
73
+ if (!(box.width > 0) || !(stage.width > 0) || !(stage.height > 0)) return 0;
74
+ const byWidth = box.width / stage.width;
75
+ if (!(box.height > 0)) return byWidth;
76
+ return Math.min(byWidth, box.height / stage.height);
77
+ }
78
+ function diffIsSplit(input) {
79
+ if (input.personChoice !== null) return input.personChoice;
80
+ if (input.authoredExplicitly || !input.presentation) return input.authored;
81
+ return isWidePane(input.presentation);
82
+ }
83
+ function mapPlacesList(p) {
84
+ if (!p) return null;
85
+ return isWidePane(p) ? "side" : "toggle";
86
+ }
87
+ const MERMAID_FLOW_HEADER = /^(\s*)(flowchart|graph)\b([^\n]*)$/;
88
+ const MERMAID_DIRECTION = /^\s*(TB|TD|BT|RL|LR)\b/;
89
+ function mermaidSourceForFlow(source, flow) {
90
+ if (flow === null) return source;
91
+ const lines = source.split("\n");
92
+ let i = 0;
93
+ if (lines[0]?.trim() === "---") {
94
+ const end = lines.findIndex((l, idx) => idx > 0 && l.trim() === "---");
95
+ if (end === -1) return source;
96
+ i = end + 1;
97
+ }
98
+ while (i < lines.length && (lines[i].trim() === "" || lines[i].trim().startsWith("%%"))) {
99
+ i++;
100
+ }
101
+ const header = lines[i];
102
+ if (header === void 0) return source;
103
+ const match = header.match(MERMAID_FLOW_HEADER);
104
+ if (!match) return source;
105
+ const rest = match[3];
106
+ if (MERMAID_DIRECTION.test(rest)) return source;
107
+ const direction = flow === "vertical" ? "TB" : "LR";
108
+ lines[i] = `${match[1]}${match[2]} ${direction}${rest}`;
109
+ return lines.join("\n");
110
+ }
111
+ export {
112
+ CANVAS_TWO_COLUMN_WIDTH,
113
+ DIAGRAM_READABLE_ZOOM,
114
+ canvasFlow,
115
+ chartPaneLayout,
116
+ decisionBranchesSideBySide,
117
+ diagramScrollPans,
118
+ diffIsSplit,
119
+ firstRankBounds,
120
+ fitScale,
121
+ mapPlacesList,
122
+ mermaidSourceForFlow,
123
+ portraitWidthFitViewport,
124
+ slideThumbnailPlacement,
125
+ timelineAxis,
126
+ treeWrapsLines
127
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * How much room a block has when it is shown in the canvas.
3
+ *
4
+ * `@ai-matrx/canvas` tells content it is in a canvas pane through
5
+ * `useCanvasPresentation()` (null everywhere else). Blocks that render in both
6
+ * the chat and the canvas read this ONE answer so a tall, narrow pane gets a
7
+ * layout built for it — stacked cards, one column, side panels above the body —
8
+ * while the chat and every other host keep exactly the layout they had.
9
+ *
10
+ * outside — not in the canvas; the block renders as it always did.
11
+ * narrow — the pane is under CANVAS_NARROW_WIDTH (480px): restructure.
12
+ * tight — wider than narrow but not roomy (< 768px) and not full screen:
13
+ * keep the structure, ease the squeeze (e.g. pin a table's first column).
14
+ * wide — roomy, or the pane is full screen: the normal layout.
15
+ *
16
+ * A person's explicit choice always wins over this hint (see the diagram
17
+ * reference adopter, `diagram/presentation-direction.ts`).
18
+ */
19
+ import type { CanvasPresentation } from "@ai-matrx/canvas";
20
+ export type CanvasFit = "outside" | "narrow" | "tight" | "wide";
21
+ /** Below this a not-full-screen pane is "tight" (between narrow and roomy). */
22
+ export declare const CANVAS_TIGHT_WIDTH = 768;
23
+ export declare function canvasFitFor(presentation: CanvasPresentation | null | undefined): CanvasFit;
24
+ export declare function useCanvasFit(): CanvasFit;
@@ -0,0 +1,19 @@
1
+ import { useCanvasPresentation } from "@ai-matrx/canvas/react";
2
+ const CANVAS_TIGHT_WIDTH = 768;
3
+ function canvasFitFor(presentation) {
4
+ if (!presentation) return "outside";
5
+ if (presentation.isNarrow) return "narrow";
6
+ if (presentation.isFullscreen) return "wide";
7
+ if (presentation.width > 0 && presentation.width < CANVAS_TIGHT_WIDTH) {
8
+ return "tight";
9
+ }
10
+ return "wide";
11
+ }
12
+ function useCanvasFit() {
13
+ return canvasFitFor(useCanvasPresentation());
14
+ }
15
+ export {
16
+ CANVAS_TIGHT_WIDTH,
17
+ canvasFitFor,
18
+ useCanvasFit
19
+ };
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ export interface ChartBlockProps {
3
+ content?: string;
4
+ isStreamActive?: boolean;
5
+ className?: string;
6
+ }
7
+ export declare const ChartBlock: React.FC<ChartBlockProps>;
8
+ export default ChartBlock;
@@ -0,0 +1,125 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useClipboard } from "@ai-matrx/kit/clipboard";
4
+ import { useEffect, useMemo, useState } from "react";
5
+ import { clientLazy } from "../../../utils/client-lazy.js";
6
+ import { createPortal } from "react-dom";
7
+ import { BarChart3, Check, Copy, Expand, TriangleAlert, X } from "lucide-react";
8
+ import { toast } from "../../../host/toast.js";
9
+ import { Skeleton } from "@ai-matrx/design-system";
10
+ import { cn } from "@ai-matrx/design-system";
11
+ import { parseChartSpec } from "./chart-spec.js";
12
+ import { useCanvasPresentation } from "@ai-matrx/canvas/react";
13
+ import { chartPaneLayout } from "../canvas-adaptive.js";
14
+ import { Button } from "@ai-matrx/design-system/controls";
15
+ const CHART_TYPE_LABEL = {
16
+ bar: "Bar chart",
17
+ line: "Line chart",
18
+ area: "Area chart",
19
+ pie: "Pie chart",
20
+ scatter: "Scatter chart"
21
+ };
22
+ const ChartCanvas = clientLazy(() => import("./ChartCanvas.js"), {
23
+ loading: () => /* @__PURE__ */ jsx(Skeleton, { className: "h-full w-full" })
24
+ });
25
+ const ChartBlock = ({ content = "", isStreamActive = false, className }) => {
26
+ const { copyText } = useClipboard({
27
+ notify: (message, kind) => kind === "error" ? toast.error(message) : toast.success(message)
28
+ });
29
+ const source = content.trim();
30
+ const parsed = useMemo(() => isStreamActive ? null : parseChartSpec(source), [source, isStreamActive]);
31
+ const spec = parsed && !("error" in parsed) ? parsed : null;
32
+ const error = parsed && "error" in parsed ? parsed.error : null;
33
+ const [copied, setCopied] = useState(false);
34
+ const [fullscreen, setFullscreen] = useState(false);
35
+ const [showSource, setShowSource] = useState(false);
36
+ const title = spec?.title ?? (spec ? CHART_TYPE_LABEL[spec.type] ?? "Chart" : "Chart");
37
+ const presentation = useCanvasPresentation();
38
+ const paneLayout = chartPaneLayout(presentation, spec?.type ?? "");
39
+ const handleCopy = async () => {
40
+ try {
41
+ await copyText(source);
42
+ setCopied(true);
43
+ setTimeout(() => setCopied(false), 1500);
44
+ } catch {
45
+ toast.error("Couldn't copy the chart source");
46
+ }
47
+ };
48
+ return /* @__PURE__ */ jsxs("div", { className: cn("my-3 overflow-hidden rounded-lg border border-border bg-card", className), children: [
49
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 border-b border-border bg-muted/50 px-3 py-1.5", children: [
50
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [
51
+ /* @__PURE__ */ jsx(BarChart3, { className: "h-3.5 w-3.5 shrink-0 text-primary" }),
52
+ /* @__PURE__ */ jsx("span", { className: "truncate text-sm font-medium text-foreground", children: title }),
53
+ spec && /* @__PURE__ */ jsx("span", { className: "hidden shrink-0 text-xs text-muted-foreground sm:inline", children: CHART_TYPE_LABEL[spec.type] ?? "Chart" }),
54
+ isStreamActive && /* @__PURE__ */ jsx("span", { className: "shrink-0 animate-pulse text-xs text-muted-foreground", children: "building\u2026" })
55
+ ] }),
56
+ !isStreamActive && /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-0.5", children: [
57
+ /* @__PURE__ */ jsx(IconBtn, { label: copied ? "Copied" : "Copy chart source", onClick: handleCopy, children: copied ? /* @__PURE__ */ jsx(Check, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ jsx(Copy, { className: "h-3.5 w-3.5" }) }),
58
+ spec && presentation === null && /* @__PURE__ */ jsx(IconBtn, { label: "View fullscreen", onClick: () => setFullscreen(true), children: /* @__PURE__ */ jsx(Expand, { className: "h-3.5 w-3.5" }) })
59
+ ] })
60
+ ] }),
61
+ /* @__PURE__ */ jsx("div", { className: "p-3", children: isStreamActive ? /* @__PURE__ */ jsxs("div", { className: "space-y-2", "aria-busy": "true", children: [
62
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-1/3" }),
63
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-48 w-full" })
64
+ ] }) : error ? /* @__PURE__ */ jsx(ChartError, { error, source, show: showSource, onToggle: () => setShowSource((v) => !v) }) : spec ? /* @__PURE__ */ jsx(
65
+ "div",
66
+ {
67
+ className: paneLayout ? "w-full" : "h-[340px] w-full",
68
+ style: paneLayout ? { height: paneLayout.height } : void 0,
69
+ "data-chart-legend": paneLayout?.legend ?? "default",
70
+ "data-chart-bars": paneLayout?.horizontalBars ? "horizontal" : "vertical",
71
+ children: /* @__PURE__ */ jsx(ChartCanvas, { spec, paneLayout })
72
+ }
73
+ ) : null }),
74
+ fullscreen && spec && /* @__PURE__ */ jsx(ChartFullscreen, { spec, title, onClose: () => setFullscreen(false) })
75
+ ] });
76
+ };
77
+ function IconBtn({ label, onClick, children }) {
78
+ return /* @__PURE__ */ jsx(Button, { variant: "quiet", "aria-label": label, title: label, onClick, children });
79
+ }
80
+ function ChartError({
81
+ error,
82
+ source,
83
+ show,
84
+ onToggle
85
+ }) {
86
+ return /* @__PURE__ */ jsx("div", { className: "rounded-md border border-destructive/30 bg-destructive/5 p-3 text-sm", children: /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
87
+ /* @__PURE__ */ jsx(TriangleAlert, { className: "mt-0.5 h-4 w-4 shrink-0 text-destructive" }),
88
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1 space-y-1.5", children: [
89
+ /* @__PURE__ */ jsx("p", { className: "font-medium text-foreground", children: "This chart could not be drawn" }),
90
+ /* @__PURE__ */ jsx("p", { className: "break-words text-xs text-muted-foreground", children: error }),
91
+ /* @__PURE__ */ jsx(Button, { variant: "link", onClick: onToggle, children: show ? "Hide source" : "Show source" }),
92
+ show && /* @__PURE__ */ jsx("pre", { className: "mt-1 max-h-64 overflow-auto rounded bg-muted p-2 text-xs text-muted-foreground", children: source })
93
+ ] })
94
+ ] }) });
95
+ }
96
+ function ChartFullscreen({ spec, title, onClose }) {
97
+ useEffect(() => {
98
+ const onKey = (e) => {
99
+ if (e.key === "Escape") onClose();
100
+ };
101
+ window.addEventListener("keydown", onKey);
102
+ const prev = document.body.style.overflow;
103
+ document.body.style.overflow = "hidden";
104
+ return () => {
105
+ window.removeEventListener("keydown", onKey);
106
+ document.body.style.overflow = prev;
107
+ };
108
+ }, [onClose]);
109
+ if (typeof document === "undefined") return null;
110
+ return createPortal(
111
+ /* @__PURE__ */ jsxs("div", { className: "fixed inset-0 z-[120] flex flex-col bg-background/98 backdrop-blur-sm", role: "dialog", "aria-modal": "true", "aria-label": title, children: [
112
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b border-border px-4 py-2 pt-safe", children: [
113
+ /* @__PURE__ */ jsx("span", { className: "truncate text-sm font-medium text-foreground", children: title }),
114
+ /* @__PURE__ */ jsx(Button, { variant: "quiet", icon: /* @__PURE__ */ jsx(X, {}), "aria-label": "Exit fullscreen", title: "Exit fullscreen (Esc)", onClick: onClose })
115
+ ] }),
116
+ /* @__PURE__ */ jsx("div", { className: "min-h-0 flex-1 p-6", children: /* @__PURE__ */ jsx(ChartCanvas, { spec }) })
117
+ ] }),
118
+ document.body
119
+ );
120
+ }
121
+ var ChartBlock_default = ChartBlock;
122
+ export {
123
+ ChartBlock,
124
+ ChartBlock_default as default
125
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * ChartCanvas — the recharts renderer for a normalized ChartSpec.
3
+ *
4
+ * IMPORTANT (bundle policy): recharts is heavy. This module is the ONLY place
5
+ * that imports it, and it is loaded EXCLUSIVELY through
6
+ * `next/dynamic(() => import("./ChartCanvas.js"), { ssr: false })` from ChartBlock,
7
+ * rendered conditionally (only once a valid spec exists). So recharts never
8
+ * enters the server build or the initial client bundle — it loads on demand,
9
+ * client-side, the first time a chart actually renders.
10
+ */
11
+ import React from "react";
12
+ import { type ChartSpec } from "./chart-spec.js";
13
+ import type { ChartPaneLayout } from "../canvas-adaptive.js";
14
+ export default function ChartCanvas({ spec, paneLayout, }: {
15
+ spec: ChartSpec;
16
+ /** The canvas pane's layout; `null` (chat, fullscreen) keeps the defaults. */
17
+ paneLayout?: ChartPaneLayout | null;
18
+ }): React.JSX.Element;
@@ -0,0 +1,159 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import {
4
+ Area,
5
+ AreaChart,
6
+ Bar,
7
+ BarChart,
8
+ CartesianGrid,
9
+ Cell,
10
+ Legend,
11
+ Line,
12
+ LineChart,
13
+ Pie,
14
+ PieChart,
15
+ ResponsiveContainer,
16
+ Scatter,
17
+ ScatterChart,
18
+ Tooltip,
19
+ XAxis,
20
+ YAxis,
21
+ ZAxis
22
+ } from "recharts";
23
+ import { CHART_PALETTE } from "./chart-spec.js";
24
+ import { pieSliceLabel } from "./labels.js";
25
+ const AXIS = { fontSize: 12, stroke: "var(--muted-foreground)" };
26
+ const GRID_STROKE = "var(--border)";
27
+ function ChartCanvas({
28
+ spec,
29
+ paneLayout = null
30
+ }) {
31
+ const showLegend = spec.series.length > 1 || spec.type === "pie";
32
+ return /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height: "100%", children: render(spec, showLegend, paneLayout) });
33
+ }
34
+ function legendFor(paneLayout) {
35
+ if (paneLayout?.legend === "right") {
36
+ return /* @__PURE__ */ jsx(Legend, { wrapperStyle: { fontSize: 12 }, layout: "vertical", verticalAlign: "middle", align: "right" });
37
+ }
38
+ if (paneLayout?.legend === "bottom") {
39
+ return /* @__PURE__ */ jsx(Legend, { wrapperStyle: { fontSize: 12 }, layout: "horizontal", verticalAlign: "bottom", align: "center" });
40
+ }
41
+ return /* @__PURE__ */ jsx(Legend, { wrapperStyle: { fontSize: 12 } });
42
+ }
43
+ function render(spec, showLegend, paneLayout) {
44
+ const common = { data: spec.data, margin: { top: 8, right: 16, bottom: 8, left: 0 } };
45
+ const axes = /* @__PURE__ */ jsxs(Fragment, { children: [
46
+ /* @__PURE__ */ jsx(CartesianGrid, { strokeDasharray: "3 3", stroke: GRID_STROKE, vertical: false }),
47
+ /* @__PURE__ */ jsx(XAxis, { dataKey: spec.xKey, type: spec.type === "scatter" ? "number" : "category", domain: spec.type === "scatter" ? ["auto", "auto"] : void 0, name: spec.xKey, tick: AXIS, tickLine: false, axisLine: { stroke: GRID_STROKE } }),
48
+ /* @__PURE__ */ jsx(YAxis, { tick: AXIS, tickLine: false, axisLine: false, width: 44 }),
49
+ /* @__PURE__ */ jsx(
50
+ Tooltip,
51
+ {
52
+ contentStyle: {
53
+ background: "var(--popover)",
54
+ border: "1px solid var(--border)",
55
+ borderRadius: 8,
56
+ fontSize: 12,
57
+ color: "var(--popover-foreground)"
58
+ }
59
+ }
60
+ ),
61
+ showLegend && legendFor(paneLayout)
62
+ ] });
63
+ switch (spec.type) {
64
+ case "line":
65
+ return /* @__PURE__ */ jsxs(LineChart, { ...common, children: [
66
+ axes,
67
+ spec.series.map((s) => /* @__PURE__ */ jsx(Line, { type: "monotone", dataKey: s.key, name: s.label, stroke: s.color, strokeWidth: 2, dot: false }, s.key))
68
+ ] });
69
+ case "area":
70
+ return /* @__PURE__ */ jsxs(AreaChart, { ...common, children: [
71
+ axes,
72
+ spec.series.map((s) => /* @__PURE__ */ jsx(
73
+ Area,
74
+ {
75
+ type: "monotone",
76
+ dataKey: s.key,
77
+ name: s.label,
78
+ stroke: s.color,
79
+ fill: s.color,
80
+ fillOpacity: 0.18,
81
+ strokeWidth: 2,
82
+ stackId: spec.stacked ? "1" : void 0
83
+ },
84
+ s.key
85
+ ))
86
+ ] });
87
+ case "scatter":
88
+ return /* @__PURE__ */ jsxs(ScatterChart, { ...common, children: [
89
+ axes,
90
+ /* @__PURE__ */ jsx(ZAxis, { range: [60, 60] }),
91
+ spec.series.map((s) => /* @__PURE__ */ jsx(Scatter, { dataKey: s.key, name: s.label, fill: s.color }, s.key))
92
+ ] });
93
+ case "pie": {
94
+ const valueKey = spec.pie?.valueKey ?? "value";
95
+ const labelKey = spec.pie?.labelKey ?? "label";
96
+ return /* @__PURE__ */ jsxs(PieChart, { children: [
97
+ /* @__PURE__ */ jsx(
98
+ Tooltip,
99
+ {
100
+ contentStyle: {
101
+ background: "var(--popover)",
102
+ border: "1px solid var(--border)",
103
+ borderRadius: 8,
104
+ fontSize: 12,
105
+ color: "var(--popover-foreground)"
106
+ }
107
+ }
108
+ ),
109
+ showLegend && legendFor(paneLayout),
110
+ /* @__PURE__ */ jsx(
111
+ Pie,
112
+ {
113
+ data: spec.data,
114
+ dataKey: valueKey,
115
+ nameKey: labelKey,
116
+ cx: "50%",
117
+ cy: "50%",
118
+ outerRadius: "78%",
119
+ innerRadius: "0%",
120
+ paddingAngle: 1,
121
+ label: (e) => pieSliceLabel(e),
122
+ labelLine: false,
123
+ children: spec.data.map((_, i) => /* @__PURE__ */ jsx(Cell, { fill: CHART_PALETTE[i % CHART_PALETTE.length] }, i))
124
+ }
125
+ )
126
+ ] });
127
+ }
128
+ case "bar":
129
+ default:
130
+ if (paneLayout?.horizontalBars) {
131
+ return /* @__PURE__ */ jsxs(BarChart, { ...common, layout: "vertical", margin: { top: 8, right: 16, bottom: 8, left: 8 }, children: [
132
+ /* @__PURE__ */ jsx(CartesianGrid, { strokeDasharray: "3 3", stroke: GRID_STROKE, horizontal: false }),
133
+ /* @__PURE__ */ jsx(XAxis, { type: "number", tick: AXIS, tickLine: false, axisLine: { stroke: GRID_STROKE } }),
134
+ /* @__PURE__ */ jsx(YAxis, { type: "category", dataKey: spec.xKey, tick: AXIS, tickLine: false, axisLine: false, width: 96 }),
135
+ /* @__PURE__ */ jsx(
136
+ Tooltip,
137
+ {
138
+ contentStyle: {
139
+ background: "var(--popover)",
140
+ border: "1px solid var(--border)",
141
+ borderRadius: 8,
142
+ fontSize: 12,
143
+ color: "var(--popover-foreground)"
144
+ }
145
+ }
146
+ ),
147
+ showLegend && legendFor(paneLayout),
148
+ spec.series.map((s) => /* @__PURE__ */ jsx(Bar, { dataKey: s.key, name: s.label, fill: s.color, radius: [0, 3, 3, 0], stackId: spec.stacked ? "1" : void 0 }, s.key))
149
+ ] });
150
+ }
151
+ return /* @__PURE__ */ jsxs(BarChart, { ...common, children: [
152
+ axes,
153
+ spec.series.map((s) => /* @__PURE__ */ jsx(Bar, { dataKey: s.key, name: s.label, fill: s.color, radius: [3, 3, 0, 0], stackId: spec.stacked ? "1" : void 0 }, s.key))
154
+ ] });
155
+ }
156
+ }
157
+ export {
158
+ ChartCanvas as default
159
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * TableChart — "Chart this" for any table an answer shows (markdown table,
3
+ * CSV/TSV block). Draws through the ONE chart primitive: `tableToChartSpec`
4
+ * builds the same ChartSpec a ```chart fence parses to, and ChartCanvas (the
5
+ * only recharts importer, loaded via next/dynamic ssr:false) draws it.
6
+ *
7
+ * `ChartThisButton` is ABSENT for a table with no numbers — never a dead
8
+ * button. The panel auto-picks bar/line/pie/scatter and lets the reader switch
9
+ * to any type the data can honestly draw.
10
+ */
11
+ import React from "react";
12
+ import { type PlainTable } from "./table-chart.js";
13
+ export declare function isChartable(table: PlainTable): boolean;
14
+ export declare function ChartThisButton({ table, active, onToggle, className, }: {
15
+ table: PlainTable;
16
+ active: boolean;
17
+ onToggle: () => void;
18
+ className?: string;
19
+ }): React.JSX.Element | null;
20
+ export declare function TableChartPanel({ table, title, onClose, className, }: {
21
+ table: PlainTable;
22
+ title?: string;
23
+ onClose?: () => void;
24
+ className?: string;
25
+ }): React.JSX.Element | null;
@@ -0,0 +1,97 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useState } from "react";
4
+ import { clientLazy } from "../../../utils/client-lazy.js";
5
+ import {
6
+ AreaChart as AreaIcon,
7
+ BarChart3,
8
+ ChartScatter,
9
+ LineChart as LineIcon,
10
+ PieChart as PieIcon,
11
+ X
12
+ } from "lucide-react";
13
+ import { Skeleton } from "@ai-matrx/design-system";
14
+ import { Button, ControlRow, SegmentedControl } from "@ai-matrx/design-system/controls";
15
+ import { cn } from "@ai-matrx/design-system";
16
+ import { chartNotice, chartableTypes, tableToChartSpec } from "./table-chart.js";
17
+ const ChartCanvas = clientLazy(() => import("./ChartCanvas.js"), {
18
+ loading: () => /* @__PURE__ */ jsx(Skeleton, { className: "h-full w-full" })
19
+ });
20
+ const TYPE_META = {
21
+ bar: { label: "Bar", Icon: BarChart3 },
22
+ line: { label: "Line", Icon: LineIcon },
23
+ area: { label: "Area", Icon: AreaIcon },
24
+ pie: { label: "Pie", Icon: PieIcon },
25
+ scatter: { label: "Scatter", Icon: ChartScatter }
26
+ };
27
+ function isChartable(table) {
28
+ return chartableTypes(table).length > 0;
29
+ }
30
+ function ChartThisButton({
31
+ table,
32
+ active,
33
+ onToggle,
34
+ className
35
+ }) {
36
+ if (!isChartable(table)) return null;
37
+ return /* @__PURE__ */ jsx(
38
+ Button,
39
+ {
40
+ variant: "outline",
41
+ tone: active ? "primary" : void 0,
42
+ icon: /* @__PURE__ */ jsx(BarChart3, {}),
43
+ onClick: onToggle,
44
+ "aria-pressed": active,
45
+ "aria-label": active ? "Hide chart" : "Chart this table",
46
+ className,
47
+ children: active ? "Hide chart" : "Chart this"
48
+ }
49
+ );
50
+ }
51
+ function TableChartPanel({
52
+ table,
53
+ title,
54
+ onClose,
55
+ className
56
+ }) {
57
+ const types = chartableTypes(table);
58
+ const [picked, setPicked] = useState(void 0);
59
+ const spec = tableToChartSpec(table, picked);
60
+ if (!spec) return null;
61
+ const notice = chartNotice(table, picked);
62
+ const heading = title ?? `${TYPE_META[spec.type].label} chart`;
63
+ return /* @__PURE__ */ jsxs(
64
+ "div",
65
+ {
66
+ className: cn("my-2 overflow-hidden rounded-lg border border-border bg-card", className),
67
+ "data-find-ignore": "",
68
+ children: [
69
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-2 border-b border-border bg-muted/50 px-2 py-1", children: [
70
+ /* @__PURE__ */ jsx("span", { className: "truncate pl-1 text-sm font-medium text-foreground", children: heading }),
71
+ /* @__PURE__ */ jsxs(ControlRow, { nowrap: true, children: [
72
+ /* @__PURE__ */ jsx(
73
+ SegmentedControl,
74
+ {
75
+ "aria-label": "Chart type",
76
+ value: picked ?? spec.type,
77
+ onValueChange: setPicked,
78
+ data: types.map((t) => {
79
+ const { Icon, label } = TYPE_META[t];
80
+ return { value: t, label: /* @__PURE__ */ jsx(Icon, {}), ariaLabel: `${label} chart`, title: `${label} chart` };
81
+ })
82
+ }
83
+ ),
84
+ onClose && /* @__PURE__ */ jsx(Button, { variant: "quiet", icon: /* @__PURE__ */ jsx(X, {}), "aria-label": "Close chart", title: "Close chart", onClick: onClose })
85
+ ] })
86
+ ] }),
87
+ notice && /* @__PURE__ */ jsx("p", { className: "border-b border-border px-3 py-1.5 text-xs text-muted-foreground", role: "status", children: notice }),
88
+ /* @__PURE__ */ jsx("div", { className: "h-[300px] w-full p-2", children: /* @__PURE__ */ jsx(ChartCanvas, { spec }) })
89
+ ]
90
+ }
91
+ );
92
+ }
93
+ export {
94
+ ChartThisButton,
95
+ TableChartPanel,
96
+ isChartable
97
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Chart spec — the forgiving normalizer between an agent's ```chart JSON and
3
+ * the recharts renderer. PURE (no recharts import) so it stays out of any heavy
4
+ * bundle and is unit-testable. The renderer (ChartCanvas) is loaded separately
5
+ * via next/dynamic ssr:false.
6
+ *
7
+ * Agent-facing shape (all keys tolerant):
8
+ * { "type": "bar", "title": "...", "x": "month", "y": ["revenue","profit"],
9
+ * "data": [ { "month": "Jan", "revenue": 100, "profit": 20 }, ... ] }
10
+ * { "type": "pie", "data": [ { "label": "A", "value": 45 }, ... ] }
11
+ */
12
+ export type ChartType = "bar" | "line" | "area" | "pie" | "scatter";
13
+ export interface ChartSeries {
14
+ key: string;
15
+ label: string;
16
+ color: string;
17
+ }
18
+ export interface ChartSpec {
19
+ type: ChartType;
20
+ title?: string;
21
+ /** Category field name (cartesian charts). */
22
+ xKey: string;
23
+ /** Numeric series (cartesian charts). */
24
+ series: ChartSeries[];
25
+ /** Normalized rows. */
26
+ data: Record<string, unknown>[];
27
+ /** Pie field mapping. */
28
+ pie?: {
29
+ labelKey: string;
30
+ valueKey: string;
31
+ };
32
+ stacked: boolean;
33
+ }
34
+ export interface ChartParseError {
35
+ error: string;
36
+ }
37
+ /** Readable categorical palette (hex; good light/dark contrast). */
38
+ export declare const CHART_PALETTE: string[];
39
+ export declare function parseChartSpec(raw: string): ChartSpec | ChartParseError;