msdfgen-ts 0.2.0 → 0.3.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 wt {
1
+ class St {
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 wt {
78
78
  return this._view.getInt16(t, !1);
79
79
  }
80
80
  }
81
- function Co(o, t) {
82
- const n = new wt(o, t);
81
+ function Qi(s, t) {
82
+ const n = new St(s, t);
83
83
  n.skip(2);
84
- const s = n.u16();
84
+ const e = n.u16();
85
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
- let f = -1;
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 });
86
+ for (let r = 0; r < e; r++) {
87
+ const c = n.u16(), a = n.u16(), l = n.u32(), h = t + l, f = n.peekU16(h);
88
+ let u = -1;
89
+ c === 3 && a === 10 && f === 12 ? u = 5 : c === 0 && a === 6 && f === 12 ? u = 4 : c === 0 && a === 4 && f === 12 ? u = 3 : c === 3 && a === 1 && f === 4 ? u = 2 : c === 0 && a <= 3 && f === 4 && (u = 1), u > ((i == null ? void 0 : i.priority) ?? -1) && (i = { priority: u, subtableAbsOffset: h });
90
90
  }
91
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;
92
+ const o = n.peekU16(i.subtableAbsOffset);
93
+ return o === 12 ? to(s, i.subtableAbsOffset) : o === 4 ? no(s, i.subtableAbsOffset) : () => 0;
94
94
  }
