agentic-mermaid 0.4.1 → 0.5.3
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.
- package/AGENT_NATIVE.md +94 -627
- package/CHANGELOG.md +651 -0
- package/Instructions_for_agents.md +44 -23
- package/LICENSES/Khroma-MIT.txt +21 -0
- package/LICENSES/Mermaid-MIT.txt +21 -0
- package/LICENSES/es-toolkit-MIT.txt +21 -0
- package/LICENSES/pele-MIT.txt +40 -0
- package/LICENSES/zenuml-core-MIT.txt +21 -0
- package/README.md +93 -50
- package/SECURITY.md +28 -12
- package/THIRD_PARTY_NOTICES.md +60 -0
- package/assets/hero.png +0 -0
- package/dist/agent-core.d.ts +478 -210
- package/dist/agent-core.js +1 -396
- package/dist/agent.d.ts +17 -8
- package/dist/agent.js +1 -408
- package/dist/agentic-mermaid-mcp.js +1 -11
- package/dist/am.js +1 -34562
- package/dist/browser-lazy/chunks/agentic-producer-core-CC6OOLDW.js +1 -0
- package/dist/browser-lazy/chunks/architecture-QUFVKYJR.js +13 -0
- package/dist/browser-lazy/chunks/block-6J3Q63BO.js +11 -0
- package/dist/browser-lazy/chunks/builtin-backends-7SOZZHPF.js +12 -0
- package/dist/browser-lazy/chunks/c4-SQVBZAKJ.js +10 -0
- package/dist/browser-lazy/chunks/chunk-2GPK4VFF.js +5 -0
- package/dist/browser-lazy/chunks/chunk-2I4UPL7Q.js +3 -0
- package/dist/browser-lazy/chunks/chunk-2SH76OTH.js +1 -0
- package/dist/browser-lazy/chunks/chunk-2UIA2IME.js +3 -0
- package/dist/browser-lazy/chunks/chunk-4LHYF3BS.js +1 -0
- package/dist/browser-lazy/chunks/chunk-5B2Z7575.js +1 -0
- package/dist/browser-lazy/chunks/chunk-5FQ534HP.js +1 -0
- package/dist/browser-lazy/chunks/chunk-5UVGUSD6.js +1 -0
- package/dist/browser-lazy/chunks/chunk-5X6MJX3H.js +1 -0
- package/dist/browser-lazy/chunks/chunk-AMJLVPUB.js +4 -0
- package/dist/browser-lazy/chunks/chunk-BU5LHXNJ.js +3 -0
- package/dist/browser-lazy/chunks/chunk-BY2CPG6B.js +1 -0
- package/dist/browser-lazy/chunks/chunk-CN7WTBWB.js +1 -0
- package/dist/browser-lazy/chunks/chunk-CQE4HQEW.js +1 -0
- package/dist/browser-lazy/chunks/chunk-CSFUKSU6.js +1 -0
- package/dist/browser-lazy/chunks/chunk-DF6765YX.js +17 -0
- package/dist/browser-lazy/chunks/chunk-E2WMJZNM.js +1 -0
- package/dist/browser-lazy/chunks/chunk-FAIMVOX5.js +6 -0
- package/dist/browser-lazy/chunks/chunk-GVOEAY52.js +1 -0
- package/dist/browser-lazy/chunks/chunk-HLWUNUCM.js +1 -0
- package/dist/browser-lazy/chunks/chunk-ICC7HBJX.js +1 -0
- package/dist/browser-lazy/chunks/chunk-J35HAQQF.js +20 -0
- package/dist/browser-lazy/chunks/chunk-J7FFAFQF.js +1 -0
- package/dist/browser-lazy/chunks/chunk-LH7HUDKW.js +1 -0
- package/dist/browser-lazy/chunks/chunk-N5ELX7LR.js +2 -0
- package/dist/browser-lazy/chunks/chunk-NMQQMRIR.js +1 -0
- package/dist/browser-lazy/chunks/chunk-NO7ZIVRU.js +1 -0
- package/dist/browser-lazy/chunks/chunk-OZ443IVJ.js +16 -0
- package/dist/browser-lazy/chunks/chunk-PQGPS2YV.js +7 -0
- package/dist/browser-lazy/chunks/chunk-QA6GJQ4X.js +1 -0
- package/dist/browser-lazy/chunks/chunk-RIVTHZAQ.js +1 -0
- package/dist/browser-lazy/chunks/chunk-SZELX2EJ.js +1 -0
- package/dist/browser-lazy/chunks/chunk-TYZOZXUJ.js +22 -0
- package/dist/browser-lazy/chunks/chunk-UL6NDWLL.js +1 -0
- package/dist/browser-lazy/chunks/chunk-VQYYGAXP.js +1 -0
- package/dist/browser-lazy/chunks/chunk-VWVZGQE2.js +1 -0
- package/dist/browser-lazy/chunks/chunk-X2UYKWKM.js +4 -0
- package/dist/browser-lazy/chunks/chunk-YCEICNM6.js +1 -0
- package/dist/browser-lazy/chunks/chunk-Z3FDIVLN.js +20 -0
- package/dist/browser-lazy/chunks/class-5QA4SCTS.js +13 -0
- package/dist/browser-lazy/chunks/decode-63UIZGD2.js +1 -0
- package/dist/browser-lazy/chunks/elk.bundled-L4CADV5W.js +24 -0
- package/dist/browser-lazy/chunks/er-7ZSKGN7Y.js +11 -0
- package/dist/browser-lazy/chunks/eventmodeling-2BPLHWRN.js +19 -0
- package/dist/browser-lazy/chunks/flowchart-NEIMZTB5.js +4 -0
- package/dist/browser-lazy/chunks/forest-implementation-AEP24AIP.js +1 -0
- package/dist/browser-lazy/chunks/gantt-RDPIFYAF.js +11 -0
- package/dist/browser-lazy/chunks/gitgraph-N4Y5RYB7.js +9 -0
- package/dist/browser-lazy/chunks/ishikawa-LD3YBDJN.js +6 -0
- package/dist/browser-lazy/chunks/journey-6YQR5DJX.js +16 -0
- package/dist/browser-lazy/chunks/kanban-PLMJ7NBW.js +20 -0
- package/dist/browser-lazy/chunks/mermaid-yaml-runtime-QVYX4EWK.js +136 -0
- package/dist/browser-lazy/chunks/mindmap-K2UBFO3Y.js +12 -0
- package/dist/browser-lazy/chunks/packet-CUW4QY6Y.js +7 -0
- package/dist/browser-lazy/chunks/pie-7F7UUCG3.js +15 -0
- package/dist/browser-lazy/chunks/quadrant-TOONO2WC.js +10 -0
- package/dist/browser-lazy/chunks/radar-J6JVWVAX.js +16 -0
- package/dist/browser-lazy/chunks/render-core-BZOM3K7D.js +3 -0
- package/dist/browser-lazy/chunks/requirement-CMAKDJPO.js +19 -0
- package/dist/browser-lazy/chunks/sankey-AWXQEP3F.js +13 -0
- package/dist/browser-lazy/chunks/sequence-Q2RJRB4L.js +5 -0
- package/dist/browser-lazy/chunks/state-WRBFQEDX.js +4 -0
- package/dist/browser-lazy/chunks/timeline-D2KILFXM.js +6 -0
- package/dist/browser-lazy/chunks/treemap-N3VYX5D4.js +6 -0
- package/dist/browser-lazy/chunks/xychart-G73OGK66.js +16 -0
- package/dist/browser-lazy/chunks/zenuml-H4BXNYXR.js +16 -0
- package/dist/browser-lazy/index.d.ts +544 -275
- package/dist/browser-lazy/index.js +1 -1
- package/dist/browser.global.js +802 -565
- package/dist/chunk-3LGLPG33.js +2 -0
- package/dist/chunk-7CRDX2QR.js +2 -0
- package/dist/chunk-7PPW2BMO.js +2 -0
- package/dist/chunk-DQDKA5ND.js +2 -0
- package/dist/chunk-EHCMJUMD.js +52 -0
- package/dist/chunk-GVCHLSHH.js +4 -0
- package/dist/chunk-H3NCS2XZ.js +19 -0
- package/dist/chunk-JZOJ4YGS.js +201 -0
- package/dist/chunk-MKE7GNYU.js +146 -0
- package/dist/chunk-NKNFOREZ.js +2 -0
- package/dist/chunk-O7H2UX5K.js +2 -0
- package/dist/chunk-OMY6NRQD.js +58 -0
- package/dist/chunk-UA234O4M.js +4 -0
- package/dist/chunk-VUFVLGTH.js +2 -0
- package/dist/chunk-XU5LPD2D.js +2 -0
- package/dist/cli-YGGTJZH7.js +226 -0
- package/dist/elk-constructor.js +2 -0
- package/dist/elk-constructor.node.js +11 -0
- package/dist/index-EeXqJXr5.d.ts +1223 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -334
- package/dist/jsonl-RPJY6YWO.js +2 -0
- package/dist/mcp-cli-63DYXTVD.js +2 -0
- package/dist/{index-BGA_-6LV.d.ts → paint-certification-6rwQjIv_.d.ts} +5283 -6173
- package/dist/server-5NEOHOFS.js +524 -0
- package/dist/svg-styles-BdnoM7AT.d.ts +724 -0
- package/dist/svg-styles.d.ts +1 -0
- package/dist/svg-styles.js +2 -0
- package/dist/svg.d.ts +13 -0
- package/dist/svg.js +2 -0
- package/dist/types-BcS52Mjt.d.ts +1360 -0
- package/dist/zenuml/chunks/appearance-UOQ5KA6O.js +1 -0
- package/dist/zenuml/chunks/builtin-backends-KDKE7YHO.js +12 -0
- package/dist/zenuml/chunks/chunk-42DXZ5C6.js +4 -0
- package/dist/zenuml/chunks/chunk-7TVYPTDW.js +1 -0
- package/dist/zenuml/chunks/chunk-EVPSMEKN.js +1 -0
- package/dist/zenuml/chunks/chunk-OXQWRSBM.js +20 -0
- package/dist/zenuml/chunks/chunk-QWX77U7G.js +2 -0
- package/dist/zenuml/chunks/chunk-RLJEI7YN.js +29 -0
- package/dist/zenuml/chunks/chunk-RZ6XK5CD.js +29 -0
- package/dist/zenuml/chunks/decode-BWERFDGK.js +1 -0
- package/dist/zenuml/chunks/mermaid-yaml-runtime-KZVU74WU.js +136 -0
- package/dist/zenuml/chunks/render-core-V5RQ737O.js +3 -0
- package/dist/zenuml/chunks/zenuml-EA2ZFRUX.js +20 -0
- package/dist/zenuml-frame.global.js +3626 -0
- package/dist/zenuml.d.ts +83 -0
- package/dist/zenuml.js +1 -0
- package/docs/MCP-DIRECTORY-LISTINGS.md +5 -1
- package/docs/README.md +59 -103
- package/docs/agent-api-cookbook.md +26 -16
- package/docs/agent-mutation-policy.md +86 -15
- package/docs/agent-workflow-examples.md +1 -1
- package/docs/api-advanced.md +385 -0
- package/docs/api.md +320 -366
- package/docs/ascii.md +40 -4
- package/docs/browser.md +46 -7
- package/docs/choosing-a-diagram.md +148 -0
- package/docs/code-mode-impact.md +1 -0
- package/docs/comparison.md +244 -28
- package/docs/computational-aesthetics-prototype-plan.md +10 -10
- package/docs/config.md +60 -2
- package/docs/custom-fonts.md +78 -21
- package/docs/diagram-families.md +160 -10
- package/docs/eventmodeling-and-zenuml.md +165 -0
- package/docs/features.md +21 -19
- package/docs/fork-differences.md +105 -32
- package/docs/getting-started.md +56 -51
- package/docs/layout-certification.md +126 -0
- package/docs/mcp-code-mode-rationale.md +20 -12
- package/docs/mcp-http-transport.md +14 -8
- package/docs/quality.md +145 -15
- package/docs/react.md +76 -31
- package/docs/style-authoring.md +23 -11
- package/docs/svg-semantic-contract.md +104 -4
- package/docs/testing-strategy.md +684 -126
- package/docs/theming.md +27 -8
- package/examples/styles/readme-hero.md +25 -0
- package/examples/styles/readme-hero.mmd +13 -0
- package/examples/styles/readme-hero.style.json +7 -0
- package/package.json +114 -57
- package/server.json +2 -2
- package/skills/agentic-mermaid-diagram-workflow/SKILL.md +26 -8
- package/skills/agentic-mermaid-diagram-workflow/references/cli.md +13 -3
- package/skills/agentic-mermaid-diagram-workflow/references/code-mode.md +2 -1
- package/skills/agentic-mermaid-diagram-workflow/references/flowchart.md +9 -6
- package/skills/agentic-mermaid-diagram-workflow/references/hosted-mcp.md +1 -0
- package/skills/agentic-mermaid-diagram-workflow/references/sequence.md +4 -3
- package/skills/agentic-mermaid-diagram-workflow/references/timeline.md +7 -6
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/agentflow.md +574 -0
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/architecture.md +10 -2
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/c4.md +18 -0
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/classDiagram.md +123 -0
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/cynefin.md +6 -1
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/entityRelationshipDiagram.md +129 -9
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/eventmodeling.md +22 -0
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/flowchart.md +188 -60
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/gitgraph.md +13 -7
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/mindmap.md +110 -1
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/packet.md +38 -0
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/requirementDiagram.md +115 -0
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/sequenceDiagram.md +101 -0
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/stateDiagram.md +87 -0
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/swimlanes.md +105 -2
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/timeline.md +12 -6
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/usecase.md +953 -0
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/venn.md +77 -0
- package/skills/agentic-mermaid-diagram-workflow/references/upstream/xyChart.md +1 -1
- package/dist/browser-lazy/chunks/architecture-KTHE2HX3.js +0 -31
- package/dist/browser-lazy/chunks/chunk-2XCPFAD5.js +0 -46
- package/dist/browser-lazy/chunks/chunk-3H4F7RBT.js +0 -1
- package/dist/browser-lazy/chunks/chunk-4EVLW2NJ.js +0 -1
- package/dist/browser-lazy/chunks/chunk-5Q4S74UO.js +0 -1
- package/dist/browser-lazy/chunks/chunk-6OAPWSDO.js +0 -1
- package/dist/browser-lazy/chunks/chunk-A7L4WWVW.js +0 -143
- package/dist/browser-lazy/chunks/chunk-C7FJO2I3.js +0 -4
- package/dist/browser-lazy/chunks/chunk-D3XXDKIO.js +0 -1
- package/dist/browser-lazy/chunks/chunk-DXA5WL7H.js +0 -4
- package/dist/browser-lazy/chunks/chunk-EPFMQPXX.js +0 -1
- package/dist/browser-lazy/chunks/chunk-FFOHLPDA.js +0 -2
- package/dist/browser-lazy/chunks/chunk-FLD63DXE.js +0 -2
- package/dist/browser-lazy/chunks/chunk-G6OLSHRG.js +0 -7
- package/dist/browser-lazy/chunks/chunk-GRXCKTHX.js +0 -0
- package/dist/browser-lazy/chunks/chunk-I6VE56S7.js +0 -1
- package/dist/browser-lazy/chunks/chunk-KJVNXJ5Y.js +0 -1
- package/dist/browser-lazy/chunks/chunk-L227EPFP.js +0 -11
- package/dist/browser-lazy/chunks/chunk-LNIHDJSF.js +0 -1
- package/dist/browser-lazy/chunks/chunk-M6BT2HIP.js +0 -1
- package/dist/browser-lazy/chunks/chunk-NZRUMODH.js +0 -1
- package/dist/browser-lazy/chunks/chunk-OFRMKQA6.js +0 -1
- package/dist/browser-lazy/chunks/chunk-P7HMSKHJ.js +0 -1
- package/dist/browser-lazy/chunks/chunk-PXKL3O6H.js +0 -1
- package/dist/browser-lazy/chunks/chunk-PZEWZT35.js +0 -1
- package/dist/browser-lazy/chunks/chunk-STQRDZ67.js +0 -1
- package/dist/browser-lazy/chunks/chunk-SUFMSWTX.js +0 -1
- package/dist/browser-lazy/chunks/chunk-T7IJ6V4B.js +0 -3
- package/dist/browser-lazy/chunks/chunk-UAEZO5VL.js +0 -1
- package/dist/browser-lazy/chunks/chunk-WEUWIFG3.js +0 -1
- package/dist/browser-lazy/chunks/chunk-X64T74C5.js +0 -24
- package/dist/browser-lazy/chunks/class-F7R6TJ73.js +0 -9
- package/dist/browser-lazy/chunks/er-BDK7CM5L.js +0 -9
- package/dist/browser-lazy/chunks/flowchart-KFU6XV7S.js +0 -4
- package/dist/browser-lazy/chunks/gantt-I64VVDSP.js +0 -28
- package/dist/browser-lazy/chunks/gitgraph-EDUVJ5IJ.js +0 -8
- package/dist/browser-lazy/chunks/journey-TLO2RNM3.js +0 -40
- package/dist/browser-lazy/chunks/mindmap-OJCNDYPM.js +0 -9
- package/dist/browser-lazy/chunks/pie-HVG6XO7K.js +0 -19
- package/dist/browser-lazy/chunks/quadrant-U6S2L4MJ.js +0 -24
- package/dist/browser-lazy/chunks/radar-ZDLOBTVG.js +0 -32
- package/dist/browser-lazy/chunks/render-core-Y2DFNMQG.js +0 -12
- package/dist/browser-lazy/chunks/sequence-Z4WFS3VB.js +0 -12
- package/dist/browser-lazy/chunks/state-2HV2YGN3.js +0 -4
- package/dist/browser-lazy/chunks/timeline-XM4UFPOC.js +0 -20
- package/dist/browser-lazy/chunks/xychart-7JDHWTQY.js +0 -36
- package/dist/chunk-GGXCNCNA.js +0 -4118
- package/dist/chunk-IVD4NXNE.js +0 -615
- package/dist/chunk-JDMRPUAG.js +0 -37
- package/dist/chunk-JWAAW3FH.js +0 -149
- package/dist/chunk-LCGBT32P.js +0 -62036
- package/dist/chunk-RWMZRUIC.js +0 -4715
- package/dist/mcp-cli-4MLKC3ZH.js +0 -17
- package/docs/mutation-testing.md +0 -285
package/docs/api.md
CHANGED
|
@@ -1,418 +1,372 @@
|
|
|
1
|
-
# API
|
|
1
|
+
# Library API
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Render artifacts, read painted geometry, or edit Mermaid source with typed operations.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- `agentic-mermaid/agent` — agent-native API with
|
|
8
|
-
parse/narrow/mutate/verify/serialize plus SVG, native Node/Bun PNG, and ASCII
|
|
9
|
-
output helpers.
|
|
10
|
-
- `agentic-mermaid/agent/core` — the same structured-edit, SVG, and ASCII
|
|
11
|
-
surface without the native PNG dependency; use this entry in browser and
|
|
12
|
-
workerd bundles.
|
|
5
|
+
```ts
|
|
6
|
+
import { renderMermaidSVG } from 'agentic-mermaid'
|
|
13
7
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
const source = 'flowchart LR\n Idea --> Ship'
|
|
9
|
+
const svg = renderMermaidSVG(source, { style: ['hand-drawn', 'nord'] })
|
|
10
|
+
console.log(svg)
|
|
11
|
+
```
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
Use `agentic-mermaid/agent/core` when the target runtime cannot load Node native
|
|
20
|
-
addons.
|
|
13
|
+
Choose the task, then use the matching surface:
|
|
21
14
|
|
|
22
|
-
|
|
15
|
+
| Task | Start here | Result |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| Render an artifact | [Rendering](#rendering) | SVG, PNG bytes, or terminal text |
|
|
18
|
+
| Draw or animate the artwork yourself | [Resolved paths and text](#resolved-paths-and-text) | JSON with painted paths, text, transforms and semantic parts |
|
|
19
|
+
| Change existing source | [Editing](#editing) | A typed edit, verification findings and serialized Mermaid |
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
the existing convenience return types:
|
|
21
|
+
Agents with a shell can use `am capabilities --json` and `am styles --json` to
|
|
22
|
+
discover installed support. In MCP, use `describe_sdk` for mutation fields and
|
|
23
|
+
`execute` for the documented Code Mode functions. Resolved scenes are currently
|
|
24
|
+
available from the main library entry only, not Code Mode.
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
import {
|
|
32
|
-
renderMermaidASCIIWithReceipt,
|
|
33
|
-
renderMermaidPNGWithReceipt,
|
|
34
|
-
renderMermaidSVGWithReceipt,
|
|
35
|
-
} from 'agentic-mermaid/agent'
|
|
36
|
-
|
|
37
|
-
const options = { style: 'hand-drawn', seed: 7, embedFontImport: false }
|
|
38
|
-
const svg = renderMermaidSVGWithReceipt(source, options)
|
|
39
|
-
const png = renderMermaidPNGWithReceipt(source, options)
|
|
40
|
-
const text = renderMermaidASCIIWithReceipt(source, { ...options, colorMode: 'none' })
|
|
41
|
-
|
|
42
|
-
console.assert(svg.receipt.sharedRequestDigest === png.receipt.sharedRequestDigest)
|
|
43
|
-
console.assert(svg.receipt.appearanceDigest === text.receipt.appearanceDigest)
|
|
44
|
-
```
|
|
26
|
+
## Vocabulary
|
|
45
27
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
compatibility, applicability, projection, and output-policy decisions. In
|
|
50
|
-
particular, `RENDER_OPTION_NOT_APPLICABLE` makes an authored family-scoped
|
|
51
|
-
option that the selected family does not consume observable instead of letting
|
|
52
|
-
it change request identity silently. CLI JSON results and local/hosted MCP
|
|
53
|
-
render results expose the same receipt. Use `validateSerializableRenderOptions(value)` and
|
|
54
|
-
`sharedRenderOptionsJsonSchema()` for untrusted advanced option objects, or
|
|
55
|
-
`styleInputJsonSchema()` for a standalone convenience `style` field; unknown
|
|
56
|
-
fields, `null`, functions, prototype keys, and non-finite values are rejected.
|
|
28
|
+
<!-- BEGIN GENERATED: diagram-terminology -->
|
|
29
|
+
A **family** is a Mermaid diagram type, such as Flowchart or Sequence. A **part** is an identified element of a Scene, such as a shape, connector, text or group. A **resolved primitive** is one painted path or text run; a part can contain many primitives. A **Scene primitive** is a unit of the pre-paint drawing contract, including document structure, shapes, text and markers. Source nodes, edges and other family-specific objects are distinct from drawing parts.
|
|
30
|
+
<!-- END GENERATED: diagram-terminology -->
|
|
57
31
|
|
|
58
|
-
|
|
32
|
+
<!-- BEGIN GENERATED: family-narrowing -->
|
|
33
|
+
Narrowing selects a structured, typed family with an as* helper. It does not select one element or freeze layout coordinates.
|
|
34
|
+
<!-- END GENERATED: family-narrowing -->
|
|
59
35
|
|
|
60
|
-
|
|
36
|
+
The API names stay specific to their layer:
|
|
61
37
|
|
|
62
|
-
|
|
63
|
-
|
|
38
|
+
| API name | Meaning |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `ParsedDiagram.kind`, `DiagramKind` | The source family discriminator. Other `kind` fields discriminate operations, Scene parts or resolved primitives. |
|
|
41
|
+
| `SceneNode`, `ShapeMark`, `ConnectorMark`, `TextMark`, `GroupMark` | Existing type names for Scene parts. A Scene node is not necessarily a source node; **mark** in these names means part. |
|
|
42
|
+
| `ResolvedPart.node` | The semantic Scene part paired with its backend-painted `primitives`. |
|
|
43
|
+
| `ResolvedPrimitive` | `ResolvedPath` or `ResolvedText`, after backend painting. |
|
|
44
|
+
| `ScenePrimitive`, `Geometry` | Scene primitive capability names and geometry, before backend painting. These are not `ResolvedPrimitive`. |
|
|
45
|
+
|
|
46
|
+
A **marker** decorates a path or connector at its start, end or interior
|
|
47
|
+
vertices, such as an arrowhead; it is distinct from the older word *mark*.
|
|
48
|
+
Use source-facing IDs for source objects and Scene IDs for parts. One source
|
|
49
|
+
object can produce several parts, and one part can produce several painted
|
|
50
|
+
primitives. Resolved primitives have no independent stable IDs. Entries in
|
|
51
|
+
`part.primitives` are associated through that part and its source-facing
|
|
52
|
+
identity where available. Entries in `scene.frame` have no containing part
|
|
53
|
+
or independent stable IDs.
|
|
54
|
+
The resolved-scene API's separate `marker-mid` limitation still applies.
|
|
55
|
+
|
|
56
|
+
## Versions
|
|
57
|
+
|
|
58
|
+
<!-- BEGIN GENERATED: api-versions -->
|
|
59
|
+
This reference describes source version **0.5.3**. The latest release recorded in the [changelog](../CHANGELOG.md) is **0.5.3** (2026-10-29). [Read that version's reference](https://github.com/adewale/agentic-mermaid/blob/v0.5.3/docs/api.md). Changes under **Unreleased**, including new exports, are not part of that recorded release.
|
|
60
|
+
<!-- END GENERATED: api-versions -->
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
```bash
|
|
63
|
+
npm ls agentic-mermaid
|
|
64
|
+
npm view agentic-mermaid version
|
|
67
65
|
```
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
The first command shows the installed version; the second asks npm for its
|
|
68
|
+
current release. For released APIs, read documentation at the release's Git tag.
|
|
69
|
+
A source checkout and successful build do not establish publication.
|
|
70
|
+
|
|
71
|
+
## Imports and runtimes
|
|
72
|
+
|
|
73
|
+
| Import | Use it for | Runtime |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| `agentic-mermaid` | SVG, ASCII/Unicode, resolved scenes and styles | Node, Bun, browsers and Workers; no native PNG addon imported |
|
|
76
|
+
| `agentic-mermaid/agent/core` | Parsing, typed editing, verification, layout, SVG and terminal rendering | Node, Bun, browsers and Workers |
|
|
77
|
+
| `agentic-mermaid/agent` | The agent/core operations plus native PNG | Node or Bun |
|
|
78
|
+
| `agentic-mermaid/browser/lazy` | `renderMermaidSVGAsync` with families loaded on demand | Browser ESM |
|
|
79
|
+
|
|
80
|
+
Use `/agent/core` for runtime-neutral editing and `/agent` when you also need
|
|
81
|
+
native PNG. The synchronous browser bundle is `agentic-mermaid/browser`.
|
|
82
|
+
Host-injected browser PNG is covered in the [advanced reference](./api-advanced.md#trusted-host-selected-graphical-backends).
|
|
83
|
+
|
|
84
|
+
## Rendering
|
|
72
85
|
|
|
73
|
-
|
|
86
|
+
These functions accept source text or a `ParsedDiagram` returned by
|
|
87
|
+
`parseRegisteredMermaid`. Parsing first is optional for artifact-only tasks.
|
|
88
|
+
Rendering is synchronous except for explicit async and browser PNG helpers.
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
renderMermaidSVG(input: ParsedDiagram | string, options?: RenderOptions): string
|
|
92
|
+
renderMermaidASCII(input: ParsedDiagram | string, options?: AsciiRenderOptions): string
|
|
93
|
+
renderMermaidPNG(input: ParsedDiagram | string, options?: PngOptions): Uint8Array
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
| Function | Return value | Notes |
|
|
97
|
+
|---|---|---|
|
|
98
|
+
| `renderMermaidSVG` | One SVG document string | `idPrefix` separates resource IDs when embedding several diagrams. |
|
|
99
|
+
| `renderMermaidASCII` | Terminal text | Unicode by default; `{ useAscii: true }` selects seven-bit ASCII. |
|
|
100
|
+
| `renderMermaidPNG` | PNG bytes | Import from `/agent`. Use `scale` or `fitTo` for size. |
|
|
101
|
+
| `renderMermaidSVGWithReceipt` | `{ svg, receipt }` | Adds request identity and diagnostics. |
|
|
102
|
+
| `renderMermaidASCIIWithMeta` | `{ ascii, regions, actions, warnings, routeParity }` | Import from `/agent/core` or `/agent` for element/cell mapping. |
|
|
103
|
+
| `renderMermaidWithActions` | Artifact and inert action regions | Import from `/agent` for SVG, PNG, ASCII or Unicode interaction metadata. |
|
|
74
104
|
|
|
75
105
|
```ts
|
|
76
106
|
import { writeFileSync } from 'node:fs'
|
|
77
107
|
import { renderMermaidPNG } from 'agentic-mermaid/agent'
|
|
78
108
|
|
|
79
|
-
const png = renderMermaidPNG(
|
|
80
|
-
|
|
81
|
-
fitTo: { width: 1200 },
|
|
82
|
-
background: '#fff',
|
|
109
|
+
const png = renderMermaidPNG('flowchart LR\n Idea --> Ship', {
|
|
110
|
+
fitTo: { width: 1200 }, background: '#ffffff',
|
|
83
111
|
})
|
|
84
|
-
|
|
85
112
|
writeFileSync('diagram.png', png)
|
|
86
113
|
```
|
|
87
114
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
accept the same parsed-or-source input contract; an unregistered preserved
|
|
92
|
-
envelope round-trips exactly and returns its stable capability diagnostic rather
|
|
93
|
-
than falling through to Flowchart.
|
|
115
|
+
Use the same render options for verification and rendering. A style can affect
|
|
116
|
+
layout and typography as well as paint. Changing `seed` rerolls styled ink
|
|
117
|
+
without changing the semantic layout.
|
|
94
118
|
|
|
95
|
-
|
|
96
|
-
canonical machine-readable field set is returned by
|
|
97
|
-
`sharedRenderOptionsJsonSchema()`; the table below contains only PNG-specific
|
|
98
|
-
controls:
|
|
119
|
+
### Graph layout selection
|
|
99
120
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
| `background` | `string` | artifact background, then white | Portable on the same surfaces. Safe explicit PNG background color. |
|
|
104
|
-
| `fitTo` | `{ width?: number; height?: number }` | — | Portable on the same surfaces. Constrain output to exactly one positive width or height. |
|
|
105
|
-
| `fontDirs` | `string[]` | — | Trusted native-host input: Node/Bun library, CLI, and local MCP only. Extra font directories for unbundled families and scripts the bundled fonts do not cover. CLI: `--font-dirs <dirs>` (comma-separated). |
|
|
106
|
-
| `loadSystemFonts` | `boolean` | `false` | Trusted native-host input on the same native surfaces. Trades cross-machine determinism for glyph coverage. CLI: `--system-fonts`. |
|
|
107
|
-
| `onWarning` | `(w: PngFontWarning) => void` | stderr | Native library callback only. Receives `PNG_FONT_COVERAGE` warnings; callbacks never enter serializable requests or receipts. |
|
|
108
|
-
|
|
109
|
-
PNG rasterization uses offline `@resvg/resvg-js` with bundled fonts for
|
|
110
|
-
deterministic same-machine output: Inter (the default face — the same family
|
|
111
|
-
the SVG requests and the family `src/text-metrics.ts` is calibrated for, so
|
|
112
|
-
rasterized labels match their measured boxes), DejaVu Sans as a per-glyph
|
|
113
|
-
fallback for symbols Inter lacks, plus the faces the built-in styles
|
|
114
|
-
reference (Caveat, EB Garamond, Architects Daughter, Share Tech Mono — see
|
|
115
|
-
`assets/fonts/FONT-LICENSES.md`). A style whose `font` is neither bundled
|
|
116
|
-
nor supplied via `fontDirs` rasterizes with Inter. Characters no loaded font
|
|
117
|
-
covers (CJK, most emoji) draw as tofu boxes and raise a `PNG_FONT_COVERAGE`
|
|
118
|
-
warning naming the script and the escape hatches (`fontDirs` /
|
|
119
|
-
`loadSystemFonts`).
|
|
120
|
-
Note for third-party rasterizers: the SVG declares fonts as
|
|
121
|
-
`font-family: var(--font, 'Face')`, and static rasterizers (resvg, librsvg)
|
|
122
|
-
do not resolve CSS custom properties — `renderMermaidPNG` inlines the
|
|
123
|
-
resolved family before rasterizing; do the same if you feed the raw SVG to
|
|
124
|
-
your own pipeline.
|
|
125
|
-
|
|
126
|
-
For complete custom-Style recipes using `font`, `fontDirs`, browser faces, and
|
|
127
|
-
SVG font declarations, see [Fonts in custom styles](./custom-fonts.md).
|
|
128
|
-
|
|
129
|
-
PNG output declares the shared sRGB policy with `sRGB` and `cICP` metadata,
|
|
130
|
-
places `cICP` before image data, and deliberately emits no conflicting ICC
|
|
131
|
-
profile. SVG and PNG consume the same resolved graphical colors before
|
|
132
|
-
rasterization.
|
|
133
|
-
|
|
134
|
-
#### Trusted host-selected graphical backends
|
|
135
|
-
|
|
136
|
-
Executable backends are bound by the host, never selected by `RenderOptions` or
|
|
137
|
-
serialized Style data. These factories apply the same canonical request,
|
|
138
|
-
Scene-admission, SVG-security, receipt, PNG-output-policy, and color-profile
|
|
139
|
-
contracts as their default counterparts:
|
|
121
|
+
Omitting `graphLayout` retains the existing automatic policy, including the
|
|
122
|
+
guarded forest optimization. Force ELK with `graphLayout: { backend: 'elk' }`,
|
|
123
|
+
or opt into the owned producer:
|
|
140
124
|
|
|
141
125
|
```ts
|
|
142
|
-
import {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const backendPolicy = { selectBackend: () => 'backend:acme/renderer' }
|
|
149
|
-
const svgRenderer = createMermaidRenderer({ backendPolicy })
|
|
150
|
-
const nodePngRenderer = createMermaidPNGRenderer({ backendPolicy })
|
|
151
|
-
const browserPngRenderer = createMermaidBrowserPNGRenderer({
|
|
152
|
-
backendPolicy,
|
|
153
|
-
rasterize: async (securedSvg, context) => ({
|
|
154
|
-
png: await rasterizeWithCanvas(securedSvg, context.outputPolicy),
|
|
155
|
-
}),
|
|
126
|
+
import { renderMermaidSVGWithReceipt } from 'agentic-mermaid'
|
|
127
|
+
|
|
128
|
+
const source = 'flowchart LR; Idea --> Ship'
|
|
129
|
+
const { svg, receipt } = renderMermaidSVGWithReceipt(source, {
|
|
130
|
+
graphLayout: { backend: 'agentic', fallback: 'elk' },
|
|
156
131
|
})
|
|
132
|
+
console.log(receipt.layoutDecisions)
|
|
157
133
|
```
|
|
158
134
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
135
|
+
Agentic currently supports measured Flowchart and State graphs, including directed
|
|
136
|
+
cycles, self-loops, shapes and edge labels, fan-in, parallel edges, disconnected
|
|
137
|
+
components and long links. Independent nested scopes retain frame endpoints,
|
|
138
|
+
headers and local directions, including State composites and concurrent regions. State pseudostates, configured fork/join dimensions and notes
|
|
139
|
+
use the shared family sizing and projection rules.
|
|
140
|
+
The shared geometry pipeline clips ports to each actual shape outline.
|
|
141
|
+
Bounded cross-hierarchy leaf and frame routes retain authored endpoints, and
|
|
142
|
+
empty frames retain measured headers. Class cards/namespaces, ER frames and
|
|
143
|
+
relations, Requirement cards, and Architecture compounds use the owned kernel
|
|
144
|
+
with their specialized family geometry. Architecture applies final authored
|
|
145
|
+
side constraints and routing after placement. Unsupported hints and constraints, overlapping
|
|
146
|
+
node/frame identities, and exhausted bounded searches still decline explicitly. ELK support remains available for every existing
|
|
147
|
+
ELK family. Omitting fallback makes an unsupported Agentic request throw
|
|
148
|
+
`GraphLayoutUnsupportedError`; requesting `fallback: 'elk'` records the actual
|
|
149
|
+
selection in `layoutDecisions` and emits a fallback diagnostic. An ELK fallback
|
|
150
|
+
is not an Agentic completion. Unexpected engine defects and global work limits
|
|
151
|
+
are not hidden by fallback.
|
|
152
|
+
|
|
153
|
+
The async `agentic-mermaid/browser/lazy` entry downloads ELK only when the
|
|
154
|
+
selected layout actually needs it. A successful strict Agentic render does not
|
|
155
|
+
fetch ELK; requested fallback still loads it when native placement declines.
|
|
156
|
+
ELK selection likewise leaves the native solver unfetched. Backend payload
|
|
157
|
+
reports include the selected solver's dynamic dependencies.
|
|
158
|
+
The synchronous `agentic-mermaid/browser` entry remains an all-in-one bundle.
|
|
159
|
+
|
|
160
|
+
The CLI accepts `am render diagram.mmd --graph-layout agentic
|
|
161
|
+
--graph-layout-fallback elk`. Mermaid source configuration is preserved and is
|
|
162
|
+
not an alias for these options. Terminal-cell placement retains its family
|
|
163
|
+
rules; optional graphical companions and Architecture's pixel placement honor
|
|
164
|
+
the selector. See the [backend design](https://github.com/adewale/agentic-mermaid/blob/ce240587211b90395a820115d2503b73bf5ff4e3/docs/design/system/layout-backends.md) for
|
|
165
|
+
qualification and comparative measurement.
|
|
166
|
+
|
|
167
|
+
## Resolved paths and text
|
|
168
|
+
|
|
169
|
+
Use this API when another renderer needs the artwork AM actually drew,
|
|
170
|
+
including sketch strokes, expanded markers and multiline text runs.
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
renderResolvedScene(input: ParsedDiagram | string, options?: RenderOptions): ResolvedScene
|
|
174
|
+
```
|
|
169
175
|
|
|
170
176
|
```ts
|
|
171
|
-
import {
|
|
177
|
+
import { renderResolvedScene } from 'agentic-mermaid'
|
|
172
178
|
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
179
|
+
const scene = renderResolvedScene('flowchart LR\n Idea --> Ship', { style: 'hand-drawn' })
|
|
180
|
+
for (const part of scene.parts) {
|
|
181
|
+
console.log(part.id, part.node.identity, part.primitives)
|
|
182
|
+
}
|
|
177
183
|
```
|
|
178
184
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
`
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
`
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
`
|
|
206
|
-
`
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|---|---|---|---|---|---|
|
|
222
|
-
| `bg` | `string` | `#FFFFFF` | Background color or CSS variable. | all | consumed |
|
|
223
|
-
| `fg` | `string` | `#27272A` | Primary foreground and text color. | all | consumed |
|
|
224
|
-
| `line` | `string` | derived | Connector and secondary-line color. | all | consumed |
|
|
225
|
-
| `accent` | `string` | derived | Arrowhead, highlight, and data accent color. | all | consumed |
|
|
226
|
-
| `muted` | `string` | derived | Secondary text and label color. | all | projected — terminal themes have no dedicated muted-text role |
|
|
227
|
-
| `surface` | `string` | derived | Node and group surface color. | all | projected — terminal cells do not paint graphical surfaces |
|
|
228
|
-
| `border` | `string` | derived | Node and group border color. | all | consumed |
|
|
229
|
-
| `font` | `string` | `Inter` | CSS font family or stack. | all | projected — the host terminal owns the font face |
|
|
230
|
-
| `style` | `StyleInput \| StyleInput[]` | `crisp` | Registered Style/Palette name, inline StyleSpec, or left-to-right stack. | all | consumed |
|
|
231
|
-
| `padding` | `number` | `40` | Canvas padding in SVG user units. | flowchart, state, architecture | not-applicable — terminal output uses paddingX, paddingY, and boxBorderPadding |
|
|
232
|
-
| `nodeSpacing` | `number` | `24` | Horizontal spacing between sibling nodes. | flowchart, state, class, er, architecture | not-applicable — terminal layout has a cell-grid spacing contract |
|
|
233
|
-
| `layerSpacing` | `number` | `40` | Vertical spacing between graph layers. | flowchart, state, class, er, architecture | not-applicable — terminal layout has a cell-grid spacing contract |
|
|
234
|
-
| `wrappingWidth` | `number` | unset | Flowchart measured-label wrapping budget in pixels. | flowchart | not-applicable — terminal output uses maxWidth or targetWidth |
|
|
235
|
-
| `componentSpacing` | `number` | extension-defined | Spacing between disconnected graph components for compatible extension families; no built-in family currently consumes it. | none — extension-defined | not-applicable — terminal layout has a cell-grid spacing contract |
|
|
236
|
-
| `transparent` | `boolean` | `false` | Omit the painted SVG canvas background. | all | projected — terminal output has no painted canvas background |
|
|
237
|
-
| `interactive` | `boolean` | `false` | Enable hover tooltips for supported chart data points. | xychart, pie, quadrant | projected — terminal output is a static semantic projection |
|
|
238
|
-
| `shadow` | `boolean` | `false` | Paint explicit drop shadows on node shapes. | flowchart, state, sequence, timeline, class, er, journey, xychart, pie, quadrant, gantt, mindmap, gitgraph | projected — elevation projects to borders and labels |
|
|
239
|
-
| `class` | `{ hierarchicalNamespaces?: boolean }` | `hierarchicalNamespaces: true` | Class-diagram rendering controls. | class | not-applicable — this option configures graphical class layout |
|
|
240
|
-
| `architecture` | `{ visual?: ArchitectureVisualOverrides }` | built-in metrics | Sparse architecture renderer visual metric and paint overrides. | architecture | not-applicable — this option configures graphical architecture rendering |
|
|
241
|
-
| `timeline` | `{ maxWidth?: number }` | `maxWidth`: unset | Timeline layout controls. | timeline | not-applicable — terminal output uses maxWidth or targetWidth |
|
|
242
|
-
| `journey` | `{ experienceCurve?: boolean }` | `experienceCurve: true` | User-journey graphical controls. | journey | not-applicable — experience curves are graphical-only |
|
|
243
|
-
| `gantt` | `{ dependencyArrows?: boolean; criticalPath?: boolean }` | both `false` | Gantt dependency and critical-path overlays. | gantt | not-applicable — graphical Gantt connector emphasis is not represented in cells |
|
|
244
|
-
| `mermaidConfig` | `MermaidRuntimeConfig` | source config | Mermaid-style recursive runtime configuration. | all | consumed |
|
|
245
|
-
| `embedFontImport` | `boolean` | `false` | Embed the Google Fonts import in SVG styles; PNG forces this off for offline rasterization. | all | not-applicable — terminal output embeds no web-font import |
|
|
246
|
-
| `compact` | `boolean` | `false` | Compact SVG serialization while preserving agent hooks. | all | not-applicable — compact controls SVG serialization |
|
|
247
|
-
| `idPrefix` | `string` | unset | Non-empty namespace for generated SVG definition IDs and local references. | all | not-applicable — terminal output has no SVG definition ids |
|
|
248
|
-
| `security` | `'default' \| 'strict'` | `default` | Active SVG content is rejected in every mode; strict additionally rejects every external reference. Raw Mermaid themeCSS is rejected in both modes. | all | not-applicable — terminal text has its own control-character and HTML-color safety projection |
|
|
249
|
-
| `ganttToday` | `string` | unset | Explicit deterministic date for the Gantt today marker. | gantt | consumed |
|
|
250
|
-
| `seed` | `number` | `0` | Deterministic re-roll seed for stochastic Styles. | all | not-applicable — terminal glyph geometry is deterministic and has no stochastic ink |
|
|
251
|
-
<!-- END GENERATED SHARED RENDER OPTIONS -->
|
|
252
|
-
|
|
253
|
-
`Built-in families: all` means the field is family-neutral. `none —
|
|
254
|
-
extension-defined` means no built-in currently consumes it. An external
|
|
255
|
-
`FamilyDescriptor` opts into any family-scoped field it consumes through its
|
|
256
|
-
frozen `applicableRenderOptions` array; an omitted or empty declaration means
|
|
257
|
-
none, and authored values receive `RENDER_OPTION_NOT_APPLICABLE` in the render
|
|
258
|
-
receipt.
|
|
259
|
-
|
|
260
|
-
`onConfigDiagnostic?: (diagnostic: ConfigDiagnostic) => void` is deliberately
|
|
261
|
-
outside the serializable field set. Library callers can collect qualified
|
|
262
|
-
`INEFFECTIVE_CONFIG` warnings without changing output bytes; CLI, MCP, editor,
|
|
263
|
-
and JSON Schema surfaces return diagnostics as data instead of accepting a
|
|
264
|
-
function.
|
|
265
|
-
|
|
266
|
-
### SVG semantic identity and accessibility
|
|
267
|
-
|
|
268
|
-
All built-in families expose the same inspectable element contract:
|
|
269
|
-
|
|
270
|
-
- every source-semantic Scene mark has a deterministic `data-id` and closed
|
|
271
|
-
`data-role`; identity is unique within one SVG (layout furniture retains typed
|
|
272
|
-
Scene identity without bloating the DOM);
|
|
273
|
-
- source relations use `data-from` and `data-to`; source `className` tokens stay
|
|
274
|
-
on the identified element's `class` attribute;
|
|
275
|
-
- typed relations expose `role="graphics-symbol"`,
|
|
276
|
-
`aria-roledescription="relation"`, and an `aria-label` derived from endpoints
|
|
277
|
-
plus the authored relation label;
|
|
278
|
-
- public Scene types expose `SvgSemanticIdentity`,
|
|
279
|
-
`SvgSemanticAccessibility`, and `SvgRelationSemantics`;
|
|
280
|
-
- `idPrefix` rewrites local DOM `id` references, not source-facing `data-id`.
|
|
281
|
-
|
|
282
|
-
Built-in concrete palettes are contrast-normalized at render time: normal text
|
|
283
|
-
roles meet WCAG AA 4.5:1 and meaningful relation lines/markers meet 3:1 against
|
|
284
|
-
the page background. Unresolved runtime CSS variables cannot be statically
|
|
285
|
-
certified and pass through unchanged. See
|
|
286
|
-
[`svg-semantic-contract.md`](./svg-semantic-contract.md) for the complete contract.
|
|
287
|
-
|
|
288
|
-
For JSON files, use
|
|
289
|
-
[`docs/schemas/style-spec.schema.json`](./schemas/style-spec.schema.json). The
|
|
290
|
-
same schema is exported from the npm package as
|
|
291
|
-
`agentic-mermaid/style-spec.schema.json`; see
|
|
292
|
-
[`custom-style-cookbook.md`](./custom-style-cookbook.md) for complete style
|
|
293
|
-
files and screenshots, and [`custom-fonts.md`](./custom-fonts.md) for font
|
|
294
|
-
resolution across output surfaces.
|
|
295
|
-
|
|
296
|
-
## Agent edit API
|
|
185
|
+
| `ResolvedScene` field | Meaning |
|
|
186
|
+
|---|---|
|
|
187
|
+
| `version` | `RESOLVED_SCENE_VERSION`, currently `2`. |
|
|
188
|
+
| `family` | Registered family ID of the input diagram: both `stateDiagram` and `stateDiagram-v2` report `state`, even though State shares Flowchart's internal Scene lowering. Extension IDs retain their `family:` namespace. |
|
|
189
|
+
| `width`, `height` | Final viewport dimensions in root SVG user units. |
|
|
190
|
+
| `svg` | Byte-identical to `renderMermaidSVG(input, options)` for the same request. |
|
|
191
|
+
| `colors` | Resolved diagram colors. |
|
|
192
|
+
| `parts` | Top-level non-document Scene parts in Scene order, each with `id`, `role`, `kind`, semantic `node` and painted resolved `primitives`. |
|
|
193
|
+
| `frame` | Painted leaves outside those parts, including style backdrops. |
|
|
194
|
+
|
|
195
|
+
Resolved primitives describe what the selected backend actually drew, including sketch
|
|
196
|
+
strokes. Shapes become local SVG path data; `matrix: [a,b,c,d,e,f]` maps local
|
|
197
|
+
coordinates to root user space. Paint, stroke widths, dashes and text sizes
|
|
198
|
+
are resolved in local units. Paint colors are lowercase six-digit hex or
|
|
199
|
+
`none`; color alpha is folded into fill/stroke opacity, while `opacity`
|
|
200
|
+
includes group opacity. Markers follow their decorated path with
|
|
201
|
+
`marker: true`. Multiline labels become separate text runs, retaining font,
|
|
202
|
+
anchor, baseline and text-length fitting.
|
|
203
|
+
|
|
204
|
+
Hidden artwork is omitted. Filters, clip paths, masks, marker-mid, paint
|
|
205
|
+
servers, unsupported elements and unresolved live palettes throw an error
|
|
206
|
+
naming the owning part (or `frame`). This API requires a family with Scene
|
|
207
|
+
lowering. It does not execute interactive/hover rules or fetch fonts.
|
|
208
|
+
`RESOLVED_SCENE_VERSION` changes for removals or semantic changes; additive
|
|
209
|
+
fields keep the version. See the changelog for contract changes.
|
|
210
|
+
|
|
211
|
+
`part.id` is a Scene part ID. `part.node.identity?.id` is source-facing identity
|
|
212
|
+
where provided; they can differ (`node:A` and `A`). Use typed endpoints and
|
|
213
|
+
ownership where available rather than parsing identifier spelling. Ownership
|
|
214
|
+
is not yet populated for every companion part.
|
|
215
|
+
|
|
216
|
+
The result is detached JSON. This function does not accept host text-measurement
|
|
217
|
+
profiles. Its [types](https://github.com/adewale/agentic-mermaid/blob/main/src/scene/resolved-types.ts) describe every primitive
|
|
218
|
+
field; the [changelog](../CHANGELOG.md) records availability. Default Sankey
|
|
219
|
+
gradients require a solid-color configuration under this version's paint-server
|
|
220
|
+
limitation.
|
|
221
|
+
|
|
222
|
+
## Editing
|
|
223
|
+
|
|
224
|
+
For new diagrams, author source, parse, verify, then render or return it. For
|
|
225
|
+
existing structured diagrams, parse, select the typed family, mutate, verify,
|
|
226
|
+
then serialize.
|
|
297
227
|
|
|
298
228
|
```ts
|
|
299
229
|
import {
|
|
300
|
-
parseRegisteredMermaid,
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
230
|
+
parseRegisteredMermaid, asFlowchart, mutate,
|
|
231
|
+
verifyMermaid, serializeMermaid,
|
|
232
|
+
} from 'agentic-mermaid/agent/core'
|
|
233
|
+
|
|
234
|
+
const parsed = parseRegisteredMermaid('flowchart LR\n API --> DB')
|
|
235
|
+
if (!parsed.ok) throw new Error(parsed.error.map(error => error.message).join('\n'))
|
|
236
|
+
const flow = asFlowchart(parsed.value)
|
|
237
|
+
if (!flow) throw new Error('Expected a structured flowchart')
|
|
238
|
+
const changed = mutate(flow, { kind: 'add_node', id: 'Cache', label: 'Cache' })
|
|
239
|
+
if (!changed.ok) throw new Error(changed.error.message)
|
|
240
|
+
const verified = verifyMermaid(changed.value)
|
|
241
|
+
if (!verified.ok) throw new Error(JSON.stringify(verified.warnings))
|
|
242
|
+
console.log(serializeMermaid(changed.value))
|
|
310
243
|
```
|
|
311
244
|
|
|
312
|
-
|
|
245
|
+
The family narrower `asFlowchart` returns the structured flowchart or `null`.
|
|
246
|
+
As defined in the [vocabulary](#vocabulary), narrowing selects the typed family;
|
|
247
|
+
a structural edit can recompute layout.
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
parseRegisteredMermaid(source: string): Result<ParsedDiagram, ParseError[]>
|
|
251
|
+
mutate(diagram: ParsedDiagram, operation: AnyMutationOp): Result<ParsedDiagram, MutationError>
|
|
252
|
+
verifyMermaid(input: ParsedDiagram | string, options?: VerifyOptions): VerifyResult
|
|
253
|
+
serializeMermaid(diagram: ParsedDiagram, options?: SerializeOptions): string
|
|
254
|
+
```
|
|
313
255
|
|
|
314
|
-
| Function |
|
|
256
|
+
| Function | Result and use |
|
|
315
257
|
|---|---|
|
|
316
|
-
| `parseRegisteredMermaid
|
|
317
|
-
| Family narrower
|
|
318
|
-
| `
|
|
319
|
-
| `
|
|
320
|
-
| `
|
|
321
|
-
| `
|
|
322
|
-
| `
|
|
323
|
-
| `
|
|
324
|
-
| `
|
|
325
|
-
| `
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
`src/section-a-capability-report.ts`. It returns the JSON-safe, registry-derived
|
|
340
|
-
request/backend/output/family/Scene matrix. `am capabilities --json` →
|
|
341
|
-
`sectionA` intentionally exposes only its version, pin, digest, counts,
|
|
342
|
-
no-absent status, and directions to this full report. Validate a stored snapshot with
|
|
343
|
-
`validateSectionACapabilityReport(report)`. The generated human projection is
|
|
344
|
-
[`project/section-a-capability-report.md`](./project/section-a-capability-report.md).
|
|
345
|
-
Keeping this audit surface out of the package prevents the full characterization
|
|
346
|
-
and upstream syntax corpora from entering renderer/browser bundles.
|
|
347
|
-
|
|
348
|
-
Canonical extension identities are kind-qualified (`look:`, `palette:`,
|
|
349
|
-
`backend:`, `family:`, `role:`, and `resource:`), versioned, provenance-bearing,
|
|
350
|
-
and collision-safe. New graphical backends declare feature/operation-level
|
|
351
|
-
Scene primitive capability claims; the registry rejects an empty, duplicate,
|
|
352
|
-
cross-target, or otherwise invalid claim set. Every external backend, and every
|
|
353
|
-
external family that supplies `lowerScene`, must also declare an explicit
|
|
354
|
-
compatible `identity.compatibility.scene` range (Scene v2: `^2.0.0`). The host
|
|
355
|
-
checks that range before running backend conformance or other executable
|
|
356
|
-
witnesses; only the internal built-in enrollment path receives compatibility
|
|
357
|
-
defaults.
|
|
358
|
-
|
|
359
|
-
### Current customization and extension inventory
|
|
360
|
-
|
|
361
|
-
This is the current authoritative inventory. Field-level `RenderOptions` and
|
|
362
|
-
`StyleSpec` details remain in their generated tables above rather than being
|
|
363
|
-
copied here.
|
|
364
|
-
|
|
365
|
-
| Level | Public seam | What it can change | Boundary and availability |
|
|
258
|
+
| `parseRegisteredMermaid` | `{ ok: true, value }` or `{ ok: false, error: ParseError[] }`. Preserving unsupported source does not grant typed edit support. |
|
|
259
|
+
| Family narrower, such as `asFlowchart` | The typed family value or `null`. Discover names with `am capabilities --json`. |
|
|
260
|
+
| `describeOps(family)`, `opSignatures(family)` | Exact mutation fields or a compact menu. Look up unfamiliar operations instead of guessing. |
|
|
261
|
+
| `mutate` | A changed diagram or structured mutation error. The operation's `kind` selects its fields. |
|
|
262
|
+
| `verifyMermaid` | `ok`, `warnings`, layout and check evidence. Inspect severity and verification scope. |
|
|
263
|
+
| `serializeMermaid` | Mermaid source. **Does not run verification.** The caller must inspect verification before saving, sending or showing an edit. |
|
|
264
|
+
| `describeMermaidFacts`, `checkMermaid` | Semantic read-back and required/forbidden-fact checks for task-critical meaning. |
|
|
265
|
+
| `analyzeMermaid` | Non-rendering feedback-edge, action and available Gantt scheduling analysis. |
|
|
266
|
+
| `layoutMermaid`, `layoutMermaidWithReceipt` | Positioned boxes, routes, labels and optional regions. The latter accepts source too and includes a receipt. This is layout geometry, not backend-painted artwork. |
|
|
267
|
+
| `buildMermaid`, `createMermaid` | Programmatic authoring from typed operations; ordinary new diagrams can start directly as source. |
|
|
268
|
+
|
|
269
|
+
Opaque bodies preserve source but have no structured mutation. Report the
|
|
270
|
+
unsupported operation, or deliberately edit source and re-parse when requested.
|
|
271
|
+
See the [agent cookbook](./agent-api-cookbook.md) for batch edits and rollback.
|
|
272
|
+
|
|
273
|
+
## Render options
|
|
274
|
+
|
|
275
|
+
SVG, PNG, terminal text, layout and resolved scenes share `RenderOptions`;
|
|
276
|
+
applicability depends on output and family. See [style authoring](./style-authoring.md)
|
|
277
|
+
for precedence and custom looks. This table is generated from runtime descriptors:
|
|
278
|
+
|
|
279
|
+
<!-- BEGIN GENERATED: render-options -->
|
|
280
|
+
| Option | Type | Default | Meaning and applicability |
|
|
366
281
|
|---|---|---|---|
|
|
367
|
-
|
|
|
368
|
-
|
|
|
369
|
-
|
|
|
370
|
-
|
|
|
371
|
-
|
|
|
372
|
-
|
|
|
373
|
-
|
|
|
374
|
-
|
|
|
375
|
-
|
|
|
376
|
-
|
|
|
377
|
-
|
|
|
378
|
-
|
|
|
379
|
-
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
`
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
282
|
+
| `layoutHints` | `{ ranks?: Record<string, number>; adjacent?: string[][]; shortEdges?: string[] }` | unset | Relative ranks, sibling adjacency and short-edge preferences. Built-in families: flowchart, state. Not consumed by terminal output. |
|
|
283
|
+
| `graphLayout` | `{ backend: 'elk' \| 'agentic'; fallback?: 'none' \| 'elk' }` | `elk`, no fallback | Graph geometry producer and explicit Agentic fallback policy. Built-in families: flowchart, state, architecture, class, er, requirement. |
|
|
284
|
+
| `layoutSafety` | `'report' \| 'strict'` | `report` | Report bounded layout evidence, or require a passed final certificate. Strict mode rejects missing or unverified evidence. |
|
|
285
|
+
| `bg` | `string` | `#FFFFFF` | Background color or CSS variable. |
|
|
286
|
+
| `fg` | `string` | `#27272A` | Primary foreground and text color. |
|
|
287
|
+
| `line` | `string` | derived | Connector and secondary-line color. |
|
|
288
|
+
| `accent` | `string` | derived | Arrowhead, highlight, and data accent color. |
|
|
289
|
+
| `muted` | `string` | derived | Secondary text and label color. |
|
|
290
|
+
| `surface` | `string` | derived | Node and group surface color. |
|
|
291
|
+
| `border` | `string` | derived | Node and group border color. |
|
|
292
|
+
| `font` | `string` | `Inter` | CSS font family or stack. |
|
|
293
|
+
| `style` | `StyleInput \| StyleInput[]` | `crisp` | Registered Style/Palette name, inline StyleSpec, or left-to-right stack. |
|
|
294
|
+
| `padding` | `number` | `40` | Canvas padding in SVG user units. Built-in families: flowchart, state, architecture, c4. Not consumed by terminal output. |
|
|
295
|
+
| `nodeSpacing` | `number` | `24` | Horizontal spacing between sibling nodes. Built-in families: flowchart, state, class, er, architecture, c4. Not consumed by terminal output. |
|
|
296
|
+
| `layerSpacing` | `number` | `40` | Vertical spacing between graph layers. Built-in families: flowchart, state, class, er, architecture, c4. Not consumed by terminal output. |
|
|
297
|
+
| `wrappingWidth` | `number` | unset | Flowchart measured-label wrapping budget in pixels. Built-in families: flowchart. Not consumed by terminal output. |
|
|
298
|
+
| `componentSpacing` | `number` | extension-defined | Spacing between disconnected graph components for compatible extension families; no built-in family currently consumes it. Built-in families: none; extension-defined. Not consumed by terminal output. |
|
|
299
|
+
| `transparent` | `boolean` | `false` | Omit the painted SVG canvas background. |
|
|
300
|
+
| `interactive` | `boolean` | `false` | Enable hover tooltips for supported chart data points. Built-in families: xychart, pie, quadrant. |
|
|
301
|
+
| `shadow` | `boolean` | `false` | Paint explicit drop shadows on node shapes. Built-in families: flowchart, state, sequence, timeline, class, er, journey, xychart, pie, quadrant, gantt, mindmap, gitgraph, sankey. |
|
|
302
|
+
| `class` | `{ hierarchicalNamespaces?: boolean }` | `hierarchicalNamespaces: true` | Class-diagram rendering controls. Built-in families: class. Not consumed by terminal output. |
|
|
303
|
+
| `kanban` | `{ maxWidth?: number }` | `maxWidth`: unset | Opt-in Kanban column wrapping with readable column widths. Built-in families: kanban. Not consumed by terminal output. |
|
|
304
|
+
| `pie` | `{ maxWidth?: number }` | `maxWidth`: unset | Opt-in Pie title and legend fitting without shrinking typography. Built-in families: pie. Not consumed by terminal output. |
|
|
305
|
+
| `radar` | `{ maxWidth?: number }` | `maxWidth`: unset | Opt-in Radar plot and legend fitting without shrinking typography. Built-in families: radar. Not consumed by terminal output. |
|
|
306
|
+
| `architecture` | `{ visual?: ArchitectureVisualOverrides }` | built-in metrics | Sparse architecture renderer visual metric and paint overrides. Built-in families: architecture. Not consumed by terminal output. |
|
|
307
|
+
| `timeline` | `{ maxWidth?: number }` | `maxWidth`: unset | Timeline layout controls. Built-in families: timeline. Not consumed by terminal output. |
|
|
308
|
+
| `journey` | `{ experienceCurve?: boolean }` | `experienceCurve: true` | User-journey graphical controls. Built-in families: journey. Not consumed by terminal output. |
|
|
309
|
+
| `gantt` | `{ dependencyArrows?: boolean; criticalPath?: boolean }` | both `false` | Gantt dependency and critical-path overlays. Built-in families: gantt. Not consumed by terminal output. |
|
|
310
|
+
| `mermaidConfig` | `MermaidRuntimeConfig` | source config | Mermaid-style recursive runtime configuration. |
|
|
311
|
+
| `embedFontImport` | `boolean` | `false` | Embed the Google Fonts import in SVG styles; PNG forces this off for offline rasterization. Not consumed by terminal output. |
|
|
312
|
+
| `compact` | `boolean` | `false` | Compact SVG serialization while preserving agent hooks. Not consumed by terminal output. |
|
|
313
|
+
| `idPrefix` | `string` | unset | Non-empty namespace for generated SVG definition IDs and local references. Not consumed by terminal output. |
|
|
314
|
+
| `security` | `'default' \| 'strict'` | `default` | Active SVG content is rejected in every mode; strict additionally rejects every external reference. Raw Mermaid themeCSS is rejected in both modes. Not consumed by terminal output. |
|
|
315
|
+
| `ganttToday` | `string` | unset | Explicit deterministic date for the Gantt today marker. Built-in families: gantt. |
|
|
316
|
+
| `seed` | `number` | `0` | Deterministic re-roll seed for stochastic Styles. Not consumed by terminal output. |
|
|
317
|
+
<!-- END GENERATED: render-options -->
|
|
318
|
+
|
|
319
|
+
Inapplicable family-scoped fields produce `RENDER_OPTION_NOT_APPLICABLE` in a
|
|
320
|
+
receipt. `onConfigDiagnostic` is a library callback outside serializable options.
|
|
321
|
+
For untrusted JSON, use `validateSerializableRenderOptions` or the
|
|
322
|
+
[render-options JSON Schema](https://agentic-mermaid.dev/schemas/render-options.schema.json).
|
|
323
|
+
Terminal-only controls are in the [ASCII reference](./ascii.md).
|
|
324
|
+
|
|
325
|
+
### PNG options
|
|
389
326
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
am init-agent --dir . --json
|
|
400
|
-
```
|
|
327
|
+
| Option | Type | Default | Availability and meaning |
|
|
328
|
+
|---|---|---:|---|
|
|
329
|
+
| `scale` | `number` | `2` | Portable: native/browser library, CLI, and local/hosted MCP. Zoom multiplier when `fitTo` is not set. |
|
|
330
|
+
| `background` | `string` | artifact background, then white | Portable on the same surfaces. Safe explicit PNG background color. |
|
|
331
|
+
| `fitTo` | `{ width?: number; height?: number }` | — | Portable on the same surfaces. Constrain output to exactly one positive width or height. |
|
|
332
|
+
| `minLabelPx` | `number` | `9` | Portable on the same surfaces. Warn with `BELOW_READABLE_SIZE` when rasterization puts the smallest measurable label below this effective-pixel floor; `0` disables the gate. The default is provisional product policy for general-purpose screen diagrams, not a universal readability or accessibility threshold. |
|
|
333
|
+
| `fontDirs` | `string[]` | — | Trusted native-host input: Node/Bun library, CLI, and local MCP only. Extra font directories for unbundled families and scripts the bundled fonts do not cover. CLI: `--font-dirs <dirs>` (comma-separated). |
|
|
334
|
+
| `loadSystemFonts` | `boolean` | `false` | Trusted native-host input on the same native surfaces. Trades cross-machine determinism for glyph coverage. CLI: `--system-fonts`. |
|
|
335
|
+
| `onWarning` | `(w: PngRasterWarning) => void` | stderr | Native library callback only. Receives `PNG_FONT_COVERAGE` and `BELOW_READABLE_SIZE` warnings; callbacks never enter serializable requests or receipts. |
|
|
401
336
|
|
|
402
|
-
|
|
337
|
+
SVG font declarations do not load fonts. See [custom fonts](./custom-fonts.md)
|
|
338
|
+
and [rasterization details](./api-advanced.md#png-fonts-portability-and-rasterization).
|
|
403
339
|
|
|
404
|
-
##
|
|
340
|
+
## Errors and recovery
|
|
405
341
|
|
|
406
|
-
|
|
407
|
-
|
|
342
|
+
| Operation | Failure shape | Recovery |
|
|
343
|
+
|---|---|---|
|
|
344
|
+
| Parse | `{ ok: false, error: ParseError[] }` | Inspect every error's message and available source position. |
|
|
345
|
+
| Mutate | `{ ok: false, error }` | Use the code/message and operation schema; preserve the previous value. |
|
|
346
|
+
| Verify | `ok: false` with structured warnings | Inspect code, severity, origin and available evidence. |
|
|
347
|
+
| Render | Throws | Catch at the artifact boundary. Family/capability failures have exported error types; other failures can be ordinary `Error`. |
|
|
348
|
+
| Resolve artwork | Throws, naming the part and unsupported feature | Report the unsupported artwork or choose a supported representation. These errors currently have no dedicated stable code. |
|
|
408
349
|
|
|
409
|
-
|
|
350
|
+
```ts
|
|
351
|
+
import { parseRegisteredMermaid } from 'agentic-mermaid/agent/core'
|
|
352
|
+
|
|
353
|
+
const result = parseRegisteredMermaid('flowchart LR\n Idea --> Ship')
|
|
354
|
+
if (result.ok) {
|
|
355
|
+
console.log(result.value.kind)
|
|
356
|
+
} else {
|
|
357
|
+
console.error(result.error.map(error => error.message).join('\n'))
|
|
358
|
+
}
|
|
359
|
+
```
|
|
410
360
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
361
|
+
`verify.ok` means no unsuppressed error was detected by the checks performed.
|
|
362
|
+
It does not establish visual perfection, complete semantic correctness or
|
|
363
|
+
portable, lossless canonical export. Check task-specific facts and review the
|
|
364
|
+
artifact when appearance matters. See [verification scope](./agent-mutation-policy.md).
|
|
415
365
|
|
|
416
|
-
|
|
366
|
+
## Advanced use
|
|
417
367
|
|
|
418
|
-
|
|
368
|
+
Use the [advanced reference](./api-advanced.md) for receipts, host-selected
|
|
369
|
+
backends, custom text metrics, parser observation, detailed source-preservation
|
|
370
|
+
examples and extension contracts. Use the [CLI](https://agentic-mermaid.dev/docs/cli/),
|
|
371
|
+
[MCP](./mcp-http-transport.md) or [agent cookbook](./agent-api-cookbook.md) for those
|
|
372
|
+
channels. You do not need those protocols to render or edit with the library.
|