@zombie-mermaid/svg-renderer 3.2.0 → 4.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.
Files changed (50) hide show
  1. package/dist/index.cjs +48 -38
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +42 -4
  4. package/dist/index.d.ts +42 -4
  5. package/dist/index.js +2567 -1766
  6. package/dist/index.js.map +1 -1
  7. package/package.json +3 -3
  8. package/src/__tests__/c4-label-clearance-1290.test.ts +112 -0
  9. package/src/__tests__/c4-line-ends-1208.test.ts +52 -0
  10. package/src/__tests__/c4-mermaid-reference.test.ts +56 -17
  11. package/src/__tests__/c4-text-width-1210.test.ts +43 -0
  12. package/src/__tests__/class-component-order-1249.test.ts +40 -0
  13. package/src/__tests__/class-member-right-padding-1238.test.ts +43 -0
  14. package/src/__tests__/class-namespace-1196.test.ts +165 -0
  15. package/src/__tests__/class-namespace-sparse-elk-1196.test.ts +96 -0
  16. package/src/__tests__/class-visibility-markers-1237.test.ts +27 -0
  17. package/src/__tests__/er-attribute-right-padding-1262.test.ts +47 -0
  18. package/src/__tests__/er-default-direction-1250.test.ts +69 -0
  19. package/src/__tests__/er-edge-label-contrast-1244.test.ts +58 -0
  20. package/src/__tests__/flowchart-parallel-edge-lanes-1308.test.ts +168 -0
  21. package/src/__tests__/sequence-label-clearance-1242.test.ts +162 -0
  22. package/src/__tests__/sequence-nested-activation-1241.test.ts +37 -0
  23. package/src/__tests__/svg-edge-to-own-cluster-1310.test.ts +32 -0
  24. package/src/__tests__/xychart-x-label-overlap-1243.test.ts +62 -0
  25. package/src/c4/arial-widths.ts +59 -0
  26. package/src/c4/layout.ts +234 -44
  27. package/src/c4/metrics.ts +56 -30
  28. package/src/c4/renderer.ts +1 -1
  29. package/src/class/layout.ts +178 -13
  30. package/src/class/renderer.ts +33 -4
  31. package/src/er/layout.ts +20 -4
  32. package/src/er/renderer.ts +12 -3
  33. package/src/generated/mono-font-subset.ts +32 -0
  34. package/src/layout-engine/back-edges.ts +73 -0
  35. package/src/layout-engine/compound-flat.ts +916 -0
  36. package/src/layout-engine/edge-bundling.ts +79 -0
  37. package/src/layout-engine/elk-graph-builder.ts +5 -4
  38. package/src/layout-engine/from-elk.ts +7 -2
  39. package/src/layout-engine/inner-edges.ts +329 -0
  40. package/src/layout-engine/layout-hints.ts +27 -0
  41. package/src/layout-engine/to-elk.ts +185 -25
  42. package/src/layout-engine.ts +42 -1
  43. package/src/registry.ts +3 -3
  44. package/src/renderer.ts +26 -2
  45. package/src/sequence/layout.ts +72 -4
  46. package/src/sequence/renderer.ts +155 -15
  47. package/src/styles.ts +28 -1
  48. package/src/title-gaps.ts +161 -0
  49. package/src/xychart/layout.ts +31 -2
  50. package/src/xychart/renderer.ts +1 -0
package/dist/index.d.cts CHANGED
@@ -26,6 +26,13 @@ import { SvgEmitOptions } from '@zombie-mermaid/core';
26
26
  import { XYChart } from '@zombie-mermaid/mermaid-parser';
27
27
  import { XyChartRenderOptions } from '@zombie-mermaid/core';
28
28
 
29
+ /**
30
+ * Distance from the bottom of a stick-figure (`actor`) icon to the vertical
31
+ * centre of its label. Shared with the renderer so the label lands where the
32
+ * layout reserved room for it.
33
+ */
34
+ export declare const ACTOR_LABEL_OFFSET = 14;
35
+
29
36
  /** Arrow head dimensions — matches spec: 8px wide × ~5px tall */
