@dxos/react-ui-graph 0.8.4-main.3a94e84 → 0.8.4-main.406dc2a

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 (87) hide show
  1. package/dist/lib/browser/{chunk-MGVY54T5.mjs → chunk-EX2Q43O6.mjs} +405 -418
  2. package/dist/lib/browser/chunk-EX2Q43O6.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +120 -47
  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 +1 -1
  7. package/dist/lib/browser/testing/index.mjs.map +2 -2
  8. package/dist/lib/node-esm/{chunk-X5YVOSXZ.mjs → chunk-SWA6OT3W.mjs} +405 -418
  9. package/dist/lib/node-esm/chunk-SWA6OT3W.mjs.map +7 -0
  10. package/dist/lib/node-esm/index.mjs +120 -47
  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 +1 -1
  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 +15 -6
  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 +9 -5
  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 +10 -8
  25. package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
  26. package/dist/types/src/components/SVG/Zoom.d.ts.map +1 -1
  27. package/dist/types/src/fx/fx.stories.d.ts +16 -15
  28. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  29. package/dist/types/src/graph/projector/graph-drag.d.ts +1 -1
  30. package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
  31. package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
  32. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  33. package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
  34. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
  35. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
  36. package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
  37. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  38. package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
  39. package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
  40. package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
  41. package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
  42. package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
  43. package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
  44. package/dist/types/src/graph/renderer/graph-renderer.d.ts +1 -1
  45. package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
  46. package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
  47. package/dist/types/src/hooks/useZoom.d.ts.map +1 -1
  48. package/dist/types/src/stories/hooks.stories.d.ts +10 -6
  49. package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
  50. package/dist/types/src/testing/hooks.d.ts.map +1 -1
  51. package/dist/types/src/util/screen.d.ts +1 -1
  52. package/dist/types/src/util/screen.d.ts.map +1 -1
  53. package/dist/types/src/util/vector.d.ts +1 -1
  54. package/dist/types/src/util/vector.d.ts.map +1 -1
  55. package/dist/types/tsconfig.tsbuildinfo +1 -1
  56. package/package.json +24 -24
  57. package/src/components/Graph/Graph.stories.tsx +27 -29
  58. package/src/components/Graph/Graph.tsx +2 -2
  59. package/src/components/Mesh/Mesh.stories.tsx +11 -9
  60. package/src/components/Mesh/Mesh.tsx +1 -1
  61. package/src/components/SVG/Grid.tsx +1 -1
  62. package/src/components/SVG/Markers.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 +23 -18
  66. package/src/components/SVG/Zoom.tsx +1 -1
  67. package/src/fx/fx.stories.tsx +15 -11
  68. package/src/graph/projector/graph-drag.ts +2 -1
  69. package/src/graph/projector/graph-force-projector.ts +2 -1
  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/useStateRef.ts +1 -1
  80. package/src/hooks/useZoom.ts +1 -1
  81. package/src/stories/hooks.stories.tsx +31 -30
  82. package/src/testing/hooks.ts +3 -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/browser/chunk-MGVY54T5.mjs.map +0 -7
  87. package/dist/lib/node-esm/chunk-X5YVOSXZ.mjs.map +0 -7
