zombie-mermaid 1.4.0 → 1.6.0

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 (124) hide show
  1. package/README.md +71 -15
  2. package/dist/ascii.cjs +8012 -0
  3. package/dist/ascii.cjs.map +1 -0
  4. package/dist/ascii.d.cts +1 -0
  5. package/dist/ascii.d.ts +1 -0
  6. package/dist/ascii.js +7981 -0
  7. package/dist/ascii.js.map +1 -0
  8. package/dist/cli.js +1423 -320
  9. package/dist/index-ZirmSoos.d.cts +178 -0
  10. package/dist/index-ZirmSoos.d.ts +178 -0
  11. package/dist/index.cjs +1248 -536
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +149 -150
  14. package/dist/index.d.ts +149 -150
  15. package/dist/index.js +1249 -538
  16. package/dist/index.js.map +1 -1
  17. package/dist/mcp.cjs +13100 -0
  18. package/dist/mcp.cjs.map +1 -0
  19. package/dist/mcp.d.cts +14 -0
  20. package/dist/mcp.d.ts +14 -0
  21. package/dist/mcp.js +13059 -0
  22. package/dist/mcp.js.map +1 -0
  23. package/package.json +46 -6
  24. package/src/__tests__/ascii-class-padding.test.ts +104 -0
  25. package/src/__tests__/ascii-combining-mark-width.test.ts +70 -0
  26. package/src/__tests__/ascii-coords-overlay.test.ts +64 -0
  27. package/src/__tests__/ascii-display-width-unit.test.ts +154 -0
  28. package/src/__tests__/ascii-draw-bundles.test.ts +198 -0
  29. package/src/__tests__/ascii-edge-cross-style-overlap.test.ts +212 -0
  30. package/src/__tests__/ascii-emoji-cluster-width.test.ts +101 -0
  31. package/src/__tests__/ascii-er-jog-stray-line.test.ts +82 -0
  32. package/src/__tests__/ascii-er-padding.test.ts +114 -0
  33. package/src/__tests__/ascii-er-relationship-label-corruption-350.test.ts +458 -0
  34. package/src/__tests__/ascii-er-relationship-overwrite.test.ts +303 -0
  35. package/src/__tests__/ascii-multibox-cjk-width.test.ts +1 -1
  36. package/src/__tests__/ascii-padding-edge-cases.test.ts +154 -0
  37. package/src/__tests__/ascii-sequence-mermaid-parity.test.ts +198 -0
  38. package/src/__tests__/ascii-sequence-padding.test.ts +119 -0
  39. package/src/__tests__/ascii-subgraph-later-edgeless-301.test.ts +273 -0
  40. package/src/__tests__/class-click-interactions.test.ts +210 -0
  41. package/src/__tests__/class-integration.test.ts +36 -0
  42. package/src/__tests__/cli-mcp-dispatch.test.ts +68 -0
  43. package/src/__tests__/cli-mcp.test.ts +44 -0
  44. package/src/__tests__/cli-render.test.ts +79 -0
  45. package/src/__tests__/cli-test-helpers.ts +4 -0
  46. package/src/__tests__/cli-web-dispatch.test.ts +62 -0
  47. package/src/__tests__/cli-web.test.ts +203 -0
  48. package/src/__tests__/cli.test.ts +152 -1
  49. package/src/__tests__/click-directive.test.ts +63 -0
  50. package/src/__tests__/edge-cell-styles.test.ts +177 -0
  51. package/src/__tests__/elk-adapter-utils.test.ts +166 -0
  52. package/src/__tests__/elk-layout-cache.test.ts +217 -0
  53. package/src/__tests__/er-click-unsupported.test.ts +72 -0
  54. package/src/__tests__/grid-occupancy.test.ts +160 -0
  55. package/src/__tests__/helpers/terminal-display-width.ts +41 -13
  56. package/src/__tests__/interactivity-config.test.ts +140 -4
  57. package/src/__tests__/interactivity-option.test.ts +173 -0
  58. package/src/__tests__/mcp-render-ascii-tool.test.ts +94 -0
  59. package/src/__tests__/mcp-render-svg-theme-guard.test.ts +27 -0
  60. package/src/__tests__/mcp-render-svg-tool.test.ts +116 -0
  61. package/src/__tests__/mcp-server.test.ts +104 -0
  62. package/src/__tests__/package-info.test.ts +51 -0
  63. package/src/__tests__/sequence-integration.test.ts +69 -0
  64. package/src/__tests__/sequence-layout.test.ts +25 -0
  65. package/src/__tests__/sequence-parser.test.ts +123 -0
  66. package/src/__tests__/svg-accessible-name-conformance.test.ts +256 -0
  67. package/src/__tests__/svg-accessible-name.test.ts +392 -0
  68. package/src/__tests__/testdata/ascii/cls_annotation.txt +18 -18
  69. package/src/__tests__/testdata/ascii/cls_basic.txt +9 -9
  70. package/src/__tests__/testdata/ascii/cls_inheritance.txt +15 -15
  71. package/src/__tests__/testdata/ascii/cls_methods.txt +12 -12
  72. package/src/__tests__/testdata/unicode/cls_annotation.txt +18 -18
  73. package/src/__tests__/testdata/unicode/cls_basic.txt +9 -9
  74. package/src/__tests__/testdata/unicode/cls_inheritance.txt +15 -15
  75. package/src/__tests__/testdata/unicode/cls_methods.txt +12 -12
  76. package/src/__tests__/text-metrics.test.ts +21 -0
  77. package/src/ascii/class-diagram.ts +18 -22
  78. package/src/ascii/coords.ts +54 -0
  79. package/src/ascii/display-width.ts +112 -26
  80. package/src/ascii/draw-boxes.ts +9 -0
  81. package/src/ascii/draw-bundles.ts +104 -0
  82. package/src/ascii/draw.ts +19 -0
  83. package/src/ascii/edge-cell-styles.ts +81 -0
  84. package/src/ascii/er-diagram.ts +551 -60
  85. package/src/ascii/grid-occupancy.ts +98 -0
  86. package/src/ascii/grid.ts +265 -9
  87. package/src/ascii/index.ts +27 -8
  88. package/src/ascii/sequence.ts +89 -15
  89. package/src/ascii/types.ts +46 -0
  90. package/src/class/format.ts +15 -0
  91. package/src/class/layout.ts +11 -33
  92. package/src/class/parser.ts +9 -0
  93. package/src/class/renderer.ts +72 -17
  94. package/src/class/types.ts +7 -1
  95. package/src/cli/mcp.ts +36 -0
  96. package/src/cli/parse-args.ts +95 -3
  97. package/src/cli/render.ts +5 -0
  98. package/src/cli/web.ts +235 -0
  99. package/src/cli.ts +39 -16
  100. package/src/click-directive.ts +105 -0
  101. package/src/elk-instance.ts +110 -1
  102. package/src/er/layout.ts +4 -13
  103. package/src/er/renderer.ts +14 -12
  104. package/src/index.ts +75 -1
  105. package/src/layout-engine/elk-adapter-utils.ts +81 -0
  106. package/src/layout-engine/from-elk.ts +7 -30
  107. package/src/layout-engine/to-elk.ts +1 -1
  108. package/src/layout-engine.ts +1 -1
  109. package/src/mcp/index.ts +17 -0
  110. package/src/mcp/server.ts +75 -0
  111. package/src/mcp/tools/render-ascii.ts +99 -0
  112. package/src/mcp/tools/render-svg.ts +95 -0
  113. package/src/multiline-utils.ts +17 -0
  114. package/src/package-info.ts +30 -0
  115. package/src/parser.ts +55 -51
  116. package/src/renderer.ts +71 -57
  117. package/src/sequence/layout.ts +2 -0
  118. package/src/sequence/parser.ts +100 -58
  119. package/src/sequence/renderer.ts +61 -20
  120. package/src/sequence/types.ts +8 -0
  121. package/src/text-metrics.ts +26 -2
  122. package/src/theme.ts +104 -1
  123. package/src/types.ts +92 -1
  124. package/src/xychart/renderer.ts +13 -4
