textmode.js 0.7.0-beta.3 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -168,7 +168,7 @@ function Rt(n, t, e, i, s) {
168
168
  n.bindBuffer(t, e), n.bufferData(t, i, s), n.bindBuffer(t, null);
169
169
  }
170
170
  const it = `#version 300 es
171
- 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 Ut;uniform float Uu;uniform float Uv;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/Ut)*2.0f;AA.y=-AA.y;float AB=y.z/Ut.y;float AC=clamp(-AB*Uu,-0.99f,0.99f);if(Uv>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);}}`, X = class X {
171
+ 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 U9;uniform float Ua;uniform float Ub;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/U9)*2.0f;AA.y=-AA.y;float AB=y.z/U9.y;float AC=clamp(-AB*Ua,-0.99f,0.99f);if(Ub>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);}}`, X = class X {
172
172
  constructor(t, e, i = e, s = 1, r = {}, h) {
173
173
  a(this, "N");
174
174
  a(this, "X");
@@ -182,7 +182,7 @@ in vec2 A0;in vec2 A1;in vec2 A2;in vec2 A3;in vec3 A4;in vec4 A5;in vec4 A6;in
182
182
  a(this, "q", null);
183
183
  a(this, "V", /* @__PURE__ */ new Map());
184
184
  this.N = e, this.X = i, this.A = t, this.W = O(s, 1, 8), this.Z = h, this.l = { filter: "nearest", wrap: "clamp", format: "rgba", type: "unsigned_byte", depth: !0, ...r }, X.J || (X.J = new W(t, it, `#version 300 es
185
- precision highp float;in vec2 v_uv;uniform sampler2D U5;uniform sampler2D U6;uniform sampler2D U7;uniform sampler2D U8;uniform vec2 U9;uniform bool Ua;uniform bool Ub;uniform bool Uc;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*U9;vec2 D=(floor(C)+0.5f)/U9;vec4 E=texture(U5,D);vec4 F=Ua?texture(U6,D):vec4(0.);if(Ua&&F.a==0.){discard;}vec4 G=Ub?texture(U7,D):vec4(0.);vec4 H=Uc?texture(U8,D):vec4(0.);o_character=E;o_primaryColor=F;o_secondaryColor=G;A=H;}`));
185
+ precision highp float;in vec2 v_uv;uniform sampler2D Uc;uniform sampler2D Ud;uniform sampler2D Ue;uniform sampler2D Uf;uniform vec2 Ug;uniform bool Uh;uniform bool Ui;uniform bool Uj;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 A;void main(){vec2 B=vec2(v_uv.x,1.-v_uv.y);vec2 C=B*Ug;vec2 D=(floor(C)+0.5f)/Ug;vec4 E=texture(Uc,D);vec4 F=Uh?texture(Ud,D):vec4(0.);if(Uh&&F.a==0.){discard;}vec4 G=Ui?texture(Ue,D):vec4(0.);vec4 H=Uj?texture(Uf,D):vec4(0.);o_character=E;o_primaryColor=F;o_secondaryColor=G;A=H;}`));
186
186
  const o = t.getParameter(t.MAX_DRAW_BUFFERS), c = t.getParameter(t.MAX_COLOR_ATTACHMENTS);
187
187
  this.W = Math.min(this.W, o, c), this.Y = t.createFramebuffer(), this.tt(), this.st(), this.l.depth && this.it();
188
188
  }
@@ -244,7 +244,7 @@ precision highp float;in vec2 v_uv;uniform sampler2D U5;uniform sampler2D U6;uni
244
244
  }
245
245
  ft() {
246
246
  if (!this.Z) return;
247
- const t = this.W > 1, e = this.W > 2, i = this.W > 3, s = { U5: this.j[0], U6: t ? this.j[1] : this.j[0], U7: e ? this.j[2] : this.j[0], U8: i ? this.j[3] : this.j[0], U9: [this.N, this.X], Ua: t, Ub: e, Uc: i }, r = X.J;
247
+ const t = this.W > 1, e = this.W > 2, i = this.W > 3, s = { Uc: this.j[0], Ud: t ? this.j[1] : this.j[0], Ue: e ? this.j[2] : this.j[0], Uf: i ? this.j[3] : this.j[0], Ug: [this.N, this.X], Uh: t, Ui: e, Uj: i }, r = X.J;
248
248
  this.q = this.Z.vt.dt(r, s, !0);
249
249
  }
250
250
  gt() {
@@ -759,7 +759,7 @@ class fe {
759
759
  const { material: e, type: i, commands: s } = t, r = this.Si.get(i);
760
760
  e.shader.D(), e.shader.O(e.uniforms);
761
761
  const h = Pt(this.A), o = s.length > 0 && s[0].state.kt;
762
- e.shader.O({ Uw: h[2] / h[3], Ut: [h[2], h[3]], Uu: 1, Uv: o ? 1 : 0 }), r.Pi();
762
+ e.shader.O({ Uw: h[2] / h[3], U9: [h[2], h[3]], Ua: 1, Ub: o ? 1 : 0 }), r.Pi();
763
763
  for (const c of s) r.yi(c.params, c.state);
764
764
  if (r.$i()) {
765
765
  const c = r.unitGeometry, l = r.unitBuffer;
@@ -3338,7 +3338,7 @@ class zt {
3338
3338
  } finally {
3339
3339
  this.Ca.pop();
3340
3340
  }
3341
- t.end(), s.begin(), r.ve(o), o.O({ u_characterTexture: e.fontFramebuffer, u_charsetDimensions: [e.textureColumns, e.textureRows], Uh: t.textures[0], Ui: t.textures[1], Uj: t.textures[2], Uk: [i.cols, i.rows], Ul: [s.width, s.height], Um: r.state.canvasBackgroundColor }), r.Ae(0, 0, h.width, h.height), s.end(), r.wi(...r.state.canvasBackgroundColor), r.ve(c), c.O({ U0: s.textures[0], U1: [s.width, s.height], U2: [i.offsetX, i.offsetY], U3: [i.width, i.height] }), r.Ae(i.offsetX, i.offsetY, i.width, i.height);
3341
+ t.end(), s.begin(), r.ve(o), o.O({ u_characterTexture: e.fontFramebuffer, u_charsetDimensions: [e.textureColumns, e.textureRows], Uk: t.textures[0], Ul: t.textures[1], Um: t.textures[2], Un: [i.cols, i.rows], Uo: [s.width, s.height], Up: r.state.canvasBackgroundColor }), r.Ae(0, 0, h.width, h.height), s.end(), r.wi(...r.state.canvasBackgroundColor), r.ve(c), c.O({ U0: s.textures[0], U1: [s.width, s.height], U2: [i.offsetX, i.offsetY], U3: [i.width, i.height] }), r.Ae(i.offsetX, i.offsetY, i.width, i.height);
3342
3342
  }
3343
3343
  Nc(t) {
3344
3344
  this.Rc = dt(this.l, t);
@@ -3418,7 +3418,7 @@ class gt {
3418
3418
  const i = this.Zc.renderer;
3419
3419
  this.el = [], this.qc.begin(), i.state.qt(), this.tl.call(t), this.qc.end();
3420
3420
  const s = this.el.length > 0, r = s ? this.Jc : this.Vc;
3421
- r.begin(), i.ve(e), e.O({ u_characterTexture: this.Zc.font.fontFramebuffer, u_charsetDimensions: [this.Zc.font.textureColumns, this.Zc.font.textureRows], Uh: this.qc.textures[0], Ui: this.qc.textures[1], Uj: this.qc.textures[2], Uk: [this.Zc.grid.cols, this.Zc.grid.rows], Ul: [r.width, r.height], Um: [0, 0, 0, 0] }), i.Ae(0, 0, this.Zc.grid.width, this.Zc.grid.height), r.end(), s && this.Zc.filterManager.cl(this.Jc.textures[0], this.Vc, this.el, this.Vc.width, this.Vc.height, this.Zc.layerPingPongBuffers), this.sl = !0;
3421
+ r.begin(), i.ve(e), e.O({ u_characterTexture: this.Zc.font.fontFramebuffer, u_charsetDimensions: [this.Zc.font.textureColumns, this.Zc.font.textureRows], Uk: this.qc.textures[0], Ul: this.qc.textures[1], Um: this.qc.textures[2], Un: [this.Zc.grid.cols, this.Zc.grid.rows], Uo: [r.width, r.height], Up: [0, 0, 0, 0] }), i.Ae(0, 0, this.Zc.grid.width, this.Zc.grid.height), r.end(), s && this.Zc.filterManager.cl(this.Jc.textures[0], this.Vc, this.el, this.Vc.width, this.Vc.height, this.Zc.layerPingPongBuffers), this.sl = !0;
3422
3422
  }
3423
3423
  Xr(t) {
3424
3424
  var e;
@@ -3456,7 +3456,7 @@ class Vt {
3456
3456
  a(this, "fl", null);
3457
3457
  a(this, "dl", 0);
3458
3458
  this.Z = t, this.ul = t.pe(Q, `#version 300 es
3459
- precision highp float;uniform sampler2D Un;uniform sampler2D Uo;uniform vec2 Up;uniform float Uq;uniform vec2 Ur;uniform int Us;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(Uo,v_uv);vec2 h=v_uv*Up-Ur;bool i=any(lessThan(h,vec2(0.)))||any(greaterThanEqual(h,Up));if(i){fragColor=g;return;}vec2 j=(floor(h)+0.5)/Up;vec4 k=texture(Un,j);float l=k.a*Uq;if(l<=0.){fragColor=g;return;}vec3 m=e(Us,g.rgb,k.rgb);vec3 n=mix(g.rgb,m,l);float o=g.a+l*(1.-g.a);fragColor=vec4(n,o);}`);
3459
+ precision highp float;uniform sampler2D Uq;uniform sampler2D Ur;uniform vec2 Us;uniform float Ut;uniform vec2 Uu;uniform int Uv;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(Ur,v_uv);vec2 h=v_uv*Us-Uu;bool i=any(lessThan(h,vec2(0.)))||any(greaterThanEqual(h,Us));if(i){fragColor=g;return;}vec2 j=(floor(h)+0.5)/Us;vec4 k=texture(Uq,j);float l=k.a*Ut;if(l<=0.){fragColor=g;return;}vec3 m=e(Uv,g.rgb,k.rgb);vec3 n=mix(g.rgb,m,l);float o=g.a+l*(1.-g.a);fragColor=vec4(n,o);}`);
3460
3460
  }
3461
3461
  yr(t) {
3462
3462
  this.fl || (this.fl = [this.Z.Pe(t.width, t.height, 1), this.Z.Pe(t.width, t.height, 1)]);
@@ -3471,11 +3471,11 @@ precision highp float;uniform sampler2D Un;uniform sampler2D Uo;uniform vec2 Up;
3471
3471
  }
3472
3472
  pl(t, e, i, s, r, h, o, c) {
3473
3473
  const l = this.fl[this.dl], u = this.dl === 0 ? 1 : 0, f = this.fl[u];
3474
- f.begin(), c.disable(c.BLEND), this.Z.ve(this.ul), this.ul.O({ Un: t, Uo: l.textures[0], Up: [e, i], Uq: s, Ur: [r, h], Us: xt[o] }), this.Z.Ae(0, 0, l.width, l.height), f.end(), this.dl = u;
3474
+ f.begin(), c.disable(c.BLEND), this.Z.ve(this.ul), this.ul.O({ Uq: t, Ur: l.textures[0], Us: [e, i], Ut: s, Uu: [r, h], Uv: xt[o] }), this.Z.Ae(0, 0, l.width, l.height), f.end(), this.dl = u;
3475
3475
  }
3476
3476
  ml(t, e, i, s) {
3477
3477
  const r = this.fl[this.dl];
3478
- t.begin(), s.disable(s.BLEND), this.Z.ve(this.ul), this.ul.O({ Un: r.textures[0], Uo: r.textures[0], Up: [r.width, r.height], Uq: 1, Ur: [0, 0], Us: xt.normal }), this.Z.Ae(0, 0, e, i), t.end();
3478
+ t.begin(), s.disable(s.BLEND), this.Z.ve(this.ul), this.ul.O({ Uq: r.textures[0], Ur: r.textures[0], Us: [r.width, r.height], Ut: 1, Uu: [0, 0], Uv: xt.normal }), this.Z.Ae(0, 0, e, i), t.end();
3479
3479
  }
3480
3480
  Xr(t) {
3481
3481
  this.fl && (this.fl[0].resize(t.width, t.height), this.fl[1].resize(t.width, t.height));
@@ -3521,7 +3521,7 @@ class Gt {
3521
3521
  }
3522
3522
  Sl(t, e) {
3523
3523
  const i = this.Ca.Nn, s = this.Ca.font, r = this.Ca.ga, h = this.bl.nl(), o = h.length > 0, c = o ? this.xl : this.Cl;
3524
- c.begin(), this.Z.ve(this._l), this._l.O({ u_characterTexture: s.fontFramebuffer, u_charsetDimensions: [s.textureColumns, s.textureRows], Uh: r.textures[0], Ui: r.textures[1], Uj: r.textures[2], Uk: [i.cols, i.rows], Ul: [c.width, c.height], Um: this.Z.state.canvasBackgroundColor }), this.Z.Ae(0, 0, i.width, i.height), c.end(), o && this.Ca.kl.cl(this.xl.textures[0], this.Cl, h, this.Cl.width, this.Cl.height, this.Ml), this.zl(), this.Dl(t, e);
3524
+ c.begin(), this.Z.ve(this._l), this._l.O({ u_characterTexture: s.fontFramebuffer, u_charsetDimensions: [s.textureColumns, s.textureRows], Uk: r.textures[0], Ul: r.textures[1], Um: r.textures[2], Un: [i.cols, i.rows], Uo: [c.width, c.height], Up: this.Z.state.canvasBackgroundColor }), this.Z.Ae(0, 0, i.width, i.height), c.end(), o && this.Ca.kl.cl(this.xl.textures[0], this.Cl, h, this.Cl.width, this.Cl.height, this.Ml), this.zl(), this.Dl(t, e);
3525
3525
  }
3526
3526
  zl() {
3527
3527
  if (this.wl.length !== 0) for (const t of this.wl) t.wa(this.Ca, this._l);
@@ -3619,9 +3619,9 @@ class kt {
3619
3619
  Il() {
3620
3620
  this.Bl("invert", `#version 300 es
3621
3621
  precision highp float;uniform sampler2D u_texture;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);fragColor=vec4(1.-A.rgb,A.a);}`, {}), this.Bl("grayscale", `#version 300 es
3622
- precision highp float;uniform sampler2D u_texture;uniform float Ud;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),Ud);fragColor=vec4(C,A.a);}`, { Ud: ["amount", 1] }), this.Bl("sepia", `#version 300 es
3623
- precision highp float;uniform sampler2D u_texture;uniform float Ud;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,Ud);fragColor=vec4(C,A.a);}`, { Ud: ["amount", 1] }), this.Bl("threshold", `#version 300 es
3624
- precision highp float;uniform sampler2D u_texture;uniform float Ue;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(Ue,B);fragColor=vec4(vec3(C),A.a);}`, { Ue: ["threshold", 0.5] });
3622
+ precision highp float;uniform sampler2D u_texture;uniform float U5;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),U5);fragColor=vec4(C,A.a);}`, { U5: ["amount", 1] }), this.Bl("sepia", `#version 300 es
3623
+ precision highp float;uniform sampler2D u_texture;uniform float U5;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,U5);fragColor=vec4(C,A.a);}`, { U5: ["amount", 1] }), this.Bl("threshold", `#version 300 es
3624
+ precision highp float;uniform sampler2D u_texture;uniform float U8;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(U8,B);fragColor=vec4(vec3(C),A.a);}`, { U8: ["threshold", 0.5] });
3625
3625
  }
3626
3626
  }
