textmode.js 0.3.2-beta.3 → 0.4.1-beta.1
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/README.md +5 -5
- package/dist/textmode.esm.js +571 -578
- package/dist/textmode.esm.min.js +113 -120
- package/dist/textmode.umd.js +4 -4
- package/dist/textmode.umd.min.js +4 -4
- package/dist/types/index.d.ts +1 -4
- package/dist/types/textmode/Textmodifier.d.ts +4 -14
- package/dist/types/textmode/font/typr/types.d.ts +0 -16
- package/dist/types/textmode/mixins/FontMixin.d.ts +2 -2
- package/dist/types/textmode/plugins/PluginManager.d.ts +45 -14
- package/package.json +1 -1
- package/dist/types/export/base/DataExtractor.d.ts +0 -34
- package/dist/types/export/base/FileHandler.d.ts +0 -46
- package/dist/types/export/base/index.d.ts +0 -2
- package/dist/types/export/index.d.ts +0 -1
- package/dist/types/export/svg/SVGContentGenerator.d.ts +0 -76
- package/dist/types/export/svg/SVGDataExtractor.d.ts +0 -33
- package/dist/types/export/svg/SVGExporter.d.ts +0 -31
- package/dist/types/export/svg/SVGFileHandler.d.ts +0 -25
- package/dist/types/export/svg/SVGPathGenerator.d.ts +0 -49
- package/dist/types/export/svg/index.d.ts +0 -6
- package/dist/types/export/svg/types.d.ts +0 -129
package/dist/textmode.umd.min.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
1
|
+
var he=Object.defineProperty;var ae=(C,T,G)=>T in C?he(C,T,{enumerable:!0,configurable:!0,writable:!0,value:G}):C[T]=G;var c=(C,T,G)=>ae(C,typeof T!="symbol"?T+"":T,G);var s,e;s=this,e=function(C){class T extends Error{constructor(t,i={}){super(T.i(t,i)),this.name="TextmodeError"}static i(t,i){return`${t}${i&&Object.keys(i).length>0?`
|
|
2
2
|
|
|
3
3
|
📋 Context:`+Object.entries(i).map(([r,n])=>`
|
|
4
4
|
- ${r}: ${T.o(n)}`).join(""):""}
|
|
5
5
|
|
|
6
6
|
${"↓".repeat(24)}
|
|
7
|
-
`}static o(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="number"||typeof t=="boolean")return t+"";if(Array.isArray(t))return t.length===0?"[]":t.length<=5?`[${t.map(i=>T.o(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>T.o(i)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const i=Object.keys(t);return i.length===0?"{}":i.length<=3?`{ ${i.map(r=>`${r}: ${T.o(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${T.o(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var G=(l=>(l[l.SILENT=0]="SILENT",l[l.WARNING=1]="WARNING",l[l.ERROR=2]="ERROR",l[l.THROW=3]="THROW",l))(G||{});const B=class B{constructor(){c(this,"u",{globalLevel:3})}static _(){return B.l||(B.l=new B),B.l}m(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.u.globalLevel){case 0:return!1;case 1:return console.group(r,n),console.warn(T.i(t,i)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(T.i(t,i)),console.groupEnd(),!1;default:throw new T(t,i)}}v(t,i,r){return!!t||(this.m(i,r),!1)}C(t){this.u.globalLevel=t}};c(B,"l",null);let Z=B;const W=Z._(),it=new WeakMap;function H(l,t){it.set(l,t)}function
|
|
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 U9;uniform vec2
|
|
7
|
+
`}static o(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="number"||typeof t=="boolean")return t+"";if(Array.isArray(t))return t.length===0?"[]":t.length<=5?`[${t.map(i=>T.o(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>T.o(i)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const i=Object.keys(t);return i.length===0?"{}":i.length<=3?`{ ${i.map(r=>`${r}: ${T.o(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${T.o(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var G=(l=>(l[l.SILENT=0]="SILENT",l[l.WARNING=1]="WARNING",l[l.ERROR=2]="ERROR",l[l.THROW=3]="THROW",l))(G||{});const B=class B{constructor(){c(this,"u",{globalLevel:3})}static _(){return B.l||(B.l=new B),B.l}m(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.u.globalLevel){case 0:return!1;case 1:return console.group(r,n),console.warn(T.i(t,i)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(T.i(t,i)),console.groupEnd(),!1;default:throw new T(t,i)}}v(t,i,r){return!!t||(this.m(i,r),!1)}C(t){this.u.globalLevel=t}};c(B,"l",null);let Z=B;const W=Z._(),it=new WeakMap;function H(l,t){it.set(l,t)}function $(l){return it.get(l)}class st{constructor(){c(this,"$",1);c(this,"U",0);c(this,"M",0);c(this,"R",0);c(this,"F",[0,0,0]);c(this,"S",[1,1,1,1]);c(this,"A",[0,0,0,1]);c(this,"k",!1);c(this,"P",!1);c(this,"L",!1);c(this,"D",[0,0]);c(this,"G",[0,0,0,1]);c(this,"I",[])}O(){this.I.push({W:this.$,H:this.U,K:this.M,X:this.R,D:[...this.D],N:this.k,j:this.P,L:this.L,Y:[...this.F],V:[...this.S],q:[...this.A]})}Z(){const t=this.I.pop();t?(this.$=t.W,this.U=t.H,this.M=t.K,this.R=t.X,this.D=t.D,this.k=t.N,this.P=t.j,this.L=t.L,this.F=t.Y,this.S=t.V,this.A=t.q):console.warn("pop() called without matching push()")}J(t){t.W=this.$,t.H=this.U,t.K=this.M,t.X=this.R,t.Y[0]=this.F[0],t.Y[1]=this.F[1],t.Y[2]=this.F[2],t.V[0]=this.S[0],t.V[1]=this.S[1],t.V[2]=this.S[2],t.V[3]=this.S[3],t.q[0]=this.A[0],t.q[1]=this.A[1],t.q[2]=this.A[2],t.q[3]=this.A[3],t.N=this.k,t.j=this.P,t.L=this.L,t.D[0]=this.D[0],t.D[1]=this.D[1]}get lineWeight(){return this.$}get canvasBackgroundColor(){return this.G}tt(t){this.$=Math.abs(t)}st(t){this.U=t}et(t){this.M=t}it(t){this.R=t}rt(t){this.F=t}nt(t,i,r,n=255){this.S=[t/255,i/255,r/255,n/255]}ot(t,i,r,n=255){this.A=[t/255,i/255,r/255,n/255]}ht(t){this.k=t}ct(t){this.P=t}lt(t){this.L=t}ut(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));this.D=[r,n]}ft(t,i,r,n){this.G=[t/255,i/255,r/255,n/255]}}class V{constructor(t,i,r=i,n=1,o={},h=null,a=!1){c(this,"dt");c(this,"_t");c(this,"u");c(this,"vt",null);c(this,"gt");c(this,"yt");c(this,"Ct",[]);c(this,"wt");c(this,"bt",null);c(this,"$t",[]);c(this,"xt",null);c(this,"Mt",!1);c(this,"Rt",null);this.dt=i,this._t=r,this.u={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.gt=t,this.wt=Math.min(Math.max(1,n),8),this.xt=h,this.Mt=!!a,this.Rt=this.Mt?new st:null;const u=t.getParameter(t.MAX_DRAW_BUFFERS),f=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.wt=Math.min(this.wt,u,f),this.yt=t.createFramebuffer(),this.Ft(),this.St(),this.$t=Array(this.wt).fill(null)}Ft(){const t=this.gt,i=this.u.filter==="linear"?t.LINEAR:t.NEAREST,r=this.u.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE,n=this.u.type==="float"?t.FLOAT:t.UNSIGNED_BYTE;for(let o=0;o<this.wt;o++){const h=t.createTexture();t.bindTexture(t.TEXTURE_2D,h),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.dt,this._t,0,t.RGBA,n,null),this.Ct.push(h)}t.bindTexture(t.TEXTURE_2D,null)}St(){const t=this.gt;if(t.bindFramebuffer(t.FRAMEBUFFER,this.yt),this.wt===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.Ct[0],0);else{const r=[];for(let n=0;n<this.wt;n++){const o=t.COLOR_ATTACHMENT0+n;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,this.Ct[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)}Tt(t){const i=this.gt;i.bindTexture(i.TEXTURE_2D,this.Ct[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.dt=t,this._t=i,this.vt=null,this.$t=Array(this.wt).fill(null);const r=this.gt,n=this.u.type==="float"?r.FLOAT:r.UNSIGNED_BYTE;for(const o of this.Ct)r.bindTexture(r.TEXTURE_2D,o),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.dt,this._t,0,r.RGBA,n,null);r.bindTexture(r.TEXTURE_2D,null)}readPixels(t){const i=this.gt,r=this.$t[t];if(r)return r;const n=this.dt,o=this._t,h=new Uint8Array(n*o*4),a=i.getParameter(i.READ_FRAMEBUFFER_BINDING);i.bindFramebuffer(i.READ_FRAMEBUFFER,this.yt),i.readBuffer(i.COLOR_ATTACHMENT0+t),i.readPixels(0,0,n,o,i.RGBA,i.UNSIGNED_BYTE,h),i.bindFramebuffer(i.READ_FRAMEBUFFER,a);const u=4*n,f=new Uint8Array(h.length);for(let g=0;g<o;g++){const d=(o-1-g)*u,v=g*u;f.set(h.subarray(d,d+u),v)}return this.$t[t]=f,f}begin(){var i,r,n,o;const t=this.gt;if(this.xt){const h=((r=(i=this.xt).At)==null?void 0:r.call(i))??null;h&&this.xt.zt(h),this.Mt&&this.Rt&&((o=(n=this.xt).kt)==null||o.call(n,this.Rt))}this.bt={framebuffer:t.getParameter(t.FRAMEBUFFER_BINDING),viewport:t.getParameter(t.VIEWPORT)},t.bindFramebuffer(t.FRAMEBUFFER,this.yt),this.$t=Array(this.wt).fill(null);for(let h=0;h<this.wt;h++)t.clearBufferfv(t.COLOR,h,new Float32Array([0,0,0,0]));t.viewport(0,0,this.dt,this._t),H(t,[0,0,this.dt,this._t])}end(){var i,r,n,o;if(!this.bt)return;const t=this.gt;if(this.xt){const h=((r=(i=this.xt).At)==null?void 0:r.call(i))??null;h&&this.xt.zt(h)}t.bindFramebuffer(t.FRAMEBUFFER,this.bt.framebuffer),t.viewport(...this.bt.viewport),H(t,this.bt.viewport),this.bt=null,this.xt&&this.Mt&&this.Rt&&((o=(n=this.xt).Et)==null||o.call(n))}Pt(){const t=this.gt;t.deleteFramebuffer(this.yt);for(const i of this.Ct)t.deleteTexture(i)}get width(){return this.dt}get height(){return this._t}get textures(){return[...this.Ct]}}class k{constructor(t,i,r){c(this,"gt");c(this,"Lt");c(this,"Dt",new Map);c(this,"Bt",new Map);c(this,"Gt",0);this.gt=t,this.Lt=this.It(i,r),this.Ot()}Ot(){const t=this.gt.getProgramParameter(this.Lt,this.gt.ACTIVE_UNIFORMS);for(let i=0;i<t;i++){const r=this.gt.getActiveUniform(this.Lt,i);if(r){const n=this.gt.getUniformLocation(this.Lt,r.name);if(n&&(this.Dt.set(r.name,n),this.Bt.set(r.name,{type:r.type,size:r.size}),r.size>1)){const o=r.name.replace(/\[.*\]$/,"");this.Dt.has(o)||(this.Dt.set(o,n),this.Bt.set(o,{type:r.type,size:r.size}))}}}}It(t,i){const r=this.Wt(this.gt.VERTEX_SHADER,t),n=this.Wt(this.gt.FRAGMENT_SHADER,i),o=this.gt.createProgram();if(this.gt.attachShader(o,r),this.gt.attachShader(o,n),this.gt.linkProgram(o),!this.gt.getProgramParameter(o,this.gt.LINK_STATUS)){const h=this.gt.getProgramInfoLog(o);throw Error("Shader program link error: "+h)}return this.gt.deleteShader(r),this.gt.deleteShader(n),o}Wt(t,i){const r=this.gt.createShader(t);if(this.gt.shaderSource(r,i),this.gt.compileShader(r),!this.gt.getShaderParameter(r,this.gt.COMPILE_STATUS)){const n=this.gt.getShaderInfoLog(r);throw this.gt.deleteShader(r),Error("Shader compilation error: "+n)}return r}Ht(){this.gt.useProgram(this.Lt),this.Kt()}Kt(){this.Gt=0}Xt(t){for(const[i,r]of Object.entries(t))this.Nt(i,r)}jt(t){return this.Dt.has(t)}Yt(t){return this.Bt.get(t)||null}Vt(){const t=[];for(const[i,r]of this.Bt.entries())t.push({name:i,...r});return t}Nt(t,i){var u;const r=this.Dt.get(t);if(!r)return;const n=this.Bt.get(t);if(!n)return void console.warn(`No type information found for uniform '${t}'`);const{type:o,size:h}=n,a=this.gt;if(typeof i=="number")switch(o){case a.INT:case a.BOOL:a.uniform1i(r,i);break;case a.FLOAT:a.uniform1f(r,i);break;default:console.warn(`Unexpected uniform type for scalar '${t}': ${o}`),a.uniform1f(r,i)}else if(typeof i=="boolean")a.uniform1i(r,i?1:0);else if(Array.isArray(i))if(Array.isArray(i[0])){const f=i,g=((u=f[0])==null?void 0:u.length)||0,d=f.flat();switch(o){case a.FLOAT_VEC2:g===2?a.uniform2fv(r,d):console.warn(`Vector length mismatch for '${t}': expected 2, got ${g}`);break;case a.FLOAT_VEC3:g===3?a.uniform3fv(r,d):console.warn(`Vector length mismatch for '${t}': expected 3, got ${g}`);break;case a.FLOAT_VEC4:g===4?a.uniform4fv(r,d):console.warn(`Vector length mismatch for '${t}': expected 4, got ${g}`);break;default:console.warn(`Unsupported uniform type for vector array '${t}': ${o}`)}}else switch(o){case a.FLOAT_VEC2:i.length===2?a.uniform2f(r,i[0],i[1]):console.warn(`Vector length mismatch for '${t}': expected 2, got ${i.length}`);break;case a.FLOAT_VEC3:i.length===3?a.uniform3f(r,i[0],i[1],i[2]):console.warn(`Vector length mismatch for '${t}': expected 3, got ${i.length}`);break;case a.FLOAT_VEC4:i.length===4?a.uniform4f(r,i[0],i[1],i[2],i[3]):console.warn(`Vector length mismatch for '${t}': expected 4, got ${i.length}`);break;case a.INT:h>1?a.uniform1iv(r,i):console.warn(`Array provided for scalar uniform '${t}'`);break;case a.FLOAT:h>1?a.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.qt();a.uniform1i(r,f),a.activeTexture(a.TEXTURE0+f),a.bindTexture(a.TEXTURE_2D,i)}else if(i instanceof V){const f=this.qt();a.uniform1i(r,f),a.activeTexture(a.TEXTURE0+f),a.bindTexture(a.TEXTURE_2D,i.textures[0])}else console.warn(`Unsupported uniform type for '${t}':`,typeof i)}qt(){return this.Gt++}get Zt(){return this.Lt}Pt(){this.gt.deleteProgram(this.Lt)}}const K=`#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 U9;uniform vec2 Uw;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 H,vec2 I,vec2 J,vec2 K,vec2 L){float M=1.-H,N=M*M,O=H*H;return N*M*I+3.*N*H*J+3.*M*O*K+O*H*L;}vec2 P(float H,vec2 I,vec2 J,vec2 K,vec2 L){float M=1.-H,N=M*M,O=H*H;return-3.*N*I+3.*N*J-6.*M*H*J+6.*M*H*K-3.*O*K+3.*O*L;}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 Q;bool R=length(a_instanceBezierCP1)+length(a_instanceBezierCP2)+length(a_instanceBezierStart)+length(a_instanceBezierEnd)>0.;bool S=a_instanceArcAngles.x!=0.||a_instanceArcAngles.y!=0.;if(R){float H=a_position.x;vec2 T=G(H,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 U=P(H,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float V=length(U);U=V>0.?U/V:vec2(1,0);Q=T+vec2(-U.y,U.x)*a_position.y*a_instanceSize.y;}else if(S){float C=a_instanceArcAngles.x,W=a_instanceArcAngles.y;C=mod(C,6.28318530718);if(C<0.)C+=6.28318530718;W=mod(W,6.28318530718);if(W<0.)W+=6.28318530718;float X=C-W;if(X<=0.)X+=6.28318530718;float Y=C-a_position.x*X;vec2 Z=vec2(cos(Y),sin(Y))*a_position.y;Q=Z*a_instanceSize*.5+a_instanceSize*.5+a_instancePosition;}else{Q=a_position*a_instanceSize+a_instancePosition;}vec2 a=(Q/Uw)*2.-1.;a.y=-a.y;if(length(a_instanceGlobalRotation)>0.){vec3 b=vec3(a-a_instanceRotationCenter,0);b.x*=U9;if(a_instanceGlobalRotation.x!=0.)b=A(-a_instanceGlobalRotation.x)*b;if(a_instanceGlobalRotation.y!=0.)b=E(-a_instanceGlobalRotation.y)*b;if(a_instanceGlobalRotation.z!=0.)b=F(-a_instanceGlobalRotation.z)*b;b.x/=U9;a=b.xy+a_instanceRotationCenter;}gl_Position=vec4(a,0,1);}`,rt="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.);}";class mt{constructor(t){c(this,"gt");c(this,"Jt");c(this,"Qt");c(this,"ts");c(this,"ss");this.gt=t,this.Qt=new k(this.gt,K,`#version 300 es
|
|
9
9
|
precision highp float;in vec2 v_uv;in vec3 v_character;in vec4 v_primaryColor;in vec4 v_secondaryColor;in vec2 v_rotation;in vec3 v_transform;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){o_character=vec4(v_character,1.);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.,1.);o_transform=vec4(v_transform,1.);}`),this.Jt=new k(this.gt,K,`#version 300 es
|
|
10
10
|
precision highp float;in vec2 v_uv;uniform sampler2D Ue;uniform sampler2D Uf;uniform sampler2D Ug;uniform sampler2D Uh;uniform sampler2D Ui;uniform vec2 Uj;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){vec2 A=vec2(v_uv.x,1.-v_uv.y);vec2 B=A*Uj;vec2 C=(floor(B)+0.5f)/Uj;vec4 D=texture(Ue,C);vec4 E=texture(Uf,C);if(E.a==0.){discard;}vec4 F=texture(Ug,C);vec4 G=texture(Uh,C);vec4 H=texture(Ui,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;o_rotation=G;o_transform=H;}`),this.ts=new k(this.gt,rt,"precision mediump float;uniform sampler2D U0;uniform vec2 U1;uniform sampler2D U3;uniform sampler2D U4;uniform sampler2D U5;uniform sampler2D U2;uniform sampler2D U6;uniform vec2 U7;uniform vec2 U8;mat2 A(float B){float C=sin(B);float D=cos(B);return mat2(D,-C,C,D);}void main(){vec2 E=gl_FragCoord.xy/U8;vec2 F=E*U7;vec2 G=floor(F);vec2 H=(G+0.5)/U7;vec4 I=texture2D(U3,H);vec4 J=texture2D(U4,H);vec4 K=texture2D(U5,H);bool L=K.r>0.5;bool M=K.g>0.5;bool N=K.b>0.5;vec4 O=texture2D(U2,H);int P=int(O.r*255.+0.5)+int(O.g*255.+0.5)*256;int Q=int(mod(float(P),U1.x));int R=P/int(U1.x);float S=(U1.y-1.)-float(R);vec2 T=vec2(float(Q),S)/U1;vec4 U=texture2D(U6,H);float V=U.r*255.+U.g;float W=-(V*360./255.)*0.017453292;vec2 X=fract(F)-0.5;if(M)X.x=-X.x;if(N)X.y=-X.y;X=A(W)*X+0.5;vec2 Y=1./U1;vec2 Z=T+X*Y;vec2 a=T+Y;if(any(lessThan(Z,T))||any(greaterThan(Z,a))){gl_FragColor=L?I:J;return;}vec4 b=texture2D(U0,Z);if(L)b.rgb=1.-b.rgb;gl_FragColor=mix(J,I,b);}"),this.ss=new k(this.gt,K,`#version 300 es
|
|
11
|
-
precision highp float;in vec2 v_uv;uniform sampler2D Uk;uniform bool Ul;uniform bool Um;uniform bool Un;uniform vec2 Uo;uniform bool Up;uniform vec4 Uq;uniform bool Ur;uniform vec4 Us;uniform vec4 Ut;uniform int Uu;uniform vec3 Uv[64];layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;float A(vec3 B){return dot(B,vec3(0.299f,0.587f,0.114f));}void main(){vec2 C=vec2(v_uv.x,1.0f-v_uv.y);vec4 D=texture(Uk,C);float E=A(D.rgb);if(Uu>0){float F=float(Uu);float G=clamp(E*(F-1.0f),0.0f,F-1.0f);int H=int(floor(G+0.5f));vec3 I=Uv[H];o_character=vec4(I,1.0f);}else{o_character=vec4(E,0.0f,0.0f,1.0f);}vec4 J=Up?Uq:D;vec4 K=Ur?Us:D;if(D.a<0.01f){J=Ut;K=Ut;}else{}o_primaryColor=vec4(J);o_secondaryColor=vec4(K);o_rotation=vec4(Uo.xy,0.0f,1.0f);o_transform=vec4(float(Ul),float(Um),float(Un),1.0f);}`)}es(){return this.Jt}At(){return this.Qt}rs(){return this.ts}ns(){return this.ss}hs(t){return new k(this.gt,K,t)}cs(t,i){return new k(this.gt,t,i)}Pt(){this.Jt.Pt(),this.Qt.Pt(),this.ts.Pt(),this.ss.Pt()}}var R=(l=>(l.RECTANGLE="rectangle",l.LINE="line",l.ELLIPSE="ellipse",l.ARC="arc",l.TRIANGLE="triangle",l.BEZIER_CURVE="bezier_curve",l.CUSTOM="custom",l))(R||{});class vt{constructor(t){c(this,"gt");c(this,"ls",new Map);this.gt=t}us(t,i,r,n){const o=this.gt;let h=this.ls.get(t);h||(h=new Map,this.ls.set(t,h));let a=h.get(i)||null;if(!a){a=o.createVertexArray(),h.set(i,a),o.bindVertexArray(a),o.bindBuffer(o.ARRAY_BUFFER,n);const u=o.getAttribLocation(t,"a_position");u!==-1&&(o.enableVertexAttribArray(u),o.vertexAttribPointer(u,r.ds.fs.size,o.FLOAT,!1,r._s,r.ds.fs.offset),o.vertexAttribDivisor(u,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,r.ds.ps.size,o.FLOAT,!1,r._s,r.ds.ps.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(a)}vs(){this.gt.bindVertexArray(null)}Pt(){for(const[,t]of this.ls)for(const[,i]of t)i&&this.gt.deleteVertexArray(i)}}class yt{constructor(t,i){c(this,"gs");c(this,"gt");c(this,"xt");c(this,"Cs",null);c(this,"ws",null);this.gt=t,this.gs=new vt(t),this.xt=i}bs(t,i,r){const{shader:n}=t,o=V(this.gt)||this.gt.getParameter(this.gt.VIEWPORT);n.Xt({U9:o[2]/o[3],Uy:[o[2],o[3]]});const h=f=>{if(!f||!f.$s())return;const g=f.unitGeometry,d=f.unitBuffer;try{this.gs.us(n.Zt,f.type+"",g,d),f.batch.Ms(n),f.batch.Rs(g.Fs,g.Ss)}finally{f.batch.Ts(n),this.gs.vs(),f.As()}};let a=null,u=null;for(const f of i){if(f.type===R.CUSTOM){u&&(h(u),a=null,u=null),this.zs(t,f.params,f.state,r.get(R.RECTANGLE));continue}a!==null&&f.type!==a&&(h(u),a=null,u=null);let g=u;g&&f.type===a||(g=r.get(f.type)||null,u=g,a=f.type),g&&g.ks(f.params,f.state)}h(u)}zs(t,i,r,n){const{x:o,y:h,width:a,height:u,shader:f,uniforms:g}=i,d=this.Es(Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)));d.begin(),this.Ps(n,f,g,0,0,d.width,d.height,{}),d.end();const v=this.Ls(),x={Ue:d.textures[0],Uf:d.textures[1],Ug:d.textures[2],Uh:d.textures[3],Ui:d.textures[4],Uj:[d.width,d.height]};this.Ps(n,v,x,Math.floor(o),Math.floor(h),Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)),r),t.shader.Ht()}Ps(t,i,r,n,o,h,a,u){i.Ht(),i.Xt(r);const f=this.gt.getParameter(this.gt.VIEWPORT);if(i.Xt({U9:f[2]/f[3],Uy:[f[2],f[3]]}),t.As(),t.ks({x:n,y:o,width:h,height:a},u),t.$s()){const g=t.unitGeometry,d=t.unitBuffer;try{this.gs.us(i.Zt,t.type+"",g,d),t.batch.Ms(i),t.batch.Rs(g.Fs,g.Ss)}finally{t.batch.Ts(i),this.gs.vs(),t.As()}}}Ls(){return this.xt.es()}Es(t,i){return this.Cs&&this.ws&&this.ws.w===t&&this.ws.h===i||(this.Cs&&this.Cs.Pt(),this.Cs=new $(this.gt,t,i,5),this.ws={w:t,h:i}),this.Cs}Pt(){this.gs.Pt(),this.Cs&&this.Cs.Pt()}}class xt{constructor(){c(this,"Ds",[]);c(this,"Bs",1);c(this,"Gs",0)}Is(t){if(this.Gs>=this.Ds.length){const r={id:this.Bs++,type:t,params:{},state:{W:1,H:0,K:0,X:0,Y:[0,0,0],V:[1,1,1,1],q:[0,0,0,1],j:!1,N:!1,L:!1,D:[0,0]}};this.Ds.push(r)}const i=this.Ds[this.Gs];return i.id=this.Bs++,i.type=t,this.Gs++,i}Os(t,i,r,n,o){const h=this.Is(R.RECTANGLE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Ws(t,i,r,n,o,h,a){const u=this.Is(R.CUSTOM);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.shader=o,u.params.uniforms=h,a.J(u.state),u.id}Hs(t,i,r,n,o,h){const a=this.Is(R.LINE);return a.params.x1=t,a.params.y1=i,a.params.x2=r,a.params.y2=n,a.params.thickness=o,h.J(a.state),a.id}Ks(t,i,r,n,o){const h=this.Is(R.ELLIPSE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Xs(t,i,r,n,o,h,a){const u=this.Is(R.ARC);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.start=o,u.params.stop=h,a.J(u.state),u.id}js(t,i,r,n,o,h,a){const u=this.Is(R.TRIANGLE);return u.params.x1=t,u.params.y1=i,u.params.x2=r,u.params.y2=n,u.params.x3=o,u.params.y3=h,a.J(u.state),u.id}Ns(t,i,r,n,o,h,a,u,f,g){const d=this.Is(R.BEZIER_CURVE);return d.params.x1=t,d.params.y1=i,d.params.cp1x=r,d.params.cp1y=n,d.params.cp2x=o,d.params.cp2y=h,d.params.x2=a,d.params.y2=u,d.params.thickness=f,g.J(d.state),d.id}get length(){return this.Gs}get isEmpty(){return this.Gs===0}Ys(){this.Gs=0}[Symbol.iterator](){let t=0;const i=this.Gs,r=this.Ds;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const M=class M{static Vs(t,i,r=0){var h,a,u,f,g,d,v,x,p,m;const n=i||new Float32Array(M.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.fs[0],n[o++]=t.fs[1],n[o++]=t.Gs[0],n[o++]=t.Gs[1],n[o++]=t.Y[0],n[o++]=t.Y[1],n[o++]=t.Y[2],n[o++]=t.V[0],n[o++]=t.V[1],n[o++]=t.V[2],n[o++]=t.V[3],n[o++]=t.q[0],n[o++]=t.q[1],n[o++]=t.q[2],n[o++]=t.q[3],n[o++]=t.D[0],n[o++]=t.D[1],n[o++]=t.qs[0],n[o++]=t.qs[1],n[o++]=t.qs[2],n[o++]=t.H,n[o++]=t.K,n[o++]=t.X,n[o++]=t.Zs[0],n[o++]=t.Zs[1],n[o++]=((h=t.Js)==null?void 0:h[0])||0,n[o++]=((a=t.Js)==null?void 0:a[1])||0,n[o++]=((u=t.Qs)==null?void 0:u[0])||0,n[o++]=((f=t.Qs)==null?void 0:f[1])||0,n[o++]=((g=t.te)==null?void 0:g[0])||0,n[o++]=((d=t.te)==null?void 0:d[1])||0,n[o++]=((v=t.se)==null?void 0:v[0])||0,n[o++]=((x=t.se)==null?void 0:x[1])||0,n[o++]=((p=t.ee)==null?void 0:p[0])||0,n[o++]=((m=t.ee)==null?void 0:m[1])||0,n}static ie(t){const i=t.length*M.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*M.FLOATS_PER_INSTANCE;M.Vs(t[n],r,o)}return r}};c(M,"BYTES_PER_INSTANCE",140),c(M,"FLOATS_PER_INSTANCE",35);let D=M;const C=class C{};c(C,"STRIDE",D.BYTES_PER_INSTANCE),c(C,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:C.STRIDE,offset:132,divisor:1}});let q=C;class Et{constructor(t,i=1e3,r=1.5){c(this,"gt");c(this,"re",[]);c(this,"ne");c(this,"oe");c(this,"he",null);c(this,"ae",!0);c(this,"ce",0);c(this,"le",new Map);c(this,"ue",null);this.gt=t,this.ne=i,this.oe=r,this.fe()}ks(t){const i=this.re.length;return this.re.push(t),this.ae=!0,i}get count(){return this.re.length}get isEmpty(){return this.re.length===0}clear(){this.re.length=0,this.ae=!0}de(t){if(t<=this.ne)return;const i=Math.ceil(t*this.oe);this.ne=i,this.fe()}fe(){const t=this.gt;this.he&&t.deleteBuffer(this.he),this.he=t.createBuffer();const i=this.ne*D.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.he),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.ae=!0,this.ce=0}_e(){if(!this.ae||this.re.length===0)return;const t=this.gt,i=this.re.length;this.de(i),(!this.ue||this.ue.length<i*D.FLOATS_PER_INSTANCE)&&(this.ue=new Float32Array(i*D.FLOATS_PER_INSTANCE));const r=D.ie(this.re);t.bindBuffer(t.ARRAY_BUFFER,this.he),i<=this.ce?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.ae=!1,this.ce=i}pe(t){let i=this.le.get(t);if(!i){i=new Map;const r=this.gt;for(const n in q.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.le.set(t,i)}return i}Ms(t){if(!this.he||this.re.length===0)return;const i=this.gt,r=t.Zt;this._e();const n=this.pe(r);i.bindBuffer(i.ARRAY_BUFFER,this.he);for(const[o,h]of n){const a=q.ATTRIBUTES[o];a&&(i.enableVertexAttribArray(h),i.vertexAttribPointer(h,a.size,a.type,a.normalized,a.stride,a.offset),i.vertexAttribDivisor(h,a.divisor))}}Ts(t){const i=this.gt,r=this.pe(t.Zt);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}Rs(t,i){this.re.length!==0&&this.gt.drawArraysInstanced(t,0,i,this.re.length)}Pt(){this.he&&this.gt.deleteBuffer(this.he)}}class z{constructor(t,i,r,n){c(this,"gt");c(this,"me");c(this,"ve");c(this,"ge");c(this,"ye",null);this.gt=t,this.me=i,this.ve=r,this.ge=n;const o=this.gt.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.gt.bindBuffer(this.gt.ARRAY_BUFFER,o),this.gt.bufferData(this.gt.ARRAY_BUFFER,this.ge.Ce,this.gt.STATIC_DRAW),this.gt.bindBuffer(this.gt.ARRAY_BUFFER,null),this.ye=o}get type(){return this.ve}get unitGeometry(){return this.ge}get unitBuffer(){return this.ye}get batch(){return this.me}As(){this.me.clear()}$s(){return!this.me.isEmpty}Pt(){this.me.Pt(),this.gt.deleteBuffer(this.ye)}we(t,i,r,n,o){const h=this.be(t,i,r,n,o.H||0,o.K||0,o.X||0);return{fs:[t,i],Gs:[r,n],Y:o.Y||[0,0,0],V:o.V||[1,1,1,1],q:o.q||[0,0,0,1],D:o.D||[0,0],qs:[o.L?1:0,o.j?1:0,o.N?1:0],H:h.radiansX,K:h.radiansY,X:h.radiansZ,Zs:[h.centerX,h.centerY]}}$e(t,i){const r=V(this.gt)||[0,0,this.gt.canvas.width,this.gt.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}xe(t,i,r){const n=this.$e(i,r);t.Zs=[n.nx,n.ny]}be(t,i,r,n,o,h,a){const u=V(this.gt)||[0,0,this.gt.canvas.width,this.gt.canvas.height],f=u[2],g=u[3];return{centerX:(t+r/2)/f*2-1,centerY:1-(i+n/2)/g*2,radiansX:-o*Math.PI/180,radiansY:-h*Math.PI/180,radiansZ:-a*Math.PI/180,aspectRatio:f/g}}}const wt={Ce: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]),Ss:6,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class Rt extends z{constructor(t,i){super(t,i,R.RECTANGLE,wt)}ks(t,i){const r=this.we(t.x,t.y,t.width,t.height,i);return this.me.ks(r)}}const At={Ce: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]),Ss:6,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class Tt extends z{constructor(t,i){super(t,i,R.LINE,At)}ks(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),h=t.thickness||i.W||1,a=t.x1+r/2,u=t.y1+n/2,f=a-o/2,g=u,d=this.we(f,g,o,h,i);return this.xe(d,a,u),this.me.ks(d)}}const bt={Ce:function(l=32){const t=[],i=2*Math.PI/l;for(let r=0;r<l;r++){const n=r*i,o=(r+1)%l*i,h=Math.cos(n),a=Math.sin(n),u=.5*(h+1),f=.5*(a+1),g=Math.cos(o),d=Math.sin(o),v=.5*(g+1),x=.5*(d+1);t.push(0,0,.5,.5,h,a,u,f,g,d,v,x)}return new Float32Array(t)}(32),Ss:96,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class _t extends z{constructor(t,i){super(t,i,R.ELLIPSE,bt)}ks(t,i){const r=this.we(t.x,t.y,t.width,t.height,i);return this.xe(r,t.x,t.y),this.me.ks(r)}}let Ct={Ce:function(l){const t=[];for(let i=0;i<l;i++){const r=i/l,n=(i+1)/l;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),Ss:96,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class Ut extends z{constructor(t,i){super(t,i,R.ARC,Ct)}ks(t,i){const r=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,h=t.stop*Math.PI/180,a=this.we(r,n,t.width,t.height,i);return this.xe(a,t.x,t.y),a.Js=[o,h],this.me.ks(a)}}const Ft={Ce:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),Ss:3,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class Pt extends z{constructor(t,i){super(t,i,R.TRIANGLE,Ft)}ks(t,i){const r=Math.min(t.x1,t.x2,t.x3),n=Math.max(t.x1,t.x2,t.x3),o=Math.min(t.y1,t.y2,t.y3),h=n-r,a=Math.max(t.y1,t.y2,t.y3)-o,u=this.we(r,o,h,a,i),f=r+.5*h,g=o+a*(1/3);return this.xe(u,f,g),this.me.ks(u)}}function nt(l,t,i,r,n){const o=1-l,h=o*o,a=l*l;return h*o*t+3*h*l*i+3*o*a*r+a*l*n}const Lt={Ce:function(l=16){const t=[];for(let i=0;i<l;i++){const r=i/l,n=(i+1)/l;t.push(r,-.5,r,0),t.push(n,-.5,n,0),t.push(r,.5,r,1),t.push(r,.5,r,1),t.push(n,-.5,n,0),t.push(n,.5,n,1)}return new Float32Array(t)}(16),Ss:96,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class It extends z{constructor(t,i){super(t,i,R.BEZIER_CURVE,Lt)}ks(t,i){const r=i.W||1,n=nt(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=nt(.5,t.y1,t.cp1y,t.cp2y,t.y2),h=this.we(0,0,1,r,i);return this.xe(h,n,o),h.se=[t.x1,t.y1],h.Qs=[t.cp1x,t.cp1y],h.te=[t.cp2x,t.cp2y],h.ee=[t.x2,t.y2],this.me.ks(h)}}class St{constructor(t){c(this,"gt");c(this,"Me",null);c(this,"Re");c(this,"Fe",null);c(this,"Se",{});c(this,"Te",null);c(this,"Ae",new Map);c(this,"ze");c(this,"ke");c(this,"Ee");c(this,"I",[]);this.gt=t,this.Re=new pt(t),this.Ee=new st,this.ze=new yt(t,this),this.ke=new xt,this.Te=t.createBuffer(),H(this.gt,[0,0,this.gt.canvas.width,this.gt.canvas.height])}Pe(t){let i=this.Ae.get(t);if(i)return i;const r=new Et(this.gt);return i=(0,{[R.RECTANGLE]:()=>new Rt(this.gt,r),[R.LINE]:()=>new Tt(this.gt,r),[R.ELLIPSE]:()=>new _t(this.gt,r),[R.ARC]:()=>new Ut(this.gt,r),[R.TRIANGLE]:()=>new Pt(this.gt,r),[R.BEZIER_CURVE]:()=>new It(this.gt,r)}[t])(),this.Ae.set(t,i),i}Le(t){this.Me!==t&&(this.Me=t,t.Ht())}cs(t,i){return this.Re.cs(t,i)}es(){return this.Re.es()}At(){return this.Re.At()}rs(){return this.Re.rs()}ns(){return this.Re.ns()}De(t){this.Fe=t,t&&(this.Se={})}jt(t,i){this.Se[t]=i}Be(t){Object.assign(this.Se,t)}hs(t){return this.Re.hs(t)}Ge(t,i,r,n,o){const h=this.es(),a={Ue:t.textures[0],Uf:t.textures[1],Ug:t.textures[2],Uh:t.textures[3],Ui:t.textures[4],Uj:[t.width,t.height]};this.ke.Ws(i,r,n,o,h,a,this.Ee)}Ie(t,i,r,n,o){const h=this.ns(),a=t.Oe(),u={Uk:a.texture,Ul:!!a.invert,Um:!!a.flipX,Un:!!a.flipY,Uo:a.charRotation,Up:a.charColorFixed,Uq:a.charColor,Ur:a.cellColorFixed,Us:a.cellColor,Ut:a.backgroundColor,Uu:a.charCount,Uv:a.charList};this.ke.Ws(i,r,n,o,h,u,this.Ee)}We(t,i,r,n){var m;const o=this.gt,h=o.canvas.width,a=o.canvas.height,u=t/h*2-1,f=(t+r)/h*2-1,g=1-i/a*2,d=1-(i+n)/a*2,v=new Float32Array([u,d,f,d,u,g,f,d,f,g,u,g]);o.bindBuffer(o.ARRAY_BUFFER,this.Te),o.bufferData(o.ARRAY_BUFFER,v,o.DYNAMIC_DRAW);const x=((m=this.Me)==null?void 0:m.Zt)||o.getParameter(o.CURRENT_PROGRAM),p=x?o.getAttribLocation(x,"a_position"):-1;p!==-1&&(o.enableVertexAttribArray(p),o.vertexAttribPointer(p,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),p!==-1&&o.disableVertexAttribArray(p)}He(t,i,r,n){this.Fe?(this.ke.Ws(t,i,r,n,this.Fe,{...this.Se},this.Ee),this.Fe=null,this.Se={}):this.ke.Os(t,i,r,n,this.Ee)}Ke(t,i,r,n){this.ke.Hs(t,i,r,n,this.Ee.lineWeight,this.Ee)}Xe(t,i,r,n){this.ke.Ks(t,i,r,n,this.Ee)}je(t,i,r,n,o,h){this.ke.js(t,i,r,n,o,h,this.Ee)}Ne(t,i,r,n,o,h,a,u){const f=this.Ee.lineWeight;this.ke.Ns(t,i,r,n,o,h,a,u,f,this.Ee)}Ye(t,i,r=1,n={}){return new $(this.gt,t,i,r,n,this,!0)}Ve(t,i,r,n,o,h){this.ke.Xs(t,i,r,n,o,h,this.Ee)}qe(t,i=t,r=t,n=255){this.Ee.ft(t,i,r,n),this.Ys(t/255,i/255,r/255,n/255)}Ys(t=0,i=0,r=0,n=0){this.gt.clearColor(t,i,r,n),this.gt.clear(this.gt.COLOR_BUFFER_BIT)}Ze(){this.gt.viewport(0,0,this.gt.canvas.width,this.gt.canvas.height),H(this.gt,[0,0,this.gt.canvas.width,this.gt.canvas.height])}get context(){return this.gt}get state(){return this.Ee}kt(t){this.I.push(this.Ee),this.Ee=t}Et(){const t=this.I.pop();t&&(this.Ee=t)}zt(t){const i=t,r=V(this.gt)??this.gt.getParameter(this.gt.VIEWPORT),n={shader:i,gl:this.gt,viewport:r};this.Le(i);const o=new Set;for(const h of this.ke)h.type===R.CUSTOM?o.add(R.RECTANGLE):o.add(h.type);for(const h of o)h!==R.CUSTOM&&this.Pe(h);this.ze.bs(n,this.ke,this.Ae),this.ke.Ys()}Pt(){this.gt.deleteBuffer(this.Te),this.ke.Ys();for(const t of this.Ae.values())t.Pt();this.Re.Pt(),this.ze.Pt()}}const _={readShort:(l,t)=>(_.t.uint16[0]=l[t]<<8|l[t+1],_.t.int16[0]),readUshort:(l,t)=>l[t]<<8|l[t+1],readUshorts(l,t,i){const r=[];for(let n=0;n<i;n++)r.push(_.readUshort(l,t+2*n));return r},readUint(l,t){const i=_.t.uint8;return i[3]=l[t],i[2]=l[t+1],i[1]=l[t+2],i[0]=l[t+3],_.t.uint32[0]},readASCII(l,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(l[t+n]);return r},writeUshort(l,t,i){l[t]=i>>>8&255,l[t+1]=255&i},writeUint(l,t,i){l[t]=i>>>24&255,l[t+1]=i>>>16&255,l[t+2]=i>>>8&255,l[t+3]=255&i},writeASCII(l,t,i){for(let r=0;r<i.length;r++)l[t+r]=255&i.charCodeAt(r)},t:(()=>{const l=new ArrayBuffer(8);return{uint8:new Uint8Array(l),int16:new Int16Array(l),uint16:new Uint16Array(l),uint32:new Uint32Array(l)}})()};function j(l){return l+3&-4}function Q(l,t,i){const r=t+i;let n=0;const o=_.t;for(let h=t;h<r;h+=4)o.uint8[3]=l[h]||0,o.uint8[2]=l[h+1]||0,o.uint8[1]=l[h+2]||0,o.uint8[0]=l[h+3]||0,n=n+(o.uint32[0]>>>0)>>>0;return n>>>0}class Mt{constructor(t){c(this,"b");c(this,"p",0);c(this,"bitbuf",0);c(this,"bitcnt",0);this.b=t}readBits(t){for(;this.bitcnt<t;){const r=this.b[this.p++]||0;this.bitbuf|=r<<this.bitcnt,this.bitcnt+=8}const i=this.bitbuf&(1<<t)-1;return this.bitbuf>>>=t,this.bitcnt-=t,i}alignToByte(){this.bitbuf=0,this.bitcnt=0}get offset(){return this.p}}function X(l){let t=32,i=0;for(const a of l)a&&(a<t&&(t=a),a>i&&(i=a));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const a of l)a&&r[a]++;const n=new Uint32Array(i+1);let o=0;r[0]=0;for(let a=1;a<=i;a++)o=o+r[a-1]<<1,n[a]=o;const h=new Map;for(let a=0;a<l.length;a++){const u=l[a];if(!u)continue;const f=n[u]++;let g=h.get(u);g||(g=[],h.set(u,g)),g[Gt(f,u)]=a}return{min:t,max:i,table:h}}function tt(l,t){let i=0;for(let r=1;r<=t.max;r++){i|=l.readBits(1)<<r-1;const n=t.table.get(r);if(n&&i<n.length){const o=n[i];if(o!==void 0)return o}}throw Error("Invalid Huffman code")}function Gt(l,t){let i=0;for(let r=0;r<t;r++)i=i<<1|1&l,l>>>=1;return i>>>0}function Dt(l){if(l.length<2)throw Error("ZLIB data too short");const t=l[0],i=l[1];if((15&t)!=8)throw Error("Unsupported ZLIB compression method");if(((t<<8)+i)%31!=0)throw Error("Bad ZLIB header check");let r=2;32&i&&(r+=4);const n=[];return function(o,h){const a=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],u=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],f=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],g=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];let d=0;for(;!d;){d=o.readBits(1);const v=o.readBits(2);if(v===0){o.alignToByte();const x=o.readBits(16);if((65535&(65535^x))!==o.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let p=0;p<x;p++)h.push(o.readBits(8))}else{if(v!==1&&v!==2)throw Error("Unsupported DEFLATE type");{let x,p;if(v===1){const m=Array(288).fill(0);for(let E=0;E<=143;E++)m[E]=8;for(let E=144;E<=255;E++)m[E]=9;for(let E=256;E<=279;E++)m[E]=7;for(let E=280;E<=287;E++)m[E]=8;x=X(m),p=X(Array(32).fill(5))}else{const m=o.readBits(5)+257,E=o.readBits(5)+1,y=o.readBits(4)+4,A=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],w=Array(19).fill(0);for(let L=0;L<y;L++)w[A[L]]=o.readBits(3);const P=X(w),U=[];for(;U.length<m+E;){const L=tt(o,P);if(L<=15)U.push(L);else if(L===16){const Y=o.readBits(2)+3,O=U[U.length-1]||0;for(let mt=0;mt<Y;mt++)U.push(O)}else if(L===17){const Y=o.readBits(3)+3;for(let O=0;O<Y;O++)U.push(0)}else{if(L!==18)throw Error("Invalid code length symbol");{const Y=o.readBits(7)+11;for(let O=0;O<Y;O++)U.push(0)}}}const F=U.slice(0,m),I=U.slice(m,m+E);x=X(F),p=X(I)}for(;;){const m=tt(o,x);if(m<256)h.push(m);else{if(m===256)break;if(m>256&&m<286){const E=m-257;let y=a[E];const A=u[E];A&&(y+=o.readBits(A));const w=tt(o,p);if(w>=30)throw Error("Invalid distance symbol");let P=f[w];const U=g[w];U&&(P+=o.readBits(U));const F=h.length-P;if(F<0)throw Error("Invalid distance");for(let I=0;I<y;I++)h.push(h[F+I]||0)}else if(m===286||m===287)throw Error("Reserved length symbol")}}}}}}(new Mt(l.subarray(r)),n),new Uint8Array(n)}function Bt(l){const t=_,i=new Uint8Array(l);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),n=t.readUshort(i,12),o=t.readUint(i,16),h=[];let a=44;for(let y=0;y<n;y++){const A=t.readASCII(i,a,4),w=t.readUint(i,a+4),P=t.readUint(i,a+8),U=t.readUint(i,a+12),F=t.readUint(i,a+16);h.push({tag:A,offset:w,compLength:P,origLength:U,checksum:F}),a+=20}for(const y of h){const A=new Uint8Array(i.buffer,y.offset,y.compLength);if(y.compLength===y.origLength)y.data=new Uint8Array(A);else if(y.data=Dt(A),y.data.length!==y.origLength)if(y.data.length<y.origLength){const w=new Uint8Array(y.origLength);w.set(y.data),y.data=w}else y.data=y.data.subarray(0,y.origLength)}const u=n;let f=1,g=0;for(;f<<1<=u;)f<<=1,g++;const d=16*f,v=16*u-d;let x=12+16*u;const p={};for(const y of h)p[y.tag]=x,x=j(x+y.data.length);const m=new Uint8Array(Math.max(o||0,x));t.writeUint(m,0,r),t.writeUshort(m,4,u),t.writeUshort(m,6,d),t.writeUshort(m,8,g),t.writeUshort(m,10,v);let E=12;for(const y of h){t.writeASCII(m,E,y.tag),E+=4;let A=y.data;if(y.tag==="head"&&A.length>=12){const w=new Uint8Array(A);t.writeUint(w,8,0);const P=Q(w,0,j(w.length));t.writeUint(m,E,P),E+=4}else{const w=Q(A,0,j(A.length));t.writeUint(m,E,w),E+=4}t.writeUint(m,E,p[y.tag]),E+=4,t.writeUint(m,E,y.data.length),E+=4}for(const y of h){const A=p[y.tag];m.set(y.data,A)}if(h.find(y=>y.tag==="head")){const y=p.head,A=function(w,P){const U=_,F=P+8,I=[w[F],w[F+1],w[F+2],w[F+3]];U.writeUint(w,F,0);const L=2981146554-(Q(w,0,j(w.length))>>>0)>>>0;return w[F]=I[0],w[F+1]=I[1],w[F+2]=I[2],w[F+3]=I[3],L>>>0}(m,y);t.writeUint(m,y+8,A)}return m.buffer}const Ot={parseTab(l,t,i){const r={tables:[],ids:{},off:t};l=new Uint8Array(l.buffer,t,i),t=0;const n=_,o=n.readUshort,h=o(l,t+=2);t+=2;const a=[];for(let u=0;u<h;u++){const f=o(l,t),g=o(l,t+=2);t+=2;const d=n.readUint(l,t);t+=4;const v=`p${f}e${g}`;let x=a.indexOf(d);if(x===-1){let p;x=r.tables.length,a.push(d);const m=o(l,d);p=m===4?this.parse4(l,d):m===12?this.parse12(l,d):{format:m},r.tables.push(p)}r.ids[v]=x}return r},parse4(l,t){const i=_,r=i.readUshort,n=i.readUshorts,o=t,h=r(l,t+=2);t+=2;const a=r(l,t+=2)>>>1,u={format:4,searchRange:r(l,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,u.entrySelector=r(l,t),t+=2,u.rangeShift=r(l,t),t+=2,u.endCount=n(l,t,a),t+=2*a,t+=2,u.startCount=n(l,t,a),t+=2*a;for(let f=0;f<a;f++)u.idDelta.push(i.readShort(l,t)),t+=2;return u.idRangeOffset=n(l,t,a),t+=2*a,u.glyphIdArray=n(l,t,o+h-t>>1),u},parse12(l,t){const i=_.readUint;i(l,t+=4),i(l,t+=4);const r=i(l,t+=4);t+=4;const n=new Uint32Array(3*r);for(let o=0;o<3*r;o+=3)n[o]=i(l,t+(o<<2)),n[o+1]=i(l,t+(o<<2)+4),n[o+2]=i(l,t+(o<<2)+8);return{format:12,groups:n}}},kt={parseTab(l,t,i){const r=_;t+=18;const n=r.readUshort(l,t);t+=2,t+=16;const o=r.readShort(l,t);t+=2;const h=r.readShort(l,t);t+=2;const a=r.readShort(l,t);t+=2;const u=r.readShort(l,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:h,xMax:a,yMax:u,indexToLocFormat:r.readShort(l,t)}}},zt={parseTab(l,t,i){const r=_;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let h=0;h<n.length;h++){const a=n[h],u=a==="advanceWidthMax"||a==="numberOfHMetrics"?r.readUshort:r.readShort;o[a]=u(l,t+2*h)}return o}},Nt={parseTab(l,t,i,r){const n=_,o=[],h=[],a=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,g=0,d=0;for(;d<u;)f=n.readUshort(l,t+(d<<2)),g=n.readShort(l,t+(d<<2)+2),o.push(f),h.push(g),d++;for(;d<a;)o.push(f),h.push(g),d++;return{aWidth:o,lsBearing:h}}},ot={cmap:Ot,head:kt,hhea:zt,maxp:{parseTab(l,t,i){const r=_;return r.readUint(l,t),t+=4,{numGlyphs:r.readUshort(l,t)}}},hmtx:Nt,loca:{parseTab(l,t,i,r){const n=_,o=[],h=r.head.indexToLocFormat,a=r.maxp.numGlyphs+1;if(h===0)for(let u=0;u<a;u++)o.push(n.readUshort(l,t+(u<<1))<<1);else if(h===1)for(let u=0;u<a;u++)o.push(n.readUint(l,t+(u<<2)));return o}},glyf:{parseTab(l,t,i,r){const n=[],o=r.maxp.numGlyphs;for(let h=0;h<o;h++)n.push(null);return n},Je(l,t){const i=_,r=l.Qe,n=l.loca;if(n[t]===n[t+1])return null;const o=S.findTable(r,"glyf",l.ti);if(!o)return null;let h=o[0]+n[t];const a={};if(a.noc=i.readShort(r,h),h+=2,a.xMin=i.readShort(r,h),h+=2,a.yMin=i.readShort(r,h),h+=2,a.xMax=i.readShort(r,h),h+=2,a.yMax=i.readShort(r,h),h+=2,a.xMin>=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(let v=0;v<a.noc;v++)a.endPts.push(i.readUshort(r,h)),h+=2;const u=i.readUshort(r,h);if(h+=2,r.length-h<u)return null;h+=u;const f=a.endPts[a.noc-1]+1;a.flags=[];for(let v=0;v<f;v++){const x=r[h];if(h++,a.flags.push(x),8&x){const p=r[h];h++;for(let m=0;m<p;m++)a.flags.push(x),v++}}a.xs=[];for(let v=0;v<f;v++){const x=a.flags[v],p=!!(16&x);2&x?(a.xs.push(p?r[h]:-r[h]),h++):p?a.xs.push(0):(a.xs.push(i.readShort(r,h)),h+=2)}a.ys=[];for(let v=0;v<f;v++){const x=a.flags[v],p=!!(32&x);4&x?(a.ys.push(p?r[h]:-r[h]),h++):p?a.ys.push(0):(a.ys.push(i.readShort(r,h)),h+=2)}let g=0,d=0;for(let v=0;v<f;v++)g+=a.xs[v],d+=a.ys[v],a.xs[v]=g,a.ys[v]=d}else a.parts=[],a.endPts=[],a.flags=[],a.xs=[],a.ys=[];return a}}},S={parse(l){const t=new Uint8Array(l),i=_.readASCII(t,0,4);if(i==="wOFF")l=Bt(l);else if(i==="wOF2")throw Error("WOFF2 is not supported in this build (Brotli + WOFF2 transforms required)");return[((r,n,o,h)=>{const a=ot,u={Qe:r,si:n,ti:o};for(const f in a){const g=f,d=S.findTable(r,g,o);if(d){const[v,x]=d;let p=h[v];p==null&&(p=a[g].parseTab(r,v,x,u),h[v]=p),u[g]=p}}return u})(new Uint8Array(l),0,0,{})]},findTable(l,t,i){const r=_,n=r.readUshort(l,i+4);let o=i+12;for(let h=0;h<n;h++){const a=r.readASCII(l,o,4);r.readUint(l,o+4);const u=r.readUint(l,o+8),f=r.readUint(l,o+12);if(a===t)return[u,f];o+=16}return null},T:ot,B:_};class Wt{ei(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ii(n);i.push(...o)}else if(n.format===12){const o=this.ri(n);i.push(...o)}}),[...new Set(i)]):[]}ni(t){return t.filter(i=>this.oi(i))}ii(t){const i=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return i;for(let r=0;r<t.startCount.length;r++){const n=t.startCount[r],o=t.endCount[r];if(n!==65535||o!==65535){for(let h=n;h<=o;h++)if(this.hi(t,h,r)>0)try{const a=String.fromCodePoint(h);i.push(a)}catch{}}}return i}ri(t){const i=[];if(!t.groups)return i;for(let r=0;r<t.groups.length;r+=3){const n=t.groups[r],o=t.groups[r+1],h=t.groups[r+2];for(let a=n;a<=o;a++)if(h+(a-n)>0)try{const u=String.fromCodePoint(a);i.push(u)}catch{}}return i}hi(t,i,r){if(t.idRangeOffset[r]===0)return i+t.idDelta[r]&65535;{const n=t.idRangeOffset[r]/2+(i-t.startCount[r])-(t.startCount.length-r);if(n>=0&&t.glyphIdArray&&n<t.glyphIdArray.length){const o=t.glyphIdArray[n];if(o!==0)return o+t.idDelta[r]&65535}}return 0}oi(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class et{constructor(){c(this,"ai",new Map);c(this,"ci",new Map)}li(t,i){const r=`${this.ui(t)}_${i}`;if(this.ai.has(r))return this.ai.get(r);const n=t.cmap;if(!n||!n.tables)return this.ai.set(r,0),0;let o=0;for(const h of n.tables)if(h.format===4?o=this.fi(i,h):h.format===12&&(o=this.di(i,h)),o>0)break;return this.ai.set(r,o),o}_i(t,i){const r=i.codePointAt(0);return r===void 0?0:this.li(t,r)}pi(t,i){const r=t.hmtx;return r&&r.aWidth&&r.aWidth.length!==0?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}mi(t,i){const r=i/t.head.unitsPerEm,n=t.hhea.ascender*r,o=t.hhea.descender*r,h=t.hhea.lineGap*r;return{ascender:n,descender:o,lineGap:h,lineHeight:n-o+h,unitsPerEm:t.head.unitsPerEm,scale:r}}gi(){this.ai.clear(),this.ci.clear()}ui(t){return`${t.ti}_${t.Qe.length}`}fi(t,i){const r=i.endCount.length;let n=-1;for(let o=0;o<r;o++)if(t<=i.endCount[o]){n=o;break}if(n===-1||t<i.startCount[n])return 0;if(i.idRangeOffset[n]===0)return t+i.idDelta[n]&65535;{const o=i.idRangeOffset[n]/2+(t-i.startCount[n])-(r-n);if(o>=0&&o<i.glyphIdArray.length){const h=i.glyphIdArray[o];return h===0?0:h+i.idDelta[n]&65535}}return 0}di(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const o=i.groups[3*n],h=i.groups[3*n+1],a=i.groups[3*n+2];if(t>=o&&t<=h)return a+(t-o)}return 0}}class Xt{constructor(t){c(this,"yi");c(this,"Ci");c(this,"xt");c(this,"wi");this.xt=t,this.wi=new et,this.yi=document.createElement("canvas"),this.Ci=this.yi.getContext("2d",{willReadFrequently:!0,alpha:!0})}createTextureAtlas(t,i,r,n){const o=t.length,h=Math.ceil(Math.sqrt(o)),a=Math.ceil(o/h),u=i.width*h,f=i.height*a,g=typeof n=="object"?n:null;this.bi(u,f),this.$i(t,i,h,r,g);const d=this.xt.Ye(u,f,1,{filter:"nearest"});return d.Tt(this.yi),{framebuffer:d,columns:h,rows:a}}bi(t,i){this.yi.width=t,this.yi.height=i,this.yi.style.width=t+"px",this.yi.style.height=i+"px",this.Ci.imageSmoothingEnabled=!1,this.yi.style.imageRendering="pixelated",this.Ci.clearRect(0,0,t,i),this.Ci.textBaseline="top",this.Ci.textAlign="left",this.Ci.fillStyle="white"}$i(t,i,r,n,o){const h=n/o.head.unitsPerEm;for(let a=0;a<t.length;a++){const u=a%r,f=Math.floor(a/r),g=t[a].character,d=this.xi(o,g);if(!d)continue;const v=g.codePointAt(0)||0,x=this.wi.li(o,v),p=this.Mi(o,x)*h,m=u*i.width,E=f*i.height,y=m+.5*i.width,A=E+.5*i.height,w=Math.round(y-.5*i.width),P=Math.round(A-.5*n),U=w+.5*(i.width-p),F=P+o.hhea.ascender*h;this.Ri(d,U,F,h)}}xi(t,i){const r=i.codePointAt(0)||0,n=this.wi.li(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(S&&S.T&&S.T.glyf){const o=S.T.glyf.Je(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}Mi(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}Ri(t,i,r,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:h,endPts:a,flags:u}=t;if(!(o&&h&&a&&u))return;this.Ci.beginPath();let f=0;for(let g=0;g<a.length;g++){const d=a[g];if(!(d<f)){if(d>=f){const v=i+o[f]*n,x=r-h[f]*n;this.Ci.moveTo(v,x);let p=f+1;for(;p<=d;)if(1&u[p]){const m=i+o[p]*n,E=r-h[p]*n;this.Ci.lineTo(m,E),p++}else{const m=i+o[p]*n,E=r-h[p]*n;let y=p+1>d?f:p+1;if(1&u[y]){const A=i+o[y]*n,w=r-h[y]*n;this.Ci.quadraticCurveTo(m,E,A,w),p=y+1}else{const A=(m+(i+o[y]*n))/2,w=(E+(r-h[y]*n))/2;this.Ci.quadraticCurveTo(m,E,A,w),p=y}}this.Ci.closePath()}f=d+1}}this.Ci.fill()}}class Yt{constructor(){c(this,"Fi");this.Fi=new et}Si(t,i,r){let n=0;const o=this.Fi.mi(r,i),h=o.lineHeight;for(const a of t){const u=this.Fi._i(r,a);if(u===0)continue;const f=this.Fi.pi(r,u)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(h)}}gi(){this.Fi.gi()}}class Ht{constructor(){c(this,"wi");this.wi=new et}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,h=this.Ti(n);let a=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.wi.li(i,o);u>0&&i.hmtx.aWidth[u]!==void 0&&(a=i.hmtx.aWidth[u])}return{character:r,unicode:o,color:h,advanceWidth:a}})}Ti(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}Ai(t,i){if(!W.v(typeof t=="string","Character must be a string.",{method:"getCharacterColor",providedValue:t}))return[0,0,0];const r=i.find(n=>n.character===t);return r?r.color:[0,0,0]}zi(t,i){return W.v(typeof t=="string"&&t.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:t})?Array.from(t).map(r=>this.Ai(r,i)||[0,0,0]):[[0,0,0]]}}class ht{constructor(t,i=16){c(this,"ki");c(this,"Ei",[]);c(this,"Pi");c(this,"Li",16);c(this,"Di",0);c(this,"Bi",0);c(this,"Gi",{width:0,height:0});c(this,"Ii");c(this,"Oi",new Map);c(this,"Wi");c(this,"Hi");c(this,"Ki");c(this,"Xi");this.Li=i,this.Wi=new Wt,this.Hi=new Xt(t),this.Ki=new Yt,this.Xi=new Ht}async ji(t){let i;if(!t)throw new T("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const r=await fetch(t);if(!r.ok)throw new T(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}await this.Ni(i),this.ki=S.parse(i)[0],await this.Yi()}Vi(t){if(t===void 0)return this.Li;this.Li=t,this.Gi=this.Ki.Si(this.Ei.map(r=>r.character),this.Li,this.ki);const i=this.Hi.createTextureAtlas(this.Ei,this.Gi,this.Li,this.ki);this.Pi=i.framebuffer,this.Di=i.columns,this.Bi=i.rows}async qi(t){try{const i=await fetch(t);if(!i.ok)throw new T(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.Ni(r);const n=S.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.ki=n[0],await this.Yi()}catch(i){throw new T("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async Ni(t){const i=Date.now();this.Ii=new FontFace("CustomFont_"+i,t),await this.Ii.load(),document.fonts.add(this.Ii)}async Yi(){const t=this.Wi.ei(this.ki),i=this.Wi.ni(t);this.Oi.clear(),this.Ei=this.Xi.createCharacterObjects(i,this.ki),this.Gi=this.Ki.Si(i,this.Li,this.ki);const r=this.Hi.createTextureAtlas(this.Ei,this.Gi,this.Li,this.ki);this.Pi=r.framebuffer,this.Di=r.columns,this.Bi=r.rows}Ai(t){return this.Xi.Ai(t,this.Ei)}zi(t){return this.Xi.zi(t,this.Ei)}getGlyphData(t){if(!Number.isFinite(t))return null;const i=this.Oi.get(t);if(i!==void 0)return i;const r=this.Zi(t);if(r<0)return this.Oi.set(t,null),null;const n=this.ki.glyf;if(!n)return this.Oi.set(t,null),null;let o=n[r]??null;return o==null&&(o=S.T.glyf.Je(this.ki,r)??null,n[r]=o),this.Oi.set(t,o),o}Zi(t){const i=this.ki.cmap;for(const r of i.tables)if(r.format===4){const n=r;for(let o=0;o<n.startCount.length;o++)if(t>=n.startCount[o]&&t<=n.endCount[o]){if(n.idRangeOffset[o]===0)return t+n.idDelta[o]&65535;{const h=n.idRangeOffset[o]/2+(t-n.startCount[o])-(n.startCount.length-o);if(h>=0&&h<n.glyphIdArray.length){const a=n.glyphIdArray[h];if(a!==0)return a+n.idDelta[o]&65535}}}}else if(r.format===12){const n=r;for(let o=0;o<n.groups.length;o+=3){const h=n.groups[o],a=n.groups[o+1],u=n.groups[o+2];if(t>=h&&t<=a)return u+(t-h)}}return 0}Pt(){this.Pi.Pt(),document.fonts.delete(this.Ii)}get fontFramebuffer(){return this.Pi}get characters(){return this.Ei}get textureColumns(){return this.Di}get textureRows(){return this.Bi}get maxGlyphDimensions(){return this.Gi}get fontSize(){return this.Li}get font(){return this.ki}}class at{constructor(t,i,r){c(this,"Ji");c(this,"Qi");c(this,"dt");c(this,"_t");c(this,"tr");c(this,"sr");c(this,"er");c(this,"ir");c(this,"rr");this.er=t,this.ir=i,this.rr=r,this.nr()}nr(){this.Ji=Math.floor(this.er.width/this.ir),this.Qi=Math.floor(this.er.height/this.rr),this.dt=this.Ji*this.ir,this._t=this.Qi*this.rr,this.tr=Math.floor((this.er.width-this.dt)/2),this.sr=Math.floor((this.er.height-this._t)/2)}hr(t,i){this.ir=t,this.rr=i,this.nr()}get cellWidth(){return this.ir}get cellHeight(){return this.rr}get cols(){return this.Ji}get rows(){return this.Qi}get width(){return this.dt}get height(){return this._t}get offsetX(){return this.tr}get offsetY(){return this.sr}}class ct{constructor(t={}){c(this,"er");c(this,"ar",null);c(this,"cr",!1);c(this,"lr");c(this,"ur");this.cr=t.overlay??!1,this.cr&&t.canvas?(this.ar=t.canvas,this.er=this.dr(),this.ur=!0,this._r()):t.canvas?(this.er=t.canvas,this.ur=!1):(this.er=this.pr(t.width,t.height),this.ur=!0),this.er.style.imageRendering="pixelated"}pr(t,i){const r=document.createElement("canvas");return r.className="textmodeCanvas",r.style.imageRendering="pixelated",r.width=t||800,r.height=i||600,document.body.appendChild(r),r}dr(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.ar.getBoundingClientRect();let r=Math.round(i.width),n=Math.round(i.height);if(this.ar instanceof HTMLVideoElement){const a=this.ar;(r===0||n===0)&&a.videoWidth>0&&a.videoHeight>0&&(r=a.videoWidth,n=a.videoHeight)}t.width=r,t.height=n,t.style.position="absolute",t.style.pointerEvents="none";const o=window.getComputedStyle(this.ar);let h=parseInt(o.zIndex||"0",10);return isNaN(h)&&(h=0),t.style.zIndex=""+(h+1),t}_r(){var t;this.mr(),(t=this.ar.parentNode)==null||t.insertBefore(this.er,this.ar.nextSibling),window.ResizeObserver&&(this.lr=new ResizeObserver(()=>{this.vr()}),this.lr.observe(this.ar)),window.addEventListener("resize",()=>{this.vr()})}mr(){if(!this.ar)return;const t=this.ar.getBoundingClientRect();let i=this.ar.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.er.style.top=t.top-r.top+"px",this.er.style.left=t.left-r.left+"px"}else this.er.style.top=t.top+window.scrollY+"px",this.er.style.left=t.left+window.scrollX+"px"}vr(t,i){if(this.cr){const r=this.ar.getBoundingClientRect();let n=Math.round(r.width),o=Math.round(r.height);if(this.ar instanceof HTMLVideoElement){const h=this.ar;(n===0||o===0)&&h.videoWidth>0&&h.videoHeight>0&&(n=h.videoWidth,o=h.videoHeight)}this.er.width=n,this.er.height=o,this.mr()}else this.er.width=t??this.er.width,this.er.height=i??this.er.height}gr(){const t=this.er.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new T("`textmode.js` requires WebGL2 support.");return t}Pt(){this.lr&&this.lr.disconnect();const t=this.er.getContext("webgl")||this.er.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.ur&&this.er.parentNode&&this.er.parentNode.removeChild(this.er)}get canvas(){return this.er}get targetCanvas(){return this.ar}get width(){return this.er.width}get height(){return this.er.height}}class N{constructor(t,i,r,n){c(this,"yr");c(this,"dt");c(this,"_t");c(this,"gt");c(this,"L",0);c(this,"j",0);c(this,"N",0);c(this,"D",[0,0]);c(this,"Cr","sampled");c(this,"wr","fixed");c(this,"V",[1,1,1,1]);c(this,"q",[0,0,0,1]);c(this,"br",[0,0,0,1]);c(this,"$r",[[.1,0,0]]);c(this,"Mr");this.gt=t,this.yr=i,this.dt=r,this._t=n}Pt(){this.gt.deleteTexture(this.yr)}Rr(t){return typeof t=="boolean"?t?1:0:(t==null?0:Number(t))>0?1:0}invert(t=!0){return this.L=this.Rr(t),this}flipX(t=!0){return this.j=this.Rr(t),this}flipY(t=!0){return this.N=this.Rr(t),this}charRotation(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));return this.D=[r,n],this}Oe(){return{texture:this.yr,invert:this.L,flipX:this.j,flipY:this.N,charRotation:this.D,charColorFixed:this.Cr==="fixed",charColor:this.V,cellColorFixed:this.wr==="fixed",cellColor:this.q,backgroundColor:this.br,charCount:this.$r.length,charList:this.$r}}charColorMode(t){return this.Cr=t,this}cellColorMode(t){return this.wr=t,this}charColor(t,i,r,n){return this.V=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}cellColor(t,i,r,n){return this.q=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}background(t,i,r,n){return this.br=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}characters(t){const i=this.Mr(t).filter(r=>Array.isArray(r)).slice(0,64);return this.$r=i,this}static Fr(t,i,r){const n=t.context,o=n.createTexture();n.bindTexture(n.TEXTURE_2D,o),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,1),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),n.bindTexture(n.TEXTURE_2D,null);const h=i.naturalWidth??i.width??i.videoWidth??0,a=i.naturalHeight??i.height??i.videoHeight??0,u=new N(n,o,h,a);return u.Mr=r,u}get texture(){return this.yr}get width(){return this.dt}get height(){return this._t}}class Vt{constructor(t=60){c(this,"Sr");c(this,"Tr");c(this,"Ar",null);c(this,"zr",0);c(this,"kr",!0);c(this,"Er",0);c(this,"Pr",0);c(this,"Lr",[]);c(this,"Dr",10);c(this,"Br",0);this.Sr=t,this.Tr=1e3/t}start(t){if(!this.kr)return;this.zr=performance.now();const i=r=>{if(!this.kr)return void(this.Ar=null);const n=r-this.zr;n>=this.Tr&&(t(),this.zr=r-n%this.Tr),this.kr&&(this.Ar=requestAnimationFrame(i))};this.Ar=requestAnimationFrame(i)}stop(){this.Ar&&(cancelAnimationFrame(this.Ar),this.Ar=null)}pause(){this.kr&&(this.kr=!1,this.stop())}resume(t){this.kr||(this.kr=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.Er;this.Sr=t,this.Tr=1e3/t,this.kr&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.Pr>0){const i=t-this.Pr;this.Lr.push(i),this.Lr.length>this.Dr&&this.Lr.shift();const r=this.Lr.reduce((n,o)=>n+o,0)/this.Lr.length;this.Er=1e3/r}this.Pr=t}get isLooping(){return this.kr}get frameRateLimit(){return this.Sr}get currentFrameRate(){return this.Er}get frameCount(){return this.Br}set frameCount(t){this.Br=t}incrementFrame(){this.Br++}resetFrameCount(){this.Br=0}}class lt{constructor(t){c(this,"er");c(this,"Gr");c(this,"Ir",{x:-1,y:-1});c(this,"Or",{x:-1,y:-1});c(this,"Wr",null);c(this,"Hr",0);c(this,"Kr");c(this,"Xr");c(this,"jr");c(this,"Nr");c(this,"Yr");c(this,"Vr");c(this,"qr",!1);c(this,"Zr");c(this,"Jr");c(this,"Qr");c(this,"tn");c(this,"sn");this.er=t}en(t){const i=performance.now()+Math.max(0,t);i>this.Hr&&(this.Hr=i)}rn(){return performance.now()<this.Hr}nn(t){const i=this.er.canvas;i.style.cursor=t==null||t===""?"":t}ji(t){this.Gr=t,this.hn()}an(){if(this.qr)return;const t=this.er.canvas;this.Kr=i=>{this.cn(i),this.ln(i)},this.Xr=()=>{this.Or={...this.Ir},this.Ir.x=-1,this.Ir.y=-1,this.Wr=null},this.jr=i=>{this.cn(i),this.un(i)},this.Nr=i=>{this.cn(i),this.fn(i)},this.Yr=i=>{this.cn(i),this.dn(i)},this.Vr=i=>{this.cn(i),this._n(i)},t.addEventListener("mousemove",this.Kr,{passive:!0}),t.addEventListener("mouseleave",this.Xr,{passive:!0}),t.addEventListener("mousedown",this.jr,{passive:!0}),t.addEventListener("mouseup",this.Nr,{passive:!0}),t.addEventListener("click",this.Yr,{passive:!0}),t.addEventListener("wheel",this.Vr,{passive:!1}),this.qr=!0}pn(){if(!this.qr)return;const t=this.er.canvas;t.removeEventListener("mousemove",this.Kr),t.removeEventListener("mouseleave",this.Xr),t.removeEventListener("mousedown",this.jr),t.removeEventListener("mouseup",this.Nr),t.removeEventListener("click",this.Yr),t.removeEventListener("wheel",this.Vr),this.qr=!1}hn(){if(this.qr)try{if(this.Wr){const t=new MouseEvent("mousemove",{clientX:this.Wr.x,clientY:this.Wr.y,bubbles:!1,cancelable:!1});this.cn(t)}else this.Ir.x!==-1&&this.Ir.y!==-1&&(this.Ir.x>=this.Gr.cols||this.Ir.y>=this.Gr.rows)&&(this.Ir.x=-1,this.Ir.y=-1)}catch{this.Ir.x=-1,this.Ir.y=-1}}mn(t){this.Zr=t}vn(t){this.Jr=t}gn(t){this.Qr=t}yn(t){this.tn=t}Cn(t){this.sn=t}wn(){return{x:this.Ir.x,y:this.Ir.y}}ln(t){if(this.tn&&!this.rn()){const i={position:{...this.Ir},previousPosition:{...this.Or},originalEvent:t};this.tn(i)}}un(t){if(this.Jr&&!this.rn()){const i={position:{...this.Ir},previousPosition:{...this.Or},button:t.button,originalEvent:t};this.Jr(i)}}fn(t){if(this.Qr&&!this.rn()){const i={position:{...this.Ir},previousPosition:{...this.Or},button:t.button,originalEvent:t};this.Qr(i)}}dn(t){if(this.Zr&&!this.rn()){const i={position:{...this.Ir},previousPosition:{...this.Or},button:t.button,originalEvent:t};this.Zr(i)}}_n(t){if(this.sn&&!this.rn()){const i={position:{...this.Ir},previousPosition:{...this.Or},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.sn(i)}}cn(t){const i=this.er.canvas;this.Or={...this.Ir},this.Wr={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,o=t.clientY-r.top,h=i.width/r.width,a=o*(i.height/r.height),u=n*h-this.Gr.offsetX,f=a-this.Gr.offsetY,g=Math.floor(u/this.Gr.cellWidth),d=Math.floor(f/this.Gr.cellHeight);g>=0&&g<this.Gr.cols&&d>=0&&d<this.Gr.rows?(this.Ir.x=g,this.Ir.y=d):(this.Ir.x=-1,this.Ir.y=-1)}}const $t=Object.freeze(Object.defineProperty({__proto__:null,MouseManager:lt},Symbol.toStringTag,{value:"Module"}));class ut{constructor(){c(this,"bn",new Map);c(this,"$n",null);c(this,"xn",null);c(this,"Mn");c(this,"Rn");c(this,"qr",!1);c(this,"Fn");c(this,"Sn");c(this,"Tn",{ArrowUp:"UP_ARROW",ArrowDown:"DOWN_ARROW",ArrowLeft:"LEFT_ARROW",ArrowRight:"RIGHT_ARROW",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",Enter:"ENTER",Return:"RETURN",Tab:"TAB",Escape:"ESCAPE",Backspace:"BACKSPACE",Delete:"DELETE",Insert:"INSERT",Home:"HOME",End:"END",PageUp:"PAGE_UP",PageDown:"PAGE_DOWN",Shift:"SHIFT",Control:"CONTROL",Alt:"ALT",Meta:"META"," ":"SPACE"})}an(){this.qr||(this.Mn=t=>{this.An(t)},this.Rn=t=>{this.zn(t)},window.addEventListener("keydown",this.Mn,{passive:!1}),window.addEventListener("keyup",this.Rn,{passive:!1}),this.qr=!0)}pn(){this.qr&&(window.removeEventListener("keydown",this.Mn),window.removeEventListener("keyup",this.Rn),this.qr=!1,this.bn.clear(),this.$n=null,this.xn=null)}vn(t){this.Fn=t}gn(t){this.Sn=t}kn(t){const i=this.En(t),r=this.bn.get(t)||this.bn.get(i);return(r==null?void 0:r.isPressed)||!1}Pn(){return this.$n}Ln(){return this.xn}Dn(){const t=[];for(const[i,r]of this.bn)r.isPressed&&t.push(i);return t}Bn(){return{ctrl:this.kn("Control"),shift:this.kn("Shift"),alt:this.kn("Alt"),meta:this.kn("Meta")}}Gn(){this.bn.clear(),this.$n=null,this.xn=null}An(t){const i=t.key,r=Date.now();this.bn.has(i)||this.bn.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.bn.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.$n=i,this.Fn)){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.Fn(o)}}zn(t){const i=t.key,r=Date.now();this.bn.has(i)||this.bn.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.bn.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.xn=i,this.Sn){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.Sn(o)}}En(t){return this.Tn[t]||t.toLowerCase()}}const Kt=Object.freeze(Object.defineProperty({__proto__:null,KeyboardManager:ut},Symbol.toStringTag,{value:"Module"}));class ft{constructor(t,i){c(this,"er");c(this,"In");c(this,"Gr");c(this,"On",new Map);c(this,"Wn",new Map);c(this,"Hn",new Map);c(this,"Kn",null);c(this,"Xn");c(this,"jn");c(this,"Nn");c(this,"Yn");c(this,"Vn");c(this,"qn");c(this,"qr",!1);c(this,"Zn");c(this,"Jn");c(this,"Qn");c(this,"so");c(this,"eo");c(this,"io");c(this,"ro");c(this,"no");c(this,"oo");c(this,"ho");c(this,"ao",320);c(this,"co",350);c(this,"lo",10);c(this,"uo",550);c(this,"fo",14);c(this,"do",48);c(this,"_o",650);c(this,"po",.02);c(this,"mo",2);c(this,"vo",600);c(this,"yo",0);c(this,"Co",null);this.er=t,this.In=i;const r=this.er.canvas;this.Xn=r.style.touchAction,this.jn=r.style.userSelect,r.style.touchAction||(r.style.touchAction="none"),r.style.userSelect||(r.style.userSelect="none")}ji(t){this.Gr=t,this.wo()}an(){if(this.qr)return;const t=this.er.canvas;this.Nn=i=>{this.bo(i)},this.Yn=i=>{this.$o(i)},this.Vn=i=>{this.xo(i)},this.qn=i=>{this.Mo(i)},t.addEventListener("touchstart",this.Nn,{passive:!1}),t.addEventListener("touchmove",this.Yn,{passive:!1}),t.addEventListener("touchend",this.Vn,{passive:!1}),t.addEventListener("touchcancel",this.qn,{passive:!1}),this.qr=!0}pn(){if(!this.qr)return;const t=this.er.canvas;t.removeEventListener("touchstart",this.Nn),t.removeEventListener("touchmove",this.Yn),t.removeEventListener("touchend",this.Vn),t.removeEventListener("touchcancel",this.qn),this.qr=!1,this.Kn=null,this.On.clear(),this.Wn.clear(),this.Hn.forEach(i=>{i.longPressTimer!==null&&window.clearTimeout(i.longPressTimer)}),this.Hn.clear(),this.Co=null,this.yo=0,t.style.touchAction=this.Xn,t.style.userSelect=this.jn}wo(){if(!this.Gr||this.On.size===0)return;const t=new Map;for(const i of this.On.values()){const r=this.Ro(i.clientX,i.clientY,i.id,i);t.set(i.id,r)}this.On=t}Fo(){return Array.from(this.On.values()).map(t=>({...t}))}So(t){this.Zn=t}yn(t){this.Jn=t}To(t){this.Qn=t}Ao(t){this.so=t}zo(t){this.eo=t}ko(t){this.io=t}Eo(t){this.ro=t}Po(t){this.no=t}Lo(t){this.oo=t}Do(t){this.ho=t}bo(t){var n;if(!this.Gr)return;t.preventDefault(),(n=this.In)==null||n.en(this.vo);const i=performance.now(),r=this.Bo(t.changedTouches);for(const o of r){const h=this.On.get(o.id);h&&this.Wn.set(o.id,this.Go(h)),this.On.set(o.id,o);const a={id:o.id,startPosition:o,lastPosition:o,startTime:i,lastTime:i,longPressTimer:null,longPressFired:!1};this.ro&&(a.longPressTimer=window.setTimeout(()=>{const u=this.On.get(o.id);u&&(a.longPressFired=!0,this.ro({touch:this.Go(u),duration:performance.now()-a.startTime,originalEvent:t}))},this.uo)),this.Hn.set(o.id,a),this.Zn&&this.Zn(this.Io(o,t,void 0,i))}this.On.size===2&&this.Oo()}$o(t){var n;if(!this.Gr)return;t.preventDefault(),(n=this.In)==null||n.en(this.vo);const i=performance.now(),r=this.Bo(t.changedTouches);for(const o of r){const h=this.On.get(o.id),a=h?this.Go(h):void 0;a&&this.Wn.set(o.id,a),this.On.set(o.id,o);const u=this.Hn.get(o.id);u&&(u.lastPosition=o,u.lastTime=i,a)&&this.Wo(a,o,!0)>this.fo&&u.longPressTimer!==null&&(window.clearTimeout(u.longPressTimer),u.longPressTimer=null),this.Jn&&this.Jn(this.Io(o,t,a,i))}this.On.size===2?this.Ho(t):this.Kn=null}xo(t){if(!this.Gr)return;t.preventDefault();const i=performance.now(),r=this.Bo(t.changedTouches);for(const n of r){const o=this.On.get(n.id),h=o?this.Go(o):void 0,a=this.Hn.get(n.id);a&&a.longPressTimer!==null&&(window.clearTimeout(a.longPressTimer),a.longPressTimer=null),this.Qn&&this.Qn(this.Io(n,t,h,i)),a&&this.Ko(a,t),this.Hn.delete(n.id),this.Wn.delete(n.id),this.On.delete(n.id)}this.On.size<2&&(this.Kn=null)}Mo(t){if(!this.Gr)return;t.preventDefault();const i=performance.now(),r=this.Bo(t.changedTouches);for(const n of r){const o=this.On.get(n.id),h=o?this.Go(o):void 0,a=this.Hn.get(n.id);a&&a.longPressTimer!==null&&(window.clearTimeout(a.longPressTimer),a.longPressTimer=null),this.so&&this.so(this.Io(n,t,h,i)),this.Hn.delete(n.id),this.Wn.delete(n.id),this.On.delete(n.id)}this.On.size<2&&(this.Kn=null)}Bo(t){const i=[];for(let r=0;r<t.length;r+=1){const n=t.item(r);n&&i.push(this.Xo(n))}return i}Xo(t){return this.Ro(t.clientX,t.clientY,t.identifier,{id:t.identifier,x:-1,y:-1,clientX:t.clientX,clientY:t.clientY,pressure:t.force,radiusX:t.radiusX,radiusY:t.radiusY,rotationAngle:t.rotationAngle})}Ro(t,i,r,n){const o=this.er.canvas,h=o.getBoundingClientRect(),a=t-h.left,u=i-h.top,f=o.width/h.width,g=u*(o.height/h.height),d=a*f-this.Gr.offsetX,v=g-this.Gr.offsetY,x=Math.floor(d/this.Gr.cellWidth),p=Math.floor(v/this.Gr.cellHeight),m=x>=0&&x<this.Gr.cols&&p>=0&&p<this.Gr.rows;return{id:r,x:m?x:-1,y:m?p:-1,clientX:t,clientY:i,pressure:n.pressure,radiusX:n.radiusX,radiusY:n.radiusY,rotationAngle:n.rotationAngle}}Io(t,i,r,n){const o=this.Hn.get(t.id),h=Array.from(this.Wn.values()).map(f=>this.Go(f)),a=Array.from(this.On.values()).map(f=>this.Go(f)),u=this.Bo(i.changedTouches);return{touch:this.Go(t),previousTouch:r?this.Go(r):void 0,touches:a,previousTouches:h,changedTouches:u,deltaTime:o?n-o.lastTime:0,originalEvent:i}}Oo(){if(this.On.size!==2)return void(this.Kn=null);const t=Array.from(this.On.values()),[i,r]=t,n=this.Wo(i,r,!1),o=this.jo(i,r);this.Kn={ids:[i.id,r.id],initialDistance:Math.max(n,1e-4),initialAngle:o,lastScale:1,lastRotation:0}}Ho(t){if(this.Kn||this.Oo(),!this.Kn)return;const[i,r]=this.Kn.ids,n=this.On.get(i),o=this.On.get(r);if(!n||!o)return;const h=this.Wo(n,o,!1)/this.Kn.initialDistance,a=h-this.Kn.lastScale;this.oo&&Math.abs(a)>this.po&&(this.oo({touches:[this.Go(n),this.Go(o)],scale:h,deltaScale:a,center:this.No(n,o),originalEvent:t}),this.Kn.lastScale=h);let u=this.jo(n,o)-this.Kn.initialAngle;u=(u+180)%360-180;const f=u-this.Kn.lastRotation;this.ho&&Math.abs(f)>this.mo&&(this.ho({touches:[this.Go(n),this.Go(o)],rotation:u,deltaRotation:f,center:this.No(n,o),originalEvent:t}),this.Kn.lastRotation=u)}No(t,i){const r=(t.clientX+i.clientX)/2,n=(t.clientY+i.clientY)/2,o=this.Ro(r,n,-1,{id:-1,x:-1,y:-1,clientX:r,clientY:n});return{x:o.x,y:o.y}}Ko(t,i){const r=performance.now(),n=r-t.startTime,o=this.Wo(t.startPosition,t.lastPosition,!0);if(!t.longPressFired&&n<=this.ao&&o<=this.lo)this.Yo(t.lastPosition,r)&&this.io?this.io({touch:this.Go(t.lastPosition),taps:2,originalEvent:i}):this.eo&&this.eo({touch:this.Go(t.lastPosition),taps:1,originalEvent:i});else if(!t.longPressFired&&n<=this._o&&o>=this.do){const h={x:t.lastPosition.clientX-t.startPosition.clientX,y:t.lastPosition.clientY-t.startPosition.clientY},a=Math.max(Math.hypot(h.x,h.y),1e-4),u={x:h.x/a,y:h.y/a},f={x:h.x/n,y:h.y/n};this.no&&this.no({touch:this.Go(t.lastPosition),direction:u,distance:a,velocity:f,originalEvent:i})}this.yo=r,this.Co=this.Go(t.lastPosition)}Yo(t,i){return!!this.Co&&!(i-this.yo>this.co)&&this.Wo(t,this.Co,!0)<=this.lo}Go(t){return{...t}}Wo(t,i,r){return r?Math.hypot(t.clientX-i.clientX,t.clientY-i.clientY):Math.hypot(t.x-i.x,t.y-i.y)}jo(t,i){return 180*Math.atan2(i.clientY-t.clientY,i.clientX-t.clientX)/Math.PI}}const qt=Object.freeze(Object.defineProperty({__proto__:null,TouchManager:ft},Symbol.toStringTag,{value:"Module"})),jt=l=>class extends l{rotate(t=0,i=0,r=0){this.xt.state.st(t),this.xt.state.et(i),this.xt.state.it(r)}rotateX(t){this.xt.state.st(t)}rotateY(t){this.xt.state.et(t)}rotateZ(t){this.xt.state.it(t)}push(){this.xt.state.O()}pop(){this.xt.state.Z()}rect(t,i,r=1,n=1){this.xt.He(t,i,r,n)}point(t,i){this.xt.He(t,i,1,1)}line(t,i,r,n){this.xt.Ke(t,i,r,n)}lineWeight(t){this.xt.state.tt(t)}background(t,i=t,r=t,n=255){this.xt.qe(t,i,r,n)}char(t){this.xt.state.rt(this.ki.Ai(t))}charColor(t,i,r,n=255){this.xt.state.nt(t,i,r,n)}cellColor(t,i,r,n=255){this.xt.state.ot(t,i,r,n)}flipX(t){this.xt.state.ht(t)}flipY(t){this.xt.state.ct(t)}charRotation(t){this.xt.state.ut(t)}invert(t){this.xt.state.lt(t)}clear(){this.xt.qe(0,0,0,0)}ellipse(t,i,r,n){this.xt.Xe(t,i,r/2,n/2)}triangle(t,i,r,n,o,h){this.xt.je(t,i,r,n,o,h)}bezierCurve(t,i,r,n,o,h,a,u){this.xt.Ne(t,i,r,n,o,h,a,u)}arc(t,i,r,n,o,h){this.xt.Ve(t,i,r,n,o,h)}shader(t){this.xt.De(t)}setUniform(t,i){this.xt.jt(t,i)}setUniforms(t){this.xt.Be(t)}createFilterShader(t){return this.xt.hs(t)}createFramebuffer(t){return this.xt.Ye(t.width,t.height,5,{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"})}image(t,i,r,n,o){if(t.textures){const h=t;this.xt.Ge(h,i,r,n??h.width,o??h.height)}else{const h=t;this.xt.Ie(h,i,r,n??Math.floor(this.Gr.cols/2),o??Math.floor(this.Gr.rows/2))}}async loadImage(t){if(typeof t!="string")return N.Fr(this.xt,t,n=>this.ki.zi(n));const i=t,r=await new Promise((n,o)=>{const h=new Image;h.crossOrigin="anonymous",h.onload=()=>n(h),h.onerror=a=>o(a),h.src=i});return N.Fr(this.xt,r,n=>this.ki.zi(n))}},Jt=l=>class extends l{async loadFont(t){return this.ki.qi(t).then(()=>{const i=this.ki.maxGlyphDimensions;this.Gr.hr(i.width,i.height),this.Vo.resize(this.Gr.cols,this.Gr.rows),this.xt.Ze(),this.In.hn()})}fontSize(t){if(!W.v(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.ki.fontSize===t)return;this.ki.Vi(t);const i=this.ki.maxGlyphDimensions;this.Gr.hr(i.width,i.height),this.Vo.resize(this.Gr.cols,this.Gr.rows),this.xt.Ze(),this.In.hn()}glyphColor(t){return this.ki.Ai(t)}glyphColors(t){return this.ki.zi(t)}},Zt=l=>class extends l{get frameCount(){return this.qo.frameCount}set frameCount(t){this.qo.frameCount=t}frameRate(t){return t===void 0?this.qo.currentFrameRate:this.qo.frameRate(t,()=>this.Zo())}noLoop(){this.qo.pause()}loop(){this.qo.resume(()=>this.Zo())}redraw(t=1){if(W.v(typeof t=="number"&&t>0&&Number.isInteger(t),"Redraw count must be a positive integer.",{method:"redraw",providedValue:t}))for(let i=0;i<t;i++)this.Zo()}isLooping(){return this.qo.isLooping}},Qt=l=>class extends l{constructor(...t){super(...t)}mouseClicked(t){this.In.mn(t)}mousePressed(t){this.In.vn(t)}mouseReleased(t){this.In.gn(t)}mouseMoved(t){this.In.yn(t)}mouseScrolled(t){this.In.Cn(t)}get mouse(){return this.In.wn()}cursor(t){this.In.nn(t)}},te=l=>class extends l{constructor(...t){super(...t)}touchStarted(t){this.Jo.So(t)}touchMoved(t){this.Jo.yn(t)}touchEnded(t){this.Jo.To(t)}touchCancelled(t){this.Jo.Ao(t)}tap(t){this.Jo.zo(t)}doubleTap(t){this.Jo.ko(t)}longPress(t){this.Jo.Eo(t)}swipe(t){this.Jo.Po(t)}pinch(t){this.Jo.Lo(t)}rotateGesture(t){this.Jo.Do(t)}get touches(){return this.Jo.Fo()}},ee=l=>class extends l{constructor(...t){super(...t)}keyPressed(t){this.Qo.vn(t)}keyReleased(t){this.Qo.gn(t)}isKeyPressed(t){return this.Qo.kn(t)}get lastKeyPressed(){return this.Qo.Pn()}get lastKeyReleased(){return this.Qo.Ln()}get pressedKeys(){return this.Qo.Dn()}get modifierState(){return this.Qo.Bn()}};class dt{constructor(t){c(this,"th");c(this,"sh",new Map);c(this,"eh",[]);c(this,"ih",new Map);c(this,"rh",new Map);this.th=t}async installMany(t){for(const i of t)await this.use(i)}async use(t){if(this.sh.has(t.name))return void console.warn(`[textmode.js] Plugin "${t.name}" is already installed.`);const i=this.nh(t.name);try{await t.install(this.th,i)}catch(r){throw this.oh(t.name),r}this.sh.set(t.name,t),this.eh.push(t.name)}async unuse(t){const i=this.sh.get(t);if(!i)return;const r=this.nh(t);if(i.uninstall)try{await i.uninstall(this.th,r)}catch(n){console.error(`[textmode.js] Error while uninstalling plugin "${t}":`,n)}this.sh.delete(t),this.eh.splice(this.eh.indexOf(t),1),this.oh(t)}has(t){return this.sh.has(t)}runPreDrawHooks(){this.hh(this.ih,"preDraw")}runPostDrawHooks(){this.hh(this.rh,"postDraw")}async disposeAll(){const t=[...this.sh.keys()];for(const i of t)await this.unuse(i)}nh(t){return{...this.th.ah(),registerPreDrawHook:i=>this.uh(this.ih,t,i),registerPostDrawHook:i=>this.uh(this.rh,t,i)}}uh(t,i,r){const n=t.get(i)??new Set;return n.add(r),t.set(i,n),()=>{const o=t.get(i);o&&(o.delete(r),o.size===0&&t.delete(i))}}oh(t){this.ih.delete(t),this.rh.delete(t)}hh(t,i){for(const r of this.eh){const n=t.get(r);if(n)for(const o of n)try{o()}catch(h){console.error(`[textmode.js] Plugin "${r}" ${i} hook failed:`,h)}}}}class ie{constructor(){c(this,"xt");c(this,"ki");c(this,"er");c(this,"Gr");c(this,"qo");c(this,"In");c(this,"Jo");c(this,"Qo");c(this,"fh");c(this,"Vo");c(this,"dh");c(this,"_h");c(this,"ph")}Zo(){}}class gt extends function(i,...r){return r.reduce((n,o)=>o(n),i)}(ie,jt,Jt,Zt,Qt,te,ee){constructor(i={}){var r;super();c(this,"mh");c(this,"gh");c(this,"yh",!1);c(this,"Ch",!1);c(this,"wh",()=>{});c(this,"bh",()=>{});c(this,"$h",()=>{});c(this,"xh");c(this,"lr");c(this,"cr",!1);c(this,"Mh");this.mh=new dt(this),this.gh=((r=i.plugins)==null?void 0:r.slice())??[],this.cr=i.overlay??!1,this.er=new ct(i),this.xt=new St(this.er.gr()),this.ki=new ht(this.xt,i.fontSize??16),this.qo=new Vt(i.frameRate??60),this.In=new lt(this.er),this.Jo=new ft(this.er,this.In),this.Qo=new ut,this.fh=this.xt.At(),this.dh=this.xt.rs(),this.Rh(i)}async Rh(i){await this.ki.ji(i.fontSource);const r=this.ki.maxGlyphDimensions;this.Gr=new at(this.er.canvas,r.width,r.height),this.In.ji(this.Gr),this.Jo.ji(this.Gr),this.Vo=this.xt.Ye(this.Gr.cols,this.Gr.rows,5),this._h=this.xt.Ye(this.Gr.width,this.Gr.height,1),this.cr&&(this.Mh=N.Fr(this.xt,this.er.targetCanvas,n=>this.ki.zi(n))),this.ph=this.xt.cs(rt,"precision mediump float;uniform sampler2D Ua;uniform vec2 Ub;uniform vec2 Uc;uniform vec2 Ud;void main(){vec2 A=gl_FragCoord.xy-Uc;vec2 B=A*(Ub/Ud);vec2 C=(floor(B)+0.5)/Ub;gl_FragColor=texture2D(Ua,C);}"),this.Fh(),await this.mh.installMany(this.gh),this.gh=[],this.yh=!0,this.wh(),this.qo.start(()=>this.Zo())}async use(i){return this.yh?await this.mh.use(i):this.gh.push(i),this}async unuse(i){return this.yh?(await this.mh.unuse(i),this):(this.gh=this.gh.filter(r=>r.name!==i),this)}hasPlugin(i){return this.yh?this.mh.has(i):this.gh.some(r=>r.name===i)}ah(){return{renderer:this.xt,font:this.ki,grid:this.Gr,canvas:this.er,drawFramebuffer:this.Vo,asciiFramebuffer:this._h,flushDrawCommands:()=>{this.xt.zt(this.fh)}}}Fh(){this.xh=()=>{this.cr&&this.resizeCanvas(this.er.targetCanvas.width,this.er.targetCanvas.height),this.$h()},window.addEventListener("resize",this.xh),this.In.an(),this.Jo.an(),this.Qo.an(),window.addEventListener("blur",()=>{this.Qo.Gn()}),window.ResizeObserver&&this.cr&&(this.lr=new ResizeObserver(()=>{this.resizeCanvas(this.er.targetCanvas.width,this.er.targetCanvas.height)}),this.lr.observe(this.er.targetCanvas))}Zo(){if(this.qo.measureFrameRate(),this.qo.incrementFrame(),this.Ch)return;if(this.cr){const r=this.xt.context;r.bindTexture(r.TEXTURE_2D,this.Mh.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.er.targetCanvas),r.bindTexture(r.TEXTURE_2D,null)}this.mh.runPreDrawHooks(),this.Vo.begin(),this.xt.Le(this.fh),this.bh(),this.xt.zt(this.fh),this.Vo.end(),this._h.begin(),this.xt.Le(this.dh),this.dh.Xt({U0:this.ki.fontFramebuffer,U1:[this.ki.textureColumns,this.ki.textureRows],U2:this.Vo.textures[0],U3:this.Vo.textures[1],U4:this.Vo.textures[2],U5:this.Vo.textures[4],U6:this.Vo.textures[3],U7:[this.Gr.cols,this.Gr.rows],U8:[this._h.width,this._h.height],U9:this._h.width/this._h.height}),this.xt.We(0,0,this.er.width,this.er.height),this._h.end();const i=this.xt.state.canvasBackgroundColor;this.xt.Ys(i[0],i[1],i[2],i[3]),this.xt.Le(this.ph),this.ph.Xt({Ua:this._h.textures[0],Ub:[this._h.width,this._h.height],Uc:[this.Gr.offsetX,this.Gr.offsetY],Ud:[this.Gr.width,this.Gr.height]}),this.xt.We(this.Gr.offsetX,this.Gr.offsetY,this.Gr.width,this.Gr.height),this.mh.runPostDrawHooks()}setup(i){this.wh=i}draw(i){this.bh=i}windowResized(i){this.$h=i}resizeCanvas(i,r){this.er.vr(i,r),this.Gr.nr(),this.Vo.resize(this.Gr.cols,this.Gr.rows),this._h.resize(this.Gr.width,this.Gr.height),this.xt.Ze(),this.In.hn(),this.Jo.wo(),this.Zo()}destroy(){this.Ch||(this.qo.stop(),this.mh.disposeAll().catch(i=>{console.error("[textmode.js] Error while disposing plugins:",i)}),window.removeEventListener("resize",this.xh),this.In.pn(),this.Jo.pn(),this.Qo.pn(),this.ki.Pt(),this.xt.Pt(),this._h.Pt(),this.ph.Pt(),this.Mh&&this.Mh.Pt(),this.Ch=!0)}get grid(){return this.Gr}get font(){return this.ki}get width(){return this.er.width}get height(){return this.er.height}get canvas(){return this.er.canvas}get drawFramebuffer(){return this.Vo}get isDisposed(){return this.Ch}get overlay(){return this.Mh}}class J{constructor(){}static create(t={}){return new gt(t)}static setErrorLevel(t){W.C(t)}static get version(){return"0.3.2-beta.3"}}const se=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),re=Object.freeze(Object.defineProperty({__proto__:null,keyboard:Kt,mouse:$t,touch:qt},Symbol.toStringTag,{value:"Module"})),ne=J.create,oe=J.setErrorLevel,he=J.version;b.PluginManager=dt,b.TextmodeCanvas=ct,b.TextmodeErrorLevel=G,b.TextmodeFont=ht,b.TextmodeFramebuffer=$,b.TextmodeGrid=at,b.TextmodeImage=N,b.Textmodifier=gt,b.create=ne,b.export=se,b.input=re,b.setErrorLevel=oe,b.textmode=J,b.version=he,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):e((s=typeof globalThis<"u"?globalThis:s||self).textmode={});
|
|
11
|
+
precision highp float;in vec2 v_uv;uniform sampler2D Uk;uniform bool Ul;uniform bool Um;uniform bool Un;uniform vec2 Uo;uniform bool Up;uniform vec4 Uq;uniform bool Ur;uniform vec4 Us;uniform vec4 Ut;uniform int Uu;uniform vec3 Uv[64];layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;float A(vec3 B){return dot(B,vec3(0.299f,0.587f,0.114f));}void main(){vec2 C=vec2(v_uv.x,1.0f-v_uv.y);vec4 D=texture(Uk,C);float E=A(D.rgb);if(Uu>0){float F=float(Uu);float G=clamp(E*(F-1.0f),0.0f,F-1.0f);int H=int(floor(G+0.5f));vec3 I=Uv[H];o_character=vec4(I,1.0f);}else{o_character=vec4(E,0.0f,0.0f,1.0f);}vec4 J=Up?Uq:D;vec4 K=Ur?Us:D;if(D.a<0.01f){J=Ut;K=Ut;}else{}o_primaryColor=vec4(J);o_secondaryColor=vec4(K);o_rotation=vec4(Uo.xy,0.0f,1.0f);o_transform=vec4(float(Ul),float(Um),float(Un),1.0f);}`)}es(){return this.Jt}At(){return this.Qt}rs(){return this.ts}ns(){return this.ss}hs(t){return new k(this.gt,K,t)}cs(t,i){return new k(this.gt,t,i)}Pt(){this.Jt.Pt(),this.Qt.Pt(),this.ts.Pt(),this.ss.Pt()}}var R=(l=>(l.RECTANGLE="rectangle",l.LINE="line",l.ELLIPSE="ellipse",l.ARC="arc",l.TRIANGLE="triangle",l.BEZIER_CURVE="bezier_curve",l.CUSTOM="custom",l))(R||{});class pt{constructor(t){c(this,"gt");c(this,"ls",new Map);this.gt=t}us(t,i,r,n){const o=this.gt;let h=this.ls.get(t);h||(h=new Map,this.ls.set(t,h));let a=h.get(i)||null;if(!a){a=o.createVertexArray(),h.set(i,a),o.bindVertexArray(a),o.bindBuffer(o.ARRAY_BUFFER,n);const u=o.getAttribLocation(t,"a_position");u!==-1&&(o.enableVertexAttribArray(u),o.vertexAttribPointer(u,r.ds.fs.size,o.FLOAT,!1,r._s,r.ds.fs.offset),o.vertexAttribDivisor(u,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,r.ds.ps.size,o.FLOAT,!1,r._s,r.ds.ps.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(a)}vs(){this.gt.bindVertexArray(null)}Pt(){for(const[,t]of this.ls)for(const[,i]of t)i&&this.gt.deleteVertexArray(i)}}class vt{constructor(t,i){c(this,"gs");c(this,"gt");c(this,"xt");c(this,"Cs",null);c(this,"ws",null);this.gt=t,this.gs=new pt(t),this.xt=i}bs(t,i,r){const{shader:n}=t,o=$(this.gt)||this.gt.getParameter(this.gt.VIEWPORT);n.Xt({U9:o[2]/o[3],Uw:[o[2],o[3]]});const h=f=>{if(!f||!f.$s())return;const g=f.unitGeometry,d=f.unitBuffer;try{this.gs.us(n.Zt,f.type+"",g,d),f.batch.Ms(n),f.batch.Rs(g.Fs,g.Ss)}finally{f.batch.Ts(n),this.gs.vs(),f.As()}};let a=null,u=null;for(const f of i){if(f.type===R.CUSTOM){u&&(h(u),a=null,u=null),this.zs(t,f.params,f.state,r.get(R.RECTANGLE));continue}a!==null&&f.type!==a&&(h(u),a=null,u=null);let g=u;g&&f.type===a||(g=r.get(f.type)||null,u=g,a=f.type),g&&g.ks(f.params,f.state)}h(u)}zs(t,i,r,n){const{x:o,y:h,width:a,height:u,shader:f,uniforms:g}=i,d=this.Es(Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)));d.begin(),this.Ps(n,f,g,0,0,d.width,d.height,{}),d.end();const v=this.Ls(),x={Ue:d.textures[0],Uf:d.textures[1],Ug:d.textures[2],Uh:d.textures[3],Ui:d.textures[4],Uj:[d.width,d.height]};this.Ps(n,v,x,Math.floor(o),Math.floor(h),Math.max(1,Math.floor(a)),Math.max(1,Math.floor(u)),r),t.shader.Ht()}Ps(t,i,r,n,o,h,a,u){i.Ht(),i.Xt(r);const f=this.gt.getParameter(this.gt.VIEWPORT);if(i.Xt({U9:f[2]/f[3],Uw:[f[2],f[3]]}),t.As(),t.ks({x:n,y:o,width:h,height:a},u),t.$s()){const g=t.unitGeometry,d=t.unitBuffer;try{this.gs.us(i.Zt,t.type+"",g,d),t.batch.Ms(i),t.batch.Rs(g.Fs,g.Ss)}finally{t.batch.Ts(i),this.gs.vs(),t.As()}}}Ls(){return this.xt.es()}Es(t,i){return this.Cs&&this.ws&&this.ws.w===t&&this.ws.h===i||(this.Cs&&this.Cs.Pt(),this.Cs=new V(this.gt,t,i,5),this.ws={w:t,h:i}),this.Cs}Pt(){this.gs.Pt(),this.Cs&&this.Cs.Pt()}}class yt{constructor(){c(this,"Ds",[]);c(this,"Bs",1);c(this,"Gs",0)}Is(t){if(this.Gs>=this.Ds.length){const r={id:this.Bs++,type:t,params:{},state:{W:1,H:0,K:0,X:0,Y:[0,0,0],V:[1,1,1,1],q:[0,0,0,1],N:!1,j:!1,L:!1,D:[0,0]}};this.Ds.push(r)}const i=this.Ds[this.Gs];return i.id=this.Bs++,i.type=t,this.Gs++,i}Os(t,i,r,n,o){const h=this.Is(R.RECTANGLE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Ws(t,i,r,n,o,h,a){const u=this.Is(R.CUSTOM);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.shader=o,u.params.uniforms=h,a.J(u.state),u.id}Hs(t,i,r,n,o,h){const a=this.Is(R.LINE);return a.params.x1=t,a.params.y1=i,a.params.x2=r,a.params.y2=n,a.params.thickness=o,h.J(a.state),a.id}Ks(t,i,r,n,o){const h=this.Is(R.ELLIPSE);return h.params.x=t,h.params.y=i,h.params.width=r,h.params.height=n,o.J(h.state),h.id}Xs(t,i,r,n,o,h,a){const u=this.Is(R.ARC);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.start=o,u.params.stop=h,a.J(u.state),u.id}Ns(t,i,r,n,o,h,a){const u=this.Is(R.TRIANGLE);return u.params.x1=t,u.params.y1=i,u.params.x2=r,u.params.y2=n,u.params.x3=o,u.params.y3=h,a.J(u.state),u.id}js(t,i,r,n,o,h,a,u,f,g){const d=this.Is(R.BEZIER_CURVE);return d.params.x1=t,d.params.y1=i,d.params.cp1x=r,d.params.cp1y=n,d.params.cp2x=o,d.params.cp2y=h,d.params.x2=a,d.params.y2=u,d.params.thickness=f,g.J(d.state),d.id}get length(){return this.Gs}get isEmpty(){return this.Gs===0}Ys(){this.Gs=0}[Symbol.iterator](){let t=0;const i=this.Gs,r=this.Ds;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const M=class M{static Vs(t,i,r=0){var h,a,u,f,g,d,v,x,p,m;const n=i||new Float32Array(M.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.fs[0],n[o++]=t.fs[1],n[o++]=t.Gs[0],n[o++]=t.Gs[1],n[o++]=t.Y[0],n[o++]=t.Y[1],n[o++]=t.Y[2],n[o++]=t.V[0],n[o++]=t.V[1],n[o++]=t.V[2],n[o++]=t.V[3],n[o++]=t.q[0],n[o++]=t.q[1],n[o++]=t.q[2],n[o++]=t.q[3],n[o++]=t.D[0],n[o++]=t.D[1],n[o++]=t.qs[0],n[o++]=t.qs[1],n[o++]=t.qs[2],n[o++]=t.H,n[o++]=t.K,n[o++]=t.X,n[o++]=t.Zs[0],n[o++]=t.Zs[1],n[o++]=((h=t.Js)==null?void 0:h[0])||0,n[o++]=((a=t.Js)==null?void 0:a[1])||0,n[o++]=((u=t.Qs)==null?void 0:u[0])||0,n[o++]=((f=t.Qs)==null?void 0:f[1])||0,n[o++]=((g=t.te)==null?void 0:g[0])||0,n[o++]=((d=t.te)==null?void 0:d[1])||0,n[o++]=((v=t.se)==null?void 0:v[0])||0,n[o++]=((x=t.se)==null?void 0:x[1])||0,n[o++]=((p=t.ee)==null?void 0:p[0])||0,n[o++]=((m=t.ee)==null?void 0:m[1])||0,n}static ie(t){const i=t.length*M.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*M.FLOATS_PER_INSTANCE;M.Vs(t[n],r,o)}return r}};c(M,"BYTES_PER_INSTANCE",140),c(M,"FLOATS_PER_INSTANCE",35);let D=M;const _=class _{};c(_,"STRIDE",D.BYTES_PER_INSTANCE),c(_,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:_.STRIDE,offset:132,divisor:1}});let q=_;class xt{constructor(t,i=1e3,r=1.5){c(this,"gt");c(this,"re",[]);c(this,"ne");c(this,"oe");c(this,"he",null);c(this,"ae",!0);c(this,"ce",0);c(this,"le",new Map);c(this,"ue",null);this.gt=t,this.ne=i,this.oe=r,this.fe()}ks(t){const i=this.re.length;return this.re.push(t),this.ae=!0,i}get count(){return this.re.length}get isEmpty(){return this.re.length===0}clear(){this.re.length=0,this.ae=!0}de(t){if(t<=this.ne)return;const i=Math.ceil(t*this.oe);this.ne=i,this.fe()}fe(){const t=this.gt;this.he&&t.deleteBuffer(this.he),this.he=t.createBuffer();const i=this.ne*D.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.he),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.ae=!0,this.ce=0}_e(){if(!this.ae||this.re.length===0)return;const t=this.gt,i=this.re.length;this.de(i),(!this.ue||this.ue.length<i*D.FLOATS_PER_INSTANCE)&&(this.ue=new Float32Array(i*D.FLOATS_PER_INSTANCE));const r=D.ie(this.re);t.bindBuffer(t.ARRAY_BUFFER,this.he),i<=this.ce?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.ae=!1,this.ce=i}pe(t){let i=this.le.get(t);if(!i){i=new Map;const r=this.gt;for(const n in q.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.le.set(t,i)}return i}Ms(t){if(!this.he||this.re.length===0)return;const i=this.gt,r=t.Zt;this._e();const n=this.pe(r);i.bindBuffer(i.ARRAY_BUFFER,this.he);for(const[o,h]of n){const a=q.ATTRIBUTES[o];a&&(i.enableVertexAttribArray(h),i.vertexAttribPointer(h,a.size,a.type,a.normalized,a.stride,a.offset),i.vertexAttribDivisor(h,a.divisor))}}Ts(t){const i=this.gt,r=this.pe(t.Zt);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}Rs(t,i){this.re.length!==0&&this.gt.drawArraysInstanced(t,0,i,this.re.length)}Pt(){this.he&&this.gt.deleteBuffer(this.he)}}class z{constructor(t,i,r,n){c(this,"gt");c(this,"me");c(this,"ve");c(this,"ge");c(this,"ye",null);this.gt=t,this.me=i,this.ve=r,this.ge=n;const o=this.gt.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.gt.bindBuffer(this.gt.ARRAY_BUFFER,o),this.gt.bufferData(this.gt.ARRAY_BUFFER,this.ge.Ce,this.gt.STATIC_DRAW),this.gt.bindBuffer(this.gt.ARRAY_BUFFER,null),this.ye=o}get type(){return this.ve}get unitGeometry(){return this.ge}get unitBuffer(){return this.ye}get batch(){return this.me}As(){this.me.clear()}$s(){return!this.me.isEmpty}Pt(){this.me.Pt(),this.gt.deleteBuffer(this.ye)}we(t,i,r,n,o){const h=this.be(t,i,r,n,o.H||0,o.K||0,o.X||0);return{fs:[t,i],Gs:[r,n],Y:o.Y||[0,0,0],V:o.V||[1,1,1,1],q:o.q||[0,0,0,1],D:o.D||[0,0],qs:[o.L?1:0,o.N?1:0,o.j?1:0],H:h.radiansX,K:h.radiansY,X:h.radiansZ,Zs:[h.centerX,h.centerY]}}$e(t,i){const r=$(this.gt)||[0,0,this.gt.canvas.width,this.gt.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}xe(t,i,r){const n=this.$e(i,r);t.Zs=[n.nx,n.ny]}be(t,i,r,n,o,h,a){const u=$(this.gt)||[0,0,this.gt.canvas.width,this.gt.canvas.height],f=u[2],g=u[3];return{centerX:(t+r/2)/f*2-1,centerY:1-(i+n/2)/g*2,radiansX:-o*Math.PI/180,radiansY:-h*Math.PI/180,radiansZ:-a*Math.PI/180,aspectRatio:f/g}}}const Et={Ce: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]),Ss:6,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class wt extends z{constructor(t,i){super(t,i,R.RECTANGLE,Et)}ks(t,i){const r=this.we(t.x,t.y,t.width,t.height,i);return this.me.ks(r)}}const Rt={Ce: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]),Ss:6,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class At extends z{constructor(t,i){super(t,i,R.LINE,Rt)}ks(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),h=t.thickness||i.W||1,a=t.x1+r/2,u=t.y1+n/2,f=a-o/2,g=u,d=this.we(f,g,o,h,i);return this.xe(d,a,u),this.me.ks(d)}}const Tt={Ce:function(l=32){const t=[],i=2*Math.PI/l;for(let r=0;r<l;r++){const n=r*i,o=(r+1)%l*i,h=Math.cos(n),a=Math.sin(n),u=.5*(h+1),f=.5*(a+1),g=Math.cos(o),d=Math.sin(o),v=.5*(g+1),x=.5*(d+1);t.push(0,0,.5,.5,h,a,u,f,g,d,v,x)}return new Float32Array(t)}(32),Ss:96,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class bt extends z{constructor(t,i){super(t,i,R.ELLIPSE,Tt)}ks(t,i){const r=this.we(t.x,t.y,t.width,t.height,i);return this.xe(r,t.x,t.y),this.me.ks(r)}}let Ct={Ce:function(l){const t=[];for(let i=0;i<l;i++){const r=i/l,n=(i+1)/l;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),Ss:96,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class _t extends z{constructor(t,i){super(t,i,R.ARC,Ct)}ks(t,i){const r=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,h=t.stop*Math.PI/180,a=this.we(r,n,t.width,t.height,i);return this.xe(a,t.x,t.y),a.Js=[o,h],this.me.ks(a)}}const Ut={Ce:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),Ss:3,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class Ft extends z{constructor(t,i){super(t,i,R.TRIANGLE,Ut)}ks(t,i){const r=Math.min(t.x1,t.x2,t.x3),n=Math.max(t.x1,t.x2,t.x3),o=Math.min(t.y1,t.y2,t.y3),h=n-r,a=Math.max(t.y1,t.y2,t.y3)-o,u=this.we(r,o,h,a,i),f=r+.5*h,g=o+a*(1/3);return this.xe(u,f,g),this.me.ks(u)}}function nt(l,t,i,r,n){const o=1-l,h=o*o,a=l*l;return h*o*t+3*h*l*i+3*o*a*r+a*l*n}const Pt={Ce:function(l=16){const t=[];for(let i=0;i<l;i++){const r=i/l,n=(i+1)/l;t.push(r,-.5,r,0),t.push(n,-.5,n,0),t.push(r,.5,r,1),t.push(r,.5,r,1),t.push(n,-.5,n,0),t.push(n,.5,n,1)}return new Float32Array(t)}(16),Ss:96,Fs:WebGL2RenderingContext.TRIANGLES,_s:16,ds:{fs:{size:2,offset:0},ps:{size:2,offset:8}}};class Lt extends z{constructor(t,i){super(t,i,R.BEZIER_CURVE,Pt)}ks(t,i){const r=i.W||1,n=nt(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=nt(.5,t.y1,t.cp1y,t.cp2y,t.y2),h=this.we(0,0,1,r,i);return this.xe(h,n,o),h.se=[t.x1,t.y1],h.Qs=[t.cp1x,t.cp1y],h.te=[t.cp2x,t.cp2y],h.ee=[t.x2,t.y2],this.me.ks(h)}}class St{constructor(t){c(this,"gt");c(this,"Me",null);c(this,"Re");c(this,"Fe",null);c(this,"Se",{});c(this,"Te",null);c(this,"Ae",new Map);c(this,"ze");c(this,"ke");c(this,"Ee");c(this,"I",[]);this.gt=t,this.Re=new mt(t),this.Ee=new st,this.ze=new vt(t,this),this.ke=new yt,this.Te=t.createBuffer(),H(this.gt,[0,0,this.gt.canvas.width,this.gt.canvas.height])}Pe(t){let i=this.Ae.get(t);if(i)return i;const r=new xt(this.gt);return i=(0,{[R.RECTANGLE]:()=>new wt(this.gt,r),[R.LINE]:()=>new At(this.gt,r),[R.ELLIPSE]:()=>new bt(this.gt,r),[R.ARC]:()=>new _t(this.gt,r),[R.TRIANGLE]:()=>new Ft(this.gt,r),[R.BEZIER_CURVE]:()=>new Lt(this.gt,r)}[t])(),this.Ae.set(t,i),i}Le(t){this.Me!==t&&(this.Me=t,t.Ht())}cs(t,i){return this.Re.cs(t,i)}es(){return this.Re.es()}At(){return this.Re.At()}rs(){return this.Re.rs()}ns(){return this.Re.ns()}De(t){this.Fe=t,t&&(this.Se={})}Nt(t,i){this.Se[t]=i}Be(t){Object.assign(this.Se,t)}hs(t){return this.Re.hs(t)}Ge(t,i,r,n,o){const h=this.es(),a={Ue:t.textures[0],Uf:t.textures[1],Ug:t.textures[2],Uh:t.textures[3],Ui:t.textures[4],Uj:[t.width,t.height]};this.ke.Ws(i,r,n,o,h,a,this.Ee)}Ie(t,i,r,n,o){const h=this.ns(),a=t.Oe(),u={Uk:a.texture,Ul:!!a.invert,Um:!!a.flipX,Un:!!a.flipY,Uo:a.charRotation,Up:a.charColorFixed,Uq:a.charColor,Ur:a.cellColorFixed,Us:a.cellColor,Ut:a.backgroundColor,Uu:a.charCount,Uv:a.charList};this.ke.Ws(i,r,n,o,h,u,this.Ee)}We(t,i,r,n){var m;const o=this.gt,h=o.canvas.width,a=o.canvas.height,u=t/h*2-1,f=(t+r)/h*2-1,g=1-i/a*2,d=1-(i+n)/a*2,v=new Float32Array([u,d,f,d,u,g,f,d,f,g,u,g]);o.bindBuffer(o.ARRAY_BUFFER,this.Te),o.bufferData(o.ARRAY_BUFFER,v,o.DYNAMIC_DRAW);const x=((m=this.Me)==null?void 0:m.Zt)||o.getParameter(o.CURRENT_PROGRAM),p=x?o.getAttribLocation(x,"a_position"):-1;p!==-1&&(o.enableVertexAttribArray(p),o.vertexAttribPointer(p,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),p!==-1&&o.disableVertexAttribArray(p)}He(t,i,r,n){this.Fe?(this.ke.Ws(t,i,r,n,this.Fe,{...this.Se},this.Ee),this.Fe=null,this.Se={}):this.ke.Os(t,i,r,n,this.Ee)}Ke(t,i,r,n){this.ke.Hs(t,i,r,n,this.Ee.lineWeight,this.Ee)}Xe(t,i,r,n){this.ke.Ks(t,i,r,n,this.Ee)}Ne(t,i,r,n,o,h){this.ke.Ns(t,i,r,n,o,h,this.Ee)}je(t,i,r,n,o,h,a,u){const f=this.Ee.lineWeight;this.ke.js(t,i,r,n,o,h,a,u,f,this.Ee)}Ye(t,i,r=1,n={}){return new V(this.gt,t,i,r,n,this,!0)}Ve(t,i,r,n,o,h){this.ke.Xs(t,i,r,n,o,h,this.Ee)}qe(t,i=t,r=t,n=255){this.Ee.ft(t,i,r,n),this.Ys(t/255,i/255,r/255,n/255)}Ys(t=0,i=0,r=0,n=0){this.gt.clearColor(t,i,r,n),this.gt.clear(this.gt.COLOR_BUFFER_BIT)}Ze(){this.gt.viewport(0,0,this.gt.canvas.width,this.gt.canvas.height),H(this.gt,[0,0,this.gt.canvas.width,this.gt.canvas.height])}get context(){return this.gt}get state(){return this.Ee}kt(t){this.I.push(this.Ee),this.Ee=t}Et(){const t=this.I.pop();t&&(this.Ee=t)}zt(t){const i=t,r=$(this.gt)??this.gt.getParameter(this.gt.VIEWPORT),n={shader:i,gl:this.gt,viewport:r};this.Le(i);const o=new Set;for(const h of this.ke)h.type===R.CUSTOM?o.add(R.RECTANGLE):o.add(h.type);for(const h of o)h!==R.CUSTOM&&this.Pe(h);this.ze.bs(n,this.ke,this.Ae),this.ke.Ys()}Pt(){this.gt.deleteBuffer(this.Te),this.ke.Ys();for(const t of this.Ae.values())t.Pt();this.Re.Pt(),this.ze.Pt()}}const b={readShort:(l,t)=>(b.t.uint16[0]=l[t]<<8|l[t+1],b.t.int16[0]),readUshort:(l,t)=>l[t]<<8|l[t+1],readUshorts(l,t,i){const r=[];for(let n=0;n<i;n++)r.push(b.readUshort(l,t+2*n));return r},readUint(l,t){const i=b.t.uint8;return i[3]=l[t],i[2]=l[t+1],i[1]=l[t+2],i[0]=l[t+3],b.t.uint32[0]},readASCII(l,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(l[t+n]);return r},writeUshort(l,t,i){l[t]=i>>>8&255,l[t+1]=255&i},writeUint(l,t,i){l[t]=i>>>24&255,l[t+1]=i>>>16&255,l[t+2]=i>>>8&255,l[t+3]=255&i},writeASCII(l,t,i){for(let r=0;r<i.length;r++)l[t+r]=255&i.charCodeAt(r)},t:(()=>{const l=new ArrayBuffer(8);return{uint8:new Uint8Array(l),int16:new Int16Array(l),uint16:new Uint16Array(l),uint32:new Uint32Array(l)}})()};function j(l){return l+3&-4}function Q(l,t,i){const r=t+i;let n=0;const o=b.t;for(let h=t;h<r;h+=4)o.uint8[3]=l[h]||0,o.uint8[2]=l[h+1]||0,o.uint8[1]=l[h+2]||0,o.uint8[0]=l[h+3]||0,n=n+(o.uint32[0]>>>0)>>>0;return n>>>0}class It{constructor(t){c(this,"b");c(this,"p",0);c(this,"bitbuf",0);c(this,"bitcnt",0);this.b=t}readBits(t){for(;this.bitcnt<t;){const r=this.b[this.p++]||0;this.bitbuf|=r<<this.bitcnt,this.bitcnt+=8}const i=this.bitbuf&(1<<t)-1;return this.bitbuf>>>=t,this.bitcnt-=t,i}alignToByte(){this.bitbuf=0,this.bitcnt=0}get offset(){return this.p}}function X(l){let t=32,i=0;for(const a of l)a&&(a<t&&(t=a),a>i&&(i=a));if(i===0)return{min:0,max:0,table:new Map};const r=new Uint32Array(i+1);for(const a of l)a&&r[a]++;const n=new Uint32Array(i+1);let o=0;r[0]=0;for(let a=1;a<=i;a++)o=o+r[a-1]<<1,n[a]=o;const h=new Map;for(let a=0;a<l.length;a++){const u=l[a];if(!u)continue;const f=n[u]++;let g=h.get(u);g||(g=[],h.set(u,g)),g[Mt(f,u)]=a}return{min:t,max:i,table:h}}function tt(l,t){let i=0;for(let r=1;r<=t.max;r++){i|=l.readBits(1)<<r-1;const n=t.table.get(r);if(n&&i<n.length){const o=n[i];if(o!==void 0)return o}}throw Error("Invalid Huffman code")}function Mt(l,t){let i=0;for(let r=0;r<t;r++)i=i<<1|1&l,l>>>=1;return i>>>0}function Gt(l){if(l.length<2)throw Error("ZLIB data too short");const t=l[0],i=l[1];if((15&t)!=8)throw Error("Unsupported ZLIB compression method");if(((t<<8)+i)%31!=0)throw Error("Bad ZLIB header check");let r=2;32&i&&(r+=4);const n=[];return function(o,h){const a=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258],u=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],f=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],g=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13];let d=0;for(;!d;){d=o.readBits(1);const v=o.readBits(2);if(v===0){o.alignToByte();const x=o.readBits(16);if((65535&(65535^x))!==o.readBits(16))throw Error("DEFLATE uncompressed LEN/NLEN mismatch");for(let p=0;p<x;p++)h.push(o.readBits(8))}else{if(v!==1&&v!==2)throw Error("Unsupported DEFLATE type");{let x,p;if(v===1){const m=Array(288).fill(0);for(let E=0;E<=143;E++)m[E]=8;for(let E=144;E<=255;E++)m[E]=9;for(let E=256;E<=279;E++)m[E]=7;for(let E=280;E<=287;E++)m[E]=8;x=X(m),p=X(Array(32).fill(5))}else{const m=o.readBits(5)+257,E=o.readBits(5)+1,y=o.readBits(4)+4,A=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],w=Array(19).fill(0);for(let L=0;L<y;L++)w[A[L]]=o.readBits(3);const P=X(w),U=[];for(;U.length<m+E;){const L=tt(o,P);if(L<=15)U.push(L);else if(L===16){const Y=o.readBits(2)+3,O=U[U.length-1]||0;for(let gt=0;gt<Y;gt++)U.push(O)}else if(L===17){const Y=o.readBits(3)+3;for(let O=0;O<Y;O++)U.push(0)}else{if(L!==18)throw Error("Invalid code length symbol");{const Y=o.readBits(7)+11;for(let O=0;O<Y;O++)U.push(0)}}}const F=U.slice(0,m),S=U.slice(m,m+E);x=X(F),p=X(S)}for(;;){const m=tt(o,x);if(m<256)h.push(m);else{if(m===256)break;if(m>256&&m<286){const E=m-257;let y=a[E];const A=u[E];A&&(y+=o.readBits(A));const w=tt(o,p);if(w>=30)throw Error("Invalid distance symbol");let P=f[w];const U=g[w];U&&(P+=o.readBits(U));const F=h.length-P;if(F<0)throw Error("Invalid distance");for(let S=0;S<y;S++)h.push(h[F+S]||0)}else if(m===286||m===287)throw Error("Reserved length symbol")}}}}}}(new It(l.subarray(r)),n),new Uint8Array(n)}function Dt(l){const t=b,i=new Uint8Array(l);if(t.readASCII(i,0,4)!=="wOFF")throw Error("Invalid WOFF signature");const r=t.readUint(i,4),n=t.readUshort(i,12),o=t.readUint(i,16),h=[];let a=44;for(let y=0;y<n;y++){const A=t.readASCII(i,a,4),w=t.readUint(i,a+4),P=t.readUint(i,a+8),U=t.readUint(i,a+12),F=t.readUint(i,a+16);h.push({tag:A,offset:w,compLength:P,origLength:U,checksum:F}),a+=20}for(const y of h){const A=new Uint8Array(i.buffer,y.offset,y.compLength);if(y.compLength===y.origLength)y.data=new Uint8Array(A);else if(y.data=Gt(A),y.data.length!==y.origLength)if(y.data.length<y.origLength){const w=new Uint8Array(y.origLength);w.set(y.data),y.data=w}else y.data=y.data.subarray(0,y.origLength)}const u=n;let f=1,g=0;for(;f<<1<=u;)f<<=1,g++;const d=16*f,v=16*u-d;let x=12+16*u;const p={};for(const y of h)p[y.tag]=x,x=j(x+y.data.length);const m=new Uint8Array(Math.max(o||0,x));t.writeUint(m,0,r),t.writeUshort(m,4,u),t.writeUshort(m,6,d),t.writeUshort(m,8,g),t.writeUshort(m,10,v);let E=12;for(const y of h){t.writeASCII(m,E,y.tag),E+=4;let A=y.data;if(y.tag==="head"&&A.length>=12){const w=new Uint8Array(A);t.writeUint(w,8,0);const P=Q(w,0,j(w.length));t.writeUint(m,E,P),E+=4}else{const w=Q(A,0,j(A.length));t.writeUint(m,E,w),E+=4}t.writeUint(m,E,p[y.tag]),E+=4,t.writeUint(m,E,y.data.length),E+=4}for(const y of h){const A=p[y.tag];m.set(y.data,A)}if(h.find(y=>y.tag==="head")){const y=p.head,A=function(w,P){const U=b,F=P+8,S=[w[F],w[F+1],w[F+2],w[F+3]];U.writeUint(w,F,0);const L=2981146554-(Q(w,0,j(w.length))>>>0)>>>0;return w[F]=S[0],w[F+1]=S[1],w[F+2]=S[2],w[F+3]=S[3],L>>>0}(m,y);t.writeUint(m,y+8,A)}return m.buffer}const Bt={parseTab(l,t,i){const r={tables:[],ids:{},off:t};l=new Uint8Array(l.buffer,t,i),t=0;const n=b,o=n.readUshort,h=o(l,t+=2);t+=2;const a=[];for(let u=0;u<h;u++){const f=o(l,t),g=o(l,t+=2);t+=2;const d=n.readUint(l,t);t+=4;const v=`p${f}e${g}`;let x=a.indexOf(d);if(x===-1){let p;x=r.tables.length,a.push(d);const m=o(l,d);p=m===4?this.parse4(l,d):m===12?this.parse12(l,d):{format:m},r.tables.push(p)}r.ids[v]=x}return r},parse4(l,t){const i=b,r=i.readUshort,n=i.readUshorts,o=t,h=r(l,t+=2);t+=2;const a=r(l,t+=2)>>>1,u={format:4,searchRange:r(l,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,u.entrySelector=r(l,t),t+=2,u.rangeShift=r(l,t),t+=2,u.endCount=n(l,t,a),t+=2*a,t+=2,u.startCount=n(l,t,a),t+=2*a;for(let f=0;f<a;f++)u.idDelta.push(i.readShort(l,t)),t+=2;return u.idRangeOffset=n(l,t,a),t+=2*a,u.glyphIdArray=n(l,t,o+h-t>>1),u},parse12(l,t){const i=b.readUint;i(l,t+=4),i(l,t+=4);const r=i(l,t+=4);t+=4;const n=new Uint32Array(3*r);for(let o=0;o<3*r;o+=3)n[o]=i(l,t+(o<<2)),n[o+1]=i(l,t+(o<<2)+4),n[o+2]=i(l,t+(o<<2)+8);return{format:12,groups:n}}},Ot={parseTab(l,t,i){const r=b;t+=18;const n=r.readUshort(l,t);t+=2,t+=16;const o=r.readShort(l,t);t+=2;const h=r.readShort(l,t);t+=2;const a=r.readShort(l,t);t+=2;const u=r.readShort(l,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:h,xMax:a,yMax:u,indexToLocFormat:r.readShort(l,t)}}},kt={parseTab(l,t,i){const r=b;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let h=0;h<n.length;h++){const a=n[h],u=a==="advanceWidthMax"||a==="numberOfHMetrics"?r.readUshort:r.readShort;o[a]=u(l,t+2*h)}return o}},zt={parseTab(l,t,i,r){const n=b,o=[],h=[],a=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,g=0,d=0;for(;d<u;)f=n.readUshort(l,t+(d<<2)),g=n.readShort(l,t+(d<<2)+2),o.push(f),h.push(g),d++;for(;d<a;)o.push(f),h.push(g),d++;return{aWidth:o,lsBearing:h}}},ot={cmap:Bt,head:Ot,hhea:kt,maxp:{parseTab(l,t,i){const r=b;return r.readUint(l,t),t+=4,{numGlyphs:r.readUshort(l,t)}}},hmtx:zt,loca:{parseTab(l,t,i,r){const n=b,o=[],h=r.head.indexToLocFormat,a=r.maxp.numGlyphs+1;if(h===0)for(let u=0;u<a;u++)o.push(n.readUshort(l,t+(u<<1))<<1);else if(h===1)for(let u=0;u<a;u++)o.push(n.readUint(l,t+(u<<2)));return o}},glyf:{parseTab(l,t,i,r){const n=[],o=r.maxp.numGlyphs;for(let h=0;h<o;h++)n.push(null);return n},Je(l,t){const i=b,r=l.Qe,n=l.loca;if(n[t]===n[t+1])return null;const o=I.findTable(r,"glyf",l.ti);if(!o)return null;let h=o[0]+n[t];const a={};if(a.noc=i.readShort(r,h),h+=2,a.xMin=i.readShort(r,h),h+=2,a.yMin=i.readShort(r,h),h+=2,a.xMax=i.readShort(r,h),h+=2,a.yMax=i.readShort(r,h),h+=2,a.xMin>=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(let v=0;v<a.noc;v++)a.endPts.push(i.readUshort(r,h)),h+=2;const u=i.readUshort(r,h);if(h+=2,r.length-h<u)return null;h+=u;const f=a.endPts[a.noc-1]+1;a.flags=[];for(let v=0;v<f;v++){const x=r[h];if(h++,a.flags.push(x),8&x){const p=r[h];h++;for(let m=0;m<p;m++)a.flags.push(x),v++}}a.xs=[];for(let v=0;v<f;v++){const x=a.flags[v],p=!!(16&x);2&x?(a.xs.push(p?r[h]:-r[h]),h++):p?a.xs.push(0):(a.xs.push(i.readShort(r,h)),h+=2)}a.ys=[];for(let v=0;v<f;v++){const x=a.flags[v],p=!!(32&x);4&x?(a.ys.push(p?r[h]:-r[h]),h++):p?a.ys.push(0):(a.ys.push(i.readShort(r,h)),h+=2)}let g=0,d=0;for(let v=0;v<f;v++)g+=a.xs[v],d+=a.ys[v],a.xs[v]=g,a.ys[v]=d}else a.parts=[],a.endPts=[],a.flags=[],a.xs=[],a.ys=[];return a}}},I={parse(l){const t=new Uint8Array(l),i=b.readASCII(t,0,4);if(i==="wOFF")l=Dt(l);else if(i==="wOF2")throw Error("WOFF2 is not supported in this build (Brotli + WOFF2 transforms required)");return[((r,n,o,h)=>{const a=ot,u={Qe:r,si:n,ti:o};for(const f in a){const g=f,d=I.findTable(r,g,o);if(d){const[v,x]=d;let p=h[v];p==null&&(p=a[g].parseTab(r,v,x,u),h[v]=p),u[g]=p}}return u})(new Uint8Array(l),0,0,{})]},findTable(l,t,i){const r=b,n=r.readUshort(l,i+4);let o=i+12;for(let h=0;h<n;h++){const a=r.readASCII(l,o,4);r.readUint(l,o+4);const u=r.readUint(l,o+8),f=r.readUint(l,o+12);if(a===t)return[u,f];o+=16}return null},T:ot,B:b};class Nt{ei(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ii(n);i.push(...o)}else if(n.format===12){const o=this.ri(n);i.push(...o)}}),[...new Set(i)]):[]}ni(t){return t.filter(i=>this.oi(i))}ii(t){const i=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return i;for(let r=0;r<t.startCount.length;r++){const n=t.startCount[r],o=t.endCount[r];if(n!==65535||o!==65535){for(let h=n;h<=o;h++)if(this.hi(t,h,r)>0)try{const a=String.fromCodePoint(h);i.push(a)}catch{}}}return i}ri(t){const i=[];if(!t.groups)return i;for(let r=0;r<t.groups.length;r+=3){const n=t.groups[r],o=t.groups[r+1],h=t.groups[r+2];for(let a=n;a<=o;a++)if(h+(a-n)>0)try{const u=String.fromCodePoint(a);i.push(u)}catch{}}return i}hi(t,i,r){if(t.idRangeOffset[r]===0)return i+t.idDelta[r]&65535;{const n=t.idRangeOffset[r]/2+(i-t.startCount[r])-(t.startCount.length-r);if(n>=0&&t.glyphIdArray&&n<t.glyphIdArray.length){const o=t.glyphIdArray[n];if(o!==0)return o+t.idDelta[r]&65535}}return 0}oi(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class et{constructor(){c(this,"ai",new Map);c(this,"ci",new Map)}li(t,i){const r=`${this.ui(t)}_${i}`;if(this.ai.has(r))return this.ai.get(r);const n=t.cmap;if(!n||!n.tables)return this.ai.set(r,0),0;let o=0;for(const h of n.tables)if(h.format===4?o=this.fi(i,h):h.format===12&&(o=this.di(i,h)),o>0)break;return this.ai.set(r,o),o}_i(t,i){const r=i.codePointAt(0);return r===void 0?0:this.li(t,r)}pi(t,i){const r=t.hmtx;return r&&r.aWidth&&r.aWidth.length!==0?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}mi(t,i){const r=i/t.head.unitsPerEm,n=t.hhea.ascender*r,o=t.hhea.descender*r,h=t.hhea.lineGap*r;return{ascender:n,descender:o,lineGap:h,lineHeight:n-o+h,unitsPerEm:t.head.unitsPerEm,scale:r}}gi(){this.ai.clear(),this.ci.clear()}ui(t){return`${t.ti}_${t.Qe.length}`}fi(t,i){const r=i.endCount.length;let n=-1;for(let o=0;o<r;o++)if(t<=i.endCount[o]){n=o;break}if(n===-1||t<i.startCount[n])return 0;if(i.idRangeOffset[n]===0)return t+i.idDelta[n]&65535;{const o=i.idRangeOffset[n]/2+(t-i.startCount[n])-(r-n);if(o>=0&&o<i.glyphIdArray.length){const h=i.glyphIdArray[o];return h===0?0:h+i.idDelta[n]&65535}}return 0}di(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const o=i.groups[3*n],h=i.groups[3*n+1],a=i.groups[3*n+2];if(t>=o&&t<=h)return a+(t-o)}return 0}}class Wt{constructor(t){c(this,"yi");c(this,"Ci");c(this,"xt");c(this,"wi");this.xt=t,this.wi=new et,this.yi=document.createElement("canvas"),this.Ci=this.yi.getContext("2d",{willReadFrequently:!0,alpha:!0})}createTextureAtlas(t,i,r,n){const o=t.length,h=Math.ceil(Math.sqrt(o)),a=Math.ceil(o/h),u=i.width*h,f=i.height*a,g=typeof n=="object"?n:null;this.bi(u,f),this.$i(t,i,h,r,g);const d=this.xt.Ye(u,f,1,{filter:"nearest"});return d.Tt(this.yi),{framebuffer:d,columns:h,rows:a}}bi(t,i){this.yi.width=t,this.yi.height=i,this.yi.style.width=t+"px",this.yi.style.height=i+"px",this.Ci.imageSmoothingEnabled=!1,this.yi.style.imageRendering="pixelated",this.Ci.clearRect(0,0,t,i),this.Ci.textBaseline="top",this.Ci.textAlign="left",this.Ci.fillStyle="white"}$i(t,i,r,n,o){const h=n/o.head.unitsPerEm;for(let a=0;a<t.length;a++){const u=a%r,f=Math.floor(a/r),g=t[a].character,d=this.xi(o,g);if(!d)continue;const v=g.codePointAt(0)||0,x=this.wi.li(o,v),p=this.Mi(o,x)*h,m=u*i.width,E=f*i.height,y=m+.5*i.width,A=E+.5*i.height,w=Math.round(y-.5*i.width),P=Math.round(A-.5*n),U=w+.5*(i.width-p),F=P+o.hhea.ascender*h;this.Ri(d,U,F,h)}}xi(t,i){const r=i.codePointAt(0)||0,n=this.wi.li(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(I&&I.T&&I.T.glyf){const o=I.T.glyf.Je(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}Mi(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}Ri(t,i,r,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:h,endPts:a,flags:u}=t;if(!(o&&h&&a&&u))return;this.Ci.beginPath();let f=0;for(let g=0;g<a.length;g++){const d=a[g];if(!(d<f)){if(d>=f){const v=i+o[f]*n,x=r-h[f]*n;this.Ci.moveTo(v,x);let p=f+1;for(;p<=d;)if(1&u[p]){const m=i+o[p]*n,E=r-h[p]*n;this.Ci.lineTo(m,E),p++}else{const m=i+o[p]*n,E=r-h[p]*n;let y=p+1>d?f:p+1;if(1&u[y]){const A=i+o[y]*n,w=r-h[y]*n;this.Ci.quadraticCurveTo(m,E,A,w),p=y+1}else{const A=(m+(i+o[y]*n))/2,w=(E+(r-h[y]*n))/2;this.Ci.quadraticCurveTo(m,E,A,w),p=y}}this.Ci.closePath()}f=d+1}}this.Ci.fill()}}class Xt{constructor(){c(this,"Fi");this.Fi=new et}Si(t,i,r){let n=0;const o=this.Fi.mi(r,i),h=o.lineHeight;for(const a of t){const u=this.Fi._i(r,a);if(u===0)continue;const f=this.Fi.pi(r,u)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(h)}}gi(){this.Fi.gi()}}class Yt{constructor(){c(this,"wi");this.wi=new et}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,h=this.Ti(n);let a=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.wi.li(i,o);u>0&&i.hmtx.aWidth[u]!==void 0&&(a=i.hmtx.aWidth[u])}return{character:r,unicode:o,color:h,advanceWidth:a}})}Ti(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}Ai(t,i){if(!W.v(typeof t=="string","Character must be a string.",{method:"getCharacterColor",providedValue:t}))return[0,0,0];const r=i.find(n=>n.character===t);return r?r.color:[0,0,0]}zi(t,i){return W.v(typeof t=="string"&&t.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:t})?Array.from(t).map(r=>this.Ai(r,i)||[0,0,0]):[[0,0,0]]}}class ht{constructor(t,i=16){c(this,"ki");c(this,"Ei",[]);c(this,"Pi");c(this,"Li",16);c(this,"Di",0);c(this,"Bi",0);c(this,"Gi",{width:0,height:0});c(this,"Ii");c(this,"Oi",new Map);c(this,"Wi");c(this,"Hi");c(this,"Ki");c(this,"Xi");this.Li=i,this.Wi=new Nt,this.Hi=new Wt(t),this.Ki=new Xt,this.Xi=new Yt}async Ni(t){let i;if(!t)throw new T("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const r=await fetch(t);if(!r.ok)throw new T(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}await this.ji(i),this.ki=I.parse(i)[0],await this.Yi()}Vi(t){if(t===void 0)return this.Li;this.Li=t,this.Gi=this.Ki.Si(this.Ei.map(r=>r.character),this.Li,this.ki);const i=this.Hi.createTextureAtlas(this.Ei,this.Gi,this.Li,this.ki);this.Pi=i.framebuffer,this.Di=i.columns,this.Bi=i.rows}async qi(t){try{const i=await fetch(t);if(!i.ok)throw new T(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.ji(r);const n=I.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.ki=n[0],await this.Yi()}catch(i){throw new T("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async ji(t){const i=Date.now();this.Ii=new FontFace("CustomFont_"+i,t),await this.Ii.load(),document.fonts.add(this.Ii)}async Yi(){const t=this.Wi.ei(this.ki),i=this.Wi.ni(t);this.Oi.clear(),this.Ei=this.Xi.createCharacterObjects(i,this.ki),this.Gi=this.Ki.Si(i,this.Li,this.ki);const r=this.Hi.createTextureAtlas(this.Ei,this.Gi,this.Li,this.ki);this.Pi=r.framebuffer,this.Di=r.columns,this.Bi=r.rows}Ai(t){return this.Xi.Ai(t,this.Ei)}zi(t){return this.Xi.zi(t,this.Ei)}getGlyphData(t){if(!Number.isFinite(t))return null;const i=this.Oi.get(t);if(i!==void 0)return i;const r=this.Zi(t);if(r<0)return this.Oi.set(t,null),null;const n=this.ki.glyf;if(!n)return this.Oi.set(t,null),null;let o=n[r]??null;return o==null&&(o=I.T.glyf.Je(this.ki,r)??null,n[r]=o),this.Oi.set(t,o),o}Zi(t){const i=this.ki.cmap;for(const r of i.tables)if(r.format===4){const n=r;for(let o=0;o<n.startCount.length;o++)if(t>=n.startCount[o]&&t<=n.endCount[o]){if(n.idRangeOffset[o]===0)return t+n.idDelta[o]&65535;{const h=n.idRangeOffset[o]/2+(t-n.startCount[o])-(n.startCount.length-o);if(h>=0&&h<n.glyphIdArray.length){const a=n.glyphIdArray[h];if(a!==0)return a+n.idDelta[o]&65535}}}}else if(r.format===12){const n=r;for(let o=0;o<n.groups.length;o+=3){const h=n.groups[o],a=n.groups[o+1],u=n.groups[o+2];if(t>=h&&t<=a)return u+(t-h)}}return 0}Pt(){this.Pi.Pt(),document.fonts.delete(this.Ii)}get fontFramebuffer(){return this.Pi}get characters(){return this.Ei}get textureColumns(){return this.Di}get textureRows(){return this.Bi}get maxGlyphDimensions(){return this.Gi}get fontSize(){return this.Li}get font(){return this.ki}}class at{constructor(t,i,r){c(this,"Ji");c(this,"Qi");c(this,"dt");c(this,"_t");c(this,"tr");c(this,"sr");c(this,"er");c(this,"ir");c(this,"rr");this.er=t,this.ir=i,this.rr=r,this.nr()}nr(){this.Ji=Math.floor(this.er.width/this.ir),this.Qi=Math.floor(this.er.height/this.rr),this.dt=this.Ji*this.ir,this._t=this.Qi*this.rr,this.tr=Math.floor((this.er.width-this.dt)/2),this.sr=Math.floor((this.er.height-this._t)/2)}hr(t,i){this.ir=t,this.rr=i,this.nr()}get cellWidth(){return this.ir}get cellHeight(){return this.rr}get cols(){return this.Ji}get rows(){return this.Qi}get width(){return this.dt}get height(){return this._t}get offsetX(){return this.tr}get offsetY(){return this.sr}}class ct{constructor(t={}){c(this,"er");c(this,"ar",null);c(this,"cr",!1);c(this,"lr");c(this,"ur");this.cr=t.overlay??!1,this.cr&&t.canvas?(this.ar=t.canvas,this.er=this.dr(),this.ur=!0,this._r()):t.canvas?(this.er=t.canvas,this.ur=!1):(this.er=this.pr(t.width,t.height),this.ur=!0),this.er.style.imageRendering="pixelated"}pr(t,i){const r=document.createElement("canvas");return r.className="textmodeCanvas",r.style.imageRendering="pixelated",r.width=t||800,r.height=i||600,document.body.appendChild(r),r}dr(){const t=document.createElement("canvas");t.className="textmodeCanvas",t.style.imageRendering="pixelated";const i=this.ar.getBoundingClientRect();let r=Math.round(i.width),n=Math.round(i.height);if(this.ar instanceof HTMLVideoElement){const a=this.ar;(r===0||n===0)&&a.videoWidth>0&&a.videoHeight>0&&(r=a.videoWidth,n=a.videoHeight)}t.width=r,t.height=n,t.style.position="absolute",t.style.pointerEvents="none";const o=window.getComputedStyle(this.ar);let h=parseInt(o.zIndex||"0",10);return isNaN(h)&&(h=0),t.style.zIndex=""+(h+1),t}_r(){var t;this.mr(),(t=this.ar.parentNode)==null||t.insertBefore(this.er,this.ar.nextSibling),window.ResizeObserver&&(this.lr=new ResizeObserver(()=>{this.vr()}),this.lr.observe(this.ar)),window.addEventListener("resize",()=>{this.vr()})}mr(){if(!this.ar)return;const t=this.ar.getBoundingClientRect();let i=this.ar.offsetParent;if(i&&i!==document.body){const r=i.getBoundingClientRect();this.er.style.top=t.top-r.top+"px",this.er.style.left=t.left-r.left+"px"}else this.er.style.top=t.top+window.scrollY+"px",this.er.style.left=t.left+window.scrollX+"px"}vr(t,i){if(this.cr){const r=this.ar.getBoundingClientRect();let n=Math.round(r.width),o=Math.round(r.height);if(this.ar instanceof HTMLVideoElement){const h=this.ar;(n===0||o===0)&&h.videoWidth>0&&h.videoHeight>0&&(n=h.videoWidth,o=h.videoHeight)}this.er.width=n,this.er.height=o,this.mr()}else this.er.width=t??this.er.width,this.er.height=i??this.er.height}gr(){const t=this.er.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new T("`textmode.js` requires WebGL2 support.");return t}Pt(){this.lr&&this.lr.disconnect();const t=this.er.getContext("webgl")||this.er.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.ur&&this.er.parentNode&&this.er.parentNode.removeChild(this.er)}get canvas(){return this.er}get targetCanvas(){return this.ar}get width(){return this.er.width}get height(){return this.er.height}}class N{constructor(t,i,r,n){c(this,"yr");c(this,"dt");c(this,"_t");c(this,"gt");c(this,"L",0);c(this,"N",0);c(this,"j",0);c(this,"D",[0,0]);c(this,"Cr","sampled");c(this,"wr","fixed");c(this,"V",[1,1,1,1]);c(this,"q",[0,0,0,1]);c(this,"br",[0,0,0,1]);c(this,"$r",[[.1,0,0]]);c(this,"Mr");this.gt=t,this.yr=i,this.dt=r,this._t=n}Pt(){this.gt.deleteTexture(this.yr)}Rr(t){return typeof t=="boolean"?t?1:0:(t==null?0:Number(t))>0?1:0}invert(t=!0){return this.L=this.Rr(t),this}flipX(t=!0){return this.N=this.Rr(t),this}flipY(t=!0){return this.j=this.Rr(t),this}charRotation(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));return this.D=[r,n],this}Oe(){return{texture:this.yr,invert:this.L,flipX:this.N,flipY:this.j,charRotation:this.D,charColorFixed:this.Cr==="fixed",charColor:this.V,cellColorFixed:this.wr==="fixed",cellColor:this.q,backgroundColor:this.br,charCount:this.$r.length,charList:this.$r}}charColorMode(t){return this.Cr=t,this}cellColorMode(t){return this.wr=t,this}charColor(t,i,r,n){return this.V=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}cellColor(t,i,r,n){return this.q=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}background(t,i,r,n){return this.br=[(t??0)/255,(i??t??0)/255,(r??t??0)/255,(n??255)/255],this}characters(t){const i=this.Mr(t).filter(r=>Array.isArray(r)).slice(0,64);return this.$r=i,this}static Fr(t,i,r){const n=t.context,o=n.createTexture();n.bindTexture(n.TEXTURE_2D,o),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,1),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i),n.bindTexture(n.TEXTURE_2D,null);const h=i.naturalWidth??i.width??i.videoWidth??0,a=i.naturalHeight??i.height??i.videoHeight??0,u=new N(n,o,h,a);return u.Mr=r,u}get texture(){return this.yr}get width(){return this.dt}get height(){return this._t}}class Ht{constructor(t=60){c(this,"Sr");c(this,"Tr");c(this,"Ar",null);c(this,"zr",0);c(this,"kr",!0);c(this,"Er",0);c(this,"Pr",0);c(this,"Lr",[]);c(this,"Dr",10);c(this,"Br",0);this.Sr=t,this.Tr=1e3/t}start(t){if(!this.kr)return;this.zr=performance.now();const i=r=>{if(!this.kr)return void(this.Ar=null);const n=r-this.zr;n>=this.Tr&&(t(),this.zr=r-n%this.Tr),this.kr&&(this.Ar=requestAnimationFrame(i))};this.Ar=requestAnimationFrame(i)}stop(){this.Ar&&(cancelAnimationFrame(this.Ar),this.Ar=null)}pause(){this.kr&&(this.kr=!1,this.stop())}resume(t){this.kr||(this.kr=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.Er;this.Sr=t,this.Tr=1e3/t,this.kr&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.Pr>0){const i=t-this.Pr;this.Lr.push(i),this.Lr.length>this.Dr&&this.Lr.shift();const r=this.Lr.reduce((n,o)=>n+o,0)/this.Lr.length;this.Er=1e3/r}this.Pr=t}get isLooping(){return this.kr}get frameRateLimit(){return this.Sr}get currentFrameRate(){return this.Er}get frameCount(){return this.Br}set frameCount(t){this.Br=t}incrementFrame(){this.Br++}resetFrameCount(){this.Br=0}}class lt{constructor(t){c(this,"er");c(this,"Gr");c(this,"Ir",{x:-1,y:-1});c(this,"Or",{x:-1,y:-1});c(this,"Wr",null);c(this,"Hr",0);c(this,"Kr");c(this,"Xr");c(this,"Nr");c(this,"jr");c(this,"Yr");c(this,"Vr");c(this,"qr",!1);c(this,"Zr");c(this,"Jr");c(this,"Qr");c(this,"tn");c(this,"sn");this.er=t}en(t){const i=performance.now()+Math.max(0,t);i>this.Hr&&(this.Hr=i)}rn(){return performance.now()<this.Hr}nn(t){const i=this.er.canvas;i.style.cursor=t==null||t===""?"":t}Ni(t){this.Gr=t,this.hn()}an(){if(this.qr)return;const t=this.er.canvas;this.Kr=i=>{this.cn(i),this.ln(i)},this.Xr=()=>{this.Or={...this.Ir},this.Ir.x=-1,this.Ir.y=-1,this.Wr=null},this.Nr=i=>{this.cn(i),this.un(i)},this.jr=i=>{this.cn(i),this.fn(i)},this.Yr=i=>{this.cn(i),this.dn(i)},this.Vr=i=>{this.cn(i),this._n(i)},t.addEventListener("mousemove",this.Kr,{passive:!0}),t.addEventListener("mouseleave",this.Xr,{passive:!0}),t.addEventListener("mousedown",this.Nr,{passive:!0}),t.addEventListener("mouseup",this.jr,{passive:!0}),t.addEventListener("click",this.Yr,{passive:!0}),t.addEventListener("wheel",this.Vr,{passive:!1}),this.qr=!0}pn(){if(!this.qr)return;const t=this.er.canvas;t.removeEventListener("mousemove",this.Kr),t.removeEventListener("mouseleave",this.Xr),t.removeEventListener("mousedown",this.Nr),t.removeEventListener("mouseup",this.jr),t.removeEventListener("click",this.Yr),t.removeEventListener("wheel",this.Vr),this.qr=!1}hn(){if(this.qr)try{if(this.Wr){const t=new MouseEvent("mousemove",{clientX:this.Wr.x,clientY:this.Wr.y,bubbles:!1,cancelable:!1});this.cn(t)}else this.Ir.x!==-1&&this.Ir.y!==-1&&(this.Ir.x>=this.Gr.cols||this.Ir.y>=this.Gr.rows)&&(this.Ir.x=-1,this.Ir.y=-1)}catch{this.Ir.x=-1,this.Ir.y=-1}}mn(t){this.Zr=t}vn(t){this.Jr=t}gn(t){this.Qr=t}yn(t){this.tn=t}Cn(t){this.sn=t}wn(){return{x:this.Ir.x,y:this.Ir.y}}ln(t){if(this.tn&&!this.rn()){const i={position:{...this.Ir},previousPosition:{...this.Or},originalEvent:t};this.tn(i)}}un(t){if(this.Jr&&!this.rn()){const i={position:{...this.Ir},previousPosition:{...this.Or},button:t.button,originalEvent:t};this.Jr(i)}}fn(t){if(this.Qr&&!this.rn()){const i={position:{...this.Ir},previousPosition:{...this.Or},button:t.button,originalEvent:t};this.Qr(i)}}dn(t){if(this.Zr&&!this.rn()){const i={position:{...this.Ir},previousPosition:{...this.Or},button:t.button,originalEvent:t};this.Zr(i)}}_n(t){if(this.sn&&!this.rn()){const i={position:{...this.Ir},previousPosition:{...this.Or},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.sn(i)}}cn(t){const i=this.er.canvas;this.Or={...this.Ir},this.Wr={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,o=t.clientY-r.top,h=i.width/r.width,a=o*(i.height/r.height),u=n*h-this.Gr.offsetX,f=a-this.Gr.offsetY,g=Math.floor(u/this.Gr.cellWidth),d=Math.floor(f/this.Gr.cellHeight);g>=0&&g<this.Gr.cols&&d>=0&&d<this.Gr.rows?(this.Ir.x=g,this.Ir.y=d):(this.Ir.x=-1,this.Ir.y=-1)}}const $t=Object.freeze(Object.defineProperty({__proto__:null,MouseManager:lt},Symbol.toStringTag,{value:"Module"}));class ut{constructor(){c(this,"bn",new Map);c(this,"$n",null);c(this,"xn",null);c(this,"Mn");c(this,"Rn");c(this,"qr",!1);c(this,"Fn");c(this,"Sn");c(this,"Tn",{ArrowUp:"UP_ARROW",ArrowDown:"DOWN_ARROW",ArrowLeft:"LEFT_ARROW",ArrowRight:"RIGHT_ARROW",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",Enter:"ENTER",Return:"RETURN",Tab:"TAB",Escape:"ESCAPE",Backspace:"BACKSPACE",Delete:"DELETE",Insert:"INSERT",Home:"HOME",End:"END",PageUp:"PAGE_UP",PageDown:"PAGE_DOWN",Shift:"SHIFT",Control:"CONTROL",Alt:"ALT",Meta:"META"," ":"SPACE"})}an(){this.qr||(this.Mn=t=>{this.An(t)},this.Rn=t=>{this.zn(t)},window.addEventListener("keydown",this.Mn,{passive:!1}),window.addEventListener("keyup",this.Rn,{passive:!1}),this.qr=!0)}pn(){this.qr&&(window.removeEventListener("keydown",this.Mn),window.removeEventListener("keyup",this.Rn),this.qr=!1,this.bn.clear(),this.$n=null,this.xn=null)}vn(t){this.Fn=t}gn(t){this.Sn=t}kn(t){const i=this.En(t),r=this.bn.get(t)||this.bn.get(i);return(r==null?void 0:r.isPressed)||!1}Pn(){return this.$n}Ln(){return this.xn}Dn(){const t=[];for(const[i,r]of this.bn)r.isPressed&&t.push(i);return t}Bn(){return{ctrl:this.kn("Control"),shift:this.kn("Shift"),alt:this.kn("Alt"),meta:this.kn("Meta")}}Gn(){this.bn.clear(),this.$n=null,this.xn=null}An(t){const i=t.key,r=Date.now();this.bn.has(i)||this.bn.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.bn.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this.$n=i,this.Fn)){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.Fn(o)}}zn(t){const i=t.key,r=Date.now();this.bn.has(i)||this.bn.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.bn.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.xn=i,this.Sn){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.Sn(o)}}En(t){return this.Tn[t]||t.toLowerCase()}}const Vt=Object.freeze(Object.defineProperty({__proto__:null,KeyboardManager:ut},Symbol.toStringTag,{value:"Module"}));class ft{constructor(t,i){c(this,"er");c(this,"In");c(this,"Gr");c(this,"On",new Map);c(this,"Wn",new Map);c(this,"Hn",new Map);c(this,"Kn",null);c(this,"Xn");c(this,"Nn");c(this,"jn");c(this,"Yn");c(this,"Vn");c(this,"qn");c(this,"qr",!1);c(this,"Zn");c(this,"Jn");c(this,"Qn");c(this,"so");c(this,"eo");c(this,"io");c(this,"ro");c(this,"no");c(this,"oo");c(this,"ho");c(this,"ao",320);c(this,"co",350);c(this,"lo",10);c(this,"uo",550);c(this,"fo",14);c(this,"do",48);c(this,"_o",650);c(this,"po",.02);c(this,"mo",2);c(this,"vo",600);c(this,"yo",0);c(this,"Co",null);this.er=t,this.In=i;const r=this.er.canvas;this.Xn=r.style.touchAction,this.Nn=r.style.userSelect,r.style.touchAction||(r.style.touchAction="none"),r.style.userSelect||(r.style.userSelect="none")}Ni(t){this.Gr=t,this.wo()}an(){if(this.qr)return;const t=this.er.canvas;this.jn=i=>{this.bo(i)},this.Yn=i=>{this.$o(i)},this.Vn=i=>{this.xo(i)},this.qn=i=>{this.Mo(i)},t.addEventListener("touchstart",this.jn,{passive:!1}),t.addEventListener("touchmove",this.Yn,{passive:!1}),t.addEventListener("touchend",this.Vn,{passive:!1}),t.addEventListener("touchcancel",this.qn,{passive:!1}),this.qr=!0}pn(){if(!this.qr)return;const t=this.er.canvas;t.removeEventListener("touchstart",this.jn),t.removeEventListener("touchmove",this.Yn),t.removeEventListener("touchend",this.Vn),t.removeEventListener("touchcancel",this.qn),this.qr=!1,this.Kn=null,this.On.clear(),this.Wn.clear(),this.Hn.forEach(i=>{i.longPressTimer!==null&&window.clearTimeout(i.longPressTimer)}),this.Hn.clear(),this.Co=null,this.yo=0,t.style.touchAction=this.Xn,t.style.userSelect=this.Nn}wo(){if(!this.Gr||this.On.size===0)return;const t=new Map;for(const i of this.On.values()){const r=this.Ro(i.clientX,i.clientY,i.id,i);t.set(i.id,r)}this.On=t}Fo(){return Array.from(this.On.values()).map(t=>({...t}))}So(t){this.Zn=t}yn(t){this.Jn=t}To(t){this.Qn=t}Ao(t){this.so=t}zo(t){this.eo=t}ko(t){this.io=t}Eo(t){this.ro=t}Po(t){this.no=t}Lo(t){this.oo=t}Do(t){this.ho=t}bo(t){var n;if(!this.Gr)return;t.preventDefault(),(n=this.In)==null||n.en(this.vo);const i=performance.now(),r=this.Bo(t.changedTouches);for(const o of r){const h=this.On.get(o.id);h&&this.Wn.set(o.id,this.Go(h)),this.On.set(o.id,o);const a={id:o.id,startPosition:o,lastPosition:o,startTime:i,lastTime:i,longPressTimer:null,longPressFired:!1};this.ro&&(a.longPressTimer=window.setTimeout(()=>{const u=this.On.get(o.id);u&&(a.longPressFired=!0,this.ro({touch:this.Go(u),duration:performance.now()-a.startTime,originalEvent:t}))},this.uo)),this.Hn.set(o.id,a),this.Zn&&this.Zn(this.Io(o,t,void 0,i))}this.On.size===2&&this.Oo()}$o(t){var n;if(!this.Gr)return;t.preventDefault(),(n=this.In)==null||n.en(this.vo);const i=performance.now(),r=this.Bo(t.changedTouches);for(const o of r){const h=this.On.get(o.id),a=h?this.Go(h):void 0;a&&this.Wn.set(o.id,a),this.On.set(o.id,o);const u=this.Hn.get(o.id);u&&(u.lastPosition=o,u.lastTime=i,a)&&this.Wo(a,o,!0)>this.fo&&u.longPressTimer!==null&&(window.clearTimeout(u.longPressTimer),u.longPressTimer=null),this.Jn&&this.Jn(this.Io(o,t,a,i))}this.On.size===2?this.Ho(t):this.Kn=null}xo(t){if(!this.Gr)return;t.preventDefault();const i=performance.now(),r=this.Bo(t.changedTouches);for(const n of r){const o=this.On.get(n.id),h=o?this.Go(o):void 0,a=this.Hn.get(n.id);a&&a.longPressTimer!==null&&(window.clearTimeout(a.longPressTimer),a.longPressTimer=null),this.Qn&&this.Qn(this.Io(n,t,h,i)),a&&this.Ko(a,t),this.Hn.delete(n.id),this.Wn.delete(n.id),this.On.delete(n.id)}this.On.size<2&&(this.Kn=null)}Mo(t){if(!this.Gr)return;t.preventDefault();const i=performance.now(),r=this.Bo(t.changedTouches);for(const n of r){const o=this.On.get(n.id),h=o?this.Go(o):void 0,a=this.Hn.get(n.id);a&&a.longPressTimer!==null&&(window.clearTimeout(a.longPressTimer),a.longPressTimer=null),this.so&&this.so(this.Io(n,t,h,i)),this.Hn.delete(n.id),this.Wn.delete(n.id),this.On.delete(n.id)}this.On.size<2&&(this.Kn=null)}Bo(t){const i=[];for(let r=0;r<t.length;r+=1){const n=t.item(r);n&&i.push(this.Xo(n))}return i}Xo(t){return this.Ro(t.clientX,t.clientY,t.identifier,{id:t.identifier,x:-1,y:-1,clientX:t.clientX,clientY:t.clientY,pressure:t.force,radiusX:t.radiusX,radiusY:t.radiusY,rotationAngle:t.rotationAngle})}Ro(t,i,r,n){const o=this.er.canvas,h=o.getBoundingClientRect(),a=t-h.left,u=i-h.top,f=o.width/h.width,g=u*(o.height/h.height),d=a*f-this.Gr.offsetX,v=g-this.Gr.offsetY,x=Math.floor(d/this.Gr.cellWidth),p=Math.floor(v/this.Gr.cellHeight),m=x>=0&&x<this.Gr.cols&&p>=0&&p<this.Gr.rows;return{id:r,x:m?x:-1,y:m?p:-1,clientX:t,clientY:i,pressure:n.pressure,radiusX:n.radiusX,radiusY:n.radiusY,rotationAngle:n.rotationAngle}}Io(t,i,r,n){const o=this.Hn.get(t.id),h=Array.from(this.Wn.values()).map(f=>this.Go(f)),a=Array.from(this.On.values()).map(f=>this.Go(f)),u=this.Bo(i.changedTouches);return{touch:this.Go(t),previousTouch:r?this.Go(r):void 0,touches:a,previousTouches:h,changedTouches:u,deltaTime:o?n-o.lastTime:0,originalEvent:i}}Oo(){if(this.On.size!==2)return void(this.Kn=null);const t=Array.from(this.On.values()),[i,r]=t,n=this.Wo(i,r,!1),o=this.No(i,r);this.Kn={ids:[i.id,r.id],initialDistance:Math.max(n,1e-4),initialAngle:o,lastScale:1,lastRotation:0}}Ho(t){if(this.Kn||this.Oo(),!this.Kn)return;const[i,r]=this.Kn.ids,n=this.On.get(i),o=this.On.get(r);if(!n||!o)return;const h=this.Wo(n,o,!1)/this.Kn.initialDistance,a=h-this.Kn.lastScale;this.oo&&Math.abs(a)>this.po&&(this.oo({touches:[this.Go(n),this.Go(o)],scale:h,deltaScale:a,center:this.jo(n,o),originalEvent:t}),this.Kn.lastScale=h);let u=this.No(n,o)-this.Kn.initialAngle;u=(u+180)%360-180;const f=u-this.Kn.lastRotation;this.ho&&Math.abs(f)>this.mo&&(this.ho({touches:[this.Go(n),this.Go(o)],rotation:u,deltaRotation:f,center:this.jo(n,o),originalEvent:t}),this.Kn.lastRotation=u)}jo(t,i){const r=(t.clientX+i.clientX)/2,n=(t.clientY+i.clientY)/2,o=this.Ro(r,n,-1,{id:-1,x:-1,y:-1,clientX:r,clientY:n});return{x:o.x,y:o.y}}Ko(t,i){const r=performance.now(),n=r-t.startTime,o=this.Wo(t.startPosition,t.lastPosition,!0);if(!t.longPressFired&&n<=this.ao&&o<=this.lo)this.Yo(t.lastPosition,r)&&this.io?this.io({touch:this.Go(t.lastPosition),taps:2,originalEvent:i}):this.eo&&this.eo({touch:this.Go(t.lastPosition),taps:1,originalEvent:i});else if(!t.longPressFired&&n<=this._o&&o>=this.do){const h={x:t.lastPosition.clientX-t.startPosition.clientX,y:t.lastPosition.clientY-t.startPosition.clientY},a=Math.max(Math.hypot(h.x,h.y),1e-4),u={x:h.x/a,y:h.y/a},f={x:h.x/n,y:h.y/n};this.no&&this.no({touch:this.Go(t.lastPosition),direction:u,distance:a,velocity:f,originalEvent:i})}this.yo=r,this.Co=this.Go(t.lastPosition)}Yo(t,i){return!!this.Co&&!(i-this.yo>this.co)&&this.Wo(t,this.Co,!0)<=this.lo}Go(t){return{...t}}Wo(t,i,r){return r?Math.hypot(t.clientX-i.clientX,t.clientY-i.clientY):Math.hypot(t.x-i.x,t.y-i.y)}No(t,i){return 180*Math.atan2(i.clientY-t.clientY,i.clientX-t.clientX)/Math.PI}}const Kt=Object.freeze(Object.defineProperty({__proto__:null,TouchManager:ft},Symbol.toStringTag,{value:"Module"})),qt=l=>class extends l{rotate(t=0,i=0,r=0){this.xt.state.st(t),this.xt.state.et(i),this.xt.state.it(r)}rotateX(t){this.xt.state.st(t)}rotateY(t){this.xt.state.et(t)}rotateZ(t){this.xt.state.it(t)}push(){this.xt.state.O()}pop(){this.xt.state.Z()}rect(t,i,r=1,n=1){this.xt.He(t,i,r,n)}point(t,i){this.xt.He(t,i,1,1)}line(t,i,r,n){this.xt.Ke(t,i,r,n)}lineWeight(t){this.xt.state.tt(t)}background(t,i=t,r=t,n=255){this.xt.qe(t,i,r,n)}char(t){this.xt.state.rt(this.ki.Ai(t))}charColor(t,i,r,n=255){this.xt.state.nt(t,i,r,n)}cellColor(t,i,r,n=255){this.xt.state.ot(t,i,r,n)}flipX(t){this.xt.state.ht(t)}flipY(t){this.xt.state.ct(t)}charRotation(t){this.xt.state.ut(t)}invert(t){this.xt.state.lt(t)}clear(){this.xt.qe(0,0,0,0)}ellipse(t,i,r,n){this.xt.Xe(t,i,r/2,n/2)}triangle(t,i,r,n,o,h){this.xt.Ne(t,i,r,n,o,h)}bezierCurve(t,i,r,n,o,h,a,u){this.xt.je(t,i,r,n,o,h,a,u)}arc(t,i,r,n,o,h){this.xt.Ve(t,i,r,n,o,h)}shader(t){this.xt.De(t)}setUniform(t,i){this.xt.Nt(t,i)}setUniforms(t){this.xt.Be(t)}createFilterShader(t){return this.xt.hs(t)}createFramebuffer(t){return this.xt.Ye(t.width,t.height,5,{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"})}image(t,i,r,n,o){if(t.textures){const h=t;this.xt.Ge(h,i,r,n??h.width,o??h.height)}else{const h=t;this.xt.Ie(h,i,r,n??Math.floor(this.Gr.cols/2),o??Math.floor(this.Gr.rows/2))}}async loadImage(t){if(typeof t!="string")return N.Fr(this.xt,t,n=>this.ki.zi(n));const i=t,r=await new Promise((n,o)=>{const h=new Image;h.crossOrigin="anonymous",h.onload=()=>n(h),h.onerror=a=>o(a),h.src=i});return N.Fr(this.xt,r,n=>this.ki.zi(n))}},jt=l=>class extends l{async loadFont(t){return this.ki.qi(t).then(()=>{const i=this.ki.maxGlyphDimensions;this.Gr.hr(i.width,i.height),this.Vo.resize(this.Gr.cols,this.Gr.rows),this.xt.Ze(),this.In.hn()})}fontSize(t){if(!W.v(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.ki.fontSize===t)return;this.ki.Vi(t);const i=this.ki.maxGlyphDimensions;this.Gr.hr(i.width,i.height),this.Vo.resize(this.Gr.cols,this.Gr.rows),this.xt.Ze(),this.In.hn()}glyphColor(t){return this.ki.Ai(t)}glyphColors(t){return this.ki.zi(t)}},Jt=l=>class extends l{get frameCount(){return this.qo.frameCount}set frameCount(t){this.qo.frameCount=t}frameRate(t){return t===void 0?this.qo.currentFrameRate:this.qo.frameRate(t,()=>this.Zo())}noLoop(){this.qo.pause()}loop(){this.qo.resume(()=>this.Zo())}redraw(t=1){if(W.v(typeof t=="number"&&t>0&&Number.isInteger(t),"Redraw count must be a positive integer.",{method:"redraw",providedValue:t}))for(let i=0;i<t;i++)this.Zo()}isLooping(){return this.qo.isLooping}},Zt=l=>class extends l{constructor(...t){super(...t)}mouseClicked(t){this.In.mn(t)}mousePressed(t){this.In.vn(t)}mouseReleased(t){this.In.gn(t)}mouseMoved(t){this.In.yn(t)}mouseScrolled(t){this.In.Cn(t)}get mouse(){return this.In.wn()}cursor(t){this.In.nn(t)}},Qt=l=>class extends l{constructor(...t){super(...t)}touchStarted(t){this.Jo.So(t)}touchMoved(t){this.Jo.yn(t)}touchEnded(t){this.Jo.To(t)}touchCancelled(t){this.Jo.Ao(t)}tap(t){this.Jo.zo(t)}doubleTap(t){this.Jo.ko(t)}longPress(t){this.Jo.Eo(t)}swipe(t){this.Jo.Po(t)}pinch(t){this.Jo.Lo(t)}rotateGesture(t){this.Jo.Do(t)}get touches(){return this.Jo.Fo()}},te=l=>class extends l{constructor(...t){super(...t)}keyPressed(t){this.Qo.vn(t)}keyReleased(t){this.Qo.gn(t)}isKeyPressed(t){return this.Qo.kn(t)}get lastKeyPressed(){return this.Qo.Pn()}get lastKeyReleased(){return this.Qo.Ln()}get pressedKeys(){return this.Qo.Dn()}get modifierState(){return this.Qo.Bn()}};class ee{constructor(t){c(this,"th");c(this,"sh",new Map);c(this,"eh",[]);c(this,"ih",new Map);c(this,"rh",new Map);this.th=t}async nh(t){for(const i of t){if(this.sh.has(i.name))return void console.warn(`[textmode.js] Plugin "${i.name}" is already installed.`);const r=this.oh(i.name);try{await i.install(this.th,r)}catch(n){throw this.hh(i.name),n}this.sh.set(i.name,i),this.eh.push(i.name)}}async ah(t){const i=this.sh.get(t);if(!i)return;const r=this.oh(t);if(i.uninstall)try{await i.uninstall(this.th,r)}catch(n){console.error(`[textmode.js] Error while uninstalling plugin "${t}":`,n)}this.sh.delete(t),this.eh.splice(this.eh.indexOf(t),1),this.hh(t)}runPreDrawHooks(){this.uh(this.ih,"preDraw")}runPostDrawHooks(){this.uh(this.rh,"postDraw")}async fh(){const t=[...this.sh.keys()];for(const i of t)await this.ah(i)}oh(t){return{...this.th.dh(),registerPreDrawHook:i=>this._h(this.ih,t,i),registerPostDrawHook:i=>this._h(this.rh,t,i)}}_h(t,i,r){const n=t.get(i)??new Set;return n.add(r),t.set(i,n),()=>{const o=t.get(i);o&&(o.delete(r),o.size===0&&t.delete(i))}}hh(t){this.ih.delete(t),this.rh.delete(t)}uh(t,i){for(const r of this.eh){const n=t.get(r);if(n)for(const o of n)try{o()}catch(h){console.error(`[textmode.js] Plugin "${r}" ${i} hook failed:`,h)}}}}class ie{constructor(){c(this,"xt");c(this,"ki");c(this,"er");c(this,"Gr");c(this,"qo");c(this,"In");c(this,"Jo");c(this,"Qo");c(this,"ph");c(this,"Vo");c(this,"mh");c(this,"gh");c(this,"yh")}Zo(){}}class dt extends function(i,...r){return r.reduce((n,o)=>o(n),i)}(ie,qt,jt,Jt,Zt,Qt,te){constructor(i={}){super();c(this,"Ch");c(this,"wh",!1);c(this,"bh",!1);c(this,"$h",!1);c(this,"xh",()=>{});c(this,"Mh",()=>{});c(this,"Rh",()=>{});c(this,"Fh");c(this,"lr");c(this,"cr",!1);c(this,"Sh");this.Ch=new ee(this),this.cr=i.overlay??!1,this.er=new ct(i),this.xt=new St(this.er.gr()),this.ki=new ht(this.xt,i.fontSize??16),this.qo=new Ht(i.frameRate??60),this.In=new lt(this.er),this.Jo=new ft(this.er,this.In),this.Qo=new ut,this.ph=this.xt.At(),this.mh=this.xt.rs(),this.Th(i)}async Th(i){await this.ki.Ni(i.fontSource);const r=this.ki.maxGlyphDimensions;this.Gr=new at(this.er.canvas,r.width,r.height),this.In.Ni(this.Gr),this.Jo.Ni(this.Gr),this.Vo=this.xt.Ye(this.Gr.cols,this.Gr.rows,5),this.gh=this.xt.Ye(this.Gr.width,this.Gr.height,1),this.cr&&(this.Sh=N.Fr(this.xt,this.er.targetCanvas,n=>this.ki.zi(n))),this.yh=this.xt.cs(rt,"precision mediump float;uniform sampler2D Ua;uniform vec2 Ub;uniform vec2 Uc;uniform vec2 Ud;void main(){vec2 A=gl_FragCoord.xy-Uc;vec2 B=A*(Ub/Ud);vec2 C=(floor(B)+0.5)/Ub;gl_FragColor=texture2D(Ua,C);}"),this.Ah(),await this.Ch.nh(i.plugins??[]),this.xh(),this.qo.start(()=>this.Zo())}dh(){return{renderer:this.xt,font:this.ki,grid:this.Gr,canvas:this.er,drawFramebuffer:this.Vo,asciiFramebuffer:this.gh,flushDrawCommands:()=>{this.xt.zt(this.ph)}}}Ah(){this.Fh=()=>{this.cr&&this.resizeCanvas(this.er.targetCanvas.width,this.er.targetCanvas.height),this.Rh()},window.addEventListener("resize",this.Fh),this.In.an(),this.Jo.an(),this.Qo.an(),window.addEventListener("blur",()=>{this.Qo.Gn()}),window.ResizeObserver&&this.cr&&(this.lr=new ResizeObserver(()=>{this.resizeCanvas(this.er.targetCanvas.width,this.er.targetCanvas.height)}),this.lr.observe(this.er.targetCanvas))}Zo(){this.bh=!0;try{if(this.qo.measureFrameRate(),this.qo.incrementFrame(),this.cr){const r=this.xt.context;r.bindTexture(r.TEXTURE_2D,this.Sh.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.er.targetCanvas),r.bindTexture(r.TEXTURE_2D,null)}this.Ch.runPreDrawHooks(),this.Vo.begin(),this.xt.Le(this.ph),this.Mh(),this.xt.zt(this.ph),this.Vo.end(),this.gh.begin(),this.xt.Le(this.mh),this.mh.Xt({U0:this.ki.fontFramebuffer,U1:[this.ki.textureColumns,this.ki.textureRows],U2:this.Vo.textures[0],U3:this.Vo.textures[1],U4:this.Vo.textures[2],U5:this.Vo.textures[4],U6:this.Vo.textures[3],U7:[this.Gr.cols,this.Gr.rows],U8:[this.gh.width,this.gh.height],U9:this.gh.width/this.gh.height}),this.xt.We(0,0,this.er.width,this.er.height),this.gh.end();const i=this.xt.state.canvasBackgroundColor;this.xt.Ys(i[0],i[1],i[2],i[3]),this.xt.Le(this.yh),this.yh.Xt({Ua:this.gh.textures[0],Ub:[this.gh.width,this.gh.height],Uc:[this.Gr.offsetX,this.Gr.offsetY],Ud:[this.Gr.width,this.Gr.height]}),this.xt.We(this.Gr.offsetX,this.Gr.offsetY,this.Gr.width,this.Gr.height),this.Ch.runPostDrawHooks()}catch(i){console.error("[textmode.js] Error during render:",i)}finally{this.bh=!1,this.wh&&!this.$h&&this.zh()}}setup(i){this.xh=i}draw(i){this.Mh=i}windowResized(i){this.Rh=i}resizeCanvas(i,r){this.er.vr(i,r),this.Gr.nr(),this.Vo.resize(this.Gr.cols,this.Gr.rows),this.gh.resize(this.Gr.width,this.Gr.height),this.xt.Ze(),this.In.hn(),this.Jo.wo(),this.Zo()}destroy(){this.$h||this.wh||(this.wh=!0,this.qo.stop(),this.noLoop(),this.bh||this.zh())}zh(){this.$h||(this.wh=!1,this.Ch.fh().catch(i=>{console.error("[textmode.js] Error while disposing plugins:",i)}),window.removeEventListener("resize",this.Fh),this.In.pn(),this.Jo.pn(),this.Qo.pn(),this.ki.Pt(),this.xt.Pt(),this.gh.Pt(),this.yh.Pt(),this.er.Pt(),this.Sh&&this.Sh.Pt(),this.$h=!0)}get grid(){return this.Gr}get font(){return this.ki}get width(){return this.er.width}get height(){return this.er.height}get canvas(){return this.er.canvas}get drawFramebuffer(){return this.Vo}get isDisposed(){return this.$h}get overlay(){return this.Sh}}class J{constructor(){}static create(t={}){return new dt(t)}static setErrorLevel(t){W.C(t)}static get version(){return"0.4.1-beta.1"}}const se=Object.freeze(Object.defineProperty({__proto__:null,keyboard:Vt,mouse:$t,touch:Kt},Symbol.toStringTag,{value:"Module"})),re=J.create,ne=J.setErrorLevel,oe=J.version;C.TextmodeCanvas=ct,C.TextmodeErrorLevel=G,C.TextmodeFont=ht,C.TextmodeFramebuffer=V,C.TextmodeGrid=at,C.TextmodeImage=N,C.Textmodifier=dt,C.create=re,C.input=se,C.setErrorLevel=ne,C.textmode=J,C.version=oe,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):e((s=typeof globalThis<"u"?globalThis:s||self).textmode={});
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,10 +8,7 @@ export { TextmodeGrid } from './textmode/Grid';
|
|
|
8
8
|
export type { TextmodeOptions } from './textmode/Textmodifier';
|
|
9
9
|
export type { TextmodeFramebufferOptions } from './textmode/mixins/RenderingMixin';
|
|
10
10
|
export type { TextmodeCharacter } from './textmode/font';
|
|
11
|
-
export type { TextmodePlugin, TextmodePluginAPI,
|
|
12
|
-
export { PluginManager } from './textmode/plugins/PluginManager';
|
|
13
|
-
/** All types related to export options for different formats. */
|
|
14
|
-
export * as export from './export';
|
|
11
|
+
export type { TextmodePlugin, TextmodePluginAPI, } from './textmode/plugins/PluginManager';
|
|
15
12
|
export { TextmodeErrorLevel } from './errors/ErrorHandler';
|
|
16
13
|
export { Textmode as textmode } from './Textmode';
|
|
17
14
|
/** All types and interfaces related to input event handling. */
|
|
@@ -91,8 +91,8 @@ declare const Textmodifier_base: typeof TextmodifierCore;
|
|
|
91
91
|
*/
|
|
92
92
|
export declare class Textmodifier extends Textmodifier_base {
|
|
93
93
|
private _pluginManager;
|
|
94
|
-
private
|
|
95
|
-
private
|
|
94
|
+
private _destroyRequested;
|
|
95
|
+
private _isRenderingFrame;
|
|
96
96
|
private _isDisposed;
|
|
97
97
|
private _setupCallback;
|
|
98
98
|
private _drawCallback;
|
|
@@ -112,20 +112,9 @@ export declare class Textmodifier extends Textmodifier_base {
|
|
|
112
112
|
* @param opts Configuration options
|
|
113
113
|
*/
|
|
114
114
|
private _initialize;
|
|
115
|
-
/**
|
|
116
|
-
* Dynamically install a plugin after initialization.
|
|
117
|
-
*/
|
|
118
|
-
use(plugin: TextmodePlugin): Promise<this>;
|
|
119
|
-
/**
|
|
120
|
-
* Remove a previously installed plugin by name.
|
|
121
|
-
*/
|
|
122
|
-
unuse(pluginName: string): Promise<this>;
|
|
123
|
-
/**
|
|
124
|
-
* Check whether a plugin has been installed.
|
|
125
|
-
*/
|
|
126
|
-
hasPlugin(pluginName: string): boolean;
|
|
127
115
|
/**
|
|
128
116
|
* Provide plugins with a minimal API surface so they can interact with the renderer safely.
|
|
117
|
+
* @ignore
|
|
129
118
|
*/
|
|
130
119
|
$getPluginContext(): TextmodePluginContext;
|
|
131
120
|
/**
|
|
@@ -254,6 +243,7 @@ export declare class Textmodifier extends Textmodifier_base {
|
|
|
254
243
|
* ```
|
|
255
244
|
*/
|
|
256
245
|
destroy(): void;
|
|
246
|
+
private _performDestroy;
|
|
257
247
|
/** Get the current grid object used for rendering. */
|
|
258
248
|
get grid(): TextmodeGrid;
|
|
259
249
|
/** Get the current font object used for rendering. */
|
|
@@ -228,22 +228,6 @@ export interface TyprFont {
|
|
|
228
228
|
/** Additional font tables that may be present */
|
|
229
229
|
[tableName: string]: any;
|
|
230
230
|
}
|
|
231
|
-
/**
|
|
232
|
-
* Glyph outline data structure
|
|
233
|
-
* Contains coordinate and control point information for rendering glyphs
|
|
234
|
-
*/
|
|
235
|
-
export interface GlyphData {
|
|
236
|
-
/** Number of contours in the glyph */
|
|
237
|
-
noc: number;
|
|
238
|
-
/** X coordinates of glyph points */
|
|
239
|
-
xs: number[];
|
|
240
|
-
/** Y coordinates of glyph points */
|
|
241
|
-
ys: number[];
|
|
242
|
-
/** Indices of the last point in each contour */
|
|
243
|
-
endPts: number[];
|
|
244
|
-
/** Flags indicating point types (on-curve, off-curve, etc.) */
|
|
245
|
-
flags: number[];
|
|
246
|
-
}
|
|
247
231
|
/**
|
|
248
232
|
* Main Typr interface
|
|
249
233
|
* Provides font parsing and table lookup functionality
|
|
@@ -13,10 +13,10 @@ export interface FontCapabilities {
|
|
|
13
13
|
* const textmodifier = textmode.create();
|
|
14
14
|
*
|
|
15
15
|
* // Load a custom font from a URL
|
|
16
|
-
*
|
|
16
|
+
* await textmodifier.loadFont('https://example.com/fonts/myfont.ttf');
|
|
17
17
|
*
|
|
18
18
|
* // Local font example
|
|
19
|
-
* // textmodifier.loadFont('./fonts/myfont.ttf');
|
|
19
|
+
* // await textmodifier.loadFont('./fonts/myfont.ttf');
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
loadFont(fontSource: string): Promise<void>;
|
|
@@ -6,38 +6,69 @@ import type { TextmodeGrid } from '../Grid';
|
|
|
6
6
|
import type { TextmodeCanvas } from '../Canvas';
|
|
7
7
|
export type TextmodePluginHook = () => void;
|
|
8
8
|
export interface TextmodePluginContext {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
/** The WebGL renderer used by the Textmodifier instance. */
|
|
10
|
+
renderer: GLRenderer;
|
|
11
|
+
/** The font used by the Textmodifier instance. */
|
|
12
|
+
font: TextmodeFont;
|
|
13
|
+
/** The grid used by the Textmodifier instance. */
|
|
14
|
+
grid: TextmodeGrid;
|
|
15
|
+
/** The canvas used by the Textmodifier instance. */
|
|
16
|
+
canvas: TextmodeCanvas;
|
|
17
|
+
/** The framebuffer the user draws to. */
|
|
18
|
+
drawFramebuffer: GLFramebuffer;
|
|
19
|
+
/** The framebuffer containing the ASCII representation. */
|
|
20
|
+
asciiFramebuffer: GLFramebuffer;
|
|
21
|
+
/** Immediately execute any pending draw commands. */
|
|
15
22
|
flushDrawCommands(): void;
|
|
16
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* An extended API provided to plugins when they are installed on a {@link Textmodifier} instance.
|
|
26
|
+
*/
|
|
17
27
|
export interface TextmodePluginAPI extends TextmodePluginContext {
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Register a callback to be invoked before each draw cycle. Happens outside of the draw framebuffer being bound.
|
|
30
|
+
*/
|
|
31
|
+
registerPreDrawHook(callback: () => void): () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Register a callback to be invoked after each draw cycle. Happens outside of the draw framebuffer being bound.
|
|
34
|
+
*/
|
|
35
|
+
registerPostDrawHook(callback: () => void): () => void;
|
|
20
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* A plugin interface for extending the functionality of a {@link Textmodifier} instance.
|
|
39
|
+
*
|
|
40
|
+
* Users can create plugins by implementing this interface.
|
|
41
|
+
*/
|
|
21
42
|
export interface TextmodePlugin {
|
|
43
|
+
/** Unique name for the plugin. */
|
|
22
44
|
name: string;
|
|
45
|
+
/** Version string for the plugin. */
|
|
23
46
|
version?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Called when the plugin is installed on a {@link Textmodifier} instance.
|
|
49
|
+
* @param textmodifier The Textmodifier instance the plugin is being installed on.
|
|
50
|
+
* @param api An API object providing access to the Textmodifier's context and hook registration methods.
|
|
51
|
+
*/
|
|
24
52
|
install(textmodifier: Textmodifier, api: TextmodePluginAPI): void | Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Called when the plugin is uninstalled from a {@link Textmodifier} instance.
|
|
55
|
+
* @param textmodifier The Textmodifier instance the plugin is being uninstalled from.
|
|
56
|
+
* @param api An API object providing access to the Textmodifier's context and hook registration methods.
|
|
57
|
+
*/
|
|
25
58
|
uninstall?(textmodifier: Textmodifier, api: TextmodePluginAPI): void | Promise<void>;
|
|
26
59
|
}
|
|
27
|
-
export declare class
|
|
60
|
+
export declare class TextmodePluginManager {
|
|
28
61
|
private readonly _textmodifier;
|
|
29
62
|
private readonly _plugins;
|
|
30
63
|
private readonly _installationOrder;
|
|
31
64
|
private readonly _preDrawHooks;
|
|
32
65
|
private readonly _postDrawHooks;
|
|
33
66
|
constructor(textmodifier: Textmodifier);
|
|
34
|
-
installMany(plugins: TextmodePlugin[]): Promise<void>;
|
|
35
|
-
|
|
36
|
-
unuse(pluginName: string): Promise<void>;
|
|
37
|
-
has(pluginName: string): boolean;
|
|
67
|
+
$installMany(plugins: TextmodePlugin[]): Promise<void>;
|
|
68
|
+
$unuse(pluginName: string): Promise<void>;
|
|
38
69
|
runPreDrawHooks(): void;
|
|
39
70
|
runPostDrawHooks(): void;
|
|
40
|
-
disposeAll(): Promise<void>;
|
|
71
|
+
$disposeAll(): Promise<void>;
|
|
41
72
|
private _createAPI;
|
|
42
73
|
private _registerHook;
|
|
43
74
|
private _removePluginHooks;
|
package/package.json
CHANGED