@kahitsan/ksui 0.21.0 → 0.22.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kahitsan/ksui",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "ksui is a standalone set of SolidJS UI components for KahitSan/Hilinga and any SolidJS app. Published to the public npm registry and consumed as a normal dependency. Ships source under a `solid` export condition so the consumer's vite-plugin-solid compiles it with only solid-js externalized; it depends on nothing but solid-js + lucide-solid and injects its own CSS.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -0,0 +1,105 @@
1
+ // FlowGraph tests: the pure layout (lanes, dimensions, bipartite/layered) and
2
+ // the SVG render (nodes, edges, empty state, node selection).
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import { render, fireEvent } from "@solidjs/testing-library";
5
+ import FlowGraph from "./FlowGraph";
6
+ import { layoutGraph, DEFAULT_METRICS, type GraphEdge, type GraphNode } from "../../utils/graph";
7
+
8
+ const { nodeW, gapX, pad } = DEFAULT_METRICS;
9
+
10
+ describe("layoutGraph", () => {
11
+ it("layers roots→leaves by longest path", () => {
12
+ const nodes: GraphNode[] = [{ id: "a", label: "A" }, { id: "b", label: "B" }, { id: "c", label: "C" }];
13
+ const edges: GraphEdge[] = [{ from: "a", to: "b" }, { from: "b", to: "c" }];
14
+ const { byId } = layoutGraph(nodes, edges, "layered");
15
+ expect(byId.get("a")!.lane).toBe(0);
16
+ expect(byId.get("b")!.lane).toBe(1);
17
+ expect(byId.get("c")!.lane).toBe(2);
18
+ });
19
+
20
+ it("uses the longest path when a node has two incoming depths", () => {
21
+ // a→c and a→b→c: c must sit past b, not just past a.
22
+ const nodes: GraphNode[] = [{ id: "a", label: "A" }, { id: "b", label: "B" }, { id: "c", label: "C" }];
23
+ const edges: GraphEdge[] = [{ from: "a", to: "b" }, { from: "b", to: "c" }, { from: "a", to: "c" }];
24
+ const { byId } = layoutGraph(nodes, edges, "layered");
25
+ expect(byId.get("c")!.lane).toBe(2);
26
+ });
27
+
28
+ it("splits bipartite by incoming degree, honoring explicit lanes for isolated sinks", () => {
29
+ const nodes: GraphNode[] = [
30
+ { id: "role", label: "admin" },
31
+ { id: "p1", label: "view" },
32
+ { id: "p2", label: "delete", lane: 1 }, // ungranted permission, no edge
33
+ ];
34
+ const edges: GraphEdge[] = [{ from: "role", to: "p1" }];
35
+ const { byId } = layoutGraph(nodes, edges, "bipartite");
36
+ expect(byId.get("role")!.lane).toBe(0);
37
+ expect(byId.get("p1")!.lane).toBe(1);
38
+ expect(byId.get("p2")!.lane).toBe(1); // pinned, despite no incoming edge
39
+ });
40
+
41
+ it("does not spin forever on a cycle", () => {
42
+ const nodes: GraphNode[] = [{ id: "a", label: "A" }, { id: "b", label: "B" }];
43
+ const edges: GraphEdge[] = [{ from: "a", to: "b" }, { from: "b", to: "a" }];
44
+ const { nodes: out } = layoutGraph(nodes, edges, "layered");
45
+ expect(out).toHaveLength(2);
46
+ });
47
+
48
+ it("positions the second lane one node-width + gap past the first", () => {
49
+ const nodes: GraphNode[] = [{ id: "a", label: "A" }, { id: "b", label: "B" }];
50
+ const { byId } = layoutGraph(nodes, [{ from: "a", to: "b" }], "layered");
51
+ expect(byId.get("a")!.x).toBe(pad);
52
+ expect(byId.get("b")!.x).toBe(pad + nodeW + gapX);
53
+ });
54
+
55
+ it("ignores edges that dangle off the node set", () => {
56
+ const { nodes } = layoutGraph([{ id: "a", label: "A" }], [{ from: "a", to: "ghost" }], "layered");
57
+ expect(nodes).toHaveLength(1);
58
+ });
59
+ });
60
+
61
+ describe("FlowGraph", () => {
62
+ it("renders a node per input node and an svg", () => {
63
+ const { getByTestId } = render(() => (
64
+ <FlowGraph
65
+ testId="fg"
66
+ nodes={[{ id: "a", label: "Alpha", sublabel: "base" }, { id: "b", label: "Beta" }]}
67
+ edges={[{ from: "a", to: "b" }]}
68
+ />
69
+ ));
70
+ expect(getByTestId("fg-svg")).toBeTruthy();
71
+ expect(getByTestId("fg-node-a")).toBeTruthy();
72
+ expect(getByTestId("fg-node-b")).toBeTruthy();
73
+ });
74
+
75
+ it("shows the empty state when there are no nodes", () => {
76
+ const { getByTestId, queryByTestId } = render(() => (
77
+ <FlowGraph testId="fg" nodes={[]} edges={[]} emptyLabel="No connections" />
78
+ ));
79
+ expect(getByTestId("fg-empty").textContent).toContain("No connections");
80
+ expect(queryByTestId("fg-svg")).toBeNull();
81
+ });
82
+
83
+ it("makes nodes interactive only when onNodeSelect is supplied", () => {
84
+ const onNodeSelect = vi.fn();
85
+ const { getByTestId } = render(() => (
86
+ <FlowGraph
87
+ testId="fg"
88
+ nodes={[{ id: "a", label: "Alpha" }]}
89
+ edges={[]}
90
+ onNodeSelect={onNodeSelect}
91
+ />
92
+ ));
93
+ const node = getByTestId("fg-node-a");
94
+ expect(node.getAttribute("role")).toBe("button");
95
+ fireEvent.click(node);
96
+ expect(onNodeSelect).toHaveBeenCalledWith("a");
97
+ });
98
+
99
+ it("does not mark nodes as buttons without a handler", () => {
100
+ const { getByTestId } = render(() => (
101
+ <FlowGraph testId="fg" nodes={[{ id: "a", label: "Alpha" }]} edges={[]} />
102
+ ));
103
+ expect(getByTestId("fg-node-a").getAttribute("role")).toBeNull();
104
+ });
105
+ });
@@ -0,0 +1,216 @@
1
+ // FlowGraph (Vision §9 companion to FlowRunner): a read-only renderer for a
2
+ // DECLARATIVE node graph. Where FlowRunner *executes* a server-driven flow,
3
+ // FlowGraph *draws* a static relationship graph — plugin connections, a
4
+ // role→permission map, any directed graph the host hands it.
5
+ //
6
+ // Composite because it composes the pure graph model (utils/graph) with SVG
7
+ // layout + interaction. Domain-free: it knows nothing about plugins or roles;
8
+ // the host supplies typed nodes/edges and an optional click handler. Self-
9
+ // contained CSS (ksui-fg-* unscoped classes + CSS custom props); no Tailwind,
10
+ // no host-brand classes (standalone-library rule).
11
+
12
+ import type { Component, JSX } from "solid-js";
13
+ import { For, Show, createMemo } from "solid-js";
14
+ import {
15
+ DEFAULT_METRICS,
16
+ layoutGraph,
17
+ type GraphEdge,
18
+ type GraphLayout,
19
+ type GraphNode,
20
+ type PositionedNode,
21
+ } from "../../utils/graph";
22
+
23
+ const STYLE_ID = "ksui-flow-graph-style";
24
+
25
+ function ensureStyle(): void {
26
+ if (typeof document === "undefined") return;
27
+ if (document.getElementById(STYLE_ID)) return;
28
+ const style = document.createElement("style");
29
+ style.id = STYLE_ID;
30
+ style.textContent = `
31
+ .ksui-fg-wrap{width:100%;overflow:auto;}
32
+ .ksui-fg-svg{display:block;max-width:100%;height:auto;font-family:inherit;}
33
+ .ksui-fg-edge{fill:none;stroke:var(--ksui-fg-edge,rgba(255,255,255,0.22));stroke-width:1.5;}
34
+ .ksui-fg-edge.dashed{stroke-dasharray:4 4;}
35
+ .ksui-fg-edge.primary{stroke:var(--ksui-fg-primary,#c9a961);}
36
+ .ksui-fg-edge.info{stroke:#3b82f6;}
37
+ .ksui-fg-edge.success{stroke:#22c55e;}
38
+ .ksui-fg-edge.danger{stroke:#ef4444;}
39
+ .ksui-fg-edge.muted{stroke:rgba(255,255,255,0.14);}
40
+ .ksui-fg-elabel{fill:var(--ksui-fg-muted,rgba(255,255,255,0.7));font-size:9px;}
41
+ .ksui-fg-elabel-bg{fill:var(--ksui-fg-bg,#18181b);opacity:0.82;}
42
+ .ksui-fg-box{fill:var(--ksui-fg-node-bg,rgba(255,255,255,0.04));stroke:var(--ksui-fg-node-border,rgba(255,255,255,0.16));stroke-width:1;}
43
+ .ksui-fg-node.primary .ksui-fg-box{stroke:var(--ksui-fg-primary,#c9a961);fill:rgba(201,169,97,0.08);}
44
+ .ksui-fg-node.info .ksui-fg-box{stroke:#3b82f6;fill:rgba(59,130,246,0.08);}
45
+ .ksui-fg-node.success .ksui-fg-box{stroke:#22c55e;fill:rgba(34,197,94,0.08);}
46
+ .ksui-fg-node.danger .ksui-fg-box{stroke:#ef4444;fill:rgba(239,68,68,0.08);}
47
+ .ksui-fg-node.muted .ksui-fg-box{stroke:rgba(255,255,255,0.16);fill:rgba(255,255,255,0.02);}
48
+ .ksui-fg-node.clickable{cursor:pointer;}
49
+ .ksui-fg-node.clickable:hover .ksui-fg-box{fill:rgba(255,255,255,0.10);}
50
+ .ksui-fg-node.clickable:focus{outline:none;}
51
+ .ksui-fg-node.clickable:focus-visible .ksui-fg-box{stroke:var(--ksui-fg-primary,#c9a961);stroke-width:2;}
52
+ .ksui-fg-label{fill:var(--ksui-fg-fg,#e4e4e7);font-size:12px;font-weight:600;}
53
+ .ksui-fg-sublabel{fill:var(--ksui-fg-muted,rgba(255,255,255,0.55));font-size:9.5px;}
54
+ .ksui-fg-empty{padding:1.75rem 1rem;text-align:center;font-size:0.82rem;color:var(--ksui-fg-muted,rgba(255,255,255,0.55));}
55
+ `;
56
+ document.head.appendChild(style);
57
+ }
58
+
59
+ export interface FlowGraphProps {
60
+ nodes: GraphNode[];
61
+ edges: GraphEdge[];
62
+ /** "layered" (default) flows roots→leaves; "bipartite" splits source/sink. */
63
+ layout?: GraphLayout;
64
+ /** Shown when there are no nodes to draw. */
65
+ emptyLabel?: string;
66
+ /** Accessible description of the whole graph (the svg's aria-label). */
67
+ ariaLabel?: string;
68
+ /** When supplied, nodes become buttons that fire this with the node id. */
69
+ onNodeSelect?: (id: string) => void;
70
+ testId?: string;
71
+ }
72
+
73
+ /** SVG has no text overflow; trim to keep labels inside the node box. */
74
+ function clip(text: string, max: number): string {
75
+ return text.length > max ? text.slice(0, max - 1) + "…" : text;
76
+ }
77
+
78
+ const { nodeW, nodeH } = DEFAULT_METRICS;
79
+
80
+ export const FlowGraph: Component<FlowGraphProps> = (props) => {
81
+ ensureStyle();
82
+ const tid = (s: string) => (props.testId ? `${props.testId}-${s}` : undefined);
83
+
84
+ const laid = createMemo(() =>
85
+ layoutGraph(props.nodes, props.edges, props.layout ?? "layered"),
86
+ );
87
+
88
+ // A cubic bezier from a source node's right edge to a target's left edge.
89
+ const edgePath = (s: PositionedNode, t: PositionedNode): string => {
90
+ const x1 = s.x + nodeW;
91
+ const y1 = s.y + nodeH / 2;
92
+ const x2 = t.x;
93
+ const y2 = t.y + nodeH / 2;
94
+ const dx = Math.max(36, (x2 - x1) / 2);
95
+ return `M ${x1} ${y1} C ${x1 + dx} ${y1}, ${x2 - dx} ${y2}, ${x2} ${y2}`;
96
+ };
97
+
98
+ const activate = (e: KeyboardEvent, id: string) => {
99
+ if (e.key === "Enter" || e.key === " ") {
100
+ e.preventDefault();
101
+ props.onNodeSelect?.(id);
102
+ }
103
+ };
104
+
105
+ return (
106
+ <div class="ksui-fg-wrap" data-testid={tid("root")}>
107
+ <Show
108
+ when={laid().nodes.length > 0}
109
+ fallback={
110
+ <p class="ksui-fg-empty" data-testid={tid("empty")}>
111
+ {props.emptyLabel ?? "Nothing to show yet."}
112
+ </p>
113
+ }
114
+ >
115
+ <svg
116
+ class="ksui-fg-svg"
117
+ viewBox={`0 0 ${laid().width} ${laid().height}`}
118
+ width={laid().width}
119
+ height={laid().height}
120
+ role="img"
121
+ aria-label={props.ariaLabel ?? "Relationship graph"}
122
+ data-testid={tid("svg")}
123
+ >
124
+ <defs>
125
+ <marker
126
+ id="ksui-fg-arrow"
127
+ viewBox="0 0 8 8"
128
+ refX="7"
129
+ refY="4"
130
+ markerWidth="6"
131
+ markerHeight="6"
132
+ orient="auto-start-reverse"
133
+ >
134
+ <path d="M0 0 L8 4 L0 8 z" fill="var(--ksui-fg-edge,rgba(255,255,255,0.35))" />
135
+ </marker>
136
+ </defs>
137
+
138
+ {/* Edges first so nodes paint on top of the connectors. */}
139
+ <For each={props.edges}>
140
+ {(e) => {
141
+ const s = () => laid().byId.get(e.from);
142
+ const t = () => laid().byId.get(e.to);
143
+ return (
144
+ <Show when={s() && t()}>
145
+ {(() => {
146
+ const src = s() as PositionedNode;
147
+ const dst = t() as PositionedNode;
148
+ const mx = (src.x + nodeW + dst.x) / 2;
149
+ const my = (src.y + dst.y) / 2 + nodeH / 2;
150
+ return (
151
+ <g>
152
+ <path
153
+ class={`ksui-fg-edge ${e.accent ?? ""} ${e.dashed ? "dashed" : ""}`}
154
+ d={edgePath(src, dst)}
155
+ marker-end="url(#ksui-fg-arrow)"
156
+ />
157
+ <Show when={e.label}>
158
+ <rect
159
+ class="ksui-fg-elabel-bg"
160
+ x={mx - clip(e.label!, 18).length * 2.6 - 3}
161
+ y={my - 7}
162
+ width={clip(e.label!, 18).length * 5.2 + 6}
163
+ height={12}
164
+ rx={2}
165
+ />
166
+ <text class="ksui-fg-elabel" x={mx} y={my + 2} text-anchor="middle">
167
+ {clip(e.label!, 18)}
168
+ </text>
169
+ </Show>
170
+ </g>
171
+ );
172
+ })()}
173
+ </Show>
174
+ );
175
+ }}
176
+ </For>
177
+
178
+ {/* Nodes */}
179
+ <For each={laid().nodes}>
180
+ {(n) => {
181
+ const interactive = () => typeof props.onNodeSelect === "function";
182
+ return (
183
+ <g
184
+ class={`ksui-fg-node ${n.accent ?? ""} ${interactive() ? "clickable" : ""}`}
185
+ transform={`translate(${n.x} ${n.y})`}
186
+ data-testid={tid(`node-${n.id}`)}
187
+ role={interactive() ? "button" : undefined}
188
+ tabindex={interactive() ? 0 : undefined}
189
+ aria-label={n.sublabel ? `${n.label} — ${n.sublabel}` : n.label}
190
+ onClick={interactive() ? () => props.onNodeSelect!(n.id) : undefined}
191
+ onKeyDown={interactive() ? (ev) => activate(ev, n.id) : undefined}
192
+ >
193
+ <rect class="ksui-fg-box" width={nodeW} height={nodeH} rx={8} />
194
+ <text
195
+ class="ksui-fg-label"
196
+ x={12}
197
+ y={n.sublabel ? 20 : nodeH / 2 + 4}
198
+ >
199
+ {clip(n.label, 24)}
200
+ </text>
201
+ <Show when={n.sublabel}>
202
+ <text class="ksui-fg-sublabel" x={12} y={34}>
203
+ {clip(n.sublabel!, 28)}
204
+ </text>
205
+ </Show>
206
+ </g>
207
+ );
208
+ }}
209
+ </For>
210
+ </svg>
211
+ </Show>
212
+ </div>
213
+ ) as JSX.Element;
214
+ };
215
+
216
+ export default FlowGraph;
package/src/index.ts CHANGED
@@ -173,6 +173,11 @@ export { default as FlowRunner, type FlowRunnerProps } from "./components/compos
173
173
  // renders it with validated props, falling back safely on miss/mismatch.
