mermaid-ast 0.3.0 → 0.5.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.
Files changed (145) hide show
  1. package/README.md +301 -4
  2. package/dist/class-diagram.d.ts +129 -0
  3. package/dist/class-diagram.d.ts.map +1 -0
  4. package/dist/class-diagram.js +341 -0
  5. package/dist/diagram-wrapper.d.ts +66 -0
  6. package/dist/diagram-wrapper.d.ts.map +1 -0
  7. package/dist/diagram-wrapper.js +59 -0
  8. package/dist/er-diagram.d.ts +214 -0
  9. package/dist/er-diagram.d.ts.map +1 -0
  10. package/dist/er-diagram.js +405 -0
  11. package/dist/flowchart-graph-ops.d.ts +58 -0
  12. package/dist/flowchart-graph-ops.d.ts.map +1 -0
  13. package/dist/flowchart-graph-ops.js +262 -0
  14. package/dist/flowchart-types.d.ts +58 -0
  15. package/dist/flowchart-types.d.ts.map +1 -0
  16. package/dist/flowchart-types.js +6 -0
  17. package/dist/flowchart.d.ts +304 -0
  18. package/dist/flowchart.d.ts.map +1 -0
  19. package/dist/flowchart.js +615 -0
  20. package/dist/gantt.d.ts +199 -0
  21. package/dist/gantt.d.ts.map +1 -0
  22. package/dist/gantt.js +452 -0
  23. package/dist/index.d.ts +25 -3
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +26 -4
  26. package/dist/journey.d.ts +150 -0
  27. package/dist/journey.d.ts.map +1 -0
  28. package/dist/journey.js +317 -0
  29. package/dist/mindmap.d.ts +142 -0
  30. package/dist/mindmap.d.ts.map +1 -0
  31. package/dist/mindmap.js +350 -0
  32. package/dist/parser/class-parser.d.ts +1 -1
  33. package/dist/parser/class-parser.d.ts.map +1 -1
  34. package/dist/parser/class-parser.js +36 -32
  35. package/dist/parser/er-parser.d.ts +13 -0
  36. package/dist/parser/er-parser.d.ts.map +1 -0
  37. package/dist/parser/er-parser.js +119 -0
  38. package/dist/parser/flowchart-parser.d.ts +1 -1
  39. package/dist/parser/flowchart-parser.d.ts.map +1 -1
  40. package/dist/parser/flowchart-parser.js +51 -53
  41. package/dist/parser/gantt-parser.d.ts +13 -0
  42. package/dist/parser/gantt-parser.d.ts.map +1 -0
  43. package/dist/parser/gantt-parser.js +182 -0
  44. package/dist/parser/index.d.ts +4 -4
  45. package/dist/parser/index.d.ts.map +1 -1
  46. package/dist/parser/index.js +13 -13
  47. package/dist/parser/journey-parser.d.ts +13 -0
  48. package/dist/parser/journey-parser.d.ts.map +1 -0
  49. package/dist/parser/journey-parser.js +99 -0
  50. package/dist/parser/mindmap-parser.d.ts +13 -0
  51. package/dist/parser/mindmap-parser.d.ts.map +1 -0
  52. package/dist/parser/mindmap-parser.js +196 -0
  53. package/dist/parser/sequence-parser.d.ts +1 -1
  54. package/dist/parser/sequence-parser.d.ts.map +1 -1
  55. package/dist/parser/sequence-parser.js +88 -82
  56. package/dist/parser/state-parser.d.ts +1 -1
  57. package/dist/parser/state-parser.d.ts.map +1 -1
  58. package/dist/parser/state-parser.js +35 -36
  59. package/dist/parser/timeline-parser.d.ts +13 -0
  60. package/dist/parser/timeline-parser.d.ts.map +1 -0
  61. package/dist/parser/timeline-parser.js +97 -0
  62. package/dist/renderer/class-renderer.d.ts +2 -2
  63. package/dist/renderer/class-renderer.d.ts.map +1 -1
  64. package/dist/renderer/class-renderer.js +27 -32
  65. package/dist/renderer/doc.d.ts.map +1 -1
  66. package/dist/renderer/doc.js +9 -9
  67. package/dist/renderer/er-renderer.d.ts +19 -0
  68. package/dist/renderer/er-renderer.d.ts.map +1 -0
  69. package/dist/renderer/er-renderer.js +131 -0
  70. package/dist/renderer/flowchart-renderer.d.ts +2 -2
  71. package/dist/renderer/flowchart-renderer.d.ts.map +1 -1
  72. package/dist/renderer/flowchart-renderer.js +61 -77
  73. package/dist/renderer/gantt-renderer.d.ts +19 -0
  74. package/dist/renderer/gantt-renderer.d.ts.map +1 -0
  75. package/dist/renderer/gantt-renderer.js +118 -0
  76. package/dist/renderer/index.d.ts +4 -4
  77. package/dist/renderer/index.d.ts.map +1 -1
  78. package/dist/renderer/index.js +7 -7
  79. package/dist/renderer/journey-renderer.d.ts +19 -0
  80. package/dist/renderer/journey-renderer.d.ts.map +1 -0
  81. package/dist/renderer/journey-renderer.js +40 -0
  82. package/dist/renderer/mindmap-renderer.d.ts +19 -0
  83. package/dist/renderer/mindmap-renderer.d.ts.map +1 -0
  84. package/dist/renderer/mindmap-renderer.js +98 -0
  85. package/dist/renderer/sequence-renderer.d.ts +2 -2
  86. package/dist/renderer/sequence-renderer.d.ts.map +1 -1
  87. package/dist/renderer/sequence-renderer.js +60 -59
  88. package/dist/renderer/state-renderer.d.ts +2 -2
  89. package/dist/renderer/state-renderer.d.ts.map +1 -1
  90. package/dist/renderer/state-renderer.js +19 -21
  91. package/dist/renderer/timeline-renderer.d.ts +19 -0
  92. package/dist/renderer/timeline-renderer.d.ts.map +1 -0
  93. package/dist/renderer/timeline-renderer.js +37 -0
  94. package/dist/sequence.d.ts +134 -0
  95. package/dist/sequence.d.ts.map +1 -0
  96. package/dist/sequence.js +457 -0
  97. package/dist/state-diagram.d.ts +117 -0
  98. package/dist/state-diagram.d.ts.map +1 -0
  99. package/dist/state-diagram.js +331 -0
  100. package/dist/timeline.d.ts +150 -0
  101. package/dist/timeline.d.ts.map +1 -0
  102. package/dist/timeline.js +334 -0
  103. package/dist/types/class.d.ts +6 -6
  104. package/dist/types/class.js +2 -2
  105. package/dist/types/er.d.ts +105 -0
  106. package/dist/types/er.d.ts.map +1 -0
  107. package/dist/types/er.js +19 -0
  108. package/dist/types/flowchart.d.ts +8 -8
  109. package/dist/types/flowchart.js +2 -2
  110. package/dist/types/gantt.d.ts +101 -0
  111. package/dist/types/gantt.d.ts.map +1 -0
  112. package/dist/types/gantt.js +18 -0
  113. package/dist/types/index.d.ts +39 -9
  114. package/dist/types/index.d.ts.map +1 -1
  115. package/dist/types/index.js +42 -7
  116. package/dist/types/journey.d.ts +44 -0
  117. package/dist/types/journey.d.ts.map +1 -0
  118. package/dist/types/journey.js +14 -0
  119. package/dist/types/mindmap.d.ts +45 -0
  120. package/dist/types/mindmap.d.ts.map +1 -0
  121. package/dist/types/mindmap.js +13 -0
  122. package/dist/types/render-options.d.ts +1 -1
  123. package/dist/types/render-options.js +4 -4
  124. package/dist/types/sequence.d.ts +20 -20
  125. package/dist/types/sequence.js +1 -1
  126. package/dist/types/state.d.ts +12 -12
  127. package/dist/types/state.js +2 -2
  128. package/dist/types/timeline.d.ts +49 -0
  129. package/dist/types/timeline.d.ts.map +1 -0
  130. package/dist/types/timeline.js +14 -0
  131. package/dist/utils.d.ts +29 -0
  132. package/dist/utils.d.ts.map +1 -0
  133. package/dist/utils.js +30 -0
  134. package/dist/vendored/grammars/er.jison +294 -0
  135. package/dist/vendored/grammars/gantt.jison +188 -0
  136. package/dist/vendored/grammars/journey.jison +69 -0
  137. package/dist/vendored/grammars/mindmap.jison +127 -0
  138. package/dist/vendored/grammars/timeline.jison +79 -0
  139. package/dist/vendored/parsers/er.js +891 -0
  140. package/dist/vendored/parsers/gantt.js +762 -0
  141. package/dist/vendored/parsers/journey.js +615 -0
  142. package/dist/vendored/parsers/mindmap.js +663 -0
  143. package/dist/vendored/parsers/timeline.js +616 -0
  144. package/dist/vendored/sync-info.json +14 -9
  145. package/package.json +8 -4
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # mermaid-ast
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/mermaid-ast)](https://www.npmjs.com/package/mermaid-ast)
4
+ [![JSR](https://jsr.io/badges/@emily/mermaid-ast)](https://jsr.io/@emily/mermaid-ast)
4
5
  [![Built with Slate](https://img.shields.io/badge/Built%20with-Slate-blue)](https://randomlabs.ai)
5
6
 
6
7
  Parse and render Mermaid diagrams to/from AST (Abstract Syntax Tree).
@@ -17,9 +18,25 @@ This library provides a way to programmatically work with Mermaid diagrams by pa
17
18
 
18
19
  ## Supported Diagram Types
19
20
 
20
- - **Flowchart** (`flowchart`, `graph`)
21
- - **Sequence Diagram** (`sequenceDiagram`)
22
- - **Class Diagram** (`classDiagram`)
21
+ | Diagram Type | Parse | Render | Wrapper Class |
22
+ |--------------|-------|--------|---------------|
23
+ | Flowchart (`flowchart`, `graph`) | ✅ | ✅ | ✅ `Flowchart` |
24
+ | Sequence (`sequenceDiagram`) | ✅ | ✅ | ✅ `Sequence` |
25
+ | Class (`classDiagram`) | ✅ | ✅ | ✅ `ClassDiagram` |
26
+ | State (`stateDiagram`) | ✅ | ✅ | ✅ `StateDiagram` |
27
+ | ER Diagram (`erDiagram`) | ✅ | ✅ | ✅ `ErDiagram` |
28
+ | Gantt (`gantt`) | ✅ | ✅ | ✅ `Gantt` |
29
+ | Mindmap (`mindmap`) | ✅ | ✅ | ✅ `Mindmap` |
30
+ | Journey (`journey`) | ✅ | ✅ | ✅ `Journey` |
31
+ | Timeline (`timeline`) | ✅ | ✅ | ✅ `Timeline` |
32
+ | Pie (`pie`) | ❌ | ❌ | ❌ |
33
+ | Quadrant (`quadrantChart`) | ❌ | ❌ | ❌ |
34
+ | Requirement (`requirementDiagram`) | ❌ | ❌ | ❌ |
35
+ | Git Graph (`gitGraph`) | ❌ | ❌ | ❌ |
36
+ | C4 (`C4Context`, etc.) | ❌ | ❌ | ❌ |
37
+ | Sankey (`sankey`) | ❌ | ❌ | ❌ |
38
+ | XY Chart (`xychart`) | ❌ | ❌ | ❌ |
39
+ | Block (`block`) | ❌ | ❌ | ❌ |
23
40
 
24
41
  ## Installation
25
42
 
@@ -131,7 +148,287 @@ detectDiagramType("classDiagram\n class Animal"); // "class"
131
148
  detectDiagramType("unknown diagram"); // null
132
149
  ```
133
150
 
134
- ### Render Options (Pretty-Print)
151
+ ## Flowchart Wrapper Class (Recommended)
152
+
153
+ The `Flowchart` class provides a unified API for building, mutating, and querying flowchart diagrams. This is the recommended way to work with flowcharts programmatically.
154
+
155
+ ### Creating Flowcharts
156
+
157
+ ```typescript
158
+ import { Flowchart } from "mermaid-ast";
159
+
160
+ // Create empty flowchart
161
+ const f = Flowchart.create("LR");
162
+
163
+ // Parse existing diagram
164
+ const f = Flowchart.parse(`flowchart LR
165
+ A --> B --> C`);
166
+
167
+ // Wrap existing AST
168
+ const f = Flowchart.from(existingAst);
169
+ ```
170
+
171
+ ### Building Flowcharts
172
+
173
+ ```typescript
174
+ const diagram = Flowchart.create("LR")
175
+ .addNode("A", "Start", { shape: "stadium" })
176
+ .addNode("B", "Process")
177
+ .addNode("C", "End", { shape: "circle" })
178
+ .addLink("A", "B", { text: "begin" })
179
+ .addLink("B", "C")
180
+ .createSubgraph("sub1", ["B"], "Processing")
181
+ .addClass("A", "highlight");
182
+
183
+ console.log(diagram.render());
184
+ ```
185
+
186
+ ### Mutating Flowcharts
187
+
188
+ ```typescript
189
+ const diagram = Flowchart.parse(`flowchart LR
190
+ A --> B --> C --> D`);
191
+
192
+ // Change node properties
193
+ diagram.setNodeText("A", "New Start");
194
+ diagram.setNodeShape("A", "diamond");
195
+
196
+ // Modify links
197
+ diagram.flipLink(0); // Reverse direction
198
+ diagram.setLinkText(0, "label");
199
+
200
+ // Add/remove classes
201
+ diagram.addClass("B", "highlight");
202
+ diagram.removeClass("B", "highlight");
203
+
204
+ // Remove a node and reconnect neighbors
205
+ diagram.removeNode("B", { reconnect: true });
206
+ // Result: A --> C --> D
207
+ ```
208
+
209
+ ### Querying Flowcharts
210
+
211
+ ```typescript
212
+ const diagram = Flowchart.parse(`flowchart TD
213
+ A[Start] --> B{Decision}
214
+ B -->|Yes| C[OK]
215
+ B -->|No| D[Cancel]`);
216
+
217
+ // Find nodes
218
+ diagram.findNodes({ class: "highlight" });
219
+ diagram.findNodes({ shape: "diamond" });
220
+ diagram.findNodes({ textContains: "Start" });
221
+
222
+ // Get links
223
+ diagram.getLinksFrom("B"); // Outgoing links
224
+ diagram.getLinksTo("B"); // Incoming links
225
+
226
+ // Graph traversal
227
+ diagram.getReachable("A"); // All nodes reachable from A
228
+ diagram.getAncestors("C"); // All nodes that can reach C
229
+ diagram.getPath("A", "C"); // Shortest path: ["A", "B", "C"]
230
+ ```
231
+
232
+ ### Chain Operations (jj-style)
233
+
234
+ Inspired by [jj](https://github.com/martinvonz/jj), these operations let you manipulate chains of nodes:
235
+
236
+ ```typescript
237
+ const diagram = Flowchart.create()
238
+ .addNode("X").addNode("A").addNode("B").addNode("C").addNode("Y")
239
+ .addLink("X", "A").addLink("A", "B").addLink("B", "C").addLink("C", "Y");
240
+
241
+ // Yank (remove) a chain and reconnect
242
+ diagram.yankChain(["A", "B", "C"]);
243
+ // Result: X --> Y
244
+
245
+ // Splice a chain between nodes
246
+ diagram.spliceChain(["A", "B"], "X", "Y");
247
+ // Result: X --> A --> B --> Y
248
+
249
+ // Reverse a chain's direction
250
+ diagram.reverseChain(["A", "B", "C"]);
251
+ // Changes A-->B-->C to A<--B<--C
252
+
253
+ // Extract a chain as a new Flowchart
254
+ const extracted = diagram.extractChain(["B", "C"]);
255
+
256
+ // Rebase nodes to a new parent
257
+ diagram.rebaseNodes(["A", "B"], "NewParent");
258
+
259
+ // Get a linear chain between two nodes
260
+ diagram.getChain("A", "D"); // ["A", "B", "C", "D"] if linear
261
+ ```
262
+
263
+ ### Subgraph Operations
264
+
265
+ ```typescript
266
+ const diagram = Flowchart.create()
267
+ .addNode("A").addNode("B").addNode("C")
268
+ .createSubgraph("sub1", ["A", "B"], "Group 1")
269
+ .createSubgraph("sub2", ["C"], "Group 2");
270
+
271
+ // Move nodes between subgraphs
272
+ diagram.moveToSubgraph(["B"], "sub2");
273
+
274
+ // Extract nodes to root level
275
+ diagram.extractFromSubgraph(["A"]);
276
+
277
+ // Merge subgraphs
278
+ diagram.mergeSubgraphs("sub1", "sub2");
279
+
280
+ // Dissolve a subgraph (keep nodes, remove grouping)
281
+ diagram.dissolveSubgraph("sub1");
282
+ ```
283
+
284
+ ## Other Wrapper Classes
285
+
286
+ Similar to `Flowchart`, we provide wrapper classes for other diagram types:
287
+
288
+ ### ErDiagram
289
+
290
+ ```typescript
291
+ import { ErDiagram } from "mermaid-ast";
292
+
293
+ const diagram = ErDiagram.create()
294
+ .addEntity("Customer")
295
+ .addAttribute("Customer", "id", "int", ["PK"])
296
+ .addAttribute("Customer", "name", "string")
297
+ .addEntity("Order")
298
+ .addRelationship("Customer", "Order", "places", {
299
+ fromCardinality: "one_or_more",
300
+ toCardinality: "zero_or_more"
301
+ });
302
+
303
+ console.log(diagram.render());
304
+ ```
305
+
306
+ ### Gantt
307
+
308
+ ```typescript
309
+ import { Gantt } from "mermaid-ast";
310
+
311
+ const diagram = Gantt.create("Project Timeline")
312
+ .setDateFormat("YYYY-MM-DD")
313
+ .addSection("Planning")
314
+ .addTask("Planning", "Research", { id: "a1", duration: "3d" })
315
+ .addTask("Planning", "Design", { id: "a2", duration: "5d", after: "a1" })
316
+ .addSection("Development")
317
+ .addTask("Development", "Implementation", { duration: "10d", after: "a2" });
318
+
319
+ console.log(diagram.render());
320
+ ```
321
+
322
+ ### Mindmap
323
+
324
+ ```typescript
325
+ import { Mindmap } from "mermaid-ast";
326
+
327
+ const diagram = Mindmap.create("Project")
328
+ .addChild("root", "Frontend", { shape: "square" })
329
+ .addChild("root", "Backend", { shape: "square" })
330
+ .addChild("Frontend", "React")
331
+ .addChild("Frontend", "CSS")
332
+ .addChild("Backend", "API")
333
+ .addChild("Backend", "Database");
334
+
335
+ console.log(diagram.render());
336
+ ```
337
+
338
+ ### Journey
339
+
340
+ ```typescript
341
+ import { Journey } from "mermaid-ast";
342
+
343
+ const diagram = Journey.create("User Onboarding")
344
+ .addSection("Discovery")
345
+ .addTask("Discovery", "Visit website", 5, ["User"])
346
+ .addTask("Discovery", "Read docs", 3, ["User"])
347
+ .addSection("Signup")
348
+ .addTask("Signup", "Create account", 4, ["User"])
349
+ .addTask("Signup", "Verify email", 2, ["User", "System"]);
350
+
351
+ console.log(diagram.render());
352
+ ```
353
+
354
+ ### Timeline
355
+
356
+ ```typescript
357
+ import { Timeline } from "mermaid-ast";
358
+
359
+ const diagram = Timeline.create("Company History")
360
+ .addSection("2020s")
361
+ .addPeriod("2020s", "2020")
362
+ .addEvent("2020", "Company founded")
363
+ .addEvent("2020", "First product launch")
364
+ .addPeriod("2020s", "2023")
365
+ .addEvent("2023", "Series A funding");
366
+
367
+ console.log(diagram.render());
368
+ ```
369
+
370
+ ### Sequence
371
+
372
+ ```typescript
373
+ import { Sequence } from "mermaid-ast";
374
+
375
+ const diagram = Sequence.create()
376
+ .addActor("alice", "Alice", "participant")
377
+ .addActor("bob", "Bob", "actor")
378
+ .addMessage("alice", "bob", "Hello Bob!", { type: "solid", arrow: "filled" })
379
+ .addMessage("bob", "alice", "Hi Alice!", { type: "dashed", arrow: "filled" })
380
+ .addLoop("Every minute", (loop) => {
381
+ loop.addMessage("bob", "alice", "Ping");
382
+ })
383
+ .addNote("alice", "Important note", { placement: "right" });
384
+
385
+ console.log(diagram.render());
386
+ ```
387
+
388
+ ### ClassDiagram
389
+
390
+ ```typescript
391
+ import { ClassDiagram } from "mermaid-ast";
392
+
393
+ const diagram = ClassDiagram.create()
394
+ .addClass("Animal")
395
+ .addAttribute("Animal", "name: string", "+")
396
+ .addAttribute("Animal", "age: int", "-")
397
+ .addMethod("Animal", "speak()", "+")
398
+ .addClass("Dog")
399
+ .addInheritance("Dog", "Animal")
400
+ .addMethod("Dog", "bark()", "+")
401
+ .addClass("Cat")
402
+ .addInheritance("Cat", "Animal")
403
+ .addMethod("Cat", "meow()", "+");
404
+
405
+ console.log(diagram.render());
406
+ ```
407
+
408
+ ### StateDiagram
409
+
410
+ ```typescript
411
+ import { StateDiagram } from "mermaid-ast";
412
+
413
+ const diagram = StateDiagram.create()
414
+ .addState("Idle", { description: "Waiting for input" })
415
+ .addState("Running")
416
+ .addState("Done")
417
+ .addInitial("Idle")
418
+ .addTransition("Idle", "Running", { label: "start" })
419
+ .addTransition("Running", "Done", { label: "complete" })
420
+ .addFinal("Done")
421
+ .addComposite("Running", (composite) => {
422
+ composite
423
+ .addState("Step1")
424
+ .addState("Step2")
425
+ .addTransition("Step1", "Step2");
426
+ });
427
+
428
+ console.log(diagram.render());
429
+ ```
430
+
431
+ ## Render Options (Pretty-Print)
135
432
 
136
433
  All render functions accept an optional `RenderOptions` object to customize output formatting:
137
434
 
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Class Diagram Wrapper Class
3
+ *
4
+ * A unified API for building, mutating, and querying class diagrams.
5
+ * Provides a fluent interface that wraps the ClassDiagramAST.
6
+ */
7
+ import { DiagramWrapper } from './diagram-wrapper.js';
8
+ import type { ClassDefinition, ClassDiagramAST, ClassDirection, ClassMember, ClassRelation, LineType, RelationType } from './types/class.js';
9
+ import type { RenderOptions } from './types/render-options.js';
10
+ /** Options for adding a class */
11
+ export interface AddClassOptions {
12
+ label?: string;
13
+ annotation?: string;
14
+ }
15
+ /** Options for adding a member */
16
+ export interface AddMemberOptions {
17
+ visibility?: '+' | '-' | '#' | '~';
18
+ type?: 'method' | 'attribute';
19
+ }
20
+ /** Options for adding a relation */
21
+ export interface AddRelationOptions {
22
+ label?: string;
23
+ labelFrom?: string;
24
+ labelTo?: string;
25
+ lineType?: LineType;
26
+ }
27
+ /**
28
+ * A fluent wrapper for ClassDiagramAST that supports building, mutating, and querying.
29
+ */
30
+ export declare class ClassDiagram extends DiagramWrapper<ClassDiagramAST> {
31
+ private constructor();
32
+ /** Create a new empty class diagram */
33
+ static create(direction?: ClassDirection): ClassDiagram;
34
+ /** Create from an existing AST */
35
+ static from(ast: ClassDiagramAST): ClassDiagram;
36
+ /** Parse Mermaid syntax into a ClassDiagram */
37
+ static parse(input: string): ClassDiagram;
38
+ render(options?: RenderOptions): string;
39
+ clone(): ClassDiagram;
40
+ get direction(): ClassDirection;
41
+ get classCount(): number;
42
+ get relationCount(): number;
43
+ get classes(): Map<string, {
44
+ id: string;
45
+ label?: string;
46
+ memberCount: number;
47
+ }>;
48
+ setDirection(direction: ClassDirection): this;
49
+ /** Add a class */
50
+ addClass(id: string, options?: AddClassOptions): this;
51
+ /** Remove a class and optionally its relations */
52
+ removeClass(id: string, options?: {
53
+ removeRelations?: boolean;
54
+ }): this;
55
+ /** Rename a class */
56
+ renameClass(id: string, newId: string): this;
57
+ /** Get a class by ID */
58
+ getClass(id: string): ClassDefinition | undefined;
59
+ /** Check if class exists */
60
+ hasClass(id: string): boolean;
61
+ /** Set class label */
62
+ setClassLabel(id: string, label: string): this;
63
+ /** Add annotation to class */
64
+ addAnnotation(id: string, annotation: string): this;
65
+ /** Remove annotation from class */
66
+ removeAnnotation(id: string, annotation: string): this;
67
+ /** Add a member (attribute or method) to a class */
68
+ addMember(classId: string, text: string, options?: AddMemberOptions): this;
69
+ /** Add an attribute to a class */
70
+ addAttribute(classId: string, text: string, visibility?: '+' | '-' | '#' | '~'): this;
71
+ /** Add a method to a class */
72
+ addMethod(classId: string, text: string, visibility?: '+' | '-' | '#' | '~'): this;
73
+ /** Get members of a class */
74
+ getMembers(classId: string): ClassMember[];
75
+ /** Remove a member from a class */
76
+ removeMember(classId: string, text: string): this;
77
+ /** Add a relation between classes */
78
+ addRelation(from: string, to: string, relationType: RelationType, options?: AddRelationOptions): this;
79
+ /** Add inheritance relation (A extends B) */
80
+ addInheritance(child: string, parent: string, options?: AddRelationOptions): this;
81
+ /** Add composition relation */
82
+ addComposition(whole: string, part: string, options?: AddRelationOptions): this;
83
+ /** Add aggregation relation */
84
+ addAggregation(whole: string, part: string, options?: AddRelationOptions): this;
85
+ /** Add dependency relation */
86
+ addDependency(from: string, to: string, options?: AddRelationOptions): this;
87
+ /** Add association (simple line) */
88
+ addAssociation(from: string, to: string, options?: AddRelationOptions): this;
89
+ /** Get all relations */
90
+ getRelations(): ClassRelation[];
91
+ /** Get relations for a class */
92
+ getRelationsFor(classId: string): ClassRelation[];
93
+ /** Remove a relation */
94
+ removeRelation(from: string, to: string): this;
95
+ /** Add a namespace */
96
+ addNamespace(name: string, classIds?: string[]): this;
97
+ /** Add class to namespace */
98
+ addToNamespace(namespace: string, classId: string): this;
99
+ /** Remove class from namespace */
100
+ removeFromNamespace(namespace: string, classId: string): this;
101
+ /** Get namespace for a class */
102
+ getNamespaceFor(classId: string): string | undefined;
103
+ /** Add a note */
104
+ addNote(text: string, forClass?: string): this;
105
+ /** Get all notes */
106
+ getNotes(): Array<{
107
+ text: string;
108
+ forClass?: string;
109
+ }>;
110
+ /** Define a class style */
111
+ defineStyle(name: string, styles: string[]): this;
112
+ /** Apply style to a class */
113
+ applyStyle(classId: string, styleName: string): this;
114
+ /** Find classes by criteria */
115
+ findClasses(query: {
116
+ hasAnnotation?: string;
117
+ hasStyle?: string;
118
+ inNamespace?: string;
119
+ }): ClassDefinition[];
120
+ /** Get all subclasses of a class (direct inheritance) */
121
+ getSubclasses(classId: string): string[];
122
+ /** Get parent class (direct inheritance) */
123
+ getParentClass(classId: string): string | undefined;
124
+ /** Get all ancestors (transitive inheritance) */
125
+ getAncestors(classId: string): string[];
126
+ /** Get all descendants (transitive inheritance) */
127
+ getDescendants(classId: string): string[];
128
+ }
129
+ //# sourceMappingURL=class-diagram.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class-diagram.d.ts","sourceRoot":"","sources":["../src/class-diagram.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,cAAc,EACd,WAAW,EACX,aAAa,EACb,QAAQ,EACR,YAAY,EACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,iCAAiC;AACjC,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,kCAAkC;AAClC,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACnC,IAAI,CAAC,EAAE,QAAQ,GAAG,WAAW,CA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