pantograph2d 0.7.0 → 0.8.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.
Files changed (126) hide show
  1. package/dist/Diagram-2450b2e6.js +1750 -0
  2. package/dist/Diagram-2450b2e6.js.map +1 -0
  3. package/dist/Diagram-57e17509.cjs +4 -0
  4. package/dist/Diagram-57e17509.cjs.map +1 -0
  5. package/dist/QuadraticBezier-e116a2d6.js +3647 -0
  6. package/dist/QuadraticBezier-e116a2d6.js.map +1 -0
  7. package/dist/QuadraticBezier-e3d7218b.cjs +9 -0
  8. package/dist/QuadraticBezier-e3d7218b.cjs.map +1 -0
  9. package/dist/api/svg.d.ts +1 -0
  10. package/dist/draw-27ac6dae.cjs +2 -0
  11. package/dist/draw-27ac6dae.cjs.map +1 -0
  12. package/dist/{draw-825692f1.js → draw-c7b2705c.js} +117 -109
  13. package/dist/draw-c7b2705c.js.map +1 -0
  14. package/dist/export/svg/api.d.ts +6 -0
  15. package/dist/{types/export → export}/svg/wrapSVG.d.ts +1 -1
  16. package/dist/{types/models → models}/exports.d.ts +2 -0
  17. package/dist/pantograph/drawShape.cjs +1 -1
  18. package/dist/pantograph/drawShape.cjs.map +1 -1
  19. package/dist/pantograph/drawShape.js +12 -11
  20. package/dist/pantograph/drawShape.js.map +1 -1
  21. package/dist/pantograph/models.cjs +1 -1
  22. package/dist/pantograph/models.js +15 -12
  23. package/dist/pantograph/models.js.map +1 -1
  24. package/dist/pantograph/svg.cjs +2 -0
  25. package/dist/pantograph/svg.cjs.map +1 -0
  26. package/dist/pantograph/svg.js +11 -0
  27. package/dist/pantograph/svg.js.map +1 -0
  28. package/dist/pantograph.cjs +2 -8
  29. package/dist/pantograph.cjs.map +1 -1
  30. package/dist/pantograph.js +405 -440
  31. package/dist/pantograph.js.map +1 -1
  32. package/dist/wrapSVG-02b823ac.cjs +8 -0
  33. package/dist/wrapSVG-02b823ac.cjs.map +1 -0
  34. package/dist/wrapSVG-0ec8a111.js +62 -0
  35. package/dist/wrapSVG-0ec8a111.js.map +1 -0
  36. package/package.json +31 -23
  37. package/dist/Diagram-8c3c5e1b.js +0 -5301
  38. package/dist/Diagram-8c3c5e1b.js.map +0 -1
  39. package/dist/Diagram-d8288579.cjs +0 -11
  40. package/dist/Diagram-d8288579.cjs.map +0 -1
  41. package/dist/draw-3ee546c3.cjs +0 -2
  42. package/dist/draw-3ee546c3.cjs.map +0 -1
  43. package/dist/draw-825692f1.js.map +0 -1
  44. /package/dist/{types/algorithms → algorithms}/boolean/figureBooleans.d.ts +0 -0
  45. /package/dist/{types/algorithms → algorithms}/boolean/loopBooleans.d.ts +0 -0
  46. /package/dist/{types/algorithms → algorithms}/boolean/strandBoolean.d.ts +0 -0
  47. /package/dist/{types/algorithms → algorithms}/boolean/strandsBetweenIntersections.d.ts +0 -0
  48. /package/dist/{types/algorithms → algorithms}/distances/arcArcDistance.d.ts +0 -0
  49. /package/dist/{types/algorithms → algorithms}/distances/genericDistance.d.ts +0 -0
  50. /package/dist/{types/algorithms → algorithms}/distances/index.d.ts +0 -0
  51. /package/dist/{types/algorithms → algorithms}/distances/lineArcDistance.d.ts +0 -0
  52. /package/dist/{types/algorithms → algorithms}/distances/lineLineDistance.d.ts +0 -0
  53. /package/dist/{types/algorithms → algorithms}/filletSegments.d.ts +0 -0
  54. /package/dist/{types/algorithms → algorithms}/intersections/arcArcIntersection.d.ts +0 -0
  55. /package/dist/{types/algorithms → algorithms}/intersections/arcEllipseArcIntersection.d.ts +0 -0
  56. /package/dist/{types/algorithms → algorithms}/intersections/arcsCubicBezierIntersection.d.ts +0 -0
  57. /package/dist/{types/algorithms → algorithms}/intersections/arcsQuadraticBezierIntersection.d.ts +0 -0
  58. /package/dist/{types/algorithms → algorithms}/intersections/bezierClip.d.ts +0 -0
  59. /package/dist/{types/algorithms → algorithms}/intersections/cubicBezierCubicBezierIntersection.d.ts +0 -0
  60. /package/dist/{types/algorithms → algorithms}/intersections/ellipseArcEllipseArcIntersection.d.ts +0 -0
  61. /package/dist/{types/algorithms → algorithms}/intersections/ellipseEllipseIntersection.d.ts +0 -0
  62. /package/dist/{types/algorithms → algorithms}/intersections/index.d.ts +0 -0
  63. /package/dist/{types/algorithms → algorithms}/intersections/lineArcIntersection.d.ts +0 -0
  64. /package/dist/{types/algorithms → algorithms}/intersections/lineBezierIntersection.d.ts +0 -0
  65. /package/dist/{types/algorithms → algorithms}/intersections/lineEllipseArcIntersection.d.ts +0 -0
  66. /package/dist/{types/algorithms → algorithms}/intersections/lineLineIntersection.d.ts +0 -0
  67. /package/dist/{types/algorithms → algorithms}/intersections/quadraticBezierQuadraticBezierIntersection.d.ts +0 -0
  68. /package/dist/{types/algorithms → algorithms}/intersections/rayIntersections.d.ts +0 -0
  69. /package/dist/{types/algorithms → algorithms}/offsets/offsetFigure.d.ts +0 -0
  70. /package/dist/{types/algorithms → algorithms}/offsets/offsetSegment.d.ts +0 -0
  71. /package/dist/{types/algorithms → algorithms}/offsets/offsetStroke.d.ts +0 -0
  72. /package/dist/{types/algorithms → algorithms}/optimisation/Brent.d.ts +0 -0
  73. /package/dist/{types/algorithms → algorithms}/optimisation/DiRect.d.ts +0 -0
  74. /package/dist/{types/algorithms → algorithms}/organiseLoops.d.ts +0 -0
  75. /package/dist/{types/algorithms → algorithms}/simplify.d.ts +0 -0
  76. /package/dist/{types/algorithms → algorithms}/solvers/solvePolynomials.d.ts +0 -0
  77. /package/dist/{types/algorithms → algorithms}/stitchSegments.d.ts +0 -0
  78. /package/dist/{types/api → api}/drawShape.d.ts +0 -0
  79. /package/dist/{types/api → api}/models.d.ts +0 -0
  80. /package/dist/{types/booleanOperations.d.ts → booleanOperations.d.ts} +0 -0
  81. /package/dist/{types/definitions.d.ts → definitions.d.ts} +0 -0
  82. /package/dist/{types/draw.d.ts → draw.d.ts} +0 -0
  83. /package/dist/{types/drawShape → drawShape}/drawCircle.d.ts +0 -0
  84. /package/dist/{types/drawShape → drawShape}/drawRect.d.ts +0 -0
  85. /package/dist/{types/export → export}/json/exportJSON.d.ts +0 -0
  86. /package/dist/{types/export → export}/json/jsonDiagram.d.ts +0 -0
  87. /package/dist/{types/export → export}/json/jsonFigure.d.ts +0 -0
  88. /package/dist/{types/export → export}/json/jsonLoop.d.ts +0 -0
  89. /package/dist/{types/export → export}/json/jsonSegment.d.ts +0 -0
  90. /package/dist/{types/export → export}/svg/exportSVG.d.ts +0 -0
  91. /package/dist/{types/export → export}/svg/svgDiagram.d.ts +0 -0
  92. /package/dist/{types/export → export}/svg/svgFigure.d.ts +0 -0
  93. /package/dist/{types/export → export}/svg/svgLoop.d.ts +0 -0
  94. /package/dist/{types/export → export}/svg/svgSegment.d.ts +0 -0
  95. /package/dist/{types/export → export}/svg/svgStrand.d.ts +0 -0
  96. /package/dist/{types/import → import}/json/importJSON.d.ts +0 -0
  97. /package/dist/{types/main.d.ts → main.d.ts} +0 -0
  98. /package/dist/{types/models → models}/BoundingBox.d.ts +0 -0
  99. /package/dist/{types/models → models}/Diagram.d.ts +0 -0
  100. /package/dist/{types/models → models}/Figure.d.ts +0 -0
  101. /package/dist/{types/models → models}/Loop.d.ts +0 -0
  102. /package/dist/{types/models → models}/Strand.d.ts +0 -0
  103. /package/dist/{types/models → models}/Stroke.d.ts +0 -0
  104. /package/dist/{types/models → models}/TransformationMatrix.d.ts +0 -0
  105. /package/dist/{types/models → models}/segments/Arc.d.ts +0 -0
  106. /package/dist/{types/models → models}/segments/CubicBezier.d.ts +0 -0
  107. /package/dist/{types/models → models}/segments/EllipseArc.d.ts +0 -0
  108. /package/dist/{types/models → models}/segments/Line.d.ts +0 -0
  109. /package/dist/{types/models → models}/segments/QuadraticBezier.d.ts +0 -0
  110. /package/dist/{types/models → models}/segments/Segment.d.ts +0 -0
  111. /package/dist/{types/models → models}/segments/utils/deCasteljau.d.ts +0 -0
  112. /package/dist/{types/models → models}/segments/utils/isSegment.d.ts +0 -0
  113. /package/dist/{types/models → models}/utils/Transformable.d.ts +0 -0
  114. /package/dist/{types/offsetOperations.d.ts → offsetOperations.d.ts} +0 -0
  115. /package/dist/{types/operations.d.ts → operations.d.ts} +0 -0
  116. /package/dist/{types/utils → utils}/allCombinations.d.ts +0 -0
  117. /package/dist/{types/utils → utils}/allPairs.d.ts +0 -0
  118. /package/dist/{types/utils → utils}/angularDistance.d.ts +0 -0
  119. /package/dist/{types/utils → utils}/listOfFigures.d.ts +0 -0
  120. /package/dist/{types/utils → utils}/projectPointOnLine.d.ts +0 -0
  121. /package/dist/{types/utils → utils}/range.d.ts +0 -0
  122. /package/dist/{types/utils → utils}/removeDuplicatePoints.d.ts +0 -0
  123. /package/dist/{types/utils → utils}/removeDuplicateValues.d.ts +0 -0
  124. /package/dist/{types/utils → utils}/unitAngle.d.ts +0 -0
  125. /package/dist/{types/utils → utils}/zip.d.ts +0 -0
  126. /package/dist/{types/vectorOperations.d.ts → vectorOperations.d.ts} +0 -0
