pantograph2d 0.4.0 → 0.5.0
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/{Diagram-1c56996e.js → Diagram-9915ed5e.js} +78 -76
- package/dist/Diagram-9915ed5e.js.map +1 -0
- package/dist/{Diagram-4fa55d2b.cjs → Diagram-c2ca1c3b.cjs} +3 -3
- package/dist/Diagram-c2ca1c3b.cjs.map +1 -0
- package/dist/{draw-8c69c65f.cjs → draw-25b9ed64.cjs} +2 -2
- package/dist/{draw-8c69c65f.cjs.map → draw-25b9ed64.cjs.map} +1 -1
- package/dist/{draw-44dd36a9.js → draw-cd61ec6b.js} +9 -9
- package/dist/{draw-44dd36a9.js.map → draw-cd61ec6b.js.map} +1 -1
- package/dist/pantograph/drawShape.cjs +1 -1
- package/dist/pantograph/drawShape.js +2 -2
- package/dist/pantograph/models.cjs +1 -1
- package/dist/pantograph/models.js +3 -3
- package/dist/pantograph.cjs +6 -6
- package/dist/pantograph.cjs.map +1 -1
- package/dist/pantograph.d.ts +10 -1
- package/dist/pantograph.js +326 -260
- package/dist/pantograph.js.map +1 -1
- package/package.json +2 -2
- package/dist/Diagram-1c56996e.js.map +0 -1
- package/dist/Diagram-4fa55d2b.cjs.map +0 -1
package/dist/pantograph.js
CHANGED
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
import { o as
|
|
2
|
-
import { d as
|
|
3
|
-
import { F as
|
|
4
|
-
import {
|
|
5
|
-
function
|
|
6
|
-
if (t instanceof
|
|
1
|
+
import { o as ct, D as b } from "./draw-cd61ec6b.js";
|
|
2
|
+
import { d as _t } from "./draw-cd61ec6b.js";
|
|
3
|
+
import { F as g, L as d, D as p, f as O, r as ut, z as lt, s as pt, a as Pt, c as gt, i as mt, l as wt, d as h, b as dt, p as ht, n as B, e as v, g as St, h as At, j as Mt, k as $t, m as w, A as S, o as H, q as A, t as Lt, u as Ft, v as vt, S as K } from "./Diagram-9915ed5e.js";
|
|
4
|
+
import { w as tn } from "./Diagram-9915ed5e.js";
|
|
5
|
+
function M(t) {
|
|
6
|
+
if (t instanceof g)
|
|
7
7
|
return [t];
|
|
8
|
-
if (t instanceof
|
|
9
|
-
return [new
|
|
10
|
-
if (t instanceof
|
|
8
|
+
if (t instanceof d)
|
|
9
|
+
return [new g(t)];
|
|
10
|
+
if (t instanceof p)
|
|
11
11
|
return t.figures;
|
|
12
12
|
throw new Error("Unknown shape");
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function Q(t, n, e = 1e-9) {
|
|
15
15
|
let r = [];
|
|
16
16
|
const o = [], s = new Array(n.segments.length).fill(0).map(() => []);
|
|
17
|
-
n.segments.forEach((
|
|
18
|
-
t.segments.forEach((
|
|
19
|
-
const { intersections:
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
n.segments.forEach((a, u) => {
|
|
18
|
+
t.segments.forEach((f) => {
|
|
19
|
+
const { intersections: l, overlaps: m } = O(
|
|
20
|
+
a,
|
|
21
|
+
f,
|
|
22
22
|
e
|
|
23
23
|
);
|
|
24
|
-
r.push(...
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
r.push(...l), s[u].push(...l), o.push(...m);
|
|
25
|
+
const P = m.flatMap((c) => [
|
|
26
|
+
c.firstPoint,
|
|
27
|
+
c.lastPoint
|
|
28
28
|
]);
|
|
29
|
-
r.push(...
|
|
29
|
+
r.push(...P), s[u].push(...P);
|
|
30
30
|
});
|
|
31
|
-
}), r =
|
|
32
|
-
const
|
|
31
|
+
}), r = ut(r, e);
|
|
32
|
+
const i = lt([n.segments, s]).flatMap(([a, u]) => u.length ? a.splitAt(u) : [a]);
|
|
33
33
|
return Array.from(
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
pt(
|
|
35
|
+
i,
|
|
36
36
|
r,
|
|
37
37
|
o
|
|
38
38
|
)
|
|
39
39
|
);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
return
|
|
41
|
+
function C(t, n, e = !1) {
|
|
42
|
+
return Q(n, t).filter((o) => {
|
|
43
43
|
const s = o.segments[0].midPoint;
|
|
44
44
|
return n.onStroke(s) ? !e : !n.contains(s);
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
-
function
|
|
48
|
-
return
|
|
47
|
+
function G(t, n, e = !1) {
|
|
48
|
+
return Q(n, t).filter((o) => {
|
|
49
49
|
const s = o.segments[0].midPoint;
|
|
50
50
|
return n.onStroke(s) ? !e : n.contains(s);
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
const r =
|
|
53
|
+
function R(t, n, e = !1) {
|
|
54
|
+
const r = C(
|
|
55
55
|
t,
|
|
56
56
|
n.contour,
|
|
57
57
|
e
|
|
58
58
|
), o = n.holes.flatMap(
|
|
59
|
-
(s) =>
|
|
59
|
+
(s) => G(t, s, e)
|
|
60
60
|
);
|
|
61
61
|
return [...r, ...o];
|
|
62
62
|
}
|
|
63
|
-
function
|
|
64
|
-
let r =
|
|
63
|
+
function U(t, n, e = !1) {
|
|
64
|
+
let r = G(
|
|
65
65
|
t,
|
|
66
66
|
n.contour,
|
|
67
67
|
e
|
|
68
68
|
);
|
|
69
69
|
return n.holes.forEach((o) => {
|
|
70
70
|
r = r.flatMap(
|
|
71
|
-
(s) =>
|
|
71
|
+
(s) => C(s, o, e)
|
|
72
72
|
);
|
|
73
73
|
}), r;
|
|
74
74
|
}
|
|
75
|
-
function
|
|
76
|
-
return new
|
|
77
|
-
|
|
75
|
+
function Et(t, n) {
|
|
76
|
+
return new p(
|
|
77
|
+
Pt(M(t), M(n))
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
|
-
function
|
|
80
|
+
function E(t) {
|
|
81
81
|
return t.reduce(
|
|
82
|
-
(n, e) =>
|
|
83
|
-
new
|
|
82
|
+
(n, e) => Et(n, e),
|
|
83
|
+
new p()
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
|
-
function
|
|
87
|
-
return new
|
|
88
|
-
|
|
86
|
+
function _(t, n) {
|
|
87
|
+
return new p(
|
|
88
|
+
gt(M(t), M(n))
|
|
89
89
|
);
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
return new
|
|
93
|
-
|
|
91
|
+
function Nt(t, n) {
|
|
92
|
+
return new p(
|
|
93
|
+
mt(M(t), M(n))
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
if (n instanceof
|
|
98
|
-
return
|
|
99
|
-
if (n instanceof
|
|
100
|
-
return
|
|
96
|
+
function qt(t, n, e = !0) {
|
|
97
|
+
if (n instanceof d)
|
|
98
|
+
return C(t, n, e);
|
|
99
|
+
if (n instanceof g)
|
|
100
|
+
return R(t, n, e);
|
|
101
101
|
let r = [t];
|
|
102
102
|
return n.figures.forEach((o) => {
|
|
103
|
-
r = r.flatMap((s) =>
|
|
103
|
+
r = r.flatMap((s) => R(s, o, e));
|
|
104
104
|
}), r;
|
|
105
105
|
}
|
|
106
|
-
function
|
|
107
|
-
if (n instanceof
|
|
108
|
-
return
|
|
109
|
-
if (n instanceof
|
|
110
|
-
return
|
|
106
|
+
function Jt(t, n, e = !1) {
|
|
107
|
+
if (n instanceof d)
|
|
108
|
+
return G(t, n, e);
|
|
109
|
+
if (n instanceof g)
|
|
110
|
+
return U(t, n, e);
|
|
111
111
|
let r = [t];
|
|
112
112
|
return n.figures.forEach((o) => {
|
|
113
|
-
r = r.flatMap((s) =>
|
|
113
|
+
r = r.flatMap((s) => U(s, o, e));
|
|
114
114
|
}), r;
|
|
115
115
|
}
|
|
116
|
-
function
|
|
116
|
+
function z(t) {
|
|
117
117
|
return t < 0 ? "before" : t > 1 ? "after" : "between";
|
|
118
118
|
}
|
|
119
119
|
const N = (t, n, e) => {
|
|
@@ -123,47 +123,47 @@ const N = (t, n, e) => {
|
|
|
123
123
|
return t.distanceFrom(n.lastPoint);
|
|
124
124
|
throw new Error("Invalid position");
|
|
125
125
|
};
|
|
126
|
-
function
|
|
127
|
-
const e =
|
|
126
|
+
function yt(t, n) {
|
|
127
|
+
const e = wt(t, n);
|
|
128
128
|
if (e === "parallel")
|
|
129
129
|
return Math.min(
|
|
130
130
|
t.distanceFrom(n.firstPoint),
|
|
131
131
|
t.distanceFrom(n.lastPoint)
|
|
132
132
|
);
|
|
133
|
-
const { intersectionParam1: r, intersectionParam2: o } = e, s =
|
|
134
|
-
if (s === "between" &&
|
|
133
|
+
const { intersectionParam1: r, intersectionParam2: o } = e, s = z(r), i = z(o);
|
|
134
|
+
if (s === "between" && i === "between")
|
|
135
135
|
return 0;
|
|
136
|
-
if (s === "between" &&
|
|
137
|
-
return N(t, n,
|
|
138
|
-
if (
|
|
136
|
+
if (s === "between" && i !== "between")
|
|
137
|
+
return N(t, n, i);
|
|
138
|
+
if (i === "between" && s !== "between")
|
|
139
139
|
return N(n, t, s);
|
|
140
|
-
if (s === "before" &&
|
|
141
|
-
return
|
|
142
|
-
if (s === "after" &&
|
|
143
|
-
return
|
|
144
|
-
if (s === "before" &&
|
|
145
|
-
return
|
|
146
|
-
if (s === "after" &&
|
|
147
|
-
return
|
|
140
|
+
if (s === "before" && i === "before")
|
|
141
|
+
return h(t.firstPoint, n.firstPoint);
|
|
142
|
+
if (s === "after" && i === "after")
|
|
143
|
+
return h(t.lastPoint, n.lastPoint);
|
|
144
|
+
if (s === "before" && i === "after")
|
|
145
|
+
return h(t.firstPoint, n.lastPoint);
|
|
146
|
+
if (s === "after" && i === "before")
|
|
147
|
+
return h(t.lastPoint, n.firstPoint);
|
|
148
148
|
throw new Error("Invalid position");
|
|
149
149
|
}
|
|
150
|
-
function
|
|
151
|
-
if (
|
|
150
|
+
function q(t, n) {
|
|
151
|
+
if (dt(t, n).length > 0)
|
|
152
152
|
return 0;
|
|
153
|
-
const e =
|
|
153
|
+
const e = ht(t, n.center);
|
|
154
154
|
if (t.isOnSegment(e)) {
|
|
155
|
-
const r =
|
|
155
|
+
const r = h(e, n.center);
|
|
156
156
|
if (Math.abs(r - n.radius) < t.precision && n.isOnSegment(e))
|
|
157
157
|
return 0;
|
|
158
158
|
if (r - n.radius > t.precision) {
|
|
159
|
-
const o =
|
|
160
|
-
|
|
161
|
-
), s =
|
|
159
|
+
const o = B(
|
|
160
|
+
v(e, n.center)
|
|
161
|
+
), s = St(
|
|
162
162
|
n.center,
|
|
163
|
-
|
|
163
|
+
At(o, n.radius)
|
|
164
164
|
);
|
|
165
165
|
if (n.isOnSegment(s))
|
|
166
|
-
return
|
|
166
|
+
return h(s, e);
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
return Math.min(
|
|
@@ -173,279 +173,345 @@ function z(t, n) {
|
|
|
173
173
|
t.distanceFrom(n.lastPoint)
|
|
174
174
|
);
|
|
175
175
|
}
|
|
176
|
-
const
|
|
176
|
+
const It = (t, n) => {
|
|
177
177
|
const e = t.angleToParam(n.firstAngle);
|
|
178
178
|
if (t.isValidParameter(e))
|
|
179
179
|
return !0;
|
|
180
180
|
const r = t.angleToParam(n.lastAngle);
|
|
181
181
|
return !!t.isValidParameter(r);
|
|
182
182
|
};
|
|
183
|
-
function
|
|
184
|
-
if (
|
|
183
|
+
function bt(t, n) {
|
|
184
|
+
if (Mt(t, n, !0).length > 0)
|
|
185
185
|
return 0;
|
|
186
|
-
const e =
|
|
187
|
-
if (e < t.precision &&
|
|
186
|
+
const e = h(t.center, n.center);
|
|
187
|
+
if (e < t.precision && It(t, n))
|
|
188
188
|
return Math.abs(t.radius - n.radius);
|
|
189
|
-
const r =
|
|
190
|
-
let s =
|
|
189
|
+
const r = B(v(n.center, t.center)), o = e - Math.abs(t.radius - n.radius) < t.precision;
|
|
190
|
+
let s = $t(r);
|
|
191
191
|
o && n.radius > t.radius && (s += Math.PI);
|
|
192
|
-
const
|
|
193
|
-
return t.isValidParameter(
|
|
192
|
+
const i = o ? s : s + Math.PI, a = t.angleToParam(s), u = n.angleToParam(i);
|
|
193
|
+
return t.isValidParameter(a) && n.isValidParameter(u) ? h(t.paramPoint(a), n.paramPoint(u)) : Math.min(
|
|
194
194
|
t.distanceFrom(n.firstPoint),
|
|
195
195
|
t.distanceFrom(n.lastPoint),
|
|
196
196
|
n.distanceFrom(t.firstPoint),
|
|
197
197
|
n.distanceFrom(t.lastPoint)
|
|
198
198
|
);
|
|
199
199
|
}
|
|
200
|
-
function
|
|
201
|
-
if (t instanceof d && n instanceof d)
|
|
202
|
-
return At(t, n);
|
|
203
|
-
if (t instanceof d && n instanceof w)
|
|
204
|
-
return z(t, n);
|
|
205
|
-
if (t instanceof w && n instanceof d)
|
|
206
|
-
return z(n, t);
|
|
200
|
+
function kt(t, n) {
|
|
207
201
|
if (t instanceof w && n instanceof w)
|
|
208
|
-
return
|
|
202
|
+
return yt(t, n);
|
|
203
|
+
if (t instanceof w && n instanceof S)
|
|
204
|
+
return q(t, n);
|
|
205
|
+
if (t instanceof S && n instanceof w)
|
|
206
|
+
return q(n, t);
|
|
207
|
+
if (t instanceof S && n instanceof S)
|
|
208
|
+
return bt(t, n);
|
|
209
209
|
throw new Error("Not implemented");
|
|
210
210
|
}
|
|
211
|
-
const
|
|
212
|
-
function
|
|
213
|
-
const
|
|
214
|
-
offset:
|
|
215
|
-
original:
|
|
216
|
-
})),
|
|
217
|
-
let
|
|
218
|
-
if (
|
|
219
|
-
return
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
new d(i.offset.firstPoint, i.offset.lastPoint)
|
|
225
|
-
) : r.push(i.offset) : o = i;
|
|
211
|
+
const V = 1e-8;
|
|
212
|
+
function k(t, n, e = !0) {
|
|
213
|
+
const r = t.map((f) => ({
|
|
214
|
+
offset: ct(f, n),
|
|
215
|
+
original: f
|
|
216
|
+
})), o = [];
|
|
217
|
+
let s = e ? null : r.at(-1), i = e ? r.at(-1) : null;
|
|
218
|
+
if (o.length === 1)
|
|
219
|
+
return o;
|
|
220
|
+
const a = (f) => {
|
|
221
|
+
s ? f.offset instanceof b ? A(f.offset.firstPoint, f.offset.lastPoint) || o.push(
|
|
222
|
+
new w(f.offset.firstPoint, f.offset.lastPoint)
|
|
223
|
+
) : o.push(f.offset) : s = f;
|
|
226
224
|
}, u = function* () {
|
|
227
|
-
for (const
|
|
228
|
-
yield
|
|
229
|
-
if (!
|
|
225
|
+
for (const f of r.slice(0, -1))
|
|
226
|
+
yield f;
|
|
227
|
+
if (!s)
|
|
230
228
|
throw new Error("Bug in the offset algorithm");
|
|
231
|
-
yield
|
|
229
|
+
yield s;
|
|
232
230
|
};
|
|
233
|
-
for (const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
a(s), s = i;
|
|
231
|
+
for (const f of u()) {
|
|
232
|
+
if (!i) {
|
|
233
|
+
i = f;
|
|
237
234
|
continue;
|
|
238
235
|
}
|
|
239
|
-
|
|
240
|
-
if (
|
|
241
|
-
|
|
242
|
-
|
|
236
|
+
const l = i.offset.lastPoint, m = f.offset.firstPoint;
|
|
237
|
+
if (A(l, m)) {
|
|
238
|
+
a(i), i = f;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
let P = [];
|
|
242
|
+
if (!(i.offset instanceof b) && !(f.offset instanceof b)) {
|
|
243
|
+
const { intersections: $, overlaps: I } = O(
|
|
243
244
|
i.offset,
|
|
244
|
-
|
|
245
|
+
f.offset,
|
|
246
|
+
V / 100
|
|
245
247
|
);
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
...
|
|
248
|
+
P = [
|
|
249
|
+
...$,
|
|
250
|
+
...I.flatMap((L) => [L.firstPoint, L.lastPoint])
|
|
249
251
|
];
|
|
250
252
|
}
|
|
251
|
-
if (
|
|
252
|
-
let
|
|
253
|
-
if (
|
|
254
|
-
const
|
|
255
|
-
(
|
|
253
|
+
if (P.length > 0) {
|
|
254
|
+
let $ = P[0];
|
|
255
|
+
if (P.length > 1) {
|
|
256
|
+
const ft = i == null ? void 0 : i.original.lastPoint, T = P.map(
|
|
257
|
+
(at) => Lt(at, ft)
|
|
256
258
|
);
|
|
257
|
-
|
|
259
|
+
$ = P[T.indexOf(Math.min(...T))];
|
|
258
260
|
}
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
])[0],
|
|
262
|
-
if (!
|
|
261
|
+
const I = i.offset.splitAt([
|
|
262
|
+
$
|
|
263
|
+
])[0], L = f.offset.splitAt([$]).at(-1);
|
|
264
|
+
if (!L)
|
|
263
265
|
throw new Error("Bug in the splitting algo in offset");
|
|
264
266
|
a({
|
|
265
|
-
offset:
|
|
266
|
-
original:
|
|
267
|
-
}),
|
|
267
|
+
offset: I,
|
|
268
|
+
original: i.original
|
|
269
|
+
}), i = { offset: L, original: f.original };
|
|
268
270
|
continue;
|
|
269
271
|
}
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
) > 0,
|
|
274
|
-
a(
|
|
272
|
+
const c = i.original.lastPoint, F = vt(
|
|
273
|
+
v(m, c),
|
|
274
|
+
v(l, c)
|
|
275
|
+
) > 0, it = new S(l, m, c, F);
|
|
276
|
+
a(i), o.push(it), i = f;
|
|
275
277
|
}
|
|
276
|
-
return a(
|
|
278
|
+
return a(i), o;
|
|
277
279
|
}
|
|
278
|
-
function
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const o = /* @__PURE__ */ new Map(), s = (f, c) => {
|
|
283
|
-
const l = o.get(f) || [];
|
|
284
|
-
o.set(f, [...l, ...c]);
|
|
280
|
+
function j(t) {
|
|
281
|
+
const n = /* @__PURE__ */ new Map(), e = (r, o) => {
|
|
282
|
+
const s = n.get(r) || [];
|
|
283
|
+
n.set(r, [...s, ...o]);
|
|
285
284
|
};
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const { intersections:
|
|
289
|
-
...
|
|
290
|
-
...
|
|
291
|
-
].filter((
|
|
292
|
-
const
|
|
293
|
-
return !(
|
|
285
|
+
return t.forEach((r, o) => {
|
|
286
|
+
t.slice(o + 1).forEach((s, i) => {
|
|
287
|
+
const { intersections: a, overlaps: u } = O(r, s, V), f = [
|
|
288
|
+
...a,
|
|
289
|
+
...u.flatMap((l) => [l.firstPoint, l.lastPoint])
|
|
290
|
+
].filter((l) => {
|
|
291
|
+
const m = A(l, r.firstPoint) || A(l, r.lastPoint), P = A(l, s.firstPoint) || A(l, s.lastPoint);
|
|
292
|
+
return !(m && P);
|
|
294
293
|
});
|
|
295
|
-
|
|
294
|
+
f.length && (e(o, f), e(i + o + 1, f));
|
|
296
295
|
});
|
|
297
|
-
}),
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}).filter((f) => !t.segments.some((l) => Ft(l, f) < Math.abs(n) - I));
|
|
307
|
-
if (!u.length)
|
|
308
|
-
return new P();
|
|
309
|
-
const m = gt(u).filter((f) => f.length > 1).filter((f) => L(f[0].firstPoint, f.at(-1).lastPoint)).map((f) => new $(f));
|
|
310
|
-
return m.length ? new P(m.map((f) => new h(f))) : new P();
|
|
296
|
+
}), n;
|
|
297
|
+
}
|
|
298
|
+
function tt(t, n) {
|
|
299
|
+
return n.flatMap((e, r) => {
|
|
300
|
+
if (!t.has(r))
|
|
301
|
+
return e;
|
|
302
|
+
const o = t.get(r);
|
|
303
|
+
return o ? e.splitAt(o) : e;
|
|
304
|
+
});
|
|
311
305
|
}
|
|
312
|
-
function
|
|
306
|
+
function nt(t, n, e) {
|
|
307
|
+
return t.filter((r) => !n.segments.some((s) => kt(s, r) < Math.abs(e) - V));
|
|
308
|
+
}
|
|
309
|
+
function y(t, n) {
|
|
310
|
+
const e = t.clockwise ? n : -n, r = k(t.segments, e);
|
|
311
|
+
if (r.length < 2)
|
|
312
|
+
return new p();
|
|
313
|
+
const o = j(r);
|
|
314
|
+
if (!o.size) {
|
|
315
|
+
const f = new d(r);
|
|
316
|
+
return new p([new g(f)]);
|
|
317
|
+
}
|
|
318
|
+
const s = tt(
|
|
319
|
+
o,
|
|
320
|
+
r
|
|
321
|
+
), i = nt(s, t, n);
|
|
322
|
+
if (!i.length)
|
|
323
|
+
return new p();
|
|
324
|
+
const u = H(i).filter((f) => f.length > 1).filter((f) => A(f[0].firstPoint, f.at(-1).lastPoint)).map((f) => new d(f));
|
|
325
|
+
return u.length ? new p(u.map((f) => new g(f))) : new p();
|
|
326
|
+
}
|
|
327
|
+
function Dt(t, n, e = "round") {
|
|
328
|
+
const r = n / 2, o = k(t.segments, r, !1), s = k(t.segments, -r, !1).map(
|
|
329
|
+
(c) => c.reverse()
|
|
330
|
+
);
|
|
331
|
+
s.reverse();
|
|
332
|
+
const i = (c, F) => e === "round" ? Ft(
|
|
333
|
+
c.lastPoint,
|
|
334
|
+
F.firstPoint,
|
|
335
|
+
c.tangentAtLastPoint
|
|
336
|
+
) : new w(c.lastPoint, F.firstPoint), a = [
|
|
337
|
+
...o,
|
|
338
|
+
i(
|
|
339
|
+
o[o.length - 1],
|
|
340
|
+
s[0]
|
|
341
|
+
),
|
|
342
|
+
...s,
|
|
343
|
+
i(
|
|
344
|
+
s[s.length - 1],
|
|
345
|
+
o[0]
|
|
346
|
+
)
|
|
347
|
+
], u = j(a);
|
|
348
|
+
if (!u.size) {
|
|
349
|
+
const c = new d(a);
|
|
350
|
+
return new p([new g(c)]);
|
|
351
|
+
}
|
|
352
|
+
const f = tt(
|
|
353
|
+
u,
|
|
354
|
+
a
|
|
355
|
+
), l = nt(f, t, r);
|
|
356
|
+
if (!l.length)
|
|
357
|
+
return new p();
|
|
358
|
+
const P = H(l).filter((c) => c.length > 1).filter((c) => A(c[0].firstPoint, c.at(-1).lastPoint)).map((c) => new d(c));
|
|
359
|
+
return P.length ? new p(P.map((c) => new g(c))) : new p();
|
|
360
|
+
}
|
|
361
|
+
function Ot(t, n) {
|
|
313
362
|
const e = t.map((r) => {
|
|
314
|
-
const o =
|
|
315
|
-
r.holes.map((s) =>
|
|
363
|
+
const o = E(
|
|
364
|
+
r.holes.map((s) => y(s, n))
|
|
316
365
|
);
|
|
317
|
-
return
|
|
366
|
+
return _(y(r.contour, n), o);
|
|
318
367
|
});
|
|
319
|
-
return
|
|
368
|
+
return E(e);
|
|
320
369
|
}
|
|
321
|
-
function
|
|
322
|
-
|
|
370
|
+
function Ct(t, n) {
|
|
371
|
+
const e = Math.abs(n / 2), r = t.map(
|
|
372
|
+
(o) => E(
|
|
373
|
+
o.allLoops.map((s) => _(y(s, e), y(s, -e)))
|
|
374
|
+
)
|
|
375
|
+
);
|
|
376
|
+
return E(r);
|
|
323
377
|
}
|
|
324
|
-
function
|
|
325
|
-
|
|
326
|
-
|
|
378
|
+
function Wt(t, n) {
|
|
379
|
+
return Ot(M(t), n);
|
|
380
|
+
}
|
|
381
|
+
function Xt(t, n, { endCap: e = "round" } = {}) {
|
|
382
|
+
return t instanceof K ? Dt(t, n, e) : Ct(M(t), n);
|
|
383
|
+
}
|
|
384
|
+
function x(t) {
|
|
327
385
|
if (t instanceof w)
|
|
386
|
+
return `L ${t.lastPoint.join(" ")}`;
|
|
387
|
+
if (t instanceof S)
|
|
328
388
|
return `A ${t.radius} ${t.radius} 0 ${t.angularLength > Math.PI ? "1" : "0"} ${t.clockwise ? "0" : "1"} ${t.lastPoint.join(" ")}`;
|
|
329
389
|
throw new Error("Unknown segment type");
|
|
330
390
|
}
|
|
331
|
-
function
|
|
332
|
-
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(
|
|
391
|
+
function et(t) {
|
|
392
|
+
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(x).join(" ");
|
|
333
393
|
return `${n} ${e} Z`;
|
|
334
394
|
}
|
|
335
|
-
function
|
|
336
|
-
return `<path d="${t.allLoops.map(
|
|
395
|
+
function rt(t) {
|
|
396
|
+
return `<path d="${t.allLoops.map(et).join(" ")}" />`;
|
|
337
397
|
}
|
|
338
|
-
function
|
|
398
|
+
function Gt(t) {
|
|
339
399
|
return `<g>
|
|
340
|
-
${t.figures.map(
|
|
400
|
+
${t.figures.map(rt).join(`
|
|
341
401
|
`)}
|
|
342
402
|
</g>`;
|
|
343
403
|
}
|
|
344
|
-
function
|
|
345
|
-
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(
|
|
404
|
+
function Vt(t) {
|
|
405
|
+
const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(x).join(" ");
|
|
346
406
|
return `${n} ${e}`;
|
|
347
407
|
}
|
|
348
|
-
function
|
|
408
|
+
function xt(t, n = 1) {
|
|
349
409
|
const e = t.xMin - n, r = t.yMin - n;
|
|
350
410
|
return `${e} ${r} ${t.width + 2 * n} ${t.height + 2 * n}`;
|
|
351
411
|
}
|
|
352
|
-
function
|
|
412
|
+
function J(t, n, e = 1, r) {
|
|
413
|
+
const o = xt(n, e), s = r ? `width="${n.width + 2 * e}${r}" height="${n.height + 2 * e}${r}"` : "";
|
|
353
414
|
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
354
|
-
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${
|
|
415
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${o}" fill="none" stroke="black" stroke-width="0.2%" vector-effect="non-scaling-stroke" ${s}>
|
|
355
416
|
${t}
|
|
356
417
|
</svg>`;
|
|
357
418
|
}
|
|
358
|
-
function
|
|
359
|
-
if (t instanceof
|
|
360
|
-
return
|
|
361
|
-
if (t instanceof
|
|
362
|
-
return
|
|
363
|
-
if (t instanceof
|
|
364
|
-
return `<path d="${
|
|
365
|
-
if (t instanceof
|
|
366
|
-
return `<path d="${
|
|
367
|
-
if (t instanceof
|
|
368
|
-
return `<path d="${`M ${t.firstPoint.join(" ")}`} ${
|
|
419
|
+
function W(t) {
|
|
420
|
+
if (t instanceof p)
|
|
421
|
+
return Gt(t);
|
|
422
|
+
if (t instanceof g)
|
|
423
|
+
return rt(t);
|
|
424
|
+
if (t instanceof d)
|
|
425
|
+
return `<path d="${et(t)}" />`;
|
|
426
|
+
if (t instanceof K)
|
|
427
|
+
return `<path d="${Vt(t)}" />`;
|
|
428
|
+
if (t instanceof S || t instanceof w)
|
|
429
|
+
return `<path d="${`M ${t.firstPoint.join(" ")}`} ${x(
|
|
369
430
|
t
|
|
370
431
|
)}" />`;
|
|
371
432
|
throw new Error("Unknown shape type");
|
|
372
433
|
}
|
|
373
|
-
const
|
|
434
|
+
const X = (t) => "shape" in t ? t.shape : t, Y = (t, n) => {
|
|
374
435
|
if (!("shape" in t))
|
|
375
436
|
return n;
|
|
376
437
|
const { color: e } = t;
|
|
377
438
|
return e ? `<g stroke="${e}">${n}</g>` : n;
|
|
378
439
|
};
|
|
379
|
-
function
|
|
440
|
+
function Yt(t, {
|
|
441
|
+
margin: n = 1,
|
|
442
|
+
unit: e = null
|
|
443
|
+
} = {}) {
|
|
380
444
|
if (Array.isArray(t)) {
|
|
381
|
-
const
|
|
382
|
-
`),
|
|
383
|
-
return
|
|
445
|
+
const o = t.map((a) => X(a).mirror()), s = o.map((a, u) => Y(t[u], W(a))).join(`
|
|
446
|
+
`), i = o.slice(1).reduce((a, u) => a.merge(u.boundingBox), o[0].boundingBox);
|
|
447
|
+
return J(s, i, n, e);
|
|
384
448
|
}
|
|
385
|
-
const
|
|
386
|
-
return
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
n
|
|
449
|
+
const r = X(t).mirror();
|
|
450
|
+
return J(
|
|
451
|
+
Y(t, W(r)),
|
|
452
|
+
r.boundingBox,
|
|
453
|
+
n,
|
|
454
|
+
e
|
|
390
455
|
);
|
|
391
456
|
}
|
|
392
|
-
const
|
|
457
|
+
const st = (t) => {
|
|
393
458
|
if (t.type === "LINE")
|
|
394
|
-
return new
|
|
459
|
+
return new w(t.firstPoint, t.lastPoint);
|
|
395
460
|
if (t.type === "ARC")
|
|
396
|
-
return new
|
|
461
|
+
return new S(
|
|
397
462
|
t.firstPoint,
|
|
398
463
|
t.lastPoint,
|
|
399
464
|
t.center,
|
|
400
465
|
t.clockwise
|
|
401
466
|
);
|
|
402
467
|
throw new Error("Unknown segment type");
|
|
403
|
-
},
|
|
404
|
-
const n = t.segments.map(
|
|
405
|
-
return new
|
|
406
|
-
},
|
|
407
|
-
const n =
|
|
408
|
-
return new
|
|
409
|
-
},
|
|
410
|
-
const n = t.figures.map(
|
|
411
|
-
return new
|
|
468
|
+
}, D = (t) => {
|
|
469
|
+
const n = t.segments.map(st);
|
|
470
|
+
return new d(n);
|
|
471
|
+
}, ot = (t) => {
|
|
472
|
+
const n = D(t.contour), e = t.holes.map(D);
|
|
473
|
+
return new g(n, e);
|
|
474
|
+
}, Tt = (t) => {
|
|
475
|
+
const n = t.figures.map(ot);
|
|
476
|
+
return new p(n);
|
|
412
477
|
};
|
|
413
|
-
function
|
|
478
|
+
function Zt(t) {
|
|
414
479
|
if (t.type === "DIAGRAM")
|
|
415
|
-
return
|
|
480
|
+
return Tt(t);
|
|
416
481
|
if (t.type === "FIGURE")
|
|
417
|
-
return
|
|
482
|
+
return ot(t);
|
|
418
483
|
if (t.type === "LOOP")
|
|
419
|
-
return
|
|
484
|
+
return D(t);
|
|
420
485
|
if (t.type === "LINE" || t.type === "ARC")
|
|
421
|
-
return
|
|
486
|
+
return st(t);
|
|
422
487
|
throw new Error("Unknown shape type");
|
|
423
488
|
}
|
|
424
|
-
const
|
|
425
|
-
function
|
|
426
|
-
const e = Math.cos(n *
|
|
489
|
+
const Z = Math.PI / 180, Rt = 180 / Math.PI;
|
|
490
|
+
function Bt(t, n) {
|
|
491
|
+
const e = Math.cos(n * Z) * t, r = Math.sin(n * Z) * t;
|
|
427
492
|
return [e, r];
|
|
428
493
|
}
|
|
429
|
-
function
|
|
430
|
-
const e = Math.sqrt(t * t + n * n), r = Math.atan2(n, t) *
|
|
494
|
+
function Ht([t, n]) {
|
|
495
|
+
const e = Math.sqrt(t * t + n * n), r = Math.atan2(n, t) * Rt;
|
|
431
496
|
return [e, r];
|
|
432
497
|
}
|
|
433
498
|
export {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
499
|
+
Z as DEG2RAD,
|
|
500
|
+
Rt as RAD2DEG,
|
|
501
|
+
Ht as cartesianToPolar,
|
|
502
|
+
Jt as confineStrand,
|
|
503
|
+
_ as cut,
|
|
504
|
+
_t as draw,
|
|
505
|
+
qt as eraseStrand,
|
|
506
|
+
tn as exportJSON,
|
|
507
|
+
Yt as exportSVG,
|
|
508
|
+
Et as fuse,
|
|
509
|
+
E as fuseAll,
|
|
510
|
+
Zt as importJSON,
|
|
511
|
+
Nt as intersect,
|
|
512
|
+
Wt as offset,
|
|
513
|
+
Xt as outlineStroke,
|
|
514
|
+
Bt as polarToCartesian,
|
|
515
|
+
W as svgBody
|
|
450
516
|
};
|
|
451
517
|
//# sourceMappingURL=pantograph.js.map
|