@dxos/react-ui-graph 0.8.4-main.406dc2a → 0.8.4-main.4a85c3132b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +5 -7
  2. package/dist/lib/browser/chunk-LKC455GK.mjs +52 -0
  3. package/dist/lib/browser/chunk-LKC455GK.mjs.map +7 -0
  4. package/dist/lib/browser/index.mjs +1118 -336
  5. package/dist/lib/browser/index.mjs.map +4 -4
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/testing/index.mjs +3 -3
  8. package/dist/lib/browser/testing/index.mjs.map +3 -3
  9. package/dist/lib/node-esm/chunk-JE4KZCUF.mjs +54 -0
  10. package/dist/lib/node-esm/chunk-JE4KZCUF.mjs.map +7 -0
  11. package/dist/lib/node-esm/index.mjs +1118 -336
  12. package/dist/lib/node-esm/index.mjs.map +4 -4
  13. package/dist/lib/node-esm/meta.json +1 -1
  14. package/dist/lib/node-esm/testing/index.mjs +3 -3
  15. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  16. package/dist/types/src/components/Graph/Graph.d.ts +4 -5
  17. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  18. package/dist/types/src/components/Graph/Graph.stories.d.ts +1 -1
  19. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/SVG/Root.d.ts +4 -4
  21. package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
  22. package/dist/types/src/components/SVG/SVG.d.ts +14 -17
  23. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  24. package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
  25. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  26. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
  27. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
  28. package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
  29. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  30. package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
  31. package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
  32. package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
  33. package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
  34. package/dist/types/src/graph/types.d.ts +1 -1
  35. package/dist/types/src/graph/types.d.ts.map +1 -1
  36. package/dist/types/src/stories/hooks.stories.d.ts +3 -2
  37. package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
  38. package/dist/types/src/testing/data.d.ts +4 -4
  39. package/dist/types/src/testing/data.d.ts.map +1 -1
  40. package/dist/types/src/testing/hooks.d.ts +2 -16
  41. package/dist/types/src/testing/hooks.d.ts.map +1 -1
  42. package/dist/types/src/testing/model.d.ts +4 -8
  43. package/dist/types/src/testing/model.d.ts.map +1 -1
  44. package/dist/types/src/util/fraction.d.ts +1 -1
  45. package/dist/types/tsconfig.tsbuildinfo +1 -1
  46. package/package.json +31 -26
  47. package/src/components/Graph/Graph.stories.tsx +35 -31
  48. package/src/components/Graph/Graph.tsx +22 -15
  49. package/src/components/Mesh/Mesh.stories.tsx +2 -2
  50. package/src/components/SVG/Grid.tsx +1 -1
  51. package/src/components/SVG/Root.tsx +14 -7
  52. package/src/components/SVG/SVG.tsx +10 -1
  53. package/src/components/SVG/Svg.stories.tsx +2 -2
  54. package/src/fx/fx.stories.tsx +2 -2
  55. package/src/graph/projector/graph-force-projector.ts +1 -1
  56. package/src/graph/projector/graph-hierarchical-projector.ts +3 -3
  57. package/src/graph/projector/graph-projector.ts +2 -2
  58. package/src/graph/projector/graph-radial-projector.ts +1 -1
  59. package/src/graph/projector/graph-relational-projector.ts +3 -3
  60. package/src/graph/types.ts +1 -1
  61. package/src/stories/hooks.stories.tsx +13 -7
  62. package/src/testing/data.ts +5 -5
  63. package/src/testing/hooks.ts +1 -1
  64. package/src/testing/model.ts +3 -3
  65. package/src/util/fraction.ts +1 -1
  66. package/styles/graph.css +292 -43
  67. package/dist/lib/browser/chunk-EX2Q43O6.mjs +0 -966
  68. package/dist/lib/browser/chunk-EX2Q43O6.mjs.map +0 -7
  69. package/dist/lib/node-esm/chunk-SWA6OT3W.mjs +0 -968
  70. package/dist/lib/node-esm/chunk-SWA6OT3W.mjs.map +0 -7
@@ -1,31 +1,14 @@
1
1
  import {
2
- EventEmitter,
3
- FractionUtil,
4
- GridController,
5
- SVGContext,
6
- SVGContextProvider,
7
- Scale,
8
- Screen,
9
- Vector,
10
- ZoomHandler,
11
- getCircumferencePoints,
12
- normal,
13
- offsetPoints,
14
2
  useDynamicRef,
15
- useGrid,
16
3
  useStateRef,
17
- useSvgContext,
18
- useTimestamp,
19
- useZoom
20
- } from "./chunk-EX2Q43O6.mjs";
4
+ useTimestamp
5
+ } from "./chunk-LKC455GK.mjs";
21
6
 
22
7
  // src/components/Graph/Graph.tsx
23
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
24
- import { effect } from "@preact/signals-core";
25
- import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from "react";
8
+ import React, { forwardRef, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo3, useRef as useRef3 } from "react";
26
9
  import { combine } from "@dxos/async";
27
10
  import { log as log6 } from "@dxos/log";
28
- import { mx } from "@dxos/react-ui-theme";
11
+ import { mx } from "@dxos/ui-theme";
29
12
 
30
13
  // src/graph/markers.ts
31
14
  import { line, select } from "d3";
@@ -178,21 +161,589 @@ var emptyGraph = {
178
161
  edges: []
179
162
  };
180
163
 
