@dxos/react-ui-graph 0.8.4-main.d05673bc65 → 0.8.4-main.d9fc60f731

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 (125) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/browser/{chunk-LKC455GK.mjs → chunk-EASNZZ7B.mjs} +1 -1
  3. package/dist/lib/browser/{chunk-LKC455GK.mjs.map → chunk-EASNZZ7B.mjs.map} +2 -2
  4. package/dist/lib/browser/index.mjs +1787 -499
  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 +14 -14
  8. package/dist/lib/browser/testing/index.mjs.map +3 -3
  9. package/dist/lib/node-esm/{chunk-JE4KZCUF.mjs → chunk-JSE2X4ML.mjs} +1 -1
  10. package/dist/lib/node-esm/{chunk-JE4KZCUF.mjs.map → chunk-JSE2X4ML.mjs.map} +2 -2
  11. package/dist/lib/node-esm/index.mjs +1787 -499
  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 +14 -14
  15. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  16. package/dist/types/src/components/Graph/Graph.d.ts +22 -4
  17. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  18. package/dist/types/src/components/Graph/Graph.stories.d.ts +5 -5
  19. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/Mesh/Mesh.d.ts.map +1 -1
  21. package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
  22. package/dist/types/src/components/SVG/FPS.d.ts +20 -0
  23. package/dist/types/src/components/SVG/FPS.d.ts.map +1 -0
  24. package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
  25. package/dist/types/src/components/SVG/Markers.d.ts.map +1 -1
  26. package/dist/types/src/components/SVG/Root.d.ts +5 -1
  27. package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
  28. package/dist/types/src/components/SVG/SVG.d.ts +3 -1
  29. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  30. package/dist/types/src/components/SVG/Svg.stories.d.ts +1 -1
  31. package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
  32. package/dist/types/src/fx/fx.stories.d.ts +3 -3
  33. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  34. package/dist/types/src/fx/pulsar.d.ts.map +1 -1
  35. package/dist/types/src/graph/markers.d.ts.map +1 -1
  36. package/dist/types/src/graph/projector/graph-bundle-projector.d.ts +47 -0
  37. package/dist/types/src/graph/projector/graph-bundle-projector.d.ts.map +1 -0
  38. package/dist/types/src/graph/projector/graph-cluster-projector.d.ts +65 -0
  39. package/dist/types/src/graph/projector/graph-cluster-projector.d.ts.map +1 -0
  40. package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
  41. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  42. package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
  43. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
  44. package/dist/types/src/graph/projector/graph-lattice-projector.d.ts +23 -0
  45. package/dist/types/src/graph/projector/graph-lattice-projector.d.ts.map +1 -0
  46. package/dist/types/src/graph/projector/graph-plexus-projector.d.ts +67 -0
  47. package/dist/types/src/graph/projector/graph-plexus-projector.d.ts.map +1 -0
  48. package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts +2 -0
  49. package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts.map +1 -0
  50. package/dist/types/src/graph/projector/graph-projector.d.ts +8 -0
  51. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  52. package/dist/types/src/graph/projector/graph-radial-projector.d.ts +6 -0
  53. package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
  54. package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
  55. package/dist/types/src/graph/projector/graph-swarm-projector.d.ts +72 -0
  56. package/dist/types/src/graph/projector/graph-swarm-projector.d.ts.map +1 -0
  57. package/dist/types/src/graph/projector/index.d.ts +5 -0
  58. package/dist/types/src/graph/projector/index.d.ts.map +1 -1
  59. package/dist/types/src/graph/projector/projector.d.ts +10 -1
  60. package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
  61. package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
  62. package/dist/types/src/graph/renderer/graph-renderer.d.ts +41 -1
  63. package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
  64. package/dist/types/src/graph/renderer/index.d.ts +1 -0
  65. package/dist/types/src/graph/renderer/index.d.ts.map +1 -1
  66. package/dist/types/src/graph/renderer/labels.d.ts +33 -0
  67. package/dist/types/src/graph/renderer/labels.d.ts.map +1 -0
  68. package/dist/types/src/graph/renderer/renderer.d.ts +12 -1
  69. package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
  70. package/dist/types/src/graph/types.d.ts +14 -0
  71. package/dist/types/src/graph/types.d.ts.map +1 -1
  72. package/dist/types/src/hooks/useGrid.d.ts.map +1 -1
  73. package/dist/types/src/hooks/useStateRef.d.ts.map +1 -1
  74. package/dist/types/src/hooks/useSvgContext.d.ts.map +1 -1
  75. package/dist/types/src/hooks/useZoom.d.ts.map +1 -1
  76. package/dist/types/src/stories/experimental.stories.d.ts +7 -0
  77. package/dist/types/src/stories/experimental.stories.d.ts.map +1 -0
  78. package/dist/types/src/stories/hooks.stories.d.ts +1 -1
  79. package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
  80. package/dist/types/src/testing/data.d.ts +1 -1
  81. package/dist/types/src/testing/data.d.ts.map +1 -1
  82. package/dist/types/src/testing/hooks.d.ts.map +1 -1
  83. package/dist/types/src/testing/model.d.ts.map +1 -1
  84. package/dist/types/src/util/events.d.ts.map +1 -1
  85. package/dist/types/src/util/fraction.d.ts.map +1 -1
  86. package/dist/types/src/util/points.d.ts.map +1 -1
  87. package/dist/types/src/util/scale.d.ts.map +1 -1
  88. package/dist/types/src/util/screen.d.ts.map +1 -1
  89. package/dist/types/src/util/vector.d.ts.map +1 -1
  90. package/dist/types/tsconfig.tsbuildinfo +1 -1
  91. package/package.json +19 -26
  92. package/src/components/Graph/Graph.stories.tsx +21 -19
  93. package/src/components/Graph/Graph.tsx +115 -19
  94. package/src/components/Mesh/Mesh.stories.tsx +6 -5
  95. package/src/components/Mesh/Mesh.tsx +43 -35
  96. package/src/components/SVG/FPS.tsx +91 -0
  97. package/src/components/SVG/Root.tsx +30 -4
  98. package/src/components/SVG/SVG.tsx +4 -2
  99. package/src/components/SVG/Svg.stories.tsx +2 -3
  100. package/src/fx/fx.stories.tsx +5 -6
  101. package/src/graph/projector/graph-bundle-projector.ts +210 -0
  102. package/src/graph/projector/graph-cluster-projector.ts +337 -0
  103. package/src/graph/projector/graph-drag.ts +0 -1
  104. package/src/graph/projector/graph-force-projector.ts +6 -2
  105. package/src/graph/projector/graph-hierarchical-projector.ts +1 -1
  106. package/src/graph/projector/graph-lattice-projector.ts +86 -0
  107. package/src/graph/projector/graph-plexus-projector.test.ts +102 -0
  108. package/src/graph/projector/graph-plexus-projector.ts +309 -0
  109. package/src/graph/projector/graph-projector.ts +22 -2
  110. package/src/graph/projector/graph-radial-projector.ts +30 -3
  111. package/src/graph/projector/graph-relational-projector.ts +1 -1
  112. package/src/graph/projector/graph-swarm-projector.ts +373 -0
  113. package/src/graph/projector/index.ts +5 -0
  114. package/src/graph/projector/projector.ts +12 -3
  115. package/src/graph/renderer/graph-renderer.ts +289 -31
  116. package/src/graph/renderer/index.ts +1 -0
  117. package/src/graph/renderer/labels.ts +138 -0
  118. package/src/graph/renderer/renderer.ts +15 -4
  119. package/src/graph/types.ts +14 -0
  120. package/src/stories/experimental.stories.tsx +446 -0
  121. package/src/stories/hooks.stories.tsx +8 -3
  122. package/src/testing/data.ts +9 -9
  123. package/src/testing/hooks.ts +2 -3
  124. package/src/testing/model.ts +3 -3
  125. package/styles/graph.css +52 -3
@@ -3,12 +3,12 @@ import {
3
3
  useDynamicRef,
4
4
  useStateRef,
5
5
  useTimestamp
6
- } from "./chunk-JE4KZCUF.mjs";
6
+ } from "./chunk-JSE2X4ML.mjs";
7
7
 
8
8
  // src/components/Graph/Graph.tsx
9
9
  import React, { forwardRef, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo3, useRef as useRef3 } from "react";
10
10
  import { combine } from "@dxos/async";
11
- import { log as log6 } from "@dxos/log";
11
+ import { log as log11 } from "@dxos/log";
12
12
  import { mx } from "@dxos/ui-theme";
13
13
 
14
14
  // src/graph/markers.ts
@@ -62,99 +62,19 @@ var createMarkers = ({ arrowSize = 12 } = {}) => (group) => {
62
62
  });
63
63
  };
64
64
 
65
- // src/graph/projector/graph-drag.ts
66
- import { drag, pointer, select as select2 } from "d3";
67
- var defaultDragOptions = {
68
- linkMod: "metaKey",
69
- freezeMod: "shiftKey"
70
- };
71
- var createGraphDrag = (context, projector, options = defaultDragOptions) => {
72
- let mode;
73
- let source;
74
- let target;
75
- let offset;
76
- let moved = false;
77
- const keyMod = (event, key) => {
78
- const modKey = options?.[key] ?? defaultDragOptions[key];
79
- return modKey === void 0 || event[modKey];
80
- };
81
- return drag().filter((event) => !event.ctrlKey).on("start", function(event, d) {
82
- source = d;
83
- offset = pointer(event, this.parentElement);
84
- if (options?.onDrop && keyMod(event.sourceEvent, "linkMod")) {
85
- mode = 1;
86
- } else if (keyMod(event.sourceEvent, "dragMod")) {
87
- mode = 0;
88
- }
89
- }).on("drag", function(event, d) {
90
- const parent = this.closest("g.node");
91
- select2(parent).classed("dragging", true).raise();
92
- const [dx, dy] = pointer(event, this.parentElement);
93
- const x = d.x + dx - offset[0];
94
- const y = d.y + dy - offset[1];
95
- const point = [
96
- x,
97
- y
98
- ];
99
- switch (mode) {
100
- case 0: {
101
- select2(context.svg).attr("cursor", "grabbing");
102
- event.subject.x = event.subject.fx = point[0];
103
- event.subject.y = event.subject.fy = point[1];
104
- projector.refresh(true);
105
- moved = true;
106
- break;
107
- }
108
- case 1: {
109
- if (options?.onDrag) {
110
- target = projector.findNode(event.x, event.y, 16);
111
- if (source === target) {
112
- select2(context.svg).attr("cursor", void 0);
113
- options?.onDrag?.();
114
- } else {
115
- select2(context.svg).attr("cursor", target ? "alias" : "cell");
116
- options?.onDrag?.(source, target, point);
117
- }
118
- }
119
- }
120
- }
121
- }).on("end", function(event) {
122
- select2(context.svg).attr("cursor", void 0);
123
- select2(this.parentElement).classed("dragging", false);
124
- switch (mode) {
125
- case 1: {
126
- options?.onDrop?.(source, target);
127
- break;
128
- }
129
- }
130
- if (!keyMod(event.sourceEvent, "freezeMod")) {
131
- event.subject.fx = null;
132
- event.subject.fy = null;
133
- }
134
- mode = void 0;
135
- source = void 0;
136
- target = void 0;
137
- offset = void 0;
138
- if (moved) {
139
- projector.refresh(false);
140
- moved = false;
141
- }
142
- });
143
- };
65
+ // src/graph/projector/graph-bundle-projector.ts
66
+ import { cluster as d3Cluster, curveBundle, hierarchy, lineRadial } from "d3";
67
+ import { log as log2 } from "@dxos/log";
68
+
69
+ // src/graph/projector/graph-radial-projector.ts
70
+ import { easeCubic, timer } from "d3";
71
+ import { log } from "@dxos/log";
144
72
 
145
73
  // src/graph/types.ts
146
74
  import { invariant } from "@dxos/invariant";
147
75
  var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/types.ts";
148
76
  var defaultIdAccessor = (node) => {
149
- invariant(node.id, void 0, {
150
- F: __dxlog_file,
151
- L: 18,
152
- S: void 0,
153
- A: [
154
- "node.id",
155
- ""
156
- ]
157
- });
77
+ invariant(node.id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 10, S: void 0, A: ["node.id", ""] });
158
78
  return node.id;
159
79
  };