@@ -1,10 +1,20 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // src/util/events.ts
4
- var EventEmitter = class {
5
- constructor() {
6
- this._listeners = /* @__PURE__ */ new Set();
4
+ function _define_property(obj, key, value) {
5
+ if (key in obj) {
6
+ Object.defineProperty(obj, key, {
7
+ value,
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true
11
+ });
12
+ } else {
13
+ obj[key] = value;
7
14
  }
15
+ return obj;
16
+ }
17
+ var EventEmitter = class {
8
18
  clear() {
9
19
  this._listeners.clear();
10
20
  }
@@ -15,226 +25,161 @@ var EventEmitter = class {
15
25
  emit(value) {
16
26
  this._listeners.forEach((listener) => listener(value));
17
27
  }
28
+ constructor() {
29
+ _define_property(this, "_listeners", /* @__PURE__ */ new Set());
30
+ }
18
31
  };
19
32
 
20
33
  // src/util/fraction.ts
21
34
  import { invariant } from "@dxos/invariant";
22
- var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
23
- 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
- };
35
+ function _define_property2(obj, key, value) {
36
+ if (key in obj) {
37
+ Object.defineProperty(obj, key, {
38
+ value,
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true
42
+ });
43
+ } else {
44
+ obj[key] = value;
96
45
  }
97
- static {
98
- /**
99
- * @param {Fraction}
100
- * True if zero.
101
- */
102
- this.isZero = ([n]) => {
103
- return n === 0;
104
- };
46
+ return obj;
47
+ }
48
+ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
49
+ var FractionUtil = class {
50
+ };
51
+ _define_property2(FractionUtil, "toFraction", (n) => {
52
+ return typeof n === "number" ? [
53
+ n,
54
+ 1
55
+ ] : n;
56
+ });
57
+ _define_property2(FractionUtil, "validate", (...fraction) => {
58
+ fraction.forEach(([n, d]) => {
59
+ if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
60
+ throw new Error(`Invalid fraction: ${n}/${d}`);
61
+ }
62
+ });
63
+ return fraction;
64
+ });
65
+ _define_property2(FractionUtil, "toNumber", ([n, d]) => {
66
+ FractionUtil.validate([
67
+ n,
68
+ d
69
+ ]);
70
+ return n / d;
71
+ });
72
+ _define_property2(FractionUtil, "round", ([n, d], p = 1) => {
73
+ FractionUtil.validate([
74
+ n,
75
+ d
76
+ ]);
77
+ const v = Math.round(FractionUtil.toNumber(FractionUtil.divide([
78
+ n,
79
+ d
80
+ ], [
81
+ 1,
82
+ p
83
+ ])));
84
+ return FractionUtil.simplify([
85
+ v,
86
+ p
87
+ ]);
88
+ });
89
+ _define_property2(FractionUtil, "equals", (n1, n2) => {
90
+ return n1[0] * n2[1] === n1[1] * n2[0];
91
+ });
92
+ _define_property2(FractionUtil, "isZero", ([n]) => {
93
+ return n === 0;
94
+ });
95
+ _define_property2(FractionUtil, "simplify", ([n, d]) => {
96
+ FractionUtil.validate([
97
+ n,
98
+ d
99
+ ]);
100
+ if (d < 1) {
101
+ const t = n / d;
102
+ if (Math.floor(t) === t) {
103
+ n = t;
104
+ d = 1;
105
+ }
105
106
  }
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
- }
126
- }
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
- }
138
- }
107
+ const fn = FractionUtil.factors(n).reverse();
108
+ const fd = FractionUtil.factors(d).reverse();
109
+ let c;
110
+ for (let i = 0; i < fn.length; i++) {
111
+ c = fd.find((n2) => n2 === fn[i]);
112
+ if (c) {
139
113
  return [
140
- n,
141
- d
114
+ n / c,
115
+ d / c
142
116
  ];
143
- };
117
+ }
144
118
  }
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);
119
+ return [
120
+ n,
121
+ d
122
+ ];
123
+ });
124
+ _define_property2(FractionUtil, "factors", (n) => {
125
+ invariant(Number.isFinite(n), `Invalid number: ${n}`, {
126
+ F: __dxlog_file,
127
+ L: 113,
128
+ S: FractionUtil,
129
+ A: [
130
+ "Number.isFinite(n)",
131
+ "`Invalid number: ${n}`"
132
+ ]
133
+ });
134
+ const factors = [
135
+ 1
136
+ ];
137
+ if (Number.isSafeInteger(n)) {
138
+ let f = 1;
139
+ do {
140
+ if (n % ++f === 0) {
141
+ factors.push(f);
170
142
  }
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
- }
237
- };
143
+ } while (n / f > 1 && f < 100);
144
+ }
145
+ return factors;
146
+ });
147
+ _define_property2(FractionUtil, "add", (n1, n2) => {
148
+ FractionUtil.validate(n1, n2);
149
+ const d = n1[1] * n2[1];
150
+ const n = n1[0] * n2[1] + n2[0] * n1[1];
151
+ return FractionUtil.simplify([
152
+ n,
153
+ d
154
+ ]);
155
+ });
156
+ _define_property2(FractionUtil, "subtract", (n1, n2) => {
157
+ FractionUtil.validate(n1, n2);
158
+ const d = n1[1] * n2[1];
159
+ const n = n1[0] * n2[1] - n2[0] * n1[1];
160
+ return FractionUtil.simplify([
161
+ n,
162
+ d
163
+ ]);
164
+ });
165
+ _define_property2(FractionUtil, "multiply", (n1, n2) => {
166
+ FractionUtil.validate(n1, n2);
167
+ const n = n1[0] * n2[0];
168
+ const d = n1[1] * n2[1];
169
+ return FractionUtil.simplify([
170
+ n,
171
+ d
172
+ ]);
173
+ });
174
+ _define_property2(FractionUtil, "divide", (n1, n2) => {
175
+ FractionUtil.validate(n1, n2);
176
+ const n = n1[0] * n2[1];
177
+ const d = n1[1] * n2[0];
178
+ return FractionUtil.simplify([
179
+ n,
180
+ d
181
+ ]);
182
+ });
238
183
 