181
- // src/graph/projector/projector.ts
182
- function _define_property(obj, key, value) {
183
- if (key in obj) {
184
- Object.defineProperty(obj, key, {
185
- value,
186
- enumerable: true,
187
- configurable: true,
188
- writable: true
164
+ // src/util/events.ts
165
+ var EventEmitter = class {
166
+ _listeners = /* @__PURE__ */ new Set();
167
+ clear() {
168
+ this._listeners.clear();
169
+ }
170
+ on(onEvent) {
171
+ this._listeners.add(onEvent);
172
+ return () => this._listeners.delete(onEvent);
173
+ }
174
+ emit(value) {
175
+ this._listeners.forEach((listener) => listener(value));
176
+ }
177
+ };
178
+
179
+ // src/util/fraction.ts
180
+ import { invariant as invariant2 } from "@dxos/invariant";
181
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
182
+ var FractionUtil = class _FractionUtil {
183
+ /**
184
+ * Convert number to fraction.
185
+ * @param n
186
+ */
187
+ static toFraction = (n) => {
188
+ return typeof n === "number" ? [
189
+ n,
190
+ 1
191
+ ] : n;
192
+ };
193
+ static validate = (...fraction) => {
194
+ fraction.forEach(([n, d]) => {
195
+ if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
196
+ throw new Error(`Invalid fraction: ${n}/${d}`);
197
+ }
198
+ });
199
+ return fraction;
200
+ };
201
+ /**
202
+ * @param {Fraction}
203
+ * Convert to rounded-sm number.
204
+ */
205
+ static toNumber = ([n, d]) => {
206
+ _FractionUtil.validate([
207
+ n,
208
+ d
209
+ ]);
210
+ return n / d;
211
+ };
212
+ /**
213
+ * Round the number to the nearest fraction.
214
+ * Example: 3/5 => 1/1; 3/5 (precision 2) => 1/2.
215
+ * @param {Fraction}
216
+ * @param p Precision (e.g., 1/2, 1/4, etc.)
217
+ */
218
+ static round = ([n, d], p = 1) => {
219
+ _FractionUtil.validate([
220
+ n,
221
+ d
222
+ ]);
223
+ const v = Math.round(_FractionUtil.toNumber(_FractionUtil.divide([
224
+ n,
225
+ d
226
+ ], [
227
+ 1,
228
+ p
229
+ ])));
230
+ return _FractionUtil.simplify([
231
+ v,
232
+ p
233
+ ]);
234
+ };
235
+ //
236
+ // Boolean.
237
+ //
238
+ /**
239
+ * Tests if equals.
240
+ * @param n1
241
+ * @param n2
242
+ */
243
+ static equals = (n1, n2) => {
244
+ return n1[0] * n2[1] === n1[1] * n2[0];
245
+ };
246
+ /**
247
+ * @param {Fraction}
248
+ * True if zero.
249
+ */
250
+ static isZero = ([n]) => {
251
+ return n === 0;
252
+ };
253
+ //
254
+ // Normalization.
255
+ //
256
+ /**
257
+ * Simplify fraction finding LCDs.
258
+ * @param n
259
+ * @param d
260
+ */
261
+ static simplify = ([n, d]) => {
262
+ _FractionUtil.validate([
263
+ n,
264
+ d
265
+ ]);
266
+ if (d < 1) {
267
+ const t = n / d;
268
+ if (Math.floor(t) === t) {
269
+ n = t;
270
+ d = 1;
271
+ }
272
+ }
273
+ const fn = _FractionUtil.factors(n).reverse();
274
+ const fd = _FractionUtil.factors(d).reverse();
275
+ let c;
276
+ for (let i = 0; i < fn.length; i++) {
277
+ c = fd.find((n2) => n2 === fn[i]);
278
+ if (c) {
279
+ return [
280
+ n / c,
281
+ d / c
282
+ ];
283
+ }
284
+ }
285
+ return [
286
+ n,
287
+ d
288
+ ];
289
+ };
290
+ /**
291
+ * Return common factors.
292
+ * @param n
293
+ */
294
+ static factors = (n) => {
295
+ invariant2(Number.isFinite(n), `Invalid number: ${n}`, {
296
+ F: __dxlog_file2,
297
+ L: 113,
298
+ S: this,
299
+ A: [
300
+ "Number.isFinite(n)",
301
+ "`Invalid number: ${n}`"
302
+ ]
189
303
  });
190
- } else {
191
- obj[key] = value;
304
+ const factors = [
305
+ 1
306
+ ];
307
+ if (Number.isSafeInteger(n)) {
308
+ let f = 1;
309
+ do {
310
+ if (n % ++f === 0) {
311
+ factors.push(f);
312
+ }
313
+ } while (n / f > 1 && f < 100);
314
+ }
315
+ return factors;
316
+ };
317
+ //
318
+ // Basic arithmetic.
319
+ //
320
+ /**
321
+ * @param n1
322
+ * @param n2
323
+ */
324
+ static add = (n1, n2) => {
325
+ _FractionUtil.validate(n1, n2);
326
+ const d = n1[1] * n2[1];
327
+ const n = n1[0] * n2[1] + n2[0] * n1[1];
328
+ return _FractionUtil.simplify([
329
+ n,
330
+ d
331
+ ]);
332
+ };
333
+ /**
334
+ * @param n1
335
+ * @param n2
336
+ */
337
+ static subtract = (n1, n2) => {
338
+ _FractionUtil.validate(n1, n2);
339
+ const d = n1[1] * n2[1];
340
+ const n = n1[0] * n2[1] - n2[0] * n1[1];
341
+ return _FractionUtil.simplify([
342
+ n,
343
+ d
344
+ ]);
345
+ };
346
+ /**
347
+ * @param n1
348
+ * @param n2
349
+ */
350
+ static multiply = (n1, n2) => {
351
+ _FractionUtil.validate(n1, n2);
352
+ const n = n1[0] * n2[0];
353
+ const d = n1[1] * n2[1];
354
+ return _FractionUtil.simplify([
355
+ n,
356
+ d
357
+ ]);
358
+ };
359
+ /**
360
+ * @param n1
361
+ * @param n2
362
+ */
363
+ static divide = (n1, n2) => {
364
+ _FractionUtil.validate(n1, n2);
365
+ const n = n1[0] * n2[1];
366
+ const d = n1[1] * n2[0];
367
+ return _FractionUtil.simplify([
368
+ n,
369
+ d
370
+ ]);
371
+ };
372
+ };
373
+
374
+ // src/util/points.ts
375
+ var getCircumferencePoints = (p1, p2, r1 = 0, r2 = 0) => {
376
+ const [x1, y1] = p1;
377
+ const [x2, y2] = p2;
378
+ const theta = Math.atan2(x2 - x1, y2 - y1);
379
+ return [
380
+ [
381
+ // p1
382
+ x1 + (r1 === 0 ? 0 : r1 * Math.sin(theta)),
383
+ y1 + (r1 === 0 ? 0 : r1 * Math.cos(theta))
384
+ ],
385
+ [
386
+ // p2
387
+ x2 - (r2 === 0 ? 0 : r2 * Math.cos(Math.PI / 2 - theta)),
388
+ y2 - (r2 === 0 ? 0 : r2 * Math.sin(Math.PI / 2 - theta))
389
+ ]
390
+ ];
391
+ };
392
+ var normal = (p1, p2) => {
393
+ const dx = p2[0] - p1[0];
394
+ const dy = p2[1] - p1[1];
395
+ const len = Math.hypot(dx, dy);
396
+ return [
397
+ dy / len,
398
+ -dx / len
399
+ ];
400
+ };
401
+ var offsetPoints = (points, distance, closed) => {
402
+ const len = points.length;
403
+ const out = [];
404
+ for (let i = 0; i < len; i++) {
405
+ const p0 = points[(i - 1 + len) % len];
406
+ const p1 = points[i];
407
+ const p2 = points[(i + 1) % len];
408
+ const n1 = normal(p0, p1);
409
+ const n2 = normal(p1, p2);
410
+ const nx = (n1[0] + n2[0]) / 2;
411
+ const ny = (n1[1] + n2[1]) / 2;
412
+ const norm = Math.hypot(nx, ny) || 1;
413
+ out.push([
414
+ p1[0] + distance * nx / norm,
415
+ p1[1] + distance * ny / norm
416
+ ]);
417
+ if (!closed && (i === 0 || i === len - 1)) {
418
+ out[i] = [
419
+ p1[0] + distance * normal(p0, p1)[0],
420
+ p1[1] + distance * normal(p0, p1)[1]
421
+ ];
422
+ }
192
423
  }
193
- return obj;
194
- }
424
+ return out;
425
+ };
426
+
427
+ // src/util/scale.ts
428
+ import { zoomIdentity } from "d3";
429
+ var Scale = class {
430
+ _gridSize;
431
+ _transform;
432
+ constructor(_gridSize = 32) {
433
+ this._gridSize = _gridSize;
434
+ }
435
+ get gridSize() {
436
+ return this._gridSize;
437
+ }
438
+ get transform() {
439
+ return this._transform || zoomIdentity;
440
+ }
441
+ setTransform(transform) {
442
+ if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) {
443
+ return false;
444
+ }
445
+ this._transform = transform;
446
+ return true;
447
+ }
448
+ /**
449
+ * Translate a screen point to a logical point.
450
+ * @param point
451
+ */
452
+ translate(point) {
453
+ const { x, y, k } = this._transform ?? {
454
+ x: 0,
455
+ y: 0,
456
+ k: 1
457
+ };
458
+ return [
459
+ (point[0] - x) / k,
460
+ (point[1] - y) / k
461
+ ];
462
+ }
463
+ /**
464
+ * Map model to screen.
465
+ * Model points are represented by fractions (to preserve precision) and use normal cartesian coordinates.
466
+ */
467
+ model = {
468
+ // TODO(burdon): Precision depends on scale.
469
+ snapValues: (array) => array.map((n) => FractionUtil.round(n)),
470
+ snapVertex: ({ x, y }) => {
471
+ const [sx, sy] = this.model.snapValues([
472
+ x,
473
+ y
474
+ ]);
475
+ return {
476
+ x: sx,
477
+ y: sy
478
+ };
479
+ },
480
+ snapBounds: ({ x, y, width, height }) => {
481
+ [x, y, width, height] = this.model.snapValues([
482
+ x,
483
+ y,
484
+ width,
485
+ height
486
+ ]);
487
+ return {
488
+ x,
489
+ y,
490
+ width,
491
+ height
492
+ };
493
+ },
494
+ toValue: (value) => {
495
+ return Math.round(FractionUtil.toNumber(value) * this._gridSize);
496
+ },
497
+ toValues: (values) => {
498
+ return values.map((value) => Math.round(FractionUtil.toNumber(value) * this._gridSize));
499
+ },
500
+ toPoint: (point) => {
501
+ const [x, y] = this.model.toValues([
502
+ point.x,
503
+ point.y
504
+ ]);
505
+ return [
506
+ x,
507
+ y === 0 ? 0 : -y
508
+ ];
509
+ },
510
+ toBounds: ({ x, y, width, height }) => {
511
+ const point = this.model.toPoint({
512
+ x,
513
+ y
514
+ });
515
+ const [width2, height2] = this.model.toValues([
516
+ width,
517
+ height
518
+ ]);
519
+ return {
520
+ x: point[0],
521
+ y: point[1] - height2,
522
+ width: width2,
523
+ height: height2
524
+ };
525
+ }
526
+ };
527
+ /**
528
+ * Map screen to model.
529
+ * Screen points are represented by floating numbers and use translated SVG coordinates (with the y-axis inverted).
530
+ */
531
+ screen = {
532
+ snapValues: (array) => array.map((n) => Math.round(n / this._gridSize) * this._gridSize),
533
+ snapPoint: ([x, y]) => [
534
+ x,
535
+ y
536
+ ].map((n) => Math.round(n / this._gridSize) * this._gridSize),
537
+ snapBounds: ({ x, y, width, height }) => {
538
+ [x, y, width, height] = this.screen.snapValues([
539
+ x,
540
+ y,
541
+ width,
542
+ height
543
+ ]);
544
+ return {
545
+ x,
546
+ y,
547
+ width,
548
+ height
549
+ };
550
+ },
551
+ toValue: (value) => {
552
+ return FractionUtil.divide(FractionUtil.toFraction(value), [
553
+ this._gridSize,
554
+ 1
555
+ ]);
556
+ },
557
+ toValues: (values) => {
558
+ return values.map((value) => FractionUtil.divide(FractionUtil.toFraction(value), [
559
+ this._gridSize,
560
+ 1
561
+ ]));
562
+ },
563
+ toVertex: (point) => {
564
+ const [x, y] = point;
565
+ return {
566
+ x: FractionUtil.toFraction(x / this._gridSize),
567
+ y: FractionUtil.toFraction(-y / this._gridSize)
568
+ };
569
+ },
570
+ toBounds: (bounds) => {
571
+ const { x, y } = this.screen.toVertex([
572
+ bounds.x,
573
+ bounds.y
574
+ ]);
575
+ const [width, height] = this.screen.toValues([
576
+ bounds.width,
577
+ bounds.height
578
+ ]);
579
+ return {
580
+ x,
581
+ y: FractionUtil.subtract(y, height),
582
+ width,
583
+ height
584
+ };
585
+ }
586
+ };
587
+ };
588
+
589
+ // src/util/screen.ts
590
+ var Screen = class {
591
+ static createBounds = ([x1, y1], [x2, y2], mod = {}) => {
592
+ const { constrain, center } = mod;
593
+ const x = Math.min(x1, x2);
594
+ const y = Math.min(y1, y2);
595
+ let width = Math.abs(x2 - x1);
596
+ let height = Math.abs(y2 - y1);
597
+ if (constrain) {
598
+ width = height = Math.max(width, height);
599
+ }
600
+ if (center) {
601
+ return {
602
+ x: x - width,
603
+ y: y - height,
604
+ width: width * 2,
605
+ height: height * 2
606
+ };
607
+ } else {
608
+ return {
609
+ x,
610
+ y,
611
+ width,
612
+ height
613
+ };
614
+ }
615
+ };
616
+ static center = ({ x, y, width, height }) => {
617
+ return [
618
+ x + width / 2,
619
+ y + height / 2
620
+ ];
621
+ };
622
+ static contains = (bounds, point) => {
623
+ const [x, y] = point;
624
+ if (x < bounds.x || y < bounds.y) {
625
+ return false;
626
+ }
627
+ if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
628
+ return false;
629
+ }
630
+ return true;
631
+ };
632
+ /**
633
+ * Distance between two points.
634
+ * @param p1
635
+ * @param p2
636
+ */
637
+ static len = (p1, p2) => {
638
+ return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
639
+ };
640
+ /**
641
+ * Distance to line segment.
642
+ * https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment#1501725
643
+ * @param v1
644
+ * @param v2
645
+ * @param p
646
+ */
647
+ static normal = (v1, v2, p) => {
648
+ const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
649
+ let d;
650
+ const len2 = d2(v1, v2);
651
+ if (len2 === 0) {
652
+ d = d2(p, v1);
653
+ } else {
654
+ let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
655
+ t = Math.max(0, Math.min(1, t));
656
+ d = d2(p, [
657
+ v1[0] + t * (v2[0] - v1[0]),
658
+ v1[1] + t * (v2[1] - v1[1])
659
+ ]);
660
+ }
661
+ return Math.sqrt(d);
662
+ };
663
+ };
664
+
665
+ // src/util/vector.ts
666
+ var Vector = class {
667
+ /**
668
+ * Convert to Vertex.
669
+ * @param x
670
+ * @param y
671
+ */
672
+ static toVertex = ({ x, y }) => ({
673
+ x: FractionUtil.toFraction(x),
674
+ y: FractionUtil.toFraction(y)
675
+ });
676
+ /**
677
+ * Convert to Bounds.
678
+ * @param bounds
679
+ */
680
+ static toBounds = ({ x, y, width, height }) => ({
681
+ x: FractionUtil.toFraction(x),
682
+ y: FractionUtil.toFraction(y),
683
+ width: FractionUtil.toFraction(width),
684
+ height: FractionUtil.toFraction(height)
685
+ });
686
+ /**
687
+ * Calculate center point.
688
+ * @param bounds
689
+ */
690
+ static center = ({ x, y, width, height }) => {
691
+ const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
692
+ 1,
693
+ 2
694
+ ]));
695
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
696
+ 1,
697
+ 2
698
+ ]));
699
+ return {
700
+ x: cx,
701
+ y: cy
702
+ };
703
+ };
704
+ /**
705
+ * Calculate centered left edge.
706
+ * @param bounds
707
+ */
708
+ static left = ({ x, y, height }) => {
709
+ const cx = x;
710
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
711
+ 1,
712
+ 2
713
+ ]));
714
+ return {
715
+ x: cx,
716
+ y: cy
717
+ };
718
+ };
719
+ /**
720
+ * Calculate centered right edge.
721
+ * @param bounds
722
+ */
723
+ static right = ({ x, y, width, height }) => {
724
+ const cx = FractionUtil.add(x, width);
725
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
726
+ 1,
727
+ 2
728
+ ]));
729
+ return {
730
+ x: cx,
731
+ y: cy
732
+ };
733
+ };
734
+ };
735
+
736
+ // src/graph/projector/projector.ts
195
737
  var Projector = class {
738
+ _context;
739
+ updated = new EventEmitter();
740
+ _options;
741
+ constructor(_context, options) {
742
+ this._context = _context;
743
+ this._options = Object.assign({
744
+ idAccessor: defaultIdAccessor
745
+ }, options);
746
+ }
196
747
  get context() {
197
748
  return this._context;
198
749
  }
@@ -229,33 +780,27 @@ var Projector = class {
229
780
  }
230
781
  async onStop() {
231
782
  }
232
- constructor(_context, options) {
233
- _define_property(this, "_context", void 0);
234
- _define_property(this, "updated", void 0);
235
- _define_property(this, "_options", void 0);
236
- this._context = _context;
237
- this.updated = new EventEmitter();
238
- this._options = Object.assign({
239
- idAccessor: defaultIdAccessor
240
- }, options);
241
- }
242
783
  };
