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,4 +1,4 @@
1
- class Mt {
1
+ class wt {
2
2
  /**
3
3
  * @param buffer Source buffer (the full font file).
4
4
  * @param byteOffset Starting position (default 0).
@@ -78,228 +78,228 @@ class Mt {
78
78
  return this._view.getInt16(t, !1);
79
79
  }
80
80
  }
81
- function io(i, t) {
82
- const n = new Mt(i, t);
81
+ function Co(o, t) {
82
+ const n = new wt(o, t);
83
83
  n.skip(2);
84
84
  const s = n.u16();
85
- let o = null;
86
- for (let p = 0; p < s; p++) {
87
- const c = n.u16(), r = n.u16(), h = n.u32(), l = t + h, a = n.peekU16(l);
85
+ let i = null;
86
+ for (let a = 0; a < s; a++) {
87
+ const c = n.u16(), r = n.u16(), h = n.u32(), p = t + h, l = n.peekU16(p);
88
88
  let f = -1;
89
- 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 > ((o == null ? void 0 : o.priority) ?? -1) && (o = { priority: f, subtableAbsOffset: l });
89
+ c === 3 && r === 10 && l === 12 ? f = 5 : c === 0 && r === 6 && l === 12 ? f = 4 : c === 0 && r === 4 && l === 12 ? f = 3 : c === 3 && r === 1 && l === 4 ? f = 2 : c === 0 && r <= 3 && l === 4 && (f = 1), f > ((i == null ? void 0 : i.priority) ?? -1) && (i = { priority: f, subtableAbsOffset: p });
90
90
  }
91
- if (!o) return () => 0;
92
- const e = n.peekU16(o.subtableAbsOffset);
93
- return e === 12 ? co(i, o.subtableAbsOffset) : e === 4 ? ro(i, o.subtableAbsOffset) : () => 0;
91
+ if (!i) return () => 0;
92
+ const e = n.peekU16(i.subtableAbsOffset);
93
+ return e === 12 ? Fo(o, i.subtableAbsOffset) : e === 4 ? Ro(o, i.subtableAbsOffset) : () => 0;
94
94
  }
95
- function co(i, t) {
96
- const n = new Mt(i, t);
95
+ function Fo(o, t) {
96
+ const n = new wt(o, t);
97
97
  n.skip(2), n.skip(2), n.skip(4), n.skip(4);
98
- const s = n.u32(), o = new Uint32Array(s), e = new Uint32Array(s), p = new Uint32Array(s);
98
+ const s = n.u32(), i = new Uint32Array(s), e = new Uint32Array(s), a = new Uint32Array(s);
99
99
  for (let c = 0; c < s; c++)
100
- o[c] = n.u32(), e[c] = n.u32(), p[c] = n.u32();
100
+ i[c] = n.u32(), e[c] = n.u32(), a[c] = n.u32();
101
101
  return (c) => {
102
102
  let r = 0, h = s - 1;
103
103
  for (; r <= h; ) {
104
- const l = r + h >>> 1, a = o[l] ?? 0, f = e[l] ?? 0;
105
- if (c < a) h = l - 1;
106
- else if (c > f) r = l + 1;
107
- else return (p[l] ?? 0) + (c - a);
104
+ const p = r + h >>> 1, l = i[p] ?? 0, f = e[p] ?? 0;
105
+ if (c < l) h = p - 1;
106
+ else if (c > f) r = p + 1;
107
+ else return (a[p] ?? 0) + (c - l);
108
108
  }
109
109
  return 0;
110
110
  };
111
111
  }
112
- function ro(i, t) {
113
- const n = new Mt(i, t);
112
+ function Ro(o, t) {
113
+ const n = new wt(o, t);
114
114
  n.skip(2), n.skip(2), n.skip(2);
115
- const o = n.u16() >>> 1;
115
+ const i = n.u16() >>> 1;
116
116
  n.skip(6);
117
- const e = new Uint16Array(o);
118
- for (let a = 0; a < o; a++) e[a] = n.u16();
117
+ const e = new Uint16Array(i);
118
+ for (let l = 0; l < i; l++) e[l] = n.u16();
119
119
  n.skip(2);
120
- const p = new Uint16Array(o);
121
- for (let a = 0; a < o; a++) p[a] = n.u16();
122
- const c = new Int16Array(o);
123
- for (let a = 0; a < o; a++) c[a] = n.i16();
124
- const r = new Int32Array(o), h = new Uint16Array(o);
125
- for (let a = 0; a < o; a++)
126
- r[a] = n.pos, h[a] = n.u16();
127
- const l = new DataView(i);
128
- return (a) => {
129
- if (a > 65535) return 0;
130
- let f = 0, y = o - 1;
131
- for (; f <= y; ) {
132
- const _ = f + y >>> 1, u = e[_] ?? 0;
133
- if (a > u)
120
+ const a = new Uint16Array(i);
121
+ for (let l = 0; l < i; l++) a[l] = n.u16();
122
+ const c = new Int16Array(i);
123
+ for (let l = 0; l < i; l++) c[l] = n.i16();
124
+ const r = new Int32Array(i), h = new Uint16Array(i);
125
+ for (let l = 0; l < i; l++)
126
+ r[l] = n.pos, h[l] = n.u16();
127
+ const p = new DataView(o);
128
+ return (l) => {
129
+ if (l > 65535) return 0;
130
+ let f = 0, u = i - 1;
131
+ for (; f <= u; ) {
132
+ const _ = f + u >>> 1, y = e[_] ?? 0;
133
+ if (l > y)
134
134
  f = _ + 1;
135
- else if (a < (p[_] ?? 0))
136
- y = _ - 1;
135
+ else if (l < (a[_] ?? 0))
136
+ u = _ - 1;
137
137
  else {
138
138
  if ((e[_] ?? 0) === 65535) return 0;
139
- const g = h[_] ?? 0, A = c[_] ?? 0, m = p[_] ?? 0;
140
- if (g === 0)
141
- return a + A & 65535;
142
- const v = (r[_] ?? 0) + g + (a - m) * 2, w = l.getUint16(v, !1);
143
- return w === 0 ? 0 : w + A & 65535;
139
+ const M = h[_] ?? 0, I = c[_] ?? 0, q = a[_] ?? 0;
140
+ if (M === 0)
141
+ return l + I & 65535;
142
+ const T = (r[_] ?? 0) + M + (l - q) * 2, A = p.getUint16(T, !1);
143
+ return A === 0 ? 0 : A + I & 65535;
144
144
  }
145
145
  }
146
146
  return 0;
147
147
  };
148
148
  }
149
- function ao(i, t) {
150
- const n = new Mt(i, t);
149
+ function To(o, t) {
150
+ const n = new wt(o, t);
151
151
  n.skip(4), n.skip(4), n.skip(4), n.skip(4), n.skip(2);
152
152
  const s = n.u16();
153
153
  n.skip(16), n.skip(8), n.skip(2), n.skip(2), n.skip(2);
154
- const o = n.i16();
155
- return { unitsPerEm: s, indexToLocFormat: o };
154
+ const i = n.i16();
155
+ return { unitsPerEm: s, indexToLocFormat: i };
156
156
  }
157
- function ho(i, t) {
158
- const n = new Mt(i, t);
157
+ function So(o, t) {
158
+ const n = new wt(o, t);
159
159
  n.skip(4);
160
- const s = n.i16(), o = n.i16(), e = n.i16();
160
+ const s = n.i16(), i = n.i16(), e = n.i16();
161
161
  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);
162
- const p = n.u16();
163
- return { ascender: s, descender: o, lineGap: e, numberOfHMetrics: p };
162
+ const a = n.u16();
163
+ return { ascender: s, descender: i, lineGap: e, numberOfHMetrics: a };
164
164
  }
165
- function po(i, t, n, s) {
166
- const o = new Mt(i, t), e = new Array(n);
167
- let p = 0;
165
+ function Lo(o, t, n, s) {
166
+ const i = new wt(o, t), e = [];
167
+ let a = 0;
168
168
  for (let c = 0; c < s; c++) {
169
- const r = o.u16(), h = o.i16();
170
- e[c] = { advanceWidth: r, lsb: h }, p = r;
169
+ const r = i.u16(), h = i.i16();
170
+ e[c] = { advanceWidth: r, lsb: h }, a = r;
171
171
  }
172
172
  for (let c = s; c < n; c++) {
173
- const r = o.i16();
174
- e[c] = { advanceWidth: p, lsb: r };
173
+ const r = i.i16();
174
+ e[c] = { advanceWidth: a, lsb: r };
175
175
  }
176
176
  return e;
177
177
  }
178
- function lo(i, t, n, s) {
179
- const o = new Mt(i, t), e = n + 1, p = new Array(e);
178
+ function Po(o, t, n, s) {
179
+ const i = new wt(o, t), e = n + 1, a = [];
180
180
  if (s === 0)
181
- for (let c = 0; c < e; c++) p[c] = o.u16() * 2;
181
+ for (let c = 0; c < e; c++) a[c] = i.u16() * 2;
182
182
  else
183
- for (let c = 0; c < e; c++) p[c] = o.u32();
184
- return p;
183
+ for (let c = 0; c < e; c++) a[c] = i.u32();
184
+ return a;
185
185
  }
186
- function fo(i, t) {
187
- const n = new Mt(i, t);
186
+ function Oo(o, t) {
187
+ const n = new wt(o, t);
188
188
  return n.skip(4), { numGlyphs: n.u16() };
189
189
  }
190
- function yo(i, t, n, s) {
191
- return i * n + t * s;
190
+ function No(o, t, n, s) {
191
+ return o * n + t * s;
192
192
  }
193
- function J(i, t, n, s) {
194
- return i * s - t * n;
193
+ function z(o, t, n, s) {
194
+ return o * s - t * n;
195
195
  }
196
- function uo(i, t, n) {
197
- return (1 - n) * i + n * t;
196
+ function Go(o, t, n) {
197
+ return (1 - n) * o + n * t;
198
198
  }
199
- function rt(i) {
200
- return +(i > 0) - +(i < 0);
199
+ function pt(o) {
200
+ return +(o > 0) - +(o < 0);
201
201
  }
202
- function Et(i) {
203
- return 2 * +(i > 0) - 1;
202
+ function qt(o) {
203
+ return 2 * +(o > 0) - 1;
204
204
  }
205
- function $s(i, t, n, s) {
205
+ function bo(o, t, n, s) {
206
206
  if (t === 0 || Math.abs(n) > 1e12 * Math.abs(t))
207
- return n === 0 ? s === 0 ? -1 : 0 : (i[0] = -s / n, 1);
208
- const o = n * n - 4 * t * s;
209
- if (o > 0) {
210
- const e = Math.sqrt(o);
211
- return i[0] = (-n + e) / (2 * t), i[1] = (-n - e) / (2 * t), 2;
212
- } else if (o === 0)
213
- return i[0] = -n / (2 * t), 1;
207
+ return n === 0 ? s === 0 ? -1 : 0 : (o[0] = -s / n, 1);
208
+ const i = n * n - 4 * t * s;
209
+ if (i > 0) {
210
+ const e = Math.sqrt(i);
211
+ return o[0] = (-n + e) / (2 * t), o[1] = (-n - e) / (2 * t), 2;
212
+ } else if (i === 0)
213
+ return o[0] = -n / (2 * t), 1;
214
214
  return 0;
215
215
  }
216
- function _o(i, t, n, s) {
217
- const o = t * t, e = 1 / 9 * (o - 3 * n), p = 1 / 54 * (t * (2 * o - 9 * n) + 27 * s), c = p * p, r = e * e * e, h = t * (1 / 3);
216
+ function Uo(o, t, n, s) {
217
+ const i = t * t, e = 1 / 9 * (i - 3 * n), a = 1 / 54 * (t * (2 * i - 9 * n) + 27 * s), c = a * a, r = e * e * e, h = t * (1 / 3);
218
218
  if (c < r) {
219
- let l = p / Math.sqrt(r);
220
- l < -1 && (l = -1), l > 1 && (l = 1), l = Math.acos(l);
221
- const a = -2 * Math.sqrt(e);
222
- return i[0] = a * Math.cos(1 / 3 * l) - h, i[1] = a * Math.cos(1 / 3 * (l + 2 * Math.PI)) - h, i[2] = a * Math.cos(1 / 3 * (l - 2 * Math.PI)) - h, 3;
219
+ let p = a / Math.sqrt(r);
220
+ p < -1 && (p = -1), p > 1 && (p = 1), p = Math.acos(p);
221
+ const l = -2 * Math.sqrt(e);
222
+ return o[0] = l * Math.cos(1 / 3 * p) - h, o[1] = l * Math.cos(1 / 3 * (p + 2 * Math.PI)) - h, o[2] = l * Math.cos(1 / 3 * (p - 2 * Math.PI)) - h, 3;
223
223
  } else {
224
- const l = (p < 0 ? 1 : -1) * Math.pow(Math.abs(p) + Math.sqrt(c - r), 0.3333333333333333), a = l === 0 ? 0 : e / l;
225
- return i[0] = l + a - h, l === a || Math.abs(l - a) < 1e-12 * Math.abs(l + a) ? (i[1] = -0.5 * (l + a) - h, 2) : 1;
224
+ const p = (a < 0 ? 1 : -1) * Math.pow(Math.abs(a) + Math.sqrt(c - r), 0.3333333333333333), l = p === 0 ? 0 : e / p;
225
+ return o[0] = p + l - h, p === l || Math.abs(p - l) < 1e-12 * Math.abs(p + l) ? (o[1] = -0.5 * (p + l) - h, 2) : 1;
226
226
  }
227
227
  }
228
- function xo(i, t, n, s, o) {
228
+ function Yo(o, t, n, s, i) {
229
229
  if (t !== 0) {
230
230
  const e = n / t;
231
231
  if (Math.abs(e) < 1e6)
232
- return _o(i, e, s / t, o / t);
232
+ return Uo(o, e, s / t, i / t);
233
233
  }
234
- return $s(i, n, s, o);
234
+ return bo(o, n, s, i);
235
235
  }
236
- const go = 24;
237
- function Pt(i, t, n, s) {
238
- return ((s + i) * s + t) * s + n;
236
+ const Xo = 24;
237
+ function Bt(o, t, n, s) {
238
+ return ((s + o) * s + t) * s + n;
239
239
  }
240
- function Mo(i, t, n, s, o, e, p) {
240
+ function Wo(o, t, n, s, i, e, a) {
241
241
  const c = e < 0;
242
- let r = s - e * (o - s) / (p - e);
243
- r > s && r < o || (r = 0.5 * (s + o));
244
- for (let h = 0; h < go; h++) {
245
- const l = Pt(i, t, n, r);
246
- if (l === 0) return r;
247
- l < 0 === c ? s = r : o = r;
248
- const a = (3 * r + 2 * i) * r + t;
249
- let f = r - l / a;
250
- f > s && f < o || (f = 0.5 * (s + o));
251
- const y = f - r;
252
- if (r = f, (y < 0 ? -y : y) <= 1e-15 * (r < 0 ? -r : r)) break;
242
+ let r = s - e * (i - s) / (a - e);
243
+ r > s && r < i || (r = 0.5 * (s + i));
244
+ for (let h = 0; h < Xo; h++) {
245
+ const p = Bt(o, t, n, r);
246
+ if (p === 0) return r;
247
+ p < 0 === c ? s = r : i = r;
248
+ const l = (3 * r + 2 * o) * r + t;
249
+ let f = r - p / l;
250
+ f > s && f < i || (f = 0.5 * (s + i));
251
+ const u = f - r;
252
+ if (r = f, (u < 0 ? -u : u) <= 1e-15 * (r < 0 ? -r : r)) break;
253
253
  }
254
254
  return r;
255
255
  }
256
- function Bt(i, t, n, s, o, e, p, c, r) {
257
- return e === 0 ? c[r++] = s : e < 0 != p < 0 && (c[r++] = Mo(i, t, n, s, o, e, p)), r;
256
+ function rn(o, t, n, s, i, e, a, c, r) {
257
+ return e === 0 ? c[r++] = s : e < 0 != a < 0 && (c[r++] = Wo(o, t, n, s, i, e, a)), r;
258
258
  }
259
- function bo(i, t, n, s, o, e) {
260
- let p = 0;
261
- if (i === 0) {
259
+ function Ho(o, t, n, s, i, e) {
260
+ let a = 0;
261
+ if (o === 0) {
262
262
  if (t === 0) return 0;
263
263
  const f = -n / t;
264
- return f >= s && f <= o && (e[p++] = f), p;
264
+ return f >= s && f <= i && (e[a++] = f), a;
265
265
  }
266
- const c = t * t - 4 * i * n;
266
+ const c = t * t - 4 * o * n;
267
267
  if (c < 0) return 0;
268
268
  const r = Math.sqrt(c), h = -0.5 * (t + (t < 0 ? -r : r));
269
- let l, a;
269
+ let p, l;
270
270
  if (h === 0)
271
- l = 0, a = 0;
272
- else if (l = h / i, a = n / h, l > a) {
273
- const f = l;
274
- l = a, a = f;
271
+ p = 0, l = 0;
272
+ else if (p = h / o, l = n / h, p > l) {
273
+ const f = p;
274
+ p = l, l = f;
275
275
  }
276
- return l >= s && l <= o && (e[p++] = l), a !== l && a >= s && a <= o && (e[p++] = a), p;
276
+ return p >= s && p <= i && (e[a++] = p), l !== p && l >= s && l <= i && (e[a++] = l), a;
277
277
  }
278
- function wo(i, t, n, s, o, e, p) {
279
- if (i === 0) return bo(t, n, s, o, e, p);
280
- const c = 1 / i;
278
+ function Vo(o, t, n, s, i, e, a) {
279
+ if (o === 0) return Ho(t, n, s, i, e, a);
280
+ const c = 1 / o;
281
281
  t *= c, n *= c, s *= c;
282
- const r = Pt(t, n, s, o), h = Pt(t, n, s, e), l = t * t - 3 * n;
283
- let a = 0;
284
- if (l <= 0)
285
- a = Bt(t, n, s, o, e, r, h, p, 0);
282
+ const r = Bt(t, n, s, i), h = Bt(t, n, s, e), p = t * t - 3 * n;
283
+ let l = 0;
284
+ if (p <= 0)
285
+ l = rn(t, n, s, i, e, r, h, a, 0);
286
286
  else {
287
- const f = Math.sqrt(l) / 3, y = -t / 3, _ = y - f, u = y + f;
288
- let x = o, g = r;
289
- if (_ > o && _ < e) {
290
- const A = Pt(t, n, s, _);
291
- a = Bt(t, n, s, x, _, g, A, p, a), x = _, g = A;
287
+ const f = Math.sqrt(p) / 3, u = -t / 3, _ = u - f, y = u + f;
288
+ let g = i, M = r;
289
+ if (_ > i && _ < e) {
290
+ const I = Bt(t, n, s, _);
291
+ l = rn(t, n, s, g, _, M, I, a, l), g = _, M = I;
292
292
  }
293
- if (u > o && u < e) {
294
- const A = Pt(t, n, s, u);
295
- a = Bt(t, n, s, x, u, g, A, p, a), x = u, g = A;
293
+ if (y > i && y < e) {
294
+ const I = Bt(t, n, s, y);
295
+ l = rn(t, n, s, g, y, M, I, a, l), g = y, M = I;
296
296
  }
297
- a = Bt(t, n, s, x, e, g, h, p, a);
297
+ l = rn(t, n, s, g, e, M, h, a, l);
298
298
  }
299
- return h === 0 && (p[a++] = e), a;
299
+ return h === 0 && (a[l++] = e), l;
300
300
  }
301
- const at = 0, et = 1, Gt = 2, Is = 4, Ao = 4, U = [0, 0, 0];
302
- class it {
301
+ const lt = 0, ct = 1, Gt = 2, $s = 4, Bo = 4, X = [0, 0, 0];
302
+ class et {
303
303
  /**
304
304
  * @param type Segment type (LINEAR=0, QUADRATIC=1, CUBIC=2).
305
305
  * @param p0x Start x.
@@ -311,15 +311,15 @@ class it {
311
311
  * @param p3x CUBIC: end x. Others: 0.
312
312
  * @param p3y CUBIC: end y. Others: 0.
313
313
  */
314
- constructor(t, n, s, o, e, p, c, r, h) {
315
- this.type = t, this.p0x = n, this.p0y = s, this.p1x = o, this.p1y = e, this.p2x = p, this.p2y = c, this.p3x = r, this.p3y = h, this.color = 7;
314
+ constructor(t, n, s, i, e, a, c, r, h) {
315
+ this.type = t, this.p0x = n, this.p0y = s, this.p1x = i, this.p1y = e, this.p2x = a, this.p2y = c, this.p3x = r, this.p3y = h, this.color = 7;
316
316
  }
317
317
  /** Endpoint x (the on-curve destination of this segment). */
318
318
  endX() {
319
319
  switch (this.type) {
320
- case at:
320
+ case lt:
321
321
  return this.p1x;
322
- case et:
322
+ case ct:
323
323
  return this.p2x;
324
324
  default:
325
325
  return this.p3x;
@@ -328,9 +328,9 @@ class it {
328
328
  /** Endpoint y. */
329
329
  endY() {
330
330
  switch (this.type) {
331
- case at:
331
+ case lt:
332
332
  return this.p1y;
333
- case et:
333
+ case ct:
334
334
  return this.p2y;
335
335
  default:
336
336
  return this.p3y;
@@ -346,18 +346,18 @@ class it {
346
346
  point(t, n) {
347
347
  const s = t;
348
348
  switch (this.type) {
349
- case at: {
349
+ case lt: {
350
350
  n[0] = this.p0x + s * (this.p1x - this.p0x), n[1] = this.p0y + s * (this.p1y - this.p0y);
351
351
  return;
352
352
  }
353
- case et: {
354
- const o = this.p0x + s * (this.p1x - this.p0x), e = this.p0y + s * (this.p1y - this.p0y), p = this.p1x + s * (this.p2x - this.p1x), c = this.p1y + s * (this.p2y - this.p1y);
355
- n[0] = o + s * (p - o), n[1] = e + s * (c - e);
353
+ case ct: {
354
+ const i = this.p0x + s * (this.p1x - this.p0x), e = this.p0y + s * (this.p1y - this.p0y), a = this.p1x + s * (this.p2x - this.p1x), c = this.p1y + s * (this.p2y - this.p1y);
355
+ n[0] = i + s * (a - i), n[1] = e + s * (c - e);
356
356
  return;
357
357
  }
358
358
  default: {
359
- const o = this.p0x + s * (this.p1x - this.p0x), e = 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 = o + s * (p - o), a = e + s * (c - e), f = p + s * (r - p), y = c + s * (h - c);
360
- n[0] = l + s * (f - l), n[1] = a + s * (y - a);
359
+ const i = this.p0x + s * (this.p1x - this.p0x), e = this.p0y + s * (this.p1y - this.p0y), a = 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), p = i + s * (a - i), l = e + s * (c - e), f = a + s * (r - a), u = c + s * (h - c);
360
+ n[0] = p + s * (f - p), n[1] = l + s * (u - l);
361
361
  return;
362
362
  }
363
363
  }
@@ -372,18 +372,18 @@ class it {
372
372
  direction(t, n) {
373
373
  const s = t;
374
374
  switch (this.type) {
375
- case at: {
375
+ case lt: {
376
376
  n[0] = this.p1x - this.p0x, n[1] = this.p1y - this.p0y;
377
377
  return;
378
378
  }
379
- case et: {
380
- const o = this.p1x - this.p0x + s * (this.p2x - this.p1x - (this.p1x - this.p0x)), e = this.p1y - this.p0y + s * (this.p2y - this.p1y - (this.p1y - this.p0y));
381
- o !== 0 || e !== 0 ? (n[0] = o, n[1] = e) : (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y);
379
+ case ct: {
380
+ const i = this.p1x - this.p0x + s * (this.p2x - this.p1x - (this.p1x - this.p0x)), e = this.p1y - this.p0y + s * (this.p2y - this.p1y - (this.p1y - this.p0y));
381
+ i !== 0 || e !== 0 ? (n[0] = i, n[1] = e) : (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y);
382
382
  return;
383
383
  }
384
384
  default: {
385
- const o = this.p1x - this.p0x, e = 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 = o + s * (p - o) + s * (p + s * (r - p) - (o + s * (p - o))), a = e + s * (c - e) + s * (c + s * (h - c) - (e + s * (c - e)));
386
- l !== 0 || a !== 0 ? (n[0] = l, n[1] = a) : s === 0 ? (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y) : s === 1 ? (n[0] = this.p3x - this.p1x, n[1] = this.p3y - this.p1y) : (n[0] = l, n[1] = a);
385
+ const i = this.p1x - this.p0x, e = this.p1y - this.p0y, a = this.p2x - this.p1x, c = this.p2y - this.p1y, r = this.p3x - this.p2x, h = this.p3y - this.p2y, p = i + s * (a - i) + s * (a + s * (r - a) - (i + s * (a - i))), l = e + s * (c - e) + s * (c + s * (h - c) - (e + s * (c - e)));
386
+ p !== 0 || l !== 0 ? (n[0] = p, n[1] = l) : s === 0 ? (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y) : s === 1 ? (n[0] = this.p3x - this.p1x, n[1] = this.p3y - this.p1y) : (n[0] = p, n[1] = l);
387
387
  return;
388
388
  }
389
389
  }
@@ -398,80 +398,80 @@ class it {
398
398
  splitInThirds() {
399
399
  const t = [0, 0], n = [0, 0];
400
400
  switch (this.type) {
401
- case at: {
401
+ case lt: {
402
402
  this.point(1 / 3, t), this.point(2 / 3, n);
403
- const s = new it(at, this.p0x, this.p0y, t[0], t[1], 0, 0, 0, 0), o = new it(at, t[0], t[1], n[0], n[1], 0, 0, 0, 0), e = new it(at, n[0], n[1], this.p1x, this.p1y, 0, 0, 0, 0);
404
- return s.color = o.color = e.color = this.color, [s, o, e];
403
+ const s = new et(lt, this.p0x, this.p0y, t[0], t[1], 0, 0, 0, 0), i = new et(lt, t[0], t[1], n[0], n[1], 0, 0, 0, 0), e = new et(lt, n[0], n[1], this.p1x, this.p1y, 0, 0, 0, 0);
404
+ return s.color = i.color = e.color = this.color, [s, i, e];
405
405
  }
406
- case et: {
406
+ case ct: {
407
407
  this.point(1 / 3, t), this.point(2 / 3, n);
408
- const s = this.p0x + 1 / 3 * (this.p1x - this.p0x), o = this.p0y + 1 / 3 * (this.p1y - this.p0y), e = 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 = e + 0.5 * (c - e), 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 it(
409
- et,
408
+ const s = this.p0x + 1 / 3 * (this.p1x - this.p0x), i = this.p0y + 1 / 3 * (this.p1y - this.p0y), e = this.p0x + 5 / 9 * (this.p1x - this.p0x), a = 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 = e + 0.5 * (c - e), p = a + 0.5 * (r - a), l = this.p1x + 2 / 3 * (this.p2x - this.p1x), f = this.p1y + 2 / 3 * (this.p2y - this.p1y), u = new et(
409
+ ct,
410
410
  this.p0x,
411
411
  this.p0y,
412
412
  s,
413
- o,
413
+ i,
414
414
  t[0],
415
415
  t[1],
416
416
  0,
417
417
  0
418
- ), _ = new it(
419
- et,
418
+ ), _ = new et(
419
+ ct,
420
420
  t[0],
421
421
  t[1],
422
422
  h,
423
- l,
423
+ p,
424
424
  n[0],
425
425
  n[1],
426
426
  0,
427
427
  0
428
- ), u = new it(
429
- et,
428
+ ), y = new et(
429
+ ct,
430
430
  n[0],
431
431
  n[1],
432
- a,
432
+ l,
433
433
  f,
434
434
  this.p2x,
435
435
  this.p2y,
436
436
  0,
437
437
  0
438
438
  );
439
- return y.color = _.color = u.color = this.color, [y, _, u];
439
+ return u.color = _.color = y.color = this.color, [u, _, y];
440
440
  }
441
441
  default: {
442
442
  this.point(1 / 3, t), this.point(2 / 3, n);
443
- const s = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0x : this.p0x + 1 / 3 * (this.p1x - this.p0x), o = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0y : this.p0y + 1 / 3 * (this.p1y - this.p0y), e = 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 = e + 1 / 3 * (c - e), 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), g = this.p0x + 2 / 3 * (this.p1x - this.p0x), A = this.p0y + 2 / 3 * (this.p1y - this.p0y), m = this.p1x + 2 / 3 * (this.p2x - this.p1x), v = this.p1y + 2 / 3 * (this.p2y - this.p1y), w = this.p2x + 2 / 3 * (this.p3x - this.p2x), E = this.p2y + 2 / 3 * (this.p3y - this.p2y), C = g + 2 / 3 * (m - g), F = A + 2 / 3 * (v - A), R = m + 2 / 3 * (w - m), b = v + 2 / 3 * (E - v), N = C + 1 / 3 * (R - C), I = F + 1 / 3 * (b - F), q = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3x : this.p2x + 2 / 3 * (this.p3x - this.p2x), O = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3y : this.p2y + 2 / 3 * (this.p3y - this.p2y), X = new it(
443
+ 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), e = this.p0x + 1 / 3 * (this.p1x - this.p0x), a = 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), p = this.p2y + 1 / 3 * (this.p3y - this.p2y), l = e + 1 / 3 * (c - e), f = a + 1 / 3 * (r - a), u = c + 1 / 3 * (h - c), _ = r + 1 / 3 * (p - r), y = l + 2 / 3 * (u - l), g = f + 2 / 3 * (_ - f), M = this.p0x + 2 / 3 * (this.p1x - this.p0x), I = this.p0y + 2 / 3 * (this.p1y - this.p0y), q = this.p1x + 2 / 3 * (this.p2x - this.p1x), T = 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), R = M + 2 / 3 * (q - M), m = I + 2 / 3 * (T - I), d = q + 2 / 3 * (A - q), x = T + 2 / 3 * (D - T), C = R + 1 / 3 * (d - R), v = m + 1 / 3 * (x - m), E = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3x : this.p2x + 2 / 3 * (this.p3x - this.p2x), k = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3y : this.p2y + 2 / 3 * (this.p3y - this.p2y), S = new et(
444
444
  Gt,
445
445
  this.p0x,
446
446
  this.p0y,
447
447
  s,
448
- o,
449
- a,
448
+ i,
449
+ l,
450
450
  f,
451
451
  t[0],
452
452
  t[1]
453
- ), K = new it(
453
+ ), H = new et(
454
454
  Gt,
455
455
  t[0],
456
456
  t[1],
457
- u,
458
- x,
459
- N,
460
- I,
457
+ y,
458
+ g,
459
+ C,
460
+ v,
461
461
  n[0],
462
462
  n[1]
463
- ), V = new it(
463
+ ), Y = new et(
464
464
  Gt,
465
465
  n[0],
466
466
  n[1],
467
- R,
468
- b,
469
- q,
470
- O,
467
+ d,
468
+ x,
469
+ E,
470
+ k,
471
471
  this.p3x,
472
472
  this.p3y
473
473
  );
474
- return X.color = K.color = V.color = this.color, [X, K, V];
474
+ return S.color = H.color = Y.color = this.color, [S, H, Y];
475
475
  }
476
476
  }
477
477
  }
@@ -490,93 +490,93 @@ class it {
490
490
  */
491
491
  signedDistance(t, n, s) {
492
492
  switch (this.type) {
493
- case at: {
494
- const o = this.p0x, e = this.p0y, p = this.p1x, c = this.p1y, r = t - o, h = n - e, l = p - o, a = c - e, f = l * l + a * a, y = (r * l + h * a) / f, _ = y > 0.5, u = (_ ? p : o) - t, x = (_ ? c : e) - n, g = Math.sqrt(u * u + x * x);
495
- if (y > 0 && y < 1) {
496
- const v = Math.sqrt(l * l + a * a), w = l / v, C = a / v * r - w * h;
497
- if (Math.abs(C) < g) {
498
- s.distance = C, s.dot = 0, s.param = y;
493
+ case lt: {
494
+ const i = this.p0x, e = this.p0y, a = this.p1x, c = this.p1y, r = t - i, h = n - e, p = a - i, l = c - e, f = p * p + l * l, u = (r * p + h * l) / f, _ = u > 0.5, y = (_ ? a : i) - t, g = (_ ? c : e) - n, M = Math.sqrt(y * y + g * g);
495
+ if (u > 0 && u < 1) {
496
+ const T = Math.sqrt(p * p + l * l), A = p / T, R = l / T * r - A * h;
497
+ if (Math.abs(R) < M) {
498
+ s.distance = R, s.dot = 0, s.param = u;
499
499
  return;
500
500
  }
501
501
  }
502
- const A = r * a - h * l;
503
- s.distance = Et(A) * g;
504
- const m = Math.sqrt(l * l + a * a);
505
- s.dot = g === 0 || m === 0 ? 0 : Math.abs((l * u + a * x) / (m * g)), s.param = y;
502
+ const I = r * l - h * p;
503
+ s.distance = qt(I) * M;
504
+ const q = Math.sqrt(p * p + l * l);
505
+ s.dot = M === 0 || q === 0 ? 0 : Math.abs((p * y + l * g) / (q * M)), s.param = u;
506
506
  return;
507
507
  }
508
- case et: {
509
- const o = this.p0x, e = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, l = o - t, a = e - n, f = p - o, y = c - e, _ = r - p - f, u = h - c - y, x = _ * _ + u * u, g = 3 * (f * _ + y * u), A = 2 * (f * f + y * y) + (l * _ + a * u), m = l * f + a * y, v = wo(x, g, A, m, 0, 1, U);
510
- let w = f, E = y;
511
- const C = l * l + a * a;
512
- let F = Et(w * a - E * l), R = C, b = -(l * w + a * E) / (w * w + E * E);
508
+ case ct: {
509
+ const i = this.p0x, e = this.p0y, a = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, p = i - t, l = e - n, f = a - i, u = c - e, _ = r - a - f, y = h - c - u, g = _ * _ + y * y, M = 3 * (f * _ + u * y), I = 2 * (f * f + u * u) + (p * _ + l * y), q = p * f + l * u, T = Vo(g, M, I, q, 0, 1, X);
510
+ let A = f, D = u;
511
+ const R = p * p + l * l;
512
+ let m = qt(A * l - D * p), d = R, x = -(p * A + l * D) / (A * A + D * D);
513
513
  {
514
- const I = r - t, q = h - n, O = I * I + q * q;
515
- O < R && (w = r - p, E = h - c, F = Et(w * q - E * I), R = O, b = ((t - p) * w + (n - c) * E) / (w * w + E * E));
514
+ const v = r - t, E = h - n, k = v * v + E * E;
515
+ k < d && (A = r - a, D = h - c, m = qt(A * E - D * v), d = k, x = ((t - a) * A + (n - c) * D) / (A * A + D * D));
516
516
  }
517
- for (let I = 0; I < v; ++I) {
518
- const q = U[I];
519
- if (q > 0 && q < 1) {
520
- const O = l + 2 * q * f + q * q * _, X = a + 2 * q * y + q * q * u, K = O * O + X * X;
521
- if (K <= R) {
522
- const V = f + q * _, nt = y + q * u;
523
- F = Et(V * X - nt * O), R = K, b = q;
517
+ for (let v = 0; v < T; ++v) {
518
+ const E = X[v];
519
+ if (E > 0 && E < 1) {
520
+ const k = p + 2 * E * f + E * E * _, S = l + 2 * E * u + E * E * y, H = k * k + S * S;
521
+ if (H <= d) {
522
+ const Y = f + E * _, tt = u + E * y;
523
+ m = qt(Y * S - tt * k), d = H, x = E;
524
524
  }
525
525
  }
526
526
  }
527
- const N = F * Math.sqrt(R);
528
- if (b >= 0 && b <= 1) {
529
- s.distance = N, s.dot = 0, s.param = b;
527
+ const C = m * Math.sqrt(d);
528
+ if (x >= 0 && x <= 1) {
529
+ s.distance = C, s.dot = 0, s.param = x;
530
530
  return;
531
531
  }
532
- if (s.distance = N, s.param = b, b < 0.5) {
533
- const I = Math.sqrt(f * f + y * y), q = Math.sqrt(C);
534
- s.dot = q === 0 || I === 0 ? 0 : Math.abs((f * l + y * a) / (I * q));
532
+ if (s.distance = C, s.param = x, x < 0.5) {
533
+ const v = Math.sqrt(f * f + u * u), E = Math.sqrt(R);
534
+ s.dot = E === 0 || v === 0 ? 0 : Math.abs((f * p + u * l) / (v * E));
535
535
  } else {
536
- const I = r - p, q = h - c, O = r - t, X = h - n, K = Math.sqrt(I * I + q * q), V = Math.sqrt(O * O + X * X);
537
- s.dot = K === 0 || V === 0 ? 0 : Math.abs((I * O + q * X) / (K * V));
536
+ const v = r - a, E = h - c, k = r - t, S = h - n, H = Math.sqrt(v * v + E * E), Y = Math.sqrt(k * k + S * S);
537
+ s.dot = H === 0 || Y === 0 ? 0 : Math.abs((v * k + E * S) / (H * Y));
538
538
  }
539
539
  return;
540
540
  }
541
541
  default: {
542
- const o = this.p0x, e = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, l = this.p3x, a = this.p3y, f = o - t, y = e - n, _ = p - o, u = c - e, x = r - p - _, g = h - c - u, A = l - r - (r - p) - x, m = a - h - (h - c) - g;
543
- let v = _, w = u;
544
- v === 0 && w === 0 && (v = r - o, w = h - e);
545
- const E = Math.sqrt(f * f + y * y);
546
- let C = Et(v * y - w * f) * E, F = -(f * v + y * w) / (v * v + w * w);
542
+ const i = this.p0x, e = this.p0y, a = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, p = this.p3x, l = this.p3y, f = i - t, u = e - n, _ = a - i, y = c - e, g = r - a - _, M = h - c - y, I = p - r - (r - a) - g, q = l - h - (h - c) - M;
543
+ let T = _, A = y;
544
+ T === 0 && A === 0 && (T = r - i, A = h - e);
545
+ const D = Math.sqrt(f * f + u * u);
546
+ let R = qt(T * u - A * f) * D, m = -(f * T + u * A) / (T * T + A * A);
547
547
  {
548
- const R = l - t, b = a - n, N = Math.sqrt(R * R + b * b);
549
- if (N < Math.abs(C)) {
550
- let I = l - r, q = a - h;
551
- I === 0 && q === 0 && (I = l - p, q = a - c), v = I, w = q, C = Et(v * b - w * R) * N, F = ((v - R) * v + (w - b) * w) / (v * v + w * w);
548
+ const d = p - t, x = l - n, C = Math.sqrt(d * d + x * x);
549
+ if (C < Math.abs(R)) {
550
+ let v = p - r, E = l - h;
551
+ v === 0 && E === 0 && (v = p - a, E = l - c), T = v, A = E, R = qt(T * x - A * d) * C, m = ((T - d) * T + (A - x) * A) / (T * T + A * A);
552
552
  }
553
553
  }
554
- for (let R = 0; R <= Is; ++R) {
555
- let b = 1 / Is * R, N = f + 3 * b * _ + 3 * b * b * x + b * b * b * A, I = y + 3 * b * u + 3 * b * b * g + b * b * b * m, q = 3 * _ + 6 * b * x + 3 * b * b * A, O = 3 * u + 6 * b * g + 3 * b * b * m, X = 6 * x + 6 * b * A, K = 6 * g + 6 * b * m, V = b - (N * q + I * O) / (q * q + O * O + (N * X + I * K));
556
- if (V > 0 && V < 1) {
557
- let nt = Ao;
554
+ for (let d = 0; d <= $s; ++d) {
555
+ let x = 1 / $s * d, C = f + 3 * x * _ + 3 * x * x * g + x * x * x * I, v = u + 3 * x * y + 3 * x * x * M + x * x * x * q, E = 3 * _ + 6 * x * g + 3 * x * x * I, k = 3 * y + 6 * x * M + 3 * x * x * q, S = 6 * g + 6 * x * I, H = 6 * M + 6 * x * q, Y = x - (C * E + v * k) / (E * E + k * k + (C * S + v * H));
556
+ if (Y > 0 && Y < 1) {
557
+ let tt = Bo;
558
558
  do {
559
- if (b = V, N = f + 3 * b * _ + 3 * b * b * x + b * b * b * A, I = y + 3 * b * u + 3 * b * b * g + b * b * b * m, q = 3 * _ + 6 * b * x + 3 * b * b * A, O = 3 * u + 6 * b * g + 3 * b * b * m, !--nt) break;
560
- X = 6 * x + 6 * b * A, K = 6 * g + 6 * b * m, V = b - (N * q + I * O) / (q * q + O * O + (N * X + I * K));
561
- } while (V > 0 && V < 1);
562
- const H = Math.sqrt(N * N + I * I);
563
- H < Math.abs(C) && (C = Et(q * I - O * N) * H, F = b);
559
+ if (x = Y, C = f + 3 * x * _ + 3 * x * x * g + x * x * x * I, v = u + 3 * x * y + 3 * x * x * M + x * x * x * q, E = 3 * _ + 6 * x * g + 3 * x * x * I, k = 3 * y + 6 * x * M + 3 * x * x * q, !--tt) break;
560
+ S = 6 * g + 6 * x * I, H = 6 * M + 6 * x * q, Y = x - (C * E + v * k) / (E * E + k * k + (C * S + v * H));
561
+ } while (Y > 0 && Y < 1);
562
+ const V = Math.sqrt(C * C + v * v);
563
+ V < Math.abs(R) && (R = qt(E * v - k * C) * V, m = x);
564
564
  }
565
565
  }
566
- if (F >= 0 && F <= 1) {
567
- s.distance = C, s.dot = 0, s.param = F;
566
+ if (m >= 0 && m <= 1) {
567
+ s.distance = R, s.dot = 0, s.param = m;
568
568
  return;
569
569
  }
570
- if (s.distance = C, s.param = F, F < 0.5) {
571
- let R = _, b = u;
572
- R === 0 && b === 0 && (R = r - o, b = h - e);
573
- const N = Math.sqrt(R * R + b * b);
574
- s.dot = E === 0 || N === 0 ? 0 : Math.abs((R * f + b * y) / (N * E));
570
+ if (s.distance = R, s.param = m, m < 0.5) {
571
+ let d = _, x = y;
572
+ d === 0 && x === 0 && (d = r - i, x = h - e);
573
+ const C = Math.sqrt(d * d + x * x);
574
+ s.dot = D === 0 || C === 0 ? 0 : Math.abs((d * f + x * u) / (C * D));
575
575
  } else {
576
- let R = l - r, b = a - h;
577
- R === 0 && b === 0 && (R = l - p, b = a - c);
578
- const N = l - t, I = a - n, q = Math.sqrt(R * R + b * b), O = Math.sqrt(N * N + I * I);
579
- s.dot = q === 0 || O === 0 ? 0 : Math.abs((R * N + b * I) / (q * O));
576
+ let d = p - r, x = l - h;
577
+ d === 0 && x === 0 && (d = p - a, x = l - c);
578
+ const C = p - t, v = l - n, E = Math.sqrt(d * d + x * x), k = Math.sqrt(C * C + v * v);
579
+ s.dot = E === 0 || k === 0 ? 0 : Math.abs((d * C + x * v) / (E * k));
580
580
  }
581
581
  return;
582
582
  }
@@ -595,56 +595,56 @@ class it {
595
595
  */
596
596
  scanlineIntersections(t, n, s) {
597
597
  switch (this.type) {
598
- case at: {
599
- const o = this.p0y, e = this.p1y;
600
- if (t >= o && t < e || t >= e && t < o) {
601
- const p = (t - o) / (e - o);
602
- return n[0] = uo(this.p0x, this.p1x, p), s[0] = rt(e - o), 1;
598
+ case lt: {
599
+ const i = this.p0y, e = this.p1y;
600
+ if (t >= i && t < e || t >= e && t < i) {
601
+ const a = (t - i) / (e - i);
602
+ return n[0] = Go(this.p0x, this.p1x, a), s[0] = pt(e - i), 1;
603
603
  }
604
604
  return 0;
605
605
  }
606
- case et: {
607
- const o = this.p0x, e = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y;
608
- let l = 0, a = t > e ? 1 : -1;
609
- n[l] = o, e === t && (e < c || e === c && e < h ? s[l++] = 1 : a = 1);
606
+ case ct: {
607
+ const i = this.p0x, e = this.p0y, a = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y;
608
+ let p = 0, l = t > e ? 1 : -1;
609
+ n[p] = i, e === t && (e < c || e === c && e < h ? s[p++] = 1 : l = 1);
610
610
  {
611
- const f = p - o, y = c - e, _ = r - p - f, u = h - c - y, x = $s(U, u, 2 * y, e - t);
612
- if (x >= 2 && U[0] > U[1]) {
613
- const g = U[0];
614
- U[0] = U[1], U[1] = g;
611
+ const f = a - i, u = c - e, _ = r - a - f, y = h - c - u, g = bo(X, y, 2 * u, e - t);
612
+ if (g >= 2 && X[0] > X[1]) {
613
+ const M = X[0];
614
+ X[0] = X[1], X[1] = M;
615
615
  }
616
- for (let g = 0; g < x && l < 2; ++g) {
617
- const A = U[g];
618
- A >= 0 && A <= 1 && (n[l] = o + 2 * A * f + A * A * _, a * (y + A * u) >= 0 && (s[l++] = a, a = -a));
616
+ for (let M = 0; M < g && p < 2; ++M) {
617
+ const I = X[M];
618
+ I >= 0 && I <= 1 && (n[p] = i + 2 * I * f + I * I * _, l * (u + I * y) >= 0 && (s[p++] = l, l = -l));
619
619
  }
620
620
  }
621
- return h === t && (a > 0 && l > 0 && (--l, a = -1), (h < c || h === c && h < e) && l < 2 && (n[l] = r, a < 0 && (s[l++] = -1, a = 1))), a !== (t >= h ? 1 : -1) && (l > 0 ? --l : (Math.abs(h - t) < Math.abs(e - t) && (n[l] = r), s[l++] = a)), l;
621
+ return h === t && (l > 0 && p > 0 && (--p, l = -1), (h < c || h === c && h < e) && p < 2 && (n[p] = r, l < 0 && (s[p++] = -1, l = 1))), l !== (t >= h ? 1 : -1) && (p > 0 ? --p : (Math.abs(h - t) < Math.abs(e - t) && (n[p] = r), s[p++] = l)), p;
622
622
  }
623
623
  default: {
624
- const o = this.p0x, e = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, l = this.p3x, a = this.p3y;
625
- let f = 0, y = t > e ? 1 : -1;
626
- n[f] = o, e === t && (e < c || e === c && (e < h || e === h && e < a) ? s[f++] = 1 : y = 1);
624
+ const i = this.p0x, e = this.p0y, a = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, p = this.p3x, l = this.p3y;
625
+ let f = 0, u = t > e ? 1 : -1;
626
+ n[f] = i, e === t && (e < c || e === c && (e < h || e === h && e < l) ? s[f++] = 1 : u = 1);
627
627
  {
628
- const _ = l - 3 * r + 3 * p - o, u = a - 3 * h + 3 * c - e, x = 3 * r - 6 * p + 3 * o, g = 3 * h - 6 * c + 3 * e, A = 3 * p - 3 * o, m = 3 * c - 3 * e, v = xo(U, u, g, m, e - t);
629
- if (v >= 2) {
630
- if (U[0] > U[1]) {
631
- const w = U[0];
632
- U[0] = U[1], U[1] = w;
628
+ const _ = p - 3 * r + 3 * a - i, y = l - 3 * h + 3 * c - e, g = 3 * r - 6 * a + 3 * i, M = 3 * h - 6 * c + 3 * e, I = 3 * a - 3 * i, q = 3 * c - 3 * e, T = Yo(X, y, M, q, e - t);
629
+ if (T >= 2) {
630
+ if (X[0] > X[1]) {
631
+ const A = X[0];
632
+ X[0] = X[1], X[1] = A;
633
633
  }
634
- if (v >= 3 && U[1] > U[2]) {
635
- const w = U[1];
636
- if (U[1] = U[2], U[2] = w, U[0] > U[1]) {
637
- const E = U[0];
638
- U[0] = U[1], U[1] = E;
634
+ if (T >= 3 && X[1] > X[2]) {
635
+ const A = X[1];
636
+ if (X[1] = X[2], X[2] = A, X[0] > X[1]) {
637
+ const D = X[0];
638
+ X[0] = X[1], X[1] = D;
639
639
  }
640
640
  }
641
641
  }
642
- for (let w = 0; w < v && f < 3; ++w) {
643
- const E = U[w];
644
- E >= 0 && E <= 1 && (n[f] = ((_ * E + x) * E + A) * E + o, y * ((3 * u * E + 2 * g) * E + m) >= 0 && (s[f++] = y, y = -y));
642
+ for (let A = 0; A < T && f < 3; ++A) {
643
+ const D = X[A];
644
+ D >= 0 && D <= 1 && (n[f] = ((_ * D + g) * D + I) * D + i, u * ((3 * y * D + 2 * M) * D + q) >= 0 && (s[f++] = u, u = -u));
645
645
  }
646
646
  }
647
- return a === t && (y > 0 && f > 0 && (--f, y = -1), (a < h || a === h && (a < c || a === c && a < e)) && f < 3 && (n[f] = l, y < 0 && (s[f++] = -1, y = 1))), y !== (t >= a ? 1 : -1) && (f > 0 ? --f : (Math.abs(a - t) < Math.abs(e - t) && (n[f] = l), s[f++] = y)), f;
647
+ return l === t && (u > 0 && f > 0 && (--f, u = -1), (l < h || l === h && (l < c || l === c && l < e)) && f < 3 && (n[f] = p, u < 0 && (s[f++] = -1, u = 1))), u !== (t >= l ? 1 : -1) && (f > 0 ? --f : (Math.abs(l - t) < Math.abs(e - t) && (n[f] = p), s[f++] = u)), f;
648
648
  }
649
649
  }
650
650
  }
@@ -656,92 +656,92 @@ class it {
656
656
  * @returns A new CUBIC EdgeSegment with identical geometry.
657
657
  */
658
658
  convertToCubic() {
659
- const t = this.p0x + 0.6666666666666666 * (this.p1x - this.p0x), n = this.p0y + 2 / 3 * (this.p1y - this.p0y), s = this.p1x + 1 / 3 * (this.p2x - this.p1x), o = this.p1y + 1 / 3 * (this.p2y - this.p1y), e = new it(
659
+ const t = this.p0x + 0.6666666666666666 * (this.p1x - this.p0x), n = 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), e = new et(
660
660
  Gt,
661
661
  this.p0x,
662
662
  this.p0y,
663
663
  t,
664
664
  n,
665
665
  s,
666
- o,
666
+ i,
667
667
  this.p2x,
668
668
  this.p2y
669
669
  );
670
670
  return e.color = this.color, e;
671
671
  }
672
672
  }
673
- const Eo = 1, Do = 2, qo = 4, mo = 8, Rs = 16, Ts = 32, vo = 1, ks = 2, Co = 8, Io = 32, Ro = 64, To = 128;
674
- function ko(i, t, n, s, o) {
675
- const e = Zs(i, t, n, s, o), p = [];
673
+ const Ko = 1, zo = 2, $o = 4, jo = 8, js = 16, Qs = 32, Qo = 1, Zs = 2, Zo = 8, Jo = 32, te = 64, ne = 128;
674
+ function se(o, t, n, s, i) {
675
+ const e = Ao(o, t, n, s, i), a = [];
676
676
  for (const c of e) {
677
- const r = Lo(c);
678
- r.length > 0 && p.push(r);
677
+ const r = ie(c);
678
+ r.length > 0 && a.push(r);
679
679
  }
680
- return { contours: p, inverseYAxis: !1 };
680
+ return { contours: a, inverseYAxis: !1 };
681
681
  }
682
- function Zs(i, t, n, s, o) {
682
+ function Ao(o, t, n, s, i) {
683
683
  if (s === 0) return [];
684
- const e = t + n, p = new Mt(i, e), c = p.i16();
685
- return p.skip(8), c >= 0 ? Fo(p, c) : Po(i, p, t, o);
684
+ const e = t + n, a = new wt(o, e), c = a.i16();
685
+ return a.skip(8), c >= 0 ? oe(a, c) : ce(o, a, t, i);
686
686
  }
687
- function Fo(i, t) {
687
+ function oe(o, t) {
688
688
  if (t === 0) return [];
689
- const n = new Array(t);
690
- for (let a = 0; a < t; a++) n[a] = i.u16();
691
- const s = (n[t - 1] ?? 0) + 1, o = i.u16();
692
- i.skip(o);
689
+ const n = [];
690
+ for (let l = 0; l < t; l++) n[l] = o.u16();
691
+ const s = (n[t - 1] ?? 0) + 1, i = o.u16();
692
+ o.skip(i);
693
693
  const e = new Uint8Array(s);
694
- for (let a = 0; a < s; ) {
695
- const f = i.u8();
696
- if (e[a++] = f, f & mo) {
697
- let y = i.u8();
698
- for (; y-- > 0; ) e[a++] = f;
694
+ for (let l = 0; l < s; ) {
695
+ const f = o.u8();
696
+ if (e[l++] = f, f & jo) {
697
+ let u = o.u8();
698
+ for (; u-- > 0; ) e[l++] = f;
699
699
  }
700
700
  }
701
- const p = new Float64Array(s);
701
+ const a = new Float64Array(s);
702
702
  let c = 0;
703
- for (let a = 0; a < s; a++) {
704
- const f = e[a] ?? 0;
705
- if (f & Do) {
706
- const y = i.u8();
707
- c += f & Rs ? y : -y;
708
- } else f & Rs || (c += i.i16());
709
- p[a] = c;
703
+ for (let l = 0; l < s; l++) {
704
+ const f = e[l] ?? 0;
705
+ if (f & zo) {
706
+ const u = o.u8();
707
+ c += f & js ? u : -u;
708
+ } else f & js || (c += o.i16());
709
+ a[l] = c;
710
710
  }
711
711
  const r = new Float64Array(s);
712
712
  c = 0;
713
- for (let a = 0; a < s; a++) {
714
- const f = e[a] ?? 0;
715
- if (f & qo) {
716
- const y = i.u8();
717
- c += f & Ts ? y : -y;
718
- } else f & Ts || (c += i.i16());
719
- r[a] = c;
713
+ for (let l = 0; l < s; l++) {
714
+ const f = e[l] ?? 0;
715
+ if (f & $o) {
716
+ const u = o.u8();
717
+ c += f & Qs ? u : -u;
718
+ } else f & Qs || (c += o.i16());
719
+ r[l] = c;
720
720
  }
721
721
  const h = [];
722
- let l = 0;
723
- for (let a = 0; a < t; a++) {
724
- const f = n[a] ?? 0, y = So(e, p, r, l, f);
725
- y.length > 0 && h.push(y), l = f + 1;
722
+ let p = 0;
723
+ for (let l = 0; l < t; l++) {
724
+ const f = n[l] ?? 0, u = ee(e, a, r, p, f);
725
+ u.length > 0 && h.push(u), p = f + 1;
726
726
  }
727
727
  return h;
728
728
  }
729
- function So(i, t, n, s, o) {
730
- const e = o - s + 1;
729
+ function ee(o, t, n, s, i) {
730
+ const e = i - s + 1;
731
731
  if (e <= 0) return [];
732
- const p = [];
732
+ const a = [];
733
733
  for (let c = 0; c < e; c++) {
734
- const r = i[s + c] ?? 0, h = t[s + c] ?? 0, l = n[s + c] ?? 0;
735
- p.push({ x: h, y: l, onCurve: (r & Eo) !== 0 });
734
+ const r = o[s + c] ?? 0, h = t[s + c] ?? 0, p = n[s + c] ?? 0;
735
+ a.push({ x: h, y: p, onCurve: (r & Ko) !== 0 });
736
736
  }
737
- return p;
737
+ return a;
738
738
  }
739
- function Lo(i) {
740
- const t = i.length;
739
+ function ie(o) {
740
+ const t = o.length;
741
741
  if (t <= 0) return [];
742
742
  const n = [];
743
743
  for (let c = 0; c < t; c++) {
744
- const r = i[c], h = i[(c + 1) % t];
744
+ const r = o[c], h = o[(c + 1) % t];
745
745
  n.push(r), !r.onCurve && !h.onCurve && n.push({
746
746
  x: Math.trunc((r.x + h.x) / 2),
747
747
  y: Math.trunc((r.y + h.y) / 2),
@@ -749,109 +749,109 @@ function Lo(i) {
749
749
  });
750
750
  }
751
751
  const s = n.length;
752
- let o = 0;
752
+ let i = 0;
753
753
  if (!n[0].onCurve) {
754
754
  for (let c = 1; c < s; c++)
755
755
  if (n[c].onCurve) {
756
- o = c;
756
+ i = c;
757
757
  break;
758
758
  }
759
759
  }
760
760
  const e = [];
761
- let p = 0;
762
- for (; p < s; ) {
763
- const c = n[(o + p) % s], r = n[(o + p + 1) % s];
761
+ let a = 0;
762
+ for (; a < s; ) {
763
+ const c = n[(i + a) % s], r = n[(i + a + 1) % s];
764
764
  if (r.onCurve)
765
- e.push(new it(at, c.x, c.y, r.x, r.y, 0, 0, 0, 0)), p += 1;
765
+ e.push(new et(lt, c.x, c.y, r.x, r.y, 0, 0, 0, 0)), a += 1;
766
766
  else {
767
- const h = n[(o + p + 2) % s];
768
- e.push(new it(et, c.x, c.y, r.x, r.y, h.x, h.y, 0, 0)), p += 2;
767
+ const h = n[(i + a + 2) % s];
768
+ e.push(new et(ct, c.x, c.y, r.x, r.y, h.x, h.y, 0, 0)), a += 2;
769
769
  }
770
770
  }
771
771
  return e;
772
772
  }
773
- function Po(i, t, n, s) {
774
- const o = [];
773
+ function ce(o, t, n, s) {
774
+ const i = [];
775
775
  let e = 0;
776
776
  do {
777
777
  e = t.u16();
778
- const p = t.u16();
778
+ const a = t.u16();
779
779
  let c, r;
780
- e & vo ? (c = t.i16(), r = t.i16()) : (c = t.u8(), r = t.u8(), e & ks && (c > 127 && (c -= 256), r > 127 && (r -= 256)));
781
- let h = 0, l = 0;
782
- e & ks && (h = c, l = r);
783
- let a = 1, f = 0, y = 0, _ = 1;
784
- e & Co ? a = _ = t.f2dot14() : e & Ro ? (a = t.f2dot14(), _ = t.f2dot14()) : e & To && (a = t.f2dot14(), f = t.f2dot14(), y = t.f2dot14(), _ = t.f2dot14());
785
- const u = s(p), x = Go(u, a, f, y, _, h, l);
786
- for (const g of x) o.push(g);
787
- } while (e & Io);
788
- return o;
789
- }
790
- function Fs(i) {
791
- return i >= 0 ? Math.floor(i + 0.5) : Math.ceil(i - 0.5);
792
- }
793
- function Go(i, t, n, s, o, e, p) {
794
- if (t === 1 && n === 0 && s === 0 && o === 1 && e === 0 && p === 0) return i;
795
- const r = t === 1 && n === 0 && s === 0 && o === 1;
796
- return i.map(
797
- (h) => h.map((l) => r ? { x: l.x + e, y: l.y + p, onCurve: l.onCurve } : {
798
- x: Fs(t * l.x + n * l.y + e),
799
- y: Fs(s * l.x + o * l.y + p),
800
- onCurve: l.onCurve
780
+ e & Qo ? (c = t.i16(), r = t.i16()) : (c = t.u8(), r = t.u8(), e & Zs && (c > 127 && (c -= 256), r > 127 && (r -= 256)));
781
+ let h = 0, p = 0;
782
+ e & Zs && (h = c, p = r);
783
+ let l = 1, f = 0, u = 0, _ = 1;
784
+ e & Zo ? l = _ = t.f2dot14() : e & te ? (l = t.f2dot14(), _ = t.f2dot14()) : e & ne && (l = t.f2dot14(), f = t.f2dot14(), u = t.f2dot14(), _ = t.f2dot14());
785
+ const y = s(a), g = re(y, l, f, u, _, h, p);
786
+ for (const M of g) i.push(M);
787
+ } while (e & Jo);
788
+ return i;
789
+ }
790
+ function Js(o) {
791
+ return o >= 0 ? Math.floor(o + 0.5) : Math.ceil(o - 0.5);
792
+ }
793
+ function re(o, t, n, s, i, e, a) {
794
+ if (t === 1 && n === 0 && s === 0 && i === 1 && e === 0 && a === 0) return o;
795
+ const r = t === 1 && n === 0 && s === 0 && i === 1;
796
+ return o.map(
797
+ (h) => h.map((p) => r ? { x: p.x + e, y: p.y + a, onCurve: p.onCurve } : {
798
+ x: Js(t * p.x + n * p.y + e),
799
+ y: Js(s * p.x + i * p.y + a),
800
+ onCurve: p.onCurve
801
801
  })
802
802
  );
803
803
  }
804
- function Oo(i, t) {
805
- const n = new Mt(i, t);
804
+ function ae(o, t) {
805
+ const n = new wt(o, t);
806
806
  if (n.u16() !== 0)
807
- return Ss;
808
- const o = n.u16(), e = /* @__PURE__ */ new Map();
809
- for (let p = 0; p < o; p++) {
807
+ return to;
808
+ const i = n.u16(), e = /* @__PURE__ */ new Map();
809
+ for (let a = 0; a < i; a++) {
810
810
  const c = n.pos;
811
811
  n.skip(2);
812
- const r = n.u16(), h = n.u16(), l = h >> 8 & 255, a = !(h & 2), f = !!(h & 4);
813
- if (l !== 0 || !a || f) {
812
+ const r = n.u16(), h = n.u16(), p = h >> 8 & 255, l = !(h & 2), f = !!(h & 4);
813
+ if (p !== 0 || !l || f) {
814
814
  n.seek(c + r);
815
815
  continue;
816
816
  }
817
- const y = n.u16();
817
+ const u = n.u16();
818
818
  n.skip(6);
819
- for (let _ = 0; _ < y; _++) {
820
- const u = n.u16(), x = n.u16(), g = n.i16(), A = (u & 65535) << 16 | x & 65535;
821
- e.set(A, g);
819
+ for (let _ = 0; _ < u; _++) {
820
+ const y = n.u16(), g = n.u16(), M = n.i16(), I = (y & 65535) << 16 | g & 65535;
821
+ e.set(I, M);
822
822
  }
823
823
  n.seek(c + r);
824
824
  }
825
- return e.size === 0 ? Ss : (p, c) => {
826
- const r = (p & 65535) << 16 | c & 65535;
825
+ return e.size === 0 ? to : (a, c) => {
826
+ const r = (a & 65535) << 16 | c & 65535;
827
827
  return e.get(r) ?? 0;
828
828
  };
829
829
  }
830
- const Ss = () => 0;
831
- function No(i) {
832
- const t = new Mt(i);
830
+ const to = () => 0;
831
+ function le(o) {
832
+ const t = new wt(o);
833
833
  if (t.u32() === 1953784678) {
834
834
  if (t.skip(4), t.u32() === 0) throw new Error("TTC contains no fonts");
835
- const o = t.u32();
836
- t.seek(o);
835
+ const i = t.u32();
836
+ t.seek(i);
837
837
  } else
838
838
  t.seek(0);
839
- return Uo(i, t);
839
+ return he(o, t);
840
840
  }
841
- function Uo(i, t) {
841
+ function he(o, t) {
842
842
  t.skip(4);
843
843
  const n = t.u16();
844
844
  t.skip(6);
845
845
  const s = /* @__PURE__ */ new Map();
846
- for (let o = 0; o < n; o++) {
846
+ for (let i = 0; i < n; i++) {
847
847
  const e = String.fromCharCode(t.u8(), t.u8(), t.u8(), t.u8());
848
848
  t.skip(4);
849
- const p = t.u32(), c = t.u32();
850
- s.set(e, { offset: p, length: c });
849
+ const a = t.u32(), c = t.u32();
850
+ s.set(e, { offset: a, length: c });
851
851
  }
852
852
  return s;
853
853
  }
854
- class Yo {
854
+ class pe {
855
855
  /**
856
856
  * Parses a TrueType font from an ArrayBuffer.
857
857
  *
@@ -862,19 +862,19 @@ class Yo {
862
862
  * @param buffer Raw font file bytes.
863
863
  */
864
864
  constructor(t) {
865
- this._buffer = t, this._tables = No(t);
866
- const n = this._tables.get("head"), s = this._tables.get("maxp"), o = this._tables.get("hhea"), e = this._tables.get("hmtx"), p = this._tables.get("loca"), c = this._tables.get("cmap");
865
+ this._buffer = t, this._tables = le(t);
866
+ const n = this._tables.get("head"), s = this._tables.get("maxp"), i = this._tables.get("hhea"), e = this._tables.get("hmtx"), a = this._tables.get("loca"), c = this._tables.get("cmap");
867
867
  if (!n) throw new Error("Font missing required `head` table");
868
868
  if (!s) throw new Error("Font missing required `maxp` table");
869
- if (!o) throw new Error("Font missing required `hhea` table");
869
+ if (!i) throw new Error("Font missing required `hhea` table");
870
870
  if (!e) throw new Error("Font missing required `hmtx` table");
871
- if (!p) throw new Error("Font missing required `loca` table");
871
+ if (!a) throw new Error("Font missing required `loca` table");
872
872
  if (!c) throw new Error("Font missing required `cmap` table");
873
- this._head = ao(t, n.offset);
874
- const r = fo(t, s.offset);
875
- this._hhea = ho(t, o.offset), this._hmtx = po(t, e.offset, r.numGlyphs, this._hhea.numberOfHMetrics), this._loca = lo(t, p.offset, r.numGlyphs, this._head.indexToLocFormat), this._cmap = io(t, c.offset);
873
+ this._head = To(t, n.offset);
874
+ const r = Oo(t, s.offset);
875
+ this._hhea = So(t, i.offset), this._hmtx = Lo(t, e.offset, r.numGlyphs, this._hhea.numberOfHMetrics), this._loca = Po(t, a.offset, r.numGlyphs, this._head.indexToLocFormat), this._cmap = Co(t, c.offset);
876
876
  const h = this._tables.get("kern");
877
- this._kern = h ? Oo(t, h.offset) : () => 0, this.metrics = {
877
+ this._kern = h ? ae(t, h.offset) : () => 0, this.metrics = {
878
878
  unitsPerEm: this._head.unitsPerEm,
879
879
  ascender: this._hhea.ascender,
880
880
  descender: this._hhea.descender,
@@ -942,12 +942,12 @@ class Yo {
942
942
  shape(t) {
943
943
  const n = this._tables.get("glyf");
944
944
  if (!n) return { contours: [], inverseYAxis: !1 };
945
- const s = this._loca, o = s[t] ?? 0, p = (s[t + 1] ?? o) - o;
946
- return ko(
945
+ const s = this._loca, i = s[t] ?? 0, a = (s[t + 1] ?? i) - i;
946
+ return se(
947
947
  this._buffer,
948
948
  n.offset,
949
- o,
950
- p,
949
+ i,
950
+ a,
951
951
  (c) => this._glyphRaw(c)
952
952
  );
953
953
  }
@@ -960,583 +960,820 @@ class Yo {
960
960
  _glyphRaw(t) {
961
961
  const n = this._tables.get("glyf");
962
962
  if (!n) return [];
963
- const s = this._loca, o = s[t] ?? 0, p = (s[t + 1] ?? o) - o;
964
- return Zs(
963
+ const s = this._loca, i = s[t] ?? 0, a = (s[t + 1] ?? i) - i;
964
+ return Ao(
965
965
  this._buffer,
966
966
  n.offset,
967
- o,
968
- p,
967
+ i,
968
+ a,
969
969
  (c) => this._glyphRaw(c)
970
970
  );
971
971
  }
972
972
  }
973
- function Xo(i, t) {
973
+ function fe(o, t) {
974
974
  const n = 1 / t;
975
- for (const s of i.contours)
976
- for (let o = 0; o < s.length; o++) {
977
- const e = s[o];
978
- if (e.p0x *= n, e.p0y *= n, e.p1x *= n, e.p1y *= n, e.p2x *= n, e.p2y *= n, e.p3x *= n, e.p3y *= n, e.type === et) {
979
- const p = e.p1x - e.p0x, c = e.p1y - e.p0y, r = e.p2x - e.p1x, h = e.p2y - e.p1y;
980
- J(p, c, r, h) === 0 && (s[o] = new it(at, e.p0x, e.p0y, e.p2x, e.p2y, 0, 0, 0, 0));
975
+ for (const s of o.contours)
976
+ for (let i = 0; i < s.length; i++) {
977
+ const e = s[i];
978
+ if (e.p0x *= n, e.p0y *= n, e.p1x *= n, e.p1y *= n, e.p2x *= n, e.p2y *= n, e.p3x *= n, e.p3y *= n, e.type === ct) {
979
+ const a = e.p1x - e.p0x, c = e.p1y - e.p0y, r = e.p2x - e.p1x, h = e.p2y - e.p1y;
980
+ z(a, c, r, h) === 0 && (s[i] = new et(lt, e.p0x, e.p0y, e.p2x, e.p2y, 0, 0, 0, 0));
981
+ } else if (e.type === Gt) {
982
+ const a = e.p2x - e.p1x, c = e.p2y - e.p1y, r = 1.5 * e.p1x - 0.5 * e.p0x, h = 1.5 * e.p1y - 0.5 * e.p0y;
983
+ z(e.p1x - e.p0x, e.p1y - e.p0y, a, c) === 0 && z(a, c, e.p3x - e.p2x, e.p3y - e.p2y) === 0 ? s[i] = new et(lt, e.p0x, e.p0y, e.p3x, e.p3y, 0, 0, 0, 0) : r === 1.5 * e.p2x - 0.5 * e.p3x && h === 1.5 * e.p2y - 0.5 * e.p3y && (s[i] = new et(ct, e.p0x, e.p0y, r, h, e.p3x, e.p3y, 0, 0));
981
984
  }
982
985
  }
983
986
  }
984
- const Ls = 1e-6, Wo = 1.1111111111111112, Ho = new Float64Array(16);
985
- function Ps(i, t, n) {
986
- switch (t[n] = i.p0x, t[n + 1] = i.p0y, t[n + 2] = i.p1x, t[n + 3] = i.p1y, i.type) {
987
- case at:
987
+ const no = 1e-6, ue = 1.1111111111111112, ye = new Float64Array(16);
988
+ function so(o, t, n) {
989
+ switch (t[n] = o.p0x, t[n + 1] = o.p0y, t[n + 2] = o.p1x, t[n + 3] = o.p1y, o.type) {
990
+ case lt:
988
991
  return 1;
989
- case et:
990
- return t[n + 4] = i.p2x, t[n + 5] = i.p2y, 2;
992
+ case ct:
993
+ return t[n + 4] = o.p2x, t[n + 5] = o.p2y, 2;
991
994
  default:
992
- return t[n + 4] = i.p2x, t[n + 5] = i.p2y, t[n + 6] = i.p3x, t[n + 7] = i.p3y, 3;
995
+ return t[n + 4] = o.p2x, t[n + 5] = o.p2y, t[n + 6] = o.p3x, t[n + 7] = o.p3y, 3;
993
996
  }
994
997
  }
995
- function Gs(i, t, n) {
998
+ function oo(o, t, n) {
996
999
  if (n === 3) {
997
- const s = i[t], o = i[t + 1], e = i[t + 2], p = i[t + 3], c = i[t + 4], r = i[t + 5], h = i[t + 6], l = i[t + 7];
998
- (e === s && p === o || e === h && p === l) && (c === s && r === o || c === h && r === l) && (i[t + 2] = h, i[t + 3] = l, n = 1);
1000
+ const s = o[t], i = o[t + 1], e = o[t + 2], a = o[t + 3], c = o[t + 4], r = o[t + 5], h = o[t + 6], p = o[t + 7];
1001
+ (e === s && a === i || e === h && a === p) && (c === s && r === i || c === h && r === p) && (o[t + 2] = h, o[t + 3] = p, n = 1);
999
1002
  }
1000
1003
  if (n === 2) {
1001
- const s = i[t], o = i[t + 1], e = i[t + 2], p = i[t + 3], c = i[t + 4], r = i[t + 5];
1002
- (e === s && p === o || e === c && p === r) && (i[t + 2] = c, i[t + 3] = r, n = 1);
1003
- }
1004
- return n === 1 && i[t] === i[t + 2] && i[t + 1] === i[t + 3] && (n = 0), n;
1005
- }
1006
- function Vo(i, t) {
1007
- const n = Ho;
1008
- let s = Ps(i, n, 0), o = Ps(t, n, 8);
1009
- if (!(s >= 1 && s <= 3 && o >= 1 && o <= 3) || n[s * 2] !== n[8] || n[s * 2 + 1] !== n[9]) return 0;
1010
- s = Gs(n, 0, s), o = Gs(n, 8, o);
1011
- const e = n[s * 2], p = n[s * 2 + 1];
1012
- let c = 0, r = 0, h = 0, l = 0, a = 0, f = 0, y = 0, _ = 0, u = 0, x = 0, g = 0, A = 0;
1013
- if (s >= 1 && (c = n[(s - 1) * 2] - e, r = n[(s - 1) * 2 + 1] - p), s >= 2) {
1014
- const H = n[(s - 2) * 2] - n[(s - 1) * 2], z = n[(s - 2) * 2 + 1] - n[(s - 1) * 2 + 1];
1015
- h = H - c, l = z - r;
1004
+ const s = o[t], i = o[t + 1], e = o[t + 2], a = o[t + 3], c = o[t + 4], r = o[t + 5];
1005
+ (e === s && a === i || e === c && a === r) && (o[t + 2] = c, o[t + 3] = r, n = 1);
1006
+ }
1007
+ return n === 1 && o[t] === o[t + 2] && o[t + 1] === o[t + 3] && (n = 0), n;
1008
+ }
1009
+ function _e(o, t) {
1010
+ const n = ye;
1011
+ let s = so(o, n, 0), i = so(t, n, 8);
1012
+ if (!(s >= 1 && s <= 3 && i >= 1 && i <= 3) || n[s * 2] !== n[8] || n[s * 2 + 1] !== n[9]) return 0;
1013
+ s = oo(n, 0, s), i = oo(n, 8, i);
1014
+ const e = n[s * 2], a = n[s * 2 + 1];
1015
+ let c = 0, r = 0, h = 0, p = 0, l = 0, f = 0, u = 0, _ = 0, y = 0, g = 0, M = 0, I = 0;
1016
+ if (s >= 1 && (c = n[(s - 1) * 2] - e, r = n[(s - 1) * 2 + 1] - a), s >= 2) {
1017
+ const V = n[(s - 2) * 2] - n[(s - 1) * 2], K = n[(s - 2) * 2 + 1] - n[(s - 1) * 2 + 1];
1018
+ h = V - c, p = K - r;
1016
1019
  }
1017
1020
  if (s >= 3) {
1018
- const H = n[(s - 3) * 2] - n[(s - 2) * 2], z = n[(s - 3) * 2 + 1] - n[(s - 2) * 2 + 1], ht = n[(s - 2) * 2] - n[(s - 1) * 2], st = n[(s - 2) * 2 + 1] - n[(s - 1) * 2 + 1];
1019
- a = H - ht - h, f = z - st - l, h *= 3, l *= 3;
1020
- }
1021
- if (o >= 1 && (y = n[10] - e, _ = n[11] - p), o >= 2) {
1022
- const H = n[12] - n[10], z = n[13] - n[11];
1023
- u = H - y, x = z - _;
1024
- }
1025
- if (o >= 3) {
1026
- const H = n[14] - n[12], z = n[15] - n[13], ht = n[12] - n[10], st = n[13] - n[11];
1027
- g = H - ht - u, A = z - st - x, u *= 3, x *= 3;
1028
- }
1029
- c *= s, r *= s, y *= o, _ *= o;
1030
- const m = c !== 0 || r !== 0;
1031
- if (m && (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, g, A) + 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, g, A) + z * J(a, f, u, x);
1037
- return rt(kt || J(a, f, g, A));
1038
- }
1039
- let w = 1, E = h, C = l, F = a, R = f, b = y, N = _, I = u, q = x, O = g, X = A;
1040
- if (m && (E = u, C = x, F = g, R = A, b = c, N = r, I = h, q = l, O = a, X = f, w = -1), b !== 0 || N !== 0) {
1041
- const H = J(F, R, b, N);
1042
- if (H) return w * rt(H);
1043
- const z = J(E, C, I, q);
1044
- if (z) return w * rt(z);
1045
- const ht = J(F, R, I, q);
1046
- if (ht) return w * rt(ht);
1047
- const st = J(E, C, O, X);
1048
- return st ? w * rt(st) : w * rt(J(F, R, O, X));
1049
- }
1050
- const K = Math.sqrt(E * E + C * C), V = Math.sqrt(I * I + q * q), nt = Math.sqrt(K) * J(E, C, O, X) + Math.sqrt(V) * J(F, R, I, q);
1051
- return rt(nt || J(F, R, O, X));
1052
- }
1053
- function Os(i, t, n, s, o) {
1054
- let e = i[t];
1055
- if (e.type === et) {
1056
- const p = e.convertToCubic();
1057
- i[t] = p, e = p;
1021
+ const V = n[(s - 3) * 2] - n[(s - 2) * 2], K = n[(s - 3) * 2 + 1] - n[(s - 2) * 2 + 1], nt = n[(s - 2) * 2] - n[(s - 1) * 2], st = n[(s - 2) * 2 + 1] - n[(s - 1) * 2 + 1];
1022
+ l = V - nt - h, f = K - st - p, h *= 3, p *= 3;
1023
+ }
1024
+ if (i >= 1 && (u = n[10] - e, _ = n[11] - a), i >= 2) {
1025
+ const V = n[12] - n[10], K = n[13] - n[11];
1026
+ y = V - u, g = K - _;
1027
+ }
1028
+ if (i >= 3) {
1029
+ const V = n[14] - n[12], K = n[15] - n[13], nt = n[12] - n[10], st = n[13] - n[11];
1030
+ M = V - nt - y, I = K - st - g, y *= 3, g *= 3;
1031
+ }
1032
+ c *= s, r *= s, u *= i, _ *= i;
1033
+ const q = c !== 0 || r !== 0;
1034
+ if (q && (u !== 0 || _ !== 0)) {
1035
+ const V = Math.sqrt(c * c + r * r), K = Math.sqrt(u * u + _ * _), nt = V * z(c, r, y, g) + K * z(h, p, u, _);
1036
+ if (nt) return pt(nt);
1037
+ const st = V * V * z(c, r, M, I) + V * K * z(h, p, y, g) + K * K * z(l, f, u, _);
1038
+ if (st) return pt(st);
1039
+ const Et = V * z(h, p, M, I) + K * z(l, f, y, g);
1040
+ return pt(Et || z(l, f, M, I));
1041
+ }
1042
+ let A = 1, D = h, R = p, m = l, d = f, x = u, C = _, v = y, E = g, k = M, S = I;
1043
+ if (q && (D = y, R = g, m = M, d = I, x = c, C = r, v = h, E = p, k = l, S = f, A = -1), x !== 0 || C !== 0) {
1044
+ const V = z(m, d, x, C);
1045
+ if (V) return A * pt(V);
1046
+ const K = z(D, R, v, E);
1047
+ if (K) return A * pt(K);
1048
+ const nt = z(m, d, v, E);
1049
+ if (nt) return A * pt(nt);
1050
+ const st = z(D, R, k, S);
1051
+ return st ? A * pt(st) : A * pt(z(m, d, k, S));
1052
+ }
1053
+ const H = Math.sqrt(D * D + R * R), Y = Math.sqrt(v * v + E * E), tt = Math.sqrt(H) * z(D, R, k, S) + Math.sqrt(Y) * z(m, d, v, E);
1054
+ return pt(tt || z(m, d, k, S));
1055
+ }
1056
+ function eo(o, t, n, s, i) {
1057
+ let e = o[t];
1058
+ if (e.type === ct) {
1059
+ const a = e.convertToCubic();
1060
+ o[t] = a, e = a;
1058
1061
  }
1059
1062
  if (e.type === Gt)
1060
1063
  if (n === 0) {
1061
- const p = Math.sqrt((e.p1x - e.p0x) ** 2 + (e.p1y - e.p0y) ** 2);
1062
- e.p1x += p * s, e.p1y += p * o;
1064
+ const a = Math.sqrt((e.p1x - e.p0x) ** 2 + (e.p1y - e.p0y) ** 2);
1065
+ e.p1x += a * s, e.p1y += a * i;
1063
1066
  } else {
1064
- const p = Math.sqrt((e.p2x - e.p3x) ** 2 + (e.p2y - e.p3y) ** 2);
1065
- e.p2x += p * s, e.p2y += p * o;
1067
+ const a = Math.sqrt((e.p2x - e.p3x) ** 2 + (e.p2y - e.p3y) ** 2);
1068
+ e.p2x += a * s, e.p2y += a * i;
1066
1069
  }
1067
1070
  }
1068
- const Ft = [0, 0], St = [0, 0];
1069
- function zo(i) {
1070
- for (let t = 0; t < i.contours.length; t++) {
1071
- const n = i.contours[t];
1071
+ const Xt = [0, 0], Wt = [0, 0];
1072
+ function xe(o) {
1073
+ for (let t = 0; t < o.contours.length; t++) {
1074
+ const n = o.contours[t];
1072
1075
  let s = 0;
1073
- for (let o = 0; o < n.length; o++) {
1074
- const e = n[o];
1076
+ for (let i = 0; i < n.length; i++) {
1077
+ const e = n[i];
1075
1078
  (e.p0x !== e.endX() || e.p0y !== e.endY()) && (n[s++] = e);
1076
1079
  }
1077
1080
  n.length = s;
1078
1081
  }
1079
- for (const t of i.contours)
1082
+ for (const t of o.contours)
1080
1083
  if (t.length === 1) {
1081
- const [n, s, o] = t[0].splitInThirds();
1082
- t.length = 0, t.push(n, s, o);
1084
+ const [n, s, i] = t[0].splitInThirds();
1085
+ t.length = 0, t.push(n, s, i);
1083
1086
  } else if (t.length > 0) {
1084
1087
  const n = t.length;
1085
1088
  for (let s = 0; s < n; s++) {
1086
- const o = (s + n - 1) % n, e = t[o], p = t[s];
1087
- e.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
+ const i = (s + n - 1) % n, e = t[i], a = t[s];
1090
+ e.direction(1, Xt), a.direction(0, Wt);
1091
+ const c = Math.sqrt(Xt[0] ** 2 + Xt[1] ** 2), r = Math.sqrt(Wt[0] ** 2 + Wt[1] ** 2);
1089
1092
  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 (yo(h, l, a, f) < Ls - 1) {
1092
- const y = Ls - 1, _ = Wo * Math.sqrt(1 - y * y) / y;
1093
- let u = a - h, x = f - l;
1094
- const g = Math.sqrt(u * u + x * x);
1095
- if (g === 0) continue;
1096
- u = _ * u / g, x = _ * x / g, Vo(e, p) < 0 && (u = -u, x = -x), Os(t, o, 1, -x, u), Os(t, s, 0, x, -u);
1093
+ const h = Xt[0] / c, p = Xt[1] / c, l = Wt[0] / r, f = Wt[1] / r;
1094
+ if (No(h, p, l, f) < no - 1) {
1095
+ const u = no - 1, _ = ue * Math.sqrt(1 - u * u) / u;
1096
+ let y = l - h, g = f - p;
1097
+ const M = Math.sqrt(y * y + g * g);
1098
+ if (M === 0) continue;
1099
+ y = _ * y / M, g = _ * g / M, _e(e, a) < 0 && (y = -y, g = -g), eo(t, i, 1, -g, y), eo(t, s, 0, g, -y);
1100
+ }
1101
+ }
1102
+ }
1103
+ }
1104
+ const io = 1e-5, ls = 1e-6, ge = 2e4, Me = 1e5;
1105
+ function de(o) {
1106
+ return [o.p0x, o.p0y, o.p1x, o.p1y, o.p2x, o.p2y, o.p3x, o.p3y].slice(0, 2 * o.type + 4);
1107
+ }
1108
+ function co(o) {
1109
+ const t = o.length / 2 - 2;
1110
+ return new et(
1111
+ t,
1112
+ o[0],
1113
+ o[1],
1114
+ o[2],
1115
+ o[3],
1116
+ o[4] ?? 0,
1117
+ o[5] ?? 0,
1118
+ o[6] ?? 0,
1119
+ o[7] ?? 0
1120
+ );
1121
+ }
1122
+ const ot = new Float64Array(8), it = new Float64Array(8), vt = new Float64Array(8);
1123
+ function hs(o, t, n, s) {
1124
+ const i = o.length, e = i / 2 - 1;
1125
+ for (let a = 0; a <= e; a++) {
1126
+ for (let c = 0; c < i; c++) vt[c] = o[c];
1127
+ for (let c = 0, r = i; c < e; c++, r -= 2) {
1128
+ const h = c < e - a ? t : n;
1129
+ for (let p = 0; p < r - 2; p++) vt[p] = vt[p] + h * (vt[p + 2] - vt[p]);
1130
+ }
1131
+ s[2 * a] = vt[0], s[2 * a + 1] = vt[1];
1132
+ }
1133
+ }
1134
+ function we(o, t, n) {
1135
+ return hs(o, t, n, ot), Array.from(ot.subarray(0, o.length));
1136
+ }
1137
+ let ps = 0, fs = 0, mt = -1, $t = -1, jt = 0, Qt = 0, un = 0, yn = 0;
1138
+ function be(o, t) {
1139
+ mt = -1, $t = -1;
1140
+ let n = 0;
1141
+ for (let p = 0; p < 2; p++) {
1142
+ const l = p ? o.length - 2 : 0;
1143
+ for (let f = 0; f < 2; f++) {
1144
+ const u = f ? t.length - 2 : 0;
1145
+ o[l] === t[u] && o[l + 1] === t[u + 1] && (n++, mt = p, $t = f);
1146
+ }
1147
+ }
1148
+ if (n !== 1) {
1149
+ mt = -1;
1150
+ return;
1151
+ }
1152
+ const s = mt ? o.length - 2 : 0;
1153
+ jt = o[s], Qt = o[s + 1];
1154
+ let i = 0, e = 0;
1155
+ for (let p = 2; p < o.length && i === 0 && e === 0; p += 2) {
1156
+ const l = mt ? o.length - 2 - p : p;
1157
+ i = o[l] - jt, e = o[l + 1] - Qt;
1158
+ }
1159
+ let a = 0, c = 0;
1160
+ for (let p = 2; p < t.length && a === 0 && c === 0; p += 2) {
1161
+ const l = $t ? t.length - 2 - p : p;
1162
+ a = t[l] - jt, c = t[l + 1] - Qt;
1163
+ }
1164
+ const r = Math.hypot(i, e), h = Math.hypot(a, c);
1165
+ un = i / r - a / h, yn = e / r - c / h, Math.hypot(un, yn) > 1e-9 || (mt = -1);
1166
+ }
1167
+ function Ae(o, t) {
1168
+ const n = mt ? o - 2 : 0;
1169
+ for (let i = 0; i < o; i += 2)
1170
+ if (i !== n && (ot[i] - jt) * un + (ot[i + 1] - Qt) * yn <= 0) return !1;
1171
+ const s = $t ? t - 2 : 0;
1172
+ for (let i = 0; i < t; i += 2)
1173
+ if (i !== s && (it[i] - jt) * un + (it[i + 1] - Qt) * yn >= 0) return !1;
1174
+ return !0;
1175
+ }
1176
+ function Kt(o, t, n, s, i, e, a) {
1177
+ if (--ps < 0 || --fs < 0) return;
1178
+ const c = o.length, r = s.length;
1179
+ hs(o, t, n, ot), hs(s, i, e, it);
1180
+ let h = 1 / 0, p = 1 / 0, l = -1 / 0, f = -1 / 0;
1181
+ for (let q = 0; q < c; q += 2)
1182
+ h = Math.min(h, ot[q]), p = Math.min(p, ot[q + 1]), l = Math.max(l, ot[q]), f = Math.max(f, ot[q + 1]);
1183
+ let u = 1 / 0, _ = 1 / 0, y = -1 / 0, g = -1 / 0;
1184
+ for (let q = 0; q < r; q += 2)
1185
+ u = Math.min(u, it[q]), _ = Math.min(_, it[q + 1]), y = Math.max(y, it[q]), g = Math.max(g, it[q + 1]);
1186
+ if (h > y || u > l || p > g || _ > f || mt >= 0 && (mt ? n === 1 : t === 0) && ($t ? e === 1 : i === 0) && Ae(c, r))
1187
+ return;
1188
+ const M = Math.max(l - h, f - p), I = Math.max(y - u, g - _);
1189
+ if (c === 4 && r === 4 || M < io && I < io) {
1190
+ const q = ot[c - 2] - ot[0], T = ot[c - 1] - ot[1], A = it[r - 2] - it[0], D = it[r - 1] - it[1], R = z(q, T, A, D), m = z(it[0] - ot[0], it[1] - ot[1], A, D) / R, d = z(it[0] - ot[0], it[1] - ot[1], q, T) / R;
1191
+ m >= 0 && m <= 1 && d >= 0 && d <= 1 && a.push(t + m * (n - t), i + d * (e - i));
1192
+ } else M > I ? (Kt(o, t, (t + n) / 2, s, i, e, a), Kt(o, (t + n) / 2, n, s, i, e, a)) : (Kt(o, t, n, s, i, (i + e) / 2, a), Kt(o, t, n, s, (i + e) / 2, e, a));
1193
+ }
1194
+ function an(o, t, n) {
1195
+ const s = o[2] - o[0], i = o[3] - o[1];
1196
+ return ((t - o[0]) * s + (n - o[1]) * i) / (s * s + i * i);
1197
+ }
1198
+ function me(o, t, n) {
1199
+ if (o.length !== 4 || t.length !== 4) return !1;
1200
+ const s = o[2] - o[0], i = o[3] - o[1], e = 1e-9 * Math.hypot(s, i);
1201
+ return Math.abs(z(s, i, t[0] - o[0], t[1] - o[1])) > e || Math.abs(z(s, i, t[2] - o[0], t[3] - o[1])) > e ? !1 : (n.push(an(o, t[0], t[1]), 0, an(o, t[2], t[3]), 1), n.push(0, an(t, o[0], o[1]), 1, an(t, o[2], o[3])), !0);
1202
+ }
1203
+ function Ee(o) {
1204
+ const t = [];
1205
+ for (let n = o.length - 2; n >= 0; n -= 2) t.push(o[n], o[n + 1]);
1206
+ return t;
1207
+ }
1208
+ function Ie(o, t) {
1209
+ if (o.length !== t.length) return !1;
1210
+ for (let n = 0; n < o.length; n++) if (!(Math.abs(o[n] - t[n]) < ls)) return !1;
1211
+ return !0;
1212
+ }
1213
+ const Ht = [0, 0], kt = [0, 0], _n = [0, 0, 0], xn = [0, 0, 0];
1214
+ let Ut = new Int32Array(8);
1215
+ const De = 0, qe = 1;
1216
+ function ro(o, t, n, s) {
1217
+ let i = 0;
1218
+ for (let e = 0; e < o.length; e++) {
1219
+ if (s < t[4 * e + 1] - 1e-9 || s > t[4 * e + 3] + 1e-9) continue;
1220
+ const a = o[e].scanlineIntersections(s, _n, xn);
1221
+ for (let c = 0; c < a; c++) _n[c] <= n && (i += xn[c]);
1222
+ }
1223
+ return i !== 0;
1224
+ }
1225
+ function ao(o, t, n, s, i, e, a) {
1226
+ Ut.fill(0, 0, n);
1227
+ for (let r = 0; r < o.length; r++) {
1228
+ if (a < i[4 * r + 1] - 1e-9 || a > i[4 * r + 3] + 1e-9) continue;
1229
+ const h = o[r].scanlineIntersections(a, _n, xn);
1230
+ for (let p = 0; p < h; p++) _n[p] <= e && (Ut[t[r]] += xn[p]);
1231
+ }
1232
+ let c = !1;
1233
+ for (let r = 1; r < n && !c; r++) c = Ut[r] !== 0;
1234
+ return Ut[0] !== 0 && (s === qe ? c : !c);
1235
+ }
1236
+ function ve(o) {
1237
+ const t = ke([o.contours]);
1238
+ t && (o.contours = t);
1239
+ }
1240
+ function ke(o, t = De) {
1241
+ const n = o.flat(), s = n.flat(), i = s.map(de), e = i.length, a = o.length, c = a > 1;
1242
+ Ut.length < a && (Ut = new Int32Array(a));
1243
+ const r = new Float64Array(4 * e), h = new Int32Array(e), p = new Int32Array(e);
1244
+ let l = 0;
1245
+ for (let m = 0; m < a; m++)
1246
+ for (const d of o[m]) {
1247
+ for (let x = 0; x < d.length; x++)
1248
+ h[l + x] = l + (x + 1) % d.length, p[l + x] = m;
1249
+ l += d.length;
1250
+ }
1251
+ for (let m = 0; m < e; m++) {
1252
+ const d = i[m];
1253
+ let x = 1 / 0, C = 1 / 0, v = -1 / 0, E = -1 / 0;
1254
+ for (let k = 0; k < d.length; k += 2)
1255
+ x = Math.min(x, d[k]), C = Math.min(C, d[k + 1]), v = Math.max(v, d[k]), E = Math.max(E, d[k + 1]);
1256
+ r[4 * m] = x, r[4 * m + 1] = C, r[4 * m + 2] = v, r[4 * m + 3] = E;
1257
+ }
1258
+ const f = Array.from({ length: e }, (m, d) => d).sort((m, d) => r[4 * m] - r[4 * d]), u = i.map(() => []), _ = new Uint8Array(e);
1259
+ fs = Me;
1260
+ for (let m = 0; m < e; m++) {
1261
+ const d = f[m];
1262
+ for (let x = m + 1; x < e; x++) {
1263
+ const C = f[x];
1264
+ if (r[4 * C] > r[4 * d + 2]) break;
1265
+ if (r[4 * d + 1] > r[4 * C + 3] || r[4 * C + 1] > r[4 * d + 3]) continue;
1266
+ const v = Math.min(d, C), E = Math.max(d, C);
1267
+ h[v] !== E && h[E] !== v && (_[v] = _[E] = 1);
1268
+ const k = [];
1269
+ if (ps = ge, me(i[v], i[E], k) || (be(i[v], i[E]), Kt(i[v], 0, 1, i[E], 0, 1, k)), ps < 0 || fs < 0) return null;
1270
+ for (let S = 0; S < k.length; S += 2)
1271
+ u[v].push(k[S]), u[E].push(k[S + 1]);
1272
+ }
1273
+ }
1274
+ const y = u.map((m) => {
1275
+ const d = [0];
1276
+ for (const x of m.sort((C, v) => C - v))
1277
+ x - d[d.length - 1] > 1e-7 && x < 1 - 1e-7 && d.push(x);
1278
+ return d.push(1), d;
1279
+ });
1280
+ let g = !1;
1281
+ const M = [], I = [];
1282
+ let q = 0;
1283
+ for (const m of n) {
1284
+ const d = q + m.length;
1285
+ let x = !0;
1286
+ for (let k = q; k < d; k++) (_[k] || y[k].length > 2) && (x = !1);
1287
+ let C = !1, v = !1, E = !1;
1288
+ for (let k = q; k < d; k++) {
1289
+ const S = y[k];
1290
+ for (let H = 1; H < S.length; H++) {
1291
+ const Y = we(i[k], S[H - 1], S[H]), tt = co(Y);
1292
+ tt.point(0.5, Ht), tt.direction(0.5, kt);
1293
+ const V = Math.hypot(kt[0], kt[1]), K = Math.hypot(Y[Y.length - 2] - Y[0], Y[Y.length - 1] - Y[1]);
1294
+ if (!(V === 0 || K === 0)) {
1295
+ if (!x || !C) {
1296
+ const nt = Math.min(1e-6, K * K / 64) / V, st = Ht[0] + kt[1] * nt, Et = Ht[1] - kt[0] * nt, Tt = Ht[0] - kt[1] * nt, St = Ht[1] + kt[0] * nt;
1297
+ v = c ? ao(s, p, a, t, r, st, Et) : ro(s, r, st, Et), E = c ? ao(s, p, a, t, r, Tt, St) : ro(s, r, Tt, St), C = !0;
1298
+ }
1299
+ v === E ? p[k] === 0 && (g = !0) : (M.push(Y), I.push(v), p[k] !== 0 && (g = !0));
1097
1300
  }
1098
1301
  }
1099
1302
  }
1303
+ q = d;
1304
+ }
1305
+ const T = 2 * I.filter(Boolean).length >= I.length, A = [];
1306
+ for (let m = 0; m < M.length; m++) {
1307
+ let d = M[m];
1308
+ I[m] !== T && (d = Ee(d), g = !0);
1309
+ let x = !1;
1310
+ for (let C = 0; C < A.length && !x; C++) x = Ie(A[C], d);
1311
+ x ? g = !0 : A.push(d);
1312
+ }
1313
+ if (!g) return null;
1314
+ const D = new Uint8Array(A.length), R = [];
1315
+ for (let m = 0; m < A.length; m++) {
1316
+ if (D[m]) continue;
1317
+ D[m] = 1;
1318
+ const d = [A[m]];
1319
+ for (; ; ) {
1320
+ const x = d[d.length - 1], C = x[x.length - 2], v = x[x.length - 1];
1321
+ if (d.length > 1 && Math.hypot(C - d[0][0], v - d[0][1]) < ls) {
1322
+ d[0][0] = C, d[0][1] = v;
1323
+ break;
1324
+ }
1325
+ let E = -1, k = ls;
1326
+ for (let S = 0; S < A.length; S++) {
1327
+ if (D[S]) continue;
1328
+ const H = Math.hypot(A[S][0] - C, A[S][1] - v);
1329
+ H < k && (E = S, k = H);
1330
+ }
1331
+ if (E < 0) return null;
1332
+ D[E] = 1, A[E][0] = C, A[E][1] = v, d.push(A[E]);
1333
+ }
1334
+ R.push(d.map(co));
1335
+ }
1336
+ return R;
1100
1337
  }
1101
- const Jt = 1, tn = 2, Bo = 3, nn = 4, Ko = 5, Qo = 6, Kn = 7, ot = [0, 0], Dt = [0, 0];
1102
- function $o(i, t) {
1103
- return Math.trunc(3 + 2.875 * i / (t - 1) - 1.4375 + 0.5) - 3;
1338
+ const Mn = 1, dn = 2, Ce = 3, wn = 4, Fe = 5, Re = 6, ys = 7, at = [0, 0], Ct = [0, 0];
1339
+ function Te(o, t) {
1340
+ return Math.trunc(3 + 2.875 * o / (t - 1) - 1.4375 + 0.5) - 3;
1104
1341
  }
1105
- function Zo(i, t, n, s, o) {
1106
- return i * n + t * s <= 0 || Math.abs(i * s - t * n) > o;
1342
+ function Se(o, t, n, s, i) {
1343
+ return o * n + t * s <= 0 || Math.abs(o * s - t * n) > i;
1107
1344
  }
1108
- function jo(i) {
1109
- const t = Number(i.v & 1n);
1110
- return i.v >>= 1n, t;
1345
+ function Le(o) {
1346
+ const t = Number(o.v & 1n);
1347
+ return o.v >>= 1n, t;
1111
1348
  }
1112
- function Jo(i) {
1113
- const t = Number(i.v % 3n);
1114
- return i.v /= 3n, t;
1349
+ function Pe(o) {
1350
+ const t = Number(o.v % 3n);
1351
+ return o.v /= 3n, t;
1115
1352
  }
1116
- function Ns(i) {
1117
- return [Qo, Ko, Bo][Jo(i)];
1353
+ function lo(o) {
1354
+ return [Re, Fe, Ce][Pe(o)];
1118
1355
  }
1119
- function Ot(i, t) {
1120
- const n = i.v << 1 + jo(t);
1121
- i.v = (n | n >> 3) & Kn;
1356
+ function zt(o, t) {
1357
+ const n = o.v << 1 + Le(t);
1358
+ o.v = (n | n >> 3) & ys;
1122
1359
  }
1123
- function te(i, t, n) {
1124
- const s = i.v & n;
1125
- s === Jt || s === tn || s === nn ? i.v = s ^ Kn : Ot(i, t);
1360
+ function Oe(o, t, n) {
1361
+ const s = o.v & n;
1362
+ s === Mn || s === dn || s === wn ? o.v = s ^ ys : zt(o, t);
1126
1363
  }
1127
- function ne(i, t, n = 0n) {
1128
- const s = Math.sin(t), o = { v: Ns({ v: n }) }, e = { v: n };
1129
- e.v = n, o.v = Ns(e);
1130
- const p = [];
1131
- for (const c of i.contours) {
1364
+ function Ne(o, t, n = 0n) {
1365
+ const s = Math.sin(t), i = { v: lo({ v: n }) }, e = { v: n };
1366
+ e.v = n, i.v = lo(e);
1367
+ const a = [];
1368
+ for (const c of o.contours) {
1132
1369
  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;
1370
+ a.length = 0, c[c.length - 1].direction(1, at);
1371
+ const h = Math.sqrt(at[0] * at[0] + at[1] * at[1]);
1372
+ let p = h > 0 ? at[0] / h : 0, l = h > 0 ? at[1] / h : 0;
1136
1373
  for (let f = 0; f < c.length; f++) {
1137
- const y = c[f];
1138
- y.direction(0, Dt);
1139
- const _ = Math.sqrt(Dt[0] * Dt[0] + Dt[1] * Dt[1]), u = _ > 0 ? Dt[0] / _ : 0, x = _ > 0 ? Dt[1] / _ : 0;
1140
- Zo(l, a, u, x, s) && p.push(f), y.direction(1, ot);
1141
- const g = Math.sqrt(ot[0] * ot[0] + ot[1] * ot[1]);
1142
- l = g > 0 ? ot[0] / g : 0, a = g > 0 ? ot[1] / g : 0;
1374
+ const u = c[f];
1375
+ u.direction(0, Ct);
1376
+ const _ = Math.sqrt(Ct[0] * Ct[0] + Ct[1] * Ct[1]), y = _ > 0 ? Ct[0] / _ : 0, g = _ > 0 ? Ct[1] / _ : 0;
1377
+ Se(p, l, y, g, s) && a.push(f), u.direction(1, at);
1378
+ const M = Math.sqrt(at[0] * at[0] + at[1] * at[1]);
1379
+ p = M > 0 ? at[0] / M : 0, l = M > 0 ? at[1] / M : 0;
1143
1380
  }
1144
- if (p.length === 0) {
1145
- Ot(o, e);
1146
- for (const f of c) f.color = o.v;
1147
- } else if (p.length === 1) {
1148
- const f = [0, Kn, 0];
1149
- Ot(o, e), f[0] = o.v, Ot(o, e), f[2] = o.v;
1150
- const y = p[0], _ = c.length;
1381
+ if (a.length === 0) {
1382
+ zt(i, e);
1383
+ for (const f of c) f.color = i.v;
1384
+ } else if (a.length === 1) {
1385
+ const f = [0, ys, 0];
1386
+ zt(i, e), f[0] = i.v, zt(i, e), f[2] = i.v;
1387
+ const u = a[0], _ = c.length;
1151
1388
  if (_ >= 3)
1152
- for (let u = 0; u < _; u++) {
1153
- const x = $o(u, _);
1154
- c[(y + u) % _].color = f[1 + x];
1389
+ for (let y = 0; y < _; y++) {
1390
+ const g = Te(y, _);
1391
+ c[(u + y) % _].color = f[1 + g];
1155
1392
  }
1156
1393
  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) {
1159
- const g = c[1].splitInThirds();
1160
- u[3 - 3 * y] = g[0], u[4 - 3 * y] = g[1], u[5 - 3 * y] = g[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];
1394
+ const y = [null, null, null, null, null, null, null], g = c[0].splitInThirds();
1395
+ if (y[0 + 3 * u] = g[0], y[1 + 3 * u] = g[1], y[2 + 3 * u] = g[2], _ >= 2) {
1396
+ const M = c[1].splitInThirds();
1397
+ y[3 - 3 * u] = M[0], y[4 - 3 * u] = M[1], y[5 - 3 * u] = M[2], y[0].color = y[1].color = f[0], y[2].color = y[3].color = f[1], y[4].color = y[5].color = f[2];
1161
1398
  } else
1162
- u[0].color = f[0], u[1].color = f[1], u[2].color = f[2];
1399
+ y[0].color = f[0], y[1].color = f[1], y[2].color = f[2];
1163
1400
  c.length = 0;
1164
- for (const g of u) g !== null && c.push(g);
1401
+ for (const M of y) M !== null && c.push(M);
1165
1402
  }
1166
1403
  } else {
1167
- const f = p.length;
1168
- let y = 0;
1169
- const _ = p[0], u = c.length;
1170
- Ot(o, e);
1171
- const x = o.v;
1172
- for (let g = 0; g < u; g++) {
1173
- const A = (_ + g) % u;
1174
- y + 1 < f && p[y + 1] === A && (++y, te(o, e, y === f - 1 ? x : 0)), c[A].color = o.v;
1404
+ const f = a.length;
1405
+ let u = 0;
1406
+ const _ = a[0], y = c.length;
1407
+ zt(i, e);
1408
+ const g = i.v;
1409
+ for (let M = 0; M < y; M++) {
1410
+ const I = (_ + M) % y;
1411
+ u + 1 < f && a[u + 1] === I && (++u, Oe(i, e, u === f - 1 ? g : 0)), c[I].color = i.v;
1175
1412
  }
1176
1413
  }
1177
1414
  }
1178
1415
  }
1179
- const Y = Number.MAX_VALUE, T = [0, 0], yt = [0, 0];
1180
- let Us = 0, B = new Float64Array(0), $ = new Float64Array(0), P = new Float64Array(0), G = new Float64Array(0), Z = new Int32Array(0), j = new Float64Array(0), Ct = new Float64Array(0), It = new Float64Array(0), Rt = new Float64Array(0), qt = new Int32Array(0);
1181
- const Q = [0, 0];
1182
- let Ys = 0, In = new Float64Array(0), Rn = new Float64Array(0), Tn = new Float64Array(0), kn = new Float64Array(0), Fn = new Float64Array(0), Sn = new Float64Array(0), Ln = new Float64Array(0), Pn = new Float64Array(0), Gn = new Float64Array(0), On = new Float64Array(0), Nn = new Float64Array(0), Un = new Float64Array(0), Xs = 0, Lt = new Int32Array(0);
1183
- function se(i) {
1184
- const t = i.length;
1416
+ const W = Number.MAX_VALUE, L = [0, 0], _t = [0, 0];
1417
+ let ho = 0, $ = new Float64Array(0), Q = new Float64Array(0), G = new Float64Array(0), U = new Float64Array(0), Z = new Int32Array(0), J = new Float64Array(0), Pt = new Float64Array(0), Ot = new Float64Array(0), Nt = new Float64Array(0), Ft = new Int32Array(0);
1418
+ const j = [0, 0];
1419
+ let po = 0, Vn = new Float64Array(0), Bn = new Float64Array(0), Kn = new Float64Array(0), zn = new Float64Array(0), $n = new Float64Array(0), jn = new Float64Array(0), Qn = new Float64Array(0), Zn = new Float64Array(0), Jn = new Float64Array(0), ts = new Float64Array(0), ns = new Float64Array(0), ss = new Float64Array(0), fo = 0, Vt = new Int32Array(0);
1420
+ function Ge(o) {
1421
+ const t = o.length;
1185
1422
  if (t === 0) return 0;
1186
1423
  let n = 0;
1187
1424
  if (t === 1) {
1188
- i[0].point(0, Q);
1189
- const s = Q[0], o = Q[1];
1190
- i[0].point(1 / 3, Q);
1191
- const e = Q[0], p = Q[1];
1192
- i[0].point(2 / 3, Q);
1193
- const c = Q[0], r = Q[1];
1194
- n += s * p - o * e, n += e * r - p * c, n += c * o - r * s;
1425
+ o[0].point(0, j);
1426
+ const s = j[0], i = j[1];
1427
+ o[0].point(1 / 3, j);
1428
+ const e = j[0], a = j[1];
1429
+ o[0].point(2 / 3, j);
1430
+ const c = j[0], r = j[1];
1431
+ n += s * a - i * e, n += e * r - a * c, n += c * i - r * s;
1195
1432
  } else if (t === 2) {
1196
- i[0].point(0, Q);
1197
- const s = Q[0], o = Q[1];
1198
- i[0].point(0.5, Q);
1199
- const e = Q[0], p = Q[1];
1200
- i[1].point(0, Q);
1201
- const c = Q[0], r = Q[1];
1202
- i[1].point(0.5, Q);
1203
- const h = Q[0], l = Q[1];
1204
- n += s * p - o * e, n += e * r - p * c, n += c * l - r * h, n += h * o - l * s;
1433
+ o[0].point(0, j);
1434
+ const s = j[0], i = j[1];
1435
+ o[0].point(0.5, j);
1436
+ const e = j[0], a = j[1];
1437
+ o[1].point(0, j);
1438
+ const c = j[0], r = j[1];
1439
+ o[1].point(0.5, j);
1440
+ const h = j[0], p = j[1];
1441
+ n += s * a - i * e, n += e * r - a * c, n += c * p - r * h, n += h * i - p * s;
1205
1442
  } else {
1206
- const s = i[t - 1];
1207
- let o = s.p0x, e = s.p0y;
1208
- for (let p = 0; p < t; p++) {
1209
- const c = i[p].p0x, r = i[p].p0y;
1210
- n += o * r - e * c, o = c, e = r;
1443
+ const s = o[t - 1];
1444
+ let i = s.p0x, e = s.p0y;
1445
+ for (let a = 0; a < t; a++) {
1446
+ const c = o[a].p0x, r = o[a].p0y;
1447
+ n += i * r - e * c, i = c, e = r;
1211
1448
  }
1212
1449
  }
1213
1450
  return n > 0 ? -1 : n < 0 ? 1 : 0;
1214
1451
  }
1215
- function oe(i, t, n, s, o, e, p) {
1216
- const c = p[i][t];
1452
+ function Ue(o, t, n, s, i, e, a) {
1453
+ const c = a[o][t];
1217
1454
  let r = n;
1218
1455
  if (e < 0) {
1219
- c.direction(0, T);
1220
- const h = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1456
+ c.direction(0, L);
1457
+ const h = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
1221
1458
  if (h > 0) {
1222
- const l = T[0] / h, a = T[1] / h;
1223
- c.point(0, yt);
1224
- const f = s - yt[0], y = o - 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);
1459
+ const p = L[0] / h, l = L[1] / h;
1460
+ c.point(0, _t);
1461
+ const f = s - _t[0], u = i - _t[1];
1462
+ if (f * p + u * l < 0) {
1463
+ const y = f * l - u * p;
1464
+ Math.abs(y) <= Math.abs(r) && (r = y);
1228
1465
  }
1229
1466
  }
1230
1467
  }
1231
1468
  if (e > 1) {
1232
- c.direction(1, T);
1233
- const h = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1469
+ c.direction(1, L);
1470
+ const h = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
1234
1471
  if (h > 0) {
1235
- const l = T[0] / h, a = T[1] / h;
1236
- c.point(1, yt);
1237
- const f = s - yt[0], y = o - 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);
1472
+ const p = L[0] / h, l = L[1] / h;
1473
+ c.point(1, _t);
1474
+ const f = s - _t[0], u = i - _t[1];
1475
+ if (f * p + u * l > 0) {
1476
+ const y = f * l - u * p;
1477
+ Math.abs(y) <= Math.abs(r) && (r = y);
1241
1478
  }
1242
1479
  }
1243
1480
  }
1244
1481
  return r;
1245
1482
  }
1246
- function lt(i, t, n, s, o, e, p, c, r) {
1247
- let h = i < 0 ? t : n;
1248
- if (o >= 0) {
1249
- const l = oe(s, o, i, p, c, e, r);
1250
- Math.abs(l) < Math.abs(h) && (h = l);
1483
+ function ut(o, t, n, s, i, e, a, c, r) {
1484
+ let h = o < 0 ? t : n;
1485
+ if (i >= 0) {
1486
+ const p = Ue(s, i, o, a, c, e, r);
1487
+ Math.abs(p) < Math.abs(h) && (h = p);
1251
1488
  }
1252
1489
  return h;
1253
1490
  }
1254
- function gt(i, t, n) {
1255
- return Math.max(Math.min(i, t), Math.min(Math.max(i, t), n));
1491
+ function dt(o, t, n) {
1492
+ return Math.max(Math.min(o, t), Math.min(Math.max(o, t), n));
1256
1493
  }
1257
- function ee(i, t, n, s, o, e, p, c) {
1494
+ function Ye(o, t, n, s, i, e, a, c) {
1258
1495
  if (c.length !== t * n * 3)
1259
1496
  throw new Error(`generateMSDF: out.length ${c.length} !== ${t * n * 3}`);
1260
- const r = i.contours, h = r.length;
1497
+ const r = o.contours, h = r.length;
1261
1498
  if (h === 0) {
1262
1499
  c.fill(0);
1263
1500
  return;
1264
1501
  }
1265
- const l = s / p;
1266
- qt.length < h && (qt = new Int32Array(h));
1267
- for (let y = 0; y < h; y++) qt[y] = se(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 && (In = new Float64Array(a), Rn = new Float64Array(a), Tn = new Float64Array(a), kn = new Float64Array(a), Fn = new Float64Array(a), Sn = new Float64Array(a), Ln = new Float64Array(a), Pn = new Float64Array(a), Gn = new Float64Array(a), On = 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 g = 0; g < u; g++) {
1276
- const A = _[g], m = _[(g + u - 1) % u], v = _[(g + 1) % u], w = x + g;
1277
- A.point(0, yt), In[w] = yt[0], Rn[w] = yt[1], A.point(1, yt), Tn[w] = yt[0], kn[w] = yt[1], A.direction(0, T);
1278
- let E = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1279
- const C = E > 0 ? T[0] / E : 0, F = E > 0 ? T[1] / E : 0;
1280
- Fn[w] = C, Sn[w] = F, A.direction(1, T), E = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1281
- const R = E > 0 ? T[0] / E : 0, b = E > 0 ? T[1] / E : 0;
1282
- Ln[w] = R, Pn[w] = b, m.direction(1, T), E = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1283
- const N = E > 0 ? T[0] / E : 0, I = E > 0 ? T[1] / E : 0;
1284
- v.direction(0, T), E = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1285
- const q = E > 0 ? T[0] / E : 0, O = E > 0 ? T[1] / E : 0, X = N + C, K = I + F, V = Math.sqrt(X * X + K * K);
1286
- Gn[w] = V > 0 ? X / V : 0, On[w] = V > 0 ? K / V : 0;
1287
- const nt = R + q, H = b + O, z = Math.sqrt(nt * nt + H * H);
1288
- Nn[w] = z > 0 ? -(nt / z) : 0, Un[w] = z > 0 ? -(H / z) : 0;
1502
+ const p = s / a;
1503
+ Ft.length < h && (Ft = new Int32Array(h));
1504
+ for (let u = 0; u < h; u++) Ft[u] = Ge(r[u]);
1505
+ fo < h + 1 && (Vt = new Int32Array(h + 1), fo = h + 1);
1506
+ let l = 0;
1507
+ for (let u = 0; u < h; u++)
1508
+ Vt[u] = l, l += r[u].length;
1509
+ Vt[h] = l, po < l && (Vn = new Float64Array(l), Bn = new Float64Array(l), Kn = new Float64Array(l), zn = new Float64Array(l), $n = new Float64Array(l), jn = new Float64Array(l), Qn = new Float64Array(l), Zn = new Float64Array(l), Jn = new Float64Array(l), ts = new Float64Array(l), ns = new Float64Array(l), ss = new Float64Array(l), po = l);
1510
+ for (let u = 0; u < h; u++) {
1511
+ const _ = r[u], y = _.length, g = Vt[u];
1512
+ for (let M = 0; M < y; M++) {
1513
+ const I = _[M], q = _[(M + y - 1) % y], T = _[(M + 1) % y], A = g + M;
1514
+ I.point(0, _t), Vn[A] = _t[0], Bn[A] = _t[1], I.point(1, _t), Kn[A] = _t[0], zn[A] = _t[1], I.direction(0, L);
1515
+ let D = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
1516
+ const R = D > 0 ? L[0] / D : 0, m = D > 0 ? L[1] / D : 0;
1517
+ $n[A] = R, jn[A] = m, I.direction(1, L), D = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
1518
+ const d = D > 0 ? L[0] / D : 0, x = D > 0 ? L[1] / D : 0;
1519
+ Qn[A] = d, Zn[A] = x, q.direction(1, L), D = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
1520
+ const C = D > 0 ? L[0] / D : 0, v = D > 0 ? L[1] / D : 0;
1521
+ T.direction(0, L), D = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
1522
+ const E = D > 0 ? L[0] / D : 0, k = D > 0 ? L[1] / D : 0, S = C + R, H = v + m, Y = Math.sqrt(S * S + H * H);
1523
+ Jn[A] = Y > 0 ? S / Y : 0, ts[A] = Y > 0 ? H / Y : 0;
1524
+ const tt = d + E, V = x + k, K = Math.sqrt(tt * tt + V * V);
1525
+ ns[A] = K > 0 ? -(tt / K) : 0, ss[A] = K > 0 ? -(V / K) : 0;
1289
1526
  }
1290
1527
  }
1291
- if (Us < h) {
1292
- const y = h * 3;
1293
- B = new Float64Array(y), $ = new Float64Array(y), P = new Float64Array(y), G = new Float64Array(y), Z = new Int32Array(y), j = new Float64Array(y), Ct = new Float64Array(h), It = new Float64Array(h), Rt = new Float64Array(h), Us = h;
1528
+ if (ho < h) {
1529
+ const u = h * 3;
1530
+ $ = new Float64Array(u), Q = new Float64Array(u), G = new Float64Array(u), U = new Float64Array(u), Z = new Int32Array(u), J = new Float64Array(u), Pt = new Float64Array(h), Ot = new Float64Array(h), Nt = new Float64Array(h), ho = h;
1294
1531
  }
1295
1532
  const f = { distance: 0, dot: 0, param: 0 };
1296
- for (let y = 0; y < n; y++)
1533
+ for (let u = 0; u < n; u++)
1297
1534
  for (let _ = 0; _ < t; _++) {
1298
- const u = (_ + 0.5) / s - o, x = (y + 0.5) / s - e;
1299
- for (let D = 0; D < h; D++) {
1300
- const d = r[D], ct = d.length, M = D * 3, S = Lt[D];
1301
- B[M] = B[M + 1] = B[M + 2] = -Y, $[M] = $[M + 1] = $[M + 2] = 0, P[M] = P[M + 1] = P[M + 2] = -Y, G[M] = G[M + 1] = G[M + 2] = Y, Z[M] = Z[M + 1] = Z[M + 2] = -1, j[M] = j[M + 1] = j[M + 2] = 0;
1302
- for (let L = 0; L < ct; L++) {
1303
- const W = d[L], bn = W.color, wn = (bn & Jt) !== 0, An = (bn & tn) !== 0, En = (bn & nn) !== 0;
1304
- W.signedDistance(u, x, f);
1305
- const zt = f.distance, vt = f.dot, Dn = f.param, wt = Math.abs(zt);
1306
- if (wn) {
1307
- const dt = Math.abs(B[M]);
1308
- (wt < dt || wt === dt && vt < $[M]) && (B[M] = zt, $[M] = vt, Z[M] = L, j[M] = Dn);
1535
+ const y = (_ + 0.5) / s - i, g = (u + 0.5) / s - e;
1536
+ for (let F = 0; F < h; F++) {
1537
+ const b = r[F], ht = b.length, w = F * 3, O = Vt[F];
1538
+ $[w] = $[w + 1] = $[w + 2] = -W, Q[w] = Q[w + 1] = Q[w + 2] = 0, G[w] = G[w + 1] = G[w + 2] = -W, U[w] = U[w + 1] = U[w + 2] = W, Z[w] = Z[w + 1] = Z[w + 2] = -1, J[w] = J[w + 1] = J[w + 2] = 0;
1539
+ for (let N = 0; N < ht; N++) {
1540
+ const B = b[N], Pn = B.color, On = (Pn & Mn) !== 0, Nn = (Pn & dn) !== 0, Gn = (Pn & wn) !== 0;
1541
+ B.signedDistance(y, g, f);
1542
+ const cn = f.distance, Lt = f.dot, Un = f.param, It = Math.abs(cn);
1543
+ if (On) {
1544
+ const bt = Math.abs($[w]);
1545
+ (It < bt || It === bt && Lt < Q[w]) && ($[w] = cn, Q[w] = Lt, Z[w] = N, J[w] = Un);
1309
1546
  }
1310
- if (An) {
1311
- const dt = Math.abs(B[M + 1]);
1312
- (wt < dt || wt === dt && vt < $[M + 1]) && (B[M + 1] = zt, $[M + 1] = vt, Z[M + 1] = L, j[M + 1] = Dn);
1547
+ if (Nn) {
1548
+ const bt = Math.abs($[w + 1]);
1549
+ (It < bt || It === bt && Lt < Q[w + 1]) && ($[w + 1] = cn, Q[w + 1] = Lt, Z[w + 1] = N, J[w + 1] = Un);
1313
1550
  }
1314
- if (En) {
1315
- const dt = Math.abs(B[M + 2]);
1316
- (wt < dt || wt === dt && vt < $[M + 2]) && (B[M + 2] = zt, $[M + 2] = vt, Z[M + 2] = L, j[M + 2] = Dn);
1551
+ if (Gn) {
1552
+ const bt = Math.abs($[w + 2]);
1553
+ (It < bt || It === bt && Lt < Q[w + 2]) && ($[w + 2] = cn, Q[w + 2] = Lt, Z[w + 2] = N, J[w + 2] = Un);
1317
1554
  }
1318
- const pt = S + L, qn = u - In[pt], mn = x - Rn[pt], vn = u - Tn[pt], Cn = x - kn[pt], qs = Fn[pt], ms = Sn[pt], vs = Ln[pt], Cs = Pn[pt], oo = qn * Gn[pt] + mn * On[pt], eo = vn * Nn[pt] + Cn * Un[pt];
1319
- if (oo > 0 && -(qn * qs + mn * ms) > 0) {
1320
- const k = qn * ms - mn * qs;
1321
- Math.abs(k) < wt && (wn && (k <= 0 && k > P[M] ? P[M] = k : k > 0 && k < G[M] && (G[M] = k)), An && (k <= 0 && k > P[M + 1] ? P[M + 1] = k : k > 0 && k < G[M + 1] && (G[M + 1] = k)), En && (k <= 0 && k > P[M + 2] ? P[M + 2] = k : k > 0 && k < G[M + 2] && (G[M + 2] = k)));
1555
+ const ft = O + N, Yn = y - Vn[ft], Xn = g - Bn[ft], Wn = y - Kn[ft], Hn = g - zn[ft], Vs = $n[ft], Bs = jn[ft], Ks = Qn[ft], zs = Zn[ft], vo = Yn * Jn[ft] + Xn * ts[ft], ko = Wn * ns[ft] + Hn * ss[ft];
1556
+ if (vo > 0 && -(Yn * Vs + Xn * Bs) > 0) {
1557
+ const P = Yn * Bs - Xn * Vs;
1558
+ Math.abs(P) < It && (On && (P <= 0 && P > G[w] ? G[w] = P : P > 0 && P < U[w] && (U[w] = P)), Nn && (P <= 0 && P > G[w + 1] ? G[w + 1] = P : P > 0 && P < U[w + 1] && (U[w + 1] = P)), Gn && (P <= 0 && P > G[w + 2] ? G[w + 2] = P : P > 0 && P < U[w + 2] && (U[w + 2] = P)));
1322
1559
  }
1323
- if (eo > 0 && vn * vs + Cn * Cs > 0) {
1324
- const k = vn * Cs - Cn * vs;
1325
- Math.abs(k) < wt && (wn && (k <= 0 && k > P[M] ? P[M] = k : k > 0 && k < G[M] && (G[M] = k)), An && (k <= 0 && k > P[M + 1] ? P[M + 1] = k : k > 0 && k < G[M + 1] && (G[M + 1] = k)), En && (k <= 0 && k > P[M + 2] ? P[M + 2] = k : k > 0 && k < G[M + 2] && (G[M + 2] = k)));
1560
+ if (ko > 0 && Wn * Ks + Hn * zs > 0) {
1561
+ const P = Wn * zs - Hn * Ks;
1562
+ Math.abs(P) < It && (On && (P <= 0 && P > G[w] ? G[w] = P : P > 0 && P < U[w] && (U[w] = P)), Nn && (P <= 0 && P > G[w + 1] ? G[w + 1] = P : P > 0 && P < U[w + 1] && (U[w + 1] = P)), Gn && (P <= 0 && P > G[w + 2] ? G[w + 2] = P : P > 0 && P < U[w + 2] && (U[w + 2] = P)));
1326
1563
  }
1327
1564
  }
1328
- Ct[D] = lt(
1329
- B[M],
1330
- P[M],
1331
- G[M],
1332
- D,
1333
- Z[M],
1334
- j[M],
1335
- u,
1336
- x,
1565
+ Pt[F] = ut(
1566
+ $[w],
1567
+ G[w],
1568
+ U[w],
1569
+ F,
1570
+ Z[w],
1571
+ J[w],
1572
+ y,
1573
+ g,
1337
1574
  r
1338
- ), It[D] = lt(
1339
- B[M + 1],
1340
- P[M + 1],
1341
- G[M + 1],
1342
- D,
1343
- Z[M + 1],
1344
- j[M + 1],
1345
- u,
1346
- x,
1575
+ ), Ot[F] = ut(
1576
+ $[w + 1],
1577
+ G[w + 1],
1578
+ U[w + 1],
1579
+ F,
1580
+ Z[w + 1],
1581
+ J[w + 1],
1582
+ y,
1583
+ g,
1347
1584
  r
1348
- ), Rt[D] = lt(
1349
- B[M + 2],
1350
- P[M + 2],
1351
- G[M + 2],
1352
- D,
1353
- Z[M + 2],
1354
- j[M + 2],
1355
- u,
1356
- x,
1585
+ ), Nt[F] = ut(
1586
+ $[w + 2],
1587
+ G[w + 2],
1588
+ U[w + 2],
1589
+ F,
1590
+ Z[w + 2],
1591
+ J[w + 2],
1592
+ y,
1593
+ g,
1357
1594
  r
1358
1595
  );
1359
1596
  }
1360
- let g = -Y, A = 0, m = -Y, v = Y, w = -1, E = -1, C = 0, F = -Y, R = 0, b = -Y, N = Y, I = -1, q = -1, O = 0, X = -Y, K = 0, V = -Y, nt = Y, H = -1, z = -1, ht = 0, st = -Y, kt = 0, sn = -Y, on = Y, $n = -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, es = -1, is = -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, gs = -1, Ms = 0;
1361
- for (let D = 0; D < h; D++) {
1362
- const d = D * 3, ct = qt[D], M = gt(Ct[D], It[D], Rt[D]);
1597
+ let M = -W, I = 0, q = -W, T = W, A = -1, D = -1, R = 0, m = -W, d = 0, x = -W, C = W, v = -1, E = -1, k = 0, S = -W, H = 0, Y = -W, tt = W, V = -1, K = -1, nt = 0, st = -W, Et = 0, Tt = -W, St = W, xs = -1, gs = -1, Ms = 0, Zt = -W, ds = 0, bn = -W, An = W, ws = -1, bs = -1, As = 0, Jt = -W, ms = 0, mn = -W, En = W, Es = -1, Is = -1, Ds = 0, tn = -W, qs = 0, In = -W, Dn = W, vs = -1, ks = -1, Cs = 0, nn = -W, Fs = 0, qn = -W, vn = W, Rs = -1, Ts = -1, Ss = 0, sn = -W, Ls = 0, kn = -W, Cn = W, Ps = -1, Os = -1, Ns = 0;
1598
+ for (let F = 0; F < h; F++) {
1599
+ const b = F * 3, ht = Ft[F], w = dt(Pt[F], Ot[F], Nt[F]);
1363
1600
  {
1364
- const S = B[d], L = $[d], W = Math.abs(S);
1365
- (W < Math.abs(g) || W === Math.abs(g) && L < A) && (g = S, A = L, w = D, E = Z[d], C = j[d]), P[d] > m && (m = P[d]), G[d] < v && (v = G[d]);
1601
+ const O = $[b], N = Q[b], B = Math.abs(O);
1602
+ (B < Math.abs(M) || B === Math.abs(M) && N < I) && (M = O, I = N, A = F, D = Z[b], R = J[b]), G[b] > q && (q = G[b]), U[b] < T && (T = U[b]);
1366
1603
  }
1367
1604
  {
1368
- const S = B[d + 1], L = $[d + 1], W = Math.abs(S);
1369
- (W < Math.abs(F) || W === Math.abs(F) && L < R) && (F = S, R = L, I = D, q = Z[d + 1], O = j[d + 1]), P[d + 1] > b && (b = P[d + 1]), G[d + 1] < N && (N = G[d + 1]);
1605
+ const O = $[b + 1], N = Q[b + 1], B = Math.abs(O);
1606
+ (B < Math.abs(m) || B === Math.abs(m) && N < d) && (m = O, d = N, v = F, E = Z[b + 1], k = J[b + 1]), G[b + 1] > x && (x = G[b + 1]), U[b + 1] < C && (C = U[b + 1]);
1370
1607
  }
1371
1608
  {
1372
- const S = B[d + 2], L = $[d + 2], W = Math.abs(S);
1373
- (W < Math.abs(X) || W === Math.abs(X) && L < K) && (X = S, K = L, H = D, z = Z[d + 2], ht = j[d + 2]), P[d + 2] > V && (V = P[d + 2]), G[d + 2] < nt && (nt = G[d + 2]);
1609
+ const O = $[b + 2], N = Q[b + 2], B = Math.abs(O);
1610
+ (B < Math.abs(S) || B === Math.abs(S) && N < H) && (S = O, H = N, V = F, K = Z[b + 2], nt = J[b + 2]), G[b + 2] > Y && (Y = G[b + 2]), U[b + 2] < tt && (tt = U[b + 2]);
1374
1611
  }
1375
- if (ct > 0 && M >= 0) {
1612
+ if (ht > 0 && w >= 0) {
1376
1613
  {
1377
- const S = B[d], L = $[d], W = Math.abs(S);
1378
- (W < Math.abs(st) || W === Math.abs(st) && L < kt) && (st = S, kt = L, $n = D, Zn = Z[d], jn = j[d]), P[d] > sn && (sn = P[d]), G[d] < on && (on = G[d]);
1614
+ const O = $[b], N = Q[b], B = Math.abs(O);
1615
+ (B < Math.abs(st) || B === Math.abs(st) && N < Et) && (st = O, Et = N, xs = F, gs = Z[b], Ms = J[b]), G[b] > Tt && (Tt = G[b]), U[b] < St && (St = U[b]);
1379
1616
  }
1380
1617
  {
1381
- const S = B[d + 1], L = $[d + 1], W = Math.abs(S);
1382
- (W < Math.abs(Nt) || W === Math.abs(Nt) && L < Jn) && (Nt = S, Jn = L, ts = D, ns = Z[d + 1], ss = j[d + 1]), P[d + 1] > en && (en = P[d + 1]), G[d + 1] < cn && (cn = G[d + 1]);
1618
+ const O = $[b + 1], N = Q[b + 1], B = Math.abs(O);
1619
+ (B < Math.abs(Zt) || B === Math.abs(Zt) && N < ds) && (Zt = O, ds = N, ws = F, bs = Z[b + 1], As = J[b + 1]), G[b + 1] > bn && (bn = G[b + 1]), U[b + 1] < An && (An = U[b + 1]);
1383
1620
  }
1384
1621
  {
1385
- const S = B[d + 2], L = $[d + 2], W = Math.abs(S);
1386
- (W < Math.abs(Ut) || W === Math.abs(Ut) && L < os) && (Ut = S, os = L, es = D, is = Z[d + 2], cs = j[d + 2]), P[d + 2] > rn && (rn = P[d + 2]), G[d + 2] < an && (an = G[d + 2]);
1622
+ const O = $[b + 2], N = Q[b + 2], B = Math.abs(O);
1623
+ (B < Math.abs(Jt) || B === Math.abs(Jt) && N < ms) && (Jt = O, ms = N, Es = F, Is = Z[b + 2], Ds = J[b + 2]), G[b + 2] > mn && (mn = G[b + 2]), U[b + 2] < En && (En = U[b + 2]);
1387
1624
  }
1388
1625
  }
1389
- if (ct < 0 && M <= 0) {
1626
+ if (ht < 0 && w <= 0) {
1390
1627
  {
1391
- const S = B[d], L = $[d], W = Math.abs(S);
1392
- (W < Math.abs(Yt) || W === Math.abs(Yt) && L < rs) && (Yt = S, rs = L, as = D, hs = Z[d], ps = j[d]), P[d] > hn && (hn = P[d]), G[d] < pn && (pn = G[d]);
1628
+ const O = $[b], N = Q[b], B = Math.abs(O);
1629
+ (B < Math.abs(tn) || B === Math.abs(tn) && N < qs) && (tn = O, qs = N, vs = F, ks = Z[b], Cs = J[b]), G[b] > In && (In = G[b]), U[b] < Dn && (Dn = U[b]);
1393
1630
  }
1394
1631
  {
1395
- const S = B[d + 1], L = $[d + 1], W = Math.abs(S);
1396
- (W < Math.abs(Xt) || W === Math.abs(Xt) && L < ls) && (Xt = S, ls = L, fs = D, ys = Z[d + 1], us = j[d + 1]), P[d + 1] > ln && (ln = P[d + 1]), G[d + 1] < fn && (fn = G[d + 1]);
1632
+ const O = $[b + 1], N = Q[b + 1], B = Math.abs(O);
1633
+ (B < Math.abs(nn) || B === Math.abs(nn) && N < Fs) && (nn = O, Fs = N, Rs = F, Ts = Z[b + 1], Ss = J[b + 1]), G[b + 1] > qn && (qn = G[b + 1]), U[b + 1] < vn && (vn = U[b + 1]);
1397
1634
  }
1398
1635
  {
1399
- const S = B[d + 2], L = $[d + 2], W = Math.abs(S);
1400
- (W < Math.abs(Wt) || W === Math.abs(Wt) && L < _s) && (Wt = S, _s = L, xs = D, gs = Z[d + 2], Ms = j[d + 2]), P[d + 2] > yn && (yn = P[d + 2]), G[d + 2] < un && (un = G[d + 2]);
1636
+ const O = $[b + 2], N = Q[b + 2], B = Math.abs(O);
1637
+ (B < Math.abs(sn) || B === Math.abs(sn) && N < Ls) && (sn = O, Ls = N, Ps = F, Os = Z[b + 2], Ns = J[b + 2]), G[b + 2] > kn && (kn = G[b + 2]), U[b + 2] < Cn && (Cn = U[b + 2]);
1401
1638
  }
1402
1639
  }
1403
1640
  }
1404
- const _n = lt(
1641
+ const Fn = ut(
1642
+ M,
1643
+ q,
1644
+ T,
1645
+ A,
1646
+ D,
1647
+ R,
1648
+ y,
1405
1649
  g,
1650
+ r
1651
+ ), Rn = ut(
1406
1652
  m,
1653
+ x,
1654
+ C,
1407
1655
  v,
1408
- w,
1409
1656
  E,
1410
- C,
1411
- u,
1412
- x,
1413
- r
1414
- ), xn = lt(
1415
- F,
1416
- b,
1417
- N,
1418
- I,
1419
- q,
1420
- O,
1421
- u,
1422
- x,
1657
+ k,
1658
+ y,
1659
+ g,
1423
1660
  r
1424
- ), gn = lt(
1425
- X,
1661
+ ), Tn = ut(
1662
+ S,
1663
+ Y,
1664
+ tt,
1426
1665
  V,
1666
+ K,
1427
1667
  nt,
1428
- H,
1429
- z,
1430
- ht,
1431
- u,
1432
- x,
1668
+ y,
1669
+ g,
1433
1670
  r
1434
- ), so = gt(_n, xn, gn), ds = lt(
1671
+ ), qo = dt(Fn, Rn, Tn), Gs = ut(
1435
1672
  st,
1436
- sn,
1437
- on,
1438
- $n,
1439
- Zn,
1440
- jn,
1441
- u,
1442
- x,
1673
+ Tt,
1674
+ St,
1675
+ xs,
1676
+ gs,
1677
+ Ms,
1678
+ y,
1679
+ g,
1443
1680
  r
1444
- ), bs = lt(
1445
- Nt,
1446
- en,
1447
- cn,
1448
- ts,
1449
- ns,
1450
- ss,
1451
- u,
1452
- x,
1681
+ ), Us = ut(
1682
+ Zt,
1683
+ bn,
1684
+ An,
1685
+ ws,
1686
+ bs,
1687
+ As,
1688
+ y,
1689
+ g,
1453
1690
  r
1454
- ), ws = lt(
1455
- Ut,
1456
- rn,
1457
- an,
1458
- es,
1459
- is,
1460
- cs,
1461
- u,
1462
- x,
1691
+ ), Ys = ut(
1692
+ Jt,
1693
+ mn,
1694
+ En,
1695
+ Es,
1696
+ Is,
1697
+ Ds,
1698
+ y,
1699
+ g,
1463
1700
  r
1464
- ), Ht = gt(ds, bs, ws), As = lt(
1465
- Yt,
1466
- hn,
1467
- pn,
1468
- as,
1469
- hs,
1470
- ps,
1471
- u,
1472
- x,
1701
+ ), on = dt(Gs, Us, Ys), Xs = ut(
1702
+ tn,
1703
+ In,
1704
+ Dn,
1705
+ vs,
1706
+ ks,
1707
+ Cs,
1708
+ y,
1709
+ g,
1473
1710
  r
1474
- ), Es = lt(
1475
- Xt,
1476
- ln,
1477
- fn,
1478
- fs,
1479
- ys,
1480
- us,
1481
- u,
1482
- x,
1711
+ ), Ws = ut(
1712
+ nn,
1713
+ qn,
1714
+ vn,
1715
+ Rs,
1716
+ Ts,
1717
+ Ss,
1718
+ y,
1719
+ g,
1483
1720
  r
1484
- ), Ds = lt(
1485
- Wt,
1486
- yn,
1487
- un,
1488
- xs,
1489
- gs,
1490
- Ms,
1491
- u,
1492
- x,
1721
+ ), Hs = ut(
1722
+ sn,
1723
+ kn,
1724
+ Cn,
1725
+ Ps,
1726
+ Os,
1727
+ Ns,
1728
+ y,
1729
+ g,
1493
1730
  r
1494
- ), Vt = gt(As, Es, Ds);
1495
- let ut, _t, xt, Mn = 0;
1496
- if (Ht >= 0 && Math.abs(Ht) <= Math.abs(Vt)) {
1497
- ut = ds, _t = bs, xt = ws, Mn = 1;
1498
- for (let D = 0; D < h; D++)
1499
- if (qt[D] > 0) {
1500
- const d = Ct[D], ct = It[D], M = Rt[D], S = gt(d, ct, M);
1501
- Math.abs(S) < Math.abs(Vt) && S > gt(ut, _t, xt) && (ut = d, _t = ct, xt = M);
1731
+ ), en = dt(Xs, Ws, Hs);
1732
+ let xt, gt, Mt, Sn = 0;
1733
+ if (on >= 0 && Math.abs(on) <= Math.abs(en)) {
1734
+ xt = Gs, gt = Us, Mt = Ys, Sn = 1;
1735
+ for (let F = 0; F < h; F++)
1736
+ if (Ft[F] > 0) {
1737
+ const b = Pt[F], ht = Ot[F], w = Nt[F], O = dt(b, ht, w);
1738
+ Math.abs(O) < Math.abs(en) && O > dt(xt, gt, Mt) && (xt = b, gt = ht, Mt = w);
1502
1739
  }
1503
- } else if (Vt <= 0 && Math.abs(Vt) < Math.abs(Ht)) {
1504
- ut = As, _t = Es, xt = Ds, Mn = -1;
1505
- for (let D = 0; D < h; D++)
1506
- if (qt[D] < 0) {
1507
- const d = Ct[D], ct = It[D], M = Rt[D], S = gt(d, ct, M);
1508
- Math.abs(S) < Math.abs(Ht) && S < gt(ut, _t, xt) && (ut = d, _t = ct, xt = M);
1740
+ } else if (en <= 0 && Math.abs(en) < Math.abs(on)) {
1741
+ xt = Xs, gt = Ws, Mt = Hs, Sn = -1;
1742
+ for (let F = 0; F < h; F++)
1743
+ if (Ft[F] < 0) {
1744
+ const b = Pt[F], ht = Ot[F], w = Nt[F], O = dt(b, ht, w);
1745
+ Math.abs(O) < Math.abs(on) && O < dt(xt, gt, Mt) && (xt = b, gt = ht, Mt = w);
1509
1746
  }
1510
1747
  } else {
1511
- const D = (y * t + _) * 3;
1512
- c[D + 0] = _n * l + 0.5, c[D + 1] = xn * l + 0.5, c[D + 2] = gn * l + 0.5;
1748
+ const F = (u * t + _) * 3;
1749
+ c[F + 0] = Fn * p + 0.5, c[F + 1] = Rn * p + 0.5, c[F + 2] = Tn * p + 0.5;
1513
1750
  continue;
1514
1751
  }
1515
- for (let D = 0; D < h; D++)
1516
- if (qt[D] !== Mn) {
1517
- const d = Ct[D], ct = It[D], M = Rt[D], S = gt(d, ct, M), L = gt(ut, _t, xt);
1518
- S * L >= 0 && Math.abs(S) < Math.abs(L) && (ut = d, _t = ct, xt = M);
1752
+ for (let F = 0; F < h; F++)
1753
+ if (Ft[F] !== Sn) {
1754
+ const b = Pt[F], ht = Ot[F], w = Nt[F], O = dt(b, ht, w), N = dt(xt, gt, Mt);
1755
+ O * N >= 0 && Math.abs(O) < Math.abs(N) && (xt = b, gt = ht, Mt = w);
1519
1756
  }
1520
- gt(ut, _t, xt) === so && (ut = _n, _t = xn, xt = gn);
1521
- const dn = (y * t + _) * 3;
1522
- c[dn + 0] = ut * l + 0.5, c[dn + 1] = _t * l + 0.5, c[dn + 2] = xt * l + 0.5;
1757
+ dt(xt, gt, Mt) === qo && (xt = Fn, gt = Rn, Mt = Tn);
1758
+ const Ln = (u * t + _) * 3;
1759
+ c[Ln + 0] = xt * p + 0.5, c[Ln + 1] = gt * p + 0.5, c[Ln + 2] = Mt * p + 0.5;
1523
1760
  }
1524
1761
  }
1525
- const js = 0, ie = 1, ce = 2, re = 3;
1526
- function ae(i, t) {
1762
+ const mo = 0, Xe = 1, We = 2, He = 3;
1763
+ function Ve(o, t) {
1527
1764
  switch (t) {
1528
- case js:
1529
- return i !== 0;
1530
- case ie:
1531
- return (i & 1) !== 0;
1532
- case ce:
1533
- return i > 0;
1534
- case re:
1535
- return i < 0;
1765
+ case mo:
1766
+ return o !== 0;
1767
+ case Xe:
1768
+ return (o & 1) !== 0;
1769
+ case We:
1770
+ return o > 0;
1771
+ case He:
1772
+ return o < 0;
1536
1773
  }
1537
1774
  return !1;
1538
1775
  }
1539
- class he {
1776
+ class Be {
1540
1777
  constructor() {
1541
1778
  this._intersections = [], this._lastIndex = 0;
1542
1779
  }
@@ -1548,7 +1785,7 @@ class he {
1548
1785
  */
1549
1786
  setIntersections(t) {
1550
1787
  if (this._intersections = t, this._lastIndex = 0, t.length > 0) {
1551
- t.sort((s, o) => rt(s.x - o.x));
1788
+ t.sort((s, i) => pt(s.x - i.x));
1552
1789
  let n = 0;
1553
1790
  for (let s = 0; s < t.length; s++)
1554
1791
  n += t[s].direction, t[s].direction = n;
@@ -1592,298 +1829,326 @@ class he {
1592
1829
  * @returns True when filled.
1593
1830
  */
1594
1831
  filled(t, n) {
1595
- return ae(this.sumIntersections(t), n);
1832
+ return Ve(this.sumIntersections(t), n);
1596
1833
  }
1597
1834
  }
1598
- const Ws = [0, 0, 0], Hs = [0, 0, 0];
1599
- function pe(i, t, n) {
1835
+ const uo = [0, 0, 0], yo = [0, 0, 0];
1836
+ function Ke(o, t, n) {
1600
1837
  const s = [];
1601
- for (const o of i.contours)
1602
- for (const e of o) {
1603
- const p = e.scanlineIntersections(t, Ws, Hs);
1604
- for (let c = 0; c < p; c++)
1605
- s.push({ x: Ws[c], direction: Hs[c] });
1838
+ for (const i of o.contours)
1839
+ for (const e of i) {
1840
+ const a = e.scanlineIntersections(t, uo, yo);
1841
+ for (let c = 0; c < a; c++)
1842
+ s.push({ x: uo[c], direction: yo[c] });
1606
1843
  }
1607
1844
  n.setIntersections(s);
1608
1845
  }
1609
- const Tt = 2, Js = 1, Yn = 1.001, le = 1.1111111111111112, jt = 0.01;
1610
- function fe(i, t, n, s, o, e, p) {
1846
+ const Yt = 2, Eo = 1, os = 1.001, ze = 1.1111111111111112, gn = 0.01;
1847
+ function $e(o, t, n, s, i, e, a) {
1611
1848
  if (n === 0 || s === 0) return;
1612
- const c = new he(), r = new Int8Array(n * s);
1849
+ const c = new Be(), r = new Int8Array(n * s);
1613
1850
  for (let h = 0; h < s; h++) {
1614
- const l = (h + 0.5) / o - p;
1615
- pe(t, l, c);
1616
- for (let a = 0; a < n; a++) {
1617
- const f = (a + 0.5) / o - e, y = c.filled(f, js), _ = (h * n + a) * 3, u = i[_], x = i[_ + 1], g = i[_ + 2], A = tt(u, x, g), m = h * n + a;
1618
- A === 0.5 ? r[m] = 0 : A > 0.5 !== y ? (i[_] = 1 - u, i[_ + 1] = 1 - x, i[_ + 2] = 1 - g, r[m] = -1) : r[m] = 1;
1851
+ const p = (h + 0.5) / i - a;
1852
+ Ke(t, p, c);
1853
+ for (let l = 0; l < n; l++) {
1854
+ const f = (l + 0.5) / i - e, u = c.filled(f, mo), _ = (h * n + l) * 3, y = o[_], g = o[_ + 1], M = o[_ + 2], I = rt(y, g, M), q = h * n + l;
1855
+ I === 0.5 ? r[q] = 0 : I > 0.5 !== u ? (o[_] = 1 - y, o[_ + 1] = 1 - g, o[_ + 2] = 1 - M, r[q] = -1) : r[q] = 1;
1619
1856
  }
1620
1857
  }
1621
1858
  for (let h = 0; h < s; h++)
1622
- for (let l = 0; l < n; l++) {
1623
- const a = h * n + l;
1624
- if (r[a] !== 0) continue;
1859
+ for (let p = 0; p < n; p++) {
1860
+ const l = h * n + p;
1861
+ if (r[l] !== 0) continue;
1625
1862
  let f = 0;
1626
- if (l > 0 && (f += r[a - 1]), l < n - 1 && (f += r[a + 1]), h > 0 && (f += r[a - n]), h < s - 1 && (f += r[a + n]), f < 0) {
1627
- const y = (h * n + l) * 3;
1628
- i[y] = 1 - i[y], i[y + 1] = 1 - i[y + 1], i[y + 2] = 1 - i[y + 2];
1863
+ if (p > 0 && (f += r[l - 1]), p < n - 1 && (f += r[l + 1]), h > 0 && (f += r[l - n]), h < s - 1 && (f += r[l + n]), f < 0) {
1864
+ const u = (h * n + p) * 3;
1865
+ o[u] = 1 - o[u], o[u + 1] = 1 - o[u + 1], o[u + 2] = 1 - o[u + 2];
1629
1866
  }
1630
1867
  }
1631
1868
  }
1632
- const Xn = [0, 0];
1633
- function ye(i, t, n, s, o, e, p, c) {
1869
+ const es = [0, 0];
1870
+ function je(o, t, n, s, i, e, a, c) {
1634
1871
  const r = new Uint8Array(n * s);
1635
- ue(r, t, n, s, o, e, p), _e(r, i, n, s, o, c), de(r, i, n, s, c, le), be(r, i, n, s);
1872
+ Qe(r, t, n, s, i, e, a), Ze(r, o, n, s, i, c), si(r, o, n, s, c, ze), oi(r, o, n, s);
1636
1873
  }
1637
- function ue(i, t, n, s, o, e, p) {
1874
+ function Qe(o, t, n, s, i, e, a) {
1638
1875
  for (const c of t.contours) {
1639
1876
  if (c.length === 0) continue;
1640
1877
  let r = c[c.length - 1];
1641
1878
  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 = o * (Xn[0] + e), f = o * (Xn[1] + p), y = Math.floor(a - 0.5) | 0, _ = Math.floor(f - 0.5) | 0, u = y + 1, x = _ + 1;
1646
- y < n && _ < s && u >= 0 && x >= 0 && (y >= 0 && _ >= 0 && (i[_ * n + y] |= Tt), u < n && _ >= 0 && (i[_ * n + u] |= Tt), y >= 0 && x < s && (i[x * n + y] |= Tt), u < n && x < s && (i[x * n + u] |= Tt));
1879
+ const p = r.color & h.color;
1880
+ if (!(p & p - 1)) {
1881
+ h.point(0, es);
1882
+ const l = i * (es[0] + e), f = i * (es[1] + a), u = Math.floor(l - 0.5) | 0, _ = Math.floor(f - 0.5) | 0, y = u + 1, g = _ + 1;
1883
+ u < n && _ < s && y >= 0 && g >= 0 && (u >= 0 && _ >= 0 && (o[_ * n + u] |= Yt), y < n && _ >= 0 && (o[_ * n + y] |= Yt), u >= 0 && g < s && (o[g * n + u] |= Yt), y < n && g < s && (o[g * n + y] |= Yt));
1647
1884
  }
1648
1885
  r = h;
1649
1886
  }
1650
1887
  }
1651
1888
  }
1652
- function Kt(i, t, n) {
1889
+ function ln(o, t, n) {
1653
1890
  let s = 0;
1654
- for (let o = 0; o < 3; o++) {
1655
- const e = i[t + o], p = i[n + o], c = e - p;
1891
+ for (let i = 0; i < 3; i++) {
1892
+ const e = o[t + i], a = o[n + i], c = e - a;
1656
1893
  if (c === 0) continue;
1657
1894
  const r = (e - 0.5) / c;
1658
1895
  if (r > 0 && r < 1) {
1659
- const h = 1 - r, l = h * i[t] + r * i[n], a = h * i[t + 1] + r * i[n + 1], f = h * i[t + 2] + r * i[n + 2], y = o === 0 ? l : o === 1 ? a : f;
1660
- tt(l, a, f) === y && (s |= o === 0 ? Jt : o === 1 ? tn : nn);
1896
+ const h = 1 - r, p = h * o[t] + r * o[n], l = h * o[t + 1] + r * o[n + 1], f = h * o[t + 2] + r * o[n + 2], u = i === 0 ? p : i === 1 ? l : f;
1897
+ rt(p, l, f) === u && (s |= i === 0 ? Mn : i === 1 ? dn : wn);
1661
1898
  }
1662
1899
  }
1663
1900
  return s;
1664
1901
  }
1665
- function At(i, t, n, s, o, e) {
1666
- (e & Jt && n[s] !== o || e & tn && n[s + 1] !== o || e & nn && n[s + 2] !== o) && (i[t] |= Tt);
1902
+ function Dt(o, t, n, s, i, e) {
1903
+ (e & Mn && n[s] !== i || e & dn && n[s + 1] !== i || e & wn && n[s + 2] !== i) && (o[t] |= Yt);
1667
1904
  }
1668
- function _e(i, t, n, s, o, e) {
1669
- const p = Yn / e, c = Yn / e, r = Yn * Math.SQRT2 / e;
1905
+ function Ze(o, t, n, s, i, e) {
1906
+ const a = os / e, c = os / e, r = os * Math.SQRT2 / e;
1670
1907
  for (let h = 0; h < s; h++)
1671
- for (let l = 0; l < n - 1; l++) {
1672
- const a = (h * n + l) * 3, f = a + 3, y = tt(t[a], t[a + 1], t[a + 2]), _ = tt(t[f], t[f + 1], t[f + 2]);
1673
- if (Math.abs(y - 0.5) + Math.abs(_ - 0.5) < p) {
1674
- const u = Kt(t, a, f);
1675
- At(i, h * n + l, t, a, y, u), At(i, h * n + l + 1, t, f, _, u);
1908
+ for (let p = 0; p < n - 1; p++) {
1909
+ const l = (h * n + p) * 3, f = l + 3, u = rt(t[l], t[l + 1], t[l + 2]), _ = rt(t[f], t[f + 1], t[f + 2]);
1910
+ if (Math.abs(u - 0.5) + Math.abs(_ - 0.5) < a) {
1911
+ const y = ln(t, l, f);
1912
+ Dt(o, h * n + p, t, l, u, y), Dt(o, h * n + p + 1, t, f, _, y);
1676
1913
  }
1677
1914
  }
1678
1915
  for (let h = 0; h < s - 1; h++)
1679
- for (let l = 0; l < n; l++) {
1680
- const a = (h * n + l) * 3, f = ((h + 1) * n + l) * 3, y = tt(t[a], t[a + 1], t[a + 2]), _ = tt(t[f], t[f + 1], t[f + 2]);
1681
- if (Math.abs(y - 0.5) + Math.abs(_ - 0.5) < c) {
1682
- const u = Kt(t, a, f);
1683
- At(i, h * n + l, t, a, y, u), At(i, (h + 1) * n + l, t, f, _, u);
1916
+ for (let p = 0; p < n; p++) {
1917
+ const l = (h * n + p) * 3, f = ((h + 1) * n + p) * 3, u = rt(t[l], t[l + 1], t[l + 2]), _ = rt(t[f], t[f + 1], t[f + 2]);
1918
+ if (Math.abs(u - 0.5) + Math.abs(_ - 0.5) < c) {
1919
+ const y = ln(t, l, f);
1920
+ Dt(o, h * n + p, t, l, u, y), Dt(o, (h + 1) * n + p, t, f, _, y);
1684
1921
  }
1685
1922
  }
1686
1923
  for (let h = 0; h < s - 1; h++)
1687
- for (let l = 0; l < n - 1; l++) {
1688
- const a = (h * n + l) * 3, f = (h * n + l + 1) * 3, y = ((h + 1) * n + l) * 3, _ = ((h + 1) * n + l + 1) * 3, u = tt(t[a], t[a + 1], t[a + 2]), x = tt(t[f], t[f + 1], t[f + 2]), g = tt(t[y], t[y + 1], t[y + 2]), A = tt(t[_], t[_ + 1], t[_ + 2]);
1689
- if (Math.abs(u - 0.5) + Math.abs(A - 0.5) < r) {
1690
- const m = Kt(t, a, _);
1691
- At(i, h * n + l, t, a, u, m), At(i, (h + 1) * n + l + 1, t, _, A, m);
1924
+ for (let p = 0; p < n - 1; p++) {
1925
+ const l = (h * n + p) * 3, f = (h * n + p + 1) * 3, u = ((h + 1) * n + p) * 3, _ = ((h + 1) * n + p + 1) * 3, y = rt(t[l], t[l + 1], t[l + 2]), g = rt(t[f], t[f + 1], t[f + 2]), M = rt(t[u], t[u + 1], t[u + 2]), I = rt(t[_], t[_ + 1], t[_ + 2]);
1926
+ if (Math.abs(y - 0.5) + Math.abs(I - 0.5) < r) {
1927
+ const q = ln(t, l, _);
1928
+ Dt(o, h * n + p, t, l, y, q), Dt(o, (h + 1) * n + p + 1, t, _, I, q);
1692
1929
  }
1693
- if (Math.abs(x - 0.5) + Math.abs(g - 0.5) < r) {
1694
- const m = Kt(t, f, y);
1695
- At(i, h * n + l + 1, t, f, x, m), At(i, (h + 1) * n + l, t, y, g, m);
1930
+ if (Math.abs(g - 0.5) + Math.abs(M - 0.5) < r) {
1931
+ const q = ln(t, f, u);
1932
+ Dt(o, h * n + p + 1, t, f, g, q), Dt(o, (h + 1) * n + p, t, u, M, q);
1696
1933
  }
1697
1934
  }
1698
1935
  }
1699
- function xe(i, t, n) {
1700
- const s = t < i ? t : i, o = i < t ? t : i, e = n < o ? n : o;
1936
+ function Je(o, t, n) {
1937
+ const s = t < o ? t : o, i = o < t ? t : o, e = n < i ? n : i;
1701
1938
  return s < e ? e : s;
1702
1939
  }
1703
- function ge(i, t, n, s) {
1704
- return tt(
1705
- i[t] + s * (i[n] - i[t]),
1706
- i[t + 1] + s * (i[n + 1] - i[t + 1]),
1707
- i[t + 2] + s * (i[n + 2] - i[t + 2])
1940
+ function ti(o, t, n, s) {
1941
+ return rt(
1942
+ o[t] + s * (o[n] - o[t]),
1943
+ o[t + 1] + s * (o[n + 1] - o[t + 1]),
1944
+ o[t + 2] + s * (o[n + 2] - o[t + 2])
1708
1945
  );
1709
1946
  }
1710
- function Bn(i, t, n, s) {
1711
- return xe(
1712
- Math.fround(s * (s * n[0] + t[0]) + i[0]),
1713
- Math.fround(s * (s * n[1] + t[1]) + i[1]),
1714
- Math.fround(s * (s * n[2] + t[2]) + i[2])
1947
+ function us(o, t, n, s) {
1948
+ return Je(
1949
+ Math.fround(s * (s * n[0] + t[0]) + o[0]),
1950
+ Math.fround(s * (s * n[1] + t[1]) + o[1]),
1951
+ Math.fround(s * (s * n[2] + t[2]) + o[2])
1715
1952
  );
1716
1953
  }
1717
- const mt = [0, 0, 0], bt = [0, 0, 0], Wn = [0, 0, 0], ft = [0, 0, 0], Vs = 1, to = 2;
1718
- function Qn(i, t, n, s, o, e, p, c) {
1719
- if (s > 0.5 && o > 0.5 && e <= 0.5 || s < 0.5 && o < 0.5 && e >= 0.5 || !c && Me(s, o, e) !== e) {
1720
- const r = (n - i) * p, h = (t - n) * p;
1721
- return e >= s - r && e <= s + r && e >= o - h && e <= o + h ? Vs : Vs | to;
1954
+ const Rt = [0, 0, 0], At = [0, 0, 0], is = [0, 0, 0], yt = [0, 0, 0], _o = 1, Io = 2;
1955
+ function _s(o, t, n, s, i, e, a, c) {
1956
+ if (s > 0.5 && i > 0.5 && e <= 0.5 || s < 0.5 && i < 0.5 && e >= 0.5 || !c && ni(s, i, e) !== e) {
1957
+ const r = (n - o) * a, h = (t - n) * a;
1958
+ return e >= s - r && e <= s + r && e >= i - h && e <= i + h ? _o : _o | Io;
1722
1959
  }
1723
1960
  return 0;
1724
1961
  }
1725
- function no(i) {
1726
- return (i & to) !== 0;
1962
+ function Do(o) {
1963
+ return (o & Io) !== 0;
1727
1964
  }
1728
- function Me(i, t, n) {
1729
- return Math.max(Math.min(i, t), Math.min(Math.max(i, t), n));
1965
+ function ni(o, t, n) {
1966
+ return Math.max(Math.min(o, t), Math.min(Math.max(o, t), n));
1730
1967
  }
1731
- function Qt(i, t, n, s, o, e) {
1732
- const p = tt(i[n], i[n + 1], i[n + 2]);
1733
- if (Math.abs(s - 0.5) < Math.abs(p - 0.5)) return !1;
1968
+ function hn(o, t, n, s, i, e) {
1969
+ const a = rt(o[n], o[n + 1], o[n + 2]);
1970
+ if (Math.abs(s - 0.5) < Math.abs(a - 0.5)) return !1;
1734
1971
  for (let c = 0; c < 3; c++) {
1735
- const r = i[t + c] - i[t + (c + 1) % 3], h = i[n + c] - i[n + (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 = ge(i, t, n, a), y = Qn(0, 1, a, s, p, f, o, e);
1740
- if (no(y)) return !0;
1972
+ const r = o[t + c] - o[t + (c + 1) % 3], h = o[n + c] - o[n + (c + 1) % 3], p = r - h;
1973
+ if (p === 0) continue;
1974
+ const l = r / p;
1975
+ if (l > gn && l < 1 - gn) {
1976
+ const f = ti(o, t, n, l), u = _s(0, 1, l, s, a, f, i, e);
1977
+ if (Do(u)) return !0;
1741
1978
  }
1742
1979
  }
1743
1980
  return !1;
1744
1981
  }
1745
- function zs(i, t, n, s, o, e, p, c, r) {
1982
+ function xo(o, t, n, s, i, e, a, c, r) {
1746
1983
  if (!(r > 0 && r < 1)) return 0;
1747
- const h = r > p ? 0 : r, l = r > p ? r : 1;
1748
- ft[0] = i[t], ft[1] = i[t + 1], ft[2] = i[t + 2];
1749
- const a = r > p ? n : Bn(ft, mt, bt, r);
1750
- ft[0] = i[t], ft[1] = i[t + 1], ft[2] = i[t + 2];
1751
- const f = r > p ? Bn(ft, mt, bt, r) : s;
1752
- return Qn(h, l, p, a, f, c, o, e);
1753
- }
1754
- function $t(i, t, n, s, o, e, p, c, r) {
1755
- if (!(p > jt && p < 1 - jt)) return !1;
1756
- ft[0] = i[t], ft[1] = i[t + 1], ft[2] = i[t + 2];
1757
- const h = Bn(ft, mt, bt, p);
1758
- let l = Qn(0, 1, p, n, s, h, o, e);
1759
- return l |= zs(i, t, n, s, o, e, p, h, c), l |= zs(i, t, n, s, o, e, p, h, r), no(l);
1760
- }
1761
- function Hn(i, t, n, s, o, e, p, c, r, h, l, a, f) {
1762
- const y = Math.fround(i[t + h] - i[t + l]), _ = Math.fround(
1763
- Math.fround(i[n + h] - i[n + l]) + Math.fround(i[s + h] - i[s + l])
1764
- ), u = Math.fround(i[o + h] - i[o + l]), x = Math.fround(Math.fround(u - _) + y), g = Math.fround(Math.fround(_ - y) - y), A = y;
1765
- if (x === 0 || Math.abs(g) > 1e12 * Math.abs(x)) {
1766
- if (g !== 0) {
1767
- const v = -A / g;
1768
- if ($t(i, t, e, p, c, r, v, a, f)) return !0;
1984
+ const h = r > a ? 0 : r, p = r > a ? r : 1;
1985
+ yt[0] = o[t], yt[1] = o[t + 1], yt[2] = o[t + 2];
1986
+ const l = r > a ? n : us(yt, Rt, At, r);
1987
+ yt[0] = o[t], yt[1] = o[t + 1], yt[2] = o[t + 2];
1988
+ const f = r > a ? us(yt, Rt, At, r) : s;
1989
+ return _s(h, p, a, l, f, c, i, e);
1990
+ }
1991
+ function pn(o, t, n, s, i, e, a, c, r) {
1992
+ if (!(a > gn && a < 1 - gn)) return !1;
1993
+ yt[0] = o[t], yt[1] = o[t + 1], yt[2] = o[t + 2];
1994
+ const h = us(yt, Rt, At, a);
1995
+ let p = _s(0, 1, a, n, s, h, i, e);
1996
+ return p |= xo(o, t, n, s, i, e, a, h, c), p |= xo(o, t, n, s, i, e, a, h, r), Do(p);
1997
+ }
1998
+ function cs(o, t, n, s, i, e, a, c, r, h, p, l, f) {
1999
+ const u = Math.fround(o[t + h] - o[t + p]), _ = Math.fround(
2000
+ Math.fround(o[n + h] - o[n + p]) + Math.fround(o[s + h] - o[s + p])
2001
+ ), y = Math.fround(o[i + h] - o[i + p]), g = Math.fround(Math.fround(y - _) + u), M = Math.fround(Math.fround(_ - u) - u), I = u;
2002
+ if (g === 0 || Math.abs(M) > 1e12 * Math.abs(g)) {
2003
+ if (M !== 0) {
2004
+ const T = -I / M;
2005
+ if (pn(o, t, e, a, c, r, T, l, f)) return !0;
1769
2006
  }
1770
2007
  return !1;
1771
2008
  }
1772
- const m = g * g - 4 * x * A;
1773
- if (m > 0) {
1774
- const v = Math.sqrt(m), w = (-g + v) / (2 * x);
1775
- if ($t(i, t, e, p, c, r, w, a, f)) return !0;
1776
- const E = (-g - v) / (2 * x);
1777
- if ($t(i, t, e, p, c, r, E, a, f)) return !0;
1778
- } else if (m === 0) {
1779
- const v = -g / (2 * x);
1780
- if ($t(i, t, e, p, c, r, v, a, f)) return !0;
2009
+ const q = M * M - 4 * g * I;
2010
+ if (q > 0) {
2011
+ const T = Math.sqrt(q), A = (-M + T) / (2 * g);
2012
+ if (pn(o, t, e, a, c, r, A, l, f)) return !0;
2013
+ const D = (-M - T) / (2 * g);
2014
+ if (pn(o, t, e, a, c, r, D, l, f)) return !0;
2015
+ } else if (q === 0) {
2016
+ const T = -M / (2 * g);
2017
+ if (pn(o, t, e, a, c, r, T, l, f)) return !0;
1781
2018
  }
1782
2019
  return !1;
1783
2020
  }
1784
- function Zt(i, t, n, s, o, e, p, c) {
1785
- const r = tt(i[o], i[o + 1], i[o + 2]);
2021
+ function fn(o, t, n, s, i, e, a, c) {
2022
+ const r = rt(o[i], o[i + 1], o[i + 2]);
1786
2023
  if (Math.abs(e - 0.5) < Math.abs(r - 0.5)) return !1;
1787
2024
  for (let f = 0; f < 3; f++)
1788
- Wn[f] = Math.fround(
1789
- Math.fround(i[t + f] - i[n + f]) - i[s + f]
1790
- ), mt[f] = Math.fround(-i[t + f] - Wn[f]), bt[f] = Math.fround(i[o + f] + Wn[f]);
1791
- const h = bt[0] !== 0 ? -0.5 * mt[0] / bt[0] : -1, l = bt[1] !== 0 ? -0.5 * mt[1] / bt[1] : -1, a = bt[2] !== 0 ? -0.5 * mt[2] / bt[2] : -1;
1792
- return !!(Hn(
1793
- i,
2025
+ is[f] = Math.fround(
2026
+ Math.fround(o[t + f] - o[n + f]) - o[s + f]
2027
+ ), Rt[f] = Math.fround(-o[t + f] - is[f]), At[f] = Math.fround(o[i + f] + is[f]);
2028
+ const h = At[0] !== 0 ? -0.5 * Rt[0] / At[0] : -1, p = At[1] !== 0 ? -0.5 * Rt[1] / At[1] : -1, l = At[2] !== 0 ? -0.5 * Rt[2] / At[2] : -1;
2029
+ return !!(cs(
2030
+ o,
1794
2031
  t,
1795
2032
  n,
1796
2033
  s,
1797
- o,
2034
+ i,
1798
2035
  e,
1799
2036
  r,
1800
- p,
2037
+ a,
1801
2038
  c,
1802
2039
  0,
1803
2040
  1,
1804
2041
  h,
1805
- l
1806
- ) || Hn(
1807
- i,
2042
+ p
2043
+ ) || cs(
2044
+ o,
1808
2045
  t,
1809
2046
  n,
1810
2047
  s,
1811
- o,
2048
+ i,
1812
2049
  e,
1813
2050
  r,
1814
- p,
2051
+ a,
1815
2052
  c,
1816
2053
  1,
1817
2054
  2,
1818
- l,
1819
- a
1820
- ) || Hn(
1821
- i,
2055
+ p,
2056
+ l
2057
+ ) || cs(
2058
+ o,
1822
2059
  t,
1823
2060
  n,
1824
2061
  s,
1825
- o,
2062
+ i,
1826
2063
  e,
1827
2064
  r,
1828
- p,
2065
+ a,
1829
2066
  c,
1830
2067
  2,
1831
2068
  0,
1832
- a,
2069
+ l,
1833
2070
  h
1834
2071
  ));
1835
2072
  }
1836
- function de(i, t, n, s, o, e) {
1837
- const p = e / o, c = e / o, r = e * Math.SQRT2 / o;
2073
+ function si(o, t, n, s, i, e) {
2074
+ const a = e / i, c = e / i, r = e * Math.SQRT2 / i;
1838
2075
  for (let h = 0; h < s; h++)
1839
- for (let l = 0; l < n; l++) {
1840
- const a = h * n + l, f = a * 3, y = tt(t[f], t[f + 1], t[f + 2]), _ = (i[a] & Tt) !== 0, u = l > 0, x = l < n - 1, g = h > 0, A = h < s - 1, m = u ? (a - 1) * 3 : -1, v = x ? (a + 1) * 3 : -1, w = g ? (a - n) * 3 : -1, E = A ? (a + n) * 3 : -1;
1841
- let C = !1;
1842
- if (u && Qt(t, f, m, y, p, _) && (C = !0), !C && g && Qt(t, f, w, y, c, _) && (C = !0), !C && x && Qt(t, f, v, y, p, _) && (C = !0), !C && A && Qt(t, f, E, y, c, _) && (C = !0), !C && u && g) {
1843
- const F = (a - n - 1) * 3;
1844
- Zt(t, f, m, w, F, y, r, _) && (C = !0);
2076
+ for (let p = 0; p < n; p++) {
2077
+ const l = h * n + p, f = l * 3, u = rt(t[f], t[f + 1], t[f + 2]), _ = (o[l] & Yt) !== 0, y = p > 0, g = p < n - 1, M = h > 0, I = h < s - 1, q = y ? (l - 1) * 3 : -1, T = g ? (l + 1) * 3 : -1, A = M ? (l - n) * 3 : -1, D = I ? (l + n) * 3 : -1;
2078
+ let R = !1;
2079
+ if (y && hn(t, f, q, u, a, _) && (R = !0), !R && M && hn(t, f, A, u, c, _) && (R = !0), !R && g && hn(t, f, T, u, a, _) && (R = !0), !R && I && hn(t, f, D, u, c, _) && (R = !0), !R && y && M) {
2080
+ const m = (l - n - 1) * 3;
2081
+ fn(t, f, q, A, m, u, r, _) && (R = !0);
1845
2082
  }
1846
- if (!C && x && g) {
1847
- const F = (a - n + 1) * 3;
1848
- Zt(t, f, v, w, F, y, r, _) && (C = !0);
2083
+ if (!R && g && M) {
2084
+ const m = (l - n + 1) * 3;
2085
+ fn(t, f, T, A, m, u, r, _) && (R = !0);
1849
2086
  }
1850
- if (!C && u && A) {
1851
- const F = (a + n - 1) * 3;
1852
- Zt(t, f, m, E, F, y, r, _) && (C = !0);
2087
+ if (!R && y && I) {
2088
+ const m = (l + n - 1) * 3;
2089
+ fn(t, f, q, D, m, u, r, _) && (R = !0);
1853
2090
  }
1854
- if (!C && x && A) {
1855
- const F = (a + n + 1) * 3;
1856
- Zt(t, f, v, E, F, y, r, _) && (C = !0);
2091
+ if (!R && g && I) {
2092
+ const m = (l + n + 1) * 3;
2093
+ fn(t, f, T, D, m, u, r, _) && (R = !0);
1857
2094
  }
1858
- C && (i[a] |= Js);
2095
+ R && (o[l] |= Eo);
1859
2096
  }
1860
2097
  }
1861
- function be(i, t, n, s) {
1862
- const o = n * s;
1863
- for (let e = 0; e < o; e++)
1864
- if (i[e] & Js) {
1865
- const p = e * 3, c = tt(t[p], t[p + 1], t[p + 2]);
1866
- t[p] = c, t[p + 1] = c, t[p + 2] = c;
2098
+ function oi(o, t, n, s) {
2099
+ const i = n * s;
2100
+ for (let e = 0; e < i; e++)
2101
+ if (o[e] & Eo) {
2102
+ const a = e * 3, c = rt(t[a], t[a + 1], t[a + 2]);
2103
+ t[a] = c, t[a + 1] = c, t[a + 2] = c;
1867
2104
  }
1868
2105
  }
1869
- function tt(i, t, n) {
1870
- return Math.max(Math.min(i, t), Math.min(Math.max(i, t), n));
2106
+ function rt(o, t, n) {
2107
+ return Math.max(Math.min(o, t), Math.min(Math.max(o, t), n));
2108
+ }
2109
+ const ei = 3, ii = 0n, go = 16;
2110
+ function ci(o, t, n, s = !0) {
2111
+ if (s && ve(o), o.contours.length === 0) return null;
2112
+ const i = ri(o), e = t, a = n, c = Math.max(1, Math.ceil((i.maxX - i.minX) * e)) + 2 * a, r = Math.max(1, Math.ceil((i.maxY - i.minY) * e)) + 2 * a, h = a / e - i.minX, p = a / e - i.minY;
2113
+ xe(o), Ne(o, ei, ii);
2114
+ const l = new Float32Array(c * r * 3);
2115
+ return Ye(o, c, r, e, h, p, a, l), $e(l, o, c, r, e, h, p), je(l, o, c, r, e, h, p, a), {
2116
+ msdf: l,
2117
+ w: c,
2118
+ h: r,
2119
+ planeLeft: -h,
2120
+ planeBottom: -p,
2121
+ planeRight: c / e - h,
2122
+ planeTop: r / e - p
2123
+ };
2124
+ }
2125
+ const rs = [0, 0];
2126
+ function ri(o) {
2127
+ let t = 1 / 0, n = 1 / 0, s = -1 / 0, i = -1 / 0;
2128
+ for (const e of o.contours)
2129
+ for (const a of e)
2130
+ for (let c = 0; c <= go; c++) {
2131
+ a.point(c / go, rs);
2132
+ const r = rs[0], h = rs[1];
2133
+ r < t && (t = r), h < n && (n = h), r > s && (s = r), h > i && (i = h);
2134
+ }
2135
+ return { minX: t, minY: n, maxX: s, maxY: i };
1871
2136
  }
1872
- function we(i) {
2137
+ function ai(o) {
1873
2138
  let t = 0, n = 0;
1874
- for (const c of i)
2139
+ for (const c of o)
1875
2140
  t += c.w * c.h, n = Math.max(n, c.w);
1876
- i.sort((c, r) => r.h - c.h);
1877
- const o = [{ x: 0, y: 0, w: Math.max(Math.ceil(Math.sqrt(t / 0.95)), n), h: 1 / 0 }];
1878
- let e = 0, p = 0;
1879
- for (const c of i)
1880
- for (let r = o.length - 1; r >= 0; r--) {
1881
- const h = o[r];
2141
+ o.sort((c, r) => r.h - c.h);
2142
+ const i = [{ x: 0, y: 0, w: Math.max(Math.ceil(Math.sqrt(t / 0.95)), n), h: 1 / 0 }];
2143
+ let e = 0, a = 0;
2144
+ for (const c of o)
2145
+ for (let r = i.length - 1; r >= 0; r--) {
2146
+ const h = i[r];
1882
2147
  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), e = Math.max(e, c.x + c.w), c.w === h.w && c.h === h.h) {
1884
- const l = o.pop();
1885
- l && r < o.length && (o[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) : (o.push({
2148
+ if (c.x = h.x, c.y = h.y, a = Math.max(a, c.y + c.h), e = Math.max(e, c.x + c.w), c.w === h.w && c.h === h.h) {
2149
+ const p = i.pop();
2150
+ p && r < i.length && (i[r] = p);
2151
+ } 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
2152
  x: h.x + c.w,
1888
2153
  y: h.y,
1889
2154
  w: h.w - c.w,
@@ -1895,20 +2160,24 @@ function we(i) {
1895
2160
  return {
1896
2161
  w: e,
1897
2162
  // container width
1898
- h: p,
2163
+ h: a,
1899
2164
  // container height
1900
- fill: t / (e * p) || 0
2165
+ fill: t / (e * a) || 0
1901
2166
  // space utilization
1902
2167
  };
1903
2168
  }
1904
- const Ae = 3, Ee = 0n, Bs = 4, Ks = 16;
1905
- function Vn(i) {
1906
- const t = i < 0 ? 0 : i > 1 ? 1 : i;
2169
+ const Mo = 4;
2170
+ function as(o) {
2171
+ const t = o < 0 ? 0 : o > 1 ? 1 : o;
1907
2172
  return ~Math.trunc(255.5 - 255 * t) & 255;
1908
2173
  }
1909
- class De {
2174
+ class li {
2175
+ /**
2176
+ * @param font Font for the glyph/layout methods; `null` for a shapes-only atlas.
2177
+ * @param opts Generation scale and distance range.
2178
+ */
1910
2179
  constructor(t, n = {}) {
1911
- this._width = 0, this._height = 0, this._pixels = new Uint8Array(0), this._cache = /* @__PURE__ */ new Map(), this._cacheByGid = /* @__PURE__ */ new Map(), this._font = t, this._pxPerEm = n.pixelsPerEm ?? 40, this._pxrange = n.pxrange ?? 4, this.pxrangeEm = this._pxrange / this._pxPerEm;
2180
+ 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
2181
  }
1913
2182
  /** Packed atlas texture width in texels (chosen by potpack). */
1914
2183
  get width() {
@@ -1922,24 +2191,19 @@ class De {
1922
2191
  get texture() {
1923
2192
  return this._pixels;
1924
2193
  }
2194
+ /** {@link Atlas.texture} as raw float RGB, not clamped to [0, 1], for zoom that
2195
+ * outruns 8 bits; `null` without the `float` option. */
2196
+ get floatTexture() {
2197
+ return this._floats;
2198
+ }
1925
2199
  /**
1926
2200
  * Batched generate + pack. Generates MSDFs for any codepoints not
1927
2201
  * already cached, then runs potpack **once** over the whole cache.
1928
2202
  * Returns the `AtlasGlyph` for each requested codepoint, in order.
1929
2203
  */
1930
2204
  glyphs(t) {
1931
- const n = [];
1932
- let s = 0;
1933
- for (const o of t) {
1934
- const e = this._cache.get(o);
1935
- if (e) {
1936
- n.push(e.glyph);
1937
- continue;
1938
- }
1939
- const p = this._generateForGlyphId(this._font.glyphId(o));
1940
- this._cache.set(o, p), n.push(p.glyph), s++;
1941
- }
1942
- return s > 0 && this._repack(), n;
2205
+ const n = this._requireFont();
2206
+ return this.glyphsByIndex(Array.from(t, (s) => n.glyphId(s)));
1943
2207
  }
1944
2208
  /**
1945
2209
  * Single-glyph convenience: generates + packs if missing. Repacks the
@@ -1954,23 +2218,20 @@ class De {
1954
2218
  * Unicode codepoint — the {@link Atlas.glyphs} twin for glyphs with no
1955
2219
  * reachable cmap entry. Icon fonts (e.g. Lucide) commonly have far more
1956
2220
  * 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).
2221
+ * generated. Shares one cache and one packed atlas texture with
2222
+ * {@link Atlas.glyphs}, which maps codepoints to glyph indices first.
1962
2223
  */
1963
2224
  glyphsByIndex(t) {
1964
2225
  const n = [];
1965
2226
  let s = 0;
1966
- for (const o of t) {
1967
- const e = this._cacheByGid.get(o);
2227
+ for (const i of t) {
2228
+ const e = this._cache.get(i);
1968
2229
  if (e) {
1969
2230
  n.push(e.glyph);
1970
2231
  continue;
1971
2232
  }
1972
- const p = this._generateForGlyphId(o);
1973
- this._cacheByGid.set(o, p), n.push(p.glyph), s++;
2233
+ const a = this._generateForGlyphId(i);
2234
+ this._cache.set(i, a), n.push(a.glyph), s++;
1974
2235
  }
1975
2236
  return s > 0 && this._repack(), n;
1976
2237
  }
@@ -1981,38 +2242,46 @@ class De {
1981
2242
  return this.glyphsByIndex([t])[0];
1982
2243
  }
1983
2244
  /**
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.
2245
+ * Batched generate + pack for arbitrary shapes (e.g. from `parseSvg`),
2246
+ * keyed by a caller-chosen string — the {@link Atlas.glyphs} twin for
2247
+ * non-font input. Shapes must be y-up, in the units `pixelsPerEm` scales
2248
+ * (`parseSvg` makes 1 unit = the viewBox height). A new shape is mutated
2249
+ * (overlaps merged, normalized + coloured); a cached key ignores the shape
2250
+ * passed. `advance` is 0. Shares the one packed texture with the glyph cache.
1987
2251
  */
2252
+ shapes(t) {
2253
+ const n = [];
2254
+ let s = 0;
2255
+ for (const [i, e] of t) {
2256
+ let a = this._cacheByKey.get(i);
2257
+ a || (a = this._generate(e, 0), this._cacheByKey.set(i, a), s++), n.push(a.glyph);
2258
+ }
2259
+ return s > 0 && this._repack(), n;
2260
+ }
2261
+ /** The font, or a clear error for glyph/layout calls on a shapes-only atlas. */
2262
+ _requireFont() {
2263
+ if (!this._font) throw new Error("Atlas: no font — this atlas only supports shapes()");
2264
+ return this._font;
2265
+ }
2266
+ /** Generates the MSDF for `glyphId`. Does not cache and does not pack. */
1988
2267
  _generateForGlyphId(t) {
1989
- const n = this._font, s = n.metrics.unitsPerEm, o = n.advance(t) / s, e = n.shape(t);
1990
- if (Xo(e, s), e.contours.length === 0)
1991
- return { glyph: {
1992
- x: 0,
1993
- y: 0,
1994
- w: 0,
1995
- h: 0,
1996
- advance: o,
1997
- planeLeft: 0,
1998
- planeBottom: 0,
1999
- planeRight: 0,
2000
- planeTop: 0
2001
- }, msdf: null };
2002
- const p = qe(e), 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
- zo(e), ne(e, Ae, Ee);
2004
- const y = new Float32Array(h * l * 3);
2005
- return ee(e, h, l, c, a, f, r, y), fe(y, e, h, l, c, a, f), ye(y, e, h, l, c, a, f, r), { glyph: {
2268
+ const n = this._requireFont(), s = n.metrics.unitsPerEm, i = n.shape(t);
2269
+ return fe(i, s), this._generate(i, n.advance(t) / s);
2270
+ }
2271
+ /** Generates one entry from an em-unit shape. Does not cache or pack. */
2272
+ _generate(t, n) {
2273
+ const s = ci(t, this._pxPerEm, this._pxrange);
2274
+ return { glyph: {
2006
2275
  x: 0,
2007
2276
  y: 0,
2008
- w: h,
2009
- h: l,
2010
- advance: o,
2011
- planeLeft: -a,
2012
- planeBottom: -f,
2013
- planeRight: h / c - a,
2014
- planeTop: l / c - f
2015
- }, msdf: y };
2277
+ w: s ? s.w : 0,
2278
+ h: s ? s.h : 0,
2279
+ advance: n,
2280
+ planeLeft: s ? s.planeLeft : 0,
2281
+ planeBottom: s ? s.planeBottom : 0,
2282
+ planeRight: s ? s.planeRight : 0,
2283
+ planeTop: s ? s.planeTop : 0
2284
+ }, msdf: s ? s.msdf : null };
2016
2285
  }
2017
2286
  /**
2018
2287
  * Lays out `text` left-to-right on a single line, applying kerning.
@@ -2025,15 +2294,15 @@ class De {
2025
2294
  const n = [];
2026
2295
  for (const r of t) n.push(r.codePointAt(0));
2027
2296
  this.glyphs(n);
2028
- const s = [], o = this._font, e = o.metrics.unitsPerEm;
2029
- let p = 0, c = -1;
2297
+ const s = [], i = this._requireFont(), e = i.metrics.unitsPerEm;
2298
+ let a = 0, c = -1;
2030
2299
  for (const r of n) {
2031
- const h = o.glyphId(r);
2032
- c >= 0 && (p += o.kerning(c, h) / e);
2033
- const l = this._cache.get(r).glyph;
2034
- s.push({ glyph: l, penX: p, penY: 0 }), p += l.advance, c = h;
2300
+ const h = i.glyphId(r);
2301
+ c >= 0 && (a += i.kerning(c, h) / e);
2302
+ const p = this._cache.get(h).glyph;
2303
+ s.push({ glyph: p, penX: a, penY: 0 }), a += p.advance, c = h;
2035
2304
  }
2036
- return { glyphs: s, widthEm: p };
2305
+ return { glyphs: s, widthEm: a };
2037
2306
  }
2038
2307
  /**
2039
2308
  * Lays out `text` as one or more `\n`-separated lines, each run through
@@ -2051,90 +2320,84 @@ class De {
2051
2320
  * cropping.
2052
2321
  */
2053
2322
  layoutMultiline(t) {
2054
- const n = this._font, s = n.metrics.unitsPerEm, o = (n.metrics.ascender - n.metrics.descender + n.metrics.lineGap) / s, e = t.split(`
2055
- `), p = [];
2323
+ const n = this._requireFont(), s = n.metrics.unitsPerEm, i = (n.metrics.ascender - n.metrics.descender + n.metrics.lineGap) / s, e = t.split(`
2324
+ `), a = [];
2056
2325
  let c = 0;
2057
2326
  for (let r = 0; r < e.length; r++) {
2058
- const { glyphs: h, widthEm: l } = this.layout(e[r]), a = -r * o;
2059
- for (const f of h) p.push({ glyph: f.glyph, penX: f.penX, penY: a });
2060
- l > c && (c = l);
2327
+ const { glyphs: h, widthEm: p } = this.layout(e[r]), l = -r * i;
2328
+ for (const f of h) a.push({ glyph: f.glyph, penX: f.penX, penY: l });
2329
+ p > c && (c = p);
2061
2330
  }
2062
- return { glyphs: p, widthEm: c, heightEm: e.length * o };
2331
+ return { glyphs: a, widthEm: c, heightEm: e.length * i };
2063
2332
  }
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. */
2333
+ /** Repacks every cached entry (glyph-index- and string-keyed caches — one
2334
+ * shared texture) with potpack, reallocates the texture, and re-blits each
2335
+ * MSDF at its assigned rect. Called by `glyphsByIndex()`/`shapes()` after
2336
+ * any batch of new inserts — once per batch.
2337
+ *
2338
+ * Each cell gets a 1-texel gutter of zeros on its right and bottom, so a
2339
+ * quad covering the whole cell can sample its full rect: linear filtering
2340
+ * at the edge blends with zeros (further outside the glyph), never with a
2341
+ * neighbouring glyph's texels. */
2068
2342
  _repack() {
2069
2343
  const t = [];
2070
- for (const o of this._cache.values())
2071
- o.msdf !== null && t.push({ w: o.glyph.w, h: o.glyph.h, x: 0, y: 0, entry: o });
2072
- for (const o of this._cacheByGid.values())
2073
- o.msdf !== null && t.push({ w: o.glyph.w, h: o.glyph.h, x: 0, y: 0, entry: o });
2074
- const { w: n, h: s } = we(t);
2075
- this._width = n, this._height = s, this._pixels = new Uint8Array(n * s * Bs);
2076
- for (const o of t)
2077
- o.entry.glyph.x = o.x, o.entry.glyph.y = o.y, this._blit(o.entry.msdf, o.x, o.y, o.w, o.h);
2344
+ for (const i of [this._cache, this._cacheByKey])
2345
+ for (const { glyph: e, msdf: a } of i.values())
2346
+ a && t.push({ w: e.w + 1, h: e.h + 1, x: 0, y: 0, glyph: e, msdf: a });
2347
+ const { w: n, h: s } = ai(t);
2348
+ this._width = n, this._height = s, this._pixels = new Uint8Array(n * s * Mo), this._floats && (this._floats = new Float32Array(n * s * 3));
2349
+ for (const i of t)
2350
+ i.glyph.x = i.x, i.glyph.y = i.y, this._blit(i.msdf, i.x, i.y, i.glyph.w, i.glyph.h);
2078
2351
  }
2079
2352
  /**
2080
2353
  * Quantise `msdf` (float, y-up, row 0 = bottom, w×h×3) into `_pixels` at
2081
2354
  * atlas rect (`ax`, `ay`, `w`, `h`) — the single y-flip point.
2082
2355
  */
2083
- _blit(t, n, s, o, e) {
2084
- const p = this._width, c = this._pixels;
2085
- for (let r = 0; r < e; r++) {
2086
- const h = s + (e - 1 - r);
2087
- for (let l = 0; l < o; l++) {
2088
- const a = (r * o + l) * 3, f = (h * p + (n + l)) * Bs;
2089
- c[f] = Vn(t[a]), c[f + 1] = Vn(t[a + 1]), c[f + 2] = Vn(t[a + 2]), c[f + 3] = 255;
2356
+ _blit(t, n, s, i, e) {
2357
+ var r;
2358
+ const a = this._width, c = this._pixels;
2359
+ for (let h = 0; h < e; h++) {
2360
+ const p = s + (e - 1 - h);
2361
+ (r = this._floats) == null || r.set(t.subarray(h * i * 3, (h + 1) * i * 3), (p * a + n) * 3);
2362
+ for (let l = 0; l < i; l++) {
2363
+ const f = (h * i + l) * 3, u = (p * a + (n + l)) * Mo;
2364
+ c[u] = as(t[f]), c[u + 1] = as(t[f + 1]), c[u + 2] = as(t[f + 2]), c[u + 3] = 255;
2090
2365
  }
2091
2366
  }
2092
2367
  }
2093
2368
  }
2094
- const zn = [0, 0];
2095
- function qe(i) {
2096
- let t = 1 / 0, n = 1 / 0, s = -1 / 0, o = -1 / 0;
2097
- for (const e of i.contours)
2098
- for (const p of e)
2099
- for (let c = 0; c <= Ks; c++) {
2100
- p.point(c / Ks, zn);
2101
- const r = zn[0], h = zn[1];
2102
- r < t && (t = r), h < n && (n = h), r > s && (s = r), h > o && (o = h);
2103
- }
2104
- return { minX: t, minY: n, maxX: s, maxY: o };
2105
- }
2106
- const Qs = /* @__PURE__ */ new Map();
2107
- self.onmessage = (i) => {
2108
- const t = i.data;
2369
+ const wo = /* @__PURE__ */ new Map();
2370
+ self.onmessage = (o) => {
2371
+ const t = o.data;
2109
2372
  if (t.type === "build")
2110
2373
  try {
2111
- let n = Qs.get(t.fontKey);
2374
+ let n = wo.get(t.fontKey);
2112
2375
  if (!n) {
2113
2376
  if (!t.font)
2114
2377
  throw new Error(
2115
2378
  `atlas-worker: no cached font for fontKey "${t.fontKey}" and no \`font\` bytes provided on this request`
2116
2379
  );
2117
- n = new Yo(t.font), Qs.set(t.fontKey, n);
2380
+ n = new pe(t.font), wo.set(t.fontKey, n);
2118
2381
  }
2119
- const s = performance.now(), o = new De(n, { pixelsPerEm: t.pixelsPerEm, pxrange: t.pxrange }), { glyphs: e, widthEm: p, heightEm: c } = o.layoutMultiline(t.text), r = performance.now() - s, h = e.map(({ glyph: f, penX: y, penY: _ }) => ({
2382
+ const s = performance.now(), i = new li(n, { pixelsPerEm: t.pixelsPerEm, pxrange: t.pxrange }), { glyphs: e, widthEm: a, heightEm: c } = i.layoutMultiline(t.text), r = performance.now() - s, h = e.map(({ glyph: f, penX: u, penY: _ }) => ({
2120
2383
  ...f,
2121
- penX: y,
2384
+ penX: u,
2122
2385
  penY: _
2123
- })), l = o.texture.slice().buffer, a = {
2386
+ })), p = i.texture.slice().buffer, l = {
2124
2387
  type: "built",
2125
2388
  id: t.id,
2126
2389
  pixelsPerEm: t.pixelsPerEm,
2127
2390
  pxrange: t.pxrange,
2128
- pxrangeEm: o.pxrangeEm,
2129
- width: o.width,
2130
- height: o.height,
2131
- texture: l,
2391
+ pxrangeEm: i.pxrangeEm,
2392
+ width: i.width,
2393
+ height: i.height,
2394
+ texture: p,
2132
2395
  glyphs: h,
2133
- widthEm: p,
2396
+ widthEm: a,
2134
2397
  heightEm: c,
2135
2398
  genMs: r
2136
2399
  };
2137
- self.postMessage(a, [l]);
2400
+ self.postMessage(l, [p]);
2138
2401
  } catch (n) {
2139
2402
  const s = { type: "error", id: t.id, message: String(n) };
2140
2403
  self.postMessage(s);