@dxos/react-ui-graph 0.8.3 → 0.8.4-main.28f8d3d

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 (92) hide show
  1. package/dist/lib/browser/{chunk-2YMRPQU7.mjs → chunk-HLAKLUDC.mjs} +362 -383
  2. package/dist/lib/browser/{chunk-2YMRPQU7.mjs.map → chunk-HLAKLUDC.mjs.map} +3 -3
  3. package/dist/lib/browser/index.mjs +57 -50
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +4 -4
  7. package/dist/lib/browser/testing/index.mjs.map +2 -2
  8. package/dist/lib/node-esm/{chunk-ITHTKQOY.mjs → chunk-O6GWCXDC.mjs} +362 -383
  9. package/dist/lib/node-esm/{chunk-ITHTKQOY.mjs.map → chunk-O6GWCXDC.mjs.map} +3 -3
  10. package/dist/lib/node-esm/index.mjs +57 -50
  11. package/dist/lib/node-esm/index.mjs.map +3 -3
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing/index.mjs +4 -4
  14. package/dist/lib/node-esm/testing/index.mjs.map +2 -2
  15. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  16. package/dist/types/src/components/Graph/Graph.stories.d.ts +2 -2
  17. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  18. package/dist/types/src/components/Mesh/Mesh.stories.d.ts +1 -1
  19. package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
  21. package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
  22. package/dist/types/src/components/SVG/SVG.d.ts +2 -2
  23. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  24. package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
  25. package/dist/types/src/components/SVG/Zoom.d.ts.map +1 -1
  26. package/dist/types/src/fx/fx.stories.d.ts +1 -1
  27. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  28. package/dist/types/src/graph/projector/graph-drag.d.ts +1 -1
  29. package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
  30. package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
  31. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  32. package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
  33. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
  34. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
  35. package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
  36. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  37. package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
  38. package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
  39. package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
  40. package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
  41. package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
  42. package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
  43. package/dist/types/src/graph/renderer/graph-renderer.d.ts +1 -1
  44. package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
  45. package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
  46. package/dist/types/src/hooks/useZoom.d.ts.map +1 -1
  47. package/dist/types/src/stories/hooks.stories.d.ts +1 -1
  48. package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
  49. package/dist/types/src/testing/hooks.d.ts.map +1 -1
  50. package/dist/types/src/util/index.d.ts +2 -2
  51. package/dist/types/src/util/index.d.ts.map +1 -1
  52. package/dist/types/src/util/screen.d.ts +1 -1
  53. package/dist/types/src/util/screen.d.ts.map +1 -1
  54. package/dist/types/src/util/vector.d.ts +1 -1
  55. package/dist/types/src/util/vector.d.ts.map +1 -1
  56. package/dist/types/tsconfig.tsbuildinfo +1 -1
  57. package/package.json +17 -17
  58. package/src/components/Graph/Graph.stories.tsx +10 -9
  59. package/src/components/Graph/Graph.tsx +1 -1
  60. package/src/components/Mesh/Mesh.stories.tsx +3 -2
  61. package/src/components/Mesh/Mesh.tsx +1 -1
  62. package/src/components/SVG/Grid.tsx +1 -1
  63. package/src/components/SVG/Root.tsx +1 -1
  64. package/src/components/SVG/SVG.tsx +4 -3
  65. package/src/components/SVG/Svg.stories.tsx +2 -1
  66. package/src/components/SVG/Zoom.tsx +1 -1
  67. package/src/fx/fx.stories.tsx +3 -2
  68. package/src/graph/projector/graph-drag.ts +2 -1
  69. package/src/graph/projector/graph-force-projector.ts +3 -2
  70. package/src/graph/projector/graph-forces.ts +1 -1
  71. package/src/graph/projector/graph-hierarchical-projector.ts +2 -1
  72. package/src/graph/projector/graph-projector.ts +4 -3
  73. package/src/graph/projector/graph-radial-projector.ts +3 -2
  74. package/src/graph/projector/graph-relational-projector.ts +2 -1
  75. package/src/graph/projector/projector.ts +1 -1
  76. package/src/graph/renderer/bullets.ts +1 -1
  77. package/src/graph/renderer/graph-renderer.ts +4 -3
  78. package/src/graph/renderer/renderer.ts +1 -1
  79. package/src/hooks/useZoom.ts +1 -1
  80. package/src/stories/hooks.stories.tsx +6 -6
  81. package/src/testing/hooks.ts +3 -2
  82. package/src/util/index.ts +2 -2
  83. package/src/util/screen.test.ts +1 -1
  84. package/src/util/screen.ts +1 -1
  85. package/src/util/vector.ts +1 -1
  86. package/dist/lib/node/chunk-WFHWEMPB.cjs +0 -919
  87. package/dist/lib/node/chunk-WFHWEMPB.cjs.map +0 -7
  88. package/dist/lib/node/index.cjs +0 -1547
  89. package/dist/lib/node/index.cjs.map +0 -7
  90. package/dist/lib/node/meta.json +0 -1
  91. package/dist/lib/node/testing/index.cjs +0 -214
  92. package/dist/lib/node/testing/index.cjs.map +0 -7
