@unmade/text-renderer 1.1.1 → 1.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.
Files changed (36) hide show
  1. package/README.md +231 -0
  2. package/dist/{__vite-browser-external-CijFC1_R.js → __vite-browser-external-oLchLuMx.js} +1 -1
  3. package/dist/baselines/index.d.ts +19 -0
  4. package/dist/ce-adapter/index.cjs +1 -1
  5. package/dist/ce-adapter/index.js +1 -1
  6. package/dist/fitting/index.d.ts +86 -0
  7. package/dist/helpers/bbox.d.ts +2 -1
  8. package/dist/index.d.ts +2 -0
  9. package/dist/index.js +1143 -339
  10. package/dist/layout/index.d.ts +77 -0
  11. package/dist/node/baselines/index.d.ts +19 -0
  12. package/dist/node/fitting/index.d.ts +86 -0
  13. package/dist/node/helpers/bbox.d.ts +2 -1
  14. package/dist/node/index.d.ts +2 -0
  15. package/dist/node/index.js +446 -201
  16. package/dist/node/layout/index.d.ts +77 -0
  17. package/dist/node/renderText.d.ts +3 -0
  18. package/dist/node/rendering/index.d.ts +2 -2
  19. package/dist/node/types.d.ts +3 -0
  20. package/dist/renderText.d.ts +3 -0
  21. package/dist/rendering/index.d.ts +2 -2
  22. package/dist/{chunk-3b4jIN3o.js → rolldown-runtime-DtPi1Y-2.js} +2 -2
  23. package/dist/types.d.ts +3 -0
  24. package/dist/worker/baselines/index.d.ts +19 -0
  25. package/dist/worker/fitting/index.d.ts +86 -0
  26. package/dist/worker/helpers/bbox.d.ts +2 -1
  27. package/dist/worker/index.d.ts +2 -0
  28. package/dist/worker/index.js +2846 -2377
  29. package/dist/worker/layout/index.d.ts +77 -0
  30. package/dist/worker/renderText.d.ts +3 -0
  31. package/dist/worker/rendering/index.d.ts +2 -2
  32. package/dist/worker/types.d.ts +3 -0
  33. package/package.json +12 -5
  34. package/dist/helpers/matrix.d.ts +0 -8
  35. package/dist/node/helpers/matrix.d.ts +0 -8
  36. package/dist/worker/helpers/matrix.d.ts +0 -8
@@ -1,8 +1,8 @@
1
1
  import { Blob as e, Buffer as t, Face as n, Feature as r, Font as i, shape as a } from "harfbuzzjs";
2
- import { svgPathProperties as o } from "svg-path-properties";
2
+ import o from "@thednp/dommatrix";
3
3
  import { DOMParser as s } from "linkedom";
4
4
  import "node:path";
5
- import c from "@thednp/dommatrix";
5
+ import { svgPathProperties as c } from "svg-path-properties";
6
6
  //#region src/loading/createLoadedFont.ts