243
784
 
244
785
  // src/graph/projector/graph-projector.ts
245
- function _define_property2(obj, key, value) {
246
- if (key in obj) {
247
- Object.defineProperty(obj, key, {
248
- value,
249
- enumerable: true,
250
- configurable: true,
251
- writable: true
252
- });
253
- } else {
254
- obj[key] = value;
255
- }
256
- return obj;
257
- }
258
786
  var GraphProjector = class extends Projector {
787
+ _selection;
788
+ _layout;
789
+ // TODO(burdon): Change to object props.
790
+ constructor(context, options, _selection, layout) {
791
+ super(context, options), this._selection = _selection;
792
+ this._layout = {
793
+ id: (Math.random() * 10).toString().slice(8),
794
+ graph: {
795
+ nodes: [
796
+ ...layout?.graph.nodes ?? []
797
+ ],
798
+ edges: [
799
+ ...layout?.graph.edges ?? []
800
+ ]
801
+ }
802
+ };
803
+ }
259
804
  get layout() {
260
805
  return this._layout;
261
806
  }
@@ -301,21 +846,6 @@ var GraphProjector = class extends Projector {
301
846
  async onClear() {
302
847
  this.reset();
303
848
  }
304
- // TODO(burdon): Change to object props.
305
- constructor(context, options, _selection, layout) {
306
- super(context, options), _define_property2(this, "_selection", void 0), _define_property2(this, "_layout", void 0), this._selection = _selection;
307
- this._layout = {
308
- id: (Math.random() * 10).toString().slice(8),
309
- graph: {
310
- nodes: [
311
- ...layout?.graph.nodes ?? []
312
- ],
313
- edges: [
314
- ...layout?.graph.edges ?? []
315
- ]
316
- }
317
- };
318
- }
319
849
  };
320
850
 
321
851
  // src/graph/projector/graph-force-projector.ts
@@ -339,20 +869,7 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
339
869
  };