239
184
  // src/util/points.ts
240
185
  var getCircumferencePoints = (p1, p2, r1 = 0, r2 = 0) => {
@@ -291,8 +236,53 @@ var offsetPoints = (points, distance, closed) => {
291
236
 
292
237
  // src/util/scale.ts
293
238
  import { zoomIdentity } from "d3";
239
+ function _define_property3(obj, key, value) {
240
+ if (key in obj) {
241
+ Object.defineProperty(obj, key, {
242
+ value,
243
+ enumerable: true,
244
+ configurable: true,
245
+ writable: true
246
+ });
247
+ } else {
248
+ obj[key] = value;
249
+ }
250
+ return obj;
251
+ }
294
252
  var Scale = class {
253
+ get gridSize() {
254
+ return this._gridSize;
255
+ }
256
+ get transform() {
257
+ return this._transform || zoomIdentity;
258
+ }
259
+ setTransform(transform) {
260
+ if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) {
261
+ return false;
262
+ }
263
+ this._transform = transform;
264
+ return true;
265
+ }
266
+ /**
267
+ * Translate a screen point to a logical point.
268
+ * @param point
269
+ */
270
+ translate(point) {
271
+ const { x, y, k } = this._transform ?? {
272
+ x: 0,
273
+ y: 0,
274
+ k: 1
275
+ };
276
+ return [
277
+ (point[0] - x) / k,
278
+ (point[1] - y) / k
279
+ ];
280
+ }
295
281
  constructor(_gridSize = 32) {
282
+ _define_property3(this, "_gridSize", void 0);
283
+ _define_property3(this, "_transform", void 0);
284
+ _define_property3(this, "model", void 0);
285
+ _define_property3(this, "screen", void 0);
296
286
  this._gridSize = _gridSize;
297
287
  this.model = {
298
288
  // TODO(burdon): Precision depends on scale.
@@ -411,214 +401,166 @@ var Scale = class {
411
401
  }
412
402
  };
413
403
  }
414
- get gridSize() {
415
- return this._gridSize;
416
- }
417
- get transform() {
418
- return this._transform || zoomIdentity;
419
- }
420
- setTransform(transform) {
421
- if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) {
422
- return false;
423
- }
424
- this._transform = transform;
425
- return true;
426
- }
427
- /**
428
- * Translate a screen point to a logical point.
429
- * @param point
430
- */
431
- translate(point) {
432
- const { x, y, k } = this._transform ?? {
433
- x: 0,
434
- y: 0,
435
- k: 1
436
- };
437
- return [
438
- (point[0] - x) / k,
439
- (point[1] - y) / k
440
- ];
441
- }
442
404
  };
443
405
 
444
406
  // src/util/screen.ts
445
- 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
- };
407
+ function _define_property4(obj, key, value) {
408
+ if (key in obj) {
409
+ Object.defineProperty(obj, key, {
410
+ value,
411
+ enumerable: true,
412
+ configurable: true,
413
+ writable: true
414
+ });
415
+ } else {
416
+ obj[key] = value;
480
417
  }
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;
418
+ return obj;
419
+ }
420
+ var Screen = class {
421
+ };
422
+ _define_property4(Screen, "createBounds", ([x1, y1], [x2, y2], mod = {}) => {
423
+ const { constrain, center } = mod;
424
+ const x = Math.min(x1, x2);
425
+ const y = Math.min(y1, y2);
426
+ let width = Math.abs(x2 - x1);
427
+ let height = Math.abs(y2 - y1);
428
+ if (constrain) {
429
+ width = height = Math.max(width, height);
430
+ }
431
+ if (center) {
432
+ return {
433
+ x: x - width,
434
+ y: y - height,
435
+ width: width * 2,
436
+ height: height * 2
491
437
  };
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));
438
+ } else {
439
+ return {
440
+ x,
441
+ y,
442
+ width,
443
+ height
501
444
  };
502
445
  }
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
- };
446
+ });
447
+ _define_property4(Screen, "center", ({ x, y, width, height }) => {
448
+ return [
449
+ x + width / 2,
450
+ y + height / 2
451
+ ];
452
+ });
453
+ _define_property4(Screen, "contains", (bounds, point) => {
454
+ const [x, y] = point;
455
+ if (x < bounds.x || y < bounds.y) {
456
+ return false;
457
+ }
458
+ if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
459
+ return false;
460
+ }
461
+ return true;
462
+ });
463
+ _define_property4(Screen, "len", (p1, p2) => {
464
+ return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
465
+ });
466
+ _define_property4(Screen, "normal", (v1, v2, p) => {
467
+ const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
468
+ let d;
469
+ const len2 = d2(v1, v2);
470
+ if (len2 === 0) {
471
+ d = d2(p, v1);
472
+ } else {
473
+ let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
474
+ t = Math.max(0, Math.min(1, t));
475
+ d = d2(p, [
476
+ v1[0] + t * (v2[0] - v1[0]),
477
+ v1[1] + t * (v2[1] - v1[1])
478
+ ]);
527
479
  }
528
- };
480
+ return Math.sqrt(d);
481
+ });
529
482
 
