textmode.js 0.4.1-beta.1 → 0.6.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/textmode.esm.js +2578 -1861
- package/dist/textmode.esm.min.js +2578 -1861
- package/dist/textmode.umd.js +11 -8
- package/dist/textmode.umd.min.js +11 -8
- package/dist/types/Textmode.d.ts +13 -22
- package/dist/types/errors/ErrorHandler.d.ts +6 -1
- package/dist/types/index.d.ts +8 -6
- package/dist/types/rendering/index.d.ts +3 -3
- package/dist/types/rendering/webgl/batching/DrawQueue.d.ts +89 -0
- package/dist/types/rendering/webgl/{VAOManager.d.ts → batching/GeometryAttributeCache.d.ts} +4 -4
- package/dist/types/rendering/webgl/batching/InstanceAttributeBinder.d.ts +87 -0
- package/dist/types/rendering/webgl/{InstanceBatch.d.ts → batching/InstanceBatch.d.ts} +28 -37
- package/dist/types/rendering/webgl/batching/InstanceBuffer.d.ts +78 -0
- package/dist/types/rendering/webgl/{InstanceData.d.ts → batching/InstanceData.d.ts} +11 -18
- package/dist/types/rendering/webgl/batching/InstanceWriter.d.ts +70 -0
- package/dist/types/rendering/webgl/{Framebuffer.d.ts → core/Framebuffer.d.ts} +37 -39
- package/dist/types/rendering/webgl/core/Renderer.d.ts +64 -0
- package/dist/types/rendering/webgl/{Shader.d.ts → core/Shader.d.ts} +2 -23
- package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +103 -0
- package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +210 -0
- package/dist/types/rendering/webgl/geometries/{Arc.d.ts → 2d/Arc.d.ts} +5 -4
- package/dist/types/rendering/webgl/geometries/{BezierCurve.d.ts → 2d/BezierCurve.d.ts} +5 -4
- package/dist/types/rendering/webgl/geometries/{Ellipse.d.ts → 2d/Ellipse.d.ts} +6 -5
- package/dist/types/rendering/webgl/geometries/{Line.d.ts → 2d/Line.d.ts} +5 -4
- package/dist/types/rendering/webgl/geometries/{Rectangle.d.ts → 2d/Rectangle.d.ts} +5 -4
- package/dist/types/rendering/webgl/geometries/{Triangle.d.ts → 2d/Triangle.d.ts} +5 -4
- package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +30 -26
- package/dist/types/rendering/webgl/geometries/immediate/ImmediateQuad.d.ts +33 -0
- package/dist/types/rendering/webgl/geometries/index.d.ts +6 -6
- package/dist/types/rendering/webgl/geometries/utils/GeometryDescriptors.d.ts +31 -0
- package/dist/types/rendering/webgl/geometries/utils/GeometryGenerator.d.ts +16 -0
- package/dist/types/rendering/webgl/index.d.ts +15 -14
- package/dist/types/rendering/webgl/materials/Material.d.ts +26 -0
- package/dist/types/rendering/webgl/materials/MaterialManager.d.ts +63 -0
- package/dist/types/rendering/webgl/materials/index.d.ts +2 -0
- package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +63 -0
- package/dist/types/rendering/webgl/pipeline/index.d.ts +7 -0
- package/dist/types/rendering/webgl/state/RenderState.d.ts +143 -0
- package/dist/types/rendering/webgl/types/DrawCommand.d.ts +5 -3
- package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +10 -10
- package/dist/types/rendering/webgl/types/RenderTypes.d.ts +1 -1
- package/dist/types/rendering/webgl/utils/GLUtils.d.ts +45 -0
- package/dist/types/rendering/webgl/utils/hash.d.ts +118 -0
- package/dist/types/textmode/AnimationController.d.ts +11 -21
- package/dist/types/textmode/Canvas.d.ts +10 -2
- package/dist/types/textmode/Grid.d.ts +2 -0
- package/dist/types/textmode/TextmodeColor.d.ts +57 -0
- package/dist/types/textmode/Textmodifier.d.ts +32 -213
- package/dist/types/textmode/interfaces/ITextmodifier.d.ts +275 -0
- package/dist/types/textmode/interfaces/index.d.ts +1 -0
- package/dist/types/textmode/loadables/TextmodeImage.d.ts +47 -0
- package/dist/types/textmode/loadables/TextmodeSource.d.ts +130 -0
- package/dist/types/textmode/loadables/TextmodeVideo.d.ts +265 -0
- package/dist/types/textmode/{font → loadables/font}/CharacterColorMapper.d.ts +1 -1
- package/dist/types/textmode/{font → loadables/font}/CharacterExtractor.d.ts +0 -10
- package/dist/types/textmode/{font → loadables/font}/TextmodeFont.d.ts +9 -3
- package/dist/types/textmode/{font → loadables/font}/TextureAtlas.d.ts +4 -11
- package/dist/types/textmode/{font → loadables/font}/typr/types.d.ts +0 -6
- package/dist/types/textmode/loadables/index.d.ts +5 -0
- package/dist/types/textmode/loading/LoadingPhaseTracker.d.ts +20 -0
- package/dist/types/textmode/loading/LoadingScreenManager.d.ts +211 -0
- package/dist/types/textmode/loading/LoadingScreenState.d.ts +22 -0
- package/dist/types/textmode/loading/LoadingScreenTheme.d.ts +26 -0
- package/dist/types/textmode/loading/LoadingScreenTransition.d.ts +17 -0
- package/dist/types/textmode/loading/index.d.ts +6 -0
- package/dist/types/textmode/loading/templates/SpinnerTemplate.d.ts +2 -0
- package/dist/types/textmode/loading/templates/index.d.ts +1 -0
- package/dist/types/textmode/loading/types.d.ts +251 -0
- package/dist/types/textmode/managers/KeyboardManager.d.ts +2 -3
- package/dist/types/textmode/managers/MouseManager.d.ts +1 -1
- package/dist/types/textmode/{plugins → managers}/PluginManager.d.ts +18 -16
- package/dist/types/textmode/managers/TouchManager.d.ts +0 -2
- package/dist/types/textmode/mixins/AnimationMixin.d.ts +2 -122
- package/dist/types/textmode/mixins/FontMixin.d.ts +2 -77
- package/dist/types/textmode/mixins/KeyboardMixin.d.ts +3 -85
- package/dist/types/textmode/mixins/MouseMixin.d.ts +3 -130
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +2 -749
- package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +2 -44
- package/dist/types/textmode/mixins/TouchMixin.d.ts +2 -187
- package/dist/types/textmode/mixins/index.d.ts +8 -8
- package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +167 -0
- package/dist/types/textmode/mixins/interfaces/IFontMixin.d.ts +46 -0
- package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +235 -0
- package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +457 -0
- package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +1124 -0
- package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +186 -0
- package/dist/types/textmode/types.d.ts +49 -0
- package/dist/types/textmode/utils/cssColor.d.ts +8 -0
- package/dist/types/utils/array.d.ts +34 -0
- package/dist/types/utils/math.d.ts +69 -0
- package/package.json +1 -1
- package/dist/types/rendering/webgl/DrawQueue.d.ts +0 -30
- package/dist/types/rendering/webgl/RenderPipeline.d.ts +0 -30
- package/dist/types/rendering/webgl/RenderState.d.ts +0 -73
- package/dist/types/rendering/webgl/Renderer.d.ts +0 -158
- package/dist/types/rendering/webgl/ShaderManager.d.ts +0 -66
- package/dist/types/rendering/webgl/geometries/NoiseGrid.d.ts +0 -1
- package/dist/types/textmode/TextmodeImage.d.ts +0 -161
- package/dist/types/textmode/mixins/ShaderMixin.d.ts +0 -1
- /package/dist/types/rendering/webgl/{StateCache.d.ts → utils/ViewportCache.d.ts} +0 -0
- /package/dist/types/textmode/{font → loadables/font}/MetricsCalculator.d.ts +0 -0
- /package/dist/types/textmode/{font → loadables/font}/index.d.ts +0 -0
- /package/dist/types/textmode/{font → loadables/font}/types.d.ts +0 -0
- /package/dist/types/textmode/{font → loadables/font}/typr/Typr.d.ts +0 -0
- /package/dist/types/textmode/{font → loadables/font}/utils/FontTableReader.d.ts +0 -0
- /package/dist/types/textmode/{font → loadables/font}/utils/index.d.ts +0 -0
package/dist/textmode.umd.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
var
|
|
1
|
+
var We=Object.defineProperty;var Ze=(F,x,X)=>x in F?We(F,x,{enumerable:!0,configurable:!0,writable:!0,value:X}):F[x]=X;var l=(F,x,X)=>Ze(F,typeof x!="symbol"?x+"":x,X);var s,e;s=this,e=function(F){class x extends Error{constructor(t,i={}){super(x.i(t,i)),this.name="TextmodeError"}static i(t,i){return`${t}${i&&Object.keys(i).length>0?`
|
|
2
2
|
|
|
3
|
-
📋 Context:`+Object.entries(i).map(([r,
|
|
4
|
-
- ${r}: ${
|
|
3
|
+
📋 Context:`+Object.entries(i).map(([r,h])=>`
|
|
4
|
+
- ${r}: ${x.o(h)}`).join(""):""}
|
|
5
5
|
|
|
6
6
|
${"↓".repeat(24)}
|
|
7
|
-
`}static o(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="number"||typeof t=="boolean")return t+"";if(Array.isArray(t))return t.length===0?"[]":t.length<=5?`[${t.map(i=>
|
|
8
|
-
in vec2
|
|
9
|
-
precision highp float;in vec2 v_uv;in vec3 v_character;in vec4 v_primaryColor;in vec4 v_secondaryColor;in vec2 v_rotation;in vec3 v_transform;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){o_character=vec4(v_character,1.);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.,1.);o_transform=vec4(v_transform,1.);}`),this.Qt=new z(this.gt,j,`#version 300 es
|
|
10
|
-
precision highp float;in vec2 v_uv;uniform sampler2D Ue;uniform sampler2D Uf;uniform sampler2D Ug;uniform sampler2D Uh;uniform sampler2D Ui;uniform vec2 Uj;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){vec2 A=vec2(v_uv.x,1.-v_uv.y);vec2 B=A*Uj;vec2 C=(floor(B)+0.5f)/Uj;vec4 D=texture(Ue,C);vec4 E=texture(Uf,C);if(E.a==0.){discard;}vec4 F=texture(Ug,C);vec4 G=texture(Uh,C);vec4 H=texture(Ui,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;o_rotation=G;o_transform=H;}`),this.ts=new z(this.gt,rt,"precision mediump float;uniform sampler2D U0;uniform vec2 U1;uniform sampler2D U3;uniform sampler2D U4;uniform sampler2D U5;uniform sampler2D U2;uniform sampler2D U6;uniform vec2 U7;uniform vec2 U8;mat2 A(float B){float C=sin(B);float D=cos(B);return mat2(D,-C,C,D);}void main(){vec2 E=gl_FragCoord.xy/U8;vec2 F=E*U7;vec2 G=floor(F);vec2 H=(G+0.5)/U7;vec4 I=texture2D(U3,H);vec4 J=texture2D(U4,H);vec4 K=texture2D(U5,H);bool L=K.r>0.5;bool M=K.g>0.5;bool N=K.b>0.5;vec4 O=texture2D(U2,H);int P=int(O.r*255.+0.5)+int(O.g*255.+0.5)*256;int Q=int(mod(float(P),U1.x));int R=P/int(U1.x);float S=(U1.y-1.)-float(R);vec2 T=vec2(float(Q),S)/U1;vec4 U=texture2D(U6,H);float V=U.r*255.+U.g;float W=-(V*360./255.)*0.017453292;vec2 X=fract(F)-0.5;if(M)X.x=-X.x;if(N)X.y=-X.y;X=A(W)*X+0.5;vec2 Y=1./U1;vec2 Z=T+X*Y;vec2 a=T+Y;if(any(lessThan(Z,T))||any(greaterThan(Z,a))){gl_FragColor=L?I:J;return;}vec4 b=texture2D(U0,Z);if(L)b.rgb=1.-b.rgb;gl_FragColor=mix(J,I,b);}"),this.ss=new z(this.gt,j,`#version 300 es
|
|
11
|
-
precision highp float;in vec2 v_uv;uniform sampler2D Uk;uniform bool Ul;uniform bool Um;uniform bool Un;uniform vec2 Uo;uniform bool Up;uniform vec4 Uq;uniform bool Ur;uniform vec4 Us;uniform vec4 Ut;uniform int Uu;uniform vec3 Uv[64];layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;float A(vec3 B){return dot(B,vec3(0.299f,0.587f,0.114f));}void main(){vec2 C=vec2(v_uv.x,1.0f-v_uv.y);vec4 D=texture(Uk,C);float E=A(D.rgb);if(Uu>0){float F=float(Uu);float G=clamp(E*(F-1.0f),0.0f,F-1.0f);int H=int(floor(G+0.5f));vec3 I=Uv[H];o_character=vec4(I,1.0f);}else{o_character=vec4(E,0.0f,0.0f,1.0f);}vec4 J=Up?Uq:D;vec4 K=Ur?Us:D;if(D.a<0.01f){J=Ut;K=Ut;}else{}o_primaryColor=vec4(J);o_secondaryColor=vec4(K);o_rotation=vec4(Uo.xy,0.0f,1.0f);o_transform=vec4(float(Ul),float(Um),float(Un),1.0f);}`)}es(){return this.Qt}Pt(){return this.Jt}rs(){return this.ts}ns(){return this.ss}hs(t){return new z(this.gt,j,t)}cs(t,i){return new z(this.gt,t,i)}Dt(){this.Qt.Dt(),this.Jt.Dt(),this.ts.Dt(),this.ss.Dt()}}var E=(l=>(l.RECTANGLE="rectangle",l.LINE="line",l.ELLIPSE="ellipse",l.ARC="arc",l.TRIANGLE="triangle",l.BEZIER_CURVE="bezier_curve",l.CUSTOM="custom",l))(E||{});class At{constructor(t){c(this,"gt");c(this,"ls",new Map);this.gt=t}us(t,i,r,n){const o=this.gt;let h=this.ls.get(t);h||(h=new Map,this.ls.set(t,h));let a=h.get(i)||null;if(!a){a=o.createVertexArray(),h.set(i,a),o.bindVertexArray(a),o.bindBuffer(o.ARRAY_BUFFER,n);const u=o.getAttribLocation(t,"a_position");u!==-1&&(o.enableVertexAttribArray(u),o.vertexAttribPointer(u,r.ds.fs.size,o.FLOAT,!1,r.ps,r.ds.fs.offset),o.vertexAttribDivisor(u,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,r.ds._s.size,o.FLOAT,!1,r.ps,r.ds._s.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(a)}vs(){this.gt.bindVertexArray(null)}Dt(){for(const[,t]of this.ls)for(const[,i]of t)i&&this.gt.deleteVertexArray(i)}}class pt{constructor(t,i){c(this,"gs");c(this,"gt");c(this,"xt");c(this,"As",null);c(this,"ws",null);this.gt=t,this.gs=new At(t),this.xt=i}Cs(t,i,r){const{shader:n}=t,o=k(this.gt)||this.gt.getParameter(this.gt.VIEWPORT);n.Wt({U9:o[2]/o[3],Uw:[o[2],o[3]]});const h=f=>{if(!f||!f.bs())return;const g=f.unitGeometry,d=f.unitBuffer;try{this.gs.us(n.Zt,f.type+"",g,d),f.batch.Ms(n),f.batch.Fs(g.Rs,g.zs)}finally{f.batch.Ts(n),this.gs.vs(),f.Ps()}};let a=null,u=null;for(const f of i){if(f.type===E.CUSTOM){u&&(h(u),a=null,u=null),this.Ss(t,f.params,f.state,r.get(E.RECTANGLE));continue}a!==null&&f.type!==a&&(h(u),a=null,u=null);let g=u;g&&f.type===a||(g=r.get(f.type)||null,u=g,a=f.type),g&&g.$s(f.params,f.state)}h(u)}Ss(t,i,r,n){const{x:o,y:h,width:a,height:u,shader:f,uniforms:g}=i,d=this.Es(Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)));d.begin(),this.Ds(n,f,g,0,0,d.width,d.height,{}),d.end();const p=this.ks(),y={Ue:d.textures[0],Uf:d.textures[1],Ug:d.textures[2],Uh:d.textures[3],Ui:d.textures[4],Uj:[d.width,d.height]};this.Ds(n,p,y,Math.floor(o),Math.floor(h),Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)),r),t.shader.Nt()}Ds(t,i,r,n,o,h,a,u){i.Nt(),i.Wt(r);const f=this.gt.getParameter(this.gt.VIEWPORT);if(i.Wt({U9:f[2]/f[3],Uw:[f[2],f[3]]}),t.Ps(),t.$s({x:n,y:o,width:h,height:a},u),t.bs()){const g=t.unitGeometry,d=t.unitBuffer;try{this.gs.us(i.Zt,t.type+"",g,d),t.batch.Ms(i),t.batch.Fs(g.Rs,g.zs)}finally{t.batch.Ts(i),this.gs.vs(),t.Ps()}}}ks(){return this.xt.es()}Es(t,i){return this.As&&this.ws&&this.ws.w===t&&this.ws.h===i||(this.As&&this.As.Dt(),this.As=new K(this.gt,t,i,5),this.ws={w:t,h:i}),this.As}Dt(){this.gs.Dt(),this.As&&this.As.Dt()}}class vt{constructor(){c(this,"Bs",[]);c(this,"Ls",1);c(this,"Os",0)}Hs(t){if(this.Os>=this.Bs.length){const r={id:this.Ls++,type:t,params:{},state:{I:1,N:0,X:0,W:0,Y:[0,0,0],q:[1,1,1,1],V:[0,0,0,1],K:!1,j:!1,k:!1,L:[0,0]}};this.Bs.push(r)}const i=this.Bs[this.Os];return i.id=this.Ls++,i.type=t,this.Os++,i}Gs(t,i,r,n,o){const h=this.Hs(E.RECTANGLE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Is(t,i,r,n,o,h,a){const u=this.Hs(E.CUSTOM);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.shader=o,u.params.uniforms=h,a.J(u.state),u.id}Ns(t,i,r,n,o,h){const a=this.Hs(E.LINE);return a.params.x1=t,a.params.y1=i,a.params.x2=r,a.params.y2=n,a.params.thickness=o,h.J(a.state),a.id}Xs(t,i,r,n,o){const h=this.Hs(E.ELLIPSE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Ws(t,i,r,n,o,h,a){const u=this.Hs(E.ARC);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.start=o,u.params.stop=h,a.J(u.state),u.id}Ks(t,i,r,n,o,h,a){const u=this.Hs(E.TRIANGLE);return u.params.x1=t,u.params.y1=i,u.params.x2=r,u.params.y2=n,u.params.x3=o,u.params.y3=h,a.J(u.state),u.id}js(t,i,r,n,o,h,a,u,f,g){const d=this.Hs(E.BEZIER_CURVE);return d.params.x1=t,d.params.y1=i,d.params.cp1x=r,d.params.cp1y=n,d.params.cp2x=o,d.params.cp2y=h,d.params.x2=a,d.params.y2=u,d.params.thickness=f,g.J(d.state),d.id}get length(){return this.Os}get isEmpty(){return this.Os===0}Ys(){this.Os=0}[Symbol.iterator](){let t=0;const i=this.Os,r=this.Bs;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const _=class _{static qs(t,i,r=0){var h,a,u,f,g,d,p,y,A,m;const n=i||new Float32Array(_.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.fs[0],n[o++]=t.fs[1],n[o++]=t.Os[0],n[o++]=t.Os[1],n[o++]=t.Y[0],n[o++]=t.Y[1],n[o++]=t.Y[2],n[o++]=t.q[0],n[o++]=t.q[1],n[o++]=t.q[2],n[o++]=t.q[3],n[o++]=t.V[0],n[o++]=t.V[1],n[o++]=t.V[2],n[o++]=t.V[3],n[o++]=t.L[0],n[o++]=t.L[1],n[o++]=t.Vs[0],n[o++]=t.Vs[1],n[o++]=t.Vs[2],n[o++]=t.N,n[o++]=t.X,n[o++]=t.W,n[o++]=t.Zs[0],n[o++]=t.Zs[1],n[o++]=((h=t.Qs)==null?void 0:h[0])||0,n[o++]=((a=t.Qs)==null?void 0:a[1])||0,n[o++]=((u=t.Js)==null?void 0:u[0])||0,n[o++]=((f=t.Js)==null?void 0:f[1])||0,n[o++]=((g=t.te)==null?void 0:g[0])||0,n[o++]=((d=t.te)==null?void 0:d[1])||0,n[o++]=((p=t.se)==null?void 0:p[0])||0,n[o++]=((y=t.se)==null?void 0:y[1])||0,n[o++]=((A=t.ee)==null?void 0:A[0])||0,n[o++]=((m=t.ee)==null?void 0:m[1])||0,n}static ie(t){const i=t.length*_.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*_.FLOATS_PER_INSTANCE;_.qs(t[n],r,o)}return r}};c(_,"BYTES_PER_INSTANCE",140),c(_,"FLOATS_PER_INSTANCE",35);let B=_;const U=class U{};c(U,"STRIDE",B.BYTES_PER_INSTANCE),c(U,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:132,divisor:1}});let q=U;class yt{constructor(t,i=1e3,r=1.5){c(this,"gt");c(this,"re",[]);c(this,"ne");c(this,"oe");c(this,"he",null);c(this,"ae",!0);c(this,"ce",0);c(this,"le",new Map);c(this,"ue",null);this.gt=t,this.ne=i,this.oe=r,this.fe()}$s(t){const i=this.re.length;return this.re.push(t),this.ae=!0,i}get count(){return this.re.length}get isEmpty(){return this.re.length===0}clear(){this.re.length=0,this.ae=!0}de(t){if(t<=this.ne)return;const i=Math.ceil(t*this.oe);this.ne=i,this.fe()}fe(){const t=this.gt;this.he&&t.deleteBuffer(this.he),this.he=t.createBuffer();const i=this.ne*B.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.he),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.ae=!0,this.ce=0}pe(){if(!this.ae||this.re.length===0)return;const t=this.gt,i=this.re.length;this.de(i),(!this.ue||this.ue.length<i*B.FLOATS_PER_INSTANCE)&&(this.ue=new Float32Array(i*B.FLOATS_PER_INSTANCE));const r=B.ie(this.re);t.bindBuffer(t.ARRAY_BUFFER,this.he),i<=this.ce?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.ae=!1,this.ce=i}_e(t){let i=this.le.get(t);if(!i){i=new Map;const r=this.gt;for(const n in q.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.le.set(t,i)}return i}Ms(t){if(!this.he||this.re.length===0)return;const i=this.gt,r=t.Zt;this.pe();const n=this._e(r);i.bindBuffer(i.ARRAY_BUFFER,this.he);for(const[o,h]of n){const a=q.ATTRIBUTES[o];a&&(i.enableVertexAttribArray(h),i.vertexAttribPointer(h,a.size,a.type,a.normalized,a.stride,a.offset),i.vertexAttribDivisor(h,a.divisor))}}Ts(t){const i=this.gt,r=this._e(t.Zt);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}Fs(t,i){this.re.length!==0&&this.gt.drawArraysInstanced(t,0,i,this.re.length)}Dt(){this.he&&this.gt.deleteBuffer(this.he)}}class G{constructor(t,i,r,n){c(this,"gt");c(this,"me");c(this,"ve");c(this,"ge");c(this,"ye",null);this.gt=t,this.me=i,this.ve=r,this.ge=n;const o=this.gt.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.gt.bindBuffer(this.gt.ARRAY_BUFFER,o),this.gt.bufferData(this.gt.ARRAY_BUFFER,this.ge.Ae,this.gt.STATIC_DRAW),this.gt.bindBuffer(this.gt.ARRAY_BUFFER,null),this.ye=o}get type(){return this.ve}get unitGeometry(){return this.ge}get unitBuffer(){return this.ye}get batch(){return this.me}Ps(){this.me.clear()}bs(){return!this.me.isEmpty}Dt(){this.me.Dt(),this.gt.deleteBuffer(this.ye)}we(t,i,r,n,o){const h=this.Ce(t,i,r,n,o.N||0,o.X||0,o.W||0);return{fs:[t,i],Os:[r,n],Y:o.Y||[0,0,0],q:o.q||[1,1,1,1],V:o.V||[0,0,0,1],L:o.L||[0,0],Vs:[o.k?1:0,o.K?1:0,o.j?1:0],N:h.radiansX,X:h.radiansY,W:h.radiansZ,Zs:[h.centerX,h.centerY]}}be(t,i){const r=k(this.gt)||[0,0,this.gt.canvas.width,this.gt.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}xe(t,i,r){const n=this.be(i,r);t.Zs=[n.nx,n.ny]}Ce(t,i,r,n,o,h,a){const u=k(this.gt)||[0,0,this.gt.canvas.width,this.gt.canvas.height],f=u[2],g=u[3];return{centerX:(t+r/2)/f*2-1,centerY:1-(i+n/2)/g*2,radiansX:-o*Math.PI/180,radiansY:-h*Math.PI/180,radiansZ:-a*Math.PI/180,aspectRatio:f/g}}}const xt={Ae:new Float32Array([0,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,1,1,1]),zs:6,Rs:WebGL2RenderingContext.TRIANGLES,ps:16,ds:{fs:{size:2,offset:0},_s:{size:2,offset:8}}};class wt extends G{constructor(t,i){super(t,i,E.RECTANGLE,xt)}$s(t,i){const r=this.we(t.x,t.y,t.width,t.height,i);return this.me.$s(r)}}const Et={Ae: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]),zs:6,Rs:WebGL2RenderingContext.TRIANGLES,ps:16,ds:{fs:{size:2,offset:0},_s:{size:2,offset:8}}};class Tt extends G{constructor(t,i){super(t,i,E.LINE,Et)}$s(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),h=t.thickness||i.I||1,a=t.x1+r/2,u=t.y1+n/2,f=a-o/2,g=u,d=this.we(f,g,o,h,i);return this.xe(d,a,u),this.me.$s(d)}}const Rt={Ae:function(l=32){const t=[],i=2*Math.PI/l;for(let r=0;r<l;r++){const n=r*i,o=(r+1)%l*i,h=Math.cos(n),a=Math.sin(n),u=.5*(h+1),f=.5*(a+1),g=Math.cos(o),d=Math.sin(o),p=.5*(g+1),y=.5*(d+1);t.push(0,0,.5,.5,h,a,u,f,g,d,p,y)}return new Float32Array(t)}(32),zs:96,Rs:WebGL2RenderingContext.TRIANGLES,ps:16,ds:{fs:{size:2,offset:0},_s:{size:2,offset:8}}};class bt extends G{constructor(t,i){super(t,i,E.ELLIPSE,Rt)}$s(t,i){const r=this.we(t.x,t.y,t.width,t.height,i);return this.xe(r,t.x,t.y),this.me.$s(r)}}let Ct={Ae:function(l){const t=[];for(let i=0;i<l;i++){const r=i/l,n=(i+1)/l;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),zs:96,Rs:WebGL2RenderingContext.TRIANGLES,ps:16,ds:{fs:{size:2,offset:0},_s:{size:2,offset:8}}};class Ut extends G{constructor(t,i){super(t,i,E.ARC,Ct)}$s(t,i){const r=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,h=t.stop*Math.PI/180,a=this.we(r,n,t.width,t.height,i);return this.xe(a,t.x,t.y),a.Qs=[o,h],this.me.$s(a)}}const Ft={Ae:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),zs:3,Rs:WebGL2RenderingContext.TRIANGLES,ps:16,ds:{fs:{size:2,offset:0},_s:{size:2,offset:8}}};class Pt extends G{constructor(t,i){super(t,i,E.TRIANGLE,Ft)}$s(t,i){const r=Math.min(t.x1,t.x2,t.x3),n=Math.max(t.x1,t.x2,t.x3),o=Math.min(t.y1,t.y2,t.y3),h=n-r,a=Math.max(t.y1,t.y2,t.y3)-o,u=this.we(r,o,h,a,i),f=r+.5*h,g=o+a*(1/3);return this.xe(u,f,g),this.me.$s(u)}}function nt(l,t,i,r,n){const o=1-l,h=o*o,a=l*l;return h*o*t+3*h*l*i+3*o*a*r+a*l*n}const Ot={Ae:function(l=16){const t=[];for(let i=0;i<l;i++){const r=i/l,n=(i+1)/l;t.push(r,-.5,r,0),t.push(n,-.5,n,0),t.push(r,.5,r,1),t.push(r,.5,r,1),t.push(n,-.5,n,0),t.push(n,.5,n,1)}return new Float32Array(t)}(16),zs:96,Rs:WebGL2RenderingContext.TRIANGLES,ps:16,ds:{fs:{size:2,offset:0},_s:{size:2,offset:8}}};class Mt extends G{constructor(t,i){super(t,i,E.BEZIER_CURVE,Ot)}$s(t,i){const r=i.I||1,n=nt(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=nt(.5,t.y1,t.cp1y,t.cp2y,t.y2),h=this.we(0,0,1,r,i);return this.xe(h,n,o),h.se=[t.x1,t.y1],h.Js=[t.cp1x,t.cp1y],h.te=[t.cp2x,t.cp2y],h.ee=[t.x2,t.y2],this.me.$s(h)}}class Lt{constructor(t){c(this,"gt");c(this,"Me",null);c(this,"Fe");c(this,"Re",null);c(this,"ze",{});c(this,"Te",null);c(this,"Pe",new Map);c(this,"Se");c(this,"$e");c(this,"Ee");c(this,"H",[]);this.gt=t,this.Fe=new mt(t),this.Ee=new st,this.Se=new pt(t,this),this.$e=new vt,this.Te=t.createBuffer(),W(this.gt,[0,0,this.gt.canvas.width,this.gt.canvas.height])}De(t){let i=this.Pe.get(t);if(i)return i;const r=new yt(this.gt);return i=(0,{[E.RECTANGLE]:()=>new wt(this.gt,r),[E.LINE]:()=>new Tt(this.gt,r),[E.ELLIPSE]:()=>new bt(this.gt,r),[E.ARC]:()=>new Ut(this.gt,r),[E.TRIANGLE]:()=>new Pt(this.gt,r),[E.BEZIER_CURVE]:()=>new Mt(this.gt,r)}[t])(),this.Pe.set(t,i),i}ke(t){this.Me!==t&&(this.Me=t,t.Nt())}cs(t,i){return this.Fe.cs(t,i)}es(){return this.Fe.es()}Pt(){return this.Fe.Pt()}rs(){return this.Fe.rs()}ns(){return this.Fe.ns()}Be(t){this.Re=t,t&&(this.ze={})}Kt(t,i){this.ze[t]=i}Le(t){Object.assign(this.ze,t)}hs(t){return this.Fe.hs(t)}Oe(t,i,r,n,o){const h=this.es(),a={Ue:t.textures[0],Uf:t.textures[1],Ug:t.textures[2],Uh:t.textures[3],Ui:t.textures[4],Uj:[t.width,t.height]};this.$e.Is(i,r,n,o,h,a,this.Ee)}He(t,i,r,n,o){const h=this.ns(),a=t.Ge(),u={Uk:a.texture,Ul:!!a.invert,Um:!!a.flipX,Un:!!a.flipY,Uo:a.charRotation,Up:a.charColorFixed,Uq:a.charColor,Ur:a.cellColorFixed,Us:a.cellColor,Ut:a.backgroundColor,Uu:a.charCount,Uv:a.charList};this.$e.Is(i,r,n,o,h,u,this.Ee)}Ie(t,i,r,n){var m;const o=this.gt,h=o.canvas.width,a=o.canvas.height,u=t/h*2-1,f=(t+r)/h*2-1,g=1-i/a*2,d=1-(i+n)/a*2,p=new Float32Array([u,d,f,d,u,g,f,d,f,g,u,g]);o.bindBuffer(o.ARRAY_BUFFER,this.Te),o.bufferData(o.ARRAY_BUFFER,p,o.DYNAMIC_DRAW);const y=((m=this.Me)==null?void 0:m.Zt)||o.getParameter(o.CURRENT_PROGRAM),A=y?o.getAttribLocation(y,"a_position"):-1;A!==-1&&(o.enableVertexAttribArray(A),o.vertexAttribPointer(A,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),A!==-1&&o.disableVertexAttribArray(A)}Ne(t,i,r,n){this.Re?(this.$e.Is(t,i,r,n,this.Re,{...this.ze},this.Ee),this.Re=null,this.ze={}):this.$e.Gs(t,i,r,n,this.Ee)}Xe(t,i,r,n){this.$e.Ns(t,i,r,n,this.Ee.lineWeight,this.Ee)}We(t,i,r,n){this.$e.Xs(t,i,r,n,this.Ee)}Ke(t,i,r,n,o,h){this.$e.Ks(t,i,r,n,o,h,this.Ee)}je(t,i,r,n,o,h,a,u){const f=this.Ee.lineWeight;this.$e.js(t,i,r,n,o,h,a,u,f,this.Ee)}Ye(t,i,r=1,n={}){return new K(this.gt,t,i,r,n,this,!0)}qe(t,i,r,n,o,h){this.$e.Ws(t,i,r,n,o,h,this.Ee)}Ve(t,i=t,r=t,n=255){this.Ee.ft(t,i,r,n),this.Ys(t/255,i/255,r/255,n/255)}Ys(t=0,i=0,r=0,n=0){this.gt.clearColor(t,i,r,n),this.gt.clear(this.gt.COLOR_BUFFER_BIT)}Ze(){this.gt.viewport(0,0,this.gt.canvas.width,this.gt.canvas.height),W(this.gt,[0,0,this.gt.canvas.width,this.gt.canvas.height])}get context(){return this.gt}get state(){return this.Ee}$t(t){this.H.push(this.Ee),this.Ee=t}Et(){const t=this.H.pop();t&&(this.Ee=t)}St(t){const i=t,r=k(this.gt)??this.gt.getParameter(this.gt.VIEWPORT),n={shader:i,gl:this.gt,viewport:r};this.ke(i);const o=new Set;for(const h of this.$e)h.type===E.CUSTOM?o.add(E.RECTANGLE):o.add(h.type);for(const h of o)h!==E.CUSTOM&&this.De(h);this.Se.Cs(n,this.$e,this.Pe),this.$e.Ys()}Dt(){this.gt.deleteBuffer(this.Te),this.$e.Ys();for(const t of this.Pe.values())t.Dt();this.Fe.Dt(),this.Se.Dt()}}const b={readShort:(l,t)=>(b.t.uint16[0]=l[t]<<8|l[t+1],b.t.int16[0]),readUshort:(l,t)=>l[t]<<8|l[t+1],readUshorts(l,t,i){const r=[];for(let n=0;n<i;n++)r.push(b.readUshort(l,t+2*n));return r},readUint(l,t){const i=b.t.uint8;return i[3]=l[t],i[2]=l[t+1],i[1]=l[t+2],i[0]=l[t+3],b.t.uint32[0]},readASCII(l,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(l[t+n]);return r},writeUshort(l,t,i){l[t]=i>>>8&255,l[t+1]=255&i},writeUint(l,t,i){l[t]=i>>>24&255,l[t+1]=i>>>16&255,l[t+2]=i>>>8&255,l[t+3]=255&i},writeASCII(l,t,i){for(let r=0;r<i.length;r++)l[t+r]=255&i.charCodeAt(r)},t:(()=>{const l=new ArrayBuffer(8);return{uint8:new Uint8Array(l),int16:new Int16Array(l),uint16:new Uint16Array(l),uint32:new Uint32Array(l)}})()};function Z(l){return l+3&-4}function $(l,t,i){const r=t+i;let n=0;const o=b.t;for(let h=t;h<r;h+=4)o.uint8[3]=l[h]||0,o.uint8[2]=l[h+1]||0,o.uint8[1]=l[h+2]||0,o.uint8[0]=l[h+3]||0,n=n+(o.uint32[0]>>>0)>>>0;return n>>>0}class Dt{constructor(t){c(this,"b");c(this,"p",0);c(this,"bitbuf",0);c(this,"bitcnt",0);this.b=t}readBits(t){for(;this.bitcnt<t;){const r=this.b[this.p++]||0;this.bitbuf|=r<<this.bitcnt,this.bitcnt+=8}const i=this.bitbuf&(1<<t)-1;return this.bitbuf>>>=t,this.bitcnt-=t,i}alignToByte(){this.bitbuf=0,this.bitcnt=0}get offset(){return this.p}}function Y(l){let t=32,i=0;for(const a of l)a&&(a<t&&(t=a),a>i&&(i=a));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const a of l)a&&r[a]++;const n=new Uint32Array(i+1);let o=0;r[0]=0;for(let a=1;a<=i;a++)o=o+r[a-1]<<1,n[a]=o;const h=new Map;for(let a=0;a<l.length;a++){const u=l[a];if(!u)continue;const f=n[u]++;let g=h.get(u);g||(g=[],h.set(u,g)),g[_t(f,u)]=a}return{min:t,max:i,table:h}}function tt(l,t){let i=0;for(let r=1;r<=t.max;r++){i|=l.readBits(1)<<r-1;const n=t.table.get(r);if(n&&i<n.length){const o=n[i];if(o!==void 0)return o}}throw Error("Invalid Huffman code")}function _t(l,t){let i=0;for(let r=0;r<t;r++)i=i<<1|1&l,l>>>=1;return i>>>0}function St(l){if(l.length<2)throw Error("ZLIB data too short");const t=l[0],i=l[1];if((15&t)!=8)throw Error("Unsupported ZLIB compression method");if(((t<<8)+i)%31!=0)throw Error("Bad ZLIB header check");let r=2;32&i&&(r+=4);const n=[];return function(o,h){const a=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],u=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],f=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],g=[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 d=0;for(;!d;){d=o.readBits(1);const p=o.readBits(2);if(p===0){o.alignToByte();const y=o.readBits(16);if((65535&(65535^y))!==o.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let A=0;A<y;A++)h.push(o.readBits(8))}else{if(p!==1&&p!==2)throw Error("Unsupported DEFLATE type");{let y,A;if(p===1){const m=Array(288).fill(0);for(let x=0;x<=143;x++)m[x]=8;for(let x=144;x<=255;x++)m[x]=9;for(let x=256;x<=279;x++)m[x]=7;for(let x=280;x<=287;x++)m[x]=8;y=Y(m),A=Y(Array(32).fill(5))}else{const m=o.readBits(5)+257,x=o.readBits(5)+1,v=o.readBits(4)+4,T=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],w=Array(19).fill(0);for(let M=0;M<v;M++)w[T[M]]=o.readBits(3);const O=Y(w),F=[];for(;F.length<m+x;){const M=tt(o,O);if(M<=15)F.push(M);else if(M===16){const V=o.readBits(2)+3,N=F[F.length-1]||0;for(let gt=0;gt<V;gt++)F.push(N)}else if(M===17){const V=o.readBits(3)+3;for(let N=0;N<V;N++)F.push(0)}else{if(M!==18)throw Error("Invalid code length symbol");{const V=o.readBits(7)+11;for(let N=0;N<V;N++)F.push(0)}}}const P=F.slice(0,m),L=F.slice(m,m+x);y=Y(P),A=Y(L)}for(;;){const m=tt(o,y);if(m<256)h.push(m);else{if(m===256)break;if(m>256&&m<286){const x=m-257;let v=a[x];const T=u[x];T&&(v+=o.readBits(T));const w=tt(o,A);if(w>=30)throw Error("Invalid distance symbol");let O=f[w];const F=g[w];F&&(O+=o.readBits(F));const P=h.length-O;if(P<0)throw Error("Invalid distance");for(let L=0;L<v;L++)h.push(h[P+L]||0)}else if(m===286||m===287)throw Error("Reserved length symbol")}}}}}}(new Dt(l.subarray(r)),n),new Uint8Array(n)}function Bt(l){const t=b,i=new Uint8Array(l);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),n=t.readUshort(i,12),o=t.readUint(i,16),h=[];let a=44;for(let v=0;v<n;v++){const T=t.readASCII(i,a,4),w=t.readUint(i,a+4),O=t.readUint(i,a+8),F=t.readUint(i,a+12),P=t.readUint(i,a+16);h.push({tag:T,offset:w,compLength:O,origLength:F,checksum:P}),a+=20}for(const v of h){const T=new Uint8Array(i.buffer,v.offset,v.compLength);if(v.compLength===v.origLength)v.data=new Uint8Array(T);else if(v.data=St(T),v.data.length!==v.origLength)if(v.data.length<v.origLength){const w=new Uint8Array(v.origLength);w.set(v.data),v.data=w}else v.data=v.data.subarray(0,v.origLength)}const u=n;let f=1,g=0;for(;f<<1<=u;)f<<=1,g++;const d=16*f,p=16*u-d;let y=12+16*u;const A={};for(const v of h)A[v.tag]=y,y=Z(y+v.data.length);const m=new Uint8Array(Math.max(o||0,y));t.writeUint(m,0,r),t.writeUshort(m,4,u),t.writeUshort(m,6,d),t.writeUshort(m,8,g),t.writeUshort(m,10,p);let x=12;for(const v of h){t.writeASCII(m,x,v.tag),x+=4;let T=v.data;if(v.tag==="head"&&T.length>=12){const w=new Uint8Array(T);t.writeUint(w,8,0);const O=$(w,0,Z(w.length));t.writeUint(m,x,O),x+=4}else{const w=$(T,0,Z(T.length));t.writeUint(m,x,w),x+=4}t.writeUint(m,x,A[v.tag]),x+=4,t.writeUint(m,x,v.data.length),x+=4}for(const v of h){const T=A[v.tag];m.set(v.data,T)}if(h.find(v=>v.tag==="head")){const v=A.head,T=function(w,O){const F=b,P=O+8,L=[w[P],w[P+1],w[P+2],w[P+3]];F.writeUint(w,P,0);const M=2981146554-($(w,0,Z(w.length))>>>0)>>>0;return w[P]=L[0],w[P+1]=L[1],w[P+2]=L[2],w[P+3]=L[3],M>>>0}(m,v);t.writeUint(m,v+8,T)}return m.buffer}const It={parseTab(l,t,i){const r={tables:[],ids:{},off:t};l=new Uint8Array(l.buffer,t,i),t=0;const n=b,o=n.readUshort,h=o(l,t+=2);t+=2;const a=[];for(let u=0;u<h;u++){const f=o(l,t),g=o(l,t+=2);t+=2;const d=n.readUint(l,t);t+=4;const p=`p${f}e${g}`;let y=a.indexOf(d);if(y===-1){let A;y=r.tables.length,a.push(d);const m=o(l,d);A=m===4?this.parse4(l,d):m===12?this.parse12(l,d):{format:m},r.tables.push(A)}r.ids[p]=y}return r},parse4(l,t){const i=b,r=i.readUshort,n=i.readUshorts,o=t,h=r(l,t+=2);t+=2;const a=r(l,t+=2)>>>1,u={format:4,searchRange:r(l,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,u.entrySelector=r(l,t),t+=2,u.rangeShift=r(l,t),t+=2,u.endCount=n(l,t,a),t+=2*a,t+=2,u.startCount=n(l,t,a),t+=2*a;for(let f=0;f<a;f++)u.idDelta.push(i.readShort(l,t)),t+=2;return u.idRangeOffset=n(l,t,a),t+=2*a,u.glyphIdArray=n(l,t,o+h-t>>1),u},parse12(l,t){const i=b.readUint;i(l,t+=4),i(l,t+=4);const r=i(l,t+=4);t+=4;const n=new Uint32Array(3*r);for(let o=0;o<3*r;o+=3)n[o]=i(l,t+(o<<2)),n[o+1]=i(l,t+(o<<2)+4),n[o+2]=i(l,t+(o<<2)+8);return{format:12,groups:n}}},Nt={parseTab(l,t,i){const r=b;t+=18;const n=r.readUshort(l,t);t+=2,t+=16;const o=r.readShort(l,t);t+=2;const h=r.readShort(l,t);t+=2;const a=r.readShort(l,t);t+=2;const u=r.readShort(l,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:h,xMax:a,yMax:u,indexToLocFormat:r.readShort(l,t)}}},zt={parseTab(l,t,i){const r=b;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let h=0;h<n.length;h++){const a=n[h],u=a==="advanceWidthMax"||a==="numberOfHMetrics"?r.readUshort:r.readShort;o[a]=u(l,t+2*h)}return o}},Gt={parseTab(l,t,i,r){const n=b,o=[],h=[],a=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,g=0,d=0;for(;d<u;)f=n.readUshort(l,t+(d<<2)),g=n.readShort(l,t+(d<<2)+2),o.push(f),h.push(g),d++;for(;d<a;)o.push(f),h.push(g),d++;return{aWidth:o,lsBearing:h}}},ot={cmap:It,head:Nt,hhea:zt,maxp:{parseTab(l,t,i){const r=b;return r.readUint(l,t),t+=4,{numGlyphs:r.readUshort(l,t)}}},hmtx:Gt,loca:{parseTab(l,t,i,r){const n=b,o=[],h=r.head.indexToLocFormat,a=r.maxp.numGlyphs+1;if(h===0)for(let u=0;u<a;u++)o.push(n.readUshort(l,t+(u<<1))<<1);else if(h===1)for(let u=0;u<a;u++)o.push(n.readUint(l,t+(u<<2)));return o}},glyf:{parseTab(l,t,i,r){const n=[],o=r.maxp.numGlyphs;for(let h=0;h<o;h++)n.push(null);return n},Qe(l,t){const i=b,r=l.Je,n=l.loca;if(n[t]===n[t+1])return null;const o=D.findTable(r,"glyf",l.ti);if(!o)return null;let h=o[0]+n[t];const a={};if(a.noc=i.readShort(r,h),h+=2,a.xMin=i.readShort(r,h),h+=2,a.yMin=i.readShort(r,h),h+=2,a.xMax=i.readShort(r,h),h+=2,a.yMax=i.readShort(r,h),h+=2,a.xMin>=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(let p=0;p<a.noc;p++)a.endPts.push(i.readUshort(r,h)),h+=2;const u=i.readUshort(r,h);if(h+=2,r.length-h<u)return null;h+=u;const f=a.endPts[a.noc-1]+1;a.flags=[];for(let p=0;p<f;p++){const y=r[h];if(h++,a.flags.push(y),8&y){const A=r[h];h++;for(let m=0;m<A;m++)a.flags.push(y),p++}}a.xs=[];for(let p=0;p<f;p++){const y=a.flags[p],A=!!(16&y);2&y?(a.xs.push(A?r[h]:-r[h]),h++):A?a.xs.push(0):(a.xs.push(i.readShort(r,h)),h+=2)}a.ys=[];for(let p=0;p<f;p++){const y=a.flags[p],A=!!(32&y);4&y?(a.ys.push(A?r[h]:-r[h]),h++):A?a.ys.push(0):(a.ys.push(i.readShort(r,h)),h+=2)}let g=0,d=0;for(let p=0;p<f;p++)g+=a.xs[p],d+=a.ys[p],a.xs[p]=g,a.ys[p]=d}else a.parts=[],a.endPts=[],a.flags=[],a.xs=[],a.ys=[];return a}}},D={parse(l){const t=new Uint8Array(l),i=b.readASCII(t,0,4);if(i==="wOFF")l=Bt(l);else if(i==="wOF2")throw Error("WOFF2 is not supported in this build (Brotli + WOFF2 transforms required)");return[((r,n,o,h)=>{const a=ot,u={Je:r,si:n,ti:o};for(const f in a){const g=f,d=D.findTable(r,g,o);if(d){const[p,y]=d;let A=h[p];A==null&&(A=a[g].parseTab(r,p,y,u),h[p]=A),u[g]=A}}return u})(new Uint8Array(l),0,0,{})]},findTable(l,t,i){const r=b,n=r.readUshort(l,i+4);let o=i+12;for(let h=0;h<n;h++){const a=r.readASCII(l,o,4);r.readUint(l,o+4);const u=r.readUint(l,o+8),f=r.readUint(l,o+12);if(a===t)return[u,f];o+=16}return null},T:ot,B:b};class Ht{ei(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ii(n);i.push(...o)}else if(n.format===12){const o=this.ri(n);i.push(...o)}}),[...new Set(i)]):[]}ni(t){return t.filter(i=>this.oi(i))}ii(t){const i=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return i;for(let r=0;r<t.startCount.length;r++){const n=t.startCount[r],o=t.endCount[r];if(n!==65535||o!==65535){for(let h=n;h<=o;h++)if(this.hi(t,h,r)>0)try{const a=String.fromCodePoint(h);i.push(a)}catch{}}}return i}ri(t){const i=[];if(!t.groups)return i;for(let r=0;r<t.groups.length;r+=3){const n=t.groups[r],o=t.groups[r+1],h=t.groups[r+2];for(let a=n;a<=o;a++)if(h+(a-n)>0)try{const u=String.fromCodePoint(a);i.push(u)}catch{}}return i}hi(t,i,r){if(t.idRangeOffset[r]===0)return i+t.idDelta[r]&65535;{const n=t.idRangeOffset[r]/2+(i-t.startCount[r])-(t.startCount.length-r);if(n>=0&&t.glyphIdArray&&n<t.glyphIdArray.length){const o=t.glyphIdArray[n];if(o!==0)return o+t.idDelta[r]&65535}}return 0}oi(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class et{constructor(){c(this,"ai",new Map);c(this,"ci",new Map)}li(t,i){const r=`${this.ui(t)}_${i}`;if(this.ai.has(r))return this.ai.get(r);const n=t.cmap;if(!n||!n.tables)return this.ai.set(r,0),0;let o=0;for(const h of n.tables)if(h.format===4?o=this.fi(i,h):h.format===12&&(o=this.di(i,h)),o>0)break;return this.ai.set(r,o),o}pi(t,i){const r=i.codePointAt(0);return r===void 0?0:this.li(t,r)}_i(t,i){const r=t.hmtx;return r&&r.aWidth&&r.aWidth.length!==0?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}mi(t,i){const r=i/t.head.unitsPerEm,n=t.hhea.ascender*r,o=t.hhea.descender*r,h=t.hhea.lineGap*r;return{ascender:n,descender:o,lineGap:h,lineHeight:n-o+h,unitsPerEm:t.head.unitsPerEm,scale:r}}gi(){this.ai.clear(),this.ci.clear()}ui(t){return`${t.ti}_${t.Je.length}`}fi(t,i){const r=i.endCount.length;let n=-1;for(let o=0;o<r;o++)if(t<=i.endCount[o]){n=o;break}if(n===-1||t<i.startCount[n])return 0;if(i.idRangeOffset[n]===0)return t+i.idDelta[n]&65535;{const o=i.idRangeOffset[n]/2+(t-i.startCount[n])-(r-n);if(o>=0&&o<i.glyphIdArray.length){const h=i.glyphIdArray[o];return h===0?0:h+i.idDelta[n]&65535}}return 0}di(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const o=i.groups[3*n],h=i.groups[3*n+1],a=i.groups[3*n+2];if(t>=o&&t<=h)return a+(t-o)}return 0}}class Xt{constructor(t){c(this,"yi");c(this,"Ai");c(this,"xt");c(this,"wi");this.xt=t,this.wi=new et,this.yi=document.createElement("canvas"),this.Ai=this.yi.getContext("2d",{willReadFrequently:!0,alpha:!0})}createTextureAtlas(t,i,r,n){const o=t.length,h=Math.ceil(Math.sqrt(o)),a=Math.ceil(o/h),u=i.width*h,f=i.height*a,g=typeof n=="object"?n:null;this.Ci(u,f),this.bi(t,i,h,r,g);const d=this.xt.Ye(u,f,1,{filter:"nearest"});return d.Tt(this.yi),{framebuffer:d,columns:h,rows:a}}Ci(t,i){this.yi.width=t,this.yi.height=i,this.yi.style.width=t+"px",this.yi.style.height=i+"px",this.Ai.imageSmoothingEnabled=!1,this.yi.style.imageRendering="pixelated",this.Ai.clearRect(0,0,t,i),this.Ai.textBaseline="top",this.Ai.textAlign="left",this.Ai.fillStyle="white"}bi(t,i,r,n,o){const h=n/o.head.unitsPerEm;for(let a=0;a<t.length;a++){const u=a%r,f=Math.floor(a/r),g=t[a].character,d=this.xi(o,g);if(!d)continue;const p=g.codePointAt(0)||0,y=this.wi.li(o,p),A=this.Mi(o,y)*h,m=u*i.width,x=f*i.height,v=m+.5*i.width,T=x+.5*i.height,w=Math.round(v-.5*i.width),O=Math.round(T-.5*n),F=w+.5*(i.width-A),P=O+o.hhea.ascender*h;this.Fi(d,F,P,h)}}xi(t,i){const r=i.codePointAt(0)||0,n=this.wi.li(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(D&&D.T&&D.T.glyf){const o=D.T.glyf.Qe(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}Mi(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}Fi(t,i,r,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:h,endPts:a,flags:u}=t;if(!(o&&h&&a&&u))return;this.Ai.beginPath();let f=0;for(let g=0;g<a.length;g++){const d=a[g];if(!(d<f)){if(d>=f){const p=i+o[f]*n,y=r-h[f]*n;this.Ai.moveTo(p,y);let A=f+1;for(;A<=d;)if(1&u[A]){const m=i+o[A]*n,x=r-h[A]*n;this.Ai.lineTo(m,x),A++}else{const m=i+o[A]*n,x=r-h[A]*n;let v=A+1>d?f:A+1;if(1&u[v]){const T=i+o[v]*n,w=r-h[v]*n;this.Ai.quadraticCurveTo(m,x,T,w),A=v+1}else{const T=(m+(i+o[v]*n))/2,w=(x+(r-h[v]*n))/2;this.Ai.quadraticCurveTo(m,x,T,w),A=v}}this.Ai.closePath()}f=d+1}}this.Ai.fill()}}class Yt{constructor(){c(this,"Ri");this.Ri=new et}zi(t,i,r){let n=0;const o=this.Ri.mi(r,i),h=o.lineHeight;for(const a of t){const u=this.Ri.pi(r,a);if(u===0)continue;const f=this.Ri._i(r,u)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(h)}}gi(){this.Ri.gi()}}class Vt{constructor(){c(this,"wi");this.wi=new et}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,h=this.Ti(n);let a=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.wi.li(i,o);u>0&&i.hmtx.aWidth[u]!==void 0&&(a=i.hmtx.aWidth[u])}return{character:r,unicode:o,color:h,advanceWidth:a}})}Ti(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}Pi(t,i){if(!X.v(typeof t=="string","Character must be a string.",{method:"getCharacterColor",providedValue:t}))return[0,0,0];const r=i.find(n=>n.character===t);return r?r.color:[0,0,0]}Si(t,i){return X.v(typeof t=="string"&&t.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:t})?Array.from(t).map(r=>this.Pi(r,i)||[0,0,0]):[[0,0,0]]}}class ht{constructor(t,i=16){c(this,"$i");c(this,"Ei",[]);c(this,"Di");c(this,"ki",16);c(this,"Bi",0);c(this,"Li",0);c(this,"Oi",{width:0,height:0});c(this,"Hi");c(this,"Gi",new Map);c(this,"Ii");c(this,"Ni");c(this,"Xi");c(this,"Wi");this.ki=i,this.Ii=new Ht,this.Ni=new Xt(t),this.Xi=new Yt,this.Wi=new Vt}async Ki(t){let i;if(t){const r=await fetch(t);if(!r.ok)throw new R(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}else i=await(await fetch("data:font/woff;base64,d09GRgABAAAAABbwAAoAAAAAfywAAQABAAAAAAAAAAAAAAAAAAAAAAAAAABjbWFwAAAA9AAAAbsAAAkgIO8lSWdseWYAAAKwAAAOfgAAaLS4ctN0aGVhZAAAETAAAAAsAAAAOCi8/PVoaGVhAAARXAAAABkAAAAkCwEFAmhtdHgAABF4AAAAhQAABAQEAIOAbG9jYQAAEgAAAAKUAAAECAAy54BtYXhwAAAUlAAAABgAAAAgASIAgm5hbWUAABSsAAAB5wAAA6RWz85KT1MvMgAAFpQAAABFAAAAYM+QEyRwb3N0AAAW3AAAABQAAAAgAGkANHja7dRPSFRRFMfx38wdXblw4cJC7M0bz60gWlULGUFctWgR0UIQQkmDyn27kpAQaaEO2jhWJuafiQFtcDJtSqGhiFZtot5x3jzEVQQhlRJcOb0khiRc1+J94R64uw8cOADCAJT/avwZAiIpRC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wLHteZufmzrZobfj/K5ednna0/fe/l+Pca7seNpjYGRgYGRkaGBQYAABJgY0AAAP+ACmeNp1ksFO20AQhv8NgRJaUApSy61LDxVc4uAjNxoJReoNKdCrYy8hZb1rrTcIuPMKfaY+QM899RH6AP3tDJEKqlcefzvzz/xrywD21ScoLK9N3ktW5E3hDl6hL7zG7HvhLrMfhNfxGonwBjUnwj2uz8JbzH4R3sZbPArvIMV34T28wQ+6qG6Puz5+Civyb+EOO/4Ir6GvOsJdaLUrvI53KhXeoGYs3MOu+iq8hai+CW/jo/olvIOiA+E97HeKw/xIp8M0nYQ6O/MunpvZwmbhafv01JK/MKGee6ePB8N/JCFzN6dO+8o4bee5cbnRM+NMyKyuFqHytdHR3MXSF0ZfNQOn93rVORoNm4l64ua3NMjsdYxVfZIkeTBZZC73ZeldPfBhllSLKR0KX2ZzlzyY4BO2JmNjrdeXPtjiAIfIcQTNbz/knWKCgBoZzuDhEHEOgxkWsMyFF9Xne/1Mf8Fdo5i3dY1jDOjz/ymB0eEGp63ao2J/Q5YT8pabqOnQsGn1lvuKjoHRc05Tj4x3jCUzRZu5Wp1winvGl54jruHqjI3C0fVW3qDxuWZ/pEvNPzjhylkxrETR5fQoW09HzYDPwJMm7emm8g5Fq8nIjpWHdronLV0TjJmxXJ4nuGwnWPYcAH8BoeumrAB42mNgYmFgnMDAysDCxMDEAAIQGoiNGc6A+CwMENDAwNDNwFDwGMpliHT00WNwYFBQy4aogJCMgSCSGcJTYGAAAEBYBpIAAAB42mNgZoCANAZjIMnIgAYADecAng==")).arrayBuffer();await this.ji(i),this.$i=D.parse(i)[0],await this.Yi()}qi(t){if(t===void 0)return this.ki;this.ki=t,this.Oi=this.Xi.zi(this.Ei.map(r=>r.character),this.ki,this.$i);const i=this.Ni.createTextureAtlas(this.Ei,this.Oi,this.ki,this.$i);this.Di=i.framebuffer,this.Bi=i.columns,this.Li=i.rows}async Vi(t){try{const i=await fetch(t);if(!i.ok)throw new R(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.ji(r);const n=D.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.$i=n[0],await this.Yi()}catch(i){throw new R("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async ji(t){const i=Date.now();this.Hi=new FontFace("CustomFont_"+i,t),await this.Hi.load(),document.fonts.add(this.Hi)}async Yi(){const t=this.Ii.ei(this.$i),i=this.Ii.ni(t);this.Gi.clear(),this.Ei=this.Wi.createCharacterObjects(i,this.$i),this.Oi=this.Xi.zi(i,this.ki,this.$i);const r=this.Ni.createTextureAtlas(this.Ei,this.Oi,this.ki,this.$i);this.Di=r.framebuffer,this.Bi=r.columns,this.Li=r.rows}Pi(t){return this.Wi.Pi(t,this.Ei)}Si(t){return this.Wi.Si(t,this.Ei)}getGlyphData(t){if(!Number.isFinite(t))return null;const i=this.Gi.get(t);if(i!==void 0)return i;const r=this.Zi(t);if(r<0)return this.Gi.set(t,null),null;const n=this.$i.glyf;if(!n)return this.Gi.set(t,null),null;let o=n[r]??null;return o==null&&(o=D.T.glyf.Qe(this.$i,r)??null,n[r]=o),this.Gi.set(t,o),o}Zi(t){const i=this.$i.cmap;for(const r of i.tables)if(r.format===4){const n=r;for(let o=0;o<n.startCount.length;o++)if(t>=n.startCount[o]&&t<=n.endCount[o]){if(n.idRangeOffset[o]===0)return t+n.idDelta[o]&65535;{const h=n.idRangeOffset[o]/2+(t-n.startCount[o])-(n.startCount.length-o);if(h>=0&&h<n.glyphIdArray.length){const a=n.glyphIdArray[h];if(a!==0)return a+n.idDelta[o]&65535}}}}else if(r.format===12){const n=r;for(let o=0;o<n.groups.length;o+=3){const h=n.groups[o],a=n.groups[o+1],u=n.groups[o+2];if(t>=h&&t<=a)return u+(t-h)}}return 0}Dt(){this.Di.Dt(),document.fonts.delete(this.Hi)}get fontFramebuffer(){return this.Di}get characters(){return this.Ei}get textureColumns(){return this.Bi}get textureRows(){return this.Li}get maxGlyphDimensions(){return this.Oi}get fontSize(){return this.ki}get font(){return this.$i}}class at{constructor(t,i,r){c(this,"Qi");c(this,"Ji");c(this,"dt");c(this,"_t");c(this,"tr");c(this,"sr");c(this,"er");c(this,"ir");c(this,"rr");this.er=t,this.ir=i,this.rr=r,this.nr()}nr(){this.Qi=Math.floor(this.er.width/this.ir),this.Ji=Math.floor(this.er.height/this.rr),this.dt=this.Qi*this.ir,this._t=this.Ji*this.rr,this.tr=Math.floor((this.er.width-this.dt)/2),this.sr=Math.floor((this.er.height-this._t)/2)}hr(t,i){this.ir=t,this.rr=i,this.nr()}get cellWidth(){return this.ir}get cellHeight(){return this.rr}get cols(){return this.Qi}get rows(){return this.Ji}get width(){return this.dt}get height(){return this._t}get offsetX(){return this.tr}get offsetY(){return this.sr}}class ct{constructor(t={}){c(this,"er");c(this,"ar",null);c(this,"cr",!1);c(this,"lr");c(this,"ur");this.cr=t.overlay??!1,this.cr&&t.canvas?(this.ar=t.canvas,this.er=this.dr(),this.ur=!0,this.pr()):t.canvas?(this.er=t.canvas,this.ur=!1):(this.er=this._r(t.width,t.height),this.ur=!0),this.er.style.imageRendering="pixelated"}_r(t,i){const r=document.createElement("canvas");return r.className="textmodeCanvas",r.style.imageRendering="pixelated",r.width=t||800,r.height=i||600,document.body.appendChild(r),r}dr(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.ar.getBoundingClientRect();let r=Math.round(i.width),n=Math.round(i.height);if(this.ar instanceof HTMLVideoElement){const a=this.ar;(r===0||n===0)&&a.videoWidth>0&&a.videoHeight>0&&(r=a.videoWidth,n=a.videoHeight)}t.width=r,t.height=n,t.style.position="absolute",t.style.pointerEvents="none";const o=window.getComputedStyle(this.ar);let h=parseInt(o.zIndex||"0",10);return isNaN(h)&&(h=0),t.style.zIndex=""+(h+1),t}pr(){var t;this.mr(),(t=this.ar.parentNode)==null||t.insertBefore(this.er,this.ar.nextSibling),window.ResizeObserver&&(this.lr=new ResizeObserver(()=>{this.vr()}),this.lr.observe(this.ar)),window.addEventListener("resize",()=>{this.vr()})}mr(){if(!this.ar)return;const t=this.ar.getBoundingClientRect();let i=this.ar.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.er.style.top=t.top-r.top+"px",this.er.style.left=t.left-r.left+"px"}else this.er.style.top=t.top+window.scrollY+"px",this.er.style.left=t.left+window.scrollX+"px"}vr(t,i){if(this.cr){const r=this.ar.getBoundingClientRect();let n=Math.round(r.width),o=Math.round(r.height);if(this.ar instanceof HTMLVideoElement){const h=this.ar;(n===0||o===0)&&h.videoWidth>0&&h.videoHeight>0&&(n=h.videoWidth,o=h.videoHeight)}this.er.width=n,this.er.height=o,this.mr()}else this.er.width=t??this.er.width,this.er.height=i??this.er.height}gr(){const t=this.er.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new R("`textmode.js` requires WebGL2 support.");return t}Dt(){this.lr&&this.lr.disconnect();const t=this.er.getContext("webgl")||this.er.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.ur&&this.er.parentNode&&this.er.parentNode.removeChild(this.er)}get canvas(){return this.er}get targetCanvas(){return this.ar}get width(){return this.er.width}get height(){return this.er.height}}class H{constructor(t,i,r,n){c(this,"yr");c(this,"dt");c(this,"_t");c(this,"gt");c(this,"k",0);c(this,"K",0);c(this,"j",0);c(this,"L",[0,0]);c(this,"Ar","sampled");c(this,"wr","fixed");c(this,"q",[1,1,1,1]);c(this,"V",[0,0,0,1]);c(this,"Cr",[0,0,0,1]);c(this,"br",[[.1,0,0]]);c(this,"Mr");this.gt=t,this.yr=i,this.dt=r,this._t=n}Dt(){this.gt.deleteTexture(this.yr)}Fr(t){return typeof t=="boolean"?t?1:0:(t==null?0:Number(t))>0?1:0}invert(t=!0){return this.k=this.Fr(t),this}flipX(t=!0){return this.K=this.Fr(t),this}flipY(t=!0){return this.j=this.Fr(t),this}charRotation(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));return this.L=[r,n],this}Ge(){return{texture:this.yr,invert:this.k,flipX:this.K,flipY:this.j,charRotation:this.L,charColorFixed:this.Ar==="fixed",charColor:this.q,cellColorFixed:this.wr==="fixed",cellColor:this.V,backgroundColor:this.Cr,charCount:this.br.length,charList:this.br}}charColorMode(t){return this.Ar=t,this}cellColorMode(t){return this.wr=t,this}charColor(t,i,r,n){return this.q=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}cellColor(t,i,r,n){return this.V=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}background(t,i,r,n){return this.Cr=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}characters(t){const i=this.Mr(t).filter(r=>Array.isArray(r)).slice(0,64);return this.br=i,this}static Rr(t,i,r){const n=t.context,o=n.createTexture();n.bindTexture(n.TEXTURE_2D,o),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,1),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),n.bindTexture(n.TEXTURE_2D,null);const h=i.naturalWidth??i.width??i.videoWidth??0,a=i.naturalHeight??i.height??i.videoHeight??0,u=new H(n,o,h,a);return u.Mr=r,u}get texture(){return this.yr}get width(){return this.dt}get height(){return this._t}}class Wt{constructor(t=60){c(this,"zr");c(this,"Tr");c(this,"Pr",null);c(this,"Sr",0);c(this,"$r",!0);c(this,"Er",0);c(this,"Dr",0);c(this,"kr",[]);c(this,"Br",10);c(this,"Lr",0);this.zr=t,this.Tr=1e3/t}start(t){if(!this.$r)return;this.Sr=performance.now();const i=r=>{if(!this.$r)return void(this.Pr=null);const n=r-this.Sr;n>=this.Tr&&(t(),this.Sr=r-n%this.Tr),this.$r&&(this.Pr=requestAnimationFrame(i))};this.Pr=requestAnimationFrame(i)}stop(){this.Pr&&(cancelAnimationFrame(this.Pr),this.Pr=null)}pause(){this.$r&&(this.$r=!1,this.stop())}resume(t){this.$r||(this.$r=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.Er;this.zr=t,this.Tr=1e3/t,this.$r&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.Dr>0){const i=t-this.Dr;this.kr.push(i),this.kr.length>this.Br&&this.kr.shift();const r=this.kr.reduce((n,o)=>n+o,0)/this.kr.length;this.Er=1e3/r}this.Dr=t}get isLooping(){return this.$r}get frameRateLimit(){return this.zr}get currentFrameRate(){return this.Er}get frameCount(){return this.Lr}set frameCount(t){this.Lr=t}incrementFrame(){this.Lr++}resetFrameCount(){this.Lr=0}}class lt{constructor(t){c(this,"er");c(this,"Or");c(this,"Hr",{x:-1,y:-1});c(this,"Gr",{x:-1,y:-1});c(this,"Ir",null);c(this,"Nr",0);c(this,"Xr");c(this,"Wr");c(this,"Kr");c(this,"jr");c(this,"Yr");c(this,"qr");c(this,"Vr",!1);c(this,"Zr");c(this,"Qr");c(this,"Jr");c(this,"tn");c(this,"sn");this.er=t}en(t){const i=performance.now()+Math.max(0,t);i>this.Nr&&(this.Nr=i)}rn(){return performance.now()<this.Nr}nn(t){const i=this.er.canvas;i.style.cursor=t==null||t===""?"":t}Ki(t){this.Or=t,this.hn()}an(){if(this.Vr)return;const t=this.er.canvas;this.Xr=i=>{this.cn(i),this.ln(i)},this.Wr=()=>{this.Gr={...this.Hr},this.Hr.x=-1,this.Hr.y=-1,this.Ir=null},this.Kr=i=>{this.cn(i),this.un(i)},this.jr=i=>{this.cn(i),this.fn(i)},this.Yr=i=>{this.cn(i),this.dn(i)},this.qr=i=>{this.cn(i),this.pn(i)},t.addEventListener("mousemove",this.Xr,{passive:!0}),t.addEventListener("mouseleave",this.Wr,{passive:!0}),t.addEventListener("mousedown",this.Kr,{passive:!0}),t.addEventListener("mouseup",this.jr,{passive:!0}),t.addEventListener("click",this.Yr,{passive:!0}),t.addEventListener("wheel",this.qr,{passive:!1}),this.Vr=!0}_n(){if(!this.Vr)return;const t=this.er.canvas;t.removeEventListener("mousemove",this.Xr),t.removeEventListener("mouseleave",this.Wr),t.removeEventListener("mousedown",this.Kr),t.removeEventListener("mouseup",this.jr),t.removeEventListener("click",this.Yr),t.removeEventListener("wheel",this.qr),this.Vr=!1}hn(){if(this.Vr)try{if(this.Ir){const t=new MouseEvent("mousemove",{clientX:this.Ir.x,clientY:this.Ir.y,bubbles:!1,cancelable:!1});this.cn(t)}else this.Hr.x!==-1&&this.Hr.y!==-1&&(this.Hr.x>=this.Or.cols||this.Hr.y>=this.Or.rows)&&(this.Hr.x=-1,this.Hr.y=-1)}catch{this.Hr.x=-1,this.Hr.y=-1}}mn(t){this.Zr=t}vn(t){this.Qr=t}gn(t){this.Jr=t}yn(t){this.tn=t}An(t){this.sn=t}wn(){return{x:this.Hr.x,y:this.Hr.y}}ln(t){if(this.tn&&!this.rn()){const i={position:{...this.Hr},previousPosition:{...this.Gr},originalEvent:t};this.tn(i)}}un(t){if(this.Qr&&!this.rn()){const i={position:{...this.Hr},previousPosition:{...this.Gr},button:t.button,originalEvent:t};this.Qr(i)}}fn(t){if(this.Jr&&!this.rn()){const i={position:{...this.Hr},previousPosition:{...this.Gr},button:t.button,originalEvent:t};this.Jr(i)}}dn(t){if(this.Zr&&!this.rn()){const i={position:{...this.Hr},previousPosition:{...this.Gr},button:t.button,originalEvent:t};this.Zr(i)}}pn(t){if(this.sn&&!this.rn()){const i={position:{...this.Hr},previousPosition:{...this.Gr},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.sn(i)}}cn(t){const i=this.er.canvas;this.Gr={...this.Hr},this.Ir={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,o=t.clientY-r.top,h=i.width/r.width,a=o*(i.height/r.height),u=n*h-this.Or.offsetX,f=a-this.Or.offsetY,g=Math.floor(u/this.Or.cellWidth),d=Math.floor(f/this.Or.cellHeight);g>=0&&g<this.Or.cols&&d>=0&&d<this.Or.rows?(this.Hr.x=g,this.Hr.y=d):(this.Hr.x=-1,this.Hr.y=-1)}}const kt=Object.freeze(Object.defineProperty({__proto__:null,MouseManager:lt},Symbol.toStringTag,{value:"Module"}));class ut{constructor(){c(this,"Cn",new Map);c(this,"bn",null);c(this,"xn",null);c(this,"Mn");c(this,"Fn");c(this,"Vr",!1);c(this,"Rn");c(this,"zn");c(this,"Tn",{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"})}an(){this.Vr||(this.Mn=t=>{this.Pn(t)},this.Fn=t=>{this.Sn(t)},window.addEventListener("keydown",this.Mn,{passive:!1}),window.addEventListener("keyup",this.Fn,{passive:!1}),this.Vr=!0)}_n(){this.Vr&&(window.removeEventListener("keydown",this.Mn),window.removeEventListener("keyup",this.Fn),this.Vr=!1,this.Cn.clear(),this.bn=null,this.xn=null)}vn(t){this.Rn=t}gn(t){this.zn=t}$n(t){const i=this.En(t),r=this.Cn.get(t)||this.Cn.get(i);return(r==null?void 0:r.isPressed)||!1}Dn(){return this.bn}kn(){return this.xn}Bn(){const t=[];for(const[i,r]of this.Cn)r.isPressed&&t.push(i);return t}Ln(){return{ctrl:this.$n("Control"),shift:this.$n("Shift"),alt:this.$n("Alt"),meta:this.$n("Meta")}}On(){this.Cn.clear(),this.bn=null,this.xn=null}Pn(t){const i=t.key,r=Date.now();this.Cn.has(i)||this.Cn.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.Cn.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.bn=i,this.Rn)){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.Rn(o)}}Sn(t){const i=t.key,r=Date.now();this.Cn.has(i)||this.Cn.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.Cn.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.xn=i,this.zn){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.zn(o)}}En(t){return this.Tn[t]||t.toLowerCase()}}const Kt=Object.freeze(Object.defineProperty({__proto__:null,KeyboardManager:ut},Symbol.toStringTag,{value:"Module"}));class ft{constructor(t,i){c(this,"er");c(this,"Hn");c(this,"Or");c(this,"Gn",new Map);c(this,"In",new Map);c(this,"Nn",new Map);c(this,"Xn",null);c(this,"Wn");c(this,"Kn");c(this,"jn");c(this,"Yn");c(this,"qn");c(this,"Vn");c(this,"Vr",!1);c(this,"Zn");c(this,"Qn");c(this,"Jn");c(this,"so");c(this,"eo");c(this,"io");c(this,"ro");c(this,"no");c(this,"oo");c(this,"ho");c(this,"ao",320);c(this,"co",350);c(this,"lo",10);c(this,"uo",550);c(this,"fo",14);c(this,"do",48);c(this,"po",650);c(this,"_o",.02);c(this,"mo",2);c(this,"vo",600);c(this,"yo",0);c(this,"Ao",null);this.er=t,this.Hn=i;const r=this.er.canvas;this.Wn=r.style.touchAction,this.Kn=r.style.userSelect,r.style.touchAction||(r.style.touchAction="none"),r.style.userSelect||(r.style.userSelect="none")}Ki(t){this.Or=t,this.wo()}an(){if(this.Vr)return;const t=this.er.canvas;this.jn=i=>{this.Co(i)},this.Yn=i=>{this.bo(i)},this.qn=i=>{this.xo(i)},this.Vn=i=>{this.Mo(i)},t.addEventListener("touchstart",this.jn,{passive:!1}),t.addEventListener("touchmove",this.Yn,{passive:!1}),t.addEventListener("touchend",this.qn,{passive:!1}),t.addEventListener("touchcancel",this.Vn,{passive:!1}),this.Vr=!0}_n(){if(!this.Vr)return;const t=this.er.canvas;t.removeEventListener("touchstart",this.jn),t.removeEventListener("touchmove",this.Yn),t.removeEventListener("touchend",this.qn),t.removeEventListener("touchcancel",this.Vn),this.Vr=!1,this.Xn=null,this.Gn.clear(),this.In.clear(),this.Nn.forEach(i=>{i.longPressTimer!==null&&window.clearTimeout(i.longPressTimer)}),this.Nn.clear(),this.Ao=null,this.yo=0,t.style.touchAction=this.Wn,t.style.userSelect=this.Kn}wo(){if(!this.Or||this.Gn.size===0)return;const t=new Map;for(const i of this.Gn.values()){const r=this.Fo(i.clientX,i.clientY,i.id,i);t.set(i.id,r)}this.Gn=t}Ro(){return Array.from(this.Gn.values()).map(t=>({...t}))}zo(t){this.Zn=t}yn(t){this.Qn=t}To(t){this.Jn=t}Po(t){this.so=t}So(t){this.eo=t}$o(t){this.io=t}Eo(t){this.ro=t}Do(t){this.no=t}ko(t){this.oo=t}Bo(t){this.ho=t}Co(t){var n;if(!this.Or)return;t.preventDefault(),(n=this.Hn)==null||n.en(this.vo);const i=performance.now(),r=this.Lo(t.changedTouches);for(const o of r){const h=this.Gn.get(o.id);h&&this.In.set(o.id,this.Oo(h)),this.Gn.set(o.id,o);const a={id:o.id,startPosition:o,lastPosition:o,startTime:i,lastTime:i,longPressTimer:null,longPressFired:!1};this.ro&&(a.longPressTimer=window.setTimeout(()=>{const u=this.Gn.get(o.id);u&&(a.longPressFired=!0,this.ro({touch:this.Oo(u),duration:performance.now()-a.startTime,originalEvent:t}))},this.uo)),this.Nn.set(o.id,a),this.Zn&&this.Zn(this.Ho(o,t,void 0,i))}this.Gn.size===2&&this.Go()}bo(t){var n;if(!this.Or)return;t.preventDefault(),(n=this.Hn)==null||n.en(this.vo);const i=performance.now(),r=this.Lo(t.changedTouches);for(const o of r){const h=this.Gn.get(o.id),a=h?this.Oo(h):void 0;a&&this.In.set(o.id,a),this.Gn.set(o.id,o);const u=this.Nn.get(o.id);u&&(u.lastPosition=o,u.lastTime=i,a)&&this.Io(a,o,!0)>this.fo&&u.longPressTimer!==null&&(window.clearTimeout(u.longPressTimer),u.longPressTimer=null),this.Qn&&this.Qn(this.Ho(o,t,a,i))}this.Gn.size===2?this.No(t):this.Xn=null}xo(t){if(!this.Or)return;t.preventDefault();const i=performance.now(),r=this.Lo(t.changedTouches);for(const n of r){const o=this.Gn.get(n.id),h=o?this.Oo(o):void 0,a=this.Nn.get(n.id);a&&a.longPressTimer!==null&&(window.clearTimeout(a.longPressTimer),a.longPressTimer=null),this.Jn&&this.Jn(this.Ho(n,t,h,i)),a&&this.Xo(a,t),this.Nn.delete(n.id),this.In.delete(n.id),this.Gn.delete(n.id)}this.Gn.size<2&&(this.Xn=null)}Mo(t){if(!this.Or)return;t.preventDefault();const i=performance.now(),r=this.Lo(t.changedTouches);for(const n of r){const o=this.Gn.get(n.id),h=o?this.Oo(o):void 0,a=this.Nn.get(n.id);a&&a.longPressTimer!==null&&(window.clearTimeout(a.longPressTimer),a.longPressTimer=null),this.so&&this.so(this.Ho(n,t,h,i)),this.Nn.delete(n.id),this.In.delete(n.id),this.Gn.delete(n.id)}this.Gn.size<2&&(this.Xn=null)}Lo(t){const i=[];for(let r=0;r<t.length;r+=1){const n=t.item(r);n&&i.push(this.Wo(n))}return i}Wo(t){return this.Fo(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})}Fo(t,i,r,n){const o=this.er.canvas,h=o.getBoundingClientRect(),a=t-h.left,u=i-h.top,f=o.width/h.width,g=u*(o.height/h.height),d=a*f-this.Or.offsetX,p=g-this.Or.offsetY,y=Math.floor(d/this.Or.cellWidth),A=Math.floor(p/this.Or.cellHeight),m=y>=0&&y<this.Or.cols&&A>=0&&A<this.Or.rows;return{id:r,x:m?y:-1,y:m?A:-1,clientX:t,clientY:i,pressure:n.pressure,radiusX:n.radiusX,radiusY:n.radiusY,rotationAngle:n.rotationAngle}}Ho(t,i,r,n){const o=this.Nn.get(t.id),h=Array.from(this.In.values()).map(f=>this.Oo(f)),a=Array.from(this.Gn.values()).map(f=>this.Oo(f)),u=this.Lo(i.changedTouches);return{touch:this.Oo(t),previousTouch:r?this.Oo(r):void 0,touches:a,previousTouches:h,changedTouches:u,deltaTime:o?n-o.lastTime:0,originalEvent:i}}Go(){if(this.Gn.size!==2)return void(this.Xn=null);const t=Array.from(this.Gn.values()),[i,r]=t,n=this.Io(i,r,!1),o=this.Ko(i,r);this.Xn={ids:[i.id,r.id],initialDistance:Math.max(n,1e-4),initialAngle:o,lastScale:1,lastRotation:0}}No(t){if(this.Xn||this.Go(),!this.Xn)return;const[i,r]=this.Xn.ids,n=this.Gn.get(i),o=this.Gn.get(r);if(!n||!o)return;const h=this.Io(n,o,!1)/this.Xn.initialDistance,a=h-this.Xn.lastScale;this.oo&&Math.abs(a)>this._o&&(this.oo({touches:[this.Oo(n),this.Oo(o)],scale:h,deltaScale:a,center:this.jo(n,o),originalEvent:t}),this.Xn.lastScale=h);let u=this.Ko(n,o)-this.Xn.initialAngle;u=(u+180)%360-180;const f=u-this.Xn.lastRotation;this.ho&&Math.abs(f)>this.mo&&(this.ho({touches:[this.Oo(n),this.Oo(o)],rotation:u,deltaRotation:f,center:this.jo(n,o),originalEvent:t}),this.Xn.lastRotation=u)}jo(t,i){const r=(t.clientX+i.clientX)/2,n=(t.clientY+i.clientY)/2,o=this.Fo(r,n,-1,{id:-1,x:-1,y:-1,clientX:r,clientY:n});return{x:o.x,y:o.y}}Xo(t,i){const r=performance.now(),n=r-t.startTime,o=this.Io(t.startPosition,t.lastPosition,!0);if(!t.longPressFired&&n<=this.ao&&o<=this.lo)this.Yo(t.lastPosition,r)&&this.io?this.io({touch:this.Oo(t.lastPosition),taps:2,originalEvent:i}):this.eo&&this.eo({touch:this.Oo(t.lastPosition),taps:1,originalEvent:i});else if(!t.longPressFired&&n<=this.po&&o>=this.do){const h={x:t.lastPosition.clientX-t.startPosition.clientX,y:t.lastPosition.clientY-t.startPosition.clientY},a=Math.max(Math.hypot(h.x,h.y),1e-4),u={x:h.x/a,y:h.y/a},f={x:h.x/n,y:h.y/n};this.no&&this.no({touch:this.Oo(t.lastPosition),direction:u,distance:a,velocity:f,originalEvent:i})}this.yo=r,this.Ao=this.Oo(t.lastPosition)}Yo(t,i){return!!this.Ao&&!(i-this.yo>this.co)&&this.Io(t,this.Ao,!0)<=this.lo}Oo(t){return{...t}}Io(t,i,r){return r?Math.hypot(t.clientX-i.clientX,t.clientY-i.clientY):Math.hypot(t.x-i.x,t.y-i.y)}Ko(t,i){return 180*Math.atan2(i.clientY-t.clientY,i.clientX-t.clientX)/Math.PI}}const jt=Object.freeze(Object.defineProperty({__proto__:null,TouchManager:ft},Symbol.toStringTag,{value:"Module"})),qt=l=>class extends l{rotate(t=0,i=0,r=0){this.xt.state.st(t),this.xt.state.et(i),this.xt.state.it(r)}rotateX(t){this.xt.state.st(t)}rotateY(t){this.xt.state.et(t)}rotateZ(t){this.xt.state.it(t)}push(){this.xt.state.G()}pop(){this.xt.state.Z()}rect(t,i,r=1,n=1){this.xt.Ne(t,i,r,n)}point(t,i){this.xt.Ne(t,i,1,1)}line(t,i,r,n){this.xt.Xe(t,i,r,n)}lineWeight(t){this.xt.state.tt(t)}background(t,i=t,r=t,n=255){this.xt.Ve(t,i,r,n)}char(t){this.xt.state.rt(this.$i.Pi(t))}charColor(t,i,r,n=255){this.xt.state.nt(t,i,r,n)}cellColor(t,i,r,n=255){this.xt.state.ot(t,i,r,n)}flipX(t){this.xt.state.ht(t)}flipY(t){this.xt.state.ct(t)}charRotation(t){this.xt.state.ut(t)}invert(t){this.xt.state.lt(t)}clear(){this.xt.Ve(0,0,0,0)}ellipse(t,i,r,n){this.xt.We(t,i,r/2,n/2)}triangle(t,i,r,n,o,h){this.xt.Ke(t,i,r,n,o,h)}bezierCurve(t,i,r,n,o,h,a,u){this.xt.je(t,i,r,n,o,h,a,u)}arc(t,i,r,n,o,h){this.xt.qe(t,i,r,n,o,h)}shader(t){this.xt.Be(t)}setUniform(t,i){this.xt.Kt(t,i)}setUniforms(t){this.xt.Le(t)}createFilterShader(t){return this.xt.hs(t)}createFramebuffer(t){return this.xt.Ye(t.width,t.height,5,{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"})}image(t,i,r,n,o){if(t.textures){const h=t;this.xt.Oe(h,i,r,n??h.width,o??h.height)}else{const h=t;this.xt.He(h,i,r,n??Math.floor(this.Or.cols/2),o??Math.floor(this.Or.rows/2))}}async loadImage(t){if(typeof t!="string")return H.Rr(this.xt,t,n=>this.$i.Si(n));const i=t,r=await new Promise((n,o)=>{const h=new Image;h.crossOrigin="anonymous",h.onload=()=>n(h),h.onerror=a=>o(a),h.src=i});return H.Rr(this.xt,r,n=>this.$i.Si(n))}},Zt=l=>class extends l{async loadFont(t){return this.$i.Vi(t).then(()=>{const i=this.$i.maxGlyphDimensions;this.Or.hr(i.width,i.height),this.qo.resize(this.Or.cols,this.Or.rows),this.xt.Ze(),this.Hn.hn()})}fontSize(t){if(!X.v(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.$i.fontSize===t)return;this.$i.qi(t);const i=this.$i.maxGlyphDimensions;this.Or.hr(i.width,i.height),this.qo.resize(this.Or.cols,this.Or.rows),this.xt.Ze(),this.Hn.hn()}glyphColor(t){return this.$i.Pi(t)}glyphColors(t){return this.$i.Si(t)}},Qt=l=>class extends l{get frameCount(){return this.Vo.frameCount}set frameCount(t){this.Vo.frameCount=t}frameRate(t){return t===void 0?this.Vo.currentFrameRate:this.Vo.frameRate(t,()=>this.Zo())}noLoop(){this.Vo.pause()}loop(){this.Vo.resume(()=>this.Zo())}redraw(t=1){if(X.v(typeof t=="number"&&t>0&&Number.isInteger(t),"Redraw count must be a positive integer.",{method:"redraw",providedValue:t}))for(let i=0;i<t;i++)this.Zo()}isLooping(){return this.Vo.isLooping}},Jt=l=>class extends l{constructor(...t){super(...t)}mouseClicked(t){this.Hn.mn(t)}mousePressed(t){this.Hn.vn(t)}mouseReleased(t){this.Hn.gn(t)}mouseMoved(t){this.Hn.yn(t)}mouseScrolled(t){this.Hn.An(t)}get mouse(){return this.Hn.wn()}cursor(t){this.Hn.nn(t)}},$t=l=>class extends l{constructor(...t){super(...t)}touchStarted(t){this.Qo.zo(t)}touchMoved(t){this.Qo.yn(t)}touchEnded(t){this.Qo.To(t)}touchCancelled(t){this.Qo.Po(t)}tap(t){this.Qo.So(t)}doubleTap(t){this.Qo.$o(t)}longPress(t){this.Qo.Eo(t)}swipe(t){this.Qo.Do(t)}pinch(t){this.Qo.ko(t)}rotateGesture(t){this.Qo.Bo(t)}get touches(){return this.Qo.Ro()}},te=l=>class extends l{constructor(...t){super(...t)}keyPressed(t){this.Jo.vn(t)}keyReleased(t){this.Jo.gn(t)}isKeyPressed(t){return this.Jo.$n(t)}get lastKeyPressed(){return this.Jo.Dn()}get lastKeyReleased(){return this.Jo.kn()}get pressedKeys(){return this.Jo.Bn()}get modifierState(){return this.Jo.Ln()}};class ee{constructor(t){c(this,"th");c(this,"sh",new Map);c(this,"eh",[]);c(this,"ih",new Map);c(this,"rh",new Map);this.th=t}async nh(t){for(const i of t){if(this.sh.has(i.name))return void console.warn(`[textmode.js] Plugin "${i.name}" is already installed.`);const r=this.oh(i.name);try{await i.install(this.th,r)}catch(n){throw this.hh(i.name),n}this.sh.set(i.name,i),this.eh.push(i.name)}}async ah(t){const i=this.sh.get(t);if(!i)return;const r=this.oh(t);if(i.uninstall)try{await i.uninstall(this.th,r)}catch(n){console.error(`[textmode.js] Error while uninstalling plugin "${t}":`,n)}this.sh.delete(t),this.eh.splice(this.eh.indexOf(t),1),this.hh(t)}runPreDrawHooks(){this.uh(this.ih,"preDraw")}runPostDrawHooks(){this.uh(this.rh,"postDraw")}async fh(){const t=[...this.sh.keys()];for(const i of t)await this.ah(i)}oh(t){return{...this.th.dh(),registerPreDrawHook:i=>this.ph(this.ih,t,i),registerPostDrawHook:i=>this.ph(this.rh,t,i)}}ph(t,i,r){const n=t.get(i)??new Set;return n.add(r),t.set(i,n),()=>{const o=t.get(i);o&&(o.delete(r),o.size===0&&t.delete(i))}}hh(t){this.ih.delete(t),this.rh.delete(t)}uh(t,i){for(const r of this.eh){const n=t.get(r);if(n)for(const o of n)try{o()}catch(h){console.error(`[textmode.js] Plugin "${r}" ${i} hook failed:`,h)}}}}class ie{constructor(){c(this,"xt");c(this,"$i");c(this,"er");c(this,"Or");c(this,"Vo");c(this,"Hn");c(this,"Qo");c(this,"Jo");c(this,"_h");c(this,"qo");c(this,"mh");c(this,"gh");c(this,"yh")}Zo(){}}class dt extends function(i,...r){return r.reduce((n,o)=>o(n),i)}(ie,qt,Zt,Qt,Jt,$t,te){constructor(i={}){super();c(this,"Ah");c(this,"wh",!1);c(this,"Ch",!1);c(this,"bh",!1);c(this,"xh",()=>{});c(this,"Mh",()=>{});c(this,"Fh",()=>{});c(this,"Rh");c(this,"lr");c(this,"cr",!1);c(this,"zh");this.Ah=new ee(this),this.cr=i.overlay??!1,this.er=new ct(i),this.xt=new Lt(this.er.gr()),this.$i=new ht(this.xt,i.fontSize??16),this.Vo=new Wt(i.frameRate??60),this.Hn=new lt(this.er),this.Qo=new ft(this.er,this.Hn),this.Jo=new ut,this._h=this.xt.Pt(),this.mh=this.xt.rs(),this.Th(i)}async Th(i){await this.$i.Ki(i.fontSource);const r=this.$i.maxGlyphDimensions;this.Or=new at(this.er.canvas,r.width,r.height),this.Hn.Ki(this.Or),this.Qo.Ki(this.Or),this.qo=this.xt.Ye(this.Or.cols,this.Or.rows,5),this.gh=this.xt.Ye(this.Or.width,this.Or.height,1),this.cr&&(this.zh=H.Rr(this.xt,this.er.targetCanvas,n=>this.$i.Si(n))),this.yh=this.xt.cs(rt,"precision mediump float;uniform sampler2D Ua;uniform vec2 Ub;uniform vec2 Uc;uniform vec2 Ud;void main(){vec2 A=gl_FragCoord.xy-Uc;vec2 B=A*(Ub/Ud);vec2 C=(floor(B)+0.5)/Ub;gl_FragColor=texture2D(Ua,C);}"),this.Ph(),await this.Ah.nh(i.plugins??[]),this.xh(),this.Vo.start(()=>this.Zo())}dh(){return{renderer:this.xt,font:this.$i,grid:this.Or,canvas:this.er,drawFramebuffer:this.qo,asciiFramebuffer:this.gh,flushDrawCommands:()=>{this.xt.St(this._h)}}}Ph(){this.Rh=()=>{this.cr&&this.resizeCanvas(this.er.targetCanvas.width,this.er.targetCanvas.height),this.Fh()},window.addEventListener("resize",this.Rh),this.Hn.an(),this.Qo.an(),this.Jo.an(),window.addEventListener("blur",()=>{this.Jo.On()}),window.ResizeObserver&&this.cr&&(this.lr=new ResizeObserver(()=>{this.resizeCanvas(this.er.targetCanvas.width,this.er.targetCanvas.height)}),this.lr.observe(this.er.targetCanvas))}Zo(){this.Ch=!0;try{if(this.Vo.measureFrameRate(),this.Vo.incrementFrame(),this.cr){const r=this.xt.context;r.bindTexture(r.TEXTURE_2D,this.zh.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.er.targetCanvas),r.bindTexture(r.TEXTURE_2D,null)}this.Ah.runPreDrawHooks(),this.qo.begin(),this.xt.ke(this._h),this.Mh(),this.xt.St(this._h),this.qo.end(),this.gh.begin(),this.xt.ke(this.mh),this.mh.Wt({U0:this.$i.fontFramebuffer,U1:[this.$i.textureColumns,this.$i.textureRows],U2:this.qo.textures[0],U3:this.qo.textures[1],U4:this.qo.textures[2],U5:this.qo.textures[4],U6:this.qo.textures[3],U7:[this.Or.cols,this.Or.rows],U8:[this.gh.width,this.gh.height],U9:this.gh.width/this.gh.height}),this.xt.Ie(0,0,this.er.width,this.er.height),this.gh.end();const i=this.xt.state.canvasBackgroundColor;this.xt.Ys(i[0],i[1],i[2],i[3]),this.xt.ke(this.yh),this.yh.Wt({Ua:this.gh.textures[0],Ub:[this.gh.width,this.gh.height],Uc:[this.Or.offsetX,this.Or.offsetY],Ud:[this.Or.width,this.Or.height]}),this.xt.Ie(this.Or.offsetX,this.Or.offsetY,this.Or.width,this.Or.height),this.Ah.runPostDrawHooks()}catch(i){console.error("[textmode.js] Error during render:",i)}finally{this.Ch=!1,this.wh&&!this.bh&&this.Sh()}}setup(i){this.xh=i}draw(i){this.Mh=i}windowResized(i){this.Fh=i}resizeCanvas(i,r){this.er.vr(i,r),this.Or.nr(),this.qo.resize(this.Or.cols,this.Or.rows),this.gh.resize(this.Or.width,this.Or.height),this.xt.Ze(),this.Hn.hn(),this.Qo.wo(),this.Zo()}destroy(){this.bh||this.wh||(this.wh=!0,this.Vo.stop(),this.noLoop(),this.Ch||this.Sh())}Sh(){this.bh||(this.wh=!1,this.Ah.fh().catch(i=>{console.error("[textmode.js] Error while disposing plugins:",i)}),window.removeEventListener("resize",this.Rh),this.Hn._n(),this.Qo._n(),this.Jo._n(),this.$i.Dt(),this.xt.Dt(),this.gh.Dt(),this.yh.Dt(),this.er.Dt(),this.zh&&this.zh.Dt(),this.bh=!0)}get grid(){return this.Or}get font(){return this.$i}get width(){return this.er.width}get height(){return this.er.height}get canvas(){return this.er.canvas}get drawFramebuffer(){return this.qo}get isDisposed(){return this.bh}get overlay(){return this.zh}}class Q{constructor(){}static create(t={}){return new dt(t)}static setErrorLevel(t){X.A(t)}static get version(){return"0.4.1-beta.1"}}const se=Object.freeze(Object.defineProperty({__proto__:null,keyboard:Kt,mouse:kt,touch:jt},Symbol.toStringTag,{value:"Module"})),re=Q.create,ne=Q.setErrorLevel,oe=Q.version;C.TextmodeCanvas=ct,C.TextmodeErrorLevel=S,C.TextmodeFont=ht,C.TextmodeFramebuffer=K,C.TextmodeGrid=at,C.TextmodeImage=H,C.Textmodifier=dt,C.create=re,C.input=se,C.setErrorLevel=ne,C.textmode=Q,C.version=oe,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):e((s=typeof globalThis<"u"?globalThis:s||self).textmode={});
|
|
7
|
+
`}static o(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="number"||typeof t=="boolean")return t+"";if(Array.isArray(t))return t.length===0?"[]":t.length<=5?`[${t.map(i=>x.o(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>x.o(i)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const i=Object.keys(t);return i.length===0?"{}":i.length<=3?`{ ${i.map(r=>`${r}: ${x.o(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${x.o(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var X=(o=>(o[o.SILENT=0]="SILENT",o[o.WARNING=1]="WARNING",o[o.ERROR=2]="ERROR",o[o.THROW=3]="THROW",o))(X||{});const G=class G{constructor(){l(this,"l",{globalLevel:3})}static u(){return G.h||(G.h=new G),G.h}v(t,i){const r="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",h="color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";switch(this.l.globalLevel){case 0:return!1;case 1:return console.group(r,h),console.warn(x.i(t,i)),console.groupEnd(),!1;case 2:return console.group(r,h),console.error(x.i(t,i)),console.groupEnd(),!1;default:throw new x(t,i)}}m(t,i,r){return!!t||(this.v(i,r),!1)}_(t){this.l.globalLevel=t}};l(G,"h",null);let ft=G;const Z=ft.u();class V{constructor(t,i,r){l(this,"A");l(this,"C");l(this,"M",new Map);l(this,"F",new Map);l(this,"$",0);this.A=t,this.C=this.U(i,r),this.P()}P(){const t=this.A.getProgramParameter(this.C,this.A.ACTIVE_UNIFORMS);for(let i=0;i<t;i++){const r=this.A.getActiveUniform(this.C,i);if(r){const h=r.name.replace(/\[0\]$/,""),n=this.A.getUniformLocation(this.C,h);n&&(this.M.set(h,n),this.F.set(h,{type:r.type,size:r.size}))}}}U(t,i){const r=this.R(this.A.VERTEX_SHADER,t),h=this.R(this.A.FRAGMENT_SHADER,i),n=this.A.createProgram();if(this.A.attachShader(n,r),this.A.attachShader(n,h),this.A.linkProgram(n),!this.A.getProgramParameter(n,this.A.LINK_STATUS)){const a=this.A.getProgramInfoLog(n);throw Error("Shader program link error: "+a)}return this.A.deleteShader(r),this.A.deleteShader(h),n}R(t,i){const r=this.A.createShader(t);if(this.A.shaderSource(r,i),this.A.compileShader(r),!this.A.getShaderParameter(r,this.A.COMPILE_STATUS)){const h=this.A.getShaderInfoLog(r);throw this.A.deleteShader(r),Error("Shader compilation error: "+h)}return r}S(){this.A.useProgram(this.C),this.k()}k(){this.$=0}I(t){for(const i in t)this.O(i,t[i])}O(t,i){var u,f;const r=this.M.get(t);if(!r)return;const h=this.F.get(t);if(!h)return;const{type:n,size:a}=h,c=this.A;if(i instanceof WebGLTexture){const d=this.$++;return c.uniform1i(r,d),c.activeTexture(c.TEXTURE0+d),void c.bindTexture(c.TEXTURE_2D,i)}if(i instanceof Q){const d=this.$++;return c.uniform1i(r,d),c.activeTexture(c.TEXTURE0+d),void c.bindTexture(c.TEXTURE_2D,i.textures[0])}if(typeof i!="number")if(typeof i!="boolean")if(Array.isArray(i[0])){const d=i.flat(),g={[c.FLOAT_VEC2]:()=>c.uniform2fv(r,d),[c.FLOAT_VEC3]:()=>c.uniform3fv(r,d),[c.FLOAT_VEC4]:()=>c.uniform4fv(r,d)};(u=g[n])==null||u.call(g)}else{const d=i,g={[c.FLOAT]:()=>a>1?c.uniform1fv(r,d):c.uniform1f(r,d[0]),[c.FLOAT_VEC2]:()=>c.uniform2fv(r,d),[c.FLOAT_VEC3]:()=>c.uniform3fv(r,d),[c.FLOAT_VEC4]:()=>c.uniform4fv(r,d),[c.INT]:()=>a>1?c.uniform1iv(r,d):c.uniform1i(r,d[0]),[c.INT_VEC2]:()=>c.uniform2iv(r,d),[c.INT_VEC3]:()=>c.uniform3iv(r,d),[c.INT_VEC4]:()=>c.uniform4iv(r,d),[c.BOOL]:()=>c.uniform1iv(r,d),[c.FLOAT_MAT2]:()=>c.uniformMatrix2fv(r,!1,d),[c.FLOAT_MAT3]:()=>c.uniformMatrix3fv(r,!1,d),[c.FLOAT_MAT4]:()=>c.uniformMatrix4fv(r,!1,d)};(f=g[n])==null||f.call(g)}else c.uniform1i(r,i?1:0);else n===c.INT||n===c.BOOL?c.uniform1i(r,i):c.uniform1f(r,i)}get L(){return this.C}D(){this.A.deleteProgram(this.C)}}function bt(o,t,i,r){return 180*Math.atan2(r-t,i-o)/Math.PI}function q(o,t,i,r){return Math.hypot(i-o,r-t)}function xt(o){return(o%360+360)%360/360}function Rt(o,t,i){o.bindTexture(o.TEXTURE_2D,t),o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,1),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,o.RGBA,o.UNSIGNED_BYTE,i),o.bindTexture(o.TEXTURE_2D,null)}function it(o,t,i,r,h){o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,t),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MAG_FILTER,i),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,r),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,h)}function dt(o,t,i,r,h,n=0,a=WebGL2RenderingContext.FLOAT,c=!1){o.enableVertexAttribArray(t),o.vertexAttribPointer(t,i,a,c,r,h),o.vertexAttribDivisor(t,n)}function Ft(o,t,i,r,h){o.bindBuffer(t,i),o.bufferData(t,r,h),o.bindBuffer(t,null)}const rt=`#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,i,r=i,h=1,n={},a){l(this,"H");l(this,"G");l(this,"l");l(this,"A");l(this,"N");l(this,"X",[]);l(this,"Y",null);l(this,"K");l(this,"j");l(this,"Z",null);l(this,"W",new Map);var c;this.H=i,this.G=r,this.A=t,this.K=(c=8,Math.min(Math.max(h,1),c)),this.j=a,this.l={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",depth:!0,...n},K.q||(K.q=new V(t,rt,`#version 300 es
|
|
9
|
+
precision highp float;in vec2 v_uv;uniform sampler2D Uc;uniform sampler2D Ud;uniform sampler2D Ue;uniform vec2 Uf;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;void main(){vec2 A=vec2(v_uv.x,1.-v_uv.y);vec2 B=A*Uf;vec2 C=(floor(B)+0.5f)/Uf;vec4 D=texture(Uc,C);vec4 E=texture(Ud,C);if(E.a==0.){discard;}vec4 F=texture(Ue,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;}`));const u=t.getParameter(t.MAX_DRAW_BUFFERS),f=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.K=Math.min(this.K,u,f),this.N=t.createFramebuffer(),this.V(),this.J(),this.l.depth&&this.tt()}V(){const t=this.A,i=this.l.filter==="linear"?t.LINEAR:t.NEAREST,r=this.l.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE,h=this.l.type==="float"?t.FLOAT:t.UNSIGNED_BYTE,n=h===t.FLOAT?t.RGBA32F:t.RGBA8,a=t.RGBA;for(let c=0;c<this.K;c++){const u=t.createTexture();t.bindTexture(t.TEXTURE_2D,u),it(t,i,i,r,r),t.texImage2D(t.TEXTURE_2D,0,n,this.H,this.G,0,a,h,null),this.X.push(u)}t.bindTexture(t.TEXTURE_2D,null)}J(){const t=this.A;if(t.bindFramebuffer(t.FRAMEBUFFER,this.N),this.K===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.X[0],0);else{const i=[];for(let r=0;r<this.K;r++){const h=t.COLOR_ATTACHMENT0+r;t.framebufferTexture2D(t.FRAMEBUFFER,h,t.TEXTURE_2D,this.X[r],0),i.push(h)}t.drawBuffers(i)}t.bindFramebuffer(t.FRAMEBUFFER,null)}tt(){const t=this.A;this.Y=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,this.Y),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT24,this.H,this.G),t.bindFramebuffer(t.FRAMEBUFFER,this.N),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,this.Y),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindRenderbuffer(t.RENDERBUFFER,null)}st(t){Rt(this.A,this.X[0],t)}resize(t,i){this.H=t,this.G=i,this.W.clear();const r=this.A,h=this.l.type==="float"?r.FLOAT:r.UNSIGNED_BYTE,n=h===r.FLOAT?r.RGBA32F:r.RGBA8,a=r.RGBA;for(const c of this.X)r.bindTexture(r.TEXTURE_2D,c),r.texImage2D(r.TEXTURE_2D,0,n,this.H,this.G,0,a,h,null);r.bindTexture(r.TEXTURE_2D,null),this.Y&&(r.bindRenderbuffer(r.RENDERBUFFER,this.Y),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_COMPONENT24,this.H,this.G),r.bindRenderbuffer(r.RENDERBUFFER,null))}readPixels(t){const i=this.W.get(t);if(i)return i;const r=this.A,h=this.H,n=this.G,a=new Uint8Array(h*n*4),c=r.getParameter(r.READ_FRAMEBUFFER_BINDING);r.bindFramebuffer(r.READ_FRAMEBUFFER,this.N),r.readBuffer(r.COLOR_ATTACHMENT0+t),r.readPixels(0,0,h,n,r.RGBA,r.UNSIGNED_BYTE,a),r.bindFramebuffer(r.READ_FRAMEBUFFER,c);const u=4*h,f=new Uint8Array(a.length);for(let d=0;d<n;d++){const g=(n-1-d)*u,p=d*u;f.set(a.subarray(g,g+u),p)}return this.W.set(t,f),f}begin(){const t=this.A;this.W.clear(),this.j.et(),this.j.it(this.N,this.H,this.G),this.l.depth&&t.clear(t.DEPTH_BUFFER_BIT),this.j.state.rt()}end(){this.j.state.nt(),this.j.ot();const t=this.j.ht();this.j.it(t.framebuffer,t.viewport[2],t.viewport[3])}ct(){return this.Z||this.lt(),this.Z}lt(){if(!this.j)return;const t={Uc:this.X[0],Ud:this.X[1],Ue:this.X[2],Uf:[this.H,this.G]},i=K.q;this.Z=this.j.ft.ut(i,t,!0)}D(){const t=this.A;t.deleteFramebuffer(this.N);for(const i of this.X)t.deleteTexture(i);this.Y&&t.deleteRenderbuffer(this.Y)}get width(){return this.H}get height(){return this.G}get textures(){return this.X}get attachmentCount(){return this.K}};l(K,"q",null);let Q=K;const Pt=new WeakMap;function gt(o,t){Pt.set(o,t)}function Ct(o){return Pt.get(o)}function Y(o,t,i,r,h=255){o[0]=t/255,o[1]=(i??t)/255,o[2]=(r??t)/255,o[3]=h/255}class st{constructor(){l(this,"dt",1);l(this,"gt",0);l(this,"vt",0);l(this,"_t",0);l(this,"At",0);l(this,"yt",0);l(this,"wt",0);l(this,"bt",[0,0,0]);l(this,"Ct",[1,1,1,1]);l(this,"Mt",[0,0,0,1]);l(this,"xt",!1);l(this,"Ft",!1);l(this,"$t",!1);l(this,"Tt",0);l(this,"Pt",[0,0,0,1]);l(this,"Et",!1);l(this,"Rt",[]);l(this,"St",[])}static kt(){return{zt:1,It:0,Ot:0,Lt:0,At:0,yt:0,wt:0,Tt:0,Dt:!1,Bt:!1,$t:!1,Et:!1,Ht:[0,0,0],Gt:[1,1,1,1],Nt:[0,0,0,1]}}Xt(t){t.zt=this.dt,t.It=this.gt,t.Ot=this.vt,t.Lt=this._t,t.At=this.At,t.yt=this.yt,t.wt=this.wt,t.Dt=this.xt,t.Bt=this.Ft,t.$t=this.$t,t.Tt=this.Tt,t.Et=this.Et,t.Ht[0]=this.bt[0],t.Ht[1]=this.bt[1],t.Ht[2]=this.bt[2],t.Gt[0]=this.Ct[0],t.Gt[1]=this.Ct[1],t.Gt[2]=this.Ct[2],t.Gt[3]=this.Ct[3],t.Nt[0]=this.Mt[0],t.Nt[1]=this.Mt[1],t.Nt[2]=this.Mt[2],t.Nt[3]=this.Mt[3]}Yt(t){this.dt=t.zt,this.gt=t.It,this.vt=t.Ot,this._t=t.Lt,this.At=t.At,this.yt=t.yt,this.wt=t.wt,this.xt=t.Dt,this.Ft=t.Bt,this.$t=t.$t,this.Tt=t.Tt,this.Et=t.Et,this.bt[0]=t.Ht[0],this.bt[1]=t.Ht[1],this.bt[2]=t.Ht[2],this.Ct[0]=t.Gt[0],this.Ct[1]=t.Gt[1],this.Ct[2]=t.Gt[2],this.Ct[3]=t.Gt[3],this.Mt[0]=t.Nt[0],this.Mt[1]=t.Nt[1],this.Mt[2]=t.Nt[2],this.Mt[3]=t.Nt[3]}rt(){let t=this.St.pop();t||(t=st.kt()),this.Xt(t),this.Rt.push(t)}nt(){const t=this.Rt.pop();t?(this.Yt(t),this.St.push(t)):console.warn("pop() called without matching push()")}Kt(t){this.Xt(t)}jt(t){this.dt=Math.abs(t)}Zt(){this.gt=0,this.vt=0,this._t=0,this.At=0,this.yt=0,this.wt=0,this.Et=!1}Wt(t){t!==0&&(this.At+=t*Math.PI/180)}qt(t){t!==0&&(this.yt+=t*Math.PI/180)}Vt(t){t!==0&&(this.wt+=t*Math.PI/180)}Qt(t=0,i=0,r=0){t===0&&i===0&&r===0||(this.gt+=t,this.vt+=i,this._t+=r)}Jt(t){this.Qt(t,0,0)}ts(t){this.Qt(0,t,0)}ss(t){this.Qt(0,0,t)}es(t){this.bt[0]=t[0],this.bt[1]=t[1],this.bt[2]=t[2]}rs(t,i,r,h=255){Y(this.Ct,t,i,r,h)}ns(t,i,r,h=255){Y(this.Mt,t,i,r,h)}hs(t){this.xt=t}cs(t){this.Ft=t}ls(t){this.$t=t}us(t){this.Tt=xt(t)}fs(t,i,r,h){Y(this.Pt,t,i,r,h)}ds(t){this.Et=t}get canvasBackgroundColor(){return this.Pt}get useOrtho(){return this.Et}get rotationX(){return this.At}get rotationY(){return this.yt}get rotationZ(){return this.wt}}const At=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={ps:16,gs:WebGL2RenderingContext.TRIANGLES,vs:{_s:{size:2,offset:0},As:{size:2,offset:8}}};class kt{constructor(t){l(this,"A");l(this,"ws");l(this,"bs");this.A=t,this.ws=t.createBuffer(),this.bs=new Float32Array(At.length)}Cs(t,i,r,h){const n=this.A,a=Ct(this.A),c=a[2],u=a[3],f=t/c*2-1,d=(t+r)/c*2-1,g=1-(i+h)/u*2,p=1-i/u*2,m=At,v=this.bs;for(let A=0;A<m.length;A+=4){const E=m[A],y=m[A+1],T=m[A+2],w=m[A+3],R=f+(E+.5)*(d-f),b=g+(y+.5)*(p-g);v[A]=R,v[A+1]=b,v[A+2]=T,v[A+3]=w}n.bindBuffer(n.ARRAY_BUFFER,this.ws),n.bufferData(n.ARRAY_BUFFER,v,n.DYNAMIC_DRAW),n.enableVertexAttribArray(0),n.vertexAttribPointer(0,2,n.FLOAT,!1,16,0),n.drawArrays(n.TRIANGLES,0,6),n.disableVertexAttribArray(0),n.bindBuffer(n.ARRAY_BUFFER,null)}D(){this.A.deleteBuffer(this.ws)}}var P=(o=>(o.RECTANGLE="rectangle",o.LINE="line",o.ELLIPSE="ellipse",o.ARC="arc",o.TRIANGLE="triangle",o.BEZIER_CURVE="bezier_curve",o))(P||{});const Kt={rectangle:2,line:2,ellipse:2,triangle:2,arc:3,bezier_curve:4};class Wt{constructor(t){l(this,"A");l(this,"Ms",new Map);this.A=t}Fs(t,i,r,h){const n=this.A;let a=this.Ms.get(t);a||(a=new Map,this.Ms.set(t,a));let c=a.get(i)||null;if(!c){c=n.createVertexArray(),a.set(i,c),n.bindVertexArray(c),n.bindBuffer(n.ARRAY_BUFFER,h);const u=n.getAttribLocation(t,"A0");u!==-1&&dt(n,u,r.vs._s.size,r.ps,r.vs._s.offset,0,n.FLOAT,!1);const f=n.getAttribLocation(t,"A1");f!==-1&&dt(n,f,r.vs.As.size,r.ps,r.vs.As.offset,0,n.FLOAT,!1)}n.bindVertexArray(c)}$s(){this.A.bindVertexArray(null)}D(){for(const[,t]of this.Ms)for(const[,i]of t)i&&this.A.deleteVertexArray(i)}}const O=class O{static Ts(t,i,r=0){const h=i||new Float32Array(O.FLOATS_PER_INSTANCE);let n=r;h[n++]=t._s[0],h[n++]=t._s[1],h[n++]=t.Ps[0],h[n++]=t.Ps[1],h[n++]=t.Ht[0],h[n++]=t.Ht[1],h[n++]=t.Ht[2],h[n++]=t.Gt[0],h[n++]=t.Gt[1],h[n++]=t.Gt[2],h[n++]=t.Gt[3],h[n++]=t.Nt[0],h[n++]=t.Nt[1],h[n++]=t.Nt[2],h[n++]=t.Nt[3],h[n++]=t.Es[0],h[n++]=t.Es[1],h[n++]=t.Es[2],h[n++]=t.Tt;const a=t.Rs;h[n++]=(a==null?void 0:a[0])??0,h[n++]=(a==null?void 0:a[1])??0,h[n++]=(a==null?void 0:a[2])??0;const c=t.Ss;h[n++]=(c==null?void 0:c[0])??0,h[n++]=(c==null?void 0:c[1])??0,h[n++]=(c==null?void 0:c[2])??0;const u=t.ks,f=t.zs,d=t.Is,g=t.Os,p=t.Ls,m=!(!f||!d);return m?(h[n++]=(g==null?void 0:g[0])??0,h[n++]=(g==null?void 0:g[1])??0,h[n++]=(p==null?void 0:p[0])??0,h[n++]=(p==null?void 0:p[1])??0,h[n++]=f[0],h[n++]=f[1],h[n++]=d[0],h[n++]=d[1]):!m&&!!u?(h[n++]=u[0],h[n++]=u[1],h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0):(h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0,h[n++]=0),h[n++]=t.Ds??0,h[n++]=t.Bs??0,h[n++]=t.Hs??0,h}static Gs(t,i){const r=t.length*O.FLOATS_PER_INSTANCE,h=i||new Float32Array(r);for(let n=0;n<t.length;n++){const a=n*O.FLOATS_PER_INSTANCE;O.Ts(t[n],h,a)}return h}};l(O,"BYTES_PER_INSTANCE",144),l(O,"FLOATS_PER_INSTANCE",36);let L=O;const U=class U{};l(U,"STRIDE",L.BYTES_PER_INSTANCE),l(U,"ATTRIBUTES",{A2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:0,divisor:1},A3:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:8,divisor:1},A4:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:16,divisor:1},A5:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:28,divisor:1},A6:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:44,divisor:1},A7:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:60,divisor:1},A8:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:76,divisor:1},A9:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:88,divisor:1},Aa:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:100,divisor:1},Ab:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:116,divisor:1},Ac:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:U.STRIDE,offset:132,divisor:1}});let J=U;class Zt{constructor(t=1e3,i=1.5){l(this,"Ns");l(this,"Xs");l(this,"Ys");l(this,"Ks",0);l(this,"js",0);this.Xs=t,this.Ys=i;const r=t*L.FLOATS_PER_INSTANCE;this.Ns=new Float32Array(r)}Zs(t){if(t<=this.Xs)return;const i=Math.ceil(t*this.Ys),r=this.Xs;this.Xs=i;const h=i*L.FLOATS_PER_INSTANCE,n=new Float32Array(h),a=r*L.FLOATS_PER_INSTANCE;n.set(this.Ns.subarray(0,Math.min(a,this.Ks))),this.Ns=n}Ws(){return{buffer:this.Ns,offset:this.Ks}}qs(t){this.Ks+=t,this.js++}Vs(){this.Ks=0,this.js=0}Qs(t=0,i){return this.Ns.subarray(t,i??this.Ks)}get Js(){return this.js}get te(){return this.Xs}get se(){return this.Ks}get ee(){return this.js===0}}class Vt{constructor(t){l(this,"Ns");this.Ns=t}ie(t){this.Ns.Zs(this.Ns.Js+1);const{buffer:i,offset:r}=this.Ns.Ws();i[r+0]=t.x,i[r+1]=t.y,i[r+2]=t.width,i[r+3]=t.height,i[r+4]=t.char0,i[r+5]=t.char1,i[r+6]=t.char2,i[r+7]=t.r1,i[r+8]=t.g1,i[r+9]=t.b1,i[r+10]=t.a1,i[r+11]=t.r2,i[r+12]=t.g2,i[r+13]=t.b2,i[r+14]=t.a2,i[r+15]=t.invert,i[r+16]=t.flipX,i[r+17]=t.flipY,i[r+18]=t.charRot,i[r+19]=t.translationX,i[r+20]=t.translationY,i[r+21]=t.translationZ,i[r+22]=t.rotationX,i[r+23]=t.rotationY,i[r+24]=t.rotationZ;const h=t.curveParams0,n=t.curveParams1;return i[r+25]=h[0],i[r+26]=h[1],i[r+27]=h[2],i[r+28]=h[3],i[r+29]=n[0],i[r+30]=n[1],i[r+31]=n[2],i[r+32]=n[3],i[r+33]=t.depth,i[r+34]=t.baseZ,i[r+35]=t.geometryType,this.Ns.qs(L.FLOATS_PER_INSTANCE),this.Ns.Js-1}get Js(){return this.Ns.Js}}class qt{constructor(t,i=1e3){l(this,"A");l(this,"re",null);l(this,"ne",0);l(this,"oe",new Map);this.A=t,this.he(i)}he(t){const i=this.A;this.re&&i.deleteBuffer(this.re),this.re=i.createBuffer();const r=t*L.BYTES_PER_INSTANCE;Ft(i,i.ARRAY_BUFFER,this.re,r,i.DYNAMIC_DRAW),this.ne=t}ae(t){this.he(t)}get te(){return this.ne}ce(t,i){if(i===0)return;const r=this.A;r.bindBuffer(r.ARRAY_BUFFER,this.re);const h=i*L.FLOATS_PER_INSTANCE;r.bufferSubData(r.ARRAY_BUFFER,0,t,0,h)}le(t){let i=this.oe.get(t);if(!i){i=new Map;const r=this.A;for(const h in J.ATTRIBUTES){const n=r.getAttribLocation(t,h);n!==-1&&i.set(h,n)}this.oe.set(t,i)}return i}ue(t){const i=this.A,r=t.L,h=this.le(r);for(const[n,a]of h){const c=J.ATTRIBUTES[n];c&&dt(i,a,c.size,c.stride,c.offset,c.divisor,c.type,c.normalized)}}fe(t){const i=this.A,r=this.le(t.L);for(const[h,n]of r)J.ATTRIBUTES[h]&&(i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0))}D(){this.re&&(this.A.deleteBuffer(this.re),this.re=null),this.oe.clear()}}class Qt{constructor(t,i=1e3,r=1.5){l(this,"A");l(this,"Ns");l(this,"de");l(this,"pe");this.A=t,this.Ns=new Zt(i,r),this.de=new Vt(this.Ns),this.pe=new qt(t,i)}ge(t){var h,n,a,c,u,f,d,g,p,m;const i=[0,0,0,0],r=[0,0,0,0];return t.zs&&t.Is?(i[0]=((h=t.Os)==null?void 0:h[0])??0,i[1]=((n=t.Os)==null?void 0:n[1])??0,i[2]=((a=t.Ls)==null?void 0:a[0])??0,i[3]=((c=t.Ls)==null?void 0:c[1])??0,r[0]=t.zs[0],r[1]=t.zs[1],r[2]=t.Is[0],r[3]=t.Is[1]):t.ks&&(i[0]=t.ks[0],i[1]=t.ks[1]),this.ie({x:t._s[0],y:t._s[1],width:t.Ps[0],height:t.Ps[1],char0:t.Ht[0],char1:t.Ht[1],char2:t.Ht[2],r1:t.Gt[0],g1:t.Gt[1],b1:t.Gt[2],a1:t.Gt[3],r2:t.Nt[0],g2:t.Nt[1],b2:t.Nt[2],a2:t.Nt[3],invert:t.Es[0],flipX:t.Es[1],flipY:t.Es[2],charRot:t.Tt,translationX:((u=t.Rs)==null?void 0:u[0])??0,translationY:((f=t.Rs)==null?void 0:f[1])??0,translationZ:((d=t.Rs)==null?void 0:d[2])??0,rotationX:((g=t.Ss)==null?void 0:g[0])??0,rotationY:((p=t.Ss)==null?void 0:p[1])??0,rotationZ:((m=t.Ss)==null?void 0:m[2])??0,curveParams0:i,curveParams1:r,depth:t.Ds||0,baseZ:t.Bs||0,geometryType:t.Hs||0})}ie(t){const i=this.de.ie(t);return this.Ns.te>this.pe.te&&this.pe.ae(this.Ns.te),i}get ve(){return this.Ns.Js}get ee(){return this.Ns.ee}me(){this.Ns.Vs()}ue(t){const i=this.Ns.Js;if(i===0)return;const r=this.Ns.Qs();this.pe.ce(r,i),this.pe.ue(t)}fe(t){this.pe.fe(t)}Cs(t,i){const r=this.Ns.Js;r!==0&&this.A.drawArraysInstanced(t,0,i,r)}D(){this.pe.D()}}class _{constructor(t,i,r,h){l(this,"A");l(this,"_e");l(this,"Ae");l(this,"ye");l(this,"we",null);this.A=t,this._e=i,this.Ae=r,this.ye=h;const n=this.A.createBuffer();Ft(this.A,this.A.ARRAY_BUFFER,n,this.ye.be,this.A.STATIC_DRAW),this.we=n}get type(){return this.Ae}get unitGeometry(){return this.ye}get unitBuffer(){return this.we}get batch(){return this._e}Ce(){this._e.me()}Me(){return!this._e.ee}D(){this._e.D(),this.A.deleteBuffer(this.we)}xe(t,i,r){return this._e.ge(t)}Fe(t,i,r,h,n,a){const c=n.It??0,u=n.Ot??0,f=n.Lt??0,d=n.At??0,g=n.yt??0,p=n.wt??0,m=[0,0,0,0],v=[0,0,0,0];a&&(a.bezStartX!==void 0&&a.bezStartY!==void 0&&a.bezEndX!==void 0&&a.bezEndY!==void 0?(m[0]=a.cp1x??0,m[1]=a.cp1y??0,m[2]=a.cp2x??0,m[3]=a.cp2y??0,v[0]=a.bezStartX??0,v[1]=a.bezStartY??0,v[2]=a.bezEndX??0,v[3]=a.bezEndY??0):a.arcStart===void 0&&a.arcStop===void 0||(m[0]=a.arcStart??0,m[1]=a.arcStop??0));const A={x:t,y:i,width:r,height:h,char0:n.Ht[0],char1:n.Ht[1],char2:n.Ht[2],r1:n.Gt[0],g1:n.Gt[1],b1:n.Gt[2],a1:n.Gt[3],r2:n.Nt[0],g2:n.Nt[1],b2:n.Nt[2],a2:n.Nt[3],invert:n.$t?1:0,flipX:n.Dt?1:0,flipY:n.Bt?1:0,charRot:n.Tt,translationX:c,translationY:u,translationZ:f,rotationX:d,rotationY:g,rotationZ:p,curveParams0:m,curveParams1:v,depth:(a==null?void 0:a.depth)??0,baseZ:(a==null?void 0:a.baseZ)??0,geometryType:Kt[this.Ae]??0};return this._e.ie(A)}}const Jt={be:At,$e:6,...j},$t={be: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]),$e:6,...j},te={be:function(o=32){const t=[],i=2*Math.PI/o;for(let r=0;r<o;r++){const h=r*i,n=(r+1)%o*i,a=Math.cos(h),c=Math.sin(h),u=.5*(a+1),f=.5*(c+1),d=Math.cos(n),g=Math.sin(n),p=.5*(d+1),m=.5*(g+1);t.push(0,0,.5,.5,a,c,u,f,d,g,p,m)}return new Float32Array(t)}(32),$e:96,...j};let ee={be:function(o){const t=[];for(let i=0;i<o;i++){const r=i/o,h=(i+1)/o;t.push(r,0,r,0,r,1,r,1,h,1,h,1)}return new Float32Array(t)}(32),$e:96,...j};const ie={be:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),$e:3,...j},re={be:function(o=16){const t=[];for(let i=0;i<o;i++){const r=i/o,h=(i+1)/o;t.push(r,-.5,r,0,h,-.5,h,0,r,.5,r,1,r,.5,r,1,h,-.5,h,0,h,.5,h,1)}return new Float32Array(t)}(16),$e:96,...j},se={[P.RECTANGLE]:class extends _{constructor(o,t){super(o,t,P.RECTANGLE,Jt)}ge(o,t){return this.Fe(0,0,o.width,o.height,t)}},[P.LINE]:class extends _{constructor(o,t){super(o,t,P.LINE,$t)}ge(o,t){const i=o.x2-o.x1,r=o.y2-o.y1,h=Math.hypot(i,r),n=Math.atan2(r,i),a=t.zt||1,c=o.x1+i/2-h/2,u=o.y1+r/2,f={...t,wt:(t.wt||0)+n};return this.Fe(c,u,h,a,f)}},[P.ELLIPSE]:class extends _{constructor(o,t){super(o,t,P.ELLIPSE,te)}ge(o,t){return this.Fe(0,0,o.width,o.height,t)}},[P.ARC]:class extends _{constructor(o,t){super(o,t,P.ARC,ee)}ge(o,t){const i=o.start*Math.PI/180,r=o.stop*Math.PI/180;return this.Fe(0,0,o.width,o.height,t,{arcStart:i,arcStop:r})}},[P.TRIANGLE]:class extends _{constructor(o,t){super(o,t,P.TRIANGLE,ie)}ge(o,t){const i=Math.min(o.x1,o.x2,o.x3),r=Math.max(o.x1,o.x2,o.x3),h=Math.min(o.y1,o.y2,o.y3),n=r-i,a=Math.max(o.y1,o.y2,o.y3)-h;return this.Fe(i,h,n,a,t)}},[P.BEZIER_CURVE]:class extends _{constructor(o,t){super(o,t,P.BEZIER_CURVE,re)}ge(o,t){return this.Fe(0,0,1,t.zt||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 ne{constructor(t){l(this,"A");l(this,"Te");l(this,"Pe");this.A=t,this.Pe=new Wt(t),this.Te=new Map;for(const i of Object.values(P)){const r=new Qt(t),h=new se[i](t,r);this.Te.set(i,h)}}Ee(t){const i=this.Re(t);for(const r of i)this.Se(r)}Re(t){const i=[];let r=null,h=null,n=null;for(const a of t)h!==a.material||n!==a.type?(r&&r.length>0&&i.push({material:h,type:n,commands:r}),r=[a],h=a.material,n=a.type):r.push(a);return r&&r.length>0&&i.push({material:h,type:n,commands:r}),i}Se(t){const{material:i,type:r,commands:h}=t,n=this.Te.get(r);i.shader.S(),i.shader.I(i.uniforms);const a=Ct(this.A),c=h.length>0&&h[0].state.Et;i.shader.I({Us:a[2]/a[3],Ut:[a[2],a[3]],Uu:1,Uv:c?1:0}),n.Ce();for(const u of h)n.ge(u.params,u.state);if(n.Me()){const u=n.unitGeometry,f=n.unitBuffer;try{this.Pe.Fs(i.shader.L,r+"",u,f),n.batch.ue(i.shader),n.batch.Cs(u.gs,u.$e)}finally{n.batch.fe(i.shader),this.Pe.$s(),n.Ce()}}}D(){for(const t of this.Te.values())t.D();this.Te.clear(),this.Pe.D()}}function Mt(o){let t=0;for(let i=0;i<o.length;i++)t=(t<<5)-t+o.charCodeAt(i),t&=t;return t}function Nt(o){return Mt(o+"")}function $(o,t){return(o<<5)-o+t}class he{constructor(t){l(this,"A");l(this,"ke",0);l(this,"ze");l(this,"Ie");l(this,"Oe",new Map);this.A=t,this.ze=new V(t,rt,`#version 300 es
|
|
10
|
+
precision highp float;in vec3 v_glyphIndex;in vec4 v_glyphColor;in vec4 v_cellColor;in vec4 v_glyphFlags;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;void main(){int A=int(v_glyphFlags.r>0.5?1:0);int B=int(v_glyphFlags.g>0.5?1:0);int C=int(v_glyphFlags.b>0.5?1:0);float D=float(A|(B<<1)|(C<<2))/255.;o_character=vec4(v_glyphIndex.xy,D,clamp(v_glyphFlags.a,0.,1.));o_primaryColor=vec4(v_glyphColor.rgb,v_glyphColor.a);o_secondaryColor=vec4(v_cellColor.rgb,v_cellColor.a);}`),this.Ie={id:this.ke++,shader:this.ze,uniforms:Object.freeze({}),hash:this.Le(this.ze,{}),isBuiltIn:!0}}get De(){return this.Ie}ut(t,i={},r=!1){const h=this.Le(t,i),n=this.Oe.get(h);if(n)return n;const a={id:this.ke++,shader:t,uniforms:Object.freeze({...i}),hash:h,isBuiltIn:r};return this.Oe.set(h,a),a}Be(t,i={}){return{id:this.ke++,shader:t,uniforms:Object.freeze({...i}),hash:0,isBuiltIn:!1}}Le(t,i){const r=Nt(t.L),h=function(n,a){let c=0;const u=Object.keys(n).sort();for(const f of u)c=$(c,Mt(f)),c=$(c,a(n[f]));return c}(i,this.He.bind(this));return $(r,h)}He(t){return typeof t=="number"||typeof t=="boolean"?function(i){return typeof i=="boolean"?i?1:0:Math.floor(i)}(t):Array.isArray(t)?function(i){let r=0;const h=Array.isArray(i[0])?i.flat():i;for(const n of h)r=$(r,typeof n=="number"?n:0);return r}(t):t instanceof Float32Array||t instanceof Int32Array?function(i){let r=0;const h=Math.min(i.length,16);for(let n=0;n<h;n++)r=$(r,i[n]);return r}(t):t instanceof WebGLTexture?Nt(t):0}D(){this.ze!=this.ze&&this.ze.D(),this.ze.D(),this.Oe.clear()}}class oe{constructor(){l(this,"Ge",[]);l(this,"Ne",1);l(this,"Ps",0)}Xe(t,i){if(this.Ps>=this.Ge.length){const h={id:this.Ne++,type:t,params:{},state:st.kt(),material:i};this.Ge.push(h)}const r=this.Ge[this.Ps];return r.id=this.Ne++,r.type=t,r.material=i,this.Ps++,r}Ye(t,i,r){const h=this.Xe(P.RECTANGLE,r),n=h.params;return n.width=t.width,n.height=t.height,i.Kt(h.state),h.id}Ke(t,i,r){const h=this.Xe(P.LINE,r),n=h.params;return n.x1=t.x1,n.y1=t.y1,n.x2=t.x2,n.y2=t.y2,n.thickness=t.thickness,i.Kt(h.state),h.id}je(t,i,r){const h=this.Xe(P.ELLIPSE,r),n=h.params;return n.width=t.width,n.height=t.height,n.startAngle=t.startAngle,n.endAngle=t.endAngle,n.segments=t.segments,i.Kt(h.state),h.id}Ze(t,i,r){const h=this.Xe(P.ARC,r),n=h.params;return n.width=t.width,n.height=t.height,n.start=t.start,n.stop=t.stop,i.Kt(h.state),h.id}We(t,i,r){const h=this.Xe(P.TRIANGLE,r),n=h.params;return n.x1=t.x1,n.y1=t.y1,n.x2=t.x2,n.y2=t.y2,n.x3=t.x3,n.y3=t.y3,i.Kt(h.state),h.id}qe(t,i,r){const h=this.Xe(P.BEZIER_CURVE,r),n=h.params;return n.x1=t.x1,n.y1=t.y1,n.cp1x=t.cp1x,n.cp1y=t.cp1y,n.cp2x=t.cp2x,n.cp2y=t.cp2y,n.x2=t.x2,n.y2=t.y2,n.thickness=t.thickness,n.segments=t.segments,i.Kt(h.state),h.id}me(){this.Ps=0}[Symbol.iterator](){let t=0;const i=this.Ps,r=this.Ge;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}class ae{constructor(t){l(this,"A");l(this,"Ve",null);l(this,"Qe");l(this,"ft");l(this,"Je");l(this,"ti");l(this,"si");l(this,"ei",null);l(this,"ii",{});l(this,"ri",[]);l(this,"ni",[]);l(this,"oi",null);l(this,"hi",[0,0,0,0]);this.A=t,t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.clearDepth(1),t.depthMask(!0),t.disable(t.CULL_FACE),this.Je=new st,this.ft=new he(t),this.ti=new oe,this.Qe=new ne(t),this.si=new kt(t);const i=[0,0,t.canvas.width,t.canvas.height];gt(t,i),this.ri.push(null),this.ni.push(i),this.oi=null,this.hi=i}et(){this.ri.push(this.oi),this.ni.push([...this.hi])}ht(){return{framebuffer:this.ri.pop()??null,viewport:this.ni.pop()??[0,0,this.A.canvas.width,this.A.canvas.height]}}it(t,i,r){const h=this.A;this.oi!==t&&(h.bindFramebuffer(h.FRAMEBUFFER,t),this.oi=t);const n=[0,0,i,r];this.hi[0]===n[0]&&this.hi[1]===n[1]&&this.hi[2]===n[2]&&this.hi[3]===n[3]||(h.viewport(...n),gt(h,n),this.hi=n)}ai(t){this.Ve!==t&&(this.Ve=t,t.S())}ci(t,i){return new V(this.A,t,i)}li(t){this.ei=t,t&&(this.ii={})}O(t,i){this.ii[t]=i}ui(t){Object.assign(this.ii,t)}fi(t){return new V(this.A,rt,t)}di(t,i,r){this.ti.Ye({width:i??t.width,height:r??t.height},this.Je,t.ct())}pi(t,i,r,h){this.si.Cs(t,i,r,h)}gi(t,i){if(this.ei){const r=this.ft.Be(this.ei,this.ii);this.ti.Ye({width:t,height:i},this.Je,r),this.ei=null,this.ii={}}else this.ti.Ye({width:t,height:i},this.Je,this.ft.De)}mi(t,i,r,h){this.ti.Ke({x1:t,y1:i,x2:r,y2:h},this.Je,this.ft.De)}_i(t,i){this.ti.je({width:t,height:i},this.Je,this.ft.De)}Ai(t,i,r,h,n,a){this.ti.We({x1:t,y1:i,x2:r,y2:h,x3:n,y3:a},this.Je,this.ft.De)}yi(t,i,r,h,n,a,c,u){this.ti.qe({x1:t,y1:i,cp1x:r,cp1y:h,cp2x:n,cp2y:a,x2:c,y2:u},this.Je,this.ft.De)}wi(t,i,r,h){this.ti.Ze({width:t,height:i,start:r,stop:h},this.Je,this.ft.De)}bi(t,i,r=1,h={}){return new Q(this.A,t,i,r,h,this)}Ci(t,i=t,r=t,h=255){this.Je.fs(t,i??t,r??t,h);const[n,a,c,u]=this.Je.canvasBackgroundColor;this.me(n,a,c,u)}me(t=0,i=0,r=0,h=0){this.A.clearColor(t,i,r,h),this.A.clear(this.A.COLOR_BUFFER_BIT)}Mi(){const t=[0,0,this.A.canvas.width,this.A.canvas.height];this.A.viewport(...t),gt(this.A,t),this.hi=t,this.ni.length>0&&(this.ni[0]=t)}ot(){const t=this.ti;this.Qe.Ee(t),t.me()}D(){this.ft.D(),this.Qe.D(),this.si.D()}get context(){return this.A}get state(){return this.Je}}const C={readShort:(o,t)=>(C.t.uint16[0]=o[t]<<8|o[t+1],C.t.int16[0]),readUshort:(o,t)=>o[t]<<8|o[t+1],readUshorts(o,t,i){const r=[];for(let h=0;h<i;h++)r.push(C.readUshort(o,t+2*h));return r},readUint(o,t){const i=C.t.uint8;return i[3]=o[t],i[2]=o[t+1],i[1]=o[t+2],i[0]=o[t+3],C.t.uint32[0]},readASCII(o,t,i){let r="";for(let h=0;h<i;h++)r+=String.fromCharCode(o[t+h]);return r},t:(()=>{const o=new ArrayBuffer(8);return{uint8:new Uint8Array(o),int16:new Int16Array(o),uint16:new Uint16Array(o),uint32:new Uint32Array(o)}})()};function nt(o){return o+3&-4}function ht(o,t,i){o[t]=i>>>8&255,o[t+1]=255&i}function S(o,t,i){o[t]=i>>>24&255,o[t+1]=i>>>16&255,o[t+2]=i>>>8&255,o[t+3]=255&i}function ce(o,t,i){for(let r=0;r<i.length;r++)o[t+r]=255&i.charCodeAt(r)}function pt(o,t,i){const r=t+i;let h=0;const n=C.t;for(let a=t;a<r;a+=4)n.uint8[3]=o[a]||0,n.uint8[2]=o[a+1]||0,n.uint8[1]=o[a+2]||0,n.uint8[0]=o[a+3]||0,h=h+(n.uint32[0]>>>0)>>>0;return h>>>0}class le{constructor(t){l(this,"b");l(this,"p",0);l(this,"bitbuf",0);l(this,"bitcnt",0);this.b=t}readBits(t){for(;this.bitcnt<t;){const r=this.b[this.p++]||0;this.bitbuf|=r<<this.bitcnt,this.bitcnt+=8}const i=this.bitbuf&(1<<t)-1;return this.bitbuf>>>=t,this.bitcnt-=t,i}alignToByte(){this.bitbuf=0,this.bitcnt=0}get offset(){return this.p}}function tt(o){let t=32,i=0;for(const c of o)c&&(c<t&&(t=c),c>i&&(i=c));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const c of o)c&&r[c]++;const h=new Uint32Array(i+1);let n=0;r[0]=0;for(let c=1;c<=i;c++)n=n+r[c-1]<<1,h[c]=n;const a=new Map;for(let c=0;c<o.length;c++){const u=o[c];if(!u)continue;const f=h[u]++;let d=a.get(u);d||(d=[],a.set(u,d)),d[ue(f,u)]=c}return{min:t,max:i,table:a}}function mt(o,t){let i=0;for(let r=1;r<=t.max;r++){i|=o.readBits(1)<<r-1;const h=t.table.get(r);if(h&&i<h.length){const n=h[i];if(n!==void 0)return n}}throw Error("Invalid Huffman code")}function ue(o,t){let i=0;for(let r=0;r<t;r++)i=i<<1|1&o,o>>>=1;return i>>>0}function fe(o){if(o.length<2)throw Error("ZLIB data too short");const t=o[0],i=o[1];if((15&t)!=8)throw Error("Unsupported ZLIB compression method");if(((t<<8)+i)%31!=0)throw Error("Bad ZLIB header check");let r=2;32&i&&(r+=4);const h=[];return function(n,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=n.readBits(1);const p=n.readBits(2);if(p===0){n.alignToByte();const m=n.readBits(16);if((65535&(65535^m))!==n.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let v=0;v<m;v++)a.push(n.readBits(8))}else{if(p!==1&&p!==2)throw Error("Unsupported DEFLATE type");{let m,v;if(p===1){const A=Array(288).fill(0);for(let E=0;E<=143;E++)A[E]=8;for(let E=144;E<=255;E++)A[E]=9;for(let E=256;E<=279;E++)A[E]=7;for(let E=280;E<=287;E++)A[E]=8;m=tt(A),v=tt(Array(32).fill(5))}else{const A=n.readBits(5)+257,E=n.readBits(5)+1,y=n.readBits(4)+4,T=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],w=Array(19).fill(0);for(let N=0;N<y;N++)w[T[N]]=n.readBits(3);const R=tt(w),b=[];for(;b.length<A+E;){const N=mt(n,R);if(N<=15)b.push(N);else if(N===16){const B=n.readBits(2)+3,D=b[b.length-1]||0;for(let ut=0;ut<B;ut++)b.push(D)}else if(N===17){const B=n.readBits(3)+3;for(let D=0;D<B;D++)b.push(0)}else{if(N!==18)throw Error("Invalid code length symbol");{const B=n.readBits(7)+11;for(let D=0;D<B;D++)b.push(0)}}}const M=b.slice(0,A),z=b.slice(A,A+E);m=tt(M),v=tt(z)}for(;;){const A=mt(n,m);if(A<256)a.push(A);else{if(A===256)break;if(A>256&&A<286){const E=A-257;let y=c[E];const T=u[E];T&&(y+=n.readBits(T));const w=mt(n,v);if(w>=30)throw Error("Invalid distance symbol");let R=f[w];const b=d[w];b&&(R+=n.readBits(b));const M=a.length-R;if(M<0)throw Error("Invalid distance");for(let z=0;z<y;z++)a.push(a[M+z]||0)}else if(A===286||A===287)throw Error("Reserved length symbol")}}}}}}(new le(o.subarray(r)),h),new Uint8Array(h)}function de(o){const t=C,i=new Uint8Array(o);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),h=t.readUshort(i,12),n=t.readUint(i,16),a=[];let c=44;for(let y=0;y<h;y++){const T=t.readASCII(i,c,4),w=t.readUint(i,c+4),R=t.readUint(i,c+8),b=t.readUint(i,c+12),M=t.readUint(i,c+16);a.push({tag:T,offset:w,compLength:R,origLength:b,checksum:M}),c+=20}for(const y of a){const T=new Uint8Array(i.buffer,y.offset,y.compLength);if(y.compLength===y.origLength)y.data=new Uint8Array(T);else if(y.data=fe(T),y.data.length!==y.origLength)if(y.data.length<y.origLength){const w=new Uint8Array(y.origLength);w.set(y.data),y.data=w}else y.data=y.data.subarray(0,y.origLength)}const u=h;let f=1,d=0;for(;f<<1<=u;)f<<=1,d++;const g=16*f,p=16*u-g;let m=12+16*u;const v={};for(const y of a)v[y.tag]=m,m=nt(m+y.data.length);const A=new Uint8Array(Math.max(n||0,m));S(A,0,r),ht(A,4,u),ht(A,6,g),ht(A,8,d),ht(A,10,p);let E=12;for(const y of a){ce(A,E,y.tag),E+=4;let T=y.data;if(y.tag==="head"&&T.length>=12){const w=new Uint8Array(T);S(w,8,0),S(A,E,pt(w,0,nt(w.length))),E+=4}else S(A,E,pt(T,0,nt(T.length))),E+=4;S(A,E,v[y.tag]),E+=4,S(A,E,y.data.length),E+=4}for(const y of a){const T=v[y.tag];A.set(y.data,T)}if(a.find(y=>y.tag==="head")){const y=v.head,T=function(w,R){const b=R+8,M=[w[b],w[b+1],w[b+2],w[b+3]];S(w,b,0);const z=2981146554-(pt(w,0,nt(w.length))>>>0)>>>0;return w[b]=M[0],w[b+1]=M[1],w[b+2]=M[2],w[b+3]=M[3],z>>>0}(A,y);S(A,y+8,T)}return A.buffer}const ge={parseTab(o,t,i){const r={tables:[],ids:{},off:t};o=new Uint8Array(o.buffer,t,i),t=0;const h=C,n=h.readUshort,a=n(o,t+=2);t+=2;const c=[];for(let u=0;u<a;u++){const f=n(o,t),d=n(o,t+=2);t+=2;const g=h.readUint(o,t);t+=4;const p=`p${f}e${d}`;let m=c.indexOf(g);if(m===-1){let v;m=r.tables.length,c.push(g);const A=n(o,g);v=A===4?this.parse4(o,g):A===12?this.parse12(o,g):{format:A},r.tables.push(v)}r.ids[p]=m}return r},parse4(o,t){const i=C,r=i.readUshort,h=i.readUshorts,n=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=h(o,t,c),t+=2*c,t+=2,u.startCount=h(o,t,c),t+=2*c;for(let f=0;f<c;f++)u.idDelta.push(i.readShort(o,t)),t+=2;return u.idRangeOffset=h(o,t,c),t+=2*c,u.glyphIdArray=h(o,t,n+a-t>>1),u},parse12(o,t){const i=C.readUint;i(o,t+=4),i(o,t+=4);const r=i(o,t+=4);t+=4;const h=new Uint32Array(3*r);for(let n=0;n<3*r;n+=3)h[n]=i(o,t+(n<<2)),h[n+1]=i(o,t+(n<<2)+4),h[n+2]=i(o,t+(n<<2)+8);return{format:12,groups:h}}},Ae={parseTab(o,t,i){const r=C;t+=18;const h=r.readUshort(o,t);t+=2,t+=16;const n=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:h,xMin:n,yMin:a,xMax:c,yMax:u,indexToLocFormat:r.readShort(o,t)}}},pe={parseTab(o,t,i){const r=C;t+=4;const h=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],n={};for(let a=0;a<h.length;a++){const c=h[a],u=c==="advanceWidthMax"||c==="numberOfHMetrics"?r.readUshort:r.readShort;n[c]=u(o,t+2*a)}return n}},me={parseTab(o,t,i,r){const h=C,n=[],a=[],c=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,d=0,g=0;for(;g<u;)f=h.readUshort(o,t+(g<<2)),d=h.readShort(o,t+(g<<2)+2),n.push(f),a.push(d),g++;for(;g<c;)n.push(f),a.push(d),g++;return{aWidth:n,lsBearing:a}}},It={cmap:ge,head:Ae,hhea:pe,maxp:{parseTab(o,t,i){const r=C;return r.readUint(o,t),t+=4,{numGlyphs:r.readUshort(o,t)}}},hmtx:me,loca:{parseTab(o,t,i,r){const h=C,n=[],a=r.head.indexToLocFormat,c=r.maxp.numGlyphs+1;if(a===0)for(let u=0;u<c;u++)n.push(h.readUshort(o,t+(u<<1))<<1);else if(a===1)for(let u=0;u<c;u++)n.push(h.readUint(o,t+(u<<2)));return n}},glyf:{parseTab(o,t,i,r){const h=[],n=r.maxp.numGlyphs;for(let a=0;a<n;a++)h.push(null);return h},xi(o,t){const i=C,r=o.Fi,h=o.loca;if(h[t]===h[t+1])return null;const n=H.findTable(r,"glyf",o.$i);if(!n)return null;let a=n[0]+h[t];const c={};if(c.noc=i.readShort(r,a),a+=2,c.xMin=i.readShort(r,a),a+=2,c.yMin=i.readShort(r,a),a+=2,c.xMax=i.readShort(r,a),a+=2,c.yMax=i.readShort(r,a),a+=2,c.xMin>=c.xMax||c.yMin>=c.yMax)return null;if(c.noc>0){c.endPts=[];for(let p=0;p<c.noc;p++)c.endPts.push(i.readUshort(r,a)),a+=2;const u=i.readUshort(r,a);if(a+=2,r.length-a<u)return null;a+=u;const f=c.endPts[c.noc-1]+1;c.flags=[];for(let p=0;p<f;p++){const m=r[a];if(a++,c.flags.push(m),8&m){const v=r[a];a++;for(let A=0;A<v;A++)c.flags.push(m),p++}}c.xs=[];for(let p=0;p<f;p++){const m=c.flags[p],v=!!(16&m);2&m?(c.xs.push(v?r[a]:-r[a]),a++):v?c.xs.push(0):(c.xs.push(i.readShort(r,a)),a+=2)}c.ys=[];for(let p=0;p<f;p++){const m=c.flags[p],v=!!(32&m);4&m?(c.ys.push(v?r[a]:-r[a]),a++):v?c.ys.push(0):(c.ys.push(i.readShort(r,a)),a+=2)}let d=0,g=0;for(let p=0;p<f;p++)d+=c.xs[p],g+=c.ys[p],c.xs[p]=d,c.ys[p]=g}else c.parts=[],c.endPts=[],c.flags=[],c.xs=[],c.ys=[];return c}}},H={parse(o){const t=new Uint8Array(o);C.readASCII(t,0,4)==="wOFF"&&(o=de(o));const i=new Uint8Array(o),r=It,h={},n={Fi:i,Ti:0,$i:0};for(const a in r){const c=a,u=H.findTable(i,c,0);if(u){const[f,d]=u;let g=h[f];g==null&&(g=r[c].parseTab(i,f,d,n),h[f]=g),n[c]=g}}return[n]},findTable(o,t,i){const r=C,h=r.readUshort(o,i+4);let n=i+12;for(let a=0;a<h;a++){const c=r.readASCII(o,n,4);r.readUint(o,n+4);const u=r.readUint(o,n+8),f=r.readUint(o,n+12);if(c===t)return[u,f];n+=16}return null},T:It,B:C};class ve{Pi(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(h=>{if(h.format===4){const n=this.Ei(h);i.push(...n)}else if(h.format===12){const n=this.Ri(h);i.push(...n)}}),[...new Set(i)]):[]}Ei(t){const i=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return i;for(let r=0;r<t.startCount.length;r++){const h=t.startCount[r],n=t.endCount[r];if(h!==65535||n!==65535){for(let a=h;a<=n;a++)if(this.Si(t,a,r)>0)try{const c=String.fromCodePoint(a);i.push(c)}catch{}}}return i}Ri(t){const i=[];if(!t.groups)return i;for(let r=0;r<t.groups.length;r+=3){const h=t.groups[r],n=t.groups[r+1],a=t.groups[r+2];for(let c=h;c<=n;c++)if(a+(c-h)>0)try{const u=String.fromCodePoint(c);i.push(u)}catch{}}return i}Si(t,i,r){if(t.idRangeOffset[r]===0)return i+t.idDelta[r]&65535;{const h=t.idRangeOffset[r]/2+(i-t.startCount[r])-(t.startCount.length-r);if(h>=0&&t.glyphIdArray&&h<t.glyphIdArray.length){const n=t.glyphIdArray[h];if(n!==0)return n+t.idDelta[r]&65535}}return 0}}class vt{constructor(){l(this,"ki",new Map);l(this,"zi",new Map)}Ii(t,i){const r=`${this.Oi(t)}_${i}`;if(this.ki.has(r))return this.ki.get(r);const h=t.cmap;if(!h||!h.tables)return this.ki.set(r,0),0;let n=0;for(const a of h.tables)if(a.format===4?n=this.Li(i,a):a.format===12&&(n=this.Di(i,a)),n>0)break;return this.ki.set(r,n),n}Bi(t,i){const r=i.codePointAt(0);return r===void 0?0:this.Ii(t,r)}Hi(t,i){const r=t.hmtx;return r&&r.aWidth&&r.aWidth.length!==0?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}Gi(t,i){const r=i/t.head.unitsPerEm,h=t.hhea.ascender*r,n=t.hhea.descender*r,a=t.hhea.lineGap*r;return{ascender:h,descender:n,lineGap:a,lineHeight:h-n+a,unitsPerEm:t.head.unitsPerEm,scale:r}}Ni(){this.ki.clear(),this.zi.clear()}Oi(t){return`${t.$i}_${t.Fi.length}`}Li(t,i){const r=i.endCount.length;let h=-1;for(let n=0;n<r;n++)if(t<=i.endCount[n]){h=n;break}if(h===-1||t<i.startCount[h])return 0;if(i.idRangeOffset[h]===0)return t+i.idDelta[h]&65535;{const n=i.idRangeOffset[h]/2+(t-i.startCount[h])-(r-h);if(n>=0&&n<i.glyphIdArray.length){const a=i.glyphIdArray[n];return a===0?0:a+i.idDelta[h]&65535}}return 0}Di(t,i){const r=i.groups.length/3;for(let h=0;h<r;h++){const n=i.groups[3*h],a=i.groups[3*h+1],c=i.groups[3*h+2];if(t>=n&&t<=a)return c+(t-n)}return 0}}class ye{constructor(t){l(this,"Xi");l(this,"Yi");l(this,"j");l(this,"Ki");this.j=t,this.Ki=new vt,this.Xi=document.createElement("canvas"),this.Yi=this.Xi.getContext("2d",{willReadFrequently:!0,alpha:!0})}ji(t,i,r,h){const n=t.length,a=Math.ceil(Math.sqrt(n)),c=Math.ceil(n/a),u=i.width*a,f=i.height*c;this.Zi(u,f),this.Wi(t,i,a,r,h);const d=this.j.bi(u,f,1,{filter:"nearest"});return d.st(this.Xi),{framebuffer:d,columns:a,rows:c}}Zi(t,i){this.Xi.width=t,this.Xi.height=i,this.Xi.style.width=t+"px",this.Xi.style.height=i+"px",this.Yi.imageSmoothingEnabled=!1,this.Xi.style.imageRendering="pixelated",this.Yi.clearRect(0,0,t,i),this.Yi.textBaseline="top",this.Yi.textAlign="left",this.Yi.fillStyle="white"}Wi(t,i,r,h,n){const a=h/n.head.unitsPerEm;for(let c=0;c<t.length;c++){const u=c%r,f=Math.floor(c/r),d=t[c].character,g=this.qi(n,d);if(!g)continue;const p=d.codePointAt(0)||0,m=this.Ki.Ii(n,p),v=this.Ki.Hi(n,m)*a,A=u*i.width,E=f*i.height,y=A+.5*i.width,T=E+.5*i.height,w=Math.round(y-.5*i.width),R=Math.round(T-.5*h),b=w+.5*(i.width-v),M=R+n.hhea.ascender*a;this.Vi(g,b,M,a)}}qi(t,i){const r=i.codePointAt(0)||0,h=this.Ki.Ii(t,r);return h===0?null:H.T.glyf.xi(t,h)}Vi(t,i,r,h){if(!t||!t.xs||t.noc===0)return;let{xs:n,ys:a,endPts:c,flags:u}=t;if(!(n&&a&&c&&u))return;this.Yi.beginPath();let f=0;for(let d=0;d<c.length;d++){const g=c[d];if(!(g<f)){if(g>=f){const p=i+n[f]*h,m=r-a[f]*h;this.Yi.moveTo(p,m);let v=f+1;for(;v<=g;)if(1&u[v]){const A=i+n[v]*h,E=r-a[v]*h;this.Yi.lineTo(A,E),v++}else{const A=i+n[v]*h,E=r-a[v]*h;if(v+1>g){const T=i+n[f]*h,w=r-a[f]*h;if(1&u[f])this.Yi.quadraticCurveTo(A,E,T,w);else{const R=(A+T)/2,b=(E+w)/2;this.Yi.quadraticCurveTo(A,E,R,b)}break}const y=v+1;if(1&u[y]){const T=i+n[y]*h,w=r-a[y]*h;this.Yi.quadraticCurveTo(A,E,T,w),v=y+1}else{const T=(A+(i+n[y]*h))/2,w=(E+(r-a[y]*h))/2;this.Yi.quadraticCurveTo(A,E,T,w),v=y}}this.Yi.closePath()}f=g+1}}this.Yi.fill()}}class Ee{constructor(){l(this,"Qi");this.Qi=new vt}Ji(t,i,r){let h=0;const n=this.Qi.Gi(r,i),a=n.lineHeight;for(const c of t){const u=this.Qi.Bi(r,c);if(u===0)continue;const f=this.Qi.Hi(r,u)*n.scale;h=Math.max(h,f)}return{width:Math.ceil(h),height:Math.ceil(a)}}Ni(){this.Qi.Ni()}}class we{constructor(){l(this,"Ki");this.Ki=new vt}createCharacterObjects(t,i){return t.map((r,h)=>{const n=r.codePointAt(0)||0,a=this.tr(h);let c=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.Ki.Ii(i,n);u>0&&i.hmtx.aWidth[u]!==void 0&&(c=i.hmtx.aWidth[u])}return{character:r,unicode:n,color:a,advanceWidth:c}})}tr(t){return[t%256/255,Math.floor(t/256)%256/255,0]}sr(t,i){if(!Z.m(typeof t=="string","Character must be a string.",{method:"getCharacterColor",providedValue:t}))return[0,0,0];const r=i.find(h=>h.character===t);return r?r.color:[0,0,0]}er(t,i){return Z.m(typeof t=="string"&&t.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:t})?Array.from(t).map(r=>this.sr(r,i)||[0,0,0]):[[0,0,0]]}}class yt{constructor(t,i=16){l(this,"ir");l(this,"rr",[]);l(this,"nr");l(this,"hr",16);l(this,"ar",0);l(this,"cr",0);l(this,"lr",{width:0,height:0});l(this,"ur");l(this,"dr",new Map);l(this,"pr");l(this,"gr");l(this,"vr");l(this,"mr");this.hr=i,this.pr=new ve,this.gr=new ye(t),this.vr=new Ee,this.mr=new we}async _r(t){let i;if(t){const r=await fetch(t);if(!r.ok)throw new x(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}else i=await(await fetch("data:font/woff;base64,d09GRgABAAAAABbwAAoAAAAAfywAAQABAAAAAAAAAAAAAAAAAAAAAAAAAABjbWFwAAAA9AAAAbsAAAkgIO8lSWdseWYAAAKwAAAOfgAAaLS4ctN0aGVhZAAAETAAAAAsAAAAOCi8/PVoaGVhAAARXAAAABkAAAAkCwEFAmhtdHgAABF4AAAAhQAABAQEAIOAbG9jYQAAEgAAAAKUAAAECAAy54BtYXhwAAAUlAAAAB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ar(i),this.ir=H.parse(i)[0],await this.yr()}wr(t){if(t===void 0)return this.hr;this.hr=t,this.lr=this.vr.Ji(this.rr.map(r=>r.character),this.hr,this.ir);const i=this.gr.ji(this.rr,this.lr,this.hr,this.ir);this.nr=i.framebuffer,this.ar=i.columns,this.cr=i.rows}async br(t){try{const i=await fetch(t);if(!i.ok)throw new x(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.Ar(r);const h=H.parse(r);if(!h||h.length===0)throw Error("Failed to parse font file");this.ir=h[0],await this.yr()}catch(i){throw new x("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async Ar(t){const i=Date.now();this.ur=new FontFace("CustomFont_"+i,t),await this.ur.load(),document.fonts.add(this.ur)}async yr(){const t=this.pr.Pi(this.ir);this.dr.clear(),this.rr=this.mr.createCharacterObjects(t,this.ir),this.lr=this.vr.Ji(t,this.hr,this.ir);const i=this.gr.ji(this.rr,this.lr,this.hr,this.ir);this.nr=i.framebuffer,this.ar=i.columns,this.cr=i.rows}sr(t){return this.mr.sr(t,this.rr)}er(t){return this.mr.er(t,this.rr)}getGlyphData(t){if(!Number.isFinite(t))return null;const i=this.dr.get(t);if(i!==void 0)return i;const r=this.Cr(t);if(r<0)return this.dr.set(t,null),null;const h=this.ir.glyf;if(!h)return this.dr.set(t,null),null;let n=h[r]??null;return n==null&&(n=H.T.glyf.xi(this.ir,r)??null,h[r]=n),this.dr.set(t,n),n}Cr(t){const i=this.ir.cmap;for(const r of i.tables)if(r.format===4){const h=r;for(let n=0;n<h.startCount.length;n++)if(t>=h.startCount[n]&&t<=h.endCount[n]){if(h.idRangeOffset[n]===0)return t+h.idDelta[n]&65535;{const a=h.idRangeOffset[n]/2+(t-h.startCount[n])-(h.startCount.length-n);if(a>=0&&a<h.glyphIdArray.length){const c=h.glyphIdArray[a];if(c!==0)return c+h.idDelta[n]&65535}}}}else if(r.format===12){const h=r;for(let n=0;n<h.groups.length;n+=3){const a=h.groups[n],c=h.groups[n+1],u=h.groups[n+2];if(t>=a&&t<=c)return u+(t-a)}}return 0}D(){this.nr.D(),document.fonts.delete(this.ur)}get fontFramebuffer(){return this.nr}get characters(){return this.rr}get textureColumns(){return this.ar}get textureRows(){return this.cr}get maxGlyphDimensions(){return this.lr}get fontSize(){return this.hr}get font(){return this.ir}}class Et{constructor(t,i,r){l(this,"Mr");l(this,"Fr");l(this,"H");l(this,"G");l(this,"$r");l(this,"Tr");l(this,"Pr");l(this,"Er");l(this,"Rr");this.Pr=t,this.Er=i,this.Rr=r,this.Vs()}Vs(){this.Mr=Math.floor(this.Pr.width/this.Er),this.Fr=Math.floor(this.Pr.height/this.Rr),this.H=this.Mr*this.Er,this.G=this.Fr*this.Rr,this.$r=Math.floor((this.Pr.width-this.H)/2),this.Tr=Math.floor((this.Pr.height-this.G)/2)}Sr(t,i){this.Er=t,this.Rr=i,this.Vs()}get cellWidth(){return this.Er}get cellHeight(){return this.Rr}get cols(){return this.Mr}get rows(){return this.Fr}get width(){return this.H}get height(){return this.G}get offsetX(){return this.$r}get offsetY(){return this.Tr}}const Te=/^#([0-9a-f]{3,8})$/i,be=/^rgba?\(([^)]+)\)$/i;function wt(o){return Number.isNaN(o)?0:Math.max(0,Math.min(255,o))}function xe(o){if(!o)return null;const t=o.trim().toLowerCase();if(!t||t==="transparent")return null;let i=null;return t.startsWith("#")?i=function(r){const h=Te.exec(r.trim());if(!h)return null;const n=h[1];return n.length===3?[parseInt(n[0]+n[0],16),parseInt(n[1]+n[1],16),parseInt(n[2]+n[2],16),255]:n.length===4?[parseInt(n[0]+n[0],16),parseInt(n[1]+n[1],16),parseInt(n[2]+n[2],16),parseInt(n[3]+n[3],16)]:n.length===6||n.length===8?[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16),n.length===8?parseInt(n.slice(6,8),16):255]:null}(t):t.startsWith("rgb")&&(i=function(r){const h=be.exec(r.trim());if(!h)return null;const n=h[1].split(",").map(d=>d.trim());if(n.length<3)return null;const a=wt(parseFloat(n[0])),c=wt(parseFloat(n[1])),u=wt(parseFloat(n[2])),f=n[3]!==void 0?255*Math.max(0,Math.min(1,parseFloat(n[3]))):255;return[a,c,u,Math.round(f)]}(t)),i?i[3]===0?null:i:null}class Ut{constructor(t={}){l(this,"Pr");l(this,"kr",null);l(this,"zr",!1);l(this,"Ir");this.zr=t.overlay??!1,this.zr&&t.canvas?(this.kr=t.canvas,this.Pr=this.Or(),this.Ir=!0,this.Lr()):t.canvas?(this.Pr=t.canvas,this.Ir=!1):(this.Pr=this.Dr(t.width,t.height),this.Ir=!0),this.Pr.style.imageRendering="pixelated"}Dr(t,i){const r=document.createElement("canvas");return r.className="textmodeCanvas",r.style.imageRendering="pixelated",r.width=t||800,r.height=i||600,document.body.appendChild(r),r}Or(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.kr.getBoundingClientRect();let r=Math.round(i.width),h=Math.round(i.height);if(this.kr instanceof HTMLVideoElement){const c=this.kr;(r===0||h===0)&&c.videoWidth>0&&c.videoHeight>0&&(r=c.videoWidth,h=c.videoHeight)}t.width=r,t.height=h,t.style.position="absolute",t.style.pointerEvents="none";const n=window.getComputedStyle(this.kr);let a=parseInt(n.zIndex||"0",10);return isNaN(a)&&(a=0),t.style.zIndex=""+(a+1),t}Lr(){var t;this.Br(),(t=this.kr.parentNode)==null||t.insertBefore(this.Pr,this.kr.nextSibling)}Hr(){const t=[];return this.zr&&this.kr instanceof HTMLElement&&(t.push(this.kr),this.kr.parentElement&&t.push(this.kr.parentElement)),this.Pr.parentElement&&t.push(this.Pr.parentElement),t.push(this.Pr),t.push(document.body),t.push(document.documentElement),t}Gr(){const t=this.Hr();for(const i of t){if(!i)continue;const r=xe(window.getComputedStyle(i).backgroundColor);if(r)return r}return[255,255,255,255]}Br(){if(!this.kr)return;const t=this.kr.getBoundingClientRect();let i=this.kr.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.Pr.style.top=t.top-r.top+"px",this.Pr.style.left=t.left-r.left+"px"}else this.Pr.style.top=t.top+window.scrollY+"px",this.Pr.style.left=t.left+window.scrollX+"px"}Nr(t,i){if(this.zr){const r=this.kr.getBoundingClientRect();this.Pr.width=Math.round(r.width),this.Pr.height=Math.round(r.height),this.Br()}else this.Pr.width=t??this.Pr.width,this.Pr.height=i??this.Pr.height}Xr(){const t=this.Pr.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!0,stencil:!1,powerPreference:"high-performance"});if(!t)throw new x("`textmode.js` requires WebGL2 support.");return t}D(){const t=this.Pr.getContext("webgl")||this.Pr.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i==null||i.loseContext()}this.Ir&&this.Pr.parentNode&&this.Pr.parentNode.removeChild(this.Pr)}get canvas(){return this.Pr}get targetCanvas(){return this.kr}get width(){return this.Pr.width}get height(){return this.Pr.height}}const Re=/^#|0x/gi;function et(o){return Number.isNaN(o)||!Number.isFinite(o)||o<=0?0:o>=255?255:Math.round(o)}function ot(o){return et(parseInt(o,16))}class I{constructor(t,i,r,h,n){l(this,"Yr");l(this,"Kr");l(this,"Ht");l(this,"r");l(this,"g");l(this,"b");l(this,"a");this.r=et(t),this.g=et(i),this.b=et(r),this.a=et(h),this.Yr=[this.r,this.g,this.b,this.a],this.Kr=[this.r/255,this.g/255,this.b/255,this.a/255],this.Ht=n?[...n]:void 0}static jr(t,i,r,h=255){return new I(t,i,r,h)}static Zr(t,i=255){return new I(t,t,t,i)}static Wr(t){const[i,r,h,n]=function(a){const c=a.replace(Re,""),u=(f=c).length===3||f.length===4?f.split("").map(d=>d+d).join(""):f;var f;if(u.length!==6&&u.length!==8)throw Error("Invalid hex color: "+a);return[ot(u.slice(0,2)),ot(u.slice(2,4)),ot(u.slice(4,6)),u.length===8?ot(u.slice(6,8)):255]}(t);return new I(i,r,h,n)}static qr(t){const[i,r,h]=t;return new I(255*i,255*r,255*h,255,t)}get rgb(){return[this.r,this.g,this.b]}get rgba(){return[...this.Yr]}get normalized(){return[...this.Kr]}get character(){return this.Ht?[...this.Ht]:void 0}static Vr(t){return t instanceof I}}const W=class W{constructor(t,i,r,h,n,a,c){l(this,"A");l(this,"j");l(this,"Qr");l(this,"Jr");l(this,"tn");l(this,"H");l(this,"G");l(this,"Z",null);l(this,"$t",0);l(this,"Dt",0);l(this,"Bt",0);l(this,"Tt",0);l(this,"sn","sampled");l(this,"en","fixed");l(this,"Gt",[1,1,1,1]);l(this,"Nt",[0,0,0,1]);l(this,"rn",[0,0,0,1]);l(this,"nn",[[.1,0,0]]);l(this,"hn");this.A=t,this.j=i,this.Qr=r,this.Jr=h,this.tn=n,this.H=a,this.G=c}D(){this.A.deleteTexture(this.Qr)}invert(t=!0){return this.$t=t?1:0,this.Z=null,this}flipX(t=!0){return this.Dt=t?1:0,this.Z=null,this}flipY(t=!0){return this.Bt=t?1:0,this.Z=null,this}charRotation(t){return this.Tt=xt(t),this.Z=null,this}charColorMode(t){return this.sn=t,this.Z=null,this}cellColorMode(t){return this.en=t,this.Z=null,this}charColor(t,i,r,h){return this.cn(this.Gt,t,i,r,h),this.Z=null,this}cellColor(t,i,r,h){return this.cn(this.Nt,t,i,r,h),this.Z=null,this}background(t,i,r,h){return this.cn(this.rn,t,i,r,h),this.Z=null,this}characters(t){if(!this.hn)throw Error("Glyph color resolver not initialized");const i=this.hn(t).filter(r=>Array.isArray(r)).slice(0,64);return this.nn=i,this.Z=null,this}get texture(){return this.Qr}get width(){return this.H}get height(){return this.G}get originalWidth(){return this.Jr}get originalHeight(){return this.tn}ct(){return this.Z||this.lt(),this.Z}ln(){}lt(){this.ln();const t=this.un(),i=this.fn();this.Z=this.j.ft.Be(t,i)}cn(t,i,r,h,n){if(I.Vr(i))Y(t,i.r,i.g,i.b,i.a);else{if(typeof i=="string"){const a=I.Wr(i);return void Y(t,a.r,a.g,a.b,a.a)}Y(t,i,r,h,n)}}un(){return W.an||(W.an=new V(this.A,rt,`#version 300 es
|
|
11
|
+
precision highp float;in vec2 v_uv;uniform sampler2D Ug;uniform bool Uh;uniform bool Ui;uniform bool Uj;uniform float Uk;uniform bool Ul;uniform vec4 Um;uniform bool Un;uniform vec4 Uo;uniform vec4 Up;uniform int Uq;uniform vec3 Ur[64];layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;float A(vec3 B){return dot(B,vec3(0.299f,0.587f,0.114f));}void main(){vec2 C=vec2(v_uv.x,1.0f-v_uv.y);vec4 D=texture(Ug,C);float E=A(D.rgb);vec2 F=vec2(0.);if(Uq>0){float G=float(Uq);float H=clamp(E*(G-1.0f),0.0f,G-1.0f);int I=int(floor(H+0.5f));vec3 J=Ur[I];F=J.xy;}else{F=vec2(E,0.0f);}vec4 K=Ul?Um:D;vec4 L=Un?Uo:D;if(D.a<0.01f){K=Up;L=Up;}else{}o_primaryColor=vec4(K.rgb,K.a);o_secondaryColor=vec4(L.rgb,L.a);int M=int(Uh?1:0);int N=int(Ui?1:0);int O=int(Uj?1:0);float P=float(M|(N<<1)|(O<<2))/255.;o_character=vec4(F,P,clamp(Uk,0.0f,1.0f));}`)),W.an}fn(){return{Ug:this.dn(),Uh:!!this.$t,Ui:!!this.Dt,Uj:!!this.Bt,Uk:this.Tt,Ul:this.sn==="fixed",Um:this.Gt,Un:this.en==="fixed",Uo:this.Nt,Up:this.rn,Uq:this.nn.length,Ur:this.nn}}};l(W,"an",null);let at=W;class k extends at{constructor(t,i,r,h,n,a,c){const u=Math.min(a/h,c/n);super(t,i,r,h,n,Math.max(1,Math.floor(h*u)),Math.max(1,Math.floor(n*u)))}static pn(t,i,r,h,n){const a=t.context,c=a.createTexture();a.bindTexture(a.TEXTURE_2D,c),a.pixelStorei(a.UNPACK_FLIP_Y_WEBGL,1),it(a,a.NEAREST,a.NEAREST,a.CLAMP_TO_EDGE,a.CLAMP_TO_EDGE),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,i),a.bindTexture(a.TEXTURE_2D,null);const u=i.naturalWidth??i.width??i.videoWidth??0,f=i.naturalHeight??i.height??i.videoHeight??0,d=new k(a,t,c,u,f,r,h);return d.hn=n,d}dn(){return this.Qr}}class Dt{constructor(t=60){l(this,"gn");l(this,"vn",null);l(this,"mn",0);l(this,"_n",!0);l(this,"An",0);l(this,"yn",0);l(this,"wn",[]);l(this,"bn",10);l(this,"Cn",0);this.gn=1e3/t}Mn(t){if(!this._n)return;this.mn=performance.now();const i=r=>{if(!this._n)return void(this.vn=null);const h=r-this.mn;h>=this.gn&&(t(),this.mn=r-h%this.gn),this._n&&(this.vn=requestAnimationFrame(i))};this.vn=requestAnimationFrame(i)}xn(){this.vn&&(cancelAnimationFrame(this.vn),this.vn=null)}Fn(){this._n&&(this._n=!1,this.xn())}$n(t){this._n||(this._n=!0,this.Mn(t))}Tn(t,i){if(t===void 0)return this.An;this.gn=1e3/t,this._n&&i&&(this.xn(),this.Mn(i))}Pn(){const t=performance.now();if(this.yn>0){const i=t-this.yn;this.wn.push(i),this.wn.length>this.bn&&this.wn.shift();const r=this.wn.reduce((h,n)=>h+n,0)/this.wn.length;this.An=1e3/r}this.yn=t}get En(){return this._n}get Rn(){return this.An}get Sn(){return this.Cn}set Sn(t){this.Cn=t}kn(){this.Cn++}}class zt{constructor(t){l(this,"Pr");l(this,"zn");l(this,"In",{x:-1,y:-1});l(this,"On",{x:-1,y:-1});l(this,"Ln",null);l(this,"Dn",0);l(this,"Bn");l(this,"Hn");l(this,"Gn");l(this,"Nn");l(this,"Xn");l(this,"Yn");l(this,"Kn",!1);l(this,"jn");l(this,"Zn");l(this,"Wn");l(this,"qn");l(this,"Vn");this.Pr=t}Qn(t){const i=performance.now()+Math.max(0,t);i>this.Dn&&(this.Dn=i)}Jn(){return performance.now()<this.Dn}so(t){const i=this.Pr.canvas;i.style.cursor=t==null||t===""?"":t}_r(t){this.zn=t,this.eo()}io(){if(this.Kn)return;const t=this.Pr.canvas;this.Bn=i=>{this.ro(i),this.no(i)},this.Hn=()=>{this.On={...this.In},this.In.x=-1,this.In.y=-1,this.Ln=null},this.Gn=i=>{this.ro(i),this.oo(i)},this.Nn=i=>{this.ro(i),this.ho(i)},this.Xn=i=>{this.ro(i),this.ao(i)},this.Yn=i=>{this.ro(i),this.co(i)},t.addEventListener("mousemove",this.Bn,{passive:!0}),t.addEventListener("mouseleave",this.Hn,{passive:!0}),t.addEventListener("mousedown",this.Gn,{passive:!0}),t.addEventListener("mouseup",this.Nn,{passive:!0}),t.addEventListener("click",this.Xn,{passive:!0}),t.addEventListener("wheel",this.Yn,{passive:!1}),this.Kn=!0}lo(){if(!this.Kn)return;const t=this.Pr.canvas;t.removeEventListener("mousemove",this.Bn),t.removeEventListener("mouseleave",this.Hn),t.removeEventListener("mousedown",this.Gn),t.removeEventListener("mouseup",this.Nn),t.removeEventListener("click",this.Xn),t.removeEventListener("wheel",this.Yn),this.Kn=!1}eo(){if(this.Kn)try{if(this.Ln){const t=new MouseEvent("mousemove",{clientX:this.Ln.x,clientY:this.Ln.y,bubbles:!1,cancelable:!1});this.ro(t)}else this.In.x!==-1&&this.In.y!==-1&&(this.In.x>=this.zn.cols||this.In.y>=this.zn.rows)&&(this.In.x=-1,this.In.y=-1)}catch{this.In.x=-1,this.In.y=-1}}uo(t){this.jn=t}fo(t){this.Zn=t}do(t){this.Wn=t}po(t){this.qn=t}vo(t){this.Vn=t}mo(){return{x:this.In.x,y:this.In.y}}no(t){if(this.qn&&!this.Jn()){const i={position:{...this.In},previousPosition:{...this.On},originalEvent:t};this.qn(i)}}oo(t){if(this.Zn&&!this.Jn()){const i={position:{...this.In},previousPosition:{...this.On},button:t.button,originalEvent:t};this.Zn(i)}}ho(t){if(this.Wn&&!this.Jn()){const i={position:{...this.In},previousPosition:{...this.On},button:t.button,originalEvent:t};this.Wn(i)}}ao(t){if(this.jn&&!this.Jn()){const i={position:{...this.In},previousPosition:{...this.On},button:t.button,originalEvent:t};this.jn(i)}}co(t){if(this.Vn&&!this.Jn()){const i={position:{...this.In},previousPosition:{...this.On},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.Vn(i)}}ro(t){const i=this.Pr.canvas;this.On={...this.In},this.Ln={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),h=t.clientX-r.left,n=t.clientY-r.top,a=i.width/r.width,c=n*(i.height/r.height),u=h*a-this.zn.offsetX,f=c-this.zn.offsetY,d=Math.floor(u/this.zn.cellWidth),g=Math.floor(f/this.zn.cellHeight);d>=0&&d<this.zn.cols&&g>=0&&g<this.zn.rows?(this.In.x=d,this.In.y=g):(this.In.x=-1,this.In.y=-1)}}const Fe=Object.freeze(Object.defineProperty({__proto__:null,MouseManager:zt},Symbol.toStringTag,{value:"Module"}));class Lt{constructor(){l(this,"_o",new Map);l(this,"Ao",null);l(this,"yo",null);l(this,"wo");l(this,"bo");l(this,"Kn",!1);l(this,"Co");l(this,"Mo");l(this,"xo",{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"})}io(){this.Kn||(this.wo=t=>{this.Fo(t)},this.bo=t=>{this.$o(t)},window.addEventListener("keydown",this.wo,{passive:!1}),window.addEventListener("keyup",this.bo,{passive:!1}),this.Kn=!0)}lo(){this.Kn&&(window.removeEventListener("keydown",this.wo),window.removeEventListener("keyup",this.bo),this.Kn=!1,this._o.clear(),this.Ao=null,this.yo=null)}fo(t){this.Co=t}do(t){this.Mo=t}To(t){const i=this.Po(t),r=this._o.get(t)||this._o.get(i);return(r==null?void 0:r.isPressed)||!1}Eo(){return this.Ao}Ro(){return this.yo}So(){const t=[];for(const[i,r]of this._o)r.isPressed&&t.push(i);return t}ko(){return{ctrl:this.To("Control"),shift:this.To("Shift"),alt:this.To("Alt"),meta:this.To("Meta")}}zo(){this._o.clear(),this.Ao=null,this.yo=null}Fo(t){const i=t.key,r=Date.now();this._o.has(i)||this._o.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const h=this._o.get(i);if(!h.isPressed&&(h.isPressed=!0,h.lastPressTime=r,this.Ao=i,this.Co)){const n={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.Co(n)}}$o(t){const i=t.key,r=Date.now();this._o.has(i)||this._o.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const h=this._o.get(i);if(h.isPressed=!1,h.lastReleaseTime=r,this.yo=i,this.Mo){const n={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.Mo(n)}}Po(t){return this.xo[t]||t.toLowerCase()}}const Pe=Object.freeze(Object.defineProperty({__proto__:null,KeyboardManager:Lt},Symbol.toStringTag,{value:"Module"}));class Bt{constructor(t,i){l(this,"Pr");l(this,"Io");l(this,"zn");l(this,"Oo",new Map);l(this,"Lo",new Map);l(this,"Do",new Map);l(this,"Bo",null);l(this,"Ho");l(this,"Go");l(this,"No");l(this,"Xo");l(this,"Yo");l(this,"Ko");l(this,"Kn",!1);l(this,"jo");l(this,"Zo");l(this,"Wo");l(this,"qo");l(this,"Vo");l(this,"Qo");l(this,"Jo");l(this,"th");l(this,"sh");l(this,"eh");l(this,"ih",320);l(this,"rh",350);l(this,"nh",10);l(this,"oh",550);l(this,"hh",14);l(this,"ah",48);l(this,"uh",650);l(this,"fh",.02);l(this,"dh",2);l(this,"ph",600);l(this,"gh",0);l(this,"mh",null);this.Pr=t,this.Io=i;const r=this.Pr.canvas;this.Ho=r.style.touchAction,this.Go=r.style.userSelect,r.style.touchAction||(r.style.touchAction="none"),r.style.userSelect||(r.style.userSelect="none")}_r(t){this.zn=t,this.eo()}io(){if(this.Kn)return;const t=this.Pr.canvas;this.No=i=>{this._h(i)},this.Xo=i=>{this.Ah(i)},this.Yo=i=>{this.yh(i)},this.Ko=i=>{this.wh(i)},t.addEventListener("touchstart",this.No,{passive:!1}),t.addEventListener("touchmove",this.Xo,{passive:!1}),t.addEventListener("touchend",this.Yo,{passive:!1}),t.addEventListener("touchcancel",this.Ko,{passive:!1}),this.Kn=!0}lo(){if(!this.Kn)return;const t=this.Pr.canvas;t.removeEventListener("touchstart",this.No),t.removeEventListener("touchmove",this.Xo),t.removeEventListener("touchend",this.Yo),t.removeEventListener("touchcancel",this.Ko),this.Kn=!1,this.Bo=null,this.Oo.clear(),this.Lo.clear(),this.Do.forEach(i=>{i.longPressTimer!==null&&window.clearTimeout(i.longPressTimer)}),this.Do.clear(),this.mh=null,this.gh=0,t.style.touchAction=this.Ho,t.style.userSelect=this.Go}eo(){if(!this.zn||this.Oo.size===0)return;const t=new Map;for(const i of this.Oo.values()){const r=this.bh(i.clientX,i.clientY,i.id,i);t.set(i.id,r)}this.Oo=t}Ch(){return Array.from(this.Oo.values()).map(t=>({...t}))}Mh(t){this.jo=t}po(t){this.Zo=t}xh(t){this.Wo=t}Fh(t){this.qo=t}$h(t){this.Vo=t}Th(t){this.Qo=t}Ph(t){this.Jo=t}Eh(t){this.th=t}Rh(t){this.sh=t}Sh(t){this.eh=t}_h(t){var h;if(!this.zn)return;t.preventDefault(),(h=this.Io)==null||h.Qn(this.ph);const i=performance.now(),r=this.kh(t.changedTouches);for(const n of r){const a=this.Oo.get(n.id);a&&this.Lo.set(n.id,this.zh(a)),this.Oo.set(n.id,n);const c={id:n.id,startPosition:n,lastPosition:n,startTime:i,lastTime:i,longPressTimer:null,longPressFired:!1};this.Jo&&(c.longPressTimer=window.setTimeout(()=>{const u=this.Oo.get(n.id);u&&(c.longPressFired=!0,this.Jo({touch:this.zh(u),duration:performance.now()-c.startTime,originalEvent:t}))},this.oh)),this.Do.set(n.id,c),this.jo&&this.jo(this.Ih(n,t,void 0,i))}this.Oo.size===2&&this.Oh()}Ah(t){var h;if(!this.zn)return;t.preventDefault(),(h=this.Io)==null||h.Qn(this.ph);const i=performance.now(),r=this.kh(t.changedTouches);for(const n of r){const a=this.Oo.get(n.id),c=a?this.zh(a):void 0;c&&this.Lo.set(n.id,c),this.Oo.set(n.id,n);const u=this.Do.get(n.id);u&&(u.lastPosition=n,u.lastTime=i,c)&&q(c.clientX,c.clientY,n.clientX,n.clientY)>this.hh&&u.longPressTimer!==null&&(window.clearTimeout(u.longPressTimer),u.longPressTimer=null),this.Zo&&this.Zo(this.Ih(n,t,c,i))}this.Oo.size===2?this.Lh(t):this.Bo=null}yh(t){if(!this.zn)return;t.preventDefault();const i=performance.now(),r=this.kh(t.changedTouches);for(const h of r){const n=this.Oo.get(h.id),a=n?this.zh(n):void 0,c=this.Do.get(h.id);c&&c.longPressTimer!==null&&(window.clearTimeout(c.longPressTimer),c.longPressTimer=null),this.Wo&&this.Wo(this.Ih(h,t,a,i)),c&&this.Dh(c,t),this.Do.delete(h.id),this.Lo.delete(h.id),this.Oo.delete(h.id)}this.Oo.size<2&&(this.Bo=null)}wh(t){if(!this.zn)return;t.preventDefault();const i=performance.now(),r=this.kh(t.changedTouches);for(const h of r){const n=this.Oo.get(h.id),a=n?this.zh(n):void 0,c=this.Do.get(h.id);c&&c.longPressTimer!==null&&(window.clearTimeout(c.longPressTimer),c.longPressTimer=null),this.qo&&this.qo(this.Ih(h,t,a,i)),this.Do.delete(h.id),this.Lo.delete(h.id),this.Oo.delete(h.id)}this.Oo.size<2&&(this.Bo=null)}kh(t){const i=[];for(let r=0;r<t.length;r+=1){const h=t.item(r);h&&i.push(this.Bh(h))}return i}Bh(t){return this.bh(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})}bh(t,i,r,h){const n=this.Pr.canvas,a=n.getBoundingClientRect(),c=t-a.left,u=i-a.top,f=n.width/a.width,d=u*(n.height/a.height),g=c*f-this.zn.offsetX,p=d-this.zn.offsetY,m=Math.floor(g/this.zn.cellWidth),v=Math.floor(p/this.zn.cellHeight),A=m>=0&&m<this.zn.cols&&v>=0&&v<this.zn.rows;return{id:r,x:A?m:-1,y:A?v:-1,clientX:t,clientY:i,pressure:h.pressure,radiusX:h.radiusX,radiusY:h.radiusY,rotationAngle:h.rotationAngle}}Ih(t,i,r,h){const n=this.Do.get(t.id),a=Array.from(this.Lo.values()).map(f=>this.zh(f)),c=Array.from(this.Oo.values()).map(f=>this.zh(f)),u=this.kh(i.changedTouches);return{touch:this.zh(t),previousTouch:r?this.zh(r):void 0,touches:c,previousTouches:a,changedTouches:u,deltaTime:n?h-n.lastTime:0,originalEvent:i}}Oh(){if(this.Oo.size!==2)return void(this.Bo=null);const t=Array.from(this.Oo.values()),[i,r]=t,h=q(i.x,i.y,r.x,r.y),n=bt(i.clientX,i.clientY,r.clientX,r.clientY);this.Bo={ids:[i.id,r.id],initialDistance:Math.max(h,1e-4),initialAngle:n,lastScale:1,lastRotation:0}}Lh(t){if(this.Bo||this.Oh(),!this.Bo)return;const[i,r]=this.Bo.ids,h=this.Oo.get(i),n=this.Oo.get(r);if(!h||!n)return;const a=q(h.x,h.y,n.x,n.y)/this.Bo.initialDistance,c=a-this.Bo.lastScale;this.sh&&Math.abs(c)>this.fh&&(this.sh({touches:[this.zh(h),this.zh(n)],scale:a,deltaScale:c,center:this.Hh(h,n),originalEvent:t}),this.Bo.lastScale=a);let u=bt(h.clientX,h.clientY,n.clientX,n.clientY)-this.Bo.initialAngle;u=(u+180)%360-180;const f=u-this.Bo.lastRotation;this.eh&&Math.abs(f)>this.dh&&(this.eh({touches:[this.zh(h),this.zh(n)],rotation:u,deltaRotation:f,center:this.Hh(h,n),originalEvent:t}),this.Bo.lastRotation=u)}Hh(t,i){const r=(t.clientX+i.clientX)/2,h=(t.clientY+i.clientY)/2,n=this.bh(r,h,-1,{id:-1,x:-1,y:-1,clientX:r,clientY:h});return{x:n.x,y:n.y}}Dh(t,i){const r=performance.now(),h=r-t.startTime,n=q(t.startPosition.clientX,t.startPosition.clientY,t.lastPosition.clientX,t.lastPosition.clientY);if(!t.longPressFired&&h<=this.ih&&n<=this.nh)this.Gh(t.lastPosition,r)&&this.Qo?this.Qo({touch:this.zh(t.lastPosition),taps:2,originalEvent:i}):this.Vo&&this.Vo({touch:this.zh(t.lastPosition),taps:1,originalEvent:i});else if(!t.longPressFired&&h<=this.uh&&n>=this.ah){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/h,y:a.y/h};this.th&&this.th({touch:this.zh(t.lastPosition),direction:u,distance:c,velocity:f,originalEvent:i})}this.gh=r,this.mh=this.zh(t.lastPosition)}Gh(t,i){return!!this.mh&&!(i-this.gh>this.rh)&&q(t.clientX,t.clientY,this.mh.clientX,this.mh.clientY)<=this.nh}zh(t){return{...t}}}const Ce=Object.freeze(Object.defineProperty({__proto__:null,TouchManager:Bt},Symbol.toStringTag,{value:"Module"}));class ct extends at{constructor(i,r,h,n,a,c,u,f){const d=a/c;let g,p;d>1?(g=u,p=Math.round(u/d)):(p=f,g=Math.round(f*d));super(i,r,h,a,c,g,p);l(this,"Nh");l(this,"Xh",!1);l(this,"Yh",[]);l(this,"An",null);l(this,"Kh",0);l(this,"jh",0);l(this,"Zh",-1);this.Nh=n}D(){super.D();for(const i of this.Yh)this.A.deleteTexture(i);this.Yh=[],this.Nh.pause(),this.Nh.src="",this.Nh.load()}Wh(){if(!this.Xh&&this.Nh.readyState>=this.Nh.HAVE_CURRENT_DATA){const i=this.A;i.bindTexture(i.TEXTURE_2D,this.Qr),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,this.Nh),i.bindTexture(i.TEXTURE_2D,null)}}dn(){if(this.Xh&&this.Yh.length>0){const i=this.jh%this.Yh.length;return this.Yh[i]}return this.Qr}ct(){return this.Z=null,super.ct()}ln(){this.Wh()}async qh(i,r){var h;try{if(i<=0)throw Error("Video preload requires a frameRate greater than 0.");const n=this.Nh.duration;if(!isFinite(n)||n<=0)throw Error("Video duration is invalid, cannot preload frames.");const a=Math.max(1,Math.ceil(n*i));if(this.Vh(i,a),await this.Qh(i,r))return void this.Jh("captureStream",r);await this.ta(i,r),this.Jh("seeking",r)}catch(n){const a=n instanceof Error?n:Error(n+"");throw(h=r==null?void 0:r.onError)==null||h.call(r,a),a}}Vh(i,r){this.An=i,this.Kh=r,this.Yh=[],this.Xh=!1,this.jh=0,this.Zh=-1}Jh(i,r){var h;if(this.Yh.length===0)throw Error(`Video preload via ${i} completed but produced 0 frames.`);this.Kh=this.Yh.length,this.Xh=!0,this.jh=0,this.Zh=-1,this.Nh.pause(),this.Nh.currentTime=0,r!=null&&r.onProgress&&r.onProgress({percent:100,loadedFrames:this.Kh,totalFrames:this.Kh,strategy:i}),(h=r==null?void 0:r.onComplete)==null||h.call(r,{totalFrames:this.Kh,strategy:i})}sa(i){const r=this.A,h=r.createTexture();return r.bindTexture(r.TEXTURE_2D,h),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),it(r,r.LINEAR,r.LINEAR,r.CLAMP_TO_EDGE,r.CLAMP_TO_EDGE),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,i),r.bindTexture(r.TEXTURE_2D,null),h}ea(i,r){if(!(r!=null&&r.onProgress)||this.Kh===0)return;const h=Math.min(99,Math.floor(this.Yh.length/this.Kh*100)),n=10*Math.floor(h/10);n>this.Zh&&(this.Zh=n,r.onProgress({percent:h,loadedFrames:this.Yh.length,totalFrames:this.Kh,strategy:i}))}async Qh(i,r){const h=globalThis,n=h==null?void 0:h.MediaStreamTrackProcessor,a=this.Nh.captureStream;if(typeof n!="function"||typeof a!="function")return!1;let c,u=null;try{const f=a.call(this.Nh);if(c=f.getVideoTracks()[0],!c)return f.getTracks().forEach(p=>p.stop()),!1;if(u=new n({track:c}).readable.getReader(),this.Nh.currentTime=0,this.Nh.muted=!0,await this.Nh.play().catch(()=>{}),this.Nh.paused)return!1;const d=1e6/i;let g=0;for(;this.Yh.length<this.Kh;){const p=await u.read();if(p.done)break;const m=p.value;if(m)try{const v=typeof m.timestamp=="number"?m.timestamp:g;(this.Yh.length===0||v>=g)&&(this.Yh.push(this.sa(m)),g=v+d,this.ea("captureStream",r))}finally{m.close()}}return u.releaseLock(),c.stop(),u=null,c=void 0,this.Nh.pause(),this.Nh.currentTime=0,this.Yh.length!==0}catch{return this.Yh=[],this.Zh=-1,!1}finally{if(u)try{await u.cancel()}catch{}c&&c.stop(),this.Nh.pause(),this.Nh.currentTime=0}}async ta(i,r){const h=1/i,n=this.Kh,a=this.Nh;a.pause();for(let c=0;c<n;c++){const u=Math.min(a.duration,c*h);await this.ia(u),this.Yh.push(this.sa(a)),this.ea("seeking",r)}a.currentTime=0}ia(i){return new Promise((r,h)=>{const n=this.Nh,a=()=>{n.removeEventListener("seeked",c),n.removeEventListener("error",u)},c=()=>{a(),r()},u=()=>{a(),h(Error("Video seek failed while preloading frames."))};n.addEventListener("seeked",c,{once:!0}),n.addEventListener("error",u,{once:!0});const f=isFinite(n.duration)?n.duration:i,d=Math.min(Math.max(i,0),f);if(Math.abs(n.currentTime-d)<1e-4)return a(),void r();n.currentTime=d})}frame(i){return this.Xh&&i!==void 0&&this.Kh>0&&(this.jh=(i%this.Kh+this.Kh)%this.Kh,this.Z=null),this}static async pn(i,r,h,n,a,c){const u=i.context,f=c==null?void 0:c.frameRate;let d;typeof r=="string"?(d=document.createElement("video"),d.crossOrigin="anonymous",d.loop=!0,d.muted=!0,d.playsInline=!0,await new Promise((A,E)=>{d.addEventListener("loadedmetadata",()=>A(),{once:!0}),d.addEventListener("error",y=>{var w;const T=y.target;E(Error("Failed to load video: "+(((w=T.error)==null?void 0:w.message)||"Unknown error")))},{once:!0}),d.src=r})):(d=r,d.readyState<d.HAVE_METADATA&&await new Promise((A,E)=>{d.addEventListener("loadedmetadata",()=>A(),{once:!0}),d.addEventListener("error",y=>{var T;return E(Error("Video error: "+((T=y.target.error)==null?void 0:T.message)))},{once:!0})}));const g=u.createTexture();u.bindTexture(u.TEXTURE_2D,g),u.pixelStorei(u.UNPACK_FLIP_Y_WEBGL,1),it(u,u.LINEAR,u.LINEAR,u.CLAMP_TO_EDGE,u.CLAMP_TO_EDGE),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,u.RGBA,u.UNSIGNED_BYTE,d),u.bindTexture(u.TEXTURE_2D,null);const p=d.videoWidth,m=d.videoHeight,v=new ct(u,i,g,d,p,m,h,n);return v.hn=a,f&&f>0&&await v.qh(f,c),v}async play(){await this.Nh.play()}pause(){this.Nh.pause()}stop(){this.Nh.pause(),this.Nh.currentTime=0}speed(i){return this.Nh.playbackRate=i,this}loop(i=!0){return this.Nh.loop=i,this}time(i){return this.Nh.currentTime=i,this}volume(i){return this.Nh.volume=Math.max(0,Math.min(1,i)),this}get texture(){return this.Qr}get width(){return this.H}get height(){return this.G}get originalWidth(){return this.Jr}get originalHeight(){return this.tn}get videoElement(){return this.Nh}get currentTime(){return this.Nh.currentTime}get duration(){return this.Nh.duration}get isPlaying(){return!this.Nh.paused&&!this.Nh.ended}get isPreloaded(){return this.Xh}get totalFrames(){return this.Kh}get preloadFrameRate(){return this.An}get currentFrameIndex(){return this.jh}}const Me=o=>class extends o{ra(t,i,r,h){if(I.Vr(t))return t;if(typeof t=="number"||typeof t=="string")return this.color(t,i,r,h);throw Error("Unsupported color input passed to color-capable method.")}rotate(t=0,i=0,r=0){this.j.state.Wt(t),this.j.state.qt(i),this.j.state.Vt(r)}rotateX(t){this.j.state.Wt(t)}rotateY(t){this.j.state.qt(t)}rotateZ(t){this.j.state.Vt(t)}translate(t=0,i=0,r=0){this.j.state.Qt(t,i,r)}translateX(t){this.j.state.Qt(t,0,0)}translateY(t){this.j.state.Qt(0,t,0)}translateZ(t){this.j.state.Qt(0,0,t)}push(){this.j.state.rt()}pop(){this.j.state.nt()}color(t,i,r,h){if(I.Vr(t))return t;if(typeof t=="string"){const n=Array.from(t);if(n.length===1){const a=n[0],c=this.ir.sr(a);return I.qr(c)}return I.Wr(t)}if(typeof t=="number")return typeof i=="number"&&typeof r=="number"?I.jr(t,i,r,h??255):typeof i=="number"&&r===void 0?I.Zr(t,i):I.Zr(t,h??255);throw Error("Unsupported color input passed to color().")}rect(t=1,i=1){this.j.gi(t,i)}point(){this.j.gi(1,1)}line(t,i,r,h){this.j.mi(t,i,r,h)}lineWeight(t){this.j.state.jt(t)}background(t,i,r,h=255){const n=this.ra(t,i,r,h);this.j.Ci(n.r,n.g,n.b,n.a)}char(t){if(I.Vr(t)){const r=t.character;return void(r&&this.j.state.es(r))}const i=Array.from(t);if(i.length===0)throw Error("char() requires at least one character.");this.j.state.es(this.ir.sr(i[0]))}charColor(t,i,r,h){const n=this.ra(t,i,r,h);this.j.state.rs(n.r,n.g,n.b,n.a)}cellColor(t,i,r,h){const n=this.ra(t,i,r,h);this.j.state.ns(n.r,n.g,n.b,n.a)}flipX(t){this.j.state.hs(t)}flipY(t){this.j.state.cs(t)}charRotation(t){this.j.state.us(t)}invert(t){this.j.state.ls(t)}clear(){this.j.Ci(0,0,0,0)}ellipse(t,i){this.j._i(t/2,i/2)}triangle(t,i,r,h,n,a){this.j.Ai(t,i,r,h,n,a)}bezierCurve(t,i,r,h,n,a,c,u){this.j.yi(t,i,r,h,n,a,c,u)}arc(t,i,r,h){this.j.wi(t/2,i/2,r,h)}shader(t){this.j.li(t)}setUniform(t,i){this.j.O(t,i)}setUniforms(t){this.j.ui(t)}async createFilterShader(t){if(typeof t=="string"&&(t.includes("/")||t.startsWith("./")||t.startsWith("../")||t.endsWith(".frag")||t.endsWith(".glsl"))){const i=await fetch(t);if(!i.ok)throw Error(`Failed to load shader from ${t}: ${i.statusText}`);const r=await i.text();return this.j.fi(r)}return this.j.fi(t)}createFramebuffer(t){return this.j.bi(t.width??this.grid.cols,t.height??this.grid.rows,3)}image(t,i,r){this.j.di(t,i,r)}ortho(){this.j.state.ds(!0)}async loadImage(t){if(typeof t!="string")return k.pn(this.j,t,this.zn.cols,this.zn.rows,h=>this.ir.er(h));const i=t,r=await new Promise((h,n)=>{const a=new Image;a.crossOrigin="anonymous",a.onload=()=>h(a),a.onerror=c=>n(c),a.src=i});return k.pn(this.j,r,this.zn.cols,this.zn.rows,h=>this.ir.er(h))}async loadVideo(t,i){return ct.pn(this.j,t,this.zn.cols,this.zn.rows,r=>this.ir.er(r),i)}},Ne=o=>class extends o{async loadFont(t){return this.ir.br(t).then(()=>{const i=this.ir.maxGlyphDimensions;this.zn.Sr(i.width,i.height),this.na.resize(this.zn.cols,this.zn.rows),this.j.Mi(),this.Io.eo(),this.oa.eo()})}fontSize(t){if(!Z.m(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.ir.fontSize===t)return;this.ir.wr(t);const i=this.ir.maxGlyphDimensions;this.zn.Sr(i.width,i.height),this.na.resize(this.zn.cols,this.zn.rows),this.j.Mi(),this.Io.eo(),this.oa.eo()}},Ie=o=>class extends o{get frameCount(){return this.ha.Sn}set frameCount(t){this.ha.Sn=t}frameRate(t){return t===void 0?this.ha.Rn:this.ha.Tn(t,()=>this.aa())}noLoop(){this.ha.Fn()}loop(){this.ha.$n(()=>this.aa())}redraw(t=1){if(Z.m(typeof t=="number"&&t>0&&Number.isInteger(t),"Redraw count must be a positive integer.",{method:"redraw",providedValue:t}))for(let i=0;i<t;i++)this.aa()}isLooping(){return this.ha.En}},Ue=o=>class extends o{constructor(...t){super(...t)}mouseClicked(t){this.Io.uo(t)}mousePressed(t){this.Io.fo(t)}mouseReleased(t){this.Io.do(t)}mouseMoved(t){this.Io.po(t)}mouseScrolled(t){this.Io.vo(t)}get mouse(){return this.Io.mo()}cursor(t){this.Io.so(t)}},De=o=>class extends o{constructor(...t){super(...t)}touchStarted(t){this.oa.Mh(t)}touchMoved(t){this.oa.po(t)}touchEnded(t){this.oa.xh(t)}touchCancelled(t){this.oa.Fh(t)}tap(t){this.oa.$h(t)}doubleTap(t){this.oa.Th(t)}longPress(t){this.oa.Ph(t)}swipe(t){this.oa.Eh(t)}pinch(t){this.oa.Rh(t)}rotateGesture(t){this.oa.Sh(t)}get touches(){return this.oa.Ch()}},ze=o=>class extends o{constructor(...t){super(...t)}keyPressed(t){this.ca.fo(t)}keyReleased(t){this.ca.do(t)}isKeyPressed(t){return this.ca.To(t)}get lastKeyPressed(){return this.ca.Eo()}get lastKeyReleased(){return this.ca.Ro()}get pressedKeys(){return this.ca.So()}get modifierState(){return this.ca.ko()}};class Le{constructor(t){l(this,"la");l(this,"ua",new Map);l(this,"fa",[]);l(this,"da",new Map);l(this,"pa",new Map);this.la=t}async ga(t){for(const i of t){if(this.ua.has(i.name))return void console.warn(`[textmode.js] Plugin "${i.name}" is already installed.`);const r=this.va(i.name);try{await i.install(this.la,r)}catch(h){throw this.ma(i.name),h}this.ua.set(i.name,i),this.fa.push(i.name)}}async _a(t){const i=this.ua.get(t);if(!i)return;const r=this.va(t);i.uninstall&&await i.uninstall(this.la,r),this.ua.delete(t),this.fa.splice(this.fa.indexOf(t),1),this.ma(t)}ya(){this.wa(this.da)}ba(){this.wa(this.pa)}async Ca(){const t=[...this.ua.keys()];for(const i of t)await this._a(i)}va(t){return{renderer:this.la.j,font:this.la.ir,grid:this.la.zn,canvas:this.la.Pr,drawFramebuffer:this.la.na,asciiFramebuffer:this.la.Ma,registerPreDrawHook:i=>this.xa(this.da,t,i),registerPostDrawHook:i=>this.xa(this.pa,t,i)}}xa(t,i,r){const h=t.get(i)??new Set;return h.add(r),t.set(i,h),()=>{const n=t.get(i);n&&(n.delete(r),n.size===0&&t.delete(i))}}ma(t){this.da.delete(t),this.pa.delete(t)}wa(t){for(const i of this.fa){const r=t.get(i);r&&r.forEach(h=>h())}}}const St=`#version 300 es
|
|
12
|
+
in vec2 A0;in vec2 A1;out vec2 v_uv;void main(){v_uv=A1;gl_Position=vec4(A0,0.,1.);}`;class Ot{constructor(){l(this,"Fa",new Map);l(this,"$a",[]);l(this,"Ta",0);l(this,"Pa",0);l(this,"Ea")}get Ra(){return this.Ta}get Sa(){if(this.Ta===0)return 0;let t=0;for(const i of this.$a){const r=this.Fa.get(i);r&&(t+=Math.min(1,Math.max(0,r.progress))*r.weight)}return Math.min(1,t/this.Ta)}ka(t){this.Ea=t}za(t,i=1){const r=`phase-${this.$a.length+1}-${Date.now()}`,h={id:r,label:t,weight:Math.max(.001,i),progress:0,status:"running"};return this.Fa.set(r,h),this.$a.push(r),this.Ta+=h.weight,r}Ia(t,i){const r=this.Fa.get(t);if(!r)return;r.progress=Math.max(0,Math.min(1,i)),r.status=r.progress>=1?"complete":"running";const h=this.Sa;Math.abs(h-this.Pa)>.001&&(this.Pa=h,this.Ea&&this.Ea(h))}Oa(t){const i=this.Fa.get(t);i&&(i.progress=1,i.status="complete",this.Ia(t,1))}La(t){const i=this.Fa.get(t);i&&(i.status="failed")}Da(){return this.$a.map(t=>{const i=this.Fa.get(t);return i?{id:i.id,label:i.label,weight:i.weight,progress:i.progress,status:i.status}:{id:t,label:t,weight:1,progress:0,status:"pending"}})}}class Xt{constructor(t="active"){l(this,"Ba");l(this,"Ha","");l(this,"Ga","");this.Ba=t}get Na(){return this.Ba}get Xa(){return this.Ba!=="disabled"}get Ya(){return this.Ba==="active"||this.Ba==="transitioning"||this.Ba==="error"}get Ka(){return this.Ha}get ja(){return this.Ga}Za(){this.Ba!=="done"&&this.Ba!=="transitioning"||(this.Ba="active")}Wa(){this.Ba!=="disabled"&&(this.Ba="done")}qa(){this.Ba!=="disabled"&&(this.Ba="transitioning")}Va(){this.Ba==="transitioning"&&(this.Ba="done")}Qa(t){this.Ba!=="disabled"&&(this.Ba="error",t instanceof Error?(this.Ha=t.message,this.Ga=t.stack||""):(this.Ha=t,this.Ga=""))}Ja(){this.Ba="disabled"}}class Gt{constructor(t,i){l(this,"tc",0);l(this,"sc",1);l(this,"ec");l(this,"rc");this.ec=t,this.rc=i}get nc(){return this.sc}get oc(){return this.sc<1}Mn(){this.ec!=="none"&&this.rc>0&&(this.tc=performance.now())}st(){if(this.ec==="none"||this.rc===0)return this.sc=1,!1;const t=performance.now()-this.tc,i=Math.min(1,t/this.rc);return i>=1?(this.sc=0,!0):(this.sc=1-i,!1)}Vs(){this.sc=1,this.tc=0}}function Tt(o,t){const i=o.tone??"auto";let r="dark";return i==="light"||i==="dark"?r=i:t&&(r=function(h){if(!h)return 0;const[n,a,c]=h.map(f=>f/255),u=f=>f<=.04045?f/12.92:Math.pow((f+.055)/1.055,2.4);return .2126*u(n)+.7152*u(a)+.0722*u(c)}(t)>.5?"light":"dark"),{mode:r,background:t,textColor:r==="light"?"#1A1A1A":"#F8F8F8",subtleColor:r==="light"?"#4A4A4A":"#C0C0C0"}}function Yt(o){return o.mode==="light"?["#E91E63","#9C27B0","#FF6F00"]:["#8EF9F3","#F15BB5","#FF9B71"]}function jt(o,t){return o.length?o.map(i=>t.color(i)):[t.color("#FFFFFF")]}const Be=({textmodifier:o,grid:t,progress:i,frameCount:r,message:h,palette:n,theme:a,phases:c,transitionOpacity:u,isError:f,errorMessage:d})=>{const g="|/-\\",p=Math.floor(r/6)%4,m=o.color(a.textColor),v=Math.floor(255*u),A=o.color(m.r,m.g,m.b,v);if(o.charColor(A),o.cellColor(0,0,0,0),f){const E=o.color(a.mode==="light"?"#D32F2F":"#FF6B6B",v);o.charColor(E),o.push(),o.translate(0,-2,0),o.char("X"),o.rect(1,1),o.pop();const y="SETUP ERROR",T=-Math.floor(y.length/2);o.push(),o.translate(T,0,0);for(const w of y)o.char(w),o.rect(1,1),o.translateX(1);if(o.pop(),d){const w=o.color(a.subtleColor),R=o.color(w.r,w.g,w.b,v);o.charColor(R);const b=Math.floor(.8*t.cols),M=d.split(" "),z=[];let N="";for(const D of M)(N+" "+D).length<=b?N=N?N+" "+D:D:(N&&z.push(N),N=D);N&&z.push(N);const B=z.slice(0,3);z.length>3&&(B[2]=B[2].substring(0,b-3)+"..."),B.forEach((D,ut)=>{const ke=-Math.floor(D.length/2);o.push(),o.translate(ke,3+ut,0);for(const Ke of D)o.char(Ke),o.rect(1,1),o.translateX(1);o.pop()})}return}if(o.push(),o.translate(0,0,0),o.char(g[p]),o.rect(1,1),o.pop(),i>0||c.some(E=>E.status!=="pending")){const E=Math.max(6,Math.floor(.6*t.cols)),y=-Math.floor(E/2),T=Math.floor(E*i),w=n.length?n:[o.color("#FFFFFF")];o.push(),o.translate(y,3,0);for(let R=0;R<E;R++){const b=R<T?"*":".",M=w[R%w.length],z=o.color(M.r,M.g,M.b,v);o.charColor(z),o.char(b),o.rect(1,1),o.translateX(1)}o.pop()}if(h){const E=o.color(a.subtleColor),y=o.color(E.r,E.g,E.b,v);o.charColor(y);const T=-Math.floor(h.toUpperCase().length/2);o.push(),o.translate(T,5,0);for(const w of h.toUpperCase())o.char(w),o.rect(1,1),o.translateX(1);o.pop()}},Se={message:"loading...",tone:"auto",transition:"fade",transitionDuration:500};class Oe{constructor(t,i,r){this.hc=t,this.id=i,this.label=r}report(t){this.hc.Ia(this.id,t)}complete(){this.hc.Oa(this.id)}fail(t){this.hc.La(this.id)}async track(t){try{const i=typeof t=="function"?await t():await t;return this.complete(),i}catch(i){throw this.fail(),i}}}class _t{constructor(t,i,r){l(this,"la");l(this,"l");l(this,"ac");l(this,"hc");l(this,"cc");l(this,"lc");l(this,"uc");l(this,"fc");l(this,"dc");l(this,"gc");l(this,"j");l(this,"vc",[]);l(this,"mc");l(this,"_c",performance.now());l(this,"yc",0);l(this,"wc",!1);l(this,"bc",!1);l(this,"Fc");this.la=t,this.l={...Se,...i??{}},this.ac=new Xt("active"),this.hc=new Ot,this.cc=new Gt(this.l.transition,this.l.transitionDuration),this.lc=new Dt(60),this.mc=Tt(this.l,r);const h=Yt(this.mc);this.vc=jt(h,this.la),this.j=this.Cc(),this.hc.ka(n=>{n>=.999&&this.Wa()})}async _r(t){if(this.bc)return;const i=this.la.j,r=this.la.Pr;this.uc=new yt(i,16),await this.uc._r(t);const h=this.uc.maxGlyphDimensions;this.fc=new Et(r.canvas,h.width,h.height),this.dc=i.bi(this.fc.cols,this.fc.rows,3),this.gc=i.bi(this.fc.width,this.fc.height,1),this.bc=!0}get Ya(){return this.ac.Ya&&this.wc}Mn(){this.wc||(this.wc=!0,this._c=performance.now(),this.yc=0,this.lc.Mn(()=>this.Mc()))}xn(){this.wc&&(this.wc=!1,this.lc.xn())}Nr(){this.bc&&(this.fc.Vs(),this.dc.resize(this.fc.cols,this.fc.rows),this.gc.resize(this.fc.width,this.fc.height))}D(){this.xn(),this.bc&&(this.uc.D(),this.dc.D(),this.gc.D(),this.bc=!1)}get progress(){return this.hc.Sa}message(t){return typeof t=="string"&&(this.l.message=t),this.l.message}addPhase(t,i=1){this.ac.Za();const r=this.hc.za(t,i);return new Oe(this.hc,r,t)}Wa(){this.l.transition!=="none"&&this.l.transitionDuration>0?(this.ac.qa(),this.cc.Mn()):(this.ac.Wa(),this.xn(),this.xc())}xc(){this.Fc&&this.Fc()}$c(t){this.Fc=t}error(t){this.ac.Qa(t)}Mc(){if(this.ac.Ya){if(this.yc++,this.ac.Na==="transitioning"&&this.cc.st())return this.ac.Va(),this.xc(),void this.xn();this.Tc()}}Tc(){if(!this.bc)return;const t=this.dc,i=this.uc,r=this.fc,h=this.gc,n=this.la.j,a=this.la.Pr,c=this.la.Pc,u=this.la.Ec;n.state.Zt(),t.begin(),this.la.clear(),this.la.push();try{const f={textmodifier:this.la,grid:r,progress:this.progress,elapsedMs:performance.now()-this._c,frameCount:this.yc,message:this.l.message,palette:this.vc,theme:this.mc,phases:this.hc.Da(),transitionOpacity:this.cc.nc,isError:this.ac.Na==="error",errorMessage:this.ac.Ka||void 0,errorDetails:this.ac.ja||void 0};this.j(f)}finally{this.la.pop()}t.end(),h.begin(),n.ai(c),c.I({U0:i.fontFramebuffer,U1:[i.textureColumns,i.textureRows],U2:t.textures[0],U3:t.textures[1],U4:t.textures[2],U5:[r.cols,r.rows],U6:[h.width,h.height],U7:n.state.canvasBackgroundColor}),n.pi(0,0,a.width,a.height),h.end(),n.me(...n.state.canvasBackgroundColor),n.ai(u),u.I({U8:h.textures[0],U9:[h.width,h.height],Ua:[r.offsetX,r.offsetY],Ub:[r.width,r.height]}),n.pi(r.offsetX,r.offsetY,r.width,r.height)}Rc(t){this.mc=Tt(this.l,t)}Cc(){const t=this.l.renderer||Be;return i=>{t(i),this.Sc(i)}}Sc(t){const{textmodifier:i,grid:r,frameCount:h,theme:n,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=n.mode==="light"?[[233,30,99],[156,39,176],[255,111,0]]:[[142,249,243],[241,91,181],[255,155,113]];i.push(),i.translate(f,u,0);for(let g=0;g<c.length;g++){const p=c[g],m=Math.floor(.1*h+.5*g)%d.length,[v,A,E]=d[m],y=Math.floor(255*a),T=i.color(v,A,E,y);i.charColor(T),i.char(p),i.point(),i.translateX(1)}i.pop()}}class Ht extends function(i,...r){return r.reduce((h,n)=>n(h),i)}(class{},Me,Ne,Ie,Ue,De,ze){constructor(i={}){super();l(this,"j");l(this,"ir");l(this,"Pr");l(this,"zn");l(this,"ha");l(this,"Io");l(this,"oa");l(this,"ca");l(this,"kc");l(this,"na");l(this,"Pc");l(this,"Ma");l(this,"Ec");l(this,"zc");l(this,"Ic",!1);l(this,"Oc",!1);l(this,"Lc",!1);l(this,"Dc",!1);l(this,"Bc",()=>{});l(this,"Hc",()=>{});l(this,"Gc",()=>{});l(this,"Nc");l(this,"Xc");l(this,"zr",!1);l(this,"Yc");this.zc=new Le(this),this.zr=i.overlay??!1,this.Pr=new Ut(i),this.j=new ae(this.Pr.Xr()),this.ir=new yt(this.j,i.fontSize??16),this.ha=new Dt(i.frameRate??60),this.kc=new _t(this,i.loadingScreen,this.Pr.Gr()),this.kc.$c(()=>{this.ha.Sn=0,this.Dc=!0}),this.Io=new zt(this.Pr),this.oa=new Bt(this.Pr,this.Io),this.ca=new Lt,this.Pc=this.j.ci(St,`#version 300 es
|
|
13
|
+
precision highp float;uniform sampler2D U0;uniform vec2 U1;uniform sampler2D U3;uniform sampler2D U4;uniform sampler2D U2;uniform vec2 U5;uniform vec2 U6;uniform vec4 U7;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/U6;vec2 F=E*U5;vec2 G=floor(F);vec2 H=(G+0.5)/U5;vec4 I=texture(U3,H);vec4 J=texture(U4,H);vec4 K=texture(U2,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(U1.x);int R=P/Q;int S=P-(R*Q);float T=(U1.y-1.)-float(R);vec2 U=1./U1;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(U0,a);if(M)c.rgb=mix(c.rgb,1.-c.rgb,float(M));vec4 d=mix(U7,J,J.a);fragColor=mix(d,I,c);}`),this.kc.Mn(),this.Kc(i)}async Kc(i){await Promise.all([this.ir._r(i.fontSource),this.kc._r(i.fontSource)]);const r=this.ir.maxGlyphDimensions;this.zn=new Et(this.Pr.canvas,r.width,r.height),this.Io._r(this.zn),this.oa._r(this.zn),this.na=this.j.bi(this.zn.cols,this.zn.rows,3),this.Ma=this.j.bi(this.zn.width,this.zn.height,1),this.zr&&(this.Yc=k.pn(this.j,this.Pr.targetCanvas,this.zn.cols,this.zn.rows,h=>this.ir.er(h))),this.Ec=this.j.ci(St,`#version 300 es
|
|
14
|
+
precision highp float;uniform sampler2D U8;uniform vec2 U9;uniform vec2 Ua;uniform vec2 Ub;in vec2 v_uv;out vec4 fragColor;void main(){vec2 A=gl_FragCoord.xy-Ua;vec2 B=A*(U9/Ub);vec2 C=(floor(B)+0.5)/U9;fragColor=texture(U8,C);}`),this.jc(),this.ha.Mn(()=>this.aa()),await this.zc.ga(i.plugins??[]);try{await this.Bc(),this.kc.Wa()}catch(h){console.error("Error during setup:",h),this.kc.error(h)}}jc(){this.Nc=()=>{this.zr&&this.resizeCanvas(this.Pr.targetCanvas.width,this.Pr.targetCanvas.height),this.Gc()},window.addEventListener("resize",this.Nc),this.Io.io(),this.oa.io(),this.ca.io(),window.addEventListener("blur",()=>{this.ca.zo()}),this.zr&&(this.Xc=new ResizeObserver(()=>{this.resizeCanvas(this.Pr.targetCanvas.width,this.Pr.targetCanvas.height)}),this.Xc.observe(this.Pr.targetCanvas))}aa(){if(!this.kc.Ya&&this.Dc){this.Oc=!0;try{this.ha.Pn(),this.ha.kn(),this.zr&&Rt(this.j.context,this.Yc.texture,this.Pr.targetCanvas),this.zc.ya(),this.j.state.Zt(),this.na.begin(),this.Hc(),this.na.end(),this.Ma.begin(),this.j.ai(this.Pc),this.Pc.I({U0:this.ir.fontFramebuffer,U1:[this.ir.textureColumns,this.ir.textureRows],U2:this.na.textures[0],U3:this.na.textures[1],U4:this.na.textures[2],U5:[this.zn.cols,this.zn.rows],U6:[this.Ma.width,this.Ma.height],U7:this.j.state.canvasBackgroundColor}),this.j.pi(0,0,this.Pr.width,this.Pr.height),this.Ma.end(),this.j.me(...this.j.state.canvasBackgroundColor),this.j.ai(this.Ec),this.Ec.I({U8:this.Ma.textures[0],U9:[this.Ma.width,this.Ma.height],Ua:[this.zn.offsetX,this.zn.offsetY],Ub:[this.zn.width,this.zn.height]}),this.j.pi(this.zn.offsetX,this.zn.offsetY,this.zn.width,this.zn.height),this.zc.ba()}finally{this.Oc=!1,this.Ic&&!this.Lc&&this.Zc()}}}resizeCanvas(i,r){this.Pr.Nr(i,r),this.kc.Rc(this.Pr.Gr()),this.zn.Vs(),this.kc.Nr(),this.na.resize(this.zn.cols,this.zn.rows),this.Ma.resize(this.zn.width,this.zn.height),this.j.Mi(),this.Io.eo(),this.oa.eo(),this.aa()}destroy(){this.Lc||this.Ic||(this.Ic=!0,this.ha.Fn(),this.Oc||this.Zc())}Zc(){var i,r;this.Ic=!1,this.kc.D(),this.zc.Ca(),window.removeEventListener("resize",this.Nc),(i=this.Xc)==null||i.disconnect(),this.Io.lo(),this.oa.lo(),this.ca.lo(),this.na.D(),this.Pc.D(),this.ir.D(),this.j.D(),this.Ma.D(),this.Ec.D(),(r=this.Yc)==null||r.D(),this.Pr.D(),this.Lc=!0}setup(i){this.Bc=i}draw(i){this.Hc=i}windowResized(i){this.Gc=i}get grid(){return this.zn}get font(){return this.ir}get width(){return this.Pr.width}get height(){return this.Pr.height}get canvas(){return this.Pr.canvas}get drawFramebuffer(){return this.na}get isDisposed(){return this.Lc}get overlay(){return this.Yc}get loading(){return this.kc}}class lt{constructor(){}static create(t={}){return new Ht(t)}static setErrorLevel(t){Z._(t)}static get version(){return"0.6.0-beta.2"}}const Xe=Object.freeze(Object.defineProperty({__proto__:null,LoadingPhaseTracker:Ot,LoadingScreenManager:_t,LoadingScreenStateMachine:Xt,LoadingScreenTransition:Gt,resolveColorInputs:jt,resolveDefaultPalette:Yt,resolveTheme:Tt},Symbol.toStringTag,{value:"Module"})),Ge=Object.freeze(Object.defineProperty({__proto__:null,TextmodeFont:yt,TextmodeImage:k,TextmodeVideo:ct},Symbol.toStringTag,{value:"Module"})),Ye=Object.freeze(Object.defineProperty({__proto__:null,keyboard:Pe,mouse:Fe,touch:Ce},Symbol.toStringTag,{value:"Module"})),je=lt.create,_e=lt.setErrorLevel,He=lt.version;F.TextmodeCanvas=Ut,F.TextmodeColor=I,F.TextmodeErrorLevel=X,F.TextmodeFramebuffer=Q,F.TextmodeGrid=Et,F.Textmodifier=Ht,F.create=je,F.input=Ye,F.loadables=Ge,F.loading=Xe,F.setErrorLevel=_e,F.textmode=lt,F.version=He,Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):e((s=typeof globalThis<"u"?globalThis:s||self).textmode={});
|