@statelyai/graph 1.0.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 +55 -26
- package/dist/{adjacency-list-VsUaH9SJ.mjs → adjacency-list-GeL1Cu-L.mjs} +3 -1
- package/dist/{algorithms-fTqmvhzP.d.mts → algorithms-CsGNehct.d.mts} +137 -2
- package/dist/{algorithms-Ba7o7niK.mjs → algorithms-DF1pSQGv.mjs} +1476 -343
- package/dist/algorithms.d.mts +2 -2
- package/dist/algorithms.mjs +2 -2
- package/dist/{converter-udLITX36.mjs → converter-DyCJJfTe.mjs} +2 -2
- package/dist/format-support.mjs +38 -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 -1
- package/dist/formats/converter/index.mjs +1 -1
- package/dist/formats/cytoscape/index.d.mts +1 -1
- package/dist/formats/cytoscape/index.mjs +3 -1
- package/dist/formats/d2/index.d.mts +1 -1
- package/dist/formats/d2/index.mjs +26 -12
- package/dist/formats/d3/index.d.mts +1 -1
- package/dist/formats/d3/index.mjs +3 -1
- package/dist/formats/dot/index.d.mts +1 -1
- package/dist/formats/dot/index.mjs +22 -6
- 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 +21 -14
- package/dist/formats/gexf/index.d.mts +1 -1
- package/dist/formats/gexf/index.mjs +22 -15
- package/dist/formats/gml/index.d.mts +1 -1
- package/dist/formats/gml/index.mjs +21 -12
- package/dist/formats/graphml/index.d.mts +1 -1
- package/dist/formats/graphml/index.mjs +73 -22
- package/dist/formats/jgf/index.d.mts +1 -1
- package/dist/formats/jgf/index.mjs +5 -2
- package/dist/formats/mermaid/index.d.mts +1 -1
- package/dist/formats/mermaid/index.mjs +49 -12
- package/dist/formats/tgf/index.d.mts +1 -1
- package/dist/formats/tgf/index.mjs +1 -1
- package/dist/formats/xyflow/index.d.mts +1 -1
- package/dist/formats/xyflow/index.mjs +31 -4
- package/dist/{index-D9Kj6Fe3.d.mts → index-D51lJnt2.d.mts} +1 -1
- package/dist/{index-CHoriXZD.d.mts → index-DWmo1mIp.d.mts} +77 -18
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +143 -295
- package/dist/{queries-BlkA1HAN.d.mts → queries-BfXeTXRf.d.mts} +43 -12
- package/dist/queries-KirMDR7e.mjs +980 -0
- package/dist/queries.d.mts +1 -1
- package/dist/queries.mjs +1 -768
- package/dist/schemas.d.mts +1 -1
- package/dist/schemas.mjs +23 -84
- package/dist/{types-3-FS9NV2.d.mts → types-DNYdIU21.d.mts} +54 -5
- package/dist/validate-TtH-x3JV.mjs +190 -0
- package/package.json +13 -3
- package/dist/indexing-DR8M1vBy.mjs +0 -137
- /package/dist/{edge-list-DP4otyPU.mjs → edge-list-BcZ0h6zz.mjs} +0 -0
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,11 @@ 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
|
+
]
|
|
53
61
|
},
|
|
54
62
|
{
|
|
55
63
|
id: "d2",
|
|
@@ -69,6 +77,7 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
69
77
|
"sql_table/class fields map to ports; node.field connections round-trip as sourcePort/targetPort.",
|
|
70
78
|
"Per-edge connectors (->, <-, --, <->) map to edge.mode; the authored glyph is preserved in _d2.arrow.",
|
|
71
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.",
|
|
72
81
|
"d2 has no native edge weight."
|
|
73
82
|
]
|
|
74
83
|
},
|
|
@@ -115,7 +124,11 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
115
124
|
weight: "full",
|
|
116
125
|
roundTrip: "full"
|
|
117
126
|
},
|
|
118
|
-
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
|
+
]
|
|
119
132
|
},
|
|
120
133
|
{
|
|
121
134
|
id: "gexf",
|
|
@@ -149,7 +162,11 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
149
162
|
weight: "full",
|
|
150
163
|
roundTrip: "full"
|
|
151
164
|
},
|
|
152
|
-
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
|
+
]
|
|
153
170
|
},
|
|
154
171
|
{
|
|
155
172
|
id: "graphml",
|
|
@@ -162,11 +179,13 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
162
179
|
visual: "partial",
|
|
163
180
|
style: "partial",
|
|
164
181
|
weight: "full",
|
|
165
|
-
roundTrip: "
|
|
182
|
+
roundTrip: "full"
|
|
166
183
|
},
|
|
167
184
|
notes: [
|
|
168
|
-
"
|
|
169
|
-
"
|
|
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.",
|
|
170
189
|
"Per-edge directedness round-trips via the `directed` edge attribute; bidirectional maps to directed."
|
|
171
190
|
]
|
|
172
191
|
},
|
|
@@ -183,7 +202,11 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
183
202
|
weight: "full",
|
|
184
203
|
roundTrip: "full"
|
|
185
204
|
},
|
|
186
|
-
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
|
+
]
|
|
187
210
|
},
|
|
188
211
|
{
|
|
189
212
|
id: "tgf",
|
|
@@ -213,7 +236,7 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
213
236
|
weight: "full",
|
|
214
237
|
roundTrip: "full"
|
|
215
238
|
},
|
|
216
|
-
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."]
|
|
217
240
|
},
|
|
218
241
|
{
|
|
219
242
|
id: "mermaid/block",
|
|
@@ -331,9 +354,13 @@ const FORMAT_SUPPORT_MATRIX = [
|
|
|
331
354
|
visual: "partial",
|
|
332
355
|
style: "partial",
|
|
333
356
|
weight: "none",
|
|
334
|
-
roundTrip: "
|
|
357
|
+
roundTrip: "partial"
|
|
335
358
|
},
|
|
336
|
-
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
|
+
]
|
|
337
364
|
}
|
|
338
365
|
];
|
|
339
366
|
function getFormatSupportEntry(id) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../index-
|
|
1
|
+
import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../index-D51lJnt2.mjs";
|
|
2
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
|
/**
|
|
@@ -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;
|
|
@@ -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 },
|
|
@@ -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/d2/shared.ts
|
|
4
4
|
/** Map a d2 connector glyph to a graph edge mode. */
|
|
@@ -800,6 +800,17 @@ function fromD2(input) {
|
|
|
800
800
|
//#endregion
|
|
801
801
|
//#region src/formats/d2/emitter.ts
|
|
802
802
|
const STRUCTURED_SHAPES = new Set(["sql_table", "class"]);
|
|
803
|
+
/**
|
|
804
|
+
* Parser-shaped node data, tolerating graphs not produced by `fromD2` whose
|
|
805
|
+
* `data` may be `undefined`, `null`, or an arbitrary user object.
|
|
806
|
+
*/
|
|
807
|
+
function nodeData(node) {
|
|
808
|
+
return node.data ?? {};
|
|
809
|
+
}
|
|
810
|
+
/** Parser-shaped edge data; see {@link nodeData}. */
|
|
811
|
+
function edgeData(edge) {
|
|
812
|
+
return edge.data ?? {};
|
|
813
|
+
}
|
|
803
814
|
function splitId(id) {
|
|
804
815
|
const out = [];
|
|
805
816
|
let buf = "";
|
|
@@ -835,7 +846,7 @@ function emitComments(comments, ind, lines) {
|
|
|
835
846
|
}
|
|
836
847
|
function nodeAttrLines(node, ind) {
|
|
837
848
|
const lines = [];
|
|
838
|
-
const d = node
|
|
849
|
+
const d = nodeData(node);
|
|
839
850
|
if (node.shape) lines.push(`${indent(ind)}shape: ${escapeD2Label(node.shape)}`);
|
|
840
851
|
if (d.near) lines.push(`${indent(ind)}near: ${escapeD2Label(d.near)}`);
|
|
841
852
|
if (d.icon) lines.push(`${indent(ind)}icon: ${d.icon}`);
|
|
@@ -869,7 +880,8 @@ function portLines(node, ind) {
|
|
|
869
880
|
}
|
|
870
881
|
function labelHeader(node) {
|
|
871
882
|
if (node.label == null || node.label === "") return "";
|
|
872
|
-
|
|
883
|
+
const labelBlock = nodeData(node).labelBlock;
|
|
884
|
+
if (labelBlock) return emitLabelBlock(node.label, labelBlock);
|
|
873
885
|
return escapeD2Label(node.label);
|
|
874
886
|
}
|
|
875
887
|
/** Whether a node carries its own attributes/ports/label (needs a line of its own). */
|
|
@@ -883,7 +895,7 @@ function hasOwnContent(node) {
|
|
|
883
895
|
*/
|
|
884
896
|
function isPurePrefix(ctx, node) {
|
|
885
897
|
const children = ctx.childrenOf.get(node.id) ?? [];
|
|
886
|
-
return node.
|
|
898
|
+
return nodeData(node).declarationForm !== "block" && children.length > 0 && !hasOwnContent(node);
|
|
887
899
|
}
|
|
888
900
|
/**
|
|
889
901
|
* Emit the items (child nodes + owned edges) of a scope, in `data.order` when
|
|
@@ -893,7 +905,7 @@ function isPurePrefix(ctx, node) {
|
|
|
893
905
|
function emitScope(ctx, container, containerId, scopeSegs, ind, lines) {
|
|
894
906
|
const children = ctx.childrenOf.get(containerId) ?? [];
|
|
895
907
|
const ownedEdges = container ? ctx.edgesByOwner.get(container.id) ?? [] : [];
|
|
896
|
-
const order = container
|
|
908
|
+
const order = container ? nodeData(container).order : void 0;
|
|
897
909
|
if (order) {
|
|
898
910
|
const childById = new Map(children.map((c) => [c.id, c]));
|
|
899
911
|
const edgeById = new Map(ownedEdges.map((e) => [e.id, e]));
|
|
@@ -918,7 +930,7 @@ function emitItem(ctx, node, scopeSegs, ind, lines) {
|
|
|
918
930
|
emitScope(ctx, node, node.id, scopeSegs, ind, lines);
|
|
919
931
|
return;
|
|
920
932
|
}
|
|
921
|
-
emitComments(node.
|
|
933
|
+
emitComments(nodeData(node).commentsBefore, ind, lines);
|
|
922
934
|
const label = labelHeader(node);
|
|
923
935
|
const structured = node.shape && STRUCTURED_SHAPES.has(node.shape);
|
|
924
936
|
const attrLines = nodeAttrLines(node, ind + 1);
|
|
@@ -946,8 +958,9 @@ function endpointRef(nodeId$1, port, scopeSegs) {
|
|
|
946
958
|
}
|
|
947
959
|
function emitEdge(ctx, edge, ind, lines, scoped) {
|
|
948
960
|
ctx.emittedEdges.add(edge.id);
|
|
949
|
-
|
|
950
|
-
|
|
961
|
+
const d = edgeData(edge);
|
|
962
|
+
emitComments(d.commentsBefore, ind, lines);
|
|
963
|
+
const arrow = d.arrow ?? modeToArrow(edge);
|
|
951
964
|
const owner = scoped ? ctx.ownerOfEdge.get(edge.id) : void 0;
|
|
952
965
|
const scopeSegs = owner ? splitId(owner) : [];
|
|
953
966
|
let sId = edge.sourceId;
|
|
@@ -962,7 +975,7 @@ function emitEdge(ctx, edge, ind, lines, scoped) {
|
|
|
962
975
|
const right = endpointRef(tId, tPort, scopeSegs);
|
|
963
976
|
let line = `${indent(ind)}${left} ${arrow} ${right}`;
|
|
964
977
|
if (edge.label != null && edge.label !== "") {
|
|
965
|
-
const lbl =
|
|
978
|
+
const lbl = d.labelBlock ? emitLabelBlock(edge.label, d.labelBlock) : escapeD2Label(edge.label);
|
|
966
979
|
line += `: ${lbl}`;
|
|
967
980
|
}
|
|
968
981
|
const blockLines = edgeBlockLines(edge);
|
|
@@ -975,10 +988,11 @@ function emitEdge(ctx, edge, ind, lines, scoped) {
|
|
|
975
988
|
function edgeBlockLines(edge) {
|
|
976
989
|
const out = [];
|
|
977
990
|
if (edge.style) for (const [k, v] of Object.entries(edge.style)) out.push(`style.${k}: ${styleValueToD2(v)}`);
|
|
978
|
-
const
|
|
991
|
+
const d = edgeData(edge);
|
|
992
|
+
const { sourceArrowhead, targetArrowhead } = d;
|
|
979
993
|
if (sourceArrowhead?.shape) out.push(`source-arrowhead.shape: ${sourceArrowhead.shape}`);
|
|
980
994
|
if (targetArrowhead?.shape) out.push(`target-arrowhead.shape: ${targetArrowhead.shape}`);
|
|
981
|
-
if (
|
|
995
|
+
if (d.reserved) for (const [k, v] of Object.entries(d.reserved)) out.push(`${k}: ${styleValueToD2(v)}`);
|
|
982
996
|
return out;
|
|
983
997
|
}
|
|
984
998
|
function modeToArrow(edge) {
|
|
@@ -999,7 +1013,7 @@ function buildEdgeOwnership(graph) {
|
|
|
999
1013
|
const ownerOfEdge = /* @__PURE__ */ new Map();
|
|
1000
1014
|
const edgeById = new Map(graph.edges.map((e) => [e.id, e]));
|
|
1001
1015
|
for (const node of graph.nodes) {
|
|
1002
|
-
const order = node.
|
|
1016
|
+
const order = nodeData(node).order;
|
|
1003
1017
|
if (!order) continue;
|
|
1004
1018
|
for (const refId of order) {
|
|
1005
1019
|
const edge = edgeById.get(refId);
|
|
@@ -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/d3/index.ts
|
|
4
4
|
/**
|
|
@@ -49,6 +49,7 @@ function toD3Graph(graph) {
|
|
|
49
49
|
};
|
|
50
50
|
if (e.id) link.id = e.id;
|
|
51
51
|
if (e.label) link.label = e.label;
|
|
52
|
+
if (e.mode) link.mode = e.mode;
|
|
52
53
|
if (e.data !== void 0) link.data = e.data;
|
|
53
54
|
if (e.weight !== void 0) link.weight = e.weight;
|
|
54
55
|
if (e.x !== void 0) link.x = e.x;
|
|
@@ -109,6 +110,7 @@ function fromD3Graph(d3) {
|
|
|
109
110
|
sourceId: typeof l.source === "string" ? l.source : l.source.id,
|
|
110
111
|
targetId: typeof l.target === "string" ? l.target : l.target.id,
|
|
111
112
|
label: l.label ?? "",
|
|
113
|
+
...l.mode && { mode: l.mode },
|
|
112
114
|
data: l.data,
|
|
113
115
|
...l.weight !== void 0 && { weight: l.weight },
|
|
114
116
|
...l.x !== void 0 && { x: l.x },
|
|
@@ -1,15 +1,31 @@
|
|
|
1
|
-
import { n as createFormatConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter } from "../../converter-DyCJJfTe.mjs";
|
|
2
2
|
import parse from "dotparser";
|
|
3
3
|
|
|
4
4
|
//#region src/formats/dot/index.ts
|
|
5
|
+
/** DOT reserved keywords — must be quoted when used as identifiers. */
|
|
6
|
+
const DOT_KEYWORDS = new Set([
|
|
7
|
+
"node",
|
|
8
|
+
"edge",
|
|
9
|
+
"graph",
|
|
10
|
+
"digraph",
|
|
11
|
+
"subgraph",
|
|
12
|
+
"strict"
|
|
13
|
+
]);
|
|
5
14
|
/** Escape a DOT identifier */
|
|
6
15
|
function escapeId(id) {
|
|
7
|
-
if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(id)) return id;
|
|
16
|
+
if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(id) && !DOT_KEYWORDS.has(id.toLowerCase())) return id;
|
|
8
17
|
return `"${id.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
9
18
|
}
|
|
10
19
|
/** Escape a DOT label string */
|
|
11
20
|
function escapeLabel(label) {
|
|
12
|
-
return label.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
21
|
+
return label.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\n/g, "\\n");
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Invert {@link escapeLabel}. dotparser unescapes `\"` itself but passes
|
|
25
|
+
* `\\` and `\n` through verbatim.
|
|
26
|
+
*/
|
|
27
|
+
function unescapeLabel(label) {
|
|
28
|
+
return label.replace(/\\(\\|n)/g, (_, ch) => ch === "n" ? "\n" : "\\");
|
|
13
29
|
}
|
|
14
30
|
function formatEndpoint(id, port) {
|
|
15
31
|
return `${escapeId(id)}${port ? `:${escapeId(port)}` : ""}`;
|
|
@@ -112,7 +128,7 @@ function nodeFromAttrs(id, attrs, defaults, parentId) {
|
|
|
112
128
|
...defaults,
|
|
113
129
|
...attrs
|
|
114
130
|
};
|
|
115
|
-
const label = merged["label"] ?? "";
|
|
131
|
+
const label = unescapeLabel(merged["label"] ?? "");
|
|
116
132
|
const rawShape = merged["shape"];
|
|
117
133
|
const shape = rawShape ? DOT_TO_SHAPE[rawShape] ?? rawShape : void 0;
|
|
118
134
|
const color = merged["fillcolor"] ?? merged["color"] ?? void 0;
|
|
@@ -235,7 +251,7 @@ function fromDOT(dot) {
|
|
|
235
251
|
id: `e${edgeIdx++}`,
|
|
236
252
|
sourceId: source.id,
|
|
237
253
|
targetId: target.id,
|
|
238
|
-
label: mergedEdgeAttrs["label"] ?? "",
|
|
254
|
+
label: unescapeLabel(mergedEdgeAttrs["label"] ?? ""),
|
|
239
255
|
data: void 0,
|
|
240
256
|
...source.port && { sourcePort: source.port },
|
|
241
257
|
...target.port && { targetPort: target.port },
|
|
@@ -251,7 +267,7 @@ function fromDOT(dot) {
|
|
|
251
267
|
let subLabel = "";
|
|
252
268
|
for (const child of stmt.children) if (child.type === "attr_stmt" && child.target === "graph") {
|
|
253
269
|
const ga = attrsToMap(child.attr_list);
|
|
254
|
-
if (ga["label"]) subLabel = ga["label"];
|
|
270
|
+
if (ga["label"]) subLabel = unescapeLabel(ga["label"]);
|
|
255
271
|
}
|
|
256
272
|
const subNode = {
|
|
257
273
|
type: "node",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { L as VisualGraphFormatConverter, P as VisualGraph } from "../../types-DNYdIU21.mjs";
|
|
2
2
|
import { ElkEdge, ElkEdgeSection, ElkExtendedEdge, ElkGraphElement, ElkLabel, ElkNode, ElkNode as ElkNode$1, ElkPoint, ElkPort, ElkPrimitiveEdge, ElkShape, LayoutOptions } from "elkjs/lib/elk-api";
|
|
3
3
|
|
|
4
4
|
//#region src/formats/elk/index.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getChildren } from "../../queries.mjs";
|
|
1
|
+
import { n as getChildren } from "../../queries-KirMDR7e.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/elk/index.ts
|
|
4
4
|
const STATELYAI_METADATA_KEY = "statelyai.metadata";
|
|
@@ -33,8 +33,8 @@ const ELK_TO_DIRECTION = {
|
|
|
33
33
|
function convertEdge(edge) {
|
|
34
34
|
const elkEdge = {
|
|
35
35
|
id: edge.id,
|
|
36
|
-
sources: [edge.sourcePort
|
|
37
|
-
targets: [edge.targetPort
|
|
36
|
+
sources: [edge.sourcePort != null ? `${edge.sourceId}__${edge.sourcePort}` : edge.sourceId],
|
|
37
|
+
targets: [edge.targetPort != null ? `${edge.targetId}__${edge.targetPort}` : edge.targetId]
|
|
38
38
|
};
|
|
39
39
|
if (edge.label) elkEdge.labels = [{ text: edge.label }];
|
|
40
40
|
return addMetadata(elkEdge, { edge: {
|
|
@@ -43,6 +43,7 @@ function convertEdge(edge) {
|
|
|
43
43
|
sourcePort: edge.sourcePort,
|
|
44
44
|
targetPort: edge.targetPort,
|
|
45
45
|
label: edge.label,
|
|
46
|
+
mode: edge.mode,
|
|
46
47
|
data: edge.data,
|
|
47
48
|
weight: edge.weight,
|
|
48
49
|
color: edge.color,
|
|
@@ -53,9 +54,9 @@ function convertEdge(edge) {
|
|
|
53
54
|
height: edge.height
|
|
54
55
|
} });
|
|
55
56
|
}
|
|
56
|
-
function convertPort(port) {
|
|
57
|
+
function convertPort(nodeId, port) {
|
|
57
58
|
const elkPort = {
|
|
58
|
-
id: port.name
|
|
59
|
+
id: `${nodeId}__${port.name}`,
|
|
59
60
|
x: port.x,
|
|
60
61
|
y: port.y,
|
|
61
62
|
width: port.width,
|
|
@@ -64,6 +65,7 @@ function convertPort(port) {
|
|
|
64
65
|
if (port.label) elkPort.labels = [{ text: port.label }];
|
|
65
66
|
if (port.direction !== "inout") elkPort.layoutOptions = { "org.eclipse.elk.port.side": port.direction === "in" ? "WEST" : "EAST" };
|
|
66
67
|
return addMetadata(elkPort, { port: {
|
|
68
|
+
name: port.name,
|
|
67
69
|
data: port.data,
|
|
68
70
|
style: port.style
|
|
69
71
|
} });
|
|
@@ -77,7 +79,7 @@ function convertNode(graph, node) {
|
|
|
77
79
|
height: node.height
|
|
78
80
|
};
|
|
79
81
|
if (node.label) elkNode.labels = [{ text: node.label }];
|
|
80
|
-
if (node.ports && node.ports.length > 0) elkNode.ports = node.ports.map(convertPort);
|
|
82
|
+
if (node.ports && node.ports.length > 0) elkNode.ports = node.ports.map((port) => convertPort(node.id, port));
|
|
81
83
|
addMetadata(elkNode, { node: {
|
|
82
84
|
initialNodeId: node.initialNodeId,
|
|
83
85
|
data: node.data,
|
|
@@ -166,14 +168,18 @@ function flattenElkNodes(elkNode, parentId, nodes, edges, edgeIdx, portOwner) {
|
|
|
166
168
|
...metadata?.style !== void 0 && { style: metadata.style }
|
|
167
169
|
};
|
|
168
170
|
if (child.ports && child.ports.length > 0) node.ports = child.ports.map((elkPort) => {
|
|
169
|
-
portOwner.set(elkPort.id, child.id);
|
|
170
171
|
const metadata$1 = readMetadata(elkPort)?.port;
|
|
172
|
+
const portName = metadata$1?.name ?? elkPort.id;
|
|
173
|
+
portOwner.set(elkPort.id, {
|
|
174
|
+
nodeId: child.id,
|
|
175
|
+
portName
|
|
176
|
+
});
|
|
171
177
|
const sideOpt = elkPort.layoutOptions?.["org.eclipse.elk.port.side"];
|
|
172
178
|
let direction = "inout";
|
|
173
179
|
if (sideOpt === "WEST") direction = "in";
|
|
174
180
|
else if (sideOpt === "EAST") direction = "out";
|
|
175
181
|
return {
|
|
176
|
-
name:
|
|
182
|
+
name: portName,
|
|
177
183
|
direction,
|
|
178
184
|
label: elkPort.labels?.[0]?.text,
|
|
179
185
|
data: metadata$1 && "data" in metadata$1 ? metadata$1.data : void 0,
|
|
@@ -189,27 +195,28 @@ function flattenElkNodes(elkNode, parentId, nodes, edges, edgeIdx, portOwner) {
|
|
|
189
195
|
}
|
|
190
196
|
if (elkNode.edges) for (const elkEdge of elkNode.edges) for (const source of elkEdge.sources) for (const target of elkEdge.targets) {
|
|
191
197
|
const metadata = readMetadata(elkEdge)?.edge;
|
|
192
|
-
const
|
|
193
|
-
const
|
|
198
|
+
const sourceOwner = portOwner.get(source);
|
|
199
|
+
const targetOwner = portOwner.get(target);
|
|
194
200
|
const edge = {
|
|
195
201
|
type: "edge",
|
|
196
202
|
id: elkEdge.id ?? `e${edgeIdx.value++}`,
|
|
197
|
-
sourceId: metadata?.sourceId ??
|
|
198
|
-
targetId: metadata?.targetId ??
|
|
203
|
+
sourceId: metadata?.sourceId ?? sourceOwner?.nodeId ?? source,
|
|
204
|
+
targetId: metadata?.targetId ?? targetOwner?.nodeId ?? target,
|
|
199
205
|
label: metadata && "label" in metadata ? metadata.label : elkEdge.labels?.[0]?.text ?? "",
|
|
200
206
|
data: metadata && "data" in metadata ? metadata.data : void 0,
|
|
201
207
|
x: metadata?.x ?? 0,
|
|
202
208
|
y: metadata?.y ?? 0,
|
|
203
209
|
width: metadata?.width ?? 0,
|
|
204
210
|
height: metadata?.height ?? 0,
|
|
211
|
+
...metadata?.mode !== void 0 && { mode: metadata.mode },
|
|
205
212
|
...metadata?.weight !== void 0 && { weight: metadata.weight },
|
|
206
213
|
...metadata?.color !== void 0 && { color: metadata.color },
|
|
207
214
|
...metadata?.style !== void 0 && { style: metadata.style }
|
|
208
215
|
};
|
|
209
216
|
if (metadata && "sourcePort" in metadata) edge.sourcePort = metadata.sourcePort;
|
|
210
|
-
else if (
|
|
217
|
+
else if (sourceOwner) edge.sourcePort = sourceOwner.portName;
|
|
211
218
|
if (metadata && "targetPort" in metadata) edge.targetPort = metadata.targetPort;
|
|
212
|
-
else if (
|
|
219
|
+
else if (targetOwner) edge.targetPort = targetOwner.portName;
|
|
213
220
|
edges.push(edge);
|
|
214
221
|
}
|
|
215
222
|
}
|