530
483
  // 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)
484
+ function _define_property5(obj, key, value) {
485
+ if (key in obj) {
486
+ Object.defineProperty(obj, key, {
487
+ value,
488
+ enumerable: true,
489
+ configurable: true,
490
+ writable: true
541
491
  });
492
+ } else {
493
+ obj[key] = value;
542
494
  }
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
- ]));
569
- return {
570
- x: cx,
571
- y: cy
572
- };
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
- ]));
586
- return {
587
- x: cx,
588
- y: cy
589
- };
590
- };
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
- };
607
- };
608
- }
495
+ return obj;
496
+ }
497
+ var Vector = class {
609
498
  };
499
+ _define_property5(Vector, "toVertex", ({ x, y }) => ({
500
+ x: FractionUtil.toFraction(x),
501
+ y: FractionUtil.toFraction(y)
502
+ }));
503
+ _define_property5(Vector, "toBounds", ({ x, y, width, height }) => ({
504
+ x: FractionUtil.toFraction(x),
505
+ y: FractionUtil.toFraction(y),
506
+ width: FractionUtil.toFraction(width),
507
+ height: FractionUtil.toFraction(height)
508
+ }));
509
+ _define_property5(Vector, "center", ({ x, y, width, height }) => {
510
+ const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
511
+ 1,
512
+ 2
513
+ ]));
514
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
515
+ 1,
516
+ 2
517
+ ]));
518
+ return {
519
+ x: cx,
520
+ y: cy
521
+ };
522
+ });
523
+ _define_property5(Vector, "left", ({ x, y, height }) => {
524
+ const cx = x;
525
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
526
+ 1,
527
+ 2
528
+ ]));
529
+ return {
530
+ x: cx,
531
+ y: cy
532
+ };
533
+ });
534
+ _define_property5(Vector, "right", ({ x, y, width, height }) => {
535
+ const cx = FractionUtil.add(x, width);
536
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
537
+ 1,
538
+ 2
539
+ ]));
540
+ return {
541
+ x: cx,
542
+ y: cy
543
+ };
544
+ });
610
545
 
611
546
  // src/hooks/useSvgContext.ts
612
547
  import { createContext, useContext } from "react";
613
548
  import { createRef } from "react";
614
549
  import { raise } from "@dxos/debug";
