@statelyai/graph 0.13.0 → 1.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.
Files changed (55) hide show
  1. package/README.md +3 -1
  2. package/dist/{adjacency-list-Ca0VjKIf.mjs → adjacency-list-VsUaH9SJ.mjs} +2 -2
  3. package/dist/{algorithms-BNDQcHU3.mjs → algorithms-Ba7o7niK.mjs} +29 -25
  4. package/dist/{algorithms-BlM-qoJb.d.mts → algorithms-fTqmvhzP.d.mts} +1 -1
  5. package/dist/algorithms.d.mts +1 -1
  6. package/dist/algorithms.mjs +1 -1
  7. package/dist/{converter-Dspillnn.mjs → converter-udLITX36.mjs} +2 -2
  8. package/dist/{edge-list-gKe8-iRa.mjs → edge-list-DP4otyPU.mjs} +1 -1
  9. package/dist/format-support.mjs +31 -2
  10. package/dist/formats/adjacency-list/index.d.mts +1 -1
  11. package/dist/formats/adjacency-list/index.mjs +1 -1
  12. package/dist/formats/converter/index.d.mts +1 -60
  13. package/dist/formats/converter/index.mjs +1 -1
  14. package/dist/formats/cytoscape/index.d.mts +1 -1
  15. package/dist/formats/cytoscape/index.mjs +3 -3
  16. package/dist/formats/d2/index.d.mts +109 -0
  17. package/dist/formats/d2/index.mjs +1086 -0
  18. package/dist/formats/d3/index.d.mts +2 -2
  19. package/dist/formats/d3/index.mjs +3 -3
  20. package/dist/formats/dot/index.d.mts +1 -1
  21. package/dist/formats/dot/index.mjs +3 -3
  22. package/dist/formats/edge-list/index.d.mts +1 -1
  23. package/dist/formats/edge-list/index.mjs +1 -1
  24. package/dist/formats/elk/index.d.mts +1 -1
  25. package/dist/formats/elk/index.mjs +2 -2
  26. package/dist/formats/gexf/index.d.mts +1 -1
  27. package/dist/formats/gexf/index.mjs +9 -3
  28. package/dist/formats/gml/index.d.mts +1 -1
  29. package/dist/formats/gml/index.mjs +3 -3
  30. package/dist/formats/graphml/index.d.mts +1 -1
  31. package/dist/formats/graphml/index.mjs +11 -4
  32. package/dist/formats/jgf/index.d.mts +1 -1
  33. package/dist/formats/jgf/index.mjs +3 -3
  34. package/dist/formats/mermaid/index.d.mts +1 -1
  35. package/dist/formats/mermaid/index.mjs +9 -9
  36. package/dist/formats/tgf/index.d.mts +1 -1
  37. package/dist/formats/tgf/index.mjs +2 -2
  38. package/dist/formats/xyflow/index.d.mts +1 -1
  39. package/dist/formats/xyflow/index.mjs +2 -2
  40. package/dist/index-CHoriXZD.d.mts +638 -0
  41. package/dist/index-D9Kj6Fe3.d.mts +61 -0
  42. package/dist/index.d.mts +6 -631
  43. package/dist/index.mjs +8 -7
  44. package/dist/mode-D8OnHFBk.mjs +15 -0
  45. package/dist/queries-BlkA1HAN.d.mts +516 -0
  46. package/dist/queries.d.mts +1 -514
  47. package/dist/queries.mjs +17 -15
  48. package/dist/schemas.d.mts +21 -10
  49. package/dist/schemas.mjs +12 -2
  50. package/dist/{types-CnZ01raw.d.mts → types-3-FS9NV2.d.mts} +30 -7
  51. package/package.json +2 -1
  52. package/schemas/edge.schema.json +11 -0
  53. package/schemas/graph.schema.json +24 -3
  54. package/schemas/node.schema.json +6 -0
  55. /package/dist/{indexing-DUl3kTqm.mjs → indexing-DR8M1vBy.mjs} +0 -0
package/README.md CHANGED
@@ -252,7 +252,7 @@ const imported = fromGEXF(gexfXmlString); // GEXF (Gephi)
252
252
 
