textmode.js 0.6.0-beta.5 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/dist/textmode.esm.js +1813 -1885
  2. package/dist/textmode.umd.js +11 -11
  3. package/dist/types/index.d.ts +1 -1
  4. package/dist/types/rendering/index.d.ts +1 -1
  5. package/dist/types/rendering/webgl/core/Renderer.d.ts +1 -4
  6. package/dist/types/rendering/webgl/core/Shader.d.ts +1 -2
  7. package/dist/types/rendering/webgl/materials/MaterialManager.d.ts +0 -1
  8. package/dist/types/textmode/TextmodeColor.d.ts +2 -13
  9. package/dist/types/textmode/Textmodifier.d.ts +4 -5
  10. package/dist/types/textmode/conversion/ConversionRegistry.d.ts +30 -2
  11. package/dist/types/textmode/interfaces/ITextmodifier.d.ts +5 -5
  12. package/dist/types/textmode/loadables/TextmodeImage.d.ts +1 -1
  13. package/dist/types/textmode/loadables/TextmodeSource.d.ts +21 -7
  14. package/dist/types/textmode/loadables/font/CharacterColorMapper.d.ts +11 -14
  15. package/dist/types/textmode/loadables/font/MetricsCalculator.d.ts +0 -4
  16. package/dist/types/textmode/loadables/font/TextmodeFont.d.ts +7 -19
  17. package/dist/types/textmode/loadables/font/TextureAtlas.d.ts +1 -9
  18. package/dist/types/textmode/loadables/font/index.d.ts +1 -1
  19. package/dist/types/textmode/loadables/font/types.d.ts +26 -2
  20. package/dist/types/textmode/loadables/font/utils/FontTableReader.d.ts +1 -12
  21. package/dist/types/textmode/loadables/index.d.ts +2 -4
  22. package/dist/types/textmode/loadables/{TextmodeVideo.d.ts → video/TextmodeVideo.d.ts} +8 -76
  23. package/dist/types/textmode/loadables/video/TextmodeVideoPreloader.d.ts +29 -0
  24. package/dist/types/textmode/loadables/video/types.d.ts +43 -0
  25. package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +5 -13
  26. package/package.json +2 -1