95
- function Fo(o, t) {
96
- const n = new wt(o, t);
95
+ function to(s, t) {
96
+ const n = new St(s, t);
97
97
  n.skip(2), n.skip(2), n.skip(4), n.skip(4);
98
- const s = n.u32(), i = new Uint32Array(s), e = new Uint32Array(s), a = new Uint32Array(s);
99
- for (let c = 0; c < s; c++)
100
- i[c] = n.u32(), e[c] = n.u32(), a[c] = n.u32();
98
+ const e = n.u32(), i = new Uint32Array(e), o = new Uint32Array(e), r = new Uint32Array(e);
99
+ for (let c = 0; c < e; c++)
100
+ i[c] = n.u32(), o[c] = n.u32(), r[c] = n.u32();
101
101
  return (c) => {
102
- let r = 0, h = s - 1;
103
- for (; r <= h; ) {
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);
102
+ let a = 0, l = e - 1;
103
+ for (; a <= l; ) {
104
+ const h = a + l >>> 1, f = i[h] ?? 0, u = o[h] ?? 0;
105
+ if (c < f) l = h - 1;
106
+ else if (c > u) a = h + 1;
107
+ else return (r[h] ?? 0) + (c - f);
108
108
  }
109
109
  return 0;
110
110
  };
111
111
  }
112
- function Ro(o, t) {
113
- const n = new wt(o, t);
112
+ function no(s, t) {
113
+ const n = new St(s, t);
114
114
  n.skip(2), n.skip(2), n.skip(2);
115
115
  const i = n.u16() >>> 1;
116
116
  n.skip(6);
117
- const e = new Uint16Array(i);
118
- for (let l = 0; l < i; l++) e[l] = n.u16();
117
+ const o = new Uint16Array(i);
118
+ for (let f = 0; f < i; f++) o[f] = n.u16();
119
119
  n.skip(2);
120
- const a = new Uint16Array(i);
121
- for (let l = 0; l < i; l++) a[l] = n.u16();
120
+ const r = new Uint16Array(i);
121
+ for (let f = 0; f < i; f++) r[f] = n.u16();
122
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
- f = _ + 1;
135
- else if (l < (a[_] ?? 0))
136
- u = _ - 1;
123
+ for (let f = 0; f < i; f++) c[f] = n.i16();
124
+ const a = new Int32Array(i), l = new Uint16Array(i);
125
+ for (let f = 0; f < i; f++)
126
+ a[f] = n.pos, l[f] = n.u16();
127
+ const h = new DataView(s);
128
+ return (f) => {
129
+ if (f > 65535) return 0;
130
+ let u = 0, p = i - 1;
131
+ for (; u <= p; ) {
132
+ const y = u + p >>> 1, _ = o[y] ?? 0;
133
+ if (f > _)
134
+ u = y + 1;
135
+ else if (f < (r[y] ?? 0))
136
+ p = y - 1;
137
137
  else {
138
- if ((e[_] ?? 0) === 65535) return 0;
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;
138
+ if ((o[y] ?? 0) === 65535) return 0;
139
+ const x = l[y] ?? 0, b = c[y] ?? 0, M = r[y] ?? 0;
140
+ if (x === 0)
141
+ return f + b & 65535;
142
+ const k = (a[y] ?? 0) + x + (f - M) * 2, w = h.getUint16(k, !1);
143
+ return w === 0 ? 0 : w + b & 65535;
144
144
  }
145
145
  }
146
146
  return 0;
147
147
  };
148
148
  }
149
- function To(o, t) {
150
- const n = new wt(o, t);
149
+ function eo(s, t) {
150
+ const n = new St(s, t);
151
151
  n.skip(4), n.skip(4), n.skip(4), n.skip(4), n.skip(2);
152
- const s = n.u16();
152
+ const e = n.u16();
153
153
  n.skip(16), n.skip(8), n.skip(2), n.skip(2), n.skip(2);
154
154
  const i = n.i16();
155
- return { unitsPerEm: s, indexToLocFormat: i };
155
+ return { unitsPerEm: e, indexToLocFormat: i };
156
156
  }
157
- function So(o, t) {
158
- const n = new wt(o, t);
157
+ function so(s, t) {
158
+ const n = new St(s, t);
159
159
  n.skip(4);
160
- const s = n.i16(), i = n.i16(), e = n.i16();
160
+ const e = n.i16(), i = n.i16(), o = 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 a = n.u16();
163
- return { ascender: s, descender: i, lineGap: e, numberOfHMetrics: a };
162
+ const r = n.u16();
163
+ return { ascender: e, descender: i, lineGap: o, numberOfHMetrics: r };
164
164
  }
165
- function Lo(o, t, n, s) {
166
- const i = new wt(o, t), e = [];
167
- let a = 0;
168
- for (let c = 0; c < s; c++) {
169
- const r = i.u16(), h = i.i16();
170
- e[c] = { advanceWidth: r, lsb: h }, a = r;
165
+ function io(s, t, n, e) {
166
+ const i = new St(s, t), o = [];
167
+ let r = 0;
168
+ for (let c = 0; c < e; c++) {
169
+ const a = i.u16(), l = i.i16();
170
+ o[c] = { advanceWidth: a, lsb: l }, r = a;
171
171
  }
172
- for (let c = s; c < n; c++) {
173
- const r = i.i16();
174
- e[c] = { advanceWidth: a, lsb: r };
172
+ for (let c = e; c < n; c++) {
173
+ const a = i.i16();
174
+ o[c] = { advanceWidth: r, lsb: a };
175
175
  }
176
- return e;
176
+ return o;
177
177
  }
178
- function Po(o, t, n, s) {
179
- const i = new wt(o, t), e = n + 1, a = [];
180
- if (s === 0)
181
- for (let c = 0; c < e; c++) a[c] = i.u16() * 2;
178
+ function oo(s, t, n, e) {
179
+ const i = new St(s, t), o = n + 1, r = [];
180
+ if (e === 0)
181
+ for (let c = 0; c < o; c++) r[c] = i.u16() * 2;
182
182
  else
183
- for (let c = 0; c < e; c++) a[c] = i.u32();
184
- return a;
183
+ for (let c = 0; c < o; c++) r[c] = i.u32();
184
+ return r;
185
185
  }
186
- function Oo(o, t) {
187
- const n = new wt(o, t);
186
+ function ro(s, t) {
187
+ const n = new St(s, t);
188
188
  return n.skip(4), { numGlyphs: n.u16() };
189
189
  }
190
- function No(o, t, n, s) {
191
- return o * n + t * s;
190
+ function co(s, t, n, e) {
191
+ return s * n + t * e;
192
192
  }
193
- function z(o, t, n, s) {
194
- return o * s - t * n;
193
+ function z(s, t, n, e) {
194
+ return s * e - t * n;
195
195
  }
196
- function Go(o, t, n) {
197
- return (1 - n) * o + n * t;
196
+ function ao(s, t, n) {
197
+ return (1 - n) * s + n * t;
198
198
  }
199
- function pt(o) {
200
- return +(o > 0) - +(o < 0);
199
+ function pt(s) {
200
+ return +(s > 0) - +(s < 0);
201
201
  }
202
- function qt(o) {
203
- return 2 * +(o > 0) - 1;
202
+ function Nt(s) {
203
+ return 2 * +(s > 0) - 1;
204
204
  }
205
- function bo(o, t, n, s) {
205
+ function Ri(s, t, n, e) {
206
206
  if (t === 0 || Math.abs(n) > 1e12 * Math.abs(t))
207
- return n === 0 ? s === 0 ? -1 : 0 : (o[0] = -s / n, 1);
208
- const i = n * n - 4 * t * s;
207
+ return n === 0 ? e === 0 ? -1 : 0 : (s[0] = -e / n, 1);
208
+ const i = n * n - 4 * t * e;
209
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;
210
+ const o = Math.sqrt(i);
211
+ return s[0] = (-n + o) / (2 * t), s[1] = (-n - o) / (2 * t), 2;
212
212
  } else if (i === 0)
213
- return o[0] = -n / (2 * t), 1;
213
+ return s[0] = -n / (2 * t), 1;
214
214
  return 0;
215
215
  }
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
- if (c < r) {
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;
216
+ function lo(s, t, n, e) {
217
+ const i = t * t, o = 1 / 9 * (i - 3 * n), r = 1 / 54 * (t * (2 * i - 9 * n) + 27 * e), c = r * r, a = o * o * o, l = t * (1 / 3);
218
+ if (c < a) {
219
+ let h = r / Math.sqrt(a);
220
+ h < -1 && (h = -1), h > 1 && (h = 1), h = Math.acos(h);
221
+ const f = -2 * Math.sqrt(o);
222
+ return s[0] = f * Math.cos(1 / 3 * h) - l, s[1] = f * Math.cos(1 / 3 * (h + 2 * Math.PI)) - l, s[2] = f * Math.cos(1 / 3 * (h - 2 * Math.PI)) - l, 3;
223
223
  } else {
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;
224
+ const h = (r < 0 ? 1 : -1) * Math.pow(Math.abs(r) + Math.sqrt(c - a), 0.3333333333333333), f = h === 0 ? 0 : o / h;
225
+ return s[0] = h + f - l, h === f || Math.abs(h - f) < 1e-12 * Math.abs(h + f) ? (s[1] = -0.5 * (h + f) - l, 2) : 1;
226
226
  }
227
227
  }
228
- function Yo(o, t, n, s, i) {
228
+ function ho(s, t, n, e, i) {
229
229
  if (t !== 0) {
230
- const e = n / t;
231
- if (Math.abs(e) < 1e6)
232
- return Uo(o, e, s / t, i / t);
233
- }
234
- return bo(o, n, s, i);
235
- }
236
- const Xo = 24;
237
- function Bt(o, t, n, s) {
238
- return ((s + o) * s + t) * s + n;
239
- }
240
- function Wo(o, t, n, s, i, e, a) {
241
- const c = e < 0;
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;
230
+ const o = n / t;
231
+ if (Math.abs(o) < 1e6)
232
+ return lo(s, o, e / t, i / t);
233
+ }
234
+ return Ri(s, n, e, i);
235
+ }
236
+ const fo = 24;
237
+ function _n(s, t, n, e) {
238
+ return ((e + s) * e + t) * e + n;
239
+ }
240
+ function uo(s, t, n, e, i, o, r) {
241
+ const c = o < 0;
242
+ let a = e - o * (i - e) / (r - o);
243
+ a > e && a < i || (a = 0.5 * (e + i));
244
+ for (let l = 0; l < fo; l++) {
245
+ const h = _n(s, t, n, a);
246
+ if (h === 0) return a;
247
+ h < 0 === c ? e = a : i = a;
248
+ const f = (3 * a + 2 * s) * a + t;
249
+ let u = a - h / f;
250
+ u > e && u < i || (u = 0.5 * (e + i));
251
+ const p = u - a;
252
+ if (a = u, (p < 0 ? -p : p) <= 1e-15 * (a < 0 ? -a : a)) break;
253
253
  }
254
- return r;
254
+ return a;
255
255
  }
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;
256
+ function Dn(s, t, n, e, i, o, r, c, a) {
257
+ return o === 0 ? c[a++] = e : o < 0 != r < 0 && (c[a++] = uo(s, t, n, e, i, o, r)), a;
258
258
  }
259
- function Ho(o, t, n, s, i, e) {
260
- let a = 0;
261
- if (o === 0) {
259
+ function po(s, t, n, e, i, o) {
260
+ let r = 0;
261
+ if (s === 0) {
262
262
  if (t === 0) return 0;
263
- const f = -n / t;
264
- return f >= s && f <= i && (e[a++] = f), a;
263
+ const u = -n / t;
264
+ return u >= e && u <= i && (o[r++] = u), r;
265
265
  }
266
- const c = t * t - 4 * o * n;
266
+ const c = t * t - 4 * s * n;
267
267
  if (c < 0) return 0;
268
- const r = Math.sqrt(c), h = -0.5 * (t + (t < 0 ? -r : r));
269
- let p, l;
270
- if (h === 0)
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
- }
276
- return p >= s && p <= i && (e[a++] = p), l !== p && l >= s && l <= i && (e[a++] = l), a;
277
- }
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
- t *= c, n *= c, s *= c;
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);
268
+ const a = Math.sqrt(c), l = -0.5 * (t + (t < 0 ? -a : a));
269
+ let h, f;
270
+ if (l === 0)
271
+ h = 0, f = 0;
272
+ else if (h = l / s, f = n / l, h > f) {
273
+ const u = h;
274
+ h = f, f = u;
275
+ }
276
+ return h >= e && h <= i && (o[r++] = h), f !== h && f >= e && f <= i && (o[r++] = f), r;
277
+ }
278
+ function _o(s, t, n, e, i, o, r) {
279
+ if (s === 0) return po(t, n, e, i, o, r);
280
+ const c = 1 / s;
281
+ t *= c, n *= c, e *= c;
282
+ const a = _n(t, n, e, i), l = _n(t, n, e, o), h = t * t - 3 * n;
283
+ let f = 0;
284
+ if (h <= 0)
285
+ f = Dn(t, n, e, i, o, a, l, r, 0);
286
286
  else {
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;
287
+ const u = Math.sqrt(h) / 3, p = -t / 3, y = p - u, _ = p + u;
288
+ let g = i, x = a;
289
+ if (y > i && y < o) {
290
+ const b = _n(t, n, e, y);
291
+ f = Dn(t, n, e, g, y, x, b, r, f), g = y, x = b;
292
292
  }
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;
293
+ if (_ > i && _ < o) {
294
+ const b = _n(t, n, e, _);
295
+ f = Dn(t, n, e, g, _, x, b, r, f), g = _, x = b;
296
296
  }
297
- l = rn(t, n, s, g, e, M, h, a, l);
297
+ f = Dn(t, n, e, g, o, x, l, r, f);
298
298
  }
299
- return h === 0 && (a[l++] = e), l;
299
+ return l === 0 && (r[f++] = o), f;
300
300
  }
301
- const lt = 0, ct = 1, Gt = 2, $s = 4, Bo = 4, X = [0, 0, 0];
302
- class et {
301
+ const ft = 0, at = 1, nn = 2, Vs = 4, yo = 4, K = [0, 0, 0];
302
+ class ot {
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 et {
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, 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;
314
+ constructor(t, n, e, i, o, r, c, a, l) {
315
+ this.type = t, this.p0x = n, this.p0y = e, this.p1x = i, this.p1y = o, this.p2x = r, this.p2y = c, this.p3x = a, this.p3y = l, 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 lt:
320
+ case ft:
321
321
  return this.p1x;
322
- case ct:
322
+ case at:
323
323
  return this.p2x;
324
324
  default:
325
325
  return this.p3x;
@@ -328,9 +328,9 @@ class et {
328
328
  /** Endpoint y. */
329
329
  endY() {
330
330
  switch (this.type) {
331
- case lt:
331
+ case ft:
332
332
  return this.p1y;
333
- case ct:
333
+ case at:
334
334
  return this.p2y;
335
335
  default:
336
336
  return this.p3y;
@@ -344,20 +344,20 @@ class et {
344
344
  * @param out Two-element array [x, y] to write into (reuse to avoid allocation).
345
345
  */
346
346
  point(t, n) {
347
- const s = t;
347
+ const e = t;
348
348
  switch (this.type) {
349
- case lt: {
350
- n[0] = this.p0x + s * (this.p1x - this.p0x), n[1] = this.p0y + s * (this.p1y - this.p0y);
349
+ case ft: {
350
+ n[0] = this.p0x + e * (this.p1x - this.p0x), n[1] = this.p0y + e * (this.p1y - this.p0y);
351
351
  return;
352
352
  }
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);
353
+ case at: {
354
+ const i = this.p0x + e * (this.p1x - this.p0x), o = this.p0y + e * (this.p1y - this.p0y), r = this.p1x + e * (this.p2x - this.p1x), c = this.p1y + e * (this.p2y - this.p1y);
355
+ n[0] = i + e * (r - i), n[1] = o + e * (c - o);
356
356
  return;
357
357
  }
358
358
  default: {
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);
359
+ const i = this.p0x + e * (this.p1x - this.p0x), o = this.p0y + e * (this.p1y - this.p0y), r = this.p1x + e * (this.p2x - this.p1x), c = this.p1y + e * (this.p2y - this.p1y), a = this.p2x + e * (this.p3x - this.p2x), l = this.p2y + e * (this.p3y - this.p2y), h = i + e * (r - i), f = o + e * (c - o), u = r + e * (a - r), p = c + e * (l - c);
360
+ n[0] = h + e * (u - h), n[1] = f + e * (p - f);
361
361
  return;
362
362
  }
363
363
  }
@@ -370,20 +370,20 @@ class et {
370
370
  * @param out Two-element array [dx, dy] to write into.
371
371
  */
372
372
  direction(t, n) {
373
- const s = t;
373
+ const e = t;
374
374
  switch (this.type) {
375
- case lt: {
375
+ case ft: {
376
376
  n[0] = this.p1x - this.p0x, n[1] = this.p1y - this.p0y;
377
377
  return;
378
378
  }
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);
379
+ case at: {
380
+ const i = this.p1x - this.p0x + e * (this.p2x - this.p1x - (this.p1x - this.p0x)), o = this.p1y - this.p0y + e * (this.p2y - this.p1y - (this.p1y - this.p0y));
381
+ i !== 0 || o !== 0 ? (n[0] = i, n[1] = o) : (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y);
382
382
  return;
383
383
  }
384
384
  default: {
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);
385
+ const i = this.p1x - this.p0x, o = this.p1y - this.p0y, r = this.p2x - this.p1x, c = this.p2y - this.p1y, a = this.p3x - this.p2x, l = this.p3y - this.p2y, h = i + e * (r - i) + e * (r + e * (a - r) - (i + e * (r - i))), f = o + e * (c - o) + e * (c + e * (l - c) - (o + e * (c - o)));
386
+ h !== 0 || f !== 0 ? (n[0] = h, n[1] = f) : e === 0 ? (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y) : e === 1 ? (n[0] = this.p3x - this.p1x, n[1] = this.p3y - this.p1y) : (n[0] = h, n[1] = f);
387
387
  return;
388
388
  }
389
389
  }
@@ -398,80 +398,80 @@ class et {
398
398
  splitInThirds() {
399
399
  const t = [0, 0], n = [0, 0];
400
400
  switch (this.type) {
401
- case lt: {
401
+ case ft: {
402
402
  this.point(1 / 3, t), this.point(2 / 3, n);
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];
403
+ const e = new ot(ft, this.p0x, this.p0y, t[0], t[1], 0, 0, 0, 0), i = new ot(ft, t[0], t[1], n[0], n[1], 0, 0, 0, 0), o = new ot(ft, n[0], n[1], this.p1x, this.p1y, 0, 0, 0, 0);
404
+ return e.color = i.color = o.color = this.color, [e, i, o];
405
405
  }
406
- case ct: {
406
+ case at: {
407
407
  this.point(1 / 3, t), this.point(2 / 3, n);
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,
408
+ const e = this.p0x + 1 / 3 * (this.p1x - this.p0x), i = this.p0y + 1 / 3 * (this.p1y - this.p0y), o = this.p0x + 5 / 9 * (this.p1x - this.p0x), r = this.p0y + 5 / 9 * (this.p1y - this.p0y), c = this.p1x + 4 / 9 * (this.p2x - this.p1x), a = this.p1y + 4 / 9 * (this.p2y - this.p1y), l = o + 0.5 * (c - o), h = r + 0.5 * (a - r), f = this.p1x + 2 / 3 * (this.p2x - this.p1x), u = this.p1y + 2 / 3 * (this.p2y - this.p1y), p = new ot(
409
+ at,
410
410
  this.p0x,
411
411
  this.p0y,
412
- s,
412
+ e,
413
413
  i,
414
414
  t[0],
415
415
  t[1],
416
416
  0,
417
417
  0
418
- ), _ = new et(
419
- ct,
418
+ ), y = new ot(
419
+ at,
420
420
  t[0],
421
421
  t[1],
422
+ l,
422
423
  h,
423
- p,
424
424
  n[0],
425
425
  n[1],
426
426
  0,
427
427
  0
428
- ), y = new et(
429
- ct,
428
+ ), _ = new ot(
429
+ at,
430
430
  n[0],
431
431
  n[1],
432
- l,
433
432
  f,
433
+ u,
434
434
  this.p2x,
435
435
  this.p2y,
436
436
  0,
437
437
  0
438
438
  );
439
- return u.color = _.color = y.color = this.color, [u, _, y];
439
+ return p.color = y.color = _.color = this.color, [p, 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), 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
- Gt,
443
+ const e = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0x : this.p0x + 1 / 3 * (this.p1x - this.p0x), i = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0y : this.p0y + 1 / 3 * (this.p1y - this.p0y), o = this.p0x + 1 / 3 * (this.p1x - this.p0x), r = this.p0y + 1 / 3 * (this.p1y - this.p0y), c = this.p1x + 1 / 3 * (this.p2x - this.p1x), a = this.p1y + 1 / 3 * (this.p2y - this.p1y), l = this.p2x + 1 / 3 * (this.p3x - this.p2x), h = this.p2y + 1 / 3 * (this.p3y - this.p2y), f = o + 1 / 3 * (c - o), u = r + 1 / 3 * (a - r), p = c + 1 / 3 * (l - c), y = a + 1 / 3 * (h - a), _ = f + 2 / 3 * (p - f), g = u + 2 / 3 * (y - u), x = this.p0x + 2 / 3 * (this.p1x - this.p0x), b = this.p0y + 2 / 3 * (this.p1y - this.p0y), M = this.p1x + 2 / 3 * (this.p2x - this.p1x), k = this.p1y + 2 / 3 * (this.p2y - this.p1y), w = this.p2x + 2 / 3 * (this.p3x - this.p2x), T = this.p2y + 2 / 3 * (this.p3y - this.p2y), D = x + 2 / 3 * (M - x), m = b + 2 / 3 * (k - b), A = M + 2 / 3 * (w - M), d = k + 2 / 3 * (T - k), R = D + 1 / 3 * (A - D), S = m + 1 / 3 * (d - m), E = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3x : this.p2x + 2 / 3 * (this.p3x - this.p2x), I = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3y : this.p2y + 2 / 3 * (this.p3y - this.p2y), F = new ot(
444
+ nn,
445
445
  this.p0x,
446
446
  this.p0y,
447
- s,
447
+ e,
448
448
  i,
449
- l,
450
449
  f,
450
+ u,
451
451
  t[0],
452
452
  t[1]
453
- ), H = new et(
454
- Gt,
453
+ ), V = new ot(
454
+ nn,
455
455
  t[0],
456
456
  t[1],
457
- y,
457
+ _,
458
458
  g,
459
- C,
460
- v,
459
+ R,
460
+ S,
461
461
  n[0],
462
462
  n[1]
463
- ), Y = new et(
464
- Gt,
463
+ ), B = new ot(
464
+ nn,
465
465
  n[0],
466
466
  n[1],
467
+ A,
467
468
  d,
468
- x,
469
469
  E,
470
- k,
470
+ I,
471
471
  this.p3x,
472
472
  this.p3y
473
473
  );
474
- return S.color = H.color = Y.color = this.color, [S, H, Y];
474
+ return F.color = V.color = B.color = this.color, [F, V, B];
475
475
  }
476
476
  }
477
477
  }
@@ -488,95 +488,95 @@ class et {
488
488
  * @param oy Query point y (shape space).
489
489
  * @param out Reusable result object (mutated).
490
490
  */
491
- signedDistance(t, n, s) {
491
+ signedDistance(t, n, e) {
492
492
  switch (this.type) {
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;
493
+ case ft: {
494
+ const i = this.p0x, o = this.p0y, r = this.p1x, c = this.p1y, a = t - i, l = n - o, h = r - i, f = c - o, u = h * h + f * f, p = (a * h + l * f) / u, y = p > 0.5, _ = (y ? r : i) - t, g = (y ? c : o) - n, x = Math.sqrt(_ * _ + g * g);
495
+ if (p > 0 && p < 1) {
496
+ const k = Math.sqrt(h * h + f * f), w = h / k, D = f / k * a - w * l;
497
+ if (Math.abs(D) < x) {
498
+ e.distance = D, e.dot = 0, e.param = p;
499
499
  return;
500
500
  }
501
501
  }
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;
502
+ const b = a * f - l * h;
503
+ e.distance = Nt(b) * x;
504
+ const M = Math.sqrt(h * h + f * f);
505
+ e.dot = x === 0 || M === 0 ? 0 : Math.abs((h * _ + f * g) / (M * x)), e.param = p;
506
506
  return;
507
507
  }
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);
508
+ case at: {
509
+ const i = this.p0x, o = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = i - t, f = o - n, u = r - i, p = c - o, y = a - r - u, _ = l - c - p, g = y * y + _ * _, x = 3 * (u * y + p * _), b = 2 * (u * u + p * p) + (h * y + f * _), M = h * u + f * p, k = _o(g, x, b, M, 0, 1, K);
510
+ let w = u, T = p;
511
+ const D = h * h + f * f;
512
+ let m = Nt(w * f - T * h), A = D, d = -(h * w + f * T) / (w * w + T * T);
513
513
  {
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));
514
+ const S = a - t, E = l - n, I = S * S + E * E;
515
+ I < A && (w = a - r, T = l - c, m = Nt(w * E - T * S), A = I, d = ((t - r) * w + (n - c) * T) / (w * w + T * T));
516
516
  }
517
- for (let v = 0; v < T; ++v) {
518
- const E = X[v];
517
+ for (let S = 0; S < k; ++S) {
518
+ const E = K[S];
519
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;
520
+ const I = h + 2 * E * u + E * E * y, F = f + 2 * E * p + E * E * _, V = I * I + F * F;
521
+ if (V <= A) {
522
+ const B = u + E * y, nt = p + E * _;
523
+ m = Nt(B * F - nt * I), A = V, d = E;
524
524
  }
525
525
  }
526
526
  }
527
- const C = m * Math.sqrt(d);
528
- if (x >= 0 && x <= 1) {
529
- s.distance = C, s.dot = 0, s.param = x;
527
+ const R = m * Math.sqrt(A);
528
+ if (d >= 0 && d <= 1) {
529
+ e.distance = R, e.dot = 0, e.param = d;
530
530
  return;
531
531
  }
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));
532
+ if (e.distance = R, e.param = d, d < 0.5) {
533
+ const S = Math.sqrt(u * u + p * p), E = Math.sqrt(D);
534
+ e.dot = E === 0 || S === 0 ? 0 : Math.abs((u * h + p * f) / (S * E));
535
535
  } else {
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));
536
+ const S = a - r, E = l - c, I = a - t, F = l - n, V = Math.sqrt(S * S + E * E), B = Math.sqrt(I * I + F * F);
537
+ e.dot = V === 0 || B === 0 ? 0 : Math.abs((S * I + E * F) / (V * B));
538
538
  }
539
539
  return;
540
540
  }
541
541
  default: {
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);
542
+ const i = this.p0x, o = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = this.p3x, f = this.p3y, u = i - t, p = o - n, y = r - i, _ = c - o, g = a - r - y, x = l - c - _, b = h - a - (a - r) - g, M = f - l - (l - c) - x;
543
+ let k = y, w = _;
544
+ k === 0 && w === 0 && (k = a - i, w = l - o);
545
+ const T = Math.sqrt(u * u + p * p);
546
+ let D = Nt(k * p - w * u) * T, m = -(u * k + p * w) / (k * k + w * w);
547
547
  {
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);
548
+ const A = h - t, d = f - n, R = Math.sqrt(A * A + d * d);
549
+ if (R < Math.abs(D)) {
550
+ let S = h - a, E = f - l;
551
+ S === 0 && E === 0 && (S = h - r, E = f - c), k = S, w = E, D = Nt(k * d - w * A) * R, m = ((k - A) * k + (w - d) * w) / (k * k + w * w);
552
552
  }
553
553
  }
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;
554
+ for (let A = 0; A <= Vs; ++A) {
555
+ let d = 1 / Vs * A, R = u + 3 * d * y + 3 * d * d * g + d * d * d * b, S = p + 3 * d * _ + 3 * d * d * x + d * d * d * M, E = 3 * y + 6 * d * g + 3 * d * d * b, I = 3 * _ + 6 * d * x + 3 * d * d * M, F = 6 * g + 6 * d * b, V = 6 * x + 6 * d * M, B = d - (R * E + S * I) / (E * E + I * I + (R * F + S * V));
556
+ if (B > 0 && B < 1) {
557
+ let nt = yo;
558
558
  do {
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);
559
+ if (d = B, R = u + 3 * d * y + 3 * d * d * g + d * d * d * b, S = p + 3 * d * _ + 3 * d * d * x + d * d * d * M, E = 3 * y + 6 * d * g + 3 * d * d * b, I = 3 * _ + 6 * d * x + 3 * d * d * M, !--nt) break;
560
+ F = 6 * g + 6 * d * b, V = 6 * x + 6 * d * M, B = d - (R * E + S * I) / (E * E + I * I + (R * F + S * V));
561
+ } while (B > 0 && B < 1);
562
+ const j = Math.sqrt(R * R + S * S);
563
+ j < Math.abs(D) && (D = Nt(E * S - I * R) * j, m = d);
564
564
  }
565
565
  }
566
566
  if (m >= 0 && m <= 1) {
567
- s.distance = R, s.dot = 0, s.param = m;
567
+ e.distance = D, e.dot = 0, e.param = m;
568
568
  return;
569
569
  }
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));
570
+ if (e.distance = D, e.param = m, m < 0.5) {
571
+ let A = y, d = _;
572
+ A === 0 && d === 0 && (A = a - i, d = l - o);
573
+ const R = Math.sqrt(A * A + d * d);
574
+ e.dot = T === 0 || R === 0 ? 0 : Math.abs((A * u + d * p) / (R * T));
575
575
  } else {
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));
576
+ let A = h - a, d = f - l;
577
+ A === 0 && d === 0 && (A = h - r, d = f - c);
578
+ const R = h - t, S = f - n, E = Math.sqrt(A * A + d * d), I = Math.sqrt(R * R + S * S);
579
+ e.dot = E === 0 || I === 0 ? 0 : Math.abs((A * R + d * S) / (E * I));
580
580
  }
581
581
  return;
582
582
  }
@@ -593,58 +593,58 @@ class et {
593
593
  * @param dyOut Output array (length >= 3) — crossing directions (±1).
594
594
  * @returns Number of crossings written (0..3).
595
595
  */
596
- scanlineIntersections(t, n, s) {
596
+ scanlineIntersections(t, n, e) {
597
597
  switch (this.type) {
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;
598
+ case ft: {
599
+ const i = this.p0y, o = this.p1y;
600
+ if (t >= i && t < o || t >= o && t < i) {
601
+ const r = (t - i) / (o - i);
602
+ return n[0] = ao(this.p0x, this.p1x, r), e[0] = pt(o - i), 1;
603
603
  }
604
604
  return 0;
605
605
  }
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);
606
+ case at: {
607
+ const i = this.p0x, o = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y;
608
+ let h = 0, f = t > o ? 1 : -1;
609
+ n[h] = i, o === t && (o < c || o === c && o < l ? e[h++] = 1 : f = 1);
610
610
  {
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;
611
+ const u = r - i, p = c - o, y = a - r - u, _ = l - c - p, g = Ri(K, _, 2 * p, o - t);
612
+ if (g >= 2 && K[0] > K[1]) {
613
+ const x = K[0];
614
+ K[0] = K[1], K[1] = x;
615
615
  }
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));
616
+ for (let x = 0; x < g && h < 2; ++x) {
617
+ const b = K[x];
618
+ b >= 0 && b <= 1 && (n[h] = i + 2 * b * u + b * b * y, f * (p + b * _) >= 0 && (e[h++] = f, f = -f));
619
619
  }
620
620
  }
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;
621
+ return l === t && (f > 0 && h > 0 && (--h, f = -1), (l < c || l === c && l < o) && h < 2 && (n[h] = a, f < 0 && (e[h++] = -1, f = 1))), f !== (t >= l ? 1 : -1) && (h > 0 ? --h : (Math.abs(l - t) < Math.abs(o - t) && (n[h] = a), e[h++] = f)), h;
622
622
  }
623
623
  default: {
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);
624
+ const i = this.p0x, o = this.p0y, r = this.p1x, c = this.p1y, a = this.p2x, l = this.p2y, h = this.p3x, f = this.p3y;
625
+ let u = 0, p = t > o ? 1 : -1;
626
+ n[u] = i, o === t && (o < c || o === c && (o < l || o === l && o < f) ? e[u++] = 1 : p = 1);
627
627
  {
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;
628
+ const y = h - 3 * a + 3 * r - i, _ = f - 3 * l + 3 * c - o, g = 3 * a - 6 * r + 3 * i, x = 3 * l - 6 * c + 3 * o, b = 3 * r - 3 * i, M = 3 * c - 3 * o, k = ho(K, _, x, M, o - t);
629
+ if (k >= 2) {
630
+ if (K[0] > K[1]) {
631
+ const w = K[0];
632
+ K[0] = K[1], K[1] = w;
633
633
  }
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;
634
+ if (k >= 3 && K[1] > K[2]) {
635
+ const w = K[1];
636
+ if (K[1] = K[2], K[2] = w, K[0] > K[1]) {
637
+ const T = K[0];
638
+ K[0] = K[1], K[1] = T;
639
639
  }
640
640
  }
641
641
  }
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));
642
+ for (let w = 0; w < k && u < 3; ++w) {
643
+ const T = K[w];
644
+ T >= 0 && T <= 1 && (n[u] = ((y * T + g) * T + b) * T + i, p * ((3 * _ * T + 2 * x) * T + M) >= 0 && (e[u++] = p, p = -p));
645
645
  }
646
646
  }
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;
647
+ return f === t && (p > 0 && u > 0 && (--u, p = -1), (f < l || f === l && (f < c || f === c && f < o)) && u < 3 && (n[u] = h, p < 0 && (e[u++] = -1, p = 1))), p !== (t >= f ? 1 : -1) && (u > 0 ? --u : (Math.abs(f - t) < Math.abs(o - t) && (n[u] = h), e[u++] = p)), u;
648
648
  }
649
649
  }
650
650
  }
@@ -656,202 +656,1290 @@ class et {
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), i = this.p1y + 1 / 3 * (this.p2y - this.p1y), e = new et(
660
- Gt,
659
+ const t = this.p0x + 0.6666666666666666 * (this.p1x - this.p0x), n = this.p0y + 2 / 3 * (this.p1y - this.p0y), e = this.p1x + 1 / 3 * (this.p2x - this.p1x), i = this.p1y + 1 / 3 * (this.p2y - this.p1y), o = new ot(
660
+ nn,
661
661
  this.p0x,
662
662
  this.p0y,
663
663
  t,
664
664
  n,
665
- s,
665
+ e,
666
666
  i,
667
667
  this.p2x,
668
668
  this.p2y
669
669
  );
670
- return e.color = this.color, e;
670
+ return o.color = this.color, o;
671
671
  }
672
672
  }
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
- for (const c of e) {
677
- const r = ie(c);
678
- r.length > 0 && a.push(r);
673
+ const go = 1, xo = 2, Mo = 4, wo = 8, js = 16, Xs = 32, Ao = 1, Ws = 2, bo = 8, mo = 32, ko = 64, Uo = 128;
674
+ function To(s, t, n, e, i) {
675
+ const o = Li(s, t, n, e, i), r = [];
676
+ for (const c of o) {
677
+ const a = Co(c);
678
+ a.length > 0 && r.push(a);
679
679
  }
680
- return { contours: a, inverseYAxis: !1 };
680
+ return { contours: r, inverseYAxis: !1 };
681
681
  }
682
- function Ao(o, t, n, s, i) {
683
- if (s === 0) return [];
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);
682
+ function Li(s, t, n, e, i) {
683
+ if (e === 0) return [];
684
+ const o = t + n, r = new St(s, o), c = r.i16();
685
+ return r.skip(8), c >= 0 ? vo(r, c) : So(s, r, t, i);
686
686
  }
687
- function oe(o, t) {
687
+ function vo(s, t) {
688
688
  if (t === 0) return [];
689
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
- const e = new Uint8Array(s);
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
- }
700
- }
701
- const a = new Float64Array(s);
690
+ for (let f = 0; f < t; f++) n[f] = s.u16();
691
+ const e = (n[t - 1] ?? 0) + 1, i = s.u16();
692
+ s.skip(i);
693
+ const o = new Uint8Array(e);
694
+ for (let f = 0; f < e; ) {
695
+ const u = s.u8();
696
+ if (o[f++] = u, u & wo) {
697
+ let p = s.u8();
698
+ for (; p-- > 0; ) o[f++] = u;
699
+ }
700
+ }
701
+ const r = new Float64Array(e);
702
702
  let c = 0;
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
- }
711
- const r = new Float64Array(s);
703
+ for (let f = 0; f < e; f++) {
704
+ const u = o[f] ?? 0;
705
+ if (u & xo) {
706
+ const p = s.u8();
707
+ c += u & js ? p : -p;
708
+ } else u & js || (c += s.i16());
709
+ r[f] = c;
710
+ }
711
+ const a = new Float64Array(e);
712
712
  c = 0;
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
- }
721
- const h = [];
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
- }
727
- return h;
728
- }
729
- function ee(o, t, n, s, i) {
730
- const e = i - s + 1;
731
- if (e <= 0) return [];
732
- const a = [];
733
- for (let c = 0; c < e; c++) {
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 });
713
+ for (let f = 0; f < e; f++) {
714
+ const u = o[f] ?? 0;
715
+ if (u & Mo) {
716
+ const p = s.u8();
717
+ c += u & Xs ? p : -p;
718
+ } else u & Xs || (c += s.i16());
719
+ a[f] = c;
720
+ }
721
+ const l = [];
722
+ let h = 0;
723
+ for (let f = 0; f < t; f++) {
724
+ const u = n[f] ?? 0, p = Eo(o, r, a, h, u);
725
+ p.length > 0 && l.push(p), h = u + 1;
726
+ }
727
+ return l;
728
+ }
729
+ function Eo(s, t, n, e, i) {
730
+ const o = i - e + 1;
731
+ if (o <= 0) return [];
732
+ const r = [];
733
+ for (let c = 0; c < o; c++) {
734
+ const a = s[e + c] ?? 0, l = t[e + c] ?? 0, h = n[e + c] ?? 0;
735
+ r.push({ x: l, y: h, onCurve: (a & go) !== 0 });
736
736
  }
737
- return a;
737
+ return r;
738
738
  }
739
- function ie(o) {
740
- const t = o.length;
739
+ function Co(s) {
740
+ const t = s.length;
741
741
  if (t <= 0) return [];
742
742
  const n = [];
743
743
  for (let c = 0; c < t; c++) {
744
- const r = o[c], h = o[(c + 1) % t];
745
- n.push(r), !r.onCurve && !h.onCurve && n.push({
746
- x: Math.trunc((r.x + h.x) / 2),
747
- y: Math.trunc((r.y + h.y) / 2),
744
+ const a = s[c], l = s[(c + 1) % t];
745
+ n.push(a), !a.onCurve && !l.onCurve && n.push({
746
+ x: Math.trunc((a.x + l.x) / 2),
747
+ y: Math.trunc((a.y + l.y) / 2),
748
748
  onCurve: !0
749
749
  });
750
750
  }
751
- const s = n.length;
751
+ const e = n.length;
752
752
  let i = 0;
753
753
  if (!n[0].onCurve) {
754
- for (let c = 1; c < s; c++)
754
+ for (let c = 1; c < e; c++)
755
755
  if (n[c].onCurve) {
756
756
  i = c;
757
757
  break;
758
758
  }
759
759
  }
760
- const e = [];
761
- let a = 0;
762
- for (; a < s; ) {
763
- const c = n[(i + a) % s], r = n[(i + a + 1) % s];
764
- if (r.onCurve)
765
- e.push(new et(lt, c.x, c.y, r.x, r.y, 0, 0, 0, 0)), a += 1;
760
+ const o = [];
761
+ let r = 0;
762
+ for (; r < e; ) {
763
+ const c = n[(i + r) % e], a = n[(i + r + 1) % e];
764
+ if (a.onCurve)
765
+ o.push(new ot(ft, c.x, c.y, a.x, a.y, 0, 0, 0, 0)), r += 1;
766
766
  else {
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;
767
+ const l = n[(i + r + 2) % e];
768
+ o.push(new ot(at, c.x, c.y, a.x, a.y, l.x, l.y, 0, 0)), r += 2;
769
769
  }
770
770
  }
771
- return e;
771
+ return o;
772
772
  }
773
- function ce(o, t, n, s) {
773
+ function So(s, t, n, e) {
774
774
  const i = [];
775
- let e = 0;
775
+ let o = 0;
776
776
  do {
777
- e = t.u16();
778
- const a = t.u16();
779
- let c, r;
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);
777
+ o = t.u16();
778
+ const r = t.u16();
779
+ let c, a;
780
+ o & Ao ? (c = t.i16(), a = t.i16()) : (c = t.u8(), a = t.u8(), o & Ws && (c > 127 && (c -= 256), a > 127 && (a -= 256)));
781
+ let l = 0, h = 0;
782
+ o & Ws && (l = c, h = a);
783
+ let f = 1, u = 0, p = 0, y = 1;
784
+ o & bo ? f = y = t.f2dot14() : o & ko ? (f = t.f2dot14(), y = t.f2dot14()) : o & Uo && (f = t.f2dot14(), u = t.f2dot14(), p = t.f2dot14(), y = t.f2dot14());
785
+ const _ = e(r), g = Io(_, f, u, p, y, l, h);
786
+ for (const x of g) i.push(x);
787
+ } while (o & mo);
788
788
  return i;
789
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
790
+ function zs(s) {
791
+ return s >= 0 ? Math.floor(s + 0.5) : Math.ceil(s - 0.5);
792
+ }
793
+ function Io(s, t, n, e, i, o, r) {
794
+ if (t === 1 && n === 0 && e === 0 && i === 1 && o === 0 && r === 0) return s;
795
+ const a = t === 1 && n === 0 && e === 0 && i === 1;
796
+ return s.map(
797
+ (l) => l.map((h) => a ? { x: h.x + o, y: h.y + r, onCurve: h.onCurve } : {
798
+ x: zs(t * h.x + n * h.y + o),
799
+ y: zs(e * h.x + i * h.y + r),
800
+ onCurve: h.onCurve
801
801
  })
802
802
  );
803
803
  }
804
- function ae(o, t) {
805
- const n = new wt(o, t);
806
- if (n.u16() !== 0)
807
- return to;
808
- const i = n.u16(), e = /* @__PURE__ */ new Map();
809
- for (let a = 0; a < i; a++) {
810
- const c = n.pos;
811
- n.skip(2);
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
- n.seek(c + r);
804
+ const on = 1, Xn = 2, Do = 4, Ct = 8, xn = 16, C = {
805
+ /** Unicode codepoint per glyph. */
806
+ _cp: new Int32Array(64),
807
+ /** Glyph index per glyph. */
808
+ _gid: new Uint16Array(64),
809
+ /** PROP_* bits per glyph. */
810
+ _gp: new Uint16Array(64),
811
+ /** x advance, font units. */
812
+ _xa: new Float64Array(64),
813
+ /** x offset, font units. */
814
+ _xo: new Float64Array(64),
815
+ /** y offset, font units (y-up). */
816
+ _yo: new Float64Array(64),
817
+ /** Script-run end indices and ICU script codes (see script.ts: itemize). */
818
+ _runEnd: new Int32Array(64),
819
+ _runScript: new Int32Array(64)
820
+ };
821
+ function dn(s, t, n, e) {
822
+ if (s & n & 14) return !1;
823
+ if (s & Ct) {
824
+ if (n & 16) return e !== null && t < e.length && e[t] !== 65535;
825
+ if (n & 65280) return (n & 65280) === (s & 65280);
826
+ }
827
+ return !0;
828
+ }
829
+ function rs(s, t, n, e) {
830
+ const i = C._gp, o = C._gid;
831
+ for (let r = s + 1; r < t; r++) {
832
+ const c = i[r];
833
+ if (!(c & on) && dn(c, o[r], n, e)) return r;
834
+ }
835
+ return -1;
836
+ }
837
+ function Fi(s) {
838
+ if (C._gid.length >= s) return;
839
+ let t = C._gid.length;
840
+ for (; t < s; ) t *= 2;
841
+ C._cp = new Int32Array(t), C._gid = new Uint16Array(t), C._gp = new Uint16Array(t), C._xa = new Float64Array(t), C._xo = new Float64Array(t), C._yo = new Float64Array(t), C._runEnd = new Int32Array(t), C._runScript = new Int32Array(t);
842
+ }
843
+ let rn = new Uint8Array(64);
844
+ class Ro {
845
+ /**
846
+ * @param buffer Full font buffer.
847
+ * @param offset Byte offset of the kern table.
848
+ */
849
+ constructor(t, n) {
850
+ this._pairs = [], this._counts = [], this._cross = [];
851
+ const e = new DataView(t);
852
+ this._dv = e;
853
+ const i = e.getUint16(n) === 1, o = i ? e.getUint32(n + 4) : e.getUint16(n + 2);
854
+ let r = n + (i ? 8 : 4), c = !1, a = !1;
855
+ for (let l = 0; l < o && r + 8 <= e.byteLength; l++) {
856
+ let h, f, u, p, y = !1, _;
857
+ if (i) {
858
+ h = e.getUint32(r);
859
+ const g = e.getUint8(r + 4);
860
+ f = e.getUint8(r + 5), u = !(g & 128), p = !!(g & 64), y = !!(g & 32), _ = r + 8;
861
+ } else {
862
+ h = e.getUint16(r + 2), f = e.getUint8(r + 4);
863
+ const g = e.getUint8(r + 5);
864
+ u = !!(g & 1), p = !!(g & 4), _ = r + 6;
865
+ }
866
+ if (f === 1 && (c = !0), p && (a = !0), f === 0 && u && !y && (this._pairs.push(_ + 8), this._counts.push(e.getUint16(_)), this._cross.push(p)), h < 6) break;
867
+ r += h;
868
+ }
869
+ this._hasData = o > 0, this._hasMachine = c, this._hasCross = a;
870
+ }
871
+ /** Kern value of subtable `s` for a pair, 0 if not listed (binary search, like HarfBuzz). */
872
+ _get(t, n, e) {
873
+ const i = this._dv, o = this._pairs[t], r = (n << 16 | e) >>> 0;
874
+ let c = 0, a = this._counts[t] - 1;
875
+ for (; c <= a; ) {
876
+ const l = c + a >> 1, h = i.getUint32(o + 6 * l);
877
+ if (h < r) c = l + 1;
878
+ else if (h > r) a = l - 1;
879
+ else return i.getInt16(o + 6 * l + 4);
880
+ }
881
+ return 0;
882
+ }
883
+ /** Kerns `run[start, end)`. */
884
+ _apply(t, n) {
885
+ const e = C._gid, i = C._xa, o = C._xo, r = C._yo;
886
+ let c = !1, a = !1;
887
+ for (let l = 0; l < this._pairs.length; l++) {
888
+ const h = this._cross[l];
889
+ h && !c && (c = !0, rn.length < n && (rn = new Uint8Array(n * 2)), rn.fill(0, t, n));
890
+ for (let f = t; f < n; ) {
891
+ const u = rs(f, n, Ct, null);
892
+ if (u < 0) {
893
+ f++;
894
+ continue;
895
+ }
896
+ const p = this._get(l, e[f], e[u]);
897
+ if (p)
898
+ if (h)
899
+ p === -32768 ? (rn[u] = 1, r[u] = 0) : (r[u] = p, a = !0);
900
+ else {
901
+ const y = p / 2;
902
+ i[f] = i[f] + y, i[u] = i[u] + p - y, o[u] = o[u] + p - y;
903
+ }
904
+ f = u;
905
+ }
906
+ }
907
+ if (a)
908
+ for (let l = t + 1; l < n; l++) rn[l] || (r[l] = r[l] + r[l - 1]);
909
+ }
910
+ }
911
+ const Gt = 65535, Pi = new Uint16Array(0);
912
+ function Lo(s, t) {
913
+ const n = s.getUint16(t + 4);
914
+ if (!n) return new Uint32Array(0);
915
+ const e = t + n, i = new Uint32Array(s.getUint16(e));
916
+ for (let o = 0; o < i.length; o++) i[o] = s.getUint32(e + 2 + 6 * o);
917
+ return i;
918
+ }
919
+ function qi(s, t) {
920
+ const n = s.getUint16(t), e = s.getUint16(t + 2);
921
+ let i = -1;
922
+ if (n === 1) {
923
+ for (let r = 0; r < e; r++) i = Math.max(i, s.getUint16(t + 4 + 2 * r));
924
+ const o = new Uint16Array(i + 1).fill(Gt);
925
+ for (let r = e - 1; r >= 0; r--) o[s.getUint16(t + 4 + 2 * r)] = r;
926
+ return o;
927
+ }
928
+ if (n === 2) {
929
+ for (let r = 0; r < e; r++) i = Math.max(i, s.getUint16(t + 6 + 6 * r));
930
+ const o = new Uint16Array(i + 1).fill(Gt);
931
+ for (let r = e - 1; r >= 0; r--) {
932
+ const c = t + 4 + 6 * r, a = s.getUint16(c), l = s.getUint16(c + 2), h = s.getUint16(c + 4);
933
+ for (let f = a; f <= l; f++) o[f] = h + f - a;
934
+ }
935
+ return o;
936
+ }
937
+ return Pi;
938
+ }
939
+ function ts(s, t) {
940
+ const n = s.getUint16(t);
941
+ if (n === 1) {
942
+ const e = s.getUint16(t + 2), i = s.getUint16(t + 4), o = new Uint16Array(e + i);
943
+ for (let r = 0; r < i; r++) o[e + r] = s.getUint16(t + 6 + 2 * r);
944
+ return o;
945
+ }
946
+ if (n === 2) {
947
+ const e = s.getUint16(t + 2);
948
+ let i = -1;
949
+ for (let r = 0; r < e; r++) i = Math.max(i, s.getUint16(t + 6 + 6 * r));
950
+ const o = new Uint16Array(i + 1);
951
+ for (let r = e - 1; r >= 0; r--) {
952
+ const c = t + 4 + 6 * r, a = s.getUint16(c + 2), l = s.getUint16(c + 4);
953
+ for (let h = s.getUint16(c); h <= a; h++) o[h] = l;
954
+ }
955
+ return o;
956
+ }
957
+ return Pi;
958
+ }
959
+ class Fo {
960
+ /**
961
+ * @param buffer Full font buffer.
962
+ * @param offset Byte offset of the GDEF table.
963
+ * @param numGlyphs `maxp.numGlyphs`.
964
+ */
965
+ constructor(t, n, e) {
966
+ this._setCache = [];
967
+ const i = new DataView(t);
968
+ this._dv = i;
969
+ const o = i.getUint16(n + 2), r = i.getUint16(n + 4), c = i.getUint16(n + 10), a = o >= 2 ? i.getUint16(n + 12) : 0;
970
+ if (this._sets = a ? n + a : 0, !r) {
971
+ this._props = null;
972
+ return;
973
+ }
974
+ const l = ts(i, n + r), h = c ? ts(i, n + c) : new Uint16Array(0), f = new Uint16Array(e);
975
+ for (let u = 0; u < e && u < l.length; u++)
976
+ switch (l[u]) {
977
+ case 1:
978
+ f[u] = Xn;
979
+ break;
980
+ case 2:
981
+ f[u] = Do;
982
+ break;
983
+ case 3:
984
+ f[u] = Ct | (h[u] ?? 0) << 8;
985
+ break;
986
+ }
987
+ this._props = f;
988
+ }
989
+ /** Coverage of mark glyph set `index` (empty if the font has none). */
990
+ _markSet(t) {
991
+ let n = this._setCache[t];
992
+ if (!n) {
993
+ const e = this._dv, i = this._sets;
994
+ n = i && t < e.getUint16(i + 2) ? qi(e, i + e.getUint32(i + 4 + 4 * t)) : new Uint16Array(0), this._setCache[t] = n;
995
+ }
996
+ return n;
997
+ }
998
+ }
999
+ const Oi = "ZyyyZinhArabArmnBengBopoCherCoptCyrlDsrtDevaEthiGeorGothGrekGujrGuruHaniHangHebrHiraKndaKanaKhmrLaooLatnMlymMongMymrOgamItalOryaRunrSinhSyrcTamlTeluThaaThaiTibtCansYiiiTglgHanoBuhdTagbBraiCprtLimbLinbOsmaShawTaleUgarHrktBugiGlagKharSyloTaluTfngXpeoBaliBatkBlisBrahChamCirtCyrsEgydEgyhEgypGeokHansHantHmngHungIndsJavaKaliLatfLatgLepcLinaMandMayaMeroNkooOrkhPermPhagPhnxPlrdRoroSaraSyreSyrjSyrnTengVaiiVispXsuxZxxxZzzzCariJpanLanaLyciLydiOlckRjngSaurSgnwSundMoonMteiArmiAvstCakmKoreKthiManiPhliPhlpPhlvPrtiSamrTavtZmthZsymBamuLisuNkgbSarbBassDuplElbaGranKpelLomaMendMercNarbNbatPalmSindWaraAfakJurcMrooNshuShrdSoraTakrTangWoleHluwKhojTirhAghbMahjAhomHatrModiMultPaucSiddAdlmBhksMarcNewaOsgeHanbJamoZsyeGonmSoyoZanbDogrGongMakaMedfRohgSogdSogoElymHmnpNandWchoChrsDiakKitsYeziCpmnOugrTnsaTotoVithKawiNagmAranGaraGukhKraiOnaoSunuTodrTutgBerfSidtTayoTols", Vn = Oi.length / 4, rt = 0, Et = 1, Wn = 25, Po = 8, qo = 14;
1000
+ function mn(s) {
1001
+ return Oi.substring(s * 4, s * 4 + 4);
1002
+ }
1003
+ const Oo = [], Go = [];
1004
+ function Rn(s, t) {
1005
+ const n = t ? Go : Oo;
1006
+ let e = n[s];
1007
+ if (e === void 0) {
1008
+ try {
1009
+ e = new RegExp(`^\\p{${t ? "scx" : "sc"}=${mn(s)}}$`, "u");
1010
+ } catch {
1011
+ e = null;
1012
+ }
1013
+ n[s] = e;
1014
+ }
1015
+ return e;
1016
+ }
1017
+ let Ee = null;
1018
+ const Ln = [Wn, rt, Et, Po, qo], Mn = [[rt], [Wn]], Zs = /* @__PURE__ */ new Map();
1019
+ let Fn = null;
1020
+ const $s = /* @__PURE__ */ new Map();
1021
+ function Ce(s) {
1022
+ if (s < 128)
1023
+ return Mn[s >= 65 && s <= 90 || s >= 97 && s <= 122 ? 1 : 0];
1024
+ let t;
1025
+ if (s < 65536) {
1026
+ Fn || (Fn = new Uint16Array(65536));
1027
+ const n = Fn[s];
1028
+ if (n) return Mn[n - 1];
1029
+ t = Js(s), Fn[s] = t + 1;
1030
+ } else
1031
+ t = $s.get(s), t === void 0 && (t = Js(s), $s.set(s, t));
1032
+ return Mn[t];
1033
+ }
1034
+ function Js(s) {
1035
+ const t = String.fromCodePoint(s);
1036
+ let n = 103;
1037
+ for (let r = 0; r < Ln.length + Vn; r++) {
1038
+ const c = r < Ln.length ? Ln[r] : r - Ln.length, a = Rn(c, !1);
1039
+ if (a && a.test(t)) {
1040
+ n = c;
1041
+ break;
1042
+ }
1043
+ }
1044
+ let e = [n];
1045
+ if (!Ee) {
1046
+ let r = "";
1047
+ for (let c = 0; c < Vn; c++)
1048
+ Rn(c, !1) && Rn(c, !0) && (r += `${r ? "|" : ""}(?!\\p{sc=${mn(c)}})\\p{scx=${mn(c)}}`);
1049
+ Ee = new RegExp(`^(?:${r})$`, "u");
1050
+ }
1051
+ if (Ee.test(t)) {
1052
+ const r = [];
1053
+ for (let c = 0; c < Vn; c++) {
1054
+ const a = Rn(c, !0);
1055
+ a && a.test(t) && r.push(c);
1056
+ }
1057
+ r.length && (e = No(n, r));
1058
+ }
1059
+ const i = e.join(",");
1060
+ let o = Zs.get(i);
1061
+ return o === void 0 && (o = Mn.length, Mn.push(e), Zs.set(i, o)), o;
1062
+ }
1063
+ function No(s, t) {
1064
+ if (s === t[0]) return t;
1065
+ if (s !== Et && s !== rt) {
1066
+ const n = t.indexOf(s, 1);
1067
+ if (n < 0) {
1068
+ t.push(s);
1069
+ const e = t[0];
1070
+ t[0] = s, t[t.length - 1] = e;
1071
+ } else
1072
+ t[n] = t[0], t[0] = s;
1073
+ return t;
1074
+ }
1075
+ if (s === rt) {
1076
+ if (t.length === 1) return [rt, t[0]];
1077
+ for (let n = 1; n < t.length; n++)
1078
+ if (t[0] === Wn || t[n] < t[0]) {
1079
+ const e = t[0];
1080
+ t[0] = t[n], t[n] = e;
1081
+ }
1082
+ return t;
1083
+ }
1084
+ t.push(t[0]), t[0] = s;
1085
+ for (let n = 2; n < t.length; n++)
1086
+ if (t[1] === Wn || t[n] < t[1]) {
1087
+ const e = t[1];
1088
+ t[1] = t[n], t[n] = e;
1089
+ }
1090
+ return t;
1091
+ }
1092
+ const cn = [
1093
+ 40,
1094
+ 41,
1095
+ 91,
1096
+ 93,
1097
+ 123,
1098
+ 125,
1099
+ 3898,
1100
+ 3899,
1101
+ 3900,
1102
+ 3901,
1103
+ 5787,
1104
+ 5788,
1105
+ 8261,
1106
+ 8262,
1107
+ 8317,
1108
+ 8318,
1109
+ 8333,
1110
+ 8334,
1111
+ 8968,
1112
+ 8969,
1113
+ 8970,
1114
+ 8971,
1115
+ 9001,
1116
+ 9002,
1117
+ 10088,
1118
+ 10089,
1119
+ 10090,
1120
+ 10091,
1121
+ 10092,
1122
+ 10093,
1123
+ 10094,
1124
+ 10095,
1125
+ 10096,
1126
+ 10097,
1127
+ 10098,
1128
+ 10099,
1129
+ 10100,
1130
+ 10101,
1131
+ 10181,
1132
+ 10182,
1133
+ 10214,
1134
+ 10215,
1135
+ 10216,
1136
+ 10217,
1137
+ 10218,
1138
+ 10219,
1139
+ 10220,
1140
+ 10221,
1141
+ 10222,
1142
+ 10223,
1143
+ 10627,
1144
+ 10628,
1145
+ 10629,
1146
+ 10630,
1147
+ 10631,
1148
+ 10632,
1149
+ 10633,
1150
+ 10634,
1151
+ 10635,
1152
+ 10636,
1153
+ 10637,
1154
+ 10640,
1155
+ 10639,
1156
+ 10638,
1157
+ 10641,
1158
+ 10642,
1159
+ 10643,
1160
+ 10644,
1161
+ 10645,
1162
+ 10646,
1163
+ 10647,
1164
+ 10648,
1165
+ 10712,
1166
+ 10713,
1167
+ 10714,
1168
+ 10715,
1169
+ 10748,
1170
+ 10749,
1171
+ 11810,
1172
+ 11811,
1173
+ 11812,
1174
+ 11813,
1175
+ 11814,
1176
+ 11815,
1177
+ 11816,
1178
+ 11817,
1179
+ 11861,
1180
+ 11862,
1181
+ 11863,
1182
+ 11864,
1183
+ 11865,
1184
+ 11866,
1185
+ 11867,
1186
+ 11868,
1187
+ 12296,
1188
+ 12297,
1189
+ 12298,
1190
+ 12299,
1191
+ 12300,
1192
+ 12301,
1193
+ 12302,
1194
+ 12303,
1195
+ 12304,
1196
+ 12305,
1197
+ 12308,
1198
+ 12309,
1199
+ 12310,
1200
+ 12311,
1201
+ 12312,
1202
+ 12313,
1203
+ 12314,
1204
+ 12315,
1205
+ 65113,
1206
+ 65114,
1207
+ 65115,
1208
+ 65116,
1209
+ 65117,
1210
+ 65118,
1211
+ 65288,
1212
+ 65289,
1213
+ 65339,
1214
+ 65341,
1215
+ 65371,
1216
+ 65373,
1217
+ 65375,
1218
+ 65376,
1219
+ 65378,
1220
+ 65379
1221
+ ];
1222
+ let an = null;
1223
+ function Ho(s) {
1224
+ if (s < 40 || s > 125 && s < 3898) return 0;
1225
+ if (!an) {
1226
+ an = /* @__PURE__ */ new Map();
1227
+ for (let t = 0; t < cn.length; t += 2)
1228
+ an.set(cn[t], cn[t + 1]), an.set(cn[t + 1], -cn[t]);
1229
+ }
1230
+ return an.get(s) ?? 0;
1231
+ }
1232
+ const Qs = 32, kt = [], Qt = [];
1233
+ let Dt = 0, zn = rt;
1234
+ const Ot = [];
1235
+ let tn = [], Ht = [];
1236
+ const ti = [];
1237
+ function ni(s) {
1238
+ let t = ti[s];
1239
+ return t || (ti[s] = t = [s]), t;
1240
+ }
1241
+ function Se() {
1242
+ const s = Ot[0];
1243
+ return s === rt ? zn : s;
1244
+ }
1245
+ function ei(s, t) {
1246
+ let n = Dt;
1247
+ if (n <= 0) return;
1248
+ n > kt.length && (n = kt.length);
1249
+ let e = kt.length - 1;
1250
+ for (t ? (e--, n--, Dt = 1) : Dt = 0; n > 0; e--, n--) Qt[e] = s;
1251
+ }
1252
+ function Bo() {
1253
+ const s = tn, t = Ot;
1254
+ if (s.length === 0 || t.length === 0) return !1;
1255
+ if (s.length === 1 && t.length === 1) {
1256
+ const c = s[0];
1257
+ return c <= Et ? !0 : t[0] <= Et ? (t[0] = c, !0) : t[0] === c;
1258
+ }
1259
+ let n = 0, e = t[n++];
1260
+ if (s[0] <= Et)
1261
+ return s.length === 2 && e <= Et && zn === rt && (zn = s[1]), !0;
1262
+ if (e <= Et)
1263
+ return Gi(Ot, s), !0;
1264
+ let i = s.indexOf(e) >= 0;
1265
+ if (n === t.length) return i;
1266
+ let o = 0;
1267
+ i || (e = s[o++], i = t.indexOf(e, n) >= 0);
1268
+ let r = 0;
1269
+ if (i && (t[r++] = e), o !== s.length)
1270
+ for (; n < t.length; n++) s.indexOf(t[n], o) >= 0 && (t[r++] = t[n]);
1271
+ return r > 0 ? (t.length = r, !0) : !1;
1272
+ }
1273
+ function Gi(s, t) {
1274
+ s.length = t.length;
1275
+ for (let n = 0; n < t.length; n++) s[n] = t[n];
1276
+ }
1277
+ function Ko(s, t, n, e) {
1278
+ if (t === 0) return 0;
1279
+ let i = rt, o = 0;
1280
+ for (; o < t; o++) {
1281
+ const l = Ce(s[o]);
1282
+ if (l.length !== 1) break;
1283
+ const h = l[0];
1284
+ if (!(h <= Et || h === i)) {
1285
+ if (i !== rt) break;
1286
+ i = h;
1287
+ }
1288
+ }
1289
+ if (o === t)
1290
+ return n[0] = t, e[0] = i, 1;
1291
+ kt.length = 0, Qt.length = 0, Dt = 0, zn = rt, Ot.length = 1, Ot[0] = rt, Ht = Ce(s[0]);
1292
+ let r = 1, c = s[0], a = 0;
1293
+ for (; Ot.length; ) {
1294
+ let l = !1;
1295
+ for (; r <= t; ) {
1296
+ const h = r - 1, f = c;
1297
+ tn = Ht, r === t ? r++ : (c = s[r++], Ht = Ce(c), Ht[0] === Et && Ht.length > 1 && (tn[0] === rt && (tn = Ht.slice(1)), Ht = ni(Et)));
1298
+ const u = Ho(f);
1299
+ if (u > 0)
1300
+ kt.length === Qs && (kt.shift(), Qt.shift(), Dt === Qs && Dt--), ei(Se(), !1), kt.push(f), Qt.push(rt), Dt++;
1301
+ else if (u < 0) {
1302
+ for (let p = kt.length - 1; p >= 0; p--)
1303
+ if (kt[p] === -u) {
1304
+ const y = Qt[p];
1305
+ y !== rt && (tn = ni(y));
1306
+ const _ = kt.length - 1 - p;
1307
+ kt.length -= _, Qt.length -= _, Dt = Math.max(0, Dt - _);
1308
+ break;
1309
+ }
1310
+ }
1311
+ if (!Bo()) {
1312
+ const p = Se();
1313
+ ei(p, u > 0), n[a] = h, e[a++] = p, Gi(Ot, tn), l = !0;
1314
+ break;
1315
+ }
1316
+ }
1317
+ l || (n[a] = t, e[a++] = Se(), Ot.length = 0);
1318
+ }
1319
+ return a;
1320
+ }
1321
+ const si = [];
1322
+ function Mt(s) {
1323
+ return (s.charCodeAt(0) << 24 | s.charCodeAt(1) << 16 | s.charCodeAt(2) << 8 | s.charCodeAt(3)) >>> 0;
1324
+ }
1325
+ const Yo = "Bengbng2Devadev2Gujrgjr2Gurugur2Kndaknd2Mlymmlm2Oryaory2Tamltml2Telutel2Mymrmym2", Vo = "HirakanaLaoolao Yiiiyi Nkoonko Vaiivai Zmthmath";
1326
+ function ii(s, t) {
1327
+ for (let n = 0; n < s.length; n += 8)
1328
+ if (s.substring(n, n + 4) === t) return s.substring(n + 4, n + 8);
1329
+ return "";
1330
+ }
1331
+ function Ni(s) {
1332
+ let t = si[s];
1333
+ if (!t) {
1334
+ t = [];
1335
+ const n = mn(s), e = ii(Yo, n);
1336
+ e && (e !== "mym2" && t.push(Mt(e.substring(0, 3) + "3")), t.push(Mt(e))), t.push(Mt(ii(Vo, n) || n.toLowerCase())), si[s] = t;
1337
+ }
1338
+ return t;
1339
+ }
1340
+ const Hi = 64, jn = 64, jo = ["abvm", "blwm", "mark", "mkmk", "curs", "dist", "kern"].map(Mt), Xo = Mt("kern"), oi = [Mt("DFLT"), Mt("dflt"), Mt("latn")], Ie = 0, De = 1, Pn = 2, Ut = new Uint16Array(0), Wo = new Int16Array(0), zo = new Uint32Array(0);
1341
+ class ln {
1342
+ constructor(t, n, e, i) {
1343
+ this._type = t, this._fmt = n, this._off = e, this._cov = i, this._cd1 = Ut, this._cd2 = Ut, this._cd3 = Ut, this._vf1 = 0, this._vf2 = 0, this._len1 = 0, this._len2 = 0, this._n1 = 0, this._n2 = 0, this._simple = !1, this._kx = Wo, this._ps = zo, this._sg = Ut;
1344
+ }
1345
+ }
1346
+ class Zo {
1347
+ constructor(t, n, e) {
1348
+ this._props = t, this._set = n, this._subs = e;
1349
+ let i = 0;
1350
+ for (const r of e) i = Math.max(i, r._cov.length);
1351
+ const o = new Uint8Array(i);
1352
+ for (const r of e) {
1353
+ const c = r._cov;
1354
+ for (let a = 0; a < c.length; a++) c[a] !== Gt && (o[a] = 1);
1355
+ }
1356
+ this._any = o, this._pairs = e.length > 0 && e.every((r) => r._simple);
1357
+ }
1358
+ }
1359
+ class $o {
1360
+ constructor(t, n) {
1361
+ this._lookups = t, this._kern = n;
1362
+ }
1363
+ }
1364
+ let gt = new DataView(new ArrayBuffer(0)), ri = 0, qn = 0, ci = 0, It = 0, Pt = null;
1365
+ const Re = new Int32Array(Hi * jn);
1366
+ function On(s, t, n) {
1367
+ let e = s;
1368
+ t & 1 && (C._xo[n] = C._xo[n] + gt.getInt16(e), e += 2), t & 2 && (C._yo[n] = C._yo[n] + gt.getInt16(e), e += 2), t & 4 && (C._xa[n] = C._xa[n] + gt.getInt16(e));
1369
+ }
1370
+ function Jo(s, t, n) {
1371
+ const e = C._gid, i = C._gp, o = C._xa, r = s._any, c = s._subs, a = s._props, l = s._set;
1372
+ for (let h = t; h < n; h++) {
1373
+ const f = e[h];
1374
+ if (f >= r.length || !r[f]) continue;
1375
+ const u = i[h];
1376
+ if (u & a & 14 || u & Ct && !dn(u, f, a, l)) continue;
1377
+ let p = h + 1;
1378
+ if (p >= n) break;
1379
+ const y = i[p];
1380
+ if ((y & (on | Ct) || y & a & 14) && (p = rs(h, n, a, l), p < 0))
815
1381
  continue;
1382
+ const _ = e[p];
1383
+ for (let g = 0; g < c.length; g++) {
1384
+ const x = c[g], b = x._cov, M = f < b.length ? b[f] : Gt;
1385
+ if (M === Gt) continue;
1386
+ let k = -1;
1387
+ if (x._fmt === 1) {
1388
+ if (M >= x._ps.length - 1) continue;
1389
+ const w = x._sg;
1390
+ let T = x._ps[M], D = x._ps[M + 1] - 1;
1391
+ for (; T <= D; ) {
1392
+ const m = T + D >> 1, A = w[m];
1393
+ if (A < _) T = m + 1;
1394
+ else if (A > _) D = m - 1;
1395
+ else {
1396
+ k = m;
1397
+ break;
1398
+ }
1399
+ }
1400
+ } else {
1401
+ const w = f < x._cd1.length ? x._cd1[f] : 0, T = _ < x._cd2.length ? x._cd2[_] : 0;
1402
+ w < x._n1 && T < x._n2 && (k = w * x._n2 + T);
1403
+ }
1404
+ if (!(k < 0)) {
1405
+ o[h] = o[h] + x._kx[k], h = p - 1;
1406
+ break;
1407
+ }
816
1408
  }
817
- const u = n.u16();
818
- n.skip(6);
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);
1409
+ }
1410
+ }
1411
+ function ai(s) {
1412
+ let t = 0;
1413
+ for (let n = s & 255; n; n &= n - 1) t++;
1414
+ return t * 2;
1415
+ }
1416
+ class Qo {
1417
+ /**
1418
+ * @param buffer Full font buffer.
1419
+ * @param offset Byte offset of the GPOS table.
1420
+ * @param gdef The font's GDEF (mark filtering sets), or null.
1421
+ */
1422
+ constructor(t, n, e) {
1423
+ this._lookupCache = [], this._planCache = [], this._covCache = /* @__PURE__ */ new Map(), this._cdCache = /* @__PURE__ */ new Map();
1424
+ const i = new DataView(t);
1425
+ this._view = i, this._scripts = n + i.getUint16(n + 4), this._features = n + i.getUint16(n + 6), this._lookupList = n + i.getUint16(n + 8), this._gdef = e;
1426
+ }
1427
+ /** Coverage at `base + rel` (offset 0 = HarfBuzz's Null coverage). */
1428
+ _cov(t, n) {
1429
+ if (!n) return Ut;
1430
+ let e = this._covCache.get(t + n);
1431
+ return e || (e = qi(this._view, t + n), this._covCache.set(t + n, e)), e;
1432
+ }
1433
+ /** ClassDef at `base + rel` (offset 0 = every glyph class 0). */
1434
+ _cd(t, n) {
1435
+ if (!n) return Ut;
1436
+ let e = this._cdCache.get(t + n);
1437
+ return e || (e = ts(this._view, t + n), this._cdCache.set(t + n, e)), e;
1438
+ }
1439
+ /** Absolute offset of the Script table tagged `t`, or 0. */
1440
+ _script(t) {
1441
+ const n = this._view, e = this._scripts;
1442
+ for (let i = 0, o = n.getUint16(e); i < o; i++)
1443
+ if (n.getUint32(e + 2 + 6 * i) === t) return e + n.getUint16(e + 6 + 6 * i);
1444
+ return 0;
1445
+ }
1446
+ /**
1447
+ * The lookups to apply to a run whose OpenType script tags (most
1448
+ * preferred first) are `tags`, cached under ICU script code `code`.
1449
+ * port of hb-ot-layout.cc: hb_ot_layout_table_select_script (falls back to
1450
+ * DFLT, dflt, then latn) + hb-ot-map.cc: hb_ot_map_builder_t::compile.
1451
+ */
1452
+ _plan(t, n) {
1453
+ let e = this._planCache[t];
1454
+ if (e) return e;
1455
+ const i = this._view;
1456
+ let o = 0;
1457
+ for (let l = 0; l < n.length && !o; l++) o = this._script(n[l]);
1458
+ for (let l = 0; l < oi.length && !o; l++) o = this._script(oi[l]);
1459
+ const r = [];
1460
+ let c = !1;
1461
+ const a = o ? i.getUint16(o) : 0;
1462
+ if (a) {
1463
+ const l = o + a, h = i.getUint16(l + 2), f = this._features, u = i.getUint16(f), p = i.getUint16(l + 4);
1464
+ for (let y = -1; y < p; y++) {
1465
+ const _ = y < 0 ? h : i.getUint16(l + 6 + 2 * y);
1466
+ if (_ >= u) continue;
1467
+ const g = i.getUint32(f + 2 + 6 * _);
1468
+ if (y >= 0 && jo.indexOf(g) < 0) continue;
1469
+ g === Xo && (c = !0);
1470
+ const x = f + i.getUint16(f + 6 + 6 * _);
1471
+ for (let b = 0, M = i.getUint16(x + 2); b < M; b++) {
1472
+ const k = i.getUint16(x + 4 + 2 * b);
1473
+ r.indexOf(k) < 0 && r.push(k);
1474
+ }
1475
+ }
1476
+ }
1477
+ return r.sort((l, h) => l - h), e = new $o(r, c), this._planCache[t] = e, e;
1478
+ }
1479
+ /** Lookup `li`, decoded on first use; null if out of range. */
1480
+ _lookup(t) {
1481
+ const n = this._lookupCache[t];
1482
+ if (n) return n;
1483
+ const e = this._view, i = this._lookupList;
1484
+ if (t >= e.getUint16(i)) return null;
1485
+ const o = i + e.getUint16(i + 2 + 2 * t), r = e.getUint16(o), c = e.getUint16(o + 2), a = e.getUint16(o + 4);
1486
+ let l = null;
1487
+ c & 16 && (l = this._gdef ? this._gdef._markSet(e.getUint16(o + 6 + 2 * a)) : Ut);
1488
+ const h = [];
1489
+ for (let u = 0; u < a; u++) {
1490
+ let p = o + e.getUint16(o + 6 + 2 * u), y = r;
1491
+ y === 9 && (y = e.getUint16(p + 2), p += e.getUint32(p + 4));
1492
+ const _ = this._sub(y, p);
1493
+ _ && h.push(_);
1494
+ }
1495
+ const f = new Zo(c, l, h);
1496
+ return this._lookupCache[t] = f, f;
1497
+ }
1498
+ /** Decodes one subtable; null for unsupported types/formats. */
1499
+ _sub(t, n) {
1500
+ const e = this._view, i = e.getUint16(n);
1501
+ if (t === 1 || t === 2) {
1502
+ if (i !== 1 && i !== 2) return null;
1503
+ const o = new ln(t, i, n, this._cov(n, e.getUint16(n + 2)));
1504
+ return o._vf1 = e.getUint16(n + 4), o._len1 = ai(o._vf1), t === 2 && (o._vf2 = e.getUint16(n + 6), o._len2 = ai(o._vf2), i === 2 && (o._cd1 = this._cd(n, e.getUint16(n + 8)), o._cd2 = this._cd(n, e.getUint16(n + 10)), o._n1 = e.getUint16(n + 12), o._n2 = e.getUint16(n + 14)), (o._vf1 & 15) === 4 && o._vf2 === 0 && this._decodePairs(o)), o;
1505
+ }
1506
+ if (t === 7) {
1507
+ if (i === 3) return new ln(t, i, n, this._cov(n, e.getUint16(n + 6)));
1508
+ if (i !== 1 && i !== 2) return null;
1509
+ const o = new ln(t, i, n, this._cov(n, e.getUint16(n + 2)));
1510
+ return i === 2 && (o._cd1 = this._cd(n, e.getUint16(n + 4))), o;
1511
+ }
1512
+ if (t === 8) {
1513
+ if (i === 3) {
1514
+ const r = e.getUint16(n + 2);
1515
+ return new ln(t, i, n, this._cov(n, e.getUint16(n + 6 + 2 * r)));
1516
+ }
1517
+ if (i !== 1 && i !== 2) return null;
1518
+ const o = new ln(t, i, n, this._cov(n, e.getUint16(n + 2)));
1519
+ return i === 2 && (o._cd1 = this._cd(n, e.getUint16(n + 4)), o._cd2 = this._cd(n, e.getUint16(n + 6)), o._cd3 = this._cd(n, e.getUint16(n + 8))), o;
822
1520
  }
823
- n.seek(c + r);
1521
+ return null;
1522
+ }
1523
+ /** Decodes a plain-kerning PairPos (XAdvance of the first glyph only) into typed arrays. */
1524
+ _decodePairs(t) {
1525
+ const n = this._view, e = t._off, i = t._len1;
1526
+ if (t._simple = !0, t._fmt === 2) {
1527
+ const h = t._n1 * t._n2, f = new Int16Array(h);
1528
+ for (let u = 0; u < h; u++) f[u] = n.getInt16(e + 16 + u * i);
1529
+ t._kx = f;
1530
+ return;
1531
+ }
1532
+ const o = n.getUint16(e + 8), r = new Uint32Array(o + 1);
1533
+ let c = 0;
1534
+ for (let h = 0; h < o; h++)
1535
+ r[h] = c, c += n.getUint16(e + n.getUint16(e + 10 + 2 * h));
1536
+ r[o] = c;
1537
+ const a = new Uint16Array(c), l = new Int16Array(c);
1538
+ for (let h = 0; h < o; h++) {
1539
+ const f = e + n.getUint16(e + 10 + 2 * h);
1540
+ for (let u = 0, p = r[h + 1] - r[h]; u < p; u++) {
1541
+ const y = f + 2 + u * (2 + i);
1542
+ a[r[h] + u] = n.getUint16(y), l[r[h] + u] = n.getInt16(y + 2);
1543
+ }
1544
+ }
1545
+ t._ps = r, t._sg = a, t._kx = l;
824
1546
  }
825
- return e.size === 0 ? to : (a, c) => {
826
- const r = (a & 65535) << 16 | c & 65535;
827
- return e.get(r) ?? 0;
828
- };
1547
+ /**
1548
+ * Applies `plan` to `run[start, end)`, one HarfBuzz buffer (a script run).
1549
+ * port of hb-ot-layout.cc: apply_forward, for each lookup in turn.
1550
+ */
1551
+ _position(t, n, e) {
1552
+ gt = this._view, ri = n, qn = e, ci = Math.max((e - n) * 64, 16384);
1553
+ const i = t._lookups;
1554
+ for (let o = 0; o < i.length; o++) {
1555
+ const r = this._lookup(i[o]);
1556
+ if (!r || !r._subs.length) continue;
1557
+ if (It = r._props, Pt = r._set, r._pairs) {
1558
+ Jo(r, n, e);
1559
+ continue;
1560
+ }
1561
+ const c = C._gp, a = C._gid, l = r._any;
1562
+ for (let h = n; h < e; ) {
1563
+ const f = a[h];
1564
+ if (f < l.length && l[f] && dn(c[h], f, It, Pt)) {
1565
+ const u = this._applyAt(r, h, 0);
1566
+ if (u >= 0) {
1567
+ h = u;
1568
+ continue;
1569
+ }
1570
+ }
1571
+ h++;
1572
+ }
1573
+ }
1574
+ }
1575
+ /** First subtable of `lk` that applies at `i`: returns the next index, or −1. */
1576
+ _applyAt(t, n, e) {
1577
+ const i = t._subs;
1578
+ for (let o = 0; o < i.length; o++) {
1579
+ const r = this._applySub(i[o], n, e);
1580
+ if (r >= 0) return r;
1581
+ }
1582
+ return -1;
1583
+ }
1584
+ /** One subtable at glyph `i`: returns the index to continue from, or −1. */
1585
+ _applySub(t, n, e) {
1586
+ const i = C._gid[n], o = t._cov, r = i < o.length ? o[i] : Gt;
1587
+ if (r === Gt) return -1;
1588
+ const c = gt, a = t._off;
1589
+ switch (t._type) {
1590
+ case 1: {
1591
+ if (t._fmt === 1)
1592
+ On(a + 6, t._vf1, n);
1593
+ else {
1594
+ if (r >= c.getUint16(a + 6)) return -1;
1595
+ On(a + 8 + r * t._len1, t._vf1, n);
1596
+ }
1597
+ return n + 1;
1598
+ }
1599
+ case 2: {
1600
+ let l = n + 1;
1601
+ if (l >= qn) return -1;
1602
+ const h = C._gp[l];
1603
+ if ((h & (on | Ct) || h & It & 14) && (l = rs(n, qn, It, Pt), l < 0))
1604
+ return -1;
1605
+ const f = C._gid[l];
1606
+ if (t._simple) {
1607
+ const p = t._kx;
1608
+ if (t._fmt === 1) {
1609
+ if (r >= t._ps.length - 1) return -1;
1610
+ const g = t._sg;
1611
+ let x = t._ps[r], b = t._ps[r + 1] - 1;
1612
+ for (; x <= b; ) {
1613
+ const M = x + b >> 1, k = g[M];
1614
+ if (k < f) x = M + 1;
1615
+ else if (k > f) b = M - 1;
1616
+ else
1617
+ return C._xa[n] = C._xa[n] + p[M], l;
1618
+ }
1619
+ return -1;
1620
+ }
1621
+ const y = i < t._cd1.length ? t._cd1[i] : 0, _ = f < t._cd2.length ? t._cd2[f] : 0;
1622
+ return y >= t._n1 || _ >= t._n2 ? -1 : (C._xa[n] = C._xa[n] + p[y * t._n2 + _], l);
1623
+ }
1624
+ let u;
1625
+ if (t._fmt === 1) {
1626
+ if (r >= c.getUint16(a + 8)) return -1;
1627
+ const p = a + c.getUint16(a + 10 + 2 * r), y = 2 + t._len1 + t._len2;
1628
+ let _ = 0, g = c.getUint16(p) - 1;
1629
+ for (u = -1; _ <= g; ) {
1630
+ const x = _ + g >> 1, b = p + 2 + x * y, M = c.getUint16(b);
1631
+ if (M < f) _ = x + 1;
1632
+ else if (M > f) g = x - 1;
1633
+ else {
1634
+ u = b + 2;
1635
+ break;
1636
+ }
1637
+ }
1638
+ if (u < 0) return -1;
1639
+ } else {
1640
+ const p = i < t._cd1.length ? t._cd1[i] : 0, y = f < t._cd2.length ? t._cd2[f] : 0;
1641
+ if (p >= t._n1 || y >= t._n2) return -1;
1642
+ u = a + 16 + (p * t._n2 + y) * (t._len1 + t._len2);
1643
+ }
1644
+ return t._vf1 && On(u, t._vf1, n), t._vf2 && On(u + t._len1, t._vf2, l), t._len2 ? l + 1 : l;
1645
+ }
1646
+ case 7:
1647
+ return this._context(t, n, i, r, e);
1648
+ case 8:
1649
+ return this._chain(t, n, i, r, e);
1650
+ }
1651
+ return -1;
1652
+ }
1653
+ /** port of ContextFormat1/2/3::apply (SequenceContext). */
1654
+ _context(t, n, e, i, o) {
1655
+ const r = gt, c = t._off;
1656
+ if (t._fmt === 3) {
1657
+ const p = r.getUint16(c + 2), y = this._input(n, p, Pn, Ut, c + 8, c, o);
1658
+ return y < 0 ? -1 : (this._apply(c + 6 + 2 * p, r.getUint16(c + 4), p, o), y);
1659
+ }
1660
+ let a = i, l = c + 4, h = Ie;
1661
+ if (t._fmt === 2 && (a = e < t._cd1.length ? t._cd1[e] : 0, l = c + 6, h = De), a >= r.getUint16(l)) return -1;
1662
+ const f = r.getUint16(l + 2 + 2 * a);
1663
+ if (!f) return -1;
1664
+ const u = c + f;
1665
+ for (let p = 0, y = r.getUint16(u); p < y; p++) {
1666
+ const _ = u + r.getUint16(u + 2 + 2 * p), g = r.getUint16(_), x = this._input(n, g, h, t._cd1, _ + 4, 0, o);
1667
+ if (!(x < 0))
1668
+ return this._apply(_ + 4 + 2 * Math.max(g - 1, 0), r.getUint16(_ + 2), g, o), x;
1669
+ }
1670
+ return -1;
1671
+ }
1672
+ /** port of ChainContextFormat1/2/3::apply (ChainedSequenceContext). */
1673
+ _chain(t, n, e, i, o) {
1674
+ const r = gt, c = t._off;
1675
+ if (t._fmt === 3) {
1676
+ let p = c + 2;
1677
+ const y = r.getUint16(p), _ = p + 2;
1678
+ p += 2 + 2 * y;
1679
+ const g = r.getUint16(p), x = p + 2;
1680
+ p += 2 + 2 * g;
1681
+ const b = r.getUint16(p), M = p + 2;
1682
+ p += 2 + 2 * b;
1683
+ const k = this._input(n, g, Pn, Ut, x + 2, c, o);
1684
+ return k < 0 || !this._lookahead(k, b, Pn, Ut, M, c) || !this._backtrack(n, y, Pn, Ut, _, c) ? -1 : (this._apply(p + 2, r.getUint16(p), g, o), k);
1685
+ }
1686
+ let a = i, l = c + 4, h = Ie;
1687
+ if (t._fmt === 2 && (a = e < t._cd2.length ? t._cd2[e] : 0, l = c + 10, h = De), a >= r.getUint16(l)) return -1;
1688
+ const f = r.getUint16(l + 2 + 2 * a);
1689
+ if (!f) return -1;
1690
+ const u = c + f;
1691
+ for (let p = 0, y = r.getUint16(u); p < y; p++) {
1692
+ let _ = u + r.getUint16(u + 2 + 2 * p);
1693
+ const g = r.getUint16(_), x = _ + 2;
1694
+ _ += 2 + 2 * g;
1695
+ const b = r.getUint16(_), M = _ + 2;
1696
+ _ += 2 + 2 * Math.max(b - 1, 0);
1697
+ const k = r.getUint16(_), w = _ + 2;
1698
+ _ += 2 + 2 * k;
1699
+ const T = this._input(n, b, h, t._cd2, M, 0, o);
1700
+ if (!(T < 0) && this._lookahead(T, k, h, t._cd3, w, 0) && this._backtrack(n, g, h, t._cd1, x, 0))
1701
+ return this._apply(_ + 2, r.getUint16(_), b, o), T;
1702
+ }
1703
+ return -1;
1704
+ }
1705
+ /** Whether glyph `g` matches rule item `v` (glyph id, class, or coverage offset from `base`). */
1706
+ _matches(t, n, e, i, o) {
1707
+ if (t === Ie) return o === i;
1708
+ if (t === De) return (o < n.length ? n[o] : 0) === i;
1709
+ const r = this._cov(e, i);
1710
+ return o < r.length && r[o] !== Gt;
1711
+ }
1712
+ /**
1713
+ * Next glyph after `j` matching item `v`, or −1 (skipping_iterator_t::next
1714
+ * with a match function): ignored glyphs are skipped; a default ignorable
1715
+ * is skipped unless it matches; any other mismatch fails.
1716
+ */
1717
+ _next(t, n, e, i, o) {
1718
+ const r = C._gp, c = C._gid;
1719
+ for (let a = t + 1; a < qn; a++) {
1720
+ const l = r[a], h = c[a];
1721
+ if (dn(l, h, It, Pt)) {
1722
+ if (this._matches(n, e, i, o, h)) return a;
1723
+ if (!(l & on))
1724
+ return -1;
1725
+ }
1726
+ }
1727
+ return -1;
1728
+ }
1729
+ /** skipping_iterator_t::prev counterpart of {@link Gpos._next}. */
1730
+ _prev(t, n, e, i, o) {
1731
+ const r = C._gp, c = C._gid;
1732
+ for (let a = t - 1; a >= ri; a--) {
1733
+ const l = r[a], h = c[a];
1734
+ if (dn(l, h, It, Pt)) {
1735
+ if (this._matches(n, e, i, o, h)) return a;
1736
+ if (!(l & on))
1737
+ return -1;
1738
+ }
1739
+ }
1740
+ return -1;
1741
+ }
1742
+ /**
1743
+ * port of match_input: matches input items 1..count−1 (u16 values from
1744
+ * `seq`) after glyph `i`; records match positions for this nesting level.
1745
+ * Returns the match end (exclusive), or −1.
1746
+ */
1747
+ _input(t, n, e, i, o, r, c) {
1748
+ if (n > jn) return -1;
1749
+ const a = c * jn;
1750
+ Re[a] = t;
1751
+ let l = t;
1752
+ for (let h = 1; h < n; h++) {
1753
+ if (l = this._next(l, e, i, r, gt.getUint16(o + 2 * (h - 1))), l < 0) return -1;
1754
+ Re[a + h] = l;
1755
+ }
1756
+ return l + 1;
1757
+ }
1758
+ /** port of match_lookahead, starting at `end`. */
1759
+ _lookahead(t, n, e, i, o, r) {
1760
+ let c = t - 1;
1761
+ for (let a = 0; a < n; a++)
1762
+ if (c = this._next(c, e, i, r, gt.getUint16(o + 2 * a)), c < 0) return !1;
1763
+ return !0;
1764
+ }
1765
+ /** port of match_backtrack (item 0 is the glyph right before `i`). */
1766
+ _backtrack(t, n, e, i, o, r) {
1767
+ let c = t;
1768
+ for (let a = 0; a < n; a++)
1769
+ if (c = this._prev(c, e, i, r, gt.getUint16(o + 2 * a)), c < 0) return !1;
1770
+ return !0;
1771
+ }
1772
+ /**
1773
+ * port of apply_lookup (GPOS: the buffer never changes length): applies
1774
+ * each SequenceLookupRecord at its matched position, in design order.
1775
+ */
1776
+ _apply(t, n, e, i) {
1777
+ const o = i * jn;
1778
+ for (let r = 0; r < n; r++) {
1779
+ const c = gt.getUint16(t + 4 * r);
1780
+ if (c >= e || i + 1 >= Hi || ci-- <= 0) continue;
1781
+ const a = this._lookup(gt.getUint16(t + 4 * r + 2));
1782
+ if (!a) continue;
1783
+ const l = It, h = Pt;
1784
+ It = a._props, Pt = a._set, this._applyAt(a, Re[o + c], i + 1), It = l, Pt = h;
1785
+ }
1786
+ }
1787
+ }
1788
+ function tr(s) {
1789
+ if (s < 173) return !1;
1790
+ if (s < 65536) {
1791
+ switch (s >> 8) {
1792
+ case 0:
1793
+ return s === 173;
1794
+ case 3:
1795
+ return s === 847;
1796
+ case 6:
1797
+ return s === 1564;
1798
+ case 23:
1799
+ return s >= 6068 && s <= 6069;
1800
+ case 24:
1801
+ return s >= 6155 && s <= 6159;
1802
+ case 32:
1803
+ return s >= 8203 && s <= 8207 || s >= 8234 && s <= 8238 || s >= 8288 && s <= 8303;
1804
+ case 254:
1805
+ return s >= 65024 && s <= 65039 || s === 65279;
1806
+ case 255:
1807
+ return s >= 65520 && s <= 65528;
1808
+ }
1809
+ return !1;
1810
+ }
1811
+ return s >= 119155 && s <= 119162 || s >= 917504 && s <= 921599;
1812
+ }
1813
+ function nr(s, t, n) {
1814
+ const e = s.metrics.unitsPerEm;
1815
+ switch (t) {
1816
+ case 160:
1817
+ return s.advance(n);
1818
+ case 8193:
1819
+ case 8195:
1820
+ case 12288:
1821
+ return e;
1822
+ case 8192:
1823
+ case 8194:
1824
+ return e / 2;
1825
+ case 8196:
1826
+ return e / 3;
1827
+ case 8197:
1828
+ return e / 4;
1829
+ case 8198:
1830
+ return e / 6;
1831
+ case 8201:
1832
+ return e / 5;
1833
+ case 8202:
1834
+ return e / 16;
1835
+ case 8287:
1836
+ return e * 4 / 18;
1837
+ case 8239:
1838
+ return s.advance(n) / 2;
1839
+ case 8199: {
1840
+ for (let i = 48; i <= 57; i++) {
1841
+ const o = s.glyphId(i);
1842
+ if (o) return s.advance(o);
1843
+ }
1844
+ return s.advance(n);
1845
+ }
1846
+ case 8200: {
1847
+ const i = s.glyphId(46) || s.glyphId(44);
1848
+ return s.advance(i || n);
1849
+ }
1850
+ }
1851
+ return -1;
1852
+ }
1853
+ let Le = null;
1854
+ const li = /* @__PURE__ */ new Map();
1855
+ function er(s) {
1856
+ if (s < 768) return !1;
1857
+ let t = li.get(s);
1858
+ return t === void 0 && (Le || (Le = new RegExp("^\\p{Mn}$", "u")), t = Le.test(String.fromCodePoint(s)), li.set(s, t)), t;
1859
+ }
1860
+ function sr(s, t) {
1861
+ const n = t.length;
1862
+ Fi(n);
1863
+ const e = C._cp, i = C._gid, o = C._gp, r = C._xa, c = C._xo, a = C._yo, l = s._glyphProps(), h = s._advances(), f = h.length ? h[h.length - 1] : 0, u = s.glyphId(32);
1864
+ let p = !1, y = 0, _ = 0;
1865
+ for (let M = 0; M < n; M++) {
1866
+ let k = t.charCodeAt(M);
1867
+ if (k >= 55296 && k < 56320 && M + 1 < n) {
1868
+ const A = t.charCodeAt(M + 1);
1869
+ A >= 56320 && A < 57344 && (k = (k - 55296 << 10) + (A - 56320) + 65536, M++);
1870
+ }
1871
+ let w = s.glyphId(k), T = -1;
1872
+ !w && k >= 160 && u && ((k === 8192 || k === 8193) && (w = s.glyphId(k + 2)), w || (T = nr(s, k, u), T >= 0 && (w = u)));
1873
+ const D = k >= 173 && tr(k);
1874
+ let m;
1875
+ l ? m = w < l.length ? l[w] : 0 : m = !D && er(k) ? Ct : Xn, D && (m |= k === 8204 ? xn : xn | on, p = !0), y |= m, e[_] = k, i[_] = w, o[_] = m, r[_] = T >= 0 ? T : w < h.length ? h[w] : f, c[_] = 0, a[_] = 0, _++;
1876
+ }
1877
+ const g = Ko(e, _, C._runEnd, C._runScript), x = (y & Ct) !== 0;
1878
+ let b = 0;
1879
+ for (let M = 0; M < g; M++) {
1880
+ const k = C._runEnd[M];
1881
+ Vi(s, b, k, C._runScript[M], x), b = k;
1882
+ }
1883
+ if (p)
1884
+ for (let M = 0; M < _; M++) o[M] & xn && (r[M] = c[M] = a[M] = 0);
1885
+ return _;
1886
+ }
1887
+ const cs = 0, Bi = 1, as = 2, ir = 3, ls = 4, Gn = as | ls, or = cs | ls, rr = as, hi = cs, Fe = Bi, cr = "BengDevaGujrGuruKndaMlymOryaTamlTelu", ar = "TibtMongSinhBuhdHanoTglgTagbLimbTaleBugiKharSyloTfngBaliNkooPhagChamKaliLepcRjngSaurSundEgypJavaKthiMteiLanaTavtBatkBrahMandCakmPlrdShrdTakrDuplGranKhojSindMahjManiModiHmngPhlpSiddTirhAhomMultAdlmBhksMarcNewaGonmSoyoZanbDogrGongRohgMakaMedfSogoSogdElymNandHmnpWchoChrsDiakKitsYeziCpmnOugrTnsaTotoVithKawiNagmGaraGukhKraiOnaoSunuTodrTutgBerfSidtTayoTolsJurcPcunSeal", Ki = Mt("DFLT"), Yi = Mt("latn"), lr = Mt("mymr"), fi = [Ki, Mt("dflt"), Yi];
1888
+ function hr(s, t) {
1889
+ if (!s) return 0;
1890
+ for (let n = 0; n < t.length; n++) if (s.indexOf(t[n]) >= 0) return t[n];
1891
+ for (let n = 0; n < 3; n++)
1892
+ if (s.indexOf(fi[n]) >= 0) return fi[n];
1893
+ return 0;
1894
+ }
1895
+ function fr(s, t) {
1896
+ const n = t === Ki || t === Yi;
1897
+ return s === "Thai" || s === "Laoo" ? rr : s === "Hang" ? or : s === "Khmr" ? hi : s === "Mymr" ? n || t === lr ? Gn : Fe : cr.indexOf(s) >= 0 ? n ? Gn : (t & 255) === 51 ? Fe : hi : ar.indexOf(s) >= 0 ? n ? Gn : Fe : Gn;
1898
+ }
1899
+ function ur(s, t) {
1900
+ const n = s._shaperCache();
1901
+ let e = n[t];
1902
+ return e < 0 && (e = fr(mn(t), hr(s._gsubScriptTags(), Ni(t))), n[t] = e), e;
1903
+ }
1904
+ function ui(s, t, n) {
1905
+ const e = C._gp, i = C._xa, o = C._xo;
1906
+ for (let r = s; r < t; r++)
1907
+ e[r] & Ct && (n && (o[r] = o[r] - i[r]), i[r] = 0);
1908
+ }
1909
+ function Vi(s, t, n, e, i) {
1910
+ const o = ur(s, e), r = s._gposTable(), c = s._kernTable(), a = r ? r._plan(e, Ni(e)) : null, l = c !== null && c._hasData && !(a && a._kern) && (o & ls) !== 0, h = !i || l && c._hasMachine ? cs : o & ir, f = !r && (!l || !c._hasCross);
1911
+ h === Bi && ui(t, n, f), a && r._position(a, t, n), l && c._apply(t, n), h === as && ui(t, n, f);
829
1912
  }
830
- const to = () => 0;
831
- function le(o) {
832
- const t = new wt(o);
1913
+ function pr(s, t, n) {
1914
+ Fi(2);
1915
+ const e = s._glyphProps(), i = s.advance(t), o = s.advance(n);
1916
+ return C._gid[0] = t, C._gid[1] = n, C._gp[0] = e ? t < e.length ? e[t] : 0 : Xn, C._gp[1] = e ? n < e.length ? e[n] : 0 : Xn, C._xa[0] = i, C._xa[1] = o, C._xo[0] = C._xo[1] = C._yo[0] = C._yo[1] = 0, Vi(s, 0, 2, rt, ((C._gp[0] | C._gp[1]) & Ct) !== 0), C._xa[0] + C._xa[1] - i - o;
1917
+ }
1918
+ function _r(s) {
1919
+ const t = new St(s);
833
1920
  if (t.u32() === 1953784678) {
834
1921
  if (t.skip(4), t.u32() === 0) throw new Error("TTC contains no fonts");
835
1922
  const i = t.u32();
836
1923
  t.seek(i);
837
1924
  } else
838
1925
  t.seek(0);
839
- return he(o, t);
1926
+ return yr(s, t);
840
1927
  }
841
- function he(o, t) {
1928
+ function yr(s, t) {
842
1929
  t.skip(4);
843
1930
  const n = t.u16();
844
1931
  t.skip(6);
845
- const s = /* @__PURE__ */ new Map();
1932
+ const e = /* @__PURE__ */ new Map();
846
1933
  for (let i = 0; i < n; i++) {
847
- const e = String.fromCharCode(t.u8(), t.u8(), t.u8(), t.u8());
1934
+ const o = String.fromCharCode(t.u8(), t.u8(), t.u8(), t.u8());
848
1935
  t.skip(4);
849
- const a = t.u32(), c = t.u32();
850
- s.set(e, { offset: a, length: c });
1936
+ const r = t.u32(), c = t.u32();
1937
+ e.set(o, { offset: r, length: c });
851
1938
  }
852
- return s;
1939
+ return e;
853
1940
  }
854
- class pe {
1941
+ const pi = 2048, gr = 65536;
1942
+ class xr {
855
1943
  /**
856
1944
  * Parses a TrueType font from an ArrayBuffer.
857
1945
  *
@@ -862,19 +1950,17 @@ class pe {
862
1950
  * @param buffer Raw font file bytes.
863
1951
  */
864
1952
  constructor(t) {
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");
1953
+ this._buffer = t, this._tables = _r(t);
1954
+ const n = this._tables.get("head"), e = this._tables.get("maxp"), i = this._tables.get("hhea"), o = this._tables.get("hmtx"), r = this._tables.get("loca"), c = this._tables.get("cmap");
867
1955
  if (!n) throw new Error("Font missing required `head` table");
868
- if (!s) throw new Error("Font missing required `maxp` table");
1956
+ if (!e) throw new Error("Font missing required `maxp` table");
869
1957
  if (!i) throw new Error("Font missing required `hhea` table");
870
- if (!e) throw new Error("Font missing required `hmtx` table");
871
- if (!a) throw new Error("Font missing required `loca` table");
1958
+ if (!o) throw new Error("Font missing required `hmtx` table");
1959
+ if (!r) throw new Error("Font missing required `loca` table");
872
1960
  if (!c) throw new Error("Font missing required `cmap` table");
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
- const h = this._tables.get("kern");
877
- this._kern = h ? ae(t, h.offset) : () => 0, this.metrics = {
1961
+ this._head = eo(t, n.offset);
1962
+ const a = ro(t, e.offset);
1963
+ this._hhea = so(t, i.offset), this._hmtx = io(t, o.offset, a.numGlyphs, this._hhea.numberOfHMetrics), this._loca = oo(t, r.offset, a.numGlyphs, this._head.indexToLocFormat), this._cmap = Qi(t, c.offset), this._cmapCache = null, this._layoutLoaded = !1, this._gdef = null, this._gpos = null, this._kern = null, this._gsubScripts = null, this._shapers = null, this._advanceTable = null, this._pairCache = /* @__PURE__ */ new Map(), this.metrics = {
878
1964
  unitsPerEm: this._head.unitsPerEm,
879
1965
  ascender: this._hhea.ascender,
880
1966
  descender: this._hhea.descender,
@@ -888,7 +1974,11 @@ class pe {
888
1974
  * @param codepoint Unicode scalar value.
889
1975
  */
890
1976
  glyphId(t) {
891
- return this._cmap(t);
1977
+ if (t >= pi || t < 0) return this._cmap(t);
1978
+ let n = this._cmapCache;
1979
+ n || (n = this._cmapCache = new Uint16Array(pi));
1980
+ let e = n[t];
1981
+ return e || (n[t] = e = this._cmap(t) + 1), e - 1;
892
1982
  }
893
1983
  /**
894
1984
  * Total glyph count (`maxp.numGlyphs`), including `.notdef` at index 0.
@@ -918,14 +2008,63 @@ class pe {
918
2008
  return (this._hmtx[t] ?? this._hmtx[this._hmtx.length - 1] ?? { lsb: 0 }).lsb;
919
2009
  }
920
2010
  /**
921
- * Kerning adjustment between two glyphs in font units.
922
- * Returns 0 if the font has no kern table or the pair is not listed.
2011
+ * Kerning between two glyphs in font units: how much positioning the pair
2012
+ * on its own changes its total advance (GPOS `kern` and other default
2013
+ * positioning features, else the legacy `kern` table, as Chrome applies
2014
+ * them). Pairwise only — {@link Atlas.layout} kerns whole runs, which also
2015
+ * accounts for script runs and contextual kerning.
923
2016
  *
924
2017
  * @param leftGlyphId Left glyph index.
925
2018
  * @param rightGlyphId Right glyph index.
2019
+ * @returns Advance adjustment in font units, 0 for an unkerned pair.
926
2020
  */
927
2021
  kerning(t, n) {
928
- return this._kern(t, n);
2022
+ const e = t < 32768 && n < 32768 ? t << 15 | n : -1 - (t * 65536 + n), i = this._pairCache.get(e);
2023
+ return i !== void 0 ? i : this._kerningMiss(e, t, n);
2024
+ }
2025
+ /** {@link Font.kerning}'s cache miss, kept out of line so the hit path stays small. */
2026
+ _kerningMiss(t, n, e) {
2027
+ const i = pr(this, n, e);
2028
+ return this._pairCache.size >= gr && this._pairCache.clear(), this._pairCache.set(t, i), i;
2029
+ }
2030
+ /** Parses GDEF, GPOS, kern and GSUB's script list on first use (keeps `new Font` cheap). */
2031
+ _loadLayout() {
2032
+ if (this._layoutLoaded) return;
2033
+ this._layoutLoaded = !0;
2034
+ const t = this._buffer, n = this._tables.get("GDEF"), e = this._tables.get("GPOS"), i = this._tables.get("kern"), o = this._tables.get("GSUB");
2035
+ n && (this._gdef = new Fo(t, n.offset, this.numGlyphs)), e && (this._gpos = new Qo(t, e.offset, this._gdef)), i && (this._kern = new Ro(t, i.offset)), o && (this._gsubScripts = Lo(new DataView(t), o.offset));
2036
+ }
2037
+ /** @internal GSUB's script tags, or null when the font has no GSUB. */
2038
+ _gsubScriptTags() {
2039
+ return this._loadLayout(), this._gsubScripts;
2040
+ }
2041
+ /** @internal Per-script shaper flags cache (see shaper.ts: shaperOf), -1 = unset. */
2042
+ _shaperCache() {
2043
+ let t = this._shapers;
2044
+ return t || (t = this._shapers = new Int8Array(Vn).fill(-1)), t;
2045
+ }
2046
+ /** @internal Advance widths by glyph id (dense copy of `hmtx` for layout). */
2047
+ _advances() {
2048
+ let t = this._advanceTable;
2049
+ if (!t) {
2050
+ const n = this._hmtx.length;
2051
+ t = new Uint16Array(n);
2052
+ for (let e = 0; e < n; e++) t[e] = this._hmtx[e].advanceWidth;
2053
+ this._advanceTable = t;
2054
+ }
2055
+ return t;
2056
+ }
2057
+ /** @internal GDEF glyph props per glyph, or null (classes are then synthesized). */
2058
+ _glyphProps() {
2059
+ return this._loadLayout(), this._gdef ? this._gdef._props : null;
2060
+ }
2061
+ /** @internal The GPOS table, or null. */
2062
+ _gposTable() {
2063
+ return this._loadLayout(), this._gpos;
2064
+ }
2065
+ /** @internal The legacy kern table, or null. */
2066
+ _kernTable() {
2067
+ return this._loadLayout(), this._kern;
929
2068
  }
930
2069
  /**
931
2070
  * Parses and returns the outline of a glyph as a Shape (raw font units, y-up).
@@ -942,12 +2081,12 @@ class pe {
942
2081
  shape(t) {
943
2082
  const n = this._tables.get("glyf");
944
2083
  if (!n) return { contours: [], inverseYAxis: !1 };
945
- const s = this._loca, i = s[t] ?? 0, a = (s[t + 1] ?? i) - i;
946
- return se(
2084
+ const e = this._loca, i = e[t] ?? 0, r = (e[t + 1] ?? i) - i;
2085
+ return To(
947
2086
  this._buffer,
948
2087
  n.offset,
949
2088
  i,
950
- a,
2089
+ r,
951
2090
  (c) => this._glyphRaw(c)
952
2091
  );
953
2092
  }
@@ -960,820 +2099,820 @@ class pe {
960
2099
  _glyphRaw(t) {
961
2100
  const n = this._tables.get("glyf");
962
2101
  if (!n) return [];
963
- const s = this._loca, i = s[t] ?? 0, a = (s[t + 1] ?? i) - i;
964
- return Ao(
2102
+ const e = this._loca, i = e[t] ?? 0, r = (e[t + 1] ?? i) - i;
2103
+ return Li(
965
2104
  this._buffer,
966
2105
  n.offset,
967
2106
  i,
968
- a,
2107
+ r,
969
2108
  (c) => this._glyphRaw(c)
970
2109
  );
971
2110
  }
972
2111
  }
973
- function fe(o, t) {
2112
+ function dr(s, t) {
974
2113
  const n = 1 / t;
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));
2114
+ for (const e of s.contours)
2115
+ for (let i = 0; i < e.length; i++) {
2116
+ const o = e[i];
2117
+ if (o.p0x *= n, o.p0y *= n, o.p1x *= n, o.p1y *= n, o.p2x *= n, o.p2y *= n, o.p3x *= n, o.p3y *= n, o.type === at) {
2118
+ const r = o.p1x - o.p0x, c = o.p1y - o.p0y, a = o.p2x - o.p1x, l = o.p2y - o.p1y;
2119
+ z(r, c, a, l) === 0 && (e[i] = new ot(ft, o.p0x, o.p0y, o.p2x, o.p2y, 0, 0, 0, 0));
2120
+ } else if (o.type === nn) {
2121
+ const r = o.p2x - o.p1x, c = o.p2y - o.p1y, a = 1.5 * o.p1x - 0.5 * o.p0x, l = 1.5 * o.p1y - 0.5 * o.p0y;
2122
+ z(o.p1x - o.p0x, o.p1y - o.p0y, r, c) === 0 && z(r, c, o.p3x - o.p2x, o.p3y - o.p2y) === 0 ? e[i] = new ot(ft, o.p0x, o.p0y, o.p3x, o.p3y, 0, 0, 0, 0) : a === 1.5 * o.p2x - 0.5 * o.p3x && l === 1.5 * o.p2y - 0.5 * o.p3y && (e[i] = new ot(at, o.p0x, o.p0y, a, l, o.p3x, o.p3y, 0, 0));
984
2123
  }
985
2124
  }
986
2125
  }
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:
2126
+ const _i = 1e-6, Mr = 1.1111111111111112, wr = new Float64Array(16);
2127
+ function yi(s, t, n) {
2128
+ switch (t[n] = s.p0x, t[n + 1] = s.p0y, t[n + 2] = s.p1x, t[n + 3] = s.p1y, s.type) {
2129
+ case ft:
991
2130
  return 1;
992
- case ct:
993
- return t[n + 4] = o.p2x, t[n + 5] = o.p2y, 2;
2131
+ case at:
2132
+ return t[n + 4] = s.p2x, t[n + 5] = s.p2y, 2;
994
2133
  default:
995
- return t[n + 4] = o.p2x, t[n + 5] = o.p2y, t[n + 6] = o.p3x, t[n + 7] = o.p3y, 3;
2134
+ return t[n + 4] = s.p2x, t[n + 5] = s.p2y, t[n + 6] = s.p3x, t[n + 7] = s.p3y, 3;
996
2135
  }
997
2136
  }
998
- function oo(o, t, n) {
2137
+ function gi(s, t, n) {
999
2138
  if (n === 3) {
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);
2139
+ const e = s[t], i = s[t + 1], o = s[t + 2], r = s[t + 3], c = s[t + 4], a = s[t + 5], l = s[t + 6], h = s[t + 7];
2140
+ (o === e && r === i || o === l && r === h) && (c === e && a === i || c === l && a === h) && (s[t + 2] = l, s[t + 3] = h, n = 1);
1002
2141
  }
1003
2142
  if (n === 2) {
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;
1019
- }
1020
- if (s >= 3) {
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 - _;
2143
+ const e = s[t], i = s[t + 1], o = s[t + 2], r = s[t + 3], c = s[t + 4], a = s[t + 5];
2144
+ (o === e && r === i || o === c && r === a) && (s[t + 2] = c, s[t + 3] = a, n = 1);
2145
+ }
2146
+ return n === 1 && s[t] === s[t + 2] && s[t + 1] === s[t + 3] && (n = 0), n;
2147
+ }
2148
+ function Ar(s, t) {
2149
+ const n = wr;
2150
+ let e = yi(s, n, 0), i = yi(t, n, 8);
2151
+ if (!(e >= 1 && e <= 3 && i >= 1 && i <= 3) || n[e * 2] !== n[8] || n[e * 2 + 1] !== n[9]) return 0;
2152
+ e = gi(n, 0, e), i = gi(n, 8, i);
2153
+ const o = n[e * 2], r = n[e * 2 + 1];
2154
+ let c = 0, a = 0, l = 0, h = 0, f = 0, u = 0, p = 0, y = 0, _ = 0, g = 0, x = 0, b = 0;
2155
+ if (e >= 1 && (c = n[(e - 1) * 2] - o, a = n[(e - 1) * 2 + 1] - r), e >= 2) {
2156
+ const j = n[(e - 2) * 2] - n[(e - 1) * 2], W = n[(e - 2) * 2 + 1] - n[(e - 1) * 2 + 1];
2157
+ l = j - c, h = W - a;
2158
+ }
2159
+ if (e >= 3) {
2160
+ const j = n[(e - 3) * 2] - n[(e - 2) * 2], W = n[(e - 3) * 2 + 1] - n[(e - 2) * 2 + 1], et = n[(e - 2) * 2] - n[(e - 1) * 2], st = n[(e - 2) * 2 + 1] - n[(e - 1) * 2 + 1];
2161
+ f = j - et - l, u = W - st - h, l *= 3, h *= 3;
2162
+ }
2163
+ if (i >= 1 && (p = n[10] - o, y = n[11] - r), i >= 2) {
2164
+ const j = n[12] - n[10], W = n[13] - n[11];
2165
+ _ = j - p, g = W - y;
1027
2166
  }
1028
2167
  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, _);
2168
+ const j = n[14] - n[12], W = n[15] - n[13], et = n[12] - n[10], st = n[13] - n[11];
2169
+ x = j - et - _, b = W - st - g, _ *= 3, g *= 3;
2170
+ }
2171
+ c *= e, a *= e, p *= i, y *= i;
2172
+ const M = c !== 0 || a !== 0;
2173
+ if (M && (p !== 0 || y !== 0)) {
2174
+ const j = Math.sqrt(c * c + a * a), W = Math.sqrt(p * p + y * y), et = j * z(c, a, _, g) + W * z(l, h, p, y);
2175
+ if (et) return pt(et);
2176
+ const st = j * j * z(c, a, x, b) + j * W * z(l, h, _, g) + W * W * z(f, u, p, y);
1038
2177
  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;
1061
- }
1062
- if (e.type === Gt)
2178
+ const Lt = j * z(l, h, x, b) + W * z(f, u, _, g);
2179
+ return pt(Lt || z(f, u, x, b));
2180
+ }
2181
+ let w = 1, T = l, D = h, m = f, A = u, d = p, R = y, S = _, E = g, I = x, F = b;
2182
+ if (M && (T = _, D = g, m = x, A = b, d = c, R = a, S = l, E = h, I = f, F = u, w = -1), d !== 0 || R !== 0) {
2183
+ const j = z(m, A, d, R);
2184
+ if (j) return w * pt(j);
2185
+ const W = z(T, D, S, E);
2186
+ if (W) return w * pt(W);
2187
+ const et = z(m, A, S, E);
2188
+ if (et) return w * pt(et);
2189
+ const st = z(T, D, I, F);
2190
+ return st ? w * pt(st) : w * pt(z(m, A, I, F));
2191
+ }
2192
+ const V = Math.sqrt(T * T + D * D), B = Math.sqrt(S * S + E * E), nt = Math.sqrt(V) * z(T, D, I, F) + Math.sqrt(B) * z(m, A, S, E);
2193
+ return pt(nt || z(m, A, I, F));
2194
+ }
2195
+ function xi(s, t, n, e, i) {
2196
+ let o = s[t];
2197
+ if (o.type === at) {
2198
+ const r = o.convertToCubic();
2199
+ s[t] = r, o = r;
2200
+ }
2201
+ if (o.type === nn)
1063
2202
  if (n === 0) {
1064
- const a = Math.sqrt((e.p1x - e.p0x) ** 2 + (e.p1y - e.p0y) ** 2);
1065
- e.p1x += a * s, e.p1y += a * i;
2203
+ const r = Math.sqrt((o.p1x - o.p0x) ** 2 + (o.p1y - o.p0y) ** 2);
2204
+ o.p1x += r * e, o.p1y += r * i;
1066
2205
  } else {
1067
- const a = Math.sqrt((e.p2x - e.p3x) ** 2 + (e.p2y - e.p3y) ** 2);
1068
- e.p2x += a * s, e.p2y += a * i;
2206
+ const r = Math.sqrt((o.p2x - o.p3x) ** 2 + (o.p2y - o.p3y) ** 2);
2207
+ o.p2x += r * e, o.p2y += r * i;
1069
2208
  }
1070
2209
  }
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];
1075
- let s = 0;
2210
+ const hn = [0, 0], fn = [0, 0];
2211
+ function br(s) {
2212
+ for (let t = 0; t < s.contours.length; t++) {
2213
+ const n = s.contours[t];
2214
+ let e = 0;
1076
2215
  for (let i = 0; i < n.length; i++) {
1077
- const e = n[i];
1078
- (e.p0x !== e.endX() || e.p0y !== e.endY()) && (n[s++] = e);
2216
+ const o = n[i];
2217
+ (o.p0x !== o.endX() || o.p0y !== o.endY()) && (n[e++] = o);
1079
2218
  }
1080
- n.length = s;
2219
+ n.length = e;
1081
2220
  }
1082
- for (const t of o.contours)
2221
+ for (const t of s.contours)
1083
2222
  if (t.length === 1) {
1084
- const [n, s, i] = t[0].splitInThirds();
1085
- t.length = 0, t.push(n, s, i);
2223
+ const [n, e, i] = t[0].splitInThirds();
2224
+ t.length = 0, t.push(n, e, i);
1086
2225
  } else if (t.length > 0) {
1087
2226
  const n = t.length;
1088
- for (let s = 0; s < n; s++) {
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);
1092
- if (c === 0 || r === 0) continue;
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);
2227
+ for (let e = 0; e < n; e++) {
2228
+ const i = (e + n - 1) % n, o = t[i], r = t[e];
2229
+ o.direction(1, hn), r.direction(0, fn);
2230
+ const c = Math.sqrt(hn[0] ** 2 + hn[1] ** 2), a = Math.sqrt(fn[0] ** 2 + fn[1] ** 2);
2231
+ if (c === 0 || a === 0) continue;
2232
+ const l = hn[0] / c, h = hn[1] / c, f = fn[0] / a, u = fn[1] / a;
2233
+ if (co(l, h, f, u) < _i - 1) {
2234
+ const p = _i - 1, y = Mr * Math.sqrt(1 - p * p) / p;
2235
+ let _ = f - l, g = u - h;
2236
+ const x = Math.sqrt(_ * _ + g * g);
2237
+ if (x === 0) continue;
2238
+ _ = y * _ / x, g = y * g / x, Ar(o, r) < 0 && (_ = -_, g = -g), xi(t, i, 1, -g, _), xi(t, e, 0, g, -_);
1100
2239
  }
1101
2240
  }
1102
2241
  }
1103
2242
  }
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);
2243
+ const di = 1e-5, ns = 1e-6, mr = 2e4, kr = 1e5;
2244
+ function Ur(s) {
2245
+ return [s.p0x, s.p0y, s.p1x, s.p1y, s.p2x, s.p2y, s.p3x, s.p3y].slice(0, 2 * s.type + 4);
1107
2246
  }
1108
- function co(o) {
1109
- const t = o.length / 2 - 2;
1110
- return new et(
2247
+ function Mi(s) {
2248
+ const t = s.length / 2 - 2;
2249
+ return new ot(
1111
2250
  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
2251
+ s[0],
2252
+ s[1],
2253
+ s[2],
2254
+ s[3],
2255
+ s[4] ?? 0,
2256
+ s[5] ?? 0,
2257
+ s[6] ?? 0,
2258
+ s[7] ?? 0
1120
2259
  );
1121
2260
  }
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]);
2261
+ const it = new Float64Array(8), ct = new Float64Array(8), Bt = new Float64Array(8);
2262
+ function es(s, t, n, e) {
2263
+ const i = s.length, o = i / 2 - 1;
2264
+ for (let r = 0; r <= o; r++) {
2265
+ for (let c = 0; c < i; c++) Bt[c] = s[c];
2266
+ for (let c = 0, a = i; c < o; c++, a -= 2) {
2267
+ const l = c < o - r ? t : n;
2268
+ for (let h = 0; h < a - 2; h++) Bt[h] = Bt[h] + l * (Bt[h + 2] - Bt[h]);
1130
2269
  }
1131
- s[2 * a] = vt[0], s[2 * a + 1] = vt[1];
2270
+ e[2 * r] = Bt[0], e[2 * r + 1] = Bt[1];
1132
2271
  }
1133
2272
  }
1134
- function we(o, t, n) {
1135
- return hs(o, t, n, ot), Array.from(ot.subarray(0, o.length));
2273
+ function Tr(s, t, n) {
2274
+ return es(s, t, n, it), Array.from(it.subarray(0, s.length));
1136
2275
  }
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;
2276
+ let ss = 0, is = 0, Rt = -1, wn = -1, An = 0, bn = 0, Zn = 0, $n = 0;
2277
+ function vr(s, t) {
2278
+ Rt = -1, wn = -1;
1140
2279
  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);
2280
+ for (let h = 0; h < 2; h++) {
2281
+ const f = h ? s.length - 2 : 0;
2282
+ for (let u = 0; u < 2; u++) {
2283
+ const p = u ? t.length - 2 : 0;
2284
+ s[f] === t[p] && s[f + 1] === t[p + 1] && (n++, Rt = h, wn = u);
1146
2285
  }
1147
2286
  }
1148
2287
  if (n !== 1) {
1149
- mt = -1;
2288
+ Rt = -1;
1150
2289
  return;
1151
2290
  }
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;
2291
+ const e = Rt ? s.length - 2 : 0;
2292
+ An = s[e], bn = s[e + 1];
2293
+ let i = 0, o = 0;
2294
+ for (let h = 2; h < s.length && i === 0 && o === 0; h += 2) {
2295
+ const f = Rt ? s.length - 2 - h : h;
2296
+ i = s[f] - An, o = s[f + 1] - bn;
2297
+ }
2298
+ let r = 0, c = 0;
2299
+ for (let h = 2; h < t.length && r === 0 && c === 0; h += 2) {
2300
+ const f = wn ? t.length - 2 - h : h;
2301
+ r = t[f] - An, c = t[f + 1] - bn;
2302
+ }
2303
+ const a = Math.hypot(i, o), l = Math.hypot(r, c);
2304
+ Zn = i / a - r / l, $n = o / a - c / l, Math.hypot(Zn, $n) > 1e-9 || (Rt = -1);
2305
+ }
2306
+ function Er(s, t) {
2307
+ const n = Rt ? s - 2 : 0;
2308
+ for (let i = 0; i < s; i += 2)
2309
+ if (i !== n && (it[i] - An) * Zn + (it[i + 1] - bn) * $n <= 0) return !1;
2310
+ const e = wn ? t - 2 : 0;
1172
2311
  for (let i = 0; i < t; i += 2)
1173
- if (i !== s && (it[i] - jt) * un + (it[i + 1] - Qt) * yn >= 0) return !1;
2312
+ if (i !== e && (ct[i] - An) * Zn + (ct[i + 1] - bn) * $n >= 0) return !1;
1174
2313
  return !0;
1175
2314
  }
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))
2315
+ function yn(s, t, n, e, i, o, r) {
2316
+ if (--ss < 0 || --is < 0) return;
2317
+ const c = s.length, a = e.length;
2318
+ es(s, t, n, it), es(e, i, o, ct);
2319
+ let l = 1 / 0, h = 1 / 0, f = -1 / 0, u = -1 / 0;
2320
+ for (let M = 0; M < c; M += 2)
2321
+ l = Math.min(l, it[M]), h = Math.min(h, it[M + 1]), f = Math.max(f, it[M]), u = Math.max(u, it[M + 1]);
2322
+ let p = 1 / 0, y = 1 / 0, _ = -1 / 0, g = -1 / 0;
2323
+ for (let M = 0; M < a; M += 2)
2324
+ p = Math.min(p, ct[M]), y = Math.min(y, ct[M + 1]), _ = Math.max(_, ct[M]), g = Math.max(g, ct[M + 1]);
2325
+ if (l > _ || p > f || h > g || y > u || Rt >= 0 && (Rt ? n === 1 : t === 0) && (wn ? o === 1 : i === 0) && Er(c, a))
1187
2326
  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) {
2327
+ const x = Math.max(f - l, u - h), b = Math.max(_ - p, g - y);
2328
+ if (c === 4 && a === 4 || x < di && b < di) {
2329
+ const M = it[c - 2] - it[0], k = it[c - 1] - it[1], w = ct[a - 2] - ct[0], T = ct[a - 1] - ct[1], D = z(M, k, w, T), m = z(ct[0] - it[0], ct[1] - it[1], w, T) / D, A = z(ct[0] - it[0], ct[1] - it[1], M, k) / D;
2330
+ m >= 0 && m <= 1 && A >= 0 && A <= 1 && r.push(t + m * (n - t), i + A * (o - i));
2331
+ } else x > b ? (yn(s, t, (t + n) / 2, e, i, o, r), yn(s, (t + n) / 2, n, e, i, o, r)) : (yn(s, t, n, e, i, (i + o) / 2, r), yn(s, t, n, e, (i + o) / 2, o, r));
2332
+ }
2333
+ function Nn(s, t, n) {
2334
+ const e = s[2] - s[0], i = s[3] - s[1];
2335
+ return ((t - s[0]) * e + (n - s[1]) * i) / (e * e + i * i);
2336
+ }
2337
+ function Cr(s, t, n) {
2338
+ if (s.length !== 4 || t.length !== 4) return !1;
2339
+ const e = s[2] - s[0], i = s[3] - s[1], o = 1e-9 * Math.hypot(e, i);
2340
+ return Math.abs(z(e, i, t[0] - s[0], t[1] - s[1])) > o || Math.abs(z(e, i, t[2] - s[0], t[3] - s[1])) > o ? !1 : (n.push(Nn(s, t[0], t[1]), 0, Nn(s, t[2], t[3]), 1), n.push(0, Nn(t, s[0], s[1]), 1, Nn(t, s[2], s[3])), !0);
2341
+ }
2342
+ function Sr(s) {
1204
2343
  const t = [];
1205
- for (let n = o.length - 2; n >= 0; n -= 2) t.push(o[n], o[n + 1]);
2344
+ for (let n = s.length - 2; n >= 0; n -= 2) t.push(s[n], s[n + 1]);
1206
2345
  return t;
1207
2346
  }
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;
2347
+ function Ir(s, t) {
2348
+ if (s.length !== t.length) return !1;
2349
+ for (let n = 0; n < s.length; n++) if (!(Math.abs(s[n] - t[n]) < ns)) return !1;
1211
2350
  return !0;
1212
2351
  }
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) {
2352
+ const un = [0, 0], Kt = [0, 0], Jn = [0, 0, 0], Qn = [0, 0, 0];
2353
+ let en = new Int32Array(8);
2354
+ const Dr = 0, Rr = 1;
2355
+ function wi(s, t, n, e) {
1217
2356
  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]);
2357
+ for (let o = 0; o < s.length; o++) {
2358
+ if (e < t[4 * o + 1] - 1e-9 || e > t[4 * o + 3] + 1e-9) continue;
2359
+ const r = s[o].scanlineIntersections(e, Jn, Qn);
2360
+ for (let c = 0; c < r; c++) Jn[c] <= n && (i += Qn[c]);
1222
2361
  }
1223
2362
  return i !== 0;
1224
2363
  }
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]);
2364
+ function Ai(s, t, n, e, i, o, r) {
2365
+ en.fill(0, 0, n);
2366
+ for (let a = 0; a < s.length; a++) {
2367
+ if (r < i[4 * a + 1] - 1e-9 || r > i[4 * a + 3] + 1e-9) continue;
2368
+ const l = s[a].scanlineIntersections(r, Jn, Qn);
2369
+ for (let h = 0; h < l; h++) Jn[h] <= o && (en[t[a]] += Qn[h]);
1231
2370
  }
1232
2371
  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;
2372
+ for (let a = 1; a < n && !c; a++) c = en[a] !== 0;
2373
+ return en[0] !== 0 && (e === Rr ? c : !c);
2374
+ }
2375
+ function Lr(s) {
2376
+ const t = Fr([s.contours]);
2377
+ t && (s.contours = t);
2378
+ }
2379
+ function Fr(s, t = Dr) {
2380
+ const n = s.flat(), e = n.flat(), i = e.map(Ur), o = i.length, r = s.length, c = r > 1;
2381
+ en.length < r && (en = new Int32Array(r));
2382
+ const a = new Float64Array(4 * o), l = new Int32Array(o), h = new Int32Array(o);
2383
+ let f = 0;
2384
+ for (let m = 0; m < r; m++)
2385
+ for (const A of s[m]) {
2386
+ for (let d = 0; d < A.length; d++)
2387
+ l[f + d] = f + (d + 1) % A.length, h[f + d] = m;
2388
+ f += A.length;
2389
+ }
2390
+ for (let m = 0; m < o; m++) {
2391
+ const A = i[m];
2392
+ let d = 1 / 0, R = 1 / 0, S = -1 / 0, E = -1 / 0;
2393
+ for (let I = 0; I < A.length; I += 2)
2394
+ d = Math.min(d, A[I]), R = Math.min(R, A[I + 1]), S = Math.max(S, A[I]), E = Math.max(E, A[I + 1]);
2395
+ a[4 * m] = d, a[4 * m + 1] = R, a[4 * m + 2] = S, a[4 * m + 3] = E;
2396
+ }
2397
+ const u = Array.from({ length: o }, (m, A) => A).sort((m, A) => a[4 * m] - a[4 * A]), p = i.map(() => []), y = new Uint8Array(o);
2398
+ is = kr;
2399
+ for (let m = 0; m < o; m++) {
2400
+ const A = u[m];
2401
+ for (let d = m + 1; d < o; d++) {
2402
+ const R = u[d];
2403
+ if (a[4 * R] > a[4 * A + 2]) break;
2404
+ if (a[4 * A + 1] > a[4 * R + 3] || a[4 * R + 1] > a[4 * A + 3]) continue;
2405
+ const S = Math.min(A, R), E = Math.max(A, R);
2406
+ l[S] !== E && l[E] !== S && (y[S] = y[E] = 1);
2407
+ const I = [];
2408
+ if (ss = mr, Cr(i[S], i[E], I) || (vr(i[S], i[E]), yn(i[S], 0, 1, i[E], 0, 1, I)), ss < 0 || is < 0) return null;
2409
+ for (let F = 0; F < I.length; F += 2)
2410
+ p[S].push(I[F]), p[E].push(I[F + 1]);
2411
+ }
2412
+ }
2413
+ const _ = p.map((m) => {
2414
+ const A = [0];
2415
+ for (const d of m.sort((R, S) => R - S))
2416
+ d - A[A.length - 1] > 1e-7 && d < 1 - 1e-7 && A.push(d);
2417
+ return A.push(1), A;
1279
2418
  });
1280
2419
  let g = !1;
1281
- const M = [], I = [];
1282
- let q = 0;
2420
+ const x = [], b = [];
2421
+ let M = 0;
1283
2422
  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;
2423
+ const A = M + m.length;
2424
+ let d = !0;
2425
+ for (let I = M; I < A; I++) (y[I] || _[I].length > 2) && (d = !1);
2426
+ let R = !1, S = !1, E = !1;
2427
+ for (let I = M; I < A; I++) {
2428
+ const F = _[I];
2429
+ for (let V = 1; V < F.length; V++) {
2430
+ const B = Tr(i[I], F[V - 1], F[V]), nt = Mi(B);
2431
+ nt.point(0.5, un), nt.direction(0.5, Kt);
2432
+ const j = Math.hypot(Kt[0], Kt[1]), W = Math.hypot(B[B.length - 2] - B[0], B[B.length - 1] - B[1]);
2433
+ if (!(j === 0 || W === 0)) {
2434
+ if (!d || !R) {
2435
+ const et = Math.min(1e-6, W * W / 64) / j, st = un[0] + Kt[1] * et, Lt = un[1] - Kt[0] * et, Xt = un[0] - Kt[1] * et, Wt = un[1] + Kt[0] * et;
2436
+ S = c ? Ai(e, h, r, t, a, st, Lt) : wi(e, a, st, Lt), E = c ? Ai(e, h, r, t, a, Xt, Wt) : wi(e, a, Xt, Wt), R = !0;
1298
2437
  }
1299
- v === E ? p[k] === 0 && (g = !0) : (M.push(Y), I.push(v), p[k] !== 0 && (g = !0));
2438
+ S === E ? h[I] === 0 && (g = !0) : (x.push(B), b.push(S), h[I] !== 0 && (g = !0));
1300
2439
  }
1301
2440
  }
1302
2441
  }
1303
- q = d;
2442
+ M = A;
1304
2443
  }
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);
2444
+ const k = 2 * b.filter(Boolean).length >= b.length, w = [];
2445
+ for (let m = 0; m < x.length; m++) {
2446
+ let A = x[m];
2447
+ b[m] !== k && (A = Sr(A), g = !0);
2448
+ let d = !1;
2449
+ for (let R = 0; R < w.length && !d; R++) d = Ir(w[R], A);
2450
+ d ? g = !0 : w.push(A);
1312
2451
  }
1313
2452
  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]];
2453
+ const T = new Uint8Array(w.length), D = [];
2454
+ for (let m = 0; m < w.length; m++) {
2455
+ if (T[m]) continue;
2456
+ T[m] = 1;
2457
+ const A = [w[m]];
1319
2458
  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;
2459
+ const d = A[A.length - 1], R = d[d.length - 2], S = d[d.length - 1];
2460
+ if (A.length > 1 && Math.hypot(R - A[0][0], S - A[0][1]) < ns) {
2461
+ A[0][0] = R, A[0][1] = S;
1323
2462
  break;
1324
2463
  }
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);
2464
+ let E = -1, I = ns;
2465
+ for (let F = 0; F < w.length; F++) {
2466
+ if (T[F]) continue;
2467
+ const V = Math.hypot(w[F][0] - R, w[F][1] - S);
2468
+ V < I && (E = F, I = V);
1330
2469
  }
1331
2470
  if (E < 0) return null;
1332
- D[E] = 1, A[E][0] = C, A[E][1] = v, d.push(A[E]);
2471
+ T[E] = 1, w[E][0] = R, w[E][1] = S, A.push(w[E]);
1333
2472
  }
1334
- R.push(d.map(co));
2473
+ D.push(A.map(Mi));
1335
2474
  }
1336
- return R;
2475
+ return D;
1337
2476
  }
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;
2477
+ const ne = 1, ee = 2, Pr = 3, se = 4, qr = 5, Or = 6, hs = 7, ht = [0, 0], Yt = [0, 0];
2478
+ function Gr(s, t) {
2479
+ return Math.trunc(3 + 2.875 * s / (t - 1) - 1.4375 + 0.5) - 3;
1341
2480
  }
1342
- function Se(o, t, n, s, i) {
1343
- return o * n + t * s <= 0 || Math.abs(o * s - t * n) > i;
2481
+ function Nr(s, t, n, e, i) {
2482
+ return s * n + t * e <= 0 || Math.abs(s * e - t * n) > i;
1344
2483
  }
1345
- function Le(o) {
1346
- const t = Number(o.v & 1n);
1347
- return o.v >>= 1n, t;
2484
+ function Hr(s) {
2485
+ const t = Number(s.v & 1n);
2486
+ return s.v >>= 1n, t;
1348
2487
  }
1349
- function Pe(o) {
1350
- const t = Number(o.v % 3n);
1351
- return o.v /= 3n, t;
2488
+ function Br(s) {
2489
+ const t = Number(s.v % 3n);
2490
+ return s.v /= 3n, t;
1352
2491
  }
1353
- function lo(o) {
1354
- return [Re, Fe, Ce][Pe(o)];
2492
+ function bi(s) {
2493
+ return [Or, qr, Pr][Br(s)];
1355
2494
  }
1356
- function zt(o, t) {
1357
- const n = o.v << 1 + Le(t);
1358
- o.v = (n | n >> 3) & ys;
2495
+ function gn(s, t) {
2496
+ const n = s.v << 1 + Hr(t);
2497
+ s.v = (n | n >> 3) & hs;
1359
2498
  }
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);
2499
+ function Kr(s, t, n) {
2500
+ const e = s.v & n;
2501
+ e === ne || e === ee || e === se ? s.v = e ^ hs : gn(s, t);
1363
2502
  }
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) {
2503
+ function Yr(s, t, n = 0n) {
2504
+ const e = Math.sin(t), i = { v: bi({ v: n }) }, o = { v: n };
2505
+ o.v = n, i.v = bi(o);
2506
+ const r = [];
2507
+ for (const c of s.contours) {
1369
2508
  if (c.length === 0) continue;
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;
1373
- for (let f = 0; f < c.length; f++) {
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;
1380
- }
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;
1388
- if (_ >= 3)
1389
- for (let y = 0; y < _; y++) {
1390
- const g = Te(y, _);
1391
- c[(u + y) % _].color = f[1 + g];
2509
+ r.length = 0, c[c.length - 1].direction(1, ht);
2510
+ const l = Math.sqrt(ht[0] * ht[0] + ht[1] * ht[1]);
2511
+ let h = l > 0 ? ht[0] / l : 0, f = l > 0 ? ht[1] / l : 0;
2512
+ for (let u = 0; u < c.length; u++) {
2513
+ const p = c[u];
2514
+ p.direction(0, Yt);
2515
+ const y = Math.sqrt(Yt[0] * Yt[0] + Yt[1] * Yt[1]), _ = y > 0 ? Yt[0] / y : 0, g = y > 0 ? Yt[1] / y : 0;
2516
+ Nr(h, f, _, g, e) && r.push(u), p.direction(1, ht);
2517
+ const x = Math.sqrt(ht[0] * ht[0] + ht[1] * ht[1]);
2518
+ h = x > 0 ? ht[0] / x : 0, f = x > 0 ? ht[1] / x : 0;
2519
+ }
2520
+ if (r.length === 0) {
2521
+ gn(i, o);
2522
+ for (const u of c) u.color = i.v;
2523
+ } else if (r.length === 1) {
2524
+ const u = [0, hs, 0];
2525
+ gn(i, o), u[0] = i.v, gn(i, o), u[2] = i.v;
2526
+ const p = r[0], y = c.length;
2527
+ if (y >= 3)
2528
+ for (let _ = 0; _ < y; _++) {
2529
+ const g = Gr(_, y);
2530
+ c[(p + _) % y].color = u[1 + g];
1392
2531
  }
1393
- else if (_ >= 1) {
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];
2532
+ else if (y >= 1) {
2533
+ const _ = [null, null, null, null, null, null, null], g = c[0].splitInThirds();
2534
+ if (_[0 + 3 * p] = g[0], _[1 + 3 * p] = g[1], _[2 + 3 * p] = g[2], y >= 2) {
2535
+ const x = c[1].splitInThirds();
2536
+ _[3 - 3 * p] = x[0], _[4 - 3 * p] = x[1], _[5 - 3 * p] = x[2], _[0].color = _[1].color = u[0], _[2].color = _[3].color = u[1], _[4].color = _[5].color = u[2];
1398
2537
  } else
1399
- y[0].color = f[0], y[1].color = f[1], y[2].color = f[2];
2538
+ _[0].color = u[0], _[1].color = u[1], _[2].color = u[2];
1400
2539
  c.length = 0;
1401
- for (const M of y) M !== null && c.push(M);
2540
+ for (const x of _) x !== null && c.push(x);
1402
2541
  }
1403
2542
  } else {
1404
- const f = a.length;
1405
- let u = 0;
1406
- const _ = a[0], y = c.length;
1407
- zt(i, e);
2543
+ const u = r.length;
2544
+ let p = 0;
2545
+ const y = r[0], _ = c.length;
2546
+ gn(i, o);
1408
2547
  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;
2548
+ for (let x = 0; x < _; x++) {
2549
+ const b = (y + x) % _;
2550
+ p + 1 < u && r[p + 1] === b && (++p, Kr(i, o, p === u - 1 ? g : 0)), c[b].color = i.v;
1412
2551
  }
1413
2552
  }
1414
2553
  }
1415
2554
  }
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;
2555
+ const Y = Number.MAX_VALUE, P = [0, 0], dt = [0, 0];
2556
+ let mi = 0, Z = new Float64Array(0), J = new Float64Array(0), N = new Float64Array(0), H = new Float64Array(0), Q = new Int32Array(0), tt = new Float64Array(0), Zt = new Float64Array(0), $t = new Float64Array(0), Jt = new Float64Array(0), Vt = new Int32Array(0);
2557
+ const $ = [0, 0];
2558
+ let ki = 0, Pe = new Float64Array(0), qe = new Float64Array(0), Oe = new Float64Array(0), Ge = new Float64Array(0), Ne = new Float64Array(0), He = new Float64Array(0), Be = new Float64Array(0), Ke = new Float64Array(0), Ye = new Float64Array(0), Ve = new Float64Array(0), je = new Float64Array(0), Xe = new Float64Array(0), Ui = 0, pn = new Int32Array(0);
2559
+ function Vr(s) {
2560
+ const t = s.length;
1422
2561
  if (t === 0) return 0;
1423
2562
  let n = 0;
1424
2563
  if (t === 1) {
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;
2564
+ s[0].point(0, $);
2565
+ const e = $[0], i = $[1];
2566
+ s[0].point(1 / 3, $);
2567
+ const o = $[0], r = $[1];
2568
+ s[0].point(2 / 3, $);
2569
+ const c = $[0], a = $[1];
2570
+ n += e * r - i * o, n += o * a - r * c, n += c * i - a * e;
1432
2571
  } else if (t === 2) {
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;
2572
+ s[0].point(0, $);
2573
+ const e = $[0], i = $[1];
2574
+ s[0].point(0.5, $);
2575
+ const o = $[0], r = $[1];
2576
+ s[1].point(0, $);
2577
+ const c = $[0], a = $[1];
2578
+ s[1].point(0.5, $);
2579
+ const l = $[0], h = $[1];
2580
+ n += e * r - i * o, n += o * a - r * c, n += c * h - a * l, n += l * i - h * e;
1442
2581
  } else {
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;
2582
+ const e = s[t - 1];
2583
+ let i = e.p0x, o = e.p0y;
2584
+ for (let r = 0; r < t; r++) {
2585
+ const c = s[r].p0x, a = s[r].p0y;
2586
+ n += i * a - o * c, i = c, o = a;
1448
2587
  }
1449
2588
  }
1450
2589
  return n > 0 ? -1 : n < 0 ? 1 : 0;
1451
2590
  }
1452
- function Ue(o, t, n, s, i, e, a) {
1453
- const c = a[o][t];
1454
- let r = n;
1455
- if (e < 0) {
1456
- c.direction(0, L);
1457
- const h = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
1458
- if (h > 0) {
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);
2591
+ function jr(s, t, n, e, i, o, r) {
2592
+ const c = r[s][t];
2593
+ let a = n;
2594
+ if (o < 0) {
2595
+ c.direction(0, P);
2596
+ const l = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
2597
+ if (l > 0) {
2598
+ const h = P[0] / l, f = P[1] / l;
2599
+ c.point(0, dt);
2600
+ const u = e - dt[0], p = i - dt[1];
2601
+ if (u * h + p * f < 0) {
2602
+ const _ = u * f - p * h;
2603
+ Math.abs(_) <= Math.abs(a) && (a = _);
1465
2604
  }
1466
2605
  }
1467
2606
  }
1468
- if (e > 1) {
1469
- c.direction(1, L);
1470
- const h = Math.sqrt(L[0] * L[0] + L[1] * L[1]);
1471
- if (h > 0) {
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);
2607
+ if (o > 1) {
2608
+ c.direction(1, P);
2609
+ const l = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
2610
+ if (l > 0) {
2611
+ const h = P[0] / l, f = P[1] / l;
2612
+ c.point(1, dt);
2613
+ const u = e - dt[0], p = i - dt[1];
2614
+ if (u * h + p * f > 0) {
2615
+ const _ = u * f - p * h;
2616
+ Math.abs(_) <= Math.abs(a) && (a = _);
1478
2617
  }
1479
2618
  }
1480
2619
  }
1481
- return r;
2620
+ return a;
1482
2621
  }
1483
- function ut(o, t, n, s, i, e, a, c, r) {
1484
- let h = o < 0 ? t : n;
2622
+ function yt(s, t, n, e, i, o, r, c, a) {
2623
+ let l = s < 0 ? t : n;
1485
2624
  if (i >= 0) {
1486
- const p = Ue(s, i, o, a, c, e, r);
1487
- Math.abs(p) < Math.abs(h) && (h = p);
2625
+ const h = jr(e, i, s, r, c, o, a);
2626
+ Math.abs(h) < Math.abs(l) && (l = h);
1488
2627
  }
1489
- return h;
2628
+ return l;
1490
2629
  }
1491
- function dt(o, t, n) {
1492
- return Math.max(Math.min(o, t), Math.min(Math.max(o, t), n));
2630
+ function mt(s, t, n) {
2631
+ return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
1493
2632
  }
1494
- function Ye(o, t, n, s, i, e, a, c) {
2633
+ function Xr(s, t, n, e, i, o, r, c) {
1495
2634
  if (c.length !== t * n * 3)
1496
2635
  throw new Error(`generateMSDF: out.length ${c.length} !== ${t * n * 3}`);
1497
- const r = o.contours, h = r.length;
1498
- if (h === 0) {
2636
+ const a = s.contours, l = a.length;
2637
+ if (l === 0) {
1499
2638
  c.fill(0);
1500
2639
  return;
1501
2640
  }
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;
1526
- }
1527
- }
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;
1531
- }
1532
- const f = { distance: 0, dot: 0, param: 0 };
1533
- for (let u = 0; u < n; u++)
1534
- for (let _ = 0; _ < t; _++) {
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);
2641
+ const h = e / r;
2642
+ Vt.length < l && (Vt = new Int32Array(l));
2643
+ for (let p = 0; p < l; p++) Vt[p] = Vr(a[p]);
2644
+ Ui < l + 1 && (pn = new Int32Array(l + 1), Ui = l + 1);
2645
+ let f = 0;
2646
+ for (let p = 0; p < l; p++)
2647
+ pn[p] = f, f += a[p].length;
2648
+ pn[l] = f, ki < f && (Pe = new Float64Array(f), qe = new Float64Array(f), Oe = new Float64Array(f), Ge = new Float64Array(f), Ne = new Float64Array(f), He = new Float64Array(f), Be = new Float64Array(f), Ke = new Float64Array(f), Ye = new Float64Array(f), Ve = new Float64Array(f), je = new Float64Array(f), Xe = new Float64Array(f), ki = f);
2649
+ for (let p = 0; p < l; p++) {
2650
+ const y = a[p], _ = y.length, g = pn[p];
2651
+ for (let x = 0; x < _; x++) {
2652
+ const b = y[x], M = y[(x + _ - 1) % _], k = y[(x + 1) % _], w = g + x;
2653
+ b.point(0, dt), Pe[w] = dt[0], qe[w] = dt[1], b.point(1, dt), Oe[w] = dt[0], Ge[w] = dt[1], b.direction(0, P);
2654
+ let T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
2655
+ const D = T > 0 ? P[0] / T : 0, m = T > 0 ? P[1] / T : 0;
2656
+ Ne[w] = D, He[w] = m, b.direction(1, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
2657
+ const A = T > 0 ? P[0] / T : 0, d = T > 0 ? P[1] / T : 0;
2658
+ Be[w] = A, Ke[w] = d, M.direction(1, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
2659
+ const R = T > 0 ? P[0] / T : 0, S = T > 0 ? P[1] / T : 0;
2660
+ k.direction(0, P), T = Math.sqrt(P[0] * P[0] + P[1] * P[1]);
2661
+ const E = T > 0 ? P[0] / T : 0, I = T > 0 ? P[1] / T : 0, F = R + D, V = S + m, B = Math.sqrt(F * F + V * V);
2662
+ Ye[w] = B > 0 ? F / B : 0, Ve[w] = B > 0 ? V / B : 0;
2663
+ const nt = A + E, j = d + I, W = Math.sqrt(nt * nt + j * j);
2664
+ je[w] = W > 0 ? -(nt / W) : 0, Xe[w] = W > 0 ? -(j / W) : 0;
2665
+ }
2666
+ }
2667
+ if (mi < l) {
2668
+ const p = l * 3;
2669
+ Z = new Float64Array(p), J = new Float64Array(p), N = new Float64Array(p), H = new Float64Array(p), Q = new Int32Array(p), tt = new Float64Array(p), Zt = new Float64Array(l), $t = new Float64Array(l), Jt = new Float64Array(l), mi = l;
2670
+ }
2671
+ const u = { distance: 0, dot: 0, param: 0 };
2672
+ for (let p = 0; p < n; p++)
2673
+ for (let y = 0; y < t; y++) {
2674
+ const _ = (y + 0.5) / e - i, g = (p + 0.5) / e - o;
2675
+ for (let L = 0; L < l; L++) {
2676
+ const v = a[L], ut = v.length, U = L * 3, O = pn[L];
2677
+ Z[U] = Z[U + 1] = Z[U + 2] = -Y, J[U] = J[U + 1] = J[U + 2] = 0, N[U] = N[U + 1] = N[U + 2] = -Y, H[U] = H[U + 1] = H[U + 2] = Y, Q[U] = Q[U + 1] = Q[U + 2] = -1, tt[U] = tt[U + 1] = tt[U + 2] = 0;
2678
+ for (let G = 0; G < ut; G++) {
2679
+ const X = v[G], Me = X.color, we = (Me & ne) !== 0, Ae = (Me & ee) !== 0, be = (Me & se) !== 0;
2680
+ X.signedDistance(_, g, u);
2681
+ const In = u.distance, zt = u.dot, me = u.param, Ft = Math.abs(In);
2682
+ if (we) {
2683
+ const Tt = Math.abs(Z[U]);
2684
+ (Ft < Tt || Ft === Tt && zt < J[U]) && (Z[U] = In, J[U] = zt, Q[U] = G, tt[U] = me);
1546
2685
  }
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);
2686
+ if (Ae) {
2687
+ const Tt = Math.abs(Z[U + 1]);
2688
+ (Ft < Tt || Ft === Tt && zt < J[U + 1]) && (Z[U + 1] = In, J[U + 1] = zt, Q[U + 1] = G, tt[U + 1] = me);
1550
2689
  }
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);
2690
+ if (be) {
2691
+ const Tt = Math.abs(Z[U + 2]);
2692
+ (Ft < Tt || Ft === Tt && zt < J[U + 2]) && (Z[U + 2] = In, J[U + 2] = zt, Q[U + 2] = G, tt[U + 2] = me);
1554
2693
  }
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)));
2694
+ const _t = O + G, ke = _ - Pe[_t], Ue = g - qe[_t], Te = _ - Oe[_t], ve = g - Ge[_t], Hs = Ne[_t], Bs = He[_t], Ks = Be[_t], Ys = Ke[_t], $i = ke * Ye[_t] + Ue * Ve[_t], Ji = Te * je[_t] + ve * Xe[_t];
2695
+ if ($i > 0 && -(ke * Hs + Ue * Bs) > 0) {
2696
+ const q = ke * Bs - Ue * Hs;
2697
+ Math.abs(q) < Ft && (we && (q <= 0 && q > N[U] ? N[U] = q : q > 0 && q < H[U] && (H[U] = q)), Ae && (q <= 0 && q > N[U + 1] ? N[U + 1] = q : q > 0 && q < H[U + 1] && (H[U + 1] = q)), be && (q <= 0 && q > N[U + 2] ? N[U + 2] = q : q > 0 && q < H[U + 2] && (H[U + 2] = q)));
1559
2698
  }
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)));
2699
+ if (Ji > 0 && Te * Ks + ve * Ys > 0) {
2700
+ const q = Te * Ys - ve * Ks;
2701
+ Math.abs(q) < Ft && (we && (q <= 0 && q > N[U] ? N[U] = q : q > 0 && q < H[U] && (H[U] = q)), Ae && (q <= 0 && q > N[U + 1] ? N[U + 1] = q : q > 0 && q < H[U + 1] && (H[U + 1] = q)), be && (q <= 0 && q > N[U + 2] ? N[U + 2] = q : q > 0 && q < H[U + 2] && (H[U + 2] = q)));
1563
2702
  }
1564
2703
  }
1565
- Pt[F] = ut(
1566
- $[w],
1567
- G[w],
1568
- U[w],
1569
- F,
1570
- Z[w],
1571
- J[w],
1572
- y,
2704
+ Zt[L] = yt(
2705
+ Z[U],
2706
+ N[U],
2707
+ H[U],
2708
+ L,
2709
+ Q[U],
2710
+ tt[U],
2711
+ _,
1573
2712
  g,
1574
- r
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,
2713
+ a
2714
+ ), $t[L] = yt(
2715
+ Z[U + 1],
2716
+ N[U + 1],
2717
+ H[U + 1],
2718
+ L,
2719
+ Q[U + 1],
2720
+ tt[U + 1],
2721
+ _,
1583
2722
  g,
1584
- r
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,
2723
+ a
2724
+ ), Jt[L] = yt(
2725
+ Z[U + 2],
2726
+ N[U + 2],
2727
+ H[U + 2],
2728
+ L,
2729
+ Q[U + 2],
2730
+ tt[U + 2],
2731
+ _,
1593
2732
  g,
1594
- r
2733
+ a
1595
2734
  );
1596
2735
  }
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]);
2736
+ let x = -Y, b = 0, M = -Y, k = Y, w = -1, T = -1, D = 0, m = -Y, A = 0, d = -Y, R = Y, S = -1, E = -1, I = 0, F = -Y, V = 0, B = -Y, nt = Y, j = -1, W = -1, et = 0, st = -Y, Lt = 0, Xt = -Y, Wt = Y, us = -1, ps = -1, _s = 0, kn = -Y, ys = 0, ie = -Y, oe = Y, gs = -1, xs = -1, ds = 0, Un = -Y, Ms = 0, re = -Y, ce = Y, ws = -1, As = -1, bs = 0, Tn = -Y, ms = 0, ae = -Y, le = Y, ks = -1, Us = -1, Ts = 0, vn = -Y, vs = 0, he = -Y, fe = Y, Es = -1, Cs = -1, Ss = 0, En = -Y, Is = 0, ue = -Y, pe = Y, Ds = -1, Rs = -1, Ls = 0;
2737
+ for (let L = 0; L < l; L++) {
2738
+ const v = L * 3, ut = Vt[L], U = mt(Zt[L], $t[L], Jt[L]);
1600
2739
  {
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]);
2740
+ const O = Z[v], G = J[v], X = Math.abs(O);
2741
+ (X < Math.abs(x) || X === Math.abs(x) && G < b) && (x = O, b = G, w = L, T = Q[v], D = tt[v]), N[v] > M && (M = N[v]), H[v] < k && (k = H[v]);
1603
2742
  }
1604
2743
  {
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]);
2744
+ const O = Z[v + 1], G = J[v + 1], X = Math.abs(O);
2745
+ (X < Math.abs(m) || X === Math.abs(m) && G < A) && (m = O, A = G, S = L, E = Q[v + 1], I = tt[v + 1]), N[v + 1] > d && (d = N[v + 1]), H[v + 1] < R && (R = H[v + 1]);
1607
2746
  }
1608
2747
  {
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]);
2748
+ const O = Z[v + 2], G = J[v + 2], X = Math.abs(O);
2749
+ (X < Math.abs(F) || X === Math.abs(F) && G < V) && (F = O, V = G, j = L, W = Q[v + 2], et = tt[v + 2]), N[v + 2] > B && (B = N[v + 2]), H[v + 2] < nt && (nt = H[v + 2]);
1611
2750
  }
1612
- if (ht > 0 && w >= 0) {
2751
+ if (ut > 0 && U >= 0) {
1613
2752
  {
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]);
2753
+ const O = Z[v], G = J[v], X = Math.abs(O);
2754
+ (X < Math.abs(st) || X === Math.abs(st) && G < Lt) && (st = O, Lt = G, us = L, ps = Q[v], _s = tt[v]), N[v] > Xt && (Xt = N[v]), H[v] < Wt && (Wt = H[v]);
1616
2755
  }
1617
2756
  {
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]);
2757
+ const O = Z[v + 1], G = J[v + 1], X = Math.abs(O);
2758
+ (X < Math.abs(kn) || X === Math.abs(kn) && G < ys) && (kn = O, ys = G, gs = L, xs = Q[v + 1], ds = tt[v + 1]), N[v + 1] > ie && (ie = N[v + 1]), H[v + 1] < oe && (oe = H[v + 1]);
1620
2759
  }
1621
2760
  {
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]);
2761
+ const O = Z[v + 2], G = J[v + 2], X = Math.abs(O);
2762
+ (X < Math.abs(Un) || X === Math.abs(Un) && G < Ms) && (Un = O, Ms = G, ws = L, As = Q[v + 2], bs = tt[v + 2]), N[v + 2] > re && (re = N[v + 2]), H[v + 2] < ce && (ce = H[v + 2]);
1624
2763
  }
1625
2764
  }
1626
- if (ht < 0 && w <= 0) {
2765
+ if (ut < 0 && U <= 0) {
1627
2766
  {
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]);
2767
+ const O = Z[v], G = J[v], X = Math.abs(O);
2768
+ (X < Math.abs(Tn) || X === Math.abs(Tn) && G < ms) && (Tn = O, ms = G, ks = L, Us = Q[v], Ts = tt[v]), N[v] > ae && (ae = N[v]), H[v] < le && (le = H[v]);
1630
2769
  }
1631
2770
  {
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]);
2771
+ const O = Z[v + 1], G = J[v + 1], X = Math.abs(O);
2772
+ (X < Math.abs(vn) || X === Math.abs(vn) && G < vs) && (vn = O, vs = G, Es = L, Cs = Q[v + 1], Ss = tt[v + 1]), N[v + 1] > he && (he = N[v + 1]), H[v + 1] < fe && (fe = H[v + 1]);
1634
2773
  }
1635
2774
  {
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]);
2775
+ const O = Z[v + 2], G = J[v + 2], X = Math.abs(O);
2776
+ (X < Math.abs(En) || X === Math.abs(En) && G < Is) && (En = O, Is = G, Ds = L, Rs = Q[v + 2], Ls = tt[v + 2]), N[v + 2] > ue && (ue = N[v + 2]), H[v + 2] < pe && (pe = H[v + 2]);
1638
2777
  }
1639
2778
  }
1640
2779
  }
1641
- const Fn = ut(
2780
+ const _e = yt(
2781
+ x,
1642
2782
  M,
1643
- q,
2783
+ k,
2784
+ w,
1644
2785
  T,
1645
- A,
1646
2786
  D,
1647
- R,
1648
- y,
2787
+ _,
1649
2788
  g,
1650
- r
1651
- ), Rn = ut(
2789
+ a
2790
+ ), ye = yt(
1652
2791
  m,
1653
- x,
1654
- C,
1655
- v,
2792
+ d,
2793
+ R,
2794
+ S,
1656
2795
  E,
1657
- k,
1658
- y,
2796
+ I,
2797
+ _,
1659
2798
  g,
1660
- r
1661
- ), Tn = ut(
1662
- S,
1663
- Y,
1664
- tt,
1665
- V,
1666
- K,
2799
+ a
2800
+ ), ge = yt(
2801
+ F,
2802
+ B,
1667
2803
  nt,
1668
- y,
2804
+ j,
2805
+ W,
2806
+ et,
2807
+ _,
1669
2808
  g,
1670
- r
1671
- ), qo = dt(Fn, Rn, Tn), Gs = ut(
2809
+ a
2810
+ ), Zi = mt(_e, ye, ge), Fs = yt(
1672
2811
  st,
1673
- Tt,
1674
- St,
1675
- xs,
2812
+ Xt,
2813
+ Wt,
2814
+ us,
2815
+ ps,
2816
+ _s,
2817
+ _,
2818
+ g,
2819
+ a
2820
+ ), Ps = yt(
2821
+ kn,
2822
+ ie,
2823
+ oe,
1676
2824
  gs,
1677
- Ms,
1678
- y,
2825
+ xs,
2826
+ ds,
2827
+ _,
1679
2828
  g,
1680
- r
1681
- ), Us = ut(
1682
- Zt,
1683
- bn,
1684
- An,
2829
+ a
2830
+ ), qs = yt(
2831
+ Un,
2832
+ re,
2833
+ ce,
1685
2834
  ws,
1686
- bs,
1687
2835
  As,
1688
- y,
1689
- g,
1690
- r
1691
- ), Ys = ut(
1692
- Jt,
1693
- mn,
1694
- En,
1695
- Es,
1696
- Is,
1697
- Ds,
1698
- y,
2836
+ bs,
2837
+ _,
1699
2838
  g,
1700
- r
1701
- ), on = dt(Gs, Us, Ys), Xs = ut(
1702
- tn,
1703
- In,
1704
- Dn,
1705
- vs,
2839
+ a
2840
+ ), Cn = mt(Fs, Ps, qs), Os = yt(
2841
+ Tn,
2842
+ ae,
2843
+ le,
1706
2844
  ks,
1707
- Cs,
1708
- y,
2845
+ Us,
2846
+ Ts,
2847
+ _,
1709
2848
  g,
1710
- r
1711
- ), Ws = ut(
1712
- nn,
1713
- qn,
2849
+ a
2850
+ ), Gs = yt(
1714
2851
  vn,
1715
- Rs,
1716
- Ts,
2852
+ he,
2853
+ fe,
2854
+ Es,
2855
+ Cs,
1717
2856
  Ss,
1718
- y,
2857
+ _,
1719
2858
  g,
1720
- r
1721
- ), Hs = ut(
1722
- sn,
1723
- kn,
1724
- Cn,
1725
- Ps,
1726
- Os,
1727
- Ns,
1728
- y,
2859
+ a
2860
+ ), Ns = yt(
2861
+ En,
2862
+ ue,
2863
+ pe,
2864
+ Ds,
2865
+ Rs,
2866
+ Ls,
2867
+ _,
1729
2868
  g,
1730
- r
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);
2869
+ a
2870
+ ), Sn = mt(Os, Gs, Ns);
2871
+ let wt, At, bt, xe = 0;
2872
+ if (Cn >= 0 && Math.abs(Cn) <= Math.abs(Sn)) {
2873
+ wt = Fs, At = Ps, bt = qs, xe = 1;
2874
+ for (let L = 0; L < l; L++)
2875
+ if (Vt[L] > 0) {
2876
+ const v = Zt[L], ut = $t[L], U = Jt[L], O = mt(v, ut, U);
2877
+ Math.abs(O) < Math.abs(Sn) && O > mt(wt, At, bt) && (wt = v, At = ut, bt = U);
1739
2878
  }
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);
2879
+ } else if (Sn <= 0 && Math.abs(Sn) < Math.abs(Cn)) {
2880
+ wt = Os, At = Gs, bt = Ns, xe = -1;
2881
+ for (let L = 0; L < l; L++)
2882
+ if (Vt[L] < 0) {
2883
+ const v = Zt[L], ut = $t[L], U = Jt[L], O = mt(v, ut, U);
2884
+ Math.abs(O) < Math.abs(Cn) && O < mt(wt, At, bt) && (wt = v, At = ut, bt = U);
1746
2885
  }
1747
2886
  } else {
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;
2887
+ const L = (p * t + y) * 3;
2888
+ c[L + 0] = _e * h + 0.5, c[L + 1] = ye * h + 0.5, c[L + 2] = ge * h + 0.5;
1750
2889
  continue;
1751
2890
  }
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);
2891
+ for (let L = 0; L < l; L++)
2892
+ if (Vt[L] !== xe) {
2893
+ const v = Zt[L], ut = $t[L], U = Jt[L], O = mt(v, ut, U), G = mt(wt, At, bt);
2894
+ O * G >= 0 && Math.abs(O) < Math.abs(G) && (wt = v, At = ut, bt = U);
1756
2895
  }
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;
2896
+ mt(wt, At, bt) === Zi && (wt = _e, At = ye, bt = ge);
2897
+ const de = (p * t + y) * 3;
2898
+ c[de + 0] = wt * h + 0.5, c[de + 1] = At * h + 0.5, c[de + 2] = bt * h + 0.5;
1760
2899
  }
1761
2900
  }
1762
- const mo = 0, Xe = 1, We = 2, He = 3;
1763
- function Ve(o, t) {
2901
+ const ji = 0, Wr = 1, zr = 2, Zr = 3;
2902
+ function $r(s, t) {
1764
2903
  switch (t) {
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;
2904
+ case ji:
2905
+ return s !== 0;
2906
+ case Wr:
2907
+ return (s & 1) !== 0;
2908
+ case zr:
2909
+ return s > 0;
2910
+ case Zr:
2911
+ return s < 0;
1773
2912
  }
1774
2913
  return !1;
1775
2914
  }
1776
- class Be {
2915
+ class Jr {
1777
2916
  constructor() {
1778
2917
  this._intersections = [], this._lastIndex = 0;
1779
2918
  }
@@ -1785,10 +2924,10 @@ class Be {
1785
2924
  */
1786
2925
  setIntersections(t) {
1787
2926
  if (this._intersections = t, this._lastIndex = 0, t.length > 0) {
1788
- t.sort((s, i) => pt(s.x - i.x));
2927
+ t.sort((e, i) => pt(e.x - i.x));
1789
2928
  let n = 0;
1790
- for (let s = 0; s < t.length; s++)
1791
- n += t[s].direction, t[s].direction = n;
2929
+ for (let e = 0; e < t.length; e++)
2930
+ n += t[e].direction, t[e].direction = n;
1792
2931
  }
1793
2932
  }
1794
2933
  /**
@@ -1800,16 +2939,16 @@ class Be {
1800
2939
  _moveTo(t) {
1801
2940
  const n = this._intersections.length;
1802
2941
  if (n === 0) return -1;
1803
- let s = this._lastIndex;
1804
- if (t < this._intersections[s].x)
2942
+ let e = this._lastIndex;
2943
+ if (t < this._intersections[e].x)
1805
2944
  do {
1806
- if (s === 0)
2945
+ if (e === 0)
1807
2946
  return this._lastIndex = 0, -1;
1808
- --s;
1809
- } while (t < this._intersections[s].x);
2947
+ --e;
2948
+ } while (t < this._intersections[e].x);
1810
2949
  else
1811
- for (; s < n - 1 && t >= this._intersections[s + 1].x; ) ++s;
1812
- return this._lastIndex = s, s;
2950
+ for (; e < n - 1 && t >= this._intersections[e + 1].x; ) ++e;
2951
+ return this._lastIndex = e, e;
1813
2952
  }
1814
2953
  /**
1815
2954
  * Returns the accumulated winding number at x.
@@ -1829,355 +2968,365 @@ class Be {
1829
2968
  * @returns True when filled.
1830
2969
  */
1831
2970
  filled(t, n) {
1832
- return Ve(this.sumIntersections(t), n);
1833
- }
1834
- }
1835
- const uo = [0, 0, 0], yo = [0, 0, 0];
1836
- function Ke(o, t, n) {
1837
- const s = [];
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] });
1843
- }
1844
- n.setIntersections(s);
1845
- }
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) {
1848
- if (n === 0 || s === 0) return;
1849
- const c = new Be(), r = new Int8Array(n * s);
1850
- for (let h = 0; h < s; h++) {
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;
1856
- }
1857
- }
1858
- for (let h = 0; h < s; h++)
1859
- for (let p = 0; p < n; p++) {
1860
- const l = h * n + p;
1861
- if (r[l] !== 0) continue;
1862
- let f = 0;
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];
2971
+ return $r(this.sumIntersections(t), n);
2972
+ }
2973
+ }
2974
+ const Ti = [0, 0, 0], vi = [0, 0, 0];
2975
+ function Qr(s, t, n) {
2976
+ const e = [];
2977
+ for (const i of s.contours)
2978
+ for (const o of i) {
2979
+ const r = o.scanlineIntersections(t, Ti, vi);
2980
+ for (let c = 0; c < r; c++)
2981
+ e.push({ x: Ti[c], direction: vi[c] });
2982
+ }
2983
+ n.setIntersections(e);
2984
+ }
2985
+ const sn = 2, Xi = 1, We = 1.001, tc = 1.1111111111111112, te = 0.01;
2986
+ function nc(s, t, n, e, i, o, r) {
2987
+ if (n === 0 || e === 0) return;
2988
+ const c = new Jr(), a = new Int8Array(n * e);
2989
+ for (let l = 0; l < e; l++) {
2990
+ const h = (l + 0.5) / i - r;
2991
+ Qr(t, h, c);
2992
+ for (let f = 0; f < n; f++) {
2993
+ const u = (f + 0.5) / i - o, p = c.filled(u, ji), y = (l * n + f) * 3, _ = s[y], g = s[y + 1], x = s[y + 2], b = lt(_, g, x), M = l * n + f;
2994
+ b === 0.5 ? a[M] = 0 : b > 0.5 !== p ? (s[y] = 1 - _, s[y + 1] = 1 - g, s[y + 2] = 1 - x, a[M] = -1) : a[M] = 1;
2995
+ }
2996
+ }
2997
+ for (let l = 0; l < e; l++)
2998
+ for (let h = 0; h < n; h++) {
2999
+ const f = l * n + h;
3000
+ if (a[f] !== 0) continue;
3001
+ let u = 0;
3002
+ if (h > 0 && (u += a[f - 1]), h < n - 1 && (u += a[f + 1]), l > 0 && (u += a[f - n]), l < e - 1 && (u += a[f + n]), u < 0) {
3003
+ const p = (l * n + h) * 3;
3004
+ s[p] = 1 - s[p], s[p + 1] = 1 - s[p + 1], s[p + 2] = 1 - s[p + 2];
1866
3005
  }
1867
3006
  }
1868
3007
  }
1869
- const es = [0, 0];
1870
- function je(o, t, n, s, i, e, a, c) {
1871
- const r = new Uint8Array(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);
3008
+ const ze = [0, 0];
3009
+ function ec(s, t, n, e, i, o, r, c) {
3010
+ const a = new Uint8Array(n * e);
3011
+ sc(a, t, n, e, i, o, r), ic(a, s, n, e, i, c), ac(a, s, n, e, c, tc), lc(a, s, n, e);
1873
3012
  }
1874
- function Qe(o, t, n, s, i, e, a) {
3013
+ function sc(s, t, n, e, i, o, r) {
1875
3014
  for (const c of t.contours) {
1876
3015
  if (c.length === 0) continue;
1877
- let r = c[c.length - 1];
1878
- for (const h of c) {
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));
3016
+ let a = c[c.length - 1];
3017
+ for (const l of c) {
3018
+ const h = a.color & l.color;
3019
+ if (!(h & h - 1)) {
3020
+ l.point(0, ze);
3021
+ const f = i * (ze[0] + o), u = i * (ze[1] + r), p = Math.floor(f - 0.5) | 0, y = Math.floor(u - 0.5) | 0, _ = p + 1, g = y + 1;
3022
+ p < n && y < e && _ >= 0 && g >= 0 && (p >= 0 && y >= 0 && (s[y * n + p] |= sn), _ < n && y >= 0 && (s[y * n + _] |= sn), p >= 0 && g < e && (s[g * n + p] |= sn), _ < n && g < e && (s[g * n + _] |= sn));
1884
3023
  }
1885
- r = h;
3024
+ a = l;
1886
3025
  }
1887
3026
  }
1888
3027
  }
1889
- function ln(o, t, n) {
1890
- let s = 0;
3028
+ function Hn(s, t, n) {
3029
+ let e = 0;
1891
3030
  for (let i = 0; i < 3; i++) {
1892
- const e = o[t + i], a = o[n + i], c = e - a;
3031
+ const o = s[t + i], r = s[n + i], c = o - r;
1893
3032
  if (c === 0) continue;
1894
- const r = (e - 0.5) / c;
1895
- if (r > 0 && r < 1) {
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);
3033
+ const a = (o - 0.5) / c;
3034
+ if (a > 0 && a < 1) {
3035
+ const l = 1 - a, h = l * s[t] + a * s[n], f = l * s[t + 1] + a * s[n + 1], u = l * s[t + 2] + a * s[n + 2], p = i === 0 ? h : i === 1 ? f : u;
3036
+ lt(h, f, u) === p && (e |= i === 0 ? ne : i === 1 ? ee : se);
1898
3037
  }
1899
3038
  }
1900
- return s;
1901
- }
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);
3039
+ return e;
1904
3040
  }
1905
- function Ze(o, t, n, s, i, e) {
1906
- const a = os / e, c = os / e, r = os * Math.SQRT2 / e;
1907
- for (let h = 0; h < s; h++)
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);
3041
+ function qt(s, t, n, e, i, o) {
3042
+ (o & ne && n[e] !== i || o & ee && n[e + 1] !== i || o & se && n[e + 2] !== i) && (s[t] |= sn);
3043
+ }
3044
+ function ic(s, t, n, e, i, o) {
3045
+ const r = We / o, c = We / o, a = We * Math.SQRT2 / o;
3046
+ for (let l = 0; l < e; l++)
3047
+ for (let h = 0; h < n - 1; h++) {
3048
+ const f = (l * n + h) * 3, u = f + 3, p = lt(t[f], t[f + 1], t[f + 2]), y = lt(t[u], t[u + 1], t[u + 2]);
3049
+ if (Math.abs(p - 0.5) + Math.abs(y - 0.5) < r) {
3050
+ const _ = Hn(t, f, u);
3051
+ qt(s, l * n + h, t, f, p, _), qt(s, l * n + h + 1, t, u, y, _);
1913
3052
  }
1914
3053
  }
1915
- for (let h = 0; h < s - 1; h++)
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);
3054
+ for (let l = 0; l < e - 1; l++)
3055
+ for (let h = 0; h < n; h++) {
3056
+ const f = (l * n + h) * 3, u = ((l + 1) * n + h) * 3, p = lt(t[f], t[f + 1], t[f + 2]), y = lt(t[u], t[u + 1], t[u + 2]);
3057
+ if (Math.abs(p - 0.5) + Math.abs(y - 0.5) < c) {
3058
+ const _ = Hn(t, f, u);
3059
+ qt(s, l * n + h, t, f, p, _), qt(s, (l + 1) * n + h, t, u, y, _);
1921
3060
  }
1922
3061
  }
1923
- for (let h = 0; h < s - 1; h++)
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);
3062
+ for (let l = 0; l < e - 1; l++)
3063
+ for (let h = 0; h < n - 1; h++) {
3064
+ const f = (l * n + h) * 3, u = (l * n + h + 1) * 3, p = ((l + 1) * n + h) * 3, y = ((l + 1) * n + h + 1) * 3, _ = lt(t[f], t[f + 1], t[f + 2]), g = lt(t[u], t[u + 1], t[u + 2]), x = lt(t[p], t[p + 1], t[p + 2]), b = lt(t[y], t[y + 1], t[y + 2]);
3065
+ if (Math.abs(_ - 0.5) + Math.abs(b - 0.5) < a) {
3066
+ const M = Hn(t, f, y);
3067
+ qt(s, l * n + h, t, f, _, M), qt(s, (l + 1) * n + h + 1, t, y, b, M);
1929
3068
  }
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);
3069
+ if (Math.abs(g - 0.5) + Math.abs(x - 0.5) < a) {
3070
+ const M = Hn(t, u, p);
3071
+ qt(s, l * n + h + 1, t, u, g, M), qt(s, (l + 1) * n + h, t, p, x, M);
1933
3072
  }
1934
3073
  }
1935
3074
  }
1936
- function Je(o, t, n) {
1937
- const s = t < o ? t : o, i = o < t ? t : o, e = n < i ? n : i;
1938
- return s < e ? e : s;
3075
+ function oc(s, t, n) {
3076
+ const e = t < s ? t : s, i = s < t ? t : s, o = n < i ? n : i;
3077
+ return e < o ? o : e;
1939
3078
  }
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])
3079
+ function rc(s, t, n, e) {
3080
+ return lt(
3081
+ s[t] + e * (s[n] - s[t]),
3082
+ s[t + 1] + e * (s[n + 1] - s[t + 1]),
3083
+ s[t + 2] + e * (s[n + 2] - s[t + 2])
1945
3084
  );
1946
3085
  }
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])
3086
+ function os(s, t, n, e) {
3087
+ return oc(
3088
+ Math.fround(e * (e * n[0] + t[0]) + s[0]),
3089
+ Math.fround(e * (e * n[1] + t[1]) + s[1]),
3090
+ Math.fround(e * (e * n[2] + t[2]) + s[2])
1952
3091
  );
1953
3092
  }
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;
3093
+ const jt = [0, 0, 0], vt = [0, 0, 0], Ze = [0, 0, 0], xt = [0, 0, 0], Ei = 1, Wi = 2;
3094
+ function fs(s, t, n, e, i, o, r, c) {
3095
+ if (e > 0.5 && i > 0.5 && o <= 0.5 || e < 0.5 && i < 0.5 && o >= 0.5 || !c && cc(e, i, o) !== o) {
3096
+ const a = (n - s) * r, l = (t - n) * r;
3097
+ return o >= e - a && o <= e + a && o >= i - l && o <= i + l ? Ei : Ei | Wi;
1959
3098
  }
1960
3099
  return 0;
1961
3100
  }
1962
- function Do(o) {
1963
- return (o & Io) !== 0;
3101
+ function zi(s) {
3102
+ return (s & Wi) !== 0;
1964
3103
  }
1965
- function ni(o, t, n) {
1966
- return Math.max(Math.min(o, t), Math.min(Math.max(o, t), n));
3104
+ function cc(s, t, n) {
3105
+ return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
1967
3106
  }
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;
3107
+ function Bn(s, t, n, e, i, o) {
3108
+ const r = lt(s[n], s[n + 1], s[n + 2]);
3109
+ if (Math.abs(e - 0.5) < Math.abs(r - 0.5)) return !1;
1971
3110
  for (let c = 0; c < 3; c++) {
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;
3111
+ const a = s[t + c] - s[t + (c + 1) % 3], l = s[n + c] - s[n + (c + 1) % 3], h = a - l;
3112
+ if (h === 0) continue;
3113
+ const f = a / h;
3114
+ if (f > te && f < 1 - te) {
3115
+ const u = rc(s, t, n, f), p = fs(0, 1, f, e, r, u, i, o);
3116
+ if (zi(p)) return !0;
1978
3117
  }
1979
3118
  }
1980
3119
  return !1;
1981
3120
  }
1982
- function xo(o, t, n, s, i, e, a, c, r) {
1983
- if (!(r > 0 && r < 1)) 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;
3121
+ function Ci(s, t, n, e, i, o, r, c, a) {
3122
+ if (!(a > 0 && a < 1)) return 0;
3123
+ const l = a > r ? 0 : a, h = a > r ? a : 1;
3124
+ xt[0] = s[t], xt[1] = s[t + 1], xt[2] = s[t + 2];
3125
+ const f = a > r ? n : os(xt, jt, vt, a);
3126
+ xt[0] = s[t], xt[1] = s[t + 1], xt[2] = s[t + 2];
3127
+ const u = a > r ? os(xt, jt, vt, a) : e;
3128
+ return fs(l, h, r, f, u, c, i, o);
3129
+ }
3130
+ function Kn(s, t, n, e, i, o, r, c, a) {
3131
+ if (!(r > te && r < 1 - te)) return !1;
3132
+ xt[0] = s[t], xt[1] = s[t + 1], xt[2] = s[t + 2];
3133
+ const l = os(xt, jt, vt, r);
3134
+ let h = fs(0, 1, r, n, e, l, i, o);
3135
+ return h |= Ci(s, t, n, e, i, o, r, l, c), h |= Ci(s, t, n, e, i, o, r, l, a), zi(h);
3136
+ }
3137
+ function $e(s, t, n, e, i, o, r, c, a, l, h, f, u) {
3138
+ const p = Math.fround(s[t + l] - s[t + h]), y = Math.fround(
3139
+ Math.fround(s[n + l] - s[n + h]) + Math.fround(s[e + l] - s[e + h])
3140
+ ), _ = Math.fround(s[i + l] - s[i + h]), g = Math.fround(Math.fround(_ - y) + p), x = Math.fround(Math.fround(y - p) - p), b = p;
3141
+ if (g === 0 || Math.abs(x) > 1e12 * Math.abs(g)) {
3142
+ if (x !== 0) {
3143
+ const k = -b / x;
3144
+ if (Kn(s, t, o, r, c, a, k, f, u)) return !0;
2006
3145
  }
2007
3146
  return !1;
2008
3147
  }
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;
3148
+ const M = x * x - 4 * g * b;
3149
+ if (M > 0) {
3150
+ const k = Math.sqrt(M), w = (-x + k) / (2 * g);
3151
+ if (Kn(s, t, o, r, c, a, w, f, u)) return !0;
3152
+ const T = (-x - k) / (2 * g);
3153
+ if (Kn(s, t, o, r, c, a, T, f, u)) return !0;
3154
+ } else if (M === 0) {
3155
+ const k = -x / (2 * g);
3156
+ if (Kn(s, t, o, r, c, a, k, f, u)) return !0;
2018
3157
  }
2019
3158
  return !1;
2020
3159
  }
2021
- function fn(o, t, n, s, i, e, a, c) {
2022
- const r = rt(o[i], o[i + 1], o[i + 2]);
2023
- if (Math.abs(e - 0.5) < Math.abs(r - 0.5)) return !1;
2024
- for (let f = 0; f < 3; f++)
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,
3160
+ function Yn(s, t, n, e, i, o, r, c) {
3161
+ const a = lt(s[i], s[i + 1], s[i + 2]);
3162
+ if (Math.abs(o - 0.5) < Math.abs(a - 0.5)) return !1;
3163
+ for (let u = 0; u < 3; u++)
3164
+ Ze[u] = Math.fround(
3165
+ Math.fround(s[t + u] - s[n + u]) - s[e + u]
3166
+ ), jt[u] = Math.fround(-s[t + u] - Ze[u]), vt[u] = Math.fround(s[i + u] + Ze[u]);
3167
+ const l = vt[0] !== 0 ? -0.5 * jt[0] / vt[0] : -1, h = vt[1] !== 0 ? -0.5 * jt[1] / vt[1] : -1, f = vt[2] !== 0 ? -0.5 * jt[2] / vt[2] : -1;
3168
+ return !!($e(
3169
+ s,
2031
3170
  t,
2032
3171
  n,
2033
- s,
2034
- i,
2035
3172
  e,
2036
- r,
3173
+ i,
3174
+ o,
2037
3175
  a,
3176
+ r,
2038
3177
  c,
2039
3178
  0,
2040
3179
  1,
2041
- h,
2042
- p
2043
- ) || cs(
2044
- o,
3180
+ l,
3181
+ h
3182
+ ) || $e(
3183
+ s,
2045
3184
  t,
2046
3185
  n,
2047
- s,
2048
- i,
2049
3186
  e,
2050
- r,
3187
+ i,
3188
+ o,
2051
3189
  a,
3190
+ r,
2052
3191
  c,
2053
3192
  1,
2054
3193
  2,
2055
- p,
2056
- l
2057
- ) || cs(
2058
- o,
3194
+ h,
3195
+ f
3196
+ ) || $e(
3197
+ s,
2059
3198
  t,
2060
3199
  n,
2061
- s,
2062
- i,
2063
3200
  e,
2064
- r,
3201
+ i,
3202
+ o,
2065
3203
  a,
3204
+ r,
2066
3205
  c,
2067
3206
  2,
2068
3207
  0,
2069
- l,
2070
- h
3208
+ f,
3209
+ l
2071
3210
  ));
2072
3211
  }
2073
- function si(o, t, n, s, i, e) {
2074
- const a = e / i, c = e / i, r = e * Math.SQRT2 / i;
2075
- for (let h = 0; h < s; h++)
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);
3212
+ function ac(s, t, n, e, i, o) {
3213
+ const r = o / i, c = o / i, a = o * Math.SQRT2 / i;
3214
+ for (let l = 0; l < e; l++)
3215
+ for (let h = 0; h < n; h++) {
3216
+ const f = l * n + h, u = f * 3, p = lt(t[u], t[u + 1], t[u + 2]), y = (s[f] & sn) !== 0, _ = h > 0, g = h < n - 1, x = l > 0, b = l < e - 1, M = _ ? (f - 1) * 3 : -1, k = g ? (f + 1) * 3 : -1, w = x ? (f - n) * 3 : -1, T = b ? (f + n) * 3 : -1;
3217
+ let D = !1;
3218
+ if (_ && Bn(t, u, M, p, r, y) && (D = !0), !D && x && Bn(t, u, w, p, c, y) && (D = !0), !D && g && Bn(t, u, k, p, r, y) && (D = !0), !D && b && Bn(t, u, T, p, c, y) && (D = !0), !D && _ && x) {
3219
+ const m = (f - n - 1) * 3;
3220
+ Yn(t, u, M, w, m, p, a, y) && (D = !0);
2082
3221
  }
2083
- if (!R && g && M) {
2084
- const m = (l - n + 1) * 3;
2085
- fn(t, f, T, A, m, u, r, _) && (R = !0);
3222
+ if (!D && g && x) {
3223
+ const m = (f - n + 1) * 3;
3224
+ Yn(t, u, k, w, m, p, a, y) && (D = !0);
2086
3225
  }
2087
- if (!R && y && I) {
2088
- const m = (l + n - 1) * 3;
2089
- fn(t, f, q, D, m, u, r, _) && (R = !0);
3226
+ if (!D && _ && b) {
3227
+ const m = (f + n - 1) * 3;
3228
+ Yn(t, u, M, T, m, p, a, y) && (D = !0);
2090
3229
  }
2091
- if (!R && g && I) {
2092
- const m = (l + n + 1) * 3;
2093
- fn(t, f, T, D, m, u, r, _) && (R = !0);
3230
+ if (!D && g && b) {
3231
+ const m = (f + n + 1) * 3;
3232
+ Yn(t, u, k, T, m, p, a, y) && (D = !0);
2094
3233
  }
2095
- R && (o[l] |= Eo);
3234
+ D && (s[f] |= Xi);
2096
3235
  }
2097
3236
  }
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;
3237
+ function lc(s, t, n, e) {
3238
+ const i = n * e;
3239
+ for (let o = 0; o < i; o++)
3240
+ if (s[o] & Xi) {
3241
+ const r = o * 3, c = lt(t[r], t[r + 1], t[r + 2]);
3242
+ t[r] = c, t[r + 1] = c, t[r + 2] = c;
2104
3243
  }
2105
3244
  }
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,
3245
+ function lt(s, t, n) {
3246
+ return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
3247
+ }
3248
+ const hc = 3, fc = 0n, Si = 16;
3249
+ function uc(s, t, n, e = !0) {
3250
+ if (e && Lr(s), s.contours.length === 0) return null;
3251
+ const i = pc(s), o = t, r = n, c = Math.max(1, Math.ceil((i.maxX - i.minX) * o)) + 2 * r, a = Math.max(1, Math.ceil((i.maxY - i.minY) * o)) + 2 * r, l = r / o - i.minX, h = r / o - i.minY;
3252
+ br(s), Yr(s, hc, fc);
3253
+ const f = new Float32Array(c * a * 3);
3254
+ return Xr(s, c, a, o, l, h, r, f), nc(f, s, c, a, o, l, h), ec(f, s, c, a, o, l, h, r), {
3255
+ msdf: f,
2117
3256
  w: c,
2118
- h: r,
2119
- planeLeft: -h,
2120
- planeBottom: -p,
2121
- planeRight: c / e - h,
2122
- planeTop: r / e - p
3257
+ h: a,
3258
+ planeLeft: -l,
3259
+ planeBottom: -h,
3260
+ planeRight: c / o - l,
3261
+ planeTop: a / o - h
2123
3262
  };
2124
3263
  }
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);
3264
+ const Je = [0, 0];
3265
+ function pc(s) {
3266
+ let t = 1 / 0, n = 1 / 0, e = -1 / 0, i = -1 / 0;
3267
+ for (const o of s.contours)
3268
+ for (const r of o)
3269
+ for (let c = 0; c <= Si; c++) {
3270
+ r.point(c / Si, Je);
3271
+ const a = Je[0], l = Je[1];
3272
+ a < t && (t = a), l < n && (n = l), a > e && (e = a), l > i && (i = l);
2134
3273
  }
2135
- return { minX: t, minY: n, maxX: s, maxY: i };
3274
+ return { minX: t, minY: n, maxX: e, maxY: i };
2136
3275
  }
2137
- function ai(o) {
3276
+ function _c(s) {
2138
3277
  let t = 0, n = 0;
2139
- for (const c of o)
3278
+ for (const c of s)
2140
3279
  t += c.w * c.h, n = Math.max(n, c.w);
2141
- o.sort((c, r) => r.h - c.h);
3280
+ s.sort((c, a) => a.h - c.h);
2142
3281
  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];
2147
- if (!(c.w > h.w || c.h > h.h)) {
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({
2152
- x: h.x + c.w,
2153
- y: h.y,
2154
- w: h.w - c.w,
3282
+ let o = 0, r = 0;
3283
+ for (const c of s)
3284
+ for (let a = i.length - 1; a >= 0; a--) {
3285
+ const l = i[a];
3286
+ if (!(c.w > l.w || c.h > l.h)) {
3287
+ if (c.x = l.x, c.y = l.y, r = Math.max(r, c.y + c.h), o = Math.max(o, c.x + c.w), c.w === l.w && c.h === l.h) {
3288
+ const h = i.pop();
3289
+ h && a < i.length && (i[a] = h);
3290
+ } else c.h === l.h ? (l.x += c.w, l.w -= c.w) : c.w === l.w ? (l.y += c.h, l.h -= c.h) : (i.push({
3291
+ x: l.x + c.w,
3292
+ y: l.y,
3293
+ w: l.w - c.w,
2155
3294
  h: c.h
2156
- }), h.y += c.h, h.h -= c.h);
3295
+ }), l.y += c.h, l.h -= c.h);
2157
3296
  break;
2158
3297
  }
2159
3298
  }
2160
3299
  return {
2161
- w: e,
3300
+ w: o,
2162
3301
  // container width
2163
- h: a,
3302
+ h: r,
2164
3303
  // container height
2165
- fill: t / (e * a) || 0
3304
+ fill: t / (o * r) || 0
2166
3305
  // space utilization
2167
3306
  };
2168
3307
  }
2169
- const Mo = 4;
2170
- function as(o) {
2171
- const t = o < 0 ? 0 : o > 1 ? 1 : o;
3308
+ const Ii = 4, yc = {
3309
+ x: 0,
3310
+ y: 0,
3311
+ w: 0,
3312
+ h: 0,
3313
+ advance: 0,
3314
+ planeLeft: 0,
3315
+ planeBottom: 0,
3316
+ planeRight: 0,
3317
+ planeTop: 0
3318
+ };
3319
+ function Qe(s) {
3320
+ const t = s < 0 ? 0 : s > 1 ? 1 : s;
2172
3321
  return ~Math.trunc(255.5 - 255 * t) & 255;
2173
3322
  }
2174
- class li {
3323
+ class gc {
2175
3324
  /**
2176
3325
  * @param font Font for the glyph/layout methods; `null` for a shapes-only atlas.
2177
3326
  * @param opts Generation scale and distance range.
2178
3327
  */
2179
3328
  constructor(t, n = {}) {
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;
3329
+ this._width = 0, this._height = 0, this._pixels = new Uint8Array(0), this._cache = /* @__PURE__ */ new Map(), this._byGid = [], 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;
2181
3330
  }
2182
3331
  /** Packed atlas texture width in texels (chosen by potpack). */
2183
3332
  get width() {
@@ -2203,7 +3352,7 @@ class li {
2203
3352
  */
2204
3353
  glyphs(t) {
2205
3354
  const n = this._requireFont();
2206
- return this.glyphsByIndex(Array.from(t, (s) => n.glyphId(s)));
3355
+ return this.glyphsByIndex(Array.from(t, (e) => n.glyphId(e)));
2207
3356
  }
2208
3357
  /**
2209
3358
  * Single-glyph convenience: generates + packs if missing. Repacks the
@@ -2223,17 +3372,17 @@ class li {
2223
3372
  */
2224
3373
  glyphsByIndex(t) {
2225
3374
  const n = [];
2226
- let s = 0;
3375
+ let e = 0;
2227
3376
  for (const i of t) {
2228
- const e = this._cache.get(i);
2229
- if (e) {
2230
- n.push(e.glyph);
3377
+ const o = this._cache.get(i);
3378
+ if (o) {
3379
+ n.push(o.glyph);
2231
3380
  continue;
2232
3381
  }
2233
- const a = this._generateForGlyphId(i);
2234
- this._cache.set(i, a), n.push(a.glyph), s++;
3382
+ const r = this._generateForGlyphId(i);
3383
+ this._cache.set(i, r), this._byGid[i] = r.glyph, n.push(r.glyph), e++;
2235
3384
  }
2236
- return s > 0 && this._repack(), n;
3385
+ return e > 0 && this._repack(), n;
2237
3386
  }
2238
3387
  /** Single-glyph convenience for {@link Atlas.glyphsByIndex} — see its
2239
3388
  * doc. For more than one glyph, prefer {@link Atlas.glyphsByIndex}
@@ -2251,12 +3400,12 @@ class li {
2251
3400
  */
2252
3401
  shapes(t) {
2253
3402
  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);
3403
+ let e = 0;
3404
+ for (const [i, o] of t) {
3405
+ let r = this._cacheByKey.get(i);
3406
+ r || (r = this._generate(o, 0), this._cacheByKey.set(i, r), e++), n.push(r.glyph);
2258
3407
  }
2259
- return s > 0 && this._repack(), n;
3408
+ return e > 0 && this._repack(), n;
2260
3409
  }
2261
3410
  /** The font, or a clear error for glyph/layout calls on a shapes-only atlas. */
2262
3411
  _requireFont() {
@@ -2265,44 +3414,51 @@ class li {
2265
3414
  }
2266
3415
  /** Generates the MSDF for `glyphId`. Does not cache and does not pack. */
2267
3416
  _generateForGlyphId(t) {
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);
3417
+ const n = this._requireFont(), e = n.metrics.unitsPerEm, i = n.shape(t);
3418
+ return dr(i, e), this._generate(i, n.advance(t) / e);
2270
3419
  }
2271
3420
  /** Generates one entry from an em-unit shape. Does not cache or pack. */
2272
3421
  _generate(t, n) {
2273
- const s = ci(t, this._pxPerEm, this._pxrange);
3422
+ const e = uc(t, this._pxPerEm, this._pxrange);
2274
3423
  return { glyph: {
2275
3424
  x: 0,
2276
3425
  y: 0,
2277
- w: s ? s.w : 0,
2278
- h: s ? s.h : 0,
3426
+ w: e ? e.w : 0,
3427
+ h: e ? e.h : 0,
2279
3428
  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 };
3429
+ planeLeft: e ? e.planeLeft : 0,
3430
+ planeBottom: e ? e.planeBottom : 0,
3431
+ planeRight: e ? e.planeRight : 0,
3432
+ planeTop: e ? e.planeTop : 0
3433
+ }, msdf: e ? e.msdf : null };
2285
3434
  }
2286
3435
  /**
2287
- * Lays out `text` left-to-right on a single line, applying kerning.
3436
+ * Lays out `text` left-to-right on a single line, kerned the way Chrome
3437
+ * kerns it (see src/font/shaper.ts: script runs, GPOS or the `kern` table).
2288
3438
  * Generates any missing glyphs and packs the atlas **once** for the
2289
- * whole run. Baseline is y=0 (`penY` on every result is 0); each `penX`
2290
- * is the pen position in em. `text` must not contain `\n` — use
3439
+ * whole run. Baseline is y=0 (`penY` is the glyph's GPOS y offset, almost
3440
+ * always 0); each `penX` is the glyph's drawing origin in em. One entry
3441
+ * per codepoint (no ligatures). `text` must not contain `\n` — use
2291
3442
  * {@link Atlas.layoutMultiline} for multi-line input.
2292
3443
  */
2293
3444
  layout(t) {
2294
- const n = [];
2295
- for (const r of t) n.push(r.codePointAt(0));
2296
- this.glyphs(n);
2297
- const s = [], i = this._requireFont(), e = i.metrics.unitsPerEm;
2298
- let a = 0, c = -1;
2299
- for (const r of n) {
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;
2304
- }
2305
- return { glyphs: s, widthEm: a };
3445
+ const n = this._requireFont(), e = sr(n, t), i = C._gid, o = C._gp;
3446
+ let r = 0;
3447
+ const c = this._byGid;
3448
+ for (let y = 0; y < e; y++) {
3449
+ const _ = i[y];
3450
+ if (o[y] & xn || c[_]) continue;
3451
+ const g = this._generateForGlyphId(_);
3452
+ this._cache.set(_, g), c[_] = g.glyph, r++;
3453
+ }
3454
+ r > 0 && this._repack();
3455
+ const a = C._xa, l = C._xo, h = C._yo, f = n.metrics.unitsPerEm, u = [];
3456
+ let p = 0;
3457
+ for (let y = 0; y < e; y++) {
3458
+ const _ = o[y] & xn ? yc : c[i[y]];
3459
+ u.push({ glyph: _, penX: (p + l[y]) / f, penY: h[y] / f }), p += a[y];
3460
+ }
3461
+ return { glyphs: u, widthEm: p / f };
2306
3462
  }
2307
3463
  /**
2308
3464
  * Lays out `text` as one or more `\n`-separated lines, each run through
@@ -2320,15 +3476,16 @@ class li {
2320
3476
  * cropping.
2321
3477
  */
2322
3478
  layoutMultiline(t) {
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 = [];
3479
+ const n = this._requireFont(), e = n.metrics.unitsPerEm, i = (n.metrics.ascender - n.metrics.descender + n.metrics.lineGap) / e, o = t.split(`
3480
+ `), r = [];
2325
3481
  let c = 0;
2326
- for (let r = 0; r < e.length; r++) {
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);
3482
+ for (let a = 0; a < o.length; a++) {
3483
+ const { glyphs: l, widthEm: h } = this.layout(o[a]), f = -a * i;
3484
+ for (const u of l)
3485
+ r.push({ glyph: u.glyph, penX: u.penX, penY: f + u.penY });
3486
+ h > c && (c = h);
2330
3487
  }
2331
- return { glyphs: a, widthEm: c, heightEm: e.length * i };
3488
+ return { glyphs: r, widthEm: c, heightEm: o.length * i };
2332
3489
  }
2333
3490
  /** Repacks every cached entry (glyph-index- and string-keyed caches — one
2334
3491
  * shared texture) with potpack, reallocates the texture, and re-blits each
@@ -2342,10 +3499,10 @@ class li {
2342
3499
  _repack() {
2343
3500
  const t = [];
2344
3501
  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));
3502
+ for (const { glyph: o, msdf: r } of i.values())
3503
+ r && t.push({ w: o.w + 1, h: o.h + 1, x: 0, y: 0, glyph: o, msdf: r });
3504
+ const { w: n, h: e } = _c(t);
3505
+ this._width = n, this._height = e, this._pixels = new Uint8Array(n * e * Ii), this._floats && (this._floats = new Float32Array(n * e * 3));
2349
3506
  for (const i of t)
2350
3507
  i.glyph.x = i.x, i.glyph.y = i.y, this._blit(i.msdf, i.x, i.y, i.glyph.w, i.glyph.h);
2351
3508
  }
@@ -2353,37 +3510,37 @@ class li {
2353
3510
  * Quantise `msdf` (float, y-up, row 0 = bottom, w×h×3) into `_pixels` at
2354
3511
  * atlas rect (`ax`, `ay`, `w`, `h`) — the single y-flip point.
2355
3512
  */
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;
3513
+ _blit(t, n, e, i, o) {
3514
+ var a;
3515
+ const r = this._width, c = this._pixels;
3516
+ for (let l = 0; l < o; l++) {
3517
+ const h = e + (o - 1 - l);
3518
+ (a = this._floats) == null || a.set(t.subarray(l * i * 3, (l + 1) * i * 3), (h * r + n) * 3);
3519
+ for (let f = 0; f < i; f++) {
3520
+ const u = (l * i + f) * 3, p = (h * r + (n + f)) * Ii;
3521
+ c[p] = Qe(t[u]), c[p + 1] = Qe(t[u + 1]), c[p + 2] = Qe(t[u + 2]), c[p + 3] = 255;
2365
3522
  }
2366
3523
  }
2367
3524
  }
2368
3525
  }
2369
- const wo = /* @__PURE__ */ new Map();
2370
- self.onmessage = (o) => {
2371
- const t = o.data;
3526
+ const Di = /* @__PURE__ */ new Map();
3527
+ self.onmessage = (s) => {
3528
+ const t = s.data;
2372
3529
  if (t.type === "build")
2373
3530
  try {
2374
- let n = wo.get(t.fontKey);
3531
+ let n = Di.get(t.fontKey);
2375
3532
  if (!n) {
2376
3533
  if (!t.font)
2377
3534
  throw new Error(
2378
3535
  `atlas-worker: no cached font for fontKey "${t.fontKey}" and no \`font\` bytes provided on this request`
2379
3536
  );
2380
- n = new pe(t.font), wo.set(t.fontKey, n);
3537
+ n = new xr(t.font), Di.set(t.fontKey, n);
2381
3538
  }
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: _ }) => ({
2383
- ...f,
2384
- penX: u,
2385
- penY: _
2386
- })), p = i.texture.slice().buffer, l = {
3539
+ const e = performance.now(), i = new gc(n, { pixelsPerEm: t.pixelsPerEm, pxrange: t.pxrange }), { glyphs: o, widthEm: r, heightEm: c } = i.layoutMultiline(t.text), a = performance.now() - e, l = o.map(({ glyph: u, penX: p, penY: y }) => ({
3540
+ ...u,
3541
+ penX: p,
3542
+ penY: y
3543
+ })), h = i.texture.slice().buffer, f = {
2387
3544
  type: "built",
2388
3545
  id: t.id,
2389
3546
  pixelsPerEm: t.pixelsPerEm,
@@ -2391,15 +3548,15 @@ self.onmessage = (o) => {
2391
3548
  pxrangeEm: i.pxrangeEm,
2392
3549
  width: i.width,
2393
3550
  height: i.height,
2394
- texture: p,
2395
- glyphs: h,
2396
- widthEm: a,
3551
+ texture: h,
3552
+ glyphs: l,
3553
+ widthEm: r,
2397
3554
  heightEm: c,
2398
- genMs: r
3555
+ genMs: a
2399
3556
  };
2400
- self.postMessage(l, [p]);
3557
+ self.postMessage(f, [h]);
2401
3558
  } catch (n) {
2402
- const s = { type: "error", id: t.id, message: String(n) };
2403
- self.postMessage(s);
3559
+ const e = { type: "error", id: t.id, message: String(n) };
3560
+ self.postMessage(e);
2404
3561
  }
2405
3562
  };