ts-graphviz 1.8.3-dev.273c1f434 → 2.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 (51) hide show
  1. package/CHANGELOG.md +344 -0
  2. package/README.md +40 -13
  3. package/lib/adapter.cjs +1 -0
  4. package/lib/adapter.d.ts +1 -0
  5. package/lib/adapter.js +1 -0
  6. package/lib/ast.cjs +1 -0
  7. package/lib/ast.d.ts +1 -0
  8. package/lib/ast.js +1 -0
  9. package/lib/attribute.d.ts +2 -0
  10. package/lib/from-dot.d.ts +10 -0
  11. package/lib/model-factory-builder.d.ts +7 -0
  12. package/lib/model-factory.d.ts +6 -0
  13. package/lib/to-dot.d.ts +7 -0
  14. package/lib/ts-graphviz.cjs +1 -0
  15. package/lib/ts-graphviz.d.ts +7 -0
  16. package/lib/ts-graphviz.js +55 -0
  17. package/lib/types.d.ts +14 -0
  18. package/media/adapter-state-machine.svg +1 -1
  19. package/media/state-machine.svg +1 -1
  20. package/media/ts-graphviz.svg +1 -1
  21. package/package.json +69 -119
  22. package/SECURITY.md +0 -5
  23. package/lib/adapter/browser/index.cjs +0 -12
  24. package/lib/adapter/browser/index.d.ts +0 -15
  25. package/lib/adapter/browser/index.js +0 -9
  26. package/lib/adapter/deno/mod.d.ts +0 -13
  27. package/lib/adapter/deno/mod.js +0 -36
  28. package/lib/adapter/node/index.cjs +0 -45
  29. package/lib/adapter/node/index.d.ts +0 -15
  30. package/lib/adapter/node/index.js +0 -42
  31. package/lib/adapter/types/index.cjs +0 -1
  32. package/lib/adapter/types/index.d.ts +0 -134
  33. package/lib/adapter/types/index.js +0 -0
  34. package/lib/adapter/utils/index.cjs +0 -58
  35. package/lib/adapter/utils/index.d.ts +0 -11
  36. package/lib/adapter/utils/index.js +0 -56
  37. package/lib/ast/index.cjs +0 -5775
  38. package/lib/ast/index.d.ts +0 -946
  39. package/lib/ast/index.js +0 -5770
  40. package/lib/common/index.cjs +0 -58
  41. package/lib/common/index.d.ts +0 -4981
  42. package/lib/common/index.js +0 -58
  43. package/lib/core/index.cjs +0 -359
  44. package/lib/core/index.d.ts +0 -347
  45. package/lib/core/index.js +0 -364
  46. package/lib/index.cjs +0 -23
  47. package/lib/index.d.ts +0 -3
  48. package/lib/index.js +0 -2
  49. package/lib/utils/index.cjs +0 -41
  50. package/lib/utils/index.d.ts +0 -34
  51. package/lib/utils/index.js +0 -37
