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