@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,8 +1,18 @@
1
1
  // src/util/events.ts
2
- var EventEmitter = class {
3
- constructor() {
4
- this._listeners = /* @__PURE__ */ new Set();
2
+ function _define_property(obj, key, value) {
3
+ if (key in obj) {
4
+ Object.defineProperty(obj, key, {
5
+ value,
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true
9
+ });
10
+ } else {
11
+ obj[key] = value;
5
12
  }
13
+ return obj;
14
+ }
15
+ var EventEmitter = class {
6
16
  clear() {
7
17
  this._listeners.clear();
8
18
  }
@@ -13,226 +23,161 @@ var EventEmitter = class {
13
23
  emit(value) {
14
24
  this._listeners.forEach((listener) => listener(value));
15
25
  }
26
+ constructor() {
27
+ _define_property(this, "_listeners", /* @__PURE__ */ new Set());
28
+ }
16
29
  };
17
30
 
18
31
  // src/util/fraction.ts
19
32
  import { invariant } from "@dxos/invariant";
20
- var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
21
- var FractionUtil = class _FractionUtil {
22
- static {
23
- /**
24
- * Convert number to fraction.
25
- * @param n
26
- */
27
- this.toFraction = (n) => {
28
- return typeof n === "number" ? [
29
- n,
30
- 1
31
- ] : n;
32
- };
33
- }
34
- static {
35
- this.validate = (...fraction) => {
36
- fraction.forEach(([n, d]) => {
37
- if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
38
- throw new Error(`Invalid fraction: ${n}/${d}`);
39
- }
40
- });
41
- return fraction;
42
- };
43
- }
44
- static {
45
- /**
46
- * @param {Fraction}
47
- * Convert to rounded number.
48
- */
49
- this.toNumber = ([n, d]) => {
50
- _FractionUtil.validate([
51
- n,
52
- d
53
- ]);
54
- return n / d;
55
- };
56
- }
57
- static {
58
- /**
59
- * Round the number to the nearest fraction.
60
- * Example: 3/5 => 1/1; 3/5 (precision 2) => 1/2.
61
- * @param {Fraction}
62
- * @param p Precision (e.g., 1/2, 1/4, etc.)
63
- */
64
- this.round = ([n, d], p = 1) => {
65
- _FractionUtil.validate([
66
- n,
67
- d
68
- ]);
69
- const v = Math.round(_FractionUtil.toNumber(_FractionUtil.divide([
70
- n,
71
- d
72
- ], [
73
- 1,
74
- p
75
- ])));
76
- return _FractionUtil.simplify([
77
- v,
78
- p
79
- ]);
80
- };
81
- }
82
- static {
83
- //
84
- // Boolean.
85
- //
86
- /**
87
- * Tests if equals.
88
- * @param n1
89
- * @param n2
90
- */
91
- this.equals = (n1, n2) => {
92
- return n1[0] * n2[1] === n1[1] * n2[0];
93
- };
33
+ function _define_property2(obj, key, value) {
34
+ if (key in obj) {
35
+ Object.defineProperty(obj, key, {
36
+ value,
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true
40
+ });
41
+ } else {
42
+ obj[key] = value;
94
43
  }
95
- static {
96
- /**
97
- * @param {Fraction}
98
- * True if zero.
99
- */
100
- this.isZero = ([n]) => {
101
- return n === 0;
102
- };
44
+ return obj;
45
+ }
46
+ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
47
+ var FractionUtil = class {
48
+ };
49
+ _define_property2(FractionUtil, "toFraction", (n) => {
50
+ return typeof n === "number" ? [
51
+ n,
52
+ 1
53
+ ] : n;
54
+ });
55
+ _define_property2(FractionUtil, "validate", (...fraction) => {
56
+ fraction.forEach(([n, d]) => {
57
+ if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
58
+ throw new Error(`Invalid fraction: ${n}/${d}`);
59
+ }
60
+ });
61
+ return fraction;
62
+ });
63
+ _define_property2(FractionUtil, "toNumber", ([n, d]) => {
64
+ FractionUtil.validate([
65
+ n,
66
+ d
67
+ ]);
68
+ return n / d;
69
+ });
70
+ _define_property2(FractionUtil, "round", ([n, d], p = 1) => {
71
+ FractionUtil.validate([
72
+ n,
73
+ d
74
+ ]);
75
+ const v = Math.round(FractionUtil.toNumber(FractionUtil.divide([
76
+ n,
77
+ d
78
+ ], [
79
+ 1,
80
+ p
81
+ ])));
82
+ return FractionUtil.simplify([
83
+ v,
84
+ p
85
+ ]);
86
+ });
87
+ _define_property2(FractionUtil, "equals", (n1, n2) => {
88
+ return n1[0] * n2[1] === n1[1] * n2[0];
89
+ });
90
+ _define_property2(FractionUtil, "isZero", ([n]) => {
91
+ return n === 0;
92
+ });
93
+ _define_property2(FractionUtil, "simplify", ([n, d]) => {
94
+ FractionUtil.validate([
95
+ n,
96
+ d
97
+ ]);
98
+ if (d < 1) {
99
+ const t = n / d;
100
+ if (Math.floor(t) === t) {
101
+ n = t;
102
+ d = 1;
103
+ }
103
104
  }
104
- static {
105
- //
106
- // Normalization.
107
- //
108
- /**
109
- * Simplify fraction finding LCDs.
110
- * @param n
111
- * @param d
112
- */
113
- this.simplify = ([n, d]) => {
114
- _FractionUtil.validate([
115
- n,
116
- d
117
- ]);
118
- if (d < 1) {
119
- const t = n / d;
120
- if (Math.floor(t) === t) {
121
- n = t;
122
- d = 1;
123
- }
124
- }
125
- const fn = _FractionUtil.factors(n).reverse();
126
- const fd = _FractionUtil.factors(d).reverse();
127
- let c;
128
- for (let i = 0; i < fn.length; i++) {
129
- c = fd.find((n2) => n2 === fn[i]);
130
- if (c) {
131
- return [
132
- n / c,
133
- d / c
134
- ];
135
- }
136
- }
105
+ const fn = FractionUtil.factors(n).reverse();
106
+ const fd = FractionUtil.factors(d).reverse();
107
+ let c;
108
+ for (let i = 0; i < fn.length; i++) {
109
+ c = fd.find((n2) => n2 === fn[i]);
110
+ if (c) {
137
111
  return [
138
- n,
139
- d
112
+ n / c,
113
+ d / c
140
114
  ];
141
- };
115
+ }
142
116
  }
143
- static {
144
- /**
145
- * Return common factors.
146
- * @param n
147
- */
148
- this.factors = (n) => {
149
- invariant(Number.isFinite(n), `Invalid number: ${n}`, {
150
- F: __dxlog_file,
151
- L: 113,
152
- S: this,
153
- A: [
154
- "Number.isFinite(n)",
155
- "`Invalid number: ${n}`"
156
- ]
157
- });
158
- const factors = [
159
- 1
160
- ];
161
- if (Number.isSafeInteger(n)) {
162
- let f = 1;
163
- do {
164
- if (n % ++f === 0) {
165
- factors.push(f);
166
- }
167
- } while (n / f > 1 && f < 100);
117
+ return [
118
+ n,
119
+ d
120
+ ];
121
+ });
122
+ _define_property2(FractionUtil, "factors", (n) => {
123
+ invariant(Number.isFinite(n), `Invalid number: ${n}`, {
124
+ F: __dxlog_file,
125
+ L: 113,
126
+ S: FractionUtil,
127
+ A: [
128
+ "Number.isFinite(n)",
129
+ "`Invalid number: ${n}`"
130
+ ]
131
+ });
132
+ const factors = [
133
+ 1
134
+ ];
135
+ if (Number.isSafeInteger(n)) {
136
+ let f = 1;
137
+ do {
138
+ if (n % ++f === 0) {
139
+ factors.push(f);
168
140
  }
169
- return factors;
170
- };
171
- }
172
- static {
173
- //
174
- // Basic arithmetic.
175
- //
176
- /**
177
- * @param n1
178
- * @param n2
179
- */
180
- this.add = (n1, n2) => {
181
- _FractionUtil.validate(n1, n2);
182
- const d = n1[1] * n2[1];
183
- const n = n1[0] * n2[1] + n2[0] * n1[1];
184
- return _FractionUtil.simplify([
185
- n,
186
- d
187
- ]);
188
- };
189
- }
190
- static {
191
- /**
192
- * @param n1
193
- * @param n2
194
- */
195
- this.subtract = (n1, n2) => {
196
- _FractionUtil.validate(n1, n2);
197
- const d = n1[1] * n2[1];
198
- const n = n1[0] * n2[1] - n2[0] * n1[1];
199
- return _FractionUtil.simplify([
200
- n,
201
- d
202
- ]);
203
- };
204
- }
205
- static {
206
- /**
207
- * @param n1
208
- * @param n2
209
- */
210
- this.multiply = (n1, n2) => {
211
- _FractionUtil.validate(n1, n2);
212
- const n = n1[0] * n2[0];
213
- const d = n1[1] * n2[1];
214
- return _FractionUtil.simplify([
215
- n,
216
- d
217
- ]);
218
- };
219
- }
220
- static {
221
- /**
222
- * @param n1
223
- * @param n2
224
- */
225
- this.divide = (n1, n2) => {
226
- _FractionUtil.validate(n1, n2);
227
- const n = n1[0] * n2[1];
228
- const d = n1[1] * n2[0];
229
- return _FractionUtil.simplify([
230
- n,
231
- d
232
- ]);
233
- };
234
- }
235
- };
141
+ } while (n / f > 1 && f < 100);
142
+ }
143
+ return factors;
144
+ });
145
+ _define_property2(FractionUtil, "add", (n1, n2) => {
146
+ FractionUtil.validate(n1, n2);
147
+ const d = n1[1] * n2[1];
148
+ const n = n1[0] * n2[1] + n2[0] * n1[1];
149
+ return FractionUtil.simplify([
150
+ n,
151
+ d
152
+ ]);
153
+ });
154
+ _define_property2(FractionUtil, "subtract", (n1, n2) => {
155
+ FractionUtil.validate(n1, n2);
156
+ const d = n1[1] * n2[1];
157
+ const n = n1[0] * n2[1] - n2[0] * n1[1];
158
+ return FractionUtil.simplify([
159
+ n,
160
+ d
161
+ ]);
162
+ });
163
+ _define_property2(FractionUtil, "multiply", (n1, n2) => {
164
+ FractionUtil.validate(n1, n2);
165
+ const n = n1[0] * n2[0];
166
+ const d = n1[1] * n2[1];
167
+ return FractionUtil.simplify([
168
+ n,
169
+ d
170
+ ]);
171
+ });
172
+ _define_property2(FractionUtil, "divide", (n1, n2) => {
173
+ FractionUtil.validate(n1, n2);
174
+ const n = n1[0] * n2[1];
175
+ const d = n1[1] * n2[0];
176
+ return FractionUtil.simplify([
177
+ n,
178
+ d
179
+ ]);
180
+ });
236
181
 
237
182
  // src/util/points.ts
238
183
  var getCircumferencePoints = (p1, p2, r1 = 0, r2 = 0) => {
@@ -289,8 +234,53 @@ var offsetPoints = (points, distance, closed) => {
289
234
 
290
235
  // src/util/scale.ts
291
236
  import { zoomIdentity } from "d3";
237
+ function _define_property3(obj, key, value) {
238
+ if (key in obj) {
239
+ Object.defineProperty(obj, key, {
240
+ value,
241
+ enumerable: true,
242
+ configurable: true,
243
+ writable: true
244
+ });
245
+ } else {
246
+ obj[key] = value;
247
+ }
248
+ return obj;
249
+ }
292
250
  var Scale = class {
251
+ get gridSize() {
252
+ return this._gridSize;
253
+ }
254
+ get transform() {
255
+ return this._transform || zoomIdentity;
256
+ }
257
+ setTransform(transform) {
258
+ if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) {
259
+ return false;
260
+ }
261
+ this._transform = transform;
262
+ return true;
263
+ }
264
+ /**
265
+ * Translate a screen point to a logical point.
266
+ * @param point
267
+ */
268
+ translate(point) {
269
+ const { x, y, k } = this._transform ?? {
270
+ x: 0,
271
+ y: 0,
272
+ k: 1
273
+ };
274
+ return [
275
+ (point[0] - x) / k,
276
+ (point[1] - y) / k
277
+ ];
278
+ }
293
279
  constructor(_gridSize = 32) {
280
+ _define_property3(this, "_gridSize", void 0);
281
+ _define_property3(this, "_transform", void 0);
282
+ _define_property3(this, "model", void 0);
283
+ _define_property3(this, "screen", void 0);
294
284
  this._gridSize = _gridSize;
295
285
  this.model = {
296
286
  // TODO(burdon): Precision depends on scale.
@@ -409,214 +399,166 @@ var Scale = class {
409
399
  }
410
400
  };
411
401
  }
412
- get gridSize() {
413
- return this._gridSize;
414
- }
415
- get transform() {
416
- return this._transform || zoomIdentity;
417
- }
418
- setTransform(transform) {
419
- if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) {
420
- return false;
421
- }
422
- this._transform = transform;
423
- return true;
424
- }
425
- /**
426
- * Translate a screen point to a logical point.
427
- * @param point
428
- */
429
- translate(point) {
430
- const { x, y, k } = this._transform ?? {
431
- x: 0,
432
- y: 0,
433
- k: 1
434
- };
435
- return [
436
- (point[0] - x) / k,
437
- (point[1] - y) / k
438
- ];
439
- }
440
402
  };
441
403
 
442
404
  // src/util/screen.ts
443
- var Screen = class {
444
- static {
445
- this.createBounds = ([x1, y1], [x2, y2], mod = {}) => {
446
- const { constrain, center } = mod;
447
- const x = Math.min(x1, x2);
448
- const y = Math.min(y1, y2);
449
- let width = Math.abs(x2 - x1);
450
- let height = Math.abs(y2 - y1);
451
- if (constrain) {
452
- width = height = Math.max(width, height);
453
- }
454
- if (center) {
455
- return {
456
- x: x - width,
457
- y: y - height,
458
- width: width * 2,
459
- height: height * 2
460
- };
461
- } else {
462
- return {
463
- x,
464
- y,
465
- width,
466
- height
467
- };
468
- }
469
- };
470
- }
471
- static {
472
- this.center = ({ x, y, width, height }) => {
473
- return [
474
- x + width / 2,
475
- y + height / 2
476
- ];
477
- };
405
+ function _define_property4(obj, key, value) {
406
+ if (key in obj) {
407
+ Object.defineProperty(obj, key, {
408
+ value,
409
+ enumerable: true,
410
+ configurable: true,
411
+ writable: true
412
+ });
413
+ } else {
414
+ obj[key] = value;
478
415
  }
479
- static {
480
- this.contains = (bounds, point) => {
481
- const [x, y] = point;
482
- if (x < bounds.x || y < bounds.y) {
483
- return false;
484
- }
485
- if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
486
- return false;
487
- }
488
- return true;
416
+ return obj;
417
+ }
418
+ var Screen = class {
419
+ };
420
+ _define_property4(Screen, "createBounds", ([x1, y1], [x2, y2], mod = {}) => {
421
+ const { constrain, center } = mod;
422
+ const x = Math.min(x1, x2);
423
+ const y = Math.min(y1, y2);
424
+ let width = Math.abs(x2 - x1);
425
+ let height = Math.abs(y2 - y1);
426
+ if (constrain) {
427
+ width = height = Math.max(width, height);
428
+ }
429
+ if (center) {
430
+ return {
431
+ x: x - width,
432
+ y: y - height,
433
+ width: width * 2,
434
+ height: height * 2
489
435
  };
490
- }
491
- static {
492
- /**
493
- * Distance between two points.
494
- * @param p1
495
- * @param p2
496
- */
497
- this.len = (p1, p2) => {
498
- return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
436
+ } else {
437
+ return {
438
+ x,
439
+ y,
440
+ width,
441
+ height
499
442
  };
500
443
  }
501
- static {
502
- /**
503
- * Distance to line segment.
504
- * https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment#1501725
505
- * @param v1
506
- * @param v2
507
- * @param p
508
- */
509
- this.normal = (v1, v2, p) => {
510
- const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
511
- let d;
512
- const len2 = d2(v1, v2);
513
- if (len2 === 0) {
514
- d = d2(p, v1);
515
- } else {
516
- let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
517
- t = Math.max(0, Math.min(1, t));
518
- d = d2(p, [
519
- v1[0] + t * (v2[0] - v1[0]),
520
- v1[1] + t * (v2[1] - v1[1])
521
- ]);
522
- }
523
- return Math.sqrt(d);
524
- };
444
+ });
445
+ _define_property4(Screen, "center", ({ x, y, width, height }) => {
446
+ return [
447
+ x + width / 2,
448
+ y + height / 2
449
+ ];
450
+ });
451
+ _define_property4(Screen, "contains", (bounds, point) => {
452
+ const [x, y] = point;
453
+ if (x < bounds.x || y < bounds.y) {
454
+ return false;
455
+ }
456
+ if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
457
+ return false;
458
+ }
459
+ return true;
460
+ });
461
+ _define_property4(Screen, "len", (p1, p2) => {
462
+ return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
463
+ });
464
+ _define_property4(Screen, "normal", (v1, v2, p) => {
465
+ const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
466
+ let d;
467
+ const len2 = d2(v1, v2);
468
+ if (len2 === 0) {
469
+ d = d2(p, v1);
470
+ } else {
471
+ let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
472
+ t = Math.max(0, Math.min(1, t));
473
+ d = d2(p, [
474
+ v1[0] + t * (v2[0] - v1[0]),
475
+ v1[1] + t * (v2[1] - v1[1])
476
+ ]);
525
477
  }
526
- };
478
+ return Math.sqrt(d);
479
+ });
527
480
 
528
481
  // src/util/vector.ts
529
- var Vector = class {
530
- static {
531
- /**
532
- * Convert to Vertex.
533
- * @param x
534
- * @param y
535
- */
536
- this.toVertex = ({ x, y }) => ({
537
- x: FractionUtil.toFraction(x),
538
- y: FractionUtil.toFraction(y)
482
+ function _define_property5(obj, key, value) {
483
+ if (key in obj) {
484
+ Object.defineProperty(obj, key, {
485
+ value,
486
+ enumerable: true,
487
+ configurable: true,
488
+ writable: true
539
489
  });
490
+ } else {
491
+ obj[key] = value;
540
492
  }
541
- static {
542
- /**
543
- * Convert to Bounds.
544
- * @param bounds
545
- */
546
- this.toBounds = ({ x, y, width, height }) => ({
547
- x: FractionUtil.toFraction(x),
548
- y: FractionUtil.toFraction(y),
549
- width: FractionUtil.toFraction(width),
550
- height: FractionUtil.toFraction(height)
551
- });
552
- }
553
- static {
554
- /**
555
- * Calculate center point.
556
- * @param bounds
557
- */
558
- this.center = ({ x, y, width, height }) => {
559
- const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
560
- 1,
561
- 2
562
- ]));
563
- const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
564
- 1,
565
- 2
566
- ]));
567
- return {
568
- x: cx,
569
- y: cy
570
- };
571
- };
572
- }
573
- static {
574
- /**
575
- * Calculate centered left edge.
576
- * @param bounds
577
- */
578
- this.left = ({ x, y, height }) => {
579
- const cx = x;
580
- const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
581
- 1,
582
- 2
583
- ]));
584
- return {
585
- x: cx,
586
- y: cy
587
- };
588
- };
589
- }
590
- static {
591
- /**
592
- * Calculate centered right edge.
593
- * @param bounds
594
- */
595
- this.right = ({ x, y, width, height }) => {
596
- const cx = FractionUtil.add(x, width);
597
- const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
598
- 1,
599
- 2
600
- ]));
601
- return {
602
- x: cx,
603
- y: cy
604
- };
605
- };
606
- }
493
+ return obj;
494
+ }
495
+ var Vector = class {
607
496
  };
