@zombie-mermaid/svg-renderer 2.2.6 → 3.1.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 +28 -8
- package/dist/index.cjs +37 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.js +1436 -893
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/__tests__/render-mermaid-svg.test.ts +64 -0
- package/src/class/renderer.ts +65 -62
- package/src/edge-curves.ts +17 -16
- package/src/er/renderer.ts +50 -49
- package/src/index.ts +222 -5
- package/src/layout-engine/from-elk.ts +80 -5
- package/src/registry.ts +351 -0
- package/src/renderer.ts +190 -189
- package/src/sequence/renderer.ts +66 -65
- package/src/layout.ts +0 -8
package/README.md
CHANGED
|
@@ -5,22 +5,42 @@
|
|
|
5
5
|
|
|
6
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
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
**Just want SVG output from Mermaid text?** Use [`zombie-mermaid`](https://www.npmjs.com/package/zombie-mermaid)'s `renderMermaidSVG(text)` instead — it's simpler and does exactly that.
|
|
11
|
-
|
|
12
|
-
This package does **not** currently include that single entry point. It exports the lower-level pieces the umbrella assembles it 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. Diagram-type dispatch (detecting which diagram type a given Mermaid source is, and routing to the right layout/render pair) still lives in the umbrella. Adding a `renderMermaidSVG` front door here, for parity with `@zombie-mermaid/ascii-renderer`, is tracked separately — see [zombie-mermaid#1111](https://github.com/dfadler/zombie-mermaid/issues/1111).
|
|
13
|
-
|
|
14
|
-
Reach for this package 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 the umbrella package's own dispatch and ASCII-rendering code.
|
|
8
|
+
Supports flowcharts, state diagrams, sequence diagrams, class diagrams, ER diagrams, and XY charts.
|
|
15
9
|
|
|
16
10
|
## Install
|
|
17
11
|
|
|
18
12
|
```bash
|
|
19
|
-
npm install @zombie-mermaid/svg-renderer
|
|
13
|
+
npm install @zombie-mermaid/svg-renderer
|
|
20
14
|
```
|
|
21
15
|
|
|
22
16
|
## Usage
|
|
23
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
|
+
|
|
24
44
|
Each diagram type follows the same shape: parse (from `@zombie-mermaid/mermaid-parser`) → lay out → render. Class diagrams, for example:
|
|
25
45
|
|
|
26
46
|
```ts
|