msdfgen-ts 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,116 +1,116 @@
1
- function io(e, n, t, s) {
2
- return e * t + n * s;
3
- }
4
- function J(e, n, t, s) {
5
- return e * s - n * t;
6
- }
7
- function eo(e, n, t) {
8
- return (1 - t) * e + t * n;
9
- }
10
- function rt(e) {
11
- return +(e > 0) - +(e < 0);
12
- }
13
- function Dt(e) {
14
- return 2 * +(e > 0) - 1;
15
- }
16
- function $s(e, n, t, s) {
17
- if (n === 0 || Math.abs(t) > 1e12 * Math.abs(n))
18
- return t === 0 ? s === 0 ? -1 : 0 : (e[0] = -s / t, 1);
19
- const i = t * t - 4 * n * s;
20
- if (i > 0) {
21
- const o = Math.sqrt(i);
22
- return e[0] = (-t + o) / (2 * n), e[1] = (-t - o) / (2 * n), 2;
23
- } else if (i === 0)
24
- return e[0] = -t / (2 * n), 1;
1
+ function Ko(s, t, n, o) {
2
+ return s * n + t * o;
3
+ }
4
+ function K(s, t, n, o) {
5
+ return s * o - t * n;
6
+ }
7
+ function Po(s, t, n) {
8
+ return (1 - n) * s + n * t;
9
+ }
10
+ function ft(s) {
11
+ return +(s > 0) - +(s < 0);
12
+ }
13
+ function St(s) {
14
+ return 2 * +(s > 0) - 1;
15
+ }
16
+ function $o(s, t, n, o) {
17
+ if (t === 0 || Math.abs(n) > 1e12 * Math.abs(t))
18
+ return n === 0 ? o === 0 ? -1 : 0 : (s[0] = -o / n, 1);
19
+ const e = n * n - 4 * t * o;
20
+ if (e > 0) {
21
+ const i = Math.sqrt(e);
22
+ return s[0] = (-n + i) / (2 * t), s[1] = (-n - i) / (2 * t), 2;
23
+ } else if (e === 0)
24
+ return s[0] = -n / (2 * t), 1;
25
25
  return 0;
26
26
  }
27
- function co(e, n, t, s) {
28
- const i = n * n, o = 1 / 9 * (i - 3 * t), p = 1 / 54 * (n * (2 * i - 9 * t) + 27 * s), c = p * p, r = o * o * o, h = n * (1 / 3);
29
- if (c < r) {
30
- let l = p / Math.sqrt(r);
31
- l < -1 && (l = -1), l > 1 && (l = 1), l = Math.acos(l);
32
- const a = -2 * Math.sqrt(o);
33
- return e[0] = a * Math.cos(1 / 3 * l) - h, e[1] = a * Math.cos(1 / 3 * (l + 2 * Math.PI)) - h, e[2] = a * Math.cos(1 / 3 * (l - 2 * Math.PI)) - h, 3;
27
+ function Zo(s, t, n, o) {
28
+ const e = t * t, i = 1 / 9 * (e - 3 * n), r = 1 / 54 * (t * (2 * e - 9 * n) + 27 * o), c = r * r, a = i * i * i, l = t * (1 / 3);
29
+ if (c < a) {
30
+ let h = r / Math.sqrt(a);
31
+ h < -1 && (h = -1), h > 1 && (h = 1), h = Math.acos(h);
32
+ const p = -2 * Math.sqrt(i);
33
+ return s[0] = p * Math.cos(1 / 3 * h) - l, s[1] = p * Math.cos(1 / 3 * (h + 2 * Math.PI)) - l, s[2] = p * Math.cos(1 / 3 * (h - 2 * Math.PI)) - l, 3;
34
34
  } else {
35
- const l = (p < 0 ? 1 : -1) * Math.pow(Math.abs(p) + Math.sqrt(c - r), 0.3333333333333333), a = l === 0 ? 0 : o / l;
36
- return e[0] = l + a - h, l === a || Math.abs(l - a) < 1e-12 * Math.abs(l + a) ? (e[1] = -0.5 * (l + a) - h, 2) : 1;
37
- }
38
- }
39
- function ro(e, n, t, s, i) {
40
- if (n !== 0) {
41
- const o = t / n;
42
- if (Math.abs(o) < 1e6)
43
- return co(e, o, s / n, i / n);
44
- }
45
- return $s(e, t, s, i);
46
- }
47
- const ao = 24;
48
- function Gt(e, n, t, s) {
49
- return ((s + e) * s + n) * s + t;
50
- }
51
- function ho(e, n, t, s, i, o, p) {
52
- const c = o < 0;
53
- let r = s - o * (i - s) / (p - o);
54
- r > s && r < i || (r = 0.5 * (s + i));
55
- for (let h = 0; h < ao; h++) {
56
- const l = Gt(e, n, t, r);
57
- if (l === 0) return r;
58
- l < 0 === c ? s = r : i = r;
59
- const a = (3 * r + 2 * e) * r + n;
60
- let f = r - l / a;
61
- f > s && f < i || (f = 0.5 * (s + i));
62
- const y = f - r;
63
- if (r = f, (y < 0 ? -y : y) <= 1e-15 * (r < 0 ? -r : r)) break;
64
- }
65
- return r;
66
- }
67
- function Bt(e, n, t, s, i, o, p, c, r) {
68
- return o === 0 ? c[r++] = s : o < 0 != p < 0 && (c[r++] = ho(e, n, t, s, i, o, p)), r;
69
- }
70
- function po(e, n, t, s, i, o) {
71
- let p = 0;
72
- if (e === 0) {
73
- if (n === 0) return 0;
74
- const f = -t / n;
75
- return f >= s && f <= i && (o[p++] = f), p;
76
- }
77
- const c = n * n - 4 * e * t;
35
+ const h = (r < 0 ? 1 : -1) * Math.pow(Math.abs(r) + Math.sqrt(c - a), 0.3333333333333333), p = h === 0 ? 0 : i / h;
36
+ return s[0] = h + p - l, h === p || Math.abs(h - p) < 1e-12 * Math.abs(h + p) ? (s[1] = -0.5 * (h + p) - l, 2) : 1;
37
+ }
38
+ }
39
+ function Jo(s, t, n, o, e) {
40
+ if (t !== 0) {
41
+ const i = n / t;
42
+ if (Math.abs(i) < 1e6)
43
+ return Zo(s, i, o / t, e / t);
44
+ }
45
+ return $o(s, n, o, e);
46
+ }
47
+ const te = 24;
48
+ function Qt(s, t, n, o) {
49
+ return ((o + s) * o + t) * o + n;
50
+ }
51
+ function ne(s, t, n, o, e, i, r) {
52
+ const c = i < 0;
53
+ let a = o - i * (e - o) / (r - i);
54
+ a > o && a < e || (a = 0.5 * (o + e));
55
+ for (let l = 0; l < te; l++) {
56
+ const h = Qt(s, t, n, a);
57
+ if (h === 0) return a;
58
+ h < 0 === c ? o = a : e = a;
59
+ const p = (3 * a + 2 * s) * a + t;
60
+ let f = a - h / p;
61
+ f > o && f < e || (f = 0.5 * (o + e));
62
+ const u = f - a;
63
+ if (a = f, (u < 0 ? -u : u) <= 1e-15 * (a < 0 ? -a : a)) break;
64
+ }
65
+ return a;
66
+ }
67
+ function fn(s, t, n, o, e, i, r, c, a) {
68
+ return i === 0 ? c[a++] = o : i < 0 != r < 0 && (c[a++] = ne(s, t, n, o, e, i, r)), a;
69
+ }
70
+ function se(s, t, n, o, e, i) {
71
+ let r = 0;
72
+ if (s === 0) {
73
+ if (t === 0) return 0;
74
+ const f = -n / t;
75
+ return f >= o && f <= e && (i[r++] = f), r;
76
+ }
77
+ const c = t * t - 4 * s * n;
78
78
  if (c < 0) return 0;
79
- const r = Math.sqrt(c), h = -0.5 * (n + (n < 0 ? -r : r));
80
- let l, a;
81
- if (h === 0)
82
- l = 0, a = 0;
83
- else if (l = h / e, a = t / h, l > a) {
84
- const f = l;
85
- l = a, a = f;
86
- }
87
- return l >= s && l <= i && (o[p++] = l), a !== l && a >= s && a <= i && (o[p++] = a), p;
88
- }
89
- function lo(e, n, t, s, i, o, p) {
90
- if (e === 0) return po(n, t, s, i, o, p);
91
- const c = 1 / e;
92
- n *= c, t *= c, s *= c;
93
- const r = Gt(n, t, s, i), h = Gt(n, t, s, o), l = n * n - 3 * t;
94
- let a = 0;
95
- if (l <= 0)
96
- a = Bt(n, t, s, i, o, r, h, p, 0);
79
+ const a = Math.sqrt(c), l = -0.5 * (t + (t < 0 ? -a : a));
80
+ let h, p;
81
+ if (l === 0)
82
+ h = 0, p = 0;
83
+ else if (h = l / s, p = n / l, h > p) {
84
+ const f = h;
85
+ h = p, p = f;
86
+ }
87
+ return h >= o && h <= e && (i[r++] = h), p !== h && p >= o && p <= e && (i[r++] = p), r;
88
+ }
89
+ function oe(s, t, n, o, e, i, r) {
90
+ if (s === 0) return se(t, n, o, e, i, r);
91
+ const c = 1 / s;
92
+ t *= c, n *= c, o *= c;
93
+ const a = Qt(t, n, o, e), l = Qt(t, n, o, i), h = t * t - 3 * n;
94
+ let p = 0;
95
+ if (h <= 0)
96
+ p = fn(t, n, o, e, i, a, l, r, 0);
97
97
  else {
98
- const f = Math.sqrt(l) / 3, y = -n / 3, _ = y - f, u = y + f;
99
- let x = i, M = r;
100
- if (_ > i && _ < o) {
101
- const w = Gt(n, t, s, _);
102
- a = Bt(n, t, s, x, _, M, w, p, a), x = _, M = w;
98
+ const f = Math.sqrt(h) / 3, u = -t / 3, y = u - f, x = u + f;
99
+ let g = e, M = a;
100
+ if (y > e && y < i) {
101
+ const b = Qt(t, n, o, y);
102
+ p = fn(t, n, o, g, y, M, b, r, p), g = y, M = b;
103
103
  }
104
- if (u > i && u < o) {
105
- const w = Gt(n, t, s, u);
106
- a = Bt(n, t, s, x, u, M, w, p, a), x = u, M = w;
104
+ if (x > e && x < i) {
105
+ const b = Qt(t, n, o, x);
106
+ p = fn(t, n, o, g, x, M, b, r, p), g = x, M = b;
107
107
  }
108
- a = Bt(n, t, s, x, o, M, h, p, a);
108
+ p = fn(t, n, o, g, i, M, l, r, p);
109
109
  }
110
- return h === 0 && (p[a++] = o), a;
110
+ return l === 0 && (r[p++] = i), p;
111
111
  }
112
- const at = 0, it = 1, Ot = 2, Rs = 4, fo = 4, U = [0, 0, 0];
113
- class et {
112
+ const nt = 0, ct = 1, Ct = 2, co = 4, ee = 4, B = [0, 0, 0];
113
+ class st {
114
114
  /**
115
115
  * @param type Segment type (LINEAR=0, QUADRATIC=1, CUBIC=2).
116
116
  * @param p0x Start x.
@@ -122,15 +122,15 @@ class et {
122
122
  * @param p3x CUBIC: end x. Others: 0.
123
123
  * @param p3y CUBIC: end y. Others: 0.
124
124
  */
125
- constructor(n, t, s, i, o, p, c, r, h) {
126
- this.type = n, this.p0x = t, this.p0y = s, this.p1x = i, this.p1y = o, this.p2x = p, this.p2y = c, this.p3x = r, this.p3y = h, this.color = 7;
125
+ constructor(t, n, o, e, i, r, c, a, l) {
126
+ this.type = t, this.p0x = n, this.p0y = o, this.p1x = e, this.p1y = i, this.p2x = r, this.p2y = c, this.p3x = a, this.p3y = l, this.color = 7;
127
127
  }
128
128
  /** Endpoint x (the on-curve destination of this segment). */
129
129
  endX() {
130
130
  switch (this.type) {
131
- case at:
131
+ case nt:
132
132
  return this.p1x;
133
- case it:
133
+ case ct:
134
134
  return this.p2x;
135
135
  default:
136
136
  return this.p3x;
@@ -139,9 +139,9 @@ class et {
139
139
  /** Endpoint y. */
140
140
  endY() {
141
141
  switch (this.type) {
142
- case at:
142
+ case nt:
143
143
  return this.p1y;
144
- case it:
144
+ case ct:
145
145
  return this.p2y;
146
146
  default:
147
147
  return this.p3y;
@@ -154,21 +154,21 @@ class et {
154
154
  * @param param Parameter t.
155
155
  * @param out Two-element array [x, y] to write into (reuse to avoid allocation).
156
156
  */
157
- point(n, t) {
158
- const s = n;
157
+ point(t, n) {
158
+ const o = t;
159
159
  switch (this.type) {
160
- case at: {
161
- t[0] = this.p0x + s * (this.p1x - this.p0x), t[1] = this.p0y + s * (this.p1y - this.p0y);
160
+ case nt: {
161
+ n[0] = this.p0x + o * (this.p1x - this.p0x), n[1] = this.p0y + o * (this.p1y - this.p0y);
162
162
  return;
163
163
  }
164
- case it: {
165
- const i = this.p0x + s * (this.p1x - this.p0x), o = this.p0y + s * (this.p1y - this.p0y), p = this.p1x + s * (this.p2x - this.p1x), c = this.p1y + s * (this.p2y - this.p1y);
166
- t[0] = i + s * (p - i), t[1] = o + s * (c - o);
164
+ case ct: {
165
+ const e = this.p0x + o * (this.p1x - this.p0x), i = this.p0y + o * (this.p1y - this.p0y), r = this.p1x + o * (this.p2x - this.p1x), c = this.p1y + o * (this.p2y - this.p1y);
166
+ n[0] = e + o * (r - e), n[1] = i + o * (c - i);
167
167
  return;
168
168
  }
169
169
  default: {
170
- const i = this.p0x + s * (this.p1x - this.p0x), o = this.p0y + s * (this.p1y - this.p0y), p = this.p1x + s * (this.p2x - this.p1x), c = this.p1y + s * (this.p2y - this.p1y), r = this.p2x + s * (this.p3x - this.p2x), h = this.p2y + s * (this.p3y - this.p2y), l = i + s * (p - i), a = o + s * (c - o), f = p + s * (r - p), y = c + s * (h - c);
171
- t[0] = l + s * (f - l), t[1] = a + s * (y - a);
170
+ const e = this.p0x + o * (this.p1x - this.p0x), i = this.p0y + o * (this.p1y - this.p0y), r = this.p1x + o * (this.p2x - this.p1x), c = this.p1y + o * (this.p2y - this.p1y), a = this.p2x + o * (this.p3x - this.p2x), l = this.p2y + o * (this.p3y - this.p2y), h = e + o * (r - e), p = i + o * (c - i), f = r + o * (a - r), u = c + o * (l - c);
171
+ n[0] = h + o * (f - h), n[1] = p + o * (u - p);
172
172
  return;
173
173
  }
174
174
  }
@@ -180,21 +180,21 @@ class et {
180
180
  * @param param Parameter t.
181
181
  * @param out Two-element array [dx, dy] to write into.
182
182
  */
183
- direction(n, t) {
184
- const s = n;
183
+ direction(t, n) {
184
+ const o = t;
185
185
  switch (this.type) {
186
- case at: {
187
- t[0] = this.p1x - this.p0x, t[1] = this.p1y - this.p0y;
186
+ case nt: {
187
+ n[0] = this.p1x - this.p0x, n[1] = this.p1y - this.p0y;
188
188
  return;
189
189
  }
190
- case it: {
191
- const i = this.p1x - this.p0x + s * (this.p2x - this.p1x - (this.p1x - this.p0x)), o = this.p1y - this.p0y + s * (this.p2y - this.p1y - (this.p1y - this.p0y));
192
- i !== 0 || o !== 0 ? (t[0] = i, t[1] = o) : (t[0] = this.p2x - this.p0x, t[1] = this.p2y - this.p0y);
190
+ case ct: {
191
+ const e = this.p1x - this.p0x + o * (this.p2x - this.p1x - (this.p1x - this.p0x)), i = this.p1y - this.p0y + o * (this.p2y - this.p1y - (this.p1y - this.p0y));
192
+ e !== 0 || i !== 0 ? (n[0] = e, n[1] = i) : (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y);
193
193
  return;
194
194
  }
195
195
  default: {
196
- const i = this.p1x - this.p0x, o = this.p1y - this.p0y, p = this.p2x - this.p1x, c = this.p2y - this.p1y, r = this.p3x - this.p2x, h = this.p3y - this.p2y, l = i + s * (p - i) + s * (p + s * (r - p) - (i + s * (p - i))), a = o + s * (c - o) + s * (c + s * (h - c) - (o + s * (c - o)));
197
- l !== 0 || a !== 0 ? (t[0] = l, t[1] = a) : s === 0 ? (t[0] = this.p2x - this.p0x, t[1] = this.p2y - this.p0y) : s === 1 ? (t[0] = this.p3x - this.p1x, t[1] = this.p3y - this.p1y) : (t[0] = l, t[1] = a);
196
+ const e = this.p1x - this.p0x, i = this.p1y - this.p0y, r = this.p2x - this.p1x, c = this.p2y - this.p1y, a = this.p3x - this.p2x, l = this.p3y - this.p2y, h = e + o * (r - e) + o * (r + o * (a - r) - (e + o * (r - e))), p = i + o * (c - i) + o * (c + o * (l - c) - (i + o * (c - i)));
197
+ h !== 0 || p !== 0 ? (n[0] = h, n[1] = p) : o === 0 ? (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y) : o === 1 ? (n[0] = this.p3x - this.p1x, n[1] = this.p3y - this.p1y) : (n[0] = h, n[1] = p);
198
198
  return;
199
199
  }
200
200
  }
@@ -207,82 +207,82 @@ class et {
207
207
  * @returns Tuple [part0, part1, part2].
208
208
  */
209
209
  splitInThirds() {
210
- const n = [0, 0], t = [0, 0];
210
+ const t = [0, 0], n = [0, 0];
211
211
  switch (this.type) {
212
- case at: {
213
- this.point(1 / 3, n), this.point(2 / 3, t);
214
- const s = new et(at, this.p0x, this.p0y, n[0], n[1], 0, 0, 0, 0), i = new et(at, n[0], n[1], t[0], t[1], 0, 0, 0, 0), o = new et(at, t[0], t[1], this.p1x, this.p1y, 0, 0, 0, 0);
215
- return s.color = i.color = o.color = this.color, [s, i, o];
212
+ case nt: {
213
+ this.point(1 / 3, t), this.point(2 / 3, n);
214
+ const o = new st(nt, this.p0x, this.p0y, t[0], t[1], 0, 0, 0, 0), e = new st(nt, t[0], t[1], n[0], n[1], 0, 0, 0, 0), i = new st(nt, n[0], n[1], this.p1x, this.p1y, 0, 0, 0, 0);
215
+ return o.color = e.color = i.color = this.color, [o, e, i];
216
216
  }
217
- case it: {
218
- this.point(1 / 3, n), this.point(2 / 3, t);
219
- const s = this.p0x + 1 / 3 * (this.p1x - this.p0x), i = this.p0y + 1 / 3 * (this.p1y - this.p0y), o = this.p0x + 5 / 9 * (this.p1x - this.p0x), p = this.p0y + 5 / 9 * (this.p1y - this.p0y), c = this.p1x + 4 / 9 * (this.p2x - this.p1x), r = this.p1y + 4 / 9 * (this.p2y - this.p1y), h = o + 0.5 * (c - o), l = p + 0.5 * (r - p), a = this.p1x + 2 / 3 * (this.p2x - this.p1x), f = this.p1y + 2 / 3 * (this.p2y - this.p1y), y = new et(
220
- it,
217
+ case ct: {
218
+ this.point(1 / 3, t), this.point(2 / 3, n);
219
+ const o = this.p0x + 1 / 3 * (this.p1x - this.p0x), e = this.p0y + 1 / 3 * (this.p1y - this.p0y), i = this.p0x + 5 / 9 * (this.p1x - this.p0x), r = this.p0y + 5 / 9 * (this.p1y - this.p0y), c = this.p1x + 4 / 9 * (this.p2x - this.p1x), a = this.p1y + 4 / 9 * (this.p2y - this.p1y), l = i + 0.5 * (c - i), h = r + 0.5 * (a - r), p = this.p1x + 2 / 3 * (this.p2x - this.p1x), f = this.p1y + 2 / 3 * (this.p2y - this.p1y), u = new st(
220
+ ct,
221
221
  this.p0x,
222
222
  this.p0y,
223
- s,
224
- i,
225
- n[0],
226
- n[1],
227
- 0,
228
- 0
229
- ), _ = new et(
230
- it,
231
- n[0],
232
- n[1],
233
- h,
234
- l,
223
+ o,
224
+ e,
235
225
  t[0],
236
226
  t[1],
237
227
  0,
238
228
  0
239
- ), u = new et(
240
- it,
229
+ ), y = new st(
230
+ ct,
241
231
  t[0],
242
232
  t[1],
243
- a,
233
+ l,
234
+ h,
235
+ n[0],
236
+ n[1],
237
+ 0,
238
+ 0
239
+ ), x = new st(
240
+ ct,
241
+ n[0],
242
+ n[1],
243
+ p,
244
244
  f,
245
245
  this.p2x,
246
246
  this.p2y,
247
247
  0,
248
248
  0
249
249
  );
250
- return y.color = _.color = u.color = this.color, [y, _, u];
250
+ return u.color = y.color = x.color = this.color, [u, y, x];
251
251
  }
252
252
  default: {
253
- this.point(1 / 3, n), this.point(2 / 3, t);
254
- const s = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0x : this.p0x + 1 / 3 * (this.p1x - this.p0x), i = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0y : this.p0y + 1 / 3 * (this.p1y - this.p0y), o = this.p0x + 1 / 3 * (this.p1x - this.p0x), p = this.p0y + 1 / 3 * (this.p1y - this.p0y), c = this.p1x + 1 / 3 * (this.p2x - this.p1x), r = this.p1y + 1 / 3 * (this.p2y - this.p1y), h = this.p2x + 1 / 3 * (this.p3x - this.p2x), l = this.p2y + 1 / 3 * (this.p3y - this.p2y), a = o + 1 / 3 * (c - o), f = p + 1 / 3 * (r - p), y = c + 1 / 3 * (h - c), _ = r + 1 / 3 * (l - r), u = a + 2 / 3 * (y - a), x = f + 2 / 3 * (_ - f), M = this.p0x + 2 / 3 * (this.p1x - this.p0x), w = this.p0y + 2 / 3 * (this.p1y - this.p0y), v = this.p1x + 2 / 3 * (this.p2x - this.p1x), C = this.p1y + 2 / 3 * (this.p2y - this.p1y), A = this.p2x + 2 / 3 * (this.p3x - this.p2x), D = this.p2y + 2 / 3 * (this.p3y - this.p2y), I = M + 2 / 3 * (v - M), F = w + 2 / 3 * (C - w), T = v + 2 / 3 * (A - v), b = C + 2 / 3 * (D - C), N = I + 1 / 3 * (T - I), R = F + 1 / 3 * (b - F), q = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3x : this.p2x + 2 / 3 * (this.p3x - this.p2x), P = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3y : this.p2y + 2 / 3 * (this.p3y - this.p2y), X = new et(
255
- Ot,
253
+ this.point(1 / 3, t), this.point(2 / 3, n);
254
+ const o = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0x : this.p0x + 1 / 3 * (this.p1x - this.p0x), e = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0y : this.p0y + 1 / 3 * (this.p1y - this.p0y), i = this.p0x + 1 / 3 * (this.p1x - this.p0x), r = this.p0y + 1 / 3 * (this.p1y - this.p0y), c = this.p1x + 1 / 3 * (this.p2x - this.p1x), a = this.p1y + 1 / 3 * (this.p2y - this.p1y), l = this.p2x + 1 / 3 * (this.p3x - this.p2x), h = this.p2y + 1 / 3 * (this.p3y - this.p2y), p = i + 1 / 3 * (c - i), f = r + 1 / 3 * (a - r), u = c + 1 / 3 * (l - c), y = a + 1 / 3 * (h - a), x = p + 2 / 3 * (u - p), g = f + 2 / 3 * (y - f), M = this.p0x + 2 / 3 * (this.p1x - this.p0x), b = this.p0y + 2 / 3 * (this.p1y - this.p0y), A = this.p1x + 2 / 3 * (this.p2x - this.p1x), F = this.p1y + 2 / 3 * (this.p2y - this.p1y), k = this.p2x + 2 / 3 * (this.p3x - this.p2x), T = this.p2y + 2 / 3 * (this.p3y - this.p2y), q = M + 2 / 3 * (A - M), m = b + 2 / 3 * (F - b), d = A + 2 / 3 * (k - A), _ = F + 2 / 3 * (T - F), w = q + 1 / 3 * (d - q), E = m + 1 / 3 * (_ - m), I = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3x : this.p2x + 2 / 3 * (this.p3x - this.p2x), C = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3y : this.p2y + 2 / 3 * (this.p3y - this.p2y), S = new st(
255
+ Ct,
256
256
  this.p0x,
257
257
  this.p0y,
258
- s,
259
- i,
260
- a,
258
+ o,
259
+ e,
260
+ p,
261
261
  f,
262
- n[0],
263
- n[1]
264
- ), Q = new et(
265
- Ot,
266
- n[0],
267
- n[1],
268
- u,
269
- x,
270
- N,
271
- R,
272
262
  t[0],
273
263
  t[1]
274
- ), V = new et(
275
- Ot,
264
+ ), O = new st(
265
+ Ct,
276
266
  t[0],
277
267
  t[1],
278
- T,
279
- b,
280
- q,
281
- P,
268
+ x,
269
+ g,
270
+ w,
271
+ E,
272
+ n[0],
273
+ n[1]
274
+ ), L = new st(
275
+ Ct,
276
+ n[0],
277
+ n[1],
278
+ d,
279
+ _,
280
+ I,
281
+ C,
282
282
  this.p3x,
283
283
  this.p3y
284
284
  );
285
- return X.color = Q.color = V.color = this.color, [X, Q, V];
285
+ return S.color = O.color = L.color = this.color, [S, O, L];
286
286
  }
287
287
  }
288
288
  }
@@ -299,95 +299,95 @@ class et {
299
299
  * @param oy Query point y (shape space).
300
300
  * @param out Reusable result object (mutated).
301
301
  */
302
- signedDistance(n, t, s) {
302
+ signedDistance(t, n, o) {
303
303
  switch (this.type) {
304
- case at: {
305
- const i = this.p0x, o = this.p0y, p = this.p1x, c = this.p1y, r = n - i, h = t - o, l = p - i, a = c - o, f = l * l + a * a, y = (r * l + h * a) / f, _ = y > 0.5, u = (_ ? p : i) - n, x = (_ ? c : o) - t, M = Math.sqrt(u * u + x * x);
306
- if (y > 0 && y < 1) {
307
- const C = Math.sqrt(l * l + a * a), A = l / C, I = a / C * r - A * h;
308
- if (Math.abs(I) < M) {
309
- s.distance = I, s.dot = 0, s.param = y;
304
+ case nt: {
305
+ const e = this.p0x, i = this.p0y, r = this.p1x, c = this.p1y, a = t - e, l = n - i, h = r - e, p = c - i, f = h * h + p * p, u = (a * h + l * p) / f, y = u > 0.5, x = (y ? r : e) - t, g = (y ? c : i) - n, M = Math.sqrt(x * x + g * g);
306
+ if (u > 0 && u < 1) {
307
+ const F = Math.sqrt(h * h + p * p), k = h / F, q = p / F * a - k * l;
308
+ if (Math.abs(q) < M) {
309
+ o.distance = q, o.dot = 0, o.param = u;
310
310
  return;
311
311
  }
312
312
  }
313
- const w = r * a - h * l;
314
- s.distance = Dt(w) * M;
315
- const v = Math.sqrt(l * l + a * a);
316
- s.dot = M === 0 || v === 0 ? 0 : Math.abs((l * u + a * x) / (v * M)), s.param = y;
313
+ const b = a * p - l * h;
314
+ o.distance = St(b) * M;
315
+ const A = Math.sqrt(h * h + p * p);
316
+ o.dot = M === 0 || A === 0 ? 0 : Math.abs((h * x + p * g) / (A * M)), o.param = u;
317
317
  return;
318
318
  }
319
- case it: {
320
- const i = this.p0x, o = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, l = i - n, a = o - t, f = p - i, y = c - o, _ = r - p - f, u = h - c - y, x = _ * _ + u * u, M = 3 * (f * _ + y * u), w = 2 * (f * f + y * y) + (l * _ + a * u), v = l * f + a * y, C = lo(x, M, w, v, 0, 1, U);
321
- let A = f, D = y;
322
- const I = l * l + a * a;
323
- let F = Dt(A * a - D * l), T = I, b = -(l * A + a * D) / (A * A + D * D);
319
+ case ct: {
320
+ const e = this.p0x, i = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = e - t, p = i - n, f = r - e, u = c - i, y = a - r - f, x = l - c - u, g = y * y + x * x, M = 3 * (f * y + u * x), b = 2 * (f * f + u * u) + (h * y + p * x), A = h * f + p * u, F = oe(g, M, b, A, 0, 1, B);
321
+ let k = f, T = u;
322
+ const q = h * h + p * p;
323
+ let m = St(k * p - T * h), d = q, _ = -(h * k + p * T) / (k * k + T * T);
324
324
  {
325
- const R = r - n, q = h - t, P = R * R + q * q;
326
- P < T && (A = r - p, D = h - c, F = Dt(A * q - D * R), T = P, b = ((n - p) * A + (t - c) * D) / (A * A + D * D));
325
+ const E = a - t, I = l - n, C = E * E + I * I;
326
+ C < d && (k = a - r, T = l - c, m = St(k * I - T * E), d = C, _ = ((t - r) * k + (n - c) * T) / (k * k + T * T));
327
327
  }
328
- for (let R = 0; R < C; ++R) {
329
- const q = U[R];
330
- if (q > 0 && q < 1) {
331
- const P = l + 2 * q * f + q * q * _, X = a + 2 * q * y + q * q * u, Q = P * P + X * X;
332
- if (Q <= T) {
333
- const V = f + q * _, nt = y + q * u;
334
- F = Dt(V * X - nt * P), T = Q, b = q;
328
+ for (let E = 0; E < F; ++E) {
329
+ const I = B[E];
330
+ if (I > 0 && I < 1) {
331
+ const C = h + 2 * I * f + I * I * y, S = p + 2 * I * u + I * I * x, O = C * C + S * S;
332
+ if (O <= d) {
333
+ const L = f + I * y, W = u + I * x;
334
+ m = St(L * S - W * C), d = O, _ = I;
335
335
  }
336
336
  }
337
337
  }
338
- const N = F * Math.sqrt(T);
339
- if (b >= 0 && b <= 1) {
340
- s.distance = N, s.dot = 0, s.param = b;
338
+ const w = m * Math.sqrt(d);
339
+ if (_ >= 0 && _ <= 1) {
340
+ o.distance = w, o.dot = 0, o.param = _;
341
341
  return;
342
342
  }
343
- if (s.distance = N, s.param = b, b < 0.5) {
344
- const R = Math.sqrt(f * f + y * y), q = Math.sqrt(I);
345
- s.dot = q === 0 || R === 0 ? 0 : Math.abs((f * l + y * a) / (R * q));
343
+ if (o.distance = w, o.param = _, _ < 0.5) {
344
+ const E = Math.sqrt(f * f + u * u), I = Math.sqrt(q);
345
+ o.dot = I === 0 || E === 0 ? 0 : Math.abs((f * h + u * p) / (E * I));
346
346
  } else {
347
- const R = r - p, q = h - c, P = r - n, X = h - t, Q = Math.sqrt(R * R + q * q), V = Math.sqrt(P * P + X * X);
348
- s.dot = Q === 0 || V === 0 ? 0 : Math.abs((R * P + q * X) / (Q * V));
347
+ const E = a - r, I = l - c, C = a - t, S = l - n, O = Math.sqrt(E * E + I * I), L = Math.sqrt(C * C + S * S);
348
+ o.dot = O === 0 || L === 0 ? 0 : Math.abs((E * C + I * S) / (O * L));
349
349
  }
350
350
  return;
351
351
  }
352
352
  default: {
353
- const i = this.p0x, o = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, l = this.p3x, a = this.p3y, f = i - n, y = o - t, _ = p - i, u = c - o, x = r - p - _, M = h - c - u, w = l - r - (r - p) - x, v = a - h - (h - c) - M;
354
- let C = _, A = u;
355
- C === 0 && A === 0 && (C = r - i, A = h - o);
356
- const D = Math.sqrt(f * f + y * y);
357
- let I = Dt(C * y - A * f) * D, F = -(f * C + y * A) / (C * C + A * A);
353
+ const e = this.p0x, i = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = this.p3x, p = this.p3y, f = e - t, u = i - n, y = r - e, x = c - i, g = a - r - y, M = l - c - x, b = h - a - (a - r) - g, A = p - l - (l - c) - M;
354
+ let F = y, k = x;
355
+ F === 0 && k === 0 && (F = a - e, k = l - i);
356
+ const T = Math.sqrt(f * f + u * u);
357
+ let q = St(F * u - k * f) * T, m = -(f * F + u * k) / (F * F + k * k);
358
358
  {
359
- const T = l - n, b = a - t, N = Math.sqrt(T * T + b * b);
360
- if (N < Math.abs(I)) {
361
- let R = l - r, q = a - h;
362
- R === 0 && q === 0 && (R = l - p, q = a - c), C = R, A = q, I = Dt(C * b - A * T) * N, F = ((C - T) * C + (A - b) * A) / (C * C + A * A);
359
+ const d = h - t, _ = p - n, w = Math.sqrt(d * d + _ * _);
360
+ if (w < Math.abs(q)) {
361
+ let E = h - a, I = p - l;
362
+ E === 0 && I === 0 && (E = h - r, I = p - c), F = E, k = I, q = St(F * _ - k * d) * w, m = ((F - d) * F + (k - _) * k) / (F * F + k * k);
363
363
  }
364
364
  }
365
- for (let T = 0; T <= Rs; ++T) {
366
- let b = 1 / Rs * T, N = f + 3 * b * _ + 3 * b * b * x + b * b * b * w, R = y + 3 * b * u + 3 * b * b * M + b * b * b * v, q = 3 * _ + 6 * b * x + 3 * b * b * w, P = 3 * u + 6 * b * M + 3 * b * b * v, X = 6 * x + 6 * b * w, Q = 6 * M + 6 * b * v, V = b - (N * q + R * P) / (q * q + P * P + (N * X + R * Q));
367
- if (V > 0 && V < 1) {
368
- let nt = fo;
365
+ for (let d = 0; d <= co; ++d) {
366
+ let _ = 1 / co * d, w = f + 3 * _ * y + 3 * _ * _ * g + _ * _ * _ * b, E = u + 3 * _ * x + 3 * _ * _ * M + _ * _ * _ * A, I = 3 * y + 6 * _ * g + 3 * _ * _ * b, C = 3 * x + 6 * _ * M + 3 * _ * _ * A, S = 6 * g + 6 * _ * b, O = 6 * M + 6 * _ * A, L = _ - (w * I + E * C) / (I * I + C * C + (w * S + E * O));
367
+ if (L > 0 && L < 1) {
368
+ let W = ee;
369
369
  do {
370
- if (b = V, N = f + 3 * b * _ + 3 * b * b * x + b * b * b * w, R = y + 3 * b * u + 3 * b * b * M + b * b * b * v, q = 3 * _ + 6 * b * x + 3 * b * b * w, P = 3 * u + 6 * b * M + 3 * b * b * v, !--nt) break;
371
- X = 6 * x + 6 * b * w, Q = 6 * M + 6 * b * v, V = b - (N * q + R * P) / (q * q + P * P + (N * X + R * Q));
372
- } while (V > 0 && V < 1);
373
- const H = Math.sqrt(N * N + R * R);
374
- H < Math.abs(I) && (I = Dt(q * R - P * N) * H, F = b);
370
+ if (_ = L, w = f + 3 * _ * y + 3 * _ * _ * g + _ * _ * _ * b, E = u + 3 * _ * x + 3 * _ * _ * M + _ * _ * _ * A, I = 3 * y + 6 * _ * g + 3 * _ * _ * b, C = 3 * x + 6 * _ * M + 3 * _ * _ * A, !--W) break;
371
+ S = 6 * g + 6 * _ * b, O = 6 * M + 6 * _ * A, L = _ - (w * I + E * C) / (I * I + C * C + (w * S + E * O));
372
+ } while (L > 0 && L < 1);
373
+ const X = Math.sqrt(w * w + E * E);
374
+ X < Math.abs(q) && (q = St(I * E - C * w) * X, m = _);
375
375
  }
376
376
  }
377
- if (F >= 0 && F <= 1) {
378
- s.distance = I, s.dot = 0, s.param = F;
377
+ if (m >= 0 && m <= 1) {
378
+ o.distance = q, o.dot = 0, o.param = m;
379
379
  return;
380
380
  }
381
- if (s.distance = I, s.param = F, F < 0.5) {
382
- let T = _, b = u;
383
- T === 0 && b === 0 && (T = r - i, b = h - o);
384
- const N = Math.sqrt(T * T + b * b);
385
- s.dot = D === 0 || N === 0 ? 0 : Math.abs((T * f + b * y) / (N * D));
381
+ if (o.distance = q, o.param = m, m < 0.5) {
382
+ let d = y, _ = x;
383
+ d === 0 && _ === 0 && (d = a - e, _ = l - i);
384
+ const w = Math.sqrt(d * d + _ * _);
385
+ o.dot = T === 0 || w === 0 ? 0 : Math.abs((d * f + _ * u) / (w * T));
386
386
  } else {
387
- let T = l - r, b = a - h;
388
- T === 0 && b === 0 && (T = l - p, b = a - c);
389
- const N = l - n, R = a - t, q = Math.sqrt(T * T + b * b), P = Math.sqrt(N * N + R * R);
390
- s.dot = q === 0 || P === 0 ? 0 : Math.abs((T * N + b * R) / (q * P));
387
+ let d = h - a, _ = p - l;
388
+ d === 0 && _ === 0 && (d = h - r, _ = p - c);
389
+ const w = h - t, E = p - n, I = Math.sqrt(d * d + _ * _), C = Math.sqrt(w * w + E * E);
390
+ o.dot = I === 0 || C === 0 ? 0 : Math.abs((d * w + _ * E) / (I * C));
391
391
  }
392
392
  return;
393
393
  }
@@ -404,58 +404,58 @@ class et {
404
404
  * @param dyOut Output array (length >= 3) — crossing directions (±1).
405
405
  * @returns Number of crossings written (0..3).
406
406
  */
407
- scanlineIntersections(n, t, s) {
407
+ scanlineIntersections(t, n, o) {
408
408
  switch (this.type) {
409
- case at: {
410
- const i = this.p0y, o = this.p1y;
411
- if (n >= i && n < o || n >= o && n < i) {
412
- const p = (n - i) / (o - i);
413
- return t[0] = eo(this.p0x, this.p1x, p), s[0] = rt(o - i), 1;
409
+ case nt: {
410
+ const e = this.p0y, i = this.p1y;
411
+ if (t >= e && t < i || t >= i && t < e) {
412
+ const r = (t - e) / (i - e);
413
+ return n[0] = Po(this.p0x, this.p1x, r), o[0] = ft(i - e), 1;
414
414
  }
415
415
  return 0;
416
416
  }
417
- case it: {
418
- const i = this.p0x, o = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y;
419
- let l = 0, a = n > o ? 1 : -1;
420
- t[l] = i, o === n && (o < c || o === c && o < h ? s[l++] = 1 : a = 1);
417
+ case ct: {
418
+ const e = this.p0x, i = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y;
419
+ let h = 0, p = t > i ? 1 : -1;
420
+ n[h] = e, i === t && (i < c || i === c && i < l ? o[h++] = 1 : p = 1);
421
421
  {
422
- const f = p - i, y = c - o, _ = r - p - f, u = h - c - y, x = $s(U, u, 2 * y, o - n);
423
- if (x >= 2 && U[0] > U[1]) {
424
- const M = U[0];
425
- U[0] = U[1], U[1] = M;
422
+ const f = r - e, u = c - i, y = a - r - f, x = l - c - u, g = $o(B, x, 2 * u, i - t);
423
+ if (g >= 2 && B[0] > B[1]) {
424
+ const M = B[0];
425
+ B[0] = B[1], B[1] = M;
426
426
  }
427
- for (let M = 0; M < x && l < 2; ++M) {
428
- const w = U[M];
429
- w >= 0 && w <= 1 && (t[l] = i + 2 * w * f + w * w * _, a * (y + w * u) >= 0 && (s[l++] = a, a = -a));
427
+ for (let M = 0; M < g && h < 2; ++M) {
428
+ const b = B[M];
429
+ b >= 0 && b <= 1 && (n[h] = e + 2 * b * f + b * b * y, p * (u + b * x) >= 0 && (o[h++] = p, p = -p));
430
430
  }
431
431
  }
432
- return h === n && (a > 0 && l > 0 && (--l, a = -1), (h < c || h === c && h < o) && l < 2 && (t[l] = r, a < 0 && (s[l++] = -1, a = 1))), a !== (n >= h ? 1 : -1) && (l > 0 ? --l : (Math.abs(h - n) < Math.abs(o - n) && (t[l] = r), s[l++] = a)), l;
432
+ return l === t && (p > 0 && h > 0 && (--h, p = -1), (l < c || l === c && l < i) && h < 2 && (n[h] = a, p < 0 && (o[h++] = -1, p = 1))), p !== (t >= l ? 1 : -1) && (h > 0 ? --h : (Math.abs(l - t) < Math.abs(i - t) && (n[h] = a), o[h++] = p)), h;
433
433
  }
434
434
  default: {
435
- const i = this.p0x, o = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, l = this.p3x, a = this.p3y;
436
- let f = 0, y = n > o ? 1 : -1;
437
- t[f] = i, o === n && (o < c || o === c && (o < h || o === h && o < a) ? s[f++] = 1 : y = 1);
435
+ const e = this.p0x, i = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = this.p3x, p = this.p3y;
436
+ let f = 0, u = t > i ? 1 : -1;
437
+ n[f] = e, i === t && (i < c || i === c && (i < l || i === l && i < p) ? o[f++] = 1 : u = 1);
438
438
  {
439
- const _ = l - 3 * r + 3 * p - i, u = a - 3 * h + 3 * c - o, x = 3 * r - 6 * p + 3 * i, M = 3 * h - 6 * c + 3 * o, w = 3 * p - 3 * i, v = 3 * c - 3 * o, C = ro(U, u, M, v, o - n);
440
- if (C >= 2) {
441
- if (U[0] > U[1]) {
442
- const A = U[0];
443
- U[0] = U[1], U[1] = A;
439
+ const y = h - 3 * a + 3 * r - e, x = p - 3 * l + 3 * c - i, g = 3 * a - 6 * r + 3 * e, M = 3 * l - 6 * c + 3 * i, b = 3 * r - 3 * e, A = 3 * c - 3 * i, F = Jo(B, x, M, A, i - t);
440
+ if (F >= 2) {
441
+ if (B[0] > B[1]) {
442
+ const k = B[0];
443
+ B[0] = B[1], B[1] = k;
444
444
  }
445
- if (C >= 3 && U[1] > U[2]) {
446
- const A = U[1];
447
- if (U[1] = U[2], U[2] = A, U[0] > U[1]) {
448
- const D = U[0];
449
- U[0] = U[1], U[1] = D;
445
+ if (F >= 3 && B[1] > B[2]) {
446
+ const k = B[1];
447
+ if (B[1] = B[2], B[2] = k, B[0] > B[1]) {
448
+ const T = B[0];
449
+ B[0] = B[1], B[1] = T;
450
450
  }
451
451
  }
452
452
  }
453
- for (let A = 0; A < C && f < 3; ++A) {
454
- const D = U[A];
455
- D >= 0 && D <= 1 && (t[f] = ((_ * D + x) * D + w) * D + i, y * ((3 * u * D + 2 * M) * D + v) >= 0 && (s[f++] = y, y = -y));
453
+ for (let k = 0; k < F && f < 3; ++k) {
454
+ const T = B[k];
455
+ T >= 0 && T <= 1 && (n[f] = ((y * T + g) * T + b) * T + e, u * ((3 * x * T + 2 * M) * T + A) >= 0 && (o[f++] = u, u = -u));
456
456
  }
457
457
  }
458
- return a === n && (y > 0 && f > 0 && (--f, y = -1), (a < h || a === h && (a < c || a === c && a < o)) && f < 3 && (t[f] = l, y < 0 && (s[f++] = -1, y = 1))), y !== (n >= a ? 1 : -1) && (f > 0 ? --f : (Math.abs(a - n) < Math.abs(o - n) && (t[f] = l), s[f++] = y)), f;
458
+ return p === t && (u > 0 && f > 0 && (--f, u = -1), (p < l || p === l && (p < c || p === c && p < i)) && f < 3 && (n[f] = h, u < 0 && (o[f++] = -1, u = 1))), u !== (t >= p ? 1 : -1) && (f > 0 ? --f : (Math.abs(p - t) < Math.abs(i - t) && (n[f] = h), o[f++] = u)), f;
459
459
  }
460
460
  }
461
461
  }
@@ -467,39 +467,39 @@ class et {
467
467
  * @returns A new CUBIC EdgeSegment with identical geometry.
468
468
  */
469
469
  convertToCubic() {
470
- const n = this.p0x + 0.6666666666666666 * (this.p1x - this.p0x), t = this.p0y + 2 / 3 * (this.p1y - this.p0y), s = this.p1x + 1 / 3 * (this.p2x - this.p1x), i = this.p1y + 1 / 3 * (this.p2y - this.p1y), o = new et(
471
- Ot,
470
+ const t = this.p0x + 0.6666666666666666 * (this.p1x - this.p0x), n = this.p0y + 2 / 3 * (this.p1y - this.p0y), o = this.p1x + 1 / 3 * (this.p2x - this.p1x), e = this.p1y + 1 / 3 * (this.p2y - this.p1y), i = new st(
471
+ Ct,
472
472
  this.p0x,
473
473
  this.p0y,
474
- n,
475
474
  t,
476
- s,
477
- i,
475
+ n,
476
+ o,
477
+ e,
478
478
  this.p2x,
479
479
  this.p2y
480
480
  );
481
- return o.color = this.color, o;
481
+ return i.color = this.color, i;
482
482
  }
483
483
  }
484
- class gt {
484
+ class At {
485
485
  /**
486
486
  * @param buffer Source buffer (the full font file).
487
487
  * @param byteOffset Starting position (default 0).
488
488
  */
489
- constructor(n, t = 0) {
490
- this._view = new DataView(n), this._pos = t;
489
+ constructor(t, n = 0) {
490
+ this._view = new DataView(t), this._pos = n;
491
491
  }
492
492
  /** Current byte position. */
493
493
  get pos() {
494
494
  return this._pos;
495
495
  }
496
496
  /** Move to an absolute byte position. */
497
- seek(n) {
498
- this._pos = n;
497
+ seek(t) {
498
+ this._pos = t;
499
499
  }
500
500
  /** Advance position by `n` bytes without reading. */
501
- skip(n) {
502
- this._pos += n;
501
+ skip(t) {
502
+ this._pos += t;
503
503
  }
504
504
  /** Read uint8 (1 byte). */
505
505
  u8() {
@@ -507,23 +507,23 @@ class gt {
507
507
  }
508
508
  /** Read uint16 big-endian (2 bytes). */
509
509
  u16() {
510
- const n = this._view.getUint16(this._pos, !1);
511
- return this._pos += 2, n;
510
+ const t = this._view.getUint16(this._pos, !1);
511
+ return this._pos += 2, t;
512
512
  }
513
513
  /** Read int16 big-endian (2 bytes). */
514
514
  i16() {
515
- const n = this._view.getInt16(this._pos, !1);
516
- return this._pos += 2, n;
515
+ const t = this._view.getInt16(this._pos, !1);
516
+ return this._pos += 2, t;
517
517
  }
518
518
  /** Read uint32 big-endian (4 bytes). */
519
519
  u32() {
520
- const n = this._view.getUint32(this._pos, !1);
521
- return this._pos += 4, n;
520
+ const t = this._view.getUint32(this._pos, !1);
521
+ return this._pos += 4, t;
522
522
  }
523
523
  /** Read int32 big-endian (4 bytes). */
524
524
  i32() {
525
- const n = this._view.getInt32(this._pos, !1);
526
- return this._pos += 4, n;
525
+ const t = this._view.getInt32(this._pos, !1);
526
+ return this._pos += 4, t;
527
527
  }
528
528
  /**
529
529
  * Read F2Dot14 (2 bytes): 2-bit signed integer + 14-bit fraction.
@@ -549,309 +549,309 @@ class gt {
549
549
  }
550
550
  // ── peek helpers (non-advancing reads at absolute positions) ──────────────
551
551
  /** Read uint16 big-endian at an absolute byte offset without moving pos. */
552
- peekU16(n) {
553
- return this._view.getUint16(n, !1);
552
+ peekU16(t) {
553
+ return this._view.getUint16(t, !1);
554
554
  }
555
555
  /** Read uint32 big-endian at an absolute byte offset without moving pos. */
556
- peekU32(n) {
557
- return this._view.getUint32(n, !1);
556
+ peekU32(t) {
557
+ return this._view.getUint32(t, !1);
558
558
  }
559
559
  /** Read int16 big-endian at an absolute byte offset without moving pos. */
560
- peekI16(n) {
561
- return this._view.getInt16(n, !1);
560
+ peekI16(t) {
561
+ return this._view.getInt16(t, !1);
562
562
  }
563
563
  }
564
- function yo(e, n) {
565
- const t = new gt(e, n);
566
- t.skip(2);
567
- const s = t.u16();
568
- let i = null;
569
- for (let p = 0; p < s; p++) {
570
- const c = t.u16(), r = t.u16(), h = t.u32(), l = n + h, a = t.peekU16(l);
564
+ function ie(s, t) {
565
+ const n = new At(s, t);
566
+ n.skip(2);
567
+ const o = n.u16();
568
+ let e = null;
569
+ for (let r = 0; r < o; r++) {
570
+ const c = n.u16(), a = n.u16(), l = n.u32(), h = t + l, p = n.peekU16(h);
571
571
  let f = -1;
572
- c === 3 && r === 10 && a === 12 ? f = 5 : c === 0 && r === 6 && a === 12 ? f = 4 : c === 0 && r === 4 && a === 12 ? f = 3 : c === 3 && r === 1 && a === 4 ? f = 2 : c === 0 && r <= 3 && a === 4 && (f = 1), f > ((i == null ? void 0 : i.priority) ?? -1) && (i = { priority: f, subtableAbsOffset: l });
573
- }
574
- if (!i) return () => 0;
575
- const o = t.peekU16(i.subtableAbsOffset);
576
- return o === 12 ? uo(e, i.subtableAbsOffset) : o === 4 ? _o(e, i.subtableAbsOffset) : () => 0;
577
- }
578
- function uo(e, n) {
579
- const t = new gt(e, n);
580
- t.skip(2), t.skip(2), t.skip(4), t.skip(4);
581
- const s = t.u32(), i = new Uint32Array(s), o = new Uint32Array(s), p = new Uint32Array(s);
582
- for (let c = 0; c < s; c++)
583
- i[c] = t.u32(), o[c] = t.u32(), p[c] = t.u32();
572
+ c === 3 && a === 10 && p === 12 ? f = 5 : c === 0 && a === 6 && p === 12 ? f = 4 : c === 0 && a === 4 && p === 12 ? f = 3 : c === 3 && a === 1 && p === 4 ? f = 2 : c === 0 && a <= 3 && p === 4 && (f = 1), f > ((e == null ? void 0 : e.priority) ?? -1) && (e = { priority: f, subtableAbsOffset: h });
573
+ }
574
+ if (!e) return () => 0;
575
+ const i = n.peekU16(e.subtableAbsOffset);
576
+ return i === 12 ? ce(s, e.subtableAbsOffset) : i === 4 ? re(s, e.subtableAbsOffset) : () => 0;
577
+ }
578
+ function ce(s, t) {
579
+ const n = new At(s, t);
580
+ n.skip(2), n.skip(2), n.skip(4), n.skip(4);
581
+ const o = n.u32(), e = new Uint32Array(o), i = new Uint32Array(o), r = new Uint32Array(o);
582
+ for (let c = 0; c < o; c++)
583
+ e[c] = n.u32(), i[c] = n.u32(), r[c] = n.u32();
584
584
  return (c) => {
585
- let r = 0, h = s - 1;
586
- for (; r <= h; ) {
587
- const l = r + h >>> 1, a = i[l] ?? 0, f = o[l] ?? 0;
588
- if (c < a) h = l - 1;
589
- else if (c > f) r = l + 1;
590
- else return (p[l] ?? 0) + (c - a);
585
+ let a = 0, l = o - 1;
586
+ for (; a <= l; ) {
587
+ const h = a + l >>> 1, p = e[h] ?? 0, f = i[h] ?? 0;
588
+ if (c < p) l = h - 1;
589
+ else if (c > f) a = h + 1;
590
+ else return (r[h] ?? 0) + (c - p);
591
591
  }
592
592
  return 0;
593
593
  };
594
594
  }
595
- function _o(e, n) {
596
- const t = new gt(e, n);
597
- t.skip(2), t.skip(2), t.skip(2);
598
- const i = t.u16() >>> 1;
599
- t.skip(6);
600
- const o = new Uint16Array(i);
601
- for (let a = 0; a < i; a++) o[a] = t.u16();
602
- t.skip(2);
603
- const p = new Uint16Array(i);
604
- for (let a = 0; a < i; a++) p[a] = t.u16();
605
- const c = new Int16Array(i);
606
- for (let a = 0; a < i; a++) c[a] = t.i16();
607
- const r = new Int32Array(i), h = new Uint16Array(i);
608
- for (let a = 0; a < i; a++)
609
- r[a] = t.pos, h[a] = t.u16();
610
- const l = new DataView(e);
611
- return (a) => {
612
- if (a > 65535) return 0;
613
- let f = 0, y = i - 1;
614
- for (; f <= y; ) {
615
- const _ = f + y >>> 1, u = o[_] ?? 0;
616
- if (a > u)
617
- f = _ + 1;
618
- else if (a < (p[_] ?? 0))
619
- y = _ - 1;
595
+ function re(s, t) {
596
+ const n = new At(s, t);
597
+ n.skip(2), n.skip(2), n.skip(2);
598
+ const e = n.u16() >>> 1;
599
+ n.skip(6);
600
+ const i = new Uint16Array(e);
601
+ for (let p = 0; p < e; p++) i[p] = n.u16();
602
+ n.skip(2);
603
+ const r = new Uint16Array(e);
604
+ for (let p = 0; p < e; p++) r[p] = n.u16();
605
+ const c = new Int16Array(e);
606
+ for (let p = 0; p < e; p++) c[p] = n.i16();
607
+ const a = new Int32Array(e), l = new Uint16Array(e);
608
+ for (let p = 0; p < e; p++)
609
+ a[p] = n.pos, l[p] = n.u16();
610
+ const h = new DataView(s);
611
+ return (p) => {
612
+ if (p > 65535) return 0;
613
+ let f = 0, u = e - 1;
614
+ for (; f <= u; ) {
615
+ const y = f + u >>> 1, x = i[y] ?? 0;
616
+ if (p > x)
617
+ f = y + 1;
618
+ else if (p < (r[y] ?? 0))
619
+ u = y - 1;
620
620
  else {
621
- if ((o[_] ?? 0) === 65535) return 0;
622
- const M = h[_] ?? 0, w = c[_] ?? 0, v = p[_] ?? 0;
621
+ if ((i[y] ?? 0) === 65535) return 0;
622
+ const M = l[y] ?? 0, b = c[y] ?? 0, A = r[y] ?? 0;
623
623
  if (M === 0)
624
- return a + w & 65535;
625
- const C = (r[_] ?? 0) + M + (a - v) * 2, A = l.getUint16(C, !1);
626
- return A === 0 ? 0 : A + w & 65535;
624
+ return p + b & 65535;
625
+ const F = (a[y] ?? 0) + M + (p - A) * 2, k = h.getUint16(F, !1);
626
+ return k === 0 ? 0 : k + b & 65535;
627
627
  }
628
628
  }
629
629
  return 0;
630
630
  };
631
631
  }
632
- function xo(e, n) {
633
- const t = new gt(e, n);
634
- t.skip(4), t.skip(4), t.skip(4), t.skip(4), t.skip(2);
635
- const s = t.u16();
636
- t.skip(16), t.skip(8), t.skip(2), t.skip(2), t.skip(2);
637
- const i = t.i16();
638
- return { unitsPerEm: s, indexToLocFormat: i };
639
- }
640
- function Mo(e, n) {
641
- const t = new gt(e, n);
642
- t.skip(4);
643
- const s = t.i16(), i = t.i16(), o = t.i16();
644
- t.skip(2), t.skip(2), t.skip(2), t.skip(2), t.skip(2), t.skip(2), t.skip(2), t.skip(8), t.skip(2);
645
- const p = t.u16();
646
- return { ascender: s, descender: i, lineGap: o, numberOfHMetrics: p };
632
+ function ae(s, t) {
633
+ const n = new At(s, t);
634
+ n.skip(4), n.skip(4), n.skip(4), n.skip(4), n.skip(2);
635
+ const o = n.u16();
636
+ n.skip(16), n.skip(8), n.skip(2), n.skip(2), n.skip(2);
637
+ const e = n.i16();
638
+ return { unitsPerEm: o, indexToLocFormat: e };
647
639
  }
648
- function go(e, n, t, s) {
649
- const i = new gt(e, n), o = new Array(t);
650
- let p = 0;
651
- for (let c = 0; c < s; c++) {
652
- const r = i.u16(), h = i.i16();
653
- o[c] = { advanceWidth: r, lsb: h }, p = r;
640
+ function le(s, t) {
641
+ const n = new At(s, t);
642
+ n.skip(4);
643
+ const o = n.i16(), e = n.i16(), i = n.i16();
644
+ n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(2), n.skip(8), n.skip(2);
645
+ const r = n.u16();
646
+ return { ascender: o, descender: e, lineGap: i, numberOfHMetrics: r };
647
+ }
648
+ function he(s, t, n, o) {
649
+ const e = new At(s, t), i = [];
650
+ let r = 0;
651
+ for (let c = 0; c < o; c++) {
652
+ const a = e.u16(), l = e.i16();
653
+ i[c] = { advanceWidth: a, lsb: l }, r = a;
654
654
  }
655
- for (let c = s; c < t; c++) {
656
- const r = i.i16();
657
- o[c] = { advanceWidth: p, lsb: r };
655
+ for (let c = o; c < n; c++) {
656
+ const a = e.i16();
657
+ i[c] = { advanceWidth: r, lsb: a };
658
658
  }
659
- return o;
659
+ return i;
660
660
  }
661
- function bo(e, n, t, s) {
662
- const i = new gt(e, n), o = t + 1, p = new Array(o);
663
- if (s === 0)
664
- for (let c = 0; c < o; c++) p[c] = i.u16() * 2;
661
+ function pe(s, t, n, o) {
662
+ const e = new At(s, t), i = n + 1, r = [];
663
+ if (o === 0)
664
+ for (let c = 0; c < i; c++) r[c] = e.u16() * 2;
665
665
  else
666
- for (let c = 0; c < o; c++) p[c] = i.u32();
667
- return p;
668
- }
669
- function Ao(e, n) {
670
- const t = new gt(e, n);
671
- return t.skip(4), { numGlyphs: t.u16() };
672
- }
673
- const wo = 1, Do = 2, Eo = 4, qo = 8, Ts = 16, ms = 32, vo = 1, ks = 2, Co = 8, Io = 32, Ro = 64, To = 128;
674
- function mo(e, n, t, s, i) {
675
- const o = Ks(e, n, t, s, i), p = [];
676
- for (const c of o) {
677
- const r = So(c);
678
- r.length > 0 && p.push(r);
679
- }
680
- return { contours: p, inverseYAxis: !1 };
681
- }
682
- function Ks(e, n, t, s, i) {
683
- if (s === 0) return [];
684
- const o = n + t, p = new gt(e, o), c = p.i16();
685
- return p.skip(8), c >= 0 ? ko(p, c) : Lo(e, p, n, i);
686
- }
687
- function ko(e, n) {
688
- if (n === 0) return [];
689
- const t = new Array(n);
690
- for (let a = 0; a < n; a++) t[a] = e.u16();
691
- const s = (t[n - 1] ?? 0) + 1, i = e.u16();
692
- e.skip(i);
693
- const o = new Uint8Array(s);
694
- for (let a = 0; a < s; ) {
695
- const f = e.u8();
696
- if (o[a++] = f, f & qo) {
697
- let y = e.u8();
698
- for (; y-- > 0; ) o[a++] = f;
666
+ for (let c = 0; c < i; c++) r[c] = e.u32();
667
+ return r;
668
+ }
669
+ function fe(s, t) {
670
+ const n = new At(s, t);
671
+ return n.skip(4), { numGlyphs: n.u16() };
672
+ }
673
+ const ue = 1, ye = 2, xe = 4, _e = 8, ro = 16, ao = 32, ge = 1, lo = 2, de = 8, Me = 32, me = 64, be = 128;
674
+ function we(s, t, n, o, e) {
675
+ const i = Oo(s, t, n, o, e), r = [];
676
+ for (const c of i) {
677
+ const a = Ie(c);
678
+ a.length > 0 && r.push(a);
679
+ }
680
+ return { contours: r, inverseYAxis: !1 };
681
+ }
682
+ function Oo(s, t, n, o, e) {
683
+ if (o === 0) return [];
684
+ const i = t + n, r = new At(s, i), c = r.i16();
685
+ return r.skip(8), c >= 0 ? Ae(r, c) : Ee(s, r, t, e);
686
+ }
687
+ function Ae(s, t) {
688
+ if (t === 0) return [];
689
+ const n = [];
690
+ for (let p = 0; p < t; p++) n[p] = s.u16();
691
+ const o = (n[t - 1] ?? 0) + 1, e = s.u16();
692
+ s.skip(e);
693
+ const i = new Uint8Array(o);
694
+ for (let p = 0; p < o; ) {
695
+ const f = s.u8();
696
+ if (i[p++] = f, f & _e) {
697
+ let u = s.u8();
698
+ for (; u-- > 0; ) i[p++] = f;
699
699
  }
700
700
  }
701
- const p = new Float64Array(s);
701
+ const r = new Float64Array(o);
702
702
  let c = 0;
703
- for (let a = 0; a < s; a++) {
704
- const f = o[a] ?? 0;
705
- if (f & Do) {
706
- const y = e.u8();
707
- c += f & Ts ? y : -y;
708
- } else f & Ts || (c += e.i16());
709
- p[a] = c;
710
- }
711
- const r = new Float64Array(s);
703
+ for (let p = 0; p < o; p++) {
704
+ const f = i[p] ?? 0;
705
+ if (f & ye) {
706
+ const u = s.u8();
707
+ c += f & ro ? u : -u;
708
+ } else f & ro || (c += s.i16());
709
+ r[p] = c;
710
+ }
711
+ const a = new Float64Array(o);
712
712
  c = 0;
713
- for (let a = 0; a < s; a++) {
714
- const f = o[a] ?? 0;
715
- if (f & Eo) {
716
- const y = e.u8();
717
- c += f & ms ? y : -y;
718
- } else f & ms || (c += e.i16());
719
- r[a] = c;
720
- }
721
- const h = [];
722
- let l = 0;
723
- for (let a = 0; a < n; a++) {
724
- const f = t[a] ?? 0, y = Fo(o, p, r, l, f);
725
- y.length > 0 && h.push(y), l = f + 1;
726
- }
727
- return h;
728
- }
729
- function Fo(e, n, t, s, i) {
730
- const o = i - s + 1;
731
- if (o <= 0) return [];
732
- const p = [];
733
- for (let c = 0; c < o; c++) {
734
- const r = e[s + c] ?? 0, h = n[s + c] ?? 0, l = t[s + c] ?? 0;
735
- p.push({ x: h, y: l, onCurve: (r & wo) !== 0 });
713
+ for (let p = 0; p < o; p++) {
714
+ const f = i[p] ?? 0;
715
+ if (f & xe) {
716
+ const u = s.u8();
717
+ c += f & ao ? u : -u;
718
+ } else f & ao || (c += s.i16());
719
+ a[p] = c;
720
+ }
721
+ const l = [];
722
+ let h = 0;
723
+ for (let p = 0; p < t; p++) {
724
+ const f = n[p] ?? 0, u = ke(i, r, a, h, f);
725
+ u.length > 0 && l.push(u), h = f + 1;
726
+ }
727
+ return l;
728
+ }
729
+ function ke(s, t, n, o, e) {
730
+ const i = e - o + 1;
731
+ if (i <= 0) return [];
732
+ const r = [];
733
+ for (let c = 0; c < i; c++) {
734
+ const a = s[o + c] ?? 0, l = t[o + c] ?? 0, h = n[o + c] ?? 0;
735
+ r.push({ x: l, y: h, onCurve: (a & ue) !== 0 });
736
736
  }
737
- return p;
737
+ return r;
738
738
  }
739
- function So(e) {
740
- const n = e.length;
741
- if (n <= 0) return [];
742
- const t = [];
743
- for (let c = 0; c < n; c++) {
744
- const r = e[c], h = e[(c + 1) % n];
745
- t.push(r), !r.onCurve && !h.onCurve && t.push({
746
- x: Math.trunc((r.x + h.x) / 2),
747
- y: Math.trunc((r.y + h.y) / 2),
739
+ function Ie(s) {
740
+ const t = s.length;
741
+ if (t <= 0) return [];
742
+ const n = [];
743
+ for (let c = 0; c < t; c++) {
744
+ const a = s[c], l = s[(c + 1) % t];
745
+ n.push(a), !a.onCurve && !l.onCurve && n.push({
746
+ x: Math.trunc((a.x + l.x) / 2),
747
+ y: Math.trunc((a.y + l.y) / 2),
748
748
  onCurve: !0
749
749
  });
750
750
  }
751
- const s = t.length;
752
- let i = 0;
753
- if (!t[0].onCurve) {
754
- for (let c = 1; c < s; c++)
755
- if (t[c].onCurve) {
756
- i = c;
751
+ const o = n.length;
752
+ let e = 0;
753
+ if (!n[0].onCurve) {
754
+ for (let c = 1; c < o; c++)
755
+ if (n[c].onCurve) {
756
+ e = c;
757
757
  break;
758
758
  }
759
759
  }
760
- const o = [];
761
- let p = 0;
762
- for (; p < s; ) {
763
- const c = t[(i + p) % s], r = t[(i + p + 1) % s];
764
- if (r.onCurve)
765
- o.push(new et(at, c.x, c.y, r.x, r.y, 0, 0, 0, 0)), p += 1;
760
+ const i = [];
761
+ let r = 0;
762
+ for (; r < o; ) {
763
+ const c = n[(e + r) % o], a = n[(e + r + 1) % o];
764
+ if (a.onCurve)
765
+ i.push(new st(nt, c.x, c.y, a.x, a.y, 0, 0, 0, 0)), r += 1;
766
766
  else {
767
- const h = t[(i + p + 2) % s];
768
- o.push(new et(it, c.x, c.y, r.x, r.y, h.x, h.y, 0, 0)), p += 2;
767
+ const l = n[(e + r + 2) % o];
768
+ i.push(new st(ct, c.x, c.y, a.x, a.y, l.x, l.y, 0, 0)), r += 2;
769
769
  }
770
770
  }
771
- return o;
772
- }
773
- function Lo(e, n, t, s) {
774
- const i = [];
775
- let o = 0;
776
- do {
777
- o = n.u16();
778
- const p = n.u16();
779
- let c, r;
780
- o & vo ? (c = n.i16(), r = n.i16()) : (c = n.u8(), r = n.u8(), o & ks && (c > 127 && (c -= 256), r > 127 && (r -= 256)));
781
- let h = 0, l = 0;
782
- o & ks && (h = c, l = r);
783
- let a = 1, f = 0, y = 0, _ = 1;
784
- o & Co ? a = _ = n.f2dot14() : o & Ro ? (a = n.f2dot14(), _ = n.f2dot14()) : o & To && (a = n.f2dot14(), f = n.f2dot14(), y = n.f2dot14(), _ = n.f2dot14());
785
- const u = s(p), x = Go(u, a, f, y, _, h, l);
786
- for (const M of x) i.push(M);
787
- } while (o & Io);
788
771
  return i;
789
772
  }
790
- function Fs(e) {
791
- return e >= 0 ? Math.floor(e + 0.5) : Math.ceil(e - 0.5);
792
- }
793
- function Go(e, n, t, s, i, o, p) {
794
- if (n === 1 && t === 0 && s === 0 && i === 1 && o === 0 && p === 0) return e;
795
- const r = n === 1 && t === 0 && s === 0 && i === 1;
796
- return e.map(
797
- (h) => h.map((l) => r ? { x: l.x + o, y: l.y + p, onCurve: l.onCurve } : {
798
- x: Fs(n * l.x + t * l.y + o),
799
- y: Fs(s * l.x + i * l.y + p),
800
- onCurve: l.onCurve
773
+ function Ee(s, t, n, o) {
774
+ const e = [];
775
+ let i = 0;
776
+ do {
777
+ i = t.u16();
778
+ const r = t.u16();
779
+ let c, a;
780
+ i & ge ? (c = t.i16(), a = t.i16()) : (c = t.u8(), a = t.u8(), i & lo && (c > 127 && (c -= 256), a > 127 && (a -= 256)));
781
+ let l = 0, h = 0;
782
+ i & lo && (l = c, h = a);
783
+ let p = 1, f = 0, u = 0, y = 1;
784
+ i & de ? p = y = t.f2dot14() : i & me ? (p = t.f2dot14(), y = t.f2dot14()) : i & be && (p = t.f2dot14(), f = t.f2dot14(), u = t.f2dot14(), y = t.f2dot14());
785
+ const x = o(r), g = De(x, p, f, u, y, l, h);
786
+ for (const M of g) e.push(M);
787
+ } while (i & Me);
788
+ return e;
789
+ }
790
+ function ho(s) {
791
+ return s >= 0 ? Math.floor(s + 0.5) : Math.ceil(s - 0.5);
792
+ }
793
+ function De(s, t, n, o, e, i, r) {
794
+ if (t === 1 && n === 0 && o === 0 && e === 1 && i === 0 && r === 0) return s;
795
+ const a = t === 1 && n === 0 && o === 0 && e === 1;
796
+ return s.map(
797
+ (l) => l.map((h) => a ? { x: h.x + i, y: h.y + r, onCurve: h.onCurve } : {
798
+ x: ho(t * h.x + n * h.y + i),
799
+ y: ho(o * h.x + e * h.y + r),
800
+ onCurve: h.onCurve
801
801
  })
802
802
  );
803
803
  }
804
- function Oo(e, n) {
805
- const t = new gt(e, n);
806
- if (t.u16() !== 0)
807
- return Ss;
808
- const i = t.u16(), o = /* @__PURE__ */ new Map();
809
- for (let p = 0; p < i; p++) {
810
- const c = t.pos;
811
- t.skip(2);
812
- const r = t.u16(), h = t.u16(), l = h >> 8 & 255, a = !(h & 2), f = !!(h & 4);
813
- if (l !== 0 || !a || f) {
814
- t.seek(c + r);
804
+ function qe(s, t) {
805
+ const n = new At(s, t);
806
+ if (n.u16() !== 0)
807
+ return po;
808
+ const e = n.u16(), i = /* @__PURE__ */ new Map();
809
+ for (let r = 0; r < e; r++) {
810
+ const c = n.pos;
811
+ n.skip(2);
812
+ const a = n.u16(), l = n.u16(), h = l >> 8 & 255, p = !(l & 2), f = !!(l & 4);
813
+ if (h !== 0 || !p || f) {
814
+ n.seek(c + a);
815
815
  continue;
816
816
  }
817
- const y = t.u16();
818
- t.skip(6);
819
- for (let _ = 0; _ < y; _++) {
820
- const u = t.u16(), x = t.u16(), M = t.i16(), w = (u & 65535) << 16 | x & 65535;
821
- o.set(w, M);
817
+ const u = n.u16();
818
+ n.skip(6);
819
+ for (let y = 0; y < u; y++) {
820
+ const x = n.u16(), g = n.u16(), M = n.i16(), b = (x & 65535) << 16 | g & 65535;
821
+ i.set(b, M);
822
822
  }
823
- t.seek(c + r);
823
+ n.seek(c + a);
824
824
  }
825
- return o.size === 0 ? Ss : (p, c) => {
826
- const r = (p & 65535) << 16 | c & 65535;
827
- return o.get(r) ?? 0;
825
+ return i.size === 0 ? po : (r, c) => {
826
+ const a = (r & 65535) << 16 | c & 65535;
827
+ return i.get(a) ?? 0;
828
828
  };
829
829
  }
830
- const Ss = () => 0;
831
- function Po(e) {
832
- const n = new gt(e);
833
- if (n.u32() === 1953784678) {
834
- if (n.skip(4), n.u32() === 0) throw new Error("TTC contains no fonts");
835
- const i = n.u32();
836
- n.seek(i);
830
+ const po = () => 0;
831
+ function Ce(s) {
832
+ const t = new At(s);
833
+ if (t.u32() === 1953784678) {
834
+ if (t.skip(4), t.u32() === 0) throw new Error("TTC contains no fonts");
835
+ const e = t.u32();
836
+ t.seek(e);
837
837
  } else
838
- n.seek(0);
839
- return No(e, n);
838
+ t.seek(0);
839
+ return ve(s, t);
840
840
  }
841
- function No(e, n) {
842
- n.skip(4);
843
- const t = n.u16();
844
- n.skip(6);
845
- const s = /* @__PURE__ */ new Map();
846
- for (let i = 0; i < t; i++) {
847
- const o = String.fromCharCode(n.u8(), n.u8(), n.u8(), n.u8());
848
- n.skip(4);
849
- const p = n.u32(), c = n.u32();
850
- s.set(o, { offset: p, length: c });
841
+ function ve(s, t) {
842
+ t.skip(4);
843
+ const n = t.u16();
844
+ t.skip(6);
845
+ const o = /* @__PURE__ */ new Map();
846
+ for (let e = 0; e < n; e++) {
847
+ const i = String.fromCharCode(t.u8(), t.u8(), t.u8(), t.u8());
848
+ t.skip(4);
849
+ const r = t.u32(), c = t.u32();
850
+ o.set(i, { offset: r, length: c });
851
851
  }
852
- return s;
852
+ return o;
853
853
  }
854
- class Di {
854
+ class Ti {
855
855
  /**
856
856
  * Parses a TrueType font from an ArrayBuffer.
857
857
  *
@@ -861,20 +861,20 @@ class Di {
861
861
  *
862
862
  * @param buffer Raw font file bytes.
863
863
  */
864
- constructor(n) {
865
- this._buffer = n, this._tables = Po(n);
866
- const t = this._tables.get("head"), s = this._tables.get("maxp"), i = this._tables.get("hhea"), o = this._tables.get("hmtx"), p = this._tables.get("loca"), c = this._tables.get("cmap");
867
- if (!t) throw new Error("Font missing required `head` table");
868
- if (!s) throw new Error("Font missing required `maxp` table");
869
- if (!i) throw new Error("Font missing required `hhea` table");
870
- if (!o) throw new Error("Font missing required `hmtx` table");
871
- if (!p) throw new Error("Font missing required `loca` table");
864
+ constructor(t) {
865
+ this._buffer = t, this._tables = Ce(t);
866
+ const n = this._tables.get("head"), o = this._tables.get("maxp"), e = this._tables.get("hhea"), i = this._tables.get("hmtx"), r = this._tables.get("loca"), c = this._tables.get("cmap");
867
+ if (!n) throw new Error("Font missing required `head` table");
868
+ if (!o) throw new Error("Font missing required `maxp` table");
869
+ if (!e) throw new Error("Font missing required `hhea` table");
870
+ if (!i) throw new Error("Font missing required `hmtx` table");
871
+ if (!r) throw new Error("Font missing required `loca` table");
872
872
  if (!c) throw new Error("Font missing required `cmap` table");
873
- this._head = xo(n, t.offset);
874
- const r = Ao(n, s.offset);
875
- this._hhea = Mo(n, i.offset), this._hmtx = go(n, o.offset, r.numGlyphs, this._hhea.numberOfHMetrics), this._loca = bo(n, p.offset, r.numGlyphs, this._head.indexToLocFormat), this._cmap = yo(n, c.offset);
876
- const h = this._tables.get("kern");
877
- this._kern = h ? Oo(n, h.offset) : () => 0, this.metrics = {
873
+ this._head = ae(t, n.offset);
874
+ const a = fe(t, o.offset);
875
+ this._hhea = le(t, e.offset), this._hmtx = he(t, i.offset, a.numGlyphs, this._hhea.numberOfHMetrics), this._loca = pe(t, r.offset, a.numGlyphs, this._head.indexToLocFormat), this._cmap = ie(t, c.offset);
876
+ const l = this._tables.get("kern");
877
+ this._kern = l ? qe(t, l.offset) : () => 0, this.metrics = {
878
878
  unitsPerEm: this._head.unitsPerEm,
879
879
  ascender: this._hhea.ascender,
880
880
  descender: this._hhea.descender,
@@ -887,8 +887,8 @@ class Di {
887
887
  *
888
888
  * @param codepoint Unicode scalar value.
889
889
  */
890
- glyphId(n) {
891
- return this._cmap(n);
890
+ glyphId(t) {
891
+ return this._cmap(t);
892
892
  }
893
893
  /**
894
894
  * Total glyph count (`maxp.numGlyphs`), including `.notdef` at index 0.
@@ -906,16 +906,16 @@ class Di {
906
906
  *
907
907
  * @param glyphId Glyph index.
908
908
  */
909
- advance(n) {
910
- return (this._hmtx[n] ?? this._hmtx[this._hmtx.length - 1] ?? { advanceWidth: 0 }).advanceWidth;
909
+ advance(t) {
910
+ return (this._hmtx[t] ?? this._hmtx[this._hmtx.length - 1] ?? { advanceWidth: 0 }).advanceWidth;
911
911
  }
912
912
  /**
913
913
  * Left side bearing of a glyph in font units.
914
914
  *
915
915
  * @param glyphId Glyph index.
916
916
  */
917
- lsb(n) {
918
- return (this._hmtx[n] ?? this._hmtx[this._hmtx.length - 1] ?? { lsb: 0 }).lsb;
917
+ lsb(t) {
918
+ return (this._hmtx[t] ?? this._hmtx[this._hmtx.length - 1] ?? { lsb: 0 }).lsb;
919
919
  }
920
920
  /**
921
921
  * Kerning adjustment between two glyphs in font units.
@@ -924,8 +924,8 @@ class Di {
924
924
  * @param leftGlyphId Left glyph index.
925
925
  * @param rightGlyphId Right glyph index.
926
926
  */
927
- kerning(n, t) {
928
- return this._kern(n, t);
927
+ kerning(t, n) {
928
+ return this._kern(t, n);
929
929
  }
930
930
  /**
931
931
  * Parses and returns the outline of a glyph as a Shape (raw font units, y-up).
@@ -939,15 +939,15 @@ class Di {
939
939
  * @param glyphId Glyph index.
940
940
  * @returns Shape with contours in font units, inverseYAxis=false.
941
941
  */
942
- shape(n) {
943
- const t = this._tables.get("glyf");
944
- if (!t) return { contours: [], inverseYAxis: !1 };
945
- const s = this._loca, i = s[n] ?? 0, p = (s[n + 1] ?? i) - i;
946
- return mo(
942
+ shape(t) {
943
+ const n = this._tables.get("glyf");
944
+ if (!n) return { contours: [], inverseYAxis: !1 };
945
+ const o = this._loca, e = o[t] ?? 0, r = (o[t + 1] ?? e) - e;
946
+ return we(
947
947
  this._buffer,
948
- t.offset,
949
- i,
950
- p,
948
+ n.offset,
949
+ e,
950
+ r,
951
951
  (c) => this._glyphRaw(c)
952
952
  );
953
953
  }
@@ -957,586 +957,867 @@ class Di {
957
957
  * merged outline (matching FreeType).
958
958
  * @internal
959
959
  */
960
- _glyphRaw(n) {
961
- const t = this._tables.get("glyf");
962
- if (!t) return [];
963
- const s = this._loca, i = s[n] ?? 0, p = (s[n + 1] ?? i) - i;
964
- return Ks(
960
+ _glyphRaw(t) {
961
+ const n = this._tables.get("glyf");
962
+ if (!n) return [];
963
+ const o = this._loca, e = o[t] ?? 0, r = (o[t + 1] ?? e) - e;
964
+ return Oo(
965
965
  this._buffer,
966
- t.offset,
967
- i,
968
- p,
966
+ n.offset,
967
+ e,
968
+ r,
969
969
  (c) => this._glyphRaw(c)
970
970
  );
971
971
  }
972
972
  }
973
- function Uo(e, n) {
974
- const t = 1 / n;
975
- for (const s of e.contours)
976
- for (let i = 0; i < s.length; i++) {
977
- const o = s[i];
978
- if (o.p0x *= t, o.p0y *= t, o.p1x *= t, o.p1y *= t, o.p2x *= t, o.p2y *= t, o.p3x *= t, o.p3y *= t, o.type === it) {
979
- const p = o.p1x - o.p0x, c = o.p1y - o.p0y, r = o.p2x - o.p1x, h = o.p2y - o.p1y;
980
- J(p, c, r, h) === 0 && (s[i] = new et(at, o.p0x, o.p0y, o.p2x, o.p2y, 0, 0, 0, 0));
973
+ function dn(s, t) {
974
+ const n = 1 / t;
975
+ for (const o of s.contours)
976
+ for (let e = 0; e < o.length; e++) {
977
+ const i = o[e];
978
+ if (i.p0x *= n, i.p0y *= n, i.p1x *= n, i.p1y *= n, i.p2x *= n, i.p2y *= n, i.p3x *= n, i.p3y *= n, i.type === ct) {
979
+ const r = i.p1x - i.p0x, c = i.p1y - i.p0y, a = i.p2x - i.p1x, l = i.p2y - i.p1y;
980
+ K(r, c, a, l) === 0 && (o[e] = new st(nt, i.p0x, i.p0y, i.p2x, i.p2y, 0, 0, 0, 0));
981
+ } else if (i.type === Ct) {
982
+ const r = i.p2x - i.p1x, c = i.p2y - i.p1y, a = 1.5 * i.p1x - 0.5 * i.p0x, l = 1.5 * i.p1y - 0.5 * i.p0y;
983
+ K(i.p1x - i.p0x, i.p1y - i.p0y, r, c) === 0 && K(r, c, i.p3x - i.p2x, i.p3y - i.p2y) === 0 ? o[e] = new st(nt, i.p0x, i.p0y, i.p3x, i.p3y, 0, 0, 0, 0) : a === 1.5 * i.p2x - 0.5 * i.p3x && l === 1.5 * i.p2y - 0.5 * i.p3y && (o[e] = new st(ct, i.p0x, i.p0y, a, l, i.p3x, i.p3y, 0, 0));
981
984
  }
982
985
  }
983
986
  }
984
- const Ls = 1e-6, Yo = 1.1111111111111112, Xo = new Float64Array(16);
985
- function Gs(e, n, t) {
986
- switch (n[t] = e.p0x, n[t + 1] = e.p0y, n[t + 2] = e.p1x, n[t + 3] = e.p1y, e.type) {
987
- case at:
987
+ const fo = 1e-6, Te = 1.1111111111111112, Fe = new Float64Array(16);
988
+ function uo(s, t, n) {
989
+ switch (t[n] = s.p0x, t[n + 1] = s.p0y, t[n + 2] = s.p1x, t[n + 3] = s.p1y, s.type) {
990
+ case nt:
988
991
  return 1;
989
- case it:
990
- return n[t + 4] = e.p2x, n[t + 5] = e.p2y, 2;
992
+ case ct:
993
+ return t[n + 4] = s.p2x, t[n + 5] = s.p2y, 2;
991
994
  default:
992
- return n[t + 4] = e.p2x, n[t + 5] = e.p2y, n[t + 6] = e.p3x, n[t + 7] = e.p3y, 3;
993
- }
994
- }
995
- function Os(e, n, t) {
996
- if (t === 3) {
997
- const s = e[n], i = e[n + 1], o = e[n + 2], p = e[n + 3], c = e[n + 4], r = e[n + 5], h = e[n + 6], l = e[n + 7];
998
- (o === s && p === i || o === h && p === l) && (c === s && r === i || c === h && r === l) && (e[n + 2] = h, e[n + 3] = l, t = 1);
999
- }
1000
- if (t === 2) {
1001
- const s = e[n], i = e[n + 1], o = e[n + 2], p = e[n + 3], c = e[n + 4], r = e[n + 5];
1002
- (o === s && p === i || o === c && p === r) && (e[n + 2] = c, e[n + 3] = r, t = 1);
1003
- }
1004
- return t === 1 && e[n] === e[n + 2] && e[n + 1] === e[n + 3] && (t = 0), t;
1005
- }
1006
- function Wo(e, n) {
1007
- const t = Xo;
1008
- let s = Gs(e, t, 0), i = Gs(n, t, 8);
1009
- if (!(s >= 1 && s <= 3 && i >= 1 && i <= 3) || t[s * 2] !== t[8] || t[s * 2 + 1] !== t[9]) return 0;
1010
- s = Os(t, 0, s), i = Os(t, 8, i);
1011
- const o = t[s * 2], p = t[s * 2 + 1];
1012
- let c = 0, r = 0, h = 0, l = 0, a = 0, f = 0, y = 0, _ = 0, u = 0, x = 0, M = 0, w = 0;
1013
- if (s >= 1 && (c = t[(s - 1) * 2] - o, r = t[(s - 1) * 2 + 1] - p), s >= 2) {
1014
- const H = t[(s - 2) * 2] - t[(s - 1) * 2], z = t[(s - 2) * 2 + 1] - t[(s - 1) * 2 + 1];
1015
- h = H - c, l = z - r;
1016
- }
1017
- if (s >= 3) {
1018
- const H = t[(s - 3) * 2] - t[(s - 2) * 2], z = t[(s - 3) * 2 + 1] - t[(s - 2) * 2 + 1], ht = t[(s - 2) * 2] - t[(s - 1) * 2], st = t[(s - 2) * 2 + 1] - t[(s - 1) * 2 + 1];
1019
- a = H - ht - h, f = z - st - l, h *= 3, l *= 3;
1020
- }
1021
- if (i >= 1 && (y = t[10] - o, _ = t[11] - p), i >= 2) {
1022
- const H = t[12] - t[10], z = t[13] - t[11];
1023
- u = H - y, x = z - _;
1024
- }
1025
- if (i >= 3) {
1026
- const H = t[14] - t[12], z = t[15] - t[13], ht = t[12] - t[10], st = t[13] - t[11];
1027
- M = H - ht - u, w = z - st - x, u *= 3, x *= 3;
1028
- }
1029
- c *= s, r *= s, y *= i, _ *= i;
1030
- const v = c !== 0 || r !== 0;
1031
- if (v && (y !== 0 || _ !== 0)) {
1032
- const H = Math.sqrt(c * c + r * r), z = Math.sqrt(y * y + _ * _), ht = H * J(c, r, u, x) + z * J(h, l, y, _);
1033
- if (ht) return rt(ht);
1034
- const st = H * H * J(c, r, M, w) + H * z * J(h, l, u, x) + z * z * J(a, f, y, _);
1035
- if (st) return rt(st);
1036
- const kt = H * J(h, l, M, w) + z * J(a, f, u, x);
1037
- return rt(kt || J(a, f, M, w));
1038
- }
1039
- let A = 1, D = h, I = l, F = a, T = f, b = y, N = _, R = u, q = x, P = M, X = w;
1040
- if (v && (D = u, I = x, F = M, T = w, b = c, N = r, R = h, q = l, P = a, X = f, A = -1), b !== 0 || N !== 0) {
1041
- const H = J(F, T, b, N);
1042
- if (H) return A * rt(H);
1043
- const z = J(D, I, R, q);
1044
- if (z) return A * rt(z);
1045
- const ht = J(F, T, R, q);
1046
- if (ht) return A * rt(ht);
1047
- const st = J(D, I, P, X);
1048
- return st ? A * rt(st) : A * rt(J(F, T, P, X));
1049
- }
1050
- const Q = Math.sqrt(D * D + I * I), V = Math.sqrt(R * R + q * q), nt = Math.sqrt(Q) * J(D, I, P, X) + Math.sqrt(V) * J(F, T, R, q);
1051
- return rt(nt || J(F, T, P, X));
1052
- }
1053
- function Ps(e, n, t, s, i) {
1054
- let o = e[n];
1055
- if (o.type === it) {
1056
- const p = o.convertToCubic();
1057
- e[n] = p, o = p;
1058
- }
1059
- if (o.type === Ot)
1060
- if (t === 0) {
1061
- const p = Math.sqrt((o.p1x - o.p0x) ** 2 + (o.p1y - o.p0y) ** 2);
1062
- o.p1x += p * s, o.p1y += p * i;
995
+ return t[n + 4] = s.p2x, t[n + 5] = s.p2y, t[n + 6] = s.p3x, t[n + 7] = s.p3y, 3;
996
+ }
997
+ }
998
+ function yo(s, t, n) {
999
+ if (n === 3) {
1000
+ const o = s[t], e = s[t + 1], i = s[t + 2], r = s[t + 3], c = s[t + 4], a = s[t + 5], l = s[t + 6], h = s[t + 7];
1001
+ (i === o && r === e || i === l && r === h) && (c === o && a === e || c === l && a === h) && (s[t + 2] = l, s[t + 3] = h, n = 1);
1002
+ }
1003
+ if (n === 2) {
1004
+ const o = s[t], e = s[t + 1], i = s[t + 2], r = s[t + 3], c = s[t + 4], a = s[t + 5];
1005
+ (i === o && r === e || i === c && r === a) && (s[t + 2] = c, s[t + 3] = a, n = 1);
1006
+ }
1007
+ return n === 1 && s[t] === s[t + 2] && s[t + 1] === s[t + 3] && (n = 0), n;
1008
+ }
1009
+ function Se(s, t) {
1010
+ const n = Fe;
1011
+ let o = uo(s, n, 0), e = uo(t, n, 8);
1012
+ if (!(o >= 1 && o <= 3 && e >= 1 && e <= 3) || n[o * 2] !== n[8] || n[o * 2 + 1] !== n[9]) return 0;
1013
+ o = yo(n, 0, o), e = yo(n, 8, e);
1014
+ const i = n[o * 2], r = n[o * 2 + 1];
1015
+ let c = 0, a = 0, l = 0, h = 0, p = 0, f = 0, u = 0, y = 0, x = 0, g = 0, M = 0, b = 0;
1016
+ if (o >= 1 && (c = n[(o - 1) * 2] - i, a = n[(o - 1) * 2 + 1] - r), o >= 2) {
1017
+ const X = n[(o - 2) * 2] - n[(o - 1) * 2], H = n[(o - 2) * 2 + 1] - n[(o - 1) * 2 + 1];
1018
+ l = X - c, h = H - a;
1019
+ }
1020
+ if (o >= 3) {
1021
+ const X = n[(o - 3) * 2] - n[(o - 2) * 2], H = n[(o - 3) * 2 + 1] - n[(o - 2) * 2 + 1], J = n[(o - 2) * 2] - n[(o - 1) * 2], z = n[(o - 2) * 2 + 1] - n[(o - 1) * 2 + 1];
1022
+ p = X - J - l, f = H - z - h, l *= 3, h *= 3;
1023
+ }
1024
+ if (e >= 1 && (u = n[10] - i, y = n[11] - r), e >= 2) {
1025
+ const X = n[12] - n[10], H = n[13] - n[11];
1026
+ x = X - u, g = H - y;
1027
+ }
1028
+ if (e >= 3) {
1029
+ const X = n[14] - n[12], H = n[15] - n[13], J = n[12] - n[10], z = n[13] - n[11];
1030
+ M = X - J - x, b = H - z - g, x *= 3, g *= 3;
1031
+ }
1032
+ c *= o, a *= o, u *= e, y *= e;
1033
+ const A = c !== 0 || a !== 0;
1034
+ if (A && (u !== 0 || y !== 0)) {
1035
+ const X = Math.sqrt(c * c + a * a), H = Math.sqrt(u * u + y * y), J = X * K(c, a, x, g) + H * K(l, h, u, y);
1036
+ if (J) return ft(J);
1037
+ const z = X * X * K(c, a, M, b) + X * H * K(l, h, x, g) + H * H * K(p, f, u, y);
1038
+ if (z) return ft(z);
1039
+ const Et = X * K(l, h, M, b) + H * K(p, f, x, g);
1040
+ return ft(Et || K(p, f, M, b));
1041
+ }
1042
+ let k = 1, T = l, q = h, m = p, d = f, _ = u, w = y, E = x, I = g, C = M, S = b;
1043
+ if (A && (T = x, q = g, m = M, d = b, _ = c, w = a, E = l, I = h, C = p, S = f, k = -1), _ !== 0 || w !== 0) {
1044
+ const X = K(m, d, _, w);
1045
+ if (X) return k * ft(X);
1046
+ const H = K(T, q, E, I);
1047
+ if (H) return k * ft(H);
1048
+ const J = K(m, d, E, I);
1049
+ if (J) return k * ft(J);
1050
+ const z = K(T, q, C, S);
1051
+ return z ? k * ft(z) : k * ft(K(m, d, C, S));
1052
+ }
1053
+ const O = Math.sqrt(T * T + q * q), L = Math.sqrt(E * E + I * I), W = Math.sqrt(O) * K(T, q, C, S) + Math.sqrt(L) * K(m, d, E, I);
1054
+ return ft(W || K(m, d, C, S));
1055
+ }
1056
+ function xo(s, t, n, o, e) {
1057
+ let i = s[t];
1058
+ if (i.type === ct) {
1059
+ const r = i.convertToCubic();
1060
+ s[t] = r, i = r;
1061
+ }
1062
+ if (i.type === Ct)
1063
+ if (n === 0) {
1064
+ const r = Math.sqrt((i.p1x - i.p0x) ** 2 + (i.p1y - i.p0y) ** 2);
1065
+ i.p1x += r * o, i.p1y += r * e;
1063
1066
  } else {
1064
- const p = Math.sqrt((o.p2x - o.p3x) ** 2 + (o.p2y - o.p3y) ** 2);
1065
- o.p2x += p * s, o.p2y += p * i;
1067
+ const r = Math.sqrt((i.p2x - i.p3x) ** 2 + (i.p2y - i.p3y) ** 2);
1068
+ i.p2x += r * o, i.p2y += r * e;
1066
1069
  }
1067
1070
  }
1068
- const Ft = [0, 0], St = [0, 0];
1069
- function Ho(e) {
1070
- for (let n = 0; n < e.contours.length; n++) {
1071
- const t = e.contours[n];
1072
- let s = 0;
1073
- for (let i = 0; i < t.length; i++) {
1074
- const o = t[i];
1075
- (o.p0x !== o.endX() || o.p0y !== o.endY()) && (t[s++] = o);
1071
+ const Bt = [0, 0], Vt = [0, 0];
1072
+ function Re(s) {
1073
+ for (let t = 0; t < s.contours.length; t++) {
1074
+ const n = s.contours[t];
1075
+ let o = 0;
1076
+ for (let e = 0; e < n.length; e++) {
1077
+ const i = n[e];
1078
+ (i.p0x !== i.endX() || i.p0y !== i.endY()) && (n[o++] = i);
1076
1079
  }
1077
- t.length = s;
1078
- }
1079
- for (const n of e.contours)
1080
- if (n.length === 1) {
1081
- const [t, s, i] = n[0].splitInThirds();
1082
- n.length = 0, n.push(t, s, i);
1083
- } else if (n.length > 0) {
1084
- const t = n.length;
1085
- for (let s = 0; s < t; s++) {
1086
- const i = (s + t - 1) % t, o = n[i], p = n[s];
1087
- o.direction(1, Ft), p.direction(0, St);
1088
- const c = Math.sqrt(Ft[0] ** 2 + Ft[1] ** 2), r = Math.sqrt(St[0] ** 2 + St[1] ** 2);
1089
- if (c === 0 || r === 0) continue;
1090
- const h = Ft[0] / c, l = Ft[1] / c, a = St[0] / r, f = St[1] / r;
1091
- if (io(h, l, a, f) < Ls - 1) {
1092
- const y = Ls - 1, _ = Yo * Math.sqrt(1 - y * y) / y;
1093
- let u = a - h, x = f - l;
1094
- const M = Math.sqrt(u * u + x * x);
1080
+ n.length = o;
1081
+ }
1082
+ for (const t of s.contours)
1083
+ if (t.length === 1) {
1084
+ const [n, o, e] = t[0].splitInThirds();
1085
+ t.length = 0, t.push(n, o, e);
1086
+ } else if (t.length > 0) {
1087
+ const n = t.length;
1088
+ for (let o = 0; o < n; o++) {
1089
+ const e = (o + n - 1) % n, i = t[e], r = t[o];
1090
+ i.direction(1, Bt), r.direction(0, Vt);
1091
+ const c = Math.sqrt(Bt[0] ** 2 + Bt[1] ** 2), a = Math.sqrt(Vt[0] ** 2 + Vt[1] ** 2);
1092
+ if (c === 0 || a === 0) continue;
1093
+ const l = Bt[0] / c, h = Bt[1] / c, p = Vt[0] / a, f = Vt[1] / a;
1094
+ if (Ko(l, h, p, f) < fo - 1) {
1095
+ const u = fo - 1, y = Te * Math.sqrt(1 - u * u) / u;
1096
+ let x = p - l, g = f - h;
1097
+ const M = Math.sqrt(x * x + g * g);
1095
1098
  if (M === 0) continue;
1096
- u = _ * u / M, x = _ * x / M, Wo(o, p) < 0 && (u = -u, x = -x), Ps(n, i, 1, -x, u), Ps(n, s, 0, x, -u);
1099
+ x = y * x / M, g = y * g / M, Se(i, r) < 0 && (x = -x, g = -g), xo(t, e, 1, -g, x), xo(t, o, 0, g, -x);
1100
+ }
1101
+ }
1102
+ }
1103
+ }
1104
+ const _o = [0, 0, 0], go = [0, 0, 0], Mo = [0, 0];
1105
+ function No(s) {
1106
+ const t = 0.5 * (Math.sqrt(5) - 1), n = s.map(() => 0), o = [];
1107
+ for (let e = 0; e < s.length; e++) {
1108
+ const i = s[e];
1109
+ if (n[e] || i.length === 0) continue;
1110
+ const r = i[0].p0y;
1111
+ let c = r;
1112
+ for (let l = 0; l < i.length && r === c; l++) c = i[l].endY();
1113
+ for (let l = 0; l < i.length && r === c; l++)
1114
+ i[l].point(t, Mo), c = Mo[1];
1115
+ const a = Po(r, c, t);
1116
+ for (let l = 0; l < s.length; l++)
1117
+ for (const h of s[l]) {
1118
+ const p = h.scanlineIntersections(a, _o, go);
1119
+ for (let f = 0; f < p; f++) o.push({ x: _o[f], dy: go[f], c: l });
1120
+ }
1121
+ o.sort((l, h) => ft(l.x - h.x));
1122
+ for (let l = 1; l < o.length; l++)
1123
+ o[l].x === o[l - 1].x && (o[l].dy = o[l - 1].dy = 0);
1124
+ for (let l = 0; l < o.length; l++) {
1125
+ const h = o[l];
1126
+ h.dy && (n[h.c] += 2 * (l & 1 ^ (h.dy > 0 ? 1 : 0)) - 1);
1127
+ }
1128
+ o.length = 0;
1129
+ }
1130
+ for (let e = 0; e < s.length; e++) {
1131
+ if (n[e] >= 0) continue;
1132
+ const i = s[e].reverse();
1133
+ for (let r = 0; r < i.length; r++) {
1134
+ const c = i[r];
1135
+ i[r] = c.type === nt ? new st(nt, c.p1x, c.p1y, c.p0x, c.p0y, 0, 0, 0, 0) : c.type === ct ? new st(ct, c.p2x, c.p2y, c.p1x, c.p1y, c.p0x, c.p0y, 0, 0) : new st(Ct, c.p3x, c.p3y, c.p2x, c.p2y, c.p1x, c.p1y, c.p0x, c.p0y);
1136
+ }
1137
+ }
1138
+ }
1139
+ const mo = 1e-5, ms = 1e-6, Le = 2e4, Pe = 1e5;
1140
+ function $e(s) {
1141
+ return [s.p0x, s.p0y, s.p1x, s.p1y, s.p2x, s.p2y, s.p3x, s.p3y].slice(0, 2 * s.type + 4);
1142
+ }
1143
+ function bo(s) {
1144
+ const t = s.length / 2 - 2;
1145
+ return new st(
1146
+ t,
1147
+ s[0],
1148
+ s[1],
1149
+ s[2],
1150
+ s[3],
1151
+ s[4] ?? 0,
1152
+ s[5] ?? 0,
1153
+ s[6] ?? 0,
1154
+ s[7] ?? 0
1155
+ );
1156
+ }
1157
+ const rt = new Float64Array(8), at = new Float64Array(8), Rt = new Float64Array(8);
1158
+ function bs(s, t, n, o) {
1159
+ const e = s.length, i = e / 2 - 1;
1160
+ for (let r = 0; r <= i; r++) {
1161
+ for (let c = 0; c < e; c++) Rt[c] = s[c];
1162
+ for (let c = 0, a = e; c < i; c++, a -= 2) {
1163
+ const l = c < i - r ? t : n;
1164
+ for (let h = 0; h < a - 2; h++) Rt[h] = Rt[h] + l * (Rt[h + 2] - Rt[h]);
1165
+ }
1166
+ o[2 * r] = Rt[0], o[2 * r + 1] = Rt[1];
1167
+ }
1168
+ }
1169
+ function Oe(s, t, n) {
1170
+ return bs(s, t, n, rt), Array.from(rt.subarray(0, s.length));
1171
+ }
1172
+ let ws = 0, As = 0, qt = -1, Jt = -1, tn = 0, nn = 0, Mn = 0, mn = 0;
1173
+ function Ne(s, t) {
1174
+ qt = -1, Jt = -1;
1175
+ let n = 0;
1176
+ for (let h = 0; h < 2; h++) {
1177
+ const p = h ? s.length - 2 : 0;
1178
+ for (let f = 0; f < 2; f++) {
1179
+ const u = f ? t.length - 2 : 0;
1180
+ s[p] === t[u] && s[p + 1] === t[u + 1] && (n++, qt = h, Jt = f);
1181
+ }
1182
+ }
1183
+ if (n !== 1) {
1184
+ qt = -1;
1185
+ return;
1186
+ }
1187
+ const o = qt ? s.length - 2 : 0;
1188
+ tn = s[o], nn = s[o + 1];
1189
+ let e = 0, i = 0;
1190
+ for (let h = 2; h < s.length && e === 0 && i === 0; h += 2) {
1191
+ const p = qt ? s.length - 2 - h : h;
1192
+ e = s[p] - tn, i = s[p + 1] - nn;
1193
+ }
1194
+ let r = 0, c = 0;
1195
+ for (let h = 2; h < t.length && r === 0 && c === 0; h += 2) {
1196
+ const p = Jt ? t.length - 2 - h : h;
1197
+ r = t[p] - tn, c = t[p + 1] - nn;
1198
+ }
1199
+ const a = Math.hypot(e, i), l = Math.hypot(r, c);
1200
+ Mn = e / a - r / l, mn = i / a - c / l, Math.hypot(Mn, mn) > 1e-9 || (qt = -1);
1201
+ }
1202
+ function Ue(s, t) {
1203
+ const n = qt ? s - 2 : 0;
1204
+ for (let e = 0; e < s; e += 2)
1205
+ if (e !== n && (rt[e] - tn) * Mn + (rt[e + 1] - nn) * mn <= 0) return !1;
1206
+ const o = Jt ? t - 2 : 0;
1207
+ for (let e = 0; e < t; e += 2)
1208
+ if (e !== o && (at[e] - tn) * Mn + (at[e + 1] - nn) * mn >= 0) return !1;
1209
+ return !0;
1210
+ }
1211
+ function Kt(s, t, n, o, e, i, r) {
1212
+ if (--ws < 0 || --As < 0) return;
1213
+ const c = s.length, a = o.length;
1214
+ bs(s, t, n, rt), bs(o, e, i, at);
1215
+ let l = 1 / 0, h = 1 / 0, p = -1 / 0, f = -1 / 0;
1216
+ for (let A = 0; A < c; A += 2)
1217
+ l = Math.min(l, rt[A]), h = Math.min(h, rt[A + 1]), p = Math.max(p, rt[A]), f = Math.max(f, rt[A + 1]);
1218
+ let u = 1 / 0, y = 1 / 0, x = -1 / 0, g = -1 / 0;
1219
+ for (let A = 0; A < a; A += 2)
1220
+ u = Math.min(u, at[A]), y = Math.min(y, at[A + 1]), x = Math.max(x, at[A]), g = Math.max(g, at[A + 1]);
1221
+ if (l > x || u > p || h > g || y > f || qt >= 0 && (qt ? n === 1 : t === 0) && (Jt ? i === 1 : e === 0) && Ue(c, a))
1222
+ return;
1223
+ const M = Math.max(p - l, f - h), b = Math.max(x - u, g - y);
1224
+ if (c === 4 && a === 4 || M < mo && b < mo) {
1225
+ const A = rt[c - 2] - rt[0], F = rt[c - 1] - rt[1], k = at[a - 2] - at[0], T = at[a - 1] - at[1], q = K(A, F, k, T), m = K(at[0] - rt[0], at[1] - rt[1], k, T) / q, d = K(at[0] - rt[0], at[1] - rt[1], A, F) / q;
1226
+ m >= 0 && m <= 1 && d >= 0 && d <= 1 && r.push(t + m * (n - t), e + d * (i - e));
1227
+ } else M > b ? (Kt(s, t, (t + n) / 2, o, e, i, r), Kt(s, (t + n) / 2, n, o, e, i, r)) : (Kt(s, t, n, o, e, (e + i) / 2, r), Kt(s, t, n, o, (e + i) / 2, i, r));
1228
+ }
1229
+ function un(s, t, n) {
1230
+ const o = s[2] - s[0], e = s[3] - s[1];
1231
+ return ((t - s[0]) * o + (n - s[1]) * e) / (o * o + e * e);
1232
+ }
1233
+ function Ge(s, t, n) {
1234
+ if (s.length !== 4 || t.length !== 4) return !1;
1235
+ const o = s[2] - s[0], e = s[3] - s[1], i = 1e-9 * Math.hypot(o, e);
1236
+ return Math.abs(K(o, e, t[0] - s[0], t[1] - s[1])) > i || Math.abs(K(o, e, t[2] - s[0], t[3] - s[1])) > i ? !1 : (n.push(un(s, t[0], t[1]), 0, un(s, t[2], t[3]), 1), n.push(0, un(t, s[0], s[1]), 1, un(t, s[2], s[3])), !0);
1237
+ }
1238
+ function Ye(s) {
1239
+ const t = [];
1240
+ for (let n = s.length - 2; n >= 0; n -= 2) t.push(s[n], s[n + 1]);
1241
+ return t;
1242
+ }
1243
+ function Xe(s, t) {
1244
+ if (s.length !== t.length) return !1;
1245
+ for (let n = 0; n < s.length; n++) if (!(Math.abs(s[n] - t[n]) < ms)) return !1;
1246
+ return !0;
1247
+ }
1248
+ const jt = [0, 0], Lt = [0, 0], bn = [0, 0, 0], wn = [0, 0, 0];
1249
+ let Wt = new Int32Array(8);
1250
+ const We = 0, Uo = 1, He = 2;
1251
+ function wo(s, t, n, o) {
1252
+ let e = 0;
1253
+ for (let i = 0; i < s.length; i++) {
1254
+ if (o < t[4 * i + 1] - 1e-9 || o > t[4 * i + 3] + 1e-9) continue;
1255
+ const r = s[i].scanlineIntersections(o, bn, wn);
1256
+ for (let c = 0; c < r; c++) bn[c] <= n && (e += wn[c]);
1257
+ }
1258
+ return e !== 0;
1259
+ }
1260
+ function Ao(s, t, n, o, e, i, r) {
1261
+ Wt.fill(0, 0, n);
1262
+ for (let a = 0; a < s.length; a++) {
1263
+ if (r < e[4 * a + 1] - 1e-9 || r > e[4 * a + 3] + 1e-9) continue;
1264
+ const l = s[a].scanlineIntersections(r, bn, wn);
1265
+ for (let h = 0; h < l; h++) bn[h] <= i && (Wt[t[a]] += wn[h]);
1266
+ }
1267
+ let c = !1;
1268
+ for (let a = 1; a < n && !c; a++) c = Wt[a] !== 0;
1269
+ return Wt[0] !== 0 && (o === Uo ? c : !c);
1270
+ }
1271
+ function Be(s) {
1272
+ const t = Is([s.contours]);
1273
+ t && (s.contours = t);
1274
+ }
1275
+ function ko(s, t) {
1276
+ const n = Is([s.contours, ...t.length > 0 ? t : [[]]], Uo);
1277
+ n && (s.contours = n);
1278
+ }
1279
+ function Ve(s, t) {
1280
+ if (t.length === 0) return;
1281
+ const n = Is([s.contours, ...t], He);
1282
+ n && (s.contours = n);
1283
+ }
1284
+ function Is(s, t = We) {
1285
+ const n = s.flat(), o = n.flat(), e = o.map($e), i = e.length, r = s.length, c = r > 1;
1286
+ Wt.length < r && (Wt = new Int32Array(r));
1287
+ const a = new Float64Array(4 * i), l = new Int32Array(i), h = new Int32Array(i);
1288
+ let p = 0;
1289
+ for (let m = 0; m < r; m++)
1290
+ for (const d of s[m]) {
1291
+ for (let _ = 0; _ < d.length; _++)
1292
+ l[p + _] = p + (_ + 1) % d.length, h[p + _] = m;
1293
+ p += d.length;
1294
+ }
1295
+ for (let m = 0; m < i; m++) {
1296
+ const d = e[m];
1297
+ let _ = 1 / 0, w = 1 / 0, E = -1 / 0, I = -1 / 0;
1298
+ for (let C = 0; C < d.length; C += 2)
1299
+ _ = Math.min(_, d[C]), w = Math.min(w, d[C + 1]), E = Math.max(E, d[C]), I = Math.max(I, d[C + 1]);
1300
+ a[4 * m] = _, a[4 * m + 1] = w, a[4 * m + 2] = E, a[4 * m + 3] = I;
1301
+ }
1302
+ const f = Array.from({ length: i }, (m, d) => d).sort((m, d) => a[4 * m] - a[4 * d]), u = e.map(() => []), y = new Uint8Array(i);
1303
+ As = Pe;
1304
+ for (let m = 0; m < i; m++) {
1305
+ const d = f[m];
1306
+ for (let _ = m + 1; _ < i; _++) {
1307
+ const w = f[_];
1308
+ if (a[4 * w] > a[4 * d + 2]) break;
1309
+ if (a[4 * d + 1] > a[4 * w + 3] || a[4 * w + 1] > a[4 * d + 3]) continue;
1310
+ const E = Math.min(d, w), I = Math.max(d, w);
1311
+ l[E] !== I && l[I] !== E && (y[E] = y[I] = 1);
1312
+ const C = [];
1313
+ if (ws = Le, Ge(e[E], e[I], C) || (Ne(e[E], e[I]), Kt(e[E], 0, 1, e[I], 0, 1, C)), ws < 0 || As < 0) return null;
1314
+ for (let S = 0; S < C.length; S += 2)
1315
+ u[E].push(C[S]), u[I].push(C[S + 1]);
1316
+ }
1317
+ }
1318
+ const x = u.map((m) => {
1319
+ const d = [0];
1320
+ for (const _ of m.sort((w, E) => w - E))
1321
+ _ - d[d.length - 1] > 1e-7 && _ < 1 - 1e-7 && d.push(_);
1322
+ return d.push(1), d;
1323
+ });
1324
+ let g = !1;
1325
+ const M = [], b = [];
1326
+ let A = 0;
1327
+ for (const m of n) {
1328
+ const d = A + m.length;
1329
+ let _ = !0;
1330
+ for (let C = A; C < d; C++) (y[C] || x[C].length > 2) && (_ = !1);
1331
+ let w = !1, E = !1, I = !1;
1332
+ for (let C = A; C < d; C++) {
1333
+ const S = x[C];
1334
+ for (let O = 1; O < S.length; O++) {
1335
+ const L = Oe(e[C], S[O - 1], S[O]), W = bo(L);
1336
+ W.point(0.5, jt), W.direction(0.5, Lt);
1337
+ const X = Math.hypot(Lt[0], Lt[1]), H = Math.hypot(L[L.length - 2] - L[0], L[L.length - 1] - L[1]);
1338
+ if (!(X === 0 || H === 0)) {
1339
+ if (!_ || !w) {
1340
+ const J = Math.min(1e-6, H * H / 64) / X, z = jt[0] + Lt[1] * J, Et = jt[1] - Lt[0] * J, ht = jt[0] - Lt[1] * J, vt = jt[1] + Lt[0] * J;
1341
+ E = c ? Ao(o, h, r, t, a, z, Et) : wo(o, a, z, Et), I = c ? Ao(o, h, r, t, a, ht, vt) : wo(o, a, ht, vt), w = !0;
1342
+ }
1343
+ E === I ? h[C] === 0 && (g = !0) : (M.push(L), b.push(E), h[C] !== 0 && (g = !0));
1097
1344
  }
1098
1345
  }
1099
1346
  }
1347
+ A = d;
1348
+ }
1349
+ const F = 2 * b.filter(Boolean).length >= b.length, k = [];
1350
+ for (let m = 0; m < M.length; m++) {
1351
+ let d = M[m];
1352
+ b[m] !== F && (d = Ye(d), g = !0);
1353
+ let _ = !1;
1354
+ for (let w = 0; w < k.length && !_; w++) _ = Xe(k[w], d);
1355
+ _ ? g = !0 : k.push(d);
1356
+ }
1357
+ if (!g) return null;
1358
+ const T = new Uint8Array(k.length), q = [];
1359
+ for (let m = 0; m < k.length; m++) {
1360
+ if (T[m]) continue;
1361
+ T[m] = 1;
1362
+ const d = [k[m]];
1363
+ for (; ; ) {
1364
+ const _ = d[d.length - 1], w = _[_.length - 2], E = _[_.length - 1];
1365
+ if (d.length > 1 && Math.hypot(w - d[0][0], E - d[0][1]) < ms) {
1366
+ d[0][0] = w, d[0][1] = E;
1367
+ break;
1368
+ }
1369
+ let I = -1, C = ms;
1370
+ for (let S = 0; S < k.length; S++) {
1371
+ if (T[S]) continue;
1372
+ const O = Math.hypot(k[S][0] - w, k[S][1] - E);
1373
+ O < C && (I = S, C = O);
1374
+ }
1375
+ if (I < 0) return null;
1376
+ T[I] = 1, k[I][0] = w, k[I][1] = E, d.push(k[I]);
1377
+ }
1378
+ q.push(d.map(bo));
1379
+ }
1380
+ return q;
1100
1381
  }
1101
- const Jt = 1, tn = 2, Vo = 3, nn = 4, zo = 5, Bo = 6, Qn = 7, ot = [0, 0], Et = [0, 0];
1102
- function Qo(e, n) {
1103
- return Math.trunc(3 + 2.875 * e / (n - 1) - 1.4375 + 0.5) - 3;
1382
+ const qn = 1, Cn = 2, je = 3, vn = 4, ze = 5, Qe = 6, Es = 7, pt = [0, 0], Pt = [0, 0];
1383
+ function Ke(s, t) {
1384
+ return Math.trunc(3 + 2.875 * s / (t - 1) - 1.4375 + 0.5) - 3;
1104
1385
  }
1105
- function $o(e, n, t, s, i) {
1106
- return e * t + n * s <= 0 || Math.abs(e * s - n * t) > i;
1386
+ function Ze(s, t, n, o, e) {
1387
+ return s * n + t * o <= 0 || Math.abs(s * o - t * n) > e;
1107
1388
  }
1108
- function Ko(e) {
1109
- const n = Number(e.v & 1n);
1110
- return e.v >>= 1n, n;
1389
+ function Je(s) {
1390
+ const t = Number(s.v & 1n);
1391
+ return s.v >>= 1n, t;
1111
1392
  }
1112
- function Zo(e) {
1113
- const n = Number(e.v % 3n);
1114
- return e.v /= 3n, n;
1393
+ function ti(s) {
1394
+ const t = Number(s.v % 3n);
1395
+ return s.v /= 3n, t;
1115
1396
  }
1116
- function Ns(e) {
1117
- return [Bo, zo, Vo][Zo(e)];
1397
+ function Io(s) {
1398
+ return [Qe, ze, je][ti(s)];
1118
1399
  }
1119
- function Pt(e, n) {
1120
- const t = e.v << 1 + Ko(n);
1121
- e.v = (t | t >> 3) & Qn;
1400
+ function Zt(s, t) {
1401
+ const n = s.v << 1 + Je(t);
1402
+ s.v = (n | n >> 3) & Es;
1122
1403
  }
1123
- function jo(e, n, t) {
1124
- const s = e.v & t;
1125
- s === Jt || s === tn || s === nn ? e.v = s ^ Qn : Pt(e, n);
1404
+ function ni(s, t, n) {
1405
+ const o = s.v & n;
1406
+ o === qn || o === Cn || o === vn ? s.v = o ^ Es : Zt(s, t);
1126
1407
  }
1127
- function Jo(e, n, t = 0n) {
1128
- const s = Math.sin(n), i = { v: Ns({ v: t }) }, o = { v: t };
1129
- o.v = t, i.v = Ns(o);
1130
- const p = [];
1131
- for (const c of e.contours) {
1408
+ function si(s, t, n = 0n) {
1409
+ const o = Math.sin(t), e = { v: Io({ v: n }) }, i = { v: n };
1410
+ i.v = n, e.v = Io(i);
1411
+ const r = [];
1412
+ for (const c of s.contours) {
1132
1413
  if (c.length === 0) continue;
1133
- p.length = 0, c[c.length - 1].direction(1, ot);
1134
- const h = Math.sqrt(ot[0] * ot[0] + ot[1] * ot[1]);
1135
- let l = h > 0 ? ot[0] / h : 0, a = h > 0 ? ot[1] / h : 0;
1414
+ r.length = 0, c[c.length - 1].direction(1, pt);
1415
+ const l = Math.sqrt(pt[0] * pt[0] + pt[1] * pt[1]);
1416
+ let h = l > 0 ? pt[0] / l : 0, p = l > 0 ? pt[1] / l : 0;
1136
1417
  for (let f = 0; f < c.length; f++) {
1137
- const y = c[f];
1138
- y.direction(0, Et);
1139
- const _ = Math.sqrt(Et[0] * Et[0] + Et[1] * Et[1]), u = _ > 0 ? Et[0] / _ : 0, x = _ > 0 ? Et[1] / _ : 0;
1140
- $o(l, a, u, x, s) && p.push(f), y.direction(1, ot);
1141
- const M = Math.sqrt(ot[0] * ot[0] + ot[1] * ot[1]);
1142
- l = M > 0 ? ot[0] / M : 0, a = M > 0 ? ot[1] / M : 0;
1418
+ const u = c[f];
1419
+ u.direction(0, Pt);
1420
+ const y = Math.sqrt(Pt[0] * Pt[0] + Pt[1] * Pt[1]), x = y > 0 ? Pt[0] / y : 0, g = y > 0 ? Pt[1] / y : 0;
1421
+ Ze(h, p, x, g, o) && r.push(f), u.direction(1, pt);
1422
+ const M = Math.sqrt(pt[0] * pt[0] + pt[1] * pt[1]);
1423
+ h = M > 0 ? pt[0] / M : 0, p = M > 0 ? pt[1] / M : 0;
1143
1424
  }
1144
- if (p.length === 0) {
1145
- Pt(i, o);
1146
- for (const f of c) f.color = i.v;
1147
- } else if (p.length === 1) {
1148
- const f = [0, Qn, 0];
1149
- Pt(i, o), f[0] = i.v, Pt(i, o), f[2] = i.v;
1150
- const y = p[0], _ = c.length;
1151
- if (_ >= 3)
1152
- for (let u = 0; u < _; u++) {
1153
- const x = Qo(u, _);
1154
- c[(y + u) % _].color = f[1 + x];
1425
+ if (r.length === 0) {
1426
+ Zt(e, i);
1427
+ for (const f of c) f.color = e.v;
1428
+ } else if (r.length === 1) {
1429
+ const f = [0, Es, 0];
1430
+ Zt(e, i), f[0] = e.v, Zt(e, i), f[2] = e.v;
1431
+ const u = r[0], y = c.length;
1432
+ if (y >= 3)
1433
+ for (let x = 0; x < y; x++) {
1434
+ const g = Ke(x, y);
1435
+ c[(u + x) % y].color = f[1 + g];
1155
1436
  }
1156
- else if (_ >= 1) {
1157
- const u = [null, null, null, null, null, null, null], x = c[0].splitInThirds();
1158
- if (u[0 + 3 * y] = x[0], u[1 + 3 * y] = x[1], u[2 + 3 * y] = x[2], _ >= 2) {
1437
+ else if (y >= 1) {
1438
+ const x = [null, null, null, null, null, null, null], g = c[0].splitInThirds();
1439
+ if (x[0 + 3 * u] = g[0], x[1 + 3 * u] = g[1], x[2 + 3 * u] = g[2], y >= 2) {
1159
1440
  const M = c[1].splitInThirds();
1160
- u[3 - 3 * y] = M[0], u[4 - 3 * y] = M[1], u[5 - 3 * y] = M[2], u[0].color = u[1].color = f[0], u[2].color = u[3].color = f[1], u[4].color = u[5].color = f[2];
1441
+ x[3 - 3 * u] = M[0], x[4 - 3 * u] = M[1], x[5 - 3 * u] = M[2], x[0].color = x[1].color = f[0], x[2].color = x[3].color = f[1], x[4].color = x[5].color = f[2];
1161
1442
  } else
1162
- u[0].color = f[0], u[1].color = f[1], u[2].color = f[2];
1443
+ x[0].color = f[0], x[1].color = f[1], x[2].color = f[2];
1163
1444
  c.length = 0;
1164
- for (const M of u) M !== null && c.push(M);
1445
+ for (const M of x) M !== null && c.push(M);
1165
1446
  }
1166
1447
  } else {
1167
- const f = p.length;
1168
- let y = 0;
1169
- const _ = p[0], u = c.length;
1170
- Pt(i, o);
1171
- const x = i.v;
1172
- for (let M = 0; M < u; M++) {
1173
- const w = (_ + M) % u;
1174
- y + 1 < f && p[y + 1] === w && (++y, jo(i, o, y === f - 1 ? x : 0)), c[w].color = i.v;
1448
+ const f = r.length;
1449
+ let u = 0;
1450
+ const y = r[0], x = c.length;
1451
+ Zt(e, i);
1452
+ const g = e.v;
1453
+ for (let M = 0; M < x; M++) {
1454
+ const b = (y + M) % x;
1455
+ u + 1 < f && r[u + 1] === b && (++u, ni(e, i, u === f - 1 ? g : 0)), c[b].color = e.v;
1175
1456
  }
1176
1457
  }
1177
1458
  }
1178
1459
  }
1179
- const Y = Number.MAX_VALUE, m = [0, 0], yt = [0, 0];
1180
- let Us = 0, B = new Float64Array(0), K = new Float64Array(0), G = new Float64Array(0), O = new Float64Array(0), Z = new Int32Array(0), j = new Float64Array(0), It = new Float64Array(0), Rt = new Float64Array(0), Tt = new Float64Array(0), qt = new Int32Array(0);
1181
- const $ = [0, 0];
1182
- let Ys = 0, Rn = new Float64Array(0), Tn = new Float64Array(0), mn = new Float64Array(0), kn = new Float64Array(0), Fn = new Float64Array(0), Sn = new Float64Array(0), Ln = new Float64Array(0), Gn = new Float64Array(0), On = new Float64Array(0), Pn = new Float64Array(0), Nn = new Float64Array(0), Un = new Float64Array(0), Xs = 0, Lt = new Int32Array(0);
1183
- function ti(e) {
1184
- const n = e.length;
1185
- if (n === 0) return 0;
1186
- let t = 0;
1187
- if (n === 1) {
1188
- e[0].point(0, $);
1189
- const s = $[0], i = $[1];
1190
- e[0].point(1 / 3, $);
1191
- const o = $[0], p = $[1];
1192
- e[0].point(2 / 3, $);
1193
- const c = $[0], r = $[1];
1194
- t += s * p - i * o, t += o * r - p * c, t += c * i - r * s;
1195
- } else if (n === 2) {
1196
- e[0].point(0, $);
1197
- const s = $[0], i = $[1];
1198
- e[0].point(0.5, $);
1199
- const o = $[0], p = $[1];
1200
- e[1].point(0, $);
1201
- const c = $[0], r = $[1];
1202
- e[1].point(0.5, $);
1203
- const h = $[0], l = $[1];
1204
- t += s * p - i * o, t += o * r - p * c, t += c * l - r * h, t += h * i - l * s;
1460
+ const V = Number.MAX_VALUE, P = [0, 0], gt = [0, 0];
1461
+ let Eo = 0, Z = new Float64Array(0), ot = new Float64Array(0), G = new Float64Array(0), Y = new Float64Array(0), et = new Int32Array(0), it = new Float64Array(0), Gt = new Float64Array(0), Yt = new Float64Array(0), Xt = new Float64Array(0), $t = new Int32Array(0);
1462
+ const tt = [0, 0];
1463
+ let Do = 0, ns = new Float64Array(0), ss = new Float64Array(0), os = new Float64Array(0), es = new Float64Array(0), is = new Float64Array(0), cs = new Float64Array(0), rs = new Float64Array(0), as = new Float64Array(0), ls = new Float64Array(0), hs = new Float64Array(0), ps = new Float64Array(0), fs = new Float64Array(0), qo = 0, zt = new Int32Array(0);
1464
+ function oi(s) {
1465
+ const t = s.length;
1466
+ if (t === 0) return 0;
1467
+ let n = 0;
1468
+ if (t === 1) {
1469
+ s[0].point(0, tt);
1470
+ const o = tt[0], e = tt[1];
1471
+ s[0].point(1 / 3, tt);
1472
+ const i = tt[0], r = tt[1];
1473
+ s[0].point(2 / 3, tt);
1474
+ const c = tt[0], a = tt[1];
1475
+ n += o * r - e * i, n += i * a - r * c, n += c * e - a * o;
1476
+ } else if (t === 2) {
1477
+ s[0].point(0, tt);
1478
+ const o = tt[0], e = tt[1];
1479
+ s[0].point(0.5, tt);
1480
+ const i = tt[0], r = tt[1];
1481
+ s[1].point(0, tt);
1482
+ const c = tt[0], a = tt[1];
1483
+ s[1].point(0.5, tt);
1484
+ const l = tt[0], h = tt[1];
1485
+ n += o * r - e * i, n += i * a - r * c, n += c * h - a * l, n += l * e - h * o;
1205
1486
  } else {
1206
- const s = e[n - 1];
1207
- let i = s.p0x, o = s.p0y;
1208
- for (let p = 0; p < n; p++) {
1209
- const c = e[p].p0x, r = e[p].p0y;
1210
- t += i * r - o * c, i = c, o = r;
1487
+ const o = s[t - 1];
1488
+ let e = o.p0x, i = o.p0y;
1489
+ for (let r = 0; r < t; r++) {
1490
+ const c = s[r].p0x, a = s[r].p0y;
1491
+ n += e * a - i * c, e = c, i = a;
1211
1492
  }
1212
1493
  }
1213
- return t > 0 ? -1 : t < 0 ? 1 : 0;
1214
- }
1215
- function ni(e, n, t, s, i, o, p) {
1216
- const c = p[e][n];
1217
- let r = t;
1218
- if (o < 0) {
1219
- c.direction(0, m);
1220
- const h = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
1221
- if (h > 0) {
1222
- const l = m[0] / h, a = m[1] / h;
1223
- c.point(0, yt);
1224
- const f = s - yt[0], y = i - yt[1];
1225
- if (f * l + y * a < 0) {
1226
- const u = f * a - y * l;
1227
- Math.abs(u) <= Math.abs(r) && (r = u);
1494
+ return n > 0 ? -1 : n < 0 ? 1 : 0;
1495
+ }
1496
+ function ei(s, t, n, o, e, i, r) {
1497
+ const c = r[s][t];
1498
+ let a = n;
1499
+ if (i < 0) {
1500
+ c.direction(0, P);
1501
+ const l = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
1502
+ if (l > 0) {
1503
+ const h = P[0] / l, p = P[1] / l;
1504
+ c.point(0, gt);
1505
+ const f = o - gt[0], u = e - gt[1];
1506
+ if (f * h + u * p < 0) {
1507
+ const x = f * p - u * h;
1508
+ Math.abs(x) <= Math.abs(a) && (a = x);
1228
1509
  }
1229
1510
  }
1230
1511
  }
1231
- if (o > 1) {
1232
- c.direction(1, m);
1233
- const h = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
1234
- if (h > 0) {
1235
- const l = m[0] / h, a = m[1] / h;
1236
- c.point(1, yt);
1237
- const f = s - yt[0], y = i - yt[1];
1238
- if (f * l + y * a > 0) {
1239
- const u = f * a - y * l;
1240
- Math.abs(u) <= Math.abs(r) && (r = u);
1512
+ if (i > 1) {
1513
+ c.direction(1, P);
1514
+ const l = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
1515
+ if (l > 0) {
1516
+ const h = P[0] / l, p = P[1] / l;
1517
+ c.point(1, gt);
1518
+ const f = o - gt[0], u = e - gt[1];
1519
+ if (f * h + u * p > 0) {
1520
+ const x = f * p - u * h;
1521
+ Math.abs(x) <= Math.abs(a) && (a = x);
1241
1522
  }
1242
1523
  }
1243
1524
  }
1244
- return r;
1525
+ return a;
1245
1526
  }
1246
- function lt(e, n, t, s, i, o, p, c, r) {
1247
- let h = e < 0 ? n : t;
1248
- if (i >= 0) {
1249
- const l = ni(s, i, e, p, c, o, r);
1250
- Math.abs(l) < Math.abs(h) && (h = l);
1527
+ function xt(s, t, n, o, e, i, r, c, a) {
1528
+ let l = s < 0 ? t : n;
1529
+ if (e >= 0) {
1530
+ const h = ei(o, e, s, r, c, i, a);
1531
+ Math.abs(h) < Math.abs(l) && (l = h);
1251
1532
  }
1252
- return h;
1533
+ return l;
1253
1534
  }
1254
- function Mt(e, n, t) {
1255
- return Math.max(Math.min(e, n), Math.min(Math.max(e, n), t));
1535
+ function wt(s, t, n) {
1536
+ return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
1256
1537
  }
1257
- function si(e, n, t, s, i, o, p, c) {
1258
- if (c.length !== n * t * 3)
1259
- throw new Error(`generateMSDF: out.length ${c.length} !== ${n * t * 3}`);
1260
- const r = e.contours, h = r.length;
1261
- if (h === 0) {
1538
+ function ii(s, t, n, o, e, i, r, c) {
1539
+ if (c.length !== t * n * 3)
1540
+ throw new Error(`generateMSDF: out.length ${c.length} !== ${t * n * 3}`);
1541
+ const a = s.contours, l = a.length;
1542
+ if (l === 0) {
1262
1543
  c.fill(0);
1263
1544
  return;
1264
1545
  }
1265
- const l = s / p;
1266
- qt.length < h && (qt = new Int32Array(h));
1267
- for (let y = 0; y < h; y++) qt[y] = ti(r[y]);
1268
- Xs < h + 1 && (Lt = new Int32Array(h + 1), Xs = h + 1);
1269
- let a = 0;
1270
- for (let y = 0; y < h; y++)
1271
- Lt[y] = a, a += r[y].length;
1272
- Lt[h] = a, Ys < a && (Rn = new Float64Array(a), Tn = new Float64Array(a), mn = new Float64Array(a), kn = new Float64Array(a), Fn = new Float64Array(a), Sn = new Float64Array(a), Ln = new Float64Array(a), Gn = new Float64Array(a), On = new Float64Array(a), Pn = new Float64Array(a), Nn = new Float64Array(a), Un = new Float64Array(a), Ys = a);
1273
- for (let y = 0; y < h; y++) {
1274
- const _ = r[y], u = _.length, x = Lt[y];
1275
- for (let M = 0; M < u; M++) {
1276
- const w = _[M], v = _[(M + u - 1) % u], C = _[(M + 1) % u], A = x + M;
1277
- w.point(0, yt), Rn[A] = yt[0], Tn[A] = yt[1], w.point(1, yt), mn[A] = yt[0], kn[A] = yt[1], w.direction(0, m);
1278
- let D = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
1279
- const I = D > 0 ? m[0] / D : 0, F = D > 0 ? m[1] / D : 0;
1280
- Fn[A] = I, Sn[A] = F, w.direction(1, m), D = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
1281
- const T = D > 0 ? m[0] / D : 0, b = D > 0 ? m[1] / D : 0;
1282
- Ln[A] = T, Gn[A] = b, v.direction(1, m), D = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
1283
- const N = D > 0 ? m[0] / D : 0, R = D > 0 ? m[1] / D : 0;
1284
- C.direction(0, m), D = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
1285
- const q = D > 0 ? m[0] / D : 0, P = D > 0 ? m[1] / D : 0, X = N + I, Q = R + F, V = Math.sqrt(X * X + Q * Q);
1286
- On[A] = V > 0 ? X / V : 0, Pn[A] = V > 0 ? Q / V : 0;
1287
- const nt = T + q, H = b + P, z = Math.sqrt(nt * nt + H * H);
1288
- Nn[A] = z > 0 ? -(nt / z) : 0, Un[A] = z > 0 ? -(H / z) : 0;
1546
+ const h = o / r;
1547
+ $t.length < l && ($t = new Int32Array(l));
1548
+ for (let u = 0; u < l; u++) $t[u] = oi(a[u]);
1549
+ qo < l + 1 && (zt = new Int32Array(l + 1), qo = l + 1);
1550
+ let p = 0;
1551
+ for (let u = 0; u < l; u++)
1552
+ zt[u] = p, p += a[u].length;
1553
+ zt[l] = p, Do < p && (ns = new Float64Array(p), ss = new Float64Array(p), os = new Float64Array(p), es = new Float64Array(p), is = new Float64Array(p), cs = new Float64Array(p), rs = new Float64Array(p), as = new Float64Array(p), ls = new Float64Array(p), hs = new Float64Array(p), ps = new Float64Array(p), fs = new Float64Array(p), Do = p);
1554
+ for (let u = 0; u < l; u++) {
1555
+ const y = a[u], x = y.length, g = zt[u];
1556
+ for (let M = 0; M < x; M++) {
1557
+ const b = y[M], A = y[(M + x - 1) % x], F = y[(M + 1) % x], k = g + M;
1558
+ b.point(0, gt), ns[k] = gt[0], ss[k] = gt[1], b.point(1, gt), os[k] = gt[0], es[k] = gt[1], b.direction(0, P);
1559
+ let T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
1560
+ const q = T > 0 ? P[0] / T : 0, m = T > 0 ? P[1] / T : 0;
1561
+ is[k] = q, cs[k] = m, b.direction(1, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
1562
+ const d = T > 0 ? P[0] / T : 0, _ = T > 0 ? P[1] / T : 0;
1563
+ rs[k] = d, as[k] = _, A.direction(1, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
1564
+ const w = T > 0 ? P[0] / T : 0, E = T > 0 ? P[1] / T : 0;
1565
+ F.direction(0, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
1566
+ const I = T > 0 ? P[0] / T : 0, C = T > 0 ? P[1] / T : 0, S = w + q, O = E + m, L = Math.sqrt(S * S + O * O);
1567
+ ls[k] = L > 0 ? S / L : 0, hs[k] = L > 0 ? O / L : 0;
1568
+ const W = d + I, X = _ + C, H = Math.sqrt(W * W + X * X);
1569
+ ps[k] = H > 0 ? -(W / H) : 0, fs[k] = H > 0 ? -(X / H) : 0;
1289
1570
  }
1290
1571
  }
1291
- if (Us < h) {
1292
- const y = h * 3;
1293
- B = new Float64Array(y), K = new Float64Array(y), G = new Float64Array(y), O = new Float64Array(y), Z = new Int32Array(y), j = new Float64Array(y), It = new Float64Array(h), Rt = new Float64Array(h), Tt = new Float64Array(h), Us = h;
1572
+ if (Eo < l) {
1573
+ const u = l * 3;
1574
+ Z = new Float64Array(u), ot = new Float64Array(u), G = new Float64Array(u), Y = new Float64Array(u), et = new Int32Array(u), it = new Float64Array(u), Gt = new Float64Array(l), Yt = new Float64Array(l), Xt = new Float64Array(l), Eo = l;
1294
1575
  }
1295
1576
  const f = { distance: 0, dot: 0, param: 0 };
1296
- for (let y = 0; y < t; y++)
1297
- for (let _ = 0; _ < n; _++) {
1298
- const u = (_ + 0.5) / s - i, x = (y + 0.5) / s - o;
1299
- for (let E = 0; E < h; E++) {
1300
- const d = r[E], ct = d.length, g = E * 3, S = Lt[E];
1301
- B[g] = B[g + 1] = B[g + 2] = -Y, K[g] = K[g + 1] = K[g + 2] = 0, G[g] = G[g + 1] = G[g + 2] = -Y, O[g] = O[g + 1] = O[g + 2] = Y, Z[g] = Z[g + 1] = Z[g + 2] = -1, j[g] = j[g + 1] = j[g + 2] = 0;
1302
- for (let L = 0; L < ct; L++) {
1303
- const W = d[L], bn = W.color, An = (bn & Jt) !== 0, wn = (bn & tn) !== 0, Dn = (bn & nn) !== 0;
1304
- W.signedDistance(u, x, f);
1305
- const zt = f.distance, Ct = f.dot, En = f.param, At = Math.abs(zt);
1306
- if (An) {
1307
- const dt = Math.abs(B[g]);
1308
- (At < dt || At === dt && Ct < K[g]) && (B[g] = zt, K[g] = Ct, Z[g] = L, j[g] = En);
1577
+ for (let u = 0; u < n; u++)
1578
+ for (let y = 0; y < t; y++) {
1579
+ const x = (y + 0.5) / o - e, g = (u + 0.5) / o - i;
1580
+ for (let R = 0; R < l; R++) {
1581
+ const v = a[R], ut = v.length, D = R * 3, N = zt[R];
1582
+ Z[D] = Z[D + 1] = Z[D + 2] = -V, ot[D] = ot[D + 1] = ot[D + 2] = 0, G[D] = G[D + 1] = G[D + 2] = -V, Y[D] = Y[D + 1] = Y[D + 2] = V, et[D] = et[D + 1] = et[D + 2] = -1, it[D] = it[D + 1] = it[D + 2] = 0;
1583
+ for (let U = 0; U < ut; U++) {
1584
+ const j = v[U], Bn = j.color, Vn = (Bn & qn) !== 0, jn = (Bn & Cn) !== 0, zn = (Bn & vn) !== 0;
1585
+ j.signedDistance(x, g, f);
1586
+ const pn = f.distance, Ut = f.dot, Qn = f.param, Tt = Math.abs(pn);
1587
+ if (Vn) {
1588
+ const kt = Math.abs(Z[D]);
1589
+ (Tt < kt || Tt === kt && Ut < ot[D]) && (Z[D] = pn, ot[D] = Ut, et[D] = U, it[D] = Qn);
1309
1590
  }
1310
- if (wn) {
1311
- const dt = Math.abs(B[g + 1]);
1312
- (At < dt || At === dt && Ct < K[g + 1]) && (B[g + 1] = zt, K[g + 1] = Ct, Z[g + 1] = L, j[g + 1] = En);
1591
+ if (jn) {
1592
+ const kt = Math.abs(Z[D + 1]);
1593
+ (Tt < kt || Tt === kt && Ut < ot[D + 1]) && (Z[D + 1] = pn, ot[D + 1] = Ut, et[D + 1] = U, it[D + 1] = Qn);
1313
1594
  }
1314
- if (Dn) {
1315
- const dt = Math.abs(B[g + 2]);
1316
- (At < dt || At === dt && Ct < K[g + 2]) && (B[g + 2] = zt, K[g + 2] = Ct, Z[g + 2] = L, j[g + 2] = En);
1595
+ if (zn) {
1596
+ const kt = Math.abs(Z[D + 2]);
1597
+ (Tt < kt || Tt === kt && Ut < ot[D + 2]) && (Z[D + 2] = pn, ot[D + 2] = Ut, et[D + 2] = U, it[D + 2] = Qn);
1317
1598
  }
1318
- const pt = S + L, qn = u - Rn[pt], vn = x - Tn[pt], Cn = u - mn[pt], In = x - kn[pt], qs = Fn[pt], vs = Sn[pt], Cs = Ln[pt], Is = Gn[pt], so = qn * On[pt] + vn * Pn[pt], oo = Cn * Nn[pt] + In * Un[pt];
1319
- if (so > 0 && -(qn * qs + vn * vs) > 0) {
1320
- const k = qn * vs - vn * qs;
1321
- Math.abs(k) < At && (An && (k <= 0 && k > G[g] ? G[g] = k : k > 0 && k < O[g] && (O[g] = k)), wn && (k <= 0 && k > G[g + 1] ? G[g + 1] = k : k > 0 && k < O[g + 1] && (O[g + 1] = k)), Dn && (k <= 0 && k > G[g + 2] ? G[g + 2] = k : k > 0 && k < O[g + 2] && (O[g + 2] = k)));
1599
+ const yt = N + U, Kn = x - ns[yt], Zn = g - ss[yt], Jn = x - os[yt], ts = g - es[yt], so = is[yt], oo = cs[yt], eo = rs[yt], io = as[yt], zo = Kn * ls[yt] + Zn * hs[yt], Qo = Jn * ps[yt] + ts * fs[yt];
1600
+ if (zo > 0 && -(Kn * so + Zn * oo) > 0) {
1601
+ const $ = Kn * oo - Zn * so;
1602
+ Math.abs($) < Tt && (Vn && ($ <= 0 && $ > G[D] ? G[D] = $ : $ > 0 && $ < Y[D] && (Y[D] = $)), jn && ($ <= 0 && $ > G[D + 1] ? G[D + 1] = $ : $ > 0 && $ < Y[D + 1] && (Y[D + 1] = $)), zn && ($ <= 0 && $ > G[D + 2] ? G[D + 2] = $ : $ > 0 && $ < Y[D + 2] && (Y[D + 2] = $)));
1322
1603
  }
1323
- if (oo > 0 && Cn * Cs + In * Is > 0) {
1324
- const k = Cn * Is - In * Cs;
1325
- Math.abs(k) < At && (An && (k <= 0 && k > G[g] ? G[g] = k : k > 0 && k < O[g] && (O[g] = k)), wn && (k <= 0 && k > G[g + 1] ? G[g + 1] = k : k > 0 && k < O[g + 1] && (O[g + 1] = k)), Dn && (k <= 0 && k > G[g + 2] ? G[g + 2] = k : k > 0 && k < O[g + 2] && (O[g + 2] = k)));
1604
+ if (Qo > 0 && Jn * eo + ts * io > 0) {
1605
+ const $ = Jn * io - ts * eo;
1606
+ Math.abs($) < Tt && (Vn && ($ <= 0 && $ > G[D] ? G[D] = $ : $ > 0 && $ < Y[D] && (Y[D] = $)), jn && ($ <= 0 && $ > G[D + 1] ? G[D + 1] = $ : $ > 0 && $ < Y[D + 1] && (Y[D + 1] = $)), zn && ($ <= 0 && $ > G[D + 2] ? G[D + 2] = $ : $ > 0 && $ < Y[D + 2] && (Y[D + 2] = $)));
1326
1607
  }
1327
1608
  }
1328
- It[E] = lt(
1329
- B[g],
1330
- G[g],
1331
- O[g],
1332
- E,
1333
- Z[g],
1334
- j[g],
1335
- u,
1609
+ Gt[R] = xt(
1610
+ Z[D],
1611
+ G[D],
1612
+ Y[D],
1613
+ R,
1614
+ et[D],
1615
+ it[D],
1336
1616
  x,
1337
- r
1338
- ), Rt[E] = lt(
1339
- B[g + 1],
1340
- G[g + 1],
1341
- O[g + 1],
1342
- E,
1343
- Z[g + 1],
1344
- j[g + 1],
1345
- u,
1617
+ g,
1618
+ a
1619
+ ), Yt[R] = xt(
1620
+ Z[D + 1],
1621
+ G[D + 1],
1622
+ Y[D + 1],
1623
+ R,
1624
+ et[D + 1],
1625
+ it[D + 1],
1346
1626
  x,
1347
- r
1348
- ), Tt[E] = lt(
1349
- B[g + 2],
1350
- G[g + 2],
1351
- O[g + 2],
1352
- E,
1353
- Z[g + 2],
1354
- j[g + 2],
1355
- u,
1627
+ g,
1628
+ a
1629
+ ), Xt[R] = xt(
1630
+ Z[D + 2],
1631
+ G[D + 2],
1632
+ Y[D + 2],
1633
+ R,
1634
+ et[D + 2],
1635
+ it[D + 2],
1356
1636
  x,
1357
- r
1637
+ g,
1638
+ a
1358
1639
  );
1359
1640
  }
1360
- let M = -Y, w = 0, v = -Y, C = Y, A = -1, D = -1, I = 0, F = -Y, T = 0, b = -Y, N = Y, R = -1, q = -1, P = 0, X = -Y, Q = 0, V = -Y, nt = Y, H = -1, z = -1, ht = 0, st = -Y, kt = 0, sn = -Y, on = Y, Kn = -1, Zn = -1, jn = 0, Nt = -Y, Jn = 0, en = -Y, cn = Y, ts = -1, ns = -1, ss = 0, Ut = -Y, os = 0, rn = -Y, an = Y, is = -1, es = -1, cs = 0, Yt = -Y, rs = 0, hn = -Y, pn = Y, as = -1, hs = -1, ps = 0, Xt = -Y, ls = 0, ln = -Y, fn = Y, fs = -1, ys = -1, us = 0, Wt = -Y, _s = 0, yn = -Y, un = Y, xs = -1, Ms = -1, gs = 0;
1361
- for (let E = 0; E < h; E++) {
1362
- const d = E * 3, ct = qt[E], g = Mt(It[E], Rt[E], Tt[E]);
1641
+ let M = -V, b = 0, A = -V, F = V, k = -1, T = -1, q = 0, m = -V, d = 0, _ = -V, w = V, E = -1, I = -1, C = 0, S = -V, O = 0, L = -V, W = V, X = -1, H = -1, J = 0, z = -V, Et = 0, ht = -V, vt = V, Dt = -1, qs = -1, Cs = 0, on = -V, vs = 0, Tn = -V, Fn = V, Ts = -1, Fs = -1, Ss = 0, en = -V, Rs = 0, Sn = -V, Rn = V, Ls = -1, Ps = -1, $s = 0, cn = -V, Os = 0, Ln = -V, Pn = V, Ns = -1, Us = -1, Gs = 0, rn = -V, Ys = 0, $n = -V, On = V, Xs = -1, Ws = -1, Hs = 0, an = -V, Bs = 0, Nn = -V, Un = V, Vs = -1, js = -1, zs = 0;
1642
+ for (let R = 0; R < l; R++) {
1643
+ const v = R * 3, ut = $t[R], D = wt(Gt[R], Yt[R], Xt[R]);
1363
1644
  {
1364
- const S = B[d], L = K[d], W = Math.abs(S);
1365
- (W < Math.abs(M) || W === Math.abs(M) && L < w) && (M = S, w = L, A = E, D = Z[d], I = j[d]), G[d] > v && (v = G[d]), O[d] < C && (C = O[d]);
1645
+ const N = Z[v], U = ot[v], j = Math.abs(N);
1646
+ (j < Math.abs(M) || j === Math.abs(M) && U < b) && (M = N, b = U, k = R, T = et[v], q = it[v]), G[v] > A && (A = G[v]), Y[v] < F && (F = Y[v]);
1366
1647
  }
1367
1648
  {
1368
- const S = B[d + 1], L = K[d + 1], W = Math.abs(S);
1369
- (W < Math.abs(F) || W === Math.abs(F) && L < T) && (F = S, T = L, R = E, q = Z[d + 1], P = j[d + 1]), G[d + 1] > b && (b = G[d + 1]), O[d + 1] < N && (N = O[d + 1]);
1649
+ const N = Z[v + 1], U = ot[v + 1], j = Math.abs(N);
1650
+ (j < Math.abs(m) || j === Math.abs(m) && U < d) && (m = N, d = U, E = R, I = et[v + 1], C = it[v + 1]), G[v + 1] > _ && (_ = G[v + 1]), Y[v + 1] < w && (w = Y[v + 1]);
1370
1651
  }
1371
1652
  {
1372
- const S = B[d + 2], L = K[d + 2], W = Math.abs(S);
1373
- (W < Math.abs(X) || W === Math.abs(X) && L < Q) && (X = S, Q = L, H = E, z = Z[d + 2], ht = j[d + 2]), G[d + 2] > V && (V = G[d + 2]), O[d + 2] < nt && (nt = O[d + 2]);
1653
+ const N = Z[v + 2], U = ot[v + 2], j = Math.abs(N);
1654
+ (j < Math.abs(S) || j === Math.abs(S) && U < O) && (S = N, O = U, X = R, H = et[v + 2], J = it[v + 2]), G[v + 2] > L && (L = G[v + 2]), Y[v + 2] < W && (W = Y[v + 2]);
1374
1655
  }
1375
- if (ct > 0 && g >= 0) {
1656
+ if (ut > 0 && D >= 0) {
1376
1657
  {
1377
- const S = B[d], L = K[d], W = Math.abs(S);
1378
- (W < Math.abs(st) || W === Math.abs(st) && L < kt) && (st = S, kt = L, Kn = E, Zn = Z[d], jn = j[d]), G[d] > sn && (sn = G[d]), O[d] < on && (on = O[d]);
1658
+ const N = Z[v], U = ot[v], j = Math.abs(N);
1659
+ (j < Math.abs(z) || j === Math.abs(z) && U < Et) && (z = N, Et = U, Dt = R, qs = et[v], Cs = it[v]), G[v] > ht && (ht = G[v]), Y[v] < vt && (vt = Y[v]);
1379
1660
  }
1380
1661
  {
1381
- const S = B[d + 1], L = K[d + 1], W = Math.abs(S);
1382
- (W < Math.abs(Nt) || W === Math.abs(Nt) && L < Jn) && (Nt = S, Jn = L, ts = E, ns = Z[d + 1], ss = j[d + 1]), G[d + 1] > en && (en = G[d + 1]), O[d + 1] < cn && (cn = O[d + 1]);
1662
+ const N = Z[v + 1], U = ot[v + 1], j = Math.abs(N);
1663
+ (j < Math.abs(on) || j === Math.abs(on) && U < vs) && (on = N, vs = U, Ts = R, Fs = et[v + 1], Ss = it[v + 1]), G[v + 1] > Tn && (Tn = G[v + 1]), Y[v + 1] < Fn && (Fn = Y[v + 1]);
1383
1664
  }
1384
1665
  {
1385
- const S = B[d + 2], L = K[d + 2], W = Math.abs(S);
1386
- (W < Math.abs(Ut) || W === Math.abs(Ut) && L < os) && (Ut = S, os = L, is = E, es = Z[d + 2], cs = j[d + 2]), G[d + 2] > rn && (rn = G[d + 2]), O[d + 2] < an && (an = O[d + 2]);
1666
+ const N = Z[v + 2], U = ot[v + 2], j = Math.abs(N);
1667
+ (j < Math.abs(en) || j === Math.abs(en) && U < Rs) && (en = N, Rs = U, Ls = R, Ps = et[v + 2], $s = it[v + 2]), G[v + 2] > Sn && (Sn = G[v + 2]), Y[v + 2] < Rn && (Rn = Y[v + 2]);
1387
1668
  }
1388
1669
  }
1389
- if (ct < 0 && g <= 0) {
1670
+ if (ut < 0 && D <= 0) {
1390
1671
  {
1391
- const S = B[d], L = K[d], W = Math.abs(S);
1392
- (W < Math.abs(Yt) || W === Math.abs(Yt) && L < rs) && (Yt = S, rs = L, as = E, hs = Z[d], ps = j[d]), G[d] > hn && (hn = G[d]), O[d] < pn && (pn = O[d]);
1672
+ const N = Z[v], U = ot[v], j = Math.abs(N);
1673
+ (j < Math.abs(cn) || j === Math.abs(cn) && U < Os) && (cn = N, Os = U, Ns = R, Us = et[v], Gs = it[v]), G[v] > Ln && (Ln = G[v]), Y[v] < Pn && (Pn = Y[v]);
1393
1674
  }
1394
1675
  {
1395
- const S = B[d + 1], L = K[d + 1], W = Math.abs(S);
1396
- (W < Math.abs(Xt) || W === Math.abs(Xt) && L < ls) && (Xt = S, ls = L, fs = E, ys = Z[d + 1], us = j[d + 1]), G[d + 1] > ln && (ln = G[d + 1]), O[d + 1] < fn && (fn = O[d + 1]);
1676
+ const N = Z[v + 1], U = ot[v + 1], j = Math.abs(N);
1677
+ (j < Math.abs(rn) || j === Math.abs(rn) && U < Ys) && (rn = N, Ys = U, Xs = R, Ws = et[v + 1], Hs = it[v + 1]), G[v + 1] > $n && ($n = G[v + 1]), Y[v + 1] < On && (On = Y[v + 1]);
1397
1678
  }
1398
1679
  {
1399
- const S = B[d + 2], L = K[d + 2], W = Math.abs(S);
1400
- (W < Math.abs(Wt) || W === Math.abs(Wt) && L < _s) && (Wt = S, _s = L, xs = E, Ms = Z[d + 2], gs = j[d + 2]), G[d + 2] > yn && (yn = G[d + 2]), O[d + 2] < un && (un = O[d + 2]);
1680
+ const N = Z[v + 2], U = ot[v + 2], j = Math.abs(N);
1681
+ (j < Math.abs(an) || j === Math.abs(an) && U < Bs) && (an = N, Bs = U, Vs = R, js = et[v + 2], zs = it[v + 2]), G[v + 2] > Nn && (Nn = G[v + 2]), Y[v + 2] < Un && (Un = Y[v + 2]);
1401
1682
  }
1402
1683
  }
1403
1684
  }
1404
- const _n = lt(
1685
+ const Gn = xt(
1405
1686
  M,
1406
- v,
1407
- C,
1408
1687
  A,
1409
- D,
1410
- I,
1411
- u,
1412
- x,
1413
- r
1414
- ), xn = lt(
1415
1688
  F,
1416
- b,
1417
- N,
1418
- R,
1689
+ k,
1690
+ T,
1419
1691
  q,
1420
- P,
1421
- u,
1422
1692
  x,
1423
- r
1424
- ), Mn = lt(
1693
+ g,
1694
+ a
1695
+ ), Yn = xt(
1696
+ m,
1697
+ _,
1698
+ w,
1699
+ E,
1700
+ I,
1701
+ C,
1702
+ x,
1703
+ g,
1704
+ a
1705
+ ), Xn = xt(
1706
+ S,
1707
+ L,
1708
+ W,
1425
1709
  X,
1426
- V,
1427
- nt,
1428
1710
  H,
1711
+ J,
1712
+ x,
1713
+ g,
1714
+ a
1715
+ ), jo = wt(Gn, Yn, Xn), Qs = xt(
1429
1716
  z,
1430
1717
  ht,
1431
- u,
1718
+ vt,
1719
+ Dt,
1720
+ qs,
1721
+ Cs,
1432
1722
  x,
1433
- r
1434
- ), no = Mt(_n, xn, Mn), ds = lt(
1435
- st,
1436
- sn,
1723
+ g,
1724
+ a
1725
+ ), Ks = xt(
1437
1726
  on,
1438
- Kn,
1439
- Zn,
1440
- jn,
1441
- u,
1727
+ Tn,
1728
+ Fn,
1729
+ Ts,
1730
+ Fs,
1731
+ Ss,
1442
1732
  x,
1443
- r
1444
- ), bs = lt(
1445
- Nt,
1733
+ g,
1734
+ a
1735
+ ), Zs = xt(
1446
1736
  en,
1737
+ Sn,
1738
+ Rn,
1739
+ Ls,
1740
+ Ps,
1741
+ $s,
1742
+ x,
1743
+ g,
1744
+ a
1745
+ ), ln = wt(Qs, Ks, Zs), Js = xt(
1447
1746
  cn,
1448
- ts,
1449
- ns,
1450
- ss,
1451
- u,
1747
+ Ln,
1748
+ Pn,
1749
+ Ns,
1750
+ Us,
1751
+ Gs,
1452
1752
  x,
1453
- r
1454
- ), As = lt(
1455
- Ut,
1753
+ g,
1754
+ a
1755
+ ), to = xt(
1456
1756
  rn,
1457
- an,
1458
- is,
1459
- es,
1460
- cs,
1461
- u,
1462
- x,
1463
- r
1464
- ), Ht = Mt(ds, bs, As), ws = lt(
1465
- Yt,
1466
- hn,
1467
- pn,
1468
- as,
1469
- hs,
1470
- ps,
1471
- u,
1472
- x,
1473
- r
1474
- ), Ds = lt(
1475
- Xt,
1476
- ln,
1477
- fn,
1478
- fs,
1479
- ys,
1480
- us,
1481
- u,
1757
+ $n,
1758
+ On,
1759
+ Xs,
1760
+ Ws,
1761
+ Hs,
1482
1762
  x,
1483
- r
1484
- ), Es = lt(
1485
- Wt,
1486
- yn,
1487
- un,
1488
- xs,
1489
- Ms,
1490
- gs,
1491
- u,
1763
+ g,
1764
+ a
1765
+ ), no = xt(
1766
+ an,
1767
+ Nn,
1768
+ Un,
1769
+ Vs,
1770
+ js,
1771
+ zs,
1492
1772
  x,
1493
- r
1494
- ), Vt = Mt(ws, Ds, Es);
1495
- let ut, _t, xt, gn = 0;
1496
- if (Ht >= 0 && Math.abs(Ht) <= Math.abs(Vt)) {
1497
- ut = ds, _t = bs, xt = As, gn = 1;
1498
- for (let E = 0; E < h; E++)
1499
- if (qt[E] > 0) {
1500
- const d = It[E], ct = Rt[E], g = Tt[E], S = Mt(d, ct, g);
1501
- Math.abs(S) < Math.abs(Vt) && S > Mt(ut, _t, xt) && (ut = d, _t = ct, xt = g);
1773
+ g,
1774
+ a
1775
+ ), hn = wt(Js, to, no);
1776
+ let Mt, mt, bt, Wn = 0;
1777
+ if (ln >= 0 && Math.abs(ln) <= Math.abs(hn)) {
1778
+ Mt = Qs, mt = Ks, bt = Zs, Wn = 1;
1779
+ for (let R = 0; R < l; R++)
1780
+ if ($t[R] > 0) {
1781
+ const v = Gt[R], ut = Yt[R], D = Xt[R], N = wt(v, ut, D);
1782
+ Math.abs(N) < Math.abs(hn) && N > wt(Mt, mt, bt) && (Mt = v, mt = ut, bt = D);
1502
1783
  }
1503
- } else if (Vt <= 0 && Math.abs(Vt) < Math.abs(Ht)) {
1504
- ut = ws, _t = Ds, xt = Es, gn = -1;
1505
- for (let E = 0; E < h; E++)
1506
- if (qt[E] < 0) {
1507
- const d = It[E], ct = Rt[E], g = Tt[E], S = Mt(d, ct, g);
1508
- Math.abs(S) < Math.abs(Ht) && S < Mt(ut, _t, xt) && (ut = d, _t = ct, xt = g);
1784
+ } else if (hn <= 0 && Math.abs(hn) < Math.abs(ln)) {
1785
+ Mt = Js, mt = to, bt = no, Wn = -1;
1786
+ for (let R = 0; R < l; R++)
1787
+ if ($t[R] < 0) {
1788
+ const v = Gt[R], ut = Yt[R], D = Xt[R], N = wt(v, ut, D);
1789
+ Math.abs(N) < Math.abs(ln) && N < wt(Mt, mt, bt) && (Mt = v, mt = ut, bt = D);
1509
1790
  }
1510
1791
  } else {
1511
- const E = (y * n + _) * 3;
1512
- c[E + 0] = _n * l + 0.5, c[E + 1] = xn * l + 0.5, c[E + 2] = Mn * l + 0.5;
1792
+ const R = (u * t + y) * 3;
1793
+ c[R + 0] = Gn * h + 0.5, c[R + 1] = Yn * h + 0.5, c[R + 2] = Xn * h + 0.5;
1513
1794
  continue;
1514
1795
  }
1515
- for (let E = 0; E < h; E++)
1516
- if (qt[E] !== gn) {
1517
- const d = It[E], ct = Rt[E], g = Tt[E], S = Mt(d, ct, g), L = Mt(ut, _t, xt);
1518
- S * L >= 0 && Math.abs(S) < Math.abs(L) && (ut = d, _t = ct, xt = g);
1796
+ for (let R = 0; R < l; R++)
1797
+ if ($t[R] !== Wn) {
1798
+ const v = Gt[R], ut = Yt[R], D = Xt[R], N = wt(v, ut, D), U = wt(Mt, mt, bt);
1799
+ N * U >= 0 && Math.abs(N) < Math.abs(U) && (Mt = v, mt = ut, bt = D);
1519
1800
  }
1520
- Mt(ut, _t, xt) === no && (ut = _n, _t = xn, xt = Mn);
1521
- const dn = (y * n + _) * 3;
1522
- c[dn + 0] = ut * l + 0.5, c[dn + 1] = _t * l + 0.5, c[dn + 2] = xt * l + 0.5;
1801
+ wt(Mt, mt, bt) === jo && (Mt = Gn, mt = Yn, bt = Xn);
1802
+ const Hn = (u * t + y) * 3;
1803
+ c[Hn + 0] = Mt * h + 0.5, c[Hn + 1] = mt * h + 0.5, c[Hn + 2] = bt * h + 0.5;
1523
1804
  }
1524
1805
  }
1525
- const Zs = 0, oi = 1, ii = 2, ei = 3;
1526
- function ci(e, n) {
1527
- switch (n) {
1528
- case Zs:
1529
- return e !== 0;
1530
- case oi:
1531
- return (e & 1) !== 0;
1532
- case ii:
1533
- return e > 0;
1534
- case ei:
1535
- return e < 0;
1806
+ const Go = 0, ci = 1, ri = 2, ai = 3;
1807
+ function li(s, t) {
1808
+ switch (t) {
1809
+ case Go:
1810
+ return s !== 0;
1811
+ case ci:
1812
+ return (s & 1) !== 0;
1813
+ case ri:
1814
+ return s > 0;
1815
+ case ai:
1816
+ return s < 0;
1536
1817
  }
1537
1818
  return !1;
1538
1819
  }
1539
- class ri {
1820
+ class hi {
1540
1821
  constructor() {
1541
1822
  this._intersections = [], this._lastIndex = 0;
1542
1823
  }
@@ -1546,12 +1827,12 @@ class ri {
1546
1827
  *
1547
1828
  * @param intersections Unsorted crossings (ownership transferred; mutated).
1548
1829
  */
1549
- setIntersections(n) {
1550
- if (this._intersections = n, this._lastIndex = 0, n.length > 0) {
1551
- n.sort((s, i) => rt(s.x - i.x));
1552
- let t = 0;
1553
- for (let s = 0; s < n.length; s++)
1554
- t += n[s].direction, n[s].direction = t;
1830
+ setIntersections(t) {
1831
+ if (this._intersections = t, this._lastIndex = 0, t.length > 0) {
1832
+ t.sort((o, e) => ft(o.x - e.x));
1833
+ let n = 0;
1834
+ for (let o = 0; o < t.length; o++)
1835
+ n += t[o].direction, t[o].direction = n;
1555
1836
  }
1556
1837
  }
1557
1838
  /**
@@ -1560,19 +1841,19 @@ class ri {
1560
1841
  * @param x Query x-coordinate.
1561
1842
  * @returns Index into the sorted crossings, or -1 when x precedes all.
1562
1843
  */
1563
- _moveTo(n) {
1564
- const t = this._intersections.length;
1565
- if (t === 0) return -1;
1566
- let s = this._lastIndex;
1567
- if (n < this._intersections[s].x)
1844
+ _moveTo(t) {
1845
+ const n = this._intersections.length;
1846
+ if (n === 0) return -1;
1847
+ let o = this._lastIndex;
1848
+ if (t < this._intersections[o].x)
1568
1849
  do {
1569
- if (s === 0)
1850
+ if (o === 0)
1570
1851
  return this._lastIndex = 0, -1;
1571
- --s;
1572
- } while (n < this._intersections[s].x);
1852
+ --o;
1853
+ } while (t < this._intersections[o].x);
1573
1854
  else
1574
- for (; s < t - 1 && n >= this._intersections[s + 1].x; ) ++s;
1575
- return this._lastIndex = s, s;
1855
+ for (; o < n - 1 && t >= this._intersections[o + 1].x; ) ++o;
1856
+ return this._lastIndex = o, o;
1576
1857
  }
1577
1858
  /**
1578
1859
  * Returns the accumulated winding number at x.
@@ -1580,9 +1861,9 @@ class ri {
1580
1861
  * @param x Query x-coordinate.
1581
1862
  * @returns Signed winding number.
1582
1863
  */
1583
- sumIntersections(n) {
1584
- const t = this._moveTo(n);
1585
- return t >= 0 ? this._intersections[t].direction : 0;
1864
+ sumIntersections(t) {
1865
+ const n = this._moveTo(t);
1866
+ return n >= 0 ? this._intersections[n].direction : 0;
1586
1867
  }
1587
1868
  /**
1588
1869
  * Tests whether the point at x is filled under the given fill rule.
@@ -1591,324 +1872,664 @@ class ri {
1591
1872
  * @param fillRule Fill rule to apply.
1592
1873
  * @returns True when filled.
1593
1874
  */
1594
- filled(n, t) {
1595
- return ci(this.sumIntersections(n), t);
1596
- }
1597
- }
1598
- const Ws = [0, 0, 0], Hs = [0, 0, 0];
1599
- function ai(e, n, t) {
1600
- const s = [];
1601
- for (const i of e.contours)
1602
- for (const o of i) {
1603
- const p = o.scanlineIntersections(n, Ws, Hs);
1604
- for (let c = 0; c < p; c++)
1605
- s.push({ x: Ws[c], direction: Hs[c] });
1875
+ filled(t, n) {
1876
+ return li(this.sumIntersections(t), n);
1877
+ }
1878
+ }
1879
+ const Co = [0, 0, 0], vo = [0, 0, 0];
1880
+ function pi(s, t, n) {
1881
+ const o = [];
1882
+ for (const e of s.contours)
1883
+ for (const i of e) {
1884
+ const r = i.scanlineIntersections(t, Co, vo);
1885
+ for (let c = 0; c < r; c++)
1886
+ o.push({ x: Co[c], direction: vo[c] });
1606
1887
  }
1607
- t.setIntersections(s);
1608
- }
1609
- const mt = 2, js = 1, Yn = 1.001, hi = 1.1111111111111112, jt = 0.01;
1610
- function pi(e, n, t, s, i, o, p) {
1611
- if (t === 0 || s === 0) return;
1612
- const c = new ri(), r = new Int8Array(t * s);
1613
- for (let h = 0; h < s; h++) {
1614
- const l = (h + 0.5) / i - p;
1615
- ai(n, l, c);
1616
- for (let a = 0; a < t; a++) {
1617
- const f = (a + 0.5) / i - o, y = c.filled(f, Zs), _ = (h * t + a) * 3, u = e[_], x = e[_ + 1], M = e[_ + 2], w = tt(u, x, M), v = h * t + a;
1618
- w === 0.5 ? r[v] = 0 : w > 0.5 !== y ? (e[_] = 1 - u, e[_ + 1] = 1 - x, e[_ + 2] = 1 - M, r[v] = -1) : r[v] = 1;
1888
+ n.setIntersections(o);
1889
+ }
1890
+ const Ht = 2, Yo = 1, us = 1.001, fi = 1.1111111111111112, An = 0.01;
1891
+ function ui(s, t, n, o, e, i, r) {
1892
+ if (n === 0 || o === 0) return;
1893
+ const c = new hi(), a = new Int8Array(n * o);
1894
+ for (let l = 0; l < o; l++) {
1895
+ const h = (l + 0.5) / e - r;
1896
+ pi(t, h, c);
1897
+ for (let p = 0; p < n; p++) {
1898
+ const f = (p + 0.5) / e - i, u = c.filled(f, Go), y = (l * n + p) * 3, x = s[y], g = s[y + 1], M = s[y + 2], b = lt(x, g, M), A = l * n + p;
1899
+ b === 0.5 ? a[A] = 0 : b > 0.5 !== u ? (s[y] = 1 - x, s[y + 1] = 1 - g, s[y + 2] = 1 - M, a[A] = -1) : a[A] = 1;
1619
1900
  }
1620
1901
  }
1621
- for (let h = 0; h < s; h++)
1622
- for (let l = 0; l < t; l++) {
1623
- const a = h * t + l;
1624
- if (r[a] !== 0) continue;
1902
+ for (let l = 0; l < o; l++)
1903
+ for (let h = 0; h < n; h++) {
1904
+ const p = l * n + h;
1905
+ if (a[p] !== 0) continue;
1625
1906
  let f = 0;
1626
- if (l > 0 && (f += r[a - 1]), l < t - 1 && (f += r[a + 1]), h > 0 && (f += r[a - t]), h < s - 1 && (f += r[a + t]), f < 0) {
1627
- const y = (h * t + l) * 3;
1628
- e[y] = 1 - e[y], e[y + 1] = 1 - e[y + 1], e[y + 2] = 1 - e[y + 2];
1907
+ if (h > 0 && (f += a[p - 1]), h < n - 1 && (f += a[p + 1]), l > 0 && (f += a[p - n]), l < o - 1 && (f += a[p + n]), f < 0) {
1908
+ const u = (l * n + h) * 3;
1909
+ s[u] = 1 - s[u], s[u + 1] = 1 - s[u + 1], s[u + 2] = 1 - s[u + 2];
1629
1910
  }
1630
1911
  }
1631
1912
  }
1632
- const Xn = [0, 0];
1633
- function li(e, n, t, s, i, o, p, c) {
1634
- const r = new Uint8Array(t * s);
1635
- fi(r, n, t, s, i, o, p), yi(r, e, t, s, i, c), Mi(r, e, t, s, c, hi), gi(r, e, t, s);
1913
+ const ys = [0, 0];
1914
+ function yi(s, t, n, o, e, i, r, c) {
1915
+ const a = new Uint8Array(n * o);
1916
+ xi(a, t, n, o, e, i, r), _i(a, s, n, o, e, c), mi(a, s, n, o, c, fi), bi(a, s, n, o);
1636
1917
  }
1637
- function fi(e, n, t, s, i, o, p) {
1638
- for (const c of n.contours) {
1918
+ function xi(s, t, n, o, e, i, r) {
1919
+ for (const c of t.contours) {
1639
1920
  if (c.length === 0) continue;
1640
- let r = c[c.length - 1];
1641
- for (const h of c) {
1642
- const l = r.color & h.color;
1643
- if (!(l & l - 1)) {
1644
- h.point(0, Xn);
1645
- const a = i * (Xn[0] + o), f = i * (Xn[1] + p), y = Math.floor(a - 0.5) | 0, _ = Math.floor(f - 0.5) | 0, u = y + 1, x = _ + 1;
1646
- y < t && _ < s && u >= 0 && x >= 0 && (y >= 0 && _ >= 0 && (e[_ * t + y] |= mt), u < t && _ >= 0 && (e[_ * t + u] |= mt), y >= 0 && x < s && (e[x * t + y] |= mt), u < t && x < s && (e[x * t + u] |= mt));
1921
+ let a = c[c.length - 1];
1922
+ for (const l of c) {
1923
+ const h = a.color & l.color;
1924
+ if (!(h & h - 1)) {
1925
+ l.point(0, ys);
1926
+ const p = e * (ys[0] + i), f = e * (ys[1] + r), u = Math.floor(p - 0.5) | 0, y = Math.floor(f - 0.5) | 0, x = u + 1, g = y + 1;
1927
+ u < n && y < o && x >= 0 && g >= 0 && (u >= 0 && y >= 0 && (s[y * n + u] |= Ht), x < n && y >= 0 && (s[y * n + x] |= Ht), u >= 0 && g < o && (s[g * n + u] |= Ht), x < n && g < o && (s[g * n + x] |= Ht));
1647
1928
  }
1648
- r = h;
1929
+ a = l;
1649
1930
  }
1650
1931
  }
1651
1932
  }
1652
- function Qt(e, n, t) {
1653
- let s = 0;
1654
- for (let i = 0; i < 3; i++) {
1655
- const o = e[n + i], p = e[t + i], c = o - p;
1933
+ function yn(s, t, n) {
1934
+ let o = 0;
1935
+ for (let e = 0; e < 3; e++) {
1936
+ const i = s[t + e], r = s[n + e], c = i - r;
1656
1937
  if (c === 0) continue;
1657
- const r = (o - 0.5) / c;
1658
- if (r > 0 && r < 1) {
1659
- const h = 1 - r, l = h * e[n] + r * e[t], a = h * e[n + 1] + r * e[t + 1], f = h * e[n + 2] + r * e[t + 2], y = i === 0 ? l : i === 1 ? a : f;
1660
- tt(l, a, f) === y && (s |= i === 0 ? Jt : i === 1 ? tn : nn);
1938
+ const a = (i - 0.5) / c;
1939
+ if (a > 0 && a < 1) {
1940
+ const l = 1 - a, h = l * s[t] + a * s[n], p = l * s[t + 1] + a * s[n + 1], f = l * s[t + 2] + a * s[n + 2], u = e === 0 ? h : e === 1 ? p : f;
1941
+ lt(h, p, f) === u && (o |= e === 0 ? qn : e === 1 ? Cn : vn);
1661
1942
  }
1662
1943
  }
1663
- return s;
1664
- }
1665
- function wt(e, n, t, s, i, o) {
1666
- (o & Jt && t[s] !== i || o & tn && t[s + 1] !== i || o & nn && t[s + 2] !== i) && (e[n] |= mt);
1944
+ return o;
1667
1945
  }
1668
- function yi(e, n, t, s, i, o) {
1669
- const p = Yn / o, c = Yn / o, r = Yn * Math.SQRT2 / o;
1670
- for (let h = 0; h < s; h++)
1671
- for (let l = 0; l < t - 1; l++) {
1672
- const a = (h * t + l) * 3, f = a + 3, y = tt(n[a], n[a + 1], n[a + 2]), _ = tt(n[f], n[f + 1], n[f + 2]);
1673
- if (Math.abs(y - 0.5) + Math.abs(_ - 0.5) < p) {
1674
- const u = Qt(n, a, f);
1675
- wt(e, h * t + l, n, a, y, u), wt(e, h * t + l + 1, n, f, _, u);
1946
+ function Ft(s, t, n, o, e, i) {
1947
+ (i & qn && n[o] !== e || i & Cn && n[o + 1] !== e || i & vn && n[o + 2] !== e) && (s[t] |= Ht);
1948
+ }
1949
+ function _i(s, t, n, o, e, i) {
1950
+ const r = us / i, c = us / i, a = us * Math.SQRT2 / i;
1951
+ for (let l = 0; l < o; l++)
1952
+ for (let h = 0; h < n - 1; h++) {
1953
+ const p = (l * n + h) * 3, f = p + 3, u = lt(t[p], t[p + 1], t[p + 2]), y = lt(t[f], t[f + 1], t[f + 2]);
1954
+ if (Math.abs(u - 0.5) + Math.abs(y - 0.5) < r) {
1955
+ const x = yn(t, p, f);
1956
+ Ft(s, l * n + h, t, p, u, x), Ft(s, l * n + h + 1, t, f, y, x);
1676
1957
  }
1677
1958
  }
1678
- for (let h = 0; h < s - 1; h++)
1679
- for (let l = 0; l < t; l++) {
1680
- const a = (h * t + l) * 3, f = ((h + 1) * t + l) * 3, y = tt(n[a], n[a + 1], n[a + 2]), _ = tt(n[f], n[f + 1], n[f + 2]);
1681
- if (Math.abs(y - 0.5) + Math.abs(_ - 0.5) < c) {
1682
- const u = Qt(n, a, f);
1683
- wt(e, h * t + l, n, a, y, u), wt(e, (h + 1) * t + l, n, f, _, u);
1959
+ for (let l = 0; l < o - 1; l++)
1960
+ for (let h = 0; h < n; h++) {
1961
+ const p = (l * n + h) * 3, f = ((l + 1) * n + h) * 3, u = lt(t[p], t[p + 1], t[p + 2]), y = lt(t[f], t[f + 1], t[f + 2]);
1962
+ if (Math.abs(u - 0.5) + Math.abs(y - 0.5) < c) {
1963
+ const x = yn(t, p, f);
1964
+ Ft(s, l * n + h, t, p, u, x), Ft(s, (l + 1) * n + h, t, f, y, x);
1684
1965
  }
1685
1966
  }
1686
- for (let h = 0; h < s - 1; h++)
1687
- for (let l = 0; l < t - 1; l++) {
1688
- const a = (h * t + l) * 3, f = (h * t + l + 1) * 3, y = ((h + 1) * t + l) * 3, _ = ((h + 1) * t + l + 1) * 3, u = tt(n[a], n[a + 1], n[a + 2]), x = tt(n[f], n[f + 1], n[f + 2]), M = tt(n[y], n[y + 1], n[y + 2]), w = tt(n[_], n[_ + 1], n[_ + 2]);
1689
- if (Math.abs(u - 0.5) + Math.abs(w - 0.5) < r) {
1690
- const v = Qt(n, a, _);
1691
- wt(e, h * t + l, n, a, u, v), wt(e, (h + 1) * t + l + 1, n, _, w, v);
1967
+ for (let l = 0; l < o - 1; l++)
1968
+ for (let h = 0; h < n - 1; h++) {
1969
+ const p = (l * n + h) * 3, f = (l * n + h + 1) * 3, u = ((l + 1) * n + h) * 3, y = ((l + 1) * n + h + 1) * 3, x = lt(t[p], t[p + 1], t[p + 2]), g = lt(t[f], t[f + 1], t[f + 2]), M = lt(t[u], t[u + 1], t[u + 2]), b = lt(t[y], t[y + 1], t[y + 2]);
1970
+ if (Math.abs(x - 0.5) + Math.abs(b - 0.5) < a) {
1971
+ const A = yn(t, p, y);
1972
+ Ft(s, l * n + h, t, p, x, A), Ft(s, (l + 1) * n + h + 1, t, y, b, A);
1692
1973
  }
1693
- if (Math.abs(x - 0.5) + Math.abs(M - 0.5) < r) {
1694
- const v = Qt(n, f, y);
1695
- wt(e, h * t + l + 1, n, f, x, v), wt(e, (h + 1) * t + l, n, y, M, v);
1974
+ if (Math.abs(g - 0.5) + Math.abs(M - 0.5) < a) {
1975
+ const A = yn(t, f, u);
1976
+ Ft(s, l * n + h + 1, t, f, g, A), Ft(s, (l + 1) * n + h, t, u, M, A);
1696
1977
  }
1697
1978
  }
1698
1979
  }
1699
- function ui(e, n, t) {
1700
- const s = n < e ? n : e, i = e < n ? n : e, o = t < i ? t : i;
1701
- return s < o ? o : s;
1980
+ function gi(s, t, n) {
1981
+ const o = t < s ? t : s, e = s < t ? t : s, i = n < e ? n : e;
1982
+ return o < i ? i : o;
1702
1983
  }
1703
- function _i(e, n, t, s) {
1704
- return tt(
1705
- e[n] + s * (e[t] - e[n]),
1706
- e[n + 1] + s * (e[t + 1] - e[n + 1]),
1707
- e[n + 2] + s * (e[t + 2] - e[n + 2])
1984
+ function di(s, t, n, o) {
1985
+ return lt(
1986
+ s[t] + o * (s[n] - s[t]),
1987
+ s[t + 1] + o * (s[n + 1] - s[t + 1]),
1988
+ s[t + 2] + o * (s[n + 2] - s[t + 2])
1708
1989
  );
1709
1990
  }
1710
- function Bn(e, n, t, s) {
1711
- return ui(
1712
- Math.fround(s * (s * t[0] + n[0]) + e[0]),
1713
- Math.fround(s * (s * t[1] + n[1]) + e[1]),
1714
- Math.fround(s * (s * t[2] + n[2]) + e[2])
1991
+ function ks(s, t, n, o) {
1992
+ return gi(
1993
+ Math.fround(o * (o * n[0] + t[0]) + s[0]),
1994
+ Math.fround(o * (o * n[1] + t[1]) + s[1]),
1995
+ Math.fround(o * (o * n[2] + t[2]) + s[2])
1715
1996
  );
1716
1997
  }
1717
- const vt = [0, 0, 0], bt = [0, 0, 0], Wn = [0, 0, 0], ft = [0, 0, 0], Vs = 1, Js = 2;
1718
- function $n(e, n, t, s, i, o, p, c) {
1719
- if (s > 0.5 && i > 0.5 && o <= 0.5 || s < 0.5 && i < 0.5 && o >= 0.5 || !c && xi(s, i, o) !== o) {
1720
- const r = (t - e) * p, h = (n - t) * p;
1721
- return o >= s - r && o <= s + r && o >= i - h && o <= i + h ? Vs : Vs | Js;
1998
+ const Nt = [0, 0, 0], It = [0, 0, 0], xs = [0, 0, 0], _t = [0, 0, 0], To = 1, Xo = 2;
1999
+ function Ds(s, t, n, o, e, i, r, c) {
2000
+ if (o > 0.5 && e > 0.5 && i <= 0.5 || o < 0.5 && e < 0.5 && i >= 0.5 || !c && Mi(o, e, i) !== i) {
2001
+ const a = (n - s) * r, l = (t - n) * r;
2002
+ return i >= o - a && i <= o + a && i >= e - l && i <= e + l ? To : To | Xo;
1722
2003
  }
1723
2004
  return 0;
1724
2005
  }
1725
- function to(e) {
1726
- return (e & Js) !== 0;
2006
+ function Wo(s) {
2007
+ return (s & Xo) !== 0;
1727
2008
  }
1728
- function xi(e, n, t) {
1729
- return Math.max(Math.min(e, n), Math.min(Math.max(e, n), t));
2009
+ function Mi(s, t, n) {
2010
+ return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
1730
2011
  }
1731
- function $t(e, n, t, s, i, o) {
1732
- const p = tt(e[t], e[t + 1], e[t + 2]);
1733
- if (Math.abs(s - 0.5) < Math.abs(p - 0.5)) return !1;
2012
+ function xn(s, t, n, o, e, i) {
2013
+ const r = lt(s[n], s[n + 1], s[n + 2]);
2014
+ if (Math.abs(o - 0.5) < Math.abs(r - 0.5)) return !1;
1734
2015
  for (let c = 0; c < 3; c++) {
1735
- const r = e[n + c] - e[n + (c + 1) % 3], h = e[t + c] - e[t + (c + 1) % 3], l = r - h;
1736
- if (l === 0) continue;
1737
- const a = r / l;
1738
- if (a > jt && a < 1 - jt) {
1739
- const f = _i(e, n, t, a), y = $n(0, 1, a, s, p, f, i, o);
1740
- if (to(y)) return !0;
2016
+ const a = s[t + c] - s[t + (c + 1) % 3], l = s[n + c] - s[n + (c + 1) % 3], h = a - l;
2017
+ if (h === 0) continue;
2018
+ const p = a / h;
2019
+ if (p > An && p < 1 - An) {
2020
+ const f = di(s, t, n, p), u = Ds(0, 1, p, o, r, f, e, i);
2021
+ if (Wo(u)) return !0;
1741
2022
  }
1742
2023
  }
1743
2024
  return !1;
1744
2025
  }
1745
- function zs(e, n, t, s, i, o, p, c, r) {
1746
- if (!(r > 0 && r < 1)) return 0;
1747
- const h = r > p ? 0 : r, l = r > p ? r : 1;
1748
- ft[0] = e[n], ft[1] = e[n + 1], ft[2] = e[n + 2];
1749
- const a = r > p ? t : Bn(ft, vt, bt, r);
1750
- ft[0] = e[n], ft[1] = e[n + 1], ft[2] = e[n + 2];
1751
- const f = r > p ? Bn(ft, vt, bt, r) : s;
1752
- return $n(h, l, p, a, f, c, i, o);
1753
- }
1754
- function Kt(e, n, t, s, i, o, p, c, r) {
1755
- if (!(p > jt && p < 1 - jt)) return !1;
1756
- ft[0] = e[n], ft[1] = e[n + 1], ft[2] = e[n + 2];
1757
- const h = Bn(ft, vt, bt, p);
1758
- let l = $n(0, 1, p, t, s, h, i, o);
1759
- return l |= zs(e, n, t, s, i, o, p, h, c), l |= zs(e, n, t, s, i, o, p, h, r), to(l);
1760
- }
1761
- function Hn(e, n, t, s, i, o, p, c, r, h, l, a, f) {
1762
- const y = Math.fround(e[n + h] - e[n + l]), _ = Math.fround(
1763
- Math.fround(e[t + h] - e[t + l]) + Math.fround(e[s + h] - e[s + l])
1764
- ), u = Math.fround(e[i + h] - e[i + l]), x = Math.fround(Math.fround(u - _) + y), M = Math.fround(Math.fround(_ - y) - y), w = y;
1765
- if (x === 0 || Math.abs(M) > 1e12 * Math.abs(x)) {
2026
+ function Fo(s, t, n, o, e, i, r, c, a) {
2027
+ if (!(a > 0 && a < 1)) return 0;
2028
+ const l = a > r ? 0 : a, h = a > r ? a : 1;
2029
+ _t[0] = s[t], _t[1] = s[t + 1], _t[2] = s[t + 2];
2030
+ const p = a > r ? n : ks(_t, Nt, It, a);
2031
+ _t[0] = s[t], _t[1] = s[t + 1], _t[2] = s[t + 2];
2032
+ const f = a > r ? ks(_t, Nt, It, a) : o;
2033
+ return Ds(l, h, r, p, f, c, e, i);
2034
+ }
2035
+ function _n(s, t, n, o, e, i, r, c, a) {
2036
+ if (!(r > An && r < 1 - An)) return !1;
2037
+ _t[0] = s[t], _t[1] = s[t + 1], _t[2] = s[t + 2];
2038
+ const l = ks(_t, Nt, It, r);
2039
+ let h = Ds(0, 1, r, n, o, l, e, i);
2040
+ return h |= Fo(s, t, n, o, e, i, r, l, c), h |= Fo(s, t, n, o, e, i, r, l, a), Wo(h);
2041
+ }
2042
+ function _s(s, t, n, o, e, i, r, c, a, l, h, p, f) {
2043
+ const u = Math.fround(s[t + l] - s[t + h]), y = Math.fround(
2044
+ Math.fround(s[n + l] - s[n + h]) + Math.fround(s[o + l] - s[o + h])
2045
+ ), x = Math.fround(s[e + l] - s[e + h]), g = Math.fround(Math.fround(x - y) + u), M = Math.fround(Math.fround(y - u) - u), b = u;
2046
+ if (g === 0 || Math.abs(M) > 1e12 * Math.abs(g)) {
1766
2047
  if (M !== 0) {
1767
- const C = -w / M;
1768
- if (Kt(e, n, o, p, c, r, C, a, f)) return !0;
2048
+ const F = -b / M;
2049
+ if (_n(s, t, i, r, c, a, F, p, f)) return !0;
1769
2050
  }
1770
2051
  return !1;
1771
2052
  }
1772
- const v = M * M - 4 * x * w;
1773
- if (v > 0) {
1774
- const C = Math.sqrt(v), A = (-M + C) / (2 * x);
1775
- if (Kt(e, n, o, p, c, r, A, a, f)) return !0;
1776
- const D = (-M - C) / (2 * x);
1777
- if (Kt(e, n, o, p, c, r, D, a, f)) return !0;
1778
- } else if (v === 0) {
1779
- const C = -M / (2 * x);
1780
- if (Kt(e, n, o, p, c, r, C, a, f)) return !0;
2053
+ const A = M * M - 4 * g * b;
2054
+ if (A > 0) {
2055
+ const F = Math.sqrt(A), k = (-M + F) / (2 * g);
2056
+ if (_n(s, t, i, r, c, a, k, p, f)) return !0;
2057
+ const T = (-M - F) / (2 * g);
2058
+ if (_n(s, t, i, r, c, a, T, p, f)) return !0;
2059
+ } else if (A === 0) {
2060
+ const F = -M / (2 * g);
2061
+ if (_n(s, t, i, r, c, a, F, p, f)) return !0;
1781
2062
  }
1782
2063
  return !1;
1783
2064
  }
1784
- function Zt(e, n, t, s, i, o, p, c) {
1785
- const r = tt(e[i], e[i + 1], e[i + 2]);
1786
- if (Math.abs(o - 0.5) < Math.abs(r - 0.5)) return !1;
2065
+ function gn(s, t, n, o, e, i, r, c) {
2066
+ const a = lt(s[e], s[e + 1], s[e + 2]);
2067
+ if (Math.abs(i - 0.5) < Math.abs(a - 0.5)) return !1;
1787
2068
  for (let f = 0; f < 3; f++)
1788
- Wn[f] = Math.fround(
1789
- Math.fround(e[n + f] - e[t + f]) - e[s + f]
1790
- ), vt[f] = Math.fround(-e[n + f] - Wn[f]), bt[f] = Math.fround(e[i + f] + Wn[f]);
1791
- const h = bt[0] !== 0 ? -0.5 * vt[0] / bt[0] : -1, l = bt[1] !== 0 ? -0.5 * vt[1] / bt[1] : -1, a = bt[2] !== 0 ? -0.5 * vt[2] / bt[2] : -1;
1792
- return !!(Hn(
1793
- e,
1794
- n,
1795
- t,
2069
+ xs[f] = Math.fround(
2070
+ Math.fround(s[t + f] - s[n + f]) - s[o + f]
2071
+ ), Nt[f] = Math.fround(-s[t + f] - xs[f]), It[f] = Math.fround(s[e + f] + xs[f]);
2072
+ const l = It[0] !== 0 ? -0.5 * Nt[0] / It[0] : -1, h = It[1] !== 0 ? -0.5 * Nt[1] / It[1] : -1, p = It[2] !== 0 ? -0.5 * Nt[2] / It[2] : -1;
2073
+ return !!(_s(
1796
2074
  s,
1797
- i,
2075
+ t,
2076
+ n,
1798
2077
  o,
2078
+ e,
2079
+ i,
2080
+ a,
1799
2081
  r,
1800
- p,
1801
2082
  c,
1802
2083
  0,
1803
2084
  1,
1804
- h,
1805
- l
1806
- ) || Hn(
1807
- e,
1808
- n,
1809
- t,
2085
+ l,
2086
+ h
2087
+ ) || _s(
1810
2088
  s,
1811
- i,
2089
+ t,
2090
+ n,
1812
2091
  o,
2092
+ e,
2093
+ i,
2094
+ a,
1813
2095
  r,
1814
- p,
1815
2096
  c,
1816
2097
  1,
1817
2098
  2,
1818
- l,
1819
- a
1820
- ) || Hn(
1821
- e,
1822
- n,
1823
- t,
2099
+ h,
2100
+ p
2101
+ ) || _s(
1824
2102
  s,
1825
- i,
2103
+ t,
2104
+ n,
1826
2105
  o,
2106
+ e,
2107
+ i,
2108
+ a,
1827
2109
  r,
1828
- p,
1829
2110
  c,
1830
2111
  2,
1831
2112
  0,
1832
- a,
1833
- h
2113
+ p,
2114
+ l
1834
2115
  ));
1835
2116
  }
1836
- function Mi(e, n, t, s, i, o) {
1837
- const p = o / i, c = o / i, r = o * Math.SQRT2 / i;
1838
- for (let h = 0; h < s; h++)
1839
- for (let l = 0; l < t; l++) {
1840
- const a = h * t + l, f = a * 3, y = tt(n[f], n[f + 1], n[f + 2]), _ = (e[a] & mt) !== 0, u = l > 0, x = l < t - 1, M = h > 0, w = h < s - 1, v = u ? (a - 1) * 3 : -1, C = x ? (a + 1) * 3 : -1, A = M ? (a - t) * 3 : -1, D = w ? (a + t) * 3 : -1;
1841
- let I = !1;
1842
- if (u && $t(n, f, v, y, p, _) && (I = !0), !I && M && $t(n, f, A, y, c, _) && (I = !0), !I && x && $t(n, f, C, y, p, _) && (I = !0), !I && w && $t(n, f, D, y, c, _) && (I = !0), !I && u && M) {
1843
- const F = (a - t - 1) * 3;
1844
- Zt(n, f, v, A, F, y, r, _) && (I = !0);
2117
+ function mi(s, t, n, o, e, i) {
2118
+ const r = i / e, c = i / e, a = i * Math.SQRT2 / e;
2119
+ for (let l = 0; l < o; l++)
2120
+ for (let h = 0; h < n; h++) {
2121
+ const p = l * n + h, f = p * 3, u = lt(t[f], t[f + 1], t[f + 2]), y = (s[p] & Ht) !== 0, x = h > 0, g = h < n - 1, M = l > 0, b = l < o - 1, A = x ? (p - 1) * 3 : -1, F = g ? (p + 1) * 3 : -1, k = M ? (p - n) * 3 : -1, T = b ? (p + n) * 3 : -1;
2122
+ let q = !1;
2123
+ if (x && xn(t, f, A, u, r, y) && (q = !0), !q && M && xn(t, f, k, u, c, y) && (q = !0), !q && g && xn(t, f, F, u, r, y) && (q = !0), !q && b && xn(t, f, T, u, c, y) && (q = !0), !q && x && M) {
2124
+ const m = (p - n - 1) * 3;
2125
+ gn(t, f, A, k, m, u, a, y) && (q = !0);
1845
2126
  }
1846
- if (!I && x && M) {
1847
- const F = (a - t + 1) * 3;
1848
- Zt(n, f, C, A, F, y, r, _) && (I = !0);
2127
+ if (!q && g && M) {
2128
+ const m = (p - n + 1) * 3;
2129
+ gn(t, f, F, k, m, u, a, y) && (q = !0);
1849
2130
  }
1850
- if (!I && u && w) {
1851
- const F = (a + t - 1) * 3;
1852
- Zt(n, f, v, D, F, y, r, _) && (I = !0);
2131
+ if (!q && x && b) {
2132
+ const m = (p + n - 1) * 3;
2133
+ gn(t, f, A, T, m, u, a, y) && (q = !0);
1853
2134
  }
1854
- if (!I && x && w) {
1855
- const F = (a + t + 1) * 3;
1856
- Zt(n, f, C, D, F, y, r, _) && (I = !0);
2135
+ if (!q && g && b) {
2136
+ const m = (p + n + 1) * 3;
2137
+ gn(t, f, F, T, m, u, a, y) && (q = !0);
1857
2138
  }
1858
- I && (e[a] |= js);
2139
+ q && (s[p] |= Yo);
1859
2140
  }
1860
2141
  }
1861
- function gi(e, n, t, s) {
1862
- const i = t * s;
1863
- for (let o = 0; o < i; o++)
1864
- if (e[o] & js) {
1865
- const p = o * 3, c = tt(n[p], n[p + 1], n[p + 2]);
1866
- n[p] = c, n[p + 1] = c, n[p + 2] = c;
2142
+ function bi(s, t, n, o) {
2143
+ const e = n * o;
2144
+ for (let i = 0; i < e; i++)
2145
+ if (s[i] & Yo) {
2146
+ const r = i * 3, c = lt(t[r], t[r + 1], t[r + 2]);
2147
+ t[r] = c, t[r + 1] = c, t[r + 2] = c;
1867
2148
  }
1868
2149
  }
1869
- function tt(e, n, t) {
1870
- return Math.max(Math.min(e, n), Math.min(Math.max(e, n), t));
1871
- }
1872
- function di(e) {
1873
- let n = 0, t = 0;
1874
- for (const c of e)
1875
- n += c.w * c.h, t = Math.max(t, c.w);
1876
- e.sort((c, r) => r.h - c.h);
1877
- const i = [{ x: 0, y: 0, w: Math.max(Math.ceil(Math.sqrt(n / 0.95)), t), h: 1 / 0 }];
1878
- let o = 0, p = 0;
1879
- for (const c of e)
1880
- for (let r = i.length - 1; r >= 0; r--) {
1881
- const h = i[r];
1882
- if (!(c.w > h.w || c.h > h.h)) {
1883
- if (c.x = h.x, c.y = h.y, p = Math.max(p, c.y + c.h), o = Math.max(o, c.x + c.w), c.w === h.w && c.h === h.h) {
1884
- const l = i.pop();
1885
- l && r < i.length && (i[r] = l);
1886
- } else c.h === h.h ? (h.x += c.w, h.w -= c.w) : c.w === h.w ? (h.y += c.h, h.h -= c.h) : (i.push({
1887
- x: h.x + c.w,
1888
- y: h.y,
1889
- w: h.w - c.w,
2150
+ function lt(s, t, n) {
2151
+ return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
2152
+ }
2153
+ const wi = 3, Ai = 0n, So = 16;
2154
+ function ki(s, t, n, o = !0) {
2155
+ if (o && Be(s), s.contours.length === 0) return null;
2156
+ const e = kn(s), i = t, r = n, c = Math.max(1, Math.ceil((e.maxX - e.minX) * i)) + 2 * r, a = Math.max(1, Math.ceil((e.maxY - e.minY) * i)) + 2 * r, l = r / i - e.minX, h = r / i - e.minY;
2157
+ Re(s), si(s, wi, Ai);
2158
+ const p = new Float32Array(c * a * 3);
2159
+ return ii(s, c, a, i, l, h, r, p), ui(p, s, c, a, i, l, h), yi(p, s, c, a, i, l, h, r), {
2160
+ msdf: p,
2161
+ w: c,
2162
+ h: a,
2163
+ planeLeft: -l,
2164
+ planeBottom: -h,
2165
+ planeRight: c / i - l,
2166
+ planeTop: a / i - h
2167
+ };
2168
+ }
2169
+ const gs = [0, 0];
2170
+ function kn(s) {
2171
+ let t = 1 / 0, n = 1 / 0, o = -1 / 0, e = -1 / 0;
2172
+ for (const i of s.contours)
2173
+ for (const r of i)
2174
+ for (let c = 0; c <= So; c++) {
2175
+ r.point(c / So, gs);
2176
+ const a = gs[0], l = gs[1];
2177
+ a < t && (t = a), l < n && (n = l), a > o && (o = a), l > e && (e = l);
2178
+ }
2179
+ return { minX: t, minY: n, maxX: o, maxY: e };
2180
+ }
2181
+ function Q(s, t) {
2182
+ var n;
2183
+ return (n = new RegExp(`\\s${t}\\s*=\\s*(["'])([\\s\\S]*?)\\1`).exec(s)) == null ? void 0 : n[2];
2184
+ }
2185
+ function In(s, t, n) {
2186
+ const o = new RegExp(`(?:^|;)\\s*${t}\\s*:\\s*([^;]+)`, "g"), e = (c) => {
2187
+ var a, l;
2188
+ return (l = (a = [...c.matchAll(o)].pop()) == null ? void 0 : a[1]) == null ? void 0 : l.trim();
2189
+ }, i = Q(s, "class");
2190
+ let r = "";
2191
+ if (i && n) {
2192
+ const c = new Set(i.split(/\s+/));
2193
+ r = n.filter(([a]) => c.has(a)).map(([, a]) => a).join(";");
2194
+ }
2195
+ return e(Q(s, "style") ?? "") ?? e(r) ?? Q(s, t);
2196
+ }
2197
+ function En(s, t) {
2198
+ return s === void 0 ? t : parseFloat(s) / (s.trim().endsWith("%") ? 100 : 1);
2199
+ }
2200
+ function Ot(s, t) {
2201
+ return s === void 0 ? 0 : parseFloat(s) * (s.trim().endsWith("%") ? t / 100 : 1);
2202
+ }
2203
+ function Fi(s) {
2204
+ const { layers: t, width: n } = Ii(s);
2205
+ return { shape: { contours: t.flatMap((e) => e.shape.contours), inverseYAxis: !1 }, width: n };
2206
+ }
2207
+ function Ii(s) {
2208
+ var k, T;
2209
+ s = s.replace(/<!--[\s\S]*?-->/g, "");
2210
+ const t = ((k = /<svg\b[^>]*>/.exec(s)) == null ? void 0 : k[0]) ?? "", n = (Q(t, "viewBox") ?? `0 0 ${Q(t, "width")} ${Q(t, "height")}`).trim().split(/[\s,]+/).map(parseFloat), [o = 0, e = 0, i = NaN, r = NaN] = n;
2211
+ if (!(r > 0)) throw new Error("parseSvg: needs a viewBox or width/height");
2212
+ const c = [i, r], a = [r, 0, 0, -r, o, e + r], l = [1, 0, 0, -1, -o, e + r], h = i / r, p = [];
2213
+ i > 0 && Dn(`M${o} ${e}h${i}v${r}h${-i}z`, l, p), dn({ contours: p }, r);
2214
+ const f = /* @__PURE__ */ new Map(), u = /<(linear|radial)Gradient\b([^>]*?)(?:\/>|>([\s\S]*?)<\/\1Gradient>)/g;
2215
+ for (const [, q = "", m = "", d = ""] of s.matchAll(u))
2216
+ f.set(Q(m, "id") ?? "", [q, m, d]);
2217
+ const y = /* @__PURE__ */ new Map();
2218
+ for (const [, q = "", m = ""] of s.matchAll(
2219
+ /<clipPath\b([^>]*?)(?:\/>|>([\s\S]*?)<\/clipPath>)/g
2220
+ ))
2221
+ y.set(Q(q, "id") ?? "", [q, m]);
2222
+ const x = /* @__PURE__ */ new Map();
2223
+ for (const [, q = "", m = ""] of s.matchAll(Ho)) {
2224
+ const d = Q(m, "id");
2225
+ d !== void 0 && x.set(d, [q, m]);
2226
+ }
2227
+ const g = [];
2228
+ for (const [, q = ""] of s.matchAll(/<style\b[^>]*>([\s\S]*?)<\/style>/g))
2229
+ for (const [, m = "", d = ""] of q.matchAll(/([^{}]+)\{([^}]*)\}/g))
2230
+ for (const _ of m.split(",")) {
2231
+ const w = (T = /^\s*\.([\w-]+)\s*$/.exec(_)) == null ? void 0 : T[1];
2232
+ w && g.push([w, d]);
2233
+ }
2234
+ const M = [], b = [], A = [
2235
+ {
2236
+ m: [1, 0, 0, 1, 0, 0],
2237
+ fill: "black",
2238
+ rule: "nonzero",
2239
+ fillOpacity: 1,
2240
+ opacity: 1,
2241
+ clips: [],
2242
+ // every clip region on the way here, each in shape space
2243
+ group: -1
2244
+ // innermost container with opacity < 1, in `groups`
2245
+ }
2246
+ ];
2247
+ let F = 0;
2248
+ for (const [, q, m = "", d = "", _] of s.matchAll(
2249
+ /<(\/?)([\w:-]+)([^>]*?)(\/?)>/g
2250
+ )) {
2251
+ if (F > 0 || /^(defs|clipPath|mask|symbol|pattern|marker|style)$/.test(m)) {
2252
+ q ? F-- : _ || F++;
2253
+ continue;
2254
+ }
2255
+ if (q) {
2256
+ A.pop();
2257
+ continue;
2258
+ }
2259
+ const w = A[A.length - 1], E = (ht) => In(d, ht, g), I = En(E("opacity"), 1), C = Bo(m, d, c), S = {
2260
+ m: dt(w.m, sn(Q(d, "transform") ?? "")),
2261
+ fill: E("fill") ?? w.fill,
2262
+ rule: E("fill-rule") ?? w.rule,
2263
+ fillOpacity: En(E("fill-opacity"), w.fillOpacity),
2264
+ opacity: w.opacity * I,
2265
+ clips: w.clips,
2266
+ group: w.group
2267
+ };
2268
+ C === void 0 && I < 1 && !_ && (S.group = b.push({ members: [], parent: w.group, translucent: !1 }) - 1);
2269
+ const O = y.get(Ro(E("clip-path")));
2270
+ if (O && Q(O[0], "clipPathUnits") !== "objectBoundingBox" && (S.clips = [...w.clips, Ei(O, x, g, dt(l, S.m), c)]), _ || A.push(S), C === void 0 || S.fill === "none") continue;
2271
+ const L = [];
2272
+ Dn(C, dt(l, S.m), L), S.rule === "evenodd" && No(L);
2273
+ const W = { contours: L, inverseYAxis: !1 };
2274
+ dn(W, r);
2275
+ const X = f.get(Ro(S.fill)), H = dt(Vo(S.m), a), J = X ? Di(X, f, g, H, C, c) : null;
2276
+ for (const ht of S.clips) ko(W, ht);
2277
+ const z = kn(W);
2278
+ if (!(z.maxX <= 0 || z.minX >= h || z.maxY <= 0 || z.minY >= 1 || ((z.minX < 0 || z.minY < 0 || z.maxX > h || z.maxY > 1) && p.length > 0 && ko(W, [p]), W.contours.length === 0))) {
2279
+ if (S.group >= 0) {
2280
+ const ht = b[S.group];
2281
+ ht.members.push(M.length);
2282
+ const vt = J ? J.stops.some((Dt) => Dt.opacity < 1) : !1;
2283
+ (I < 1 || S.fillOpacity < 1 || vt) && (ht.translucent = !0);
2284
+ for (let Dt = ht.parent; Dt >= 0; Dt = b[Dt].parent) b[Dt].translucent = !0;
2285
+ }
2286
+ M.push({
2287
+ shape: W,
2288
+ color: S.fill,
2289
+ opacity: S.opacity * S.fillOpacity,
2290
+ gradient: J
2291
+ });
2292
+ }
2293
+ }
2294
+ for (const q of b) {
2295
+ if (q.translucent || q.members.length < 2) continue;
2296
+ const m = q.members.map((d) => kn(M[d].shape));
2297
+ for (let d = 0; d < q.members.length - 1; d++) {
2298
+ const _ = m[d], w = [];
2299
+ for (let E = d + 1; E < q.members.length; E++) {
2300
+ const I = m[E];
2301
+ I.minX < _.maxX && _.minX < I.maxX && I.minY < _.maxY && _.minY < I.maxY && w.push(M[q.members[E]].shape.contours);
2302
+ }
2303
+ Ve(M[q.members[d]].shape, w);
2304
+ }
2305
+ }
2306
+ return { layers: M.filter((q) => q.shape.contours.length > 0), width: i / r };
2307
+ }
2308
+ const Ho = /<([\w:-]+)\b([^>]*?)\/?>/g;
2309
+ function Ro(s) {
2310
+ var t;
2311
+ return ((t = /url\(\s*['"]?#([^)'"\s]+)/.exec(s ?? "")) == null ? void 0 : t[1]) ?? "";
2312
+ }
2313
+ function Ei([s = "", t = ""], n, o, e, i) {
2314
+ var h;
2315
+ const [r = 0, c = 1] = i, a = [], l = dt(e, sn(Q(s, "transform") ?? ""));
2316
+ for (const [, p = "", f = ""] of t.matchAll(Ho)) {
2317
+ let u = [p, f], y = dt(l, sn(Q(f, "transform") ?? ""));
2318
+ if (p === "use") {
2319
+ const b = n.get(((h = Q(f, "(?:xlink:)?href")) == null ? void 0 : h.slice(1)) ?? "");
2320
+ if (!b) continue;
2321
+ y = dt(y, [1, 0, 0, 1, Ot(Q(f, "x"), r), Ot(Q(f, "y"), c)]), y = dt(y, sn(Q(b[1], "transform") ?? "")), u = b;
2322
+ }
2323
+ const x = Bo(u[0], u[1], i);
2324
+ if (x === void 0) continue;
2325
+ const g = [];
2326
+ Dn(x, y, g), [u[1], f, s].map((b) => In(b, "clip-rule", o)).find(Boolean) === "evenodd" && No(g), dn({ contours: g }, c), a.push(g);
2327
+ }
2328
+ return a;
2329
+ }
2330
+ function Bo(s, t, [n = 0, o = 0]) {
2331
+ const e = (f, u) => Ot(Q(t, f), u), [i, r, c, a] = [e("x", n), e("y", o), e("width", n), e("height", o)], [l, h, p] = [e("cx", n), e("cy", o), Math.hypot(n, o) / Math.SQRT2];
2332
+ switch (s) {
2333
+ case "path":
2334
+ return Q(t, "d") ?? "";
2335
+ case "polygon":
2336
+ case "polyline":
2337
+ return `M${Q(t, "points") ?? "0 0"}`;
2338
+ case "circle":
2339
+ case "ellipse": {
2340
+ const [f, u] = s === "circle" ? [e("r", p), e("r", p)] : [e("rx", n), e("ry", o)], y = `A${f} ${u} 0 1 0`;
2341
+ return `M${l - f} ${h}${y} ${l + f} ${h}${y} ${l - f} ${h}Z`;
2342
+ }
2343
+ case "rect": {
2344
+ const [f, u] = [Q(t, "rx"), Q(t, "ry")], y = Math.min(f === void 0 ? Ot(u, o) : Ot(f, n), c / 2), x = Math.min(u === void 0 ? Ot(f, n) : Ot(u, o), a / 2), g = `A${y} ${x} 0 0 1`;
2345
+ return `M${i + y} ${r}H${i + c - y}${g} ${i + c} ${r + x}V${r + a - x}${g} ${i + c - y} ${r + a}H${i + y}${g} ${i} ${r + a - x}V${r + x}${g} ${i + y} ${r}Z`;
2346
+ }
2347
+ default:
2348
+ return;
2349
+ }
2350
+ }
2351
+ function Di(s, t, n, o, e, [i = 0, r = 0]) {
2352
+ var d;
2353
+ const c = [];
2354
+ for (let _ = s; _ && !c.includes(_); )
2355
+ c.push(_), _ = t.get(((d = Q(_[1] ?? "", "(?:xlink:)?href")) == null ? void 0 : d.slice(1)) ?? "");
2356
+ const a = (_) => c.map((w) => Q(w[1] ?? "", _)).find((w) => w !== void 0), l = a("gradientUnits") === "userSpaceOnUse", h = (_, w, E) => {
2357
+ const I = a(_) ?? w;
2358
+ return parseFloat(I) * (I.trim().endsWith("%") ? (l ? E : 1) / 100 : 1);
2359
+ };
2360
+ let p = sn(a("gradientTransform") ?? "");
2361
+ if (!l) {
2362
+ const _ = [];
2363
+ Dn(e, [1, 0, 0, 1, 0, 0], _);
2364
+ const w = kn({ contours: _ });
2365
+ p = dt([w.maxX - w.minX, 0, 0, w.maxY - w.minY, w.minX, w.minY], p);
2366
+ }
2367
+ const f = s[0] === "radial", [u, y] = [h("x1", "0%", i), h("y1", "0%", r)], [x, g] = [h("x2", "100%", i) - u, h("y2", "0%", r) - y], M = Math.hypot(i, r) / Math.SQRT2, [b, A, F] = [h("cx", "50%", i), h("cy", "50%", r), h("r", "50%", M)], k = x * x + g * g || 1, T = f ? [1 / F, 0, 0, 1 / F, -b / F, -A / F] : [x / k, 0, g / k, 0, -(u * x + y * g) / k, 0], m = [...(c.map((_) => _[2] ?? "").find((_) => /<stop\b/.test(_)) ?? "").matchAll(/<stop\b[^>]*>/g)].map(([_]) => ({
2368
+ offset: En(Q(_, "offset"), 0),
2369
+ color: In(_, "stop-color", n) ?? "black",
2370
+ opacity: En(In(_, "stop-opacity", n), 1)
2371
+ }));
2372
+ return { radial: f, matrix: dt(T, dt(Vo(p), o)), stops: m };
2373
+ }
2374
+ function dt(s, t) {
2375
+ const [n = 0, o = 0, e = 0, i = 0, r = 0, c = 0] = s, [a = 0, l = 0, h = 0, p = 0, f = 0, u = 0] = t;
2376
+ return [
2377
+ n * a + e * l,
2378
+ o * a + i * l,
2379
+ n * h + e * p,
2380
+ o * h + i * p,
2381
+ n * f + e * u + r,
2382
+ o * f + i * u + c
2383
+ ];
2384
+ }
2385
+ function qi([s = 0, t = 0, n = 0, o = 0, e = 0, i = 0], r, c) {
2386
+ return [s * r + n * c + e, t * r + o * c + i];
2387
+ }
2388
+ function Vo([s = 0, t = 0, n = 0, o = 0, e = 0, i = 0]) {
2389
+ const r = s * o - t * n;
2390
+ return [o / r, -t / r, -n / r, s / r, (n * i - o * e) / r, (t * e - s * i) / r];
2391
+ }
2392
+ function sn(s) {
2393
+ let t = [1, 0, 0, 1, 0, 0];
2394
+ for (const [, n, o = ""] of s.matchAll(/(\w+)\s*\(([^)]*)\)/g)) {
2395
+ const [e = 0, i, r, c = 0, a = 0, l = 0] = o.trim().split(/[\s,]+/).map(parseFloat), h = e * Math.PI / 180, [p, f] = [Math.cos(h), Math.sin(h)], [u, y] = [i ?? 0, r ?? 0];
2396
+ t = dt(
2397
+ t,
2398
+ n === "matrix" ? [e, i ?? 0, r ?? 0, c, a, l] : n === "translate" ? [1, 0, 0, 1, e, i ?? 0] : n === "scale" ? [e, 0, 0, i ?? e, 0, 0] : n === "rotate" ? [p, f, -f, p, u - p * u + f * y, y - f * u - p * y] : n === "skewX" ? [1, 0, Math.tan(h), 1, 0, 0] : [1, Math.tan(h), 0, 1, 0, 0]
2399
+ // skewY
2400
+ );
2401
+ }
2402
+ return t;
2403
+ }
2404
+ const ds = /[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/y;
2405
+ function Dn(s, t, n) {
2406
+ let o = 0, e = 0, i = 0, r = 0, c = 0, a = 0, l = 0, h = "", p = "", f = [];
2407
+ const u = () => {
2408
+ for (; o < s.length && ` \r
2409
+ ,`.includes(s[o]); ) o++;
2410
+ }, y = () => {
2411
+ u(), ds.lastIndex = o;
2412
+ const b = ds.exec(s);
2413
+ if (!b) throw new Error(`parseSvg: expected a number at ${o} in path "${s}"`);
2414
+ return o = ds.lastIndex, parseFloat(b[0]);
2415
+ }, x = () => (u(), s[o++] === "1" ? 1 : 0), g = (b, ...A) => {
2416
+ const F = [e, i, ...A], k = [];
2417
+ for (let C = 0; C < F.length; C += 2) k.push(...qi(t, F[C], F[C + 1]));
2418
+ const [T = 0, q = 0, m = 0, d = 0, _ = 0, w = 0, E = 0, I = 0] = k;
2419
+ f.push(new st(b, T, q, m, d, _, w, E, I)), e = A[A.length - 2], i = A[A.length - 1];
2420
+ }, M = () => {
2421
+ f.length > 0 && ((e !== r || i !== c) && g(nt, r, c), n.push(f), f = []), e = r, i = c;
2422
+ };
2423
+ for (u(); o < s.length; u()) {
2424
+ if (/[a-zA-Z]/.test(s[o])) h = s[o++];
2425
+ else if (!h) throw new Error(`parseSvg: expected a command at ${o} in path "${s}"`);
2426
+ const b = h.toUpperCase(), A = h === b ? 0 : e, F = h === b ? 0 : i, k = b === "S" && "CS".includes(p) || b === "T" && "QT".includes(p), T = k ? 2 * e - a : e, q = k ? 2 * i - l : i;
2427
+ switch (b) {
2428
+ case "M": {
2429
+ const m = A + y(), d = F + y();
2430
+ M(), e = r = m, i = c = d, h = h === "M" ? "L" : "l";
2431
+ break;
2432
+ }
2433
+ case "L":
2434
+ g(nt, A + y(), F + y());
2435
+ break;
2436
+ case "H":
2437
+ g(nt, A + y(), i);
2438
+ break;
2439
+ case "V":
2440
+ g(nt, e, F + y());
2441
+ break;
2442
+ case "C":
2443
+ case "S": {
2444
+ const m = b === "C" ? A + y() : T, d = b === "C" ? F + y() : q;
2445
+ a = A + y(), l = F + y(), g(Ct, m, d, a, l, A + y(), F + y());
2446
+ break;
2447
+ }
2448
+ case "Q":
2449
+ case "T":
2450
+ a = b === "Q" ? A + y() : T, l = b === "Q" ? F + y() : q, g(ct, a, l, A + y(), F + y());
2451
+ break;
2452
+ case "A": {
2453
+ const m = y(), d = y(), _ = y(), w = x(), E = x();
2454
+ Ci(g, e, i, m, d, _, w, E, A + y(), F + y());
2455
+ break;
2456
+ }
2457
+ case "Z":
2458
+ M(), h = "";
2459
+ break;
2460
+ default:
2461
+ throw new Error(`parseSvg: unknown path command "${h}"`);
2462
+ }
2463
+ p = b;
2464
+ }
2465
+ M();
2466
+ }
2467
+ function Ci(s, t, n, o, e, i, r, c, a, l) {
2468
+ if (t === a && n === l) return;
2469
+ if (o = Math.abs(o), e = Math.abs(e), o === 0 || e === 0) return s(nt, a, l);
2470
+ const h = Math.cos(i * Math.PI / 180), p = Math.sin(i * Math.PI / 180), f = (t - a) / 2, u = (n - l) / 2, y = h * f + p * u, x = -p * f + h * u, g = y * y / (o * o) + x * x / (e * e);
2471
+ g > 1 && (o *= Math.sqrt(g), e *= Math.sqrt(g));
2472
+ const M = o * o * x * x + e * e * y * y, b = (r === c ? -1 : 1) * Math.sqrt(Math.max(0, (o * o * e * e - M) / M)), A = b * o * x / e, F = -b * e * y / o, k = h * A - p * F + (t + a) / 2, T = p * A + h * F + (n + l) / 2, q = Math.atan2((x - F) / e, (y - A) / o);
2473
+ let m = Math.atan2((-x - F) / e, (-y - A) / o) - q;
2474
+ c && m < 0 ? m += 2 * Math.PI : !c && m > 0 && (m -= 2 * Math.PI);
2475
+ const d = Math.max(1, Math.ceil(Math.abs(m) / (Math.PI / 2) - 1e-9)), _ = m / d, w = 4 / 3 * Math.tan(_ / 4), E = (C, S) => k + o * C * h - e * S * p, I = (C, S) => T + o * C * p + e * S * h;
2476
+ for (let C = 0; C < d; C++) {
2477
+ const S = Math.cos(q + C * _), O = Math.sin(q + C * _), L = Math.cos(q + (C + 1) * _), W = Math.sin(q + (C + 1) * _), X = C === d - 1;
2478
+ s(
2479
+ Ct,
2480
+ E(S - w * O, O + w * S),
2481
+ I(S - w * O, O + w * S),
2482
+ E(L + w * W, W - w * L),
2483
+ I(L + w * W, W - w * L),
2484
+ X ? a : E(L, W),
2485
+ X ? l : I(L, W)
2486
+ );
2487
+ }
2488
+ }
2489
+ function vi(s) {
2490
+ let t = 0, n = 0;
2491
+ for (const c of s)
2492
+ t += c.w * c.h, n = Math.max(n, c.w);
2493
+ s.sort((c, a) => a.h - c.h);
2494
+ const e = [{ x: 0, y: 0, w: Math.max(Math.ceil(Math.sqrt(t / 0.95)), n), h: 1 / 0 }];
2495
+ let i = 0, r = 0;
2496
+ for (const c of s)
2497
+ for (let a = e.length - 1; a >= 0; a--) {
2498
+ const l = e[a];
2499
+ if (!(c.w > l.w || c.h > l.h)) {
2500
+ if (c.x = l.x, c.y = l.y, r = Math.max(r, c.y + c.h), i = Math.max(i, c.x + c.w), c.w === l.w && c.h === l.h) {
2501
+ const h = e.pop();
2502
+ h && a < e.length && (e[a] = h);
2503
+ } else c.h === l.h ? (l.x += c.w, l.w -= c.w) : c.w === l.w ? (l.y += c.h, l.h -= c.h) : (e.push({
2504
+ x: l.x + c.w,
2505
+ y: l.y,
2506
+ w: l.w - c.w,
1890
2507
  h: c.h
1891
- }), h.y += c.h, h.h -= c.h);
2508
+ }), l.y += c.h, l.h -= c.h);
1892
2509
  break;
1893
2510
  }
1894
2511
  }
1895
2512
  return {
1896
- w: o,
2513
+ w: i,
1897
2514
  // container width
1898
- h: p,
2515
+ h: r,
1899
2516
  // container height
1900
- fill: n / (o * p) || 0
2517
+ fill: t / (i * r) || 0
1901
2518
  // space utilization
1902
2519
  };
1903
2520
  }
1904
- const bi = 3, Ai = 0n, Bs = 4, Qs = 16;
1905
- function Vn(e) {
1906
- const n = e < 0 ? 0 : e > 1 ? 1 : e;
1907
- return ~Math.trunc(255.5 - 255 * n) & 255;
2521
+ const Lo = 4;
2522
+ function Ms(s) {
2523
+ const t = s < 0 ? 0 : s > 1 ? 1 : s;
2524
+ return ~Math.trunc(255.5 - 255 * t) & 255;
1908
2525
  }
1909
- class Ei {
1910
- constructor(n, t = {}) {
1911
- this._width = 0, this._height = 0, this._pixels = new Uint8Array(0), this._cache = /* @__PURE__ */ new Map(), this._cacheByGid = /* @__PURE__ */ new Map(), this._font = n, this._pxPerEm = t.pixelsPerEm ?? 40, this._pxrange = t.pxrange ?? 4, this.pxrangeEm = this._pxrange / this._pxPerEm;
2526
+ class Si {
2527
+ /**
2528
+ * @param font Font for the glyph/layout methods; `null` for a shapes-only atlas.
2529
+ * @param opts Generation scale and distance range.
2530
+ */
2531
+ constructor(t, n = {}) {
2532
+ this._width = 0, this._height = 0, this._pixels = new Uint8Array(0), this._cache = /* @__PURE__ */ new Map(), this._cacheByKey = /* @__PURE__ */ new Map(), this._font = t, this._pxPerEm = n.pixelsPerEm ?? 40, this._pxrange = n.pxrange ?? 4, this._floats = n.float ? new Float32Array(0) : null, this.pxrangeEm = this._pxrange / this._pxPerEm;
1912
2533
  }
1913
2534
  /** Packed atlas texture width in texels (chosen by potpack). */
1914
2535
  get width() {
@@ -1922,97 +2543,97 @@ class Ei {
1922
2543
  get texture() {
1923
2544
  return this._pixels;
1924
2545
  }
2546
+ /** {@link Atlas.texture} as raw float RGB, not clamped to [0, 1], for zoom that
2547
+ * outruns 8 bits; `null` without the `float` option. */
2548
+ get floatTexture() {
2549
+ return this._floats;
2550
+ }
1925
2551
  /**
1926
2552
  * Batched generate + pack. Generates MSDFs for any codepoints not
1927
2553
  * already cached, then runs potpack **once** over the whole cache.
1928
2554
  * Returns the `AtlasGlyph` for each requested codepoint, in order.
1929
2555
  */
1930
- glyphs(n) {
1931
- const t = [];
1932
- let s = 0;
1933
- for (const i of n) {
1934
- const o = this._cache.get(i);
1935
- if (o) {
1936
- t.push(o.glyph);
1937
- continue;
1938
- }
1939
- const p = this._generateForGlyphId(this._font.glyphId(i));
1940
- this._cache.set(i, p), t.push(p.glyph), s++;
1941
- }
1942
- return s > 0 && this._repack(), t;
2556
+ glyphs(t) {
2557
+ const n = this._requireFont();
2558
+ return this.glyphsByIndex(Array.from(t, (o) => n.glyphId(o)));
1943
2559
  }
1944
2560
  /**
1945
2561
  * Single-glyph convenience: generates + packs if missing. Repacks the
1946
2562
  * whole atlas on every new insert — for more than one glyph, use
1947
2563
  * {@link Atlas.glyphs} instead.
1948
2564
  */
1949
- glyph(n) {
1950
- return this.glyphs([n])[0];
2565
+ glyph(t) {
2566
+ return this.glyphs([t])[0];
1951
2567
  }
1952
2568
  /**
1953
2569
  * Batched generate + pack, addressed by raw glyph index instead of
1954
2570
  * Unicode codepoint — the {@link Atlas.glyphs} twin for glyphs with no
1955
2571
  * reachable cmap entry. Icon fonts (e.g. Lucide) commonly have far more
1956
2572
  * glyphs than mapped codepoints; this is how the rest of the set gets
1957
- * generated. Shares one packed atlas texture with the codepoint-addressed
1958
- * cache — {@link Atlas.texture} always reflects everything requested
1959
- * through either method. Cached separately from {@link Atlas.glyphs} (a
1960
- * codepoint and a glyph index are different numbers in the same integer
1961
- * space — sharing one cache would collide them).
2573
+ * generated. Shares one cache and one packed atlas texture with
2574
+ * {@link Atlas.glyphs}, which maps codepoints to glyph indices first.
1962
2575
  */
1963
- glyphsByIndex(n) {
1964
- const t = [];
1965
- let s = 0;
1966
- for (const i of n) {
1967
- const o = this._cacheByGid.get(i);
1968
- if (o) {
1969
- t.push(o.glyph);
2576
+ glyphsByIndex(t) {
2577
+ const n = [];
2578
+ let o = 0;
2579
+ for (const e of t) {
2580
+ const i = this._cache.get(e);
2581
+ if (i) {
2582
+ n.push(i.glyph);
1970
2583
  continue;
1971
2584
  }
1972
- const p = this._generateForGlyphId(i);
1973
- this._cacheByGid.set(i, p), t.push(p.glyph), s++;
2585
+ const r = this._generateForGlyphId(e);
2586
+ this._cache.set(e, r), n.push(r.glyph), o++;
1974
2587
  }
1975
- return s > 0 && this._repack(), t;
2588
+ return o > 0 && this._repack(), n;
1976
2589
  }
1977
2590
  /** Single-glyph convenience for {@link Atlas.glyphsByIndex} — see its
1978
2591
  * doc. For more than one glyph, prefer {@link Atlas.glyphsByIndex}
1979
2592
  * (one potpack for the whole batch instead of one per insert). */
1980
- glyphByIndex(n) {
1981
- return this.glyphsByIndex([n])[0];
2593
+ glyphByIndex(t) {
2594
+ return this.glyphsByIndex([t])[0];
1982
2595
  }
1983
2596
  /**
1984
- * Generates the MSDF for `glyphId`. Does not cache and does not pack —
1985
- * callers own the cache key (a codepoint for {@link Atlas.glyphs}, the
1986
- * glyph ID itself for {@link Atlas.glyphsByIndex}) and the repack.
2597
+ * Batched generate + pack for arbitrary shapes (e.g. from `parseSvg`),
2598
+ * keyed by a caller-chosen string — the {@link Atlas.glyphs} twin for
2599
+ * non-font input. Shapes must be y-up, in the units `pixelsPerEm` scales
2600
+ * (`parseSvg` makes 1 unit = the viewBox height). A new shape is mutated
2601
+ * (overlaps merged, normalized + coloured); a cached key ignores the shape
2602
+ * passed. `advance` is 0. Shares the one packed texture with the glyph cache.
1987
2603
  */
1988
- _generateForGlyphId(n) {
1989
- const t = this._font, s = t.metrics.unitsPerEm, i = t.advance(n) / s, o = t.shape(n);
1990
- if (Uo(o, s), o.contours.length === 0)
1991
- return { glyph: {
1992
- x: 0,
1993
- y: 0,
1994
- w: 0,
1995
- h: 0,
1996
- advance: i,
1997
- planeLeft: 0,
1998
- planeBottom: 0,
1999
- planeRight: 0,
2000
- planeTop: 0
2001
- }, msdf: null };
2002
- const p = wi(o), c = this._pxPerEm, r = this._pxrange, h = Math.max(1, Math.ceil((p.maxX - p.minX) * c)) + 2 * r, l = Math.max(1, Math.ceil((p.maxY - p.minY) * c)) + 2 * r, a = r / c - p.minX, f = r / c - p.minY;
2003
- Ho(o), Jo(o, bi, Ai);
2004
- const y = new Float32Array(h * l * 3);
2005
- return si(o, h, l, c, a, f, r, y), pi(y, o, h, l, c, a, f), li(y, o, h, l, c, a, f, r), { glyph: {
2604
+ shapes(t) {
2605
+ const n = [];
2606
+ let o = 0;
2607
+ for (const [e, i] of t) {
2608
+ let r = this._cacheByKey.get(e);
2609
+ r || (r = this._generate(i, 0), this._cacheByKey.set(e, r), o++), n.push(r.glyph);
2610
+ }
2611
+ return o > 0 && this._repack(), n;
2612
+ }
2613
+ /** The font, or a clear error for glyph/layout calls on a shapes-only atlas. */
2614
+ _requireFont() {
2615
+ if (!this._font) throw new Error("Atlas: no font — this atlas only supports shapes()");
2616
+ return this._font;
2617
+ }
2618
+ /** Generates the MSDF for `glyphId`. Does not cache and does not pack. */
2619
+ _generateForGlyphId(t) {
2620
+ const n = this._requireFont(), o = n.metrics.unitsPerEm, e = n.shape(t);
2621
+ return dn(e, o), this._generate(e, n.advance(t) / o);
2622
+ }
2623
+ /** Generates one entry from an em-unit shape. Does not cache or pack. */
2624
+ _generate(t, n) {
2625
+ const o = ki(t, this._pxPerEm, this._pxrange);
2626
+ return { glyph: {
2006
2627
  x: 0,
2007
2628
  y: 0,
2008
- w: h,
2009
- h: l,
2010
- advance: i,
2011
- planeLeft: -a,
2012
- planeBottom: -f,
2013
- planeRight: h / c - a,
2014
- planeTop: l / c - f
2015
- }, msdf: y };
2629
+ w: o ? o.w : 0,
2630
+ h: o ? o.h : 0,
2631
+ advance: n,
2632
+ planeLeft: o ? o.planeLeft : 0,
2633
+ planeBottom: o ? o.planeBottom : 0,
2634
+ planeRight: o ? o.planeRight : 0,
2635
+ planeTop: o ? o.planeTop : 0
2636
+ }, msdf: o ? o.msdf : null };
2016
2637
  }
2017
2638
  /**
2018
2639
  * Lays out `text` left-to-right on a single line, applying kerning.
@@ -2021,19 +2642,19 @@ class Ei {
2021
2642
  * is the pen position in em. `text` must not contain `\n` — use
2022
2643
  * {@link Atlas.layoutMultiline} for multi-line input.
2023
2644
  */
2024
- layout(n) {
2025
- const t = [];
2026
- for (const r of n) t.push(r.codePointAt(0));
2027
- this.glyphs(t);
2028
- const s = [], i = this._font, o = i.metrics.unitsPerEm;
2029
- let p = 0, c = -1;
2030
- for (const r of t) {
2031
- const h = i.glyphId(r);
2032
- c >= 0 && (p += i.kerning(c, h) / o);
2033
- const l = this._cache.get(r).glyph;
2034
- s.push({ glyph: l, penX: p, penY: 0 }), p += l.advance, c = h;
2645
+ layout(t) {
2646
+ const n = [];
2647
+ for (const a of t) n.push(a.codePointAt(0));
2648
+ this.glyphs(n);
2649
+ const o = [], e = this._requireFont(), i = e.metrics.unitsPerEm;
2650
+ let r = 0, c = -1;
2651
+ for (const a of n) {
2652
+ const l = e.glyphId(a);
2653
+ c >= 0 && (r += e.kerning(c, l) / i);
2654
+ const h = this._cache.get(l).glyph;
2655
+ o.push({ glyph: h, penX: r, penY: 0 }), r += h.advance, c = l;
2035
2656
  }
2036
- return { glyphs: s, widthEm: p };
2657
+ return { glyphs: o, widthEm: r };
2037
2658
  }
2038
2659
  /**
2039
2660
  * Lays out `text` as one or more `\n`-separated lines, each run through
@@ -2050,65 +2671,62 @@ class Ei {
2050
2671
  * not per-glyph ink bounds) — fine for camera framing, not for tight
2051
2672
  * cropping.
2052
2673
  */
2053
- layoutMultiline(n) {
2054
- const t = this._font, s = t.metrics.unitsPerEm, i = (t.metrics.ascender - t.metrics.descender + t.metrics.lineGap) / s, o = n.split(`
2055
- `), p = [];
2674
+ layoutMultiline(t) {
2675
+ const n = this._requireFont(), o = n.metrics.unitsPerEm, e = (n.metrics.ascender - n.metrics.descender + n.metrics.lineGap) / o, i = t.split(`
2676
+ `), r = [];
2056
2677
  let c = 0;
2057
- for (let r = 0; r < o.length; r++) {
2058
- const { glyphs: h, widthEm: l } = this.layout(o[r]), a = -r * i;
2059
- for (const f of h) p.push({ glyph: f.glyph, penX: f.penX, penY: a });
2060
- l > c && (c = l);
2678
+ for (let a = 0; a < i.length; a++) {
2679
+ const { glyphs: l, widthEm: h } = this.layout(i[a]), p = -a * e;
2680
+ for (const f of l) r.push({ glyph: f.glyph, penX: f.penX, penY: p });
2681
+ h > c && (c = h);
2061
2682
  }
2062
- return { glyphs: p, widthEm: c, heightEm: o.length * i };
2683
+ return { glyphs: r, widthEm: c, heightEm: i.length * e };
2063
2684
  }
2064
- /** Repacks every cached glyph (both the codepoint- and glyph-index-keyed
2065
- * caches — one shared texture) with potpack, reallocates the texture,
2066
- * and re-blits each MSDF at its assigned rect. Called by `glyphs()`/
2067
- * `glyphsByIndex()` after any batch of new inserts — once per batch. */
2685
+ /** Repacks every cached entry (glyph-index- and string-keyed caches — one
2686
+ * shared texture) with potpack, reallocates the texture, and re-blits each
2687
+ * MSDF at its assigned rect. Called by `glyphsByIndex()`/`shapes()` after
2688
+ * any batch of new inserts — once per batch.
2689
+ *
2690
+ * Each cell gets a 1-texel gutter of zeros on its right and bottom, so a
2691
+ * quad covering the whole cell can sample its full rect: linear filtering
2692
+ * at the edge blends with zeros (further outside the glyph), never with a
2693
+ * neighbouring glyph's texels. */
2068
2694
  _repack() {
2069
- const n = [];
2070
- for (const i of this._cache.values())
2071
- i.msdf !== null && n.push({ w: i.glyph.w, h: i.glyph.h, x: 0, y: 0, entry: i });
2072
- for (const i of this._cacheByGid.values())
2073
- i.msdf !== null && n.push({ w: i.glyph.w, h: i.glyph.h, x: 0, y: 0, entry: i });
2074
- const { w: t, h: s } = di(n);
2075
- this._width = t, this._height = s, this._pixels = new Uint8Array(t * s * Bs);
2076
- for (const i of n)
2077
- i.entry.glyph.x = i.x, i.entry.glyph.y = i.y, this._blit(i.entry.msdf, i.x, i.y, i.w, i.h);
2695
+ const t = [];
2696
+ for (const e of [this._cache, this._cacheByKey])
2697
+ for (const { glyph: i, msdf: r } of e.values())
2698
+ r && t.push({ w: i.w + 1, h: i.h + 1, x: 0, y: 0, glyph: i, msdf: r });
2699
+ const { w: n, h: o } = vi(t);
2700
+ this._width = n, this._height = o, this._pixels = new Uint8Array(n * o * Lo), this._floats && (this._floats = new Float32Array(n * o * 3));
2701
+ for (const e of t)
2702
+ e.glyph.x = e.x, e.glyph.y = e.y, this._blit(e.msdf, e.x, e.y, e.glyph.w, e.glyph.h);
2078
2703
  }
2079
2704
  /**
2080
2705
  * Quantise `msdf` (float, y-up, row 0 = bottom, w×h×3) into `_pixels` at
2081
2706
  * atlas rect (`ax`, `ay`, `w`, `h`) — the single y-flip point.
2082
2707
  */
2083
- _blit(n, t, s, i, o) {
2084
- const p = this._width, c = this._pixels;
2085
- for (let r = 0; r < o; r++) {
2086
- const h = s + (o - 1 - r);
2087
- for (let l = 0; l < i; l++) {
2088
- const a = (r * i + l) * 3, f = (h * p + (t + l)) * Bs;
2089
- c[f] = Vn(n[a]), c[f + 1] = Vn(n[a + 1]), c[f + 2] = Vn(n[a + 2]), c[f + 3] = 255;
2708
+ _blit(t, n, o, e, i) {
2709
+ var a;
2710
+ const r = this._width, c = this._pixels;
2711
+ for (let l = 0; l < i; l++) {
2712
+ const h = o + (i - 1 - l);
2713
+ (a = this._floats) == null || a.set(t.subarray(l * e * 3, (l + 1) * e * 3), (h * r + n) * 3);
2714
+ for (let p = 0; p < e; p++) {
2715
+ const f = (l * e + p) * 3, u = (h * r + (n + p)) * Lo;
2716
+ c[u] = Ms(t[f]), c[u + 1] = Ms(t[f + 1]), c[u + 2] = Ms(t[f + 2]), c[u + 3] = 255;
2090
2717
  }
2091
2718
  }
2092
2719
  }
2093
2720
  }
2094
- const zn = [0, 0];
2095
- function wi(e) {
2096
- let n = 1 / 0, t = 1 / 0, s = -1 / 0, i = -1 / 0;
2097
- for (const o of e.contours)
2098
- for (const p of o)
2099
- for (let c = 0; c <= Qs; c++) {
2100
- p.point(c / Qs, zn);
2101
- const r = zn[0], h = zn[1];
2102
- r < n && (n = r), h < t && (t = h), r > s && (s = r), h > i && (i = h);
2103
- }
2104
- return { minX: n, minY: t, maxX: s, maxY: i };
2105
- }
2106
2721
  export {
2107
- Ei as Atlas,
2108
- Ot as CUBIC,
2109
- et as EdgeSegment,
2110
- Di as Font,
2111
- at as LINEAR,
2112
- it as QUADRATIC,
2113
- Vn as pixelFloatToByte
2722
+ Si as Atlas,
2723
+ Ct as CUBIC,
2724
+ st as EdgeSegment,
2725
+ Ti as Font,
2726
+ nt as LINEAR,
2727
+ ct as QUADRATIC,
2728
+ ki as generateShapeMSDF,
2729
+ Fi as parseSvg,
2730
+ Ii as parseSvgLayers,
2731
+ Ms as pixelFloatToByte
2114
2732
  };