497
+ _define_property5(Vector, "toVertex", ({ x, y }) => ({
498
+ x: FractionUtil.toFraction(x),
499
+ y: FractionUtil.toFraction(y)
500
+ }));
501
+ _define_property5(Vector, "toBounds", ({ x, y, width, height }) => ({
502
+ x: FractionUtil.toFraction(x),
503
+ y: FractionUtil.toFraction(y),
504
+ width: FractionUtil.toFraction(width),
505
+ height: FractionUtil.toFraction(height)
506
+ }));
507
+ _define_property5(Vector, "center", ({ x, y, width, height }) => {
508
+ const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
509
+ 1,
510
+ 2
511
+ ]));
512
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
513
+ 1,
514
+ 2
515
+ ]));
516
+ return {
517
+ x: cx,
518
+ y: cy
519
+ };
520
+ });
521
+ _define_property5(Vector, "left", ({ x, y, height }) => {
522
+ const cx = x;
523
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
524
+ 1,
525
+ 2
526
+ ]));
527
+ return {
528
+ x: cx,
529
+ y: cy
530
+ };
531
+ });
532
+ _define_property5(Vector, "right", ({ x, y, width, height }) => {
533
+ const cx = FractionUtil.add(x, width);
534
+ const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
535
+ 1,
536
+ 2
537
+ ]));
538
+ return {
539
+ x: cx,
540
+ y: cy
541
+ };
542
+ });
608
543
 
