@statelyai/graph 0.3.0 → 0.4.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 (41) hide show
  1. package/README.md +12 -11
  2. package/dist/{adjacency-list-A4_Eiwj3.mjs → adjacency-list-Bv4tfiM3.mjs} +33 -0
  3. package/dist/{algorithms-DBU7nmIV.mjs → algorithms-CnTmuX9t.mjs} +682 -24
  4. package/dist/algorithms.d.mts +479 -10
  5. package/dist/algorithms.mjs +1 -1
  6. package/dist/converter-C5DlzzHs.mjs +67 -0
  7. package/dist/{edge-list-DuHMz8hf.mjs → edge-list-R1SUbHwe.mjs} +32 -0
  8. package/dist/formats/adjacency-list/index.d.mts +35 -1
  9. package/dist/formats/adjacency-list/index.mjs +1 -1
  10. package/dist/formats/converter/index.d.mts +37 -3
  11. package/dist/formats/converter/index.mjs +1 -1
  12. package/dist/formats/cytoscape/index.d.mts +50 -2
  13. package/dist/formats/cytoscape/index.mjs +53 -5
  14. package/dist/formats/d3/index.d.mts +48 -2
  15. package/dist/formats/d3/index.mjs +48 -2
  16. package/dist/formats/dot/index.d.mts +56 -2
  17. package/dist/formats/dot/index.mjs +55 -2
  18. package/dist/formats/edge-list/index.d.mts +34 -1
  19. package/dist/formats/edge-list/index.mjs +1 -1
  20. package/dist/formats/gexf/index.d.mts +1 -1
  21. package/dist/formats/gexf/index.mjs +5 -5
  22. package/dist/formats/gml/index.d.mts +58 -2
  23. package/dist/formats/gml/index.mjs +59 -4
  24. package/dist/formats/graphml/index.d.mts +1 -1
  25. package/dist/formats/graphml/index.mjs +2 -2
  26. package/dist/formats/jgf/index.d.mts +51 -2
  27. package/dist/formats/jgf/index.mjs +54 -5
  28. package/dist/formats/mermaid/index.d.mts +201 -8
  29. package/dist/formats/mermaid/index.mjs +365 -26
  30. package/dist/formats/tgf/index.d.mts +47 -2
  31. package/dist/formats/tgf/index.mjs +46 -2
  32. package/dist/formats/xyflow/index.d.mts +73 -0
  33. package/dist/formats/xyflow/index.mjs +133 -0
  34. package/dist/index.d.mts +320 -14
  35. package/dist/index.mjs +117 -9
  36. package/dist/{indexing-BFFVMnjF.mjs → indexing-DitHphT7.mjs} +37 -7
  37. package/dist/queries.d.mts +353 -8
  38. package/dist/queries.mjs +359 -15
  39. package/dist/{types-B6Tpeerk.d.mts → types-Bq_fmLwW.d.mts} +15 -4
  40. package/package.json +3 -1
  41. package/dist/converter-DnbeyE_p.mjs +0 -33
@@ -1,9 +1,65 @@
1
- import { c as Graph, f as GraphFormatConverter } from "../../types-B6Tpeerk.mjs";
1
+ import { c as Graph, f as GraphFormatConverter } from "../../types-Bq_fmLwW.mjs";
2
2
 
3
3
  //#region src/formats/gml/index.d.ts
4
+
5
+ /**
6
+ * Converts a graph to GML (Graph Modelling Language) string.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { createGraph } from '@statelyai/graph';
11
+ * import { toGML } from '@statelyai/graph/formats/gml';
12
+ *
13
+ * const graph = createGraph({
14
+ * nodes: [{ id: 'a' }, { id: 'b' }],
15
+ * edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
16
+ * });
17
+ *
18
+ * const gml = toGML(graph);
19
+ * // graph [
20
+ * // directed 1
21
+ * // node [ id "a" ]
22
+ * // node [ id "b" ]
23
+ * // edge [ id "e0" source "a" target "b" ]
24
+ * // ]
25
+ * ```
26
+ */
4
27
  declare function toGML(graph: Graph): string;