340
870
 
341
871
  // src/graph/projector/graph-force-projector.ts
342
- function _define_property3(obj, key, value) {
343
- if (key in obj) {
344
- Object.defineProperty(obj, key, {
345
- value,
346
- enumerable: true,
347
- configurable: true,
348
- writable: true
349
- });
350
- } else {
351
- obj[key] = value;
352
- }
353
- return obj;
354
- }
355
- var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
872
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
356
873
  var getValue = (valueOrFunction, invoker, defaultValue) => {
357
874
  return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
358
875
  };
@@ -369,6 +886,9 @@ var defaultForceOptions = {
369
886
  point: true
370
887
  };
371
888
  var GraphForceProjector = class extends GraphProjector {
889
+ // https://github.com/d3/d3-force
890
+ _simulation = forceSimulation();
891
+ _timeout;
372
892
  get forces() {
373
893
  return this.options.forces ?? defaultForceOptions;
374
894
  }
@@ -422,7 +942,7 @@ var GraphForceProjector = class extends GraphProjector {
422
942
  edges: graph?.edges.length
423
943
  }
424
944
  }, {
425
- F: __dxlog_file2,
945
+ F: __dxlog_file3,
426
946
  L: 227,
427
947
  S: this,
428
948
  C: (f, a) => f(...a)
@@ -477,7 +997,7 @@ var GraphForceProjector = class extends GraphProjector {
477
997
  log("updateForces", {
478
998
  forces
479
999
  }, {
480
- F: __dxlog_file2,
1000
+ F: __dxlog_file3,
481
1001
  L: 288,
482
1002
  S: this,
483
1003
  C: (f, a) => f(...a)
@@ -542,10 +1062,6 @@ var GraphForceProjector = class extends GraphProjector {
542
1062
  return force;
543
1063
  }));
544
1064
  }
545
- constructor(...args) {
546
- super(...args), // https://github.com/d3/d3-force
547
- _define_property3(this, "_simulation", forceSimulation()), _define_property3(this, "_timeout", void 0);
548
- }
549
1065
  };
550
1066
 
551
1067
  // src/graph/projector/graph-hierarchical-projector.ts
@@ -554,21 +1070,9 @@ import { log as log3 } from "@dxos/log";
554
1070
  // src/graph/projector/graph-radial-projector.ts
555
1071
  import { easeCubic, timer } from "d3";
556
1072
  import { log as log2 } from "@dxos/log";
557
- function _define_property4(obj, key, value) {
558
- if (key in obj) {
559
- Object.defineProperty(obj, key, {
560
- value,
561
- enumerable: true,
562
- configurable: true,
563
- writable: true
564
- });
565
- } else {
566
- obj[key] = value;
567
- }
568
- return obj;
569
- }
570
- var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
1073
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
571
1074
  var GraphRadialProjector = class extends GraphProjector {
1075
+ _timer;
572
1076
  findNode(x, y, radius) {
573
1077
  return void 0;
574
1078
  }
@@ -579,7 +1083,7 @@ var GraphRadialProjector = class extends GraphProjector {
579
1083
  edges: graph?.edges.length
580
1084
  }
581
1085
  }, {
582
- F: __dxlog_file3,
1086
+ F: __dxlog_file4,
583
1087
  L: 32,
584
1088
  S: this,
585
1089
  C: (f, a) => f(...a)
@@ -626,9 +1130,6 @@ var GraphRadialProjector = class extends GraphProjector {
626
1130
  });
627
1131
  this.animate();
628
1132
  }
629
- constructor(...args) {
630
- super(...args), _define_property4(this, "_timer", void 0);
631
- }
632
1133
  };