@@ -1,10 +1,8 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
- // packages/ui/react-ui-graph/src/util/events.ts
3
+ // src/util/events.ts
4
4
  var EventEmitter = class {
5
- constructor() {
6
- this._listeners = /* @__PURE__ */ new Set();
7
- }
5
+ _listeners = /* @__PURE__ */ new Set();
8
6
  clear() {
9
7
  this._listeners.clear();
10
8
  }
@@ -17,226 +15,202 @@ var EventEmitter = class {
17
15
  }
18
16
  };
19
17
 
20
- // packages/ui/react-ui-graph/src/util/fraction.ts
18
+ // src/util/fraction.ts
21
19
  import { invariant } from "@dxos/invariant";
22
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
20
+ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
23
21
  var FractionUtil = class _FractionUtil {
24
- static {
25
- /**
26
- * Convert number to fraction.
27
- * @param n
28
- */
29
- this.toFraction = (n) => {
30
- return typeof n === "number" ? [
31
- n,
32
- 1
33
- ] : n;
34
- };
35
- }
36
- static {
37
- this.validate = (...fraction) => {
38
- fraction.forEach(([n, d]) => {
39
- if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
40
- throw new Error(`Invalid fraction: ${n}/${d}`);
41
- }
42
- });
43
- return fraction;
44
- };
45
- }
46
- static {
47
- /**
48
- * @param {Fraction}
49
- * Convert to rounded number.
50
- */
51
- this.toNumber = ([n, d]) => {
52
- _FractionUtil.validate([
53
- n,
54
- d
55
- ]);
56
- return n / d;
57
- };
58
- }
59
- static {
60
- /**
61
- * Round the number to the nearest fraction.
62
- * Example: 3/5 => 1/1; 3/5 (precision 2) => 1/2.
63
- * @param {Fraction}
64
- * @param p Precision (e.g., 1/2, 1/4, etc.)
65
- */
66
- this.round = ([n, d], p = 1) => {
67
- _FractionUtil.validate([
68
- n,
69
- d
70
- ]);
71
- const v = Math.round(_FractionUtil.toNumber(_FractionUtil.divide([
72
- n,
73
- d
74
- ], [
75
- 1,
76
- p
77
- ])));
78
- return _FractionUtil.simplify([
79
- v,
80
- p
81
- ]);
82
- };
83
- }
84
- static {
85
- //
86
- // Boolean.
87
- //
88
- /**
89
- * Tests if equals.
90
- * @param n1
91
- * @param n2
92
- */
93
- this.equals = (n1, n2) => {
94
- return n1[0] * n2[1] === n1[1] * n2[0];
95
- };
96
- }
97
- static {
98
- /**
99
- * @param {Fraction}
100
- * True if zero.
101
- */
102
- this.isZero = ([n]) => {
103
- return n === 0;
104
- };
105
- }
106
- static {
107
- //
108
- // Normalization.
109
- //
110
- /**
111
- * Simplify fraction finding LCDs.
112
- * @param n
113
- * @param d
114
- */
115
- this.simplify = ([n, d]) => {
116
- _FractionUtil.validate([
117
- n,
118
- d
119
- ]);
120
- if (d < 1) {
121
- const t = n / d;
122
- if (Math.floor(t) === t) {
123
- n = t;
124
- d = 1;
125
- }
22
+ /**
23
+ * Convert number to fraction.
24
+ * @param n
25
+ */
26
+ static toFraction = (n) => {
27
+ return typeof n === "number" ? [
28
+ n,
29
+ 1
30
+ ] : n;
31
+ };
32
+ static validate = (...fraction) => {
33
+ fraction.forEach(([n, d]) => {
34
+ if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
35
+ throw new Error(`Invalid fraction: ${n}/${d}`);
126
36
  }
127
- const fn = _FractionUtil.factors(n).reverse();
128
- const fd = _FractionUtil.factors(d).reverse();
129
- let c;
130
- for (let i = 0; i < fn.length; i++) {
131
- c = fd.find((n2) => n2 === fn[i]);
132
- if (c) {
133
- return [
134
- n / c,
135
- d / c
136
- ];
137
- }
37
+ });
38
+ return fraction;
39
+ };
40
+ /**
41
+ * @param {Fraction}
42
+ * Convert to rounded number.
43
+ */
44
+ static toNumber = ([n, d]) => {
45
+ _FractionUtil.validate([
46
+ n,
47
+ d
48
+ ]);
49
+ return n / d;
50
+ };
51
+ /**
52
+ * Round the number to the nearest fraction.
53
+ * Example: 3/5 => 1/1; 3/5 (precision 2) => 1/2.
54
+ * @param {Fraction}
55
+ * @param p Precision (e.g., 1/2, 1/4, etc.)
56
+ */
57
+ static round = ([n, d], p = 1) => {
58
+ _FractionUtil.validate([
59
+ n,
60
+ d
61
+ ]);
62
+ const v = Math.round(_FractionUtil.toNumber(_FractionUtil.divide([
63
+ n,
64
+ d
65
+ ], [
66
+ 1,
67
+ p
68
+ ])));
69
+ return _FractionUtil.simplify([
70
+ v,
71
+ p
72
+ ]);
73
+ };
74
+ //
75
+ // Boolean.
76
+ //
77
+ /**
78
+ * Tests if equals.
79
+ * @param n1
80
+ * @param n2
81
+ */
82
+ static equals = (n1, n2) => {
83
+ return n1[0] * n2[1] === n1[1] * n2[0];
84
+ };
85
+ /**
86
+ * @param {Fraction}
87
+ * True if zero.
88
+ */
89
+ static isZero = ([n]) => {
90
+ return n === 0;
91
+ };
92
+ //
93
+ // Normalization.
94
+ //
95
+ /**
96
+ * Simplify fraction finding LCDs.
97
+ * @param n
98
+ * @param d
99
+ */
100
+ static simplify = ([n, d]) => {
101
+ _FractionUtil.validate([
102
+ n,
103
+ d
104
+ ]);
105
+ if (d < 1) {
106
+ const t = n / d;
107
+ if (Math.floor(t) === t) {
108
+ n = t;
109
+ d = 1;
138
110
  }
139
- return [
140
- n,
141
- d
142
- ];
143
- };
144
- }
145
- static {
146
- /**
147
- * Return common factors.
148
- * @param n
149
- */
150
- this.factors = (n) => {
151
- invariant(Number.isFinite(n), `Invalid number: ${n}`, {
152
- F: __dxlog_file,
153
- L: 113,
154
- S: this,
155
- A: [
156
- "Number.isFinite(n)",
157
- "`Invalid number: ${n}`"
158
- ]
159
- });
160
- const factors = [
161
- 1
162
- ];
163
- if (Number.isSafeInteger(n)) {
164
- let f = 1;
165
- do {
166
- if (n % ++f === 0) {
167
- factors.push(f);
168
- }
169
- } while (n / f > 1 && f < 100);
111
+ }
112
+ const fn = _FractionUtil.factors(n).reverse();
113
+ const fd = _FractionUtil.factors(d).reverse();
114
+ let c;
115
+ for (let i = 0; i < fn.length; i++) {
116
+ c = fd.find((n2) => n2 === fn[i]);
117
+ if (c) {
118
+ return [
119
+ n / c,
120
+ d / c
121
+ ];
170
122
  }
171
- return factors;
172
- };
173
- }
174
- static {
175
- //
176
- // Basic arithmetic.
177
- //
178
- /**
179
- * @param n1
180
- * @param n2
181
- */
182
- this.add = (n1, n2) => {
183
- _FractionUtil.validate(n1, n2);
184
- const d = n1[1] * n2[1];
185
- const n = n1[0] * n2[1] + n2[0] * n1[1];
186
- return _FractionUtil.simplify([
187
- n,
188
- d
189
- ]);
190
- };
191
- }
192
- static {
193
- /**
194
- * @param n1
195
- * @param n2
196
- */
197
- this.subtract = (n1, n2) => {
198
- _FractionUtil.validate(n1, n2);
199
- const d = n1[1] * n2[1];
200
- const n = n1[0] * n2[1] - n2[0] * n1[1];
201
- return _FractionUtil.simplify([
202
- n,
203
- d
204
- ]);
205
- };
206
- }
207
- static {
208
- /**
209
- * @param n1
210
- * @param n2
211
- */
212
- this.multiply = (n1, n2) => {
213
- _FractionUtil.validate(n1, n2);
214
- const n = n1[0] * n2[0];
215
- const d = n1[1] * n2[1];
216
- return _FractionUtil.simplify([
217
- n,
218
- d
219
- ]);
220
- };
221
- }
222
- static {
223
- /**
224
- * @param n1
225
- * @param n2
226
- */
227
- this.divide = (n1, n2) => {
228
- _FractionUtil.validate(n1, n2);
229
- const n = n1[0] * n2[1];
230
- const d = n1[1] * n2[0];
231
- return _FractionUtil.simplify([
232
- n,
233
- d
234
- ]);
235
- };
236
- }
123
+ }
124
+ return [
125
+ n,
126
+ d
127
+ ];
128
+ };
129
+ /**
130
+ * Return common factors.
131
+ * @param n
132
+ */
133
+ static factors = (n) => {
134
+ invariant(Number.isFinite(n), `Invalid number: ${n}`, {
135
+ F: __dxlog_file,
136
+ L: 113,
137
+ S: this,
138
+ A: [
139
+ "Number.isFinite(n)",
140
+ "`Invalid number: ${n}`"
141
+ ]
142
+ });
143
+ const factors = [
144
+ 1
145
+ ];
146
+ if (Number.isSafeInteger(n)) {
147
+ let f = 1;
148
+ do {
149
+ if (n % ++f === 0) {
150
+ factors.push(f);
151
+ }
152
+ } while (n / f > 1 && f < 100);
153
+ }
154
+ return factors;
155
+ };
156
+ //
157
+ // Basic arithmetic.
158
+ //
159
+ /**
160
+ * @param n1
161
+ * @param n2
162
+ */
163
+ static add = (n1, n2) => {
164
+ _FractionUtil.validate(n1, n2);
165
+ const d = n1[1] * n2[1];
166
+ const n = n1[0] * n2[1] + n2[0] * n1[1];
167
+ return _FractionUtil.simplify([
168
+ n,
169
+ d
170
+ ]);
171
+ };
172
+ /**
173
+ * @param n1
174
+ * @param n2
175
+ */
176
+ static subtract = (n1, n2) => {
177
+ _FractionUtil.validate(n1, n2);
178
+ const d = n1[1] * n2[1];
179
+ const n = n1[0] * n2[1] - n2[0] * n1[1];
180
+ return _FractionUtil.simplify([
181
+ n,
182
+ d
183
+ ]);
184
+ };
185
+ /**
186
+ * @param n1
187
+ * @param n2
188
+ */
189
+ static multiply = (n1, n2) => {
190
+ _FractionUtil.validate(n1, n2);
191
+ const n = n1[0] * n2[0];
192
+ const d = n1[1] * n2[1];
193
+ return _FractionUtil.simplify([
194
+ n,
195
+ d
196
+ ]);
197
+ };
198
+ /**
199
+ * @param n1
200
+ * @param n2
201
+ */
202
+ static divide = (n1, n2) => {
203
+ _FractionUtil.validate(n1, n2);
204
+ const n = n1[0] * n2[1];
205
+ const d = n1[1] * n2[0];
206
+ return _FractionUtil.simplify([
207
+ n,
208
+ d
209
+ ]);
210
+ };
237
211
  };
238
212
 
239
- // packages/ui/react-ui-graph/src/util/points.ts
213
+ // src/util/points.ts
240
214
  var getCircumferencePoints = (p1, p2, r1 = 0, r2 = 0) => {
241
215
  const [x1, y1] = p1;
242
216
  const [x2, y2] = p2;
@@ -289,9 +263,11 @@ var offsetPoints = (points, distance, closed) => {
289
263
  return out;
290
264
  };
291
265
 
292
- // packages/ui/react-ui-graph/src/util/scale.ts
266
+ // src/util/scale.ts
293
267
  import { zoomIdentity } from "d3";
294
268
  var Scale = class {
269
+ _gridSize;
270
+ _transform;
295
271
  constructor(_gridSize = 32) {
296
272
  this._gridSize = _gridSize;
297
273
  this.model = {
@@ -439,183 +415,177 @@ var Scale = class {
439
415
  (point[1] - y) / k
440
416
  ];
441
417
  }
418
+ /**
419
+ * Map model to screen.
420
+ * Model points are represented by fractions (to preserve precision) and use normal cartesian coordinates.
421
+ */
422
+ model;
423
+ /**
424
+ * Map screen to model.
425
+ * Screen points are represented by floating numbers and use translated SVG coordinates (with the y-axis inverted).
426
+ */
427
+ screen;
442
428
  };
443
429
 
444
- // packages/ui/react-ui-graph/src/util/screen.ts
430
+ // src/util/screen.ts
445
431
  var Screen = class {
446
- static {
447
- this.createBounds = ([x1, y1], [x2, y2], mod = {}) => {
448
- const { constrain, center } = mod;
449
- const x = Math.min(x1, x2);
450
- const y = Math.min(y1, y2);
451
- let width = Math.abs(x2 - x1);
452
- let height = Math.abs(y2 - y1);
453
- if (constrain) {
454
- width = height = Math.max(width, height);
455
- }
456
- if (center) {
457
- return {
458
- x: x - width,
459
- y: y - height,
460
- width: width * 2,
461
- height: height * 2
462
- };
463
- } else {
464
- return {
465
- x,
466
- y,
467
- width,
468
- height
469
- };
470
- }
471
- };
472
- }
473
- static {
474
- this.center = ({ x, y, width, height }) => {
475
- return [
476
- x + width / 2,
477
- y + height / 2
478
- ];
479
- };
480
- }
481
- static {
482
- this.contains = (bounds, point) => {
483
- const [x, y] = point;
484
- if (x < bounds.x || y < bounds.y) {
485
- return false;
486
- }
487
- if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
488
- return false;
489
- }
490
- return true;
491
- };
492
- }
493
- static {
494
- /**
495
- * Distance between two points.
496
- * @param p1
497
- * @param p2
498
- */
499
- this.len = (p1, p2) => {
500
- return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
501
- };
502
- }
503
- static {
504
- /**
505
- * Distance to line segment.
506
- * https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment#1501725
507
- * @param v1
508
- * @param v2
509
- * @param p
510
- */
511
- this.normal = (v1, v2, p) => {
512
- const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
513
- let d;
514
- const len2 = d2(v1, v2);
515
- if (len2 === 0) {
516
- d = d2(p, v1);
517
- } else {
518
- let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
519
- t = Math.max(0, Math.min(1, t));
520
- d = d2(p, [
521
- v1[0] + t * (v2[0] - v1[0]),
522
- v1[1] + t * (v2[1] - v1[1])
523
- ]);
524
- }
525
- return Math.sqrt(d);
526
- };
527
- }
528
- };
529
-
530
- // packages/ui/react-ui-graph/src/util/vector.ts
531
- var Vector = class {
532
- static {
533
- /**
534
- * Convert to Vertex.
535
- * @param x
536
- * @param y
537
- */
538
- this.toVertex = ({ x, y }) => ({
539
- x: FractionUtil.toFraction(x),
540
- y: FractionUtil.toFraction(y)
541
- });
542
- }
543
- static {
544
- /**
545
- * Convert to Bounds.
546
- * @param bounds
547
- */
548
- this.toBounds = ({ x, y, width, height }) => ({
549
- x: FractionUtil.toFraction(x),
550
- y: FractionUtil.toFraction(y),
551
- width: FractionUtil.toFraction(width),
552
- height: FractionUtil.toFraction(height)
553
- });
554
- }
555
- static {
556
- /**
557
- * Calculate center point.
558
- * @param bounds
559
- */
560
- this.center = ({ x, y, width, height }) => {
561
- const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
562
- 1,
563
- 2
564
- ]));
565
- const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
566
- 1,
567
- 2
568
- ]));
432
+ static createBounds = ([x1, y1], [x2, y2], mod = {}) => {
433
+ const { constrain, center } = mod;
434
+ const x = Math.min(x1, x2);
435
+ const y = Math.min(y1, y2);
436
+ let width = Math.abs(x2 - x1);
437
+ let height = Math.abs(y2 - y1);
438
+ if (constrain) {
439
+ width = height = Math.max(width, height);
440
+ }
441
+ if (center) {
569
442
  return {
570
- x: cx,
571
- y: cy
443
+ x: x - width,
444
+ y: y - height,
445
+ width: width * 2,
446
+ height: height * 2
572
447
  };
573
- };
574
- }
575
- static {
576
- /**
577
- * Calculate centered left edge.
578
- * @param bounds
579
- */
580
- this.left = ({ x, y, height }) => {
581
- const cx = x;
582
- const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
583
- 1,
584
- 2
585
- ]));
448
+ } else {
586
449
  return {
587
- x: cx,
588
- y: cy
450
+ x,
451
+ y,
452
+ width,
453
+ height
589
454
  };
455
+ }
456
+ };
457
+ static center = ({ x, y, width, height }) => {
458
+ return [
459
+ x + width / 2,
460
+ y + height / 2
461
+ ];
462
+ };
463
+ static contains = (bounds, point) => {
464
+ const [x, y] = point;
465
+ if (x < bounds.x || y < bounds.y) {
466
+ return false;
467
+ }
468
+ if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
469
+ return false;
470
+ }
471
+ return true;
472
+ };
473
+ /**
474
+ * Distance between two points.
475
+ * @param p1
476
+ * @param p2
477
+ */
478
+ static len = (p1, p2) => {
479
+ return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
480
+ };
481
+ /**
482
+ * Distance to line segment.
483
+ * https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment#1501725
484
+ * @param v1
485
+ * @param v2
486
+ * @param p
487
+ */
488
+ static normal = (v1, v2, p) => {
489
+ const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
490
+ let d;
491
+ const len2 = d2(v1, v2);
492
+ if (len2 === 0) {
493
+ d = d2(p, v1);
494
+ } else {
495
+ let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
496
+ t = Math.max(0, Math.min(1, t));
497
+ d = d2(p, [
498
+ v1[0] + t * (v2[0] - v1[0]),
499
+ v1[1] + t * (v2[1] - v1[1])
500
+ ]);
501
+ }
502
+ return Math.sqrt(d);
503
+ };
504
+ };
505
+
506
+ // src/util/vector.ts
507
+ var Vector = class {
508
+ /**
509
+ * Convert to Vertex.
510
+ * @param x
511
+ * @param y
512
+ */
513
+ static toVertex = ({ x, y }) => ({
514
+ x: FractionUtil.toFraction(x),
515
+ y: FractionUtil.toFraction(y)
516
+ });
517
+ /**
518
+ * Convert to Bounds.
519
+ * @param bounds
520
+ */
521
+ static toBounds = ({ x, y, width, height }) => ({
522
+ x: FractionUtil.toFraction(x),
523
+ y: FractionUtil.toFraction(y),
524
+ width: FractionUtil.toFraction(width),
525
+ height: FractionUtil.toFraction(height)
526
+ });
527
+ /**
528
+ * Calculate center point.
529
+ * @param bounds
530
+ */
531
+ static center = ({ x, y, width, height }) => {
532
+ const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
533
+ 1,
534
+ 2
535
+ ]));
536
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
537
+ 1,
538
+ 2
539
+ ]));
540
+ return {
541
+ x: cx,
542
+ y: cy
590
543
  };