174
174
  export { default as CustomRenderer, type CustomRendererProps } from "./components/composite/CustomRenderer";
175
175
 
176
+ // FlowGraph — read-only renderer for a declarative directed graph (the static
177
+ // companion to FlowRunner). Domain-free: host supplies typed nodes/edges; used
178
+ // for plugin-connection and role→permission visualizations.
179
+ export { default as FlowGraph, type FlowGraphProps } from "./components/composite/FlowGraph";
180
+
176
181
  // ---------------------------------------------------------------------------
177
182
  // Utils (not components)
178
183
  // ---------------------------------------------------------------------------
@@ -234,6 +239,20 @@ export type {
234
239
  FlowInput,
235
240
  } from "./utils/flow";
236
241
 
242
+ // FlowGraph model (pure): the node/edge types + the dependency-free layout the
243
+ // renderer uses. Exported so hosts can type their graph data and, if needed,
244
+ // pre-compute layout off the DOM.
245
+ export { layoutGraph, DEFAULT_METRICS } from "./utils/graph";
246
+ export type {
247
+ GraphNode,
248
+ GraphEdge,
249
+ GraphLayout,
250
+ GraphAccent,
251
+ GraphMetrics,
252
+ PositionedNode,
253
+ GraphLayoutResult,
254
+ } from "./utils/graph";
255
+
237
256
  // U8 — in-process, build-time custom renderer registry (no eval/remote code) and
