@zombie-mermaid/mermaid-parser 3.1.0 → 3.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.d.cts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { Direction } from '@zombie-mermaid/core';
2
+ import { MermaidGraph } from '@zombie-mermaid/core';
2
3
  import { NodeInteraction } from '@zombie-mermaid/core';
3
4
  import { NodeShape } from '@zombie-mermaid/core';
5
+ import { Point } from '@zombie-mermaid/core';
4
6
  import { Statement } from '@zombie-mermaid/core';
5
7
  import { StyleDirectives } from '@zombie-mermaid/core';
6
8
 
@@ -88,6 +90,54 @@ export declare interface Actor {
88
90
  destroyedAt?: number;
89
91
  }
90
92
 
93
+ export declare interface ArchitectureDiagram {
94
+ groups: ArchitectureGroup[];
95
+ services: ArchitectureService[];
96
+ junctions: ArchitectureJunction[];
97
+ edges: ArchitectureEdge[];
98
+ }
99
+
100
+ export declare interface ArchitectureEdge {
101
+ source: string;
102
+ sourcePort: ArchitecturePort;
103
+ /** `{group}` modifier: the edge attaches to the enclosing group's border. */
104
+ sourceGroup: boolean;
105
+ target: string;
106
+ targetPort: ArchitecturePort;
107
+ targetGroup: boolean;
108
+ /** `<--` / `<-->`: arrowhead at the source end. */
109
+ arrowStart: boolean;
110
+ /** `-->` / `<-->`: arrowhead at the target end. */
111
+ arrowEnd: boolean;
112
+ }
113
+
114
+ export declare interface ArchitectureGroup {
115
+ id: string;
116
+ /** Icon name from `(icon)`; kept for consumers, not drawn (see to-graph). */
117
+ icon?: string;
118
+ /** `[Title]`; falls back to the id. */
119
+ title: string;
120
+ /** Enclosing group id, from `in <parent>`. */
121
+ parent?: string;
122
+ }
123
+
124
+ export declare interface ArchitectureJunction {
125
+ id: string;
126
+ parent?: string;
127
+ }
128
+
129
+ /** A port on a service/junction: left, right, top, bottom. */
130
+ export declare type ArchitecturePort = 'L' | 'R' | 'T' | 'B';
131
+
132
+ export declare interface ArchitectureService {
133
+ id: string;
134
+ icon?: string;
135
+ title: string;
136
+ parent?: string;
137
+ }
138
+
139
+ export declare function architectureToGraph(diagram: ArchitectureDiagram): MermaidGraph;
140
+
91
141
  export declare interface AxisTick {
92
142
  /** Label text for this tick */
93
143
  label: string;
@@ -120,6 +170,111 @@ export declare interface Block {
120
170
  }>;
121
171
  }
122
172
 