609
544
  // src/hooks/useSvgContext.ts
610
545
  import { createContext, useContext } from "react";
611
546
  import { createRef } from "react";
612
547
  import { raise } from "@dxos/debug";
613
- var SVGContext = class {
614
- constructor({ scale = new Scale(), centered = true }) {
615
- this._ref = createRef();
616
- this.resized = new EventEmitter();
617
- this._scale = scale;
618
- this._centered = centered;
548
+ function _define_property6(obj, key, value) {
549
+ if (key in obj) {
550
+ Object.defineProperty(obj, key, {
551
+ value,
552
+ enumerable: true,
553
+ configurable: true,
554
+ writable: true
555
+ });
556
+ } else {
557
+ obj[key] = value;
619
558
  }
559
+ return obj;
560
+ }
561
+ var SVGContext = class {
620
562
  get ref() {
621
563
  return this._ref;
622
564
  }
@@ -666,6 +608,16 @@ var SVGContext = class {
666
608
  const [cx, cy] = this._center;
667
609
  return document.elementFromPoint(cx + x, cy + y);
668
610
  }
611
+ constructor({ scale = new Scale(), centered = true }) {
612
+ _define_property6(this, "_ref", createRef());
613
+ _define_property6(this, "_scale", void 0);
614
+ _define_property6(this, "_centered", void 0);
615
+ _define_property6(this, "_size", void 0);
616
+ _define_property6(this, "_center", void 0);
617
+ _define_property6(this, "resized", new EventEmitter());
618
+ this._scale = scale;
619
+ this._centered = centered;
620
+ }
669
621
  };
670
622
  var SVGContextType = createContext(void 0);
671
623
  var SVGContextProvider = SVGContextType.Provider;
@@ -676,6 +628,19 @@ var useSvgContext = () => {
676
628
  // src/hooks/useGrid.ts
677
629
  import { line, range, select } from "d3";
678
630
  import { useEffect, useMemo, useRef } from "react";
631
+ function _define_property7(obj, key, value) {
632
+ if (key in obj) {
633
+ Object.defineProperty(obj, key, {
634
+ value,
635
+ enumerable: true,
636
+ configurable: true,
637
+ writable: true
638
+ });
639
+ } else {
640
+ obj[key] = value;
641
+ }
642
+ return obj;
643
+ }
679
644
  var createLine = line();
680
645
  var createGrid = (context, options) => {
681
646
  if (!context.size) {
@@ -791,13 +756,6 @@ var defaultGridOptions = {
791
756
  grid: true
792
757
  };
793
758
  var GridController = class {
794
- constructor(_ref, _context, _options) {
795
- this._ref = _ref;
796
- this._context = _context;
797
- this._options = _options;
798
- this._visible = false;
799
- this._visible = this._options.visible ?? true;
800
- }
801
759
  get ref() {
802
760
  return this._ref;
803
761
  }
@@ -822,6 +780,17 @@ var GridController = class {
822
780
  this.draw();
823
781
  return this;
824
782
  }
783
+ constructor(_ref, _context, _options) {
784
+ _define_property7(this, "_ref", void 0);
785
+ _define_property7(this, "_context", void 0);
786
+ _define_property7(this, "_options", void 0);
787
+ _define_property7(this, "_visible", void 0);
788
+ this._ref = _ref;
789
+ this._context = _context;
790
+ this._options = _options;
791
+ this._visible = false;
792
+ this._visible = this._options.visible ?? true;
793
+ }
825
794
  };
826
795
  var useGrid = (options = defaultGridOptions) => {
827
796
  const ref = useRef(null);
@@ -838,7 +807,7 @@ var useGrid = (options = defaultGridOptions) => {
838
807
  import { useEffect as useEffect2, useRef as useRef2, useState } from "react";
839
808
  var useStateRef = (initialValue) => {
840
809
  const [value, setValue] = useState(initialValue);
841
- const ref = useRef2();
810
+ const ref = useRef2(null);
842
811
  useEffect2(() => {
843
812
  ref.current = value;
844
813
  }, [
@@ -884,6 +853,19 @@ var useTimestamp = (deps) => {
884
853
  import { select as select2, zoom, zoomIdentity as zoomIdentity2 } from "d3";
885
854
  import defaultsDeep from "lodash.defaultsdeep";
886
855
  import { useEffect as useEffect3, useMemo as useMemo2, useRef as useRef3 } from "react";
856
+ function _define_property8(obj, key, value) {
857
+ if (key in obj) {
858
+ Object.defineProperty(obj, key, {
859
+ value,
860
+ enumerable: true,
861
+ configurable: true,
862
+ writable: true
863
+ });
864
+ } else {
865
+ obj[key] = value;
866
+ }
867
+ return obj;
868
+ }
887
869
  var defaultZoomOptions = {
888
870
  enabled: true,
889
871
  extent: [
@@ -893,13 +875,6 @@ var defaultZoomOptions = {
893
875
  onDblClick: (zoom2) => zoom2.reset()
894
876
  };
895
877
  var ZoomHandler = class {
896
- constructor(_ref, _context, options) {
897
- this._ref = _ref;
898
- this._context = _context;
899
- this._options = defaultsDeep({}, options, defaultZoomOptions);
900
- this._enabled = this._options.enabled ?? true;
901
- this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
902
- }
903
878
  /**
904
879
  * Gets the reference which the transform is applied to.
905
880
  */
@@ -936,6 +911,18 @@ var ZoomHandler = class {
936
911
  select2(this._context.svg).transition().duration(duration).call(this._zoom.transform, transform);
937
912
  return this;
938
913
  }
914
+ constructor(_ref, _context, options) {
915
+ _define_property8(this, "_ref", void 0);
916
+ _define_property8(this, "_context", void 0);
917
+ _define_property8(this, "_zoom", void 0);
918
+ _define_property8(this, "_options", void 0);
919
+ _define_property8(this, "_enabled", void 0);
920
+ this._ref = _ref;
921
+ this._context = _context;
922
+ this._options = defaultsDeep({}, options, defaultZoomOptions);
923
+ this._enabled = this._options.enabled ?? true;
924
+ this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
925
+ }
939
926
  };
940
927
  var useZoom = (options = defaultZoomOptions) => {
941
928
  const context = useSvgContext();
@@ -976,4 +963,4 @@ export {
976
963
  ZoomHandler,
977
964
  useZoom
978
965
  };
979
- //# sourceMappingURL=chunk-MGVY54T5.mjs.map
966
+ //# sourceMappingURL=chunk-EX2Q43O6.mjs.map