@dxos/react-ui-graph 0.8.2-main.10c050d
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/LICENSE +8 -0
- package/README.md +25 -0
- package/dist/lib/browser/chunk-2YMRPQU7.mjs +979 -0
- package/dist/lib/browser/chunk-2YMRPQU7.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1546 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/browser/testing/index.mjs +180 -0
- package/dist/lib/browser/testing/index.mjs.map +7 -0
- package/dist/lib/node/chunk-WFHWEMPB.cjs +919 -0
- package/dist/lib/node/chunk-WFHWEMPB.cjs.map +7 -0
- package/dist/lib/node/index.cjs +1547 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/lib/node/testing/index.cjs +214 -0
- package/dist/lib/node/testing/index.cjs.map +7 -0
- package/dist/lib/node-esm/chunk-ITHTKQOY.mjs +981 -0
- package/dist/lib/node-esm/chunk-ITHTKQOY.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1547 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +181 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/components/Graph/Graph.d.ts +26 -0
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -0
- package/dist/types/src/components/Graph/Graph.stories.d.ts +29 -0
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -0
- package/dist/types/src/components/Graph/index.d.ts +2 -0
- package/dist/types/src/components/Graph/index.d.ts.map +1 -0
- package/dist/types/src/components/Mesh/Mesh.d.ts +6 -0
- package/dist/types/src/components/Mesh/Mesh.d.ts.map +1 -0
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts +12 -0
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -0
- package/dist/types/src/components/Mesh/index.d.ts +2 -0
- package/dist/types/src/components/Mesh/index.d.ts.map +1 -0
- package/dist/types/src/components/SVG/Grid.d.ts +9 -0
- package/dist/types/src/components/SVG/Grid.d.ts.map +1 -0
- package/dist/types/src/components/SVG/Markers.d.ts +10 -0
- package/dist/types/src/components/SVG/Markers.d.ts.map +1 -0
- package/dist/types/src/components/SVG/Root.d.ts +12 -0
- package/dist/types/src/components/SVG/Root.d.ts.map +1 -0
- package/dist/types/src/components/SVG/SVG.d.ts +23 -0
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -0
- package/dist/types/src/components/SVG/Svg.stories.d.ts +17 -0
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -0
- package/dist/types/src/components/SVG/Zoom.d.ts +12 -0
- package/dist/types/src/components/SVG/Zoom.d.ts.map +1 -0
- package/dist/types/src/components/SVG/index.d.ts +2 -0
- package/dist/types/src/components/SVG/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +4 -0
- package/dist/types/src/components/index.d.ts.map +1 -0
- package/dist/types/src/fx/fx.stories.d.ts +19 -0
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -0
- package/dist/types/src/fx/index.d.ts +2 -0
- package/dist/types/src/fx/index.d.ts.map +1 -0
- package/dist/types/src/fx/pulsar.d.ts +17 -0
- package/dist/types/src/fx/pulsar.d.ts.map +1 -0
- package/dist/types/src/graph/index.d.ts +5 -0
- package/dist/types/src/graph/index.d.ts.map +1 -0
- package/dist/types/src/graph/markers.d.ts +11 -0
- package/dist/types/src/graph/markers.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-drag.d.ts +16 -0
- package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-force-projector.d.ts +96 -0
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-forces.d.ts +8 -0
- package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +14 -0
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-projector.d.ts +25 -0
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +34 -0
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts +14 -0
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/index.d.ts +8 -0
- package/dist/types/src/graph/projector/index.d.ts.map +1 -0
- package/dist/types/src/graph/projector/projector.d.ts +32 -0
- package/dist/types/src/graph/projector/projector.d.ts.map +1 -0
- package/dist/types/src/graph/renderer/bullets.d.ts +16 -0
- package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -0
- package/dist/types/src/graph/renderer/graph-renderer.d.ts +43 -0
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -0
- package/dist/types/src/graph/renderer/index.d.ts +4 -0
- package/dist/types/src/graph/renderer/index.d.ts.map +1 -0
- package/dist/types/src/graph/renderer/linker.d.ts +12 -0
- package/dist/types/src/graph/renderer/linker.d.ts.map +1 -0
- package/dist/types/src/graph/renderer/renderer.d.ts +20 -0
- package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -0
- package/dist/types/src/graph/types.d.ts +52 -0
- package/dist/types/src/graph/types.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +5 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useGrid.d.ts +24 -0
- package/dist/types/src/hooks/useGrid.d.ts.map +1 -0
- package/dist/types/src/hooks/useStateRef.d.ts +22 -0
- package/dist/types/src/hooks/useStateRef.d.ts.map +1 -0
- package/dist/types/src/hooks/useSvgContext.d.ts +41 -0
- package/dist/types/src/hooks/useSvgContext.d.ts.map +1 -0
- package/dist/types/src/hooks/useZoom.d.ts +34 -0
- package/dist/types/src/hooks/useZoom.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +6 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/stories/hooks.stories.d.ts +22 -0
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -0
- package/dist/types/src/testing/data.d.ts +27 -0
- package/dist/types/src/testing/data.d.ts.map +1 -0
- package/dist/types/src/testing/data.test.d.ts +2 -0
- package/dist/types/src/testing/data.test.d.ts.map +1 -0
- package/dist/types/src/testing/hooks.d.ts +42 -0
- package/dist/types/src/testing/hooks.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +4 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/model.d.ts +14 -0
- package/dist/types/src/testing/model.d.ts.map +1 -0
- package/dist/types/src/util/d3-types.d.ts +5 -0
- package/dist/types/src/util/d3-types.d.ts.map +1 -0
- package/dist/types/src/util/events.d.ts +10 -0
- package/dist/types/src/util/events.d.ts.map +1 -0
- package/dist/types/src/util/fraction.d.ts +65 -0
- package/dist/types/src/util/fraction.d.ts.map +1 -0
- package/dist/types/src/util/fraction.test.d.ts +2 -0
- package/dist/types/src/util/fraction.test.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +9 -0
- package/dist/types/src/util/index.d.ts.map +1 -0
- package/dist/types/src/util/points.d.ts +15 -0
- package/dist/types/src/util/points.d.ts.map +1 -0
- package/dist/types/src/util/scale.d.ts +57 -0
- package/dist/types/src/util/scale.d.ts.map +1 -0
- package/dist/types/src/util/scale.test.d.ts +2 -0
- package/dist/types/src/util/scale.test.d.ts.map +1 -0
- package/dist/types/src/util/screen.d.ts +25 -0
- package/dist/types/src/util/screen.d.ts.map +1 -0
- package/dist/types/src/util/screen.test.d.ts +2 -0
- package/dist/types/src/util/screen.test.d.ts.map +1 -0
- package/dist/types/src/util/types.d.ts +4 -0
- package/dist/types/src/util/types.d.ts.map +1 -0
- package/dist/types/src/util/vector.d.ts +48 -0
- package/dist/types/src/util/vector.d.ts.map +1 -0
- package/dist/types/src/util/vector.test.d.ts +2 -0
- package/dist/types/src/util/vector.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +86 -0
- package/src/components/Graph/Graph.stories.tsx +457 -0
- package/src/components/Graph/Graph.tsx +130 -0
- package/src/components/Graph/index.ts +5 -0
- package/src/components/Mesh/Mesh.stories.tsx +62 -0
- package/src/components/Mesh/Mesh.tsx +143 -0
- package/src/components/Mesh/index.ts +5 -0
- package/src/components/SVG/Grid.tsx +20 -0
- package/src/components/SVG/Markers.tsx +25 -0
- package/src/components/SVG/Root.tsx +55 -0
- package/src/components/SVG/SVG.tsx +27 -0
- package/src/components/SVG/Svg.stories.tsx +57 -0
- package/src/components/SVG/Zoom.tsx +27 -0
- package/src/components/SVG/index.ts +5 -0
- package/src/components/index.ts +7 -0
- package/src/fx/fx.stories.tsx +116 -0
- package/src/fx/index.ts +5 -0
- package/src/fx/pulsar.ts +58 -0
- package/src/graph/index.ts +8 -0
- package/src/graph/markers.ts +85 -0
- package/src/graph/projector/graph-drag.ts +124 -0
- package/src/graph/projector/graph-force-projector.ts +414 -0
- package/src/graph/projector/graph-forces.ts +35 -0
- package/src/graph/projector/graph-hierarchical-projector.ts +80 -0
- package/src/graph/projector/graph-projector.ts +99 -0
- package/src/graph/projector/graph-radial-projector.ts +142 -0
- package/src/graph/projector/graph-relational-projector.ts +110 -0
- package/src/graph/projector/index.ts +11 -0
- package/src/graph/projector/projector.ts +72 -0
- package/src/graph/renderer/bullets.ts +72 -0
- package/src/graph/renderer/graph-renderer.ts +484 -0
- package/src/graph/renderer/index.ts +7 -0
- package/src/graph/renderer/linker.ts +42 -0
- package/src/graph/renderer/renderer.ts +49 -0
- package/src/graph/types.ts +80 -0
- package/src/hooks/index.ts +8 -0
- package/src/hooks/useGrid.ts +194 -0
- package/src/hooks/useStateRef.ts +60 -0
- package/src/hooks/useSvgContext.ts +96 -0
- package/src/hooks/useZoom.ts +118 -0
- package/src/index.ts +9 -0
- package/src/stories/hooks.stories.tsx +212 -0
- package/src/testing/data.test.ts +12 -0
- package/src/testing/data.ts +100 -0
- package/src/testing/hooks.ts +103 -0
- package/src/testing/index.ts +7 -0
- package/src/testing/model.ts +29 -0
- package/src/typings.d.ts +5 -0
- package/src/util/d3-types.ts +26 -0
- package/src/util/events.ts +24 -0
- package/src/util/fraction.test.ts +76 -0
- package/src/util/fraction.ts +175 -0
- package/src/util/index.ts +12 -0
- package/src/util/points.ts +68 -0
- package/src/util/scale.test.ts +31 -0
- package/src/util/scale.ts +137 -0
- package/src/util/screen.test.ts +41 -0
- package/src/util/screen.ts +91 -0
- package/src/util/types.ts +9 -0
- package/src/util/vector.test.ts +15 -0
- package/src/util/vector.ts +67 -0
- package/styles/graph.css +142 -0
- package/testing.d.ts +11 -0
- package/testing.js +5 -0
|
@@ -0,0 +1,919 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var chunk_WFHWEMPB_exports = {};
|
|
29
|
+
__export(chunk_WFHWEMPB_exports, {
|
|
30
|
+
EventEmitter: () => EventEmitter,
|
|
31
|
+
FractionUtil: () => FractionUtil,
|
|
32
|
+
GridController: () => GridController,
|
|
33
|
+
SVGContext: () => SVGContext,
|
|
34
|
+
SVGContextProvider: () => SVGContextProvider,
|
|
35
|
+
Scale: () => Scale,
|
|
36
|
+
Screen: () => Screen,
|
|
37
|
+
Vector: () => Vector,
|
|
38
|
+
ZoomHandler: () => ZoomHandler,
|
|
39
|
+
getCircumferencePoints: () => getCircumferencePoints,
|
|
40
|
+
normal: () => normal,
|
|
41
|
+
offsetPoints: () => offsetPoints,
|
|
42
|
+
useDynamicRef: () => useDynamicRef,
|
|
43
|
+
useGrid: () => useGrid,
|
|
44
|
+
useStateRef: () => useStateRef,
|
|
45
|
+
useSvgContext: () => useSvgContext,
|
|
46
|
+
useTimestamp: () => useTimestamp,
|
|
47
|
+
useZoom: () => useZoom
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(chunk_WFHWEMPB_exports);
|
|
50
|
+
var import_invariant = require("@dxos/invariant");
|
|
51
|
+
var import_d3 = require("d3");
|
|
52
|
+
var import_react = require("react");
|
|
53
|
+
var import_react2 = require("react");
|
|
54
|
+
var import_debug = require("@dxos/debug");
|
|
55
|
+
var import_d32 = require("d3");
|
|
56
|
+
var import_react3 = require("react");
|
|
57
|
+
var import_react4 = require("react");
|
|
58
|
+
var import_d33 = require("d3");
|
|
59
|
+
var import_lodash = __toESM(require("lodash.defaultsdeep"));
|
|
60
|
+
var import_react5 = require("react");
|
|
61
|
+
var EventEmitter = class {
|
|
62
|
+
constructor() {
|
|
63
|
+
this._listeners = /* @__PURE__ */ new Set();
|
|
64
|
+
}
|
|
65
|
+
clear() {
|
|
66
|
+
this._listeners.clear();
|
|
67
|
+
}
|
|
68
|
+
on(onEvent) {
|
|
69
|
+
this._listeners.add(onEvent);
|
|
70
|
+
return () => this._listeners.delete(onEvent);
|
|
71
|
+
}
|
|
72
|
+
emit(value) {
|
|
73
|
+
this._listeners.forEach((listener) => listener(value));
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
|
|
77
|
+
var FractionUtil = class _FractionUtil {
|
|
78
|
+
static {
|
|
79
|
+
this.toFraction = (n) => {
|
|
80
|
+
return typeof n === "number" ? [
|
|
81
|
+
n,
|
|
82
|
+
1
|
|
83
|
+
] : n;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
static {
|
|
87
|
+
this.validate = (...fraction) => {
|
|
88
|
+
fraction.forEach(([n, d]) => {
|
|
89
|
+
if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
|
|
90
|
+
throw new Error(`Invalid fraction: ${n}/${d}`);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return fraction;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
static {
|
|
97
|
+
this.toNumber = ([n, d]) => {
|
|
98
|
+
_FractionUtil.validate([
|
|
99
|
+
n,
|
|
100
|
+
d
|
|
101
|
+
]);
|
|
102
|
+
return n / d;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
static {
|
|
106
|
+
this.round = ([n, d], p = 1) => {
|
|
107
|
+
_FractionUtil.validate([
|
|
108
|
+
n,
|
|
109
|
+
d
|
|
110
|
+
]);
|
|
111
|
+
const v = Math.round(_FractionUtil.toNumber(_FractionUtil.divide([
|
|
112
|
+
n,
|
|
113
|
+
d
|
|
114
|
+
], [
|
|
115
|
+
1,
|
|
116
|
+
p
|
|
117
|
+
])));
|
|
118
|
+
return _FractionUtil.simplify([
|
|
119
|
+
v,
|
|
120
|
+
p
|
|
121
|
+
]);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
static {
|
|
125
|
+
this.equals = (n1, n2) => {
|
|
126
|
+
return n1[0] * n2[1] === n1[1] * n2[0];
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
static {
|
|
130
|
+
this.isZero = ([n]) => {
|
|
131
|
+
return n === 0;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
static {
|
|
135
|
+
this.simplify = ([n, d]) => {
|
|
136
|
+
_FractionUtil.validate([
|
|
137
|
+
n,
|
|
138
|
+
d
|
|
139
|
+
]);
|
|
140
|
+
if (d < 1) {
|
|
141
|
+
const t = n / d;
|
|
142
|
+
if (Math.floor(t) === t) {
|
|
143
|
+
n = t;
|
|
144
|
+
d = 1;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const fn = _FractionUtil.factors(n).reverse();
|
|
148
|
+
const fd = _FractionUtil.factors(d).reverse();
|
|
149
|
+
let c;
|
|
150
|
+
for (let i = 0; i < fn.length; i++) {
|
|
151
|
+
c = fd.find((n2) => n2 === fn[i]);
|
|
152
|
+
if (c) {
|
|
153
|
+
return [
|
|
154
|
+
n / c,
|
|
155
|
+
d / c
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return [
|
|
160
|
+
n,
|
|
161
|
+
d
|
|
162
|
+
];
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
static {
|
|
166
|
+
this.factors = (n) => {
|
|
167
|
+
(0, import_invariant.invariant)(Number.isFinite(n), `Invalid number: ${n}`, {
|
|
168
|
+
F: __dxlog_file,
|
|
169
|
+
L: 113,
|
|
170
|
+
S: this,
|
|
171
|
+
A: [
|
|
172
|
+
"Number.isFinite(n)",
|
|
173
|
+
"`Invalid number: ${n}`"
|
|
174
|
+
]
|
|
175
|
+
});
|
|
176
|
+
const factors = [
|
|
177
|
+
1
|
|
178
|
+
];
|
|
179
|
+
if (Number.isSafeInteger(n)) {
|
|
180
|
+
let f = 1;
|
|
181
|
+
do {
|
|
182
|
+
if (n % ++f === 0) {
|
|
183
|
+
factors.push(f);
|
|
184
|
+
}
|
|
185
|
+
} while (n / f > 1 && f < 100);
|
|
186
|
+
}
|
|
187
|
+
return factors;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
static {
|
|
191
|
+
this.add = (n1, n2) => {
|
|
192
|
+
_FractionUtil.validate(n1, n2);
|
|
193
|
+
const d = n1[1] * n2[1];
|
|
194
|
+
const n = n1[0] * n2[1] + n2[0] * n1[1];
|
|
195
|
+
return _FractionUtil.simplify([
|
|
196
|
+
n,
|
|
197
|
+
d
|
|
198
|
+
]);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
static {
|
|
202
|
+
this.subtract = (n1, n2) => {
|
|
203
|
+
_FractionUtil.validate(n1, n2);
|
|
204
|
+
const d = n1[1] * n2[1];
|
|
205
|
+
const n = n1[0] * n2[1] - n2[0] * n1[1];
|
|
206
|
+
return _FractionUtil.simplify([
|
|
207
|
+
n,
|
|
208
|
+
d
|
|
209
|
+
]);
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
static {
|
|
213
|
+
this.multiply = (n1, n2) => {
|
|
214
|
+
_FractionUtil.validate(n1, n2);
|
|
215
|
+
const n = n1[0] * n2[0];
|
|
216
|
+
const d = n1[1] * n2[1];
|
|
217
|
+
return _FractionUtil.simplify([
|
|
218
|
+
n,
|
|
219
|
+
d
|
|
220
|
+
]);
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
static {
|
|
224
|
+
this.divide = (n1, n2) => {
|
|
225
|
+
_FractionUtil.validate(n1, n2);
|
|
226
|
+
const n = n1[0] * n2[1];
|
|
227
|
+
const d = n1[1] * n2[0];
|
|
228
|
+
return _FractionUtil.simplify([
|
|
229
|
+
n,
|
|
230
|
+
d
|
|
231
|
+
]);
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var getCircumferencePoints = (p1, p2, r1 = 0, r2 = 0) => {
|
|
236
|
+
const [x1, y1] = p1;
|
|
237
|
+
const [x2, y2] = p2;
|
|
238
|
+
const theta = Math.atan2(x2 - x1, y2 - y1);
|
|
239
|
+
return [
|
|
240
|
+
[
|
|
241
|
+
// p1
|
|
242
|
+
x1 + (r1 === 0 ? 0 : r1 * Math.sin(theta)),
|
|
243
|
+
y1 + (r1 === 0 ? 0 : r1 * Math.cos(theta))
|
|
244
|
+
],
|
|
245
|
+
[
|
|
246
|
+
// p2
|
|
247
|
+
x2 - (r2 === 0 ? 0 : r2 * Math.cos(Math.PI / 2 - theta)),
|
|
248
|
+
y2 - (r2 === 0 ? 0 : r2 * Math.sin(Math.PI / 2 - theta))
|
|
249
|
+
]
|
|
250
|
+
];
|
|
251
|
+
};
|
|
252
|
+
var normal = (p1, p2) => {
|
|
253
|
+
const dx = p2[0] - p1[0];
|
|
254
|
+
const dy = p2[1] - p1[1];
|
|
255
|
+
const len = Math.hypot(dx, dy);
|
|
256
|
+
return [
|
|
257
|
+
dy / len,
|
|
258
|
+
-dx / len
|
|
259
|
+
];
|
|
260
|
+
};
|
|
261
|
+
var offsetPoints = (points, distance, closed) => {
|
|
262
|
+
const len = points.length;
|
|
263
|
+
const out = [];
|
|
264
|
+
for (let i = 0; i < len; i++) {
|
|
265
|
+
const p0 = points[(i - 1 + len) % len];
|
|
266
|
+
const p1 = points[i];
|
|
267
|
+
const p2 = points[(i + 1) % len];
|
|
268
|
+
const n1 = normal(p0, p1);
|
|
269
|
+
const n2 = normal(p1, p2);
|
|
270
|
+
const nx = (n1[0] + n2[0]) / 2;
|
|
271
|
+
const ny = (n1[1] + n2[1]) / 2;
|
|
272
|
+
const norm = Math.hypot(nx, ny) || 1;
|
|
273
|
+
out.push([
|
|
274
|
+
p1[0] + distance * nx / norm,
|
|
275
|
+
p1[1] + distance * ny / norm
|
|
276
|
+
]);
|
|
277
|
+
if (!closed && (i === 0 || i === len - 1)) {
|
|
278
|
+
out[i] = [
|
|
279
|
+
p1[0] + distance * normal(p0, p1)[0],
|
|
280
|
+
p1[1] + distance * normal(p0, p1)[1]
|
|
281
|
+
];
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return out;
|
|
285
|
+
};
|
|
286
|
+
var Scale = class {
|
|
287
|
+
constructor(_gridSize = 32) {
|
|
288
|
+
this._gridSize = _gridSize;
|
|
289
|
+
this.model = {
|
|
290
|
+
// TODO(burdon): Precision depends on scale.
|
|
291
|
+
snapValues: (array) => array.map((n) => FractionUtil.round(n)),
|
|
292
|
+
snapVertex: ({ x, y }) => {
|
|
293
|
+
const [sx, sy] = this.model.snapValues([
|
|
294
|
+
x,
|
|
295
|
+
y
|
|
296
|
+
]);
|
|
297
|
+
return {
|
|
298
|
+
x: sx,
|
|
299
|
+
y: sy
|
|
300
|
+
};
|
|
301
|
+
},
|
|
302
|
+
snapBounds: ({ x, y, width, height }) => {
|
|
303
|
+
[x, y, width, height] = this.model.snapValues([
|
|
304
|
+
x,
|
|
305
|
+
y,
|
|
306
|
+
width,
|
|
307
|
+
height
|
|
308
|
+
]);
|
|
309
|
+
return {
|
|
310
|
+
x,
|
|
311
|
+
y,
|
|
312
|
+
width,
|
|
313
|
+
height
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
toValue: (value) => {
|
|
317
|
+
return Math.round(FractionUtil.toNumber(value) * this._gridSize);
|
|
318
|
+
},
|
|
319
|
+
toValues: (values) => {
|
|
320
|
+
return values.map((value) => Math.round(FractionUtil.toNumber(value) * this._gridSize));
|
|
321
|
+
},
|
|
322
|
+
toPoint: (point) => {
|
|
323
|
+
const [x, y] = this.model.toValues([
|
|
324
|
+
point.x,
|
|
325
|
+
point.y
|
|
326
|
+
]);
|
|
327
|
+
return [
|
|
328
|
+
x,
|
|
329
|
+
y === 0 ? 0 : -y
|
|
330
|
+
];
|
|
331
|
+
},
|
|
332
|
+
toBounds: ({ x, y, width, height }) => {
|
|
333
|
+
const point = this.model.toPoint({
|
|
334
|
+
x,
|
|
335
|
+
y
|
|
336
|
+
});
|
|
337
|
+
const [width2, height2] = this.model.toValues([
|
|
338
|
+
width,
|
|
339
|
+
height
|
|
340
|
+
]);
|
|
341
|
+
return {
|
|
342
|
+
x: point[0],
|
|
343
|
+
y: point[1] - height2,
|
|
344
|
+
width: width2,
|
|
345
|
+
height: height2
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
this.screen = {
|
|
350
|
+
snapValues: (array) => array.map((n) => Math.round(n / this._gridSize) * this._gridSize),
|
|
351
|
+
snapPoint: ([x, y]) => [
|
|
352
|
+
x,
|
|
353
|
+
y
|
|
354
|
+
].map((n) => Math.round(n / this._gridSize) * this._gridSize),
|
|
355
|
+
snapBounds: ({ x, y, width, height }) => {
|
|
356
|
+
[x, y, width, height] = this.screen.snapValues([
|
|
357
|
+
x,
|
|
358
|
+
y,
|
|
359
|
+
width,
|
|
360
|
+
height
|
|
361
|
+
]);
|
|
362
|
+
return {
|
|
363
|
+
x,
|
|
364
|
+
y,
|
|
365
|
+
width,
|
|
366
|
+
height
|
|
367
|
+
};
|
|
368
|
+
},
|
|
369
|
+
toValue: (value) => {
|
|
370
|
+
return FractionUtil.divide(FractionUtil.toFraction(value), [
|
|
371
|
+
this._gridSize,
|
|
372
|
+
1
|
|
373
|
+
]);
|
|
374
|
+
},
|
|
375
|
+
toValues: (values) => {
|
|
376
|
+
return values.map((value) => FractionUtil.divide(FractionUtil.toFraction(value), [
|
|
377
|
+
this._gridSize,
|
|
378
|
+
1
|
|
379
|
+
]));
|
|
380
|
+
},
|
|
381
|
+
toVertex: (point) => {
|
|
382
|
+
const [x, y] = point;
|
|
383
|
+
return {
|
|
384
|
+
x: FractionUtil.toFraction(x / this._gridSize),
|
|
385
|
+
y: FractionUtil.toFraction(-y / this._gridSize)
|
|
386
|
+
};
|
|
387
|
+
},
|
|
388
|
+
toBounds: (bounds) => {
|
|
389
|
+
const { x, y } = this.screen.toVertex([
|
|
390
|
+
bounds.x,
|
|
391
|
+
bounds.y
|
|
392
|
+
]);
|
|
393
|
+
const [width, height] = this.screen.toValues([
|
|
394
|
+
bounds.width,
|
|
395
|
+
bounds.height
|
|
396
|
+
]);
|
|
397
|
+
return {
|
|
398
|
+
x,
|
|
399
|
+
y: FractionUtil.subtract(y, height),
|
|
400
|
+
width,
|
|
401
|
+
height
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
get gridSize() {
|
|
407
|
+
return this._gridSize;
|
|
408
|
+
}
|
|
409
|
+
get transform() {
|
|
410
|
+
return this._transform || import_d3.zoomIdentity;
|
|
411
|
+
}
|
|
412
|
+
setTransform(transform) {
|
|
413
|
+
if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
this._transform = transform;
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Translate a screen point to a logical point.
|
|
421
|
+
* @param point
|
|
422
|
+
*/
|
|
423
|
+
translate(point) {
|
|
424
|
+
const { x, y, k } = this._transform ?? {
|
|
425
|
+
x: 0,
|
|
426
|
+
y: 0,
|
|
427
|
+
k: 1
|
|
428
|
+
};
|
|
429
|
+
return [
|
|
430
|
+
(point[0] - x) / k,
|
|
431
|
+
(point[1] - y) / k
|
|
432
|
+
];
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
var Screen = class {
|
|
436
|
+
static {
|
|
437
|
+
this.createBounds = ([x1, y1], [x2, y2], mod = {}) => {
|
|
438
|
+
const { constrain, center } = mod;
|
|
439
|
+
const x = Math.min(x1, x2);
|
|
440
|
+
const y = Math.min(y1, y2);
|
|
441
|
+
let width = Math.abs(x2 - x1);
|
|
442
|
+
let height = Math.abs(y2 - y1);
|
|
443
|
+
if (constrain) {
|
|
444
|
+
width = height = Math.max(width, height);
|
|
445
|
+
}
|
|
446
|
+
if (center) {
|
|
447
|
+
return {
|
|
448
|
+
x: x - width,
|
|
449
|
+
y: y - height,
|
|
450
|
+
width: width * 2,
|
|
451
|
+
height: height * 2
|
|
452
|
+
};
|
|
453
|
+
} else {
|
|
454
|
+
return {
|
|
455
|
+
x,
|
|
456
|
+
y,
|
|
457
|
+
width,
|
|
458
|
+
height
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
static {
|
|
464
|
+
this.center = ({ x, y, width, height }) => {
|
|
465
|
+
return [
|
|
466
|
+
x + width / 2,
|
|
467
|
+
y + height / 2
|
|
468
|
+
];
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
static {
|
|
472
|
+
this.contains = (bounds, point) => {
|
|
473
|
+
const [x, y] = point;
|
|
474
|
+
if (x < bounds.x || y < bounds.y) {
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
return true;
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
static {
|
|
484
|
+
this.len = (p1, p2) => {
|
|
485
|
+
return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
static {
|
|
489
|
+
this.normal = (v1, v2, p) => {
|
|
490
|
+
const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
|
|
491
|
+
let d;
|
|
492
|
+
const len2 = d2(v1, v2);
|
|
493
|
+
if (len2 === 0) {
|
|
494
|
+
d = d2(p, v1);
|
|
495
|
+
} else {
|
|
496
|
+
let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
|
|
497
|
+
t = Math.max(0, Math.min(1, t));
|
|
498
|
+
d = d2(p, [
|
|
499
|
+
v1[0] + t * (v2[0] - v1[0]),
|
|
500
|
+
v1[1] + t * (v2[1] - v1[1])
|
|
501
|
+
]);
|
|
502
|
+
}
|
|
503
|
+
return Math.sqrt(d);
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
var Vector = class {
|
|
508
|
+
static {
|
|
509
|
+
this.toVertex = ({ x, y }) => ({
|
|
510
|
+
x: FractionUtil.toFraction(x),
|
|
511
|
+
y: FractionUtil.toFraction(y)
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
static {
|
|
515
|
+
this.toBounds = ({ x, y, width, height }) => ({
|
|
516
|
+
x: FractionUtil.toFraction(x),
|
|
517
|
+
y: FractionUtil.toFraction(y),
|
|
518
|
+
width: FractionUtil.toFraction(width),
|
|
519
|
+
height: FractionUtil.toFraction(height)
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
static {
|
|
523
|
+
this.center = ({ x, y, width, height }) => {
|
|
524
|
+
const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
|
|
525
|
+
1,
|
|
526
|
+
2
|
|
527
|
+
]));
|
|
528
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
529
|
+
1,
|
|
530
|
+
2
|
|
531
|
+
]));
|
|
532
|
+
return {
|
|
533
|
+
x: cx,
|
|
534
|
+
y: cy
|
|
535
|
+
};
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
static {
|
|
539
|
+
this.left = ({ x, y, height }) => {
|
|
540
|
+
const cx = x;
|
|
541
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
542
|
+
1,
|
|
543
|
+
2
|
|
544
|
+
]));
|
|
545
|
+
return {
|
|
546
|
+
x: cx,
|
|
547
|
+
y: cy
|
|
548
|
+
};
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
static {
|
|
552
|
+
this.right = ({ x, y, width, height }) => {
|
|
553
|
+
const cx = FractionUtil.add(x, width);
|
|
554
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
555
|
+
1,
|
|
556
|
+
2
|
|
557
|
+
]));
|
|
558
|
+
return {
|
|
559
|
+
x: cx,
|
|
560
|
+
y: cy
|
|
561
|
+
};
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
var SVGContext = class {
|
|
566
|
+
constructor({ scale = new Scale(), centered = true }) {
|
|
567
|
+
this._ref = (0, import_react2.createRef)();
|
|
568
|
+
this.resized = new EventEmitter();
|
|
569
|
+
this._scale = scale;
|
|
570
|
+
this._centered = centered;
|
|
571
|
+
}
|
|
572
|
+
get ref() {
|
|
573
|
+
return this._ref;
|
|
574
|
+
}
|
|
575
|
+
get svg() {
|
|
576
|
+
return this._ref.current;
|
|
577
|
+
}
|
|
578
|
+
get scale() {
|
|
579
|
+
return this._scale;
|
|
580
|
+
}
|
|
581
|
+
get center() {
|
|
582
|
+
return this._center;
|
|
583
|
+
}
|
|
584
|
+
get size() {
|
|
585
|
+
return this._size;
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
|
|
589
|
+
*/
|
|
590
|
+
get viewBox() {
|
|
591
|
+
const [x, y] = this.center;
|
|
592
|
+
return `${x},${y},${this._size.width},${this._size.height}`;
|
|
593
|
+
}
|
|
594
|
+
setSize(size) {
|
|
595
|
+
this._size = {
|
|
596
|
+
...size
|
|
597
|
+
};
|
|
598
|
+
this._center = this._centered ? [
|
|
599
|
+
-Math.floor(size.width / 2),
|
|
600
|
+
-Math.floor(size.height / 2)
|
|
601
|
+
] : [
|
|
602
|
+
0,
|
|
603
|
+
0
|
|
604
|
+
];
|
|
605
|
+
this.resized.emit(this);
|
|
606
|
+
}
|
|
607
|
+
setTransform(transform) {
|
|
608
|
+
if (this._scale.setTransform(transform)) {
|
|
609
|
+
this.resized.emit(this);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint
|
|
614
|
+
* @param point
|
|
615
|
+
*/
|
|
616
|
+
elementFromPoint(point) {
|
|
617
|
+
const [x, y] = point;
|
|
618
|
+
const [cx, cy] = this._center;
|
|
619
|
+
return document.elementFromPoint(cx + x, cy + y);
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
var SVGContextType = (0, import_react.createContext)(void 0);
|
|
623
|
+
var SVGContextProvider = SVGContextType.Provider;
|
|
624
|
+
var useSvgContext = () => {
|
|
625
|
+
return (0, import_react.useContext)(SVGContextType) ?? (0, import_debug.raise)(new Error("Missing SVGRoot"));
|
|
626
|
+
};
|
|
627
|
+
var createLine = (0, import_d32.line)();
|
|
628
|
+
var createGrid = (context, options) => {
|
|
629
|
+
if (!context.size) {
|
|
630
|
+
return [];
|
|
631
|
+
}
|
|
632
|
+
const paths = [];
|
|
633
|
+
const { width, height } = context.size;
|
|
634
|
+
const { x, y, k } = context.scale.transform;
|
|
635
|
+
const s = 1 / k;
|
|
636
|
+
const w = width * s;
|
|
637
|
+
const h = height * s;
|
|
638
|
+
const dx = -(x + width / 2) * s;
|
|
639
|
+
const dy = -(y + height / 2) * s;
|
|
640
|
+
if (options.axis) {
|
|
641
|
+
const axis = [
|
|
642
|
+
[
|
|
643
|
+
[
|
|
644
|
+
0,
|
|
645
|
+
dy
|
|
646
|
+
],
|
|
647
|
+
[
|
|
648
|
+
0,
|
|
649
|
+
dy + h
|
|
650
|
+
]
|
|
651
|
+
],
|
|
652
|
+
[
|
|
653
|
+
[
|
|
654
|
+
dx,
|
|
655
|
+
0
|
|
656
|
+
],
|
|
657
|
+
[
|
|
658
|
+
dx + w,
|
|
659
|
+
0
|
|
660
|
+
]
|
|
661
|
+
]
|
|
662
|
+
];
|
|
663
|
+
paths.push({
|
|
664
|
+
id: "axis",
|
|
665
|
+
class: "dx-axis",
|
|
666
|
+
path: axis.map((line2) => createLine(line2)).join()
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
if (options.grid) {
|
|
670
|
+
const mod = (n, size, delta = 0) => Math.floor(n / size + delta) * size;
|
|
671
|
+
const majorSize = context.scale.gridSize;
|
|
672
|
+
const xMajor = (0, import_d32.range)(-mod((x + width / 2) * s, majorSize), mod((-x + width / 2) * s, majorSize, 1), majorSize);
|
|
673
|
+
const yMajor = (0, import_d32.range)(-mod((y + height / 2) * s, majorSize), mod((-y + height / 2) * s, majorSize, 1), majorSize);
|
|
674
|
+
const major = [
|
|
675
|
+
...xMajor.filter((x2) => !options.axis || x2).map((x2) => [
|
|
676
|
+
[
|
|
677
|
+
x2,
|
|
678
|
+
dy
|
|
679
|
+
],
|
|
680
|
+
[
|
|
681
|
+
x2,
|
|
682
|
+
dy + h
|
|
683
|
+
]
|
|
684
|
+
]),
|
|
685
|
+
...yMajor.filter((y2) => !options.axis || y2).map((y2) => [
|
|
686
|
+
[
|
|
687
|
+
dx,
|
|
688
|
+
y2
|
|
689
|
+
],
|
|
690
|
+
[
|
|
691
|
+
dx + w,
|
|
692
|
+
y2
|
|
693
|
+
]
|
|
694
|
+
])
|
|
695
|
+
];
|
|
696
|
+
paths.push({
|
|
697
|
+
id: "major",
|
|
698
|
+
class: "dx-major",
|
|
699
|
+
path: major.map((line2) => createLine(line2)).join()
|
|
700
|
+
});
|
|
701
|
+
const minorSize = Math.pow(2, Math.round(Math.log2(s * context.scale.gridSize)));
|
|
702
|
+
if (majorSize > minorSize) {
|
|
703
|
+
const xMinor = (0, import_d32.range)(-mod((x + width / 2) * s, minorSize), mod((-x + width / 2) * s, minorSize, 1), minorSize);
|
|
704
|
+
const yMinor = (0, import_d32.range)(-mod((y + height / 2) * s, minorSize), mod((-y + height / 2) * s, minorSize, 1), minorSize);
|
|
705
|
+
const minor = [
|
|
706
|
+
...xMinor.filter((x2) => xMajor.indexOf(x2) === -1).map((x2) => [
|
|
707
|
+
[
|
|
708
|
+
x2,
|
|
709
|
+
dy
|
|
710
|
+
],
|
|
711
|
+
[
|
|
712
|
+
x2,
|
|
713
|
+
dy + h
|
|
714
|
+
]
|
|
715
|
+
]),
|
|
716
|
+
...yMinor.filter((y2) => yMajor.indexOf(y2) === -1).map((y2) => [
|
|
717
|
+
[
|
|
718
|
+
dx,
|
|
719
|
+
y2
|
|
720
|
+
],
|
|
721
|
+
[
|
|
722
|
+
dx + w,
|
|
723
|
+
y2
|
|
724
|
+
]
|
|
725
|
+
])
|
|
726
|
+
];
|
|
727
|
+
paths.push({
|
|
728
|
+
id: "minor",
|
|
729
|
+
class: "dx-minor",
|
|
730
|
+
path: minor.map((line2) => createLine(line2)).join()
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return paths;
|
|
735
|
+
};
|
|
736
|
+
var defaultGridOptions = {
|
|
737
|
+
visible: true,
|
|
738
|
+
axis: true,
|
|
739
|
+
grid: true
|
|
740
|
+
};
|
|
741
|
+
var GridController = class {
|
|
742
|
+
constructor(_ref, _context, _options) {
|
|
743
|
+
this._ref = _ref;
|
|
744
|
+
this._context = _context;
|
|
745
|
+
this._options = _options;
|
|
746
|
+
this._visible = false;
|
|
747
|
+
this._visible = this._options.visible ?? true;
|
|
748
|
+
}
|
|
749
|
+
get ref() {
|
|
750
|
+
return this._ref;
|
|
751
|
+
}
|
|
752
|
+
get visible() {
|
|
753
|
+
return this._visible;
|
|
754
|
+
}
|
|
755
|
+
draw() {
|
|
756
|
+
if (!this._context.size) {
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
const paths = this._visible ? createGrid(this._context, this._options) : [];
|
|
760
|
+
const root = (0, import_d32.select)(this._ref.current);
|
|
761
|
+
root.selectAll("path").data(paths, (path) => path.id).join("path").style("pointer-events", "none").attr("d", (d) => d.path).attr("class", (d) => d.class);
|
|
762
|
+
const transform = this._context.scale.transform;
|
|
763
|
+
if (transform) {
|
|
764
|
+
root.attr("transform", transform);
|
|
765
|
+
root.attr("stroke-width", 1 / transform.k);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
setVisible(visible) {
|
|
769
|
+
this._visible = visible;
|
|
770
|
+
this.draw();
|
|
771
|
+
return this;
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
var useGrid = (options = defaultGridOptions) => {
|
|
775
|
+
const ref = (0, import_react3.useRef)(null);
|
|
776
|
+
const context = useSvgContext();
|
|
777
|
+
const controller = (0, import_react3.useMemo)(() => new GridController(ref, context, options), []);
|
|
778
|
+
(0, import_react3.useEffect)(() => context.resized.on(() => controller.draw()), [
|
|
779
|
+
context,
|
|
780
|
+
controller
|
|
781
|
+
]);
|
|
782
|
+
return controller;
|
|
783
|
+
};
|
|
784
|
+
var useStateRef = (initialValue) => {
|
|
785
|
+
const [value, setValue] = (0, import_react4.useState)(initialValue);
|
|
786
|
+
const ref = (0, import_react4.useRef)();
|
|
787
|
+
(0, import_react4.useEffect)(() => {
|
|
788
|
+
ref.current = value;
|
|
789
|
+
}, [
|
|
790
|
+
initialValue,
|
|
791
|
+
value
|
|
792
|
+
]);
|
|
793
|
+
return [
|
|
794
|
+
value,
|
|
795
|
+
setValue,
|
|
796
|
+
ref
|
|
797
|
+
];
|
|
798
|
+
};
|
|
799
|
+
var useDynamicRef = (initialValue, deps) => {
|
|
800
|
+
const [, setValue] = (0, import_react4.useState)(initialValue);
|
|
801
|
+
const ref = (0, import_react4.useRef)(initialValue());
|
|
802
|
+
(0, import_react4.useEffect)(() => {
|
|
803
|
+
ref.current = initialValue();
|
|
804
|
+
setValue(ref.current);
|
|
805
|
+
}, deps);
|
|
806
|
+
return ref;
|
|
807
|
+
};
|
|
808
|
+
var useTimestamp = (deps) => {
|
|
809
|
+
const [{ timestamp, previous }, setTimestamp] = (0, import_react4.useState)({
|
|
810
|
+
timestamp: Date.now()
|
|
811
|
+
});
|
|
812
|
+
(0, import_react4.useEffect)(() => {
|
|
813
|
+
setTimestamp({
|
|
814
|
+
timestamp: Date.now(),
|
|
815
|
+
previous: timestamp
|
|
816
|
+
});
|
|
817
|
+
}, deps ?? []);
|
|
818
|
+
return [
|
|
819
|
+
timestamp,
|
|
820
|
+
() => setTimestamp({
|
|
821
|
+
timestamp: Date.now(),
|
|
822
|
+
previous: timestamp
|
|
823
|
+
}),
|
|
824
|
+
previous
|
|
825
|
+
];
|
|
826
|
+
};
|
|
827
|
+
var defaultZoomOptions = {
|
|
828
|
+
enabled: true,
|
|
829
|
+
extent: [
|
|
830
|
+
1 / 4,
|
|
831
|
+
4
|
|
832
|
+
],
|
|
833
|
+
onDblClick: (zoom2) => zoom2.reset()
|
|
834
|
+
};
|
|
835
|
+
var ZoomHandler = class {
|
|
836
|
+
constructor(_ref, _context, options) {
|
|
837
|
+
this._ref = _ref;
|
|
838
|
+
this._context = _context;
|
|
839
|
+
this._options = (0, import_lodash.default)({}, options, defaultZoomOptions);
|
|
840
|
+
this._enabled = this._options.enabled ?? true;
|
|
841
|
+
this._zoom = (0, import_d33.zoom)().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Gets the reference which the transform is applied to.
|
|
845
|
+
*/
|
|
846
|
+
get ref() {
|
|
847
|
+
return this._ref;
|
|
848
|
+
}
|
|
849
|
+
get zoom() {
|
|
850
|
+
return this._zoom;
|
|
851
|
+
}
|
|
852
|
+
init() {
|
|
853
|
+
this.setEnabled(this._enabled);
|
|
854
|
+
this.reset(0);
|
|
855
|
+
return this;
|
|
856
|
+
}
|
|
857
|
+
setEnabled(enable) {
|
|
858
|
+
if (enable) {
|
|
859
|
+
(0, import_d33.select)(this._context.svg).call(this._zoom).on(
|
|
860
|
+
"dblclick.zoom",
|
|
861
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
862
|
+
// @ts-ignore
|
|
863
|
+
this._options?.onDblClick ? () => {
|
|
864
|
+
this._options?.onDblClick(this);
|
|
865
|
+
} : null
|
|
866
|
+
);
|
|
867
|
+
} else {
|
|
868
|
+
(0, import_d33.select)(this._context.svg).on(".zoom", null);
|
|
869
|
+
}
|
|
870
|
+
this._enabled = enable;
|
|
871
|
+
return this;
|
|
872
|
+
}
|
|
873
|
+
reset(duration = 500) {
|
|
874
|
+
const scale = 1;
|
|
875
|
+
const transform = import_d33.zoomIdentity.scale(scale);
|
|
876
|
+
(0, import_d33.select)(this._context.svg).transition().duration(duration).call(this._zoom.transform, transform);
|
|
877
|
+
return this;
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
var useZoom = (options = defaultZoomOptions) => {
|
|
881
|
+
const context = useSvgContext();
|
|
882
|
+
const ref = (0, import_react5.useRef)(null);
|
|
883
|
+
const handler = (0, import_react5.useMemo)(() => new ZoomHandler(ref, context, options), [
|
|
884
|
+
context,
|
|
885
|
+
options
|
|
886
|
+
]);
|
|
887
|
+
(0, import_react5.useEffect)(() => {
|
|
888
|
+
handler.zoom.on("zoom", ({ transform }) => {
|
|
889
|
+
context.setTransform(transform);
|
|
890
|
+
(0, import_d33.select)(ref.current).attr("transform", transform);
|
|
891
|
+
});
|
|
892
|
+
handler.init();
|
|
893
|
+
}, [
|
|
894
|
+
handler
|
|
895
|
+
]);
|
|
896
|
+
return handler;
|
|
897
|
+
};
|
|
898
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
899
|
+
0 && (module.exports = {
|
|
900
|
+
EventEmitter,
|
|
901
|
+
FractionUtil,
|
|
902
|
+
GridController,
|
|
903
|
+
SVGContext,
|
|
904
|
+
SVGContextProvider,
|
|
905
|
+
Scale,
|
|
906
|
+
Screen,
|
|
907
|
+
Vector,
|
|
908
|
+
ZoomHandler,
|
|
909
|
+
getCircumferencePoints,
|
|
910
|
+
normal,
|
|
911
|
+
offsetPoints,
|
|
912
|
+
useDynamicRef,
|
|
913
|
+
useGrid,
|
|
914
|
+
useStateRef,
|
|
915
|
+
useSvgContext,
|
|
916
|
+
useTimestamp,
|
|
917
|
+
useZoom
|
|
918
|
+
});
|
|
919
|
+
//# sourceMappingURL=chunk-WFHWEMPB.cjs.map
|