30
37
  export declare const ARROW_HEAD: {
31
38
  readonly width: 8;
@@ -88,6 +95,14 @@ export declare function buildElkLeafNode(id: string, size: {
88
95
  height: number;
89
96
  }, label?: string): ElkNode;
90
97
 
98
+ /**
99
+ * SVG `<style>` block for a diagram: core's `buildStyleBlock` plus, when
100
+ * `hasMonoFont` is set, the self-hosted mono font subset for the `.mono`
101
+ * rule. The subset lives here rather than in `core` because only SVG output
102
+ * embeds it (#1319).
103
+ */
104
+ export declare function buildSvgStyleBlock(font: string, hasMonoFont: boolean, nonce?: string): string;
105
+
91
106
  /**
92
107
  * Layout id for the i-th note. A class id is a run of non-whitespace
93
108
  * (`\S+` in the parser), so an id containing a space can never collide
@@ -122,6 +137,11 @@ export declare const CLS: {
122
137
  /** Horizontal / vertical padding inside a note box, around its text */
123
138
  readonly notePadX: 10;
124
139
  readonly notePadY: 6;
140
+ /** Space reserved above a namespace's classes for its title */
141
+ readonly namespaceTitleHeight: 28;
142
+ /** Padding between a namespace frame and its classes (other three sides) */
143
+ readonly namespacePad: 16;
144
+ readonly namespaceTitleFontSize: 12;
125
145
  };
126
146
 
127
147
  /**
@@ -171,10 +191,11 @@ export declare function directionToElk(dir: Direction | undefined, fallback: Elk
171
191
  * - **C4** — `DOWN`. `C4Diagram.direction` is never set by the parser (C4
172
192
  * sources have no direction statement), only by `RenderOptions.direction`,
173
193
  * so an unset one is the top-down layout every C4 diagram is drawn in.
174
- * - **ER** — `RIGHT`. An ER diagram's `direction` is optional
194
+ * - **ER** — `DOWN`. An ER diagram's `direction` is optional
175
195
  * (`ErDiagram.direction?`), left `undefined` when the source has no
176
- * `direction` statement, and this renderer has always laid those out
177
- * left-to-right. `direction TB`/`LR`/`BT`/`RL` in the source (or
196
+ * `direction` statement, and official Mermaid lays those out top-to-bottom
197
+ * (#1250; this renderer used to lay them out left-to-right).
198
+ * `direction TB`/`LR`/`BT`/`RL` in the source (or
178
199
  * `RenderOptions.direction`, applied via `withDirectionOverride`) still
179
200
  * wins over it.
180
201
  *
@@ -188,7 +209,7 @@ export declare const ELK_DIRECTION_FALLBACK: {
188
209
  readonly flowchart: "DOWN";
189
210
  readonly state: "DOWN";
190
211
  readonly class: "DOWN";
191
- readonly er: "RIGHT";
212
+ readonly er: "DOWN";
192
213
  readonly c4: "DOWN";
193
214
  };
194
215
 
@@ -340,6 +361,15 @@ export declare function layoutClassDiagramSync(diagram: ClassDiagram, options?:
340
361
  */
341
362
  export declare function layoutErDiagramSync(diagram: ErDiagram, options?: ErRenderOptions): PositionedErDiagram;
342
363
 
364
+ /**
365
+ * Lay out a flowchart, with its subgraphs arranged the way mermaid.js arranges
366
+ * them (see `layout-engine/compound-flat.ts`). Anything that layout doesn't
367
+ * handle, or can't make fit, is laid out by `layoutGraphSync`, so this is a
368
+ * drop-in for it wherever the graph is a flowchart. Other diagram types that
369
+ * share the engine (state, architecture) keep using `layoutGraphSync`.
370
+ */
371
+ export declare function layoutFlowchartSync(rawGraph: MermaidGraph, options?: FlowchartRenderOptions): PositionedGraph;
372
+
343
373
  /**
344
374
  * Lay out a parsed MermaidGraph using ELK.js (synchronous).
345
375
  * Returns a fully positioned graph ready for rendering.
@@ -630,4 +660,12 @@ export declare function themeCssVariables(options?: RenderOptions): string;
630
660
  */
631
661
  export declare function withDataSrc(svgTag: string, source: string | undefined): string;
632
662
 
663
+ /**
664
+ * Step between shown x-axis labels: 1 when every pair of neighbouring labels
665
+ * keeps `X_LABEL_MIN_GAP` of clear space, otherwise the smallest n for which
666
+ * every pair of shown (every n-th) labels does. Checked pairwise on the real
667
+ * widths so one long label doesn't thin out an otherwise roomy axis.
668
+ */
669
+ export declare function xLabelStep(labels: string[], bandWidth: number): number;
670
+
633
671
  export { }
package/dist/index.d.ts CHANGED
@@ -26,6 +26,13 @@ import { SvgEmitOptions } from '@zombie-mermaid/core';
26
26
  import { XYChart } from '@zombie-mermaid/mermaid-parser';
27
27
  import { XyChartRenderOptions } from '@zombie-mermaid/core';
28
28
 
29
+ /**
30
+ * Distance from the bottom of a stick-figure (`actor`) icon to the vertical
31
+ * centre of its label. Shared with the renderer so the label lands where the
32
+ * layout reserved room for it.
33
+ */
34
+ export declare const ACTOR_LABEL_OFFSET = 14;
35
+
29
36
  /** Arrow head dimensions — matches spec: 8px wide × ~5px tall */
