textmode.js 0.2.0-beta.3 → 0.2.0-beta.5

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.
@@ -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), b = Math.max(1, Math.floor(o)), _ = Math.max(1, Math.floor(h));
433
- if (i.Kt({ x: E, y: v, width: b, height: _ }, r), i.Yt()) {
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()) {
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);
@@ -938,7 +938,7 @@ const R = { readShort: (a, t) => (R.t.uint16[0] = a[t] << 8 | a[t + 1], R.t.int1
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
- } }, j = { cmap: yt, head: Ct, hhea: vt, maxp: { parseTab(a, t, e) {
941
+ } }, X = { cmap: yt, head: Ct, hhea: vt, maxp: { parseTab(a, t, e) {
942
942
  const r = R;
943
943
  return r.readUint(a, t), t += 4, { numGlyphs: r.readUshort(a, t) };
944
944
  } }, hmtx: St, loca: { parseTab(a, t, e, r) {
@@ -989,7 +989,7 @@ const R = { readShort: (a, t) => (R.t.uint16[0] = a[t] << 8 | a[t + 1], R.t.int1
989
989
  } else o.parts = [], o.endPts = [], o.flags = [], o.xs = [], o.ys = [];
990
990
  return o;
991
991
  } } }, w = { parse: (a) => [((t, e, r, i) => {
992
- const s = j, n = { fs: t, ps: e, ds: r };
992
+ const s = X, n = { fs: t, ps: e, ds: r };
993
993
  for (const o in s) {
994
994
  const h = o, l = w.findTable(t, h, r);
995
995
  if (l) {
@@ -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: j, B: R };
1013
+ }, T: X, B: R };
1014
1014
  class z {
1015
1015
  constructor() {
1016
1016
  c(this, "_s", /* @__PURE__ */ new Map());
@@ -1166,7 +1166,7 @@ class Et {
1166
1166
  return this.Es.Ps(t, e);
1167
1167
  }
1168
1168
  }
1169
- class bt {
1169
+ class _t {
1170
1170
  constructor(t) {
1171
1171
  c(this, "Ws");
1172
1172
  c(this, "ks");
@@ -1188,7 +1188,7 @@ class bt {
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, b = E + 0.5 * e.height, _ = Math.round(v - 0.5 * e.width), y = Math.round(b - 0.5 * i), P = _ + 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, 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;
1192
1192
  this.Ys(u, P, Z, n);
1193
1193
  }
1194
1194
  }
@@ -1227,11 +1227,11 @@ class bt {
1227
1227
  const m = e + s[p] * i, E = r - n[p] * i;
1228
1228
  let v = p + 1 > u ? l : p + 1;
1229
1229
  if (1 & h[v]) {
1230
- const b = e + s[v] * i, _ = r - n[v] * i;
1231
- this.ks.quadraticCurveTo(m, E, b, _), p = v + 1;
1230
+ const _ = e + s[v] * i, b = r - n[v] * i;
1231
+ this.ks.quadraticCurveTo(m, E, _, b), p = v + 1;
1232
1232
  } else {
1233
- const b = (m + (e + s[v] * i)) / 2, _ = (E + (r - n[v] * i)) / 2;
1234
- this.ks.quadraticCurveTo(m, E, b, _), p = v;
1233
+ const _ = (m + (e + s[v] * i)) / 2, b = (E + (r - n[v] * i)) / 2;
1234
+ this.ks.quadraticCurveTo(m, E, _, b), p = v;
1235
1235
  }
1236
1236
  }
1237
1237
  this.ks.closePath();
@@ -1242,7 +1242,7 @@ class bt {
1242
1242
  this.ks.fill();
1243
1243
  }
1244
1244
  }
1245
- class _t {
1245
+ class bt {
1246
1246
  constructor() {
1247
1247
  c(this, "Ss");
1248
1248
  this.Ss = new z();
@@ -1311,7 +1311,7 @@ class Tt {
1311
1311
  c(this, "oi");
1312
1312
  c(this, "ai");
1313
1313
  c(this, "hi");
1314
- this.ti = e, this.ni = new Et(), this.oi = new bt(t), this.ai = new _t(), this.hi = new wt();
1314
+ this.ti = e, this.ni = new Et(), this.oi = new _t(t), this.ai = new bt(), this.hi = new wt();
1315
1315
  }
1316
1316
  async ci(t) {
1317
1317
  let e;
@@ -1574,10 +1574,10 @@ const Lt = (a) => class extends a {
1574
1574
  cellColor(t, e, r) {
1575
1575
  this.Us.state.Pt(t, e, r);
1576
1576
  }
1577
- flipHorizontally(t) {
1577
+ flipX(t) {
1578
1578
  this.Us.state.At(t);
1579
1579
  }
1580
- flipVertically(t) {
1580
+ flipY(t) {
1581
1581
  this.Us.state.Bt(t);
1582
1582
  }
1583
1583
  charRotation(t) {
@@ -1723,13 +1723,13 @@ class It {
1723
1723
  l += `L${E.toFixed(2)},${v.toFixed(2)}`, m++;
1724
1724
  } else {
1725
1725
  const E = e + s[m] * i, v = r - n[m] * i;
1726
- let b = m + 1 > f ? d : m + 1;
1727
- if (1 & h[b]) {
1728
- const _ = e + s[b] * i, y = r - n[b] * i;
1729
- l += `Q${E.toFixed(2)},${v.toFixed(2)} ${_.toFixed(2)},${y.toFixed(2)}`, m = b + 1;
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;
1730
1730
  } else {
1731
- const _ = (E + (e + s[b] * i)) / 2, y = (v + (r - n[b] * i)) / 2;
1732
- l += `Q${E.toFixed(2)},${v.toFixed(2)} ${_.toFixed(2)},${y.toFixed(2)}`, m = b;
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 = _;
1733
1733
  }
1734
1734
  }
1735
1735
  l += "Z";
@@ -1832,7 +1832,7 @@ class Mt extends k {
1832
1832
  this.dr(t, e || this.Hi());
1833
1833
  }
1834
1834
  }
1835
- class X {
1835
+ class j {
1836
1836
  constructor() {
1837
1837
  c(this, "_r");
1838
1838
  c(this, "gr");
@@ -1998,15 +1998,15 @@ const Vt = (a) => class extends a {
1998
1998
  this.Ar(), new Y().$r({ pipeline: this.Ir, grid: this.Lr, font: this.Qs }, t);
1999
1999
  }
2000
2000
  toSVG(t = {}) {
2001
- return this.Ar(), new X().Cr({ pipeline: this.Ir, grid: this.Lr, font: this.Qs }, t);
2001
+ return this.Ar(), new j().Cr({ pipeline: this.Ir, grid: this.Lr, font: this.Qs }, t);
2002
2002
  }
2003
2003
  saveSVG(t = {}) {
2004
- this.Ar(), new X().pr({ pipeline: this.Ir, grid: this.Lr, font: this.Qs }, t);
2004
+ this.Ar(), new j().pr({ pipeline: this.Ir, grid: this.Lr, font: this.Qs }, t);
2005
2005
  }
2006
2006
  async saveCanvas(t = {}) {
2007
2007
  await new Nt().Fr(this.xi, t);
2008
2008
  }
2009
- }, jt = (a) => class extends a {
2009
+ }, Xt = (a) => class extends a {
2010
2010
  async loadFont(t) {
2011
2011
  return this.Qs.di(t).then(() => {
2012
2012
  const e = this.Qs.maxGlyphDimensions;
@@ -2019,7 +2019,7 @@ const Vt = (a) => class extends a {
2019
2019
  const e = this.Qs.maxGlyphDimensions;
2020
2020
  this.Lr.wi(e.width, e.height), this.Ir.W(this.Lr.cols, this.Lr.rows), this.Us.cs();
2021
2021
  }
2022
- }, Xt = (a) => class extends a {
2022
+ }, jt = (a) => class extends a {
2023
2023
  get frameCount() {
2024
2024
  return this.Er.frameCount;
2025
2025
  }
@@ -2058,7 +2058,7 @@ class Yt {
2058
2058
  }
2059
2059
  class Ht extends function(e, ...r) {
2060
2060
  return r.reduce((i, s) => s(i), e);
2061
- }(Yt, Lt, Vt, jt, Xt) {
2061
+ }(Yt, Lt, Vt, Xt, jt) {
2062
2062
  constructor(e = {}) {
2063
2063
  super();
2064
2064
  c(this, "Ur", !1);
@@ -2066,38 +2066,42 @@ class Ht extends function(e, ...r) {
2066
2066
  });
2067
2067
  c(this, "Or", () => {
2068
2068
  });
2069
- c(this, "jr");
2069
+ c(this, "jr", () => {
2070
+ });
2071
+ c(this, "Hr");
2070
2072
  this.xi = new Ft(e), this.Us = new xt(this.xi.Ri()), this.Qs = new Tt(this.Us, e.fontSize ?? 16), this.Er = new Ut(e.frameRate ?? 60), this.Br = this.Us.Xe(O, `#version 300 es
2071
- precision highp float;in vec2 v_uv;in vec3 v_character;in vec4 v_primaryColor;in vec4 v_secondaryColor;in vec2 v_rotation;in vec3 v_transform;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){o_character=vec4(v_character,1.0);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.0,1.0);o_transform=vec4(v_transform,1.0);}`), this.kr = this.Us.Xe("attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.0,1.0);}", "precision mediump float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D u_primaryColorTexture;uniform sampler2D u_secondaryColorTexture;uniform sampler2D u_transformTexture;uniform sampler2D u_asciiCharacterTexture;uniform sampler2D u_rotationTexture;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;uniform vec2 u_gridOffsetPixels;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){vec2 adjustedCoord=(gl_FragCoord.xy-u_gridOffsetPixels)/u_gridPixelDimensions;vec2 gridCoord=adjustedCoord*u_gridCellDimensions;vec2 cellCoord=floor(gridCoord);vec2 charIndexTexCoord=(cellCoord+0.5)/u_gridCellDimensions;vec4 primaryColor=texture2D(u_primaryColorTexture,charIndexTexCoord);vec4 secondaryColor=texture2D(u_secondaryColorTexture,charIndexTexCoord);vec4 transformColor=texture2D(u_transformTexture,charIndexTexCoord);bool isInverted=transformColor.r>0.5;bool flipHorizontal=transformColor.g>0.5;bool flipVertical=transformColor.b>0.5;vec4 encodedIndexVec=texture2D(u_asciiCharacterTexture,charIndexTexCoord);int charIndex=int(encodedIndexVec.r*255.0+0.5)+int(encodedIndexVec.g*255.0+0.5)*256;int charCol=int(mod(float(charIndex),u_charsetDimensions.x));int charRow=charIndex/int(u_charsetDimensions.x);float flippedRow=(u_charsetDimensions.y-1.0)-float(charRow);vec2 charCoord=vec2(float(charCol),flippedRow)/u_charsetDimensions;vec4 rotationColor=texture2D(u_rotationTexture,charIndexTexCoord);float scaledAngle=rotationColor.r*255.0+rotationColor.g;float rotationAngle=-(scaledAngle*360.0/255.0)*0.017453292;vec2 fractionalPart=fract(gridCoord)-0.5;if(flipHorizontal)fractionalPart.x=-fractionalPart.x;if(flipVertical)fractionalPart.y=-fractionalPart.y;fractionalPart=rotate2D(rotationAngle)*fractionalPart+0.5;vec2 cellSize=1.0/u_charsetDimensions;vec2 texCoord=charCoord+fractionalPart*cellSize;vec2 cellMax=charCoord+cellSize;if(any(lessThan(texCoord,charCoord))||any(greaterThan(texCoord,cellMax))){gl_FragColor=isInverted ? primaryColor : secondaryColor;return;}vec4 charTexel=texture2D(u_characterTexture,texCoord);if(isInverted)charTexel.rgb=1.0-charTexel.rgb;gl_FragColor=mix(secondaryColor,primaryColor,charTexel);}");
2073
+ precision highp float;in vec2 v_uv;in vec3 v_character;in vec4 v_primaryColor;in vec4 v_secondaryColor;in vec2 v_rotation;in vec3 v_transform;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){o_character=vec4(v_character,1.0);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.0,1.0);o_transform=vec4(v_transform,1.0);}`), this.kr = this.Us.Xe("attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.0,1.0);}", "precision mediump float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D u_primaryColorTexture;uniform sampler2D u_secondaryColorTexture;uniform sampler2D u_transformTexture;uniform sampler2D u_asciiCharacterTexture;uniform sampler2D u_rotationTexture;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;uniform vec2 u_gridOffsetPixels;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){vec2 adjustedCoord=(gl_FragCoord.xy-u_gridOffsetPixels)/u_gridPixelDimensions;vec2 gridCoord=adjustedCoord*u_gridCellDimensions;vec2 cellCoord=floor(gridCoord);vec2 charIndexTexCoord=(cellCoord+0.5)/u_gridCellDimensions;vec4 primaryColor=texture2D(u_primaryColorTexture,charIndexTexCoord);vec4 secondaryColor=texture2D(u_secondaryColorTexture,charIndexTexCoord);vec4 transformColor=texture2D(u_transformTexture,charIndexTexCoord);bool isInverted=transformColor.r>0.5;bool flipHorizontal=transformColor.g>0.5;bool flipVertical=transformColor.b>0.5;vec4 encodedIndexVec=texture2D(u_asciiCharacterTexture,charIndexTexCoord);int charIndex=int(encodedIndexVec.r*255.0+0.5)+int(encodedIndexVec.g*255.0+0.5)*256;int charCol=int(mod(float(charIndex),u_charsetDimensions.x));int charRow=charIndex/int(u_charsetDimensions.x);float flippedRow=(u_charsetDimensions.y-1.0)-float(charRow);vec2 charCoord=vec2(float(charCol),flippedRow)/u_charsetDimensions;vec4 rotationColor=texture2D(u_rotationTexture,charIndexTexCoord);float scaledAngle=rotationColor.r*255.0+rotationColor.g;float rotationAngle=-(scaledAngle*360.0/255.0)*0.017453292;vec2 fractionalPart=fract(gridCoord)-0.5;if(flipHorizontal)fractionalPart.x=-fractionalPart.x;if(flipVertical)fractionalPart.y=-fractionalPart.y;fractionalPart=rotate2D(rotationAngle)*fractionalPart+0.5;vec2 cellSize=1.0/u_charsetDimensions;vec2 texCoord=charCoord+fractionalPart*cellSize;vec2 cellMax=charCoord+cellSize;if(any(lessThan(texCoord,charCoord))||any(greaterThan(texCoord,cellMax))){gl_FragColor=isInverted ? primaryColor : secondaryColor;return;}vec4 charTexel=texture2D(u_characterTexture,texCoord);if(isInverted)charTexel.rgb=1.0-charTexel.rgb;gl_FragColor=mix(secondaryColor,primaryColor,charTexel);}"), this.Xr(e);
2072
2074
  }
2073
- static async create(e = {}) {
2074
- const r = new this(e);
2075
- await r.Qs.ci(e.fontSource);
2076
- const i = r.Qs.maxGlyphDimensions;
2077
- return r.Lr = new At(r.xi.canvas, i.width, i.height), r.Ir = r.Us.rs(r.Lr.cols, r.Lr.rows, 5), r.Hr(), r.Er.start(() => r.Wr()), r;
2075
+ async Xr(e) {
2076
+ await this.Qs.ci(e.fontSource);
2077
+ const r = this.Qs.maxGlyphDimensions;
2078
+ this.Lr = new At(this.xi.canvas, r.width, r.height), this.Ir = this.Us.rs(this.Lr.cols, this.Lr.rows, 5), this.Yr(), this.Vr(), this.Er.start(() => this.Wr());
2078
2079
  }
2079
- Hr() {
2080
- this.jr = () => {
2081
- this.Or();
2082
- }, window.addEventListener("resize", this.jr);
2080
+ Yr() {
2081
+ this.Hr = () => {
2082
+ this.jr();
2083
+ }, window.addEventListener("resize", this.Hr);
2083
2084
  }
2084
2085
  Wr() {
2085
2086
  if (this.Er.measureFrameRate(), this.Er.incrementFrame(), this.Ur) return;
2086
- this.Ir.V(), this.Us.He(this.Br), this.Vr(), this.Us.ls(this.Br), this.Ir.O();
2087
+ this.Ir.V(), this.Us.He(this.Br), this.Or(), this.Us.ls(this.Br), this.Ir.O();
2087
2088
  const e = this.Us.state.canvasBackgroundColor;
2088
2089
  this.Us.de(e[0], e[1], e[2], e[3]), this.Us.He(this.kr), this.kr.st({ u_characterTexture: this.Qs.fontFramebuffer, u_charsetDimensions: [this.Qs.textureColumns, this.Qs.textureRows], u_asciiCharacterTexture: this.Ir.textures[0], u_primaryColorTexture: this.Ir.textures[1], u_secondaryColorTexture: this.Ir.textures[2], u_transformTexture: this.Ir.textures[4], u_rotationTexture: this.Ir.textures[3], u_gridCellDimensions: [this.Lr.cols, this.Lr.rows], u_gridPixelDimensions: [this.Lr.width, this.Lr.height], u_gridOffsetPixels: [this.Lr.offsetX, this.Lr.offsetY], u_aspectRatio: this.Lr.width / this.Lr.height }), this.Us.Qe(this.Lr.offsetX, this.Lr.offsetY, this.Lr.width, this.Lr.height);
2089
2090
  }
2090
- draw(e) {
2091
+ setup(e) {
2091
2092
  this.Vr = e;
2092
2093
  }
2093
- windowResized(e) {
2094
+ draw(e) {
2094
2095
  this.Or = e;
2095
2096
  }
2097
+ windowResized(e) {
2098
+ this.jr = e;
2099
+ }
2096
2100
  resizeCanvas(e, r) {
2097
2101
  this.xi.W(e, r), this.Lr.zt(), this.Ir.W(this.Lr.cols, this.Lr.rows), this.Us.cs(), this.Wr();
2098
2102
  }
2099
2103
  destroy() {
2100
- this.Ur || (this.Er.stop(), window.removeEventListener("resize", this.jr), this.Qs.j(), this.Us.j(), this.Ur = !0);
2104
+ this.Ur || (this.Er.stop(), window.removeEventListener("resize", this.Hr), this.Qs.j(), this.Us.j(), this.Ur = !0);
2101
2105
  }
2102
2106
  get grid() {
2103
2107
  return this.Lr;
@@ -2125,14 +2129,14 @@ class N {
2125
2129
  constructor() {
2126
2130
  throw new S("Textmode is a static class and cannot be instantiated.");
2127
2131
  }
2128
- static async create(t) {
2129
- return Ht.create(t);
2132
+ static create(t = {}) {
2133
+ return new Ht(t);
2130
2134
  }
2131
2135
  static setErrorLevel(t) {
2132
2136
  I.v(t);
2133
2137
  }
2134
2138
  static get version() {
2135
- return "0.2.0-beta.3";
2139
+ return "0.2.0-beta.5";
2136
2140
  }
2137
2141
  }
2138
2142
  const Zt = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), Kt = N.create, qt = N.setErrorLevel, Jt = N.version;