@statelyai/graph 0.13.0 → 2.0.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.
- package/README.md +57 -26
- package/dist/{adjacency-list-Ca0VjKIf.mjs → adjacency-list-GeL1Cu-L.mjs} +5 -3
- package/dist/{algorithms-BlM-qoJb.d.mts → algorithms-CsGNehct.d.mts} +137 -2
- package/dist/{algorithms-BNDQcHU3.mjs → algorithms-DF1pSQGv.mjs} +1494 -357
- package/dist/algorithms.d.mts +2 -2
- package/dist/algorithms.mjs +2 -2
- package/dist/{converter-Dspillnn.mjs → converter-DyCJJfTe.mjs} +2 -2
- package/dist/{edge-list-gKe8-iRa.mjs → edge-list-BcZ0h6zz.mjs} +1 -1
- package/dist/format-support.mjs +67 -11
- package/dist/formats/adjacency-list/index.d.mts +1 -1
- package/dist/formats/adjacency-list/index.mjs +1 -1
- package/dist/formats/converter/index.d.mts +1 -60
- package/dist/formats/converter/index.mjs +1 -1
- package/dist/formats/cytoscape/index.d.mts +1 -1
- package/dist/formats/cytoscape/index.mjs +5 -3
- package/dist/formats/d2/index.d.mts +109 -0
- package/dist/formats/d2/index.mjs +1100 -0
- package/dist/formats/d3/index.d.mts +2 -2
- package/dist/formats/d3/index.mjs +5 -3
- package/dist/formats/dot/index.d.mts +1 -1
- package/dist/formats/dot/index.mjs +24 -8
- package/dist/formats/edge-list/index.d.mts +1 -1
- package/dist/formats/edge-list/index.mjs +1 -1
- package/dist/formats/elk/index.d.mts +1 -1
- package/dist/formats/elk/index.mjs +23 -16
- package/dist/formats/gexf/index.d.mts +1 -1
- package/dist/formats/gexf/index.mjs +30 -17
- package/dist/formats/gml/index.d.mts +1 -1
- package/dist/formats/gml/index.mjs +22 -13
- package/dist/formats/graphml/index.d.mts +1 -1
- package/dist/formats/graphml/index.mjs +83 -25
- package/dist/formats/jgf/index.d.mts +1 -1
- package/dist/formats/jgf/index.mjs +6 -3
- package/dist/formats/mermaid/index.d.mts +1 -1
- package/dist/formats/mermaid/index.mjs +57 -20
- package/dist/formats/tgf/index.d.mts +1 -1
- package/dist/formats/tgf/index.mjs +2 -2
- package/dist/formats/xyflow/index.d.mts +1 -1
- package/dist/formats/xyflow/index.mjs +33 -6
- package/dist/index-D51lJnt2.d.mts +61 -0
- package/dist/index-DWmo1mIp.d.mts +697 -0
- package/dist/index.d.mts +6 -631
- package/dist/index.mjs +144 -295
- package/dist/mode-D8OnHFBk.mjs +15 -0
- package/dist/queries-BfXeTXRf.d.mts +547 -0
- package/dist/queries-KirMDR7e.mjs +980 -0
- package/dist/queries.d.mts +1 -514
- package/dist/queries.mjs +1 -766
- package/dist/schemas.d.mts +21 -10
- package/dist/schemas.mjs +35 -86
- package/dist/{types-CnZ01raw.d.mts → types-DNYdIU21.d.mts} +83 -11
- package/dist/validate-TtH-x3JV.mjs +190 -0
- package/package.json +14 -3
- package/schemas/edge.schema.json +11 -0
- package/schemas/graph.schema.json +24 -3
- package/schemas/node.schema.json +6 -0
- package/dist/indexing-DUl3kTqm.mjs +0 -137
package/dist/algorithms.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { GirvanNewmanOptions, HITSResult, IsomorphismOptions, IterativeCentralityOptions, LabelPropagationOptions, bfs, dfs, genCycles, genGirvanNewmanCommunities, genPostorders, genPreorders, genShortestPaths, genSimplePaths, getAStarPath, getAllPairsShortestPaths, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getClosenessCentrality, getConnectedComponents, getCycles, getDegreeCentrality, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegreeCentrality, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getOutDegreeCentrality, getPageRank, getPostorder, getPostorders, getPreorder, getPreorders, getShortestPath, getShortestPaths, getSimplePath, getSimplePaths, getStronglyConnectedComponents, getTopologicalSort, hasPath, isAcyclic, isConnected, isIsomorphic, isTree, joinPaths };
|
|
1
|
+
import { $ as getTopologicalSort, A as getPageRank, B as genSimplePaths, C as getBetweennessCentrality, D as getHITS, E as getEigenvectorCentrality, F as getPostorders, G as getShortestPaths, H as getAllPairsShortestPaths, I as getPreorder, J as getStronglyConnectedComponents, K as getSimplePath, L as getPreorders, M as genPostorders, N as genPreorders, O as getInDegreeCentrality, P as getPostorder, Q as getConnectedComponents, R as genCycles, S as IterativeCentralityOptions, T as getDegreeCentrality, U as getCycles, V as getAStarPath, W as getShortestPath, X as bfs, Y as joinPaths, Z as dfs, _ as getGirvanNewmanCommunities, a as MaxFlowResult, b as getModularity, c as getLouvainCommunities, d as getArticulationPoints, et as hasPath, f as getBiconnectedComponents, g as genGirvanNewmanCommunities, h as LabelPropagationOptions, i as MaxFlowOptions, j as getMinimumSpanningTree, k as getOutDegreeCentrality, l as IsomorphismOptions, m as GirvanNewmanOptions, n as DominatorTreeOptions, nt as isConnected, o as getMaxFlow, p as getBridges, q as getSimplePaths, r as getDominatorTree, rt as isTree, s as LouvainOptions, t as getTransitiveReduction, tt as isAcyclic, u as isIsomorphic, v as getGreedyModularityCommunities, w as getClosenessCentrality, x as HITSResult, y as getLabelPropagationCommunities, z as genShortestPaths } from "./algorithms-CsGNehct.mjs";
|
|
2
|
+
export { DominatorTreeOptions, GirvanNewmanOptions, HITSResult, IsomorphismOptions, IterativeCentralityOptions, LabelPropagationOptions, LouvainOptions, MaxFlowOptions, MaxFlowResult, bfs, dfs, genCycles, genGirvanNewmanCommunities, genPostorders, genPreorders, genShortestPaths, genSimplePaths, getAStarPath, getAllPairsShortestPaths, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getClosenessCentrality, getConnectedComponents, getCycles, getDegreeCentrality, getDominatorTree, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegreeCentrality, getLabelPropagationCommunities, getLouvainCommunities, getMaxFlow, getMinimumSpanningTree, getModularity, getOutDegreeCentrality, getPageRank, getPostorder, getPostorders, getPreorder, getPreorders, getShortestPath, getShortestPaths, getSimplePath, getSimplePaths, getStronglyConnectedComponents, getTopologicalSort, getTransitiveReduction, hasPath, isAcyclic, isConnected, isIsomorphic, isTree, joinPaths };
|
package/dist/algorithms.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as joinPaths, A as dfs, C as genPostorders, D as getPreorder, E as getPostorders, F as isConnected, G as getAStarPath, H as genCycles, I as isTree, J as getShortestPath, K as getAllPairsShortestPaths, M as getTopologicalSort, N as hasPath, O as getPreorders, P as isAcyclic, Q as getStronglyConnectedComponents, S as getMinimumSpanningTree, T as getPostorder, U as genShortestPaths, W as genSimplePaths, X as getSimplePath, Y as getShortestPaths, Z as getSimplePaths, _ as getEigenvectorCentrality, a as isIsomorphic, b as getOutDegreeCentrality, c as getBridges, d as getGreedyModularityCommunities, f as getLabelPropagationCommunities, g as getDegreeCentrality, h as getClosenessCentrality, i as getLouvainCommunities, j as getConnectedComponents, k as bfs, l as genGirvanNewmanCommunities, m as getBetweennessCentrality, n as getDominatorTree, o as getArticulationPoints, p as getModularity, q as getCycles, r as getMaxFlow, s as getBiconnectedComponents, t as getTransitiveReduction, u as getGirvanNewmanCommunities, v as getHITS, w as genPreorders, x as getPageRank, y as getInDegreeCentrality } from "./algorithms-DF1pSQGv.mjs";
|
|
2
2
|
|
|
3
|
-
export { bfs, dfs, genCycles, genGirvanNewmanCommunities, genPostorders, genPreorders, genShortestPaths, genSimplePaths, getAStarPath, getAllPairsShortestPaths, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getClosenessCentrality, getConnectedComponents, getCycles, getDegreeCentrality, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegreeCentrality, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getOutDegreeCentrality, getPageRank, getPostorder, getPostorders, getPreorder, getPreorders, getShortestPath, getShortestPaths, getSimplePath, getSimplePaths, getStronglyConnectedComponents, getTopologicalSort, hasPath, isAcyclic, isConnected, isIsomorphic, isTree, joinPaths };
|
|
3
|
+
export { bfs, dfs, genCycles, genGirvanNewmanCommunities, genPostorders, genPreorders, genShortestPaths, genSimplePaths, getAStarPath, getAllPairsShortestPaths, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getClosenessCentrality, getConnectedComponents, getCycles, getDegreeCentrality, getDominatorTree, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegreeCentrality, getLabelPropagationCommunities, getLouvainCommunities, getMaxFlow, getMinimumSpanningTree, getModularity, getOutDegreeCentrality, getPageRank, getPostorder, getPostorders, getPreorder, getPreorders, getShortestPath, getShortestPaths, getSimplePath, getSimplePaths, getStronglyConnectedComponents, getTopologicalSort, getTransitiveReduction, hasPath, isAcyclic, isConnected, isIsomorphic, isTree, joinPaths };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as toAdjacencyList, t as fromAdjacencyList } from "./adjacency-list-
|
|
2
|
-
import { n as toEdgeList, t as fromEdgeList } from "./edge-list-
|
|
1
|
+
import { n as toAdjacencyList, t as fromAdjacencyList } from "./adjacency-list-GeL1Cu-L.mjs";
|
|
2
|
+
import { n as toEdgeList, t as fromEdgeList } from "./edge-list-BcZ0h6zz.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/formats/converter/index.ts
|
|
5
5
|
/**
|
package/dist/format-support.mjs
CHANGED
|
@@ -34,7 +34,11 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
34
34
|
weight: "full",
|
|
35
35
|
roundTrip: "full"
|
|
36
36
|
},
|
|
37
|
-
notes: [
|
|
37
|
+
notes: [
|
|
38
|
+
"Uses Cytoscape JSON element data with graph, node, and edge metadata stored in element data.",
|
|
39
|
+
"Ports round-trip through element data as `ports`, `sourcePort`, and `targetPort`.",
|
|
40
|
+
"Per-edge `mode` overrides (including bidirectional) round-trip through element data."
|
|
41
|
+
]
|
|
38
42
|
},
|
|
39
43
|
{
|
|
40
44
|
id: "d3",
|
|
@@ -49,7 +53,33 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
49
53
|
weight: "full",
|
|
50
54
|
roundTrip: "full"
|
|
51
55
|
},
|
|
52
|
-
notes: [
|
|
56
|
+
notes: [
|
|
57
|
+
"Targets force-graph structures, but graph, node, and edge metadata can be preserved on the loose JSON shape.",
|
|
58
|
+
"Ports round-trip through node/link objects.",
|
|
59
|
+
"Per-edge `mode` overrides (including bidirectional) round-trip through link objects."
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: "d2",
|
|
64
|
+
importPath: "@statelyai/graph/d2",
|
|
65
|
+
features: {
|
|
66
|
+
directed: "full",
|
|
67
|
+
undirected: "full",
|
|
68
|
+
hierarchy: "full",
|
|
69
|
+
ports: "full",
|
|
70
|
+
visual: "full",
|
|
71
|
+
style: "full",
|
|
72
|
+
weight: "none",
|
|
73
|
+
roundTrip: "full"
|
|
74
|
+
},
|
|
75
|
+
notes: [
|
|
76
|
+
"Containers map to hierarchy; dot vs block declaration form is preserved per node.",
|
|
77
|
+
"sql_table/class fields map to ports; node.field connections round-trip as sourcePort/targetPort.",
|
|
78
|
+
"Per-edge connectors (->, <-, --, <->) map to edge.mode; the authored glyph is preserved in _d2.arrow.",
|
|
79
|
+
"vars/classes/imports are preserved on graph data; comments attach to the following entity (best-effort).",
|
|
80
|
+
"Only flat key/value vars round-trip; nested sub-blocks inside vars are dropped.",
|
|
81
|
+
"d2 has no native edge weight."
|
|
82
|
+
]
|
|
53
83
|
},
|
|
54
84
|
{
|
|
55
85
|
id: "dot",
|
|
@@ -94,7 +124,11 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
94
124
|
weight: "full",
|
|
95
125
|
roundTrip: "full"
|
|
96
126
|
},
|
|
97
|
-
notes: [
|
|
127
|
+
notes: [
|
|
128
|
+
"ELK-native layout fields are preserved directly; graph, node, port, and edge metadata round-trip through reserved layout options.",
|
|
129
|
+
"Per-edge `mode` overrides (including bidirectional) round-trip through reserved layout options.",
|
|
130
|
+
"Port ids are emitted as `nodeId__portName` so they are document-unique as ELK requires; original port names round-trip through reserved layout options."
|
|
131
|
+
]
|
|
98
132
|
},
|
|
99
133
|
{
|
|
100
134
|
id: "gexf",
|
|
@@ -109,7 +143,11 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
109
143
|
weight: "full",
|
|
110
144
|
roundTrip: "full"
|
|
111
145
|
},
|
|
112
|
-
notes: [
|
|
146
|
+
notes: [
|
|
147
|
+
"Custom attributes preserve graph, node, and edge metadata beyond the standard viz module.",
|
|
148
|
+
"Ports round-trip via custom node/edge attributes.",
|
|
149
|
+
"Per-edge directedness round-trips via the `type` edge attribute; bidirectional maps to directed."
|
|
150
|
+
]
|
|
113
151
|
},
|
|
114
152
|
{
|
|
115
153
|
id: "gml",
|
|
@@ -124,7 +162,11 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
124
162
|
weight: "full",
|
|
125
163
|
roundTrip: "full"
|
|
126
164
|
},
|
|
127
|
-
notes: [
|
|
165
|
+
notes: [
|
|
166
|
+
"GML stores graph, node, and edge metadata directly or as JSON-stringified fields.",
|
|
167
|
+
"Ports round-trip through JSON-stringified node metadata and edge fields.",
|
|
168
|
+
"Per-edge `mode` overrides and graph-level bidirectional mode round-trip through a dialect `mode` key (GML `directed` is binary)."
|
|
169
|
+
]
|
|
128
170
|
},
|
|
129
171
|
{
|
|
130
172
|
id: "graphml",
|
|
@@ -137,9 +179,15 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
137
179
|
visual: "partial",
|
|
138
180
|
style: "partial",
|
|
139
181
|
weight: "full",
|
|
140
|
-
roundTrip: "
|
|
182
|
+
roundTrip: "full"
|
|
141
183
|
},
|
|
142
|
-
notes: [
|
|
184
|
+
notes: [
|
|
185
|
+
"Emit is own-dialect: a flat structure with hierarchy, ports, and metadata in `<data>` fields; the emitter does not write nested `<graph>` or native `<port>` elements.",
|
|
186
|
+
"Import handles both dialects: own-dialect `<data>` fields plus standard nested `<graph>` hierarchy, native `<port>` elements (imported as direction `inout`), and `sourceport`/`targetport` edge attributes. `<data>` fields take precedence.",
|
|
187
|
+
"Multi-graph documents import the first `<graph>` element only.",
|
|
188
|
+
"Vendor extensions (e.g. yEd visual attributes) are not represented.",
|
|
189
|
+
"Per-edge directedness round-trips via the `directed` edge attribute; bidirectional maps to directed."
|
|
190
|
+
]
|
|
143
191
|
},
|
|
144
192
|
{
|
|
145
193
|
id: "jgf",
|
|
@@ -154,7 +202,11 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
154
202
|
weight: "full",
|
|
155
203
|
roundTrip: "full"
|
|
156
204
|
},
|
|
157
|
-
notes: [
|
|
205
|
+
notes: [
|
|
206
|
+
"JGF preserves graph, node, and edge metadata via `metadata` objects.",
|
|
207
|
+
"Ports round-trip through node and edge metadata.",
|
|
208
|
+
"Per-edge `mode` overrides and graph-level bidirectional mode round-trip through `metadata` (JGF `directed` is binary)."
|
|
209
|
+
]
|
|
158
210
|
},
|
|
159
211
|
{
|
|
160
212
|
id: "tgf",
|
|
@@ -184,7 +236,7 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
184
236
|
weight: "full",
|
|
185
237
|
roundTrip: "full"
|
|
186
238
|
},
|
|
187
|
-
notes: ["xyflow-native fields are preserved directly; graph, node, edge, style, weight, and
|
|
239
|
+
notes: ["xyflow-native fields are preserved directly; graph, node, edge, style, weight, port, and per-edge `mode` metadata round-trip through reserved data fields."]
|
|
188
240
|
},
|
|
189
241
|
{
|
|
190
242
|
id: "mermaid/block",
|
|
@@ -302,9 +354,13 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
302
354
|
visual: "partial",
|
|
303
355
|
style: "partial",
|
|
304
356
|
weight: "none",
|
|
305
|
-
roundTrip: "
|
|
357
|
+
roundTrip: "partial"
|
|
306
358
|
},
|
|
307
|
-
notes: [
|
|
359
|
+
notes: [
|
|
360
|
+
"State-specific syntax such as notes, classes, descriptions, directions, hierarchy, and parallel regions round-trips through node and graph data.",
|
|
361
|
+
"Isolated plain states emit as bare state lines, and node labels emit via the `state \"label\" as id` description form — a distinct label is lost when a description is also present.",
|
|
362
|
+
"`graph.initialNodeId` round-trips as a top-level `[*] -->` transition."
|
|
363
|
+
]
|
|
308
364
|
}
|
|
309
365
|
];
|
|
310
366
|
function getFormatSupportEntry(id) {
|
|
@@ -1,61 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/formats/converter/index.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Create a `GraphFormatConverter` from a pair of `to`/`from` functions.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* import { createFormatConverter } from '@statelyai/graph';
|
|
11
|
-
*
|
|
12
|
-
* const yamlConverter = createFormatConverter(
|
|
13
|
-
* (graph) => toYAML(graph),
|
|
14
|
-
* (yaml) => fromYAML(yaml),
|
|
15
|
-
* );
|
|
16
|
-
*
|
|
17
|
-
* const yaml = yamlConverter.to(graph);
|
|
18
|
-
* const graph = yamlConverter.from(yaml);
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
declare function createFormatConverter<TSerial, N = any, E = any, G = any>(to: (graph: Graph<N, E, G>) => TSerial, from: (input: TSerial) => Graph<N, E, G>): GraphFormatConverter<TSerial, N, E, G>;
|
|
22
|
-
/**
|
|
23
|
-
* Bidirectional converter for adjacency-list format (`Record<string, string[]>`).
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* import { adjacencyListConverter, createGraph } from '@statelyai/graph';
|
|
28
|
-
*
|
|
29
|
-
* const graph = createGraph({
|
|
30
|
-
* nodes: { a: {}, b: {} },
|
|
31
|
-
* edges: [{ source: 'a', target: 'b' }],
|
|
32
|
-
* });
|
|
33
|
-
*
|
|
34
|
-
* const adj = adjacencyListConverter.to(graph);
|
|
35
|
-
* // { a: ['b'], b: [] }
|
|
36
|
-
*
|
|
37
|
-
* const roundTripped = adjacencyListConverter.from(adj);
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
declare const adjacencyListConverter: GraphFormatConverter<Record<string, string[]>>;
|
|
41
|
-
/**
|
|
42
|
-
* Bidirectional converter for edge-list format (`[source, target][]`).
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* import { edgeListConverter, createGraph } from '@statelyai/graph';
|
|
47
|
-
*
|
|
48
|
-
* const graph = createGraph({
|
|
49
|
-
* nodes: { a: {}, b: {} },
|
|
50
|
-
* edges: [{ source: 'a', target: 'b' }],
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* const edges = edgeListConverter.to(graph);
|
|
54
|
-
* // [['a', 'b']]
|
|
55
|
-
*
|
|
56
|
-
* const roundTripped = edgeListConverter.from(edges);
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
declare const edgeListConverter: GraphFormatConverter<[string, string][]>;
|
|
60
|
-
//#endregion
|
|
1
|
+
import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../index-D51lJnt2.mjs";
|
|
61
2
|
export { adjacencyListConverter, createFormatConverter, edgeListConverter };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../converter-DyCJJfTe.mjs";
|
|
2
2
|
|
|
3
3
|
export { adjacencyListConverter, createFormatConverter, edgeListConverter };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createFormatConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter } from "../../converter-DyCJJfTe.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/cytoscape/index.ts
|
|
4
4
|
/**
|
|
@@ -21,7 +21,7 @@ import { n as createFormatConverter } from "../../converter-Dspillnn.mjs";
|
|
|
21
21
|
function toCytoscapeJSON(graph) {
|
|
22
22
|
const graphData = {};
|
|
23
23
|
if (graph.id) graphData.id = graph.id;
|
|
24
|
-
graphData.
|
|
24
|
+
graphData.mode = graph.mode;
|
|
25
25
|
if (graph.initialNodeId) graphData.initialNodeId = graph.initialNodeId;
|
|
26
26
|
if (graph.data !== void 0) graphData.graphData = graph.data;
|
|
27
27
|
if (graph.direction) graphData.direction = graph.direction;
|
|
@@ -55,6 +55,7 @@ function toCytoscapeJSON(graph) {
|
|
|
55
55
|
target: e.targetId
|
|
56
56
|
};
|
|
57
57
|
if (e.label) data.label = e.label;
|
|
58
|
+
if (e.mode) data.mode = e.mode;
|
|
58
59
|
if (e.data !== void 0) data.edgeData = e.data;
|
|
59
60
|
if (e.weight !== void 0) data.weight = e.weight;
|
|
60
61
|
if (e.x !== void 0) data.x = e.x;
|
|
@@ -92,7 +93,7 @@ function fromCytoscapeJSON(cyto) {
|
|
|
92
93
|
if (!Array.isArray(cyto.elements.edges)) throw new Error("Cytoscape: \"elements.edges\" must be an array");
|
|
93
94
|
return {
|
|
94
95
|
id: cyto.data?.id ?? "",
|
|
95
|
-
|
|
96
|
+
mode: cyto.data?.mode ?? "directed",
|
|
96
97
|
initialNodeId: cyto.data?.initialNodeId ?? null,
|
|
97
98
|
data: cyto.data?.graphData,
|
|
98
99
|
...cyto.data?.direction && { direction: cyto.data.direction },
|
|
@@ -121,6 +122,7 @@ function fromCytoscapeJSON(cyto) {
|
|
|
121
122
|
sourceId: e.data.source,
|
|
122
123
|
targetId: e.data.target,
|
|
123
124
|
label: e.data.label ?? "",
|
|
125
|
+
...e.data.mode && { mode: e.data.mode },
|
|
124
126
|
data: e.data.edgeData,
|
|
125
127
|
...e.data.weight !== void 0 && { weight: e.data.weight },
|
|
126
128
|
...e.data.x !== void 0 && { x: e.data.x },
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { d as Graph, g as GraphFormatConverter } from "../../types-DNYdIU21.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/formats/d2/shared.d.ts
|
|
4
|
+
type D2Arrow = '->' | '<-' | '--' | '<->';
|
|
5
|
+
/** Descriptor for a typed/block label (`|md ...|`, `|js ...|`, block strings). */
|
|
6
|
+
interface D2LabelBlock {
|
|
7
|
+
kind: 'md' | 'code' | 'latex' | 'block';
|
|
8
|
+
/** Language tag for code blocks (e.g. `js`, `go`). */
|
|
9
|
+
lang?: string;
|
|
10
|
+
/** The fence delimiter used (`|`, `||`, `` |` ``, etc.), preserved for emit. */
|
|
11
|
+
fence: string;
|
|
12
|
+
}
|
|
13
|
+
interface D2GridSpec {
|
|
14
|
+
rows?: number;
|
|
15
|
+
columns?: number;
|
|
16
|
+
gap?: number;
|
|
17
|
+
verticalGap?: number;
|
|
18
|
+
horizontalGap?: number;
|
|
19
|
+
}
|
|
20
|
+
/** Source-level abstractions preserved from the original d2 text. */
|
|
21
|
+
interface D2Source {
|
|
22
|
+
/** `vars: { ... }` blocks, stored as nested key/value maps. */
|
|
23
|
+
vars?: Record<string, any>;
|
|
24
|
+
/** `classes: { name: { ...style } }` definitions. */
|
|
25
|
+
classes?: Record<string, Record<string, string | number | boolean>>;
|
|
26
|
+
/** `@path` import references in declaration order. */
|
|
27
|
+
imports?: string[];
|
|
28
|
+
}
|
|
29
|
+
interface D2GraphData {
|
|
30
|
+
diagramType: 'd2';
|
|
31
|
+
source?: D2Source;
|
|
32
|
+
/** Comments before any statement / at file top. */
|
|
33
|
+
leadingComments?: string[];
|
|
34
|
+
/** Comments after the last statement. */
|
|
35
|
+
trailingComments?: string[];
|
|
36
|
+
}
|
|
37
|
+
interface D2NodeData {
|
|
38
|
+
/** Whether the author declared this node via dot-path or a `{ }` block. */
|
|
39
|
+
declarationForm?: 'dot' | 'block';
|
|
40
|
+
/** Relative positioning keyword/target (`near: top-center`, `near: a.b`). */
|
|
41
|
+
near?: string;
|
|
42
|
+
/** Icon URL. */
|
|
43
|
+
icon?: string;
|
|
44
|
+
tooltip?: string;
|
|
45
|
+
link?: string;
|
|
46
|
+
/** Names of `classes` applied to this node via `class:`. */
|
|
47
|
+
classes?: string[];
|
|
48
|
+
/** Typed/block label descriptor; absent for plain labels. */
|
|
49
|
+
labelBlock?: D2LabelBlock;
|
|
50
|
+
/** Grid layout spec for grid containers. */
|
|
51
|
+
grid?: D2GridSpec;
|
|
52
|
+
/**
|
|
53
|
+
* Source-order list of direct child node IDs and edge IDs, used by
|
|
54
|
+
* sequence diagrams (and any ordering-sensitive container) to replay
|
|
55
|
+
* statement order on emit.
|
|
56
|
+
*/
|
|
57
|
+
order?: string[];
|
|
58
|
+
/** Comments immediately preceding this node's declaration. */
|
|
59
|
+
commentsBefore?: string[];
|
|
60
|
+
/** Reserved keywords with no canonical/typed home, preserved verbatim. */
|
|
61
|
+
reserved?: Record<string, string | number | boolean>;
|
|
62
|
+
}
|
|
63
|
+
interface D2ArrowheadSpec {
|
|
64
|
+
shape?: string;
|
|
65
|
+
label?: string;
|
|
66
|
+
}
|
|
67
|
+
interface D2EdgeData {
|
|
68
|
+
/** Authored connector glyph, for faithful re-emit (incl. reversed `<-`). */
|
|
69
|
+
arrow: D2Arrow;
|
|
70
|
+
sourceArrowhead?: D2ArrowheadSpec;
|
|
71
|
+
targetArrowhead?: D2ArrowheadSpec;
|
|
72
|
+
classes?: string[];
|
|
73
|
+
labelBlock?: D2LabelBlock;
|
|
74
|
+
commentsBefore?: string[];
|
|
75
|
+
reserved?: Record<string, string | number | boolean>;
|
|
76
|
+
}
|
|
77
|
+
interface D2PortData {
|
|
78
|
+
/** SQL column type (`int`, `varchar`, ...) or class member type. */
|
|
79
|
+
typeName?: string;
|
|
80
|
+
/** SQL constraints (`primary_key`, `foreign_key`, `unique`). */
|
|
81
|
+
constraint?: string[];
|
|
82
|
+
/** Class member visibility marker (`+`, `-`, `#`). */
|
|
83
|
+
visibility?: string;
|
|
84
|
+
/** True when this port came from a `shape: class` member rather than sql_table. */
|
|
85
|
+
classMember?: boolean;
|
|
86
|
+
}
|
|
87
|
+
type D2Graph = Graph<D2NodeData, D2EdgeData, D2GraphData, D2PortData>;
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/formats/d2/parser.d.ts
|
|
90
|
+
declare function fromD2(input: string): D2Graph;
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/formats/d2/emitter.d.ts
|
|
93
|
+
declare function toD2(graph: D2Graph): string;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/formats/d2/index.d.ts
|
|
96
|
+
/**
|
|
97
|
+
* Bidirectional converter for [d2](https://d2lang.com/) diagram syntax.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { d2Converter } from '@statelyai/graph/d2';
|
|
102
|
+
*
|
|
103
|
+
* const graph = d2Converter.from('a -> b: hello');
|
|
104
|
+
* const text = d2Converter.to(graph);
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
declare const d2Converter: GraphFormatConverter<string, D2NodeData, D2EdgeData, D2GraphData>;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { type D2Arrow, type D2ArrowheadSpec, type D2EdgeData, type D2Graph, type D2GraphData, type D2GridSpec, type D2LabelBlock, type D2NodeData, type D2PortData, type D2Source, d2Converter, fromD2, toD2 };
|