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