238
257
  // its consumes-schema validator. Hosts register renderers at startup.
239
258
  export {
@@ -0,0 +1,154 @@
1
+ // Domain-free directed-graph model + a deterministic, dependency-free layout.
2
+ // Powers the FlowGraph renderer. No DOM, no solid — pure functions so the
3
+ // layout is unit-testable in isolation. ksui ships no graph library (solid +
4
+ // lucide only), so layering is a small longest-path pass, not dagre/d3.
5
+
6
+ export type GraphAccent = "primary" | "info" | "success" | "danger" | "muted";
7
+
8
+ export interface GraphNode {
9
+ /** Stable unique id; edges reference nodes by this. */
10
+ id: string;
11
+ label: string;
12
+ /** Secondary line under the label (e.g. a tier, a category, a count). */
13
+ sublabel?: string;
14
+ accent?: GraphAccent;
15
+ /**
16
+ * Explicit column index. Overrides automatic layering when set — required for
17
+ * a clean bipartite split when a sink node has no edges (e.g. an ungranted
18
+ * permission still belongs in the right column).
19
+ */
20
+ lane?: number;
21
+ }
22
+
23
+ export interface GraphEdge {
24
+ from: string;
25
+ to: string;
26
+ label?: string;
27
+ /**
28
+ * Render the connector dashed — e.g. "requires" vs a solid "provides", or a
29
+ * denied grant vs an allowed one.
30
+ */
31
+ dashed?: boolean;
32
+ accent?: GraphAccent;
33
+ }
34
+
35
+ export type GraphLayout = "layered" | "bipartite";
36
+
37
+ export interface PositionedNode extends GraphNode {
38
+ lane: number;
39
+ row: number;
40
+ x: number;
41
+ y: number;
42
+ }
43
+
44
+ export interface GraphLayoutResult {
45
+ nodes: PositionedNode[];
46
+ /** id → positioned node, for edge endpoint lookup. */
47
+ byId: Map<string, PositionedNode>;
48
+ width: number;
49
+ height: number;
50
+ }
51
+
52
+ export interface GraphMetrics {
53
+ nodeW: number;
54
+ nodeH: number;
55
+ gapX: number;
56
+ gapY: number;
57
+ pad: number;
58
+ }
59
+
60
+ export const DEFAULT_METRICS: GraphMetrics = {
61
+ nodeW: 168,
62
+ nodeH: 48,
63
+ gapX: 72,
64
+ gapY: 18,
65
+ pad: 16,
66
+ };
67
+
68
+ /** Count incoming edges per node id, ignoring edges that dangle off the set. */
69
+ function incomingDegree(ids: Set<string>, edges: GraphEdge[]): Map<string, number> {
70
+ const incoming = new Map<string, number>();
71
+ for (const id of ids) incoming.set(id, 0);
72
+ for (const e of edges) {
73
+ if (ids.has(e.from) && ids.has(e.to)) incoming.set(e.to, (incoming.get(e.to) ?? 0) + 1);
74
+ }
75
+ return incoming;
76
+ }
77
+
78
+ /** Assign each node a lane (column index). Explicit `node.lane` always wins. */
79
+ function assignLanes(
80
+ nodes: GraphNode[],
81
+ edges: GraphEdge[],
82
+ layout: GraphLayout,
83
+ ): Map<string, number> {
84
+ const ids = new Set(nodes.map((n) => n.id));
85
+ const pinned = new Set(nodes.filter((n) => typeof n.lane === "number").map((n) => n.id));
86
+ const lane = new Map<string, number>();
87
+ for (const n of nodes) if (typeof n.lane === "number") lane.set(n.id, n.lane);
88
+
89
+ const incoming = incomingDegree(ids, edges);
90
+
91
+ if (layout === "bipartite") {
92
+ // Sources (nothing points at them) on the left, sinks on the right.
93
+ for (const n of nodes) {
94
+ if (lane.has(n.id)) continue;
95
+ lane.set(n.id, (incoming.get(n.id) ?? 0) > 0 ? 1 : 0);
96
+ }
97
+ return lane;
98
+ }
99
+
100
+ // Layered: longest-path layering. Roots (no incoming) start at 0; relax each
101
+ // edge so a target sits at least one lane past its source. Cap the passes at
102
+ // node-count so a cycle can't spin forever.
103
+ for (const n of nodes) if (!lane.has(n.id)) lane.set(n.id, 0);
104
+ const live = edges.filter((e) => ids.has(e.from) && ids.has(e.to));
105
+ for (let pass = 0; pass < nodes.length; pass++) {
106
+ let changed = false;
107
+ for (const e of live) {
108
+ if (pinned.has(e.to)) continue; // don't move a caller-pinned node
109
+ const want = (lane.get(e.from) ?? 0) + 1;
110
+ if (want > (lane.get(e.to) ?? 0)) {
111
+ lane.set(e.to, want);
112
+ changed = true;
113
+ }
114
+ }
115
+ if (!changed) break;
116
+ }
117
+ return lane;
118
+ }
119
+
120
+ /**
121
+ * Compute node positions for the graph. Lanes flow left→right; within a lane,
122
+ * nodes stack top-down in input order (stable, so the render is deterministic).
123
+ */
124
+ export function layoutGraph(
125
+ nodes: GraphNode[],
126
+ edges: GraphEdge[],
127
+ layout: GraphLayout = "layered",
128
+ metrics: GraphMetrics = DEFAULT_METRICS,
129
+ ): GraphLayoutResult {
130
+ const { nodeW, nodeH, gapX, gapY, pad } = metrics;
131
+ const lane = assignLanes(nodes, edges, layout);
132
+
133
+ const nextRow = new Map<number, number>(); // lane → next free row
134
+ const positioned: PositionedNode[] = nodes.map((n) => {
135
+ const l = lane.get(n.id) ?? 0;
136
+ const r = nextRow.get(l) ?? 0;
137
+ nextRow.set(l, r + 1);
138
+ return {
139
+ ...n,
140
+ lane: l,
141
+ row: r,
142
+ x: pad + l * (nodeW + gapX),
143
+ y: pad + r * (nodeH + gapY),
144
+ };
145
+ });
146
+
147
+ const lanes = positioned.reduce((m, n) => Math.max(m, n.lane + 1), 0);
148
+ const maxRows = [...nextRow.values()].reduce((m, v) => Math.max(m, v), 0);
149
+ const width = lanes > 0 ? pad * 2 + lanes * nodeW + (lanes - 1) * gapX : pad * 2;
150
+ const height = maxRows > 0 ? pad * 2 + maxRows * nodeH + (maxRows - 1) * gapY : pad * 2;
151
+
152
+ const byId = new Map(positioned.map((n) => [n.id, n]));
153
+ return { nodes: positioned, byId, width, height };
154
+ }