@@ -1,946 +0,0 @@
1
- import {
2
- Compass,
3
- AttributeKey,
4
- ASTType,
5
- DotObjectModel,
6
- RootGraphModel,
7
- EdgeModel,
8
- NodeModel,
9
- SubgraphModel,
10
- ModelsContext,
11
- } from '../common/index.js';
12
-
13
- /**
14
- * The FilePosition interface represents the position of a file in terms of its offset, line number, and column number.
15
- *
16
- * @group AST
17
- */
18
- interface FilePosition$1 {
19
- /**
20
- * The offset of the file.
21
- */
22
- offset: number;
23
- /**
24
- * The line number of the file.
25
- */
26
- line: number;
27
- /**
28
- * The column number of the file.
29
- */
30
- column: number;
31
- }
32
- /**
33
- * FileRange interface represents a range of positions within a file.
34
- * @group AST
35
- */
36
- interface FileRange$1 {
37
- /**
38
- * The start position of the range.
39
- */
40
- start: FilePosition$1;
41
- /**
42
- * The end position of the range.
43
- */
44
- end: FilePosition$1;
45
- }
46
- /**
47
- * This interface provides common properties to be used across all abstract syntax tree (AST) objects.
48
- *
49
- * @group AST
50
- */
51
- interface ASTCommonPropaties {
52
- /**
53
- * The start and end location of the AST object.
54
- */
55
- location?: FileRange$1;
56
- }
57
- /**
58
- * This interface represents the properties of a dot AST node.
59
- * @group AST
60
- */
61
- interface DotASTPropaties extends ASTCommonPropaties {}
62
- /**
63
- * This interface defines the properties of a Graph AST Node.
64
- * @group AST
65
- */
66
- interface GraphASTPropaties extends ASTCommonPropaties {
67
- /**
68
- * An optional identifier for the Graph AST Node.
69
- */
70
- id?: LiteralASTNode;
71
- /**
72
- * A boolean indicating whether the graph is directed.
73
- */
74
- directed: boolean;
75
- /**
76
- * A boolean indicating whether the graph is strict.
77
- */
78
- strict: boolean;
79
- }
80
- /**
81
- * LiteralASTPropaties defines interface for literal AST nodes.
82
- *
83
- * @group AST
84
- */
85
- interface LiteralASTPropaties<T extends string = string> extends ASTCommonPropaties {
86
- /**
87
- * The value of the literal.
88
- */
89
- value: T;
90
- /**
91
- * A flag indicating whether the literal was quoted or not.
92
- * If 'html' then the literal is an html like value.
93
- */
94
- quoted: boolean | 'html';
95
- }
96
- /**
97
- * SubgraphASTPropaties describes the properties of an AST node representing a subgraph.
98
- * @group AST
99
- */
100
- interface SubgraphASTPropaties extends ASTCommonPropaties {
101
- /**
102
- * id is an optional {@link LiteralASTNode} that represents the identifier of the subgraph.
103
- */
104
- id?: LiteralASTNode;
105
- }
106
- /**
107
- * SubgraphASTPropaties describes the properties of an AST node representing a node.
108
- * @group AST
109
- */
110
- interface NodeASTPropaties extends ASTCommonPropaties {
111
- /**
112
- * The unique identifier of the node.
113
- */
114
- id: LiteralASTNode;
115
- }
116
- /**
117
- * EdgeASTPropaties is an interface that defines the properties of an {@link EdgeASTNode}.
118
- * @group AST
119
- */
120
- interface EdgeASTPropaties extends ASTCommonPropaties {
121
- /**
122
- * An array of EdgeTargetASTNodes.
123
- * The {@link EdgeTargetASTNode} represents a node that is the target of an edge.
124
- */
125
- targets: [from: EdgeTargetASTNode, to: EdgeTargetASTNode, ...rest: EdgeTargetASTNode[]];
126
- }
127
- /**
128
- * NodeRefASTPropaties is an interface that defines the properties of a {@link NodeRefASTNode}.
129
- * @group AST
130
- */
131
- interface NodeRefASTPropaties extends ASTCommonPropaties {
132
- id: LiteralASTNode;
133
- port?: LiteralASTNode;
134
- compass?: LiteralASTNode<Compass>;
135
- }
136
- /**
137
- * NodeRefGroupASTPropaties is an interface that defines the properties of a {@link NodeRefGroupASTNode}.
138
- * @group AST
139
- */
140
- interface NodeRefGroupASTPropaties extends ASTCommonPropaties {}
141
- /**
142
- * AttributeASTPropaties interface defines the properties of an {@link AttributeASTNode}.
143
- * @group AST
144
- */
145
- interface AttributeASTPropaties<T extends AttributeKey = AttributeKey> extends ASTCommonPropaties {
146
- key: LiteralASTNode<T>;
147
- value: LiteralASTNode;
148
- }
149
- /**
150
- * AttributeListASTPropaties interface defines the properties of an {@link AttributeListASTNode}.
151
- * @group AST
152
- */
153
- interface AttributeListASTPropaties extends ASTCommonPropaties {
154
- kind: 'Graph' | 'Edge' | 'Node';
155
- }
156
- /**
157
- * CommentKind is an enum type that describes a type of comment.
158
- *
159
- * @group AST
160
- */
161
- type CommentKind = 'Block' | 'Slash' | 'Macro';
162
- /**
163
- * @group AST
164
- */
165
- interface CommentASTPropaties extends ASTCommonPropaties {
166
- /**
167
- * A string that specifies the kind of comment.
168
- */
169
- kind: CommentKind;
170
- /**
171
- * A string that contains the actual content of the comment.
172
- */
173
- value: string;
174
- }
175
- /**
176
- * ASTBaseNode is an interface that serves as the base for all AST nodes.
177
- * It requires all leaf interfaces to specify a type property,
178
- * which is of type {@link ASTType}.
179
- *
180
- * @group AST
181
- */
182
- interface ASTBaseNode {
183
- /**
184
- * Every leaf interface that extends ASTBaseNode
185
- * must specify a type property.
186
- */
187
- type: ASTType;
188
- }
189
- /**
190
- * ASTBaseParentNode represents a parent node that has some child nodes.
191
- *
192
- * @template STMT The type of {@link ASTBaseNode} to be stored in the children array.
193
- * @group AST
194
- */
195
- interface ASTBaseParentNode<STMT extends ASTBaseNode = ASTBaseNode> extends ASTBaseNode {
196
- children: STMT[];
197
- }
198
- /**
199
- * LiteralASTNode is a type of AST node that represents a literal value.
200
- *
201
- * @group AST
202
- */
203
- interface LiteralASTNode<T extends string = string> extends ASTBaseParentNode<never>, LiteralASTPropaties<T> {
204
- type: 'Literal';
205
- }
206
- /**
207
- * DotASTNode is a type of AST node that represents a dot in a graph.
208
- *
209
- * @group AST
210
- */
211
- interface DotASTNode extends ASTBaseParentNode<StatementASTNode>, DotASTPropaties {
212
- type: 'Dot';
213
- }
214
- /**
215
- * GraphASTNode is a type of AST node that represents a graph.
216
- *
217
- * @group AST
218
- */
219
- interface GraphASTNode extends ASTBaseParentNode<ClusterStatementASTNode>, GraphASTPropaties {
220
- type: 'Graph';
221
- }
222
- /**
223
- * AttributeASTNode is a type of AST node that represents an attribute.
224
- * @group AST
225
- */
226
- interface AttributeASTNode<T extends AttributeKey = AttributeKey>
227
- extends ASTBaseParentNode<never>,
228
- AttributeASTPropaties<T> {
229
- type: 'Attribute';
230
- }
231
- /**
232
- * CommentASTNode is a type of AST node that represents a comment.
233
- * @group AST
234
- */
235
- interface CommentASTNode extends ASTBaseParentNode<never>, CommentASTPropaties {
236
- type: 'Comment';
237
- }
238
- /**
239
- * AttributeListASTNode is a type of AST node that represents a list of attributes.
240
- * @group AST
241
- */
242
- interface AttributeListASTNode extends ASTBaseParentNode<AttributeASTNode | CommentASTNode>, AttributeListASTPropaties {
243
- type: 'AttributeList';
244
- }
245
- /**
246
- * NodeRefASTNode is a type of AST node that represents a reference to a node.
247
- * @group AST
248
- */
249
- interface NodeRefASTNode extends ASTBaseParentNode<never>, NodeRefASTPropaties {
250
- type: 'NodeRef';
251
- }
252
- /**
253
- * NodeRefGroupASTNode is a type of AST node that represents a group of nodes referenced together.
254
- * @group AST
255
- */
256
- interface NodeRefGroupASTNode extends ASTBaseParentNode<NodeRefASTNode>, NodeRefGroupASTPropaties {
257
- type: 'NodeRefGroup';
258
- }
259
- /**
260
- * This type is used to represent a target of an edge in an AST (Abstract Syntax Tree).
261
- *
262
- * @group AST
263
- */
264
- type EdgeTargetASTNode = NodeRefASTNode | NodeRefGroupASTNode;
265
- /**
266
- * EdgeASTNode is a type of AST node that represents an edge in a graph.
267
- * @group AST
268
- */
269
- interface EdgeASTNode extends ASTBaseParentNode<AttributeASTNode | CommentASTNode>, EdgeASTPropaties {
270
- type: 'Edge';
271
- }
272
- /**
273
- * NodeASTNode is a type of AST node that represents a node in a graph.
274
- * @group AST
275
- */
276
- interface NodeASTNode extends ASTBaseParentNode<AttributeASTNode | CommentASTNode>, NodeASTPropaties {
277
- type: 'Node';
278
- }
279
- /**
280
- * SubgraphASTNode is a type of AST node that represents a subgraph.
281
- * @group AST
282
- */
283
- interface SubgraphASTNode extends ASTBaseParentNode<ClusterStatementASTNode>, SubgraphASTPropaties {
284
- type: 'Subgraph';
285
- }
286
- /**
287
- * @group AST
288
- */
289
- type StatementASTNode = GraphASTNode | CommentASTNode;
290
- /**
291
- * ClusterStatementASTNode is a type used to represent a statement in a cluster graph.
292
- * @group AST
293
- */
294
- type ClusterStatementASTNode =
295
- | AttributeASTNode
296
- | AttributeListASTNode
297
- | EdgeASTNode
298
- | NodeASTNode
299
- | SubgraphASTNode
300
- | CommentASTNode;
301
- /**
302
- * ASTNode is a type used to define a set of different types of AST nodes that can be used in a graph.
303
- *
304
- * @group AST
305
- */
306
- type ASTNode =
307
- | LiteralASTNode
308
- | DotASTNode
309
- | GraphASTNode
310
- | AttributeASTNode
311
- | CommentASTNode
312
- | AttributeListASTNode
313
- | NodeRefASTNode
314
- | NodeRefGroupASTNode
315
- | EdgeASTNode
316
- | NodeASTNode
317
- | SubgraphASTNode;
318
- /**
319
- * ASTChildNode is a type alias used to represent the child nodes of a given {@link ASTBaseParentNode}.
320
- * @group AST
321
- */
322
- type ASTChildNode<T> = T extends ASTBaseParentNode<infer C> ? C : never;
323
-
324
- /**
325
- * This interface is used to define the options for the builder.
326
- *
327
- * @group Create AST
328
- * @alpha
329
- */
330
- interface BuilderOptions {
331
- /**
332
- * This is a function that returns a {@link FileRange} object.
333
- * It is used to specify the location of the builder.
334
- */
335
- locationFunction: () => FileRange$1;
336
- }
337
- /**
338
- * This interface provides a method for creating an Abstract Syntax Tree (AST) for a given type.
339
- * @group Create AST
340
- * @alpha
341
- */
342
- interface CreateElement {
343
- /**
344
- * Creates a LiteralASTNode with the given type, properties, and children.
345
- *
346
- * @param type The type of the AST node.
347
- * @param props The properties of the AST node.
348
- * @param children The children of the AST node.
349
- * @returns A {@link LiteralASTNode} with the given type, properties, and children.
350
- */
351
- <T extends string>(
352
- type: 'Literal',
353
- props: LiteralASTPropaties<T>,
354
- children?: ASTChildNode<LiteralASTNode>[],
355
- ): LiteralASTNode<T>;
356
- /**
357
- * Creates a LiteralASTNode with the given type, properties, and children.
358
- *
359
- * @param type The type of the AST node.
360
- * @param props The properties of the AST node.
361
- * @param children The children of the AST node.
362
- * @returns A {@link LiteralASTNode} with the given type, properties, and children.
363
- */
364
- (type: 'Literal', props: LiteralASTPropaties, children?: ASTChildNode<LiteralASTNode>[]): LiteralASTNode;
365
- /**
366
- * Creates a {@link DotASTNode} with the given type, properties, and children.
367
- *
368
- * @param type The type of the AST node.
369
- * @param props The properties of the AST node.
370
- * @param children The children of the AST node.
371
- * @returns A {@link DotASTNode} with the given type, properties, and children.
372
- */
373
- (type: 'Dot', props: DotASTPropaties, children?: ASTChildNode<DotASTNode>[]): DotASTNode;
374
- /**
375
- * Creates a {@link GraphASTNode} with the given type, properties, and children.
376
- *
377
- * @param type The type of the AST node.
378
- * @param props The properties of the AST node.
379
- * @param children The children of the AST node.
380
- * @returns A {GraphASTNode} with the given type, properties, and children.
381
- */
382
- (type: 'Graph', props: GraphASTPropaties, children?: ASTChildNode<GraphASTNode>[]): GraphASTNode;
383
- /**
384
- * Creates an {@link AttributeASTNode} with the given type, properties, and children.
385
- *
386
- * @param type The type of the AST node.
387
- * @param props The properties of the AST node.
388
- * @param children The children of the AST node.
389
- * @returns An {@link AttributeASTNode} with the given type, properties, and children.
390
- */
391
- <T extends AttributeKey>(
392
- type: 'Attribute',
393
- props: AttributeASTPropaties<T>,
394
- children?: ASTChildNode<AttributeASTNode>[],
395
- ): AttributeASTNode<T>;
396
- (type: 'Attribute', props: AttributeASTPropaties, children?: ASTChildNode<AttributeASTNode>[]): AttributeASTNode;
397
- /**
398
- * Creates a {@link CommentASTNode} with the given type, properties, and children.
399
- *
400
- * @param type The type of the AST node.
401
- * @param props The properties of the AST node.
402
- * @param children The children of the AST node.
403
- * @returns A {@link CommentASTNode} with the given type, properties, and children.
404
- */
405
- (type: 'Comment', props: CommentASTPropaties, children?: ASTChildNode<CommentASTNode>[]): CommentASTNode;
406
- /**
407
- * Creates an {@link AttributeListASTNode} with the given type, properties, and children.
408
- *
409
- * @param type The type of the AST node.
410
- * @param props The properties of the AST node.
411
- * @param children The children of the AST node.
412
- * @returns An {@link AttributeListASTNode} with the given type, properties, and children.
413
- */
414
- (
415
- type: 'AttributeList',
416
- props: AttributeListASTPropaties,
417
- children?: ASTChildNode<AttributeListASTNode>[],
418
- ): AttributeListASTNode;
419
- /**
420
- * Creates a {@link NodeRefASTNode} with the given type, properties, and children.
421
- *
422
- * @param type The type of the AST node.
423
- * @param props The properties of the AST node.
424
- * @param children The children of the AST node.
425
- * @returns A {@link NodeRefASTNode} with the given type, properties, and children.
426
- */
427
- (type: 'NodeRef', props: NodeRefASTPropaties, children?: ASTChildNode<NodeRefASTNode>[]): NodeRefASTNode;
428
- /**
429
- * Creates a {@link NodeRefGroupASTNode} with the given type, properties, and children.
430
- *
431
- * @param type The type of the AST node.
432
- * @param props The properties of the AST node.
433
- * @param children The children of the AST node.
434
- * @returns A {@link NodeRefGroupASTNode} with the given type, properties, and children.
435
- */
436
- (
437
- type: 'NodeRefGroup',
438
- props: NodeRefGroupASTPropaties,
439
- children?: ASTChildNode<NodeRefGroupASTNode>[],
440
- ): NodeRefGroupASTNode;
441
- /**
442
- * Creates an {@link EdgeASTNode} with the given type, properties, and children.
443
- *
444
- * @param type The type of the AST node.
445
- * @param props The properties of the AST node.
446
- * @param children The children of the AST node.
447
- * @returns An {@link EdgeASTNode} with the given type, properties, and children.
448
- */
449
- (type: 'Edge', props: EdgeASTPropaties, children?: ASTChildNode<EdgeASTNode>[]): EdgeASTNode;
450
- /**
451
- * Creates a {@link NodeASTNode} with the given type, properties, and children.
452
- *
453
- * @param type The type of the AST node.
454
- * @param props The properties of the AST node.
455
- * @param children The children of the AST node.
456
- * @returns A {@link NodeASTNode} with the given type, properties, and children.
457
- */
458
- (type: 'Node', props: NodeASTPropaties, children?: ASTChildNode<NodeASTNode>[]): NodeASTNode;
459
- /**
460
- * Creates a {@link SubgraphASTNode} with the given type, properties, and children.
461
- *
462
- * @param type The type of the AST node.
463
- * @param props The properties of the AST node.
464
- * @param children The children of the AST node.
465
- * @returns A {@link SubgraphASTNode} with the given type, properties, and children.
466
- */
467
- (type: 'Subgraph', props: SubgraphASTPropaties, children?: ASTChildNode<SubgraphASTNode>[]): SubgraphASTNode;
468
- }
469
- /**
470
- * This interface provides an ASTBuilder object with a createElement function.
471
- * @group Create AST
472
- * @alpha
473
- */
474
- interface ASTBuilder {
475
- createElement: CreateElement;
476
- }
477
-
478
- /**
479
- * Builder is an ASTBuilder that provides a method to create an ASTNode.
480
- *
481
- * @group Create AST
482
- */
483
- declare class Builder implements ASTBuilder {
484
- private options?;
485
- /**
486
- * Get the current file range or null
487
- * @internal
488
- */
489
- private getLocation;
490
- /**
491
- * Constructor of Builder
492
- * @param options - Options to initialize Builder
493
- */
494
- constructor(options?: Partial<BuilderOptions> | undefined);
495
- /**
496
- * Create an {@link ASTNode} of the specified type
497
- *
498
- * @param type - Type of the {@link ASTNode}
499
- * @param props - Properties of the {@link ASTNode}
500
- * @param children - Children of the {@link ASTNode}
501
- * @returns An {@link ASTNode}
502
- */
503
- createElement<T extends ASTNode>(type: T['type'], props: any, children?: ASTChildNode<T>[]): T;
504
- }
505
-
506
- /**
507
- * Create an {@link ASTNode} of the specified type
508
- *
509
- * @param type - Type of the {@link ASTNode}
510
- * @param props - Properties of the {@link ASTNode}
511
- * @param children - Children of the {@link ASTNode}
512
- * @group Create AST
513
- * @returns An {@link ASTNode}
514
- */
515
- declare const createElement: CreateElement;
516
-
517
- /**
518
- * The IndentStyle type represents an indentation style for text. It can either be a `"space"` or a `"tab"`.
519
- * @group Convert AST to DOT
520
- */
521
- type IndentStyle = 'space' | 'tab';
522
- /**
523
- * This type represents the EndOfLine type which is used to determine the type of line ending to be used when writing to a file.
524
- * @group Convert AST to DOT
525
- */
526
- type EndOfLine = 'lf' | 'crlf';
527
- /**
528
- * This interface provides options for converting an abstract syntax tree (AST) to a DOT representation.
529
- * @group Convert AST to DOT
530
- * @alpha
531
- */
532
- interface PrintOptions {
533
- /**
534
- * The style of indentation to use when printing the AST.
535
- *
536
- * @default "space"
537
- */
538
- indentStyle?: IndentStyle;
539
- /**
540
- * The size of the indentation to use when printing the AST.
541
- *
542
- * @default 2
543
- */
544
- indentSize?: number;
545
- /**
546
- * The type of line ending to use when printing the AST.
547
- *
548
- * @default lf
549
- */
550
- endOfLine?: EndOfLine;
551
- }
552
- /**
553
- * PrintContext interface provides an interface for printing an ASTNode with a set of options.
554
- * @group Convert AST to DOT
555
- * @alpha
556
- */
557
- interface PrintContext extends Required<PrintOptions> {
558
- /**
559
- * Indicates if the AST should be printed in a directed graph.
560
- */
561
- directed: boolean;
562
- /**
563
- * A function to print an ASTNode, taking in an ASTNode as an argument. Returns a string.
564
- */
565
- print(ast: ASTNode): string;
566
- }
567
- /**
568
- * PrintPlugin is an interface for plugins used for printing an {@link ASTNode}.
569
- * @template T T extends {@link ASTNode}
570
- * @group Convert AST to DOT
571
- * @alpha
572
- */
573
- interface PrintPlugin<T extends ASTNode = ASTNode> {
574
- /**
575
- * Checks if an ASTNode matches the plugin
576
- * @returns {boolean} true if the ASTNode matches the plugin
577
- */
578
- match(ast: ASTNode): boolean;
579
- /**
580
- * Prints an ASTNode
581
- * @param context PrintContext object
582
- * @param ast an ASTNode
583
- * @returns printed string
584
- * @memberof PrintPlugin
585
- */
586
- print(context: PrintContext, ast: T): string;
587
- }
588
-
589
- /**
590
- * Printer is a class responsible for converting an AST into a DOT string.
591
- * @group Convert AST to DOT
592
- */
593
- declare class Printer {
594
- #private;
595
- private options;
596
- /**
597
- * @param options Options to be used when generating the DOT string.
598
- */
599
- constructor(options?: PrintOptions);
600
- /**
601
- * Generates a DOT string from an ASTNode.
602
- * @param ast The ASTNode to be converted into a DOT string.
603
- * @returns The DOT string generated from the ASTNode.
604
- */
605
- print(ast: ASTNode): string;
606
- }
607
-
608
- /**
609
- * stringify is a function that converts a Graphviz AST Node into a string in DOT language.
610
- *
611
- * @param ast Graphviz AST node that is to be converted.
612
- * @param options PrintOptions object containing formatting options.
613
- * @returns A string in DOT language.
614
- * @group Convert AST to DOT
615
- */
616
- declare function stringify(ast: ASTNode, options?: PrintOptions): string;
617
-
618
- interface FilePosition {
619
- offset: number;
620
- line: number;
621
- column: number;
622
- }
623
- interface FileRange {
624
- start: FilePosition;
625
- end: FilePosition;
626
- source: string;
627
- }
628
- interface LiteralExpectation {
629
- type: 'literal';
630
- text: string;
631
- ignoreCase: boolean;
632
- }
633
- interface ClassParts extends Array<string | ClassParts> {}
634
- interface ClassExpectation {
635
- type: 'class';
636
- parts: ClassParts;
637
- inverted: boolean;
638
- ignoreCase: boolean;
639
- }
640
- interface AnyExpectation {
641
- type: 'any';
642
- }
643
- interface EndExpectation {
644
- type: 'end';
645
- }
646
- interface OtherExpectation {
647
- type: 'other';
648
- description: string;
649
- }
650
- type Expectation = LiteralExpectation | ClassExpectation | AnyExpectation | EndExpectation | OtherExpectation;
651
- declare class DotSyntaxError$1 extends Error {
652
- static buildMessage(expected: Expectation[], found: string | null): string;
653
- message: string;
654
- expected: Expectation[];
655
- found: string | null;
656
- location: FileRange;
657
- name: string;
658
- constructor(message: string, expected: Expectation[], found: string | null, location: FileRange);
659
- format(
660
- sources: {
661
- grammarSource?: string;
662
- text: string;
663
- }[],
664
- ): string;
665
- }
666
-
667
- /**
668
- * @group Convert DOT to AST
669
- */
670
- type Rule = 'Dot' | 'Graph' | 'Node' | 'Edge' | 'AttributeList' | 'Attribute' | 'Subgraph' | 'ClusterStatements';
671
- /**
672
- * CommonParseOptions is an interface that defines the properties needed in order to parse a file.
673
- * @group Convert DOT to AST
674
- */
675
- interface CommonParseOptions {
676
- /**
677
- * filename (optional): A string value that is used to identify the file to be parsed.
678
- */
679
- filename?: string;
680
- }
681
- /**
682
- * ParseOptions interface is used to provide additional information to the parser while parsing a rule.
683
- * @template T The type of the rule to be parsed.
684
- * @group Convert DOT to AST
685
- */
686
- interface ParseOptions<T extends Rule> extends CommonParseOptions {
687
- startRule?: T;
688
- }
689
- /**
690
- * parse is a function that takes a string input and optional parse options and
691
- * returns an ASTNode or an array of ClusterStatementASTNodes.
692
- *
693
- * Depending on the type of parse option specified, the function will return different types of ASTNodes.
694
- *
695
- * The types of ASTNodes that can be returned are:
696
- *
697
- * - {@link DotASTNode}
698
- * - {@link GraphASTNode}
699
- * - {@link NodeASTNode}
700
- * - {@link EdgeASTNode}
701
- * - {@link AttributeListASTNode}
702
- * - {@link AttributeASTNode}
703
- * - {@link SubgraphASTNode}
704
- * - {@link ClusterStatementASTNode}
705
- *
706
- * @throws {@link SyntaxError}
707
- * @group Convert DOT to AST
708
- */
709
- declare function parse(input: string): DotASTNode;
710
- declare function parse(input: string, options?: ParseOptions<'Dot'>): DotASTNode;
711
- declare function parse(input: string, options?: ParseOptions<'Graph'>): GraphASTNode;
712
- declare function parse(input: string, options?: ParseOptions<'Node'>): NodeASTNode;
713
- declare function parse(input: string, options?: ParseOptions<'Edge'>): EdgeASTNode;
714
- declare function parse(input: string, options?: ParseOptions<'AttributeList'>): AttributeListASTNode;
715
- declare function parse(input: string, options?: ParseOptions<'Attribute'>): AttributeASTNode;
716
- declare function parse(input: string, options?: ParseOptions<'Subgraph'>): SubgraphASTNode;
717
- declare function parse(input: string, options?: ParseOptions<'ClusterStatements'>): ClusterStatementASTNode[];
718
- declare function parse(input: string, options?: ParseOptions<Rule>): ASTNode | ClusterStatementASTNode[];
719
- /**
720
- * @group Convert DOT to AST
721
- */
722
- declare const DotSyntaxError: typeof DotSyntaxError$1;
723
-
724
- /**
725
- * ModelToAST is a type alias used to map a generic type T to a specific AST node type.
726
- *
727
- * If T is a DotObjectModel, the type U is inferred and used to determine which AST node type to map to.
728
- *
729
- * If U is 'Graph', the type is mapped to either a {@link GraphASTNode} or a {@link DotASTNode}.
730
- * If U is 'AttributeList', the type is mapped to an {@link AttributeListASTNode}.
731
- * If U is 'Edge', the type is mapped to an {@link EdgeASTNode}.
732
- * If U is 'Node', the type is mapped to a {@link NodeASTNode}.
733
- * If U is 'Subgraph', the type is mapped to a {@link SubgraphASTNode}.
734
- *
735
- * If T is not a DotObjectModel, the type is mapped to never.
736
- *
737
- * @group AST
738
- */
739
- type ModelToAST<T> = T extends DotObjectModel<infer U>
740
- ? U extends 'Graph'
741
- ? GraphASTNode | DotASTNode
742
- : U extends 'AttributeList'
743
- ? AttributeListASTNode
744
- : U extends 'Edge'
745
- ? EdgeASTNode
746
- : U extends 'Node'
747
- ? NodeASTNode
748
- : U extends 'Subgraph'
749
- ? SubgraphASTNode
750
- : never
751
- : never;
752
- /**
753
- * @group Convert Model to AST
754
- * @alpha
755
- */
756
- interface ConvertFromModelOptions {
757
- commentKind?: CommentKind;
758
- }
759
- /**
760
- * @group Convert Model to AST
761
- * @alpha
762
- */
763
- interface ConvertFromModelContext extends Required<ConvertFromModelOptions> {
764
- convert<T extends DotObjectModel>(model: T): ModelToAST<T>;
765
- }
766
- /**
767
- * @group Convert Model to AST
768
- * @alpha
769
- */
770
- interface ConvertFromModelPlugin<T extends DotObjectModel> {
771
- match(model: T): boolean;
772
- convert(context: ConvertFromModelContext, model: T): ModelToAST<T>;
773
- }
774
-
775
- /**
776
- * FromModelConverter is a class used to convert a {@link DotObjectModel} into an ASTNode.
777
- *
778
- * @group Convert Model to AST
779
- */
780
- declare class FromModelConverter {
781
- #private;
782
- private options;
783
- constructor(options?: ConvertFromModelOptions);
784
- /**
785
- * Converts a DotObjectModel into an AST.
786
- *
787
- * @param model The {@link DotObjectModel} to be converted.
788
- * @returns The AST generated from the model.
789
- */
790
- convert<T extends DotObjectModel>(model: T): ModelToAST<T>;
791
- }
792
-
793
- /**
794
- * A function used to convert a DotObjectModel into an AST.
795
- *
796
- * @param model - The {@link DotObjectModel} to be converted.
797
- * @param options - An optional {@link ConvertFromModelOptions} object.
798
- * @returns ModelToAST - The AST representation of the {@link DotObjectModel}.
799
- *
800
- * @group Convert Model to AST
801
- */
802
- declare function fromModel<T extends DotObjectModel>(model: T, options?: ConvertFromModelOptions): ModelToAST<T>;
803
-
804
- /**
805
- * ModelOf is a type that determines the type of model to use depending on the value of T.
806
- * @group AST
807
- */
808
- type ModelOf<T> = T extends 'Dot' | 'Graph'
809
- ? RootGraphModel
810
- : T extends 'Edge'
811
- ? EdgeModel
812
- : T extends 'Node'
813
- ? NodeModel
814
- : T extends 'Subgraph'
815
- ? SubgraphModel
816
- : never;
817
- /**
818
- * ASTToModel is a type that determines a model type from an AST.
819
- *
820
- * @group AST
821
- */
822
- type ASTToModel<T> = T extends {
823
- type: infer U;
824
- }
825
- ? ModelOf<U>
826
- : never;
827
- /**
828
- * This type is used to define what AST nodes can be converted to a model.
829
- * @group Convert AST to Model
830
- * @beta
831
- */
832
- type ToModelConvertableASTNode = DotASTNode | GraphASTNode | SubgraphASTNode | NodeASTNode | EdgeASTNode;
833
- /**
834
- * @group Convert AST to Model
835
- * @alpha
836
- */
837
- interface ConvertToModelOptions {
838
- models?: Partial<ModelsContext>;
839
- }
840
- /**
841
- * @group Convert AST to Model
842
- * @alpha
843
- */
844
- interface ConvertToModelContext {
845
- models: ModelsContext;
846
- convert<T extends ToModelConvertableASTNode>(ast: T): ASTToModel<T>;
847
- }
848
- /**
849
- * @group Convert AST to Model
850
- * @alpha
851
- */
852
- interface ConvertToModelPlugin<T extends ToModelConvertableASTNode = ToModelConvertableASTNode> {
853
- match(ast: T): boolean;
854
- convert(context: ConvertToModelContext, ast: T): ASTToModel<T>;
855
- }
856
-
857
- /**
858
- * @group Convert AST to Model
859
- * @alpha
860
- */
861
- declare class ToModelConverter {
862
- private options;
863
- /** @hidden */
864
- protected plugins: ConvertToModelPlugin<ToModelConvertableASTNode>[];
865
- constructor(options?: ConvertToModelOptions);
866
- /**
867
- * Convert AST to Model.
868
- *
869
- * @param ast AST node.
870
- * @alpha
871
- */
872
- convert<T extends ToModelConvertableASTNode>(ast: T): ASTToModel<T>;
873
- }
874
-
875
- /**
876
- * @group Convert AST to Model
877
- * @beta
878
- */
879
- declare function toModel<T extends ToModelConvertableASTNode>(ast: T, options?: ConvertToModelOptions): ASTToModel<T>;
880
-
881
- export {
882
- ASTBaseNode,
883
- ASTBaseParentNode,
884
- ASTBuilder,
885
- ASTChildNode,
886
- ASTCommonPropaties,
887
- ASTNode,
888
- ASTToModel,
889
- AttributeASTNode,
890
- AttributeASTPropaties,
891
- AttributeListASTNode,
892
- AttributeListASTPropaties,
893
- Builder,
894
- BuilderOptions,
895
- ClusterStatementASTNode,
896
- CommentASTNode,
897
- CommentASTPropaties,
898
- CommentKind,
899
- CommonParseOptions,
900
- ConvertFromModelContext,
901
- ConvertFromModelOptions,
902
- ConvertFromModelPlugin,
903
- ConvertToModelContext,
904
- ConvertToModelOptions,
905
- ConvertToModelPlugin,
906
- CreateElement,
907
- DotASTNode,
908
- DotASTPropaties,
909
- DotSyntaxError,
910
- EdgeASTNode,
911
- EdgeASTPropaties,
912
- EdgeTargetASTNode,
913
- EndOfLine,
914
- FilePosition$1 as FilePosition,
915
- FileRange$1 as FileRange,
916
- FromModelConverter,
917
- GraphASTNode,
918
- GraphASTPropaties,
919
- IndentStyle,
920
- LiteralASTNode,
921
- LiteralASTPropaties,
922
- ModelOf,
923
- ModelToAST,
924
- NodeASTNode,
925
- NodeASTPropaties,
926
- NodeRefASTNode,
927
- NodeRefASTPropaties,
928
- NodeRefGroupASTNode,
929
- NodeRefGroupASTPropaties,
930
- ParseOptions,
931
- PrintContext,
932
- PrintOptions,
933
- PrintPlugin,
934
- Printer,
935
- Rule,
936
- StatementASTNode,
937
- SubgraphASTNode,
938
- SubgraphASTPropaties,
939
- ToModelConvertableASTNode,
940
- ToModelConverter,
941
- createElement,
942
- fromModel,
943
- parse,
944
- stringify,
945
- toModel,
946
- };