30
37
  export declare const ARROW_HEAD: {
31
38
  readonly width: 8;
@@ -88,6 +95,14 @@ export declare function buildElkLeafNode(id: string, size: {
88
95
  height: number;
89
96
  }, label?: string): ElkNode;
90
97
 
98
+ /**
99
+ * SVG `<style>` block for a diagram: core's `buildStyleBlock` plus, when
100
+ * `hasMonoFont` is set, the self-hosted mono font subset for the `.mono`
101
+ * rule. The subset lives here rather than in `core` because only SVG output
102
+ * embeds it (#1319).
103
+ */
104
+ export declare function buildSvgStyleBlock(font: string, hasMonoFont: boolean, nonce?: string): string;
105
+
91
106
  /**
92
107
  * Layout id for the i-th note. A class id is a run of non-whitespace
93
108
  * (`\S+` in the parser), so an id containing a space can never collide
@@ -122,6 +137,11 @@ export declare const CLS: {
122
137
  /** Horizontal / vertical padding inside a note box, around its text */
123
138
  readonly notePadX: 10;
124
139
  readonly notePadY: 6;
140
+ /** Space reserved above a namespace's classes for its title */
141
+ readonly namespaceTitleHeight: 28;
142
+ /** Padding between a namespace frame and its classes (other three sides) */
143
+ readonly namespacePad: 16;
144
+ readonly namespaceTitleFontSize: 12;
125
145
  };
126
146
 
127
147
  /**
@@ -171,10 +191,11 @@ export declare function directionToElk(dir: Direction | undefined, fallback: Elk
171
191
  * - **C4** — `DOWN`. `C4Diagram.direction` is never set by the parser (C4
172
192
  * sources have no direction statement), only by `RenderOptions.direction`,
173
193
  * so an unset one is the top-down layout every C4 diagram is drawn in.
174
- * - **ER** — `RIGHT`. An ER diagram's `direction` is optional
194
+ * - **ER** — `DOWN`. An ER diagram's `direction` is optional
175
195
  * (`ErDiagram.direction?`), left `undefined` when the source has no
176
- * `direction` statement, and this renderer has always laid those out
177
- * left-to-right. `direction TB`/`LR`/`BT`/`RL` in the source (or
196
+ * `direction` statement, and official Mermaid lays those out top-to-bottom
197
+ * (#1250; this renderer used to lay them out left-to-right).
198
+ * `direction TB`/`LR`/`BT`/`RL` in the source (or
178
199
  * `RenderOptions.direction`, applied via `withDirectionOverride`) still
179
200
  * wins over it.
180
201
  *
@@ -188,7 +209,7 @@ export declare const ELK_DIRECTION_FALLBACK: {
188
209
  readonly flowchart: "DOWN";
189
210
  readonly state: "DOWN";
190
211
  readonly class: "DOWN";
191
- readonly er: "RIGHT";
212
+ readonly er: "DOWN";
192
213
  readonly c4: "DOWN";
193
214
  };
194
215
 
@@ -340,6 +361,15 @@ export declare function layoutClassDiagramSync(diagram: ClassDiagram, options?:
340
361
  */
341
362
  export declare function layoutErDiagramSync(diagram: ErDiagram, options?: ErRenderOptions): PositionedErDiagram;
342
363
 
364
+ /**
365
+ * Lay out a flowchart, with its subgraphs arranged the way mermaid.js arranges
366
+ * them (see `layout-engine/compound-flat.ts`). Anything that layout doesn't
367
+ * handle, or can't make fit, is laid out by `layoutGraphSync`, so this is a
368
+ * drop-in for it wherever the graph is a flowchart. Other diagram types that
369
+ * share the engine (state, architecture) keep using `layoutGraphSync`.
370
+ */
371
+ export declare function layoutFlowchartSync(rawGraph: MermaidGraph, options?: FlowchartRenderOptions): PositionedGraph;
372
+
343
373
  /**
344
374
  * Lay out a parsed MermaidGraph using ELK.js (synchronous).
345
375
  * Returns a fully positioned graph ready for rendering.
@@ -630,4 +660,12 @@ export declare function themeCssVariables(options?: RenderOptions): string;
630
660
  */
631
661
  export declare function withDataSrc(svgTag: string, source: string | undefined): string;
632
662
 
663
+ /**
664
+ * Step between shown x-axis labels: 1 when every pair of neighbouring labels
665
+ * keeps `X_LABEL_MIN_GAP` of clear space, otherwise the smallest n for which
666
+ * every pair of shown (every n-th) labels does. Checked pairwise on the real
667
+ * widths so one long label doesn't thin out an otherwise roomy axis.
668
+ */
669
+ export declare function xLabelStep(labels: string[], bandWidth: number): number;
670
+
633
671
  export { }