@@ -1,14 +1,14 @@
1
- var qe=Object.defineProperty;var Qe=(x,R,H)=>R in x?qe(x,R,{enumerable:!0,configurable:!0,writable:!0,value:H}):x[R]=H;var l=(x,R,H)=>Qe(x,typeof R!="symbol"?R+"":R,H);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 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?`
2
2
 
3
- 📋 Context:`+Object.entries(i).map(([r,h])=>`
4
- - ${r}: ${R.o(h)}`).join(""):""}
3
+ 📋 Context:`+Object.entries(i).map(([r,n])=>`
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 H=(o=>(o[o.SILENT=0]="SILENT",o[o.WARNING=1]="WARNING",o[o.ERROR=2]="ERROR",o[o.THROW=3]="THROW",o))(H||{});const _=class _{constructor(){l(this,"l",{globalLevel:3})}static u(){return _.h||(_.h=new _),_.h}v(t,i){const r="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",h="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,h),console.warn(R.i(t,i)),console.groupEnd(),!1;case 2:return console.group(r,h),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(_,"h",null);let lt=_;const j=lt.u();class W{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 h=r.name.replace(/\[0\]$/,""),n=this.A.getUniformLocation(this.C,h);n&&(this.M.set(h,n),this.F.set(h,{type:r.type,size:r.size}))}}}P(t,i){const r=this.S(this.A.VERTEX_SHADER,t),h=this.S(this.A.FRAGMENT_SHADER,i),n=this.A.createProgram();if(this.A.attachShader(n,r),this.A.attachShader(n,h),this.A.linkProgram(n),!this.A.getProgramParameter(n,this.A.LINK_STATUS)){const c=this.A.getProgramInfoLog(n);throw Error("Shader program link error: "+c)}return this.A.deleteShader(r),this.A.deleteShader(h),n}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 h=this.A.getShaderInfoLog(r);throw this.A.deleteShader(r),Error("Shader compilation error: "+h)}return r}U(){this.A.useProgram(this.C),this.k()}k(){this.$=0}I(t){for(const i in t)this.L(i,t[i])}L(t,i){var u,f;const r=this.M.get(t);if(!r)return;const h=this.F.get(t);if(!h)return;const{type:n,size:c}=h,a=this.A;if(i instanceof WebGLTexture){const d=this.$++;return a.uniform1i(r,d),a.activeTexture(a.TEXTURE0+d),void a.bindTexture(a.TEXTURE_2D,i)}if(i instanceof q){const d=this.$++;return a.uniform1i(r,d),a.activeTexture(a.TEXTURE0+d),void a.bindTexture(a.TEXTURE_2D,i.textures[0])}if(typeof i!="number")if(typeof i!="boolean")if(Array.isArray(i[0])){const d=i.flat(),g={[a.FLOAT_VEC2]:()=>a.uniform2fv(r,d),[a.FLOAT_VEC3]:()=>a.uniform3fv(r,d),[a.FLOAT_VEC4]:()=>a.uniform4fv(r,d)};(u=g[n])==null||u.call(g)}else{const d=i,g={[a.FLOAT]:()=>c>1?a.uniform1fv(r,d):a.uniform1f(r,d[0]),[a.FLOAT_VEC2]:()=>a.uniform2fv(r,d),[a.FLOAT_VEC3]:()=>a.uniform3fv(r,d),[a.FLOAT_VEC4]:()=>a.uniform4fv(r,d),[a.INT]:()=>c>1?a.uniform1iv(r,d):a.uniform1i(r,d[0]),[a.INT_VEC2]:()=>a.uniform2iv(r,d),[a.INT_VEC3]:()=>a.uniform3iv(r,d),[a.INT_VEC4]:()=>a.uniform4iv(r,d),[a.BOOL]:()=>a.uniform1iv(r,d),[a.FLOAT_MAT2]:()=>a.uniformMatrix2fv(r,!1,d),[a.FLOAT_MAT3]:()=>a.uniformMatrix3fv(r,!1,d),[a.FLOAT_MAT4]:()=>a.uniformMatrix4fv(r,!1,d)};(f=g[n])==null||f.call(g)}else a.uniform1i(r,i?1:0);else n===a.INT||n===a.BOOL?a.uniform1i(r,i):a.uniform1f(r,i)}get O(){return this.C}D(){this.A.deleteProgram(this.C)}}function xt(o,t,i,r){return 180*Math.atan2(r-t,i-o)/Math.PI}function k(o,t,i,r){return Math.hypot(i-o,r-t)}function X(o,t,i){return Math.min(Math.max(o,t),i)}function Ft(o){return(o%360+360)%360/360}function Rt(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,h){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,h)}function ut(o,t,i,r,h,n=0,c=WebGL2RenderingContext.FLOAT,a=!1){o.enableVertexAttribArray(t),o.vertexAttribPointer(t,i,c,a,r,h),o.vertexAttribDivisor(t,n)}function Ct(o,t,i,r,h){o.bindBuffer(t,i),o.bufferData(t,r,h),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 Ua;uniform float Ub;uniform float Uc;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/Ua)*2.0f;AA.y=-AA.y;float AB=y.z/Ua.y;float AC=clamp(-AB*Ub,-0.99f,0.99f);if(Uc>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);}}`,Z=class Z{constructor(t,i,r=i,h=1,n={},c){l(this,"H");l(this,"G");l(this,"l");l(this,"A");l(this,"N");l(this,"X",[]);l(this,"Y",null);l(this,"K");l(this,"W");l(this,"Z",null);l(this,"j",new Map);this.H=i,this.G=r,this.A=t,this.K=X(h,1,8),this.W=c,this.l={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",depth:!0,...n},Z.V||(Z.V=new W(t,et,`#version 300 es
9
- precision highp float;in vec2 v_uv;uniform sampler2D Ud;uniform sampler2D Ue;uniform sampler2D Uf;uniform vec2 Ug;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*Ug;vec2 C=(floor(B)+0.5f)/Ug;vec4 D=texture(Ud,C);vec4 E=texture(Ue,C);if(E.a==0.){discard;}vec4 F=texture(Uf,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;}`));const a=t.getParameter(t.MAX_DRAW_BUFFERS),u=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.K=Math.min(this.K,a,u),this.N=t.createFramebuffer(),this.q(),this.J(),this.l.depth&&this.tt()}q(){const t=this.A,i=this.l.filter==="linear"?t.LINEAR:t.NEAREST,r=this.l.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE,h=this.l.type==="float"?t.FLOAT:t.UNSIGNED_BYTE,n=h===t.FLOAT?t.RGBA32F:t.RGBA8,c=t.RGBA;for(let a=0;a<this.K;a++){const u=t.createTexture();t.bindTexture(t.TEXTURE_2D,u),tt(t,i,i,r,r),t.texImage2D(t.TEXTURE_2D,0,n,this.H,this.G,0,c,h,null),this.X.push(u)}t.bindTexture(t.TEXTURE_2D,null)}J(){const t=this.A;if(t.bindFramebuffer(t.FRAMEBUFFER,this.N),this.K===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.X[0],0);else{const i=[];for(let r=0;r<this.K;r++){const h=t.COLOR_ATTACHMENT0+r;t.framebufferTexture2D(t.FRAMEBUFFER,h,t.TEXTURE_2D,this.X[r],0),i.push(h)}t.drawBuffers(i)}t.bindFramebuffer(t.FRAMEBUFFER,null)}tt(){const t=this.A;this.Y=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,this.Y),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT24,this.H,this.G),t.bindFramebuffer(t.FRAMEBUFFER,this.N),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,this.Y),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindRenderbuffer(t.RENDERBUFFER,null)}st(t){Rt(this.A,this.X[0],t)}resize(t,i){this.H=t,this.G=i,this.j.clear();const r=this.A,h=this.l.type==="float"?r.FLOAT:r.UNSIGNED_BYTE,n=h===r.FLOAT?r.RGBA32F:r.RGBA8,c=r.RGBA;for(const a of this.X)r.bindTexture(r.TEXTURE_2D,a),r.texImage2D(r.TEXTURE_2D,0,n,this.H,this.G,0,c,h,null);r.bindTexture(r.TEXTURE_2D,null),this.Y&&(r.bindRenderbuffer(r.RENDERBUFFER,this.Y),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT24,this.H,this.G),r.bindRenderbuffer(r.RENDERBUFFER,null))}readPixels(t){const i=this.j.get(t);if(i)return i;const r=this.A,h=this.H,n=this.G,c=new Uint8Array(h*n*4),a=r.getParameter(r.READ_FRAMEBUFFER_BINDING);r.bindFramebuffer(r.READ_FRAMEBUFFER,this.N),r.readBuffer(r.COLOR_ATTACHMENT0+t),r.readPixels(0,0,h,n,r.RGBA,r.UNSIGNED_BYTE,c),r.bindFramebuffer(r.READ_FRAMEBUFFER,a);const u=4*h,f=new Uint8Array(c.length);for(let d=0;d<n;d++){const g=(n-1-d)*u,m=d*u;f.set(c.subarray(g,g+u),m)}return this.j.set(t,f),f}begin(){const t=this.A;this.j.clear(),this.W.et(),this.W.it(this.N,this.H,this.G),this.l.depth&&t.clear(t.DEPTH_BUFFER_BIT),this.W.state.rt()}end(){this.W.state.nt(),this.W.ot();const t=this.W.ht();this.W.it(t.framebuffer,t.viewport[2],t.viewport[3])}ct(){return this.Z||this.lt(),this.Z}lt(){if(!this.W)return;const t={Ud:this.X[0],Ue:this.X[1],Uf:this.X[2],Ug:[this.H,this.G]},i=Z.V;this.Z=this.W.ft.ut(i,t,!0)}D(){const t=this.A;t.deleteFramebuffer(this.N);for(const i of this.X)t.deleteTexture(i);this.Y&&t.deleteRenderbuffer(this.Y)}get width(){return this.H}get height(){return this.G}get textures(){return this.X}get attachmentCount(){return this.K}};l(Z,"V",null);let q=Z;const Dt=new WeakMap;function ft(o,t){Dt.set(o,t)}function Mt(o){return Dt.get(o)}function it(o,t,i,r,h=255){o[0]=t/255,o[1]=(i??t)/255,o[2]=(r??t)/255,o[3]=h/255}class rt{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,"xt",[0,0,0,1]);l(this,"Mt",!1);l(this,"Ft",!1);l(this,"$t",!1);l(this,"Tt",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,It:0,Lt:0,At:0,yt:0,wt:0,Tt:0,Ot:!1,Dt:!1,$t:!1,Et:!1,Ht:[0,0,0],Bt:[1,1,1,1],Gt:[0,0,0,1]}}Nt(t){t.kt=this.dt,t.zt=this.gt,t.It=this.vt,t.Lt=this._t,t.At=this.At,t.yt=this.yt,t.wt=this.wt,t.Ot=this.Mt,t.Dt=this.Ft,t.$t=this.$t,t.Tt=this.Tt,t.Et=this.Et,t.Ht[0]=this.bt[0],t.Ht[1]=this.bt[1],t.Ht[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.xt[0],t.Gt[1]=this.xt[1],t.Gt[2]=this.xt[2],t.Gt[3]=this.xt[3]}Xt(t){this.dt=t.kt,this.gt=t.zt,this.vt=t.It,this._t=t.Lt,this.At=t.At,this.yt=t.yt,this.wt=t.wt,this.Mt=t.Ot,this.Ft=t.Dt,this.$t=t.$t,this.Tt=t.Tt,this.Et=t.Et,this.bt[0]=t.Ht[0],this.bt[1]=t.Ht[1],this.bt[2]=t.Ht[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.xt[0]=t.Gt[0],this.xt[1]=t.Gt[1],this.xt[2]=t.Gt[2],this.xt[3]=t.Gt[3]}rt(){let t=this.St.pop();t||(t=rt.Ut()),this.Nt(t),this.Rt.push(t)}nt(){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,h=255){it(this.Ct,t,i,r,h)}rs(t,i,r,h=255){it(this.xt,t,i,r,h)}ns(t){this.Mt=t}hs(t){this.Ft=t}cs(t){this.$t=t}ls(t){this.Tt=Ft(t)}us(t,i,r,h){it(this.Pt,t,i,r,h)}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]),Y={ds:16,ps:WebGL2RenderingContext.TRIANGLES,gs:{vs:{size:2,offset:0},_s:{size:2,offset:8}}};class jt{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,h){const n=this.A,c=Mt(this.A),a=c[2],u=c[3],f=t/a*2-1,d=(t+r)/a*2-1,g=1-(i+h)/u*2,m=1-i/u*2,p=dt,v=this.ws;for(let A=0;A<p.length;A+=4){const E=p[A],y=p[A+1],T=p[A+2],w=p[A+3],F=f+(E+.5)*(d-f),b=g+(y+.5)*(m-g);v[A]=F,v[A+1]=b,v[A+2]=T,v[A+3]=w}n.bindBuffer(n.ARRAY_BUFFER,this.As),n.bufferData(n.ARRAY_BUFFER,v,n.DYNAMIC_DRAW),n.enableVertexAttribArray(0),n.vertexAttribPointer(0,2,n.FLOAT,!1,16,0),n.drawArrays(n.TRIANGLES,0,6),n.disableVertexAttribArray(0),n.bindBuffer(n.ARRAY_BUFFER,null)}D(){this.A.deleteBuffer(this.As)}}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 kt={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,h){const n=this.A;let c=this.Cs.get(t);c||(c=new Map,this.Cs.set(t,c));let a=c.get(i)||null;if(!a){a=n.createVertexArray(),c.set(i,a),n.bindVertexArray(a),n.bindBuffer(n.ARRAY_BUFFER,h);const u=n.getAttribLocation(t,"A0");u!==-1&&ut(n,u,r.gs.vs.size,r.ds,r.gs.vs.offset,0,n.FLOAT,!1);const f=n.getAttribLocation(t,"A1");f!==-1&&ut(n,f,r.gs._s.size,r.ds,r.gs._s.offset,0,n.FLOAT,!1)}n.bindVertexArray(a)}Fs(){this.A.bindVertexArray(null)}D(){for(const[,t]of this.Cs)for(const[,i]of t)i&&this.A.deleteVertexArray(i)}}const G=class G{static $s(t,i,r=0){const h=i||new Float32Array(G.FLOATS_PER_INSTANCE);let n=r;h[n++]=t.vs[0],h[n++]=t.vs[1],h[n++]=t.Ts[0],h[n++]=t.Ts[1],h[n++]=t.Ht[0],h[n++]=t.Ht[1],h[n++]=t.Ht[2],h[n++]=t.Bt[0],h[n++]=t.Bt[1],h[n++]=t.Bt[2],h[n++]=t.Bt[3],h[n++]=t.Gt[0],h[n++]=t.Gt[1],h[n++]=t.Gt[2],h[n++]=t.Gt[3],h[n++]=t.Ps[0],h[n++]=t.Ps[1],h[n++]=t.Ps[2],h[n++]=t.Tt;const c=t.Es;h[n++]=(c==null?void 0:c[0])??0,h[n++]=(c==null?void 0:c[1])??0,h[n++]=(c==null?void 0:c[2])??0;const a=t.Rs;h[n++]=(a==null?void 0:a[0])??0,h[n++]=(a==null?void 0:a[1])??0,h[n++]=(a==null?void 0:a[2])??0;const u=t.Ss,f=t.Us,d=t.ks,g=t.zs,m=t.Is,p=!(!f||!d);return p?(h[n++]=(g==null?void 0:g[0])??0,h[n++]=(g==null?void 0:g[1])??0,h[n++]=(m==null?void 0:m[0])??0,h[n++]=(m==null?void 0:m[1])??0,h[n++]=f[0],h[n++]=f[1],h[n++]=d[0],h[n++]=d[1]):!p&&!!u?(h[n++]=u[0],h[n++]=u[1],h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0):(h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0),h[n++]=t.Ls??0,h[n++]=t.Os??0,h[n++]=t.Ds??0,h}static Hs(t,i){const r=t.length*G.FLOATS_PER_INSTANCE,h=i||new Float32Array(r);for(let n=0;n<t.length;n++){const c=n*G.FLOATS_PER_INSTANCE;G.$s(t[n],h,c)}return h}};l(G,"BYTES_PER_INSTANCE",144),l(G,"FLOATS_PER_INSTANCE",36);let N=G;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 Q=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 h=i*N.FLOATS_PER_INSTANCE,n=new Float32Array(h),c=r*N.FLOATS_PER_INSTANCE;n.set(this.Bs.subarray(0,Math.min(c,this.Xs))),this.Bs=n}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 h=t.curveParams0,n=t.curveParams1;return i[r+25]=h[0],i[r+26]=h[1],i[r+27]=h[2],i[r+28]=h[3],i[r+29]=n[0],i[r+30]=n[1],i[r+31]=n[2],i[r+32]=n[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;Ct(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 h=i*N.FLOATS_PER_INSTANCE;r.bufferSubData(r.ARRAY_BUFFER,0,t,0,h)}ae(t){let i=this.re.get(t);if(!i){i=new Map;const r=this.A;for(const h in Q.ATTRIBUTES){const n=r.getAttribLocation(t,h);n!==-1&&i.set(h,n)}this.re.set(t,i)}return i}ce(t){const i=this.A,r=t.O,h=this.ae(r);for(const[n,c]of h){const a=Q.ATTRIBUTES[n];a&&ut(i,c,a.size,a.stride,a.offset,a.divisor,a.type,a.normalized)}}le(t){const i=this.A,r=this.ae(t.O);for(const[h,n]of r)Q.ATTRIBUTES[h]&&(i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0))}D(){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 h,n,c,a,u,f,d,g,m,p;const i=[0,0,0,0],r=[0,0,0,0];return t.Us&&t.ks?(i[0]=((h=t.zs)==null?void 0:h[0])??0,i[1]=((n=t.zs)==null?void 0:n[1])??0,i[2]=((c=t.Is)==null?void 0:c[0])??0,i[3]=((a=t.Is)==null?void 0:a[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.Ts[0],height:t.Ts[1],char0:t.Ht[0],char1:t.Ht[1],char2:t.Ht[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.Tt,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:((m=t.Rs)==null?void 0:m[1])??0,rotationZ:((p=t.Rs)==null?void 0:p[2])??0,curveParams0:i,curveParams1:r,depth:t.Ls||0,baseZ:t.Os||0,geometryType:t.Ds||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)}D(){this.fe.D()}}class z{constructor(t,i,r,h){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=h;const n=this.A.createBuffer();Ct(this.A,this.A.ARRAY_BUFFER,n,this._e.ye,this.A.STATIC_DRAW),this.Ae=n}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}D(){this.ve.D(),this.A.deleteBuffer(this.Ae)}Ce(t,i,r){return this.ve.de(t)}xe(t,i,r,h,n,c){const a=n.zt??0,u=n.It??0,f=n.Lt??0,d=n.At??0,g=n.yt??0,m=n.wt??0,p=[0,0,0,0],v=[0,0,0,0];c&&(c.bezStartX!==void 0&&c.bezStartY!==void 0&&c.bezEndX!==void 0&&c.bezEndY!==void 0?(p[0]=c.cp1x??0,p[1]=c.cp1y??0,p[2]=c.cp2x??0,p[3]=c.cp2y??0,v[0]=c.bezStartX??0,v[1]=c.bezStartY??0,v[2]=c.bezEndX??0,v[3]=c.bezEndY??0):c.arcStart===void 0&&c.arcStop===void 0||(p[0]=c.arcStart??0,p[1]=c.arcStop??0));const A={x:t,y:i,width:r,height:h,char0:n.Ht[0],char1:n.Ht[1],char2:n.Ht[2],r1:n.Bt[0],g1:n.Bt[1],b1:n.Bt[2],a1:n.Bt[3],r2:n.Gt[0],g2:n.Gt[1],b2:n.Gt[2],a2:n.Gt[3],invert:n.$t?1:0,flipX:n.Ot?1:0,flipY:n.Dt?1:0,charRot:n.Tt,translationX:a,translationY:u,translationZ:f,rotationX:d,rotationY:g,rotationZ:m,curveParams0:p,curveParams1:v,depth:(c==null?void 0:c.depth)??0,baseZ:(c==null?void 0:c.baseZ)??0,geometryType:kt[this.me]??0};return this.ve.se(A)}}const ee={ye:dt,Me:6,...Y},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]),Me:6,...Y},re={ye:function(o=32){const t=[],i=2*Math.PI/o;for(let r=0;r<o;r++){const h=r*i,n=(r+1)%o*i,c=Math.cos(h),a=Math.sin(h),u=.5*(c+1),f=.5*(a+1),d=Math.cos(n),g=Math.sin(n),m=.5*(d+1),p=.5*(g+1);t.push(0,0,.5,.5,c,a,u,f,d,g,m,p)}return new Float32Array(t)}(32),Me:96,...Y};let se={ye:function(o){const t=[];for(let i=0;i<o;i++){const r=i/o,h=(i+1)/o;t.push(r,0,r,0,r,1,r,1,h,1,h,1)}return new Float32Array(t)}(32),Me:96,...Y};const ne={ye:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),Me:3,...Y},he={ye:function(o=16){const t=[];for(let i=0;i<o;i++){const r=i/o,h=(i+1)/o;t.push(r,-.5,r,0,h,-.5,h,0,r,.5,r,1,r,.5,r,1,h,-.5,h,0,h,.5,h,1)}return new Float32Array(t)}(16),Me:96,...Y},oe={[C.RECTANGLE]:class extends z{constructor(o,t){super(o,t,C.RECTANGLE,ee)}de(o,t){return this.xe(0,0,o.width,o.height,t)}},[C.LINE]:class extends z{constructor(o,t){super(o,t,C.LINE,ie)}de(o,t){const i=o.x2-o.x1,r=o.y2-o.y1,h=Math.hypot(i,r),n=Math.atan2(r,i),c=t.kt||1,a=o.x1+i/2-h/2,u=o.y1+r/2,f={...t,wt:(t.wt||0)+n};return this.xe(a,u,h,c,f)}},[C.ELLIPSE]:class extends z{constructor(o,t){super(o,t,C.ELLIPSE,re)}de(o,t){return this.xe(0,0,o.width,o.height,t)}},[C.ARC]:class extends z{constructor(o,t){super(o,t,C.ARC,se)}de(o,t){const i=o.start*Math.PI/180,r=o.stop*Math.PI/180;return this.xe(0,0,o.width,o.height,t,{arcStart:i,arcStop:r})}},[C.TRIANGLE]:class extends z{constructor(o,t){super(o,t,C.TRIANGLE,ne)}de(o,t){const i=Math.min(o.x1,o.x2,o.x3),r=Math.max(o.x1,o.x2,o.x3),h=Math.min(o.y1,o.y2,o.y3),n=r-i,c=Math.max(o.y1,o.y2,o.y3)-h;return this.xe(i,h,n,c,t)}},[C.BEZIER_CURVE]:class extends z{constructor(o,t){super(o,t,C.BEZIER_CURVE,he)}de(o,t){return this.xe(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,"$e");this.A=t,this.$e=new qt(t),this.Fe=new Map;for(const i of Object.values(C)){const r=new te(t),h=new oe[i](t,r);this.Fe.set(i,h)}}Te(t){const i=this.Pe(t);for(const r of i)this.Ee(r)}Pe(t){const i=[];let r=null,h=null,n=null;for(const c of t)h!==c.material||n!==c.type?(r&&r.length>0&&i.push({material:h,type:n,commands:r}),r=[c],h=c.material,n=c.type):r.push(c);return r&&r.length>0&&i.push({material:h,type:n,commands:r}),i}Ee(t){const{material:i,type:r,commands:h}=t,n=this.Fe.get(r);i.shader.U(),i.shader.I(i.uniforms);const c=Mt(this.A),a=h.length>0&&h[0].state.Et;i.shader.I({Uh:c[2]/c[3],Ua:[c[2],c[3]],Ub:1,Uc:a?1:0}),n.we();for(const u of h)n.de(u.params,u.state);if(n.be()){const u=n.unitGeometry,f=n.unitBuffer;try{this.$e.Ms(i.shader.O,r+"",u,f),n.batch.ce(i.shader),n.batch.bs(u.ps,u.Me)}finally{n.batch.le(i.shader),this.$e.Fs(),n.we()}}}D(){for(const t of this.Fe.values())t.D();this.Fe.clear(),this.$e.D()}}function Pt(o){let t=0;for(let i=0;i<o.length;i++)t=(t<<5)-t+o.charCodeAt(i),t&=t;return t}function Bt(o){return Pt(o+"")}function J(o,t){return(o<<5)-o+t}class ce{constructor(t){l(this,"A");l(this,"Re",0);l(this,"Se");l(this,"ke");l(this,"ze",new Map);this.A=t,this.Se=new W(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;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.Ie(this.Se,{}),isBuiltIn:!0}}get Le(){return this.ke}ut(t,i={},r=!1){const h=this.Ie(t,i),n=this.ze.get(h);if(n)return n;const c={id:this.Re++,shader:t,uniforms:Object.freeze({...i}),hash:h,isBuiltIn:r};return this.ze.set(h,c),c}Oe(t,i={}){return{id:this.Re++,shader:t,uniforms:Object.freeze({...i}),hash:0,isBuiltIn:!1}}Ie(t,i){const r=Bt(t.O),h=function(n,c){let a=0;const u=Object.keys(n).sort();for(const f of u)a=J(a,Pt(f)),a=J(a,c(n[f]));return a}(i,this.De.bind(this));return J(r,h)}De(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 h=Array.isArray(i[0])?i.flat():i;for(const n of h)r=J(r,typeof n=="number"?n:0);return r}(t):t instanceof Float32Array||t instanceof Int32Array?function(i){let r=0;const h=Math.min(i.length,16);for(let n=0;n<h;n++)r=J(r,i[n]);return r}(t):t instanceof WebGLTexture?Bt(t):0}D(){this.Se!=this.Se&&this.Se.D(),this.Se.D(),this.ze.clear()}}class le{constructor(){l(this,"He",[]);l(this,"Be",1);l(this,"Ts",0)}Ge(t,i){if(this.Ts>=this.He.length){const h={id:this.Be++,type:t,params:{},state:rt.Ut(),material:i};this.He.push(h)}const r=this.He[this.Ts];return r.id=this.Be++,r.type=t,r.material=i,this.Ts++,r}Ne(t,i,r){const h=this.Ge(C.RECTANGLE,r),n=h.params;return n.width=t.width,n.height=t.height,i.Yt(h.state),h.id}Xe(t,i,r){const h=this.Ge(C.LINE,r),n=h.params;return n.x1=t.x1,n.y1=t.y1,n.x2=t.x2,n.y2=t.y2,n.thickness=t.thickness,i.Yt(h.state),h.id}Ye(t,i,r){const h=this.Ge(C.ELLIPSE,r),n=h.params;return n.width=t.width,n.height=t.height,n.startAngle=t.startAngle,n.endAngle=t.endAngle,n.segments=t.segments,i.Yt(h.state),h.id}Ke(t,i,r){const h=this.Ge(C.ARC,r),n=h.params;return n.width=t.width,n.height=t.height,n.start=t.start,n.stop=t.stop,i.Yt(h.state),h.id}We(t,i,r){const h=this.Ge(C.TRIANGLE,r),n=h.params;return n.x1=t.x1,n.y1=t.y1,n.x2=t.x2,n.y2=t.y2,n.x3=t.x3,n.y3=t.y3,i.Yt(h.state),h.id}Ze(t,i,r){const h=this.Ge(C.BEZIER_CURVE,r),n=h.params;return n.x1=t.x1,n.y1=t.y1,n.cp1x=t.cp1x,n.cp1y=t.cp1y,n.cp2x=t.cp2x,n.cp2y=t.cp2y,n.x2=t.x2,n.y2=t.y2,n.thickness=t.thickness,n.segments=t.segments,i.Yt(h.state),h.id}ge(){this.Ts=0}[Symbol.iterator](){let t=0;const i=this.Ts,r=this.He;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,"ft");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 rt,this.ft=new ce(t),this.Qe=new le,this.Ve=new ae(t),this.Je=new jt(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}et(){this.ei.push(this.ri),this.ii.push([...this.ni])}ht(){return{framebuffer:this.ei.pop()??null,viewport:this.ii.pop()??[0,0,this.A.canvas.width,this.A.canvas.height]}}it(t,i,r){const h=this.A;this.ri!==t&&(h.bindFramebuffer(h.FRAMEBUFFER,t),this.ri=t);const n=[0,0,i,r];this.ni[0]===n[0]&&this.ni[1]===n[1]&&this.ni[2]===n[2]&&this.ni[3]===n[3]||(h.viewport(...n),ft(h,n),this.ni=n)}oi(t){this.je!==t&&(this.je=t,t.U())}hi(t,i){return new W(this.A,t,i)}ai(t){this.ti=t,t&&(this.si={})}L(t,i){this.si[t]=i}ci(t){Object.assign(this.si,t)}li(t){return new W(this.A,et,t)}ui(t,i,r){this.Qe.Ne({width:i??t.width,height:r??t.height},this.qe,t.ct())}fi(t,i,r,h){this.Je.bs(t,i,r,h)}di(t,i){if(this.ti){const r=this.ft.Oe(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.ft.Le)}pi(t,i,r,h){this.Qe.Xe({x1:t,y1:i,x2:r,y2:h},this.qe,this.ft.Le)}gi(t,i){this.Qe.Ye({width:t,height:i},this.qe,this.ft.Le)}mi(t,i,r,h,n,c){this.Qe.We({x1:t,y1:i,x2:r,y2:h,x3:n,y3:c},this.qe,this.ft.Le)}_i(t,i,r,h,n,c,a,u){this.Qe.Ze({x1:t,y1:i,cp1x:r,cp1y:h,cp2x:n,cp2y:c,x2:a,y2:u},this.qe,this.ft.Le)}Ai(t,i,r,h){this.Qe.Ke({width:t,height:i,start:r,stop:h},this.qe,this.ft.Le)}yi(t,i,r=1,h={}){return new q(this.A,t,i,r,h,this)}wi(t,i=t,r=t,h=255){this.qe.us(t,i??t,r??t,h);const[n,c,a,u]=this.qe.canvasBackgroundColor;this.ge(n,c,a,u)}ge(t=0,i=0,r=0,h=0){this.A.clearColor(t,i,r,h),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)}ot(){const t=this.Qe;this.Ve.Te(t),t.ge()}D(){this.ft.D(),this.Ve.D(),this.Je.D()}get context(){return this.A}get state(){return this.qe}get materialManager(){return this.ft}}const D={readShort:(o,t)=>(D.t.uint16[0]=o[t]<<8|o[t+1],D.t.int16[0]),readUshort:(o,t)=>o[t]<<8|o[t+1],readUshorts(o,t,i){const r=[];for(let h=0;h<i;h++)r.push(D.readUshort(o,t+2*h));return r},readUint(o,t){const i=D.t.uint8;return i[3]=o[t],i[2]=o[t+1],i[1]=o[t+2],i[0]=o[t+3],D.t.uint32[0]},readASCII(o,t,i){let r="";for(let h=0;h<i;h++)r+=String.fromCharCode(o[t+h]);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 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 h=0;const n=D.t;for(let c=t;c<r;c+=4)n.uint8[3]=o[c]||0,n.uint8[2]=o[c+1]||0,n.uint8[1]=o[c+2]||0,n.uint8[0]=o[c+3]||0,h=h+(n.uint32[0]>>>0)>>>0;return h>>>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 $(o){let t=32,i=0;for(const a of o)a&&(a<t&&(t=a),a>i&&(i=a));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const a of o)a&&r[a]++;const h=new Uint32Array(i+1);let n=0;r[0]=0;for(let a=1;a<=i;a++)n=n+r[a-1]<<1,h[a]=n;const c=new Map;for(let a=0;a<o.length;a++){const u=o[a];if(!u)continue;const f=h[u]++;let d=c.get(u);d||(d=[],c.set(u,d)),d[ge(f,u)]=a}return{min:t,max:i,table:c}}function At(o,t){let i=0;for(let r=1;r<=t.max;r++){i|=o.readBits(1)<<r-1;const h=t.table.get(r);if(h&&i<h.length){const n=h[i];if(n!==void 0)return n}}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 h=[];return function(n,c){const a=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],u=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],f=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],d=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];let g=0;for(;!g;){g=n.readBits(1);const m=n.readBits(2);if(m===0){n.alignToByte();const p=n.readBits(16);if((65535&(65535^p))!==n.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let v=0;v<p;v++)c.push(n.readBits(8))}else{if(m!==1&&m!==2)throw Error("Unsupported DEFLATE type");{let p,v;if(m===1){const A=Array(288).fill(0);for(let E=0;E<=143;E++)A[E]=8;for(let E=144;E<=255;E++)A[E]=9;for(let E=256;E<=279;E++)A[E]=7;for(let E=280;E<=287;E++)A[E]=8;p=$(A),v=$(Array(32).fill(5))}else{const A=n.readBits(5)+257,E=n.readBits(5)+1,y=n.readBits(4)+4,T=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],w=Array(19).fill(0);for(let B=0;B<y;B++)w[T[B]]=n.readBits(3);const F=$(w),b=[];for(;b.length<A+E;){const B=At(n,F);if(B<=15)b.push(B);else if(B===16){const I=n.readBits(2)+3,U=b[b.length-1]||0;for(let ct=0;ct<I;ct++)b.push(U)}else if(B===17){const I=n.readBits(3)+3;for(let U=0;U<I;U++)b.push(0)}else{if(B!==18)throw Error("Invalid code length symbol");{const I=n.readBits(7)+11;for(let U=0;U<I;U++)b.push(0)}}}const P=b.slice(0,A),L=b.slice(A,A+E);p=$(P),v=$(L)}for(;;){const A=At(n,p);if(A<256)c.push(A);else{if(A===256)break;if(A>256&&A<286){const E=A-257;let y=a[E];const T=u[E];T&&(y+=n.readBits(T));const w=At(n,v);if(w>=30)throw Error("Invalid distance symbol");let F=f[w];const b=d[w];b&&(F+=n.readBits(b));const P=c.length-F;if(P<0)throw Error("Invalid distance");for(let L=0;L<y;L++)c.push(c[P+L]||0)}else if(A===286||A===287)throw Error("Reserved length symbol")}}}}}}(new de(o.subarray(r)),h),new Uint8Array(h)}function pe(o){const t=D,i=new Uint8Array(o);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),h=t.readUshort(i,12),n=t.readUint(i,16),c=[];let a=44;for(let y=0;y<h;y++){const T=t.readASCII(i,a,4),w=t.readUint(i,a+4),F=t.readUint(i,a+8),b=t.readUint(i,a+12),P=t.readUint(i,a+16);c.push({tag:T,offset:w,compLength:F,origLength:b,checksum:P}),a+=20}for(const y of c){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 w=new Uint8Array(y.origLength);w.set(y.data),y.data=w}else y.data=y.data.subarray(0,y.origLength)}const u=h;let f=1,d=0;for(;f<<1<=u;)f<<=1,d++;const g=16*f,m=16*u-g;let p=12+16*u;const v={};for(const y of c)v[y.tag]=p,p=st(p+y.data.length);const A=new Uint8Array(Math.max(n||0,p));O(A,0,r),nt(A,4,u),nt(A,6,g),nt(A,8,d),nt(A,10,m);let E=12;for(const y of c){fe(A,E,y.tag),E+=4;let T=y.data;if(y.tag==="head"&&T.length>=12){const w=new Uint8Array(T);O(w,8,0),O(A,E,gt(w,0,st(w.length))),E+=4}else O(A,E,gt(T,0,st(T.length))),E+=4;O(A,E,v[y.tag]),E+=4,O(A,E,y.data.length),E+=4}for(const y of c){const T=v[y.tag];A.set(y.data,T)}if(c.find(y=>y.tag==="head")){const y=v.head,T=function(w,F){const b=F+8,P=[w[b],w[b+1],w[b+2],w[b+3]];O(w,b,0);const L=2981146554-(gt(w,0,st(w.length))>>>0)>>>0;return w[b]=P[0],w[b+1]=P[1],w[b+2]=P[2],w[b+3]=P[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 h=D,n=h.readUshort,c=n(o,t+=2);t+=2;const a=[];for(let u=0;u<c;u++){const f=n(o,t),d=n(o,t+=2);t+=2;const g=h.readUint(o,t);t+=4;const m=`p${f}e${d}`;let p=a.indexOf(g);if(p===-1){let v;p=r.tables.length,a.push(g);const A=n(o,g);v=A===4?this.parse4(o,g):A===12?this.parse12(o,g):{format:A},r.tables.push(v)}r.ids[m]=p}return r},parse4(o,t){const i=D,r=i.readUshort,h=i.readUshorts,n=t,c=r(o,t+=2);t+=2;const a=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=h(o,t,a),t+=2*a,t+=2,u.startCount=h(o,t,a),t+=2*a;for(let f=0;f<a;f++)u.idDelta.push(i.readShort(o,t)),t+=2;return u.idRangeOffset=h(o,t,a),t+=2*a,u.glyphIdArray=h(o,t,n+c-t>>1),u},parse12(o,t){const i=D.readUint;i(o,t+=4),i(o,t+=4);const r=i(o,t+=4);t+=4;const h=new Uint32Array(3*r);for(let n=0;n<3*r;n+=3)h[n]=i(o,t+(n<<2)),h[n+1]=i(o,t+(n<<2)+4),h[n+2]=i(o,t+(n<<2)+8);return{format:12,groups:h}}},ve={parseTab(o,t,i){const r=D;t+=18;const h=r.readUshort(o,t);t+=2,t+=16;const n=r.readShort(o,t);t+=2;const c=r.readShort(o,t);t+=2;const a=r.readShort(o,t);t+=2;const u=r.readShort(o,t);return t+=2,t+=6,{unitsPerEm:h,xMin:n,yMin:c,xMax:a,yMax:u,indexToLocFormat:r.readShort(o,t)}}},ye={parseTab(o,t,i){const r=D;t+=4;const h=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],n={};for(let c=0;c<h.length;c++){const a=h[c],u=a==="advanceWidthMax"||a==="numberOfHMetrics"?r.readUshort:r.readShort;n[a]=u(o,t+2*c)}return n}},Ee={parseTab(o,t,i,r){const h=D,n=[],c=[],a=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,d=0,g=0;for(;g<u;)f=h.readUshort(o,t+(g<<2)),d=h.readShort(o,t+(g<<2)+2),n.push(f),c.push(d),g++;for(;g<a;)n.push(f),c.push(d),g++;return{aWidth:n,lsBearing:c}}},St={cmap:me,head:ve,hhea:ye,maxp:{parseTab(o,t,i){const r=D;return r.readUint(o,t),t+=4,{numGlyphs:r.readUshort(o,t)}}},hmtx:Ee,loca:{parseTab(o,t,i,r){const h=D,n=[],c=r.head.indexToLocFormat,a=r.maxp.numGlyphs+1;if(c===0)for(let u=0;u<a;u++)n.push(h.readUshort(o,t+(u<<1))<<1);else if(c===1)for(let u=0;u<a;u++)n.push(h.readUint(o,t+(u<<2)));return n}},glyf:{parseTab(o,t,i,r){const h=[],n=r.maxp.numGlyphs;for(let c=0;c<n;c++)h.push(null);return h},Ci(o,t){const i=D,r=o.xi,h=o.loca;if(h[t]===h[t+1])return null;const n=K.findTable(r,"glyf",o.Mi);if(!n)return null;let c=n[0]+h[t];const a={};if(a.noc=i.readShort(r,c),c+=2,a.xMin=i.readShort(r,c),c+=2,a.yMin=i.readShort(r,c),c+=2,a.xMax=i.readShort(r,c),c+=2,a.yMax=i.readShort(r,c),c+=2,a.xMin>=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(let m=0;m<a.noc;m++)a.endPts.push(i.readUshort(r,c)),c+=2;const u=i.readUshort(r,c);if(c+=2,r.length-c<u)return null;c+=u;const f=a.endPts[a.noc-1]+1;a.flags=[];for(let m=0;m<f;m++){const p=r[c];if(c++,a.flags.push(p),8&p){const v=r[c];c++;for(let A=0;A<v;A++)a.flags.push(p),m++}}a.xs=[];for(let m=0;m<f;m++){const p=a.flags[m],v=!!(16&p);2&p?(a.xs.push(v?r[c]:-r[c]),c++):v?a.xs.push(0):(a.xs.push(i.readShort(r,c)),c+=2)}a.ys=[];for(let m=0;m<f;m++){const p=a.flags[m],v=!!(32&p);4&p?(a.ys.push(v?r[c]:-r[c]),c++):v?a.ys.push(0):(a.ys.push(i.readShort(r,c)),c+=2)}let d=0,g=0;for(let m=0;m<f;m++)d+=a.xs[m],g+=a.ys[m],a.xs[m]=d,a.ys[m]=g}else a.parts=[],a.endPts=[],a.flags=[],a.xs=[],a.ys=[];return a}}},K={parse(o){const t=new Uint8Array(o);D.readASCII(t,0,4)==="wOFF"&&(o=pe(o));const i=new Uint8Array(o),r=St,h={},n={xi:i,Fi:0,Mi:0};for(const c in r){const a=c,u=K.findTable(i,a,0);if(u){const[f,d]=u;let g=h[f];g==null&&(g=r[a].parseTab(i,f,d,n),h[f]=g),n[a]=g}}return[n]},findTable(o,t,i){const r=D,h=r.readUshort(o,i+4);let n=i+12;for(let c=0;c<h;c++){const a=r.readASCII(o,n,4);r.readUint(o,n+4);const u=r.readUint(o,n+8),f=r.readUint(o,n+12);if(a===t)return[u,f];n+=16}return null},T:St,B:D};class we{$i(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(h=>{if(h.format===4){const n=this.Ti(h);i.push(...n)}else if(h.format===12){const n=this.Pi(h);i.push(...n)}}),[...new Set(i)]):[]}Ti(t){const i=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return i;for(let r=0;r<t.startCount.length;r++){const h=t.startCount[r],n=t.endCount[r];if(h!==65535||n!==65535){for(let c=h;c<=n;c++)if(this.Ei(t,c,r)>0)try{const a=String.fromCodePoint(c);i.push(a)}catch{}}}return i}Pi(t){const i=[];if(!t.groups)return i;for(let r=0;r<t.groups.length;r+=3){const h=t.groups[r],n=t.groups[r+1],c=t.groups[r+2];for(let a=h;a<=n;a++)if(c+(a-h)>0)try{const u=String.fromCodePoint(a);i.push(u)}catch{}}return i}Ei(t,i,r){if(t.idRangeOffset[r]===0)return i+t.idDelta[r]&65535;{const h=t.idRangeOffset[r]/2+(i-t.startCount[r])-(t.startCount.length-r);if(h>=0&&t.glyphIdArray&&h<t.glyphIdArray.length){const n=t.glyphIdArray[h];if(n!==0)return n+t.idDelta[r]&65535}}return 0}}class pt{constructor(){l(this,"Ri",new Map);l(this,"Si",new Map)}Ui(t,i){const r=`${this.ki(t)}_${i}`;if(this.Ri.has(r))return this.Ri.get(r);const h=t.cmap;if(!h||!h.tables)return this.Ri.set(r,0),0;let n=0;for(const c of h.tables)if(c.format===4?n=this.zi(i,c):c.format===12&&(n=this.Ii(i,c)),n>0)break;return this.Ri.set(r,n),n}Li(t,i){const r=i.codePointAt(0);return r===void 0?0:this.Ui(t,r)}Oi(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}Di(t,i){const r=i/t.head.unitsPerEm,h=t.hhea.ascender*r,n=t.hhea.descender*r,c=t.hhea.lineGap*r;return{ascender:h,descender:n,lineGap:c,lineHeight:h-n+c,unitsPerEm:t.head.unitsPerEm,scale:r}}Hi(){this.Ri.clear(),this.Si.clear()}ki(t){return`${t.Mi}_${t.xi.length}`}zi(t,i){const r=i.endCount.length;let h=-1;for(let n=0;n<r;n++)if(t<=i.endCount[n]){h=n;break}if(h===-1||t<i.startCount[h])return 0;if(i.idRangeOffset[h]===0)return t+i.idDelta[h]&65535;{const n=i.idRangeOffset[h]/2+(t-i.startCount[h])-(r-h);if(n>=0&&n<i.glyphIdArray.length){const c=i.glyphIdArray[n];return c===0?0:c+i.idDelta[h]&65535}}return 0}Ii(t,i){const r=i.groups.length/3;for(let h=0;h<r;h++){const n=i.groups[3*h],c=i.groups[3*h+1],a=i.groups[3*h+2];if(t>=n&&t<=c)return a+(t-n)}return 0}}class Te{constructor(t){l(this,"Bi");l(this,"Gi");l(this,"W");l(this,"Ni");this.W=t,this.Ni=new pt,this.Bi=document.createElement("canvas"),this.Gi=this.Bi.getContext("2d",{willReadFrequently:!0,alpha:!0})}Xi(t,i,r,h){const n=t.length,c=Math.ceil(Math.sqrt(n)),a=Math.ceil(n/c),u=i.width*c,f=i.height*a;this.Yi(u,f),this.Ki(t,i,c,r,h);const d=this.W.yi(u,f,1,{filter:"nearest"});return d.st(this.Bi),{framebuffer:d,columns:c,rows:a}}Yi(t,i){this.Bi.width=t,this.Bi.height=i,this.Bi.style.width=t+"px",this.Bi.style.height=i+"px",this.Gi.imageSmoothingEnabled=!1,this.Bi.style.imageRendering="pixelated",this.Gi.clearRect(0,0,t,i),this.Gi.textBaseline="top",this.Gi.textAlign="left",this.Gi.fillStyle="white"}Ki(t,i,r,h,n){const c=h/n.head.unitsPerEm;for(let a=0;a<t.length;a++){const u=a%r,f=Math.floor(a/r),d=t[a].character,g=this.Wi(n,d);if(!g)continue;const m=d.codePointAt(0)||0,p=this.Ni.Ui(n,m),v=this.Ni.Oi(n,p)*c,A=u*i.width,E=f*i.height,y=A+.5*i.width,T=E+.5*i.height,w=Math.round(y-.5*i.width),F=Math.round(T-.5*h),b=w+.5*(i.width-v),P=F+n.hhea.ascender*c;this.Zi(g,b,P,c)}}Wi(t,i){const r=i.codePointAt(0)||0,h=this.Ni.Ui(t,r);return h===0?null:K.T.glyf.Ci(t,h)}Zi(t,i,r,h){if(!t||!t.xs||t.noc===0)return;let{xs:n,ys:c,endPts:a,flags:u}=t;if(!(n&&c&&a&&u))return;this.Gi.beginPath();let f=0;for(let d=0;d<a.length;d++){const g=a[d];if(!(g<f)){if(g>=f){const m=i+n[f]*h,p=r-c[f]*h;this.Gi.moveTo(m,p);let v=f+1;for(;v<=g;)if(1&u[v]){const A=i+n[v]*h,E=r-c[v]*h;this.Gi.lineTo(A,E),v++}else{const A=i+n[v]*h,E=r-c[v]*h;if(v+1>g){const T=i+n[f]*h,w=r-c[f]*h;if(1&u[f])this.Gi.quadraticCurveTo(A,E,T,w);else{const F=(A+T)/2,b=(E+w)/2;this.Gi.quadraticCurveTo(A,E,F,b)}break}const y=v+1;if(1&u[y]){const T=i+n[y]*h,w=r-c[y]*h;this.Gi.quadraticCurveTo(A,E,T,w),v=y+1}else{const T=(A+(i+n[y]*h))/2,w=(E+(r-c[y]*h))/2;this.Gi.quadraticCurveTo(A,E,T,w),v=y}}this.Gi.closePath()}f=g+1}}this.Gi.fill()}}class be{constructor(){l(this,"ji");this.ji=new pt}Vi(t,i,r){let h=0;const n=this.ji.Di(r,i),c=n.lineHeight;for(const a of t){const u=this.ji.Li(r,a);if(u===0)continue;const f=this.ji.Oi(r,u)*n.scale;h=Math.max(h,f)}return{width:Math.ceil(h),height:Math.ceil(c)}}Hi(){this.ji.Hi()}}class xe{constructor(){l(this,"Ni");this.Ni=new pt}createCharacterObjects(t,i){return t.map((r,h)=>{const n=r.codePointAt(0)||0,c=this.qi(h);let a=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.Ni.Ui(i,n);u>0&&i.hmtx.aWidth[u]!==void 0&&(a=i.hmtx.aWidth[u])}return{character:r,unicode:n,color:c,advanceWidth:a}})}qi(t){return[t%256/255,Math.floor(t/256)%256/255,0]}Qi(t,i){if(!j.m(typeof t=="string","Character must be a string.",{method:"getCharacterColor",providedValue:t}))return[0,0,0];const r=i.find(h=>h.character===t);return r?r.color:[0,0,0]}Ji(t,i){return j.m(typeof t=="string"&&t.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:t})?Array.from(t).map(r=>this.Qi(r,i)||[0,0,0]):[[0,0,0]]}}class mt{constructor(t,i=16){l(this,"tr");l(this,"sr",[]);l(this,"er");l(this,"ir",16);l(this,"rr",0);l(this,"nr",0);l(this,"hr",{width:0,height:0});l(this,"ar");l(this,"cr",new Map);l(this,"lr");l(this,"ur");l(this,"dr");l(this,"pr");this.ir=i,this.lr=new we,this.ur=new Te(t),this.dr=new be,this.pr=new xe}async gr(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.vr(i),this.tr=K.parse(i)[0],await this.mr()}_r(t){if(t===void 0)return this.ir;this.ir=t,this.hr=this.dr.Vi(this.sr.map(r=>r.character),this.ir,this.tr);const i=this.ur.Xi(this.sr,this.hr,this.ir,this.tr);this.er=i.framebuffer,this.rr=i.columns,this.nr=i.rows}async Ar(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.vr(r);const h=K.parse(r);if(!h||h.length===0)throw Error("Failed to parse font file");this.tr=h[0],await this.mr()}catch(i){throw new R("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async vr(t){const i=Date.now();this.ar=new FontFace("CustomFont_"+i,t),await this.ar.load(),document.fonts.add(this.ar)}async mr(){const t=this.lr.$i(this.tr);this.cr.clear(),this.sr=this.pr.createCharacterObjects(t,this.tr),this.hr=this.dr.Vi(t,this.ir,this.tr);const i=this.ur.Xi(this.sr,this.hr,this.ir,this.tr);this.er=i.framebuffer,this.rr=i.columns,this.nr=i.rows}Qi(t){return this.pr.Qi(t,this.sr)}Ji(t){return this.pr.Ji(t,this.sr)}getGlyphData(t){if(!Number.isFinite(t))return null;const i=this.cr.get(t);if(i!==void 0)return i;const r=this.yr(t);if(r<0)return this.cr.set(t,null),null;const h=this.tr.glyf;if(!h)return this.cr.set(t,null),null;let n=h[r]??null;return n==null&&(n=K.T.glyf.Ci(this.tr,r)??null,h[r]=n),this.cr.set(t,n),n}yr(t){const i=this.tr.cmap;for(const r of i.tables)if(r.format===4){const h=r;for(let n=0;n<h.startCount.length;n++)if(t>=h.startCount[n]&&t<=h.endCount[n]){if(h.idRangeOffset[n]===0)return t+h.idDelta[n]&65535;{const c=h.idRangeOffset[n]/2+(t-h.startCount[n])-(h.startCount.length-n);if(c>=0&&c<h.glyphIdArray.length){const a=h.glyphIdArray[c];if(a!==0)return a+h.idDelta[n]&65535}}}}else if(r.format===12){const h=r;for(let n=0;n<h.groups.length;n+=3){const c=h.groups[n],a=h.groups[n+1],u=h.groups[n+2];if(t>=c&&t<=a)return u+(t-c)}}return 0}D(){this.er.D(),document.fonts.delete(this.ar)}get fontFramebuffer(){return this.er}get characters(){return this.sr}get textureColumns(){return this.rr}get textureRows(){return this.nr}get maxGlyphDimensions(){return this.hr}get fontSize(){return this.ir}get font(){return this.tr}}class vt{constructor(t,i,r){l(this,"wr");l(this,"br");l(this,"H");l(this,"G");l(this,"Cr");l(this,"Mr");l(this,"Fr");l(this,"$r");l(this,"Tr");this.Fr=t,this.$r=i,this.Tr=r,this.js()}js(){this.wr=Math.floor(this.Fr.width/this.$r),this.br=Math.floor(this.Fr.height/this.Tr),this.H=this.wr*this.$r,this.G=this.br*this.Tr,this.Cr=Math.floor((this.Fr.width-this.H)/2),this.Mr=Math.floor((this.Fr.height-this.G)/2)}Pr(t,i){this.$r=t,this.Tr=i,this.js()}get cellWidth(){return this.$r}get cellHeight(){return this.Tr}get cols(){return this.wr}get rows(){return this.br}get width(){return this.H}get height(){return this.G}get offsetX(){return this.Cr}get offsetY(){return this.Mr}}const Fe=/^#([0-9a-f]{3,8})$/i,Re=/^rgba?\(([^)]+)\)$/i;function yt(o){return Number.isNaN(o)?0:Math.max(0,Math.min(255,o))}function Ce(o){if(!o)return null;const t=o.trim().toLowerCase();if(!t||t==="transparent")return null;let i=null;return t.startsWith("#")?i=function(r){const h=Fe.exec(r.trim());if(!h)return null;const n=h[1];return n.length===3?[parseInt(n[0]+n[0],16),parseInt(n[1]+n[1],16),parseInt(n[2]+n[2],16),255]:n.length===4?[parseInt(n[0]+n[0],16),parseInt(n[1]+n[1],16),parseInt(n[2]+n[2],16),parseInt(n[3]+n[3],16)]:n.length===6||n.length===8?[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16),n.length===8?parseInt(n.slice(6,8),16):255]:null}(t):t.startsWith("rgb")&&(i=function(r){const h=Re.exec(r.trim());if(!h)return null;const n=h[1].split(",").map(d=>d.trim());if(n.length<3)return null;const c=yt(parseFloat(n[0])),a=yt(parseFloat(n[1])),u=yt(parseFloat(n[2])),f=n[3]!==void 0?255*Math.max(0,Math.min(1,parseFloat(n[3]))):255;return[c,a,u,Math.round(f)]}(t)),i?i[3]===0?null:i:null}class Ut{constructor(t={}){l(this,"Fr");l(this,"Er",null);l(this,"Rr",!1);l(this,"Sr");this.Rr=t.overlay??!1,this.Rr&&t.canvas?(this.Er=t.canvas,this.Fr=this.Ur(),this.Sr=!0,this.kr()):t.canvas?(this.Fr=t.canvas,this.Sr=!1):(this.Fr=this.zr(t.width,t.height),this.Sr=!0),this.Fr.style.imageRendering="pixelated"}zr(t,i){const r=document.createElement("canvas");return r.className="textmodeCanvas",r.style.imageRendering="pixelated",r.width=t||800,r.height=i||600,document.body.appendChild(r),r}Ur(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.Er.getBoundingClientRect();let r=Math.round(i.width),h=Math.round(i.height);if(this.Er instanceof HTMLVideoElement){const a=this.Er;(r===0||h===0)&&a.videoWidth>0&&a.videoHeight>0&&(r=a.videoWidth,h=a.videoHeight)}t.width=r,t.height=h,t.style.position="absolute",t.style.pointerEvents="none";const n=window.getComputedStyle(this.Er);let c=parseInt(n.zIndex||"0",10);return isNaN(c)&&(c=0),t.style.zIndex=""+(c+1),t}kr(){var t;this.Ir(),(t=this.Er.parentNode)==null||t.insertBefore(this.Fr,this.Er.nextSibling)}Lr(){const t=[];return this.Rr&&this.Er instanceof HTMLElement&&(t.push(this.Er),this.Er.parentElement&&t.push(this.Er.parentElement)),this.Fr.parentElement&&t.push(this.Fr.parentElement),t.push(this.Fr),t.push(document.body),t.push(document.documentElement),t}Or(){const t=this.Lr();for(const i of t){if(!i)continue;const r=Ce(window.getComputedStyle(i).backgroundColor);if(r)return r}return[255,255,255,255]}Ir(){if(!this.Er)return;const t=this.Er.getBoundingClientRect();let i=this.Er.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.Fr.style.top=t.top-r.top+"px",this.Fr.style.left=t.left-r.left+"px"}else this.Fr.style.top=t.top+window.scrollY+"px",this.Fr.style.left=t.left+window.scrollX+"px"}Dr(t,i){if(this.Rr){const r=this.Er.getBoundingClientRect();this.Fr.width=Math.round(r.width),this.Fr.height=Math.round(r.height),this.Ir()}else this.Fr.width=t??this.Fr.width,this.Fr.height=i??this.Fr.height}Hr(){const t=this.Fr.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}D(){const t=this.Fr.getContext("webgl")||this.Fr.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i==null||i.loseContext()}this.Sr&&this.Fr.parentNode&&this.Fr.parentNode.removeChild(this.Fr)}get canvas(){return this.Fr}get targetCanvas(){return this.Er}get width(){return this.Fr.width}get height(){return this.Fr.height}}function ht(o){return X(parseInt(o,16),0,255)}class M{constructor(t,i,r,h,n){l(this,"Br");l(this,"Gr");l(this,"Ht");l(this,"r");l(this,"g");l(this,"b");l(this,"a");this.r=X(t,0,255),this.g=X(i,0,255),this.b=X(r,0,255),this.a=X(h,0,255),this.Br=[this.r,this.g,this.b,this.a],this.Gr=[this.r/255,this.g/255,this.b/255,this.a/255],this.Ht=n?[...n]:void 0}static Nr(t,i,r,h){if(M.Xr(t))return t;if(Array.isArray(t))return function(n){if(n.length<3)throw Error("Component tuples must include at least RGB values.");const[c,a,u]=n,f=n.length===4?n[3]:255;return M.Yr(c,a,u,f)}(t);if(typeof t=="string"){const n=t.trim();if(n.length===0)throw Error("Color strings cannot be empty.");if(typeof i=="function"&&Array.from(n).length===1){const c=function(a,u){const f=u(a);if(!Array.isArray(f)||f.length===0)return null;const d=f[0];return!Array.isArray(d)||d.length<3?null:[d[0],d[1],d[2]]}(n,i);if(c)return M.Kr(c)}return M.Wr(n)}if(typeof t=="number")return typeof i=="number"&&typeof r=="number"?M.Yr(t,i,r,h??255):M.Zr(t);throw Error("Unsupported color input passed to TextmodeColor.$from.")}static Yr(t,i,r,h=255){return new M(t,i,r,h)}static Zr(t,i=255){return new M(t,t,t,i)}static Wr(t){return new M(...function(i){const r=i.replace(/^#|0x/gi,""),h=(n=r).length===3||n.length===4?n.split("").map(c=>c+c).join(""):n;var n;if(h.length!==6&&h.length!==8)throw Error("Invalid hex color: "+i);return[ht(h.slice(0,2)),ht(h.slice(2,4)),ht(h.slice(4,6)),h.length===8?ht(h.slice(6,8)):255]}(t))}static Kr(t){const[i,r,h]=t;return new M(255*i,255*r,255*h,255,t)}get rgb(){return[this.r,this.g,this.b]}get rgba(){return[...this.Br]}get normalized(){return[...this.Gr]}get character(){return this.Ht?[...this.Ht]:void 0}withAlpha(t){return new M(this.r,this.g,this.b,t,this.Ht)}static Xr(t){return t instanceof M}}const Et=new Map;function Lt(o){Et.set(o.id,o)}function Nt(o){return Et.get(o)}class wt{constructor(t,i,r,h,n,c,a,u){l(this,"A");l(this,"W");l(this,"jr");l(this,"Vr");l(this,"qr");l(this,"H");l(this,"G");l(this,"Z",null);l(this,"tr");l(this,"Qr","brightness");l(this,"Jr",null);l(this,"$t",0);l(this,"Ot",0);l(this,"Dt",0);l(this,"Tt",0);l(this,"tn","sampled");l(this,"sn","fixed");l(this,"Bt",[1,1,1,1]);l(this,"Gt",[0,0,0,1]);l(this,"en",[0,0,0,1]);l(this,"rn",[[.1,0,0]]);l(this,"nn");l(this,"hn",null);l(this,"an",new Set);l(this,"cn",[[0,0,0,0]]);l(this,"ln",0);this.A=t,this.W=i,this.jr=r,this.tr=h,this.Vr=n,this.qr=c,this.H=a,this.G=u}conversionMode(t){return this.Qr=t,this.Jr=null,this.Z=null,this}D(){this.A.deleteTexture(this.jr);for(const t of this.an)t();this.an.clear()}un(t){this.an.add(t)}invert(t=!0){return this.$t=t?1:0,this.Z=null,this}flipX(t=!0){return this.Ot=t?1:0,this.Z=null,this}flipY(t=!0){return this.Dt=t?1:0,this.Z=null,this}charRotation(t){return this.Tt=Ft(t),this.Z=null,this}charColorMode(t){return this.tn=t,this.Z=null,this}cellColorMode(t){return this.sn=t,this.Z=null,this}charColor(t,i,r,h){return this.fn(this.Bt,t,i,r,h),this.Z=null,this}cellColor(t,i,r,h){return this.fn(this.Gt,t,i,r,h),this.Z=null,this}background(t,i,r,h){return this.fn(this.en,t,i,r,h),this.Z=null,this}colorFilter(t){if(!t||t.length===0)return this.ln=0,this.cn=[[0,0,0,0]],this.Z=null,this;const i=[];for(const r of t){if(i.length>=64)break;let h=M.Nr(r);i.push(h.normalized)}return this.cn=i,this.ln=i.length,this.Z=null,this}characters(t){return this.hn=t,this.dn(t),this.Z=null,this}pn(t){this.tr=t,this.hn&&this.dn(this.hn),this.Z=null}get texture(){return this.jr}get width(){return this.H}get height(){return this.G}get originalWidth(){return this.Vr}get originalHeight(){return this.qr}ct(){return this.Z||this.lt(),this.Z}gn(){}lt(){this.gn();const t=this.vn(),i=this.mn(),r=t.createShader(i),h=t.createUniforms(i);this.Z=this.W.materialManager.Oe(r,h)}fn(t,i,r,h,n){const c=M.Nr(i,r,h,n);it(t,c.r,c.g,c.b,c.a)}dn(t){const i=this.nn(t).filter(r=>Array.isArray(r)).slice(0,255);this.rn=i.length>0?i:this.rn}createBaseConversionUniforms(){const t=this.ln>0;return{u_image:this._n(),u_invert:!!this.$t,u_flipX:!!this.Ot,u_flipY:!!this.Dt,u_charRotation:this.Tt,u_charColorFixed:this.tn==="fixed",u_charColor:this.Bt,u_cellColorFixed:this.sn==="fixed",u_cellColor:this.Gt,u_backgroundColor:this.en,u_charCount:this.rn.length,u_charList:this.rn,u_colorFilterEnabled:t,u_colorFilterSize:t?this.ln:0,u_colorFilterPalette:this.cn}}vn(){if(this.Jr&&this.Jr.id===this.Qr)return this.Jr;const t=Nt(this.Qr);if(!t)throw Error(`[textmode.js] Conversion mode "${this.Qr}" is not registered. If this mode is provided by an add-on, make sure its plugin is installed before loading sources.`);return this.Jr=t,t}mn(){return{renderer:this.W,gl:this.A,font:this.tr,source:this,gridWidth:this.H,gridHeight:this.G}}}class V extends wt{constructor(t,i,r,h,n,c,a,u){const f=Math.min(a/n,u/c);super(t,i,r,h,n,c,Math.max(1,Math.floor(n*f)),Math.max(1,Math.floor(c*f)))}static An(t,i,r,h,n,c){const a=t.context,u=a.createTexture();a.bindTexture(a.TEXTURE_2D,u),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 f=r.naturalWidth??r.width??r.videoWidth??0,d=r.naturalHeight??r.height??r.videoHeight??0,g=new V(a,t,u,i,f,d,h,n);return g.nn=c,g}_n(){return this.jr}}class It{constructor(t=60){l(this,"yn");l(this,"wn",null);l(this,"bn",0);l(this,"Cn",!0);l(this,"xn",0);l(this,"Mn",0);l(this,"Fn",[]);l(this,"$n",10);l(this,"Tn",0);this.yn=1e3/t}Pn(t){if(!this.Cn)return;this.bn=performance.now();const i=r=>{if(!this.Cn)return void(this.wn=null);const h=r-this.bn;h>=this.yn&&(t(),this.bn=r-h%this.yn),this.Cn&&(this.wn=requestAnimationFrame(i))};this.wn=requestAnimationFrame(i)}En(){this.wn&&(cancelAnimationFrame(this.wn),this.wn=null)}Rn(){this.Cn&&(this.Cn=!1,this.En())}Sn(t){this.Cn||(this.Cn=!0,this.Pn(t))}Un(t,i){if(t===void 0)return this.xn;this.yn=1e3/t,this.Cn&&i&&(this.En(),this.Pn(i))}kn(){const t=performance.now();if(this.Mn>0){const i=t-this.Mn;this.Fn.push(i),this.Fn.length>this.$n&&this.Fn.shift();const r=this.Fn.reduce((h,n)=>h+n,0)/this.Fn.length;this.xn=1e3/r}this.Mn=t}get zn(){return this.Cn}get In(){return this.xn}get Ln(){return this.Tn}set Ln(t){this.Tn=t}On(){this.Tn++}}class Ot{constructor(t){l(this,"Fr");l(this,"Dn");l(this,"Hn",{x:-1,y:-1});l(this,"Bn",{x:-1,y:-1});l(this,"Gn",null);l(this,"Nn",0);l(this,"Xn");l(this,"Yn");l(this,"Kn");l(this,"Wn");l(this,"Zn");l(this,"jn");l(this,"Vn",!1);l(this,"qn");l(this,"Qn");l(this,"Jn");l(this,"so");l(this,"eo");this.Fr=t}io(t){const i=performance.now()+Math.max(0,t);i>this.Nn&&(this.Nn=i)}ro(){return performance.now()<this.Nn}no(t){const i=this.Fr.canvas;i.style.cursor=t==null||t===""?"":t}gr(t){this.Dn=t,this.oo()}ho(){if(this.Vn)return;const t=this.Fr.canvas;this.Xn=i=>{this.ao(i),this.co(i)},this.Yn=()=>{this.Bn={...this.Hn},this.Hn.x=-1,this.Hn.y=-1,this.Gn=null},this.Kn=i=>{this.ao(i),this.lo(i)},this.Wn=i=>{this.ao(i),this.uo(i)},this.Zn=i=>{this.ao(i),this.fo(i)},this.jn=i=>{this.ao(i),this.do(i)},t.addEventListener("mousemove",this.Xn,{passive:!0}),t.addEventListener("mouseleave",this.Yn,{passive:!0}),t.addEventListener("mousedown",this.Kn,{passive:!0}),t.addEventListener("mouseup",this.Wn,{passive:!0}),t.addEventListener("click",this.Zn,{passive:!0}),t.addEventListener("wheel",this.jn,{passive:!1}),this.Vn=!0}po(){if(!this.Vn)return;const t=this.Fr.canvas;t.removeEventListener("mousemove",this.Xn),t.removeEventListener("mouseleave",this.Yn),t.removeEventListener("mousedown",this.Kn),t.removeEventListener("mouseup",this.Wn),t.removeEventListener("click",this.Zn),t.removeEventListener("wheel",this.jn),this.Vn=!1}oo(){if(this.Vn)try{if(this.Gn){const t=new MouseEvent("mousemove",{clientX:this.Gn.x,clientY:this.Gn.y,bubbles:!1,cancelable:!1});this.ao(t)}else this.Hn.x!==-1&&this.Hn.y!==-1&&(this.Hn.x>=this.Dn.cols||this.Hn.y>=this.Dn.rows)&&(this.Hn.x=-1,this.Hn.y=-1)}catch{this.Hn.x=-1,this.Hn.y=-1}}vo(t){this.qn=t}mo(t){this.Qn=t}_o(t){this.Jn=t}Ao(t){this.so=t}yo(t){this.eo=t}wo(){return{x:this.Hn.x,y:this.Hn.y}}co(t){if(this.so&&!this.ro()){const i={position:{...this.Hn},previousPosition:{...this.Bn},originalEvent:t};this.so(i)}}lo(t){if(this.Qn&&!this.ro()){const i={position:{...this.Hn},previousPosition:{...this.Bn},button:t.button,originalEvent:t};this.Qn(i)}}uo(t){if(this.Jn&&!this.ro()){const i={position:{...this.Hn},previousPosition:{...this.Bn},button:t.button,originalEvent:t};this.Jn(i)}}fo(t){if(this.qn&&!this.ro()){const i={position:{...this.Hn},previousPosition:{...this.Bn},button:t.button,originalEvent:t};this.qn(i)}}do(t){if(this.eo&&!this.ro()){const i={position:{...this.Hn},previousPosition:{...this.Bn},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.eo(i)}}ao(t){const i=this.Fr.canvas;this.Bn={...this.Hn},this.Gn={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),h=t.clientX-r.left,n=t.clientY-r.top,c=i.width/r.width,a=n*(i.height/r.height),u=h*c-this.Dn.offsetX,f=a-this.Dn.offsetY,d=Math.floor(u/this.Dn.cellWidth),g=Math.floor(f/this.Dn.cellHeight);d>=0&&d<this.Dn.cols&&g>=0&&g<this.Dn.rows?(this.Hn.x=d,this.Hn.y=g):(this.Hn.x=-1,this.Hn.y=-1)}}const De=Object.freeze(Object.defineProperty({__proto__:null,MouseManager:Ot},Symbol.toStringTag,{value:"Module"}));class Gt{constructor(){l(this,"bo",new Map);l(this,"Co",null);l(this,"xo",null);l(this,"Mo");l(this,"Fo");l(this,"Vn",!1);l(this,"$o");l(this,"To");l(this,"Po",{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"})}ho(){this.Vn||(this.Mo=t=>{this.Eo(t)},this.Fo=t=>{this.Ro(t)},window.addEventListener("keydown",this.Mo,{passive:!1}),window.addEventListener("keyup",this.Fo,{passive:!1}),this.Vn=!0)}po(){this.Vn&&(window.removeEventListener("keydown",this.Mo),window.removeEventListener("keyup",this.Fo),this.Vn=!1,this.bo.clear(),this.Co=null,this.xo=null)}mo(t){this.$o=t}_o(t){this.To=t}So(t){const i=this.Uo(t),r=this.bo.get(t)||this.bo.get(i);return(r==null?void 0:r.isPressed)||!1}ko(){return this.Co}zo(){return this.xo}Io(){const t=[];for(const[i,r]of this.bo)r.isPressed&&t.push(i);return t}Lo(){return{ctrl:this.So("Control"),shift:this.So("Shift"),alt:this.So("Alt"),meta:this.So("Meta")}}Oo(){this.bo.clear(),this.Co=null,this.xo=null}Eo(t){const i=t.key,r=Date.now();this.bo.has(i)||this.bo.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const h=this.bo.get(i);if(!h.isPressed&&(h.isPressed=!0,h.lastPressTime=r,this.Co=i,this.$o)){const n={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.$o(n)}}Ro(t){const i=t.key,r=Date.now();this.bo.has(i)||this.bo.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const h=this.bo.get(i);if(h.isPressed=!1,h.lastReleaseTime=r,this.xo=i,this.To){const n={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.To(n)}}Uo(t){return this.Po[t]||t.toLowerCase()}}const Me=Object.freeze(Object.defineProperty({__proto__:null,KeyboardManager:Gt},Symbol.toStringTag,{value:"Module"}));class Ht{constructor(t,i){l(this,"Fr");l(this,"Do");l(this,"Dn");l(this,"Ho",new Map);l(this,"Bo",new Map);l(this,"Go",new Map);l(this,"No",null);l(this,"Xo");l(this,"Yo");l(this,"Ko");l(this,"Wo");l(this,"Zo");l(this,"jo");l(this,"Vn",!1);l(this,"Vo");l(this,"qo");l(this,"Qo");l(this,"Jo");l(this,"th");l(this,"sh");l(this,"eh");l(this,"ih");l(this,"rh");l(this,"nh");l(this,"oh",320);l(this,"hh",350);l(this,"ah",10);l(this,"uh",550);l(this,"fh",14);l(this,"dh",48);l(this,"ph",650);l(this,"gh",.02);l(this,"mh",2);l(this,"_h",600);l(this,"Ah",0);l(this,"yh",null);this.Fr=t,this.Do=i;const r=this.Fr.canvas;this.Xo=r.style.touchAction,this.Yo=r.style.userSelect,r.style.touchAction||(r.style.touchAction="none"),r.style.userSelect||(r.style.userSelect="none")}gr(t){this.Dn=t,this.oo()}ho(){if(this.Vn)return;const t=this.Fr.canvas;this.Ko=i=>{this.wh(i)},this.Wo=i=>{this.bh(i)},this.Zo=i=>{this.Ch(i)},this.jo=i=>{this.xh(i)},t.addEventListener("touchstart",this.Ko,{passive:!1}),t.addEventListener("touchmove",this.Wo,{passive:!1}),t.addEventListener("touchend",this.Zo,{passive:!1}),t.addEventListener("touchcancel",this.jo,{passive:!1}),this.Vn=!0}po(){if(!this.Vn)return;const t=this.Fr.canvas;t.removeEventListener("touchstart",this.Ko),t.removeEventListener("touchmove",this.Wo),t.removeEventListener("touchend",this.Zo),t.removeEventListener("touchcancel",this.jo),this.Vn=!1,this.No=null,this.Ho.clear(),this.Bo.clear(),this.Go.forEach(i=>{i.longPressTimer!==null&&window.clearTimeout(i.longPressTimer)}),this.Go.clear(),this.yh=null,this.Ah=0,t.style.touchAction=this.Xo,t.style.userSelect=this.Yo}oo(){if(!this.Dn||this.Ho.size===0)return;const t=new Map;for(const i of this.Ho.values()){const r=this.Mh(i.clientX,i.clientY,i.id,i);t.set(i.id,r)}this.Ho=t}Fh(){return Array.from(this.Ho.values()).map(t=>({...t}))}$h(t){this.Vo=t}Ao(t){this.qo=t}Th(t){this.Qo=t}Ph(t){this.Jo=t}Eh(t){this.th=t}Rh(t){this.sh=t}Sh(t){this.eh=t}kh(t){this.ih=t}zh(t){this.rh=t}Ih(t){this.nh=t}wh(t){var h;if(!this.Dn)return;t.preventDefault(),(h=this.Do)==null||h.io(this._h);const i=performance.now(),r=this.Lh(t.changedTouches);for(const n of r){const c=this.Ho.get(n.id);c&&this.Bo.set(n.id,this.Oh(c)),this.Ho.set(n.id,n);const a={id:n.id,startPosition:n,lastPosition:n,startTime:i,lastTime:i,longPressTimer:null,longPressFired:!1};this.eh&&(a.longPressTimer=window.setTimeout(()=>{const u=this.Ho.get(n.id);u&&(a.longPressFired=!0,this.eh({touch:this.Oh(u),duration:performance.now()-a.startTime,originalEvent:t}))},this.uh)),this.Go.set(n.id,a),this.Vo&&this.Vo(this.Dh(n,t,void 0,i))}this.Ho.size===2&&this.Hh()}bh(t){var h;if(!this.Dn)return;t.preventDefault(),(h=this.Do)==null||h.io(this._h);const i=performance.now(),r=this.Lh(t.changedTouches);for(const n of r){const c=this.Ho.get(n.id),a=c?this.Oh(c):void 0;a&&this.Bo.set(n.id,a),this.Ho.set(n.id,n);const u=this.Go.get(n.id);u&&(u.lastPosition=n,u.lastTime=i,a)&&k(a.clientX,a.clientY,n.clientX,n.clientY)>this.fh&&u.longPressTimer!==null&&(window.clearTimeout(u.longPressTimer),u.longPressTimer=null),this.qo&&this.qo(this.Dh(n,t,a,i))}this.Ho.size===2?this.Bh(t):this.No=null}Ch(t){if(!this.Dn)return;t.preventDefault();const i=performance.now(),r=this.Lh(t.changedTouches);for(const h of r){const n=this.Ho.get(h.id),c=n?this.Oh(n):void 0,a=this.Go.get(h.id);a&&a.longPressTimer!==null&&(window.clearTimeout(a.longPressTimer),a.longPressTimer=null),this.Qo&&this.Qo(this.Dh(h,t,c,i)),a&&this.Gh(a,t),this.Go.delete(h.id),this.Bo.delete(h.id),this.Ho.delete(h.id)}this.Ho.size<2&&(this.No=null)}xh(t){if(!this.Dn)return;t.preventDefault();const i=performance.now(),r=this.Lh(t.changedTouches);for(const h of r){const n=this.Ho.get(h.id),c=n?this.Oh(n):void 0,a=this.Go.get(h.id);a&&a.longPressTimer!==null&&(window.clearTimeout(a.longPressTimer),a.longPressTimer=null),this.Jo&&this.Jo(this.Dh(h,t,c,i)),this.Go.delete(h.id),this.Bo.delete(h.id),this.Ho.delete(h.id)}this.Ho.size<2&&(this.No=null)}Lh(t){const i=[];for(let r=0;r<t.length;r+=1){const h=t.item(r);h&&i.push(this.Nh(h))}return i}Nh(t){return this.Mh(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})}Mh(t,i,r,h){const n=this.Fr.canvas,c=n.getBoundingClientRect(),a=t-c.left,u=i-c.top,f=n.width/c.width,d=u*(n.height/c.height),g=a*f-this.Dn.offsetX,m=d-this.Dn.offsetY,p=Math.floor(g/this.Dn.cellWidth),v=Math.floor(m/this.Dn.cellHeight),A=p>=0&&p<this.Dn.cols&&v>=0&&v<this.Dn.rows;return{id:r,x:A?p:-1,y:A?v:-1,clientX:t,clientY:i,pressure:h.pressure,radiusX:h.radiusX,radiusY:h.radiusY,rotationAngle:h.rotationAngle}}Dh(t,i,r,h){const n=this.Go.get(t.id),c=Array.from(this.Bo.values()).map(f=>this.Oh(f)),a=Array.from(this.Ho.values()).map(f=>this.Oh(f)),u=this.Lh(i.changedTouches);return{touch:this.Oh(t),previousTouch:r?this.Oh(r):void 0,touches:a,previousTouches:c,changedTouches:u,deltaTime:n?h-n.lastTime:0,originalEvent:i}}Hh(){if(this.Ho.size!==2)return void(this.No=null);const t=Array.from(this.Ho.values()),[i,r]=t,h=k(i.x,i.y,r.x,r.y),n=xt(i.clientX,i.clientY,r.clientX,r.clientY);this.No={ids:[i.id,r.id],initialDistance:Math.max(h,1e-4),initialAngle:n,lastScale:1,lastRotation:0}}Bh(t){if(this.No||this.Hh(),!this.No)return;const[i,r]=this.No.ids,h=this.Ho.get(i),n=this.Ho.get(r);if(!h||!n)return;const c=k(h.x,h.y,n.x,n.y)/this.No.initialDistance,a=c-this.No.lastScale;this.rh&&Math.abs(a)>this.gh&&(this.rh({touches:[this.Oh(h),this.Oh(n)],scale:c,deltaScale:a,center:this.Xh(h,n),originalEvent:t}),this.No.lastScale=c);let u=xt(h.clientX,h.clientY,n.clientX,n.clientY)-this.No.initialAngle;u=(u+180)%360-180;const f=u-this.No.lastRotation;this.nh&&Math.abs(f)>this.mh&&(this.nh({touches:[this.Oh(h),this.Oh(n)],rotation:u,deltaRotation:f,center:this.Xh(h,n),originalEvent:t}),this.No.lastRotation=u)}Xh(t,i){const r=(t.clientX+i.clientX)/2,h=(t.clientY+i.clientY)/2,n=this.Mh(r,h,-1,{id:-1,x:-1,y:-1,clientX:r,clientY:h});return{x:n.x,y:n.y}}Gh(t,i){const r=performance.now(),h=r-t.startTime,n=k(t.startPosition.clientX,t.startPosition.clientY,t.lastPosition.clientX,t.lastPosition.clientY);if(!t.longPressFired&&h<=this.oh&&n<=this.ah)this.Yh(t.lastPosition,r)&&this.sh?this.sh({touch:this.Oh(t.lastPosition),taps:2,originalEvent:i}):this.th&&this.th({touch:this.Oh(t.lastPosition),taps:1,originalEvent:i});else if(!t.longPressFired&&h<=this.ph&&n>=this.dh){const c={x:t.lastPosition.clientX-t.startPosition.clientX,y:t.lastPosition.clientY-t.startPosition.clientY},a=Math.max(Math.hypot(c.x,c.y),1e-4),u={x:c.x/a,y:c.y/a},f={x:c.x/h,y:c.y/h};this.ih&&this.ih({touch:this.Oh(t.lastPosition),direction:u,distance:a,velocity:f,originalEvent:i})}this.Ah=r,this.yh=this.Oh(t.lastPosition)}Yh(t,i){return!!this.yh&&!(i-this.Ah>this.hh)&&k(t.clientX,t.clientY,this.yh.clientX,this.yh.clientY)<=this.ah}Oh(t){return{...t}}}const Pe=Object.freeze(Object.defineProperty({__proto__:null,TouchManager:Ht},Symbol.toStringTag,{value:"Module"}));class ot extends wt{constructor(i,r,h,n,c,a,u,f,d){const g=a/u;let m,p;g>1?(m=f,p=Math.round(f/g)):(p=d,m=Math.round(d*g));super(i,r,h,n,a,u,m,p);l(this,"Kh");l(this,"Wh",!1);l(this,"Zh",[]);l(this,"xn",null);l(this,"jh",0);l(this,"Vh",0);l(this,"qh",-1);this.Kh=c}D(){super.D();for(const i of this.Zh)this.A.deleteTexture(i);this.Zh=[],this.Kh.pause(),this.Kh.src="",this.Kh.load()}Qh(){if(!this.Wh&&this.Kh.readyState>=this.Kh.HAVE_CURRENT_DATA){const i=this.A;i.bindTexture(i.TEXTURE_2D,this.jr),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,this.Kh),i.bindTexture(i.TEXTURE_2D,null)}}_n(){if(this.Wh&&this.Zh.length>0){const i=this.Vh%this.Zh.length;return this.Zh[i]}return this.jr}ct(){return this.Z=null,super.ct()}gn(){this.Qh()}async Jh(i,r){var h;try{if(i<=0)throw Error("Video preload requires a frameRate greater than 0.");const n=this.Kh.duration;if(!isFinite(n)||n<=0)throw Error("Video duration is invalid, cannot preload frames.");const c=Math.max(1,Math.ceil(n*i));if(this.ta(i,c),await this.sa(i,r))return void this.ea("captureStream",r);await this.ia(i,r),this.ea("seeking",r)}catch(n){const c=n instanceof Error?n:Error(n+"");throw(h=r==null?void 0:r.onError)==null||h.call(r,c),c}}ta(i,r){this.xn=i,this.jh=r,this.Zh=[],this.Wh=!1,this.Vh=0,this.qh=-1}ea(i,r){var h;if(this.Zh.length===0)throw Error(`Video preload via ${i} completed but produced 0 frames.`);this.jh=this.Zh.length,this.Wh=!0,this.Vh=0,this.qh=-1,this.Kh.pause(),this.Kh.currentTime=0,r!=null&&r.onProgress&&r.onProgress({percent:100,loadedFrames:this.jh,totalFrames:this.jh,strategy:i}),(h=r==null?void 0:r.onComplete)==null||h.call(r,{totalFrames:this.jh,strategy:i})}ra(i){const r=this.A,h=r.createTexture();return r.bindTexture(r.TEXTURE_2D,h),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),tt(r,r.LINEAR,r.LINEAR,r.CLAMP_TO_EDGE,r.CLAMP_TO_EDGE),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,i),r.bindTexture(r.TEXTURE_2D,null),h}na(i,r){if(!(r!=null&&r.onProgress)||this.jh===0)return;const h=Math.min(99,Math.floor(this.Zh.length/this.jh*100)),n=10*Math.floor(h/10);n>this.qh&&(this.qh=n,r.onProgress({percent:h,loadedFrames:this.Zh.length,totalFrames:this.jh,strategy:i}))}async sa(i,r){const h=globalThis,n=h==null?void 0:h.MediaStreamTrackProcessor,c=this.Kh.captureStream;if(typeof n!="function"||typeof c!="function")return!1;let a,u=null;try{const f=c.call(this.Kh);if(a=f.getVideoTracks()[0],!a)return f.getTracks().forEach(m=>m.stop()),!1;if(u=new n({track:a}).readable.getReader(),this.Kh.currentTime=0,this.Kh.muted=!0,await this.Kh.play().catch(()=>{}),this.Kh.paused)return!1;const d=1e6/i;let g=0;for(;this.Zh.length<this.jh;){const m=await u.read();if(m.done)break;const p=m.value;if(p)try{const v=typeof p.timestamp=="number"?p.timestamp:g;(this.Zh.length===0||v>=g)&&(this.Zh.push(this.ra(p)),g=v+d,this.na("captureStream",r))}finally{p.close()}}return u.releaseLock(),a.stop(),u=null,a=void 0,this.Kh.pause(),this.Kh.currentTime=0,this.Zh.length!==0}catch{return this.Zh=[],this.qh=-1,!1}finally{if(u)try{await u.cancel()}catch{}a&&a.stop(),this.Kh.pause(),this.Kh.currentTime=0}}async ia(i,r){const h=1/i,n=this.jh,c=this.Kh;c.pause();for(let a=0;a<n;a++){const u=Math.min(c.duration,a*h);await this.oa(u),this.Zh.push(this.ra(c)),this.na("seeking",r)}c.currentTime=0}oa(i){return new Promise((r,h)=>{const n=this.Kh,c=()=>{n.removeEventListener("seeked",a),n.removeEventListener("error",u)},a=()=>{c(),r()},u=()=>{c(),h(Error("Video seek failed while preloading frames."))};n.addEventListener("seeked",a,{once:!0}),n.addEventListener("error",u,{once:!0});const f=isFinite(n.duration)?n.duration:i,d=Math.min(Math.max(i,0),f);if(Math.abs(n.currentTime-d)<1e-4)return c(),void r();n.currentTime=d})}frame(i){return this.Wh&&i!==void 0&&this.jh>0&&(this.Vh=(i%this.jh+this.jh)%this.jh,this.Z=null),this}static async An(i,r,h,n,c,a,u){const f=i.context,d=u==null?void 0:u.frameRate;let g;typeof h=="string"?(g=document.createElement("video"),g.crossOrigin="anonymous",g.loop=!0,g.muted=!0,g.playsInline=!0,await new Promise((E,y)=>{g.addEventListener("loadedmetadata",()=>E(),{once:!0}),g.addEventListener("error",T=>{var F;const w=T.target;y(Error("Failed to load video: "+(((F=w.error)==null?void 0:F.message)||"Unknown error")))},{once:!0}),g.src=h})):(g=h,g.readyState<g.HAVE_METADATA&&await new Promise((E,y)=>{g.addEventListener("loadedmetadata",()=>E(),{once:!0}),g.addEventListener("error",T=>{var w;return y(Error("Video error: "+((w=T.target.error)==null?void 0:w.message)))},{once:!0})}));const m=f.createTexture();f.bindTexture(f.TEXTURE_2D,m),f.pixelStorei(f.UNPACK_FLIP_Y_WEBGL,1),tt(f,f.LINEAR,f.LINEAR,f.CLAMP_TO_EDGE,f.CLAMP_TO_EDGE),f.texImage2D(f.TEXTURE_2D,0,f.RGBA,f.RGBA,f.UNSIGNED_BYTE,g),f.bindTexture(f.TEXTURE_2D,null);const p=g.videoWidth,v=g.videoHeight,A=new ot(f,i,m,r,g,p,v,n,c);return A.nn=a,d&&d>0&&await A.Jh(d,u),A}async play(){await this.Kh.play()}pause(){this.Kh.pause()}stop(){this.Kh.pause(),this.Kh.currentTime=0}speed(i){return this.Kh.playbackRate=i,this}loop(i=!0){return this.Kh.loop=i,this}time(i){return this.Kh.currentTime=i,this}volume(i){return this.Kh.volume=Math.max(0,Math.min(1,i)),this}get texture(){return this.jr}get width(){return this.H}get height(){return this.G}get originalWidth(){return this.Vr}get originalHeight(){return this.qr}get videoElement(){return this.Kh}get currentTime(){return this.Kh.currentTime}get duration(){return this.Kh.duration}get isPlaying(){return!this.Kh.paused&&!this.Kh.ended}get isPreloaded(){return this.Wh}get totalFrames(){return this.jh}get preloadFrameRate(){return this.xn}get currentFrameIndex(){return this.Vh}}const Be=o=>class extends o{ha(t,i,r,h){if(M.Xr(t))return t;if(typeof t=="number"||typeof t=="string")return this.color(t,i,r,h);throw Error("Unsupported color input passed to color-capable method.")}rotate(t=0,i=0,r=0){this.W.state.Zt(t),this.W.state.jt(i),this.W.state.Vt(r)}rotateX(t){this.W.state.Zt(t)}rotateY(t){this.W.state.jt(t)}rotateZ(t){this.W.state.Vt(t)}translate(t=0,i=0,r=0){this.W.state.qt(t,i,r)}translateX(t){this.W.state.qt(t,0,0)}translateY(t){this.W.state.qt(0,t,0)}translateZ(t){this.W.state.qt(0,0,t)}push(){this.W.state.rt()}pop(){this.W.state.nt()}color(t,i,r,h){const n=typeof t=="string"?c=>this.tr.Ji(c):void 0;return M.Nr(t,n??i,r,h)}rect(t=1,i=1){this.W.di(t,i)}point(){this.W.di(1,1)}line(t,i,r,h){this.W.pi(t,i,r,h)}lineWeight(t){this.W.state.Kt(t)}background(t,i,r,h=255){const n=this.ha(t,i,r,h);this.W.wi(n.r,n.g,n.b,n.a)}char(t){if(M.Xr(t)){const r=t.character;return void(r&&this.W.state.ss(r))}const i=Array.from(t);if(i.length===0)throw Error("char() requires at least one character.");this.W.state.ss(this.tr.Qi(i[0]))}charColor(t,i,r,h){const n=this.ha(t,i,r,h);this.W.state.es(n.r,n.g,n.b,n.a)}cellColor(t,i,r,h){const n=this.ha(t,i,r,h);this.W.state.rs(n.r,n.g,n.b,n.a)}flipX(t){this.W.state.ns(t)}flipY(t){this.W.state.hs(t)}charRotation(t){this.W.state.ls(t)}invert(t){this.W.state.cs(t)}clear(){this.W.wi(0,0,0,0)}ellipse(t,i){this.W.gi(t/2,i/2)}triangle(t,i,r,h,n,c){this.W.mi(t,i,r,h,n,c)}bezierCurve(t,i,r,h,n,c,a,u){this.W._i(t,i,r,h,n,c,a,u)}arc(t,i,r,h){this.W.Ai(t/2,i/2,r,h)}shader(t){this.W.ai(t)}setUniform(t,i){this.W.L(t,i)}setUniforms(t){this.W.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.W.li(r)}return this.W.li(t)}createFramebuffer(t){return this.W.yi(t.width??this.grid.cols,t.height??this.grid.rows,3)}image(t,i,r){this.W.ui(t,i,r)}ortho(){this.W.state.fs(!0)}async loadImage(t){if(typeof t!="string"){const n=V.An(this.W,this.tr,t,this.Dn.cols,this.Dn.rows,c=>this.tr.Ji(c));return this.aa(n),n}const i=t,r=await new Promise((n,c)=>{const a=new Image;a.crossOrigin="anonymous",a.onload=()=>n(a),a.onerror=u=>c(u),a.src=i}),h=V.An(this.W,this.tr,r,this.Dn.cols,this.Dn.rows,n=>this.tr.Ji(n));return this.aa(h),h}async loadVideo(t,i){const r=await ot.An(this.W,this.tr,t,this.Dn.cols,this.Dn.rows,h=>this.tr.Ji(h),i);return this.aa(r),r}},Se=o=>class extends o{async loadFont(t){return this.tr.Ar(t).then(()=>{const i=this.tr.maxGlyphDimensions;this.Dn.Pr(i.width,i.height),this.ca.resize(this.Dn.cols,this.Dn.rows),this.W.bi(),this.Do.oo(),this.la.oo(),this.ua()})}fontSize(t){if(!j.m(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.tr.fontSize===t)return;this.tr._r(t);const i=this.tr.maxGlyphDimensions;this.Dn.Pr(i.width,i.height),this.ca.resize(this.Dn.cols,this.Dn.rows),this.W.bi(),this.Do.oo(),this.la.oo(),this.ua()}},Ue=o=>class extends o{get frameCount(){return this.fa.Ln}set frameCount(t){this.fa.Ln=t}frameRate(t){return t===void 0?this.fa.In:this.fa.Un(t,()=>this.da())}noLoop(){this.fa.Rn()}loop(){this.fa.Sn(()=>this.da())}redraw(t=1){if(j.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.da()}isLooping(){return this.fa.zn}},Le=o=>class extends o{constructor(...t){super(...t)}mouseClicked(t){this.Do.vo(t)}mousePressed(t){this.Do.mo(t)}mouseReleased(t){this.Do._o(t)}mouseMoved(t){this.Do.Ao(t)}mouseScrolled(t){this.Do.yo(t)}get mouse(){return this.Do.wo()}cursor(t){this.Do.no(t)}},Ne=o=>class extends o{constructor(...t){super(...t)}touchStarted(t){this.la.$h(t)}touchMoved(t){this.la.Ao(t)}touchEnded(t){this.la.Th(t)}touchCancelled(t){this.la.Ph(t)}tap(t){this.la.Eh(t)}doubleTap(t){this.la.Rh(t)}longPress(t){this.la.Sh(t)}swipe(t){this.la.kh(t)}pinch(t){this.la.zh(t)}rotateGesture(t){this.la.Ih(t)}get touches(){return this.la.Fh()}},Ie=o=>class extends o{constructor(...t){super(...t)}keyPressed(t){this.pa.mo(t)}keyReleased(t){this.pa._o(t)}isKeyPressed(t){return this.pa.So(t)}get lastKeyPressed(){return this.pa.ko()}get lastKeyReleased(){return this.pa.zo()}get pressedKeys(){return this.pa.Io()}get modifierState(){return this.pa.Lo()}};class Oe{constructor(t){l(this,"ga");l(this,"va",new Map);l(this,"ma",[]);l(this,"_a",new Map);l(this,"ya",new Map);this.ga=t}async wa(t){for(const i of t){if(this.va.has(i.name))return void console.warn(`[textmode.js] Plugin "${i.name}" is already installed.`);const r=this.ba(i.name);try{await i.install(this.ga,r)}catch(h){throw this.Ca(i.name),h}this.va.set(i.name,i),this.ma.push(i.name)}}async xa(t){const i=this.va.get(t);if(!i)return;const r=this.ba(t);i.uninstall&&await i.uninstall(this.ga,r),this.va.delete(t),this.ma.splice(this.ma.indexOf(t),1),this.Ca(t)}Ma(){this.Fa(this._a)}$a(){this.Fa(this.ya)}async Ta(){const t=[...this.va.keys()];for(const i of t)await this.xa(i)}ba(t){return{renderer:this.ga.W,font:this.ga.tr,grid:this.ga.Dn,canvas:this.ga.Fr,drawFramebuffer:this.ga.ca,asciiFramebuffer:this.ga.Pa,registerPreDrawHook:i=>this.Ea(this._a,t,i),registerPostDrawHook:i=>this.Ea(this.ya,t,i)}}Ea(t,i,r){const h=t.get(i)??new Set;return h.add(r),t.set(i,h),()=>{const n=t.get(i);n&&(n.delete(r),n.size===0&&t.delete(i))}}Ca(t){this._a.delete(t),this.ya.delete(t)}Fa(t){for(const i of this.ma){const r=t.get(i);r&&r.forEach(h=>h())}}}const _t=`#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 Wt{constructor(){l(this,"Ra",new Map);l(this,"Sa",[]);l(this,"ka",0);l(this,"za",0);l(this,"Ia")}get La(){return this.ka}get Oa(){if(this.ka===0)return 0;let t=0;for(const i of this.Sa){const r=this.Ra.get(i);r&&(t+=Math.min(1,Math.max(0,r.progress))*r.weight)}return Math.min(1,t/this.ka)}Da(t){this.Ia=t}Ha(t,i=1){const r=`phase-${this.Sa.length+1}-${Date.now()}`,h={id:r,label:t,weight:Math.max(.001,i),progress:0,status:"running"};return this.Ra.set(r,h),this.Sa.push(r),this.ka+=h.weight,r}Ba(t,i){const r=this.Ra.get(t);if(!r)return;r.progress=Math.max(0,Math.min(1,i)),r.status=r.progress>=1?"complete":"running";const h=this.Oa;Math.abs(h-this.za)>.001&&(this.za=h,this.Ia&&this.Ia(h))}Ga(t){const i=this.Ra.get(t);i&&(i.progress=1,i.status="complete",this.Ba(t,1))}Na(t){const i=this.Ra.get(t);i&&(i.status="failed")}Xa(){return this.Sa.map(t=>{const i=this.Ra.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 Xt{constructor(t="active"){l(this,"Ya");l(this,"Ka","");l(this,"Wa","");this.Ya=t}get Za(){return this.Ya}get ja(){return this.Ya!=="disabled"}get Va(){return this.Ya==="active"||this.Ya==="transitioning"||this.Ya==="error"}get qa(){return this.Ka}get Qa(){return this.Wa}Ja(){this.Ya!=="done"&&this.Ya!=="transitioning"||(this.Ya="active")}tc(){this.Ya!=="disabled"&&(this.Ya="done")}sc(){this.Ya!=="disabled"&&(this.Ya="transitioning")}ec(){this.Ya==="transitioning"&&(this.Ya="done")}rc(t){this.Ya!=="disabled"&&(this.Ya="error",t instanceof Error?(this.Ka=t.message,this.Wa=t.stack||""):(this.Ka=t,this.Wa=""))}nc(){this.Ya="disabled"}}class Yt{constructor(t,i){l(this,"oc",0);l(this,"hc",1);l(this,"ac");l(this,"cc");this.ac=t,this.cc=i}get lc(){return this.hc}get uc(){return this.hc<1}Pn(){this.ac!=="none"&&this.cc>0&&(this.oc=performance.now())}st(){if(this.ac==="none"||this.cc===0)return this.hc=1,!1;const t=performance.now()-this.oc,i=Math.min(1,t/this.cc);return i>=1?(this.hc=0,!0):(this.hc=1-i,!1)}js(){this.hc=1,this.oc=0}}function Tt(o,t){const i=o.tone??"auto";let r="dark";return i==="light"||i==="dark"?r=i:t&&(r=function(h){if(!h)return 0;const[n,c,a]=h.map(f=>f/255),u=f=>f<=.04045?f/12.92:Math.pow((f+.055)/1.055,2.4);return .2126*u(n)+.7152*u(c)+.0722*u(a)}(t)>.5?"light":"dark"),{mode:r,background:t,textColor:r==="light"?"#1A1A1A":"#F8F8F8",subtleColor:r==="light"?"#4A4A4A":"#C0C0C0"}}function zt(o){return o.mode==="light"?["#E91E63","#9C27B0","#FF6F00"]:["#8EF9F3","#F15BB5","#FF9B71"]}function Kt(o,t){return o.length?o.map(i=>t.color(i)):[t.color("#FFFFFF")]}const Ge=({textmodifier:o,grid:t,progress:i,frameCount:r,message:h,palette:n,theme:c,phases:a,transitionOpacity:u,isError:f,errorMessage:d})=>{const g="|/-\\",m=Math.floor(r/6)%4,p=o.color(c.textColor),v=Math.floor(255*u),A=o.color(p.r,p.g,p.b,v);if(o.charColor(A),o.cellColor(0,0,0,0),f){const E=o.color(c.mode==="light"?"#D32F2F":"#FF6B6B",v);o.charColor(E),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 w of y)o.char(w),o.rect(1,1),o.translateX(1);if(o.pop(),d){const w=o.color(c.subtleColor),F=o.color(w.r,w.g,w.b,v);o.charColor(F);const b=Math.floor(.8*t.cols),P=d.split(" "),L=[];let B="";for(const U of P)(B+" "+U).length<=b?B=B?B+" "+U:U:(B&&L.push(B),B=U);B&&L.push(B);const I=L.slice(0,3);L.length>3&&(I[2]=I[2].substring(0,b-3)+"..."),I.forEach((U,ct)=>{const je=-Math.floor(U.length/2);o.push(),o.translate(je,3+ct,0);for(const ke of U)o.char(ke),o.rect(1,1),o.translateX(1);o.pop()})}return}if(o.push(),o.translate(0,0,0),o.char(g[m]),o.rect(1,1),o.pop(),i>0||a.some(E=>E.status!=="pending")){const E=Math.max(6,Math.floor(.6*t.cols)),y=-Math.floor(E/2),T=Math.floor(E*i),w=n.length?n:[o.color("#FFFFFF")];o.push(),o.translate(y,3,0);for(let F=0;F<E;F++){const b=F<T?"*":".",P=w[F%w.length],L=o.color(P.r,P.g,P.b,v);o.charColor(L),o.char(b),o.rect(1,1),o.translateX(1)}o.pop()}if(h){const E=o.color(c.subtleColor),y=o.color(E.r,E.g,E.b,v);o.charColor(y);const T=-Math.floor(h.toUpperCase().length/2);o.push(),o.translate(T,5,0);for(const w of h.toUpperCase())o.char(w),o.rect(1,1),o.translateX(1);o.pop()}},He={message:"loading...",tone:"auto",transition:"fade",transitionDuration:500};class _e{constructor(t,i,r){this.fc=t,this.id=i,this.label=r}report(t){this.fc.Ba(this.id,t)}complete(){this.fc.Ga(this.id)}fail(t){this.fc.Na(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 Vt{constructor(t,i,r){l(this,"ga");l(this,"l");l(this,"dc");l(this,"fc");l(this,"gc");l(this,"vc");l(this,"mc");l(this,"_c");l(this,"yc");l(this,"wc");l(this,"W");l(this,"bc",[]);l(this,"Cc");l(this,"xc",performance.now());l(this,"Mc",0);l(this,"Fc",!1);l(this,"$c",!1);l(this,"Rc");this.ga=t,this.l={...He,...i??{}},this.dc=new Xt("active"),this.fc=new Wt,this.gc=new Yt(this.l.transition,this.l.transitionDuration),this.vc=new It(60),this.Cc=Tt(this.l,r);const h=zt(this.Cc);this.bc=Kt(h,this.ga),this.W=this.Tc(),this.fc.Da(n=>{n>=.999&&this.tc()})}async gr(t){if(this.$c)return;const i=this.ga.W,r=this.ga.Fr;this.mc=new mt(i,16),await this.mc.gr(t);const h=this.mc.maxGlyphDimensions;this._c=new vt(r.canvas,h.width,h.height),this.yc=i.yi(this._c.cols,this._c.rows,3),this.wc=i.yi(this._c.width,this._c.height,1),this.$c=!0}get Va(){return this.dc.Va&&this.Fc}Pn(){this.Fc||(this.Fc=!0,this.xc=performance.now(),this.Mc=0,this.vc.Pn(()=>this.Pc()))}En(){this.Fc&&(this.Fc=!1,this.vc.En())}Dr(){this.$c&&(this._c.js(),this.yc.resize(this._c.cols,this._c.rows),this.wc.resize(this._c.width,this._c.height))}D(){this.En(),this.$c&&(this.mc.D(),this.yc.D(),this.wc.D(),this.$c=!1)}get progress(){return this.fc.Oa}message(t){return typeof t=="string"&&(this.l.message=t),this.l.message}addPhase(t,i=1){this.dc.Ja();const r=this.fc.Ha(t,i);return new _e(this.fc,r,t)}tc(){this.l.transition!=="none"&&this.l.transitionDuration>0?(this.dc.sc(),this.gc.Pn()):(this.dc.tc(),this.En(),this.Ec())}Ec(){this.Rc&&this.Rc()}Sc(t){this.Rc=t}error(t){this.dc.rc(t)}Pc(){if(this.dc.Va){if(this.Mc++,this.dc.Za==="transitioning"&&this.gc.st())return this.dc.ec(),this.Ec(),void this.En();this.kc()}}kc(){if(!this.$c)return;const t=this.yc,i=this.mc,r=this._c,h=this.wc,n=this.ga.W,c=this.ga.Fr,a=this.ga.zc,u=this.ga.Ic;n.state.Wt(),t.begin(),this.ga.clear(),this.ga.push();try{const f={textmodifier:this.ga,grid:r,progress:this.progress,elapsedMs:performance.now()-this.xc,frameCount:this.Mc,message:this.l.message,palette:this.bc,theme:this.Cc,phases:this.fc.Xa(),transitionOpacity:this.gc.lc,isError:this.dc.Za==="error",errorMessage:this.dc.qa||void 0,errorDetails:this.dc.Qa||void 0};this.W(f)}finally{this.ga.pop()}t.end(),h.begin(),n.oi(a),a.I({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:[h.width,h.height],U5:n.state.canvasBackgroundColor}),n.fi(0,0,c.width,c.height),h.end(),n.ge(...n.state.canvasBackgroundColor),n.oi(u),u.I({U6:h.textures[0],U7:[h.width,h.height],U8:[r.offsetX,r.offsetY],U9:[r.width,r.height]}),n.fi(r.offsetX,r.offsetY,r.width,r.height)}Lc(t){this.Cc=Tt(this.l,t)}Tc(){const t=this.l.renderer||Ge;return i=>{t(i),this.Oc(i)}}Oc(t){const{textmodifier:i,grid:r,frameCount:h,theme:n,transitionOpacity:c}=t,a=[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=n.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<a.length;g++){const m=a[g],p=Math.floor(.1*h+.5*g)%d.length,[v,A,E]=d[p],y=Math.floor(255*c),T=i.color(v,A,E,y);i.charColor(T),i.char(m),i.point(),i.translateX(1)}i.pop()}}class Zt extends function(i,...r){return r.reduce((h,n)=>n(h),i)}(class{},Be,Se,Ue,Le,Ne,Ie){constructor(i={}){super();l(this,"W");l(this,"tr");l(this,"Fr");l(this,"Dn");l(this,"fa");l(this,"Do");l(this,"la");l(this,"pa");l(this,"Dc");l(this,"ca");l(this,"zc");l(this,"Pa");l(this,"Ic");l(this,"Hc");l(this,"Bc",!1);l(this,"Gc",!1);l(this,"Nc",!1);l(this,"Xc",!1);l(this,"Yc",()=>{});l(this,"Kc",()=>{});l(this,"Wc",()=>{});l(this,"Zc");l(this,"jc");l(this,"Rr",!1);l(this,"Vc");l(this,"qc",new Set);this.Hc=new Oe(this),this.Rr=i.overlay??!1,this.Fr=new Ut(i),this.W=new ue(this.Fr.Hr()),this.tr=new mt(this.W,i.fontSize??16),this.fa=new It(i.frameRate??60),this.Dc=new Vt(this,i.loadingScreen,this.Fr.Or()),this.Dc.Sc(()=>{this.fa.Ln=0,this.Xc=!0}),this.Do=new Ot(this.Fr),this.la=new Ht(this.Fr,this.Do),this.pa=new Gt,this.zc=this.W.hi(_t,`#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.Dc.Pn(),this.Qc(i)}async Qc(i){await Promise.all([this.tr.gr(i.fontSource),this.Dc.gr(i.fontSource)]);const r=this.tr.maxGlyphDimensions;this.Dn=new vt(this.Fr.canvas,r.width,r.height),this.Do.gr(this.Dn),this.la.gr(this.Dn),this.ca=this.W.yi(this.Dn.cols,this.Dn.rows,3),this.Pa=this.W.yi(this.Dn.width,this.Dn.height,1),this.Rr&&(this.Vc=V.An(this.W,this.tr,this.Fr.targetCanvas,this.Dn.cols,this.Dn.rows,h=>this.tr.Ji(h)),this.aa(this.Vc)),this.Ic=this.W.hi(_t,`#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.Jc(),this.fa.Pn(()=>this.da()),await this.Hc.wa(i.plugins??[]);try{await this.Yc(),this.Dc.tc()}catch(h){console.error("Error during setup:",h),this.Dc.error(h)}}Jc(){this.Zc=()=>{this.Rr&&this.resizeCanvas(this.Fr.targetCanvas.width,this.Fr.targetCanvas.height),this.Wc()},window.addEventListener("resize",this.Zc),this.Do.ho(),this.la.ho(),this.pa.ho(),window.addEventListener("blur",()=>{this.pa.Oo()}),this.Rr&&(this.jc=new ResizeObserver(()=>{this.resizeCanvas(this.Fr.targetCanvas.width,this.Fr.targetCanvas.height)}),this.jc.observe(this.Fr.targetCanvas))}da(){if(!this.Dc.Va&&this.Xc){this.Gc=!0;try{this.fa.kn(),this.fa.On(),this.Rr&&Rt(this.W.context,this.Vc.texture,this.Fr.targetCanvas),this.Hc.Ma(),this.W.state.Wt(),this.ca.begin(),this.Kc(),this.ca.end(),this.Pa.begin(),this.W.oi(this.zc),this.zc.I({u_characterTexture:this.tr.fontFramebuffer,u_charsetDimensions:[this.tr.textureColumns,this.tr.textureRows],U0:this.ca.textures[0],U1:this.ca.textures[1],U2:this.ca.textures[2],U3:[this.Dn.cols,this.Dn.rows],U4:[this.Pa.width,this.Pa.height],U5:this.W.state.canvasBackgroundColor}),this.W.fi(0,0,this.Fr.width,this.Fr.height),this.Pa.end(),this.W.ge(...this.W.state.canvasBackgroundColor),this.W.oi(this.Ic),this.Ic.I({U6:this.Pa.textures[0],U7:[this.Pa.width,this.Pa.height],U8:[this.Dn.offsetX,this.Dn.offsetY],U9:[this.Dn.width,this.Dn.height]}),this.W.fi(this.Dn.offsetX,this.Dn.offsetY,this.Dn.width,this.Dn.height),this.Hc.$a()}finally{this.Gc=!1,this.Bc&&!this.Nc&&this.tl()}}}resizeCanvas(i,r){this.Fr.Dr(i,r),this.Dc.Lc(this.Fr.Or()),this.Dn.js(),this.Dc.Dr(),this.ca.resize(this.Dn.cols,this.Dn.rows),this.Pa.resize(this.Dn.width,this.Dn.height),this.W.bi(),this.Do.oo(),this.la.oo(),this.da()}destroy(){this.Nc||this.Bc||(this.Bc=!0,this.fa.Rn(),this.Gc||this.tl())}tl(){var i,r;this.Bc=!1,this.Dc.D(),this.Hc.Ta(),window.removeEventListener("resize",this.Zc),(i=this.jc)==null||i.disconnect(),this.Do.po(),this.la.po(),this.pa.po(),this.ca.D(),this.zc.D(),this.tr.D(),this.W.D(),this.Pa.D(),this.Ic.D(),(r=this.Vc)==null||r.D(),this.Fr.D(),this.Nc=!0}setup(i){this.Yc=i}draw(i){this.Kc=i}windowResized(i){this.Wc=i}get grid(){return this.Dn}get font(){return this.tr}get width(){return this.Fr.width}get height(){return this.Fr.height}get canvas(){return this.Fr.canvas}get drawFramebuffer(){return this.ca}get isDisposed(){return this.Nc}get overlay(){return this.Vc}get loading(){return this.Dc}aa(i){this.qc.has(i)||this.qc.add(i)}ua(){for(const i of this.qc)i.pn(this.tr)}}class at{constructor(){}static create(t={}){return new Zt(t)}static setErrorLevel(t){j._(t)}static get version(){return"0.6.0-beta.5"}}let bt=null;const We={id:"brightness",createShader:({gl:o})=>(bt||(bt=new W(o,et,`#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));}`)),bt),createUniforms:({source:o})=>o.createBaseConversionUniforms()},Xe=Object.freeze(Object.defineProperty({__proto__:null,LoadingPhaseTracker:Wt,LoadingScreenManager:Vt,LoadingScreenStateMachine:Xt,LoadingScreenTransition:Yt,resolveColorInputs:Kt,resolveDefaultPalette:zt,resolveTheme:Tt},Symbol.toStringTag,{value:"Module"})),Ye=Object.freeze(Object.defineProperty({__proto__:null,TextmodeFont:mt,TextmodeImage:V,TextmodeSource:wt,TextmodeVideo:ot},Symbol.toStringTag,{value:"Module"})),ze=Object.freeze(Object.defineProperty({__proto__:null,keyboard:Me,mouse:De,touch:Pe},Symbol.toStringTag,{value:"Module"}));Lt(We);const Ke=at.create,Ve=at.setErrorLevel,Ze=at.version;x.Shader=W,x.TextmodeCanvas=Ut,x.TextmodeColor=M,x.TextmodeErrorLevel=H,x.TextmodeFramebuffer=q,x.TextmodeGrid=vt,x.Textmodifier=Zt,x.create=Ke,x.getConversionStrategy=Nt,x.input=ze,x.loadables=Ye,x.loading=Xe,x.registerConversionStrategy=Lt,x.setErrorLevel=Ve,x.textmode=at,x.unregisterConversionStrategy=function(o){Et.delete(o)},x.version=Ze,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 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,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")).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)),console.log("Grid dimensions:",this.Un.cols,"cols x",this.Un.rows,"rows"),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.0"}}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={});