28
+ /**
29
+ * Parses a GML (Graph Modelling Language) string into a graph.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { fromGML } from '@statelyai/graph/formats/gml';
34
+ *
35
+ * const graph = fromGML(`
36
+ * graph [
37
+ * directed 1
38
+ * node [ id "a" ]
39
+ * node [ id "b" ]
40
+ * edge [ source "a" target "b" ]
41
+ * ]
42
+ * `);
43
+ * ```
44
+ */
5
45
  declare function fromGML(gml: string): Graph;
6
- /** Bidirectional converter for GML (Graph Modelling Language) format. */
46
+ /**
47
+ * Bidirectional converter for GML (Graph Modelling Language) format.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { createGraph } from '@statelyai/graph';
52
+ * import { gmlConverter } from '@statelyai/graph/formats/gml';
53
+ *
54
+ * const graph = createGraph({
55
+ * nodes: [{ id: 'a' }, { id: 'b' }],
56
+ * edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
57
+ * });
58
+ *
59
+ * const gml = gmlConverter.to(graph);
60
+ * const roundTripped = gmlConverter.from(gml);
61
+ * ```
62
+ */
7
63
  declare const gmlConverter: GraphFormatConverter<string>;
8
64
  //#endregion
9
65
  export { fromGML, gmlConverter, toGML };
@@ -1,6 +1,28 @@
1
- import { n as createFormatConverter } from "../../converter-DnbeyE_p.mjs";
1
+ import { n as createFormatConverter } from "../../converter-C5DlzzHs.mjs";
2
2
 
3
3
  //#region src/formats/gml/index.ts
