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.
@@ -1,119 +1,119 @@
1
- import { o as nt, D } from "./draw-44dd36a9.js";
2
- import { d as Jt } from "./draw-44dd36a9.js";
3
- import { F as h, L as $, D as P, f as C, r as et, z as st, s as rt, a as ot, c as it, i as ft, l as at, d as g, b as ct, p as ut, n as Z, e as E, g as lt, h as pt, j as Pt, k as mt, m as d, A as w, o as L, q as gt, t as dt, u as wt, S as ht } from "./Diagram-1c56996e.js";
4
- import { v as Xt } from "./Diagram-1c56996e.js";
5
- function F(t) {
6
- if (t instanceof h)
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 h(t)];
10
- if (t instanceof P)
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 H(t, n, e = 1e-9) {
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((u, i) => {
18
- t.segments.forEach((m) => {
19
- const { intersections: f, overlaps: c } = C(
20
- u,
21
- m,
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(...f), s[i].push(...f), o.push(...c);
25
- const l = c.flatMap((S) => [
26
- S.firstPoint,
27
- S.lastPoint
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(...l), s[i].push(...l);
29
+ r.push(...P), s[u].push(...P);
30
30
  });
31
- }), r = et(r, e);
32
- const a = st([n.segments, s]).flatMap(([u, i]) => i.length ? u.splitAt(i) : [u]);
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
- rt(
35
- a,
34
+ pt(
35
+ i,
36
36
  r,
37
37
  o
38
38
  )
39
39
  );
40
40
  }
41
- function O(t, n, e = !1) {
42
- return H(n, t).filter((o) => {
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 x(t, n, e = !1) {
48
- return H(n, t).filter((o) => {
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 V(t, n, e = !1) {
54
- const r = O(
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) => x(t, s, e)
59
+ (s) => G(t, s, e)
60
60
  );
61
61
  return [...r, ...o];
62
62
  }
63
- function T(t, n, e = !1) {
64
- let r = x(
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) => O(s, o, e)
71
+ (s) => C(s, o, e)
72
72
  );
73
73
  }), r;
74
74
  }
75
- function St(t, n) {
76
- return new P(
77
- ot(F(t), F(n))
75
+ function Et(t, n) {
76
+ return new p(
77
+ Pt(M(t), M(n))
78
78
  );
79
79
  }
80
- function R(t) {
80
+ function E(t) {
81
81
  return t.reduce(
82
- (n, e) => St(n, e),
83
- new P()
82
+ (n, e) => Et(n, e),
83
+ new p()
84
84
  );
85
85
  }
86
- function Mt(t, n) {
87
- return new P(
88
- it(F(t), F(n))
86
+ function _(t, n) {
87
+ return new p(
88
+ gt(M(t), M(n))
89
89
  );
90
90
  }
91
- function xt(t, n) {
92
- return new P(
93
- ft(F(t), F(n))
91
+ function Nt(t, n) {
92
+ return new p(
93
+ mt(M(t), M(n))
94
94
  );
95
95
  }
96
- function Gt(t, n, e = !0) {
97
- if (n instanceof $)
98
- return O(t, n, e);
99
- if (n instanceof h)
100
- return V(t, n, e);
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) => V(s, o, e));
103
+ r = r.flatMap((s) => R(s, o, e));
104
104
  }), r;
105
105
  }
106
- function Vt(t, n, e = !1) {
107
- if (n instanceof $)
108
- return x(t, n, e);
109
- if (n instanceof h)
110
- return T(t, n, e);
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) => T(s, o, e));
113
+ r = r.flatMap((s) => U(s, o, e));
114
114
  }), r;
115
115
  }
116
- function U(t) {
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 At(t, n) {
127
- const e = at(t, n);
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 = U(r), a = U(o);
134
- if (s === "between" && a === "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" && a !== "between")
137
- return N(t, n, a);
138
- if (a === "between" && s !== "between")
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" && a === "before")
141
- return g(t.firstPoint, n.firstPoint);
142
- if (s === "after" && a === "after")
143
- return g(t.lastPoint, n.lastPoint);
144
- if (s === "before" && a === "after")
145
- return g(t.firstPoint, n.lastPoint);
146
- if (s === "after" && a === "before")
147
- return g(t.lastPoint, n.firstPoint);
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 z(t, n) {
151
- if (ct(t, n).length > 0)
150
+ function q(t, n) {
151
+ if (dt(t, n).length > 0)
152
152
  return 0;
153
- const e = ut(t, n.center);
153
+ const e = ht(t, n.center);
154
154
  if (t.isOnSegment(e)) {
155
- const r = g(e, n.center);
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 = Z(
160
- E(e, n.center)
161
- ), s = lt(
159
+ const o = B(
160
+ v(e, n.center)
161
+ ), s = St(
162
162
  n.center,
163
- pt(o, n.radius)
163
+ At(o, n.radius)
164
164
  );
165
165
  if (n.isOnSegment(s))
166
- return g(s, e);
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 Lt = (t, n) => {
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 $t(t, n) {
184
- if (Pt(t, n, !0).length > 0)
183
+ function bt(t, n) {
184
+ if (Mt(t, n, !0).length > 0)
185
185
  return 0;
186
- const e = g(t.center, n.center);
187
- if (e < t.precision && Lt(t, n))
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 = Z(E(n.center, t.center)), o = e - Math.abs(t.radius - n.radius) < t.precision;
190
- let s = mt(r);
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 a = o ? s : s + Math.PI, u = t.angleToParam(s), i = n.angleToParam(a);
193
- return t.isValidParameter(u) && n.isValidParameter(i) ? g(t.paramPoint(u), n.paramPoint(i)) : Math.min(
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 Ft(t, n) {
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 $t(t, n);
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 I = 1e-8;
212
- function vt(t, n) {
213
- const e = t.map((i) => ({
214
- offset: nt(i, n),
215
- original: i
216
- })), r = [];
217
- let o = null, s = e.at(-1);
218
- if (!s)
219
- return [];
220
- if (r.length === 1)
221
- return r;
222
- const a = (i) => {
223
- o ? i.offset instanceof D ? L(i.offset.firstPoint, i.offset.lastPoint) || r.push(
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 i of e.slice(0, -1))
228
- yield i;
229
- if (!o)
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 o;
229
+ yield s;
232
230
  };
233
- for (const i of u()) {
234
- const m = s.offset.lastPoint, f = i.offset.firstPoint;
235
- if (L(m, f)) {
236
- a(s), s = i;
231
+ for (const f of u()) {
232
+ if (!i) {
233
+ i = f;
237
234
  continue;
238
235
  }
239
- let c = [];
240
- if (!(s.offset instanceof D) && !(i.offset instanceof D)) {
241
- const { intersections: M, overlaps: A } = C(
242
- s.offset,
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
- I / 100
245
+ f.offset,
246
+ V / 100
245
247
  );
246
- c = [
247
- ...M,
248
- ...A.flatMap((p) => [p.firstPoint, p.lastPoint])
248
+ P = [
249
+ ...$,
250
+ ...I.flatMap((L) => [L.firstPoint, L.lastPoint])
249
251
  ];
250
252
  }
251
- if (c.length > 0) {
252
- let M = c[0];
253
- if (c.length > 1) {
254
- const b = s == null ? void 0 : s.original.lastPoint, v = c.map(
255
- (tt) => dt(tt, b)
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
- M = c[v.indexOf(Math.min(...v))];
259
+ $ = P[T.indexOf(Math.min(...T))];
258
260
  }
259
- const A = s.offset.splitAt([
260
- M
261
- ])[0], p = i.offset.splitAt([M]).at(-1);
262
- if (!p)
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: A,
266
- original: s.original
267
- }), s = { offset: p, original: i.original };
267
+ offset: I,
268
+ original: i.original
269
+ }), i = { offset: L, original: f.original };
268
270
  continue;
269
271
  }
270
- const l = s.original.lastPoint, S = wt(
271
- E(f, l),
272
- E(m, l)
273
- ) > 0, y = new w(m, f, l, S);
274
- a(s), r.push(y), s = i;
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(s), r;
278
+ return a(i), o;
277
279
  }
278
- function q(t, n) {
279
- const e = t.clockwise ? n : -n, r = vt(t.segments, e);
280
- if (r.length < 2)
281
- return new P();
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
- if (r.forEach((f, c) => {
287
- r.slice(c + 1).forEach((l, S) => {
288
- const { intersections: y, overlaps: M } = C(f, l, I), A = [
289
- ...y,
290
- ...M.flatMap((p) => [p.firstPoint, p.lastPoint])
291
- ].filter((p) => {
292
- const b = L(p, f.firstPoint) || L(p, f.lastPoint), v = L(p, l.firstPoint) || L(p, l.lastPoint);
293
- return !(b && v);
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
- A.length && (s(c, A), s(S + c + 1, A));
294
+ f.length && (e(o, f), e(i + o + 1, f));
296
295
  });
297
- }), !o.size) {
298
- const f = new $(r);
299
- return new P([new h(f)]);
300
- }
301
- const u = r.flatMap((f, c) => {
302
- if (!o.has(c))
303
- return f;
304
- const l = o.get(c) || [];
305
- return f.splitAt(l);
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 Et(t, n) {
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 = R(
315
- r.holes.map((s) => q(s, n))
363
+ const o = E(
364
+ r.holes.map((s) => y(s, n))
316
365
  );
317
- return Mt(q(r.contour, n), o);
366
+ return _(y(r.contour, n), o);
318
367
  });
319
- return R(e);
368
+ return E(e);
320
369
  }
321
- function Tt(t, n) {
322
- return Et(F(t), n);
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 G(t) {
325
- if (t instanceof d)
326
- return `L ${t.lastPoint.join(" ")}`;
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 K(t) {
332
- const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(G).join(" ");
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 Q(t) {
336
- return `<path d="${t.allLoops.map(K).join(" ")}" />`;
395
+ function rt(t) {
396
+ return `<path d="${t.allLoops.map(et).join(" ")}" />`;
337
397
  }
338
- function yt(t) {
398
+ function Gt(t) {
339
399
  return `<g>
340
- ${t.figures.map(Q).join(`
400
+ ${t.figures.map(rt).join(`
341
401
  `)}
342
402
  </g>`;
343
403
  }
344
- function bt(t) {
345
- const n = `M ${t.firstPoint.join(" ")}`, e = t.segments.map(G).join(" ");
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 Dt(t, n = 1) {
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 B(t, n, e = 1) {
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="${Dt(n, e)}" fill="none" stroke="black" stroke-width="0.2%" vector-effect="non-scaling-stroke">
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 J(t) {
359
- if (t instanceof P)
360
- return yt(t);
361
- if (t instanceof h)
362
- return Q(t);
363
- if (t instanceof $)
364
- return `<path d="${K(t)}" />`;
365
- if (t instanceof ht)
366
- return `<path d="${bt(t)}" />`;
367
- if (t instanceof w || t instanceof d)
368
- return `<path d="${`M ${t.firstPoint.join(" ")}`} ${G(
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 W = (t) => "shape" in t ? t.shape : t, X = (t, n) => {
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 Rt(t, n = 1) {
440
+ function Yt(t, {
441
+ margin: n = 1,
442
+ unit: e = null
443
+ } = {}) {
380
444
  if (Array.isArray(t)) {
381
- const r = t.map((a) => W(a).mirror()), o = r.map((a, u) => X(t[u], J(a))).join(`
382
- `), s = r.slice(1).reduce((a, u) => a.merge(u.boundingBox), r[0].boundingBox);
383
- return B(o, s);
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 e = W(t).mirror();
386
- return B(
387
- X(t, J(e)),
388
- e.boundingBox,
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 _ = (t) => {
457
+ const st = (t) => {
393
458
  if (t.type === "LINE")
394
- return new d(t.firstPoint, t.lastPoint);
459
+ return new w(t.firstPoint, t.lastPoint);
395
460
  if (t.type === "ARC")
396
- return new w(
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
- }, k = (t) => {
404
- const n = t.segments.map(_);
405
- return new $(n);
406
- }, j = (t) => {
407
- const n = k(t.contour), e = t.holes.map(k);
408
- return new h(n, e);
409
- }, It = (t) => {
410
- const n = t.figures.map(j);
411
- return new P(n);
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 Ut(t) {
478
+ function Zt(t) {
414
479
  if (t.type === "DIAGRAM")
415
- return It(t);
480
+ return Tt(t);
416
481
  if (t.type === "FIGURE")
417
- return j(t);
482
+ return ot(t);
418
483
  if (t.type === "LOOP")
419
- return k(t);
484
+ return D(t);
420
485
  if (t.type === "LINE" || t.type === "ARC")
421
- return _(t);
486
+ return st(t);
422
487
  throw new Error("Unknown shape type");
423
488
  }
424
- const Y = Math.PI / 180, kt = 180 / Math.PI;
425
- function Nt(t, n) {
426
- const e = Math.cos(n * Y) * t, r = Math.sin(n * Y) * t;
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 zt([t, n]) {
430
- const e = Math.sqrt(t * t + n * n), r = Math.atan2(n, t) * kt;
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
- Y as DEG2RAD,
435
- kt as RAD2DEG,
436
- zt as cartesianToPolar,
437
- Vt as confineStrand,
438
- Mt as cut,
439
- Jt as draw,
440
- Gt as eraseStrand,
441
- Xt as exportJSON,
442
- Rt as exportSVG,
443
- St as fuse,
444
- R as fuseAll,
445
- Ut as importJSON,
446
- xt as intersect,
447
- Tt as offset,
448
- Nt as polarToCartesian,
449
- J as svgBody
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