textmode.js 0.6.1 → 0.7.0-beta.2

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.
Files changed (27) hide show
  1. package/README.md +0 -2
  2. package/dist/textmode.esm.js +2405 -2027
  3. package/dist/textmode.umd.js +17 -9
  4. package/dist/types/index.d.ts +4 -0
  5. package/dist/types/rendering/webgl/core/Framebuffer.d.ts +2 -0
  6. package/dist/types/rendering/webgl/core/Renderer.d.ts +12 -1
  7. package/dist/types/rendering/webgl/core/Shader.d.ts +3 -0
  8. package/dist/types/rendering/webgl/utils/hash.d.ts +0 -16
  9. package/dist/types/textmode/Textmodifier.d.ts +4 -0
  10. package/dist/types/textmode/interfaces/ITextmodifier.d.ts +8 -2
  11. package/dist/types/textmode/layers/ILayerManager.d.ts +36 -0
  12. package/dist/types/textmode/layers/Layer2DCompositor.d.ts +74 -0
  13. package/dist/types/textmode/layers/LayerManager.d.ts +118 -0
  14. package/dist/types/textmode/layers/TextmodeLayer.d.ts +193 -0
  15. package/dist/types/textmode/layers/filters/FilterRegistry.d.ts +83 -0
  16. package/dist/types/textmode/layers/filters/LayerFilterManager.d.ts +74 -0
  17. package/dist/types/textmode/layers/filters/index.d.ts +3 -0
  18. package/dist/types/textmode/layers/filters/types.d.ts +123 -0
  19. package/dist/types/textmode/layers/index.d.ts +6 -0
  20. package/dist/types/textmode/layers/types.d.ts +74 -0
  21. package/dist/types/textmode/loading/LoadingScreenManager.d.ts +4 -4
  22. package/dist/types/textmode/managers/MouseManager.d.ts +6 -1
  23. package/dist/types/textmode/managers/TouchManager.d.ts +5 -0
  24. package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +0 -1
  25. package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +80 -27
  26. package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +1 -1
  27. package/package.json +1 -1
