agentic-mermaid 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (333) hide show
  1. package/CHANGELOG.md +149 -4
  2. package/LICENSES/Apache-2.0.txt +202 -0
  3. package/README.md +25 -32
  4. package/THIRD_PARTY_NOTICES.md +29 -0
  5. package/assets/fonts/FONT-LICENSES.md +9 -5
  6. package/assets/fonts/Inter-Bold.ttf +0 -0
  7. package/assets/fonts/Inter-Medium.ttf +0 -0
  8. package/assets/fonts/Inter-Regular.ttf +0 -0
  9. package/assets/fonts/Inter-SemiBold.ttf +0 -0
  10. package/dist/agent-core.d.ts +463 -0
  11. package/dist/agent-core.js +397 -0
  12. package/dist/agent.d.ts +81 -1822
  13. package/dist/agent.js +336 -36839
  14. package/dist/agentic-mermaid-mcp.js +7 -37908
  15. package/dist/am.js +33638 -36261
  16. package/dist/chunk-4QECACIA.js +4702 -0
  17. package/dist/chunk-CDPKJ2BQ.js +37 -0
  18. package/dist/chunk-QKDLMOJJ.js +3487 -0
  19. package/dist/chunk-WI35L7IR.js +615 -0
  20. package/dist/chunk-WN3YDOBG.js +149 -0
  21. package/dist/chunk-ZYMMKQ3I.js +62637 -0
  22. package/dist/index-D54dqSdC.d.ts +6777 -0
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +310 -32836
  25. package/dist/mcp-cli-SBQSTJFC.js +17 -0
  26. package/docs/README.md +14 -6
  27. package/docs/schemas/style-spec.schema.json +1221 -30
  28. package/examples/styles/catalog.json +54 -0
  29. package/examples/styles/cloudflare-workers-inspired-prototype.mmd +9 -0
  30. package/examples/styles/cloudflare-workers-inspired-prototype.style.json +110 -0
  31. package/examples/styles/cupertino-prototype.mmd +10 -0
  32. package/examples/styles/cupertino-prototype.style.json +63 -0
  33. package/examples/styles/mid-century-report.style.json +2 -2
  34. package/examples/styles/star-chart-atlas.style.json +2 -1
  35. package/examples/styles/transit-route-map.style.json +2 -2
  36. package/examples/styles/vercel-inspired-prototype.mmd +6 -0
  37. package/examples/styles/vercel-inspired-prototype.style.json +87 -0
  38. package/package.json +70 -43
  39. package/server.json +41 -0
  40. package/skills/agentic-mermaid-diagram-workflow/SKILL.md +17 -36
  41. package/skills/agentic-mermaid-diagram-workflow/references/cli.md +4 -5
  42. package/skills/agentic-mermaid-diagram-workflow/references/code-mode.md +15 -31
  43. package/skills/agentic-mermaid-diagram-workflow/references/sequence.md +10 -14
  44. package/skills/agentic-mermaid-live-editor/SKILL.md +100 -206
  45. package/AGENT_NATIVE.md +0 -602
  46. package/Instructions_for_agents.md +0 -83
  47. package/TODO.md +0 -662
  48. package/assets/hero.png +0 -0
  49. package/dist/index-x2Cj1dVv.d.ts +0 -1089
  50. package/docs/agent-api-cookbook.md +0 -308
  51. package/docs/agent-mutation-policy.md +0 -104
  52. package/docs/agent-workflow-examples.md +0 -46
  53. package/docs/api.md +0 -203
  54. package/docs/ascii.md +0 -103
  55. package/docs/assets/improvements/box-start-connector.png +0 -0
  56. package/docs/assets/improvements/comment-dropped-lint.png +0 -0
  57. package/docs/assets/improvements/er-content-loss.png +0 -0
  58. package/docs/assets/improvements/fan-in-trunks.png +0 -0
  59. package/docs/assets/improvements/gantt-family.png +0 -0
  60. package/docs/assets/improvements/gantt-milestone-clamp.png +0 -0
  61. package/docs/assets/improvements/gantt-verify-seam.png +0 -0
  62. package/docs/assets/improvements/subgraph-container-edges.png +0 -0
  63. package/docs/assets/improvements/wrapper-frontmatter.png +0 -0
  64. package/docs/assets/improvements/wrapper-init-directive.png +0 -0
  65. package/docs/assets/improvements/wrapper-leading-comment.png +0 -0
  66. package/docs/assets/style-cookbook/mid-century-report.png +0 -0
  67. package/docs/assets/style-cookbook/star-chart-atlas.png +0 -0
  68. package/docs/assets/style-cookbook/transit-route-map.png +0 -0
  69. package/docs/comparison.md +0 -94
  70. package/docs/config.md +0 -105
  71. package/docs/contributing/adding-diagram-types.md +0 -144
  72. package/docs/contributing/diagram-family-citizenship.matrix.json +0 -2127
  73. package/docs/contributing/diagram-family-citizenship.md +0 -82
  74. package/docs/contributing/harvesting-upstream-tests.md +0 -126
  75. package/docs/contributing/lessons-learned.md +0 -276
  76. package/docs/contributing/releasing.md +0 -71
  77. package/docs/contributing/visual-review-evidence.md +0 -53
  78. package/docs/custom-style-cookbook.md +0 -154
  79. package/docs/design/families/README.md +0 -26
  80. package/docs/design/families/architecture-beta.md +0 -48
  81. package/docs/design/families/flowchart-parser-conformance.md +0 -22
  82. package/docs/design/families/gantt-research.md +0 -137
  83. package/docs/design/families/gantt.md +0 -329
  84. package/docs/design/families/journey-agentic-cards-before.png +0 -0
  85. package/docs/design/families/journey-mermaid-classic-implementation.png +0 -0
  86. package/docs/design/families/journey-mermaid-classic-prototype.png +0 -0
  87. package/docs/design/families/journey-mermaid-classic-prototype.svg +0 -163
  88. package/docs/design/families/journey-mermaid-classic-prototype.svg.png +0 -0
  89. package/docs/design/families/journey-migration-parity.md +0 -433
  90. package/docs/design/families/journey-usage-research.md +0 -423
  91. package/docs/design/families/journey.md +0 -125
  92. package/docs/design/families/xychart.md +0 -85
  93. package/docs/design/system/README.md +0 -45
  94. package/docs/design/system/abstraction-audit.md +0 -224
  95. package/docs/design/system/abstraction-recommendations.md +0 -655
  96. package/docs/design/system/architecture.mmd +0 -29
  97. package/docs/design/system/architecture.svg +0 -137
  98. package/docs/design/system/layout-guarantees-and-robustness.md +0 -351
  99. package/docs/design/system/layout-rubric.md +0 -138
  100. package/docs/design/system/route-contracts.md +0 -848
  101. package/docs/design/system/source-preservation-ladder.md +0 -52
  102. package/docs/design/system/styles-rollout.md +0 -216
  103. package/docs/design/system/ugly-layouts.md +0 -119
  104. package/docs/diagram-families.md +0 -193
  105. package/docs/features.md +0 -147
  106. package/docs/fork-differences.md +0 -130
  107. package/docs/getting-started.md +0 -175
  108. package/docs/issue-derived-test-cases.md +0 -156
  109. package/docs/layout-characterization/README.md +0 -245
  110. package/docs/layout-characterization/contact-sheet-families.md +0 -496
  111. package/docs/layout-characterization/contact-sheet.md +0 -638
  112. package/docs/layout-characterization/properties.md +0 -281
  113. package/docs/layout-characterization/visual-quality.md +0 -160
  114. package/docs/layout-characterization/visual-snapshots/architecture.svg +0 -79
  115. package/docs/layout-characterization/visual-snapshots/class.svg +0 -60
  116. package/docs/layout-characterization/visual-snapshots/er.svg +0 -61
  117. package/docs/layout-characterization/visual-snapshots/flowchart.svg +0 -58
  118. package/docs/layout-characterization/visual-snapshots/gantt.svg +0 -52
  119. package/docs/layout-characterization/visual-snapshots/journey.svg +0 -118
  120. package/docs/layout-characterization/visual-snapshots/pie.svg +0 -36
  121. package/docs/layout-characterization/visual-snapshots/quadrant.svg +0 -47
  122. package/docs/layout-characterization/visual-snapshots/sequence.svg +0 -59
  123. package/docs/layout-characterization/visual-snapshots/state.svg +0 -52
  124. package/docs/layout-characterization/visual-snapshots/timeline.svg +0 -64
  125. package/docs/layout-characterization/visual-snapshots/xychart.svg +0 -97
  126. package/docs/mcp-code-mode-rationale.md +0 -101
  127. package/docs/mcp-http-transport.md +0 -223
  128. package/docs/mermaid-layout-complaints.md +0 -837
  129. package/docs/mutation-testing.md +0 -206
  130. package/docs/project/divergences.md +0 -98
  131. package/docs/project/dogfooding-docs-strategy.md +0 -66
  132. package/docs/project/hosted-mcp-cloudflare-plan.md +0 -338
  133. package/docs/project/lessons-learned.md +0 -1019
  134. package/docs/project/remove-role-styling-plan.md +0 -176
  135. package/docs/quality.md +0 -212
  136. package/docs/react.md +0 -97
  137. package/docs/style-authoring.md +0 -133
  138. package/docs/testing-strategy.md +0 -335
  139. package/docs/theming.md +0 -162
  140. package/examples/agent-improve-auth-flow.ts +0 -206
  141. package/examples/agent-loop.ts +0 -53
  142. package/examples/mcp-vs-cli-complex-diagrams.ts +0 -133
  143. package/llms.txt +0 -104
  144. package/skill-evals/README.md +0 -77
  145. package/skill-evals/fixtures/architecture-cache/input.mmd +0 -5
  146. package/skill-evals/fixtures/class-payment/input.mmd +0 -4
  147. package/skill-evals/fixtures/er-orders/input.mmd +0 -10
  148. package/skill-evals/fixtures/flowchart-cache/input.mmd +0 -3
  149. package/skill-evals/fixtures/gantt-release/input.mmd +0 -7
  150. package/skill-evals/fixtures/journey-checkout/input.mmd +0 -6
  151. package/skill-evals/fixtures/pie-exports/input.mmd +0 -5
  152. package/skill-evals/fixtures/quadrant-priorities/input.mmd +0 -11
  153. package/skill-evals/fixtures/sequence-retry/input.mmd +0 -8
  154. package/skill-evals/fixtures/state-lifecycle/input.mmd +0 -5
  155. package/skill-evals/fixtures/timeline-release/input.mmd +0 -6
  156. package/skill-evals/fixtures/xychart-growth/input.mmd +0 -5
  157. package/skill-evals/shared-benchmark.json +0 -510
  158. package/src/agent/analyze.ts +0 -157
  159. package/src/agent/apply.ts +0 -146
  160. package/src/agent/architecture-body.ts +0 -458
  161. package/src/agent/certificates.ts +0 -110
  162. package/src/agent/class-body.ts +0 -319
  163. package/src/agent/core.ts +0 -207
  164. package/src/agent/create.ts +0 -106
  165. package/src/agent/describe.ts +0 -364
  166. package/src/agent/er-body.ts +0 -224
  167. package/src/agent/facts.ts +0 -337
  168. package/src/agent/families-builtin.ts +0 -934
  169. package/src/agent/families.ts +0 -232
  170. package/src/agent/family-layouts.ts +0 -826
  171. package/src/agent/flowchart-body.ts +0 -372
  172. package/src/agent/flowchart-unsupported.ts +0 -243
  173. package/src/agent/gantt-body.ts +0 -495
  174. package/src/agent/index.ts +0 -10
  175. package/src/agent/journey-body.ts +0 -414
  176. package/src/agent/label-metrics.ts +0 -28
  177. package/src/agent/layout-to-rendered.ts +0 -63
  178. package/src/agent/mutate.ts +0 -97
  179. package/src/agent/mutation-ops.ts +0 -51
  180. package/src/agent/op-schema.ts +0 -439
  181. package/src/agent/parse.ts +0 -223
  182. package/src/agent/pie-body.ts +0 -270
  183. package/src/agent/png.ts +0 -117
  184. package/src/agent/quadrant-body.ts +0 -336
  185. package/src/agent/quality.ts +0 -363
  186. package/src/agent/readability-audit.ts +0 -92
  187. package/src/agent/rendered-route-audit.ts +0 -61
  188. package/src/agent/sequence-body.ts +0 -345
  189. package/src/agent/serialize.ts +0 -214
  190. package/src/agent/state-body.ts +0 -589
  191. package/src/agent/structural-count.ts +0 -150
  192. package/src/agent/timeline-body.ts +0 -280
  193. package/src/agent/trace-log.ts +0 -43
  194. package/src/agent/types.ts +0 -979
  195. package/src/agent/verify.ts +0 -571
  196. package/src/agent/xychart-body.ts +0 -472
  197. package/src/architecture/config.ts +0 -282
  198. package/src/architecture/layout.ts +0 -496
  199. package/src/architecture/parser.ts +0 -375
  200. package/src/architecture/renderer.ts +0 -611
  201. package/src/architecture/types.ts +0 -113
  202. package/src/ascii/ansi.ts +0 -423
  203. package/src/ascii/architecture.ts +0 -210
  204. package/src/ascii/canvas.ts +0 -443
  205. package/src/ascii/class-diagram.ts +0 -697
  206. package/src/ascii/converter.ts +0 -475
  207. package/src/ascii/draw.ts +0 -1693
  208. package/src/ascii/edge-bundling.ts +0 -328
  209. package/src/ascii/edge-routing.ts +0 -330
  210. package/src/ascii/er-diagram.ts +0 -439
  211. package/src/ascii/gantt.ts +0 -276
  212. package/src/ascii/grid.ts +0 -747
  213. package/src/ascii/index.ts +0 -196
  214. package/src/ascii/journey.ts +0 -189
  215. package/src/ascii/meta.ts +0 -244
  216. package/src/ascii/multiline-utils.ts +0 -80
  217. package/src/ascii/pathfinder.ts +0 -301
  218. package/src/ascii/pie.ts +0 -67
  219. package/src/ascii/quadrant.ts +0 -158
  220. package/src/ascii/reverse.ts +0 -216
  221. package/src/ascii/sequence.ts +0 -499
  222. package/src/ascii/shapes/circle.ts +0 -27
  223. package/src/ascii/shapes/corners.ts +0 -143
  224. package/src/ascii/shapes/diamond.ts +0 -27
  225. package/src/ascii/shapes/hexagon.ts +0 -27
  226. package/src/ascii/shapes/index.ts +0 -106
  227. package/src/ascii/shapes/rectangle.ts +0 -168
  228. package/src/ascii/shapes/rounded.ts +0 -27
  229. package/src/ascii/shapes/special.ts +0 -332
  230. package/src/ascii/shapes/stadium.ts +0 -110
  231. package/src/ascii/shapes/state.ts +0 -192
  232. package/src/ascii/shapes/types.ts +0 -73
  233. package/src/ascii/timeline.ts +0 -128
  234. package/src/ascii/types.ts +0 -312
  235. package/src/ascii/validate.ts +0 -120
  236. package/src/ascii/width.ts +0 -81
  237. package/src/ascii/xychart.ts +0 -919
  238. package/src/browser.ts +0 -29
  239. package/src/class/layout.ts +0 -240
  240. package/src/class/parser.ts +0 -332
  241. package/src/class/renderer.ts +0 -638
  242. package/src/class/types.ts +0 -129
  243. package/src/cli/agent-instructions.ts +0 -1
  244. package/src/cli/am-bin.ts +0 -6
  245. package/src/cli/exit-codes.ts +0 -18
  246. package/src/cli/index.ts +0 -1117
  247. package/src/cli/init-agent.ts +0 -147
  248. package/src/color-resolver.ts +0 -152
  249. package/src/elk-instance.ts +0 -114
  250. package/src/er/layout.ts +0 -187
  251. package/src/er/parser.ts +0 -226
  252. package/src/er/renderer.ts +0 -792
  253. package/src/er/types.ts +0 -99
  254. package/src/font-manifest.ts +0 -27
  255. package/src/gantt/layout.ts +0 -365
  256. package/src/gantt/parser.ts +0 -282
  257. package/src/gantt/pipeline.ts +0 -27
  258. package/src/gantt/renderer.ts +0 -414
  259. package/src/gantt/schedule.ts +0 -513
  260. package/src/gantt/types.ts +0 -255
  261. package/src/index.ts +0 -368
  262. package/src/journey/layout.ts +0 -520
  263. package/src/journey/parser.ts +0 -218
  264. package/src/journey/renderer.ts +0 -811
  265. package/src/journey/types.ts +0 -144
  266. package/src/layout/geometry.ts +0 -182
  267. package/src/layout/pass.ts +0 -142
  268. package/src/layout/passes/index.ts +0 -3916
  269. package/src/layout-engine.ts +0 -1565
  270. package/src/layout-rubric.ts +0 -659
  271. package/src/mcp/artifacts.ts +0 -137
  272. package/src/mcp/dynamic-harness.ts +0 -31
  273. package/src/mcp/dynamic-modules.d.ts +0 -7
  274. package/src/mcp/facade.ts +0 -608
  275. package/src/mcp/harness-runtime.ts +0 -203
  276. package/src/mcp/hosted-server.ts +0 -468
  277. package/src/mcp/mcp-bin.ts +0 -3
  278. package/src/mcp/mcp-cli.ts +0 -82
  279. package/src/mcp/protocol.ts +0 -13
  280. package/src/mcp/sandbox.ts +0 -195
  281. package/src/mcp/sdk-decl.ts +0 -387
  282. package/src/mcp/server.ts +0 -362
  283. package/src/mcp/tool-surface.ts +0 -146
  284. package/src/mermaid-source.ts +0 -655
  285. package/src/multiline-utils.ts +0 -228
  286. package/src/parser.ts +0 -1031
  287. package/src/pie/layout.ts +0 -168
  288. package/src/pie/parser.ts +0 -136
  289. package/src/pie/renderer.ts +0 -234
  290. package/src/pie/types.ts +0 -82
  291. package/src/quadrant/layout.ts +0 -191
  292. package/src/quadrant/parser.ts +0 -183
  293. package/src/quadrant/renderer.ts +0 -322
  294. package/src/quadrant/types.ts +0 -113
  295. package/src/render-family-hooks.ts +0 -244
  296. package/src/renderer.ts +0 -1099
  297. package/src/route-contracts.ts +0 -2723
  298. package/src/scene/backend.ts +0 -76
  299. package/src/scene/fidelity.ts +0 -183
  300. package/src/scene/hybrid-backend.ts +0 -174
  301. package/src/scene/ir.ts +0 -181
  302. package/src/scene/marks.ts +0 -127
  303. package/src/scene/rough-backend.ts +0 -378
  304. package/src/scene/seed.ts +0 -46
  305. package/src/scene/style-registry.ts +0 -556
  306. package/src/sequence/layout.ts +0 -456
  307. package/src/sequence/parser.ts +0 -255
  308. package/src/sequence/renderer.ts +0 -604
  309. package/src/sequence/types.ts +0 -154
  310. package/src/shape-clipping.ts +0 -351
  311. package/src/shared/accessibility-directives.ts +0 -22
  312. package/src/shared/batched.ts +0 -61
  313. package/src/shared/color-math.ts +0 -72
  314. package/src/shared/svg-a11y.ts +0 -29
  315. package/src/shared/syntax-error.ts +0 -17
  316. package/src/shared/unicode-ranges.ts +0 -135
  317. package/src/styles.ts +0 -318
  318. package/src/svg-paths.ts +0 -28
  319. package/src/text-metrics.ts +0 -248
  320. package/src/theme.ts +0 -639
  321. package/src/timeline/layout.ts +0 -381
  322. package/src/timeline/parser.ts +0 -215
  323. package/src/timeline/renderer.ts +0 -538
  324. package/src/timeline/types.ts +0 -105
  325. package/src/types.ts +0 -454
  326. package/src/website-worker-modules.d.ts +0 -18
  327. package/src/xychart/axis-utils.ts +0 -109
  328. package/src/xychart/colors.ts +0 -124
  329. package/src/xychart/config.ts +0 -88
  330. package/src/xychart/layout.ts +0 -656
  331. package/src/xychart/parser.ts +0 -504
  332. package/src/xychart/renderer.ts +0 -640
  333. package/src/xychart/types.ts +0 -282