3627
3627
  class Wt {
@@ -3732,7 +3732,7 @@ class Qe extends function(e, ...i) {
3732
3732
  this.Jl = new ke(this), this.Lr = e.overlay ?? !1, this.Er = new Se(e), this.Z = new ve(this.Er.Yr()), this.rr = new vt(this.Z, e.fontSize ?? 16), this.ya = new Lt(e.frameRate ?? 60), this.Kl = new zt(this, e.loadingScreen, this.Er.Nr()), this.Kl.Bc(() => {
3733
3733
  this.ya.Gn = 0, this.eu = !0;
3734
3734
  }), this.Yh = new Dt(this.Er), this.ma = new Bt(this.Er, this.Yh), this.ba = new Zt(), this.Gc = this.Z.pe(Q, `#version 300 es
3735
- precision highp float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D Ui;uniform sampler2D Uj;uniform sampler2D Uh;uniform vec2 Uk;uniform vec2 Ul;uniform vec4 Um;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/Ul;vec2 F=E*Uk;vec2 G=floor(F);vec2 H=(G+0.5)/Uk;vec4 I=texture(Ui,H);vec4 J=texture(Uj,H);vec4 K=texture(Uh,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(Um,J,J.a);fragColor=mix(d,I,c);}`), this.Wl = new Gt(this), this.kl = new Wt(this.Z), this.Kl.kn(), this.cu(e);
3735
+ precision highp float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D Ul;uniform sampler2D Um;uniform sampler2D Uk;uniform vec2 Un;uniform vec2 Uo;uniform vec4 Up;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/Uo;vec2 F=E*Un;vec2 G=floor(F);vec2 H=(G+0.5)/Un;vec4 I=texture(Ul,H);vec4 J=texture(Um,H);vec4 K=texture(Uk,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(Up,J,J.a);fragColor=mix(d,I,c);}`), this.Wl = new Gt(this), this.kl = new Wt(this.Z), this.Kl.kn(), this.cu(e);
3736
3736
  }
3737
3737
  async cu(e) {
3738
3738
  await Promise.all([this.rr.yr(e.fontSource), this.Kl.yr(e.fontSource)]);
@@ -3838,7 +3838,7 @@ class At {
3838
3838
  mt._(t);
3839
3839
  }
3840
3840
  static get version() {
3841
- return "0.7.0-beta.3";
3841
+ return "0.7.0";
3842
3842
  }
3843
3843
  }
3844
3844
  let ct = null;
@@ -1,20 +1,20 @@
1
- var hi=Object.defineProperty;var oi=(T,C,O)=>C in T?hi(T,C,{enumerable:!0,configurable:!0,writable:!0,value:O}):T[C]=O;var l=(T,C,O)=>oi(T,typeof C!="symbol"?C+"":C,O);var s,i;s=this,i=function(T){class C extends Error{constructor(t,e={}){super(C.i(t,e)),this.name="TextmodeError"}static i(t,e){return`${t}${e&&Object.keys(e).length>0?`
1
+ var hi=Object.defineProperty;var oi=(T,C,X)=>C in T?hi(T,C,{enumerable:!0,configurable:!0,writable:!0,value:X}):T[C]=X;var l=(T,C,X)=>oi(T,typeof C!="symbol"?C+"":C,X);var s,i;s=this,i=function(T){class C extends Error{constructor(t,e={}){super(C.i(t,e)),this.name="TextmodeError"}static i(t,e){return`${t}${e&&Object.keys(e).length>0?`
2
2
 
3
3
  📋 Context:`+Object.entries(e).map(([r,n])=>`
4
4
  - ${r}: ${C.h(n)}`).join(""):""}
5
5
 
6
6
  ${"↓".repeat(24)}
7
- `}static h(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(e=>C.h(e)).join(", ")}]`:`[${t.slice(0,3).map(e=>C.h(e)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const e=Object.keys(t);return e.length===0?"{}":e.length<=3?`{ ${e.map(r=>`${r}: ${C.h(t[r])}`).join(", ")} }`:`{ ${e.slice(0,2).map(r=>`${r}: ${C.h(t[r])}`).join(", ")}, ... +${e.length-2} more }`}return t+""}}var O=(o=>(o[o.SILENT=0]="SILENT",o[o.WARNING=1]="WARNING",o[o.ERROR=2]="ERROR",o[o.THROW=3]="THROW",o))(O||{});const I=class I{constructor(){l(this,"l",{globalLevel:3})}static u(){return I.o||(I.o=new I),I.o}v(t,e){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(C.i(t,e)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(C.i(t,e)),console.groupEnd(),!1;default:throw new C(t,e)}}m(t,e,r){return!!t||(this.v(e,r),!1)}_(t){this.l.globalLevel=t}};l(I,"o",null);let lt=I;const ut=lt.u();class W{constructor(t,e,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(e,r),this.S()}S(){const t=this.A.getProgramParameter(this.C,this.A.ACTIVE_UNIFORMS);for(let e=0;e<t;e++){const r=this.A.getActiveUniform(this.C,e);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,e){const r=this.k(this.A.VERTEX_SHADER,t),n=this.k(this.A.FRAGMENT_SHADER,e),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,e){const r=this.A.createShader(t);if(this.A.shaderSource(r,e),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()}O(t){for(const e in t)this.I(e,t[e])}I(t,e){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(e instanceof WebGLTexture){const d=this.H(t);return c.uniform1i(r,d),c.activeTexture(c.TEXTURE0+d),void c.bindTexture(c.TEXTURE_2D,e)}if(e instanceof Y){const d=this.H(t);return c.uniform1i(r,d),c.activeTexture(c.TEXTURE0+d),void c.bindTexture(c.TEXTURE_2D,e.textures[0])}if(typeof e!="number")if(typeof e!="boolean")if(Array.isArray(e[0])){const d=e.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=e,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,e?1:0);else h===c.INT||h===c.BOOL?c.uniform1i(r,e):c.uniform1f(r,e)}H(t){const e=this.$.get(t);if(e!==void 0)return e;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 Tt(o,t,e,r){return 180*Math.atan2(r-t,e-o)/Math.PI}function H(o,t,e,r){return Math.hypot(e-o,r-t)}function z(o,t,e){return Math.min(Math.max(o,t),e)}function Ct(o){return(o%360+360)%360/360}function Ft(o,t,e){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,e),o.bindTexture(o.TEXTURE_2D,null)}function tt(o,t,e,r,n){o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,t),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,e),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,r),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,n)}function ft(o,t,e,r,n,h=0,a=WebGL2RenderingContext.FLOAT,c=!1){o.enableVertexAttribArray(t),o.vertexAttribPointer(t,e,a,c,r,n),o.vertexAttribDivisor(t,h)}function Rt(o,t,e,r,n){o.bindBuffer(t,e),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 Ut;uniform float Uu;uniform float Uv;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/Ut)*2.0f;AA.y=-AA.y;float AB=y.z/Ut.y;float AC=clamp(-AB*Uu,-0.99f,0.99f);if(Uv>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,e,r=e,n=1,h={},a){l(this,"N");l(this,"j");l(this,"l");l(this,"A");l(this,"X");l(this,"Y",[]);l(this,"K",null);l(this,"W");l(this,"Z");l(this,"q",null);l(this,"V",new Map);this.N=e,this.j=r,this.A=t,this.W=z(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 W(t,et,`#version 300 es
9
- precision highp float;in vec2 v_uv;uniform sampler2D U5;uniform sampler2D U6;uniform sampler2D U7;uniform sampler2D U8;uniform vec2 U9;uniform bool Ua;uniform bool Ub;uniform bool Uc;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*U9;vec2 D=(floor(C)+0.5f)/U9;vec4 E=texture(U5,D);vec4 F=Ua?texture(U6,D):vec4(0.);if(Ua&&F.a==0.){discard;}vec4 G=Ub?texture(U7,D):vec4(0.);vec4 H=Uc?texture(U8,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.X=t.createFramebuffer(),this.tt(),this.st(),this.l.depth&&this.it()}tt(){const t=this.A,e=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,e,e,r,r),t.texImage2D(t.TEXTURE_2D,0,h,this.N,this.j,0,a,n,null),this.Y.push(u)}t.bindTexture(t.TEXTURE_2D,null)}st(){const t=this.A;if(t.bindFramebuffer(t.FRAMEBUFFER,this.X),this.W===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.Y[0],0);else{const e=[];for(let r=0;r<this.W;r++){const n=t.COLOR_ATTACHMENT0+r;t.framebufferTexture2D(t.FRAMEBUFFER,n,t.TEXTURE_2D,this.Y[r],0),e.push(n)}t.drawBuffers(e)}t.bindFramebuffer(t.FRAMEBUFFER,null)}it(){const t=this.A;this.K=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,this.K),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT24,this.N,this.j),t.bindFramebuffer(t.FRAMEBUFFER,this.X),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,this.K),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindRenderbuffer(t.RENDERBUFFER,null)}et(t){Ft(this.A,this.Y[0],t)}resize(t,e){this.N=t,this.j=e,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.Y)r.bindTexture(r.TEXTURE_2D,c),r.texImage2D(r.TEXTURE_2D,0,h,this.N,this.j,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.j),r.bindRenderbuffer(r.RENDERBUFFER,null))}readPixels(t){const e=this.V.get(t);if(e)return e;const r=this.A,n=this.N,h=this.j,a=new Uint8Array(n*h*4),c=r.getParameter(r.READ_FRAMEBUFFER_BINDING);r.bindFramebuffer(r.READ_FRAMEBUFFER,this.X),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.X,this.N,this.j,this.W),this.l.depth&&t.clear(t.DEPTH_BUFFER_BIT),this.Z.state.ht()}end(){this.Z.state.ot(),this.Z.ct(),this.Z.lt()}ut(){return this.q||this.ft(),this.q}ft(){if(!this.Z)return;const t=this.W>1,e=this.W>2,r=this.W>3,n={U5:this.Y[0],U6:t?this.Y[1]:this.Y[0],U7:e?this.Y[2]:this.Y[0],U8:r?this.Y[3]:this.Y[0],U9:[this.N,this.j],Ua:t,Ub:e,Uc:r},h=k.J;this.q=this.Z.vt.dt(h,n,!0)}gt(){const t=this.A;t.deleteFramebuffer(this.X);for(const e of this.Y)t.deleteTexture(e);this.K&&t.deleteRenderbuffer(this.K)}get width(){return this.N}get height(){return this.j}get textures(){return this.Y}get attachmentCount(){return this.W}};l(k,"J",null);let Y=k;const Pt=new WeakMap;function dt(o,t){Pt.set(o,t)}function Mt(o){return Pt.get(o)}function it(o,t,e,r,n=255){o[0]=t/255,o[1]=(e??t)/255,o[2]=(r??t)/255,o[3]=n/255}class st{constructor(){l(this,"_t",1);l(this,"yt",0);l(this,"At",0);l(this,"bt",0);l(this,"wt",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,"Rt",!1);l(this,"Et",0);l(this,"St",[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,wt:0,Ct:0,xt:0,Et:0,Gt:!1,Qt:!1,Rt:!1,kt:!1,Nt:[0,0,0],jt:[1,1,1,1],Xt:[0,0,0,1]}}Yt(t){t.Ot=this._t,t.It=this.yt,t.Bt=this.At,t.Ht=this.bt,t.wt=this.wt,t.Ct=this.Ct,t.xt=this.xt,t.Gt=this.$t,t.Qt=this.Tt,t.Rt=this.Rt,t.Et=this.Et,t.kt=this.kt,t.Nt[0]=this.Mt[0],t.Nt[1]=this.Mt[1],t.Nt[2]=this.Mt[2],t.jt[0]=this.Ft[0],t.jt[1]=this.Ft[1],t.jt[2]=this.Ft[2],t.jt[3]=this.Ft[3],t.Xt[0]=this.Pt[0],t.Xt[1]=this.Pt[1],t.Xt[2]=this.Pt[2],t.Xt[3]=this.Pt[3]}Kt(t){this._t=t.Ot,this.yt=t.It,this.At=t.Bt,this.bt=t.Ht,this.wt=t.wt,this.Ct=t.Ct,this.xt=t.xt,this.$t=t.Gt,this.Tt=t.Qt,this.Rt=t.Rt,this.Et=t.Et,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.jt[0],this.Ft[1]=t.jt[1],this.Ft[2]=t.jt[2],this.Ft[3]=t.jt[3],this.Pt[0]=t.Xt[0],this.Pt[1]=t.Xt[1],this.Pt[2]=t.Xt[2],this.Pt[3]=t.Xt[3]}ht(){let t=this.Dt.pop();t||(t=st.Lt()),this.Yt(t),this.zt.push(t)}ot(){const t=this.zt.pop();t?(this.Kt(t),this.Dt.push(t)):console.warn("pop() called without matching push()")}Wt(t){this.Yt(t)}Zt(t){this._t=Math.abs(t)}qt(){this.yt=0,this.At=0,this.bt=0,this.wt=0,this.Ct=0,this.xt=0,this.kt=!1}Vt(t){t!==0&&(this.wt+=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,e=0,r=0){t===0&&e===0&&r===0||(this.yt+=t,this.At+=e,this.bt+=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,e,r,n=255){it(this.Ft,t,e,r,n)}ls(t,e,r,n=255){it(this.Pt,t,e,r,n)}us(t){this.$t=t}fs(t){this.Tt=t}ds(t){this.Rt=t}vs(t){this.Et=Ct(t)}ps(t,e,r,n){it(this.St,t,e,r,n)}gs(t){this.kt=t}get canvasBackgroundColor(){return this.St}get useOrtho(){return this.kt}get rotationX(){return this.wt}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]),j={_s:16,As:WebGL2RenderingContext.TRIANGLES,bs:{ws:{size:2,offset:0},Cs:{size:2,offset:8}}};class ee{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,e,r,n){const h=this.A,a=Mt(this.A),c=a[2],u=a[3],f=t/c*2-1,d=(t+r)/c*2-1,g=1-(e+n)/u*2,v=1-e/u*2,p=gt,m=this.Fs;for(let A=0;A<p.length;A+=4){const y=p[A],E=p[A+1],b=p[A+2],w=p[A+3],P=f+(y+.5)*(d-f),x=g+(E+.5)*(v-g);m[A]=P,m[A+1]=x,m[A+2]=b,m[A+3]=w}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 F=(o=>(o.RECTANGLE="rectangle",o.LINE="line",o.ELLIPSE="ellipse",o.ARC="arc",o.TRIANGLE="triangle",o.BEZIER_CURVE="bezier_curve",o))(F||{});const ie={rectangle:2,line:2,ellipse:2,triangle:2,arc:3,bezier_curve:4};class se{constructor(t){l(this,"A");l(this,"$s",new Map);this.A=t}Ts(t,e,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(e)||null;if(!c){c=h.createVertexArray(),a.set(e,c),h.bindVertexArray(c),h.bindBuffer(h.ARRAY_BUFFER,n);const u=h.getAttribLocation(t,"A0");u!==-1&&ft(h,u,r.bs.ws.size,r._s,r.bs.ws.offset,0,h.FLOAT,!1);const f=h.getAttribLocation(t,"A1");f!==-1&&ft(h,f,r.bs.Cs.size,r._s,r.bs.Cs.offset,0,h.FLOAT,!1)}h.bindVertexArray(c)}Rs(){this.A.bindVertexArray(null)}gt(){for(const[,t]of this.$s)for(const[,e]of t)e&&this.A.deleteVertexArray(e)}}const X=class X{static Es(t,e,r=0){const n=e||new Float32Array(X.FLOATS_PER_INSTANCE);let h=r;n[h++]=t.ws[0],n[h++]=t.ws[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.jt[0],n[h++]=t.jt[1],n[h++]=t.jt[2],n[h++]=t.jt[3],n[h++]=t.Xt[0],n[h++]=t.Xt[1],n[h++]=t.Xt[2],n[h++]=t.Xt[3],n[h++]=t.ks[0],n[h++]=t.ks[1],n[h++]=t.ks[2],n[h++]=t.Et;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,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 js(t,e){const r=t.length*X.FLOATS_PER_INSTANCE,n=e||new Float32Array(r);for(let h=0;h<t.length;h++){const a=h*X.FLOATS_PER_INSTANCE;X.Es(t[h],n,a)}return n}};l(X,"BYTES_PER_INSTANCE",144),l(X,"FLOATS_PER_INSTANCE",36);let Z=X;const S=class S{};l(S,"STRIDE",Z.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,e=1.5){l(this,"Xs");l(this,"Ys");l(this,"Ks");l(this,"Ws",0);l(this,"Zs",0);this.Ys=t,this.Ks=e;const r=t*Z.FLOATS_PER_INSTANCE;this.Xs=new Float32Array(r)}qs(t){if(t<=this.Ys)return;const e=Math.ceil(t*this.Ks),r=this.Ys;this.Ys=e;const n=e*Z.FLOATS_PER_INSTANCE,h=new Float32Array(n),a=r*Z.FLOATS_PER_INSTANCE;h.set(this.Xs.subarray(0,Math.min(a,this.Ws))),this.Xs=h}Vs(){return{buffer:this.Xs,offset:this.Ws}}Js(t){this.Ws+=t,this.Zs++}ti(){this.Ws=0,this.Zs=0}si(t=0,e){return this.Xs.subarray(t,e??this.Ws)}get ii(){return this.Zs}get ei(){return this.Ys}get ri(){return this.Ws}get ni(){return this.Zs===0}}class ne{constructor(t){l(this,"Xs");this.Xs=t}hi(t){this.Xs.qs(this.Xs.ii+1);const{buffer:e,offset:r}=this.Xs.Vs();e[r+0]=t.x,e[r+1]=t.y,e[r+2]=t.width,e[r+3]=t.height,e[r+4]=t.char0,e[r+5]=t.char1,e[r+6]=t.char2,e[r+7]=t.r1,e[r+8]=t.g1,e[r+9]=t.b1,e[r+10]=t.a1,e[r+11]=t.r2,e[r+12]=t.g2,e[r+13]=t.b2,e[r+14]=t.a2,e[r+15]=t.invert,e[r+16]=t.flipX,e[r+17]=t.flipY,e[r+18]=t.charRot,e[r+19]=t.translationX,e[r+20]=t.translationY,e[r+21]=t.translationZ,e[r+22]=t.rotationX,e[r+23]=t.rotationY,e[r+24]=t.rotationZ;const n=t.curveParams0,h=t.curveParams1;return e[r+25]=n[0],e[r+26]=n[1],e[r+27]=n[2],e[r+28]=n[3],e[r+29]=h[0],e[r+30]=h[1],e[r+31]=h[2],e[r+32]=h[3],e[r+33]=t.depth,e[r+34]=t.baseZ,e[r+35]=t.geometryType,this.Xs.Js(Z.FLOATS_PER_INSTANCE),this.Xs.ii-1}get ii(){return this.Xs.ii}}class he{constructor(t,e=1e3){l(this,"A");l(this,"oi",null);l(this,"ai",0);l(this,"ci",new Map);this.A=t,this.li(e)}li(t){const e=this.A;this.oi&&e.deleteBuffer(this.oi),this.oi=e.createBuffer();const r=t*Z.BYTES_PER_INSTANCE;Rt(e,e.ARRAY_BUFFER,this.oi,r,e.DYNAMIC_DRAW),this.ai=t}ui(t){this.li(t)}get ei(){return this.ai}fi(t,e){if(e===0)return;const r=this.A;r.bindBuffer(r.ARRAY_BUFFER,this.oi);const n=e*Z.FLOATS_PER_INSTANCE;r.bufferSubData(r.ARRAY_BUFFER,0,t,0,n)}di(t){let e=this.ci.get(t);if(!e){e=new Map;const r=this.A;for(const n in Q.ATTRIBUTES){const h=r.getAttribLocation(t,n);h!==-1&&e.set(n,h)}this.ci.set(t,e)}return e}pi(t){const e=this.A,r=t.G,n=this.di(r);for(const[h,a]of n){const c=Q.ATTRIBUTES[h];c&&ft(e,a,c.size,c.stride,c.offset,c.divisor,c.type,c.normalized)}}gi(t){const e=this.A,r=this.di(t.G);for(const[n,h]of r)Q.ATTRIBUTES[n]&&(e.disableVertexAttribArray(h),e.vertexAttribDivisor(h,0))}gt(){this.oi&&(this.A.deleteBuffer(this.oi),this.oi=null),this.ci.clear()}}class oe{constructor(t,e=1e3,r=1.5){l(this,"A");l(this,"Xs");l(this,"mi");l(this,"_i");this.A=t,this.Xs=new re(e,r),this.mi=new ne(this.Xs),this._i=new he(t,e)}yi(t){var n,h,a,c,u,f,d,g,v,p;const e=[0,0,0,0],r=[0,0,0,0];return t.Os&&t.Is?(e[0]=((n=t.Bs)==null?void 0:n[0])??0,e[1]=((h=t.Bs)==null?void 0:h[1])??0,e[2]=((a=t.Hs)==null?void 0:a[0])??0,e[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&&(e[0]=t.Ls[0],e[1]=t.Ls[1]),this.hi({x:t.ws[0],y:t.ws[1],width:t.Ss[0],height:t.Ss[1],char0:t.Nt[0],char1:t.Nt[1],char2:t.Nt[2],r1:t.jt[0],g1:t.jt[1],b1:t.jt[2],a1:t.jt[3],r2:t.Xt[0],g2:t.Xt[1],b2:t.Xt[2],a2:t.Xt[3],invert:t.ks[0],flipX:t.ks[1],flipY:t.ks[2],charRot:t.Et,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:e,curveParams1:r,depth:t.Gs||0,baseZ:t.Qs||0,geometryType:t.Ns||0})}hi(t){const e=this.mi.hi(t);return this.Xs.ei>this._i.ei&&this._i.ui(this.Xs.ei),e}get Ai(){return this.Xs.ii}get ni(){return this.Xs.ni}bi(){this.Xs.ti()}pi(t){const e=this.Xs.ii;if(e===0)return;const r=this.Xs.si();this._i.fi(r,e),this._i.pi(t)}gi(t){this._i.gi(t)}Ps(t,e){const r=this.Xs.ii;r!==0&&this.A.drawArraysInstanced(t,0,e,r)}gt(){this._i.gt()}}class V{constructor(t,e,r,n){l(this,"A");l(this,"wi");l(this,"Ci");l(this,"xi");l(this,"Mi",null);this.A=t,this.wi=e,this.Ci=r,this.xi=n;const h=this.A.createBuffer();Rt(this.A,this.A.ARRAY_BUFFER,h,this.xi.Fi,this.A.STATIC_DRAW),this.Mi=h}get type(){return this.Ci}get unitGeometry(){return this.xi}get unitBuffer(){return this.Mi}get batch(){return this.wi}Pi(){this.wi.bi()}$i(){return!this.wi.ni}gt(){this.wi.gt(),this.A.deleteBuffer(this.Mi)}Ti(t,e,r){return this.wi.yi(t)}Ri(t,e,r,n,h,a){const c=h.It??0,u=h.Bt??0,f=h.Ht??0,d=h.wt??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:e,width:r,height:n,char0:h.Nt[0],char1:h.Nt[1],char2:h.Nt[2],r1:h.jt[0],g1:h.jt[1],b1:h.jt[2],a1:h.jt[3],r2:h.Xt[0],g2:h.Xt[1],b2:h.Xt[2],a2:h.Xt[3],invert:h.Rt?1:0,flipX:h.Gt?1:0,flipY:h.Qt?1:0,charRot:h.Et,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:ie[this.Ci]??0};return this.wi.hi(A)}}const ae={Fi:gt,Ei:6,...j},ce={Fi: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]),Ei:6,...j},le={Fi:function(o=32){const t=[],e=2*Math.PI/o;for(let r=0;r<o;r++){const n=r*e,h=(r+1)%o*e,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),Ei:96,...j};let ue={Fi:function(o){const t=[];for(let e=0;e<o;e++){const r=e/o,n=(e+1)/o;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),Ei:96,...j};const fe={Fi:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),Ei:3,...j},de={Fi:function(o=16){const t=[];for(let e=0;e<o;e++){const r=e/o,n=(e+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),Ei:96,...j},ge={[F.RECTANGLE]:class extends V{constructor(o,t){super(o,t,F.RECTANGLE,ae)}yi(o,t){return this.Ri(0,0,o.width,o.height,t)}},[F.LINE]:class extends V{constructor(o,t){super(o,t,F.LINE,ce)}yi(o,t){const e=o.x2-o.x1,r=o.y2-o.y1,n=Math.hypot(e,r),h=Math.atan2(r,e),a=t.Ot||1,c=o.x1+e/2-n/2,u=o.y1+r/2,f={...t,xt:(t.xt||0)+h};return this.Ri(c,u,n,a,f)}},[F.ELLIPSE]:class extends V{constructor(o,t){super(o,t,F.ELLIPSE,le)}yi(o,t){return this.Ri(0,0,o.width,o.height,t)}},[F.ARC]:class extends V{constructor(o,t){super(o,t,F.ARC,ue)}yi(o,t){const e=o.start*Math.PI/180,r=o.stop*Math.PI/180;return this.Ri(0,0,o.width,o.height,t,{arcStart:e,arcStop:r})}},[F.TRIANGLE]:class extends V{constructor(o,t){super(o,t,F.TRIANGLE,fe)}yi(o,t){const e=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-e,a=Math.max(o.y1,o.y2,o.y3)-n;return this.Ri(e,n,h,a,t)}},[F.BEZIER_CURVE]:class extends V{constructor(o,t){super(o,t,F.BEZIER_CURVE,de)}yi(o,t){return this.Ri(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 me{constructor(t){l(this,"A");l(this,"Si");l(this,"ki");this.A=t,this.ki=new se(t),this.Si=new Map;for(const e of Object.values(F)){const r=new oe(t),n=new ge[e](t,r);this.Si.set(e,n)}}zi(t){const e=this.Di(t);for(const r of e)this.Li(r)}Di(t){const e=[];let r=null,n=null,h=null;for(const a of t)n!==a.material||h!==a.type?(r&&r.length>0&&e.push({material:n,type:h,commands:r}),r=[a],n=a.material,h=a.type):r.push(a);return r&&r.length>0&&e.push({material:n,type:h,commands:r}),e}Li(t){const{material:e,type:r,commands:n}=t,h=this.Si.get(r);e.shader.D(),e.shader.O(e.uniforms);const a=Mt(this.A),c=n.length>0&&n[0].state.kt;e.shader.O({Uw:a[2]/a[3],Ut:[a[2],a[3]],Uu:1,Uv:c?1:0}),h.Pi();for(const u of n)h.yi(u.params,u.state);if(h.$i()){const u=h.unitGeometry,f=h.unitBuffer;try{this.ki.Ts(e.shader.G,r+"",u,f),h.batch.pi(e.shader),h.batch.Ps(u.As,u.Ei)}finally{h.batch.gi(e.shader),this.ki.Rs(),h.Pi()}}}gt(){for(const t of this.Si.values())t.gt();this.Si.clear(),this.ki.gt()}}function Nt(o){let t=0;for(let e=0;e<o.length;e++)t=(t<<5)-t+o.charCodeAt(e),t&=t;return t}const Ut=new WeakMap;let ve=1;function St(o){if(o==null)return 0;if(typeof o!="object"&&typeof o!="function")return Nt(o+"");let t=Ut.get(o);return t||(t=ve++,Ut.set(o,t)),t}function K(o,t){return(o<<5)-o+t}class pe{constructor(t){l(this,"Oi",0);l(this,"Ii");l(this,"Bi");l(this,"Hi",new Map);this.Ii=new W(t,et,`#version 300 es
10
- precision highp float;in vec3 v_glyphIndex;in vec4 v_glyphColor;in vec4 v_cellColor;in vec4 v_glyphFlags;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;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.Bi={id:this.Oi++,shader:this.Ii,uniforms:Object.freeze({}),hash:this.Gi(this.Ii,{}),isBuiltIn:!0}}get Qi(){return this.Bi}dt(t,e={},r=!1){const n=this.Gi(t,e),h=this.Hi.get(n);if(h)return h;const a={id:this.Oi++,shader:t,uniforms:Object.freeze({...e}),hash:n,isBuiltIn:r};return this.Hi.set(n,a),a}Ni(t,e={}){return{id:this.Oi++,shader:t,uniforms:Object.freeze({...e}),hash:0,isBuiltIn:!1}}Gi(t,e){const r=St(t.G),n=function(h,a){let c=0;const u=Object.keys(h).sort();for(const f of u)c=K(c,Nt(f)),c=K(c,a(h[f]));return c}(e,this.ji.bind(this));return K(r,n)}ji(t){return typeof t=="number"||typeof t=="boolean"?function(e){return typeof e=="boolean"?e?1:0:Math.floor(e)}(t):Array.isArray(t)?function(e){let r=0;const n=Array.isArray(e[0])?e.flat():e;for(const h of n)r=K(r,typeof h=="number"?h:0);return r}(t):t instanceof Float32Array||t instanceof Int32Array?function(e){let r=0;const n=Math.min(e.length,16);for(let h=0;h<n;h++)r=K(r,e[h]);return r}(t):t instanceof WebGLTexture?St(t):0}gt(){this.Ii!=this.Ii&&this.Ii.dispose(),this.Ii.dispose(),this.Hi.clear()}}class Ae{constructor(){l(this,"Xi",[]);l(this,"Yi",1);l(this,"Ss",0)}Ki(t,e){if(this.Ss>=this.Xi.length){const n={id:this.Yi++,type:t,params:{},state:st.Lt(),material:e};this.Xi.push(n)}const r=this.Xi[this.Ss];return r.id=this.Yi++,r.type=t,r.material=e,this.Ss++,r}Wi(t,e,r){const n=this.Ki(F.RECTANGLE,r),h=n.params;return h.width=t.width,h.height=t.height,e.Wt(n.state),n.id}Zi(t,e,r){const n=this.Ki(F.LINE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.x2=t.x2,h.y2=t.y2,h.thickness=t.thickness,e.Wt(n.state),n.id}qi(t,e,r){const n=this.Ki(F.ELLIPSE,r),h=n.params;return h.width=t.width,h.height=t.height,h.startAngle=t.startAngle,h.endAngle=t.endAngle,h.segments=t.segments,e.Wt(n.state),n.id}Vi(t,e,r){const n=this.Ki(F.ARC,r),h=n.params;return h.width=t.width,h.height=t.height,h.start=t.start,h.stop=t.stop,e.Wt(n.state),n.id}Ji(t,e,r){const n=this.Ki(F.TRIANGLE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.x2=t.x2,h.y2=t.y2,h.x3=t.x3,h.y3=t.y3,e.Wt(n.state),n.id}te(t,e,r){const n=this.Ki(F.BEZIER_CURVE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.cp1x=t.cp1x,h.cp1y=t.cp1y,h.cp2x=t.cp2x,h.cp2y=t.cp2y,h.x2=t.x2,h.y2=t.y2,h.thickness=t.thickness,h.segments=t.segments,e.Wt(n.state),n.id}bi(){this.Ss=0}[Symbol.iterator](){let t=0;const e=this.Ss,r=this.Xi;return{next:()=>t<e?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}class Ee{constructor(t){l(this,"A");l(this,"se",null);l(this,"ie");l(this,"vt");l(this,"ee");l(this,"re");l(this,"ne");l(this,"he",null);l(this,"oe",{});l(this,"ae",[]);l(this,"ce",[]);l(this,"le",[]);l(this,"ue",null);l(this,"fe",[0,0,0,0]);l(this,"de",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.ee=new st,this.vt=new pe(t),this.re=new Ae,this.ie=new me(t),this.ne=new ee(t);const e=[0,0,t.canvas.width,t.canvas.height];dt(t,e),this.ae.push(null),this.ce.push(e),this.le.push(1),this.ue=null,this.fe=e,this.de=1}rt(){this.ae.push(this.ue),this.ce.push([...this.fe]),this.le.push(this.de)}lt(){const t=this.ae.pop()??null,e=this.ce.pop()??[0,0,this.A.canvas.width,this.A.canvas.height],r=this.le.pop()??1;this.nt(t,e[2],e[3],r)}nt(t,e,r,n=1){const h=this.A;this.ue!==t&&(h.bindFramebuffer(h.FRAMEBUFFER,t),this.ue=t),this.de=n;const a=[0,0,e,r];this.fe[0]===a[0]&&this.fe[1]===a[1]&&this.fe[2]===a[2]&&this.fe[3]===a[3]||(h.viewport(...a),dt(h,a),this.fe=a)}ve(t){this.se!==t&&(this.se=t,t.D())}pe(t,e){return new W(this.A,t,e)}ge(t){this.he=t,t&&(this.oe={})}I(t,e){this.oe[t]=e}me(t){Object.assign(this.oe,t)}_e(t){return new W(this.A,et,t)}ye(t,e,r){this.re.Wi({width:e??t.width,height:r??t.height},this.ee,t.ut())}Ae(t,e,r,n){this.ne.Ps(t,e,r,n)}be(t,e){if(this.he){const r=this.vt.Ni(this.he,this.oe);this.re.Wi({width:t,height:e},this.ee,r),this.he=null,this.oe={}}else this.re.Wi({width:t,height:e},this.ee,this.vt.Qi)}we(t,e,r,n){this.re.Zi({x1:t,y1:e,x2:r,y2:n},this.ee,this.vt.Qi)}Ce(t,e){this.re.qi({width:t,height:e},this.ee,this.vt.Qi)}xe(t,e,r,n,h,a){this.re.Ji({x1:t,y1:e,x2:r,y2:n,x3:h,y3:a},this.ee,this.vt.Qi)}Me(t,e,r,n,h,a,c,u){this.re.te({x1:t,y1:e,cp1x:r,cp1y:n,cp2x:h,cp2y:a,x2:c,y2:u},this.ee,this.vt.Qi)}Fe(t,e,r,n){this.re.Vi({width:t,height:e,start:r,stop:n},this.ee,this.vt.Qi)}Pe(t,e,r=1,n={}){return new Y(this.A,t,e,r,n,this)}$e(t,e=t,r=t,n=255){this.ee.ps(t,e??t,r??t,n);const[h,a,c,u]=this.ee.canvasBackgroundColor;this.Te(h,a,c,u,!1)}bi(t=0,e=0,r=0,n=0){this.Te(t,e,r,n,!0)}Te(t,e,r,n,h){const a=this.A;if(this.de>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.de>=3&&a.clearBufferfv(a.COLOR,2,new Float32Array([t,e,r,n]));for(let u=3;u<this.de;u++)a.clearBufferfv(a.COLOR,u,new Float32Array([0,0,0,0]))}else a.clearColor(t,e,r,n),a.clear(a.COLOR_BUFFER_BIT)}Re(){const t=[0,0,this.A.canvas.width,this.A.canvas.height];this.A.viewport(...t),dt(this.A,t),this.fe=t,this.ce.length>0&&(this.ce[0]=t)}ct(){const t=this.re;this.ie.zi(t),t.bi(),this.se=null}gt(){this.vt.gt(),this.ie.gt(),this.ne.gt()}get context(){return this.A}get state(){return this.ee}get materialManager(){return this.vt}}const R={readShort:(o,t)=>(R.t.uint16[0]=o[t]<<8|o[t+1],R.t.int16[0]),readUshort:(o,t)=>o[t]<<8|o[t+1],readUshorts(o,t,e){const r=[];for(let n=0;n<e;n++)r.push(R.readUshort(o,t+2*n));return r},readUint(o,t){const e=R.t.uint8;return e[3]=o[t],e[2]=o[t+1],e[1]=o[t+2],e[0]=o[t+3],R.t.uint32[0]},readASCII(o,t,e){let r="";for(let n=0;n<e;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 rt(o){return o+3&-4}function nt(o,t,e){o[t]=e>>>8&255,o[t+1]=255&e}function _(o,t,e){o[t]=e>>>24&255,o[t+1]=e>>>16&255,o[t+2]=e>>>8&255,o[t+3]=255&e}function ye(o,t,e){for(let r=0;r<e.length;r++)o[t+r]=255&e.charCodeAt(r)}function mt(o,t,e){const r=t+e;let n=0;const h=R.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 e=this.bitbuf&(1<<t)-1;return this.bitbuf>>>=t,this.bitcnt-=t,e}alignToByte(){this.bitbuf=0,this.bitcnt=0}get offset(){return this.p}}function q(o){let t=32,e=0;for(const c of o)c&&(c<t&&(t=c),c>e&&(e=c));if(e===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(e+1);for(const c of o)c&&r[c]++;const n=new Uint32Array(e+1);let h=0;r[0]=0;for(let c=1;c<=e;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[be(f,u)]=c}return{min:t,max:e,table:a}}function vt(o,t){let e=0;for(let r=1;r<=t.max;r++){e|=o.readBits(1)<<r-1;const n=t.table.get(r);if(n&&e<n.length){const h=n[e];if(h!==void 0)return h}}throw Error("Invalid Huffman code")}function be(o,t){let e=0;for(let r=0;r<t;r++)e=e<<1|1&o,o>>>=1;return e>>>0}function xe(o){if(o.length<2)throw Error("ZLIB data too short");const t=o[0],e=o[1];if((15&t)!=8)throw Error("Unsupported ZLIB compression method");if(((t<<8)+e)%31!=0)throw Error("Bad ZLIB header check");let r=2;32&e&&(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 y=0;y<=143;y++)A[y]=8;for(let y=144;y<=255;y++)A[y]=9;for(let y=256;y<=279;y++)A[y]=7;for(let y=280;y<=287;y++)A[y]=8;p=q(A),m=q(Array(32).fill(5))}else{const A=h.readBits(5)+257,y=h.readBits(5)+1,E=h.readBits(4)+4,b=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],w=Array(19).fill(0);for(let M=0;M<E;M++)w[b[M]]=h.readBits(3);const P=q(w),x=[];for(;x.length<A+y;){const M=vt(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 ct=0;ct<B;ct++)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 N=x.slice(0,A),D=x.slice(A,A+y);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 y=A-257;let E=c[y];const b=u[y];b&&(E+=h.readBits(b));const w=vt(h,m);if(w>=30)throw Error("Invalid distance symbol");let P=f[w];const x=d[w];x&&(P+=h.readBits(x));const N=a.length-P;if(N<0)throw Error("Invalid distance");for(let D=0;D<E;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 Te(o){const t=R,e=new Uint8Array(o);if(t.readASCII(e,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(e,4),n=t.readUshort(e,12),h=t.readUint(e,16),a=[];let c=44;for(let E=0;E<n;E++){const b=t.readASCII(e,c,4),w=t.readUint(e,c+4),P=t.readUint(e,c+8),x=t.readUint(e,c+12),N=t.readUint(e,c+16);a.push({tag:b,offset:w,compLength:P,origLength:x,checksum:N}),c+=20}for(const E of a){const b=new Uint8Array(e.buffer,E.offset,E.compLength);if(E.compLength===E.origLength)E.data=new Uint8Array(b);else if(E.data=xe(b),E.data.length!==E.origLength)if(E.data.length<E.origLength){const w=new Uint8Array(E.origLength);w.set(E.data),E.data=w}else E.data=E.data.subarray(0,E.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 E of a)m[E.tag]=p,p=rt(p+E.data.length);const A=new Uint8Array(Math.max(h||0,p));_(A,0,r),nt(A,4,u),nt(A,6,g),nt(A,8,d),nt(A,10,v);let y=12;for(const E of a){ye(A,y,E.tag),y+=4;let b=E.data;if(E.tag==="head"&&b.length>=12){const w=new Uint8Array(b);_(w,8,0),_(A,y,mt(w,0,rt(w.length))),y+=4}else _(A,y,mt(b,0,rt(b.length))),y+=4;_(A,y,m[E.tag]),y+=4,_(A,y,E.data.length),y+=4}for(const E of a){const b=m[E.tag];A.set(E.data,b)}if(a.find(E=>E.tag==="head")){const E=m.head,b=function(w,P){const x=P+8,N=[w[x],w[x+1],w[x+2],w[x+3]];_(w,x,0);const D=2981146554-(mt(w,0,rt(w.length))>>>0)>>>0;return w[x]=N[0],w[x+1]=N[1],w[x+2]=N[2],w[x+3]=N[3],D>>>0}(A,E);_(A,E+8,b)}return A.buffer}const Ce={parseTab(o,t,e){const r={tables:[],ids:{},off:t};o=new Uint8Array(o.buffer,t,e),t=0;const n=R,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 e=R,r=e.readUshort,n=e.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(e.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 e=R.readUint;e(o,t+=4),e(o,t+=4);const r=e(o,t+=4);t+=4;const n=new Uint32Array(3*r);for(let h=0;h<3*r;h+=3)n[h]=e(o,t+(h<<2)),n[h+1]=e(o,t+(h<<2)+4),n[h+2]=e(o,t+(h<<2)+8);return{format:12,groups:n}}},Fe={parseTab(o,t,e){const r=R;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)}}},Re={parseTab(o,t,e){const r=R;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}},Pe={parseTab(o,t,e,r){const n=R,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}}},Lt={cmap:Ce,head:Fe,hhea:Re,maxp:{parseTab(o,t,e){const r=R;return r.readUint(o,t),t+=4,{numGlyphs:r.readUshort(o,t)}}},hmtx:Pe,loca:{parseTab(o,t,e,r){const n=R,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,e,r){const n=[],h=r.maxp.numGlyphs;for(let a=0;a<h;a++)n.push(null);return n},Ee(o,t){const e=R,r=o.Se,n=o.loca;if(n[t]===n[t+1])return null;const h=J.findTable(r,"glyf",o.ke);if(!h)return null;let a=h[0]+n[t];const c={};if(c.noc=e.readShort(r,a),a+=2,c.xMin=e.readShort(r,a),a+=2,c.yMin=e.readShort(r,a),a+=2,c.xMax=e.readShort(r,a),a+=2,c.yMax=e.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(e.readUshort(r,a)),a+=2;const u=e.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(e.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(e.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);R.readASCII(t,0,4)==="wOFF"&&(o=Te(o));const e=new Uint8Array(o),r=Lt,n={},h={Se:e,ze:0,ke:0};for(const a in r){const c=a,u=J.findTable(e,c,0);if(u){const[f,d]=u;let g=n[f];g==null&&(g=r[c].parseTab(e,f,d,h),n[f]=g),h[c]=g}}return[h]},findTable(o,t,e){const r=R,n=r.readUshort(o,e+4);let h=e+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:Lt,B:R};class Me{De(t){var r;const e=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const h=this.Le(n);e.push(...h)}else if(n.format===12){const h=this.Oe(n);e.push(...h)}}),[...new Set(e)]):[]}Le(t){const e=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return e;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.Ie(t,a,r)>0)try{const c=String.fromCodePoint(a);e.push(c)}catch{}}}return e}Oe(t){const e=[];if(!t.groups)return e;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);e.push(u)}catch{}}return e}Ie(t,e,r){if(t.idRangeOffset[r]===0)return e+t.idDelta[r]&65535;{const n=t.idRangeOffset[r]/2+(e-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 Ne{constructor(t){l(this,"Be");l(this,"He");l(this,"Z");this.Z=t,this.Be=document.createElement("canvas"),this.He=this.Be.getContext("2d",{willReadFrequently:!0,alpha:!0})}Ge(t,e,r,n){const h=t.length,a=Math.ceil(Math.sqrt(h)),c=Math.ceil(h/a),u=e.width*a,f=e.height*c;this.Qe(u,f),this.Ne(t,e,a,r,n);const d=this.Z.Pe(u,f,1,{filter:"nearest"});return d.et(this.Be),{framebuffer:d,columns:a,rows:c}}Qe(t,e){this.Be.width=t,this.Be.height=e,this.Be.style.width=t+"px",this.Be.style.height=e+"px",this.He.imageSmoothingEnabled=!1,this.Be.style.imageRendering="pixelated",this.He.clearRect(0,0,t,e),this.He.textBaseline="top",this.He.textAlign="left",this.He.fillStyle="white"}Ne(t,e,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*e.width,p=f*e.height,m=v+.5*e.width,A=p+.5*e.height,y=Math.round(m-.5*e.width),E=Math.round(A-.5*n),b=y+.5*(e.width-g),w=E+h.hhea.ascender*a;this.je(d,b,w,a)}}je(t,e,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.He.beginPath();let f=0;for(let d=0;d<c.length;d++){const g=c[d];if(!(g<f)){if(g>=f){const v=e+h[f]*n,p=r-a[f]*n;this.He.moveTo(v,p);let m=f+1;for(;m<=g;)if(1&u[m]){const A=e+h[m]*n,y=r-a[m]*n;this.He.lineTo(A,y),m++}else{const A=e+h[m]*n,y=r-a[m]*n;if(m+1>g){const b=e+h[f]*n,w=r-a[f]*n;if(1&u[f])this.He.quadraticCurveTo(A,y,b,w);else{const P=(A+b)/2,x=(y+w)/2;this.He.quadraticCurveTo(A,y,P,x)}break}const E=m+1;if(1&u[E]){const b=e+h[E]*n,w=r-a[E]*n;this.He.quadraticCurveTo(A,y,b,w),m=E+1}else{const b=(A+(e+h[E]*n))/2,w=(y+(r-a[E]*n))/2;this.He.quadraticCurveTo(A,y,b,w),m=E}}this.He.closePath()}f=g+1}}this.He.fill()}}class Dt{Xe(t,e){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.Ye(e,h):h.format===12&&(n=this.Ke(e,h)),n>0)break;return n}We(t,e){const r=e.codePointAt(0);return r===void 0?0:this.Xe(t,r)}Ze(t,e){const r=t.hmtx;return r&&r.aWidth&&r.aWidth.length!==0?e<r.aWidth.length?r.aWidth[e]:r.aWidth[r.aWidth.length-1]:0}qe(t,e){const r=e/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}}Ye(t,e){const r=e.endCount.length;let n=-1;for(let h=0;h<r;h++)if(t<=e.endCount[h]){n=h;break}if(n===-1||t<e.startCount[n])return 0;if(e.idRangeOffset[n]===0)return t+e.idDelta[n]&65535;{const h=e.idRangeOffset[n]/2+(t-e.startCount[n])-(r-n);if(h>=0&&h<e.glyphIdArray.length){const a=e.glyphIdArray[h];return a===0?0:a+e.idDelta[n]&65535}}return 0}Ke(t,e){const r=e.groups.length/3;for(let n=0;n<r;n++){const h=e.groups[3*n],a=e.groups[3*n+1],c=e.groups[3*n+2];if(t>=h&&t<=a)return c+(t-h)}return 0}}class Ue{constructor(){l(this,"Ve");this.Ve=new Dt}Je(t,e,r){let n=0;const h=this.Ve.qe(r,e),a=h.lineHeight;for(const c of t){const u=this.Ve.We(r,c);if(u===0)continue;const f=this.Ve.Ze(r,u)*h.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}}class Se{constructor(){l(this,"tr");this.tr=new Dt}sr(t,e){const r=[],n=new Map;return t.forEach((h,a)=>{const c=h.codePointAt(0)||0,u={character:h,unicode:c,color:this.ir(a),glyphData:this.er(e,h)};r.push(u),n.set(h,u)}),{array:r,map:n}}ir(t){return[t%256/255,Math.floor(t/256)%256/255,0]}er(t,e){const r=e.codePointAt(0)||0,n=this.tr.Xe(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.Ee(t,n);return a?{...a,advanceWidth:h}:null}}class pt{constructor(t,e=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=e,this.pr=new Me,this.gr=new Ne(t),this.mr=new Ue,this._r=new Se}async yr(t){let e;if(t){const r=await fetch(t);if(!r.ok)throw new C(`Failed to load font file: ${r.status} ${r.statusText}`);e=await r.arrayBuffer()}else e=await(await fetch("data:font/woff;base64,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")).arrayBuffer();await this.Ar(e),this.rr=J.parse(e)[0],await this.br()}wr(t){if(t===void 0)return this.cr;this.cr=t,this.dr=this.mr.Je(this.nr.map(r=>r.character),this.cr,this.rr);const e=this.gr.Ge(this.nr,this.dr,this.cr,this.rr);this.ar=e.framebuffer,this.lr=e.columns,this.ur=e.rows}async Cr(t){try{const e=await fetch(t);if(!e.ok)throw new C(`Failed to load font file: ${e.status} ${e.statusText}`);const r=await e.arrayBuffer();await this.Ar(r);const n=J.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.rr=n[0],await this.br()}catch(e){throw new C("Failed to load font: "+(e instanceof Error?e.message:"Unknown error"),e)}}async Ar(t){const e=Date.now();this.vr=new FontFace("CustomFont_"+e,t),await this.vr.load(),document.fonts.add(this.vr)}async br(){const t=this.pr.De(this.rr),{array:e,map:r}=this._r.sr(t,this.rr);this.nr=e,this.hr=r,this.dr=this.mr.Je(t,this.cr,this.rr);const n=this.gr.Ge(this.nr,this.dr,this.cr,this.rr);this.ar=n.framebuffer,this.lr=n.columns,this.ur=n.rows}Mr(t){const e=this.hr.get(t);return e?e.color:[0,0,0]}Fr(t){return Array.from(t).map(e=>{const r=this.hr.get(e);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,e,r){l(this,"Pr");l(this,"$r");l(this,"N");l(this,"j");l(this,"Tr");l(this,"Rr");l(this,"Er");l(this,"Sr");l(this,"kr");this.Er=t,this.Sr=e,this.kr=r,this.ti()}ti(){this.Pr=Math.floor(this.Er.width/this.Sr),this.$r=Math.floor(this.Er.height/this.kr),this.N=this.Pr*this.Sr,this.j=this.$r*this.kr,this.Tr=Math.floor((this.Er.width-this.N)/2),this.Rr=Math.floor((this.Er.height-this.j)/2)}zr(t,e){this.Sr=t,this.kr=e,this.ti()}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.j}get offsetX(){return this.Tr}get offsetY(){return this.Rr}}const Le=/^rgba?\(([^)]+)\)$/i;function Et(o){return Number.isNaN(o)?0:Math.max(0,Math.min(255,o))}function De(o){if(!o)return null;const t=o.trim().toLowerCase();if(!t)return null;let e=null;return t.startsWith("rgb")&&(e=function(r){const n=Le.exec(r.trim());if(!n)return null;const h=n[1].split(",").map(d=>d.trim());if(h.length<3)return null;const a=Et(parseFloat(h[0])),c=Et(parseFloat(h[1])),u=Et(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)),e?e[3]===0?null:e:null}class Zt{constructor(t={}){l(this,"Er");l(this,"Dr",null);l(this,"Lr",!1);l(this,"Or");this.Lr=t.overlay??!1,this.Lr&&t.canvas?(this.Dr=t.canvas,this.Er=this.Ir(),this.Or=!0,this.Br()):t.canvas?(this.Er=t.canvas,this.Or=!1):(this.Er=this.Hr(t.width,t.height),this.Or=!0),this.Er.style.imageRendering="pixelated"}Hr(t,e){const r=document.createElement("canvas");return r.className="textmodeCanvas",r.style.imageRendering="pixelated",r.width=t||800,r.height=e||600,document.body.appendChild(r),r}Ir(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const e=this.Dr.getBoundingClientRect();let r=Math.round(e.width),n=Math.round(e.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.Er,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.Er.parentElement&&t.push(this.Er.parentElement),t.push(this.Er),t.push(document.body),t.push(document.documentElement),t}Nr(){const t=this.Qr();for(const e of t){if(!e)continue;const r=De(window.getComputedStyle(e).backgroundColor);if(r)return r}return[255,255,255,255]}Gr(){if(!this.Dr)return;const t=this.Dr.getBoundingClientRect();let e=this.Dr.offsetParent;if(e&&e!==document.body){const r=e.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"}jr(t,e){if(this.Lr){const r=this.Dr.getBoundingClientRect();this.Er.width=Math.round(r.width),this.Er.height=Math.round(r.height),this.Gr()}else this.Er.width=t??this.Er.width,this.Er.height=e??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 C("`textmode.js` requires WebGL2 support.");return t}gt(){const t=this.Er.getContext("webgl")||this.Er.getContext("webgl2");if(t){const e=t.getExtension("WEBGL_lose_context");e==null||e.loseContext()}this.Or&&this.Er.parentNode&&this.Er.parentNode.removeChild(this.Er)}get canvas(){return this.Er}get targetCanvas(){return this.Dr}get width(){return this.Er.width}get height(){return this.Er.height}}function ht(o){return z(parseInt(o,16),0,255)}class U{constructor(t,e,r,n){l(this,"Yr");l(this,"Kr");l(this,"r");l(this,"g");l(this,"b");l(this,"a");this.r=z(t,0,255),this.g=z(e,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.Kr=[this.r/255,this.g/255,this.b/255,this.a/255]}static Wr(t,e,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 e=="number"&&typeof r=="number"?U.qr(t,e,r,n??255):U.Jr(t);throw Error("Unsupported color input passed to TextmodeColor.$from.")}static qr(t,e,r,n=255){return new U(t,e,r,n)}static Jr(t,e=255){return new U(t,t,t,e)}static Vr(t){return new U(...function(e){const r=e.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: "+e);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.Yr]}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 yt=new Map;function Bt(o){yt.set(o.id,o)}function _t(o){return yt.get(o)}class Xt{constructor(t,e,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,"j");l(this,"q",null);l(this,"rr");l(this,"rn","brightness");l(this,"nn",null);l(this,"Rt",0);l(this,"Gt",0);l(this,"Qt",0);l(this,"Et",0);l(this,"hn","sampled");l(this,"an","fixed");l(this,"jt",[1,1,1,1]);l(this,"Xt",[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=e,this.tn=r,this.rr=n,this.sn=h,this.en=a,this.N=c,this.j=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.Rt=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.Et=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,e,r,n){return this.gn(this.jt,t,e,r,n),this.q=null,this}cellColor(t,e,r,n){return this.gn(this.Xt,t,e,r,n),this.q=null,this}background(t,e,r,n){return this.gn(this.cn,t,e,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 e=[];for(const r of t){if(e.length>=64)break;let n=U.Wr(r);e.push(n.normalized)}return this.dn=e,this.vn=e.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.j}get originalWidth(){return this.sn}get originalHeight(){return this.en}ut(){return this.q||this.ft(),this.q}yn(){}ft(){this.yn();const t=this.An(),e=this.bn(),r=t.createShader(e),n=t.createUniforms(e);this.q=this.Z.materialManager.Ni(r,n)}gn(t,e,r,n,h){const a=U.Wr(e,r,n,h);it(t,a.r,a.g,a.b,a.a)}mn(t){const e=this.rr.Fr(t).filter(r=>Array.isArray(r)).slice(0,255);this.ln=e.length>0?e:this.ln}createBaseConversionUniforms(){const t=this.vn>0;return{u_image:this.wn(),u_invert:!!this.Rt,u_flipX:!!this.Gt,u_flipY:!!this.Qt,u_charRotation:this.Et,u_charColorFixed:this.hn==="fixed",u_charColor:this.jt,u_cellColorFixed:this.an==="fixed",u_cellColor:this.Xt,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}}An(){if(this.nn&&this.nn.id===this.rn)return this.nn;const t=_t(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}bn(){return{renderer:this.Z,gl:this.A,font:this.rr,source:this,gridWidth:this.N,gridHeight:this.j}}}class G extends Xt{constructor(t,e,r,n,h,a,c,u){const f=Math.min(c/h,u/a);super(t,e,r,n,h,a,Math.max(1,Math.floor(h*f)),Math.max(1,Math.floor(a*f)))}static Cn(t,e,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 G(a,t,c,e,u,f,n,h)}wn(){return this.tn}}class Ot{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,"Rn",[]);l(this,"En",10);l(this,"Sn",0);this.xn=1e3/t}kn(t){if(!this.Pn)return;this.Fn=performance.now();const e=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(e))};this.Mn=requestAnimationFrame(e)}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))}On(t,e){if(t===void 0)return this.$n;this.xn=1e3/t,this.Pn&&e&&(this.zn(),this.kn(e))}In(){const t=performance.now();if(this.Tn>0){const e=t-this.Tn;this.Rn.push(e),this.Rn.length>this.En&&this.Rn.shift();const r=this.Rn.reduce((n,h)=>n+h,0)/this.Rn.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 It{constructor(t){l(this,"Er");l(this,"Nn");l(this,"jn",{x:-1,y:-1});l(this,"Xn",{x:-1,y:-1});l(this,"Yn",null);l(this,"Kn",0);l(this,"Wn");l(this,"Zn");l(this,"qn");l(this,"Vn");l(this,"Jn");l(this,"th");l(this,"sh",!1);l(this,"ih");l(this,"eh");l(this,"rh");l(this,"nh");l(this,"hh");this.Er=t}oh(t){const e=performance.now()+Math.max(0,t);e>this.Kn&&(this.Kn=e)}ah(){return performance.now()<this.Kn}uh(t){const e=this.Er.canvas;e.style.cursor=t==null||t===""?"":t}yr(t){this.Nn=t,this.fh()}dh(){if(this.sh)return;const t=this.Er.canvas;this.Wn=e=>{this.ph(e),this.gh(e)},this.Zn=()=>{this.Xn={...this.jn},this.jn.x=-1,this.jn.y=-1,this.Yn=null},this.qn=e=>{this.ph(e),this.mh(e)},this.Vn=e=>{this.ph(e),this._h(e)},this.Jn=e=>{this.ph(e),this.yh(e)},this.th=e=>{this.ph(e),this.Ah(e)},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.th,{passive:!1}),this.sh=!0}bh(){if(!this.sh)return;const t=this.Er.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.th),this.sh=!1}fh(){if(this.sh)try{if(this.Yn){const t=new MouseEvent("mousemove",{clientX:this.Yn.x,clientY:this.Yn.y,bubbles:!1,cancelable:!1});this.ph(t)}else this.jn.x!==-1&&this.jn.y!==-1&&(this.jn.x>=this.Nn.cols||this.jn.y>=this.Nn.rows)&&(this.jn.x=-1,this.jn.y=-1)}catch{this.jn.x=-1,this.jn.y=-1}}wh(t){this.ih=t}Ch(t){this.eh=t}xh(t){this.rh=t}Mh(t){this.nh=t}Fh(t){this.hh=t}Ph(){return{x:this.jn.x,y:this.jn.y}}gh(t){if(this.nh&&!this.ah()){const e={position:{...this.jn},previousPosition:{...this.Xn},originalEvent:t};this.nh(e)}}mh(t){if(this.eh&&!this.ah()){const e={position:{...this.jn},previousPosition:{...this.Xn},button:t.button,originalEvent:t};this.eh(e)}}_h(t){if(this.rh&&!this.ah()){const e={position:{...this.jn},previousPosition:{...this.Xn},button:t.button,originalEvent:t};this.rh(e)}}yh(t){if(this.ih&&!this.ah()){const e={position:{...this.jn},previousPosition:{...this.Xn},button:t.button,originalEvent:t};this.ih(e)}}Ah(t){if(this.hh&&!this.ah()){const e={position:{...this.jn},previousPosition:{...this.Xn},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.hh(e)}}ph(t){const e=this.Er.canvas;this.Xn={...this.jn},this.Yn={x:t.clientX,y:t.clientY};const r=e.getBoundingClientRect(),n=t.clientX-r.left,h=t.clientY-r.top,a=e.width/r.width,c=h*(e.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.jn.x=d,this.jn.y=g):(this.jn.x=-1,this.jn.y=-1)}}const Ze=Object.freeze(Object.defineProperty({__proto__:null,MouseManager:It},Symbol.toStringTag,{value:"Module"}));class zt{constructor(){l(this,"$h",new Map);l(this,"Th",null);l(this,"Rh",null);l(this,"Eh");l(this,"Sh");l(this,"sh",!1);l(this,"kh");l(this,"zh");l(this,"Dh",{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"})}dh(){this.sh||(this.Eh=t=>{this.Lh(t)},this.Sh=t=>{this.Oh(t)},window.addEventListener("keydown",this.Eh,{passive:!1}),window.addEventListener("keyup",this.Sh,{passive:!1}),this.sh=!0)}bh(){this.sh&&(window.removeEventListener("keydown",this.Eh),window.removeEventListener("keyup",this.Sh),this.sh=!1,this.$h.clear(),this.Th=null,this.Rh=null)}Ch(t){this.kh=t}xh(t){this.zh=t}Ih(t){const e=this.Bh(t),r=this.$h.get(t)||this.$h.get(e);return(r==null?void 0:r.isPressed)||!1}Hh(){return this.Th}Gh(){return this.Rh}Qh(){const t=[];for(const[e,r]of this.$h)r.isPressed&&t.push(e);return t}Nh(){return{ctrl:this.Ih("Control"),shift:this.Ih("Shift"),alt:this.Ih("Alt"),meta:this.Ih("Meta")}}jh(){this.$h.clear(),this.Th=null,this.Rh=null}Lh(t){const e=t.key,r=Date.now();this.$h.has(e)||this.$h.set(e,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.$h.get(e);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.Th=e,this.kh)){const h={key:e,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.kh(h)}}Oh(t){const e=t.key,r=Date.now();this.$h.has(e)||this.$h.set(e,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.$h.get(e);if(n.isPressed=!1,n.lastReleaseTime=r,this.Rh=e,this.zh){const h={key:e,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.zh(h)}}Bh(t){return this.Dh[t]||t.toLowerCase()}}const Be=Object.freeze(Object.defineProperty({__proto__:null,KeyboardManager:zt},Symbol.toStringTag,{value:"Module"}));class Yt{constructor(t,e){l(this,"Er");l(this,"Xh");l(this,"Nn");l(this,"Yh",new Map);l(this,"Kh",new Map);l(this,"Wh",new Map);l(this,"Zh",null);l(this,"qh");l(this,"Vh");l(this,"Jh");l(this,"so");l(this,"io");l(this,"eo");l(this,"sh",!1);l(this,"ro");l(this,"no");l(this,"ho");l(this,"oo");l(this,"ao");l(this,"co");l(this,"lo");l(this,"uo");l(this,"fo");l(this,"do");l(this,"vo",320);l(this,"po",350);l(this,"mo",10);l(this,"_o",550);l(this,"yo",14);l(this,"Ao",48);l(this,"bo",650);l(this,"wo",.02);l(this,"Co",2);l(this,"xo",600);l(this,"Mo",0);l(this,"Fo",null);this.Er=t,this.Xh=e;const r=this.Er.canvas;this.qh=r.style.touchAction,this.Vh=r.style.userSelect,r.style.touchAction||(r.style.touchAction="none"),r.style.userSelect||(r.style.userSelect="none")}yr(t){this.Nn=t,this.fh()}dh(){if(this.sh)return;const t=this.Er.canvas;this.Jh=e=>{this.Po(e)},this.so=e=>{this.$o(e)},this.io=e=>{this.To(e)},this.eo=e=>{this.Ro(e)},t.addEventListener("touchstart",this.Jh,{passive:!1}),t.addEventListener("touchmove",this.so,{passive:!1}),t.addEventListener("touchend",this.io,{passive:!1}),t.addEventListener("touchcancel",this.eo,{passive:!1}),this.sh=!0}bh(){if(!this.sh)return;const t=this.Er.canvas;t.removeEventListener("touchstart",this.Jh),t.removeEventListener("touchmove",this.so),t.removeEventListener("touchend",this.io),t.removeEventListener("touchcancel",this.eo),this.sh=!1,this.Zh=null,this.Yh.clear(),this.Kh.clear(),this.Wh.forEach(e=>{e.longPressTimer!==null&&window.clearTimeout(e.longPressTimer)}),this.Wh.clear(),this.Fo=null,this.Mo=0,t.style.touchAction=this.qh,t.style.userSelect=this.Vh}fh(){if(!this.Nn||this.Yh.size===0)return;const t=new Map;for(const e of this.Yh.values()){const r=this.Eo(e.clientX,e.clientY,e.id,e);t.set(e.id,r)}this.Yh=t}So(){return Array.from(this.Yh.values()).map(t=>({...t}))}ko(t){this.ro=t}Mh(t){this.no=t}zo(t){this.ho=t}Do(t){this.oo=t}Lo(t){this.ao=t}Oo(t){this.co=t}Io(t){this.lo=t}Bo(t){this.uo=t}Ho(t){this.fo=t}Go(t){this.do=t}Po(t){var n;if(!this.Nn)return;t.preventDefault(),(n=this.Xh)==null||n.oh(this.xo);const e=performance.now(),r=this.Qo(t.changedTouches);for(const h of r){const a=this.Yh.get(h.id);a&&this.Kh.set(h.id,this.No(a)),this.Yh.set(h.id,h);const c={id:h.id,startPosition:h,lastPosition:h,startTime:e,lastTime:e,longPressTimer:null,longPressFired:!1};this.lo&&(c.longPressTimer=window.setTimeout(()=>{const u=this.Yh.get(h.id);u&&(c.longPressFired=!0,this.lo({touch:this.No(u),duration:performance.now()-c.startTime,originalEvent:t}))},this._o)),this.Wh.set(h.id,c),this.ro&&this.ro(this.jo(h,t,void 0,e))}this.Yh.size===2&&this.Xo()}$o(t){var n;if(!this.Nn)return;t.preventDefault(),(n=this.Xh)==null||n.oh(this.xo);const e=performance.now(),r=this.Qo(t.changedTouches);for(const h of r){const a=this.Yh.get(h.id),c=a?this.No(a):void 0;c&&this.Kh.set(h.id,c),this.Yh.set(h.id,h);const u=this.Wh.get(h.id);u&&(u.lastPosition=h,u.lastTime=e,c)&&H(c.clientX,c.clientY,h.clientX,h.clientY)>this.yo&&u.longPressTimer!==null&&(window.clearTimeout(u.longPressTimer),u.longPressTimer=null),this.no&&this.no(this.jo(h,t,c,e))}this.Yh.size===2?this.Yo(t):this.Zh=null}To(t){if(!this.Nn)return;t.preventDefault();const e=performance.now(),r=this.Qo(t.changedTouches);for(const n of r){const h=this.Yh.get(n.id),a=h?this.No(h):void 0,c=this.Wh.get(n.id);c&&c.longPressTimer!==null&&(window.clearTimeout(c.longPressTimer),c.longPressTimer=null),this.ho&&this.ho(this.jo(n,t,a,e)),c&&this.Ko(c,t),this.Wh.delete(n.id),this.Kh.delete(n.id),this.Yh.delete(n.id)}this.Yh.size<2&&(this.Zh=null)}Ro(t){if(!this.Nn)return;t.preventDefault();const e=performance.now(),r=this.Qo(t.changedTouches);for(const n of r){const h=this.Yh.get(n.id),a=h?this.No(h):void 0,c=this.Wh.get(n.id);c&&c.longPressTimer!==null&&(window.clearTimeout(c.longPressTimer),c.longPressTimer=null),this.oo&&this.oo(this.jo(n,t,a,e)),this.Wh.delete(n.id),this.Kh.delete(n.id),this.Yh.delete(n.id)}this.Yh.size<2&&(this.Zh=null)}Qo(t){const e=[];for(let r=0;r<t.length;r+=1){const n=t.item(r);n&&e.push(this.Wo(n))}return e}Wo(t){return this.Eo(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})}Eo(t,e,r,n){const h=this.Er.canvas,a=h.getBoundingClientRect(),c=t-a.left,u=e-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:e,pressure:n.pressure,radiusX:n.radiusX,radiusY:n.radiusY,rotationAngle:n.rotationAngle}}jo(t,e,r,n){const h=this.Wh.get(t.id),a=Array.from(this.Kh.values()).map(f=>this.No(f)),c=Array.from(this.Yh.values()).map(f=>this.No(f)),u=this.Qo(e.changedTouches);return{touch:this.No(t),previousTouch:r?this.No(r):void 0,touches:c,previousTouches:a,changedTouches:u,deltaTime:h?n-h.lastTime:0,originalEvent:e}}Xo(){if(this.Yh.size!==2)return void(this.Zh=null);const t=Array.from(this.Yh.values()),[e,r]=t,n=H(e.x,e.y,r.x,r.y),h=Tt(e.clientX,e.clientY,r.clientX,r.clientY);this.Zh={ids:[e.id,r.id],initialDistance:Math.max(n,1e-4),initialAngle:h,lastScale:1,lastRotation:0}}Yo(t){if(this.Zh||this.Xo(),!this.Zh)return;const[e,r]=this.Zh.ids,n=this.Yh.get(e),h=this.Yh.get(r);if(!n||!h)return;const a=H(n.x,n.y,h.x,h.y)/this.Zh.initialDistance,c=a-this.Zh.lastScale;this.fo&&Math.abs(c)>this.wo&&(this.fo({touches:[this.No(n),this.No(h)],scale:a,deltaScale:c,center:this.Zo(n,h),originalEvent:t}),this.Zh.lastScale=a);let u=Tt(n.clientX,n.clientY,h.clientX,h.clientY)-this.Zh.initialAngle;u=(u+180)%360-180;const f=u-this.Zh.lastRotation;this.do&&Math.abs(f)>this.Co&&(this.do({touches:[this.No(n),this.No(h)],rotation:u,deltaRotation:f,center:this.Zo(n,h),originalEvent:t}),this.Zh.lastRotation=u)}Zo(t,e){const r=(t.clientX+e.clientX)/2,n=(t.clientY+e.clientY)/2,h=this.Eo(r,n,-1,{id:-1,x:-1,y:-1,clientX:r,clientY:n});return{x:h.x,y:h.y}}Ko(t,e){const r=performance.now(),n=r-t.startTime,h=H(t.startPosition.clientX,t.startPosition.clientY,t.lastPosition.clientX,t.lastPosition.clientY);if(!t.longPressFired&&n<=this.vo&&h<=this.mo)this.qo(t.lastPosition,r)&&this.co?this.co({touch:this.No(t.lastPosition),taps:2,originalEvent:e}):this.ao&&this.ao({touch:this.No(t.lastPosition),taps:1,originalEvent:e});else if(!t.longPressFired&&n<=this.bo&&h>=this.Ao){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.uo&&this.uo({touch:this.No(t.lastPosition),direction:u,distance:c,velocity:f,originalEvent:e})}this.Mo=r,this.Fo=this.No(t.lastPosition)}qo(t,e){return!!this.Fo&&!(e-this.Mo>this.po)&&H(t.clientX,t.clientY,this.Fo.clientX,this.Fo.clientY)<=this.mo}No(t){return{...t}}}const _e=Object.freeze(Object.defineProperty({__proto__:null,TouchManager:Yt},Symbol.toStringTag,{value:"Module"}));class Xe{constructor(t,e){l(this,"A");l(this,"Vo");l(this,"$n",null);l(this,"Jo",0);l(this,"ta",!1);l(this,"sa",[]);l(this,"ia",-1);this.A=t,this.Vo=e}get isPreloaded(){return this.ta}get totalFrames(){return this.Jo}get frameRate(){return this.$n}get textures(){return this.sa}dispose(){this.ea(),this.sa=[],this.$n=null,this.Jo=0,this.ta=!1,this.ia=-1}async preload(t,e){var r;try{if(t<=0)throw Error("Video preload requires a frameRate greater than 0.");const n=this.Vo.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,e)?(this.ha("captureStream",e),"captureStream"):(await this.oa(t,e),this.ha("seeking",e),"seeking")}catch(n){const h=n instanceof Error?n:Error(n+"");throw(r=e==null?void 0:e.onError)==null||r.call(e,h),this.dispose(),h}}ra(t,e){this.ea(),this.$n=t,this.Jo=e,this.sa=[],this.ta=!1,this.ia=-1}ha(t,e){var r;if(this.sa.length===0)throw Error(`Video preload via ${t} completed but produced 0 frames.`);this.Jo=this.sa.length,this.ta=!0,this.ia=-1,this.Vo.pause(),this.Vo.currentTime=0,e!=null&&e.onProgress&&e.onProgress({percent:100,loadedFrames:this.Jo,totalFrames:this.Jo,strategy:t}),(r=e==null?void 0:e.onComplete)==null||r.call(e,{totalFrames:this.Jo,strategy:t})}aa(t){const e=this.A,r=e.createTexture();return e.bindTexture(e.TEXTURE_2D,r),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,1),tt(e,e.LINEAR,e.LINEAR,e.CLAMP_TO_EDGE,e.CLAMP_TO_EDGE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.bindTexture(e.TEXTURE_2D,null),r}ca(t,e){if(!(e!=null&&e.onProgress)||this.Jo===0)return;const r=Math.min(99,Math.floor(this.sa.length/this.Jo*100)),n=10*Math.floor(r/10);n>this.ia&&(this.ia=n,e.onProgress({percent:r,loadedFrames:this.sa.length,totalFrames:this.Jo,strategy:t}))}async na(t,e){const r=globalThis,n=r==null?void 0:r.MediaStreamTrackProcessor,h=this.Vo.captureStream;if(typeof n!="function"||typeof h!="function")return!1;let a,c=null;try{const u=h.call(this.Vo);if(a=u.getVideoTracks()[0],!a)return u.getTracks().forEach(g=>g.stop()),!1;if(c=new n({track:a}).readable.getReader(),this.Vo.currentTime=0,this.Vo.muted=!0,await this.Vo.play().catch(()=>{}),this.Vo.paused)return!1;const f=1e6/t;let d=0;for(;this.sa.length<this.Jo;){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",e))}finally{v.close()}}return c.releaseLock(),a.stop(),c=null,a=void 0,this.Vo.pause(),this.Vo.currentTime=0,this.sa.length!==0}catch{return this.ea(),this.sa=[],this.ia=-1,!1}finally{if(c)try{await c.cancel()}catch{}a&&a.stop(),this.Vo.pause(),this.Vo.currentTime=0}}async oa(t,e){const r=1/t,n=this.Jo,h=this.Vo;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",e)}h.currentTime=0}la(t){return new Promise((e,r)=>{const n=this.Vo,h=()=>{n.removeEventListener("seeked",a),n.removeEventListener("error",c)},a=()=>{h(),e()},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 e();n.currentTime=f})}ea(){for(const t of this.sa)this.A.deleteTexture(t)}}class ot extends Xt{constructor(e,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(e,r,n,h,c,u,v,p);l(this,"Vo");l(this,"ua",0);l(this,"fa",null);this.Vo=a}gt(){var e;super.gt(),(e=this.fa)==null||e.dispose(),this.fa=null,this.Vo.pause(),this.Vo.src="",this.Vo.load()}da(){var e;if(!((e=this.fa)!=null&&e.isPreloaded)&&this.Vo.readyState>=this.Vo.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.Vo),r.bindTexture(r.TEXTURE_2D,null)}}wn(){var r,n;const e=(r=this.fa)==null?void 0:r.textures;return e&&e.length>0&&((n=this.fa)!=null&&n.isPreloaded)?e[this.ua%e.length]:this.tn}ut(){return this.q=null,super.ut()}yn(){this.da()}frame(e){var n,h;const r=((n=this.fa)==null?void 0:n.totalFrames)??0;return(h=this.fa)!=null&&h.isPreloaded&&e!==void 0&&r>0&&(this.ua=(e%r+r)%r,this.q=null),this}static async Cn(e,r,n,h,a,c){const u=e.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,y)=>{d.addEventListener("loadedmetadata",()=>A(),{once:!0}),d.addEventListener("error",E=>{var w;const b=E.target;y(Error("Failed to load video: "+(((w=b.error)==null?void 0:w.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,e,g,r,d,v,p,h,a);return f&&f>0&&(m.fa=new Xe(u,d),await m.fa.preload(f,c),m.ua=0),m}async play(){await this.Vo.play()}pause(){this.Vo.pause()}stop(){this.Vo.pause(),this.Vo.currentTime=0}speed(e){return this.Vo.playbackRate=e,this}loop(e=!0){return this.Vo.loop=e,this}time(e){return this.Vo.currentTime=e,this}volume(e){return this.Vo.volume=Math.max(0,Math.min(1,e)),this}get texture(){return this.tn}get width(){return this.N}get height(){return this.j}get originalWidth(){return this.sn}get originalHeight(){return this.en}get videoElement(){return this.Vo}get currentTime(){return this.Vo.currentTime}get duration(){return this.Vo.duration}get isPlaying(){return!this.Vo.paused&&!this.Vo.ended}get totalFrames(){var e;return((e=this.fa)==null?void 0:e.totalFrames)??0}}const Oe=o=>class extends o{va(t,e,r,n){if(U.Zr(t))return t;if(typeof t=="number"||typeof t=="string")return this.color(t,e,r,n);throw Error("Unsupported color input passed to color-capable method.")}rotate(t=0,e=0,r=0){this.Z.state.Vt(t),this.Z.state.Jt(e),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,e=0,r=0){this.Z.state.ss(t,e,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.ht()}pop(){this.Z.state.ot()}color(t,e,r,n){return U.Wr(t,e,r,n)}rect(t=1,e=1){this.Z.be(t,e)}point(){this.Z.be(1,1)}line(t,e,r,n){this.Z.we(t,e,r,n)}lineWeight(t){this.Z.state.Zt(t)}background(t,e,r,n=255){const h=this.va(t,e,r,n);this.Z.$e(h.r,h.g,h.b,h.a)}char(t){const e=Array.from(t);if(e.length===0)throw Error("char() requires at least one character.");this.Z.state.hs(this.rr.Mr(e[0]))}charColor(t,e,r,n){const h=this.va(t,e,r,n);this.Z.state.cs(h.r,h.g,h.b,h.a)}cellColor(t,e,r,n){const h=this.va(t,e,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.bi(0,0,0,0)}ellipse(t,e){this.Z.Ce(t/2,e/2)}triangle(t,e,r,n,h,a){this.Z.xe(t,e,r,n,h,a)}bezierCurve(t,e,r,n,h,a,c,u){this.Z.Me(t,e,r,n,h,a,c,u)}arc(t,e,r,n){this.Z.Fe(t/2,e/2,r,n)}shader(t){this.Z.ge(t)}setUniform(t,e){this.Z.I(t,e)}setUniforms(t){this.Z.me(t)}async createFilterShader(t){if(typeof t=="string"&&(t.startsWith("./")||t.startsWith("../")||t.endsWith(".frag")||t.endsWith(".glsl"))){const e=await fetch(t);if(!e.ok)throw Error(`Failed to load shader from ${t}: ${e.statusText}`);const r=await e.text();return this.Z._e(r)}return this.Z._e(t)}createFramebuffer(t){return this.Z.Pe(t.width??this.grid.cols,t.height??this.grid.rows,t.attachments??3)}image(t,e,r){this.Z.ye(t,e,r),t instanceof Y&&this.Z.ct()}ortho(){this.Z.state.gs(!0)}async loadImage(t){if(typeof t!="string"){const h=G.Cn(this.Z,this.rr,t,this.Nn.cols,this.Nn.rows);return this.pa(h),h}const e=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=e}),n=G.Cn(this.Z,this.rr,r,this.Nn.cols,this.Nn.rows);return this.pa(n),n}async loadVideo(t,e){const r=await ot.Cn(this.Z,this.rr,t,this.Nn.cols,this.Nn.rows,e);return this.pa(r),r}},Ie=o=>class extends o{async loadFont(t){return this.rr.Cr(t).then(()=>{const e=this.rr.maxGlyphDimensions;this.Nn.zr(e.width,e.height),this.ga.resize(this.Nn.cols,this.Nn.rows),this.Z.Re(),this.Xh.fh(),this.ma.fh();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.wr(t);const e=this.rr.maxGlyphDimensions;this.Nn.zr(e.width,e.height),this.ga.resize(this.Nn.cols,this.Nn.rows),this.Z.Re(),this.Xh.fh(),this.ma.fh()}},ze=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.On(t,()=>this.ba())}noLoop(){this.ya.Dn()}loop(){this.ya.Ln(()=>this.ba())}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 e=0;e<t;e++)this.ba()}isLooping(){return this.ya.Bn}},Ye=o=>class extends o{constructor(...t){super(...t)}mouseClicked(t){this.Xh.wh(t)}mousePressed(t){this.Xh.Ch(t)}mouseReleased(t){this.Xh.xh(t)}mouseMoved(t){this.Xh.Mh(t)}mouseScrolled(t){this.Xh.Fh(t)}get mouse(){return this.Xh.Ph()}cursor(t){this.Xh.uh(t)}},je=o=>class extends o{constructor(...t){super(...t)}touchStarted(t){this.ma.ko(t)}touchMoved(t){this.ma.Mh(t)}touchEnded(t){this.ma.zo(t)}touchCancelled(t){this.ma.Do(t)}tap(t){this.ma.Lo(t)}doubleTap(t){this.ma.Oo(t)}longPress(t){this.ma.Io(t)}swipe(t){this.ma.Bo(t)}pinch(t){this.ma.Ho(t)}rotateGesture(t){this.ma.Go(t)}get touches(){return this.ma.So()}},Ve=o=>class extends o{constructor(...t){super(...t)}keyPressed(t){this.wa.Ch(t)}keyReleased(t){this.wa.xh(t)}isKeyPressed(t){return this.wa.Ih(t)}get lastKeyPressed(){return this.wa.Hh()}get lastKeyReleased(){return this.wa.Gh()}get pressedKeys(){return this.wa.Qh()}get modifierState(){return this.wa.Nh()}};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 e of t){if(this.xa.has(e.name))return void console.warn(`[textmode.js] Plugin "${e.name}" is already installed.`);const r=this.Ta(e.name);try{await e.install(this.Ca,r)}catch(n){throw this.Ra(e.name),n}this.xa.set(e.name,e),this.Ma.push(e.name)}}async Ea(t){const e=this.xa.get(t);if(!e)return;const r=this.Ta(t);e.uninstall&&await e.uninstall(this.Ca,r),this.xa.delete(t),this.Ma.splice(this.Ma.indexOf(t),1),this.Ra(t)}Sa(){this.ka(this.Fa)}za(){this.ka(this.Pa)}async Da(){const t=[...this.xa.keys()];for(const e of t)await this.Ea(e)}Ta(t){return{renderer:this.Ca.Z,font:this.Ca.rr,grid:this.Ca.Nn,canvas:this.Ca.Er,drawFramebuffer:this.Ca.ga,asciiFramebuffer:this.Ca.La,registerPreDrawHook:e=>this.Oa(this.Fa,t,e),registerPostDrawHook:e=>this.Oa(this.Pa,t,e)}}Oa(t,e,r){const n=t.get(e)??new Set;return n.add(r),t.set(e,n),()=>{const h=t.get(e);h&&(h.delete(r),h.size===0&&t.delete(e))}}Ra(t){this.Fa.delete(t),this.Pa.delete(t)}ka(t){for(const e of this.Ma){const r=t.get(e);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 jt{constructor(){l(this,"Ia",new Map);l(this,"Ba",[]);l(this,"Ha",0);l(this,"Ga",0);l(this,"Qa")}get Na(){return this.Ha}get ja(){if(this.Ha===0)return 0;let t=0;for(const e of this.Ba){const r=this.Ia.get(e);r&&(t+=Math.min(1,Math.max(0,r.progress))*r.weight)}return Math.min(1,t/this.Ha)}Xa(t){this.Qa=t}Ya(t,e=1){const r=`phase-${this.Ba.length+1}-${Date.now()}`,n={id:r,label:t,weight:Math.max(.001,e),progress:0,status:"running"};return this.Ia.set(r,n),this.Ba.push(r),this.Ha+=n.weight,r}Ka(t,e){const r=this.Ia.get(t);if(!r)return;r.progress=Math.max(0,Math.min(1,e)),r.status=r.progress>=1?"complete":"running";const n=this.ja;Math.abs(n-this.Ga)>.001&&(this.Ga=n,this.Qa&&this.Qa(n))}Wa(t){const e=this.Ia.get(t);e&&(e.progress=1,e.status="complete",this.Ka(t,1))}Za(t){const e=this.Ia.get(t);e&&(e.status="failed")}qa(){return this.Ba.map(t=>{const e=this.Ia.get(t);return e?{id:e.id,label:e.label,weight:e.weight,progress:e.progress,status:e.status}:{id:t,label:t,weight:1,progress:0,status:"pending"}})}}class Vt{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 hc(){return this.tc}oc(){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 Gt{constructor(t,e){l(this,"dc",0);l(this,"vc",1);l(this,"gc");l(this,"mc");this.gc=t,this.mc=e}get _c(){return this.vc}get yc(){return this.vc<1}kn(){this.gc!=="none"&&this.mc>0&&(this.dc=performance.now())}et(){if(this.gc==="none"||this.mc===0)return this.vc=1,!1;const t=performance.now()-this.dc,e=Math.min(1,t/this.mc);return e>=1?(this.vc=0,!0):(this.vc=1-e,!1)}ti(){this.vc=1,this.dc=0}}function wt(o,t){const e=o.tone??"auto";let r="dark";return e==="light"||e==="dark"?r=e: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 Wt(o,t){return o.length?o.map(e=>t.color(e)):[t.color("#FFFFFF")]}const ke=({textmodifier:o,grid:t,progress:e,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 y=o.color(a.mode==="light"?"#D32F2F":"#FF6B6B",m);o.charColor(y),o.push(),o.translate(0,-2,0),o.char("X"),o.rect(1,1),o.pop();const E="SETUP ERROR",b=-Math.floor(E.length/2);o.push(),o.translate(b,0,0);for(const w of E)o.char(w),o.rect(1,1),o.translateX(1);if(o.pop(),d){const w=o.color(a.subtleColor),P=o.color(w.r,w.g,w.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 B=D.slice(0,3);D.length>3&&(B[2]=B[2].substring(0,x-3)+"..."),B.forEach((L,ct)=>{const ri=-Math.floor(L.length/2);o.push(),o.translate(ri,3+ct,0);for(const ni of L)o.char(ni),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(),e>0||c.some(y=>y.status!=="pending")){const y=Math.max(6,Math.floor(.6*t.cols)),E=-Math.floor(y/2),b=Math.floor(y*e),w=h.length?h:[o.color("#FFFFFF")];o.push(),o.translate(E,3,0);for(let P=0;P<y;P++){const x=P<b?"*":".",N=w[P%w.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 y=o.color(a.subtleColor),E=o.color(y.r,y.g,y.b,m);o.charColor(E);const b=-Math.floor(n.length/2);o.push(),o.translate(b,5,0);for(const w of n)o.char(w),o.rect(1,1),o.translateX(1);o.pop()}},We={message:"LOADING...",tone:"auto",transition:"fade",transitionDuration:500};class He{constructor(t,e,r){this.bc=t,this.id=e,this.label=r}report(t){this.bc.Ka(this.id,t)}complete(){this.bc.Wa(this.id)}fail(t){this.bc.Za(this.id)}async track(t){try{const e=typeof t=="function"?await t():await t;return this.complete(),e}catch(e){throw this.fail(),e}}}class Ht{constructor(t,e,r){l(this,"Ca");l(this,"l");l(this,"wc");l(this,"bc");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,"Rc");l(this,"Ec",performance.now());l(this,"Sc",0);l(this,"kc",!1);l(this,"zc",!1);l(this,"Ic");this.Ca=t,this.l={...We,...e??{}},this.wc=new Vt("active"),this.bc=new jt,this.Cc=new Gt(this.l.transition,this.l.transitionDuration),this.xc=new Ot(60),this.Rc=wt(this.l,r);const n=kt(this.Rc);this.Tc=Wt(n,this.Ca),this.Z=this.Dc(),this.bc.Xa(h=>{h>=.999&&this.ac()})}async yr(t){if(this.zc)return;const e=this.Ca.Z,r=this.Ca.Er;this.Mc=new pt(e,16),await this.Mc.yr(t);const n=this.Mc.maxGlyphDimensions;this.Fc=new At(r.canvas,n.width,n.height),this.Pc=e.Pe(this.Fc.cols,this.Fc.rows,3),this.$c=e.Pe(this.Fc.width,this.Fc.height,1),this.zc=!0}get rc(){return this.wc.rc&&this.kc}kn(){this.kc||(this.kc=!0,this.Ec=performance.now(),this.Sc=0,this.xc.kn(()=>this.Lc()))}zn(){this.kc&&(this.kc=!1,this.xc.zn())}jr(){this.zc&&(this.Fc.ti(),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.bc.ja}message(t){return typeof t=="string"&&(this.l.message=t),this.l.message}addPhase(t,e=1){this.wc.oc();const r=this.bc.Ya(t,e);return new He(this.bc,r,t)}ac(){this.l.transition!=="none"&&this.l.transitionDuration>0?(this.wc.cc(),this.Cc.kn()):(this.wc.ac(),this.zn(),this.Oc())}Oc(){this.Ic&&this.Ic()}Bc(t){this.Ic=t}error(t){this.wc.uc(t)}Lc(){if(this.wc.rc){if(this.Sc++,this.wc.sc==="transitioning"&&this.Cc.et())return this.wc.lc(),this.Oc(),void this.zn();this.Hc()}}Hc(){if(!this.zc)return;const t=this.Pc,e=this.Mc,r=this.Fc,n=this.$c,h=this.Ca.Z,a=this.Ca.Er,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.Ec,frameCount:this.Sc,message:this.l.message,palette:this.Tc,theme:this.Rc,phases:this.bc.qa(),transitionOpacity:this.Cc._c,isError:this.wc.sc==="error",errorMessage:this.wc.nc||void 0,errorDetails:this.wc.hc||void 0};this.Z(f)}finally{this.Ca.pop()}t.end(),n.begin(),h.ve(c),c.O({u_characterTexture:e.fontFramebuffer,u_charsetDimensions:[e.textureColumns,e.textureRows],Uh:t.textures[0],Ui:t.textures[1],Uj:t.textures[2],Uk:[r.cols,r.rows],Ul:[n.width,n.height],Um:h.state.canvasBackgroundColor}),h.Ae(0,0,a.width,a.height),n.end(),h.bi(...h.state.canvasBackgroundColor),h.ve(u),u.O({U0:n.textures[0],U1:[n.width,n.height],U2:[r.offsetX,r.offsetY],U3:[r.width,r.height]}),h.Ae(r.offsetX,r.offsetY,r.width,r.height)}Nc(t){this.Rc=wt(this.l,t)}Dc(){const t=this.l.renderer||ke;return e=>{t(e),this.jc(e)}}jc(t){const{textmodifier:e,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]];e.push(),e.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,y]=d[p],E=Math.floor(255*a),b=e.color(m,A,y,E);e.charColor(b),e.char(v),e.point(),e.translateX(1)}e.pop()}}class bt{constructor(t={}){l(this,"Xc");l(this,"_c");l(this,"Yc");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,"il",!0);l(this,"el",[]);this.Xc=t.visible??!0,this._c=Math.min(1,Math.max(0,t.opacity??1)),this.Yc=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.el;return this.el=[],t}hl(t){this.tl&&this.tl.call(t)}draw(t){this.tl=t}show(){this.Xc=!0}hide(){this.Xc=!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.Yc;this.Yc=t}offset(t,e=0){if(t===void 0)return{x:this.Kc,y:this.Wc};this.Kc=Math.round(t),this.Wc=Math.round(e)}filter(t,e){this.el.push({name:t,params:e})}ol(t){this.Zc=t,this.al(t.grid)}ba(t,e){if(!this.Xc||!this.tl)return void(this.sl=!1);const r=this.Zc.renderer;this.el=[],this.qc.begin(),r.state.qt(),this.tl.call(t),this.qc.end();const n=this.el.length>0,h=n?this.Jc:this.Vc;h.begin(),r.ve(e),e.O({u_characterTexture:this.Zc.font.fontFramebuffer,u_charsetDimensions:[this.Zc.font.textureColumns,this.Zc.font.textureRows],Uh:this.qc.textures[0],Ui:this.qc.textures[1],Uj:this.qc.textures[2],Uk:[this.Zc.grid.cols,this.Zc.grid.rows],Ul:[h.width,h.height],Um:[0,0,0,0]}),r.Ae(0,0,this.Zc.grid.width,this.Zc.grid.height),h.end(),n&&this.Zc.filterManager.cl(this.Jc.textures[0],this.Vc,this.el,this.Vc.width,this.Vc.height,this.Zc.layerPingPongBuffers),this.sl=!0}jr(t){var e;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),(e=this.Jc)==null||e.resize(t.width,t.height))}gt(){var t,e,r;this.il&&((t=this.qc)==null||t.gt(),(e=this.Vc)==null||e.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.il=!this.Zc.externalDrawFramebuffer&&!this.Zc.externalAsciiFramebuffer,this.sl=!1)}}const Qt={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 Kt{constructor(t){l(this,"Z");l(this,"ul");l(this,"fl",null);l(this,"dl",0);this.Z=t,this.ul=t.pe($,`#version 300 es
12
- precision highp float;uniform sampler2D Un;uniform sampler2D Uo;uniform vec2 Up;uniform float Uq;uniform vec2 Ur;uniform int Us;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(Uo,v_uv);vec2 h=v_uv*Up-Ur;bool i=any(lessThan(h,vec2(0.)))||any(greaterThanEqual(h,Up));if(i){fragColor=g;return;}vec2 j=(floor(h)+0.5)/Up;vec4 k=texture(Un,j);float l=k.a*Uq;if(l<=0.){fragColor=g;return;}vec3 m=e(Us,g.rgb,k.rgb);vec3 n=mix(g.rgb,m,l);float o=g.a+l*(1.-g.a);fragColor=vec4(n,o);}`)}yr(t){this.fl||(this.fl=[this.Z.Pe(t.width,t.height,1),this.Z.Pe(t.width,t.height,1)])}vl(t,e){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=e.width,v=e.height,p=this.fl[0];p.begin(),this.Z.bi(...a),p.end(),this.dl=0,c.Xc&&this.pl(n,g,v,c._c,c.Kc,c.Wc,"normal",r);for(const m of u)m.Xc&&m.ll&&this.pl(m.texture,m.width,m.height,m._c,m.Kc,m.Wc,m.Yc,r);this.ml(h,g,v,r),r.depthMask(d),f&&r.enable(r.DEPTH_TEST)}pl(t,e,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.ve(this.ul),this.ul.O({Un:t,Uo:f.textures[0],Up:[e,r],Uq:n,Ur:[h,a],Us:Qt[c]}),this.Z.Ae(0,0,f.width,f.height),g.end(),this.dl=d}ml(t,e,r,n){const h=this.fl[this.dl];t.begin(),n.disable(n.BLEND),this.Z.ve(this.ul),this.ul.O({Un:h.textures[0],Uo:h.textures[0],Up:[h.width,h.height],Uq:1,Ur:[0,0],Us:Qt.normal}),this.Z.Ae(0,0,e,r),t.end()}jr(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 qt{constructor(t){l(this,"Ca");l(this,"Z");l(this,"_l");l(this,"yl");l(this,"Al",[]);l(this,"bl",[]);l(this,"wl");l(this,"Cl");l(this,"xl");l(this,"Ml");l(this,"Fl",!1);this.Ca=t,this.Z=t.Z,this._l=t.Gc,this.yl=new Kt(this.Z),this.wl=new bt({visible:!0,opacity:1})}add(t={}){const e=new bt(t);return this.Fl?(this.Pl(e),this.bl.push(e)):this.Al.push(e),e}remove(t){this.$l(this.bl,t)||this.$l(this.Al,t)}move(t,e){this.Tl(this.bl,t,e)||this.Tl(this.Al,t,e)}swap(t,e){t!==e&&(this.Rl(this.bl,t,e)||this.Rl(this.Al,t,e))}yr(){if(this.Fl)return;const t=this.Ca.Nn;this.Cl=this.Z.Pe(t.width,t.height,1),this.xl=this.Z.Pe(t.width,t.height,1),this.Ml=[this.Z.Pe(t.width,t.height,1,{depth:!1}),this.Z.Pe(t.width,t.height,1,{depth:!1})],this.El(),this.yl.yr(t);for(const e of this.Al)this.Pl(e),this.bl.push(e);this.Al.length=0,this.Fl=!0}Sl(t,e){const r=this.Ca.Nn,n=this.Ca.font,h=this.Ca.ga,a=this.wl.nl(),c=a.length>0,u=c?this.xl:this.Cl;u.begin(),this.Z.ve(this._l),this._l.O({u_characterTexture:n.fontFramebuffer,u_charsetDimensions:[n.textureColumns,n.textureRows],Uh:h.textures[0],Ui:h.textures[1],Uj:h.textures[2],Uk:[r.cols,r.rows],Ul:[u.width,u.height],Um:this.Z.state.canvasBackgroundColor}),this.Z.Ae(0,0,r.width,r.height),u.end(),c&&this.Ca.kl.cl(this.xl.textures[0],this.Cl,a,this.Cl.width,this.Cl.height,this.Ml),this.zl(),this.Dl(t,e)}zl(){if(this.bl.length!==0)for(const t of this.bl)t.ba(this.Ca,this._l)}Dl(t,e){this.yl.vl({baseTexture:this.Cl.textures[0],targetFramebuffer:t,backgroundColor:e,baseLayer:this.wl,layers:this.bl},this.Ca.Nn)}jr(){if(!this.Fl)return;const t=this.Ca.Nn;this.Cl.resize(t.width,t.height),this.xl.resize(t.width,t.height),this.wl.jr(t),this.Ml&&(this.Ml[0].resize(t.width,t.height),this.Ml[1].resize(t.width,t.height));for(const e of this.bl)e.jr(t);this.yl.jr(t)}gt(){var t,e,r,n;for(const h of this.bl)h.gt();for(const h of this.Al)h.gt();this.bl.length=0,this.Al.length=0,this.wl.gt(),(t=this.Cl)==null||t.gt(),(e=this.xl)==null||e.gt(),(r=this.Ml)==null||r[0].gt(),(n=this.Ml)==null||n[1].gt(),this.yl.gt()}get all(){return this.bl}get base(){return this.wl}Pl(t){const e={renderer:this.Z,grid:this.Ca.Nn,font:this.Ca.font,filterManager:this.Ca.kl,layerPingPongBuffers:this.Ml,createFramebuffer:(r,n,h=1)=>this.Z.Pe(r,n,h)};t.ol(e)}El(){const t={renderer:this.Z,grid:this.Ca.Nn,font:this.Ca.font,filterManager:this.Ca.kl,layerPingPongBuffers:this.Ml,createFramebuffer:(e,r,n=1)=>this.Z.Pe(e,r,n),externalDrawFramebuffer:this.Ca.ga,externalAsciiFramebuffer:this.Cl};this.wl.ol(t)}$l(t,e){const r=t.indexOf(e);if(r===-1)return!1;const[n]=t.splice(r,1);return n.gt(),!0}Tl(t,e,r){const n=t.indexOf(e);if(n===-1)return!1;t.splice(n,1);const h=Math.max(0,Math.min(t.length,r));return t.splice(h,0,e),!0}Rl(t,e,r){const n=t.indexOf(e);if(n===-1)return!1;const h=t.indexOf(r);return h!==-1&&(t[n]=r,t[h]=e,!0)}}class Jt{constructor(t){l(this,"Z");l(this,"Ll",new Map);l(this,"Ol",new Map);this.Z=t,this.Il()}async Bl(t,e,r={}){const n=Object.entries(r),h=n.length>0?n[0][1][0]:null;let a;if(typeof e=="string"){let u=e;if(e.startsWith("./")||e.startsWith("../")||e.endsWith(".frag")||e.endsWith(".glsl")){const f=await fetch(e);if(!f.ok)throw Error(`Failed to load shader from ${e}: ${f.statusText}`);u=await f.text()}a=this.Z.pe($,u),this.Ol.set(t,a)}else a=e,this.Ol.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.Ll.set(t,c)}Hl(t){const e=this.Ol.get(t);return e&&(e.dispose(),this.Ol.delete(t)),this.Ll.delete(t)}Gl(t){return this.Ll.get(t)}gt(){for(const t of this.Ol.values())t.dispose();this.Ol.clear(),this.Ll.clear()}Il(){this.Bl("invert",`#version 300 es
7
+ `}static h(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(e=>C.h(e)).join(", ")}]`:`[${t.slice(0,3).map(e=>C.h(e)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const e=Object.keys(t);return e.length===0?"{}":e.length<=3?`{ ${e.map(r=>`${r}: ${C.h(t[r])}`).join(", ")} }`:`{ ${e.slice(0,2).map(r=>`${r}: ${C.h(t[r])}`).join(", ")}, ... +${e.length-2} more }`}return t+""}}var X=(o=>(o[o.SILENT=0]="SILENT",o[o.WARNING=1]="WARNING",o[o.ERROR=2]="ERROR",o[o.THROW=3]="THROW",o))(X||{});const I=class I{constructor(){l(this,"l",{globalLevel:3})}static u(){return I.o||(I.o=new I),I.o}v(t,e){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(C.i(t,e)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(C.i(t,e)),console.groupEnd(),!1;default:throw new C(t,e)}}m(t,e,r){return!!t||(this.v(e,r),!1)}_(t){this.l.globalLevel=t}};l(I,"o",null);let lt=I;const ut=lt.u();class H{constructor(t,e,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(e,r),this.S()}S(){const t=this.A.getProgramParameter(this.C,this.A.ACTIVE_UNIFORMS);for(let e=0;e<t;e++){const r=this.A.getActiveUniform(this.C,e);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,e){const r=this.k(this.A.VERTEX_SHADER,t),n=this.k(this.A.FRAGMENT_SHADER,e),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,e){const r=this.A.createShader(t);if(this.A.shaderSource(r,e),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()}O(t){for(const e in t)this.I(e,t[e])}I(t,e){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(e instanceof WebGLTexture){const d=this.H(t);return c.uniform1i(r,d),c.activeTexture(c.TEXTURE0+d),void c.bindTexture(c.TEXTURE_2D,e)}if(e instanceof z){const d=this.H(t);return c.uniform1i(r,d),c.activeTexture(c.TEXTURE0+d),void c.bindTexture(c.TEXTURE_2D,e.textures[0])}if(typeof e!="number")if(typeof e!="boolean")if(Array.isArray(e[0])){const d=e.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=e,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,e?1:0);else h===c.INT||h===c.BOOL?c.uniform1i(r,e):c.uniform1f(r,e)}H(t){const e=this.$.get(t);if(e!==void 0)return e;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 Tt(o,t,e,r){return 180*Math.atan2(r-t,e-o)/Math.PI}function j(o,t,e,r){return Math.hypot(e-o,r-t)}function Y(o,t,e){return Math.min(Math.max(o,t),e)}function Ct(o){return(o%360+360)%360/360}function Ft(o,t,e){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,e),o.bindTexture(o.TEXTURE_2D,null)}function tt(o,t,e,r,n){o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,t),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,e),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,r),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,n)}function ft(o,t,e,r,n,h=0,a=WebGL2RenderingContext.FLOAT,c=!1){o.enableVertexAttribArray(t),o.vertexAttribPointer(t,e,a,c,r,n),o.vertexAttribDivisor(t,h)}function Rt(o,t,e,r,n){o.bindBuffer(t,e),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 U9;uniform float Ua;uniform float Ub;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/U9)*2.0f;AA.y=-AA.y;float AB=y.z/U9.y;float AC=clamp(-AB*Ua,-0.99f,0.99f);if(Ub>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);}}`,W=class W{constructor(t,e,r=e,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=e,this.X=r,this.A=t,this.W=Y(n,1,8),this.Z=a,this.l={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",depth:!0,...h},W.J||(W.J=new H(t,et,`#version 300 es
9
+ precision highp float;in vec2 v_uv;uniform sampler2D Uc;uniform sampler2D Ud;uniform sampler2D Ue;uniform sampler2D Uf;uniform vec2 Ug;uniform bool Uh;uniform bool Ui;uniform bool Uj;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 A;void main(){vec2 B=vec2(v_uv.x,1.-v_uv.y);vec2 C=B*Ug;vec2 D=(floor(C)+0.5f)/Ug;vec4 E=texture(Uc,D);vec4 F=Uh?texture(Ud,D):vec4(0.);if(Uh&&F.a==0.){discard;}vec4 G=Ui?texture(Ue,D):vec4(0.);vec4 H=Uj?texture(Uf,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.it()}tt(){const t=this.A,e=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,e,e,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 e=[];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),e.push(n)}t.drawBuffers(e)}t.bindFramebuffer(t.FRAMEBUFFER,null)}it(){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)}et(t){Ft(this.A,this.j[0],t)}resize(t,e){this.N=t,this.X=e,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 e=this.V.get(t);if(e)return e;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.ht()}end(){this.Z.state.ot(),this.Z.ct(),this.Z.lt()}ut(){return this.q||this.ft(),this.q}ft(){if(!this.Z)return;const t=this.W>1,e=this.W>2,r=this.W>3,n={Uc:this.j[0],Ud:t?this.j[1]:this.j[0],Ue:e?this.j[2]:this.j[0],Uf:r?this.j[3]:this.j[0],Ug:[this.N,this.X],Uh:t,Ui:e,Uj:r},h=W.J;this.q=this.Z.vt.dt(h,n,!0)}gt(){const t=this.A;t.deleteFramebuffer(this.Y);for(const e of this.j)t.deleteTexture(e);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(W,"J",null);let z=W;const Pt=new WeakMap;function dt(o,t){Pt.set(o,t)}function Mt(o){return Pt.get(o)}function it(o,t,e,r,n=255){o[0]=t/255,o[1]=(e??t)/255,o[2]=(r??t)/255,o[3]=n/255}class st{constructor(){l(this,"_t",1);l(this,"yt",0);l(this,"At",0);l(this,"bt",0);l(this,"wt",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,"Rt",!1);l(this,"Et",0);l(this,"St",[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,wt:0,Ct:0,xt:0,Et:0,Gt:!1,Qt:!1,Rt:!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.bt,t.wt=this.wt,t.Ct=this.Ct,t.xt=this.xt,t.Gt=this.$t,t.Qt=this.Tt,t.Rt=this.Rt,t.Et=this.Et,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.bt=t.Ht,this.wt=t.wt,this.Ct=t.Ct,this.xt=t.xt,this.$t=t.Gt,this.Tt=t.Qt,this.Rt=t.Rt,this.Et=t.Et,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]}ht(){let t=this.Dt.pop();t||(t=st.Lt()),this.jt(t),this.zt.push(t)}ot(){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.bt=0,this.wt=0,this.Ct=0,this.xt=0,this.kt=!1}Vt(t){t!==0&&(this.wt+=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,e=0,r=0){t===0&&e===0&&r===0||(this.yt+=t,this.At+=e,this.bt+=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,e,r,n=255){it(this.Ft,t,e,r,n)}ls(t,e,r,n=255){it(this.Pt,t,e,r,n)}us(t){this.$t=t}fs(t){this.Tt=t}ds(t){this.Rt=t}vs(t){this.Et=Ct(t)}ps(t,e,r,n){it(this.St,t,e,r,n)}gs(t){this.kt=t}get canvasBackgroundColor(){return this.St}get useOrtho(){return this.kt}get rotationX(){return this.wt}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,bs:{ws:{size:2,offset:0},Cs:{size:2,offset:8}}};class ee{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,e,r,n){const h=this.A,a=Mt(this.A),c=a[2],u=a[3],f=t/c*2-1,d=(t+r)/c*2-1,g=1-(e+n)/u*2,v=1-e/u*2,p=gt,m=this.Fs;for(let A=0;A<p.length;A+=4){const y=p[A],E=p[A+1],b=p[A+2],w=p[A+3],P=f+(y+.5)*(d-f),x=g+(E+.5)*(v-g);m[A]=P,m[A+1]=x,m[A+2]=b,m[A+3]=w}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 F=(o=>(o.RECTANGLE="rectangle",o.LINE="line",o.ELLIPSE="ellipse",o.ARC="arc",o.TRIANGLE="triangle",o.BEZIER_CURVE="bezier_curve",o))(F||{});const ie={rectangle:2,line:2,ellipse:2,triangle:2,arc:3,bezier_curve:4};class se{constructor(t){l(this,"A");l(this,"$s",new Map);this.A=t}Ts(t,e,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(e)||null;if(!c){c=h.createVertexArray(),a.set(e,c),h.bindVertexArray(c),h.bindBuffer(h.ARRAY_BUFFER,n);const u=h.getAttribLocation(t,"A0");u!==-1&&ft(h,u,r.bs.ws.size,r._s,r.bs.ws.offset,0,h.FLOAT,!1);const f=h.getAttribLocation(t,"A1");f!==-1&&ft(h,f,r.bs.Cs.size,r._s,r.bs.Cs.offset,0,h.FLOAT,!1)}h.bindVertexArray(c)}Rs(){this.A.bindVertexArray(null)}gt(){for(const[,t]of this.$s)for(const[,e]of t)e&&this.A.deleteVertexArray(e)}}const O=class O{static Es(t,e,r=0){const n=e||new Float32Array(O.FLOATS_PER_INSTANCE);let h=r;n[h++]=t.ws[0],n[h++]=t.ws[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.Et;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,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,e){const r=t.length*O.FLOATS_PER_INSTANCE,n=e||new Float32Array(r);for(let h=0;h<t.length;h++){const a=h*O.FLOATS_PER_INSTANCE;O.Es(t[h],n,a)}return n}};l(O,"BYTES_PER_INSTANCE",144),l(O,"FLOATS_PER_INSTANCE",36);let Z=O;const S=class S{};l(S,"STRIDE",Z.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,e=1.5){l(this,"Ys");l(this,"js");l(this,"Ks");l(this,"Ws",0);l(this,"Zs",0);this.js=t,this.Ks=e;const r=t*Z.FLOATS_PER_INSTANCE;this.Ys=new Float32Array(r)}qs(t){if(t<=this.js)return;const e=Math.ceil(t*this.Ks),r=this.js;this.js=e;const n=e*Z.FLOATS_PER_INSTANCE,h=new Float32Array(n),a=r*Z.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++}ti(){this.Ws=0,this.Zs=0}si(t=0,e){return this.Ys.subarray(t,e??this.Ws)}get ii(){return this.Zs}get ei(){return this.js}get ri(){return this.Ws}get ni(){return this.Zs===0}}class ne{constructor(t){l(this,"Ys");this.Ys=t}hi(t){this.Ys.qs(this.Ys.ii+1);const{buffer:e,offset:r}=this.Ys.Vs();e[r+0]=t.x,e[r+1]=t.y,e[r+2]=t.width,e[r+3]=t.height,e[r+4]=t.char0,e[r+5]=t.char1,e[r+6]=t.char2,e[r+7]=t.r1,e[r+8]=t.g1,e[r+9]=t.b1,e[r+10]=t.a1,e[r+11]=t.r2,e[r+12]=t.g2,e[r+13]=t.b2,e[r+14]=t.a2,e[r+15]=t.invert,e[r+16]=t.flipX,e[r+17]=t.flipY,e[r+18]=t.charRot,e[r+19]=t.translationX,e[r+20]=t.translationY,e[r+21]=t.translationZ,e[r+22]=t.rotationX,e[r+23]=t.rotationY,e[r+24]=t.rotationZ;const n=t.curveParams0,h=t.curveParams1;return e[r+25]=n[0],e[r+26]=n[1],e[r+27]=n[2],e[r+28]=n[3],e[r+29]=h[0],e[r+30]=h[1],e[r+31]=h[2],e[r+32]=h[3],e[r+33]=t.depth,e[r+34]=t.baseZ,e[r+35]=t.geometryType,this.Ys.Js(Z.FLOATS_PER_INSTANCE),this.Ys.ii-1}get ii(){return this.Ys.ii}}class he{constructor(t,e=1e3){l(this,"A");l(this,"oi",null);l(this,"ai",0);l(this,"ci",new Map);this.A=t,this.li(e)}li(t){const e=this.A;this.oi&&e.deleteBuffer(this.oi),this.oi=e.createBuffer();const r=t*Z.BYTES_PER_INSTANCE;Rt(e,e.ARRAY_BUFFER,this.oi,r,e.DYNAMIC_DRAW),this.ai=t}ui(t){this.li(t)}get ei(){return this.ai}fi(t,e){if(e===0)return;const r=this.A;r.bindBuffer(r.ARRAY_BUFFER,this.oi);const n=e*Z.FLOATS_PER_INSTANCE;r.bufferSubData(r.ARRAY_BUFFER,0,t,0,n)}di(t){let e=this.ci.get(t);if(!e){e=new Map;const r=this.A;for(const n in Q.ATTRIBUTES){const h=r.getAttribLocation(t,n);h!==-1&&e.set(n,h)}this.ci.set(t,e)}return e}pi(t){const e=this.A,r=t.G,n=this.di(r);for(const[h,a]of n){const c=Q.ATTRIBUTES[h];c&&ft(e,a,c.size,c.stride,c.offset,c.divisor,c.type,c.normalized)}}gi(t){const e=this.A,r=this.di(t.G);for(const[n,h]of r)Q.ATTRIBUTES[n]&&(e.disableVertexAttribArray(h),e.vertexAttribDivisor(h,0))}gt(){this.oi&&(this.A.deleteBuffer(this.oi),this.oi=null),this.ci.clear()}}class oe{constructor(t,e=1e3,r=1.5){l(this,"A");l(this,"Ys");l(this,"mi");l(this,"_i");this.A=t,this.Ys=new re(e,r),this.mi=new ne(this.Ys),this._i=new he(t,e)}yi(t){var n,h,a,c,u,f,d,g,v,p;const e=[0,0,0,0],r=[0,0,0,0];return t.Os&&t.Is?(e[0]=((n=t.Bs)==null?void 0:n[0])??0,e[1]=((h=t.Bs)==null?void 0:h[1])??0,e[2]=((a=t.Hs)==null?void 0:a[0])??0,e[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&&(e[0]=t.Ls[0],e[1]=t.Ls[1]),this.hi({x:t.ws[0],y:t.ws[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.Et,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:e,curveParams1:r,depth:t.Gs||0,baseZ:t.Qs||0,geometryType:t.Ns||0})}hi(t){const e=this.mi.hi(t);return this.Ys.ei>this._i.ei&&this._i.ui(this.Ys.ei),e}get Ai(){return this.Ys.ii}get ni(){return this.Ys.ni}bi(){this.Ys.ti()}pi(t){const e=this.Ys.ii;if(e===0)return;const r=this.Ys.si();this._i.fi(r,e),this._i.pi(t)}gi(t){this._i.gi(t)}Ps(t,e){const r=this.Ys.ii;r!==0&&this.A.drawArraysInstanced(t,0,e,r)}gt(){this._i.gt()}}class G{constructor(t,e,r,n){l(this,"A");l(this,"wi");l(this,"Ci");l(this,"xi");l(this,"Mi",null);this.A=t,this.wi=e,this.Ci=r,this.xi=n;const h=this.A.createBuffer();Rt(this.A,this.A.ARRAY_BUFFER,h,this.xi.Fi,this.A.STATIC_DRAW),this.Mi=h}get type(){return this.Ci}get unitGeometry(){return this.xi}get unitBuffer(){return this.Mi}get batch(){return this.wi}Pi(){this.wi.bi()}$i(){return!this.wi.ni}gt(){this.wi.gt(),this.A.deleteBuffer(this.Mi)}Ti(t,e,r){return this.wi.yi(t)}Ri(t,e,r,n,h,a){const c=h.It??0,u=h.Bt??0,f=h.Ht??0,d=h.wt??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:e,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.Rt?1:0,flipX:h.Gt?1:0,flipY:h.Qt?1:0,charRot:h.Et,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:ie[this.Ci]??0};return this.wi.hi(A)}}const ae={Fi:gt,Ei:6,...V},ce={Fi: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]),Ei:6,...V},le={Fi:function(o=32){const t=[],e=2*Math.PI/o;for(let r=0;r<o;r++){const n=r*e,h=(r+1)%o*e,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),Ei:96,...V};let ue={Fi:function(o){const t=[];for(let e=0;e<o;e++){const r=e/o,n=(e+1)/o;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),Ei:96,...V};const fe={Fi:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),Ei:3,...V},de={Fi:function(o=16){const t=[];for(let e=0;e<o;e++){const r=e/o,n=(e+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),Ei:96,...V},ge={[F.RECTANGLE]:class extends G{constructor(o,t){super(o,t,F.RECTANGLE,ae)}yi(o,t){return this.Ri(0,0,o.width,o.height,t)}},[F.LINE]:class extends G{constructor(o,t){super(o,t,F.LINE,ce)}yi(o,t){const e=o.x2-o.x1,r=o.y2-o.y1,n=Math.hypot(e,r),h=Math.atan2(r,e),a=t.Ot||1,c=o.x1+e/2-n/2,u=o.y1+r/2,f={...t,xt:(t.xt||0)+h};return this.Ri(c,u,n,a,f)}},[F.ELLIPSE]:class extends G{constructor(o,t){super(o,t,F.ELLIPSE,le)}yi(o,t){return this.Ri(0,0,o.width,o.height,t)}},[F.ARC]:class extends G{constructor(o,t){super(o,t,F.ARC,ue)}yi(o,t){const e=o.start*Math.PI/180,r=o.stop*Math.PI/180;return this.Ri(0,0,o.width,o.height,t,{arcStart:e,arcStop:r})}},[F.TRIANGLE]:class extends G{constructor(o,t){super(o,t,F.TRIANGLE,fe)}yi(o,t){const e=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-e,a=Math.max(o.y1,o.y2,o.y3)-n;return this.Ri(e,n,h,a,t)}},[F.BEZIER_CURVE]:class extends G{constructor(o,t){super(o,t,F.BEZIER_CURVE,de)}yi(o,t){return this.Ri(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 me{constructor(t){l(this,"A");l(this,"Si");l(this,"ki");this.A=t,this.ki=new se(t),this.Si=new Map;for(const e of Object.values(F)){const r=new oe(t),n=new ge[e](t,r);this.Si.set(e,n)}}zi(t){const e=this.Di(t);for(const r of e)this.Li(r)}Di(t){const e=[];let r=null,n=null,h=null;for(const a of t)n!==a.material||h!==a.type?(r&&r.length>0&&e.push({material:n,type:h,commands:r}),r=[a],n=a.material,h=a.type):r.push(a);return r&&r.length>0&&e.push({material:n,type:h,commands:r}),e}Li(t){const{material:e,type:r,commands:n}=t,h=this.Si.get(r);e.shader.D(),e.shader.O(e.uniforms);const a=Mt(this.A),c=n.length>0&&n[0].state.kt;e.shader.O({Uw:a[2]/a[3],U9:[a[2],a[3]],Ua:1,Ub:c?1:0}),h.Pi();for(const u of n)h.yi(u.params,u.state);if(h.$i()){const u=h.unitGeometry,f=h.unitBuffer;try{this.ki.Ts(e.shader.G,r+"",u,f),h.batch.pi(e.shader),h.batch.Ps(u.As,u.Ei)}finally{h.batch.gi(e.shader),this.ki.Rs(),h.Pi()}}}gt(){for(const t of this.Si.values())t.gt();this.Si.clear(),this.ki.gt()}}function Nt(o){let t=0;for(let e=0;e<o.length;e++)t=(t<<5)-t+o.charCodeAt(e),t&=t;return t}const Ut=new WeakMap;let ve=1;function St(o){if(o==null)return 0;if(typeof o!="object"&&typeof o!="function")return Nt(o+"");let t=Ut.get(o);return t||(t=ve++,Ut.set(o,t)),t}function K(o,t){return(o<<5)-o+t}class pe{constructor(t){l(this,"Oi",0);l(this,"Ii");l(this,"Bi");l(this,"Hi",new Map);this.Ii=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.Bi={id:this.Oi++,shader:this.Ii,uniforms:Object.freeze({}),hash:this.Gi(this.Ii,{}),isBuiltIn:!0}}get Qi(){return this.Bi}dt(t,e={},r=!1){const n=this.Gi(t,e),h=this.Hi.get(n);if(h)return h;const a={id:this.Oi++,shader:t,uniforms:Object.freeze({...e}),hash:n,isBuiltIn:r};return this.Hi.set(n,a),a}Ni(t,e={}){return{id:this.Oi++,shader:t,uniforms:Object.freeze({...e}),hash:0,isBuiltIn:!1}}Gi(t,e){const r=St(t.G),n=function(h,a){let c=0;const u=Object.keys(h).sort();for(const f of u)c=K(c,Nt(f)),c=K(c,a(h[f]));return c}(e,this.Xi.bind(this));return K(r,n)}Xi(t){return typeof t=="number"||typeof t=="boolean"?function(e){return typeof e=="boolean"?e?1:0:Math.floor(e)}(t):Array.isArray(t)?function(e){let r=0;const n=Array.isArray(e[0])?e.flat():e;for(const h of n)r=K(r,typeof h=="number"?h:0);return r}(t):t instanceof Float32Array||t instanceof Int32Array?function(e){let r=0;const n=Math.min(e.length,16);for(let h=0;h<n;h++)r=K(r,e[h]);return r}(t):t instanceof WebGLTexture?St(t):0}gt(){this.Ii!=this.Ii&&this.Ii.dispose(),this.Ii.dispose(),this.Hi.clear()}}class Ae{constructor(){l(this,"Yi",[]);l(this,"ji",1);l(this,"Ss",0)}Ki(t,e){if(this.Ss>=this.Yi.length){const n={id:this.ji++,type:t,params:{},state:st.Lt(),material:e};this.Yi.push(n)}const r=this.Yi[this.Ss];return r.id=this.ji++,r.type=t,r.material=e,this.Ss++,r}Wi(t,e,r){const n=this.Ki(F.RECTANGLE,r),h=n.params;return h.width=t.width,h.height=t.height,e.Wt(n.state),n.id}Zi(t,e,r){const n=this.Ki(F.LINE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.x2=t.x2,h.y2=t.y2,h.thickness=t.thickness,e.Wt(n.state),n.id}qi(t,e,r){const n=this.Ki(F.ELLIPSE,r),h=n.params;return h.width=t.width,h.height=t.height,h.startAngle=t.startAngle,h.endAngle=t.endAngle,h.segments=t.segments,e.Wt(n.state),n.id}Vi(t,e,r){const n=this.Ki(F.ARC,r),h=n.params;return h.width=t.width,h.height=t.height,h.start=t.start,h.stop=t.stop,e.Wt(n.state),n.id}Ji(t,e,r){const n=this.Ki(F.TRIANGLE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.x2=t.x2,h.y2=t.y2,h.x3=t.x3,h.y3=t.y3,e.Wt(n.state),n.id}te(t,e,r){const n=this.Ki(F.BEZIER_CURVE,r),h=n.params;return h.x1=t.x1,h.y1=t.y1,h.cp1x=t.cp1x,h.cp1y=t.cp1y,h.cp2x=t.cp2x,h.cp2y=t.cp2y,h.x2=t.x2,h.y2=t.y2,h.thickness=t.thickness,h.segments=t.segments,e.Wt(n.state),n.id}bi(){this.Ss=0}[Symbol.iterator](){let t=0;const e=this.Ss,r=this.Yi;return{next:()=>t<e?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}class Ee{constructor(t){l(this,"A");l(this,"se",null);l(this,"ie");l(this,"vt");l(this,"ee");l(this,"re");l(this,"ne");l(this,"he",null);l(this,"oe",{});l(this,"ae",[]);l(this,"ce",[]);l(this,"le",[]);l(this,"ue",null);l(this,"fe",[0,0,0,0]);l(this,"de",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.ee=new st,this.vt=new pe(t),this.re=new Ae,this.ie=new me(t),this.ne=new ee(t);const e=[0,0,t.canvas.width,t.canvas.height];dt(t,e),this.ae.push(null),this.ce.push(e),this.le.push(1),this.ue=null,this.fe=e,this.de=1}rt(){this.ae.push(this.ue),this.ce.push([...this.fe]),this.le.push(this.de)}lt(){const t=this.ae.pop()??null,e=this.ce.pop()??[0,0,this.A.canvas.width,this.A.canvas.height],r=this.le.pop()??1;this.nt(t,e[2],e[3],r)}nt(t,e,r,n=1){const h=this.A;this.ue!==t&&(h.bindFramebuffer(h.FRAMEBUFFER,t),this.ue=t),this.de=n;const a=[0,0,e,r];this.fe[0]===a[0]&&this.fe[1]===a[1]&&this.fe[2]===a[2]&&this.fe[3]===a[3]||(h.viewport(...a),dt(h,a),this.fe=a)}ve(t){this.se!==t&&(this.se=t,t.D())}pe(t,e){return new H(this.A,t,e)}ge(t){this.he=t,t&&(this.oe={})}I(t,e){this.oe[t]=e}me(t){Object.assign(this.oe,t)}_e(t){return new H(this.A,et,t)}ye(t,e,r){this.re.Wi({width:e??t.width,height:r??t.height},this.ee,t.ut())}Ae(t,e,r,n){this.ne.Ps(t,e,r,n)}be(t,e){if(this.he){const r=this.vt.Ni(this.he,this.oe);this.re.Wi({width:t,height:e},this.ee,r),this.he=null,this.oe={}}else this.re.Wi({width:t,height:e},this.ee,this.vt.Qi)}we(t,e,r,n){this.re.Zi({x1:t,y1:e,x2:r,y2:n},this.ee,this.vt.Qi)}Ce(t,e){this.re.qi({width:t,height:e},this.ee,this.vt.Qi)}xe(t,e,r,n,h,a){this.re.Ji({x1:t,y1:e,x2:r,y2:n,x3:h,y3:a},this.ee,this.vt.Qi)}Me(t,e,r,n,h,a,c,u){this.re.te({x1:t,y1:e,cp1x:r,cp1y:n,cp2x:h,cp2y:a,x2:c,y2:u},this.ee,this.vt.Qi)}Fe(t,e,r,n){this.re.Vi({width:t,height:e,start:r,stop:n},this.ee,this.vt.Qi)}Pe(t,e,r=1,n={}){return new z(this.A,t,e,r,n,this)}$e(t,e=t,r=t,n=255){this.ee.ps(t,e??t,r??t,n);const[h,a,c,u]=this.ee.canvasBackgroundColor;this.Te(h,a,c,u,!1)}bi(t=0,e=0,r=0,n=0){this.Te(t,e,r,n,!0)}Te(t,e,r,n,h){const a=this.A;if(this.de>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.de>=3&&a.clearBufferfv(a.COLOR,2,new Float32Array([t,e,r,n]));for(let u=3;u<this.de;u++)a.clearBufferfv(a.COLOR,u,new Float32Array([0,0,0,0]))}else a.clearColor(t,e,r,n),a.clear(a.COLOR_BUFFER_BIT)}Re(){const t=[0,0,this.A.canvas.width,this.A.canvas.height];this.A.viewport(...t),dt(this.A,t),this.fe=t,this.ce.length>0&&(this.ce[0]=t)}ct(){const t=this.re;this.ie.zi(t),t.bi(),this.se=null}gt(){this.vt.gt(),this.ie.gt(),this.ne.gt()}get context(){return this.A}get state(){return this.ee}get materialManager(){return this.vt}}const R={readShort:(o,t)=>(R.t.uint16[0]=o[t]<<8|o[t+1],R.t.int16[0]),readUshort:(o,t)=>o[t]<<8|o[t+1],readUshorts(o,t,e){const r=[];for(let n=0;n<e;n++)r.push(R.readUshort(o,t+2*n));return r},readUint(o,t){const e=R.t.uint8;return e[3]=o[t],e[2]=o[t+1],e[1]=o[t+2],e[0]=o[t+3],R.t.uint32[0]},readASCII(o,t,e){let r="";for(let n=0;n<e;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 rt(o){return o+3&-4}function nt(o,t,e){o[t]=e>>>8&255,o[t+1]=255&e}function _(o,t,e){o[t]=e>>>24&255,o[t+1]=e>>>16&255,o[t+2]=e>>>8&255,o[t+3]=255&e}function ye(o,t,e){for(let r=0;r<e.length;r++)o[t+r]=255&e.charCodeAt(r)}function mt(o,t,e){const r=t+e;let n=0;const h=R.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 e=this.bitbuf&(1<<t)-1;return this.bitbuf>>>=t,this.bitcnt-=t,e}alignToByte(){this.bitbuf=0,this.bitcnt=0}get offset(){return this.p}}function q(o){let t=32,e=0;for(const c of o)c&&(c<t&&(t=c),c>e&&(e=c));if(e===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(e+1);for(const c of o)c&&r[c]++;const n=new Uint32Array(e+1);let h=0;r[0]=0;for(let c=1;c<=e;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[be(f,u)]=c}return{min:t,max:e,table:a}}function vt(o,t){let e=0;for(let r=1;r<=t.max;r++){e|=o.readBits(1)<<r-1;const n=t.table.get(r);if(n&&e<n.length){const h=n[e];if(h!==void 0)return h}}throw Error("Invalid Huffman code")}function be(o,t){let e=0;for(let r=0;r<t;r++)e=e<<1|1&o,o>>>=1;return e>>>0}function xe(o){if(o.length<2)throw Error("ZLIB data too short");const t=o[0],e=o[1];if((15&t)!=8)throw Error("Unsupported ZLIB compression method");if(((t<<8)+e)%31!=0)throw Error("Bad ZLIB header check");let r=2;32&e&&(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 y=0;y<=143;y++)A[y]=8;for(let y=144;y<=255;y++)A[y]=9;for(let y=256;y<=279;y++)A[y]=7;for(let y=280;y<=287;y++)A[y]=8;p=q(A),m=q(Array(32).fill(5))}else{const A=h.readBits(5)+257,y=h.readBits(5)+1,E=h.readBits(4)+4,b=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],w=Array(19).fill(0);for(let M=0;M<E;M++)w[b[M]]=h.readBits(3);const P=q(w),x=[];for(;x.length<A+y;){const M=vt(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 ct=0;ct<B;ct++)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 N=x.slice(0,A),D=x.slice(A,A+y);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 y=A-257;let E=c[y];const b=u[y];b&&(E+=h.readBits(b));const w=vt(h,m);if(w>=30)throw Error("Invalid distance symbol");let P=f[w];const x=d[w];x&&(P+=h.readBits(x));const N=a.length-P;if(N<0)throw Error("Invalid distance");for(let D=0;D<E;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 Te(o){const t=R,e=new Uint8Array(o);if(t.readASCII(e,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(e,4),n=t.readUshort(e,12),h=t.readUint(e,16),a=[];let c=44;for(let E=0;E<n;E++){const b=t.readASCII(e,c,4),w=t.readUint(e,c+4),P=t.readUint(e,c+8),x=t.readUint(e,c+12),N=t.readUint(e,c+16);a.push({tag:b,offset:w,compLength:P,origLength:x,checksum:N}),c+=20}for(const E of a){const b=new Uint8Array(e.buffer,E.offset,E.compLength);if(E.compLength===E.origLength)E.data=new Uint8Array(b);else if(E.data=xe(b),E.data.length!==E.origLength)if(E.data.length<E.origLength){const w=new Uint8Array(E.origLength);w.set(E.data),E.data=w}else E.data=E.data.subarray(0,E.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 E of a)m[E.tag]=p,p=rt(p+E.data.length);const A=new Uint8Array(Math.max(h||0,p));_(A,0,r),nt(A,4,u),nt(A,6,g),nt(A,8,d),nt(A,10,v);let y=12;for(const E of a){ye(A,y,E.tag),y+=4;let b=E.data;if(E.tag==="head"&&b.length>=12){const w=new Uint8Array(b);_(w,8,0),_(A,y,mt(w,0,rt(w.length))),y+=4}else _(A,y,mt(b,0,rt(b.length))),y+=4;_(A,y,m[E.tag]),y+=4,_(A,y,E.data.length),y+=4}for(const E of a){const b=m[E.tag];A.set(E.data,b)}if(a.find(E=>E.tag==="head")){const E=m.head,b=function(w,P){const x=P+8,N=[w[x],w[x+1],w[x+2],w[x+3]];_(w,x,0);const D=2981146554-(mt(w,0,rt(w.length))>>>0)>>>0;return w[x]=N[0],w[x+1]=N[1],w[x+2]=N[2],w[x+3]=N[3],D>>>0}(A,E);_(A,E+8,b)}return A.buffer}const Ce={parseTab(o,t,e){const r={tables:[],ids:{},off:t};o=new Uint8Array(o.buffer,t,e),t=0;const n=R,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 e=R,r=e.readUshort,n=e.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(e.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 e=R.readUint;e(o,t+=4),e(o,t+=4);const r=e(o,t+=4);t+=4;const n=new Uint32Array(3*r);for(let h=0;h<3*r;h+=3)n[h]=e(o,t+(h<<2)),n[h+1]=e(o,t+(h<<2)+4),n[h+2]=e(o,t+(h<<2)+8);return{format:12,groups:n}}},Fe={parseTab(o,t,e){const r=R;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)}}},Re={parseTab(o,t,e){const r=R;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}},Pe={parseTab(o,t,e,r){const n=R,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}}},Lt={cmap:Ce,head:Fe,hhea:Re,maxp:{parseTab(o,t,e){const r=R;return r.readUint(o,t),t+=4,{numGlyphs:r.readUshort(o,t)}}},hmtx:Pe,loca:{parseTab(o,t,e,r){const n=R,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,e,r){const n=[],h=r.maxp.numGlyphs;for(let a=0;a<h;a++)n.push(null);return n},Ee(o,t){const e=R,r=o.Se,n=o.loca;if(n[t]===n[t+1])return null;const h=J.findTable(r,"glyf",o.ke);if(!h)return null;let a=h[0]+n[t];const c={};if(c.noc=e.readShort(r,a),a+=2,c.xMin=e.readShort(r,a),a+=2,c.yMin=e.readShort(r,a),a+=2,c.xMax=e.readShort(r,a),a+=2,c.yMax=e.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(e.readUshort(r,a)),a+=2;const u=e.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(e.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(e.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);R.readASCII(t,0,4)==="wOFF"&&(o=Te(o));const e=new Uint8Array(o),r=Lt,n={},h={Se:e,ze:0,ke:0};for(const a in r){const c=a,u=J.findTable(e,c,0);if(u){const[f,d]=u;let g=n[f];g==null&&(g=r[c].parseTab(e,f,d,h),n[f]=g),h[c]=g}}return[h]},findTable(o,t,e){const r=R,n=r.readUshort(o,e+4);let h=e+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:Lt,B:R};class Me{De(t){var r;const e=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const h=this.Le(n);e.push(...h)}else if(n.format===12){const h=this.Oe(n);e.push(...h)}}),[...new Set(e)]):[]}Le(t){const e=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return e;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.Ie(t,a,r)>0)try{const c=String.fromCodePoint(a);e.push(c)}catch{}}}return e}Oe(t){const e=[];if(!t.groups)return e;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);e.push(u)}catch{}}return e}Ie(t,e,r){if(t.idRangeOffset[r]===0)return e+t.idDelta[r]&65535;{const n=t.idRangeOffset[r]/2+(e-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 Ne{constructor(t){l(this,"Be");l(this,"He");l(this,"Z");this.Z=t,this.Be=document.createElement("canvas"),this.He=this.Be.getContext("2d",{willReadFrequently:!0,alpha:!0})}Ge(t,e,r,n){const h=t.length,a=Math.ceil(Math.sqrt(h)),c=Math.ceil(h/a),u=e.width*a,f=e.height*c;this.Qe(u,f),this.Ne(t,e,a,r,n);const d=this.Z.Pe(u,f,1,{filter:"nearest"});return d.et(this.Be),{framebuffer:d,columns:a,rows:c}}Qe(t,e){this.Be.width=t,this.Be.height=e,this.Be.style.width=t+"px",this.Be.style.height=e+"px",this.He.imageSmoothingEnabled=!1,this.Be.style.imageRendering="pixelated",this.He.clearRect(0,0,t,e),this.He.textBaseline="top",this.He.textAlign="left",this.He.fillStyle="white"}Ne(t,e,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*e.width,p=f*e.height,m=v+.5*e.width,A=p+.5*e.height,y=Math.round(m-.5*e.width),E=Math.round(A-.5*n),b=y+.5*(e.width-g),w=E+h.hhea.ascender*a;this.Xe(d,b,w,a)}}Xe(t,e,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.He.beginPath();let f=0;for(let d=0;d<c.length;d++){const g=c[d];if(!(g<f)){if(g>=f){const v=e+h[f]*n,p=r-a[f]*n;this.He.moveTo(v,p);let m=f+1;for(;m<=g;)if(1&u[m]){const A=e+h[m]*n,y=r-a[m]*n;this.He.lineTo(A,y),m++}else{const A=e+h[m]*n,y=r-a[m]*n;if(m+1>g){const b=e+h[f]*n,w=r-a[f]*n;if(1&u[f])this.He.quadraticCurveTo(A,y,b,w);else{const P=(A+b)/2,x=(y+w)/2;this.He.quadraticCurveTo(A,y,P,x)}break}const E=m+1;if(1&u[E]){const b=e+h[E]*n,w=r-a[E]*n;this.He.quadraticCurveTo(A,y,b,w),m=E+1}else{const b=(A+(e+h[E]*n))/2,w=(y+(r-a[E]*n))/2;this.He.quadraticCurveTo(A,y,b,w),m=E}}this.He.closePath()}f=g+1}}this.He.fill()}}class Dt{Ye(t,e){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.je(e,h):h.format===12&&(n=this.Ke(e,h)),n>0)break;return n}We(t,e){const r=e.codePointAt(0);return r===void 0?0:this.Ye(t,r)}Ze(t,e){const r=t.hmtx;return r&&r.aWidth&&r.aWidth.length!==0?e<r.aWidth.length?r.aWidth[e]:r.aWidth[r.aWidth.length-1]:0}qe(t,e){const r=e/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}}je(t,e){const r=e.endCount.length;let n=-1;for(let h=0;h<r;h++)if(t<=e.endCount[h]){n=h;break}if(n===-1||t<e.startCount[n])return 0;if(e.idRangeOffset[n]===0)return t+e.idDelta[n]&65535;{const h=e.idRangeOffset[n]/2+(t-e.startCount[n])-(r-n);if(h>=0&&h<e.glyphIdArray.length){const a=e.glyphIdArray[h];return a===0?0:a+e.idDelta[n]&65535}}return 0}Ke(t,e){const r=e.groups.length/3;for(let n=0;n<r;n++){const h=e.groups[3*n],a=e.groups[3*n+1],c=e.groups[3*n+2];if(t>=h&&t<=a)return c+(t-h)}return 0}}class Ue{constructor(){l(this,"Ve");this.Ve=new Dt}Je(t,e,r){let n=0;const h=this.Ve.qe(r,e),a=h.lineHeight;for(const c of t){const u=this.Ve.We(r,c);if(u===0)continue;const f=this.Ve.Ze(r,u)*h.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}}class Se{constructor(){l(this,"tr");this.tr=new Dt}sr(t,e){const r=[],n=new Map;return t.forEach((h,a)=>{const c=h.codePointAt(0)||0,u={character:h,unicode:c,color:this.ir(a),glyphData:this.er(e,h)};r.push(u),n.set(h,u)}),{array:r,map:n}}ir(t){return[t%256/255,Math.floor(t/256)%256/255,0]}er(t,e){const r=e.codePointAt(0)||0,n=this.tr.Ye(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.Ee(t,n);return a?{...a,advanceWidth:h}:null}}class pt{constructor(t,e=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=e,this.pr=new Me,this.gr=new Ne(t),this.mr=new Ue,this._r=new Se}async yr(t){let e;if(t){const r=await fetch(t);if(!r.ok)throw new C(`Failed to load font file: ${r.status} ${r.statusText}`);e=await r.arrayBuffer()}else e=await(await fetch("data:font/woff;base64,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")).arrayBuffer();await this.Ar(e),this.rr=J.parse(e)[0],await this.br()}wr(t){if(t===void 0)return this.cr;this.cr=t,this.dr=this.mr.Je(this.nr.map(r=>r.character),this.cr,this.rr);const e=this.gr.Ge(this.nr,this.dr,this.cr,this.rr);this.ar=e.framebuffer,this.lr=e.columns,this.ur=e.rows}async Cr(t){try{const e=await fetch(t);if(!e.ok)throw new C(`Failed to load font file: ${e.status} ${e.statusText}`);const r=await e.arrayBuffer();await this.Ar(r);const n=J.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.rr=n[0],await this.br()}catch(e){throw new C("Failed to load font: "+(e instanceof Error?e.message:"Unknown error"),e)}}async Ar(t){const e=Date.now();this.vr=new FontFace("CustomFont_"+e,t),await this.vr.load(),document.fonts.add(this.vr)}async br(){const t=this.pr.De(this.rr),{array:e,map:r}=this._r.sr(t,this.rr);this.nr=e,this.hr=r,this.dr=this.mr.Je(t,this.cr,this.rr);const n=this.gr.Ge(this.nr,this.dr,this.cr,this.rr);this.ar=n.framebuffer,this.lr=n.columns,this.ur=n.rows}Mr(t){const e=this.hr.get(t);return e?e.color:[0,0,0]}Fr(t){return Array.from(t).map(e=>{const r=this.hr.get(e);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,e,r){l(this,"Pr");l(this,"$r");l(this,"N");l(this,"X");l(this,"Tr");l(this,"Rr");l(this,"Er");l(this,"Sr");l(this,"kr");this.Er=t,this.Sr=e,this.kr=r,this.ti()}ti(){this.Pr=Math.floor(this.Er.width/this.Sr),this.$r=Math.floor(this.Er.height/this.kr),this.N=this.Pr*this.Sr,this.X=this.$r*this.kr,this.Tr=Math.floor((this.Er.width-this.N)/2),this.Rr=Math.floor((this.Er.height-this.X)/2)}zr(t,e){this.Sr=t,this.kr=e,this.ti()}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.Rr}}const Le=/^rgba?\(([^)]+)\)$/i;function Et(o){return Number.isNaN(o)?0:Math.max(0,Math.min(255,o))}function De(o){if(!o)return null;const t=o.trim().toLowerCase();if(!t)return null;let e=null;return t.startsWith("rgb")&&(e=function(r){const n=Le.exec(r.trim());if(!n)return null;const h=n[1].split(",").map(d=>d.trim());if(h.length<3)return null;const a=Et(parseFloat(h[0])),c=Et(parseFloat(h[1])),u=Et(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)),e?e[3]===0?null:e:null}class Zt{constructor(t={}){l(this,"Er");l(this,"Dr",null);l(this,"Lr",!1);l(this,"Or");this.Lr=t.overlay??!1,this.Lr&&t.canvas?(this.Dr=t.canvas,this.Er=this.Ir(),this.Or=!0,this.Br()):t.canvas?(this.Er=t.canvas,this.Or=!1):(this.Er=this.Hr(t.width,t.height),this.Or=!0),this.Er.style.imageRendering="pixelated"}Hr(t,e){const r=document.createElement("canvas");return r.className="textmodeCanvas",r.style.imageRendering="pixelated",r.width=t||800,r.height=e||600,document.body.appendChild(r),r}Ir(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const e=this.Dr.getBoundingClientRect();let r=Math.round(e.width),n=Math.round(e.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.Er,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.Er.parentElement&&t.push(this.Er.parentElement),t.push(this.Er),t.push(document.body),t.push(document.documentElement),t}Nr(){const t=this.Qr();for(const e of t){if(!e)continue;const r=De(window.getComputedStyle(e).backgroundColor);if(r)return r}return[255,255,255,255]}Gr(){if(!this.Dr)return;const t=this.Dr.getBoundingClientRect();let e=this.Dr.offsetParent;if(e&&e!==document.body){const r=e.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"}Xr(t,e){if(this.Lr){const r=this.Dr.getBoundingClientRect();this.Er.width=Math.round(r.width),this.Er.height=Math.round(r.height),this.Gr()}else this.Er.width=t??this.Er.width,this.Er.height=e??this.Er.height}Yr(){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 C("`textmode.js` requires WebGL2 support.");return t}gt(){const t=this.Er.getContext("webgl")||this.Er.getContext("webgl2");if(t){const e=t.getExtension("WEBGL_lose_context");e==null||e.loseContext()}this.Or&&this.Er.parentNode&&this.Er.parentNode.removeChild(this.Er)}get canvas(){return this.Er}get targetCanvas(){return this.Dr}get width(){return this.Er.width}get height(){return this.Er.height}}function ht(o){return Y(parseInt(o,16),0,255)}class U{constructor(t,e,r,n){l(this,"jr");l(this,"Kr");l(this,"r");l(this,"g");l(this,"b");l(this,"a");this.r=Y(t,0,255),this.g=Y(e,0,255),this.b=Y(r,0,255),this.a=Y(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,e,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 e=="number"&&typeof r=="number"?U.qr(t,e,r,n??255):U.Jr(t);throw Error("Unsupported color input passed to TextmodeColor.$from.")}static qr(t,e,r,n=255){return new U(t,e,r,n)}static Jr(t,e=255){return new U(t,t,t,e)}static Vr(t){return new U(...function(e){const r=e.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: "+e);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 yt=new Map;function Bt(o){yt.set(o.id,o)}function _t(o){return yt.get(o)}class Ot{constructor(t,e,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,"Rt",0);l(this,"Gt",0);l(this,"Qt",0);l(this,"Et",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=e,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.Rt=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.Et=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,e,r,n){return this.gn(this.Xt,t,e,r,n),this.q=null,this}cellColor(t,e,r,n){return this.gn(this.Yt,t,e,r,n),this.q=null,this}background(t,e,r,n){return this.gn(this.cn,t,e,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 e=[];for(const r of t){if(e.length>=64)break;let n=U.Wr(r);e.push(n.normalized)}return this.dn=e,this.vn=e.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}yn(){}ft(){this.yn();const t=this.An(),e=this.bn(),r=t.createShader(e),n=t.createUniforms(e);this.q=this.Z.materialManager.Ni(r,n)}gn(t,e,r,n,h){const a=U.Wr(e,r,n,h);it(t,a.r,a.g,a.b,a.a)}mn(t){const e=this.rr.Fr(t).filter(r=>Array.isArray(r)).slice(0,255);this.ln=e.length>0?e:this.ln}createBaseConversionUniforms(){const t=this.vn>0;return{u_image:this.wn(),u_invert:!!this.Rt,u_flipX:!!this.Gt,u_flipY:!!this.Qt,u_charRotation:this.Et,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}}An(){if(this.nn&&this.nn.id===this.rn)return this.nn;const t=_t(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}bn(){return{renderer:this.Z,gl:this.A,font:this.rr,source:this,gridWidth:this.N,gridHeight:this.X}}}class k extends Ot{constructor(t,e,r,n,h,a,c,u){const f=Math.min(c/h,u/a);super(t,e,r,n,h,a,Math.max(1,Math.floor(h*f)),Math.max(1,Math.floor(a*f)))}static Cn(t,e,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 k(a,t,c,e,u,f,n,h)}wn(){return this.tn}}class Xt{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,"Rn",[]);l(this,"En",10);l(this,"Sn",0);this.xn=1e3/t}kn(t){if(!this.Pn)return;this.Fn=performance.now();const e=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(e))};this.Mn=requestAnimationFrame(e)}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))}On(t,e){if(t===void 0)return this.$n;this.xn=1e3/t,this.Pn&&e&&(this.zn(),this.kn(e))}In(){const t=performance.now();if(this.Tn>0){const e=t-this.Tn;this.Rn.push(e),this.Rn.length>this.En&&this.Rn.shift();const r=this.Rn.reduce((n,h)=>n+h,0)/this.Rn.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 It{constructor(t){l(this,"Er");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,"th");l(this,"sh",!1);l(this,"ih");l(this,"eh");l(this,"rh");l(this,"nh");l(this,"hh");this.Er=t}oh(t){const e=performance.now()+Math.max(0,t);e>this.Kn&&(this.Kn=e)}ah(){return performance.now()<this.Kn}uh(t){const e=this.Er.canvas;e.style.cursor=t==null||t===""?"":t}yr(t){this.Nn=t,this.fh()}dh(){if(this.sh)return;const t=this.Er.canvas;this.Wn=e=>{this.ph(e),this.gh(e)},this.Zn=()=>{this.Yn={...this.Xn},this.Xn.x=-1,this.Xn.y=-1,this.jn=null},this.qn=e=>{this.ph(e),this.mh(e)},this.Vn=e=>{this.ph(e),this._h(e)},this.Jn=e=>{this.ph(e),this.yh(e)},this.th=e=>{this.ph(e),this.Ah(e)},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.th,{passive:!1}),this.sh=!0}bh(){if(!this.sh)return;const t=this.Er.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.th),this.sh=!1}fh(){if(this.sh)try{if(this.jn){const t=new MouseEvent("mousemove",{clientX:this.jn.x,clientY:this.jn.y,bubbles:!1,cancelable:!1});this.ph(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}}wh(t){this.ih=t}Ch(t){this.eh=t}xh(t){this.rh=t}Mh(t){this.nh=t}Fh(t){this.hh=t}Ph(){return{x:this.Xn.x,y:this.Xn.y}}gh(t){if(this.nh&&!this.ah()){const e={position:{...this.Xn},previousPosition:{...this.Yn},originalEvent:t};this.nh(e)}}mh(t){if(this.eh&&!this.ah()){const e={position:{...this.Xn},previousPosition:{...this.Yn},button:t.button,originalEvent:t};this.eh(e)}}_h(t){if(this.rh&&!this.ah()){const e={position:{...this.Xn},previousPosition:{...this.Yn},button:t.button,originalEvent:t};this.rh(e)}}yh(t){if(this.ih&&!this.ah()){const e={position:{...this.Xn},previousPosition:{...this.Yn},button:t.button,originalEvent:t};this.ih(e)}}Ah(t){if(this.hh&&!this.ah()){const e={position:{...this.Xn},previousPosition:{...this.Yn},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.hh(e)}}ph(t){const e=this.Er.canvas;this.Yn={...this.Xn},this.jn={x:t.clientX,y:t.clientY};const r=e.getBoundingClientRect(),n=t.clientX-r.left,h=t.clientY-r.top,a=e.width/r.width,c=h*(e.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 Ze=Object.freeze(Object.defineProperty({__proto__:null,MouseManager:It},Symbol.toStringTag,{value:"Module"}));class Yt{constructor(){l(this,"$h",new Map);l(this,"Th",null);l(this,"Rh",null);l(this,"Eh");l(this,"Sh");l(this,"sh",!1);l(this,"kh");l(this,"zh");l(this,"Dh",{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"})}dh(){this.sh||(this.Eh=t=>{this.Lh(t)},this.Sh=t=>{this.Oh(t)},window.addEventListener("keydown",this.Eh,{passive:!1}),window.addEventListener("keyup",this.Sh,{passive:!1}),this.sh=!0)}bh(){this.sh&&(window.removeEventListener("keydown",this.Eh),window.removeEventListener("keyup",this.Sh),this.sh=!1,this.$h.clear(),this.Th=null,this.Rh=null)}Ch(t){this.kh=t}xh(t){this.zh=t}Ih(t){const e=this.Bh(t),r=this.$h.get(t)||this.$h.get(e);return(r==null?void 0:r.isPressed)||!1}Hh(){return this.Th}Gh(){return this.Rh}Qh(){const t=[];for(const[e,r]of this.$h)r.isPressed&&t.push(e);return t}Nh(){return{ctrl:this.Ih("Control"),shift:this.Ih("Shift"),alt:this.Ih("Alt"),meta:this.Ih("Meta")}}Xh(){this.$h.clear(),this.Th=null,this.Rh=null}Lh(t){const e=t.key,r=Date.now();this.$h.has(e)||this.$h.set(e,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.$h.get(e);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.Th=e,this.kh)){const h={key:e,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.kh(h)}}Oh(t){const e=t.key,r=Date.now();this.$h.has(e)||this.$h.set(e,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.$h.get(e);if(n.isPressed=!1,n.lastReleaseTime=r,this.Rh=e,this.zh){const h={key:e,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.zh(h)}}Bh(t){return this.Dh[t]||t.toLowerCase()}}const Be=Object.freeze(Object.defineProperty({__proto__:null,KeyboardManager:Yt},Symbol.toStringTag,{value:"Module"}));class zt{constructor(t,e){l(this,"Er");l(this,"Yh");l(this,"Nn");l(this,"jh",new Map);l(this,"Kh",new Map);l(this,"Wh",new Map);l(this,"Zh",null);l(this,"qh");l(this,"Vh");l(this,"Jh");l(this,"so");l(this,"io");l(this,"eo");l(this,"sh",!1);l(this,"ro");l(this,"no");l(this,"ho");l(this,"oo");l(this,"ao");l(this,"co");l(this,"lo");l(this,"uo");l(this,"fo");l(this,"do");l(this,"vo",320);l(this,"po",350);l(this,"mo",10);l(this,"_o",550);l(this,"yo",14);l(this,"Ao",48);l(this,"bo",650);l(this,"wo",.02);l(this,"Co",2);l(this,"xo",600);l(this,"Mo",0);l(this,"Fo",null);this.Er=t,this.Yh=e;const r=this.Er.canvas;this.qh=r.style.touchAction,this.Vh=r.style.userSelect,r.style.touchAction||(r.style.touchAction="none"),r.style.userSelect||(r.style.userSelect="none")}yr(t){this.Nn=t,this.fh()}dh(){if(this.sh)return;const t=this.Er.canvas;this.Jh=e=>{this.Po(e)},this.so=e=>{this.$o(e)},this.io=e=>{this.To(e)},this.eo=e=>{this.Ro(e)},t.addEventListener("touchstart",this.Jh,{passive:!1}),t.addEventListener("touchmove",this.so,{passive:!1}),t.addEventListener("touchend",this.io,{passive:!1}),t.addEventListener("touchcancel",this.eo,{passive:!1}),this.sh=!0}bh(){if(!this.sh)return;const t=this.Er.canvas;t.removeEventListener("touchstart",this.Jh),t.removeEventListener("touchmove",this.so),t.removeEventListener("touchend",this.io),t.removeEventListener("touchcancel",this.eo),this.sh=!1,this.Zh=null,this.jh.clear(),this.Kh.clear(),this.Wh.forEach(e=>{e.longPressTimer!==null&&window.clearTimeout(e.longPressTimer)}),this.Wh.clear(),this.Fo=null,this.Mo=0,t.style.touchAction=this.qh,t.style.userSelect=this.Vh}fh(){if(!this.Nn||this.jh.size===0)return;const t=new Map;for(const e of this.jh.values()){const r=this.Eo(e.clientX,e.clientY,e.id,e);t.set(e.id,r)}this.jh=t}So(){return Array.from(this.jh.values()).map(t=>({...t}))}ko(t){this.ro=t}Mh(t){this.no=t}zo(t){this.ho=t}Do(t){this.oo=t}Lo(t){this.ao=t}Oo(t){this.co=t}Io(t){this.lo=t}Bo(t){this.uo=t}Ho(t){this.fo=t}Go(t){this.do=t}Po(t){var n;if(!this.Nn)return;t.preventDefault(),(n=this.Yh)==null||n.oh(this.xo);const e=performance.now(),r=this.Qo(t.changedTouches);for(const h of r){const a=this.jh.get(h.id);a&&this.Kh.set(h.id,this.No(a)),this.jh.set(h.id,h);const c={id:h.id,startPosition:h,lastPosition:h,startTime:e,lastTime:e,longPressTimer:null,longPressFired:!1};this.lo&&(c.longPressTimer=window.setTimeout(()=>{const u=this.jh.get(h.id);u&&(c.longPressFired=!0,this.lo({touch:this.No(u),duration:performance.now()-c.startTime,originalEvent:t}))},this._o)),this.Wh.set(h.id,c),this.ro&&this.ro(this.Xo(h,t,void 0,e))}this.jh.size===2&&this.Yo()}$o(t){var n;if(!this.Nn)return;t.preventDefault(),(n=this.Yh)==null||n.oh(this.xo);const e=performance.now(),r=this.Qo(t.changedTouches);for(const h of r){const a=this.jh.get(h.id),c=a?this.No(a):void 0;c&&this.Kh.set(h.id,c),this.jh.set(h.id,h);const u=this.Wh.get(h.id);u&&(u.lastPosition=h,u.lastTime=e,c)&&j(c.clientX,c.clientY,h.clientX,h.clientY)>this.yo&&u.longPressTimer!==null&&(window.clearTimeout(u.longPressTimer),u.longPressTimer=null),this.no&&this.no(this.Xo(h,t,c,e))}this.jh.size===2?this.jo(t):this.Zh=null}To(t){if(!this.Nn)return;t.preventDefault();const e=performance.now(),r=this.Qo(t.changedTouches);for(const n of r){const h=this.jh.get(n.id),a=h?this.No(h):void 0,c=this.Wh.get(n.id);c&&c.longPressTimer!==null&&(window.clearTimeout(c.longPressTimer),c.longPressTimer=null),this.ho&&this.ho(this.Xo(n,t,a,e)),c&&this.Ko(c,t),this.Wh.delete(n.id),this.Kh.delete(n.id),this.jh.delete(n.id)}this.jh.size<2&&(this.Zh=null)}Ro(t){if(!this.Nn)return;t.preventDefault();const e=performance.now(),r=this.Qo(t.changedTouches);for(const n of r){const h=this.jh.get(n.id),a=h?this.No(h):void 0,c=this.Wh.get(n.id);c&&c.longPressTimer!==null&&(window.clearTimeout(c.longPressTimer),c.longPressTimer=null),this.oo&&this.oo(this.Xo(n,t,a,e)),this.Wh.delete(n.id),this.Kh.delete(n.id),this.jh.delete(n.id)}this.jh.size<2&&(this.Zh=null)}Qo(t){const e=[];for(let r=0;r<t.length;r+=1){const n=t.item(r);n&&e.push(this.Wo(n))}return e}Wo(t){return this.Eo(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})}Eo(t,e,r,n){const h=this.Er.canvas,a=h.getBoundingClientRect(),c=t-a.left,u=e-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:e,pressure:n.pressure,radiusX:n.radiusX,radiusY:n.radiusY,rotationAngle:n.rotationAngle}}Xo(t,e,r,n){const h=this.Wh.get(t.id),a=Array.from(this.Kh.values()).map(f=>this.No(f)),c=Array.from(this.jh.values()).map(f=>this.No(f)),u=this.Qo(e.changedTouches);return{touch:this.No(t),previousTouch:r?this.No(r):void 0,touches:c,previousTouches:a,changedTouches:u,deltaTime:h?n-h.lastTime:0,originalEvent:e}}Yo(){if(this.jh.size!==2)return void(this.Zh=null);const t=Array.from(this.jh.values()),[e,r]=t,n=j(e.x,e.y,r.x,r.y),h=Tt(e.clientX,e.clientY,r.clientX,r.clientY);this.Zh={ids:[e.id,r.id],initialDistance:Math.max(n,1e-4),initialAngle:h,lastScale:1,lastRotation:0}}jo(t){if(this.Zh||this.Yo(),!this.Zh)return;const[e,r]=this.Zh.ids,n=this.jh.get(e),h=this.jh.get(r);if(!n||!h)return;const a=j(n.x,n.y,h.x,h.y)/this.Zh.initialDistance,c=a-this.Zh.lastScale;this.fo&&Math.abs(c)>this.wo&&(this.fo({touches:[this.No(n),this.No(h)],scale:a,deltaScale:c,center:this.Zo(n,h),originalEvent:t}),this.Zh.lastScale=a);let u=Tt(n.clientX,n.clientY,h.clientX,h.clientY)-this.Zh.initialAngle;u=(u+180)%360-180;const f=u-this.Zh.lastRotation;this.do&&Math.abs(f)>this.Co&&(this.do({touches:[this.No(n),this.No(h)],rotation:u,deltaRotation:f,center:this.Zo(n,h),originalEvent:t}),this.Zh.lastRotation=u)}Zo(t,e){const r=(t.clientX+e.clientX)/2,n=(t.clientY+e.clientY)/2,h=this.Eo(r,n,-1,{id:-1,x:-1,y:-1,clientX:r,clientY:n});return{x:h.x,y:h.y}}Ko(t,e){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.vo&&h<=this.mo)this.qo(t.lastPosition,r)&&this.co?this.co({touch:this.No(t.lastPosition),taps:2,originalEvent:e}):this.ao&&this.ao({touch:this.No(t.lastPosition),taps:1,originalEvent:e});else if(!t.longPressFired&&n<=this.bo&&h>=this.Ao){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.uo&&this.uo({touch:this.No(t.lastPosition),direction:u,distance:c,velocity:f,originalEvent:e})}this.Mo=r,this.Fo=this.No(t.lastPosition)}qo(t,e){return!!this.Fo&&!(e-this.Mo>this.po)&&j(t.clientX,t.clientY,this.Fo.clientX,this.Fo.clientY)<=this.mo}No(t){return{...t}}}const _e=Object.freeze(Object.defineProperty({__proto__:null,TouchManager:zt},Symbol.toStringTag,{value:"Module"}));class Oe{constructor(t,e){l(this,"A");l(this,"Vo");l(this,"$n",null);l(this,"Jo",0);l(this,"ta",!1);l(this,"sa",[]);l(this,"ia",-1);this.A=t,this.Vo=e}get isPreloaded(){return this.ta}get totalFrames(){return this.Jo}get frameRate(){return this.$n}get textures(){return this.sa}dispose(){this.ea(),this.sa=[],this.$n=null,this.Jo=0,this.ta=!1,this.ia=-1}async preload(t,e){var r;try{if(t<=0)throw Error("Video preload requires a frameRate greater than 0.");const n=this.Vo.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,e)?(this.ha("captureStream",e),"captureStream"):(await this.oa(t,e),this.ha("seeking",e),"seeking")}catch(n){const h=n instanceof Error?n:Error(n+"");throw(r=e==null?void 0:e.onError)==null||r.call(e,h),this.dispose(),h}}ra(t,e){this.ea(),this.$n=t,this.Jo=e,this.sa=[],this.ta=!1,this.ia=-1}ha(t,e){var r;if(this.sa.length===0)throw Error(`Video preload via ${t} completed but produced 0 frames.`);this.Jo=this.sa.length,this.ta=!0,this.ia=-1,this.Vo.pause(),this.Vo.currentTime=0,e!=null&&e.onProgress&&e.onProgress({percent:100,loadedFrames:this.Jo,totalFrames:this.Jo,strategy:t}),(r=e==null?void 0:e.onComplete)==null||r.call(e,{totalFrames:this.Jo,strategy:t})}aa(t){const e=this.A,r=e.createTexture();return e.bindTexture(e.TEXTURE_2D,r),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,1),tt(e,e.LINEAR,e.LINEAR,e.CLAMP_TO_EDGE,e.CLAMP_TO_EDGE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.bindTexture(e.TEXTURE_2D,null),r}ca(t,e){if(!(e!=null&&e.onProgress)||this.Jo===0)return;const r=Math.min(99,Math.floor(this.sa.length/this.Jo*100)),n=10*Math.floor(r/10);n>this.ia&&(this.ia=n,e.onProgress({percent:r,loadedFrames:this.sa.length,totalFrames:this.Jo,strategy:t}))}async na(t,e){const r=globalThis,n=r==null?void 0:r.MediaStreamTrackProcessor,h=this.Vo.captureStream;if(typeof n!="function"||typeof h!="function")return!1;let a,c=null;try{const u=h.call(this.Vo);if(a=u.getVideoTracks()[0],!a)return u.getTracks().forEach(g=>g.stop()),!1;if(c=new n({track:a}).readable.getReader(),this.Vo.currentTime=0,this.Vo.muted=!0,await this.Vo.play().catch(()=>{}),this.Vo.paused)return!1;const f=1e6/t;let d=0;for(;this.sa.length<this.Jo;){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",e))}finally{v.close()}}return c.releaseLock(),a.stop(),c=null,a=void 0,this.Vo.pause(),this.Vo.currentTime=0,this.sa.length!==0}catch{return this.ea(),this.sa=[],this.ia=-1,!1}finally{if(c)try{await c.cancel()}catch{}a&&a.stop(),this.Vo.pause(),this.Vo.currentTime=0}}async oa(t,e){const r=1/t,n=this.Jo,h=this.Vo;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",e)}h.currentTime=0}la(t){return new Promise((e,r)=>{const n=this.Vo,h=()=>{n.removeEventListener("seeked",a),n.removeEventListener("error",c)},a=()=>{h(),e()},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 e();n.currentTime=f})}ea(){for(const t of this.sa)this.A.deleteTexture(t)}}class ot extends Ot{constructor(e,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(e,r,n,h,c,u,v,p);l(this,"Vo");l(this,"ua",0);l(this,"fa",null);this.Vo=a}gt(){var e;super.gt(),(e=this.fa)==null||e.dispose(),this.fa=null,this.Vo.pause(),this.Vo.src="",this.Vo.load()}da(){var e;if(!((e=this.fa)!=null&&e.isPreloaded)&&this.Vo.readyState>=this.Vo.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.Vo),r.bindTexture(r.TEXTURE_2D,null)}}wn(){var r,n;const e=(r=this.fa)==null?void 0:r.textures;return e&&e.length>0&&((n=this.fa)!=null&&n.isPreloaded)?e[this.ua%e.length]:this.tn}ut(){return this.q=null,super.ut()}yn(){this.da()}frame(e){var n,h;const r=((n=this.fa)==null?void 0:n.totalFrames)??0;return(h=this.fa)!=null&&h.isPreloaded&&e!==void 0&&r>0&&(this.ua=(e%r+r)%r,this.q=null),this}static async Cn(e,r,n,h,a,c){const u=e.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,y)=>{d.addEventListener("loadedmetadata",()=>A(),{once:!0}),d.addEventListener("error",E=>{var w;const b=E.target;y(Error("Failed to load video: "+(((w=b.error)==null?void 0:w.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,e,g,r,d,v,p,h,a);return f&&f>0&&(m.fa=new Oe(u,d),await m.fa.preload(f,c),m.ua=0),m}async play(){await this.Vo.play()}pause(){this.Vo.pause()}stop(){this.Vo.pause(),this.Vo.currentTime=0}speed(e){return this.Vo.playbackRate=e,this}loop(e=!0){return this.Vo.loop=e,this}time(e){return this.Vo.currentTime=e,this}volume(e){return this.Vo.volume=Math.max(0,Math.min(1,e)),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.Vo}get currentTime(){return this.Vo.currentTime}get duration(){return this.Vo.duration}get isPlaying(){return!this.Vo.paused&&!this.Vo.ended}get totalFrames(){var e;return((e=this.fa)==null?void 0:e.totalFrames)??0}}const Xe=o=>class extends o{va(t,e,r,n){if(U.Zr(t))return t;if(typeof t=="number"||typeof t=="string")return this.color(t,e,r,n);throw Error("Unsupported color input passed to color-capable method.")}rotate(t=0,e=0,r=0){this.Z.state.Vt(t),this.Z.state.Jt(e),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,e=0,r=0){this.Z.state.ss(t,e,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.ht()}pop(){this.Z.state.ot()}color(t,e,r,n){return U.Wr(t,e,r,n)}rect(t=1,e=1){this.Z.be(t,e)}point(){this.Z.be(1,1)}line(t,e,r,n){this.Z.we(t,e,r,n)}lineWeight(t){this.Z.state.Zt(t)}background(t,e,r,n=255){const h=this.va(t,e,r,n);this.Z.$e(h.r,h.g,h.b,h.a)}char(t){const e=Array.from(t);if(e.length===0)throw Error("char() requires at least one character.");this.Z.state.hs(this.rr.Mr(e[0]))}charColor(t,e,r,n){const h=this.va(t,e,r,n);this.Z.state.cs(h.r,h.g,h.b,h.a)}cellColor(t,e,r,n){const h=this.va(t,e,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.bi(0,0,0,0)}ellipse(t,e){this.Z.Ce(t/2,e/2)}triangle(t,e,r,n,h,a){this.Z.xe(t,e,r,n,h,a)}bezierCurve(t,e,r,n,h,a,c,u){this.Z.Me(t,e,r,n,h,a,c,u)}arc(t,e,r,n){this.Z.Fe(t/2,e/2,r,n)}shader(t){this.Z.ge(t)}setUniform(t,e){this.Z.I(t,e)}setUniforms(t){this.Z.me(t)}async createFilterShader(t){if(typeof t=="string"&&(t.startsWith("./")||t.startsWith("../")||t.endsWith(".frag")||t.endsWith(".glsl"))){const e=await fetch(t);if(!e.ok)throw Error(`Failed to load shader from ${t}: ${e.statusText}`);const r=await e.text();return this.Z._e(r)}return this.Z._e(t)}createFramebuffer(t){return this.Z.Pe(t.width??this.grid.cols,t.height??this.grid.rows,t.attachments??3)}image(t,e,r){this.Z.ye(t,e,r),t instanceof z&&this.Z.ct()}ortho(){this.Z.state.gs(!0)}async loadImage(t){if(typeof t!="string"){const h=k.Cn(this.Z,this.rr,t,this.Nn.cols,this.Nn.rows);return this.pa(h),h}const e=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=e}),n=k.Cn(this.Z,this.rr,r,this.Nn.cols,this.Nn.rows);return this.pa(n),n}async loadVideo(t,e){const r=await ot.Cn(this.Z,this.rr,t,this.Nn.cols,this.Nn.rows,e);return this.pa(r),r}},Ie=o=>class extends o{async loadFont(t){return this.rr.Cr(t).then(()=>{const e=this.rr.maxGlyphDimensions;this.Nn.zr(e.width,e.height),this.ga.resize(this.Nn.cols,this.Nn.rows),this.Z.Re(),this.Yh.fh(),this.ma.fh();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.wr(t);const e=this.rr.maxGlyphDimensions;this.Nn.zr(e.width,e.height),this.ga.resize(this.Nn.cols,this.Nn.rows),this.Z.Re(),this.Yh.fh(),this.ma.fh()}},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.On(t,()=>this.ba())}noLoop(){this.ya.Dn()}loop(){this.ya.Ln(()=>this.ba())}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 e=0;e<t;e++)this.ba()}isLooping(){return this.ya.Bn}},ze=o=>class extends o{constructor(...t){super(...t)}mouseClicked(t){this.Yh.wh(t)}mousePressed(t){this.Yh.Ch(t)}mouseReleased(t){this.Yh.xh(t)}mouseMoved(t){this.Yh.Mh(t)}mouseScrolled(t){this.Yh.Fh(t)}get mouse(){return this.Yh.Ph()}cursor(t){this.Yh.uh(t)}},Ve=o=>class extends o{constructor(...t){super(...t)}touchStarted(t){this.ma.ko(t)}touchMoved(t){this.ma.Mh(t)}touchEnded(t){this.ma.zo(t)}touchCancelled(t){this.ma.Do(t)}tap(t){this.ma.Lo(t)}doubleTap(t){this.ma.Oo(t)}longPress(t){this.ma.Io(t)}swipe(t){this.ma.Bo(t)}pinch(t){this.ma.Ho(t)}rotateGesture(t){this.ma.Go(t)}get touches(){return this.ma.So()}},Ge=o=>class extends o{constructor(...t){super(...t)}keyPressed(t){this.wa.Ch(t)}keyReleased(t){this.wa.xh(t)}isKeyPressed(t){return this.wa.Ih(t)}get lastKeyPressed(){return this.wa.Hh()}get lastKeyReleased(){return this.wa.Gh()}get pressedKeys(){return this.wa.Qh()}get modifierState(){return this.wa.Nh()}};class ke{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 e of t){if(this.xa.has(e.name))return void console.warn(`[textmode.js] Plugin "${e.name}" is already installed.`);const r=this.Ta(e.name);try{await e.install(this.Ca,r)}catch(n){throw this.Ra(e.name),n}this.xa.set(e.name,e),this.Ma.push(e.name)}}async Ea(t){const e=this.xa.get(t);if(!e)return;const r=this.Ta(t);e.uninstall&&await e.uninstall(this.Ca,r),this.xa.delete(t),this.Ma.splice(this.Ma.indexOf(t),1),this.Ra(t)}Sa(){this.ka(this.Fa)}za(){this.ka(this.Pa)}async Da(){const t=[...this.xa.keys()];for(const e of t)await this.Ea(e)}Ta(t){return{renderer:this.Ca.Z,font:this.Ca.rr,grid:this.Ca.Nn,canvas:this.Ca.Er,drawFramebuffer:this.Ca.ga,asciiFramebuffer:this.Ca.La,registerPreDrawHook:e=>this.Oa(this.Fa,t,e),registerPostDrawHook:e=>this.Oa(this.Pa,t,e)}}Oa(t,e,r){const n=t.get(e)??new Set;return n.add(r),t.set(e,n),()=>{const h=t.get(e);h&&(h.delete(r),h.size===0&&t.delete(e))}}Ra(t){this.Fa.delete(t),this.Pa.delete(t)}ka(t){for(const e of this.Ma){const r=t.get(e);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 Vt{constructor(){l(this,"Ia",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 e of this.Ba){const r=this.Ia.get(e);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,e=1){const r=`phase-${this.Ba.length+1}-${Date.now()}`,n={id:r,label:t,weight:Math.max(.001,e),progress:0,status:"running"};return this.Ia.set(r,n),this.Ba.push(r),this.Ha+=n.weight,r}Ka(t,e){const r=this.Ia.get(t);if(!r)return;r.progress=Math.max(0,Math.min(1,e)),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 e=this.Ia.get(t);e&&(e.progress=1,e.status="complete",this.Ka(t,1))}Za(t){const e=this.Ia.get(t);e&&(e.status="failed")}qa(){return this.Ba.map(t=>{const e=this.Ia.get(t);return e?{id:e.id,label:e.label,weight:e.weight,progress:e.progress,status:e.status}:{id:t,label:t,weight:1,progress:0,status:"pending"}})}}class Gt{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 hc(){return this.tc}oc(){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,e){l(this,"dc",0);l(this,"vc",1);l(this,"gc");l(this,"mc");this.gc=t,this.mc=e}get _c(){return this.vc}get yc(){return this.vc<1}kn(){this.gc!=="none"&&this.mc>0&&(this.dc=performance.now())}et(){if(this.gc==="none"||this.mc===0)return this.vc=1,!1;const t=performance.now()-this.dc,e=Math.min(1,t/this.mc);return e>=1?(this.vc=0,!0):(this.vc=1-e,!1)}ti(){this.vc=1,this.dc=0}}function wt(o,t){const e=o.tone??"auto";let r="dark";return e==="light"||e==="dark"?r=e: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 Wt(o){return o.mode==="light"?["#E91E63","#9C27B0","#FF6F00"]:["#8EF9F3","#F15BB5","#FF9B71"]}function Ht(o,t){return o.length?o.map(e=>t.color(e)):[t.color("#FFFFFF")]}const We=({textmodifier:o,grid:t,progress:e,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 y=o.color(a.mode==="light"?"#D32F2F":"#FF6B6B",m);o.charColor(y),o.push(),o.translate(0,-2,0),o.char("X"),o.rect(1,1),o.pop();const E="SETUP ERROR",b=-Math.floor(E.length/2);o.push(),o.translate(b,0,0);for(const w of E)o.char(w),o.rect(1,1),o.translateX(1);if(o.pop(),d){const w=o.color(a.subtleColor),P=o.color(w.r,w.g,w.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 B=D.slice(0,3);D.length>3&&(B[2]=B[2].substring(0,x-3)+"..."),B.forEach((L,ct)=>{const ri=-Math.floor(L.length/2);o.push(),o.translate(ri,3+ct,0);for(const ni of L)o.char(ni),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(),e>0||c.some(y=>y.status!=="pending")){const y=Math.max(6,Math.floor(.6*t.cols)),E=-Math.floor(y/2),b=Math.floor(y*e),w=h.length?h:[o.color("#FFFFFF")];o.push(),o.translate(E,3,0);for(let P=0;P<y;P++){const x=P<b?"*":".",N=w[P%w.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 y=o.color(a.subtleColor),E=o.color(y.r,y.g,y.b,m);o.charColor(E);const b=-Math.floor(n.length/2);o.push(),o.translate(b,5,0);for(const w of n)o.char(w),o.rect(1,1),o.translateX(1);o.pop()}},He={message:"LOADING...",tone:"auto",transition:"fade",transitionDuration:500};class je{constructor(t,e,r){this.bc=t,this.id=e,this.label=r}report(t){this.bc.Ka(this.id,t)}complete(){this.bc.Wa(this.id)}fail(t){this.bc.Za(this.id)}async track(t){try{const e=typeof t=="function"?await t():await t;return this.complete(),e}catch(e){throw this.fail(),e}}}class jt{constructor(t,e,r){l(this,"Ca");l(this,"l");l(this,"wc");l(this,"bc");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,"Rc");l(this,"Ec",performance.now());l(this,"Sc",0);l(this,"kc",!1);l(this,"zc",!1);l(this,"Ic");this.Ca=t,this.l={...He,...e??{}},this.wc=new Gt("active"),this.bc=new Vt,this.Cc=new kt(this.l.transition,this.l.transitionDuration),this.xc=new Xt(60),this.Rc=wt(this.l,r);const n=Wt(this.Rc);this.Tc=Ht(n,this.Ca),this.Z=this.Dc(),this.bc.Ya(h=>{h>=.999&&this.ac()})}async yr(t){if(this.zc)return;const e=this.Ca.Z,r=this.Ca.Er;this.Mc=new pt(e,16),await this.Mc.yr(t);const n=this.Mc.maxGlyphDimensions;this.Fc=new At(r.canvas,n.width,n.height),this.Pc=e.Pe(this.Fc.cols,this.Fc.rows,3),this.$c=e.Pe(this.Fc.width,this.Fc.height,1),this.zc=!0}get rc(){return this.wc.rc&&this.kc}kn(){this.kc||(this.kc=!0,this.Ec=performance.now(),this.Sc=0,this.xc.kn(()=>this.Lc()))}zn(){this.kc&&(this.kc=!1,this.xc.zn())}Xr(){this.zc&&(this.Fc.ti(),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.bc.Xa}message(t){return typeof t=="string"&&(this.l.message=t),this.l.message}addPhase(t,e=1){this.wc.oc();const r=this.bc.ja(t,e);return new je(this.bc,r,t)}ac(){this.l.transition!=="none"&&this.l.transitionDuration>0?(this.wc.cc(),this.Cc.kn()):(this.wc.ac(),this.zn(),this.Oc())}Oc(){this.Ic&&this.Ic()}Bc(t){this.Ic=t}error(t){this.wc.uc(t)}Lc(){if(this.wc.rc){if(this.Sc++,this.wc.sc==="transitioning"&&this.Cc.et())return this.wc.lc(),this.Oc(),void this.zn();this.Hc()}}Hc(){if(!this.zc)return;const t=this.Pc,e=this.Mc,r=this.Fc,n=this.$c,h=this.Ca.Z,a=this.Ca.Er,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.Ec,frameCount:this.Sc,message:this.l.message,palette:this.Tc,theme:this.Rc,phases:this.bc.qa(),transitionOpacity:this.Cc._c,isError:this.wc.sc==="error",errorMessage:this.wc.nc||void 0,errorDetails:this.wc.hc||void 0};this.Z(f)}finally{this.Ca.pop()}t.end(),n.begin(),h.ve(c),c.O({u_characterTexture:e.fontFramebuffer,u_charsetDimensions:[e.textureColumns,e.textureRows],Uk:t.textures[0],Ul:t.textures[1],Um:t.textures[2],Un:[r.cols,r.rows],Uo:[n.width,n.height],Up:h.state.canvasBackgroundColor}),h.Ae(0,0,a.width,a.height),n.end(),h.bi(...h.state.canvasBackgroundColor),h.ve(u),u.O({U0:n.textures[0],U1:[n.width,n.height],U2:[r.offsetX,r.offsetY],U3:[r.width,r.height]}),h.Ae(r.offsetX,r.offsetY,r.width,r.height)}Nc(t){this.Rc=wt(this.l,t)}Dc(){const t=this.l.renderer||We;return e=>{t(e),this.Xc(e)}}Xc(t){const{textmodifier:e,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]];e.push(),e.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,y]=d[p],E=Math.floor(255*a),b=e.color(m,A,y,E);e.charColor(b),e.char(v),e.point(),e.translateX(1)}e.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,"il",!0);l(this,"el",[]);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.el;return this.el=[],t}hl(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,e=0){if(t===void 0)return{x:this.Kc,y:this.Wc};this.Kc=Math.round(t),this.Wc=Math.round(e)}filter(t,e){this.el.push({name:t,params:e})}ol(t){this.Zc=t,this.al(t.grid)}ba(t,e){if(!this.Yc||!this.tl)return void(this.sl=!1);const r=this.Zc.renderer;this.el=[],this.qc.begin(),r.state.qt(),this.tl.call(t),this.qc.end();const n=this.el.length>0,h=n?this.Jc:this.Vc;h.begin(),r.ve(e),e.O({u_characterTexture:this.Zc.font.fontFramebuffer,u_charsetDimensions:[this.Zc.font.textureColumns,this.Zc.font.textureRows],Uk:this.qc.textures[0],Ul:this.qc.textures[1],Um:this.qc.textures[2],Un:[this.Zc.grid.cols,this.Zc.grid.rows],Uo:[h.width,h.height],Up:[0,0,0,0]}),r.Ae(0,0,this.Zc.grid.width,this.Zc.grid.height),h.end(),n&&this.Zc.filterManager.cl(this.Jc.textures[0],this.Vc,this.el,this.Vc.width,this.Vc.height,this.Zc.layerPingPongBuffers),this.sl=!0}Xr(t){var e;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),(e=this.Jc)==null||e.resize(t.width,t.height))}gt(){var t,e,r;this.il&&((t=this.qc)==null||t.gt(),(e=this.Vc)==null||e.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.il=!this.Zc.externalDrawFramebuffer&&!this.Zc.externalAsciiFramebuffer,this.sl=!1)}}const Qt={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 Kt{constructor(t){l(this,"Z");l(this,"ul");l(this,"fl",null);l(this,"dl",0);this.Z=t,this.ul=t.pe($,`#version 300 es
12
+ precision highp float;uniform sampler2D Uq;uniform sampler2D Ur;uniform vec2 Us;uniform float Ut;uniform vec2 Uu;uniform int Uv;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(Ur,v_uv);vec2 h=v_uv*Us-Uu;bool i=any(lessThan(h,vec2(0.)))||any(greaterThanEqual(h,Us));if(i){fragColor=g;return;}vec2 j=(floor(h)+0.5)/Us;vec4 k=texture(Uq,j);float l=k.a*Ut;if(l<=0.){fragColor=g;return;}vec3 m=e(Uv,g.rgb,k.rgb);vec3 n=mix(g.rgb,m,l);float o=g.a+l*(1.-g.a);fragColor=vec4(n,o);}`)}yr(t){this.fl||(this.fl=[this.Z.Pe(t.width,t.height,1),this.Z.Pe(t.width,t.height,1)])}vl(t,e){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=e.width,v=e.height,p=this.fl[0];p.begin(),this.Z.bi(...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,e,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.ve(this.ul),this.ul.O({Uq:t,Ur:f.textures[0],Us:[e,r],Ut:n,Uu:[h,a],Uv:Qt[c]}),this.Z.Ae(0,0,f.width,f.height),g.end(),this.dl=d}ml(t,e,r,n){const h=this.fl[this.dl];t.begin(),n.disable(n.BLEND),this.Z.ve(this.ul),this.ul.O({Uq:h.textures[0],Ur:h.textures[0],Us:[h.width,h.height],Ut:1,Uu:[0,0],Uv:Qt.normal}),this.Z.Ae(0,0,e,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 qt{constructor(t){l(this,"Ca");l(this,"Z");l(this,"_l");l(this,"yl");l(this,"Al",[]);l(this,"bl",[]);l(this,"wl");l(this,"Cl");l(this,"xl");l(this,"Ml");l(this,"Fl",!1);this.Ca=t,this.Z=t.Z,this._l=t.Gc,this.yl=new Kt(this.Z),this.wl=new bt({visible:!0,opacity:1})}add(t={}){const e=new bt(t);return this.Fl?(this.Pl(e),this.bl.push(e)):this.Al.push(e),e}remove(t){this.$l(this.bl,t)||this.$l(this.Al,t)}move(t,e){this.Tl(this.bl,t,e)||this.Tl(this.Al,t,e)}swap(t,e){t!==e&&(this.Rl(this.bl,t,e)||this.Rl(this.Al,t,e))}yr(){if(this.Fl)return;const t=this.Ca.Nn;this.Cl=this.Z.Pe(t.width,t.height,1),this.xl=this.Z.Pe(t.width,t.height,1),this.Ml=[this.Z.Pe(t.width,t.height,1,{depth:!1}),this.Z.Pe(t.width,t.height,1,{depth:!1})],this.El(),this.yl.yr(t);for(const e of this.Al)this.Pl(e),this.bl.push(e);this.Al.length=0,this.Fl=!0}Sl(t,e){const r=this.Ca.Nn,n=this.Ca.font,h=this.Ca.ga,a=this.wl.nl(),c=a.length>0,u=c?this.xl:this.Cl;u.begin(),this.Z.ve(this._l),this._l.O({u_characterTexture:n.fontFramebuffer,u_charsetDimensions:[n.textureColumns,n.textureRows],Uk:h.textures[0],Ul:h.textures[1],Um:h.textures[2],Un:[r.cols,r.rows],Uo:[u.width,u.height],Up:this.Z.state.canvasBackgroundColor}),this.Z.Ae(0,0,r.width,r.height),u.end(),c&&this.Ca.kl.cl(this.xl.textures[0],this.Cl,a,this.Cl.width,this.Cl.height,this.Ml),this.zl(),this.Dl(t,e)}zl(){if(this.bl.length!==0)for(const t of this.bl)t.ba(this.Ca,this._l)}Dl(t,e){this.yl.vl({baseTexture:this.Cl.textures[0],targetFramebuffer:t,backgroundColor:e,baseLayer:this.wl,layers:this.bl},this.Ca.Nn)}Xr(){if(!this.Fl)return;const t=this.Ca.Nn;this.Cl.resize(t.width,t.height),this.xl.resize(t.width,t.height),this.wl.Xr(t),this.Ml&&(this.Ml[0].resize(t.width,t.height),this.Ml[1].resize(t.width,t.height));for(const e of this.bl)e.Xr(t);this.yl.Xr(t)}gt(){var t,e,r,n;for(const h of this.bl)h.gt();for(const h of this.Al)h.gt();this.bl.length=0,this.Al.length=0,this.wl.gt(),(t=this.Cl)==null||t.gt(),(e=this.xl)==null||e.gt(),(r=this.Ml)==null||r[0].gt(),(n=this.Ml)==null||n[1].gt(),this.yl.gt()}get all(){return this.bl}get base(){return this.wl}Pl(t){const e={renderer:this.Z,grid:this.Ca.Nn,font:this.Ca.font,filterManager:this.Ca.kl,layerPingPongBuffers:this.Ml,createFramebuffer:(r,n,h=1)=>this.Z.Pe(r,n,h)};t.ol(e)}El(){const t={renderer:this.Z,grid:this.Ca.Nn,font:this.Ca.font,filterManager:this.Ca.kl,layerPingPongBuffers:this.Ml,createFramebuffer:(e,r,n=1)=>this.Z.Pe(e,r,n),externalDrawFramebuffer:this.Ca.ga,externalAsciiFramebuffer:this.Cl};this.wl.ol(t)}$l(t,e){const r=t.indexOf(e);if(r===-1)return!1;const[n]=t.splice(r,1);return n.gt(),!0}Tl(t,e,r){const n=t.indexOf(e);if(n===-1)return!1;t.splice(n,1);const h=Math.max(0,Math.min(t.length,r));return t.splice(h,0,e),!0}Rl(t,e,r){const n=t.indexOf(e);if(n===-1)return!1;const h=t.indexOf(r);return h!==-1&&(t[n]=r,t[h]=e,!0)}}class Jt{constructor(t){l(this,"Z");l(this,"Ll",new Map);l(this,"Ol",new Map);this.Z=t,this.Il()}async Bl(t,e,r={}){const n=Object.entries(r),h=n.length>0?n[0][1][0]:null;let a;if(typeof e=="string"){let u=e;if(e.startsWith("./")||e.startsWith("../")||e.endsWith(".frag")||e.endsWith(".glsl")){const f=await fetch(e);if(!f.ok)throw Error(`Failed to load shader from ${e}: ${f.statusText}`);u=await f.text()}a=this.Z.pe($,u),this.Ol.set(t,a)}else a=e,this.Ol.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.Ll.set(t,c)}Hl(t){const e=this.Ol.get(t);return e&&(e.dispose(),this.Ol.delete(t)),this.Ll.delete(t)}Gl(t){return this.Ll.get(t)}gt(){for(const t of this.Ol.values())t.dispose();this.Ol.clear(),this.Ll.clear()}Il(){this.Bl("invert",`#version 300 es
13
13
  precision highp float;uniform sampler2D u_texture;in vec2 v_uv;out vec4 fragColor;void main(){vec4 A=texture(u_texture,v_uv);fragColor=vec4(1.-A.rgb,A.a);}`,{}),this.Bl("grayscale",`#version 300 es
14
- precision highp float;uniform sampler2D u_texture;uniform float Ud;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),Ud);fragColor=vec4(C,A.a);}`,{Ud:["amount",1]}),this.Bl("sepia",`#version 300 es
15
- precision highp float;uniform sampler2D u_texture;uniform float Ud;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,Ud);fragColor=vec4(C,A.a);}`,{Ud:["amount",1]}),this.Bl("threshold",`#version 300 es
16
- precision highp float;uniform sampler2D u_texture;uniform float Ue;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(Ue,B);fragColor=vec4(vec3(C),A.a);}`,{Ue:["threshold",.5]})}}class $t{constructor(t){l(this,"Z");l(this,"Ol",new Map);l(this,"J");l(this,"fl");l(this,"zc",!1);l(this,"Ql");this.Z=t,this.Ql=new Jt(this.Z),this.J=t.pe($,`#version 300 es
17
- precision highp float;uniform sampler2D u_texture;in vec2 v_uv;out vec4 fragColor;void main(){fragColor=texture(u_texture,v_uv);}`)}async register(t,e,r={}){await this.Ql.Bl(t,e,r)}unregister(t){return this.Ql.Hl(t)??!1}has(t){return this.Ql.Gl(t)!==void 0}yr(t,e){this.zc||(this.fl=[this.Z.Pe(t,e,1,{depth:!1}),this.Z.Pe(t,e,1,{depth:!1})],this.zc=!0)}Nl(t,e,r,n,h){this.fl[0].width===n&&this.fl[0].height===h||(this.fl[0].resize(n,h),this.fl[1].resize(n,h)),this.cl(t,e,r,n,h,this.fl)}cl(t,e,r,n,h,a){if(r.length===0)return void this.jl(t,e,n,h);const c=this.Z.context,u=c.isEnabled(c.BLEND);c.disable(c.BLEND),this.jl(t,a[0],n,h);let f=0;for(let d=0;d<r.length;d++){const g=r[d],v=d===r.length-1,p=f===0?1:0,m=v?e:a[p];this.Xl(g,a[f],m,n,h),v||(f=p)}u&&c.enable(c.BLEND)}Xl(t,e,r,n,h){const a=this.Ql.Gl(t.name);if(!a)return console.warn(`[textmode.js] Unknown filter: "${t.name}". Skipping.`),void this.jl(e.textures[0],r,n,h);const c=this.Yl(t.name,a,n,h),u={renderer:this.Z,gl:this.Z.context,width:n,height:h};r.begin(),this.Z.ve(c),c.O({u_texture:e.textures[0]});const f=a.createUniforms(t.params,u);c.O(f),this.Z.Ae(0,0,n,h),r.end()}Yl(t,e,r,n){let h=this.Ol.get(t);if(!h&&e){const a={renderer:this.Z,gl:this.Z.context,width:r,height:n};h=e.createShader(a),this.Ol.set(t,h)}return h}jl(t,e,r,n){e.begin(),this.Z.ve(this.J),this.J.O({u_texture:t,u_resolution:[r,n]}),this.Z.Ae(0,0,r,n),e.end()}jr(t,e){this.fl&&(this.fl[0].resize(t,e),this.fl[1].resize(t,e))}gt(){for(const t of this.Ol.values())t.dispose();this.Ol.clear(),this.J.dispose(),this.Ql.gt(),this.fl&&(this.fl[0].gt(),this.fl[1].gt()),this.zc=!1}}const Qe=Object.freeze(Object.defineProperty({__proto__:null,FilterRegistry:Jt,TextmodeFilterManager:$t},Symbol.toStringTag,{value:"Module"}));class te extends function(e,...r){return r.reduce((n,h)=>h(n),e)}(class{},Oe,Ie,ze,Ye,je,Ve){constructor(e={}){super();l(this,"Z");l(this,"rr");l(this,"Er");l(this,"Nn");l(this,"ya");l(this,"Xh");l(this,"ma");l(this,"wa");l(this,"Kl");l(this,"ga");l(this,"Gc");l(this,"La");l(this,"Qc");l(this,"Wl");l(this,"kl");l(this,"Zl",[]);l(this,"ql");l(this,"Vl");l(this,"Jl");l(this,"tu",!1);l(this,"su",!1);l(this,"iu",!1);l(this,"eu",!1);l(this,"ru",()=>{});l(this,"tl",()=>{});l(this,"nu",()=>{});l(this,"hu");l(this,"ou");l(this,"Lr",!1);l(this,"au");l(this,"_a",new Set);this.Jl=new Ge(this),this.Lr=e.overlay??!1,this.Er=new Zt(e),this.Z=new Ee(this.Er.Xr()),this.rr=new pt(this.Z,e.fontSize??16),this.ya=new Ot(e.frameRate??60),this.Kl=new Ht(this,e.loadingScreen,this.Er.Nr()),this.Kl.Bc(()=>{this.ya.Gn=0,this.eu=!0}),this.Xh=new It(this.Er),this.ma=new Yt(this.Er,this.Xh),this.wa=new zt,this.Gc=this.Z.pe($,`#version 300 es
18
- precision highp float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D Ui;uniform sampler2D Uj;uniform sampler2D Uh;uniform vec2 Uk;uniform vec2 Ul;uniform vec4 Um;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/Ul;vec2 F=E*Uk;vec2 G=floor(F);vec2 H=(G+0.5)/Uk;vec4 I=texture(Ui,H);vec4 J=texture(Uj,H);vec4 K=texture(Uh,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(Um,J,J.a);fragColor=mix(d,I,c);}`),this.Wl=new qt(this),this.kl=new $t(this.Z),this.Kl.kn(),this.cu(e)}async cu(e){await Promise.all([this.rr.yr(e.fontSource),this.Kl.yr(e.fontSource)]);const r=this.rr.maxGlyphDimensions;this.Nn=new At(this.Er.canvas,r.width,r.height),this.Xh.yr(this.Nn),this.ma.yr(this.Nn),this.ga=this.Z.Pe(this.Nn.cols,this.Nn.rows,3),this.La=this.Z.Pe(this.Nn.width,this.Nn.height,1),this.ql=this.Z.Pe(this.Er.width,this.Er.height,1),this.Vl=this.Z.Pe(this.Er.width,this.Er.height,1),this.kl.yr(this.Er.width,this.Er.height),this.Wl.yr(),this.Lr&&(this.au=G.Cn(this.Z,this.rr,this.Er.targetCanvas,this.Nn.cols,this.Nn.rows),this.pa(this.au)),this.Qc=this.Z.pe($,`#version 300 es
19
- 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.lu(),this.ya.kn(()=>this.ba()),await this.Jl.$a(e.plugins??[]);try{await this.ru(),this.Kl.ac()}catch(n){console.error("Error during setup:",n),this.Kl.error(n)}}lu(){this.hu=()=>{this.Lr&&this.resizeCanvas(this.Er.targetCanvas.width,this.Er.targetCanvas.height),this.nu()},window.addEventListener("resize",this.hu),this.Xh.dh(),this.ma.dh(),this.wa.dh(),window.addEventListener("blur",()=>{this.wa.jh()}),this.Lr&&(this.ou=new ResizeObserver(()=>{this.resizeCanvas(this.Er.targetCanvas.width,this.Er.targetCanvas.height)}),this.ou.observe(this.Er.targetCanvas))}ba(){if(!this.Kl.rc&&this.eu){this.su=!0;try{this.ya.In(),this.ya.Qn(),this.Lr&&Ft(this.Z.context,this.au.texture,this.Er.targetCanvas),this.Jl.Sa(),this.Z.state.qt(),this.ga.begin(),this.Wl.base.rl()?this.Wl.base.hl(this):this.tl(),this.ga.end();const e=[...this.Z.state.canvasBackgroundColor];this.Wl.Sl(this.La,e),this.ql.begin(),this.Z.bi(...e),this.Z.ve(this.Qc),this.Qc.O({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.Ae(this.Nn.offsetX,this.Nn.offsetY,this.Nn.width,this.Nn.height),this.ql.end();let r=this.ql.textures[0];this.Zl.length>0&&(this.kl.Nl(this.ql.textures[0],this.Vl,this.Zl,this.Er.width,this.Er.height),r=this.Vl.textures[0],this.Zl=[]),this.Z.bi(0,0,0,0),this.Z.ve(this.Qc),this.Qc.O({U0:r,U1:[this.Er.width,this.Er.height],U2:[0,0],U3:[this.Er.width,this.Er.height]}),this.Z.Ae(0,0,this.Er.width,this.Er.height),this.Jl.za()}finally{this.su=!1,this.tu&&!this.iu&&this.uu()}}}resizeCanvas(e,r){var n,h,a,c;this.Er.jr(e,r),this.Kl.Nc(this.Er.Nr()),this.Nn.ti(),this.Kl.jr(),this.ga.resize(this.Nn.cols,this.Nn.rows),this.La.resize(this.Nn.width,this.Nn.height),(n=this.ql)==null||n.resize(this.Er.width,this.Er.height),(h=this.Vl)==null||h.resize(this.Er.width,this.Er.height),(a=this.kl)==null||a.jr(this.Er.width,this.Er.height),(c=this.Wl)==null||c.jr(),this.Z.Re(),this.Xh.fh(),this.ma.fh(),this.ba()}destroy(){this.iu||this.tu||(this.tu=!0,this.ya.Dn(),this.su||this.uu())}uu(){var e,r,n,h,a,c;this.tu=!1,this.Kl.gt(),this.Jl.Da(),window.removeEventListener("resize",this.hu),(e=this.ou)==null||e.disconnect(),this.Xh.bh(),this.ma.bh(),this.wa.bh(),this.ga.gt(),this.Gc.dispose(),(r=this.Wl)==null||r.gt(),(n=this.kl)==null||n.gt(),(h=this.ql)==null||h.gt(),(a=this.Vl)==null||a.gt(),this.rr.gt(),this.Z.gt(),this.La.gt(),this.Qc.dispose(),(c=this.au)==null||c.gt(),this.Er.gt(),this.iu=!0}setup(e){this.ru=e}draw(e){this.tl=e}windowResized(e){this.nu=e}get grid(){return this.Nn}get font(){return this.rr}get width(){return this.Er.width}get height(){return this.Er.height}get canvas(){return this.Er.canvas}get drawFramebuffer(){return this.ga}get isDisposed(){return this.iu}get overlay(){return this.au}get loading(){return this.Kl}get layers(){return this.Wl}get filters(){return this.kl}filter(e,r){this.Zl.push({name:e,params:r})}pa(e){this._a.has(e)||this._a.add(e)}}class at{constructor(){}static create(t={}){return new te(t)}static setErrorLevel(t){ut._(t)}static get version(){return"0.7.0-beta.3"}}let xt=null;const Ke={id:"brightness",createShader:({gl:o})=>(xt||(xt=new W(o,et,`#version 300 es
20
- 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));}`)),xt),createUniforms:({source:o})=>o.createBaseConversionUniforms()},qe=Object.freeze(Object.defineProperty({__proto__:null,LoadingPhaseTracker:jt,LoadingScreenManager:Ht,LoadingScreenStateMachine:Vt,LoadingScreenTransition:Gt,resolveColorInputs:Wt,resolveDefaultPalette:kt,resolveTheme:wt},Symbol.toStringTag,{value:"Module"})),Je=Object.freeze(Object.defineProperty({__proto__:null,TextmodeFont:pt,TextmodeImage:G,TextmodeVideo:ot},Symbol.toStringTag,{value:"Module"})),$e=Object.freeze(Object.defineProperty({__proto__:null,keyboard:Be,mouse:Ze,touch:_e},Symbol.toStringTag,{value:"Module"})),ti=Object.freeze(Object.defineProperty({__proto__:null,LayerCompositor:Kt,TextmodeLayer:bt,TextmodeLayerManager:qt},Symbol.toStringTag,{value:"Module"}));Bt(Ke);const ei=at.create,ii=at.setErrorLevel,si=at.version;T.TextmodeCanvas=Zt,T.TextmodeColor=U,T.TextmodeErrorLevel=O,T.TextmodeFramebuffer=Y,T.TextmodeGrid=At,T.Textmodifier=te,T.create=ei,T.filters=Qe,T.getConversionStrategy=_t,T.input=$e,T.layering=ti,T.loadables=Je,T.loading=qe,T.registerConversionStrategy=Bt,T.setErrorLevel=ii,T.textmode=at,T.unregisterConversionStrategy=function(o){yt.delete(o)},T.version=si,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):i((s=typeof globalThis<"u"?globalThis:s||self).textmode={});
14
+ precision highp float;uniform sampler2D u_texture;uniform float U5;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),U5);fragColor=vec4(C,A.a);}`,{U5:["amount",1]}),this.Bl("sepia",`#version 300 es
15
+ precision highp float;uniform sampler2D u_texture;uniform float U5;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,U5);fragColor=vec4(C,A.a);}`,{U5:["amount",1]}),this.Bl("threshold",`#version 300 es
16
+ precision highp float;uniform sampler2D u_texture;uniform float U8;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(U8,B);fragColor=vec4(vec3(C),A.a);}`,{U8:["threshold",.5]})}}class $t{constructor(t){l(this,"Z");l(this,"Ol",new Map);l(this,"J");l(this,"fl");l(this,"zc",!1);l(this,"Ql");this.Z=t,this.Ql=new Jt(this.Z),this.J=t.pe($,`#version 300 es
17
+ precision highp float;uniform sampler2D u_texture;in vec2 v_uv;out vec4 fragColor;void main(){fragColor=texture(u_texture,v_uv);}`)}async register(t,e,r={}){await this.Ql.Bl(t,e,r)}unregister(t){return this.Ql.Hl(t)??!1}has(t){return this.Ql.Gl(t)!==void 0}yr(t,e){this.zc||(this.fl=[this.Z.Pe(t,e,1,{depth:!1}),this.Z.Pe(t,e,1,{depth:!1})],this.zc=!0)}Nl(t,e,r,n,h){this.fl[0].width===n&&this.fl[0].height===h||(this.fl[0].resize(n,h),this.fl[1].resize(n,h)),this.cl(t,e,r,n,h,this.fl)}cl(t,e,r,n,h,a){if(r.length===0)return void this.Xl(t,e,n,h);const c=this.Z.context,u=c.isEnabled(c.BLEND);c.disable(c.BLEND),this.Xl(t,a[0],n,h);let f=0;for(let d=0;d<r.length;d++){const g=r[d],v=d===r.length-1,p=f===0?1:0,m=v?e:a[p];this.Yl(g,a[f],m,n,h),v||(f=p)}u&&c.enable(c.BLEND)}Yl(t,e,r,n,h){const a=this.Ql.Gl(t.name);if(!a)return console.warn(`[textmode.js] Unknown filter: "${t.name}". Skipping.`),void this.Xl(e.textures[0],r,n,h);const c=this.jl(t.name,a,n,h),u={renderer:this.Z,gl:this.Z.context,width:n,height:h};r.begin(),this.Z.ve(c),c.O({u_texture:e.textures[0]});const f=a.createUniforms(t.params,u);c.O(f),this.Z.Ae(0,0,n,h),r.end()}jl(t,e,r,n){let h=this.Ol.get(t);if(!h&&e){const a={renderer:this.Z,gl:this.Z.context,width:r,height:n};h=e.createShader(a),this.Ol.set(t,h)}return h}Xl(t,e,r,n){e.begin(),this.Z.ve(this.J),this.J.O({u_texture:t,u_resolution:[r,n]}),this.Z.Ae(0,0,r,n),e.end()}Xr(t,e){this.fl&&(this.fl[0].resize(t,e),this.fl[1].resize(t,e))}gt(){for(const t of this.Ol.values())t.dispose();this.Ol.clear(),this.J.dispose(),this.Ql.gt(),this.fl&&(this.fl[0].gt(),this.fl[1].gt()),this.zc=!1}}const Qe=Object.freeze(Object.defineProperty({__proto__:null,FilterRegistry:Jt,TextmodeFilterManager:$t},Symbol.toStringTag,{value:"Module"}));class te extends function(e,...r){return r.reduce((n,h)=>h(n),e)}(class{},Xe,Ie,Ye,ze,Ve,Ge){constructor(e={}){super();l(this,"Z");l(this,"rr");l(this,"Er");l(this,"Nn");l(this,"ya");l(this,"Yh");l(this,"ma");l(this,"wa");l(this,"Kl");l(this,"ga");l(this,"Gc");l(this,"La");l(this,"Qc");l(this,"Wl");l(this,"kl");l(this,"Zl",[]);l(this,"ql");l(this,"Vl");l(this,"Jl");l(this,"tu",!1);l(this,"su",!1);l(this,"iu",!1);l(this,"eu",!1);l(this,"ru",()=>{});l(this,"tl",()=>{});l(this,"nu",()=>{});l(this,"hu");l(this,"ou");l(this,"Lr",!1);l(this,"au");l(this,"_a",new Set);this.Jl=new ke(this),this.Lr=e.overlay??!1,this.Er=new Zt(e),this.Z=new Ee(this.Er.Yr()),this.rr=new pt(this.Z,e.fontSize??16),this.ya=new Xt(e.frameRate??60),this.Kl=new jt(this,e.loadingScreen,this.Er.Nr()),this.Kl.Bc(()=>{this.ya.Gn=0,this.eu=!0}),this.Yh=new It(this.Er),this.ma=new zt(this.Er,this.Yh),this.wa=new Yt,this.Gc=this.Z.pe($,`#version 300 es
18
+ precision highp float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D Ul;uniform sampler2D Um;uniform sampler2D Uk;uniform vec2 Un;uniform vec2 Uo;uniform vec4 Up;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/Uo;vec2 F=E*Un;vec2 G=floor(F);vec2 H=(G+0.5)/Un;vec4 I=texture(Ul,H);vec4 J=texture(Um,H);vec4 K=texture(Uk,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(Up,J,J.a);fragColor=mix(d,I,c);}`),this.Wl=new qt(this),this.kl=new $t(this.Z),this.Kl.kn(),this.cu(e)}async cu(e){await Promise.all([this.rr.yr(e.fontSource),this.Kl.yr(e.fontSource)]);const r=this.rr.maxGlyphDimensions;this.Nn=new At(this.Er.canvas,r.width,r.height),this.Yh.yr(this.Nn),this.ma.yr(this.Nn),this.ga=this.Z.Pe(this.Nn.cols,this.Nn.rows,3),this.La=this.Z.Pe(this.Nn.width,this.Nn.height,1),this.ql=this.Z.Pe(this.Er.width,this.Er.height,1),this.Vl=this.Z.Pe(this.Er.width,this.Er.height,1),this.kl.yr(this.Er.width,this.Er.height),this.Wl.yr(),this.Lr&&(this.au=k.Cn(this.Z,this.rr,this.Er.targetCanvas,this.Nn.cols,this.Nn.rows),this.pa(this.au)),this.Qc=this.Z.pe($,`#version 300 es
19
+ 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.lu(),this.ya.kn(()=>this.ba()),await this.Jl.$a(e.plugins??[]);try{await this.ru(),this.Kl.ac()}catch(n){console.error("Error during setup:",n),this.Kl.error(n)}}lu(){this.hu=()=>{this.Lr&&this.resizeCanvas(this.Er.targetCanvas.width,this.Er.targetCanvas.height),this.nu()},window.addEventListener("resize",this.hu),this.Yh.dh(),this.ma.dh(),this.wa.dh(),window.addEventListener("blur",()=>{this.wa.Xh()}),this.Lr&&(this.ou=new ResizeObserver(()=>{this.resizeCanvas(this.Er.targetCanvas.width,this.Er.targetCanvas.height)}),this.ou.observe(this.Er.targetCanvas))}ba(){if(!this.Kl.rc&&this.eu){this.su=!0;try{this.ya.In(),this.ya.Qn(),this.Lr&&Ft(this.Z.context,this.au.texture,this.Er.targetCanvas),this.Jl.Sa(),this.Z.state.qt(),this.ga.begin(),this.Wl.base.rl()?this.Wl.base.hl(this):this.tl(),this.ga.end();const e=[...this.Z.state.canvasBackgroundColor];this.Wl.Sl(this.La,e),this.ql.begin(),this.Z.bi(...e),this.Z.ve(this.Qc),this.Qc.O({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.Ae(this.Nn.offsetX,this.Nn.offsetY,this.Nn.width,this.Nn.height),this.ql.end();let r=this.ql.textures[0];this.Zl.length>0&&(this.kl.Nl(this.ql.textures[0],this.Vl,this.Zl,this.Er.width,this.Er.height),r=this.Vl.textures[0],this.Zl=[]),this.Z.bi(0,0,0,0),this.Z.ve(this.Qc),this.Qc.O({U0:r,U1:[this.Er.width,this.Er.height],U2:[0,0],U3:[this.Er.width,this.Er.height]}),this.Z.Ae(0,0,this.Er.width,this.Er.height),this.Jl.za()}finally{this.su=!1,this.tu&&!this.iu&&this.uu()}}}resizeCanvas(e,r){var n,h,a,c;this.Er.Xr(e,r),this.Kl.Nc(this.Er.Nr()),this.Nn.ti(),this.Kl.Xr(),this.ga.resize(this.Nn.cols,this.Nn.rows),this.La.resize(this.Nn.width,this.Nn.height),(n=this.ql)==null||n.resize(this.Er.width,this.Er.height),(h=this.Vl)==null||h.resize(this.Er.width,this.Er.height),(a=this.kl)==null||a.Xr(this.Er.width,this.Er.height),(c=this.Wl)==null||c.Xr(),this.Z.Re(),this.Yh.fh(),this.ma.fh(),this.ba()}destroy(){this.iu||this.tu||(this.tu=!0,this.ya.Dn(),this.su||this.uu())}uu(){var e,r,n,h,a,c;this.tu=!1,this.Kl.gt(),this.Jl.Da(),window.removeEventListener("resize",this.hu),(e=this.ou)==null||e.disconnect(),this.Yh.bh(),this.ma.bh(),this.wa.bh(),this.ga.gt(),this.Gc.dispose(),(r=this.Wl)==null||r.gt(),(n=this.kl)==null||n.gt(),(h=this.ql)==null||h.gt(),(a=this.Vl)==null||a.gt(),this.rr.gt(),this.Z.gt(),this.La.gt(),this.Qc.dispose(),(c=this.au)==null||c.gt(),this.Er.gt(),this.iu=!0}setup(e){this.ru=e}draw(e){this.tl=e}windowResized(e){this.nu=e}get grid(){return this.Nn}get font(){return this.rr}get width(){return this.Er.width}get height(){return this.Er.height}get canvas(){return this.Er.canvas}get drawFramebuffer(){return this.ga}get isDisposed(){return this.iu}get overlay(){return this.au}get loading(){return this.Kl}get layers(){return this.Wl}get filters(){return this.kl}filter(e,r){this.Zl.push({name:e,params:r})}pa(e){this._a.has(e)||this._a.add(e)}}class at{constructor(){}static create(t={}){return new te(t)}static setErrorLevel(t){ut._(t)}static get version(){return"0.7.0"}}let xt=null;const Ke={id:"brightness",createShader:({gl:o})=>(xt||(xt=new H(o,et,`#version 300 es
20
+ 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));}`)),xt),createUniforms:({source:o})=>o.createBaseConversionUniforms()},qe=Object.freeze(Object.defineProperty({__proto__:null,LoadingPhaseTracker:Vt,LoadingScreenManager:jt,LoadingScreenStateMachine:Gt,LoadingScreenTransition:kt,resolveColorInputs:Ht,resolveDefaultPalette:Wt,resolveTheme:wt},Symbol.toStringTag,{value:"Module"})),Je=Object.freeze(Object.defineProperty({__proto__:null,TextmodeFont:pt,TextmodeImage:k,TextmodeVideo:ot},Symbol.toStringTag,{value:"Module"})),$e=Object.freeze(Object.defineProperty({__proto__:null,keyboard:Be,mouse:Ze,touch:_e},Symbol.toStringTag,{value:"Module"})),ti=Object.freeze(Object.defineProperty({__proto__:null,LayerCompositor:Kt,TextmodeLayer:bt,TextmodeLayerManager:qt},Symbol.toStringTag,{value:"Module"}));Bt(Ke);const ei=at.create,ii=at.setErrorLevel,si=at.version;T.TextmodeCanvas=Zt,T.TextmodeColor=U,T.TextmodeErrorLevel=X,T.TextmodeFramebuffer=z,T.TextmodeGrid=At,T.Textmodifier=te,T.create=ei,T.filters=Qe,T.getConversionStrategy=_t,T.input=$e,T.layering=ti,T.loadables=Je,T.loading=qe,T.registerConversionStrategy=Bt,T.setErrorLevel=ii,T.textmode=at,T.unregisterConversionStrategy=function(o){yt.delete(o)},T.version=si,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):i((s=typeof globalThis<"u"?globalThis:s||self).textmode={});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "textmode.js",
3
- "version": "0.7.0-beta.3",
3
+ "version": "0.7.0",
4
4
  "description": "textmode.js is a lightweight creative coding library for creating real-time ASCII art on the web.",
5
5
  "type": "module",
6
6
  "types": "./dist/types/index.d.ts",