textmode.js 0.2.0-beta.3 → 0.2.0-beta.4
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/textmode.esm.js +44 -40
- package/dist/textmode.esm.min.js +33 -29
- package/dist/textmode.umd.js +6 -6
- package/dist/textmode.umd.min.js +6 -6
- package/dist/types/Textmode.d.ts +17 -5
- package/dist/types/textmode/Textmodifier.d.ts +39 -4
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +4 -4
- package/package.json +1 -1
package/dist/textmode.esm.js
CHANGED
|
@@ -340,7 +340,7 @@ class AA {
|
|
|
340
340
|
this.PA = [A / 255, t / 255, e / 255, s / 255];
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
|
-
var
|
|
343
|
+
var L = `#version 300 es
|
|
344
344
|
in vec2 a_position;in vec2 a_texCoord;in vec2 a_instancePosition;in vec2 a_instanceSize;in vec3 a_instanceCharacter;in vec4 a_instancePrimaryColor;in vec4 a_instanceSecondaryColor;in vec2 a_instanceRotation;in vec3 a_instanceTransform;in vec3 a_instanceGlobalRotation;in vec2 a_instanceRotationCenter;in vec2 a_instanceBezierCP1;in vec2 a_instanceBezierCP2;in vec2 a_instanceBezierStart;in vec2 a_instanceBezierEnd;in vec2 a_instanceArcAngles;uniform float u_aspectRatio;uniform vec2 u_viewportSize;out vec2 v_uv;out vec3 v_character;out vec4 v_primaryColor;out vec4 v_secondaryColor;out vec2 v_rotation;out vec3 v_transform;mat3 rotateX(float a){float s=sin(a),c=cos(a);return mat3(1,0,0,0,c,-s,0,s,c);}mat3 rotateY(float a){float s=sin(a),c=cos(a);return mat3(c,0,s,0,1,0,-s,0,c);}mat3 rotateZ(float a){float s=sin(a),c=cos(a);return mat3(c,-s,0,s,c,0,0,0,1);}vec2 evaluateBezier(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float u=1.-t,u2=u*u,t2=t*t;return u2*u*p0+3.*u2*t*p1+3.*u*t2*p2+t2*t*p3;}vec2 evaluateBezierDerivative(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float u=1.-t,u2=u*u,t2=t*t;return-3.*u2*p0+3.*u2*p1-6.*u*t*p1+6.*u*t*p2-3.*t2*p2+3.*t2*p3;}void main(){v_uv=a_texCoord;v_character=a_instanceCharacter;v_primaryColor=a_instancePrimaryColor;v_secondaryColor=a_instanceSecondaryColor;v_rotation=a_instanceRotation;v_transform=a_instanceTransform;vec2 worldPosition;bool isBezier=length(a_instanceBezierCP1)+length(a_instanceBezierCP2)+length(a_instanceBezierStart)+length(a_instanceBezierEnd)>0.;bool isArc=a_instanceArcAngles.x!=0.||a_instanceArcAngles.y!=0.;if(isBezier){float t=a_position.x;vec2 curvePoint=evaluateBezier(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 tangent=evaluateBezierDerivative(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float tLen=length(tangent);tangent=tLen>0.?tangent/tLen:vec2(1,0);worldPosition=curvePoint+vec2(-tangent.y,tangent.x)*a_position.y*a_instanceSize.y;}else if(isArc){float s=a_instanceArcAngles.x,e=a_instanceArcAngles.y;s=mod(s,6.28318530718);if(s<0.)s+=6.28318530718;e=mod(e,6.28318530718);if(e<0.)e+=6.28318530718;float d=s-e;if(d<=0.)d+=6.28318530718;float angle=s-a_position.x*d;vec2 local=vec2(cos(angle),sin(angle))*a_position.y;worldPosition=local*a_instanceSize*.5+a_instanceSize*.5+a_instancePosition;}else{worldPosition=a_position*a_instanceSize+a_instancePosition;}vec2 ndc=(worldPosition/u_viewportSize)*2.-1.;ndc.y=-ndc.y;if(length(a_instanceGlobalRotation)>0.){vec3 pos3D=vec3(ndc-a_instanceRotationCenter,0);pos3D.x*=u_aspectRatio;if(a_instanceGlobalRotation.x!=0.)pos3D=rotateX(-a_instanceGlobalRotation.x)*pos3D;if(a_instanceGlobalRotation.y!=0.)pos3D=rotateY(-a_instanceGlobalRotation.y)*pos3D;if(a_instanceGlobalRotation.z!=0.)pos3D=rotateZ(-a_instanceGlobalRotation.z)*pos3D;pos3D.x/=u_aspectRatio;ndc=pos3D.xy+a_instanceRotationCenter;}gl_Position=vec4(ndc,0,1);}`, D = ((E) => (E.RECTANGLE = "rectangle", E.LINE = "line", E.ELLIPSE = "ellipse", E.ARC = "arc", E.TRIANGLE = "triangle", E.BEZIER_CURVE = "bezier_curve", E.CUSTOM = "custom", E))(D || {});
|
|
345
345
|
class tA {
|
|
346
346
|
constructor(A) {
|
|
@@ -441,7 +441,7 @@ class eA {
|
|
|
441
441
|
A.shader.AA();
|
|
442
442
|
}
|
|
443
443
|
NA() {
|
|
444
|
-
return this.OA || (this.OA = new z(this.m,
|
|
444
|
+
return this.OA || (this.OA = new z(this.m, L, `#version 300 es
|
|
445
445
|
precision highp float;in vec2 v_uv;uniform sampler2D u_src0;uniform sampler2D u_src1;uniform sampler2D u_src2;uniform sampler2D u_src3;uniform sampler2D u_src4;uniform vec2 u_srcSize;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(){vec2 uvTex=v_uv*u_srcSize;vec2 uvQ=(floor(uvTex)+0.5f)/u_srcSize;o_character=texture(u_src0,uvQ);o_primaryColor=texture(u_src1,uvQ);o_secondaryColor=texture(u_src2,uvQ);o_rotation=texture(u_src3,uvQ);o_transform=texture(u_src4,uvQ);}`)), this.OA;
|
|
446
446
|
}
|
|
447
447
|
XA(A, t) {
|
|
@@ -800,7 +800,7 @@ class DA {
|
|
|
800
800
|
Object.assign(this.St, A);
|
|
801
801
|
}
|
|
802
802
|
jt(A) {
|
|
803
|
-
return new z(this.m,
|
|
803
|
+
return new z(this.m, L, A);
|
|
804
804
|
}
|
|
805
805
|
Xt(A, t, e, s) {
|
|
806
806
|
var C;
|
|
@@ -1575,10 +1575,10 @@ const TA = (E) => class extends E {
|
|
|
1575
1575
|
cellColor(A, t, e) {
|
|
1576
1576
|
this.ze.state.bA(A, t, e);
|
|
1577
1577
|
}
|
|
1578
|
-
|
|
1578
|
+
flipX(A) {
|
|
1579
1579
|
this.ze.state.GA(A);
|
|
1580
1580
|
}
|
|
1581
|
-
|
|
1581
|
+
flipY(A) {
|
|
1582
1582
|
this.ze.state.$A(A);
|
|
1583
1583
|
}
|
|
1584
1584
|
charRotation(A) {
|
|
@@ -1615,7 +1615,7 @@ const TA = (E) => class extends E {
|
|
|
1615
1615
|
return this.ze.jt(A);
|
|
1616
1616
|
}
|
|
1617
1617
|
};
|
|
1618
|
-
class
|
|
1618
|
+
class O {
|
|
1619
1619
|
bB(A) {
|
|
1620
1620
|
const t = A.U(0), e = A.U(1), s = A.U(2), r = A.U(3);
|
|
1621
1621
|
return { characterPixels: t, primaryColorPixels: e, secondaryColorPixels: s, transformPixels: A.U(4), rotationPixels: r };
|
|
@@ -1653,7 +1653,7 @@ class W {
|
|
|
1653
1653
|
return "textmode-export-" + this.zB();
|
|
1654
1654
|
}
|
|
1655
1655
|
}
|
|
1656
|
-
class MA extends
|
|
1656
|
+
class MA extends O {
|
|
1657
1657
|
FB(A, t, e) {
|
|
1658
1658
|
const s = A[e] === 255, r = A[e + 1] === 255, i = A[e + 2] === 255, B = t[e], n = t[e + 1];
|
|
1659
1659
|
return { isInverted: s, flipHorizontal: r, flipVertical: i, rotation: Math.round(360 * (B + n / 255) / 255 * 100) / 100 };
|
|
@@ -1851,7 +1851,7 @@ class H {
|
|
|
1851
1851
|
this.ns.Qs(this.hs(A, t), t.filename);
|
|
1852
1852
|
}
|
|
1853
1853
|
}
|
|
1854
|
-
class SA extends
|
|
1854
|
+
class SA extends O {
|
|
1855
1855
|
cs(A, t, e, s = " ") {
|
|
1856
1856
|
var B;
|
|
1857
1857
|
const r = [];
|
|
@@ -1890,7 +1890,7 @@ class zA extends W {
|
|
|
1890
1890
|
return t === ".txt" || t.length <= 4 ? this.SB() : t;
|
|
1891
1891
|
}
|
|
1892
1892
|
}
|
|
1893
|
-
class
|
|
1893
|
+
class X {
|
|
1894
1894
|
constructor() {
|
|
1895
1895
|
o(this, "rs");
|
|
1896
1896
|
o(this, "Es");
|
|
@@ -1908,7 +1908,7 @@ class J {
|
|
|
1908
1908
|
this.ns.Ds(this.Ps(A, t), t.filename);
|
|
1909
1909
|
}
|
|
1910
1910
|
}
|
|
1911
|
-
class UA extends
|
|
1911
|
+
class UA extends O {
|
|
1912
1912
|
us(A, t = 1, e = "transparent") {
|
|
1913
1913
|
const s = A.canvas;
|
|
1914
1914
|
if (t === 1 && e === "transparent") return s;
|
|
@@ -1916,7 +1916,7 @@ class UA extends L {
|
|
|
1916
1916
|
return r.width = B, r.height = n, e !== "transparent" && (i.fillStyle = e, i.fillRect(0, 0, B, n)), i.imageSmoothingEnabled = !1, i.drawImage(s, 0, 0, s.width, s.height, 0, 0, B, n), r;
|
|
1917
1917
|
}
|
|
1918
1918
|
}
|
|
1919
|
-
class
|
|
1919
|
+
class LA {
|
|
1920
1920
|
Is(A, t) {
|
|
1921
1921
|
const e = this.ws(t.format);
|
|
1922
1922
|
return t.format === "png" ? A.toDataURL(e) : A.toDataURL(e, t.quality);
|
|
@@ -1942,10 +1942,10 @@ class OA {
|
|
|
1942
1942
|
}
|
|
1943
1943
|
}
|
|
1944
1944
|
}
|
|
1945
|
-
const
|
|
1945
|
+
const OA = { png: "image/png", jpg: "image/jpeg", webp: "image/webp" }, J = { png: ".png", jpg: ".jpg", webp: ".webp" };
|
|
1946
1946
|
class WA extends W {
|
|
1947
1947
|
ds(A, t, e) {
|
|
1948
|
-
this.ps(A, this.TB(t) +
|
|
1948
|
+
this.ps(A, this.TB(t) + J[e]);
|
|
1949
1949
|
}
|
|
1950
1950
|
ps(A, t) {
|
|
1951
1951
|
const e = URL.createObjectURL(A);
|
|
@@ -1957,7 +1957,7 @@ class WA extends W {
|
|
|
1957
1957
|
}
|
|
1958
1958
|
}
|
|
1959
1959
|
_s(A) {
|
|
1960
|
-
return A in
|
|
1960
|
+
return A in OA && A in J;
|
|
1961
1961
|
}
|
|
1962
1962
|
}
|
|
1963
1963
|
class $A {
|
|
@@ -1965,7 +1965,7 @@ class $A {
|
|
|
1965
1965
|
o(this, "rs");
|
|
1966
1966
|
o(this, "Es");
|
|
1967
1967
|
o(this, "ns");
|
|
1968
|
-
this.rs = new UA(), this.Es = new
|
|
1968
|
+
this.rs = new UA(), this.Es = new LA(), this.ns = new WA();
|
|
1969
1969
|
}
|
|
1970
1970
|
gs(A) {
|
|
1971
1971
|
return { format: A.format ?? "png", quality: A.quality ?? 1, scale: A.scale ?? 1, backgroundColor: A.backgroundColor ?? "transparent", filename: A.filename || this.ns.SB() };
|
|
@@ -1993,10 +1993,10 @@ const kA = (E) => class extends E {
|
|
|
1993
1993
|
this.ze.re(this.Gs);
|
|
1994
1994
|
}
|
|
1995
1995
|
toString(A = {}) {
|
|
1996
|
-
return this.bs(), new
|
|
1996
|
+
return this.bs(), new X().Ps({ pipeline: this.$s, grid: this.Ms, font: this.We }, A);
|
|
1997
1997
|
}
|
|
1998
1998
|
saveStrings(A = {}) {
|
|
1999
|
-
this.bs(), new
|
|
1999
|
+
this.bs(), new X().Ds({ pipeline: this.$s, grid: this.Ms, font: this.We }, A);
|
|
2000
2000
|
}
|
|
2001
2001
|
toSVG(A = {}) {
|
|
2002
2002
|
return this.bs(), new H().hs({ pipeline: this.$s, grid: this.Ms, font: this.We }, A);
|
|
@@ -2043,7 +2043,7 @@ const kA = (E) => class extends E {
|
|
|
2043
2043
|
return this.Ys.isLooping;
|
|
2044
2044
|
}
|
|
2045
2045
|
};
|
|
2046
|
-
class
|
|
2046
|
+
class XA {
|
|
2047
2047
|
constructor() {
|
|
2048
2048
|
o(this, "ze");
|
|
2049
2049
|
o(this, "We");
|
|
@@ -2057,9 +2057,9 @@ class JA {
|
|
|
2057
2057
|
zs() {
|
|
2058
2058
|
}
|
|
2059
2059
|
}
|
|
2060
|
-
class
|
|
2060
|
+
class JA extends function(t, ...e) {
|
|
2061
2061
|
return e.reduce((s, r) => r(s), t);
|
|
2062
|
-
}(
|
|
2062
|
+
}(XA, TA, kA, NA, HA) {
|
|
2063
2063
|
constructor(t = {}) {
|
|
2064
2064
|
super();
|
|
2065
2065
|
o(this, "Ts", !1);
|
|
@@ -2067,38 +2067,42 @@ class XA extends function(t, ...e) {
|
|
|
2067
2067
|
});
|
|
2068
2068
|
o(this, "Fs", () => {
|
|
2069
2069
|
});
|
|
2070
|
-
o(this, "Os")
|
|
2071
|
-
|
|
2072
|
-
|
|
2070
|
+
o(this, "Os", () => {
|
|
2071
|
+
});
|
|
2072
|
+
o(this, "Us");
|
|
2073
|
+
this.aB = new bA(t), this.ze = new DA(this.aB.uB()), this.We = new xA(this.ze, t.fontSize ?? 16), this.Ys = new RA(t.frameRate ?? 60), this.Gs = this.ze.Jt(L, `#version 300 es
|
|
2074
|
+
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.Rs = this.ze.Jt("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.Ls(t);
|
|
2073
2075
|
}
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
return e.Ms = new vA(e.aB.canvas, s.width, s.height), e.$s = e.ze.Be(e.Ms.cols, e.Ms.rows, 5), e.Us(), e.Ys.start(() => e.zs()), e;
|
|
2076
|
+
async Ls(t) {
|
|
2077
|
+
await this.We.BB(t.fontSource);
|
|
2078
|
+
const e = this.We.maxGlyphDimensions;
|
|
2079
|
+
this.Ms = new vA(this.aB.canvas, e.width, e.height), this.$s = this.ze.Be(this.Ms.cols, this.Ms.rows, 5), this.ks(), this.Ss(), this.Ys.start(() => this.zs());
|
|
2079
2080
|
}
|
|
2080
|
-
|
|
2081
|
-
this.
|
|
2082
|
-
this.
|
|
2083
|
-
}, window.addEventListener("resize", this.
|
|
2081
|
+
ks() {
|
|
2082
|
+
this.Us = () => {
|
|
2083
|
+
this.Os();
|
|
2084
|
+
}, window.addEventListener("resize", this.Us);
|
|
2084
2085
|
}
|
|
2085
2086
|
zs() {
|
|
2086
2087
|
if (this.Ys.measureFrameRate(), this.Ys.incrementFrame(), this.Ts) return;
|
|
2087
|
-
this.$s.k(), this.ze.Wt(this.Gs), this.
|
|
2088
|
+
this.$s.k(), this.ze.Wt(this.Gs), this.Fs(), this.ze.re(this.Gs), this.$s.H();
|
|
2088
2089
|
const t = this.ze.state.canvasBackgroundColor;
|
|
2089
2090
|
this.ze.ot(t[0], t[1], t[2], t[3]), this.ze.Wt(this.Rs), this.Rs.eA({ u_characterTexture: this.We.fontFramebuffer, u_charsetDimensions: [this.We.textureColumns, this.We.textureRows], u_asciiCharacterTexture: this.$s.textures[0], u_primaryColorTexture: this.$s.textures[1], u_secondaryColorTexture: this.$s.textures[2], u_transformTexture: this.$s.textures[4], u_rotationTexture: this.$s.textures[3], u_gridCellDimensions: [this.Ms.cols, this.Ms.rows], u_gridPixelDimensions: [this.Ms.width, this.Ms.height], u_gridOffsetPixels: [this.Ms.offsetX, this.Ms.offsetY], u_aspectRatio: this.Ms.width / this.Ms.height }), this.ze.Xt(this.Ms.offsetX, this.Ms.offsetY, this.Ms.width, this.Ms.height);
|
|
2090
2091
|
}
|
|
2091
|
-
|
|
2092
|
+
setup(t) {
|
|
2092
2093
|
this.Ss = t;
|
|
2093
2094
|
}
|
|
2094
|
-
|
|
2095
|
+
draw(t) {
|
|
2095
2096
|
this.Fs = t;
|
|
2096
2097
|
}
|
|
2098
|
+
windowResized(t) {
|
|
2099
|
+
this.Os = t;
|
|
2100
|
+
}
|
|
2097
2101
|
resizeCanvas(t, e) {
|
|
2098
2102
|
this.aB.O(t, e), this.Ms.fA(), this.$s.O(this.Ms.cols, this.Ms.rows), this.ze.Qe(), this.zs();
|
|
2099
2103
|
}
|
|
2100
2104
|
destroy() {
|
|
2101
|
-
this.Ts || (this.Ys.stop(), window.removeEventListener("resize", this.
|
|
2105
|
+
this.Ts || (this.Ys.stop(), window.removeEventListener("resize", this.Us), this.We.W(), this.ze.W(), this.Ts = !0);
|
|
2102
2106
|
}
|
|
2103
2107
|
get grid() {
|
|
2104
2108
|
return this.Ms;
|
|
@@ -2126,14 +2130,14 @@ class $ {
|
|
|
2126
2130
|
constructor() {
|
|
2127
2131
|
throw new m("Textmode is a static class and cannot be instantiated.");
|
|
2128
2132
|
}
|
|
2129
|
-
static
|
|
2130
|
-
return
|
|
2133
|
+
static create(A = {}) {
|
|
2134
|
+
return new JA(A);
|
|
2131
2135
|
}
|
|
2132
2136
|
static setErrorLevel(A) {
|
|
2133
2137
|
_.u(A);
|
|
2134
2138
|
}
|
|
2135
2139
|
static get version() {
|
|
2136
|
-
return "0.2.0-beta.
|
|
2140
|
+
return "0.2.0-beta.4";
|
|
2137
2141
|
}
|
|
2138
2142
|
}
|
|
2139
2143
|
const jA = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), ZA = $.create, KA = $.setErrorLevel, qA = $.version;
|
|
@@ -2142,7 +2146,7 @@ export {
|
|
|
2142
2146
|
q as TextmodeErrorLevel,
|
|
2143
2147
|
xA as TextmodeFont,
|
|
2144
2148
|
vA as TextmodeGrid,
|
|
2145
|
-
|
|
2149
|
+
JA as Textmodifier,
|
|
2146
2150
|
ZA as create,
|
|
2147
2151
|
jA as export,
|
|
2148
2152
|
KA as setErrorLevel,
|
package/dist/textmode.esm.min.js
CHANGED
|
@@ -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
|
-
} },
|
|
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 =
|
|
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:
|
|
1013
|
+
}, T: X, B: R };
|
|
1014
1014
|
class z {
|
|
1015
1015
|
constructor() {
|
|
1016
1016
|
c(this, "_s", /* @__PURE__ */ new Map());
|
|
@@ -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
|
-
|
|
1577
|
+
flipX(t) {
|
|
1578
1578
|
this.Us.state.At(t);
|
|
1579
1579
|
}
|
|
1580
|
-
|
|
1580
|
+
flipY(t) {
|
|
1581
1581
|
this.Us.state.Bt(t);
|
|
1582
1582
|
}
|
|
1583
1583
|
charRotation(t) {
|
|
@@ -1832,7 +1832,7 @@ class Mt extends k {
|
|
|
1832
1832
|
this.dr(t, e || this.Hi());
|
|
1833
1833
|
}
|
|
1834
1834
|
}
|
|
1835
|
-
class
|
|
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
|
|
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
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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,
|
|
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
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
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
|
-
|
|
2080
|
-
this.
|
|
2081
|
-
this.
|
|
2082
|
-
}, window.addEventListener("resize", this.
|
|
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.
|
|
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
|
-
|
|
2091
|
+
setup(e) {
|
|
2091
2092
|
this.Vr = e;
|
|
2092
2093
|
}
|
|
2093
|
-
|
|
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.
|
|
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
|
|
2129
|
-
return Ht
|
|
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.
|
|
2139
|
+
return "0.2.0-beta.4";
|
|
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;
|