textmode.js 0.2.1-beta.3 → 0.2.1-beta.4
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 +1107 -1069
- package/dist/textmode.esm.min.js +1356 -1318
- package/dist/textmode.umd.js +7 -7
- package/dist/textmode.umd.min.js +7 -7
- package/dist/types/rendering/webgl/Shader.d.ts +17 -1
- package/dist/types/textmode/mixins/AnimationMixin.d.ts +2 -0
- package/package.json +1 -1
package/dist/textmode.umd.min.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var oe=Object.defineProperty;var ae=(R,
|
|
1
|
+
var oe=Object.defineProperty;var ae=(R,E,L)=>E in R?oe(R,E,{enumerable:!0,configurable:!0,writable:!0,value:L}):R[E]=L;var u=(R,E,L)=>ae(R,typeof E!="symbol"?E+"":E,L);var e,s;e=this,s=function(R){class E extends Error{constructor(t,i={}){super(E.u(t,i)),this.name="TextmodeError"}static u(t,i){return`${t}${i&&Object.keys(i).length>0?`
|
|
2
2
|
|
|
3
3
|
📋 Context:`+Object.entries(i).map(([r,n])=>`
|
|
4
|
-
- ${r}: ${
|
|
4
|
+
- ${r}: ${E._(n)}`).join(""):""}
|
|
5
5
|
|
|
6
6
|
${"↓".repeat(24)}
|
|
7
|
-
`}static _(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=>v._(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>v._(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}: ${v._(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${v._(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var S=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(S||{});const L=class L{constructor(){l(this,"C",{globalLevel:3})}static $(){return L.v||(L.v=new L),L.v}R(t,i){const r="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",n="color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";switch(this.C.globalLevel){case 0:return!1;case 1:return console.group(r,n),console.warn(v.u(t,i)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(v.u(t,i)),console.groupEnd(),!1;default:throw new v(t,i)}}M(t,i,r){return!!t||(this.R(i,r),!1)}S(t){this.C.globalLevel=t}};l(L,"v",null);let k=L;const B=k.$(),H=new WeakMap;function N(c,t){H.set(c,t)}function z(c){return H.get(c)}class j{constructor(){l(this,"F",1);l(this,"P",0);l(this,"G",0);l(this,"A",0);l(this,"L",[0,0,0]);l(this,"D",[1,1,1,1]);l(this,"W",[0,0,0,1]);l(this,"I",!1);l(this,"U",!1);l(this,"O",!1);l(this,"V",[0,0]);l(this,"H",[0,0,0,1]);l(this,"K",[])}N(){this.K.push({X:this.F,Y:this.P,Z:this.G,J:this.A,V:[...this.V],I:this.I,U:this.U,O:this.O,tt:[...this.L],et:[...this.D],st:[...this.W]})}it(){const t=this.K.pop();t?(this.F=t.X,this.P=t.Y,this.G=t.Z,this.A=t.J,this.V=t.V,this.I=t.I,this.U=t.U,this.O=t.O,this.L=t.tt,this.D=t.et,this.W=t.st):console.warn("pop() called without matching push()")}rt(){this.K=[],this.P=0,this.G=0,this.A=0}nt(t){t.lineWeight=this.F,t.rotationX=this.P,t.rotationY=this.G,t.rotationZ=this.A,t.character[0]=this.L[0],t.character[1]=this.L[1],t.character[2]=this.L[2],t.charColor[0]=this.D[0],t.charColor[1]=this.D[1],t.charColor[2]=this.D[2],t.charColor[3]=this.D[3],t.bgColor[0]=this.W[0],t.bgColor[1]=this.W[1],t.bgColor[2]=this.W[2],t.bgColor[3]=this.W[3],t.flipHorizontally=this.I,t.flipVertically=this.U,t.invert=this.O,t.charRotation[0]=this.V[0],t.charRotation[1]=this.V[1]}get lineWeight(){return this.F}get canvasBackgroundColor(){return this.H}ot(t){this.F=Math.abs(t)}ht(t){this.P=t}ct(t){this.G=t}lt(t){this.A=t}ut(t){this.L=t}ft(t,i,r,n=255){this.D=[t/255,i/255,r/255,n/255]}dt(t,i,r,n=255){this.W=[t/255,i/255,r/255,n/255]}_t(t){this.I=t}gt(t){this.U=t}vt(t){this.O=t}yt(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));this.V=[r,n]}Ct(t,i,r,n){this.H=[t/255,i/255,r/255,n/255]}}class O{constructor(t,i,r=i,n=1,o={},a=null,h=!1){l(this,"$t");l(this,"wt");l(this,"C");l(this,"bt",null);l(this,"xt");l(this,"Rt");l(this,"Mt",[]);l(this,"St");l(this,"Ft",null);l(this,"zt",[]);l(this,"Pt",null);l(this,"Tt",!1);l(this,"kt",null);this.$t=i,this.wt=r,this.C={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.xt=t,this.St=Math.min(Math.max(1,n),8),this.Pt=a,this.Tt=!!h,this.kt=this.Tt?new j:null;const u=t.getParameter(t.MAX_DRAW_BUFFERS),f=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.St=Math.min(this.St,u,f),this.Rt=t.createFramebuffer(),this.Gt(),this.At(),this.zt=Array(this.St).fill(null)}Gt(){const t=this.xt,i=this.C.filter==="linear"?t.LINEAR:t.NEAREST,r=this.C.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE,n=this.C.type==="float"?t.FLOAT:t.UNSIGNED_BYTE;for(let o=0;o<this.St;o++){const a=t.createTexture();t.bindTexture(t.TEXTURE_2D,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,r),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.$t,this.wt,0,t.RGBA,n,null),this.Mt.push(a)}t.bindTexture(t.TEXTURE_2D,null)}At(){const t=this.xt;if(t.bindFramebuffer(t.FRAMEBUFFER,this.Rt),this.St===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.Mt[0],0);else{const r=[];for(let n=0;n<this.St;n++){const o=t.COLOR_ATTACHMENT0+n;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,this.Mt[n],0),r.push(o)}t.drawBuffers(r)}const i=t.checkFramebufferStatus(t.FRAMEBUFFER);i!==t.FRAMEBUFFER_COMPLETE&&console.error("GLFramebuffer is not complete:",i),t.bindFramebuffer(t.FRAMEBUFFER,null)}Lt(t){const i=this.xt;i.bindTexture(i.TEXTURE_2D,this.Mt[0]),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,1),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.bindTexture(i.TEXTURE_2D,null)}resize(t,i){this.$t=t,this.wt=i,this.bt=null,this.zt=Array(this.St).fill(null);const r=this.xt,n=this.C.type==="float"?r.FLOAT:r.UNSIGNED_BYTE;for(const o of this.Mt)r.bindTexture(r.TEXTURE_2D,o),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.$t,this.wt,0,r.RGBA,n,null);r.bindTexture(r.TEXTURE_2D,null)}Et(t){const i=this.xt,r=this.zt[t];if(r)return r;const n=this.$t,o=this.wt,a=new Uint8Array(n*o*4),h=i.getParameter(i.READ_FRAMEBUFFER_BINDING);i.bindFramebuffer(i.READ_FRAMEBUFFER,this.Rt),i.readBuffer(i.COLOR_ATTACHMENT0+t),i.readPixels(0,0,n,o,i.RGBA,i.UNSIGNED_BYTE,a),i.bindFramebuffer(i.READ_FRAMEBUFFER,h);const u=4*n,f=new Uint8Array(a.length);for(let p=0;p<o;p++){const d=(o-1-p)*u,g=p*u;f.set(a.subarray(d,d+u),g)}return this.zt[t]=f,f}begin(){var i,r,n,o;const t=this.xt;if(this.Pt){const a=((r=(i=this.Pt).Bt)==null?void 0:r.call(i))??null;a&&this.Pt.Dt(a),this.Tt&&this.kt&&((o=(n=this.Pt).Wt)==null||o.call(n,this.kt))}this.Ft={framebuffer:t.getParameter(t.FRAMEBUFFER_BINDING),viewport:t.getParameter(t.VIEWPORT)},t.bindFramebuffer(t.FRAMEBUFFER,this.Rt),this.zt=Array(this.St).fill(null);for(let a=0;a<this.St;a++)t.clearBufferfv(t.COLOR,a,new Float32Array([0,0,0,0]));t.viewport(0,0,this.$t,this.wt),N(t,[0,0,this.$t,this.wt])}end(){var i,r,n,o;if(!this.Ft)return;const t=this.xt;if(this.Pt){const a=((r=(i=this.Pt).Bt)==null?void 0:r.call(i))??null;a&&this.Pt.Dt(a)}t.bindFramebuffer(t.FRAMEBUFFER,this.Ft.framebuffer),t.viewport(...this.Ft.viewport),N(t,this.Ft.viewport),this.Ft=null,this.Pt&&this.Tt&&this.kt&&((o=(n=this.Pt).It)==null||o.call(n))}Ut(){const t=this.xt;t.deleteFramebuffer(this.Rt);for(const i of this.Mt)t.deleteTexture(i)}get width(){return this.$t}get height(){return this.wt}get textures(){return[...this.Mt]}}function K(c){return typeof c=="string"?c:c.sourceCode}class D{constructor(t,i,r){l(this,"xt");l(this,"Ot");l(this,"Vt",new Map);l(this,"Ht",0);this.xt=t,this.Ot=this.Kt(K(i),K(r)),this.Nt()}Nt(){const t=this.xt.getProgramParameter(this.Ot,this.xt.ACTIVE_UNIFORMS);for(let i=0;i<t;i++){const r=this.xt.getActiveUniform(this.Ot,i);if(r){const n=this.xt.getUniformLocation(this.Ot,r.name);n&&this.Vt.set(r.name,n)}}}Kt(t,i){const r=this.jt(this.xt.VERTEX_SHADER,t),n=this.jt(this.xt.FRAGMENT_SHADER,i),o=this.xt.createProgram();if(this.xt.attachShader(o,r),this.xt.attachShader(o,n),this.xt.linkProgram(o),!this.xt.getProgramParameter(o,this.xt.LINK_STATUS)){const a=this.xt.getProgramInfoLog(o);throw Error("Shader program link error: "+a)}return this.xt.deleteShader(r),this.xt.deleteShader(n),o}jt(t,i){const r=this.xt.createShader(t);if(this.xt.shaderSource(r,i),this.xt.compileShader(r),!this.xt.getShaderParameter(r,this.xt.COMPILE_STATUS)){const n=this.xt.getShaderInfoLog(r);throw this.xt.deleteShader(r),Error("Shader compilation error: "+n)}return r}Xt(){this.xt.useProgram(this.Ot),this.Yt()}Yt(){this.Ht=0}qt(t){for(const[i,r]of Object.entries(t))this.Zt(i,r)}Jt(t){return this.Vt.has(t)}Zt(t,i){var n;const r=this.Vt.get(t);if(r)if(typeof i=="number")this.xt.uniform1f(r,i);else if(typeof i=="boolean")this.xt.uniform1i(r,i?1:0);else if(Array.isArray(i))if(Array.isArray(i[0])){const o=i,a=((n=o[0])==null?void 0:n.length)||0,h=o.flat();switch(a){case 2:this.xt.uniform2fv(r,h);break;case 3:this.xt.uniform3fv(r,h);break;case 4:this.xt.uniform4fv(r,h);break;default:return void console.warn(`Unsupported vector array length for '${t}': ${a}`)}}else switch(i.length){case 2:this.xt.uniform2f(r,i[0],i[1]);break;case 3:this.xt.uniform3f(r,i[0],i[1],i[2]);break;case 4:this.xt.uniform4f(r,i[0],i[1],i[2],i[3]);break;default:return}else if(i instanceof WebGLTexture){const o=this.Qt();this.xt.uniform1i(r,o),this.xt.activeTexture(this.xt.TEXTURE0+o),this.xt.bindTexture(this.xt.TEXTURE_2D,i)}else if(i instanceof O){const o=this.Qt();this.xt.uniform1i(r,o),this.xt.activeTexture(this.xt.TEXTURE0+o),this.xt.bindTexture(this.xt.TEXTURE_2D,i.textures[0])}else console.warn(`Unsupported uniform type for '${t}':`,typeof i)}Qt(){return this.Ht++}get te(){return this.Ot}Ut(){this.xt.deleteProgram(this.Ot)}}const X=`#version 300 es
|
|
8
|
-
in vec2 a_position;in vec2 a_texCoord;in vec2 a_instancePosition;in vec2 a_instanceSize;in vec3 a_instanceCharacter;in vec4 a_instancePrimaryColor;in vec4 a_instanceSecondaryColor;in vec2 a_instanceRotation;in vec3 a_instanceTransform;in vec3 a_instanceGlobalRotation;in vec2 a_instanceRotationCenter;in vec2 a_instanceBezierCP1;in vec2 a_instanceBezierCP2;in vec2 a_instanceBezierStart;in vec2 a_instanceBezierEnd;in vec2 a_instanceArcAngles;uniform float k;uniform vec2 t;out vec2 v_uv;out vec3 v_character;out vec4 v_primaryColor;out vec4 v_secondaryColor;out vec2 v_rotation;out vec3 v_transform;mat3 A(float B){float C=sin(B),D=cos(B);return mat3(1,0,0,0,D,-C,0,C,D);}mat3 E(float B){float C=sin(B),D=cos(B);return mat3(D,0,C,0,1,0,-C,0,D);}mat3 F(float B){float C=sin(B),D=cos(B);return mat3(D,-C,0,C,D,0,0,0,1);}vec2 G(float t,vec2 H,vec2 I,vec2 J,vec2 K){float L=1.-t,M=L*L,N=t*t;return M*L*H+3.*M*t*I+3.*L*N*J+N*t*K;}vec2 O(float t,vec2 H,vec2 I,vec2 J,vec2 K){float L=1.-t,M=L*L,N=t*t;return-3.*M*H+3.*M*I-6.*L*t*I+6.*L*t*J-3.*N*J+3.*N*K;}void main(){v_uv=a_texCoord;v_character=a_instanceCharacter;v_primaryColor=a_instancePrimaryColor;v_secondaryColor=a_instanceSecondaryColor;v_rotation=a_instanceRotation;v_transform=a_instanceTransform;vec2 P;bool Q=length(a_instanceBezierCP1)+length(a_instanceBezierCP2)+length(a_instanceBezierStart)+length(a_instanceBezierEnd)>0.;bool R=a_instanceArcAngles.x!=0.||a_instanceArcAngles.y!=0.;if(Q){float t=a_position.x;vec2 S=G(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 T=O(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float U=length(T);T=U>0.?T/U:vec2(1,0);P=S+vec2(-T.y,T.x)*a_position.y*a_instanceSize.y;}else if(R){float C=a_instanceArcAngles.x,V=a_instanceArcAngles.y;C=mod(C,6.28318530718);if(C<0.)C+=6.28318530718;V=mod(V,6.28318530718);if(V<0.)V+=6.28318530718;float W=C-V;if(W<=0.)W+=6.28318530718;float X=C-a_position.x*W;vec2 Y=vec2(cos(X),sin(X))*a_position.y;P=Y*a_instanceSize*.5+a_instanceSize*.5+a_instancePosition;}else{P=a_position*a_instanceSize+a_instancePosition;}vec2 Z=(P/t)*2.-1.;Z.y=-Z.y;if(length(a_instanceGlobalRotation)>0.){vec3 a=vec3(Z-a_instanceRotationCenter,0);a.x*=k;if(a_instanceGlobalRotation.x!=0.)a=A(-a_instanceGlobalRotation.x)*a;if(a_instanceGlobalRotation.y!=0.)a=E(-a_instanceGlobalRotation.y)*a;if(a_instanceGlobalRotation.z!=0.)a=F(-a_instanceGlobalRotation.z)*a;a.x/=k;Z=a.xy+a_instanceRotationCenter;}gl_Position=vec4(Z,0,1);}`;class nt{constructor(t){
|
|
9
|
-
precision highp float;in vec2 v_uv;uniform sampler2D l;uniform sampler2D m;uniform sampler2D n;uniform sampler2D o;uniform sampler2D p;uniform vec2 q;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*q;vec2 C=(floor(B)+0.5f)/q;vec4 D=texture(l,C);vec4 E=texture(m,C);if(E.a==0.){discard;}vec4 F=texture(n,C);vec4 G=texture(o,C);vec4 H=texture(p,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;o_rotation=G;o_transform=H;}`))}Bt(){return this.
|
|
10
|
-
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.);}`))}re(){return this.se("ascii-conversion",()=>new D(this.xt,"attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.,1.);}","precision mediump float;uniform sampler2D a;uniform vec2 b;uniform sampler2D d;uniform sampler2D e;uniform sampler2D f;uniform sampler2D c;uniform sampler2D g;uniform vec2 h;uniform vec2 i;uniform vec2 j;mat2 A(float B){float C=sin(B);float c=cos(B);return mat2(c,-C,C,c);}void main(){vec2 D=(gl_FragCoord.xy-j)/i;vec2 E=D*h;vec2 F=floor(E);vec2 G=(F+0.5)/h;vec4 H=texture2D(d,G);vec4 I=texture2D(e,G);vec4 J=texture2D(f,G);bool K=J.r>0.5;bool L=J.g>0.5;bool M=J.b>0.5;vec4 N=texture2D(c,G);int O=int(N.r*255.+0.5)+int(N.g*255.+0.5)*256;int P=int(mod(float(O),b.x));int Q=O/int(b.x);float R=(b.y-1.)-float(Q);vec2 S=vec2(float(P),R)/b;vec4 T=texture2D(g,G);float U=T.r*255.+T.g;float V=-(U*360./255.)*0.017453292;vec2 W=fract(E)-0.5;if(L)W.x=-W.x;if(M)W.y=-W.y;W=A(V)*W+0.5;vec2 X=1./b;vec2 Y=S+W*X;vec2 Z=S+X;if(any(lessThan(Y,S))||any(greaterThan(Y,Z))){gl_FragColor=K?H:I;return;}vec4 a=texture2D(a,Y);if(K)a.rgb=1.-a.rgb;gl_FragColor=mix(I,H,a);}"))}ne(t){return new D(this.xt,X,t)}oe(t,i){return new D(this.xt,t,i)}Ut(){for(const t of this.ee.values())t.Ut();this.ee.clear()}}var y=(c=>(c.RECTANGLE="rectangle",c.LINE="line",c.ELLIPSE="ellipse",c.ARC="arc",c.TRIANGLE="triangle",c.BEZIER_CURVE="bezier_curve",c.CUSTOM="custom",c))(y||{});class ot{constructor(t){l(this,"xt");l(this,"ae",new Map);this.xt=t}he(t,i,r,n){const o=this.xt;let a=this.ae.get(t);a||(a=new Map,this.ae.set(t,a));let h=a.get(i)||null;if(!h){h=o.createVertexArray(),a.set(i,h),o.bindVertexArray(h),o.bindBuffer(o.ARRAY_BUFFER,n);const u=o.getAttribLocation(t,"a_position");u!==-1&&(o.enableVertexAttribArray(u),o.vertexAttribPointer(u,r.le.ce.size,o.FLOAT,!1,r.ue,r.le.ce.offset),o.vertexAttribDivisor(u,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,r.le.fe.size,o.FLOAT,!1,r.ue,r.le.fe.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(h)}de(){this.xt.bindVertexArray(null)}Ut(){const t=this.xt;for(const[,i]of this.ae)for(const[,r]of i)r&&t.deleteVertexArray(r);this.ae.clear()}}class at{constructor(t,i){l(this,"_e");l(this,"xt");l(this,"Pt");l(this,"pe",null);l(this,"ge",null);this.xt=t,this._e=new ot(t),this.Pt=i}me(t,i,r){const{shader:n}=t,o=z(this.xt)||this.xt.getParameter(this.xt.VIEWPORT);n.qt({k:o[2]/o[3],t:[o[2],o[3]]});const a=f=>{if(!f||!f.ve())return;const p=f.unitGeometry,d=f.unitBuffer;try{this._e.he(n.te,f.type+"",p,d),f.batch.ye(n),f.batch.Ce(p.$e,p.we)}finally{f.batch.be(n),this._e.de(),f.xe()}};let h=null,u=null;for(const f of i){if(f.type===y.CUSTOM){u&&(a(u),h=null,u=null),this.Re(t,f.params,f.state,r.get(y.RECTANGLE));continue}h!==null&&f.type!==h&&(a(u),h=null,u=null);let p=u;p&&f.type===h||(p=r.get(f.type)||null,u=p,h=f.type),p&&p.Me(f.params,f.state)}a(u)}Re(t,i,r,n){const{x:o,y:a,width:h,height:u,shader:f,uniforms:p}=i;if(f===this.Se())return this.Fe(n,f,p,Math.floor(o),Math.floor(a),Math.max(1,Math.floor(h)),Math.max(1,Math.floor(u)),r),void t.shader.Xt();const d=this.ze(Math.max(1,Math.floor(h)),Math.max(1,Math.floor(u)));d.begin(),this.Fe(n,f,p,0,0,d.width,d.height,{}),d.end();const g=this.Se(),m={l:d.textures[0],m:d.textures[1],n:d.textures[2],o:d.textures[3],p:d.textures[4],q:[d.width,d.height]};this.Fe(n,g,m,Math.floor(o),Math.floor(a),Math.max(1,Math.floor(h)),Math.max(1,Math.floor(u)),r),t.shader.Xt()}Fe(t,i,r,n,o,a,h,u){i.Xt(),i.qt(r);const f=this.xt.getParameter(this.xt.VIEWPORT);if(i.qt({k:f[2]/f[3],t:[f[2],f[3]]}),t.xe(),t.Me({x:n,y:o,width:a,height:h},u),t.ve()){const p=t.unitGeometry,d=t.unitBuffer;try{this._e.he(i.te,t.type+"",p,d),t.batch.ye(i),t.batch.Ce(p.$e,p.we)}finally{t.batch.be(i),this._e.de(),t.xe()}}}Se(){return this.Pt.ie()}ze(t,i){return this.pe&&this.ge&&this.ge.w===t&&this.ge.h===i||(this.pe&&this.pe.Ut(),this.pe=new O(this.xt,t,i,5),this.ge={w:t,h:i}),this.pe}}class ht{constructor(){l(this,"Pe",[]);l(this,"Te",1);l(this,"ke",0)}Ge(t){if(this.ke>=this.Pe.length){const r={id:this.Te++,type:t,params:{},state:{X:1,Y:0,Z:0,J:0,character:[0,0,0],charColor:[1,1,1,1],bgColor:[0,0,0,1],flipHorizontally:!1,flipVertically:!1,invert:!1,charRotation:[0,0]}};this.Pe.push(r)}const i=this.Pe[this.ke];switch(i.id=this.Te++,i.type=t,t){case y.RECTANGLE:case y.ELLIPSE:i.params&&"width"in i.params||(i.params={x:0,y:0,width:0,height:0});break;case y.CUSTOM:i.params&&"shader"in i.params||(i.params={x:0,y:0,width:0,height:0,shader:void 0,uniforms:{}});break;case y.ARC:i.params&&"start"in i.params||(i.params={x:0,y:0,width:0,height:0,start:0,stop:0});break;case y.LINE:i.params&&"x2"in i.params||(i.params={x1:0,y1:0,x2:0,y2:0,thickness:void 0});break;case y.TRIANGLE:i.params&&"x3"in i.params||(i.params={x1:0,y1:0,x2:0,y2:0,x3:0,y3:0});break;case y.BEZIER_CURVE:i.params&&"cp2y"in i.params||(i.params={x1:0,y1:0,cp1x:0,cp1y:0,cp2x:0,cp2y:0,x2:0,y2:0,thickness:void 0});break;default:i.params||(i.params={})}return this.ke++,i}Ae(t,i,r,n,o){const a=this.Ge(y.RECTANGLE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.nt(a.state),a.id}Le(t,i,r,n,o,a,h){const u=this.Ge(y.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=a,h.nt(u.state),u.id}Ee(t,i,r,n,o,a){const h=this.Ge(y.LINE);return h.params.x1=t,h.params.y1=i,h.params.x2=r,h.params.y2=n,h.params.thickness=o,a.nt(h.state),h.id}Be(t,i,r,n,o){const a=this.Ge(y.ELLIPSE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.nt(a.state),a.id}De(t,i,r,n,o,a,h){const u=this.Ge(y.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=a,h.nt(u.state),u.id}We(t,i,r,n,o,a,h){const u=this.Ge(y.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=a,h.nt(u.state),u.id}Ie(t,i,r,n,o,a,h,u,f,p){const d=this.Ge(y.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=a,d.params.x2=h,d.params.y2=u,d.params.thickness=f,p.nt(d.state),d.id}get length(){return this.ke}get isEmpty(){return this.ke===0}Ue(){this.ke=0}[Symbol.iterator](){let t=0;const i=this.ke,r=this.Pe;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const F=class F{static Oe(t,i,r=0){var a,h,u,f,p,d,g,m,x,E;const n=i||new Float32Array(F.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.position[0],n[o++]=t.position[1],n[o++]=t.size[0],n[o++]=t.size[1],n[o++]=t.tt[0],n[o++]=t.tt[1],n[o++]=t.tt[2],n[o++]=t.primaryColor[0],n[o++]=t.primaryColor[1],n[o++]=t.primaryColor[2],n[o++]=t.primaryColor[3],n[o++]=t.secondaryColor[0],n[o++]=t.secondaryColor[1],n[o++]=t.secondaryColor[2],n[o++]=t.secondaryColor[3],n[o++]=t.rotation[0],n[o++]=t.rotation[1],n[o++]=t.transform[0],n[o++]=t.transform[1],n[o++]=t.transform[2],n[o++]=t.globalRotationX,n[o++]=t.globalRotationY,n[o++]=t.globalRotationZ,n[o++]=t.rotationCenter[0],n[o++]=t.rotationCenter[1],n[o++]=((a=t.arcAngles)==null?void 0:a[0])||0,n[o++]=((h=t.arcAngles)==null?void 0:h[1])||0,n[o++]=((u=t.bezierControlPoint1)==null?void 0:u[0])||0,n[o++]=((f=t.bezierControlPoint1)==null?void 0:f[1])||0,n[o++]=((p=t.bezierControlPoint2)==null?void 0:p[0])||0,n[o++]=((d=t.bezierControlPoint2)==null?void 0:d[1])||0,n[o++]=((g=t.bezierStartPoint)==null?void 0:g[0])||0,n[o++]=((m=t.bezierStartPoint)==null?void 0:m[1])||0,n[o++]=((x=t.bezierEndPoint)==null?void 0:x[0])||0,n[o++]=((E=t.bezierEndPoint)==null?void 0:E[1])||0,n}static Ve(t){const i=t.length*F.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*F.FLOATS_PER_INSTANCE;F.Oe(t[n],r,o)}return r}};l(F,"BYTES_PER_INSTANCE",140),l(F,"FLOATS_PER_INSTANCE",35);let M=F;const b=class b{};l(b,"STRIDE",M.BYTES_PER_INSTANCE),l(b,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:b.STRIDE,offset:132,divisor:1}});let G=b;class ct{constructor(t,i=1e3,r=1.5){l(this,"xt");l(this,"He",[]);l(this,"Ke");l(this,"Ne");l(this,"je",null);l(this,"Xe",!0);l(this,"Ye",0);l(this,"qe",new Map);l(this,"Ze",null);this.xt=t,this.Ke=i,this.Ne=r,this.Je()}Me(t){const i=this.He.length;return this.He.push(t),this.Xe=!0,i}get count(){return this.He.length}get isEmpty(){return this.He.length===0}clear(){this.He.length=0,this.Xe=!0}Qe(t){if(t<=this.Ke)return;const i=Math.ceil(t*this.Ne);this.Ke=i,this.Je()}Je(){const t=this.xt;this.je&&t.deleteBuffer(this.je),this.je=t.createBuffer();const i=this.Ke*M.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.je),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Xe=!0,this.Ye=0}ts(){if(!this.Xe||this.He.length===0)return;const t=this.xt,i=this.He.length;this.Qe(i),(!this.Ze||this.Ze.length<i*M.FLOATS_PER_INSTANCE)&&(this.Ze=new Float32Array(i*M.FLOATS_PER_INSTANCE));const r=M.Ve(this.He);t.bindBuffer(t.ARRAY_BUFFER,this.je),i<=this.Ye?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Xe=!1,this.Ye=i}es(t){let i=this.qe.get(t);if(!i){i=new Map;const r=this.xt;for(const n in G.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.qe.set(t,i)}return i}ye(t){if(!this.je||this.He.length===0)return;const i=this.xt,r=t.te;this.ts();const n=this.es(r);i.bindBuffer(i.ARRAY_BUFFER,this.je);for(const[o,a]of n){const h=G.ATTRIBUTES[o];h&&(i.enableVertexAttribArray(a),i.vertexAttribPointer(a,h.size,h.type,h.normalized,h.stride,h.offset),i.vertexAttribDivisor(a,h.divisor))}}be(t){const i=this.xt,r=this.es(t.te);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}Ce(t,i){this.He.length!==0&&this.xt.drawArraysInstanced(t,0,i,this.He.length)}Ut(){const t=this.xt;this.je&&(t.deleteBuffer(this.je),this.je=null),this.He.length=0,this.qe.clear(),this.Ze=null}}class U{constructor(t,i,r,n){l(this,"xt");l(this,"ss");l(this,"rs");l(this,"ns");l(this,"hs",null);this.xt=t,this.ss=i,this.rs=r,this.ns=n;const o=this.xt.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.xt.bindBuffer(this.xt.ARRAY_BUFFER,o),this.xt.bufferData(this.xt.ARRAY_BUFFER,this.ns.cs,this.xt.STATIC_DRAW),this.xt.bindBuffer(this.xt.ARRAY_BUFFER,null),this.hs=o}get type(){return this.rs}get unitGeometry(){return this.ns}get unitBuffer(){return this.hs}get batch(){return this.ss}xe(){this.ss.clear()}ve(){return!this.ss.isEmpty}Ut(){this.ss.Ut(),this.hs&&(this.xt.deleteBuffer(this.hs),this.hs=null)}ls(t,i,r,n,o){const a=this.us(t,i,r,n,o.rotationX||0,o.rotationY||0,o.rotationZ||0);return{position:[t,i],size:[r,n],tt:o.character||[0,0,0],primaryColor:o.charColor||[1,1,1,1],secondaryColor:o.bgColor||[0,0,0,1],rotation:o.charRotation||[0,0],transform:[o.invert?1:0,o.flipHorizontally?1:0,o.flipVertically?1:0],globalRotationX:a.radiansX,globalRotationY:a.radiansY,globalRotationZ:a.radiansZ,rotationCenter:[a.centerX,a.centerY]}}fs(t,i){const r=z(this.xt)||[0,0,this.xt.canvas.width,this.xt.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}ds(t,i,r){const n=this.fs(i,r);t.rotationCenter=[n.nx,n.ny]}us(t,i,r,n,o,a,h){const u=z(this.xt)||[0,0,this.xt.canvas.width,this.xt.canvas.height],f=u[2],p=u[3];return{centerX:(t+r/2)/f*2-1,centerY:1-(i+n/2)/p*2,radiansX:-o*Math.PI/180,radiansY:-a*Math.PI/180,radiansZ:-h*Math.PI/180,aspectRatio:f/p}}}const lt={cs: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]),we:6,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class ut extends U{constructor(t,i){super(t,i,y.RECTANGLE,lt)}Me(t,i){const r=this.ls(t.x,t.y,t.width,t.height,i);return this.ss.Me(r)}}const ft={cs: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]),we:6,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class dt extends U{constructor(t,i){super(t,i,y.LINE,ft)}Me(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),a=Math.atan2(n,r),h=t.thickness||i.lineWeight||1,u=t.x1+r/2,f=t.y1+n/2,p=u-o/2,d=f,g={character:i.character,charColor:i.charColor,bgColor:i.bgColor,charRotation:i.charRotation,flipHorizontally:i.flipHorizontally,flipVertically:i.flipVertically,invert:i.invert,rotationX:i.rotationX||0,rotationY:i.rotationY||0,rotationZ:(i.rotationZ||0)+180*a/Math.PI,lineWeight:h},m=this.ls(p,d,o,h,g);return this.ds(m,u,f),this.ss.Me(m)}}const pt={cs:function(c=32){const t=[],i=2*Math.PI/c;for(let r=0;r<c;r++){const n=r*i,o=(r+1)%c*i,a=Math.cos(n),h=Math.sin(n),u=.5*(a+1),f=.5*(h+1),p=Math.cos(o),d=Math.sin(o),g=.5*(p+1),m=.5*(d+1);t.push(0,0,.5,.5,a,h,u,f,p,d,g,m)}return new Float32Array(t)}(32),we:96,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class gt extends U{constructor(t,i){super(t,i,y.ELLIPSE,pt)}Me(t,i){const r=this.ls(t.x,t.y,t.width,t.height,i);return this.ds(r,t.x,t.y),this.ss.Me(r)}}let mt={cs:function(c){const t=[];for(let i=0;i<c;i++){const r=i/c,n=(i+1)/c;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),we:96,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class xt extends U{constructor(t,i){super(t,i,y.ARC,mt)}Me(t,i){const r=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,a=t.stop*Math.PI/180,h=this.ls(r,n,t.width,t.height,i);return this.ds(h,t.x,t.y),h.arcAngles=[o,a],this.ss.Me(h)}}const yt={cs:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),we:3,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class Et extends U{constructor(t,i){super(t,i,y.TRIANGLE,yt)}Me(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),a=n-r,h=Math.max(t.y1,t.y2,t.y3)-o,u=this.ls(r,o,a,h,i),f=r+.5*a,p=o+h*(1/3);return this.ds(u,f,p),this.ss.Me(u)}}function Z(c,t,i,r,n){const o=1-c,a=o*o,h=c*c;return a*o*t+3*a*c*i+3*o*h*r+h*c*n}const vt={cs:function(c=16){const t=[];for(let i=0;i<c;i++){const r=i/c,n=(i+1)/c;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),we:96,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class Rt extends U{constructor(t,i){super(t,i,y.BEZIER_CURVE,vt)}Me(t,i){const r=i.lineWeight||1,n=Z(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=Z(.5,t.y1,t.cp1y,t.cp2y,t.y2),a={character:i.character,charColor:i.charColor,bgColor:i.bgColor,charRotation:i.charRotation,flipHorizontally:i.flipHorizontally,flipVertically:i.flipVertically,invert:i.invert,rotationX:i.rotationX||0,rotationY:i.rotationY||0,rotationZ:i.rotationZ||0,lineWeight:r},h=this.ls(0,0,1,r,a);return this.ds(h,n,o),h.bezierStartPoint=[t.x1,t.y1],h.bezierControlPoint1=[t.cp1x,t.cp1y],h.bezierControlPoint2=[t.cp2x,t.cp2y],h.bezierEndPoint=[t.x2,t.y2],this.ss.Me(h)}}class bt{constructor(t){l(this,"xt");l(this,"_s",null);l(this,"ps");l(this,"gs",null);l(this,"vs",{});l(this,"Cs",null);l(this,"$s",new Map);l(this,"ws");l(this,"bs");l(this,"Rs");l(this,"K",[]);this.xt=t,this.ps=new nt(t),this.Rs=new j,this.ws=new at(t,this),this.bs=new ht,this.Cs=t.createBuffer(),N(this.xt,[0,0,this.xt.canvas.width,this.xt.canvas.height])}Ms(t){let i=this.$s.get(t);if(i)return i;const r=new ct(this.xt);return i=(0,{[y.RECTANGLE]:()=>new ut(this.xt,r),[y.LINE]:()=>new dt(this.xt,r),[y.ELLIPSE]:()=>new gt(this.xt,r),[y.ARC]:()=>new xt(this.xt,r),[y.TRIANGLE]:()=>new Et(this.xt,r),[y.BEZIER_CURVE]:()=>new Rt(this.xt,r)}[t])(),this.$s.set(t,i),i}Ss(t){this._s!==t&&(this._s=t,t.Xt())}Fs(t,i){return this.ps.oe(t,i)}ie(){return this.ps.ie()}Bt(){return this.ps.Bt()}re(){return this.ps.re()}zs(t){this.gs=t,t&&(this.vs={})}Zt(t,i){this.vs[t]=i}Ps(t){Object.assign(this.vs,t)}ne(t){return this.ps.ne(t)}Ts(t,i,r,n,o){const a=this.ie(),h={l:t.textures[0],m:t.textures[1],n:t.textures[2],o:t.textures[3],p:t.textures[4],q:[t.width,t.height]};this.bs.Le(i,r,n,o,a,h,this.Rs)}ks(t,i,r,n){var E;const o=this.xt,a=o.canvas.width,h=o.canvas.height,u=t/a*2-1,f=(t+r)/a*2-1,p=1-i/h*2,d=1-(i+n)/h*2,g=new Float32Array([u,d,f,d,u,p,f,d,f,p,u,p]);o.bindBuffer(o.ARRAY_BUFFER,this.Cs),o.bufferData(o.ARRAY_BUFFER,g,o.DYNAMIC_DRAW);const m=((E=this._s)==null?void 0:E.te)||o.getParameter(o.CURRENT_PROGRAM),x=m?o.getAttribLocation(m,"a_position"):-1;x!==-1&&(o.enableVertexAttribArray(x),o.vertexAttribPointer(x,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),x!==-1&&o.disableVertexAttribArray(x)}Gs(t,i,r,n){this.gs?(this.bs.Le(t,i,r,n,this.gs,{...this.vs},this.Rs),this.gs=null,this.vs={}):this.bs.Ae(t,i,r,n,this.Rs)}As(t,i,r,n){this.bs.Ee(t,i,r,n,this.Rs.lineWeight,this.Rs)}Ls(t,i,r,n){this.bs.Be(t,i,r,n,this.Rs)}Es(t,i,r,n,o,a){this.bs.We(t,i,r,n,o,a,this.Rs)}Bs(t,i,r,n,o,a,h,u){const f=this.Rs.lineWeight;this.bs.Ie(t,i,r,n,o,a,h,u,f,this.Rs)}Ds(t,i,r=1,n={}){return new O(this.xt,t,i,r,n,this,!0)}Ws(t,i,r,n,o,a){this.bs.De(t,i,r,n,o,a,this.Rs)}Is(t,i=t,r=t,n=255){this.state.Ct(t,i,r,n),this.Ue(t/255,i/255,r/255,n/255)}Ue(t=0,i=0,r=0,n=0){this.xt.clearColor(t,i,r,n),this.xt.clear(this.xt.COLOR_BUFFER_BIT)}Us(){this.xt.viewport(0,0,this.xt.canvas.width,this.xt.canvas.height),N(this.xt,[0,0,this.xt.canvas.width,this.xt.canvas.height])}get context(){return this.xt}get state(){return this.Rs}Wt(t){this.K.push(this.Rs),this.Rs=t}It(){const t=this.K.pop();t&&(this.Rs=t)}Dt(t){const i=t,r=z(this.xt)??this.xt.getParameter(this.xt.VIEWPORT),n={shader:i,gl:this.xt,viewport:r};this.Ss(i);const o=new Set;for(const a of this.bs)a.type===y.CUSTOM?o.add(y.RECTANGLE):o.add(a.type);for(const a of o)a!==y.CUSTOM&&this.Ms(a);this.ws.me(n,this.bs,this.$s),this.bs.Ue()}Ut(){this.xt.deleteBuffer(this.Cs),this.bs.Ue();for(const t of this.$s.values())t.Ut();this.ps.Ut()}}const w={readShort:(c,t)=>(w.t.uint16[0]=c[t]<<8|c[t+1],w.t.int16[0]),readUshort:(c,t)=>c[t]<<8|c[t+1],readUshorts(c,t,i){const r=[];for(let n=0;n<i;n++)r.push(w.readUshort(c,t+2*n));return r},readUint(c,t){const i=w.t.uint8;return i[3]=c[t],i[2]=c[t+1],i[1]=c[t+2],i[0]=c[t+3],w.t.uint32[0]},readASCII(c,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(c[t+n]);return r},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()},wt={parseTab(c,t,i){const r={tables:[],ids:{},off:t};c=new Uint8Array(c.buffer,t,i),t=0;const n=w,o=n.readUshort,a=o(c,t+=2);t+=2;const h=[];for(let u=0;u<a;u++){const f=o(c,t),p=o(c,t+=2);t+=2;const d=n.readUint(c,t);t+=4;const g=`p${f}e${p}`;let m=h.indexOf(d);if(m===-1){let x;m=r.tables.length,h.push(d);const E=o(c,d);x=E===4?this.parse4(c,d):E===12?this.parse12(c,d):{format:E},r.tables.push(x)}r.ids[g]=m}return r},parse4(c,t){const i=w,r=i.readUshort,n=i.readUshorts,o=t,a=r(c,t+=2);t+=2;const h=r(c,t+=2)>>>1,u={format:4,searchRange:r(c,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,u.entrySelector=r(c,t),t+=2,u.rangeShift=r(c,t),t+=2,u.endCount=n(c,t,h),t+=2*h,t+=2,u.startCount=n(c,t,h),t+=2*h;for(let f=0;f<h;f++)u.idDelta.push(i.readShort(c,t)),t+=2;return u.idRangeOffset=n(c,t,h),t+=2*h,u.glyphIdArray=n(c,t,o+a-t>>1),u},parse12(c,t){const i=w.readUint;i(c,t+=4),i(c,t+=4);const r=i(c,t+=4);t+=4;const n=new Uint32Array(3*r);for(let o=0;o<3*r;o+=3)n[o]=i(c,t+(o<<2)),n[o+1]=i(c,t+(o<<2)+4),n[o+2]=i(c,t+(o<<2)+8);return{format:12,groups:n}}},Ct={parseTab(c,t,i){const r=w;t+=18;const n=r.readUshort(c,t);t+=2,t+=16;const o=r.readShort(c,t);t+=2;const a=r.readShort(c,t);t+=2;const h=r.readShort(c,t);t+=2;const u=r.readShort(c,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:a,xMax:h,yMax:u,indexToLocFormat:r.readShort(c,t)}}},At={parseTab(c,t,i){const r=w;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let a=0;a<n.length;a++){const h=n[a],u=h==="advanceWidthMax"||h==="numberOfHMetrics"?r.readUshort:r.readShort;o[h]=u(c,t+2*a)}return o}},Tt={parseTab(c,t,i,r){const n=w,o=[],a=[],h=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,p=0,d=0;for(;d<u;)f=n.readUshort(c,t+(d<<2)),p=n.readShort(c,t+(d<<2)+2),o.push(f),a.push(p),d++;for(;d<h;)o.push(f),a.push(p),d++;return{aWidth:o,lsBearing:a}}},q={cmap:wt,head:Ct,hhea:At,maxp:{parseTab(c,t,i){const r=w;return r.readUint(c,t),t+=4,{numGlyphs:r.readUshort(c,t)}}},hmtx:Tt,loca:{parseTab(c,t,i,r){const n=w,o=[],a=r.head.indexToLocFormat,h=r.maxp.numGlyphs+1;if(a===0)for(let u=0;u<h;u++)o.push(n.readUshort(c,t+(u<<1))<<1);else if(a===1)for(let u=0;u<h;u++)o.push(n.readUint(c,t+(u<<2)));return o}},glyf:{parseTab(c,t,i,r){const n=[],o=r.maxp.numGlyphs;for(let a=0;a<o;a++)n.push(null);return n},Os(c,t){const i=w,r=c.Vs,n=c.loca;if(n[t]===n[t+1])return null;const o=_.findTable(r,"glyf",c.Hs);if(!o)return null;let a=o[0]+n[t];const h={};if(h.noc=i.readShort(r,a),a+=2,h.xMin=i.readShort(r,a),a+=2,h.yMin=i.readShort(r,a),a+=2,h.xMax=i.readShort(r,a),a+=2,h.yMax=i.readShort(r,a),a+=2,h.xMin>=h.xMax||h.yMin>=h.yMax)return null;if(h.noc>0){h.endPts=[];for(let g=0;g<h.noc;g++)h.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=h.endPts[h.noc-1]+1;h.flags=[];for(let g=0;g<f;g++){const m=r[a];if(a++,h.flags.push(m),8&m){const x=r[a];a++;for(let E=0;E<x;E++)h.flags.push(m),g++}}h.xs=[];for(let g=0;g<f;g++){const m=h.flags[g],x=!!(16&m);2&m?(h.xs.push(x?r[a]:-r[a]),a++):x?h.xs.push(0):(h.xs.push(i.readShort(r,a)),a+=2)}h.ys=[];for(let g=0;g<f;g++){const m=h.flags[g],x=!!(32&m);4&m?(h.ys.push(x?r[a]:-r[a]),a++):x?h.ys.push(0):(h.ys.push(i.readShort(r,a)),a+=2)}let p=0,d=0;for(let g=0;g<f;g++)p+=h.xs[g],d+=h.ys[g],h.xs[g]=p,h.ys[g]=d}else h.parts=[],h.endPts=[],h.flags=[],h.xs=[],h.ys=[];return h}}},_={parse:c=>[((t,i,r,n)=>{const o=q,a={Vs:t,Ks:i,Hs:r};for(const h in o){const u=h,f=_.findTable(t,u,r);if(f){const[p,d]=f;let g=n[p];g==null&&(g=o[u].parseTab(t,p,d,a),n[p]=g),a[u]=g}}return a})(new Uint8Array(c),0,0,{})],findTable(c,t,i){const r=w,n=r.readUshort(c,i+4);let o=i+12;for(let a=0;a<n;a++){const h=r.readASCII(c,o,4);r.readUint(c,o+4);const u=r.readUint(c,o+8),f=r.readUint(c,o+12);if(h===t)return[u,f];o+=16}return null},T:q,B:w};class W{constructor(){l(this,"Ns",new Map);l(this,"js",new Map)}Xs(t,i){const r=`${this.Ys(t)}_${i}`;if(this.Ns.has(r))return this.Ns.get(r);const n=t.cmap;if(!n||!n.tables)return this.Ns.set(r,0),0;let o=0;for(const a of n.tables)if(a.format===4?o=this.qs(i,a):a.format===12&&(o=this.Zs(i,a)),o>0)break;return this.Ns.set(r,o),o}Js(t,i){const r=i.codePointAt(0);return r===void 0?0:this.Xs(t,r)}Qs(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}ti(t,i){const r=i/t.head.unitsPerEm,n=t.hhea.ascender*r,o=t.hhea.descender*r,a=t.hhea.lineGap*r;return{ascender:n,descender:o,lineGap:a,lineHeight:n-o+a,unitsPerEm:t.head.unitsPerEm,scale:r}}ei(){this.Ns.clear(),this.js.clear()}Ys(t){return`${t.Hs}_${t.Vs.length}`}qs(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 a=i.glyphIdArray[o];return a===0?0:a+i.idDelta[n]&65535}}return 0}Zs(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const o=i.groups[3*n],a=i.groups[3*n+1],h=i.groups[3*n+2];if(t>=o&&t<=a)return h+(t-o)}return 0}}class _t{constructor(t){l(this,"si");this.si=t}ii(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ri(n);i.push(...o)}else if(n.format===12){const o=this.ni(n);i.push(...o)}}),[...new Set(i)]):[]}oi(t,i){return this.si.Js(t,i)>0}ai(t,i){for(const r of i)if(!this.oi(t,r))return!1;return!0}hi(t,i){return i.filter(r=>this.oi(t,r))}ci(t){return t.filter(i=>this.li(i))}ri(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 a=n;a<=o;a++)if(this.ui(t,a,r)>0)try{const h=String.fromCodePoint(a);i.push(h)}catch{}}}return i}ni(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],a=t.groups[r+2];for(let h=n;h<=o;h++)if(a+(h-n)>0)try{const u=String.fromCodePoint(h);i.push(u)}catch{}}return i}ui(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}li(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class Pt{constructor(){l(this,"fi");const t=new W;this.fi=new _t(t)}extractCharacters(t){return this.fi.ii(t)}filterProblematicCharacters(t){return this.fi.ci(t)}characterExists(t,i){return this.fi.oi(t,i)}allCharactersExist(t,i){return this.fi.ai(t,i)}}class Ft{constructor(t){l(this,"di");l(this,"_i");l(this,"Pt");l(this,"pi");this.Pt=t,this.pi=new W,this.di=document.createElement("canvas"),this._i=this.di.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(t,i,r,n){const o=t.length,a=Math.ceil(Math.sqrt(o)),h=Math.ceil(o/a),u=i.width*a,f=i.height*h,p=typeof n=="object"?n:null;this.gi(u,f),this.mi(t,i,a,r,p);const d=this.Pt.Ds(u,f,1,{filter:"nearest"});return d.Lt(this.di),{framebuffer:d,columns:a,rows:h}}gi(t,i){this.di.width=t,this.di.height=i,this.di.style.width=t+"px",this.di.style.height=t+"px",this._i.imageSmoothingEnabled=!1,this.di.style.imageRendering="pixelated",this._i.fillStyle="black",this._i.fillRect(0,0,t,i),this._i.textBaseline="top",this._i.textAlign="left",this._i.fillStyle="white"}mi(t,i,r,n,o){const a=n/o.head.unitsPerEm;for(let h=0;h<t.length;h++){const u=h%r,f=Math.floor(h/r),p=t[h].character,d=this.yi(o,p);if(!d)continue;const g=p.codePointAt(0)||0,m=this.pi.Xs(o,g),x=this.Ci(o,m)*a,E=u*i.width,A=f*i.height,C=E+.5*i.width,T=A+.5*i.height,P=Math.round(C-.5*i.width),I=Math.round(T-.5*n),re=P+.5*(i.width-x),ne=I+o.hhea.ascender*a;this.$i(d,re,ne,a)}}yi(t,i){const r=i.codePointAt(0)||0,n=this.pi.Xs(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(_&&_.T&&_.T.glyf){const o=_.T.glyf.Os(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}Ci(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}$i(t,i,r,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:a,endPts:h,flags:u}=t;if(!(o&&a&&h&&u))return;this._i.beginPath();let f=0;for(let p=0;p<h.length;p++){const d=h[p];if(!(d<f)){if(d>=f){const g=i+o[f]*n,m=r-a[f]*n;this._i.moveTo(g,m);let x=f+1;for(;x<=d;)if(1&u[x]){const E=i+o[x]*n,A=r-a[x]*n;this._i.lineTo(E,A),x++}else{const E=i+o[x]*n,A=r-a[x]*n;let C=x+1>d?f:x+1;if(1&u[C]){const T=i+o[C]*n,P=r-a[C]*n;this._i.quadraticCurveTo(E,A,T,P),x=C+1}else{const T=(E+(i+o[C]*n))/2,P=(A+(r-a[C]*n))/2;this._i.quadraticCurveTo(E,A,T,P),x=C}}this._i.closePath()}f=d+1}}this._i.fill()}}class St{constructor(){l(this,"si");this.si=new W}calculateMaxGlyphDimensions(t,i,r){let n=0;const o=this.si.ti(r,i),a=o.lineHeight;for(const h of t){const u=this.si.Js(r,h);if(u===0)continue;const f=this.si.Qs(r,u)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}getCharacterAdvanceWidth(t,i,r){const n=this.si.ti(r,i),o=this.si.Js(r,t);return this.si.Qs(r,o)*n.scale}getFontMetrics(t,i){return this.si.ti(i,t)}ei(){this.si.ei()}}class Mt{constructor(){l(this,"pi");this.pi=new W}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,a=this.wi(n);let h=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.pi.Xs(i,o);u>0&&i.hmtx.aWidth[u]!==void 0&&(h=i.hmtx.aWidth[u])}return{character:r,unicode:o,color:a,advanceWidth:h}})}wi(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}bi(t,i){if(!B.M(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]}xi(t,i){return B.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.bi(r,i)||[0,0,0]):[[0,0,0]]}}class J{constructor(t,i=16){l(this,"Ri");l(this,"Mi",[]);l(this,"Si");l(this,"Fi",16);l(this,"zi",0);l(this,"Pi",0);l(this,"Ti",{width:0,height:0});l(this,"ki");l(this,"Gi");l(this,"Ai");l(this,"Li");l(this,"Ei");this.Fi=i,this.Gi=new Pt,this.Ai=new Ft(t),this.Li=new St,this.Ei=new Mt}async Bi(t){let i;if(!t)throw new v("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const r=await fetch(t);if(!r.ok)throw new v(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}await this.Di(i),this.Ri=_.parse(i)[0],await this.Wi()}Ii(t){if(t===void 0)return this.Fi;this.Fi=t,this.Ti=this.Li.calculateMaxGlyphDimensions(this.Mi.map(r=>r.character),this.Fi,this.Ri);const i=this.Ai.createTextureAtlas(this.Mi,this.Ti,this.Fi,this.Ri);this.Si=i.framebuffer,this.zi=i.columns,this.Pi=i.rows}async Ui(t){try{const i=await fetch(t);if(!i.ok)throw new v(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.Di(r);const n=_.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.Ri=n[0],await this.Wi()}catch(i){throw new v("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async Di(t){const i=Date.now();this.ki=new FontFace("CustomFont_"+i,t),await this.ki.load(),document.fonts.add(this.ki)}async Wi(){const t=this.Gi.extractCharacters(this.Ri),i=this.Gi.filterProblematicCharacters(t);this.Mi=this.Ei.createCharacterObjects(i,this.Ri),this.Ti=this.Li.calculateMaxGlyphDimensions(i,this.Fi,this.Ri);const r=this.Ai.createTextureAtlas(this.Mi,this.Ti,this.Fi,this.Ri);this.Si=r.framebuffer,this.zi=r.columns,this.Pi=r.rows}bi(t){return this.Ei.bi(t,this.Mi)}xi(t){return this.Ei.xi(t,this.Mi)}Ut(){this.Si.Ut(),document.fonts.delete(this.ki)}get fontFramebuffer(){return this.Si}get characters(){return this.Mi}get textureColumns(){return this.zi}get textureRows(){return this.Pi}get maxGlyphDimensions(){return this.Ti}get fontSize(){return this.Fi}get font(){return this.Ri}}class Q{constructor(t,i,r){l(this,"Oi");l(this,"Vi");l(this,"$t");l(this,"wt");l(this,"Hi");l(this,"Ki");l(this,"Ni");l(this,"ji");l(this,"Xi");this.Ni=t,this.ji=i,this.Xi=r,this.rt()}rt(){this.Oi=Math.floor(this.Ni.width/this.ji),this.Vi=Math.floor(this.Ni.height/this.Xi),this.$t=this.Oi*this.ji,this.wt=this.Vi*this.Xi,this.Hi=Math.floor((this.Ni.width-this.$t)/2),this.Ki=Math.floor((this.Ni.height-this.wt)/2)}Yi(t,i){this.ji=t,this.Xi=i,this.rt()}get cellWidth(){return this.ji}get cellHeight(){return this.Xi}get cols(){return this.Oi}get rows(){return this.Vi}get width(){return this.$t}get height(){return this.wt}get offsetX(){return this.Hi}get offsetY(){return this.Ki}}class tt{constructor(t={}){l(this,"Ni");l(this,"qi");l(this,"Zi");t.canvas?(this.Ni=t.canvas,this.Zi=!1):(this.Ni=this.Ji(t.width,t.height),this.Zi=!0),this.Ni.style.imageRendering="pixelated"}Ji(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}Qi(t,i){this.Ni.width=t??this.Ni.width,this.Ni.height=i??this.Ni.height}tr(){const t=this.Ni.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new v("`textmode.js` requires WebGL2 support.");return t}Ut(){this.qi&&this.qi.disconnect();const t=this.Ni.getContext("webgl")||this.Ni.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.Zi&&this.Ni.parentNode&&this.Ni.parentNode.removeChild(this.Ni)}get canvas(){return this.Ni}get width(){return this.Ni.width}get height(){return this.Ni.height}}class Lt{constructor(t=60){l(this,"er");l(this,"sr");l(this,"ir",null);l(this,"rr",0);l(this,"nr",!0);l(this,"ar",0);l(this,"hr",0);l(this,"cr",[]);l(this,"lr",10);l(this,"ur",0);this.er=t,this.sr=1e3/t}start(t){if(!this.nr)return;this.rr=performance.now();const i=r=>{if(!this.nr)return void(this.ir=null);const n=r-this.rr;n>=this.sr&&(t(),this.rr=r-n%this.sr),this.nr&&(this.ir=requestAnimationFrame(i))};this.ir=requestAnimationFrame(i)}stop(){this.ir&&(cancelAnimationFrame(this.ir),this.ir=null)}pause(){this.nr&&(this.nr=!1,this.stop())}resume(t){this.nr||(this.nr=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.ar;this.er=t,this.sr=1e3/t,this.nr&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.hr>0){const i=t-this.hr;this.cr.push(i),this.cr.length>this.lr&&this.cr.shift();const r=this.cr.reduce((n,o)=>n+o,0)/this.cr.length;this.ar=1e3/r}this.hr=t}get isLooping(){return this.nr}get frameRateLimit(){return this.er}get currentFrameRate(){return this.ar}get frameCount(){return this.ur}set frameCount(t){this.ur=t}incrementFrame(){this.ur++}resetFrameCount(){this.ur=0}}class Ut{constructor(){l(this,"dr",new Map);l(this,"_r",null);l(this,"pr",null);l(this,"gr");l(this,"mr");l(this,"vr",!1);l(this,"yr");l(this,"Cr");l(this,"$r",{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"})}wr(){this.vr||(this.gr=t=>{this.br(t)},this.mr=t=>{this.Rr(t)},window.addEventListener("keydown",this.gr,{passive:!1}),window.addEventListener("keyup",this.mr,{passive:!1}),this.vr=!0)}Mr(){this.vr&&(window.removeEventListener("keydown",this.gr),window.removeEventListener("keyup",this.mr),this.vr=!1,this.dr.clear(),this._r=null,this.pr=null)}Sr(t){this.yr=t}Fr(t){this.Cr=t}zr(t){const i=this.Pr(t),r=this.dr.get(t)||this.dr.get(i);return(r==null?void 0:r.isPressed)||!1}Tr(){return this._r}kr(){return this.pr}Gr(){const t=[];for(const[i,r]of this.dr)r.isPressed&&t.push(i);return t}Ar(){return{ctrl:this.zr("Control"),shift:this.zr("Shift"),alt:this.zr("Alt"),meta:this.zr("Meta")}}Lr(){this.dr.clear(),this._r=null,this.pr=null}br(t){const i=t.key,r=Date.now();this.dr.has(i)||this.dr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.dr.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this._r=i,this.yr)){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.yr(o)}}Rr(t){const i=t.key,r=Date.now();this.dr.has(i)||this.dr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.dr.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.pr=i,this.Cr){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.Cr(o)}}Pr(t){return this.$r[t]||t.toLowerCase()}}class Bt{constructor(t){l(this,"Ni");l(this,"Er");l(this,"Br",{x:-1,y:-1});l(this,"Dr",{x:-1,y:-1});l(this,"Wr",null);l(this,"Ir");l(this,"Ur");l(this,"Or");l(this,"Vr");l(this,"Hr");l(this,"Kr");l(this,"vr",!1);l(this,"Nr");l(this,"jr");l(this,"Xr");l(this,"Yr");l(this,"qr");this.Ni=t}Bi(t){this.Er=t,this.Zr()}wr(){if(this.vr)return;const t=this.Ni.canvas;this.Ir=i=>{this.Jr(i),this.Qr(i)},this.Ur=()=>{this.Dr={...this.Br},this.Br.x=-1,this.Br.y=-1,this.Wr=null},this.Or=i=>{this.Jr(i),this.tn(i)},this.Vr=i=>{this.Jr(i),this.en(i)},this.Hr=i=>{this.Jr(i),this.sn(i)},this.Kr=i=>{this.Jr(i),this.rn(i)},t.addEventListener("mousemove",this.Ir,{passive:!0}),t.addEventListener("mouseleave",this.Ur,{passive:!0}),t.addEventListener("mousedown",this.Or,{passive:!0}),t.addEventListener("mouseup",this.Vr,{passive:!0}),t.addEventListener("click",this.Hr,{passive:!0}),t.addEventListener("wheel",this.Kr,{passive:!1}),this.vr=!0}Mr(){if(!this.vr)return;const t=this.Ni.canvas;t.removeEventListener("mousemove",this.Ir),t.removeEventListener("mouseleave",this.Ur),t.removeEventListener("mousedown",this.Or),t.removeEventListener("mouseup",this.Vr),t.removeEventListener("click",this.Hr),t.removeEventListener("wheel",this.Kr),this.vr=!1}Zr(){if(this.vr)try{if(this.Wr){const t=new MouseEvent("mousemove",{clientX:this.Wr.x,clientY:this.Wr.y,bubbles:!1,cancelable:!1});this.Jr(t)}else this.Br.x!==-1&&this.Br.y!==-1&&(this.Br.x>=this.Er.cols||this.Br.y>=this.Er.rows)&&(this.Br.x=-1,this.Br.y=-1)}catch{this.Br.x=-1,this.Br.y=-1}}nn(t){this.Nr=t}Sr(t){this.jr=t}Fr(t){this.Xr=t}an(t){this.Yr=t}hn(t){this.qr=t}cn(){return{x:this.Br.x,y:this.Br.y}}Qr(t){if(this.Yr){const i={position:{...this.Br},previousPosition:{...this.Dr},originalEvent:t};this.Yr(i)}}tn(t){if(this.jr){const i={position:{...this.Br},previousPosition:{...this.Dr},button:t.button,originalEvent:t};this.jr(i)}}en(t){if(this.Xr){const i={position:{...this.Br},previousPosition:{...this.Dr},button:t.button,originalEvent:t};this.Xr(i)}}sn(t){if(this.Nr){const i={position:{...this.Br},previousPosition:{...this.Dr},button:t.button,originalEvent:t};this.Nr(i)}}rn(t){if(this.qr){const i={position:{...this.Br},previousPosition:{...this.Dr},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.qr(i)}}Jr(t){const i=this.Ni.canvas;this.Dr={...this.Br},this.Wr={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,o=t.clientY-r.top,a=i.width/r.width,h=o*(i.height/r.height),u=n*a-this.Er.offsetX,f=h-this.Er.offsetY,p=Math.floor(u/this.Er.cellWidth),d=Math.floor(f/this.Er.cellHeight);p>=0&&p<this.Er.cols&&d>=0&&d<this.Er.rows?(this.Br.x=p,this.Br.y=d):(this.Br.x=-1,this.Br.y=-1)}}const Dt=c=>class extends c{rotate(t=0,i=0,r=0){this.Pt.state.ht(t),this.Pt.state.ct(i),this.Pt.state.lt(r)}rotateX(t){this.Pt.state.ht(t)}rotateY(t){this.Pt.state.ct(t)}rotateZ(t){this.Pt.state.lt(t)}push(){this.Pt.state.N()}pop(){this.Pt.state.it()}rect(t,i,r=1,n=1){this.Pt.Gs(t,i,r,n)}point(t,i){this.Pt.Gs(t,i,1,1)}line(t,i,r,n){this.Pt.As(t,i,r,n)}lineWeight(t){this.Pt.state.ot(t)}background(t,i=t,r=t,n=255){this.Pt.Is(t,i,r,n)}char(t){this.Pt.state.ut(this.Ri.bi(t))}charColor(t,i,r){this.Pt.state.ft(t,i,r)}cellColor(t,i,r){this.Pt.state.dt(t,i,r)}flipX(t){this.Pt.state._t(t)}flipY(t){this.Pt.state.gt(t)}charRotation(t){this.Pt.state.yt(t)}invert(t){this.Pt.state.vt(t)}clear(){this.Pt.Is(0,0,0,0)}ellipse(t,i,r,n){this.Pt.Ls(t,i,r/2,n/2)}triangle(t,i,r,n,o,a){this.Pt.Es(t,i,r,n,o,a)}bezierCurve(t,i,r,n,o,a,h,u){this.Pt.Bs(t,i,r,n,o,a,h,u)}arc(t,i,r,n,o,a){this.Pt.Ws(t,i,r,n,o,a)}shader(t){this.Pt.zs(t)}setUniform(t,i){this.Pt.Zt(t,i)}setUniforms(t){this.Pt.Ps(t)}createFilterShader(t){return this.Pt.ne(t)}createFramebuffer(t){return this.Pt.Ds(t.width,t.height,5,{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"})}image(t,i,r,n,o){this.Pt.Ts(t,i,r,n??t.width,o??t.height)}};class Y{ln(t){const i=t.Et(0),r=t.Et(1),n=t.Et(2),o=t.Et(3);return{characterPixels:i,primaryColorPixels:r,secondaryColorPixels:n,transformPixels:t.Et(4),rotationPixels:o}}un(t,i){return t[i]+(t[i+1]<<8)}fn(t,i){return{r:t[i],g:t[i+1],b:t[i+2],a:t[i+3]}}}class V{dn(t,i){return new Blob([t],{type:i})}_n(t,i,r){try{const n=this.dn(t,r),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=i,a.style.display="none",a.rel="noopener",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(o)}catch(n){throw console.error("Failed to download file:",n),Error("File download failed: "+(n instanceof Error?n.message:"Unknown error"))}}pn(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}gn(){const t=new Date;return{date:t.toISOString().split("T")[0],time:t.toTimeString().split(" ")[0].replace(/:/g,"-")}}mn(t){return t.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}vn(){return"textmode-export-"+this.pn()}}class It extends Y{yn(t,i,r){const n=t[r]===255,o=t[r+1]===255,a=t[r+2]===255,h=i[r],u=i[r+1];return{isInverted:n,flipHorizontal:o,flipVertical:a,rotation:Math.round(360*(h+u/255)/255*100)/100}}Cn(t,i,r){return{x:t,y:i,cellX:t*r.cellWidth,cellY:i*r.cellHeight}}$n(t,i){const r=[];let n=0;for(let o=0;o<i.rows;o++)for(let a=0;a<i.cols;a++){const h=4*n,u=this.un(t.characterPixels,h);let f=this.fn(t.primaryColorPixels,h),p=this.fn(t.secondaryColorPixels,h);const d=this.yn(t.transformPixels,t.rotationPixels,h);if(d.isInverted){const m=f;f=p,p=m}const g=this.Cn(a,o,i);r.push({charIndex:u,primaryColor:f,secondaryColor:p,transform:d,position:g}),n++}return r}}class Nt{wn(t,i){const r=t.cmap;for(const n of r.tables)if(n.format===4){const o=n;for(let a=0;a<o.startCount.length;a++)if(i>=o.startCount[a]&&i<=o.endCount[a]){if(o.idRangeOffset[a]===0)return i+o.idDelta[a]&65535;{const h=o.idRangeOffset[a]/2+(i-o.startCount[a])-(o.startCount.length-a);if(h>=0&&h<o.glyphIdArray.length){const u=o.glyphIdArray[h];if(u!==0)return u+o.idDelta[a]&65535}}}}else if(n.format===12){const o=n;for(let a=0;a<o.groups.length;a+=3){const h=o.groups[a],u=o.groups[a+1],f=o.groups[a+2];if(i>=h&&i<=u)return f+(i-h)}}return 0}bn(t,i,r,n,o){const a=o/t.head.unitsPerEm;return{getBoundingBox:()=>({x1:r+i.xMin*a,y1:n+-i.yMax*a,x2:r+i.xMax*a,y2:n+-i.yMin*a}),toSVG:()=>this.xn(i,r,n,a)}}xn(t,i,r,n){if(!t||!t.xs)return"";const{xs:o,ys:a,endPts:h,flags:u}=t;if(!(o&&a&&h&&u))return"";let f="",p=0;for(let d=0;d<h.length;d++){const g=h[d];if(!(g<p)){if(g>=p){const m=i+o[p]*n,x=r-a[p]*n;f+=`M${m.toFixed(2)},${x.toFixed(2)}`;let E=p+1;for(;E<=g;)if(1&u[E]){const A=i+o[E]*n,C=r-a[E]*n;f+=`L${A.toFixed(2)},${C.toFixed(2)}`,E++}else{const A=i+o[E]*n,C=r-a[E]*n;let T=E+1>g?p:E+1;if(1&u[T]){const P=i+o[T]*n,I=r-a[T]*n;f+=`Q${A.toFixed(2)},${C.toFixed(2)} ${P.toFixed(2)},${I.toFixed(2)}`,E=T+1}else{const P=(A+(i+o[T]*n))/2,I=(C+(r-a[T]*n))/2;f+=`Q${A.toFixed(2)},${C.toFixed(2)} ${P.toFixed(2)},${I.toFixed(2)}`,E=T}}f+="Z"}p=g+1}}return f}Rn(t,i,r,n,o){const a=t.codePointAt(0)||0,h=this.wn(i,a);let u=null;return i.glyf&&i.glyf[h]!==null?u=i.glyf[h]:(u=_.T.glyf.Os(i,h),i.glyf[h]=u),this.bn(i,u,r,n,o)}Mn(t,i,r,n,o,a,h,u){const f=r+(o-u*(h/i.head.unitsPerEm))/2,p=n+(a+.7*h)/2;return this.Rn(t,i,f,p,h).toSVG()||null}}class zt{constructor(){l(this,"Sn");this.Sn=new Nt}Fn(t){const{width:i,height:r}=t;return`<?xml version="1.0" encoding="UTF-8"?><svg width="${i}" height="${r}" viewBox="0 0 ${i} ${r}" xmlns="http://www.w3.org/2000/svg"><title>textmode.js sketch</title>`}zn(){return"</g></svg>"}Pn(t,i){if(!i.includeBackgroundRectangles)return"";const[r,n,o,a]=i.backgroundColor;return`<rect width="${t.width}" height="${t.height}" fill="rgba(${r},${n},${o},${a/255})"/>`}Tn(t,i){const{transform:r,position:n}=t;if(!r.flipHorizontal&&!r.flipVertical&&!r.rotation)return"";const o=n.cellX+i.cellWidth/2,a=n.cellY+i.cellHeight/2,h=[];if(r.flipHorizontal||r.flipVertical){const u=r.flipHorizontal?-1:1,f=r.flipVertical?-1:1;h.push(`translate(${o} ${a})scale(${u} ${f})translate(${-o} ${-a})`)}return r.rotation&&h.push(`rotate(${r.rotation} ${o} ${a})`),` transform="${h.join(" ")}"`}kn(t,i,r){if(!r.includeBackgroundRectangles||t.secondaryColor.a===0)return"";const{position:n}=t,{r:o,g:a,b:h,a:u}=t.secondaryColor,f=`rgba(${o},${a},${h},${u/255})`;return r.drawMode==="stroke"?`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" stroke="${f}" fill="none" stroke-width="${r.strokeWidth}"/>`:`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" fill="${f}"/>`}Rn(t,i,r,n){const o=r.characters[t.charIndex];if(!o)return"";const a=this.Sn.Mn(o.character,r.font,t.position.cellX,t.position.cellY,i.cellWidth,i.cellHeight,r.fontSize,o.advanceWidth);if(!a)return"";const{r:h,g:u,b:f,a:p}=t.primaryColor,d=`rgba(${h},${u},${f},${p/255})`;return n.drawMode==="stroke"?`<path d="${a}" stroke="${d}" stroke-width="${n.strokeWidth}" fill="none"/>`:`<path d="${a}" fill="${d}"/>`}Gn(t,i,r,n){const o=[],a=this.kn(t,i,n);a&&o.push(a);const h=this.Rn(t,i,r,n);if(h){const u=this.Tn(t,i);o.push(u?`<g${u}>${h}</g>`:h)}return o.join("")}An(t,i,r,n){const o=[this.Fn(i),this.Pn(i,n),'<g id="ascii-cells">'];for(const a of t)o.push(this.Gn(a,i,r,n));return o.push(this.zn()),o.join("")}Ln(t){return t.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\s+/g," ").replace(/> </g,"><")}}class Ot extends V{En(t){return this.dn(t,"image/svg+xml;charset=utf-8")}Bn(t,i){this._n(t,this.mn(i)+".svg","image/svg+xml;charset=utf-8")}Dn(t,i){this.Bn(t,i||this.vn())}}class et{constructor(){l(this,"Wn");l(this,"In");l(this,"Un");this.Wn=new It,this.In=new zt,this.Un=new Ot}On(t){return{includeBackgroundRectangles:t.includeBackgroundRectangles??!0,drawMode:t.drawMode??"fill",strokeWidth:t.strokeWidth??1,backgroundColor:t.backgroundColor??[0,0,0,0],filename:t.filename||this.Un.vn()}}Vn(t,i={}){const r=this.Wn.$n(this.Wn.ln(t.pipeline),t.grid),n=this.In.An(r,t.grid,t.font,this.On(i));return this.In.Ln(n)}Dn(t,i={}){this.Un.Dn(this.Vn(t,i),i.filename)}}class Gt extends Y{Hn(t,i,r,n=" "){var h;const o=[];let a=0;for(let u=0;u<i.rows;u++){const f=[];for(let p=0;p<i.cols;p++){const d=4*a,g=this.un(t.characterPixels,d),m=((h=r.characters[g])==null?void 0:h.character)||n;f.push(m),a++}o.push(f)}return o}}class Wt{Kn(t,i){const r=[];for(const o of t){let a=o.join("");i.preserveTrailingSpaces||(a=a.replace(/\s+$/,"")),r.push(a)}const n=i.lineEnding==="crlf"?`\r
|
|
7
|
+
`}static _(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=>E._(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>E._(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}: ${E._(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${E._(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var L=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(L||{});const M=class M{constructor(){u(this,"$",{globalLevel:3})}static C(){return M.v||(M.v=new M),M.v}R(t,i){const r="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",n="color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";switch(this.$.globalLevel){case 0:return!1;case 1:return console.group(r,n),console.warn(E.u(t,i)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(E.u(t,i)),console.groupEnd(),!1;default:throw new E(t,i)}}M(t,i,r){return!!t||(this.R(i,r),!1)}S(t){this.$.globalLevel=t}};u(M,"v",null);let Y=M;const I=Y.C(),X=new WeakMap;function W(c,t){X.set(c,t)}function D(c){return X.get(c)}class j{constructor(){u(this,"F",1);u(this,"P",0);u(this,"A",0);u(this,"G",0);u(this,"L",[0,0,0]);u(this,"D",[1,1,1,1]);u(this,"W",[0,0,0,1]);u(this,"I",!1);u(this,"U",!1);u(this,"V",!1);u(this,"O",[0,0]);u(this,"H",[0,0,0,1]);u(this,"K",[])}N(){this.K.push({X:this.F,Y:this.P,Z:this.A,J:this.G,O:[...this.O],I:this.I,U:this.U,V:this.V,tt:[...this.L],et:[...this.D],st:[...this.W]})}it(){const t=this.K.pop();t?(this.F=t.X,this.P=t.Y,this.A=t.Z,this.G=t.J,this.O=t.O,this.I=t.I,this.U=t.U,this.V=t.V,this.L=t.tt,this.D=t.et,this.W=t.st):console.warn("pop() called without matching push()")}rt(){this.K=[],this.P=0,this.A=0,this.G=0}nt(t){t.lineWeight=this.F,t.rotationX=this.P,t.rotationY=this.A,t.rotationZ=this.G,t.character[0]=this.L[0],t.character[1]=this.L[1],t.character[2]=this.L[2],t.charColor[0]=this.D[0],t.charColor[1]=this.D[1],t.charColor[2]=this.D[2],t.charColor[3]=this.D[3],t.bgColor[0]=this.W[0],t.bgColor[1]=this.W[1],t.bgColor[2]=this.W[2],t.bgColor[3]=this.W[3],t.flipHorizontally=this.I,t.flipVertically=this.U,t.invert=this.V,t.charRotation[0]=this.O[0],t.charRotation[1]=this.O[1]}get lineWeight(){return this.F}get canvasBackgroundColor(){return this.H}ot(t){this.F=Math.abs(t)}ht(t){this.P=t}ct(t){this.A=t}lt(t){this.G=t}ut(t){this.L=t}ft(t,i,r,n=255){this.D=[t/255,i/255,r/255,n/255]}dt(t,i,r,n=255){this.W=[t/255,i/255,r/255,n/255]}_t(t){this.I=t}gt(t){this.U=t}vt(t){this.V=t}yt(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));this.O=[r,n]}$t(t,i,r,n){this.H=[t/255,i/255,r/255,n/255]}}class B{constructor(t,i,r=i,n=1,o={},a=null,h=!1){u(this,"Ct");u(this,"wt");u(this,"$");u(this,"bt",null);u(this,"xt");u(this,"Rt");u(this,"Mt",[]);u(this,"St");u(this,"Ft",null);u(this,"zt",[]);u(this,"kt",null);u(this,"Tt",!1);u(this,"Pt",null);this.Ct=i,this.wt=r,this.$={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.xt=t,this.St=Math.min(Math.max(1,n),8),this.kt=a,this.Tt=!!h,this.Pt=this.Tt?new j:null;const l=t.getParameter(t.MAX_DRAW_BUFFERS),f=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.St=Math.min(this.St,l,f),this.Rt=t.createFramebuffer(),this.At(),this.Gt(),this.zt=Array(this.St).fill(null)}At(){const t=this.xt,i=this.$.filter==="linear"?t.LINEAR:t.NEAREST,r=this.$.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE,n=this.$.type==="float"?t.FLOAT:t.UNSIGNED_BYTE;for(let o=0;o<this.St;o++){const a=t.createTexture();t.bindTexture(t.TEXTURE_2D,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,r),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.Ct,this.wt,0,t.RGBA,n,null),this.Mt.push(a)}t.bindTexture(t.TEXTURE_2D,null)}Gt(){const t=this.xt;if(t.bindFramebuffer(t.FRAMEBUFFER,this.Rt),this.St===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.Mt[0],0);else{const r=[];for(let n=0;n<this.St;n++){const o=t.COLOR_ATTACHMENT0+n;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,this.Mt[n],0),r.push(o)}t.drawBuffers(r)}const i=t.checkFramebufferStatus(t.FRAMEBUFFER);i!==t.FRAMEBUFFER_COMPLETE&&console.error("GLFramebuffer is not complete:",i),t.bindFramebuffer(t.FRAMEBUFFER,null)}Lt(t){const i=this.xt;i.bindTexture(i.TEXTURE_2D,this.Mt[0]),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,1),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.bindTexture(i.TEXTURE_2D,null)}resize(t,i){this.Ct=t,this.wt=i,this.bt=null,this.zt=Array(this.St).fill(null);const r=this.xt,n=this.$.type==="float"?r.FLOAT:r.UNSIGNED_BYTE;for(const o of this.Mt)r.bindTexture(r.TEXTURE_2D,o),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.Ct,this.wt,0,r.RGBA,n,null);r.bindTexture(r.TEXTURE_2D,null)}Et(t){const i=this.xt,r=this.zt[t];if(r)return r;const n=this.Ct,o=this.wt,a=new Uint8Array(n*o*4),h=i.getParameter(i.READ_FRAMEBUFFER_BINDING);i.bindFramebuffer(i.READ_FRAMEBUFFER,this.Rt),i.readBuffer(i.COLOR_ATTACHMENT0+t),i.readPixels(0,0,n,o,i.RGBA,i.UNSIGNED_BYTE,a),i.bindFramebuffer(i.READ_FRAMEBUFFER,h);const l=4*n,f=new Uint8Array(a.length);for(let d=0;d<o;d++){const p=(o-1-d)*l,g=d*l;f.set(a.subarray(p,p+l),g)}return this.zt[t]=f,f}begin(){var i,r,n,o;const t=this.xt;if(this.kt){const a=((r=(i=this.kt).Bt)==null?void 0:r.call(i))??null;a&&this.kt.Dt(a),this.Tt&&this.Pt&&((o=(n=this.kt).Wt)==null||o.call(n,this.Pt))}this.Ft={framebuffer:t.getParameter(t.FRAMEBUFFER_BINDING),viewport:t.getParameter(t.VIEWPORT)},t.bindFramebuffer(t.FRAMEBUFFER,this.Rt),this.zt=Array(this.St).fill(null);for(let a=0;a<this.St;a++)t.clearBufferfv(t.COLOR,a,new Float32Array([0,0,0,0]));t.viewport(0,0,this.Ct,this.wt),W(t,[0,0,this.Ct,this.wt])}end(){var i,r,n,o;if(!this.Ft)return;const t=this.xt;if(this.kt){const a=((r=(i=this.kt).Bt)==null?void 0:r.call(i))??null;a&&this.kt.Dt(a)}t.bindFramebuffer(t.FRAMEBUFFER,this.Ft.framebuffer),t.viewport(...this.Ft.viewport),W(t,this.Ft.viewport),this.Ft=null,this.kt&&this.Tt&&this.Pt&&((o=(n=this.kt).It)==null||o.call(n))}Ut(){const t=this.xt;t.deleteFramebuffer(this.Rt);for(const i of this.Mt)t.deleteTexture(i)}get width(){return this.Ct}get height(){return this.wt}get textures(){return[...this.Mt]}}function K(c){return typeof c=="string"?c:c.sourceCode}class k{constructor(t,i,r){u(this,"xt");u(this,"Vt");u(this,"Ot",new Map);u(this,"Ht",new Map);u(this,"Kt",0);this.xt=t,this.Vt=this.Nt(K(i),K(r)),this.jt()}jt(){const t=this.xt.getProgramParameter(this.Vt,this.xt.ACTIVE_UNIFORMS);for(let i=0;i<t;i++){const r=this.xt.getActiveUniform(this.Vt,i);if(r){const n=this.xt.getUniformLocation(this.Vt,r.name);if(n&&(this.Ot.set(r.name,n),this.Ht.set(r.name,{type:r.type,size:r.size}),r.size>1)){const o=r.name.replace(/\[.*\]$/,"");this.Ot.has(o)||(this.Ot.set(o,n),this.Ht.set(o,{type:r.type,size:r.size}))}}}}Nt(t,i){const r=this.Xt(this.xt.VERTEX_SHADER,t),n=this.Xt(this.xt.FRAGMENT_SHADER,i),o=this.xt.createProgram();if(this.xt.attachShader(o,r),this.xt.attachShader(o,n),this.xt.linkProgram(o),!this.xt.getProgramParameter(o,this.xt.LINK_STATUS)){const a=this.xt.getProgramInfoLog(o);throw Error("Shader program link error: "+a)}return this.xt.deleteShader(r),this.xt.deleteShader(n),o}Xt(t,i){const r=this.xt.createShader(t);if(this.xt.shaderSource(r,i),this.xt.compileShader(r),!this.xt.getShaderParameter(r,this.xt.COMPILE_STATUS)){const n=this.xt.getShaderInfoLog(r);throw this.xt.deleteShader(r),Error("Shader compilation error: "+n)}return r}Yt(){this.xt.useProgram(this.Vt),this.qt()}qt(){this.Kt=0}Zt(t){for(const[i,r]of Object.entries(t))this.Jt(i,r)}Qt(t){return this.Ot.has(t)}te(t){return this.Ht.get(t)||null}ee(){const t=[];for(const[i,r]of this.Ht.entries())t.push({name:i,...r});return t}Jt(t,i){var l;const r=this.Ot.get(t);if(!r)return;const n=this.Ht.get(t);if(!n)return void console.warn(`No type information found for uniform '${t}'`);const{type:o,size:a}=n,h=this.xt;if(typeof i=="number")switch(o){case h.INT:case h.BOOL:h.uniform1i(r,i);break;case h.FLOAT:h.uniform1f(r,i);break;default:console.warn(`Unexpected uniform type for scalar '${t}': ${o}`),h.uniform1f(r,i)}else if(typeof i=="boolean")h.uniform1i(r,i?1:0);else if(Array.isArray(i))if(Array.isArray(i[0])){const f=i,d=((l=f[0])==null?void 0:l.length)||0,p=f.flat();switch(o){case h.FLOAT_VEC2:d===2?h.uniform2fv(r,p):console.warn(`Vector length mismatch for '${t}': expected 2, got ${d}`);break;case h.FLOAT_VEC3:d===3?h.uniform3fv(r,p):console.warn(`Vector length mismatch for '${t}': expected 3, got ${d}`);break;case h.FLOAT_VEC4:d===4?h.uniform4fv(r,p):console.warn(`Vector length mismatch for '${t}': expected 4, got ${d}`);break;default:console.warn(`Unsupported uniform type for vector array '${t}': ${o}`)}}else switch(o){case h.FLOAT_VEC2:i.length===2?h.uniform2f(r,i[0],i[1]):console.warn(`Vector length mismatch for '${t}': expected 2, got ${i.length}`);break;case h.FLOAT_VEC3:i.length===3?h.uniform3f(r,i[0],i[1],i[2]):console.warn(`Vector length mismatch for '${t}': expected 3, got ${i.length}`);break;case h.FLOAT_VEC4:i.length===4?h.uniform4f(r,i[0],i[1],i[2],i[3]):console.warn(`Vector length mismatch for '${t}': expected 4, got ${i.length}`);break;case h.INT:a>1?h.uniform1iv(r,i):console.warn(`Array provided for scalar uniform '${t}'`);break;case h.FLOAT:a>1?h.uniform1fv(r,i):console.warn(`Array provided for scalar uniform '${t}'`);break;default:console.warn(`Unsupported uniform type for array '${t}': ${o}`)}else if(i instanceof WebGLTexture){const f=this.se();h.uniform1i(r,f),h.activeTexture(h.TEXTURE0+f),h.bindTexture(h.TEXTURE_2D,i)}else if(i instanceof B){const f=this.se();h.uniform1i(r,f),h.activeTexture(h.TEXTURE0+f),h.bindTexture(h.TEXTURE_2D,i.textures[0])}else console.warn(`Unsupported uniform type for '${t}':`,typeof i)}se(){return this.Kt++}get ie(){return this.Vt}Ut(){this.xt.deleteProgram(this.Vt)}}const N=`#version 300 es
|
|
8
|
+
in vec2 a_position;in vec2 a_texCoord;in vec2 a_instancePosition;in vec2 a_instanceSize;in vec3 a_instanceCharacter;in vec4 a_instancePrimaryColor;in vec4 a_instanceSecondaryColor;in vec2 a_instanceRotation;in vec3 a_instanceTransform;in vec3 a_instanceGlobalRotation;in vec2 a_instanceRotationCenter;in vec2 a_instanceBezierCP1;in vec2 a_instanceBezierCP2;in vec2 a_instanceBezierStart;in vec2 a_instanceBezierEnd;in vec2 a_instanceArcAngles;uniform float k;uniform vec2 t;out vec2 v_uv;out vec3 v_character;out vec4 v_primaryColor;out vec4 v_secondaryColor;out vec2 v_rotation;out vec3 v_transform;mat3 A(float B){float C=sin(B),D=cos(B);return mat3(1,0,0,0,D,-C,0,C,D);}mat3 E(float B){float C=sin(B),D=cos(B);return mat3(D,0,C,0,1,0,-C,0,D);}mat3 F(float B){float C=sin(B),D=cos(B);return mat3(D,-C,0,C,D,0,0,0,1);}vec2 G(float t,vec2 H,vec2 I,vec2 J,vec2 K){float L=1.-t,M=L*L,N=t*t;return M*L*H+3.*M*t*I+3.*L*N*J+N*t*K;}vec2 O(float t,vec2 H,vec2 I,vec2 J,vec2 K){float L=1.-t,M=L*L,N=t*t;return-3.*M*H+3.*M*I-6.*L*t*I+6.*L*t*J-3.*N*J+3.*N*K;}void main(){v_uv=a_texCoord;v_character=a_instanceCharacter;v_primaryColor=a_instancePrimaryColor;v_secondaryColor=a_instanceSecondaryColor;v_rotation=a_instanceRotation;v_transform=a_instanceTransform;vec2 P;bool Q=length(a_instanceBezierCP1)+length(a_instanceBezierCP2)+length(a_instanceBezierStart)+length(a_instanceBezierEnd)>0.;bool R=a_instanceArcAngles.x!=0.||a_instanceArcAngles.y!=0.;if(Q){float t=a_position.x;vec2 S=G(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 T=O(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float U=length(T);T=U>0.?T/U:vec2(1,0);P=S+vec2(-T.y,T.x)*a_position.y*a_instanceSize.y;}else if(R){float C=a_instanceArcAngles.x,V=a_instanceArcAngles.y;C=mod(C,6.28318530718);if(C<0.)C+=6.28318530718;V=mod(V,6.28318530718);if(V<0.)V+=6.28318530718;float W=C-V;if(W<=0.)W+=6.28318530718;float X=C-a_position.x*W;vec2 Y=vec2(cos(X),sin(X))*a_position.y;P=Y*a_instanceSize*.5+a_instanceSize*.5+a_instancePosition;}else{P=a_position*a_instanceSize+a_instancePosition;}vec2 Z=(P/t)*2.-1.;Z.y=-Z.y;if(length(a_instanceGlobalRotation)>0.){vec3 a=vec3(Z-a_instanceRotationCenter,0);a.x*=k;if(a_instanceGlobalRotation.x!=0.)a=A(-a_instanceGlobalRotation.x)*a;if(a_instanceGlobalRotation.y!=0.)a=E(-a_instanceGlobalRotation.y)*a;if(a_instanceGlobalRotation.z!=0.)a=F(-a_instanceGlobalRotation.z)*a;a.x/=k;Z=a.xy+a_instanceRotationCenter;}gl_Position=vec4(Z,0,1);}`;class nt{constructor(t){u(this,"re",new Map);u(this,"xt");this.xt=t}ne(t,i){if(!this.re.has(t)){const r=i();this.re.set(t,r)}return this.re.get(t)}oe(){return this.ne("mrt-copy",()=>new k(this.xt,N,`#version 300 es
|
|
9
|
+
precision highp float;in vec2 v_uv;uniform sampler2D l;uniform sampler2D m;uniform sampler2D n;uniform sampler2D o;uniform sampler2D p;uniform vec2 q;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*q;vec2 C=(floor(B)+0.5f)/q;vec4 D=texture(l,C);vec4 E=texture(m,C);if(E.a==0.){discard;}vec4 F=texture(n,C);vec4 G=texture(o,C);vec4 H=texture(p,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;o_rotation=G;o_transform=H;}`))}Bt(){return this.ne("mrt-draw",()=>new k(this.xt,N,`#version 300 es
|
|
10
|
+
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.);}`))}ae(){return this.ne("ascii-conversion",()=>new k(this.xt,"attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.,1.);}","precision mediump float;uniform sampler2D a;uniform vec2 b;uniform sampler2D d;uniform sampler2D e;uniform sampler2D f;uniform sampler2D c;uniform sampler2D g;uniform vec2 h;uniform vec2 i;uniform vec2 j;mat2 A(float B){float C=sin(B);float c=cos(B);return mat2(c,-C,C,c);}void main(){vec2 D=(gl_FragCoord.xy-j)/i;vec2 E=D*h;vec2 F=floor(E);vec2 G=(F+0.5)/h;vec4 H=texture2D(d,G);vec4 I=texture2D(e,G);vec4 J=texture2D(f,G);bool K=J.r>0.5;bool L=J.g>0.5;bool M=J.b>0.5;vec4 N=texture2D(c,G);int O=int(N.r*255.+0.5)+int(N.g*255.+0.5)*256;int P=int(mod(float(O),b.x));int Q=O/int(b.x);float R=(b.y-1.)-float(Q);vec2 S=vec2(float(P),R)/b;vec4 T=texture2D(g,G);float U=T.r*255.+T.g;float V=-(U*360./255.)*0.017453292;vec2 W=fract(E)-0.5;if(L)W.x=-W.x;if(M)W.y=-W.y;W=A(V)*W+0.5;vec2 X=1./b;vec2 Y=S+W*X;vec2 Z=S+X;if(any(lessThan(Y,S))||any(greaterThan(Y,Z))){gl_FragColor=K?H:I;return;}vec4 a=texture2D(a,Y);if(K)a.rgb=1.-a.rgb;gl_FragColor=mix(I,H,a);}"))}he(t){return new k(this.xt,N,t)}ce(t,i){return new k(this.xt,t,i)}Ut(){for(const t of this.re.values())t.Ut();this.re.clear()}}var y=(c=>(c.RECTANGLE="rectangle",c.LINE="line",c.ELLIPSE="ellipse",c.ARC="arc",c.TRIANGLE="triangle",c.BEZIER_CURVE="bezier_curve",c.CUSTOM="custom",c))(y||{});class ot{constructor(t){u(this,"xt");u(this,"le",new Map);this.xt=t}ue(t,i,r,n){const o=this.xt;let a=this.le.get(t);a||(a=new Map,this.le.set(t,a));let h=a.get(i)||null;if(!h){h=o.createVertexArray(),a.set(i,h),o.bindVertexArray(h),o.bindBuffer(o.ARRAY_BUFFER,n);const l=o.getAttribLocation(t,"a_position");l!==-1&&(o.enableVertexAttribArray(l),o.vertexAttribPointer(l,r.de.fe.size,o.FLOAT,!1,r._e,r.de.fe.offset),o.vertexAttribDivisor(l,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,r.de.pe.size,o.FLOAT,!1,r._e,r.de.pe.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(h)}ge(){this.xt.bindVertexArray(null)}Ut(){const t=this.xt;for(const[,i]of this.le)for(const[,r]of i)r&&t.deleteVertexArray(r);this.le.clear()}}class at{constructor(t,i){u(this,"me");u(this,"xt");u(this,"kt");u(this,"ve",null);u(this,"ye",null);this.xt=t,this.me=new ot(t),this.kt=i}$e(t,i,r){const{shader:n}=t,o=D(this.xt)||this.xt.getParameter(this.xt.VIEWPORT);n.Zt({k:o[2]/o[3],t:[o[2],o[3]]});const a=f=>{if(!f||!f.Ce())return;const d=f.unitGeometry,p=f.unitBuffer;try{this.me.ue(n.ie,f.type+"",d,p),f.batch.we(n),f.batch.be(d.xe,d.Re)}finally{f.batch.Me(n),this.me.ge(),f.Se()}};let h=null,l=null;for(const f of i){if(f.type===y.CUSTOM){l&&(a(l),h=null,l=null),this.Fe(t,f.params,f.state,r.get(y.RECTANGLE));continue}h!==null&&f.type!==h&&(a(l),h=null,l=null);let d=l;d&&f.type===h||(d=r.get(f.type)||null,l=d,h=f.type),d&&d.ze(f.params,f.state)}a(l)}Fe(t,i,r,n){const{x:o,y:a,width:h,height:l,shader:f,uniforms:d}=i;if(f===this.ke())return this.Te(n,f,d,Math.floor(o),Math.floor(a),Math.max(1,Math.floor(h)),Math.max(1,Math.floor(l)),r),void t.shader.Yt();const p=this.Pe(Math.max(1,Math.floor(h)),Math.max(1,Math.floor(l)));p.begin(),this.Te(n,f,d,0,0,p.width,p.height,{}),p.end();const g=this.ke(),m={l:p.textures[0],m:p.textures[1],n:p.textures[2],o:p.textures[3],p:p.textures[4],q:[p.width,p.height]};this.Te(n,g,m,Math.floor(o),Math.floor(a),Math.max(1,Math.floor(h)),Math.max(1,Math.floor(l)),r),t.shader.Yt()}Te(t,i,r,n,o,a,h,l){i.Yt(),i.Zt(r);const f=this.xt.getParameter(this.xt.VIEWPORT);if(i.Zt({k:f[2]/f[3],t:[f[2],f[3]]}),t.Se(),t.ze({x:n,y:o,width:a,height:h},l),t.Ce()){const d=t.unitGeometry,p=t.unitBuffer;try{this.me.ue(i.ie,t.type+"",d,p),t.batch.we(i),t.batch.be(d.xe,d.Re)}finally{t.batch.Me(i),this.me.ge(),t.Se()}}}ke(){return this.kt.oe()}Pe(t,i){return this.ve&&this.ye&&this.ye.w===t&&this.ye.h===i||(this.ve&&this.ve.Ut(),this.ve=new B(this.xt,t,i,5),this.ye={w:t,h:i}),this.ve}}class ht{constructor(){u(this,"Ae",[]);u(this,"Ge",1);u(this,"Le",0)}Ee(t){if(this.Le>=this.Ae.length){const r={id:this.Ge++,type:t,params:{},state:{X:1,Y:0,Z:0,J:0,character:[0,0,0],charColor:[1,1,1,1],bgColor:[0,0,0,1],flipHorizontally:!1,flipVertically:!1,invert:!1,charRotation:[0,0]}};this.Ae.push(r)}const i=this.Ae[this.Le];switch(i.id=this.Ge++,i.type=t,t){case y.RECTANGLE:case y.ELLIPSE:i.params&&"width"in i.params||(i.params={x:0,y:0,width:0,height:0});break;case y.CUSTOM:i.params&&"shader"in i.params||(i.params={x:0,y:0,width:0,height:0,shader:void 0,uniforms:{}});break;case y.ARC:i.params&&"start"in i.params||(i.params={x:0,y:0,width:0,height:0,start:0,stop:0});break;case y.LINE:i.params&&"x2"in i.params||(i.params={x1:0,y1:0,x2:0,y2:0,thickness:void 0});break;case y.TRIANGLE:i.params&&"x3"in i.params||(i.params={x1:0,y1:0,x2:0,y2:0,x3:0,y3:0});break;case y.BEZIER_CURVE:i.params&&"cp2y"in i.params||(i.params={x1:0,y1:0,cp1x:0,cp1y:0,cp2x:0,cp2y:0,x2:0,y2:0,thickness:void 0});break;default:i.params||(i.params={})}return this.Le++,i}Be(t,i,r,n,o){const a=this.Ee(y.RECTANGLE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.nt(a.state),a.id}De(t,i,r,n,o,a,h){const l=this.Ee(y.CUSTOM);return l.params.x=t,l.params.y=i,l.params.width=r,l.params.height=n,l.params.shader=o,l.params.uniforms=a,h.nt(l.state),l.id}We(t,i,r,n,o,a){const h=this.Ee(y.LINE);return h.params.x1=t,h.params.y1=i,h.params.x2=r,h.params.y2=n,h.params.thickness=o,a.nt(h.state),h.id}Ie(t,i,r,n,o){const a=this.Ee(y.ELLIPSE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.nt(a.state),a.id}Ue(t,i,r,n,o,a,h){const l=this.Ee(y.ARC);return l.params.x=t,l.params.y=i,l.params.width=r,l.params.height=n,l.params.start=o,l.params.stop=a,h.nt(l.state),l.id}Ve(t,i,r,n,o,a,h){const l=this.Ee(y.TRIANGLE);return l.params.x1=t,l.params.y1=i,l.params.x2=r,l.params.y2=n,l.params.x3=o,l.params.y3=a,h.nt(l.state),l.id}Oe(t,i,r,n,o,a,h,l,f,d){const p=this.Ee(y.BEZIER_CURVE);return p.params.x1=t,p.params.y1=i,p.params.cp1x=r,p.params.cp1y=n,p.params.cp2x=o,p.params.cp2y=a,p.params.x2=h,p.params.y2=l,p.params.thickness=f,d.nt(p.state),p.id}get length(){return this.Le}get isEmpty(){return this.Le===0}He(){this.Le=0}[Symbol.iterator](){let t=0;const i=this.Le,r=this.Ae;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const S=class S{static Ke(t,i,r=0){var a,h,l,f,d,p,g,m,x,v;const n=i||new Float32Array(S.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.position[0],n[o++]=t.position[1],n[o++]=t.size[0],n[o++]=t.size[1],n[o++]=t.tt[0],n[o++]=t.tt[1],n[o++]=t.tt[2],n[o++]=t.primaryColor[0],n[o++]=t.primaryColor[1],n[o++]=t.primaryColor[2],n[o++]=t.primaryColor[3],n[o++]=t.secondaryColor[0],n[o++]=t.secondaryColor[1],n[o++]=t.secondaryColor[2],n[o++]=t.secondaryColor[3],n[o++]=t.rotation[0],n[o++]=t.rotation[1],n[o++]=t.transform[0],n[o++]=t.transform[1],n[o++]=t.transform[2],n[o++]=t.globalRotationX,n[o++]=t.globalRotationY,n[o++]=t.globalRotationZ,n[o++]=t.rotationCenter[0],n[o++]=t.rotationCenter[1],n[o++]=((a=t.arcAngles)==null?void 0:a[0])||0,n[o++]=((h=t.arcAngles)==null?void 0:h[1])||0,n[o++]=((l=t.bezierControlPoint1)==null?void 0:l[0])||0,n[o++]=((f=t.bezierControlPoint1)==null?void 0:f[1])||0,n[o++]=((d=t.bezierControlPoint2)==null?void 0:d[0])||0,n[o++]=((p=t.bezierControlPoint2)==null?void 0:p[1])||0,n[o++]=((g=t.bezierStartPoint)==null?void 0:g[0])||0,n[o++]=((m=t.bezierStartPoint)==null?void 0:m[1])||0,n[o++]=((x=t.bezierEndPoint)==null?void 0:x[0])||0,n[o++]=((v=t.bezierEndPoint)==null?void 0:v[1])||0,n}static Ne(t){const i=t.length*S.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*S.FLOATS_PER_INSTANCE;S.Ke(t[n],r,o)}return r}};u(S,"BYTES_PER_INSTANCE",140),u(S,"FLOATS_PER_INSTANCE",35);let P=S;const w=class w{};u(w,"STRIDE",P.BYTES_PER_INSTANCE),u(w,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:w.STRIDE,offset:132,divisor:1}});let O=w;class ct{constructor(t,i=1e3,r=1.5){u(this,"xt");u(this,"je",[]);u(this,"Xe");u(this,"Ye");u(this,"qe",null);u(this,"Ze",!0);u(this,"Je",0);u(this,"Qe",new Map);u(this,"ts",null);this.xt=t,this.Xe=i,this.Ye=r,this.es()}ze(t){const i=this.je.length;return this.je.push(t),this.Ze=!0,i}get count(){return this.je.length}get isEmpty(){return this.je.length===0}clear(){this.je.length=0,this.Ze=!0}ss(t){if(t<=this.Xe)return;const i=Math.ceil(t*this.Ye);this.Xe=i,this.es()}es(){const t=this.xt;this.qe&&t.deleteBuffer(this.qe),this.qe=t.createBuffer();const i=this.Xe*P.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.qe),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Ze=!0,this.Je=0}rs(){if(!this.Ze||this.je.length===0)return;const t=this.xt,i=this.je.length;this.ss(i),(!this.ts||this.ts.length<i*P.FLOATS_PER_INSTANCE)&&(this.ts=new Float32Array(i*P.FLOATS_PER_INSTANCE));const r=P.Ne(this.je);t.bindBuffer(t.ARRAY_BUFFER,this.qe),i<=this.Je?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Ze=!1,this.Je=i}ns(t){let i=this.Qe.get(t);if(!i){i=new Map;const r=this.xt;for(const n in O.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.Qe.set(t,i)}return i}we(t){if(!this.qe||this.je.length===0)return;const i=this.xt,r=t.ie;this.rs();const n=this.ns(r);i.bindBuffer(i.ARRAY_BUFFER,this.qe);for(const[o,a]of n){const h=O.ATTRIBUTES[o];h&&(i.enableVertexAttribArray(a),i.vertexAttribPointer(a,h.size,h.type,h.normalized,h.stride,h.offset),i.vertexAttribDivisor(a,h.divisor))}}Me(t){const i=this.xt,r=this.ns(t.ie);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}be(t,i){this.je.length!==0&&this.xt.drawArraysInstanced(t,0,i,this.je.length)}Ut(){const t=this.xt;this.qe&&(t.deleteBuffer(this.qe),this.qe=null),this.je.length=0,this.Qe.clear(),this.ts=null}}class U{constructor(t,i,r,n){u(this,"xt");u(this,"hs");u(this,"cs");u(this,"ls");u(this,"us",null);this.xt=t,this.hs=i,this.cs=r,this.ls=n;const o=this.xt.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.xt.bindBuffer(this.xt.ARRAY_BUFFER,o),this.xt.bufferData(this.xt.ARRAY_BUFFER,this.ls.fs,this.xt.STATIC_DRAW),this.xt.bindBuffer(this.xt.ARRAY_BUFFER,null),this.us=o}get type(){return this.cs}get unitGeometry(){return this.ls}get unitBuffer(){return this.us}get batch(){return this.hs}Se(){this.hs.clear()}Ce(){return!this.hs.isEmpty}Ut(){this.hs.Ut(),this.us&&(this.xt.deleteBuffer(this.us),this.us=null)}ds(t,i,r,n,o){const a=this._s(t,i,r,n,o.rotationX||0,o.rotationY||0,o.rotationZ||0);return{position:[t,i],size:[r,n],tt:o.character||[0,0,0],primaryColor:o.charColor||[1,1,1,1],secondaryColor:o.bgColor||[0,0,0,1],rotation:o.charRotation||[0,0],transform:[o.invert?1:0,o.flipHorizontally?1:0,o.flipVertically?1:0],globalRotationX:a.radiansX,globalRotationY:a.radiansY,globalRotationZ:a.radiansZ,rotationCenter:[a.centerX,a.centerY]}}ps(t,i){const r=D(this.xt)||[0,0,this.xt.canvas.width,this.xt.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}gs(t,i,r){const n=this.ps(i,r);t.rotationCenter=[n.nx,n.ny]}_s(t,i,r,n,o,a,h){const l=D(this.xt)||[0,0,this.xt.canvas.width,this.xt.canvas.height],f=l[2],d=l[3];return{centerX:(t+r/2)/f*2-1,centerY:1-(i+n/2)/d*2,radiansX:-o*Math.PI/180,radiansY:-a*Math.PI/180,radiansZ:-h*Math.PI/180,aspectRatio:f/d}}}const lt={fs: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]),Re:6,xe:WebGL2RenderingContext.TRIANGLES,_e:16,de:{fe:{size:2,offset:0},pe:{size:2,offset:8}}};class ut extends U{constructor(t,i){super(t,i,y.RECTANGLE,lt)}ze(t,i){const r=this.ds(t.x,t.y,t.width,t.height,i);return this.hs.ze(r)}}const ft={fs: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]),Re:6,xe:WebGL2RenderingContext.TRIANGLES,_e:16,de:{fe:{size:2,offset:0},pe:{size:2,offset:8}}};class dt extends U{constructor(t,i){super(t,i,y.LINE,ft)}ze(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),a=Math.atan2(n,r),h=t.thickness||i.lineWeight||1,l=t.x1+r/2,f=t.y1+n/2,d=l-o/2,p=f,g={character:i.character,charColor:i.charColor,bgColor:i.bgColor,charRotation:i.charRotation,flipHorizontally:i.flipHorizontally,flipVertically:i.flipVertically,invert:i.invert,rotationX:i.rotationX||0,rotationY:i.rotationY||0,rotationZ:(i.rotationZ||0)+180*a/Math.PI,lineWeight:h},m=this.ds(d,p,o,h,g);return this.gs(m,l,f),this.hs.ze(m)}}const pt={fs:function(c=32){const t=[],i=2*Math.PI/c;for(let r=0;r<c;r++){const n=r*i,o=(r+1)%c*i,a=Math.cos(n),h=Math.sin(n),l=.5*(a+1),f=.5*(h+1),d=Math.cos(o),p=Math.sin(o),g=.5*(d+1),m=.5*(p+1);t.push(0,0,.5,.5,a,h,l,f,d,p,g,m)}return new Float32Array(t)}(32),Re:96,xe:WebGL2RenderingContext.TRIANGLES,_e:16,de:{fe:{size:2,offset:0},pe:{size:2,offset:8}}};class gt extends U{constructor(t,i){super(t,i,y.ELLIPSE,pt)}ze(t,i){const r=this.ds(t.x,t.y,t.width,t.height,i);return this.gs(r,t.x,t.y),this.hs.ze(r)}}let mt={fs:function(c){const t=[];for(let i=0;i<c;i++){const r=i/c,n=(i+1)/c;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),Re:96,xe:WebGL2RenderingContext.TRIANGLES,_e:16,de:{fe:{size:2,offset:0},pe:{size:2,offset:8}}};class xt extends U{constructor(t,i){super(t,i,y.ARC,mt)}ze(t,i){const r=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,a=t.stop*Math.PI/180,h=this.ds(r,n,t.width,t.height,i);return this.gs(h,t.x,t.y),h.arcAngles=[o,a],this.hs.ze(h)}}const yt={fs:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),Re:3,xe:WebGL2RenderingContext.TRIANGLES,_e:16,de:{fe:{size:2,offset:0},pe:{size:2,offset:8}}};class vt extends U{constructor(t,i){super(t,i,y.TRIANGLE,yt)}ze(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),a=n-r,h=Math.max(t.y1,t.y2,t.y3)-o,l=this.ds(r,o,a,h,i),f=r+.5*a,d=o+h*(1/3);return this.gs(l,f,d),this.hs.ze(l)}}function Z(c,t,i,r,n){const o=1-c,a=o*o,h=c*c;return a*o*t+3*a*c*i+3*o*h*r+h*c*n}const Et={fs:function(c=16){const t=[];for(let i=0;i<c;i++){const r=i/c,n=(i+1)/c;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),Re:96,xe:WebGL2RenderingContext.TRIANGLES,_e:16,de:{fe:{size:2,offset:0},pe:{size:2,offset:8}}};class Rt extends U{constructor(t,i){super(t,i,y.BEZIER_CURVE,Et)}ze(t,i){const r=i.lineWeight||1,n=Z(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=Z(.5,t.y1,t.cp1y,t.cp2y,t.y2),a={character:i.character,charColor:i.charColor,bgColor:i.bgColor,charRotation:i.charRotation,flipHorizontally:i.flipHorizontally,flipVertically:i.flipVertically,invert:i.invert,rotationX:i.rotationX||0,rotationY:i.rotationY||0,rotationZ:i.rotationZ||0,lineWeight:r},h=this.ds(0,0,1,r,a);return this.gs(h,n,o),h.bezierStartPoint=[t.x1,t.y1],h.bezierControlPoint1=[t.cp1x,t.cp1y],h.bezierControlPoint2=[t.cp2x,t.cp2y],h.bezierEndPoint=[t.x2,t.y2],this.hs.ze(h)}}class wt{constructor(t){u(this,"xt");u(this,"vs",null);u(this,"$s");u(this,"Cs",null);u(this,"ws",{});u(this,"bs",null);u(this,"Rs",new Map);u(this,"Ms");u(this,"Ss");u(this,"Fs");u(this,"K",[]);this.xt=t,this.$s=new nt(t),this.Fs=new j,this.Ms=new at(t,this),this.Ss=new ht,this.bs=t.createBuffer(),W(this.xt,[0,0,this.xt.canvas.width,this.xt.canvas.height])}zs(t){let i=this.Rs.get(t);if(i)return i;const r=new ct(this.xt);return i=(0,{[y.RECTANGLE]:()=>new ut(this.xt,r),[y.LINE]:()=>new dt(this.xt,r),[y.ELLIPSE]:()=>new gt(this.xt,r),[y.ARC]:()=>new xt(this.xt,r),[y.TRIANGLE]:()=>new vt(this.xt,r),[y.BEZIER_CURVE]:()=>new Rt(this.xt,r)}[t])(),this.Rs.set(t,i),i}ks(t){this.vs!==t&&(this.vs=t,t.Yt())}Ts(t,i){return this.$s.ce(t,i)}oe(){return this.$s.oe()}Bt(){return this.$s.Bt()}ae(){return this.$s.ae()}Ps(t){this.Cs=t,t&&(this.ws={})}Jt(t,i){this.ws[t]=i}As(t){Object.assign(this.ws,t)}he(t){return this.$s.he(t)}Gs(t,i,r,n,o){const a=this.oe(),h={l:t.textures[0],m:t.textures[1],n:t.textures[2],o:t.textures[3],p:t.textures[4],q:[t.width,t.height]};this.Ss.De(i,r,n,o,a,h,this.Fs)}Ls(t,i,r,n){var v;const o=this.xt,a=o.canvas.width,h=o.canvas.height,l=t/a*2-1,f=(t+r)/a*2-1,d=1-i/h*2,p=1-(i+n)/h*2,g=new Float32Array([l,p,f,p,l,d,f,p,f,d,l,d]);o.bindBuffer(o.ARRAY_BUFFER,this.bs),o.bufferData(o.ARRAY_BUFFER,g,o.DYNAMIC_DRAW);const m=((v=this.vs)==null?void 0:v.ie)||o.getParameter(o.CURRENT_PROGRAM),x=m?o.getAttribLocation(m,"a_position"):-1;x!==-1&&(o.enableVertexAttribArray(x),o.vertexAttribPointer(x,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),x!==-1&&o.disableVertexAttribArray(x)}Es(t,i,r,n){this.Cs?(this.Ss.De(t,i,r,n,this.Cs,{...this.ws},this.Fs),this.Cs=null,this.ws={}):this.Ss.Be(t,i,r,n,this.Fs)}Bs(t,i,r,n){this.Ss.We(t,i,r,n,this.Fs.lineWeight,this.Fs)}Ds(t,i,r,n){this.Ss.Ie(t,i,r,n,this.Fs)}Ws(t,i,r,n,o,a){this.Ss.Ve(t,i,r,n,o,a,this.Fs)}Is(t,i,r,n,o,a,h,l){const f=this.Fs.lineWeight;this.Ss.Oe(t,i,r,n,o,a,h,l,f,this.Fs)}Us(t,i,r=1,n={}){return new B(this.xt,t,i,r,n,this,!0)}Vs(t,i,r,n,o,a){this.Ss.Ue(t,i,r,n,o,a,this.Fs)}Os(t,i=t,r=t,n=255){this.state.$t(t,i,r,n),this.He(t/255,i/255,r/255,n/255)}He(t=0,i=0,r=0,n=0){this.xt.clearColor(t,i,r,n),this.xt.clear(this.xt.COLOR_BUFFER_BIT)}Hs(){this.xt.viewport(0,0,this.xt.canvas.width,this.xt.canvas.height),W(this.xt,[0,0,this.xt.canvas.width,this.xt.canvas.height])}get context(){return this.xt}get state(){return this.Fs}Wt(t){this.K.push(this.Fs),this.Fs=t}It(){const t=this.K.pop();t&&(this.Fs=t)}Dt(t){const i=t,r=D(this.xt)??this.xt.getParameter(this.xt.VIEWPORT),n={shader:i,gl:this.xt,viewport:r};this.ks(i);const o=new Set;for(const a of this.Ss)a.type===y.CUSTOM?o.add(y.RECTANGLE):o.add(a.type);for(const a of o)a!==y.CUSTOM&&this.zs(a);this.Ms.$e(n,this.Ss,this.Rs),this.Ss.He()}Ut(){this.xt.deleteBuffer(this.bs),this.Ss.He();for(const t of this.Rs.values())t.Ut();this.$s.Ut()}}const C={readShort:(c,t)=>(C.t.uint16[0]=c[t]<<8|c[t+1],C.t.int16[0]),readUshort:(c,t)=>c[t]<<8|c[t+1],readUshorts(c,t,i){const r=[];for(let n=0;n<i;n++)r.push(C.readUshort(c,t+2*n));return r},readUint(c,t){const i=C.t.uint8;return i[3]=c[t],i[2]=c[t+1],i[1]=c[t+2],i[0]=c[t+3],C.t.uint32[0]},readASCII(c,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(c[t+n]);return r},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()},Ct={parseTab(c,t,i){const r={tables:[],ids:{},off:t};c=new Uint8Array(c.buffer,t,i),t=0;const n=C,o=n.readUshort,a=o(c,t+=2);t+=2;const h=[];for(let l=0;l<a;l++){const f=o(c,t),d=o(c,t+=2);t+=2;const p=n.readUint(c,t);t+=4;const g=`p${f}e${d}`;let m=h.indexOf(p);if(m===-1){let x;m=r.tables.length,h.push(p);const v=o(c,p);x=v===4?this.parse4(c,p):v===12?this.parse12(c,p):{format:v},r.tables.push(x)}r.ids[g]=m}return r},parse4(c,t){const i=C,r=i.readUshort,n=i.readUshorts,o=t,a=r(c,t+=2);t+=2;const h=r(c,t+=2)>>>1,l={format:4,searchRange:r(c,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,l.entrySelector=r(c,t),t+=2,l.rangeShift=r(c,t),t+=2,l.endCount=n(c,t,h),t+=2*h,t+=2,l.startCount=n(c,t,h),t+=2*h;for(let f=0;f<h;f++)l.idDelta.push(i.readShort(c,t)),t+=2;return l.idRangeOffset=n(c,t,h),t+=2*h,l.glyphIdArray=n(c,t,o+a-t>>1),l},parse12(c,t){const i=C.readUint;i(c,t+=4),i(c,t+=4);const r=i(c,t+=4);t+=4;const n=new Uint32Array(3*r);for(let o=0;o<3*r;o+=3)n[o]=i(c,t+(o<<2)),n[o+1]=i(c,t+(o<<2)+4),n[o+2]=i(c,t+(o<<2)+8);return{format:12,groups:n}}},bt={parseTab(c,t,i){const r=C;t+=18;const n=r.readUshort(c,t);t+=2,t+=16;const o=r.readShort(c,t);t+=2;const a=r.readShort(c,t);t+=2;const h=r.readShort(c,t);t+=2;const l=r.readShort(c,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:a,xMax:h,yMax:l,indexToLocFormat:r.readShort(c,t)}}},At={parseTab(c,t,i){const r=C;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let a=0;a<n.length;a++){const h=n[a],l=h==="advanceWidthMax"||h==="numberOfHMetrics"?r.readUshort:r.readShort;o[h]=l(c,t+2*a)}return o}},Tt={parseTab(c,t,i,r){const n=C,o=[],a=[],h=r.maxp.numGlyphs,l=r.hhea.numberOfHMetrics;let f=0,d=0,p=0;for(;p<l;)f=n.readUshort(c,t+(p<<2)),d=n.readShort(c,t+(p<<2)+2),o.push(f),a.push(d),p++;for(;p<h;)o.push(f),a.push(d),p++;return{aWidth:o,lsBearing:a}}},q={cmap:Ct,head:bt,hhea:At,maxp:{parseTab(c,t,i){const r=C;return r.readUint(c,t),t+=4,{numGlyphs:r.readUshort(c,t)}}},hmtx:Tt,loca:{parseTab(c,t,i,r){const n=C,o=[],a=r.head.indexToLocFormat,h=r.maxp.numGlyphs+1;if(a===0)for(let l=0;l<h;l++)o.push(n.readUshort(c,t+(l<<1))<<1);else if(a===1)for(let l=0;l<h;l++)o.push(n.readUint(c,t+(l<<2)));return o}},glyf:{parseTab(c,t,i,r){const n=[],o=r.maxp.numGlyphs;for(let a=0;a<o;a++)n.push(null);return n},Ks(c,t){const i=C,r=c.Ns,n=c.loca;if(n[t]===n[t+1])return null;const o=F.findTable(r,"glyf",c.js);if(!o)return null;let a=o[0]+n[t];const h={};if(h.noc=i.readShort(r,a),a+=2,h.xMin=i.readShort(r,a),a+=2,h.yMin=i.readShort(r,a),a+=2,h.xMax=i.readShort(r,a),a+=2,h.yMax=i.readShort(r,a),a+=2,h.xMin>=h.xMax||h.yMin>=h.yMax)return null;if(h.noc>0){h.endPts=[];for(let g=0;g<h.noc;g++)h.endPts.push(i.readUshort(r,a)),a+=2;const l=i.readUshort(r,a);if(a+=2,r.length-a<l)return null;a+=l;const f=h.endPts[h.noc-1]+1;h.flags=[];for(let g=0;g<f;g++){const m=r[a];if(a++,h.flags.push(m),8&m){const x=r[a];a++;for(let v=0;v<x;v++)h.flags.push(m),g++}}h.xs=[];for(let g=0;g<f;g++){const m=h.flags[g],x=!!(16&m);2&m?(h.xs.push(x?r[a]:-r[a]),a++):x?h.xs.push(0):(h.xs.push(i.readShort(r,a)),a+=2)}h.ys=[];for(let g=0;g<f;g++){const m=h.flags[g],x=!!(32&m);4&m?(h.ys.push(x?r[a]:-r[a]),a++):x?h.ys.push(0):(h.ys.push(i.readShort(r,a)),a+=2)}let d=0,p=0;for(let g=0;g<f;g++)d+=h.xs[g],p+=h.ys[g],h.xs[g]=d,h.ys[g]=p}else h.parts=[],h.endPts=[],h.flags=[],h.xs=[],h.ys=[];return h}}},F={parse:c=>[((t,i,r,n)=>{const o=q,a={Ns:t,Xs:i,js:r};for(const h in o){const l=h,f=F.findTable(t,l,r);if(f){const[d,p]=f;let g=n[d];g==null&&(g=o[l].parseTab(t,d,p,a),n[d]=g),a[l]=g}}return a})(new Uint8Array(c),0,0,{})],findTable(c,t,i){const r=C,n=r.readUshort(c,i+4);let o=i+12;for(let a=0;a<n;a++){const h=r.readASCII(c,o,4);r.readUint(c,o+4);const l=r.readUint(c,o+8),f=r.readUint(c,o+12);if(h===t)return[l,f];o+=16}return null},T:q,B:C};class ${constructor(){u(this,"Ys",new Map);u(this,"qs",new Map)}Zs(t,i){const r=`${this.Js(t)}_${i}`;if(this.Ys.has(r))return this.Ys.get(r);const n=t.cmap;if(!n||!n.tables)return this.Ys.set(r,0),0;let o=0;for(const a of n.tables)if(a.format===4?o=this.Qs(i,a):a.format===12&&(o=this.ti(i,a)),o>0)break;return this.Ys.set(r,o),o}ei(t,i){const r=i.codePointAt(0);return r===void 0?0:this.Zs(t,r)}si(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}ii(t,i){const r=i/t.head.unitsPerEm,n=t.hhea.ascender*r,o=t.hhea.descender*r,a=t.hhea.lineGap*r;return{ascender:n,descender:o,lineGap:a,lineHeight:n-o+a,unitsPerEm:t.head.unitsPerEm,scale:r}}ri(){this.Ys.clear(),this.qs.clear()}Js(t){return`${t.js}_${t.Ns.length}`}Qs(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 a=i.glyphIdArray[o];return a===0?0:a+i.idDelta[n]&65535}}return 0}ti(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const o=i.groups[3*n],a=i.groups[3*n+1],h=i.groups[3*n+2];if(t>=o&&t<=a)return h+(t-o)}return 0}}class Ft{constructor(t){u(this,"ni");this.ni=t}oi(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ai(n);i.push(...o)}else if(n.format===12){const o=this.hi(n);i.push(...o)}}),[...new Set(i)]):[]}ci(t,i){return this.ni.ei(t,i)>0}li(t,i){for(const r of i)if(!this.ci(t,r))return!1;return!0}ui(t,i){return i.filter(r=>this.ci(t,r))}fi(t){return t.filter(i=>this.di(i))}ai(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 a=n;a<=o;a++)if(this._i(t,a,r)>0)try{const h=String.fromCodePoint(a);i.push(h)}catch{}}}return i}hi(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],a=t.groups[r+2];for(let h=n;h<=o;h++)if(a+(h-n)>0)try{const l=String.fromCodePoint(h);i.push(l)}catch{}}return i}_i(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}di(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class _t{constructor(){u(this,"pi");const t=new $;this.pi=new Ft(t)}extractCharacters(t){return this.pi.oi(t)}filterProblematicCharacters(t){return this.pi.fi(t)}characterExists(t,i){return this.pi.ci(t,i)}allCharactersExist(t,i){return this.pi.li(t,i)}}class St{constructor(t){u(this,"gi");u(this,"mi");u(this,"kt");u(this,"yi");this.kt=t,this.yi=new $,this.gi=document.createElement("canvas"),this.mi=this.gi.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(t,i,r,n){const o=t.length,a=Math.ceil(Math.sqrt(o)),h=Math.ceil(o/a),l=i.width*a,f=i.height*h,d=typeof n=="object"?n:null;this.$i(l,f),this.Ci(t,i,a,r,d);const p=this.kt.Us(l,f,1,{filter:"nearest"});return p.Lt(this.gi),{framebuffer:p,columns:a,rows:h}}$i(t,i){this.gi.width=t,this.gi.height=i,this.gi.style.width=t+"px",this.gi.style.height=t+"px",this.mi.imageSmoothingEnabled=!1,this.gi.style.imageRendering="pixelated",this.mi.fillStyle="black",this.mi.fillRect(0,0,t,i),this.mi.textBaseline="top",this.mi.textAlign="left",this.mi.fillStyle="white"}Ci(t,i,r,n,o){const a=n/o.head.unitsPerEm;for(let h=0;h<t.length;h++){const l=h%r,f=Math.floor(h/r),d=t[h].character,p=this.wi(o,d);if(!p)continue;const g=d.codePointAt(0)||0,m=this.yi.Zs(o,g),x=this.bi(o,m)*a,v=l*i.width,A=f*i.height,b=v+.5*i.width,T=A+.5*i.height,_=Math.round(b-.5*i.width),z=Math.round(T-.5*n),se=_+.5*(i.width-x),ne=z+o.hhea.ascender*a;this.xi(p,se,ne,a)}}wi(t,i){const r=i.codePointAt(0)||0,n=this.yi.Zs(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(F&&F.T&&F.T.glyf){const o=F.T.glyf.Ks(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}bi(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}xi(t,i,r,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:a,endPts:h,flags:l}=t;if(!(o&&a&&h&&l))return;this.mi.beginPath();let f=0;for(let d=0;d<h.length;d++){const p=h[d];if(!(p<f)){if(p>=f){const g=i+o[f]*n,m=r-a[f]*n;this.mi.moveTo(g,m);let x=f+1;for(;x<=p;)if(1&l[x]){const v=i+o[x]*n,A=r-a[x]*n;this.mi.lineTo(v,A),x++}else{const v=i+o[x]*n,A=r-a[x]*n;let b=x+1>p?f:x+1;if(1&l[b]){const T=i+o[b]*n,_=r-a[b]*n;this.mi.quadraticCurveTo(v,A,T,_),x=b+1}else{const T=(v+(i+o[b]*n))/2,_=(A+(r-a[b]*n))/2;this.mi.quadraticCurveTo(v,A,T,_),x=b}}this.mi.closePath()}f=p+1}}this.mi.fill()}}class Lt{constructor(){u(this,"ni");this.ni=new $}calculateMaxGlyphDimensions(t,i,r){let n=0;const o=this.ni.ii(r,i),a=o.lineHeight;for(const h of t){const l=this.ni.ei(r,h);if(l===0)continue;const f=this.ni.si(r,l)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}getCharacterAdvanceWidth(t,i,r){const n=this.ni.ii(r,i),o=this.ni.ei(r,t);return this.ni.si(r,o)*n.scale}getFontMetrics(t,i){return this.ni.ii(i,t)}ri(){this.ni.ri()}}class Pt{constructor(){u(this,"yi");this.yi=new $}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,a=this.Ri(n);let h=0;if(i.hmtx&&i.hmtx.aWidth){const l=this.yi.Zs(i,o);l>0&&i.hmtx.aWidth[l]!==void 0&&(h=i.hmtx.aWidth[l])}return{character:r,unicode:o,color:a,advanceWidth:h}})}Ri(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}Mi(t,i){if(!I.M(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 I.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.Mi(r,i)||[0,0,0]):[[0,0,0]]}}class J{constructor(t,i=16){u(this,"Fi");u(this,"zi",[]);u(this,"ki");u(this,"Ti",16);u(this,"Pi",0);u(this,"Ai",0);u(this,"Gi",{width:0,height:0});u(this,"Li");u(this,"Ei");u(this,"Bi");u(this,"Di");u(this,"Wi");this.Ti=i,this.Ei=new _t,this.Bi=new St(t),this.Di=new Lt,this.Wi=new Pt}async Ii(t){let i;if(!t)throw new E("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const r=await fetch(t);if(!r.ok)throw new E(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}await this.Ui(i),this.Fi=F.parse(i)[0],await this.Vi()}Oi(t){if(t===void 0)return this.Ti;this.Ti=t,this.Gi=this.Di.calculateMaxGlyphDimensions(this.zi.map(r=>r.character),this.Ti,this.Fi);const i=this.Bi.createTextureAtlas(this.zi,this.Gi,this.Ti,this.Fi);this.ki=i.framebuffer,this.Pi=i.columns,this.Ai=i.rows}async Hi(t){try{const i=await fetch(t);if(!i.ok)throw new E(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.Ui(r);const n=F.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.Fi=n[0],await this.Vi()}catch(i){throw new E("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async Ui(t){const i=Date.now();this.Li=new FontFace("CustomFont_"+i,t),await this.Li.load(),document.fonts.add(this.Li)}async Vi(){const t=this.Ei.extractCharacters(this.Fi),i=this.Ei.filterProblematicCharacters(t);this.zi=this.Wi.createCharacterObjects(i,this.Fi),this.Gi=this.Di.calculateMaxGlyphDimensions(i,this.Ti,this.Fi);const r=this.Bi.createTextureAtlas(this.zi,this.Gi,this.Ti,this.Fi);this.ki=r.framebuffer,this.Pi=r.columns,this.Ai=r.rows}Mi(t){return this.Wi.Mi(t,this.zi)}Si(t){return this.Wi.Si(t,this.zi)}Ut(){this.ki.Ut(),document.fonts.delete(this.Li)}get fontFramebuffer(){return this.ki}get characters(){return this.zi}get textureColumns(){return this.Pi}get textureRows(){return this.Ai}get maxGlyphDimensions(){return this.Gi}get fontSize(){return this.Ti}get font(){return this.Fi}}class Q{constructor(t,i,r){u(this,"Ki");u(this,"Ni");u(this,"Ct");u(this,"wt");u(this,"ji");u(this,"Xi");u(this,"Yi");u(this,"qi");u(this,"Zi");this.Yi=t,this.qi=i,this.Zi=r,this.rt()}rt(){this.Ki=Math.floor(this.Yi.width/this.qi),this.Ni=Math.floor(this.Yi.height/this.Zi),this.Ct=this.Ki*this.qi,this.wt=this.Ni*this.Zi,this.ji=Math.floor((this.Yi.width-this.Ct)/2),this.Xi=Math.floor((this.Yi.height-this.wt)/2)}Ji(t,i){this.qi=t,this.Zi=i,this.rt()}get cellWidth(){return this.qi}get cellHeight(){return this.Zi}get cols(){return this.Ki}get rows(){return this.Ni}get width(){return this.Ct}get height(){return this.wt}get offsetX(){return this.ji}get offsetY(){return this.Xi}}class tt{constructor(t={}){u(this,"Yi");u(this,"Qi");u(this,"tr");t.canvas?(this.Yi=t.canvas,this.tr=!1):(this.Yi=this.er(t.width,t.height),this.tr=!0),this.Yi.style.imageRendering="pixelated"}er(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}sr(t,i){this.Yi.width=t??this.Yi.width,this.Yi.height=i??this.Yi.height}ir(){const t=this.Yi.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new E("`textmode.js` requires WebGL2 support.");return t}Ut(){this.Qi&&this.Qi.disconnect();const t=this.Yi.getContext("webgl")||this.Yi.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.tr&&this.Yi.parentNode&&this.Yi.parentNode.removeChild(this.Yi)}get canvas(){return this.Yi}get width(){return this.Yi.width}get height(){return this.Yi.height}}class Mt{constructor(t=60){u(this,"rr");u(this,"nr");u(this,"ar",null);u(this,"hr",0);u(this,"cr",!0);u(this,"lr",0);u(this,"ur",0);u(this,"dr",[]);u(this,"_r",10);u(this,"pr",0);this.rr=t,this.nr=1e3/t}start(t){if(!this.cr)return;this.hr=performance.now();const i=r=>{if(!this.cr)return void(this.ar=null);const n=r-this.hr;n>=this.nr&&(t(),this.hr=r-n%this.nr),this.cr&&(this.ar=requestAnimationFrame(i))};this.ar=requestAnimationFrame(i)}stop(){this.ar&&(cancelAnimationFrame(this.ar),this.ar=null)}pause(){this.cr&&(this.cr=!1,this.stop())}resume(t){this.cr||(this.cr=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.lr;this.rr=t,this.nr=1e3/t,this.cr&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.ur>0){const i=t-this.ur;this.dr.push(i),this.dr.length>this._r&&this.dr.shift();const r=this.dr.reduce((n,o)=>n+o,0)/this.dr.length;this.lr=1e3/r}this.ur=t}get isLooping(){return this.cr}get frameRateLimit(){return this.rr}get currentFrameRate(){return this.lr}get frameCount(){return this.pr}set frameCount(t){this.pr=t}incrementFrame(){this.pr++}resetFrameCount(){this.pr=0}}class Ut{constructor(){u(this,"gr",new Map);u(this,"mr",null);u(this,"vr",null);u(this,"yr");u(this,"$r");u(this,"Cr",!1);u(this,"wr");u(this,"br");u(this,"Rr",{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"})}Mr(){this.Cr||(this.yr=t=>{this.Sr(t)},this.$r=t=>{this.Fr(t)},window.addEventListener("keydown",this.yr,{passive:!1}),window.addEventListener("keyup",this.$r,{passive:!1}),this.Cr=!0)}zr(){this.Cr&&(window.removeEventListener("keydown",this.yr),window.removeEventListener("keyup",this.$r),this.Cr=!1,this.gr.clear(),this.mr=null,this.vr=null)}kr(t){this.wr=t}Tr(t){this.br=t}Pr(t){const i=this.Ar(t),r=this.gr.get(t)||this.gr.get(i);return(r==null?void 0:r.isPressed)||!1}Gr(){return this.mr}Lr(){return this.vr}Er(){const t=[];for(const[i,r]of this.gr)r.isPressed&&t.push(i);return t}Br(){return{ctrl:this.Pr("Control"),shift:this.Pr("Shift"),alt:this.Pr("Alt"),meta:this.Pr("Meta")}}Dr(){this.gr.clear(),this.mr=null,this.vr=null}Sr(t){const i=t.key,r=Date.now();this.gr.has(i)||this.gr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.gr.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.mr=i,this.wr)){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.wr(o)}}Fr(t){const i=t.key,r=Date.now();this.gr.has(i)||this.gr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.gr.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.vr=i,this.br){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.br(o)}}Ar(t){return this.Rr[t]||t.toLowerCase()}}class It{constructor(t){u(this,"Yi");u(this,"Wr");u(this,"Ir",{x:-1,y:-1});u(this,"Ur",{x:-1,y:-1});u(this,"Vr",null);u(this,"Or");u(this,"Hr");u(this,"Kr");u(this,"Nr");u(this,"jr");u(this,"Xr");u(this,"Cr",!1);u(this,"Yr");u(this,"qr");u(this,"Zr");u(this,"Jr");u(this,"Qr");this.Yi=t}Ii(t){this.Wr=t,this.tn()}Mr(){if(this.Cr)return;const t=this.Yi.canvas;this.Or=i=>{this.en(i),this.sn(i)},this.Hr=()=>{this.Ur={...this.Ir},this.Ir.x=-1,this.Ir.y=-1,this.Vr=null},this.Kr=i=>{this.en(i),this.rn(i)},this.Nr=i=>{this.en(i),this.nn(i)},this.jr=i=>{this.en(i),this.an(i)},this.Xr=i=>{this.en(i),this.hn(i)},t.addEventListener("mousemove",this.Or,{passive:!0}),t.addEventListener("mouseleave",this.Hr,{passive:!0}),t.addEventListener("mousedown",this.Kr,{passive:!0}),t.addEventListener("mouseup",this.Nr,{passive:!0}),t.addEventListener("click",this.jr,{passive:!0}),t.addEventListener("wheel",this.Xr,{passive:!1}),this.Cr=!0}zr(){if(!this.Cr)return;const t=this.Yi.canvas;t.removeEventListener("mousemove",this.Or),t.removeEventListener("mouseleave",this.Hr),t.removeEventListener("mousedown",this.Kr),t.removeEventListener("mouseup",this.Nr),t.removeEventListener("click",this.jr),t.removeEventListener("wheel",this.Xr),this.Cr=!1}tn(){if(this.Cr)try{if(this.Vr){const t=new MouseEvent("mousemove",{clientX:this.Vr.x,clientY:this.Vr.y,bubbles:!1,cancelable:!1});this.en(t)}else this.Ir.x!==-1&&this.Ir.y!==-1&&(this.Ir.x>=this.Wr.cols||this.Ir.y>=this.Wr.rows)&&(this.Ir.x=-1,this.Ir.y=-1)}catch{this.Ir.x=-1,this.Ir.y=-1}}cn(t){this.Yr=t}kr(t){this.qr=t}Tr(t){this.Zr=t}ln(t){this.Jr=t}un(t){this.Qr=t}fn(){return{x:this.Ir.x,y:this.Ir.y}}sn(t){if(this.Jr){const i={position:{...this.Ir},previousPosition:{...this.Ur},originalEvent:t};this.Jr(i)}}rn(t){if(this.qr){const i={position:{...this.Ir},previousPosition:{...this.Ur},button:t.button,originalEvent:t};this.qr(i)}}nn(t){if(this.Zr){const i={position:{...this.Ir},previousPosition:{...this.Ur},button:t.button,originalEvent:t};this.Zr(i)}}an(t){if(this.Yr){const i={position:{...this.Ir},previousPosition:{...this.Ur},button:t.button,originalEvent:t};this.Yr(i)}}hn(t){if(this.Qr){const i={position:{...this.Ir},previousPosition:{...this.Ur},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.Qr(i)}}en(t){const i=this.Yi.canvas;this.Ur={...this.Ir},this.Vr={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,o=t.clientY-r.top,a=i.width/r.width,h=o*(i.height/r.height),l=n*a-this.Wr.offsetX,f=h-this.Wr.offsetY,d=Math.floor(l/this.Wr.cellWidth),p=Math.floor(f/this.Wr.cellHeight);d>=0&&d<this.Wr.cols&&p>=0&&p<this.Wr.rows?(this.Ir.x=d,this.Ir.y=p):(this.Ir.x=-1,this.Ir.y=-1)}}const kt=c=>class extends c{rotate(t=0,i=0,r=0){this.kt.state.ht(t),this.kt.state.ct(i),this.kt.state.lt(r)}rotateX(t){this.kt.state.ht(t)}rotateY(t){this.kt.state.ct(t)}rotateZ(t){this.kt.state.lt(t)}push(){this.kt.state.N()}pop(){this.kt.state.it()}rect(t,i,r=1,n=1){this.kt.Es(t,i,r,n)}point(t,i){this.kt.Es(t,i,1,1)}line(t,i,r,n){this.kt.Bs(t,i,r,n)}lineWeight(t){this.kt.state.ot(t)}background(t,i=t,r=t,n=255){this.kt.Os(t,i,r,n)}char(t){this.kt.state.ut(this.Fi.Mi(t))}charColor(t,i,r){this.kt.state.ft(t,i,r)}cellColor(t,i,r){this.kt.state.dt(t,i,r)}flipX(t){this.kt.state._t(t)}flipY(t){this.kt.state.gt(t)}charRotation(t){this.kt.state.yt(t)}invert(t){this.kt.state.vt(t)}clear(){this.kt.Os(0,0,0,0)}ellipse(t,i,r,n){this.kt.Ds(t,i,r/2,n/2)}triangle(t,i,r,n,o,a){this.kt.Ws(t,i,r,n,o,a)}bezierCurve(t,i,r,n,o,a,h,l){this.kt.Is(t,i,r,n,o,a,h,l)}arc(t,i,r,n,o,a){this.kt.Vs(t,i,r,n,o,a)}shader(t){this.kt.Ps(t)}setUniform(t,i){this.kt.Jt(t,i)}setUniforms(t){this.kt.As(t)}createFilterShader(t){return this.kt.he(t)}createFramebuffer(t){return this.kt.Us(t.width,t.height,5,{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"})}image(t,i,r,n,o){this.kt.Gs(t,i,r,n??t.width,o??t.height)}};class V{dn(t){const i=t.Et(0),r=t.Et(1),n=t.Et(2),o=t.Et(3);return{characterPixels:i,primaryColorPixels:r,secondaryColorPixels:n,transformPixels:t.Et(4),rotationPixels:o}}_n(t,i){return t[i]+(t[i+1]<<8)}pn(t,i){return{r:t[i],g:t[i+1],b:t[i+2],a:t[i+3]}}}class H{gn(t,i){return new Blob([t],{type:i})}mn(t,i,r){try{const n=this.gn(t,r),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=i,a.style.display="none",a.rel="noopener",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(o)}catch(n){throw console.error("Failed to download file:",n),Error("File download failed: "+(n instanceof Error?n.message:"Unknown error"))}}vn(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}yn(){const t=new Date;return{date:t.toISOString().split("T")[0],time:t.toTimeString().split(" ")[0].replace(/:/g,"-")}}$n(t){return t.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Cn(){return"textmode-export-"+this.vn()}}class zt extends V{wn(t,i,r){const n=t[r]===255,o=t[r+1]===255,a=t[r+2]===255,h=i[r],l=i[r+1];return{isInverted:n,flipHorizontal:o,flipVertical:a,rotation:Math.round(360*(h+l/255)/255*100)/100}}bn(t,i,r){return{x:t,y:i,cellX:t*r.cellWidth,cellY:i*r.cellHeight}}xn(t,i){const r=[];let n=0;for(let o=0;o<i.rows;o++)for(let a=0;a<i.cols;a++){const h=4*n,l=this._n(t.characterPixels,h);let f=this.pn(t.primaryColorPixels,h),d=this.pn(t.secondaryColorPixels,h);const p=this.wn(t.transformPixels,t.rotationPixels,h);if(p.isInverted){const m=f;f=d,d=m}const g=this.bn(a,o,i);r.push({charIndex:l,primaryColor:f,secondaryColor:d,transform:p,position:g}),n++}return r}}class Wt{Rn(t,i){const r=t.cmap;for(const n of r.tables)if(n.format===4){const o=n;for(let a=0;a<o.startCount.length;a++)if(i>=o.startCount[a]&&i<=o.endCount[a]){if(o.idRangeOffset[a]===0)return i+o.idDelta[a]&65535;{const h=o.idRangeOffset[a]/2+(i-o.startCount[a])-(o.startCount.length-a);if(h>=0&&h<o.glyphIdArray.length){const l=o.glyphIdArray[h];if(l!==0)return l+o.idDelta[a]&65535}}}}else if(n.format===12){const o=n;for(let a=0;a<o.groups.length;a+=3){const h=o.groups[a],l=o.groups[a+1],f=o.groups[a+2];if(i>=h&&i<=l)return f+(i-h)}}return 0}Mn(t,i,r,n,o){const a=o/t.head.unitsPerEm;return{getBoundingBox:()=>({x1:r+i.xMin*a,y1:n+-i.yMax*a,x2:r+i.xMax*a,y2:n+-i.yMin*a}),toSVG:()=>this.Sn(i,r,n,a)}}Sn(t,i,r,n){if(!t||!t.xs)return"";const{xs:o,ys:a,endPts:h,flags:l}=t;if(!(o&&a&&h&&l))return"";let f="",d=0;for(let p=0;p<h.length;p++){const g=h[p];if(!(g<d)){if(g>=d){const m=i+o[d]*n,x=r-a[d]*n;f+=`M${m.toFixed(2)},${x.toFixed(2)}`;let v=d+1;for(;v<=g;)if(1&l[v]){const A=i+o[v]*n,b=r-a[v]*n;f+=`L${A.toFixed(2)},${b.toFixed(2)}`,v++}else{const A=i+o[v]*n,b=r-a[v]*n;let T=v+1>g?d:v+1;if(1&l[T]){const _=i+o[T]*n,z=r-a[T]*n;f+=`Q${A.toFixed(2)},${b.toFixed(2)} ${_.toFixed(2)},${z.toFixed(2)}`,v=T+1}else{const _=(A+(i+o[T]*n))/2,z=(b+(r-a[T]*n))/2;f+=`Q${A.toFixed(2)},${b.toFixed(2)} ${_.toFixed(2)},${z.toFixed(2)}`,v=T}}f+="Z"}d=g+1}}return f}Fn(t,i,r,n,o){const a=t.codePointAt(0)||0,h=this.Rn(i,a);let l=null;return i.glyf&&i.glyf[h]!==null?l=i.glyf[h]:(l=F.T.glyf.Ks(i,h),i.glyf[h]=l),this.Mn(i,l,r,n,o)}zn(t,i,r,n,o,a,h,l){const f=r+(o-l*(h/i.head.unitsPerEm))/2,d=n+(a+.7*h)/2;return this.Fn(t,i,f,d,h).toSVG()||null}}class Dt{constructor(){u(this,"kn");this.kn=new Wt}Tn(t){const{width:i,height:r}=t;return`<?xml version="1.0" encoding="UTF-8"?><svg width="${i}" height="${r}" viewBox="0 0 ${i} ${r}" xmlns="http://www.w3.org/2000/svg"><title>textmode.js sketch</title>`}Pn(){return"</g></svg>"}An(t,i){if(!i.includeBackgroundRectangles)return"";const[r,n,o,a]=i.backgroundColor;return`<rect width="${t.width}" height="${t.height}" fill="rgba(${r},${n},${o},${a/255})"/>`}Gn(t,i){const{transform:r,position:n}=t;if(!r.flipHorizontal&&!r.flipVertical&&!r.rotation)return"";const o=n.cellX+i.cellWidth/2,a=n.cellY+i.cellHeight/2,h=[];if(r.flipHorizontal||r.flipVertical){const l=r.flipHorizontal?-1:1,f=r.flipVertical?-1:1;h.push(`translate(${o} ${a})scale(${l} ${f})translate(${-o} ${-a})`)}return r.rotation&&h.push(`rotate(${r.rotation} ${o} ${a})`),` transform="${h.join(" ")}"`}Ln(t,i,r){if(!r.includeBackgroundRectangles||t.secondaryColor.a===0)return"";const{position:n}=t,{r:o,g:a,b:h,a:l}=t.secondaryColor,f=`rgba(${o},${a},${h},${l/255})`;return r.drawMode==="stroke"?`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" stroke="${f}" fill="none" stroke-width="${r.strokeWidth}"/>`:`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" fill="${f}"/>`}Fn(t,i,r,n){const o=r.characters[t.charIndex];if(!o)return"";const a=this.kn.zn(o.character,r.font,t.position.cellX,t.position.cellY,i.cellWidth,i.cellHeight,r.fontSize,o.advanceWidth);if(!a)return"";const{r:h,g:l,b:f,a:d}=t.primaryColor,p=`rgba(${h},${l},${f},${d/255})`;return n.drawMode==="stroke"?`<path d="${a}" stroke="${p}" stroke-width="${n.strokeWidth}" fill="none"/>`:`<path d="${a}" fill="${p}"/>`}En(t,i,r,n){const o=[],a=this.Ln(t,i,n);a&&o.push(a);const h=this.Fn(t,i,r,n);if(h){const l=this.Gn(t,i);o.push(l?`<g${l}>${h}</g>`:h)}return o.join("")}Bn(t,i,r,n){const o=[this.Tn(i),this.An(i,n),'<g id="ascii-cells">'];for(const a of t)o.push(this.En(a,i,r,n));return o.push(this.Pn()),o.join("")}Dn(t){return t.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\s+/g," ").replace(/> </g,"><")}}class Bt extends H{Wn(t){return this.gn(t,"image/svg+xml;charset=utf-8")}In(t,i){this.mn(t,this.$n(i)+".svg","image/svg+xml;charset=utf-8")}Un(t,i){this.In(t,i||this.Cn())}}class et{constructor(){u(this,"Vn");u(this,"On");u(this,"Hn");this.Vn=new zt,this.On=new Dt,this.Hn=new Bt}Kn(t){return{includeBackgroundRectangles:t.includeBackgroundRectangles??!0,drawMode:t.drawMode??"fill",strokeWidth:t.strokeWidth??1,backgroundColor:t.backgroundColor??[0,0,0,0],filename:t.filename||this.Hn.Cn()}}Nn(t,i={}){const r=this.Vn.xn(this.Vn.dn(t.pipeline),t.grid),n=this.On.Bn(r,t.grid,t.font,this.Kn(i));return this.On.Dn(n)}Un(t,i={}){this.Hn.Un(this.Nn(t,i),i.filename)}}class Ot extends V{jn(t,i,r,n=" "){var h;const o=[];let a=0;for(let l=0;l<i.rows;l++){const f=[];for(let d=0;d<i.cols;d++){const p=4*a,g=this._n(t.characterPixels,p),m=((h=r.characters[g])==null?void 0:h.character)||n;f.push(m),a++}o.push(f)}return o}}class $t{Xn(t,i){const r=[];for(const o of t){let a=o.join("");i.preserveTrailingSpaces||(a=a.replace(/\s+$/,"")),r.push(a)}const n=i.lineEnding==="crlf"?`\r
|
|
11
11
|
`:`
|
|
12
|
-
`;return r.join(n)}}class
|
|
12
|
+
`;return r.join(n)}}class Gt extends H{Yn(t,i){const r=this.qn(i);this.mn(t,r,"text/plain;charset=utf-8")}qn(t){let i=this.$n(t);return i===".txt"||i.length<=4?this.Cn():i}}class it{constructor(){u(this,"Vn");u(this,"On");u(this,"Hn");this.Vn=new Ot,this.On=new $t,this.Hn=new Gt}Kn(t){return{preserveTrailingSpaces:t.preserveTrailingSpaces??!1,lineEnding:t.lineEnding??"lf",emptyCharacter:t.emptyCharacter??" ",filename:t.filename||this.Hn.Cn()}}Zn(t,i={}){const r=this.Kn(i),n=this.Vn.jn(this.Vn.dn(t.pipeline),t.grid,t.font,r.emptyCharacter);return this.On.Xn(n,r)}Yn(t,i={}){this.Hn.Yn(this.Zn(t,i),i.filename)}}class Yt extends V{Jn(t,i=1,r="transparent"){const n=t.canvas;if(i===1&&r==="transparent")return n;const o=document.createElement("canvas"),a=o.getContext("2d"),h=Math.round(n.width*i),l=Math.round(n.height*i);return o.width=h,o.height=l,r!=="transparent"&&(a.fillStyle=r,a.fillRect(0,0,h,l)),a.imageSmoothingEnabled=!1,a.drawImage(n,0,0,n.width,n.height,0,0,h,l),o}}class Nt{Qn(t,i){const r=this.eo(i.format);return i.format==="png"?t.toDataURL(r):t.toDataURL(r,i.quality)}async so(t,i){return new Promise((r,n)=>{const o=this.eo(i.format),a=h=>{h?r(h):n(Error(`Failed to generate ${i.format.toUpperCase()} blob`))};i.format==="png"?t.toBlob(a,o):t.toBlob(a,o,i.quality)})}eo(t){switch(t){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+t)}}}const Vt={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},rt={png:".png",jpg:".jpg",webp:".webp"};class Ht extends H{io(t,i,r){this.ro(t,this.$n(i)+rt[r])}ro(t,i){const r=URL.createObjectURL(t);try{const n=document.createElement("a");n.href=r,n.download=i,n.style.display="none",n.rel="noopener",document.body.appendChild(n),n.click(),document.body.removeChild(n)}finally{URL.revokeObjectURL(r)}}no(t){return t in Vt&&t in rt}}class Xt{constructor(){u(this,"Vn");u(this,"On");u(this,"Hn");this.Vn=new Yt,this.On=new Nt,this.Hn=new Ht}Kn(t){return{format:t.format??"png",quality:t.quality??1,scale:t.scale??1,backgroundColor:t.backgroundColor??"transparent",filename:t.filename||this.Hn.Cn()}}oo(t){if(!this.Hn.no(t.format))throw Error(`Saving '${t.format}' files is not supported`);if(t.quality<0||t.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(t.scale<=0)throw Error("Scale factor must be greater than 0");t.format==="jpg"&&t.backgroundColor==="transparent"&&(t.backgroundColor="black")}async so(t,i){if(i.scale===1&&i.backgroundColor==="transparent")return await this.On.so(t.canvas,i);const r=this.Vn.Jn(t,i.scale,i.backgroundColor);return await this.On.so(r,i)}async io(t,i={}){const r=this.Kn(i);this.oo(r);const n=await this.so(t,r);this.Hn.io(n,r.filename,r.format)}}const jt=c=>class extends c{ao(){this.kt.Dt(this.ho)}toString(t={}){return this.ao(),new it().Zn({pipeline:this.co,grid:this.Wr,font:this.Fi},t)}saveStrings(t={}){this.ao(),new it().Yn({pipeline:this.co,grid:this.Wr,font:this.Fi},t)}toSVG(t={}){return this.ao(),new et().Nn({pipeline:this.co,grid:this.Wr,font:this.Fi},t)}saveSVG(t={}){this.ao(),new et().Un({pipeline:this.co,grid:this.Wr,font:this.Fi},t)}async saveCanvas(t={}){await new Xt().io(this.Yi,t)}},Kt=c=>class extends c{async loadFont(t){return this.Fi.Hi(t).then(()=>{const i=this.Fi.maxGlyphDimensions;this.Wr.Ji(i.width,i.height),this.co.resize(this.Wr.cols,this.Wr.rows),this.kt.Hs(),this.lo.tn()})}fontSize(t){if(!I.M(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.Fi.fontSize===t)return;this.Fi.Oi(t);const i=this.Fi.maxGlyphDimensions;this.Wr.Ji(i.width,i.height),this.co.resize(this.Wr.cols,this.Wr.rows),this.kt.Hs(),this.lo.tn()}glyphColor(t){return this.Fi.Mi(t)}glyphColors(t){return this.Fi.Si(t)}},Zt=c=>class extends c{get frameCount(){return this.uo.frameCount}set frameCount(t){this.uo.frameCount=t}frameRate(t){return t===void 0?this.uo.currentFrameRate:this.uo.frameRate(t,()=>this.fo())}noLoop(){this.uo.pause()}loop(){this.uo.resume(()=>this.fo())}redraw(t=1){if(I.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.fo()}isLooping(){return this.uo.isLooping}},qt=c=>class extends c{constructor(...t){super(...t)}mouseClicked(t){this.lo.cn(t)}mousePressed(t){this.lo.kr(t)}mouseReleased(t){this.lo.Tr(t)}mouseMoved(t){this.lo.ln(t)}mouseScrolled(t){this.lo.un(t)}get mouse(){return this.lo.fn()}},Jt=c=>class extends c{constructor(...t){super(...t)}keyPressed(t){this.do.kr(t)}keyReleased(t){this.do.Tr(t)}isKeyPressed(t){return this.do.Pr(t)}get lastKeyPressed(){return this.do.Gr()}get lastKeyReleased(){return this.do.Lr()}get pressedKeys(){return this.do.Er()}get modifierState(){return this.do.Br()}};class Qt{constructor(){u(this,"kt");u(this,"Fi");u(this,"Yi");u(this,"Wr");u(this,"uo");u(this,"lo");u(this,"do");u(this,"ho");u(this,"co");u(this,"_o")}fo(){}}class st extends function(i,...r){return r.reduce((n,o)=>o(n),i)}(Qt,kt,jt,Kt,Zt,qt,Jt){constructor(i={}){super();u(this,"po",!1);u(this,"mo",()=>{});u(this,"vo",()=>{});u(this,"yo",()=>{});u(this,"$o");this.Yi=new tt(i),this.kt=new wt(this.Yi.ir()),this.Fi=new J(this.kt,i.fontSize??16),this.uo=new Mt(i.frameRate??60),this.lo=new It(this.Yi),this.do=new Ut,this.ho=this.kt.Bt(),this._o=this.kt.ae(),this.Co(i)}async Co(i){await this.Fi.Ii(i.fontSource);const r=this.Fi.maxGlyphDimensions;this.Wr=new Q(this.Yi.canvas,r.width,r.height),this.lo.Ii(this.Wr),this.co=this.kt.Us(this.Wr.cols,this.Wr.rows,5),this.wo(),this.mo(),this.uo.start(()=>this.fo())}wo(){this.$o=()=>{this.yo()},window.addEventListener("resize",this.$o),this.lo.Mr(),this.do.Mr(),window.addEventListener("blur",()=>{this.do.Dr()})}fo(){if(this.uo.measureFrameRate(),this.uo.incrementFrame(),this.po)return;this.co.begin(),this.kt.ks(this.ho),this.vo(),this.kt.Dt(this.ho),this.co.end();const i=this.kt.state.canvasBackgroundColor;this.kt.He(i[0],i[1],i[2],i[3]),this.kt.ks(this._o),this._o.Zt({a:this.Fi.fontFramebuffer,b:[this.Fi.textureColumns,this.Fi.textureRows],c:this.co.textures[0],d:this.co.textures[1],e:this.co.textures[2],f:this.co.textures[4],g:this.co.textures[3],h:[this.Wr.cols,this.Wr.rows],i:[this.Wr.width,this.Wr.height],j:[this.Wr.offsetX,this.Wr.offsetY],k:this.Wr.width/this.Wr.height}),this.kt.Ls(this.Wr.offsetX,this.Wr.offsetY,this.Wr.width,this.Wr.height)}setup(i){this.mo=i}draw(i){this.vo=i}windowResized(i){this.yo=i}resizeCanvas(i,r){this.Yi.sr(i,r),this.Wr.rt(),this.co.resize(this.Wr.cols,this.Wr.rows),this.kt.Hs(),this.lo.tn(),this.fo()}destroy(){this.po||(this.uo.stop(),window.removeEventListener("resize",this.$o),this.lo.zr(),this.do.zr(),this.Fi.Ut(),this.kt.Ut(),this.po=!0)}get grid(){return this.Wr}get font(){return this.Fi}get width(){return this.Yi.width}get height(){return this.Yi.height}get canvas(){return this.Yi.canvas}get isDisposed(){return this.po}get drawFramebuffer(){return this.co}}class G{constructor(){}static create(t={}){return new st(t)}static setErrorLevel(t){I.S(t)}static get version(){return"0.2.1-beta.4"}}const te=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),ee=G.create,ie=G.setErrorLevel,re=G.version;R.TextmodeCanvas=tt,R.TextmodeErrorLevel=L,R.TextmodeFont=J,R.TextmodeFramebuffer=B,R.TextmodeGrid=Q,R.Textmodifier=st,R.create=ee,R.export=te,R.setErrorLevel=ie,R.textmode=G,R.version=re,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):s((e=typeof globalThis<"u"?globalThis:e||self).textmode={});
|
|
@@ -12,6 +12,7 @@ export declare class GLShader {
|
|
|
12
12
|
private _gl;
|
|
13
13
|
private _program;
|
|
14
14
|
private _uniformLocations;
|
|
15
|
+
private _uniformTypes;
|
|
15
16
|
private _textureUnitCounter;
|
|
16
17
|
/**
|
|
17
18
|
* Creates a new GLShader instance.
|
|
@@ -38,7 +39,22 @@ export declare class GLShader {
|
|
|
38
39
|
*/
|
|
39
40
|
$hasUniform(name: string): boolean;
|
|
40
41
|
/**
|
|
41
|
-
*
|
|
42
|
+
* Get debug information about a uniform
|
|
43
|
+
*/
|
|
44
|
+
$getUniformInfo(name: string): {
|
|
45
|
+
type: number;
|
|
46
|
+
size: number;
|
|
47
|
+
} | null;
|
|
48
|
+
/**
|
|
49
|
+
* List all available uniforms for debugging
|
|
50
|
+
*/
|
|
51
|
+
$listUniforms(): Array<{
|
|
52
|
+
name: string;
|
|
53
|
+
type: number;
|
|
54
|
+
size: number;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Set a single uniform value with automatic texture unit management and proper type detection
|
|
42
58
|
*/
|
|
43
59
|
$setUniform(name: string, value: UniformValue): void;
|
|
44
60
|
private _getNextTextureUnit;
|
package/package.json
CHANGED