633
1134
  var updateNode = (node, [tx, ty], tr = 8) => {
634
1135
  const sx = node.x ?? tx;
@@ -682,7 +1183,7 @@ var layoutVertical = (x, y, h, n) => {
682
1183
  };
683
1184
 
684
1185
  // src/graph/projector/graph-hierarchical-projector.ts
685
- var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
1186
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
686
1187
  var GraphHierarchicalProjector = class extends GraphRadialProjector {
687
1188
  onUpdate(graph) {
688
1189
  log3("onUpdate", {
@@ -690,15 +1191,15 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
690
1191
  nodes: graph?.nodes.length,
691
1192
  edges: graph?.edges.length
692
1193
  },
693
- selection: this.selection?.selected.value
1194
+ selection: this.selection?.getSelectedIds()
694
1195
  }, {
695
- F: __dxlog_file4,
1196
+ F: __dxlog_file5,
696
1197
  L: 24,
697
1198
  S: this,
698
1199
  C: (f, a) => f(...a)
699
1200
  });
700
1201
  this.mergeData(graph);
701
- const selected = this.selection?.selected.value?.[0];
1202
+ const selected = this.selection?.getSelectedIds()[0];
702
1203
  if (selected) {
703
1204
  const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
704
1205
  if (node) {
@@ -745,7 +1246,7 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
745
1246
 
746
1247
  // src/graph/projector/graph-relational-projector.ts
747
1248
  import { log as log4 } from "@dxos/log";
748
- var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
1249
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
749
1250
  var GraphRelationalProjector = class extends GraphRadialProjector {
750
1251
  onUpdate(graph) {
751
1252
  log4("onUpdate", {
@@ -753,15 +1254,15 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
753
1254
  nodes: graph?.nodes.length,
754
1255
  edges: graph?.edges.length
755
1256
  },
756
- selection: this.selection?.selected.value
1257
+ selection: this.selection?.getSelectedIds()
757
1258
  }, {
758
- F: __dxlog_file5,
1259
+ F: __dxlog_file6,
759
1260
  L: 24,
760
1261
  S: this,
761
1262
  C: (f, a) => f(...a)
762
1263
  });
763
1264
  this.mergeData(graph);
764
- const selected = this.selection?.selected.value?.[0];
1265
+ const selected = this.selection?.getSelectedIds()[0];
765
1266
  if (selected) {
766
1267
  const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
767
1268
  if (node) {
@@ -868,28 +1369,25 @@ var createBullets = (group, nodeId, options = {}) => {
868
1369
  };
869
1370
 
870
1371
  // src/graph/renderer/renderer.ts
871
- import { invariant as invariant2 } from "@dxos/invariant";
872
- function _define_property5(obj, key, value) {
873
- if (key in obj) {
874
- Object.defineProperty(obj, key, {
875
- value,
876
- enumerable: true,
877
- configurable: true,
878
- writable: true
879
- });
880
- } else {
881
- obj[key] = value;
882
- }
883
- return obj;
884
- }
885
- var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
1372
+ import { invariant as invariant3 } from "@dxos/invariant";
1373
+ var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
886
1374
  var Renderer = class {
1375
+ _context;
1376
+ _root;
1377
+ _options;
1378
+ constructor(_context, _root, options) {
1379
+ this._context = _context;
1380
+ this._root = _root;
1381
+ this._options = Object.assign({
1382
+ idAccessor: defaultIdAccessor
1383
+ }, options);
1384
+ }
887
1385
  get context() {
888
1386
  return this._context;
889
1387
  }
890
1388
  get root() {
891
- invariant2(this._root.current, "SVG root is not initialized", {
892
- F: __dxlog_file6,
1389
+ invariant3(this._root.current, "SVG root is not initialized", {
1390
+ F: __dxlog_file7,
893
1391
  L: 40,
894
1392
  S: this,
895
1393
  A: [
@@ -902,25 +1400,15 @@ var Renderer = class {
902
1400
  get options() {
903
1401
  return this._options;
904
1402
  }
905
- constructor(_context, _root, options) {
906
- _define_property5(this, "_context", void 0);
907
- _define_property5(this, "_root", void 0);
908
- _define_property5(this, "_options", void 0);
909
- this._context = _context;
910
- this._root = _root;
911
- this._options = Object.assign({
912
- idAccessor: defaultIdAccessor
913
- }, options);
914
- }
915
1403
  };
916
1404
 
917
1405
  // src/graph/renderer/graph-renderer.ts
918
- var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
1406
+ var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
919
1407
  var createLine2 = line2();
920
1408
  var GraphRenderer = class extends Renderer {
921
1409
  render(layout) {
922
1410
  log5("render", layout, {
923
- F: __dxlog_file7,
1411
+ F: __dxlog_file8,
924
1412
  L: 63,
925
1413
  S: this,
926
1414
  C: (f, a) => f(...a)
@@ -1068,7 +1556,7 @@ var updateNode2 = (group, options) => {
1068
1556
  log5.error("updateNode", {
1069
1557
  error: error?.message
1070
1558
  }, {
1071
- F: __dxlog_file7,
1559
+ F: __dxlog_file8,
1072
1560
  L: 305,
1073
1561
  S: void 0,
1074
1562
  C: (f, a) => f(...a)
@@ -1124,7 +1612,7 @@ var updateEdge = (group, options, nodeGroup) => {
1124
1612
  log5.error("updateEdge", {
1125
1613
  error: error?.message
1126
1614
  }, {
1127
- F: __dxlog_file7,
1615
+ F: __dxlog_file8,
1128
1616
  L: 417,
1129
1617
  S: void 0,
1130
1618
  C: (f, a) => f(...a)
@@ -1206,112 +1694,427 @@ var linkerRenderer = (root, { source, target, point } = {}) => {
1206
1694
  });
1207
1695
  };
1208
1696
 
1697
+ // src/hooks/useGrid.ts
1698
+ import { line as line4, range, select as select5 } from "d3";
1699
+ import { useEffect, useMemo, useRef } from "react";
1700
+
1701
+ // src/hooks/useSvgContext.ts
1702
+ import { createContext, useContext } from "react";
1703
+ import { createRef } from "react";
1704
+ import { raise } from "@dxos/debug";
1705
+ var SVGContext = class {
1706
+ _ref = createRef();
1707
+ _scale;
1708
+ _centered;
1709
+ _size;
1710
+ _center;
1711
+ resized = new EventEmitter();
1712
+ constructor({ scale = new Scale(), centered = true }) {
1713
+ this._scale = scale;
1714
+ this._centered = centered;
1715
+ }
1716
+ get ref() {
1717
+ return this._ref;
1718
+ }
1719
+ get svg() {
1720
+ return this._ref.current;
1721
+ }
1722
+ get scale() {
1723
+ return this._scale;
1724
+ }
1725
+ get center() {
1726
+ return this._center;
1727
+ }
1728
+ get size() {
1729
+ return this._size;
1730
+ }
1731
+ /**
1732
+ * https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
1733
+ */
1734
+ get viewBox() {
1735
+ const [x, y] = this.center;
1736
+ return `${x},${y},${this._size.width},${this._size.height}`;
1737
+ }
1738
+ setSize(size) {
1739
+ this._size = {
1740
+ ...size
1741
+ };
1742
+ this._center = this._centered ? [
1743
+ -Math.floor(size.width / 2),
1744
+ -Math.floor(size.height / 2)
1745
+ ] : [
1746
+ 0,
1747
+ 0
1748
+ ];
1749
+ this.resized.emit(this);
1750
+ }
1751
+ setTransform(transform) {
1752
+ if (this._scale.setTransform(transform)) {
1753
+ this.resized.emit(this);
1754
+ }
1755
+ }
1756
+ /**
1757
+ * https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint
1758
+ * @param point
1759
+ */
1760
+ elementFromPoint(point) {
1761
+ const [x, y] = point;
1762
+ const [cx, cy] = this._center;
1763
+ return document.elementFromPoint(cx + x, cy + y);
1764
+ }
1765
+ };
1766
+ var SVGContextType = createContext(void 0);
1767
+ var SVGContextProvider = SVGContextType.Provider;
1768
+ var useSvgContext = () => {
1769
+ return useContext(SVGContextType) ?? raise(new Error("Missing SVGRoot"));
1770
+ };
1771
+
1772
+ // src/hooks/useGrid.ts
1773
+ var createLine4 = line4();
1774
+ var createGrid = (context, options) => {
1775
+ if (!context.size) {
1776
+ return [];
1777
+ }
1778
+ const paths = [];
1779
+ const { width, height } = context.size;
1780
+ const { x, y, k } = context.scale.transform;
1781
+ const s = 1 / k;
1782
+ const w = width * s;
1783
+ const h = height * s;
1784
+ const dx = -(x + width / 2) * s;
1785
+ const dy = -(y + height / 2) * s;
1786
+ if (options.axis) {
1787
+ const axis = [
1788
+ [
1789
+ [
1790
+ 0,
1791
+ dy
1792
+ ],
1793
+ [
1794
+ 0,
1795
+ dy + h
1796
+ ]
1797
+ ],
1798
+ [
1799
+ [
1800
+ dx,
1801
+ 0
1802
+ ],
1803
+ [
1804
+ dx + w,
1805
+ 0
1806
+ ]
1807
+ ]
1808
+ ];
1809
+ paths.push({
1810
+ id: "axis",
1811
+ class: "dx-axis",
1812
+ path: axis.map((line5) => createLine4(line5)).join()
1813
+ });
1814
+ }
1815
+ if (options.grid) {
1816
+ const mod = (n, size, delta = 0) => Math.floor(n / size + delta) * size;
1817
+ const majorSize = context.scale.gridSize;
1818
+ const xMajor = range(-mod((x + width / 2) * s, majorSize), mod((-x + width / 2) * s, majorSize, 1), majorSize);
1819
+ const yMajor = range(-mod((y + height / 2) * s, majorSize), mod((-y + height / 2) * s, majorSize, 1), majorSize);
1820
+ const major = [
1821
+ ...xMajor.filter((x2) => !options.axis || x2).map((x2) => [
1822
+ [
1823
+ x2,
1824
+ dy
1825
+ ],
1826
+ [
1827
+ x2,
1828
+ dy + h
1829
+ ]
1830
+ ]),
1831
+ ...yMajor.filter((y2) => !options.axis || y2).map((y2) => [
1832
+ [
1833
+ dx,
1834
+ y2
1835
+ ],
1836
+ [
1837
+ dx + w,
1838
+ y2
1839
+ ]
1840
+ ])
1841
+ ];
1842
+ paths.push({
1843
+ id: "major",
1844
+ class: "dx-major",
1845
+ path: major.map((line5) => createLine4(line5)).join()
1846
+ });
1847
+ const minorSize = Math.pow(2, Math.round(Math.log2(s * context.scale.gridSize)));
1848
+ if (majorSize > minorSize) {
1849
+ const xMinor = range(-mod((x + width / 2) * s, minorSize), mod((-x + width / 2) * s, minorSize, 1), minorSize);
1850
+ const yMinor = range(-mod((y + height / 2) * s, minorSize), mod((-y + height / 2) * s, minorSize, 1), minorSize);
1851
+ const minor = [
1852
+ ...xMinor.filter((x2) => xMajor.indexOf(x2) === -1).map((x2) => [
1853
+ [
1854
+ x2,
1855
+ dy
1856
+ ],
1857
+ [
1858
+ x2,
1859
+ dy + h
1860
+ ]
1861
+ ]),
1862
+ ...yMinor.filter((y2) => yMajor.indexOf(y2) === -1).map((y2) => [
1863
+ [
1864
+ dx,
1865
+ y2
1866
+ ],
1867
+ [
1868
+ dx + w,
1869
+ y2
1870
+ ]
1871
+ ])
1872
+ ];
1873
+ paths.push({
1874
+ id: "minor",
1875
+ class: "dx-minor",
1876
+ path: minor.map((line5) => createLine4(line5)).join()
1877
+ });
1878
+ }
1879
+ }
1880
+ return paths;
1881
+ };
1882
+ var defaultGridOptions = {
1883
+ visible: true,
1884
+ axis: true,
1885
+ grid: true
1886
+ };
1887
+ var GridController = class {
1888
+ _ref;
1889
+ _context;
1890
+ _options;
1891
+ _visible = false;
1892
+ constructor(_ref, _context, _options) {
1893
+ this._ref = _ref;
1894
+ this._context = _context;
1895
+ this._options = _options;
1896
+ this._visible = this._options.visible ?? true;
1897
+ }
1898
+ get ref() {
1899
+ return this._ref;
1900
+ }
1901
+ get visible() {
1902
+ return this._visible;
1903
+ }
1904
+ draw() {
1905
+ if (!this._context.size) {
1906
+ return;
1907
+ }
1908
+ const paths = this._visible ? createGrid(this._context, this._options) : [];
1909
+ const root = select5(this._ref.current);
1910
+ root.selectAll("path").data(paths, (path) => path.id).join("path").style("pointer-events", "none").attr("d", (d) => d.path).attr("class", (d) => d.class);
1911
+ const transform = this._context.scale.transform;
1912
+ if (transform) {
1913
+ root.attr("transform", transform);
1914
+ root.attr("stroke-width", 1 / transform.k);
1915
+ }
1916
+ }
1917
+ setVisible(visible) {
1918
+ this._visible = visible;
1919
+ this.draw();
1920
+ return this;
1921
+ }
1922
+ };
1923
+ var useGrid = (options = defaultGridOptions) => {
1924
+ const ref = useRef(null);
1925
+ const context = useSvgContext();
1926
+ const controller = useMemo(() => new GridController(ref, context, options), []);
1927
+ useEffect(() => context.resized.on(() => controller.draw()), [
1928
+ context,
1929
+ controller
1930
+ ]);
1931
+ return controller;
1932
+ };
1933
+
1934
+ // src/hooks/useZoom.ts
1935
+ import { select as select6, zoom, zoomIdentity as zoomIdentity2 } from "d3";
1936
+ import defaultsDeep from "lodash.defaultsdeep";
1937
+ import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
1938
+ var defaultZoomOptions = {
1939
+ enabled: true,
1940
+ extent: [
1941
+ 1 / 4,
1942
+ 4
1943
+ ],
1944
+ onDblClick: (zoom2) => zoom2.reset()
1945
+ };
1946
+ var ZoomHandler = class {
1947
+ _ref;
1948
+ _context;
1949
+ _zoom;
1950
+ _options;
1951
+ _enabled;
1952
+ constructor(_ref, _context, options) {
1953
+ this._ref = _ref;
1954
+ this._context = _context;
1955
+ this._options = defaultsDeep({}, options, defaultZoomOptions);
1956
+ this._enabled = this._options.enabled ?? true;
1957
+ this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
1958
+ }
1959
+ /**
1960
+ * Gets the reference which the transform is applied to.
1961
+ */
1962
+ get ref() {
1963
+ return this._ref;
1964
+ }
1965
+ get zoom() {
1966
+ return this._zoom;
1967
+ }
1968
+ init() {
1969
+ this.setEnabled(this._enabled);
1970
+ this.reset(0);
1971
+ return this;
1972
+ }
1973
+ setEnabled(enable) {
1974
+ if (enable) {
1975
+ select6(this._context.svg).call(this._zoom).on(
1976
+ "dblclick.zoom",
1977
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1978
+ // @ts-ignore
1979
+ this._options?.onDblClick ? () => {
1980
+ this._options?.onDblClick(this);
1981
+ } : null
1982
+ );
1983
+ } else {
1984
+ select6(this._context.svg).on(".zoom", null);
1985
+ }
1986
+ this._enabled = enable;
1987
+ return this;
1988
+ }
1989
+ reset(duration = 500) {
1990
+ const scale = 1;
1991
+ const transform = zoomIdentity2.scale(scale);
1992
+ select6(this._context.svg).transition().duration(duration).call(this._zoom.transform, transform);
1993
+ return this;
1994
+ }
1995
+ };
1996
+ var useZoom = (options = defaultZoomOptions) => {
1997
+ const context = useSvgContext();
1998
+ const ref = useRef2(null);
1999
+ const handler = useMemo2(() => new ZoomHandler(ref, context, options), [
2000
+ context,
2001
+ options
2002
+ ]);
2003
+ useEffect2(() => {
2004
+ handler.zoom.on("zoom", ({ transform }) => {
2005
+ context.setTransform(transform);
2006
+ select6(ref.current).attr("transform", transform);
2007
+ });
2008
+ handler.init();
2009
+ }, [
2010
+ handler
2011
+ ]);
2012
+ return handler;
2013
+ };
2014
+
1209
2015
  // src/components/Graph/Graph.tsx
1210
- var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
1211
- var GraphInner = ({ classNames, model, projector: _projector, renderer: _renderer, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
1212
- var _effect = _useSignals();
1213
- try {
1214
- const context = useSvgContext();
1215
- const graphRef = useRef(null);
1216
- const { projector, renderer } = useMemo(() => {
1217
- let projector2 = _projector;
1218
- if (!projector2) {
1219
- projector2 = new GraphForceProjector(context);
1220
- }
1221
- let renderer2 = _renderer;
1222
- if (!renderer2) {
1223
- renderer2 = new GraphRenderer(context, graphRef, {
1224
- ...props,
1225
- // TODO(burdon): Replace drag when projector is updated.
1226
- drag: drag2 ? createGraphDrag(context, projector2) : void 0,
1227
- arrows: {
1228
- end: arrows
1229
- },
1230
- onNodeClick: onSelect ? (node, event) => onSelect(node, event) : void 0,
1231
- onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0
2016
+ var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
2017
+ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
2018
+ const context = useSvgContext();
2019
+ const graphRef = useRef3(null);
2020
+ const { projector, renderer } = useMemo3(() => {
2021
+ let projector2 = projectorProp;
2022
+ if (!projector2) {
2023
+ projector2 = new GraphForceProjector(context);
2024
+ }
2025
+ let renderer2 = rendererProp;
2026
+ if (!renderer2) {
2027
+ renderer2 = new GraphRenderer(context, graphRef, {
2028
+ ...props,
2029
+ // TODO(burdon): Replace drag when projector is updated.
2030
+ drag: drag2 ? createGraphDrag(context, projector2) : void 0,
2031
+ arrows: {
2032
+ end: arrows
2033
+ },
2034
+ onNodeClick: onSelect ? (node, event) => onSelect(node, event) : void 0,
2035
+ onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0
2036
+ });
2037
+ }
2038
+ return {
2039
+ projector: projector2,
2040
+ renderer: renderer2
2041
+ };
2042
+ }, [
2043
+ context,
2044
+ projectorProp,
2045
+ rendererProp,
2046
+ drag2
2047
+ ]);
2048
+ useImperativeHandle(forwardedRef, () => ({
2049
+ refresh: () => {
2050
+ projector.updateData(model?.graph);
2051
+ },
2052
+ repaint: () => {
2053
+ renderer.render(projector.layout);
2054
+ },
2055
+ findNode: (id) => {
2056
+ return graphRef.current?.querySelector(`g[data-id="${id}"]`);
2057
+ }
2058
+ }), [
2059
+ model,
2060
+ projector,
2061
+ renderer
2062
+ ]);
2063
+ useEffect3(() => {
2064
+ projector.updateData(model?.graph);
2065
+ const unsubscribeModel = model && "subscribe" in model ? model.subscribe(() => {
2066
+ projector.updateData(model?.graph);
2067
+ }) : void 0;
2068
+ return combine(unsubscribeModel, projector.updated.on(({ layout }) => {
2069
+ try {
2070
+ renderer.render(layout);
2071
+ } catch (error) {
2072
+ void projector.stop();
2073
+ log6.catch(error, void 0, {
2074
+ F: __dxlog_file9,
2075
+ L: 115,
2076
+ S: void 0,
2077
+ C: (f, a) => f(...a)
1232
2078
  });
1233
2079
  }
1234
- return {
1235
- projector: projector2,
1236
- renderer: renderer2
1237
- };
1238
- }, [
1239
- context,
1240
- _projector,
1241
- _renderer,
1242
- drag2
1243
- ]);
1244
- useImperativeHandle(forwardedRef, () => ({
1245
- refresh: () => {
1246
- projector.updateData(model?.graph);
1247
- },
1248
- repaint: () => {
1249
- renderer.render(projector.layout);
1250
- },
1251
- findNode: (id) => {
1252
- return graphRef.current?.querySelector(`g[data-id="${id}"]`);
1253
- }
1254
- }), [
1255
- model,
1256
- projector,
1257
- renderer
1258
- ]);
1259
- useEffect(() => {
1260
- return combine(effect(() => {
1261
- projector.updateData(model?.graph);
1262
- }), projector.updated.on(({ layout }) => {
1263
- try {
1264
- renderer.render(layout);
1265
- } catch (error) {
1266
- void projector.stop();
1267
- log6.catch(error, void 0, {
1268
- F: __dxlog_file8,
1269
- L: 108,
1270
- S: void 0,
1271
- C: (f, a) => f(...a)
1272
- });
1273
- }
1274
- }));
1275
- }, [
1276
- model,
1277
- projector,
1278
- renderer
1279
- ]);
1280
- useEffect(() => {
1281
- void projector.start();
1282
- return () => {
1283
- void projector.stop();
1284
- };
1285
- }, [
1286
- projector
1287
- ]);
1288
- return /* @__PURE__ */ React.createElement("g", {
1289
- ref: graphRef,
1290
- className: mx("dx-graph", classNames)
1291
- });
1292
- } finally {
1293
- _effect.f();
1294
- }
2080
+ }));
2081
+ }, [
2082
+ model,
2083
+ projector,
2084
+ renderer
2085
+ ]);
2086
+ useEffect3(() => {
2087
+ void projector.start();
2088
+ return () => {
2089
+ void projector.stop();
2090
+ };
2091
+ }, [
2092
+ projector
2093
+ ]);
2094
+ return /* @__PURE__ */ React.createElement("g", {
2095
+ ref: graphRef,
2096
+ className: mx("dx-graph", classNames)
2097
+ });
1295
2098
  };
1296
2099
  var Graph = /* @__PURE__ */ forwardRef(GraphInner);
1297
2100
 
1298
2101
  // src/components/Mesh/Mesh.tsx
1299
- import { geoPath, select as select5 } from "d3";
1300
- import { useEffect as useEffect2 } from "react";
2102
+ import { geoPath, select as select7 } from "d3";
2103
+ import { useEffect as useEffect4 } from "react";
1301
2104
  import { feature, mesh } from "topojson-client";
1302
2105
  var Mesh = ({ radius = 16, value = 0.5 }) => {
1303
2106
  const { svg, size } = useSvgContext();
1304
- useEffect2(() => {
2107
+ useEffect4(() => {
1305
2108
  if (size) {
1306
2109
  const topology = hexTopology(size, radius, value);
1307
2110
  const projection = hexProjection(radius);
1308
2111
  const path = geoPath().projection(projection);
1309
- select5(svg).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);
1310
- select5(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
2112
+ select7(svg).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);
2113
+ select7(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
1311
2114
  const redraw = (border) => {
1312
2115
  border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
1313
2116
  };
1314
- select5(svg).append("path").attr("class", "border").call(redraw);
2117
+ select7(svg).append("path").attr("class", "border").call(redraw);
1315
2118
  }
1316
2119
  }, [
1317
2120
  svg,
@@ -1428,115 +2231,95 @@ var hexProjection = (radius) => {
1428
2231
  };
1429
2232
 
1430
2233
  // src/components/SVG/Grid.tsx
1431
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
1432
2234
  import React2 from "react";
1433
- import { mx as mx2 } from "@dxos/react-ui-theme";
2235
+ import { mx as mx2 } from "@dxos/ui-theme";
1434
2236
  var Grid = ({ classNames, ...props }) => {
1435
- var _effect = _useSignals2();
1436
- try {
1437
- const { ref } = useGrid(props);
1438
- return /* @__PURE__ */ React2.createElement("g", {
1439
- ref,
1440
- className: mx2("dx-grid", classNames)
1441
- });
1442
- } finally {
1443
- _effect.f();
1444
- }
2237
+ const { ref } = useGrid(props);
2238
+ return /* @__PURE__ */ React2.createElement("g", {
2239
+ ref,
2240
+ className: mx2("dx-grid", classNames)
2241
+ });
1445
2242
  };
1446
2243
 
1447
2244
  // src/components/SVG/Markers.tsx
1448
- import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
1449
- import { select as select6 } from "d3";
1450
- import React3, { useEffect as useEffect3, useRef as useRef2 } from "react";
2245
+ import { select as select8 } from "d3";
2246
+ import React3, { useEffect as useEffect5, useRef as useRef4 } from "react";
1451
2247
  var Markers = ({ arrowSize, className }) => {
1452
- var _effect = _useSignals3();
1453
- try {
1454
- const ref = useRef2(null);
1455
- useEffect3(() => {
1456
- select6(ref.current).call(createMarkers({
1457
- arrowSize
1458
- }));
1459
- }, [
1460
- ref
1461
- ]);
1462
- return /* @__PURE__ */ React3.createElement("defs", {
1463
- ref,
1464
- className
1465
- });
1466
- } finally {
1467
- _effect.f();
1468
- }
2248
+ const ref = useRef4(null);
2249
+ useEffect5(() => {
2250
+ select8(ref.current).call(createMarkers({
2251
+ arrowSize
2252
+ }));
2253
+ }, [
2254
+ ref
2255
+ ]);
2256
+ return /* @__PURE__ */ React3.createElement("defs", {
2257
+ ref,
2258
+ className
2259
+ });
1469
2260
  };
1470
2261
 
1471
2262
  // src/components/SVG/Root.tsx
1472
- import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
1473
- import { select as select7 } from "d3";
1474
- import React4, { forwardRef as forwardRef2, useEffect as useEffect4, useImperativeHandle as useImperativeHandle2, useMemo as useMemo2 } from "react";
2263
+ import { select as select9 } from "d3";
2264
+ import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4 } from "react";
1475
2265
  import { useResizeDetector } from "react-resize-detector";
1476
- import { mx as mx3 } from "@dxos/react-ui-theme";
1477
- var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, ...props }, ref) => {
1478
- var _effect = _useSignals4();
1479
- try {
1480
- const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
1481
- refreshRate: 200
2266
+ import { mx as mx3 } from "@dxos/ui-theme";
2267
+ var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, scale, centered, ...props }, ref) => {
2268
+ const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
2269
+ refreshRate: 200
2270
+ });
2271
+ const context = useMemo4(() => {
2272
+ return new SVGContext({
2273
+ scale,
2274
+ centered
1482
2275
  });
1483
- const context = useMemo2(() => {
1484
- return new SVGContext(props);
1485
- }, [
1486
- props.scale,
1487
- props.centered
1488
- ]);
1489
- useImperativeHandle2(ref, () => context, [
1490
- context
1491
- ]);
1492
- useEffect4(() => {
1493
- if (width && height) {
1494
- context.setSize({
1495
- width,
1496
- height
1497
- });
1498
- select7(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
1499
- }
1500
- }, [
1501
- context,
1502
- width,
1503
- height
1504
- ]);
1505
- const ready = width !== 0 && height !== 0;
1506
- return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
1507
- value: context
1508
- }, /* @__PURE__ */ React4.createElement("div", {
1509
- ref: containerRef,
1510
- className: mx3("grid grow overflow-hidden", classNames)
1511
- }, /* @__PURE__ */ React4.createElement("svg", {
1512
- xmlns: "http://www.w3.org/2000/svg",
1513
- ref: context.ref,
1514
- className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
1515
- }, ready && children)));
1516
- } finally {
1517
- _effect.f();
1518
- }
2276
+ }, [
2277
+ scale,
2278
+ centered
2279
+ ]);
2280
+ useImperativeHandle2(ref, () => context, [
2281
+ context
2282
+ ]);
2283
+ useEffect6(() => {
2284
+ if (width && height) {
2285
+ context.setSize({
2286
+ width,
2287
+ height
2288
+ });
2289
+ select9(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
2290
+ }
2291
+ }, [
2292
+ context,
2293
+ width,
2294
+ height
2295
+ ]);
2296
+ const ready = width !== 0 && height !== 0;
2297
+ return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
2298
+ value: context
2299
+ }, /* @__PURE__ */ React4.createElement("div", {
2300
+ ...props,
2301
+ ref: containerRef,
2302
+ className: mx3("grid grow overflow-hidden", classNames)
2303
+ }, /* @__PURE__ */ React4.createElement("svg", {
2304
+ xmlns: "http://www.w3.org/2000/svg",
2305
+ ref: context.ref,
2306
+ className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
2307
+ }, ready && children)));
1519
2308
  });
1520
2309
 
1521
2310
  // src/components/SVG/Zoom.tsx
1522
- import { useSignals as _useSignals5 } from "@preact-signals/safe-react/tracking";
1523
- import React5, { memo, useMemo as useMemo3 } from "react";
2311
+ import React5, { memo, useMemo as useMemo5 } from "react";
1524
2312
  var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
1525
- var _effect = _useSignals5();
1526
- try {
1527
- const options = useMemo3(() => ({
1528
- extent
1529
- }), [
1530
- JSON.stringify(extent)
1531
- ]);
1532
- const zoom = useZoom(options);
1533
- return /* @__PURE__ */ React5.createElement("g", {
1534
- ref: zoom.ref,
1535
- className
1536
- }, children);
1537
- } finally {
1538
- _effect.f();
1539
- }
2313
+ const options = useMemo5(() => ({
2314
+ extent
2315
+ }), [
2316
+ JSON.stringify(extent)
2317
+ ]);
2318
+ const zoom2 = useZoom(options);
2319
+ return /* @__PURE__ */ React5.createElement("g", {
2320
+ ref: zoom2.ref,
2321
+ className
2322
+ }, children);
1540
2323
  });
1541
2324
 
1542
2325
  // src/components/SVG/SVG.tsx
@@ -1550,7 +2333,7 @@ var SVG = {
1550
2333
  };
1551
2334
 
1552
2335
  // src/fx/pulsar.ts
1553
- import { easeCubicOut as easeCubicOut2, select as select8 } from "d3";
2336
+ import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
1554
2337
  var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
1555
2338
  (function(Pulsar2) {
1556
2339
  Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
@@ -1565,10 +2348,10 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
1565
2348
  var startAnimation = (pulsar, r, options = {}) => {
1566
2349
  const { period = 1e3, duration = 800, ratio = 3 } = options;
1567
2350
  return pulsar.attr("r", r).attr("opacity", 1).transition("pulsar").delay(period - Date.now() % period).duration(Math.min(duration, period - 20)).ease(easeCubicOut2).attr("r", r * ratio).attr("opacity", -0.1).on("end", function() {
1568
- if (select8(this).property(PROP_PULSAR_ACTIVE)) {
1569
- startAnimation(select8(this), r, options);
2351
+ if (select10(this).property(PROP_PULSAR_ACTIVE)) {
2352
+ startAnimation(select10(this), r, options);
1570
2353
  } else {
1571
- select8(this).remove();
2354
+ select10(this).remove();
1572
2355
  }
1573
2356
  });
1574
2357
  };
@@ -1579,7 +2362,6 @@ export {
1579
2362
  Graph,
1580
2363
  GraphForceProjector,
1581
2364
  GraphHierarchicalProjector,
1582
- GraphInner,
1583
2365
  GraphProjector,
1584
2366
  GraphRadialProjector,
1585
2367
  GraphRelationalProjector,