@@ -0,0 +1,1750 @@
1
+ var tn = Object.defineProperty;
2
+ var nn = (t, n, e) => n in t ? tn(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e;
3
+ var C = (t, n, e) => (nn(t, typeof n != "symbol" ? n + "" : n, e), e);
4
+ import { s as k, q as en, d as Ot, a as q, b as V, n as sn, h as Tt, r as U, A as S, e as g, u as Lt, E as M, T as on, v as rn, Q as A, w as $, C as I, f as ln, x as cn, L as y, y as zt, g as lt, z as N, F as un, l as an, c as fn, G as dt, B as hn } from "./QuadraticBezier-e116a2d6.js";
5
+ function pn(t, n) {
6
+ const e = k(n, t.firstPoint), s = en(e, t.V) / t.squareLength;
7
+ return t.paramPoint(s);
8
+ }
9
+ function J(t, n, e) {
10
+ const s = e || t.precision, i = pn(t, n.center), o = Ot(i, n.center);
11
+ if (o > n.radius + s)
12
+ return [];
13
+ if (Math.abs(o - n.radius) < s) {
14
+ const c = i;
15
+ return t.isOnSegment(c) && n.isOnSegment(c) ? [c] : [];
16
+ }
17
+ const r = [], l = Math.sqrt(
18
+ n.radius * n.radius - o * o
19
+ ), u = t.tangentAtFirstPoint, a = q(i, V(u, l));
20
+ t.isOnSegment(a) && n.isOnSegment(a) && r.push(a);
21
+ const f = q(i, V(u, -l));
22
+ return t.isOnSegment(f) && n.isOnSegment(f) && r.push(f), r;
23
+ }
24
+ const dn = (t) => {
25
+ const { firstPoint: n, lastPoint: e, center: s, clockwise: i } = t;
26
+ return new S(e, n, s, i, {
27
+ ignoreChecks: !0
28
+ });
29
+ }, mn = (t, n) => {
30
+ if (t.isSame(n))
31
+ return [t];
32
+ const e = U(
33
+ [
34
+ n.isOnSegment(t.firstPoint) ? t.firstPoint : null,
35
+ n.isOnSegment(t.lastPoint) ? t.lastPoint : null,
36
+ t.isOnSegment(n.firstPoint) ? n.firstPoint : null,
37
+ t.isOnSegment(n.lastPoint) ? n.lastPoint : null
38
+ ].filter((s) => s !== null)
39
+ // We sort by the param value of the first arc. This means that the points
40
+ // will be sorted with the same orientation than arc1
41
+ ).sort((s, i) => t.pointToParam(s) - t.pointToParam(i));
42
+ if (e.length === 0)
43
+ return [];
44
+ if (e.length === 1)
45
+ return [];
46
+ if (e.length === 2)
47
+ return t.isSame(dn(n)) ? [] : [new S(e[0], e[1], t.center, t.clockwise)];
48
+ if (e.length === 3) {
49
+ const s = g(e[0], n.lastPoint) || g(e[0], n.firstPoint) ? 1 : 0;
50
+ return [
51
+ new S(
52
+ e[0 + s],
53
+ e[1 + s],
54
+ t.center,
55
+ t.clockwise
56
+ )
57
+ ];
58
+ } else if (e.length === 4)
59
+ return [
60
+ new S(e[0], e[1], t.center, t.clockwise),
61
+ new S(e[2], e[3], t.center, t.clockwise)
62
+ ];
63
+ throw new Error("Bug in the arc arc overlap algorithm");
64
+ };
65
+ function qt(t, n, e = !1, s) {
66
+ const i = s || t.precision, o = Ot(t.center, n.center), r = t.radius + n.radius;
67
+ if (o > r + i)
68
+ return [];
69
+ const l = Math.abs(t.radius - n.radius);
70
+ if (o < l - i)
71
+ return [];
72
+ if (o < i)
73
+ return l > i ? [] : e ? mn(t, n) : [];
74
+ const u = sn(k(n.center, t.center)), a = o > r - i;
75
+ if (
76
+ // circles are outside each other
77
+ a || // circles are inside each other
78
+ Math.abs(o - l) < i
79
+ ) {
80
+ const w = a || t.radius > n.radius ? 1 : -1, x = q(
81
+ t.center,
82
+ V(u, w * t.radius)
83
+ );
84
+ return t.isOnSegment(x) && n.isOnSegment(x) ? [x] : [];
85
+ }
86
+ const f = t.radius * t.radius / (2 * o) - n.radius * n.radius / (2 * o) + o / 2, c = q(
87
+ t.center,
88
+ V(u, f)
89
+ ), h = Math.sqrt(
90
+ t.radius * t.radius - f * f
91
+ ), p = Tt(u), d = q(c, V(p, h)), m = q(c, V(p, -h)), P = [];
92
+ return t.isOnSegment(d) && n.isOnSegment(d) && P.push(d), t.isOnSegment(m) && n.isOnSegment(m) && P.push(m), P;
93
+ }
94
+ function et(t, n, e = 1e-9) {
95
+ const s = t.transform(n.ellipseReferenceFrameTransform), i = s.slope, o = s.yIntercept, r = n.majorRadius * n.majorRadius, l = n.minorRadius * n.minorRadius, u = n.majorRadius * n.minorRadius, a = s.slope * s.slope, f = s.yIntercept * s.yIntercept, c = (w) => w.map(
96
+ (x) => n.reverseEllipseReferenceFrameTransform.transform(x)
97
+ ).filter((x) => t.isOnSegment(x) && n.isOnSegment(x));
98
+ if (!Number.isFinite(i)) {
99
+ const w = s.firstPoint[0];
100
+ if (Math.abs(w) - n.majorRadius > e)
101
+ return [];
102
+ if (Math.abs(Math.abs(w) - n.majorRadius) < e)
103
+ return c([[w, 0]]);
104
+ const x = n.minorRadius * Math.sqrt(1 - w * w / r), E = [w, x], b = [w, -x];
105
+ return c([E, b]);
106
+ }
107
+ const h = r * a + l - f;
108
+ if (h < -e)
109
+ return [];
110
+ const p = r * a + l;
111
+ if (Math.abs(h) < e) {
112
+ const w = -(r * i * o) / p, x = l * o / p;
113
+ return c([[w, x]]);
114
+ }
115
+ const d = Math.sqrt(h), m = [
116
+ -(r * i * o + u * d) / p,
117
+ (l * o - u * i * d) / p
118
+ ], P = [
119
+ -(r * i * o - u * d) / p,
120
+ (l * o + u * i * d) / p
121
+ ];
122
+ return c([m, P]);
123
+ }
124
+ function Dt(t, n) {
125
+ const e = Math.max(t.precision, n.precision), s = t.coefficients, i = s.x2, o = s.xy, r = s.y2, l = s.x, u = s.y, a = s.c, f = n.coefficients, c = f.x2, h = f.xy, p = f.y2, d = f.x, m = f.y, P = f.c, w = {
126
+ z0: a * i * d * d + i * i * P * P - l * i * d * P + c * c * a * a - 2 * i * P * c * a - l * d * c * a + c * l * l * P,
127
+ z1: m * l * l * c - P * d * i * o - 2 * i * P * c * u - a * c * h * l + 2 * d * h * i * a + 2 * m * P * i * i + d * d * i * u - m * d * i * l - 2 * i * m * c * a - a * c * d * o + 2 * a * u * c * c - P * h * i * l - u * c * d * l + 2 * P * o * c * l,
128
+ z2: m * m * i * i + 2 * p * P * i * i - u * c * d * o + P * c * o * o - u * c * h * l - P * h * i * o - 2 * i * m * c * u + 2 * d * h * i * u - p * d * i * l - 2 * i * p * c * a + h * h * i * a + 2 * m * o * c * l + u * u * c * c - r * c * d * l - m * h * i * l + 2 * a * r * c * c - a * c * h * o + p * l * l * c + d * d * i * r - m * d * i * o - 2 * i * P * c * r,
129
+ z3: -2 * i * c * r * m + m * c * o * o + 2 * p * o * c * l - r * c * h * l + h * h * i * u - m * h * i * o - 2 * i * p * c * u - u * c * h * o - p * h * i * l + 2 * m * p * i * i + 2 * u * r * c * c - r * c * d * o + 2 * d * h * i * r - p * d * i * o,
130
+ z4: i * i * p * p - 2 * i * p * c * r + c * c * r * r - o * i * h * p - o * h * c * r + o * o * c * p + r * i * h * h
131
+ }, E = Lt(
132
+ [w.z0, w.z1, w.z2, w.z3, w.z4],
133
+ e
134
+ ).flatMap((b) => {
135
+ const R = i * h * b + i * d - c * o * b - c * l;
136
+ if (R)
137
+ return [[-(i * P + i * p * b * b - c * r * b * b + i * m * b - c * u * b - c * a) / R, b]];
138
+ const T = o * b + l, L = -T / (2 * i), j = r * b * b + u * b + a, z = T * T / (4 * i * i) - j / i;
139
+ if (Math.abs(z) < e)
140
+ return [[L, b]];
141
+ if (z > 0) {
142
+ const Y = Math.sqrt(z);
143
+ return [[L + Y, b], [L - Y, b]];
144
+ }
145
+ return [];
146
+ });
147
+ return U(E, e);
148
+ }
149
+ function mt(t, n) {
150
+ return Dt(t, n).filter((s) => t.isOnSegment(s) && n.isOnSegment(s));
151
+ }
152
+ const gn = (t) => {
153
+ const {
154
+ firstPoint: n,
155
+ lastPoint: e,
156
+ center: s,
157
+ majorRadius: i,
158
+ minorRadius: o,
159
+ tiltAngle: r,
160
+ clockwise: l
161
+ } = t;
162
+ return new M(
163
+ e,
164
+ n,
165
+ s,
166
+ i,
167
+ o,
168
+ r,
169
+ l,
170
+ {
171
+ ignoreChecks: !0,
172
+ angleUnits: "rad"
173
+ }
174
+ );
175
+ }, Pn = (t, n) => {
176
+ if (t.isSame(n))
177
+ return [t];
178
+ const e = (i, o) => new M(
179
+ i,
180
+ o,
181
+ t.center,
182
+ t.majorRadius,
183
+ t.minorRadius,
184
+ t.tiltAngle,
185
+ t.clockwise,
186
+ { ignoreChecks: !0, angleUnits: "rad" }
187
+ ), s = U(
188
+ [
189
+ n.isOnSegment(t.firstPoint) ? t.firstPoint : null,
190
+ n.isOnSegment(t.lastPoint) ? t.lastPoint : null,
191
+ t.isOnSegment(n.firstPoint) ? n.firstPoint : null,
192
+ t.isOnSegment(n.lastPoint) ? n.lastPoint : null
193
+ ].filter((i) => i !== null)
194
+ // We sort by the param value of the first arc. This means that the points
195
+ // will be sorted with the same orientation than arc1
196
+ ).sort((i, o) => t.pointToParam(i) - t.pointToParam(o));
197
+ if (s.length === 0)
198
+ return [];
199
+ if (s.length === 1)
200
+ return [];
201
+ if (s.length === 2)
202
+ return t.isSame(gn(n)) ? [] : [e(s[0], s[1])];
203
+ if (s.length === 3) {
204
+ const i = g(s[0], n.lastPoint) || g(s[0], n.firstPoint) ? 1 : 0;
205
+ return [e(s[0 + i], s[1 + i])];
206
+ } else if (s.length === 4)
207
+ return [e(s[0], s[1]), e(s[2], s[3])];
208
+ throw new Error("Bug in the ellipse arc ellipse arc overlap algorithm");
209
+ };
210
+ function wn(t, n, e = !1) {
211
+ const s = Math.max(t.precision, n.precision);
212
+ return g(t.center, n.center) && Math.abs(t.majorRadius - n.majorRadius) < s && Math.abs(t.minorRadius - n.minorRadius) < s && (Math.abs(t.tiltAngle - n.tiltAngle) < s || Math.abs(Math.abs(t.tiltAngle - n.tiltAngle) - Math.PI) < s) ? e ? Pn(t, n) : [] : Dt(t, n).filter((r) => t.isOnSegment(r) && n.isOnSegment(r));
213
+ }
214
+ function gt(t, n) {
215
+ const [e, s] = t.firstPoint, [i, o] = t.lastPoint, r = new on().rotate(-Math.atan2(o - s, i - e)).translate(-e, -s), l = r.clone().inverse(), u = n.transform(r);
216
+ return u.paramsAtY(0).map((a) => u.paramPoint(a)).map((a) => l.transform(a)).filter((a) => t.isOnSegment(a));
217
+ }
218
+ const xn = (t, n = 1e-9) => {
219
+ let e = t;
220
+ return Math.abs(t) < n && (e = 0), e.toFixed(-Math.log10(n));
221
+ };
222
+ function Rt(t, n = 1e-9) {
223
+ return Array.from(
224
+ new Map(t.map((e) => [xn(e, n), e])).values()
225
+ );
226
+ }
227
+ const Sn = (t, n) => {
228
+ const [[e, s, i, o], [r, l, u, a]] = n.polynomialCoefficients, f = t.coefficients, c = f.x2, h = f.xy, p = f.y2, d = f.x, m = f.y, P = f.c, w = e * e, x = s * s, E = i * i, b = o * o, R = r * r, T = l * l, L = u * u, j = a * a, z = P + d * e + c * w + m * r + h * e * r + p * R, Y = d * s + 2 * c * e * s + h * s * r + m * l + h * e * l + 2 * p * r * l, Qt = c * x + d * i + 2 * c * e * i + h * i * r + h * s * l + p * T + m * u + h * e * u + 2 * p * r * u, Wt = 2 * c * s * i + d * o + 2 * c * e * o + h * o * r + h * i * l + h * s * u + 2 * p * l * u + m * a + h * e * a + 2 * p * r * a, Jt = c * E + 2 * c * s * o + h * o * l + h * i * u + p * L + h * s * a + 2 * p * l * a, Kt = 2 * c * i * o + h * o * u + h * i * a + 2 * p * u * a, Zt = c * b + h * o * a + p * j;
229
+ return [z, Y, Qt, Wt, Jt, Kt, Zt];
230
+ };
231
+ function Pt(t, n) {
232
+ const e = Math.max(t.precision, n.precision), s = Sn(t, n), i = Lt(s, e).filter((o) => o >= -n.precision && o <= 1 + n.precision);
233
+ return Rt(i, e).map((o) => n.paramPoint(o)).filter((o) => t.isOnSegment(o));
234
+ }
235
+ const yn = (t, n) => {
236
+ const [[e, s, i], [o, r, l]] = n.polynomialCoefficients, u = t.coefficients, a = u.x2, f = u.xy, c = u.y2, h = u.x, p = u.y, d = u.c, m = e * e, P = s * s, w = i * i, x = o * o, E = r * r, b = l * l, R = a * m + f * e * o + c * x + h * e + p * o + d, T = 2 * a * e * s + f * e * r + f * s * o + 2 * c * o * r + h * s + p * r, L = 2 * a * e * i + a * P + f * e * l + f * s * r + f * i * o + 2 * c * o * l + c * E + h * i + p * l, j = 2 * a * s * i + f * s * l + f * i * r + 2 * c * r * l, z = a * w + f * i * l + c * b;
237
+ return [R, T, L, j, z];
238
+ };
239
+ function wt(t, n) {
240
+ const e = Math.max(t.precision, n.precision), s = yn(t, n), i = rn(...s).filter((o) => o >= -n.precision && o <= 1 + n.precision);
241
+ return Rt(i, e).map((o) => n.paramPoint(o)).filter((o) => t.isOnSegment(o));
242
+ }
243
+ function F(t, { firstPoint: n, lastPoint: e }, s = 1e-9) {
244
+ const i = k(e, n);
245
+ return Math.abs(i[0]) < s ? i[1] > 0 ? n[0] - t[0] : t[0] - n[0] : Math.abs(i[1]) < s ? i[0] > 0 ? t[1] - n[1] : n[1] - t[1] : ln(i, k(t, n)) / cn(i);
246
+ }
247
+ class ct {
248
+ constructor(n, e, s, i) {
249
+ this.firstPoint = n, this.lastPoint = e, this.negativeThickness = s, this.positiveThickness = i;
250
+ }
251
+ get width() {
252
+ return this.positiveThickness - this.negativeThickness;
253
+ }
254
+ }
255
+ const bn = 3 / 4, Cn = 4 / 9;
256
+ function Mn(t) {
257
+ const n = F(t.firstControlPoint, t), e = F(t.lastControlPoint, t), s = n * e > 0 ? bn : Cn;
258
+ return new ct(
259
+ t.firstPoint,
260
+ t.lastPoint,
261
+ s * Math.min(0, n, e),
262
+ s * Math.max(0, n, e)
263
+ );
264
+ }
265
+ function An(t) {
266
+ const n = F(t.controlPoint, t);
267
+ return new ct(
268
+ t.firstPoint,
269
+ t.lastPoint,
270
+ Math.min(0, n / 2),
271
+ Math.max(0, n / 2)
272
+ );
273
+ }
274
+ function In(t) {
275
+ if (t instanceof I)
276
+ return Mn(t);
277
+ if (t instanceof A)
278
+ return An(t);
279
+ throw new Error("Not implemented");
280
+ }
281
+ function Fn(t) {
282
+ const n = t.paramPoint(0.5), e = Tt(k(n, t.firstPoint)), s = q(n, e), i = {
283
+ firstPoint: n,
284
+ lastPoint: s
285
+ }, o = [
286
+ F(t.firstPoint, i),
287
+ F(t.lastPoint, i)
288
+ ];
289
+ return t instanceof I ? o.push(
290
+ F(t.firstControlPoint, i),
291
+ F(t.lastControlPoint, i)
292
+ ) : t instanceof A && o.push(F(t.controlPoint, i)), new ct(
293
+ n,
294
+ s,
295
+ Math.min(...o),
296
+ Math.max(...o)
297
+ );
298
+ }
299
+ function xt(t, n) {
300
+ const e = [];
301
+ for (let s = 1; s < t.length; s++) {
302
+ const i = t[s];
303
+ if (i[1] === n) {
304
+ e.push(i[0]);
305
+ continue;
306
+ }
307
+ const o = t[s - 1], r = n - o[1], l = n - i[1];
308
+ if (r * l < 0) {
309
+ e.push(
310
+ o[0] + (n - o[1]) * (i[0] - o[0]) / (i[1] - o[1])
311
+ );
312
+ continue;
313
+ }
314
+ }
315
+ return e;
316
+ }
317
+ class H {
318
+ constructor(n, e) {
319
+ this.from = n, this.to = e;
320
+ }
321
+ get size() {
322
+ return this.from === "start" ? this.to === "end" ? 1 : this.to : this.to === "end" ? 1 - this.from : Math.abs(this.from - this.to);
323
+ }
324
+ clipCurve(n) {
325
+ return this.from === "start" ? this.to === "end" ? n : n.splitAtParameters([this.to])[0] : this.to === "end" ? n.splitAtParameters([this.from])[1] : n.splitAtParameters([this.from, this.to])[1];
326
+ }
327
+ }
328
+ function En(t, n) {
329
+ if (t instanceof I)
330
+ return new Bn([
331
+ F(t.firstPoint, n),
332
+ F(t.firstControlPoint, n),
333
+ F(t.lastControlPoint, n),
334
+ F(t.lastPoint, n)
335
+ ]);
336
+ if (t instanceof A)
337
+ return new vn([
338
+ F(t.firstPoint, n),
339
+ F(t.controlPoint, n),
340
+ F(t.lastPoint, n)
341
+ ]);
342
+ throw new Error("Not implemented");
343
+ }
344
+ class vn {
345
+ constructor(n) {
346
+ C(this, "topHull", []);
347
+ C(this, "bottomHull", []);
348
+ this.distances = n;
349
+ const [e, s, i] = n, o = [0, e], r = [1 / 2, s], l = [1, i], u = i - e, a = e;
350
+ s - (u * (1 / 2) + a) > 0 ? (this.topHull = [o, r, l], this.bottomHull = [o, l]) : (this.topHull = [o, l], this.bottomHull = [o, r, l]);
351
+ }
352
+ get startDistance() {
353
+ return this.distances[0];
354
+ }
355
+ get endDistance() {
356
+ return this.distances[2];
357
+ }
358
+ }
359
+ class Bn {
360
+ constructor(n) {
361
+ C(this, "topHull", []);
362
+ C(this, "bottomHull", []);
363
+ this.distances = n;
364
+ const [e, s, i, o] = n, r = [0, e], l = [1 / 3, s], u = [2 / 3, i], a = [1, o], f = o - e, c = e, h = s - (f * (1 / 3) + c), p = i - (f * (2 / 3) + c);
365
+ let d = null, m = null;
366
+ if (h * p < 0)
367
+ d = [r, l, a], m = [r, u, a];
368
+ else {
369
+ const w = h / p;
370
+ w >= 2 ? (d = [r, l, a], m = [r, a]) : w <= 0.5 ? (d = [r, u, a], m = [r, a]) : (d = [r, l, u, a], m = [r, a]);
371
+ }
372
+ h < 0 && ([d, m] = [m, d]), this.topHull = d, this.bottomHull = m;
373
+ }
374
+ get startDistance() {
375
+ return this.distances[0];
376
+ }
377
+ get endDistance() {
378
+ return this.distances[3];
379
+ }
380
+ }
381
+ function St(t, n) {
382
+ const e = En(n, t), s = xt(
383
+ e.topHull,
384
+ t.negativeThickness
385
+ ), i = xt(
386
+ e.bottomHull,
387
+ t.positiveThickness
388
+ ), o = e.endDistance >= t.negativeThickness && e.endDistance <= t.positiveThickness;
389
+ if (!s.length && !i.length)
390
+ return o ? new H("start", "end") : null;
391
+ if (s.length === 1 && i.length === 1)
392
+ return new H(s[0], i[0]);
393
+ if (s.length === 2 && i.length === 2)
394
+ throw new Error(
395
+ "Bug in the clipping algorithm, unexpected number of crossing points"
396
+ );
397
+ const r = s.length ? s : i;
398
+ return r.length === 2 ? new H(r[0], r[1]) : o ? new H(r[0], "end") : new H("start", r[0]);
399
+ }
400
+ function yt(t, n) {
401
+ const e = In(t), s = St(e, n);
402
+ if (!s)
403
+ return null;
404
+ const i = Fn(t), o = St(
405
+ i,
406
+ n
407
+ );
408
+ return o ? s.size > o.size ? o.clipCurve(n) : s.clipCurve(n) : null;
409
+ }
410
+ const W = (t) => t instanceof A ? $(k(t.controlPoint, t.firstPoint)) + $(k(t.controlPoint, t.lastPoint)) : $(k(t.firstControlPoint, t.firstPoint)) + $(k(t.lastControlPoint, t.firstControlPoint)) + $(k(t.lastControlPoint, t.lastPoint));
411
+ function D(t, n, e = 1e-9, { maxIterations: s = 100 } = {}) {
412
+ const i = Math.max(e * e, Number.EPSILON * 10);
413
+ let o = t, r = n, l = W(o), u = W(r);
414
+ for (let a = 0; a < s; a++) {
415
+ const f = l > i ? yt(r, o) : o;
416
+ if (!f)
417
+ return [];
418
+ const c = W(f), h = u > i ? yt(f, r) : r;
419
+ if (!h)
420
+ return [];
421
+ const p = W(h);
422
+ if (c <= i && p <= i)
423
+ return [
424
+ f.boundingBox.intersection(h.boundingBox).center
425
+ ];
426
+ if (g(f.firstPoint, f.lastPoint) && h.isOnSegment(f.firstPoint))
427
+ return [f.firstPoint];
428
+ if (g(h.firstPoint, h.lastPoint) && f.isOnSegment(h.firstPoint))
429
+ return [h.firstPoint];
430
+ if (c > 0.8 * l && p > 0.8 * u)
431
+ if (c / l > p / u) {
432
+ const [d, m] = f.splitAtParameters([
433
+ 0.5
434
+ ]);
435
+ return U(
436
+ [
437
+ ...D(d, h, e, {
438
+ maxIterations: s - a
439
+ }),
440
+ ...D(m, h, e, {
441
+ maxIterations: s - a
442
+ })
443
+ ],
444
+ e
445
+ );
446
+ } else {
447
+ const [d, m] = h.splitAtParameters([
448
+ 0.5
449
+ ]);
450
+ return U(
451
+ [
452
+ ...D(f, d, e, {
453
+ maxIterations: s - a
454
+ }),
455
+ ...D(f, m, e, {
456
+ maxIterations: s - a
457
+ })
458
+ ],
459
+ e
460
+ );
461
+ }
462
+ o = f, r = h, l = c, u = p;
463
+ }
464
+ throw new Error("Bézier clip: Maximum number of iterations reached");
465
+ }
466
+ function kn(t, n) {
467
+ const e = [];
468
+ if ([
469
+ [t.firstPoint, n],
470
+ [t.lastPoint, n],
471
+ [n.firstPoint, t],
472
+ [n.lastPoint, t]
473
+ ].forEach(([i, o]) => {
474
+ o.isOnSegment(i) && e.push(i);
475
+ }), e.length < 2)
476
+ return null;
477
+ if (e.length === 2)
478
+ return [t.splitAt(e)[1]];
479
+ if (e.length === 3)
480
+ return g(e[0], t.firstPoint) && g(e[1], t.lastPoint) ? [t] : [n];
481
+ if (e.length === 4)
482
+ return [t];
483
+ }
484
+ function _n(t, n, e = !1) {
485
+ const s = Math.max(t.precision, n.precision);
486
+ if (e) {
487
+ const i = kn(t, n);
488
+ if (i)
489
+ return i;
490
+ }
491
+ return D(t, n, s);
492
+ }
493
+ function On(t, n) {
494
+ const e = [];
495
+ if ([
496
+ [t.firstPoint, n],
497
+ [t.lastPoint, n],
498
+ [n.firstPoint, t],
499
+ [n.lastPoint, t]
500
+ ].forEach(([i, o]) => {
501
+ o.isOnSegment(i) && e.push(i);
502
+ }), e.length < 2)
503
+ return null;
504
+ if (e.length === 2)
505
+ return [t.splitAt(e)[1]];
506
+ if (e.length === 3)
507
+ return g(e[0], t.firstPoint) && g(e[1], t.lastPoint) ? [t] : [n];
508
+ if (e.length === 4)
509
+ return [t];
510
+ }
511
+ function Tn(t, n, e = !1) {
512
+ const s = Math.max(t.precision, n.precision);
513
+ if (e) {
514
+ const i = On(t, n);
515
+ if (i)
516
+ return i;
517
+ }
518
+ return D(t, n, s);
519
+ }
520
+ function ae(t, n, e) {
521
+ if (t instanceof y && n instanceof y) {
522
+ const s = zt(
523
+ t,
524
+ n,
525
+ !1,
526
+ e
527
+ );
528
+ return s === null ? [] : [s];
529
+ }
530
+ if (t instanceof y && n instanceof S)
531
+ return J(t, n, e);
532
+ if (t instanceof S && n instanceof y)
533
+ return J(n, t, e);
534
+ if (t instanceof S && n instanceof S)
535
+ return qt(t, n, !1, e);
536
+ throw new Error("Not implemented");
537
+ }
538
+ function K(t, n, e) {
539
+ if (t instanceof y && n instanceof y) {
540
+ const s = zt(
541
+ t,
542
+ n,
543
+ !0,
544
+ e
545
+ );
546
+ return s === null ? { intersections: [], overlaps: [], count: 0 } : s instanceof y ? { intersections: [], overlaps: [s], count: 1 } : { intersections: [s], overlaps: [], count: 1 };
547
+ }
548
+ if (!t.boundingBox.overlaps(n.boundingBox))
549
+ return { intersections: [], overlaps: [], count: 0 };
550
+ if (t instanceof y && n instanceof S) {
551
+ const s = J(t, n, e);
552
+ return { intersections: s, overlaps: [], count: s.length };
553
+ }
554
+ if (t instanceof S && n instanceof y) {
555
+ const s = J(n, t, e);
556
+ return { intersections: s, overlaps: [], count: s.length };
557
+ }
558
+ if (t instanceof S && n instanceof S) {
559
+ const s = qt(
560
+ t,
561
+ n,
562
+ !0,
563
+ e
564
+ );
565
+ return s.length ? s[0] instanceof S ? {
566
+ intersections: [],
567
+ overlaps: s,
568
+ count: s.length
569
+ } : {
570
+ intersections: s,
571
+ overlaps: [],
572
+ count: s.length
573
+ } : { intersections: [], overlaps: [], count: 0 };
574
+ }
575
+ if (t instanceof y && n instanceof M) {
576
+ const s = et(
577
+ t,
578
+ n,
579
+ e
580
+ );
581
+ return { intersections: s, overlaps: [], count: s.length };
582
+ }
583
+ if (n instanceof y && t instanceof M) {
584
+ const s = et(
585
+ n,
586
+ t,
587
+ e
588
+ );
589
+ return { intersections: s, overlaps: [], count: s.length };
590
+ }
591
+ if (t instanceof S && n instanceof M) {
592
+ const s = mt(t, n);
593
+ return { intersections: s, overlaps: [], count: s.length };
594
+ }
595
+ if (n instanceof S && t instanceof M) {
596
+ const s = mt(n, t);
597
+ return { intersections: s, overlaps: [], count: s.length };
598
+ }
599
+ if (t instanceof M && n instanceof M) {
600
+ const s = wn(
601
+ t,
602
+ n,
603
+ !0
604
+ );
605
+ return s.length ? s[0] instanceof M ? {
606
+ intersections: [],
607
+ overlaps: s,
608
+ count: s.length
609
+ } : {
610
+ intersections: s,
611
+ overlaps: [],
612
+ count: s.length
613
+ } : { intersections: [], overlaps: [], count: 0 };
614
+ }
615
+ if (t instanceof y && (n instanceof I || n instanceof A)) {
616
+ const s = gt(t, n);
617
+ return { intersections: s, overlaps: [], count: s.length };
618
+ }
619
+ if (n instanceof y && (t instanceof I || t instanceof A)) {
620
+ const s = gt(n, t);
621
+ return { intersections: s, overlaps: [], count: s.length };
622
+ }
623
+ if ((t instanceof S || t instanceof M) && n instanceof A) {
624
+ const s = wt(t, n);
625
+ return { intersections: s, overlaps: [], count: s.length };
626
+ }
627
+ if ((n instanceof S || n instanceof M) && t instanceof A) {
628
+ const s = wt(n, t);
629
+ return { intersections: s, overlaps: [], count: s.length };
630
+ }
631
+ if ((t instanceof S || t instanceof M) && n instanceof I) {
632
+ const s = Pt(t, n);
633
+ return { intersections: s, overlaps: [], count: s.length };
634
+ }
635
+ if ((n instanceof S || n instanceof M) && t instanceof I) {
636
+ const s = Pt(n, t);
637
+ return { intersections: s, overlaps: [], count: s.length };
638
+ }
639
+ if (t instanceof A && n instanceof A) {
640
+ const s = Tn(
641
+ t,
642
+ n
643
+ );
644
+ return s.length ? s[0] instanceof A ? {
645
+ intersections: [],
646
+ overlaps: s,
647
+ count: s.length
648
+ } : {
649
+ intersections: s,
650
+ overlaps: [],
651
+ count: s.length
652
+ } : { intersections: [], overlaps: [], count: 0 };
653
+ }
654
+ if (t instanceof A && n instanceof I || n instanceof A && t instanceof I) {
655
+ const s = D(t, n);
656
+ return { intersections: s, overlaps: [], count: s.length };
657
+ }
658
+ if (t instanceof I && n instanceof I) {
659
+ const s = _n(
660
+ t,
661
+ n
662
+ );
663
+ return s.length ? s[0] instanceof I ? {
664
+ intersections: [],
665
+ overlaps: s,
666
+ count: s.length
667
+ } : {
668
+ intersections: s,
669
+ overlaps: [],
670
+ count: s.length
671
+ } : { intersections: [], overlaps: [], count: 0 };
672
+ }
673
+ throw new Error("Not implemented");
674
+ }
675
+ function Vt(t) {
676
+ const n = [];
677
+ for (let e = 0; e < t; e++)
678
+ for (let s = 0; s <= e; s++)
679
+ n.push([e, s]);
680
+ return n;
681
+ }
682
+ function* st(t) {
683
+ for (const [n, e] of Vt(t.length))
684
+ n !== e && (yield [t[n], t[e]]);
685
+ }
686
+ class Nt extends lt {
687
+ constructor(e, { ignoreChecks: s = !1 } = {}) {
688
+ super();
689
+ C(this, "segments");
690
+ C(this, "_boundingBox", null);
691
+ s || Ut(e), this.segments = e;
692
+ }
693
+ get repr() {
694
+ return this.segments.map((e) => e.repr).join(`
695
+ `) + `
696
+ `;
697
+ }
698
+ get info() {
699
+ return this.repr;
700
+ }
701
+ get firstPoint() {
702
+ return this.segments[0].firstPoint;
703
+ }
704
+ get lastPoint() {
705
+ return this.segments[this.segments.length - 1].lastPoint;
706
+ }
707
+ get segmentsCount() {
708
+ return this.segments.length;
709
+ }
710
+ onStroke(e) {
711
+ return this.segments.some((s) => s.isOnSegment(e));
712
+ }
713
+ intersects(e) {
714
+ return this.boundingBox.overlaps(e.boundingBox) ? this.segments.some(
715
+ (s) => e.segments.some(
716
+ (i) => K(s, i).count > 0
717
+ )
718
+ ) : !1;
719
+ }
720
+ overlappingSegments(e) {
721
+ return this.segments.flatMap((s) => e.segments.flatMap((i) => s.boundingBox.overlaps(i.boundingBox) ? K(s, i).overlaps : []));
722
+ }
723
+ get boundingBox() {
724
+ if (this._boundingBox === null) {
725
+ let e = this.segments[0].boundingBox;
726
+ this.segments.slice(1).forEach((s) => {
727
+ e = e.merge(s.boundingBox);
728
+ }), this._boundingBox = e;
729
+ }
730
+ return this._boundingBox;
731
+ }
732
+ [Symbol.for("nodejs.util.inspect.custom")]() {
733
+ return this.repr;
734
+ }
735
+ }
736
+ function Ln(t, n = "Stroke") {
737
+ Vt(t.length).forEach(
738
+ ([e, s]) => {
739
+ if (e === s)
740
+ return;
741
+ const i = t[e], o = t[s], r = K(i, o), l = Math.max(i.precision, o.precision);
742
+ if (r.count !== 0) {
743
+ if (r.count === 1 && !r.overlaps.length) {
744
+ const u = e - s, a = r.intersections[0];
745
+ if (u === 1 && g(i.firstPoint, a, l) || u === -1 && g(i.lastPoint, a, l) || u === t.length - 1 && g(i.lastPoint, a, l) && g(o.firstPoint, a, l) || -u === t.length - 1 && g(i.firstPoint, a, l) && g(o.lastPoint, a, l))
746
+ return;
747
+ }
748
+ if (!(r.count === 2 && t.length === 2 && (g(
749
+ i.firstPoint,
750
+ r.intersections[0],
751
+ l
752
+ ) && g(
753
+ i.lastPoint,
754
+ r.intersections[1],
755
+ l
756
+ ) || g(
757
+ i.firstPoint,
758
+ r.intersections[1],
759
+ l
760
+ ) && g(
761
+ i.lastPoint,
762
+ r.intersections[0],
763
+ l
764
+ ))))
765
+ throw new Error(
766
+ `${n} segments must not intersect, but segments ${i.info} and ${o.info} do at ${JSON.stringify(
767
+ r.intersections
768
+ )}`
769
+ );
770
+ }
771
+ }
772
+ );
773
+ }
774
+ function Ut(t, n = "Stroke") {
775
+ if (t.length === 0)
776
+ throw new Error(`${n} must have at least one segment`);
777
+ N([t.slice(0, -1), t.slice(1)]).forEach(
778
+ ([e, s]) => {
779
+ if (!g(e.lastPoint, s.firstPoint))
780
+ throw new Error(
781
+ `${n} segments must be connected, but ${e.info} and ${s.info} are not`
782
+ );
783
+ }
784
+ ), Ln(t, n);
785
+ }
786
+ function bt(t, n) {
787
+ return !!(t instanceof y && n instanceof y && un(t.V, n.V) || t instanceof S && n instanceof S && g(t.center, n.center) && t.radius - n.radius < t.precision);
788
+ }
789
+ function Ct(t, n) {
790
+ if (t instanceof y && n instanceof y)
791
+ return new y(t.firstPoint, n.lastPoint);
792
+ if (t instanceof S && n instanceof S)
793
+ return new S(
794
+ t.firstPoint,
795
+ n.lastPoint,
796
+ t.center,
797
+ t.clockwise
798
+ );
799
+ throw new Error("Not implemented");
800
+ }
801
+ function jt(t) {
802
+ let n = !1;
803
+ const e = [];
804
+ for (const s of t.segments) {
805
+ if (e.length === 0) {
806
+ e.push(s);
807
+ continue;
808
+ }
809
+ const i = e[e.length - 1];
810
+ bt(i, s) ? (n = !0, e.pop(), e.push(Ct(i, s))) : e.push(s);
811
+ }
812
+ if (g(t.firstPoint, t.lastPoint) && bt(
813
+ e[0],
814
+ e[e.length - 1]
815
+ )) {
816
+ n = !0;
817
+ const s = e.pop();
818
+ e[0] = Ct(s, e[0]);
819
+ }
820
+ return n ? e : null;
821
+ }
822
+ class B extends Nt {
823
+ constructor() {
824
+ super(...arguments);
825
+ C(this, "strokeType", "STRAND");
826
+ }
827
+ reverse() {
828
+ const e = this.segments.map((s) => s.reverse());
829
+ return e.reverse(), new B(e, { ignoreChecks: !0 });
830
+ }
831
+ clone() {
832
+ return new B(
833
+ this.segments.map((e) => e.clone()),
834
+ { ignoreChecks: !0 }
835
+ );
836
+ }
837
+ extend(e) {
838
+ if (!g(this.lastPoint, e.firstPoint))
839
+ throw console.error(this.repr, e.repr), new Error("Cannot extend strand: connection point is not the same");
840
+ return new B([...this.segments, ...e.segments]);
841
+ }
842
+ simplify() {
843
+ const e = jt(this);
844
+ return e ? new B(e, { ignoreChecks: !0 }) : this;
845
+ }
846
+ transform(e) {
847
+ return new B(
848
+ this.segments.map((s) => s.transform(e)),
849
+ { ignoreChecks: !0 }
850
+ );
851
+ }
852
+ }
853
+ const zn = (t, n) => {
854
+ const e = an(n, {
855
+ V: [1, 0],
856
+ firstPoint: t,
857
+ precision: n.precision
858
+ });
859
+ if (e === "parallel")
860
+ return 0;
861
+ const { intersectionParam1: s, intersectionParam2: i } = e;
862
+ if (!n.isValidParameter(s) || i <= -n.precision)
863
+ return 0;
864
+ if (Math.abs(s) < n.precision || Math.abs(s - 1) < n.precision) {
865
+ const [, o] = n.midPoint;
866
+ return t[1] - o < 0 ? 1 : 0;
867
+ }
868
+ return 1;
869
+ };
870
+ class ut {
871
+ constructor(n) {
872
+ C(this, "_count", 0);
873
+ C(this, "segment");
874
+ this.segment = n;
875
+ }
876
+ update(n, e = !1) {
877
+ !e && !this.segment.isOnSegment(n) || (g(n, this.segment.firstPoint) ? this._count += this.segment.tangentAtFirstPoint[1] > 0 ? 1 : 0 : g(n, this.segment.lastPoint) ? this._count += this.segment.tangentAtLastPoint[1] > 0 ? 0 : 1 : this._count += 1);
878
+ }
879
+ get count() {
880
+ return this._count;
881
+ }
882
+ }
883
+ const qn = (t, n) => {
884
+ const e = n.precision, s = Math.abs(t[1] - n.center[1]);
885
+ if (s > n.radius + e)
886
+ return 0;
887
+ const i = fn(t, n.center), o = n.radius * n.radius, r = e * e;
888
+ if (Math.abs(i - o) < r && n.isOnSegment(t))
889
+ return 0;
890
+ const l = i - o > r;
891
+ if (l && n.center[0] < t[0])
892
+ return 0;
893
+ const u = Math.sqrt(
894
+ n.radius * n.radius - s * s
895
+ ), a = new ut(n);
896
+ return a.update([n.center[0] + u, t[1]]), l && a.update([n.center[0] - u, t[1]]), a.count;
897
+ }, Dn = (t, n) => {
898
+ const e = n.boundingBox.xMax + n.boundingBox.width / 2, s = new y(t, [e, t[1]]), i = new ut(n);
899
+ return et(s, n).forEach((o) => {
900
+ i.update(o, !0);
901
+ }), i.count;
902
+ }, Rn = (t, n) => {
903
+ const e = new ut(n);
904
+ return n.paramsAtY(t[1]).map((s) => {
905
+ try {
906
+ return n.paramPoint(s);
907
+ } catch {
908
+ return null;
909
+ }
910
+ }).filter((s) => s !== null).filter((s) => {
911
+ const [i] = s;
912
+ return i >= t[0];
913
+ }).forEach((s) => {
914
+ e.update(s, !0);
915
+ }), e.count;
916
+ };
917
+ function Vn(t, n) {
918
+ if (n instanceof y)
919
+ return zn(t, n);
920
+ if (n instanceof S)
921
+ return qn(t, n);
922
+ if (n instanceof M)
923
+ return Dn(t, n);
924
+ if (n instanceof I || n instanceof A)
925
+ return Rn(t, n);
926
+ throw new Error("Not implemented");
927
+ }
928
+ class O extends Nt {
929
+ constructor(e, { ignoreChecks: s = !1 } = {}) {
930
+ super(e, { ignoreChecks: !0 });
931
+ C(this, "strokeType", "LOOP");
932
+ C(this, "_clockwise", null);
933
+ s || Nn(e);
934
+ }
935
+ get clockwise() {
936
+ if (this._clockwise === null) {
937
+ const e = this.segments.flatMap((i) => i instanceof y ? [i.firstPoint] : [i.firstPoint, i.paramPoint(0.5)]), s = e.map((i, o) => {
938
+ const r = e[(o + 1) % e.length];
939
+ return (r[0] - i[0]) * (r[1] + i[1]);
940
+ }).reduce((i, o) => i + o, 0);
941
+ this._clockwise = s > 0;
942
+ }
943
+ return this._clockwise;
944
+ }
945
+ clone() {
946
+ return new O(
947
+ this.segments.map((e) => e.clone()),
948
+ { ignoreChecks: !0 }
949
+ );
950
+ }
951
+ reverse() {
952
+ const e = this.segments.map((s) => s.reverse());
953
+ return e.reverse(), new O(e, { ignoreChecks: !0 });
954
+ }
955
+ transform(e) {
956
+ return new O(
957
+ this.segments.map((s) => s.transform(e)),
958
+ { ignoreChecks: !0 }
959
+ );
960
+ }
961
+ contains(e) {
962
+ return this.onStroke(e) || !this.boundingBox.contains(e) ? !1 : this.segments.reduce((i, o) => i + Vn(e, o), 0) % 2 === 1;
963
+ }
964
+ simplify() {
965
+ const e = jt(this);
966
+ return e ? new O(e, { ignoreChecks: !0 }) : this;
967
+ }
968
+ }
969
+ function Nn(t) {
970
+ if (Ut(t, "Loop"), !g(t[0].firstPoint, t[t.length - 1].lastPoint))
971
+ throw new Error("Loop segment must be closed");
972
+ }
973
+ const Un = [
974
+ y,
975
+ S,
976
+ M,
977
+ A,
978
+ I
979
+ ];
980
+ function jn(t) {
981
+ return Un.some((n) => t instanceof n);
982
+ }
983
+ function Yt(t) {
984
+ if (t instanceof y)
985
+ return {
986
+ type: t.segmentType,
987
+ firstPoint: t.firstPoint,
988
+ lastPoint: t.lastPoint
989
+ };
990
+ if (t instanceof S)
991
+ return {
992
+ type: t.segmentType,
993
+ firstPoint: t.firstPoint,
994
+ lastPoint: t.lastPoint,
995
+ center: t.center,
996
+ clockwise: t.clockwise
997
+ };
998
+ if (t instanceof M)
999
+ return {
1000
+ type: t.segmentType,
1001
+ firstPoint: t.firstPoint,
1002
+ lastPoint: t.lastPoint,
1003
+ center: t.center,
1004
+ clockwise: t.clockwise,
1005
+ majorRadius: t.majorRadius,
1006
+ minorRadius: t.minorRadius,
1007
+ tiltAngle: t.tiltAngle
1008
+ };
1009
+ if (t instanceof A)
1010
+ return {
1011
+ type: t.segmentType,
1012
+ firstPoint: t.firstPoint,
1013
+ lastPoint: t.lastPoint,
1014
+ controlPoint: t.controlPoint
1015
+ };
1016
+ if (t instanceof I)
1017
+ return {
1018
+ type: t.segmentType,
1019
+ firstPoint: t.firstPoint,
1020
+ lastPoint: t.lastPoint,
1021
+ firstControlPoint: t.firstControlPoint,
1022
+ lastControlPoint: t.lastControlPoint
1023
+ };
1024
+ throw new Error("Unknown segment type");
1025
+ }
1026
+ function it(t) {
1027
+ return {
1028
+ type: "LOOP",
1029
+ segments: t.segments.map(Yt)
1030
+ };
1031
+ }
1032
+ function $t(t) {
1033
+ return {
1034
+ type: "FIGURE",
1035
+ contour: it(t.contour),
1036
+ holes: t.holes.map(it)
1037
+ };
1038
+ }
1039
+ function Yn(t) {
1040
+ return {
1041
+ type: "DIAGRAM",
1042
+ figures: t.figures.map($t)
1043
+ };
1044
+ }
1045
+ function Mt(t) {
1046
+ if (t instanceof _)
1047
+ return Yn(t);
1048
+ if (t instanceof v)
1049
+ return $t(t);
1050
+ if (t instanceof O)
1051
+ return it(t);
1052
+ if (jn(t))
1053
+ return Yt(t);
1054
+ throw new Error("Unknown shape type");
1055
+ }
1056
+ class $n {
1057
+ constructor() {
1058
+ this.ids = [], this.values = [], this.length = 0;
1059
+ }
1060
+ clear() {
1061
+ this.length = 0;
1062
+ }
1063
+ push(n, e) {
1064
+ let s = this.length++;
1065
+ for (; s > 0; ) {
1066
+ const i = s - 1 >> 1, o = this.values[i];
1067
+ if (e >= o)
1068
+ break;
1069
+ this.ids[s] = this.ids[i], this.values[s] = o, s = i;
1070
+ }
1071
+ this.ids[s] = n, this.values[s] = e;
1072
+ }
1073
+ pop() {
1074
+ if (this.length === 0)
1075
+ return;
1076
+ const n = this.ids[0];
1077
+ if (this.length--, this.length > 0) {
1078
+ const e = this.ids[0] = this.ids[this.length], s = this.values[0] = this.values[this.length], i = this.length >> 1;
1079
+ let o = 0;
1080
+ for (; o < i; ) {
1081
+ let r = (o << 1) + 1;
1082
+ const l = r + 1;
1083
+ let u = this.ids[r], a = this.values[r];
1084
+ const f = this.values[l];
1085
+ if (l < this.length && f < a && (r = l, u = this.ids[l], a = f), a >= s)
1086
+ break;
1087
+ this.ids[o] = u, this.values[o] = a, o = r;
1088
+ }
1089
+ this.ids[o] = e, this.values[o] = s;
1090
+ }
1091
+ return n;
1092
+ }
1093
+ peek() {
1094
+ if (this.length !== 0)
1095
+ return this.ids[0];
1096
+ }
1097
+ peekValue() {
1098
+ if (this.length !== 0)
1099
+ return this.values[0];
1100
+ }
1101
+ shrink() {
1102
+ this.ids.length = this.values.length = this.length;
1103
+ }
1104
+ }
1105
+ const At = [
1106
+ Int8Array,
1107
+ Uint8Array,
1108
+ Uint8ClampedArray,
1109
+ Int16Array,
1110
+ Uint16Array,
1111
+ Int32Array,
1112
+ Uint32Array,
1113
+ Float32Array,
1114
+ Float64Array
1115
+ ], nt = 3;
1116
+ class at {
1117
+ static from(n) {
1118
+ if (!n || n.byteLength === void 0 || n.buffer)
1119
+ throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");
1120
+ const [e, s] = new Uint8Array(n, 0, 2);
1121
+ if (e !== 251)
1122
+ throw new Error("Data does not appear to be in a Flatbush format.");
1123
+ if (s >> 4 !== nt)
1124
+ throw new Error(`Got v${s >> 4} data when expected v${nt}.`);
1125
+ const [i] = new Uint16Array(n, 2, 1), [o] = new Uint32Array(n, 4, 1);
1126
+ return new at(o, i, At[s & 15], void 0, n);
1127
+ }
1128
+ constructor(n, e = 16, s = Float64Array, i = ArrayBuffer, o) {
1129
+ if (n === void 0)
1130
+ throw new Error("Missing required argument: numItems.");
1131
+ if (isNaN(n) || n <= 0)
1132
+ throw new Error(`Unexpected numItems value: ${n}.`);
1133
+ this.numItems = +n, this.nodeSize = Math.min(Math.max(+e, 2), 65535);
1134
+ let r = n, l = r;
1135
+ this._levelBounds = [r * 4];
1136
+ do
1137
+ r = Math.ceil(r / this.nodeSize), l += r, this._levelBounds.push(l * 4);
1138
+ while (r !== 1);
1139
+ this.ArrayType = s || Float64Array, this.IndexArrayType = l < 16384 ? Uint16Array : Uint32Array;
1140
+ const u = At.indexOf(this.ArrayType), a = l * 4 * this.ArrayType.BYTES_PER_ELEMENT;
1141
+ if (u < 0)
1142
+ throw new Error(`Unexpected typed array class: ${s}.`);
1143
+ o && o.byteLength !== void 0 && !o.buffer ? (this.data = o, this._boxes = new this.ArrayType(this.data, 8, l * 4), this._indices = new this.IndexArrayType(this.data, 8 + a, l), this._pos = l * 4, this.minX = this._boxes[this._pos - 4], this.minY = this._boxes[this._pos - 3], this.maxX = this._boxes[this._pos - 2], this.maxY = this._boxes[this._pos - 1]) : (this.data = new i(8 + a + l * this.IndexArrayType.BYTES_PER_ELEMENT), this._boxes = new this.ArrayType(this.data, 8, l * 4), this._indices = new this.IndexArrayType(this.data, 8 + a, l), this._pos = 0, this.minX = 1 / 0, this.minY = 1 / 0, this.maxX = -1 / 0, this.maxY = -1 / 0, new Uint8Array(this.data, 0, 2).set([251, (nt << 4) + u]), new Uint16Array(this.data, 2, 1)[0] = e, new Uint32Array(this.data, 4, 1)[0] = n), this._queue = new $n();
1144
+ }
1145
+ add(n, e, s, i) {
1146
+ const o = this._pos >> 2, r = this._boxes;
1147
+ return this._indices[o] = o, r[this._pos++] = n, r[this._pos++] = e, r[this._pos++] = s, r[this._pos++] = i, n < this.minX && (this.minX = n), e < this.minY && (this.minY = e), s > this.maxX && (this.maxX = s), i > this.maxY && (this.maxY = i), o;
1148
+ }
1149
+ finish() {
1150
+ if (this._pos >> 2 !== this.numItems)
1151
+ throw new Error(`Added ${this._pos >> 2} items when expected ${this.numItems}.`);
1152
+ const n = this._boxes;
1153
+ if (this.numItems <= this.nodeSize) {
1154
+ n[this._pos++] = this.minX, n[this._pos++] = this.minY, n[this._pos++] = this.maxX, n[this._pos++] = this.maxY;
1155
+ return;
1156
+ }
1157
+ const e = this.maxX - this.minX || 1, s = this.maxY - this.minY || 1, i = new Uint32Array(this.numItems), o = (1 << 16) - 1;
1158
+ for (let r = 0, l = 0; r < this.numItems; r++) {
1159
+ const u = n[l++], a = n[l++], f = n[l++], c = n[l++], h = Math.floor(o * ((u + f) / 2 - this.minX) / e), p = Math.floor(o * ((a + c) / 2 - this.minY) / s);
1160
+ i[r] = Xn(h, p);
1161
+ }
1162
+ ot(i, n, this._indices, 0, this.numItems - 1, this.nodeSize);
1163
+ for (let r = 0, l = 0; r < this._levelBounds.length - 1; r++) {
1164
+ const u = this._levelBounds[r];
1165
+ for (; l < u; ) {
1166
+ const a = l;
1167
+ let f = n[l++], c = n[l++], h = n[l++], p = n[l++];
1168
+ for (let d = 1; d < this.nodeSize && l < u; d++)
1169
+ f = Math.min(f, n[l++]), c = Math.min(c, n[l++]), h = Math.max(h, n[l++]), p = Math.max(p, n[l++]);
1170
+ this._indices[this._pos >> 2] = a, n[this._pos++] = f, n[this._pos++] = c, n[this._pos++] = h, n[this._pos++] = p;
1171
+ }
1172
+ }
1173
+ }
1174
+ search(n, e, s, i, o) {
1175
+ if (this._pos !== this._boxes.length)
1176
+ throw new Error("Data not yet indexed - call index.finish().");
1177
+ let r = this._boxes.length - 4;
1178
+ const l = [], u = [];
1179
+ for (; r !== void 0; ) {
1180
+ const a = Math.min(r + this.nodeSize * 4, Ft(r, this._levelBounds));
1181
+ for (let f = r; f < a; f += 4) {
1182
+ if (s < this._boxes[f] || i < this._boxes[f + 1] || n > this._boxes[f + 2] || e > this._boxes[f + 3])
1183
+ continue;
1184
+ const c = this._indices[f >> 2] | 0;
1185
+ r >= this.numItems * 4 ? l.push(c) : (o === void 0 || o(c)) && u.push(c);
1186
+ }
1187
+ r = l.pop();
1188
+ }
1189
+ return u;
1190
+ }
1191
+ neighbors(n, e, s = 1 / 0, i = 1 / 0, o) {
1192
+ if (this._pos !== this._boxes.length)
1193
+ throw new Error("Data not yet indexed - call index.finish().");
1194
+ let r = this._boxes.length - 4;
1195
+ const l = this._queue, u = [], a = i * i;
1196
+ for (; r !== void 0; ) {
1197
+ const f = Math.min(r + this.nodeSize * 4, Ft(r, this._levelBounds));
1198
+ for (let c = r; c < f; c += 4) {
1199
+ const h = this._indices[c >> 2] | 0, p = It(n, this._boxes[c], this._boxes[c + 2]), d = It(e, this._boxes[c + 1], this._boxes[c + 3]), m = p * p + d * d;
1200
+ r >= this.numItems * 4 ? l.push(h << 1, m) : (o === void 0 || o(h)) && l.push((h << 1) + 1, m);
1201
+ }
1202
+ for (; l.length && l.peek() & 1; )
1203
+ if (l.peekValue() > a || (u.push(l.pop() >> 1), u.length === s))
1204
+ return l.clear(), u;
1205
+ r = l.pop() >> 1;
1206
+ }
1207
+ return l.clear(), u;
1208
+ }
1209
+ }
1210
+ function It(t, n, e) {
1211
+ return t < n ? n - t : t <= e ? 0 : t - e;
1212
+ }
1213
+ function Ft(t, n) {
1214
+ let e = 0, s = n.length - 1;
1215
+ for (; e < s; ) {
1216
+ const i = e + s >> 1;
1217
+ n[i] > t ? s = i : e = i + 1;
1218
+ }
1219
+ return n[e];
1220
+ }
1221
+ function ot(t, n, e, s, i, o) {
1222
+ if (Math.floor(s / o) >= Math.floor(i / o))
1223
+ return;
1224
+ const r = t[s + i >> 1];
1225
+ let l = s - 1, u = i + 1;
1226
+ for (; ; ) {
1227
+ do
1228
+ l++;
1229
+ while (t[l] < r);
1230
+ do
1231
+ u--;
1232
+ while (t[u] > r);
1233
+ if (l >= u)
1234
+ break;
1235
+ Hn(t, n, e, l, u);
1236
+ }
1237
+ ot(t, n, e, s, u, o), ot(t, n, e, u + 1, i, o);
1238
+ }
1239
+ function Hn(t, n, e, s, i) {
1240
+ const o = t[s];
1241
+ t[s] = t[i], t[i] = o;
1242
+ const r = 4 * s, l = 4 * i, u = n[r], a = n[r + 1], f = n[r + 2], c = n[r + 3];
1243
+ n[r] = n[l], n[r + 1] = n[l + 1], n[r + 2] = n[l + 2], n[r + 3] = n[l + 3], n[l] = u, n[l + 1] = a, n[l + 2] = f, n[l + 3] = c;
1244
+ const h = e[s];
1245
+ e[s] = e[i], e[i] = h;
1246
+ }
1247
+ function Xn(t, n) {
1248
+ let e = t ^ n, s = 65535 ^ e, i = 65535 ^ (t | n), o = t & (n ^ 65535), r = e | s >> 1, l = e >> 1 ^ e, u = i >> 1 ^ s & o >> 1 ^ i, a = e & i >> 1 ^ o >> 1 ^ o;
1249
+ e = r, s = l, i = u, o = a, r = e & e >> 2 ^ s & s >> 2, l = e & s >> 2 ^ s & (e ^ s) >> 2, u ^= e & i >> 2 ^ s & o >> 2, a ^= s & i >> 2 ^ (e ^ s) & o >> 2, e = r, s = l, i = u, o = a, r = e & e >> 4 ^ s & s >> 4, l = e & s >> 4 ^ s & (e ^ s) >> 4, u ^= e & i >> 4 ^ s & o >> 4, a ^= s & i >> 4 ^ (e ^ s) & o >> 4, e = r, s = l, i = u, o = a, u ^= e & i >> 8 ^ s & o >> 8, a ^= s & i >> 8 ^ (e ^ s) & o >> 8, e = u ^ u >> 1, s = a ^ a >> 1;
1250
+ let f = t ^ n, c = s | 65535 ^ (f | e);
1251
+ return f = (f | f << 8) & 16711935, f = (f | f << 4) & 252645135, f = (f | f << 2) & 858993459, f = (f | f << 1) & 1431655765, c = (c | c << 8) & 16711935, c = (c | c << 4) & 252645135, c = (c | c << 2) & 858993459, c = (c | c << 1) & 1431655765, (c << 1 | f) >>> 0;
1252
+ }
1253
+ function Ht(t, n = 1e-7) {
1254
+ if (t.length === 0)
1255
+ return [];
1256
+ if (t.length === 1)
1257
+ return [t];
1258
+ const e = new at(t.length);
1259
+ t.forEach((o) => {
1260
+ const [r, l] = o.firstPoint;
1261
+ e.add(r - n, l - n, r + n, l + n);
1262
+ }), e.finish();
1263
+ const s = [], i = /* @__PURE__ */ new Set();
1264
+ return t.forEach((o, r) => {
1265
+ if (i.has(r))
1266
+ return;
1267
+ const l = [o];
1268
+ let u = r;
1269
+ i.add(r);
1270
+ let a = t.length;
1271
+ for (; ; ) {
1272
+ if (a-- < 0)
1273
+ throw new Error("Infinite loop detected");
1274
+ const f = l[l.length - 1].lastPoint, [c, h] = f, p = e.search(
1275
+ c - n,
1276
+ h - n,
1277
+ c + n,
1278
+ h + n
1279
+ ), d = (x) => Math.abs((u - x) % t.length), m = p.filter((x) => !i.has(x)).map((x) => [
1280
+ t[x],
1281
+ x,
1282
+ d(x)
1283
+ ]).sort(([, , x], [, , E]) => d(x) - d(E));
1284
+ if (m.length === 0) {
1285
+ s.push(l);
1286
+ break;
1287
+ }
1288
+ const [P, w] = m[0];
1289
+ l.push(P), i.add(w), u = w;
1290
+ }
1291
+ }), s;
1292
+ }
1293
+ class v extends lt {
1294
+ constructor(e, s = [], { ignoreChecks: i = !1 } = {}) {
1295
+ super();
1296
+ C(this, "contour");
1297
+ C(this, "holes");
1298
+ i || Gn(e, s), this.contour = e, this.holes = s;
1299
+ }
1300
+ get boundingBox() {
1301
+ return this.contour.boundingBox;
1302
+ }
1303
+ get isFull() {
1304
+ return this.holes.length === 0;
1305
+ }
1306
+ get allLoops() {
1307
+ return [this.contour, ...this.holes];
1308
+ }
1309
+ clone() {
1310
+ return new v(
1311
+ this.contour.clone(),
1312
+ this.holes.map((e) => e.clone())
1313
+ );
1314
+ }
1315
+ transform(e) {
1316
+ return new v(
1317
+ this.contour.transform(e),
1318
+ this.holes.map((s) => s.transform(e))
1319
+ );
1320
+ }
1321
+ contains(e) {
1322
+ return this.contour.contains(e) && !this.holes.some((s) => s.contains(e));
1323
+ }
1324
+ intersects(e) {
1325
+ return this.allLoops.some(
1326
+ (s) => e.allLoops.some((i) => s.intersects(i))
1327
+ );
1328
+ }
1329
+ overlappingStrands(e) {
1330
+ const s = e instanceof v ? e.allLoops : [e], i = this.allLoops.flatMap((o) => s.flatMap((r) => o.overlappingSegments(r)));
1331
+ return Ht(i).map((o) => new B(o));
1332
+ }
1333
+ }
1334
+ function Gn(t, n = []) {
1335
+ if (!t)
1336
+ throw new Error("Figure must have a contour");
1337
+ for (const [e, s] of st([t, ...n]))
1338
+ if (e.intersects(s))
1339
+ throw new Error("Loops in a figure must not intersect");
1340
+ if (n.some(
1341
+ (e) => !t.contains(e.firstPoint) && !t.onStroke(e.firstPoint)
1342
+ ))
1343
+ throw new Error("Holes must be inside the contour");
1344
+ for (const [e, s] of st(n))
1345
+ if (e.contains(s.firstPoint))
1346
+ throw console.error(Mt(e), Mt(s)), new Error("Holes must not be inside other holes");
1347
+ }
1348
+ const Qn = (t) => {
1349
+ const n = t.map((i, o) => t.slice(o + 1).map((r, l) => [l + o + 1, r]).filter(([, r]) => i.boundingBox.overlaps(r.boundingBox)).map(([r]) => r)), e = [], s = Array(n.length);
1350
+ return n.forEach((i, o) => {
1351
+ let r = s[o];
1352
+ r || (r = [], e.push(r)), r.push(t[o]), i.length && i.forEach((l) => {
1353
+ s[l] = r;
1354
+ });
1355
+ }), e;
1356
+ }, Xt = (t) => t.map((n, e) => {
1357
+ const i = n.segments[0].midPoint, o = t.filter((r, l) => e === l ? !1 : r.contains(i));
1358
+ return {
1359
+ loop: n,
1360
+ isIn: o
1361
+ };
1362
+ }), Wn = (t, n) => t.flatMap(({ loop: e }) => ft(
1363
+ n.filter(
1364
+ ({ loop: s, isIn: i }) => s === e || i.indexOf(e) !== -1
1365
+ )
1366
+ )), Jn = (t, n) => {
1367
+ const e = n.filter(({ isIn: i }) => i.length <= 1), s = ft(
1368
+ Xt(t.map(({ loop: i }) => i))
1369
+ );
1370
+ return [e, ...s];
1371
+ }, ft = (t) => {
1372
+ if (!t.length)
1373
+ return [];
1374
+ const n = t.filter(({ isIn: s }) => !s.length), e = t.filter(({ isIn: s }) => s.length > 1);
1375
+ return n.length === 1 && e.length === 0 ? [t] : n.length > 1 ? Wn(n, t) : Jn(e, t);
1376
+ };
1377
+ function X(t) {
1378
+ return Qn(t).map(Xt).flatMap(ft).map((e) => {
1379
+ if (e.length === 1)
1380
+ return new v(e[0].loop);
1381
+ e.sort((o, r) => o.isIn.length - r.isIn.length);
1382
+ const [s, ...i] = e.map(({ loop: o }) => o);
1383
+ return new v(s, i);
1384
+ });
1385
+ }
1386
+ function Kn(t, n) {
1387
+ const e = [];
1388
+ for (const s of t)
1389
+ for (const i of n)
1390
+ e.push([s, i]);
1391
+ return e;
1392
+ }
1393
+ function* Et(t, n, e) {
1394
+ const s = (r) => n.some((l) => g(l, r.lastPoint)), i = (r) => e.some((l) => r.isSame(l));
1395
+ let o = [];
1396
+ for (const r of t)
1397
+ s(r) ? (o.push(r), yield new B(o, { ignoreChecks: !0 }), o = []) : i(r) ? (o.length && (yield new B(o, { ignoreChecks: !0 }), o = []), yield new B([r], { ignoreChecks: !0 })) : o.push(r);
1398
+ o.length && (yield new B(o, { ignoreChecks: !0 }));
1399
+ }
1400
+ const vt = (t, n) => {
1401
+ const e = t.findIndex((o) => g(n, o.firstPoint)), s = t.slice(0, e);
1402
+ return t.slice(e).concat(s);
1403
+ }, Bt = (t, n) => {
1404
+ let e = t;
1405
+ const s = (l) => g(l.firstPoint, n.firstPoint) && g(l.lastPoint, n.lastPoint);
1406
+ let i = t.findIndex(s);
1407
+ if (i === -1) {
1408
+ const l = t.map((u) => u.reverse());
1409
+ if (l.reverse(), i = l.findIndex(s), i === -1)
1410
+ throw console.error(
1411
+ l.map((u) => u.repr),
1412
+ n.repr
1413
+ ), new Error("Failed to rotate to segment start");
1414
+ e = l;
1415
+ }
1416
+ const o = e.slice(0, i);
1417
+ return e.slice(i).concat(o);
1418
+ };
1419
+ function Zn(t, n, e) {
1420
+ return t.filter((s) => {
1421
+ const i = n.filter((l) => g(l.firstPoint, s) || g(l.lastPoint, s));
1422
+ if (i.length % 2)
1423
+ throw new Error("Bug in the intersection algo on non crossing point");
1424
+ const o = i.map((l) => e.contains(l.midPoint));
1425
+ return !(o.every((l) => l) || !o.some((l) => l));
1426
+ });
1427
+ }
1428
+ function te(t, n, e) {
1429
+ let s = [];
1430
+ const i = [], o = new Array(t.segments.length).fill(0).map(() => []), r = new Array(n.segments.length).fill(0).map(() => []);
1431
+ if (t.segments.forEach((h, p) => {
1432
+ n.segments.forEach((d, m) => {
1433
+ const { intersections: P, overlaps: w } = K(
1434
+ h,
1435
+ d,
1436
+ e
1437
+ );
1438
+ s.push(...P), o[p].push(...P), r[m].push(...P), i.push(...w);
1439
+ const x = w.flatMap((E) => [
1440
+ E.firstPoint,
1441
+ E.lastPoint
1442
+ ]);
1443
+ s.push(...x), o[p].push(...x), r[m].push(...x);
1444
+ });
1445
+ }), s = U(s, e), !s.length || s.length === 1)
1446
+ return null;
1447
+ const l = ([h, p]) => p.length ? h.splitAt(p) : [h];
1448
+ let u = N([t.segments, o]).flatMap(l), a = N([n.segments, r]).flatMap(l);
1449
+ if (s = Zn(
1450
+ s,
1451
+ u,
1452
+ n
1453
+ ), !s.length && !i.length)
1454
+ return null;
1455
+ if (i.length) {
1456
+ const h = i[0];
1457
+ u = Bt(
1458
+ u,
1459
+ h
1460
+ ), a = Bt(
1461
+ a,
1462
+ h
1463
+ );
1464
+ } else {
1465
+ const h = s[0];
1466
+ u = vt(u, h), a = vt(a, h);
1467
+ }
1468
+ let f = Array.from(
1469
+ Et(
1470
+ u,
1471
+ s,
1472
+ i
1473
+ )
1474
+ ), c = Array.from(
1475
+ Et(
1476
+ a,
1477
+ s,
1478
+ i
1479
+ )
1480
+ );
1481
+ return (!g(
1482
+ c[0].lastPoint,
1483
+ f[0].lastPoint
1484
+ ) || i.length > 0 && c[0].segmentsCount !== 1) && (c = c.map((h) => h.reverse()).reverse(), g(c[0].lastPoint, f[0].lastPoint) || (f = f.map((h) => h.reverse()).reverse())), N([f, c]).map(([h, p]) => h.segmentsCount === 1 && i.some((d) => h.segments[0].isSame(d)) ? [h, "same"] : [h, p]);
1485
+ }
1486
+ function kt(t) {
1487
+ let n = t[0];
1488
+ for (const e of t.slice(1))
1489
+ n = n.extend(e);
1490
+ if (!g(n.firstPoint, n.lastPoint))
1491
+ throw console.error(
1492
+ dt(n.firstPoint),
1493
+ dt(n.lastPoint)
1494
+ ), new Error("Bug in the intersection algo on non closing strand");
1495
+ return new O(n.segments);
1496
+ }
1497
+ function ne(t, n) {
1498
+ const e = N([
1499
+ n.slice(0, -1),
1500
+ n.slice(1)
1501
+ ]).map(([i, o]) => kt(t.slice(i, o)));
1502
+ let s = t.slice(
1503
+ n[n.length - 1]
1504
+ );
1505
+ return n[0] !== 0 && (s = s.concat(t.slice(0, n[0]))), e.push(kt(s)), e;
1506
+ }
1507
+ function ee(t) {
1508
+ if (!t.length)
1509
+ return [];
1510
+ const n = t.map((i) => i.firstPoint);
1511
+ let e = t.map((i) => i.lastPoint);
1512
+ e = e.slice(-1).concat(e.slice(0, -1));
1513
+ const s = N([n, e]).flatMap(
1514
+ ([i, o], r) => g(i, o) ? [] : r
1515
+ );
1516
+ try {
1517
+ return ne(t, s);
1518
+ } catch {
1519
+ return Ht(t.flatMap((o) => o.segments)).filter((o) => o.length > 1).filter((o) => g(o[0].firstPoint, o.at(-1).lastPoint)).map((o) => new O(o));
1520
+ }
1521
+ }
1522
+ const _t = (t, n) => {
1523
+ if (t.length === 0)
1524
+ return [n];
1525
+ const e = t.at(-1);
1526
+ return g(e.lastPoint, n.firstPoint) ? t.slice(0, -1).concat([e.extend(n)]) : g(e.lastPoint, n.lastPoint) ? t.slice(0, -1).concat([e.extend(n.reverse())]) : t.concat([n]);
1527
+ }, se = (t, n) => t.length === 0 ? [n] : g(t[0].firstPoint, n.lastPoint) ? [n.extend(t[0])].concat(t.slice(1)) : [n].concat(t);
1528
+ function ht(t, n, {
1529
+ firstInside: e,
1530
+ secondInside: s
1531
+ }) {
1532
+ const i = te(t, n);
1533
+ if (!i) {
1534
+ const u = t.segments[0].midPoint, a = n.contains(u), f = n.segments[0].midPoint, c = t.contains(f);
1535
+ return {
1536
+ identical: !1,
1537
+ firstCurveInSecond: a,
1538
+ secondCurveInFirst: c
1539
+ };
1540
+ }
1541
+ if (i.every(([, u]) => u === "same"))
1542
+ return { identical: !0 };
1543
+ let o = null, r = null;
1544
+ const l = i.flatMap(([u, a]) => {
1545
+ let f = [], c = 0;
1546
+ if (a === "same")
1547
+ return r === 1 ? (r = 1, u) : r === 2 || r === 0 ? (r = null, []) : r === null ? (o ? o = o.extend(u) : o = u, []) : (console.error("weird situation"), []);
1548
+ const h = u.segments[0].midPoint, p = n.contains(h);
1549
+ (e === "keep" && p || e === "remove" && !p) && (c += 1, f = _t(f, u));
1550
+ const d = a.segments[0].midPoint, m = t.contains(d);
1551
+ if (s === "keep" && m || s === "remove" && !m) {
1552
+ const P = a;
1553
+ c += 1, c === 2 && f.length ? (f = _t(f, P), o = null) : f = [P];
1554
+ }
1555
+ return r === null && c === 1 && o && (f = se(f, o)), c === 1 && (r = c, o = null), f.length ? f : (o = null, []);
1556
+ });
1557
+ return ee(l);
1558
+ }
1559
+ const ie = (t, n) => {
1560
+ const e = ht(t, n, {
1561
+ firstInside: "remove",
1562
+ secondInside: "remove"
1563
+ });
1564
+ return Array.isArray(e) ? e : e.identical ? [t] : e.firstCurveInSecond ? [n] : e.secondCurveInFirst ? [t] : [t, n];
1565
+ }, Z = (t, n) => {
1566
+ const e = ht(t, n, {
1567
+ firstInside: "remove",
1568
+ secondInside: "keep"
1569
+ });
1570
+ return Array.isArray(e) ? e : e.identical ? [] : e.firstCurveInSecond ? [] : e.secondCurveInFirst ? [t, n] : [t];
1571
+ }, pt = (t, n) => {
1572
+ const e = ht(t, n, {
1573
+ firstInside: "keep",
1574
+ secondInside: "keep"
1575
+ });
1576
+ return Array.isArray(e) ? e : e.identical ? [t] : e.firstCurveInSecond ? [t] : e.secondCurveInFirst ? [n] : [];
1577
+ };
1578
+ function oe(t) {
1579
+ const n = /* @__PURE__ */ new Map(), e = [];
1580
+ return t.forEach((s, i) => {
1581
+ let o;
1582
+ n.has(i) ? o = n.get(i) : (o = { current: [s], fusedWith: /* @__PURE__ */ new Set([i]) }, e.push(o)), t.slice(i + 1).forEach((r, l) => {
1583
+ const u = o.current, a = i + l + 1;
1584
+ if (o.fusedWith.has(a))
1585
+ return;
1586
+ let f = [r], c = !1;
1587
+ if (n.has(a) && (f = n.get(a).current, c = !0), !u.some(
1588
+ (d) => f.some((m) => d.intersects(m))
1589
+ ))
1590
+ return;
1591
+ let p;
1592
+ u.length > 1 || f.length > 1 ? p = G(u, f) : p = Gt(u[0], f[0]), o.fusedWith.add(a), o.current = p, c || n.set(a, o);
1593
+ });
1594
+ }), e.flatMap(({ current: s }) => s);
1595
+ }
1596
+ function Gt(t, n) {
1597
+ const e = ie(t.contour, n.contour), s = n.holes.flatMap((r) => Z(r, t.contour)), i = t.holes.flatMap((r) => Z(r, n.contour)), o = Kn(t.holes, n.holes).flatMap(
1598
+ ([r, l]) => pt(r, l)
1599
+ );
1600
+ return X([
1601
+ ...e,
1602
+ ...s,
1603
+ ...i,
1604
+ ...o
1605
+ ]);
1606
+ }
1607
+ function tt(t, n) {
1608
+ if (t.isFull && n.isFull)
1609
+ return X(Z(t.contour, n.contour));
1610
+ if (t.isFull) {
1611
+ const s = Z(t.contour, n.contour), i = n.holes.flatMap(
1612
+ (o) => pt(o, t.contour)
1613
+ );
1614
+ return X([...s, ...i]);
1615
+ } else if (n.isFull && !t.contour.intersects(n.contour))
1616
+ if (t.contour.contains(n.contour.firstPoint)) {
1617
+ const s = G(
1618
+ t.holes.map((i) => new v(i)),
1619
+ [n]
1620
+ );
1621
+ return X([
1622
+ t.contour,
1623
+ ...s.flatMap((i) => i.allLoops)
1624
+ ]);
1625
+ } else
1626
+ return [t];
1627
+ let e = tt(new v(t.contour), n);
1628
+ return t.holes.forEach((s) => {
1629
+ e = e.flatMap((i) => tt(i, new v(s)));
1630
+ }), e;
1631
+ }
1632
+ function re(t, n) {
1633
+ const e = pt(t.contour, n.contour);
1634
+ if (!e.length)
1635
+ return [];
1636
+ let s = X(e);
1637
+ return s = Q(
1638
+ s,
1639
+ t.holes.map((i) => new v(i))
1640
+ ), Q(
1641
+ s,
1642
+ n.holes.map((i) => new v(i))
1643
+ );
1644
+ }
1645
+ function G(t, n) {
1646
+ if (!t.length)
1647
+ return n;
1648
+ if (!n.length)
1649
+ return t;
1650
+ if (t.length === 1 && n.length > 1 || n.length === 1 && t.length > 1)
1651
+ return oe([...t, ...n]);
1652
+ if (t.length > 1 && n.length > 1) {
1653
+ let e = G([t[0]], n);
1654
+ return t.slice(1).forEach((s) => {
1655
+ e = G([s], e);
1656
+ }), e;
1657
+ }
1658
+ return t.length === 1 && n.length === 1 ? Gt(t[0], n[0]) : [];
1659
+ }
1660
+ function Q(t, n) {
1661
+ if (!t.length)
1662
+ return [];
1663
+ if (!n.length)
1664
+ return t;
1665
+ if (t.length === 1 && n.length === 1)
1666
+ return tt(t[0], n[0]);
1667
+ if (t.length > 1)
1668
+ return t.flatMap((s) => Q([s], n));
1669
+ let e = tt(t[0], n[0]);
1670
+ return n.slice(1).forEach((s) => {
1671
+ e = Q(e, [s]);
1672
+ }), e;
1673
+ }
1674
+ function rt(t, n) {
1675
+ return !t.length || !n.length ? [] : t.length === 1 && n.length === 1 ? re(t[0], n[0]) : t.length > 1 ? t.flatMap((e) => rt([e], n)) : n.flatMap((e) => rt(t, [e]));
1676
+ }
1677
+ class _ extends lt {
1678
+ constructor(e = [], { ignoreChecks: s = !1 } = {}) {
1679
+ super();
1680
+ C(this, "figures");
1681
+ C(this, "_boundingBox", null);
1682
+ s || le(e), this.figures = e;
1683
+ }
1684
+ get isEmpty() {
1685
+ return this.figures.length === 0;
1686
+ }
1687
+ get boundingBox() {
1688
+ if (this.isEmpty)
1689
+ return new hn();
1690
+ if (this._boundingBox === null) {
1691
+ let e = this.figures[0].boundingBox;
1692
+ for (const s of this.figures.slice(1))
1693
+ e = e.merge(s.boundingBox);
1694
+ this._boundingBox = e;
1695
+ }
1696
+ return this._boundingBox;
1697
+ }
1698
+ clone() {
1699
+ return new _(this.figures.map((e) => e.clone()));
1700
+ }
1701
+ transform(e) {
1702
+ return new _(this.figures.map((s) => s.transform(e)));
1703
+ }
1704
+ contains(e) {
1705
+ return this.figures.some((s) => s.contains(e));
1706
+ }
1707
+ intersects(e) {
1708
+ return this.figures.some(
1709
+ (s) => e.figures.some((i) => s.intersects(i))
1710
+ );
1711
+ }
1712
+ overlappingStrands(e) {
1713
+ return this.figures.flatMap((s) => e instanceof _ ? e.figures.flatMap(
1714
+ (i) => s.overlappingStrands(i)
1715
+ ) : s.overlappingStrands(e));
1716
+ }
1717
+ fuse(e) {
1718
+ return new _(G(this.figures, e.figures));
1719
+ }
1720
+ cut(e) {
1721
+ return new _(Q(this.figures, e.figures));
1722
+ }
1723
+ intersect(e) {
1724
+ return new _(rt(this.figures, e.figures));
1725
+ }
1726
+ }
1727
+ function le(t) {
1728
+ for (const [n, e] of st(t))
1729
+ if (n.intersects(e))
1730
+ throw new Error("Diagram figures must not intersect");
1731
+ }
1732
+ export {
1733
+ _ as D,
1734
+ v as F,
1735
+ O as L,
1736
+ B as S,
1737
+ G as a,
1738
+ qt as b,
1739
+ Q as c,
1740
+ Ht as d,
1741
+ jn as e,
1742
+ K as f,
1743
+ Mt as g,
1744
+ ae as h,
1745
+ rt as i,
1746
+ J as l,
1747
+ pn as p,
1748
+ Et as s
1749
+ };
1750
+ //# sourceMappingURL=Diagram-2450b2e6.js.map