173
+ export declare interface C4Boundary {
174
+ alias: string;
175
+ label: string;
176
+ /** Boundary type (`Boundary(a, "x", "type")`) or deployment node type. */
177
+ type?: string;
178
+ description?: string;
179
+ /** Aliases of elements declared directly inside this boundary. */
180
+ elementAliases: string[];
181
+ children: C4Boundary[];
182
+ }
183
+
184
+ /** A boundary's type line (`[ENTERPRISE]`, `[Ubuntu]`), when it has a type. */
185
+ export declare function c4BoundaryTypeLine(b: C4Boundary): string | undefined;
186
+
187
+ export declare interface C4Diagram {
188
+ variant: C4Variant;
189
+ /**
190
+ * Top-level layout direction. Never set by the parser (C4 sources have no
191
+ * direction statement); only `RenderOptions.direction` sets it, via
192
+ * `withDirectionOverride`. Unset lays out top-to-bottom.
193
+ */
194
+ direction?: Direction;
195
+ title?: string;
196
+ /** Every element in declaration order, wherever it is nested. */
197
+ elements: C4Element[];
198
+ /** Top-level boundaries; elements outside any boundary are not listed. */
199
+ boundaries: C4Boundary[];
200
+ relationships: C4Relationship[];
201
+ }
202
+
203
+ export declare interface C4Element {
204
+ alias: string;
205
+ kind: C4ElementKind;
206
+ shape: C4ElementShape;
207
+ /** `*_Ext` variants: outside the system being described. */
208
+ external: boolean;
209
+ label: string;
210
+ technology?: string;
211
+ description?: string;
212
+ }
213
+
214
+ export declare type C4ElementKind = 'person' | 'system' | 'container' | 'component';
215
+
216
+ /** Visual variant of an element: plain box, database cylinder, or queue. */
217
+ export declare type C4ElementShape = 'default' | 'db' | 'queue';
218
+
219
+ /**
220
+ * Layout placement hint carried by `Rel_U`/`Rel_D`/`Rel_L`/`Rel_R` (and their
221
+ * long-form aliases): where `to` should sit relative to `from`. Plain `Rel`,
222
+ * `BiRel`, `RelIndex` and `Rel_Back` carry none.
223
+ */
224
+ export declare type C4LayoutHint = 'up' | 'down' | 'left' | 'right';
225
+
226
+ /**
227
+ * How a relationship constrains placement. `source` is meant to sit before
228
+ * `target` along `axis`: above it for `'vertical'`, left of it for
229
+ * `'horizontal'`. `Rel_U`/`Rel_L` reverse the pair (the target sits above /
230
+ * left of the source); plain `Rel` is a vertical hint, since C4 diagrams flow
231
+ * top to bottom by default.
232
+ */
233
+ export declare interface C4Placement {
234
+ source: string;
235
+ target: string;
236
+ axis: 'vertical' | 'horizontal';
237
+ /** True when the hint came from an explicit `Rel_U/D/L/R`. */
238
+ explicit: boolean;
239
+ }
240
+
241
+ export declare function c4Placement(rel: C4Relationship): C4Placement;
242
+
243
+ export declare interface C4Relationship {
244
+ from: string;
245
+ to: string;
246
+ label: string;
247
+ technology?: string;
248
+ /** `BiRel`: arrowheads at both ends. */
249
+ bidirectional: boolean;
250
+ /**
251
+ * `Rel_Back`: the arrowhead points at `from` instead of `to`. `from`/`to`
252
+ * stay as declared, so layout and placement hints still follow them.
253
+ */
254
+ reversed?: boolean;
255
+ /** `RelIndex(n, ...)` in C4Dynamic diagrams. */
256
+ index?: string;
257
+ /** Placement hint from a directional `Rel_*` macro; see `C4LayoutHint`. */
258
+ layout?: C4LayoutHint;
259
+ }
260
+
261
+ /**
262
+ * The text lines of a relationship label: the label itself (prefixed with its
263
+ * sequence number in a C4Dynamic diagram), then the technology in brackets on its
264
+ * own line. Empty when the relationship has neither.
265
+ */
266
+ export declare function c4RelLabelLines(rel: C4Relationship): string[];
267
+
268
+ /**
269
+ * The bracketed type line under an element's name, as Mermaid draws it:
270
+ * `[Person]`, `[Software System]`, `[Container: PostgreSQL]`. External,
271
+ * database and queue variants share their base kind's line; the fill and the
272
+ * shape tell them apart.
273
+ */
274
+ export declare function c4TypeLine(el: C4Element): string;
275
+
276
+ export declare type C4Variant = 'context' | 'container' | 'component' | 'dynamic' | 'deployment';
277
+
123
278
  /**
124
279
  * Cardinality notation (crow's foot):
125
280
  * 'one' || || exactly one
@@ -435,6 +590,12 @@ export declare interface Note {
435
590
  afterIndex: number;
436
591
  }
437
592
 
593
+ /**
594
+ * Parse a Mermaid architecture diagram.
595
+ * Expects the first statement to be the `architecture-beta` header.
596
+ */
597
+ export declare function parseArchitecture(lines: Statement[]): ArchitectureDiagram;
598
+
438
599
  /**
439
600
  * Split the text after the `box` keyword into a colour and a label, per
440
601
  * Mermaid's `parseBoxData`: the leading word (or function call) is the
@@ -447,6 +608,13 @@ export declare function parseBoxHeader(header: string): {
447
608
  label: string;
448
609
  };
449
610
 
611
+ /**
612
+ * Parse a Mermaid C4 diagram. Expects the first statement to be a
613
+ * `C4Context` / `C4Container` / `C4Component` / `C4Dynamic` /
614
+ * `C4Deployment` header.
615
+ */
616
+ export declare function parseC4Diagram(lines: Statement[]): C4Diagram;
617
+
450
618
  /**
451
619
  * Parse a Mermaid class diagram.
452
620
  * Expects the first line to be "classDiagram".
@@ -580,6 +748,60 @@ export declare interface PositionedBlock {
580
748
  }>;
581
749
  }
582
750
 
751
+ export declare interface PositionedC4Boundary {
752
+ alias: string;
753
+ label: string;
754
+ type?: string;
755
+ description?: string;
756
+ x: number;
757
+ y: number;
758
+ width: number;
759
+ height: number;
760
+ /** Nesting depth, 0 for a top-level boundary. */
761
+ depth: number;
762
+ /** Centre line of the title, below the frame's top edge (Mermaid's layout). */
763
+ labelY?: number;
764
+ /** Centre line of the `[type]` text, below the frame's top edge. */
765
+ typeY?: number;
766
+ /** Centre line of the description (deployment nodes), below the top edge. */
767
+ descrY?: number;
768
+ }
769
+
770
+ export declare interface PositionedC4Diagram {
771
+ variant: C4Variant;
772
+ title?: string;
773
+ width: number;
774
+ height: number;
775
+ /** Where the title baseline sits (centre x, y), when there is a title. */
776
+ titlePosition?: Point;
777
+ elements: PositionedC4Element[];
778
+ /** Outer boundaries first, so inner ones paint on top. */
779
+ boundaries: PositionedC4Boundary[];
780
+ relationships: PositionedC4Relationship[];
781
+ }
782
+
783
+ export declare interface PositionedC4Element extends C4Element {
784
+ x: number;
785
+ y: number;
786
+ width: number;
787
+ height: number;
788
+ /** Name wrapped to the box width, one entry per line. */
789
+ nameLines: string[];
790
+ /** Description wrapped to the box width, one entry per line. */
791
+ descriptionLines: string[];
792
+ }
793
+
794
+ export declare interface PositionedC4Relationship extends C4Relationship {
795
+ /** The start and end of the line (a straight chord when `curve` is unset). */
796
+ points: Point[];
797
+ /** Control point of a quadratic curve from the first to the last point. */
798
+ curve?: Point;
799
+ /** Centre of the label block, when the relationship has label text. */
800
+ labelPosition?: Point;
801
+ /** Centre x of the `[technology]` line, which Mermaid lays out on its own. */
802
+ technologyX?: number;
803
+ }
804
+
583
805
  export declare interface PositionedClassDiagram {
584
806
  width: number;
585
807
  height: number;
@@ -834,6 +1056,9 @@ export declare interface SequenceDiagram {
834
1056
  */
835
1057
  export declare function toBlockType(value: string): Block['type'];
836
1058
 
1059
+ /** Greedy word wrap; a word longer than `width` stays on its own line. */
1060
+ export declare function wrapC4Text(text: string, width: number): string[];
1061
+
837
1062
  /** Axis configuration — categorical (labels) or numeric (range) */
838
1063
  export declare interface XYAxis {
839
1064
  /** Optional axis title/label */
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { Direction } from '@zombie-mermaid/core';
2
+ import { MermaidGraph } from '@zombie-mermaid/core';
2
3
  import { NodeInteraction } from '@zombie-mermaid/core';
3
4
  import { NodeShape } from '@zombie-mermaid/core';
5
+ import { Point } from '@zombie-mermaid/core';
4
6
  import { Statement } from '@zombie-mermaid/core';
5
7
  import { StyleDirectives } from '@zombie-mermaid/core';
6
8
 
@@ -88,6 +90,54 @@ export declare interface Actor {
88
90
  destroyedAt?: number;
89
91
  }
90
92
 
93
+ export declare interface ArchitectureDiagram {
94
+ groups: ArchitectureGroup[];
95
+ services: ArchitectureService[];
96
+ junctions: ArchitectureJunction[];
97
+ edges: ArchitectureEdge[];
98
+ }
99
+
100
+ export declare interface ArchitectureEdge {
101
+ source: string;
102
+ sourcePort: ArchitecturePort;
103
+ /** `{group}` modifier: the edge attaches to the enclosing group's border. */
104
+ sourceGroup: boolean;
105
+ target: string;
106
+ targetPort: ArchitecturePort;
107
+ targetGroup: boolean;
108
+ /** `<--` / `<-->`: arrowhead at the source end. */
109
+ arrowStart: boolean;
110
+ /** `-->` / `<-->`: arrowhead at the target end. */
111
+ arrowEnd: boolean;
112
+ }
113
+
114
+ export declare interface ArchitectureGroup {
115
+ id: string;
116
+ /** Icon name from `(icon)`; kept for consumers, not drawn (see to-graph). */
117
+ icon?: string;
118
+ /** `[Title]`; falls back to the id. */
119
+ title: string;
120
+ /** Enclosing group id, from `in <parent>`. */
121
+ parent?: string;
122
+ }
123
+
124
+ export declare interface ArchitectureJunction {
125
+ id: string;
126
+ parent?: string;
127
+ }
128
+
129
+ /** A port on a service/junction: left, right, top, bottom. */
130
+ export declare type ArchitecturePort = 'L' | 'R' | 'T' | 'B';
131
+
132
+ export declare interface ArchitectureService {
133
+ id: string;
134
+ icon?: string;
135
+ title: string;
136
+ parent?: string;
137
+ }
138
+
139
+ export declare function architectureToGraph(diagram: ArchitectureDiagram): MermaidGraph;
140
+
91
141
  export declare interface AxisTick {
92
142
  /** Label text for this tick */
93
143
  label: string;
@@ -120,6 +170,111 @@ export declare interface Block {
120
170
  }>;
121
171
  }
122
172
 
173
+ export declare interface C4Boundary {
174
+ alias: string;
175
+ label: string;
176
+ /** Boundary type (`Boundary(a, "x", "type")`) or deployment node type. */
177
+ type?: string;
178
+ description?: string;
179
+ /** Aliases of elements declared directly inside this boundary. */
180
+ elementAliases: string[];
181
+ children: C4Boundary[];
182
+ }
183
+
184
+ /** A boundary's type line (`[ENTERPRISE]`, `[Ubuntu]`), when it has a type. */
185
+ export declare function c4BoundaryTypeLine(b: C4Boundary): string | undefined;
186
+
187
+ export declare interface C4Diagram {
188
+ variant: C4Variant;
189
+ /**
190
+ * Top-level layout direction. Never set by the parser (C4 sources have no
191
+ * direction statement); only `RenderOptions.direction` sets it, via
192
+ * `withDirectionOverride`. Unset lays out top-to-bottom.
193
+ */
194
+ direction?: Direction;
195
+ title?: string;
196
+ /** Every element in declaration order, wherever it is nested. */
197
+ elements: C4Element[];
198
+ /** Top-level boundaries; elements outside any boundary are not listed. */
199
+ boundaries: C4Boundary[];
200
+ relationships: C4Relationship[];
201
+ }
202
+
203
+ export declare interface C4Element {
204
+ alias: string;
205
+ kind: C4ElementKind;
206
+ shape: C4ElementShape;
207
+ /** `*_Ext` variants: outside the system being described. */
208
+ external: boolean;
209
+ label: string;
210
+ technology?: string;
211
+ description?: string;
212
+ }
213
+
214
+ export declare type C4ElementKind = 'person' | 'system' | 'container' | 'component';
215
+
216
+ /** Visual variant of an element: plain box, database cylinder, or queue. */
217
+ export declare type C4ElementShape = 'default' | 'db' | 'queue';
218
+
219
+ /**
220
+ * Layout placement hint carried by `Rel_U`/`Rel_D`/`Rel_L`/`Rel_R` (and their
221
+ * long-form aliases): where `to` should sit relative to `from`. Plain `Rel`,
222
+ * `BiRel`, `RelIndex` and `Rel_Back` carry none.
223
+ */
224
+ export declare type C4LayoutHint = 'up' | 'down' | 'left' | 'right';
225
+
226
+ /**
227
+ * How a relationship constrains placement. `source` is meant to sit before
228
+ * `target` along `axis`: above it for `'vertical'`, left of it for
229
+ * `'horizontal'`. `Rel_U`/`Rel_L` reverse the pair (the target sits above /
230
+ * left of the source); plain `Rel` is a vertical hint, since C4 diagrams flow
231
+ * top to bottom by default.
232
+ */
233
+ export declare interface C4Placement {
234
+ source: string;
235
+ target: string;
236
+ axis: 'vertical' | 'horizontal';
237
+ /** True when the hint came from an explicit `Rel_U/D/L/R`. */
238
+ explicit: boolean;
239
+ }
240
+
241
+ export declare function c4Placement(rel: C4Relationship): C4Placement;
242
+
243
+ export declare interface C4Relationship {
244
+ from: string;
245
+ to: string;
246
+ label: string;
247
+ technology?: string;
248
+ /** `BiRel`: arrowheads at both ends. */
249
+ bidirectional: boolean;
250
+ /**
251
+ * `Rel_Back`: the arrowhead points at `from` instead of `to`. `from`/`to`
252
+ * stay as declared, so layout and placement hints still follow them.
253
+ */
254
+ reversed?: boolean;
255
+ /** `RelIndex(n, ...)` in C4Dynamic diagrams. */
256
+ index?: string;
257
+ /** Placement hint from a directional `Rel_*` macro; see `C4LayoutHint`. */
258
+ layout?: C4LayoutHint;
259
+ }
260
+
261
+ /**
262
+ * The text lines of a relationship label: the label itself (prefixed with its
263
+ * sequence number in a C4Dynamic diagram), then the technology in brackets on its
264
+ * own line. Empty when the relationship has neither.
265
+ */
266
+ export declare function c4RelLabelLines(rel: C4Relationship): string[];
267
+
268
+ /**
269
+ * The bracketed type line under an element's name, as Mermaid draws it:
270
+ * `[Person]`, `[Software System]`, `[Container: PostgreSQL]`. External,
271
+ * database and queue variants share their base kind's line; the fill and the
272
+ * shape tell them apart.
273
+ */
274
+ export declare function c4TypeLine(el: C4Element): string;
275
+
276
+ export declare type C4Variant = 'context' | 'container' | 'component' | 'dynamic' | 'deployment';
277
+
123
278
  /**
124
279
  * Cardinality notation (crow's foot):
125
280
  * 'one' || || exactly one
@@ -435,6 +590,12 @@ export declare interface Note {
435
590
  afterIndex: number;
436
591
  }
437
592
 
593
+ /**
594
+ * Parse a Mermaid architecture diagram.
595
+ * Expects the first statement to be the `architecture-beta` header.
596
+ */
597
+ export declare function parseArchitecture(lines: Statement[]): ArchitectureDiagram;
598
+
438
599
  /**
439
600
  * Split the text after the `box` keyword into a colour and a label, per
440
601
  * Mermaid's `parseBoxData`: the leading word (or function call) is the
@@ -447,6 +608,13 @@ export declare function parseBoxHeader(header: string): {
447
608
  label: string;
448
609
  };
449
610
 
611
+ /**
612
+ * Parse a Mermaid C4 diagram. Expects the first statement to be a
613
+ * `C4Context` / `C4Container` / `C4Component` / `C4Dynamic` /
614
+ * `C4Deployment` header.
615
+ */
616
+ export declare function parseC4Diagram(lines: Statement[]): C4Diagram;
617
+
450
618
  /**
451
619
  * Parse a Mermaid class diagram.
452
620
  * Expects the first line to be "classDiagram".
@@ -580,6 +748,60 @@ export declare interface PositionedBlock {
580
748
  }>;
581
749
  }
582
750
 
751
+ export declare interface PositionedC4Boundary {
752
+ alias: string;
753
+ label: string;
754
+ type?: string;
755
+ description?: string;
756
+ x: number;
757
+ y: number;
758
+ width: number;
759
+ height: number;
760
+ /** Nesting depth, 0 for a top-level boundary. */
761
+ depth: number;
762
+ /** Centre line of the title, below the frame's top edge (Mermaid's layout). */
763
+ labelY?: number;
764
+ /** Centre line of the `[type]` text, below the frame's top edge. */
765
+ typeY?: number;
766
+ /** Centre line of the description (deployment nodes), below the top edge. */
767
+ descrY?: number;
768
+ }
769
+
770
+ export declare interface PositionedC4Diagram {
771
+ variant: C4Variant;
772
+ title?: string;
773
+ width: number;
774
+ height: number;
775
+ /** Where the title baseline sits (centre x, y), when there is a title. */
776
+ titlePosition?: Point;
777
+ elements: PositionedC4Element[];
778
+ /** Outer boundaries first, so inner ones paint on top. */
779
+ boundaries: PositionedC4Boundary[];
780
+ relationships: PositionedC4Relationship[];
781
+ }
782
+
783
+ export declare interface PositionedC4Element extends C4Element {
784
+ x: number;
785
+ y: number;
786
+ width: number;
787
+ height: number;
788
+ /** Name wrapped to the box width, one entry per line. */
789
+ nameLines: string[];
790
+ /** Description wrapped to the box width, one entry per line. */
791
+ descriptionLines: string[];
792
+ }
793
+
794
+ export declare interface PositionedC4Relationship extends C4Relationship {
795
+ /** The start and end of the line (a straight chord when `curve` is unset). */
796
+ points: Point[];
797
+ /** Control point of a quadratic curve from the first to the last point. */
798
+ curve?: Point;
799
+ /** Centre of the label block, when the relationship has label text. */
800
+ labelPosition?: Point;
801
+ /** Centre x of the `[technology]` line, which Mermaid lays out on its own. */
802
+ technologyX?: number;
803
+ }
804
+
583
805
  export declare interface PositionedClassDiagram {
584
806
  width: number;
585
807
  height: number;
@@ -834,6 +1056,9 @@ export declare interface SequenceDiagram {
834
1056
  */
835
1057
  export declare function toBlockType(value: string): Block['type'];
836
1058
 
1059
+ /** Greedy word wrap; a word longer than `width` stays on its own line. */
1060
+ export declare function wrapC4Text(text: string, width: number): string[];
1061
+
837
1062
  /** Axis configuration — categorical (labels) or numeric (range) */
838
1063
  export declare interface XYAxis {
839
1064
  /** Optional axis title/label */