@dxos/react-ui-graph 0.8.4-main.b97322e → 0.8.4-main.f5c0578

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