@unmade/text-renderer 1.0.0 → 1.1.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.
@@ -3,206 +3,256 @@ import { svgPathProperties as Pt } from "svg-path-properties";
3
3
  import { DOMParser as Tt } from "linkedom";
4
4
  import "node:path";
5
5
  import Lt from "@thednp/dommatrix";
6
- function Ut(e) {
7
- let t = 1 / 0, n = 1 / 0, o = -1 / 0, a = -1 / 0;
8
- const c = /([MLCQTSAZHVmlcqtsazhv])([^MLCQTSAZHVmlcqtsazhv]*)/g;
9
- let f = c.exec(e);
10
- for (; f !== null; ) {
11
- const s = f[1].toUpperCase();
12
- if (s !== "Z") {
13
- const r = f[2].trim().split(/[\s,]+/).filter(Boolean).map(Number);
14
- if (s === "H")
15
- for (const i of r)
16
- t = Math.min(t, i), o = Math.max(o, i);
17
- else if (s === "V")
18
- for (const i of r)
19
- n = Math.min(n, i), a = Math.max(a, i);
20
- else
21
- for (let i = 0; i + 1 < r.length; i += 2)
22
- t = Math.min(t, r[i]), o = Math.max(o, r[i]), n = Math.min(n, r[i + 1]), a = Math.max(a, r[i + 1]);
6
+ function Ct(e) {
7
+ let t = 1 / 0, n = 1 / 0, o = -1 / 0, l = -1 / 0, r = 0, a = 0;
8
+ function s(f, d) {
9
+ f < t && (t = f), f > o && (o = f), d < n && (n = d), d > l && (l = d);
10
+ }
11
+ function c(f, d, g) {
12
+ const w = f - 2 * d + g;
13
+ if (Math.abs(w) < 1e-10) return [];
14
+ const m = (f - d) / w;
15
+ return m > 0 && m < 1 ? [m] : [];
16
+ }
17
+ function h(f, d, g, w) {
18
+ const m = 1 - f;
19
+ return m * m * d + 2 * m * f * g + f * f * w;
20
+ }
21
+ function i(f, d, g, w) {
22
+ const m = d - f, y = g - d, $ = w - g, v = m - 2 * y + $, M = 2 * (y - m), S = m;
23
+ if (Math.abs(v) < 1e-10) {
24
+ if (Math.abs(M) < 1e-10) return [];
25
+ const x = -S / M;
26
+ return x > 0 && x < 1 ? [x] : [];
27
+ }
28
+ const A = M * M - 4 * v * S;
29
+ if (A < 0) return [];
30
+ const k = Math.sqrt(A);
31
+ return [(-M + k) / (2 * v), (-M - k) / (2 * v)].filter((x) => x > 0 && x < 1);
32
+ }
33
+ function b(f, d, g, w, m) {
34
+ const y = 1 - f;
35
+ return y * y * y * d + 3 * y * y * f * g + 3 * y * f * f * w + f * f * f * m;
36
+ }
37
+ const p = /([MLCQTSAZHVmlcqtsazhv])([^MLCQTSAZHVmlcqtsazhv]*)/g;
38
+ let u = p.exec(e);
39
+ for (; u !== null; ) {
40
+ const f = u[1].toUpperCase();
41
+ if (f === "Z") {
42
+ u = p.exec(e);
43
+ continue;
23
44
  }
24
- f = c.exec(e);
45
+ const d = u[2].trim().split(/[\s,]+/).filter(Boolean).map(Number);
46
+ if (f === "M" || f === "L" || f === "T")
47
+ for (let g = 0; g + 1 < d.length; g += 2)
48
+ r = d[g], a = d[g + 1], s(r, a);
49
+ else if (f === "H")
50
+ for (const g of d)
51
+ r = g, s(r, a);
52
+ else if (f === "V")
53
+ for (const g of d)
54
+ a = g, s(r, a);
55
+ else if (f === "Q")
56
+ for (let g = 0; g + 3 < d.length; g += 4) {
57
+ const [w, m, y, $] = d.slice(g, g + 4);
58
+ s(y, $);
59
+ for (const v of c(r, w, y)) s(h(v, r, w, y), h(v, a, m, $));
60
+ for (const v of c(a, m, $)) s(h(v, r, w, y), h(v, a, m, $));
61
+ r = y, a = $;
62
+ }
63
+ else if (f === "C")
64
+ for (let g = 0; g + 5 < d.length; g += 6) {
65
+ const [w, m, y, $, v, M] = d.slice(g, g + 6);
66
+ s(v, M);
67
+ for (const S of i(r, w, y, v)) s(b(S, r, w, y, v), b(S, a, m, $, M));
68
+ for (const S of i(a, m, $, M)) s(b(S, r, w, y, v), b(S, a, m, $, M));
69
+ r = v, a = M;
70
+ }
71
+ else
72
+ for (let g = 0; g + 1 < d.length; g += 2)
73
+ s(d[g], d[g + 1]);
74
+ u = p.exec(e);
25
75
  }
26
- return Number.isFinite(t) ? { x1: t, y1: n, x2: o, y2: a } : null;
76
+ return Number.isFinite(t) ? { x1: t, y1: n, x2: o, y2: l } : null;
27
77
  }
28
78
  function Et(e, t, n, o) {
29
79
  return e.replace(
30
80
  /([MLCQTSAZHVmlcqtsazhv])([^MLCQTSAZHVmlcqtsazhv]*)/g,
31
- (a, c, f) => {
32
- const s = c.toUpperCase();
33
- if (s === "Z") return c;
34
- const r = f.trim().split(/[\s,]+/).filter(Boolean).map(Number), i = [];
81
+ (l, r, a) => {
82
+ const s = r.toUpperCase();
83
+ if (s === "Z") return r;
84
+ const c = a.trim().split(/[\s,]+/).filter(Boolean).map(Number), h = [];
35
85
  if (s === "M" || s === "L" || s === "T")
36
- for (let l = 0; l < r.length; l += 2)
37
- i.push(r[l] * t + o, -r[l + 1] * n);
86
+ for (let i = 0; i < c.length; i += 2)
87
+ h.push(c[i] * t + o, -c[i + 1] * n);
38
88
  else if (s === "C")
39
- for (let l = 0; l < r.length; l += 6)
40
- i.push(
41
- r[l] * t + o,
42
- -r[l + 1] * n,
43
- r[l + 2] * t + o,
44
- -r[l + 3] * n,
45
- r[l + 4] * t + o,
46
- -r[l + 5] * n
89
+ for (let i = 0; i < c.length; i += 6)
90
+ h.push(
91
+ c[i] * t + o,
92
+ -c[i + 1] * n,
93
+ c[i + 2] * t + o,
94
+ -c[i + 3] * n,
95
+ c[i + 4] * t + o,
96
+ -c[i + 5] * n
47
97
  );
48
98
  else if (s === "Q" || s === "S")
49
- for (let l = 0; l < r.length; l += 4)
50
- i.push(
51
- r[l] * t + o,
52
- -r[l + 1] * n,
53
- r[l + 2] * t + o,
54
- -r[l + 3] * n
99
+ for (let i = 0; i < c.length; i += 4)
100
+ h.push(
101
+ c[i] * t + o,
102
+ -c[i + 1] * n,
103
+ c[i + 2] * t + o,
104
+ -c[i + 3] * n
55
105
  );
56
106
  else if (s === "H")
57
- for (let l = 0; l < r.length; l++)
58
- i.push(r[l] * t + o);
107
+ for (let i = 0; i < c.length; i++)
108
+ h.push(c[i] * t + o);
59
109
  else if (s === "V")
60
- for (let l = 0; l < r.length; l++)
61
- i.push(-r[l] * n);
110
+ for (let i = 0; i < c.length; i++)
111
+ h.push(-c[i] * n);
62
112
  else
63
- return c + f;
64
- return c + i.join(",");
113
+ return r + a;
114
+ return r + h.join(",");
65
115
  }
66
116
  );
67
117
  }
68
- function Ct(e, t, n, o) {
69
- const a = e.upem;
70
- function c(l) {
71
- const p = l.codePointAt(0), u = t.glyph(p) ?? 0, h = t.glyphExtents(u);
118
+ function Ut(e, t, n, o) {
119
+ const l = e.upem;
120
+ function r(i) {
121
+ const b = i.codePointAt(0) ?? 0, p = t.glyph(b) ?? 0, u = t.glyphExtents(p);
72
122
  return {
73
- index: u,
74
- advanceWidth: t.glyphHAdvance(u),
75
- name: t.glyphName(u),
123
+ index: p,
124
+ advanceWidth: t.glyphHAdvance(p),
125
+ name: t.glyphName(p),
76
126
  getBoundingBox() {
77
- return h ? {
78
- x1: h.xBearing,
79
- y1: -h.yBearing,
80
- x2: h.xBearing + h.width,
127
+ return u ? {
128
+ x1: u.xBearing,
129
+ y1: -u.yBearing,
130
+ x2: u.xBearing + u.width,
81
131
  // height is negative in HarfBuzz (extends downward), so subtracting gives y2 >= y1
82
- y2: -(h.yBearing + h.height)
132
+ y2: -(u.yBearing + u.height)
83
133
  } : { x1: 0, y1: 0, x2: 0, y2: 0 };
84
134
  }
85
135
  };
86
136
  }
87
- const f = [new nt("liga", 0), new nt("calt", 0)];
88
- function s(l, p, u, h) {
89
- const d = h / a, g = new At();
90
- g.addText(l), g.guessSegmentProperties(), Bt(t, g, f);
91
- const m = g.getGlyphInfos(), $ = g.getGlyphPositions();
92
- let w = 0;
93
- return m.map((b, k) => {
94
- const A = $[k], E = b.codepoint, S = w + A.xOffset, U = t.glyphToPath(E), v = Et(U, d, d, S * d);
95
- return w += A.xAdvance, {
137
+ const a = [new nt("liga", 0), new nt("calt", 0)];
138
+ function s(i, b, p, u) {
139
+ const f = u / l, d = new At();
140
+ d.addText(i), d.guessSegmentProperties(), Bt(t, d, a);
141
+ const g = d.getGlyphInfos(), w = d.getGlyphPositions();
142
+ let m = 0;
143
+ return g.map((y, $) => {
144
+ const v = w[$], M = y.codepoint, S = m + v.xOffset, A = t.glyphToPath(M), k = Et(A, f, f, S * f);
145
+ return m += v.xAdvance, {
96
146
  getBoundingBox() {
97
- const y = Ut(v);
98
- return y || { x1: S * d, y1: 0, x2: S * d, y2: 0 };
147
+ const x = Ct(k);
148
+ return x || { x1: S * f, y1: 0, x2: S * f, y2: 0 };
99
149
  },
100
- toPathData(y) {
101
- return v;
150
+ toPathData(x) {
151
+ return k;
102
152
  }
103
153
  };
104
154
  });
105
155
  }
106
- function r(l, p, u, h) {
107
- const d = s(l, p, u, h);
156
+ function c(i, b, p, u) {
157
+ const f = s(i, b, p, u);
108
158
  return {
109
159
  getBoundingBox() {
110
- if (d.length === 0)
160
+ if (f.length === 0)
111
161
  return { x1: 0, y1: 0, x2: 0, y2: 0 };
112
- const g = d.map((m) => m.getBoundingBox());
162
+ const d = f.map((g) => g.getBoundingBox());
113
163
  return {
114
- x1: Math.min(...g.map((m) => m.x1)),
115
- y1: Math.min(...g.map((m) => m.y1)),
116
- x2: Math.max(...g.map((m) => m.x2)),
117
- y2: Math.max(...g.map((m) => m.y2))
164
+ x1: Math.min(...d.map((g) => g.x1)),
165
+ y1: Math.min(...d.map((g) => g.y1)),
166
+ x2: Math.max(...d.map((g) => g.x2)),
167
+ y2: Math.max(...d.map((g) => g.y2))
118
168
  };
119
169
  },
120
- toPathData(g) {
121
- return d.map((m) => m.toPathData()).join("");
170
+ toPathData(d) {
171
+ return f.map((g) => g.toPathData()).join("");
122
172
  }
123
173
  };
124
174
  }
125
175
  return {
126
- unitsPerEm: a,
176
+ unitsPerEm: l,
127
177
  names: { fontFamily: n },
128
178
  svgGlyphs: o,
129
- charToGlyph: c,
130
- getPath: r,
179
+ charToGlyph: r,
180
+ getPath: c,
131
181
  getPaths: s
132
182
  };
133
183
  }
134
184
  const X = /* @__PURE__ */ new Map(), ve = () => X;
135
185
  async function ut(e, t) {
136
- const n = new DecompressionStream(t), o = n.writable.getWriter(), a = n.readable.getReader();
186
+ const n = new DecompressionStream(t), o = n.writable.getWriter(), l = n.readable.getReader();
137
187
  o.write(new Uint8Array(e)), o.close();
138
- const c = [];
188
+ const r = [];
139
189
  for (; ; ) {
140
- const { done: i, value: l } = await a.read();
141
- if (i) break;
142
- c.push(l);
190
+ const { done: h, value: i } = await l.read();
191
+ if (h) break;
192
+ r.push(i);
143
193
  }
144
- const f = c.reduce((i, l) => i + l.length, 0), s = new Uint8Array(f);
145
- let r = 0;
146
- for (const i of c)
147
- s.set(i, r), r += i.length;
194
+ const a = r.reduce((h, i) => h + i.length, 0), s = new Uint8Array(a);
195
+ let c = 0;
196
+ for (const h of r)
197
+ s.set(h, c), c += h.length;
148
198
  return s;
149
199
  }
150
200
  async function It(e) {
151
201
  return ut(e, "gzip");
152
202
  }
153
203
  async function Wt(e) {
154
- const t = new DataView(e), n = t.getUint32(4), o = t.getUint16(12), a = [];
155
- for (let h = 0; h < o; h++) {
156
- const d = 44 + h * 20, g = String.fromCharCode(
157
- t.getUint8(d),
158
- t.getUint8(d + 1),
159
- t.getUint8(d + 2),
160
- t.getUint8(d + 3)
204
+ const t = new DataView(e), n = t.getUint32(4), o = t.getUint16(12), l = [];
205
+ for (let u = 0; u < o; u++) {
206
+ const f = 44 + u * 20, d = String.fromCharCode(
207
+ t.getUint8(f),
208
+ t.getUint8(f + 1),
209
+ t.getUint8(f + 2),
210
+ t.getUint8(f + 3)
161
211
  );
162
- a.push({
163
- tag: g,
164
- offset: t.getUint32(d + 4),
165
- compLength: t.getUint32(d + 8),
166
- origLength: t.getUint32(d + 12),
167
- checksum: t.getUint32(d + 16)
212
+ l.push({
213
+ tag: d,
214
+ offset: t.getUint32(f + 4),
215
+ compLength: t.getUint32(f + 8),
216
+ origLength: t.getUint32(f + 12),
217
+ checksum: t.getUint32(f + 16)
168
218
  });
169
219
  }
170
- const c = [];
171
- for (const h of a) {
172
- const d = new Uint8Array(e, h.offset, h.compLength);
173
- h.compLength === h.origLength ? c.push(new Uint8Array(d)) : c.push(await ut(d, "deflate"));
220
+ const r = [];
221
+ for (const u of l) {
222
+ const f = new Uint8Array(e, u.offset, u.compLength);
223
+ u.compLength === u.origLength ? r.push(new Uint8Array(f)) : r.push(await ut(f, "deflate"));
174
224
  }
175
- const f = 2 ** Math.floor(Math.log2(o)) * 16, s = Math.floor(Math.log2(o)), r = o * 16 - f;
176
- let i = 12 + o * 16;
177
- const l = [];
178
- for (let h = 0; h < a.length; h++)
179
- l.push(i), i += a[h].origLength + 3 & -4;
180
- const p = new Uint8Array(i), u = new DataView(p.buffer);
181
- u.setUint32(0, n), u.setUint16(4, o), u.setUint16(6, f), u.setUint16(8, s), u.setUint16(10, r);
182
- for (let h = 0; h < a.length; h++) {
183
- const d = a[h], g = 12 + h * 16;
184
- for (let m = 0; m < 4; m++) p[g + m] = d.tag.charCodeAt(m);
185
- u.setUint32(g + 4, d.checksum), u.setUint32(g + 8, l[h]), u.setUint32(g + 12, d.origLength), p.set(c[h], l[h]);
225
+ const a = 2 ** Math.floor(Math.log2(o)) * 16, s = Math.floor(Math.log2(o)), c = o * 16 - a;
226
+ let h = 12 + o * 16;
227
+ const i = [];
228
+ for (let u = 0; u < l.length; u++)
229
+ i.push(h), h += l[u].origLength + 3 & -4;
230
+ const b = new Uint8Array(h), p = new DataView(b.buffer);
231
+ p.setUint32(0, n), p.setUint16(4, o), p.setUint16(6, a), p.setUint16(8, s), p.setUint16(10, c);
232
+ for (let u = 0; u < l.length; u++) {
233
+ const f = l[u], d = 12 + u * 16;
234
+ for (let g = 0; g < 4; g++) b[d + g] = f.tag.charCodeAt(g);
235
+ p.setUint32(d + 4, f.checksum), p.setUint32(d + 8, i[u]), p.setUint32(d + 12, f.origLength), b.set(r[u], i[u]);
186
236
  }
187
- return p.buffer;
237
+ return b.buffer;
188
238
  }
189
239
  async function at(e, t, n) {
190
- const o = /* @__PURE__ */ new Map(), a = new DataView(e.buffer, e.byteOffset, e.byteLength), c = a.getUint32(2), f = a.getUint16(c), s = c;
191
- for (let r = 0; r < f; r++) {
192
- const i = c + 2 + r * 12, l = a.getUint16(i), p = a.getUint16(i + 2), u = a.getUint32(i + 4), h = a.getUint32(i + 8), d = s + u;
193
- let g = e.slice(d, d + h);
194
- g[0] === 31 && g[1] === 139 && (g = await It(g));
195
- const m = new TextDecoder().decode(g);
196
- for (let $ = l; $ <= p; $++) {
197
- const w = t.glyphExtents($);
198
- let b;
199
- w ? b = `${w.xBearing} ${-w.yBearing} ${w.width} ${-w.height}` : b = "0 0 0 0", o.set($, { svg: m, viewbox: b });
240
+ const o = /* @__PURE__ */ new Map(), l = new DataView(e.buffer, e.byteOffset, e.byteLength), r = l.getUint32(2), a = l.getUint16(r), s = r;
241
+ for (let c = 0; c < a; c++) {
242
+ const h = r + 2 + c * 12, i = l.getUint16(h), b = l.getUint16(h + 2), p = l.getUint32(h + 4), u = l.getUint32(h + 8), f = s + p;
243
+ let d = e.slice(f, f + u);
244
+ d[0] === 31 && d[1] === 139 && (d = await It(d));
245
+ const g = new TextDecoder().decode(d);
246
+ for (let w = i; w <= b; w++) {
247
+ const m = t.glyphExtents(w);
248
+ let y;
249
+ m ? y = `${m.xBearing} ${-m.yBearing} ${m.width} ${-m.height}` : y = "0 0 0 0", o.set(w, { svg: g, viewbox: y });
200
250
  }
201
251
  }
202
252
  return o;
203
253
  }
204
254
  const Gt = 2001684038;
205
- async function Dt(e) {
255
+ async function Ot(e) {
206
256
  return e.byteLength >= 4 && new DataView(e).getUint32(0) === Gt ? Wt(e) : e;
207
257
  }
208
258
  async function it(e) {
@@ -212,31 +262,31 @@ async function it(e) {
212
262
  `Failed to load font from ${e}: ${t.status} ${t.statusText}`
213
263
  );
214
264
  const n = await t.arrayBuffer();
215
- return Dt(n);
265
+ return Ot(n);
216
266
  }
217
- const Ot = async (e, t = !1) => {
267
+ const Dt = async (e, t = !1) => {
218
268
  const n = X.get(e);
219
269
  if (n) {
220
270
  if (t && !n.svgGlyphs) {
221
- const l = await it(e), p = new ot(l), u = new rt(p), h = new st(u), d = u.referenceTable("SVG "), g = d ? await at(d, h, u.upem) : /* @__PURE__ */ new Map();
222
- n.svgGlyphs = g;
271
+ const i = await it(e), b = new ot(i), p = new rt(b), u = new st(p), f = p.referenceTable("SVG "), d = f ? await at(f, u, p.upem) : /* @__PURE__ */ new Map();
272
+ n.svgGlyphs = d;
223
273
  }
224
274
  return n;
225
275
  }
226
- const o = await it(e), a = new ot(o), c = new rt(a), f = new st(c), s = c.getName(1, "en") ?? "";
227
- let r;
276
+ const o = await it(e), l = new ot(o), r = new rt(l), a = new st(r), s = r.getName(1, "en") ?? "";
277
+ let c;
228
278
  if (t) {
229
- const l = c.referenceTable("SVG ");
230
- r = l ? await at(l, f, c.upem) : /* @__PURE__ */ new Map();
279
+ const i = r.referenceTable("SVG ");
280
+ c = i ? await at(i, a, r.upem) : /* @__PURE__ */ new Map();
231
281
  }
232
- const i = Ct(c, f, s, r);
233
- return X.set(e, i), i;
234
- }, Nt = 0.03125, pt = 1.1, _t = 0.2, G = {
235
- outlineWidth: Nt,
282
+ const h = Ut(r, a, s, c);
283
+ return X.set(e, h), h;
284
+ }, qt = 0.03125, pt = 1.1, Nt = 0.2, G = {
285
+ outlineWidth: qt,
236
286
  letterSpacing: 0,
237
287
  letterSpacingOutline: 0
238
288
  };
239
- class F {
289
+ class P {
240
290
  constructor(t, n) {
241
291
  this.x = t, this.y = n;
242
292
  }
@@ -250,11 +300,11 @@ class F {
250
300
  return `${this.x} ${this.y}`;
251
301
  }
252
302
  }
253
- function Vt(e, t, n = new F(0, 0)) {
254
- const o = e.X - n.X, a = e.Y - n.Y, c = t / 180 * Math.PI, f = Math.cos(c), s = Math.sin(c), r = o * f - a * s, i = o * s + a * f;
255
- return new F(r + n.X, i + n.Y);
303
+ function _t(e, t, n = new P(0, 0)) {
304
+ const o = e.X - n.X, l = e.Y - n.Y, r = t / 180 * Math.PI, a = Math.cos(r), s = Math.sin(r), c = o * a - l * s, h = o * s + l * a;
305
+ return new P(c + n.X, h + n.Y);
256
306
  }
257
- const qt = (e) => e === void 0 || e === "flat" ? { type: "flat" } : e === "curved" ? { type: "curved" } : e, Ht = (e) => {
307
+ const Vt = (e) => e === void 0 || e === "flat" ? { type: "flat" } : e === "curved" ? { type: "curved" } : e, Ht = (e) => {
258
308
  if (!e || !e.trim())
259
309
  throw new Error("Custom baseline path must be a non-empty SVG path string");
260
310
  if (!e.trim().startsWith("M"))
@@ -266,44 +316,44 @@ const qt = (e) => e === void 0 || e === "flat" ? { type: "flat" } : e === "curve
266
316
  totalTextHeight: t,
267
317
  baseline: n,
268
318
  lineHeight: o,
269
- verticalAlignment: a = "centre",
270
- lineNumber: c = 0
319
+ verticalAlignment: l = "centre",
320
+ lineNumber: r = 0
271
321
  }) => {
272
- const { width: f, height: s } = e, r = o - n;
273
- let i = n;
274
- switch (a) {
322
+ const { width: a, height: s } = e, c = o - n;
323
+ let h = n;
324
+ switch (l) {
275
325
  case "centre": {
276
- i = (s - t) / 2 + o - r;
326
+ h = (s - t) / 2 + o - c;
277
327
  break;
278
328
  }
279
329
  case "bottom": {
280
- i = s - t + o - r;
330
+ h = s - t + o - c;
281
331
  break;
282
332
  }
283
333
  }
284
- return i += c * (o * pt), `M 0 ${i} L ${f} ${i}`;
334
+ return h += r * (o * pt), `M 0 ${h} L ${a} ${h}`;
285
335
  }, mt = ({
286
336
  boxDimensions: e,
287
337
  baseline: t,
288
338
  textHeight: n,
289
339
  verticalAlignment: o
290
340
  }) => {
291
- const { width: a, height: c } = e, f = n * _t, s = n + f, r = o === "top" ? 0 : c / 2 - s / 2, i = t + r, l = i + f;
292
- if (o !== "top" && (l > c || i - n < 0))
341
+ const { width: l, height: r } = e, a = n * Nt, s = n + a, c = o === "top" ? 0 : r / 2 - s / 2, h = t + c, i = h + a;
342
+ if (o !== "top" && (i > r || h - n < 0))
293
343
  return mt({
294
344
  boxDimensions: e,
295
345
  baseline: t,
296
346
  textHeight: n,
297
347
  verticalAlignment: "top"
298
348
  });
299
- const p = n / 4, u = new F(p, l), h = new F(a / 2, i), d = new F(a - p, l), g = a * 0.2, m = new F(
300
- g,
301
- t + r
302
- ), $ = new F(
303
- a - g,
304
- t + r
305
- ), w = `M ${u.toSVGString()}`, b = `Q ${m.toSVGString()} ${h.toSVGString()}`, k = `Q ${$.toSVGString()} ${d.toSVGString()}`;
306
- return `${w} ${b} ${k}`;
349
+ const b = n / 4, p = new P(b, i), u = new P(l / 2, h), f = new P(l - b, i), d = l * 0.2, g = new P(
350
+ d,
351
+ t + c
352
+ ), w = new P(
353
+ l - d,
354
+ t + c
355
+ ), m = `M ${p.toSVGString()}`, y = `Q ${g.toSVGString()} ${u.toSVGString()}`, $ = `Q ${w.toSVGString()} ${f.toSVGString()}`;
356
+ return `${m} ${y} ${$}`;
307
357
  }, yt = (e) => {
308
358
  const t = ["I", "l", "1"];
309
359
  for (const n of t) {
@@ -320,37 +370,37 @@ const qt = (e) => e === void 0 || e === "flat" ? { type: "flat" } : e === "curve
320
370
  physicalSize: n,
321
371
  spacing: o = G
322
372
  }) => {
323
- const a = n;
324
- if (a[1] !== t.physicalUnits)
373
+ const l = n;
374
+ if (l[1] !== t.physicalUnits)
325
375
  throw new Error(
326
- `Mismatched units between physicalFontSize (${a[1]}) and boxDimensions (${t.physicalUnits})`
376
+ `Mismatched units between physicalFontSize (${l[1]}) and boxDimensions (${t.physicalUnits})`
327
377
  );
328
- const { outlineWidth: c } = o, f = yt(e), r = e.getPath(
329
- f,
378
+ const { outlineWidth: r } = o, a = yt(e), c = e.getPath(
379
+ a,
330
380
  0,
331
381
  0,
332
382
  z
333
383
  ).getBoundingBox();
334
- let i = r.y2 - r.y1;
335
- if (c > 0) {
336
- const d = z * c;
337
- i += d * 2;
384
+ let h = c.y2 - c.y1;
385
+ if (r > 0) {
386
+ const f = z * r;
387
+ h += f * 2;
338
388
  }
339
- const p = i / t.height * t.physicalHeight, u = a[0] / p;
340
- return z * u;
389
+ const b = h / t.height * t.physicalHeight, p = l[0] / b;
390
+ return z * p;
341
391
  }, ct = ({
342
392
  font: e,
343
393
  text: t,
344
394
  fontSize: n,
345
395
  spacing: o = G
346
396
  }) => {
347
- const { outlineWidth: a, letterSpacing: c, letterSpacingOutline: f } = o, r = e.getPath(t, 0, 0, n).getBoundingBox(), i = a ? n * a * 2 : 0, l = a > 0 ? f : c, p = t.length > 1 ? l * n * (t.length - 1) : 0, u = r.x2 - r.x1 + i + p, h = r.y2 - r.y1 + i, d = r.y1 * -1 + i / 2;
397
+ const { outlineWidth: l, letterSpacing: r, letterSpacingOutline: a } = o, c = e.getPath(t, 0, 0, n).getBoundingBox(), h = l ? n * l * 2 : 0, i = l > 0 ? a : r, b = t.length > 1 ? i * n * (t.length - 1) : 0, p = c.x2 - c.x1 + h + b, u = c.y2 - c.y1 + h, f = c.y1 * -1 + h / 2;
348
398
  return {
349
- width: u,
350
- height: h,
351
- baseline: d
399
+ width: p,
400
+ height: u,
401
+ baseline: f
352
402
  };
353
- }, N = Tt, jt = Lt, Xt = () => new N().parseFromString("<svg></svg>", "image/svg+xml"), Zt = Xt();
403
+ }, q = Tt, jt = Lt, Xt = () => new q().parseFromString("<svg></svg>", "image/svg+xml"), Zt = Xt();
354
404
  Zt.readyState = "complete";
355
405
  const Qt = {
356
406
  aliceblue: "#f0f8ff",
@@ -512,15 +562,15 @@ const Qt = {
512
562
  return `#${R(t)}${R(n)}${R(o)}`;
513
563
  }, Jt = (e, t, n) => {
514
564
  if (t === 0) {
515
- const l = Math.round(n * 255);
516
- return [l, l, l];
565
+ const i = Math.round(n * 255);
566
+ return [i, i, i];
517
567
  }
518
- const o = (e % 360 + 360) % 360, a = (1 - Math.abs(2 * n - 1)) * t, c = a * (1 - Math.abs(o / 60 % 2 - 1)), f = n - a / 2;
519
- let s = 0, r = 0, i = 0;
520
- return o < 60 ? (s = a, r = c, i = 0) : o < 120 ? (s = c, r = a, i = 0) : o < 180 ? (s = 0, r = a, i = c) : o < 240 ? (s = 0, r = c, i = a) : o < 300 ? (s = c, r = 0, i = a) : (s = a, r = 0, i = c), [
521
- Math.round((s + f) * 255),
522
- Math.round((r + f) * 255),
523
- Math.round((i + f) * 255)
568
+ const o = (e % 360 + 360) % 360, l = (1 - Math.abs(2 * n - 1)) * t, r = l * (1 - Math.abs(o / 60 % 2 - 1)), a = n - l / 2;
569
+ let s = 0, c = 0, h = 0;
570
+ return o < 60 ? (s = l, c = r, h = 0) : o < 120 ? (s = r, c = l, h = 0) : o < 180 ? (s = 0, c = l, h = r) : o < 240 ? (s = 0, c = r, h = l) : o < 300 ? (s = r, c = 0, h = l) : (s = l, c = 0, h = r), [
571
+ Math.round((s + a) * 255),
572
+ Math.round((c + a) * 255),
573
+ Math.round((h + a) * 255)
524
574
  ];
525
575
  }, Kt = (e) => /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(e), Z = (e) => {
526
576
  const t = e.trim().toLowerCase();
@@ -541,12 +591,12 @@ const Qt = {
541
591
  /hsla?\(\s*(\d+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*[\d.]+\s*)?\)/
542
592
  );
543
593
  if (!o) return;
544
- const a = Number.parseInt(o[1], 10), c = Number.parseFloat(o[2]) / 100, f = Number.parseFloat(o[3]) / 100, [s, r, i] = Jt(a, c, f);
545
- return lt(s, r, i);
594
+ const l = Number.parseInt(o[1], 10), r = Number.parseFloat(o[2]) / 100, a = Number.parseFloat(o[3]) / 100, [s, c, h] = Jt(l, r, a);
595
+ return lt(s, c, h);
546
596
  }
547
597
  const n = Qt[t];
548
598
  if (n) return n;
549
- }, L = {
599
+ }, E = {
550
600
  circle: "circle",
551
601
  ellipse: "ellipse",
552
602
  rect: "rect",
@@ -555,28 +605,28 @@ const Qt = {
555
605
  polygon: "polygon",
556
606
  polyline: "polyline",
557
607
  stop: "stop"
558
- }, O = {
608
+ }, D = {
559
609
  fill: "fill",
560
610
  stroke: "stroke"
561
611
  }, te = {
562
612
  tiling: [
563
- L.circle,
564
- L.ellipse,
565
- L.rect,
566
- L.line,
567
- L.path,
568
- L.polygon,
569
- L.polyline,
570
- L.stop,
571
- `[${O.fill}]`,
572
- `[${O.stroke}]`
613
+ E.circle,
614
+ E.ellipse,
615
+ E.rect,
616
+ E.line,
617
+ E.path,
618
+ E.polygon,
619
+ E.polyline,
620
+ E.stop,
621
+ `[${D.fill}]`,
622
+ `[${D.stroke}]`
573
623
  ]
574
624
  }, ee = (e) => Array.from(
575
625
  e.querySelectorAll(
576
626
  te.tiling.map((t) => `*:not(clipPath) > ${t}`).join(", ")
577
627
  )
578
628
  ), ne = (e) => {
579
- const t = e.getAttribute(O.stroke);
629
+ const t = e.getAttribute(D.stroke);
580
630
  return t === "none" || !t ? !1 : t;
581
631
  }, j = (e) => {
582
632
  if (!(e === "none" || e === "transparent" || e.startsWith("url(")))
@@ -584,17 +634,17 @@ const Qt = {
584
634
  }, oe = (e) => {
585
635
  const t = ee(e).reduce(
586
636
  (n, o) => {
587
- const a = o.getAttribute("stop-color"), c = o.getAttribute(O.fill) || "#000", f = ne(o);
588
- if (!a) {
589
- const s = j(c);
637
+ const l = o.getAttribute("stop-color"), r = o.getAttribute(D.fill) || "#000", a = ne(o);
638
+ if (!l) {
639
+ const s = j(r);
590
640
  s && n.add(s);
591
641
  }
592
- if (a) {
593
- const s = j(a);
642
+ if (l) {
643
+ const s = j(l);
594
644
  s && n.add(s);
595
645
  }
596
- if (f) {
597
- const s = j(f);
646
+ if (a) {
647
+ const s = j(a);
598
648
  s && n.add(s);
599
649
  }
600
650
  return n;
@@ -603,14 +653,14 @@ const Qt = {
603
653
  );
604
654
  return Array.from(t);
605
655
  }, re = (e) => {
606
- const t = new N().parseFromString(e, "image/svg+xml").querySelector("svg");
656
+ const t = new q().parseFromString(e, "image/svg+xml").querySelector("svg");
607
657
  return t ? oe(t) : [];
608
658
  };
609
- function wt(e) {
659
+ function bt(e) {
610
660
  const t = e.trim(), n = t.startsWith("<svg") || t.startsWith("<?xml"), o = n ? t : `<svg>${t}</svg>`;
611
- return { doc: new N().parseFromString(o, "image/svg+xml"), wasWrapped: !n };
661
+ return { doc: new q().parseFromString(o, "image/svg+xml"), wasWrapped: !n };
612
662
  }
613
- function bt(e, t) {
663
+ function wt(e, t) {
614
664
  const n = e.querySelector("svg");
615
665
  return n ? t ? n.innerHTML : n.outerHTML : "";
616
666
  }
@@ -620,68 +670,68 @@ function $e(e) {
620
670
  return [];
621
671
  const n = /* @__PURE__ */ new Set();
622
672
  for (const [, o] of t)
623
- for (const a of re(o.svg))
624
- n.add(a);
673
+ for (const l of re(o.svg))
674
+ n.add(l);
625
675
  return Array.from(n);
626
676
  }
627
677
  function se(e) {
628
678
  return !!e && e !== "none" && e !== "transparent" && !e.startsWith("url(");
629
679
  }
630
680
  function ae(e) {
631
- const n = new N().parseFromString(e, "image/svg+xml").querySelector("svg");
681
+ const n = new q().parseFromString(e, "image/svg+xml").querySelector("svg");
632
682
  return n ? n.innerHTML.trim() : "";
633
683
  }
634
684
  const ie = ["fill", "stroke", "clip-path", "mask", "filter"];
635
685
  function ce(e, t) {
636
- const { doc: n, wasWrapped: o } = wt(e), a = /* @__PURE__ */ new Map();
637
- for (const c of n.querySelectorAll("[id]")) {
638
- const f = c.getAttribute("id");
639
- if (!f) continue;
640
- const s = `${t}-${f}`;
641
- a.set(f, s), c.setAttribute("id", s);
686
+ const { doc: n, wasWrapped: o } = bt(e), l = /* @__PURE__ */ new Map();
687
+ for (const r of n.querySelectorAll("[id]")) {
688
+ const a = r.getAttribute("id");
689
+ if (!a) continue;
690
+ const s = `${t}-${a}`;
691
+ l.set(a, s), r.setAttribute("id", s);
642
692
  }
643
- if (a.size === 0)
693
+ if (l.size === 0)
644
694
  return e;
645
- for (const c of ie)
646
- for (const f of n.querySelectorAll(`[${c}]`)) {
647
- const s = f.getAttribute(c);
695
+ for (const r of ie)
696
+ for (const a of n.querySelectorAll(`[${r}]`)) {
697
+ const s = a.getAttribute(r);
648
698
  if (s) {
649
- const r = s.replace(/url\(#([^)]+)\)/g, (i, l) => {
650
- const p = a.get(l);
651
- return p ? `url(#${p})` : `url(#${l})`;
699
+ const c = s.replace(/url\(#([^)]+)\)/g, (h, i) => {
700
+ const b = l.get(i);
701
+ return b ? `url(#${b})` : `url(#${i})`;
652
702
  });
653
- r !== s && f.setAttribute(c, r);
703
+ c !== s && a.setAttribute(r, c);
654
704
  }
655
705
  }
656
- for (const c of n.querySelectorAll("[href], [xlink\\:href]"))
657
- for (const f of ["href", "xlink:href"]) {
658
- const s = c.getAttribute(f);
706
+ for (const r of n.querySelectorAll("[href], [xlink\\:href]"))
707
+ for (const a of ["href", "xlink:href"]) {
708
+ const s = r.getAttribute(a);
659
709
  if (s?.startsWith("#")) {
660
- const r = s.slice(1), i = a.get(r);
661
- i && c.setAttribute(f, `#${i}`);
710
+ const c = s.slice(1), h = l.get(c);
711
+ h && r.setAttribute(a, `#${h}`);
662
712
  }
663
713
  }
664
- return bt(n, o);
714
+ return wt(n, o);
665
715
  }
666
716
  const le = ["fill", "stroke", "stop-color"], fe = ["path", "rect", "circle", "ellipse", "polygon", "polyline", "text"];
667
717
  function he(e, t) {
668
- const { doc: n, wasWrapped: o } = wt(e), a = {};
669
- for (const [f, s] of Object.entries(t))
670
- a[Z(f) ?? f.toLowerCase()] = s;
671
- for (const f of le)
672
- for (const s of n.querySelectorAll(`[${f}]`)) {
673
- const r = s.getAttribute(f);
674
- if (!r || !se(r)) continue;
675
- const i = Z(r), l = i ? a[i] : void 0;
676
- l && s.setAttribute(f, l.hex);
718
+ const { doc: n, wasWrapped: o } = bt(e), l = {};
719
+ for (const [a, s] of Object.entries(t))
720
+ l[Z(a) ?? a.toLowerCase()] = s;
721
+ for (const a of le)
722
+ for (const s of n.querySelectorAll(`[${a}]`)) {
723
+ const c = s.getAttribute(a);
724
+ if (!c || !se(c)) continue;
725
+ const h = Z(c), i = h ? l[h] : void 0;
726
+ i && s.setAttribute(a, i.hex);
677
727
  }
678
- const c = a["#000000"];
679
- if (c) {
680
- const f = fe.map((s) => `${s}:not([fill])`).join(", ");
681
- for (const s of n.querySelectorAll(f))
682
- s.setAttribute("fill", c.hex);
728
+ const r = l["#000000"];
729
+ if (r) {
730
+ const a = fe.map((s) => `${s}:not([fill])`).join(", ");
731
+ for (const s of n.querySelectorAll(a))
732
+ s.setAttribute("fill", r.hex);
683
733
  }
684
- return bt(n, o);
734
+ return wt(n, o);
685
735
  }
686
736
  const de = (e = [1, 0, 0, 1, 0, 0]) => {
687
737
  const t = `matrix(${e.join(",")})`, n = new jt(t);
@@ -697,80 +747,80 @@ const ft = (e, t, n) => e / n * t, ue = ({
697
747
  baselinePath: t,
698
748
  text: n,
699
749
  fontSize: o,
700
- spacing: a = G,
701
- horizontalAlignment: c = "centre",
702
- colourMap: f
750
+ spacing: l = G,
751
+ horizontalAlignment: r = "centre",
752
+ colourMap: a
703
753
  }) => {
704
- const { outlineWidth: s, letterSpacing: r, letterSpacingOutline: i } = a, l = new Pt(t), p = s ? o * s * 2 : 0, u = l.getTotalLength(), h = e.getPaths(n, 0, 0, o, { drawSVG: !1 }), g = e.getPath(n, 0, 0, o, { drawSVG: !1 }).getBoundingBox(), m = g.x1 - p / 2, w = g.x2 + p / 2 - m, b = s > 0 ? i : r;
705
- let k = b ? b * o : 0;
706
- c === "distributed" && (k = n.length === 1 ? 0 : (u - w) / (n.length - 1));
707
- const A = k * (n.length - 1), E = w + A;
708
- let S = 0 - m;
709
- c === "centre" ? S = (u - E) / 2 - m : c === "right" && (S = u - w - m - A);
710
- const U = [];
711
- for (let v = 0; v < h.length; v++) {
712
- const y = h[v], x = y.getBoundingBox(), B = e.charToGlyph(n[v]), { advanceWidth: C } = B;
713
- if (!C)
754
+ const { outlineWidth: s, letterSpacing: c, letterSpacingOutline: h } = l, i = new Pt(t), b = s ? o * s * 2 : 0, p = i.getTotalLength(), u = e.getPaths(n, 0, 0, o, { drawSVG: !1 }), d = e.getPath(n, 0, 0, o, { drawSVG: !1 }).getBoundingBox(), g = d.x1 - b / 2, m = d.x2 + b / 2 - g, y = s > 0 ? h : c;
755
+ let $ = y ? y * o : 0;
756
+ r === "distributed" && ($ = n.length === 1 ? 0 : (p - m) / (n.length - 1));
757
+ const v = $ * (n.length - 1), M = m + v;
758
+ let S = 0 - g;
759
+ r === "centre" ? S = (p - M) / 2 - g : r === "right" && (S = p - m - g - v);
760
+ const A = [];
761
+ for (let k = 0; k < u.length; k++) {
762
+ const x = u[k], F = x.getBoundingBox(), T = e.charToGlyph(n[k]), { advanceWidth: U } = T;
763
+ if (!U)
714
764
  throw new Error(
715
- `No advance width for character: ${n[v]} in font ${e.names.fontFamily}`
765
+ `No advance width for character: ${n[k]} in font ${e.names.fontFamily}`
716
766
  );
717
- const { x1: xt, x2: vt } = B.getBoundingBox(), $t = ft(
718
- C,
767
+ const { x1: xt, x2: vt } = T.getBoundingBox(), $t = ft(
768
+ U,
719
769
  o,
720
770
  e.unitsPerEm
721
771
  ), Y = ft(vt - xt, o, e.unitsPerEm);
722
- let I = S + x.x1;
723
- if (v > 0 && (I += k * v), I + Y > u)
772
+ let I = S + F.x1;
773
+ if (k > 0 && (I += $ * k), I + Y > p)
724
774
  throw new Error(
725
- `TOO_WIDE: character "${n[v]}" at index ${v} exceeds baseline path length (${Math.round(I + Y)} > ${Math.round(u)})`
775
+ `TOO_WIDE: character "${n[k]}" at index ${k} exceeds baseline path length (${Math.round(I + Y)} > ${Math.round(p)})`
726
776
  );
727
- const St = I + $t / 2, J = l.getTangentAtLength(St), D = Math.atan2(J.y, J.x) * 180 / Math.PI, K = l.getPointAtLength(I), kt = K.x, Mt = K.y, tt = x.x2 - x.x1, Ft = new F(x.x1 + tt / 2, 0), et = Vt(
728
- new F(x.x1, 0),
729
- D,
777
+ const St = I + $t / 2, J = i.getTangentAtLength(St), O = Math.atan2(J.y, J.x) * 180 / Math.PI, K = i.getPointAtLength(I), kt = K.x, Mt = K.y, tt = F.x2 - F.x1, Ft = new P(F.x1 + tt / 2, 0), et = _t(
778
+ new P(F.x1, 0),
779
+ O,
730
780
  Ft
731
- ), _ = kt - et.X, V = Mt - et.Y;
732
- let M = de();
733
- M = M.translate(_, V);
734
- let q;
735
- if (D) {
736
- const T = x.x1 + tt / 2;
737
- M = M.translate(T, 0), M = M.rotate(D), M = M.translate(-T, 0), q = `translate(${_} ${V}) translate(${T} 0) rotate(${D}) translate(${-T} 0)`;
781
+ ), N = kt - et.X, _ = Mt - et.Y;
782
+ let B = de();
783
+ B = B.translate(N, _);
784
+ let V;
785
+ if (O) {
786
+ const C = F.x1 + tt / 2;
787
+ B = B.translate(C, 0), B = B.rotate(O), B = B.translate(-C, 0), V = `translate(${N} ${_}) translate(${C} 0) rotate(${O}) translate(${-C} 0)`;
738
788
  } else
739
- q = `translate(${_} ${V})`;
740
- let P = y.toPathData(2);
741
- P.length && !P.endsWith("Z") && (P += "Z", P = P.replace(/M/g, "ZM"), P = P.substring(1));
789
+ V = `translate(${N} ${_})`;
790
+ let L = x.toPathData(2);
791
+ L.length && !L.endsWith("Z") && (L += "Z", L = L.replace(/M/g, "ZM"), L = L.substring(1));
742
792
  let H;
743
793
  if (e.svgGlyphs) {
744
- const T = e.svgGlyphs.get(B.index);
745
- if (T) {
746
- let W = ae(T.svg);
747
- W = ce(W, `g${B.index}-${v}`), f && (W = he(W, f)), H = {
794
+ const C = e.svgGlyphs.get(T.index);
795
+ if (C) {
796
+ let W = ae(C.svg);
797
+ W = ce(W, `g${T.index}-${k}`), a && (W = he(W, a)), H = {
748
798
  content: W,
749
- viewBox: T.viewbox,
750
- x: x.x1,
751
- y: x.y1,
752
- width: x.x2 - x.x1,
753
- height: x.y2 - x.y1,
754
- glyphIndex: B.index
799
+ viewBox: C.viewbox,
800
+ x: F.x1,
801
+ y: F.y1,
802
+ width: F.x2 - F.x1,
803
+ height: F.y2 - F.y1,
804
+ glyphIndex: T.index
755
805
  };
756
806
  }
757
807
  }
758
- U.push({
759
- path: y,
760
- matrix: M,
808
+ A.push({
809
+ path: x,
810
+ matrix: B,
761
811
  attributes: {
762
- d: P,
763
- "data-character": ge(n[v]),
764
- transform: q
812
+ d: L,
813
+ "data-character": ge(n[k]),
814
+ transform: V
765
815
  },
766
816
  glyphData: {
767
- index: B.index,
768
- bbox: x
817
+ index: T.index,
818
+ bbox: F
769
819
  },
770
820
  ...H ? { svgGlyph: H } : {}
771
821
  });
772
822
  }
773
- return U;
823
+ return A;
774
824
  }, ht = { hex: "#FFFFFF" }, Q = (e, t) => {
775
825
  const n = `data-${e}-colour-url`, o = [`${e}="${t.hex}"`];
776
826
  return t.reference && o.push(`${n}="${t.reference}"`), o.join(" ");
@@ -782,128 +832,128 @@ const ft = (e, t, n) => e / n * t, ue = ({
782
832
  paths: t,
783
833
  spacing: n = G,
784
834
  fontSize: o = 0,
785
- fillColour: a = ht,
786
- strokeColour: c = ht
835
+ fillColour: l = ht,
836
+ strokeColour: r = ht
787
837
  }) => {
788
- const { width: f, height: s } = e, { outlineWidth: r } = n, i = r > 0 && o > 0;
789
- let l;
790
- if (i) {
791
- const u = o * r * 2, h = t.filter((g) => !g.svgGlyph).map(
792
- ({ attributes: g }) => `<path d="${g.d}" ${Q("fill", c)} ${Q("stroke", c)} stroke-width="${u}" stroke-linejoin="round" transform="${g.transform}" data-character="${g["data-character"]}"/>`
838
+ const { width: a, height: s } = e, { outlineWidth: c } = n, h = c > 0 && o > 0;
839
+ let i;
840
+ if (h) {
841
+ const p = o * c * 2, u = t.filter((d) => !d.svgGlyph).map(
842
+ ({ attributes: d }) => `<path d="${d.d}" ${Q("fill", r)} ${Q("stroke", r)} stroke-width="${p}" stroke-linejoin="round" transform="${d.transform}" data-character="${d["data-character"]}"/>`
793
843
  ).join(`
794
- `), d = t.map((g) => dt(g, a)).join(`
844
+ `), f = t.map((d) => dt(d, l)).join(`
795
845
  `);
796
- l = `${h}
797
- ${d}`;
846
+ i = `${u}
847
+ ${f}`;
798
848
  } else
799
- l = t.map((u) => dt(u, a)).join(`
849
+ i = t.map((p) => dt(p, l)).join(`
800
850
  `);
801
- const p = l ? `
802
- ${l}
851
+ const b = i ? `
852
+ ${i}
803
853
  ` : "";
804
- return `<svg xmlns="http://www.w3.org/2000/svg" width="${f}" height="${s}" viewBox="0 0 ${f} ${s}">${p}</svg>`;
854
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${a}" height="${s}" viewBox="0 0 ${a} ${s}">${b}</svg>`;
805
855
  }, gt = (e) => {
806
856
  const {
807
857
  text: t,
808
858
  font: n,
809
859
  physicalSize: o,
810
- fontSize: a,
811
- boxDimensions: c,
812
- spacing: f = G,
860
+ fontSize: l,
861
+ boxDimensions: r,
862
+ spacing: a = G,
813
863
  verticalAlignment: s = "centre",
814
- baseline: r = "flat",
815
- horizontalAlignment: i = "left",
816
- fillColour: l = { hex: "#FFFFFF" },
817
- strokeColour: p = { hex: "#FFFFFF" },
818
- colourMap: u
819
- } = e, { width: h, height: d, physicalWidth: g, physicalHeight: m } = c;
820
- if (h <= 0 || d <= 0)
864
+ baseline: c = "flat",
865
+ horizontalAlignment: h = "left",
866
+ fillColour: i = { hex: "#FFFFFF" },
867
+ strokeColour: b = { hex: "#FFFFFF" },
868
+ colourMap: p
869
+ } = e, { width: u, height: f, physicalWidth: d, physicalHeight: g } = r;
870
+ if (u <= 0 || f <= 0)
821
871
  throw new Error(
822
- `boxDimensions width and height must be positive (got ${h}x${d})`
872
+ `boxDimensions width and height must be positive (got ${u}x${f})`
823
873
  );
824
- if (g <= 0 || m <= 0)
874
+ if (d <= 0 || g <= 0)
825
875
  throw new Error(
826
- `boxDimensions physicalWidth and physicalHeight must be positive (got ${g}x${m})`
876
+ `boxDimensions physicalWidth and physicalHeight must be positive (got ${d}x${g})`
827
877
  );
828
878
  if (o[0] <= 0)
829
879
  throw new Error(
830
880
  `physicalSize height must be positive (got ${o[0]})`
831
881
  );
832
- const $ = a ?? Rt({
882
+ const w = l ?? Rt({
833
883
  font: n,
834
- boxDimensions: c,
884
+ boxDimensions: r,
835
885
  physicalSize: o,
836
- spacing: f
837
- }), w = qt(r);
838
- let b = t.split(`
839
- `).filter((y) => y.length > 0);
840
- b.length || (b = [""]), (w.type === "curved" || w.type === "custom") && (b = [b.join("")]);
841
- const k = b.map(
842
- (y) => ct({ font: n, text: y, fontSize: $, spacing: f })
843
- ), A = Math.max(...k.map((y) => y.baseline)), E = Math.max(...k.map((y) => y.height - y.baseline)), S = A + E, U = b.length === 1 ? S : S + S * (b.length - 1) * pt, v = [];
844
- for (let y = 0; y < b.length; y++) {
845
- let x;
846
- switch (w.type) {
886
+ spacing: a
887
+ }), m = Vt(c);
888
+ let y = t.split(`
889
+ `).filter((x) => x.length > 0);
890
+ y.length || (y = [""]), (m.type === "curved" || m.type === "custom") && (y = [y.join("")]);
891
+ const $ = y.map(
892
+ (x) => ct({ font: n, text: x, fontSize: w, spacing: a })
893
+ ), v = Math.max(...$.map((x) => x.baseline)), M = Math.max(...$.map((x) => x.height - x.baseline)), S = v + M, A = y.length === 1 ? S : S + S * (y.length - 1) * pt, k = [];
894
+ for (let x = 0; x < y.length; x++) {
895
+ let F;
896
+ switch (m.type) {
847
897
  case "custom":
848
- Ht(w.path), x = w.path;
898
+ Ht(m.path), F = m.path;
849
899
  break;
850
900
  case "curved": {
851
- const C = ct({
901
+ const U = ct({
852
902
  font: n,
853
903
  text: yt(n),
854
- fontSize: $,
855
- spacing: f
904
+ fontSize: w,
905
+ spacing: a
856
906
  });
857
- x = mt({
858
- boxDimensions: c,
859
- baseline: C.baseline,
860
- textHeight: C.height,
907
+ F = mt({
908
+ boxDimensions: r,
909
+ baseline: U.baseline,
910
+ textHeight: U.height,
861
911
  verticalAlignment: s
862
912
  });
863
913
  break;
864
914
  }
865
915
  case "flat":
866
- x = zt({
867
- boxDimensions: c,
868
- totalTextHeight: U,
869
- baseline: A,
916
+ F = zt({
917
+ boxDimensions: r,
918
+ totalTextHeight: A,
919
+ baseline: v,
870
920
  lineHeight: S,
871
921
  verticalAlignment: s,
872
- lineNumber: y
922
+ lineNumber: x
873
923
  });
874
924
  break;
875
925
  }
876
- const B = ue({
926
+ const T = ue({
877
927
  font: n,
878
- baselinePath: x,
879
- text: b[y],
880
- fontSize: $,
881
- spacing: f,
882
- horizontalAlignment: i,
883
- colourMap: u
928
+ baselinePath: F,
929
+ text: y[x],
930
+ fontSize: w,
931
+ spacing: a,
932
+ horizontalAlignment: h,
933
+ colourMap: p
884
934
  });
885
- v.push(...B);
935
+ k.push(...T);
886
936
  }
887
937
  return pe({
888
- boxDimensions: c,
889
- paths: v,
890
- spacing: f,
891
- fontSize: $,
892
- fillColour: l,
893
- strokeColour: p
938
+ boxDimensions: r,
939
+ paths: k,
940
+ spacing: a,
941
+ fontSize: w,
942
+ fillColour: i,
943
+ strokeColour: b
894
944
  });
895
945
  }, Se = async (e) => {
896
- const { fontUrl: t, fontSizeFallback: n, ...o } = e, a = !!o.colourMap, c = await Ot(t, a);
946
+ const { fontUrl: t, fontSizeFallback: n, ...o } = e, l = !!o.colourMap, r = await Dt(t, l);
897
947
  try {
898
- return gt({ ...o, font: c });
899
- } catch (f) {
900
- if (n != null && f instanceof Error && f.message.startsWith("TOO_WIDE"))
901
- return gt({ ...o, font: c, fontSize: n });
902
- throw f;
948
+ return gt({ ...o, font: r });
949
+ } catch (a) {
950
+ if (n != null && a instanceof Error && a.message.startsWith("TOO_WIDE"))
951
+ return gt({ ...o, font: r, fontSize: n });
952
+ throw a;
903
953
  }
904
954
  };
905
955
  export {
906
- Nt as DEFAULT_OUTLINE_FACTOR,
956
+ qt as DEFAULT_OUTLINE_FACTOR,
907
957
  G as DEFAULT_SPACING,
908
958
  pt as LINE_HEIGHT,
909
959
  mt as generateCurvedBaseline,
@@ -913,8 +963,8 @@ export {
913
963
  Rt as getFontSizeFromPhysicalSize,
914
964
  Se as getRenderedText,
915
965
  ct as getTextMetricsAtFontSize,
916
- Ot as loadFont,
917
- qt as normaliseBaselineOption,
966
+ Dt as loadFont,
967
+ Vt as normaliseBaselineOption,
918
968
  gt as renderText,
919
969
  Ht as validateCustomBaselinePath
920
970
  };