253
253
  <!-- supported format adapters derived from src/formats/* subdirectories -->
254
254
 
255
- **Supported formats:** Cytoscape.js JSON, D3.js JSON, JSON Graph Format, GEXF, GraphML, GML, TGF, DOT, Mermaid (flowchart, state, sequence, class, ER, mindmap, block, Ishikawa), ELK, xyflow, adjacency list, and edge list.
255
+ **Supported formats:** Cytoscape.js JSON, D3.js JSON, D2, JSON Graph Format, GEXF, GraphML, GML, TGF, DOT, Mermaid (flowchart, state, sequence, class, ER, mindmap, block, Ishikawa), ELK, xyflow, adjacency list, and edge list.
256
256
 
257
257
  Each bidirectional format also has a converter object:
258
258
 
@@ -277,6 +277,7 @@ source information instead of preserving it as metadata.
277
277
  | `adjacency-list` | none | none | none | partial | Connectivity only; edge metadata is lost. |
278
278
  | `cytoscape` | full | full | full | full | Graph, node, and edge metadata round-trip through element data. |
279
279
  | `d3` | full | full | full | full | Graph, node, and edge metadata round-trip through the loose JSON shape. |
280
+ | `d2` | full | full | full | full | D2 syntax, hierarchy, ports, styles, and connector modes round-trip. |
280
281
  | `dot` | partial | partial | partial | partial | Edge port ids round-trip, but `:port:compass` mapping is still incomplete. |
281
282
  | `edge-list` | none | none | none | partial | Endpoints only. |
282
283
  | `elk` | full | full | full | full | Metadata round-trips through reserved layout options. |
@@ -304,6 +305,7 @@ Format-specific docs live alongside the source:
304
305
  - [Adjacency list](./src/formats/adjacency-list/README.md)
305
306
  - [Cytoscape](./src/formats/cytoscape/README.md)
306
307
  - [D3](./src/formats/d3/README.md)
308
+ - [D2](./src/formats/d2/README.md)
307
309
  - [DOT](./src/formats/dot/README.md)
308
310
  - [Edge list](./src/formats/edge-list/README.md)
309
311
  - [ELK](./src/formats/elk/README.md)
@@ -20,7 +20,7 @@ function toAdjacencyList(graph) {
20
20
  for (const node of graph.nodes) adj[node.id] = [];
21
21
  for (const edge of graph.edges) {
22
22
  adj[edge.sourceId]?.push(edge.targetId);
23
- if (graph.type === "undirected") adj[edge.targetId]?.push(edge.sourceId);
23
+ if (graph.mode !== "directed") adj[edge.targetId]?.push(edge.sourceId);
24
24
  }
25
25
  return adj;
26
26
  }
@@ -70,7 +70,7 @@ function fromAdjacencyList(adj, options) {
70
70
  }
71
71
  return {
72
72
  id: options?.id ?? "",
73
- type: directed ? "directed" : "undirected",
73
+ mode: directed ? "directed" : "undirected",
74
74
  initialNodeId: null,
75
75
  nodes,
76
76
  edges,
@@ -1,4 +1,5 @@
1
- import { a as indexUpdateEdgeEndpoints, i as indexReparentNode, n as indexAddEdge, o as invalidateIndex, r as indexAddNode, t as getIndex } from "./indexing-DUl3kTqm.mjs";
1
+ import { a as indexUpdateEdgeEndpoints, i as indexReparentNode, n as indexAddEdge, o as invalidateIndex, r as indexAddNode, t as getIndex } from "./indexing-DR8M1vBy.mjs";
2
+ import { t as getEdgeMode } from "./mode-D8OnHFBk.mjs";
2
3
 
3
4
  //#region src/graph.ts
4
5
  /**
@@ -88,6 +89,7 @@ function createGraphEdge(config) {
88
89
  };
89
90
  if (config.sourcePort !== void 0) edge.sourcePort = config.sourcePort;
90
91
  if (config.targetPort !== void 0) edge.targetPort = config.targetPort;
92
+ if (config.mode !== void 0) edge.mode = config.mode;
91
93
  if (config.weight !== void 0) edge.weight = config.weight;
92
94
  if (config.x !== void 0) edge.x = config.x;
93
95
  if (config.y !== void 0) edge.y = config.y;
@@ -111,7 +113,7 @@ function createGraphEdge(config) {
111
113
  function createGraph(config) {
112
114
  const graph = {
113
115
  id: config?.id ?? "",
114
- type: config?.type ?? "directed",
116
+ mode: config?.mode ?? "directed",
115
117
  initialNodeId: config?.initialNodeId ?? null,
116
118
  nodes: (config?.nodes ?? []).map(createGraphNode),
117
119
  edges: (config?.edges ?? []).map(createGraphEdge),
@@ -244,7 +246,7 @@ function createGraphFromTransition(transition, options) {
244
246
  }
245
247
  return createGraph({
246
248
  id: options.id ?? "",
247
- type: "directed",
249
+ mode: "directed",
248
250
  initialNodeId: initialStateId,
249
251
  nodes,
250
252
  edges
@@ -582,8 +584,9 @@ var GraphInstance = class GraphInstance {
582
584
  get id() {
583
585
  return this.graph.id;
584
586
  }
585
- get type() {
586
- return this.graph.type;
587
+ /** Default directedness for all edges. */
588
+ get mode() {
589
+ return this.graph.mode;
587
590
  }
