textmode.js 0.2.1-beta.8 → 0.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.
@@ -10,4 +10,4 @@ precision highp float;in vec2 v_uv;in vec3 v_character;in vec4 v_primaryColor;in
10
10
  precision highp float;in vec2 v_uv;uniform sampler2D Ue;uniform sampler2D Uf;uniform sampler2D Ug;uniform sampler2D Uh;uniform sampler2D Ui;uniform vec2 Uj;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 A=vec2(v_uv.x,1.-v_uv.y);vec2 B=A*Uj;vec2 C=(floor(B)+0.5f)/Uj;vec4 D=texture(Ue,C);vec4 E=texture(Uf,C);if(E.a==0.){discard;}vec4 F=texture(Ug,C);vec4 G=texture(Uh,C);vec4 H=texture(Ui,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;o_rotation=G;o_transform=H;}`),this.ee=new $(this.vt,ot,"precision mediump float;uniform sampler2D U0;uniform vec2 U1;uniform sampler2D U3;uniform sampler2D U4;uniform sampler2D U5;uniform sampler2D U2;uniform sampler2D U6;uniform vec2 U7;uniform vec2 U8;mat2 A(float B){float C=sin(B);float D=cos(B);return mat2(D,-C,C,D);}void main(){vec2 E=gl_FragCoord.xy/U8;vec2 F=E*U7;vec2 G=floor(F);vec2 H=(G+0.5)/U7;vec4 I=texture2D(U3,H);vec4 J=texture2D(U4,H);vec4 K=texture2D(U5,H);bool L=K.r>0.5;bool M=K.g>0.5;bool N=K.b>0.5;vec4 O=texture2D(U2,H);int P=int(O.r*255.+0.5)+int(O.g*255.+0.5)*256;int Q=int(mod(float(P),U1.x));int R=P/int(U1.x);float S=(U1.y-1.)-float(R);vec2 T=vec2(float(Q),S)/U1;vec4 U=texture2D(U6,H);float V=U.r*255.+U.g;float W=-(V*360./255.)*0.017453292;vec2 X=fract(F)-0.5;if(M)X.x=-X.x;if(N)X.y=-X.y;X=A(W)*X+0.5;vec2 Y=1./U1;vec2 Z=T+X*Y;vec2 a=T+Y;if(any(lessThan(Z,T))||any(greaterThan(Z,a))){gl_FragColor=L?I:J;return;}vec4 b=texture2D(U0,Z);if(L)b.rgb=1.-b.rgb;gl_FragColor=mix(J,I,b);}"),this.se=new $(this.vt,j,`#version 300 es
