@zombie-mermaid/core 4.0.0 → 4.2.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/dist/index.cjs +7 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -17
- package/dist/index.d.ts +62 -17
- package/dist/index.js +215 -160
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/cluster-edges.test.ts +47 -0
- package/src/__tests__/diagram-type.test.ts +15 -0
- package/src/__tests__/theme.test.ts +18 -15
- package/src/cluster-edges.ts +78 -0
- package/src/diagram-type.ts +9 -1
- package/src/index.ts +1 -0
- package/src/multiline-utils.ts +66 -2
- package/src/theme.ts +53 -37
- package/src/generated/mono-font-subset.ts +0 -32
package/dist/index.d.cts
CHANGED
|
@@ -63,22 +63,15 @@ export declare function applyInitConfig(options: RenderOptions, config: InitConf
|
|
|
63
63
|
* Any other value is treated as a literal font name: sanitized and quoted
|
|
64
64
|
* exactly as before.
|
|
65
65
|
*
|
|
66
|
-
* `
|
|
67
|
-
* attribute types) never reaches out to Google Fonts at all
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* `woff2` data URI, generated by scripts/build-mono-font-subset.ts into
|
|
74
|
-
* ./generated/mono-font-subset.ts — directly in the SVG's own `<style>`
|
|
75
|
-
* block. Unlike `font` above, this isn't caller-configurable: it's the same
|
|
76
|
-
* embed for every consumer, on by default, with no network request either
|
|
77
|
-
* way — a strict improvement over the dead-or-alive CDN fetch it replaces,
|
|
78
|
-
* and the only way a *standalone* SVG (no surrounding host page providing
|
|
79
|
-
* its own copy of the font) renders `.mono` text correctly out of the box.
|
|
66
|
+
* `mono`'s `.mono` rule (class-diagram method signatures, ER-diagram
|
|
67
|
+
* attribute types) never reaches out to Google Fonts at all. The caller
|
|
68
|
+
* supplies a self-hosted {@link MonoFontEmbed} (a base64 `woff2` `@font-face`
|
|
69
|
+
* plus its family name), which is inlined directly in the SVG's own `<style>`
|
|
70
|
+
* block (#1061). The font data itself lives in `@zombie-mermaid/svg-renderer`
|
|
71
|
+
* (see its `buildSvgStyleBlock`), not here, so ASCII-only consumers of
|
|
72
|
+
* `core` never carry it (#1319). Pass `false` to omit the `.mono` rule.
|
|
80
73
|
*/
|
|
81
|
-
export declare function buildStyleBlock(font: string,
|
|
74
|
+
export declare function buildStyleBlock(font: string, mono: MonoFontEmbed | false, nonce?: string): string;
|
|
82
75
|
|
|
83
76
|
/**
|
|
84
77
|
* Options applicable to class diagrams (`classDiagram`). Class diagrams use
|
|
@@ -99,6 +92,23 @@ export declare type CommonRenderOptions = Pick<RenderOptions, 'bg' | 'fg' | 'lin
|
|
|
99
92
|
/** How an edge path is interpolated between its routed points. */
|
|
100
93
|
export declare type CurveStyle = 'linear' | 'basis' | 'natural' | 'step' | 'stepBefore' | 'stepAfter';
|
|
101
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Decode Mermaid's entity codes (`#quot;`, `#lt;`, `#35;`, `#x5B;`), the way
|
|
97
|
+
* Mermaid writes characters that would otherwise end a label or break its
|
|
98
|
+
* syntax. Call it on a single already-parsed label, never on diagram source:
|
|
99
|
+
* decoding up front would let the characters it produces (`<`, `"`, `[`)
|
|
100
|
+
* change how the line parses, and would hit `#fff;` colors in style lines.
|
|
101
|
+
* Unknown names and out-of-range numbers are left untouched.
|
|
102
|
+
*/
|
|
103
|
+
export declare function decodeMermaidEntities(text: string): string;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Decode HTML/XML entities (`"`, `<`, `#`, `[`) in one label,
|
|
107
|
+
* in a single pass so `&lt;` becomes `<` rather than `<`. Used by the
|
|
108
|
+
* ASCII renderer, which (unlike SVG) has no source-level decode step.
|
|
109
|
+
*/
|
|
110
|
+
export declare function decodeXmlEntitiesInLabel(text: string): string;
|
|
111
|
+
|
|
102
112
|
/** Default bg/fg when no colors are provided (zinc light) */
|
|
103
113
|
export declare const DEFAULTS: Readonly<{
|
|
104
114
|
bg: string;
|
|
@@ -125,7 +135,7 @@ export declare function detectDiagramType(text: string): DiagramType;
|
|
|
125
135
|
* need to enumerate the types (e.g. the MCP `list_diagram_types` tool) never
|
|
126
136
|
* keep a duplicate list that could drift.
|
|
127
137
|
*/
|
|
128
|
-
export declare const DIAGRAM_TYPES: readonly ["flowchart", "sequence", "class", "er", "xychart", "architecture", "c4"];
|
|
138
|
+
export declare const DIAGRAM_TYPES: readonly ["flowchart", "sequence", "class", "er", "xychart", "architecture", "c4", "pie"];
|
|
129
139
|
|
|
130
140
|
/**
|
|
131
141
|
* Diagram color configuration.
|
|
@@ -292,6 +302,15 @@ export declare interface InitConfig {
|
|
|
292
302
|
/** True when `value` is one of the five directions Mermaid recognizes. */
|
|
293
303
|
export declare function isDirection(value: string): value is Direction;
|
|
294
304
|
|
|
305
|
+
/**
|
|
306
|
+
* True when one endpoint of `edge` is a subgraph id and the other is a node or
|
|
307
|
+
* subgraph nested inside it, at any depth.
|
|
308
|
+
*/
|
|
309
|
+
export declare function isEdgeWithinOwnCluster(edge: {
|
|
310
|
+
source: string;
|
|
311
|
+
target: string;
|
|
312
|
+
}, subgraphById: Map<string, MermaidSubgraph>): boolean;
|
|
313
|
+
|
|
295
314
|
/** True if `line` is an init directive. */
|
|
296
315
|
export declare function isInitDirective(line: string): boolean;
|
|
297
316
|
|
|
@@ -451,6 +470,17 @@ export declare function mixHexColors(fg: string, bg: string, pct: number): strin
|
|
|
451
470
|
*/
|
|
452
471
|
export declare function mixSrgb(c1: RgbaColor, c2: RgbaColor, p1?: number, p2?: number): RgbaColor | null;
|
|
453
472
|
|
|
473
|
+
/**
|
|
474
|
+
* A self-hosted monospace font a caller embeds in the SVG `<style>` block
|
|
475
|
+
* for the `.mono` rule. See `buildStyleBlock`.
|
|
476
|
+
*/
|
|
477
|
+
export declare interface MonoFontEmbed {
|
|
478
|
+
/** Font family name, listed first in the `.mono` rule's font stack. */
|
|
479
|
+
family: string;
|
|
480
|
+
/** The complete `@font-face { ... }` rule (typically a base64 data URI). */
|
|
481
|
+
faceCss: string;
|
|
482
|
+
}
|
|
483
|
+
|
|
454
484
|
/** Metrics for multi-line text measurement */
|
|
455
485
|
export declare interface MultilineMetrics {
|
|
456
486
|
/** Maximum line width in pixels */
|
|
@@ -1136,8 +1166,13 @@ export declare interface SvgEmitOptions {
|
|
|
1136
1166
|
* See #239 — forces no root `role` so the link
|
|
1137
1167
|
* stays reachable, regardless of `decorative`.
|
|
1138
1168
|
* @param styleAttribute - Emit the root `style="…"` attribute. Default true.
|
|
1169
|
+
* @param description - Accessible description: a `<desc id="zm-desc-N">`
|
|
1170
|
+
* after the title plus `aria-describedby` on the root.
|
|
1171
|
+
* Follows the same rules as `title` (dropped when
|
|
1172
|
+
* decorative without interactive links). Used for
|
|
1173
|
+
* Mermaid's `accDescr`.
|
|
1139
1174
|
*/
|
|
1140
|
-
export declare function svgOpenTag(width: number, height: number, colors: DiagramColors, transparent?: boolean, title?: string, decorative?: boolean, hasInteractiveLinks?: boolean, styleAttribute?: boolean): string;
|
|
1175
|
+
export declare function svgOpenTag(width: number, height: number, colors: DiagramColors, transparent?: boolean, title?: string, decorative?: boolean, hasInteractiveLinks?: boolean, styleAttribute?: boolean, description?: string): string;
|
|
1141
1176
|
|
|
1142
1177
|
export declare type ThemeName = keyof typeof THEMES;
|
|
1143
1178
|
|
|
@@ -1243,6 +1278,16 @@ export declare function withDirectionOverride<T extends {
|
|
|
1243
1278
|
direction?: Direction;
|
|
1244
1279
|
}>(diagram: T, override: Direction | undefined): T;
|
|
1245
1280
|
|
|
1281
|
+
/**
|
|
1282
|
+
* `graph` without its edges between a node and a subgraph that contains it.
|
|
1283
|
+
* The parser also registers a subgraph id used as an edge endpoint as a
|
|
1284
|
+
* placeholder entry in `graph.nodes`; one no remaining edge refers to is
|
|
1285
|
+
* removed too, so the result equals the graph parsed without those edges.
|
|
1286
|
+
* Returns `graph` itself (same reference) when it has none, and never mutates
|
|
1287
|
+
* its input.
|
|
1288
|
+
*/
|
|
1289
|
+
export declare function withoutOwnClusterEdges(graph: MermaidGraph): MermaidGraph;
|
|
1290
|
+
|
|
1246
1291
|
/**
|
|
1247
1292
|
* Options applicable to XY charts (`xychart-beta`). XY charts have no
|
|
1248
1293
|
* spacing/`direction`/`curve`/`fontSizes`/`layoutCache` concept (layout is
|
package/dist/index.d.ts
CHANGED
|
@@ -63,22 +63,15 @@ export declare function applyInitConfig(options: RenderOptions, config: InitConf
|
|
|
63
63
|
* Any other value is treated as a literal font name: sanitized and quoted
|
|
64
64
|
* exactly as before.
|
|
65
65
|
*
|
|
66
|
-
* `
|
|
67
|
-
* attribute types) never reaches out to Google Fonts at all
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* `woff2` data URI, generated by scripts/build-mono-font-subset.ts into
|
|
74
|
-
* ./generated/mono-font-subset.ts — directly in the SVG's own `<style>`
|
|
75
|
-
* block. Unlike `font` above, this isn't caller-configurable: it's the same
|
|
76
|
-
* embed for every consumer, on by default, with no network request either
|
|
77
|
-
* way — a strict improvement over the dead-or-alive CDN fetch it replaces,
|
|
78
|
-
* and the only way a *standalone* SVG (no surrounding host page providing
|
|
79
|
-
* its own copy of the font) renders `.mono` text correctly out of the box.
|
|
66
|
+
* `mono`'s `.mono` rule (class-diagram method signatures, ER-diagram
|
|
67
|
+
* attribute types) never reaches out to Google Fonts at all. The caller
|
|
68
|
+
* supplies a self-hosted {@link MonoFontEmbed} (a base64 `woff2` `@font-face`
|
|
69
|
+
* plus its family name), which is inlined directly in the SVG's own `<style>`
|
|
70
|
+
* block (#1061). The font data itself lives in `@zombie-mermaid/svg-renderer`
|
|
71
|
+
* (see its `buildSvgStyleBlock`), not here, so ASCII-only consumers of
|
|
72
|
+
* `core` never carry it (#1319). Pass `false` to omit the `.mono` rule.
|
|
80
73
|
*/
|
|
81
|
-
export declare function buildStyleBlock(font: string,
|
|
74
|
+
export declare function buildStyleBlock(font: string, mono: MonoFontEmbed | false, nonce?: string): string;
|
|
82
75
|
|
|
83
76
|
/**
|
|
84
77
|
* Options applicable to class diagrams (`classDiagram`). Class diagrams use
|
|
@@ -99,6 +92,23 @@ export declare type CommonRenderOptions = Pick<RenderOptions, 'bg' | 'fg' | 'lin
|
|
|
99
92
|
/** How an edge path is interpolated between its routed points. */
|
|
100
93
|
export declare type CurveStyle = 'linear' | 'basis' | 'natural' | 'step' | 'stepBefore' | 'stepAfter';
|
|
101
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Decode Mermaid's entity codes (`#quot;`, `#lt;`, `#35;`, `#x5B;`), the way
|
|
97
|
+
* Mermaid writes characters that would otherwise end a label or break its
|
|
98
|
+
* syntax. Call it on a single already-parsed label, never on diagram source:
|
|
99
|
+
* decoding up front would let the characters it produces (`<`, `"`, `[`)
|
|
100
|
+
* change how the line parses, and would hit `#fff;` colors in style lines.
|
|
101
|
+
* Unknown names and out-of-range numbers are left untouched.
|
|
102
|
+
*/
|
|
103
|
+
export declare function decodeMermaidEntities(text: string): string;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Decode HTML/XML entities (`"`, `<`, `#`, `[`) in one label,
|
|
107
|
+
* in a single pass so `&lt;` becomes `<` rather than `<`. Used by the
|
|
108
|
+
* ASCII renderer, which (unlike SVG) has no source-level decode step.
|
|
109
|
+
*/
|
|
110
|
+
export declare function decodeXmlEntitiesInLabel(text: string): string;
|
|
111
|
+
|
|
102
112
|
/** Default bg/fg when no colors are provided (zinc light) */
|
|
103
113
|
export declare const DEFAULTS: Readonly<{
|
|
104
114
|
bg: string;
|
|
@@ -125,7 +135,7 @@ export declare function detectDiagramType(text: string): DiagramType;
|
|
|
125
135
|
* need to enumerate the types (e.g. the MCP `list_diagram_types` tool) never
|
|
126
136
|
* keep a duplicate list that could drift.
|
|
127
137
|
*/
|
|
128
|
-
export declare const DIAGRAM_TYPES: readonly ["flowchart", "sequence", "class", "er", "xychart", "architecture", "c4"];
|
|
138
|
+
export declare const DIAGRAM_TYPES: readonly ["flowchart", "sequence", "class", "er", "xychart", "architecture", "c4", "pie"];
|
|
129
139
|
|
|
130
140
|
/**
|
|
131
141
|
* Diagram color configuration.
|
|
@@ -292,6 +302,15 @@ export declare interface InitConfig {
|
|
|
292
302
|
/** True when `value` is one of the five directions Mermaid recognizes. */
|
|
293
303
|
export declare function isDirection(value: string): value is Direction;
|
|
294
304
|
|
|
305
|
+
/**
|
|
306
|
+
* True when one endpoint of `edge` is a subgraph id and the other is a node or
|
|
307
|
+
* subgraph nested inside it, at any depth.
|
|
308
|
+
*/
|
|
309
|
+
export declare function isEdgeWithinOwnCluster(edge: {
|
|
310
|
+
source: string;
|
|
311
|
+
target: string;
|
|
312
|
+
}, subgraphById: Map<string, MermaidSubgraph>): boolean;
|
|
313
|
+
|
|
295
314
|
/** True if `line` is an init directive. */
|
|
296
315
|
export declare function isInitDirective(line: string): boolean;
|
|
297
316
|
|
|
@@ -451,6 +470,17 @@ export declare function mixHexColors(fg: string, bg: string, pct: number): strin
|
|
|
451
470
|
*/
|
|
452
471
|
export declare function mixSrgb(c1: RgbaColor, c2: RgbaColor, p1?: number, p2?: number): RgbaColor | null;
|
|
453
472
|
|
|
473
|
+
/**
|
|
474
|
+
* A self-hosted monospace font a caller embeds in the SVG `<style>` block
|
|
475
|
+
* for the `.mono` rule. See `buildStyleBlock`.
|
|
476
|
+
*/
|
|
477
|
+
export declare interface MonoFontEmbed {
|
|
478
|
+
/** Font family name, listed first in the `.mono` rule's font stack. */
|
|
479
|
+
family: string;
|
|
480
|
+
/** The complete `@font-face { ... }` rule (typically a base64 data URI). */
|
|
481
|
+
faceCss: string;
|
|
482
|
+
}
|
|
483
|
+
|
|
454
484
|
/** Metrics for multi-line text measurement */
|
|
455
485
|
export declare interface MultilineMetrics {
|
|
456
486
|
/** Maximum line width in pixels */
|
|
@@ -1136,8 +1166,13 @@ export declare interface SvgEmitOptions {
|
|
|
1136
1166
|
* See #239 — forces no root `role` so the link
|
|
1137
1167
|
* stays reachable, regardless of `decorative`.
|
|
1138
1168
|
* @param styleAttribute - Emit the root `style="…"` attribute. Default true.
|
|
1169
|
+
* @param description - Accessible description: a `<desc id="zm-desc-N">`
|
|
1170
|
+
* after the title plus `aria-describedby` on the root.
|
|
1171
|
+
* Follows the same rules as `title` (dropped when
|
|
1172
|
+
* decorative without interactive links). Used for
|
|
1173
|
+
* Mermaid's `accDescr`.
|
|
1139
1174
|
*/
|
|
1140
|
-
export declare function svgOpenTag(width: number, height: number, colors: DiagramColors, transparent?: boolean, title?: string, decorative?: boolean, hasInteractiveLinks?: boolean, styleAttribute?: boolean): string;
|
|
1175
|
+
export declare function svgOpenTag(width: number, height: number, colors: DiagramColors, transparent?: boolean, title?: string, decorative?: boolean, hasInteractiveLinks?: boolean, styleAttribute?: boolean, description?: string): string;
|
|
1141
1176
|
|
|
1142
1177
|
export declare type ThemeName = keyof typeof THEMES;
|
|
1143
1178
|
|
|
@@ -1243,6 +1278,16 @@ export declare function withDirectionOverride<T extends {
|
|
|
1243
1278
|
direction?: Direction;
|
|
1244
1279
|
}>(diagram: T, override: Direction | undefined): T;
|
|
1245
1280
|
|
|
1281
|
+
/**
|
|
1282
|
+
* `graph` without its edges between a node and a subgraph that contains it.
|
|
1283
|
+
* The parser also registers a subgraph id used as an edge endpoint as a
|
|
1284
|
+
* placeholder entry in `graph.nodes`; one no remaining edge refers to is
|
|
1285
|
+
* removed too, so the result equals the graph parsed without those edges.
|
|
1286
|
+
* Returns `graph` itself (same reference) when it has none, and never mutates
|
|
1287
|
+
* its input.
|
|
1288
|
+
*/
|
|
1289
|
+
export declare function withoutOwnClusterEdges(graph: MermaidGraph): MermaidGraph;
|
|
1290
|
+
|
|
1246
1291
|
/**
|
|
1247
1292
|
* Options applicable to XY charts (`xychart-beta`). XY charts have no
|
|
1248
1293
|
* spacing/`direction`/`curve`/`fontSizes`/`layoutCache` concept (layout is
|