pantograph2d 0.7.0 → 0.8.1

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