@zombie-mermaid/mermaid-parser 2.2.1
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/LICENSE +22 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +879 -0
- package/dist/index.d.ts +879 -0
- package/dist/index.js +994 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -0
- package/src/__tests__/box-color.test.ts +80 -0
- package/src/__tests__/sequence-activation-fix.test.ts +91 -0
- package/src/__tests__/xychart-colors.test.ts +149 -0
- package/src/class/format.ts +15 -0
- package/src/class/parser.ts +593 -0
- package/src/class/types.ts +166 -0
- package/src/er/parser.ts +286 -0
- package/src/er/types.ts +99 -0
- package/src/expanded-shapes.ts +376 -0
- package/src/index.ts +48 -0
- package/src/sequence/activation-check.ts +149 -0
- package/src/sequence/activation-fix.ts +112 -0
- package/src/sequence/box-color.ts +85 -0
- package/src/sequence/parser.ts +613 -0
- package/src/sequence/types.ts +242 -0
- package/src/xychart/colors.ts +177 -0
- package/src/xychart/parser.ts +246 -0
- package/src/xychart/types.ts +150 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,879 @@
|
|
|
1
|
+
import { Direction } from '@zombie-mermaid/core';
|
|
2
|
+
import { NodeInteraction } from '@zombie-mermaid/core';
|
|
3
|
+
import { NodeShape } from '@zombie-mermaid/core';
|
|
4
|
+
import { Statement } from '@zombie-mermaid/core';
|
|
5
|
+
import { StyleDirectives } from '@zombie-mermaid/core';
|
|
6
|
+
|
|
7
|
+
/** Narrow rectangle on a lifeline showing active processing */
|
|
8
|
+
export declare interface Activation {
|
|
9
|
+
actorId: string;
|
|
10
|
+
x: number;
|
|
11
|
+
topY: number;
|
|
12
|
+
bottomY: number;
|
|
13
|
+
width: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export declare interface ActivationCheckResult {
|
|
17
|
+
/** true when every activation is balanced (no issues found). */
|
|
18
|
+
ok: boolean;
|
|
19
|
+
issues: ActivationIssue[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* One standalone `activate X` (`kind: 'start'`) or `deactivate X`
|
|
24
|
+
* (`kind: 'end'`) statement. Mermaid's own grammar expands the `+`/`-` arrow
|
|
25
|
+
* shorthand into exactly these events — `A->>+B` is a message followed by an
|
|
26
|
+
* `activeStart` for the recipient, `A-->>-B` a message followed by an
|
|
27
|
+
* `activeEnd` for the sender — so this is the primitive and the shorthand is
|
|
28
|
+
* sugar over it.
|
|
29
|
+
*/
|
|
30
|
+
export declare interface ActivationEvent {
|
|
31
|
+
actorId: string;
|
|
32
|
+
kind: 'start' | 'end';
|
|
33
|
+
/**
|
|
34
|
+
* Index of the message this statement follows (-1 if it precedes every
|
|
35
|
+
* message). The activation bar starts/ends at that message's row, which
|
|
36
|
+
* is where the shorthand form's bar starts/ends too.
|
|
37
|
+
*/
|
|
38
|
+
afterIndex: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export declare interface ActivationFixResult {
|
|
42
|
+
/** true when the returned diagram has no remaining activation issues. */
|
|
43
|
+
ok: boolean;
|
|
44
|
+
/** Original diagram, unchanged if there was nothing fixable. */
|
|
45
|
+
originalDiagram: string;
|
|
46
|
+
/**
|
|
47
|
+
* Diagram with a "deactivate X" statement appended for every
|
|
48
|
+
* DANGLING_ACTIVATION issue found. Identical to `originalDiagram` when
|
|
49
|
+
* there was nothing to fix.
|
|
50
|
+
*/
|
|
51
|
+
fixedDiagram: string;
|
|
52
|
+
/** Human-readable description of each fix actually applied. */
|
|
53
|
+
fixesApplied: string[];
|
|
54
|
+
/**
|
|
55
|
+
* Issues that could not be auto-fixed (currently always
|
|
56
|
+
* UNMATCHED_DEACTIVATION — see module header). Empty when `ok` is true.
|
|
57
|
+
*/
|
|
58
|
+
remainingIssues: ActivationIssue[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export declare interface ActivationIssue {
|
|
62
|
+
code: ActivationIssueCode;
|
|
63
|
+
/** Actor whose activation is unbalanced. */
|
|
64
|
+
actorId: string;
|
|
65
|
+
/** Human-readable explanation, including a source-position hint. */
|
|
66
|
+
message: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export declare type ActivationIssueCode = 'DANGLING_ACTIVATION' | 'UNMATCHED_DEACTIVATION';
|
|
70
|
+
|
|
71
|
+
export declare interface Actor {
|
|
72
|
+
id: string;
|
|
73
|
+
label: string;
|
|
74
|
+
/** 'participant' renders as a box, 'actor' renders as a stick figure */
|
|
75
|
+
type: 'participant' | 'actor';
|
|
76
|
+
/**
|
|
77
|
+
* Index of the message that creates this participant (`create participant
|
|
78
|
+
* X` on the line before it). The participant's box is drawn at that
|
|
79
|
+
* message's row instead of in the header, and its lifeline starts there.
|
|
80
|
+
* Unset for participants that exist from the top of the diagram.
|
|
81
|
+
*/
|
|
82
|
+
createdAt?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Index of the message that destroys this participant (`destroy X` on the
|
|
85
|
+
* line before it). Its lifeline ends at that message's row with a cross,
|
|
86
|
+
* and no footer box is drawn. Unset for participants that live to the end.
|
|
87
|
+
*/
|
|
88
|
+
destroyedAt?: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export declare interface AxisTick {
|
|
92
|
+
/** Label text for this tick */
|
|
93
|
+
label: string;
|
|
94
|
+
/** Position of the tick mark on the axis */
|
|
95
|
+
x: number;
|
|
96
|
+
y: number;
|
|
97
|
+
/** End of the tick mark (short perpendicular line) */
|
|
98
|
+
tx: number;
|
|
99
|
+
ty: number;
|
|
100
|
+
/** Label anchor position */
|
|
101
|
+
labelX: number;
|
|
102
|
+
labelY: number;
|
|
103
|
+
/** Text anchor for label */
|
|
104
|
+
textAnchor: 'start' | 'middle' | 'end';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export declare interface Block {
|
|
108
|
+
/** Block type keyword */
|
|
109
|
+
type: 'loop' | 'alt' | 'opt' | 'par' | 'critical' | 'break' | 'rect';
|
|
110
|
+
/** Label for the block header */
|
|
111
|
+
label: string;
|
|
112
|
+
/** Index of the first message inside this block */
|
|
113
|
+
startIndex: number;
|
|
114
|
+
/** Index of the last message inside this block (inclusive) */
|
|
115
|
+
endIndex: number;
|
|
116
|
+
/** For alt/par blocks: indices where "else"/"and" dividers appear (message indices) */
|
|
117
|
+
dividers: Array<{
|
|
118
|
+
index: number;
|
|
119
|
+
label: string;
|
|
120
|
+
}>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Cardinality notation (crow's foot):
|
|
125
|
+
* 'one' || || exactly one
|
|
126
|
+
* 'zero-one' |o o| zero or one
|
|
127
|
+
* 'many' }| |{ one or more
|
|
128
|
+
* 'zero-many' }o o{ zero or more
|
|
129
|
+
*/
|
|
130
|
+
export declare type Cardinality = 'one' | 'zero-one' | 'many' | 'zero-many';
|
|
131
|
+
|
|
132
|
+
/** Default accent for charts when the theme doesn't provide one. */
|
|
133
|
+
export declare const CHART_ACCENT_FALLBACK = "#3b82f6";
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Check a parsed sequence diagram for activation/deactivation imbalance.
|
|
137
|
+
*
|
|
138
|
+
* Merges the inline `+`/`-` arrow shorthand (`Message.activate` /
|
|
139
|
+
* `Message.deactivate`) with standalone `activate X` / `deactivate X`
|
|
140
|
+
* statements (`SequenceDiagram.activations`) into one chronological event
|
|
141
|
+
* stream per actor — the same merge `layout.ts` performs to position
|
|
142
|
+
* activation bars — then walks a stack per actor:
|
|
143
|
+
*
|
|
144
|
+
* - A `deactivate` with nothing open on that actor's stack is reported as
|
|
145
|
+
* `UNMATCHED_DEACTIVATION` (the renderer silently ignores this case —
|
|
146
|
+
* see `endActivation` in layout.ts — this check surfaces it instead).
|
|
147
|
+
* - Anything left on a stack once every message has been processed is
|
|
148
|
+
* reported as `DANGLING_ACTIVATION` (the renderer draws these extending
|
|
149
|
+
* to the bottom of the diagram, which usually isn't what the author
|
|
150
|
+
* intended).
|
|
151
|
+
*/
|
|
152
|
+
export declare function checkActivationBalance(diagram: SequenceDiagram): ActivationCheckResult;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Parsed class diagram — logical structure from mermaid text.
|
|
156
|
+
*
|
|
157
|
+
* Extends {@link StyleDirectives} so `classDef` / `cssClass` / `style` /
|
|
158
|
+
* `:::` resolve through the same cascade flowcharts use (see
|
|
159
|
+
* packages/core/src/style-directives.ts).
|
|
160
|
+
*/
|
|
161
|
+
export declare interface ClassDiagram extends StyleDirectives {
|
|
162
|
+
/** All class definitions */
|
|
163
|
+
classes: ClassNode[];
|
|
164
|
+
/** Relationships between classes */
|
|
165
|
+
relationships: ClassRelationship[];
|
|
166
|
+
/** Optional namespace groupings */
|
|
167
|
+
namespaces: ClassNamespace[];
|
|
168
|
+
/** Maps class IDs to interactions declared by `click` statements */
|
|
169
|
+
interactions: Map<string, NodeInteraction>;
|
|
170
|
+
/** Notes, in source order — `note "text"` and `note for X "text"` */
|
|
171
|
+
notes: ClassNote[];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export declare interface ClassMember {
|
|
175
|
+
/** Visibility: + public, - private, # protected, ~ package */
|
|
176
|
+
visibility: '+' | '-' | '#' | '~' | '';
|
|
177
|
+
/** Member name */
|
|
178
|
+
name: string;
|
|
179
|
+
/** Type annotation (e.g., "String", "int", "void") */
|
|
180
|
+
type?: string;
|
|
181
|
+
/** Whether the member is static (underlined in UML) */
|
|
182
|
+
isStatic?: boolean;
|
|
183
|
+
/** Whether the member is abstract (italic in UML) */
|
|
184
|
+
isAbstract?: boolean;
|
|
185
|
+
/** Whether the member is a method (renders with parentheses) */
|
|
186
|
+
isMethod?: boolean;
|
|
187
|
+
/** Method parameters (e.g., "data", "key, val") — only for methods */
|
|
188
|
+
params?: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export declare interface ClassNamespace {
|
|
192
|
+
name: string;
|
|
193
|
+
classIds: string[];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export declare interface ClassNode {
|
|
197
|
+
id: string;
|
|
198
|
+
label: string;
|
|
199
|
+
/** Annotation like <<interface>>, <<abstract>>, <<service>>, <<enumeration>> */
|
|
200
|
+
annotation?: string;
|
|
201
|
+
/** Class attributes (fields/properties) */
|
|
202
|
+
attributes: ClassMember[];
|
|
203
|
+
/** Class methods (functions) */
|
|
204
|
+
methods: ClassMember[];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* A class-diagram note. Mermaid lays an attached note out as its own node
|
|
209
|
+
* joined to the class by a dotted, arrowless link (classDb.getData); a free
|
|
210
|
+
* note is a lone node.
|
|
211
|
+
*/
|
|
212
|
+
export declare interface ClassNote {
|
|
213
|
+
/** Note text; `\n` / `<br/>` in the source are already normalized to newlines */
|
|
214
|
+
text: string;
|
|
215
|
+
/** Class this note is attached to (`note for X`); absent for a free note */
|
|
216
|
+
forClass?: string;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export declare interface ClassRelationship {
|
|
220
|
+
from: string;
|
|
221
|
+
to: string;
|
|
222
|
+
type: RelationshipType;
|
|
223
|
+
/**
|
|
224
|
+
* Which end of the relationship line has the UML marker (triangle, diamond, arrow).
|
|
225
|
+
* Determined by the arrow syntax direction:
|
|
226
|
+
* - Prefix markers like `<|--`, `*--`, `o--` → 'from' (marker on left/from side)
|
|
227
|
+
* - Suffix markers like `..|>`, `-->`, `..>`, `--*`, `--o` → 'to' (marker on right/to side)
|
|
228
|
+
*/
|
|
229
|
+
markerAt: 'from' | 'to';
|
|
230
|
+
/** Label on the relationship line */
|
|
231
|
+
label?: string;
|
|
232
|
+
/** Cardinality at the "from" end (e.g., "1", "*", "0..1") */
|
|
233
|
+
fromCardinality?: string;
|
|
234
|
+
/** Cardinality at the "to" end */
|
|
235
|
+
toCardinality?: string;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export declare interface ErAttribute {
|
|
239
|
+
/** Data type (string, int, varchar, etc.) */
|
|
240
|
+
type: string;
|
|
241
|
+
/** Attribute name */
|
|
242
|
+
name: string;
|
|
243
|
+
/** Key constraints: PK, FK, UK */
|
|
244
|
+
keys: Array<'PK' | 'FK' | 'UK'>;
|
|
245
|
+
/** Optional comment */
|
|
246
|
+
comment?: string;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** Parsed ER diagram — logical structure from mermaid text */
|
|
250
|
+
export declare interface ErDiagram {
|
|
251
|
+
/** All entity definitions */
|
|
252
|
+
entities: ErEntity[];
|
|
253
|
+
/** Relationships between entities */
|
|
254
|
+
relationships: ErRelationship[];
|
|
255
|
+
/**
|
|
256
|
+
* Overall layout direction, from a top-level `direction TB` / `direction LR`
|
|
257
|
+
* / `direction BT` / `direction RL` statement. `undefined` when the diagram
|
|
258
|
+
* doesn't specify one, in which case the layout falls back to its default.
|
|
259
|
+
*/
|
|
260
|
+
direction?: Direction;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export declare interface ErEntity {
|
|
264
|
+
id: string;
|
|
265
|
+
/** Display name (same as id unless aliased) */
|
|
266
|
+
label: string;
|
|
267
|
+
/** Entity attributes (columns) */
|
|
268
|
+
attributes: ErAttribute[];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export declare interface ErRelationship {
|
|
272
|
+
entity1: string;
|
|
273
|
+
entity2: string;
|
|
274
|
+
/** Cardinality at entity1's end */
|
|
275
|
+
cardinality1: Cardinality;
|
|
276
|
+
/** Cardinality at entity2's end */
|
|
277
|
+
cardinality2: Cardinality;
|
|
278
|
+
/** Relationship verb/label (e.g., "places", "contains") */
|
|
279
|
+
label: string;
|
|
280
|
+
/** Whether the relationship is identifying (solid line) or non-identifying (dashed) */
|
|
281
|
+
identifying: boolean;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** The metadata a `@{ ... }` block can carry. */
|
|
285
|
+
export declare interface ExpandedNodeMeta {
|
|
286
|
+
shape?: string;
|
|
287
|
+
label?: string;
|
|
288
|
+
icon?: string;
|
|
289
|
+
img?: string;
|
|
290
|
+
/** Outline drawn around an icon or image: `square`, `circle`, `rounded`. */
|
|
291
|
+
form?: string;
|
|
292
|
+
/** Explicit width/height for an image node. */
|
|
293
|
+
w?: string;
|
|
294
|
+
h?: string;
|
|
295
|
+
/** Image fit mode Mermaid accepts alongside `img`. */
|
|
296
|
+
constraint?: string;
|
|
297
|
+
/** Any other key seen, preserved rather than dropped. */
|
|
298
|
+
[key: string]: string | undefined;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Check a Mermaid sequence diagram for activation/deactivation imbalance
|
|
303
|
+
* and, where mechanically safe, return a corrected version.
|
|
304
|
+
*
|
|
305
|
+
* Throws the same way `parseSequenceDiagram`/`detectDiagramType` do on
|
|
306
|
+
* invalid or non-sequence input — callers (e.g. the MCP tool handler) are
|
|
307
|
+
* expected to catch and translate, matching `check-sequence-activations.ts`'s
|
|
308
|
+
* own error handling.
|
|
309
|
+
*/
|
|
310
|
+
export declare function fixActivationBalance(sourceDiagram: string): ActivationFixResult;
|
|
311
|
+
|
|
312
|
+
/** Format a class member as a display string: visibility + name(+params for methods) + optional type */
|
|
313
|
+
export declare function formatClassMember(m: ClassMember): string;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Get the hex color for a series index.
|
|
317
|
+
* Index 0 returns the accent color as-is.
|
|
318
|
+
* Index 1+ alternate between darker and lighter shades of the same hue
|
|
319
|
+
* with subtle hue drift (±8-12° per tier) to stay in the same family.
|
|
320
|
+
*
|
|
321
|
+
* When `bgColor` is provided, shade direction adapts to the background:
|
|
322
|
+
* - Light bg: odd = darker, even = lighter (default)
|
|
323
|
+
* - Dark bg: odd = lighter, even = darker (so shades stay visible)
|
|
324
|
+
*/
|
|
325
|
+
export declare function getSeriesColor(index: number, accentColor: string, bgColor?: string): string;
|
|
326
|
+
|
|
327
|
+
export declare interface GridLine {
|
|
328
|
+
x1: number;
|
|
329
|
+
y1: number;
|
|
330
|
+
x2: number;
|
|
331
|
+
y2: number;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Narrow a regex-captured block keyword to `Block['type']`. The capturing
|
|
336
|
+
* regex at the call site uses the same `(loop|alt|opt|par|critical|break|
|
|
337
|
+
* rect)` alternation, so the input is always one of these seven values in
|
|
338
|
+
* practice — but the match itself is typed as `string`.
|
|
339
|
+
*
|
|
340
|
+
* Exported for direct unit testing (see
|
|
341
|
+
* src/__tests__/sequence-parser.test.ts) — not otherwise part of this
|
|
342
|
+
* module's public parsing API.
|
|
343
|
+
*/
|
|
344
|
+
export declare function isBlockType(value: string): value is Block['type'];
|
|
345
|
+
|
|
346
|
+
/** Whether `value` is a colour this renderer will emit as-is (case-insensitive). */
|
|
347
|
+
export declare function isCssColor(value: string): boolean;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Detect whether a background color is dark (lightness < 50%).
|
|
351
|
+
*/
|
|
352
|
+
export declare function isDarkBackground(bgHex: string): boolean;
|
|
353
|
+
|
|
354
|
+
/** Check whether a string is a valid 6-digit hex color (e.g. "#3b82f6"). */
|
|
355
|
+
export declare function isValidHex(color: string): boolean;
|
|
356
|
+
|
|
357
|
+
/** Every shape name this renderer accepts, for documentation and tests. */
|
|
358
|
+
export declare function knownShapeNames(): string[];
|
|
359
|
+
|
|
360
|
+
export declare interface LegendItem {
|
|
361
|
+
/** Display label */
|
|
362
|
+
label: string;
|
|
363
|
+
/** Position of the swatch/icon */
|
|
364
|
+
x: number;
|
|
365
|
+
y: number;
|
|
366
|
+
/** Series type determines swatch shape (rect for bar, line+dot for line) */
|
|
367
|
+
type: 'bar' | 'line';
|
|
368
|
+
/** Series index within its type (for layout grouping) */
|
|
369
|
+
seriesIndex: number;
|
|
370
|
+
/** Global color index across all series (for unified color assignment) */
|
|
371
|
+
colorIndex: number;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/** Vertical dashed line from actor to bottom of diagram */
|
|
375
|
+
export declare interface Lifeline {
|
|
376
|
+
actorId: string;
|
|
377
|
+
x: number;
|
|
378
|
+
topY: number;
|
|
379
|
+
bottomY: number;
|
|
380
|
+
/**
|
|
381
|
+
* Set when the actor is destroyed mid-diagram (`Actor.destroyedAt`):
|
|
382
|
+
* `bottomY` is then the destroying message's row rather than the diagram
|
|
383
|
+
* bottom, and the renderer marks it with a cross.
|
|
384
|
+
*/
|
|
385
|
+
destroyed?: boolean;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Find the `@{ ... }` block at the start of `text`, returning its body and
|
|
390
|
+
* total length.
|
|
391
|
+
*
|
|
392
|
+
* Brace matching is depth-aware and quote-aware, so a label containing `}`
|
|
393
|
+
* (`A@{ label: "a } b" }`) does not terminate the block early. Returns
|
|
394
|
+
* `undefined` if `text` does not open with `@{` or the block is unterminated.
|
|
395
|
+
*/
|
|
396
|
+
export declare function matchExpandedBlock(text: string): {
|
|
397
|
+
body: string;
|
|
398
|
+
length: number;
|
|
399
|
+
} | undefined;
|
|
400
|
+
|
|
401
|
+
export declare interface Message {
|
|
402
|
+
from: string;
|
|
403
|
+
to: string;
|
|
404
|
+
label: string;
|
|
405
|
+
/** Arrow style: solid line or dashed line */
|
|
406
|
+
lineStyle: 'solid' | 'dashed';
|
|
407
|
+
/** Arrow head: filled (closed) or open */
|
|
408
|
+
arrowHead: 'filled' | 'open';
|
|
409
|
+
/**
|
|
410
|
+
* Set for a "lost message" cross-terminator (`-x`/`--x`). `arrowHead`
|
|
411
|
+
* stays `'filled'` for these (unchanged, to preserve existing SVG output)
|
|
412
|
+
* — this flag lets the ASCII renderer draw a distinct cross glyph instead
|
|
413
|
+
* of the plain filled arrowhead it shares with `->>`/`-->>`. See issue
|
|
414
|
+
* #330; not yet modeled by the SVG renderer's markers.
|
|
415
|
+
*/
|
|
416
|
+
isLost?: boolean;
|
|
417
|
+
/** Activate the target lifeline (+) */
|
|
418
|
+
activate?: boolean;
|
|
419
|
+
/** Deactivate the source lifeline (-) */
|
|
420
|
+
deactivate?: boolean;
|
|
421
|
+
/** Bidirectional arrow (`<<->>` or `<<-->>`) — draw an arrow head on both ends */
|
|
422
|
+
bidirectional?: boolean;
|
|
423
|
+
/** Sequence number to display next to this arrow when `autonumber` is active */
|
|
424
|
+
seqNumber?: number;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Mix two hex colors in RGB space.
|
|
429
|
+
* `ratio` controls how much of `fgHex` shows: 0 = pure bg, 1 = pure fg.
|
|
430
|
+
* Equivalent to alpha-compositing fg over bg at the given opacity.
|
|
431
|
+
*/
|
|
432
|
+
export declare function mixHexColors(bgHex: string, fgHex: string, ratio: number): string;
|
|
433
|
+
|
|
434
|
+
export declare interface Note {
|
|
435
|
+
/** Which actor(s) the note is attached to */
|
|
436
|
+
actorIds: string[];
|
|
437
|
+
/** Note text content */
|
|
438
|
+
text: string;
|
|
439
|
+
/** Position relative to the actor(s) */
|
|
440
|
+
position: 'left' | 'right' | 'over';
|
|
441
|
+
/** Message index after which this note appears */
|
|
442
|
+
afterIndex: number;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Split the text after the `box` keyword into a colour and a label, per
|
|
447
|
+
* Mermaid's `parseBoxData`: the leading word (or function call) is the
|
|
448
|
+
* colour if it is one, otherwise the whole header is the label. An explicit
|
|
449
|
+
* `transparent` is consumed as "no colour" so `box transparent Aqua` yields
|
|
450
|
+
* a colourless box labelled `Aqua`, exactly as upstream documents.
|
|
451
|
+
*/
|
|
452
|
+
export declare function parseBoxHeader(header: string): {
|
|
453
|
+
color?: string;
|
|
454
|
+
label: string;
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Parse a Mermaid class diagram.
|
|
459
|
+
* Expects the first line to be "classDiagram".
|
|
460
|
+
*/
|
|
461
|
+
export declare function parseClassDiagram(lines: Statement[]): ClassDiagram;
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Parse a Mermaid ER diagram.
|
|
465
|
+
* Expects the first line to be "erDiagram".
|
|
466
|
+
*/
|
|
467
|
+
export declare function parseErDiagram(lines: Statement[]): ErDiagram;
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Parse the body of a `@{ ... }` block into key/value pairs.
|
|
471
|
+
*
|
|
472
|
+
* The body is a comma-separated list of `key: value`. Values may be quoted
|
|
473
|
+
* with `"` or `'`, and a quoted value may contain commas, colons, and braces
|
|
474
|
+
* — which is why this is a scanner rather than a `split(',')`.
|
|
475
|
+
*
|
|
476
|
+
* Mermaid also accepts a bare value with no key as shorthand for the shape
|
|
477
|
+
* (`A@{ rounded }`); that is handled by the caller, which sees an entry with
|
|
478
|
+
* an empty key.
|
|
479
|
+
*/
|
|
480
|
+
export declare function parseExpandedMeta(body: string): ExpandedNodeMeta;
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Convert mermaid's `~T~` generic syntax to the `<T>` form mermaid itself
|
|
484
|
+
* renders — `List~Observer~` → `List<Observer>`, `Map~K,V~` → `Map<K,V>`,
|
|
485
|
+
* `List~List~T~~` → `List<List<T>>`.
|
|
486
|
+
*
|
|
487
|
+
* Port of mermaid's `parseGenericTypes` (packages/mermaid/src/diagrams/
|
|
488
|
+
* common/common.ts): the text is split on commas so a comma *inside* a
|
|
489
|
+
* generic (`Map~K,V~`) can be re-joined with its neighbors — two adjacent
|
|
490
|
+
* comma-separated pieces that each carry exactly one `~` are the two halves
|
|
491
|
+
* of one generic — before each piece's `~` pairs are converted outermost-first.
|
|
492
|
+
*/
|
|
493
|
+
export declare function parseGenericTypes(input: string): string;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Parse a Mermaid sequence diagram.
|
|
497
|
+
* Expects the first line to be "sequenceDiagram".
|
|
498
|
+
*/
|
|
499
|
+
export declare function parseSequenceDiagram(lines: Statement[]): SequenceDiagram;
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Parse a Mermaid xychart-beta diagram from preprocessed lines.
|
|
503
|
+
* Lines should already be trimmed and comment-stripped.
|
|
504
|
+
*/
|
|
505
|
+
export declare function parseXYChart(lines: Statement[]): XYChart;
|
|
506
|
+
|
|
507
|
+
/** A `box … end` group of participants (Mermaid's "Grouping / Box"). */
|
|
508
|
+
export declare interface ParticipantBox {
|
|
509
|
+
/** Descriptive label; empty when the box has none. */
|
|
510
|
+
label: string;
|
|
511
|
+
/**
|
|
512
|
+
* Validated CSS colour (named, `#hex`, `rgb()`/`rgba()`, `hsl()`/`hsla()`)
|
|
513
|
+
* exactly as written. Unset for a transparent box — including an explicit
|
|
514
|
+
* `box transparent …`, and any first word that isn't a colour, which then
|
|
515
|
+
* counts as the start of the label (Mermaid's `parseBoxData` rule).
|
|
516
|
+
*/
|
|
517
|
+
color?: string;
|
|
518
|
+
/** Ids of the participants declared (or first used) inside the box. */
|
|
519
|
+
actorIds: string[];
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
export declare interface PlotArea {
|
|
523
|
+
x: number;
|
|
524
|
+
y: number;
|
|
525
|
+
width: number;
|
|
526
|
+
height: number;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
export declare interface PositionedActor {
|
|
530
|
+
id: string;
|
|
531
|
+
label: string;
|
|
532
|
+
type: 'participant' | 'actor';
|
|
533
|
+
/** Center x of the actor box */
|
|
534
|
+
x: number;
|
|
535
|
+
/** Top y of the actor box */
|
|
536
|
+
y: number;
|
|
537
|
+
width: number;
|
|
538
|
+
height: number;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
export declare interface PositionedAxis {
|
|
542
|
+
/** Optional axis title text and position */
|
|
543
|
+
title?: {
|
|
544
|
+
text: string;
|
|
545
|
+
x: number;
|
|
546
|
+
y: number;
|
|
547
|
+
rotate?: number;
|
|
548
|
+
};
|
|
549
|
+
/** Tick positions along the axis */
|
|
550
|
+
ticks: AxisTick[];
|
|
551
|
+
/** Axis line: start and end coordinates */
|
|
552
|
+
line: {
|
|
553
|
+
x1: number;
|
|
554
|
+
y1: number;
|
|
555
|
+
x2: number;
|
|
556
|
+
y2: number;
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export declare interface PositionedBar {
|
|
561
|
+
/** Bar rectangle in SVG coordinates */
|
|
562
|
+
x: number;
|
|
563
|
+
y: number;
|
|
564
|
+
width: number;
|
|
565
|
+
height: number;
|
|
566
|
+
/** Original data value */
|
|
567
|
+
value: number;
|
|
568
|
+
/** Category label for this bar (e.g. "Jan") */
|
|
569
|
+
label?: string;
|
|
570
|
+
/** Series index within bar type (for layout grouping) */
|
|
571
|
+
seriesIndex: number;
|
|
572
|
+
/** Global color index across all series */
|
|
573
|
+
colorIndex: number;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
export declare interface PositionedBlock {
|
|
577
|
+
type: Block['type'];
|
|
578
|
+
label: string;
|
|
579
|
+
x: number;
|
|
580
|
+
y: number;
|
|
581
|
+
width: number;
|
|
582
|
+
height: number;
|
|
583
|
+
/** Divider lines within the block (for alt/par) */
|
|
584
|
+
dividers: Array<{
|
|
585
|
+
y: number;
|
|
586
|
+
label: string;
|
|
587
|
+
}>;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
export declare interface PositionedClassDiagram {
|
|
591
|
+
width: number;
|
|
592
|
+
height: number;
|
|
593
|
+
classes: PositionedClassNode[];
|
|
594
|
+
relationships: PositionedClassRelationship[];
|
|
595
|
+
notes: PositionedClassNote[];
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
export declare interface PositionedClassNode {
|
|
599
|
+
id: string;
|
|
600
|
+
label: string;
|
|
601
|
+
annotation?: string;
|
|
602
|
+
attributes: ClassMember[];
|
|
603
|
+
methods: ClassMember[];
|
|
604
|
+
x: number;
|
|
605
|
+
y: number;
|
|
606
|
+
width: number;
|
|
607
|
+
height: number;
|
|
608
|
+
/** Height of the header section (name + annotation) */
|
|
609
|
+
headerHeight: number;
|
|
610
|
+
/** Height of the attributes section */
|
|
611
|
+
attrHeight: number;
|
|
612
|
+
/** Height of the methods section */
|
|
613
|
+
methodHeight: number;
|
|
614
|
+
/** Interaction from a `click` statement — an href wraps the class box in an <a> */
|
|
615
|
+
interaction?: NodeInteraction;
|
|
616
|
+
/** Inline styles resolved from classDef + `style` statements — override theme defaults */
|
|
617
|
+
inlineStyle?: Record<string, string>;
|
|
618
|
+
/** Style class assigned via `cssClass`, `class A name`, or `:::name` — emitted onto the group's `class` attribute so external CSS can target it */
|
|
619
|
+
className?: string;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
export declare interface PositionedClassNote {
|
|
623
|
+
/** Layout id — never collides with a class id (class ids contain no spaces) */
|
|
624
|
+
id: string;
|
|
625
|
+
text: string;
|
|
626
|
+
/** Class this note is attached to, when that class exists in the diagram */
|
|
627
|
+
forClass?: string;
|
|
628
|
+
x: number;
|
|
629
|
+
y: number;
|
|
630
|
+
width: number;
|
|
631
|
+
height: number;
|
|
632
|
+
/** Routed path of the dotted note→class link; absent for a free note */
|
|
633
|
+
linkPoints?: Array<{
|
|
634
|
+
x: number;
|
|
635
|
+
y: number;
|
|
636
|
+
}>;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
export declare interface PositionedClassRelationship {
|
|
640
|
+
from: string;
|
|
641
|
+
to: string;
|
|
642
|
+
type: RelationshipType;
|
|
643
|
+
/** Which end of the line has the UML marker — propagated from ClassRelationship */
|
|
644
|
+
markerAt: 'from' | 'to';
|
|
645
|
+
label?: string;
|
|
646
|
+
fromCardinality?: string;
|
|
647
|
+
toCardinality?: string;
|
|
648
|
+
/** Path points from source to target */
|
|
649
|
+
points: Array<{
|
|
650
|
+
x: number;
|
|
651
|
+
y: number;
|
|
652
|
+
}>;
|
|
653
|
+
/** ELK-computed label center position (avoids overlaps between nearby edges) */
|
|
654
|
+
labelPosition?: {
|
|
655
|
+
x: number;
|
|
656
|
+
y: number;
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
export declare interface PositionedErDiagram {
|
|
661
|
+
width: number;
|
|
662
|
+
height: number;
|
|
663
|
+
entities: PositionedErEntity[];
|
|
664
|
+
relationships: PositionedErRelationship[];
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
export declare interface PositionedErEntity {
|
|
668
|
+
id: string;
|
|
669
|
+
label: string;
|
|
670
|
+
attributes: ErAttribute[];
|
|
671
|
+
x: number;
|
|
672
|
+
y: number;
|
|
673
|
+
width: number;
|
|
674
|
+
height: number;
|
|
675
|
+
/** Height of the header row */
|
|
676
|
+
headerHeight: number;
|
|
677
|
+
/** Height per attribute row */
|
|
678
|
+
rowHeight: number;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
export declare interface PositionedErRelationship {
|
|
682
|
+
entity1: string;
|
|
683
|
+
entity2: string;
|
|
684
|
+
cardinality1: Cardinality;
|
|
685
|
+
cardinality2: Cardinality;
|
|
686
|
+
label: string;
|
|
687
|
+
identifying: boolean;
|
|
688
|
+
/** Path points from entity1 to entity2 */
|
|
689
|
+
points: Array<{
|
|
690
|
+
x: number;
|
|
691
|
+
y: number;
|
|
692
|
+
}>;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
export declare interface PositionedLine {
|
|
696
|
+
/** Polyline points */
|
|
697
|
+
points: Array<{
|
|
698
|
+
x: number;
|
|
699
|
+
y: number;
|
|
700
|
+
value: number;
|
|
701
|
+
label?: string;
|
|
702
|
+
}>;
|
|
703
|
+
/** Series index within line type (for layout grouping) */
|
|
704
|
+
seriesIndex: number;
|
|
705
|
+
/** Global color index across all series */
|
|
706
|
+
colorIndex: number;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
export declare interface PositionedMessage {
|
|
710
|
+
from: string;
|
|
711
|
+
to: string;
|
|
712
|
+
label: string;
|
|
713
|
+
lineStyle: 'solid' | 'dashed';
|
|
714
|
+
arrowHead: 'filled' | 'open';
|
|
715
|
+
/** Start point (from actor's lifeline) */
|
|
716
|
+
x1: number;
|
|
717
|
+
/** End point (to actor's lifeline) */
|
|
718
|
+
x2: number;
|
|
719
|
+
/** Vertical position */
|
|
720
|
+
y: number;
|
|
721
|
+
/** Whether this is a self-message (same actor) */
|
|
722
|
+
isSelf: boolean;
|
|
723
|
+
/** Bidirectional arrow (`<<->>` or `<<-->>`) — draw an arrow head on both ends */
|
|
724
|
+
bidirectional: boolean;
|
|
725
|
+
/** Sequence number to display next to this arrow when `autonumber` is active */
|
|
726
|
+
seqNumber?: number;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
export declare interface PositionedNote {
|
|
730
|
+
text: string;
|
|
731
|
+
x: number;
|
|
732
|
+
y: number;
|
|
733
|
+
width: number;
|
|
734
|
+
height: number;
|
|
735
|
+
/** Actor IDs this note is attached to (for SVG attribution) */
|
|
736
|
+
actors?: string[];
|
|
737
|
+
/** Note position relative to actors (for SVG attribution) */
|
|
738
|
+
position?: 'left' | 'right' | 'over';
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/** A positioned `box … end` group: a full-height background behind its participants. */
|
|
742
|
+
export declare interface PositionedParticipantBox {
|
|
743
|
+
label: string;
|
|
744
|
+
/** See {@link ParticipantBox.color}. */
|
|
745
|
+
color?: string;
|
|
746
|
+
x: number;
|
|
747
|
+
y: number;
|
|
748
|
+
width: number;
|
|
749
|
+
height: number;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
export declare interface PositionedSequenceDiagram {
|
|
753
|
+
width: number;
|
|
754
|
+
height: number;
|
|
755
|
+
actors: PositionedActor[];
|
|
756
|
+
lifelines: Lifeline[];
|
|
757
|
+
messages: PositionedMessage[];
|
|
758
|
+
activations: Activation[];
|
|
759
|
+
blocks: PositionedBlock[];
|
|
760
|
+
notes: PositionedNote[];
|
|
761
|
+
/** `box … end` group backgrounds, drawn behind everything else. */
|
|
762
|
+
boxes: PositionedParticipantBox[];
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
export declare interface PositionedTitle {
|
|
766
|
+
text: string;
|
|
767
|
+
x: number;
|
|
768
|
+
y: number;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
export declare interface PositionedXYChart {
|
|
772
|
+
width: number;
|
|
773
|
+
height: number;
|
|
774
|
+
/** Whether this is a horizontal (rotated) chart */
|
|
775
|
+
horizontal?: boolean;
|
|
776
|
+
/** Title text and position (if present) */
|
|
777
|
+
title?: PositionedTitle;
|
|
778
|
+
/** Positioned x-axis with tick marks and labels */
|
|
779
|
+
xAxis: PositionedAxis;
|
|
780
|
+
/** Positioned y-axis with tick marks and labels */
|
|
781
|
+
yAxis: PositionedAxis;
|
|
782
|
+
/** The plot area bounds (inside axes) */
|
|
783
|
+
plotArea: PlotArea;
|
|
784
|
+
/** Positioned bar groups */
|
|
785
|
+
bars: PositionedBar[];
|
|
786
|
+
/** Positioned line polylines */
|
|
787
|
+
lines: PositionedLine[];
|
|
788
|
+
/** Horizontal grid lines for readability */
|
|
789
|
+
gridLines: GridLine[];
|
|
790
|
+
/** Legend items (shown when multiple series) */
|
|
791
|
+
legend: LegendItem[];
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/** Relationship types following UML conventions */
|
|
795
|
+
export declare type RelationshipType = 'inheritance' | 'composition' | 'aggregation' | 'association' | 'dependency' | 'realization';
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Resolve a Mermaid shape name to the geometry this renderer draws.
|
|
799
|
+
* Returns `undefined` for an unrecognized name so the caller can decide
|
|
800
|
+
* whether to fall back or report it.
|
|
801
|
+
*/
|
|
802
|
+
export declare function resolveShapeName(name: string): NodeShape | undefined;
|
|
803
|
+
|
|
804
|
+
/** Parsed sequence diagram — logical structure from mermaid text */
|
|
805
|
+
export declare interface SequenceDiagram {
|
|
806
|
+
/** Ordered list of actors/participants */
|
|
807
|
+
actors: Actor[];
|
|
808
|
+
/** Messages between actors in chronological order */
|
|
809
|
+
messages: Message[];
|
|
810
|
+
/** Structural blocks (loop, alt, opt, par, critical) */
|
|
811
|
+
blocks: Block[];
|
|
812
|
+
/** Notes attached to actors */
|
|
813
|
+
notes: Note[];
|
|
814
|
+
/**
|
|
815
|
+
* Standalone `activate X` / `deactivate X` statements, in source order.
|
|
816
|
+
* The inline `+`/`-` arrow shorthand is *not* recorded here — it stays on
|
|
817
|
+
* `Message.activate` / `Message.deactivate` — but both feed the same
|
|
818
|
+
* activation stack at layout time (see layout.ts), so the two forms
|
|
819
|
+
* render identically.
|
|
820
|
+
*/
|
|
821
|
+
activations: ActivationEvent[];
|
|
822
|
+
/**
|
|
823
|
+
* `box <color?> <label?> … end` participant groups, in source order. A box
|
|
824
|
+
* with no members (nothing declared inside it) is kept here but drawn by
|
|
825
|
+
* neither renderer.
|
|
826
|
+
*/
|
|
827
|
+
boxes: ParticipantBox[];
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/**
|
|
831
|
+
* Narrow a regex-captured block keyword to `Block['type']`, throwing if it
|
|
832
|
+
* somehow isn't one of the seven recognized keywords (see `isBlockType`
|
|
833
|
+
* above — unreachable via the guarding regex in practice, but this keeps
|
|
834
|
+
* the failure explicit rather than silently mistyping the value).
|
|
835
|
+
*
|
|
836
|
+
* Exported for direct unit testing (see
|
|
837
|
+
* src/__tests__/sequence-parser.test.ts) — the throw branch is unreachable
|
|
838
|
+
* through the public `parseSequenceDiagram` API (the regex that captures
|
|
839
|
+
* the value already restricts it to the seven valid keywords), so it can
|
|
840
|
+
* only be exercised by calling this function directly.
|
|
841
|
+
*/
|
|
842
|
+
export declare function toBlockType(value: string): Block['type'];
|
|
843
|
+
|
|
844
|
+
/** Axis configuration — categorical (labels) or numeric (range) */
|
|
845
|
+
export declare interface XYAxis {
|
|
846
|
+
/** Optional axis title/label */
|
|
847
|
+
title?: string;
|
|
848
|
+
/** Categorical labels (e.g., ["jan", "feb", "mar"]) — mutually exclusive with range */
|
|
849
|
+
categories?: string[];
|
|
850
|
+
/** Numeric range — mutually exclusive with categories */
|
|
851
|
+
range?: {
|
|
852
|
+
min: number;
|
|
853
|
+
max: number;
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/** Parsed XY chart — logical structure from mermaid text */
|
|
858
|
+
export declare interface XYChart {
|
|
859
|
+
/** Optional chart title */
|
|
860
|
+
title?: string;
|
|
861
|
+
/** Chart orientation: vertical (default) or horizontal */
|
|
862
|
+
horizontal: boolean;
|
|
863
|
+
/** X-axis configuration */
|
|
864
|
+
xAxis: XYAxis;
|
|
865
|
+
/** Y-axis configuration */
|
|
866
|
+
yAxis: XYAxis;
|
|
867
|
+
/** Data series (bar and/or line) */
|
|
868
|
+
series: XYChartSeries[];
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/** A single data series (bar or line) */
|
|
872
|
+
export declare interface XYChartSeries {
|
|
873
|
+
/** Series type */
|
|
874
|
+
type: 'bar' | 'line';
|
|
875
|
+
/** Data values — one per category, or evenly spaced across numeric range */
|
|
876
|
+
data: number[];
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
export { }
|