@statelyai/graph 0.1.0 → 0.3.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 (49) hide show
  1. package/README.md +65 -15
  2. package/dist/{adjacency-list-CXpOCibq.mjs → adjacency-list-A4_Eiwj3.mjs} +1 -1
  3. package/dist/{algorithms-R35X6ro4.mjs → algorithms-DBU7nmIV.mjs} +83 -2
  4. package/dist/algorithms.d.mts +10 -2
  5. package/dist/algorithms.mjs +2 -2
  6. package/dist/converter-DnbeyE_p.mjs +33 -0
  7. package/dist/{edge-list-BRujEnnU.mjs → edge-list-DuHMz8hf.mjs} +1 -1
  8. package/dist/{adjacency-list-DW-lAUe8.d.mts → formats/adjacency-list/index.d.mts} +3 -3
  9. package/dist/formats/adjacency-list/index.mjs +3 -0
  10. package/dist/formats/converter/index.d.mts +27 -0
  11. package/dist/formats/converter/index.mjs +3 -0
  12. package/dist/formats/cytoscape/index.d.mts +35 -0
  13. package/dist/formats/cytoscape/index.mjs +87 -0
  14. package/dist/formats/d3/index.d.mts +22 -0
  15. package/dist/formats/d3/index.mjs +65 -0
  16. package/dist/formats/dot/index.d.mts +9 -0
  17. package/dist/formats/dot/index.mjs +235 -0
  18. package/dist/{edge-list-CJmfoNu2.d.mts → formats/edge-list/index.d.mts} +3 -3
  19. package/dist/formats/edge-list/index.mjs +3 -0
  20. package/dist/formats/gexf/index.d.mts +9 -0
  21. package/dist/formats/gexf/index.mjs +249 -0
  22. package/dist/formats/gml/index.d.mts +9 -0
  23. package/dist/formats/gml/index.mjs +236 -0
  24. package/dist/formats/graphml/index.d.mts +9 -0
  25. package/dist/{graphml-CUTNRXqd.mjs → formats/graphml/index.mjs} +18 -4
  26. package/dist/formats/jgf/index.d.mts +30 -0
  27. package/dist/formats/jgf/index.mjs +85 -0
  28. package/dist/formats/mermaid/index.d.mts +188 -0
  29. package/dist/formats/mermaid/index.mjs +1898 -0
  30. package/dist/formats/tgf/index.d.mts +9 -0
  31. package/dist/formats/tgf/index.mjs +67 -0
  32. package/dist/index.d.mts +14 -9
  33. package/dist/index.mjs +5 -9
  34. package/dist/queries.d.mts +78 -2
  35. package/dist/queries.mjs +121 -2
  36. package/dist/{types-XV3S5Jnh.d.mts → types-B6Tpeerk.d.mts} +36 -1
  37. package/package.json +43 -17
  38. package/dist/dot-BRtq3e3c.mjs +0 -59
  39. package/dist/dot-HmJeUMsj.d.mts +0 -6
  40. package/dist/formats/adjacency-list.d.mts +0 -2
  41. package/dist/formats/adjacency-list.mjs +0 -3
  42. package/dist/formats/dot.d.mts +0 -2
  43. package/dist/formats/dot.mjs +0 -3
  44. package/dist/formats/edge-list.d.mts +0 -2
  45. package/dist/formats/edge-list.mjs +0 -3
  46. package/dist/formats/graphml.d.mts +0 -2
  47. package/dist/formats/graphml.mjs +0 -3
  48. package/dist/graphml-CMjPzSfY.d.mts +0 -7
  49. /package/dist/{indexing-BHg1VhqN.mjs → indexing-BFFVMnjF.mjs} +0 -0
