@unmade/text-renderer 0.3.0 → 1.0.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.
package/dist/index.d.ts CHANGED
@@ -185,7 +185,7 @@ export declare interface LoadedFont {
185
185
  }>;
186
186
  }
187
187
 
188
- export declare const loadOpentypeFont: (fontUrl: string, fetchSVGGlyphs?: boolean) => Promise<LoadedFont>;
188
+ export declare const loadFont: (fontUrl: string, fetchSVGGlyphs?: boolean) => Promise<LoadedFont>;
189
189
 
190
190
  export declare type MeasurementUnits = 'mm' | 'in';
191
191
 
package/dist/index.js CHANGED
@@ -1986,7 +1986,7 @@ export {
1986
1986
  wI as getFontSizeFromPhysicalSize,
1987
1987
  lI as getRenderedText,
1988
1988
  PA as getTextMetricsAtFontSize,
1989
- gI as loadOpentypeFont,
1989
+ gI as loadFont,
1990
1990
  CI as normaliseBaselineOption,
1991
1991
  Ag as renderText,
1992
1992
  EI as validateCustomBaselinePath
@@ -185,7 +185,7 @@ export declare interface LoadedFont {
185
185
  }>;
186
186
  }
187
187
 
188
- export declare const loadOpentypeFont: (fontUrl: string, fetchSVGGlyphs?: boolean) => Promise<LoadedFont>;
188
+ export declare const loadFont: (fontUrl: string, fetchSVGGlyphs?: boolean) => Promise<LoadedFont>;
189
189
 
190
190
  export declare type MeasurementUnits = 'mm' | 'in';
191
191
 
@@ -202,7 +202,7 @@ async function at(e, t, n) {
202
202
  return o;
203
203
  }
204
204
  const Gt = 2001684038;
205
- async function Ot(e) {
205
+ async function Dt(e) {
206
206
  return e.byteLength >= 4 && new DataView(e).getUint32(0) === Gt ? Wt(e) : e;
207
207
  }
208
208
  async function it(e) {
@@ -212,9 +212,9 @@ async function it(e) {
212
212
  `Failed to load font from ${e}: ${t.status} ${t.statusText}`
213
213
  );
214
214
  const n = await t.arrayBuffer();
215
- return Ot(n);
215
+ return Dt(n);
216
216
  }
217
- const Dt = async (e, t = !1) => {
217
+ const Ot = async (e, t = !1) => {
218
218
  const n = X.get(e);
219
219
  if (n) {
220
220
  if (t && !n.svgGlyphs) {
@@ -555,7 +555,7 @@ const Qt = {
555
555
  polygon: "polygon",
556
556
  polyline: "polyline",
557
557
  stop: "stop"
558
- }, D = {
558
+ }, O = {
559
559
  fill: "fill",
560
560
  stroke: "stroke"
561
561
  }, te = {
@@ -568,15 +568,15 @@ const Qt = {
568
568
  L.polygon,
569
569
  L.polyline,
570
570
  L.stop,
571
- `[${D.fill}]`,
572
- `[${D.stroke}]`
571
+ `[${O.fill}]`,
572
+ `[${O.stroke}]`
573
573
  ]
574
574
  }, ee = (e) => Array.from(
575
575
  e.querySelectorAll(
576
576
  te.tiling.map((t) => `*:not(clipPath) > ${t}`).join(", ")
577
577
  )
578
578
  ), ne = (e) => {
579
- const t = e.getAttribute(D.stroke);
579
+ const t = e.getAttribute(O.stroke);
580
580
  return t === "none" || !t ? !1 : t;
581
581
  }, j = (e) => {
582
582
  if (!(e === "none" || e === "transparent" || e.startsWith("url(")))
@@ -584,7 +584,7 @@ const Qt = {
584
584
  }, oe = (e) => {
585
585
  const t = ee(e).reduce(
586
586
  (n, o) => {
587
- const a = o.getAttribute("stop-color"), c = o.getAttribute(D.fill) || "#000", f = ne(o);
587
+ const a = o.getAttribute("stop-color"), c = o.getAttribute(O.fill) || "#000", f = ne(o);
588
588
  if (!a) {
589
589
  const s = j(c);
590
590
  s && n.add(s);
@@ -724,17 +724,17 @@ const ft = (e, t, n) => e / n * t, ue = ({
724
724
  throw new Error(
725
725
  `TOO_WIDE: character "${n[v]}" at index ${v} exceeds baseline path length (${Math.round(I + Y)} > ${Math.round(u)})`
726
726
  );
727
- const St = I + $t / 2, J = l.getTangentAtLength(St), O = 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(
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
728
  new F(x.x1, 0),
729
- O,
729
+ D,
730
730
  Ft
731
731
  ), _ = kt - et.X, V = Mt - et.Y;
732
732
  let M = de();
733
733
  M = M.translate(_, V);
734
734
  let q;
735
- if (O) {
735
+ if (D) {
736
736
  const T = x.x1 + tt / 2;
737
- M = M.translate(T, 0), M = M.rotate(O), M = M.translate(-T, 0), q = `translate(${_} ${V}) translate(${T} 0) rotate(${O}) translate(${-T} 0)`;
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)`;
738
738
  } else
739
739
  q = `translate(${_} ${V})`;
740
740
  let P = y.toPathData(2);
@@ -893,7 +893,7 @@ const ft = (e, t, n) => e / n * t, ue = ({
893
893
  strokeColour: p
894
894
  });
895
895
  }, Se = async (e) => {
896
- const { fontUrl: t, fontSizeFallback: n, ...o } = e, a = !!o.colourMap, c = await Dt(t, a);
896
+ const { fontUrl: t, fontSizeFallback: n, ...o } = e, a = !!o.colourMap, c = await Ot(t, a);
897
897
  try {
898
898
  return gt({ ...o, font: c });
899
899
  } catch (f) {
@@ -913,7 +913,7 @@ export {
913
913
  Rt as getFontSizeFromPhysicalSize,
914
914
  Se as getRenderedText,
915
915
  ct as getTextMetricsAtFontSize,
916
- Dt as loadOpentypeFont,
916
+ Ot as loadFont,
917
917
  qt as normaliseBaselineOption,
918
918
  gt as renderText,
919
919
  Ht as validateCustomBaselinePath
@@ -185,7 +185,7 @@ export declare interface LoadedFont {
185
185
  }>;
186
186
  }
187
187
 
188
- export declare const loadOpentypeFont: (fontUrl: string, fetchSVGGlyphs?: boolean) => Promise<LoadedFont>;
188
+ export declare const loadFont: (fontUrl: string, fetchSVGGlyphs?: boolean) => Promise<LoadedFont>;
189
189
 
190
190
  export declare type MeasurementUnits = 'mm' | 'in';
191
191
 
@@ -9714,7 +9714,7 @@ export {
9714
9714
  Ce as getFontSizeFromPhysicalSize,
9715
9715
  jh as getRenderedText,
9716
9716
  ZQ as getTextMetricsAtFontSize,
9717
- zi as loadOpentypeFont,
9717
+ zi as loadFont,
9718
9718
  Ie as normaliseBaselineOption,
9719
9719
  _C as renderText,
9720
9720
  Be as validateCustomBaselinePath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unmade/text-renderer",
3
- "version": "0.3.0",
3
+ "version": "1.0.0",
4
4
  "description": "Pure function text renderer for SVG output",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",