msdfgen-ts 0.1.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 Mt {
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 Mt {
78
78
  return this._view.getInt16(t, !1);
79
79
  }
80
80
  }
81
- function io(i, t) {
82
- const n = new Mt(i, t);
81
+ function Qi(s, t) {
82
+ const n = new St(s, t);
83
83
  n.skip(2);
84
- const s = n.u16();
85
- let o = null;
86
- for (let p = 0; p < s; p++) {
87
- const c = n.u16(), r = n.u16(), h = n.u32(), l = t + h, a = n.peekU16(l);
88
- let f = -1;
89
- c === 3 && r === 10 && a === 12 ? f = 5 : c === 0 && r === 6 && a === 12 ? f = 4 : c === 0 && r === 4 && a === 12 ? f = 3 : c === 3 && r === 1 && a === 4 ? f = 2 : c === 0 && r <= 3 && a === 4 && (f = 1), f > ((o == null ? void 0 : o.priority) ?? -1) && (o = { priority: f, subtableAbsOffset: l });
90
- }
91
- if (!o) return () => 0;
92
- const e = n.peekU16(o.subtableAbsOffset);
93
- return e === 12 ? co(i, o.subtableAbsOffset) : e === 4 ? ro(i, o.subtableAbsOffset) : () => 0;
94
- }
95
- function co(i, t) {
96
- const n = new Mt(i, t);
84
+ const e = n.u16();
85
+ let i = null;
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
+ }
91
+ if (!i) return () => 0;
92
+ const o = n.peekU16(i.subtableAbsOffset);
93
+ return o === 12 ? to(s, i.subtableAbsOffset) : o === 4 ? no(s, i.subtableAbsOffset) : () => 0;
94
+ }
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(), o = new Uint32Array(s), e = new Uint32Array(s), p = new Uint32Array(s);
99
- for (let c = 0; c < s; c++)
100
- o[c] = n.u32(), e[c] = n.u32(), p[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 l = r + h >>> 1, a = o[l] ?? 0, f = e[l] ?? 0;
105
- if (c < a) h = l - 1;
106
- else if (c > f) r = l + 1;
107
- else return (p[l] ?? 0) + (c - a);
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(i, t) {
113
- const n = new Mt(i, 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
- const o = n.u16() >>> 1;
115
+ const i = n.u16() >>> 1;
116
116
  n.skip(6);
117
- const e = new Uint16Array(o);
118
- for (let a = 0; a < o; a++) e[a] = n.u16();
117
+ const o = new Uint16Array(i);
118
+ for (let f = 0; f < i; f++) o[f] = n.u16();
119
119
  n.skip(2);
120
- const p = new Uint16Array(o);
121
- for (let a = 0; a < o; a++) p[a] = n.u16();
122
- const c = new Int16Array(o);
123
- for (let a = 0; a < o; a++) c[a] = n.i16();
124
- const r = new Int32Array(o), h = new Uint16Array(o);
125
- for (let a = 0; a < o; a++)
126
- r[a] = n.pos, h[a] = n.u16();
127
- const l = new DataView(i);
128
- return (a) => {
129
- if (a > 65535) return 0;
130
- let f = 0, y = o - 1;
131
- for (; f <= y; ) {
132
- const _ = f + y >>> 1, u = e[_] ?? 0;
133
- if (a > u)
134
- f = _ + 1;
135
- else if (a < (p[_] ?? 0))
136
- y = _ - 1;
120
+ const r = new Uint16Array(i);
121
+ for (let f = 0; f < i; f++) r[f] = n.u16();
122
+ const c = new Int16Array(i);
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 g = h[_] ?? 0, A = c[_] ?? 0, m = p[_] ?? 0;
140
- if (g === 0)
141
- return a + A & 65535;
142
- const v = (r[_] ?? 0) + g + (a - m) * 2, w = l.getUint16(v, !1);
143
- return w === 0 ? 0 : w + A & 65535;
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 ao(i, t) {
150
- const n = new Mt(i, 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
- const o = n.i16();
155
- return { unitsPerEm: s, indexToLocFormat: o };
154
+ const i = n.i16();
155
+ return { unitsPerEm: e, indexToLocFormat: i };
156
156
  }
157
- function ho(i, t) {
158
- const n = new Mt(i, t);
157
+ function so(s, t) {
158
+ const n = new St(s, t);
159
159
  n.skip(4);
160
- const s = n.i16(), o = 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 p = n.u16();
163
- return { ascender: s, descender: o, lineGap: e, numberOfHMetrics: p };
162
+ const r = n.u16();
163
+ return { ascender: e, descender: i, lineGap: o, numberOfHMetrics: r };
164
164
  }
165
- function po(i, t, n, s) {
166
- const o = new Mt(i, t), e = new Array(n);
167
- let p = 0;
168
- for (let c = 0; c < s; c++) {
169
- const r = o.u16(), h = o.i16();
170
- e[c] = { advanceWidth: r, lsb: h }, p = r;
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 = o.i16();
174
- e[c] = { advanceWidth: p, 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 lo(i, t, n, s) {
179
- const o = new Mt(i, t), e = n + 1, p = new Array(e);
180
- if (s === 0)
181
- for (let c = 0; c < e; c++) p[c] = o.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++) p[c] = o.u32();
184
- return p;
183
+ for (let c = 0; c < o; c++) r[c] = i.u32();
184
+ return r;
185
185
  }
186
- function fo(i, t) {
187
- const n = new Mt(i, 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 yo(i, t, n, s) {
191
- return i * n + t * s;
190
+ function co(s, t, n, e) {
191
+ return s * n + t * e;
192
192
  }
193
- function J(i, t, n, s) {
194
- return i * s - t * n;
193
+ function z(s, t, n, e) {
194
+ return s * e - t * n;
195
195
  }
196
- function uo(i, t, n) {
197
- return (1 - n) * i + n * t;
196
+ function ao(s, t, n) {
197
+ return (1 - n) * s + n * t;
198
198
  }
199
- function rt(i) {
200
- return +(i > 0) - +(i < 0);
199
+ function pt(s) {
200
+ return +(s > 0) - +(s < 0);
201
201
  }
202
- function Et(i) {
203
- return 2 * +(i > 0) - 1;
202
+ function Nt(s) {
203
+ return 2 * +(s > 0) - 1;
204
204
  }
205
- function $s(i, 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 : (i[0] = -s / n, 1);
208
- const o = n * n - 4 * t * s;
209
- if (o > 0) {
210
- const e = Math.sqrt(o);
211
- return i[0] = (-n + e) / (2 * t), i[1] = (-n - e) / (2 * t), 2;
212
- } else if (o === 0)
213
- return i[0] = -n / (2 * t), 1;
207
+ return n === 0 ? e === 0 ? -1 : 0 : (s[0] = -e / n, 1);
208
+ const i = n * n - 4 * t * e;
209
+ if (i > 0) {
210
+ const o = Math.sqrt(i);
211
+ return s[0] = (-n + o) / (2 * t), s[1] = (-n - o) / (2 * t), 2;
212
+ } else if (i === 0)
213
+ return s[0] = -n / (2 * t), 1;
214
214
  return 0;
215
215
  }
216
- function _o(i, t, n, s) {
217
- const o = t * t, e = 1 / 9 * (o - 3 * n), p = 1 / 54 * (t * (2 * o - 9 * n) + 27 * s), c = p * p, r = e * e * e, h = t * (1 / 3);
218
- if (c < r) {
219
- let l = p / Math.sqrt(r);
220
- l < -1 && (l = -1), l > 1 && (l = 1), l = Math.acos(l);
221
- const a = -2 * Math.sqrt(e);
222
- return i[0] = a * Math.cos(1 / 3 * l) - h, i[1] = a * Math.cos(1 / 3 * (l + 2 * Math.PI)) - h, i[2] = a * Math.cos(1 / 3 * (l - 2 * Math.PI)) - h, 3;
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 l = (p < 0 ? 1 : -1) * Math.pow(Math.abs(p) + Math.sqrt(c - r), 0.3333333333333333), a = l === 0 ? 0 : e / l;
225
- return i[0] = l + a - h, l === a || Math.abs(l - a) < 1e-12 * Math.abs(l + a) ? (i[1] = -0.5 * (l + a) - h, 2) : 1;
224
+ const 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 xo(i, t, n, s, o) {
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 _o(i, e, s / t, o / t);
233
- }
234
- return $s(i, n, s, o);
235
- }
236
- const go = 24;
237
- function Pt(i, t, n, s) {
238
- return ((s + i) * s + t) * s + n;
239
- }
240
- function Mo(i, t, n, s, o, e, p) {
241
- const c = e < 0;
242
- let r = s - e * (o - s) / (p - e);
243
- r > s && r < o || (r = 0.5 * (s + o));
244
- for (let h = 0; h < go; h++) {
245
- const l = Pt(i, t, n, r);
246
- if (l === 0) return r;
247
- l < 0 === c ? s = r : o = r;
248
- const a = (3 * r + 2 * i) * r + t;
249
- let f = r - l / a;
250
- f > s && f < o || (f = 0.5 * (s + o));
251
- const y = f - r;
252
- if (r = f, (y < 0 ? -y : y) <= 1e-15 * (r < 0 ? -r : r)) break;
253
- }
254
- return r;
255
- }
256
- function Bt(i, t, n, s, o, e, p, c, r) {
257
- return e === 0 ? c[r++] = s : e < 0 != p < 0 && (c[r++] = Mo(i, t, n, s, o, e, p)), r;
258
- }
259
- function bo(i, t, n, s, o, e) {
260
- let p = 0;
261
- if (i === 0) {
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
+ }
254
+ return a;
255
+ }
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
+ }
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 <= o && (e[p++] = f), p;
263
+ const u = -n / t;
264
+ return u >= e && u <= i && (o[r++] = u), r;
265
265
  }
266
- const c = t * t - 4 * i * 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 l, a;
270
- if (h === 0)
271
- l = 0, a = 0;
272
- else if (l = h / i, a = n / h, l > a) {
273
- const f = l;
274
- l = a, a = f;
275
- }
276
- return l >= s && l <= o && (e[p++] = l), a !== l && a >= s && a <= o && (e[p++] = a), p;
277
- }
278
- function wo(i, t, n, s, o, e, p) {
279
- if (i === 0) return bo(t, n, s, o, e, p);
280
- const c = 1 / i;
281
- t *= c, n *= c, s *= c;
282
- const r = Pt(t, n, s, o), h = Pt(t, n, s, e), l = t * t - 3 * n;
283
- let a = 0;
284
- if (l <= 0)
285
- a = Bt(t, n, s, o, e, r, h, p, 0);
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(l) / 3, y = -t / 3, _ = y - f, u = y + f;
288
- let x = o, g = r;
289
- if (_ > o && _ < e) {
290
- const A = Pt(t, n, s, _);
291
- a = Bt(t, n, s, x, _, g, A, p, a), x = _, g = A;
287
+ const 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 (u > o && u < e) {
294
- const A = Pt(t, n, s, u);
295
- a = Bt(t, n, s, x, u, g, A, p, a), x = u, g = A;
293
+ if (_ > 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
- a = Bt(t, n, s, x, e, g, h, p, a);
297
+ f = Dn(t, n, e, g, o, x, l, r, f);
298
298
  }
299
- return h === 0 && (p[a++] = e), a;
299
+ return l === 0 && (r[f++] = o), f;
300
300
  }
301
- const at = 0, et = 1, Gt = 2, Is = 4, Ao = 4, U = [0, 0, 0];
302
- class it {
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 it {
311
311
  * @param p3x CUBIC: end x. Others: 0.
312
312
  * @param p3y CUBIC: end y. Others: 0.
313
313
  */
314
- constructor(t, n, s, o, e, p, c, r, h) {
315
- this.type = t, this.p0x = n, this.p0y = s, this.p1x = o, this.p1y = e, this.p2x = p, this.p2y = c, this.p3x = r, this.p3y = h, this.color = 7;
314
+ constructor(t, n, 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 at:
320
+ case ft:
321
321
  return this.p1x;
322
- case et:
322
+ case at:
323
323
  return this.p2x;
324
324
  default:
325
325
  return this.p3x;
@@ -328,9 +328,9 @@ class it {
328
328
  /** Endpoint y. */
329
329
  endY() {
330
330
  switch (this.type) {
331
- case at:
331
+ case ft:
332
332
  return this.p1y;
333
- case et:
333
+ case at:
334
334
  return this.p2y;
335
335
  default:
336
336
  return this.p3y;
@@ -344,20 +344,20 @@ class it {
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 at: {
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 et: {
354
- const o = this.p0x + s * (this.p1x - this.p0x), e = this.p0y + s * (this.p1y - this.p0y), p = this.p1x + s * (this.p2x - this.p1x), c = this.p1y + s * (this.p2y - this.p1y);
355
- n[0] = o + s * (p - o), n[1] = e + s * (c - e);
353
+ case 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 o = this.p0x + s * (this.p1x - this.p0x), e = this.p0y + s * (this.p1y - this.p0y), p = this.p1x + s * (this.p2x - this.p1x), c = this.p1y + s * (this.p2y - this.p1y), r = this.p2x + s * (this.p3x - this.p2x), h = this.p2y + s * (this.p3y - this.p2y), l = o + s * (p - o), a = e + s * (c - e), f = p + s * (r - p), y = c + s * (h - c);
360
- n[0] = l + s * (f - l), n[1] = a + s * (y - a);
359
+ const i = this.p0x + 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 it {
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 at: {
375
+ case ft: {
376
376
  n[0] = this.p1x - this.p0x, n[1] = this.p1y - this.p0y;
377
377
  return;
378
378
  }
379
- case et: {
380
- const o = this.p1x - this.p0x + s * (this.p2x - this.p1x - (this.p1x - this.p0x)), e = this.p1y - this.p0y + s * (this.p2y - this.p1y - (this.p1y - this.p0y));
381
- o !== 0 || e !== 0 ? (n[0] = o, n[1] = e) : (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y);
379
+ case 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 o = this.p1x - this.p0x, e = this.p1y - this.p0y, p = this.p2x - this.p1x, c = this.p2y - this.p1y, r = this.p3x - this.p2x, h = this.p3y - this.p2y, l = o + s * (p - o) + s * (p + s * (r - p) - (o + s * (p - o))), a = e + s * (c - e) + s * (c + s * (h - c) - (e + s * (c - e)));
386
- l !== 0 || a !== 0 ? (n[0] = l, n[1] = a) : s === 0 ? (n[0] = this.p2x - this.p0x, n[1] = this.p2y - this.p0y) : s === 1 ? (n[0] = this.p3x - this.p1x, n[1] = this.p3y - this.p1y) : (n[0] = l, n[1] = a);
385
+ const i = this.p1x - this.p0x, 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 it {
398
398
  splitInThirds() {
399
399
  const t = [0, 0], n = [0, 0];
400
400
  switch (this.type) {
401
- case at: {
401
+ case ft: {
402
402
  this.point(1 / 3, t), this.point(2 / 3, n);
403
- const s = new it(at, this.p0x, this.p0y, t[0], t[1], 0, 0, 0, 0), o = new it(at, t[0], t[1], n[0], n[1], 0, 0, 0, 0), e = new it(at, n[0], n[1], this.p1x, this.p1y, 0, 0, 0, 0);
404
- return s.color = o.color = e.color = this.color, [s, o, e];
403
+ const 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 et: {
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), o = this.p0y + 1 / 3 * (this.p1y - this.p0y), e = this.p0x + 5 / 9 * (this.p1x - this.p0x), p = this.p0y + 5 / 9 * (this.p1y - this.p0y), c = this.p1x + 4 / 9 * (this.p2x - this.p1x), r = this.p1y + 4 / 9 * (this.p2y - this.p1y), h = e + 0.5 * (c - e), l = p + 0.5 * (r - p), a = this.p1x + 2 / 3 * (this.p2x - this.p1x), f = this.p1y + 2 / 3 * (this.p2y - this.p1y), y = new it(
409
- et,
408
+ const 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,
413
- o,
412
+ e,
413
+ i,
414
414
  t[0],
415
415
  t[1],
416
416
  0,
417
417
  0
418
- ), _ = new it(
419
- et,
418
+ ), y = new ot(
419
+ at,
420
420
  t[0],
421
421
  t[1],
422
- h,
423
422
  l,
423
+ h,
424
424
  n[0],
425
425
  n[1],
426
426
  0,
427
427
  0
428
- ), u = new it(
429
- et,
428
+ ), _ = new ot(
429
+ at,
430
430
  n[0],
431
431
  n[1],
432
- a,
433
432
  f,
433
+ u,
434
434
  this.p2x,
435
435
  this.p2y,
436
436
  0,
437
437
  0
438
438
  );
439
- return y.color = _.color = u.color = this.color, [y, _, u];
439
+ return 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), o = this.p0x === this.p1x && this.p0y === this.p1y ? this.p0y : this.p0y + 1 / 3 * (this.p1y - this.p0y), e = this.p0x + 1 / 3 * (this.p1x - this.p0x), p = this.p0y + 1 / 3 * (this.p1y - this.p0y), c = this.p1x + 1 / 3 * (this.p2x - this.p1x), r = this.p1y + 1 / 3 * (this.p2y - this.p1y), h = this.p2x + 1 / 3 * (this.p3x - this.p2x), l = this.p2y + 1 / 3 * (this.p3y - this.p2y), a = e + 1 / 3 * (c - e), f = p + 1 / 3 * (r - p), y = c + 1 / 3 * (h - c), _ = r + 1 / 3 * (l - r), u = a + 2 / 3 * (y - a), x = f + 2 / 3 * (_ - f), g = this.p0x + 2 / 3 * (this.p1x - this.p0x), A = this.p0y + 2 / 3 * (this.p1y - this.p0y), m = this.p1x + 2 / 3 * (this.p2x - this.p1x), v = this.p1y + 2 / 3 * (this.p2y - this.p1y), w = this.p2x + 2 / 3 * (this.p3x - this.p2x), E = this.p2y + 2 / 3 * (this.p3y - this.p2y), C = g + 2 / 3 * (m - g), F = A + 2 / 3 * (v - A), R = m + 2 / 3 * (w - m), b = v + 2 / 3 * (E - v), N = C + 1 / 3 * (R - C), I = F + 1 / 3 * (b - F), q = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3x : this.p2x + 2 / 3 * (this.p3x - this.p2x), O = this.p2x === this.p3x && this.p2y === this.p3y ? this.p3y : this.p2y + 2 / 3 * (this.p3y - this.p2y), X = new it(
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,
448
- o,
449
- a,
447
+ e,
448
+ i,
450
449
  f,
450
+ u,
451
451
  t[0],
452
452
  t[1]
453
- ), K = new it(
454
- Gt,
453
+ ), V = new ot(
454
+ nn,
455
455
  t[0],
456
456
  t[1],
457
- u,
458
- x,
459
- N,
460
- I,
457
+ _,
458
+ g,
459
+ R,
460
+ S,
461
461
  n[0],
462
462
  n[1]
463
- ), V = new it(
464
- Gt,
463
+ ), B = new ot(
464
+ nn,
465
465
  n[0],
466
466
  n[1],
467
- R,
468
- b,
469
- q,
470
- O,
467
+ A,
468
+ d,
469
+ E,
470
+ I,
471
471
  this.p3x,
472
472
  this.p3y
473
473
  );
474
- return X.color = K.color = V.color = this.color, [X, K, V];
474
+ return F.color = V.color = B.color = this.color, [F, V, B];
475
475
  }
476
476
  }
477
477
  }
@@ -488,95 +488,95 @@ class it {
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 at: {
494
- const o = this.p0x, e = this.p0y, p = this.p1x, c = this.p1y, r = t - o, h = n - e, l = p - o, a = c - e, f = l * l + a * a, y = (r * l + h * a) / f, _ = y > 0.5, u = (_ ? p : o) - t, x = (_ ? c : e) - n, g = Math.sqrt(u * u + x * x);
495
- if (y > 0 && y < 1) {
496
- const v = Math.sqrt(l * l + a * a), w = l / v, C = a / v * r - w * h;
497
- if (Math.abs(C) < g) {
498
- s.distance = C, s.dot = 0, s.param = y;
493
+ case 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 A = r * a - h * l;
503
- s.distance = Et(A) * g;
504
- const m = Math.sqrt(l * l + a * a);
505
- s.dot = g === 0 || m === 0 ? 0 : Math.abs((l * u + a * x) / (m * g)), s.param = y;
502
+ const 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 et: {
509
- const o = this.p0x, e = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, l = o - t, a = e - n, f = p - o, y = c - e, _ = r - p - f, u = h - c - y, x = _ * _ + u * u, g = 3 * (f * _ + y * u), A = 2 * (f * f + y * y) + (l * _ + a * u), m = l * f + a * y, v = wo(x, g, A, m, 0, 1, U);
510
- let w = f, E = y;
511
- const C = l * l + a * a;
512
- let F = Et(w * a - E * l), R = C, b = -(l * w + a * E) / (w * w + E * E);
508
+ case 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 I = r - t, q = h - n, O = I * I + q * q;
515
- O < R && (w = r - p, E = h - c, F = Et(w * q - E * I), R = O, b = ((t - p) * w + (n - c) * E) / (w * w + E * E));
514
+ const 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 I = 0; I < v; ++I) {
518
- const q = U[I];
519
- if (q > 0 && q < 1) {
520
- const O = l + 2 * q * f + q * q * _, X = a + 2 * q * y + q * q * u, K = O * O + X * X;
521
- if (K <= R) {
522
- const V = f + q * _, nt = y + q * u;
523
- F = Et(V * X - nt * O), R = K, b = q;
517
+ for (let S = 0; S < k; ++S) {
518
+ const E = K[S];
519
+ if (E > 0 && E < 1) {
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 N = F * Math.sqrt(R);
528
- if (b >= 0 && b <= 1) {
529
- s.distance = N, s.dot = 0, s.param = b;
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 = N, s.param = b, b < 0.5) {
533
- const I = Math.sqrt(f * f + y * y), q = Math.sqrt(C);
534
- s.dot = q === 0 || I === 0 ? 0 : Math.abs((f * l + y * a) / (I * q));
532
+ if (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 I = r - p, q = h - c, O = r - t, X = h - n, K = Math.sqrt(I * I + q * q), V = Math.sqrt(O * O + X * X);
537
- s.dot = K === 0 || V === 0 ? 0 : Math.abs((I * O + q * X) / (K * V));
536
+ const 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 o = this.p0x, e = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, l = this.p3x, a = this.p3y, f = o - t, y = e - n, _ = p - o, u = c - e, x = r - p - _, g = h - c - u, A = l - r - (r - p) - x, m = a - h - (h - c) - g;
543
- let v = _, w = u;
544
- v === 0 && w === 0 && (v = r - o, w = h - e);
545
- const E = Math.sqrt(f * f + y * y);
546
- let C = Et(v * y - w * f) * E, F = -(f * v + y * w) / (v * v + w * w);
542
+ const i = this.p0x, 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 R = l - t, b = a - n, N = Math.sqrt(R * R + b * b);
549
- if (N < Math.abs(C)) {
550
- let I = l - r, q = a - h;
551
- I === 0 && q === 0 && (I = l - p, q = a - c), v = I, w = q, C = Et(v * b - w * R) * N, F = ((v - R) * v + (w - b) * w) / (v * v + w * w);
548
+ const 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 R = 0; R <= Is; ++R) {
555
- let b = 1 / Is * R, N = f + 3 * b * _ + 3 * b * b * x + b * b * b * A, I = y + 3 * b * u + 3 * b * b * g + b * b * b * m, q = 3 * _ + 6 * b * x + 3 * b * b * A, O = 3 * u + 6 * b * g + 3 * b * b * m, X = 6 * x + 6 * b * A, K = 6 * g + 6 * b * m, V = b - (N * q + I * O) / (q * q + O * O + (N * X + I * K));
556
- if (V > 0 && V < 1) {
557
- let nt = Ao;
554
+ for (let 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 (b = V, N = f + 3 * b * _ + 3 * b * b * x + b * b * b * A, I = y + 3 * b * u + 3 * b * b * g + b * b * b * m, q = 3 * _ + 6 * b * x + 3 * b * b * A, O = 3 * u + 6 * b * g + 3 * b * b * m, !--nt) break;
560
- X = 6 * x + 6 * b * A, K = 6 * g + 6 * b * m, V = b - (N * q + I * O) / (q * q + O * O + (N * X + I * K));
561
- } while (V > 0 && V < 1);
562
- const H = Math.sqrt(N * N + I * I);
563
- H < Math.abs(C) && (C = Et(q * I - O * N) * H, F = b);
559
+ if (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
- if (F >= 0 && F <= 1) {
567
- s.distance = C, s.dot = 0, s.param = F;
566
+ if (m >= 0 && m <= 1) {
567
+ e.distance = D, e.dot = 0, e.param = m;
568
568
  return;
569
569
  }
570
- if (s.distance = C, s.param = F, F < 0.5) {
571
- let R = _, b = u;
572
- R === 0 && b === 0 && (R = r - o, b = h - e);
573
- const N = Math.sqrt(R * R + b * b);
574
- s.dot = E === 0 || N === 0 ? 0 : Math.abs((R * f + b * y) / (N * E));
570
+ if (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 R = l - r, b = a - h;
577
- R === 0 && b === 0 && (R = l - p, b = a - c);
578
- const N = l - t, I = a - n, q = Math.sqrt(R * R + b * b), O = Math.sqrt(N * N + I * I);
579
- s.dot = q === 0 || O === 0 ? 0 : Math.abs((R * N + b * I) / (q * O));
576
+ let 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 it {
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 at: {
599
- const o = this.p0y, e = this.p1y;
600
- if (t >= o && t < e || t >= e && t < o) {
601
- const p = (t - o) / (e - o);
602
- return n[0] = uo(this.p0x, this.p1x, p), s[0] = rt(e - o), 1;
598
+ case 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 et: {
607
- const o = this.p0x, e = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y;
608
- let l = 0, a = t > e ? 1 : -1;
609
- n[l] = o, e === t && (e < c || e === c && e < h ? s[l++] = 1 : a = 1);
606
+ case 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 = p - o, y = c - e, _ = r - p - f, u = h - c - y, x = $s(U, u, 2 * y, e - t);
612
- if (x >= 2 && U[0] > U[1]) {
613
- const g = U[0];
614
- U[0] = U[1], U[1] = g;
611
+ const 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 g = 0; g < x && l < 2; ++g) {
617
- const A = U[g];
618
- A >= 0 && A <= 1 && (n[l] = o + 2 * A * f + A * A * _, a * (y + A * u) >= 0 && (s[l++] = a, a = -a));
616
+ for (let 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 && (a > 0 && l > 0 && (--l, a = -1), (h < c || h === c && h < e) && l < 2 && (n[l] = r, a < 0 && (s[l++] = -1, a = 1))), a !== (t >= h ? 1 : -1) && (l > 0 ? --l : (Math.abs(h - t) < Math.abs(e - t) && (n[l] = r), s[l++] = a)), l;
621
+ return 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 o = this.p0x, e = this.p0y, p = this.p1x, c = this.p1y, r = this.p2x, h = this.p2y, l = this.p3x, a = this.p3y;
625
- let f = 0, y = t > e ? 1 : -1;
626
- n[f] = o, e === t && (e < c || e === c && (e < h || e === h && e < a) ? s[f++] = 1 : y = 1);
624
+ const i = this.p0x, 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 _ = l - 3 * r + 3 * p - o, u = a - 3 * h + 3 * c - e, x = 3 * r - 6 * p + 3 * o, g = 3 * h - 6 * c + 3 * e, A = 3 * p - 3 * o, m = 3 * c - 3 * e, v = xo(U, u, g, m, e - t);
629
- if (v >= 2) {
630
- if (U[0] > U[1]) {
631
- const w = U[0];
632
- U[0] = U[1], U[1] = w;
628
+ const 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 (v >= 3 && U[1] > U[2]) {
635
- const w = U[1];
636
- if (U[1] = U[2], U[2] = w, U[0] > U[1]) {
637
- const E = U[0];
638
- U[0] = U[1], U[1] = E;
634
+ if (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 w = 0; w < v && f < 3; ++w) {
643
- const E = U[w];
644
- E >= 0 && E <= 1 && (n[f] = ((_ * E + x) * E + A) * E + o, y * ((3 * u * E + 2 * g) * E + m) >= 0 && (s[f++] = y, y = -y));
642
+ for (let 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 a === t && (y > 0 && f > 0 && (--f, y = -1), (a < h || a === h && (a < c || a === c && a < e)) && f < 3 && (n[f] = l, y < 0 && (s[f++] = -1, y = 1))), y !== (t >= a ? 1 : -1) && (f > 0 ? --f : (Math.abs(a - t) < Math.abs(e - t) && (n[f] = l), s[f++] = y)), f;
647
+ return 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 it {
656
656
  * @returns A new CUBIC EdgeSegment with identical geometry.
657
657
  */
658
658
  convertToCubic() {
659
- const t = this.p0x + 0.6666666666666666 * (this.p1x - this.p0x), n = this.p0y + 2 / 3 * (this.p1y - this.p0y), s = this.p1x + 1 / 3 * (this.p2x - this.p1x), o = this.p1y + 1 / 3 * (this.p2y - this.p1y), e = new it(
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,
666
- o,
665
+ e,
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 Eo = 1, Do = 2, qo = 4, mo = 8, Rs = 16, Ts = 32, vo = 1, ks = 2, Co = 8, Io = 32, Ro = 64, To = 128;
674
- function ko(i, t, n, s, o) {
675
- const e = Zs(i, t, n, s, o), p = [];
676
- for (const c of e) {
677
- const r = Lo(c);
678
- r.length > 0 && p.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: p, inverseYAxis: !1 };
680
+ return { contours: r, inverseYAxis: !1 };
681
681
  }
682
- function Zs(i, t, n, s, o) {
683
- if (s === 0) return [];
684
- const e = t + n, p = new Mt(i, e), c = p.i16();
685
- return p.skip(8), c >= 0 ? Fo(p, c) : Po(i, p, t, o);
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 Fo(i, t) {
687
+ function vo(s, t) {
688
688
  if (t === 0) return [];
689
- const n = new Array(t);
690
- for (let a = 0; a < t; a++) n[a] = i.u16();
691
- const s = (n[t - 1] ?? 0) + 1, o = i.u16();
692
- i.skip(o);
693
- const e = new Uint8Array(s);
694
- for (let a = 0; a < s; ) {
695
- const f = i.u8();
696
- if (e[a++] = f, f & mo) {
697
- let y = i.u8();
698
- for (; y-- > 0; ) e[a++] = f;
699
- }
700
- }
701
- const p = new Float64Array(s);
689
+ const n = [];
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 a = 0; a < s; a++) {
704
- const f = e[a] ?? 0;
705
- if (f & Do) {
706
- const y = i.u8();
707
- c += f & Rs ? y : -y;
708
- } else f & Rs || (c += i.i16());
709
- p[a] = c;
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 a = 0; a < s; a++) {
714
- const f = e[a] ?? 0;
715
- if (f & qo) {
716
- const y = i.u8();
717
- c += f & Ts ? y : -y;
718
- } else f & Ts || (c += i.i16());
719
- r[a] = c;
720
- }
721
- const h = [];
722
- let l = 0;
723
- for (let a = 0; a < t; a++) {
724
- const f = n[a] ?? 0, y = So(e, p, r, l, f);
725
- y.length > 0 && h.push(y), l = f + 1;
726
- }
727
- return h;
728
- }
729
- function So(i, t, n, s, o) {
730
- const e = o - s + 1;
731
- if (e <= 0) return [];
732
- const p = [];
733
- for (let c = 0; c < e; c++) {
734
- const r = i[s + c] ?? 0, h = t[s + c] ?? 0, l = n[s + c] ?? 0;
735
- p.push({ x: h, y: l, onCurve: (r & Eo) !== 0 });
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 p;
737
+ return r;
738
738
  }
739
- function Lo(i) {
740
- const t = i.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 = i[c], h = i[(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;
752
- let o = 0;
751
+ const e = n.length;
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
- o = c;
756
+ i = c;
757
757
  break;
758
758
  }
759
759
  }
760
- const e = [];
761
- let p = 0;
762
- for (; p < s; ) {
763
- const c = n[(o + p) % s], r = n[(o + p + 1) % s];
764
- if (r.onCurve)
765
- e.push(new it(at, c.x, c.y, r.x, r.y, 0, 0, 0, 0)), p += 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[(o + p + 2) % s];
768
- e.push(new it(et, c.x, c.y, r.x, r.y, h.x, h.y, 0, 0)), p += 2;
767
+ const 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;
772
- }
773
- function Po(i, t, n, s) {
774
- const o = [];
775
- let e = 0;
776
- do {
777
- e = t.u16();
778
- const p = t.u16();
779
- let c, r;
780
- e & vo ? (c = t.i16(), r = t.i16()) : (c = t.u8(), r = t.u8(), e & ks && (c > 127 && (c -= 256), r > 127 && (r -= 256)));
781
- let h = 0, l = 0;
782
- e & ks && (h = c, l = r);
783
- let a = 1, f = 0, y = 0, _ = 1;
784
- e & Co ? a = _ = t.f2dot14() : e & Ro ? (a = t.f2dot14(), _ = t.f2dot14()) : e & To && (a = t.f2dot14(), f = t.f2dot14(), y = t.f2dot14(), _ = t.f2dot14());
785
- const u = s(p), x = Go(u, a, f, y, _, h, l);
786
- for (const g of x) o.push(g);
787
- } while (e & Io);
788
771
  return o;
789
772
  }
790
- function Fs(i) {
791
- return i >= 0 ? Math.floor(i + 0.5) : Math.ceil(i - 0.5);
792
- }
793
- function Go(i, t, n, s, o, e, p) {
794
- if (t === 1 && n === 0 && s === 0 && o === 1 && e === 0 && p === 0) return i;
795
- const r = t === 1 && n === 0 && s === 0 && o === 1;
796
- return i.map(
797
- (h) => h.map((l) => r ? { x: l.x + e, y: l.y + p, onCurve: l.onCurve } : {
798
- x: Fs(t * l.x + n * l.y + e),
799
- y: Fs(s * l.x + o * l.y + p),
800
- onCurve: l.onCurve
773
+ function So(s, t, n, e) {
774
+ const i = [];
775
+ let o = 0;
776
+ do {
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
+ return i;
789
+ }
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 Oo(i, t) {
805
- const n = new Mt(i, t);
806
- if (n.u16() !== 0)
807
- return Ss;
808
- const o = n.u16(), e = /* @__PURE__ */ new Map();
809
- for (let p = 0; p < o; p++) {
810
- const c = n.pos;
811
- n.skip(2);
812
- const r = n.u16(), h = n.u16(), l = h >> 8 & 255, a = !(h & 2), f = !!(h & 4);
813
- if (l !== 0 || !a || f) {
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
+ }
1408
+ }
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(_);
816
1494
  }
817
- const y = n.u16();
818
- n.skip(6);
819
- for (let _ = 0; _ < y; _++) {
820
- const u = n.u16(), x = n.u16(), g = n.i16(), A = (u & 65535) << 16 | x & 65535;
821
- e.set(A, g);
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;
822
1505
  }
823
- n.seek(c + r);
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;
1520
+ }
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 ? Ss : (p, c) => {
826
- const r = (p & 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);
829
1908
  }
830
- const Ss = () => 0;
831
- function No(i) {
832
- const t = new Mt(i);
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);
1912
+ }
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
- const o = t.u32();
836
- t.seek(o);
1922
+ const i = t.u32();
1923
+ t.seek(i);
837
1924
  } else
838
1925
  t.seek(0);
839
- return Uo(i, t);
1926
+ return yr(s, t);
840
1927
  }
841
- function Uo(i, 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();
846
- for (let o = 0; o < n; o++) {
847
- const e = String.fromCharCode(t.u8(), t.u8(), t.u8(), t.u8());
1932
+ const e = /* @__PURE__ */ new Map();
1933
+ for (let i = 0; i < n; i++) {
1934
+ const o = String.fromCharCode(t.u8(), t.u8(), t.u8(), t.u8());
848
1935
  t.skip(4);
849
- const p = t.u32(), c = t.u32();
850
- s.set(e, { offset: p, 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 Yo {
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 Yo {
862
1950
  * @param buffer Raw font file bytes.
863
1951
  */
864
1952
  constructor(t) {
865
- this._buffer = t, this._tables = No(t);
866
- const n = this._tables.get("head"), s = this._tables.get("maxp"), o = this._tables.get("hhea"), e = this._tables.get("hmtx"), p = this._tables.get("loca"), c = this._tables.get("cmap");
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");
869
- if (!o) throw new Error("Font missing required `hhea` table");
870
- if (!e) throw new Error("Font missing required `hmtx` table");
871
- if (!p) throw new Error("Font missing required `loca` table");
1956
+ if (!e) throw new Error("Font missing required `maxp` table");
1957
+ if (!i) throw new Error("Font missing required `hhea` 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 = ao(t, n.offset);
874
- const r = fo(t, s.offset);
875
- this._hhea = ho(t, o.offset), this._hmtx = po(t, e.offset, r.numGlyphs, this._hhea.numberOfHMetrics), this._loca = lo(t, p.offset, r.numGlyphs, this._head.indexToLocFormat), this._cmap = io(t, c.offset);
876
- const h = this._tables.get("kern");
877
- this._kern = h ? Oo(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 Yo {
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 Yo {
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 Yo {
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, o = s[t] ?? 0, p = (s[t + 1] ?? o) - o;
946
- return ko(
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
- o,
950
- p,
2088
+ i,
2089
+ r,
951
2090
  (c) => this._glyphRaw(c)
952
2091
  );
953
2092
  }
@@ -960,583 +2099,820 @@ class Yo {
960
2099
  _glyphRaw(t) {
961
2100
  const n = this._tables.get("glyf");
962
2101
  if (!n) return [];
963
- const s = this._loca, o = s[t] ?? 0, p = (s[t + 1] ?? o) - o;
964
- return Zs(
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
- o,
968
- p,
2106
+ i,
2107
+ r,
969
2108
  (c) => this._glyphRaw(c)
970
2109
  );
971
2110
  }
972
2111
  }
973
- function Xo(i, t) {
2112
+ function dr(s, t) {
974
2113
  const n = 1 / t;
975
- for (const s of i.contours)
976
- for (let o = 0; o < s.length; o++) {
977
- const e = s[o];
978
- if (e.p0x *= n, e.p0y *= n, e.p1x *= n, e.p1y *= n, e.p2x *= n, e.p2y *= n, e.p3x *= n, e.p3y *= n, e.type === et) {
979
- const p = e.p1x - e.p0x, c = e.p1y - e.p0y, r = e.p2x - e.p1x, h = e.p2y - e.p1y;
980
- J(p, c, r, h) === 0 && (s[o] = new it(at, e.p0x, e.p0y, e.p2x, e.p2y, 0, 0, 0, 0));
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));
981
2123
  }
982
2124
  }
983
2125
  }
984
- const Ls = 1e-6, Wo = 1.1111111111111112, Ho = new Float64Array(16);
985
- function Ps(i, t, n) {
986
- switch (t[n] = i.p0x, t[n + 1] = i.p0y, t[n + 2] = i.p1x, t[n + 3] = i.p1y, i.type) {
987
- case at:
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:
988
2130
  return 1;
989
- case et:
990
- return t[n + 4] = i.p2x, t[n + 5] = i.p2y, 2;
2131
+ case at:
2132
+ return t[n + 4] = s.p2x, t[n + 5] = s.p2y, 2;
991
2133
  default:
992
- return t[n + 4] = i.p2x, t[n + 5] = i.p2y, t[n + 6] = i.p3x, t[n + 7] = i.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;
993
2135
  }
994
2136
  }
995
- function Gs(i, t, n) {
2137
+ function gi(s, t, n) {
996
2138
  if (n === 3) {
997
- const s = i[t], o = i[t + 1], e = i[t + 2], p = i[t + 3], c = i[t + 4], r = i[t + 5], h = i[t + 6], l = i[t + 7];
998
- (e === s && p === o || e === h && p === l) && (c === s && r === o || c === h && r === l) && (i[t + 2] = h, i[t + 3] = l, n = 1);
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);
999
2141
  }
1000
2142
  if (n === 2) {
1001
- const s = i[t], o = i[t + 1], e = i[t + 2], p = i[t + 3], c = i[t + 4], r = i[t + 5];
1002
- (e === s && p === o || e === c && p === r) && (i[t + 2] = c, i[t + 3] = r, n = 1);
1003
- }
1004
- return n === 1 && i[t] === i[t + 2] && i[t + 1] === i[t + 3] && (n = 0), n;
1005
- }
1006
- function Vo(i, t) {
1007
- const n = Ho;
1008
- let s = Ps(i, n, 0), o = Ps(t, n, 8);
1009
- if (!(s >= 1 && s <= 3 && o >= 1 && o <= 3) || n[s * 2] !== n[8] || n[s * 2 + 1] !== n[9]) return 0;
1010
- s = Gs(n, 0, s), o = Gs(n, 8, o);
1011
- const e = n[s * 2], p = n[s * 2 + 1];
1012
- let c = 0, r = 0, h = 0, l = 0, a = 0, f = 0, y = 0, _ = 0, u = 0, x = 0, g = 0, A = 0;
1013
- if (s >= 1 && (c = n[(s - 1) * 2] - e, r = n[(s - 1) * 2 + 1] - p), s >= 2) {
1014
- const H = n[(s - 2) * 2] - n[(s - 1) * 2], z = n[(s - 2) * 2 + 1] - n[(s - 1) * 2 + 1];
1015
- h = H - c, l = z - r;
1016
- }
1017
- if (s >= 3) {
1018
- const H = n[(s - 3) * 2] - n[(s - 2) * 2], z = n[(s - 3) * 2 + 1] - n[(s - 2) * 2 + 1], ht = n[(s - 2) * 2] - n[(s - 1) * 2], st = n[(s - 2) * 2 + 1] - n[(s - 1) * 2 + 1];
1019
- a = H - ht - h, f = z - st - l, h *= 3, l *= 3;
1020
- }
1021
- if (o >= 1 && (y = n[10] - e, _ = n[11] - p), o >= 2) {
1022
- const H = n[12] - n[10], z = n[13] - n[11];
1023
- u = H - y, x = z - _;
1024
- }
1025
- if (o >= 3) {
1026
- const H = n[14] - n[12], z = n[15] - n[13], ht = n[12] - n[10], st = n[13] - n[11];
1027
- g = H - ht - u, A = z - st - x, u *= 3, x *= 3;
1028
- }
1029
- c *= s, r *= s, y *= o, _ *= o;
1030
- const m = c !== 0 || r !== 0;
1031
- if (m && (y !== 0 || _ !== 0)) {
1032
- const H = Math.sqrt(c * c + r * r), z = Math.sqrt(y * y + _ * _), ht = H * J(c, r, u, x) + z * J(h, l, y, _);
1033
- if (ht) return rt(ht);
1034
- const st = H * H * J(c, r, g, A) + H * z * J(h, l, u, x) + z * z * J(a, f, y, _);
1035
- if (st) return rt(st);
1036
- const kt = H * J(h, l, g, A) + z * J(a, f, u, x);
1037
- return rt(kt || J(a, f, g, A));
1038
- }
1039
- let w = 1, E = h, C = l, F = a, R = f, b = y, N = _, I = u, q = x, O = g, X = A;
1040
- if (m && (E = u, C = x, F = g, R = A, b = c, N = r, I = h, q = l, O = a, X = f, w = -1), b !== 0 || N !== 0) {
1041
- const H = J(F, R, b, N);
1042
- if (H) return w * rt(H);
1043
- const z = J(E, C, I, q);
1044
- if (z) return w * rt(z);
1045
- const ht = J(F, R, I, q);
1046
- if (ht) return w * rt(ht);
1047
- const st = J(E, C, O, X);
1048
- return st ? w * rt(st) : w * rt(J(F, R, O, X));
1049
- }
1050
- const K = Math.sqrt(E * E + C * C), V = Math.sqrt(I * I + q * q), nt = Math.sqrt(K) * J(E, C, O, X) + Math.sqrt(V) * J(F, R, I, q);
1051
- return rt(nt || J(F, R, O, X));
1052
- }
1053
- function Os(i, t, n, s, o) {
1054
- let e = i[t];
1055
- if (e.type === et) {
1056
- const p = e.convertToCubic();
1057
- i[t] = p, e = p;
1058
- }
1059
- if (e.type === Gt)
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;
2166
+ }
2167
+ if (i >= 3) {
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);
2177
+ if (st) return pt(st);
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)
1060
2202
  if (n === 0) {
1061
- const p = Math.sqrt((e.p1x - e.p0x) ** 2 + (e.p1y - e.p0y) ** 2);
1062
- e.p1x += p * s, e.p1y += p * o;
2203
+ const r = Math.sqrt((o.p1x - o.p0x) ** 2 + (o.p1y - o.p0y) ** 2);
2204
+ o.p1x += r * e, o.p1y += r * i;
1063
2205
  } else {
1064
- const p = Math.sqrt((e.p2x - e.p3x) ** 2 + (e.p2y - e.p3y) ** 2);
1065
- e.p2x += p * s, e.p2y += p * o;
2206
+ const r = Math.sqrt((o.p2x - o.p3x) ** 2 + (o.p2y - o.p3y) ** 2);
2207
+ o.p2x += r * e, o.p2y += r * i;
1066
2208
  }
1067
2209
  }
1068
- const Ft = [0, 0], St = [0, 0];
1069
- function zo(i) {
1070
- for (let t = 0; t < i.contours.length; t++) {
1071
- const n = i.contours[t];
1072
- let s = 0;
1073
- for (let o = 0; o < n.length; o++) {
1074
- const e = n[o];
1075
- (e.p0x !== e.endX() || e.p0y !== e.endY()) && (n[s++] = e);
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;
2215
+ for (let i = 0; i < n.length; i++) {
2216
+ const o = n[i];
2217
+ (o.p0x !== o.endX() || o.p0y !== o.endY()) && (n[e++] = o);
1076
2218
  }
1077
- n.length = s;
2219
+ n.length = e;
1078
2220
  }
1079
- for (const t of i.contours)
2221
+ for (const t of s.contours)
1080
2222
  if (t.length === 1) {
1081
- const [n, s, o] = t[0].splitInThirds();
1082
- t.length = 0, t.push(n, s, o);
2223
+ const [n, e, i] = t[0].splitInThirds();
2224
+ t.length = 0, t.push(n, e, i);
1083
2225
  } else if (t.length > 0) {
1084
2226
  const n = t.length;
1085
- for (let s = 0; s < n; s++) {
1086
- const o = (s + n - 1) % n, e = t[o], p = t[s];
1087
- e.direction(1, Ft), p.direction(0, St);
1088
- const c = Math.sqrt(Ft[0] ** 2 + Ft[1] ** 2), r = Math.sqrt(St[0] ** 2 + St[1] ** 2);
1089
- if (c === 0 || r === 0) continue;
1090
- const h = Ft[0] / c, l = Ft[1] / c, a = St[0] / r, f = St[1] / r;
1091
- if (yo(h, l, a, f) < Ls - 1) {
1092
- const y = Ls - 1, _ = Wo * Math.sqrt(1 - y * y) / y;
1093
- let u = a - h, x = f - l;
1094
- const g = Math.sqrt(u * u + x * x);
1095
- if (g === 0) continue;
1096
- u = _ * u / g, x = _ * x / g, Vo(e, p) < 0 && (u = -u, x = -x), Os(t, o, 1, -x, u), Os(t, s, 0, x, -u);
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, -_);
2239
+ }
2240
+ }
2241
+ }
2242
+ }
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);
2246
+ }
2247
+ function Mi(s) {
2248
+ const t = s.length / 2 - 2;
2249
+ return new ot(
2250
+ t,
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
2259
+ );
2260
+ }
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]);
2269
+ }
2270
+ e[2 * r] = Bt[0], e[2 * r + 1] = Bt[1];
2271
+ }
2272
+ }
2273
+ function Tr(s, t, n) {
2274
+ return es(s, t, n, it), Array.from(it.subarray(0, s.length));
2275
+ }
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;
2279
+ let n = 0;
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);
2285
+ }
2286
+ }
2287
+ if (n !== 1) {
2288
+ Rt = -1;
2289
+ return;
2290
+ }
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;
2311
+ for (let i = 0; i < t; i += 2)
2312
+ if (i !== e && (ct[i] - An) * Zn + (ct[i + 1] - bn) * $n >= 0) return !1;
2313
+ return !0;
2314
+ }
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))
2326
+ return;
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) {
2343
+ const t = [];
2344
+ for (let n = s.length - 2; n >= 0; n -= 2) t.push(s[n], s[n + 1]);
2345
+ return t;
2346
+ }
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;
2350
+ return !0;
2351
+ }
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) {
2356
+ let i = 0;
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]);
2361
+ }
2362
+ return i !== 0;
2363
+ }
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]);
2370
+ }
2371
+ let c = !1;
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;
2418
+ });
2419
+ let g = !1;
2420
+ const x = [], b = [];
2421
+ let M = 0;
2422
+ for (const m of n) {
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;
2437
+ }
2438
+ S === E ? h[I] === 0 && (g = !0) : (x.push(B), b.push(S), h[I] !== 0 && (g = !0));
1097
2439
  }
1098
2440
  }
1099
2441
  }
2442
+ M = A;
2443
+ }
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);
2451
+ }
2452
+ if (!g) return null;
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]];
2458
+ for (; ; ) {
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;
2462
+ break;
2463
+ }
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);
2469
+ }
2470
+ if (E < 0) return null;
2471
+ T[E] = 1, w[E][0] = R, w[E][1] = S, A.push(w[E]);
2472
+ }
2473
+ D.push(A.map(Mi));
2474
+ }
2475
+ return D;
1100
2476
  }
1101
- const Jt = 1, tn = 2, Bo = 3, nn = 4, Ko = 5, Qo = 6, Kn = 7, ot = [0, 0], Dt = [0, 0];
1102
- function $o(i, t) {
1103
- return Math.trunc(3 + 2.875 * i / (t - 1) - 1.4375 + 0.5) - 3;
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;
1104
2480
  }
1105
- function Zo(i, t, n, s, o) {
1106
- return i * n + t * s <= 0 || Math.abs(i * s - t * n) > o;
2481
+ function Nr(s, t, n, e, i) {
2482
+ return s * n + t * e <= 0 || Math.abs(s * e - t * n) > i;
1107
2483
  }
1108
- function jo(i) {
1109
- const t = Number(i.v & 1n);
1110
- return i.v >>= 1n, t;
2484
+ function Hr(s) {
2485
+ const t = Number(s.v & 1n);
2486
+ return s.v >>= 1n, t;
1111
2487
  }
1112
- function Jo(i) {
1113
- const t = Number(i.v % 3n);
1114
- return i.v /= 3n, t;
2488
+ function Br(s) {
2489
+ const t = Number(s.v % 3n);
2490
+ return s.v /= 3n, t;
1115
2491
  }
1116
- function Ns(i) {
1117
- return [Qo, Ko, Bo][Jo(i)];
2492
+ function bi(s) {
2493
+ return [Or, qr, Pr][Br(s)];
1118
2494
  }
1119
- function Ot(i, t) {
1120
- const n = i.v << 1 + jo(t);
1121
- i.v = (n | n >> 3) & Kn;
2495
+ function gn(s, t) {
2496
+ const n = s.v << 1 + Hr(t);
2497
+ s.v = (n | n >> 3) & hs;
1122
2498
  }
1123
- function te(i, t, n) {
1124
- const s = i.v & n;
1125
- s === Jt || s === tn || s === nn ? i.v = s ^ Kn : Ot(i, t);
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);
1126
2502
  }
1127
- function ne(i, t, n = 0n) {
1128
- const s = Math.sin(t), o = { v: Ns({ v: n }) }, e = { v: n };
1129
- e.v = n, o.v = Ns(e);
1130
- const p = [];
1131
- for (const c of i.contours) {
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) {
1132
2508
  if (c.length === 0) continue;
1133
- p.length = 0, c[c.length - 1].direction(1, ot);
1134
- const h = Math.sqrt(ot[0] * ot[0] + ot[1] * ot[1]);
1135
- let l = h > 0 ? ot[0] / h : 0, a = h > 0 ? ot[1] / h : 0;
1136
- for (let f = 0; f < c.length; f++) {
1137
- const y = c[f];
1138
- y.direction(0, Dt);
1139
- const _ = Math.sqrt(Dt[0] * Dt[0] + Dt[1] * Dt[1]), u = _ > 0 ? Dt[0] / _ : 0, x = _ > 0 ? Dt[1] / _ : 0;
1140
- Zo(l, a, u, x, s) && p.push(f), y.direction(1, ot);
1141
- const g = Math.sqrt(ot[0] * ot[0] + ot[1] * ot[1]);
1142
- l = g > 0 ? ot[0] / g : 0, a = g > 0 ? ot[1] / g : 0;
1143
- }
1144
- if (p.length === 0) {
1145
- Ot(o, e);
1146
- for (const f of c) f.color = o.v;
1147
- } else if (p.length === 1) {
1148
- const f = [0, Kn, 0];
1149
- Ot(o, e), f[0] = o.v, Ot(o, e), f[2] = o.v;
1150
- const y = p[0], _ = c.length;
1151
- if (_ >= 3)
1152
- for (let u = 0; u < _; u++) {
1153
- const x = $o(u, _);
1154
- c[(y + u) % _].color = f[1 + x];
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];
1155
2531
  }
1156
- else if (_ >= 1) {
1157
- const u = [null, null, null, null, null, null, null], x = c[0].splitInThirds();
1158
- if (u[0 + 3 * y] = x[0], u[1 + 3 * y] = x[1], u[2 + 3 * y] = x[2], _ >= 2) {
1159
- const g = c[1].splitInThirds();
1160
- u[3 - 3 * y] = g[0], u[4 - 3 * y] = g[1], u[5 - 3 * y] = g[2], u[0].color = u[1].color = f[0], u[2].color = u[3].color = f[1], u[4].color = u[5].color = f[2];
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];
1161
2537
  } else
1162
- u[0].color = f[0], u[1].color = f[1], u[2].color = f[2];
2538
+ _[0].color = u[0], _[1].color = u[1], _[2].color = u[2];
1163
2539
  c.length = 0;
1164
- for (const g of u) g !== null && c.push(g);
2540
+ for (const x of _) x !== null && c.push(x);
1165
2541
  }
1166
2542
  } else {
1167
- const f = p.length;
1168
- let y = 0;
1169
- const _ = p[0], u = c.length;
1170
- Ot(o, e);
1171
- const x = o.v;
1172
- for (let g = 0; g < u; g++) {
1173
- const A = (_ + g) % u;
1174
- y + 1 < f && p[y + 1] === A && (++y, te(o, e, y === f - 1 ? x : 0)), c[A].color = o.v;
2543
+ const u = r.length;
2544
+ let p = 0;
2545
+ const y = r[0], _ = c.length;
2546
+ gn(i, o);
2547
+ const g = 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;
1175
2551
  }
1176
2552
  }
1177
2553
  }
1178
2554
  }
1179
- const Y = Number.MAX_VALUE, T = [0, 0], yt = [0, 0];
1180
- let Us = 0, B = new Float64Array(0), $ = new Float64Array(0), P = new Float64Array(0), G = new Float64Array(0), Z = new Int32Array(0), j = new Float64Array(0), Ct = new Float64Array(0), It = new Float64Array(0), Rt = new Float64Array(0), qt = new Int32Array(0);
1181
- const Q = [0, 0];
1182
- let Ys = 0, In = new Float64Array(0), Rn = new Float64Array(0), Tn = new Float64Array(0), kn = new Float64Array(0), Fn = new Float64Array(0), Sn = new Float64Array(0), Ln = new Float64Array(0), Pn = new Float64Array(0), Gn = new Float64Array(0), On = new Float64Array(0), Nn = new Float64Array(0), Un = new Float64Array(0), Xs = 0, Lt = new Int32Array(0);
1183
- function se(i) {
1184
- const t = i.length;
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;
1185
2561
  if (t === 0) return 0;
1186
2562
  let n = 0;
1187
2563
  if (t === 1) {
1188
- i[0].point(0, Q);
1189
- const s = Q[0], o = Q[1];
1190
- i[0].point(1 / 3, Q);
1191
- const e = Q[0], p = Q[1];
1192
- i[0].point(2 / 3, Q);
1193
- const c = Q[0], r = Q[1];
1194
- n += s * p - o * e, n += e * r - p * c, n += c * o - r * s;
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;
1195
2571
  } else if (t === 2) {
1196
- i[0].point(0, Q);
1197
- const s = Q[0], o = Q[1];
1198
- i[0].point(0.5, Q);
1199
- const e = Q[0], p = Q[1];
1200
- i[1].point(0, Q);
1201
- const c = Q[0], r = Q[1];
1202
- i[1].point(0.5, Q);
1203
- const h = Q[0], l = Q[1];
1204
- n += s * p - o * e, n += e * r - p * c, n += c * l - r * h, n += h * o - l * s;
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;
1205
2581
  } else {
1206
- const s = i[t - 1];
1207
- let o = s.p0x, e = s.p0y;
1208
- for (let p = 0; p < t; p++) {
1209
- const c = i[p].p0x, r = i[p].p0y;
1210
- n += o * r - e * c, o = c, e = r;
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;
1211
2587
  }
1212
2588
  }
1213
2589
  return n > 0 ? -1 : n < 0 ? 1 : 0;
1214
2590
  }
1215
- function oe(i, t, n, s, o, e, p) {
1216
- const c = p[i][t];
1217
- let r = n;
1218
- if (e < 0) {
1219
- c.direction(0, T);
1220
- const h = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1221
- if (h > 0) {
1222
- const l = T[0] / h, a = T[1] / h;
1223
- c.point(0, yt);
1224
- const f = s - yt[0], y = o - yt[1];
1225
- if (f * l + y * a < 0) {
1226
- const u = f * a - y * l;
1227
- Math.abs(u) <= Math.abs(r) && (r = u);
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 = _);
1228
2604
  }
1229
2605
  }
1230
2606
  }
1231
- if (e > 1) {
1232
- c.direction(1, T);
1233
- const h = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1234
- if (h > 0) {
1235
- const l = T[0] / h, a = T[1] / h;
1236
- c.point(1, yt);
1237
- const f = s - yt[0], y = o - yt[1];
1238
- if (f * l + y * a > 0) {
1239
- const u = f * a - y * l;
1240
- Math.abs(u) <= Math.abs(r) && (r = u);
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 = _);
1241
2617
  }
1242
2618
  }
1243
2619
  }
1244
- return r;
2620
+ return a;
1245
2621
  }
1246
- function lt(i, t, n, s, o, e, p, c, r) {
1247
- let h = i < 0 ? t : n;
1248
- if (o >= 0) {
1249
- const l = oe(s, o, i, p, c, e, r);
1250
- Math.abs(l) < Math.abs(h) && (h = l);
2622
+ function yt(s, t, n, e, i, o, r, c, a) {
2623
+ let l = s < 0 ? t : n;
2624
+ if (i >= 0) {
2625
+ const h = jr(e, i, s, r, c, o, a);
2626
+ Math.abs(h) < Math.abs(l) && (l = h);
1251
2627
  }
1252
- return h;
2628
+ return l;
1253
2629
  }
1254
- function gt(i, t, n) {
1255
- return Math.max(Math.min(i, t), Math.min(Math.max(i, t), n));
2630
+ function mt(s, t, n) {
2631
+ return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
1256
2632
  }
1257
- function ee(i, t, n, s, o, e, p, c) {
2633
+ function Xr(s, t, n, e, i, o, r, c) {
1258
2634
  if (c.length !== t * n * 3)
1259
2635
  throw new Error(`generateMSDF: out.length ${c.length} !== ${t * n * 3}`);
1260
- const r = i.contours, h = r.length;
1261
- if (h === 0) {
2636
+ const a = s.contours, l = a.length;
2637
+ if (l === 0) {
1262
2638
  c.fill(0);
1263
2639
  return;
1264
2640
  }
1265
- const l = s / p;
1266
- qt.length < h && (qt = new Int32Array(h));
1267
- for (let y = 0; y < h; y++) qt[y] = se(r[y]);
1268
- Xs < h + 1 && (Lt = new Int32Array(h + 1), Xs = h + 1);
1269
- let a = 0;
1270
- for (let y = 0; y < h; y++)
1271
- Lt[y] = a, a += r[y].length;
1272
- Lt[h] = a, Ys < a && (In = new Float64Array(a), Rn = new Float64Array(a), Tn = new Float64Array(a), kn = new Float64Array(a), Fn = new Float64Array(a), Sn = new Float64Array(a), Ln = new Float64Array(a), Pn = new Float64Array(a), Gn = new Float64Array(a), On = new Float64Array(a), Nn = new Float64Array(a), Un = new Float64Array(a), Ys = a);
1273
- for (let y = 0; y < h; y++) {
1274
- const _ = r[y], u = _.length, x = Lt[y];
1275
- for (let g = 0; g < u; g++) {
1276
- const A = _[g], m = _[(g + u - 1) % u], v = _[(g + 1) % u], w = x + g;
1277
- A.point(0, yt), In[w] = yt[0], Rn[w] = yt[1], A.point(1, yt), Tn[w] = yt[0], kn[w] = yt[1], A.direction(0, T);
1278
- let E = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1279
- const C = E > 0 ? T[0] / E : 0, F = E > 0 ? T[1] / E : 0;
1280
- Fn[w] = C, Sn[w] = F, A.direction(1, T), E = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1281
- const R = E > 0 ? T[0] / E : 0, b = E > 0 ? T[1] / E : 0;
1282
- Ln[w] = R, Pn[w] = b, m.direction(1, T), E = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1283
- const N = E > 0 ? T[0] / E : 0, I = E > 0 ? T[1] / E : 0;
1284
- v.direction(0, T), E = Math.sqrt(T[0] * T[0] + T[1] * T[1]);
1285
- const q = E > 0 ? T[0] / E : 0, O = E > 0 ? T[1] / E : 0, X = N + C, K = I + F, V = Math.sqrt(X * X + K * K);
1286
- Gn[w] = V > 0 ? X / V : 0, On[w] = V > 0 ? K / V : 0;
1287
- const nt = R + q, H = b + O, z = Math.sqrt(nt * nt + H * H);
1288
- Nn[w] = z > 0 ? -(nt / z) : 0, Un[w] = z > 0 ? -(H / z) : 0;
1289
- }
1290
- }
1291
- if (Us < h) {
1292
- const y = h * 3;
1293
- B = new Float64Array(y), $ = new Float64Array(y), P = new Float64Array(y), G = new Float64Array(y), Z = new Int32Array(y), j = new Float64Array(y), Ct = new Float64Array(h), It = new Float64Array(h), Rt = new Float64Array(h), Us = h;
1294
- }
1295
- const f = { distance: 0, dot: 0, param: 0 };
1296
- for (let y = 0; y < n; y++)
1297
- for (let _ = 0; _ < t; _++) {
1298
- const u = (_ + 0.5) / s - o, x = (y + 0.5) / s - e;
1299
- for (let D = 0; D < h; D++) {
1300
- const d = r[D], ct = d.length, M = D * 3, S = Lt[D];
1301
- B[M] = B[M + 1] = B[M + 2] = -Y, $[M] = $[M + 1] = $[M + 2] = 0, P[M] = P[M + 1] = P[M + 2] = -Y, G[M] = G[M + 1] = G[M + 2] = Y, Z[M] = Z[M + 1] = Z[M + 2] = -1, j[M] = j[M + 1] = j[M + 2] = 0;
1302
- for (let L = 0; L < ct; L++) {
1303
- const W = d[L], bn = W.color, wn = (bn & Jt) !== 0, An = (bn & tn) !== 0, En = (bn & nn) !== 0;
1304
- W.signedDistance(u, x, f);
1305
- const zt = f.distance, vt = f.dot, Dn = f.param, wt = Math.abs(zt);
1306
- if (wn) {
1307
- const dt = Math.abs(B[M]);
1308
- (wt < dt || wt === dt && vt < $[M]) && (B[M] = zt, $[M] = vt, Z[M] = L, j[M] = Dn);
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);
1309
2685
  }
1310
- if (An) {
1311
- const dt = Math.abs(B[M + 1]);
1312
- (wt < dt || wt === dt && vt < $[M + 1]) && (B[M + 1] = zt, $[M + 1] = vt, Z[M + 1] = L, j[M + 1] = Dn);
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);
1313
2689
  }
1314
- if (En) {
1315
- const dt = Math.abs(B[M + 2]);
1316
- (wt < dt || wt === dt && vt < $[M + 2]) && (B[M + 2] = zt, $[M + 2] = vt, Z[M + 2] = L, j[M + 2] = Dn);
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);
1317
2693
  }
1318
- const pt = S + L, qn = u - In[pt], mn = x - Rn[pt], vn = u - Tn[pt], Cn = x - kn[pt], qs = Fn[pt], ms = Sn[pt], vs = Ln[pt], Cs = Pn[pt], oo = qn * Gn[pt] + mn * On[pt], eo = vn * Nn[pt] + Cn * Un[pt];
1319
- if (oo > 0 && -(qn * qs + mn * ms) > 0) {
1320
- const k = qn * ms - mn * qs;
1321
- Math.abs(k) < wt && (wn && (k <= 0 && k > P[M] ? P[M] = k : k > 0 && k < G[M] && (G[M] = k)), An && (k <= 0 && k > P[M + 1] ? P[M + 1] = k : k > 0 && k < G[M + 1] && (G[M + 1] = k)), En && (k <= 0 && k > P[M + 2] ? P[M + 2] = k : k > 0 && k < G[M + 2] && (G[M + 2] = k)));
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)));
1322
2698
  }
1323
- if (eo > 0 && vn * vs + Cn * Cs > 0) {
1324
- const k = vn * Cs - Cn * vs;
1325
- Math.abs(k) < wt && (wn && (k <= 0 && k > P[M] ? P[M] = k : k > 0 && k < G[M] && (G[M] = k)), An && (k <= 0 && k > P[M + 1] ? P[M + 1] = k : k > 0 && k < G[M + 1] && (G[M + 1] = k)), En && (k <= 0 && k > P[M + 2] ? P[M + 2] = k : k > 0 && k < G[M + 2] && (G[M + 2] = k)));
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)));
1326
2702
  }
1327
2703
  }
1328
- Ct[D] = lt(
1329
- B[M],
1330
- P[M],
1331
- G[M],
1332
- D,
1333
- Z[M],
1334
- j[M],
1335
- u,
1336
- x,
1337
- r
1338
- ), It[D] = lt(
1339
- B[M + 1],
1340
- P[M + 1],
1341
- G[M + 1],
1342
- D,
1343
- Z[M + 1],
1344
- j[M + 1],
1345
- u,
1346
- x,
1347
- r
1348
- ), Rt[D] = lt(
1349
- B[M + 2],
1350
- P[M + 2],
1351
- G[M + 2],
1352
- D,
1353
- Z[M + 2],
1354
- j[M + 2],
1355
- u,
1356
- x,
1357
- r
2704
+ Zt[L] = yt(
2705
+ Z[U],
2706
+ N[U],
2707
+ H[U],
2708
+ L,
2709
+ Q[U],
2710
+ tt[U],
2711
+ _,
2712
+ g,
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
+ _,
2722
+ g,
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
+ _,
2732
+ g,
2733
+ a
1358
2734
  );
1359
2735
  }
1360
- let g = -Y, A = 0, m = -Y, v = Y, w = -1, E = -1, C = 0, F = -Y, R = 0, b = -Y, N = Y, I = -1, q = -1, O = 0, X = -Y, K = 0, V = -Y, nt = Y, H = -1, z = -1, ht = 0, st = -Y, kt = 0, sn = -Y, on = Y, $n = -1, Zn = -1, jn = 0, Nt = -Y, Jn = 0, en = -Y, cn = Y, ts = -1, ns = -1, ss = 0, Ut = -Y, os = 0, rn = -Y, an = Y, es = -1, is = -1, cs = 0, Yt = -Y, rs = 0, hn = -Y, pn = Y, as = -1, hs = -1, ps = 0, Xt = -Y, ls = 0, ln = -Y, fn = Y, fs = -1, ys = -1, us = 0, Wt = -Y, _s = 0, yn = -Y, un = Y, xs = -1, gs = -1, Ms = 0;
1361
- for (let D = 0; D < h; D++) {
1362
- const d = D * 3, ct = qt[D], M = gt(Ct[D], It[D], Rt[D]);
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]);
1363
2739
  {
1364
- const S = B[d], L = $[d], W = Math.abs(S);
1365
- (W < Math.abs(g) || W === Math.abs(g) && L < A) && (g = S, A = L, w = D, E = Z[d], C = j[d]), P[d] > m && (m = P[d]), G[d] < v && (v = G[d]);
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]);
1366
2742
  }
1367
2743
  {
1368
- const S = B[d + 1], L = $[d + 1], W = Math.abs(S);
1369
- (W < Math.abs(F) || W === Math.abs(F) && L < R) && (F = S, R = L, I = D, q = Z[d + 1], O = j[d + 1]), P[d + 1] > b && (b = P[d + 1]), G[d + 1] < N && (N = G[d + 1]);
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]);
1370
2746
  }
1371
2747
  {
1372
- const S = B[d + 2], L = $[d + 2], W = Math.abs(S);
1373
- (W < Math.abs(X) || W === Math.abs(X) && L < K) && (X = S, K = L, H = D, z = Z[d + 2], ht = j[d + 2]), P[d + 2] > V && (V = P[d + 2]), G[d + 2] < nt && (nt = G[d + 2]);
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]);
1374
2750
  }
1375
- if (ct > 0 && M >= 0) {
2751
+ if (ut > 0 && U >= 0) {
1376
2752
  {
1377
- const S = B[d], L = $[d], W = Math.abs(S);
1378
- (W < Math.abs(st) || W === Math.abs(st) && L < kt) && (st = S, kt = L, $n = D, Zn = Z[d], jn = j[d]), P[d] > sn && (sn = P[d]), G[d] < on && (on = G[d]);
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]);
1379
2755
  }
1380
2756
  {
1381
- const S = B[d + 1], L = $[d + 1], W = Math.abs(S);
1382
- (W < Math.abs(Nt) || W === Math.abs(Nt) && L < Jn) && (Nt = S, Jn = L, ts = D, ns = Z[d + 1], ss = j[d + 1]), P[d + 1] > en && (en = P[d + 1]), G[d + 1] < cn && (cn = G[d + 1]);
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]);
1383
2759
  }
1384
2760
  {
1385
- const S = B[d + 2], L = $[d + 2], W = Math.abs(S);
1386
- (W < Math.abs(Ut) || W === Math.abs(Ut) && L < os) && (Ut = S, os = L, es = D, is = Z[d + 2], cs = j[d + 2]), P[d + 2] > rn && (rn = P[d + 2]), G[d + 2] < an && (an = G[d + 2]);
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]);
1387
2763
  }
1388
2764
  }
1389
- if (ct < 0 && M <= 0) {
2765
+ if (ut < 0 && U <= 0) {
1390
2766
  {
1391
- const S = B[d], L = $[d], W = Math.abs(S);
1392
- (W < Math.abs(Yt) || W === Math.abs(Yt) && L < rs) && (Yt = S, rs = L, as = D, hs = Z[d], ps = j[d]), P[d] > hn && (hn = P[d]), G[d] < pn && (pn = G[d]);
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]);
1393
2769
  }
1394
2770
  {
1395
- const S = B[d + 1], L = $[d + 1], W = Math.abs(S);
1396
- (W < Math.abs(Xt) || W === Math.abs(Xt) && L < ls) && (Xt = S, ls = L, fs = D, ys = Z[d + 1], us = j[d + 1]), P[d + 1] > ln && (ln = P[d + 1]), G[d + 1] < fn && (fn = G[d + 1]);
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]);
1397
2773
  }
1398
2774
  {
1399
- const S = B[d + 2], L = $[d + 2], W = Math.abs(S);
1400
- (W < Math.abs(Wt) || W === Math.abs(Wt) && L < _s) && (Wt = S, _s = L, xs = D, gs = Z[d + 2], Ms = j[d + 2]), P[d + 2] > yn && (yn = P[d + 2]), G[d + 2] < un && (un = G[d + 2]);
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]);
1401
2777
  }
1402
2778
  }
1403
2779
  }
1404
- const _n = lt(
2780
+ const _e = yt(
2781
+ x,
2782
+ M,
2783
+ k,
2784
+ w,
2785
+ T,
2786
+ D,
2787
+ _,
1405
2788
  g,
2789
+ a
2790
+ ), ye = yt(
1406
2791
  m,
1407
- v,
1408
- w,
2792
+ d,
2793
+ R,
2794
+ S,
1409
2795
  E,
1410
- C,
1411
- u,
1412
- x,
1413
- r
1414
- ), xn = lt(
1415
- F,
1416
- b,
1417
- N,
1418
2796
  I,
1419
- q,
1420
- O,
1421
- u,
1422
- x,
1423
- r
1424
- ), gn = lt(
1425
- X,
1426
- V,
2797
+ _,
2798
+ g,
2799
+ a
2800
+ ), ge = yt(
2801
+ F,
2802
+ B,
1427
2803
  nt,
1428
- H,
1429
- z,
1430
- ht,
1431
- u,
1432
- x,
1433
- r
1434
- ), so = gt(_n, xn, gn), ds = lt(
2804
+ j,
2805
+ W,
2806
+ et,
2807
+ _,
2808
+ g,
2809
+ a
2810
+ ), Zi = mt(_e, ye, ge), Fs = yt(
1435
2811
  st,
1436
- sn,
1437
- on,
1438
- $n,
1439
- Zn,
1440
- jn,
1441
- u,
1442
- x,
1443
- r
1444
- ), bs = lt(
1445
- Nt,
1446
- en,
1447
- cn,
1448
- ts,
1449
- ns,
1450
- ss,
1451
- u,
1452
- x,
1453
- r
1454
- ), ws = lt(
1455
- Ut,
1456
- rn,
1457
- an,
1458
- es,
1459
- is,
1460
- cs,
1461
- u,
1462
- x,
1463
- r
1464
- ), Ht = gt(ds, bs, ws), As = lt(
1465
- Yt,
1466
- hn,
1467
- pn,
1468
- as,
1469
- hs,
1470
- ps,
1471
- u,
1472
- x,
1473
- r
1474
- ), Es = lt(
1475
2812
  Xt,
1476
- ln,
1477
- fn,
1478
- fs,
1479
- ys,
1480
- us,
1481
- u,
1482
- x,
1483
- r
1484
- ), Ds = lt(
1485
2813
  Wt,
1486
- yn,
1487
- un,
1488
- xs,
2814
+ us,
2815
+ ps,
2816
+ _s,
2817
+ _,
2818
+ g,
2819
+ a
2820
+ ), Ps = yt(
2821
+ kn,
2822
+ ie,
2823
+ oe,
1489
2824
  gs,
1490
- Ms,
1491
- u,
1492
- x,
1493
- r
1494
- ), Vt = gt(As, Es, Ds);
1495
- let ut, _t, xt, Mn = 0;
1496
- if (Ht >= 0 && Math.abs(Ht) <= Math.abs(Vt)) {
1497
- ut = ds, _t = bs, xt = ws, Mn = 1;
1498
- for (let D = 0; D < h; D++)
1499
- if (qt[D] > 0) {
1500
- const d = Ct[D], ct = It[D], M = Rt[D], S = gt(d, ct, M);
1501
- Math.abs(S) < Math.abs(Vt) && S > gt(ut, _t, xt) && (ut = d, _t = ct, xt = M);
2825
+ xs,
2826
+ ds,
2827
+ _,
2828
+ g,
2829
+ a
2830
+ ), qs = yt(
2831
+ Un,
2832
+ re,
2833
+ ce,
2834
+ ws,
2835
+ As,
2836
+ bs,
2837
+ _,
2838
+ g,
2839
+ a
2840
+ ), Cn = mt(Fs, Ps, qs), Os = yt(
2841
+ Tn,
2842
+ ae,
2843
+ le,
2844
+ ks,
2845
+ Us,
2846
+ Ts,
2847
+ _,
2848
+ g,
2849
+ a
2850
+ ), Gs = yt(
2851
+ vn,
2852
+ he,
2853
+ fe,
2854
+ Es,
2855
+ Cs,
2856
+ Ss,
2857
+ _,
2858
+ g,
2859
+ a
2860
+ ), Ns = yt(
2861
+ En,
2862
+ ue,
2863
+ pe,
2864
+ Ds,
2865
+ Rs,
2866
+ Ls,
2867
+ _,
2868
+ g,
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);
1502
2878
  }
1503
- } else if (Vt <= 0 && Math.abs(Vt) < Math.abs(Ht)) {
1504
- ut = As, _t = Es, xt = Ds, Mn = -1;
1505
- for (let D = 0; D < h; D++)
1506
- if (qt[D] < 0) {
1507
- const d = Ct[D], ct = It[D], M = Rt[D], S = gt(d, ct, M);
1508
- Math.abs(S) < Math.abs(Ht) && S < gt(ut, _t, xt) && (ut = d, _t = ct, xt = M);
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);
1509
2885
  }
1510
2886
  } else {
1511
- const D = (y * t + _) * 3;
1512
- c[D + 0] = _n * l + 0.5, c[D + 1] = xn * l + 0.5, c[D + 2] = gn * l + 0.5;
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;
1513
2889
  continue;
1514
2890
  }
1515
- for (let D = 0; D < h; D++)
1516
- if (qt[D] !== Mn) {
1517
- const d = Ct[D], ct = It[D], M = Rt[D], S = gt(d, ct, M), L = gt(ut, _t, xt);
1518
- S * L >= 0 && Math.abs(S) < Math.abs(L) && (ut = d, _t = ct, xt = M);
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);
1519
2895
  }
1520
- gt(ut, _t, xt) === so && (ut = _n, _t = xn, xt = gn);
1521
- const dn = (y * t + _) * 3;
1522
- c[dn + 0] = ut * l + 0.5, c[dn + 1] = _t * l + 0.5, c[dn + 2] = xt * l + 0.5;
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;
1523
2899
  }
1524
2900
  }
1525
- const js = 0, ie = 1, ce = 2, re = 3;
1526
- function ae(i, t) {
2901
+ const ji = 0, Wr = 1, zr = 2, Zr = 3;
2902
+ function $r(s, t) {
1527
2903
  switch (t) {
1528
- case js:
1529
- return i !== 0;
1530
- case ie:
1531
- return (i & 1) !== 0;
1532
- case ce:
1533
- return i > 0;
1534
- case re:
1535
- return i < 0;
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;
1536
2912
  }
1537
2913
  return !1;
1538
2914
  }
1539
- class he {
2915
+ class Jr {
1540
2916
  constructor() {
1541
2917
  this._intersections = [], this._lastIndex = 0;
1542
2918
  }
@@ -1548,10 +2924,10 @@ class he {
1548
2924
  */
1549
2925
  setIntersections(t) {
1550
2926
  if (this._intersections = t, this._lastIndex = 0, t.length > 0) {
1551
- t.sort((s, o) => rt(s.x - o.x));
2927
+ t.sort((e, i) => pt(e.x - i.x));
1552
2928
  let n = 0;
1553
- for (let s = 0; s < t.length; s++)
1554
- 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;
1555
2931
  }
1556
2932
  }
1557
2933
  /**
@@ -1563,16 +2939,16 @@ class he {
1563
2939
  _moveTo(t) {
1564
2940
  const n = this._intersections.length;
1565
2941
  if (n === 0) return -1;
1566
- let s = this._lastIndex;
1567
- if (t < this._intersections[s].x)
2942
+ let e = this._lastIndex;
2943
+ if (t < this._intersections[e].x)
1568
2944
  do {
1569
- if (s === 0)
2945
+ if (e === 0)
1570
2946
  return this._lastIndex = 0, -1;
1571
- --s;
1572
- } while (t < this._intersections[s].x);
2947
+ --e;
2948
+ } while (t < this._intersections[e].x);
1573
2949
  else
1574
- for (; s < n - 1 && t >= this._intersections[s + 1].x; ) ++s;
1575
- return this._lastIndex = s, s;
2950
+ for (; e < n - 1 && t >= this._intersections[e + 1].x; ) ++e;
2951
+ return this._lastIndex = e, e;
1576
2952
  }
1577
2953
  /**
1578
2954
  * Returns the accumulated winding number at x.
@@ -1592,323 +2968,365 @@ class he {
1592
2968
  * @returns True when filled.
1593
2969
  */
1594
2970
  filled(t, n) {
1595
- return ae(this.sumIntersections(t), n);
1596
- }
1597
- }
1598
- const Ws = [0, 0, 0], Hs = [0, 0, 0];
1599
- function pe(i, t, n) {
1600
- const s = [];
1601
- for (const o of i.contours)
1602
- for (const e of o) {
1603
- const p = e.scanlineIntersections(t, Ws, Hs);
1604
- for (let c = 0; c < p; c++)
1605
- s.push({ x: Ws[c], direction: Hs[c] });
1606
- }
1607
- n.setIntersections(s);
1608
- }
1609
- const Tt = 2, Js = 1, Yn = 1.001, le = 1.1111111111111112, jt = 0.01;
1610
- function fe(i, t, n, s, o, e, p) {
1611
- if (n === 0 || s === 0) return;
1612
- const c = new he(), r = new Int8Array(n * s);
1613
- for (let h = 0; h < s; h++) {
1614
- const l = (h + 0.5) / o - p;
1615
- pe(t, l, c);
1616
- for (let a = 0; a < n; a++) {
1617
- const f = (a + 0.5) / o - e, y = c.filled(f, js), _ = (h * n + a) * 3, u = i[_], x = i[_ + 1], g = i[_ + 2], A = tt(u, x, g), m = h * n + a;
1618
- A === 0.5 ? r[m] = 0 : A > 0.5 !== y ? (i[_] = 1 - u, i[_ + 1] = 1 - x, i[_ + 2] = 1 - g, r[m] = -1) : r[m] = 1;
1619
- }
1620
- }
1621
- for (let h = 0; h < s; h++)
1622
- for (let l = 0; l < n; l++) {
1623
- const a = h * n + l;
1624
- if (r[a] !== 0) continue;
1625
- let f = 0;
1626
- if (l > 0 && (f += r[a - 1]), l < n - 1 && (f += r[a + 1]), h > 0 && (f += r[a - n]), h < s - 1 && (f += r[a + n]), f < 0) {
1627
- const y = (h * n + l) * 3;
1628
- i[y] = 1 - i[y], i[y + 1] = 1 - i[y + 1], i[y + 2] = 1 - i[y + 2];
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];
1629
3005
  }
1630
3006
  }
1631
3007
  }
1632
- const Xn = [0, 0];
1633
- function ye(i, t, n, s, o, e, p, c) {
1634
- const r = new Uint8Array(n * s);
1635
- ue(r, t, n, s, o, e, p), _e(r, i, n, s, o, c), de(r, i, n, s, c, le), be(r, i, n, s);
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);
1636
3012
  }
1637
- function ue(i, t, n, s, o, e, p) {
3013
+ function sc(s, t, n, e, i, o, r) {
1638
3014
  for (const c of t.contours) {
1639
3015
  if (c.length === 0) continue;
1640
- let r = c[c.length - 1];
1641
- for (const h of c) {
1642
- const l = r.color & h.color;
1643
- if (!(l & l - 1)) {
1644
- h.point(0, Xn);
1645
- const a = o * (Xn[0] + e), f = o * (Xn[1] + p), y = Math.floor(a - 0.5) | 0, _ = Math.floor(f - 0.5) | 0, u = y + 1, x = _ + 1;
1646
- y < n && _ < s && u >= 0 && x >= 0 && (y >= 0 && _ >= 0 && (i[_ * n + y] |= Tt), u < n && _ >= 0 && (i[_ * n + u] |= Tt), y >= 0 && x < s && (i[x * n + y] |= Tt), u < n && x < s && (i[x * n + u] |= Tt));
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));
1647
3023
  }
1648
- r = h;
3024
+ a = l;
1649
3025
  }
1650
3026
  }
1651
3027
  }
1652
- function Kt(i, t, n) {
1653
- let s = 0;
1654
- for (let o = 0; o < 3; o++) {
1655
- const e = i[t + o], p = i[n + o], c = e - p;
3028
+ function Hn(s, t, n) {
3029
+ let e = 0;
3030
+ for (let i = 0; i < 3; i++) {
3031
+ const o = s[t + i], r = s[n + i], c = o - r;
1656
3032
  if (c === 0) continue;
1657
- const r = (e - 0.5) / c;
1658
- if (r > 0 && r < 1) {
1659
- const h = 1 - r, l = h * i[t] + r * i[n], a = h * i[t + 1] + r * i[n + 1], f = h * i[t + 2] + r * i[n + 2], y = o === 0 ? l : o === 1 ? a : f;
1660
- tt(l, a, f) === y && (s |= o === 0 ? Jt : o === 1 ? tn : nn);
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);
1661
3037
  }
1662
3038
  }
1663
- return s;
1664
- }
1665
- function At(i, t, n, s, o, e) {
1666
- (e & Jt && n[s] !== o || e & tn && n[s + 1] !== o || e & nn && n[s + 2] !== o) && (i[t] |= Tt);
3039
+ return e;
1667
3040
  }
1668
- function _e(i, t, n, s, o, e) {
1669
- const p = Yn / e, c = Yn / e, r = Yn * Math.SQRT2 / e;
1670
- for (let h = 0; h < s; h++)
1671
- for (let l = 0; l < n - 1; l++) {
1672
- const a = (h * n + l) * 3, f = a + 3, y = tt(t[a], t[a + 1], t[a + 2]), _ = tt(t[f], t[f + 1], t[f + 2]);
1673
- if (Math.abs(y - 0.5) + Math.abs(_ - 0.5) < p) {
1674
- const u = Kt(t, a, f);
1675
- At(i, h * n + l, t, a, y, u), At(i, h * n + l + 1, t, f, _, u);
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, _);
1676
3052
  }
1677
3053
  }
1678
- for (let h = 0; h < s - 1; h++)
1679
- for (let l = 0; l < n; l++) {
1680
- const a = (h * n + l) * 3, f = ((h + 1) * n + l) * 3, y = tt(t[a], t[a + 1], t[a + 2]), _ = tt(t[f], t[f + 1], t[f + 2]);
1681
- if (Math.abs(y - 0.5) + Math.abs(_ - 0.5) < c) {
1682
- const u = Kt(t, a, f);
1683
- At(i, h * n + l, t, a, y, u), At(i, (h + 1) * n + l, t, f, _, u);
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, _);
1684
3060
  }
1685
3061
  }
1686
- for (let h = 0; h < s - 1; h++)
1687
- for (let l = 0; l < n - 1; l++) {
1688
- const a = (h * n + l) * 3, f = (h * n + l + 1) * 3, y = ((h + 1) * n + l) * 3, _ = ((h + 1) * n + l + 1) * 3, u = tt(t[a], t[a + 1], t[a + 2]), x = tt(t[f], t[f + 1], t[f + 2]), g = tt(t[y], t[y + 1], t[y + 2]), A = tt(t[_], t[_ + 1], t[_ + 2]);
1689
- if (Math.abs(u - 0.5) + Math.abs(A - 0.5) < r) {
1690
- const m = Kt(t, a, _);
1691
- At(i, h * n + l, t, a, u, m), At(i, (h + 1) * n + l + 1, t, _, A, m);
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);
1692
3068
  }
1693
- if (Math.abs(x - 0.5) + Math.abs(g - 0.5) < r) {
1694
- const m = Kt(t, f, y);
1695
- At(i, h * n + l + 1, t, f, x, m), At(i, (h + 1) * n + l, t, y, g, m);
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);
1696
3072
  }
1697
3073
  }
1698
3074
  }
1699
- function xe(i, t, n) {
1700
- const s = t < i ? t : i, o = i < t ? t : i, e = n < o ? n : o;
1701
- 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;
1702
3078
  }
1703
- function ge(i, t, n, s) {
1704
- return tt(
1705
- i[t] + s * (i[n] - i[t]),
1706
- i[t + 1] + s * (i[n + 1] - i[t + 1]),
1707
- i[t + 2] + s * (i[n + 2] - i[t + 2])
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])
1708
3084
  );
1709
3085
  }
1710
- function Bn(i, t, n, s) {
1711
- return xe(
1712
- Math.fround(s * (s * n[0] + t[0]) + i[0]),
1713
- Math.fround(s * (s * n[1] + t[1]) + i[1]),
1714
- Math.fround(s * (s * n[2] + t[2]) + i[2])
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])
1715
3091
  );
1716
3092
  }
1717
- const mt = [0, 0, 0], bt = [0, 0, 0], Wn = [0, 0, 0], ft = [0, 0, 0], Vs = 1, to = 2;
1718
- function Qn(i, t, n, s, o, e, p, c) {
1719
- if (s > 0.5 && o > 0.5 && e <= 0.5 || s < 0.5 && o < 0.5 && e >= 0.5 || !c && Me(s, o, e) !== e) {
1720
- const r = (n - i) * p, h = (t - n) * p;
1721
- return e >= s - r && e <= s + r && e >= o - h && e <= o + h ? Vs : Vs | to;
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;
1722
3098
  }
1723
3099
  return 0;
1724
3100
  }
1725
- function no(i) {
1726
- return (i & to) !== 0;
3101
+ function zi(s) {
3102
+ return (s & Wi) !== 0;
1727
3103
  }
1728
- function Me(i, t, n) {
1729
- return Math.max(Math.min(i, t), Math.min(Math.max(i, t), n));
3104
+ function cc(s, t, n) {
3105
+ return Math.max(Math.min(s, t), Math.min(Math.max(s, t), n));
1730
3106
  }
1731
- function Qt(i, t, n, s, o, e) {
1732
- const p = tt(i[n], i[n + 1], i[n + 2]);
1733
- if (Math.abs(s - 0.5) < Math.abs(p - 0.5)) return !1;
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;
1734
3110
  for (let c = 0; c < 3; c++) {
1735
- const r = i[t + c] - i[t + (c + 1) % 3], h = i[n + c] - i[n + (c + 1) % 3], l = r - h;
1736
- if (l === 0) continue;
1737
- const a = r / l;
1738
- if (a > jt && a < 1 - jt) {
1739
- const f = ge(i, t, n, a), y = Qn(0, 1, a, s, p, f, o, e);
1740
- if (no(y)) return !0;
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;
1741
3117
  }
1742
3118
  }
1743
3119
  return !1;
1744
3120
  }
1745
- function zs(i, t, n, s, o, e, p, c, r) {
1746
- if (!(r > 0 && r < 1)) return 0;
1747
- const h = r > p ? 0 : r, l = r > p ? r : 1;
1748
- ft[0] = i[t], ft[1] = i[t + 1], ft[2] = i[t + 2];
1749
- const a = r > p ? n : Bn(ft, mt, bt, r);
1750
- ft[0] = i[t], ft[1] = i[t + 1], ft[2] = i[t + 2];
1751
- const f = r > p ? Bn(ft, mt, bt, r) : s;
1752
- return Qn(h, l, p, a, f, c, o, e);
1753
- }
1754
- function $t(i, t, n, s, o, e, p, c, r) {
1755
- if (!(p > jt && p < 1 - jt)) return !1;
1756
- ft[0] = i[t], ft[1] = i[t + 1], ft[2] = i[t + 2];
1757
- const h = Bn(ft, mt, bt, p);
1758
- let l = Qn(0, 1, p, n, s, h, o, e);
1759
- return l |= zs(i, t, n, s, o, e, p, h, c), l |= zs(i, t, n, s, o, e, p, h, r), no(l);
1760
- }
1761
- function Hn(i, t, n, s, o, e, p, c, r, h, l, a, f) {
1762
- const y = Math.fround(i[t + h] - i[t + l]), _ = Math.fround(
1763
- Math.fround(i[n + h] - i[n + l]) + Math.fround(i[s + h] - i[s + l])
1764
- ), u = Math.fround(i[o + h] - i[o + l]), x = Math.fround(Math.fround(u - _) + y), g = Math.fround(Math.fround(_ - y) - y), A = y;
1765
- if (x === 0 || Math.abs(g) > 1e12 * Math.abs(x)) {
1766
- if (g !== 0) {
1767
- const v = -A / g;
1768
- if ($t(i, t, e, p, c, r, v, a, f)) return !0;
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;
1769
3145
  }
1770
3146
  return !1;
1771
3147
  }
1772
- const m = g * g - 4 * x * A;
1773
- if (m > 0) {
1774
- const v = Math.sqrt(m), w = (-g + v) / (2 * x);
1775
- if ($t(i, t, e, p, c, r, w, a, f)) return !0;
1776
- const E = (-g - v) / (2 * x);
1777
- if ($t(i, t, e, p, c, r, E, a, f)) return !0;
1778
- } else if (m === 0) {
1779
- const v = -g / (2 * x);
1780
- if ($t(i, t, e, p, c, r, v, a, f)) return !0;
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;
1781
3157
  }
1782
3158
  return !1;
1783
3159
  }
1784
- function Zt(i, t, n, s, o, e, p, c) {
1785
- const r = tt(i[o], i[o + 1], i[o + 2]);
1786
- if (Math.abs(e - 0.5) < Math.abs(r - 0.5)) return !1;
1787
- for (let f = 0; f < 3; f++)
1788
- Wn[f] = Math.fround(
1789
- Math.fround(i[t + f] - i[n + f]) - i[s + f]
1790
- ), mt[f] = Math.fround(-i[t + f] - Wn[f]), bt[f] = Math.fround(i[o + f] + Wn[f]);
1791
- const h = bt[0] !== 0 ? -0.5 * mt[0] / bt[0] : -1, l = bt[1] !== 0 ? -0.5 * mt[1] / bt[1] : -1, a = bt[2] !== 0 ? -0.5 * mt[2] / bt[2] : -1;
1792
- return !!(Hn(
1793
- i,
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,
1794
3170
  t,
1795
3171
  n,
1796
- s,
1797
- o,
1798
3172
  e,
3173
+ i,
3174
+ o,
3175
+ a,
1799
3176
  r,
1800
- p,
1801
3177
  c,
1802
3178
  0,
1803
3179
  1,
1804
- h,
1805
- l
1806
- ) || Hn(
1807
- i,
3180
+ l,
3181
+ h
3182
+ ) || $e(
3183
+ s,
1808
3184
  t,
1809
3185
  n,
1810
- s,
1811
- o,
1812
3186
  e,
3187
+ i,
3188
+ o,
3189
+ a,
1813
3190
  r,
1814
- p,
1815
3191
  c,
1816
3192
  1,
1817
3193
  2,
1818
- l,
1819
- a
1820
- ) || Hn(
1821
- i,
3194
+ h,
3195
+ f
3196
+ ) || $e(
3197
+ s,
1822
3198
  t,
1823
3199
  n,
1824
- s,
1825
- o,
1826
3200
  e,
3201
+ i,
3202
+ o,
3203
+ a,
1827
3204
  r,
1828
- p,
1829
3205
  c,
1830
3206
  2,
1831
3207
  0,
1832
- a,
1833
- h
3208
+ f,
3209
+ l
1834
3210
  ));
1835
3211
  }
1836
- function de(i, t, n, s, o, e) {
1837
- const p = e / o, c = e / o, r = e * Math.SQRT2 / o;
1838
- for (let h = 0; h < s; h++)
1839
- for (let l = 0; l < n; l++) {
1840
- const a = h * n + l, f = a * 3, y = tt(t[f], t[f + 1], t[f + 2]), _ = (i[a] & Tt) !== 0, u = l > 0, x = l < n - 1, g = h > 0, A = h < s - 1, m = u ? (a - 1) * 3 : -1, v = x ? (a + 1) * 3 : -1, w = g ? (a - n) * 3 : -1, E = A ? (a + n) * 3 : -1;
1841
- let C = !1;
1842
- if (u && Qt(t, f, m, y, p, _) && (C = !0), !C && g && Qt(t, f, w, y, c, _) && (C = !0), !C && x && Qt(t, f, v, y, p, _) && (C = !0), !C && A && Qt(t, f, E, y, c, _) && (C = !0), !C && u && g) {
1843
- const F = (a - n - 1) * 3;
1844
- Zt(t, f, m, w, F, y, r, _) && (C = !0);
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);
1845
3221
  }
1846
- if (!C && x && g) {
1847
- const F = (a - n + 1) * 3;
1848
- Zt(t, f, v, w, F, y, r, _) && (C = !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);
1849
3225
  }
1850
- if (!C && u && A) {
1851
- const F = (a + n - 1) * 3;
1852
- Zt(t, f, m, E, F, y, r, _) && (C = !0);
3226
+ if (!D && _ && b) {
3227
+ const m = (f + n - 1) * 3;
3228
+ Yn(t, u, M, T, m, p, a, y) && (D = !0);
1853
3229
  }
1854
- if (!C && x && A) {
1855
- const F = (a + n + 1) * 3;
1856
- Zt(t, f, v, E, F, y, r, _) && (C = !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);
1857
3233
  }
1858
- C && (i[a] |= Js);
3234
+ D && (s[f] |= Xi);
1859
3235
  }
1860
3236
  }
1861
- function be(i, t, n, s) {
1862
- const o = n * s;
1863
- for (let e = 0; e < o; e++)
1864
- if (i[e] & Js) {
1865
- const p = e * 3, c = tt(t[p], t[p + 1], t[p + 2]);
1866
- t[p] = c, t[p + 1] = c, t[p + 2] = c;
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;
1867
3243
  }
1868
3244
  }
1869
- function tt(i, t, n) {
1870
- return Math.max(Math.min(i, t), Math.min(Math.max(i, t), n));
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,
3256
+ w: c,
3257
+ h: a,
3258
+ planeLeft: -l,
3259
+ planeBottom: -h,
3260
+ planeRight: c / o - l,
3261
+ planeTop: a / o - h
3262
+ };
3263
+ }
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);
3273
+ }
3274
+ return { minX: t, minY: n, maxX: e, maxY: i };
1871
3275
  }
1872
- function we(i) {
3276
+ function _c(s) {
1873
3277
  let t = 0, n = 0;
1874
- for (const c of i)
3278
+ for (const c of s)
1875
3279
  t += c.w * c.h, n = Math.max(n, c.w);
1876
- i.sort((c, r) => r.h - c.h);
1877
- const o = [{ x: 0, y: 0, w: Math.max(Math.ceil(Math.sqrt(t / 0.95)), n), h: 1 / 0 }];
1878
- let e = 0, p = 0;
1879
- for (const c of i)
1880
- for (let r = o.length - 1; r >= 0; r--) {
1881
- const h = o[r];
1882
- if (!(c.w > h.w || c.h > h.h)) {
1883
- if (c.x = h.x, c.y = h.y, p = Math.max(p, c.y + c.h), e = Math.max(e, c.x + c.w), c.w === h.w && c.h === h.h) {
1884
- const l = o.pop();
1885
- l && r < o.length && (o[r] = l);
1886
- } else c.h === h.h ? (h.x += c.w, h.w -= c.w) : c.w === h.w ? (h.y += c.h, h.h -= c.h) : (o.push({
1887
- x: h.x + c.w,
1888
- y: h.y,
1889
- w: h.w - c.w,
3280
+ s.sort((c, a) => a.h - c.h);
3281
+ const i = [{ x: 0, y: 0, w: Math.max(Math.ceil(Math.sqrt(t / 0.95)), n), h: 1 / 0 }];
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,
1890
3294
  h: c.h
1891
- }), h.y += c.h, h.h -= c.h);
3295
+ }), l.y += c.h, l.h -= c.h);
1892
3296
  break;
1893
3297
  }
1894
3298
  }
1895
3299
  return {
1896
- w: e,
3300
+ w: o,
1897
3301
  // container width
1898
- h: p,
3302
+ h: r,
1899
3303
  // container height
1900
- fill: t / (e * p) || 0
3304
+ fill: t / (o * r) || 0
1901
3305
  // space utilization
1902
3306
  };
1903
3307
  }
1904
- const Ae = 3, Ee = 0n, Bs = 4, Ks = 16;
1905
- function Vn(i) {
1906
- const t = i < 0 ? 0 : i > 1 ? 1 : i;
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;
1907
3321
  return ~Math.trunc(255.5 - 255 * t) & 255;
1908
3322
  }
1909
- class De {
3323
+ class gc {
3324
+ /**
3325
+ * @param font Font for the glyph/layout methods; `null` for a shapes-only atlas.
3326
+ * @param opts Generation scale and distance range.
3327
+ */
1910
3328
  constructor(t, n = {}) {
1911
- this._width = 0, this._height = 0, this._pixels = new Uint8Array(0), this._cache = /* @__PURE__ */ new Map(), this._cacheByGid = /* @__PURE__ */ new Map(), this._font = t, this._pxPerEm = n.pixelsPerEm ?? 40, this._pxrange = n.pxrange ?? 4, this.pxrangeEm = this._pxrange / this._pxPerEm;
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;
1912
3330
  }
1913
3331
  /** Packed atlas texture width in texels (chosen by potpack). */
1914
3332
  get width() {
@@ -1922,24 +3340,19 @@ class De {
1922
3340
  get texture() {
1923
3341
  return this._pixels;
1924
3342
  }
3343
+ /** {@link Atlas.texture} as raw float RGB, not clamped to [0, 1], for zoom that
3344
+ * outruns 8 bits; `null` without the `float` option. */
3345
+ get floatTexture() {
3346
+ return this._floats;
3347
+ }
1925
3348
  /**
1926
3349
  * Batched generate + pack. Generates MSDFs for any codepoints not
1927
3350
  * already cached, then runs potpack **once** over the whole cache.
1928
3351
  * Returns the `AtlasGlyph` for each requested codepoint, in order.
1929
3352
  */
1930
3353
  glyphs(t) {
1931
- const n = [];
1932
- let s = 0;
1933
- for (const o of t) {
1934
- const e = this._cache.get(o);
1935
- if (e) {
1936
- n.push(e.glyph);
1937
- continue;
1938
- }
1939
- const p = this._generateForGlyphId(this._font.glyphId(o));
1940
- this._cache.set(o, p), n.push(p.glyph), s++;
1941
- }
1942
- return s > 0 && this._repack(), n;
3354
+ const n = this._requireFont();
3355
+ return this.glyphsByIndex(Array.from(t, (e) => n.glyphId(e)));
1943
3356
  }
1944
3357
  /**
1945
3358
  * Single-glyph convenience: generates + packs if missing. Repacks the
@@ -1954,25 +3367,22 @@ class De {
1954
3367
  * Unicode codepoint — the {@link Atlas.glyphs} twin for glyphs with no
1955
3368
  * reachable cmap entry. Icon fonts (e.g. Lucide) commonly have far more
1956
3369
  * glyphs than mapped codepoints; this is how the rest of the set gets
1957
- * generated. Shares one packed atlas texture with the codepoint-addressed
1958
- * cache — {@link Atlas.texture} always reflects everything requested
1959
- * through either method. Cached separately from {@link Atlas.glyphs} (a
1960
- * codepoint and a glyph index are different numbers in the same integer
1961
- * space — sharing one cache would collide them).
3370
+ * generated. Shares one cache and one packed atlas texture with
3371
+ * {@link Atlas.glyphs}, which maps codepoints to glyph indices first.
1962
3372
  */
1963
3373
  glyphsByIndex(t) {
1964
3374
  const n = [];
1965
- let s = 0;
1966
- for (const o of t) {
1967
- const e = this._cacheByGid.get(o);
1968
- if (e) {
1969
- n.push(e.glyph);
3375
+ let e = 0;
3376
+ for (const i of t) {
3377
+ const o = this._cache.get(i);
3378
+ if (o) {
3379
+ n.push(o.glyph);
1970
3380
  continue;
1971
3381
  }
1972
- const p = this._generateForGlyphId(o);
1973
- this._cacheByGid.set(o, p), n.push(p.glyph), s++;
3382
+ const r = this._generateForGlyphId(i);
3383
+ this._cache.set(i, r), this._byGid[i] = r.glyph, n.push(r.glyph), e++;
1974
3384
  }
1975
- return s > 0 && this._repack(), n;
3385
+ return e > 0 && this._repack(), n;
1976
3386
  }
1977
3387
  /** Single-glyph convenience for {@link Atlas.glyphsByIndex} — see its
1978
3388
  * doc. For more than one glyph, prefer {@link Atlas.glyphsByIndex}
@@ -1981,59 +3391,74 @@ class De {
1981
3391
  return this.glyphsByIndex([t])[0];
1982
3392
  }
1983
3393
  /**
1984
- * Generates the MSDF for `glyphId`. Does not cache and does not pack —
1985
- * callers own the cache key (a codepoint for {@link Atlas.glyphs}, the
1986
- * glyph ID itself for {@link Atlas.glyphsByIndex}) and the repack.
3394
+ * Batched generate + pack for arbitrary shapes (e.g. from `parseSvg`),
3395
+ * keyed by a caller-chosen string — the {@link Atlas.glyphs} twin for
3396
+ * non-font input. Shapes must be y-up, in the units `pixelsPerEm` scales
3397
+ * (`parseSvg` makes 1 unit = the viewBox height). A new shape is mutated
3398
+ * (overlaps merged, normalized + coloured); a cached key ignores the shape
3399
+ * passed. `advance` is 0. Shares the one packed texture with the glyph cache.
1987
3400
  */
3401
+ shapes(t) {
3402
+ const n = [];
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);
3407
+ }
3408
+ return e > 0 && this._repack(), n;
3409
+ }
3410
+ /** The font, or a clear error for glyph/layout calls on a shapes-only atlas. */
3411
+ _requireFont() {
3412
+ if (!this._font) throw new Error("Atlas: no font — this atlas only supports shapes()");
3413
+ return this._font;
3414
+ }
3415
+ /** Generates the MSDF for `glyphId`. Does not cache and does not pack. */
1988
3416
  _generateForGlyphId(t) {
1989
- const n = this._font, s = n.metrics.unitsPerEm, o = n.advance(t) / s, e = n.shape(t);
1990
- if (Xo(e, s), e.contours.length === 0)
1991
- return { glyph: {
1992
- x: 0,
1993
- y: 0,
1994
- w: 0,
1995
- h: 0,
1996
- advance: o,
1997
- planeLeft: 0,
1998
- planeBottom: 0,
1999
- planeRight: 0,
2000
- planeTop: 0
2001
- }, msdf: null };
2002
- const p = qe(e), c = this._pxPerEm, r = this._pxrange, h = Math.max(1, Math.ceil((p.maxX - p.minX) * c)) + 2 * r, l = Math.max(1, Math.ceil((p.maxY - p.minY) * c)) + 2 * r, a = r / c - p.minX, f = r / c - p.minY;
2003
- zo(e), ne(e, Ae, Ee);
2004
- const y = new Float32Array(h * l * 3);
2005
- return ee(e, h, l, c, a, f, r, y), fe(y, e, h, l, c, a, f), ye(y, e, h, l, c, a, f, r), { glyph: {
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);
3419
+ }
3420
+ /** Generates one entry from an em-unit shape. Does not cache or pack. */
3421
+ _generate(t, n) {
3422
+ const e = uc(t, this._pxPerEm, this._pxrange);
3423
+ return { glyph: {
2006
3424
  x: 0,
2007
3425
  y: 0,
2008
- w: h,
2009
- h: l,
2010
- advance: o,
2011
- planeLeft: -a,
2012
- planeBottom: -f,
2013
- planeRight: h / c - a,
2014
- planeTop: l / c - f
2015
- }, msdf: y };
3426
+ w: e ? e.w : 0,
3427
+ h: e ? e.h : 0,
3428
+ advance: n,
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 };
2016
3434
  }
2017
3435
  /**
2018
- * 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).
2019
3438
  * Generates any missing glyphs and packs the atlas **once** for the
2020
- * whole run. Baseline is y=0 (`penY` on every result is 0); each `penX`
2021
- * 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
2022
3442
  * {@link Atlas.layoutMultiline} for multi-line input.
2023
3443
  */
2024
3444
  layout(t) {
2025
- const n = [];
2026
- for (const r of t) n.push(r.codePointAt(0));
2027
- this.glyphs(n);
2028
- const s = [], o = this._font, e = o.metrics.unitsPerEm;
2029
- let p = 0, c = -1;
2030
- for (const r of n) {
2031
- const h = o.glyphId(r);
2032
- c >= 0 && (p += o.kerning(c, h) / e);
2033
- const l = this._cache.get(r).glyph;
2034
- s.push({ glyph: l, penX: p, penY: 0 }), p += l.advance, c = h;
2035
- }
2036
- return { glyphs: s, widthEm: p };
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 };
2037
3462
  }
2038
3463
  /**
2039
3464
  * Lays out `text` as one or more `\n`-separated lines, each run through
@@ -2051,92 +3476,87 @@ class De {
2051
3476
  * cropping.
2052
3477
  */
2053
3478
  layoutMultiline(t) {
2054
- const n = this._font, s = n.metrics.unitsPerEm, o = (n.metrics.ascender - n.metrics.descender + n.metrics.lineGap) / s, e = t.split(`
2055
- `), p = [];
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 = [];
2056
3481
  let c = 0;
2057
- for (let r = 0; r < e.length; r++) {
2058
- const { glyphs: h, widthEm: l } = this.layout(e[r]), a = -r * o;
2059
- for (const f of h) p.push({ glyph: f.glyph, penX: f.penX, penY: a });
2060
- l > c && (c = l);
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);
2061
3487
  }
2062
- return { glyphs: p, widthEm: c, heightEm: e.length * o };
3488
+ return { glyphs: r, widthEm: c, heightEm: o.length * i };
2063
3489
  }
2064
- /** Repacks every cached glyph (both the codepoint- and glyph-index-keyed
2065
- * caches — one shared texture) with potpack, reallocates the texture,
2066
- * and re-blits each MSDF at its assigned rect. Called by `glyphs()`/
2067
- * `glyphsByIndex()` after any batch of new inserts — once per batch. */
3490
+ /** Repacks every cached entry (glyph-index- and string-keyed caches — one
3491
+ * shared texture) with potpack, reallocates the texture, and re-blits each
3492
+ * MSDF at its assigned rect. Called by `glyphsByIndex()`/`shapes()` after
3493
+ * any batch of new inserts — once per batch.
3494
+ *
3495
+ * Each cell gets a 1-texel gutter of zeros on its right and bottom, so a
3496
+ * quad covering the whole cell can sample its full rect: linear filtering
3497
+ * at the edge blends with zeros (further outside the glyph), never with a
3498
+ * neighbouring glyph's texels. */
2068
3499
  _repack() {
2069
3500
  const t = [];
2070
- for (const o of this._cache.values())
2071
- o.msdf !== null && t.push({ w: o.glyph.w, h: o.glyph.h, x: 0, y: 0, entry: o });
2072
- for (const o of this._cacheByGid.values())
2073
- o.msdf !== null && t.push({ w: o.glyph.w, h: o.glyph.h, x: 0, y: 0, entry: o });
2074
- const { w: n, h: s } = we(t);
2075
- this._width = n, this._height = s, this._pixels = new Uint8Array(n * s * Bs);
2076
- for (const o of t)
2077
- o.entry.glyph.x = o.x, o.entry.glyph.y = o.y, this._blit(o.entry.msdf, o.x, o.y, o.w, o.h);
3501
+ for (const i of [this._cache, this._cacheByKey])
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));
3506
+ for (const i of t)
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);
2078
3508
  }
2079
3509
  /**
2080
3510
  * Quantise `msdf` (float, y-up, row 0 = bottom, w×h×3) into `_pixels` at
2081
3511
  * atlas rect (`ax`, `ay`, `w`, `h`) — the single y-flip point.
2082
3512
  */
2083
- _blit(t, n, s, o, e) {
2084
- const p = this._width, c = this._pixels;
2085
- for (let r = 0; r < e; r++) {
2086
- const h = s + (e - 1 - r);
2087
- for (let l = 0; l < o; l++) {
2088
- const a = (r * o + l) * 3, f = (h * p + (n + l)) * Bs;
2089
- c[f] = Vn(t[a]), c[f + 1] = Vn(t[a + 1]), c[f + 2] = Vn(t[a + 2]), c[f + 3] = 255;
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;
2090
3522
  }
2091
3523
  }
2092
3524
  }
2093
3525
  }
2094
- const zn = [0, 0];
2095
- function qe(i) {
2096
- let t = 1 / 0, n = 1 / 0, s = -1 / 0, o = -1 / 0;
2097
- for (const e of i.contours)
2098
- for (const p of e)
2099
- for (let c = 0; c <= Ks; c++) {
2100
- p.point(c / Ks, zn);
2101
- const r = zn[0], h = zn[1];
2102
- r < t && (t = r), h < n && (n = h), r > s && (s = r), h > o && (o = h);
2103
- }
2104
- return { minX: t, minY: n, maxX: s, maxY: o };
2105
- }
2106
- const Qs = /* @__PURE__ */ new Map();
2107
- self.onmessage = (i) => {
2108
- const t = i.data;
3526
+ const Di = /* @__PURE__ */ new Map();
3527
+ self.onmessage = (s) => {
3528
+ const t = s.data;
2109
3529
  if (t.type === "build")
2110
3530
  try {
2111
- let n = Qs.get(t.fontKey);
3531
+ let n = Di.get(t.fontKey);
2112
3532
  if (!n) {
2113
3533
  if (!t.font)
2114
3534
  throw new Error(
2115
3535
  `atlas-worker: no cached font for fontKey "${t.fontKey}" and no \`font\` bytes provided on this request`
2116
3536
  );
2117
- n = new Yo(t.font), Qs.set(t.fontKey, n);
3537
+ n = new xr(t.font), Di.set(t.fontKey, n);
2118
3538
  }
2119
- const s = performance.now(), o = new De(n, { pixelsPerEm: t.pixelsPerEm, pxrange: t.pxrange }), { glyphs: e, widthEm: p, heightEm: c } = o.layoutMultiline(t.text), r = performance.now() - s, h = e.map(({ glyph: f, penX: y, penY: _ }) => ({
2120
- ...f,
2121
- penX: y,
2122
- penY: _
2123
- })), l = o.texture.slice().buffer, a = {
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 = {
2124
3544
  type: "built",
2125
3545
  id: t.id,
2126
3546
  pixelsPerEm: t.pixelsPerEm,
2127
3547
  pxrange: t.pxrange,
2128
- pxrangeEm: o.pxrangeEm,
2129
- width: o.width,
2130
- height: o.height,
2131
- texture: l,
2132
- glyphs: h,
2133
- widthEm: p,
3548
+ pxrangeEm: i.pxrangeEm,
3549
+ width: i.width,
3550
+ height: i.height,
3551
+ texture: h,
3552
+ glyphs: l,
3553
+ widthEm: r,
2134
3554
  heightEm: c,
2135
- genMs: r
3555
+ genMs: a
2136
3556
  };
2137
- self.postMessage(a, [l]);
3557
+ self.postMessage(f, [h]);
2138
3558
  } catch (n) {
2139
- const s = { type: "error", id: t.id, message: String(n) };
2140
- self.postMessage(s);
3559
+ const e = { type: "error", id: t.id, message: String(n) };
3560
+ self.postMessage(e);
2141
3561
  }
2142
3562
  };