textmode.js 0.2.0-beta.5 → 0.2.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,9 +1,9 @@
1
1
  var K = Object.defineProperty;
2
2
  var q = (a, t, e) => t in a ? K(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
3
3
  var c = (a, t, e) => q(a, typeof t != "symbol" ? t + "" : t, e);
4
- class S extends Error {
4
+ class _ extends Error {
5
5
  constructor(t, e = {}) {
6
- super(S.i(t, e)), this.name = "TextmodeError";
6
+ super(_.i(t, e)), this.name = "TextmodeError";
7
7
  }
8
8
  static i(t, e) {
9
9
  let r = t;
@@ -13,7 +13,7 @@ class S extends Error {
13
13
  📋 Context:`;
14
14
  for (const [i, s] of Object.entries(e))
15
15
  r += `
16
- - ${i}: ${S.o(s)}`;
16
+ - ${i}: ${_.o(s)}`;
17
17
  }
18
18
  return r += `
19
19
 
@@ -25,10 +25,10 @@ class S extends Error {
25
25
  if (t === void 0) return "undefined";
26
26
  if (typeof t == "string") return `"${t}"`;
27
27
  if (typeof t == "number" || typeof t == "boolean") return t + "";
28
- if (Array.isArray(t)) return t.length === 0 ? "[]" : t.length <= 5 ? `[${t.map((e) => S.o(e)).join(", ")}]` : `[${t.slice(0, 3).map((e) => S.o(e)).join(", ")}, ... +${t.length - 3} more]`;
28
+ if (Array.isArray(t)) return t.length === 0 ? "[]" : t.length <= 5 ? `[${t.map((e) => _.o(e)).join(", ")}]` : `[${t.slice(0, 3).map((e) => _.o(e)).join(", ")}, ... +${t.length - 3} more]`;
29
29
  if (typeof t == "object") {
30
30
  const e = Object.keys(t);
31
- return e.length === 0 ? "{}" : e.length <= 3 ? `{ ${e.map((r) => `${r}: ${S.o(t[r])}`).join(", ")} }` : `{ ${e.slice(0, 2).map((r) => `${r}: ${S.o(t[r])}`).join(", ")}, ... +${e.length - 2} more }`;
31
+ return e.length === 0 ? "{}" : e.length <= 3 ? `{ ${e.map((r) => `${r}: ${_.o(t[r])}`).join(", ")} }` : `{ ${e.slice(0, 2).map((r) => `${r}: ${_.o(t[r])}`).join(", ")}, ... +${e.length - 2} more }`;
32
32
  }
33
33
  return t + "";
34
34
  }
@@ -47,11 +47,11 @@ const A = class A {
47
47
  case 0:
48
48
  return !1;
49
49
  case 1:
50
- return console.group(r, i), console.warn(S.i(t, e)), console.groupEnd(), !1;
50
+ return console.group(r, i), console.warn(_.i(t, e)), console.groupEnd(), !1;
51
51
  case 2:
52
- return console.group(r, i), console.error(S.i(t, e)), console.groupEnd(), !1;
52
+ return console.group(r, i), console.error(_.i(t, e)), console.groupEnd(), !1;
53
53
  default:
54
- throw new S(t, e);
54
+ throw new _(t, e);
55
55
  }
56
56
  }
57
57
  m(t, e, r) {
@@ -429,8 +429,8 @@ class rt {
429
429
  p.tt(), p.st({ u_src0: f.textures[0], u_src1: f.textures[1], u_src2: f.textures[2], u_src3: f.textures[3], u_src4: f.textures[4], u_srcSize: [f.width, f.height] });
430
430
  const m = U(u) || u.getParameter(u.VIEWPORT);
431
431
  p.rt("u_aspectRatio") && p.it("u_aspectRatio", m[2] / m[3]), p.rt("u_viewportSize") && p.it("u_viewportSize", [m[2], m[3]]);
432
- const E = Math.floor(s), v = Math.floor(n), _ = Math.max(1, Math.floor(o)), b = Math.max(1, Math.floor(h));
433
- if (i.Kt({ x: E, y: v, width: _, height: b }, r), i.Yt()) {
432
+ const R = Math.floor(s), v = Math.floor(n), E = Math.max(1, Math.floor(o)), b = Math.max(1, Math.floor(h));
433
+ if (i.Kt({ x: R, y: v, width: E, height: b }, r), i.Yt()) {
434
434
  const y = i.unitGeometry, P = i.unitBuffer;
435
435
  try {
436
436
  this.Vt.kt(p.ot, i.type + "", y, P), i.batch.qt(p), i.batch.Zt(y.primitiveType, y.vertexCount);
@@ -859,13 +859,13 @@ class xt {
859
859
  for (const t of this.ke.values()) t.j();
860
860
  }
861
861
  }
862
- const R = { readShort: (a, t) => (R.t.uint16[0] = a[t] << 8 | a[t + 1], R.t.int16[0]), readUshort: (a, t) => a[t] << 8 | a[t + 1], readUshorts(a, t, e) {
862
+ const S = { readShort: (a, t) => (S.t.uint16[0] = a[t] << 8 | a[t + 1], S.t.int16[0]), readUshort: (a, t) => a[t] << 8 | a[t + 1], readUshorts(a, t, e) {
863
863
  const r = [];
864
- for (let i = 0; i < e; i++) r.push(R.readUshort(a, t + 2 * i));
864
+ for (let i = 0; i < e; i++) r.push(S.readUshort(a, t + 2 * i));
865
865
  return r;
866
866
  }, readUint(a, t) {
867
- const e = R.t.uint8;
868
- return e[3] = a[t], e[2] = a[t + 1], e[1] = a[t + 2], e[0] = a[t + 3], R.t.uint32[0];
867
+ const e = S.t.uint8;
868
+ return e[3] = a[t], e[2] = a[t + 1], e[1] = a[t + 2], e[0] = a[t + 3], S.t.uint32[0];
869
869
  }, readASCII(a, t, e) {
870
870
  let r = "";
871
871
  for (let i = 0; i < e; i++) r += String.fromCharCode(a[t + i]);
@@ -876,7 +876,7 @@ const R = { readShort: (a, t) => (R.t.uint16[0] = a[t] << 8 | a[t + 1], R.t.int1
876
876
  })() }, yt = { parseTab(a, t, e) {
877
877
  const r = { tables: [], ids: {}, off: t };
878
878
  a = new Uint8Array(a.buffer, t, e), t = 0;
879
- const i = R, s = i.readUshort, n = s(a, t += 2);
879
+ const i = S, s = i.readUshort, n = s(a, t += 2);
880
880
  t += 2;
881
881
  const o = [];
882
882
  for (let h = 0; h < n; h++) {
@@ -896,14 +896,14 @@ const R = { readShort: (a, t) => (R.t.uint16[0] = a[t] << 8 | a[t + 1], R.t.int1
896
896
  }
897
897
  return r;
898
898
  }, parse4(a, t) {
899
- const e = R, r = e.readUshort, i = e.readUshorts, s = t, n = r(a, t += 2);
899
+ const e = S, r = e.readUshort, i = e.readUshorts, s = t, n = r(a, t += 2);
900
900
  t += 2;
901
901
  const o = r(a, t += 2) >>> 1, h = { format: 4, searchRange: r(a, t += 2), entrySelector: 0, rangeShift: 0, endCount: [], startCount: [], idDelta: [], idRangeOffset: [], glyphIdArray: [] };
902
902
  t += 2, h.entrySelector = r(a, t), t += 2, h.rangeShift = r(a, t), t += 2, h.endCount = i(a, t, o), t += 2 * o, t += 2, h.startCount = i(a, t, o), t += 2 * o;
903
903
  for (let l = 0; l < o; l++) h.idDelta.push(e.readShort(a, t)), t += 2;
904
904
  return h.idRangeOffset = i(a, t, o), t += 2 * o, h.glyphIdArray = i(a, t, s + n - t >> 1), h;
905
905
  }, parse12(a, t) {
906
- const e = R.readUint;
906
+ const e = S.readUint;
907
907
  e(a, t += 4), e(a, t += 4);
908
908
  const r = e(a, t += 4);
909
909
  t += 4;
@@ -911,7 +911,7 @@ const R = { readShort: (a, t) => (R.t.uint16[0] = a[t] << 8 | a[t + 1], R.t.int1
911
911
  for (let s = 0; s < 3 * r; s += 3) i[s] = e(a, t + (s << 2)), i[s + 1] = e(a, t + (s << 2) + 4), i[s + 2] = e(a, t + (s << 2) + 8);
912
912
  return { format: 12, groups: i };
913
913
  } }, Ct = { parseTab(a, t, e) {
914
- const r = R;
914
+ const r = S;
915
915
  t += 18;
916
916
  const i = r.readUshort(a, t);
917
917
  t += 2, t += 16;
@@ -924,7 +924,7 @@ const R = { readShort: (a, t) => (R.t.uint16[0] = a[t] << 8 | a[t + 1], R.t.int1
924
924
  const h = r.readShort(a, t);
925
925
  return t += 2, t += 6, { unitsPerEm: i, xMin: s, yMin: n, xMax: o, yMax: h, indexToLocFormat: r.readShort(a, t) };
926
926
  } }, vt = { parseTab(a, t, e) {
927
- const r = R;
927
+ const r = S;
928
928
  t += 4;
929
929
  const i = ["ascender", "descender", "lineGap", "advanceWidthMax", "minLeftSideBearing", "minRightSideBearing", "xMaxExtent", "caretSlopeRise", "caretSlopeRun", "caretOffset", "res0", "res1", "res2", "res3", "metricDataFormat", "numberOfHMetrics"], s = {};
930
930
  for (let n = 0; n < i.length; n++) {
@@ -933,16 +933,16 @@ const R = { readShort: (a, t) => (R.t.uint16[0] = a[t] << 8 | a[t + 1], R.t.int1
933
933
  }
934
934
  return s;
935
935
  } }, St = { parseTab(a, t, e, r) {
936
- const i = R, s = [], n = [], o = r.maxp.numGlyphs, h = r.hhea.numberOfHMetrics;
936
+ const i = S, s = [], n = [], o = r.maxp.numGlyphs, h = r.hhea.numberOfHMetrics;
937
937
  let l = 0, d = 0, u = 0;
938
938
  for (; u < h; ) l = i.readUshort(a, t + (u << 2)), d = i.readShort(a, t + (u << 2) + 2), s.push(l), n.push(d), u++;
939
939
  for (; u < o; ) s.push(l), n.push(d), u++;
940
940
  return { aWidth: s, lsBearing: n };
941
941
  } }, X = { cmap: yt, head: Ct, hhea: vt, maxp: { parseTab(a, t, e) {
942
- const r = R;
942
+ const r = S;
943
943
  return r.readUint(a, t), t += 4, { numGlyphs: r.readUshort(a, t) };
944
944
  } }, hmtx: St, loca: { parseTab(a, t, e, r) {
945
- const i = R, s = [], n = r.head.indexToLocFormat, o = r.maxp.numGlyphs + 1;
945
+ const i = S, s = [], n = r.head.indexToLocFormat, o = r.maxp.numGlyphs + 1;
946
946
  if (n === 0) for (let h = 0; h < o; h++) s.push(i.readUshort(a, t + (h << 1)) << 1);
947
947
  else if (n === 1) for (let h = 0; h < o; h++) s.push(i.readUint(a, t + (h << 2)));
948
948
  return s;
@@ -951,7 +951,7 @@ const R = { readShort: (a, t) => (R.t.uint16[0] = a[t] << 8 | a[t + 1], R.t.int1
951
951
  for (let n = 0; n < s; n++) i.push(null);
952
952
  return i;
953
953
  }, us(a, t) {
954
- const e = R, r = a.fs, i = a.loca;
954
+ const e = S, r = a.fs, i = a.loca;
955
955
  if (i[t] === i[t + 1]) return null;
956
956
  const s = w.findTable(r, "glyf", a.ds);
957
957
  if (!s) return null;
@@ -1000,7 +1000,7 @@ const R = { readShort: (a, t) => (R.t.uint16[0] = a[t] << 8 | a[t + 1], R.t.int1
1000
1000
  }
1001
1001
  return n;
1002
1002
  })(new Uint8Array(a), 0, 0, {})], findTable(a, t, e) {
1003
- const r = R, i = r.readUshort(a, e + 4);
1003
+ const r = S, i = r.readUshort(a, e + 4);
1004
1004
  let s = e + 12;
1005
1005
  for (let n = 0; n < i; n++) {
1006
1006
  const o = r.readASCII(a, s, 4);
@@ -1010,7 +1010,7 @@ const R = { readShort: (a, t) => (R.t.uint16[0] = a[t] << 8 | a[t + 1], R.t.int1
1010
1010
  s += 16;
1011
1011
  }
1012
1012
  return null;
1013
- }, T: X, B: R };
1013
+ }, T: X, B: S };
1014
1014
  class z {
1015
1015
  constructor() {
1016
1016
  c(this, "_s", /* @__PURE__ */ new Map());
@@ -1188,7 +1188,7 @@ class _t {
1188
1188
  for (let o = 0; o < t.length; o++) {
1189
1189
  const h = o % r, l = Math.floor(o / r), d = t[o].character, u = this.Hs(s, d);
1190
1190
  if (!u) continue;
1191
- const f = d.codePointAt(0) || 0, g = this.Vs.vs(s, f), p = this.Xs(s, g) * n, m = h * e.width, E = l * e.height, v = m + 0.5 * e.width, _ = E + 0.5 * e.height, b = Math.round(v - 0.5 * e.width), y = Math.round(_ - 0.5 * i), P = b + 0.5 * (e.width - p), Z = y + s.hhea.ascender * n;
1191
+ const f = d.codePointAt(0) || 0, g = this.Vs.vs(s, f), p = this.Xs(s, g) * n, m = h * e.width, R = l * e.height, v = m + 0.5 * e.width, E = R + 0.5 * e.height, b = Math.round(v - 0.5 * e.width), y = Math.round(E - 0.5 * i), P = b + 0.5 * (e.width - p), Z = y + s.hhea.ascender * n;
1192
1192
  this.Ys(u, P, Z, n);
1193
1193
  }
1194
1194
  }
@@ -1221,17 +1221,17 @@ class _t {
1221
1221
  let p = l + 1;
1222
1222
  for (; p <= u; )
1223
1223
  if (1 & h[p]) {
1224
- const m = e + s[p] * i, E = r - n[p] * i;
1225
- this.ks.lineTo(m, E), p++;
1224
+ const m = e + s[p] * i, R = r - n[p] * i;
1225
+ this.ks.lineTo(m, R), p++;
1226
1226
  } else {
1227
- const m = e + s[p] * i, E = r - n[p] * i;
1227
+ const m = e + s[p] * i, R = r - n[p] * i;
1228
1228
  let v = p + 1 > u ? l : p + 1;
1229
1229
  if (1 & h[v]) {
1230
- const _ = e + s[v] * i, b = r - n[v] * i;
1231
- this.ks.quadraticCurveTo(m, E, _, b), p = v + 1;
1230
+ const E = e + s[v] * i, b = r - n[v] * i;
1231
+ this.ks.quadraticCurveTo(m, R, E, b), p = v + 1;
1232
1232
  } else {
1233
- const _ = (m + (e + s[v] * i)) / 2, b = (E + (r - n[v] * i)) / 2;
1234
- this.ks.quadraticCurveTo(m, E, _, b), p = v;
1233
+ const E = (m + (e + s[v] * i)) / 2, b = (R + (r - n[v] * i)) / 2;
1234
+ this.ks.quadraticCurveTo(m, R, E, b), p = v;
1235
1235
  }
1236
1236
  }
1237
1237
  this.ks.closePath();
@@ -1315,10 +1315,10 @@ class Tt {
1315
1315
  }
1316
1316
  async ci(t) {
1317
1317
  let e;
1318
- if (!t) throw new S("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");
1318
+ if (!t) throw new _("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");
1319
1319
  {
1320
1320
  const r = await fetch(t);
1321
- if (!r.ok) throw new S(`Failed to load font file: ${r.status} ${r.statusText}`);
1321
+ if (!r.ok) throw new _(`Failed to load font file: ${r.status} ${r.statusText}`);
1322
1322
  e = await r.arrayBuffer();
1323
1323
  }
1324
1324
  await this.li(e), this.Qs = w.parse(e)[0], await this.ui();
@@ -1332,14 +1332,14 @@ class Tt {
1332
1332
  async di(t) {
1333
1333
  try {
1334
1334
  const e = await fetch(t);
1335
- if (!e.ok) throw new S(`Failed to load font file: ${e.status} ${e.statusText}`);
1335
+ if (!e.ok) throw new _(`Failed to load font file: ${e.status} ${e.statusText}`);
1336
1336
  const r = await e.arrayBuffer();
1337
1337
  await this.li(r);
1338
1338
  const i = w.parse(r);
1339
1339
  if (!i || i.length === 0) throw Error("Failed to parse font file");
1340
1340
  this.Qs = i[0], await this.ui();
1341
1341
  } catch (e) {
1342
- throw new S("Failed to load font: " + (e instanceof Error ? e.message : "Unknown error"), e);
1342
+ throw new _("Failed to load font: " + (e instanceof Error ? e.message : "Unknown error"), e);
1343
1343
  }
1344
1344
  }
1345
1345
  async li(t) {
@@ -1443,7 +1443,7 @@ class Ft {
1443
1443
  }
1444
1444
  Ri() {
1445
1445
  const t = this.xi.getContext("webgl2", { alpha: !0, premultipliedAlpha: !1, preserveDrawingBuffer: !0, antialias: !1, depth: !1, stencil: !1, powerPreference: "high-performance" });
1446
- if (!t) throw new S("`textmode.js` requires WebGL2 support.");
1446
+ if (!t) throw new _("`textmode.js` requires WebGL2 support.");
1447
1447
  return t;
1448
1448
  }
1449
1449
  j() {
@@ -1719,17 +1719,17 @@ class It {
1719
1719
  let m = d + 1;
1720
1720
  for (; m <= f; )
1721
1721
  if (1 & h[m]) {
1722
- const E = e + s[m] * i, v = r - n[m] * i;
1723
- l += `L${E.toFixed(2)},${v.toFixed(2)}`, m++;
1722
+ const R = e + s[m] * i, v = r - n[m] * i;
1723
+ l += `L${R.toFixed(2)},${v.toFixed(2)}`, m++;
1724
1724
  } else {
1725
- const E = e + s[m] * i, v = r - n[m] * i;
1726
- let _ = m + 1 > f ? d : m + 1;
1727
- if (1 & h[_]) {
1728
- const b = e + s[_] * i, y = r - n[_] * i;
1729
- l += `Q${E.toFixed(2)},${v.toFixed(2)} ${b.toFixed(2)},${y.toFixed(2)}`, m = _ + 1;
1725
+ const R = e + s[m] * i, v = r - n[m] * i;
1726
+ let E = m + 1 > f ? d : m + 1;
1727
+ if (1 & h[E]) {
1728
+ const b = e + s[E] * i, y = r - n[E] * i;
1729
+ l += `Q${R.toFixed(2)},${v.toFixed(2)} ${b.toFixed(2)},${y.toFixed(2)}`, m = E + 1;
1730
1730
  } else {
1731
- const b = (E + (e + s[_] * i)) / 2, y = (v + (r - n[_] * i)) / 2;
1732
- l += `Q${E.toFixed(2)},${v.toFixed(2)} ${b.toFixed(2)},${y.toFixed(2)}`, m = _;
1731
+ const b = (R + (e + s[E] * i)) / 2, y = (v + (r - n[E] * i)) / 2;
1732
+ l += `Q${R.toFixed(2)},${v.toFixed(2)} ${b.toFixed(2)},${y.toFixed(2)}`, m = E;
1733
1733
  }
1734
1734
  }
1735
1735
  l += "Z";
@@ -2127,7 +2127,6 @@ precision highp float;in vec2 v_uv;in vec3 v_character;in vec4 v_primaryColor;in
2127
2127
  }
2128
2128
  class N {
2129
2129
  constructor() {
2130
- throw new S("Textmode is a static class and cannot be instantiated.");
2131
2130
  }
2132
2131
  static create(t = {}) {
2133
2132
  return new Ht(t);
@@ -2136,7 +2135,7 @@ class N {
2136
2135
  I.v(t);
2137
2136
  }
2138
2137
  static get version() {
2139
- return "0.2.0-beta.5";
2138
+ return "0.2.0";
2140
2139
  }
2141
2140
  }
2142
2141
  const Zt = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), Kt = N.create, qt = N.setErrorLevel, Jt = N.version;