11
11
  precision highp float;in vec2 v_uv;uniform sampler2D Uk;uniform bool Ul;uniform bool Um;uniform bool Un;uniform vec2 Uo;uniform bool Up;uniform vec3 Uq;uniform bool Ur;uniform vec3 Us;uniform vec4 Ut;uniform int Uu;uniform vec3 Uv[64];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;float A(vec3 B){return dot(B,vec3(0.299f,0.587f,0.114f));}void main(){vec2 C=vec2(v_uv.x,1.0f-v_uv.y);vec4 D=texture(Uk,C);float E=A(D.rgb);if(Uu>0){float F=float(Uu);float G=clamp(E*(F-1.0f),0.0f,F-1.0f);int H=int(floor(G+0.5f));vec3 I=Uv[H];o_character=vec4(I,1.0f);}else{o_character=vec4(E,0.0f,0.0f,1.0f);}vec3 J=D.rgb;vec3 K=Up?Uq:J;vec3 L=Ur?Us:J;float M=1.0f;float N=1.0f;if(D.a<0.01f){K=Ut.rgb;L=Ut.rgb;}o_primaryColor=vec4(K,M);o_secondaryColor=vec4(L,N);o_rotation=vec4(Uo.xy,0.0f,1.0f);o_transform=vec4(float(Ul),float(Um),float(Un),1.0f);}`)}ie(){return this.Qt}Tt(){return this.te}re(){return this.ee}ne(){return this.se}oe(t){return new $(this.vt,j,t)}ae(t,i){return new $(this.vt,t,i)}kt(){this.Qt.kt(),this.te.kt(),this.ee.kt(),this.se.kt()}}var R=(c=>(c.RECTANGLE="rectangle",c.LINE="line",c.ELLIPSE="ellipse",c.ARC="arc",c.TRIANGLE="triangle",c.BEZIER_CURVE="bezier_curve",c.CUSTOM="custom",c))(R||{});class xt{constructor(t){l(this,"vt");l(this,"he",new Map);this.vt=t}ce(t,i,r,n){const o=this.vt;let h=this.he.get(t);h||(h=new Map,this.he.set(t,h));let a=h.get(i)||null;if(!a){a=o.createVertexArray(),h.set(i,a),o.bindVertexArray(a),o.bindBuffer(o.ARRAY_BUFFER,n);const u=o.getAttribLocation(t,"a_position");u!==-1&&(o.enableVertexAttribArray(u),o.vertexAttribPointer(u,r.ue.le.size,o.FLOAT,!1,r.fe,r.ue.le.offset),o.vertexAttribDivisor(u,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,r.ue.de.size,o.FLOAT,!1,r.fe,r.ue.de.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(a)}_e(){this.vt.bindVertexArray(null)}kt(){for(const[,t]of this.he)for(const[,i]of t)i&&this.vt.deleteVertexArray(i)}}class yt{constructor(t,i){l(this,"pe");l(this,"vt");l(this,"xt");l(this,"me",null);l(this,"ge",null);this.vt=t,this.pe=new xt(t),this.xt=i}ve(t,i,r){const{shader:n}=t,o=Y(this.vt)||this.vt.getParameter(this.vt.VIEWPORT);n.Nt({U9:o[2]/o[3],Uy:[o[2],o[3]]});const h=f=>{if(!f||!f.ye())return;const d=f.unitGeometry,g=f.unitBuffer;try{this.pe.ce(n.Jt,f.type+"",d,g),f.batch.Ce(n),f.batch.we(d.$e,d.be)}finally{f.batch.xe(n),this.pe._e(),f.Me()}};let a=null,u=null;for(const f of i){if(f.type===R.CUSTOM){u&&(h(u),a=null,u=null),this.Re(t,f.params,f.state,r.get(R.RECTANGLE));continue}a!==null&&f.type!==a&&(h(u),a=null,u=null);let d=u;d&&f.type===a||(d=r.get(f.type)||null,u=d,a=f.type),d&&d.Fe(f.params,f.state)}h(u)}Re(t,i,r,n){const{x:o,y:h,width:a,height:u,shader:f,uniforms:d}=i,g=this.Se(Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)));g.begin(),this.Ae(n,f,d,0,0,g.width,g.height,{}),g.end();const m=this.ze(),y={Ue:g.textures[0],Uf:g.textures[1],Ug:g.textures[2],Uh:g.textures[3],Ui:g.textures[4],Uj:[g.width,g.height]};this.Ae(n,m,y,Math.floor(o),Math.floor(h),Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)),r),t.shader.Vt()}Ae(t,i,r,n,o,h,a,u){i.Vt(),i.Nt(r);const f=this.vt.getParameter(this.vt.VIEWPORT);if(i.Nt({U9:f[2]/f[3],Uy:[f[2],f[3]]}),t.Me(),t.Fe({x:n,y:o,width:h,height:a},u),t.ye()){const d=t.unitGeometry,g=t.unitBuffer;try{this.pe.ce(i.Jt,t.type+"",d,g),t.batch.Ce(i),t.batch.we(d.$e,d.be)}finally{t.batch.xe(i),this.pe._e(),t.Me()}}}ze(){return this.xt.ie()}Se(t,i){return this.me&&this.ge&&this.ge.w===t&&this.ge.h===i||(this.me&&this.me.kt(),this.me=new V(this.vt,t,i,5),this.ge={w:t,h:i}),this.me}kt(){this.pe.kt(),this.me&&this.me.kt()}}class Et{constructor(){l(this,"Te",[]);l(this,"Ee",1);l(this,"Le",0)}Pe(t){if(this.Le>=this.Te.length){const r={id:this.Ee++,type:t,params:{},state:{O:1,H:0,V:0,K:0,j:[0,0,0],Y:[1,1,1,1],q:[0,0,0,1],N:!1,X:!1,k:!1,G:[0,0]}};this.Te.push(r)}const i=this.Te[this.Le];return i.id=this.Ee++,i.type=t,this.Le++,i}ke(t,i,r,n,o){const h=this.Pe(R.RECTANGLE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Ge(t,i,r,n,o,h,a){const u=this.Pe(R.CUSTOM);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.shader=o,u.params.uniforms=h,a.J(u.state),u.id}Be(t,i,r,n,o,h){const a=this.Pe(R.LINE);return a.params.x1=t,a.params.y1=i,a.params.x2=r,a.params.y2=n,a.params.thickness=o,h.J(a.state),a.id}De(t,i,r,n,o){const h=this.Pe(R.ELLIPSE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Ie(t,i,r,n,o,h,a){const u=this.Pe(R.ARC);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.start=o,u.params.stop=h,a.J(u.state),u.id}We(t,i,r,n,o,h,a){const u=this.Pe(R.TRIANGLE);return u.params.x1=t,u.params.y1=i,u.params.x2=r,u.params.y2=n,u.params.x3=o,u.params.y3=h,a.J(u.state),u.id}Oe(t,i,r,n,o,h,a,u,f,d){const g=this.Pe(R.BEZIER_CURVE);return g.params.x1=t,g.params.y1=i,g.params.cp1x=r,g.params.cp1y=n,g.params.cp2x=o,g.params.cp2y=h,g.params.x2=a,g.params.y2=u,g.params.thickness=f,d.J(g.state),g.id}get length(){return this.Le}get isEmpty(){return this.Le===0}He(){this.Le=0}[Symbol.iterator](){let t=0;const i=this.Le,r=this.Te;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const M=class M{static Ve(t,i,r=0){var h,a,u,f,d,g,m,y,x,p;const n=i||new Float32Array(M.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.le[0],n[o++]=t.le[1],n[o++]=t.Le[0],n[o++]=t.Le[1],n[o++]=t.j[0],n[o++]=t.j[1],n[o++]=t.j[2],n[o++]=t.Y[0],n[o++]=t.Y[1],n[o++]=t.Y[2],n[o++]=t.Y[3],n[o++]=t.q[0],n[o++]=t.q[1],n[o++]=t.q[2],n[o++]=t.q[3],n[o++]=t.G[0],n[o++]=t.G[1],n[o++]=t.Ke[0],n[o++]=t.Ke[1],n[o++]=t.Ke[2],n[o++]=t.H,n[o++]=t.V,n[o++]=t.K,n[o++]=t.Ne[0],n[o++]=t.Ne[1],n[o++]=((h=t.Xe)==null?void 0:h[0])||0,n[o++]=((a=t.Xe)==null?void 0:a[1])||0,n[o++]=((u=t.je)==null?void 0:u[0])||0,n[o++]=((f=t.je)==null?void 0:f[1])||0,n[o++]=((d=t.Ye)==null?void 0:d[0])||0,n[o++]=((g=t.Ye)==null?void 0:g[1])||0,n[o++]=((m=t.qe)==null?void 0:m[0])||0,n[o++]=((y=t.qe)==null?void 0:y[1])||0,n[o++]=((x=t.Ze)==null?void 0:x[0])||0,n[o++]=((p=t.Ze)==null?void 0:p[1])||0,n}static Je(t){const i=t.length*M.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*M.FLOATS_PER_INSTANCE;M.Ve(t[n],r,o)}return r}};l(M,"BYTES_PER_INSTANCE",140),l(M,"FLOATS_PER_INSTANCE",35);let D=M;const _=class _{};l(_,"STRIDE",D.BYTES_PER_INSTANCE),l(_,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:132,divisor:1}});let K=_;class wt{constructor(t,i=1e3,r=1.5){l(this,"vt");l(this,"Qe",[]);l(this,"ts");l(this,"es");l(this,"ss",null);l(this,"rs",!0);l(this,"ns",0);l(this,"hs",new Map);l(this,"cs",null);this.vt=t,this.ts=i,this.es=r,this.ls()}Fe(t){const i=this.Qe.length;return this.Qe.push(t),this.rs=!0,i}get count(){return this.Qe.length}get isEmpty(){return this.Qe.length===0}clear(){this.Qe.length=0,this.rs=!0}us(t){if(t<=this.ts)return;const i=Math.ceil(t*this.es);this.ts=i,this.ls()}ls(){const t=this.vt;this.ss&&t.deleteBuffer(this.ss),this.ss=t.createBuffer();const i=this.ts*D.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.ss),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.rs=!0,this.ns=0}fs(){if(!this.rs||this.Qe.length===0)return;const t=this.vt,i=this.Qe.length;this.us(i),(!this.cs||this.cs.length<i*D.FLOATS_PER_INSTANCE)&&(this.cs=new Float32Array(i*D.FLOATS_PER_INSTANCE));const r=D.Je(this.Qe);t.bindBuffer(t.ARRAY_BUFFER,this.ss),i<=this.ns?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.rs=!1,this.ns=i}ds(t){let i=this.hs.get(t);if(!i){i=new Map;const r=this.vt;for(const n in K.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.hs.set(t,i)}return i}Ce(t){if(!this.ss||this.Qe.length===0)return;const i=this.vt,r=t.Jt;this.fs();const n=this.ds(r);i.bindBuffer(i.ARRAY_BUFFER,this.ss);for(const[o,h]of n){const a=K.ATTRIBUTES[o];a&&(i.enableVertexAttribArray(h),i.vertexAttribPointer(h,a.size,a.type,a.normalized,a.stride,a.offset),i.vertexAttribDivisor(h,a.divisor))}}xe(t){const i=this.vt,r=this.ds(t.Jt);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}we(t,i){this.Qe.length!==0&&this.vt.drawArraysInstanced(t,0,i,this.Qe.length)}kt(){this.ss&&this.vt.deleteBuffer(this.ss)}}class k{constructor(t,i,r,n){l(this,"vt");l(this,"_s");l(this,"ps");l(this,"gs");l(this,"vs",null);this.vt=t,this._s=i,this.ps=r,this.gs=n;const o=this.vt.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.vt.bindBuffer(this.vt.ARRAY_BUFFER,o),this.vt.bufferData(this.vt.ARRAY_BUFFER,this.gs.Cs,this.vt.STATIC_DRAW),this.vt.bindBuffer(this.vt.ARRAY_BUFFER,null),this.vs=o}get type(){return this.ps}get unitGeometry(){return this.gs}get unitBuffer(){return this.vs}get batch(){return this._s}Me(){this._s.clear()}ye(){return!this._s.isEmpty}kt(){this._s.kt(),this.vt.deleteBuffer(this.vs)}ws(t,i,r,n,o){const h=this.$s(t,i,r,n,o.H||0,o.V||0,o.K||0);return{le:[t,i],Le:[r,n],j:o.j||[0,0,0],Y:o.Y||[1,1,1,1],q:o.q||[0,0,0,1],G:o.G||[0,0],Ke:[o.k?1:0,o.N?1:0,o.X?1:0],H:h.radiansX,V:h.radiansY,K:h.radiansZ,Ne:[h.centerX,h.centerY]}}bs(t,i){const r=Y(this.vt)||[0,0,this.vt.canvas.width,this.vt.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}Ms(t,i,r){const n=this.bs(i,r);t.Ne=[n.nx,n.ny]}$s(t,i,r,n,o,h,a){const u=Y(this.vt)||[0,0,this.vt.canvas.width,this.vt.canvas.height],f=u[2],d=u[3];return{centerX:(t+r/2)/f*2-1,centerY:1-(i+n/2)/d*2,radiansX:-o*Math.PI/180,radiansY:-h*Math.PI/180,radiansZ:-a*Math.PI/180,aspectRatio:f/d}}}const bt={Cs:new Float32Array([0,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,1,1,1]),be:6,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Rt extends k{constructor(t,i){super(t,i,R.RECTANGLE,bt)}Fe(t,i){const r=this.ws(t.x,t.y,t.width,t.height,i);return this._s.Fe(r)}}const Tt={Cs:new Float32Array([0,-.5,0,0,1,-.5,1,0,0,.5,0,1,0,.5,0,1,1,-.5,1,0,1,.5,1,1]),be:6,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class At extends k{constructor(t,i){super(t,i,R.LINE,Tt)}Fe(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),h=t.thickness||i.O||1,a=t.x1+r/2,u=t.y1+n/2,f=a-o/2,d=u,g=this.ws(f,d,o,h,i);return this.Ms(g,a,u),this._s.Fe(g)}}const Ct={Cs:function(c=32){const t=[],i=2*Math.PI/c;for(let r=0;r<c;r++){const n=r*i,o=(r+1)%c*i,h=Math.cos(n),a=Math.sin(n),u=.5*(h+1),f=.5*(a+1),d=Math.cos(o),g=Math.sin(o),m=.5*(d+1),y=.5*(g+1);t.push(0,0,.5,.5,h,a,u,f,d,g,m,y)}return new Float32Array(t)}(32),be:96,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class _t extends k{constructor(t,i){super(t,i,R.ELLIPSE,Ct)}Fe(t,i){const r=this.ws(t.x,t.y,t.width,t.height,i);return this.Ms(r,t.x,t.y),this._s.Fe(r)}}let Ut={Cs:function(c){const t=[];for(let i=0;i<c;i++){const r=i/c,n=(i+1)/c;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),be:96,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Lt extends k{constructor(t,i){super(t,i,R.ARC,Ut)}Fe(t,i){const r=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,h=t.stop*Math.PI/180,a=this.ws(r,n,t.width,t.height,i);return this.Ms(a,t.x,t.y),a.Xe=[o,h],this._s.Fe(a)}}const Ft={Cs:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),be:3,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Pt extends k{constructor(t,i){super(t,i,R.TRIANGLE,Ft)}Fe(t,i){const r=Math.min(t.x1,t.x2,t.x3),n=Math.max(t.x1,t.x2,t.x3),o=Math.min(t.y1,t.y2,t.y3),h=n-r,a=Math.max(t.y1,t.y2,t.y3)-o,u=this.ws(r,o,h,a,i),f=r+.5*h,d=o+a*(1/3);return this.Ms(u,f,d),this._s.Fe(u)}}function ht(c,t,i,r,n){const o=1-c,h=o*o,a=c*c;return h*o*t+3*h*c*i+3*o*a*r+a*c*n}const St={Cs:function(c=16){const t=[];for(let i=0;i<c;i++){const r=i/c,n=(i+1)/c;t.push(r,-.5,r,0),t.push(n,-.5,n,0),t.push(r,.5,r,1),t.push(r,.5,r,1),t.push(n,-.5,n,0),t.push(n,.5,n,1)}return new Float32Array(t)}(16),be:96,$e:WebGL2RenderingContext.TRIANGLES,fe:16,ue:{le:{size:2,offset:0},de:{size:2,offset:8}}};class Bt extends k{constructor(t,i){super(t,i,R.BEZIER_CURVE,St)}Fe(t,i){const r=i.O||1,n=ht(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=ht(.5,t.y1,t.cp1y,t.cp2y,t.y2),h=this.ws(0,0,1,r,i);return this.Ms(h,n,o),h.qe=[t.x1,t.y1],h.je=[t.cp1x,t.cp1y],h.Ye=[t.cp2x,t.cp2y],h.Ze=[t.x2,t.y2],this._s.Fe(h)}}class Mt{constructor(t){l(this,"vt");l(this,"Rs",null);l(this,"Fs");l(this,"Ss",null);l(this,"As",{});l(this,"zs",null);l(this,"Ts",new Map);l(this,"Es");l(this,"Ls");l(this,"Ps");l(this,"I",[]);this.vt=t,this.Fs=new vt(t),this.Ps=new nt,this.Es=new yt(t,this),this.Ls=new Et,this.zs=t.createBuffer(),X(this.vt,[0,0,this.vt.canvas.width,this.vt.canvas.height])}ks(t){let i=this.Ts.get(t);if(i)return i;const r=new wt(this.vt);return i=(0,{[R.RECTANGLE]:()=>new Rt(this.vt,r),[R.LINE]:()=>new At(this.vt,r),[R.ELLIPSE]:()=>new _t(this.vt,r),[R.ARC]:()=>new Lt(this.vt,r),[R.TRIANGLE]:()=>new Pt(this.vt,r),[R.BEZIER_CURVE]:()=>new Bt(this.vt,r)}[t])(),this.Ts.set(t,i),i}Gs(t){this.Rs!==t&&(this.Rs=t,t.Vt())}ae(t,i){return this.Fs.ae(t,i)}ie(){return this.Fs.ie()}Tt(){return this.Fs.Tt()}re(){return this.Fs.re()}ne(){return this.Fs.ne()}Bs(t){this.Ss=t,t&&(this.As={})}Xt(t,i){this.As[t]=i}Ds(t){Object.assign(this.As,t)}oe(t){return this.Fs.oe(t)}Is(t,i,r,n,o){const h=this.ie(),a={Ue:t.textures[0],Uf:t.textures[1],Ug:t.textures[2],Uh:t.textures[3],Ui:t.textures[4],Uj:[t.width,t.height]};this.Ls.Ge(i,r,n,o,h,a,this.Ps)}Ws(t,i,r,n,o){const h=this.ne(),a=t.Os(),u={Uk:a.texture,Ul:!!a.invert,Um:!!a.flipX,Un:!!a.flipY,Uo:a.charRotation,Up:a.charColorFixed,Uq:a.charColor,Ur:a.cellColorFixed,Us:a.cellColor,Ut:a.backgroundColor,Uu:a.charCount,Uv:a.charList};this.Ls.Ge(i,r,n,o,h,u,this.Ps)}Hs(t,i,r,n){var p;const o=this.vt,h=o.canvas.width,a=o.canvas.height,u=t/h*2-1,f=(t+r)/h*2-1,d=1-i/a*2,g=1-(i+n)/a*2,m=new Float32Array([u,g,f,g,u,d,f,g,f,d,u,d]);o.bindBuffer(o.ARRAY_BUFFER,this.zs),o.bufferData(o.ARRAY_BUFFER,m,o.DYNAMIC_DRAW);const y=((p=this.Rs)==null?void 0:p.Jt)||o.getParameter(o.CURRENT_PROGRAM),x=y?o.getAttribLocation(y,"a_position"):-1;x!==-1&&(o.enableVertexAttribArray(x),o.vertexAttribPointer(x,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),x!==-1&&o.disableVertexAttribArray(x)}Vs(t,i,r,n){this.Ss?(this.Ls.Ge(t,i,r,n,this.Ss,{...this.As},this.Ps),this.Ss=null,this.As={}):this.Ls.ke(t,i,r,n,this.Ps)}Ks(t,i,r,n){this.Ls.Be(t,i,r,n,this.Ps.lineWeight,this.Ps)}Ns(t,i,r,n){this.Ls.De(t,i,r,n,this.Ps)}Xs(t,i,r,n,o,h){this.Ls.We(t,i,r,n,o,h,this.Ps)}js(t,i,r,n,o,h,a,u){const f=this.Ps.lineWeight;this.Ls.Oe(t,i,r,n,o,h,a,u,f,this.Ps)}Ys(t,i,r=1,n={}){return new V(this.vt,t,i,r,n,this,!0)}qs(t,i,r,n,o,h){this.Ls.Ie(t,i,r,n,o,h,this.Ps)}Zs(t,i=t,r=t,n=255){this.state.ft(t,i,r,n),this.He(t/255,i/255,r/255,n/255)}He(t=0,i=0,r=0,n=0){this.vt.clearColor(t,i,r,n),this.vt.clear(this.vt.COLOR_BUFFER_BIT)}Js(){this.vt.viewport(0,0,this.vt.canvas.width,this.vt.canvas.height),X(this.vt,[0,0,this.vt.canvas.width,this.vt.canvas.height])}get context(){return this.vt}get state(){return this.Ps}Lt(t){this.I.push(this.Ps),this.Ps=t}Pt(){const t=this.I.pop();t&&(this.Ps=t)}Et(t){const i=t,r=Y(this.vt)??this.vt.getParameter(this.vt.VIEWPORT),n={shader:i,gl:this.vt,viewport:r};this.Gs(i);const o=new Set;for(const h of this.Ls)h.type===R.CUSTOM?o.add(R.RECTANGLE):o.add(h.type);for(const h of o)h!==R.CUSTOM&&this.ks(h);this.Es.ve(n,this.Ls,this.Ts),this.Ls.He()}kt(){this.vt.deleteBuffer(this.zs),this.Ls.He();for(const t of this.Ts.values())t.kt();this.Fs.kt(),this.Es.kt()}}const A={readShort:(c,t)=>(A.t.uint16[0]=c[t]<<8|c[t+1],A.t.int16[0]),readUshort:(c,t)=>c[t]<<8|c[t+1],readUshorts(c,t,i){const r=[];for(let n=0;n<i;n++)r.push(A.readUshort(c,t+2*n));return r},readUint(c,t){const i=A.t.uint8;return i[3]=c[t],i[2]=c[t+1],i[1]=c[t+2],i[0]=c[t+3],A.t.uint32[0]},readASCII(c,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(c[t+n]);return r},writeUshort(c,t,i){c[t]=i>>>8&255,c[t+1]=255&i},writeUint(c,t,i){c[t]=i>>>24&255,c[t+1]=i>>>16&255,c[t+2]=i>>>8&255,c[t+3]=255&i},writeASCII(c,t,i){for(let r=0;r<i.length;r++)c[t+r]=255&i.charCodeAt(r)},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()};function q(c){return c+3&-4}function Z(c,t,i){const r=t+i;let n=0;const o=A.t;for(let h=t;h<r;h+=4)o.uint8[3]=c[h]||0,o.uint8[2]=c[h+1]||0,o.uint8[1]=c[h+2]||0,o.uint8[0]=c[h+3]||0,n=n+(o.uint32[0]>>>0)>>>0;return n>>>0}class It{constructor(t){l(this,"b");l(this,"p",0);l(this,"bitbuf",0);l(this,"bitcnt",0);this.b=t}readBits(t){for(;this.bitcnt<t;){const r=this.b[this.p++]||0;this.bitbuf|=r<<this.bitcnt,this.bitcnt+=8}const i=this.bitbuf&(1<<t)-1;return this.bitbuf>>>=t,this.bitcnt-=t,i}alignToByte(){this.bitbuf=0,this.bitcnt=0}get offset(){return this.p}}function W(c){let t=32,i=0;for(const a of c)a&&(a<t&&(t=a),a>i&&(i=a));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const a of c)a&&r[a]++;const n=new Uint32Array(i+1);let o=0;r[0]=0;for(let a=1;a<=i;a++)o=o+r[a-1]<<1,n[a]=o;const h=new Map;for(let a=0;a<c.length;a++){const u=c[a];if(!u)continue;const f=n[u]++;let d=h.get(u);d||(d=[],h.set(u,d)),d[Dt(f,u)]=a}return{min:t,max:i,table:h}}function tt(c,t){let i=0;for(let r=1;r<=t.max;r++){i|=c.readBits(1)<<r-1;const n=t.table.get(r);if(n&&i<n.length){const o=n[i];if(o!==void 0)return o}}throw Error("Invalid Huffman code")}function Dt(c,t){let i=0;for(let r=0;r<t;r++)i=i<<1|1&c,c>>>=1;return i>>>0}function Gt(c){if(c.length<2)throw Error("ZLIB data too short");const t=c[0],i=c[1];if((15&t)!=8)throw Error("Unsupported ZLIB compression method");if(((t<<8)+i)%31!=0)throw Error("Bad ZLIB header check");let r=2;32&i&&(r+=4);const n=[];return function(o,h){const a=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],u=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],f=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],d=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];let g=0;for(;!g;){g=o.readBits(1);const m=o.readBits(2);if(m===0){o.alignToByte();const y=o.readBits(16);if((65535&(65535^y))!==o.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let x=0;x<y;x++)h.push(o.readBits(8))}else{if(m!==1&&m!==2)throw Error("Unsupported DEFLATE type");{let y,x;if(m===1){const p=Array(288).fill(0);for(let E=0;E<=143;E++)p[E]=8;for(let E=144;E<=255;E++)p[E]=9;for(let E=256;E<=279;E++)p[E]=7;for(let E=280;E<=287;E++)p[E]=8;y=W(p),x=W(Array(32).fill(5))}else{const p=o.readBits(5)+257,E=o.readBits(5)+1,v=o.readBits(4)+4,b=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],w=Array(19).fill(0);for(let P=0;P<v;P++)w[b[P]]=o.readBits(3);const F=W(w),U=[];for(;U.length<p+E;){const P=tt(o,F);if(P<=15)U.push(P);else if(P===16){const H=o.readBits(2)+3,O=U[U.length-1]||0;for(let mt=0;mt<H;mt++)U.push(O)}else if(P===17){const H=o.readBits(3)+3;for(let O=0;O<H;O++)U.push(0)}else{if(P!==18)throw Error("Invalid code length symbol");{const H=o.readBits(7)+11;for(let O=0;O<H;O++)U.push(0)}}}const L=U.slice(0,p),S=U.slice(p,p+E);y=W(L),x=W(S)}for(;;){const p=tt(o,y);if(p<256)h.push(p);else{if(p===256)break;if(p>256&&p<286){const E=p-257;let v=a[E];const b=u[E];b&&(v+=o.readBits(b));const w=tt(o,x);if(w>=30)throw Error("Invalid distance symbol");let F=f[w];const U=d[w];U&&(F+=o.readBits(U));const L=h.length-F;if(L<0)throw Error("Invalid distance");for(let S=0;S<v;S++)h.push(h[L+S]||0)}else if(p===286||p===287)throw Error("Reserved length symbol")}}}}}}(new It(c.subarray(r)),n),new Uint8Array(n)}function Ot(c){const t=A,i=new Uint8Array(c);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),n=t.readUshort(i,12),o=t.readUint(i,16),h=[];let a=44;for(let v=0;v<n;v++){const b=t.readASCII(i,a,4),w=t.readUint(i,a+4),F=t.readUint(i,a+8),U=t.readUint(i,a+12),L=t.readUint(i,a+16);h.push({tag:b,offset:w,compLength:F,origLength:U,checksum:L}),a+=20}for(const v of h){const b=new Uint8Array(i.buffer,v.offset,v.compLength);if(v.compLength===v.origLength)v.data=new Uint8Array(b);else if(v.data=Gt(b),v.data.length!==v.origLength)if(v.data.length<v.origLength){const w=new Uint8Array(v.origLength);w.set(v.data),v.data=w}else v.data=v.data.subarray(0,v.origLength)}const u=n;let f=1,d=0;for(;f<<1<=u;)f<<=1,d++;const g=16*f,m=16*u-g;let y=12+16*u;const x={};for(const v of h)x[v.tag]=y,y=q(y+v.data.length);const p=new Uint8Array(Math.max(o||0,y));t.writeUint(p,0,r),t.writeUshort(p,4,u),t.writeUshort(p,6,g),t.writeUshort(p,8,d),t.writeUshort(p,10,m);let E=12;for(const v of h){t.writeASCII(p,E,v.tag),E+=4;let b=v.data;if(v.tag==="head"&&b.length>=12){const w=new Uint8Array(b);t.writeUint(w,8,0);const F=Z(w,0,q(w.length));t.writeUint(p,E,F),E+=4}else{const w=Z(b,0,q(b.length));t.writeUint(p,E,w),E+=4}t.writeUint(p,E,x[v.tag]),E+=4,t.writeUint(p,E,v.data.length),E+=4}for(const v of h){const b=x[v.tag];p.set(v.data,b)}if(h.find(v=>v.tag==="head")){const v=x.head,b=function(w,F){const U=A,L=F+8,S=[w[L],w[L+1],w[L+2],w[L+3]];U.writeUint(w,L,0);const P=2981146554-(Z(w,0,q(w.length))>>>0)>>>0;return w[L]=S[0],w[L+1]=S[1],w[L+2]=S[2],w[L+3]=S[3],P>>>0}(p,v);t.writeUint(p,v+8,b)}return p.buffer}const $t={parseTab(c,t,i){const r={tables:[],ids:{},off:t};c=new Uint8Array(c.buffer,t,i),t=0;const n=A,o=n.readUshort,h=o(c,t+=2);t+=2;const a=[];for(let u=0;u<h;u++){const f=o(c,t),d=o(c,t+=2);t+=2;const g=n.readUint(c,t);t+=4;const m=`p${f}e${d}`;let y=a.indexOf(g);if(y===-1){let x;y=r.tables.length,a.push(g);const p=o(c,g);x=p===4?this.parse4(c,g):p===12?this.parse12(c,g):{format:p},r.tables.push(x)}r.ids[m]=y}return r},parse4(c,t){const i=A,r=i.readUshort,n=i.readUshorts,o=t,h=r(c,t+=2);t+=2;const a=r(c,t+=2)>>>1,u={format:4,searchRange:r(c,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,u.entrySelector=r(c,t),t+=2,u.rangeShift=r(c,t),t+=2,u.endCount=n(c,t,a),t+=2*a,t+=2,u.startCount=n(c,t,a),t+=2*a;for(let f=0;f<a;f++)u.idDelta.push(i.readShort(c,t)),t+=2;return u.idRangeOffset=n(c,t,a),t+=2*a,u.glyphIdArray=n(c,t,o+h-t>>1),u},parse12(c,t){const i=A.readUint;i(c,t+=4),i(c,t+=4);const r=i(c,t+=4);t+=4;const n=new Uint32Array(3*r);for(let o=0;o<3*r;o+=3)n[o]=i(c,t+(o<<2)),n[o+1]=i(c,t+(o<<2)+4),n[o+2]=i(c,t+(o<<2)+8);return{format:12,groups:n}}},kt={parseTab(c,t,i){const r=A;t+=18;const n=r.readUshort(c,t);t+=2,t+=16;const o=r.readShort(c,t);t+=2;const h=r.readShort(c,t);t+=2;const a=r.readShort(c,t);t+=2;const u=r.readShort(c,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:h,xMax:a,yMax:u,indexToLocFormat:r.readShort(c,t)}}},Nt={parseTab(c,t,i){const r=A;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let h=0;h<n.length;h++){const a=n[h],u=a==="advanceWidthMax"||a==="numberOfHMetrics"?r.readUshort:r.readShort;o[a]=u(c,t+2*h)}return o}},zt={parseTab(c,t,i,r){const n=A,o=[],h=[],a=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,d=0,g=0;for(;g<u;)f=n.readUshort(c,t+(g<<2)),d=n.readShort(c,t+(g<<2)+2),o.push(f),h.push(d),g++;for(;g<a;)o.push(f),h.push(d),g++;return{aWidth:o,lsBearing:h}}},at={cmap:$t,head:kt,hhea:Nt,maxp:{parseTab(c,t,i){const r=A;return r.readUint(c,t),t+=4,{numGlyphs:r.readUshort(c,t)}}},hmtx:zt,loca:{parseTab(c,t,i,r){const n=A,o=[],h=r.head.indexToLocFormat,a=r.maxp.numGlyphs+1;if(h===0)for(let u=0;u<a;u++)o.push(n.readUshort(c,t+(u<<1))<<1);else if(h===1)for(let u=0;u<a;u++)o.push(n.readUint(c,t+(u<<2)));return o}},glyf:{parseTab(c,t,i,r){const n=[],o=r.maxp.numGlyphs;for(let h=0;h<o;h++)n.push(null);return n},Qs(c,t){const i=A,r=c.ti,n=c.loca;if(n[t]===n[t+1])return null;const o=B.findTable(r,"glyf",c.ei);if(!o)return null;let h=o[0]+n[t];const a={};if(a.noc=i.readShort(r,h),h+=2,a.xMin=i.readShort(r,h),h+=2,a.yMin=i.readShort(r,h),h+=2,a.xMax=i.readShort(r,h),h+=2,a.yMax=i.readShort(r,h),h+=2,a.xMin>=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(let m=0;m<a.noc;m++)a.endPts.push(i.readUshort(r,h)),h+=2;const u=i.readUshort(r,h);if(h+=2,r.length-h<u)return null;h+=u;const f=a.endPts[a.noc-1]+1;a.flags=[];for(let m=0;m<f;m++){const y=r[h];if(h++,a.flags.push(y),8&y){const x=r[h];h++;for(let p=0;p<x;p++)a.flags.push(y),m++}}a.xs=[];for(let m=0;m<f;m++){const y=a.flags[m],x=!!(16&y);2&y?(a.xs.push(x?r[h]:-r[h]),h++):x?a.xs.push(0):(a.xs.push(i.readShort(r,h)),h+=2)}a.ys=[];for(let m=0;m<f;m++){const y=a.flags[m],x=!!(32&y);4&y?(a.ys.push(x?r[h]:-r[h]),h++):x?a.ys.push(0):(a.ys.push(i.readShort(r,h)),h+=2)}let d=0,g=0;for(let m=0;m<f;m++)d+=a.xs[m],g+=a.ys[m],a.xs[m]=d,a.ys[m]=g}else a.parts=[],a.endPts=[],a.flags=[],a.xs=[],a.ys=[];return a}}},B={parse(c){const t=new Uint8Array(c),i=A.readASCII(t,0,4);if(i==="wOFF")c=Ot(c);else if(i==="wOF2")throw Error("WOFF2 is not supported in this build (Brotli + WOFF2 transforms required)");return[((r,n,o,h)=>{const a=at,u={ti:r,si:n,ei:o};for(const f in a){const d=f,g=B.findTable(r,d,o);if(g){const[m,y]=g;let x=h[m];x==null&&(x=a[d].parseTab(r,m,y,u),h[m]=x),u[d]=x}}return u})(new Uint8Array(c),0,0,{})]},findTable(c,t,i){const r=A,n=r.readUshort(c,i+4);let o=i+12;for(let h=0;h<n;h++){const a=r.readASCII(c,o,4);r.readUint(c,o+4);const u=r.readUint(c,o+8),f=r.readUint(c,o+12);if(a===t)return[u,f];o+=16}return null},T:at,B:A};class Wt{ii(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ri(n);i.push(...o)}else if(n.format===12){const o=this.ni(n);i.push(...o)}}),[...new Set(i)]):[]}oi(t){return t.filter(i=>this.ai(i))}ri(t){const i=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return i;for(let r=0;r<t.startCount.length;r++){const n=t.startCount[r],o=t.endCount[r];if(n!==65535||o!==65535){for(let h=n;h<=o;h++)if(this.hi(t,h,r)>0)try{const a=String.fromCodePoint(h);i.push(a)}catch{}}}return i}ni(t){const i=[];if(!t.groups)return i;for(let r=0;r<t.groups.length;r+=3){const n=t.groups[r],o=t.groups[r+1],h=t.groups[r+2];for(let a=n;a<=o;a++)if(h+(a-n)>0)try{const u=String.fromCodePoint(a);i.push(u)}catch{}}return i}hi(t,i,r){if(t.idRangeOffset[r]===0)return i+t.idDelta[r]&65535;{const n=t.idRangeOffset[r]/2+(i-t.startCount[r])-(t.startCount.length-r);if(n>=0&&t.glyphIdArray&&n<t.glyphIdArray.length){const o=t.glyphIdArray[n];if(o!==0)return o+t.idDelta[r]&65535}}return 0}ai(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class et{constructor(){l(this,"ci",new Map);l(this,"li",new Map)}ui(t,i){const r=`${this.fi(t)}_${i}`;if(this.ci.has(r))return this.ci.get(r);const n=t.cmap;if(!n||!n.tables)return this.ci.set(r,0),0;let o=0;for(const h of n.tables)if(h.format===4?o=this.di(i,h):h.format===12&&(o=this._i(i,h)),o>0)break;return this.ci.set(r,o),o}pi(t,i){const r=i.codePointAt(0);return r===void 0?0:this.ui(t,r)}mi(t,i){const r=t.hmtx;return r&&r.aWidth&&r.aWidth.length!==0?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}gi(t,i){const r=i/t.head.unitsPerEm,n=t.hhea.ascender*r,o=t.hhea.descender*r,h=t.hhea.lineGap*r;return{ascender:n,descender:o,lineGap:h,lineHeight:n-o+h,unitsPerEm:t.head.unitsPerEm,scale:r}}yi(){this.ci.clear(),this.li.clear()}fi(t){return`${t.ei}_${t.ti.length}`}di(t,i){const r=i.endCount.length;let n=-1;for(let o=0;o<r;o++)if(t<=i.endCount[o]){n=o;break}if(n===-1||t<i.startCount[n])return 0;if(i.idRangeOffset[n]===0)return t+i.idDelta[n]&65535;{const o=i.idRangeOffset[n]/2+(t-i.startCount[n])-(r-n);if(o>=0&&o<i.glyphIdArray.length){const h=i.glyphIdArray[o];return h===0?0:h+i.idDelta[n]&65535}}return 0}_i(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const o=i.groups[3*n],h=i.groups[3*n+1],a=i.groups[3*n+2];if(t>=o&&t<=h)return a+(t-o)}return 0}}class Ht{constructor(t){l(this,"Ci");l(this,"wi");l(this,"xt");l(this,"$i");this.xt=t,this.$i=new et,this.Ci=document.createElement("canvas"),this.wi=this.Ci.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(t,i,r,n){const o=t.length,h=Math.ceil(Math.sqrt(o)),a=Math.ceil(o/h),u=i.width*h,f=i.height*a,d=typeof n=="object"?n:null;this.bi(u,f),this.xi(t,i,h,r,d);const g=this.xt.Ys(u,f,1,{filter:"nearest"});return g.At(this.Ci),{framebuffer:g,columns:h,rows:a}}bi(t,i){this.Ci.width=t,this.Ci.height=i,this.Ci.style.width=t+"px",this.Ci.style.height=t+"px",this.wi.imageSmoothingEnabled=!1,this.Ci.style.imageRendering="pixelated",this.wi.fillStyle="black",this.wi.fillRect(0,0,t,i),this.wi.textBaseline="top",this.wi.textAlign="left",this.wi.fillStyle="white"}xi(t,i,r,n,o){const h=n/o.head.unitsPerEm;for(let a=0;a<t.length;a++){const u=a%r,f=Math.floor(a/r),d=t[a].character,g=this.Mi(o,d);if(!g)continue;const m=d.codePointAt(0)||0,y=this.$i.ui(o,m),x=this.Ri(o,y)*h,p=u*i.width,E=f*i.height,v=p+.5*i.width,b=E+.5*i.height,w=Math.round(v-.5*i.width),F=Math.round(b-.5*n),U=w+.5*(i.width-x),L=F+o.hhea.ascender*h;this.Fi(g,U,L,h)}}Mi(t,i){const r=i.codePointAt(0)||0,n=this.$i.ui(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(B&&B.T&&B.T.glyf){const o=B.T.glyf.Qs(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}Ri(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}Fi(t,i,r,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:h,endPts:a,flags:u}=t;if(!(o&&h&&a&&u))return;this.wi.beginPath();let f=0;for(let d=0;d<a.length;d++){const g=a[d];if(!(g<f)){if(g>=f){const m=i+o[f]*n,y=r-h[f]*n;this.wi.moveTo(m,y);let x=f+1;for(;x<=g;)if(1&u[x]){const p=i+o[x]*n,E=r-h[x]*n;this.wi.lineTo(p,E),x++}else{const p=i+o[x]*n,E=r-h[x]*n;let v=x+1>g?f:x+1;if(1&u[v]){const b=i+o[v]*n,w=r-h[v]*n;this.wi.quadraticCurveTo(p,E,b,w),x=v+1}else{const b=(p+(i+o[v]*n))/2,w=(E+(r-h[v]*n))/2;this.wi.quadraticCurveTo(p,E,b,w),x=v}}this.wi.closePath()}f=g+1}}this.wi.fill()}}class Xt{constructor(){l(this,"Si");this.Si=new et}Ai(t,i,r){let n=0;const o=this.Si.gi(r,i),h=o.lineHeight;for(const a of t){const u=this.Si.pi(r,a);if(u===0)continue;const f=this.Si.mi(r,u)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(h)}}yi(){this.Si.yi()}}class Yt{constructor(){l(this,"$i");this.$i=new et}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,h=this.zi(n);let a=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.$i.ui(i,o);u>0&&i.hmtx.aWidth[u]!==void 0&&(a=i.hmtx.aWidth[u])}return{character:r,unicode:o,color:h,advanceWidth:a}})}zi(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}Ti(t,i){if(!z.v(typeof t=="string","Character must be a string.",{method:"getCharacterColor",providedValue:t}))return[0,0,0];const r=i.find(n=>n.character===t);return r?r.color:[0,0,0]}Ei(t,i){return z.v(typeof t=="string"&&t.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:t})?Array.from(t).map(r=>this.Ti(r,i)||[0,0,0]):[[0,0,0]]}}class ct{constructor(t,i=16){l(this,"Li");l(this,"Pi",[]);l(this,"ki");l(this,"Gi",16);l(this,"Bi",0);l(this,"Di",0);l(this,"Ii",{width:0,height:0});l(this,"Wi");l(this,"Oi");l(this,"Hi");l(this,"Vi");l(this,"Ki");this.Gi=i,this.Oi=new Wt,this.Hi=new Ht(t),this.Vi=new Xt,this.Ki=new Yt}async Ni(t){let i;if(!t)throw new T("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const r=await fetch(t);if(!r.ok)throw new T(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}await this.Xi(i),this.Li=B.parse(i)[0],await this.ji()}Yi(t){if(t===void 0)return this.Gi;this.Gi=t,this.Ii=this.Vi.Ai(this.Pi.map(r=>r.character),this.Gi,this.Li);const i=this.Hi.createTextureAtlas(this.Pi,this.Ii,this.Gi,this.Li);this.ki=i.framebuffer,this.Bi=i.columns,this.Di=i.rows}async qi(t){try{const i=await fetch(t);if(!i.ok)throw new T(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.Xi(r);const n=B.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.Li=n[0],await this.ji()}catch(i){throw new T("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async Xi(t){const i=Date.now();this.Wi=new FontFace("CustomFont_"+i,t),await this.Wi.load(),document.fonts.add(this.Wi)}async ji(){const t=this.Oi.ii(this.Li),i=this.Oi.oi(t);this.Pi=this.Ki.createCharacterObjects(i,this.Li),this.Ii=this.Vi.Ai(i,this.Gi,this.Li);const r=this.Hi.createTextureAtlas(this.Pi,this.Ii,this.Gi,this.Li);this.ki=r.framebuffer,this.Bi=r.columns,this.Di=r.rows}Ti(t){return this.Ki.Ti(t,this.Pi)}Ei(t){return this.Ki.Ei(t,this.Pi)}kt(){this.ki.kt(),document.fonts.delete(this.Wi)}get fontFramebuffer(){return this.ki}get characters(){return this.Pi}get textureColumns(){return this.Bi}get textureRows(){return this.Di}get maxGlyphDimensions(){return this.Ii}get fontSize(){return this.Gi}get font(){return this.Li}}class lt{constructor(t,i,r){l(this,"Zi");l(this,"Ji");l(this,"dt");l(this,"_t");l(this,"Qi");l(this,"tr");l(this,"er");l(this,"sr");l(this,"ir");this.er=t,this.sr=i,this.ir=r,this.rr()}rr(){this.Zi=Math.floor(this.er.width/this.sr),this.Ji=Math.floor(this.er.height/this.ir),this.dt=this.Zi*this.sr,this._t=this.Ji*this.ir,this.Qi=Math.floor((this.er.width-this.dt)/2),this.tr=Math.floor((this.er.height-this._t)/2)}nr(t,i){this.sr=t,this.ir=i,this.rr()}get cellWidth(){return this.sr}get cellHeight(){return this.ir}get cols(){return this.Zi}get rows(){return this.Ji}get width(){return this.dt}get height(){return this._t}get offsetX(){return this.Qi}get offsetY(){return this.tr}}class ut{constructor(t={}){l(this,"er");l(this,"ar",null);l(this,"hr",!1);l(this,"cr");l(this,"lr");this.hr=t.overlay??!1,this.hr&&t.canvas?(this.ar=t.canvas,this.er=this.ur(),this.lr=!0,this.dr()):t.canvas?(this.er=t.canvas,this.lr=!1):(this.er=this._r(t.width,t.height),this.lr=!0),this.er.style.imageRendering="pixelated"}_r(t,i){const r=document.createElement("canvas");return r.className="textmodeCanvas",r.style.imageRendering="pixelated",r.width=t||800,r.height=i||600,document.body.appendChild(r),r}ur(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.ar.getBoundingClientRect();let r=Math.round(i.width),n=Math.round(i.height);if(this.ar instanceof HTMLVideoElement){const a=this.ar;(r===0||n===0)&&a.videoWidth>0&&a.videoHeight>0&&(r=a.videoWidth,n=a.videoHeight)}t.width=r,t.height=n,t.style.position="absolute",t.style.pointerEvents="none";const o=window.getComputedStyle(this.ar);let h=parseInt(o.zIndex||"0",10);return isNaN(h)&&(h=0),t.style.zIndex=""+(h+1),t}dr(){var t;this.pr(),(t=this.ar.parentNode)==null||t.insertBefore(this.er,this.ar.nextSibling),window.ResizeObserver&&(this.cr=new ResizeObserver(()=>{this.mr()}),this.cr.observe(this.ar)),window.addEventListener("resize",()=>{this.mr()})}pr(){if(!this.ar)return;const t=this.ar.getBoundingClientRect();let i=this.ar.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.er.style.top=t.top-r.top+"px",this.er.style.left=t.left-r.left+"px"}else this.er.style.top=t.top+window.scrollY+"px",this.er.style.left=t.left+window.scrollX+"px"}mr(t,i){if(this.hr){const r=this.ar.getBoundingClientRect();let n=Math.round(r.width),o=Math.round(r.height);if(this.ar instanceof HTMLVideoElement){const h=this.ar;(n===0||o===0)&&h.videoWidth>0&&h.videoHeight>0&&(n=h.videoWidth,o=h.videoHeight)}this.er.width=n,this.er.height=o,this.pr()}else this.er.width=t??this.er.width,this.er.height=i??this.er.height}gr(){const t=this.er.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new T("`textmode.js` requires WebGL2 support.");return t}kt(){this.cr&&this.cr.disconnect();const t=this.er.getContext("webgl")||this.er.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.lr&&this.er.parentNode&&this.er.parentNode.removeChild(this.er)}get canvas(){return this.er}get targetCanvas(){return this.ar}get width(){return this.er.width}get height(){return this.er.height}}class N{constructor(t,i,r,n){l(this,"vr");l(this,"dt");l(this,"_t");l(this,"vt");l(this,"k",0);l(this,"N",0);l(this,"X",0);l(this,"G",[0,0]);l(this,"yr","sampled");l(this,"Cr","fixed");l(this,"Y",[1,1,1]);l(this,"q",[0,0,0]);l(this,"wr",[0,0,0,1]);l(this,"$r",[[.1,0,0]]);l(this,"br");this.vt=t,this.vr=i,this.dt=r,this._t=n}kt(){this.vt.deleteTexture(this.vr)}Mr(t){return typeof t=="boolean"?t?1:0:(t==null?0:Number(t))>0?1:0}invert(t=!0){return this.k=this.Mr(t),this}flipX(t=!0){return this.N=this.Mr(t),this}flipY(t=!0){return this.X=this.Mr(t),this}charRotation(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));return this.G=[r,n],this}Os(){return{texture:this.vr,invert:this.k,flipX:this.N,flipY:this.X,charRotation:this.G,charColorFixed:this.yr==="fixed",charColor:this.Y,cellColorFixed:this.Cr==="fixed",cellColor:this.q,backgroundColor:this.wr,charCount:this.$r.length,charList:this.$r}}charColorMode(t){return this.yr=t,this}cellColorMode(t){return this.Cr=t,this}charColor(t,i,r){return this.Y=[(t??0)/255,(i??t??0)/255,(r??t??0)/255],this}cellColor(t,i,r){return this.q=[(t??0)/255,(i??t??0)/255,(r??t??0)/255],this}background(t,i,r,n){return this.wr=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}characters(t){const i=this.br(t).filter(r=>Array.isArray(r)).slice(0,64);return this.$r=i,this}static Rr(t,i,r){const n=t.context,o=n.createTexture();n.bindTexture(n.TEXTURE_2D,o),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,1),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),n.bindTexture(n.TEXTURE_2D,null);const h=i.naturalWidth??i.width??i.videoWidth??0,a=i.naturalHeight??i.height??i.videoHeight??0,u=new N(n,o,h,a);return u.br=r,u}get texture(){return this.vr}get width(){return this.dt}get height(){return this._t}}class Vt{constructor(t=60){l(this,"Fr");l(this,"Sr");l(this,"Ar",null);l(this,"zr",0);l(this,"Tr",!0);l(this,"Er",0);l(this,"Lr",0);l(this,"Pr",[]);l(this,"kr",10);l(this,"Gr",0);this.Fr=t,this.Sr=1e3/t}start(t){if(!this.Tr)return;this.zr=performance.now();const i=r=>{if(!this.Tr)return void(this.Ar=null);const n=r-this.zr;n>=this.Sr&&(t(),this.zr=r-n%this.Sr),this.Tr&&(this.Ar=requestAnimationFrame(i))};this.Ar=requestAnimationFrame(i)}stop(){this.Ar&&(cancelAnimationFrame(this.Ar),this.Ar=null)}pause(){this.Tr&&(this.Tr=!1,this.stop())}resume(t){this.Tr||(this.Tr=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.Er;this.Fr=t,this.Sr=1e3/t,this.Tr&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.Lr>0){const i=t-this.Lr;this.Pr.push(i),this.Pr.length>this.kr&&this.Pr.shift();const r=this.Pr.reduce((n,o)=>n+o,0)/this.Pr.length;this.Er=1e3/r}this.Lr=t}get isLooping(){return this.Tr}get frameRateLimit(){return this.Fr}get currentFrameRate(){return this.Er}get frameCount(){return this.Gr}set frameCount(t){this.Gr=t}incrementFrame(){this.Gr++}resetFrameCount(){this.Gr=0}}class jt{constructor(){l(this,"Br",new Map);l(this,"Dr",null);l(this,"Ir",null);l(this,"Wr");l(this,"Or");l(this,"Hr",!1);l(this,"Vr");l(this,"Kr");l(this,"Nr",{ArrowUp:"UP_ARROW",ArrowDown:"DOWN_ARROW",ArrowLeft:"LEFT_ARROW",ArrowRight:"RIGHT_ARROW",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",Enter:"ENTER",Return:"RETURN",Tab:"TAB",Escape:"ESCAPE",Backspace:"BACKSPACE",Delete:"DELETE",Insert:"INSERT",Home:"HOME",End:"END",PageUp:"PAGE_UP",PageDown:"PAGE_DOWN",Shift:"SHIFT",Control:"CONTROL",Alt:"ALT",Meta:"META"," ":"SPACE"})}Xr(){this.Hr||(this.Wr=t=>{this.jr(t)},this.Or=t=>{this.Yr(t)},window.addEventListener("keydown",this.Wr,{passive:!1}),window.addEventListener("keyup",this.Or,{passive:!1}),this.Hr=!0)}qr(){this.Hr&&(window.removeEventListener("keydown",this.Wr),window.removeEventListener("keyup",this.Or),this.Hr=!1,this.Br.clear(),this.Dr=null,this.Ir=null)}Zr(t){this.Vr=t}Jr(t){this.Kr=t}Qr(t){const i=this.tn(t),r=this.Br.get(t)||this.Br.get(i);return(r==null?void 0:r.isPressed)||!1}en(){return this.Dr}sn(){return this.Ir}rn(){const t=[];for(const[i,r]of this.Br)r.isPressed&&t.push(i);return t}nn(){return{ctrl:this.Qr("Control"),shift:this.Qr("Shift"),alt:this.Qr("Alt"),meta:this.Qr("Meta")}}an(){this.Br.clear(),this.Dr=null,this.Ir=null}jr(t){const i=t.key,r=Date.now();this.Br.has(i)||this.Br.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.Br.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.Dr=i,this.Vr)){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.Vr(o)}}Yr(t){const i=t.key,r=Date.now();this.Br.has(i)||this.Br.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.Br.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.Ir=i,this.Kr){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.Kr(o)}}tn(t){return this.Nr[t]||t.toLowerCase()}}class Kt{constructor(t){l(this,"er");l(this,"hn");l(this,"cn",{x:-1,y:-1});l(this,"ln",{x:-1,y:-1});l(this,"un",null);l(this,"fn");l(this,"dn");l(this,"_n");l(this,"pn");l(this,"mn");l(this,"gn");l(this,"Hr",!1);l(this,"vn");l(this,"yn");l(this,"Cn");l(this,"wn");l(this,"$n");this.er=t}Ni(t){this.hn=t,this.bn()}Xr(){if(this.Hr)return;const t=this.er.canvas;this.fn=i=>{this.xn(i),this.Mn(i)},this.dn=()=>{this.ln={...this.cn},this.cn.x=-1,this.cn.y=-1,this.un=null},this._n=i=>{this.xn(i),this.Rn(i)},this.pn=i=>{this.xn(i),this.Fn(i)},this.mn=i=>{this.xn(i),this.Sn(i)},this.gn=i=>{this.xn(i),this.An(i)},t.addEventListener("mousemove",this.fn,{passive:!0}),t.addEventListener("mouseleave",this.dn,{passive:!0}),t.addEventListener("mousedown",this._n,{passive:!0}),t.addEventListener("mouseup",this.pn,{passive:!0}),t.addEventListener("click",this.mn,{passive:!0}),t.addEventListener("wheel",this.gn,{passive:!1}),this.Hr=!0}qr(){if(!this.Hr)return;const t=this.er.canvas;t.removeEventListener("mousemove",this.fn),t.removeEventListener("mouseleave",this.dn),t.removeEventListener("mousedown",this._n),t.removeEventListener("mouseup",this.pn),t.removeEventListener("click",this.mn),t.removeEventListener("wheel",this.gn),this.Hr=!1}bn(){if(this.Hr)try{if(this.un){const t=new MouseEvent("mousemove",{clientX:this.un.x,clientY:this.un.y,bubbles:!1,cancelable:!1});this.xn(t)}else this.cn.x!==-1&&this.cn.y!==-1&&(this.cn.x>=this.hn.cols||this.cn.y>=this.hn.rows)&&(this.cn.x=-1,this.cn.y=-1)}catch{this.cn.x=-1,this.cn.y=-1}}zn(t){this.vn=t}Zr(t){this.yn=t}Jr(t){this.Cn=t}Tn(t){this.wn=t}En(t){this.$n=t}Ln(){return{x:this.cn.x,y:this.cn.y}}Mn(t){if(this.wn){const i={position:{...this.cn},previousPosition:{...this.ln},originalEvent:t};this.wn(i)}}Rn(t){if(this.yn){const i={position:{...this.cn},previousPosition:{...this.ln},button:t.button,originalEvent:t};this.yn(i)}}Fn(t){if(this.Cn){const i={position:{...this.cn},previousPosition:{...this.ln},button:t.button,originalEvent:t};this.Cn(i)}}Sn(t){if(this.vn){const i={position:{...this.cn},previousPosition:{...this.ln},button:t.button,originalEvent:t};this.vn(i)}}An(t){if(this.$n){const i={position:{...this.cn},previousPosition:{...this.ln},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.$n(i)}}xn(t){const i=this.er.canvas;this.ln={...this.cn},this.un={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,o=t.clientY-r.top,h=i.width/r.width,a=o*(i.height/r.height),u=n*h-this.hn.offsetX,f=a-this.hn.offsetY,d=Math.floor(u/this.hn.cellWidth),g=Math.floor(f/this.hn.cellHeight);d>=0&&d<this.hn.cols&&g>=0&&g<this.hn.rows?(this.cn.x=d,this.cn.y=g):(this.cn.x=-1,this.cn.y=-1)}}const qt=c=>class extends c{rotate(t=0,i=0,r=0){this.xt.state.et(t),this.xt.state.st(i),this.xt.state.it(r)}rotateX(t){this.xt.state.et(t)}rotateY(t){this.xt.state.st(t)}rotateZ(t){this.xt.state.it(t)}push(){this.xt.state.W()}pop(){this.xt.state.Z()}rect(t,i,r=1,n=1){this.xt.Vs(t,i,r,n)}point(t,i){this.xt.Vs(t,i,1,1)}line(t,i,r,n){this.xt.Ks(t,i,r,n)}lineWeight(t){this.xt.state.tt(t)}background(t,i=t,r=t,n=255){this.xt.Zs(t,i,r,n)}char(t){this.xt.state.rt(this.Li.Ti(t))}charColor(t,i,r){this.xt.state.nt(t,i,r)}cellColor(t,i,r){this.xt.state.ot(t,i,r)}flipX(t){this.xt.state.ht(t)}flipY(t){this.xt.state.ct(t)}charRotation(t){this.xt.state.ut(t)}invert(t){this.xt.state.lt(t)}clear(){this.xt.Zs(0,0,0,0)}ellipse(t,i,r,n){this.xt.Ns(t,i,r/2,n/2)}triangle(t,i,r,n,o,h){this.xt.Xs(t,i,r,n,o,h)}bezierCurve(t,i,r,n,o,h,a,u){this.xt.js(t,i,r,n,o,h,a,u)}arc(t,i,r,n,o,h){this.xt.qs(t,i,r,n,o,h)}shader(t){this.xt.Bs(t)}setUniform(t,i){this.xt.Xt(t,i)}setUniforms(t){this.xt.Ds(t)}createFilterShader(t){return this.xt.oe(t)}createFramebuffer(t){return this.xt.Ys(t.width,t.height,5,{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"})}image(t,i,r,n,o){if(t.textures){const h=t;this.xt.Is(h,i,r,n??h.width,o??h.height)}else{const h=t;this.xt.Ws(h,i,r,n??Math.floor(this.hn.cols/2),o??Math.floor(this.hn.rows/2))}}async loadImage(t){if(typeof t!="string")return N.Rr(this.xt,t,n=>this.Li.Ei(n));const i=t,r=await new Promise((n,o)=>{const h=new Image;h.crossOrigin="anonymous",h.onload=()=>n(h),h.onerror=a=>o(a),h.src=i});return N.Rr(this.xt,r,n=>this.Li.Ei(n))}};class it{Pn(t){const i=t.zt(0),r=t.zt(1),n=t.zt(2),o=t.zt(3);return{characterPixels:i,primaryColorPixels:r,secondaryColorPixels:n,transformPixels:t.zt(4),rotationPixels:o}}kn(t,i){return t[i]+(t[i+1]<<8)}Gn(t,i){return{r:t[i],g:t[i+1],b:t[i+2],a:t[i+3]}}}class st{Bn(t,i){return new Blob([t],{type:i})}Dn(t,i,r){try{const n=this.Bn(t,r),o=URL.createObjectURL(n),h=document.createElement("a");h.href=o,h.download=i,h.style.display="none",h.rel="noopener",document.body.appendChild(h),h.click(),document.body.removeChild(h),URL.revokeObjectURL(o)}catch(n){console.error("Failed to download file:",n)}}In(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Wn(){const t=new Date;return{date:t.toISOString().split("T")[0],time:t.toTimeString().split(" ")[0].replace(/:/g,"-")}}On(t){return t.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Hn(){return"textmode-export-"+this.In()}}class Jt extends it{Vn(t,i,r){const n=t[r]===255,o=t[r+1]===255,h=t[r+2]===255,a=i[r],u=i[r+1];return{isInverted:n,flipHorizontal:o,flipVertical:h,rotation:Math.round(360*(a+u/255)/255*100)/100}}Kn(t,i,r){return{x:t,y:i,cellX:t*r.cellWidth,cellY:i*r.cellHeight}}Nn(t,i){const r=[];let n=0;for(let o=0;o<i.rows;o++)for(let h=0;h<i.cols;h++){const a=4*n,u=this.kn(t.characterPixels,a);let f=this.Gn(t.primaryColorPixels,a),d=this.Gn(t.secondaryColorPixels,a);const g=this.Vn(t.transformPixels,t.rotationPixels,a);if(g.isInverted){const y=f;f=d,d=y}const m=this.Kn(h,o,i);r.push({charIndex:u,primaryColor:f,secondaryColor:d,transform:g,position:m}),n++}return r}}class Qt{Xn(t,i){const r=t.cmap;for(const n of r.tables)if(n.format===4){const o=n;for(let h=0;h<o.startCount.length;h++)if(i>=o.startCount[h]&&i<=o.endCount[h]){if(o.idRangeOffset[h]===0)return i+o.idDelta[h]&65535;{const a=o.idRangeOffset[h]/2+(i-o.startCount[h])-(o.startCount.length-h);if(a>=0&&a<o.glyphIdArray.length){const u=o.glyphIdArray[a];if(u!==0)return u+o.idDelta[h]&65535}}}}else if(n.format===12){const o=n;for(let h=0;h<o.groups.length;h+=3){const a=o.groups[h],u=o.groups[h+1],f=o.groups[h+2];if(i>=a&&i<=u)return f+(i-a)}}return 0}jn(t,i,r,n,o){const h=o/t.head.unitsPerEm;return{getBoundingBox:()=>({x1:r+i.xMin*h,y1:n+-i.yMax*h,x2:r+i.xMax*h,y2:n+-i.yMin*h}),toSVG:()=>this.Yn(i,r,n,h)}}Yn(t,i,r,n){if(!t||!t.xs)return"";const{xs:o,ys:h,endPts:a,flags:u}=t;if(!(o&&h&&a&&u))return"";let f="",d=0;for(let g=0;g<a.length;g++){const m=a[g];if(!(m<d)){if(m>=d){const y=i+o[d]*n,x=r-h[d]*n;f+=`M${y.toFixed(2)},${x.toFixed(2)}`;let p=d+1;for(;p<=m;)if(1&u[p]){const E=i+o[p]*n,v=r-h[p]*n;f+=`L${E.toFixed(2)},${v.toFixed(2)}`,p++}else{const E=i+o[p]*n,v=r-h[p]*n;let b=p+1>m?d:p+1;if(1&u[b]){const w=i+o[b]*n,F=r-h[b]*n;f+=`Q${E.toFixed(2)},${v.toFixed(2)} ${w.toFixed(2)},${F.toFixed(2)}`,p=b+1}else{const w=(E+(i+o[b]*n))/2,F=(v+(r-h[b]*n))/2;f+=`Q${E.toFixed(2)},${v.toFixed(2)} ${w.toFixed(2)},${F.toFixed(2)}`,p=b}}f+="Z"}d=m+1}}return f}qn(t,i,r,n,o){const h=t.codePointAt(0)||0,a=this.Xn(i,h);let u=null;return i.glyf&&i.glyf[a]!==null?u=i.glyf[a]:(u=B.T.glyf.Qs(i,a),i.glyf[a]=u),this.jn(i,u,r,n,o)}Zn(t,i,r,n,o,h,a,u){const f=r+(o-u*(a/i.head.unitsPerEm))/2,d=n+(h+.7*a)/2;return this.qn(t,i,f,d,a).toSVG()||null}}class Zt{constructor(){l(this,"Jn");this.Jn=new Qt}Qn(t){const{width:i,height:r}=t;return`<?xml version="1.0" encoding="UTF-8"?><svg width="${i}" height="${r}" viewBox="0 0 ${i} ${r}" xmlns="http://www.w3.org/2000/svg"><title>textmode.js sketch</title>`}eo(){return"</g></svg>"}so(t,i){if(!i.includeBackgroundRectangles)return"";const[r,n,o,h]=i.backgroundColor;return`<rect width="${t.width}" height="${t.height}" fill="rgba(${r},${n},${o},${h/255})"/>`}io(t,i){const{transform:r,position:n}=t;if(!r.flipHorizontal&&!r.flipVertical&&!r.rotation)return"";const o=n.cellX+i.cellWidth/2,h=n.cellY+i.cellHeight/2,a=[];if(r.flipHorizontal||r.flipVertical){const u=r.flipHorizontal?-1:1,f=r.flipVertical?-1:1;a.push(`translate(${o} ${h})scale(${u} ${f})translate(${-o} ${-h})`)}return r.rotation&&a.push(`rotate(${r.rotation} ${o} ${h})`),` transform="${a.join(" ")}"`}ro(t,i,r){if(!r.includeBackgroundRectangles||t.secondaryColor.a===0)return"";const{position:n}=t,{r:o,g:h,b:a,a:u}=t.secondaryColor,f=`rgba(${o},${h},${a},${u/255})`;return r.drawMode==="stroke"?`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" stroke="${f}" fill="none" stroke-width="${r.strokeWidth}"/>`:`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" fill="${f}"/>`}qn(t,i,r,n){const o=r.characters[t.charIndex];if(!o)return"";const h=this.Jn.Zn(o.character,r.font,t.position.cellX,t.position.cellY,i.cellWidth,i.cellHeight,r.fontSize,o.advanceWidth);if(!h)return"";const{r:a,g:u,b:f,a:d}=t.primaryColor,g=`rgba(${a},${u},${f},${d/255})`;return n.drawMode==="stroke"?`<path d="${h}" stroke="${g}" stroke-width="${n.strokeWidth}" fill="none"/>`:`<path d="${h}" fill="${g}"/>`}no(t,i,r,n){const o=[],h=this.ro(t,i,n);h&&o.push(h);const a=this.qn(t,i,r,n);if(a){const u=this.io(t,i);o.push(u?`<g${u}>${a}</g>`:a)}return o.join("")}oo(t,i,r,n){const o=[this.Qn(i),this.so(i,n),'<g id="ascii-cells">'];for(const h of t)o.push(this.no(h,i,r,n));return o.push(this.eo()),o.join("")}ao(t){return t.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\s+/g," ").replace(/> </g,"><")}}class te extends st{ho(t){return this.Bn(t,"image/svg+xml;charset=utf-8")}co(t,i){this.Dn(t,this.On(i)+".svg","image/svg+xml;charset=utf-8")}lo(t,i){this.co(t,i||this.Hn())}}class ft{constructor(){l(this,"uo");l(this,"fo");l(this,"do");this.uo=new Jt,this.fo=new Zt,this.do=new te}_o(t){return{includeBackgroundRectangles:t.includeBackgroundRectangles??!0,drawMode:t.drawMode??"fill",strokeWidth:t.strokeWidth??1,backgroundColor:t.backgroundColor??[0,0,0,0],filename:t.filename||this.do.Hn()}}po(t,i={}){const r=this.uo.Nn(this.uo.Pn(t.pipeline),t.grid),n=this.fo.oo(r,t.grid,t.font,this._o(i));return this.fo.ao(n)}lo(t,i={}){this.do.lo(this.po(t,i),i.filename)}}class ee extends it{mo(t,i,r,n=" "){var a;const o=[];let h=0;for(let u=0;u<i.rows;u++){const f=[];for(let d=0;d<i.cols;d++){const g=4*h,m=this.kn(t.characterPixels,g),y=((a=r.characters[m])==null?void 0:a.character)||n;f.push(y),h++}o.push(f)}return o}}class ie{vo(t,i){const r=[];for(const o of t){let h=o.join("");i.preserveTrailingSpaces||(h=h.replace(/\s+$/,"")),r.push(h)}const n=i.lineEnding==="crlf"?`\r
