@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/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
- import { o as invalidateIndex, t as getIndex } from "./indexing-DUl3kTqm.mjs";
2
- import { $ as createGraphPort, A as isAcyclic, B as getShortestPaths, C as getPreorder, D as getConnectedComponents, E as dfs, F as genSimplePaths, G as GraphInstance, H as getSimplePaths, I as getAStarPath, J as addNode, K as addEdge, L as getAllPairsShortestPaths, M as isTree, N as genCycles, O as getTopologicalSort, P as genShortestPaths, Q as createGraphNode, R as getCycles, S as getPostorders, T as bfs, U as getStronglyConnectedComponents, V as getSimplePath, W as joinPaths, X as createGraphEdge, Y as createGraph, Z as createGraphFromTransition, _ as getPageRank, a as genGirvanNewmanCommunities, at as getNode, b as genPreorders, c as getLabelPropagationCommunities, ct as updateEdge, d as getClosenessCentrality, et as createVisualGraph, f as getDegreeCentrality, g as getOutDegreeCentrality, h as getInDegreeCentrality, i as getBridges, it as getEdge, j as isConnected, k as hasPath, l as getModularity, lt as updateEntities, m as getHITS, n as getArticulationPoints, nt as deleteEntities, o as getGirvanNewmanCommunities, ot as hasEdge, p as getEigenvectorCentrality, q as addEntities, r as getBiconnectedComponents, rt as deleteNode, s as getGreedyModularityCommunities, st as hasNode, t as isIsomorphic, tt as deleteEdge, u as getBetweennessCentrality, ut as updateNode, v as getMinimumSpanningTree, w as getPreorders, x as getPostorder, y as genPostorders, z as getShortestPath } from "./algorithms-BNDQcHU3.mjs";
1
+ import { o as invalidateIndex, t as getIndex } from "./indexing-DR8M1vBy.mjs";
2
+ import { $ as createGraphPort, A as isAcyclic, B as getShortestPaths, C as getPreorder, D as getConnectedComponents, E as dfs, F as genSimplePaths, G as GraphInstance, H as getSimplePaths, I as getAStarPath, J as addNode, K as addEdge, L as getAllPairsShortestPaths, M as isTree, N as genCycles, O as getTopologicalSort, P as genShortestPaths, Q as createGraphNode, R as getCycles, S as getPostorders, T as bfs, U as getStronglyConnectedComponents, V as getSimplePath, W as joinPaths, X as createGraphEdge, Y as createGraph, Z as createGraphFromTransition, _ as getPageRank, a as genGirvanNewmanCommunities, at as getNode, b as genPreorders, c as getLabelPropagationCommunities, ct as updateEdge, d as getClosenessCentrality, et as createVisualGraph, f as getDegreeCentrality, g as getOutDegreeCentrality, h as getInDegreeCentrality, i as getBridges, it as getEdge, j as isConnected, k as hasPath, l as getModularity, lt as updateEntities, m as getHITS, n as getArticulationPoints, nt as deleteEntities, o as getGirvanNewmanCommunities, ot as hasEdge, p as getEigenvectorCentrality, q as addEntities, r as getBiconnectedComponents, rt as deleteNode, s as getGreedyModularityCommunities, st as hasNode, t as isIsomorphic, tt as deleteEdge, u as getBetweennessCentrality, ut as updateNode, v as getMinimumSpanningTree, w as getPreorders, x as getPostorder, y as genPostorders, z as getShortestPath } from "./algorithms-Ba7o7niK.mjs";
3
+ import { n as isEdgeDirected, t as getEdgeMode } from "./mode-D8OnHFBk.mjs";
3
4
  import { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgesBetween, getEdgesByPort, getEdgesOf, getInDegree, getInEdges, getLCA, getNeighbors, getOutDegree, getOutEdges, getParent, getPort, getPorts, getPredecessors, getRelativeDistance, getRelativeDistanceMap, getRoots, getSiblings, getSinks, getSources, getSuccessors, isCompound, isLeaf } from "./queries.mjs";
4
- import { n as createFormatConverter } from "./converter-Dspillnn.mjs";
5
+ import { n as createFormatConverter } from "./converter-udLITX36.mjs";
5
6
 
6
7
  //#region src/equivalence.ts
7
8
  /** Shallow-compare two values, returning true if they differ. */