160
80
  var emptyGraph = {
@@ -293,15 +213,7 @@ var FractionUtil = class _FractionUtil {
293
213
  * @param n
294
214
  */
295
215
  static factors = (n) => {
296
- invariant2(Number.isFinite(n), `Invalid number: ${n}`, {
297
- F: __dxlog_file2,
298
- L: 113,
299
- S: this,
300
- A: [
301
- "Number.isFinite(n)",
302
- "`Invalid number: ${n}`"
303
- ]
304
- });
216
+ invariant2(Number.isFinite(n), `Invalid number: ${n}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 113, S: this, A: ["Number.isFinite(n)", "`Invalid number: ${n}`"] });
305
217
  const factors = [
306
218
  1
307
219
  ];
@@ -757,9 +669,10 @@ var Projector = class {
757
669
  updateData(data) {
758
670
  this.onUpdate(data);
759
671
  }
760
- emitUpdate() {
672
+ emitUpdate(kind = "topology") {
761
673
  this.updated.emit({
762
- layout: this.layout
674
+ layout: this.layout,
675
+ kind
763
676
  });
764
677
  }
765
678
  async clear() {
@@ -829,10 +742,12 @@ var GraphProjector = class extends Projector {
829
742
  };
830
743
  }
831
744
  current.data = node;
745
+ current.hidden = false;
832
746
  return current;
833
747
  });
834
748
  const edges = data.edges.map((edge) => ({
835
749
  id: edge.id,
750
+ type: edge.type,
836
751
  source: nodes.find((n) => n.id === edge.source),
837
752
  target: nodes.find((n) => n.id === edge.target),
838
753
  data: edge.data
@@ -847,94 +762,24 @@ var GraphProjector = class extends Projector {
847
762
  async onClear() {
848
763
  this.reset();
849
764
  }
850
- };
851
-
852
- // src/graph/projector/graph-force-projector.ts
853
- import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX as forceX2, forceY as forceY2 } from "d3";
854
- import { log } from "@dxos/log";
855
-
856
- // src/graph/projector/graph-forces.ts
857
- import { forceX, forceY } from "d3";
858
- var forcePoint = ({ x, y, strength = 0.01 }) => {
859
- const fx = x != null ? forceX(x).strength(strength) : void 0;
860
- const fy = y != null ? forceY(y).strength(strength) : void 0;
861
- const force = (alpha) => {
862
- fx?.(alpha);
863
- fy?.(alpha);
864
- };
865
- force.initialize = (nodes, random) => {
866
- fx?.initialize(nodes, random);
867
- fy?.initialize(nodes, random);
868
- };
869
- return force;
870
- };
871
-
872
- // src/graph/projector/graph-force-projector.ts
873
- var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
874
- var getValue = (valueOrFunction, invoker, defaultValue) => {
875
- return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
876
- };
877
- var maybeForce = (options, cb, defaultValue = void 0) => {
878
- const value = typeof options === "boolean" ? options ? {} : void 0 : options ?? defaultValue;
879
- if (value) {
880
- return cb(value);
765
+ /**
766
+ * Optional projector-owned click intercept. The Graph component invokes this BEFORE
767
+ * forwarding to the consumer's `onSelect`, so projectors can implement built-in
768
+ * interactions (e.g. cluster collapse) without each consumer wiring them. Returning
769
+ * `true` indicates the click was handled — consumer's `onSelect` is suppressed.
770
+ * Default no-op returns `false` so consumer handlers still run.
771
+ */
772
+ handleNodeClick(_node, _event) {
773
+ return false;
881
774
  }
882
775
  };
883
- var defaultForceOptions = {
884
- link: true,
885
- manyBody: true,
886
- // center: true,
887
- point: true
888
- };
889
- var GraphForceProjector = class extends GraphProjector {
890
- // https://github.com/d3/d3-force
891
- _simulation = forceSimulation();
892
- _timeout;
893
- get forces() {
894
- return this.options.forces ?? defaultForceOptions;
895
- }
896
- get simulation() {
897
- return this._simulation;
898
- }
899
- restart() {
900
- this._simulation.alpha(1).restart();
901
- }
776
+
777
+ // src/graph/projector/graph-radial-projector.ts
778
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
779
+ var GraphRadialProjector = class extends GraphProjector {
780
+ _timer;
902
781
  findNode(x, y, radius) {
903
- return this._simulation.find(x, y, radius);
904
- }
905
- async onStart() {
906
- clearTimeout(this._timeout);
907
- let propagating = true;
908
- const { radial, ...forces } = this.forces;
909
- const delay = typeof radial === "object" ? radial.delay : void 0;
910
- if (delay) {
911
- propagating = false;
912
- this.updateForces(forces);
913
- this._timeout = setTimeout(() => {
914
- this.updateForces(this.forces);
915
- this.restart();
916
- this._timeout = setTimeout(() => {
917
- propagating = true;
918
- }, delay);
919
- }, delay);
920
- } else {
921
- this.updateForces(this.forces);
922
- }
923
- this._simulation.on("tick", () => propagating && this.emitUpdate()).velocityDecay(0.3).alphaDecay(1 - Math.pow(1e-3, 1 / 300)).alpha(1).restart();
924
- }
925
- async onStop() {
926
- clearTimeout(this._timeout);
927
- this._simulation.stop();
928
- }
929
- onRefresh(dragging = false) {
930
- if (this.forces.center) {
931
- if (dragging) {
932
- this._simulation.force("center", null);
933
- } else {
934
- this.updateForces(this.forces);
935
- }
936
- }
937
- this.restart();
782
+ return void 0;
938
783
  }
939
784
  onUpdate(graph) {
940
785
  log("onUpdate", {
@@ -942,68 +787,748 @@ var GraphForceProjector = class extends GraphProjector {
942
787
  nodes: graph?.nodes.length,
943
788
  edges: graph?.edges.length
944
789
  }
945
- }, {
946
- F: __dxlog_file3,
947
- L: 227,
948
- S: this,
949
- C: (f, a) => f(...a)
950
- });
951
- this._simulation.stop();
790
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 13, S: this });
952
791
  this.mergeData(graph);
953
- this.updateLayout();
954
- this.updateForces(this.forces);
955
- this.restart();
792
+ this.emitUpdate("topology");
793
+ this.doRadialLayout();
956
794
  }
957
- updateLayout() {
958
- this.layout.guides = this.options.guides ? [
959
- {
960
- id: "g-1",
961
- type: "circle",
962
- cx: 0,
963
- cy: 0,
964
- r: this.context.scale.model.toValue([
965
- 10,
966
- 1
967
- ])
968
- }
969
- ] : void 0;
970
- this.layout.graph.nodes.forEach((node) => {
971
- if (!node.initialized) {
972
- const a = 2 * Math.PI * Math.random();
973
- const r = this.options.radius ?? 200;
974
- Object.assign(node, {
975
- initialized: true,
976
- // TODO(burdon): Only when new nodes added to initial layout.
977
- // Position around center or parent; must have delta to avoid spike.
978
- // x: edge?.source?.x ?? Math.cos(a) * r,
979
- // y: edge?.source?.y ?? Math.sin(a) * r,
980
- x: Math.cos(a) * r,
981
- y: Math.sin(a) * r
795
+ animate() {
796
+ this._timer?.stop();
797
+ this._timer = void 0;
798
+ const start = Date.now();
799
+ if (this.options.duration) {
800
+ this._timer = timer(() => {
801
+ const t = Math.min(1, (Date.now() - start) / this.options.duration);
802
+ const d = easeCubic(t);
803
+ this.layout.graph.nodes.forEach((node) => {
804
+ node.x = node.sx + (node.tx - node.sx) * d;
805
+ node.y = node.sy + (node.ty - node.sy) * d;
806
+ node.r = node.sr + (node.tr - node.sr) * d;
982
807
  });
983
- }
984
- Object.assign(node, {
985
- r: getValue(this.options?.attributes?.radius, (fn) => fn(node, this.numChildren(node)), 6)
808
+ this.onTickFrame(d);
809
+ this.emitUpdate("positions");
810
+ if (t >= 1) {
811
+ this._timer.stop();
812
+ this._timer = void 0;
813
+ }
986
814
  });
987
- });
988
- this.layout.graph.edges.forEach((edge) => {
989
- Object.assign(edge, {
990
- linkForce: getValue(this.options.attributes?.linkForce, (fn) => fn(edge), true)
815
+ } else {
816
+ this.layout.graph.nodes.forEach((node) => {
817
+ node.x = node.tx;
818
+ node.y = node.ty;
819
+ node.r = node.tr;
991
820
  });
992
- });
821
+ this.onTickFrame(1);
822
+ this.emitUpdate("positions");
823
+ }
993
824
  }
994
825
  /**
995
- * Update all forces.
826
+ * Per-frame hook called after node x/y/r are interpolated and before the
827
+ * 'positions' emit. Subclasses override to update edge geometry (`edge.path`)
828
+ * so curves stay glued to moving endpoints. `t` is the eased progress in [0, 1].
996
829
  */
997
- updateForces(forces) {
998
- log("updateForces", {
999
- forces
1000
- }, {
1001
- F: __dxlog_file3,
1002
- L: 288,
1003
- S: this,
1004
- C: (f, a) => f(...a)
830
+ onTickFrame(t) {
831
+ }
832
+ async onStop() {
833
+ this._timer?.stop();
834
+ this._timer = void 0;
835
+ }
836
+ doRadialLayout() {
837
+ if (!this.context.size) {
838
+ return;
839
+ }
840
+ 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);
841
+ this.layout.graph.nodes.forEach((node, i) => {
842
+ const [tx, ty] = radial(i);
843
+ updateNode(node, [
844
+ tx,
845
+ ty
846
+ ]);
1005
847
  });
1006
- this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
848
+ this.animate();
849
+ }
850
+ };
851
+ var updateNode = (node, [tx, ty], tr = 8) => {
852
+ const sx = node.x ?? tx;
853
+ const sy = node.y ?? ty;
854
+ const sr = node.r ?? tr;
855
+ Object.assign(node, {
856
+ initialized: true,
857
+ // Start.
858
+ sx,
859
+ sy,
860
+ sr,
861
+ // Target.
862
+ tx,
863
+ ty,
864
+ tr,
865
+ // Current.
866
+ x: sx,
867
+ y: sy,
868
+ r: sr
869
+ });
870
+ };
871
+ var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
872
+ const da = 2 * Math.PI / n;
873
+ return (i) => {
874
+ const a = start + i * da;
875
+ return [
876
+ x + Math.cos(a) * r,
877
+ y + Math.sin(a) * r
878
+ ];
879
+ };
880
+ };
881
+ var layoutHorizontal = (x, y, w, n) => {
882
+ const dx = n > 1 ? w / (n - 1) : 0;
883
+ const sx = x - (n - 1) * dx / 2;
884
+ return (i) => {
885
+ return [
886
+ sx + i * dx,
887
+ y
888
+ ];
889
+ };
890
+ };
891
+ var layoutVertical = (x, y, h, n) => {
892
+ const dy = n > 1 ? h / (n - 1) : 0;
893
+ const sy = y - (n - 1) * dy / 2;
894
+ return (i) => {
895
+ return [
896
+ x,
897
+ sy + i * dy
898
+ ];
899
+ };
900
+ };
901
+
902
+ // src/graph/projector/graph-bundle-projector.ts
903
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-bundle-projector.ts";
904
+ var ROOT_ID = "__bundle_root__";
905
+ var GROUP_PREFIX = "__bundle_group__:";
906
+ var cartesianToPolar = (x, y) => ({
907
+ angle: Math.atan2(x, -y),
908
+ radius: Math.hypot(x, y)
909
+ });
910
+ var GraphBundleProjector = class extends GraphRadialProjector {
911
+ // Per-edge polar point arrays. Points 0 and N-1 are the source / target leaves and are
912
+ // overwritten from current cartesian on every tick; intermediate points stay fixed at
913
+ // their cluster-layout polar coordinates.
914
+ #edgePoints = /* @__PURE__ */ new Map();
915
+ #lineGen = lineRadial().radius((d) => d.radius).angle((d) => d.angle);
916
+ onUpdate(graph) {
917
+ log2("onUpdate", {
918
+ graph: {
919
+ nodes: graph?.nodes.length,
920
+ edges: graph?.edges.length
921
+ }
922
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 40, S: this });
923
+ this.mergeData(graph);
924
+ this.doBundleLayout();
925
+ this.emitUpdate("topology");
926
+ this.animate();
927
+ }
928
+ /**
929
+ * Refresh leaf endpoint polar values from current cartesian so the curve tracks
930
+ * its endpoints during the tween. Internal hierarchy positions stay constant.
931
+ */
932
+ onTickFrame(_t) {
933
+ for (const edge of this.layout.graph.edges) {
934
+ if (edge.type !== "bundle") {
935
+ continue;
936
+ }
937
+ const points = this.#edgePoints.get(edge.id);
938
+ if (!points || points.length < 2) {
939
+ continue;
940
+ }
941
+ const s = cartesianToPolar(edge.source.x ?? 0, edge.source.y ?? 0);
942
+ const t = cartesianToPolar(edge.target.x ?? 0, edge.target.y ?? 0);
943
+ points[0] = {
944
+ angle: s.angle,
945
+ radius: s.radius
946
+ };
947
+ points[points.length - 1] = {
948
+ angle: t.angle,
949
+ radius: t.radius
950
+ };
951
+ edge.path = this.#lineGen(points) ?? void 0;
952
+ }
953
+ }
954
+ doBundleLayout() {
955
+ if (!this.context.size) {
956
+ return;
957
+ }
958
+ const dataNodes = [
959
+ ...this.layout.graph.nodes
960
+ ];
961
+ if (!dataNodes.length) {
962
+ return;
963
+ }
964
+ const groupOf = this.options.groupOf;
965
+ const items = [
966
+ {
967
+ id: ROOT_ID
968
+ }
969
+ ];
970
+ const groupIds = /* @__PURE__ */ new Map();
971
+ for (const node of dataNodes) {
972
+ const key = groupOf?.(node);
973
+ let parent = ROOT_ID;
974
+ if (key !== void 0) {
975
+ let groupId = groupIds.get(key);
976
+ if (!groupId) {
977
+ groupId = `${GROUP_PREFIX}${key}`;
978
+ groupIds.set(key, groupId);
979
+ items.push({
980
+ id: groupId,
981
+ parent: ROOT_ID
982
+ });
983
+ }
984
+ parent = groupId;
985
+ }
986
+ items.push({
987
+ id: node.id,
988
+ parent,
989
+ node
990
+ });
991
+ }
992
+ const childrenByParent = /* @__PURE__ */ new Map();
993
+ for (const item of items) {
994
+ if (item.parent) {
995
+ const list = childrenByParent.get(item.parent) ?? [];
996
+ list.push(item);
997
+ childrenByParent.set(item.parent, list);
998
+ }
999
+ }
1000
+ const root = hierarchy({
1001
+ id: ROOT_ID
1002
+ }, (d) => childrenByParent.get(d.id) ?? []);
1003
+ const { width, height } = this.context.size;
1004
+ const margin = this.options.margin ?? 120;
1005
+ const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
1006
+ d3Cluster().size([
1007
+ 2 * Math.PI,
1008
+ ringRadius
1009
+ ]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
1010
+ const leafR = this.options.leafRadius ?? 4;
1011
+ const tension = this.options.tension ?? 0.85;
1012
+ this.#lineGen = lineRadial().curve(curveBundle.beta(tension)).radius((d) => d.radius).angle((d) => d.angle);
1013
+ const hierById = /* @__PURE__ */ new Map();
1014
+ root.each((d) => {
1015
+ hierById.set(d.data.id, d);
1016
+ });
1017
+ root.leaves().forEach((d) => {
1018
+ const angle = d.x;
1019
+ const radius = d.y;
1020
+ const x = Math.cos(angle - Math.PI / 2) * radius;
1021
+ const y = Math.sin(angle - Math.PI / 2) * radius;
1022
+ if (d.data.node) {
1023
+ updateNode(d.data.node, [
1024
+ x,
1025
+ y
1026
+ ], leafR);
1027
+ }
1028
+ });
1029
+ this.layout.graph.nodes = dataNodes;
1030
+ this.#edgePoints.clear();
1031
+ const incomingEdges = [
1032
+ ...this.layout.graph.edges
1033
+ ];
1034
+ const bundleEdges = [];
1035
+ for (const edge of incomingEdges) {
1036
+ const sourceHier = hierById.get(edge.source.id);
1037
+ const targetHier = hierById.get(edge.target.id);
1038
+ if (!sourceHier || !targetHier || sourceHier === targetHier) {
1039
+ continue;
1040
+ }
1041
+ const pathNodes = sourceHier.path(targetHier);
1042
+ const points = pathNodes.map((n) => ({
1043
+ angle: n.x,
1044
+ radius: n.y
1045
+ }));
1046
+ this.#edgePoints.set(edge.id, points);
1047
+ bundleEdges.push({
1048
+ id: edge.id,
1049
+ type: "bundle",
1050
+ source: edge.source,
1051
+ target: edge.target,
1052
+ data: edge.data
1053
+ });
1054
+ }
1055
+ this.layout.graph.edges = bundleEdges;
1056
+ this.onTickFrame(0);
1057
+ }
1058
+ };
1059
+
1060
+ // src/graph/projector/graph-cluster-projector.ts
1061
+ import { cluster as d3Cluster2, hierarchy as hierarchy2, linkRadial } from "d3";
1062
+ import { log as log3 } from "@dxos/log";
1063
+ var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-cluster-projector.ts";
1064
+ var ROOT_ID2 = "__cluster_root__";
1065
+ var GROUP_PREFIX2 = "__group__:";
1066
+ var HIER_EDGE_PREFIX = "__hier__:";
1067
+ var CLUSTER_NODE_TYPE_LEAF = "leaf";
1068
+ var CLUSTER_NODE_TYPE_GROUP = "group";
1069
+ var CLUSTER_NODE_TYPE_ROOT = "root";
1070
+ var linkPath = linkRadial().angle((d) => d.x).radius((d) => d.y);
1071
+ var cartesianToPolar2 = (x, y) => ({
1072
+ angle: Math.atan2(x, -y),
1073
+ radius: Math.hypot(x, y)
1074
+ });
1075
+ var GraphClusterProjector = class extends GraphRadialProjector {
1076
+ // Synthetic-node ids (root id, or `${GROUP_PREFIX}${key}`) whose subtree is currently
1077
+ // hidden. Clicking the corresponding rendered circle calls toggleCollapsed to flip
1078
+ // membership, then re-runs the layout so the renderer's exit transition fades the
1079
+ // hidden leaves + hierarchy edges out (and back in on expand).
1080
+ #collapsed = /* @__PURE__ */ new Set();
1081
+ // Snapshot of the full data-node set as of the last mergeData. doClusterLayout always
1082
+ // reads from this rather than `layout.graph.nodes` — the layout view is filtered (it
1083
+ // drops hidden leaves so the renderer doesn't see them), so re-reading from there
1084
+ // would permanently lose the hidden leaves and they couldn't reappear on expand.
1085
+ #dataNodes = [];
1086
+ /**
1087
+ * Built-in click semantics: clicking a synthetic root / group node toggles its subtree.
1088
+ * Leaf clicks fall through to the consumer's `onSelect` (returns `false`).
1089
+ */
1090
+ handleNodeClick(node, _event) {
1091
+ if (node.type !== CLUSTER_NODE_TYPE_ROOT && node.type !== CLUSTER_NODE_TYPE_GROUP) {
1092
+ return false;
1093
+ }
1094
+ this.toggleCollapsed(node.id);
1095
+ return true;
1096
+ }
1097
+ /** Toggle collapse state for a synthetic node id. Triggers a topology re-emit. */
1098
+ toggleCollapsed(id) {
1099
+ if (this.#collapsed.has(id)) {
1100
+ this.#collapsed.delete(id);
1101
+ } else {
1102
+ this.#collapsed.add(id);
1103
+ }
1104
+ this.doClusterLayout();
1105
+ this.emitUpdate("topology");
1106
+ this.animate();
1107
+ }
1108
+ /** Whether a synthetic-node id is currently collapsed. */
1109
+ isCollapsed(id) {
1110
+ return this.#collapsed.has(id);
1111
+ }
1112
+ onUpdate(graph) {
1113
+ log3("onUpdate", {
1114
+ graph: {
1115
+ nodes: graph?.nodes.length,
1116
+ edges: graph?.edges.length
1117
+ }
1118
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 79, S: this });
1119
+ this.mergeData(graph);
1120
+ this.#dataNodes = [
1121
+ ...this.layout.graph.nodes
1122
+ ];
1123
+ this.doClusterLayout();
1124
+ this.emitUpdate("topology");
1125
+ this.animate();
1126
+ }
1127
+ /**
1128
+ * Recompute each hierarchy edge's `path` from current cartesian source/target positions,
1129
+ * so the curves track moving endpoints during a cross-variant tween (e.g. force → cluster)
1130
+ * instead of being pinned to the final polar layout.
1131
+ */
1132
+ onTickFrame(_t) {
1133
+ for (const edge of this.layout.graph.edges) {
1134
+ if (edge.type !== "hierarchy") {
1135
+ continue;
1136
+ }
1137
+ const { source, target } = edge;
1138
+ const s = cartesianToPolar2(source.x ?? 0, source.y ?? 0);
1139
+ const t = cartesianToPolar2(target.x ?? 0, target.y ?? 0);
1140
+ edge.path = linkPath({
1141
+ source: {
1142
+ x: s.angle,
1143
+ y: s.radius
1144
+ },
1145
+ target: {
1146
+ x: t.angle,
1147
+ y: t.radius
1148
+ }
1149
+ });
1150
+ }
1151
+ }
1152
+ doClusterLayout() {
1153
+ if (!this.context.size) {
1154
+ return;
1155
+ }
1156
+ const dataNodes = this.#dataNodes;
1157
+ if (!dataNodes.length) {
1158
+ return;
1159
+ }
1160
+ const groupOf = this.options.groupOf;
1161
+ const rootId = this.options.rootId ?? ROOT_ID2;
1162
+ const items = [
1163
+ {
1164
+ id: rootId
1165
+ }
1166
+ ];
1167
+ const groupIds = /* @__PURE__ */ new Map();
1168
+ const rootCollapsed = this.#collapsed.has(rootId);
1169
+ if (!rootCollapsed) {
1170
+ for (const node of dataNodes) {
1171
+ const key = groupOf?.(node);
1172
+ let parent = rootId;
1173
+ if (key !== void 0) {
1174
+ let groupId = groupIds.get(key);
1175
+ if (!groupId) {
1176
+ groupId = `${GROUP_PREFIX2}${key}`;
1177
+ groupIds.set(key, groupId);
1178
+ items.push({
1179
+ id: groupId,
1180
+ parent: rootId,
1181
+ groupKey: key
1182
+ });
1183
+ }
1184
+ parent = groupId;
1185
+ }
1186
+ if (this.#collapsed.has(parent)) {
1187
+ continue;
1188
+ }
1189
+ items.push({
1190
+ id: node.id,
1191
+ parent,
1192
+ node
1193
+ });
1194
+ }
1195
+ }
1196
+ const childrenByParent = /* @__PURE__ */ new Map();
1197
+ for (const item of items) {
1198
+ if (item.parent) {
1199
+ const list = childrenByParent.get(item.parent) ?? [];
1200
+ list.push(item);
1201
+ childrenByParent.set(item.parent, list);
1202
+ }
1203
+ }
1204
+ const root = hierarchy2({
1205
+ id: rootId
1206
+ }, (d) => childrenByParent.get(d.id) ?? []);
1207
+ const { width, height } = this.context.size;
1208
+ const margin = this.options.margin ?? 80;
1209
+ const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
1210
+ d3Cluster2().size([
1211
+ 2 * Math.PI,
1212
+ ringRadius
1213
+ ]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
1214
+ const leafR = this.options.leafRadius ?? 4;
1215
+ const groupR = this.options.groupRadius ?? 3;
1216
+ const rootR = this.options.rootRadius ?? 5;
1217
+ const prevStubsById = /* @__PURE__ */ new Map();
1218
+ for (const node of this.layout.graph.nodes) {
1219
+ if (node.type === CLUSTER_NODE_TYPE_ROOT || node.type === CLUSTER_NODE_TYPE_GROUP) {
1220
+ prevStubsById.set(node.id, node);
1221
+ }
1222
+ }
1223
+ const syntheticNodes = /* @__PURE__ */ new Map();
1224
+ root.each((d) => {
1225
+ const id = d.data.id;
1226
+ const angle = d.x;
1227
+ const radius = d.y;
1228
+ const x = Math.cos(angle - Math.PI / 2) * radius;
1229
+ const y = Math.sin(angle - Math.PI / 2) * radius;
1230
+ if (d.data.node) {
1231
+ updateNode(d.data.node, [
1232
+ x,
1233
+ y
1234
+ ], leafR);
1235
+ d.data.node.type = CLUSTER_NODE_TYPE_LEAF;
1236
+ d.data.node.hidden = false;
1237
+ } else {
1238
+ const isRoot = id === rootId;
1239
+ const stub = prevStubsById.get(id) ?? {
1240
+ id,
1241
+ x: 0,
1242
+ y: 0
1243
+ };
1244
+ updateNode(stub, [
1245
+ x,
1246
+ y
1247
+ ], isRoot ? rootR : groupR);
1248
+ stub.type = isRoot ? CLUSTER_NODE_TYPE_ROOT : CLUSTER_NODE_TYPE_GROUP;
1249
+ if (isRoot) {
1250
+ stub.label = this.options.rootLabel;
1251
+ } else if (d.data.groupKey !== void 0) {
1252
+ stub.label = this.options.groupLabel ? this.options.groupLabel(d.data.groupKey) : d.data.groupKey;
1253
+ }
1254
+ syntheticNodes.set(id, stub);
1255
+ }
1256
+ });
1257
+ const visibleLeafIds = /* @__PURE__ */ new Set();
1258
+ for (const item of items) {
1259
+ if (item.node) {
1260
+ visibleLeafIds.add(item.id);
1261
+ }
1262
+ }
1263
+ for (const node of dataNodes) {
1264
+ if (visibleLeafIds.has(node.id)) {
1265
+ continue;
1266
+ }
1267
+ const key = groupOf?.(node);
1268
+ const parentId = key !== void 0 && groupIds.has(key) ? groupIds.get(key) : rootId;
1269
+ const parentStub = syntheticNodes.get(parentId);
1270
+ const targetX = parentStub?.tx ?? 0;
1271
+ const targetY = parentStub?.ty ?? 0;
1272
+ updateNode(node, [
1273
+ targetX,
1274
+ targetY
1275
+ ], leafR);
1276
+ node.type = CLUSTER_NODE_TYPE_LEAF;
1277
+ node.hidden = true;
1278
+ }
1279
+ const nextNodes = [];
1280
+ for (const stub of syntheticNodes.values()) {
1281
+ nextNodes.push(stub);
1282
+ }
1283
+ for (const node of dataNodes) {
1284
+ nextNodes.push(node);
1285
+ }
1286
+ this.layout.graph.nodes = nextNodes;
1287
+ const hierarchyEdges = [];
1288
+ root.links().forEach((link) => {
1289
+ const sid = link.source.data.id;
1290
+ const tid = link.target.data.id;
1291
+ const sourceNode = link.source.data.node ?? syntheticNodes.get(sid);
1292
+ const targetNode = link.target.data.node ?? syntheticNodes.get(tid);
1293
+ hierarchyEdges.push({
1294
+ id: `${HIER_EDGE_PREFIX}${sid}->${tid}`,
1295
+ type: "hierarchy",
1296
+ source: sourceNode,
1297
+ target: targetNode,
1298
+ data: void 0
1299
+ });
1300
+ });
1301
+ this.layout.graph.edges = hierarchyEdges;
1302
+ this.onTickFrame(0);
1303
+ }
1304
+ };
1305
+
1306
+ // src/graph/projector/graph-drag.ts
1307
+ import { drag, pointer, select as select2 } from "d3";
1308
+ var defaultDragOptions = {
1309
+ linkMod: "metaKey",
1310
+ freezeMod: "shiftKey"
1311
+ };
1312
+ var createGraphDrag = (context, projector, options = defaultDragOptions) => {
1313
+ let mode;
1314
+ let source;
1315
+ let target;
1316
+ let offset;
1317
+ let moved = false;
1318
+ const keyMod = (event, key) => {
1319
+ const modKey = options?.[key] ?? defaultDragOptions[key];
1320
+ return modKey === void 0 || event[modKey];
1321
+ };
1322
+ return drag().filter((event) => !event.ctrlKey).on("start", function(event, d) {
1323
+ source = d;
1324
+ offset = pointer(event, this.parentElement);
1325
+ if (options?.onDrop && keyMod(event.sourceEvent, "linkMod")) {
1326
+ mode = 1;
1327
+ } else if (keyMod(event.sourceEvent, "dragMod")) {
1328
+ mode = 0;
1329
+ }
1330
+ }).on("drag", function(event, d) {
1331
+ const parent = this.closest("g.node");
1332
+ select2(parent).classed("dragging", true).raise();
1333
+ const [dx, dy] = pointer(event, this.parentElement);
1334
+ const x = d.x + dx - offset[0];
1335
+ const y = d.y + dy - offset[1];
1336
+ const point = [
1337
+ x,
1338
+ y
1339
+ ];
1340
+ switch (mode) {
1341
+ case 0: {
1342
+ select2(context.svg).attr("cursor", "grabbing");
1343
+ event.subject.x = event.subject.fx = point[0];
1344
+ event.subject.y = event.subject.fy = point[1];
1345
+ projector.refresh(true);
1346
+ moved = true;
1347
+ break;
1348
+ }
1349
+ case 1: {
1350
+ if (options?.onDrag) {
1351
+ target = projector.findNode(event.x, event.y, 16);
1352
+ if (source === target) {
1353
+ select2(context.svg).attr("cursor", void 0);
1354
+ options?.onDrag?.();
1355
+ } else {
1356
+ select2(context.svg).attr("cursor", target ? "alias" : "cell");
1357
+ options?.onDrag?.(source, target, point);
1358
+ }
1359
+ }
1360
+ }
1361
+ }
1362
+ }).on("end", function(event) {
1363
+ select2(context.svg).attr("cursor", void 0);
1364
+ select2(this.parentElement).classed("dragging", false);
1365
+ switch (mode) {
1366
+ case 1: {
1367
+ options?.onDrop?.(source, target);
1368
+ break;
1369
+ }
1370
+ }
1371
+ if (!keyMod(event.sourceEvent, "freezeMod")) {
1372
+ event.subject.fx = null;
1373
+ event.subject.fy = null;
1374
+ }
1375
+ mode = void 0;
1376
+ source = void 0;
1377
+ target = void 0;
1378
+ offset = void 0;
1379
+ if (moved) {
1380
+ projector.refresh(false);
1381
+ moved = false;
1382
+ }
1383
+ });
1384
+ };
1385
+
1386
+ // src/graph/projector/graph-force-projector.ts
1387
+ import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX as forceX2, forceY as forceY2 } from "d3";
1388
+ import { log as log4 } from "@dxos/log";
1389
+
1390
+ // src/graph/projector/graph-forces.ts
1391
+ import { forceX, forceY } from "d3";
1392
+ var forcePoint = ({ x, y, strength = 0.01 }) => {
1393
+ const fx = x != null ? forceX(x).strength(strength) : void 0;
1394
+ const fy = y != null ? forceY(y).strength(strength) : void 0;
1395
+ const force = (alpha) => {
1396
+ fx?.(alpha);
1397
+ fy?.(alpha);
1398
+ };
1399
+ force.initialize = (nodes, random) => {
1400
+ fx?.initialize(nodes, random);
1401
+ fy?.initialize(nodes, random);
1402
+ };
1403
+ return force;
1404
+ };
1405
+
1406
+ // src/graph/projector/graph-force-projector.ts
1407
+ var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
1408
+ var getValue = (valueOrFunction, invoker, defaultValue) => {
1409
+ return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
1410
+ };
1411
+ var maybeForce = (options, cb, defaultValue = void 0) => {
1412
+ const value = typeof options === "boolean" ? options ? {} : void 0 : options ?? defaultValue;
1413
+ if (value) {
1414
+ return cb(value);
1415
+ }
1416
+ };
1417
+ var defaultForceOptions = {
1418
+ link: true,
1419
+ manyBody: true,
1420
+ // center: true,
1421
+ point: true
1422
+ };
1423
+ var GraphForceProjector = class extends GraphProjector {
1424
+ // https://github.com/d3/d3-force
1425
+ _simulation = forceSimulation();
1426
+ _timeout;
1427
+ get forces() {
1428
+ return this.options.forces ?? defaultForceOptions;
1429
+ }
1430
+ get simulation() {
1431
+ return this._simulation;
1432
+ }
1433
+ restart() {
1434
+ this._simulation.alpha(1).restart();
1435
+ }
1436
+ findNode(x, y, radius) {
1437
+ return this._simulation.find(x, y, radius);
1438
+ }
1439
+ async onStart() {
1440
+ clearTimeout(this._timeout);
1441
+ let propagating = true;
1442
+ const { radial, ...forces } = this.forces;
1443
+ const delay = typeof radial === "object" ? radial.delay : void 0;
1444
+ if (delay) {
1445
+ propagating = false;
1446
+ this.updateForces(forces);
1447
+ this._timeout = setTimeout(() => {
1448
+ this.updateForces(this.forces);
1449
+ this.restart();
1450
+ this._timeout = setTimeout(() => {
1451
+ propagating = true;
1452
+ }, delay);
1453
+ }, delay);
1454
+ } else {
1455
+ this.updateForces(this.forces);
1456
+ }
1457
+ this._simulation.on("tick", () => propagating && this.emitUpdate("positions")).velocityDecay(0.3).alphaDecay(1 - Math.pow(1e-3, 1 / 300)).alpha(1).restart();
1458
+ }
1459
+ async onStop() {
1460
+ clearTimeout(this._timeout);
1461
+ this._simulation.stop();
1462
+ }
1463
+ onRefresh(dragging = false) {
1464
+ if (this.forces.center) {
1465
+ if (dragging) {
1466
+ this._simulation.force("center", null);
1467
+ } else {
1468
+ this.updateForces(this.forces);
1469
+ }
1470
+ }
1471
+ this.restart();
1472
+ }
1473
+ onUpdate(graph) {
1474
+ log4("onUpdate", {
1475
+ graph: {
1476
+ nodes: graph?.nodes.length,
1477
+ edges: graph?.edges.length
1478
+ }
1479
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 91, S: this });
1480
+ this._simulation.stop();
1481
+ this.mergeData(graph);
1482
+ this.updateLayout();
1483
+ this.updateForces(this.forces);
1484
+ this.emitUpdate("topology");
1485
+ this.restart();
1486
+ }
1487
+ updateLayout() {
1488
+ this.layout.guides = this.options.guides ? [
1489
+ {
1490
+ id: "g-1",
1491
+ type: "circle",
1492
+ cx: 0,
1493
+ cy: 0,
1494
+ r: this.context.scale.model.toValue([
1495
+ 10,
1496
+ 1
1497
+ ])
1498
+ }
1499
+ ] : void 0;
1500
+ this.layout.graph.nodes.forEach((node) => {
1501
+ if (!node.initialized) {
1502
+ const a = 2 * Math.PI * Math.random();
1503
+ const r = this.options.radius ?? 200;
1504
+ Object.assign(node, {
1505
+ initialized: true,
1506
+ // TODO(burdon): Only when new nodes added to initial layout.
1507
+ // Position around center or parent; must have delta to avoid spike.
1508
+ // x: edge?.source?.x ?? Math.cos(a) * r,
1509
+ // y: edge?.source?.y ?? Math.sin(a) * r,
1510
+ x: Math.cos(a) * r,
1511
+ y: Math.sin(a) * r
1512
+ });
1513
+ }
1514
+ Object.assign(node, {
1515
+ r: getValue(this.options?.attributes?.radius, (fn) => fn(node, this.numChildren(node)), 6)
1516
+ });
1517
+ });
1518
+ this.layout.graph.edges.forEach((edge) => {
1519
+ Object.assign(edge, {
1520
+ linkForce: getValue(this.options.attributes?.linkForce, (fn) => fn(edge), true)
1521
+ });
1522
+ });
1523
+ }
1524
+ /**
1525
+ * Update all forces.
1526
+ */
1527
+ updateForces(forces) {
1528
+ log4("updateForces", {
1529
+ forces
1530
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 153, S: this });
1531
+ this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
1007
1532
  const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
1008
1533
  if (config.distance != null) {
1009
1534
  force.distance(config.distance);
@@ -1066,203 +1591,364 @@ var GraphForceProjector = class extends GraphProjector {
1066
1591
  };
1067
1592
 
1068
1593
  // src/graph/projector/graph-hierarchical-projector.ts
1069
- import { log as log3 } from "@dxos/log";
1070
-
1071
- // src/graph/projector/graph-radial-projector.ts
1072
- import { easeCubic, timer } from "d3";
1073
- import { log as log2 } from "@dxos/log";
1074
- var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
1075
- var GraphRadialProjector = class extends GraphProjector {
1076
- _timer;
1077
- findNode(x, y, radius) {
1078
- return void 0;
1079
- }
1594
+ import { log as log5 } from "@dxos/log";
1595
+ var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
1596
+ var GraphHierarchicalProjector = class extends GraphRadialProjector {
1080
1597
  onUpdate(graph) {
1081
- log2("onUpdate", {
1598
+ log5("onUpdate", {
1082
1599
  graph: {
1083
1600
  nodes: graph?.nodes.length,
1084
1601
  edges: graph?.edges.length
1085
- }
1086
- }, {
1087
- F: __dxlog_file4,
1088
- L: 32,
1089
- S: this,
1090
- C: (f, a) => f(...a)
1091
- });
1602
+ },
1603
+ selection: this.selection?.getSelectedIds()
1604
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 8, S: this });
1092
1605
  this.mergeData(graph);
1606
+ this.emitUpdate("topology");
1607
+ const selected = this.selection?.getSelectedIds()[0];
1608
+ if (selected) {
1609
+ const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
1610
+ if (node) {
1611
+ this.doHierarchicalLayout(node);
1612
+ return;
1613
+ }
1614
+ }
1093
1615
  this.doRadialLayout();
1094
1616
  }
1095
- animate() {
1096
- const start = Date.now();
1097
- if (this.options.duration) {
1098
- this._timer = timer(() => {
1099
- const t = Math.min(1, (Date.now() - start) / this.options.duration);
1100
- const d = easeCubic(t);
1101
- this.layout.graph.nodes.forEach((node) => {
1102
- node.x = node.sx + (node.tx - node.sx) * d;
1103
- node.y = node.sy + (node.ty - node.sy) * d;
1104
- node.r = node.sr + (node.tr - node.sr) * d;
1105
- });
1106
- this.emitUpdate();
1107
- if (t >= 1) {
1108
- this._timer.stop();
1109
- this._timer = void 0;
1110
- }
1617
+ doHierarchicalLayout(selected) {
1618
+ if (!this.context.size) {
1619
+ return;
1620
+ }
1621
+ const r2 = this.options.radius ?? Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 80);
1622
+ const r1 = r2 / 2;
1623
+ const children = this.layout.graph.edges.filter((edge) => edge.source.id === selected.id).map((edge) => edge.target);
1624
+ updateNode(selected, [
1625
+ 0,
1626
+ 0
1627
+ ], 20);
1628
+ {
1629
+ const radial = layoutRadial(0, 0, r1, children.length);
1630
+ children.forEach((node, i) => {
1631
+ const [tx, ty] = radial(i);
1632
+ updateNode(node, [
1633
+ tx,
1634
+ ty
1635
+ ]);
1636
+ });
1637
+ }
1638
+ {
1639
+ const radial = layoutRadial(0, 0, r2, this.layout.graph.nodes.length - 1 - children.length);
1640
+ this.layout.graph.nodes.filter((node) => node.id !== selected.id && !children.includes(node)).forEach((node, i) => {
1641
+ const [tx, ty] = radial(i);
1642
+ updateNode(node, [
1643
+ tx,
1644
+ ty
1645
+ ]);
1111
1646
  });
1112
- } else {
1113
- this.emitUpdate();
1114
1647
  }
1648
+ this.animate();
1115
1649
  }
1116
- async onStop() {
1117
- this._timer?.stop();
1118
- this._timer = void 0;
1650
+ };
1651
+
1652
+ // src/graph/projector/graph-lattice-projector.ts
1653
+ import { log as log6 } from "@dxos/log";
1654
+ var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-lattice-projector.ts";
1655
+ var GraphLatticeProjector = class extends GraphRadialProjector {
1656
+ onUpdate(graph) {
1657
+ log6("onUpdate", {
1658
+ graph: {
1659
+ nodes: graph?.nodes.length,
1660
+ edges: graph?.edges.length
1661
+ }
1662
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 14, S: this });
1663
+ this.mergeData(graph);
1664
+ this.doLatticeLayout();
1665
+ this.emitUpdate("topology");
1666
+ this.animate();
1119
1667
  }
1120
- doRadialLayout() {
1668
+ doLatticeLayout() {
1121
1669
  if (!this.context.size) {
1122
1670
  return;
1123
1671
  }
1124
- 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);
1125
- this.layout.graph.nodes.forEach((node, i) => {
1126
- const [tx, ty] = radial(i);
1672
+ const nodes = this.layout.graph.nodes;
1673
+ const count = nodes.length;
1674
+ if (!count) {
1675
+ return;
1676
+ }
1677
+ const sortBy = this.options.sortBy ?? ((n) => n.data?.label ?? n.id);
1678
+ nodes.sort((a, b) => sortBy(a).localeCompare(sortBy(b)));
1679
+ const columns = Math.max(1, Math.ceil(Math.sqrt(count)));
1680
+ const rows = Math.ceil(count / columns);
1681
+ const margin = this.options.margin ?? 16;
1682
+ const { width, height } = this.context.size;
1683
+ const innerW = Math.max(0, width - 2 * margin);
1684
+ const innerH = Math.max(0, height - 2 * margin);
1685
+ const r = this.options.radius ?? 6;
1686
+ const fit = Math.min(innerW / columns, innerH / rows);
1687
+ const cellSize = Math.max(0, Math.min(fit, r * 6));
1688
+ const gridW = cellSize * columns;
1689
+ const gridH = cellSize * rows;
1690
+ const offsetX = -gridW / 2 + cellSize / 2;
1691
+ const offsetY = -gridH / 2 + cellSize / 2;
1692
+ nodes.forEach((node, i) => {
1693
+ const tx = offsetX + i % columns * cellSize;
1694
+ const ty = offsetY + Math.floor(i / columns) * cellSize;
1127
1695
  updateNode(node, [
1128
1696
  tx,
1129
1697
  ty
1130
- ]);
1698
+ ], r);
1131
1699
  });
1132
- this.animate();
1133
1700
  }
1134
1701
  };
1135
- var updateNode = (node, [tx, ty], tr = 8) => {
1136
- const sx = node.x ?? tx;
1137
- const sy = node.y ?? ty;
1138
- const sr = node.r ?? tr;
1139
- Object.assign(node, {
1140
- initialized: true,
1141
- // Start.
1142
- sx,
1143
- sy,
1144
- sr,
1145
- // Target.
1146
- tx,
1147
- ty,
1148
- tr,
1149
- // Current.
1150
- x: sx,
1151
- y: sy,
1152
- r: sr
1153
- });
1154
- };
1155
- var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
1156
- const da = 2 * Math.PI / n;
1157
- return (i) => {
1158
- const a = start + i * da;
1159
- return [
1160
- x + Math.cos(a) * r,
1161
- y + Math.sin(a) * r
1162
- ];
1163
- };
1164
- };
1165
- var layoutHorizontal = (x, y, w, n) => {
1166
- const dx = n > 1 ? w / (n - 1) : 0;
1167
- const sx = x - (n - 1) * dx / 2;
1168
- return (i) => {
1169
- return [
1170
- sx + i * dx,
1171
- y
1172
- ];
1173
- };
1174
- };
1175
- var layoutVertical = (x, y, h, n) => {
1176
- const dy = n > 1 ? h / (n - 1) : 0;
1177
- const sy = y - (n - 1) * dy / 2;
1178
- return (i) => {
1179
- return [
1180
- x,
1181
- sy + i * dy
1182
- ];
1183
- };
1184
- };
1185
1702
 
1186
- // src/graph/projector/graph-hierarchical-projector.ts
1187
- var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
1188
- var GraphHierarchicalProjector = class extends GraphRadialProjector {
1703
+ // src/graph/projector/graph-plexus-projector.ts
1704
+ import { cluster as d3Cluster3, hierarchy as hierarchy3, linkRadial as linkRadial2 } from "d3";
1705
+ import { log as log7 } from "@dxos/log";
1706
+ var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-plexus-projector.ts";
1707
+ var RELATION_PREFIX = "__plexus_relation__:";
1708
+ var HIER_EDGE_PREFIX2 = "__plexus_hier__:";
1709
+ var PLEXUS_NODE_TYPE_FOCUS = "plexus-focus";
1710
+ var PLEXUS_NODE_TYPE_RELATION = "plexus-relation";
1711
+ var PLEXUS_NODE_TYPE_OBJECT = "plexus-object";
1712
+ var linkPath2 = linkRadial2().angle((d) => d.x).radius((d) => d.y);
1713
+ var cartesianToPolar3 = (x, y) => ({
1714
+ angle: Math.atan2(x, -y),
1715
+ radius: Math.hypot(x, y)
1716
+ });
1717
+ var GraphPlexusProjector = class extends GraphRadialProjector {
1718
+ // Full node / edge snapshots taken right after mergeData — doPlexusLayout reads from
1719
+ // these because it overwrites layout.graph with the filtered focus-centric view.
1720
+ #dataNodes = [];
1721
+ #dataEdges = [];
1189
1722
  onUpdate(graph) {
1190
- log3("onUpdate", {
1723
+ log7("onUpdate", {
1191
1724
  graph: {
1192
1725
  nodes: graph?.nodes.length,
1193
1726
  edges: graph?.edges.length
1194
- },
1195
- selection: this.selection?.getSelectedIds()
1196
- }, {
1197
- F: __dxlog_file5,
1198
- L: 24,
1199
- S: this,
1200
- C: (f, a) => f(...a)
1201
- });
1727
+ }
1728
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 48, S: this });
1202
1729
  this.mergeData(graph);
1203
- const selected = this.selection?.getSelectedIds()[0];
1204
- if (selected) {
1205
- const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
1206
- if (node) {
1207
- this.doHierarchicalLayout(node);
1208
- return;
1730
+ this.#dataNodes = [
1731
+ ...this.layout.graph.nodes
1732
+ ];
1733
+ this.#dataEdges = [
1734
+ ...this.layout.graph.edges
1735
+ ];
1736
+ this.doPlexusLayout();
1737
+ this.emitUpdate("topology");
1738
+ this.animate();
1739
+ }
1740
+ /**
1741
+ * Recompute each hierarchy edge's `path` from current cartesian endpoints so curves track
1742
+ * moving nodes during the tween (identical strategy to the cluster projector).
1743
+ */
1744
+ onTickFrame(_t) {
1745
+ for (const edge of this.layout.graph.edges) {
1746
+ if (edge.type !== "hierarchy") {
1747
+ continue;
1209
1748
  }
1749
+ const { source, target } = edge;
1750
+ const s = cartesianToPolar3(source.x ?? 0, source.y ?? 0);
1751
+ const t = cartesianToPolar3(target.x ?? 0, target.y ?? 0);
1752
+ edge.path = linkPath2({
1753
+ source: {
1754
+ x: s.angle,
1755
+ y: s.radius
1756
+ },
1757
+ target: {
1758
+ x: t.angle,
1759
+ y: t.radius
1760
+ }
1761
+ });
1210
1762
  }
1211
- this.doRadialLayout();
1212
1763
  }
1213
- doHierarchicalLayout(selected) {
1764
+ doPlexusLayout() {
1214
1765
  if (!this.context.size) {
1215
1766
  return;
1216
1767
  }
1217
- const r2 = this.options.radius ?? Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 80);
1218
- const r1 = r2 / 2;
1219
- const children = this.layout.graph.edges.filter((edge) => edge.source.id === selected.id).map((edge) => edge.target);
1220
- updateNode(selected, [
1221
- 0,
1222
- 0
1223
- ], 20);
1224
- {
1225
- const radial = layoutRadial(0, 0, r1, children.length);
1226
- children.forEach((node, i) => {
1227
- const [tx, ty] = radial(i);
1228
- updateNode(node, [
1229
- tx,
1230
- ty
1231
- ]);
1232
- });
1768
+ const dataNodes = this.#dataNodes;
1769
+ if (!dataNodes.length) {
1770
+ return;
1233
1771
  }
1234
- {
1235
- const radial = layoutRadial(0, 0, r2, this.layout.graph.nodes.length - 1 - children.length);
1236
- this.layout.graph.nodes.filter((node) => node.id !== selected.id && !children.includes(node)).forEach((node, i) => {
1237
- const [tx, ty] = radial(i);
1238
- updateNode(node, [
1239
- tx,
1240
- ty
1241
- ]);
1772
+ const focusId = this.options.focus;
1773
+ const focusNode = focusId ? dataNodes.find((node) => node.id === focusId) : void 0;
1774
+ if (!focusNode) {
1775
+ const radial = layoutRadial(0, 0, Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 100), dataNodes.length);
1776
+ dataNodes.forEach((node, index) => updateNode(node, radial(index), this.options.leafRadius ?? 5));
1777
+ this.layout.graph.nodes = dataNodes;
1778
+ this.layout.graph.edges = [];
1779
+ this.animate();
1780
+ return;
1781
+ }
1782
+ const relationOf = this.options.relationOf ?? defaultRelationOf;
1783
+ const groups = /* @__PURE__ */ new Map();
1784
+ const placed = /* @__PURE__ */ new Set([
1785
+ focusId
1786
+ ]);
1787
+ for (const edge of this.#dataEdges) {
1788
+ const relation = relationOf(edge, focusId);
1789
+ if (!relation) {
1790
+ continue;
1791
+ }
1792
+ const neighbour = edge.source.id === focusId ? edge.target : edge.source;
1793
+ if (placed.has(neighbour.id)) {
1794
+ continue;
1795
+ }
1796
+ placed.add(neighbour.id);
1797
+ let group = groups.get(relation.key);
1798
+ if (!group) {
1799
+ group = {
1800
+ id: `${RELATION_PREFIX}${relation.key}`,
1801
+ label: relation.label,
1802
+ leaves: []
1803
+ };
1804
+ groups.set(relation.key, group);
1805
+ }
1806
+ group.leaves.push(neighbour);
1807
+ }
1808
+ const items = [
1809
+ {
1810
+ id: focusId,
1811
+ node: focusNode
1812
+ }
1813
+ ];
1814
+ for (const group of groups.values()) {
1815
+ items.push({
1816
+ id: group.id,
1817
+ parent: focusId,
1818
+ relationLabel: group.label
1242
1819
  });
1820
+ for (const leaf of group.leaves) {
1821
+ items.push({
1822
+ id: leaf.id,
1823
+ parent: group.id,
1824
+ node: leaf
1825
+ });
1826
+ }
1243
1827
  }
1244
- this.animate();
1828
+ const childrenByParent = /* @__PURE__ */ new Map();
1829
+ for (const item of items) {
1830
+ if (item.parent) {
1831
+ const list = childrenByParent.get(item.parent) ?? [];
1832
+ list.push(item);
1833
+ childrenByParent.set(item.parent, list);
1834
+ }
1835
+ }
1836
+ const root = hierarchy3({
1837
+ id: focusId,
1838
+ node: focusNode
1839
+ }, (d) => childrenByParent.get(d.id) ?? []);
1840
+ const { width, height } = this.context.size;
1841
+ const margin = this.options.margin ?? 100;
1842
+ const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
1843
+ d3Cluster3().size([
1844
+ 2 * Math.PI,
1845
+ ringRadius
1846
+ ]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
1847
+ const leafR = this.options.leafRadius ?? 5;
1848
+ const relationR = this.options.relationRadius ?? leafR;
1849
+ const focusR = this.options.focusRadius ?? leafR * 2;
1850
+ const prevStubsById = /* @__PURE__ */ new Map();
1851
+ for (const node of this.layout.graph.nodes) {
1852
+ if (node.type === PLEXUS_NODE_TYPE_RELATION) {
1853
+ prevStubsById.set(node.id, node);
1854
+ }
1855
+ }
1856
+ const relationStubs = /* @__PURE__ */ new Map();
1857
+ root.each((d) => {
1858
+ const angle = d.x;
1859
+ const radius = d.y;
1860
+ const x = Math.cos(angle - Math.PI / 2) * radius;
1861
+ const y = Math.sin(angle - Math.PI / 2) * radius;
1862
+ const id = d.data.id;
1863
+ if (id === focusId) {
1864
+ updateNode(focusNode, [
1865
+ x,
1866
+ y
1867
+ ], focusR);
1868
+ focusNode.type = PLEXUS_NODE_TYPE_FOCUS;
1869
+ focusNode.hidden = false;
1870
+ } else if (d.data.node) {
1871
+ updateNode(d.data.node, [
1872
+ x,
1873
+ y
1874
+ ], leafR);
1875
+ d.data.node.type = PLEXUS_NODE_TYPE_OBJECT;
1876
+ d.data.node.hidden = false;
1877
+ } else {
1878
+ const stub = prevStubsById.get(id) ?? {
1879
+ id,
1880
+ x: 0,
1881
+ y: 0
1882
+ };
1883
+ updateNode(stub, [
1884
+ x,
1885
+ y
1886
+ ], relationR);
1887
+ stub.type = PLEXUS_NODE_TYPE_RELATION;
1888
+ stub.label = d.data.relationLabel;
1889
+ relationStubs.set(id, stub);
1890
+ }
1891
+ });
1892
+ const nextNodes = [];
1893
+ for (const stub of relationStubs.values()) {
1894
+ nextNodes.push(stub);
1895
+ }
1896
+ for (const group of groups.values()) {
1897
+ for (const leaf of group.leaves) {
1898
+ nextNodes.push(leaf);
1899
+ }
1900
+ }
1901
+ nextNodes.push(focusNode);
1902
+ this.layout.graph.nodes = nextNodes;
1903
+ const edges = [];
1904
+ root.links().forEach((link) => {
1905
+ const sid = link.source.data.id;
1906
+ const tid = link.target.data.id;
1907
+ const sourceNode = sid === focusId ? focusNode : link.source.data.node ?? relationStubs.get(sid);
1908
+ const targetNode = link.target.data.node ?? relationStubs.get(tid);
1909
+ if (!sourceNode || !targetNode) {
1910
+ return;
1911
+ }
1912
+ edges.push({
1913
+ id: `${HIER_EDGE_PREFIX2}${sid}->${tid}`,
1914
+ type: "hierarchy",
1915
+ source: sourceNode,
1916
+ target: targetNode,
1917
+ data: void 0
1918
+ });
1919
+ });
1920
+ this.layout.graph.edges = edges;
1921
+ this.onTickFrame(0);
1922
+ }
1923
+ };
1924
+ var defaultRelationOf = (edge, focusId) => {
1925
+ const outgoing = edge.source.id === focusId;
1926
+ const incoming = edge.target.id === focusId;
1927
+ if (!outgoing && !incoming) {
1928
+ return void 0;
1245
1929
  }
1930
+ const type = edge.type ?? "edge";
1931
+ const arrow = outgoing ? "\u2192" : "\u2190";
1932
+ return {
1933
+ key: `${type}:${outgoing ? "out" : "in"}`,
1934
+ label: `${type} ${arrow}`
1935
+ };
1246
1936
  };
1247
1937
 
1248
1938
  // src/graph/projector/graph-relational-projector.ts
1249
- import { log as log4 } from "@dxos/log";
1250
- var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
1939
+ import { log as log8 } from "@dxos/log";
1940
+ var __dxlog_file10 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
1251
1941
  var GraphRelationalProjector = class extends GraphRadialProjector {
1252
1942
  onUpdate(graph) {
1253
- log4("onUpdate", {
1943
+ log8("onUpdate", {
1254
1944
  graph: {
1255
1945
  nodes: graph?.nodes.length,
1256
1946
  edges: graph?.edges.length
1257
1947
  },
1258
1948
  selection: this.selection?.getSelectedIds()
1259
- }, {
1260
- F: __dxlog_file6,
1261
- L: 24,
1262
- S: this,
1263
- C: (f, a) => f(...a)
1264
- });
1949
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 8, S: this });
1265
1950
  this.mergeData(graph);
1951
+ this.emitUpdate("topology");
1266
1952
  const selected = this.selection?.getSelectedIds()[0];
1267
1953
  if (selected) {
1268
1954
  const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
@@ -1334,10 +2020,267 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
1334
2020
  }
1335
2021
  };
1336
2022
 
2023
+ // src/graph/projector/graph-swarm-projector.ts
2024
+ import { timer as timer2 } from "d3";
2025
+ import { log as log9 } from "@dxos/log";
2026
+ var __dxlog_file11 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-swarm-projector.ts";
2027
+ var SWARMMATE_RADIUS = 60;
2028
+ var SEPARATION_DISTANCE = 30;
2029
+ var DEFAULTS = {
2030
+ spawnRadius: 200,
2031
+ maxVelocity: 1.2,
2032
+ alignment: 3,
2033
+ cohesion: 3,
2034
+ separation: 3,
2035
+ cursorRepel: 120,
2036
+ avoidance: 3,
2037
+ trailLength: 30
2038
+ };
2039
+ var GraphSwarmProjector = class extends GraphProjector {
2040
+ #timer;
2041
+ /** Cursor in SVG model coordinates, or null when the pointer is outside the surface. */
2042
+ #cursor = null;
2043
+ findNode() {
2044
+ return void 0;
2045
+ }
2046
+ /**
2047
+ * Tell the projector where the pointer is, in SVG model coordinates (the same space
2048
+ * `node.x/y` live in — center origin, post-zoom). Pass `null` (or omit args) on
2049
+ * pointer-leave to disable cursor avoidance.
2050
+ */
2051
+ setCursor(x, y) {
2052
+ if (x == null || y == null) {
2053
+ this.#cursor = null;
2054
+ } else {
2055
+ this.#cursor = {
2056
+ x,
2057
+ y
2058
+ };
2059
+ }
2060
+ }
2061
+ onUpdate(graph) {
2062
+ log9("onUpdate", {
2063
+ graph: {
2064
+ nodes: graph?.nodes.length,
2065
+ edges: graph?.edges.length
2066
+ }
2067
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 54, S: this });
2068
+ this.mergeData(graph);
2069
+ this.initializeNodes();
2070
+ this.emitUpdate("topology");
2071
+ }
2072
+ async onStart() {
2073
+ this.startTimer();
2074
+ }
2075
+ async onStop() {
2076
+ this.stopTimer();
2077
+ }
2078
+ onRefresh() {
2079
+ if (!this.#timer) {
2080
+ this.startTimer();
2081
+ }
2082
+ }
2083
+ #opt(key) {
2084
+ return this.options[key] ?? DEFAULTS[key];
2085
+ }
2086
+ initializeNodes() {
2087
+ const spawnRadius = this.#opt("spawnRadius");
2088
+ const maxVelocity = this.#opt("maxVelocity");
2089
+ for (const node of this.layout.graph.nodes) {
2090
+ if (!node.initialized) {
2091
+ const theta = Math.random() * 2 * Math.PI;
2092
+ const r = Math.random() * spawnRadius;
2093
+ node.x = Math.cos(theta) * r;
2094
+ node.y = Math.sin(theta) * r;
2095
+ const phi = Math.random() * 2 * Math.PI;
2096
+ const speed = (0.3 + Math.random() * 0.7) * maxVelocity;
2097
+ node.vx = Math.cos(phi) * speed;
2098
+ node.vy = Math.sin(phi) * speed;
2099
+ node.ax = 0;
2100
+ node.ay = 0;
2101
+ node.initialized = true;
2102
+ } else {
2103
+ node.vx ??= 0;
2104
+ node.vy ??= 0;
2105
+ node.ax ??= 0;
2106
+ node.ay ??= 0;
2107
+ }
2108
+ node.r ??= 6;
2109
+ node.history = [
2110
+ {
2111
+ x: node.x ?? 0,
2112
+ y: node.y ?? 0
2113
+ }
2114
+ ];
2115
+ }
2116
+ }
2117
+ startTimer() {
2118
+ this.stopTimer();
2119
+ this.#timer = timer2(() => this.tick());
2120
+ }
2121
+ stopTimer() {
2122
+ this.#timer?.stop();
2123
+ this.#timer = void 0;
2124
+ }
2125
+ /**
2126
+ * One simulation step. Modeled on `tick` in Swarm.tsx, but operating in the
2127
+ * SVG centered-origin coordinate space and writing to `node.x/y` directly so
2128
+ * the existing `GraphRenderer.applyPositions` reads them unchanged.
2129
+ */
2130
+ tick() {
2131
+ const size = this.context.size;
2132
+ if (!size) {
2133
+ return;
2134
+ }
2135
+ const { width, height } = size;
2136
+ const halfW = width / 2;
2137
+ const halfH = height / 2;
2138
+ const nodes = this.layout.graph.nodes;
2139
+ const maxVelocity = this.#opt("maxVelocity");
2140
+ const alignmentW = this.#opt("alignment") / 100;
2141
+ const cohesionW = this.#opt("cohesion") / 100;
2142
+ const separationW = this.#opt("separation") / 100;
2143
+ const avoidanceW = this.#opt("avoidance") / 10;
2144
+ const cursorRepel = this.#opt("cursorRepel");
2145
+ const cursor = cursorRepel > 0 ? this.#cursor : null;
2146
+ for (const b1 of nodes) {
2147
+ let ax = 0;
2148
+ let ay = 0;
2149
+ let alignX = 0;
2150
+ let alignY = 0;
2151
+ let alignActive = false;
2152
+ let cohX = 0;
2153
+ let cohY = 0;
2154
+ let cohActive = false;
2155
+ let sepX = 0;
2156
+ let sepY = 0;
2157
+ let sepActive = false;
2158
+ let avoidX = 0;
2159
+ let avoidY = 0;
2160
+ let avoidActive = false;
2161
+ if (cursor) {
2162
+ const dx = cursor.x - (b1.x ?? 0);
2163
+ const dy = cursor.y - (b1.y ?? 0);
2164
+ const distSq = dx * dx + dy * dy;
2165
+ if (distSq > 0 && distSq < cursorRepel * cursorRepel) {
2166
+ const dist = Math.sqrt(distSq);
2167
+ avoidX = -dx / dist * (1 / dist);
2168
+ avoidY = -dy / dist * (1 / dist);
2169
+ avoidActive = true;
2170
+ }
2171
+ }
2172
+ if (!avoidActive) {
2173
+ for (const b2 of nodes) {
2174
+ if (b1 === b2) {
2175
+ continue;
2176
+ }
2177
+ const dx = (b2.x ?? 0) - (b1.x ?? 0);
2178
+ const dy = (b2.y ?? 0) - (b1.y ?? 0);
2179
+ const distSq = dx * dx + dy * dy;
2180
+ if (distSq === 0) {
2181
+ continue;
2182
+ }
2183
+ const dist = Math.sqrt(distSq);
2184
+ if (dist < SEPARATION_DISTANCE) {
2185
+ sepX += -dx / dist * (1 / dist);
2186
+ sepY += -dy / dist * (1 / dist);
2187
+ sepActive = true;
2188
+ }
2189
+ if (dist < SWARMMATE_RADIUS) {
2190
+ cohX += dx;
2191
+ cohY += dy;
2192
+ cohActive = true;
2193
+ alignX += b2.vx ?? 0;
2194
+ alignY += b2.vy ?? 0;
2195
+ alignActive = true;
2196
+ }
2197
+ }
2198
+ }
2199
+ const applyForce = (fx, fy, weight, active) => {
2200
+ if (!active || weight === 0) {
2201
+ return;
2202
+ }
2203
+ const len = Math.sqrt(fx * fx + fy * fy);
2204
+ if (len === 0) {
2205
+ return;
2206
+ }
2207
+ const sx = fx * maxVelocity / len - (b1.vx ?? 0);
2208
+ const sy = fy * maxVelocity / len - (b1.vy ?? 0);
2209
+ const slen = Math.sqrt(sx * sx + sy * sy);
2210
+ if (slen > weight) {
2211
+ ax += sx * weight / slen;
2212
+ ay += sy * weight / slen;
2213
+ } else {
2214
+ ax += sx;
2215
+ ay += sy;
2216
+ }
2217
+ };
2218
+ applyForce(alignX, alignY, alignmentW, alignActive);
2219
+ applyForce(cohX, cohY, cohesionW, cohActive);
2220
+ applyForce(sepX, sepY, separationW, sepActive);
2221
+ applyForce(avoidX, avoidY, avoidanceW, avoidActive);
2222
+ b1.ax = ax;
2223
+ b1.ay = ay;
2224
+ }
2225
+ const trailLength = Math.max(0, Math.round(this.#opt("trailLength")));
2226
+ for (const b of nodes) {
2227
+ let vx = (b.vx ?? 0) + (b.ax ?? 0);
2228
+ let vy = (b.vy ?? 0) + (b.ay ?? 0);
2229
+ const vlen = Math.sqrt(vx * vx + vy * vy);
2230
+ if (vlen > maxVelocity) {
2231
+ vx = vx * maxVelocity / vlen;
2232
+ vy = vy * maxVelocity / vlen;
2233
+ }
2234
+ b.vx = vx;
2235
+ b.vy = vy;
2236
+ if (trailLength > 0) {
2237
+ const history = b.history ?? (b.history = []);
2238
+ history.push({
2239
+ x: b.x ?? 0,
2240
+ y: b.y ?? 0
2241
+ });
2242
+ if (history.length > trailLength) {
2243
+ history.splice(0, history.length - trailLength);
2244
+ }
2245
+ }
2246
+ let x = (b.x ?? 0) + vx;
2247
+ let y = (b.y ?? 0) + vy;
2248
+ let wrapped = false;
2249
+ if (x > halfW) {
2250
+ x -= width;
2251
+ wrapped = true;
2252
+ } else if (x < -halfW) {
2253
+ x += width;
2254
+ wrapped = true;
2255
+ }
2256
+ if (y > halfH) {
2257
+ y -= height;
2258
+ wrapped = true;
2259
+ } else if (y < -halfH) {
2260
+ y += height;
2261
+ wrapped = true;
2262
+ }
2263
+ if (wrapped && b.history) {
2264
+ b.history.length = 0;
2265
+ }
2266
+ b.x = x;
2267
+ b.y = y;
2268
+ }
2269
+ for (const edge of this.layout.graph.edges) {
2270
+ const sx = edge.source.x ?? 0;
2271
+ const sy = edge.source.y ?? 0;
2272
+ const tx = edge.target.x ?? 0;
2273
+ const ty = edge.target.y ?? 0;
2274
+ edge.path = `M ${sx} ${sy} Q 0 0 ${tx} ${ty}`;
2275
+ }
2276
+ this.emitUpdate("positions");
2277
+ }
2278
+ };
2279
+
1337
2280
  // src/graph/renderer/graph-renderer.ts
1338
2281
  import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
1339
2282
  import * as Clipper from "js-clipper";
1340
- import { log as log5 } from "@dxos/log";
2283
+ import { log as log10 } from "@dxos/log";
1341
2284
 
1342
2285
  // src/graph/renderer/bullets.ts
1343
2286
  import { easeLinear, interpolate, select as select3 } from "d3";
@@ -1370,8 +2313,6 @@ var createBullets = (group, nodeId, options = {}) => {
1370
2313
  };
1371
2314
 
1372
2315
  // src/graph/renderer/renderer.ts
1373
- import { invariant as invariant3 } from "@dxos/invariant";
1374
- var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
1375
2316
  var Renderer = class {
1376
2317
  _context;
1377
2318
  _root;
@@ -1386,34 +2327,48 @@ var Renderer = class {
1386
2327
  get context() {
1387
2328
  return this._context;
1388
2329
  }
2330
+ /**
2331
+ * Returns the SVG group root if mounted.
2332
+ * The ref may be null between mount/unmount cycles or before the SVG container has sized.
2333
+ * Callers should treat null as "skip this render" rather than as an error.
2334
+ */
1389
2335
  get root() {
1390
- invariant3(this._root.current, "SVG root is not initialized", {
1391
- F: __dxlog_file7,
1392
- L: 40,
1393
- S: this,
1394
- A: [
1395
- "this._root.current",
1396
- "'SVG root is not initialized'"
1397
- ]
1398
- });
1399
2336
  return this._root.current;
1400
2337
  }
1401
2338
  get options() {
1402
2339
  return this._options;
1403
2340
  }
2341
+ /**
2342
+ * Fast path invoked when only positions changed.
2343
+ * Default falls back to a full `render`; subclasses can override to skip
2344
+ * enter/exit joins and attribute callbacks for per-tick updates.
2345
+ */
2346
+ applyPositions(layout) {
2347
+ this.render(layout);
2348
+ }
1404
2349
  };
1405
2350
 
1406
2351
  // src/graph/renderer/graph-renderer.ts
1407
- var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
2352
+ var __dxlog_file12 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
1408
2353
  var createLine2 = line2();
2354
+ var EDGE_FADE_MS = 300;
2355
+ var NODE_HIDE_MS = 500;
1409
2356
  var GraphRenderer = class extends Renderer {
2357
+ // First render of this instance — used to clear DOM left behind by a previous
2358
+ // renderer pointing at the same `<g>` (e.g. when the consumer swaps projectors
2359
+ // and a new renderer is constructed for the same SVG root). Without this, the
2360
+ // previous variant's node shapes (e.g. circles) would persist as d3.join sees
2361
+ // them in the `update` set instead of `enter`.
2362
+ #firstRender = true;
1410
2363
  render(layout) {
1411
- log5("render", layout, {
1412
- F: __dxlog_file8,
1413
- L: 63,
1414
- S: this,
1415
- C: (f, a) => f(...a)
1416
- });
2364
+ if (!this.root) {
2365
+ return;
2366
+ }
2367
+ if (this.#firstRender) {
2368
+ this.#firstRender = false;
2369
+ this.root.replaceChildren();
2370
+ }
2371
+ log10("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 35, S: this });
1417
2372
  const root = select4(this.root);
1418
2373
  if (layout.guides) {
1419
2374
  root.selectAll("g.dx-guides").data([
@@ -1471,37 +2426,92 @@ var GraphRenderer = class extends Renderer {
1471
2426
  {
1472
2427
  id: "edges"
1473
2428
  }
1474
- ], (d) => d.id).join("g").classed("dx-edges", true);
2429
+ ], (d) => d.id).join("g").classed("dx-edges", true).style("opacity", this.options.edgeOpacity != null ? String(this.options.edgeOpacity) : null);
1475
2430
  const nodeGroup = root.selectAll("g.dx-nodes").data([
1476
2431
  {
1477
2432
  id: "nodes"
1478
2433
  }
1479
2434
  ], (d) => d.id).join("g").classed("dx-nodes", true);
1480
- 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", 1).classed("dx-node", true).call(createNode, this.options), (update) => update.call(updateNode2, this.options), (exit) => {
2435
+ 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) => {
1481
2436
  return exit.transition().ease(easeCubicOut).duration(300).attr("opacity", 0).on("end", function(d) {
1482
2437
  select4(this).remove();
1483
2438
  });
1484
- }).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
1485
- 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.call(updateEdge, this.options, nodeGroup).each((d) => {
1486
- }), (exit) => exit.remove()).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
2439
+ }).call(updateNode2, this.options).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
2440
+ edgeGroup.selectAll("g.dx-edge").data(layout.graph?.edges ?? [], (d) => d.id).join(
2441
+ (enter) => enter.append("g").attr("data-id", (d) => d.id).classed("dx-edge", true).call(createEdge, this.options),
2442
+ (update) => update,
2443
+ // Exit fade: edges removed by a topology change (e.g. variant switch from cluster
2444
+ // back to force replaces hierarchy edges with data edges) ease out rather than pop.
2445
+ (exit) => exit.transition().ease(easeCubicOut).duration(EDGE_FADE_MS).attr("opacity", 0).on("end", function() {
2446
+ select4(this).remove();
2447
+ })
2448
+ ).call(updateEdge, this.options, nodeGroup).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
2449
+ }
2450
+ /**
2451
+ * Fast positions-only update. Skips enter/exit, attribute callbacks, label sizing,
2452
+ * and the subgraph hull pass; just writes `transform` per node and `d` per edge.
2453
+ * Called per simulation tick / animation frame.
2454
+ */
2455
+ applyPositions(layout) {
2456
+ if (!this.root) {
2457
+ return;
2458
+ }
2459
+ const root = select4(this.root);
2460
+ const applyNode = this.options.applyNode;
2461
+ 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) {
2462
+ applyNode(this, d);
2463
+ } : () => {
2464
+ });
2465
+ root.select("g.dx-edges").selectAll("g.dx-edge").selectAll("path").attr("d", function() {
2466
+ const edge = select4(this.parentElement).datum();
2467
+ if (edge.path) {
2468
+ return edge.path;
2469
+ }
2470
+ const { source, target } = edge;
2471
+ if (!source.initialized || !target.initialized) {
2472
+ return null;
2473
+ }
2474
+ return createLine2(getCircumferencePoints([
2475
+ source.x,
2476
+ source.y
2477
+ ], [
2478
+ target.x,
2479
+ target.y
2480
+ ], source.r, target.r));
2481
+ });
1487
2482
  }
1488
2483
  /**
1489
2484
  * Trigger path bullets.
1490
2485
  * @param node
1491
2486
  */
1492
2487
  fireBullet(node) {
2488
+ if (!this.root) {
2489
+ return;
2490
+ }
1493
2491
  select4(this.root).selectAll("g.dx-edges").selectAll("path").call(createBullets(this.root, node.id));
1494
2492
  }
1495
2493
  };
2494
+ var SHAPE_CLASS = "dx-shape";
2495
+ var renderCustomShape = (group, options) => {
2496
+ group.each(function(d) {
2497
+ const g = select4(this);
2498
+ g.selectAll(`.${SHAPE_CLASS}`).remove();
2499
+ const shapeGroup = g.append("g").classed(SHAPE_CLASS, true);
2500
+ options.renderNode(shapeGroup, d);
2501
+ });
2502
+ };
1496
2503
  var createNode = (group, options) => {
1497
- const circle = group.append("circle");
2504
+ const useCustom = !!options.renderNode;
2505
+ if (useCustom) {
2506
+ renderCustomShape(group, options);
2507
+ }
2508
+ const hitTarget = useCustom ? group : group.append("circle");
1498
2509
  if (options.drag) {
1499
- circle.call(options.drag);
2510
+ hitTarget.call(options.drag);
1500
2511
  }
1501
2512
  if (options.onNodeClick) {
1502
- group.on("click", (event) => {
1503
- const node = select4(event.target).datum();
1504
- options.onNodeClick(node, event);
2513
+ group.on("click", (event, d) => {
2514
+ options.onNodeClick(d, event);
1505
2515
  });
1506
2516
  }
1507
2517
  if (options.labels && !options.onNodePointerEnter) {
@@ -1510,24 +2520,34 @@ var createNode = (group, options) => {
1510
2520
  g.append("rect");
1511
2521
  g.append("text").style("dominant-baseline", "middle");
1512
2522
  }
1513
- if (options.onNodePointerEnter) {
1514
- circle.on("pointerenter", function(event) {
1515
- const node = select4(this.parentElement).datum();
1516
- options.onNodePointerEnter(node, event);
2523
+ if (options.onNodePointerEnter || options.onNodePointerLeave || options.highlightOnHover) {
2524
+ hitTarget.on("pointerenter", function(event) {
2525
+ const node = select4(useCustom ? this : this.parentElement).datum();
2526
+ options.onNodePointerEnter?.(node, event);
2527
+ if (options.highlightOnHover) {
2528
+ applyHoverHighlight(this.closest("g.dx-graph"), node.id);
2529
+ }
2530
+ });
2531
+ hitTarget.on("pointerleave", function(event) {
2532
+ const node = select4(useCustom ? this : this.parentElement).datum();
2533
+ options.onNodePointerLeave?.(node, event);
2534
+ if (options.highlightOnHover) {
2535
+ applyHoverHighlight(this.closest("g.dx-graph"), null);
2536
+ }
1517
2537
  });
1518
2538
  group.attr("data-hover", "handled");
1519
- } else if (options.highlight !== false) {
1520
- circle.on("pointerenter", function() {
2539
+ } else if (options.highlight !== false && !useCustom) {
2540
+ hitTarget.on("pointerenter", function() {
1521
2541
  select4(this.closest("g.dx-node")).raise();
1522
2542
  if (options.labels) {
1523
- select4(this.parentElement).classed("dx-active", true).classed("dx-highlight", true);
2543
+ select4(this.parentElement).classed("dx-node-active", true).classed("dx-highlight", true);
1524
2544
  }
1525
2545
  });
1526
2546
  group.on("pointerleave", function() {
1527
2547
  if (options.labels) {
1528
- select4(this).classed("dx-active", false);
2548
+ select4(this).classed("dx-node-active", false);
1529
2549
  setTimeout(() => {
1530
- if (!select4(this).classed("dx-active")) {
2550
+ if (!select4(this).classed("dx-node-active")) {
1531
2551
  select4(this).classed("dx-highlight", false);
1532
2552
  }
1533
2553
  }, 300);
@@ -1539,6 +2559,11 @@ var updateNode2 = (group, options) => {
1539
2559
  group.attr("transform", (d) => {
1540
2560
  return d.x != null && d.y != null ? `translate(${d.x},${d.y})` : void 0;
1541
2561
  });
2562
+ group.classed("dx-hidden", (d) => d.hidden ?? false);
2563
+ group.transition("hide").ease(easeCubicOut).duration(NODE_HIDE_MS).attr("opacity", (d) => d.hidden ? 0 : 1);
2564
+ if (options.renderNode) {
2565
+ renderCustomShape(group, options);
2566
+ }
1542
2567
  if (options.attributes?.node) {
1543
2568
  try {
1544
2569
  group.each((d, i, nodes) => {
@@ -1554,18 +2579,15 @@ var updateNode2 = (group, options) => {
1554
2579
  }
1555
2580
  });
1556
2581
  } catch (error) {
1557
- log5.error("updateNode", {
2582
+ log10.error("updateNode", {
1558
2583
  error: error?.message
1559
- }, {
1560
- F: __dxlog_file8,
1561
- L: 305,
1562
- S: void 0,
1563
- C: (f, a) => f(...a)
1564
- });
2584
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 303, S: void 0 });
1565
2585
  }
1566
2586
  }
1567
2587
  const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
1568
- groupOrTransition.select("circle").attr("r", (d) => d.r ?? 16);
2588
+ if (!options.renderNode) {
2589
+ groupOrTransition.select("circle").attr("r", (d) => d.r ?? 16);
2590
+ }
1569
2591
  if (options.labels) {
1570
2592
  const bx = 1;
1571
2593
  const px = 4;
@@ -1610,18 +2632,17 @@ var updateEdge = (group, options, nodeGroup) => {
1610
2632
  }
1611
2633
  });
1612
2634
  } catch (error) {
1613
- log5.error("updateEdge", {
2635
+ log10.error("updateEdge", {
1614
2636
  error: error?.message
1615
- }, {
1616
- F: __dxlog_file8,
1617
- L: 417,
1618
- S: void 0,
1619
- C: (f, a) => f(...a)
1620
- });
2637
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 371, S: void 0 });
1621
2638
  }
1622
2639
  const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
1623
2640
  groupOrTransition.selectAll("path").attr("d", function() {
1624
- const { source, target } = select4(this.parentElement).datum();
2641
+ const edge = select4(this.parentElement).datum();
2642
+ if (edge.path) {
2643
+ return edge.path;
2644
+ }
2645
+ const { source, target } = edge;
1625
2646
  if (!source.initialized || !target.initialized) {
1626
2647
  return;
1627
2648
  }
@@ -1634,6 +2655,62 @@ var updateEdge = (group, options, nodeGroup) => {
1634
2655
  ], source.r, target.r));
1635
2656
  });
1636
2657
  };
2658
+ var applyHoverHighlight = (root, focusedId) => {
2659
+ if (!root) {
2660
+ return;
2661
+ }
2662
+ const r = select4(root);
2663
+ const on = focusedId != null;
2664
+ const outgoing = /* @__PURE__ */ new Set();
2665
+ const incoming = /* @__PURE__ */ new Set();
2666
+ if (on) {
2667
+ r.select("g.dx-edges").selectAll("g.dx-edge").each((edge) => {
2668
+ if (edge.source.id === focusedId) {
2669
+ outgoing.add(edge.target.id);
2670
+ }
2671
+ if (edge.target.id === focusedId) {
2672
+ incoming.add(edge.source.id);
2673
+ }
2674
+ });
2675
+ }
2676
+ r.select("g.dx-edges").selectAll("g.dx-edge").each(function(edge) {
2677
+ const path = select4(this).select("path:not(.dx-click)");
2678
+ if (!on) {
2679
+ path.style("stroke", null).style("stroke-width", null).style("opacity", null);
2680
+ return;
2681
+ }
2682
+ if (edge.source.id === focusedId) {
2683
+ path.style("stroke", "var(--color-orange-500)").style("stroke-width", "1.5px").style("opacity", null);
2684
+ } else if (edge.target.id === focusedId) {
2685
+ path.style("stroke", "var(--color-sky-500)").style("stroke-width", "1.5px").style("opacity", null);
2686
+ } else {
2687
+ path.style("stroke", null).style("stroke-width", null).style("opacity", "0.8");
2688
+ }
2689
+ });
2690
+ r.select("g.dx-nodes").selectAll("g.dx-node").each(function(node) {
2691
+ const groupSel = select4(this);
2692
+ const shape = groupSel.select("circle, rect");
2693
+ if (node.hidden) {
2694
+ return;
2695
+ }
2696
+ if (!on) {
2697
+ groupSel.style("opacity", null);
2698
+ shape.style("stroke", null).style("stroke-width", null);
2699
+ return;
2700
+ }
2701
+ const connected = outgoing.has(node.id) || incoming.has(node.id);
2702
+ if (node.id === focusedId) {
2703
+ groupSel.style("opacity", null);
2704
+ shape.style("stroke", null).style("stroke-width", null);
2705
+ } else if (connected) {
2706
+ groupSel.style("opacity", null);
2707
+ shape.style("stroke", "var(--color-orange-400)").style("stroke-width", "2.5px");
2708
+ } else {
2709
+ groupSel.style("opacity", "0.4");
2710
+ shape.style("stroke", null).style("stroke-width", null);
2711
+ }
2712
+ });
2713
+ };
1637
2714
  var applyClasses = (el, classes) => {
1638
2715
  for (const [className, value] of Object.entries(classes)) {
1639
2716
  el.classed(className, value);
@@ -1672,6 +2749,45 @@ var findConnectedComponents = (graph) => {
1672
2749
  return components;
1673
2750
  };
1674
2751
 
2752
+ // src/graph/renderer/labels.ts
2753
+ var DEFAULT_DURATION = 200;
2754
+ var DEFAULT_OFFSET = 4;
2755
+ var getTarget = (node) => {
2756
+ const tx = node.tx;
2757
+ const ty = node.ty;
2758
+ return {
2759
+ x: tx ?? node.x ?? 0,
2760
+ y: ty ?? node.y ?? 0
2761
+ };
2762
+ };
2763
+ var appendRadialLeafLabel = (group, node, label, r, options = {}) => {
2764
+ if (!label) {
2765
+ return;
2766
+ }
2767
+ const { delay = 0, duration = DEFAULT_DURATION, offset = DEFAULT_OFFSET, className = "dx-cluster-label" } = options;
2768
+ const { x: targetX, y: targetY } = getTarget(node);
2769
+ const angleDeg = Math.atan2(targetY, targetX) * 180 / Math.PI;
2770
+ const flipped = angleDeg > 90 || angleDeg < -90;
2771
+ 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);
2772
+ };
2773
+ var appendRadialGroupLabel = (group, node, label, r, options = {}) => {
2774
+ if (!label) {
2775
+ return;
2776
+ }
2777
+ const { delay = 0, duration = DEFAULT_DURATION, offset = DEFAULT_OFFSET, className = "dx-cluster-label dx-cluster-label-group" } = options;
2778
+ const { x: targetX, y: targetY } = getTarget(node);
2779
+ const angleDeg = Math.atan2(targetY, targetX) * 180 / Math.PI;
2780
+ const flipped = angleDeg > 90 || angleDeg < -90;
2781
+ 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);
2782
+ };
2783
+ var appendRootLabel = (group, label, r, options = {}) => {
2784
+ if (!label) {
2785
+ return;
2786
+ }
2787
+ const { delay = 0, duration = DEFAULT_DURATION, offset = 6, className = "dx-cluster-label dx-cluster-label-root" } = options;
2788
+ 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);
2789
+ };
2790
+
1675
2791
  // src/graph/renderer/linker.ts
1676
2792
  import { line as line3 } from "d3";
1677
2793
  var createLine3 = line3();
@@ -2014,8 +3130,8 @@ var useZoom = (options = defaultZoomOptions) => {
2014
3130
  };
2015
3131
 
2016
3132
  // src/components/Graph/Graph.tsx
2017
- var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
2018
- var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
3133
+ var __dxlog_file13 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
3134
+ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, onPointerMove, onPointerLeave, ...props }, forwardedRef) => {
2019
3135
  const context = useSvgContext();
2020
3136
  const graphRef = useRef3(null);
2021
3137
  const { projector, renderer } = useMemo3(() => {
@@ -2032,8 +3148,18 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
2032
3148
  arrows: {
2033
3149
  end: arrows
2034
3150
  },
2035
- onNodeClick: onSelect ? (node, event) => onSelect(node, event) : void 0,
2036
- onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0
3151
+ // Projector intercept first so built-in interactions (e.g. cluster collapse) can
3152
+ // run without consumers wiring them. Returning true suppresses the user handler.
3153
+ onNodeClick: (node, event) => {
3154
+ if (projector2.handleNodeClick(node, event)) {
3155
+ return;
3156
+ }
3157
+ onSelect?.(node, event);
3158
+ },
3159
+ onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0,
3160
+ // Pair pointerenter with leave so consumers can clear hover-driven previews.
3161
+ // The callback receives `null` on leave (event still carries the source).
3162
+ onNodePointerLeave: onInspect ? (_node, event) => onInspect(null, event) : void 0
2037
3163
  });
2038
3164
  }
2039
3165
  return {
@@ -2044,7 +3170,17 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
2044
3170
  context,
2045
3171
  projectorProp,
2046
3172
  rendererProp,
2047
- drag2
3173
+ drag2,
3174
+ arrows,
3175
+ onSelect,
3176
+ onInspect,
3177
+ props.labels,
3178
+ props.subgraphs,
3179
+ props.attributes,
3180
+ props.renderNode,
3181
+ props.highlightOnHover,
3182
+ props.applyNode,
3183
+ props.edgeOpacity
2048
3184
  ]);
2049
3185
  useImperativeHandle(forwardedRef, () => ({
2050
3186
  refresh: () => {
@@ -2062,23 +3198,26 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
2062
3198
  renderer
2063
3199
  ]);
2064
3200
  useEffect3(() => {
3201
+ const cleanup = combine(
3202
+ // Subscribe to model changes if reactive model.
3203
+ model ? model.subscribe(() => {
3204
+ projector.updateData(model?.graph);
3205
+ }) : void 0,
3206
+ projector.updated.on(({ layout, kind }) => {
3207
+ try {
3208
+ if (kind === "positions") {
3209
+ renderer.applyPositions(layout);
3210
+ } else {
3211
+ renderer.render(layout);
3212
+ }
3213
+ } catch (error) {
3214
+ log11.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 95, S: void 0 });
3215
+ void projector.stop();
3216
+ }
3217
+ })
3218
+ );
2065
3219
  projector.updateData(model?.graph);
2066
- const unsubscribeModel = model && "subscribe" in model ? model.subscribe(() => {
2067
- projector.updateData(model?.graph);
2068
- }) : void 0;
2069
- return combine(unsubscribeModel, projector.updated.on(({ layout }) => {
2070
- try {
2071
- renderer.render(layout);
2072
- } catch (error) {
2073
- void projector.stop();
2074
- log6.catch(error, void 0, {
2075
- F: __dxlog_file9,
2076
- L: 115,
2077
- S: void 0,
2078
- C: (f, a) => f(...a)
2079
- });
2080
- }
2081
- }));
3220
+ return cleanup;
2082
3221
  }, [
2083
3222
  model,
2084
3223
  projector,
@@ -2092,6 +3231,49 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
2092
3231
  }, [
2093
3232
  projector
2094
3233
  ]);
3234
+ useEffect3(() => {
3235
+ if (!onPointerMove && !onPointerLeave) {
3236
+ return;
3237
+ }
3238
+ const svg = context.svg;
3239
+ if (!svg) {
3240
+ return;
3241
+ }
3242
+ const previousPointerEvents = svg.style.pointerEvents;
3243
+ svg.style.pointerEvents = "all";
3244
+ const handleMove = (event) => {
3245
+ if (!onPointerMove) {
3246
+ return;
3247
+ }
3248
+ const target = graphRef.current;
3249
+ const ctm = target?.getScreenCTM();
3250
+ if (!target || !ctm) {
3251
+ return;
3252
+ }
3253
+ const point = svg.createSVGPoint();
3254
+ point.x = event.clientX;
3255
+ point.y = event.clientY;
3256
+ const modelPoint = point.matrixTransform(ctm.inverse());
3257
+ onPointerMove({
3258
+ x: modelPoint.x,
3259
+ y: modelPoint.y
3260
+ }, event);
3261
+ };
3262
+ const handleLeave = (event) => {
3263
+ onPointerLeave?.(event);
3264
+ };
3265
+ svg.addEventListener("pointermove", handleMove);
3266
+ svg.addEventListener("pointerleave", handleLeave);
3267
+ return () => {
3268
+ svg.removeEventListener("pointermove", handleMove);
3269
+ svg.removeEventListener("pointerleave", handleLeave);
3270
+ svg.style.pointerEvents = previousPointerEvents;
3271
+ };
3272
+ }, [
3273
+ context,
3274
+ onPointerMove,
3275
+ onPointerLeave
3276
+ ]);
2095
3277
  return /* @__PURE__ */ React.createElement("g", {
2096
3278
  ref: graphRef,
2097
3279
  className: mx("dx-graph", classNames)
@@ -2106,21 +3288,27 @@ import { feature, mesh } from "topojson-client";
2106
3288
  var Mesh = ({ radius = 16, value = 0.5 }) => {
2107
3289
  const { svg, size } = useSvgContext();
2108
3290
  useEffect4(() => {
2109
- if (size) {
2110
- const topology = hexTopology(size, radius, value);
2111
- const projection = hexProjection(radius);
2112
- const path = geoPath().projection(projection);
2113
- 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);
2114
- select7(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
2115
- const redraw = (border) => {
2116
- border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
2117
- };
2118
- select7(svg).append("path").attr("class", "border").call(redraw);
3291
+ if (!size) {
3292
+ return;
2119
3293
  }
3294
+ const topology = hexTopology(size, radius, value);
3295
+ const projection = hexProjection(radius);
3296
+ const path = geoPath().projection(projection);
3297
+ const root = select7(svg).selectAll("g.dx-mesh-root").data([
3298
+ null
3299
+ ]).join("g").classed("dx-mesh-root", true);
3300
+ root.selectAll("*").remove();
3301
+ 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);
3302
+ root.append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
3303
+ const redraw = (border) => {
3304
+ border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
3305
+ };
3306
+ root.append("path").attr("class", "border").call(redraw);
2120
3307
  }, [
2121
3308
  svg,
2122
3309
  size,
2123
- value
3310
+ value,
3311
+ radius
2124
3312
  ]);
2125
3313
  return null;
2126
3314
  };
@@ -2231,30 +3419,86 @@ var hexProjection = (radius) => {
2231
3419
  };
2232
3420
  };
2233
3421
 
2234
- // src/components/SVG/Grid.tsx
2235
- import React2 from "react";
3422
+ // src/components/SVG/FPS.tsx
3423
+ import React2, { useEffect as useEffect5, useState } from "react";
2236
3424
  import { mx as mx2 } from "@dxos/ui-theme";
3425
+ var PADDING = 8;
3426
+ var FPS = ({ classNames, corner = "top-right", margin = PADDING }) => {
3427
+ const context = useSvgContext();
3428
+ const [size, setSize] = useState(context.size);
3429
+ const [fps, setFps] = useState(null);
3430
+ useEffect5(() => {
3431
+ setSize(context.size);
3432
+ return context.resized.on((ctx) => setSize(ctx.size));
3433
+ }, [
3434
+ context
3435
+ ]);
3436
+ useEffect5(() => {
3437
+ let frames = 0;
3438
+ let windowStart = performance.now();
3439
+ let rafId = 0;
3440
+ const loop = (now) => {
3441
+ frames++;
3442
+ const elapsed = now - windowStart;
3443
+ if (elapsed >= 1e3) {
3444
+ setFps(frames * 1e3 / elapsed);
3445
+ frames = 0;
3446
+ windowStart = now;
3447
+ }
3448
+ rafId = requestAnimationFrame(loop);
3449
+ };
3450
+ rafId = requestAnimationFrame(loop);
3451
+ return () => cancelAnimationFrame(rafId);
3452
+ }, []);
3453
+ if (!size) {
3454
+ return null;
3455
+ }
3456
+ const halfW = size.width / 2;
3457
+ const halfH = size.height / 2;
3458
+ const left = corner === "top-left" || corner === "bottom-left";
3459
+ const top = corner === "top-left" || corner === "top-right";
3460
+ const x = left ? -halfW + margin : halfW - margin;
3461
+ const y = top ? -halfH + margin : halfH - margin;
3462
+ const textAnchor = left ? "start" : "end";
3463
+ const dominantBaseline = top ? "hanging" : "alphabetic";
3464
+ return /* @__PURE__ */ React2.createElement("g", {
3465
+ className: "dx-fps",
3466
+ style: {
3467
+ pointerEvents: "none"
3468
+ }
3469
+ }, /* @__PURE__ */ React2.createElement("text", {
3470
+ x,
3471
+ y,
3472
+ textAnchor,
3473
+ dominantBaseline,
3474
+ className: mx2("font-mono text-xs fill-neutral-500 tabular-nums", classNames)
3475
+ }, fps == null ? "\u2014 fps" : `${fps.toFixed(0)} fps`));
3476
+ };
3477
+
3478
+ // src/components/SVG/Grid.tsx
3479
+ import React3 from "react";
3480
+ import { mx as mx3 } from "@dxos/ui-theme";
2237
3481
  var Grid = ({ classNames, ...props }) => {
2238
3482
  const { ref } = useGrid(props);
2239
- return /* @__PURE__ */ React2.createElement("g", {
3483
+ return /* @__PURE__ */ React3.createElement("g", {
2240
3484
  ref,
2241
- className: mx2("dx-grid", classNames)
3485
+ className: mx3("dx-grid", classNames)
2242
3486
  });
2243
3487
  };
2244
3488
 
2245
3489
  // src/components/SVG/Markers.tsx
2246
3490
  import { select as select8 } from "d3";
2247
- import React3, { useEffect as useEffect5, useRef as useRef4 } from "react";
3491
+ import React4, { useEffect as useEffect6, useRef as useRef4 } from "react";
2248
3492
  var Markers = ({ arrowSize, className }) => {
2249
3493
  const ref = useRef4(null);
2250
- useEffect5(() => {
3494
+ useEffect6(() => {
2251
3495
  select8(ref.current).call(createMarkers({
2252
3496
  arrowSize
2253
3497
  }));
2254
3498
  }, [
2255
3499
  ref
2256
3500
  ]);
2257
- return /* @__PURE__ */ React3.createElement("defs", {
3501
+ return /* @__PURE__ */ React4.createElement("defs", {
2258
3502
  ref,
2259
3503
  className
2260
3504
  });
@@ -2262,13 +3506,41 @@ var Markers = ({ arrowSize, className }) => {
2262
3506
 
2263
3507
  // src/components/SVG/Root.tsx
2264
3508
  import { select as select9 } from "d3";
2265
- import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4 } from "react";
2266
- import { useResizeDetector } from "react-resize-detector";
2267
- import { mx as mx3 } from "@dxos/ui-theme";
2268
- var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, scale, centered, ...props }, ref) => {
2269
- const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
2270
- refreshRate: 200
3509
+ import React5, { forwardRef as forwardRef2, useEffect as useEffect7, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4, useState as useState2 } from "react";
3510
+ import { composableProps } from "@dxos/react-ui";
3511
+ import { mx as mx4 } from "@dxos/ui-theme";
3512
+ var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props }, ref) => {
3513
+ const [container, setContainer] = useState2(null);
3514
+ const [size, setSize] = useState2({
3515
+ width: 0,
3516
+ height: 0
2271
3517
  });
3518
+ useEffect7(() => {
3519
+ if (!container) {
3520
+ return;
3521
+ }
3522
+ const rect = container.getBoundingClientRect();
3523
+ setSize({
3524
+ width: rect.width,
3525
+ height: rect.height
3526
+ });
3527
+ const observer = new ResizeObserver((entries) => {
3528
+ const entry = entries[0];
3529
+ if (!entry) {
3530
+ return;
3531
+ }
3532
+ const { width: width2, height: height2 } = entry.contentRect;
3533
+ setSize((prev) => prev.width === width2 && prev.height === height2 ? prev : {
3534
+ width: width2,
3535
+ height: height2
3536
+ });
3537
+ });
3538
+ observer.observe(container);
3539
+ return () => observer.disconnect();
3540
+ }, [
3541
+ container
3542
+ ]);
3543
+ const { width, height } = size;
2272
3544
  const context = useMemo4(() => {
2273
3545
  return new SVGContext({
2274
3546
  scale,
@@ -2281,7 +3553,7 @@ var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, scale, centered,
2281
3553
  useImperativeHandle2(ref, () => context, [
2282
3554
  context
2283
3555
  ]);
2284
- useEffect6(() => {
3556
+ useEffect7(() => {
2285
3557
  if (width && height) {
2286
3558
  context.setSize({
2287
3559
  width,
@@ -2295,21 +3567,22 @@ var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, scale, centered,
2295
3567
  height
2296
3568
  ]);
2297
3569
  const ready = width !== 0 && height !== 0;
2298
- return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
3570
+ return /* @__PURE__ */ React5.createElement(SVGContextProvider, {
2299
3571
  value: context
2300
- }, /* @__PURE__ */ React4.createElement("div", {
2301
- ...props,
2302
- ref: containerRef,
2303
- className: mx3("grid grow overflow-hidden", classNames)
2304
- }, /* @__PURE__ */ React4.createElement("svg", {
3572
+ }, /* @__PURE__ */ React5.createElement("div", {
3573
+ ...composableProps(props, {
3574
+ classNames: "dx-expander"
3575
+ }),
3576
+ ref: setContainer
3577
+ }, /* @__PURE__ */ React5.createElement("svg", {
2305
3578
  xmlns: "http://www.w3.org/2000/svg",
2306
3579
  ref: context.ref,
2307
- className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
3580
+ className: mx4("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
2308
3581
  }, ready && children)));
2309
3582
  });
2310
3583
 
2311
3584
  // src/components/SVG/Zoom.tsx
2312
- import React5, { memo, useMemo as useMemo5 } from "react";
3585
+ import React6, { memo, useMemo as useMemo5 } from "react";
2313
3586
  var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
2314
3587
  const options = useMemo5(() => ({
2315
3588
  extent
@@ -2317,7 +3590,7 @@ var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
2317
3590
  JSON.stringify(extent)
2318
3591
  ]);
2319
3592
  const zoom2 = useZoom(options);
2320
- return /* @__PURE__ */ React5.createElement("g", {
3593
+ return /* @__PURE__ */ React6.createElement("g", {
2321
3594
  ref: zoom2.ref,
2322
3595
  className
2323
3596
  }, children);
@@ -2330,7 +3603,8 @@ var SVG = {
2330
3603
  Markers,
2331
3604
  Mesh,
2332
3605
  Zoom,
2333
- Graph
3606
+ Graph,
3607
+ FPS
2334
3608
  };
2335
3609
 
2336
3610
  // src/fx/pulsar.ts
@@ -2358,17 +3632,28 @@ var startAnimation = (pulsar, r, options = {}) => {
2358
3632
  };
2359
3633
  var Pulsar;
2360
3634
  export {
3635
+ CLUSTER_NODE_TYPE_GROUP,
3636
+ CLUSTER_NODE_TYPE_LEAF,
3637
+ CLUSTER_NODE_TYPE_ROOT,
2361
3638
  EventEmitter,
2362
3639
  FractionUtil,
2363
3640
  Graph,
3641
+ GraphBundleProjector,
3642
+ GraphClusterProjector,
2364
3643
  GraphForceProjector,
2365
3644
  GraphHierarchicalProjector,
3645
+ GraphLatticeProjector,
3646
+ GraphPlexusProjector,
2366
3647
  GraphProjector,
2367
3648
  GraphRadialProjector,
2368
3649
  GraphRelationalProjector,
2369
3650
  GraphRenderer,
3651
+ GraphSwarmProjector,
2370
3652
  GridController,
2371
3653
  Mesh,
3654
+ PLEXUS_NODE_TYPE_FOCUS,
3655
+ PLEXUS_NODE_TYPE_OBJECT,
3656
+ PLEXUS_NODE_TYPE_RELATION,
2372
3657
  Projector,
2373
3658
  Pulsar,
2374
3659
  Renderer,
@@ -2379,6 +3664,9 @@ export {
2379
3664
  Screen,
2380
3665
  Vector,
2381
3666
  ZoomHandler,
3667
+ appendRadialGroupLabel,
3668
+ appendRadialLeafLabel,
3669
+ appendRootLabel,
2382
3670
  createGraphDrag,
2383
3671
  createMarkers,
2384
3672
  defaultForceOptions,