4
+ /**
5
+ * Converts a graph to GML (Graph Modelling Language) string.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { createGraph } from '@statelyai/graph';
10
+ * import { toGML } from '@statelyai/graph/formats/gml';
11
+ *
12
+ * const graph = createGraph({
13
+ * nodes: [{ id: 'a' }, { id: 'b' }],
14
+ * edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
15
+ * });
16
+ *
17
+ * const gml = toGML(graph);
18
+ * // graph [
19
+ * // directed 1
20
+ * // node [ id "a" ]
21
+ * // node [ id "b" ]
22
+ * // edge [ id "e0" source "a" target "b" ]
23
+ * // ]
24
+ * ```
25
+ */
4
26
  function toGML(graph) {
5
27
  const lines = [];
6
28
  lines.push("graph [");
@@ -8,7 +30,7 @@ function toGML(graph) {
8
30
  if (graph.id) lines.push(` id ${gmlString(graph.id)}`);
9
31
  const childrenMap = /* @__PURE__ */ new Map();
10
32
  for (const node of graph.nodes) {
11
- const pid = node.parentId;
33
+ const pid = node.parentId ?? null;
12
34
  if (!childrenMap.has(pid)) childrenMap.set(pid, []);
13
35
  childrenMap.get(pid).push(node);
14
36
  }
@@ -16,7 +38,7 @@ function toGML(graph) {
16
38
  lines.push(`${indent}node [`);
17
39
  lines.push(`${indent} id ${gmlString(node.id)}`);
18
40
  if (node.label) lines.push(`${indent} label ${gmlString(node.label)}`);
19
- if (node.initialNodeId !== null) lines.push(`${indent} initialNodeId ${gmlString(node.initialNodeId)}`);
41
+ if (node.initialNodeId) lines.push(`${indent} initialNodeId ${gmlString(node.initialNodeId)}`);
20
42
  if (node.data !== void 0) lines.push(`${indent} data ${gmlString(JSON.stringify(node.data))}`);
21
43
  if (node.shape) lines.push(`${indent} shape ${gmlString(node.shape)}`);
22
44
  if (node.color) lines.push(`${indent} color ${gmlString(node.color)}`);
@@ -50,6 +72,23 @@ function toGML(graph) {
50
72
  function gmlString(s) {
51
73
  return `"${s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
52
74
  }
75
+ /**
76
+ * Parses a GML (Graph Modelling Language) string into a graph.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * import { fromGML } from '@statelyai/graph/formats/gml';
81
+ *
82
+ * const graph = fromGML(`
83
+ * graph [
84
+ * directed 1
85
+ * node [ id "a" ]
86
+ * node [ id "b" ]
87
+ * edge [ source "a" target "b" ]
88
+ * ]
89
+ * `);
90
+ * ```
91
+ */
53
92
  function fromGML(gml) {
54
93
  if (typeof gml !== "string") throw new Error("GML: expected a string");
55
94
  if (!gml.trim()) throw new Error("GML: input is empty");
@@ -229,7 +268,23 @@ function tryParseJSON(str) {
229
268
  return str;
230
269
  }
231
270
  }
232
- /** Bidirectional converter for GML (Graph Modelling Language) format. */
271
+ /**
272
+ * Bidirectional converter for GML (Graph Modelling Language) format.
273
+ *
274
+ * @example
275
+ * ```ts
276
+ * import { createGraph } from '@statelyai/graph';
277
+ * import { gmlConverter } from '@statelyai/graph/formats/gml';
278
+ *
279
+ * const graph = createGraph({
280
+ * nodes: [{ id: 'a' }, { id: 'b' }],
281
+ * edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
282
+ * });
283
+ *
284
+ * const gml = gmlConverter.to(graph);
285
+ * const roundTripped = gmlConverter.from(gml);
286
+ * ```
287
+ */
233
288
  const gmlConverter = createFormatConverter(toGML, fromGML);
234
289
 
235
290
  //#endregion
@@ -1,4 +1,4 @@
1
- import { c as Graph, f as GraphFormatConverter } from "../../types-B6Tpeerk.mjs";
1
+ import { c as Graph, f as GraphFormatConverter } from "../../types-Bq_fmLwW.mjs";
2
2
 
3
3
  //#region src/formats/graphml/index.d.ts
4
4
  declare function toGraphML(graph: Graph): string;
@@ -1,4 +1,4 @@
1
- import { n as createFormatConverter } from "../../converter-DnbeyE_p.mjs";
1
+ import { n as createFormatConverter } from "../../converter-C5DlzzHs.mjs";
2
2
  import { XMLBuilder, XMLParser } from "fast-xml-parser";
3
3
 
4
4
  //#region src/formats/graphml/index.ts
@@ -72,7 +72,7 @@ function toGraphML(graph) {
72
72
  "@_key": "label",
73
73
  "#text": n.label
74
74
  });
75
- if (n.parentId !== null) data.push({
75
+ if (n.parentId) data.push({
76
76
  "@_key": "parentId",
77
77
  "#text": n.parentId
78
78
  });
@@ -1,4 +1,4 @@
1
- import { c as Graph, f as GraphFormatConverter } from "../../types-B6Tpeerk.mjs";
1
+ import { c as Graph, f as GraphFormatConverter } from "../../types-Bq_fmLwW.mjs";
2
2
 
3
3
  //#region src/formats/jgf/index.d.ts
4
4
  interface JGFNode {
@@ -22,9 +22,58 @@ interface JGFGraph {
22
22
  edges: JGFEdge[];
23
23
  };
24
24
  }
25
+ /**
26
+ * Converts a graph to JSON Graph Format (JGF).
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { createGraph } from '@statelyai/graph';
31
+ * import { toJGF } from '@statelyai/graph/formats/jgf';
32
+ *
33
+ * const graph = createGraph({
34
+ * nodes: [{ id: 'a' }, { id: 'b' }],
35
+ * edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
36
+ * });
37
+ *
38
+ * const jgf = toJGF(graph);
39
+ * // { graph: { directed: true, nodes: [...], edges: [...] } }
40
+ * ```
41
+ */
25
42
  declare function toJGF(graph: Graph): JGFGraph;
43
+ /**
44
+ * Parses a JSON Graph Format (JGF) object into a graph.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { fromJGF } from '@statelyai/graph/formats/jgf';
49
+ *
50
+ * const graph = fromJGF({
51
+ * graph: {
52
+ * directed: true,
53
+ * nodes: [{ id: 'a' }, { id: 'b' }],
54
+ * edges: [{ source: 'a', target: 'b' }],
55
+ * },
56
+ * });
57
+ * ```
58
+ */
26
59
  declare function fromJGF(jgf: JGFGraph): Graph;
27
- /** Bidirectional converter for JSON Graph Format. */
60
+ /**
61
+ * Bidirectional converter for JSON Graph Format.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import { createGraph } from '@statelyai/graph';
66
+ * import { jgfConverter } from '@statelyai/graph/formats/jgf';
67
+ *
68
+ * const graph = createGraph({
69
+ * nodes: [{ id: 'a' }, { id: 'b' }],
70
+ * edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
71
+ * });
72
+ *
73
+ * const jgf = jgfConverter.to(graph);
74
+ * const roundTripped = jgfConverter.from(jgf);
75
+ * ```
76
+ */
28
77
  declare const jgfConverter: GraphFormatConverter<JGFGraph>;
29
78
  //#endregion
30
79
  export { JGFEdge, JGFGraph, JGFNode, fromJGF, jgfConverter, toJGF };
@@ -1,9 +1,26 @@
1
- import { n as createFormatConverter } from "../../converter-DnbeyE_p.mjs";
1
+ import { n as createFormatConverter } from "../../converter-C5DlzzHs.mjs";
2
2
 
3
3
  //#region src/formats/jgf/index.ts
4
+ /**
5
+ * Converts a graph to JSON Graph Format (JGF).
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { createGraph } from '@statelyai/graph';
10
+ * import { toJGF } from '@statelyai/graph/formats/jgf';
11
+ *
12
+ * const graph = createGraph({
13
+ * nodes: [{ id: 'a' }, { id: 'b' }],
14
+ * edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
15
+ * });
16
+ *
17
+ * const jgf = toJGF(graph);
18
+ * // { graph: { directed: true, nodes: [...], edges: [...] } }
19
+ * ```
20
+ */
4
21
  function toJGF(graph) {
5
22
  const metadata = {};
6
- if (graph.initialNodeId !== null) metadata.initialNodeId = graph.initialNodeId;
23
+ if (graph.initialNodeId) metadata.initialNodeId = graph.initialNodeId;
7
24
  if (graph.data !== void 0) metadata.data = graph.data;
8
25
  if (graph.direction) metadata.direction = graph.direction;
9
26
  return { graph: {
@@ -12,8 +29,8 @@ function toJGF(graph) {
12
29
  ...Object.keys(metadata).length > 0 && { metadata },
13
30
  nodes: graph.nodes.map((n) => {
14
31
  const meta = {};
15
- if (n.parentId !== null) meta.parentId = n.parentId;
16
- if (n.initialNodeId !== null) meta.initialNodeId = n.initialNodeId;
32
+ if (n.parentId) meta.parentId = n.parentId;
33
+ if (n.initialNodeId) meta.initialNodeId = n.initialNodeId;
17
34
  if (n.data !== void 0) meta.data = n.data;
18
35
  if (n.x !== void 0) meta.x = n.x;
19
36
  if (n.y !== void 0) meta.y = n.y;
@@ -41,6 +58,22 @@ function toJGF(graph) {
41
58
  })
42
59
  } };
43
60
  }
61
+ /**
62
+ * Parses a JSON Graph Format (JGF) object into a graph.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import { fromJGF } from '@statelyai/graph/formats/jgf';
67
+ *
68
+ * const graph = fromJGF({
69
+ * graph: {
70
+ * directed: true,
71
+ * nodes: [{ id: 'a' }, { id: 'b' }],
72
+ * edges: [{ source: 'a', target: 'b' }],
73
+ * },
74
+ * });
75
+ * ```
76
+ */
44
77
  function fromJGF(jgf) {
45
78
  if (!jgf || typeof jgf !== "object") throw new Error("JGF: expected an object");
46
79
  if (!jgf.graph || typeof jgf.graph !== "object") throw new Error("JGF: missing \"graph\" property");
@@ -78,7 +111,23 @@ function fromJGF(jgf) {
78
111
  }))
79
112
  };
80
113
  }
81
- /** Bidirectional converter for JSON Graph Format. */
114
+ /**
115
+ * Bidirectional converter for JSON Graph Format.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * import { createGraph } from '@statelyai/graph';
120
+ * import { jgfConverter } from '@statelyai/graph/formats/jgf';
121
+ *
122
+ * const graph = createGraph({
123
+ * nodes: [{ id: 'a' }, { id: 'b' }],
124
+ * edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
125
+ * });
126
+ *
127
+ * const jgf = jgfConverter.to(graph);
128
+ * const roundTripped = jgfConverter.from(jgf);
129
+ * ```
130
+ */
82
131
  const jgfConverter = createFormatConverter(toJGF, fromJGF);
83
132
 
84
133
  //#endregion
@@ -1,4 +1,4 @@
1
- import { c as Graph, f as GraphFormatConverter } from "../../types-B6Tpeerk.mjs";
1
+ import { c as Graph, f as GraphFormatConverter } from "../../types-Bq_fmLwW.mjs";
2
2
 
3
3
  //#region src/formats/mermaid/sequence.d.ts
4
4
  interface SequenceNodeData {
@@ -58,9 +58,37 @@ interface SequenceGraphData {
58
58
  blocks?: SequenceBlock[];
59
59
  }
60
60
  type SequenceGraph = Graph<SequenceNodeData, SequenceEdgeData, SequenceGraphData>;
61
+ /**
62
+ * Parses a Mermaid sequence diagram string into a Graph.
63
+ *
64
+ * @example
65
+ * const graph = fromMermaidSequence(`
66
+ * sequenceDiagram
67
+ * participant Alice
68
+ * participant Bob
69
+ * Alice->>Bob: Hello
70
+ * Bob-->>Alice: Hi back
71
+ * `);
72
+ */
61
73
  declare function fromMermaidSequence(input: string): SequenceGraph;
74
+ /**
75
+ * Converts a sequence diagram Graph to a Mermaid sequence diagram string.
76
+ *
77
+ * @example
78
+ * const mermaid = toMermaidSequence(graph);
79
+ * // "sequenceDiagram\n participant Alice\n ..."
80
+ */
62
81
  declare function toMermaidSequence(graph: SequenceGraph): string;
63
- /** Bidirectional converter for Mermaid sequence diagram format. */
82
+ /**
83
+ * Bidirectional converter for Mermaid sequence diagram format.
84
+ *
85
+ * @example
86
+ * const graph = mermaidSequenceConverter.from(`
87
+ * sequenceDiagram
88
+ * Alice->>Bob: Hello
89
+ * `);
90
+ * const str = mermaidSequenceConverter.to(graph);
91
+ */
64
92
  declare const mermaidSequenceConverter: GraphFormatConverter<string>;
65
93
  //#endregion
66
94
  //#region src/formats/mermaid/flowchart.d.ts
@@ -82,9 +110,35 @@ interface FlowchartGraphData {
82
110
  classDefs?: Record<string, Record<string, string>>;
83
111
  }
84
112
  type FlowchartGraph = Graph<FlowchartNodeData, FlowchartEdgeData, FlowchartGraphData>;
113
+ /**
114
+ * Parses a Mermaid flowchart string into a Graph.
115
+ *
116
+ * @example
117
+ * const graph = fromMermaidFlowchart(`
118
+ * flowchart TD
119
+ * A[Start] --> B{Decision}
120
+ * B -->|Yes| C[End]
121
+ * `);
122
+ */
85
123
  declare function fromMermaidFlowchart(input: string): FlowchartGraph;
124
+ /**
125
+ * Converts a flowchart Graph to a Mermaid flowchart string.
126
+ *
127
+ * @example
128
+ * const mermaid = toMermaidFlowchart(graph);
129
+ * // "flowchart TD\n A[Start] --> B{Decision}\n ..."
130
+ */
86
131
  declare function toMermaidFlowchart(graph: FlowchartGraph): string;
87
- /** Bidirectional converter for Mermaid flowchart format. */
132
+ /**
133
+ * Bidirectional converter for Mermaid flowchart format.
134
+ *
135
+ * @example
136
+ * const graph = mermaidFlowchartConverter.from(`
137
+ * flowchart TD
138
+ * A --> B
139
+ * `);
140
+ * const str = mermaidFlowchartConverter.to(graph);
141
+ */
88
142
  declare const mermaidFlowchartConverter: GraphFormatConverter<string>;
89
143
  //#endregion
90
144
  //#region src/formats/mermaid/state.d.ts
@@ -103,9 +157,36 @@ interface StateGraphData {
103
157
  diagramType: 'stateDiagram';
104
158
  }
105
159
  type StateGraph = Graph<StateNodeData, StateEdgeData, StateGraphData>;
160
+ /**
161
+ * Parses a Mermaid state diagram string into a Graph.
162
+ *
163
+ * @example
164
+ * const graph = fromMermaidState(`
165
+ * stateDiagram-v2
166
+ * [*] --> Idle
167
+ * Idle --> Running : start
168
+ * Running --> [*]
169
+ * `);
170
+ */
106
171
  declare function fromMermaidState(input: string): StateGraph;
172
+ /**
173
+ * Converts a state diagram Graph to a Mermaid state diagram string.
174
+ *
175
+ * @example
176
+ * const mermaid = toMermaidState(graph);
177
+ * // "stateDiagram-v2\n [*] --> Idle\n ..."
178
+ */
107
179
  declare function toMermaidState(graph: StateGraph): string;
108
- /** Bidirectional converter for Mermaid state diagram format. */
180
+ /**
181
+ * Bidirectional converter for Mermaid state diagram format.
182
+ *
183
+ * @example
184
+ * const graph = mermaidStateConverter.from(`
185
+ * stateDiagram-v2
186
+ * [*] --> Active
187
+ * `);
188
+ * const str = mermaidStateConverter.to(graph);
189
+ */
109
190
  declare const mermaidStateConverter: GraphFormatConverter<string>;
110
191
  //#endregion
111
192
  //#region src/formats/mermaid/class-diagram.d.ts
@@ -128,9 +209,38 @@ interface ClassGraphData {
128
209
  diagramType: 'classDiagram';
129
210
  }
130
211
  type ClassGraph = Graph<ClassNodeData, ClassEdgeData, ClassGraphData>;
212
+ /**
213
+ * Parses a Mermaid class diagram string into a Graph.
214
+ *
215
+ * @example
216
+ * const graph = fromMermaidClass(`
217
+ * classDiagram
218
+ * class Animal {
219
+ * +String name
220
+ * +eat() void
221
+ * }
222
+ * Animal <|-- Dog
223
+ * `);
224
+ */
131
225
  declare function fromMermaidClass(input: string): ClassGraph;
226
+ /**
227
+ * Converts a class diagram Graph to a Mermaid class diagram string.
228
+ *
229
+ * @example
230
+ * const mermaid = toMermaidClass(graph);
231
+ * // "classDiagram\n class Animal {\n ..."
232
+ */
132
233
  declare function toMermaidClass(graph: ClassGraph): string;
133
- /** Bidirectional converter for Mermaid class diagram format. */
234
+ /**
235
+ * Bidirectional converter for Mermaid class diagram format.
236
+ *
237
+ * @example
238
+ * const graph = mermaidClassConverter.from(`
239
+ * classDiagram
240
+ * Animal <|-- Dog
241
+ * `);
242
+ * const str = mermaidClassConverter.to(graph);
243
+ */
134
244
  declare const mermaidClassConverter: GraphFormatConverter<string>;
135
245
  //#endregion
136
246
  //#region src/formats/mermaid/er-diagram.d.ts
@@ -151,9 +261,35 @@ interface ERGraphData {
151
261
  diagramType: 'erDiagram';
152
262
  }
153
263
  type ERGraph = Graph<ERNodeData, EREdgeData, ERGraphData>;
264
+ /**
265
+ * Parses a Mermaid ER diagram string into a Graph.
266
+ *
267
+ * @example
268
+ * const graph = fromMermaidER(`
269
+ * erDiagram
270
+ * CUSTOMER ||--o{ ORDER : places
271
+ * ORDER ||--|{ LINE_ITEM : contains
272
+ * `);
273
+ */
154
274
  declare function fromMermaidER(input: string): ERGraph;
275
+ /**
276
+ * Converts an ER diagram Graph to a Mermaid ER diagram string.
277
+ *
278
+ * @example
279
+ * const mermaid = toMermaidER(graph);
280
+ * // "erDiagram\n CUSTOMER ||--o{ ORDER : \"places\"\n ..."
281
+ */
155
282
  declare function toMermaidER(graph: ERGraph): string;
156
- /** Bidirectional converter for Mermaid ER diagram format. */
283
+ /**
284
+ * Bidirectional converter for Mermaid ER diagram format.
285
+ *
286
+ * @example
287
+ * const graph = mermaidERConverter.from(`
288
+ * erDiagram
289
+ * CUSTOMER ||--o{ ORDER : places
290
+ * `);
291
+ * const str = mermaidERConverter.to(graph);
292
+ */
157
293
  declare const mermaidERConverter: GraphFormatConverter<string>;
158
294
  //#endregion
159
295
  //#region src/formats/mermaid/mindmap.d.ts
@@ -165,9 +301,38 @@ interface MindmapGraphData {
165
301
  diagramType: 'mindmap';
166
302
  }
167
303
  type MindmapGraph = Graph<MindmapNodeData, MindmapEdgeData, MindmapGraphData>;
304
+ /**
305
+ * Parses a Mermaid mindmap string into a Graph.
306
+ *
307
+ * @example
308
+ * const graph = fromMermaidMindmap(`
309
+ * mindmap
310
+ * Root
311
+ * Child A
312
+ * Grandchild
313
+ * Child B
314
+ * `);
315
+ */
168
316
  declare function fromMermaidMindmap(input: string): MindmapGraph;
317
+ /**
318
+ * Converts a mindmap Graph to a Mermaid mindmap string.
319
+ *
320
+ * @example
321
+ * const mermaid = toMermaidMindmap(graph);
322
+ * // "mindmap\n Root\n Child A\n ..."
323
+ */
169
324
  declare function toMermaidMindmap(graph: MindmapGraph): string;
170
- /** Bidirectional converter for Mermaid mindmap format. */
325
+ /**
326
+ * Bidirectional converter for Mermaid mindmap format.
327
+ *
328
+ * @example
329
+ * const graph = mermaidMindmapConverter.from(`
330
+ * mindmap
331
+ * Root
332
+ * Branch
333
+ * `);
334
+ * const str = mermaidMindmapConverter.to(graph);
335
+ */
171
336
  declare const mermaidMindmapConverter: GraphFormatConverter<string>;
172
337
  //#endregion
173
338
  //#region src/formats/mermaid/block.d.ts
@@ -180,9 +345,37 @@ interface BlockGraphData {
180
345
  columns?: number;
181
346
  }
182
347
  type BlockGraph = Graph<BlockNodeData, BlockEdgeData, BlockGraphData>;
348
+ /**
349
+ * Parses a Mermaid block diagram string into a Graph.
350
+ *
351
+ * @example
352
+ * const graph = fromMermaidBlock(`
353
+ * block-beta
354
+ * columns 2
355
+ * a["Task A"] b["Task B"]
356
+ * a --> b
357
+ * `);
358
+ */
183
359
  declare function fromMermaidBlock(input: string): BlockGraph;
360
+ /**
361
+ * Converts a block diagram Graph to a Mermaid block diagram string.
362
+ *
363
+ * @example
364
+ * const mermaid = toMermaidBlock(graph);
365
+ * // "block-beta\n columns 2\n a[\"Task A\"]\n ..."
366
+ */
184
367
  declare function toMermaidBlock(graph: BlockGraph): string;
185
- /** Bidirectional converter for Mermaid block diagram format. */
368
+ /**
369
+ * Bidirectional converter for Mermaid block diagram format.
370
+ *
371
+ * @example
372
+ * const graph = mermaidBlockConverter.from(`
373
+ * block-beta
374
+ * columns 2
375
+ * a b
376
+ * `);
377
+ * const str = mermaidBlockConverter.to(graph);
378
+ */
186
379
  declare const mermaidBlockConverter: GraphFormatConverter<string>;
187
380
  //#endregion
188
381
  export { type BlockEdgeData, type BlockGraphData, type BlockNodeData, type ClassEdgeData, type ClassGraphData, type ClassNodeData, type EREdgeData, type ERGraphData, type ERNodeData, type FlowchartEdgeData, type FlowchartGraphData, type FlowchartNodeData, type MindmapEdgeData, type MindmapGraphData, type MindmapNodeData, type SequenceBlock, type SequenceEdgeData, type SequenceGraphData, type SequenceNodeData, type StateEdgeData, type StateGraphData, type StateNodeData, fromMermaidBlock, fromMermaidClass, fromMermaidER, fromMermaidFlowchart, fromMermaidMindmap, fromMermaidSequence, fromMermaidState, mermaidBlockConverter, mermaidClassConverter, mermaidERConverter, mermaidFlowchartConverter, mermaidMindmapConverter, mermaidSequenceConverter, mermaidStateConverter, toMermaidBlock, toMermaidClass, toMermaidER, toMermaidFlowchart, toMermaidMindmap, toMermaidSequence, toMermaidState };