@@ -0,0 +1,236 @@
1
+ import { n as createFormatConverter } from "../../converter-DnbeyE_p.mjs";
2
+
3
+ //#region src/formats/gml/index.ts
4
+ function toGML(graph) {
5
+ const lines = [];
6
+ lines.push("graph [");
7
+ lines.push(` directed ${graph.type === "directed" ? 1 : 0}`);
8
+ if (graph.id) lines.push(` id ${gmlString(graph.id)}`);
9
+ const childrenMap = /* @__PURE__ */ new Map();
10
+ for (const node of graph.nodes) {
11
+ const pid = node.parentId;
12
+ if (!childrenMap.has(pid)) childrenMap.set(pid, []);
13
+ childrenMap.get(pid).push(node);
14
+ }
15
+ function writeNode(node, indent) {
16
+ lines.push(`${indent}node [`);
17
+ lines.push(`${indent} id ${gmlString(node.id)}`);
18
+ if (node.label) lines.push(`${indent} label ${gmlString(node.label)}`);
19
+ if (node.initialNodeId !== null) lines.push(`${indent} initialNodeId ${gmlString(node.initialNodeId)}`);
20
+ if (node.data !== void 0) lines.push(`${indent} data ${gmlString(JSON.stringify(node.data))}`);
21
+ if (node.shape) lines.push(`${indent} shape ${gmlString(node.shape)}`);
22
+ if (node.color) lines.push(`${indent} color ${gmlString(node.color)}`);
23
+ if (node.x !== void 0 || node.y !== void 0 || node.width !== void 0 || node.height !== void 0) {
24
+ lines.push(`${indent} graphics [`);
25
+ if (node.x !== void 0) lines.push(`${indent} x ${node.x}`);
26
+ if (node.y !== void 0) lines.push(`${indent} y ${node.y}`);
27
+ if (node.width !== void 0) lines.push(`${indent} w ${node.width}`);
28
+ if (node.height !== void 0) lines.push(`${indent} h ${node.height}`);
29
+ lines.push(`${indent} ]`);
30
+ }
31
+ const children = childrenMap.get(node.id);
32
+ if (children) for (const child of children) writeNode(child, indent + " ");
33
+ lines.push(`${indent}]`);
34
+ }
35
+ const roots = childrenMap.get(null) ?? [];
36
+ for (const node of roots) writeNode(node, " ");
37
+ for (const edge of graph.edges) {
38
+ lines.push(" edge [");
39
+ lines.push(` id ${gmlString(edge.id)}`);
40
+ lines.push(` source ${gmlString(edge.sourceId)}`);
41
+ lines.push(` target ${gmlString(edge.targetId)}`);
42
+ if (edge.label) lines.push(` label ${gmlString(edge.label)}`);
43
+ if (edge.data !== void 0) lines.push(` data ${gmlString(JSON.stringify(edge.data))}`);
44
+ if (edge.color) lines.push(` color ${gmlString(edge.color)}`);
45
+ lines.push(" ]");
46
+ }
47
+ lines.push("]");
48
+ return lines.join("\n");
49
+ }
50
+ function gmlString(s) {
51
+ return `"${s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
52
+ }
53
+ function fromGML(gml) {
54
+ if (typeof gml !== "string") throw new Error("GML: expected a string");
55
+ if (!gml.trim()) throw new Error("GML: input is empty");
56
+ const tokens = tokenize(gml);
57
+ if (tokens.length === 0) throw new Error("GML: no tokens found");
58
+ const graphBlock = parseBlock(tokens, 0).value["graph"];
59
+ if (!graphBlock) throw new Error("GML: missing top-level \"graph\" block");
60
+ const directed = graphBlock["directed"] === 1;
61
+ const graphId = String(graphBlock["id"] ?? "");
62
+ const nodes = [];
63
+ const edges = [];
64
+ function parseNodes(block, parentId) {
65
+ const nodeEntries = asArray(block["node"]);
66
+ for (const n of nodeEntries) {
67
+ const id = String(n["id"] ?? "");
68
+ const gfx = n["graphics"];
69
+ nodes.push({
70
+ type: "node",
71
+ id,
72
+ parentId,
73
+ initialNodeId: n["initialNodeId"] ?? null,
74
+ label: n["label"] ?? "",
75
+ data: n["data"] !== void 0 ? tryParseJSON(n["data"]) : void 0,
76
+ ...n["shape"] && { shape: n["shape"] },
77
+ ...n["color"] && { color: n["color"] },
78
+ ...gfx?.x !== void 0 && { x: gfx.x },
79
+ ...gfx?.y !== void 0 && { y: gfx.y },
80
+ ...gfx?.w !== void 0 && { width: gfx.w },
81
+ ...gfx?.h !== void 0 && { height: gfx.h }
82
+ });
83
+ if (n["node"] !== void 0) parseNodes(n, id);
84
+ }
85
+ }
86
+ parseNodes(graphBlock, null);
87
+ const edgeEntries = asArray(graphBlock["edge"]);
88
+ for (const e of edgeEntries) edges.push({
89
+ type: "edge",
90
+ id: String(e["id"] ?? `e${edges.length}`),
91
+ sourceId: String(e["source"] ?? ""),
92
+ targetId: String(e["target"] ?? ""),
93
+ label: e["label"] ?? "",
94
+ data: e["data"] !== void 0 ? tryParseJSON(e["data"]) : void 0,
95
+ ...e["color"] && { color: e["color"] }
96
+ });
97
+ return {
98
+ id: graphId,
99
+ type: directed ? "directed" : "undirected",
100
+ initialNodeId: null,
101
+ nodes,
102
+ edges,
103
+ data: void 0
104
+ };
105
+ }
106
+ function tokenize(input) {
107
+ const tokens = [];
108
+ let i = 0;
109
+ while (i < input.length) {
110
+ const ch = input[i];
111
+ if (/\s/.test(ch)) {
112
+ i++;
113
+ continue;
114
+ }
115
+ if (ch === "#") {
116
+ while (i < input.length && input[i] !== "\n") i++;
117
+ continue;
118
+ }
119
+ if (ch === "[") {
120
+ tokens.push({
121
+ type: "open",
122
+ value: "["
123
+ });
124
+ i++;
125
+ continue;
126
+ }
127
+ if (ch === "]") {
128
+ tokens.push({
129
+ type: "close",
130
+ value: "]"
131
+ });
132
+ i++;
133
+ continue;
134
+ }
135
+ if (ch === "\"") {
136
+ i++;
137
+ let s = "";
138
+ while (i < input.length && input[i] !== "\"") {
139
+ if (input[i] === "\\" && i + 1 < input.length) {
140
+ i++;
141
+ s += input[i];
142
+ } else s += input[i];
143
+ i++;
144
+ }
145
+ i++;
146
+ tokens.push({
147
+ type: "string",
148
+ value: s
149
+ });
150
+ continue;
151
+ }
152
+ if (/[-+0-9.]/.test(ch)) {
153
+ let num = "";
154
+ while (i < input.length && /[-+0-9.eE]/.test(input[i])) {
155
+ num += input[i];
156
+ i++;
157
+ }
158
+ const parsed = Number(num);
159
+ if (!isNaN(parsed)) tokens.push({
160
+ type: "number",
161
+ value: parsed
162
+ });
163
+ else tokens.push({
164
+ type: "word",
165
+ value: num
166
+ });
167
+ continue;
168
+ }
169
+ if (/[a-zA-Z_]/.test(ch)) {
170
+ let word = "";
171
+ while (i < input.length && /[a-zA-Z0-9_]/.test(input[i])) {
172
+ word += input[i];
173
+ i++;
174
+ }
175
+ tokens.push({
176
+ type: "word",
177
+ value: word
178
+ });
179
+ continue;
180
+ }
181
+ i++;
182
+ }
183
+ return tokens;
184
+ }
185
+ function parseBlock(tokens, pos) {
186
+ const result = {};
187
+ while (pos < tokens.length) {
188
+ const tok = tokens[pos];
189
+ if (tok.type === "close") {
190
+ pos++;
191
+ break;
192
+ }
193
+ if (tok.type === "word") {
194
+ const key = tok.value;
195
+ pos++;
196
+ if (pos >= tokens.length) break;
197
+ const next = tokens[pos];
198
+ if (next.type === "open") {
199
+ pos++;
200
+ const nested = parseBlock(tokens, pos);
201
+ pos = nested.pos;
202
+ if (result[key] !== void 0) {
203
+ if (!Array.isArray(result[key])) result[key] = [result[key]];
204
+ result[key].push(nested.value);
205
+ } else result[key] = nested.value;
206
+ } else {
207
+ if (result[key] !== void 0) {
208
+ if (!Array.isArray(result[key])) result[key] = [result[key]];
209
+ result[key].push(next.value);
210
+ } else result[key] = next.value;
211
+ pos++;
212
+ }
213
+ } else pos++;
214
+ }
215
+ return {
216
+ value: result,
217
+ pos
218
+ };
219
+ }
220
+ function asArray(val) {
221
+ if (val === void 0) return [];
222
+ return Array.isArray(val) ? val : [val];
223
+ }
224
+ function tryParseJSON(str) {
225
+ if (typeof str !== "string") return str;
226
+ try {
227
+ return JSON.parse(str);
228
+ } catch {
229
+ return str;
230
+ }
231
+ }
232
+ /** Bidirectional converter for GML (Graph Modelling Language) format. */
233
+ const gmlConverter = createFormatConverter(toGML, fromGML);
234
+
235
+ //#endregion
236
+ export { fromGML, gmlConverter, toGML };
@@ -0,0 +1,9 @@
1
+ import { c as Graph, f as GraphFormatConverter } from "../../types-B6Tpeerk.mjs";
2
+
3
+ //#region src/formats/graphml/index.d.ts
4
+ declare function toGraphML(graph: Graph): string;
5
+ declare function fromGraphML(xml: string): Graph;
6
+ /** Bidirectional converter for GraphML XML format. */
7
+ declare const graphmlConverter: GraphFormatConverter<string>;
8
+ //#endregion
9
+ export { fromGraphML, graphmlConverter, toGraphML };
@@ -1,6 +1,7 @@
1
+ import { n as createFormatConverter } from "../../converter-DnbeyE_p.mjs";
1
2
  import { XMLBuilder, XMLParser } from "fast-xml-parser";
2
3
 
3
- //#region src/formats/graphml.ts
4
+ //#region src/formats/graphml/index.ts
4
5
  const GRAPHML_NS = "http://graphml.graphdrawing.org/xmlns";
5
6
  function toGraphML(graph) {
6
7
  const keys = [
@@ -174,7 +175,8 @@ function toGraphML(graph) {
174
175
  }).build(obj);
175
176
  }
176
177
  function fromGraphML(xml) {
177
- const graphEl = new XMLParser({
178
+ if (typeof xml !== "string") throw new Error("GraphML: expected a string");
179
+ const parser = new XMLParser({
178
180
  ignoreAttributes: false,
179
181
  isArray: (name) => [
180
182
  "node",
@@ -182,7 +184,17 @@ function fromGraphML(xml) {
182
184
  "data",
183
185
  "key"
184
186
  ].includes(name)
185
- }).parse(xml).graphml.graph;
187
+ });
188
+ let parsed;
189
+ try {
190
+ parsed = parser.parse(xml);
191
+ } catch (e) {
192
+ throw new Error(`GraphML: invalid XML — ${e.message}`);
193
+ }
194
+ const graphml = parsed?.graphml;
195
+ if (!graphml) throw new Error("GraphML: missing <graphml> root element");
196
+ const graphEl = graphml.graph;
197
+ if (!graphEl) throw new Error("GraphML: missing <graph> element");
186
198
  const graphType = graphEl["@_edgedefault"] === "undirected" ? "undirected" : "directed";
187
199
  let graphData = void 0;
188
200
  if (graphEl.data) {
@@ -235,6 +247,8 @@ function tryParseJSON(str) {
235
247
  return str;
236
248
  }
237
249
  }
250
+ /** Bidirectional converter for GraphML XML format. */
251
+ const graphmlConverter = createFormatConverter(toGraphML, fromGraphML);
238
252
 
239
253
  //#endregion
240
- export { toGraphML as n, fromGraphML as t };
254
+ export { fromGraphML, graphmlConverter, toGraphML };
@@ -0,0 +1,30 @@
1
+ import { c as Graph, f as GraphFormatConverter } from "../../types-B6Tpeerk.mjs";
2
+
3
+ //#region src/formats/jgf/index.d.ts
4
+ interface JGFNode {
5
+ id: string;
6
+ label?: string;
7
+ metadata?: Record<string, any>;
8
+ }
9
+ interface JGFEdge {
10
+ id?: string;
11
+ source: string;
12
+ target: string;
13
+ label?: string;
14
+ metadata?: Record<string, any>;
15
+ }
16
+ interface JGFGraph {
17
+ graph: {
18
+ id?: string;
19
+ directed?: boolean;
20
+ metadata?: Record<string, any>;
21
+ nodes: JGFNode[];
22
+ edges: JGFEdge[];
23
+ };
24
+ }
25
+ declare function toJGF(graph: Graph): JGFGraph;
26
+ declare function fromJGF(jgf: JGFGraph): Graph;
27
+ /** Bidirectional converter for JSON Graph Format. */
28
+ declare const jgfConverter: GraphFormatConverter<JGFGraph>;
29
+ //#endregion
30
+ export { JGFEdge, JGFGraph, JGFNode, fromJGF, jgfConverter, toJGF };
@@ -0,0 +1,85 @@
1
+ import { n as createFormatConverter } from "../../converter-DnbeyE_p.mjs";
2
+
3
+ //#region src/formats/jgf/index.ts
4
+ function toJGF(graph) {
5
+ const metadata = {};
6
+ if (graph.initialNodeId !== null) metadata.initialNodeId = graph.initialNodeId;
7
+ if (graph.data !== void 0) metadata.data = graph.data;
8
+ if (graph.direction) metadata.direction = graph.direction;
9
+ return { graph: {
10
+ id: graph.id || void 0,
11
+ directed: graph.type === "directed",
12
+ ...Object.keys(metadata).length > 0 && { metadata },
13
+ nodes: graph.nodes.map((n) => {
14
+ const meta = {};
15
+ if (n.parentId !== null) meta.parentId = n.parentId;
16
+ if (n.initialNodeId !== null) meta.initialNodeId = n.initialNodeId;
17
+ if (n.data !== void 0) meta.data = n.data;
18
+ if (n.x !== void 0) meta.x = n.x;
19
+ if (n.y !== void 0) meta.y = n.y;
20
+ if (n.width !== void 0) meta.width = n.width;
21
+ if (n.height !== void 0) meta.height = n.height;
22
+ if (n.shape) meta.shape = n.shape;
23
+ if (n.color) meta.color = n.color;
24
+ return {
25
+ id: n.id,
26
+ ...n.label && { label: n.label },
27
+ ...Object.keys(meta).length > 0 && { metadata: meta }
28
+ };
29
+ }),
30
+ edges: graph.edges.map((e) => {
31
+ const meta = {};
32
+ if (e.data !== void 0) meta.data = e.data;
33
+ if (e.color) meta.color = e.color;
34
+ return {
35
+ id: e.id,
36
+ source: e.sourceId,
37
+ target: e.targetId,
38
+ ...e.label && { label: e.label },
39
+ ...Object.keys(meta).length > 0 && { metadata: meta }
40
+ };
41
+ })
42
+ } };
43
+ }
44
+ function fromJGF(jgf) {
45
+ if (!jgf || typeof jgf !== "object") throw new Error("JGF: expected an object");
46
+ if (!jgf.graph || typeof jgf.graph !== "object") throw new Error("JGF: missing \"graph\" property");
47
+ const g = jgf.graph;
48
+ if (!Array.isArray(g.nodes)) throw new Error("JGF: \"graph.nodes\" must be an array");
49
+ if (!Array.isArray(g.edges)) throw new Error("JGF: \"graph.edges\" must be an array");
50
+ return {
51
+ id: g.id ?? "",
52
+ type: g.directed === false ? "undirected" : "directed",
53
+ initialNodeId: g.metadata?.initialNodeId ?? null,
54
+ data: g.metadata?.data,
55
+ ...g.metadata?.direction && { direction: g.metadata.direction },
56
+ nodes: g.nodes.map((n) => ({
57
+ type: "node",
58
+ id: n.id,
59
+ parentId: n.metadata?.parentId ?? null,
60
+ initialNodeId: n.metadata?.initialNodeId ?? null,
61
+ label: n.label ?? "",
62
+ data: n.metadata?.data,
63
+ ...n.metadata?.x !== void 0 && { x: n.metadata.x },
64
+ ...n.metadata?.y !== void 0 && { y: n.metadata.y },
65
+ ...n.metadata?.width !== void 0 && { width: n.metadata.width },
66
+ ...n.metadata?.height !== void 0 && { height: n.metadata.height },
67
+ ...n.metadata?.shape && { shape: n.metadata.shape },
68
+ ...n.metadata?.color && { color: n.metadata.color }
69
+ })),
70
+ edges: g.edges.map((e, i) => ({
71
+ type: "edge",
72
+ id: e.id ?? `e${i}`,
73
+ sourceId: e.source,
74
+ targetId: e.target,
75
+ label: e.label ?? "",
76
+ data: e.metadata?.data,
77
+ ...e.metadata?.color && { color: e.metadata.color }
78
+ }))
79
+ };
80
+ }
81
+ /** Bidirectional converter for JSON Graph Format. */
82
+ const jgfConverter = createFormatConverter(toJGF, fromJGF);
83
+
84
+ //#endregion
85
+ export { fromJGF, jgfConverter, toJGF };
@@ -0,0 +1,188 @@
1
+ import { c as Graph, f as GraphFormatConverter } from "../../types-B6Tpeerk.mjs";
2
+
3
+ //#region src/formats/mermaid/sequence.d.ts
4
+ interface SequenceNodeData {
5
+ actorType: 'participant' | 'actor';
6
+ alias?: string;
7
+ created?: boolean;
8
+ destroyed?: boolean;
9
+ }
10
+ interface SequenceEdgeData {
11
+ kind: 'message' | 'activation' | 'deactivation';
12
+ stroke?: 'solid' | 'dotted';
13
+ arrowType?: 'filled' | 'open' | 'cross' | 'async';
14
+ bidirectional?: boolean;
15
+ sequenceNumber?: number;
16
+ }
17
+ type SequenceBlock = {
18
+ type: 'loop';
19
+ label: string;
20
+ edgeIds: string[];
21
+ } | {
22
+ type: 'alt';
23
+ label: string;
24
+ branches: {
25
+ label?: string;
26
+ edgeIds: string[];
27
+ }[];
28
+ } | {
29
+ type: 'opt';
30
+ label: string;
31
+ edgeIds: string[];
32
+ } | {
33
+ type: 'par';
34
+ branches: {
35
+ label: string;
36
+ edgeIds: string[];
37
+ }[];
38
+ } | {
39
+ type: 'critical';
40
+ label: string;
41
+ edgeIds: string[];
42
+ options?: {
43
+ label: string;
44
+ edgeIds: string[];
45
+ }[];
46
+ } | {
47
+ type: 'break';
48
+ label: string;
49
+ edgeIds: string[];
50
+ } | {
51
+ type: 'rect';
52
+ color: string;
53
+ edgeIds: string[];
54
+ };
55
+ interface SequenceGraphData {
56
+ diagramType: 'sequence';
57
+ autonumber?: boolean;
58
+ blocks?: SequenceBlock[];
59
+ }
60
+ type SequenceGraph = Graph<SequenceNodeData, SequenceEdgeData, SequenceGraphData>;
61
+ declare function fromMermaidSequence(input: string): SequenceGraph;
62
+ declare function toMermaidSequence(graph: SequenceGraph): string;
63
+ /** Bidirectional converter for Mermaid sequence diagram format. */
64
+ declare const mermaidSequenceConverter: GraphFormatConverter<string>;
65
+ //#endregion
66
+ //#region src/formats/mermaid/flowchart.d.ts
67
+ interface FlowchartNodeData {
68
+ classes?: string[];
69
+ link?: string;
70
+ tooltip?: string;
71
+ }
72
+ interface FlowchartEdgeData {
73
+ stroke: 'normal' | 'dotted' | 'thick';
74
+ arrowType: 'arrow' | 'none';
75
+ endMarker?: 'arrow' | 'circle' | 'cross';
76
+ startMarker?: 'arrow' | 'circle' | 'cross';
77
+ bidirectional?: boolean;
78
+ styleIndex?: number;
79
+ }
80
+ interface FlowchartGraphData {
81
+ diagramType: 'flowchart';
82
+ classDefs?: Record<string, Record<string, string>>;
83
+ }
84
+ type FlowchartGraph = Graph<FlowchartNodeData, FlowchartEdgeData, FlowchartGraphData>;
85
+ declare function fromMermaidFlowchart(input: string): FlowchartGraph;
86
+ declare function toMermaidFlowchart(graph: FlowchartGraph): string;
87
+ /** Bidirectional converter for Mermaid flowchart format. */
88
+ declare const mermaidFlowchartConverter: GraphFormatConverter<string>;
89
+ //#endregion
90
+ //#region src/formats/mermaid/state.d.ts
91
+ interface StateNodeData {
92
+ description?: string;
93
+ stateType?: 'choice' | 'fork' | 'join';
94
+ notes?: Array<{
95
+ position: 'left' | 'right';
96
+ text: string;
97
+ }>;
98
+ isStart?: boolean;
99
+ isEnd?: boolean;
100
+ }
101
+ interface StateEdgeData {}
102
+ interface StateGraphData {
103
+ diagramType: 'stateDiagram';
104
+ }
105
+ type StateGraph = Graph<StateNodeData, StateEdgeData, StateGraphData>;
106
+ declare function fromMermaidState(input: string): StateGraph;
107
+ declare function toMermaidState(graph: StateGraph): string;
108
+ /** Bidirectional converter for Mermaid state diagram format. */
109
+ declare const mermaidStateConverter: GraphFormatConverter<string>;
110
+ //#endregion
111
+ //#region src/formats/mermaid/class-diagram.d.ts
112
+ interface ClassNodeData {
113
+ members?: Array<{
114
+ visibility: '+' | '-' | '#' | '~';
115
+ name: string;
116
+ type?: string;
117
+ isMethod: boolean;
118
+ }>;
119
+ annotation?: string;
120
+ genericType?: string;
121
+ }
122
+ interface ClassEdgeData {
123
+ relationType: 'inheritance' | 'composition' | 'aggregation' | 'association' | 'dependency' | 'realization' | 'link' | 'dashed';
124
+ sourceCardinality?: string;
125
+ targetCardinality?: string;
126
+ }
127
+ interface ClassGraphData {
128
+ diagramType: 'classDiagram';
129
+ }
130
+ type ClassGraph = Graph<ClassNodeData, ClassEdgeData, ClassGraphData>;
131
+ declare function fromMermaidClass(input: string): ClassGraph;
132
+ declare function toMermaidClass(graph: ClassGraph): string;
133
+ /** Bidirectional converter for Mermaid class diagram format. */
134
+ declare const mermaidClassConverter: GraphFormatConverter<string>;
135
+ //#endregion
136
+ //#region src/formats/mermaid/er-diagram.d.ts
137
+ interface ERNodeData {
138
+ attributes?: Array<{
139
+ type: string;
140
+ name: string;
141
+ key?: 'PK' | 'FK' | 'UK';
142
+ comment?: string;
143
+ }>;
144
+ }
145
+ interface EREdgeData {
146
+ sourceCardinality: 'one' | 'zero-or-one' | 'zero-or-more' | 'one-or-more';
147
+ targetCardinality: 'one' | 'zero-or-one' | 'zero-or-more' | 'one-or-more';
148
+ identifying: boolean;
149
+ }
150
+ interface ERGraphData {
151
+ diagramType: 'erDiagram';
152
+ }
153
+ type ERGraph = Graph<ERNodeData, EREdgeData, ERGraphData>;
154
+ declare function fromMermaidER(input: string): ERGraph;
155
+ declare function toMermaidER(graph: ERGraph): string;
156
+ /** Bidirectional converter for Mermaid ER diagram format. */
157
+ declare const mermaidERConverter: GraphFormatConverter<string>;
158
+ //#endregion
159
+ //#region src/formats/mermaid/mindmap.d.ts
160
+ interface MindmapNodeData {
161
+ icon?: string;
162
+ }
163
+ interface MindmapEdgeData {}
164
+ interface MindmapGraphData {
165
+ diagramType: 'mindmap';
166
+ }
167
+ type MindmapGraph = Graph<MindmapNodeData, MindmapEdgeData, MindmapGraphData>;
168
+ declare function fromMermaidMindmap(input: string): MindmapGraph;
169
+ declare function toMermaidMindmap(graph: MindmapGraph): string;
170
+ /** Bidirectional converter for Mermaid mindmap format. */
171
+ declare const mermaidMindmapConverter: GraphFormatConverter<string>;
172
+ //#endregion
173
+ //#region src/formats/mermaid/block.d.ts
174
+ interface BlockNodeData {
175
+ span?: number;
176
+ }
177
+ interface BlockEdgeData {}
178
+ interface BlockGraphData {
179
+ diagramType: 'block';
180
+ columns?: number;
181
+ }
182
+ type BlockGraph = Graph<BlockNodeData, BlockEdgeData, BlockGraphData>;
183
+ declare function fromMermaidBlock(input: string): BlockGraph;
184
+ declare function toMermaidBlock(graph: BlockGraph): string;
185
+ /** Bidirectional converter for Mermaid block diagram format. */
186
+ declare const mermaidBlockConverter: GraphFormatConverter<string>;
187
+ //#endregion
188
+ 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 };