12
12
  `:`
13
- `;return r.join(n)}}class se extends st{yo(t,i){const r=this.Co(i);this.Dn(t,r,"text/plain;charset=utf-8")}Co(t){let i=this.On(t);return i===".txt"||i.length<=4?this.Hn():i}}class dt{constructor(){l(this,"uo");l(this,"fo");l(this,"do");this.uo=new ee,this.fo=new ie,this.do=new se}_o(t){return{preserveTrailingSpaces:t.preserveTrailingSpaces??!1,lineEnding:t.lineEnding??"lf",emptyCharacter:t.emptyCharacter??" ",filename:t.filename||this.do.Hn()}}wo(t,i={}){const r=this._o(i),n=this.uo.mo(this.uo.Pn(t.pipeline),t.grid,t.font,r.emptyCharacter);return this.fo.vo(n,r)}yo(t,i={}){this.do.yo(this.wo(t,i),i.filename)}}class re extends it{$o(t,i=1,r="transparent"){const n=t.canvas;if(i===1&&r==="transparent")return n;const o=document.createElement("canvas"),h=o.getContext("2d"),a=Math.round(n.width*i),u=Math.round(n.height*i);return o.width=a,o.height=u,r!=="transparent"&&(h.fillStyle=r,h.fillRect(0,0,a,u)),h.imageSmoothingEnabled=!1,h.drawImage(n,0,0,n.width,n.height,0,0,a,u),o}}class ne{bo(t,i){const r=this.xo(i.format);return i.format==="png"?t.toDataURL(r):t.toDataURL(r,i.quality)}async Mo(t,i){return new Promise((r,n)=>{const o=this.xo(i.format),h=a=>{a?r(a):n(Error(`Failed to generate ${i.format.toUpperCase()} blob`))};i.format==="png"?t.toBlob(h,o):t.toBlob(h,o,i.quality)})}xo(t){switch(t){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+t)}}}const oe={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},gt={png:".png",jpg:".jpg",webp:".webp"};class he extends st{Ro(t,i,r){this.Fo(t,this.On(i)+gt[r])}Fo(t,i){const r=URL.createObjectURL(t);try{const n=document.createElement("a");n.href=r,n.download=i,n.style.display="none",n.rel="noopener",document.body.appendChild(n),n.click(),document.body.removeChild(n)}finally{URL.revokeObjectURL(r)}}So(t){return t in oe&&t in gt}}class ae{constructor(){l(this,"uo");l(this,"fo");l(this,"do");this.uo=new re,this.fo=new ne,this.do=new he}_o(t){return{format:t.format??"png",quality:t.quality??1,scale:t.scale??1,backgroundColor:t.backgroundColor??"transparent",filename:t.filename||this.do.Hn()}}Ao(t){if(!this.do.So(t.format))throw Error(`Saving '${t.format}' files is not supported`);if(t.quality<0||t.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(t.scale<=0)throw Error("Scale factor must be greater than 0");t.format==="jpg"&&t.backgroundColor==="transparent"&&(t.backgroundColor="black")}async Mo(t,i){if(i.scale===1&&i.backgroundColor==="transparent")return await this.fo.Mo(t.canvas,i);const r=this.uo.$o(t,i.scale,i.backgroundColor);return await this.fo.Mo(r,i)}async Ro(t,i={}){const r=this._o(i);this.Ao(r);const n=await this.Mo(t,r);this.do.Ro(n,r.filename,r.format)}}const ce=c=>class extends c{zo(){this.xt.Et(this.To)}toString(t={}){return this.zo(),new dt().wo({pipeline:this.Eo,grid:this.hn,font:this.Li},t)}saveStrings(t={}){this.zo(),new dt().yo({pipeline:this.Eo,grid:this.hn,font:this.Li},t)}toSVG(t={}){return this.zo(),new ft().po({pipeline:this.Eo,grid:this.hn,font:this.Li},t)}saveSVG(t={}){this.zo(),new ft().lo({pipeline:this.Eo,grid:this.hn,font:this.Li},t)}async saveCanvas(t={}){await new ae().Ro(this.er,t)}},le=c=>class extends c{async loadFont(t){return this.Li.qi(t).then(()=>{const i=this.Li.maxGlyphDimensions;this.hn.nr(i.width,i.height),this.Eo.resize(this.hn.cols,this.hn.rows),this.xt.Js(),this.Lo.bn()})}fontSize(t){if(!z.v(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.Li.fontSize===t)return;this.Li.Yi(t);const i=this.Li.maxGlyphDimensions;this.hn.nr(i.width,i.height),this.Eo.resize(this.hn.cols,this.hn.rows),this.xt.Js(),this.Lo.bn()}glyphColor(t){return this.Li.Ti(t)}glyphColors(t){return this.Li.Ei(t)}},ue=c=>class extends c{get frameCount(){return this.Po.frameCount}set frameCount(t){this.Po.frameCount=t}frameRate(t){return t===void 0?this.Po.currentFrameRate:this.Po.frameRate(t,()=>this.ko())}noLoop(){this.Po.pause()}loop(){this.Po.resume(()=>this.ko())}redraw(t=1){if(z.v(typeof t=="number"&&t>0&&Number.isInteger(t),"Redraw count must be a positive integer.",{method:"redraw",providedValue:t}))for(let i=0;i<t;i++)this.ko()}isLooping(){return this.Po.isLooping}},fe=c=>class extends c{constructor(...t){super(...t)}mouseClicked(t){this.Lo.zn(t)}mousePressed(t){this.Lo.Zr(t)}mouseReleased(t){this.Lo.Jr(t)}mouseMoved(t){this.Lo.Tn(t)}mouseScrolled(t){this.Lo.En(t)}get mouse(){return this.Lo.Ln()}},de=c=>class extends c{constructor(...t){super(...t)}keyPressed(t){this.Go.Zr(t)}keyReleased(t){this.Go.Jr(t)}isKeyPressed(t){return this.Go.Qr(t)}get lastKeyPressed(){return this.Go.en()}get lastKeyReleased(){return this.Go.sn()}get pressedKeys(){return this.Go.rn()}get modifierState(){return this.Go.nn()}};class ge{constructor(){l(this,"xt");l(this,"Li");l(this,"er");l(this,"hn");l(this,"Po");l(this,"Lo");l(this,"Go");l(this,"To");l(this,"Eo");l(this,"Bo");l(this,"Do");l(this,"Io")}ko(){}}class pt extends function(i,...r){return r.reduce((n,o)=>o(n),i)}(ge,qt,ce,le,ue,fe,de){constructor(i={}){super();l(this,"Wo",!1);l(this,"Oo",()=>{});l(this,"Ho",()=>{});l(this,"Vo",()=>{});l(this,"Ko");l(this,"cr");l(this,"hr",!1);l(this,"No");this.hr=i.overlay??!1,this.er=new ut(i),this.xt=new Mt(this.er.gr()),this.Li=new ct(this.xt,i.fontSize??16),this.Po=new Vt(i.frameRate??60),this.Lo=new Kt(this.er),this.Go=new jt,this.To=this.xt.Tt(),this.Bo=this.xt.re(),this.Xo(i)}async Xo(i){await this.Li.Ni(i.fontSource);const r=this.Li.maxGlyphDimensions;this.hn=new lt(this.er.canvas,r.width,r.height),this.Lo.Ni(this.hn),this.Eo=this.xt.Ys(this.hn.cols,this.hn.rows,5),this.Do=this.xt.Ys(this.hn.width,this.hn.height,1),this.hr&&(this.No=N.Rr(this.xt,this.er.targetCanvas,n=>this.Li.Ei(n))),this.Io=this.xt.ae(ot,"precision mediump float;uniform sampler2D Ua;uniform vec2 Ub;uniform vec2 Uc;uniform vec2 Ud;void main(){vec2 A=gl_FragCoord.xy-Uc;vec2 B=A*(Ub/Ud);vec2 C=(floor(B)+0.5)/Ub;gl_FragColor=texture2D(Ua,C);}"),this.jo(),this.Oo(),this.Po.start(()=>this.ko())}jo(){this.Ko=()=>{this.hr&&this.resizeCanvas(this.er.targetCanvas.width,this.er.targetCanvas.height),this.Vo()},window.addEventListener("resize",this.Ko),this.Lo.Xr(),this.Go.Xr(),window.addEventListener("blur",()=>{this.Go.an()}),window.ResizeObserver&&this.hr&&(this.cr=new ResizeObserver(()=>{this.resizeCanvas(this.er.targetCanvas.width,this.er.targetCanvas.height)}),this.cr.observe(this.er.targetCanvas))}ko(){if(this.Po.measureFrameRate(),this.Po.incrementFrame(),this.Wo)return;if(this.hr){const r=this.xt.context;r.bindTexture(r.TEXTURE_2D,this.No.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.er.targetCanvas),r.bindTexture(r.TEXTURE_2D,null)}this.Eo.begin(),this.xt.Gs(this.To),this.Ho(),this.xt.Et(this.To),this.Eo.end(),this.Do.begin(),this.xt.Gs(this.Bo),this.Bo.Nt({U0:this.Li.fontFramebuffer,U1:[this.Li.textureColumns,this.Li.textureRows],U2:this.Eo.textures[0],U3:this.Eo.textures[1],U4:this.Eo.textures[2],U5:this.Eo.textures[4],U6:this.Eo.textures[3],U7:[this.hn.cols,this.hn.rows],U8:[this.Do.width,this.Do.height],U9:this.Do.width/this.Do.height}),this.xt.Hs(0,0,this.er.width,this.er.height),this.Do.end();const i=this.xt.state.canvasBackgroundColor;this.xt.He(i[0],i[1],i[2],i[3]),this.xt.Gs(this.Io),this.Io.Nt({Ua:this.Do.textures[0],Ub:[this.Do.width,this.Do.height],Uc:[this.hn.offsetX,this.hn.offsetY],Ud:[this.hn.width,this.hn.height]}),this.xt.Hs(this.hn.offsetX,this.hn.offsetY,this.hn.width,this.hn.height)}setup(i){this.Oo=i}draw(i){this.Ho=i}windowResized(i){this.Vo=i}resizeCanvas(i,r){this.er.mr(i,r),this.hn.rr(),this.Eo.resize(this.hn.cols,this.hn.rows),this.Do.resize(this.hn.width,this.hn.height),this.xt.Js(),this.Lo.bn(),this.ko()}destroy(){this.Wo||(this.Po.stop(),window.removeEventListener("resize",this.Ko),this.Lo.qr(),this.Go.qr(),this.Li.kt(),this.xt.kt(),this.Do.kt(),this.Io.kt(),this.No&&this.No.kt(),this.Wo=!0)}get grid(){return this.hn}get font(){return this.Li}get width(){return this.er.width}get height(){return this.er.height}get canvas(){return this.er.canvas}get isDisposed(){return this.Wo}get overlay(){return this.No}}class J{constructor(){}static create(t={}){return new pt(t)}static setErrorLevel(t){z.C(t)}static get version(){return"0.2.1-beta.8"}}const pe=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),me=J.create,ve=J.setErrorLevel,xe=J.version;C.TextmodeCanvas=ut,C.TextmodeErrorLevel=I,C.TextmodeFont=ct,C.TextmodeFramebuffer=V,C.TextmodeGrid=lt,C.TextmodeImage=N,C.Textmodifier=pt,C.create=me,C.export=pe,C.setErrorLevel=ve,C.textmode=J,C.version=xe,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):s((e=typeof globalThis<"u"?globalThis:e||self).textmode={});
13
+ `;return r.join(n)}}class se extends st{yo(t,i){const r=this.Co(i);this.Dn(t,r,"text/plain;charset=utf-8")}Co(t){let i=this.On(t);return i===".txt"||i.length<=4?this.Hn():i}}class dt{constructor(){l(this,"uo");l(this,"fo");l(this,"do");this.uo=new ee,this.fo=new ie,this.do=new se}_o(t){return{preserveTrailingSpaces:t.preserveTrailingSpaces??!1,lineEnding:t.lineEnding??"lf",emptyCharacter:t.emptyCharacter??" ",filename:t.filename||this.do.Hn()}}wo(t,i={}){const r=this._o(i),n=this.uo.mo(this.uo.Pn(t.pipeline),t.grid,t.font,r.emptyCharacter);return this.fo.vo(n,r)}yo(t,i={}){this.do.yo(this.wo(t,i),i.filename)}}class re extends it{$o(t,i=1,r="transparent"){const n=t.canvas;if(i===1&&r==="transparent")return n;const o=document.createElement("canvas"),h=o.getContext("2d"),a=Math.round(n.width*i),u=Math.round(n.height*i);return o.width=a,o.height=u,r!=="transparent"&&(h.fillStyle=r,h.fillRect(0,0,a,u)),h.imageSmoothingEnabled=!1,h.drawImage(n,0,0,n.width,n.height,0,0,a,u),o}}class ne{bo(t,i){const r=this.xo(i.format);return i.format==="png"?t.toDataURL(r):t.toDataURL(r,i.quality)}async Mo(t,i){return new Promise((r,n)=>{const o=this.xo(i.format),h=a=>{a?r(a):n(Error(`Failed to generate ${i.format.toUpperCase()} blob`))};i.format==="png"?t.toBlob(h,o):t.toBlob(h,o,i.quality)})}xo(t){switch(t){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+t)}}}const oe={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},gt={png:".png",jpg:".jpg",webp:".webp"};class he extends st{Ro(t,i,r){this.Fo(t,this.On(i)+gt[r])}Fo(t,i){const r=URL.createObjectURL(t);try{const n=document.createElement("a");n.href=r,n.download=i,n.style.display="none",n.rel="noopener",document.body.appendChild(n),n.click(),document.body.removeChild(n)}finally{URL.revokeObjectURL(r)}}So(t){return t in oe&&t in gt}}class ae{constructor(){l(this,"uo");l(this,"fo");l(this,"do");this.uo=new re,this.fo=new ne,this.do=new he}_o(t){return{format:t.format??"png",quality:t.quality??1,scale:t.scale??1,backgroundColor:t.backgroundColor??"transparent",filename:t.filename||this.do.Hn()}}Ao(t){if(!this.do.So(t.format))throw Error(`Saving '${t.format}' files is not supported`);if(t.quality<0||t.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(t.scale<=0)throw Error("Scale factor must be greater than 0");t.format==="jpg"&&t.backgroundColor==="transparent"&&(t.backgroundColor="black")}async Mo(t,i){if(i.scale===1&&i.backgroundColor==="transparent")return await this.fo.Mo(t.canvas,i);const r=this.uo.$o(t,i.scale,i.backgroundColor);return await this.fo.Mo(r,i)}async Ro(t,i={}){const r=this._o(i);this.Ao(r);const n=await this.Mo(t,r);this.do.Ro(n,r.filename,r.format)}}const ce=c=>class extends c{zo(){this.xt.Et(this.To)}toString(t={}){return this.zo(),new dt().wo({pipeline:this.Eo,grid:this.hn,font:this.Li},t)}saveStrings(t={}){this.zo(),new dt().yo({pipeline:this.Eo,grid:this.hn,font:this.Li},t)}toSVG(t={}){return this.zo(),new ft().po({pipeline:this.Eo,grid:this.hn,font:this.Li},t)}saveSVG(t={}){this.zo(),new ft().lo({pipeline:this.Eo,grid:this.hn,font:this.Li},t)}async saveCanvas(t={}){await new ae().Ro(this.er,t)}},le=c=>class extends c{async loadFont(t){return this.Li.qi(t).then(()=>{const i=this.Li.maxGlyphDimensions;this.hn.nr(i.width,i.height),this.Eo.resize(this.hn.cols,this.hn.rows),this.xt.Js(),this.Lo.bn()})}fontSize(t){if(!z.v(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.Li.fontSize===t)return;this.Li.Yi(t);const i=this.Li.maxGlyphDimensions;this.hn.nr(i.width,i.height),this.Eo.resize(this.hn.cols,this.hn.rows),this.xt.Js(),this.Lo.bn()}glyphColor(t){return this.Li.Ti(t)}glyphColors(t){return this.Li.Ei(t)}},ue=c=>class extends c{get frameCount(){return this.Po.frameCount}set frameCount(t){this.Po.frameCount=t}frameRate(t){return t===void 0?this.Po.currentFrameRate:this.Po.frameRate(t,()=>this.ko())}noLoop(){this.Po.pause()}loop(){this.Po.resume(()=>this.ko())}redraw(t=1){if(z.v(typeof t=="number"&&t>0&&Number.isInteger(t),"Redraw count must be a positive integer.",{method:"redraw",providedValue:t}))for(let i=0;i<t;i++)this.ko()}isLooping(){return this.Po.isLooping}},fe=c=>class extends c{constructor(...t){super(...t)}mouseClicked(t){this.Lo.zn(t)}mousePressed(t){this.Lo.Zr(t)}mouseReleased(t){this.Lo.Jr(t)}mouseMoved(t){this.Lo.Tn(t)}mouseScrolled(t){this.Lo.En(t)}get mouse(){return this.Lo.Ln()}},de=c=>class extends c{constructor(...t){super(...t)}keyPressed(t){this.Go.Zr(t)}keyReleased(t){this.Go.Jr(t)}isKeyPressed(t){return this.Go.Qr(t)}get lastKeyPressed(){return this.Go.en()}get lastKeyReleased(){return this.Go.sn()}get pressedKeys(){return this.Go.rn()}get modifierState(){return this.Go.nn()}};class ge{constructor(){l(this,"xt");l(this,"Li");l(this,"er");l(this,"hn");l(this,"Po");l(this,"Lo");l(this,"Go");l(this,"To");l(this,"Eo");l(this,"Bo");l(this,"Do");l(this,"Io")}ko(){}}class pt extends function(i,...r){return r.reduce((n,o)=>o(n),i)}(ge,qt,ce,le,ue,fe,de){constructor(i={}){super();l(this,"Wo",!1);l(this,"Oo",()=>{});l(this,"Ho",()=>{});l(this,"Vo",()=>{});l(this,"Ko");l(this,"cr");l(this,"hr",!1);l(this,"No");this.hr=i.overlay??!1,this.er=new ut(i),this.xt=new Mt(this.er.gr()),this.Li=new ct(this.xt,i.fontSize??16),this.Po=new Vt(i.frameRate??60),this.Lo=new Kt(this.er),this.Go=new jt,this.To=this.xt.Tt(),this.Bo=this.xt.re(),this.Xo(i)}async Xo(i){await this.Li.Ni(i.fontSource);const r=this.Li.maxGlyphDimensions;this.hn=new lt(this.er.canvas,r.width,r.height),this.Lo.Ni(this.hn),this.Eo=this.xt.Ys(this.hn.cols,this.hn.rows,5),this.Do=this.xt.Ys(this.hn.width,this.hn.height,1),this.hr&&(this.No=N.Rr(this.xt,this.er.targetCanvas,n=>this.Li.Ei(n))),this.Io=this.xt.ae(ot,"precision mediump float;uniform sampler2D Ua;uniform vec2 Ub;uniform vec2 Uc;uniform vec2 Ud;void main(){vec2 A=gl_FragCoord.xy-Uc;vec2 B=A*(Ub/Ud);vec2 C=(floor(B)+0.5)/Ub;gl_FragColor=texture2D(Ua,C);}"),this.jo(),this.Oo(),this.Po.start(()=>this.ko())}jo(){this.Ko=()=>{this.hr&&this.resizeCanvas(this.er.targetCanvas.width,this.er.targetCanvas.height),this.Vo()},window.addEventListener("resize",this.Ko),this.Lo.Xr(),this.Go.Xr(),window.addEventListener("blur",()=>{this.Go.an()}),window.ResizeObserver&&this.hr&&(this.cr=new ResizeObserver(()=>{this.resizeCanvas(this.er.targetCanvas.width,this.er.targetCanvas.height)}),this.cr.observe(this.er.targetCanvas))}ko(){if(this.Po.measureFrameRate(),this.Po.incrementFrame(),this.Wo)return;if(this.hr){const r=this.xt.context;r.bindTexture(r.TEXTURE_2D,this.No.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.er.targetCanvas),r.bindTexture(r.TEXTURE_2D,null)}this.Eo.begin(),this.xt.Gs(this.To),this.Ho(),this.xt.Et(this.To),this.Eo.end(),this.Do.begin(),this.xt.Gs(this.Bo),this.Bo.Nt({U0:this.Li.fontFramebuffer,U1:[this.Li.textureColumns,this.Li.textureRows],U2:this.Eo.textures[0],U3:this.Eo.textures[1],U4:this.Eo.textures[2],U5:this.Eo.textures[4],U6:this.Eo.textures[3],U7:[this.hn.cols,this.hn.rows],U8:[this.Do.width,this.Do.height],U9:this.Do.width/this.Do.height}),this.xt.Hs(0,0,this.er.width,this.er.height),this.Do.end();const i=this.xt.state.canvasBackgroundColor;this.xt.He(i[0],i[1],i[2],i[3]),this.xt.Gs(this.Io),this.Io.Nt({Ua:this.Do.textures[0],Ub:[this.Do.width,this.Do.height],Uc:[this.hn.offsetX,this.hn.offsetY],Ud:[this.hn.width,this.hn.height]}),this.xt.Hs(this.hn.offsetX,this.hn.offsetY,this.hn.width,this.hn.height)}setup(i){this.Oo=i}draw(i){this.Ho=i}windowResized(i){this.Vo=i}resizeCanvas(i,r){this.er.mr(i,r),this.hn.rr(),this.Eo.resize(this.hn.cols,this.hn.rows),this.Do.resize(this.hn.width,this.hn.height),this.xt.Js(),this.Lo.bn(),this.ko()}destroy(){this.Wo||(this.Po.stop(),window.removeEventListener("resize",this.Ko),this.Lo.qr(),this.Go.qr(),this.Li.kt(),this.xt.kt(),this.Do.kt(),this.Io.kt(),this.No&&this.No.kt(),this.Wo=!0)}get grid(){return this.hn}get font(){return this.Li}get width(){return this.er.width}get height(){return this.er.height}get canvas(){return this.er.canvas}get isDisposed(){return this.Wo}get overlay(){return this.No}}class J{constructor(){}static create(t={}){return new pt(t)}static setErrorLevel(t){z.C(t)}static get version(){return"0.3.0"}}const pe=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),me=J.create,ve=J.setErrorLevel,xe=J.version;C.TextmodeCanvas=ut,C.TextmodeErrorLevel=I,C.TextmodeFont=ct,C.TextmodeFramebuffer=V,C.TextmodeGrid=lt,C.TextmodeImage=N,C.Textmodifier=pt,C.create=me,C.export=pe,C.setErrorLevel=ve,C.textmode=J,C.version=xe,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):s((e=typeof globalThis<"u"?globalThis:e||self).textmode={});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "textmode.js",
3
- "version": "0.2.1-beta.8",
3
+ "version": "0.3.0",
4
4
  "description": "textmode.js is a lightweight creative coding library for creating real-time ASCII art on the web.",
5
5
  "type": "module",
6
6
  "types": "./dist/types/index.d.ts",