615
- var SVGContext = class {
616
- constructor({ scale = new Scale(), centered = true }) {
617
- this._ref = createRef();
618
- this.resized = new EventEmitter();
619
- this._scale = scale;
620
- this._centered = centered;
550
+ function _define_property6(obj, key, value) {
551
+ if (key in obj) {
552
+ Object.defineProperty(obj, key, {
553
+ value,
554
+ enumerable: true,
555
+ configurable: true,
556
+ writable: true
557
+ });
558
+ } else {
559
+ obj[key] = value;
621
560
  }
561
+ return obj;
562
+ }
563
+ var SVGContext = class {
622
564
  get ref() {
623
565
  return this._ref;
624
566
  }
@@ -668,6 +610,16 @@ var SVGContext = class {
668
610
  const [cx, cy] = this._center;
669
611
  return document.elementFromPoint(cx + x, cy + y);
670
612
  }
613
+ constructor({ scale = new Scale(), centered = true }) {
614
+ _define_property6(this, "_ref", createRef());
615
+ _define_property6(this, "_scale", void 0);
616
+ _define_property6(this, "_centered", void 0);
617
+ _define_property6(this, "_size", void 0);
618
+ _define_property6(this, "_center", void 0);
619
+ _define_property6(this, "resized", new EventEmitter());
620
+ this._scale = scale;
621
+ this._centered = centered;
622
+ }
671
623
  };
672
624
  var SVGContextType = createContext(void 0);
673
625
  var SVGContextProvider = SVGContextType.Provider;
@@ -678,6 +630,19 @@ var useSvgContext = () => {
678
630
  // src/hooks/useGrid.ts
679
631
  import { line, range, select } from "d3";
680
632
  import { useEffect, useMemo, useRef } from "react";
633
+ function _define_property7(obj, key, value) {
634
+ if (key in obj) {
635
+ Object.defineProperty(obj, key, {
636
+ value,
637
+ enumerable: true,
638
+ configurable: true,
639
+ writable: true
640
+ });
641
+ } else {
642
+ obj[key] = value;
643
+ }
644
+ return obj;
645
+ }
681
646
  var createLine = line();
682
647
  var createGrid = (context, options) => {
683
648
  if (!context.size) {
@@ -793,13 +758,6 @@ var defaultGridOptions = {
793
758
  grid: true
794
759
  };
795
760
  var GridController = class {
796
- constructor(_ref, _context, _options) {
797
- this._ref = _ref;
798
- this._context = _context;
799
- this._options = _options;
800
- this._visible = false;
801
- this._visible = this._options.visible ?? true;
802
- }
803
761
  get ref() {
804
762
  return this._ref;
805
763
  }
@@ -824,6 +782,17 @@ var GridController = class {
824
782
  this.draw();
825
783
  return this;
826
784
  }
785
+ constructor(_ref, _context, _options) {
786
+ _define_property7(this, "_ref", void 0);
787
+ _define_property7(this, "_context", void 0);
788
+ _define_property7(this, "_options", void 0);
789
+ _define_property7(this, "_visible", void 0);
790
+ this._ref = _ref;
791
+ this._context = _context;
792
+ this._options = _options;
793
+ this._visible = false;
794
+ this._visible = this._options.visible ?? true;
795
+ }
827
796
  };
828
797
  var useGrid = (options = defaultGridOptions) => {
829
798
  const ref = useRef(null);
@@ -840,7 +809,7 @@ var useGrid = (options = defaultGridOptions) => {
840
809
  import { useEffect as useEffect2, useRef as useRef2, useState } from "react";
841
810
  var useStateRef = (initialValue) => {
842
811
  const [value, setValue] = useState(initialValue);
843
- const ref = useRef2();
812
+ const ref = useRef2(null);
844
813
  useEffect2(() => {
845
814
  ref.current = value;
846
815
  }, [
@@ -886,6 +855,19 @@ var useTimestamp = (deps) => {
886
855
  import { select as select2, zoom, zoomIdentity as zoomIdentity2 } from "d3";
887
856
  import defaultsDeep from "lodash.defaultsdeep";
888
857
  import { useEffect as useEffect3, useMemo as useMemo2, useRef as useRef3 } from "react";
858
+ function _define_property8(obj, key, value) {
859
+ if (key in obj) {
860
+ Object.defineProperty(obj, key, {
861
+ value,
862
+ enumerable: true,
863
+ configurable: true,
864
+ writable: true
865
+ });
866
+ } else {
867
+ obj[key] = value;
868
+ }
869
+ return obj;
870
+ }
889
871
  var defaultZoomOptions = {
890
872
  enabled: true,
891
873
  extent: [
@@ -895,13 +877,6 @@ var defaultZoomOptions = {
895
877
  onDblClick: (zoom2) => zoom2.reset()
896
878
  };
897
879
  var ZoomHandler = class {
898
- constructor(_ref, _context, options) {
899
- this._ref = _ref;
900
- this._context = _context;
901
- this._options = defaultsDeep({}, options, defaultZoomOptions);
902
- this._enabled = this._options.enabled ?? true;
903
- this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
904
- }
905
880
  /**
906
881
  * Gets the reference which the transform is applied to.
907
882
  */
@@ -938,6 +913,18 @@ var ZoomHandler = class {
938
913
  select2(this._context.svg).transition().duration(duration).call(this._zoom.transform, transform);
939
914
  return this;
940
915
  }
916
+ constructor(_ref, _context, options) {
917
+ _define_property8(this, "_ref", void 0);
918
+ _define_property8(this, "_context", void 0);
919
+ _define_property8(this, "_zoom", void 0);
920
+ _define_property8(this, "_options", void 0);
921
+ _define_property8(this, "_enabled", void 0);
922
+ this._ref = _ref;
923
+ this._context = _context;
924
+ this._options = defaultsDeep({}, options, defaultZoomOptions);
925
+ this._enabled = this._options.enabled ?? true;
926
+ this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
927
+ }
941
928
  };
942
929
  var useZoom = (options = defaultZoomOptions) => {
943
930
  const context = useSvgContext();
@@ -978,4 +965,4 @@ export {
978
965
  ZoomHandler,
979
966
  useZoom
980
967
  };
981
- //# sourceMappingURL=chunk-X5YVOSXZ.mjs.map
968
+ //# sourceMappingURL=chunk-SWA6OT3W.mjs.map