@jarenjs/mermaid 0.34.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 (64) hide show
  1. package/README.md +282 -0
  2. package/dist/types/ast.d.ts +210 -0
  3. package/dist/types/component/index.d.ts +81 -0
  4. package/dist/types/errors.d.ts +27 -0
  5. package/dist/types/index.d.ts +97 -0
  6. package/dist/types/interactive.d.ts +36 -0
  7. package/dist/types/layout/flowchart.d.ts +12 -0
  8. package/dist/types/layout/sequence.d.ts +12 -0
  9. package/dist/types/layout/state.d.ts +19 -0
  10. package/dist/types/parser/class.d.ts +11 -0
  11. package/dist/types/parser/config.d.ts +61 -0
  12. package/dist/types/parser/er.d.ts +11 -0
  13. package/dist/types/parser/flowchart.d.ts +26 -0
  14. package/dist/types/parser/gantt.d.ts +11 -0
  15. package/dist/types/parser/index.d.ts +22 -0
  16. package/dist/types/parser/pie.d.ts +11 -0
  17. package/dist/types/parser/sequence.d.ts +16 -0
  18. package/dist/types/parser/state.d.ts +22 -0
  19. package/dist/types/plugin.d.ts +50 -0
  20. package/dist/types/render/error.d.ts +23 -0
  21. package/dist/types/render/flowchart.d.ts +18 -0
  22. package/dist/types/render/index.d.ts +23 -0
  23. package/dist/types/render/misc.d.ts +54 -0
  24. package/dist/types/render/sequence.d.ts +16 -0
  25. package/dist/types/styles.d.ts +81 -0
  26. package/dist/types/theme.d.ts +47 -0
  27. package/dist/types/to-mermaid.d.ts +20 -0
  28. package/dist/types/utils.d.ts +47 -0
  29. package/docs/MERMAID-FORMAT.md +242 -0
  30. package/package.json +84 -0
  31. package/schemas/jaren-mermaid-ast.schema.json +78 -0
  32. package/schemas/jaren-workflow.schema.json +28 -0
  33. package/src/ast.js +252 -0
  34. package/src/component/index.js +109 -0
  35. package/src/errors.js +35 -0
  36. package/src/index.js +155 -0
  37. package/src/interactive.js +244 -0
  38. package/src/layout/flowchart.js +352 -0
  39. package/src/layout/sequence.js +178 -0
  40. package/src/layout/state.js +65 -0
  41. package/src/parser/class.js +90 -0
  42. package/src/parser/config.js +215 -0
  43. package/src/parser/er.js +86 -0
  44. package/src/parser/flowchart.js +413 -0
  45. package/src/parser/gantt.js +49 -0
  46. package/src/parser/index.js +122 -0
  47. package/src/parser/pie.js +32 -0
  48. package/src/parser/sequence.js +156 -0
  49. package/src/parser/state.js +137 -0
  50. package/src/plugin.js +76 -0
  51. package/src/render/error.js +55 -0
  52. package/src/render/flowchart.js +249 -0
  53. package/src/render/index.js +93 -0
  54. package/src/render/misc.js +135 -0
  55. package/src/render/sequence.js +152 -0
  56. package/src/styles.js +181 -0
  57. package/src/theme.js +180 -0
  58. package/src/to-mermaid.js +317 -0
  59. package/src/utils.js +64 -0
  60. package/styles/mermaid.css +115 -0
  61. package/stylesheets/dag-to-flowchart.jslt.json +62 -0
  62. package/stylesheets/flowchart-to-dag.jslt.json +29 -0
  63. package/stylesheets/state-to-workflow.jslt.json +26 -0
  64. package/stylesheets/workflow-to-state.jslt.json +41 -0
