treelines 0.0.0-stage → 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/dist/index.js ADDED
@@ -0,0 +1,525 @@
1
+ "use client";
2
+
3
+ // src/layout.ts
4
+ var sizeOf = (size, ...args) => typeof size === "function" ? size(...args) : size;
5
+ function connectorPath(start, end, shape = "curve", direction = "right") {
6
+ const { x: x1, y: y1 } = start;
7
+ const { x: x2, y: y2 } = end;
8
+ if (shape === "straight") return `M${x1} ${y1} L${x2} ${y2}`;
9
+ if (direction === "right") {
10
+ const mx = (x1 + x2) / 2;
11
+ return shape === "elbow" ? `M${x1} ${y1} H${mx} V${y2} H${x2}` : `M${x1} ${y1} C${mx} ${y1}, ${mx} ${y2}, ${x2} ${y2}`;
12
+ }
13
+ const my = (y1 + y2) / 2;
14
+ return shape === "elbow" ? `M${x1} ${y1} V${my} H${x2} V${y2}` : `M${x1} ${y1} C${x1} ${my}, ${x2} ${my}, ${x2} ${y2}`;
15
+ }
16
+ function layout(options) {
17
+ const { lanes, rootSize, nodeSize, padding = 0, start = 0, direction = "right", shape = "curve", compare } = options;
18
+ const columnGap = options.gap?.column ?? 0;
19
+ const rowGap = options.gap?.row ?? 0;
20
+ const laneGap = options.gap?.lane ?? 0;
21
+ const open = new Set(options.open ?? []);
22
+ const right = direction === "right";
23
+ const box = (size) => right ? { mainSize: size.width, crossSize: size.height } : { mainSize: size.height, crossSize: size.width };
24
+ const rect = (b) => right ? { x: b.main, y: b.cross, width: b.mainSize, height: b.crossSize } : { x: b.cross, y: b.main, width: b.crossSize, height: b.mainSize };
25
+ const point = (main, cross) => right ? { x: main, y: cross } : { x: cross, y: main };
26
+ const placed = [];
27
+ let cursor = start;
28
+ let far = 0;
29
+ for (const lane of lanes) {
30
+ const root = lane.root;
31
+ const isOpen = open.has(root);
32
+ const unfolded = isOpen && lane.edges.length > 0;
33
+ const pos = /* @__PURE__ */ new Map([[root, { main: 0, cross: cursor, ...box(sizeOf(rootSize, root)) }]]);
34
+ const depth = /* @__PURE__ */ new Map([[root, 0]]);
35
+ const order = [root];
36
+ let bottom = cursor + pos.get(root).crossSize;
37
+ far = Math.max(far, pos.get(root).mainSize);
38
+ if (unfolded) {
39
+ for (let i = 0; i < order.length; i++) {
40
+ for (const [a, b] of lane.edges) {
41
+ if (a === order[i] && !depth.has(b)) {
42
+ depth.set(b, depth.get(a) + 1);
43
+ order.push(b);
44
+ }
45
+ }
46
+ }
47
+ const columns = [];
48
+ for (const id of order.slice(1)) (columns[depth.get(id)] ??= []).push(id);
49
+ let mainAt = pos.get(root).mainSize + columnGap;
50
+ for (let c = 1; c < columns.length; c++) {
51
+ const ids = columns[c] ?? [];
52
+ const sizes = new Map(ids.map((id) => [id, box(sizeOf(nodeSize, id, c))]));
53
+ const width = Math.max(0, ...[...sizes.values()].map((s) => s.mainSize));
54
+ const want = ids.map((id, index) => {
55
+ const at = lane.edges.filter(([a, b]) => b === id && pos.has(a)).map(([a]) => pos.get(a).cross);
56
+ return { id, index, cross: at.length ? at.reduce((s, y) => s + y, 0) / at.length : cursor };
57
+ }).toSorted((a, b) => a.cross - b.cross || (compare ? compare(a.id, b.id) : a.index - b.index));
58
+ let next = -Infinity;
59
+ for (const w of want) {
60
+ const size = sizes.get(w.id);
61
+ const cross = Math.max(w.cross, next, cursor);
62
+ pos.set(w.id, { main: mainAt, cross, ...size });
63
+ next = cross + size.crossSize + rowGap;
64
+ bottom = Math.max(bottom, cross + size.crossSize);
65
+ }
66
+ far = Math.max(far, mainAt + width);
67
+ mainAt += width + columnGap;
68
+ }
69
+ }
70
+ const edges = [];
71
+ if (unfolded) {
72
+ for (const [a, b, via] of lane.edges) {
73
+ const p = pos.get(a);
74
+ const q = pos.get(b);
75
+ if (!p || !q) continue;
76
+ const startPoint = point(p.main + p.mainSize, p.cross + p.crossSize / 2);
77
+ const endPoint = point(q.main, q.cross + q.crossSize / 2);
78
+ edges.push({
79
+ from: a,
80
+ to: b,
81
+ via: via ?? [],
82
+ start: startPoint,
83
+ end: endPoint,
84
+ mid: { x: (startPoint.x + endPoint.x) / 2, y: (startPoint.y + endPoint.y) / 2 },
85
+ path: connectorPath(startPoint, endPoint, shape, direction)
86
+ });
87
+ }
88
+ }
89
+ placed.push({
90
+ root,
91
+ open: isOpen,
92
+ unfolded,
93
+ nodes: order.map((id) => ({ id, depth: depth.get(id), rect: rect(pos.get(id)) })),
94
+ edges,
95
+ ...unfolded ? { band: { start: cursor - padding, size: bottom - cursor + 2 * padding } } : {}
96
+ });
97
+ cursor = bottom + (unfolded ? 2 * padding + laneGap : laneGap);
98
+ }
99
+ return right ? { lanes: placed, width: far, height: cursor } : { lanes: placed, width: cursor, height: far };
100
+ }
101
+
102
+ // src/graph.ts
103
+ function trace(edges, id) {
104
+ const up = /* @__PURE__ */ new Set([id]);
105
+ const down = /* @__PURE__ */ new Set([id]);
106
+ for (let changed = true; changed; ) {
107
+ changed = false;
108
+ for (const [a, b] of edges) {
109
+ if (up.has(b) && !up.has(a)) {
110
+ up.add(a);
111
+ changed = true;
112
+ }
113
+ if (down.has(a) && !down.has(b)) {
114
+ down.add(b);
115
+ changed = true;
116
+ }
117
+ }
118
+ }
119
+ return { up, down };
120
+ }
121
+ var onTrace = (t, [a, b]) => t.up.has(a) && t.up.has(b) || t.down.has(a) && t.down.has(b);
122
+ function foldPassThrough(edges, root, keep) {
123
+ const kids = /* @__PURE__ */ new Map();
124
+ const parents = /* @__PURE__ */ new Map();
125
+ for (const [a, b] of edges) {
126
+ kids.set(a, [...kids.get(a) ?? [], b]);
127
+ parents.set(b, [...parents.get(b) ?? [], a]);
128
+ }
129
+ const kept = (id) => id === root || keep(id) || kids.get(id)?.length !== 1 || parents.get(id)?.length !== 1;
130
+ const out = [];
131
+ for (const [a, b] of edges) {
132
+ if (!kept(a)) continue;
133
+ const via = [];
134
+ let at = b;
135
+ while (!kept(at) && !via.includes(at)) {
136
+ via.push(at);
137
+ at = kids.get(at)[0];
138
+ }
139
+ if (at !== a) out.push([a, at, via]);
140
+ }
141
+ return out;
142
+ }
143
+ function fromTree(roots, getId, getChildren) {
144
+ const nodes = /* @__PURE__ */ new Map();
145
+ const lanes = roots.map((root) => {
146
+ const edges = [];
147
+ const seen = /* @__PURE__ */ new Set();
148
+ const visited = /* @__PURE__ */ new Set();
149
+ const walk = (node) => {
150
+ const id = getId(node);
151
+ nodes.set(id, node);
152
+ if (visited.has(id)) return;
153
+ visited.add(id);
154
+ for (const child of getChildren(node) ?? []) {
155
+ const to = getId(child);
156
+ const key = `${String(id)}\0${String(to)}`;
157
+ if (!seen.has(key)) {
158
+ seen.add(key);
159
+ edges.push([id, to]);
160
+ }
161
+ walk(child);
162
+ }
163
+ };
164
+ walk(root);
165
+ return { root: getId(root), edges };
166
+ });
167
+ return { lanes, nodes };
168
+ }
169
+
170
+ // src/react.tsx
171
+ import {
172
+ cloneElement,
173
+ createContext,
174
+ isValidElement,
175
+ useCallback,
176
+ useContext,
177
+ useEffect,
178
+ useLayoutEffect,
179
+ useMemo,
180
+ useRef,
181
+ useState
182
+ } from "react";
183
+ import { Fragment, jsx } from "react/jsx-runtime";
184
+ var resolve = (value, state) => typeof value === "function" ? value(state) : value;
185
+ var useIsomorphicLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;
186
+ function useControllable(value, defaultValue, onChange) {
187
+ const [own, setOwn] = useState(defaultValue);
188
+ const controlled = value !== void 0;
189
+ const current = controlled ? value : own;
190
+ const set = useCallback(
191
+ (next) => {
192
+ if (!controlled) setOwn(next);
193
+ onChange?.(next);
194
+ },
195
+ [controlled, onChange]
196
+ );
197
+ return [current, set];
198
+ }
199
+ var GraphContext = createContext(null);
200
+ var NodeContext = createContext(null);
201
+ function useGraphContext(part) {
202
+ const ctx = useContext(GraphContext);
203
+ if (!ctx) throw new Error(`treelines: <Graph.${part}> must be inside <Graph.Root>`);
204
+ return ctx;
205
+ }
206
+ var keyOf = (lane, id) => `${String(lane)}\0${String(id)}`;
207
+ var sizeKey = (id, root) => `${root ? "r" : "n"}\0${String(id)}`;
208
+ function Root(props) {
209
+ const { lanes, rootSize, nodeSize, gap, padding, start, direction = "right", shape, compare, multiple = false, keyboardNavigation = true, children } = props;
210
+ const [open, setOpen] = useControllable(props.open, props.defaultOpen ?? [], props.onOpenChange);
211
+ const [selected, setSelected] = useControllable(props.selected, props.defaultSelected ?? null, props.onSelectedChange);
212
+ const [hovered, setHovered] = useState(null);
213
+ const [sizes, setSizes] = useState(() => /* @__PURE__ */ new Map());
214
+ const measuredRoots = rootSize === void 0;
215
+ const measuredNodes = nodeSize === void 0;
216
+ const result = useMemo(
217
+ () => layout({
218
+ lanes,
219
+ open,
220
+ rootSize: rootSize ?? ((id) => sizes.get(sizeKey(id, true)) ?? { width: 0, height: 0 }),
221
+ nodeSize: nodeSize ?? ((id) => sizes.get(sizeKey(id, false)) ?? { width: 0, height: 0 }),
222
+ ...gap ? { gap } : {},
223
+ ...padding !== void 0 ? { padding } : {},
224
+ ...start !== void 0 ? { start } : {},
225
+ direction,
226
+ ...shape ? { shape } : {},
227
+ ...compare ? { compare } : {}
228
+ }),
229
+ [lanes, open, rootSize, nodeSize, sizes, gap, padding, start, direction, shape, compare]
230
+ );
231
+ const measuring = (measuredRoots || measuredNodes) && result.lanes.some((lane) => lane.nodes.some((n) => (n.depth === 0 ? measuredRoots : measuredNodes) && !sizes.has(sizeKey(n.id, n.depth === 0))));
232
+ const report = useCallback((id, root, element) => {
233
+ if (!element) return;
234
+ const size = { width: element.offsetWidth, height: element.offsetHeight };
235
+ const key = sizeKey(id, root);
236
+ setSizes((current) => {
237
+ const known = current.get(key);
238
+ if (known && known.width === size.width && known.height === size.height) return current;
239
+ return new Map(current).set(key, size);
240
+ });
241
+ }, []);
242
+ const active = hovered ?? selected;
243
+ const traced = useMemo(() => {
244
+ if (!active) return null;
245
+ const lane = result.lanes.find((l) => l.root === active.lane);
246
+ if (!lane?.unfolded) return null;
247
+ const edges = lanes.find((l) => l.root === active.lane)?.edges ?? [];
248
+ return { lane: active.lane, trace: trace(edges, active.id) };
249
+ }, [active, result.lanes, lanes]);
250
+ const nodeState = useCallback(
251
+ (lane, id, depth) => {
252
+ const placed = result.lanes.find((l) => l.root === lane);
253
+ const root = depth === 0;
254
+ const expandable = root && (lanes.find((l) => l.root === lane)?.edges.length ?? 0) > 0;
255
+ const highlighted = !!traced && (traced.trace.up.has(id) || traced.trace.down.has(id));
256
+ return {
257
+ root,
258
+ depth,
259
+ expandable,
260
+ expanded: root && !!placed?.unfolded,
261
+ selected: !!selected && selected.lane === lane && selected.id === id,
262
+ highlighted,
263
+ dimmed: !!traced && !highlighted,
264
+ measuring: (root ? measuredRoots : measuredNodes) && !sizes.has(sizeKey(id, root))
265
+ };
266
+ },
267
+ [result.lanes, lanes, traced, selected, measuredRoots, measuredNodes, sizes]
268
+ );
269
+ const edgeState = useCallback(
270
+ (lane, edge) => {
271
+ const highlighted = !!traced && onTrace(traced.trace, [edge.from, edge.to]);
272
+ return { highlighted, dimmed: !!traced && !highlighted };
273
+ },
274
+ [traced]
275
+ );
276
+ const toggleLane = useCallback(
277
+ (root) => {
278
+ const expandable = (lanes.find((l) => l.root === root)?.edges.length ?? 0) > 0;
279
+ const isOpen = open.includes(root);
280
+ if (multiple) {
281
+ if (expandable) setOpen(isOpen ? open.filter((r) => r !== root) : [...open, root]);
282
+ } else {
283
+ setOpen(isOpen || !expandable ? [] : [root]);
284
+ }
285
+ setSelected({ lane: root, id: root });
286
+ setHovered(null);
287
+ },
288
+ [lanes, open, multiple, setOpen, setSelected]
289
+ );
290
+ const select = useCallback(
291
+ (lane, id) => setSelected(selected && selected.lane === lane && selected.id === id ? null : { lane, id }),
292
+ [selected, setSelected]
293
+ );
294
+ const elements = useRef(/* @__PURE__ */ new Map());
295
+ const register = useCallback((key, element) => {
296
+ if (element) elements.current.set(key, element);
297
+ else elements.current.delete(key);
298
+ }, []);
299
+ const focusFrom = useCallback(
300
+ (lane, id, key) => {
301
+ const placed = result.lanes.find((l) => l.root === lane);
302
+ const here = placed?.nodes.find((n) => n.id === id);
303
+ if (!placed || !here) return false;
304
+ const right = direction === "right";
305
+ const main = (r) => right ? r.x : r.y;
306
+ const cross = (r) => right ? r.y : r.x;
307
+ let target;
308
+ if (key === "next" || key === "previous") {
309
+ const sign = key === "next" ? 1 : -1;
310
+ if (here.depth === 0) {
311
+ const at = result.lanes.indexOf(placed);
312
+ const other = result.lanes[at + sign];
313
+ if (other) target = { lane: other.root, id: other.root };
314
+ } else {
315
+ const column = placed.nodes.filter((n) => n.depth === here.depth && sign * (cross(n.rect) - cross(here.rect)) > 0);
316
+ const nearest = column.toSorted((a, b) => sign * (cross(a.rect) - cross(b.rect)))[0];
317
+ if (nearest) target = { lane, id: nearest.id };
318
+ }
319
+ } else {
320
+ const depth = here.depth + (key === "deeper" ? 1 : -1);
321
+ if (key === "deeper" && here.depth === 0 && !placed.unfolded) {
322
+ if ((lanes.find((l) => l.root === lane)?.edges.length ?? 0) > 0) toggleLane(lane);
323
+ return true;
324
+ }
325
+ const column = placed.nodes.filter((n) => n.depth === depth);
326
+ const nearest = column.toSorted((a, b) => Math.abs(cross(a.rect) - cross(here.rect)) - Math.abs(cross(b.rect) - cross(here.rect)) || main(a.rect) - main(b.rect))[0];
327
+ if (nearest) target = { lane, id: nearest.id };
328
+ }
329
+ if (!target) return false;
330
+ elements.current.get(keyOf(target.lane, target.id))?.focus();
331
+ return true;
332
+ },
333
+ [result.lanes, direction, lanes, toggleLane]
334
+ );
335
+ const value = useMemo(() => ({
336
+ layout: result,
337
+ lanes,
338
+ direction,
339
+ open,
340
+ selected,
341
+ traced,
342
+ measuredRoots,
343
+ measuredNodes,
344
+ measuring,
345
+ keyboardNavigation,
346
+ nodeState,
347
+ edgeState,
348
+ toggleLane,
349
+ select,
350
+ hover: setHovered,
351
+ report,
352
+ register,
353
+ focusFrom
354
+ }), [result, lanes, direction, open, selected, traced, measuredRoots, measuredNodes, measuring, keyboardNavigation, nodeState, edgeState, toggleLane, select, report, register, focusFrom]);
355
+ return /* @__PURE__ */ jsx(GraphContext.Provider, { value, children });
356
+ }
357
+ function Canvas({ className, style, children, ...rest }) {
358
+ const ctx = useGraphContext("Canvas");
359
+ const state = { width: ctx.layout.width, height: ctx.layout.height, measuring: ctx.measuring };
360
+ return /* @__PURE__ */ jsx(
361
+ "div",
362
+ {
363
+ ...rest,
364
+ "data-measuring": ctx.measuring ? "" : void 0,
365
+ className: resolve(className, state),
366
+ style: { position: "relative", width: state.width, height: state.height, ...ctx.measuring ? { visibility: "hidden" } : {}, ...resolve(style, state) },
367
+ children
368
+ }
369
+ );
370
+ }
371
+ function Bands({ children }) {
372
+ const ctx = useGraphContext("Bands");
373
+ return /* @__PURE__ */ jsx(Fragment, { children: ctx.layout.lanes.flatMap(
374
+ (lane) => lane.band ? [/* @__PURE__ */ jsx(BandSlot, { children: children({ lane: lane.root, start: lane.band.start, size: lane.band.size }) }, keyOf(lane.root, "band"))] : []
375
+ ) });
376
+ }
377
+ var BandSlot = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
378
+ function Connectors({ pathClassName, pathStyle, children, ...rest }) {
379
+ const ctx = useGraphContext("Connectors");
380
+ const edges = useEdges();
381
+ return /* @__PURE__ */ jsx("svg", { "aria-hidden": true, width: ctx.layout.width, height: ctx.layout.height, ...rest, children: edges.map(
382
+ (edge) => children ? /* @__PURE__ */ jsx(EdgeSlot, { children: children(edge) }, keyOf(edge.lane, `${String(edge.from)}>${String(edge.to)}`)) : /* @__PURE__ */ jsx(
383
+ "path",
384
+ {
385
+ d: edge.path,
386
+ fill: "none",
387
+ "data-highlighted": edge.state.highlighted ? "" : void 0,
388
+ "data-dimmed": edge.state.dimmed ? "" : void 0,
389
+ className: resolve(pathClassName, edge),
390
+ style: resolve(pathStyle, edge)
391
+ },
392
+ keyOf(edge.lane, `${String(edge.from)}>${String(edge.to)}`)
393
+ )
394
+ ) });
395
+ }
396
+ var EdgeSlot = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
397
+ function useEdges() {
398
+ const ctx = useGraphContext("Connectors");
399
+ return ctx.layout.lanes.flatMap((lane) => lane.edges.map((edge) => ({ ...edge, lane: lane.root, state: ctx.edgeState(lane.root, edge) })));
400
+ }
401
+ function Markers({ children }) {
402
+ const edges = useEdges();
403
+ return /* @__PURE__ */ jsx(Fragment, { children: edges.filter((edge) => edge.via.length > 0).map((edge) => /* @__PURE__ */ jsx(EdgeSlot, { children: children(edge) }, keyOf(edge.lane, `${String(edge.from)}>${String(edge.to)}`))) });
404
+ }
405
+ function Nodes({ children }) {
406
+ const ctx = useGraphContext("Nodes");
407
+ return /* @__PURE__ */ jsx(Fragment, { children: ctx.layout.lanes.flatMap(
408
+ (lane) => lane.nodes.map((n) => {
409
+ const info = { lane: lane.root, id: n.id, depth: n.depth, rect: n.rect, state: ctx.nodeState(lane.root, n.id, n.depth) };
410
+ return /* @__PURE__ */ jsx(NodeSlot, { info, render: children }, keyOf(lane.root, n.id));
411
+ })
412
+ ) });
413
+ }
414
+ function NodeSlot({ info, render }) {
415
+ const { lane, id, depth, rect, state } = info;
416
+ const value = useMemo(
417
+ () => ({ lane, id, depth, rect, state }),
418
+ // a new object only when something in it changed
419
+ // oxlint-disable-next-line react-hooks/exhaustive-deps
420
+ [lane, id, depth, rect.x, rect.y, rect.width, rect.height, state.root, state.expandable, state.expanded, state.selected, state.highlighted, state.dimmed, state.measuring]
421
+ );
422
+ return /* @__PURE__ */ jsx(NodeContext.Provider, { value, children: render(value) });
423
+ }
424
+ function Node({ render, className, style, onClick, onMouseEnter, onMouseLeave, onFocus, onBlur, onKeyDown, children, ...rest }) {
425
+ const ctx = useGraphContext("Node");
426
+ const node = useContext(NodeContext);
427
+ if (!node) throw new Error("treelines: <Graph.Node> must be rendered from <Graph.Nodes>");
428
+ const { lane, id, rect, state } = node;
429
+ const key = keyOf(lane, id);
430
+ const measured = state.root ? ctx.measuredRoots : ctx.measuredNodes;
431
+ const { register, report } = ctx;
432
+ const [element, setElement] = useState(null);
433
+ const ref = useCallback(
434
+ (el) => {
435
+ setElement(el);
436
+ register(key, el);
437
+ },
438
+ [key, register]
439
+ );
440
+ const root = state.root;
441
+ useIsomorphicLayoutEffect(() => {
442
+ if (!measured || !element) return;
443
+ report(id, root, element);
444
+ if (typeof ResizeObserver === "undefined") return;
445
+ const observer = new ResizeObserver(() => report(id, root, element));
446
+ observer.observe(element);
447
+ return () => observer.disconnect();
448
+ }, [measured, element, id, root, report]);
449
+ const position = measured ? { position: "absolute", left: rect.x, top: rect.y } : { position: "absolute", left: rect.x, top: rect.y, width: rect.width, height: rect.height };
450
+ const props = {
451
+ ...rest,
452
+ "data-root": state.root ? "" : void 0,
453
+ "data-expanded": state.expanded ? "" : void 0,
454
+ "data-selected": state.selected ? "" : void 0,
455
+ "data-highlighted": state.highlighted ? "" : void 0,
456
+ "data-dimmed": state.dimmed ? "" : void 0,
457
+ "data-depth": String(state.depth),
458
+ ...state.root ? { "aria-expanded": state.expandable ? state.expanded : void 0 } : { "aria-pressed": state.selected },
459
+ className: resolve(className, state),
460
+ style: { ...position, ...resolve(style, state) },
461
+ onClick: (event) => {
462
+ onClick?.(event);
463
+ if (event.defaultPrevented) return;
464
+ if (state.root) ctx.toggleLane(lane);
465
+ else ctx.select(lane, id);
466
+ },
467
+ onMouseEnter: (event) => {
468
+ onMouseEnter?.(event);
469
+ if (!event.defaultPrevented) ctx.hover({ lane, id });
470
+ },
471
+ onMouseLeave: (event) => {
472
+ onMouseLeave?.(event);
473
+ if (!event.defaultPrevented) ctx.hover(null);
474
+ },
475
+ onFocus: (event) => {
476
+ onFocus?.(event);
477
+ if (!event.defaultPrevented) ctx.hover({ lane, id });
478
+ },
479
+ onBlur: (event) => {
480
+ onBlur?.(event);
481
+ if (!event.defaultPrevented) ctx.hover(null);
482
+ },
483
+ onKeyDown: (event) => {
484
+ onKeyDown?.(event);
485
+ if (event.defaultPrevented || !ctx.keyboardNavigation) return;
486
+ const right = ctx.direction === "right";
487
+ const move = { ArrowDown: right ? "next" : "deeper", ArrowUp: right ? "previous" : "shallower", ArrowRight: right ? "deeper" : "next", ArrowLeft: right ? "shallower" : "previous" }[event.key];
488
+ if (move && ctx.focusFrom(lane, id, move)) event.preventDefault();
489
+ }
490
+ };
491
+ if (typeof render === "function") return render({ ...props, ref }, state);
492
+ if (isValidElement(render)) return cloneElement(render, { ...props, ref }, children ?? render.props.children);
493
+ return /* @__PURE__ */ jsx("button", { type: "button", ...props, ref, children });
494
+ }
495
+ function useGraph() {
496
+ const ctx = useGraphContext("useGraph");
497
+ return {
498
+ layout: ctx.layout,
499
+ open: ctx.open,
500
+ selected: ctx.selected,
501
+ /** The routes being traced, and in which lane. */
502
+ traced: ctx.traced,
503
+ measuring: ctx.measuring,
504
+ toggleLane: ctx.toggleLane,
505
+ select: ctx.select
506
+ };
507
+ }
508
+ function useNode() {
509
+ const node = useContext(NodeContext);
510
+ if (!node) throw new Error("treelines: useNode() must be used inside <Graph.Nodes>");
511
+ return node;
512
+ }
513
+ var Graph = { Root, Canvas, Bands, Connectors, Markers, Nodes, Node };
514
+ export {
515
+ Graph,
516
+ connectorPath,
517
+ foldPassThrough,
518
+ fromTree,
519
+ layout,
520
+ onTrace,
521
+ trace,
522
+ useGraph,
523
+ useNode
524
+ };
525
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/layout.ts","../src/graph.ts","../src/react.tsx"],"sourcesContent":["/**\n * The layout: where every node goes and the path of every connector, from the graph and the node sizes alone. No DOM and\n * no React, so it runs anywhere (the server included) and gives the same numbers every time.\n *\n * The shape it draws: a list of lanes, each a root you can unfold. An unfolded lane shows the graph below its root\n * beside it, in columns by depth: a node's column is its distance from the root, its row follows its parents (the average\n * of where they are), pushed further along so nothing overlaps. Lanes stack, the open ones with room around them.\n *\n * \"Main\" is the axis the graph grows along (x when it grows to the right), \"cross\" the one lanes and rows stack along.\n */\n\nexport type Id = string | number;\n\nexport interface Point {\n x: number;\n y: number;\n}\n\nexport interface Size {\n width: number;\n height: number;\n}\n\nexport interface Rect extends Point, Size {}\n\n/** From, to, and optionally what was folded into it (see `foldPassThrough`): opaque to the layout, counted by renderers. */\nexport type Edge<I extends Id = Id, V = unknown> = readonly [from: I, to: I, via?: readonly V[]];\n\n/** A root and the graph that unfolds from it. The edges should only reach nodes below the root. */\nexport interface Lane<I extends Id = Id, V = unknown> {\n root: I;\n edges: readonly Edge<I, V>[];\n}\n\n/** Which way the graph grows from its root: to the right (lanes stack downwards), or down (lanes sit side by side). */\nexport type Direction = \"right\" | \"down\";\n\n/** How a connector runs: a smooth S-curve, right angles, or a straight line. */\nexport type ConnectorShape = \"curve\" | \"elbow\" | \"straight\";\n\nexport interface LayoutOptions<I extends Id = Id, V = unknown> {\n lanes: readonly Lane<I, V>[];\n /** The roots whose graph is unfolded. A lane without edges has nothing to unfold and stays folded. */\n open?: Iterable<I>;\n /** The size of a lane's root. */\n rootSize: Size | ((id: I) => Size);\n /** The size of the nodes below it; `depth` is 1 for the root's children. */\n nodeSize: Size | ((id: I, depth: number) => Size);\n gap?: {\n /** Between columns, from the root's column on. */\n column?: number;\n /** Between nodes in one column. */\n row?: number;\n /** Between lanes. */\n lane?: number;\n };\n /** Room kept around an unfolded lane (its `band`), on both sides along the cross axis. */\n padding?: number;\n /** Where the first lane starts along the cross axis. */\n start?: number;\n direction?: Direction;\n shape?: ConnectorShape;\n /** Breaks ties between nodes that want the same row: by default the order they first appear in. */\n compare?: (a: I, b: I) => number;\n}\n\nexport interface PlacedNode<I extends Id = Id> {\n id: I;\n /** 0 for the root. */\n depth: number;\n rect: Rect;\n}\n\nexport interface PlacedEdge<I extends Id = Id, V = unknown> {\n from: I;\n to: I;\n via: readonly V[];\n /** Where it leaves `from` (the middle of its far side) and enters `to` (the middle of its near side). */\n start: Point;\n end: Point;\n /** Halfway between them: where a \"+N\" marker for the folded nodes goes. */\n mid: Point;\n /** An SVG path: `<path d={edge.path} />`. */\n path: string;\n}\n\nexport interface PlacedLane<I extends Id = Id, V = unknown> {\n root: I;\n /** Asked to be open (see `LayoutOptions.open`). */\n open: boolean;\n /** Open and with something to show. */\n unfolded: boolean;\n /** The root first, then the nodes below it in reading order (breadth first), which is also a good tab order. */\n nodes: PlacedNode<I>[];\n edges: PlacedEdge<I, V>[];\n /**\n * The room an unfolded lane takes along the cross axis, padding included: for a background behind it. It runs the whole\n * width of the layout along the main axis.\n */\n band?: { start: number; size: number };\n}\n\nexport interface Layout<I extends Id = Id, V = unknown> {\n lanes: PlacedLane<I, V>[];\n /** The far edge of the furthest node, and where the next lane would start: the layout's size. */\n width: number;\n height: number;\n}\n\n/** Positions along the two axes, before they become x and y. */\ninterface Box {\n main: number;\n cross: number;\n mainSize: number;\n crossSize: number;\n}\n\nconst sizeOf = <A extends unknown[]>(size: Size | ((...args: A) => Size), ...args: A): Size => (typeof size === \"function\" ? size(...args) : size);\n\n/** Builds a connector's SVG path between two points, the graph growing in `direction`. */\nexport function connectorPath(start: Point, end: Point, shape: ConnectorShape = \"curve\", direction: Direction = \"right\"): string {\n const { x: x1, y: y1 } = start;\n const { x: x2, y: y2 } = end;\n if (shape === \"straight\") return `M${x1} ${y1} L${x2} ${y2}`;\n if (direction === \"right\") {\n const mx = (x1 + x2) / 2;\n return shape === \"elbow\" ? `M${x1} ${y1} H${mx} V${y2} H${x2}` : `M${x1} ${y1} C${mx} ${y1}, ${mx} ${y2}, ${x2} ${y2}`;\n }\n const my = (y1 + y2) / 2;\n return shape === \"elbow\" ? `M${x1} ${y1} V${my} H${x2} V${y2}` : `M${x1} ${y1} C${x1} ${my}, ${x2} ${my}, ${x2} ${y2}`;\n}\n\nexport function layout<I extends Id = Id, V = unknown>(options: LayoutOptions<I, V>): Layout<I, V> {\n const { lanes, rootSize, nodeSize, padding = 0, start = 0, direction = \"right\", shape = \"curve\", compare } = options;\n const columnGap = options.gap?.column ?? 0;\n const rowGap = options.gap?.row ?? 0;\n const laneGap = options.gap?.lane ?? 0;\n const open = new Set(options.open ?? []);\n const right = direction === \"right\";\n const box = (size: Size): Pick<Box, \"mainSize\" | \"crossSize\"> => (right ? { mainSize: size.width, crossSize: size.height } : { mainSize: size.height, crossSize: size.width });\n const rect = (b: Box): Rect => (right ? { x: b.main, y: b.cross, width: b.mainSize, height: b.crossSize } : { x: b.cross, y: b.main, width: b.crossSize, height: b.mainSize });\n const point = (main: number, cross: number): Point => (right ? { x: main, y: cross } : { x: cross, y: main });\n\n const placed: PlacedLane<I, V>[] = [];\n let cursor = start;\n let far = 0;\n for (const lane of lanes) {\n const root = lane.root;\n const isOpen = open.has(root);\n const unfolded = isOpen && lane.edges.length > 0;\n const pos = new Map<I, Box>([[root, { main: 0, cross: cursor, ...box(sizeOf(rootSize, root)) }]]);\n const depth = new Map<I, number>([[root, 0]]);\n const order: I[] = [root];\n let bottom = cursor + pos.get(root)!.crossSize;\n far = Math.max(far, pos.get(root)!.mainSize);\n\n if (unfolded) {\n // breadth first, in the edges' order: a node's depth is its shortest distance from the root\n for (let i = 0; i < order.length; i++) {\n for (const [a, b] of lane.edges) {\n if (a === order[i] && !depth.has(b)) {\n depth.set(b, depth.get(a)! + 1);\n order.push(b);\n }\n }\n }\n const columns: I[][] = [];\n for (const id of order.slice(1)) (columns[depth.get(id)!] ??= []).push(id);\n let mainAt = pos.get(root)!.mainSize + columnGap;\n for (let c = 1; c < columns.length; c++) {\n const ids = columns[c] ?? [];\n const sizes = new Map(ids.map((id) => [id, box(sizeOf(nodeSize, id, c))]));\n const width = Math.max(0, ...[...sizes.values()].map((s) => s.mainSize));\n // each node wants to sit level with its parents (the ones already placed, in earlier columns)\n const want = ids\n .map((id, index) => {\n const at = lane.edges.filter(([a, b]) => b === id && pos.has(a)).map(([a]) => pos.get(a)!.cross);\n return { id, index, cross: at.length ? at.reduce((s, y) => s + y, 0) / at.length : cursor };\n })\n .toSorted((a, b) => a.cross - b.cross || (compare ? compare(a.id, b.id) : a.index - b.index));\n let next = -Infinity;\n for (const w of want) {\n const size = sizes.get(w.id)!;\n const cross = Math.max(w.cross, next, cursor);\n pos.set(w.id, { main: mainAt, cross, ...size });\n next = cross + size.crossSize + rowGap;\n bottom = Math.max(bottom, cross + size.crossSize);\n }\n far = Math.max(far, mainAt + width);\n mainAt += width + columnGap;\n }\n }\n\n const edges: PlacedEdge<I, V>[] = [];\n if (unfolded) {\n for (const [a, b, via] of lane.edges) {\n const p = pos.get(a);\n const q = pos.get(b);\n if (!p || !q) continue;\n const startPoint = point(p.main + p.mainSize, p.cross + p.crossSize / 2);\n const endPoint = point(q.main, q.cross + q.crossSize / 2);\n edges.push({\n from: a,\n to: b,\n via: via ?? [],\n start: startPoint,\n end: endPoint,\n mid: { x: (startPoint.x + endPoint.x) / 2, y: (startPoint.y + endPoint.y) / 2 },\n path: connectorPath(startPoint, endPoint, shape, direction),\n });\n }\n }\n\n placed.push({\n root,\n open: isOpen,\n unfolded,\n nodes: order.map((id) => ({ id, depth: depth.get(id)!, rect: rect(pos.get(id)!) })),\n edges,\n ...(unfolded ? { band: { start: cursor - padding, size: bottom - cursor + 2 * padding } } : {}),\n });\n cursor = bottom + (unfolded ? 2 * padding + laneGap : laneGap);\n }\n\n return right ? { lanes: placed, width: far, height: cursor } : { lanes: placed, width: cursor, height: far };\n}\n","import type { Edge, Id, Lane } from \"./layout\";\n\n/**\n * Working with the graph itself, apart from where it is drawn: the routes through a node, folding the nodes that only\n * pass a route on, and turning nested data into lanes.\n */\n\nexport interface Trace<I extends Id = Id> {\n /** The node and everything that leads to it. */\n up: Set<I>;\n /** The node and everything it leads to. */\n down: Set<I>;\n}\n\n/** Every route through `id`: what leads to it and what it leads to. For highlighting a node's routes on hover. */\nexport function trace<I extends Id>(edges: readonly Edge<I, unknown>[], id: I): Trace<I> {\n const up = new Set([id]);\n const down = new Set([id]);\n for (let changed = true; changed; ) {\n changed = false;\n for (const [a, b] of edges) {\n if (up.has(b) && !up.has(a)) {\n up.add(a);\n changed = true;\n }\n if (down.has(a) && !down.has(b)) {\n down.add(b);\n changed = true;\n }\n }\n }\n return { up, down };\n}\n\n/** Whether an edge lies on a route through the traced node: both ends lead to it, or both come from it. */\nexport const onTrace = <I extends Id>(t: Trace<I>, [a, b]: Edge<I, unknown>): boolean => (t.up.has(a) && t.up.has(b)) || (t.down.has(a) && t.down.has(b));\n\n/**\n * Folds the nodes that only pass a route on: a node that is not the root, not kept, and has exactly one parent and one\n * child becomes part of the edge around it, listed in its `via`. A long chain of such nodes becomes one edge with a \"+N\".\n * A loop that folds back onto where it started is left out.\n */\nexport function foldPassThrough<I extends Id>(edges: readonly Edge<I, unknown>[], root: I, keep: (id: I) => boolean): Edge<I, I>[] {\n const kids = new Map<I, I[]>();\n const parents = new Map<I, I[]>();\n for (const [a, b] of edges) {\n kids.set(a, [...(kids.get(a) ?? []), b]);\n parents.set(b, [...(parents.get(b) ?? []), a]);\n }\n const kept = (id: I) => id === root || keep(id) || kids.get(id)?.length !== 1 || parents.get(id)?.length !== 1;\n const out: Edge<I, I>[] = [];\n for (const [a, b] of edges) {\n if (!kept(a)) continue;\n const via: I[] = [];\n let at = b;\n // a cycle of pass-through nodes would never end: stop where the route returns\n while (!kept(at) && !via.includes(at)) {\n via.push(at);\n at = kids.get(at)![0]!;\n }\n // a loop folded down to where it started draws nothing\n if (at !== a) out.push([a, at, via]);\n }\n return out;\n}\n\n/**\n * Nested data as lanes: one per top-level item, its edges running from every node to its children. The same id twice\n * is the same node, so shared children (a graph rather than a tree) work too.\n */\nexport function fromTree<T, I extends Id>(roots: readonly T[], getId: (node: T) => I, getChildren: (node: T) => readonly T[] | null | undefined): { lanes: Lane<I, never>[]; nodes: Map<I, T> } {\n const nodes = new Map<I, T>();\n const lanes = roots.map((root) => {\n const edges: Edge<I, never>[] = [];\n const seen = new Set<string>();\n const visited = new Set<I>();\n const walk = (node: T) => {\n const id = getId(node);\n nodes.set(id, node);\n if (visited.has(id)) return;\n visited.add(id);\n for (const child of getChildren(node) ?? []) {\n const to = getId(child);\n const key = `${String(id)}\\u0000${String(to)}`;\n if (!seen.has(key)) {\n seen.add(key);\n edges.push([id, to]);\n }\n walk(child);\n }\n };\n walk(root);\n return { root: getId(root), edges };\n });\n return { lanes, nodes };\n}\n","\"use client\";\n\nimport {\n cloneElement,\n createContext,\n isValidElement,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type FocusEvent,\n type HTMLAttributes,\n type KeyboardEvent,\n type MouseEvent,\n type ReactElement,\n type ReactNode,\n type SVGAttributes,\n} from \"react\";\nimport { onTrace, trace, type Trace } from \"./graph\";\nimport { layout as computeLayout, type ConnectorShape, type Direction, type Id, type Lane, type Layout, type PlacedEdge, type PlacedLane, type Rect, type Size } from \"./layout\";\n\n/**\n * The React parts. Headless: they place your elements and tell them their state, they draw no boxes of their own.\n *\n * <Graph.Root lanes={lanes} rootSize={…} nodeSize={…}>\n * <Graph.Canvas>\n * <Graph.Connectors />\n * <Graph.Nodes>{(node) => <Graph.Node>{node.id}</Graph.Node>}</Graph.Nodes>\n * </Graph.Canvas>\n * </Graph.Root>\n *\n * State reaches the markup as data attributes (data-root, data-expanded, data-selected, data-highlighted, data-dimmed)\n * and through `className`/`style` functions, so it is styled with plain CSS or Tailwind.\n */\n\n/** A node in a lane: the lane's root and the node's id (the same node can sit in several lanes). */\nexport type Selection<I extends Id = Id> = { lane: I; id: I } | null;\n\nexport interface NodeState {\n /** The lane's root itself (it opens and closes the lane). */\n root: boolean;\n /** 0 for a root. */\n depth: number;\n /** A root with something to unfold. */\n expandable: boolean;\n /** A root whose lane is unfolded. */\n expanded: boolean;\n selected: boolean;\n /**\n * On a route through the hovered or focused node (or the selected one, when nothing is hovered). Matched by id, so the\n * same node lights up wherever it appears, as the root of another lane too.\n */\n highlighted: boolean;\n /** Routes are being traced and this node is not on one. */\n dimmed: boolean;\n /** Its size is not known yet (measured sizes only). */\n measuring: boolean;\n}\n\nexport interface EdgeState {\n highlighted: boolean;\n dimmed: boolean;\n}\n\nexport interface NodeInfo<I extends Id = Id> {\n lane: I;\n id: I;\n depth: number;\n rect: Rect;\n state: NodeState;\n}\n\nexport interface EdgeInfo<I extends Id = Id, V = unknown> extends PlacedEdge<I, V> {\n lane: I;\n state: EdgeState;\n}\n\nexport interface BandInfo<I extends Id = Id> {\n lane: I;\n /** Along the cross axis (y when the graph grows to the right): where the unfolded lane's room starts and how big it is. */\n start: number;\n size: number;\n}\n\ntype Styled<S> = {\n className?: string | ((state: S) => string | undefined);\n style?: CSSProperties | ((state: S) => CSSProperties | undefined);\n};\n\nconst resolve = <S, T>(value: T | ((state: S) => T), state: S): T => (typeof value === \"function\" ? (value as (state: S) => T)(state) : value);\n\n// effects that measure must run before paint in the browser and not at all on the server\nconst useIsomorphicLayoutEffect = typeof window === \"undefined\" ? useEffect : useLayoutEffect;\n\nfunction useControllable<T>(value: T | undefined, defaultValue: T, onChange?: (next: T) => void): [T, (next: T) => void] {\n const [own, setOwn] = useState(defaultValue);\n const controlled = value !== undefined;\n const current = controlled ? value : own;\n const set = useCallback(\n (next: T) => {\n if (!controlled) setOwn(next);\n onChange?.(next);\n },\n [controlled, onChange],\n );\n return [current, set];\n}\n\ninterface GraphContextValue<I extends Id = Id, V = unknown> {\n layout: Layout<I, V>;\n lanes: readonly Lane<I, V>[];\n direction: Direction;\n open: readonly I[];\n selected: Selection<I>;\n traced: { lane: I; trace: Trace<I> } | null;\n measuredRoots: boolean;\n measuredNodes: boolean;\n measuring: boolean;\n keyboardNavigation: boolean;\n nodeState: (lane: I, id: I, depth: number) => NodeState;\n edgeState: (lane: I, edge: PlacedEdge<I, V>) => EdgeState;\n toggleLane: (root: I) => void;\n select: (lane: I, id: I) => void;\n hover: (target: Selection<I>) => void;\n report: (id: I, root: boolean, element: HTMLElement | null) => void;\n register: (key: string, element: HTMLElement | null) => void;\n focusFrom: (lane: I, id: I, key: string) => boolean;\n}\n\nconst GraphContext = createContext<GraphContextValue | null>(null);\nconst NodeContext = createContext<NodeInfo | null>(null);\n\nfunction useGraphContext(part: string): GraphContextValue {\n const ctx = useContext(GraphContext);\n if (!ctx) throw new Error(`treelines: <Graph.${part}> must be inside <Graph.Root>`);\n return ctx;\n}\n\nconst keyOf = (lane: Id, id: Id) => `${String(lane)}\\u0000${String(id)}`;\n/** Measured sizes are kept per node id, roots apart from the rest. */\nconst sizeKey = (id: Id, root: boolean) => `${root ? \"r\" : \"n\"}\\u0000${String(id)}`;\n\nexport interface RootProps<I extends Id = Id, V = unknown> {\n lanes: readonly Lane<I, V>[];\n /** The size of every lane's root. Leave it out to measure each root as you render it. */\n rootSize?: Size | ((id: I) => Size);\n /** The size of the nodes below. Leave it out to measure them. Fixed sizes need no measuring and lay out on the server too. */\n nodeSize?: Size | ((id: I, depth: number) => Size);\n gap?: { column?: number; row?: number; lane?: number };\n /** Room around an unfolded lane (its band). */\n padding?: number;\n /** Where the first lane starts along the cross axis. */\n start?: number;\n direction?: Direction;\n shape?: ConnectorShape;\n /** Breaks ties between nodes that want the same row. */\n compare?: (a: I, b: I) => number;\n /** The unfolded lanes (by root): controlled. */\n open?: readonly I[];\n defaultOpen?: readonly I[];\n onOpenChange?: (open: I[]) => void;\n /** Several lanes open at once. By default opening one closes the other. */\n multiple?: boolean;\n /** The selected node: controlled. */\n selected?: Selection<I>;\n defaultSelected?: Selection<I>;\n onSelectedChange?: (selected: Selection<I>) => void;\n /** Arrow keys move between nodes (and the right arrow unfolds a folded root). On by default. */\n keyboardNavigation?: boolean;\n children?: ReactNode;\n}\n\nfunction Root<I extends Id = Id, V = unknown>(props: RootProps<I, V>) {\n const { lanes, rootSize, nodeSize, gap, padding, start, direction = \"right\", shape, compare, multiple = false, keyboardNavigation = true, children } = props;\n const [open, setOpen] = useControllable<readonly I[]>(props.open, props.defaultOpen ?? [], props.onOpenChange as ((next: readonly I[]) => void) | undefined);\n const [selected, setSelected] = useControllable<Selection<I>>(props.selected, props.defaultSelected ?? null, props.onSelectedChange);\n const [hovered, setHovered] = useState<Selection<I>>(null);\n\n // measured sizes, by node id (the same node has the same content in every lane)\n const [sizes, setSizes] = useState<ReadonlyMap<string, Size>>(() => new Map());\n const measuredRoots = rootSize === undefined;\n const measuredNodes = nodeSize === undefined;\n\n const result = useMemo(\n () =>\n computeLayout<I, V>({\n lanes,\n open,\n rootSize: rootSize ?? ((id: I) => sizes.get(sizeKey(id, true)) ?? { width: 0, height: 0 }),\n nodeSize: nodeSize ?? ((id: I) => sizes.get(sizeKey(id, false)) ?? { width: 0, height: 0 }),\n ...(gap ? { gap } : {}),\n ...(padding !== undefined ? { padding } : {}),\n ...(start !== undefined ? { start } : {}),\n direction,\n ...(shape ? { shape } : {}),\n ...(compare ? { compare } : {}),\n }),\n [lanes, open, rootSize, nodeSize, sizes, gap, padding, start, direction, shape, compare],\n );\n\n const measuring =\n (measuredRoots || measuredNodes) &&\n result.lanes.some((lane) => lane.nodes.some((n) => (n.depth === 0 ? measuredRoots : measuredNodes) && !sizes.has(sizeKey(n.id, n.depth === 0))));\n\n const report = useCallback((id: I, root: boolean, element: HTMLElement | null) => {\n if (!element) return;\n const size = { width: element.offsetWidth, height: element.offsetHeight };\n const key = sizeKey(id, root);\n setSizes((current) => {\n const known = current.get(key);\n if (known && known.width === size.width && known.height === size.height) return current;\n return new Map(current).set(key, size);\n });\n }, []);\n\n // hover (or focus) traces routes; without it, the selection does. Only inside an unfolded lane.\n const active = hovered ?? selected;\n const traced = useMemo(() => {\n if (!active) return null;\n const lane = result.lanes.find((l) => l.root === active.lane);\n if (!lane?.unfolded) return null;\n const edges = lanes.find((l) => l.root === active.lane)?.edges ?? [];\n return { lane: active.lane, trace: trace(edges, active.id) };\n }, [active, result.lanes, lanes]);\n\n const nodeState = useCallback(\n (lane: I, id: I, depth: number): NodeState => {\n const placed = result.lanes.find((l) => l.root === lane);\n const root = depth === 0;\n const expandable = root && (lanes.find((l) => l.root === lane)?.edges.length ?? 0) > 0;\n // by id: the same node lights up in every lane it appears in\n const highlighted = !!traced && (traced.trace.up.has(id) || traced.trace.down.has(id));\n return {\n root,\n depth,\n expandable,\n expanded: root && !!placed?.unfolded,\n selected: !!selected && selected.lane === lane && selected.id === id,\n highlighted,\n dimmed: !!traced && !highlighted,\n measuring: (root ? measuredRoots : measuredNodes) && !sizes.has(sizeKey(id, root)),\n };\n },\n [result.lanes, lanes, traced, selected, measuredRoots, measuredNodes, sizes],\n );\n\n const edgeState = useCallback(\n (lane: I, edge: PlacedEdge<I, V>): EdgeState => {\n const highlighted = !!traced && onTrace(traced.trace, [edge.from, edge.to]);\n return { highlighted, dimmed: !!traced && !highlighted };\n },\n [traced],\n );\n\n const toggleLane = useCallback(\n (root: I) => {\n const expandable = (lanes.find((l) => l.root === root)?.edges.length ?? 0) > 0;\n const isOpen = open.includes(root);\n if (multiple) {\n if (expandable) setOpen(isOpen ? open.filter((r) => r !== root) : [...open, root]);\n } else {\n // one at a time: opening this one closes the other; a root with nothing below closes the open one\n setOpen(isOpen || !expandable ? [] : [root]);\n }\n setSelected({ lane: root, id: root });\n setHovered(null);\n },\n [lanes, open, multiple, setOpen, setSelected],\n );\n\n const select = useCallback(\n (lane: I, id: I) => setSelected(selected && selected.lane === lane && selected.id === id ? null : { lane, id }),\n [selected, setSelected],\n );\n\n // keyboard: the elements by key, to move focus between them\n const elements = useRef(new Map<string, HTMLElement>());\n const register = useCallback((key: string, element: HTMLElement | null) => {\n if (element) elements.current.set(key, element);\n else elements.current.delete(key);\n }, []);\n const focusFrom = useCallback(\n (lane: I, id: I, key: string): boolean => {\n // `key` is the arrow, already turned into a direction along the graph: next/previous across, deeper/shallower\n const placed = result.lanes.find((l) => l.root === lane);\n const here = placed?.nodes.find((n) => n.id === id);\n if (!placed || !here) return false;\n const right = direction === \"right\";\n const main = (r: Rect) => (right ? r.x : r.y);\n const cross = (r: Rect) => (right ? r.y : r.x);\n let target: { lane: I; id: I } | undefined;\n if (key === \"next\" || key === \"previous\") {\n const sign = key === \"next\" ? 1 : -1;\n if (here.depth === 0) {\n // between lanes, root to root\n const at = result.lanes.indexOf(placed);\n const other = result.lanes[at + sign];\n if (other) target = { lane: other.root, id: other.root };\n } else {\n const column = placed.nodes.filter((n) => n.depth === here.depth && sign * (cross(n.rect) - cross(here.rect)) > 0);\n const nearest = column.toSorted((a, b) => sign * (cross(a.rect) - cross(b.rect)))[0];\n if (nearest) target = { lane, id: nearest.id };\n }\n } else {\n const depth = here.depth + (key === \"deeper\" ? 1 : -1);\n if (key === \"deeper\" && here.depth === 0 && !placed.unfolded) {\n if ((lanes.find((l) => l.root === lane)?.edges.length ?? 0) > 0) toggleLane(lane);\n return true;\n }\n const column = placed.nodes.filter((n) => n.depth === depth);\n const nearest = column.toSorted((a, b) => Math.abs(cross(a.rect) - cross(here.rect)) - Math.abs(cross(b.rect) - cross(here.rect)) || main(a.rect) - main(b.rect))[0];\n if (nearest) target = { lane, id: nearest.id };\n }\n if (!target) return false;\n elements.current.get(keyOf(target.lane, target.id))?.focus();\n return true;\n },\n [result.lanes, direction, lanes, toggleLane],\n );\n\n const value = useMemo<GraphContextValue<I, V>>(() => ({\n layout: result,\n lanes,\n direction,\n open,\n selected,\n traced,\n measuredRoots,\n measuredNodes,\n measuring,\n keyboardNavigation,\n nodeState,\n edgeState,\n toggleLane,\n select,\n hover: setHovered,\n report,\n register,\n focusFrom,\n }), [result, lanes, direction, open, selected, traced, measuredRoots, measuredNodes, measuring, keyboardNavigation, nodeState, edgeState, toggleLane, select, report, register, focusFrom]);\n return <GraphContext.Provider value={value as unknown as GraphContextValue}>{children}</GraphContext.Provider>;\n}\n\nexport interface CanvasProps extends Omit<HTMLAttributes<HTMLDivElement>, \"className\" | \"style\">, Styled<{ width: number; height: number; measuring: boolean }> {}\n\n/** The area the graph is drawn in: positioned, and as big as the layout. Hidden while measured sizes are still unknown. */\nfunction Canvas({ className, style, children, ...rest }: CanvasProps) {\n const ctx = useGraphContext(\"Canvas\");\n const state = { width: ctx.layout.width, height: ctx.layout.height, measuring: ctx.measuring };\n return (\n <div\n {...rest}\n data-measuring={ctx.measuring ? \"\" : undefined}\n className={resolve(className, state)}\n style={{ position: \"relative\", width: state.width, height: state.height, ...(ctx.measuring ? { visibility: \"hidden\" } : {}), ...resolve(style, state) }}\n >\n {children}\n </div>\n );\n}\n\n/** One element per unfolded lane, for a background behind it: you render it, with the band's place along the cross axis. */\nfunction Bands<I extends Id = Id>({ children }: { children: (band: BandInfo<I>) => ReactNode }) {\n const ctx = useGraphContext(\"Bands\");\n return (\n <>\n {ctx.layout.lanes.flatMap((lane: PlacedLane) =>\n lane.band ? [<BandSlot key={keyOf(lane.root, \"band\")}>{children({ lane: lane.root as I, start: lane.band.start, size: lane.band.size })}</BandSlot>] : [],\n )}\n </>\n );\n}\nconst BandSlot = ({ children }: { children: ReactNode }) => <>{children}</>;\n\nexport interface ConnectorsProps<I extends Id = Id, V = unknown> extends Omit<SVGAttributes<SVGSVGElement>, \"children\"> {\n /** Class or style per connector, from its state; or render each connector yourself. */\n pathClassName?: string | ((edge: EdgeInfo<I, V>) => string | undefined);\n pathStyle?: CSSProperties | ((edge: EdgeInfo<I, V>) => CSSProperties | undefined);\n children?: (edge: EdgeInfo<I, V>) => ReactNode;\n}\n\n/** The connector lines, as SVG paths in one SVG over the canvas. Decorative: hidden from assistive technology. */\nfunction Connectors<I extends Id = Id, V = unknown>({ pathClassName, pathStyle, children, ...rest }: ConnectorsProps<I, V>) {\n const ctx = useGraphContext(\"Connectors\");\n const edges = useEdges<I, V>();\n return (\n <svg aria-hidden width={ctx.layout.width} height={ctx.layout.height} {...rest}>\n {edges.map((edge) =>\n children ? (\n <EdgeSlot key={keyOf(edge.lane, `${String(edge.from)}>${String(edge.to)}`)}>{children(edge)}</EdgeSlot>\n ) : (\n <path\n key={keyOf(edge.lane, `${String(edge.from)}>${String(edge.to)}`)}\n d={edge.path}\n fill=\"none\"\n data-highlighted={edge.state.highlighted ? \"\" : undefined}\n data-dimmed={edge.state.dimmed ? \"\" : undefined}\n className={resolve(pathClassName, edge)}\n style={resolve(pathStyle, edge)}\n />\n ),\n )}\n </svg>\n );\n}\nconst EdgeSlot = ({ children }: { children: ReactNode }) => <>{children}</>;\n\nfunction useEdges<I extends Id = Id, V = unknown>(): EdgeInfo<I, V>[] {\n const ctx = useGraphContext(\"Connectors\");\n return ctx.layout.lanes.flatMap((lane: PlacedLane) => lane.edges.map((edge) => ({ ...edge, lane: lane.root, state: ctx.edgeState(lane.root, edge) }))) as unknown as EdgeInfo<I, V>[];\n}\n\n/** One element per connector with folded nodes in it (\"+N\"): you render it, at `edge.mid`. */\nfunction Markers<I extends Id = Id, V = unknown>({ children }: { children: (edge: EdgeInfo<I, V>) => ReactNode }) {\n const edges = useEdges<I, V>();\n return <>{edges.filter((edge) => edge.via.length > 0).map((edge) => <EdgeSlot key={keyOf(edge.lane, `${String(edge.from)}>${String(edge.to)}`)}>{children(edge)}</EdgeSlot>)}</>;\n}\n\n/** Every node, root first then the nodes below in reading order, lane by lane. Render each with <Graph.Node>. */\nfunction Nodes<I extends Id = Id>({ children }: { children: (node: NodeInfo<I>) => ReactNode }) {\n const ctx = useGraphContext(\"Nodes\");\n return (\n <>\n {ctx.layout.lanes.flatMap((lane: PlacedLane) =>\n lane.nodes.map((n) => {\n const info: NodeInfo = { lane: lane.root, id: n.id, depth: n.depth, rect: n.rect, state: ctx.nodeState(lane.root, n.id, n.depth) };\n return <NodeSlot key={keyOf(lane.root, n.id)} info={info} render={children as (node: NodeInfo) => ReactNode} />;\n }),\n )}\n </>\n );\n}\n\n/** What <Graph.Node> puts on its element: your props, the position, the state's data attributes and the handlers. */\n/** Gives a node's info to the <Graph.Node> inside it; the value only changes when the node does. */\nfunction NodeSlot({ info, render }: { info: NodeInfo; render: (node: NodeInfo) => ReactNode }) {\n const { lane, id, depth, rect, state } = info;\n const value = useMemo(\n () => ({ lane, id, depth, rect, state }),\n // a new object only when something in it changed\n // oxlint-disable-next-line react-hooks/exhaustive-deps\n [lane, id, depth, rect.x, rect.y, rect.width, rect.height, state.root, state.expandable, state.expanded, state.selected, state.highlighted, state.dimmed, state.measuring],\n );\n return <NodeContext.Provider value={value}>{render(value)}</NodeContext.Provider>;\n}\n\ntype NodeElementProps = HTMLAttributes<HTMLElement> & Record<`data-${string}`, string | undefined>;\n\nexport interface NodeProps extends Omit<HTMLAttributes<HTMLButtonElement>, \"className\" | \"style\">, Styled<NodeState> {\n /** Another element instead of the button, or a function that renders one with the props it gets. */\n render?: ReactElement | ((props: NodeElementProps & { ref: (el: HTMLElement | null) => void }, state: NodeState) => ReactElement);\n}\n\n/**\n * A node: a button by default, placed where the layout puts it. A root opens and closes its lane (and is selected); a\n * node below toggles its selection. Hover and focus trace its routes. Your handlers run first; `event.preventDefault()`\n * in one skips the graph's own.\n */\nfunction Node({ render, className, style, onClick, onMouseEnter, onMouseLeave, onFocus, onBlur, onKeyDown, children, ...rest }: NodeProps) {\n const ctx = useGraphContext(\"Node\");\n const node = useContext(NodeContext);\n if (!node) throw new Error(\"treelines: <Graph.Node> must be rendered from <Graph.Nodes>\");\n const { lane, id, rect, state } = node;\n const key = keyOf(lane, id);\n const measured = state.root ? ctx.measuredRoots : ctx.measuredNodes;\n\n const { register, report } = ctx;\n const [element, setElement] = useState<HTMLElement | null>(null);\n const ref = useCallback(\n (el: HTMLElement | null) => {\n setElement(el);\n register(key, el);\n },\n [key, register],\n );\n // measured sizes: read the element's own size before paint, and again whenever it changes\n const root = state.root;\n useIsomorphicLayoutEffect(() => {\n if (!measured || !element) return;\n report(id, root, element);\n if (typeof ResizeObserver === \"undefined\") return;\n const observer = new ResizeObserver(() => report(id, root, element));\n observer.observe(element);\n return () => observer.disconnect();\n }, [measured, element, id, root, report]);\n\n const position: CSSProperties = measured\n ? { position: \"absolute\", left: rect.x, top: rect.y }\n : { position: \"absolute\", left: rect.x, top: rect.y, width: rect.width, height: rect.height };\n\n const props: NodeElementProps = {\n ...rest,\n \"data-root\": state.root ? \"\" : undefined,\n \"data-expanded\": state.expanded ? \"\" : undefined,\n \"data-selected\": state.selected ? \"\" : undefined,\n \"data-highlighted\": state.highlighted ? \"\" : undefined,\n \"data-dimmed\": state.dimmed ? \"\" : undefined,\n \"data-depth\": String(state.depth),\n ...(state.root ? { \"aria-expanded\": state.expandable ? state.expanded : undefined } : { \"aria-pressed\": state.selected }),\n className: resolve(className, state),\n style: { ...position, ...resolve(style, state) },\n onClick: (event: MouseEvent<HTMLElement>) => {\n onClick?.(event as MouseEvent<HTMLButtonElement>);\n if (event.defaultPrevented) return;\n if (state.root) ctx.toggleLane(lane);\n else ctx.select(lane, id);\n },\n onMouseEnter: (event: MouseEvent<HTMLElement>) => {\n onMouseEnter?.(event as MouseEvent<HTMLButtonElement>);\n if (!event.defaultPrevented) ctx.hover({ lane, id });\n },\n onMouseLeave: (event: MouseEvent<HTMLElement>) => {\n onMouseLeave?.(event as MouseEvent<HTMLButtonElement>);\n if (!event.defaultPrevented) ctx.hover(null);\n },\n onFocus: (event: FocusEvent<HTMLElement>) => {\n onFocus?.(event as FocusEvent<HTMLButtonElement>);\n if (!event.defaultPrevented) ctx.hover({ lane, id });\n },\n onBlur: (event: FocusEvent<HTMLElement>) => {\n onBlur?.(event as FocusEvent<HTMLButtonElement>);\n if (!event.defaultPrevented) ctx.hover(null);\n },\n onKeyDown: (event: KeyboardEvent<HTMLElement>) => {\n onKeyDown?.(event as KeyboardEvent<HTMLButtonElement>);\n if (event.defaultPrevented || !ctx.keyboardNavigation) return;\n const right = ctx.direction === \"right\";\n const move = { ArrowDown: right ? \"next\" : \"deeper\", ArrowUp: right ? \"previous\" : \"shallower\", ArrowRight: right ? \"deeper\" : \"next\", ArrowLeft: right ? \"shallower\" : \"previous\" }[event.key];\n if (move && ctx.focusFrom(lane, id, move)) event.preventDefault();\n },\n };\n\n if (typeof render === \"function\") return render({ ...props, ref }, state);\n if (isValidElement(render)) return cloneElement(render, { ...props, ref } as Record<string, unknown>, children ?? (render.props as { children?: ReactNode }).children);\n return (\n <button type=\"button\" {...(props as HTMLAttributes<HTMLButtonElement>)} ref={ref}>\n {children}\n </button>\n );\n}\n\n/** The graph's state, for parts of your own: a details panel, a \"show more\", a legend. */\nexport function useGraph<I extends Id = Id>() {\n const ctx = useGraphContext(\"useGraph\") as unknown as GraphContextValue<I>;\n return {\n layout: ctx.layout,\n open: ctx.open,\n selected: ctx.selected,\n /** The routes being traced, and in which lane. */\n traced: ctx.traced,\n measuring: ctx.measuring,\n toggleLane: ctx.toggleLane,\n select: ctx.select,\n };\n}\n\n/** The node a <Graph.Node> renders, for components inside it. */\nexport function useNode(): NodeInfo {\n const node = useContext(NodeContext);\n if (!node) throw new Error(\"treelines: useNode() must be used inside <Graph.Nodes>\");\n return node;\n}\n\nexport const Graph = { Root, Canvas, Bands, Connectors, Markers, Nodes, Node };\n"],"mappings":";;;AAqHA,IAAM,SAAS,CAAsB,SAAwC,SAAmB,OAAO,SAAS,aAAa,KAAK,GAAG,IAAI,IAAI;AAGtI,SAAS,cAAc,OAAc,KAAY,QAAwB,SAAS,YAAuB,SAAiB;AAC/H,QAAM,EAAE,GAAG,IAAI,GAAG,GAAG,IAAI;AACzB,QAAM,EAAE,GAAG,IAAI,GAAG,GAAG,IAAI;AACzB,MAAI,UAAU,WAAY,QAAO,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;AAC1D,MAAI,cAAc,SAAS;AACzB,UAAM,MAAM,KAAK,MAAM;AACvB,WAAO,UAAU,UAAU,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;AAAA,EACtH;AACA,QAAM,MAAM,KAAK,MAAM;AACvB,SAAO,UAAU,UAAU,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE;AACtH;AAEO,SA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