package/README.md CHANGED
@@ -4,13 +4,18 @@
4
4
 
5
5
  **Render Mermaid diagrams as beautiful SVGs or ASCII art**
6
6
 
7
- Ultra-fast, fully themeable, zero DOM dependencies. A maintained fork of [`beautiful-mermaid`](https://github.com/lukilabs/beautiful-mermaid).
7
+ Ultra-fast, fully themeable, zero DOM dependencies. A maintained fork of [`beautiful-mermaid`](https://github.com/lukilabs/beautiful-mermaid) that refuses to die.
8
8
 
9
- ![zombie-mermaid sequence diagram example](hero.png)
9
+ ![Raw Mermaid source rendering into a themed, animated diagram, drawn by zombie-mermaid itself](hero.svg)
10
10
 
11
- [**Live demo →**](https://dfadler.github.io/zombie-mermaid/)
11
+ [![Live Demo](https://img.shields.io/badge/Live_Demo-view_the_sample_gallery-1f6feb?style=for-the-badge)](https://dfadler.github.io/zombie-mermaid/)
12
+ [![Beautiful Mermaid Fork Fixes](https://img.shields.io/badge/Beautiful_Mermaid_Fork_Fixes-before%2Fafter_evidence-1f6feb?style=for-the-badge)](https://dfadler.github.io/zombie-mermaid/fork-fixes.html)
12
13
 
13
14
  [![npm version](https://img.shields.io/npm/v/zombie-mermaid.svg)](https://www.npmjs.com/package/zombie-mermaid)
15
+ [![CI](https://github.com/dfadler/zombie-mermaid/actions/workflows/ci.yml/badge.svg)](https://github.com/dfadler/zombie-mermaid/actions/workflows/ci.yml)
16
+ [![codecov](https://codecov.io/gh/dfadler/zombie-mermaid/branch/main/graph/badge.svg)](https://codecov.io/gh/dfadler/zombie-mermaid)
17
+ [![Bundle Size](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/dfadler/zombie-mermaid/main/badges/bundle-size.json)](#bundle-size)
18
+ [![Socket Security](https://socket.dev/api/badge/npm/package/zombie-mermaid)](https://socket.dev/npm/package/zombie-mermaid)
14
19
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
15
20
 
16
21
  </div>
@@ -19,11 +24,13 @@ Ultra-fast, fully themeable, zero DOM dependencies. A maintained fork of [`beaut
19
24
 
20
25
  ## Why This Fork Exists
21
26
 
22
- `beautiful-mermaid` is a genuinely good library — see "Why We Built This" below — but upstream development has stalled: as of this writing there are 30 open pull requests, the oldest dating back over half a year, and nothing has merged in months. `zombie-mermaid` is the same codebase, kept moving: upstream fixes get pulled in, PRs stuck in the upstream queue get a home, and releases actually ship.
27
+ `beautiful-mermaid` is a genuinely good library — fast, beautiful, and works everywhere from rich UIs to plain terminals. But upstream development has stalled: dozens of [pull requests](https://github.com/lukilabs/beautiful-mermaid/pulls) sit open, some for over half a year, and nothing has merged in months — by most definitions, it's dead. I maintain `zombie-mermaid` as the fork that won't stay buried: pulling in upstream fixes, giving PRs stuck in the upstream queue a home, and actually shipping releases. Craft and Craft Agents aren't part of this project's process going forward; this is an independently maintained continuation.
23
28
 
24
- It's still MIT-licensed, still built on the same foundation, and still credits the original authors below.
29
+ This isn't just a claim — see **[what this fork fixes](https://dfadler.github.io/zombie-mermaid/fork-fixes.html)** for an evidence-based before/after showcase: every bug listed there is rendered by the actual pre-fix and post-fix code, not described from memory.
25
30
 
26
- ## Why We Built This
31
+ It's still MIT-licensed, still built on the same foundation, and still credits the original authors — including the ASCII rendering engine's origins — in [Attribution](#attribution) below.
32
+
33
+ ## The Problem With Default Mermaid Rendering
27
34
 
28
35
  Diagrams are essential for AI-assisted programming. When you're working with an AI coding assistant, being able to visualize data flows, state machines, and system architecture—directly in your terminal or chat interface—makes complex concepts instantly graspable.
29
36
 
@@ -34,9 +41,15 @@ Diagrams are essential for AI-assisted programming. When you're working with an
34
41
  - **No terminal output** — Can't render to ASCII for CLI tools
35
42
  - **Heavy dependencies** — Pulls in a lot of code for simple diagrams
36
43
 
37
- We built `beautiful-mermaid` at [Craft](https://craft.do) to power diagrams in [Craft Agents](https://agents.craft.do). It's fast, beautiful, and works everywhere—from rich UIs to plain terminals.
44
+ ### Bundle Size
38
45
 
39
- The ASCII rendering engine is based on [mermaid-ascii](https://github.com/AlexanderGrooff/mermaid-ascii) by Alexander Grooff. We ported it from Go to TypeScript and extended it. Thank you Alexander for the excellent foundation! (And inspiration that this was possible.)
46
+ The **Bundle Size** badge above tracks the gzipped size of `zombie-mermaid`'s
47
+ main entry point (`dist/index.js`) and updates automatically with every
48
+ release — the same badge/CI-tracked pattern already backing the coverage and
49
+ CI status badges. Need ASCII rendering only? `import { renderMermaidASCII }
50
+ from 'zombie-mermaid/ascii'` skips [ELK.js](https://github.com/kieler/elkjs),
51
+ the layout engine the SVG renderer depends on, for a substantially smaller
52
+ bundle.
40
53
 
41
54
  ## Features
42
55
 
@@ -49,6 +62,7 @@ The ASCII rendering engine is based on [mermaid-ascii](https://github.com/Alexan
49
62
  - **Mono mode** — Beautiful diagrams from just 2 colors
50
63
  - **Zero DOM dependencies** — Pure TypeScript, works everywhere
51
64
  - **Ultra-fast** — Renders 100+ diagrams in under 500ms
65
+ - **Accessible SVG output, CI-enforced** — every diagram type always gets a `role`-correct, nameable root `<svg>`; see the [accessibility conformance statement](docs/accessibility.md) for exactly what's guaranteed
52
66
 
53
67
  ## Installation
54
68
 
@@ -95,6 +109,16 @@ const ascii = renderMermaidASCII(`graph LR; A --> B --> C`)
95
109
  └───┘ └───┘ └───┘
96
110
  ```
97
111
 
112
+ ASCII-only consumers (a CLI, a terminal UI, a serverless function) can import
113
+ from `zombie-mermaid/ascii` instead of the package root. The root entry
114
+ statically pulls in `elkjs` for the SVG layout engine — over 1.4MB minified —
115
+ even if you never call `renderMermaidSVG`. The `/ascii` subpath never imports
116
+ it:
117
+
118
+ ```typescript
119
+ import { renderMermaidASCII } from 'zombie-mermaid/ascii'
120
+ ```
121
+
98
122
  Using this from React? See [React Integration](docs/react-integration.md) for a zero-flash `useMemo()` pattern.
99
123
 
100
124
  ---
@@ -115,9 +139,43 @@ zombie-mermaid --help # Show all options
115
139
 
116
140
  ---
117
141
 
142
+ ## MCP Server
143
+
144
+ > 🧪 **Experimental — shipped to gauge interest, not a finished or best-effort implementation.** This is a first cut covering the common case; the tool surface may change based on feedback. Try it and [open an issue](https://github.com/dfadler/zombie-mermaid/issues/new) with what you'd want from it.
145
+
146
+ `zombie-mermaid mcp` starts a [Model Context Protocol](https://modelcontextprotocol.io/) server on stdio, exposing the library's rendering as two tools: `render_mermaid_svg` and `render_mermaid_ascii`. Point an MCP client (Claude Desktop, Claude Code, or anything else that speaks MCP) at it to render Mermaid diagrams directly in a conversation, without shelling out to the CLI or importing the library.
147
+
148
+ Example Claude Desktop / Claude Code MCP server config:
149
+
150
+ ```json
151
+ {
152
+ "mcpServers": {
153
+ "zombie-mermaid": {
154
+ "command": "npx",
155
+ "args": ["-y", "zombie-mermaid", "mcp"]
156
+ }
157
+ }
158
+ }
159
+ ```
160
+
161
+ Both tools accept a `diagram` string plus a handful of rendering options (`theme`, `transparent`, `font` for SVG; `useAscii`, `paddingX`/`paddingY`/`boxBorderPadding` for ASCII) — see each tool's `inputSchema` for the full, current list. Invalid Mermaid syntax comes back as a normal tool error (`isError: true`) rather than crashing the connection.
162
+
163
+ To embed the server in your own process instead of running it as a subcommand, import `zombie-mermaid/mcp` and connect it to any [MCP `Transport`](https://modelcontextprotocol.io/) yourself:
164
+
165
+ ```typescript
166
+ import { createMcpServer } from 'zombie-mermaid/mcp'
167
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
168
+
169
+ const server = createMcpServer()
170
+ await server.connect(new StdioServerTransport())
171
+ ```
172
+
173
+ ---
174
+
118
175
  ## Docs
119
176
 
120
177
  - [Guides](docs/guides/) — task-oriented walkthroughs: [browsing the samples](docs/guides/samples.md), [choosing a theme](docs/guides/theming.md)
178
+ - [Accessibility](docs/accessibility.md) — conformance statement: what's guaranteed (and CI-enforced), what's implemented but unverified by automation, and what isn't covered
121
179
  - [Theming](docs/theming.md) — the two-color foundation, enriched mode, built-in themes, custom themes, Shiki compatibility
122
180
  - [Supported Diagrams](docs/diagrams.md) — syntax for every diagram type, XY chart styling, and ASCII rendering options
123
181
  - [React Integration](docs/react-integration.md) — zero-flash rendering with `useMemo()`
@@ -130,7 +188,7 @@ More design write-ups and reference material live in [docs/](docs/).
130
188
 
131
189
  ## Attribution
132
190
 
133
- The ASCII rendering engine is based on [mermaid-ascii](https://github.com/AlexanderGrooff/mermaid-ascii) by Alexander Grooff. We ported it from Go to TypeScript and extended it with:
191
+ The ASCII rendering engine is based on [mermaid-ascii](https://github.com/AlexanderGrooff/mermaid-ascii) by Alexander Grooff, ported from Go to TypeScript and extended with:
134
192
 
135
193
  - Sequence diagram support
136
194
  - Class diagram support
@@ -142,14 +200,12 @@ Thank you Alexander for the excellent foundation!
142
200
 
143
201
  ---
144
202
 
145
- ## License
203
+ ## Contributing
146
204
 
147
- MIT — see [LICENSE](LICENSE) for details.
205
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for local setup, the test/lint workflow, and how changesets and releases work ([RELEASING.md](RELEASING.md)). Security issues should go through [SECURITY.md](SECURITY.md) instead of a public issue. Released versions are tracked in [CHANGELOG.md](CHANGELOG.md).
148
206
 
149
207
  ---
150
208
 
151
- <div align="center">
152
-
153
- Built with care by the team at [Craft](https://craft.do)
209
+ ## License
154
210
 
155
- </div>
211
+ MIT — see [LICENSE](LICENSE) for details.