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