@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.
- package/dist/lib/browser/{chunk-MGVY54T5.mjs → chunk-HLAKLUDC.mjs} +351 -372
- package/dist/lib/browser/{chunk-MGVY54T5.mjs.map → chunk-HLAKLUDC.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +23 -16
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node-esm/{chunk-X5YVOSXZ.mjs → chunk-O6GWCXDC.mjs} +351 -372
- package/dist/lib/node-esm/{chunk-X5YVOSXZ.mjs.map → chunk-O6GWCXDC.mjs.map} +3 -3
- package/dist/lib/node-esm/index.mjs +23 -16
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +1 -1
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts +2 -2
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Zoom.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-drag.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/hooks/useZoom.d.ts.map +1 -1
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/hooks.d.ts.map +1 -1
- package/dist/types/src/util/screen.d.ts +1 -1
- package/dist/types/src/util/screen.d.ts.map +1 -1
- package/dist/types/src/util/vector.d.ts +1 -1
- package/dist/types/src/util/vector.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/components/Graph/Graph.stories.tsx +7 -6
- package/src/components/Graph/Graph.tsx +1 -1
- package/src/components/Mesh/Mesh.stories.tsx +2 -1
- package/src/components/Mesh/Mesh.tsx +1 -1
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Root.tsx +1 -1
- package/src/components/SVG/SVG.tsx +4 -3
- package/src/components/SVG/Svg.stories.tsx +2 -1
- package/src/components/SVG/Zoom.tsx +1 -1
- package/src/fx/fx.stories.tsx +2 -1
- package/src/graph/projector/graph-drag.ts +2 -1
- package/src/graph/projector/graph-force-projector.ts +2 -1
- package/src/graph/projector/graph-forces.ts +1 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +2 -1
- package/src/graph/projector/graph-projector.ts +4 -3
- package/src/graph/projector/graph-radial-projector.ts +3 -2
- package/src/graph/projector/graph-relational-projector.ts +2 -1
- package/src/graph/projector/projector.ts +1 -1
- package/src/graph/renderer/bullets.ts +1 -1
- package/src/graph/renderer/graph-renderer.ts +4 -3
- package/src/graph/renderer/renderer.ts +1 -1
- package/src/hooks/useZoom.ts +1 -1
- package/src/stories/hooks.stories.tsx +5 -5
- package/src/testing/hooks.ts +3 -2
- package/src/util/screen.test.ts +1 -1
- package/src/util/screen.ts +1 -1
- package/src/util/vector.ts +1 -1
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// src/util/events.ts
|
|
2
2
|
var EventEmitter = class {
|
|
3
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
n,
|
|
186
|
-
|
|
187
|
-
]
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
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
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
static {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
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
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
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
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
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-
|
|
958
|
+
//# sourceMappingURL=chunk-HLAKLUDC.mjs.map
|