@nodius/layouting 0.1.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/LICENSE +201 -0
- package/README.md +253 -0
- package/dist/index.d.mts +176 -0
- package/dist/index.d.ts +176 -0
- package/dist/index.js +1115 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1086 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +48 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/** Position on a node where a handle can be placed */
|
|
2
|
+
type HandleSide = 'top' | 'right' | 'bottom' | 'left';
|
|
3
|
+
/** Handle type - input receives connections, output sends connections */
|
|
4
|
+
type HandleType = 'input' | 'output';
|
|
5
|
+
/** Layout direction */
|
|
6
|
+
type LayoutDirection = 'TB' | 'LR' | 'BT' | 'RL';
|
|
7
|
+
/** A 2D point */
|
|
8
|
+
interface Point {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
}
|
|
12
|
+
/** Handle definition on a node */
|
|
13
|
+
interface HandleInput {
|
|
14
|
+
id: string;
|
|
15
|
+
type: HandleType;
|
|
16
|
+
position: HandleSide;
|
|
17
|
+
/** Position along the side (0 = start, 1 = end). Default: 0.5 */
|
|
18
|
+
offset?: number;
|
|
19
|
+
}
|
|
20
|
+
/** Node input definition */
|
|
21
|
+
interface NodeInput {
|
|
22
|
+
id: string;
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
handles: HandleInput[];
|
|
26
|
+
}
|
|
27
|
+
/** Edge input definition */
|
|
28
|
+
interface EdgeInput {
|
|
29
|
+
id: string;
|
|
30
|
+
from: string;
|
|
31
|
+
to: string;
|
|
32
|
+
fromHandle: string;
|
|
33
|
+
toHandle: string;
|
|
34
|
+
}
|
|
35
|
+
/** Complete layout input */
|
|
36
|
+
interface LayoutInput {
|
|
37
|
+
nodes: NodeInput[];
|
|
38
|
+
edges: EdgeInput[];
|
|
39
|
+
}
|
|
40
|
+
/** Layout configuration options */
|
|
41
|
+
interface LayoutOptions {
|
|
42
|
+
/** Layout direction. Default: 'TB' */
|
|
43
|
+
direction?: LayoutDirection;
|
|
44
|
+
/** Minimum spacing between nodes in the same layer. Default: 40 */
|
|
45
|
+
nodeSpacing?: number;
|
|
46
|
+
/** Minimum spacing between layers. Default: 60 */
|
|
47
|
+
layerSpacing?: number;
|
|
48
|
+
/** Number of iterations for crossing minimization. Default: 24 */
|
|
49
|
+
crossingMinimizationIterations?: number;
|
|
50
|
+
/** Number of iterations for coordinate optimization. Default: 8 */
|
|
51
|
+
coordinateOptimizationIterations?: number;
|
|
52
|
+
/** Margin for edge routing (distance from node before turning). Default: 20 */
|
|
53
|
+
edgeMargin?: number;
|
|
54
|
+
}
|
|
55
|
+
/** Positioned handle in the output */
|
|
56
|
+
interface HandleOutput {
|
|
57
|
+
id: string;
|
|
58
|
+
type: HandleType;
|
|
59
|
+
position: HandleSide;
|
|
60
|
+
x: number;
|
|
61
|
+
y: number;
|
|
62
|
+
}
|
|
63
|
+
/** Positioned node in the output */
|
|
64
|
+
interface NodeOutput {
|
|
65
|
+
id: string;
|
|
66
|
+
x: number;
|
|
67
|
+
y: number;
|
|
68
|
+
width: number;
|
|
69
|
+
height: number;
|
|
70
|
+
handles: HandleOutput[];
|
|
71
|
+
}
|
|
72
|
+
/** Routed edge in the output */
|
|
73
|
+
interface EdgeOutput {
|
|
74
|
+
id: string;
|
|
75
|
+
from: string;
|
|
76
|
+
to: string;
|
|
77
|
+
fromHandle: string;
|
|
78
|
+
toHandle: string;
|
|
79
|
+
points: Point[];
|
|
80
|
+
}
|
|
81
|
+
/** Complete layout result */
|
|
82
|
+
interface LayoutResult {
|
|
83
|
+
nodes: NodeOutput[];
|
|
84
|
+
edges: EdgeOutput[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface InternalNode {
|
|
88
|
+
id: string;
|
|
89
|
+
width: number;
|
|
90
|
+
height: number;
|
|
91
|
+
handles: HandleInput[];
|
|
92
|
+
isDummy: boolean;
|
|
93
|
+
layer: number;
|
|
94
|
+
order: number;
|
|
95
|
+
x: number;
|
|
96
|
+
y: number;
|
|
97
|
+
}
|
|
98
|
+
interface InternalEdge {
|
|
99
|
+
id: string;
|
|
100
|
+
from: string;
|
|
101
|
+
to: string;
|
|
102
|
+
fromHandle: string;
|
|
103
|
+
toHandle: string;
|
|
104
|
+
reversed: boolean;
|
|
105
|
+
originalId: string;
|
|
106
|
+
}
|
|
107
|
+
declare class Graph {
|
|
108
|
+
nodes: Map<string, InternalNode>;
|
|
109
|
+
edges: Map<string, InternalEdge>;
|
|
110
|
+
outEdges: Map<string, Set<string>>;
|
|
111
|
+
inEdges: Map<string, Set<string>>;
|
|
112
|
+
addNode(node: InternalNode): void;
|
|
113
|
+
addEdge(edge: InternalEdge): void;
|
|
114
|
+
removeEdge(edgeId: string): void;
|
|
115
|
+
removeNode(nodeId: string): void;
|
|
116
|
+
predecessors(nodeId: string): string[];
|
|
117
|
+
successors(nodeId: string): string[];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Compute a complete layout for the given graph.
|
|
122
|
+
* This is the main entry point for one-shot layout computation.
|
|
123
|
+
*/
|
|
124
|
+
declare function layout(input: LayoutInput, options?: LayoutOptions): LayoutResult;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Incremental layout engine.
|
|
128
|
+
* Maintains layout state and supports adding/removing nodes
|
|
129
|
+
* without full recomputation.
|
|
130
|
+
*/
|
|
131
|
+
declare class IncrementalLayout {
|
|
132
|
+
private options;
|
|
133
|
+
private inputNodes;
|
|
134
|
+
private inputEdges;
|
|
135
|
+
private lastResult;
|
|
136
|
+
private nodePositions;
|
|
137
|
+
constructor(options?: LayoutOptions);
|
|
138
|
+
/**
|
|
139
|
+
* Set the full graph and compute a complete layout.
|
|
140
|
+
*/
|
|
141
|
+
setGraph(input: LayoutInput): LayoutResult;
|
|
142
|
+
/**
|
|
143
|
+
* Add nodes and edges incrementally.
|
|
144
|
+
* Attempts to minimize layout changes for existing nodes.
|
|
145
|
+
*/
|
|
146
|
+
addNodes(nodes: NodeInput[], edges?: EdgeInput[]): LayoutResult;
|
|
147
|
+
/**
|
|
148
|
+
* Remove nodes (and their connected edges) from the layout.
|
|
149
|
+
*/
|
|
150
|
+
removeNodes(nodeIds: string[]): LayoutResult;
|
|
151
|
+
/**
|
|
152
|
+
* Add edges between existing nodes.
|
|
153
|
+
*/
|
|
154
|
+
addEdges(edges: EdgeInput[]): LayoutResult;
|
|
155
|
+
/**
|
|
156
|
+
* Remove edges from the layout.
|
|
157
|
+
*/
|
|
158
|
+
removeEdges(edgeIds: string[]): LayoutResult;
|
|
159
|
+
/**
|
|
160
|
+
* Get the current layout result.
|
|
161
|
+
*/
|
|
162
|
+
getResult(): LayoutResult | null;
|
|
163
|
+
private recompute;
|
|
164
|
+
private recomputeIncremental;
|
|
165
|
+
/**
|
|
166
|
+
* Apply stability: blend new positions with old positions for existing nodes.
|
|
167
|
+
* This reduces visual disruption when adding new nodes.
|
|
168
|
+
*/
|
|
169
|
+
private applyStability;
|
|
170
|
+
private cachePositions;
|
|
171
|
+
private buildResult;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare function countAllCrossings(graph: Graph, layers: string[][]): number;
|
|
175
|
+
|
|
176
|
+
export { type EdgeInput, type EdgeOutput, type HandleInput, type HandleOutput, type HandleSide, type HandleType, IncrementalLayout, type LayoutDirection, type LayoutInput, type LayoutOptions, type LayoutResult, type NodeInput, type NodeOutput, type Point, countAllCrossings, layout };
|