@zombie-mermaid/svg-renderer 2.2.1 → 3.0.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.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # @zombie-mermaid/svg-renderer
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@zombie-mermaid/svg-renderer.svg)](https://www.npmjs.com/package/@zombie-mermaid/svg-renderer)
4
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
+
6
+ SVG layout and rendering primitives for [Mermaid](https://mermaid.js.org/) diagrams — the [ELK.js](https://github.com/kieler/elkjs)-backed layout engine and per-diagram-type SVG emitters behind [`zombie-mermaid`](https://www.npmjs.com/package/zombie-mermaid)'s SVG output.
7
+
8
+ Supports flowcharts, state diagrams, sequence diagrams, class diagrams, ER diagrams, and XY charts.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install @zombie-mermaid/svg-renderer
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { renderMermaidSVG } from '@zombie-mermaid/svg-renderer'
20
+
21
+ const svg = renderMermaidSVG('graph LR\n A --> B')
22
+ console.log(svg)
23
+ ```
24
+
25
+ ```ts
26
+ const text = 'graph LR\n A --> B'
27
+
28
+ renderMermaidSVG(text, {
29
+ bg: '#1a1b26', // background color
30
+ fg: '#a9b1d6', // foreground/text/line color
31
+ font: 'Inter',
32
+ transparent: false,
33
+ embedSource: true, // stamp the original text onto the root <svg> as data-src
34
+ title: 'Flowchart: A to B', // accessible name (role="img" + aria-labelledby)
35
+ })
36
+ ```
37
+
38
+ See `RenderOptions` in [`@zombie-mermaid/core`](https://www.npmjs.com/package/@zombie-mermaid/core) for the full option set. Need async? Use `renderMermaidSVGAsync()` — same output, returns a `Promise<string>`.
39
+
40
+ ## Lower-level pieces
41
+
42
+ This package also exports the per-diagram-type building blocks `renderMermaidSVG` is assembled from — a `layout*Sync()` function and a `render*Svg()` function per diagram type (flowchart/state, class, ER, sequence, XY chart), plus the shared ELK.js adapter and layout engine underneath them. Reach for these directly if you're doing custom integration work — a different dispatch layer, a subset of diagram types, or reusing the ELK.js layout adapters for something else — and want to skip diagram-type detection.
43
+
44
+ Each diagram type follows the same shape: parse (from `@zombie-mermaid/mermaid-parser`) → lay out → render. Class diagrams, for example:
45
+
46
+ ```ts
47
+ import { splitStatements } from '@zombie-mermaid/core'
48
+ import { THEMES } from '@zombie-mermaid/core'
49
+ import { parseClassDiagram } from '@zombie-mermaid/mermaid-parser'
50
+ import {
51
+ layoutClassDiagramSync,
52
+ renderClassSvg,
53
+ } from '@zombie-mermaid/svg-renderer'
54
+
55
+ const text = 'classDiagram\n Animal <|-- Dog'
56
+ const diagram = parseClassDiagram(splitStatements(text))
57
+ const positioned = layoutClassDiagramSync(diagram)
58
+ const svg = renderClassSvg(positioned, THEMES['zinc-light'])
59
+ ```
60
+
61
+ The equivalent pairs for the other diagram types: `layoutErDiagramSync`/`renderErSvg`, `layoutSequenceDiagramSync`/`renderSequenceSvg`, `layoutXYChartSync`/`renderXYChartSvg`, and flowchart/state via `layoutGraphSync` (re-exported from `layout-engine.ts`) plus `renderer.ts`'s renderer. See each module under [`src/`](src) for exact signatures — most render functions take additional optional parameters (font, transparent background, embedded source, title, CSP nonce) beyond the two shown above.
62
+
63
+ ## Relationship to `zombie-mermaid`
64
+
65
+ This package is one of the internal pieces `zombie-mermaid` is built from (alongside `@zombie-mermaid/core` and `@zombie-mermaid/mermaid-parser`, which stay internal-only). Installing `zombie-mermaid` pulls in the exact same layout/render code, wired up behind `renderMermaidSVG`.
66
+
67
+ ## License
68
+
69
+ MIT — see [LICENSE](LICENSE).