591
- }
592
- static {
593
- /**
594
- * Calculate centered right edge.
595
- * @param bounds
596
- */
597
- this.right = ({ x, y, width, height }) => {
598
- const cx = FractionUtil.add(x, width);
599
- const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
600
- 1,
601
- 2
602
- ]));
603
- return {
604
- x: cx,
605
- y: cy
606
- };
544
+ };
545
+ /**
546
+ * Calculate centered left edge.
547
+ * @param bounds
548
+ */
549
+ static left = ({ x, y, height }) => {
550
+ const cx = x;
551
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
552
+ 1,
553
+ 2
554
+ ]));
555
+ return {
556
+ x: cx,
557
+ y: cy
607
558
  };
608
- }
559
+ };
560
+ /**
561
+ * Calculate centered right edge.
562
+ * @param bounds
563
+ */
564
+ static right = ({ x, y, width, height }) => {
565
+ const cx = FractionUtil.add(x, width);
566
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
567
+ 1,
568
+ 2
569
+ ]));
570
+ return {
571
+ x: cx,
572
+ y: cy
573
+ };
574
+ };
609
575
  };
610
576
 
611
- // packages/ui/react-ui-graph/src/hooks/useSvgContext.ts
577
+ // src/hooks/useSvgContext.ts
612
578
  import { createContext, useContext } from "react";