7
7
  function l(e) {
8
8
  let t = Infinity, n = Infinity, r = -Infinity, i = -Infinity, a = 0, o = 0;
@@ -237,18 +237,18 @@ var x = async (t, r = !1) => {
237
237
  let a = f.get(t);
238
238
  if (a) {
239
239
  if (r && !a.svgGlyphs) {
240
- let r = new n(new e(await b(t))), o = new i(r), s = r.referenceTable("SVG ");
241
- a.svgGlyphs = s ? await _(s, o, r.upem) : /* @__PURE__ */ new Map();
240
+ let r = await b(t), o = new e(r), s = new n(o), c = new i(s), l = s.referenceTable("SVG ");
241
+ a.svgGlyphs = l ? await _(l, c, s.upem) : /* @__PURE__ */ new Map();
242
242
  }
243
243
  return a;
244
244
  }
245
- let o = new n(new e(await b(t))), s = new i(o), c = o.getName(1, "en") ?? "", l;
245
+ let o = await b(t), s = new e(o), c = new n(s), l = new i(c), u = c.getName(1, "en") ?? "", p;
246
246
  if (r) {
247
- let e = o.referenceTable("SVG ");
248
- l = e ? await _(e, s, o.upem) : /* @__PURE__ */ new Map();
247
+ let e = c.referenceTable("SVG ");
248
+ p = e ? await _(e, l, c.upem) : /* @__PURE__ */ new Map();
249
249
  }
250
- let u = d(o, s, c, l);
251
- return f.set(t, u), u;
250
+ let m = d(c, l, u, p);
251
+ return f.set(t, m), m;
252
252
  }, S = .03125, C = 1.1, w = .2, T = {
253
253
  outlineWidth: S,
254
254
  letterSpacing: 0,
@@ -267,37 +267,125 @@ var x = async (t, r = !1) => {
267
267
  return `${this.x} ${this.y}`;
268
268
  }
269
269
  };
270
- function D(e, t, n = new E(0, 0)) {
270
+ function ee(e, t, n = new E(0, 0)) {
271
271
  let r = e.X - n.X, i = e.Y - n.Y, a = t / 180 * Math.PI, o = Math.cos(a), s = Math.sin(a), c = r * o - i * s, l = r * s + i * o;
272
272
  return new E(c + n.X, l + n.Y);
273
273
  }
274
274
  //#endregion
275
275
  //#region src/baselines/index.ts
276
- var O = (e) => e === void 0 || e === "flat" ? { type: "flat" } : e === "curved" ? { type: "curved" } : e, k = (e) => {
276
+ var D = (e) => e === void 0 || e === "flat" ? { type: "flat" } : e === "curved" ? { type: "curved" } : e, O = (e) => {
277
277
  if (!e || !e.trim()) throw Error("Custom baseline path must be a non-empty SVG path string");
278
278
  if (!e.trim().startsWith("M")) throw Error("Custom baseline path must start with an M (moveto) command");
279
- }, A = ({ boxDimensions: e, totalTextHeight: t, baseline: n, lineHeight: r, verticalAlignment: i = "centre", lineNumber: a = 0 }) => {
279
+ }, k = ({ boxDimensions: e, totalTextHeight: t, baseline: n, lineHeight: r, verticalAlignment: i = "centre", lineNumber: a = 0 }) => {
280
280
  let { width: o, height: s } = e, c = r - n, l = n;
281
281
  switch (i) {
282
282
  case "centre":
283
283
  l = (s - t) / 2 + r - c;
284
284
  break;
285
- case "bottom":
286
- l = s - t + r - c;
287
- break;
285
+ case "bottom": l = s - t + r - c;
288
286
  }
289
287
  return l += r * C * a, `M 0 ${l} L ${o} ${l}`;
290
- }, j = ({ boxDimensions: e, baseline: t, textHeight: n, verticalAlignment: r }) => {
291
- let { width: i, height: a } = e, o = n * w, s = n + o, c = r === "top" ? 0 : a / 2 - s / 2, l = t + c, u = l + o;
292
- if (r !== "top" && (u > a || l - n < 0)) return j({
288
+ }, A = ({ boxDimensions: e, baseline: t, textHeight: n, verticalAlignment: r }) => {
289
+ let { height: i } = e, a = n * w, o = n + a, s = t + (r === "top" ? 0 : i / 2 - o / 2), c = s + a;
290
+ return r !== "top" && (c > i || s - n < 0) ? A({
293
291
  boxDimensions: e,
294
292
  baseline: t,
295
293
  textHeight: n,
296
294
  verticalAlignment: "top"
297
- });
298
- let d = n / 4, f = new E(d, u), p = new E(i / 2, l), m = new E(i - d, u), h = i * .2, g = new E(h, t + c), _ = new E(i - h, t + c);
299
- return `${`M ${f.toSVGString()}`} ${`Q ${g.toSVGString()} ${p.toSVGString()}`} ${`Q ${_.toSVGString()} ${m.toSVGString()}`}`;
300
- }, M = (e) => {
295
+ }) : {
296
+ curveTop: s,
297
+ curveBottom: c,
298
+ curveXInset: n / 4
299
+ };
300
+ }, j = ({ boxDimensions: e, baseline: t, textHeight: n, verticalAlignment: r }) => {
301
+ let { width: i } = e, { curveTop: a, curveBottom: o, curveXInset: s } = A({
302
+ boxDimensions: e,
303
+ baseline: t,
304
+ textHeight: n,
305
+ verticalAlignment: r
306
+ }), c = new E(s, o), l = new E(i / 2, a), u = new E(i - s, o), d = i * .2, f = new E(d, a), p = new E(i - d, a);
307
+ return `${`M ${c.toSVGString()}`} ${`Q ${f.toSVGString()} ${l.toSVGString()}`} ${`Q ${p.toSVGString()} ${u.toSVGString()}`}`;
308
+ }, M = class e {
309
+ constructor(e = 0, t = 0, n = 0, r = 1) {
310
+ this.x = e, this.y = t, this.z = n, this.w = r;
311
+ }
312
+ static fromPoint(t) {
313
+ return new e(t.x, t.y, t.z === void 0 ? 0 : t.z, t.w === void 0 ? 1 : t.w);
314
+ }
315
+ matrixTransform(t) {
316
+ return t.is2D && this.z === 0 && this.w === 1 ? new e(this.x * t.a + this.y * t.c + t.e, this.x * t.b + this.y * t.d + t.f, 0, 1) : new e(this.x * t.m11 + this.y * t.m21 + this.z * t.m31 + this.w * t.m41, this.x * t.m12 + this.y * t.m22 + this.z * t.m32 + this.w * t.m42, this.x * t.m13 + this.y * t.m23 + this.z * t.m33 + this.w * t.m43, this.x * t.m14 + this.y * t.m24 + this.z * t.m34 + this.w * t.m44);
317
+ }
318
+ toJSON() {
319
+ return {
320
+ x: this.x,
321
+ y: this.y,
322
+ z: this.z,
323
+ w: this.w
324
+ };
325
+ }
326
+ }, N = s, te = o, P = new N().parseFromString("<svg></svg>", "image/svg+xml");
327
+ P.readyState = "complete";
328
+ //#endregion
329
+ //#region src/helpers/bbox.ts
330
+ var F = class {
331
+ get x3() {
332
+ return this._x3 || this.x1;
333
+ }
334
+ get y3() {
335
+ return this._y3 || this.y2;
336
+ }
337
+ get x4() {
338
+ return this._x4 || this.x2;
339
+ }
340
+ get y4() {
341
+ return this._y4 || this.y1;
342
+ }
343
+ constructor(e, t, n, r, i, a, o, s) {
344
+ this.x1 = e, this.y1 = t, this.x2 = n, this.y2 = r, this._x3 = i, this._y3 = a, this._x4 = o, this._y4 = s, this.corners = [
345
+ new M(this.x1, this.y1),
346
+ new M(this.x2, this.y2),
347
+ new M(this.x3, this.y3),
348
+ new M(this.x4, this.y4)
349
+ ];
350
+ }
351
+ transform(e) {
352
+ this.corners = this.corners.map((t) => t.matrixTransform(e)), this.x1 = this.corners[0].x, this.y1 = this.corners[0].y, this.x2 = this.corners[1].x, this.y2 = this.corners[1].y, this._x3 = this.corners[2].x, this._y3 = this.corners[2].y, this._x4 = this.corners[3].x, this._y4 = this.corners[3].y;
353
+ }
354
+ toPointsArray() {
355
+ return this.corners.map((e) => [e.x, e.y]);
356
+ }
357
+ getBBox() {
358
+ let e = Math.min(this.x1, this.x2, this.x3, this.x4), t = Math.min(this.y1, this.y2, this.y3, this.y4), n = Math.max(this.x1, this.x2, this.x3, this.x4) - e, r = Math.max(this.y1, this.y2, this.y3, this.y4) - t;
359
+ return new I(e, t, e + n, t + r);
360
+ }
361
+ }, I = class extends F {
362
+ get x() {
363
+ return this.x1;
364
+ }
365
+ get y() {
366
+ return this.y1;
367
+ }
368
+ get width() {
369
+ return this.x2 - this.x1;
370
+ }
371
+ get height() {
372
+ return this.y2 - this.y1;
373
+ }
374
+ add(e) {
375
+ this.x1 = Math.min(this.x1, e.x1, e.x2, e.x3, e.x4), this.y1 = Math.min(this.y1, e.y1, e.y2, e.y3, e.y4), this.x2 = Math.max(this.x2, e.x1, e.x2, e.x3, e.x4), this.y2 = Math.max(this.y2, e.y1, e.y2, e.y3, e.y4);
376
+ }
377
+ addPoint(e, t) {
378
+ this.x1 = Math.min(this.x1, e), this.y1 = Math.min(this.y1, t), this.x2 = Math.max(this.x2, e), this.y2 = Math.max(this.y2, t);
379
+ }
380
+ serialize() {
381
+ return {
382
+ x: this.x,
383
+ y: this.y,
384
+ width: this.width,
385
+ height: this.height
386
+ };
387
+ }
388
+ }, L = (e) => {
301
389
  for (let t of [
302
390
  "I",
303
391
  "l",
@@ -307,28 +395,24 @@ var O = (e) => e === void 0 || e === "flat" ? { type: "flat" } : e === "curved"
307
395
  if (n && n.name !== ".notdef") return t;
308
396
  }
309
397
  return console.error("No standard character found for fixed height calculation. Using \"I\" as default."), "I";
310
- }, N = 100, P = ({ font: e, boxDimensions: t, physicalSize: n, spacing: r = T }) => {
398
+ }, R = 100, z = ({ font: e, boxDimensions: t, physicalSize: n, spacing: r = T }) => {
311
399
  let i = n;
312
400
  if (i[1] !== t.physicalUnits) throw Error(`Mismatched units between physicalFontSize (${i[1]}) and boxDimensions (${t.physicalUnits})`);
313
- let { outlineWidth: a } = r, o = M(e), s = e.getPath(o, 0, 0, N).getBoundingBox(), c = s.y2 - s.y1;
401
+ let { outlineWidth: a } = r, o = L(e), s = e.getPath(o, 0, 0, R).getBoundingBox(), c = s.y2 - s.y1;
314
402
  if (a > 0) {
315
- let e = N * a;
403
+ let e = R * a;
316
404
  c += e * 2;
317
405
  }
318
406
  let l = c / t.height * t.physicalHeight;
319
- return N * (i[0] / l);
320
- }, F = ({ font: e, text: t, fontSize: n, spacing: r = T }) => {
407
+ return R * (i[0] / l);
408
+ }, B = ({ font: e, text: t, fontSize: n, spacing: r = T }) => {
321
409
  let { outlineWidth: i, letterSpacing: a, letterSpacingOutline: o } = r, s = e.getPath(t, 0, 0, n).getBoundingBox(), c = i ? n * i * 2 : 0, l = i > 0 ? o : a, u = t.length > 1 ? l * n * (t.length - 1) : 0;
322
410
  return {
323
411
  width: s.x2 - s.x1 + c + u,
324
412
  height: s.y2 - s.y1 + c,
325
413
  baseline: s.y1 * -1 + c / 2
326
414
  };
327
- }, I = s, ee = c, te = new I().parseFromString("<svg></svg>", "image/svg+xml");
328
- te.readyState = "complete";
329
- //#endregion
330
- //#region ../svg-helpers/dist/colours/named-colours.mjs
331
- var ne = {
415
+ }, ne = {
332
416
  aliceblue: "#f0f8ff",
333
417
  antiquewhite: "#faebd7",
334
418
  aqua: "#00ffff",
@@ -480,9 +564,9 @@ var ne = {
480
564
  }, re = (e) => {
481
565
  let t = Array.from(e), n = !1;
482
566
  return t[0] === "#" && (t.shift(), n = !0), t.length === 3 && (t = t.map((e) => `${e}${e}`)), `${n ? "#" : ""}${t.join("").toLowerCase()}`;
483
- }, L = (e) => Math.max(0, Math.min(255, Math.round(typeof e == "string" ? Number.parseInt(e, 10) : e))).toString(16).padStart(2, "0"), R = (...e) => {
567
+ }, V = (e) => Math.max(0, Math.min(255, Math.round(typeof e == "string" ? Number.parseInt(e, 10) : e))).toString(16).padStart(2, "0"), H = (...e) => {
484
568
  let [t, n, r] = Array.isArray(e[0]) ? e[0] : e;
485
- return `#${L(t)}${L(n)}${L(r)}`;
569
+ return `#${V(t)}${V(n)}${V(r)}`;
486
570
  }, ie = (e, t, n) => {
487
571
  if (t === 0) {
488
572
  let e = Math.round(n * 255);
@@ -498,22 +582,22 @@ var ne = {
498
582
  Math.round((c + o) * 255),
499
583
  Math.round((l + o) * 255)
500
584
  ];
501
- }, ae = (e) => /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(e), z = (e) => {
585
+ }, ae = (e) => /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.test(e), U = (e) => {
502
586
  let t = e.trim().toLowerCase();
503
587
  if (t.startsWith("#") || /^[0-9a-f]{3}([0-9a-f]{3})?$/.test(t)) return ae(t) ? re(t) : void 0;
504
588
  if (t.startsWith("rgb")) {
505
589
  let e = t.match(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*[\d.]+\s*)?\)/);
506
- return e ? R(Number.parseInt(e[1], 10), Number.parseInt(e[2], 10), Number.parseInt(e[3], 10)) : void 0;
590
+ return e ? H(Number.parseInt(e[1], 10), Number.parseInt(e[2], 10), Number.parseInt(e[3], 10)) : void 0;
507
591
  }
508
592
  if (t.startsWith("hsl")) {
509
593
  let e = t.match(/hsla?\(\s*(\d+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%\s*(?:,\s*[\d.]+\s*)?\)/);
510
594
  if (!e) return;
511
595
  let [n, r, i] = ie(Number.parseInt(e[1], 10), Number.parseFloat(e[2]) / 100, Number.parseFloat(e[3]) / 100);
512
- return R(n, r, i);
596
+ return H(n, r, i);
513
597
  }
514
598
  let n = ne[t];
515
599
  if (n) return n;
516
- }, B = {
600
+ }, W = {
517
601
  svg: "svg",
518
602
  circle: "circle",
519
603
  desc: "desc",
@@ -524,98 +608,98 @@ var ne = {
524
608
  polygon: "polygon",
525
609
  polyline: "polyline",
526
610
  stop: "stop"
527
- }, V = {
611
+ }, G = {
528
612
  fill: "fill",
529
613
  stroke: "stroke"
530
614
  }, oe = {
531
615
  tiling: [
532
- B.circle,
533
- B.ellipse,
534
- B.rect,
535
- B.line,
536
- B.path,
537
- B.polygon,
538
- B.polyline,
539
- B.stop,
540
- `[${V.fill}]`,
541
- `[${V.stroke}]`
616
+ W.circle,
617
+ W.ellipse,
618
+ W.rect,
619
+ W.line,
620
+ W.path,
621
+ W.polygon,
622
+ W.polyline,
623
+ W.stop,
624
+ `[${G.fill}]`,
625
+ `[${G.stroke}]`
542
626
  ],
543
627
  nonTiling: [
544
- B.circle,
545
- B.desc,
546
- B.ellipse,
547
- B.rect,
548
- B.line,
549
- B.path,
550
- B.polygon,
551
- B.polyline,
552
- B.stop,
553
- `[${V.fill}]`,
554
- `[${V.stroke}]`
628
+ W.circle,
629
+ W.desc,
630
+ W.ellipse,
631
+ W.rect,
632
+ W.line,
633
+ W.path,
634
+ W.polygon,
635
+ W.polyline,
636
+ W.stop,
637
+ `[${G.fill}]`,
638
+ `[${G.stroke}]`
555
639
  ]
556
- }, se = (e) => Array.from(e.querySelectorAll(oe.tiling.map((e) => `*:not(clipPath) > ${e}`).join(", "))), H = (e) => {
557
- let t = e.getAttribute(V.stroke);
640
+ }, se = (e) => Array.from(e.querySelectorAll(oe.tiling.map((e) => `*:not(clipPath) > ${e}`).join(", "))), ce = (e) => {
641
+ let t = e.getAttribute(G.stroke);
558
642
  return t === "none" || !t ? !1 : t;
559
- }, U = (e) => {
560
- if (!(e === "none" || e === "transparent" || e.startsWith("url("))) return z(e);
561
- }, W = (e) => {
643
+ }, K = (e) => {
644
+ if (!(e === "none" || e === "transparent" || e.startsWith("url("))) return U(e);
645
+ }, le = (e) => {
562
646
  let t = se(e).reduce((e, t) => {
563
- let n = t.getAttribute("stop-color"), r = t.getAttribute(V.fill) || "#000", i = H(t);
647
+ let n = t.getAttribute("stop-color"), r = t.getAttribute(G.fill) || "#000", i = ce(t);
564
648
  if (r && !n) {
565
- let t = U(r);
649
+ let t = K(r);
566
650
  t && e.add(t);
567
651
  }
568
652
  if (n) {
569
- let t = U(n);
653
+ let t = K(n);
570
654
  t && e.add(t);
571
655
  }
572
656
  if (i) {
573
- let t = U(i);
657
+ let t = K(i);
574
658
  t && e.add(t);
575
659
  }
576
660
  return e;
577
661
  }, /* @__PURE__ */ new Set());
578
662
  return Array.from(t);
579
- }, G = (e) => {
580
- let t = new I().parseFromString(e, "image/svg+xml").querySelector("svg");
581
- return t ? W(t) : [];
663
+ }, ue = (e) => {
664
+ let t = new N().parseFromString(e, "image/svg+xml").querySelector("svg");
665
+ return t ? le(t) : [];
582
666
  };
583
667
  //#endregion
584
668
  //#region src/glyph/svg-glyph-converter.ts
585
- function K(e) {
669
+ function q(e) {
586
670
  let t = e.trim(), n = t.startsWith("<svg") || t.startsWith("<?xml"), r = n ? t : `<svg>${t}</svg>`;
587
671
  return {
588
- doc: new I().parseFromString(r, "image/svg+xml"),
672
+ doc: new N().parseFromString(r, "image/svg+xml"),
589
673
  wasWrapped: !n
590
674
  };
591
675
  }
592
- function q(e, t) {
676
+ function J(e, t) {
593
677
  let n = e.querySelector("svg");
594
678
  return n ? t ? n.innerHTML : n.outerHTML : "";
595
679
  }
596
- function ce(e) {
680
+ function de(e) {
597
681
  let { svgGlyphs: t } = e;
598
682
  if (!t || t.size === 0) return [];
599
683
  let n = /* @__PURE__ */ new Set();
600
- for (let [, e] of t) for (let t of G(e.svg)) n.add(t);
684
+ for (let [, e] of t) for (let t of ue(e.svg)) n.add(t);
601
685
  return Array.from(n);
602
686
  }
603
- function le(e) {
687
+ function fe(e) {
604
688
  return !!e && e !== "none" && e !== "transparent" && !e.startsWith("url(");
605
689
  }
606
- function ue(e) {
607
- let t = new I().parseFromString(e, "image/svg+xml").querySelector("svg");
690
+ function pe(e) {
691
+ let t = new N().parseFromString(e, "image/svg+xml").querySelector("svg");
608
692
  return t ? t.innerHTML.trim() : "";
609
693
  }
610
- var de = [
694
+ var me = [
611
695
  "fill",
612
696
  "stroke",
613
697
  "clip-path",
614
698
  "mask",
615
699
  "filter"
616
700
  ];
617
- function fe(e, t) {
618
- let { doc: n, wasWrapped: r } = K(e), i = /* @__PURE__ */ new Map();
701
+ function he(e, t) {
702
+ let { doc: n, wasWrapped: r } = q(e), i = /* @__PURE__ */ new Map();
619
703
  for (let e of n.querySelectorAll("[id]")) {
620
704
  let n = e.getAttribute("id");
621
705
  if (!n) continue;
@@ -623,7 +707,7 @@ function fe(e, t) {
623
707
  i.set(n, r), e.setAttribute("id", r);
624
708
  }
625
709
  if (i.size === 0) return e;
626
- for (let e of de) for (let t of n.querySelectorAll(`[${e}]`)) {
710
+ for (let e of me) for (let t of n.querySelectorAll(`[${e}]`)) {
627
711
  let n = t.getAttribute(e);
628
712
  if (n) {
629
713
  let r = n.replace(/url\(#([^)]+)\)/g, (e, t) => {
@@ -640,13 +724,13 @@ function fe(e, t) {
640
724
  a && e.setAttribute(t, `#${a}`);
641
725
  }
642
726
  }
643
- return q(n, r);
727
+ return J(n, r);
644
728
  }
645
- var pe = [
729
+ var ge = [
646
730
  "fill",
647
731
  "stroke",
648
732
  "stop-color"
649
- ], me = [
733
+ ], _e = [
650
734
  "path",
651
735
  "rect",
652
736
  "circle",
@@ -655,186 +739,347 @@ var pe = [
655
739
  "polyline",
656
740
  "text"
657
741
  ];
658
- function he(e, t) {
659
- let { doc: n, wasWrapped: r } = K(e), i = {};
660
- for (let [e, n] of Object.entries(t)) i[z(e) ?? e.toLowerCase()] = n;
661
- for (let e of pe) for (let t of n.querySelectorAll(`[${e}]`)) {
742
+ function ve(e, t) {
743
+ let { doc: n, wasWrapped: r } = q(e), i = {};
744
+ for (let [e, n] of Object.entries(t)) i[U(e) ?? e.toLowerCase()] = n;
745
+ for (let e of ge) for (let t of n.querySelectorAll(`[${e}]`)) {
662
746
  let n = t.getAttribute(e);
663
- if (!n || !le(n)) continue;
664
- let r = z(n), a = r ? i[r] : void 0;
747
+ if (!n || !fe(n)) continue;
748
+ let r = U(n), a = r ? i[r] : void 0;
665
749
  a && t.setAttribute(e, a.hex);
666
750
  }
667
751
  let a = i["#000000"];
668
752
  if (a) {
669
- let e = me.map((e) => `${e}:not([fill])`).join(", ");
753
+ let e = _e.map((e) => `${e}:not([fill])`).join(", ");
670
754
  for (let t of n.querySelectorAll(e)) t.setAttribute("fill", a.hex);
671
755
  }
672
- return q(n, r);
756
+ return J(n, r);
673
757
  }
674
758
  //#endregion
675
- //#region src/helpers/matrix.ts
676
- var ge = (e = [
677
- 1,
678
- 0,
679
- 0,
680
- 1,
681
- 0,
682
- 0
683
- ]) => {
684
- let t = new ee(`matrix(${e.join(",")})`);
685
- if (!t) throw Error("Your browser does not support matrices");
686
- return t;
687
- };
688
- //#endregion
689
759
  //#region src/helpers/xml.ts
690
- function _e(e) {
760
+ function ye(e) {
691
761
  return e.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/'/g, "&apos;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
692
762
  }
693
763
  //#endregion
694
764
  //#region src/rendering/index.ts
695
- var J = (e, t, n) => e / n * t, Y = ({ font: e, baselinePath: t, text: n, fontSize: r, spacing: i = T, horizontalAlignment: a = "centre", colourMap: s }) => {
696
- let { outlineWidth: c, letterSpacing: l, letterSpacingOutline: u } = i, d = new o(t), f = c ? r * c * 2 : 0, p = d.getTotalLength(), m = e.getPaths(n, 0, 0, r, { drawSVG: !1 }), h = e.getPath(n, 0, 0, r, { drawSVG: !1 }).getBoundingBox(), g = h.x1 - f / 2, _ = h.x2 + f / 2 - g, v = c > 0 ? u : l, y = v ? v * r : 0;
765
+ var Y = (e, t, n) => e / n * t, be = ({ font: e, baselinePath: t, text: n, fontSize: r, spacing: i = T, horizontalAlignment: a = "centre", colourMap: o }) => {
766
+ let { outlineWidth: s, letterSpacing: l, letterSpacingOutline: u } = i, d = new c(t), f = s ? r * s * 2 : 0, p = d.getTotalLength(), m = e.getPaths(n, 0, 0, r, { drawSVG: !1 }), h = e.getPath(n, 0, 0, r, { drawSVG: !1 }).getBoundingBox(), g = h.x1 - f / 2, _ = h.x2 + f / 2 - g, v = s > 0 ? u : l, y = v ? v * r : 0;
697
767
  a === "distributed" && (y = n.length === 1 ? 0 : (p - _) / (n.length - 1));
698
768
  let b = y * (n.length - 1), x = _ + b, S = 0 - g;
699
769
  a === "centre" ? S = (p - x) / 2 - g : a === "right" && (S = p - _ - g - b);
700
770
  let C = [];
701
771
  for (let t = 0; t < m.length; t++) {
702
- let i = m[t], a = i.getBoundingBox(), o = e.charToGlyph(n[t]), { advanceWidth: c } = o;
772
+ let i = m[t], a = i.getBoundingBox(), s = e.charToGlyph(n[t]), { advanceWidth: c } = s;
703
773
  if (!c) throw Error(`No advance width for character: ${n[t]} in font ${e.names.fontFamily}`);
704
- let { x1: l, x2: u } = o.getBoundingBox(), f = J(c, r, e.unitsPerEm), h = J(u - l, r, e.unitsPerEm), g = S + a.x1;
774
+ let { x1: l, x2: u } = s.getBoundingBox(), f = Y(c, r, e.unitsPerEm), h = Y(u - l, r, e.unitsPerEm), g = S + a.x1;
705
775
  if (t > 0 && (g += y * t), g + h > p) throw Error(`TOO_WIDE: character "${n[t]}" at index ${t} exceeds baseline path length (${Math.round(g + h)} > ${Math.round(p)})`);
706
- let _ = g + f / 2, v = d.getTangentAtLength(_), b = Math.atan2(v.y, v.x) * 180 / Math.PI, x = d.getPointAtLength(g), w = x.x, T = x.y, O = a.x2 - a.x1, k = new E(a.x1 + O / 2, 0), A = D(new E(a.x1, 0), b, k), j = w - A.X, M = T - A.Y, N = ge();
707
- N = N.translate(j, M);
708
- let P;
776
+ let _ = g + f / 2, v = d.getTangentAtLength(_), b = Math.atan2(v.y, v.x) * 180 / Math.PI, x = d.getPointAtLength(g), w = x.x, T = x.y, D = a.x2 - a.x1, O = new E(a.x1 + D / 2, 0), k = ee(new E(a.x1, 0), b, O), A = w - k.X, j = T - k.Y, M = new te();
777
+ M = M.translate(A, j);
778
+ let N;
709
779
  if (b) {
710
- let e = a.x1 + O / 2;
711
- N = N.translate(e, 0), N = N.rotate(b), N = N.translate(-e, 0), P = `translate(${j} ${M}) translate(${e} 0) rotate(${b}) translate(${-e} 0)`;
712
- } else P = `translate(${j} ${M})`;
713
- let F = i.toPathData(2);
714
- F.length && !F.endsWith("Z") && (F += "Z", F = F.replace(/M/g, "ZM"), F = F.substring(1));
715
- let I;
780
+ let e = a.x1 + D / 2;
781
+ M = M.translate(e, 0), M = M.rotate(b), M = M.translate(-e, 0), N = `translate(${A} ${j}) translate(${e} 0) rotate(${b}) translate(${-e} 0)`;
782
+ } else N = `translate(${A} ${j})`;
783
+ let P = i.toPathData(2);
784
+ P.length && !P.endsWith("Z") && (P += "Z", P = P.replace(/M/g, "ZM"), P = P.substring(1));
785
+ let F;
716
786
  if (e.svgGlyphs) {
717
- let n = e.svgGlyphs.get(o.index);
787
+ let n = e.svgGlyphs.get(s.index);
718
788
  if (n) {
719
- let e = ue(n.svg);
720
- e = fe(e, `g${o.index}-${t}`), s && (e = he(e, s)), I = {
789
+ let e = pe(n.svg);
790
+ e = he(e, `g${s.index}-${t}`), o && (e = ve(e, o)), F = {
721
791
  content: e,
722
792
  viewBox: n.viewbox,
723
793
  x: a.x1,
724
794
  y: a.y1,
725
795
  width: a.x2 - a.x1,
726
796
  height: a.y2 - a.y1,
727
- glyphIndex: o.index
797
+ glyphIndex: s.index
728
798
  };
729
799
  }
730
800
  }
731
801
  C.push({
732
802
  path: i,
733
- matrix: N,
803
+ matrix: M,
734
804
  attributes: {
735
- d: F,
736
- "data-character": _e(n[t]),
737
- transform: P
805
+ d: P,
806
+ "data-character": ye(n[t]),
807
+ transform: N
738
808
  },
739
809
  glyphData: {
740
- index: o.index,
810
+ index: s.index,
741
811
  bbox: a
742
812
  },
743
- ...I ? { svgGlyph: I } : {}
813
+ ...F ? { svgGlyph: F } : {}
744
814
  });
745
815
  }
746
816
  return C;
747
- }, X = { hex: "#FFFFFF" }, Z = (e, t) => {
748
- let n = `data-${e}-colour-url`, r = [`${e}="${t.hex}"`];
749
- return t.reference && r.push(`${n}="${t.reference}"`), r.join(" ");
750
- }, Q = (e, t) => {
751
- let { attributes: n, svgGlyph: r } = e;
752
- return r ? `<g transform="${n.transform}" data-character="${n["data-character"]}"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="${r.viewBox}" width="${r.width}" height="${r.height}" x="${r.x}" y="${r.y}" data-glyph-index="${r.glyphIndex}">${r.content}</svg></g>` : `<path d="${n.d}" ${Z("fill", t)} transform="${n.transform}" data-character="${n["data-character"]}"/>`;
753
- }, ve = ({ boxDimensions: e, paths: t, spacing: n = T, fontSize: r = 0, fillColour: i = X, strokeColour: a = X }) => {
754
- let { width: o, height: s } = e, { outlineWidth: c } = n, l = c > 0 && r > 0, u;
755
- if (l) {
756
- let e = r * c * 2;
757
- u = `${t.filter((e) => !e.svgGlyph).map(({ attributes: t }) => `<path d="${t.d}" ${Z("fill", a)} ${Z("stroke", a)} stroke-width="${e}" stroke-linejoin="round" transform="${t.transform}" data-character="${t["data-character"]}"/>`).join("\n ")}\n ${t.map((e) => Q(e, i)).join("\n ")}`;
758
- } else u = t.map((e) => Q(e, i)).join("\n ");
759
- return `<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${s}" viewBox="0 0 ${o} ${s}">${u ? `\n ${u}\n` : ""}</svg>`;
760
- }, $ = (e) => {
761
- let { text: t, font: n, physicalSize: r, fontSize: i, boxDimensions: a, spacing: o = T, verticalAlignment: s = "centre", baseline: c = "flat", horizontalAlignment: l = "left", fillColour: u = { hex: "#FFFFFF" }, strokeColour: d = { hex: "#FFFFFF" }, colourMap: f } = e, { width: p, height: m, physicalWidth: h, physicalHeight: g } = a;
762
- if (p <= 0 || m <= 0) throw Error(`boxDimensions width and height must be positive (got ${p}x${m})`);
763
- if (h <= 0 || g <= 0) throw Error(`boxDimensions physicalWidth and physicalHeight must be positive (got ${h}x${g})`);
764
- if (r[0] <= 0) throw Error(`physicalSize height must be positive (got ${r[0]})`);
765
- let _ = i ?? P({
766
- font: n,
767
- boxDimensions: a,
768
- physicalSize: r,
817
+ }, X = (e) => {
818
+ let { font: t, text: n, boxDimensions: r, physicalSize: i, fontSize: a, spacing: o = T, baseline: s = "flat", horizontalAlignment: c = "left", verticalAlignment: l = "centre", colourMap: u } = e, { width: d, height: f, physicalWidth: p, physicalHeight: m } = r;
819
+ if (d <= 0 || f <= 0) throw Error(`boxDimensions width and height must be positive (got ${d}x${f})`);
820
+ if (p <= 0 || m <= 0) throw Error(`boxDimensions physicalWidth and physicalHeight must be positive (got ${p}x${m})`);
821
+ if (i[0] <= 0) throw Error(`physicalSize height must be positive (got ${i[0]})`);
822
+ let h = a ?? z({
823
+ font: t,
824
+ boxDimensions: r,
825
+ physicalSize: i,
769
826
  spacing: o
770
- }), v = O(c), y = t.split("\n").filter((e) => e.length > 0);
771
- y.length || (y = [""]), (v.type === "curved" || v.type === "custom") && (y = [y.join("")]);
772
- let b = y.map((e) => F({
773
- font: n,
827
+ }), g = D(s), _ = n.split("\n").filter((e) => e.length > 0);
828
+ _.length || (_ = [""]), (g.type === "curved" || g.type === "custom") && (_ = [_.join("")]);
829
+ let v = _.map((e) => B({
830
+ font: t,
774
831
  text: e,
775
- fontSize: _,
832
+ fontSize: h,
776
833
  spacing: o
777
- })), x = Math.max(...b.map((e) => e.baseline)), S = x + Math.max(...b.map((e) => e.height - e.baseline)), w = y.length === 1 ? S : S + S * (y.length - 1) * C, E = [];
778
- for (let e = 0; e < y.length; e++) {
779
- let t;
780
- switch (v.type) {
834
+ })), y = Math.max(...v.map((e) => e.baseline)), b = y + Math.max(...v.map((e) => e.height - e.baseline)), x = _.length === 1 ? b : b + b * (_.length - 1) * C, S = [];
835
+ for (let e = 0; e < _.length; e++) {
836
+ let n;
837
+ switch (g.type) {
781
838
  case "custom":
782
- k(v.path), t = v.path;
839
+ O(g.path), n = g.path;
783
840
  break;
784
841
  case "curved": {
785
- let e = F({
786
- font: n,
787
- text: M(n),
788
- fontSize: _,
842
+ let e = B({
843
+ font: t,
844
+ text: L(t),
845
+ fontSize: h,
789
846
  spacing: o
790
847
  });
791
- t = j({
792
- boxDimensions: a,
848
+ n = j({
849
+ boxDimensions: r,
793
850
  baseline: e.baseline,
794
851
  textHeight: e.height,
795
- verticalAlignment: s
852
+ verticalAlignment: l
796
853
  });
797
854
  break;
798
855
  }
799
- case "flat":
800
- t = A({
801
- boxDimensions: a,
802
- totalTextHeight: w,
803
- baseline: x,
804
- lineHeight: S,
805
- verticalAlignment: s,
806
- lineNumber: e
807
- });
808
- break;
856
+ case "flat": n = k({
857
+ boxDimensions: r,
858
+ totalTextHeight: x,
859
+ baseline: y,
860
+ lineHeight: b,
861
+ verticalAlignment: l,
862
+ lineNumber: e
863
+ });
809
864
  }
810
- let r = Y({
811
- font: n,
812
- baselinePath: t,
813
- text: y[e],
814
- fontSize: _,
865
+ S.push(...be({
866
+ font: t,
867
+ baselinePath: n,
868
+ text: _[e],
869
+ fontSize: h,
815
870
  spacing: o,
816
- horizontalAlignment: l,
817
- colourMap: f
818
- });
819
- E.push(...r);
871
+ horizontalAlignment: c,
872
+ colourMap: u
873
+ }));
820
874
  }
821
- return ve({
822
- boxDimensions: a,
823
- paths: E,
875
+ return {
876
+ fontSize: h,
877
+ lines: _,
878
+ paths: S,
824
879
  spacing: o,
825
- fontSize: _,
826
- fillColour: u,
827
- strokeColour: d
880
+ tallestHeight: b,
881
+ totalHeight: x,
882
+ maxBaseline: y
883
+ };
884
+ }, xe = (e) => {
885
+ let { font: t, boxDimensions: n, spacing: r = T } = e, { fontSize: i, paths: a, lines: o } = X(e), s = null;
886
+ for (let e of a) {
887
+ let { x1: t, y1: n, x2: r, y2: i } = e.glyphData.bbox, a = new I(t, n, r, i);
888
+ a.transform(e.matrix), s ? s.add(a) : s = a.getBBox();
889
+ }
890
+ if (s && r.outlineWidth > 0) {
891
+ let e = i * r.outlineWidth;
892
+ s = new I(s.x1 - e, s.y1 - e, s.x2 + e, s.y2 + e);
893
+ }
894
+ let c = s ?? new I(0, 0, 0, 0), l = (e) => e / n.width * n.physicalWidth, u = (e) => e / n.height * n.physicalHeight, d = B({
895
+ font: t,
896
+ text: L(t),
897
+ fontSize: i,
898
+ spacing: r
828
899
  });
829
- }, ye = async (e) => {
900
+ return {
901
+ fontSize: i,
902
+ bbox: {
903
+ x: c.x,
904
+ y: c.y,
905
+ width: c.width,
906
+ height: c.height
907
+ },
908
+ physicalWidth: l(c.width),
909
+ physicalHeight: u(c.height),
910
+ physicalUnits: n.physicalUnits,
911
+ physicalCapHeight: u(d.height),
912
+ lines: o.map((e) => {
913
+ let n = B({
914
+ font: t,
915
+ text: e,
916
+ fontSize: i,
917
+ spacing: r
918
+ });
919
+ return {
920
+ text: e,
921
+ width: n.width,
922
+ height: n.height,
923
+ baseline: n.baseline
924
+ };
925
+ })
926
+ };
927
+ }, Se = { hex: "#FFFFFF" }, Z = (e, t) => {
928
+ let n = `data-${e}-colour-url`, r = [`${e}="${t.hex}"`];
929
+ return t.reference && r.push(`${n}="${t.reference}"`), r.join(" ");
930
+ }, Ce = (e, t) => {
931
+ let { attributes: n, svgGlyph: r } = e;
932
+ return r ? `<g transform="${n.transform}" data-character="${n["data-character"]}"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="${r.viewBox}" width="${r.width}" height="${r.height}" x="${r.x}" y="${r.y}" data-glyph-index="${r.glyphIndex}">${r.content}</svg></g>` : `<path d="${n.d}" ${Z("fill", t)} transform="${n.transform}" data-character="${n["data-character"]}"/>`;
933
+ }, we = ({ boxDimensions: e, paths: t, spacing: n = T, fontSize: r = 0, fillColour: i = Se, strokeColour: a = Se }) => {
934
+ let { width: o, height: s } = e, { outlineWidth: c } = n, l = c > 0 && r > 0, u;
935
+ if (l) {
936
+ let e = r * c * 2;
937
+ u = `${t.filter((e) => !e.svgGlyph).map(({ attributes: t }) => `<path d="${t.d}" ${Z("fill", a)} ${Z("stroke", a)} stroke-width="${e}" stroke-linejoin="round" transform="${t.transform}" data-character="${t["data-character"]}"/>`).join("\n ")}\n ${t.map((e) => Ce(e, i)).join("\n ")}`;
938
+ } else u = t.map((e) => Ce(e, i)).join("\n ");
939
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${s}" viewBox="0 0 ${o} ${s}">${u ? `\n ${u}\n` : ""}</svg>`;
940
+ }, Q = (e) => {
941
+ let { boxDimensions: t, fillColour: n = { hex: "#FFFFFF" }, strokeColour: r = { hex: "#FFFFFF" } } = e, { fontSize: i, paths: a, spacing: o } = X(e);
942
+ return we({
943
+ boxDimensions: t,
944
+ paths: a,
945
+ spacing: o,
946
+ fontSize: i,
947
+ fillColour: n,
948
+ strokeColour: r
949
+ });
950
+ }, Te = 100, Ee = (e) => {
951
+ let t = e.split("\n").filter((e) => e.length > 0);
952
+ return t.length ? t : [""];
953
+ }, De = (e) => e.split("\n").filter((e) => e.length > 0).join(""), Oe = (e, t, n, r, i, a) => {
954
+ let o = B({
955
+ font: e,
956
+ text: L(e),
957
+ fontSize: n,
958
+ spacing: r
959
+ }), s = {
960
+ boxDimensions: i,
961
+ baseline: o.baseline,
962
+ textHeight: o.height,
963
+ verticalAlignment: a
964
+ }, l = new c(j(s)).getTotalLength(), { curveTop: u, curveBottom: d } = A(s), f = B({
965
+ font: e,
966
+ text: t,
967
+ fontSize: n,
968
+ spacing: r
969
+ }), p = u - f.baseline, m = d + (f.height - f.baseline);
970
+ return {
971
+ width: f.width <= l,
972
+ height: p >= 0 && m <= i.height
973
+ };
974
+ }, $ = (e) => e.width && e.height, ke = (e) => e.width ? "height" : "width", Ae = .01, je = 60, Me = ({ font: e, text: t, boxDimensions: n, spacing: r, verticalAlignment: i, minFontSize: a, maxFontSize: o }) => {
975
+ let s = De(t);
976
+ if (!s.length) return {
977
+ fontSize: o,
978
+ fits: !0,
979
+ boundBy: "requestedSize"
980
+ };
981
+ let c = (t) => Oe(e, s, t, r, n, i), l = c(a);
982
+ if (!$(l)) return {
983
+ fontSize: a,
984
+ fits: !1,
985
+ boundBy: ke(l)
986
+ };
987
+ if ($(c(o))) return {
988
+ fontSize: o,
989
+ fits: !0,
990
+ boundBy: "requestedSize"
991
+ };
992
+ let u = a, d = o, f = 0;
993
+ for (; d - u > Ae && f < je;) {
994
+ let e = (u + d) / 2;
995
+ $(c(e)) ? u = e : d = e, f++;
996
+ }
997
+ return {
998
+ fontSize: u,
999
+ fits: !0,
1000
+ boundBy: ke(c(d))
1001
+ };
1002
+ }, Ne = (e) => {
1003
+ let { font: t, text: n, boxDimensions: r, size: i, spacing: a = T, baseline: o = "flat", verticalAlignment: s = "centre" } = e, l = i.mode === "fitToBox" ? i.maxFontSize : i.mode === "fontSize" ? i.fontSize : z({
1004
+ font: t,
1005
+ boxDimensions: r,
1006
+ physicalSize: i.physicalSize,
1007
+ spacing: a
1008
+ });
1009
+ if (!n.length) return {
1010
+ fontSize: l,
1011
+ fits: !0,
1012
+ boundBy: "requestedSize"
1013
+ };
1014
+ let u = D(o);
1015
+ if (u.type === "curved") return Me({
1016
+ font: t,
1017
+ text: n,
1018
+ boxDimensions: r,
1019
+ spacing: a,
1020
+ verticalAlignment: s,
1021
+ minFontSize: i.mode === "fitToBox" ? i.minFontSize : l,
1022
+ maxFontSize: l
1023
+ });
1024
+ let d = Ee(n);
1025
+ u.type === "custom" && (d = [d.join("")]);
1026
+ let f = d.map((e) => B({
1027
+ font: t,
1028
+ text: e,
1029
+ fontSize: Te,
1030
+ spacing: a
1031
+ })), p = Math.max(...f.map((e) => e.baseline)) + Math.max(...f.map((e) => e.height - e.baseline)), m = d.length === 1 ? p : p + p * (d.length - 1) * C, h = Math.max(...f.map((e) => e.width)), g = (u.type === "custom" ? new c(u.path).getTotalLength() : r.width) / h, _ = r.height / m, v = g <= _ ? "width" : "height", y = Te * Math.min(g, _);
1032
+ return i.mode === "fitToBox" ? y < i.minFontSize ? {
1033
+ fontSize: i.minFontSize,
1034
+ fits: !1,
1035
+ boundBy: v
1036
+ } : y > i.maxFontSize ? {
1037
+ fontSize: i.maxFontSize,
1038
+ fits: !0,
1039
+ boundBy: "requestedSize"
1040
+ } : {
1041
+ fontSize: y,
1042
+ fits: !0,
1043
+ boundBy: v
1044
+ } : l <= y ? {
1045
+ fontSize: l,
1046
+ fits: !0,
1047
+ boundBy: "requestedSize"
1048
+ } : {
1049
+ fontSize: l,
1050
+ fits: !1,
1051
+ boundBy: v
1052
+ };
1053
+ }, Pe = (e) => {
1054
+ let t = e.text, n = t, r = 0, i = 0;
1055
+ for (;;) {
1056
+ let a = Ne({
1057
+ ...e,
1058
+ text: n
1059
+ });
1060
+ if (a.fits) return {
1061
+ ...a,
1062
+ text: n,
1063
+ truncated: n !== t,
1064
+ linesDropped: r,
1065
+ charactersRemoved: i
1066
+ };
1067
+ let o = n.split("\n");
1068
+ if (o.length > 1) n = o.slice(0, -1).join("\n"), r += 1;
1069
+ else {
1070
+ let e = n.slice(0, -1).trim();
1071
+ i += n.length - e.length, n = e;
1072
+ }
1073
+ }
1074
+ }, Fe = async (e) => {
830
1075
  let { fontUrl: t, fontSizeFallback: n, ...r } = e, i = await x(t, !!r.colourMap);
831
1076
  try {
832
- return $({
1077
+ return Q({
833
1078
  ...r,
834
1079
  font: i
835
1080
  });
836
1081
  } catch (e) {
837
- if (n != null && e instanceof Error && e.message.startsWith("TOO_WIDE")) return $({
1082
+ if (n != null && e instanceof Error && e.message.startsWith("TOO_WIDE")) return Q({
838
1083
  ...r,
839
1084
  font: i,
840
1085
  fontSize: n
@@ -843,4 +1088,4 @@ var J = (e, t, n) => e / n * t, Y = ({ font: e, baselinePath: t, text: n, fontSi
843
1088
  }
844
1089
  };
845
1090
  //#endregion
846
- export { S as DEFAULT_OUTLINE_FACTOR, T as DEFAULT_SPACING, C as LINE_HEIGHT, j as generateCurvedBaseline, A as generateFlatBaseline, p as getFontCache, ce as getFontColours, P as getFontSizeFromPhysicalSize, ye as getRenderedText, F as getTextMetricsAtFontSize, x as loadFont, O as normaliseBaselineOption, $ as renderText, k as validateCustomBaselinePath };
1091
+ export { S as DEFAULT_OUTLINE_FACTOR, T as DEFAULT_SPACING, C as LINE_HEIGHT, Pe as fitAndTruncateTextToBox, j as generateCurvedBaseline, k as generateFlatBaseline, p as getFontCache, de as getFontColours, z as getFontSizeFromPhysicalSize, Ne as getFontSizeToFitBox, Fe as getRenderedText, B as getTextMetricsAtFontSize, X as layoutText, x as loadFont, xe as measureText, D as normaliseBaselineOption, Q as renderText, O as validateCustomBaselinePath };