@dxos/react-ui-graph 0.9.1-staging.ee54ba693a → 0.11.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.
@@ -0,0 +1,3679 @@
1
+ import { n as useStateRef, r as useTimestamp, t as useDynamicRef } from "./chunk-useStateRef.mjs";
2
+ import { createContext, createRef, forwardRef, memo, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
3
+ import { combine } from "@dxos/async";
4
+ import { log } from "@dxos/log";
5
+ import { mx } from "@dxos/ui-theme";
6
+ import { cluster, curveBumpX, curveBundle, drag, easeCubic, easeCubicOut, easeLinear, forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX, forceY, geoPath, hierarchy, interpolate, line, lineRadial, link, linkHorizontal, linkRadial, pointer, polygonHull, range, select, timer, tree, zoom, zoomIdentity } from "d3";
7
+ import { invariant } from "@dxos/invariant";
8
+ import * as Clipper from "js-clipper";
9
+ import { raise } from "@dxos/debug";
10
+ import defaultsDeep from "lodash.defaultsdeep";
11
+ import { jsx } from "react/jsx-runtime";
12
+ import { feature, mesh } from "topojson-client";
13
+ import { composableProps } from "@dxos/react-ui";
14
+ //#region src/graph/markers.ts
15
+ var createLine$3 = line();
16
+ var createArrow = (length, offset, start) => (el) => {
17
+ const height = length * .5;
18
+ el.attr("markerWidth", length * 2).attr("markerHeight", height * 2).attr("viewBox", `-${length},-${height},${length * 2},${height * 2}`).attr("orient", "auto").attr("refX", offset).append("path").attr("fill", "none").attr("stroke", "context-stroke").attr("d", createLine$3([
19
+ start ? [length, height] : [-length, -height],
20
+ [0, 0],
21
+ start ? [length, -height] : [-length, height]
22
+ ]));
23
+ };
24
+ var createDot = (size) => (el) => {
25
+ el.attr("markerWidth", size * 2).attr("markerHeight", size * 2).attr("viewBox", `-${size},-${size},${size * 2},${size * 2}`).attr("orient", "auto").append("circle").attr("fill", "context-stroke").attr("r", size / 2 - 1);
26
+ };
27
+ /**
28
+ * https://developer.mozilla.org/en-US/docs/Web/SVG/Element/marker
29
+ * https://www.dashingd3js.com/svg-paths-and-d3js
30
+ * http://bl.ocks.org/dustinlarimer/5888271
31
+ */
32
+ var createMarkers = ({ arrowSize = 12 } = {}) => (group) => {
33
+ return group.selectAll("marker").data([
34
+ {
35
+ id: "marker-arrow-start",
36
+ generator: createArrow(arrowSize, -.5, true),
37
+ className: "dx-arrow"
38
+ },
39
+ {
40
+ id: "marker-arrow-end",
41
+ generator: createArrow(arrowSize, .5, false),
42
+ className: "dx-arrow"
43
+ },
44
+ {
45
+ id: "marker-dot",
46
+ generator: createDot(6),
47
+ className: "dx-dot"
48
+ }
49
+ ]).join("marker").attr("id", (d) => d.id).attr("markerUnits", "strokeWidth").attr("class", (d) => d.className).each((d, i, nodes) => {
50
+ select(nodes[i]).call(d.generator);
51
+ });
52
+ };
53
+ //#endregion
54
+ //#region src/graph/types.ts
55
+ var __dxlog_file$13 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/types.ts";
56
+ var defaultIdAccessor = (node) => {
57
+ invariant(node.id, void 0, {
58
+ "~LogMeta": "~LogMeta",
59
+ F: __dxlog_file$13,
60
+ L: 18,
61
+ S: void 0,
62
+ A: ["node.id", ""]
63
+ });
64
+ return node.id;
65
+ };
66
+ var emptyGraph = {
67
+ nodes: [],
68
+ edges: []
69
+ };
70
+ //#endregion
71
+ //#region src/util/events.ts
72
+ var EventEmitter = class {
73
+ _listeners = /* @__PURE__ */ new Set();
74
+ clear() {
75
+ this._listeners.clear();
76
+ }
77
+ on(onEvent) {
78
+ this._listeners.add(onEvent);
79
+ return () => this._listeners.delete(onEvent);
80
+ }
81
+ emit(value) {
82
+ this._listeners.forEach((listener) => listener(value));
83
+ }
84
+ };
85
+ //#endregion
86
+ //#region src/util/fraction.ts
87
+ var __dxlog_file$12 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
88
+ var FractionUtil = class FractionUtil {
89
+ /**
90
+ * Convert number to fraction.
91
+ * @param n
92
+ */
93
+ static toFraction = (n) => {
94
+ return typeof n === "number" ? [n, 1] : n;
95
+ };
96
+ static validate = (...fraction) => {
97
+ fraction.forEach(([n, d]) => {
98
+ if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) throw new Error(`Invalid fraction: ${n}/${d}`);
99
+ });
100
+ return fraction;
101
+ };
102
+ /**
103
+ * @param {Fraction}
104
+ * Convert to rounded-sm number.
105
+ */
106
+ static toNumber = ([n, d]) => {
107
+ FractionUtil.validate([n, d]);
108
+ return n / d;
109
+ };
110
+ /**
111
+ * Round the number to the nearest fraction.
112
+ * Example: 3/5 => 1/1; 3/5 (precision 2) => 1/2.
113
+ * @param {Fraction}
114
+ * @param p Precision (e.g., 1/2, 1/4, etc.)
115
+ */
116
+ static round = ([n, d], p = 1) => {
117
+ FractionUtil.validate([n, d]);
118
+ const v = Math.round(FractionUtil.toNumber(FractionUtil.divide([n, d], [1, p])));
119
+ return FractionUtil.simplify([v, p]);
120
+ };
121
+ /**
122
+ * Tests if equals.
123
+ * @param n1
124
+ * @param n2
125
+ */
126
+ static equals = (n1, n2) => {
127
+ return n1[0] * n2[1] === n1[1] * n2[0];
128
+ };
129
+ /**
130
+ * @param {Fraction}
131
+ * True if zero.
132
+ */
133
+ static isZero = ([n]) => {
134
+ return n === 0;
135
+ };
136
+ /**
137
+ * Simplify fraction finding LCDs.
138
+ * @param n
139
+ * @param d
140
+ */
141
+ static simplify = ([n, d]) => {
142
+ FractionUtil.validate([n, d]);
143
+ if (d < 1) {
144
+ const t = n / d;
145
+ if (Math.floor(t) === t) {
146
+ n = t;
147
+ d = 1;
148
+ }
149
+ }
150
+ const fn = FractionUtil.factors(n).reverse();
151
+ const fd = FractionUtil.factors(d).reverse();
152
+ let c;
153
+ for (let i = 0; i < fn.length; i++) {
154
+ c = fd.find((n) => n === fn[i]);
155
+ if (c) return [n / c, d / c];
156
+ }
157
+ return [n, d];
158
+ };
159
+ /**
160
+ * Return common factors.
161
+ * @param n
162
+ */
163
+ static factors = (n) => {
164
+ invariant(Number.isFinite(n), `Invalid number: ${n}`, {
165
+ "~LogMeta": "~LogMeta",
166
+ F: __dxlog_file$12,
167
+ L: 113,
168
+ S: this,
169
+ A: ["Number.isFinite(n)", "`Invalid number: ${n}`"]
170
+ });
171
+ const factors = [1];
172
+ if (Number.isSafeInteger(n)) {
173
+ let f = 1;
174
+ do
175
+ if (n % ++f === 0) factors.push(f);
176
+ while (n / f > 1 && f < 100);
177
+ }
178
+ return factors;
179
+ };
180
+ /**
181
+ * @param n1
182
+ * @param n2
183
+ */
184
+ static add = (n1, n2) => {
185
+ FractionUtil.validate(n1, n2);
186
+ const d = n1[1] * n2[1];
187
+ const n = n1[0] * n2[1] + n2[0] * n1[1];
188
+ return FractionUtil.simplify([n, d]);
189
+ };
190
+ /**
191
+ * @param n1
192
+ * @param n2
193
+ */
194
+ static subtract = (n1, n2) => {
195
+ FractionUtil.validate(n1, n2);
196
+ const d = n1[1] * n2[1];
197
+ const n = n1[0] * n2[1] - n2[0] * n1[1];
198
+ return FractionUtil.simplify([n, d]);
199
+ };
200
+ /**
201
+ * @param n1
202
+ * @param n2
203
+ */
204
+ static multiply = (n1, n2) => {
205
+ FractionUtil.validate(n1, n2);
206
+ const n = n1[0] * n2[0];
207
+ const d = n1[1] * n2[1];
208
+ return FractionUtil.simplify([n, d]);
209
+ };
210
+ /**
211
+ * @param n1
212
+ * @param n2
213
+ */
214
+ static divide = (n1, n2) => {
215
+ FractionUtil.validate(n1, n2);
216
+ const n = n1[0] * n2[1];
217
+ const d = n1[1] * n2[0];
218
+ return FractionUtil.simplify([n, d]);
219
+ };
220
+ };
221
+ //#endregion
222
+ //#region src/util/points.ts
223
+ /**
224
+ * Creates an array of points on the the circumference of two circles.
225
+ * http://www.math.com/tables/geometry/circles.htm
226
+ *
227
+ * @param p1
228
+ * @param p2
229
+ * @param r1
230
+ * @param r2
231
+ * @return {[Point, Point]}
232
+ */
233
+ var getCircumferencePoints = (p1, p2, r1 = 0, r2 = 0) => {
234
+ const [x1, y1] = p1;
235
+ const [x2, y2] = p2;
236
+ const theta = Math.atan2(x2 - x1, y2 - y1);
237
+ return [[x1 + (r1 === 0 ? 0 : r1 * Math.sin(theta)), y1 + (r1 === 0 ? 0 : r1 * Math.cos(theta))], [x2 - (r2 === 0 ? 0 : r2 * Math.cos(Math.PI / 2 - theta)), y2 - (r2 === 0 ? 0 : r2 * Math.sin(Math.PI / 2 - theta))]];
238
+ };
239
+ var normal = (p1, p2) => {
240
+ const dx = p2[0] - p1[0];
241
+ const dy = p2[1] - p1[1];
242
+ const len = Math.hypot(dx, dy);
243
+ return [dy / len, -dx / len];
244
+ };
245
+ var offsetPoints = (points, distance, closed) => {
246
+ const len = points.length;
247
+ const out = [];
248
+ for (let i = 0; i < len; i++) {
249
+ const p0 = points[(i - 1 + len) % len];
250
+ const p1 = points[i];
251
+ const p2 = points[(i + 1) % len];
252
+ const n1 = normal(p0, p1);
253
+ const n2 = normal(p1, p2);
254
+ const nx = (n1[0] + n2[0]) / 2;
255
+ const ny = (n1[1] + n2[1]) / 2;
256
+ const norm = Math.hypot(nx, ny) || 1;
257
+ out.push([p1[0] + distance * nx / norm, p1[1] + distance * ny / norm]);
258
+ if (!closed && (i === 0 || i === len - 1)) out[i] = [p1[0] + distance * normal(p0, p1)[0], p1[1] + distance * normal(p0, p1)[1]];
259
+ }
260
+ return out;
261
+ };
262
+ //#endregion
263
+ //#region src/util/scale.ts
264
+ /**
265
+ * Scale to map vector space to view (screen) space.
266
+ */
267
+ var Scale = class {
268
+ _gridSize;
269
+ _transform;
270
+ constructor(_gridSize = 32) {
271
+ this._gridSize = _gridSize;
272
+ }
273
+ get gridSize() {
274
+ return this._gridSize;
275
+ }
276
+ get transform() {
277
+ return this._transform || zoomIdentity;
278
+ }
279
+ setTransform(transform) {
280
+ if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) return false;
281
+ this._transform = transform;
282
+ return true;
283
+ }
284
+ /**
285
+ * Translate a screen point to a logical point.
286
+ * @param point
287
+ */
288
+ translate(point) {
289
+ const { x, y, k } = this._transform ?? {
290
+ x: 0,
291
+ y: 0,
292
+ k: 1
293
+ };
294
+ return [(point[0] - x) / k, (point[1] - y) / k];
295
+ }
296
+ /**
297
+ * Map model to screen.
298
+ * Model points are represented by fractions (to preserve precision) and use normal cartesian coordinates.
299
+ */
300
+ model = {
301
+ snapValues: (array) => array.map((n) => FractionUtil.round(n)),
302
+ snapVertex: ({ x, y }) => {
303
+ const [sx, sy] = this.model.snapValues([x, y]);
304
+ return {
305
+ x: sx,
306
+ y: sy
307
+ };
308
+ },
309
+ snapBounds: ({ x, y, width, height }) => {
310
+ [x, y, width, height] = this.model.snapValues([
311
+ x,
312
+ y,
313
+ width,
314
+ height
315
+ ]);
316
+ return {
317
+ x,
318
+ y,
319
+ width,
320
+ height
321
+ };
322
+ },
323
+ toValue: (value) => {
324
+ return Math.round(FractionUtil.toNumber(value) * this._gridSize);
325
+ },
326
+ toValues: (values) => {
327
+ return values.map((value) => Math.round(FractionUtil.toNumber(value) * this._gridSize));
328
+ },
329
+ toPoint: (point) => {
330
+ const [x, y] = this.model.toValues([point.x, point.y]);
331
+ return [x, y === 0 ? 0 : -y];
332
+ },
333
+ toBounds: ({ x, y, width, height }) => {
334
+ const point = this.model.toPoint({
335
+ x,
336
+ y
337
+ });
338
+ const [width2, height2] = this.model.toValues([width, height]);
339
+ return {
340
+ x: point[0],
341
+ y: point[1] - height2,
342
+ width: width2,
343
+ height: height2
344
+ };
345
+ }
346
+ };
347
+ /**
348
+ * Map screen to model.
349
+ * Screen points are represented by floating numbers and use translated SVG coordinates (with the y-axis inverted).
350
+ */
351
+ screen = {
352
+ snapValues: (array) => array.map((n) => Math.round(n / this._gridSize) * this._gridSize),
353
+ snapPoint: ([x, y]) => [x, y].map((n) => Math.round(n / this._gridSize) * this._gridSize),
354
+ snapBounds: ({ x, y, width, height }) => {
355
+ [x, y, width, height] = this.screen.snapValues([
356
+ x,
357
+ y,
358
+ width,
359
+ height
360
+ ]);
361
+ return {
362
+ x,
363
+ y,
364
+ width,
365
+ height
366
+ };
367
+ },
368
+ toValue: (value) => {
369
+ return FractionUtil.divide(FractionUtil.toFraction(value), [this._gridSize, 1]);
370
+ },
371
+ toValues: (values) => {
372
+ return values.map((value) => FractionUtil.divide(FractionUtil.toFraction(value), [this._gridSize, 1]));
373
+ },
374
+ toVertex: (point) => {
375
+ const [x, y] = point;
376
+ return {
377
+ x: FractionUtil.toFraction(x / this._gridSize),
378
+ y: FractionUtil.toFraction(-y / this._gridSize)
379
+ };
380
+ },
381
+ toBounds: (bounds) => {
382
+ const { x, y } = this.screen.toVertex([bounds.x, bounds.y]);
383
+ const [width, height] = this.screen.toValues([bounds.width, bounds.height]);
384
+ return {
385
+ x,
386
+ y: FractionUtil.subtract(y, height),
387
+ width,
388
+ height
389
+ };
390
+ }
391
+ };
392
+ };
393
+ //#endregion
394
+ //#region src/util/screen.ts
395
+ var Screen = class {
396
+ static createBounds = ([x1, y1], [x2, y2], mod = {}) => {
397
+ const { constrain, center } = mod;
398
+ const x = Math.min(x1, x2);
399
+ const y = Math.min(y1, y2);
400
+ let width = Math.abs(x2 - x1);
401
+ let height = Math.abs(y2 - y1);
402
+ if (constrain) width = height = Math.max(width, height);
403
+ if (center) return {
404
+ x: x - width,
405
+ y: y - height,
406
+ width: width * 2,
407
+ height: height * 2
408
+ };
409
+ else return {
410
+ x,
411
+ y,
412
+ width,
413
+ height
414
+ };
415
+ };
416
+ static center = ({ x, y, width, height }) => {
417
+ return [x + width / 2, y + height / 2];
418
+ };
419
+ static contains = (bounds, point) => {
420
+ const [x, y] = point;
421
+ if (x < bounds.x || y < bounds.y) return false;
422
+ if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) return false;
423
+ return true;
424
+ };
425
+ /**
426
+ * Distance between two points.
427
+ * @param p1
428
+ * @param p2
429
+ */
430
+ static len = (p1, p2) => {
431
+ return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
432
+ };
433
+ /**
434
+ * Distance to line segment.
435
+ * https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment#1501725
436
+ * @param v1
437
+ * @param v2
438
+ * @param p
439
+ */
440
+ static normal = (v1, v2, p) => {
441
+ const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
442
+ let d;
443
+ const len2 = d2(v1, v2);
444
+ if (len2 === 0) d = d2(p, v1);
445
+ else {
446
+ let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
447
+ t = Math.max(0, Math.min(1, t));
448
+ d = d2(p, [v1[0] + t * (v2[0] - v1[0]), v1[1] + t * (v2[1] - v1[1])]);
449
+ }
450
+ return Math.sqrt(d);
451
+ };
452
+ };
453
+ //#endregion
454
+ //#region src/util/vector.ts
455
+ var Vector = class {
456
+ /**
457
+ * Convert to Vertex.
458
+ * @param x
459
+ * @param y
460
+ */
461
+ static toVertex = ({ x, y }) => ({
462
+ x: FractionUtil.toFraction(x),
463
+ y: FractionUtil.toFraction(y)
464
+ });
465
+ /**
466
+ * Convert to Bounds.
467
+ * @param bounds
468
+ */
469
+ static toBounds = ({ x, y, width, height }) => ({
470
+ x: FractionUtil.toFraction(x),
471
+ y: FractionUtil.toFraction(y),
472
+ width: FractionUtil.toFraction(width),
473
+ height: FractionUtil.toFraction(height)
474
+ });
475
+ /**
476
+ * Calculate center point.
477
+ * @param bounds
478
+ */
479
+ static center = ({ x, y, width, height }) => {
480
+ return {
481
+ x: FractionUtil.add(x, FractionUtil.multiply(width, [1, 2])),
482
+ y: FractionUtil.add(y, FractionUtil.multiply(height, [1, 2]))
483
+ };
484
+ };
485
+ /**
486
+ * Calculate centered left edge.
487
+ * @param bounds
488
+ */
489
+ static left = ({ x, y, height }) => {
490
+ return {
491
+ x,
492
+ y: FractionUtil.add(y, FractionUtil.multiply(height, [1, 2]))
493
+ };
494
+ };
495
+ /**
496
+ * Calculate centered right edge.
497
+ * @param bounds
498
+ */
499
+ static right = ({ x, y, width, height }) => {
500
+ return {
501
+ x: FractionUtil.add(x, width),
502
+ y: FractionUtil.add(y, FractionUtil.multiply(height, [1, 2]))
503
+ };
504
+ };
505
+ };
506
+ //#endregion
507
+ //#region src/graph/projector/projector.ts
508
+ /**
509
+ * Generates a layout to be rendered.
510
+ */
511
+ var Projector = class {
512
+ _context;
513
+ updated = new EventEmitter();
514
+ _options;
515
+ constructor(_context, options) {
516
+ this._context = _context;
517
+ this._options = Object.assign({ idAccessor: defaultIdAccessor }, options);
518
+ }
519
+ get context() {
520
+ return this._context;
521
+ }
522
+ get options() {
523
+ return this._options;
524
+ }
525
+ refresh(dragging = false) {
526
+ this.onRefresh(dragging);
527
+ }
528
+ updateData(data) {
529
+ this.onUpdate(data);
530
+ }
531
+ emitUpdate(kind = "topology") {
532
+ this.updated.emit({
533
+ layout: this.layout,
534
+ kind
535
+ });
536
+ }
537
+ async clear() {
538
+ await this.onClear();
539
+ }
540
+ async start() {
541
+ await this.onStart();
542
+ }
543
+ async stop() {
544
+ await this.onStop();
545
+ }
546
+ onRefresh(dragging = false) {}
547
+ onUpdate(data) {}
548
+ async onClear() {}
549
+ async onStart() {}
550
+ async onStop() {}
551
+ };
552
+ //#endregion
553
+ //#region src/graph/projector/graph-projector.ts
554
+ /**
555
+ * Base class for graph projectors.
556
+ */
557
+ var GraphProjector = class extends Projector {
558
+ _selection;
559
+ _layout;
560
+ constructor(context, options, _selection, layout) {
561
+ super(context, options);
562
+ this._selection = _selection;
563
+ this._layout = {
564
+ id: (Math.random() * 10).toString().slice(8),
565
+ graph: {
566
+ nodes: [...layout?.graph.nodes ?? []],
567
+ edges: [...layout?.graph.edges ?? []]
568
+ }
569
+ };
570
+ }
571
+ get layout() {
572
+ return this._layout;
573
+ }
574
+ get selection() {
575
+ return this._selection;
576
+ }
577
+ numChildren(node) {
578
+ return this._layout.graph.edges.filter((edge) => edge.source.id === this.options.idAccessor(node)).length;
579
+ }
580
+ reset() {
581
+ this._layout.graph.nodes = [];
582
+ this._layout.graph.edges = [];
583
+ this.emitUpdate();
584
+ }
585
+ /**
586
+ * Merge external data with internal representation (e.g., so force properties like position are preserved).
587
+ * @param data
588
+ */
589
+ mergeData(data = emptyGraph) {
590
+ const nodes = data.nodes.map((node) => {
591
+ let current = this._layout.graph.nodes.find((n) => n.id === this.options.idAccessor(node));
592
+ if (!current) current = { id: this.options.idAccessor(node) };
593
+ current.data = node;
594
+ current.hidden = false;
595
+ return current;
596
+ });
597
+ const edges = data.edges.map((edge) => ({
598
+ id: edge.id,
599
+ type: edge.type,
600
+ source: nodes.find((n) => n.id === edge.source),
601
+ target: nodes.find((n) => n.id === edge.target),
602
+ data: edge.data
603
+ })).filter((edge) => edge.source && edge.target);
604
+ Object.assign(this._layout, { graph: {
605
+ nodes,
606
+ edges
607
+ } });
608
+ }
609
+ async onClear() {
610
+ this.reset();
611
+ }
612
+ /**
613
+ * Optional projector-owned click intercept. The Graph component invokes this BEFORE
614
+ * forwarding to the consumer's `onSelect`, so projectors can implement built-in
615
+ * interactions (e.g. cluster collapse) without each consumer wiring them. Returning
616
+ * `true` indicates the click was handled — consumer's `onSelect` is suppressed.
617
+ * Default no-op returns `false` so consumer handlers still run.
618
+ */
619
+ handleNodeClick(_node, _event) {
620
+ return false;
621
+ }
622
+ };
623
+ //#endregion
624
+ //#region src/graph/projector/graph-radial-projector.ts
625
+ var __dxlog_file$11 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
626
+ var GraphRadialProjector = class extends GraphProjector {
627
+ _timer;
628
+ findNode(x, y, radius) {}
629
+ onUpdate(graph) {
630
+ log("onUpdate", { graph: {
631
+ nodes: graph?.nodes.length,
632
+ edges: graph?.edges.length
633
+ } }, {
634
+ "~LogMeta": "~LogMeta",
635
+ F: __dxlog_file$11,
636
+ L: 31,
637
+ S: this
638
+ });
639
+ this.mergeData(graph);
640
+ this.emitUpdate("topology");
641
+ this.doRadialLayout();
642
+ }
643
+ animate() {
644
+ this._timer?.stop();
645
+ this._timer = void 0;
646
+ const start = Date.now();
647
+ if (this.options.duration) this._timer = timer(() => {
648
+ const t = Math.min(1, (Date.now() - start) / this.options.duration);
649
+ const d = easeCubic(t);
650
+ this.layout.graph.nodes.forEach((node) => {
651
+ node.x = node.sx + (node.tx - node.sx) * d;
652
+ node.y = node.sy + (node.ty - node.sy) * d;
653
+ node.r = node.sr + (node.tr - node.sr) * d;
654
+ });
655
+ this.onTickFrame(d);
656
+ this.emitUpdate("positions");
657
+ if (t >= 1) {
658
+ this._timer.stop();
659
+ this._timer = void 0;
660
+ }
661
+ });
662
+ else {
663
+ this.layout.graph.nodes.forEach((node) => {
664
+ node.x = node.tx;
665
+ node.y = node.ty;
666
+ node.r = node.tr;
667
+ });
668
+ this.onTickFrame(1);
669
+ this.emitUpdate("positions");
670
+ }
671
+ }
672
+ /**
673
+ * Per-frame hook called after node x/y/r are interpolated and before the
674
+ * 'positions' emit. Subclasses override to update edge geometry (`edge.path`)
675
+ * so curves stay glued to moving endpoints. `t` is the eased progress in [0, 1].
676
+ */
677
+ onTickFrame(t) {}
678
+ async onStop() {
679
+ this._timer?.stop();
680
+ this._timer = void 0;
681
+ }
682
+ doRadialLayout() {
683
+ if (!this.context.size) return;
684
+ const radial = layoutRadial(0, 0, this.options.radius ?? Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 80), this.layout.graph.nodes.length);
685
+ this.layout.graph.nodes.forEach((node, i) => {
686
+ const [tx, ty] = radial(i);
687
+ updateNode(node, [tx, ty]);
688
+ });
689
+ this.animate();
690
+ }
691
+ };
692
+ /**
693
+ * Update node target.
694
+ */
695
+ var updateNode = (node, [tx, ty], tr = 8) => {
696
+ const sx = node.x ?? tx;
697
+ const sy = node.y ?? ty;
698
+ const sr = node.r ?? tr;
699
+ Object.assign(node, {
700
+ initialized: true,
701
+ sx,
702
+ sy,
703
+ sr,
704
+ tx,
705
+ ty,
706
+ tr,
707
+ x: sx,
708
+ y: sy,
709
+ r: sr
710
+ });
711
+ };
712
+ /**
713
+ * Radial position generator.
714
+ */
715
+ var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
716
+ const da = 2 * Math.PI / n;
717
+ return (i) => {
718
+ const a = start + i * da;
719
+ return [x + Math.cos(a) * r, y + Math.sin(a) * r];
720
+ };
721
+ };
722
+ /**
723
+ * Horizontal position generator.
724
+ */
725
+ var layoutHorizontal = (x, y, w, n) => {
726
+ const dx = n > 1 ? w / (n - 1) : 0;
727
+ const sx = x - (n - 1) * dx / 2;
728
+ return (i) => {
729
+ return [sx + i * dx, y];
730
+ };
731
+ };
732
+ /**
733
+ * Vertical position generator.
734
+ */
735
+ var layoutVertical = (x, y, h, n) => {
736
+ const dy = n > 1 ? h / (n - 1) : 0;
737
+ const sy = y - (n - 1) * dy / 2;
738
+ return (i) => {
739
+ return [x, sy + i * dy];
740
+ };
741
+ };
742
+ //#endregion
743
+ //#region src/graph/projector/graph-bundle-projector.ts
744
+ var __dxlog_file$10 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-bundle-projector.ts";
745
+ var ROOT_ID$1 = "__bundle_root__";
746
+ var GROUP_PREFIX$1 = "__bundle_group__:";
747
+ /**
748
+ * Cartesian → d3-radial polar. d3 measures angle clockwise from "up" (the -y direction).
749
+ * Inverse of `[cos(a - π/2) * r, sin(a - π/2) * r]`.
750
+ */
751
+ var cartesianToPolar$2 = (x, y) => ({
752
+ angle: Math.atan2(x, -y),
753
+ radius: Math.hypot(x, y)
754
+ });
755
+ /**
756
+ * Hierarchical edge bundling — Holten 2006 / d3 observable notebook
757
+ * (https://observablehq.com/@d3/hierarchical-edge-bundling).
758
+ *
759
+ * Synthesizes the same root → group → leaf hierarchy as `GraphClusterProjector`, runs
760
+ * d3.cluster to give every node a polar position, but renders ONLY the leaves
761
+ * (root + groups are routing anchors, not visible nodes). Each data edge is replaced
762
+ * with a curve generated by `lineRadial(curveBundle.beta(tension))` over the polar
763
+ * positions of `source.path(target)` — i.e. the chain of ancestors through the lowest
764
+ * common ancestor.
765
+ *
766
+ * Per-frame `onTickFrame` refreshes the leaf endpoints (first + last point of every
767
+ * path) from current cartesian positions so the curves stay glued to leaves during a
768
+ * cross-variant tween (force → bundle, lattice → bundle). Internal ancestor positions
769
+ * are fixed at d3.cluster's final polar layout, which means during the tween curves
770
+ * route through the destination "pivot points" while the leaf endpoints catch up —
771
+ * visually the bundle "snaps into shape" as the leaves arrive.
772
+ */
773
+ var GraphBundleProjector = class extends GraphRadialProjector {
774
+ #edgePoints = /* @__PURE__ */ new Map();
775
+ #lineGen = lineRadial().radius((d) => d.radius).angle((d) => d.angle);
776
+ onUpdate(graph) {
777
+ log("onUpdate", { graph: {
778
+ nodes: graph?.nodes.length,
779
+ edges: graph?.edges.length
780
+ } }, {
781
+ "~LogMeta": "~LogMeta",
782
+ F: __dxlog_file$10,
783
+ L: 74,
784
+ S: this
785
+ });
786
+ this.mergeData(graph);
787
+ this.doBundleLayout();
788
+ this.emitUpdate("topology");
789
+ this.animate();
790
+ }
791
+ /**
792
+ * Refresh leaf endpoint polar values from current cartesian so the curve tracks
793
+ * its endpoints during the tween. Internal hierarchy positions stay constant.
794
+ */
795
+ onTickFrame(_t) {
796
+ for (const edge of this.layout.graph.edges) {
797
+ if (edge.type !== "bundle") continue;
798
+ const points = this.#edgePoints.get(edge.id);
799
+ if (!points || points.length < 2) continue;
800
+ const s = cartesianToPolar$2(edge.source.x ?? 0, edge.source.y ?? 0);
801
+ const t = cartesianToPolar$2(edge.target.x ?? 0, edge.target.y ?? 0);
802
+ points[0] = {
803
+ angle: s.angle,
804
+ radius: s.radius
805
+ };
806
+ points[points.length - 1] = {
807
+ angle: t.angle,
808
+ radius: t.radius
809
+ };
810
+ edge.path = this.#lineGen(points) ?? void 0;
811
+ }
812
+ }
813
+ doBundleLayout() {
814
+ if (!this.context.size) return;
815
+ const dataNodes = [...this.layout.graph.nodes];
816
+ if (!dataNodes.length) return;
817
+ const groupOf = this.options.groupOf;
818
+ const items = [{ id: ROOT_ID$1 }];
819
+ const groupIds = /* @__PURE__ */ new Map();
820
+ for (const node of dataNodes) {
821
+ const key = groupOf?.(node);
822
+ let parent = ROOT_ID$1;
823
+ if (key !== void 0) {
824
+ let groupId = groupIds.get(key);
825
+ if (!groupId) {
826
+ groupId = `${GROUP_PREFIX$1}${key}`;
827
+ groupIds.set(key, groupId);
828
+ items.push({
829
+ id: groupId,
830
+ parent: ROOT_ID$1
831
+ });
832
+ }
833
+ parent = groupId;
834
+ }
835
+ items.push({
836
+ id: node.id,
837
+ parent,
838
+ node
839
+ });
840
+ }
841
+ const childrenByParent = /* @__PURE__ */ new Map();
842
+ for (const item of items) if (item.parent) {
843
+ const list = childrenByParent.get(item.parent) ?? [];
844
+ list.push(item);
845
+ childrenByParent.set(item.parent, list);
846
+ }
847
+ const root = hierarchy({ id: ROOT_ID$1 }, (d) => childrenByParent.get(d.id) ?? []);
848
+ const { width, height } = this.context.size;
849
+ const margin = this.options.margin ?? 120;
850
+ const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
851
+ cluster().size([2 * Math.PI, ringRadius]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
852
+ const leafR = this.options.leafRadius ?? 4;
853
+ const tension = this.options.tension ?? .85;
854
+ this.#lineGen = lineRadial().curve(curveBundle.beta(tension)).radius((d) => d.radius).angle((d) => d.angle);
855
+ const hierById = /* @__PURE__ */ new Map();
856
+ root.each((d) => {
857
+ hierById.set(d.data.id, d);
858
+ });
859
+ root.leaves().forEach((d) => {
860
+ const angle = d.x;
861
+ const radius = d.y;
862
+ const x = Math.cos(angle - Math.PI / 2) * radius;
863
+ const y = Math.sin(angle - Math.PI / 2) * radius;
864
+ if (d.data.node) updateNode(d.data.node, [x, y], leafR);
865
+ });
866
+ this.layout.graph.nodes = dataNodes;
867
+ this.#edgePoints.clear();
868
+ const incomingEdges = [...this.layout.graph.edges];
869
+ const bundleEdges = [];
870
+ for (const edge of incomingEdges) {
871
+ const sourceHier = hierById.get(edge.source.id);
872
+ const targetHier = hierById.get(edge.target.id);
873
+ if (!sourceHier || !targetHier || sourceHier === targetHier) continue;
874
+ const points = sourceHier.path(targetHier).map((n) => ({
875
+ angle: n.x,
876
+ radius: n.y
877
+ }));
878
+ this.#edgePoints.set(edge.id, points);
879
+ bundleEdges.push({
880
+ id: edge.id,
881
+ type: "bundle",
882
+ source: edge.source,
883
+ target: edge.target,
884
+ data: edge.data
885
+ });
886
+ }
887
+ this.layout.graph.edges = bundleEdges;
888
+ this.onTickFrame(0);
889
+ }
890
+ };
891
+ //#endregion
892
+ //#region src/graph/projector/graph-cluster-projector.ts
893
+ var __dxlog_file$9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-cluster-projector.ts";
894
+ var ROOT_ID = "__cluster_root__";
895
+ var GROUP_PREFIX = "__group__:";
896
+ var HIER_EDGE_PREFIX$2 = "__hier__:";
897
+ /** Node type tags so consumer renderers can distinguish leaves from synthetic structural nodes. */
898
+ var CLUSTER_NODE_TYPE_LEAF = "leaf";
899
+ var CLUSTER_NODE_TYPE_GROUP = "group";
900
+ var CLUSTER_NODE_TYPE_ROOT = "root";
901
+ /**
902
+ * Standard d3 radial link generator — `curveBumpRadial`. Same shape as the original
903
+ * `RadialTree` component (and the d3 radial-cluster observable notebook).
904
+ *
905
+ * IMPORTANT: relies on the `dx-edge path` CSS setting `fill: none`. Without that, the SVG
906
+ * default fill (black) closes the curve across the source-target chord and visually
907
+ * swallows part of the stroke. The Graph engine's `createEdge` doesn't set `fill='none'`
908
+ * inline (unlike the original RadialTree), so the rule lives in graph.css.
909
+ */
910
+ var linkPath$2 = linkRadial().angle((d) => d.x).radius((d) => d.y);
911
+ /**
912
+ * Cartesian → d3-radial polar. d3 measures angle clockwise from "up" (the -y direction).
913
+ * Inverse of `[cos(a - π/2) * r, sin(a - π/2) * r]`.
914
+ */
915
+ var cartesianToPolar$1 = (x, y) => ({
916
+ angle: Math.atan2(x, -y),
917
+ radius: Math.hypot(x, y)
918
+ });
919
+ /**
920
+ * Radial cluster (d3.cluster) layout. Materializes a root → group → leaf
921
+ * hierarchy from the `groupOf` callback, runs d3.cluster, and:
922
+ *
923
+ * - Places leaves around the outer ring; synthetic group nodes sit on an
924
+ * inner ring; the root sits at the origin. All three kinds are added to the
925
+ * layout so they render via the consumer's `renderNode` (the `type` field
926
+ * identifies which is which).
927
+ * - Each hierarchy edge carries a `path` string (d3's `linkRadial` curve)
928
+ * computed from CURRENT cartesian endpoint positions every frame via
929
+ * `onTickFrame`. The curve therefore tracks moving endpoints during a
930
+ * cross-variant tween (e.g. force → cluster) instead of snapping to the
931
+ * final polar shape.
932
+ */
933
+ var GraphClusterProjector = class extends GraphRadialProjector {
934
+ #collapsed = /* @__PURE__ */ new Set();
935
+ #dataNodes = [];
936
+ /**
937
+ * Built-in click semantics: clicking a synthetic root / group node toggles its subtree.
938
+ * Leaf clicks fall through to the consumer's `onSelect` (returns `false`).
939
+ */
940
+ handleNodeClick(node, _event) {
941
+ if (node.type !== "root" && node.type !== "group") return false;
942
+ this.toggleCollapsed(node.id);
943
+ return true;
944
+ }
945
+ /** Toggle collapse state for a synthetic node id. Triggers a topology re-emit. */
946
+ toggleCollapsed(id) {
947
+ if (this.#collapsed.has(id)) this.#collapsed.delete(id);
948
+ else this.#collapsed.add(id);
949
+ this.doClusterLayout();
950
+ this.emitUpdate("topology");
951
+ this.animate();
952
+ }
953
+ /** Whether a synthetic-node id is currently collapsed. */
954
+ isCollapsed(id) {
955
+ return this.#collapsed.has(id);
956
+ }
957
+ onUpdate(graph) {
958
+ log("onUpdate", { graph: {
959
+ nodes: graph?.nodes.length,
960
+ edges: graph?.edges.length
961
+ } }, {
962
+ "~LogMeta": "~LogMeta",
963
+ F: __dxlog_file$9,
964
+ L: 130,
965
+ S: this
966
+ });
967
+ this.mergeData(graph);
968
+ this.#dataNodes = [...this.layout.graph.nodes];
969
+ this.doClusterLayout();
970
+ this.emitUpdate("topology");
971
+ this.animate();
972
+ }
973
+ /**
974
+ * Recompute each hierarchy edge's `path` from current cartesian source/target positions,
975
+ * so the curves track moving endpoints during a cross-variant tween (e.g. force → cluster)
976
+ * instead of being pinned to the final polar layout.
977
+ */
978
+ onTickFrame(_t) {
979
+ for (const edge of this.layout.graph.edges) {
980
+ if (edge.type !== "hierarchy") continue;
981
+ const { source, target } = edge;
982
+ const s = cartesianToPolar$1(source.x ?? 0, source.y ?? 0);
983
+ const t = cartesianToPolar$1(target.x ?? 0, target.y ?? 0);
984
+ edge.path = linkPath$2({
985
+ source: {
986
+ x: s.angle,
987
+ y: s.radius
988
+ },
989
+ target: {
990
+ x: t.angle,
991
+ y: t.radius
992
+ }
993
+ });
994
+ }
995
+ }
996
+ doClusterLayout() {
997
+ if (!this.context.size) return;
998
+ const dataNodes = this.#dataNodes;
999
+ if (!dataNodes.length) return;
1000
+ const groupOf = this.options.groupOf;
1001
+ const rootId = this.options.rootId ?? ROOT_ID;
1002
+ const items = [{ id: rootId }];
1003
+ const groupIds = /* @__PURE__ */ new Map();
1004
+ if (!this.#collapsed.has(rootId)) for (const node of dataNodes) {
1005
+ const key = groupOf?.(node);
1006
+ let parent = rootId;
1007
+ if (key !== void 0) {
1008
+ let groupId = groupIds.get(key);
1009
+ if (!groupId) {
1010
+ groupId = `${GROUP_PREFIX}${key}`;
1011
+ groupIds.set(key, groupId);
1012
+ items.push({
1013
+ id: groupId,
1014
+ parent: rootId,
1015
+ groupKey: key
1016
+ });
1017
+ }
1018
+ parent = groupId;
1019
+ }
1020
+ if (this.#collapsed.has(parent)) continue;
1021
+ items.push({
1022
+ id: node.id,
1023
+ parent,
1024
+ node
1025
+ });
1026
+ }
1027
+ const childrenByParent = /* @__PURE__ */ new Map();
1028
+ for (const item of items) if (item.parent) {
1029
+ const list = childrenByParent.get(item.parent) ?? [];
1030
+ list.push(item);
1031
+ childrenByParent.set(item.parent, list);
1032
+ }
1033
+ const root = hierarchy({ id: rootId }, (d) => childrenByParent.get(d.id) ?? []);
1034
+ const { width, height } = this.context.size;
1035
+ const margin = this.options.margin ?? 80;
1036
+ const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
1037
+ cluster().size([2 * Math.PI, ringRadius]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
1038
+ const leafR = this.options.leafRadius ?? 4;
1039
+ const groupR = this.options.groupRadius ?? 3;
1040
+ const rootR = this.options.rootRadius ?? 5;
1041
+ const prevStubsById = /* @__PURE__ */ new Map();
1042
+ for (const node of this.layout.graph.nodes) if (node.type === "root" || node.type === "group") prevStubsById.set(node.id, node);
1043
+ const syntheticNodes = /* @__PURE__ */ new Map();
1044
+ root.each((d) => {
1045
+ const id = d.data.id;
1046
+ const angle = d.x;
1047
+ const radius = d.y;
1048
+ const x = Math.cos(angle - Math.PI / 2) * radius;
1049
+ const y = Math.sin(angle - Math.PI / 2) * radius;
1050
+ if (d.data.node) {
1051
+ updateNode(d.data.node, [x, y], leafR);
1052
+ d.data.node.type = CLUSTER_NODE_TYPE_LEAF;
1053
+ d.data.node.hidden = false;
1054
+ } else {
1055
+ const isRoot = id === rootId;
1056
+ const stub = prevStubsById.get(id) ?? {
1057
+ id,
1058
+ x: 0,
1059
+ y: 0
1060
+ };
1061
+ updateNode(stub, [x, y], isRoot ? rootR : groupR);
1062
+ stub.type = isRoot ? CLUSTER_NODE_TYPE_ROOT : CLUSTER_NODE_TYPE_GROUP;
1063
+ if (isRoot) stub.label = this.options.rootLabel;
1064
+ else if (d.data.groupKey !== void 0) stub.label = this.options.groupLabel ? this.options.groupLabel(d.data.groupKey) : d.data.groupKey;
1065
+ syntheticNodes.set(id, stub);
1066
+ }
1067
+ });
1068
+ const visibleLeafIds = /* @__PURE__ */ new Set();
1069
+ for (const item of items) if (item.node) visibleLeafIds.add(item.id);
1070
+ for (const node of dataNodes) {
1071
+ if (visibleLeafIds.has(node.id)) continue;
1072
+ const key = groupOf?.(node);
1073
+ const parentId = key !== void 0 && groupIds.has(key) ? groupIds.get(key) : rootId;
1074
+ const parentStub = syntheticNodes.get(parentId);
1075
+ updateNode(node, [parentStub?.tx ?? 0, parentStub?.ty ?? 0], leafR);
1076
+ node.type = CLUSTER_NODE_TYPE_LEAF;
1077
+ node.hidden = true;
1078
+ }
1079
+ const nextNodes = [];
1080
+ for (const stub of syntheticNodes.values()) nextNodes.push(stub);
1081
+ for (const node of dataNodes) nextNodes.push(node);
1082
+ this.layout.graph.nodes = nextNodes;
1083
+ const hierarchyEdges = [];
1084
+ root.links().forEach((link) => {
1085
+ const sid = link.source.data.id;
1086
+ const tid = link.target.data.id;
1087
+ const sourceNode = link.source.data.node ?? syntheticNodes.get(sid);
1088
+ const targetNode = link.target.data.node ?? syntheticNodes.get(tid);
1089
+ hierarchyEdges.push({
1090
+ id: `${HIER_EDGE_PREFIX$2}${sid}->${tid}`,
1091
+ type: "hierarchy",
1092
+ source: sourceNode,
1093
+ target: targetNode,
1094
+ data: void 0
1095
+ });
1096
+ });
1097
+ this.layout.graph.edges = hierarchyEdges;
1098
+ this.onTickFrame(0);
1099
+ }
1100
+ };
1101
+ //#endregion
1102
+ //#region src/graph/projector/graph-drag.ts
1103
+ var defaultDragOptions = {
1104
+ linkMod: "metaKey",
1105
+ freezeMod: "shiftKey"
1106
+ };
1107
+ /**
1108
+ * Create drag handler.
1109
+ */
1110
+ var createGraphDrag = (context, projector, options = defaultDragOptions) => {
1111
+ let mode;
1112
+ let source;
1113
+ let target;
1114
+ let offset;
1115
+ let moved = false;
1116
+ const keyMod = (event, key) => {
1117
+ const modKey = options?.[key] ?? defaultDragOptions[key];
1118
+ return modKey === void 0 || event[modKey];
1119
+ };
1120
+ return drag().filter((event) => !event.ctrlKey).on("start", function(event, d) {
1121
+ source = d;
1122
+ offset = pointer(event, this.parentElement);
1123
+ if (options?.onDrop && keyMod(event.sourceEvent, "linkMod")) mode = 1;
1124
+ else if (keyMod(event.sourceEvent, "dragMod")) mode = 0;
1125
+ }).on("drag", function(event, d) {
1126
+ select(this.closest("g.node")).classed("dragging", true).raise();
1127
+ const [dx, dy] = pointer(event, this.parentElement);
1128
+ const point = [d.x + dx - offset[0], d.y + dy - offset[1]];
1129
+ switch (mode) {
1130
+ case 0:
1131
+ select(context.svg).attr("cursor", "grabbing");
1132
+ event.subject.x = event.subject.fx = point[0];
1133
+ event.subject.y = event.subject.fy = point[1];
1134
+ projector.refresh(true);
1135
+ moved = true;
1136
+ break;
1137
+ case 1: if (options?.onDrag) {
1138
+ target = projector.findNode(event.x, event.y, 16);
1139
+ if (source === target) {
1140
+ select(context.svg).attr("cursor", void 0);
1141
+ options?.onDrag?.();
1142
+ } else {
1143
+ select(context.svg).attr("cursor", target ? "alias" : "cell");
1144
+ options?.onDrag?.(source, target, point);
1145
+ }
1146
+ }
1147
+ }
1148
+ }).on("end", function(event) {
1149
+ select(context.svg).attr("cursor", void 0);
1150
+ select(this.parentElement).classed("dragging", false);
1151
+ switch (mode) {
1152
+ case 1:
1153
+ options?.onDrop?.(source, target);
1154
+ break;
1155
+ }
1156
+ if (!keyMod(event.sourceEvent, "freezeMod")) {
1157
+ event.subject.fx = null;
1158
+ event.subject.fy = null;
1159
+ }
1160
+ mode = void 0;
1161
+ source = void 0;
1162
+ target = void 0;
1163
+ offset = void 0;
1164
+ if (moved) {
1165
+ projector.refresh(false);
1166
+ moved = false;
1167
+ }
1168
+ });
1169
+ };
1170
+ //#endregion
1171
+ //#region src/graph/projector/graph-forces.ts
1172
+ var forcePoint = ({ x, y, strength = .01 }) => {
1173
+ const fx = x != null ? forceX(x).strength(strength) : void 0;
1174
+ const fy = y != null ? forceY(y).strength(strength) : void 0;
1175
+ const force = (alpha) => {
1176
+ fx?.(alpha);
1177
+ fy?.(alpha);
1178
+ };
1179
+ force.initialize = (nodes, random) => {
1180
+ fx?.initialize(nodes, random);
1181
+ fy?.initialize(nodes, random);
1182
+ };
1183
+ return force;
1184
+ };
1185
+ //#endregion
1186
+ //#region src/graph/projector/graph-force-projector.ts
1187
+ var __dxlog_file$8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
1188
+ /**
1189
+ * Return value or invoke function.
1190
+ * @param valueOrFunction
1191
+ * @param invoker
1192
+ * @param defaultValue
1193
+ */
1194
+ var getValue = (valueOrFunction, invoker, defaultValue) => {
1195
+ return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
1196
+ };
1197
+ /**
1198
+ * Returns the config object or an empty object if the property is set to true (or defaults to true).
1199
+ * Otherwise returns undefined.
1200
+ * @param options
1201
+ * @param cb
1202
+ * @param defaultValue
1203
+ */
1204
+ var maybeForce = (options, cb, defaultValue = void 0) => {
1205
+ const value = typeof options === "boolean" ? options ? {} : void 0 : options ?? defaultValue;
1206
+ if (value) return cb(value);
1207
+ };
1208
+ var defaultForceOptions = {
1209
+ link: true,
1210
+ manyBody: true,
1211
+ point: true
1212
+ };
1213
+ /**
1214
+ * D3 force directed graph layout using d3 simulation..
1215
+ */
1216
+ var GraphForceProjector = class extends GraphProjector {
1217
+ _simulation = forceSimulation();
1218
+ _timeout;
1219
+ get forces() {
1220
+ return this.options.forces ?? defaultForceOptions;
1221
+ }
1222
+ get simulation() {
1223
+ return this._simulation;
1224
+ }
1225
+ restart() {
1226
+ this._simulation.alpha(1).restart();
1227
+ }
1228
+ findNode(x, y, radius) {
1229
+ return this._simulation.find(x, y, radius);
1230
+ }
1231
+ async onStart() {
1232
+ clearTimeout(this._timeout);
1233
+ let propagating = true;
1234
+ const { radial, ...forces } = this.forces;
1235
+ const delay = typeof radial === "object" ? radial.delay : void 0;
1236
+ if (delay) {
1237
+ propagating = false;
1238
+ this.updateForces(forces);
1239
+ this._timeout = setTimeout(() => {
1240
+ this.updateForces(this.forces);
1241
+ this.restart();
1242
+ this._timeout = setTimeout(() => {
1243
+ propagating = true;
1244
+ }, delay);
1245
+ }, delay);
1246
+ } else this.updateForces(this.forces);
1247
+ this._simulation.on("tick", () => propagating && this.emitUpdate("positions")).velocityDecay(.3).alphaDecay(1 - Math.pow(.001, 1 / 300)).alpha(1).restart();
1248
+ }
1249
+ async onStop() {
1250
+ clearTimeout(this._timeout);
1251
+ this._simulation.stop();
1252
+ }
1253
+ onRefresh(dragging = false) {
1254
+ if (this.forces.center) if (dragging) this._simulation.force("center", null);
1255
+ else this.updateForces(this.forces);
1256
+ this.restart();
1257
+ }
1258
+ onUpdate(graph) {
1259
+ log("onUpdate", { graph: {
1260
+ nodes: graph?.nodes.length,
1261
+ edges: graph?.edges.length
1262
+ } }, {
1263
+ "~LogMeta": "~LogMeta",
1264
+ F: __dxlog_file$8,
1265
+ L: 228,
1266
+ S: this
1267
+ });
1268
+ this._simulation.stop();
1269
+ this.mergeData(graph);
1270
+ this.updateLayout();
1271
+ this.updateForces(this.forces);
1272
+ this.emitUpdate("topology");
1273
+ this.restart();
1274
+ }
1275
+ updateLayout() {
1276
+ this.layout.guides = this.options.guides ? [{
1277
+ id: "g-1",
1278
+ type: "circle",
1279
+ cx: 0,
1280
+ cy: 0,
1281
+ r: this.context.scale.model.toValue([10, 1])
1282
+ }] : void 0;
1283
+ this.layout.graph.nodes.forEach((node) => {
1284
+ if (!node.initialized) {
1285
+ const a = 2 * Math.PI * Math.random();
1286
+ const r = this.options.radius ?? 200;
1287
+ Object.assign(node, {
1288
+ initialized: true,
1289
+ x: Math.cos(a) * r,
1290
+ y: Math.sin(a) * r
1291
+ });
1292
+ }
1293
+ Object.assign(node, { r: getValue(this.options?.attributes?.radius, (fn) => fn(node, this.numChildren(node)), 6) });
1294
+ });
1295
+ this.layout.graph.edges.forEach((edge) => {
1296
+ Object.assign(edge, { linkForce: getValue(this.options.attributes?.linkForce, (fn) => fn(edge), true) });
1297
+ });
1298
+ }
1299
+ /**
1300
+ * Update all forces.
1301
+ */
1302
+ updateForces(forces) {
1303
+ log("updateForces", { forces }, {
1304
+ "~LogMeta": "~LogMeta",
1305
+ F: __dxlog_file$8,
1306
+ L: 292,
1307
+ S: this
1308
+ });
1309
+ this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
1310
+ const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
1311
+ if (config.distance != null) force.distance(config.distance);
1312
+ if (config.strength != null) force.strength(config.strength);
1313
+ if (config.iterations != null) force.iterations(config.iterations);
1314
+ return force;
1315
+ }, forces?.link === false ? void 0 : {})).force("manyBody", maybeForce(forces?.manyBody, (config) => {
1316
+ const force = forceManyBody();
1317
+ if (config.distanceMax != null) force.distanceMax(config.distanceMax);
1318
+ if (config.strength != null) force.strength(config.strength);
1319
+ return force;
1320
+ }, forces?.manyBody === false ? void 0 : {})).force("collide", maybeForce(forces?.collide, (config) => {
1321
+ const force = forceCollide();
1322
+ force.radius(config.radius ?? 8);
1323
+ if (config.strength != null) force.strength(config.strength);
1324
+ return force;
1325
+ })).force("radial", maybeForce(forces?.radial, (config) => {
1326
+ const force = forceRadial(config.radius ?? 100, config.x ?? 0, config.y ?? 0);
1327
+ if (config.strength != null) force.strength(config.strength);
1328
+ return force;
1329
+ })).force("center", maybeForce(forces?.center, (config) => {
1330
+ const force = forceCenter().x(config.x ?? 0).y(config.y ?? 0);
1331
+ if (config.strength != null) force.strength(config.strength);
1332
+ return force;
1333
+ })).force("point", maybeForce(forces?.point, ({ x = 0, y = 0, strength }) => {
1334
+ return forcePoint({
1335
+ x,
1336
+ y,
1337
+ strength
1338
+ });
1339
+ })).force("x", maybeForce(forces?.x, (config) => {
1340
+ const force = forceX(config.x ?? 0);
1341
+ if (config.strength != null) force.strength(config.strength);
1342
+ return force;
1343
+ })).force("y", maybeForce(forces?.y, (config) => {
1344
+ const force = forceY(config.y ?? 0);
1345
+ if (config.strength != null) force.strength(config.strength);
1346
+ return force;
1347
+ }));
1348
+ }
1349
+ };
1350
+ //#endregion
1351
+ //#region src/graph/projector/graph-hierarchical-projector.ts
1352
+ var __dxlog_file$7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
1353
+ var GraphHierarchicalProjector = class extends GraphRadialProjector {
1354
+ onUpdate(graph) {
1355
+ log("onUpdate", {
1356
+ graph: {
1357
+ nodes: graph?.nodes.length,
1358
+ edges: graph?.edges.length
1359
+ },
1360
+ selection: this.selection?.getSelectedIds()
1361
+ }, {
1362
+ "~LogMeta": "~LogMeta",
1363
+ F: __dxlog_file$7,
1364
+ L: 23,
1365
+ S: this
1366
+ });
1367
+ this.mergeData(graph);
1368
+ this.emitUpdate("topology");
1369
+ const selected = this.selection?.getSelectedIds()[0];
1370
+ if (selected) {
1371
+ const node = this.layout.graph.nodes.find((node) => node.id === selected);
1372
+ if (node) {
1373
+ this.doHierarchicalLayout(node);
1374
+ return;
1375
+ }
1376
+ }
1377
+ this.doRadialLayout();
1378
+ }
1379
+ doHierarchicalLayout(selected) {
1380
+ if (!this.context.size) return;
1381
+ const r2 = this.options.radius ?? Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 80);
1382
+ const r1 = r2 / 2;
1383
+ const children = this.layout.graph.edges.filter((edge) => edge.source.id === selected.id).map((edge) => edge.target);
1384
+ updateNode(selected, [0, 0], 20);
1385
+ {
1386
+ const radial = layoutRadial(0, 0, r1, children.length);
1387
+ children.forEach((node, i) => {
1388
+ const [tx, ty] = radial(i);
1389
+ updateNode(node, [tx, ty]);
1390
+ });
1391
+ }
1392
+ {
1393
+ const radial = layoutRadial(0, 0, r2, this.layout.graph.nodes.length - 1 - children.length);
1394
+ this.layout.graph.nodes.filter((node) => node.id !== selected.id && !children.includes(node)).forEach((node, i) => {
1395
+ const [tx, ty] = radial(i);
1396
+ updateNode(node, [tx, ty]);
1397
+ });
1398
+ }
1399
+ this.animate();
1400
+ }
1401
+ };
1402
+ //#endregion
1403
+ //#region src/graph/projector/graph-lattice-projector.ts
1404
+ var __dxlog_file$6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-lattice-projector.ts";
1405
+ /**
1406
+ * Lays out nodes as a square-as-possible grid that fits the container.
1407
+ * Extends `GraphRadialProjector` to inherit the tween (`updateNode` + `animate`),
1408
+ * so switching to / from this layout animates each node from its current
1409
+ * position to the grid cell — and the initial mount can also "grow" from
1410
+ * existing positions if seeded with a prior projector's layout.
1411
+ */
1412
+ var GraphLatticeProjector = class extends GraphRadialProjector {
1413
+ onUpdate(graph) {
1414
+ log("onUpdate", { graph: {
1415
+ nodes: graph?.nodes.length,
1416
+ edges: graph?.edges.length
1417
+ } }, {
1418
+ "~LogMeta": "~LogMeta",
1419
+ F: __dxlog_file$6,
1420
+ L: 32,
1421
+ S: this
1422
+ });
1423
+ this.mergeData(graph);
1424
+ this.doLatticeLayout();
1425
+ this.emitUpdate("topology");
1426
+ this.animate();
1427
+ }
1428
+ doLatticeLayout() {
1429
+ if (!this.context.size) return;
1430
+ const nodes = this.layout.graph.nodes;
1431
+ const count = nodes.length;
1432
+ if (!count) return;
1433
+ const sortBy = this.options.sortBy ?? ((n) => n.data?.label ?? n.id);
1434
+ nodes.sort((a, b) => sortBy(a).localeCompare(sortBy(b)));
1435
+ const columns = Math.max(1, Math.ceil(Math.sqrt(count)));
1436
+ const rows = Math.ceil(count / columns);
1437
+ const margin = this.options.margin ?? 16;
1438
+ const { width, height } = this.context.size;
1439
+ const innerW = Math.max(0, width - 2 * margin);
1440
+ const innerH = Math.max(0, height - 2 * margin);
1441
+ const r = this.options.radius ?? 6;
1442
+ const fit = Math.min(innerW / columns, innerH / rows);
1443
+ const cellSize = Math.max(0, Math.min(fit, r * 6));
1444
+ const gridW = cellSize * columns;
1445
+ const gridH = cellSize * rows;
1446
+ const offsetX = -gridW / 2 + cellSize / 2;
1447
+ const offsetY = -gridH / 2 + cellSize / 2;
1448
+ nodes.forEach((node, i) => {
1449
+ updateNode(node, [offsetX + i % columns * cellSize, offsetY + Math.floor(i / columns) * cellSize], r);
1450
+ });
1451
+ }
1452
+ };
1453
+ //#endregion
1454
+ //#region src/graph/projector/graph-plexus-projector.ts
1455
+ var __dxlog_file$5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-plexus-projector.ts";
1456
+ var RELATION_PREFIX = "__plexus_relation__:";
1457
+ var HIER_EDGE_PREFIX$1 = "__plexus_hier__:";
1458
+ /** Node type tags so consumer renderers can distinguish the three kinds of node. */
1459
+ var PLEXUS_NODE_TYPE_FOCUS = "plexus-focus";
1460
+ var PLEXUS_NODE_TYPE_RELATION = "plexus-relation";
1461
+ var PLEXUS_NODE_TYPE_OBJECT = "plexus-object";
1462
+ /**
1463
+ * Standard d3 radial link generator — `curveBumpRadial` (same as the cluster projector).
1464
+ * Relies on `dx-edge path { fill: none }` from graph.css.
1465
+ */
1466
+ var linkPath$1 = linkRadial().angle((d) => d.x).radius((d) => d.y);
1467
+ /**
1468
+ * Cartesian → d3-radial polar. d3 measures angle clockwise from "up" (the -y direction).
1469
+ * Inverse of `[cos(a - π/2) * r, sin(a - π/2) * r]`.
1470
+ */
1471
+ var cartesianToPolar = (x, y) => ({
1472
+ angle: Math.atan2(x, -y),
1473
+ radius: Math.hypot(x, y)
1474
+ });
1475
+ /**
1476
+ * Focus-centric radial layout. A single focused object sits at the centre; its immediate
1477
+ * neighbourhood fans out around it, grouped by the relation that connects each neighbour
1478
+ * to the focus:
1479
+ *
1480
+ * - **Focus** (depth 0) — the focused data node, at the origin.
1481
+ * - **Relation nodes** (depth 1) — synthetic group nodes (one per `relationOf` key) on an
1482
+ * inner ring.
1483
+ * - **Object nodes** (depth 2) — the neighbours reached through each relation, on the
1484
+ * outer ring.
1485
+ *
1486
+ * Built on the same `d3.cluster` machinery as `GraphClusterProjector`: the synthesized
1487
+ * `focus → relation → object` hierarchy is laid out radially and each hierarchy edge gets
1488
+ * a `linkRadial` `path` recomputed from current cartesian endpoints every tick, so curves
1489
+ * track moving nodes during a cross-focus (or cross-variant) tween.
1490
+ *
1491
+ * Focus itself is owned by the consumer (passed via `options.focus`); re-focusing is a
1492
+ * matter of recreating the projector with the new focus and the previous layout as `prev`,
1493
+ * which makes persistent nodes animate into their new positions.
1494
+ */
1495
+ var GraphPlexusProjector = class extends GraphRadialProjector {
1496
+ #dataNodes = [];
1497
+ #dataEdges = [];
1498
+ onUpdate(graph) {
1499
+ log("onUpdate", { graph: {
1500
+ nodes: graph?.nodes.length,
1501
+ edges: graph?.edges.length
1502
+ } }, {
1503
+ "~LogMeta": "~LogMeta",
1504
+ F: __dxlog_file$5,
1505
+ L: 104,
1506
+ S: this
1507
+ });
1508
+ this.mergeData(graph);
1509
+ this.#dataNodes = [...this.layout.graph.nodes];
1510
+ this.#dataEdges = [...this.layout.graph.edges];
1511
+ this.doPlexusLayout();
1512
+ this.emitUpdate("topology");
1513
+ this.animate();
1514
+ }
1515
+ /**
1516
+ * Recompute each hierarchy edge's `path` from current cartesian endpoints so curves track
1517
+ * moving nodes during the tween (identical strategy to the cluster projector).
1518
+ */
1519
+ onTickFrame(_t) {
1520
+ for (const edge of this.layout.graph.edges) {
1521
+ if (edge.type !== "hierarchy") continue;
1522
+ const { source, target } = edge;
1523
+ const s = cartesianToPolar(source.x ?? 0, source.y ?? 0);
1524
+ const t = cartesianToPolar(target.x ?? 0, target.y ?? 0);
1525
+ edge.path = linkPath$1({
1526
+ source: {
1527
+ x: s.angle,
1528
+ y: s.radius
1529
+ },
1530
+ target: {
1531
+ x: t.angle,
1532
+ y: t.radius
1533
+ }
1534
+ });
1535
+ }
1536
+ }
1537
+ doPlexusLayout() {
1538
+ if (!this.context.size) return;
1539
+ const dataNodes = this.#dataNodes;
1540
+ if (!dataNodes.length) return;
1541
+ const focusId = this.options.focus;
1542
+ const focusNode = focusId ? dataNodes.find((node) => node.id === focusId) : void 0;
1543
+ if (!focusNode) {
1544
+ const radial = layoutRadial(0, 0, Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 100), dataNodes.length);
1545
+ dataNodes.forEach((node, index) => updateNode(node, radial(index), this.options.leafRadius ?? 5));
1546
+ this.layout.graph.nodes = dataNodes;
1547
+ this.layout.graph.edges = [];
1548
+ this.animate();
1549
+ return;
1550
+ }
1551
+ const relationOf = this.options.relationOf ?? defaultRelationOf;
1552
+ const groups = /* @__PURE__ */ new Map();
1553
+ const placed = /* @__PURE__ */ new Set([focusId]);
1554
+ for (const edge of this.#dataEdges) {
1555
+ const relation = relationOf(edge, focusId);
1556
+ if (!relation) continue;
1557
+ const neighbour = edge.source.id === focusId ? edge.target : edge.source;
1558
+ if (placed.has(neighbour.id)) continue;
1559
+ placed.add(neighbour.id);
1560
+ let group = groups.get(relation.key);
1561
+ if (!group) {
1562
+ group = {
1563
+ id: `${RELATION_PREFIX}${relation.key}`,
1564
+ label: relation.label,
1565
+ leaves: []
1566
+ };
1567
+ groups.set(relation.key, group);
1568
+ }
1569
+ group.leaves.push(neighbour);
1570
+ }
1571
+ const items = [{
1572
+ id: focusId,
1573
+ node: focusNode
1574
+ }];
1575
+ for (const group of groups.values()) {
1576
+ items.push({
1577
+ id: group.id,
1578
+ parent: focusId,
1579
+ relationLabel: group.label
1580
+ });
1581
+ for (const leaf of group.leaves) items.push({
1582
+ id: leaf.id,
1583
+ parent: group.id,
1584
+ node: leaf
1585
+ });
1586
+ }
1587
+ const childrenByParent = /* @__PURE__ */ new Map();
1588
+ for (const item of items) if (item.parent) {
1589
+ const list = childrenByParent.get(item.parent) ?? [];
1590
+ list.push(item);
1591
+ childrenByParent.set(item.parent, list);
1592
+ }
1593
+ const root = hierarchy({
1594
+ id: focusId,
1595
+ node: focusNode
1596
+ }, (d) => childrenByParent.get(d.id) ?? []);
1597
+ const { width, height } = this.context.size;
1598
+ const margin = this.options.margin ?? 100;
1599
+ const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
1600
+ cluster().size([2 * Math.PI, ringRadius]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
1601
+ const leafR = this.options.leafRadius ?? 5;
1602
+ const relationR = this.options.relationRadius ?? leafR;
1603
+ const focusR = this.options.focusRadius ?? leafR * 2;
1604
+ const prevStubsById = /* @__PURE__ */ new Map();
1605
+ for (const node of this.layout.graph.nodes) if (node.type === "plexus-relation") prevStubsById.set(node.id, node);
1606
+ const relationStubs = /* @__PURE__ */ new Map();
1607
+ root.each((d) => {
1608
+ const angle = d.x;
1609
+ const radius = d.y;
1610
+ const x = Math.cos(angle - Math.PI / 2) * radius;
1611
+ const y = Math.sin(angle - Math.PI / 2) * radius;
1612
+ const id = d.data.id;
1613
+ if (id === focusId) {
1614
+ updateNode(focusNode, [x, y], focusR);
1615
+ focusNode.type = PLEXUS_NODE_TYPE_FOCUS;
1616
+ focusNode.hidden = false;
1617
+ } else if (d.data.node) {
1618
+ updateNode(d.data.node, [x, y], leafR);
1619
+ d.data.node.type = PLEXUS_NODE_TYPE_OBJECT;
1620
+ d.data.node.hidden = false;
1621
+ } else {
1622
+ const stub = prevStubsById.get(id) ?? {
1623
+ id,
1624
+ x: 0,
1625
+ y: 0
1626
+ };
1627
+ updateNode(stub, [x, y], relationR);
1628
+ stub.type = PLEXUS_NODE_TYPE_RELATION;
1629
+ stub.label = d.data.relationLabel;
1630
+ relationStubs.set(id, stub);
1631
+ }
1632
+ });
1633
+ const nextNodes = [];
1634
+ for (const stub of relationStubs.values()) nextNodes.push(stub);
1635
+ for (const group of groups.values()) for (const leaf of group.leaves) nextNodes.push(leaf);
1636
+ nextNodes.push(focusNode);
1637
+ this.layout.graph.nodes = nextNodes;
1638
+ const edges = [];
1639
+ root.links().forEach((link) => {
1640
+ const sid = link.source.data.id;
1641
+ const tid = link.target.data.id;
1642
+ const sourceNode = sid === focusId ? focusNode : link.source.data.node ?? relationStubs.get(sid);
1643
+ const targetNode = link.target.data.node ?? relationStubs.get(tid);
1644
+ if (!sourceNode || !targetNode) return;
1645
+ edges.push({
1646
+ id: `${HIER_EDGE_PREFIX$1}${sid}->${tid}`,
1647
+ type: "hierarchy",
1648
+ source: sourceNode,
1649
+ target: targetNode,
1650
+ data: void 0
1651
+ });
1652
+ });
1653
+ this.layout.graph.edges = edges;
1654
+ this.onTickFrame(0);
1655
+ }
1656
+ };
1657
+ /** Fallback grouping: every edge incident to the focus becomes a relation keyed by edge type + direction. */
1658
+ var defaultRelationOf = (edge, focusId) => {
1659
+ const outgoing = edge.source.id === focusId;
1660
+ const incoming = edge.target.id === focusId;
1661
+ if (!outgoing && !incoming) return;
1662
+ const type = edge.type ?? "edge";
1663
+ const arrow = outgoing ? "→" : "←";
1664
+ return {
1665
+ key: `${type}:${outgoing ? "out" : "in"}`,
1666
+ label: `${type} ${arrow}`
1667
+ };
1668
+ };
1669
+ //#endregion
1670
+ //#region src/graph/projector/graph-relational-projector.ts
1671
+ var __dxlog_file$4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
1672
+ var GraphRelationalProjector = class extends GraphRadialProjector {
1673
+ onUpdate(graph) {
1674
+ log("onUpdate", {
1675
+ graph: {
1676
+ nodes: graph?.nodes.length,
1677
+ edges: graph?.edges.length
1678
+ },
1679
+ selection: this.selection?.getSelectedIds()
1680
+ }, {
1681
+ "~LogMeta": "~LogMeta",
1682
+ F: __dxlog_file$4,
1683
+ L: 23,
1684
+ S: this
1685
+ });
1686
+ this.mergeData(graph);
1687
+ this.emitUpdate("topology");
1688
+ const selected = this.selection?.getSelectedIds()[0];
1689
+ if (selected) {
1690
+ const node = this.layout.graph.nodes.find((node) => node.id === selected);
1691
+ if (node) {
1692
+ this.doRelationalLayout(node);
1693
+ return;
1694
+ }
1695
+ }
1696
+ this.doRadialLayout();
1697
+ }
1698
+ doRelationalLayout(selected) {
1699
+ if (!this.context.size) return;
1700
+ const r2 = this.options.radius ?? Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 80);
1701
+ const r1 = r2 * .5;
1702
+ this.layout.graph.nodes.forEach((node) => node.type = void 0);
1703
+ this.layout.graph.edges.forEach((edge) => {
1704
+ edge.order = 0;
1705
+ edge.type = void 0;
1706
+ });
1707
+ const children = this.layout.graph.edges.filter((edge) => edge.source.id === selected.id).map((edge) => {
1708
+ edge.order = 1;
1709
+ edge.type = "1";
1710
+ edge.target.type = "1";
1711
+ return edge.target;
1712
+ });
1713
+ const parents = this.layout.graph.edges.filter((edge) => edge.target.id === selected.id).map((edge) => {
1714
+ edge.order = 2;
1715
+ edge.type = "2";
1716
+ edge.source.type = "2";
1717
+ return edge.source;
1718
+ });
1719
+ updateNode(selected, [0, 0], 30);
1720
+ {
1721
+ const vertical = layoutHorizontal(0, r1, r1 * 2, children.length);
1722
+ children.forEach((node, i) => {
1723
+ const [tx, ty] = vertical(i);
1724
+ updateNode(node, [tx, ty], 20);
1725
+ });
1726
+ }
1727
+ {
1728
+ const vertical = layoutHorizontal(0, -r1, r1, parents.length);
1729
+ parents.forEach((node, i) => {
1730
+ const [tx, ty] = vertical(i);
1731
+ updateNode(node, [tx, ty], 20);
1732
+ });
1733
+ }
1734
+ {
1735
+ const radial = layoutRadial(0, 0, r2, this.layout.graph.nodes.length - 1 - children.length - parents.length);
1736
+ this.layout.graph.nodes.filter((node) => node.id !== selected.id && !children.includes(node) && !parents.includes(node)).forEach((node, i) => {
1737
+ const [tx, ty] = radial(i);
1738
+ updateNode(node, [tx, ty]);
1739
+ });
1740
+ }
1741
+ this.animate();
1742
+ }
1743
+ };
1744
+ //#endregion
1745
+ //#region src/graph/projector/graph-swarm-projector.ts
1746
+ var __dxlog_file$3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-swarm-projector.ts";
1747
+ var SWARMMATE_RADIUS = 60;
1748
+ var SEPARATION_DISTANCE = 30;
1749
+ var DEFAULTS = {
1750
+ spawnRadius: 200,
1751
+ maxVelocity: 1.2,
1752
+ alignment: 3,
1753
+ cohesion: 3,
1754
+ separation: 3,
1755
+ cursorRepel: 120,
1756
+ avoidance: 3,
1757
+ trailLength: 30
1758
+ };
1759
+ /**
1760
+ * Boids projector. One simulation timer (d3 `timer`) drives the tick; nodes are
1761
+ * the boids, with `vx/vy/ax/ay` carried alongside `x/y`. Edges are kept in the
1762
+ * layout so the renderer still draws them between connected boids, but they do
1763
+ * NOT exert a link force — boid motion is governed purely by alignment, cohesion
1764
+ * and separation, with viewBox-wrap at the SVG bounds.
1765
+ */
1766
+ var GraphSwarmProjector = class extends GraphProjector {
1767
+ #timer;
1768
+ /** Cursor in SVG model coordinates, or null when the pointer is outside the surface. */
1769
+ #cursor = null;
1770
+ findNode() {}
1771
+ /**
1772
+ * Tell the projector where the pointer is, in SVG model coordinates (the same space
1773
+ * `node.x/y` live in — center origin, post-zoom). Pass `null` (or omit args) on
1774
+ * pointer-leave to disable cursor avoidance.
1775
+ */
1776
+ setCursor(x, y) {
1777
+ if (x == null || y == null) this.#cursor = null;
1778
+ else this.#cursor = {
1779
+ x,
1780
+ y
1781
+ };
1782
+ }
1783
+ onUpdate(graph) {
1784
+ log("onUpdate", { graph: {
1785
+ nodes: graph?.nodes.length,
1786
+ edges: graph?.edges.length
1787
+ } }, {
1788
+ "~LogMeta": "~LogMeta",
1789
+ F: __dxlog_file$3,
1790
+ L: 115,
1791
+ S: this
1792
+ });
1793
+ this.mergeData(graph);
1794
+ this.initializeNodes();
1795
+ this.emitUpdate("topology");
1796
+ }
1797
+ async onStart() {
1798
+ this.startTimer();
1799
+ }
1800
+ async onStop() {
1801
+ this.stopTimer();
1802
+ }
1803
+ onRefresh() {
1804
+ if (!this.#timer) this.startTimer();
1805
+ }
1806
+ #opt(key) {
1807
+ return this.options[key] ?? DEFAULTS[key];
1808
+ }
1809
+ initializeNodes() {
1810
+ const spawnRadius = this.#opt("spawnRadius");
1811
+ const maxVelocity = this.#opt("maxVelocity");
1812
+ for (const node of this.layout.graph.nodes) {
1813
+ if (!node.initialized) {
1814
+ const theta = Math.random() * 2 * Math.PI;
1815
+ const r = Math.random() * spawnRadius;
1816
+ node.x = Math.cos(theta) * r;
1817
+ node.y = Math.sin(theta) * r;
1818
+ const phi = Math.random() * 2 * Math.PI;
1819
+ const speed = (.3 + Math.random() * .7) * maxVelocity;
1820
+ node.vx = Math.cos(phi) * speed;
1821
+ node.vy = Math.sin(phi) * speed;
1822
+ node.ax = 0;
1823
+ node.ay = 0;
1824
+ node.initialized = true;
1825
+ } else {
1826
+ node.vx ??= 0;
1827
+ node.vy ??= 0;
1828
+ node.ax ??= 0;
1829
+ node.ay ??= 0;
1830
+ }
1831
+ node.r ??= 6;
1832
+ node.history = [{
1833
+ x: node.x ?? 0,
1834
+ y: node.y ?? 0
1835
+ }];
1836
+ }
1837
+ }
1838
+ startTimer() {
1839
+ this.stopTimer();
1840
+ this.#timer = timer(() => this.tick());
1841
+ }
1842
+ stopTimer() {
1843
+ this.#timer?.stop();
1844
+ this.#timer = void 0;
1845
+ }
1846
+ /**
1847
+ * One simulation step. Modeled on `tick` in Swarm.tsx, but operating in the
1848
+ * SVG centered-origin coordinate space and writing to `node.x/y` directly so
1849
+ * the existing `GraphRenderer.applyPositions` reads them unchanged.
1850
+ */
1851
+ tick() {
1852
+ const size = this.context.size;
1853
+ if (!size) return;
1854
+ const { width, height } = size;
1855
+ const halfW = width / 2;
1856
+ const halfH = height / 2;
1857
+ const nodes = this.layout.graph.nodes;
1858
+ const maxVelocity = this.#opt("maxVelocity");
1859
+ const alignmentW = this.#opt("alignment") / 100;
1860
+ const cohesionW = this.#opt("cohesion") / 100;
1861
+ const separationW = this.#opt("separation") / 100;
1862
+ const avoidanceW = this.#opt("avoidance") / 10;
1863
+ const cursorRepel = this.#opt("cursorRepel");
1864
+ const cursor = cursorRepel > 0 ? this.#cursor : null;
1865
+ for (const b1 of nodes) {
1866
+ let ax = 0;
1867
+ let ay = 0;
1868
+ let alignX = 0;
1869
+ let alignY = 0;
1870
+ let alignActive = false;
1871
+ let cohX = 0;
1872
+ let cohY = 0;
1873
+ let cohActive = false;
1874
+ let sepX = 0;
1875
+ let sepY = 0;
1876
+ let sepActive = false;
1877
+ let avoidX = 0;
1878
+ let avoidY = 0;
1879
+ let avoidActive = false;
1880
+ if (cursor) {
1881
+ const dx = cursor.x - (b1.x ?? 0);
1882
+ const dy = cursor.y - (b1.y ?? 0);
1883
+ const distSq = dx * dx + dy * dy;
1884
+ if (distSq > 0 && distSq < cursorRepel * cursorRepel) {
1885
+ const dist = Math.sqrt(distSq);
1886
+ avoidX = -dx / dist * (1 / dist);
1887
+ avoidY = -dy / dist * (1 / dist);
1888
+ avoidActive = true;
1889
+ }
1890
+ }
1891
+ if (!avoidActive) for (const b2 of nodes) {
1892
+ if (b1 === b2) continue;
1893
+ const dx = (b2.x ?? 0) - (b1.x ?? 0);
1894
+ const dy = (b2.y ?? 0) - (b1.y ?? 0);
1895
+ const distSq = dx * dx + dy * dy;
1896
+ if (distSq === 0) continue;
1897
+ const dist = Math.sqrt(distSq);
1898
+ if (dist < SEPARATION_DISTANCE) {
1899
+ sepX += -dx / dist * (1 / dist);
1900
+ sepY += -dy / dist * (1 / dist);
1901
+ sepActive = true;
1902
+ }
1903
+ if (dist < SWARMMATE_RADIUS) {
1904
+ cohX += dx;
1905
+ cohY += dy;
1906
+ cohActive = true;
1907
+ alignX += b2.vx ?? 0;
1908
+ alignY += b2.vy ?? 0;
1909
+ alignActive = true;
1910
+ }
1911
+ }
1912
+ const applyForce = (fx, fy, weight, active) => {
1913
+ if (!active || weight === 0) return;
1914
+ const len = Math.sqrt(fx * fx + fy * fy);
1915
+ if (len === 0) return;
1916
+ const sx = fx * maxVelocity / len - (b1.vx ?? 0);
1917
+ const sy = fy * maxVelocity / len - (b1.vy ?? 0);
1918
+ const slen = Math.sqrt(sx * sx + sy * sy);
1919
+ if (slen > weight) {
1920
+ ax += sx * weight / slen;
1921
+ ay += sy * weight / slen;
1922
+ } else {
1923
+ ax += sx;
1924
+ ay += sy;
1925
+ }
1926
+ };
1927
+ applyForce(alignX, alignY, alignmentW, alignActive);
1928
+ applyForce(cohX, cohY, cohesionW, cohActive);
1929
+ applyForce(sepX, sepY, separationW, sepActive);
1930
+ applyForce(avoidX, avoidY, avoidanceW, avoidActive);
1931
+ b1.ax = ax;
1932
+ b1.ay = ay;
1933
+ }
1934
+ const trailLength = Math.max(0, Math.round(this.#opt("trailLength")));
1935
+ for (const b of nodes) {
1936
+ let vx = (b.vx ?? 0) + (b.ax ?? 0);
1937
+ let vy = (b.vy ?? 0) + (b.ay ?? 0);
1938
+ const vlen = Math.sqrt(vx * vx + vy * vy);
1939
+ if (vlen > maxVelocity) {
1940
+ vx = vx * maxVelocity / vlen;
1941
+ vy = vy * maxVelocity / vlen;
1942
+ }
1943
+ b.vx = vx;
1944
+ b.vy = vy;
1945
+ if (trailLength > 0) {
1946
+ const history = b.history ?? (b.history = []);
1947
+ history.push({
1948
+ x: b.x ?? 0,
1949
+ y: b.y ?? 0
1950
+ });
1951
+ if (history.length > trailLength) history.splice(0, history.length - trailLength);
1952
+ }
1953
+ let x = (b.x ?? 0) + vx;
1954
+ let y = (b.y ?? 0) + vy;
1955
+ let wrapped = false;
1956
+ if (x > halfW) {
1957
+ x -= width;
1958
+ wrapped = true;
1959
+ } else if (x < -halfW) {
1960
+ x += width;
1961
+ wrapped = true;
1962
+ }
1963
+ if (y > halfH) {
1964
+ y -= height;
1965
+ wrapped = true;
1966
+ } else if (y < -halfH) {
1967
+ y += height;
1968
+ wrapped = true;
1969
+ }
1970
+ if (wrapped && b.history) b.history.length = 0;
1971
+ b.x = x;
1972
+ b.y = y;
1973
+ }
1974
+ for (const edge of this.layout.graph.edges) edge.path = `M ${edge.source.x ?? 0} ${edge.source.y ?? 0} Q 0 0 ${edge.target.x ?? 0} ${edge.target.y ?? 0}`;
1975
+ this.emitUpdate("positions");
1976
+ }
1977
+ };
1978
+ //#endregion
1979
+ //#region src/graph/projector/graph-tree-projector.ts
1980
+ var __dxlog_file$2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-tree-projector.ts";
1981
+ /** Node type tags so consumer renderers can distinguish the root, outgoing, and inbound nodes. */
1982
+ var TREE_NODE_TYPE_ROOT = "tree-root";
1983
+ /** Outgoing descendant (root is an ancestor source), on the right. */
1984
+ var TREE_NODE_TYPE_NODE = "tree-node";
1985
+ /** Inbound source (an edge points at the root), on the left. */
1986
+ var TREE_NODE_TYPE_INBOUND = "tree-inbound";
1987
+ var HIER_EDGE_PREFIX = "__tree_hier__:";
1988
+ /**
1989
+ * Horizontal link generator: x is the horizontal (depth) axis, y the vertical (breadth) axis.
1990
+ * Our cartesian coordinates already map x→horizontal / y→vertical, so feed them straight through.
1991
+ */
1992
+ var linkPath = linkHorizontal().x((d) => d.x).y((d) => d.y);
1993
+ /**
1994
+ * Bidirectional Reingold–Tilford "tidy tree" layout (see
1995
+ * https://observablehq.com/@observablehq/plot-tree-tidy). The focus node is the root, drawn at the
1996
+ * centre. Outgoing edges (the root, then each descendant, is the edge source) form a spanning tree
1997
+ * fanning out to the **right**, one column per hop. Inbound edges (an edge whose target is the root)
1998
+ * place their source on the **left** as a terminal leaf — the graph is not explored beyond those
1999
+ * sources. Cross edges and nodes the directed view does not reach are dropped. Hierarchy links get a
2000
+ * `linkHorizontal` `path` recomputed from current endpoints every tick so curves track moving nodes.
2001
+ */
2002
+ var GraphTreeProjector = class extends GraphRadialProjector {
2003
+ #dataNodes = [];
2004
+ #dataEdges = [];
2005
+ #resizeCleanup;
2006
+ async onStart() {
2007
+ this.#resizeCleanup = this.context.resized.on(() => {
2008
+ if (this.#dataNodes.length) {
2009
+ this.doTreeLayout();
2010
+ this.emitUpdate("topology");
2011
+ this.animate();
2012
+ }
2013
+ });
2014
+ }
2015
+ async onStop() {
2016
+ this.#resizeCleanup?.();
2017
+ this.#resizeCleanup = void 0;
2018
+ await super.onStop();
2019
+ }
2020
+ onUpdate(graph) {
2021
+ log("onUpdate", { graph: {
2022
+ nodes: graph?.nodes.length,
2023
+ edges: graph?.edges.length
2024
+ } }, {
2025
+ "~LogMeta": "~LogMeta",
2026
+ F: __dxlog_file$2,
2027
+ L: 83,
2028
+ S: this
2029
+ });
2030
+ this.mergeData(graph);
2031
+ this.#dataNodes = [...this.layout.graph.nodes];
2032
+ this.#dataEdges = [...this.layout.graph.edges];
2033
+ this.doTreeLayout();
2034
+ this.emitUpdate("topology");
2035
+ this.animate();
2036
+ }
2037
+ onTickFrame(_t) {
2038
+ for (const edge of this.layout.graph.edges) {
2039
+ if (edge.type !== "hierarchy") continue;
2040
+ const { source, target } = edge;
2041
+ edge.path = linkPath({
2042
+ source: {
2043
+ x: source.x ?? 0,
2044
+ y: source.y ?? 0
2045
+ },
2046
+ target: {
2047
+ x: target.x ?? 0,
2048
+ y: target.y ?? 0
2049
+ }
2050
+ }) ?? void 0;
2051
+ }
2052
+ }
2053
+ doTreeLayout() {
2054
+ if (!this.context.size) return;
2055
+ const dataNodes = this.#dataNodes;
2056
+ if (!dataNodes.length) return;
2057
+ const focusId = this.options.focus;
2058
+ const focusNode = focusId ? dataNodes.find((node) => node.id === focusId) : void 0;
2059
+ if (!focusNode) {
2060
+ this.doRadialLayout();
2061
+ return;
2062
+ }
2063
+ const nodesById = new Map(dataNodes.map((node) => [node.id, node]));
2064
+ const makeDatum = (id) => ({
2065
+ id,
2066
+ node: nodesById.get(id)
2067
+ });
2068
+ const outgoing = /* @__PURE__ */ new Map();
2069
+ for (const edge of this.#dataEdges) {
2070
+ const list = outgoing.get(edge.source.id) ?? [];
2071
+ list.push(edge.target.id);
2072
+ outgoing.set(edge.source.id, list);
2073
+ }
2074
+ const rightChildren = /* @__PURE__ */ new Map();
2075
+ const visited = /* @__PURE__ */ new Set([focusId]);
2076
+ let frontier = [focusId];
2077
+ while (frontier.length) {
2078
+ const next = [];
2079
+ for (const id of frontier) for (const target of outgoing.get(id) ?? []) if (!visited.has(target)) {
2080
+ visited.add(target);
2081
+ const list = rightChildren.get(id) ?? [];
2082
+ list.push(target);
2083
+ rightChildren.set(id, list);
2084
+ next.push(target);
2085
+ }
2086
+ frontier = next;
2087
+ }
2088
+ const leftSources = [];
2089
+ for (const edge of this.#dataEdges) {
2090
+ const source = edge.source.id;
2091
+ if (edge.target.id === focusId && source !== focusId && !visited.has(source)) {
2092
+ visited.add(source);
2093
+ leftSources.push(source);
2094
+ }
2095
+ }
2096
+ const rightRoot = hierarchy(makeDatum(focusId), (d) => (rightChildren.get(d.id) ?? []).map(makeDatum));
2097
+ const leftRoot = hierarchy(makeDatum(focusId), (d) => d.id === focusId ? leftSources.map(makeDatum) : []);
2098
+ const { width } = this.context.size;
2099
+ const margin = this.options.margin ?? 80;
2100
+ const rowGap = this.options.rowGap ?? 28;
2101
+ const maxColumnGap = this.options.maxColumnGap ?? 300;
2102
+ const sideDepth = Math.max(1, rightRoot.height, leftRoot.height);
2103
+ const columnGap = Math.min(maxColumnGap, Math.max(0, (width / 2 - margin) / sideDepth));
2104
+ const layoutTree = tree().nodeSize([rowGap, columnGap]);
2105
+ const rightPoint = layoutTree(rightRoot);
2106
+ const leftPoint = layoutTree(leftRoot);
2107
+ const nodeR = this.options.nodeRadius ?? 6;
2108
+ const rootR = this.options.rootRadius ?? nodeR * 2;
2109
+ const placed = [];
2110
+ updateNode(focusNode, [0, 0], rootR);
2111
+ focusNode.type = TREE_NODE_TYPE_ROOT;
2112
+ placed.push(focusNode);
2113
+ const rightBreadth = rightPoint.x;
2114
+ rightPoint.each((d) => {
2115
+ if (d.data.id === focusId || !d.data.node) return;
2116
+ updateNode(d.data.node, [d.y, d.x - rightBreadth], nodeR);
2117
+ d.data.node.type = TREE_NODE_TYPE_NODE;
2118
+ placed.push(d.data.node);
2119
+ });
2120
+ const leftBreadth = leftPoint.x;
2121
+ leftPoint.each((d) => {
2122
+ if (d.data.id === focusId || !d.data.node) return;
2123
+ updateNode(d.data.node, [-d.y, d.x - leftBreadth], nodeR);
2124
+ d.data.node.type = TREE_NODE_TYPE_INBOUND;
2125
+ placed.push(d.data.node);
2126
+ });
2127
+ this.layout.graph.nodes = placed;
2128
+ const edges = [];
2129
+ const addLinks = (root, reverse = false) => {
2130
+ root.links().forEach((link) => {
2131
+ const parent = link.source.data;
2132
+ const child = link.target.data;
2133
+ const [from, to] = reverse ? [child, parent] : [parent, child];
2134
+ if (!from.node || !to.node) return;
2135
+ edges.push({
2136
+ id: `${HIER_EDGE_PREFIX}${from.id}->${to.id}`,
2137
+ type: "hierarchy",
2138
+ source: from.node,
2139
+ target: to.node,
2140
+ data: void 0
2141
+ });
2142
+ });
2143
+ };
2144
+ addLinks(rightPoint);
2145
+ addLinks(leftPoint, true);
2146
+ this.layout.graph.edges = edges;
2147
+ this.onTickFrame(0);
2148
+ }
2149
+ };
2150
+ //#endregion
2151
+ //#region src/graph/renderer/bullets.ts
2152
+ /**
2153
+ * Generate animated bullets that follow selected paths.
2154
+ * @param group
2155
+ * @param nodeId
2156
+ * @param options
2157
+ */
2158
+ var createBullets = (group, nodeId, options = {}) => {
2159
+ return (selection) => {
2160
+ const { max = 32, radius = 3, delay = 50, minDuration = 100, maxDuration = 500 } = options;
2161
+ selection.each(function(d, i, edges) {
2162
+ const { source, target } = d;
2163
+ if (source.id === nodeId) {
2164
+ const path = select(edges[i]);
2165
+ const p = path.node().getPointAtLength(0);
2166
+ select(group).append("circle").attr("class", "dx-bullet").attr("cx", p.x).attr("cy", p.y).attr("r", radius).transition().delay(delay).duration(minDuration + Math.random() * maxDuration).ease(easeLinear).tween("pathTween", function() {
2167
+ const r = interpolate(0, path.node().getTotalLength());
2168
+ return (t) => {
2169
+ const point = path.node().getPointAtLength(r(t));
2170
+ select(this).attr("cx", point.x).attr("cy", point.y);
2171
+ };
2172
+ }).on("end", function() {
2173
+ select(this).remove();
2174
+ if (select(group).selectAll("circle.dx-bullet").size() < max) selection.call(createBullets(group, target.id));
2175
+ });
2176
+ }
2177
+ });
2178
+ };
2179
+ };
2180
+ //#endregion
2181
+ //#region src/graph/renderer/renderer.ts
2182
+ /**
2183
+ * Base class for renderer that draw layouts.
2184
+ */
2185
+ var Renderer = class {
2186
+ _context;
2187
+ _root;
2188
+ _options;
2189
+ constructor(_context, _root, options) {
2190
+ this._context = _context;
2191
+ this._root = _root;
2192
+ this._options = Object.assign({ idAccessor: defaultIdAccessor }, options);
2193
+ }
2194
+ get context() {
2195
+ return this._context;
2196
+ }
2197
+ /**
2198
+ * Returns the SVG group root if mounted.
2199
+ * The ref may be null between mount/unmount cycles or before the SVG container has sized.
2200
+ * Callers should treat null as "skip this render" rather than as an error.
2201
+ */
2202
+ get root() {
2203
+ return this._root.current;
2204
+ }
2205
+ get options() {
2206
+ return this._options;
2207
+ }
2208
+ /**
2209
+ * Fast path invoked when only positions changed.
2210
+ * Default falls back to a full `render`; subclasses can override to skip
2211
+ * enter/exit joins and attribute callbacks for per-tick updates.
2212
+ */
2213
+ applyPositions(layout) {
2214
+ this.render(layout);
2215
+ }
2216
+ };
2217
+ //#endregion
2218
+ //#region src/graph/renderer/graph-renderer.ts
2219
+ var __dxlog_file$1 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
2220
+ var createLine$2 = line();
2221
+ /** Duration for edge opacity transitions on enter / exit (ms). Matches node enter/exit timing. */
2222
+ var EDGE_FADE_MS = 300;
2223
+ /** Duration for node hide/show opacity transitions (ms). Matches the projector's tween
2224
+ * duration so a cluster collapse/expand fades opacity over the same window the position
2225
+ * is tweening toward / away from the parent group. */
2226
+ var NODE_HIDE_MS = 500;
2227
+ /**
2228
+ * Renders the Graph layout.
2229
+ */
2230
+ var GraphRenderer = class extends Renderer {
2231
+ #firstRender = true;
2232
+ render(layout) {
2233
+ if (!this.root) return;
2234
+ if (this.#firstRender) {
2235
+ this.#firstRender = false;
2236
+ this.root.replaceChildren();
2237
+ }
2238
+ log("render", layout, {
2239
+ "~LogMeta": "~LogMeta",
2240
+ F: __dxlog_file$1,
2241
+ L: 118,
2242
+ S: this
2243
+ });
2244
+ const root = select(this.root);
2245
+ if (layout.guides) root.selectAll("g.dx-guides").data([{ id: "guides" }]).join("g").classed("dx-guides", true).selectAll("circle").data(layout.guides ?? []).join((enter) => enter.append("circle").attr("r", 0), (update) => update, (exit) => exit.transition().duration(500).attr("r", 0).remove()).attr("cx", (d) => d.cx).attr("cy", (d) => d.cy).attr("r", (d) => d.r);
2246
+ const scale = 100;
2247
+ const offsetDistance = 24 * scale;
2248
+ if (this._options.subgraphs) {
2249
+ const components = this._options.subgraphs ? findConnectedComponents({
2250
+ nodes: layout.graph?.nodes ?? [],
2251
+ edges: (layout.graph?.edges ?? []).map(({ source, target }) => ({
2252
+ source: source.id,
2253
+ target: target.id
2254
+ }))
2255
+ }).filter((component) => component.length > 2).map((component, i) => ({
2256
+ id: `subgraph-${i}`,
2257
+ component
2258
+ })) : [];
2259
+ root.selectAll("g.dx-subgraphs").data([{ id: "subgraphs" }]).join("g").classed("dx-subgraphs", true).selectAll("path").data(components).join((enter) => enter.append("path").classed("dx-subgraph", true), (update) => {
2260
+ return update.attr("d", ({ component }) => {
2261
+ const hullPoints = polygonHull(layout.graph?.nodes.filter((node) => component.includes(node.id)).map((node) => [node.x, node.y]) ?? []);
2262
+ const co = new Clipper.ClipperOffset();
2263
+ const solution = [];
2264
+ const clipperPath = hullPoints.map(([x, y]) => ({
2265
+ X: x * scale,
2266
+ Y: y * scale
2267
+ }));
2268
+ co.AddPath(clipperPath, Clipper.JoinType.jtRound, Clipper.EndType.etClosedPolygon);
2269
+ co.Execute(solution, offsetDistance);
2270
+ if (solution.length > 0) {
2271
+ const offset = solution[0].map(({ X, Y }) => [X / scale, Y / scale]);
2272
+ return createLine$2([...offset, offset[0]]);
2273
+ }
2274
+ });
2275
+ });
2276
+ }
2277
+ const edgeGroup = root.selectAll("g.dx-edges").data([{ id: "edges" }], (d) => d.id).join("g").classed("dx-edges", true).style("opacity", this.options.edgeOpacity != null ? String(this.options.edgeOpacity) : null);
2278
+ const nodeGroup = root.selectAll("g.dx-nodes").data([{ id: "nodes" }], (d) => d.id).join("g").classed("dx-nodes", true);
2279
+ nodeGroup.selectAll("g.dx-node").data(layout.graph?.nodes ?? [], (d) => d.id).join((enter) => enter.append("g").attr("data-id", (d) => d.id).attr("opacity", (d) => d.hidden ? 0 : 1).classed("dx-node", true).call(createNode, this.options), (update) => update, (exit) => {
2280
+ return exit.transition().ease(easeCubicOut).duration(300).attr("opacity", 0).on("end", function(d) {
2281
+ select(this).remove();
2282
+ });
2283
+ }).call(updateNode$1, this.options).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
2284
+ edgeGroup.selectAll("g.dx-edge").data(layout.graph?.edges ?? [], (d) => d.id).join((enter) => enter.append("g").attr("data-id", (d) => d.id).classed("dx-edge", true).call(createEdge, this.options), (update) => update, (exit) => exit.transition().ease(easeCubicOut).duration(EDGE_FADE_MS).attr("opacity", 0).on("end", function() {
2285
+ select(this).remove();
2286
+ })).call(updateEdge, this.options, nodeGroup).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
2287
+ }
2288
+ /**
2289
+ * Fast positions-only update. Skips enter/exit, attribute callbacks, label sizing,
2290
+ * and the subgraph hull pass; just writes `transform` per node and `d` per edge.
2291
+ * Called per simulation tick / animation frame.
2292
+ */
2293
+ applyPositions(layout) {
2294
+ if (!this.root) return;
2295
+ const root = select(this.root);
2296
+ const applyNode = this.options.applyNode;
2297
+ root.select("g.dx-nodes").selectAll("g.dx-node").attr("transform", (d) => d.x != null && d.y != null ? `translate(${d.x},${d.y})` : null).each(applyNode ? function(d) {
2298
+ applyNode(this, d);
2299
+ } : () => {});
2300
+ root.select("g.dx-edges").selectAll("g.dx-edge").selectAll("path").attr("d", function() {
2301
+ const edge = select(this.parentElement).datum();
2302
+ if (edge.path) return edge.path;
2303
+ const { source, target } = edge;
2304
+ if (!source.initialized || !target.initialized) return null;
2305
+ return createLine$2(getCircumferencePoints([source.x, source.y], [target.x, target.y], source.r, target.r));
2306
+ });
2307
+ }
2308
+ /**
2309
+ * Trigger path bullets.
2310
+ * @param node
2311
+ */
2312
+ fireBullet(node) {
2313
+ if (!this.root) return;
2314
+ select(this.root).selectAll("g.dx-edges").selectAll("path").call(createBullets(this.root, node.id));
2315
+ }
2316
+ };
2317
+ /**
2318
+ * Create node elements.
2319
+ * @param group
2320
+ * @param options
2321
+ */
2322
+ var SHAPE_CLASS = "dx-shape";
2323
+ var renderCustomShape = (group, options) => {
2324
+ group.each(function(d) {
2325
+ const g = select(this);
2326
+ g.selectAll(`.${SHAPE_CLASS}`).remove();
2327
+ const shapeGroup = g.append("g").classed(SHAPE_CLASS, true);
2328
+ options.renderNode(shapeGroup, d);
2329
+ });
2330
+ };
2331
+ var createNode = (group, options) => {
2332
+ const useCustom = !!options.renderNode;
2333
+ if (useCustom) renderCustomShape(group, options);
2334
+ const hitTarget = useCustom ? group : group.append("circle");
2335
+ if (options.drag) hitTarget.call(options.drag);
2336
+ if (options.onNodeClick) group.on("click", (event, d) => {
2337
+ options.onNodeClick(d, event);
2338
+ });
2339
+ if (options.labels && !options.onNodePointerEnter) {
2340
+ const g = group.append("g").classed("dx-label", true);
2341
+ g.append("line");
2342
+ g.append("rect");
2343
+ g.append("text").style("dominant-baseline", "middle");
2344
+ }
2345
+ if (options.onNodePointerEnter || options.onNodePointerLeave || options.highlightOnHover) {
2346
+ hitTarget.on("pointerenter", function(event) {
2347
+ const node = select(useCustom ? this : this.parentElement).datum();
2348
+ options.onNodePointerEnter?.(node, event);
2349
+ if (options.highlightOnHover) applyHoverHighlight(this.closest("g.dx-graph"), node.id);
2350
+ });
2351
+ hitTarget.on("pointerleave", function(event) {
2352
+ const node = select(useCustom ? this : this.parentElement).datum();
2353
+ options.onNodePointerLeave?.(node, event);
2354
+ if (options.highlightOnHover) applyHoverHighlight(this.closest("g.dx-graph"), null);
2355
+ });
2356
+ group.attr("data-hover", "handled");
2357
+ } else if (options.highlight !== false && !useCustom) {
2358
+ hitTarget.on("pointerenter", function() {
2359
+ select(this.closest("g.dx-node")).raise();
2360
+ if (options.labels) select(this.parentElement).classed("dx-node-active", true).classed("dx-highlight", true);
2361
+ });
2362
+ group.on("pointerleave", function() {
2363
+ if (options.labels) {
2364
+ select(this).classed("dx-node-active", false);
2365
+ setTimeout(() => {
2366
+ if (!select(this).classed("dx-node-active")) select(this).classed("dx-highlight", false);
2367
+ }, 300);
2368
+ }
2369
+ });
2370
+ }
2371
+ };
2372
+ /**
2373
+ * Update node elements.
2374
+ * @param group
2375
+ * @param options
2376
+ */
2377
+ var updateNode$1 = (group, options) => {
2378
+ group.attr("transform", (d) => {
2379
+ return d.x != null && d.y != null ? `translate(${d.x},${d.y})` : void 0;
2380
+ });
2381
+ group.classed("dx-hidden", (d) => d.hidden ?? false);
2382
+ group.transition("hide").ease(easeCubicOut).duration(NODE_HIDE_MS).attr("opacity", (d) => d.hidden ? 0 : 1);
2383
+ if (options.renderNode) renderCustomShape(group, options);
2384
+ if (options.attributes?.node) try {
2385
+ group.each((d, i, nodes) => {
2386
+ const node = select(nodes[i]);
2387
+ const { classes, data } = options.attributes?.node?.(d) ?? {};
2388
+ if (classes) applyClasses(node, classes);
2389
+ if (data) Object.entries(data).forEach(([key, value]) => {
2390
+ node.attr(`data-${key}`, value);
2391
+ });
2392
+ });
2393
+ } catch (error) {
2394
+ log.error("updateNode", { error: error?.message }, {
2395
+ "~LogMeta": "~LogMeta",
2396
+ F: __dxlog_file$1,
2397
+ L: 481,
2398
+ S: void 0
2399
+ });
2400
+ }
2401
+ const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
2402
+ if (!options.renderNode) groupOrTransition.select("circle").attr("r", (d) => d.r ?? 16);
2403
+ if (options.labels) {
2404
+ const py = 2;
2405
+ const offset = 16;
2406
+ const dx = (d, offset = 0) => (offset + (d.r ?? 0)) * (d.x > 0 ? 1 : -1);
2407
+ groupOrTransition.select("text").text((d) => options.labels.text(d)).style("text-anchor", (d) => d.x > 0 ? "start" : "end").attr("dx", (d) => dx(d, offset)).attr("dy", 1).text((d) => options.labels.text(d)).each(function(d) {
2408
+ let bbox = d.bbox;
2409
+ if (!bbox) {
2410
+ bbox = this.getBBox();
2411
+ d.bbox = bbox;
2412
+ }
2413
+ const width = bbox.width + 10;
2414
+ const height = bbox.height + py * 2;
2415
+ select(this.parentElement).select("rect").attr("x", dx(d, offset - 5) + (d.x > 0 ? 0 : -1) * width).attr("y", -height / 2).attr("width", width).attr("height", height).attr("rx", 4);
2416
+ select(this.parentElement).select("line").attr("x1", dx(d, 1)).attr("y1", 0).attr("x2", dx(d, offset - 5)).attr("y2", 0);
2417
+ });
2418
+ }
2419
+ };
2420
+ /**
2421
+ * Create edge elements.
2422
+ * @param group
2423
+ * @param options
2424
+ * @param nodes
2425
+ */
2426
+ var createEdge = (group, options) => {
2427
+ if (options.onLinkClick) group.append("path").classed("dx-click", true).on("click", (event) => {
2428
+ const edge = select(event.target).datum();
2429
+ options.onLinkClick(edge, event);
2430
+ });
2431
+ group.append("path").attr("pointer-events", "none").attr("marker-start", () => options.arrows?.start ? "url(#marker-arrow-start)" : void 0).attr("marker-end", () => options.arrows?.end ? "url(#marker-arrow-end)" : void 0);
2432
+ };
2433
+ /**
2434
+ * Update edge elements.
2435
+ * @param group
2436
+ * @param options
2437
+ */
2438
+ var updateEdge = (group, options, nodeGroup) => {
2439
+ try {
2440
+ group.each((d, i, edges) => {
2441
+ const edge = select(edges[i]);
2442
+ edge.classed("dx-dashed", d.linkForce === false);
2443
+ const { classes, data } = options.attributes?.edge?.(d) ?? {};
2444
+ if (classes) applyClasses(edge, classes);
2445
+ if (data) Object.entries(data).forEach(([key, value]) => {
2446
+ edge.attr(`data-${key}`, value);
2447
+ });
2448
+ });
2449
+ } catch (error) {
2450
+ log.error("updateEdge", { error: error?.message }, {
2451
+ "~LogMeta": "~LogMeta",
2452
+ F: __dxlog_file$1,
2453
+ L: 595,
2454
+ S: void 0
2455
+ });
2456
+ }
2457
+ (options.transition ? group.transition(options.transition()) : group).selectAll("path").attr("d", function() {
2458
+ const edge = select(this.parentElement).datum();
2459
+ if (edge.path) return edge.path;
2460
+ const { source, target } = edge;
2461
+ if (!source.initialized || !target.initialized) return;
2462
+ return createLine$2(getCircumferencePoints([source.x, source.y], [target.x, target.y], source.r, target.r));
2463
+ });
2464
+ };
2465
+ /**
2466
+ * Hover-driven directional highlight: when `focusedId` is set, paint outgoing edges
2467
+ * orange, incoming edges sky-blue, dim unrelated edges, stroke connected nodes, and
2468
+ * dim unrelated nodes. When `focusedId` is null, clear every inline override so the
2469
+ * graph returns to its default styling.
2470
+ */
2471
+ var applyHoverHighlight = (root, focusedId) => {
2472
+ if (!root) return;
2473
+ const r = select(root);
2474
+ const on = focusedId != null;
2475
+ const outgoing = /* @__PURE__ */ new Set();
2476
+ const incoming = /* @__PURE__ */ new Set();
2477
+ if (on) r.select("g.dx-edges").selectAll("g.dx-edge").each((edge) => {
2478
+ if (edge.source.id === focusedId) outgoing.add(edge.target.id);
2479
+ if (edge.target.id === focusedId) incoming.add(edge.source.id);
2480
+ });
2481
+ r.select("g.dx-edges").selectAll("g.dx-edge").each(function(edge) {
2482
+ const path = select(this).select("path:not(.dx-click)");
2483
+ if (!on) {
2484
+ path.style("stroke", null).style("stroke-width", null).style("opacity", null);
2485
+ return;
2486
+ }
2487
+ if (edge.source.id === focusedId) path.style("stroke", "var(--color-orange-500)").style("stroke-width", "1.5px").style("opacity", null);
2488
+ else if (edge.target.id === focusedId) path.style("stroke", "var(--color-sky-500)").style("stroke-width", "1.5px").style("opacity", null);
2489
+ else path.style("stroke", null).style("stroke-width", null).style("opacity", "0.8");
2490
+ });
2491
+ r.select("g.dx-nodes").selectAll("g.dx-node").each(function(node) {
2492
+ const groupSel = select(this);
2493
+ const shape = groupSel.select("circle, rect");
2494
+ if (node.hidden) return;
2495
+ if (!on) {
2496
+ groupSel.style("opacity", null);
2497
+ shape.style("stroke", null).style("stroke-width", null);
2498
+ return;
2499
+ }
2500
+ const connected = outgoing.has(node.id) || incoming.has(node.id);
2501
+ if (node.id === focusedId) {
2502
+ groupSel.style("opacity", null);
2503
+ shape.style("stroke", null).style("stroke-width", null);
2504
+ } else if (connected) {
2505
+ groupSel.style("opacity", null);
2506
+ shape.style("stroke", "var(--color-orange-400)").style("stroke-width", "2.5px");
2507
+ } else {
2508
+ groupSel.style("opacity", "0.4");
2509
+ shape.style("stroke", null).style("stroke-width", null);
2510
+ }
2511
+ });
2512
+ };
2513
+ var applyClasses = (el, classes) => {
2514
+ for (const [className, value] of Object.entries(classes)) el.classed(className, value);
2515
+ };
2516
+ /**
2517
+ * Find connected components (subgraphs) in a graph.
2518
+ */
2519
+ var findConnectedComponents = (graph) => {
2520
+ const adj = {};
2521
+ for (const node of graph.nodes) adj[node.id] = [];
2522
+ for (const { source, target } of graph.edges) {
2523
+ adj[source].push(target);
2524
+ adj[target].push(source);
2525
+ }
2526
+ const visited = /* @__PURE__ */ new Set();
2527
+ const components = [];
2528
+ for (const node of graph.nodes) {
2529
+ if (visited.has(node.id)) continue;
2530
+ const stack = [node.id];
2531
+ const componentIds = [];
2532
+ while (stack.length) {
2533
+ const current = stack.pop();
2534
+ if (visited.has(current)) continue;
2535
+ visited.add(current);
2536
+ componentIds.push(current);
2537
+ stack.push(...adj[current]);
2538
+ }
2539
+ components.push(componentIds);
2540
+ }
2541
+ return components;
2542
+ };
2543
+ //#endregion
2544
+ //#region src/graph/renderer/labels.ts
2545
+ var DEFAULT_DURATION = 200;
2546
+ var DEFAULT_OFFSET = 4;
2547
+ /** Read the target (post-tween) position from a node. Falls back to current x/y on entry. */
2548
+ var getTarget = (node) => {
2549
+ const tx = node.tx;
2550
+ const ty = node.ty;
2551
+ return {
2552
+ x: tx ?? node.x ?? 0,
2553
+ y: ty ?? node.y ?? 0
2554
+ };
2555
+ };
2556
+ /**
2557
+ * Append a radial leaf label outside the node ring, oriented outward toward the TARGET
2558
+ * position so the label rotates with the layout tween rather than the pre-tween position.
2559
+ * Used by cluster + bundle variants for typename-grouped leaves.
2560
+ */
2561
+ var appendRadialLeafLabel = (group, node, label, r, options = {}) => {
2562
+ if (!label) return;
2563
+ const { delay = 0, duration = DEFAULT_DURATION, offset = DEFAULT_OFFSET, className = "dx-cluster-label" } = options;
2564
+ const { x: targetX, y: targetY } = getTarget(node);
2565
+ const angleDeg = Math.atan2(targetY, targetX) * 180 / Math.PI;
2566
+ const flipped = angleDeg > 90 || angleDeg < -90;
2567
+ group.append("text").attr("class", className).attr("dy", "0.32em").attr("transform", `rotate(${flipped ? angleDeg + 180 : angleDeg})`).attr("x", flipped ? -(r + offset) : r + offset).attr("text-anchor", flipped ? "end" : "start").attr("opacity", 0).style("cursor", "pointer").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
2568
+ };
2569
+ /**
2570
+ * Append a radial group label inside the node ring (anchored toward center), oriented along
2571
+ * the TARGET radial direction. Mirrors `appendRadialLeafLabel` but anchored on the opposite
2572
+ * side so leaf and group labels don't collide.
2573
+ */
2574
+ var appendRadialGroupLabel = (group, node, label, r, options = {}) => {
2575
+ if (!label) return;
2576
+ const { delay = 0, duration = DEFAULT_DURATION, offset = DEFAULT_OFFSET, className = "dx-cluster-label dx-cluster-label-group" } = options;
2577
+ const { x: targetX, y: targetY } = getTarget(node);
2578
+ const angleDeg = Math.atan2(targetY, targetX) * 180 / Math.PI;
2579
+ const flipped = angleDeg > 90 || angleDeg < -90;
2580
+ group.append("text").attr("class", className).attr("dy", "0.32em").attr("transform", `rotate(${flipped ? angleDeg + 180 : angleDeg})`).attr("x", flipped ? r + offset : -(r + offset)).attr("text-anchor", flipped ? "start" : "end").attr("opacity", 0).style("pointer-events", "none").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
2581
+ };
2582
+ /**
2583
+ * Append a centered root label above the node. Used by the cluster variant for the synthetic
2584
+ * root circle so the database / collection name reads from above the ring.
2585
+ */
2586
+ var appendRootLabel = (group, label, r, options = {}) => {
2587
+ if (!label) return;
2588
+ const { delay = 0, duration = DEFAULT_DURATION, offset = 6, className = "dx-cluster-label dx-cluster-label-root" } = options;
2589
+ group.append("text").attr("class", className).attr("text-anchor", "middle").attr("y", -(r + offset)).attr("opacity", 0).style("pointer-events", "none").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
2590
+ };
2591
+ //#endregion
2592
+ //#region src/graph/renderer/linker.ts
2593
+ var createLine$1 = line();
2594
+ /**
2595
+ * Render linker while dragging.
2596
+ */
2597
+ var linkerRenderer = (root, { source, target, point } = {}) => {
2598
+ root.selectAll("g.dx-linker").data([{ id: "linker" }]).join("g").attr("class", "dx-linker").selectAll("path").data(source ? [{ id: "edge" }] : []).join("path").attr("marker-end", () => target ? "url(#marker-arrow-end)" : "url(#marker-dot)").attr("d", () => {
2599
+ return createLine$1(getCircumferencePoints([source.x, source.y], target ? [target.x, target.y] : point, source.r, target ? target.r : 0));
2600
+ });
2601
+ };
2602
+ //#endregion
2603
+ //#region src/hooks/useSvgContext.ts
2604
+ /**
2605
+ * Contains a reference to the root SVG element and objects and configuration required by child nodes.
2606
+ */
2607
+ var SVGContext = class {
2608
+ _ref = createRef();
2609
+ _scale;
2610
+ _centered;
2611
+ _size;
2612
+ _center;
2613
+ resized = new EventEmitter();
2614
+ constructor({ scale = new Scale(), centered = true }) {
2615
+ this._scale = scale;
2616
+ this._centered = centered;
2617
+ }
2618
+ get ref() {
2619
+ return this._ref;
2620
+ }
2621
+ get svg() {
2622
+ return this._ref.current;
2623
+ }
2624
+ get scale() {
2625
+ return this._scale;
2626
+ }
2627
+ get center() {
2628
+ return this._center;
2629
+ }
2630
+ get size() {
2631
+ return this._size;
2632
+ }
2633
+ /**
2634
+ * https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
2635
+ */
2636
+ get viewBox() {
2637
+ const [x, y] = this.center;
2638
+ return `${x},${y},${this._size.width},${this._size.height}`;
2639
+ }
2640
+ setSize(size) {
2641
+ this._size = { ...size };
2642
+ this._center = this._centered ? [-Math.floor(size.width / 2), -Math.floor(size.height / 2)] : [0, 0];
2643
+ this.resized.emit(this);
2644
+ }
2645
+ setTransform(transform) {
2646
+ if (this._scale.setTransform(transform)) this.resized.emit(this);
2647
+ }
2648
+ /**
2649
+ * https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint
2650
+ * @param point
2651
+ */
2652
+ elementFromPoint(point) {
2653
+ const [x, y] = point;
2654
+ const [cx, cy] = this._center;
2655
+ return document.elementFromPoint(cx + x, cy + y);
2656
+ }
2657
+ };
2658
+ var SVGContextType = createContext(void 0);
2659
+ var SVGContextProvider = SVGContextType.Provider;
2660
+ /**
2661
+ * Get SVG context from the React context.
2662
+ */
2663
+ var useSvgContext = () => {
2664
+ return useContext(SVGContextType) ?? raise(/* @__PURE__ */ new Error("Missing SVGRoot"));
2665
+ };
2666
+ //#endregion
2667
+ //#region src/hooks/useGrid.ts
2668
+ var createLine = line();
2669
+ /**
2670
+ * Create grid based on size and current zoom transform.
2671
+ */
2672
+ var createGrid = (context, options) => {
2673
+ if (!context.size) return [];
2674
+ const paths = [];
2675
+ const { width, height } = context.size;
2676
+ const { x, y, k } = context.scale.transform;
2677
+ const s = 1 / k;
2678
+ const w = width * s;
2679
+ const h = height * s;
2680
+ const dx = -(x + width / 2) * s;
2681
+ const dy = -(y + height / 2) * s;
2682
+ if (options.axis) {
2683
+ const axis = [[[0, dy], [0, dy + h]], [[dx, 0], [dx + w, 0]]];
2684
+ paths.push({
2685
+ id: "axis",
2686
+ class: "dx-axis",
2687
+ path: axis.map((line) => createLine(line)).join()
2688
+ });
2689
+ }
2690
+ if (options.grid) {
2691
+ const mod = (n, size, delta = 0) => Math.floor(n / size + delta) * size;
2692
+ const majorSize = context.scale.gridSize;
2693
+ const xMajor = range(-mod((x + width / 2) * s, majorSize), mod((-x + width / 2) * s, majorSize, 1), majorSize);
2694
+ const yMajor = range(-mod((y + height / 2) * s, majorSize), mod((-y + height / 2) * s, majorSize, 1), majorSize);
2695
+ const major = [...xMajor.filter((x) => !options.axis || x).map((x) => [[x, dy], [x, dy + h]]), ...yMajor.filter((y) => !options.axis || y).map((y) => [[dx, y], [dx + w, y]])];
2696
+ paths.push({
2697
+ id: "major",
2698
+ class: "dx-major",
2699
+ path: major.map((line) => createLine(line)).join()
2700
+ });
2701
+ const minorSize = Math.pow(2, Math.round(Math.log2(s * context.scale.gridSize)));
2702
+ if (majorSize > minorSize) {
2703
+ const xMinor = range(-mod((x + width / 2) * s, minorSize), mod((-x + width / 2) * s, minorSize, 1), minorSize);
2704
+ const yMinor = range(-mod((y + height / 2) * s, minorSize), mod((-y + height / 2) * s, minorSize, 1), minorSize);
2705
+ const minor = [...xMinor.filter((x) => xMajor.indexOf(x) === -1).map((x) => [[x, dy], [x, dy + h]]), ...yMinor.filter((y) => yMajor.indexOf(y) === -1).map((y) => [[dx, y], [dx + w, y]])];
2706
+ paths.push({
2707
+ id: "minor",
2708
+ class: "dx-minor",
2709
+ path: minor.map((line) => createLine(line)).join()
2710
+ });
2711
+ }
2712
+ }
2713
+ return paths;
2714
+ };
2715
+ var defaultGridOptions = {
2716
+ visible: true,
2717
+ axis: true,
2718
+ grid: true
2719
+ };
2720
+ var GridController = class {
2721
+ _ref;
2722
+ _context;
2723
+ _options;
2724
+ _visible = false;
2725
+ constructor(_ref, _context, _options) {
2726
+ this._ref = _ref;
2727
+ this._context = _context;
2728
+ this._options = _options;
2729
+ this._visible = this._options.visible ?? true;
2730
+ }
2731
+ get ref() {
2732
+ return this._ref;
2733
+ }
2734
+ get visible() {
2735
+ return this._visible;
2736
+ }
2737
+ draw() {
2738
+ if (!this._context.size) return;
2739
+ const paths = this._visible ? createGrid(this._context, this._options) : [];
2740
+ const root = select(this._ref.current);
2741
+ root.selectAll("path").data(paths, (path) => path.id).join("path").style("pointer-events", "none").attr("d", (d) => d.path).attr("class", (d) => d.class);
2742
+ const transform = this._context.scale.transform;
2743
+ if (transform) {
2744
+ root.attr("transform", transform);
2745
+ root.attr("stroke-width", 1 / transform.k);
2746
+ }
2747
+ }
2748
+ setVisible(visible) {
2749
+ this._visible = visible;
2750
+ this.draw();
2751
+ return this;
2752
+ }
2753
+ };
2754
+ /**
2755
+ * Creates a reference to a SVG Group element which renders a grid.
2756
+ * @param options
2757
+ */
2758
+ var useGrid = (options = defaultGridOptions) => {
2759
+ const ref = useRef(null);
2760
+ const context = useSvgContext();
2761
+ const controller = useMemo(() => new GridController(ref, context, options), []);
2762
+ useEffect(() => context.resized.on(() => controller.draw()), [context, controller]);
2763
+ return controller;
2764
+ };
2765
+ //#endregion
2766
+ //#region src/hooks/useZoom.ts
2767
+ var defaultZoomOptions = {
2768
+ enabled: true,
2769
+ extent: [1 / 4, 4],
2770
+ onDblClick: (zoom) => zoom.reset()
2771
+ };
2772
+ /**
2773
+ * Zoom API.
2774
+ */
2775
+ var ZoomHandler = class {
2776
+ _ref;
2777
+ _context;
2778
+ _zoom;
2779
+ _options;
2780
+ _enabled;
2781
+ constructor(_ref, _context, options) {
2782
+ this._ref = _ref;
2783
+ this._context = _context;
2784
+ this._options = defaultsDeep({}, options, defaultZoomOptions);
2785
+ this._enabled = this._options.enabled ?? true;
2786
+ this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
2787
+ }
2788
+ /**
2789
+ * Gets the reference which the transform is applied to.
2790
+ */
2791
+ get ref() {
2792
+ return this._ref;
2793
+ }
2794
+ get zoom() {
2795
+ return this._zoom;
2796
+ }
2797
+ init() {
2798
+ this.setEnabled(this._enabled);
2799
+ this.reset(0);
2800
+ return this;
2801
+ }
2802
+ setEnabled(enable) {
2803
+ if (enable) select(this._context.svg).call(this._zoom).on("dblclick.zoom", this._options?.onDblClick ? () => {
2804
+ this._options?.onDblClick(this);
2805
+ } : null);
2806
+ else select(this._context.svg).on(".zoom", null);
2807
+ this._enabled = enable;
2808
+ return this;
2809
+ }
2810
+ reset(duration = 500) {
2811
+ const transform = zoomIdentity.scale(1);
2812
+ select(this._context.svg).transition().duration(duration).call(this._zoom.transform, transform);
2813
+ return this;
2814
+ }
2815
+ };
2816
+ /**
2817
+ * Creates the zoom handler.
2818
+ * @param options
2819
+ */
2820
+ var useZoom = (options = defaultZoomOptions) => {
2821
+ const context = useSvgContext();
2822
+ const ref = useRef(null);
2823
+ const handler = useMemo(() => new ZoomHandler(ref, context, options), [context, options]);
2824
+ useEffect(() => {
2825
+ handler.zoom.on("zoom", ({ transform }) => {
2826
+ context.setTransform(transform);
2827
+ select(ref.current).attr("transform", transform);
2828
+ });
2829
+ handler.init();
2830
+ }, [handler]);
2831
+ return handler;
2832
+ };
2833
+ //#endregion
2834
+ //#region src/components/Graph/Graph.tsx
2835
+ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
2836
+ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag, arrows, onSelect, onInspect, onPointerMove, onPointerLeave, ...props }, forwardedRef) => {
2837
+ const context = useSvgContext();
2838
+ const graphRef = useRef(null);
2839
+ const { projector, renderer } = useMemo(() => {
2840
+ let projector = projectorProp;
2841
+ if (!projector) projector = new GraphForceProjector(context);
2842
+ let renderer = rendererProp;
2843
+ if (!renderer) renderer = new GraphRenderer(context, graphRef, {
2844
+ ...props,
2845
+ drag: drag ? createGraphDrag(context, projector) : void 0,
2846
+ arrows: { end: arrows },
2847
+ onNodeClick: (node, event) => {
2848
+ if (projector.handleNodeClick(node, event)) return;
2849
+ onSelect?.(node, event);
2850
+ },
2851
+ onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0,
2852
+ onNodePointerLeave: onInspect ? (_node, event) => onInspect(null, event) : void 0
2853
+ });
2854
+ return {
2855
+ projector,
2856
+ renderer
2857
+ };
2858
+ }, [
2859
+ context,
2860
+ projectorProp,
2861
+ rendererProp,
2862
+ drag,
2863
+ arrows,
2864
+ onSelect,
2865
+ onInspect,
2866
+ props.labels,
2867
+ props.subgraphs,
2868
+ props.attributes,
2869
+ props.renderNode,
2870
+ props.highlightOnHover,
2871
+ props.applyNode,
2872
+ props.edgeOpacity
2873
+ ]);
2874
+ useImperativeHandle(forwardedRef, () => ({
2875
+ refresh: () => {
2876
+ projector.updateData(model?.graph);
2877
+ },
2878
+ repaint: () => {
2879
+ renderer.render(projector.layout);
2880
+ },
2881
+ findNode: (id) => {
2882
+ return graphRef.current?.querySelector(`g[data-id="${id}"]`);
2883
+ }
2884
+ }), [
2885
+ model,
2886
+ projector,
2887
+ renderer
2888
+ ]);
2889
+ useEffect(() => {
2890
+ const cleanup = combine(model ? model.subscribe(() => {
2891
+ projector.updateData(model?.graph);
2892
+ }) : void 0, projector.updated.on(({ layout, kind }) => {
2893
+ try {
2894
+ if (kind === "positions") renderer.applyPositions(layout);
2895
+ else renderer.render(layout);
2896
+ } catch (error) {
2897
+ log.catch(error, void 0, {
2898
+ "~LogMeta": "~LogMeta",
2899
+ F: __dxlog_file,
2900
+ L: 165,
2901
+ S: void 0
2902
+ });
2903
+ projector.stop();
2904
+ }
2905
+ }));
2906
+ projector.updateData(model?.graph);
2907
+ return cleanup;
2908
+ }, [
2909
+ model,
2910
+ projector,
2911
+ renderer
2912
+ ]);
2913
+ useEffect(() => {
2914
+ projector.start();
2915
+ return () => {
2916
+ projector.stop();
2917
+ };
2918
+ }, [projector]);
2919
+ useEffect(() => {
2920
+ if (!onPointerMove && !onPointerLeave) return;
2921
+ const svg = context.svg;
2922
+ if (!svg) return;
2923
+ const previousPointerEvents = svg.style.pointerEvents;
2924
+ svg.style.pointerEvents = "all";
2925
+ const handleMove = (event) => {
2926
+ if (!onPointerMove) return;
2927
+ const target = graphRef.current;
2928
+ const ctm = target?.getScreenCTM();
2929
+ if (!target || !ctm) return;
2930
+ const point = svg.createSVGPoint();
2931
+ point.x = event.clientX;
2932
+ point.y = event.clientY;
2933
+ const modelPoint = point.matrixTransform(ctm.inverse());
2934
+ onPointerMove({
2935
+ x: modelPoint.x,
2936
+ y: modelPoint.y
2937
+ }, event);
2938
+ };
2939
+ const handleLeave = (event) => {
2940
+ onPointerLeave?.(event);
2941
+ };
2942
+ svg.addEventListener("pointermove", handleMove);
2943
+ svg.addEventListener("pointerleave", handleLeave);
2944
+ return () => {
2945
+ svg.removeEventListener("pointermove", handleMove);
2946
+ svg.removeEventListener("pointerleave", handleLeave);
2947
+ svg.style.pointerEvents = previousPointerEvents;
2948
+ };
2949
+ }, [
2950
+ context,
2951
+ onPointerMove,
2952
+ onPointerLeave
2953
+ ]);
2954
+ return /* @__PURE__ */ jsx("g", {
2955
+ ref: graphRef,
2956
+ className: mx("dx-graph", classNames)
2957
+ });
2958
+ };
2959
+ /**
2960
+ * SVG Graph.
2961
+ */
2962
+ var Graph = forwardRef(GraphInner);
2963
+ //#endregion
2964
+ //#region src/components/Mesh/Mesh.tsx
2965
+ var Mesh = ({ radius = 16, value = .5 }) => {
2966
+ const { svg, size } = useSvgContext();
2967
+ useEffect(() => {
2968
+ if (!size) return;
2969
+ const topology = hexTopology(size, radius, value);
2970
+ const projection = hexProjection(radius);
2971
+ const path = geoPath().projection(projection);
2972
+ const root = select(svg).selectAll("g.dx-mesh-root").data([null]).join("g").classed("dx-mesh-root", true);
2973
+ root.selectAll("*").remove();
2974
+ root.append("g").attr("class", "hexagon").selectAll("path").data(topology.objects.hexagons.geometries).enter().append("path").attr("d", (d) => path(feature(topology, d))).attr("class", (d) => d.properties?.fill ? "fill" : null);
2975
+ root.append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
2976
+ const redraw = (border) => {
2977
+ border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
2978
+ };
2979
+ root.append("path").attr("class", "border").call(redraw);
2980
+ }, [
2981
+ svg,
2982
+ size,
2983
+ value,
2984
+ radius
2985
+ ]);
2986
+ return null;
2987
+ };
2988
+ var hexTopology = ({ width, height }, radius, value = 1) => {
2989
+ const dx = radius * 2 * Math.sin(Math.PI / 3);
2990
+ const dy = radius * 1.5;
2991
+ const m = Math.ceil((height + radius) / dy) + 1;
2992
+ const n = Math.ceil(width / dx) + 1;
2993
+ const geometries = [];
2994
+ const arcs = [];
2995
+ for (let j = -1; j <= m; ++j) for (let i = -1; i <= n; ++i) {
2996
+ const y = j * 2;
2997
+ const x = (i + (j & 1) / 2) * 2;
2998
+ arcs.push([[x, y - 1], [1, 1]], [[x + 1, y], [0, 1]], [[x + 1, y + 1], [-1, 1]]);
2999
+ }
3000
+ for (let j = 0, q = 3; j < m; ++j, q += 6) for (let i = 0; i < n; ++i, q += 3) geometries.push({
3001
+ type: "Polygon",
3002
+ arcs: [[
3003
+ q,
3004
+ q + 1,
3005
+ q + 2,
3006
+ ~(q + (n + 2 - (j & 1)) * 3),
3007
+ ~(q - 2),
3008
+ ~(q - (n + 2 + (j & 1)) * 3 + 2)
3009
+ ]],
3010
+ properties: { fill: Math.random() > i / n * (1 / value) }
3011
+ });
3012
+ return {
3013
+ type: "Topology",
3014
+ transform: {
3015
+ translate: [0, 0],
3016
+ scale: [1, 1]
3017
+ },
3018
+ objects: { hexagons: {
3019
+ type: "GeometryCollection",
3020
+ geometries
3021
+ } },
3022
+ arcs
3023
+ };
3024
+ };
3025
+ var hexProjection = (radius) => {
3026
+ const dx = radius * 2 * Math.sin(Math.PI / 3);
3027
+ const dy = radius * 1.5;
3028
+ return { stream: (stream) => ({
3029
+ point: (x, y) => {
3030
+ stream.point(x * dx / 2, (y - (2 - (y & 1)) / 3) * dy / 2);
3031
+ },
3032
+ lineStart: () => {
3033
+ stream.lineStart();
3034
+ },
3035
+ lineEnd: () => {
3036
+ stream.lineEnd();
3037
+ },
3038
+ polygonStart: () => {
3039
+ stream.polygonStart();
3040
+ },
3041
+ polygonEnd: () => {
3042
+ stream.polygonEnd();
3043
+ }
3044
+ }) };
3045
+ };
3046
+ //#endregion
3047
+ //#region src/components/SVG/FPS.tsx
3048
+ var PADDING = 8;
3049
+ /**
3050
+ * Frame-rate readout — drops into an `<SVG.Root>` alongside `<SVG.Graph>` to display a
3051
+ * rolling 1-second average of the browser's repaint rate. Self-contained: runs its own
3052
+ * `requestAnimationFrame` loop, so the number reflects actual render rate independent of
3053
+ * whichever projector is driving the graph.
3054
+ *
3055
+ * Anchored to a corner of the SVG viewBox via the `<text>`'s `text-anchor` and `dy`
3056
+ * attributes — re-renders on `context.resized` so the position tracks container resizes.
3057
+ */
3058
+ var FPS = ({ classNames, corner = "top-right", margin = PADDING }) => {
3059
+ const context = useSvgContext();
3060
+ const [size, setSize] = useState(context.size);
3061
+ const [fps, setFps] = useState(null);
3062
+ useEffect(() => {
3063
+ setSize(context.size);
3064
+ return context.resized.on((ctx) => setSize(ctx.size));
3065
+ }, [context]);
3066
+ useEffect(() => {
3067
+ let frames = 0;
3068
+ let windowStart = performance.now();
3069
+ let rafId = 0;
3070
+ const loop = (now) => {
3071
+ frames++;
3072
+ const elapsed = now - windowStart;
3073
+ if (elapsed >= 1e3) {
3074
+ setFps(frames * 1e3 / elapsed);
3075
+ frames = 0;
3076
+ windowStart = now;
3077
+ }
3078
+ rafId = requestAnimationFrame(loop);
3079
+ };
3080
+ rafId = requestAnimationFrame(loop);
3081
+ return () => cancelAnimationFrame(rafId);
3082
+ }, []);
3083
+ if (!size) return null;
3084
+ const halfW = size.width / 2;
3085
+ const halfH = size.height / 2;
3086
+ const left = corner === "top-left" || corner === "bottom-left";
3087
+ const top = corner === "top-left" || corner === "top-right";
3088
+ return /* @__PURE__ */ jsx("g", {
3089
+ className: "dx-fps",
3090
+ style: { pointerEvents: "none" },
3091
+ children: /* @__PURE__ */ jsx("text", {
3092
+ x: left ? -halfW + margin : halfW - margin,
3093
+ y: top ? -halfH + margin : halfH - margin,
3094
+ textAnchor: left ? "start" : "end",
3095
+ dominantBaseline: top ? "hanging" : "alphabetic",
3096
+ className: mx("font-mono text-xs fill-neutral-500 tabular-nums", classNames),
3097
+ children: fps == null ? "— fps" : `${fps.toFixed(0)} fps`
3098
+ })
3099
+ });
3100
+ };
3101
+ //#endregion
3102
+ //#region src/components/SVG/Grid.tsx
3103
+ /**
3104
+ * SVG grid wrapper.
3105
+ */
3106
+ var Grid = ({ classNames, ...props }) => {
3107
+ const { ref } = useGrid(props);
3108
+ return /* @__PURE__ */ jsx("g", {
3109
+ ref,
3110
+ className: mx("dx-grid", classNames)
3111
+ });
3112
+ };
3113
+ //#endregion
3114
+ //#region src/components/SVG/Markers.tsx
3115
+ /**
3116
+ * SVG markers wrapper.
3117
+ */
3118
+ var Markers = ({ arrowSize, className }) => {
3119
+ const ref = useRef(null);
3120
+ useEffect(() => {
3121
+ select(ref.current).call(createMarkers({ arrowSize }));
3122
+ }, [ref]);
3123
+ return /* @__PURE__ */ jsx("defs", {
3124
+ ref,
3125
+ className
3126
+ });
3127
+ };
3128
+ //#endregion
3129
+ //#region src/components/SVG/SVG.tsx
3130
+ var SVG = {
3131
+ Root: forwardRef(({ children, scale, centered, ...props }, ref) => {
3132
+ const [container, setContainer] = useState(null);
3133
+ const [size, setSize] = useState({
3134
+ width: 0,
3135
+ height: 0
3136
+ });
3137
+ useEffect(() => {
3138
+ if (!container) return;
3139
+ const rect = container.getBoundingClientRect();
3140
+ setSize({
3141
+ width: rect.width,
3142
+ height: rect.height
3143
+ });
3144
+ const observer = new ResizeObserver((entries) => {
3145
+ const entry = entries[0];
3146
+ if (!entry) return;
3147
+ const { width, height } = entry.contentRect;
3148
+ setSize((prev) => prev.width === width && prev.height === height ? prev : {
3149
+ width,
3150
+ height
3151
+ });
3152
+ });
3153
+ observer.observe(container);
3154
+ return () => observer.disconnect();
3155
+ }, [container]);
3156
+ const { width, height } = size;
3157
+ const context = useMemo(() => {
3158
+ return new SVGContext({
3159
+ scale,
3160
+ centered
3161
+ });
3162
+ }, [scale, centered]);
3163
+ useImperativeHandle(ref, () => context, [context]);
3164
+ useEffect(() => {
3165
+ if (width && height) {
3166
+ context.setSize({
3167
+ width,
3168
+ height
3169
+ });
3170
+ select(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
3171
+ }
3172
+ }, [
3173
+ context,
3174
+ width,
3175
+ height
3176
+ ]);
3177
+ const ready = width !== 0 && height !== 0;
3178
+ return /* @__PURE__ */ jsx(SVGContextProvider, {
3179
+ value: context,
3180
+ children: /* @__PURE__ */ jsx("div", {
3181
+ ...composableProps(props, { classNames: "dx-expander" }),
3182
+ ref: setContainer,
3183
+ children: /* @__PURE__ */ jsx("svg", {
3184
+ xmlns: "http://www.w3.org/2000/svg",
3185
+ ref: context.ref,
3186
+ className: mx("transition-opacity opacity-0 duration-1000", ready && "opacity-100"),
3187
+ children: ready && children
3188
+ })
3189
+ })
3190
+ });
3191
+ }),
3192
+ Grid,
3193
+ Markers,
3194
+ Mesh,
3195
+ Zoom: memo(({ extent, className, children }) => {
3196
+ return /* @__PURE__ */ jsx("g", {
3197
+ ref: useZoom(useMemo(() => ({ extent }), [JSON.stringify(extent)])).ref,
3198
+ className,
3199
+ children
3200
+ });
3201
+ }),
3202
+ Graph,
3203
+ FPS
3204
+ };
3205
+ //#endregion
3206
+ //#region src/components/Tree/layout/slots.ts
3207
+ var defaultTreeLayoutSlots = {
3208
+ node: "fill-blue-600 hover:fill-orange-500 cursor-pointer transition-colors",
3209
+ path: "fill-none stroke-blue-500/50 stroke-[1px] dark:stroke-blue-400/60",
3210
+ text: "fill-neutral-700 dark:fill-neutral-300 text-xs hover:fill-orange-500 cursor-pointer transition-colors"
3211
+ };
3212
+ //#endregion
3213
+ //#region src/components/Tree/layout/useContainerSize.ts
3214
+ /**
3215
+ * Track an element's content-box size via ResizeObserver.
3216
+ * Returns the most recently observed `{ width, height }` plus a callback ref to attach to the element.
3217
+ *
3218
+ * Why not `react-resize-detector` directly: its `targetRef` API doesn't pick up a ref whose
3219
+ * `.current` is set later than the hook runs, and the returned-`ref` API forces the consumer to
3220
+ * forward a callback ref through their own component — which is awkward for class refs.
3221
+ * This hook returns a setter so the consumer assigns it directly to `<div ref={setRef}>`.
3222
+ */
3223
+ var useContainerSize = () => {
3224
+ const [el, setEl] = useState(null);
3225
+ const [size, setSize] = useState({
3226
+ width: 0,
3227
+ height: 0
3228
+ });
3229
+ useEffect(() => {
3230
+ if (!el) return;
3231
+ const rect = el.getBoundingClientRect();
3232
+ setSize({
3233
+ width: rect.width,
3234
+ height: rect.height
3235
+ });
3236
+ const observer = new ResizeObserver((entries) => {
3237
+ const entry = entries[0];
3238
+ if (!entry) return;
3239
+ const { width, height } = entry.contentRect;
3240
+ setSize((prev) => prev.width === width && prev.height === height ? prev : {
3241
+ width,
3242
+ height
3243
+ });
3244
+ });
3245
+ observer.observe(el);
3246
+ return () => observer.disconnect();
3247
+ }, [el]);
3248
+ return {
3249
+ setRef: setEl,
3250
+ width: size.width,
3251
+ height: size.height
3252
+ };
3253
+ };
3254
+ //#endregion
3255
+ //#region src/components/Tree/layout/HierarchicalEdgeBundling.tsx
3256
+ var TRANSITION_MS$2 = 350;
3257
+ /**
3258
+ * Hierarchical edge bundling.
3259
+ * https://observablehq.com/@d3/hierarchical-edge-bundling?intent=fork
3260
+ *
3261
+ * Leaves are placed on a circle, grouped by their parent in the hierarchy.
3262
+ * Edges between leaves are drawn as bundled curves that route through their lowest common ancestor.
3263
+ */
3264
+ var HierarchicalEdgeBundling = ({ classNames, data, edges = [], label = (d) => d.label ?? d.id, padding = 120, tension = .85, r = 4, slots = defaultTreeLayoutSlots, onNodeHover }) => {
3265
+ const svgRef = useRef(null);
3266
+ const { setRef, width, height } = useContainerSize();
3267
+ const root = useMemo(() => buildBundleHierarchy(data, edges), [data, edges]);
3268
+ const handleHoverRef = useRef(() => {});
3269
+ handleHoverRef.current = (node, event) => onNodeHover?.(node, event);
3270
+ useEffect(() => {
3271
+ if (!svgRef.current || !width || !height) return;
3272
+ const radius = Math.max(0, Math.min(width, height) / 2 - padding);
3273
+ renderBundling(svgRef.current, root, {
3274
+ radius,
3275
+ r,
3276
+ label,
3277
+ slots,
3278
+ tension,
3279
+ onNodeHover: (n, e) => handleHoverRef.current(n, e)
3280
+ });
3281
+ }, [
3282
+ root,
3283
+ width,
3284
+ height,
3285
+ padding,
3286
+ tension,
3287
+ r,
3288
+ label,
3289
+ slots
3290
+ ]);
3291
+ return /* @__PURE__ */ jsx("div", {
3292
+ ref: setRef,
3293
+ className: mx("dx-expander relative", classNames),
3294
+ children: width > 0 && height > 0 && /* @__PURE__ */ jsx("svg", {
3295
+ ref: svgRef,
3296
+ xmlns: "http://www.w3.org/2000/svg",
3297
+ width,
3298
+ height,
3299
+ viewBox: `${-width / 2} ${-height / 2} ${width} ${height}`
3300
+ })
3301
+ });
3302
+ };
3303
+ /**
3304
+ * Build the bundling hierarchy from data + edges.
3305
+ * Edges connect leaves (by id); the cluster layout places leaves on the circle.
3306
+ */
3307
+ var buildBundleHierarchy = (data, edges) => {
3308
+ const root = hierarchy(data);
3309
+ const byId = /* @__PURE__ */ new Map();
3310
+ for (const node of root.descendants()) {
3311
+ byId.set(node.data.id, node);
3312
+ node.outgoing = [];
3313
+ node.incoming = [];
3314
+ }
3315
+ for (const edge of edges) {
3316
+ const source = byId.get(edge.source);
3317
+ const target = byId.get(edge.target);
3318
+ if (!source || !target || source === target) continue;
3319
+ source.outgoing.push([
3320
+ source,
3321
+ target,
3322
+ edge
3323
+ ]);
3324
+ target.incoming.push([
3325
+ source,
3326
+ target,
3327
+ edge
3328
+ ]);
3329
+ }
3330
+ return root;
3331
+ };
3332
+ var renderBundling = (svgElement, root, options) => {
3333
+ const { radius, r, tension, label, slots, onNodeHover } = options;
3334
+ const svg = select(svgElement);
3335
+ if (!root.children?.length) {
3336
+ svg.selectAll("g.dx-bundle-root").remove();
3337
+ return;
3338
+ }
3339
+ cluster().size([2 * Math.PI, radius])(root);
3340
+ const g = svg.selectAll("g.dx-bundle-root").data([null]).join("g").classed("dx-bundle-root", true);
3341
+ const linksLayer = g.selectAll("g.dx-bundle-links").data([null]).join("g").classed("dx-bundle-links", true);
3342
+ const nodesLayer = g.selectAll("g.dx-bundle-nodes").data([null]).join("g").classed("dx-bundle-nodes", true);
3343
+ const line = lineRadial().curve(curveBundle.beta(tension)).radius((d) => d.y).angle((d) => d.x);
3344
+ const leaves = root.leaves();
3345
+ const flatEdges = leaves.flatMap((leaf) => leaf.outgoing ?? []);
3346
+ linksLayer.selectAll("path").data(flatEdges, (d) => `${d[0].data.id}->${d[1].data.id}`).join((enter) => enter.append("path").attr("class", slots.path ?? "").attr("fill", "none").attr("opacity", 0), (update) => update, (exit) => exit.each(function() {
3347
+ select(this).interrupt();
3348
+ }).transition().duration(TRANSITION_MS$2).attr("opacity", 0).remove()).each(function(d) {
3349
+ d[0].pathEl = this;
3350
+ }).transition().duration(TRANSITION_MS$2).attr("opacity", 1).attr("d", ([s, t]) => line(s.path(t)));
3351
+ const labels = nodesLayer.selectAll("g.dx-bundle-leaf").data(leaves, (d) => d.data.id).join((enter) => {
3352
+ const ge = enter.append("g").classed("dx-bundle-leaf", true).attr("opacity", 0);
3353
+ ge.append("circle").style("cursor", "pointer");
3354
+ ge.append("text").attr("dy", "0.32em").attr("paint-order", "stroke").style("cursor", "pointer");
3355
+ return ge;
3356
+ }, (update) => update, (exit) => exit.each(function() {
3357
+ select(this).interrupt();
3358
+ }).transition().duration(TRANSITION_MS$2).attr("opacity", 0).remove());
3359
+ labels.transition().duration(TRANSITION_MS$2).attr("opacity", 1).attr("transform", (d) => `rotate(${d.x * 180 / Math.PI - 90}) translate(${d.y},0)`);
3360
+ const onEnter = function(event, d) {
3361
+ onNodeHover(d.data, event);
3362
+ hover(linksLayer, leaves, d, true);
3363
+ };
3364
+ const onLeave = function(event, d) {
3365
+ onNodeHover(null);
3366
+ hover(linksLayer, leaves, d, false);
3367
+ };
3368
+ labels.select("circle").attr("class", [slots.node ?? "", "dx-leaf"].filter(Boolean).join(" ")).attr("r", r).style("fill", (d) => slots.nodeFill?.(d.data.data) ?? null).each(function(d) {
3369
+ d.circle = this;
3370
+ }).on("pointerenter", onEnter).on("pointerleave", onLeave);
3371
+ labels.select("text").attr("class", slots.text ?? "").attr("x", (d) => d.x < Math.PI ? r + 4 : -(r + 4)).attr("text-anchor", (d) => d.x < Math.PI ? "start" : "end").attr("transform", (d) => d.x >= Math.PI ? "rotate(180)" : null).each(function(d) {
3372
+ d.text = this;
3373
+ }).text((d) => label(d.data)).on("pointerenter", onEnter).on("pointerleave", onLeave);
3374
+ };
3375
+ var hover = (linksLayer, leaves, focused, on) => {
3376
+ const outgoing = new Set((focused.outgoing ?? []).map(([, t]) => t));
3377
+ const incoming = new Set((focused.incoming ?? []).map(([s]) => s));
3378
+ linksLayer.selectAll("path").style("stroke", (d) => {
3379
+ if (!on) return null;
3380
+ if (d[0] === focused) return "var(--color-orange-500)";
3381
+ if (d[1] === focused) return "var(--color-sky-500)";
3382
+ return null;
3383
+ }).style("stroke-width", (d) => on && (d[0] === focused || d[1] === focused) ? "1.5px" : null).style("opacity", (d) => on && d[0] !== focused && d[1] !== focused ? "0.08" : null);
3384
+ for (const leaf of leaves) {
3385
+ const isOut = outgoing.has(leaf);
3386
+ const isIn = incoming.has(leaf);
3387
+ const isConnected = isOut || isIn;
3388
+ if (leaf.text) select(leaf.text).style("fill", () => {
3389
+ if (!on) return null;
3390
+ if (leaf === focused) return "var(--color-neutral-900)";
3391
+ if (isOut) return "var(--color-orange-500)";
3392
+ if (isIn) return "var(--color-sky-500)";
3393
+ return null;
3394
+ }).style("font-weight", () => on && leaf === focused ? "600" : null);
3395
+ if (leaf.circle) select(leaf.circle).style("stroke", () => on && isConnected ? "var(--color-orange-400)" : null).style("stroke-width", () => on && isConnected ? "2.5px" : null).style("opacity", () => on && !isConnected && leaf !== focused ? "0.15" : null);
3396
+ }
3397
+ };
3398
+ //#endregion
3399
+ //#region src/components/Tree/layout/hierarchy.ts
3400
+ /**
3401
+ * Build a d3 hierarchy from a TreeNode, pruning children of nodes whose ids are in `collapsed`.
3402
+ * Nodes that have children but are collapsed retain their identity in the hierarchy and can be
3403
+ * distinguished by `node._children` (the original list).
3404
+ */
3405
+ var buildHierarchy = (data, collapsed = /* @__PURE__ */ new Set()) => {
3406
+ return hierarchy(data, (d) => {
3407
+ if (!d.children?.length) return;
3408
+ return collapsed.has(d.id) ? void 0 : d.children;
3409
+ });
3410
+ };
3411
+ /**
3412
+ * True when the node has children that have been hidden via collapse.
3413
+ */
3414
+ var isCollapsed = (data, collapsed) => Boolean(data.children?.length) && collapsed.has(data.id);
3415
+ /**
3416
+ * True when the node has no children at all (a real leaf, not a collapsed branch).
3417
+ */
3418
+ var isLeaf = (data) => !data.children?.length;
3419
+ //#endregion
3420
+ //#region src/components/Tree/layout/RadialTree.tsx
3421
+ var TRANSITION_MS$1 = 350;
3422
+ /**
3423
+ * Radial tree layout based on the D3 reference component.
3424
+ * https://observablehq.com/@d3/radial-tree-component
3425
+ *
3426
+ * Click a node with children to toggle collapse / expand.
3427
+ */
3428
+ var RadialTree = ({ classNames, data, label = (d) => d.label ?? d.id, slots = defaultTreeLayoutSlots, r = 4, padding = 80, initialCollapsed, cluster = false, onNodeClick, onNodeHover }) => {
3429
+ const svgRef = useRef(null);
3430
+ const { setRef, width, height } = useContainerSize();
3431
+ const [collapsed, setCollapsed] = useState(() => new Set(initialCollapsed ?? []));
3432
+ const toggle = useCallback((id) => {
3433
+ setCollapsed((prev) => {
3434
+ const next = new Set(prev);
3435
+ if (next.has(id)) next.delete(id);
3436
+ else next.add(id);
3437
+ return next;
3438
+ });
3439
+ }, []);
3440
+ const handleClickRef = useRef(() => {});
3441
+ handleClickRef.current = (node) => {
3442
+ onNodeClick?.(node);
3443
+ if (node.children?.length) toggle(node.id);
3444
+ };
3445
+ const handleHoverRef = useRef(() => {});
3446
+ handleHoverRef.current = (node, event) => onNodeHover?.(node, event);
3447
+ const root = useMemo(() => buildHierarchy(data, collapsed), [data, collapsed]);
3448
+ useEffect(() => {
3449
+ if (!svgRef.current || !width || !height) return;
3450
+ const radius = Math.max(0, Math.min(width, height) / 2 - padding);
3451
+ renderRadialTree(svgRef.current, root, {
3452
+ radius,
3453
+ r,
3454
+ label,
3455
+ slots,
3456
+ collapsed,
3457
+ cluster,
3458
+ onNodeClick: (n) => handleClickRef.current(n),
3459
+ onNodeHover: (n, e) => handleHoverRef.current(n, e)
3460
+ });
3461
+ }, [
3462
+ root,
3463
+ width,
3464
+ height,
3465
+ r,
3466
+ padding,
3467
+ label,
3468
+ slots,
3469
+ collapsed,
3470
+ cluster
3471
+ ]);
3472
+ return /* @__PURE__ */ jsx("div", {
3473
+ ref: setRef,
3474
+ className: mx("dx-expander relative", classNames),
3475
+ children: width > 0 && height > 0 && /* @__PURE__ */ jsx("svg", {
3476
+ ref: svgRef,
3477
+ xmlns: "http://www.w3.org/2000/svg",
3478
+ width,
3479
+ height,
3480
+ viewBox: `${-width / 2} ${-height / 2} ${width} ${height}`
3481
+ })
3482
+ });
3483
+ };
3484
+ var renderRadialTree = (svgElement, root, options) => {
3485
+ const { radius, r, label, slots, collapsed, cluster: cluster$1, onNodeClick, onNodeHover } = options;
3486
+ const svg = select(svgElement);
3487
+ (cluster$1 ? cluster() : tree()).size([2 * Math.PI, radius]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
3488
+ const g = svg.selectAll("g.dx-radial-root").data([null]).join("g").classed("dx-radial-root", true);
3489
+ const linksLayer = g.selectAll("g.dx-radial-links").data([null]).join("g").classed("dx-radial-links", true);
3490
+ const nodesLayer = g.selectAll("g.dx-radial-nodes").data([null]).join("g").classed("dx-radial-nodes", true);
3491
+ const linkPath = linkRadial().angle((d) => d.x).radius((d) => d.y);
3492
+ linksLayer.selectAll("path").data(root.links(), (d) => `${d.source.data.id}->${d.target.data.id}`).join((enter) => enter.append("path").attr("class", slots.path ?? "").attr("fill", "none").attr("opacity", 0), (update) => update, (exit) => exit.transition().duration(TRANSITION_MS$1).attr("opacity", 0).remove()).transition().duration(TRANSITION_MS$1).attr("opacity", 1).attr("d", linkPath);
3493
+ const node = nodesLayer.selectAll("g.dx-radial-node").data(root.descendants(), (d) => d.data.id);
3494
+ const nodeEnter = node.enter().append("g").classed("dx-radial-node", true).attr("opacity", 0).attr("transform", (d) => `rotate(${d.x * 180 / Math.PI - 90}) translate(${d.y},0)`).style("cursor", (d) => d.data.children?.length ? "pointer" : "default").on("click", (_, d) => onNodeClick(d.data));
3495
+ nodeEnter.append("circle").attr("r", r).on("pointerenter", (event, d) => onNodeHover(d.data, event)).on("pointerleave", (event) => onNodeHover(null, event));
3496
+ nodeEnter.append("text").attr("dy", "0.32em").attr("paint-order", "stroke").text((d) => label(d.data));
3497
+ const nodeMerge = nodeEnter.merge(node);
3498
+ nodeMerge.transition().duration(TRANSITION_MS$1).attr("opacity", 1).attr("transform", (d) => `rotate(${d.x * 180 / Math.PI - 90}) translate(${d.y},0)`);
3499
+ nodeMerge.select("circle").attr("class", (d) => {
3500
+ const collapsedHere = isCollapsed(d.data, collapsed);
3501
+ const leaf = isLeaf(d.data);
3502
+ return [slots.node ?? "", collapsedHere ? "dx-collapsed" : leaf ? "dx-leaf" : "dx-branch"].filter(Boolean).join(" ");
3503
+ }).attr("r", r).style("fill", (d) => isLeaf(d.data) ? slots.nodeFill?.(d.data.data) ?? null : null);
3504
+ nodeMerge.select("text").attr("class", slots.text ?? "").attr("transform", (d) => d.x >= Math.PI ? "rotate(180)" : null).attr("x", (d) => d.x < Math.PI === !d.children ? r + 4 : -(r + 4)).attr("text-anchor", (d) => d.x < Math.PI === !d.children ? "start" : "end").text((d) => label(d.data));
3505
+ node.exit().transition().duration(TRANSITION_MS$1).attr("opacity", 0).remove();
3506
+ };
3507
+ //#endregion
3508
+ //#region src/components/Tree/layout/TidyTree.tsx
3509
+ var TRANSITION_MS = 350;
3510
+ /**
3511
+ * Tidy (horizontal) tree layout based on the D3 reference component.
3512
+ * https://observablehq.com/@d3/tree-component
3513
+ *
3514
+ * Click a node with children to toggle collapse / expand.
3515
+ */
3516
+ var TidyTree = ({ classNames, data, label = (d) => d.label ?? d.id, slots = defaultTreeLayoutSlots, r = 4, margin = 24, initialCollapsed, onNodeClick }) => {
3517
+ const svgRef = useRef(null);
3518
+ const { setRef, width, height } = useContainerSize();
3519
+ const [collapsed, setCollapsed] = useState(() => new Set(initialCollapsed ?? []));
3520
+ const toggle = useCallback((id) => {
3521
+ setCollapsed((prev) => {
3522
+ const next = new Set(prev);
3523
+ if (next.has(id)) next.delete(id);
3524
+ else next.add(id);
3525
+ return next;
3526
+ });
3527
+ }, []);
3528
+ const handleClickRef = useRef(() => {});
3529
+ handleClickRef.current = (node) => {
3530
+ onNodeClick?.(node);
3531
+ if (node.children?.length) toggle(node.id);
3532
+ };
3533
+ const root = useMemo(() => buildHierarchy(data, collapsed), [data, collapsed]);
3534
+ useEffect(() => {
3535
+ if (!svgRef.current || !width || !height) return;
3536
+ renderTidyTree(svgRef.current, root, {
3537
+ width,
3538
+ height,
3539
+ r,
3540
+ margin,
3541
+ label,
3542
+ slots,
3543
+ collapsed,
3544
+ onNodeClick: (n) => handleClickRef.current(n)
3545
+ });
3546
+ }, [
3547
+ root,
3548
+ width,
3549
+ height,
3550
+ r,
3551
+ margin,
3552
+ label,
3553
+ slots,
3554
+ collapsed
3555
+ ]);
3556
+ return /* @__PURE__ */ jsx("div", {
3557
+ ref: setRef,
3558
+ className: mx("dx-expander relative", classNames),
3559
+ children: width > 0 && height > 0 && /* @__PURE__ */ jsx("svg", {
3560
+ ref: svgRef,
3561
+ xmlns: "http://www.w3.org/2000/svg",
3562
+ width,
3563
+ height,
3564
+ viewBox: `${-width / 2} ${-height / 2} ${width} ${height}`
3565
+ })
3566
+ });
3567
+ };
3568
+ var renderTidyTree = (svgElement, root, options) => {
3569
+ const { width, height, r, margin, label, slots, collapsed, onNodeClick } = options;
3570
+ const svg = select(svgElement);
3571
+ const dx = 18;
3572
+ const dy = Math.max(60, (width - margin * 2) / Math.max(1, root.height + 1));
3573
+ tree().nodeSize([dx, dy])(root);
3574
+ let x0 = Infinity;
3575
+ let x1 = -x0;
3576
+ root.each((d) => {
3577
+ if (d.x > x1) x1 = d.x;
3578
+ if (d.x < x0) x0 = d.x;
3579
+ });
3580
+ const treeWidth = width - margin * 2;
3581
+ const treeHeight = x1 - x0;
3582
+ const scaleY = treeHeight > 0 ? Math.min(1, (height - margin * 2) / treeHeight) : 1;
3583
+ const offsetX = -treeWidth / 2;
3584
+ const offsetY = -(x0 + x1) / 2;
3585
+ const g = svg.selectAll("g.dx-tidy-root").data([null]).join("g").classed("dx-tidy-root", true);
3586
+ const linksLayer = g.selectAll("g.dx-tidy-links").data([null]).join("g").classed("dx-tidy-links", true);
3587
+ const nodesLayer = g.selectAll("g.dx-tidy-nodes").data([null]).join("g").classed("dx-tidy-nodes", true);
3588
+ const linkPath = link(curveBumpX).x((d) => offsetX + d.y).y((d) => (d.x + offsetY) * scaleY);
3589
+ linksLayer.selectAll("path").data(root.links(), (d) => `${d.source.data.id}->${d.target.data.id}`).join((enter) => enter.append("path").attr("class", slots.path ?? "").attr("fill", "none").attr("opacity", 0), (update) => update, (exit) => exit.transition().duration(TRANSITION_MS).attr("opacity", 0).remove()).transition().duration(TRANSITION_MS).attr("opacity", 1).attr("d", linkPath);
3590
+ const node = nodesLayer.selectAll("g.dx-tidy-node").data(root.descendants(), (d) => d.data.id);
3591
+ const nodeEnter = node.enter().append("g").classed("dx-tidy-node", true).attr("transform", (d) => `translate(${offsetX + d.y},${(d.x + offsetY) * scaleY})`).attr("opacity", 0).style("cursor", (d) => d.data.children?.length ? "pointer" : "default").on("click", (_, d) => onNodeClick(d.data));
3592
+ nodeEnter.append("circle").attr("r", r);
3593
+ nodeEnter.append("text").attr("dy", "0.32em").attr("x", (d) => d.children ? -(r + 4) : r + 4).attr("text-anchor", (d) => d.children ? "end" : "start").text((d) => label(d.data));
3594
+ const nodeMerge = nodeEnter.merge(node);
3595
+ nodeMerge.transition().duration(TRANSITION_MS).attr("opacity", 1).attr("transform", (d) => `translate(${offsetX + d.y},${(d.x + offsetY) * scaleY})`);
3596
+ nodeMerge.select("circle").attr("class", (d) => {
3597
+ const collapsedHere = isCollapsed(d.data, collapsed);
3598
+ const leaf = isLeaf(d.data);
3599
+ return [slots.node ?? "", collapsedHere ? "dx-collapsed" : leaf ? "dx-leaf" : "dx-branch"].filter(Boolean).join(" ");
3600
+ }).attr("r", r);
3601
+ nodeMerge.select("text").attr("class", slots.text ?? "").attr("x", (d) => d.children ? -(r + 4) : r + 4).attr("text-anchor", (d) => d.children ? "end" : "start").text((d) => label(d.data));
3602
+ node.exit().each(function() {
3603
+ select(this).interrupt();
3604
+ }).transition().duration(TRANSITION_MS).attr("opacity", 0).remove();
3605
+ };
3606
+ //#endregion
3607
+ //#region src/components/Tree/Tree.tsx
3608
+ /**
3609
+ * Tree visualization wrapping the three layout variants.
3610
+ * - `tidy` — horizontal tidy tree (collapsible)
3611
+ * - `radial` — radial tree (collapsible)
3612
+ * - `edge` — hierarchical edge bundling (`edges` connect leaves)
3613
+ */
3614
+ var Tree = ({ classNames, data, edges, variant = "tidy", label, slots, margin, initialCollapsed, onNodeClick, onNodeHover }) => {
3615
+ return useMemo(() => {
3616
+ switch (variant) {
3617
+ case "tidy": return /* @__PURE__ */ jsx(TidyTree, {
3618
+ classNames,
3619
+ data,
3620
+ label,
3621
+ slots,
3622
+ margin,
3623
+ initialCollapsed,
3624
+ onNodeClick
3625
+ });
3626
+ case "radial": return /* @__PURE__ */ jsx(RadialTree, {
3627
+ classNames,
3628
+ data,
3629
+ label,
3630
+ slots,
3631
+ initialCollapsed,
3632
+ onNodeClick,
3633
+ onNodeHover
3634
+ });
3635
+ case "edge": return /* @__PURE__ */ jsx(HierarchicalEdgeBundling, {
3636
+ classNames,
3637
+ data,
3638
+ edges: edges ?? [],
3639
+ label,
3640
+ slots,
3641
+ onNodeHover
3642
+ });
3643
+ }
3644
+ }, [
3645
+ variant,
3646
+ classNames,
3647
+ data,
3648
+ edges,
3649
+ label,
3650
+ slots,
3651
+ initialCollapsed,
3652
+ onNodeClick,
3653
+ onNodeHover
3654
+ ]);
3655
+ };
3656
+ //#endregion
3657
+ //#region src/fx/pulsar.ts
3658
+ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
3659
+ var Pulsar;
3660
+ (function(_Pulsar) {
3661
+ _Pulsar.has = (group) => group.select("circle.dx-pulsar").empty();
3662
+ _Pulsar.create = (group, r, options = {}) => {
3663
+ startAnimation(group.append("circle").classed("dx-pulsar", true).classed("stroke-2 stroke-red-500 fill-none", true).property(PROP_PULSAR_ACTIVE, true), r, options);
3664
+ };
3665
+ _Pulsar.remove = (group) => {
3666
+ group.select("circle.dx-pulsar").property(PROP_PULSAR_ACTIVE, false);
3667
+ };
3668
+ })(Pulsar || (Pulsar = {}));
3669
+ var startAnimation = (pulsar, r, options = {}) => {
3670
+ const { period = 1e3, duration = 800, ratio = 3 } = options;
3671
+ return pulsar.attr("r", r).attr("opacity", 1).transition("pulsar").delay(period - Date.now() % period).duration(Math.min(duration, period - 20)).ease(easeCubicOut).attr("r", r * ratio).attr("opacity", -.1).on("end", function() {
3672
+ if (select(this).property(PROP_PULSAR_ACTIVE)) startAnimation(select(this), r, options);
3673
+ else select(this).remove();
3674
+ });
3675
+ };
3676
+ //#endregion
3677
+ export { CLUSTER_NODE_TYPE_GROUP, CLUSTER_NODE_TYPE_LEAF, CLUSTER_NODE_TYPE_ROOT, EventEmitter, FractionUtil, Graph, GraphBundleProjector, GraphClusterProjector, GraphForceProjector, GraphHierarchicalProjector, GraphLatticeProjector, GraphPlexusProjector, GraphProjector, GraphRadialProjector, GraphRelationalProjector, GraphRenderer, GraphSwarmProjector, GraphTreeProjector, GridController, HierarchicalEdgeBundling, Mesh, PLEXUS_NODE_TYPE_FOCUS, PLEXUS_NODE_TYPE_OBJECT, PLEXUS_NODE_TYPE_RELATION, Projector, Pulsar, RadialTree, Renderer, SVG, SVGContext, SVGContextProvider, Scale, Screen, TREE_NODE_TYPE_INBOUND, TREE_NODE_TYPE_NODE, TREE_NODE_TYPE_ROOT, TidyTree, Tree, Vector, ZoomHandler, appendRadialGroupLabel, appendRadialLeafLabel, appendRootLabel, buildHierarchy, createGraphDrag, createMarkers, defaultForceOptions, defaultIdAccessor, defaultTreeLayoutSlots, emptyGraph, getCircumferencePoints, isCollapsed, isLeaf, layoutHorizontal, layoutRadial, layoutVertical, linkerRenderer, normal, offsetPoints, updateNode, useContainerSize, useDynamicRef, useGrid, useStateRef, useSvgContext, useTimestamp, useZoom };
3678
+
3679
+ //# sourceMappingURL=index.mjs.map