@@ -1,14 +1,22 @@
1
- var qe=Object.defineProperty;var Qe=(x,R,X)=>R in x?qe(x,R,{enumerable:!0,configurable:!0,writable:!0,value:X}):x[R]=X;var l=(x,R,X)=>Qe(x,typeof R!="symbol"?R+"":R,X);var s,e;s=this,e=function(x){class R extends Error{constructor(t,i={}){super(R.i(t,i)),this.name="TextmodeError"}static i(t,i){return`${t}${i&&Object.keys(i).length>0?`
1
+ var ni=Object.defineProperty;var hi=(T,R,Z)=>R in T?ni(T,R,{enumerable:!0,configurable:!0,writable:!0,value:Z}):T[R]=Z;var l=(T,R,Z)=>hi(T,typeof R!="symbol"?R+"":R,Z);var s,e;s=this,e=function(T){class R extends Error{constructor(t,i={}){super(R.i(t,i)),this.name="TextmodeError"}static i(t,i){return`${t}${i&&Object.keys(i).length>0?`
2
2
 
3
3
  📋 Context:`+Object.entries(i).map(([r,n])=>`
4
4
  - ${r}: ${R.o(n)}`).join(""):""}
5
5
 
6
6
  ${"↓".repeat(24)}
7
- `}static o(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="number"||typeof t=="boolean")return t+"";if(Array.isArray(t))return t.length===0?"[]":t.length<=5?`[${t.map(i=>R.o(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>R.o(i)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const i=Object.keys(t);return i.length===0?"{}":i.length<=3?`{ ${i.map(r=>`${r}: ${R.o(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${R.o(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var X=(o=>(o[o.SILENT=0]="SILENT",o[o.WARNING=1]="WARNING",o[o.ERROR=2]="ERROR",o[o.THROW=3]="THROW",o))(X||{});const G=class G{constructor(){l(this,"l",{globalLevel:3})}static u(){return G.h||(G.h=new G),G.h}v(t,i){const r="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",n="color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";switch(this.l.globalLevel){case 0:return!1;case 1:return console.group(r,n),console.warn(R.i(t,i)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(R.i(t,i)),console.groupEnd(),!1;default:throw new R(t,i)}}m(t,i,r){return!!t||(this.v(i,r),!1)}_(t){this.l.globalLevel=t}};l(G,"h",null);let ct=G;const lt=ct.u();class j{constructor(t,i,r){l(this,"A");l(this,"C");l(this,"M",new Map);l(this,"F",new Map);l(this,"$",0);this.A=t,this.C=this.P(i,r),this.R()}R(){const t=this.A.getProgramParameter(this.C,this.A.ACTIVE_UNIFORMS);for(let i=0;i<t;i++){const r=this.A.getActiveUniform(this.C,i);if(r){const n=r.name.replace(/\[0\]$/,""),h=this.A.getUniformLocation(this.C,n);h&&(this.M.set(n,h),this.F.set(n,{type:r.type,size:r.size}))}}}P(t,i){const r=this.S(this.A.VERTEX_SHADER,t),n=this.S(this.A.FRAGMENT_SHADER,i),h=this.A.createProgram();if(this.A.attachShader(h,r),this.A.attachShader(h,n),this.A.linkProgram(h),!this.A.getProgramParameter(h,this.A.LINK_STATUS)){const a=this.A.getProgramInfoLog(h);throw Error("Shader program link error: "+a)}return this.A.deleteShader(r),this.A.deleteShader(n),h}S(t,i){const r=this.A.createShader(t);if(this.A.shaderSource(r,i),this.A.compileShader(r),!this.A.getShaderParameter(r,this.A.COMPILE_STATUS)){const n=this.A.getShaderInfoLog(r);throw this.A.deleteShader(r),Error("Shader compilation error: "+n)}return r}U(){this.A.useProgram(this.C),this.k()}k(){this.$=0}L(t){for(const i in t)this.O(i,t[i])}O(t,i){var u,f;const r=this.M.get(t);if(!r)return;const n=this.F.get(t);if(!n)return;const{type:h,size:a}=n,c=this.A;if(i instanceof WebGLTexture){const d=this.$++;return c.uniform1i(r,d),c.activeTexture(c.TEXTURE0+d),void c.bindTexture(c.TEXTURE_2D,i)}if(i instanceof V){const d=this.$++;return c.uniform1i(r,d),c.activeTexture(c.TEXTURE0+d),void c.bindTexture(c.TEXTURE_2D,i.textures[0])}if(typeof i!="number")if(typeof i!="boolean")if(Array.isArray(i[0])){const d=i.flat(),g={[c.FLOAT_VEC2]:()=>c.uniform2fv(r,d),[c.FLOAT_VEC3]:()=>c.uniform3fv(r,d),[c.FLOAT_VEC4]:()=>c.uniform4fv(r,d)};(u=g[h])==null||u.call(g)}else{const d=i,g={[c.FLOAT]:()=>a>1?c.uniform1fv(r,d):c.uniform1f(r,d[0]),[c.FLOAT_VEC2]:()=>c.uniform2fv(r,d),[c.FLOAT_VEC3]:()=>c.uniform3fv(r,d),[c.FLOAT_VEC4]:()=>c.uniform4fv(r,d),[c.INT]:()=>a>1?c.uniform1iv(r,d):c.uniform1i(r,d[0]),[c.INT_VEC2]:()=>c.uniform2iv(r,d),[c.INT_VEC3]:()=>c.uniform3iv(r,d),[c.INT_VEC4]:()=>c.uniform4iv(r,d),[c.BOOL]:()=>c.uniform1iv(r,d),[c.FLOAT_MAT2]:()=>c.uniformMatrix2fv(r,!1,d),[c.FLOAT_MAT3]:()=>c.uniformMatrix3fv(r,!1,d),[c.FLOAT_MAT4]:()=>c.uniformMatrix4fv(r,!1,d)};(f=g[h])==null||f.call(g)}else c.uniform1i(r,i?1:0);else h===c.INT||h===c.BOOL?c.uniform1i(r,i):c.uniform1f(r,i)}get D(){return this.C}dispose(){this.A.deleteProgram(this.C)}}function Tt(o,t,i,r){return 180*Math.atan2(r-t,i-o)/Math.PI}function W(o,t,i,r){return Math.hypot(i-o,r-t)}function z(o,t,i){return Math.min(Math.max(o,t),i)}function bt(o){return(o%360+360)%360/360}function xt(o,t,i){o.bindTexture(o.TEXTURE_2D,t),o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,1),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,i),o.bindTexture(o.TEXTURE_2D,null)}function $(o,t,i,r,n){o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,t),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,i),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,r),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,n)}function ut(o,t,i,r,n,h=0,a=WebGL2RenderingContext.FLOAT,c=!1){o.enableVertexAttribArray(t),o.vertexAttribPointer(t,i,a,c,r,n),o.vertexAttribDivisor(t,h)}function Rt(o,t,i,r,n){o.bindBuffer(t,i),o.bufferData(t,r,n),o.bindBuffer(t,null)}const tt=`#version 300 es
8
- in vec2 A0;in vec2 A1;in vec2 A2;in vec2 A3;in vec3 A4;in vec4 A5;in vec4 A6;in vec4 A7;in vec3 A8;in vec3 A9;in vec4 Aa;in vec4 Ab;in vec3 Ac;uniform vec2 Ue;uniform float Uf;uniform float Ug;out vec2 v_uv;out vec3 v_glyphIndex;out vec4 v_glyphColor;out vec4 v_cellColor;out vec4 v_glyphFlags;out vec3 v_worldPosition;out vec3 v_normal;out float v_geometryType;const float A=6.28318530718f;const int B=2;const int C=3;const int D=4;vec2 E(float F,vec2 G,vec2 H,vec2 I,vec2 J){float K=1.0f-F;float L=K*K;float M=L*K;float N=F*F;float O=N*F;return M*G+3.0f*L*F*H+3.0f*K*N*I+O*J;}vec2 P(float F,vec2 G,vec2 H,vec2 I,vec2 J){float K=1.0f-F;float L=K*K;float N=F*F;return-3.0f*L*G+3.0f*(L-2.0f*K*F)*H+3.0f*(2.0f*K*F-N)*I+3.0f*N*J;}vec3 Q(vec3 R,float S){float T=cos(S);float U=sin(S);return vec3(R.x,R.y*T-R.z*U,R.y*U+R.z*T);}vec3 V(vec3 R,float S){float T=cos(S);float U=sin(S);return vec3(R.x*T+R.z*U,R.y,-R.x*U+R.z*T);}vec3 W(vec3 R,float S){float T=cos(S);float U=sin(S);return vec3(R.x*T-R.y*U,R.x*U+R.y*T,R.z);}vec3 X(vec3 R,vec3 Y){vec3 Z=R;if(Y.z!=0.0f){Z=W(Z,Y.z);}if(Y.y!=0.0f){Z=V(Z,Y.y);}if(Y.x!=0.0f){Z=Q(Z,Y.x);}return Z;}void main(){v_uv=A1;v_glyphIndex=A4;v_glyphColor=A5;v_cellColor=A6;v_glyphFlags=A7;vec4 a=Aa;vec4 b=Ab;vec2 c=A3;vec2 d=A2;float e=Ac.x;float f=Ac.y;int g=int(Ac.z);vec2 h=d;vec2 i=h+c*0.5f;float j=f+e*0.5f;vec3 k=vec3(i,j);vec3 l;if(g==D){float F=clamp(A0.x,0.0f,1.0f);vec2 G=b.xy;vec2 H=a.xy;vec2 I=a.zw;vec2 J=b.zw;vec2 m=E(F,G,H,I,J);vec2 n=P(F,G,H,I,J);float o=length(n);vec2 p=o>0.0f?n/o:vec2(1.0f,0.0f);vec2 q=vec2(-p.y,p.x);vec2 r=m;vec2 s=r+q*A0.y*c.y;l=vec3(s,f);}else if(g==C){float t=mod(a.x,A);if(t<0.0f){t+=A;}float u=mod(a.y,A);if(u<0.0f){u+=A;}float v=t-u;if(v<=0.0f){v+=A;}float S=t-A0.x*v;vec2 w=vec2(cos(S),sin(S))*A0.y;vec2 s=w*c+h;l=vec3(s,f);}else if(g==B){vec2 s=A0.xy*c+h;l=vec3(s,f);}vec3 x=X(l,A9);vec3 y=x+A8;vec3 z=vec3(0.0f,0.0f,1.0f);v_worldPosition=y;v_normal=z;v_geometryType=float(g);vec2 AA=(y.xy/Ue)*2.0f;AA.y=-AA.y;float AB=y.z/Ue.y;float AC=clamp(-AB*Uf,-0.99f,0.99f);if(Ug>0.5f){gl_Position=vec4(AA,AC,1.0f);}else{float AD=0.5f;float AE=1.0f/(1.0f-AB*AD);AA*=AE;gl_Position=vec4(AA,AC,1.0f);}}`,H=class H{constructor(t,i,r=i,n=1,h={},a){l(this,"H");l(this,"I");l(this,"l");l(this,"A");l(this,"G");l(this,"N",[]);l(this,"X",null);l(this,"Y");l(this,"K");l(this,"W",null);l(this,"Z",new Map);this.H=i,this.I=r,this.A=t,this.Y=z(n,1,8),this.K=a,this.l={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",depth:!0,...h},H.j||(H.j=new j(t,tt,`#version 300 es
9
- precision highp float;in vec2 v_uv;uniform sampler2D Ua;uniform sampler2D Ub;uniform sampler2D Uc;uniform vec2 Ud;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;void main(){vec2 A=vec2(v_uv.x,1.-v_uv.y);vec2 B=A*Ud;vec2 C=(floor(B)+0.5f)/Ud;vec4 D=texture(Ua,C);vec4 E=texture(Ub,C);if(E.a==0.){discard;}vec4 F=texture(Uc,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;}`));const c=t.getParameter(t.MAX_DRAW_BUFFERS),u=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.Y=Math.min(this.Y,c,u),this.G=t.createFramebuffer(),this.V(),this.q(),this.l.depth&&this.J()}V(){const t=this.A,i=this.l.filter==="linear"?t.LINEAR:t.NEAREST,r=this.l.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE,n=this.l.type==="float"?t.FLOAT:t.UNSIGNED_BYTE,h=n===t.FLOAT?t.RGBA32F:t.RGBA8,a=t.RGBA;for(let c=0;c<this.Y;c++){const u=t.createTexture();t.bindTexture(t.TEXTURE_2D,u),$(t,i,i,r,r),t.texImage2D(t.TEXTURE_2D,0,h,this.H,this.I,0,a,n,null),this.N.push(u)}t.bindTexture(t.TEXTURE_2D,null)}q(){const t=this.A;if(t.bindFramebuffer(t.FRAMEBUFFER,this.G),this.Y===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.N[0],0);else{const i=[];for(let r=0;r<this.Y;r++){const n=t.COLOR_ATTACHMENT0+r;t.framebufferTexture2D(t.FRAMEBUFFER,n,t.TEXTURE_2D,this.N[r],0),i.push(n)}t.drawBuffers(i)}t.bindFramebuffer(t.FRAMEBUFFER,null)}J(){const t=this.A;this.X=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,this.X),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT24,this.H,this.I),t.bindFramebuffer(t.FRAMEBUFFER,this.G),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,this.X),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindRenderbuffer(t.RENDERBUFFER,null)}tt(t){xt(this.A,this.N[0],t)}resize(t,i){this.H=t,this.I=i,this.Z.clear();const r=this.A,n=this.l.type==="float"?r.FLOAT:r.UNSIGNED_BYTE,h=n===r.FLOAT?r.RGBA32F:r.RGBA8,a=r.RGBA;for(const c of this.N)r.bindTexture(r.TEXTURE_2D,c),r.texImage2D(r.TEXTURE_2D,0,h,this.H,this.I,0,a,n,null);r.bindTexture(r.TEXTURE_2D,null),this.X&&(r.bindRenderbuffer(r.RENDERBUFFER,this.X),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT24,this.H,this.I),r.bindRenderbuffer(r.RENDERBUFFER,null))}readPixels(t){const i=this.Z.get(t);if(i)return i;const r=this.A,n=this.H,h=this.I,a=new Uint8Array(n*h*4),c=r.getParameter(r.READ_FRAMEBUFFER_BINDING);r.bindFramebuffer(r.READ_FRAMEBUFFER,this.G),r.readBuffer(r.COLOR_ATTACHMENT0+t),r.readPixels(0,0,n,h,r.RGBA,r.UNSIGNED_BYTE,a),r.bindFramebuffer(r.READ_FRAMEBUFFER,c);const u=4*n,f=new Uint8Array(a.length);for(let d=0;d<h;d++){const g=(h-1-d)*u,p=d*u;f.set(a.subarray(g,g+u),p)}return this.Z.set(t,f),f}begin(){const t=this.A;this.Z.clear(),this.K.st(),this.K.et(this.G,this.H,this.I),this.l.depth&&t.clear(t.DEPTH_BUFFER_BIT),this.K.state.it()}end(){this.K.state.rt(),this.K.nt(),this.K.ot()}ht(){return this.W||this.ct(),this.W}ct(){if(!this.K)return;const t={Ua:this.N[0],Ub:this.N[1],Uc:this.N[2],Ud:[this.H,this.I]},i=H.j;this.W=this.K.ut.lt(i,t,!0)}ft(){const t=this.A;t.deleteFramebuffer(this.G);for(const i of this.N)t.deleteTexture(i);this.X&&t.deleteRenderbuffer(this.X)}get width(){return this.H}get height(){return this.I}get textures(){return this.N}get attachmentCount(){return this.Y}};l(H,"j",null);let V=H;const Ft=new WeakMap;function ft(o,t){Ft.set(o,t)}function Ct(o){return Ft.get(o)}function et(o,t,i,r,n=255){o[0]=t/255,o[1]=(i??t)/255,o[2]=(r??t)/255,o[3]=n/255}class it{constructor(){l(this,"dt",1);l(this,"gt",0);l(this,"vt",0);l(this,"_t",0);l(this,"At",0);l(this,"yt",0);l(this,"wt",0);l(this,"bt",[0,0,0]);l(this,"Ct",[1,1,1,1]);l(this,"Mt",[0,0,0,1]);l(this,"xt",!1);l(this,"Ft",!1);l(this,"Tt",!1);l(this,"$t",0);l(this,"Pt",[0,0,0,1]);l(this,"Et",!1);l(this,"Rt",[]);l(this,"St",[])}static Ut(){return{kt:1,zt:0,Lt:0,Ot:0,At:0,yt:0,wt:0,$t:0,Dt:!1,Ht:!1,Tt:!1,Et:!1,It:[0,0,0],Bt:[1,1,1,1],Gt:[0,0,0,1]}}Nt(t){t.kt=this.dt,t.zt=this.gt,t.Lt=this.vt,t.Ot=this._t,t.At=this.At,t.yt=this.yt,t.wt=this.wt,t.Dt=this.xt,t.Ht=this.Ft,t.Tt=this.Tt,t.$t=this.$t,t.Et=this.Et,t.It[0]=this.bt[0],t.It[1]=this.bt[1],t.It[2]=this.bt[2],t.Bt[0]=this.Ct[0],t.Bt[1]=this.Ct[1],t.Bt[2]=this.Ct[2],t.Bt[3]=this.Ct[3],t.Gt[0]=this.Mt[0],t.Gt[1]=this.Mt[1],t.Gt[2]=this.Mt[2],t.Gt[3]=this.Mt[3]}Xt(t){this.dt=t.kt,this.gt=t.zt,this.vt=t.Lt,this._t=t.Ot,this.At=t.At,this.yt=t.yt,this.wt=t.wt,this.xt=t.Dt,this.Ft=t.Ht,this.Tt=t.Tt,this.$t=t.$t,this.Et=t.Et,this.bt[0]=t.It[0],this.bt[1]=t.It[1],this.bt[2]=t.It[2],this.Ct[0]=t.Bt[0],this.Ct[1]=t.Bt[1],this.Ct[2]=t.Bt[2],this.Ct[3]=t.Bt[3],this.Mt[0]=t.Gt[0],this.Mt[1]=t.Gt[1],this.Mt[2]=t.Gt[2],this.Mt[3]=t.Gt[3]}it(){let t=this.St.pop();t||(t=it.Ut()),this.Nt(t),this.Rt.push(t)}rt(){const t=this.Rt.pop();t?(this.Xt(t),this.St.push(t)):console.warn("pop() called without matching push()")}Yt(t){this.Nt(t)}Kt(t){this.dt=Math.abs(t)}Wt(){this.gt=0,this.vt=0,this._t=0,this.At=0,this.yt=0,this.wt=0,this.Et=!1}Zt(t){t!==0&&(this.At+=t*Math.PI/180)}jt(t){t!==0&&(this.yt+=t*Math.PI/180)}Vt(t){t!==0&&(this.wt+=t*Math.PI/180)}qt(t=0,i=0,r=0){t===0&&i===0&&r===0||(this.gt+=t,this.vt+=i,this._t+=r)}Qt(t){this.qt(t,0,0)}Jt(t){this.qt(0,t,0)}ts(t){this.qt(0,0,t)}ss(t){this.bt[0]=t[0],this.bt[1]=t[1],this.bt[2]=t[2]}es(t,i,r,n=255){et(this.Ct,t,i,r,n)}rs(t,i,r,n=255){et(this.Mt,t,i,r,n)}ns(t){this.xt=t}hs(t){this.Ft=t}cs(t){this.Tt=t}ls(t){this.$t=bt(t)}us(t,i,r,n){et(this.Pt,t,i,r,n)}fs(t){this.Et=t}get canvasBackgroundColor(){return this.Pt}get useOrtho(){return this.Et}get rotationX(){return this.At}get rotationY(){return this.yt}get rotationZ(){return this.wt}}const dt=new Float32Array([-.5,-.5,0,0,.5,-.5,1,0,-.5,.5,0,1,-.5,.5,0,1,.5,-.5,1,0,.5,.5,1,1]),K={ds:16,ps:WebGL2RenderingContext.TRIANGLES,gs:{vs:{size:2,offset:0},_s:{size:2,offset:8}}};class Vt{constructor(t){l(this,"A");l(this,"As");l(this,"ws");this.A=t,this.As=t.createBuffer(),this.ws=new Float32Array(dt.length)}bs(t,i,r,n){const h=this.A,a=Ct(this.A),c=a[2],u=a[3],f=t/c*2-1,d=(t+r)/c*2-1,g=1-(i+n)/u*2,p=1-i/u*2,m=dt,v=this.ws;for(let A=0;A<m.length;A+=4){const w=m[A],y=m[A+1],T=m[A+2],E=m[A+3],U=f+(w+.5)*(d-f),b=g+(y+.5)*(p-g);v[A]=U,v[A+1]=b,v[A+2]=T,v[A+3]=E}h.bindBuffer(h.ARRAY_BUFFER,this.As),h.bufferData(h.ARRAY_BUFFER,v,h.DYNAMIC_DRAW),h.enableVertexAttribArray(0),h.vertexAttribPointer(0,2,h.FLOAT,!1,16,0),h.drawArrays(h.TRIANGLES,0,6),h.disableVertexAttribArray(0),h.bindBuffer(h.ARRAY_BUFFER,null)}ft(){this.A.deleteBuffer(this.As)}}var F=(o=>(o.RECTANGLE="rectangle",o.LINE="line",o.ELLIPSE="ellipse",o.ARC="arc",o.TRIANGLE="triangle",o.BEZIER_CURVE="bezier_curve",o))(F||{});const Zt={rectangle:2,line:2,ellipse:2,triangle:2,arc:3,bezier_curve:4};class qt{constructor(t){l(this,"A");l(this,"Cs",new Map);this.A=t}Ms(t,i,r,n){const h=this.A;let a=this.Cs.get(t);a||(a=new Map,this.Cs.set(t,a));let c=a.get(i)||null;if(!c){c=h.createVertexArray(),a.set(i,c),h.bindVertexArray(c),h.bindBuffer(h.ARRAY_BUFFER,n);const u=h.getAttribLocation(t,"A0");u!==-1&&ut(h,u,r.gs.vs.size,r.ds,r.gs.vs.offset,0,h.FLOAT,!1);const f=h.getAttribLocation(t,"A1");f!==-1&&ut(h,f,r.gs._s.size,r.ds,r.gs._s.offset,0,h.FLOAT,!1)}h.bindVertexArray(c)}Fs(){this.A.bindVertexArray(null)}ft(){for(const[,t]of this.Cs)for(const[,i]of t)i&&this.A.deleteVertexArray(i)}}const _=class _{static Ts(t,i,r=0){const n=i||new Float32Array(_.FLOATS_PER_INSTANCE);let h=r;n[h++]=t.vs[0],n[h++]=t.vs[1],n[h++]=t.$s[0],n[h++]=t.$s[1],n[h++]=t.It[0],n[h++]=t.It[1],n[h++]=t.It[2],n[h++]=t.Bt[0],n[h++]=t.Bt[1],n[h++]=t.Bt[2],n[h++]=t.Bt[3],n[h++]=t.Gt[0],n[h++]=t.Gt[1],n[h++]=t.Gt[2],n[h++]=t.Gt[3],n[h++]=t.Ps[0],n[h++]=t.Ps[1],n[h++]=t.Ps[2],n[h++]=t.$t;const a=t.Es;n[h++]=(a==null?void 0:a[0])??0,n[h++]=(a==null?void 0:a[1])??0,n[h++]=(a==null?void 0:a[2])??0;const c=t.Rs;n[h++]=(c==null?void 0:c[0])??0,n[h++]=(c==null?void 0:c[1])??0,n[h++]=(c==null?void 0:c[2])??0;const u=t.Ss,f=t.Us,d=t.ks,g=t.zs,p=t.Ls,m=!(!f||!d);return m?(n[h++]=(g==null?void 0:g[0])??0,n[h++]=(g==null?void 0:g[1])??0,n[h++]=(p==null?void 0:p[0])??0,n[h++]=(p==null?void 0:p[1])??0,n[h++]=f[0],n[h++]=f[1],n[h++]=d[0],n[h++]=d[1]):!m&&!!u?(n[h++]=u[0],n[h++]=u[1],n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0):(n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0),n[h++]=t.Os??0,n[h++]=t.Ds??0,n[h++]=t.Hs??0,n}static Is(t,i){const r=t.length*_.FLOATS_PER_INSTANCE,n=i||new Float32Array(r);for(let h=0;h<t.length;h++){const a=h*_.FLOATS_PER_INSTANCE;_.Ts(t[h],n,a)}return n}};l(_,"BYTES_PER_INSTANCE",144),l(_,"FLOATS_PER_INSTANCE",36);let N=_;const S=class S{};l(S,"STRIDE",N.BYTES_PER_INSTANCE),l(S,"ATTRIBUTES",{A2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:0,divisor:1},A3:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:8,divisor:1},A4:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:16,divisor:1},A5:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:28,divisor:1},A6:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:44,divisor:1},A7:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:60,divisor:1},A8:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:76,divisor:1},A9:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:88,divisor:1},Aa:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:100,divisor:1},Ab:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:116,divisor:1},Ac:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:132,divisor:1}});let Z=S;class Qt{constructor(t=1e3,i=1.5){l(this,"Bs");l(this,"Gs");l(this,"Ns");l(this,"Xs",0);l(this,"Ys",0);this.Gs=t,this.Ns=i;const r=t*N.FLOATS_PER_INSTANCE;this.Bs=new Float32Array(r)}Ks(t){if(t<=this.Gs)return;const i=Math.ceil(t*this.Ns),r=this.Gs;this.Gs=i;const n=i*N.FLOATS_PER_INSTANCE,h=new Float32Array(n),a=r*N.FLOATS_PER_INSTANCE;h.set(this.Bs.subarray(0,Math.min(a,this.Xs))),this.Bs=h}Ws(){return{buffer:this.Bs,offset:this.Xs}}Zs(t){this.Xs+=t,this.Ys++}js(){this.Xs=0,this.Ys=0}Vs(t=0,i){return this.Bs.subarray(t,i??this.Xs)}get qs(){return this.Ys}get Qs(){return this.Gs}get Js(){return this.Xs}get te(){return this.Ys===0}}class Jt{constructor(t){l(this,"Bs");this.Bs=t}se(t){this.Bs.Ks(this.Bs.qs+1);const{buffer:i,offset:r}=this.Bs.Ws();i[r+0]=t.x,i[r+1]=t.y,i[r+2]=t.width,i[r+3]=t.height,i[r+4]=t.char0,i[r+5]=t.char1,i[r+6]=t.char2,i[r+7]=t.r1,i[r+8]=t.g1,i[r+9]=t.b1,i[r+10]=t.a1,i[r+11]=t.r2,i[r+12]=t.g2,i[r+13]=t.b2,i[r+14]=t.a2,i[r+15]=t.invert,i[r+16]=t.flipX,i[r+17]=t.flipY,i[r+18]=t.charRot,i[r+19]=t.translationX,i[r+20]=t.translationY,i[r+21]=t.translationZ,i[r+22]=t.rotationX,i[r+23]=t.rotationY,i[r+24]=t.rotationZ;const n=t.curveParams0,h=t.curveParams1;return i[r+25]=n[0],i[r+26]=n[1],i[r+27]=n[2],i[r+28]=n[3],i[r+29]=h[0],i[r+30]=h[1],i[r+31]=h[2],i[r+32]=h[3],i[r+33]=t.depth,i[r+34]=t.baseZ,i[r+35]=t.geometryType,this.Bs.Zs(N.FLOATS_PER_INSTANCE),this.Bs.qs-1}get qs(){return this.Bs.qs}}class $t{constructor(t,i=1e3){l(this,"A");l(this,"ee",null);l(this,"ie",0);l(this,"re",new Map);this.A=t,this.ne(i)}ne(t){const i=this.A;this.ee&&i.deleteBuffer(this.ee),this.ee=i.createBuffer();const r=t*N.BYTES_PER_INSTANCE;Rt(i,i.ARRAY_BUFFER,this.ee,r,i.DYNAMIC_DRAW),this.ie=t}oe(t){this.ne(t)}get Qs(){return this.ie}he(t,i){if(i===0)return;const r=this.A;r.bindBuffer(r.ARRAY_BUFFER,this.ee);const n=i*N.FLOATS_PER_INSTANCE;r.bufferSubData(r.ARRAY_BUFFER,0,t,0,n)}ae(t){let i=this.re.get(t);if(!i){i=new Map;const r=this.A;for(const n in Z.ATTRIBUTES){const h=r.getAttribLocation(t,n);h!==-1&&i.set(n,h)}this.re.set(t,i)}return i}ce(t){const i=this.A,r=t.D,n=this.ae(r);for(const[h,a]of n){const c=Z.ATTRIBUTES[h];c&&ut(i,a,c.size,c.stride,c.offset,c.divisor,c.type,c.normalized)}}le(t){const i=this.A,r=this.ae(t.D);for(const[n,h]of r)Z.ATTRIBUTES[n]&&(i.disableVertexAttribArray(h),i.vertexAttribDivisor(h,0))}ft(){this.ee&&(this.A.deleteBuffer(this.ee),this.ee=null),this.re.clear()}}class te{constructor(t,i=1e3,r=1.5){l(this,"A");l(this,"Bs");l(this,"ue");l(this,"fe");this.A=t,this.Bs=new Qt(i,r),this.ue=new Jt(this.Bs),this.fe=new $t(t,i)}de(t){var n,h,a,c,u,f,d,g,p,m;const i=[0,0,0,0],r=[0,0,0,0];return t.Us&&t.ks?(i[0]=((n=t.zs)==null?void 0:n[0])??0,i[1]=((h=t.zs)==null?void 0:h[1])??0,i[2]=((a=t.Ls)==null?void 0:a[0])??0,i[3]=((c=t.Ls)==null?void 0:c[1])??0,r[0]=t.Us[0],r[1]=t.Us[1],r[2]=t.ks[0],r[3]=t.ks[1]):t.Ss&&(i[0]=t.Ss[0],i[1]=t.Ss[1]),this.se({x:t.vs[0],y:t.vs[1],width:t.$s[0],height:t.$s[1],char0:t.It[0],char1:t.It[1],char2:t.It[2],r1:t.Bt[0],g1:t.Bt[1],b1:t.Bt[2],a1:t.Bt[3],r2:t.Gt[0],g2:t.Gt[1],b2:t.Gt[2],a2:t.Gt[3],invert:t.Ps[0],flipX:t.Ps[1],flipY:t.Ps[2],charRot:t.$t,translationX:((u=t.Es)==null?void 0:u[0])??0,translationY:((f=t.Es)==null?void 0:f[1])??0,translationZ:((d=t.Es)==null?void 0:d[2])??0,rotationX:((g=t.Rs)==null?void 0:g[0])??0,rotationY:((p=t.Rs)==null?void 0:p[1])??0,rotationZ:((m=t.Rs)==null?void 0:m[2])??0,curveParams0:i,curveParams1:r,depth:t.Os||0,baseZ:t.Ds||0,geometryType:t.Hs||0})}se(t){const i=this.ue.se(t);return this.Bs.Qs>this.fe.Qs&&this.fe.oe(this.Bs.Qs),i}get pe(){return this.Bs.qs}get te(){return this.Bs.te}ge(){this.Bs.js()}ce(t){const i=this.Bs.qs;if(i===0)return;const r=this.Bs.Vs();this.fe.he(r,i),this.fe.ce(t)}le(t){this.fe.le(t)}bs(t,i){const r=this.Bs.qs;r!==0&&this.A.drawArraysInstanced(t,0,i,r)}ft(){this.fe.ft()}}class Y{constructor(t,i,r,n){l(this,"A");l(this,"ve");l(this,"me");l(this,"_e");l(this,"Ae",null);this.A=t,this.ve=i,this.me=r,this._e=n;const h=this.A.createBuffer();Rt(this.A,this.A.ARRAY_BUFFER,h,this._e.ye,this.A.STATIC_DRAW),this.Ae=h}get type(){return this.me}get unitGeometry(){return this._e}get unitBuffer(){return this.Ae}get batch(){return this.ve}we(){this.ve.ge()}be(){return!this.ve.te}ft(){this.ve.ft(),this.A.deleteBuffer(this.Ae)}Ce(t,i,r){return this.ve.de(t)}Me(t,i,r,n,h,a){const c=h.zt??0,u=h.Lt??0,f=h.Ot??0,d=h.At??0,g=h.yt??0,p=h.wt??0,m=[0,0,0,0],v=[0,0,0,0];a&&(a.bezStartX!==void 0&&a.bezStartY!==void 0&&a.bezEndX!==void 0&&a.bezEndY!==void 0?(m[0]=a.cp1x??0,m[1]=a.cp1y??0,m[2]=a.cp2x??0,m[3]=a.cp2y??0,v[0]=a.bezStartX??0,v[1]=a.bezStartY??0,v[2]=a.bezEndX??0,v[3]=a.bezEndY??0):a.arcStart===void 0&&a.arcStop===void 0||(m[0]=a.arcStart??0,m[1]=a.arcStop??0));const A={x:t,y:i,width:r,height:n,char0:h.It[0],char1:h.It[1],char2:h.It[2],r1:h.Bt[0],g1:h.Bt[1],b1:h.Bt[2],a1:h.Bt[3],r2:h.Gt[0],g2:h.Gt[1],b2:h.Gt[2],a2:h.Gt[3],invert:h.Tt?1:0,flipX:h.Dt?1:0,flipY:h.Ht?1:0,charRot:h.$t,translationX:c,translationY:u,translationZ:f,rotationX:d,rotationY:g,rotationZ:p,curveParams0:m,curveParams1:v,depth:(a==null?void 0:a.depth)??0,baseZ:(a==null?void 0:a.baseZ)??0,geometryType:Zt[this.me]??0};return this.ve.se(A)}}const ee={ye:dt,xe:6,...K},ie={ye: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]),xe:6,...K},se={ye:function(o=32){const t=[],i=2*Math.PI/o;for(let r=0;r<o;r++){const n=r*i,h=(r+1)%o*i,a=Math.cos(n),c=Math.sin(n),u=.5*(a+1),f=.5*(c+1),d=Math.cos(h),g=Math.sin(h),p=.5*(d+1),m=.5*(g+1);t.push(0,0,.5,.5,a,c,u,f,d,g,p,m)}return new Float32Array(t)}(32),xe:96,...K};let re={ye:function(o){const t=[];for(let i=0;i<o;i++){const r=i/o,n=(i+1)/o;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),xe:96,...K};const ne={ye:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),xe:3,...K},he={ye:function(o=16){const t=[];for(let i=0;i<o;i++){const r=i/o,n=(i+1)/o;t.push(r,-.5,r,0,n,-.5,n,0,r,.5,r,1,r,.5,r,1,n,-.5,n,0,n,.5,n,1)}return new Float32Array(t)}(16),xe:96,...K},oe={[F.RECTANGLE]:class extends Y{constructor(o,t){super(o,t,F.RECTANGLE,ee)}de(o,t){return this.Me(0,0,o.width,o.height,t)}},[F.LINE]:class extends Y{constructor(o,t){super(o,t,F.LINE,ie)}de(o,t){const i=o.x2-o.x1,r=o.y2-o.y1,n=Math.hypot(i,r),h=Math.atan2(r,i),a=t.kt||1,c=o.x1+i/2-n/2,u=o.y1+r/2,f={...t,wt:(t.wt||0)+h};return this.Me(c,u,n,a,f)}},[F.ELLIPSE]:class extends Y{constructor(o,t){super(o,t,F.ELLIPSE,se)}de(o,t){return this.Me(0,0,o.width,o.height,t)}},[F.ARC]:class extends Y{constructor(o,t){super(o,t,F.ARC,re)}de(o,t){const i=o.start*Math.PI/180,r=o.stop*Math.PI/180;return this.Me(0,0,o.width,o.height,t,{arcStart:i,arcStop:r})}},[F.TRIANGLE]:class extends Y{constructor(o,t){super(o,t,F.TRIANGLE,ne)}de(o,t){const i=Math.min(o.x1,o.x2,o.x3),r=Math.max(o.x1,o.x2,o.x3),n=Math.min(o.y1,o.y2,o.y3),h=r-i,a=Math.max(o.y1,o.y2,o.y3)-n;return this.Me(i,n,h,a,t)}},[F.BEZIER_CURVE]:class extends Y{constructor(o,t){super(o,t,F.BEZIER_CURVE,he)}de(o,t){return this.Me(0,0,1,t.kt||1,t,{cp1x:o.cp1x,cp1y:o.cp1y,cp2x:o.cp2x,cp2y:o.cp2y,bezStartX:o.x1,bezStartY:o.y1,bezEndX:o.x2,bezEndY:o.y2})}}};class ae{constructor(t){l(this,"A");l(this,"Fe");l(this,"Te");this.A=t,this.Te=new qt(t),this.Fe=new Map;for(const i of Object.values(F)){const r=new te(t),n=new oe[i](t,r);this.Fe.set(i,n)}}$e(t){const i=this.Pe(t);for(const r of i)this.Ee(r)}Pe(t){const i=[];let r=null,n=null,h=null;for(const a of t)n!==a.material||h!==a.type?(r&&r.length>0&&i.push({material:n,type:h,commands:r}),r=[a],n=a.material,h=a.type):r.push(a);return r&&r.length>0&&i.push({material:n,type:h,commands:r}),i}Ee(t){const{material:i,type:r,commands:n}=t,h=this.Fe.get(r);i.shader.U(),i.shader.L(i.uniforms);const a=Ct(this.A),c=n.length>0&&n[0].state.Et;i.shader.L({Uh:a[2]/a[3],Ue:[a[2],a[3]],Uf:1,Ug:c?1:0}),h.we();for(const u of n)h.de(u.params,u.state);if(h.be()){const u=h.unitGeometry,f=h.unitBuffer;try{this.Te.Ms(i.shader.D,r+"",u,f),h.batch.ce(i.shader),h.batch.bs(u.ps,u.xe)}finally{h.batch.le(i.shader),this.Te.Fs(),h.we()}}}ft(){for(const t of this.Fe.values())t.ft();this.Fe.clear(),this.Te.ft()}}function Ut(o){let t=0;for(let i=0;i<o.length;i++)t=(t<<5)-t+o.charCodeAt(i),t&=t;return t}function Mt(o){return Ut(o+"")}function q(o,t){return(o<<5)-o+t}class ce{constructor(t){l(this,"Re",0);l(this,"Se");l(this,"ke");l(this,"ze",new Map);this.Se=new j(t,tt,`#version 300 es
10
- precision highp float;in vec3 v_glyphIndex;in vec4 v_glyphColor;in vec4 v_cellColor;in vec4 v_glyphFlags;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;void main(){int A=int(v_glyphFlags.r>0.5?1:0);int B=int(v_glyphFlags.g>0.5?1:0);int C=int(v_glyphFlags.b>0.5?1:0);float D=float(A|(B<<1)|(C<<2))/255.;o_character=vec4(v_glyphIndex.xy,D,clamp(v_glyphFlags.a,0.,1.));o_primaryColor=vec4(v_glyphColor.rgb,v_glyphColor.a);o_secondaryColor=vec4(v_cellColor.rgb,v_cellColor.a);}`),this.ke={id:this.Re++,shader:this.Se,uniforms:Object.freeze({}),hash:this.Le(this.Se,{}),isBuiltIn:!0}}get Oe(){return this.ke}lt(t,i={},r=!1){const n=this.Le(t,i),h=this.ze.get(n);if(h)return h;const a={id:this.Re++,shader:t,uniforms:Object.freeze({...i}),hash:n,isBuiltIn:r};return this.ze.set(n,a),a}De(t,i={}){return{id:this.Re++,shader:t,uniforms:Object.freeze({...i}),hash:0,isBuiltIn:!1}}Le(t,i){const r=Mt(t.D),n=function(h,a){let c=0;const u=Object.keys(h).sort();for(const f of u)c=q(c,Ut(f)),c=q(c,a(h[f]));return c}(i,this.He.bind(this));return q(r,n)}He(t){return typeof t=="number"||typeof t=="boolean"?function(i){return typeof i=="boolean"?i?1:0:Math.floor(i)}(t):Array.isArray(t)?function(i){let r=0;const n=Array.isArray(i[0])?i.flat():i;for(const h of n)r=q(r,typeof h=="number"?h:0);return r}(t):t instanceof Float32Array||t instanceof Int32Array?function(i){let r=0;const n=Math.min(i.length,16);for(let h=0;h<n;h++)r=q(r,i[h]);return r}(t):t instanceof WebGLTexture?Mt(t):0}ft(){this.Se!=this.Se&&this.Se.dispose(),this.Se.dispose(),this.ze.clear()}}class le{constructor(){l(this,"Ie",[]);l(this,"Be",1);l(this,"$s",0)}Ge(t,i){if(this.$s>=this.Ie.length){const n={id:this.Be++,type:t,params:{},state:it.Ut(),material:i};this.Ie.push(n)}const r=this.Ie[this.$s];return r.id=this.Be++,r.type=t,r.material=i,this.$s++,r}Ne(t,i,r){const n=this.Ge(F.RECTANGLE,r),h=n.params;return h.width=t.width,h.height=t.height,i.Yt(n.state),n.id}Xe(t,i,r){const n=this.Ge(F.LINE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.x2=t.x2,h.y2=t.y2,h.thickness=t.thickness,i.Yt(n.state),n.id}Ye(t,i,r){const n=this.Ge(F.ELLIPSE,r),h=n.params;return h.width=t.width,h.height=t.height,h.startAngle=t.startAngle,h.endAngle=t.endAngle,h.segments=t.segments,i.Yt(n.state),n.id}Ke(t,i,r){const n=this.Ge(F.ARC,r),h=n.params;return h.width=t.width,h.height=t.height,h.start=t.start,h.stop=t.stop,i.Yt(n.state),n.id}We(t,i,r){const n=this.Ge(F.TRIANGLE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.x2=t.x2,h.y2=t.y2,h.x3=t.x3,h.y3=t.y3,i.Yt(n.state),n.id}Ze(t,i,r){const n=this.Ge(F.BEZIER_CURVE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.cp1x=t.cp1x,h.cp1y=t.cp1y,h.cp2x=t.cp2x,h.cp2y=t.cp2y,h.x2=t.x2,h.y2=t.y2,h.thickness=t.thickness,h.segments=t.segments,i.Yt(n.state),n.id}ge(){this.$s=0}[Symbol.iterator](){let t=0;const i=this.$s,r=this.Ie;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}class ue{constructor(t){l(this,"A");l(this,"je",null);l(this,"Ve");l(this,"ut");l(this,"qe");l(this,"Qe");l(this,"Je");l(this,"ti",null);l(this,"si",{});l(this,"ei",[]);l(this,"ii",[]);l(this,"ri",null);l(this,"ni",[0,0,0,0]);this.A=t,t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.clearDepth(1),t.depthMask(!0),t.disable(t.CULL_FACE),this.qe=new it,this.ut=new ce(t),this.Qe=new le,this.Ve=new ae(t),this.Je=new Vt(t);const i=[0,0,t.canvas.width,t.canvas.height];ft(t,i),this.ei.push(null),this.ii.push(i),this.ri=null,this.ni=i}st(){this.ei.push(this.ri),this.ii.push([...this.ni])}ot(){const t=this.ei.pop()??null,i=this.ii.pop()??[0,0,this.A.canvas.width,this.A.canvas.height];this.et(t,i[2],i[3])}et(t,i,r){const n=this.A;this.ri!==t&&(n.bindFramebuffer(n.FRAMEBUFFER,t),this.ri=t);const h=[0,0,i,r];this.ni[0]===h[0]&&this.ni[1]===h[1]&&this.ni[2]===h[2]&&this.ni[3]===h[3]||(n.viewport(...h),ft(n,h),this.ni=h)}oi(t){this.je!==t&&(this.je=t,t.U())}hi(t,i){return new j(this.A,t,i)}ai(t){this.ti=t,t&&(this.si={})}O(t,i){this.si[t]=i}ci(t){Object.assign(this.si,t)}li(t){return new j(this.A,tt,t)}ui(t,i,r){this.Qe.Ne({width:i??t.width,height:r??t.height},this.qe,t.ht())}fi(t,i,r,n){this.Je.bs(t,i,r,n)}di(t,i){if(this.ti){const r=this.ut.De(this.ti,this.si);this.Qe.Ne({width:t,height:i},this.qe,r),this.ti=null,this.si={}}else this.Qe.Ne({width:t,height:i},this.qe,this.ut.Oe)}pi(t,i,r,n){this.Qe.Xe({x1:t,y1:i,x2:r,y2:n},this.qe,this.ut.Oe)}gi(t,i){this.Qe.Ye({width:t,height:i},this.qe,this.ut.Oe)}mi(t,i,r,n,h,a){this.Qe.We({x1:t,y1:i,x2:r,y2:n,x3:h,y3:a},this.qe,this.ut.Oe)}_i(t,i,r,n,h,a,c,u){this.Qe.Ze({x1:t,y1:i,cp1x:r,cp1y:n,cp2x:h,cp2y:a,x2:c,y2:u},this.qe,this.ut.Oe)}Ai(t,i,r,n){this.Qe.Ke({width:t,height:i,start:r,stop:n},this.qe,this.ut.Oe)}yi(t,i,r=1,n={}){return new V(this.A,t,i,r,n,this)}wi(t,i=t,r=t,n=255){this.qe.us(t,i??t,r??t,n);const[h,a,c,u]=this.qe.canvasBackgroundColor;this.ge(h,a,c,u)}ge(t=0,i=0,r=0,n=0){this.A.clearColor(t,i,r,n),this.A.clear(this.A.COLOR_BUFFER_BIT)}bi(){const t=[0,0,this.A.canvas.width,this.A.canvas.height];this.A.viewport(...t),ft(this.A,t),this.ni=t,this.ii.length>0&&(this.ii[0]=t)}nt(){const t=this.Qe;this.Ve.$e(t),t.ge()}ft(){this.ut.ft(),this.Ve.ft(),this.Je.ft()}get context(){return this.A}get state(){return this.qe}get materialManager(){return this.ut}}const C={readShort:(o,t)=>(C.t.uint16[0]=o[t]<<8|o[t+1],C.t.int16[0]),readUshort:(o,t)=>o[t]<<8|o[t+1],readUshorts(o,t,i){const r=[];for(let n=0;n<i;n++)r.push(C.readUshort(o,t+2*n));return r},readUint(o,t){const i=C.t.uint8;return i[3]=o[t],i[2]=o[t+1],i[1]=o[t+2],i[0]=o[t+3],C.t.uint32[0]},readASCII(o,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(o[t+n]);return r},t:(()=>{const o=new ArrayBuffer(8);return{uint8:new Uint8Array(o),int16:new Int16Array(o),uint16:new Uint16Array(o),uint32:new Uint32Array(o)}})()};function st(o){return o+3&-4}function rt(o,t,i){o[t]=i>>>8&255,o[t+1]=255&i}function O(o,t,i){o[t]=i>>>24&255,o[t+1]=i>>>16&255,o[t+2]=i>>>8&255,o[t+3]=255&i}function fe(o,t,i){for(let r=0;r<i.length;r++)o[t+r]=255&i.charCodeAt(r)}function gt(o,t,i){const r=t+i;let n=0;const h=C.t;for(let a=t;a<r;a+=4)h.uint8[3]=o[a]||0,h.uint8[2]=o[a+1]||0,h.uint8[1]=o[a+2]||0,h.uint8[0]=o[a+3]||0,n=n+(h.uint32[0]>>>0)>>>0;return n>>>0}class de{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 Q(o){let t=32,i=0;for(const c of o)c&&(c<t&&(t=c),c>i&&(i=c));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const c of o)c&&r[c]++;const n=new Uint32Array(i+1);let h=0;r[0]=0;for(let c=1;c<=i;c++)h=h+r[c-1]<<1,n[c]=h;const a=new Map;for(let c=0;c<o.length;c++){const u=o[c];if(!u)continue;const f=n[u]++;let d=a.get(u);d||(d=[],a.set(u,d)),d[ge(f,u)]=c}return{min:t,max:i,table:a}}function At(o,t){let i=0;for(let r=1;r<=t.max;r++){i|=o.readBits(1)<<r-1;const n=t.table.get(r);if(n&&i<n.length){const h=n[i];if(h!==void 0)return h}}throw Error("Invalid Huffman code")}function ge(o,t){let i=0;for(let r=0;r<t;r++)i=i<<1|1&o,o>>>=1;return i>>>0}function Ae(o){if(o.length<2)throw Error("ZLIB data too short");const t=o[0],i=o[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(h,a){const c=[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=h.readBits(1);const p=h.readBits(2);if(p===0){h.alignToByte();const m=h.readBits(16);if((65535&(65535^m))!==h.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let v=0;v<m;v++)a.push(h.readBits(8))}else{if(p!==1&&p!==2)throw Error("Unsupported DEFLATE type");{let m,v;if(p===1){const A=Array(288).fill(0);for(let w=0;w<=143;w++)A[w]=8;for(let w=144;w<=255;w++)A[w]=9;for(let w=256;w<=279;w++)A[w]=7;for(let w=280;w<=287;w++)A[w]=8;m=Q(A),v=Q(Array(32).fill(5))}else{const A=h.readBits(5)+257,w=h.readBits(5)+1,y=h.readBits(4)+4,T=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],E=Array(19).fill(0);for(let M=0;M<y;M++)E[T[M]]=h.readBits(3);const U=Q(E),b=[];for(;b.length<A+w;){const M=At(h,U);if(M<=15)b.push(M);else if(M===16){const D=h.readBits(2)+3,P=b[b.length-1]||0;for(let at=0;at<D;at++)b.push(P)}else if(M===17){const D=h.readBits(3)+3;for(let P=0;P<D;P++)b.push(0)}else{if(M!==18)throw Error("Invalid code length symbol");{const D=h.readBits(7)+11;for(let P=0;P<D;P++)b.push(0)}}}const I=b.slice(0,A),L=b.slice(A,A+w);m=Q(I),v=Q(L)}for(;;){const A=At(h,m);if(A<256)a.push(A);else{if(A===256)break;if(A>256&&A<286){const w=A-257;let y=c[w];const T=u[w];T&&(y+=h.readBits(T));const E=At(h,v);if(E>=30)throw Error("Invalid distance symbol");let U=f[E];const b=d[E];b&&(U+=h.readBits(b));const I=a.length-U;if(I<0)throw Error("Invalid distance");for(let L=0;L<y;L++)a.push(a[I+L]||0)}else if(A===286||A===287)throw Error("Reserved length symbol")}}}}}}(new de(o.subarray(r)),n),new Uint8Array(n)}function pe(o){const t=C,i=new Uint8Array(o);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),n=t.readUshort(i,12),h=t.readUint(i,16),a=[];let c=44;for(let y=0;y<n;y++){const T=t.readASCII(i,c,4),E=t.readUint(i,c+4),U=t.readUint(i,c+8),b=t.readUint(i,c+12),I=t.readUint(i,c+16);a.push({tag:T,offset:E,compLength:U,origLength:b,checksum:I}),c+=20}for(const y of a){const T=new Uint8Array(i.buffer,y.offset,y.compLength);if(y.compLength===y.origLength)y.data=new Uint8Array(T);else if(y.data=Ae(T),y.data.length!==y.origLength)if(y.data.length<y.origLength){const E=new Uint8Array(y.origLength);E.set(y.data),y.data=E}else y.data=y.data.subarray(0,y.origLength)}const u=n;let f=1,d=0;for(;f<<1<=u;)f<<=1,d++;const g=16*f,p=16*u-g;let m=12+16*u;const v={};for(const y of a)v[y.tag]=m,m=st(m+y.data.length);const A=new Uint8Array(Math.max(h||0,m));O(A,0,r),rt(A,4,u),rt(A,6,g),rt(A,8,d),rt(A,10,p);let w=12;for(const y of a){fe(A,w,y.tag),w+=4;let T=y.data;if(y.tag==="head"&&T.length>=12){const E=new Uint8Array(T);O(E,8,0),O(A,w,gt(E,0,st(E.length))),w+=4}else O(A,w,gt(T,0,st(T.length))),w+=4;O(A,w,v[y.tag]),w+=4,O(A,w,y.data.length),w+=4}for(const y of a){const T=v[y.tag];A.set(y.data,T)}if(a.find(y=>y.tag==="head")){const y=v.head,T=function(E,U){const b=U+8,I=[E[b],E[b+1],E[b+2],E[b+3]];O(E,b,0);const L=2981146554-(gt(E,0,st(E.length))>>>0)>>>0;return E[b]=I[0],E[b+1]=I[1],E[b+2]=I[2],E[b+3]=I[3],L>>>0}(A,y);O(A,y+8,T)}return A.buffer}const me={parseTab(o,t,i){const r={tables:[],ids:{},off:t};o=new Uint8Array(o.buffer,t,i),t=0;const n=C,h=n.readUshort,a=h(o,t+=2);t+=2;const c=[];for(let u=0;u<a;u++){const f=h(o,t),d=h(o,t+=2);t+=2;const g=n.readUint(o,t);t+=4;const p=`p${f}e${d}`;let m=c.indexOf(g);if(m===-1){let v;m=r.tables.length,c.push(g);const A=h(o,g);v=A===4?this.parse4(o,g):A===12?this.parse12(o,g):{format:A},r.tables.push(v)}r.ids[p]=m}return r},parse4(o,t){const i=C,r=i.readUshort,n=i.readUshorts,h=t,a=r(o,t+=2);t+=2;const c=r(o,t+=2)>>>1,u={format:4,searchRange:r(o,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,u.entrySelector=r(o,t),t+=2,u.rangeShift=r(o,t),t+=2,u.endCount=n(o,t,c),t+=2*c,t+=2,u.startCount=n(o,t,c),t+=2*c;for(let f=0;f<c;f++)u.idDelta.push(i.readShort(o,t)),t+=2;return u.idRangeOffset=n(o,t,c),t+=2*c,u.glyphIdArray=n(o,t,h+a-t>>1),u},parse12(o,t){const i=C.readUint;i(o,t+=4),i(o,t+=4);const r=i(o,t+=4);t+=4;const n=new Uint32Array(3*r);for(let h=0;h<3*r;h+=3)n[h]=i(o,t+(h<<2)),n[h+1]=i(o,t+(h<<2)+4),n[h+2]=i(o,t+(h<<2)+8);return{format:12,groups:n}}},ve={parseTab(o,t,i){const r=C;t+=18;const n=r.readUshort(o,t);t+=2,t+=16;const h=r.readShort(o,t);t+=2;const a=r.readShort(o,t);t+=2;const c=r.readShort(o,t);t+=2;const u=r.readShort(o,t);return t+=2,t+=6,{unitsPerEm:n,xMin:h,yMin:a,xMax:c,yMax:u,indexToLocFormat:r.readShort(o,t)}}},ye={parseTab(o,t,i){const r=C;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],h={};for(let a=0;a<n.length;a++){const c=n[a],u=c==="advanceWidthMax"||c==="numberOfHMetrics"?r.readUshort:r.readShort;h[c]=u(o,t+2*a)}return h}},we={parseTab(o,t,i,r){const n=C,h=[],a=[],c=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,d=0,g=0;for(;g<u;)f=n.readUshort(o,t+(g<<2)),d=n.readShort(o,t+(g<<2)+2),h.push(f),a.push(d),g++;for(;g<c;)h.push(f),a.push(d),g++;return{aWidth:h,lsBearing:a}}},It={cmap:me,head:ve,hhea:ye,maxp:{parseTab(o,t,i){const r=C;return r.readUint(o,t),t+=4,{numGlyphs:r.readUshort(o,t)}}},hmtx:we,loca:{parseTab(o,t,i,r){const n=C,h=[],a=r.head.indexToLocFormat,c=r.maxp.numGlyphs+1;if(a===0)for(let u=0;u<c;u++)h.push(n.readUshort(o,t+(u<<1))<<1);else if(a===1)for(let u=0;u<c;u++)h.push(n.readUint(o,t+(u<<2)));return h}},glyf:{parseTab(o,t,i,r){const n=[],h=r.maxp.numGlyphs;for(let a=0;a<h;a++)n.push(null);return n},Ci(o,t){const i=C,r=o.Mi,n=o.loca;if(n[t]===n[t+1])return null;const h=J.findTable(r,"glyf",o.xi);if(!h)return null;let a=h[0]+n[t];const c={};if(c.noc=i.readShort(r,a),a+=2,c.xMin=i.readShort(r,a),a+=2,c.yMin=i.readShort(r,a),a+=2,c.xMax=i.readShort(r,a),a+=2,c.yMax=i.readShort(r,a),a+=2,c.xMin>=c.xMax||c.yMin>=c.yMax)return null;if(c.noc>0){c.endPts=[];for(let p=0;p<c.noc;p++)c.endPts.push(i.readUshort(r,a)),a+=2;const u=i.readUshort(r,a);if(a+=2,r.length-a<u)return null;a+=u;const f=c.endPts[c.noc-1]+1;c.flags=[];for(let p=0;p<f;p++){const m=r[a];if(a++,c.flags.push(m),8&m){const v=r[a];a++;for(let A=0;A<v;A++)c.flags.push(m),p++}}c.xs=[];for(let p=0;p<f;p++){const m=c.flags[p],v=!!(16&m);2&m?(c.xs.push(v?r[a]:-r[a]),a++):v?c.xs.push(0):(c.xs.push(i.readShort(r,a)),a+=2)}c.ys=[];for(let p=0;p<f;p++){const m=c.flags[p],v=!!(32&m);4&m?(c.ys.push(v?r[a]:-r[a]),a++):v?c.ys.push(0):(c.ys.push(i.readShort(r,a)),a+=2)}let d=0,g=0;for(let p=0;p<f;p++)d+=c.xs[p],g+=c.ys[p],c.xs[p]=d,c.ys[p]=g}else c.parts=[],c.endPts=[],c.flags=[],c.xs=[],c.ys=[];return c}}},J={parse(o){const t=new Uint8Array(o);C.readASCII(t,0,4)==="wOFF"&&(o=pe(o));const i=new Uint8Array(o),r=It,n={},h={Mi:i,Fi:0,xi:0};for(const a in r){const c=a,u=J.findTable(i,c,0);if(u){const[f,d]=u;let g=n[f];g==null&&(g=r[c].parseTab(i,f,d,h),n[f]=g),h[c]=g}}return[h]},findTable(o,t,i){const r=C,n=r.readUshort(o,i+4);let h=i+12;for(let a=0;a<n;a++){const c=r.readASCII(o,h,4);r.readUint(o,h+4);const u=r.readUint(o,h+8),f=r.readUint(o,h+12);if(c===t)return[u,f];h+=16}return null},T:It,B:C};class Ee{Ti(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const h=this.$i(n);i.push(...h)}else if(n.format===12){const h=this.Pi(n);i.push(...h)}}),[...new Set(i)]):[]}$i(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],h=t.endCount[r];if(n!==65535||h!==65535){for(let a=n;a<=h;a++)if(this.Ei(t,a,r)>0)try{const c=String.fromCodePoint(a);i.push(c)}catch{}}}return i}Pi(t){const i=[];if(!t.groups)return i;for(let r=0;r<t.groups.length;r+=3){const n=t.groups[r],h=t.groups[r+1],a=t.groups[r+2];for(let c=n;c<=h;c++)if(a+(c-n)>0)try{const u=String.fromCodePoint(c);i.push(u)}catch{}}return i}Ei(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 h=t.glyphIdArray[n];if(h!==0)return h+t.idDelta[r]&65535}}return 0}}class Te{constructor(t){l(this,"Ri");l(this,"Si");l(this,"K");this.K=t,this.Ri=document.createElement("canvas"),this.Si=this.Ri.getContext("2d",{willReadFrequently:!0,alpha:!0})}Ui(t,i,r,n){const h=t.length,a=Math.ceil(Math.sqrt(h)),c=Math.ceil(h/a),u=i.width*a,f=i.height*c;this.ki(u,f),this.zi(t,i,a,r,n);const d=this.K.yi(u,f,1,{filter:"nearest"});return d.tt(this.Ri),{framebuffer:d,columns:a,rows:c}}ki(t,i){this.Ri.width=t,this.Ri.height=i,this.Ri.style.width=t+"px",this.Ri.style.height=i+"px",this.Si.imageSmoothingEnabled=!1,this.Ri.style.imageRendering="pixelated",this.Si.clearRect(0,0,t,i),this.Si.textBaseline="top",this.Si.textAlign="left",this.Si.fillStyle="white"}zi(t,i,r,n,h){const a=n/h.head.unitsPerEm;for(let c=0;c<t.length;c++){const u=c%r,f=Math.floor(c/r),d=t[c].glyphData;if(!d)continue;const g=d.advanceWidth*a,p=u*i.width,m=f*i.height,v=p+.5*i.width,A=m+.5*i.height,w=Math.round(v-.5*i.width),y=Math.round(A-.5*n),T=w+.5*(i.width-g),E=y+h.hhea.ascender*a;this.Li(d,T,E,a)}}Li(t,i,r,n){if(!t||!t.xs||t.noc===0)return;let{xs:h,ys:a,endPts:c,flags:u}=t;if(!(h&&a&&c&&u))return;this.Si.beginPath();let f=0;for(let d=0;d<c.length;d++){const g=c[d];if(!(g<f)){if(g>=f){const p=i+h[f]*n,m=r-a[f]*n;this.Si.moveTo(p,m);let v=f+1;for(;v<=g;)if(1&u[v]){const A=i+h[v]*n,w=r-a[v]*n;this.Si.lineTo(A,w),v++}else{const A=i+h[v]*n,w=r-a[v]*n;if(v+1>g){const T=i+h[f]*n,E=r-a[f]*n;if(1&u[f])this.Si.quadraticCurveTo(A,w,T,E);else{const U=(A+T)/2,b=(w+E)/2;this.Si.quadraticCurveTo(A,w,U,b)}break}const y=v+1;if(1&u[y]){const T=i+h[y]*n,E=r-a[y]*n;this.Si.quadraticCurveTo(A,w,T,E),v=y+1}else{const T=(A+(i+h[y]*n))/2,E=(w+(r-a[y]*n))/2;this.Si.quadraticCurveTo(A,w,T,E),v=y}}this.Si.closePath()}f=g+1}}this.Si.fill()}}class Bt{Oi(t,i){const r=t.cmap;if(!r||!r.tables)return 0;let n=0;for(const h of r.tables)if(h.format===4?n=this.Di(i,h):h.format===12&&(n=this.Hi(i,h)),n>0)break;return n}Ii(t,i){const r=i.codePointAt(0);return r===void 0?0:this.Oi(t,r)}Bi(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,h=t.hhea.descender*r,a=t.hhea.lineGap*r;return{ascender:n,descender:h,lineGap:a,lineHeight:n-h+a,unitsPerEm:t.head.unitsPerEm,scale:r}}Di(t,i){const r=i.endCount.length;let n=-1;for(let h=0;h<r;h++)if(t<=i.endCount[h]){n=h;break}if(n===-1||t<i.startCount[n])return 0;if(i.idRangeOffset[n]===0)return t+i.idDelta[n]&65535;{const h=i.idRangeOffset[n]/2+(t-i.startCount[n])-(r-n);if(h>=0&&h<i.glyphIdArray.length){const a=i.glyphIdArray[h];return a===0?0:a+i.idDelta[n]&65535}}return 0}Hi(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const h=i.groups[3*n],a=i.groups[3*n+1],c=i.groups[3*n+2];if(t>=h&&t<=a)return c+(t-h)}return 0}}class be{constructor(){l(this,"Ni");this.Ni=new Bt}Xi(t,i,r){let n=0;const h=this.Ni.Gi(r,i),a=h.lineHeight;for(const c of t){const u=this.Ni.Ii(r,c);if(u===0)continue;const f=this.Ni.Bi(r,u)*h.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}}class xe{constructor(){l(this,"Yi");this.Yi=new Bt}Ki(t,i){const r=[],n=new Map;return t.forEach((h,a)=>{const c=h.codePointAt(0)||0,u={character:h,unicode:c,color:this.Wi(a),glyphData:this.Zi(i,h)};r.push(u),n.set(h,u)}),{array:r,map:n}}Wi(t){return[t%256/255,Math.floor(t/256)%256/255,0]}Zi(t,i){const r=i.codePointAt(0)||0,n=this.Yi.Oi(t,r);if(n===0)return null;let h=0;t.hmtx&&t.hmtx.aWidth&&n>0&&t.hmtx.aWidth[n]!==void 0&&(h=t.hmtx.aWidth[n]);const a=J.T.glyf.Ci(t,n);return a?{...a,advanceWidth:h}:null}}class pt{constructor(t,i=16){l(this,"ji");l(this,"Vi",[]);l(this,"qi",new Map);l(this,"Qi");l(this,"Ji",16);l(this,"tr",0);l(this,"sr",0);l(this,"er",{width:0,height:0});l(this,"ir");l(this,"rr");l(this,"nr");l(this,"hr");l(this,"ar");this.Ji=i,this.rr=new Ee,this.nr=new Te(t),this.hr=new be,this.ar=new xe}async cr(t){let i;if(t){const r=await fetch(t);if(!r.ok)throw new R(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}else i=await(await fetch("data:font/woff;base64,d09GRgABAAAAABbwAAoAAAAAfywAAQABAAAAAAAAAAAAAAAAAAAAAAAAAABjbWFwAAAA9AAAAbsAAAkgIO8lSWdseWYAAAKwAAAOfgAAaLS4ctN0aGVhZAAAETAAAAAsAAAAOCi8/PVoaGVhAAARXAAAABkAAAAkCwEFAmhtdHgAABF4AAAAhQAABAQEAIOAbG9jYQAAEgAAAAKUAAAECAAy54BtYXhwAAAUlAAAABgAAAAgASIAgm5hbWUAABSsAAAB5wAAA6RWz85KT1MvMgAAFpQAAABFAAAAYM+QEyRwb3N0AAAW3AAAABQAAAAgAGkANHja7dRPSFRRFMfx38wdXblw4cJC7M0bz60gWlULGUFctWgR0UIQQkmDyn27kpAQaaEO2jhWJuafiQFtcDJtSqGhiFZtot5x3jzEVQQhlRJcOb0khiRc1+J94R64uw8cOADCAJT/avwZAiIpRCK3/P999KAS9biOSUxhBhlksYjnWMFrvME7vMca1vEF37ANAwkNqYRKqkk1rdLqscqpVVVQryzbils3rJnocHTWPmgfso/ap+0OuysWjlXHogQKUxVVUw3VUh010DE6QXHqph7qpT66TQmaoAxlaZnyVKC39FHHdbNu0e36or6kr4r4TgsTu75HmEcOy76vUPaVsIFNbOHHX74F3/fyD9+A7ztg1//2de76rH18Z8u+AXqwx/dBN5Z9XfqKiKzLqqzIC8nLkixKThZkXuZkVh7KuNyTuzImKRmVO1KxU7ETMtvmu/lqPptPxjOuKXo3vcveYQ+l2lKlO+Im3H632z3vnis+KaaLKc7zM87yHGc4zdM8zkke5H6+xp3cwRe4jVv5DLdwE5/ik3ycj3Cdk3eWnKfOmDPqJJ3hX9sOCvpPC65QcIWCgv5pPwGY9ak7AHja3V07ryQ5FT62axjQaDWsVmiCFQJpA4QINiAgICDYgICAgICAgICAgICAgIAA//AuF9Xlsn2etqv67iIY6apv3+6yj31e33nYA95FiD4uAAHeA7jyLzoA2Paf/Lp/Dun5W8x/Be/AxyCfO79fnj+e25/ZZzlewcM+3wIhwpfwE/Sc9e8YDyLU1ycF5XUD+to+L98O/An8VKQj0lnOtYdM776OJ71fTVC8//N1rLKDGsXl863OjSl5/iyIUu0HjJ+d+uO3rX3rXd33d/DjfR0/h6/n1iK5kWf36Hf2AxpVa6zU7ZLTnt3Q3wN7+tK6MVcBjUP/3vj56diHuT3YxVbKSvl9FdJHeFE4jfmJn2DSSOS9fuJ27SH7umuoL3oLWGOLxh3f2b8bnn/5Ql8n5SEYFD33q/0lKXxwjQfDOZtGgyEz+W8X5txl2zVb9MXO2S8HfD3ncbHousP6WPV2i/R7C+c06HK5ye/lfdl3Bj5Q2qitaLYhgLQWZY+fr/65A9Ly1r10jI783HOffJWZJ6ee8uuB0nmMXeSqWvRz5Dx/tiWf7H0OF+1DuK7vhy4ffP8An/doofqbQNXTqmlNT1c0v4/Eqpy29eBMLHty0PKZoCMW6VqRlDXNwvbD4RW2MYfyjNdXV3LaJuEdKgXcHvX2nHiz27RxHmC9w/qn0AbS+mJbSeX8pO1zlbbogPK7zJxAs3iFtrV8W/LHsHVZvxJ6Rlt7gum1nvjpnHNO4gFJqaoBWOKFVwKqAangorb2j5KKvG5N31O1ownZdhcZH7FuT9nznoxRv4ylrbfvzA9D88GO8uGDtgN0/1O09ntFlv3YhbIf/ml3/dPGqvi6rCMw6jNd53PM07BnK2eCJXmnzxrruI8ObOuxmZ/dxbd5nS77U7I/xaMdLm5/DXzuLLcwXlOLIVQ0an722pou6raGnpp/QYiwR0V5nwDL0Gk/f2TSUalIGOkSvfNAcVNCesV9a2q675FtsVAk4c5GPEfZT27XVqT9PmpxXtVn0577KO3MGrkXs+xKkHZk6EMUS440uO01t+Ark8yGYYjtsleqoPQksLuF0kOd/7TtbZ3XvNalNRNLqK+90fEDTAfy1FWWOBcT9fkTmrExe+viDNccYF+JqHeIbyBtlYxhStbmSc8DSX9/rICoXkkGSMfEJR7QsYAjNlhgn6iNS7T0AtakNnvaJ+W1TeQdeIxHaHtXaMtU+GP3CL5v+2RqHfc5JC6k9DJ6HhFaHHfu9Lc1Z5HlB5JWNOc8NupiUSlpa/7NIx0W0Ra10YcOVWnDfqhodmgI1CM5nrJS1DYKlMmyeAmoZaLrQnmNSRxAV7qZ0u0sr2Q8WbzUrRivE200nZ+x371Yj+idQH+bsOAFD16woZXuheBJI85UYyA+Ht17bJsTKLHHG+tuQpJX/AGX4eu2lq+vh8gQPgaLUpk1h7fcb1SJ4LEnGb+rdUHRHw96riVV36L5EgdqHNByqCTy82hnkrSSk3k5KTNWnJZ/buTlOvQngiceAkd4OHPz0K+tdOmGUYwJht2kcuBEntSRPOmZfyc40tFqD40IQeb2goGZvKIVzW4G5DMcQ4qOY3zVRzpmo1sMg+U1VemumtLofjFeCcxqJIUnM2vJuQeCHiOOwx4ss7pF6u+PtXxmZApbjCti22JtA+hVxUw7z6Xs2sSzMkeklSLPfwalYkjjt/0bHye4gKkXeaig5MpILVRiAd1vCrtP5Aj5uaN2PF1zxrE7koOgaY2PPL9FkccCKlprUZGr+zr0tw56iCvwGBTs+MFFxVbWeTaCQTj2WCBM1NnoWNxOBpBZU8f00hPsFDr+15wPevNsJG4IN+OGwKyWzKnW8S/GDUHZOd+44SsvbDvCuhYUTQSaQSFeWtoR4Xc833VimVzRvgm58QwZFQTthQ+awgQTeuVI7gLrF638Yixi+ot4RVZ5niDPFxBediyXNj++jUWDgkU3Zc96fDKwv4iiylyA4nalMkLX9C1hf24DNNkZyNDkflOPF4BqwdYbv1vLG9VX03W96PVKiCq+A01i5utY2d9YfSMP0qvQ7eFQUHSKvNfpCl21nqNafqf1UQksqfVe1PEPPNiJpY81iZoP119ZTUHojdpseMYqec5zr/2Jgo695rmycZWzSgOpXzMpbFrHu1Zmq/xA8pX3cgEQZU1/YzaexuQbXIoxF9THdaEzz9VaE5fgNVIPR/sIS8fQyipam9JXqHdOtPEIRllqzP7Ewh9063Z2IYH+GiLNUPFXJIcEM4RYc7bEkjwQL4/1fx+aHL8/62Of5vo3y+p92QX2fh18zrNFcPX9sfZAdBDZu8vxCM4clX31Qr9RrLPkDDDau8v8LZRar2N8lSOj1NGsLJeBZam1TIuwpzwepL3CJAvyANsPnj3BAzsD3a5X6ydEaZUSs50b7g2JrYcyG2lRL+xl+jD+Gfod33w82P0FTuYREa3c70CRS82XCtxIueJHXuIMB6tMt+x7lf7m5U4tyK9L3smuLrxqDxYPI30rYzk2h2NzgPXqAvPrQdqUxvdWF2zVwDrHCq0RoI0Hcrzcn9D8BMxYEMszZBzooqa/jsTxSeTthXTm9FC2n+pYEh8uVqyL9436quMD6pnK7njZM6msy4uYsunVquBSi4clVn8gblYc96TFyF04ll2oqCB300cDIbPxrZoqXZ1DHWvNh2irrNxstSaZYa2VB333tOr9mRcx7ETmXKmSFz6GkidstKjZFE8qIX26eG8KoS/b9uij9GFOiwFIVj5NyErT8rZGstdmD4lc4/xaNevd1uwOPCLX7Ems2TTc81MrUVmzyqdOr1v1PCPat9jmQfUYJEEbzNCSse4DevSYCIXal+bDCC3I2+EeTFKd7ltnFNN0sGLIfRcGfSWKD0BPANWTQIqcNtsaAON/1A/BeywPGhybs2ZEA1sH9FbgDMpTQx5L5k4fN/RR8lBHvif2ftB7oa8isVdrdWDxp/Hp6N8MsdUgqdS0M12EZrhC7TpJZZLZOZelRdeDUyffq3s6xPhztK4Xd9h6f4pIieNu4lI/jEN1XEMjbafK6lry/jkOYedyVMyp2vaHGlM8zBjCkdi28NdrNldgLa/a0orYtN6OwoMh7vPAsxb9eNTDrOdJBWuXsb6En8Evb5yTrJw1Y1XTHnmCFNtPkhHnuN+8QwHGi3JUJf4zeaTJsBpFdnik5V4fZq510ifEHMf7M55f2fteR1DJ73gzf4vyO42Or3Z5mZcWdlY6wb3sRvd0olKfGeaCWm5yGEtDwzLH6yPS95wmcVb2BBrYzig5tGb7Bvb5fkyfvW2nRhlxF3cyz8qGOF//eVLXq7P4oQTop9UASTKPr91h1zu5wu753DbqtXUO8pOT6wzdnQfWn2X3Csr5ktxP4FUmlBHHPThBO0mQ6wTFVxbM5mPCeXWP7ha4YDf8BdvAeaGd/XntlgHlW2eMFAR2CBPYAQzPrGeVy1ieYCOQdtpXGZyss4F2rkr5W8tJh06NTd/HGi+1vbiPN6JTeSfP5k0ihAhRQwgad9wQ1dhoKAntU87DfZy/K8SuEsPg82VQRU5xUGU+ZVrp8SMYtOHiwFC+Z1jLG2dqRuhAw01cZ2qeXBk/ROjaAS1TIuKHVp+Fi5YMrHqqahlY3YbJ0E/N2uUTq/0Cvt717Vfwa/gNfAO/hd/B7+EP8Ef4E/wZ/gJ/hb/B3+Ef8E/4F/z7nla+5T+Afp1wHdQRH/F/+/lF6VrSbuP4v/18VHMVmm7q6TX/Czha0mxJrf+YyNyOfRcYeKSap3+b8UufB8GnJSdec6Iu+toF6nHkaeZxvJ5h4PVgj3ILMz5teArdxnr8/PPoCXqiuvR91zoh2pvS8b0SqUD1FLPubHPaK9Q5lU+GzwI3PgfCOsB9NORgqm5OqfVxLMd1L9+A/s2s+0/0a93MTd3NNRHapruGQLnhZTSzpBMuYFNaz7N5RffPo/MnV2zac3wfRX6Vng0As1cTmE5M38U0eS+H0rvZxXtg6460jlQTZ3Snxw+pO9TKz+mOB5vffTs6umGj+UjMb3/QKfndvlP47UsVAO9Drzo11h+T/rF09Po0st98jHsKh31Ruj2UnbYWLuEd/pM9wOwpZ+KqccfWNZsc4F6c3jtf2ou7Ca6akqXRPThzsadua+/4hq7vgmn6uqux6bXw6AjnLMJbXMM5Ixwi8mR2rc3AOfg2nrs4zZlnDFaChbCtk/bwilwMfBxc0iMYy0MX40x2o/ft9D2Znn9Kl+3MO90HUb747jnzjpyCKVeTuij6DllsctyiUzXN0dgE9We1yK54WBffFqtew9TXpbYfy7dILWH/SXxmqeg4zlvRsZfIbuFnic0SHfRtfj4vsaVq532jl/QpYBykzpe/jec7n1uOmhuETi2xzM5vfy01xQC0vkp6PiKpDd07x6qcUc719K0A1YZjpvLivftqNpzxV/tDtXPTWFrbaowzXj+czsG+nmMt/bQspzj7fnvxeeuG4O/s/Xe412VW3+5VuPT+EV97/r++14Gc3ZvQRHrXMz91IrWHZ4FnK7WOVGjJPfAO3R0BczdLKuevQd5LPVsXd/X8PK6Ll2jK0/NM7P4V1PuI51FvsEMV+KhV4T2+22IQF85a0FlLWXs/IHTOX1B5CGCeEDh6V2ZiTK+eee/dnNjOa2xXz2zndd7sq+XYEZ/Gx/exoK5PoOceWNdnef9W9KCT9EYXqkrPxuhC9GA7faMXpHef1smLTDe1qaDY1N4ozLI4fqsHlwpf+3Cu9F1E/Z4AajG3V8430/6bCdq8QQs9b4OqJyQa1+6BACWaTPI8zrROa//7QGJ19U4tHeTTtePNqu3PnVhXJFSjzZFz4eo3Ndqidi/O6J5Z7X+VsS3cYki51T35Iv+merFeuGe69cbJM3Jq1Fn4kUA5rze4o9CRs22iy5jMsYLMS8g5/wOjbDW/AAB42mNgZGBgAOIzT9tXxvPbfGVgYGEAgZokCXVkmgUizsHABFLNwAAACJYG1HjaY2BkYGBhAAEIyc7AwMiAAhgZAQHPABQAAAB42r1TwRaAIAgD88P59PRA0hxUlw578mBDQOwi0i+oDUzb7nC/xyKH8SuwHH/jSx83jnE745c1RO44G9E1WTE14AQtYvKO6PN6BXRW5EONgCazSS4VXiere+sp7F7cQeSp7Pe2YkaxN7fVFhg/8z/1hfnfaBXnZ8k7wNzp/y13+wRWwErCAAAAeNpl0ylUVVEUBuCtoiKgoiIzAjIIMj9mZBZYMsmMjwcuBhEIBoPBYDAYDAaDwWA0GAwGgsFgMBgMBoPBYDAYDAaDweBnlrX+9e6955x/2oeI//664HbEgTL4HnHwZ8Sh1/AlIm0W3kUc3oN9+BFxJBva4E3E0SvwLCIdR/qniGO98Coiw3vG04hMv5n/fj9GZBUD3iz8xx9FnMiBJxEn0+E+/IrIppNt/VQzvITfEadH4HnEmUG4BV8jchaBn7NZgCMXdy7uXGfzeMjjKZ/PfBwF9hTYU/AhotC5QtpFtIt4K7oLnyOK6RXTKP4TUcJDCe5zNXAHcJTiKOWxlEZZPeAo00U5b+XyltM9vw24KvBWyFzpTOWLiCr5qu6BPdV0qx+Cni+sAc4a3mvw1nqu/RZxsRJkrEsDWeo2wAzq8dY/iGgwpwbfGvTdaA6NOmnUb5PnpiTY00S3SXfN/DU/BustdFrMq8VagqcE/YReEjK3+t4qayuPbTTbdNH2PqJdL+06a5e33VoHjg7vHdY7cXTK2ekedPHWha+b5279ddPo1ndPPuDrkbkH3yX5e/XXy3OvzH34+sy132+//P14B/AO6GuA3qBOB3U6hH/It2Haw2Y2rI9hHV6WdcSsR6eAl1GZx3Qwpr9xcxv3PqGDCbyTvE3KM+muT+lwypkpe6bNaZqfaX6v8j7D8wyNGbwzbyNmdTMrzxxfc9bndDFn5vM8zds37x4smMeCHhf5WTKHJb0uuc/L/C7bs4zrGr2kO5m0ntRZkv8VfazIkvI9RSelg5ReUrKvOrvqHq7p4Lr5retx3fcN/5Mb+Dfs25RpE/8mji0etqzfwLHteZufmzrZobfj/K5ednna0/fe/l+Pca7seNpjYGRgYGRkaGBQYAABJgY0AAAP+ACmeNp1ksFO20AQhv8NgRJaUApSy61LDxVc4uAjNxoJReoNKdCrYy8hZb1rrTcIuPMKfaY+QM899RH6AP3tDJEKqlcefzvzz/xrywD21ScoLK9N3ktW5E3hDl6hL7zG7HvhLrMfhNfxGonwBjUnwj2uz8JbzH4R3sZbPArvIMV34T28wQ+6qG6Puz5+Civyb+EOO/4Ir6GvOsJdaLUrvI53KhXeoGYs3MOu+iq8hai+CW/jo/olvIOiA+E97HeKw/xIp8M0nYQ6O/MunpvZwmbhafv01JK/MKGee6ePB8N/JCFzN6dO+8o4bee5cbnRM+NMyKyuFqHytdHR3MXSF0ZfNQOn93rVORoNm4l64ua3NMjsdYxVfZIkeTBZZC73ZeldPfBhllSLKR0KX2ZzlzyY4BO2JmNjrdeXPtjiAIfIcQTNbz/knWKCgBoZzuDhEHEOgxkWsMyFF9Xne/1Mf8Fdo5i3dY1jDOjz/ymB0eEGp63ao2J/Q5YT8pabqOnQsGn1lvuKjoHRc05Tj4x3jCUzRZu5Wp1winvGl54jruHqjI3C0fVW3qDxuWZ/pEvNPzjhylkxrETR5fQoW09HzYDPwJMm7emm8g5Fq8nIjpWHdronLV0TjJmxXJ4nuGwnWPYcAH8BoeumrAB42mNgYmFgnMDAysDCxMDEAAIQGoiNGc6A+CwMENDAwNDNwFDwGMpliHT00WNwYFBQy4aogJCMgSCSGcJTYGAAAEBYBpIAAAB42mNgZoCANAZjIMnIgAYADecAng==")).arrayBuffer();await this.lr(i),this.ji=J.parse(i)[0],await this.ur()}dr(t){if(t===void 0)return this.Ji;this.Ji=t,this.er=this.hr.Xi(this.Vi.map(r=>r.character),this.Ji,this.ji);const i=this.nr.Ui(this.Vi,this.er,this.Ji,this.ji);this.Qi=i.framebuffer,this.tr=i.columns,this.sr=i.rows}async pr(t){try{const i=await fetch(t);if(!i.ok)throw new R(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.lr(r);const n=J.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.ji=n[0],await this.ur()}catch(i){throw new R("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async lr(t){const i=Date.now();this.ir=new FontFace("CustomFont_"+i,t),await this.ir.load(),document.fonts.add(this.ir)}async ur(){const t=this.rr.Ti(this.ji),{array:i,map:r}=this.ar.Ki(t,this.ji);this.Vi=i,this.qi=r,this.er=this.hr.Xi(t,this.Ji,this.ji);const n=this.nr.Ui(this.Vi,this.er,this.Ji,this.ji);this.Qi=n.framebuffer,this.tr=n.columns,this.sr=n.rows}gr(t){const i=this.qi.get(t);return i?i.color:[0,0,0]}vr(t){return Array.from(t).map(i=>{const r=this.qi.get(i);return r?r.color:[0,0,0]})}ft(){this.Qi.ft(),document.fonts.delete(this.ir)}get fontFramebuffer(){return this.Qi}get characterMap(){return this.qi}get characters(){return this.Vi}get textureColumns(){return this.tr}get textureRows(){return this.sr}get maxGlyphDimensions(){return this.er}get fontSize(){return this.Ji}get font(){return this.ji}}class mt{constructor(t,i,r){l(this,"mr");l(this,"_r");l(this,"H");l(this,"I");l(this,"Ar");l(this,"yr");l(this,"wr");l(this,"br");l(this,"Cr");this.wr=t,this.br=i,this.Cr=r,this.js()}js(){this.mr=Math.floor(this.wr.width/this.br),this._r=Math.floor(this.wr.height/this.Cr),this.H=this.mr*this.br,this.I=this._r*this.Cr,this.Ar=Math.floor((this.wr.width-this.H)/2),this.yr=Math.floor((this.wr.height-this.I)/2)}Mr(t,i){this.br=t,this.Cr=i,this.js()}get cellWidth(){return this.br}get cellHeight(){return this.Cr}get cols(){return this.mr}get rows(){return this._r}get width(){return this.H}get height(){return this.I}get offsetX(){return this.Ar}get offsetY(){return this.yr}}const Re=/^rgba?\(([^)]+)\)$/i;function vt(o){return Number.isNaN(o)?0:Math.max(0,Math.min(255,o))}function Fe(o){if(!o)return null;const t=o.trim().toLowerCase();if(!t)return null;let i=null;return t.startsWith("rgb")&&(i=function(r){const n=Re.exec(r.trim());if(!n)return null;const h=n[1].split(",").map(d=>d.trim());if(h.length<3)return null;const a=vt(parseFloat(h[0])),c=vt(parseFloat(h[1])),u=vt(parseFloat(h[2])),f=h[3]!==void 0?255*Math.max(0,Math.min(1,parseFloat(h[3]))):255;return[a,c,u,Math.round(f)]}(t)),i?i[3]===0?null:i:null}class St{constructor(t={}){l(this,"wr");l(this,"Fr",null);l(this,"Tr",!1);l(this,"$r");this.Tr=t.overlay??!1,this.Tr&&t.canvas?(this.Fr=t.canvas,this.wr=this.Pr(),this.$r=!0,this.Er()):t.canvas?(this.wr=t.canvas,this.$r=!1):(this.wr=this.Rr(t.width,t.height),this.$r=!0),this.wr.style.imageRendering="pixelated"}Rr(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}Pr(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.Fr.getBoundingClientRect();let r=Math.round(i.width),n=Math.round(i.height);if(this.Fr instanceof HTMLVideoElement){const c=this.Fr;(r===0||n===0)&&c.videoWidth>0&&c.videoHeight>0&&(r=c.videoWidth,n=c.videoHeight)}t.width=r,t.height=n,t.style.position="absolute",t.style.pointerEvents="none";const h=window.getComputedStyle(this.Fr);let a=parseInt(h.zIndex||"0",10);return isNaN(a)&&(a=0),t.style.zIndex=""+(a+1),t}Er(){var t;this.Sr(),(t=this.Fr.parentNode)==null||t.insertBefore(this.wr,this.Fr.nextSibling)}Ur(){const t=[];return this.Tr&&this.Fr instanceof HTMLElement&&(t.push(this.Fr),this.Fr.parentElement&&t.push(this.Fr.parentElement)),this.wr.parentElement&&t.push(this.wr.parentElement),t.push(this.wr),t.push(document.body),t.push(document.documentElement),t}kr(){const t=this.Ur();for(const i of t){if(!i)continue;const r=Fe(window.getComputedStyle(i).backgroundColor);if(r)return r}return[255,255,255,255]}Sr(){if(!this.Fr)return;const t=this.Fr.getBoundingClientRect();let i=this.Fr.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.wr.style.top=t.top-r.top+"px",this.wr.style.left=t.left-r.left+"px"}else this.wr.style.top=t.top+window.scrollY+"px",this.wr.style.left=t.left+window.scrollX+"px"}zr(t,i){if(this.Tr){const r=this.Fr.getBoundingClientRect();this.wr.width=Math.round(r.width),this.wr.height=Math.round(r.height),this.Sr()}else this.wr.width=t??this.wr.width,this.wr.height=i??this.wr.height}Lr(){const t=this.wr.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!0,stencil:!1,powerPreference:"high-performance"});if(!t)throw new R("`textmode.js` requires WebGL2 support.");return t}ft(){const t=this.wr.getContext("webgl")||this.wr.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i==null||i.loseContext()}this.$r&&this.wr.parentNode&&this.wr.parentNode.removeChild(this.wr)}get canvas(){return this.wr}get targetCanvas(){return this.Fr}get width(){return this.wr.width}get height(){return this.wr.height}}function nt(o){return z(parseInt(o,16),0,255)}class B{constructor(t,i,r,n){l(this,"Or");l(this,"Dr");l(this,"r");l(this,"g");l(this,"b");l(this,"a");this.r=z(t,0,255),this.g=z(i,0,255),this.b=z(r,0,255),this.a=z(n,0,255),this.Or=[this.r,this.g,this.b,this.a],this.Dr=[this.r/255,this.g/255,this.b/255,this.a/255]}static Hr(t,i,r,n){if(B.Ir(t))return t;if(Array.isArray(t)){if(t.length<3)throw Error("Component tuples must include at least RGB values.");const[h,a,c]=t,u=t.length===4?t[3]:255;return B.Br(h,a,c,u)}if(typeof t=="string"){const h=t.trim();if(h.length===0)throw Error("Color strings cannot be empty.");return B.Gr(h)}if(typeof t=="number")return typeof i=="number"&&typeof r=="number"?B.Br(t,i,r,n??255):B.Nr(t);throw Error("Unsupported color input passed to TextmodeColor.$from.")}static Br(t,i,r,n=255){return new B(t,i,r,n)}static Nr(t,i=255){return new B(t,t,t,i)}static Gr(t){return new B(...function(i){const r=i.replace(/^#|0x/gi,""),n=(h=r).length===3||h.length===4?h.split("").map(a=>a+a).join(""):h;var h;if(n.length!==6&&n.length!==8)throw Error("Invalid hex color: "+i);return[nt(n.slice(0,2)),nt(n.slice(2,4)),nt(n.slice(4,6)),n.length===8?nt(n.slice(6,8)):255]}(t))}get rgb(){return[this.r,this.g,this.b]}get rgba(){return[...this.Or]}get normalized(){return[...this.Dr]}withAlpha(t){return new B(this.r,this.g,this.b,t)}static Ir(t){return t instanceof B}}const yt=new Map;function Pt(o){yt.set(o.id,o)}function Lt(o){return yt.get(o)}class Nt{constructor(t,i,r,n,h,a,c,u){l(this,"A");l(this,"K");l(this,"Xr");l(this,"Yr");l(this,"Kr");l(this,"H");l(this,"I");l(this,"W",null);l(this,"ji");l(this,"Wr","brightness");l(this,"Zr",null);l(this,"Tt",0);l(this,"Dt",0);l(this,"Ht",0);l(this,"$t",0);l(this,"jr","sampled");l(this,"Vr","fixed");l(this,"Bt",[1,1,1,1]);l(this,"Gt",[0,0,0,1]);l(this,"qr",[0,0,0,1]);l(this,"Qr",[[.1,0,0]]);l(this,"Jr",null);l(this,"tn",new Set);l(this,"sn",[[0,0,0,0]]);l(this,"en",0);this.A=t,this.K=i,this.Xr=r,this.ji=n,this.Yr=h,this.Kr=a,this.H=c,this.I=u}conversionMode(t){return this.Wr=t,this.Zr=null,this.W=null,this}ft(){this.A.deleteTexture(this.Xr);for(const t of this.tn)t();this.tn.clear()}rn(t){this.tn.add(t)}invert(t=!0){return this.Tt=t?1:0,this.W=null,this}flipX(t=!0){return this.Dt=t?1:0,this.W=null,this}flipY(t=!0){return this.Ht=t?1:0,this.W=null,this}charRotation(t){return this.$t=bt(t),this.W=null,this}charColorMode(t){return this.jr=t,this.W=null,this}cellColorMode(t){return this.Vr=t,this.W=null,this}charColor(t,i,r,n){return this.nn(this.Bt,t,i,r,n),this.W=null,this}cellColor(t,i,r,n){return this.nn(this.Gt,t,i,r,n),this.W=null,this}background(t,i,r,n){return this.nn(this.qr,t,i,r,n),this.W=null,this}colorFilter(t){if(!t||t.length===0)return this.en=0,this.sn=[[0,0,0,0]],this.W=null,this;const i=[];for(const r of t){if(i.length>=64)break;let n=B.Hr(r);i.push(n.normalized)}return this.sn=i,this.en=i.length,this.W=null,this}characters(t){return this.Jr=t,this.hn(t),this.W=null,this}an(t){this.ji=t,this.Jr&&this.hn(this.Jr),this.W=null}get texture(){return this.Xr}get width(){return this.H}get height(){return this.I}get originalWidth(){return this.Yr}get originalHeight(){return this.Kr}ht(){return this.W||this.ct(),this.W}cn(){}ct(){this.cn();const t=this.ln(),i=this.un(),r=t.createShader(i),n=t.createUniforms(i);this.W=this.K.materialManager.De(r,n)}nn(t,i,r,n,h){const a=B.Hr(i,r,n,h);et(t,a.r,a.g,a.b,a.a)}hn(t){const i=this.ji.vr(t).filter(r=>Array.isArray(r)).slice(0,255);this.Qr=i.length>0?i:this.Qr}createBaseConversionUniforms(){const t=this.en>0;return{u_image:this.fn(),u_invert:!!this.Tt,u_flipX:!!this.Dt,u_flipY:!!this.Ht,u_charRotation:this.$t,u_charColorFixed:this.jr==="fixed",u_charColor:this.Bt,u_cellColorFixed:this.Vr==="fixed",u_cellColor:this.Gt,u_backgroundColor:this.qr,u_charCount:this.Qr.length,u_charList:this.Qr,u_colorFilterEnabled:t,u_colorFilterSize:t?this.en:0,u_colorFilterPalette:this.sn}}ln(){if(this.Zr&&this.Zr.id===this.Wr)return this.Zr;const t=Lt(this.Wr);if(!t)throw Error(`[textmode.js] Conversion mode "${this.Wr}" is not registered. If this mode is provided by an add-on, make sure its plugin is installed before loading sources.`);return this.Zr=t,t}un(){return{renderer:this.K,gl:this.A,font:this.ji,source:this,gridWidth:this.H,gridHeight:this.I}}}class k extends Nt{constructor(t,i,r,n,h,a,c,u){const f=Math.min(c/h,u/a);super(t,i,r,n,h,a,Math.max(1,Math.floor(h*f)),Math.max(1,Math.floor(a*f)))}static dn(t,i,r,n,h){const a=t.context,c=a.createTexture();a.bindTexture(a.TEXTURE_2D,c),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,1),$(a,a.NEAREST,a.NEAREST,a.CLAMP_TO_EDGE,a.CLAMP_TO_EDGE),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,r),a.bindTexture(a.TEXTURE_2D,null);const u=r.naturalWidth??r.width??r.videoWidth??0,f=r.naturalHeight??r.height??r.videoHeight??0;return new k(a,t,c,i,u,f,n,h)}fn(){return this.Xr}}class Dt{constructor(t=60){l(this,"pn");l(this,"gn",null);l(this,"vn",0);l(this,"mn",!0);l(this,"_n",0);l(this,"An",0);l(this,"yn",[]);l(this,"wn",10);l(this,"bn",0);this.pn=1e3/t}Cn(t){if(!this.mn)return;this.vn=performance.now();const i=r=>{if(!this.mn)return void(this.gn=null);const n=r-this.vn;n>=this.pn&&(t(),this.vn=r-n%this.pn),this.mn&&(this.gn=requestAnimationFrame(i))};this.gn=requestAnimationFrame(i)}Mn(){this.gn&&(cancelAnimationFrame(this.gn),this.gn=null)}xn(){this.mn&&(this.mn=!1,this.Mn())}Fn(t){this.mn||(this.mn=!0,this.Cn(t))}Tn(t,i){if(t===void 0)return this._n;this.pn=1e3/t,this.mn&&i&&(this.Mn(),this.Cn(i))}$n(){const t=performance.now();if(this.An>0){const i=t-this.An;this.yn.push(i),this.yn.length>this.wn&&this.yn.shift();const r=this.yn.reduce((n,h)=>n+h,0)/this.yn.length;this._n=1e3/r}this.An=t}get Pn(){return this.mn}get En(){return this._n}get Rn(){return this.bn}set Rn(t){this.bn=t}Sn(){this.bn++}}class Ot{constructor(t){l(this,"wr");l(this,"Un");l(this,"kn",{x:-1,y:-1});l(this,"zn",{x:-1,y:-1});l(this,"Ln",null);l(this,"On",0);l(this,"Dn");l(this,"Hn");l(this,"In");l(this,"Bn");l(this,"Gn");l(this,"Nn");l(this,"Xn",!1);l(this,"Yn");l(this,"Kn");l(this,"Wn");l(this,"Zn");l(this,"jn");this.wr=t}Vn(t){const i=performance.now()+Math.max(0,t);i>this.On&&(this.On=i)}qn(){return performance.now()<this.On}Qn(t){const i=this.wr.canvas;i.style.cursor=t==null||t===""?"":t}cr(t){this.Un=t,this.Jn()}so(){if(this.Xn)return;const t=this.wr.canvas;this.Dn=i=>{this.eo(i),this.io(i)},this.Hn=()=>{this.zn={...this.kn},this.kn.x=-1,this.kn.y=-1,this.Ln=null},this.In=i=>{this.eo(i),this.ro(i)},this.Bn=i=>{this.eo(i),this.no(i)},this.Gn=i=>{this.eo(i),this.oo(i)},this.Nn=i=>{this.eo(i),this.ho(i)},t.addEventListener("mousemove",this.Dn,{passive:!0}),t.addEventListener("mouseleave",this.Hn,{passive:!0}),t.addEventListener("mousedown",this.In,{passive:!0}),t.addEventListener("mouseup",this.Bn,{passive:!0}),t.addEventListener("click",this.Gn,{passive:!0}),t.addEventListener("wheel",this.Nn,{passive:!1}),this.Xn=!0}ao(){if(!this.Xn)return;const t=this.wr.canvas;t.removeEventListener("mousemove",this.Dn),t.removeEventListener("mouseleave",this.Hn),t.removeEventListener("mousedown",this.In),t.removeEventListener("mouseup",this.Bn),t.removeEventListener("click",this.Gn),t.removeEventListener("wheel",this.Nn),this.Xn=!1}Jn(){if(this.Xn)try{if(this.Ln){const t=new MouseEvent("mousemove",{clientX:this.Ln.x,clientY:this.Ln.y,bubbles:!1,cancelable:!1});this.eo(t)}else this.kn.x!==-1&&this.kn.y!==-1&&(this.kn.x>=this.Un.cols||this.kn.y>=this.Un.rows)&&(this.kn.x=-1,this.kn.y=-1)}catch{this.kn.x=-1,this.kn.y=-1}}co(t){this.Yn=t}lo(t){this.Kn=t}uo(t){this.Wn=t}fo(t){this.Zn=t}do(t){this.jn=t}po(){return{x:this.kn.x,y:this.kn.y}}io(t){if(this.Zn&&!this.qn()){const i={position:{...this.kn},previousPosition:{...this.zn},originalEvent:t};this.Zn(i)}}ro(t){if(this.Kn&&!this.qn()){const i={position:{...this.kn},previousPosition:{...this.zn},button:t.button,originalEvent:t};this.Kn(i)}}no(t){if(this.Wn&&!this.qn()){const i={position:{...this.kn},previousPosition:{...this.zn},button:t.button,originalEvent:t};this.Wn(i)}}oo(t){if(this.Yn&&!this.qn()){const i={position:{...this.kn},previousPosition:{...this.zn},button:t.button,originalEvent:t};this.Yn(i)}}ho(t){if(this.jn&&!this.qn()){const i={position:{...this.kn},previousPosition:{...this.zn},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.jn(i)}}eo(t){const i=this.wr.canvas;this.zn={...this.kn},this.Ln={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,h=t.clientY-r.top,a=i.width/r.width,c=h*(i.height/r.height),u=n*a-this.Un.offsetX,f=c-this.Un.offsetY,d=Math.floor(u/this.Un.cellWidth),g=Math.floor(f/this.Un.cellHeight);d>=0&&d<this.Un.cols&&g>=0&&g<this.Un.rows?(this.kn.x=d,this.kn.y=g):(this.kn.x=-1,this.kn.y=-1)}}const Ce=Object.freeze(Object.defineProperty({__proto__:null,MouseManager:Ot},Symbol.toStringTag,{value:"Module"}));class _t{constructor(){l(this,"vo",new Map);l(this,"mo",null);l(this,"_o",null);l(this,"Ao");l(this,"yo");l(this,"Xn",!1);l(this,"wo");l(this,"bo");l(this,"Co",{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"})}so(){this.Xn||(this.Ao=t=>{this.Mo(t)},this.yo=t=>{this.xo(t)},window.addEventListener("keydown",this.Ao,{passive:!1}),window.addEventListener("keyup",this.yo,{passive:!1}),this.Xn=!0)}ao(){this.Xn&&(window.removeEventListener("keydown",this.Ao),window.removeEventListener("keyup",this.yo),this.Xn=!1,this.vo.clear(),this.mo=null,this._o=null)}lo(t){this.wo=t}uo(t){this.bo=t}Fo(t){const i=this.To(t),r=this.vo.get(t)||this.vo.get(i);return(r==null?void 0:r.isPressed)||!1}$o(){return this.mo}Po(){return this._o}Eo(){const t=[];for(const[i,r]of this.vo)r.isPressed&&t.push(i);return t}Ro(){return{ctrl:this.Fo("Control"),shift:this.Fo("Shift"),alt:this.Fo("Alt"),meta:this.Fo("Meta")}}So(){this.vo.clear(),this.mo=null,this._o=null}Mo(t){const i=t.key,r=Date.now();this.vo.has(i)||this.vo.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.vo.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.mo=i,this.wo)){const h={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.wo(h)}}xo(t){const i=t.key,r=Date.now();this.vo.has(i)||this.vo.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.vo.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this._o=i,this.bo){const h={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.bo(h)}}To(t){return this.Co[t]||t.toLowerCase()}}const Ue=Object.freeze(Object.defineProperty({__proto__:null,KeyboardManager:_t},Symbol.toStringTag,{value:"Module"}));class Xt{constructor(t,i){l(this,"wr");l(this,"Uo");l(this,"Un");l(this,"ko",new Map);l(this,"zo",new Map);l(this,"Lo",new Map);l(this,"Oo",null);l(this,"Do");l(this,"Ho");l(this,"Io");l(this,"Bo");l(this,"Go");l(this,"No");l(this,"Xn",!1);l(this,"Xo");l(this,"Yo");l(this,"Ko");l(this,"Wo");l(this,"Zo");l(this,"jo");l(this,"Vo");l(this,"qo");l(this,"Qo");l(this,"Jo");l(this,"th",320);l(this,"sh",350);l(this,"eh",10);l(this,"ih",550);l(this,"rh",14);l(this,"nh",48);l(this,"oh",650);l(this,"hh",.02);l(this,"ah",2);l(this,"uh",600);l(this,"fh",0);l(this,"dh",null);this.wr=t,this.Uo=i;const r=this.wr.canvas;this.Do=r.style.touchAction,this.Ho=r.style.userSelect,r.style.touchAction||(r.style.touchAction="none"),r.style.userSelect||(r.style.userSelect="none")}cr(t){this.Un=t,this.Jn()}so(){if(this.Xn)return;const t=this.wr.canvas;this.Io=i=>{this.ph(i)},this.Bo=i=>{this.gh(i)},this.Go=i=>{this.mh(i)},this.No=i=>{this._h(i)},t.addEventListener("touchstart",this.Io,{passive:!1}),t.addEventListener("touchmove",this.Bo,{passive:!1}),t.addEventListener("touchend",this.Go,{passive:!1}),t.addEventListener("touchcancel",this.No,{passive:!1}),this.Xn=!0}ao(){if(!this.Xn)return;const t=this.wr.canvas;t.removeEventListener("touchstart",this.Io),t.removeEventListener("touchmove",this.Bo),t.removeEventListener("touchend",this.Go),t.removeEventListener("touchcancel",this.No),this.Xn=!1,this.Oo=null,this.ko.clear(),this.zo.clear(),this.Lo.forEach(i=>{i.longPressTimer!==null&&window.clearTimeout(i.longPressTimer)}),this.Lo.clear(),this.dh=null,this.fh=0,t.style.touchAction=this.Do,t.style.userSelect=this.Ho}Jn(){if(!this.Un||this.ko.size===0)return;const t=new Map;for(const i of this.ko.values()){const r=this.Ah(i.clientX,i.clientY,i.id,i);t.set(i.id,r)}this.ko=t}yh(){return Array.from(this.ko.values()).map(t=>({...t}))}wh(t){this.Xo=t}fo(t){this.Yo=t}bh(t){this.Ko=t}Ch(t){this.Wo=t}Mh(t){this.Zo=t}xh(t){this.jo=t}Fh(t){this.Vo=t}Th(t){this.qo=t}$h(t){this.Qo=t}Ph(t){this.Jo=t}ph(t){var n;if(!this.Un)return;t.preventDefault(),(n=this.Uo)==null||n.Vn(this.uh);const i=performance.now(),r=this.Eh(t.changedTouches);for(const h of r){const a=this.ko.get(h.id);a&&this.zo.set(h.id,this.Rh(a)),this.ko.set(h.id,h);const c={id:h.id,startPosition:h,lastPosition:h,startTime:i,lastTime:i,longPressTimer:null,longPressFired:!1};this.Vo&&(c.longPressTimer=window.setTimeout(()=>{const u=this.ko.get(h.id);u&&(c.longPressFired=!0,this.Vo({touch:this.Rh(u),duration:performance.now()-c.startTime,originalEvent:t}))},this.ih)),this.Lo.set(h.id,c),this.Xo&&this.Xo(this.Sh(h,t,void 0,i))}this.ko.size===2&&this.kh()}gh(t){var n;if(!this.Un)return;t.preventDefault(),(n=this.Uo)==null||n.Vn(this.uh);const i=performance.now(),r=this.Eh(t.changedTouches);for(const h of r){const a=this.ko.get(h.id),c=a?this.Rh(a):void 0;c&&this.zo.set(h.id,c),this.ko.set(h.id,h);const u=this.Lo.get(h.id);u&&(u.lastPosition=h,u.lastTime=i,c)&&W(c.clientX,c.clientY,h.clientX,h.clientY)>this.rh&&u.longPressTimer!==null&&(window.clearTimeout(u.longPressTimer),u.longPressTimer=null),this.Yo&&this.Yo(this.Sh(h,t,c,i))}this.ko.size===2?this.zh(t):this.Oo=null}mh(t){if(!this.Un)return;t.preventDefault();const i=performance.now(),r=this.Eh(t.changedTouches);for(const n of r){const h=this.ko.get(n.id),a=h?this.Rh(h):void 0,c=this.Lo.get(n.id);c&&c.longPressTimer!==null&&(window.clearTimeout(c.longPressTimer),c.longPressTimer=null),this.Ko&&this.Ko(this.Sh(n,t,a,i)),c&&this.Lh(c,t),this.Lo.delete(n.id),this.zo.delete(n.id),this.ko.delete(n.id)}this.ko.size<2&&(this.Oo=null)}_h(t){if(!this.Un)return;t.preventDefault();const i=performance.now(),r=this.Eh(t.changedTouches);for(const n of r){const h=this.ko.get(n.id),a=h?this.Rh(h):void 0,c=this.Lo.get(n.id);c&&c.longPressTimer!==null&&(window.clearTimeout(c.longPressTimer),c.longPressTimer=null),this.Wo&&this.Wo(this.Sh(n,t,a,i)),this.Lo.delete(n.id),this.zo.delete(n.id),this.ko.delete(n.id)}this.ko.size<2&&(this.Oo=null)}Eh(t){const i=[];for(let r=0;r<t.length;r+=1){const n=t.item(r);n&&i.push(this.Oh(n))}return i}Oh(t){return this.Ah(t.clientX,t.clientY,t.identifier,{id:t.identifier,x:-1,y:-1,clientX:t.clientX,clientY:t.clientY,pressure:t.force,radiusX:t.radiusX,radiusY:t.radiusY,rotationAngle:t.rotationAngle})}Ah(t,i,r,n){const h=this.wr.canvas,a=h.getBoundingClientRect(),c=t-a.left,u=i-a.top,f=h.width/a.width,d=u*(h.height/a.height),g=c*f-this.Un.offsetX,p=d-this.Un.offsetY,m=Math.floor(g/this.Un.cellWidth),v=Math.floor(p/this.Un.cellHeight),A=m>=0&&m<this.Un.cols&&v>=0&&v<this.Un.rows;return{id:r,x:A?m:-1,y:A?v:-1,clientX:t,clientY:i,pressure:n.pressure,radiusX:n.radiusX,radiusY:n.radiusY,rotationAngle:n.rotationAngle}}Sh(t,i,r,n){const h=this.Lo.get(t.id),a=Array.from(this.zo.values()).map(f=>this.Rh(f)),c=Array.from(this.ko.values()).map(f=>this.Rh(f)),u=this.Eh(i.changedTouches);return{touch:this.Rh(t),previousTouch:r?this.Rh(r):void 0,touches:c,previousTouches:a,changedTouches:u,deltaTime:h?n-h.lastTime:0,originalEvent:i}}kh(){if(this.ko.size!==2)return void(this.Oo=null);const t=Array.from(this.ko.values()),[i,r]=t,n=W(i.x,i.y,r.x,r.y),h=Tt(i.clientX,i.clientY,r.clientX,r.clientY);this.Oo={ids:[i.id,r.id],initialDistance:Math.max(n,1e-4),initialAngle:h,lastScale:1,lastRotation:0}}zh(t){if(this.Oo||this.kh(),!this.Oo)return;const[i,r]=this.Oo.ids,n=this.ko.get(i),h=this.ko.get(r);if(!n||!h)return;const a=W(n.x,n.y,h.x,h.y)/this.Oo.initialDistance,c=a-this.Oo.lastScale;this.Qo&&Math.abs(c)>this.hh&&(this.Qo({touches:[this.Rh(n),this.Rh(h)],scale:a,deltaScale:c,center:this.Dh(n,h),originalEvent:t}),this.Oo.lastScale=a);let u=Tt(n.clientX,n.clientY,h.clientX,h.clientY)-this.Oo.initialAngle;u=(u+180)%360-180;const f=u-this.Oo.lastRotation;this.Jo&&Math.abs(f)>this.ah&&(this.Jo({touches:[this.Rh(n),this.Rh(h)],rotation:u,deltaRotation:f,center:this.Dh(n,h),originalEvent:t}),this.Oo.lastRotation=u)}Dh(t,i){const r=(t.clientX+i.clientX)/2,n=(t.clientY+i.clientY)/2,h=this.Ah(r,n,-1,{id:-1,x:-1,y:-1,clientX:r,clientY:n});return{x:h.x,y:h.y}}Lh(t,i){const r=performance.now(),n=r-t.startTime,h=W(t.startPosition.clientX,t.startPosition.clientY,t.lastPosition.clientX,t.lastPosition.clientY);if(!t.longPressFired&&n<=this.th&&h<=this.eh)this.Hh(t.lastPosition,r)&&this.jo?this.jo({touch:this.Rh(t.lastPosition),taps:2,originalEvent:i}):this.Zo&&this.Zo({touch:this.Rh(t.lastPosition),taps:1,originalEvent:i});else if(!t.longPressFired&&n<=this.oh&&h>=this.nh){const a={x:t.lastPosition.clientX-t.startPosition.clientX,y:t.lastPosition.clientY-t.startPosition.clientY},c=Math.max(Math.hypot(a.x,a.y),1e-4),u={x:a.x/c,y:a.y/c},f={x:a.x/n,y:a.y/n};this.qo&&this.qo({touch:this.Rh(t.lastPosition),direction:u,distance:c,velocity:f,originalEvent:i})}this.fh=r,this.dh=this.Rh(t.lastPosition)}Hh(t,i){return!!this.dh&&!(i-this.fh>this.sh)&&W(t.clientX,t.clientY,this.dh.clientX,this.dh.clientY)<=this.eh}Rh(t){return{...t}}}const Me=Object.freeze(Object.defineProperty({__proto__:null,TouchManager:Xt},Symbol.toStringTag,{value:"Module"}));class Ie{constructor(t,i){l(this,"A");l(this,"Ih");l(this,"_n",null);l(this,"Bh",0);l(this,"Gh",!1);l(this,"Nh",[]);l(this,"Xh",-1);this.A=t,this.Ih=i}get isPreloaded(){return this.Gh}get totalFrames(){return this.Bh}get frameRate(){return this._n}get textures(){return this.Nh}dispose(){this.Yh(),this.Nh=[],this._n=null,this.Bh=0,this.Gh=!1,this.Xh=-1}async preload(t,i){var r;try{if(t<=0)throw Error("Video preload requires a frameRate greater than 0.");const n=this.Ih.duration;if(!isFinite(n)||n<=0)throw Error("Video duration is invalid, cannot preload frames.");const h=Math.max(1,Math.ceil(n*t));return this.Kh(t,h),await this.Wh(t,i)?(this.Zh("captureStream",i),"captureStream"):(await this.jh(t,i),this.Zh("seeking",i),"seeking")}catch(n){const h=n instanceof Error?n:Error(n+"");throw(r=i==null?void 0:i.onError)==null||r.call(i,h),this.dispose(),h}}Kh(t,i){this.Yh(),this._n=t,this.Bh=i,this.Nh=[],this.Gh=!1,this.Xh=-1}Zh(t,i){var r;if(this.Nh.length===0)throw Error(`Video preload via ${t} completed but produced 0 frames.`);this.Bh=this.Nh.length,this.Gh=!0,this.Xh=-1,this.Ih.pause(),this.Ih.currentTime=0,i!=null&&i.onProgress&&i.onProgress({percent:100,loadedFrames:this.Bh,totalFrames:this.Bh,strategy:t}),(r=i==null?void 0:i.onComplete)==null||r.call(i,{totalFrames:this.Bh,strategy:t})}Vh(t){const i=this.A,r=i.createTexture();return i.bindTexture(i.TEXTURE_2D,r),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,1),$(i,i.LINEAR,i.LINEAR,i.CLAMP_TO_EDGE,i.CLAMP_TO_EDGE),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.bindTexture(i.TEXTURE_2D,null),r}qh(t,i){if(!(i!=null&&i.onProgress)||this.Bh===0)return;const r=Math.min(99,Math.floor(this.Nh.length/this.Bh*100)),n=10*Math.floor(r/10);n>this.Xh&&(this.Xh=n,i.onProgress({percent:r,loadedFrames:this.Nh.length,totalFrames:this.Bh,strategy:t}))}async Wh(t,i){const r=globalThis,n=r==null?void 0:r.MediaStreamTrackProcessor,h=this.Ih.captureStream;if(typeof n!="function"||typeof h!="function")return!1;let a,c=null;try{const u=h.call(this.Ih);if(a=u.getVideoTracks()[0],!a)return u.getTracks().forEach(g=>g.stop()),!1;if(c=new n({track:a}).readable.getReader(),this.Ih.currentTime=0,this.Ih.muted=!0,await this.Ih.play().catch(()=>{}),this.Ih.paused)return!1;const f=1e6/t;let d=0;for(;this.Nh.length<this.Bh;){const g=await c.read();if(g.done)break;const p=g.value;if(p)try{const m=typeof p.timestamp=="number"?p.timestamp:d;(this.Nh.length===0||m>=d)&&(this.Nh.push(this.Vh(p)),d=m+f,this.qh("captureStream",i))}finally{p.close()}}return c.releaseLock(),a.stop(),c=null,a=void 0,this.Ih.pause(),this.Ih.currentTime=0,this.Nh.length!==0}catch{return this.Yh(),this.Nh=[],this.Xh=-1,!1}finally{if(c)try{await c.cancel()}catch{}a&&a.stop(),this.Ih.pause(),this.Ih.currentTime=0}}async jh(t,i){const r=1/t,n=this.Bh,h=this.Ih;h.pause();for(let a=0;a<n;a++){const c=Math.min(h.duration,a*r);await this.Qh(c),this.Nh.push(this.Vh(h)),this.qh("seeking",i)}h.currentTime=0}Qh(t){return new Promise((i,r)=>{const n=this.Ih,h=()=>{n.removeEventListener("seeked",a),n.removeEventListener("error",c)},a=()=>{h(),i()},c=()=>{h(),r(Error("Video seek failed while preloading frames."))};n.addEventListener("seeked",a,{once:!0}),n.addEventListener("error",c,{once:!0});const u=isFinite(n.duration)?n.duration:t,f=Math.min(Math.max(t,0),u);if(Math.abs(n.currentTime-f)<1e-4)return h(),void i();n.currentTime=f})}Yh(){for(const t of this.Nh)this.A.deleteTexture(t)}}class ht extends Nt{constructor(i,r,n,h,a,c,u,f,d){const g=c/u;let p,m;g>1?(p=f,m=Math.round(f/g)):(m=d,p=Math.round(d*g));super(i,r,n,h,c,u,p,m);l(this,"Ih");l(this,"Jh",0);l(this,"ta",null);this.Ih=a}ft(){var i;super.ft(),(i=this.ta)==null||i.dispose(),this.ta=null,this.Ih.pause(),this.Ih.src="",this.Ih.load()}sa(){var i;if(!((i=this.ta)!=null&&i.isPreloaded)&&this.Ih.readyState>=this.Ih.HAVE_CURRENT_DATA){const r=this.A;r.bindTexture(r.TEXTURE_2D,this.Xr),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.Ih),r.bindTexture(r.TEXTURE_2D,null)}}fn(){var r,n;const i=(r=this.ta)==null?void 0:r.textures;return i&&i.length>0&&((n=this.ta)!=null&&n.isPreloaded)?i[this.Jh%i.length]:this.Xr}ht(){return this.W=null,super.ht()}cn(){this.sa()}frame(i){var n,h;const r=((n=this.ta)==null?void 0:n.totalFrames)??0;return(h=this.ta)!=null&&h.isPreloaded&&i!==void 0&&r>0&&(this.Jh=(i%r+r)%r,this.W=null),this}static async dn(i,r,n,h,a,c){const u=i.context,f=c==null?void 0:c.frameRate;let d;d=document.createElement("video"),d.crossOrigin="anonymous",d.loop=!0,d.muted=!0,d.playsInline=!0,await new Promise((A,w)=>{d.addEventListener("loadedmetadata",()=>A(),{once:!0}),d.addEventListener("error",y=>{var E;const T=y.target;w(Error("Failed to load video: "+(((E=T.error)==null?void 0:E.message)||"Unknown error")))},{once:!0}),d.src=n});const g=u.createTexture();u.bindTexture(u.TEXTURE_2D,g),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,1),$(u,u.LINEAR,u.LINEAR,u.CLAMP_TO_EDGE,u.CLAMP_TO_EDGE),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,u.RGBA,u.UNSIGNED_BYTE,d),u.bindTexture(u.TEXTURE_2D,null);const p=d.videoWidth,m=d.videoHeight,v=new ht(u,i,g,r,d,p,m,h,a);return f&&f>0&&(v.ta=new Ie(u,d),await v.ta.preload(f,c),v.Jh=0),v}async play(){await this.Ih.play()}pause(){this.Ih.pause()}stop(){this.Ih.pause(),this.Ih.currentTime=0}speed(i){return this.Ih.playbackRate=i,this}loop(i=!0){return this.Ih.loop=i,this}time(i){return this.Ih.currentTime=i,this}volume(i){return this.Ih.volume=Math.max(0,Math.min(1,i)),this}get texture(){return this.Xr}get width(){return this.H}get height(){return this.I}get originalWidth(){return this.Yr}get originalHeight(){return this.Kr}get videoElement(){return this.Ih}get currentTime(){return this.Ih.currentTime}get duration(){return this.Ih.duration}get isPlaying(){return!this.Ih.paused&&!this.Ih.ended}get totalFrames(){var i;return((i=this.ta)==null?void 0:i.totalFrames)??0}}const Be=o=>class extends o{ea(t,i,r,n){if(B.Ir(t))return t;if(typeof t=="number"||typeof t=="string")return this.color(t,i,r,n);throw Error("Unsupported color input passed to color-capable method.")}rotate(t=0,i=0,r=0){this.K.state.Zt(t),this.K.state.jt(i),this.K.state.Vt(r)}rotateX(t){this.K.state.Zt(t)}rotateY(t){this.K.state.jt(t)}rotateZ(t){this.K.state.Vt(t)}translate(t=0,i=0,r=0){this.K.state.qt(t,i,r)}translateX(t){this.K.state.qt(t,0,0)}translateY(t){this.K.state.qt(0,t,0)}translateZ(t){this.K.state.qt(0,0,t)}push(){this.K.state.it()}pop(){this.K.state.rt()}color(t,i,r,n){return B.Hr(t,i,r,n)}rect(t=1,i=1){this.K.di(t,i)}point(){this.K.di(1,1)}line(t,i,r,n){this.K.pi(t,i,r,n)}lineWeight(t){this.K.state.Kt(t)}background(t,i,r,n=255){const h=this.ea(t,i,r,n);this.K.wi(h.r,h.g,h.b,h.a)}char(t){const i=Array.from(t);if(i.length===0)throw Error("char() requires at least one character.");this.K.state.ss(this.ji.gr(i[0]))}charColor(t,i,r,n){const h=this.ea(t,i,r,n);this.K.state.es(h.r,h.g,h.b,h.a)}cellColor(t,i,r,n){const h=this.ea(t,i,r,n);this.K.state.rs(h.r,h.g,h.b,h.a)}flipX(t){this.K.state.ns(t)}flipY(t){this.K.state.hs(t)}charRotation(t){this.K.state.ls(t)}invert(t){this.K.state.cs(t)}clear(){this.K.wi(0,0,0,0)}ellipse(t,i){this.K.gi(t/2,i/2)}triangle(t,i,r,n,h,a){this.K.mi(t,i,r,n,h,a)}bezierCurve(t,i,r,n,h,a,c,u){this.K._i(t,i,r,n,h,a,c,u)}arc(t,i,r,n){this.K.Ai(t/2,i/2,r,n)}shader(t){this.K.ai(t)}setUniform(t,i){this.K.O(t,i)}setUniforms(t){this.K.ci(t)}async createFilterShader(t){if(typeof t=="string"&&(t.startsWith("./")||t.startsWith("../")||t.endsWith(".frag")||t.endsWith(".glsl"))){const i=await fetch(t);if(!i.ok)throw Error(`Failed to load shader from ${t}: ${i.statusText}`);const r=await i.text();return this.K.li(r)}return this.K.li(t)}createFramebuffer(t){return this.K.yi(t.width??this.grid.cols,t.height??this.grid.rows,3)}image(t,i,r){this.K.ui(t,i,r)}ortho(){this.K.state.fs(!0)}async loadImage(t){if(typeof t!="string"){const h=k.dn(this.K,this.ji,t,this.Un.cols,this.Un.rows);return this.ia(h),h}const i=t,r=await new Promise((h,a)=>{const c=new Image;c.crossOrigin="anonymous",c.onload=()=>h(c),c.onerror=u=>a(u),c.src=i}),n=k.dn(this.K,this.ji,r,this.Un.cols,this.Un.rows);return this.ia(n),n}async loadVideo(t,i){const r=await ht.dn(this.K,this.ji,t,this.Un.cols,this.Un.rows,i);return this.ia(r),r}},Se=o=>class extends o{async loadFont(t){return this.ji.pr(t).then(()=>{const i=this.ji.maxGlyphDimensions;this.Un.Mr(i.width,i.height),this.ra.resize(this.Un.cols,this.Un.rows),this.K.bi(),this.Uo.Jn(),this.na.Jn();for(const r of this.oa)r.an(this.ji)})}fontSize(t){if(!lt.m(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.ji.fontSize===t)return;this.ji.dr(t);const i=this.ji.maxGlyphDimensions;this.Un.Mr(i.width,i.height),this.ra.resize(this.Un.cols,this.Un.rows),this.K.bi(),this.Uo.Jn(),this.na.Jn()}},Pe=o=>class extends o{get frameCount(){return this.ha.Rn}set frameCount(t){this.ha.Rn=t}frameRate(t){return t===void 0?this.ha.En:this.ha.Tn(t,()=>this.aa())}noLoop(){this.ha.xn()}loop(){this.ha.Fn(()=>this.aa())}redraw(t=1){if(lt.m(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.aa()}isLooping(){return this.ha.Pn}},Le=o=>class extends o{constructor(...t){super(...t)}mouseClicked(t){this.Uo.co(t)}mousePressed(t){this.Uo.lo(t)}mouseReleased(t){this.Uo.uo(t)}mouseMoved(t){this.Uo.fo(t)}mouseScrolled(t){this.Uo.do(t)}get mouse(){return this.Uo.po()}cursor(t){this.Uo.Qn(t)}},Ne=o=>class extends o{constructor(...t){super(...t)}touchStarted(t){this.na.wh(t)}touchMoved(t){this.na.fo(t)}touchEnded(t){this.na.bh(t)}touchCancelled(t){this.na.Ch(t)}tap(t){this.na.Mh(t)}doubleTap(t){this.na.xh(t)}longPress(t){this.na.Fh(t)}swipe(t){this.na.Th(t)}pinch(t){this.na.$h(t)}rotateGesture(t){this.na.Ph(t)}get touches(){return this.na.yh()}},De=o=>class extends o{constructor(...t){super(...t)}keyPressed(t){this.ca.lo(t)}keyReleased(t){this.ca.uo(t)}isKeyPressed(t){return this.ca.Fo(t)}get lastKeyPressed(){return this.ca.$o()}get lastKeyReleased(){return this.ca.Po()}get pressedKeys(){return this.ca.Eo()}get modifierState(){return this.ca.Ro()}};class Oe{constructor(t){l(this,"la");l(this,"ua",new Map);l(this,"fa",[]);l(this,"da",new Map);l(this,"pa",new Map);this.la=t}async ga(t){for(const i of t){if(this.ua.has(i.name))return void console.warn(`[textmode.js] Plugin "${i.name}" is already installed.`);const r=this.va(i.name);try{await i.install(this.la,r)}catch(n){throw this.ma(i.name),n}this.ua.set(i.name,i),this.fa.push(i.name)}}async _a(t){const i=this.ua.get(t);if(!i)return;const r=this.va(t);i.uninstall&&await i.uninstall(this.la,r),this.ua.delete(t),this.fa.splice(this.fa.indexOf(t),1),this.ma(t)}ya(){this.wa(this.da)}ba(){this.wa(this.pa)}async Ca(){const t=[...this.ua.keys()];for(const i of t)await this._a(i)}va(t){return{renderer:this.la.K,font:this.la.ji,grid:this.la.Un,canvas:this.la.wr,drawFramebuffer:this.la.ra,asciiFramebuffer:this.la.Ma,registerPreDrawHook:i=>this.xa(this.da,t,i),registerPostDrawHook:i=>this.xa(this.pa,t,i)}}xa(t,i,r){const n=t.get(i)??new Set;return n.add(r),t.set(i,n),()=>{const h=t.get(i);h&&(h.delete(r),h.size===0&&t.delete(i))}}ma(t){this.da.delete(t),this.pa.delete(t)}wa(t){for(const i of this.fa){const r=t.get(i);r&&r.forEach(n=>n())}}}const Gt=`#version 300 es
11
- in vec2 A0;in vec2 A1;out vec2 v_uv;void main(){v_uv=A1;gl_Position=vec4(A0,0.,1.);}`;class zt{constructor(){l(this,"Fa",new Map);l(this,"Ta",[]);l(this,"$a",0);l(this,"Pa",0);l(this,"Ea")}get Ra(){return this.$a}get Sa(){if(this.$a===0)return 0;let t=0;for(const i of this.Ta){const r=this.Fa.get(i);r&&(t+=Math.min(1,Math.max(0,r.progress))*r.weight)}return Math.min(1,t/this.$a)}ka(t){this.Ea=t}za(t,i=1){const r=`phase-${this.Ta.length+1}-${Date.now()}`,n={id:r,label:t,weight:Math.max(.001,i),progress:0,status:"running"};return this.Fa.set(r,n),this.Ta.push(r),this.$a+=n.weight,r}La(t,i){const r=this.Fa.get(t);if(!r)return;r.progress=Math.max(0,Math.min(1,i)),r.status=r.progress>=1?"complete":"running";const n=this.Sa;Math.abs(n-this.Pa)>.001&&(this.Pa=n,this.Ea&&this.Ea(n))}Oa(t){const i=this.Fa.get(t);i&&(i.progress=1,i.status="complete",this.La(t,1))}Da(t){const i=this.Fa.get(t);i&&(i.status="failed")}Ha(){return this.Ta.map(t=>{const i=this.Fa.get(t);return i?{id:i.id,label:i.label,weight:i.weight,progress:i.progress,status:i.status}:{id:t,label:t,weight:1,progress:0,status:"pending"}})}}class Kt{constructor(t="active"){l(this,"Ia");l(this,"Ba","");l(this,"Ga","");this.Ia=t}get Na(){return this.Ia}get Xa(){return this.Ia!=="disabled"}get Ya(){return this.Ia==="active"||this.Ia==="transitioning"||this.Ia==="error"}get Ka(){return this.Ba}get Wa(){return this.Ga}Za(){this.Ia!=="done"&&this.Ia!=="transitioning"||(this.Ia="active")}ja(){this.Ia!=="disabled"&&(this.Ia="done")}Va(){this.Ia!=="disabled"&&(this.Ia="transitioning")}qa(){this.Ia==="transitioning"&&(this.Ia="done")}Qa(t){this.Ia!=="disabled"&&(this.Ia="error",t instanceof Error?(this.Ba=t.message,this.Ga=t.stack||""):(this.Ba=t,this.Ga=""))}Ja(){this.Ia="disabled"}}class Yt{constructor(t,i){l(this,"tc",0);l(this,"sc",1);l(this,"ec");l(this,"rc");this.ec=t,this.rc=i}get nc(){return this.sc}get oc(){return this.sc<1}Cn(){this.ec!=="none"&&this.rc>0&&(this.tc=performance.now())}tt(){if(this.ec==="none"||this.rc===0)return this.sc=1,!1;const t=performance.now()-this.tc,i=Math.min(1,t/this.rc);return i>=1?(this.sc=0,!0):(this.sc=1-i,!1)}js(){this.sc=1,this.tc=0}}function wt(o,t){const i=o.tone??"auto";let r="dark";return i==="light"||i==="dark"?r=i:t&&(r=function(n){if(!n)return 0;const[h,a,c]=n.map(f=>f/255),u=f=>f<=.04045?f/12.92:Math.pow((f+.055)/1.055,2.4);return .2126*u(h)+.7152*u(a)+.0722*u(c)}(t)>.5?"light":"dark"),{mode:r,background:t,textColor:r==="light"?"#1A1A1A":"#F8F8F8",subtleColor:r==="light"?"#4A4A4A":"#C0C0C0"}}function kt(o){return o.mode==="light"?["#E91E63","#9C27B0","#FF6F00"]:["#8EF9F3","#F15BB5","#FF9B71"]}function Ht(o,t){return o.length?o.map(i=>t.color(i)):[t.color("#FFFFFF")]}const _e=({textmodifier:o,grid:t,progress:i,frameCount:r,message:n,palette:h,theme:a,phases:c,transitionOpacity:u,isError:f,errorMessage:d})=>{const g="|/-\\",p=Math.floor(r/6)%4,m=o.color(a.textColor),v=Math.floor(255*u),A=o.color(m.r,m.g,m.b,v);if(o.charColor(A),o.cellColor(0,0,0,0),f){const w=o.color(a.mode==="light"?"#D32F2F":"#FF6B6B",v);o.charColor(w),o.push(),o.translate(0,-2,0),o.char("X"),o.rect(1,1),o.pop();const y="SETUP ERROR",T=-Math.floor(y.length/2);o.push(),o.translate(T,0,0);for(const E of y)o.char(E),o.rect(1,1),o.translateX(1);if(o.pop(),d){const E=o.color(a.subtleColor),U=o.color(E.r,E.g,E.b,v);o.charColor(U);const b=Math.floor(.8*t.cols),I=d.split(" "),L=[];let M="";for(const P of I)(M+" "+P).length<=b?M=M?M+" "+P:P:(M&&L.push(M),M=P);M&&L.push(M);const D=L.slice(0,3);L.length>3&&(D[2]=D[2].substring(0,b-3)+"..."),D.forEach((P,at)=>{const Ve=-Math.floor(P.length/2);o.push(),o.translate(Ve,3+at,0);for(const Ze of P)o.char(Ze),o.rect(1,1),o.translateX(1);o.pop()})}return}if(o.push(),o.translate(0,0,0),o.char(g[p]),o.rect(1,1),o.pop(),i>0||c.some(w=>w.status!=="pending")){const w=Math.max(6,Math.floor(.6*t.cols)),y=-Math.floor(w/2),T=Math.floor(w*i),E=h.length?h:[o.color("#FFFFFF")];o.push(),o.translate(y,3,0);for(let U=0;U<w;U++){const b=U<T?"*":".",I=E[U%E.length],L=o.color(I.r,I.g,I.b,v);o.charColor(L),o.char(b),o.rect(1,1),o.translateX(1)}o.pop()}if(n){const w=o.color(a.subtleColor),y=o.color(w.r,w.g,w.b,v);o.charColor(y);const T=-Math.floor(n.length/2);o.push(),o.translate(T,5,0);for(const E of n)o.char(E),o.rect(1,1),o.translateX(1);o.pop()}},Xe={message:"LOADING...",tone:"auto",transition:"fade",transitionDuration:500};class Ge{constructor(t,i,r){this.hc=t,this.id=i,this.label=r}report(t){this.hc.La(this.id,t)}complete(){this.hc.Oa(this.id)}fail(t){this.hc.Da(this.id)}async track(t){try{const i=typeof t=="function"?await t():await t;return this.complete(),i}catch(i){throw this.fail(),i}}}class jt{constructor(t,i,r){l(this,"la");l(this,"l");l(this,"ac");l(this,"hc");l(this,"cc");l(this,"lc");l(this,"uc");l(this,"fc");l(this,"dc");l(this,"gc");l(this,"K");l(this,"vc",[]);l(this,"mc");l(this,"_c",performance.now());l(this,"yc",0);l(this,"wc",!1);l(this,"bc",!1);l(this,"Fc");this.la=t,this.l={...Xe,...i??{}},this.ac=new Kt("active"),this.hc=new zt,this.cc=new Yt(this.l.transition,this.l.transitionDuration),this.lc=new Dt(60),this.mc=wt(this.l,r);const n=kt(this.mc);this.vc=Ht(n,this.la),this.K=this.Cc(),this.hc.ka(h=>{h>=.999&&this.ja()})}async cr(t){if(this.bc)return;const i=this.la.K,r=this.la.wr;this.uc=new pt(i,16),await this.uc.cr(t);const n=this.uc.maxGlyphDimensions;this.fc=new mt(r.canvas,n.width,n.height),this.dc=i.yi(this.fc.cols,this.fc.rows,3),this.gc=i.yi(this.fc.width,this.fc.height,1),this.bc=!0}get Ya(){return this.ac.Ya&&this.wc}Cn(){this.wc||(this.wc=!0,this._c=performance.now(),this.yc=0,this.lc.Cn(()=>this.Mc()))}Mn(){this.wc&&(this.wc=!1,this.lc.Mn())}zr(){this.bc&&(this.fc.js(),this.dc.resize(this.fc.cols,this.fc.rows),this.gc.resize(this.fc.width,this.fc.height))}ft(){this.Mn(),this.bc&&(this.uc.ft(),this.dc.ft(),this.gc.ft(),this.bc=!1)}get progress(){return this.hc.Sa}message(t){return typeof t=="string"&&(this.l.message=t),this.l.message}addPhase(t,i=1){this.ac.Za();const r=this.hc.za(t,i);return new Ge(this.hc,r,t)}ja(){this.l.transition!=="none"&&this.l.transitionDuration>0?(this.ac.Va(),this.cc.Cn()):(this.ac.ja(),this.Mn(),this.xc())}xc(){this.Fc&&this.Fc()}Tc(t){this.Fc=t}error(t){this.ac.Qa(t)}Mc(){if(this.ac.Ya){if(this.yc++,this.ac.Na==="transitioning"&&this.cc.tt())return this.ac.qa(),this.xc(),void this.Mn();this.$c()}}$c(){if(!this.bc)return;const t=this.dc,i=this.uc,r=this.fc,n=this.gc,h=this.la.K,a=this.la.wr,c=this.la.Pc,u=this.la.Ec;h.state.Wt(),t.begin(),this.la.clear(),this.la.push();try{const f={textmodifier:this.la,grid:r,progress:this.progress,elapsedMs:performance.now()-this._c,frameCount:this.yc,message:this.l.message,palette:this.vc,theme:this.mc,phases:this.hc.Ha(),transitionOpacity:this.cc.nc,isError:this.ac.Na==="error",errorMessage:this.ac.Ka||void 0,errorDetails:this.ac.Wa||void 0};this.K(f)}finally{this.la.pop()}t.end(),n.begin(),h.oi(c),c.L({u_characterTexture:i.fontFramebuffer,u_charsetDimensions:[i.textureColumns,i.textureRows],U0:t.textures[0],U1:t.textures[1],U2:t.textures[2],U3:[r.cols,r.rows],U4:[n.width,n.height],U5:h.state.canvasBackgroundColor}),h.fi(0,0,a.width,a.height),n.end(),h.ge(...h.state.canvasBackgroundColor),h.oi(u),u.L({U6:n.textures[0],U7:[n.width,n.height],U8:[r.offsetX,r.offsetY],U9:[r.width,r.height]}),h.fi(r.offsetX,r.offsetY,r.width,r.height)}Rc(t){this.mc=wt(this.l,t)}Cc(){const t=this.l.renderer||_e;return i=>{t(i),this.Sc(i)}}Sc(t){const{textmodifier:i,grid:r,frameCount:n,theme:h,transitionOpacity:a}=t,c=[116,101,120,116,109,111,100,101,46,106,115].map(g=>String.fromCharCode(g)).join(""),u=(r.rows+1>>1)-2,f=2-(r.cols+1>>1),d=h.mode==="light"?[[233,30,99],[156,39,176],[255,111,0]]:[[142,249,243],[241,91,181],[255,155,113]];i.push(),i.translate(f,u,0);for(let g=0;g<c.length;g++){const p=c[g],m=Math.floor(.1*n+.5*g)%d.length,[v,A,w]=d[m],y=Math.floor(255*a),T=i.color(v,A,w,y);i.charColor(T),i.char(p),i.point(),i.translateX(1)}i.pop()}}class Wt extends function(i,...r){return r.reduce((n,h)=>h(n),i)}(class{},Be,Se,Pe,Le,Ne,De){constructor(i={}){super();l(this,"K");l(this,"ji");l(this,"wr");l(this,"Un");l(this,"ha");l(this,"Uo");l(this,"na");l(this,"ca");l(this,"kc");l(this,"ra");l(this,"Pc");l(this,"Ma");l(this,"Ec");l(this,"zc");l(this,"Lc",!1);l(this,"Oc",!1);l(this,"Dc",!1);l(this,"Hc",!1);l(this,"Ic",()=>{});l(this,"Bc",()=>{});l(this,"Gc",()=>{});l(this,"Nc");l(this,"Xc");l(this,"Tr",!1);l(this,"Yc");l(this,"oa",new Set);this.zc=new Oe(this),this.Tr=i.overlay??!1,this.wr=new St(i),this.K=new ue(this.wr.Lr()),this.ji=new pt(this.K,i.fontSize??16),this.ha=new Dt(i.frameRate??60),this.kc=new jt(this,i.loadingScreen,this.wr.kr()),this.kc.Tc(()=>{this.ha.Rn=0,this.Hc=!0}),this.Uo=new Ot(this.wr),this.na=new Xt(this.wr,this.Uo),this.ca=new _t,this.Pc=this.K.hi(Gt,`#version 300 es
12
- precision highp float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D U1;uniform sampler2D U2;uniform sampler2D U0;uniform vec2 U3;uniform vec2 U4;uniform vec4 U5;in vec2 v_uv;out vec4 fragColor;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/U4;vec2 F=E*U3;vec2 G=floor(F);vec2 H=(G+0.5)/U3;vec4 I=texture(U1,H);vec4 J=texture(U2,H);vec4 K=texture(U0,H);int L=int(K.b*255.+0.5);bool M=(L&1)!=0;bool N=(L&2)!=0;bool O=(L&4)!=0;int P=int(K.r*255.+0.5)+int(K.g*255.+0.5)*256;int Q=int(u_charsetDimensions.x);int R=P/Q;int S=P-(R*Q);float T=(u_charsetDimensions.y-1.)-float(R);vec2 U=1./u_charsetDimensions;vec2 V=vec2(float(S),T)*U;vec2 W=V+U;float X=-K.a*360.*0.017453292;vec2 Y=fract(F)-0.5f;vec2 Z=vec2(N?-1.:1.,O?-1.:1.);Y*=Z;Y=A(X)*Y+0.5;vec2 a=V+clamp(Y,0.,1.)*U;const float b=0.0001;if(any(lessThan(a,V-b))||any(greaterThan(a,W+b))){fragColor=M?I:J;return;}vec4 c=texture(u_characterTexture,a);if(M)c.rgb=mix(c.rgb,1.-c.rgb,float(M));vec4 d=mix(U5,J,J.a);fragColor=mix(d,I,c);}`),this.kc.Cn(),this.Kc(i)}async Kc(i){await Promise.all([this.ji.cr(i.fontSource),this.kc.cr(i.fontSource)]);const r=this.ji.maxGlyphDimensions;this.Un=new mt(this.wr.canvas,r.width,r.height),this.Uo.cr(this.Un),this.na.cr(this.Un),this.ra=this.K.yi(this.Un.cols,this.Un.rows,3),this.Ma=this.K.yi(this.Un.width,this.Un.height,1),this.Tr&&(this.Yc=k.dn(this.K,this.ji,this.wr.targetCanvas,this.Un.cols,this.Un.rows),this.ia(this.Yc)),this.Ec=this.K.hi(Gt,`#version 300 es
13
- precision highp float;uniform sampler2D U6;uniform vec2 U7;uniform vec2 U8;uniform vec2 U9;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=gl_FragCoord.xy-U8;vec2 B=A*(U7/U9);vec2 C=(floor(B)+0.5)/U7;fragColor=texture(U6,C);}`),this.Wc(),this.ha.Cn(()=>this.aa()),await this.zc.ga(i.plugins??[]);try{await this.Ic(),this.kc.ja()}catch(n){console.error("Error during setup:",n),this.kc.error(n)}}Wc(){this.Nc=()=>{this.Tr&&this.resizeCanvas(this.wr.targetCanvas.width,this.wr.targetCanvas.height),this.Gc()},window.addEventListener("resize",this.Nc),this.Uo.so(),this.na.so(),this.ca.so(),window.addEventListener("blur",()=>{this.ca.So()}),this.Tr&&(this.Xc=new ResizeObserver(()=>{this.resizeCanvas(this.wr.targetCanvas.width,this.wr.targetCanvas.height)}),this.Xc.observe(this.wr.targetCanvas))}aa(){if(!this.kc.Ya&&this.Hc){this.Oc=!0;try{this.ha.$n(),this.ha.Sn(),this.Tr&&xt(this.K.context,this.Yc.texture,this.wr.targetCanvas),this.zc.ya(),this.K.state.Wt(),this.ra.begin(),this.Bc(),this.ra.end(),this.Ma.begin(),this.K.oi(this.Pc),this.Pc.L({u_characterTexture:this.ji.fontFramebuffer,u_charsetDimensions:[this.ji.textureColumns,this.ji.textureRows],U0:this.ra.textures[0],U1:this.ra.textures[1],U2:this.ra.textures[2],U3:[this.Un.cols,this.Un.rows],U4:[this.Ma.width,this.Ma.height],U5:this.K.state.canvasBackgroundColor}),this.K.fi(0,0,this.wr.width,this.wr.height),this.Ma.end(),this.K.ge(...this.K.state.canvasBackgroundColor),this.K.oi(this.Ec),this.Ec.L({U6:this.Ma.textures[0],U7:[this.Ma.width,this.Ma.height],U8:[this.Un.offsetX,this.Un.offsetY],U9:[this.Un.width,this.Un.height]}),this.K.fi(this.Un.offsetX,this.Un.offsetY,this.Un.width,this.Un.height),this.zc.ba()}finally{this.Oc=!1,this.Lc&&!this.Dc&&this.Zc()}}}resizeCanvas(i,r){this.wr.zr(i,r),this.kc.Rc(this.wr.kr()),this.Un.js(),this.kc.zr(),this.ra.resize(this.Un.cols,this.Un.rows),this.Ma.resize(this.Un.width,this.Un.height),this.K.bi(),this.Uo.Jn(),this.na.Jn(),this.aa()}destroy(){this.Dc||this.Lc||(this.Lc=!0,this.ha.xn(),this.Oc||this.Zc())}Zc(){var i,r;this.Lc=!1,this.kc.ft(),this.zc.Ca(),window.removeEventListener("resize",this.Nc),(i=this.Xc)==null||i.disconnect(),this.Uo.ao(),this.na.ao(),this.ca.ao(),this.ra.ft(),this.Pc.dispose(),this.ji.ft(),this.K.ft(),this.Ma.ft(),this.Ec.dispose(),(r=this.Yc)==null||r.ft(),this.wr.ft(),this.Dc=!0}setup(i){this.Ic=i}draw(i){this.Bc=i}windowResized(i){this.Gc=i}get grid(){return this.Un}get font(){return this.ji}get width(){return this.wr.width}get height(){return this.wr.height}get canvas(){return this.wr.canvas}get drawFramebuffer(){return this.ra}get isDisposed(){return this.Dc}get overlay(){return this.Yc}get loading(){return this.kc}ia(i){this.oa.has(i)||this.oa.add(i)}}class ot{constructor(){}static create(t={}){return new Wt(t)}static setErrorLevel(t){lt._(t)}static get version(){return"0.6.1"}}let Et=null;const ze={id:"brightness",createShader:({gl:o})=>(Et||(Et=new j(o,tt,`#version 300 es
14
- precision highp float;in vec2 v_uv;uniform sampler2D u_image;uniform bool u_invert;uniform bool u_flipX;uniform bool u_flipY;uniform float u_charRotation;uniform bool u_charColorFixed;uniform vec4 u_charColor;uniform bool u_cellColorFixed;uniform vec4 u_cellColor;uniform vec4 u_backgroundColor;uniform int u_charCount;uniform vec3 u_charList[255];uniform bool u_colorFilterEnabled;uniform int u_colorFilterSize;uniform vec4 u_colorFilterPalette[64];layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;float A(vec3 B){return dot(B,vec3(0.299f,0.587f,0.114f));}float C(vec3 D,vec3 E){vec3 F=D-E;return dot(F,F);}vec4 G(vec4 H){if(!u_colorFilterEnabled||u_colorFilterSize<=0){return H;}int I=min(u_colorFilterSize,64);vec3 J=u_colorFilterPalette[0].rgb;float K=C(H.rgb,J);for(int L=1;L<64;++L){if(L>=I){break;}vec3 M=u_colorFilterPalette[L].rgb;float N=C(H.rgb,M);if(N<K){K=N;J=M;}}return vec4(J,H.a);}void main(){vec2 O=vec2(v_uv.x,1.0f-v_uv.y);vec4 H=texture(u_image,O);H=G(H);float E=A(H.rgb);vec2 P=vec2(0.);if(u_charCount>0){float Q=float(u_charCount);float R=clamp(E*(Q-1.0f),0.0f,Q-1.0f);int S=int(floor(R+0.5f));vec3 T=u_charList[S];P=T.xy;}else{P=vec2(E,0.0f);}vec4 U=u_charColorFixed?u_charColor:H;vec4 V=u_cellColorFixed?u_cellColor:H;if(H.a<0.01f){U=u_backgroundColor;V=u_backgroundColor;}else{}o_primaryColor=vec4(U.rgb,U.a);o_secondaryColor=vec4(V.rgb,V.a);int W=int(u_invert?1:0);int X=int(u_flipX?1:0);int Y=int(u_flipY?1:0);float Z=float(W|(X<<1)|(Y<<2))/255.;o_character=vec4(P,Z,clamp(u_charRotation,0.0f,1.0f));}`)),Et),createUniforms:({source:o})=>o.createBaseConversionUniforms()},Ke=Object.freeze(Object.defineProperty({__proto__:null,LoadingPhaseTracker:zt,LoadingScreenManager:jt,LoadingScreenStateMachine:Kt,LoadingScreenTransition:Yt,resolveColorInputs:Ht,resolveDefaultPalette:kt,resolveTheme:wt},Symbol.toStringTag,{value:"Module"})),Ye=Object.freeze(Object.defineProperty({__proto__:null,TextmodeFont:pt,TextmodeImage:k,TextmodeVideo:ht},Symbol.toStringTag,{value:"Module"})),ke=Object.freeze(Object.defineProperty({__proto__:null,keyboard:Ue,mouse:Ce,touch:Me},Symbol.toStringTag,{value:"Module"}));Pt(ze);const He=ot.create,je=ot.setErrorLevel,We=ot.version;x.TextmodeCanvas=St,x.TextmodeColor=B,x.TextmodeErrorLevel=X,x.TextmodeFramebuffer=V,x.TextmodeGrid=mt,x.Textmodifier=Wt,x.create=He,x.getConversionStrategy=Lt,x.input=ke,x.loadables=Ye,x.loading=Ke,x.registerConversionStrategy=Pt,x.setErrorLevel=je,x.textmode=ot,x.unregisterConversionStrategy=function(o){yt.delete(o)},x.version=We,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):e((s=typeof globalThis<"u"?globalThis:s||self).textmode={});
7
+ `}static o(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="number"||typeof t=="boolean")return t+"";if(Array.isArray(t))return t.length===0?"[]":t.length<=5?`[${t.map(i=>R.o(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>R.o(i)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const i=Object.keys(t);return i.length===0?"{}":i.length<=3?`{ ${i.map(r=>`${r}: ${R.o(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${R.o(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var Z=(o=>(o[o.SILENT=0]="SILENT",o[o.WARNING=1]="WARNING",o[o.ERROR=2]="ERROR",o[o.THROW=3]="THROW",o))(Z||{});const Y=class Y{constructor(){l(this,"l",{globalLevel:3})}static u(){return Y.h||(Y.h=new Y),Y.h}v(t,i){const r="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",n="color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";switch(this.l.globalLevel){case 0:return!1;case 1:return console.group(r,n),console.warn(R.i(t,i)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(R.i(t,i)),console.groupEnd(),!1;default:throw new R(t,i)}}m(t,i,r){return!!t||(this.v(i,r),!1)}_(t){this.l.globalLevel=t}};l(Y,"h",null);let lt=Y;const ut=lt.u();class H{constructor(t,i,r){l(this,"A");l(this,"C");l(this,"M",new Map);l(this,"F",new Map);l(this,"P",0);l(this,"$",new Map);l(this,"U");this.A=t,this.U=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS)??16,this.C=this.R(i,r),this.S()}S(){const t=this.A.getProgramParameter(this.C,this.A.ACTIVE_UNIFORMS);for(let i=0;i<t;i++){const r=this.A.getActiveUniform(this.C,i);if(r){const n=r.name.replace(/\[0\]$/,""),h=this.A.getUniformLocation(this.C,n);h&&(this.M.set(n,h),this.F.set(n,{type:r.type,size:r.size}))}}}R(t,i){const r=this.k(this.A.VERTEX_SHADER,t),n=this.k(this.A.FRAGMENT_SHADER,i),h=this.A.createProgram();if(this.A.attachShader(h,r),this.A.attachShader(h,n),this.A.linkProgram(h),!this.A.getProgramParameter(h,this.A.LINK_STATUS)){const a=this.A.getProgramInfoLog(h);throw Error("Shader program link error: "+a)}return this.A.deleteShader(r),this.A.deleteShader(n),h}k(t,i){const r=this.A.createShader(t);if(this.A.shaderSource(r,i),this.A.compileShader(r),!this.A.getShaderParameter(r,this.A.COMPILE_STATUS)){const n=this.A.getShaderInfoLog(r);throw this.A.deleteShader(r),Error("Shader compilation error: "+n)}return r}D(){this.A.useProgram(this.C),this.L()}L(){this.P=0,this.$.clear()}I(t){for(const i in t)this.O(i,t[i])}O(t,i){var u,f;const r=this.M.get(t);if(!r)return;const n=this.F.get(t);if(!n)return;const{type:h,size:a}=n,c=this.A;if(i instanceof WebGLTexture){const d=this.H(t);return c.uniform1i(r,d),c.activeTexture(c.TEXTURE0+d),void c.bindTexture(c.TEXTURE_2D,i)}if(i instanceof z){const d=this.H(t);return c.uniform1i(r,d),c.activeTexture(c.TEXTURE0+d),void c.bindTexture(c.TEXTURE_2D,i.textures[0])}if(typeof i!="number")if(typeof i!="boolean")if(Array.isArray(i[0])){const d=i.flat(),g={[c.FLOAT_VEC2]:()=>c.uniform2fv(r,d),[c.FLOAT_VEC3]:()=>c.uniform3fv(r,d),[c.FLOAT_VEC4]:()=>c.uniform4fv(r,d)};(u=g[h])==null||u.call(g)}else{const d=i,g={[c.FLOAT]:()=>a>1?c.uniform1fv(r,d):c.uniform1f(r,d[0]),[c.FLOAT_VEC2]:()=>c.uniform2fv(r,d),[c.FLOAT_VEC3]:()=>c.uniform3fv(r,d),[c.FLOAT_VEC4]:()=>c.uniform4fv(r,d),[c.INT]:()=>a>1?c.uniform1iv(r,d):c.uniform1i(r,d[0]),[c.INT_VEC2]:()=>c.uniform2iv(r,d),[c.INT_VEC3]:()=>c.uniform3iv(r,d),[c.INT_VEC4]:()=>c.uniform4iv(r,d),[c.BOOL]:()=>c.uniform1iv(r,d),[c.FLOAT_MAT2]:()=>c.uniformMatrix2fv(r,!1,d),[c.FLOAT_MAT3]:()=>c.uniformMatrix3fv(r,!1,d),[c.FLOAT_MAT4]:()=>c.uniformMatrix4fv(r,!1,d)};(f=g[h])==null||f.call(g)}else c.uniform1i(r,i?1:0);else h===c.INT||h===c.BOOL?c.uniform1i(r,i):c.uniform1f(r,i)}H(t){const i=this.$.get(t);if(i!==void 0)return i;if(this.P>=this.U)throw Error(`[textmode.js] Shader attempted to bind more than ${this.U} texture samplers. Uniform "${t}" cannot be assigned.`);const r=this.P++;return this.$.set(t,r),r}get G(){return this.C}dispose(){this.A.deleteProgram(this.C)}}function Rt(o,t,i,r){return 180*Math.atan2(r-t,i-o)/Math.PI}function j(o,t,i,r){return Math.hypot(i-o,r-t)}function O(o,t,i){return Math.min(Math.max(o,t),i)}function Ct(o){return(o%360+360)%360/360}function Ft(o,t,i){o.bindTexture(o.TEXTURE_2D,t),o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,1),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,i),o.bindTexture(o.TEXTURE_2D,null)}function tt(o,t,i,r,n){o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,t),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,i),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,r),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,n)}function ft(o,t,i,r,n,h=0,a=WebGL2RenderingContext.FLOAT,c=!1){o.enableVertexAttribArray(t),o.vertexAttribPointer(t,i,a,c,r,n),o.vertexAttribDivisor(t,h)}function Pt(o,t,i,r,n){o.bindBuffer(t,i),o.bufferData(t,r,n),o.bindBuffer(t,null)}const et=`#version 300 es
8
+ in vec2 A0;in vec2 A1;in vec2 A2;in vec2 A3;in vec3 A4;in vec4 A5;in vec4 A6;in vec4 A7;in vec3 A8;in vec3 A9;in vec4 Aa;in vec4 Ab;in vec3 Ac;uniform vec2 Uc;uniform float Ud;uniform float Ue;out vec2 v_uv;out vec3 v_glyphIndex;out vec4 v_glyphColor;out vec4 v_cellColor;out vec4 v_glyphFlags;out vec3 v_worldPosition;out vec3 v_normal;out float v_geometryType;const float A=6.28318530718f;const int B=2;const int C=3;const int D=4;vec2 E(float F,vec2 G,vec2 H,vec2 I,vec2 J){float K=1.0f-F;float L=K*K;float M=L*K;float N=F*F;float O=N*F;return M*G+3.0f*L*F*H+3.0f*K*N*I+O*J;}vec2 P(float F,vec2 G,vec2 H,vec2 I,vec2 J){float K=1.0f-F;float L=K*K;float N=F*F;return-3.0f*L*G+3.0f*(L-2.0f*K*F)*H+3.0f*(2.0f*K*F-N)*I+3.0f*N*J;}vec3 Q(vec3 R,float S){float T=cos(S);float U=sin(S);return vec3(R.x,R.y*T-R.z*U,R.y*U+R.z*T);}vec3 V(vec3 R,float S){float T=cos(S);float U=sin(S);return vec3(R.x*T+R.z*U,R.y,-R.x*U+R.z*T);}vec3 W(vec3 R,float S){float T=cos(S);float U=sin(S);return vec3(R.x*T-R.y*U,R.x*U+R.y*T,R.z);}vec3 X(vec3 R,vec3 Y){vec3 Z=R;if(Y.z!=0.0f){Z=W(Z,Y.z);}if(Y.y!=0.0f){Z=V(Z,Y.y);}if(Y.x!=0.0f){Z=Q(Z,Y.x);}return Z;}void main(){v_uv=A1;v_glyphIndex=A4;v_glyphColor=A5;v_cellColor=A6;v_glyphFlags=A7;vec4 a=Aa;vec4 b=Ab;vec2 c=A3;vec2 d=A2;float e=Ac.x;float f=Ac.y;int g=int(Ac.z);vec2 h=d;vec2 i=h+c*0.5f;float j=f+e*0.5f;vec3 k=vec3(i,j);vec3 l;if(g==D){float F=clamp(A0.x,0.0f,1.0f);vec2 G=b.xy;vec2 H=a.xy;vec2 I=a.zw;vec2 J=b.zw;vec2 m=E(F,G,H,I,J);vec2 n=P(F,G,H,I,J);float o=length(n);vec2 p=o>0.0f?n/o:vec2(1.0f,0.0f);vec2 q=vec2(-p.y,p.x);vec2 r=m;vec2 s=r+q*A0.y*c.y;l=vec3(s,f);}else if(g==C){float t=mod(a.x,A);if(t<0.0f){t+=A;}float u=mod(a.y,A);if(u<0.0f){u+=A;}float v=t-u;if(v<=0.0f){v+=A;}float S=t-A0.x*v;vec2 w=vec2(cos(S),sin(S))*A0.y;vec2 s=w*c+h;l=vec3(s,f);}else if(g==B){vec2 s=A0.xy*c+h;l=vec3(s,f);}vec3 x=X(l,A9);vec3 y=x+A8;vec3 z=vec3(0.0f,0.0f,1.0f);v_worldPosition=y;v_normal=z;v_geometryType=float(g);vec2 AA=(y.xy/Uc)*2.0f;AA.y=-AA.y;float AB=y.z/Uc.y;float AC=clamp(-AB*Ud,-0.99f,0.99f);if(Ue>0.5f){gl_Position=vec4(AA,AC,1.0f);}else{float AD=0.5f;float AE=1.0f/(1.0f-AB*AD);AA*=AE;gl_Position=vec4(AA,AC,1.0f);}}`,k=class k{constructor(t,i,r=i,n=1,h={},a){l(this,"N");l(this,"X");l(this,"l");l(this,"A");l(this,"Y");l(this,"j",[]);l(this,"K",null);l(this,"W");l(this,"Z");l(this,"q",null);l(this,"V",new Map);this.N=i,this.X=r,this.A=t,this.W=O(n,1,8),this.Z=a,this.l={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",depth:!0,...h},k.J||(k.J=new H(t,et,`#version 300 es
9
+ precision highp float;in vec2 v_uv;uniform sampler2D U4;uniform sampler2D U5;uniform sampler2D U6;uniform sampler2D U7;uniform vec2 U8;uniform bool U9;uniform bool Ua;uniform bool Ub;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 A;void main(){vec2 B=vec2(v_uv.x,1.-v_uv.y);vec2 C=B*U8;vec2 D=(floor(C)+0.5f)/U8;vec4 E=texture(U4,D);vec4 F=U9?texture(U5,D):vec4(0.);if(U9&&F.a==0.){discard;}vec4 G=Ua?texture(U6,D):vec4(0.);vec4 H=Ub?texture(U7,D):vec4(0.);o_character=E;o_primaryColor=F;o_secondaryColor=G;A=H;}`));const c=t.getParameter(t.MAX_DRAW_BUFFERS),u=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.W=Math.min(this.W,c,u),this.Y=t.createFramebuffer(),this.tt(),this.st(),this.l.depth&&this.et()}tt(){const t=this.A,i=this.l.filter==="linear"?t.LINEAR:t.NEAREST,r=this.l.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE,n=this.l.type==="float"?t.FLOAT:t.UNSIGNED_BYTE,h=n===t.FLOAT?t.RGBA32F:t.RGBA8,a=t.RGBA;for(let c=0;c<this.W;c++){const u=t.createTexture();t.bindTexture(t.TEXTURE_2D,u),tt(t,i,i,r,r),t.texImage2D(t.TEXTURE_2D,0,h,this.N,this.X,0,a,n,null),this.j.push(u)}t.bindTexture(t.TEXTURE_2D,null)}st(){const t=this.A;if(t.bindFramebuffer(t.FRAMEBUFFER,this.Y),this.W===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.j[0],0);else{const i=[];for(let r=0;r<this.W;r++){const n=t.COLOR_ATTACHMENT0+r;t.framebufferTexture2D(t.FRAMEBUFFER,n,t.TEXTURE_2D,this.j[r],0),i.push(n)}t.drawBuffers(i)}t.bindFramebuffer(t.FRAMEBUFFER,null)}et(){const t=this.A;this.K=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,this.K),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT24,this.N,this.X),t.bindFramebuffer(t.FRAMEBUFFER,this.Y),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,this.K),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindRenderbuffer(t.RENDERBUFFER,null)}it(t){Ft(this.A,this.j[0],t)}resize(t,i){this.N=t,this.X=i,this.V.clear();const r=this.A,n=this.l.type==="float"?r.FLOAT:r.UNSIGNED_BYTE,h=n===r.FLOAT?r.RGBA32F:r.RGBA8,a=r.RGBA;for(const c of this.j)r.bindTexture(r.TEXTURE_2D,c),r.texImage2D(r.TEXTURE_2D,0,h,this.N,this.X,0,a,n,null);r.bindTexture(r.TEXTURE_2D,null),this.K&&(r.bindRenderbuffer(r.RENDERBUFFER,this.K),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT24,this.N,this.X),r.bindRenderbuffer(r.RENDERBUFFER,null))}readPixels(t){const i=this.V.get(t);if(i)return i;const r=this.A,n=this.N,h=this.X,a=new Uint8Array(n*h*4),c=r.getParameter(r.READ_FRAMEBUFFER_BINDING);r.bindFramebuffer(r.READ_FRAMEBUFFER,this.Y),r.readBuffer(r.COLOR_ATTACHMENT0+t),r.readPixels(0,0,n,h,r.RGBA,r.UNSIGNED_BYTE,a),r.bindFramebuffer(r.READ_FRAMEBUFFER,c);const u=4*n,f=new Uint8Array(a.length);for(let d=0;d<h;d++){const g=(h-1-d)*u,v=d*u;f.set(a.subarray(g,g+u),v)}return this.V.set(t,f),f}begin(){const t=this.A;this.V.clear(),this.Z.rt(),this.Z.nt(this.Y,this.N,this.X,this.W),this.l.depth&&t.clear(t.DEPTH_BUFFER_BIT),this.Z.state.ot()}end(){this.Z.state.ht(),this.Z.ct(),this.Z.lt()}ut(){return this.q||this.ft(),this.q}ft(){if(!this.Z)return;const t=this.W>1,i=this.W>2,r=this.W>3,n={U4:this.j[0],U5:t?this.j[1]:this.j[0],U6:i?this.j[2]:this.j[0],U7:r?this.j[3]:this.j[0],U8:[this.N,this.X],U9:t,Ua:i,Ub:r},h=k.J;this.q=this.Z.vt.dt(h,n,!0)}gt(){const t=this.A;t.deleteFramebuffer(this.Y);for(const i of this.j)t.deleteTexture(i);this.K&&t.deleteRenderbuffer(this.K)}get width(){return this.N}get height(){return this.X}get textures(){return this.j}get attachmentCount(){return this.W}};l(k,"J",null);let z=k;const Mt=new WeakMap;function dt(o,t){Mt.set(o,t)}function Nt(o){return Mt.get(o)}function it(o,t,i,r,n=255){o[0]=t/255,o[1]=(i??t)/255,o[2]=(r??t)/255,o[3]=n/255}class rt{constructor(){l(this,"_t",1);l(this,"At",0);l(this,"yt",0);l(this,"wt",0);l(this,"bt",0);l(this,"Ct",0);l(this,"xt",0);l(this,"Mt",[0,0,0]);l(this,"Ft",[1,1,1,1]);l(this,"Pt",[0,0,0,1]);l(this,"$t",!1);l(this,"Tt",!1);l(this,"Et",!1);l(this,"Rt",0);l(this,"St",[0,0,0,1]);l(this,"kt",!1);l(this,"zt",[]);l(this,"Dt",[])}static Lt(){return{It:1,Ot:0,Bt:0,Ht:0,bt:0,Ct:0,xt:0,Rt:0,Gt:!1,Qt:!1,Et:!1,kt:!1,Nt:[0,0,0],Xt:[1,1,1,1],Yt:[0,0,0,1]}}jt(t){t.It=this._t,t.Ot=this.At,t.Bt=this.yt,t.Ht=this.wt,t.bt=this.bt,t.Ct=this.Ct,t.xt=this.xt,t.Gt=this.$t,t.Qt=this.Tt,t.Et=this.Et,t.Rt=this.Rt,t.kt=this.kt,t.Nt[0]=this.Mt[0],t.Nt[1]=this.Mt[1],t.Nt[2]=this.Mt[2],t.Xt[0]=this.Ft[0],t.Xt[1]=this.Ft[1],t.Xt[2]=this.Ft[2],t.Xt[3]=this.Ft[3],t.Yt[0]=this.Pt[0],t.Yt[1]=this.Pt[1],t.Yt[2]=this.Pt[2],t.Yt[3]=this.Pt[3]}Kt(t){this._t=t.It,this.At=t.Ot,this.yt=t.Bt,this.wt=t.Ht,this.bt=t.bt,this.Ct=t.Ct,this.xt=t.xt,this.$t=t.Gt,this.Tt=t.Qt,this.Et=t.Et,this.Rt=t.Rt,this.kt=t.kt,this.Mt[0]=t.Nt[0],this.Mt[1]=t.Nt[1],this.Mt[2]=t.Nt[2],this.Ft[0]=t.Xt[0],this.Ft[1]=t.Xt[1],this.Ft[2]=t.Xt[2],this.Ft[3]=t.Xt[3],this.Pt[0]=t.Yt[0],this.Pt[1]=t.Yt[1],this.Pt[2]=t.Yt[2],this.Pt[3]=t.Yt[3]}ot(){let t=this.Dt.pop();t||(t=rt.Lt()),this.jt(t),this.zt.push(t)}ht(){const t=this.zt.pop();t?(this.Kt(t),this.Dt.push(t)):console.warn("pop() called without matching push()")}Wt(t){this.jt(t)}Zt(t){this._t=Math.abs(t)}qt(){this.At=0,this.yt=0,this.wt=0,this.bt=0,this.Ct=0,this.xt=0,this.kt=!1}Vt(t){t!==0&&(this.bt+=t*Math.PI/180)}Jt(t){t!==0&&(this.Ct+=t*Math.PI/180)}ts(t){t!==0&&(this.xt+=t*Math.PI/180)}ss(t=0,i=0,r=0){t===0&&i===0&&r===0||(this.At+=t,this.yt+=i,this.wt+=r)}es(t){this.ss(t,0,0)}rs(t){this.ss(0,t,0)}ns(t){this.ss(0,0,t)}hs(t){this.Mt[0]=t[0],this.Mt[1]=t[1],this.Mt[2]=t[2]}cs(t,i,r,n=255){it(this.Ft,t,i,r,n)}ls(t,i,r,n=255){it(this.Pt,t,i,r,n)}us(t){this.$t=t}fs(t){this.Tt=t}ds(t){this.Et=t}vs(t){this.Rt=Ct(t)}ps(t,i,r,n){it(this.St,t,i,r,n)}gs(t){this.kt=t}get canvasBackgroundColor(){return this.St}get useOrtho(){return this.kt}get rotationX(){return this.bt}get rotationY(){return this.Ct}get rotationZ(){return this.xt}}const gt=new Float32Array([-.5,-.5,0,0,.5,-.5,1,0,-.5,.5,0,1,-.5,.5,0,1,.5,-.5,1,0,.5,.5,1,1]),V={_s:16,As:WebGL2RenderingContext.TRIANGLES,ws:{bs:{size:2,offset:0},Cs:{size:2,offset:8}}};class te{constructor(t){l(this,"A");l(this,"Ms");l(this,"Fs");this.A=t,this.Ms=t.createBuffer(),this.Fs=new Float32Array(gt.length)}Ps(t,i,r,n){const h=this.A,a=Nt(this.A),c=a[2],u=a[3],f=t/c*2-1,d=(t+r)/c*2-1,g=1-(i+n)/u*2,v=1-i/u*2,p=gt,m=this.Fs;for(let A=0;A<p.length;A+=4){const w=p[A],y=p[A+1],b=p[A+2],E=p[A+3],P=f+(w+.5)*(d-f),x=g+(y+.5)*(v-g);m[A]=P,m[A+1]=x,m[A+2]=b,m[A+3]=E}h.bindBuffer(h.ARRAY_BUFFER,this.Ms),h.bufferData(h.ARRAY_BUFFER,m,h.DYNAMIC_DRAW),h.enableVertexAttribArray(0),h.vertexAttribPointer(0,2,h.FLOAT,!1,16,0),h.enableVertexAttribArray(1),h.vertexAttribPointer(1,2,h.FLOAT,!1,16,8),h.drawArrays(h.TRIANGLES,0,6),h.disableVertexAttribArray(1),h.disableVertexAttribArray(0),h.bindBuffer(h.ARRAY_BUFFER,null)}gt(){this.A.deleteBuffer(this.Ms)}}var C=(o=>(o.RECTANGLE="rectangle",o.LINE="line",o.ELLIPSE="ellipse",o.ARC="arc",o.TRIANGLE="triangle",o.BEZIER_CURVE="bezier_curve",o))(C||{});const ee={rectangle:2,line:2,ellipse:2,triangle:2,arc:3,bezier_curve:4};class ie{constructor(t){l(this,"A");l(this,"$s",new Map);this.A=t}Ts(t,i,r,n){const h=this.A;let a=this.$s.get(t);a||(a=new Map,this.$s.set(t,a));let c=a.get(i)||null;if(!c){c=h.createVertexArray(),a.set(i,c),h.bindVertexArray(c),h.bindBuffer(h.ARRAY_BUFFER,n);const u=h.getAttribLocation(t,"A0");u!==-1&&ft(h,u,r.ws.bs.size,r._s,r.ws.bs.offset,0,h.FLOAT,!1);const f=h.getAttribLocation(t,"A1");f!==-1&&ft(h,f,r.ws.Cs.size,r._s,r.ws.Cs.offset,0,h.FLOAT,!1)}h.bindVertexArray(c)}Es(){this.A.bindVertexArray(null)}gt(){for(const[,t]of this.$s)for(const[,i]of t)i&&this.A.deleteVertexArray(i)}}const I=class I{static Rs(t,i,r=0){const n=i||new Float32Array(I.FLOATS_PER_INSTANCE);let h=r;n[h++]=t.bs[0],n[h++]=t.bs[1],n[h++]=t.Ss[0],n[h++]=t.Ss[1],n[h++]=t.Nt[0],n[h++]=t.Nt[1],n[h++]=t.Nt[2],n[h++]=t.Xt[0],n[h++]=t.Xt[1],n[h++]=t.Xt[2],n[h++]=t.Xt[3],n[h++]=t.Yt[0],n[h++]=t.Yt[1],n[h++]=t.Yt[2],n[h++]=t.Yt[3],n[h++]=t.ks[0],n[h++]=t.ks[1],n[h++]=t.ks[2],n[h++]=t.Rt;const a=t.zs;n[h++]=(a==null?void 0:a[0])??0,n[h++]=(a==null?void 0:a[1])??0,n[h++]=(a==null?void 0:a[2])??0;const c=t.Ds;n[h++]=(c==null?void 0:c[0])??0,n[h++]=(c==null?void 0:c[1])??0,n[h++]=(c==null?void 0:c[2])??0;const u=t.Ls,f=t.Is,d=t.Os,g=t.Bs,v=t.Hs,p=!(!f||!d);return p?(n[h++]=(g==null?void 0:g[0])??0,n[h++]=(g==null?void 0:g[1])??0,n[h++]=(v==null?void 0:v[0])??0,n[h++]=(v==null?void 0:v[1])??0,n[h++]=f[0],n[h++]=f[1],n[h++]=d[0],n[h++]=d[1]):!p&&!!u?(n[h++]=u[0],n[h++]=u[1],n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0):(n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0,n[h++]=0),n[h++]=t.Gs??0,n[h++]=t.Qs??0,n[h++]=t.Ns??0,n}static Xs(t,i){const r=t.length*I.FLOATS_PER_INSTANCE,n=i||new Float32Array(r);for(let h=0;h<t.length;h++){const a=h*I.FLOATS_PER_INSTANCE;I.Rs(t[h],n,a)}return n}};l(I,"BYTES_PER_INSTANCE",144),l(I,"FLOATS_PER_INSTANCE",36);let _=I;const S=class S{};l(S,"STRIDE",_.BYTES_PER_INSTANCE),l(S,"ATTRIBUTES",{A2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:0,divisor:1},A3:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:8,divisor:1},A4:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:16,divisor:1},A5:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:28,divisor:1},A6:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:44,divisor:1},A7:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:60,divisor:1},A8:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:76,divisor:1},A9:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:88,divisor:1},Aa:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:100,divisor:1},Ab:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:116,divisor:1},Ac:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:132,divisor:1}});let Q=S;class re{constructor(t=1e3,i=1.5){l(this,"Ys");l(this,"js");l(this,"Ks");l(this,"Ws",0);l(this,"Zs",0);this.js=t,this.Ks=i;const r=t*_.FLOATS_PER_INSTANCE;this.Ys=new Float32Array(r)}qs(t){if(t<=this.js)return;const i=Math.ceil(t*this.Ks),r=this.js;this.js=i;const n=i*_.FLOATS_PER_INSTANCE,h=new Float32Array(n),a=r*_.FLOATS_PER_INSTANCE;h.set(this.Ys.subarray(0,Math.min(a,this.Ws))),this.Ys=h}Vs(){return{buffer:this.Ys,offset:this.Ws}}Js(t){this.Ws+=t,this.Zs++}te(){this.Ws=0,this.Zs=0}se(t=0,i){return this.Ys.subarray(t,i??this.Ws)}get ee(){return this.Zs}get ie(){return this.js}get re(){return this.Ws}get ne(){return this.Zs===0}}class se{constructor(t){l(this,"Ys");this.Ys=t}oe(t){this.Ys.qs(this.Ys.ee+1);const{buffer:i,offset:r}=this.Ys.Vs();i[r+0]=t.x,i[r+1]=t.y,i[r+2]=t.width,i[r+3]=t.height,i[r+4]=t.char0,i[r+5]=t.char1,i[r+6]=t.char2,i[r+7]=t.r1,i[r+8]=t.g1,i[r+9]=t.b1,i[r+10]=t.a1,i[r+11]=t.r2,i[r+12]=t.g2,i[r+13]=t.b2,i[r+14]=t.a2,i[r+15]=t.invert,i[r+16]=t.flipX,i[r+17]=t.flipY,i[r+18]=t.charRot,i[r+19]=t.translationX,i[r+20]=t.translationY,i[r+21]=t.translationZ,i[r+22]=t.rotationX,i[r+23]=t.rotationY,i[r+24]=t.rotationZ;const n=t.curveParams0,h=t.curveParams1;return i[r+25]=n[0],i[r+26]=n[1],i[r+27]=n[2],i[r+28]=n[3],i[r+29]=h[0],i[r+30]=h[1],i[r+31]=h[2],i[r+32]=h[3],i[r+33]=t.depth,i[r+34]=t.baseZ,i[r+35]=t.geometryType,this.Ys.Js(_.FLOATS_PER_INSTANCE),this.Ys.ee-1}get ee(){return this.Ys.ee}}class ne{constructor(t,i=1e3){l(this,"A");l(this,"he",null);l(this,"ae",0);l(this,"ce",new Map);this.A=t,this.le(i)}le(t){const i=this.A;this.he&&i.deleteBuffer(this.he),this.he=i.createBuffer();const r=t*_.BYTES_PER_INSTANCE;Pt(i,i.ARRAY_BUFFER,this.he,r,i.DYNAMIC_DRAW),this.ae=t}ue(t){this.le(t)}get ie(){return this.ae}fe(t,i){if(i===0)return;const r=this.A;r.bindBuffer(r.ARRAY_BUFFER,this.he);const n=i*_.FLOATS_PER_INSTANCE;r.bufferSubData(r.ARRAY_BUFFER,0,t,0,n)}de(t){let i=this.ce.get(t);if(!i){i=new Map;const r=this.A;for(const n in Q.ATTRIBUTES){const h=r.getAttribLocation(t,n);h!==-1&&i.set(n,h)}this.ce.set(t,i)}return i}ve(t){const i=this.A,r=t.G,n=this.de(r);for(const[h,a]of n){const c=Q.ATTRIBUTES[h];c&&ft(i,a,c.size,c.stride,c.offset,c.divisor,c.type,c.normalized)}}pe(t){const i=this.A,r=this.de(t.G);for(const[n,h]of r)Q.ATTRIBUTES[n]&&(i.disableVertexAttribArray(h),i.vertexAttribDivisor(h,0))}gt(){this.he&&(this.A.deleteBuffer(this.he),this.he=null),this.ce.clear()}}class he{constructor(t,i=1e3,r=1.5){l(this,"A");l(this,"Ys");l(this,"ge");l(this,"me");this.A=t,this.Ys=new re(i,r),this.ge=new se(this.Ys),this.me=new ne(t,i)}_e(t){var n,h,a,c,u,f,d,g,v,p;const i=[0,0,0,0],r=[0,0,0,0];return t.Is&&t.Os?(i[0]=((n=t.Bs)==null?void 0:n[0])??0,i[1]=((h=t.Bs)==null?void 0:h[1])??0,i[2]=((a=t.Hs)==null?void 0:a[0])??0,i[3]=((c=t.Hs)==null?void 0:c[1])??0,r[0]=t.Is[0],r[1]=t.Is[1],r[2]=t.Os[0],r[3]=t.Os[1]):t.Ls&&(i[0]=t.Ls[0],i[1]=t.Ls[1]),this.oe({x:t.bs[0],y:t.bs[1],width:t.Ss[0],height:t.Ss[1],char0:t.Nt[0],char1:t.Nt[1],char2:t.Nt[2],r1:t.Xt[0],g1:t.Xt[1],b1:t.Xt[2],a1:t.Xt[3],r2:t.Yt[0],g2:t.Yt[1],b2:t.Yt[2],a2:t.Yt[3],invert:t.ks[0],flipX:t.ks[1],flipY:t.ks[2],charRot:t.Rt,translationX:((u=t.zs)==null?void 0:u[0])??0,translationY:((f=t.zs)==null?void 0:f[1])??0,translationZ:((d=t.zs)==null?void 0:d[2])??0,rotationX:((g=t.Ds)==null?void 0:g[0])??0,rotationY:((v=t.Ds)==null?void 0:v[1])??0,rotationZ:((p=t.Ds)==null?void 0:p[2])??0,curveParams0:i,curveParams1:r,depth:t.Gs||0,baseZ:t.Qs||0,geometryType:t.Ns||0})}oe(t){const i=this.ge.oe(t);return this.Ys.ie>this.me.ie&&this.me.ue(this.Ys.ie),i}get Ae(){return this.Ys.ee}get ne(){return this.Ys.ne}ye(){this.Ys.te()}ve(t){const i=this.Ys.ee;if(i===0)return;const r=this.Ys.se();this.me.fe(r,i),this.me.ve(t)}pe(t){this.me.pe(t)}Ps(t,i){const r=this.Ys.ee;r!==0&&this.A.drawArraysInstanced(t,0,i,r)}gt(){this.me.gt()}}class G{constructor(t,i,r,n){l(this,"A");l(this,"we");l(this,"be");l(this,"Ce");l(this,"xe",null);this.A=t,this.we=i,this.be=r,this.Ce=n;const h=this.A.createBuffer();Pt(this.A,this.A.ARRAY_BUFFER,h,this.Ce.Me,this.A.STATIC_DRAW),this.xe=h}get type(){return this.be}get unitGeometry(){return this.Ce}get unitBuffer(){return this.xe}get batch(){return this.we}Fe(){this.we.ye()}Pe(){return!this.we.ne}gt(){this.we.gt(),this.A.deleteBuffer(this.xe)}$e(t,i,r){return this.we._e(t)}Te(t,i,r,n,h,a){const c=h.Ot??0,u=h.Bt??0,f=h.Ht??0,d=h.bt??0,g=h.Ct??0,v=h.xt??0,p=[0,0,0,0],m=[0,0,0,0];a&&(a.bezStartX!==void 0&&a.bezStartY!==void 0&&a.bezEndX!==void 0&&a.bezEndY!==void 0?(p[0]=a.cp1x??0,p[1]=a.cp1y??0,p[2]=a.cp2x??0,p[3]=a.cp2y??0,m[0]=a.bezStartX??0,m[1]=a.bezStartY??0,m[2]=a.bezEndX??0,m[3]=a.bezEndY??0):a.arcStart===void 0&&a.arcStop===void 0||(p[0]=a.arcStart??0,p[1]=a.arcStop??0));const A={x:t,y:i,width:r,height:n,char0:h.Nt[0],char1:h.Nt[1],char2:h.Nt[2],r1:h.Xt[0],g1:h.Xt[1],b1:h.Xt[2],a1:h.Xt[3],r2:h.Yt[0],g2:h.Yt[1],b2:h.Yt[2],a2:h.Yt[3],invert:h.Et?1:0,flipX:h.Gt?1:0,flipY:h.Qt?1:0,charRot:h.Rt,translationX:c,translationY:u,translationZ:f,rotationX:d,rotationY:g,rotationZ:v,curveParams0:p,curveParams1:m,depth:(a==null?void 0:a.depth)??0,baseZ:(a==null?void 0:a.baseZ)??0,geometryType:ee[this.be]??0};return this.we.oe(A)}}const oe={Me:gt,Ee:6,...V},ae={Me: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]),Ee:6,...V},ce={Me:function(o=32){const t=[],i=2*Math.PI/o;for(let r=0;r<o;r++){const n=r*i,h=(r+1)%o*i,a=Math.cos(n),c=Math.sin(n),u=.5*(a+1),f=.5*(c+1),d=Math.cos(h),g=Math.sin(h),v=.5*(d+1),p=.5*(g+1);t.push(0,0,.5,.5,a,c,u,f,d,g,v,p)}return new Float32Array(t)}(32),Ee:96,...V};let le={Me:function(o){const t=[];for(let i=0;i<o;i++){const r=i/o,n=(i+1)/o;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),Ee:96,...V};const ue={Me:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),Ee:3,...V},fe={Me:function(o=16){const t=[];for(let i=0;i<o;i++){const r=i/o,n=(i+1)/o;t.push(r,-.5,r,0,n,-.5,n,0,r,.5,r,1,r,.5,r,1,n,-.5,n,0,n,.5,n,1)}return new Float32Array(t)}(16),Ee:96,...V},de={[C.RECTANGLE]:class extends G{constructor(o,t){super(o,t,C.RECTANGLE,oe)}_e(o,t){return this.Te(0,0,o.width,o.height,t)}},[C.LINE]:class extends G{constructor(o,t){super(o,t,C.LINE,ae)}_e(o,t){const i=o.x2-o.x1,r=o.y2-o.y1,n=Math.hypot(i,r),h=Math.atan2(r,i),a=t.It||1,c=o.x1+i/2-n/2,u=o.y1+r/2,f={...t,xt:(t.xt||0)+h};return this.Te(c,u,n,a,f)}},[C.ELLIPSE]:class extends G{constructor(o,t){super(o,t,C.ELLIPSE,ce)}_e(o,t){return this.Te(0,0,o.width,o.height,t)}},[C.ARC]:class extends G{constructor(o,t){super(o,t,C.ARC,le)}_e(o,t){const i=o.start*Math.PI/180,r=o.stop*Math.PI/180;return this.Te(0,0,o.width,o.height,t,{arcStart:i,arcStop:r})}},[C.TRIANGLE]:class extends G{constructor(o,t){super(o,t,C.TRIANGLE,ue)}_e(o,t){const i=Math.min(o.x1,o.x2,o.x3),r=Math.max(o.x1,o.x2,o.x3),n=Math.min(o.y1,o.y2,o.y3),h=r-i,a=Math.max(o.y1,o.y2,o.y3)-n;return this.Te(i,n,h,a,t)}},[C.BEZIER_CURVE]:class extends G{constructor(o,t){super(o,t,C.BEZIER_CURVE,fe)}_e(o,t){return this.Te(0,0,1,t.It||1,t,{cp1x:o.cp1x,cp1y:o.cp1y,cp2x:o.cp2x,cp2y:o.cp2y,bezStartX:o.x1,bezStartY:o.y1,bezEndX:o.x2,bezEndY:o.y2})}}};class ge{constructor(t){l(this,"A");l(this,"Re");l(this,"Se");this.A=t,this.Se=new ie(t),this.Re=new Map;for(const i of Object.values(C)){const r=new he(t),n=new de[i](t,r);this.Re.set(i,n)}}ke(t){const i=this.ze(t);for(const r of i)this.De(r)}ze(t){const i=[];let r=null,n=null,h=null;for(const a of t)n!==a.material||h!==a.type?(r&&r.length>0&&i.push({material:n,type:h,commands:r}),r=[a],n=a.material,h=a.type):r.push(a);return r&&r.length>0&&i.push({material:n,type:h,commands:r}),i}De(t){const{material:i,type:r,commands:n}=t,h=this.Re.get(r);i.shader.D(),i.shader.I(i.uniforms);const a=Nt(this.A),c=n.length>0&&n[0].state.kt;i.shader.I({Uw:a[2]/a[3],Uc:[a[2],a[3]],Ud:1,Ue:c?1:0}),h.Fe();for(const u of n)h._e(u.params,u.state);if(h.Pe()){const u=h.unitGeometry,f=h.unitBuffer;try{this.Se.Ts(i.shader.G,r+"",u,f),h.batch.ve(i.shader),h.batch.Ps(u.As,u.Ee)}finally{h.batch.pe(i.shader),this.Se.Es(),h.Fe()}}}gt(){for(const t of this.Re.values())t.gt();this.Re.clear(),this.Se.gt()}}function Ut(o){let t=0;for(let i=0;i<o.length;i++)t=(t<<5)-t+o.charCodeAt(i),t&=t;return t}const St=new WeakMap;let me=1;function Lt(o){if(o==null)return 0;if(typeof o!="object"&&typeof o!="function")return Ut(o+"");let t=St.get(o);return t||(t=me++,St.set(o,t)),t}function K(o,t){return(o<<5)-o+t}class ve{constructor(t){l(this,"Le",0);l(this,"Ie");l(this,"Oe");l(this,"Be",new Map);this.Ie=new H(t,et,`#version 300 es
10
+ precision highp float;in vec3 v_glyphIndex;in vec4 v_glyphColor;in vec4 v_cellColor;in vec4 v_glyphFlags;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 A;void main(){int B=int(v_glyphFlags.r>0.5?1:0);int C=int(v_glyphFlags.g>0.5?1:0);int D=int(v_glyphFlags.b>0.5?1:0);float E=float(B|(C<<1)|(D<<2))/255.;o_character=vec4(v_glyphIndex.xy,E,clamp(v_glyphFlags.a,0.,1.));o_primaryColor=vec4(v_glyphColor.rgb,v_glyphColor.a);o_secondaryColor=vec4(v_cellColor.rgb,v_cellColor.a);A=vec4(0.);}`),this.Oe={id:this.Le++,shader:this.Ie,uniforms:Object.freeze({}),hash:this.He(this.Ie,{}),isBuiltIn:!0}}get Ge(){return this.Oe}dt(t,i={},r=!1){const n=this.He(t,i),h=this.Be.get(n);if(h)return h;const a={id:this.Le++,shader:t,uniforms:Object.freeze({...i}),hash:n,isBuiltIn:r};return this.Be.set(n,a),a}Qe(t,i={}){return{id:this.Le++,shader:t,uniforms:Object.freeze({...i}),hash:0,isBuiltIn:!1}}He(t,i){const r=Lt(t.G),n=function(h,a){let c=0;const u=Object.keys(h).sort();for(const f of u)c=K(c,Ut(f)),c=K(c,a(h[f]));return c}(i,this.Ne.bind(this));return K(r,n)}Ne(t){return typeof t=="number"||typeof t=="boolean"?function(i){return typeof i=="boolean"?i?1:0:Math.floor(i)}(t):Array.isArray(t)?function(i){let r=0;const n=Array.isArray(i[0])?i.flat():i;for(const h of n)r=K(r,typeof h=="number"?h:0);return r}(t):t instanceof Float32Array||t instanceof Int32Array?function(i){let r=0;const n=Math.min(i.length,16);for(let h=0;h<n;h++)r=K(r,i[h]);return r}(t):t instanceof WebGLTexture?Lt(t):0}gt(){this.Ie!=this.Ie&&this.Ie.dispose(),this.Ie.dispose(),this.Be.clear()}}class pe{constructor(){l(this,"Xe",[]);l(this,"Ye",1);l(this,"Ss",0)}je(t,i){if(this.Ss>=this.Xe.length){const n={id:this.Ye++,type:t,params:{},state:rt.Lt(),material:i};this.Xe.push(n)}const r=this.Xe[this.Ss];return r.id=this.Ye++,r.type=t,r.material=i,this.Ss++,r}Ke(t,i,r){const n=this.je(C.RECTANGLE,r),h=n.params;return h.width=t.width,h.height=t.height,i.Wt(n.state),n.id}We(t,i,r){const n=this.je(C.LINE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.x2=t.x2,h.y2=t.y2,h.thickness=t.thickness,i.Wt(n.state),n.id}Ze(t,i,r){const n=this.je(C.ELLIPSE,r),h=n.params;return h.width=t.width,h.height=t.height,h.startAngle=t.startAngle,h.endAngle=t.endAngle,h.segments=t.segments,i.Wt(n.state),n.id}qe(t,i,r){const n=this.je(C.ARC,r),h=n.params;return h.width=t.width,h.height=t.height,h.start=t.start,h.stop=t.stop,i.Wt(n.state),n.id}Ve(t,i,r){const n=this.je(C.TRIANGLE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.x2=t.x2,h.y2=t.y2,h.x3=t.x3,h.y3=t.y3,i.Wt(n.state),n.id}Je(t,i,r){const n=this.je(C.BEZIER_CURVE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.cp1x=t.cp1x,h.cp1y=t.cp1y,h.cp2x=t.cp2x,h.cp2y=t.cp2y,h.x2=t.x2,h.y2=t.y2,h.thickness=t.thickness,h.segments=t.segments,i.Wt(n.state),n.id}ye(){this.Ss=0}[Symbol.iterator](){let t=0;const i=this.Ss,r=this.Xe;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}class Ae{constructor(t){l(this,"A");l(this,"ti",null);l(this,"si");l(this,"vt");l(this,"ei");l(this,"ii");l(this,"ri");l(this,"ni",null);l(this,"oi",{});l(this,"hi",[]);l(this,"ai",[]);l(this,"ci",[]);l(this,"li",null);l(this,"ui",[0,0,0,0]);l(this,"fi",1);this.A=t,t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.clearDepth(1),t.depthMask(!0),t.disable(t.CULL_FACE),this.ei=new rt,this.vt=new ve(t),this.ii=new pe,this.si=new ge(t),this.ri=new te(t);const i=[0,0,t.canvas.width,t.canvas.height];dt(t,i),this.hi.push(null),this.ai.push(i),this.ci.push(1),this.li=null,this.ui=i,this.fi=1}rt(){this.hi.push(this.li),this.ai.push([...this.ui]),this.ci.push(this.fi)}lt(){const t=this.hi.pop()??null,i=this.ai.pop()??[0,0,this.A.canvas.width,this.A.canvas.height],r=this.ci.pop()??1;this.nt(t,i[2],i[3],r)}nt(t,i,r,n=1){const h=this.A;this.li!==t&&(h.bindFramebuffer(h.FRAMEBUFFER,t),this.li=t),this.fi=n;const a=[0,0,i,r];this.ui[0]===a[0]&&this.ui[1]===a[1]&&this.ui[2]===a[2]&&this.ui[3]===a[3]||(h.viewport(...a),dt(h,a),this.ui=a)}di(t){this.ti!==t&&(this.ti=t,t.D())}pi(t,i){return new H(this.A,t,i)}gi(t){this.ni=t,t&&(this.oi={})}O(t,i){this.oi[t]=i}mi(t){Object.assign(this.oi,t)}_i(t){return new H(this.A,et,t)}Ai(t,i,r){this.ii.Ke({width:i??t.width,height:r??t.height},this.ei,t.ut())}yi(t,i,r,n){this.ri.Ps(t,i,r,n)}wi(t,i){if(this.ni){const r=this.vt.Qe(this.ni,this.oi);this.ii.Ke({width:t,height:i},this.ei,r),this.ni=null,this.oi={}}else this.ii.Ke({width:t,height:i},this.ei,this.vt.Ge)}bi(t,i,r,n){this.ii.We({x1:t,y1:i,x2:r,y2:n},this.ei,this.vt.Ge)}Ci(t,i){this.ii.Ze({width:t,height:i},this.ei,this.vt.Ge)}xi(t,i,r,n,h,a){this.ii.Ve({x1:t,y1:i,x2:r,y2:n,x3:h,y3:a},this.ei,this.vt.Ge)}Mi(t,i,r,n,h,a,c,u){this.ii.Je({x1:t,y1:i,cp1x:r,cp1y:n,cp2x:h,cp2y:a,x2:c,y2:u},this.ei,this.vt.Ge)}Fi(t,i,r,n){this.ii.qe({width:t,height:i,start:r,stop:n},this.ei,this.vt.Ge)}Pi(t,i,r=1,n={}){return new z(this.A,t,i,r,n,this)}$i(t,i=t,r=t,n=255){this.ei.ps(t,i??t,r??t,n);const[h,a,c,u]=this.ei.canvasBackgroundColor;this.Ti(h,a,c,u,!1)}ye(t=0,i=0,r=0,n=0){this.Ti(t,i,r,n,!0)}Ti(t,i,r,n,h){const a=this.A;if(this.fi>1){const c=h?[1,1,0,0]:[0,0,0,0];a.clearBufferfv(a.COLOR,0,new Float32Array(c)),a.clearBufferfv(a.COLOR,1,new Float32Array([0,0,0,0])),this.fi>=3&&a.clearBufferfv(a.COLOR,2,new Float32Array([t,i,r,n]));for(let u=3;u<this.fi;u++)a.clearBufferfv(a.COLOR,u,new Float32Array([0,0,0,0]))}else a.clearColor(t,i,r,n),a.clear(a.COLOR_BUFFER_BIT)}Ei(){const t=[0,0,this.A.canvas.width,this.A.canvas.height];this.A.viewport(...t),dt(this.A,t),this.ui=t,this.ai.length>0&&(this.ai[0]=t)}ct(){const t=this.ii;this.si.ke(t),t.ye(),this.ti=null}gt(){this.vt.gt(),this.si.gt(),this.ri.gt()}get context(){return this.A}get state(){return this.ei}get materialManager(){return this.vt}}const F={readShort:(o,t)=>(F.t.uint16[0]=o[t]<<8|o[t+1],F.t.int16[0]),readUshort:(o,t)=>o[t]<<8|o[t+1],readUshorts(o,t,i){const r=[];for(let n=0;n<i;n++)r.push(F.readUshort(o,t+2*n));return r},readUint(o,t){const i=F.t.uint8;return i[3]=o[t],i[2]=o[t+1],i[1]=o[t+2],i[0]=o[t+3],F.t.uint32[0]},readASCII(o,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(o[t+n]);return r},t:(()=>{const o=new ArrayBuffer(8);return{uint8:new Uint8Array(o),int16:new Int16Array(o),uint16:new Uint16Array(o),uint32:new Uint32Array(o)}})()};function st(o){return o+3&-4}function nt(o,t,i){o[t]=i>>>8&255,o[t+1]=255&i}function B(o,t,i){o[t]=i>>>24&255,o[t+1]=i>>>16&255,o[t+2]=i>>>8&255,o[t+3]=255&i}function ye(o,t,i){for(let r=0;r<i.length;r++)o[t+r]=255&i.charCodeAt(r)}function mt(o,t,i){const r=t+i;let n=0;const h=F.t;for(let a=t;a<r;a+=4)h.uint8[3]=o[a]||0,h.uint8[2]=o[a+1]||0,h.uint8[1]=o[a+2]||0,h.uint8[0]=o[a+3]||0,n=n+(h.uint32[0]>>>0)>>>0;return n>>>0}class we{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 q(o){let t=32,i=0;for(const c of o)c&&(c<t&&(t=c),c>i&&(i=c));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const c of o)c&&r[c]++;const n=new Uint32Array(i+1);let h=0;r[0]=0;for(let c=1;c<=i;c++)h=h+r[c-1]<<1,n[c]=h;const a=new Map;for(let c=0;c<o.length;c++){const u=o[c];if(!u)continue;const f=n[u]++;let d=a.get(u);d||(d=[],a.set(u,d)),d[Ee(f,u)]=c}return{min:t,max:i,table:a}}function vt(o,t){let i=0;for(let r=1;r<=t.max;r++){i|=o.readBits(1)<<r-1;const n=t.table.get(r);if(n&&i<n.length){const h=n[i];if(h!==void 0)return h}}throw Error("Invalid Huffman code")}function Ee(o,t){let i=0;for(let r=0;r<t;r++)i=i<<1|1&o,o>>>=1;return i>>>0}function be(o){if(o.length<2)throw Error("ZLIB data too short");const t=o[0],i=o[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(h,a){const c=[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=h.readBits(1);const v=h.readBits(2);if(v===0){h.alignToByte();const p=h.readBits(16);if((65535&(65535^p))!==h.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let m=0;m<p;m++)a.push(h.readBits(8))}else{if(v!==1&&v!==2)throw Error("Unsupported DEFLATE type");{let p,m;if(v===1){const A=Array(288).fill(0);for(let w=0;w<=143;w++)A[w]=8;for(let w=144;w<=255;w++)A[w]=9;for(let w=256;w<=279;w++)A[w]=7;for(let w=280;w<=287;w++)A[w]=8;p=q(A),m=q(Array(32).fill(5))}else{const A=h.readBits(5)+257,w=h.readBits(5)+1,y=h.readBits(4)+4,b=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],E=Array(19).fill(0);for(let M=0;M<y;M++)E[b[M]]=h.readBits(3);const P=q(E),x=[];for(;x.length<A+w;){const M=vt(h,P);if(M<=15)x.push(M);else if(M===16){const X=h.readBits(2)+3,L=x[x.length-1]||0;for(let ct=0;ct<X;ct++)x.push(L)}else if(M===17){const X=h.readBits(3)+3;for(let L=0;L<X;L++)x.push(0)}else{if(M!==18)throw Error("Invalid code length symbol");{const X=h.readBits(7)+11;for(let L=0;L<X;L++)x.push(0)}}}const N=x.slice(0,A),D=x.slice(A,A+w);p=q(N),m=q(D)}for(;;){const A=vt(h,p);if(A<256)a.push(A);else{if(A===256)break;if(A>256&&A<286){const w=A-257;let y=c[w];const b=u[w];b&&(y+=h.readBits(b));const E=vt(h,m);if(E>=30)throw Error("Invalid distance symbol");let P=f[E];const x=d[E];x&&(P+=h.readBits(x));const N=a.length-P;if(N<0)throw Error("Invalid distance");for(let D=0;D<y;D++)a.push(a[N+D]||0)}else if(A===286||A===287)throw Error("Reserved length symbol")}}}}}}(new we(o.subarray(r)),n),new Uint8Array(n)}function xe(o){const t=F,i=new Uint8Array(o);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),n=t.readUshort(i,12),h=t.readUint(i,16),a=[];let c=44;for(let y=0;y<n;y++){const b=t.readASCII(i,c,4),E=t.readUint(i,c+4),P=t.readUint(i,c+8),x=t.readUint(i,c+12),N=t.readUint(i,c+16);a.push({tag:b,offset:E,compLength:P,origLength:x,checksum:N}),c+=20}for(const y of a){const b=new Uint8Array(i.buffer,y.offset,y.compLength);if(y.compLength===y.origLength)y.data=new Uint8Array(b);else if(y.data=be(b),y.data.length!==y.origLength)if(y.data.length<y.origLength){const E=new Uint8Array(y.origLength);E.set(y.data),y.data=E}else y.data=y.data.subarray(0,y.origLength)}const u=n;let f=1,d=0;for(;f<<1<=u;)f<<=1,d++;const g=16*f,v=16*u-g;let p=12+16*u;const m={};for(const y of a)m[y.tag]=p,p=st(p+y.data.length);const A=new Uint8Array(Math.max(h||0,p));B(A,0,r),nt(A,4,u),nt(A,6,g),nt(A,8,d),nt(A,10,v);let w=12;for(const y of a){ye(A,w,y.tag),w+=4;let b=y.data;if(y.tag==="head"&&b.length>=12){const E=new Uint8Array(b);B(E,8,0),B(A,w,mt(E,0,st(E.length))),w+=4}else B(A,w,mt(b,0,st(b.length))),w+=4;B(A,w,m[y.tag]),w+=4,B(A,w,y.data.length),w+=4}for(const y of a){const b=m[y.tag];A.set(y.data,b)}if(a.find(y=>y.tag==="head")){const y=m.head,b=function(E,P){const x=P+8,N=[E[x],E[x+1],E[x+2],E[x+3]];B(E,x,0);const D=2981146554-(mt(E,0,st(E.length))>>>0)>>>0;return E[x]=N[0],E[x+1]=N[1],E[x+2]=N[2],E[x+3]=N[3],D>>>0}(A,y);B(A,y+8,b)}return A.buffer}const Te={parseTab(o,t,i){const r={tables:[],ids:{},off:t};o=new Uint8Array(o.buffer,t,i),t=0;const n=F,h=n.readUshort,a=h(o,t+=2);t+=2;const c=[];for(let u=0;u<a;u++){const f=h(o,t),d=h(o,t+=2);t+=2;const g=n.readUint(o,t);t+=4;const v=`p${f}e${d}`;let p=c.indexOf(g);if(p===-1){let m;p=r.tables.length,c.push(g);const A=h(o,g);m=A===4?this.parse4(o,g):A===12?this.parse12(o,g):{format:A},r.tables.push(m)}r.ids[v]=p}return r},parse4(o,t){const i=F,r=i.readUshort,n=i.readUshorts,h=t,a=r(o,t+=2);t+=2;const c=r(o,t+=2)>>>1,u={format:4,searchRange:r(o,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,u.entrySelector=r(o,t),t+=2,u.rangeShift=r(o,t),t+=2,u.endCount=n(o,t,c),t+=2*c,t+=2,u.startCount=n(o,t,c),t+=2*c;for(let f=0;f<c;f++)u.idDelta.push(i.readShort(o,t)),t+=2;return u.idRangeOffset=n(o,t,c),t+=2*c,u.glyphIdArray=n(o,t,h+a-t>>1),u},parse12(o,t){const i=F.readUint;i(o,t+=4),i(o,t+=4);const r=i(o,t+=4);t+=4;const n=new Uint32Array(3*r);for(let h=0;h<3*r;h+=3)n[h]=i(o,t+(h<<2)),n[h+1]=i(o,t+(h<<2)+4),n[h+2]=i(o,t+(h<<2)+8);return{format:12,groups:n}}},Re={parseTab(o,t,i){const r=F;t+=18;const n=r.readUshort(o,t);t+=2,t+=16;const h=r.readShort(o,t);t+=2;const a=r.readShort(o,t);t+=2;const c=r.readShort(o,t);t+=2;const u=r.readShort(o,t);return t+=2,t+=6,{unitsPerEm:n,xMin:h,yMin:a,xMax:c,yMax:u,indexToLocFormat:r.readShort(o,t)}}},Ce={parseTab(o,t,i){const r=F;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],h={};for(let a=0;a<n.length;a++){const c=n[a],u=c==="advanceWidthMax"||c==="numberOfHMetrics"?r.readUshort:r.readShort;h[c]=u(o,t+2*a)}return h}},Fe={parseTab(o,t,i,r){const n=F,h=[],a=[],c=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,d=0,g=0;for(;g<u;)f=n.readUshort(o,t+(g<<2)),d=n.readShort(o,t+(g<<2)+2),h.push(f),a.push(d),g++;for(;g<c;)h.push(f),a.push(d),g++;return{aWidth:h,lsBearing:a}}},Dt={cmap:Te,head:Re,hhea:Ce,maxp:{parseTab(o,t,i){const r=F;return r.readUint(o,t),t+=4,{numGlyphs:r.readUshort(o,t)}}},hmtx:Fe,loca:{parseTab(o,t,i,r){const n=F,h=[],a=r.head.indexToLocFormat,c=r.maxp.numGlyphs+1;if(a===0)for(let u=0;u<c;u++)h.push(n.readUshort(o,t+(u<<1))<<1);else if(a===1)for(let u=0;u<c;u++)h.push(n.readUint(o,t+(u<<2)));return h}},glyf:{parseTab(o,t,i,r){const n=[],h=r.maxp.numGlyphs;for(let a=0;a<h;a++)n.push(null);return n},Ri(o,t){const i=F,r=o.Si,n=o.loca;if(n[t]===n[t+1])return null;const h=J.findTable(r,"glyf",o.ki);if(!h)return null;let a=h[0]+n[t];const c={};if(c.noc=i.readShort(r,a),a+=2,c.xMin=i.readShort(r,a),a+=2,c.yMin=i.readShort(r,a),a+=2,c.xMax=i.readShort(r,a),a+=2,c.yMax=i.readShort(r,a),a+=2,c.xMin>=c.xMax||c.yMin>=c.yMax)return null;if(c.noc>0){c.endPts=[];for(let v=0;v<c.noc;v++)c.endPts.push(i.readUshort(r,a)),a+=2;const u=i.readUshort(r,a);if(a+=2,r.length-a<u)return null;a+=u;const f=c.endPts[c.noc-1]+1;c.flags=[];for(let v=0;v<f;v++){const p=r[a];if(a++,c.flags.push(p),8&p){const m=r[a];a++;for(let A=0;A<m;A++)c.flags.push(p),v++}}c.xs=[];for(let v=0;v<f;v++){const p=c.flags[v],m=!!(16&p);2&p?(c.xs.push(m?r[a]:-r[a]),a++):m?c.xs.push(0):(c.xs.push(i.readShort(r,a)),a+=2)}c.ys=[];for(let v=0;v<f;v++){const p=c.flags[v],m=!!(32&p);4&p?(c.ys.push(m?r[a]:-r[a]),a++):m?c.ys.push(0):(c.ys.push(i.readShort(r,a)),a+=2)}let d=0,g=0;for(let v=0;v<f;v++)d+=c.xs[v],g+=c.ys[v],c.xs[v]=d,c.ys[v]=g}else c.parts=[],c.endPts=[],c.flags=[],c.xs=[],c.ys=[];return c}}},J={parse(o){const t=new Uint8Array(o);F.readASCII(t,0,4)==="wOFF"&&(o=xe(o));const i=new Uint8Array(o),r=Dt,n={},h={Si:i,zi:0,ki:0};for(const a in r){const c=a,u=J.findTable(i,c,0);if(u){const[f,d]=u;let g=n[f];g==null&&(g=r[c].parseTab(i,f,d,h),n[f]=g),h[c]=g}}return[h]},findTable(o,t,i){const r=F,n=r.readUshort(o,i+4);let h=i+12;for(let a=0;a<n;a++){const c=r.readASCII(o,h,4);r.readUint(o,h+4);const u=r.readUint(o,h+8),f=r.readUint(o,h+12);if(c===t)return[u,f];h+=16}return null},T:Dt,B:F};class Pe{Di(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const h=this.Li(n);i.push(...h)}else if(n.format===12){const h=this.Ii(n);i.push(...h)}}),[...new Set(i)]):[]}Li(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],h=t.endCount[r];if(n!==65535||h!==65535){for(let a=n;a<=h;a++)if(this.Oi(t,a,r)>0)try{const c=String.fromCodePoint(a);i.push(c)}catch{}}}return i}Ii(t){const i=[];if(!t.groups)return i;for(let r=0;r<t.groups.length;r+=3){const n=t.groups[r],h=t.groups[r+1],a=t.groups[r+2];for(let c=n;c<=h;c++)if(a+(c-n)>0)try{const u=String.fromCodePoint(c);i.push(u)}catch{}}return i}Oi(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 h=t.glyphIdArray[n];if(h!==0)return h+t.idDelta[r]&65535}}return 0}}class Me{constructor(t){l(this,"Bi");l(this,"Hi");l(this,"Z");this.Z=t,this.Bi=document.createElement("canvas"),this.Hi=this.Bi.getContext("2d",{willReadFrequently:!0,alpha:!0})}Gi(t,i,r,n){const h=t.length,a=Math.ceil(Math.sqrt(h)),c=Math.ceil(h/a),u=i.width*a,f=i.height*c;this.Qi(u,f),this.Ni(t,i,a,r,n);const d=this.Z.Pi(u,f,1,{filter:"nearest"});return d.it(this.Bi),{framebuffer:d,columns:a,rows:c}}Qi(t,i){this.Bi.width=t,this.Bi.height=i,this.Bi.style.width=t+"px",this.Bi.style.height=i+"px",this.Hi.imageSmoothingEnabled=!1,this.Bi.style.imageRendering="pixelated",this.Hi.clearRect(0,0,t,i),this.Hi.textBaseline="top",this.Hi.textAlign="left",this.Hi.fillStyle="white"}Ni(t,i,r,n,h){const a=n/h.head.unitsPerEm;for(let c=0;c<t.length;c++){const u=c%r,f=Math.floor(c/r),d=t[c].glyphData;if(!d)continue;const g=d.advanceWidth*a,v=u*i.width,p=f*i.height,m=v+.5*i.width,A=p+.5*i.height,w=Math.round(m-.5*i.width),y=Math.round(A-.5*n),b=w+.5*(i.width-g),E=y+h.hhea.ascender*a;this.Xi(d,b,E,a)}}Xi(t,i,r,n){if(!t||!t.xs||t.noc===0)return;let{xs:h,ys:a,endPts:c,flags:u}=t;if(!(h&&a&&c&&u))return;this.Hi.beginPath();let f=0;for(let d=0;d<c.length;d++){const g=c[d];if(!(g<f)){if(g>=f){const v=i+h[f]*n,p=r-a[f]*n;this.Hi.moveTo(v,p);let m=f+1;for(;m<=g;)if(1&u[m]){const A=i+h[m]*n,w=r-a[m]*n;this.Hi.lineTo(A,w),m++}else{const A=i+h[m]*n,w=r-a[m]*n;if(m+1>g){const b=i+h[f]*n,E=r-a[f]*n;if(1&u[f])this.Hi.quadraticCurveTo(A,w,b,E);else{const P=(A+b)/2,x=(w+E)/2;this.Hi.quadraticCurveTo(A,w,P,x)}break}const y=m+1;if(1&u[y]){const b=i+h[y]*n,E=r-a[y]*n;this.Hi.quadraticCurveTo(A,w,b,E),m=y+1}else{const b=(A+(i+h[y]*n))/2,E=(w+(r-a[y]*n))/2;this.Hi.quadraticCurveTo(A,w,b,E),m=y}}this.Hi.closePath()}f=g+1}}this.Hi.fill()}}class _t{Yi(t,i){const r=t.cmap;if(!r||!r.tables)return 0;let n=0;for(const h of r.tables)if(h.format===4?n=this.ji(i,h):h.format===12&&(n=this.Ki(i,h)),n>0)break;return n}Wi(t,i){const r=i.codePointAt(0);return r===void 0?0:this.Yi(t,r)}Zi(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}qi(t,i){const r=i/t.head.unitsPerEm,n=t.hhea.ascender*r,h=t.hhea.descender*r,a=t.hhea.lineGap*r;return{ascender:n,descender:h,lineGap:a,lineHeight:n-h+a,unitsPerEm:t.head.unitsPerEm,scale:r}}ji(t,i){const r=i.endCount.length;let n=-1;for(let h=0;h<r;h++)if(t<=i.endCount[h]){n=h;break}if(n===-1||t<i.startCount[n])return 0;if(i.idRangeOffset[n]===0)return t+i.idDelta[n]&65535;{const h=i.idRangeOffset[n]/2+(t-i.startCount[n])-(r-n);if(h>=0&&h<i.glyphIdArray.length){const a=i.glyphIdArray[h];return a===0?0:a+i.idDelta[n]&65535}}return 0}Ki(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const h=i.groups[3*n],a=i.groups[3*n+1],c=i.groups[3*n+2];if(t>=h&&t<=a)return c+(t-h)}return 0}}class Ne{constructor(){l(this,"Vi");this.Vi=new _t}Ji(t,i,r){let n=0;const h=this.Vi.qi(r,i),a=h.lineHeight;for(const c of t){const u=this.Vi.Wi(r,c);if(u===0)continue;const f=this.Vi.Zi(r,u)*h.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}}class Ue{constructor(){l(this,"tr");this.tr=new _t}sr(t,i){const r=[],n=new Map;return t.forEach((h,a)=>{const c=h.codePointAt(0)||0,u={character:h,unicode:c,color:this.er(a),glyphData:this.ir(i,h)};r.push(u),n.set(h,u)}),{array:r,map:n}}er(t){return[t%256/255,Math.floor(t/256)%256/255,0]}ir(t,i){const r=i.codePointAt(0)||0,n=this.tr.Yi(t,r);if(n===0)return null;let h=0;t.hmtx&&t.hmtx.aWidth&&n>0&&t.hmtx.aWidth[n]!==void 0&&(h=t.hmtx.aWidth[n]);const a=J.T.glyf.Ri(t,n);return a?{...a,advanceWidth:h}:null}}class pt{constructor(t,i=16){l(this,"rr");l(this,"nr",[]);l(this,"hr",new Map);l(this,"ar");l(this,"cr",16);l(this,"lr",0);l(this,"ur",0);l(this,"dr",{width:0,height:0});l(this,"vr");l(this,"pr");l(this,"gr");l(this,"mr");l(this,"_r");this.cr=i,this.pr=new Pe,this.gr=new Me(t),this.mr=new Ne,this._r=new Ue}async Ar(t){let i;if(t){const r=await fetch(t);if(!r.ok)throw new R(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}else i=await(await fetch("data:font/woff;base64,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")).arrayBuffer();await this.yr(i),this.rr=J.parse(i)[0],await this.wr()}br(t){if(t===void 0)return this.cr;this.cr=t,this.dr=this.mr.Ji(this.nr.map(r=>r.character),this.cr,this.rr);const i=this.gr.Gi(this.nr,this.dr,this.cr,this.rr);this.ar=i.framebuffer,this.lr=i.columns,this.ur=i.rows}async Cr(t){try{const i=await fetch(t);if(!i.ok)throw new R(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.yr(r);const n=J.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.rr=n[0],await this.wr()}catch(i){throw new R("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async yr(t){const i=Date.now();this.vr=new FontFace("CustomFont_"+i,t),await this.vr.load(),document.fonts.add(this.vr)}async wr(){const t=this.pr.Di(this.rr),{array:i,map:r}=this._r.sr(t,this.rr);this.nr=i,this.hr=r,this.dr=this.mr.Ji(t,this.cr,this.rr);const n=this.gr.Gi(this.nr,this.dr,this.cr,this.rr);this.ar=n.framebuffer,this.lr=n.columns,this.ur=n.rows}Mr(t){const i=this.hr.get(t);return i?i.color:[0,0,0]}Fr(t){return Array.from(t).map(i=>{const r=this.hr.get(i);return r?r.color:[0,0,0]})}gt(){this.ar.gt(),document.fonts.delete(this.vr)}get fontFramebuffer(){return this.ar}get characterMap(){return this.hr}get characters(){return this.nr}get textureColumns(){return this.lr}get textureRows(){return this.ur}get maxGlyphDimensions(){return this.dr}get fontSize(){return this.cr}get font(){return this.rr}}class At{constructor(t,i,r){l(this,"Pr");l(this,"$r");l(this,"N");l(this,"X");l(this,"Tr");l(this,"Er");l(this,"Rr");l(this,"Sr");l(this,"kr");this.Rr=t,this.Sr=i,this.kr=r,this.te()}te(){this.Pr=Math.floor(this.Rr.width/this.Sr),this.$r=Math.floor(this.Rr.height/this.kr),this.N=this.Pr*this.Sr,this.X=this.$r*this.kr,this.Tr=Math.floor((this.Rr.width-this.N)/2),this.Er=Math.floor((this.Rr.height-this.X)/2)}zr(t,i){this.Sr=t,this.kr=i,this.te()}get cellWidth(){return this.Sr}get cellHeight(){return this.kr}get cols(){return this.Pr}get rows(){return this.$r}get width(){return this.N}get height(){return this.X}get offsetX(){return this.Tr}get offsetY(){return this.Er}}const Se=/^rgba?\(([^)]+)\)$/i;function yt(o){return Number.isNaN(o)?0:Math.max(0,Math.min(255,o))}function Le(o){if(!o)return null;const t=o.trim().toLowerCase();if(!t)return null;let i=null;return t.startsWith("rgb")&&(i=function(r){const n=Se.exec(r.trim());if(!n)return null;const h=n[1].split(",").map(d=>d.trim());if(h.length<3)return null;const a=yt(parseFloat(h[0])),c=yt(parseFloat(h[1])),u=yt(parseFloat(h[2])),f=h[3]!==void 0?255*Math.max(0,Math.min(1,parseFloat(h[3]))):255;return[a,c,u,Math.round(f)]}(t)),i?i[3]===0?null:i:null}class Xt{constructor(t={}){l(this,"Rr");l(this,"Dr",null);l(this,"Lr",!1);l(this,"Ir");this.Lr=t.overlay??!1,this.Lr&&t.canvas?(this.Dr=t.canvas,this.Rr=this.Or(),this.Ir=!0,this.Br()):t.canvas?(this.Rr=t.canvas,this.Ir=!1):(this.Rr=this.Hr(t.width,t.height),this.Ir=!0),this.Rr.style.imageRendering="pixelated"}Hr(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}Or(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.Dr.getBoundingClientRect();let r=Math.round(i.width),n=Math.round(i.height);if(this.Dr instanceof HTMLVideoElement){const c=this.Dr;(r===0||n===0)&&c.videoWidth>0&&c.videoHeight>0&&(r=c.videoWidth,n=c.videoHeight)}t.width=r,t.height=n,t.style.position="absolute",t.style.pointerEvents="none";const h=window.getComputedStyle(this.Dr);let a=parseInt(h.zIndex||"0",10);return isNaN(a)&&(a=0),t.style.zIndex=""+(a+1),t}Br(){var t;this.Gr(),(t=this.Dr.parentNode)==null||t.insertBefore(this.Rr,this.Dr.nextSibling)}Qr(){const t=[];return this.Lr&&this.Dr instanceof HTMLElement&&(t.push(this.Dr),this.Dr.parentElement&&t.push(this.Dr.parentElement)),this.Rr.parentElement&&t.push(this.Rr.parentElement),t.push(this.Rr),t.push(document.body),t.push(document.documentElement),t}Nr(){const t=this.Qr();for(const i of t){if(!i)continue;const r=Le(window.getComputedStyle(i).backgroundColor);if(r)return r}return[255,255,255,255]}Gr(){if(!this.Dr)return;const t=this.Dr.getBoundingClientRect();let i=this.Dr.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.Rr.style.top=t.top-r.top+"px",this.Rr.style.left=t.left-r.left+"px"}else this.Rr.style.top=t.top+window.scrollY+"px",this.Rr.style.left=t.left+window.scrollX+"px"}Xr(t,i){if(this.Lr){const r=this.Dr.getBoundingClientRect();this.Rr.width=Math.round(r.width),this.Rr.height=Math.round(r.height),this.Gr()}else this.Rr.width=t??this.Rr.width,this.Rr.height=i??this.Rr.height}Yr(){const t=this.Rr.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!0,stencil:!1,powerPreference:"high-performance"});if(!t)throw new R("`textmode.js` requires WebGL2 support.");return t}gt(){const t=this.Rr.getContext("webgl")||this.Rr.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i==null||i.loseContext()}this.Ir&&this.Rr.parentNode&&this.Rr.parentNode.removeChild(this.Rr)}get canvas(){return this.Rr}get targetCanvas(){return this.Dr}get width(){return this.Rr.width}get height(){return this.Rr.height}}function ht(o){return O(parseInt(o,16),0,255)}class U{constructor(t,i,r,n){l(this,"jr");l(this,"Kr");l(this,"r");l(this,"g");l(this,"b");l(this,"a");this.r=O(t,0,255),this.g=O(i,0,255),this.b=O(r,0,255),this.a=O(n,0,255),this.jr=[this.r,this.g,this.b,this.a],this.Kr=[this.r/255,this.g/255,this.b/255,this.a/255]}static Wr(t,i,r,n){if(U.Zr(t))return t;if(Array.isArray(t)){if(t.length<3)throw Error("Component tuples must include at least RGB values.");const[h,a,c]=t,u=t.length===4?t[3]:255;return U.qr(h,a,c,u)}if(typeof t=="string"){const h=t.trim();if(h.length===0)throw Error("Color strings cannot be empty.");return U.Vr(h)}if(typeof t=="number")return typeof i=="number"&&typeof r=="number"?U.qr(t,i,r,n??255):U.Jr(t);throw Error("Unsupported color input passed to TextmodeColor.$from.")}static qr(t,i,r,n=255){return new U(t,i,r,n)}static Jr(t,i=255){return new U(t,t,t,i)}static Vr(t){return new U(...function(i){const r=i.replace(/^#|0x/gi,""),n=(h=r).length===3||h.length===4?h.split("").map(a=>a+a).join(""):h;var h;if(n.length!==6&&n.length!==8)throw Error("Invalid hex color: "+i);return[ht(n.slice(0,2)),ht(n.slice(2,4)),ht(n.slice(4,6)),n.length===8?ht(n.slice(6,8)):255]}(t))}get rgb(){return[this.r,this.g,this.b]}get rgba(){return[...this.jr]}get normalized(){return[...this.Kr]}withAlpha(t){return new U(this.r,this.g,this.b,t)}static Zr(t){return t instanceof U}}const wt=new Map;function Bt(o){wt.set(o.id,o)}function It(o){return wt.get(o)}class Zt{constructor(t,i,r,n,h,a,c,u){l(this,"A");l(this,"Z");l(this,"tn");l(this,"sn");l(this,"en");l(this,"N");l(this,"X");l(this,"q",null);l(this,"rr");l(this,"rn","brightness");l(this,"nn",null);l(this,"Et",0);l(this,"Gt",0);l(this,"Qt",0);l(this,"Rt",0);l(this,"hn","sampled");l(this,"an","fixed");l(this,"Xt",[1,1,1,1]);l(this,"Yt",[0,0,0,1]);l(this,"cn",[0,0,0,1]);l(this,"ln",[[.1,0,0]]);l(this,"un",null);l(this,"fn",new Set);l(this,"dn",[[0,0,0,0]]);l(this,"vn",0);this.A=t,this.Z=i,this.tn=r,this.rr=n,this.sn=h,this.en=a,this.N=c,this.X=u}conversionMode(t){return this.rn=t,this.nn=null,this.q=null,this}gt(){this.A.deleteTexture(this.tn);for(const t of this.fn)t();this.fn.clear()}pn(t){this.fn.add(t)}invert(t=!0){return this.Et=t?1:0,this.q=null,this}flipX(t=!0){return this.Gt=t?1:0,this.q=null,this}flipY(t=!0){return this.Qt=t?1:0,this.q=null,this}charRotation(t){return this.Rt=Ct(t),this.q=null,this}charColorMode(t){return this.hn=t,this.q=null,this}cellColorMode(t){return this.an=t,this.q=null,this}charColor(t,i,r,n){return this.gn(this.Xt,t,i,r,n),this.q=null,this}cellColor(t,i,r,n){return this.gn(this.Yt,t,i,r,n),this.q=null,this}background(t,i,r,n){return this.gn(this.cn,t,i,r,n),this.q=null,this}colorFilter(t){if(!t||t.length===0)return this.vn=0,this.dn=[[0,0,0,0]],this.q=null,this;const i=[];for(const r of t){if(i.length>=64)break;let n=U.Wr(r);i.push(n.normalized)}return this.dn=i,this.vn=i.length,this.q=null,this}characters(t){return this.un=t,this.mn(t),this.q=null,this}_n(t){this.rr=t,this.un&&this.mn(this.un),this.q=null}get texture(){return this.tn}get width(){return this.N}get height(){return this.X}get originalWidth(){return this.sn}get originalHeight(){return this.en}ut(){return this.q||this.ft(),this.q}An(){}ft(){this.An();const t=this.yn(),i=this.wn(),r=t.createShader(i),n=t.createUniforms(i);this.q=this.Z.materialManager.Qe(r,n)}gn(t,i,r,n,h){const a=U.Wr(i,r,n,h);it(t,a.r,a.g,a.b,a.a)}mn(t){const i=this.rr.Fr(t).filter(r=>Array.isArray(r)).slice(0,255);this.ln=i.length>0?i:this.ln}createBaseConversionUniforms(){const t=this.vn>0;return{u_image:this.bn(),u_invert:!!this.Et,u_flipX:!!this.Gt,u_flipY:!!this.Qt,u_charRotation:this.Rt,u_charColorFixed:this.hn==="fixed",u_charColor:this.Xt,u_cellColorFixed:this.an==="fixed",u_cellColor:this.Yt,u_backgroundColor:this.cn,u_charCount:this.ln.length,u_charList:this.ln,u_colorFilterEnabled:t,u_colorFilterSize:t?this.vn:0,u_colorFilterPalette:this.dn}}yn(){if(this.nn&&this.nn.id===this.rn)return this.nn;const t=It(this.rn);if(!t)throw Error(`[textmode.js] Conversion mode "${this.rn}" is not registered. If this mode is provided by an add-on, make sure its plugin is installed before loading sources.`);return this.nn=t,t}wn(){return{renderer:this.Z,gl:this.A,font:this.rr,source:this,gridWidth:this.N,gridHeight:this.X}}}class W extends Zt{constructor(t,i,r,n,h,a,c,u){const f=Math.min(c/h,u/a);super(t,i,r,n,h,a,Math.max(1,Math.floor(h*f)),Math.max(1,Math.floor(a*f)))}static Cn(t,i,r,n,h){const a=t.context,c=a.createTexture();a.bindTexture(a.TEXTURE_2D,c),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,1),tt(a,a.NEAREST,a.NEAREST,a.CLAMP_TO_EDGE,a.CLAMP_TO_EDGE),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,r),a.bindTexture(a.TEXTURE_2D,null);const u=r.naturalWidth??r.width??r.videoWidth??0,f=r.naturalHeight??r.height??r.videoHeight??0;return new W(a,t,c,i,u,f,n,h)}bn(){return this.tn}}class Yt{constructor(t=60){l(this,"xn");l(this,"Mn",null);l(this,"Fn",0);l(this,"Pn",!0);l(this,"$n",0);l(this,"Tn",0);l(this,"En",[]);l(this,"Rn",10);l(this,"Sn",0);this.xn=1e3/t}kn(t){if(!this.Pn)return;this.Fn=performance.now();const i=r=>{if(!this.Pn)return void(this.Mn=null);const n=r-this.Fn;n>=this.xn&&(t(),this.Fn=r-n%this.xn),this.Pn&&(this.Mn=requestAnimationFrame(i))};this.Mn=requestAnimationFrame(i)}zn(){this.Mn&&(cancelAnimationFrame(this.Mn),this.Mn=null)}Dn(){this.Pn&&(this.Pn=!1,this.zn())}Ln(t){this.Pn||(this.Pn=!0,this.kn(t))}In(t,i){if(t===void 0)return this.$n;this.xn=1e3/t,this.Pn&&i&&(this.zn(),this.kn(i))}On(){const t=performance.now();if(this.Tn>0){const i=t-this.Tn;this.En.push(i),this.En.length>this.Rn&&this.En.shift();const r=this.En.reduce((n,h)=>n+h,0)/this.En.length;this.$n=1e3/r}this.Tn=t}get Bn(){return this.Pn}get Hn(){return this.$n}get Gn(){return this.Sn}set Gn(t){this.Sn=t}Qn(){this.Sn++}}class Ot{constructor(t){l(this,"Rr");l(this,"Nn");l(this,"Xn",{x:-1,y:-1});l(this,"Yn",{x:-1,y:-1});l(this,"jn",null);l(this,"Kn",0);l(this,"Wn");l(this,"Zn");l(this,"qn");l(this,"Vn");l(this,"Jn");l(this,"so");l(this,"eo",!1);l(this,"io");l(this,"ro");l(this,"no");l(this,"oo");l(this,"ho");this.Rr=t}ao(t){const i=performance.now()+Math.max(0,t);i>this.Kn&&(this.Kn=i)}co(){return performance.now()<this.Kn}lo(t){const i=this.Rr.canvas;i.style.cursor=t==null||t===""?"":t}Ar(t){this.Nn=t,this.uo()}fo(){if(this.eo)return;const t=this.Rr.canvas;this.Wn=i=>{this.do(i),this.vo(i)},this.Zn=()=>{this.Yn={...this.Xn},this.Xn.x=-1,this.Xn.y=-1,this.jn=null},this.qn=i=>{this.do(i),this.po(i)},this.Vn=i=>{this.do(i),this.mo(i)},this.Jn=i=>{this.do(i),this._o(i)},this.so=i=>{this.do(i),this.Ao(i)},t.addEventListener("mousemove",this.Wn,{passive:!0}),t.addEventListener("mouseleave",this.Zn,{passive:!0}),t.addEventListener("mousedown",this.qn,{passive:!0}),t.addEventListener("mouseup",this.Vn,{passive:!0}),t.addEventListener("click",this.Jn,{passive:!0}),t.addEventListener("wheel",this.so,{passive:!1}),this.eo=!0}yo(){if(!this.eo)return;const t=this.Rr.canvas;t.removeEventListener("mousemove",this.Wn),t.removeEventListener("mouseleave",this.Zn),t.removeEventListener("mousedown",this.qn),t.removeEventListener("mouseup",this.Vn),t.removeEventListener("click",this.Jn),t.removeEventListener("wheel",this.so),this.eo=!1}uo(){if(this.eo)try{if(this.jn){const t=new MouseEvent("mousemove",{clientX:this.jn.x,clientY:this.jn.y,bubbles:!1,cancelable:!1});this.do(t)}else this.Xn.x!==-1&&this.Xn.y!==-1&&(this.Xn.x>=this.Nn.cols||this.Xn.y>=this.Nn.rows)&&(this.Xn.x=-1,this.Xn.y=-1)}catch{this.Xn.x=-1,this.Xn.y=-1}}wo(t){this.io=t}bo(t){this.ro=t}Co(t){this.no=t}xo(t){this.oo=t}Mo(t){this.ho=t}Fo(){return{x:this.Xn.x,y:this.Xn.y}}vo(t){if(this.oo&&!this.co()){const i={position:{...this.Xn},previousPosition:{...this.Yn},originalEvent:t};this.oo(i)}}po(t){if(this.ro&&!this.co()){const i={position:{...this.Xn},previousPosition:{...this.Yn},button:t.button,originalEvent:t};this.ro(i)}}mo(t){if(this.no&&!this.co()){const i={position:{...this.Xn},previousPosition:{...this.Yn},button:t.button,originalEvent:t};this.no(i)}}_o(t){if(this.io&&!this.co()){const i={position:{...this.Xn},previousPosition:{...this.Yn},button:t.button,originalEvent:t};this.io(i)}}Ao(t){if(this.ho&&!this.co()){const i={position:{...this.Xn},previousPosition:{...this.Yn},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.ho(i)}}do(t){const i=this.Rr.canvas;this.Yn={...this.Xn},this.jn={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,h=t.clientY-r.top,a=i.width/r.width,c=h*(i.height/r.height),u=n*a-this.Nn.offsetX,f=c-this.Nn.offsetY,d=Math.floor(u/this.Nn.cellWidth),g=Math.floor(f/this.Nn.cellHeight);d>=0&&d<this.Nn.cols&&g>=0&&g<this.Nn.rows?(this.Xn.x=d,this.Xn.y=g):(this.Xn.x=-1,this.Xn.y=-1)}}const De=Object.freeze(Object.defineProperty({__proto__:null,MouseManager:Ot},Symbol.toStringTag,{value:"Module"}));class zt{constructor(){l(this,"Po",new Map);l(this,"$o",null);l(this,"To",null);l(this,"Eo");l(this,"Ro");l(this,"eo",!1);l(this,"So");l(this,"ko");l(this,"zo",{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"})}fo(){this.eo||(this.Eo=t=>{this.Do(t)},this.Ro=t=>{this.Lo(t)},window.addEventListener("keydown",this.Eo,{passive:!1}),window.addEventListener("keyup",this.Ro,{passive:!1}),this.eo=!0)}yo(){this.eo&&(window.removeEventListener("keydown",this.Eo),window.removeEventListener("keyup",this.Ro),this.eo=!1,this.Po.clear(),this.$o=null,this.To=null)}bo(t){this.So=t}Co(t){this.ko=t}Io(t){const i=this.Oo(t),r=this.Po.get(t)||this.Po.get(i);return(r==null?void 0:r.isPressed)||!1}Bo(){return this.$o}Ho(){return this.To}Go(){const t=[];for(const[i,r]of this.Po)r.isPressed&&t.push(i);return t}Qo(){return{ctrl:this.Io("Control"),shift:this.Io("Shift"),alt:this.Io("Alt"),meta:this.Io("Meta")}}No(){this.Po.clear(),this.$o=null,this.To=null}Do(t){const i=t.key,r=Date.now();this.Po.has(i)||this.Po.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.Po.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.$o=i,this.So)){const h={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.So(h)}}Lo(t){const i=t.key,r=Date.now();this.Po.has(i)||this.Po.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.Po.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.To=i,this.ko){const h={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.ko(h)}}Oo(t){return this.zo[t]||t.toLowerCase()}}const _e=Object.freeze(Object.defineProperty({__proto__:null,KeyboardManager:zt},Symbol.toStringTag,{value:"Module"}));class Vt{constructor(t,i){l(this,"Rr");l(this,"Xo");l(this,"Nn");l(this,"Yo",new Map);l(this,"jo",new Map);l(this,"Ko",new Map);l(this,"Wo",null);l(this,"Zo");l(this,"qo");l(this,"Vo");l(this,"Jo");l(this,"th");l(this,"sh");l(this,"eo",!1);l(this,"eh");l(this,"ih");l(this,"rh");l(this,"nh");l(this,"oh");l(this,"hh");l(this,"ah");l(this,"uh");l(this,"fh");l(this,"dh");l(this,"ph",320);l(this,"gh",350);l(this,"mh",10);l(this,"_h",550);l(this,"Ah",14);l(this,"yh",48);l(this,"wh",650);l(this,"bh",.02);l(this,"Ch",2);l(this,"xh",600);l(this,"Mh",0);l(this,"Fh",null);this.Rr=t,this.Xo=i;const r=this.Rr.canvas;this.Zo=r.style.touchAction,this.qo=r.style.userSelect,r.style.touchAction||(r.style.touchAction="none"),r.style.userSelect||(r.style.userSelect="none")}Ar(t){this.Nn=t,this.uo()}fo(){if(this.eo)return;const t=this.Rr.canvas;this.Vo=i=>{this.Ph(i)},this.Jo=i=>{this.$h(i)},this.th=i=>{this.Th(i)},this.sh=i=>{this.Eh(i)},t.addEventListener("touchstart",this.Vo,{passive:!1}),t.addEventListener("touchmove",this.Jo,{passive:!1}),t.addEventListener("touchend",this.th,{passive:!1}),t.addEventListener("touchcancel",this.sh,{passive:!1}),this.eo=!0}yo(){if(!this.eo)return;const t=this.Rr.canvas;t.removeEventListener("touchstart",this.Vo),t.removeEventListener("touchmove",this.Jo),t.removeEventListener("touchend",this.th),t.removeEventListener("touchcancel",this.sh),this.eo=!1,this.Wo=null,this.Yo.clear(),this.jo.clear(),this.Ko.forEach(i=>{i.longPressTimer!==null&&window.clearTimeout(i.longPressTimer)}),this.Ko.clear(),this.Fh=null,this.Mh=0,t.style.touchAction=this.Zo,t.style.userSelect=this.qo}uo(){if(!this.Nn||this.Yo.size===0)return;const t=new Map;for(const i of this.Yo.values()){const r=this.Rh(i.clientX,i.clientY,i.id,i);t.set(i.id,r)}this.Yo=t}Sh(){return Array.from(this.Yo.values()).map(t=>({...t}))}kh(t){this.eh=t}xo(t){this.ih=t}zh(t){this.rh=t}Dh(t){this.nh=t}Lh(t){this.oh=t}Ih(t){this.hh=t}Oh(t){this.ah=t}Bh(t){this.uh=t}Hh(t){this.fh=t}Gh(t){this.dh=t}Ph(t){var n;if(!this.Nn)return;t.preventDefault(),(n=this.Xo)==null||n.ao(this.xh);const i=performance.now(),r=this.Qh(t.changedTouches);for(const h of r){const a=this.Yo.get(h.id);a&&this.jo.set(h.id,this.Nh(a)),this.Yo.set(h.id,h);const c={id:h.id,startPosition:h,lastPosition:h,startTime:i,lastTime:i,longPressTimer:null,longPressFired:!1};this.ah&&(c.longPressTimer=window.setTimeout(()=>{const u=this.Yo.get(h.id);u&&(c.longPressFired=!0,this.ah({touch:this.Nh(u),duration:performance.now()-c.startTime,originalEvent:t}))},this._h)),this.Ko.set(h.id,c),this.eh&&this.eh(this.Xh(h,t,void 0,i))}this.Yo.size===2&&this.Yh()}$h(t){var n;if(!this.Nn)return;t.preventDefault(),(n=this.Xo)==null||n.ao(this.xh);const i=performance.now(),r=this.Qh(t.changedTouches);for(const h of r){const a=this.Yo.get(h.id),c=a?this.Nh(a):void 0;c&&this.jo.set(h.id,c),this.Yo.set(h.id,h);const u=this.Ko.get(h.id);u&&(u.lastPosition=h,u.lastTime=i,c)&&j(c.clientX,c.clientY,h.clientX,h.clientY)>this.Ah&&u.longPressTimer!==null&&(window.clearTimeout(u.longPressTimer),u.longPressTimer=null),this.ih&&this.ih(this.Xh(h,t,c,i))}this.Yo.size===2?this.jh(t):this.Wo=null}Th(t){if(!this.Nn)return;t.preventDefault();const i=performance.now(),r=this.Qh(t.changedTouches);for(const n of r){const h=this.Yo.get(n.id),a=h?this.Nh(h):void 0,c=this.Ko.get(n.id);c&&c.longPressTimer!==null&&(window.clearTimeout(c.longPressTimer),c.longPressTimer=null),this.rh&&this.rh(this.Xh(n,t,a,i)),c&&this.Kh(c,t),this.Ko.delete(n.id),this.jo.delete(n.id),this.Yo.delete(n.id)}this.Yo.size<2&&(this.Wo=null)}Eh(t){if(!this.Nn)return;t.preventDefault();const i=performance.now(),r=this.Qh(t.changedTouches);for(const n of r){const h=this.Yo.get(n.id),a=h?this.Nh(h):void 0,c=this.Ko.get(n.id);c&&c.longPressTimer!==null&&(window.clearTimeout(c.longPressTimer),c.longPressTimer=null),this.nh&&this.nh(this.Xh(n,t,a,i)),this.Ko.delete(n.id),this.jo.delete(n.id),this.Yo.delete(n.id)}this.Yo.size<2&&(this.Wo=null)}Qh(t){const i=[];for(let r=0;r<t.length;r+=1){const n=t.item(r);n&&i.push(this.Wh(n))}return i}Wh(t){return this.Rh(t.clientX,t.clientY,t.identifier,{id:t.identifier,x:-1,y:-1,clientX:t.clientX,clientY:t.clientY,pressure:t.force,radiusX:t.radiusX,radiusY:t.radiusY,rotationAngle:t.rotationAngle})}Rh(t,i,r,n){const h=this.Rr.canvas,a=h.getBoundingClientRect(),c=t-a.left,u=i-a.top,f=h.width/a.width,d=u*(h.height/a.height),g=c*f-this.Nn.offsetX,v=d-this.Nn.offsetY,p=Math.floor(g/this.Nn.cellWidth),m=Math.floor(v/this.Nn.cellHeight),A=p>=0&&p<this.Nn.cols&&m>=0&&m<this.Nn.rows;return{id:r,x:A?p:-1,y:A?m:-1,clientX:t,clientY:i,pressure:n.pressure,radiusX:n.radiusX,radiusY:n.radiusY,rotationAngle:n.rotationAngle}}Xh(t,i,r,n){const h=this.Ko.get(t.id),a=Array.from(this.jo.values()).map(f=>this.Nh(f)),c=Array.from(this.Yo.values()).map(f=>this.Nh(f)),u=this.Qh(i.changedTouches);return{touch:this.Nh(t),previousTouch:r?this.Nh(r):void 0,touches:c,previousTouches:a,changedTouches:u,deltaTime:h?n-h.lastTime:0,originalEvent:i}}Yh(){if(this.Yo.size!==2)return void(this.Wo=null);const t=Array.from(this.Yo.values()),[i,r]=t,n=j(i.x,i.y,r.x,r.y),h=Rt(i.clientX,i.clientY,r.clientX,r.clientY);this.Wo={ids:[i.id,r.id],initialDistance:Math.max(n,1e-4),initialAngle:h,lastScale:1,lastRotation:0}}jh(t){if(this.Wo||this.Yh(),!this.Wo)return;const[i,r]=this.Wo.ids,n=this.Yo.get(i),h=this.Yo.get(r);if(!n||!h)return;const a=j(n.x,n.y,h.x,h.y)/this.Wo.initialDistance,c=a-this.Wo.lastScale;this.fh&&Math.abs(c)>this.bh&&(this.fh({touches:[this.Nh(n),this.Nh(h)],scale:a,deltaScale:c,center:this.Zh(n,h),originalEvent:t}),this.Wo.lastScale=a);let u=Rt(n.clientX,n.clientY,h.clientX,h.clientY)-this.Wo.initialAngle;u=(u+180)%360-180;const f=u-this.Wo.lastRotation;this.dh&&Math.abs(f)>this.Ch&&(this.dh({touches:[this.Nh(n),this.Nh(h)],rotation:u,deltaRotation:f,center:this.Zh(n,h),originalEvent:t}),this.Wo.lastRotation=u)}Zh(t,i){const r=(t.clientX+i.clientX)/2,n=(t.clientY+i.clientY)/2,h=this.Rh(r,n,-1,{id:-1,x:-1,y:-1,clientX:r,clientY:n});return{x:h.x,y:h.y}}Kh(t,i){const r=performance.now(),n=r-t.startTime,h=j(t.startPosition.clientX,t.startPosition.clientY,t.lastPosition.clientX,t.lastPosition.clientY);if(!t.longPressFired&&n<=this.ph&&h<=this.mh)this.qh(t.lastPosition,r)&&this.hh?this.hh({touch:this.Nh(t.lastPosition),taps:2,originalEvent:i}):this.oh&&this.oh({touch:this.Nh(t.lastPosition),taps:1,originalEvent:i});else if(!t.longPressFired&&n<=this.wh&&h>=this.yh){const a={x:t.lastPosition.clientX-t.startPosition.clientX,y:t.lastPosition.clientY-t.startPosition.clientY},c=Math.max(Math.hypot(a.x,a.y),1e-4),u={x:a.x/c,y:a.y/c},f={x:a.x/n,y:a.y/n};this.uh&&this.uh({touch:this.Nh(t.lastPosition),direction:u,distance:c,velocity:f,originalEvent:i})}this.Mh=r,this.Fh=this.Nh(t.lastPosition)}qh(t,i){return!!this.Fh&&!(i-this.Mh>this.gh)&&j(t.clientX,t.clientY,this.Fh.clientX,this.Fh.clientY)<=this.mh}Nh(t){return{...t}}}const Xe=Object.freeze(Object.defineProperty({__proto__:null,TouchManager:Vt},Symbol.toStringTag,{value:"Module"}));class Be{constructor(t,i){l(this,"A");l(this,"Vh");l(this,"$n",null);l(this,"Jh",0);l(this,"ta",!1);l(this,"sa",[]);l(this,"ea",-1);this.A=t,this.Vh=i}get isPreloaded(){return this.ta}get totalFrames(){return this.Jh}get frameRate(){return this.$n}get textures(){return this.sa}dispose(){this.ia(),this.sa=[],this.$n=null,this.Jh=0,this.ta=!1,this.ea=-1}async preload(t,i){var r;try{if(t<=0)throw Error("Video preload requires a frameRate greater than 0.");const n=this.Vh.duration;if(!isFinite(n)||n<=0)throw Error("Video duration is invalid, cannot preload frames.");const h=Math.max(1,Math.ceil(n*t));return this.ra(t,h),await this.na(t,i)?(this.oa("captureStream",i),"captureStream"):(await this.ha(t,i),this.oa("seeking",i),"seeking")}catch(n){const h=n instanceof Error?n:Error(n+"");throw(r=i==null?void 0:i.onError)==null||r.call(i,h),this.dispose(),h}}ra(t,i){this.ia(),this.$n=t,this.Jh=i,this.sa=[],this.ta=!1,this.ea=-1}oa(t,i){var r;if(this.sa.length===0)throw Error(`Video preload via ${t} completed but produced 0 frames.`);this.Jh=this.sa.length,this.ta=!0,this.ea=-1,this.Vh.pause(),this.Vh.currentTime=0,i!=null&&i.onProgress&&i.onProgress({percent:100,loadedFrames:this.Jh,totalFrames:this.Jh,strategy:t}),(r=i==null?void 0:i.onComplete)==null||r.call(i,{totalFrames:this.Jh,strategy:t})}aa(t){const i=this.A,r=i.createTexture();return i.bindTexture(i.TEXTURE_2D,r),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,1),tt(i,i.LINEAR,i.LINEAR,i.CLAMP_TO_EDGE,i.CLAMP_TO_EDGE),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.bindTexture(i.TEXTURE_2D,null),r}ca(t,i){if(!(i!=null&&i.onProgress)||this.Jh===0)return;const r=Math.min(99,Math.floor(this.sa.length/this.Jh*100)),n=10*Math.floor(r/10);n>this.ea&&(this.ea=n,i.onProgress({percent:r,loadedFrames:this.sa.length,totalFrames:this.Jh,strategy:t}))}async na(t,i){const r=globalThis,n=r==null?void 0:r.MediaStreamTrackProcessor,h=this.Vh.captureStream;if(typeof n!="function"||typeof h!="function")return!1;let a,c=null;try{const u=h.call(this.Vh);if(a=u.getVideoTracks()[0],!a)return u.getTracks().forEach(g=>g.stop()),!1;if(c=new n({track:a}).readable.getReader(),this.Vh.currentTime=0,this.Vh.muted=!0,await this.Vh.play().catch(()=>{}),this.Vh.paused)return!1;const f=1e6/t;let d=0;for(;this.sa.length<this.Jh;){const g=await c.read();if(g.done)break;const v=g.value;if(v)try{const p=typeof v.timestamp=="number"?v.timestamp:d;(this.sa.length===0||p>=d)&&(this.sa.push(this.aa(v)),d=p+f,this.ca("captureStream",i))}finally{v.close()}}return c.releaseLock(),a.stop(),c=null,a=void 0,this.Vh.pause(),this.Vh.currentTime=0,this.sa.length!==0}catch{return this.ia(),this.sa=[],this.ea=-1,!1}finally{if(c)try{await c.cancel()}catch{}a&&a.stop(),this.Vh.pause(),this.Vh.currentTime=0}}async ha(t,i){const r=1/t,n=this.Jh,h=this.Vh;h.pause();for(let a=0;a<n;a++){const c=Math.min(h.duration,a*r);await this.la(c),this.sa.push(this.aa(h)),this.ca("seeking",i)}h.currentTime=0}la(t){return new Promise((i,r)=>{const n=this.Vh,h=()=>{n.removeEventListener("seeked",a),n.removeEventListener("error",c)},a=()=>{h(),i()},c=()=>{h(),r(Error("Video seek failed while preloading frames."))};n.addEventListener("seeked",a,{once:!0}),n.addEventListener("error",c,{once:!0});const u=isFinite(n.duration)?n.duration:t,f=Math.min(Math.max(t,0),u);if(Math.abs(n.currentTime-f)<1e-4)return h(),void i();n.currentTime=f})}ia(){for(const t of this.sa)this.A.deleteTexture(t)}}class ot extends Zt{constructor(i,r,n,h,a,c,u,f,d){const g=c/u;let v,p;g>1?(v=f,p=Math.round(f/g)):(p=d,v=Math.round(d*g));super(i,r,n,h,c,u,v,p);l(this,"Vh");l(this,"ua",0);l(this,"fa",null);this.Vh=a}gt(){var i;super.gt(),(i=this.fa)==null||i.dispose(),this.fa=null,this.Vh.pause(),this.Vh.src="",this.Vh.load()}da(){var i;if(!((i=this.fa)!=null&&i.isPreloaded)&&this.Vh.readyState>=this.Vh.HAVE_CURRENT_DATA){const r=this.A;r.bindTexture(r.TEXTURE_2D,this.tn),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.Vh),r.bindTexture(r.TEXTURE_2D,null)}}bn(){var r,n;const i=(r=this.fa)==null?void 0:r.textures;return i&&i.length>0&&((n=this.fa)!=null&&n.isPreloaded)?i[this.ua%i.length]:this.tn}ut(){return this.q=null,super.ut()}An(){this.da()}frame(i){var n,h;const r=((n=this.fa)==null?void 0:n.totalFrames)??0;return(h=this.fa)!=null&&h.isPreloaded&&i!==void 0&&r>0&&(this.ua=(i%r+r)%r,this.q=null),this}static async Cn(i,r,n,h,a,c){const u=i.context,f=c==null?void 0:c.frameRate;let d;d=document.createElement("video"),d.crossOrigin="anonymous",d.loop=!0,d.muted=!0,d.playsInline=!0,await new Promise((A,w)=>{d.addEventListener("loadedmetadata",()=>A(),{once:!0}),d.addEventListener("error",y=>{var E;const b=y.target;w(Error("Failed to load video: "+(((E=b.error)==null?void 0:E.message)||"Unknown error")))},{once:!0}),d.src=n});const g=u.createTexture();u.bindTexture(u.TEXTURE_2D,g),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,1),tt(u,u.LINEAR,u.LINEAR,u.CLAMP_TO_EDGE,u.CLAMP_TO_EDGE),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,u.RGBA,u.UNSIGNED_BYTE,d),u.bindTexture(u.TEXTURE_2D,null);const v=d.videoWidth,p=d.videoHeight,m=new ot(u,i,g,r,d,v,p,h,a);return f&&f>0&&(m.fa=new Be(u,d),await m.fa.preload(f,c),m.ua=0),m}async play(){await this.Vh.play()}pause(){this.Vh.pause()}stop(){this.Vh.pause(),this.Vh.currentTime=0}speed(i){return this.Vh.playbackRate=i,this}loop(i=!0){return this.Vh.loop=i,this}time(i){return this.Vh.currentTime=i,this}volume(i){return this.Vh.volume=Math.max(0,Math.min(1,i)),this}get texture(){return this.tn}get width(){return this.N}get height(){return this.X}get originalWidth(){return this.sn}get originalHeight(){return this.en}get videoElement(){return this.Vh}get currentTime(){return this.Vh.currentTime}get duration(){return this.Vh.duration}get isPlaying(){return!this.Vh.paused&&!this.Vh.ended}get totalFrames(){var i;return((i=this.fa)==null?void 0:i.totalFrames)??0}}const Ie=o=>class extends o{va(t,i,r,n){if(U.Zr(t))return t;if(typeof t=="number"||typeof t=="string")return this.color(t,i,r,n);throw Error("Unsupported color input passed to color-capable method.")}rotate(t=0,i=0,r=0){this.Z.state.Vt(t),this.Z.state.Jt(i),this.Z.state.ts(r)}rotateX(t){this.Z.state.Vt(t)}rotateY(t){this.Z.state.Jt(t)}rotateZ(t){this.Z.state.ts(t)}translate(t=0,i=0,r=0){this.Z.state.ss(t,i,r)}translateX(t){this.Z.state.ss(t,0,0)}translateY(t){this.Z.state.ss(0,t,0)}translateZ(t){this.Z.state.ss(0,0,t)}push(){this.Z.state.ot()}pop(){this.Z.state.ht()}color(t,i,r,n){return U.Wr(t,i,r,n)}rect(t=1,i=1){this.Z.wi(t,i)}point(){this.Z.wi(1,1)}line(t,i,r,n){this.Z.bi(t,i,r,n)}lineWeight(t){this.Z.state.Zt(t)}background(t,i,r,n=255){const h=this.va(t,i,r,n);this.Z.$i(h.r,h.g,h.b,h.a)}char(t){const i=Array.from(t);if(i.length===0)throw Error("char() requires at least one character.");this.Z.state.hs(this.rr.Mr(i[0]))}charColor(t,i,r,n){const h=this.va(t,i,r,n);this.Z.state.cs(h.r,h.g,h.b,h.a)}cellColor(t,i,r,n){const h=this.va(t,i,r,n);this.Z.state.ls(h.r,h.g,h.b,h.a)}flipX(t){this.Z.state.us(t)}flipY(t){this.Z.state.fs(t)}charRotation(t){this.Z.state.vs(t)}invert(t){this.Z.state.ds(t)}clear(){this.Z.ye(0,0,0,0)}ellipse(t,i){this.Z.Ci(t/2,i/2)}triangle(t,i,r,n,h,a){this.Z.xi(t,i,r,n,h,a)}bezierCurve(t,i,r,n,h,a,c,u){this.Z.Mi(t,i,r,n,h,a,c,u)}arc(t,i,r,n){this.Z.Fi(t/2,i/2,r,n)}shader(t){this.Z.gi(t)}setUniform(t,i){this.Z.O(t,i)}setUniforms(t){this.Z.mi(t)}async createFilterShader(t){if(typeof t=="string"&&(t.startsWith("./")||t.startsWith("../")||t.endsWith(".frag")||t.endsWith(".glsl"))){const i=await fetch(t);if(!i.ok)throw Error(`Failed to load shader from ${t}: ${i.statusText}`);const r=await i.text();return this.Z._i(r)}return this.Z._i(t)}async createShader(t,i){const r=async a=>{if(a.startsWith("./")||a.startsWith("../")||a.endsWith(".vert")||a.endsWith(".frag")||a.endsWith(".glsl")){const c=await fetch(a);if(!c.ok)throw Error(`Failed to load shader from ${a}: ${c.statusText}`);return c.text()}return a},[n,h]=await Promise.all([r(t),r(i)]);return this.Z.pi(n,h)}createFramebuffer(t){return this.Z.Pi(t.width??this.grid.cols,t.height??this.grid.rows,t.attachments??3)}image(t,i,r){this.Z.Ai(t,i,r),t instanceof z&&this.Z.ct()}ortho(){this.Z.state.gs(!0)}async loadImage(t){if(typeof t!="string"){const h=W.Cn(this.Z,this.rr,t,this.Nn.cols,this.Nn.rows);return this.pa(h),h}const i=t,r=await new Promise((h,a)=>{const c=new Image;c.crossOrigin="anonymous",c.onload=()=>h(c),c.onerror=u=>a(u),c.src=i}),n=W.Cn(this.Z,this.rr,r,this.Nn.cols,this.Nn.rows);return this.pa(n),n}async loadVideo(t,i){const r=await ot.Cn(this.Z,this.rr,t,this.Nn.cols,this.Nn.rows,i);return this.pa(r),r}},Ze=o=>class extends o{async loadFont(t){return this.rr.Cr(t).then(()=>{const i=this.rr.maxGlyphDimensions;this.Nn.zr(i.width,i.height),this.ga.resize(this.Nn.cols,this.Nn.rows),this.Z.Ei(),this.Xo.uo(),this.ma.uo();for(const r of this._a)r._n(this.rr)})}fontSize(t){if(!ut.m(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.rr.fontSize===t)return;this.rr.br(t);const i=this.rr.maxGlyphDimensions;this.Nn.zr(i.width,i.height),this.ga.resize(this.Nn.cols,this.Nn.rows),this.Z.Ei(),this.Xo.uo(),this.ma.uo()}},Ye=o=>class extends o{get frameCount(){return this.ya.Gn}set frameCount(t){this.ya.Gn=t}frameRate(t){return t===void 0?this.ya.Hn:this.ya.In(t,()=>this.wa())}noLoop(){this.ya.Dn()}loop(){this.ya.Ln(()=>this.wa())}redraw(t=1){if(ut.m(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.wa()}isLooping(){return this.ya.Bn}},Oe=o=>class extends o{constructor(...t){super(...t)}mouseClicked(t){this.Xo.wo(t)}mousePressed(t){this.Xo.bo(t)}mouseReleased(t){this.Xo.Co(t)}mouseMoved(t){this.Xo.xo(t)}mouseScrolled(t){this.Xo.Mo(t)}get mouse(){return this.Xo.Fo()}cursor(t){this.Xo.lo(t)}},ze=o=>class extends o{constructor(...t){super(...t)}touchStarted(t){this.ma.kh(t)}touchMoved(t){this.ma.xo(t)}touchEnded(t){this.ma.zh(t)}touchCancelled(t){this.ma.Dh(t)}tap(t){this.ma.Lh(t)}doubleTap(t){this.ma.Ih(t)}longPress(t){this.ma.Oh(t)}swipe(t){this.ma.Bh(t)}pinch(t){this.ma.Hh(t)}rotateGesture(t){this.ma.Gh(t)}get touches(){return this.ma.Sh()}},Ve=o=>class extends o{constructor(...t){super(...t)}keyPressed(t){this.ba.bo(t)}keyReleased(t){this.ba.Co(t)}isKeyPressed(t){return this.ba.Io(t)}get lastKeyPressed(){return this.ba.Bo()}get lastKeyReleased(){return this.ba.Ho()}get pressedKeys(){return this.ba.Go()}get modifierState(){return this.ba.Qo()}};class Ge{constructor(t){l(this,"Ca");l(this,"xa",new Map);l(this,"Ma",[]);l(this,"Fa",new Map);l(this,"Pa",new Map);this.Ca=t}async $a(t){for(const i of t){if(this.xa.has(i.name))return void console.warn(`[textmode.js] Plugin "${i.name}" is already installed.`);const r=this.Ta(i.name);try{await i.install(this.Ca,r)}catch(n){throw this.Ea(i.name),n}this.xa.set(i.name,i),this.Ma.push(i.name)}}async Ra(t){const i=this.xa.get(t);if(!i)return;const r=this.Ta(t);i.uninstall&&await i.uninstall(this.Ca,r),this.xa.delete(t),this.Ma.splice(this.Ma.indexOf(t),1),this.Ea(t)}Sa(){this.ka(this.Fa)}za(){this.ka(this.Pa)}async Da(){const t=[...this.xa.keys()];for(const i of t)await this.Ra(i)}Ta(t){return{renderer:this.Ca.Z,font:this.Ca.rr,grid:this.Ca.Nn,canvas:this.Ca.Rr,drawFramebuffer:this.Ca.ga,asciiFramebuffer:this.Ca.La,registerPreDrawHook:i=>this.Ia(this.Fa,t,i),registerPostDrawHook:i=>this.Ia(this.Pa,t,i)}}Ia(t,i,r){const n=t.get(i)??new Set;return n.add(r),t.set(i,n),()=>{const h=t.get(i);h&&(h.delete(r),h.size===0&&t.delete(i))}}Ea(t){this.Fa.delete(t),this.Pa.delete(t)}ka(t){for(const i of this.Ma){const r=t.get(i);r&&r.forEach(n=>n())}}}const $=`#version 300 es
11
+ in vec2 A0;in vec2 A1;out vec2 v_uv;void main(){v_uv=A1;gl_Position=vec4(A0,0.,1.);}`;class Gt{constructor(){l(this,"Oa",new Map);l(this,"Ba",[]);l(this,"Ha",0);l(this,"Ga",0);l(this,"Qa")}get Na(){return this.Ha}get Xa(){if(this.Ha===0)return 0;let t=0;for(const i of this.Ba){const r=this.Oa.get(i);r&&(t+=Math.min(1,Math.max(0,r.progress))*r.weight)}return Math.min(1,t/this.Ha)}Ya(t){this.Qa=t}ja(t,i=1){const r=`phase-${this.Ba.length+1}-${Date.now()}`,n={id:r,label:t,weight:Math.max(.001,i),progress:0,status:"running"};return this.Oa.set(r,n),this.Ba.push(r),this.Ha+=n.weight,r}Ka(t,i){const r=this.Oa.get(t);if(!r)return;r.progress=Math.max(0,Math.min(1,i)),r.status=r.progress>=1?"complete":"running";const n=this.Xa;Math.abs(n-this.Ga)>.001&&(this.Ga=n,this.Qa&&this.Qa(n))}Wa(t){const i=this.Oa.get(t);i&&(i.progress=1,i.status="complete",this.Ka(t,1))}Za(t){const i=this.Oa.get(t);i&&(i.status="failed")}qa(){return this.Ba.map(t=>{const i=this.Oa.get(t);return i?{id:i.id,label:i.label,weight:i.weight,progress:i.progress,status:i.status}:{id:t,label:t,weight:1,progress:0,status:"pending"}})}}class Wt{constructor(t="active"){l(this,"Va");l(this,"Ja","");l(this,"tc","");this.Va=t}get sc(){return this.Va}get ec(){return this.Va!=="disabled"}get rc(){return this.Va==="active"||this.Va==="transitioning"||this.Va==="error"}get nc(){return this.Ja}get oc(){return this.tc}hc(){this.Va!=="done"&&this.Va!=="transitioning"||(this.Va="active")}ac(){this.Va!=="disabled"&&(this.Va="done")}cc(){this.Va!=="disabled"&&(this.Va="transitioning")}lc(){this.Va==="transitioning"&&(this.Va="done")}uc(t){this.Va!=="disabled"&&(this.Va="error",t instanceof Error?(this.Ja=t.message,this.tc=t.stack||""):(this.Ja=t,this.tc=""))}fc(){this.Va="disabled"}}class kt{constructor(t,i){l(this,"dc",0);l(this,"vc",1);l(this,"gc");l(this,"mc");this.gc=t,this.mc=i}get _c(){return this.vc}get yc(){return this.vc<1}kn(){this.gc!=="none"&&this.mc>0&&(this.dc=performance.now())}it(){if(this.gc==="none"||this.mc===0)return this.vc=1,!1;const t=performance.now()-this.dc,i=Math.min(1,t/this.mc);return i>=1?(this.vc=0,!0):(this.vc=1-i,!1)}te(){this.vc=1,this.dc=0}}function Et(o,t){const i=o.tone??"auto";let r="dark";return i==="light"||i==="dark"?r=i:t&&(r=function(n){if(!n)return 0;const[h,a,c]=n.map(f=>f/255),u=f=>f<=.04045?f/12.92:Math.pow((f+.055)/1.055,2.4);return .2126*u(h)+.7152*u(a)+.0722*u(c)}(t)>.5?"light":"dark"),{mode:r,background:t,textColor:r==="light"?"#1A1A1A":"#F8F8F8",subtleColor:r==="light"?"#4A4A4A":"#C0C0C0"}}function Ht(o){return o.mode==="light"?["#E91E63","#9C27B0","#FF6F00"]:["#8EF9F3","#F15BB5","#FF9B71"]}function jt(o,t){return o.length?o.map(i=>t.color(i)):[t.color("#FFFFFF")]}const We=({textmodifier:o,grid:t,progress:i,frameCount:r,message:n,palette:h,theme:a,phases:c,transitionOpacity:u,isError:f,errorMessage:d})=>{const g="|/-\\",v=Math.floor(r/6)%4,p=o.color(a.textColor),m=Math.floor(255*u),A=o.color(p.r,p.g,p.b,m);if(o.charColor(A),o.cellColor(0,0,0,0),f){const w=o.color(a.mode==="light"?"#D32F2F":"#FF6B6B",m);o.charColor(w),o.push(),o.translate(0,-2,0),o.char("X"),o.rect(1,1),o.pop();const y="SETUP ERROR",b=-Math.floor(y.length/2);o.push(),o.translate(b,0,0);for(const E of y)o.char(E),o.rect(1,1),o.translateX(1);if(o.pop(),d){const E=o.color(a.subtleColor),P=o.color(E.r,E.g,E.b,m);o.charColor(P);const x=Math.floor(.8*t.cols),N=d.split(" "),D=[];let M="";for(const L of N)(M+" "+L).length<=x?M=M?M+" "+L:L:(M&&D.push(M),M=L);M&&D.push(M);const X=D.slice(0,3);D.length>3&&(X[2]=X[2].substring(0,x-3)+"..."),X.forEach((L,ct)=>{const ri=-Math.floor(L.length/2);o.push(),o.translate(ri,3+ct,0);for(const si of L)o.char(si),o.rect(1,1),o.translateX(1);o.pop()})}return}if(o.push(),o.translate(0,0,0),o.char(g[v]),o.rect(1,1),o.pop(),i>0||c.some(w=>w.status!=="pending")){const w=Math.max(6,Math.floor(.6*t.cols)),y=-Math.floor(w/2),b=Math.floor(w*i),E=h.length?h:[o.color("#FFFFFF")];o.push(),o.translate(y,3,0);for(let P=0;P<w;P++){const x=P<b?"*":".",N=E[P%E.length],D=o.color(N.r,N.g,N.b,m);o.charColor(D),o.char(x),o.rect(1,1),o.translateX(1)}o.pop()}if(n){const w=o.color(a.subtleColor),y=o.color(w.r,w.g,w.b,m);o.charColor(y);const b=-Math.floor(n.length/2);o.push(),o.translate(b,5,0);for(const E of n)o.char(E),o.rect(1,1),o.translateX(1);o.pop()}},ke={message:"LOADING...",tone:"auto",transition:"fade",transitionDuration:500};class He{constructor(t,i,r){this.wc=t,this.id=i,this.label=r}report(t){this.wc.Ka(this.id,t)}complete(){this.wc.Wa(this.id)}fail(t){this.wc.Za(this.id)}async track(t){try{const i=typeof t=="function"?await t():await t;return this.complete(),i}catch(i){throw this.fail(),i}}}class Qt{constructor(t,i,r){l(this,"Ca");l(this,"l");l(this,"bc");l(this,"wc");l(this,"Cc");l(this,"xc");l(this,"Mc");l(this,"Fc");l(this,"Pc");l(this,"$c");l(this,"Z");l(this,"Tc",[]);l(this,"Ec");l(this,"Rc",performance.now());l(this,"Sc",0);l(this,"kc",!1);l(this,"zc",!1);l(this,"Oc");this.Ca=t,this.l={...ke,...i??{}},this.bc=new Wt("active"),this.wc=new Gt,this.Cc=new kt(this.l.transition,this.l.transitionDuration),this.xc=new Yt(60),this.Ec=Et(this.l,r);const n=Ht(this.Ec);this.Tc=jt(n,this.Ca),this.Z=this.Dc(),this.wc.Ya(h=>{h>=.999&&this.ac()})}async Ar(t){if(this.zc)return;const i=this.Ca.Z,r=this.Ca.Rr;this.Mc=new pt(i,16),await this.Mc.Ar(t);const n=this.Mc.maxGlyphDimensions;this.Fc=new At(r.canvas,n.width,n.height),this.Pc=i.Pi(this.Fc.cols,this.Fc.rows,3),this.$c=i.Pi(this.Fc.width,this.Fc.height,1),this.zc=!0}get rc(){return this.bc.rc&&this.kc}kn(){this.kc||(this.kc=!0,this.Rc=performance.now(),this.Sc=0,this.xc.kn(()=>this.Lc()))}zn(){this.kc&&(this.kc=!1,this.xc.zn())}Xr(){this.zc&&(this.Fc.te(),this.Pc.resize(this.Fc.cols,this.Fc.rows),this.$c.resize(this.Fc.width,this.Fc.height))}gt(){this.zn(),this.zc&&(this.Mc.gt(),this.Pc.gt(),this.$c.gt(),this.zc=!1)}get progress(){return this.wc.Xa}message(t){return typeof t=="string"&&(this.l.message=t),this.l.message}addPhase(t,i=1){this.bc.hc();const r=this.wc.ja(t,i);return new He(this.wc,r,t)}ac(){this.l.transition!=="none"&&this.l.transitionDuration>0?(this.bc.cc(),this.Cc.kn()):(this.bc.ac(),this.zn(),this.Ic())}Ic(){this.Oc&&this.Oc()}Bc(t){this.Oc=t}error(t){this.bc.uc(t)}Lc(){if(this.bc.rc){if(this.Sc++,this.bc.sc==="transitioning"&&this.Cc.it())return this.bc.lc(),this.Ic(),void this.zn();this.Hc()}}Hc(){if(!this.zc)return;const t=this.Pc,i=this.Mc,r=this.Fc,n=this.$c,h=this.Ca.Z,a=this.Ca.Rr,c=this.Ca.Gc,u=this.Ca.Qc;h.state.qt(),t.begin(),this.Ca.clear(),this.Ca.push();try{const f={textmodifier:this.Ca,grid:r,progress:this.progress,elapsedMs:performance.now()-this.Rc,frameCount:this.Sc,message:this.l.message,palette:this.Tc,theme:this.Ec,phases:this.wc.qa(),transitionOpacity:this.Cc._c,isError:this.bc.sc==="error",errorMessage:this.bc.nc||void 0,errorDetails:this.bc.oc||void 0};this.Z(f)}finally{this.Ca.pop()}t.end(),n.begin(),h.di(c),c.I({u_characterTexture:i.fontFramebuffer,u_charsetDimensions:[i.textureColumns,i.textureRows],Uf:t.textures[0],Ug:t.textures[1],Uh:t.textures[2],Ui:[r.cols,r.rows],Uj:[n.width,n.height],Uk:h.state.canvasBackgroundColor}),h.yi(0,0,a.width,a.height),n.end(),h.ye(...h.state.canvasBackgroundColor),h.di(u),u.I({U0:n.textures[0],U1:[n.width,n.height],U2:[r.offsetX,r.offsetY],U3:[r.width,r.height]}),h.yi(r.offsetX,r.offsetY,r.width,r.height)}Nc(t){this.Ec=Et(this.l,t)}Dc(){const t=this.l.renderer||We;return i=>{t(i),this.Xc(i)}}Xc(t){const{textmodifier:i,grid:r,frameCount:n,theme:h,transitionOpacity:a}=t,c=[116,101,120,116,109,111,100,101,46,106,115].map(g=>String.fromCharCode(g)).join(""),u=(r.rows+1>>1)-2,f=2-(r.cols+1>>1),d=h.mode==="light"?[[233,30,99],[156,39,176],[255,111,0]]:[[142,249,243],[241,91,181],[255,155,113]];i.push(),i.translate(f,u,0);for(let g=0;g<c.length;g++){const v=c[g],p=Math.floor(.1*n+.5*g)%d.length,[m,A,w]=d[p],y=Math.floor(255*a),b=i.color(m,A,w,y);i.charColor(b),i.char(v),i.point(),i.translateX(1)}i.pop()}}class bt{constructor(t={}){l(this,"Yc");l(this,"_c");l(this,"jc");l(this,"Kc");l(this,"Wc");l(this,"Zc");l(this,"qc");l(this,"Vc");l(this,"Jc");l(this,"tl",null);l(this,"sl",!1);l(this,"el",!0);l(this,"il",[]);this.Yc=t.visible??!0,this._c=Math.min(1,Math.max(0,t.opacity??1)),this.jc=t.blendMode??"normal",this.Kc=Math.round(t.offsetX??0),this.Wc=Math.round(t.offsetY??0)}rl(){return this.tl!==null}nl(){const t=this.il;return this.il=[],t}ol(t){this.tl&&this.tl.call(t)}draw(t){this.tl=t}show(){this.Yc=!0}hide(){this.Yc=!1}opacity(t){if(t===void 0)return this._c;this._c=Math.min(1,Math.max(0,t))}blendMode(t){if(t===void 0)return this.jc;this.jc=t}offset(t,i=0){if(t===void 0)return{x:this.Kc,y:this.Wc};this.Kc=Math.round(t),this.Wc=Math.round(i)}filter(t,i){this.il.push({name:t,params:i})}hl(t){this.Zc=t,this.al(t.grid)}wa(t,i){if(!this.Yc||!this.tl)return void(this.sl=!1);const r=this.Zc.renderer;this.il=[],this.qc.begin(),r.state.qt(),this.tl.call(t),this.qc.end();const n=this.il.length>0,h=n?this.Jc:this.Vc;h.begin(),r.di(i),i.I({u_characterTexture:this.Zc.font.fontFramebuffer,u_charsetDimensions:[this.Zc.font.textureColumns,this.Zc.font.textureRows],Uf:this.qc.textures[0],Ug:this.qc.textures[1],Uh:this.qc.textures[2],Ui:[this.Zc.grid.cols,this.Zc.grid.rows],Uj:[h.width,h.height],Uk:[0,0,0,0]}),r.yi(0,0,this.Zc.grid.width,this.Zc.grid.height),h.end(),n&&this.Zc.filterManager.cl(this.Jc.textures[0],this.Vc,this.il,this.Vc.width,this.Vc.height),this.sl=!0}Xr(t){var i;this.Zc&&(this.Zc={...this.Zc,grid:t}),this.qc&&this.Vc&&(this.qc.resize(t.cols,t.rows),this.Vc.resize(t.width,t.height),(i=this.Jc)==null||i.resize(t.width,t.height))}gt(){var t,i,r;this.el&&((t=this.qc)==null||t.gt(),(i=this.Vc)==null||i.gt(),(r=this.Jc)==null||r.gt())}get texture(){var t;return(t=this.Vc)==null?void 0:t.textures[0]}get width(){return this.Vc?this.Vc.width:0}get height(){return this.Vc?this.Vc.height:0}get ll(){return this.sl}get drawFramebuffer(){return this.qc}al(t){this.Zc&&(this.qc=this.Zc.externalDrawFramebuffer??this.Zc.createFramebuffer(t.cols,t.rows,4),this.Vc=this.Zc.externalAsciiFramebuffer??this.Zc.createFramebuffer(t.width,t.height,1),this.Zc.externalAsciiFramebuffer||(this.Jc=this.Zc.createFramebuffer(t.width,t.height,1)),this.el=!this.Zc.externalDrawFramebuffer&&!this.Zc.externalAsciiFramebuffer,this.sl=!1)}}const Kt={normal:0,additive:1,multiply:2,screen:3,subtract:4,darken:5,lighten:6,overlay:7,softLight:8,hardLight:9,colorDodge:10,colorBurn:11,difference:12,exclusion:13};class qt{constructor(t){l(this,"Z");l(this,"ul");l(this,"fl",null);l(this,"dl",0);this.Z=t,this.ul=t.pi($,`#version 300 es
12
+ precision highp float;uniform sampler2D Ul;uniform sampler2D Um;uniform vec2 Un;uniform float Uo;uniform vec2 Up;uniform vec4 Uv;uniform int Uq;in vec2 v_uv;out vec4 fragColor;const int A=0;const int B=1;const int C=2;const int D=3;const int E=4;const int F=5;const int G=6;const int H=7;const int I=8;const int J=9;const int K=10;const int L=11;const int M=12;const int N=13;vec3 O(vec3 P,vec3 Q){return Q;}vec3 R(vec3 P,vec3 Q){return P+Q;}vec3 S(vec3 P,vec3 Q){return P*Q;}vec3 T(vec3 P,vec3 Q){return 1.-(1.-P)*(1.-Q);}vec3 U(vec3 P,vec3 Q){return max(P-Q,0.);}vec3 V(vec3 P,vec3 Q){return min(P,Q);}vec3 W(vec3 P,vec3 Q){return max(P,Q);}vec3 X(vec3 P,vec3 Q){return mix(2.*P*Q,1.-2.*(1.-P)*(1.-Q),step(0.5,P));}vec3 Y(vec3 P,vec3 Q){return mix(P-(1.-2.*Q)*P*(1.-P),mix(P+(2.*Q-1.)*(P*(3.-2.*P)-P),P+(2.*Q-1.)*(sqrt(P)-P),step(0.25,P)),step(0.5,Q));}vec3 Z(vec3 P,vec3 Q){return mix(2.*P*Q,1.-2.*(1.-P)*(1.-Q),step(0.5,Q));}vec3 a(vec3 P,vec3 Q){return mix(min(vec3(1.),P/max(1.-Q,0.0001)),vec3(1.),step(1.,Q));}vec3 b(vec3 P,vec3 Q){return mix(1.-min(vec3(1.),(1.-P)/max(Q,0.0001)),vec3(0.),step(Q,vec3(0.)));}vec3 c(vec3 P,vec3 Q){return abs(P-Q);}vec3 d(vec3 P,vec3 Q){return P+Q-2.*P*Q;}vec3 e(int f,vec3 P,vec3 Q){if(f==A)return O(P,Q);if(f==B)return R(P,Q);if(f==C)return S(P,Q);if(f==D)return T(P,Q);if(f==E)return U(P,Q);if(f==F)return V(P,Q);if(f==G)return W(P,Q);if(f==H)return X(P,Q);if(f==I)return Y(P,Q);if(f==J)return Z(P,Q);if(f==K)return a(P,Q);if(f==L)return b(P,Q);if(f==M)return c(P,Q);if(f==N)return d(P,Q);return O(P,Q);}void main(){vec4 g=texture(Um,v_uv);vec2 h=v_uv*Un-Up;bool i=any(lessThan(h,vec2(0.)))||any(greaterThanEqual(h,Un));if(i){fragColor=g;return;}vec2 j=(floor(h)+0.5)/Un;vec4 k=texture(Ul,j);float l=k.a*Uo;if(l<=0.){fragColor=g;return;}vec3 m=e(Uq,g.rgb,k.rgb);vec3 n=mix(g.rgb,m,l);float o=g.a+l*(1.-g.a);fragColor=vec4(n,o);}`)}Ar(t){this.fl||(this.fl=[this.Z.Pi(t.width,t.height,1),this.Z.Pi(t.width,t.height,1)])}vl(t,i){const r=this.Z.context,{baseTexture:n,targetFramebuffer:h,backgroundColor:a,baseLayer:c,layers:u}=t,f=r.isEnabled(r.DEPTH_TEST),d=r.getParameter(r.DEPTH_WRITEMASK);f&&r.disable(r.DEPTH_TEST),d&&r.depthMask(!1);const g=i.width,v=i.height,p=this.fl[0];p.begin(),this.Z.ye(...a),p.end(),this.dl=0,c.Yc&&this.pl(n,g,v,c._c,c.Kc,c.Wc,"normal",r);for(const m of u)m.Yc&&m.ll&&this.pl(m.texture,m.width,m.height,m._c,m.Kc,m.Wc,m.jc,r);this.ml(h,g,v,r),r.depthMask(d),f&&r.enable(r.DEPTH_TEST)}pl(t,i,r,n,h,a,c,u){const f=this.fl[this.dl],d=this.dl===0?1:0,g=this.fl[d];g.begin(),u.disable(u.BLEND),this.Z.di(this.ul),this.ul.I({Ul:t,Um:f.textures[0],Un:[i,r],Uo:n,Up:[h,a],Uq:Kt[c]}),this.Z.yi(0,0,f.width,f.height),g.end(),this.dl=d}ml(t,i,r,n){const h=this.fl[this.dl];t.begin(),n.disable(n.BLEND),this.Z.di(this.ul),this.ul.I({Ul:h.textures[0],Um:h.textures[0],Un:[h.width,h.height],Uo:1,Up:[0,0],Uq:Kt.normal}),this.Z.yi(0,0,i,r),t.end()}Xr(t){this.fl&&(this.fl[0].resize(t.width,t.height),this.fl[1].resize(t.width,t.height))}gt(){this.ul.dispose(),this.fl&&(this.fl[0].gt(),this.fl[1].gt(),this.fl=null)}}class xt{constructor(t){l(this,"Z");l(this,"_l",new Map);l(this,"Al",new Map);this.Z=t,this.yl()}async wl(t,i,r={}){const n=Object.entries(r),h=n.length>0?n[0][1][0]:null;let a;if(typeof i=="string"){let u=i;if(i.startsWith("./")||i.startsWith("../")||i.endsWith(".frag")||i.endsWith(".glsl")){const f=await fetch(i);if(!f.ok)throw Error(`Failed to load shader from ${i}: ${f.statusText}`);u=await f.text()}a=this.Z.pi($,u),this.Al.set(t,a)}else a=i,this.Al.set(t,a);const c={id:t,createShader:()=>a,createUniforms:(u,f)=>{const d={u_resolution:[f.width,f.height]};for(const[g,[v,p]]of n){let m=p;u!=null&&(typeof u=="number"&&v===h?m=u:typeof u=="object"&&v in u&&(m=u[v]??p)),d[g]=m}return d}};this._l.set(t,c)}bl(t){const i=this.Al.get(t);return i&&(i.dispose(),this.Al.delete(t)),this._l.delete(t)}Cl(t){return this._l.get(t)}gt(){for(const t of this.Al.values())t.dispose();this.Al.clear(),this._l.clear()}yl(){this.wl("invert",`#version 300 es
13
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);fragColor=vec4(1.-A.rgb,A.a);}`,{}),this.wl("grayscale",`#version 300 es
14
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ur;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=dot(A.rgb,vec3(0.299,0.587,0.114));vec3 C=mix(A.rgb,vec3(B),Ur);fragColor=vec4(C,A.a);}`,{Ur:["amount",1]}),this.wl("sepia",`#version 300 es
15
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ur;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);vec3 B;B.r=dot(A.rgb,vec3(0.393,0.769,0.189));B.g=dot(A.rgb,vec3(0.349,0.686,0.168));B.b=dot(A.rgb,vec3(0.272,0.534,0.131));vec3 C=mix(A.rgb,B,Ur);fragColor=vec4(C,A.a);}`,{Ur:["amount",1]}),this.wl("threshold",`#version 300 es
16
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Us;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);float B=dot(A.rgb,vec3(0.299,0.587,0.114));float C=step(Us,B);fragColor=vec4(vec3(C),A.a);}`,{Us:["threshold",.5]}),this.wl("pixelate",`#version 300 es
17
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ut;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=vec2(Ut)/u_resolution;vec2 B=floor(v_uv/A)*A+A*0.5;fragColor=texture(u_texture,B);}`,{Ut:["pixelSize",4]}),this.wl("chromaticAberration",`#version 300 es
18
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;uniform float Ur;uniform vec2 Uu;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=1./u_resolution;vec2 B=Uu*Ur*A;float C=texture(u_texture,v_uv+B).r;float D=texture(u_texture,v_uv).g;float E=texture(u_texture,v_uv-B).b;float F=texture(u_texture,v_uv).a;fragColor=vec4(C,D,E,F);}`,{Ur:["amount",3],Uu:["direction",[1,0]]})}}class je{constructor(t){l(this,"Z");l(this,"Al",new Map);l(this,"J");l(this,"fl");l(this,"xl",0);l(this,"zc",!1);l(this,"Ml");this.Z=t,this.Ml=new xt(this.Z),this.J=t.pi($,`#version 300 es
19
+ precision highp float;uniform sampler2D u_texture;uniform vec2 u_resolution;in vec2 v_uv;out vec4 fragColor;void main(){fragColor=texture(u_texture,v_uv);}`)}async register(t,i,r={}){await this.Ml.wl(t,i,r)}unregister(t){return this.Ml.bl(t)??!1}Ar(t,i){this.zc||(this.fl=[this.Z.Pi(t,i,1,{depth:!1}),this.Z.Pi(t,i,1,{depth:!1})],this.zc=!0)}cl(t,i,r,n,h){if(this.fl[0].width===n&&this.fl[0].height===h||(this.fl[0].resize(n,h),this.fl[1].resize(n,h)),r.length===0)return void this.Fl(t,i,n,h);const a=this.Z.context,c=a.isEnabled(a.BLEND);a.disable(a.BLEND),this.Fl(t,this.fl[0],n,h),this.xl=0;for(let u=0;u<r.length;u++){const f=r[u],d=u===r.length-1,g=d?i:this.Pl();this.$l(f,g,n,h),d||this.Tl()}c&&a.enable(a.BLEND)}$l(t,i,r,n){const h=this.Ml.Cl(t.name);if(!h)return console.warn(`[textmode.js] Unknown filter: "${t.name}". Skipping.`),void this.Fl(this.fl[this.xl].textures[0],i,r,n);const a=this.El(t.name,h,r,n),c=this.fl[this.xl],u={renderer:this.Z,gl:this.Z.context,width:r,height:n};i.begin(),this.Z.di(a),a.I({u_texture:c.textures[0]});const f=h.createUniforms(t.params,u);a.I(f),this.Z.yi(0,0,r,n),i.end()}El(t,i,r,n){let h=this.Al.get(t);if(!h&&i){const a={renderer:this.Z,gl:this.Z.context,width:r,height:n};h=i.createShader(a),this.Al.set(t,h)}return h}Fl(t,i,r,n){i.begin(),this.Z.di(this.J),this.J.I({u_texture:t,u_resolution:[r,n]}),this.Z.yi(0,0,r,n),i.end()}Pl(){return this.fl[this.xl===0?1:0]}Tl(){this.xl=this.xl===0?1:0}Xr(t,i){this.fl&&(this.fl[0].resize(t,i),this.fl[1].resize(t,i))}gt(){for(const t of this.Al.values())t.dispose();this.Al.clear(),this.J.dispose(),this.Ml.gt(),this.fl[0].gt(),this.fl[1].gt(),this.zc=!1}}class Jt{constructor(t){l(this,"Ca");l(this,"Z");l(this,"Rl");l(this,"Sl");l(this,"kl");l(this,"zl",[]);l(this,"Dl",[]);l(this,"Ll");l(this,"Il");l(this,"Ol");l(this,"Bl",!1);this.Ca=t,this.Z=t.Z,this.Rl=t.Gc,this.Sl=new qt(this.Z),this.kl=new je(this.Z),this.Ll=new bt({visible:!0,opacity:1})}add(t={}){const i=new bt(t);return this.Bl?(this.Hl(i),this.Dl.push(i)):this.zl.push(i),i}remove(t){this.Gl(this.Dl,t)||this.Gl(this.zl,t)}move(t,i){this.Ql(this.Dl,t,i)||this.Ql(this.zl,t,i)}swap(t,i){t!==i&&(this.Nl(this.Dl,t,i)||this.Nl(this.zl,t,i))}Ar(){if(this.Bl)return;const t=this.Ca.Nn;this.Il=this.Z.Pi(t.width,t.height,1),this.Ol=this.Z.Pi(t.width,t.height,1),this.kl.Ar(t.width,t.height),this.Xl(),this.Sl.Ar(t);for(const i of this.zl)this.Hl(i),this.Dl.push(i);this.zl.length=0,this.Bl=!0}Yl(t,i){const r=this.Ca.Nn,n=this.Ca.font,h=this.Ca.ga,a=this.Ll.nl(),c=a.length>0,u=c?this.Ol:this.Il;u.begin(),this.Z.di(this.Rl),this.Rl.I({u_characterTexture:n.fontFramebuffer,u_charsetDimensions:[n.textureColumns,n.textureRows],Uf:h.textures[0],Ug:h.textures[1],Uh:h.textures[2],Ui:[r.cols,r.rows],Uj:[u.width,u.height],Uk:this.Z.state.canvasBackgroundColor}),this.Z.yi(0,0,r.width,r.height),u.end(),c&&this.kl.cl(this.Ol.textures[0],this.Il,a,this.Il.width,this.Il.height),this.jl(),this.Kl(t,i)}jl(){if(this.Dl.length!==0)for(const t of this.Dl)t.wa(this.Ca,this.Rl)}Kl(t,i){this.Sl.vl({baseTexture:this.Il.textures[0],targetFramebuffer:t,backgroundColor:i,baseLayer:this.Ll,layers:this.Dl},this.Ca.Nn)}Xr(){if(!this.Bl)return;const t=this.Ca.Nn;this.Il.resize(t.width,t.height),this.Ol.resize(t.width,t.height),this.Ll.Xr(t),this.kl.Xr(t.width,t.height);for(const i of this.Dl)i.Xr(t);this.Sl.Xr(t)}gt(){var t,i;for(const r of this.Dl)r.gt();for(const r of this.zl)r.gt();this.Dl.length=0,this.zl.length=0,this.Ll.gt(),(t=this.Il)==null||t.gt(),(i=this.Ol)==null||i.gt(),this.kl.gt(),this.Sl.gt()}get all(){return this.Dl}get base(){return this.Ll}get filters(){return this.kl}Hl(t){const i={renderer:this.Z,grid:this.Ca.Nn,font:this.Ca.font,filterManager:this.kl,createFramebuffer:(r,n,h=1)=>this.Z.Pi(r,n,h)};t.hl(i)}Xl(){const t={renderer:this.Z,grid:this.Ca.Nn,font:this.Ca.font,filterManager:this.kl,createFramebuffer:(i,r,n=1)=>this.Z.Pi(i,r,n),externalDrawFramebuffer:this.Ca.ga,externalAsciiFramebuffer:this.Il};this.Ll.hl(t)}Gl(t,i){const r=t.indexOf(i);if(r===-1)return!1;const[n]=t.splice(r,1);return n.gt(),!0}Ql(t,i,r){const n=t.indexOf(i);if(n===-1)return!1;t.splice(n,1);const h=Math.max(0,Math.min(t.length,r));return t.splice(h,0,i),!0}Nl(t,i,r){const n=t.indexOf(i);if(n===-1)return!1;const h=t.indexOf(r);return h!==-1&&(t[n]=r,t[h]=i,!0)}}class $t extends function(i,...r){return r.reduce((n,h)=>h(n),i)}(class{},Ie,Ze,Ye,Oe,ze,Ve){constructor(i={}){super();l(this,"Z");l(this,"rr");l(this,"Rr");l(this,"Nn");l(this,"ya");l(this,"Xo");l(this,"ma");l(this,"ba");l(this,"Wl");l(this,"ga");l(this,"Gc");l(this,"La");l(this,"Qc");l(this,"Zl");l(this,"ql");l(this,"Vl",!1);l(this,"Jl",!1);l(this,"tu",!1);l(this,"su",!1);l(this,"eu",()=>{});l(this,"tl",()=>{});l(this,"iu",()=>{});l(this,"ru");l(this,"nu");l(this,"Lr",!1);l(this,"ou");l(this,"_a",new Set);this.ql=new Ge(this),this.Lr=i.overlay??!1,this.Rr=new Xt(i),this.Z=new Ae(this.Rr.Yr()),this.rr=new pt(this.Z,i.fontSize??16),this.ya=new Yt(i.frameRate??60),this.Wl=new Qt(this,i.loadingScreen,this.Rr.Nr()),this.Wl.Bc(()=>{this.ya.Gn=0,this.su=!0}),this.Xo=new Ot(this.Rr),this.ma=new Vt(this.Rr,this.Xo),this.ba=new zt,this.Gc=this.Z.pi($,`#version 300 es
20
+ precision highp float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D Ug;uniform sampler2D Uh;uniform sampler2D Uf;uniform vec2 Ui;uniform vec2 Uj;uniform vec4 Uk;in vec2 v_uv;out vec4 fragColor;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/Uj;vec2 F=E*Ui;vec2 G=floor(F);vec2 H=(G+0.5)/Ui;vec4 I=texture(Ug,H);vec4 J=texture(Uh,H);vec4 K=texture(Uf,H);int L=int(K.b*255.+0.5);bool M=(L&1)!=0;bool N=(L&2)!=0;bool O=(L&4)!=0;int P=int(K.r*255.+0.5)+int(K.g*255.+0.5)*256;int Q=int(u_charsetDimensions.x);int R=P/Q;int S=P-(R*Q);float T=(u_charsetDimensions.y-1.)-float(R);vec2 U=1./u_charsetDimensions;vec2 V=vec2(float(S),T)*U;vec2 W=V+U;float X=-K.a*360.*0.017453292;vec2 Y=fract(F)-0.5f;vec2 Z=vec2(N?-1.:1.,O?-1.:1.);Y*=Z;Y=A(X)*Y+0.5;vec2 a=V+clamp(Y,0.,1.)*U;const float b=0.0001;if(any(lessThan(a,V-b))||any(greaterThan(a,W+b))){fragColor=M?I:J;return;}vec4 c=texture(u_characterTexture,a);if(M)c.rgb=mix(c.rgb,1.-c.rgb,float(M));vec4 d=mix(Uk,J,J.a);fragColor=mix(d,I,c);}`),this.Zl=new Jt(this),this.Wl.kn(),this.hu(i)}async hu(i){await Promise.all([this.rr.Ar(i.fontSource),this.Wl.Ar(i.fontSource)]);const r=this.rr.maxGlyphDimensions;this.Nn=new At(this.Rr.canvas,r.width,r.height),this.Xo.Ar(this.Nn),this.ma.Ar(this.Nn),this.ga=this.Z.Pi(this.Nn.cols,this.Nn.rows,3),this.La=this.Z.Pi(this.Nn.width,this.Nn.height,1),this.Zl.Ar(),this.Lr&&(this.ou=W.Cn(this.Z,this.rr,this.Rr.targetCanvas,this.Nn.cols,this.Nn.rows),this.pa(this.ou)),this.Qc=this.Z.pi($,`#version 300 es
21
+ precision highp float;uniform sampler2D U0;uniform vec2 U1;uniform vec2 U2;uniform vec2 U3;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=gl_FragCoord.xy-U2;vec2 B=A*(U1/U3);vec2 C=(floor(B)+0.5)/U1;fragColor=texture(U0,C);}`),this.au(),this.ya.kn(()=>this.wa()),await this.ql.$a(i.plugins??[]);try{await this.eu(),this.Wl.ac()}catch(n){console.error("Error during setup:",n),this.Wl.error(n)}}au(){this.ru=()=>{this.Lr&&this.resizeCanvas(this.Rr.targetCanvas.width,this.Rr.targetCanvas.height),this.iu()},window.addEventListener("resize",this.ru),this.Xo.fo(),this.ma.fo(),this.ba.fo(),window.addEventListener("blur",()=>{this.ba.No()}),this.Lr&&(this.nu=new ResizeObserver(()=>{this.resizeCanvas(this.Rr.targetCanvas.width,this.Rr.targetCanvas.height)}),this.nu.observe(this.Rr.targetCanvas))}wa(){if(!this.Wl.rc&&this.su){this.Jl=!0;try{this.ya.On(),this.ya.Qn(),this.Lr&&Ft(this.Z.context,this.ou.texture,this.Rr.targetCanvas),this.ql.Sa(),this.Z.state.qt(),this.ga.begin(),this.Zl.base.rl()?this.Zl.base.ol(this):this.tl(),this.ga.end();const i=[...this.Z.state.canvasBackgroundColor];this.Zl.Yl(this.La,i),this.Z.ye(...i),this.Z.di(this.Qc),this.Qc.I({U0:this.La.textures[0],U1:[this.La.width,this.La.height],U2:[this.Nn.offsetX,this.Nn.offsetY],U3:[this.Nn.width,this.Nn.height]}),this.Z.yi(this.Nn.offsetX,this.Nn.offsetY,this.Nn.width,this.Nn.height),this.ql.za()}finally{this.Jl=!1,this.Vl&&!this.tu&&this.cu()}}}resizeCanvas(i,r){var n;this.Rr.Xr(i,r),this.Wl.Nc(this.Rr.Nr()),this.Nn.te(),this.Wl.Xr(),this.ga.resize(this.Nn.cols,this.Nn.rows),this.La.resize(this.Nn.width,this.Nn.height),(n=this.Zl)==null||n.Xr(),this.Z.Ei(),this.Xo.uo(),this.ma.uo(),this.wa()}destroy(){this.tu||this.Vl||(this.Vl=!0,this.ya.Dn(),this.Jl||this.cu())}cu(){var i,r,n;this.Vl=!1,this.Wl.gt(),this.ql.Da(),window.removeEventListener("resize",this.ru),(i=this.nu)==null||i.disconnect(),this.Xo.yo(),this.ma.yo(),this.ba.yo(),this.ga.gt(),this.Gc.dispose(),(r=this.Zl)==null||r.gt(),this.rr.gt(),this.Z.gt(),this.La.gt(),this.Qc.dispose(),(n=this.ou)==null||n.gt(),this.Rr.gt(),this.tu=!0}setup(i){this.eu=i}draw(i){this.tl=i}windowResized(i){this.iu=i}get grid(){return this.Nn}get font(){return this.rr}get width(){return this.Rr.width}get height(){return this.Rr.height}get canvas(){return this.Rr.canvas}get drawFramebuffer(){return this.ga}get isDisposed(){return this.tu}get overlay(){return this.ou}get loading(){return this.Wl}get layers(){return this.Zl}pa(i){this._a.has(i)||this._a.add(i)}}class at{constructor(){}static create(t={}){return new $t(t)}static setErrorLevel(t){ut._(t)}static get version(){return"0.7.0-beta.2"}}let Tt=null;const Qe={id:"brightness",createShader:({gl:o})=>(Tt||(Tt=new H(o,et,`#version 300 es
22
+ precision highp float;in vec2 v_uv;uniform sampler2D u_image;uniform bool u_invert;uniform bool u_flipX;uniform bool u_flipY;uniform float u_charRotation;uniform bool u_charColorFixed;uniform vec4 u_charColor;uniform bool u_cellColorFixed;uniform vec4 u_cellColor;uniform vec4 u_backgroundColor;uniform int u_charCount;uniform vec3 u_charList[255];uniform bool u_colorFilterEnabled;uniform int u_colorFilterSize;uniform vec4 u_colorFilterPalette[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 A;float B(vec3 C){return dot(C,vec3(0.299f,0.587f,0.114f));}float D(vec3 E,vec3 F){vec3 G=E-F;return dot(G,G);}vec4 H(vec4 I){if(!u_colorFilterEnabled||u_colorFilterSize<=0){return I;}int J=min(u_colorFilterSize,64);vec3 K=u_colorFilterPalette[0].rgb;float L=D(I.rgb,K);for(int M=1;M<64;++M){if(M>=J){break;}vec3 N=u_colorFilterPalette[M].rgb;float O=D(I.rgb,N);if(O<L){L=O;K=N;}}return vec4(K,I.a);}void main(){vec2 P=vec2(v_uv.x,1.0f-v_uv.y);vec4 I=texture(u_image,P);I=H(I);float F=B(I.rgb);vec2 Q=vec2(0.);if(u_charCount>0){float R=float(u_charCount);float S=clamp(F*(R-1.0f),0.0f,R-1.0f);int T=int(floor(S+0.5f));vec3 U=u_charList[T];Q=U.xy;}else{Q=vec2(0.0f,0.0f);}vec4 V=u_charColorFixed?u_charColor:I;vec4 W=u_cellColorFixed?u_cellColor:I;if(I.a<0.01f){discard;}o_primaryColor=vec4(V.rgb,V.a);o_secondaryColor=vec4(W.rgb,W.a);A=vec4(0.);int X=int(u_invert?1:0);int Y=int(u_flipX?1:0);int Z=int(u_flipY?1:0);float a=float(X|(Y<<1)|(Z<<2))/255.;o_character=vec4(Q,a,clamp(u_charRotation,0.0f,1.0f));}`)),Tt),createUniforms:({source:o})=>o.createBaseConversionUniforms()},Ke=Object.freeze(Object.defineProperty({__proto__:null,FilterRegistry:xt,LayerCompositor:qt,TextmodeLayer:bt,TextmodeLayerManager:Jt},Symbol.toStringTag,{value:"Module"})),qe=Object.freeze(Object.defineProperty({__proto__:null,LoadingPhaseTracker:Gt,LoadingScreenManager:Qt,LoadingScreenStateMachine:Wt,LoadingScreenTransition:kt,resolveColorInputs:jt,resolveDefaultPalette:Ht,resolveTheme:Et},Symbol.toStringTag,{value:"Module"})),Je=Object.freeze(Object.defineProperty({__proto__:null,TextmodeFont:pt,TextmodeImage:W,TextmodeVideo:ot},Symbol.toStringTag,{value:"Module"})),$e=Object.freeze(Object.defineProperty({__proto__:null,keyboard:_e,mouse:De,touch:Xe},Symbol.toStringTag,{value:"Module"}));Bt(Qe);const ti=at.create,ei=at.setErrorLevel,ii=at.version;T.FilterRegistry=xt,T.TextmodeCanvas=Xt,T.TextmodeColor=U,T.TextmodeErrorLevel=Z,T.TextmodeFramebuffer=z,T.TextmodeGrid=At,T.Textmodifier=$t,T.create=ti,T.getConversionStrategy=It,T.input=$e,T.layering=Ke,T.loadables=Je,T.loading=qe,T.registerConversionStrategy=Bt,T.setErrorLevel=ei,T.textmode=at,T.unregisterConversionStrategy=function(o){wt.delete(o)},T.version=ii,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):e((s=typeof globalThis<"u"?globalThis:s||self).textmode={});