@@ -1,1089 +0,0 @@
1
- type MermaidConfigScalar = string | number | boolean | null;
2
- type MermaidConfigValue = MermaidConfigScalar | MermaidConfigValue[] | MermaidConfigMap;
3
- interface MermaidConfigMap {
4
- [key: string]: MermaidConfigValue | undefined;
5
- }
6
- interface MermaidFrontmatterMap extends MermaidConfigMap {
7
- }
8
- interface MermaidThemeVariables extends MermaidConfigMap {
9
- fontFamily?: string;
10
- }
11
- interface TimelineRuntimeConfig extends MermaidConfigMap {
12
- disableMulticolor?: boolean;
13
- sectionFills?: string[];
14
- sectionColours?: string[];
15
- }
16
- interface JourneyRuntimeConfig extends MermaidConfigMap {
17
- diagramMarginX?: number;
18
- diagramMarginY?: number;
19
- leftMargin?: number;
20
- maxLabelWidth?: number;
21
- width?: number;
22
- height?: number;
23
- boxMargin?: number;
24
- boxTextMargin?: number;
25
- noteMargin?: number;
26
- messageMargin?: number;
27
- messageAlign?: 'left' | 'center' | 'right';
28
- bottomMarginAdj?: number;
29
- useMaxWidth?: boolean;
30
- rightAngles?: boolean;
31
- taskFontSize?: string | number;
32
- taskFontFamily?: string;
33
- taskMargin?: number;
34
- activationWidth?: number;
35
- textPlacement?: string;
36
- actorColours?: string[];
37
- sectionFills?: string[];
38
- sectionColours?: string[];
39
- titleColor?: string;
40
- titleFontFamily?: string;
41
- titleFontSize?: string | number;
42
- }
43
- interface GanttRuntimeConfig extends MermaidConfigMap {
44
- displayMode?: string;
45
- }
46
- interface MermaidRuntimeConfig extends MermaidConfigMap {
47
- theme?: string;
48
- fontFamily?: string;
49
- themeVariables?: MermaidThemeVariables;
50
- timeline?: TimelineRuntimeConfig;
51
- journey?: JourneyRuntimeConfig;
52
- xyChart?: MermaidConfigMap;
53
- gantt?: GanttRuntimeConfig;
54
- useMaxWidth?: boolean;
55
- useWidth?: number;
56
- themeCSS?: string;
57
- }
58
- interface NormalizedMermaidSource {
59
- text: string;
60
- body: string;
61
- lines: string[];
62
- firstLine: string;
63
- config: MermaidRuntimeConfig;
64
- frontmatter: MermaidFrontmatterMap;
65
- }
66
-
67
- interface DiagramColors {
68
- /** Background color → CSS variable --bg */
69
- bg: string;
70
- /** Foreground / primary text color → CSS variable --fg */
71
- fg: string;
72
- /** Edge/connector color → CSS variable --line */
73
- line?: string;
74
- /** Arrow heads, highlights, special nodes → CSS variable --accent */
75
- accent?: string;
76
- /** Secondary text, edge labels → CSS variable --muted */
77
- muted?: string;
78
- /** Node/box fill tint → CSS variable --surface */
79
- surface?: string;
80
- /** Node/group stroke color → CSS variable --border */
81
- border?: string;
82
- /** Optional explicit drop shadows on node shapes. Default: false */
83
- shadow?: boolean;
84
- /**
85
- * Font family for all text. Emitted on the SVG root as `--font`, so the family
86
- * stays overridable post-render via inline style. Default: 'Inter'.
87
- */
88
- font?: string;
89
- /**
90
- * Whether to embed the Google Fonts `@import` line in the SVG `<style>` block.
91
- * Default: `true` (preserves wire compatibility with all existing consumers).
92
- *
93
- * CLI / PNG paths set `false` explicitly to render offline / CSP-friendly.
94
- * The CSS variable `--font` is always emitted on the SVG root regardless,
95
- * so the family stays overridable post-render even when the @import is gone.
96
- */
97
- embedFontImport?: boolean;
98
- }
99
- /** Default bg/fg when no colors are provided (zinc light) */
100
- declare const DEFAULTS: Readonly<{
101
- bg: string;
102
- fg: string;
103
- }>;
104
- declare const THEMES: Record<string, DiagramColors>;
105
- type ThemeName = keyof typeof THEMES;
106
- /**
107
- * Minimal subset of Shiki's ThemeRegistrationResolved that we need.
108
- * We don't import from shiki to avoid a hard dependency.
109
- */
110
- interface ShikiThemeLike {
111
- type?: string;
112
- colors?: Record<string, string>;
113
- tokenColors?: Array<{
114
- scope?: string | string[];
115
- settings?: {
116
- foreground?: string;
117
- };
118
- }>;
119
- }
120
- /**
121
- * Extract diagram colors from a Shiki theme object.
122
- * Works with any VS Code / TextMate theme loaded by Shiki.
123
- *
124
- * Maps editor UI colors to diagram roles:
125
- * editor.background → bg
126
- * editor.foreground → fg
127
- * editorLineNumber.fg → line (optional)
128
- * focusBorder / keyword → accent (optional)
129
- * comment token → muted (optional)
130
- * editor.selectionBackground→ surface (optional)
131
- * editorWidget.border → border (optional)
132
- *
133
- * @example
134
- * ```ts
135
- * import { getSingletonHighlighter } from 'shiki'
136
- * import { fromShikiTheme } from 'agentic-mermaid'
137
- *
138
- * const hl = await getSingletonHighlighter({ themes: ['tokyo-night'] })
139
- * const colors = fromShikiTheme(hl.getTheme('tokyo-night'))
140
- * const svg = renderMermaidSVG(code, colors)
141
- * ```
142
- */
143
- declare function fromShikiTheme(theme: ShikiThemeLike): DiagramColors;
144
- /**
145
- * All derived diagram colors resolved to concrete hex values.
146
- * Mirrors the CSS variable derivation system in buildStyleBlock().
147
- */
148
- interface ResolvedColors {
149
- bg: string;
150
- fg: string;
151
- text: string;
152
- textSec: string;
153
- textMuted: string;
154
- textFaint: string;
155
- line: string;
156
- arrow: string;
157
- nodeFill: string;
158
- nodeStroke: string;
159
- groupFill: string;
160
- groupHdr: string;
161
- innerStroke: string;
162
- keyBadge: string;
163
- }
164
- /**
165
- * Resolve all derived colors from a DiagramColors to concrete hex values.
166
- * Implements the same logic as the CSS color-mix() derivations in buildStyleBlock().
167
- */
168
- declare function resolveColors(colors: DiagramColors): ResolvedColors;
169
- /**
170
- * Resolve all CSS var() and color-mix() expressions in an SVG string to
171
- * concrete hex color values. This makes the SVG render correctly in
172
- * non-browser renderers (resvg, librsvg, etc.) that don't support CSS
173
- * custom properties or color-mix().
174
- *
175
- * Operates via iterative string replacement:
176
- * 1. Replace var(--name) with known resolved values
177
- * 2. Replace var(--name, fallback) — use value if known, else fallback
178
- * 3. Resolve color-mix(in srgb, #hex P%, #hex) to computed hex
179
- * 4. Extract CSS variable definitions from <style> and resolve remaining refs
180
- * 5. Repeat until stable
181
- *
182
- * When bg/fg are not hex colors (e.g. CSS variable strings for live theming),
183
- * the SVG is returned as-is since resolution isn't possible.
184
- */
185
- declare function inlineResolvedColors(svg: string, colors: DiagramColors): string;
186
-
187
- interface ArchitectureVisualConfig {
188
- groupHeaderHeight: number;
189
- groupFontSize: number;
190
- groupFontWeight: number;
191
- groupLetterSpacing: number;
192
- groupFont?: string;
193
- groupTextTransform?: TextTransform;
194
- groupPaddingX: number;
195
- groupPaddingY: number;
196
- groupLabelPaddingX: number;
197
- groupCornerRadius: number;
198
- groupLineWidth: number;
199
- groupText?: string;
200
- serviceFontSize: number;
201
- serviceFontWeight: number;
202
- serviceLetterSpacing: number;
203
- serviceTextTransform?: TextTransform;
204
- servicePaddingX: number;
205
- servicePaddingY: number;
206
- serviceCornerRadius: number;
207
- serviceLineWidth: number;
208
- serviceText?: string;
209
- edgeFontSize: number;
210
- edgeFontWeight: number;
211
- edgeLetterSpacing: number;
212
- edgeTextTransform?: TextTransform;
213
- edgeLineWidth: number;
214
- edgeBendRadius: number;
215
- edgeStroke?: string;
216
- edgeText?: string;
217
- iconSize: number;
218
- serviceIconSize: number;
219
- junctionOuterRadius: number;
220
- junctionInnerRadius: number;
221
- groupSurface?: string;
222
- groupHeaderSurface?: string;
223
- groupBorder?: string;
224
- serviceSurface?: string;
225
- serviceBorder?: string;
226
- }
227
-
228
- /** A partial, composable public description of how diagrams look. */
229
- interface StyleSpec {
230
- /** Optional JSON Schema pointer for file-backed styles. Ignored at render time. */
231
- $schema?: string;
232
- name?: string;
233
- blurb?: string;
234
- /** Palette — the seven tokens every mark references. A colors-only style
235
- * is a theme. User themeVariables/color options still win over these. */
236
- colors?: {
237
- bg?: string;
238
- fg?: string;
239
- line?: string;
240
- accent?: string;
241
- muted?: string;
242
- surface?: string;
243
- border?: string;
244
- };
245
- /** Font family default (threaded through the --font CSS variable). PNG
246
- * export needs the family bundled or resolvable by the rasterizer. */
247
- font?: string;
248
- /** Stroke rendering: 'crisp' (default), 'jittered' rough.js strokes, or
249
- * 'freehand' pressure-ribbon strokes. */
250
- stroke?: 'crisp' | 'jittered' | 'freehand';
251
- roughness?: number;
252
- bowing?: number;
253
- /** 1 = single stroke (disableMultiStroke), 2 = sketchy double stroke. */
254
- passes?: number;
255
- strokeWidth?: number;
256
- fill?: 'none' | 'hachure' | 'solid' | 'wash';
257
- hachureAngle?: number;
258
- hachureGap?: number;
259
- fillWeight?: number;
260
- /** Wash fill glaze opacity / edge-darkening opacity (fill: 'wash'). */
261
- washOpacity?: number;
262
- washEdge?: number;
263
- /** Flat page furniture drawn right after the document prelude. */
264
- backdrop?: 'plain' | 'paper-ruled' | 'grid';
265
- /** Expert override only — normally inferred by inferBackend(). */
266
- backend?: 'default' | 'rough' | 'hybrid';
267
- intent?: 'premium' | 'draft' | 'lofi';
268
- /** §3.8 monochrome contract: tone via shading/weight, never extra hues. */
269
- mono?: boolean;
270
- }
271
- /** What RenderOptions.style accepts: a registered name, an inline spec, or a
272
- * stack of either (merged left → right). */
273
- type StyleInput = string | StyleSpec;
274
- declare function registerStyle(spec: StyleSpec): void;
275
- declare function getStyle(name: string): StyleSpec | undefined;
276
- declare function knownStyles(): string[];
277
- /** Which backend a style needs, derived from what it asks for — authors
278
- * describe the look, the engine picks the machinery. */
279
- declare function inferBackend(spec: StyleSpec): 'default' | 'rough' | 'hybrid';
280
- declare function resolveStyleStack(input: StyleInput | StyleInput[] | undefined): StyleSpec | undefined;
281
- /** Validate an untrusted (e.g. JSON) style record. Returns human-readable
282
- * problems; [] means the record is a usable StyleSpec. Declarative-only by
283
- * construction — there is no field that can carry markup or URLs. */
284
- declare function validateStyleSpec(value: unknown): string[];
285
-
286
- interface MermaidGraph {
287
- direction: Direction;
288
- nodes: Map<string, MermaidNode>;
289
- edges: MermaidEdge[];
290
- subgraphs: MermaidSubgraph[];
291
- classDefs: Map<string, Record<string, string>>;
292
- /** Maps node IDs to their class names (from `class X className` or `:::className` shorthand) */
293
- classAssignments: Map<string, string>;
294
- /** Maps node IDs to inline styles (from `style X fill:#f00,stroke:#333`) */
295
- nodeStyles: Map<string, Record<string, string>>;
296
- /** Maps edge indices (or 'default') to inline styles from `linkStyle` directives */
297
- linkStyles: Map<number | 'default', Record<string, string>>;
298
- }
299
- type Direction = 'TD' | 'TB' | 'LR' | 'BT' | 'RL';
300
- interface MermaidNode {
301
- id: string;
302
- label: string;
303
- shape: NodeShape;
304
- }
305
- type NodeShape = 'rectangle' | 'service' | 'rounded' | 'diamond' | 'stadium' | 'circle' | 'subroutine' | 'doublecircle' | 'hexagon' | 'cylinder' | 'asymmetric' | 'trapezoid' | 'trapezoid-alt' | 'lean-r' | 'lean-l' | 'state-start' | 'state-end';
306
- interface MermaidEdge {
307
- source: string;
308
- target: string;
309
- label?: string;
310
- style: EdgeStyle;
311
- /** Whether to render a marker at the start (source end) of the edge */
312
- hasArrowStart: boolean;
313
- /** Whether to render a marker at the end (target end) of the edge */
314
- hasArrowEnd: boolean;
315
- /** Marker shape at start when hasArrowStart=true. Defaults to 'arrow' if undefined. */
316
- startMarker?: EdgeMarker;
317
- /** Marker shape at end when hasArrowEnd=true. Defaults to 'arrow' if undefined. */
318
- endMarker?: EdgeMarker;
319
- /** Mermaid link length (rank-distance intent): 1 = base operator, 2 = one
320
- * extra shaft unit (`--->`, `-..->`, `====>`, `~~~~`), etc. Undefined ≡ 1,
321
- * so base-form edges serialize byte-identically. Preserved through
322
- * round-trip; layout honors this conservatively for simple primary-forward
323
- * no-subgraph DAGs and leaves grouped/cyclic cases to ELK. */
324
- length?: number;
325
- }
326
- /** 'invisible' is Mermaid's `~~~` link: it participates in layout ordering
327
- * but draws no stroke. */
328
- type EdgeStyle = 'solid' | 'dotted' | 'thick' | 'invisible';
329
- type EdgeMarker = 'arrow' | 'circle' | 'cross';
330
- interface MermaidSubgraph {
331
- id: string;
332
- label: string;
333
- nodeIds: string[];
334
- children: MermaidSubgraph[];
335
- /** Optional direction override for this subgraph's internal layout */
336
- direction?: Direction;
337
- }
338
- interface PositionedDiagram {
339
- width: number;
340
- height: number;
341
- }
342
- interface RenderContext<TPositioned extends PositionedDiagram = PositionedDiagram> {
343
- positioned: TPositioned;
344
- colors: DiagramColors;
345
- options: RenderOptions;
346
- }
347
- interface PositionedGraph extends PositionedDiagram {
348
- width: number;
349
- height: number;
350
- nodes: PositionedNode[];
351
- edges: PositionedEdge[];
352
- groups: PositionedGroup[];
353
- }
354
- interface PositionedNode {
355
- id: string;
356
- label: string;
357
- shape: NodeShape;
358
- x: number;
359
- y: number;
360
- width: number;
361
- height: number;
362
- /** Inline styles resolved from classDef + explicit `style` statements — override theme defaults */
363
- inlineStyle?: Record<string, string>;
364
- /** User-assigned Mermaid class names (from `class X myClass` / `:::myClass`). Emitted as SVG CSS classes so external stylesheets can target them. */
365
- classNames?: string[];
366
- }
367
- interface PositionedEdge {
368
- source: string;
369
- target: string;
370
- label?: string;
371
- style: EdgeStyle;
372
- hasArrowStart: boolean;
373
- hasArrowEnd: boolean;
374
- /** Marker shape at start when hasArrowStart=true. Defaults to 'arrow' if undefined. */
375
- startMarker?: EdgeMarker;
376
- /** Marker shape at end when hasArrowEnd=true. Defaults to 'arrow' if undefined. */
377
- endMarker?: EdgeMarker;
378
- /** Full path including bends — array of {x, y} points */
379
- points: Point[];
380
- /** Layout-computed label center position (avoids label-label collisions) */
381
- labelPosition?: Point;
382
- /** Inline styles resolved from `linkStyle` directives — override theme defaults */
383
- inlineStyle?: Record<string, string>;
384
- /** Index into MermaidGraph.edges this positioned edge was extracted from */
385
- edgeIndex?: number;
386
- /** Route contract certificate attached by the layout pipeline (docs/design/system/route-contracts.md) */
387
- routeCertificate?: RouteCertificate;
388
- }
389
- type RouteClass = 'primary-forward' | 'feedback' | 'self-loop' | 'container' | 'cross-hierarchy';
390
- type LayoutRouteClass = RouteClass | 'family-layout';
391
- /** The four canonical connection points of a shape (Visio connection-point /
392
- * yFiles port-candidate model). For every Mermaid shape these lie at the
393
- * bbox side midpoints: the diamond's vertices, the rectangle's side
394
- * midpoints, and the boundary extremes of circles, stadiums, hexagons and
395
- * cylinders are the same four points, because each shape is symmetric and
396
- * inscribed in its bbox. */
397
- type PortSide = 'N' | 'E' | 'S' | 'W';
398
- /** Diamond facet-midpoints: the four points halfway along each slanted edge
399
- * (NE/SE/SW/NW). They lie exactly on the diamond outline and serve as
400
- * designated attachment points alongside the four cardinal vertices, but are
401
- * diamond-only — shapePorts() stays four-cardinal for every shape. */
402
- type DiamondFacet = 'NE' | 'SE' | 'SW' | 'NW';
403
- /** A port an endpoint may sit on: a cardinal vertex/side-midpoint, or — on a
404
- * diamond — a facet-midpoint. */
405
- type AnyPort = PortSide | DiamondFacet;
406
- type PortSemanticRole = 'flow-source' | 'flow-target' | 'feedback-source' | 'feedback-target' | 'self-loop-source' | 'self-loop-target' | 'container-source' | 'container-target' | 'cross-hierarchy-source' | 'cross-hierarchy-target';
407
- /** Dynamic port allocation metadata: which side an endpoint semantically uses,
408
- * its deterministic order among the endpoints on that side, and why it is
409
- * there. This extends `sourcePort`/`targetPort` without changing their V1
410
- * vocabulary: exact endpoint ports remain `AnyPort`, while the allocation
411
- * records side-level slot/role intent for pre-layout and debugging. */
412
- interface RoutePortAssignment {
413
- side: PortSide;
414
- /** 0-based deterministic order along the side (N/S: left→right; E/W: top→bottom). */
415
- slotIndex: number;
416
- /** Number of endpoints allocated to this node side. */
417
- slotCount: number;
418
- role: PortSemanticRole;
419
- /** Exact designated port when the final endpoint landed on one. */
420
- port?: AnyPort;
421
- }
422
- interface RouteBlocker {
423
- kind: 'node' | 'label' | 'channel' | 'span' | 'crossing' | 'port';
424
- id: string;
425
- }
426
- type RouteInvariant = 'straight' | 'explained-detour' | 'bundle' | 'outer-feedback' | 'feedback-detour' | 'self-loop' | 'container-attach' | 'unverified-shape';
427
- interface RouteCertificateBase {
428
- /** Index into MermaidGraph.edges */
429
- edgeIndex: number;
430
- routeClass: RouteClass;
431
- bendCount: number;
432
- directLaneClear?: boolean;
433
- directLaneBlockedBy?: RouteBlocker[];
434
- /** Set when the endpoint sits exactly on a port: a cardinal side-midpoint
435
- * for every shape, or a diamond facet-midpoint (NE/SE/SW/NW). */
436
- sourcePort?: AnyPort;
437
- /** Set when the endpoint sits exactly on a port: a cardinal side-midpoint
438
- * for every shape, or a diamond facet-midpoint (NE/SE/SW/NW). */
439
- targetPort?: AnyPort;
440
- /** Dynamic side/slot/role allocation for the source endpoint. */
441
- sourcePortAssignment?: RoutePortAssignment;
442
- /** Dynamic side/slot/role allocation for the target endpoint. */
443
- targetPortAssignment?: RoutePortAssignment;
444
- }
445
- type StraightRouteCertificate = RouteCertificateBase & {
446
- invariant: 'straight';
447
- /** True when the certifying straightener collapsed this route */
448
- straightened?: true;
449
- };
450
- type NonStraightRouteCertificate = RouteCertificateBase & {
451
- invariant: Exclude<RouteInvariant, 'straight'>;
452
- /** Non-straight certificates cannot claim a straightening happened. */
453
- straightened?: never;
454
- };
455
- type RouteCertificate = StraightRouteCertificate | NonStraightRouteCertificate;
456
- type FamilyEdgeRouteCertificate = {
457
- family: 'class' | 'er';
458
- edgeIndex: number;
459
- routeClass: 'family-layout';
460
- invariant: 'orthogonal-box' | 'unverified-family-route';
461
- bendCount: number;
462
- orthogonal: boolean;
463
- sourceBoundary: boolean;
464
- targetBoundary: boolean;
465
- } | {
466
- family: 'architecture';
467
- edgeIndex: number;
468
- routeClass: 'family-layout';
469
- invariant: 'side-anchored' | 'unverified-family-route';
470
- bendCount: number;
471
- orthogonal: boolean;
472
- sourceSide: 'L' | 'R' | 'T' | 'B';
473
- targetSide: 'L' | 'R' | 'T' | 'B';
474
- sourceBoundary: 'item' | 'group';
475
- targetBoundary: 'item' | 'group';
476
- sourceAnchored: boolean;
477
- targetAnchored: boolean;
478
- } | {
479
- family: 'sequence';
480
- edgeIndex: number;
481
- routeClass: 'family-layout';
482
- invariant: 'lifeline-message' | 'self-message' | 'unverified-family-route';
483
- bendCount: number;
484
- horizontal: boolean;
485
- sourceLifeline: boolean;
486
- targetLifeline: boolean;
487
- selfMessage: boolean;
488
- };
489
- type RegionContainmentCertificate = {
490
- family: 'timeline' | 'xychart' | 'pie' | 'quadrant' | 'gantt';
491
- elementId: string;
492
- routeClass: 'family-layout';
493
- invariant: 'timeline-interval' | 'plot-contained' | 'legend-contained' | 'section-contained' | 'unverified-family-layout';
494
- /** Node/mark box in layout coordinates; included so cert consumers do not have to join back to nodes. */
495
- bounds: {
496
- x: number;
497
- y: number;
498
- w: number;
499
- h: number;
500
- };
501
- /** Center point used by plot/region-mark containment certs. */
502
- center: {
503
- x: number;
504
- y: number;
505
- };
506
- /** Whether the cert proves the full box or the semantic mark center is contained. */
507
- containment: 'bounds' | 'center';
508
- withinBounds: boolean;
509
- groupId?: string;
510
- withinGroup?: boolean;
511
- };
512
- type EdgeRouteCertificate = RouteCertificate | FamilyEdgeRouteCertificate;
513
- type FamilyRouteCertificate = FamilyEdgeRouteCertificate | RegionContainmentCertificate;
514
- type LayoutRouteCertificate = EdgeRouteCertificate | RegionContainmentCertificate;
515
- interface Point {
516
- x: number;
517
- y: number;
518
- }
519
- interface PositionedGroup {
520
- id: string;
521
- label: string;
522
- x: number;
523
- y: number;
524
- width: number;
525
- height: number;
526
- children: PositionedGroup[];
527
- }
528
- type TextTransform = 'uppercase' | 'lowercase' | 'capitalize';
529
- interface RenderOptions {
530
- /** Background color → CSS variable --bg. Default: '#FFFFFF' */
531
- bg?: string;
532
- /** Foreground / primary text color → CSS variable --fg. Default: '#27272A' */
533
- fg?: string;
534
- /** Edge/connector color → CSS variable --line */
535
- line?: string;
536
- /** Arrow heads, highlights → CSS variable --accent */
537
- accent?: string;
538
- /** Secondary text, edge labels → CSS variable --muted */
539
- muted?: string;
540
- /** Node/box fill tint → CSS variable --surface */
541
- surface?: string;
542
- /** Node/group stroke color → CSS variable --border */
543
- border?: string;
544
- /** Font family for all text. Default: 'Inter' */
545
- font?: string;
546
- /**
547
- * How the diagram looks: a registered style name ('hand-drawn', 'tufte',
548
- * any THEMES palette name like 'dracula'), an inline StyleSpec, or a STACK
549
- * of either merged left-to-right ({ style: ['hand-drawn', 'dracula'] } is
550
- * hand-drawn geometry with the dracula palette). A colors-only style is a
551
- * palette.
552
- * Precedence: defaults < style stack < themeVariables < explicit color
553
- * options. Unknown names throw. Unset (or 'crisp') = the default renderer,
554
- * byte-identical to previous releases.
555
- */
556
- style?: StyleInput | StyleInput[];
557
- /** Canvas padding in px. Default: 40 */
558
- padding?: number;
559
- /** Horizontal spacing between sibling nodes. Default: 24 */
560
- nodeSpacing?: number;
561
- /** Vertical spacing between layers. Default: 40 */
562
- layerSpacing?: number;
563
- /** Spacing between disconnected components. Default: nodeSpacing (24) */
564
- componentSpacing?: number;
565
- /** Render with transparent background (no background style on SVG). Default: false */
566
- transparent?: boolean;
567
- /** Enable hover tooltips on chart data points (xychart only). Default: false */
568
- interactive?: boolean;
569
- /** Optional explicit drop shadows on node shapes. Default: false */
570
- shadow?: boolean;
571
- /** Family-specific SVG renderer options for architecture-beta diagrams. */
572
- architecture?: {
573
- visual?: ArchitectureVisualConfig;
574
- };
575
- /** Optional Mermaid-style runtime config (analogous to initialize/frontmatter config). */
576
- mermaidConfig?: MermaidRuntimeConfig;
577
- /**
578
- * Whether to embed the Google Fonts `@import` line in the SVG `<style>` block.
579
- * Default: `true` (preserves wire compatibility with all existing consumers).
580
- *
581
- * CLI / PNG paths set `false` explicitly to render offline / CSP-friendly.
582
- * The CSS variable `--font` is always emitted on the SVG root regardless,
583
- * so the family stays overridable post-render even when the @import is gone.
584
- */
585
- embedFontImport?: boolean;
586
- /**
587
- * Compact SVG output. Default `false`. When true:
588
- * - Numeric coords with 3+ fractional digits are rounded (via `roundCoord`).
589
- * - Newlines between SVG elements are collapsed (whitespace inside `<style>`
590
- * is preserved so CSS declarations don't break).
591
- * - `data-*` and `class=` attributes are preserved (agent inspection hooks).
592
- *
593
- * Typical reduction: 30-40% of bytes on flowchart graphs. Useful for the
594
- * PNG render path (no need for human-readable SVG) and for bandwidth-
595
- * sensitive consumers.
596
- */
597
- compact?: boolean;
598
- /**
599
- * Namespace prefix for all generated SVG def ids (markers, filters) and
600
- * their `url(#…)` references. Default '' = current behavior (back-compat,
601
- * zero snapshot churn). Set a distinct prefix per diagram when rendering
602
- * multiple diagrams onto one HTML page so their `<defs>` don't collide
603
- * (e.g. two `arrowhead` markers — the browser dedupes by id and the second
604
- * diagram's arrows break). `am batch` auto-assigns per-line prefixes.
605
- * Must be deterministic per call site to preserve render determinism.
606
- */
607
- idPrefix?: string;
608
- /**
609
- * Security posture for the rendered output. Default `'default'`.
610
- * `'strict'` (agent / untrusted-diagram mode): guarantees no external-fetch
611
- * references in the SVG — forces `embedFontImport` off (no Google Fonts
612
- * `@import`), so the SVG renders with no network calls. The `--font` CSS
613
- * variable still declares the family. Use `verifyNoExternalRefs(svg)` to
614
- * assert the guarantee. Agent/untrusted SVG callers should opt into strict
615
- * mode explicitly. See SECURITY.md.
616
- */
617
- security?: 'default' | 'strict';
618
- /**
619
- * Explicit "today" for the Gantt `todayMarker` (a date in the diagram's
620
- * `dateFormat`, or ISO `YYYY-MM-DD`). Gantt rendering never reads the wall
621
- * clock; without this value the today marker is simply not drawn, and
622
- * `todayMarker off` disables it even when a clock is supplied.
623
- */
624
- ganttToday?: string;
625
- /**
626
- * Deterministic re-roll seed for stochastic styles.
627
- * The same source + options + seed always produces identical bytes; it
628
- * re-rolls ink wobble only — layout never moves. The crisp path ignores
629
- * it. Default 0.
630
- */
631
- seed?: number;
632
- }
633
-
634
- /**
635
- * The internal color waist: every public color dialect is normalized to
636
- * DiagramColors before layout/render code sees it.
637
- */
638
- declare function resolveDiagramColors(options: RenderOptions, config: MermaidRuntimeConfig, font?: string): DiagramColors;
639
-
640
- /**
641
- * Parse Mermaid text into a logical graph structure.
642
- * Auto-detects diagram type (flowchart or state diagram).
643
- * Throws on invalid/unsupported input.
644
- */
645
- declare function parseMermaid(text: string): MermaidGraph;
646
-
647
- /** Configuration for ASCII rendering. */
648
- interface AsciiConfig {
649
- /** true = ASCII chars (+,-,|), false = Unicode box-drawing (┌,─,│). Default: false */
650
- useAscii: boolean;
651
- /** Horizontal spacing between nodes. Default: 5 */
652
- paddingX: number;
653
- /** Vertical spacing between nodes. Default: 5 */
654
- paddingY: number;
655
- /** Padding inside node boxes. Default: 1 */
656
- boxBorderPadding: number;
657
- /** Graph direction: "LR" or "TD". */
658
- graphDirection: 'LR' | 'TD';
659
- }
660
- /**
661
- * Theme colors for ASCII output — hex color strings.
662
- * Derived from the SVG theme system for visual consistency.
663
- */
664
- interface AsciiTheme {
665
- /** Text color (node labels, edge labels) */
666
- fg: string;
667
- /** Box border color (node borders, subgraph borders) */
668
- border: string;
669
- /** Edge line color (paths between nodes) */
670
- line: string;
671
- /** Arrowhead color (▲▼◄► or ^v<>) */
672
- arrow: string;
673
- /** Theme accent color (optional, used by xycharts for series 0) */
674
- accent?: string;
675
- /** Background color (optional, used by xycharts for dark-mode-aware shading) */
676
- bg?: string;
677
- /** Corner character color (optional, defaults to line) */
678
- corner?: string;
679
- /** Junction character color (optional, defaults to border) */
680
- junction?: string;
681
- }
682
- /** Color mode for output. */
683
- type ColorMode = 'none' | 'ansi16' | 'ansi256' | 'truecolor' | 'html';
684
-
685
- interface AsciiRenderOptions {
686
- /** true = ASCII chars (+,-,|,>), false = Unicode box-drawing (┌,─,│,►). Default: false */
687
- useAscii?: boolean;
688
- /** Horizontal spacing between nodes. Default: 5 */
689
- paddingX?: number;
690
- /** Vertical spacing between nodes. Default: 5 */
691
- paddingY?: number;
692
- /** Padding inside node boxes. Default: 1 */
693
- boxBorderPadding?: number;
694
- /**
695
- * Color mode for output.
696
- * - 'none': No colors (plain text)
697
- * - 'auto': Auto-detect (terminal ANSI capabilities, or HTML in browsers)
698
- * - 'ansi16': 16-color ANSI
699
- * - 'ansi256': 256-color xterm
700
- * - 'truecolor': 24-bit RGB
701
- * - 'html': HTML <span> tags with inline color styles (for browser rendering)
702
- * Default: 'auto'
703
- */
704
- colorMode?: ColorMode | 'auto';
705
- /** Theme colors for ASCII output. Uses default theme if not provided. */
706
- theme?: Partial<AsciiTheme>;
707
- /** Optional Mermaid-style runtime config (analogous to initialize/frontmatter config). */
708
- mermaidConfig?: MermaidRuntimeConfig;
709
- /**
710
- * Loop 9 M13: cap output width in characters. When set, node labels wrap
711
- * at word boundaries to fit within `maxWidth / 3` per node. Single words
712
- * longer than `maxWidth / 2` render anyway (with a console.warn). The
713
- * overall canvas may still exceed `maxWidth` if the diagram has many
714
- * parallel columns; this is best-effort wrapping, not hard truncation.
715
- */
716
- maxWidth?: number;
717
- /**
718
- * Explicit "today" for the Gantt todayMarker (date in the diagram's
719
- * dateFormat or ISO YYYY-MM-DD). Gantt never reads the wall clock; without
720
- * this the marker is not drawn.
721
- */
722
- ganttToday?: string;
723
- }
724
- /**
725
- * Render Mermaid diagram text to an ASCII/Unicode string.
726
- *
727
- * Synchronous — no async layout engine needed (unlike the SVG renderer).
728
- * Auto-detects diagram type from the header line and dispatches to
729
- * the appropriate renderer.
730
- *
731
- * @param text - Mermaid source text (any supported diagram type)
732
- * @param options - Rendering options
733
- * @returns Multi-line ASCII/Unicode string
734
- *
735
- * @example
736
- * ```ts
737
- * const result = renderMermaidAscii(`
738
- * graph LR
739
- * A --> B --> C
740
- * `, { useAscii: true })
741
- *
742
- * // Output:
743
- * // +---+ +---+ +---+
744
- * // | | | | | |
745
- * // | A |---->| B |---->| C |
746
- * // | | | | | |
747
- * // +---+ +---+ +---+
748
- * ```
749
- */
750
- declare function renderMermaidASCII(text: string, options?: AsciiRenderOptions): string;
751
- /** @deprecated Use `renderMermaidASCII` */
752
- declare const renderMermaidAscii: typeof renderMermaidASCII;
753
-
754
- type ArchitectureSide = 'L' | 'R' | 'T' | 'B';
755
- type ArchitectureEndpointBoundary = 'item' | 'group';
756
- interface ArchitectureChildRef {
757
- kind: 'group' | 'service' | 'junction';
758
- id: string;
759
- }
760
- interface ArchitectureGroup {
761
- id: string;
762
- label: string;
763
- icon?: string;
764
- parentId?: string;
765
- children: ArchitectureChildRef[];
766
- }
767
- interface ArchitectureService {
768
- id: string;
769
- label: string;
770
- icon?: string;
771
- parentId?: string;
772
- }
773
- interface ArchitectureJunction {
774
- id: string;
775
- parentId?: string;
776
- }
777
- interface ArchitectureEndpoint {
778
- id: string;
779
- side: ArchitectureSide;
780
- boundary: ArchitectureEndpointBoundary;
781
- }
782
- interface ArchitectureEdge {
783
- source: ArchitectureEndpoint;
784
- target: ArchitectureEndpoint;
785
- label?: string;
786
- hasArrowStart: boolean;
787
- hasArrowEnd: boolean;
788
- }
789
- interface ArchitectureDiagram {
790
- groups: ArchitectureGroup[];
791
- services: ArchitectureService[];
792
- junctions: ArchitectureJunction[];
793
- edges: ArchitectureEdge[];
794
- rootChildren: ArchitectureChildRef[];
795
- accessibilityTitle?: string;
796
- accessibilityDescription?: string;
797
- }
798
-
799
- declare function parseArchitectureDiagram(lines: string[]): ArchitectureDiagram;
800
- declare function architectureToMermaidGraph(diagram: ArchitectureDiagram): MermaidGraph;
801
-
802
- /**
803
- * Measure the pixel width of a text string.
804
- *
805
- * Uses character class buckets for more accurate width estimation
806
- * than uniform character width assumptions.
807
- *
808
- * @param text - The text to measure
809
- * @param fontSize - Font size in pixels
810
- * @param fontWeight - Font weight (affects width slightly)
811
- * @returns Estimated width in pixels
812
- */
813
- interface TextMeasurementContract {
814
- version: 1;
815
- unit: 'px';
816
- fontCalibration: 'Inter-compatible proportional estimate';
817
- wideCodepoints: 'src/shared/unicode-ranges.ts';
818
- emojiDetection: 'Emoji_Presentation-or-Extended_Pictographic';
819
- ambiguousWidth: 'single-cell';
820
- }
821
- declare const TEXT_MEASUREMENT_CONTRACT: TextMeasurementContract;
822
- interface TextMeasurementInput {
823
- text: string;
824
- fontSize: number;
825
- fontWeight: number;
826
- }
827
- interface TextMeasurementResult {
828
- contract: TextMeasurementContract;
829
- width: number;
830
- charWidthUnits: number;
831
- codePointCount: number;
832
- fontSize: number;
833
- fontWeight: number;
834
- baseRatio: number;
835
- minPadding: number;
836
- }
837
- declare function measureText(input: TextMeasurementInput): TextMeasurementResult;
838
- declare function measureTextWidth(text: string, fontSize: number, fontWeight: number): number;
839
-
840
- /** Semantic channels preserved across the renderer boundary (SPEC §5).
841
- * `tone`/hue are style-derived outputs, not stored here. */
842
- interface SemanticChannels {
843
- /** Hierarchy / callout weight / star magnitude. */
844
- importance?: number;
845
- /** Chart value or quantitative measure (normalized where known). */
846
- value?: number;
847
- /** Chart series, entity type, swimlane, section identity. */
848
- category?: string;
849
- /** e.g. gantt 'done' | 'active' | 'crit'; state 'start' | 'end'. */
850
- status?: string;
851
- /** Task completion in [0,1]. */
852
- progress?: number;
853
- /** Transit route / PCB net identity. */
854
- route?: string;
855
- /** Author-flagged emphasis. */
856
- emphasis?: boolean;
857
- }
858
- /** Mark roles. A closed set per family keeps backends role-aware ("don't
859
- * hachure a lifeline; do hatch a node") without importing family modules. */
860
- type SceneRole = 'node' | 'edge' | 'edge-label' | 'group' | 'group-header' | 'label' | 'actor' | 'lifeline' | 'activation' | 'message' | 'block' | 'note' | 'class-box' | 'member' | 'entity' | 'attribute' | 'relationship' | 'cardinality' | 'pie-slice' | 'legend' | 'bar' | 'series' | 'point' | 'axis' | 'grid' | 'plate' | 'section' | 'task' | 'milestone' | 'marker-line' | 'rail' | 'period' | 'event' | 'score' | 'actor-pill' | 'service' | 'junction' | 'icon' | 'title' | 'defs' | 'prelude' | 'chrome';
861
- /** Geometry a styled backend can redraw. Numbers are in final user units.
862
- * Paint strings may be CSS var()/color-mix() refs — they resolve later via
863
- * inlineResolvedColors, exactly like the crisp path. */
864
- type Geometry = {
865
- kind: 'rect';
866
- x: number;
867
- y: number;
868
- width: number;
869
- height: number;
870
- rx?: number;
871
- ry?: number;
872
- } | {
873
- kind: 'circle';
874
- cx: number;
875
- cy: number;
876
- r: number;
877
- } | {
878
- kind: 'ellipse';
879
- cx: number;
880
- cy: number;
881
- rx: number;
882
- ry: number;
883
- } | {
884
- kind: 'line';
885
- x1: number;
886
- y1: number;
887
- x2: number;
888
- y2: number;
889
- } | {
890
- kind: 'polygon';
891
- points: Array<{
892
- x: number;
893
- y: number;
894
- }>;
895
- } | {
896
- kind: 'polyline';
897
- points: Array<{
898
- x: number;
899
- y: number;
900
- }>;
901
- } | {
902
- kind: 'path';
903
- d: string;
904
- } | {
905
- kind: 'compound';
906
- children: Geometry[];
907
- };
908
- /** The resolved paint attached to a mark — already cascaded (theme tokens,
909
- * classDef, inline style, role defaults) by the family lowering. */
910
- interface MarkPaint {
911
- fill?: string;
912
- stroke?: string;
913
- strokeWidth?: string;
914
- strokeDasharray?: string;
915
- opacity?: string;
916
- }
917
- interface SceneNodeBase {
918
- /** Stable identifier for seeding and cross-references. Derived from source
919
- * semantics (node id, edge endpoints, slice label...), never list position
920
- * (§8 seed contract). */
921
- id: string;
922
- role: SceneRole;
923
- channels?: SemanticChannels;
924
- /** The exact crisp SVG serialization of this mark (possibly multi-line,
925
- * possibly '' for marks that draw nothing, e.g. invisible edges). */
926
- crisp: string;
927
- }
928
- interface ShapeMark extends SceneNodeBase {
929
- kind: 'shape';
930
- geometry: Geometry;
931
- paint: MarkPaint;
932
- }
933
- interface MarkerRef {
934
- /** Def id referenced via url(#...) — 'arrowhead', 'cls-inherit', ... */
935
- id: string;
936
- /** Marker archetype so styled backends can redraw without parsing defs. */
937
- shape: 'arrow' | 'open-arrow' | 'circle' | 'cross' | 'triangle' | 'diamond' | 'diamond-open';
938
- }
939
- interface ConnectorMark extends SceneNodeBase {
940
- kind: 'connector';
941
- geometry: {
942
- kind: 'polyline';
943
- points: Array<{
944
- x: number;
945
- y: number;
946
- }>;
947
- } | {
948
- kind: 'path';
949
- d: string;
950
- points?: Array<{
951
- x: number;
952
- y: number;
953
- }>;
954
- } | {
955
- kind: 'line';
956
- x1: number;
957
- y1: number;
958
- x2: number;
959
- y2: number;
960
- };
961
- lineStyle: 'solid' | 'dotted' | 'dashed' | 'thick' | 'invisible';
962
- paint: MarkPaint;
963
- startMarker?: MarkerRef;
964
- endMarker?: MarkerRef;
965
- }
966
- interface TextMark extends SceneNodeBase {
967
- kind: 'text';
968
- /** Unescaped source text (may contain <br> separators for multiline). */
969
- text: string;
970
- /** Anchor position the crisp emitter used. */
971
- x: number;
972
- y: number;
973
- fontSize: number;
974
- anchor: 'start' | 'middle' | 'end';
975
- paint: MarkPaint;
976
- }
977
- /** A semantic wrapper (<g ...>...</g>) whose children are scene nodes.
978
- * Serialization is reconstructed from open/close/children + per-child indent,
979
- * so styled backends can restyle children while keeping wrapper semantics
980
- * (classes, data-* attributes, ARIA) byte-compatible. */
981
- interface GroupMark extends SceneNodeBase {
982
- kind: 'group';
983
- open: string;
984
- close: string;
985
- children: Array<{
986
- node: SceneNode;
987
- indent: number;
988
- }>;
989
- /** Joiner between open/children/close segments; '\n' everywhere today. */
990
- join: string;
991
- }
992
- /** Escape hatch for chunks not yet lowered semantically (style blocks,
993
- * defs bodies, icon glyph stacks...). Styled backends pass these through or
994
- * replace them wholesale via their own prelude/defs policy — they must not
995
- * parse them. Aim to shrink raw usage over time. */
996
- interface RawMark extends SceneNodeBase {
997
- kind: 'raw';
998
- }
999
- /** Document prelude parameters — everything svgOpenTag/buildStyleBlock were
1000
- * called with, so a styled backend can re-derive its own document shell
1001
- * (different palette, fonts, backdrop) without string-parsing the crisp one. */
1002
- interface PreludeMark extends SceneNodeBase {
1003
- kind: 'prelude';
1004
- prelude: {
1005
- width: number;
1006
- height: number;
1007
- colors: DiagramColors;
1008
- transparent: boolean;
1009
- font: string;
1010
- hasMonoFont: boolean;
1011
- /** Family-specific extra CSS appended after the shared style block ('' if none). */
1012
- extraCss: string;
1013
- };
1014
- }
1015
- type SceneNode = ShapeMark | ConnectorMark | TextMark | GroupMark | RawMark | PreludeMark;
1016
- /** The lowered document: an ordered flat list of top-level marks. The crisp
1017
- * serialization is parts.map(crisp).join('\n') — exactly what the string
1018
- * renderers produced. */
1019
- interface SceneDoc {
1020
- family: string;
1021
- width: number;
1022
- height: number;
1023
- colors: DiagramColors;
1024
- parts: SceneNode[];
1025
- }
1026
-
1027
- interface StyleBackendContext {
1028
- /** User-supplied deterministic re-roll seed (RenderOptions.seed). */
1029
- seed: number;
1030
- /** The selected style (undefined on the crisp default path). */
1031
- style?: StyleSpec;
1032
- }
1033
- interface StyleBackend {
1034
- id: string;
1035
- /** Serialize one top-level mark (recursing through groups). */
1036
- drawNode(node: SceneNode, ctx: StyleBackendContext): string;
1037
- /** Serialize the whole document. */
1038
- render(doc: SceneDoc, ctx: StyleBackendContext): string;
1039
- }
1040
- declare const DefaultBackend: StyleBackend;
1041
- declare function registerBackend(backend: StyleBackend): void;
1042
- declare function getBackend(id: string): StyleBackend | undefined;
1043
-
1044
- declare function verifyNoExternalRefs(svg: string): {
1045
- ok: boolean;
1046
- refs: string[];
1047
- };
1048
- /**
1049
- * Render Mermaid diagram text to an SVG string — synchronously.
1050
- *
1051
- * Uses elk.bundled.js with a direct FakeWorker bypass (no setTimeout(0) delay).
1052
- * The ELK singleton is created lazily on first use and cached forever.
1053
- *
1054
- * Use this in React components with useMemo() to avoid flash:
1055
- * const svg = useMemo(() => renderMermaidSVG(code, opts), [code])
1056
- *
1057
- * @param text - Mermaid source text
1058
- * @param options - Rendering options (colors, font, spacing)
1059
- * @returns A self-contained SVG string
1060
- *
1061
- * @example
1062
- * ```ts
1063
- * const svg = renderMermaidSVG('graph TD\n A --> B')
1064
- *
1065
- * // With theme
1066
- * const svg = renderMermaidSVG('graph TD\n A --> B', {
1067
- * bg: '#1a1b26', fg: '#a9b1d6'
1068
- * })
1069
- *
1070
- * // With CSS variables (for live theme switching)
1071
- * const svg = renderMermaidSVG('graph TD\n A --> B', {
1072
- * bg: 'var(--background)', fg: 'var(--foreground)', transparent: true
1073
- * })
1074
- * ```
1075
- */
1076
- declare function renderMermaidSVG(text: string, options?: RenderOptions): string;
1077
- /**
1078
- * Render Mermaid diagram text to an SVG string — async.
1079
- *
1080
- * Same result as renderMermaidSVG() but returns a Promise.
1081
- * Useful in async contexts (server handlers, data loaders, etc.)
1082
- */
1083
- declare function renderMermaidSVGAsync(text: string, options?: RenderOptions): Promise<string>;
1084
- /** @deprecated Use `renderMermaidSVG` */
1085
- declare const renderMermaidSync: typeof renderMermaidSVG;
1086
- /** @deprecated Use `renderMermaidSVGAsync` */
1087
- declare const renderMermaid: typeof renderMermaidSVGAsync;
1088
-
1089
- export { type MermaidThemeVariables as $, type AsciiConfig as A, type TextMeasurementInput as B, type ColorMode as C, type Direction as D, type EdgeStyle as E, type FamilyEdgeRouteCertificate as F, type TextMeasurementResult as G, getStyle as H, inferBackend as I, knownStyles as J, measureText as K, type LayoutRouteCertificate as L, type MermaidFrontmatterMap as M, type NodeShape as N, measureTextWidth as O, type PositionedDiagram as P, registerStyle as Q, type RouteClass as R, type SceneDoc as S, TEXT_MEASUREMENT_CONTRACT as T, resolveStyleStack as U, validateStyleSpec as V, verifyNoExternalRefs as W, DEFAULTS as X, DefaultBackend as Y, type JourneyRuntimeConfig as Z, type MermaidRuntimeConfig as _, type MermaidConfigMap as a, type PositionedGraph as a0, type ResolvedColors as a1, type SceneNode as a2, type SceneRole as a3, type SemanticChannels as a4, type StyleBackend as a5, type StyleBackendContext as a6, THEMES as a7, type ThemeName as a8, type TimelineRuntimeConfig as a9, architectureToMermaidGraph as aa, fromShikiTheme as ab, getBackend as ac, inlineResolvedColors as ad, parseArchitectureDiagram as ae, parseMermaid as af, registerBackend as ag, renderMermaid as ah, renderMermaidAscii as ai, renderMermaidSVGAsync as aj, renderMermaidSync as ak, resolveColors as al, resolveDiagramColors as am, type MermaidGraph as b, type EdgeRouteCertificate as c, type RegionContainmentCertificate as d, type MermaidNode as e, type MermaidEdge as f, type NormalizedMermaidSource as g, type RenderOptions as h, type DiagramColors as i, type RenderContext as j, type AsciiTheme as k, type AsciiRenderOptions as l, renderMermaidSVG as m, type StyleInput as n, type AnyPort as o, type DiamondFacet as p, type FamilyRouteCertificate as q, renderMermaidASCII as r, type LayoutRouteClass as s, type PortSemanticRole as t, type PortSide as u, type RouteBlocker as v, type RouteCertificate as w, type RoutePortAssignment as x, type StyleSpec as y, type TextMeasurementContract as z };