@@ -541,7 +542,7 @@ function flatten(graph) {
541
542
  }));
542
543
  return createGraph({
543
544
  id: graph.id,
544
- type: graph.type,
545
+ mode: graph.mode,
545
546
  nodes: leafNodes,
546
547
  edges: flatEdges,
547
548
  data: graph.data
@@ -607,7 +608,7 @@ function getSubgraph(graph, nodeIds) {
607
608
  const nodeIdSet = new Set(nodeIds);
608
609
  return createGraph({
609
610
  id: graph.id,
610
- type: graph.type,
611
+ mode: graph.mode,
611
612
  initialNodeId: graph.initialNodeId && nodeIdSet.has(graph.initialNodeId) ? graph.initialNodeId : void 0,
612
613
  nodes: graph.nodes.filter((n) => nodeIdSet.has(n.id)).map((n) => nodeToConfig(n, nodeIdSet)),
613
614
  edges: graph.edges.filter((e) => nodeIdSet.has(e.sourceId) && nodeIdSet.has(e.targetId)).map(edgeToConfig),
@@ -641,7 +642,7 @@ function reverseGraph(graph, filterEdge) {
641
642
  const edges = filterEdge ? graph.edges.filter(filterEdge) : graph.edges;
642
643
  return createGraph({
643
644
  id: graph.id,
644
- type: graph.type,
645
+ mode: graph.mode,
645
646
  initialNodeId: graph.initialNodeId ?? void 0,
646
647
  nodes: graph.nodes.map((n) => nodeToConfig(n)),
647
648
  edges: edges.map((e) => {
@@ -905,4 +906,4 @@ function getCoverage(graph, steps, options) {
905
906
  }
906
907
 
907
908
  //#endregion
908
- export { GraphInstance, LAYOUT_KEYS, addEdge, addEntities, addNode, applyPatches, areEntitiesEqual, bfs, createFormatConverter, createGraph, createGraphEdge, createGraphFromTransition, createGraphNode, createGraphPort, createVisualGraph, deleteEdge, deleteEntities, deleteNode, dfs, flatten, genCycles, genGirvanNewmanCommunities, genPostorders, genPredefinedWalk, genPreorders, genQuickRandomWalk, genRandomWalk, genShortestPaths, genSimplePaths, genWeightedRandomWalk, getAStarPath, getAllPairsShortestPaths, getAncestors, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getChildren, getClosenessCentrality, getConnectedComponents, getCoverage, getCycles, getDegree, getDegreeCentrality, getDepth, getDescendants, getDiff, getEdge, getEdgesBetween, getEdgesByPort, getEdgesOf, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegree, getInDegreeCentrality, getInEdges, getLCA, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getNeighbors, getNode, getOutDegree, getOutDegreeCentrality, getOutEdges, getPageRank, getParent, getPatches, getPort, getPorts, getPostorder, getPostorders, getPredecessors, getPreorder, getPreorders, getRelativeDistance, getRelativeDistanceMap, getRoots, getShortestPath, getShortestPaths, getSiblings, getSimplePath, getSimplePaths, getSinks, getSources, getStronglyConnectedComponents, getSubgraph, getSuccessors, getTopologicalSort, hasEdge, hasNode, hasPath, invalidateIndex, invertDiff, isAcyclic, isCompound, isConnected, isEmptyDiff, isIsomorphic, isLayoutEqual, isLeaf, isNonLayoutEqual, isTree, joinPaths, reverseGraph, takeSteps, takeUntilEdge, takeUntilEdgeCoverage, takeUntilNode, takeUntilNodeCoverage, toDiff, toPatches, updateEdge, updateEntities, updateNode };
909
+ export { GraphInstance, LAYOUT_KEYS, addEdge, addEntities, addNode, applyPatches, areEntitiesEqual, bfs, createFormatConverter, createGraph, createGraphEdge, createGraphFromTransition, createGraphNode, createGraphPort, createVisualGraph, deleteEdge, deleteEntities, deleteNode, dfs, flatten, genCycles, genGirvanNewmanCommunities, genPostorders, genPredefinedWalk, genPreorders, genQuickRandomWalk, genRandomWalk, genShortestPaths, genSimplePaths, genWeightedRandomWalk, getAStarPath, getAllPairsShortestPaths, getAncestors, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getChildren, getClosenessCentrality, getConnectedComponents, getCoverage, getCycles, getDegree, getDegreeCentrality, getDepth, getDescendants, getDiff, getEdge, getEdgeMode, getEdgesBetween, getEdgesByPort, getEdgesOf, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegree, getInDegreeCentrality, getInEdges, getLCA, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getNeighbors, getNode, getOutDegree, getOutDegreeCentrality, getOutEdges, getPageRank, getParent, getPatches, getPort, getPorts, getPostorder, getPostorders, getPredecessors, getPreorder, getPreorders, getRelativeDistance, getRelativeDistanceMap, getRoots, getShortestPath, getShortestPaths, getSiblings, getSimplePath, getSimplePaths, getSinks, getSources, getStronglyConnectedComponents, getSubgraph, getSuccessors, getTopologicalSort, hasEdge, hasNode, hasPath, invalidateIndex, invertDiff, isAcyclic, isCompound, isConnected, isEdgeDirected, isEmptyDiff, isIsomorphic, isLayoutEqual, isLeaf, isNonLayoutEqual, isTree, joinPaths, reverseGraph, takeSteps, takeUntilEdge, takeUntilEdgeCoverage, takeUntilNode, takeUntilNodeCoverage, toDiff, toPatches, updateEdge, updateEntities, updateNode };
@@ -0,0 +1,15 @@
1
+ //#region src/mode.ts
2
+ /**
3
+ * Resolve an edge's effective directedness. Falls back to the graph's
4
+ * {@link Graph.mode} when the edge has no per-edge override.
5
+ */
6
+ function getEdgeMode(graph, edge) {
7
+ return edge.mode ?? graph.mode;
8
+ }
9
+ /** Whether an edge points only from source to target. */
10
+ function isEdgeDirected(graph, edge) {
11
+ return getEdgeMode(graph, edge) === "directed";
12
+ }
13
+
14
+ //#endregion
15
+ export { isEdgeDirected as n, getEdgeMode as t };
@@ -0,0 +1,516 @@
1
+ import { _ as GraphNode, b as GraphPort, p as GraphEdge, u as Graph } from "./types-3-FS9NV2.mjs";
2
+
3
+ //#region src/queries.d.ts
4
+
5
+ /**
6
+ * Returns all edges (incoming + outgoing) connected to a node.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const graph = createGraph({
11
+ * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
12
+ * edges: [
13
+ * { id: 'e1', sourceId: 'a', targetId: 'b' },
14
+ * { id: 'e2', sourceId: 'c', targetId: 'b' },
15
+ * ],
16
+ * });
17
+ * getEdgesOf(graph, 'b');
18
+ * // => [edge e1, edge e2]
19
+ * ```
20
+ */
21
+ declare function getEdgesOf<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
22
+ /**
23
+ * Returns incoming edges to a node.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const graph = createGraph({
28
+ * nodes: [{ id: 'a' }, { id: 'b' }],
29
+ * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
30
+ * });
31
+ * getInEdges(graph, 'b');
32
+ * // => [edge e1]
33
+ * getInEdges(graph, 'a');
34
+ * // => []
35
+ * ```
36
+ */
37
+ declare function getInEdges<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
38
+ /**
39
+ * Returns outgoing edges from a node.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const graph = createGraph({
44
+ * nodes: [{ id: 'a' }, { id: 'b' }],
45
+ * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
46
+ * });
47
+ * getOutEdges(graph, 'a');
48
+ * // => [edge e1]
49
+ * getOutEdges(graph, 'b');
50
+ * // => []
51
+ * ```
52
+ */
53
+ declare function getOutEdges<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
54
+ /**
55
+ * Returns all edges from `sourceId` to `targetId`.
56
+ * Edges whose effective mode is not `'directed'` are matched both ways.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const graph = createGraph({
61
+ * nodes: [{ id: 'a' }, { id: 'b' }],
62
+ * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
63
+ * });
64
+ * getEdgesBetween(graph, 'a', 'b');
65
+ * // => [edge e1]
66
+ * getEdgesBetween(graph, 'b', 'a');
67
+ * // => [] (directed edge)
68
+ * ```
69
+ */
70
+ declare function getEdgesBetween<N, E>(graph: Graph<N, E>, sourceId: string, targetId: string): GraphEdge<E>[];
71
+ /**
72
+ * Returns direct successor nodes (targets of outgoing edges).
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const graph = createGraph({
77
+ * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
78
+ * edges: [
79
+ * { id: 'e1', sourceId: 'a', targetId: 'b' },
80
+ * { id: 'e2', sourceId: 'a', targetId: 'c' },
81
+ * ],
82
+ * });
83
+ * getSuccessors(graph, 'a');
84
+ * // => [node b, node c]
85
+ * ```
86
+ */
87
+ declare function getSuccessors<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
88
+ /**
89
+ * Returns direct predecessor nodes (sources of incoming edges).
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const graph = createGraph({
94
+ * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
95
+ * edges: [
96
+ * { id: 'e1', sourceId: 'a', targetId: 'c' },
97
+ * { id: 'e2', sourceId: 'b', targetId: 'c' },
98
+ * ],
99
+ * });
100
+ * getPredecessors(graph, 'c');
101
+ * // => [node a, node b]
102
+ * ```
103
+ */
104
+ declare function getPredecessors<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
105
+ /**
106
+ * Returns all neighbor nodes (successors + predecessors).
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const graph = createGraph({
111
+ * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
112
+ * edges: [
113
+ * { id: 'e1', sourceId: 'a', targetId: 'b' },
114
+ * { id: 'e2', sourceId: 'c', targetId: 'b' },
115
+ * ],
116
+ * });
117
+ * getNeighbors(graph, 'b');
118
+ * // => [node a, node c]
119
+ * ```
120
+ */
121
+ declare function getNeighbors<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
122
+ /**
123
+ * Returns the total degree of a node (inDegree + outDegree).
124
+ * For graphs whose default mode is not `'directed'`, each incident edge is
125
+ * counted once.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const graph = createGraph({
130
+ * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
131
+ * edges: [
132
+ * { id: 'e1', sourceId: 'a', targetId: 'b' },
133
+ * { id: 'e2', sourceId: 'c', targetId: 'b' },
134
+ * ],
135
+ * });
136
+ * getDegree(graph, 'b'); // => 2
137
+ * getDegree(graph, 'a'); // => 1
138
+ * ```
139
+ */
140
+ declare function getDegree(graph: Graph, nodeId: string): number;
141
+ /**
142
+ * Returns the in-degree of a node (number of incoming edges).
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * const graph = createGraph({
147
+ * nodes: [{ id: 'a' }, { id: 'b' }],
148
+ * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
149
+ * });
150
+ * getInDegree(graph, 'b'); // => 1
151
+ * getInDegree(graph, 'a'); // => 0
152
+ * ```
153
+ */
154
+ declare function getInDegree(graph: Graph, nodeId: string): number;
155
+ /**
156
+ * Returns the out-degree of a node (number of outgoing edges).
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * const graph = createGraph({
161
+ * nodes: [{ id: 'a' }, { id: 'b' }],
162
+ * edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
163
+ * });
164
+ * getOutDegree(graph, 'a'); // => 1
165
+ * getOutDegree(graph, 'b'); // => 0
166
+ * ```
167
+ */
168
+ declare function getOutDegree(graph: Graph, nodeId: string): number;
169
+ /**
170
+ * Returns direct children of a node in the hierarchy.
171
+ * Pass `null` to get root-level nodes.
172
+ *
173
+ * @example
174
+ * ```ts
175
+ * const graph = createGraph({
176
+ * nodes: [
177
+ * { id: 'parent' },
178
+ * { id: 'child1', parentId: 'parent' },
179
+ * { id: 'child2', parentId: 'parent' },
180
+ * ],
181
+ * });
182
+ * getChildren(graph, 'parent');
183
+ * // => [node child1, node child2]
184
+ * getChildren(graph, null);
185
+ * // => [node parent]
186
+ * ```
187
+ */
188
+ declare function getChildren<N>(graph: Graph<N>, nodeId: string | null): GraphNode<N>[];
189
+ /**
190
+ * Returns the parent node in the hierarchy, or `undefined` if root-level.
191
+ *
192
+ * @example
193
+ * ```ts
194
+ * const graph = createGraph({
195
+ * nodes: [
196
+ * { id: 'parent' },
197
+ * { id: 'child', parentId: 'parent' },
198
+ * ],
199
+ * });
200
+ * getParent(graph, 'child');
201
+ * // => node parent
202
+ * getParent(graph, 'parent');
203
+ * // => undefined
204
+ * ```
205
+ */
206
+ declare function getParent<N>(graph: Graph<N>, nodeId: string): GraphNode<N> | undefined;
207
+ /**
208
+ * Returns all ancestors from the node up to the root (nearest parent first).
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * const graph = createGraph({
213
+ * nodes: [
214
+ * { id: 'root' },
215
+ * { id: 'mid', parentId: 'root' },
216
+ * { id: 'leaf', parentId: 'mid' },
217
+ * ],
218
+ * });
219
+ * getAncestors(graph, 'leaf');
220
+ * // => [node mid, node root]
221
+ * ```
222
+ */
223
+ declare function getAncestors<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
224
+ /**
225
+ * Returns all descendants recursively (depth-first).
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * const graph = createGraph({
230
+ * nodes: [
231
+ * { id: 'root' },
232
+ * { id: 'child', parentId: 'root' },
233
+ * { id: 'grandchild', parentId: 'child' },
234
+ * ],
235
+ * });
236
+ * getDescendants(graph, 'root');
237
+ * // => [node child, node grandchild]
238
+ * ```
239
+ */
240
+ declare function getDescendants<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
241
+ /**
242
+ * Returns all root nodes (nodes with no parent).
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * const graph = createGraph({
247
+ * nodes: [
248
+ * { id: 'root1' },
249
+ * { id: 'root2' },
250
+ * { id: 'child', parentId: 'root1' },
251
+ * ],
252
+ * });
253
+ * getRoots(graph);
254
+ * // => [node root1, node root2]
255
+ * ```
256
+ */
257
+ declare function getRoots<N>(graph: Graph<N>): GraphNode<N>[];
258
+ /**
259
+ * Whether a node has children (is a compound/group node).
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * const graph = createGraph({
264
+ * nodes: [
265
+ * { id: 'parent' },
266
+ * { id: 'child', parentId: 'parent' },
267
+ * ],
268
+ * });
269
+ * isCompound(graph, 'parent'); // => true
270
+ * isCompound(graph, 'child'); // => false
271
+ * ```
272
+ */
273
+ declare function isCompound(graph: Graph, nodeId: string): boolean;
274
+ /**
275
+ * Whether a node has no children (is a leaf/atomic node).
276
+ *
277
+ * @example
278
+ * ```ts
279
+ * const graph = createGraph({
280
+ * nodes: [
281
+ * { id: 'parent' },
282
+ * { id: 'child', parentId: 'parent' },
283
+ * ],
284
+ * });
285
+ * isLeaf(graph, 'child'); // => true
286
+ * isLeaf(graph, 'parent'); // => false
287
+ * ```
288
+ */
289
+ declare function isLeaf(graph: Graph, nodeId: string): boolean;
290
+ /**
291
+ * Depth of a node in the hierarchy (root = 0).
292
+ * Returns -1 if the node is not found.
293
+ *
294
+ * @example
295
+ * ```ts
296
+ * const graph = createGraph({
297
+ * nodes: [
298
+ * { id: 'root' },
299
+ * { id: 'child', parentId: 'root' },
300
+ * { id: 'grandchild', parentId: 'child' },
301
+ * ],
302
+ * });
303
+ * getDepth(graph, 'root'); // => 0
304
+ * getDepth(graph, 'child'); // => 1
305
+ * getDepth(graph, 'grandchild'); // => 2
306
+ * ```
307
+ */
308
+ declare function getDepth(graph: Graph, nodeId: string): number;
309
+ /**
310
+ * Sibling nodes (same parentId, excluding the node itself).
311
+ *
312
+ * @example
313
+ * ```ts
314
+ * const graph = createGraph({
315
+ * nodes: [
316
+ * { id: 'parent' },
317
+ * { id: 'a', parentId: 'parent' },
318
+ * { id: 'b', parentId: 'parent' },
319
+ * { id: 'c', parentId: 'parent' },
320
+ * ],
321
+ * });
322
+ * getSiblings(graph, 'a');
323
+ * // => [node b, node c]
324
+ * ```
325
+ */
326
+ declare function getSiblings<N>(graph: Graph<N>, nodeId: string): GraphNode<N>[];
327
+ /**
328
+ * Least Common Ancestor -- deepest proper ancestor of all given nodes.
329
+ * A proper ancestor excludes the input nodes themselves.
330
+ *
331
+ * @example
332
+ * ```ts
333
+ * const graph = createGraph({
334
+ * nodes: [
335
+ * { id: 'root' },
336
+ * { id: 'a', parentId: 'root' },
337
+ * { id: 'b', parentId: 'root' },
338
+ * { id: 'a1', parentId: 'a' },
339
+ * ],
340
+ * });
341
+ * getLCA(graph, 'a1', 'b');
342
+ * // => node root
343
+ * getLCA(graph, 'a', 'b');
344
+ * // => node root
345
+ * ```
346
+ */
347
+ declare function getLCA<N>(graph: Graph<N>, ...nodeIds: string[]): GraphNode<N> | undefined;
348
+ /**
349
+ * Returns a map of nodeId → shortest-path distance for all sibling nodes
350
+ * (same parentId). Distance is measured from the parent's `initialNodeId`
351
+ * (or `graph.initialNodeId` for root-level nodes).
352
+ *
353
+ * Only follows edges between siblings. Unreachable siblings are omitted.
354
+ *
355
+ * @example Root-level nodes (uses `graph.initialNodeId`):
356
+ * ```ts
357
+ * const graph = createGraph({
358
+ * initialNodeId: 'a',
359
+ * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
360
+ * edges: [
361
+ * { id: 'e1', sourceId: 'a', targetId: 'b' },
362
+ * { id: 'e2', sourceId: 'b', targetId: 'c' },
363
+ * ],
364
+ * });
365
+ * getRelativeDistanceMap(graph, null);
366
+ * // => { a: 0, b: 1, c: 2 }
367
+ * ```
368
+ *
369
+ * @example Nested nodes (uses parent's `initialNodeId`):
370
+ * ```ts
371
+ * const graph = createGraph({
372
+ * nodes: [
373
+ * { id: 'parent', initialNodeId: 's1' },
374
+ * { id: 's1', parentId: 'parent' },
375
+ * { id: 's2', parentId: 'parent' },
376
+ * { id: 's3', parentId: 'parent' },
377
+ * ],
378
+ * edges: [
379
+ * { id: 'e1', sourceId: 's1', targetId: 's2' },
380
+ * { id: 'e2', sourceId: 's2', targetId: 's3' },
381
+ * ],
382
+ * });
383
+ * getRelativeDistanceMap(graph, 'parent');
384
+ * // => { s1: 0, s2: 1, s3: 2 }
385
+ * ```
386
+ */
387
+ declare function getRelativeDistanceMap(graph: Graph, parentId: string | null): Record<string, number>;
388
+ /**
389
+ * Returns the shortest-path distance of a node from its parent's initial node.
390
+ * Automatically scopes to the node's sibling group (same `parentId`).
391
+ *
392
+ * Returns `undefined` if the node is not found or unreachable.
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * const graph = createGraph({
397
+ * initialNodeId: 'a',
398
+ * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
399
+ * edges: [
400
+ * { id: 'e1', sourceId: 'a', targetId: 'b' },
401
+ * { id: 'e2', sourceId: 'b', targetId: 'c' },
402
+ * ],
403
+ * });
404
+ * getRelativeDistance(graph, 'a'); // => 0
405
+ * getRelativeDistance(graph, 'b'); // => 1
406
+ * getRelativeDistance(graph, 'c'); // => 2
407
+ * ```
408
+ *
409
+ * @example Nested nodes:
410
+ * ```ts
411
+ * const graph = createGraph({
412
+ * nodes: [
413
+ * { id: 'parent', initialNodeId: 's1' },
414
+ * { id: 's1', parentId: 'parent' },
415
+ * { id: 's2', parentId: 'parent' },
416
+ * ],
417
+ * edges: [{ id: 'e1', sourceId: 's1', targetId: 's2' }],
418
+ * });
419
+ * getRelativeDistance(graph, 's1'); // => 0
420
+ * getRelativeDistance(graph, 's2'); // => 1
421
+ * ```
422
+ */
423
+ declare function getRelativeDistance(graph: Graph, nodeId: string): number | undefined;
424
+ /**
425
+ * Nodes with no incoming edges (inDegree 0).
426
+ *
427
+ * @example
428
+ * ```ts
429
+ * const graph = createGraph({
430
+ * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
431
+ * edges: [
432
+ * { id: 'e1', sourceId: 'a', targetId: 'b' },
433
+ * { id: 'e2', sourceId: 'b', targetId: 'c' },
434
+ * ],
435
+ * });
436
+ * getSources(graph);
437
+ * // => [node a]
438
+ * ```
439
+ */
440
+ declare function getSources<N>(graph: Graph<N>): GraphNode<N>[];
441
+ /**
442
+ * Nodes with no outgoing edges (outDegree 0).
443
+ *
444
+ * @example
445
+ * ```ts
446
+ * const graph = createGraph({
447
+ * nodes: [{ id: 'a' }, { id: 'b' }, { id: 'c' }],
448
+ * edges: [
449
+ * { id: 'e1', sourceId: 'a', targetId: 'b' },
450
+ * { id: 'e2', sourceId: 'b', targetId: 'c' },
451
+ * ],
452
+ * });
453
+ * getSinks(graph);
454
+ * // => [node c]
455
+ * ```
456
+ */
457
+ declare function getSinks<N>(graph: Graph<N>): GraphNode<N>[];
458
+ /**
459
+ * Get a port by name on a node, or `undefined` if not found.
460
+ *
461
+ * @example
462
+ * ```ts
463
+ * const graph = createGraph({
464
+ * nodes: [{
465
+ * id: 'a',
466
+ * ports: [{ name: 'out', direction: 'out' }],
467
+ * }],
468
+ * });
469
+ * getPort(graph, 'a', 'out'); // => { name: 'out', direction: 'out', ... }
470
+ * getPort(graph, 'a', 'missing'); // => undefined
471
+ * ```
472
+ */
473
+ declare function getPort<N, E, G, P>(graph: Graph<N, E, G, P>, nodeId: string, portName: string): GraphPort<P> | undefined;
474
+ /**
475
+ * Get all ports on a node. Returns `[]` if the node has no ports or doesn't exist.
476
+ *
477
+ * @example
478
+ * ```ts
479
+ * const graph = createGraph({
480
+ * nodes: [{
481
+ * id: 'a',
482
+ * ports: [
483
+ * { name: 'in', direction: 'in' },
484
+ * { name: 'out', direction: 'out' },
485
+ * ],
486
+ * }],
487
+ * });
488
+ * getPorts(graph, 'a'); // => [port in, port out]
489
+ * ```
490
+ */
491
+ declare function getPorts<N, E, G, P>(graph: Graph<N, E, G, P>, nodeId: string): GraphPort<P>[];
492
+ /**
493
+ * Get all edges connected to a specific port on a node.
494
+ *
495
+ * Returns edges where:
496
+ * - `sourceId === nodeId && sourcePort === portName`, or
497
+ * - `targetId === nodeId && targetPort === portName`
498
+ *
499
+ * @example
500
+ * ```ts
501
+ * const graph = createGraph({
502
+ * nodes: [
503
+ * { id: 'a', ports: [{ name: 'out', direction: 'out' }] },
504
+ * { id: 'b', ports: [{ name: 'in', direction: 'in' }] },
505
+ * ],
506
+ * edges: [{
507
+ * id: 'e1', sourceId: 'a', targetId: 'b',
508
+ * sourcePort: 'out', targetPort: 'in',
509
+ * }],
510
+ * });
511
+ * getEdgesByPort(graph, 'a', 'out'); // => [edge e1]
512
+ * ```
513
+ */
514
+ declare function getEdgesByPort<N, E>(graph: Graph<N, E>, nodeId: string, portName: string): GraphEdge<E>[];
515
+ //#endregion
516
+ export { getSinks as C, isLeaf as D, isCompound as E, getSiblings as S, getSuccessors as T, getPorts as _, getDescendants as a, getRelativeDistanceMap as b, getEdgesOf as c, getLCA as d, getNeighbors as f, getPort as g, getParent as h, getDepth as i, getInDegree as l, getOutEdges as m, getChildren as n, getEdgesBetween as o, getOutDegree as p, getDegree as r, getEdgesByPort as s, getAncestors as t, getInEdges as u, getPredecessors as v, getSources as w, getRoots as x, getRelativeDistance as y };