613
579
  import { createRef } from "react";
614
580
  import { raise } from "@dxos/debug";
615
581
  var SVGContext = class {
582
+ _ref = createRef();
583
+ _scale;
584
+ _centered;
585
+ _size;
586
+ _center;
587
+ resized = new EventEmitter();
616
588
  constructor({ scale = new Scale(), centered = true }) {
617
- this._ref = createRef();
618
- this.resized = new EventEmitter();
619
589
  this._scale = scale;
620
590
  this._centered = centered;
621
591
  }
@@ -675,7 +645,7 @@ var useSvgContext = () => {
675
645
  return useContext(SVGContextType) ?? raise(new Error("Missing SVGRoot"));
676
646
  };
677
647
 
678
- // packages/ui/react-ui-graph/src/hooks/useGrid.ts
648
+ // src/hooks/useGrid.ts
679
649
  import { line, range, select } from "d3";
680
650
  import { useEffect, useMemo, useRef } from "react";
681
651
  var createLine = line();
@@ -793,6 +763,10 @@ var defaultGridOptions = {
793
763
  grid: true
794
764
  };
795
765
  var GridController = class {
766
+ _ref;
767
+ _context;
768
+ _options;
769
+ _visible;
796
770
  constructor(_ref, _context, _options) {
797
771
  this._ref = _ref;
798
772
  this._context = _context;
@@ -836,7 +810,7 @@ var useGrid = (options = defaultGridOptions) => {
836
810
  return controller;
837
811
  };
838
812
 
839
- // packages/ui/react-ui-graph/src/hooks/useStateRef.ts
813
+ // src/hooks/useStateRef.ts
840
814
  import { useEffect as useEffect2, useRef as useRef2, useState } from "react";
841
815
  var useStateRef = (initialValue) => {
842
816
  const [value, setValue] = useState(initialValue);
@@ -882,7 +856,7 @@ var useTimestamp = (deps) => {
882
856
  ];
883
857
  };
884
858
 
885
- // packages/ui/react-ui-graph/src/hooks/useZoom.ts
859
+ // src/hooks/useZoom.ts
886
860
  import { select as select2, zoom, zoomIdentity as zoomIdentity2 } from "d3";
887
861
  import defaultsDeep from "lodash.defaultsdeep";
888
862
  import { useEffect as useEffect3, useMemo as useMemo2, useRef as useRef3 } from "react";
@@ -895,6 +869,11 @@ var defaultZoomOptions = {
895
869
  onDblClick: (zoom2) => zoom2.reset()
896
870
  };
897
871
  var ZoomHandler = class {
872
+ _ref;
873
+ _context;
874
+ _zoom;
875
+ _options;
876
+ _enabled;
898
877
  constructor(_ref, _context, options) {
899
878
  this._ref = _ref;
900
879
  this._context = _context;
@@ -978,4 +957,4 @@ export {
978
957
  ZoomHandler,
979
958
  useZoom
980
959
  };
981
- //# sourceMappingURL=chunk-ITHTKQOY.mjs.map
960
+ //# sourceMappingURL=chunk-O6GWCXDC.mjs.map