@@ -0,0 +1,97 @@
1
+ /**
2
+ * @file `@jarenjs/mermaid` — a native, headless Mermaid clone. This is
3
+ * the **engine** (part one): pure functions over data — text ⇄ AST ⇄
4
+ * pure-vnode SVG — that know only the `@jarenjs/view` vnode shape. It
5
+ * imports nothing from the component, `@jarenjs/app`, the DOM or
6
+ * `@jarenjs/md` (the two-layer rule).
7
+ *
8
+ * The pipeline mirrors `@jarenjs/md`:
9
+ *
10
+ * source ──parseMermaid──▶ DiagramDocument (geometry-free JSON AST)
11
+ * │
12
+ * ┌─────────────────┼───────────────────┐
13
+ * ▼ ▼ ▼
14
+ * toMermaid() layoutDiagram() JSLT / query
15
+ * (canonical → diagramToVnode() (the AST is an
16
+ * round-trip) (pure-vnode SVG) ordinary document)
17
+ */
18
+ import { hashContent } from './utils.js';
19
+ export { parseMermaid } from './parser/index.js';
20
+ export { toMermaid } from './to-mermaid.js';
21
+ export { parseMermaidConfig } from './parser/config.js';
22
+ export { layoutDiagram, diagramToVnode } from './render/index.js';
23
+ export { createTheme, THEMES, HOST_VARS } from './theme.js';
24
+ export { sanitizeHref } from '@jarenjs/view/helpers';
25
+ export { MermaidParseError } from './errors.js';
26
+ export { hashContent } from './utils.js';
27
+ export { MERMAID_VERSION, diagramDocument, walkSequence, flowNode, flowEdge, sequenceAst, flowchartAst, } from './ast.js';
28
+ /**
29
+ * Convenience: parse → layout → render, error-safe, in one call.
30
+ * @param {string} source
31
+ * @param {{ theme?: any }} [options]
32
+ * @returns {any} an SVG vnode
33
+ */
34
+ export declare function renderMermaid(source: string, options?: {
35
+ theme?: any;
36
+ }): any;
37
+ export type CompiledMermaid = {
38
+ /**
39
+ * the parsed document
40
+ */
41
+ doc: import('./ast.js').DiagramDocument;
42
+ /**
43
+ * cached pure-vnode SVG
44
+ */
45
+ toVnode: () => any;
46
+ /**
47
+ * cached standalone SVG string (SSR)
48
+ */
49
+ toSvgString: () => string;
50
+ /**
51
+ * canonical Mermaid text (`toMermaid`)
52
+ */
53
+ toText: () => string;
54
+ /**
55
+ * walk the AST
56
+ */
57
+ walk: (visitor: (stmt: any) => void) => void;
58
+ };
59
+ /**
60
+ * @typedef {object} CompiledMermaid
61
+ * @property {import('./ast.js').DiagramDocument} doc the parsed document
62
+ * @property {() => any} toVnode cached pure-vnode SVG
63
+ * @property {() => string} toSvgString cached standalone SVG string (SSR)
64
+ * @property {() => string} toText canonical Mermaid text (`toMermaid`)
65
+ * @property {(visitor: (stmt: any) => void) => void} walk walk the AST
66
+ */
67
+ /**
68
+ * Parse once and return a bundle of cached projections.
69
+ * `toVnode`/`toSvgString`/`toText` each compute at most once; the
70
+ * vnode is returned by reference on repeat calls, so an unchanged
71
+ * document patches in O(1) through the view reconciler.
72
+ *
73
+ * @param {string} source
74
+ * @param {{ theme?: any, [k: string]: any }} [options]
75
+ * @returns {CompiledMermaid}
76
+ */
77
+ export declare function compileMermaid(source: string, options?: {
78
+ theme?: any;
79
+ [k: string]: any;
80
+ }): CompiledMermaid;
81
+ /**
82
+ * A host-DOM renderer (mirrors `@jarenjs/md`'s `createMdRenderer`).
83
+ * Owns a `@jarenjs/view` DOM renderer over `container` and patches the
84
+ * rendered SVG on each `render(docOrSource)` call. `createDomRenderer`
85
+ * touches no DOM until it is handed a container, so importing it keeps
86
+ * the engine host-agnostic.
87
+ *
88
+ * @param {{ container: any, document?: any, theme?: any, [k: string]: any }} config
89
+ * @returns {(docOrSource: any) => void}
90
+ */
91
+ export declare function createMermaidRenderer(config: {
92
+ container: any;
93
+ document?: any;
94
+ theme?: any;
95
+ [k: string]: any;
96
+ }): (docOrSource: any) => void;
97
+ export { hashContent as contentHash };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @file Optional pan/zoom/touch for a rendered diagram.
3
+ *
4
+ * The render stays pure: this module is never imported by it, runs only in a
5
+ * browser, and only when a consumer opts in with `mermaidPlugin({ interactive:
6
+ * true })`. Server-rendered output is byte-identical with and without it, and
7
+ * a page that never enables it tree-shakes the whole file away.
8
+ *
9
+ * Everything happens on the SVG's `viewBox`. Nothing re-renders, nothing is
10
+ * re-parsed, no `eval`, no `innerHTML` — panning is four numbers changing.
11
+ *
12
+ * The interaction rules are chosen so the diagram never fights the page,
13
+ * which is the usual failure of embedded zoomable content:
14
+ *
15
+ * - **A plain wheel scrolls the page.** Zoom needs ctrl/⌘ (the browser's own
16
+ * zoom gesture) or the on-diagram buttons. Hijacking the wheel is the
17
+ * fastest way to make a document unreadable.
18
+ * - **A one-finger drag pans only once zoomed in.** At rest the whole
19
+ * diagram is visible, so there is nothing to pan to, and a swipe should
20
+ * scroll the page like every other element. `touch-action` is switched to
21
+ * match, so the browser never has to guess.
22
+ * - **Two fingers always pinch-zoom**, because that gesture means nothing
23
+ * else inside a figure.
24
+ * - **Keyboard works**: the figure is focusable, `+`/`-`/`0` zoom and reset,
25
+ * arrows pan. A pointer-only zoom control is not usable by everyone.
26
+ */
27
+ /**
28
+ * Attach pan/zoom to one rendered diagram element.
29
+ * @param {any} el the block element wrapping the `<svg>`
30
+ * @param {{ document?: any }} [env] injection seam for tests
31
+ * @returns {(() => void)|undefined} a teardown function, or undefined when
32
+ * there is nothing to attach to
33
+ */
34
+ export declare function attachInteractiveDiagram(el: any, env?: {
35
+ document?: any;
36
+ }): (() => void) | undefined;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @file Flowchart layout: a compact "dagre-lite" — longest-path rank
3
+ * assignment, stable within-rank ordering, banded coordinate
4
+ * assignment, and straight border-clipped edge routing. Pure and
5
+ * deterministic (same AST → identical geometry), so the golden-JSON
6
+ * tests catch any drift. Output is a host-free `PositionedDiagram`.
7
+ */
8
+ /**
9
+ * @param {any} ast flowchart AST
10
+ * @returns {any} PositionedDiagram
11
+ */
12
+ export declare function layoutFlowchart(ast: any): any;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @file Sequence layout: actor lifeline x-positions, message y-advance,
3
+ * activation bars, note boxes and nested block frames
4
+ * (loop/alt/opt/par). Pure and deterministic; emits a host-free
5
+ * `PositionedDiagram`. Geometry is an approximation over the headless
6
+ * text metrics (no DOM) — pixel parity is a non-goal.
7
+ */
8
+ /**
9
+ * @param {any} ast sequence AST
10
+ * @returns {any} PositionedDiagram
11
+ */
12
+ export declare function layoutSequence(ast: any): any;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @file State-diagram layout: an ADAPTER, not a second algorithm. The
3
+ * state AST (states + labeled transitions + `[*]` pseudo-states) maps
4
+ * onto the flowchart layout's input vocabulary — states as rounded
5
+ * nodes, transition labels as edge labels, the start/end pseudo-states
6
+ * as synthetic `statedot`/`doublecircle` nodes — and `layoutFlowchart`
7
+ * does the ranking, ordering and routing. Same AST → identical
8
+ * geometry, like every layout in this component.
9
+ *
10
+ * Composite states arrive flattened from the parser (the `parent`
11
+ * field is recorded but not drawn as a cluster in v1 — the honest
12
+ * limitation lives in MERMAID-FORMAT §6).
13
+ */
14
+ /**
15
+ * Lay out a state AST through the flowchart engine.
16
+ * @param {any} ast state AST ({ states, transitions })
17
+ * @returns {any} PositionedDiagram
18
+ */
19
+ export declare function layoutState(ast: any): any;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file Class-diagram grammar → class AST. Supports `class Foo { … }`
3
+ * bodies, `Foo : +member` line form, and relations
4
+ * (`<|--`, `*--`, `o--`, `-->`, `..>`, `..|>`) with optional `: label`.
5
+ * Geometry-free: members and relations preserve declaration order.
6
+ */
7
+ /**
8
+ * @param {string[]} lines
9
+ * @returns {object}
10
+ */
11
+ export declare function parseClass(lines: string[]): object;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @file Config extraction: the leading `---` front-matter block and any
3
+ * `%%{init: {...}}%%` directives → a plain-JSON `config` (MERMAID-FORMAT
4
+ * §3).
5
+ *
6
+ * The raw source is never consumed here — this returns the cleaned body
7
+ * (front-matter, init directives and `%%` comments removed) plus the
8
+ * merged config and title, and the original source stays in the
9
+ * Markdown fence `value` so `toMarkdown` round-trips verbatim.
10
+ *
11
+ * Front-matter is a YAML subset. The engine may NOT statically import
12
+ * `@jarenjs/md` (two-layer rule), so a small built-in subset parser is
13
+ * the default; a host that already has `@jarenjs/md` can inject its
14
+ * richer `parseFrontmatter` through `options.parseFrontmatter`.
15
+ */
16
+ export type MermaidConfigResult = {
17
+ /**
18
+ * merged config object
19
+ */
20
+ config: Record<string, any>;
21
+ /**
22
+ * front-matter `title`, if any
23
+ */
24
+ title: string | null;
25
+ /**
26
+ * source with front-matter/init/comments stripped
27
+ */
28
+ body: string;
29
+ };
30
+ /**
31
+ * @typedef {object} MermaidConfigResult
32
+ * @property {Record<string, any>} config merged config object
33
+ * @property {string|null} title front-matter `title`, if any
34
+ * @property {string} body source with front-matter/init/comments stripped
35
+ */
36
+ /**
37
+ * Extract config + title and return the cleaned diagram body.
38
+ * @param {string} source
39
+ * @param {{ parseFrontmatter?: (text: string) => any }} [options]
40
+ * @returns {MermaidConfigResult}
41
+ */
42
+ export declare function parseMermaidConfig(source: string, options?: {
43
+ parseFrontmatter?: (text: string) => any;
44
+ }): MermaidConfigResult;
45
+ /**
46
+ * Parse a small YAML subset: `key: value` and one level of nesting via
47
+ * two-space indentation. Values are scalars (string/number/bool/null).
48
+ * Deliberately minimal — the documented default when `@jarenjs/md`'s
49
+ * parser is not injected.
50
+ * @param {string} text
51
+ * @returns {Record<string, any>}
52
+ */
53
+ export declare function parseYamlSubset(text: string): Record<string, any>;
54
+ /**
55
+ * Parse the relaxed object inside `%%{init: … }%%`. Tries strict JSON
56
+ * first, then a light normalization (quote bare keys, single→double
57
+ * quotes). Returns `null` on failure (config parsing never throws).
58
+ * @param {string} text
59
+ * @returns {Record<string, any> | null}
60
+ */
61
+ export declare function parseLooseObject(text: string): Record<string, any> | null;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file ER-diagram grammar → ER AST. Entity blocks
3
+ * (`CUSTOMER { string name PK }`) and relationships
4
+ * (`CUSTOMER ||--o{ ORDER : places`). Cardinality tokens are preserved
5
+ * verbatim for a faithful, geometry-free model.
6
+ */
7
+ /**
8
+ * @param {string[]} lines
9
+ * @returns {object}
10
+ */
11
+ export declare function parseEr(lines: string[]): object;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file Flowchart grammar → flowchart AST. Flowchart and sequence are
3
+ * the two fully-modeled diagram types; this is the first.
4
+ *
5
+ * Char-code recursive descent over one statement at a time. Every
6
+ * pattern regex is a module constant used with the sticky (`y`) flag so
7
+ * there is no per-call `RegExp` allocation; the vertex/edge chain is a
8
+ * hand-written scan. Produces the geometry-free flowchart AST from
9
+ * `ast.js` — nodes, edges, subgraphs, classDef/class/style — preserving
10
+ * shape, label and declaration order so `to-mermaid.js` is a fixed
11
+ * point.
12
+ */
13
+ /**
14
+ * Parse a flowchart body (config already stripped) into the flowchart
15
+ * AST. `keyword`/`firstLine` give the header; `direction` overrides.
16
+ * @param {string[]} lines body lines
17
+ * @param {number} lineOffset absolute line number of `lines[0]`
18
+ * @param {string} direction detected direction
19
+ * @returns {object}
20
+ */
21
+ export declare function parseFlowchart(lines: string[], lineOffset: number, direction: string): object;
22
+ /**
23
+ * Strip surrounding matching quotes from a label.
24
+ * @param {string} s @returns {string}
25
+ */
26
+ export declare function stripQuotes(s: string): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file Gantt grammar → gantt AST: a schedule DAG. Header
3
+ * directives (`title`, `dateFormat`, `axisFormat`, `excludes`) go to
4
+ * `meta`; `section` groups tasks; task rows keep their raw metadata
5
+ * string (`:done, id, 2014-01-06, 3d`) verbatim, geometry-free.
6
+ */
7
+ /**
8
+ * @param {string[]} lines
9
+ * @returns {object}
10
+ */
11
+ export declare function parseGantt(lines: string[]): object;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @file `parseMermaid`: detect the diagram type + config on the first
3
+ * non-config line, dispatch to the type parser, and assemble the shared
4
+ * `DiagramDocument` envelope.
5
+ *
6
+ * Flowchart and sequence are fully modeled. The remaining
7
+ * first-class types (class, ER, state, gantt, pie) plug in through
8
+ * `TYPE_PARSERS`; secondary types (mindmap, gitGraph, journey, timeline,
9
+ * quadrantChart) parse-accept into a geometry-free `rawAst` and are
10
+ * counted honestly in the coverage scorecard.
11
+ */
12
+ /** Types that parse-accept into a placeholder in the coverage scorecard. */
13
+ export declare const SECONDARY_TYPES: Set<string>;
14
+ /**
15
+ * Parse Mermaid source into a `DiagramDocument`.
16
+ * @param {string} source
17
+ * @param {{ parseFrontmatter?: (text: string) => any }} [options]
18
+ * @returns {import('../ast.js').DiagramDocument}
19
+ */
20
+ export declare function parseMermaid(source: string, options?: {
21
+ parseFrontmatter?: (text: string) => any;
22
+ }): import('../ast.js').DiagramDocument;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file Pie grammar → pie AST. `pie [showData]` then `"label" : value`
3
+ * rows, with an optional `title …`.
4
+ */
5
+ /**
6
+ * @param {string[]} lines
7
+ * @param {number} lineOffset
8
+ * @param {string} header
9
+ * @returns {object}
10
+ */
11
+ export declare function parsePie(lines: string[], lineOffset: number, header: string): object;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @file Sequence grammar → sequence AST. Flowchart and sequence are
3
+ * the two fully-modeled diagram types; this is the second.
4
+ *
5
+ * Line-oriented, with a block stack for loop/alt/opt/par/critical/break.
6
+ * Explicitly declared participants keep their declaration order; a
7
+ * message to an undeclared actor is legal (the layout pass creates the
8
+ * lifeline), so the AST records only what the source states — faithful
9
+ * and geometry-free. Module-const regexes only.
10
+ */
11
+ /**
12
+ * @param {string[]} lines body lines (config stripped)
13
+ * @param {number} lineOffset absolute line number of `lines[0]`
14
+ * @returns {object}
15
+ */
16
+ export declare function parseSequence(lines: string[], lineOffset: number): object;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @file State-diagram grammar (`stateDiagram-v2`) → state AST. Models
3
+ * the finite state machine faithfully: states, transitions
4
+ * (`A --> B : label`), the `[*]` start/end pseudo-states, `state "x" as
5
+ * s` descriptions and `s : desc` labels. This is the AST the flagship
6
+ * `state ⇄ workflow` JSLT projection consumes.
7
+ *
8
+ * A transition carries its verbatim `label` — what renderers draw and
9
+ * `toMermaid` prints — plus the label's UML reading, parsed into
10
+ * `event [guard] / effect` parts (each null when absent). A label that
11
+ * fits no UML pattern reads whole as the event, so plain labels keep
12
+ * their historical meaning byte for byte.
13
+ *
14
+ * Composite states (`state Foo { … }`) are flattened one level: the
15
+ * inner transitions are captured with their parent recorded, keeping the
16
+ * AST geometry-free.
17
+ */
18
+ /**
19
+ * @param {string[]} lines
20
+ * @returns {object}
21
+ */
22
+ export declare function parseState(lines: string[]): object;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @file The Markdown plugin — the md→mermaid dependency arrow.
3
+ * `mermaidPlugin()` returns a **plain, self-frozen object**
4
+ * shaped exactly like `@jarenjs/md`'s `MdPlugin` typedef, but it does
5
+ * **not** import `definePlugin` from `@jarenjs/md` — so there is no
6
+ * import cycle. `@jarenjs/md` re-exports this and adds `@jarenjs/mermaid`
7
+ * to its dependencies; consumers who never use it tree-shake it away
8
+ * (`sideEffects:false`).
9
+ *
10
+ * `render` is pure, synchronous and error-safe: a `mermaid`
11
+ * fence becomes inline SVG with no injected instance and no `innerHTML`,
12
+ * so a Markdown document renders to a full SVG string through SSR with
13
+ * no browser — a capability the old injection wrapper lacked.
14
+ *
15
+ * `hydrate` exists only when a consumer asks for `interactive: true`. The
16
+ * render is complete without it: hydration adds pan/zoom/touch to an already
17
+ * finished SVG, so server output is byte-identical either way and a page that
18
+ * does not opt in never loads the module.
19
+ */
20
+ /**
21
+ * @param {{ theme?: any, [k: string]: any }} [options]
22
+ * @returns {Readonly<{ name: string, fences: string[], node: string, render: (node: any, h: any, ctx: any) => any }>}
23
+ */
24
+ export declare function mermaidPlugin(options?: {
25
+ theme?: any;
26
+ [k: string]: any;
27
+ }): Readonly<{
28
+ name: string;
29
+ fences: string[];
30
+ node: string;
31
+ render: (node: any, h: any, ctx: any) => any;
32
+ }>;
33
+ /**
34
+ * Refresh a `mermaid` fence node's source after a JSLT transform so the
35
+ * generic Markdown fence printer re-emits the new diagram. Because
36
+ * there is no per-plugin `toMarkdown` hook, this is the primitive that
37
+ * makes a transformed diagram round-trip through `toMarkdown`.
38
+ *
39
+ * @param {{ value: string, [k: string]: any }} node the fence node (mutated copy is caller's job)
40
+ * @param {import('./ast.js').DiagramDocument} newDoc the transformed document
41
+ * @returns {{ type: string, value: string, meta: any }} a fresh fence node
42
+ */
43
+ export declare function refreshMermaidFence(node: {
44
+ value: string;
45
+ [k: string]: any;
46
+ }, newDoc: import('./ast.js').DiagramDocument): {
47
+ type: string;
48
+ value: string;
49
+ meta: any;
50
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @file The error vnode. The render path never
3
+ * throws: a parse/layout failure becomes a clear error box — message +
4
+ * offending line — mirroring Mermaid's own error box, keyed so the
5
+ * patcher swaps it cleanly.
6
+ *
7
+ * It themes like every other diagram (DESIGN.md §7): concrete colors ride
8
+ * as presentation attributes so `toSvgString()` stays standalone-valid,
9
+ * and the root carries the inline `--mm-*` stamp plus a class per shape,
10
+ * so a host theme re-colors the error box along with the diagrams it
11
+ * replaces. The font is pinned to monospace because the box quotes source.
12
+ */
13
+ import { createTheme } from '../theme.js';
14
+ /**
15
+ * @param {string} message
16
+ * @param {number} [line]
17
+ * @param {string} [sourceLine] the offending source line, if known
18
+ * @param {ReturnType<typeof createTheme>} [theme] the resolved theme; the
19
+ * default keeps the vnode renderable on its own (a parse failure has no
20
+ * document to read a theme from)
21
+ * @returns {any} an SVG error vnode
22
+ */
23
+ export declare function errorVnode(message: string, line?: number, sourceLine?: string, theme?: ReturnType<typeof createTheme>): any;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @file Flowchart renderer: `PositionedDiagram` → pure-vnode SVG. One
3
+ * specialized closure over the scene graph; arrowheads are inline
4
+ * polygons (no `<marker>` id collisions across diagrams on one page),
5
+ * every shape carries a `mm-*` class for CSS re-theming and concrete
6
+ * theme colors for standalone SSR.
7
+ */
8
+ /**
9
+ * @param {any} scene PositionedDiagram (flowchart or state, via its adapter)
10
+ * @param {{ tokens: Record<string,string>, cssVars: Record<string,string> }} theme
11
+ * @param {string} hash content hash for the root key
12
+ * @param {string} [rootClass] root `class` — the state renderer adds `mm-state`
13
+ * @returns {any}
14
+ */
15
+ export declare function renderFlowchart(scene: any, theme: {
16
+ tokens: Record<string, string>;
17
+ cssVars: Record<string, string>;
18
+ }, hash: string, rootClass?: string): any;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @file The render dispatcher. Turns a `DiagramDocument` (or raw source)
3
+ * into a pure-vnode SVG, choosing the specialized layout+render closure
4
+ * per diagram type, and **never throws**: a
5
+ * parse/layout error becomes an error vnode.
6
+ */
7
+ /**
8
+ * Compute the pure `PositionedDiagram` scene for a document (no vnode).
9
+ * Returns `null` for types without a geometric layout (structured/raw).
10
+ * @param {import('../ast.js').DiagramDocument} doc
11
+ * @returns {any}
12
+ */
13
+ export declare function layoutDiagram(doc: import('../ast.js').DiagramDocument): any;
14
+ /**
15
+ * Render a doc or source to a pure-vnode SVG. Error-safe.
16
+ * @param {import('../ast.js').DiagramDocument | string} docOrSource
17
+ * @param {{ theme?: any, [k: string]: any }} [options]
18
+ * @returns {any} an SVG vnode
19
+ */
20
+ export declare function diagramToVnode(docOrSource: import('../ast.js').DiagramDocument | string, options?: {
21
+ theme?: any;
22
+ [k: string]: any;
23
+ }): any;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @file Renderers for the first-class types beyond flowchart and
3
+ * sequence, and an honest placeholder for the deferred secondary
4
+ * types. Pie is
5
+ * a real chart; class/ER/state/gantt render as structured panels — a
6
+ * readable, geometry-light view that renders without error and so counts
7
+ * honestly in the coverage scorecard. Secondary types (mindmap,
8
+ * gitGraph, journey, timeline) render a labeled "not yet laid out"
9
+ * placeholder.
10
+ */
11
+ /**
12
+ * Pie rendering delegates to `@jarenjs/charts` (the pie engine's single
13
+ * home); the options carry the mermaid class names, palette and theme
14
+ * so the SVG is byte-identical to the pre-delegation renderer.
15
+ * @param {any} ast pie AST
16
+ * @param {any} theme
17
+ * @param {string} hash
18
+ * @returns {any}
19
+ */
20
+ export declare function renderPie(ast: any, theme: any, hash: string): any;
21
+ /**
22
+ * Render a structured panel: a title and a list of sections, each a
23
+ * bordered box with a heading and text rows.
24
+ * @param {string} title
25
+ * @param {{ heading: string, rows: string[] }[]} sections
26
+ * @param {any} theme
27
+ * @param {string} hash
28
+ * @returns {any}
29
+ */
30
+ export declare function renderStructured(title: string, sections: {
31
+ heading: string;
32
+ rows: string[];
33
+ }[], theme: any, hash: string): any;
34
+ /**
35
+ * The honest placeholder for a parse-accepted secondary type.
36
+ * @param {string} type
37
+ * @param {any} theme
38
+ * @param {string} hash
39
+ * @returns {any}
40
+ */
41
+ export declare function renderPlaceholder(type: string, theme: any, hash: string): any;
42
+ /**
43
+ * Build the sections for the structured renderers.
44
+ * @param {string} diagram
45
+ * @param {any} ast
46
+ * @returns {{ title: string, sections: { heading: string, rows: string[] }[] }}
47
+ */
48
+ export declare function structuredSections(diagram: string, ast: any): {
49
+ title: string;
50
+ sections: {
51
+ heading: string;
52
+ rows: string[];
53
+ }[];
54
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @file Sequence renderer: `PositionedDiagram` → pure-vnode SVG.
3
+ * Actor boxes (top and bottom), dashed lifelines, activation bars,
4
+ * messages with solid/dotted lines and arrow/open/cross/async heads,
5
+ * note boxes and block frames.
6
+ */
7
+ /**
8
+ * @param {any} scene PositionedDiagram (sequence)
9
+ * @param {{ tokens: Record<string,string>, cssVars: Record<string,string> }} theme
10
+ * @param {string} hash
11
+ * @returns {any}
12
+ */
13
+ export declare function renderSequence(scene: any, theme: {
14
+ tokens: Record<string, string>;
15
+ cssVars: Record<string, string>;
16
+ }, hash: string): any;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @file `classDef` / `class` / `style` resolution.
3
+ *
4
+ * The parser has always recorded these three statements; nothing consumed
5
+ * them, so a diagram that styled a node rendered identically to one that did
6
+ * not. This module turns them into per-node style objects the layout attaches
7
+ * to its positioned nodes, which is what lets a diagram carry emphasis —
8
+ * "this box is the input", "this one is an aside" — instead of every node
9
+ * looking the same.
10
+ *
11
+ * One built-in class ships: **`note`**. Mermaid has no flowchart note, and a
12
+ * diagram that cannot annotate a node loses exactly the information an ASCII
13
+ * drawing used to carry in a margin comment. Rather than invent syntax for
14
+ * it, `note` is a class any diagram can apply with the standard `class`
15
+ * statement, themed from the `note*` tokens the sequence renderer already
16
+ * uses. A dotted link to a note-classed node reads as an annotation and stays
17
+ * valid Mermaid that other tools can still parse.
18
+ */
19
+ /**
20
+ * Parse a Mermaid style string (`fill:#eee,stroke-width:2px`) into an object.
21
+ * Unknown properties are kept: a consumer may understand more than this one,
22
+ * and silently dropping a declaration the author wrote is the same class of
23
+ * dishonesty as dropping a schema constraint.
24
+ * @param {string} source
25
+ * @returns {Record<string,string>}
26
+ */
27
+ export declare function parseStyleString(source: string): Record<string, string>;
28
+ /**
29
+ * Resolve every node's styles from a flowchart AST.
30
+ *
31
+ * Precedence, lowest to highest: the built-in `note` class, then each
32
+ * `classDef` in the order the node's `class` statements applied them, then a
33
+ * per-node `style` statement. That is Mermaid's own order — later wins — and
34
+ * it is what lets a diagram say "these are all notes, except this one is
35
+ * red".
36
+ * @param {any} ast flowchart AST
37
+ * @returns {Map<string, Record<string,string>>} node id -> style properties
38
+ */
39
+ export declare function resolveNodeStyles(ast: any): Map<string, Record<string, string>>;
40
+ /**
41
+ * The author's styles as an inline CSS declaration, or `null` when there are
42
+ * none.
43
+ *
44
+ * This has to be a `style` attribute rather than presentation attributes:
45
+ * the bundled stylesheet sets `.mermaid .mm-node-shape { fill: var(...) }` so
46
+ * a themed page can retheme every diagram at once, and a CSS rule outranks a
47
+ * presentation attribute. Emitting `fill="..."` therefore looked correct in
48
+ * the SSR string and was silently overridden the moment the stylesheet
49
+ * loaded — a classDef that worked in a test and did nothing on the page.
50
+ * Inline style outranks the rule, which is the precedence an author asking
51
+ * for a specific colour expects.
52
+ * @param {Record<string,string>|undefined} styles
53
+ * @param {Record<string,string>} tokens theme tokens
54
+ * @returns {string|null}
55
+ */
56
+ export declare function shapeStyle(styles: Record<string, string> | undefined, tokens: Record<string, string>): string | null;
57
+ /**
58
+ * The SVG attributes a resolved style object contributes to a shape, with the
59
+ * built-in `note` marker expanded against the live theme.
60
+ * @param {Record<string,string>|undefined} styles
61
+ * @param {Record<string,string>} tokens theme tokens
62
+ * @returns {Record<string,string>}
63
+ */
64
+ export declare function shapeAttributes(styles: Record<string, string> | undefined, tokens: Record<string, string>): Record<string, string>;
65
+ /**
66
+ * The text color for a node, or null to keep the theme's.
67
+ *
68
+ * An author-specified `fill` is a CONSTANT — it does not follow light/dark —
69
+ * so the ink over it must not follow the theme either. A pale `fill:#dcfce7`
70
+ * under a dark theme would otherwise get the theme's light text and the label
71
+ * would vanish into its own box. The ink is therefore derived from the fill's
72
+ * luminance, exactly as chart tiles do it, unless the author named a `color`
73
+ * themselves.
74
+ *
75
+ * The built-in `note` class is the opposite case and keeps the theme's note
76
+ * ink: its fill is a theme token too, so the pair moves together.
77
+ * @param {Record<string,string>|undefined} styles
78
+ * @param {Record<string,string>} tokens theme tokens
79
+ * @returns {string|null}
80
+ */
81
+ export declare function textColor(styles: Record<string, string> | undefined, tokens: Record<string, string>): string | null;