588
591
  get nodes() {
589
592
  return this.graph.nodes;
@@ -703,9 +706,11 @@ function getNeighborIds$1(graph, nodeId) {
703
706
  const ai = idx.edgeById.get(eid);
704
707
  if (ai !== void 0) ids.push(graph.edges[ai].targetId);
705
708
  }
706
- if (graph.type === "undirected") for (const eid of idx.inEdges.get(nodeId) ?? []) {
709
+ for (const eid of idx.inEdges.get(nodeId) ?? []) {
707
710
  const ai = idx.edgeById.get(eid);
708
- if (ai !== void 0) ids.push(graph.edges[ai].sourceId);
711
+ if (ai === void 0) continue;
712
+ const edge = graph.edges[ai];
713
+ if (getEdgeMode(graph, edge) !== "directed") ids.push(edge.sourceId);
709
714
  }
710
715
  return ids;
711
716
  }
@@ -736,11 +741,11 @@ function getNeighborEdges(graph, nodeId) {
736
741
  });
737
742
  }
738
743
  }
739
- if (graph.type === "undirected") for (const eid of idx.inEdges.get(nodeId) ?? []) {
744
+ for (const eid of idx.inEdges.get(nodeId) ?? []) {
740
745
  const ai = idx.edgeById.get(eid);
741
746
  if (ai !== void 0) {
742
747
  const edge = graph.edges[ai];
743
- result.push({
748
+ if (getEdgeMode(graph, edge) !== "directed") result.push({
744
749
  neighborId: edge.sourceId,
745
750
  edge
746
751
  });
@@ -844,7 +849,6 @@ function bellmanFord(graph, sourceId, getWeight) {
844
849
  const dist = /* @__PURE__ */ new Map();
845
850
  const prev = /* @__PURE__ */ new Map();
846
851
  const effectiveWeight = getWeight ?? ((edge) => edge.weight ?? 1);
847
- const isUndirected = graph.type === "undirected";
848
852
  for (const node of graph.nodes) {
849
853
  dist.set(node.id, Infinity);
850
854
  prev.set(node.id, []);
@@ -857,7 +861,7 @@ function bellmanFord(graph, sourceId, getWeight) {
857
861
  toId: edge.targetId,
858
862
  edge
859
863
  });
860
- if (isUndirected) directedEdges.push({
864
+ if (getEdgeMode(graph, edge) !== "directed") directedEdges.push({
861
865
  fromId: edge.targetId,
862
866
  toId: edge.sourceId,
863
867
  edge
@@ -1021,7 +1025,7 @@ function getCycles(graph) {
1021
1025
  return [...genCycles(graph)];
1022
1026
  }
1023
1027
  function* genCycles(graph) {
1024
- if (graph.type === "undirected") yield* genCyclesUndirected(graph);
1028
+ if (graph.mode !== "directed") yield* genCyclesUndirected(graph);
1025
1029
  else yield* genCyclesDirected(graph);
1026
1030
  }
1027
1031
  function* genCyclesDirected(graph) {
@@ -1160,7 +1164,7 @@ function floydWarshallAllPaths(graph, getWeight) {
1160
1164
  from: source,
1161
1165
  edge
1162
1166
  });
1163
- if (graph.type === "undirected") {
1167
+ if (getEdgeMode(graph, edge) !== "directed") {
1164
1168
  if (edgeWeight < dist[target][source]) {
1165
1169
  dist[target][source] = edgeWeight;
1166
1170
  prev[target][source] = [{
@@ -1318,7 +1322,7 @@ function* dfs(graph, startId) {
1318
1322
  }
1319
1323
  }
1320
1324
  function isAcyclic(graph) {
1321
- if (graph.type === "undirected") return isAcyclicUndirected(graph);
1325
+ if (graph.mode !== "directed") return isAcyclicUndirected(graph);
1322
1326
  const WHITE = 0;
1323
1327
  const GRAY = 1;
1324
1328
  const BLACK = 2;
@@ -1576,7 +1580,7 @@ function getMinimumSpanningTree(graph, opts) {
1576
1580
  const mstEdges = algorithm === "kruskal" ? kruskalMST(graph, getWeight) : primMST(graph, getWeight);
1577
1581
  return createGraph({
1578
1582
  id: graph.id,
1579
- type: graph.type,
1583
+ mode: graph.mode,
1580
1584
  initialNodeId: graph.initialNodeId ?? void 0,
1581
1585
  nodes: graph.nodes.map((node) => ({
1582
1586
  id: node.id,
@@ -1611,7 +1615,7 @@ function primMST(graph, getWeight) {
1611
1615
  edge
1612
1616
  });
1613
1617
  }
1614
- if (graph.type === "undirected") for (const eid of idx.inEdges.get(nodeId) ?? []) {
1618
+ if (graph.mode !== "directed") for (const eid of idx.inEdges.get(nodeId) ?? []) {
1615
1619
  const ai = idx.edgeById.get(eid);
1616
1620
  if (ai === void 0) continue;
1617
1621
  const edge = graph.edges[ai];
@@ -1626,7 +1630,7 @@ function primMST(graph, getWeight) {
1626
1630
  addEdgesOf(startId);
1627
1631
  while (candidates.size > 0 && inMST.size < graph.nodes.length) {
1628
1632
  const { edge } = candidates.pop();
1629
- const targetId = graph.type === "undirected" && inMST.has(edge.targetId) ? edge.sourceId : edge.targetId;
1633
+ const targetId = graph.mode !== "directed" && inMST.has(edge.targetId) ? edge.sourceId : edge.targetId;
1630
1634
  if (inMST.has(targetId)) continue;
1631
1635
  inMST.add(targetId);
1632
1636
  mstEdges.push(edge);
@@ -1675,7 +1679,7 @@ function getNeighborIds(graph, nodeId) {
1675
1679
  const edgeIndex = idx.edgeById.get(edgeId);
1676
1680
  if (edgeIndex !== void 0) neighbors.push(graph.edges[edgeIndex].targetId);
1677
1681
  }
1678
- if (graph.type === "undirected") for (const edgeId of idx.inEdges.get(nodeId) ?? []) {
1682
+ if (graph.mode !== "directed") for (const edgeId of idx.inEdges.get(nodeId) ?? []) {
1679
1683
  const edgeIndex = idx.edgeById.get(edgeId);
1680
1684
  if (edgeIndex !== void 0) neighbors.push(graph.edges[edgeIndex].sourceId);
1681
1685
  }
@@ -1688,7 +1692,7 @@ function getIncomingIds(graph, nodeId) {
1688
1692
  const edgeIndex = idx.edgeById.get(edgeId);
1689
1693
  if (edgeIndex !== void 0) incoming.push(graph.edges[edgeIndex].sourceId);
1690
1694
  }
1691
- if (graph.type === "undirected") for (const edgeId of idx.outEdges.get(nodeId) ?? []) {
1695
+ if (graph.mode !== "directed") for (const edgeId of idx.outEdges.get(nodeId) ?? []) {
1692
1696
  const edgeIndex = idx.edgeById.get(edgeId);
1693
1697
  if (edgeIndex !== void 0) incoming.push(graph.edges[edgeIndex].targetId);
1694
1698
  }
@@ -1741,7 +1745,7 @@ function getDegreeCentrality(graph) {
1741
1745
  for (const node of graph.nodes) {
1742
1746
  const outDegree = idx.outEdges.get(node.id)?.length ?? 0;
1743
1747
  const inDegree = idx.inEdges.get(node.id)?.length ?? 0;
1744
- const degree = graph.type === "undirected" ? new Set([...idx.outEdges.get(node.id) ?? [], ...idx.inEdges.get(node.id) ?? []]).size : outDegree + inDegree;
1748
+ const degree = graph.mode !== "directed" ? new Set([...idx.outEdges.get(node.id) ?? [], ...idx.inEdges.get(node.id) ?? []]).size : outDegree + inDegree;
1745
1749
  scores[node.id] = degree * scale;
1746
1750
  }
1747
1751
  return scores;
@@ -1841,9 +1845,9 @@ function getBetweennessCentrality(graph) {
1841
1845
  }
1842
1846
  const order = graph.nodes.length;
1843
1847
  if (order <= 2) return scores;
1844
- const scale = graph.type === "undirected" ? 1 / ((order - 1) * (order - 2) / 2) : 1 / ((order - 1) * (order - 2));
1848
+ const scale = graph.mode !== "directed" ? 1 / ((order - 1) * (order - 2) / 2) : 1 / ((order - 1) * (order - 2));
1845
1849
  for (const nodeId of Object.keys(scores)) {
1846
- if (graph.type === "undirected") scores[nodeId] /= 2;
1850
+ if (graph.mode !== "directed") scores[nodeId] /= 2;
1847
1851
  scores[nodeId] *= scale;
1848
1852
  }
1849
1853
  return scores;
@@ -2314,11 +2318,11 @@ function getDegreeSignature(graph, nodeId) {
2314
2318
  const idx = getIndex(graph);
2315
2319
  const outDegree = idx.outEdges.get(nodeId)?.length ?? 0;
2316
2320
  const inDegree = idx.inEdges.get(nodeId)?.length ?? 0;
2317
- if (graph.type === "undirected") return `u:${new Set([...idx.outEdges.get(nodeId) ?? [], ...idx.inEdges.get(nodeId) ?? []]).size}`;
2321
+ if (graph.mode !== "directed") return `u:${new Set([...idx.outEdges.get(nodeId) ?? [], ...idx.inEdges.get(nodeId) ?? []]).size}`;
2318
2322
  return `d:${inDegree}:${outDegree}`;
2319
2323
  }
2320
2324
  function getEdgesBetween(graph, sourceId, targetId) {
2321
- if (graph.type === "undirected") return graph.edges.filter((edge) => edge.sourceId === sourceId && edge.targetId === targetId || edge.sourceId === targetId && edge.targetId === sourceId);
2325
+ if (graph.mode !== "directed") return graph.edges.filter((edge) => edge.sourceId === sourceId && edge.targetId === targetId || edge.sourceId === targetId && edge.targetId === sourceId);
2322
2326
  return graph.edges.filter((edge) => edge.sourceId === sourceId && edge.targetId === targetId);
2323
2327
  }
2324
2328
  function edgesAreCompatible(edgesA, edgesB, edgeMatch) {
@@ -2339,7 +2343,7 @@ function edgesAreCompatible(edgesA, edgesB, edgeMatch) {
2339
2343
  * node and edge payloads.
2340
2344
  */
2341
2345
  function isIsomorphic(graphA, graphB, options) {
2342
- if (graphA.type !== graphB.type) return false;
2346
+ if (graphA.mode !== graphB.mode) return false;
2343
2347
  if (graphA.nodes.length !== graphB.nodes.length) return false;
2344
2348
  if (graphA.edges.length !== graphB.edges.length) return false;
2345
2349
  const nodeMatch = options?.nodeMatch;
@@ -1,4 +1,4 @@
1
- import { D as SinglePathOptions, g as GraphNode, k as TraversalOptions, n as AllPairsShortestPathsOptions, p as GraphEdge, t as AStarOptions, u as Graph, v as GraphPath, w as PathOptions, x as MSTOptions } from "./types-CnZ01raw.mjs";
1
+ import { A as TraversalOptions, O as SinglePathOptions, S as MSTOptions, T as PathOptions, _ as GraphNode, n as AllPairsShortestPathsOptions, p as GraphEdge, t as AStarOptions, u as Graph, y as GraphPath } from "./types-3-FS9NV2.mjs";
2
2
 
3
3
  //#region src/algorithms/traversal.d.ts
4
4
  declare function bfs<N>(graph: Graph<N>, startId: string): Generator<GraphNode<N>>;
@@ -1,2 +1,2 @@
1
- import { A as genCycles, B as getStronglyConnectedComponents, C as getMinimumSpanningTree, D as getPostorders, E as getPostorder, F as getCycles, G as getTopologicalSort, H as bfs, I as getShortestPath, J as isConnected, K as hasPath, L as getShortestPaths, M as genSimplePaths, N as getAStarPath, O as getPreorder, P as getAllPairsShortestPaths, R as getSimplePath, S as getPageRank, T as genPreorders, U as dfs, V as joinPaths, W as getConnectedComponents, Y as isTree, _ as getDegreeCentrality, a as getBridges, b as getInDegreeCentrality, c as genGirvanNewmanCommunities, d as getLabelPropagationCommunities, f as getModularity, g as getClosenessCentrality, h as getBetweennessCentrality, i as getBiconnectedComponents, j as genShortestPaths, k as getPreorders, l as getGirvanNewmanCommunities, m as IterativeCentralityOptions, n as isIsomorphic, o as GirvanNewmanOptions, p as HITSResult, q as isAcyclic, r as getArticulationPoints, s as LabelPropagationOptions, t as IsomorphismOptions, u as getGreedyModularityCommunities, v as getEigenvectorCentrality, w as genPostorders, x as getOutDegreeCentrality, y as getHITS, z as getSimplePaths } from "./algorithms-BlM-qoJb.mjs";
1
+ import { A as genCycles, B as getStronglyConnectedComponents, C as getMinimumSpanningTree, D as getPostorders, E as getPostorder, F as getCycles, G as getTopologicalSort, H as bfs, I as getShortestPath, J as isConnected, K as hasPath, L as getShortestPaths, M as genSimplePaths, N as getAStarPath, O as getPreorder, P as getAllPairsShortestPaths, R as getSimplePath, S as getPageRank, T as genPreorders, U as dfs, V as joinPaths, W as getConnectedComponents, Y as isTree, _ as getDegreeCentrality, a as getBridges, b as getInDegreeCentrality, c as genGirvanNewmanCommunities, d as getLabelPropagationCommunities, f as getModularity, g as getClosenessCentrality, h as getBetweennessCentrality, i as getBiconnectedComponents, j as genShortestPaths, k as getPreorders, l as getGirvanNewmanCommunities, m as IterativeCentralityOptions, n as isIsomorphic, o as GirvanNewmanOptions, p as HITSResult, q as isAcyclic, r as getArticulationPoints, s as LabelPropagationOptions, t as IsomorphismOptions, u as getGreedyModularityCommunities, v as getEigenvectorCentrality, w as genPostorders, x as getOutDegreeCentrality, y as getHITS, z as getSimplePaths } from "./algorithms-fTqmvhzP.mjs";
2
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,3 +1,3 @@
1
- import { A as isAcyclic, B as getShortestPaths, C as getPreorder, D as getConnectedComponents, E as dfs, F as genSimplePaths, H as getSimplePaths, I as getAStarPath, L as getAllPairsShortestPaths, M as isTree, N as genCycles, O as getTopologicalSort, P as genShortestPaths, R as getCycles, S as getPostorders, T as bfs, U as getStronglyConnectedComponents, V as getSimplePath, W as joinPaths, _ as getPageRank, a as genGirvanNewmanCommunities, b as genPreorders, c as getLabelPropagationCommunities, d as getClosenessCentrality, f as getDegreeCentrality, g as getOutDegreeCentrality, h as getInDegreeCentrality, i as getBridges, j as isConnected, k as hasPath, l as getModularity, m as getHITS, n as getArticulationPoints, o as getGirvanNewmanCommunities, p as getEigenvectorCentrality, r as getBiconnectedComponents, s as getGreedyModularityCommunities, t as isIsomorphic, u as getBetweennessCentrality, v as getMinimumSpanningTree, w as getPreorders, x as getPostorder, y as genPostorders, z as getShortestPath } from "./algorithms-BNDQcHU3.mjs";
1
+ import { A as isAcyclic, B as getShortestPaths, C as getPreorder, D as getConnectedComponents, E as dfs, F as genSimplePaths, H as getSimplePaths, I as getAStarPath, L as getAllPairsShortestPaths, M as isTree, N as genCycles, O as getTopologicalSort, P as genShortestPaths, R as getCycles, S as getPostorders, T as bfs, U as getStronglyConnectedComponents, V as getSimplePath, W as joinPaths, _ as getPageRank, a as genGirvanNewmanCommunities, b as genPreorders, c as getLabelPropagationCommunities, d as getClosenessCentrality, f as getDegreeCentrality, g as getOutDegreeCentrality, h as getInDegreeCentrality, i as getBridges, j as isConnected, k as hasPath, l as getModularity, m as getHITS, n as getArticulationPoints, o as getGirvanNewmanCommunities, p as getEigenvectorCentrality, r as getBiconnectedComponents, s as getGreedyModularityCommunities, t as isIsomorphic, u as getBetweennessCentrality, v as getMinimumSpanningTree, w as getPreorders, x as getPostorder, y as genPostorders, z as getShortestPath } from "./algorithms-Ba7o7niK.mjs";
2
2
 
3
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 };
@@ -1,5 +1,5 @@
1
- import { n as toAdjacencyList, t as fromAdjacencyList } from "./adjacency-list-Ca0VjKIf.mjs";
2
- import { n as toEdgeList, t as fromEdgeList } from "./edge-list-gKe8-iRa.mjs";
1
+ import { n as toAdjacencyList, t as fromAdjacencyList } from "./adjacency-list-VsUaH9SJ.mjs";
2
+ import { n as toEdgeList, t as fromEdgeList } from "./edge-list-DP4otyPU.mjs";
3
3
 
4
4
  //#region src/formats/converter/index.ts
5
5
  /**
@@ -59,7 +59,7 @@ function fromEdgeList(edges, options) {
59
59
  }));
60
60
  return {
61
61
  id: options?.id ?? "",
62
- type: directed ? "directed" : "undirected",
62
+ mode: directed ? "directed" : "undirected",
63
63
  initialNodeId: null,
64
64
  nodes,
65
65
  edges: edgeObjects,
@@ -51,6 +51,27 @@ const FORMAT_SUPPORT_MATRIX = [
51
51
  },
52
52
  notes: ["Targets force-graph structures, but graph, node, and edge metadata can be preserved on the loose JSON shape.", "Ports round-trip through node/link objects."]
53
53
  },
54
+ {
55
+ id: "d2",
56
+ importPath: "@statelyai/graph/d2",
57
+ features: {
58
+ directed: "full",
59
+ undirected: "full",
60
+ hierarchy: "full",
61
+ ports: "full",
62
+ visual: "full",
63
+ style: "full",
64
+ weight: "none",
65
+ roundTrip: "full"
66
+ },
67
+ notes: [
68
+ "Containers map to hierarchy; dot vs block declaration form is preserved per node.",
69
+ "sql_table/class fields map to ports; node.field connections round-trip as sourcePort/targetPort.",
70
+ "Per-edge connectors (->, <-, --, <->) map to edge.mode; the authored glyph is preserved in _d2.arrow.",
71
+ "vars/classes/imports are preserved on graph data; comments attach to the following entity (best-effort).",
72
+ "d2 has no native edge weight."
73
+ ]
74
+ },
54
75
  {
55
76
  id: "dot",
56
77
  importPath: "@statelyai/graph/dot",
@@ -109,7 +130,11 @@ const FORMAT_SUPPORT_MATRIX = [
109
130
  weight: "full",
110
131
  roundTrip: "full"
111
132
  },
112
- notes: ["Custom attributes preserve graph, node, and edge metadata beyond the standard viz module.", "Ports round-trip via custom node/edge attributes."]
133
+ notes: [
134
+ "Custom attributes preserve graph, node, and edge metadata beyond the standard viz module.",
135
+ "Ports round-trip via custom node/edge attributes.",
136
+ "Per-edge directedness round-trips via the `type` edge attribute; bidirectional maps to directed."
137
+ ]
113
138
  },
114
139
  {
115
140
  id: "gml",
@@ -139,7 +164,11 @@ const FORMAT_SUPPORT_MATRIX = [
139
164
  weight: "full",
140
165
  roundTrip: "partial"
141
166
  },
142
- notes: ["GraphML attribute fidelity is good, but not every extension is represented.", "Ports round-trip through node and edge `<data>` fields."]
167
+ notes: [
168
+ "GraphML attribute fidelity is good, but not every extension is represented.",
169
+ "Ports round-trip through node and edge `<data>` fields.",
170
+ "Per-edge directedness round-trips via the `directed` edge attribute; bidirectional maps to directed."
171
+ ]
143
172
  },
144
173
  {
145
174
  id: "jgf",
@@ -1,4 +1,4 @@
1
- import { u as Graph } from "../../types-CnZ01raw.mjs";
1
+ import { u as Graph } from "../../types-3-FS9NV2.mjs";
2
2
 
3
3
  //#region src/formats/adjacency-list/index.d.ts
4
4
 
@@ -1,3 +1,3 @@
1
- import { n as toAdjacencyList, t as fromAdjacencyList } from "../../adjacency-list-Ca0VjKIf.mjs";
1
+ import { n as toAdjacencyList, t as fromAdjacencyList } from "../../adjacency-list-VsUaH9SJ.mjs";
2
2
 
3
3
  export { fromAdjacencyList, toAdjacencyList };
@@ -1,61 +1,2 @@
1
- import { h as GraphFormatConverter, u as Graph } from "../../types-CnZ01raw.mjs";
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-D9Kj6Fe3.mjs";
61
2
  export { adjacencyListConverter, createFormatConverter, edgeListConverter };
@@ -1,3 +1,3 @@
1
- import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../converter-Dspillnn.mjs";
1
+ import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../converter-udLITX36.mjs";
2
2
 
3
3
  export { adjacencyListConverter, createFormatConverter, edgeListConverter };
@@ -1,4 +1,4 @@
1
- import { h as GraphFormatConverter, u as Graph } from "../../types-CnZ01raw.mjs";
1
+ import { h as GraphFormatConverter, u as Graph } from "../../types-3-FS9NV2.mjs";
2
2
 
3
3
  //#region src/formats/cytoscape/index.d.ts
4
4
  interface CytoscapeNode {
@@ -1,4 +1,4 @@
1
- import { n as createFormatConverter } from "../../converter-Dspillnn.mjs";
1
+ import { n as createFormatConverter } from "../../converter-udLITX36.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.type = graph.type;
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;
@@ -92,7 +92,7 @@ function fromCytoscapeJSON(cyto) {
92
92
  if (!Array.isArray(cyto.elements.edges)) throw new Error("Cytoscape: \"elements.edges\" must be an array");
93
93
  return {
94
94
  id: cyto.data?.id ?? "",
95
- type: cyto.data?.type === "undirected" ? "undirected" : "directed",
95
+ mode: cyto.data?.mode ?? "directed",
96
96
  initialNodeId: cyto.data?.initialNodeId ?? null,
97
97
  data: cyto.data?.graphData,
98
98
  ...cyto.data?.direction && { direction: cyto.data.direction },
@@ -0,0 +1,109 @@
1
+ import { h as GraphFormatConverter, u as Graph } from "../../types-3-FS9NV2.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 };