textmode.js 0.2.0 → 0.2.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/textmode.esm.js +1566 -1294
  2. package/dist/textmode.esm.min.js +1662 -1390
  3. package/dist/textmode.umd.js +10 -26
  4. package/dist/textmode.umd.min.js +9 -25
  5. package/dist/types/assets/shaders-minified/frag/ascii.d.ts +14 -0
  6. package/dist/types/assets/shaders-minified/frag/copy-mrt.d.ts +14 -0
  7. package/dist/types/assets/shaders-minified/frag/instanced-ascii-mrt.d.ts +14 -0
  8. package/dist/types/assets/shaders-minified/index.d.ts +5 -0
  9. package/dist/types/assets/shaders-minified/vert/instanced-ascii-mrt.d.ts +14 -0
  10. package/dist/types/assets/shaders-minified/vert/shader.d.ts +14 -0
  11. package/dist/types/export/svg/SVGContentGenerator.d.ts +0 -6
  12. package/dist/types/index.d.ts +2 -0
  13. package/dist/types/rendering/index.d.ts +2 -0
  14. package/dist/types/rendering/webgl/Framebuffer.d.ts +8 -8
  15. package/dist/types/rendering/webgl/InstanceData.d.ts +1 -1
  16. package/dist/types/rendering/webgl/RenderPipeline.d.ts +10 -3
  17. package/dist/types/rendering/webgl/RenderState.d.ts +11 -11
  18. package/dist/types/rendering/webgl/Renderer.d.ts +26 -2
  19. package/dist/types/rendering/webgl/Shader.d.ts +6 -7
  20. package/dist/types/rendering/webgl/ShaderManager.d.ts +65 -1
  21. package/dist/types/rendering/webgl/index.d.ts +1 -0
  22. package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +7 -7
  23. package/dist/types/rendering/webgl/types/ShaderTypes.d.ts +35 -0
  24. package/dist/types/textmode/Textmodifier.d.ts +8 -2
  25. package/dist/types/textmode/managers/KeyboardManager.d.ts +123 -0
  26. package/dist/types/textmode/managers/MouseManager.d.ts +130 -0
  27. package/dist/types/textmode/managers/index.d.ts +4 -0
  28. package/dist/types/textmode/mixins/KeyboardMixin.d.ts +39 -0
  29. package/dist/types/textmode/mixins/MouseMixin.d.ts +27 -0
  30. package/dist/types/textmode/mixins/RenderingMixin.d.ts +104 -0
  31. package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +6 -0
  32. package/dist/types/textmode/mixins/index.d.ts +4 -0
  33. package/package.json +3 -2
@@ -1,28 +1,12 @@
1
- var te=Object.defineProperty;var ee=(E,v,L)=>v in E?te(E,v,{enumerable:!0,configurable:!0,writable:!0,value:L}):E[v]=L;var u=(E,v,L)=>ee(E,typeof v!="symbol"?v+"":v,L);var e,s;e=this,s=function(E){class v extends Error{constructor(t,r={}){super(v.i(t,r)),this.name="TextmodeError"}static i(t,r){let i=t;if(r&&Object.keys(r).length>0){i+=`
1
+ var oe=Object.defineProperty;var ae=(b,v,L)=>v in b?oe(b,v,{enumerable:!0,configurable:!0,writable:!0,value:L}):b[v]=L;var l=(b,v,L)=>ae(b,typeof v!="symbol"?v+"":v,L);var e,s;e=this,s=function(b){class v extends Error{constructor(t,i={}){super(v.u(t,i)),this.name="TextmodeError"}static u(t,i){return`${t}${i&&Object.keys(i).length>0?`
2
2
 
3
- 📋 Context:`;for(const[n,o]of Object.entries(r))i+=`
4
- - ${n}: ${v.o(o)}`}return i+=`
3
+ 📋 Context:`+Object.entries(i).map(([r,n])=>`
4
+ - ${r}: ${v._(n)}`).join(""):""}
5
5
 
6
- `,i+="↓".repeat(24)+`
7
- `,i}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(r=>v.o(r)).join(", ")}]`:`[${t.slice(0,3).map(r=>v.o(r)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const r=Object.keys(t);return r.length===0?"{}":r.length<=3?`{ ${r.map(i=>`${i}: ${v.o(t[i])}`).join(", ")} }`:`{ ${r.slice(0,2).map(i=>`${i}: ${v.o(t[i])}`).join(", ")}, ... +${r.length-2} more }`}return t+""}}var L=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(L||{});const I=class I{constructor(){u(this,"u",{globalLevel:3})}static p(){return I.l||(I.l=new I),I.l}_(t,r){const i="%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(i,n),console.warn(v.i(t,r)),console.groupEnd(),!1;case 2:return console.group(i,n),console.error(v.i(t,r)),console.groupEnd(),!1;default:throw new v(t,r)}}m(t,r,i){return!!t||(this._(r,i),!1)}v(t){this.u.globalLevel=t}};u(I,"l",null);let k=I;const z=k.p(),H=new WeakMap;function G(c,t){H.set(c,t)}function D(c){return H.get(c)}class N{constructor(t,r,i=r,n=1,o={}){u(this,"C");u(this,"$");u(this,"u");u(this,"R",null);u(this,"S");u(this,"M");u(this,"F",[]);u(this,"G");u(this,"D",null);u(this,"P",[]);this.C=r,this.$=i,this.u={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.S=t,this.G=Math.min(Math.max(1,n),8);const a=t.getParameter(t.MAX_DRAW_BUFFERS),h=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.G=Math.min(this.G,a,h),this.M=t.createFramebuffer(),this.A(),this.I(),this.P=Array(this.G).fill(null)}A(){const t=this.S,r=this.u.filter==="linear"?t.LINEAR:t.NEAREST,i=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.G;o++){const a=t.createTexture();t.bindTexture(t.TEXTURE_2D,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,i),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.C,this.$,0,t.RGBA,n,null),this.F.push(a)}t.bindTexture(t.TEXTURE_2D,null)}I(){const t=this.S;if(t.bindFramebuffer(t.FRAMEBUFFER,this.M),this.G===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.F[0],0);else{const i=[];for(let n=0;n<this.G;n++){const o=t.COLOR_ATTACHMENT0+n;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,this.F[n],0),i.push(o)}t.drawBuffers(i)}const r=t.checkFramebufferStatus(t.FRAMEBUFFER);r!==t.FRAMEBUFFER_COMPLETE&&console.error("GLFramebuffer is not complete:",r),t.bindFramebuffer(t.FRAMEBUFFER,null)}L(t){const r=this.S;r.bindTexture(r.TEXTURE_2D,this.F[0]),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t),r.bindTexture(r.TEXTURE_2D,null)}W(t,r){this.C=t,this.$=r,this.R=null,this.P=Array(this.G).fill(null);const i=this.S,n=this.u.type==="float"?i.FLOAT:i.UNSIGNED_BYTE;for(const o of this.F)i.bindTexture(i.TEXTURE_2D,o),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,this.C,this.$,0,i.RGBA,n,null);i.bindTexture(i.TEXTURE_2D,null)}k(t){const r=this.S;if(t<0||t>=this.G)throw Error(`GLFramebuffer: attachment index ${t} out of range (count=${this.G})`);const i=this.P[t];if(i)return i;const n=this.C,o=this.$,a=new Uint8Array(n*o*4),h=r.getParameter(r.READ_FRAMEBUFFER_BINDING);r.bindFramebuffer(r.READ_FRAMEBUFFER,this.M),r.readBuffer(r.COLOR_ATTACHMENT0+t),r.readPixels(0,0,n,o,r.RGBA,r.UNSIGNED_BYTE,a),r.bindFramebuffer(r.READ_FRAMEBUFFER,h);const l=4*n,f=new Uint8Array(a.length);for(let g=0;g<o;g++){const d=(o-1-g)*l,p=g*l;f.set(a.subarray(d,d+l),p)}return this.P[t]=f,f}U(){for(let t=0;t<this.G;t++)this.k(t)}V(){const t=this.S;this.D={framebuffer:t.getParameter(t.FRAMEBUFFER_BINDING),viewport:t.getParameter(t.VIEWPORT)},t.bindFramebuffer(t.FRAMEBUFFER,this.M),this.P=Array(this.G).fill(null);for(let r=0;r<this.G;r++)t.clearBufferfv(t.COLOR,r,new Float32Array([0,0,0,0]));t.viewport(0,0,this.C,this.$),G(t,[0,0,this.C,this.$])}O(){if(!this.D)return;const t=this.S;t.bindFramebuffer(t.FRAMEBUFFER,this.D.framebuffer),t.viewport(...this.D.viewport),G(t,this.D.viewport),this.D=null}j(){const t=this.S;this.M&&t.deleteFramebuffer(this.M);for(const r of this.F)t.deleteTexture(r);this.F=[],this.P=[]}get width(){return this.C}get height(){return this.$}get pixels(){return this.R}get options(){return{...this.u}}get framebuffer(){return this.M}get texture(){return this.F[0]}get textures(){return[...this.F]}get attachmentCount(){return this.G}getAttachmentPixels(t){return this.P[t]??null}}class V{constructor(t,r,i){u(this,"S");u(this,"H");u(this,"X",new Map);u(this,"Y",new Map);u(this,"q",0);u(this,"Z");this.S=t,this.H=this.N(r,i),this.Z=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),this.J()}J(){const t=this.S.getProgramParameter(this.H,this.S.ACTIVE_UNIFORMS);for(let r=0;r<t;r++){const i=this.S.getActiveUniform(this.H,r);if(i){const n=this.S.getUniformLocation(this.H,i.name);n&&(this.X.set(i.name,n),this.Y.set(i.name,i.type))}}}N(t,r){const i=this.K(this.S.VERTEX_SHADER,t),n=this.K(this.S.FRAGMENT_SHADER,r),o=this.S.createProgram();if(this.S.attachShader(o,i),this.S.attachShader(o,n),this.S.linkProgram(o),!this.S.getProgramParameter(o,this.S.LINK_STATUS)){const a=this.S.getProgramInfoLog(o);throw Error("Shader program link error: "+a)}return this.S.deleteShader(i),this.S.deleteShader(n),o}K(t,r){const i=this.S.createShader(t);if(this.S.shaderSource(i,r),this.S.compileShader(i),!this.S.getShaderParameter(i,this.S.COMPILE_STATUS)){const n=this.S.getShaderInfoLog(i);throw this.S.deleteShader(i),Error("Shader compilation error: "+n)}return i}tt(){this.S.useProgram(this.H),this.et()}et(){this.q=0}st(t){for(const[r,i]of Object.entries(t))this.it(r,i)}rt(t){return this.X.has(t)}it(t,r){if(this.S.getParameter(this.S.CURRENT_PROGRAM)!==this.H)return void console.warn(`Attempting to set uniform '${t}' on shader that is not currently bound`);const i=this.X.get(t);if(i)if(typeof r=="number")this.S.uniform1f(i,r);else if(typeof r=="boolean")this.S.uniform1i(i,r?1:0);else if(Array.isArray(r))switch(r.length){case 2:this.S.uniform2f(i,r[0],r[1]);break;case 3:this.S.uniform3f(i,r[0],r[1],r[2]);break;case 4:this.S.uniform4f(i,r[0],r[1],r[2],r[3]);break;default:console.warn(`Unsupported array length ${r.length} for uniform '${t}'`)}else if(r instanceof WebGLTexture){const n=this.nt();this.S.uniform1i(i,n),this.S.activeTexture(this.S.TEXTURE0+n),this.S.bindTexture(this.S.TEXTURE_2D,r)}else if(r instanceof N){const n=this.nt();this.S.uniform1i(i,n),this.S.activeTexture(this.S.TEXTURE0+n),this.S.bindTexture(this.S.TEXTURE_2D,r.texture)}else if(typeof r=="object"&&"texture"in r){const n=this.nt();this.S.uniform1i(i,n),this.S.activeTexture(this.S.TEXTURE0+n),this.S.bindTexture(this.S.TEXTURE_2D,r.texture)}else console.warn(`Unsupported uniform type for '${t}':`,typeof r)}nt(){return this.q>=this.Z&&console.warn(`Exceeded maximum texture units (${this.Z}). Texture may not render correctly.`),this.q++}get ot(){return this.H}j(){this.S.deleteProgram(this.H)}}class st{constructor(){u(this,"ht",1);u(this,"ct",0);u(this,"lt",0);u(this,"ut",0);u(this,"ft",[0,0,0]);u(this,"dt",[1,1,1,1]);u(this,"_t",[0,0,0,1]);u(this,"gt",!1);u(this,"vt",!1);u(this,"xt",!1);u(this,"Ct",[0,0]);u(this,"yt",[0,0,0,1]);u(this,"wt",[])}$t(){this.wt.push({lineWeight:this.ht,rotationX:this.ct,rotationY:this.lt,rotationZ:this.ut,charRotation:[...this.Ct],flipHorizontally:this.gt,flipVertically:this.vt,invert:this.xt,character:[...this.ft],charColor:[...this.dt],cellColor:[...this._t]})}bt(){const t=this.wt.pop();t?(this.ht=t.lineWeight,this.ct=t.rotationX,this.lt=t.rotationY,this.ut=t.rotationZ,this.Ct=t.charRotation,this.gt=t.flipHorizontally,this.vt=t.flipVertically,this.xt=t.invert,this.ft=t.character,this.dt=t.charColor,this._t=t.cellColor):console.warn("pop() called without matching push()")}zt(){this.wt=[],this.ct=0,this.lt=0,this.ut=0}Rt(t){t.lineWeight=this.ht,t.rotationX=this.ct,t.rotationY=this.lt,t.rotationZ=this.ut,t.character[0]=this.ft[0],t.character[1]=this.ft[1],t.character[2]=this.ft[2],t.charColor[0]=this.dt[0],t.charColor[1]=this.dt[1],t.charColor[2]=this.dt[2],t.charColor[3]=this.dt[3],t.bgColor[0]=this._t[0],t.bgColor[1]=this._t[1],t.bgColor[2]=this._t[2],t.bgColor[3]=this._t[3],t.flipHorizontally=this.gt,t.flipVertically=this.vt,t.invert=this.xt,t.charRotation[0]=this.Ct[0],t.charRotation[1]=this.Ct[1]}get lineWeight(){return this.ht}get canvasBackgroundColor(){return this.yt}Tt(t){this.ht=Math.abs(t)}St(t){this.ct=t}Mt(t){this.lt=t}Ft(t){this.ut=t}Gt(t){this.ft=t}Dt(t,r,i,n=255){this.dt=[t/255,r/255,i/255,n/255]}Pt(t,r,i,n=255){this._t=[t/255,r/255,i/255,n/255]}At(t){this.gt=t}Bt(t){this.vt=t}It(t){this.xt=t}Lt(t){const r=255*t/360,i=Math.floor(r)/255,n=Math.round(r-Math.floor(r));this.Ct=[i,n]}Et(t,r,i,n){this.yt=[t/255,r/255,i/255,n/255]}}var X=`#version 300 es
8
- in vec2 a_position;in vec2 a_texCoord;in vec2 a_instancePosition;in vec2 a_instanceSize;in vec3 a_instanceCharacter;in vec4 a_instancePrimaryColor;in vec4 a_instanceSecondaryColor;in vec2 a_instanceRotation;in vec3 a_instanceTransform;in vec3 a_instanceGlobalRotation;in vec2 a_instanceRotationCenter;in vec2 a_instanceBezierCP1;in vec2 a_instanceBezierCP2;in vec2 a_instanceBezierStart;in vec2 a_instanceBezierEnd;in vec2 a_instanceArcAngles;uniform float u_aspectRatio;uniform vec2 u_viewportSize;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 rotateX(float a){float s=sin(a),c=cos(a);return mat3(1,0,0,0,c,-s,0,s,c);}mat3 rotateY(float a){float s=sin(a),c=cos(a);return mat3(c,0,s,0,1,0,-s,0,c);}mat3 rotateZ(float a){float s=sin(a),c=cos(a);return mat3(c,-s,0,s,c,0,0,0,1);}vec2 evaluateBezier(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float u=1.-t,u2=u*u,t2=t*t;return u2*u*p0+3.*u2*t*p1+3.*u*t2*p2+t2*t*p3;}vec2 evaluateBezierDerivative(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float u=1.-t,u2=u*u,t2=t*t;return-3.*u2*p0+3.*u2*p1-6.*u*t*p1+6.*u*t*p2-3.*t2*p2+3.*t2*p3;}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 worldPosition;bool isBezier=length(a_instanceBezierCP1)+length(a_instanceBezierCP2)+length(a_instanceBezierStart)+length(a_instanceBezierEnd)>0.;bool isArc=a_instanceArcAngles.x!=0.||a_instanceArcAngles.y!=0.;if(isBezier){float t=a_position.x;vec2 curvePoint=evaluateBezier(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 tangent=evaluateBezierDerivative(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float tLen=length(tangent);tangent=tLen>0.?tangent/tLen:vec2(1,0);worldPosition=curvePoint+vec2(-tangent.y,tangent.x)*a_position.y*a_instanceSize.y;}else if(isArc){float s=a_instanceArcAngles.x,e=a_instanceArcAngles.y;s=mod(s,6.28318530718);if(s<0.)s+=6.28318530718;e=mod(e,6.28318530718);if(e<0.)e+=6.28318530718;float d=s-e;if(d<=0.)d+=6.28318530718;float angle=s-a_position.x*d;vec2 local=vec2(cos(angle),sin(angle))*a_position.y;worldPosition=local*a_instanceSize*.5+a_instanceSize*.5+a_instancePosition;}else{worldPosition=a_position*a_instanceSize+a_instancePosition;}vec2 ndc=(worldPosition/u_viewportSize)*2.-1.;ndc.y=-ndc.y;if(length(a_instanceGlobalRotation)>0.){vec3 pos3D=vec3(ndc-a_instanceRotationCenter,0);pos3D.x*=u_aspectRatio;if(a_instanceGlobalRotation.x!=0.)pos3D=rotateX(-a_instanceGlobalRotation.x)*pos3D;if(a_instanceGlobalRotation.y!=0.)pos3D=rotateY(-a_instanceGlobalRotation.y)*pos3D;if(a_instanceGlobalRotation.z!=0.)pos3D=rotateZ(-a_instanceGlobalRotation.z)*pos3D;pos3D.x/=u_aspectRatio;ndc=pos3D.xy+a_instanceRotationCenter;}gl_Position=vec4(ndc,0,1);}`,C=(c=>(c.RECTANGLE="rectangle",c.LINE="line",c.ELLIPSE="ellipse",c.ARC="arc",c.TRIANGLE="triangle",c.BEZIER_CURVE="bezier_curve",c.CUSTOM="custom",c))(C||{});class nt{constructor(t){u(this,"S");u(this,"Wt",new Map);this.S=t}kt(t,r,i,n){const o=this.S;let a=this.Wt.get(t);a||(a=new Map,this.Wt.set(t,a));let h=a.get(r)||null;if(!h){h=o.createVertexArray(),a.set(r,h),o.bindVertexArray(h),o.bindBuffer(o.ARRAY_BUFFER,n);const l=o.getAttribLocation(t,"a_position");l!==-1&&(o.enableVertexAttribArray(l),o.vertexAttribPointer(l,i.attributes.position.size,o.FLOAT,!1,i.stride,i.attributes.position.offset),o.vertexAttribDivisor(l,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,i.attributes.texCoord.size,o.FLOAT,!1,i.stride,i.attributes.texCoord.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(h)}Ut(){this.S.bindVertexArray(null)}j(){const t=this.S;for(const[,r]of this.Wt)for(const[,i]of r)i&&t.deleteVertexArray(i);this.Wt.clear()}}class ot{constructor(t){u(this,"Vt");u(this,"S");u(this,"Ot",null);u(this,"jt",null);u(this,"Ht",null);this.S=t,this.Vt=new nt(t)}Xt(t,r,i){const{shader:n}=t,o=D(this.S)||this.S.getParameter(this.S.VIEWPORT),a={u_aspectRatio:o[2]/o[3],u_viewportSize:[o[2],o[3]]},h={};for(const[d,p]of Object.entries(a))n.rt(d)&&(h[d]=p);Object.keys(h).length>0&&n.st(h);const l=d=>{if(!d||!d.Yt())return;const p=d.unitGeometry,x=d.unitBuffer;try{this.Vt.kt(n.ot,d.type+"",p,x),d.batch.qt(n),d.batch.Zt(p.primitiveType,p.vertexCount)}finally{d.batch.Nt(n),this.Vt.Ut(),d.Qt()}};let f=null,g=null;for(const d of r){if(d.type===C.CUSTOM){g&&(l(g),f=null,g=null),this.Jt(t,d.params,d.state,i.get(C.RECTANGLE)||null);continue}f!==null&&d.type!==f&&(l(g),f=null,g=null);let p=g;p&&d.type===f||(p=i.get(d.type)||null,g=p,f=d.type),p&&p.Kt(d.params,d.state)}l(g)}Jt(t,r,i,n){if(!n)return;const{x:o,y:a,width:h,height:l,shader:f,uniforms:g}=r,d=this.S;f.tt(),n.Qt();const p=this.te(Math.max(1,Math.floor(h)),Math.max(1,Math.floor(l)));p.V(),f.tt(),g&&Object.keys(g).length&&f.st(g);{const R=D(d)||d.getParameter(d.VIEWPORT);f.rt("u_aspectRatio")&&f.it("u_aspectRatio",R[2]/R[3]),f.rt("u_viewportSize")&&f.it("u_viewportSize",[R[2],R[3]])}const x={...i,rotationX:0,rotationY:0,rotationZ:0};if(n.Kt({x:0,y:0,width:p.width,height:p.height},x),n.Yt()){const R=n.unitGeometry,B=n.unitBuffer;try{this.Vt.kt(f.ot,n.type+"",R,B),n.batch.qt(f),n.batch.Zt(R.primitiveType,R.vertexCount)}finally{n.batch.Nt(f),this.Vt.Ut(),n.Qt()}}p.O();const m=this.ee();m.tt(),m.st({u_src0:p.textures[0],u_src1:p.textures[1],u_src2:p.textures[2],u_src3:p.textures[3],u_src4:p.textures[4],u_srcSize:[p.width,p.height]});const y=D(d)||d.getParameter(d.VIEWPORT);m.rt("u_aspectRatio")&&m.it("u_aspectRatio",y[2]/y[3]),m.rt("u_viewportSize")&&m.it("u_viewportSize",[y[2],y[3]]);const w=Math.floor(o),b=Math.floor(a),T=Math.max(1,Math.floor(h)),A=Math.max(1,Math.floor(l));if(n.Kt({x:w,y:b,width:T,height:A},i),n.Yt()){const R=n.unitGeometry,B=n.unitBuffer;try{this.Vt.kt(m.ot,n.type+"",R,B),n.batch.qt(m),n.batch.Zt(R.primitiveType,R.vertexCount)}finally{n.batch.Nt(m),this.Vt.Ut(),n.Qt()}}t.shader.tt()}ee(){return this.Ot||(this.Ot=new V(this.S,X,`#version 300 es
9
- precision highp float;in vec2 v_uv;uniform sampler2D u_src0;uniform sampler2D u_src1;uniform sampler2D u_src2;uniform sampler2D u_src3;uniform sampler2D u_src4;uniform vec2 u_srcSize;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 uvTex=v_uv*u_srcSize;vec2 uvQ=(floor(uvTex)+0.5f)/u_srcSize;o_character=texture(u_src0,uvQ);o_primaryColor=texture(u_src1,uvQ);o_secondaryColor=texture(u_src2,uvQ);o_rotation=texture(u_src3,uvQ);o_transform=texture(u_src4,uvQ);}`)),this.Ot}te(t,r){return this.jt&&this.Ht&&this.Ht.w===t&&this.Ht.h===r||(this.jt&&this.jt.j(),this.jt=new N(this.S,t,r,5),this.Ht={w:t,h:r}),this.jt}}class at{constructor(){u(this,"se",[]);u(this,"ie",1);u(this,"re",0)}ne(t){if(this.re>=this.se.length){const i={id:this.ie++,type:t,params:{},state:{lineWeight:1,rotationX:0,rotationY:0,rotationZ:0,character:[0,0,0],charColor:[1,1,1,1],bgColor:[0,0,0,1],flipHorizontally:!1,flipVertically:!1,invert:!1,charRotation:[0,0]}};this.se.push(i)}const r=this.se[this.re];switch(r.id=this.ie++,r.type=t,t){case C.RECTANGLE:case C.ELLIPSE:r.params&&"width"in r.params||(r.params={x:0,y:0,width:0,height:0});break;case C.CUSTOM:r.params&&"shader"in r.params||(r.params={x:0,y:0,width:0,height:0,shader:void 0,uniforms:{}});break;case C.ARC:r.params&&"start"in r.params||(r.params={x:0,y:0,width:0,height:0,start:0,stop:0});break;case C.LINE:r.params&&"x2"in r.params||(r.params={x1:0,y1:0,x2:0,y2:0,thickness:void 0});break;case C.TRIANGLE:r.params&&"x3"in r.params||(r.params={x1:0,y1:0,x2:0,y2:0,x3:0,y3:0});break;case C.BEZIER_CURVE:r.params&&"cp2y"in r.params||(r.params={x1:0,y1:0,cp1x:0,cp1y:0,cp2x:0,cp2y:0,x2:0,y2:0,thickness:void 0});break;default:r.params||(r.params={})}return this.re++,r}oe(t,r,i,n,o){const a=this.ne(C.RECTANGLE);return a.params.x=t,a.params.y=r,a.params.width=i,a.params.height=n,o.Rt(a.state),a.id}ae(t,r,i,n,o,a,h){const l=this.ne(C.CUSTOM);return l.params.x=t,l.params.y=r,l.params.width=i,l.params.height=n,l.params.shader=o,l.params.uniforms=a,h.Rt(l.state),l.id}he(t,r,i,n,o,a){const h=this.ne(C.LINE);return h.params.x1=t,h.params.y1=r,h.params.x2=i,h.params.y2=n,h.params.thickness=o,a.Rt(h.state),h.id}ce(t,r,i,n,o){const a=this.ne(C.ELLIPSE);return a.params.x=t,a.params.y=r,a.params.width=i,a.params.height=n,o.Rt(a.state),a.id}le(t,r,i,n,o,a,h){const l=this.ne(C.ARC);return l.params.x=t,l.params.y=r,l.params.width=i,l.params.height=n,l.params.start=o,l.params.stop=a,h.Rt(l.state),l.id}ue(t,r,i,n,o,a,h){const l=this.ne(C.TRIANGLE);return l.params.x1=t,l.params.y1=r,l.params.x2=i,l.params.y2=n,l.params.x3=o,l.params.y3=a,h.Rt(l.state),l.id}fe(t,r,i,n,o,a,h,l,f,g){const d=this.ne(C.BEZIER_CURVE);return d.params.x1=t,d.params.y1=r,d.params.cp1x=i,d.params.cp1y=n,d.params.cp2x=o,d.params.cp2y=a,d.params.x2=h,d.params.y2=l,d.params.thickness=f,g.Rt(d.state),d.id}get length(){return this.re}get isEmpty(){return this.re===0}de(){this.re=0}[Symbol.iterator](){let t=0;const r=this.re,i=this.se;return{next:()=>t<r?{value:i[t++],done:!1}:{value:void 0,done:!0}}}}const U=class U{static pe(t,r,i=0){var a,h,l,f,g,d,p,x,m,y;const n=r||new Float32Array(U.FLOATS_PER_INSTANCE);let o=i;return n[o++]=t.position[0],n[o++]=t.position[1],n[o++]=t.size[0],n[o++]=t.size[1],n[o++]=t.character[0],n[o++]=t.character[1],n[o++]=t.character[2],n[o++]=t.primaryColor[0],n[o++]=t.primaryColor[1],n[o++]=t.primaryColor[2],n[o++]=t.primaryColor[3],n[o++]=t.secondaryColor[0],n[o++]=t.secondaryColor[1],n[o++]=t.secondaryColor[2],n[o++]=t.secondaryColor[3],n[o++]=t.rotation[0],n[o++]=t.rotation[1],n[o++]=t.transform[0],n[o++]=t.transform[1],n[o++]=t.transform[2],n[o++]=t.globalRotationX,n[o++]=t.globalRotationY,n[o++]=t.globalRotationZ,n[o++]=t.rotationCenter[0],n[o++]=t.rotationCenter[1],n[o++]=((a=t.arcAngles)==null?void 0:a[0])||0,n[o++]=((h=t.arcAngles)==null?void 0:h[1])||0,n[o++]=((l=t.bezierControlPoint1)==null?void 0:l[0])||0,n[o++]=((f=t.bezierControlPoint1)==null?void 0:f[1])||0,n[o++]=((g=t.bezierControlPoint2)==null?void 0:g[0])||0,n[o++]=((d=t.bezierControlPoint2)==null?void 0:d[1])||0,n[o++]=((p=t.bezierStartPoint)==null?void 0:p[0])||0,n[o++]=((x=t.bezierStartPoint)==null?void 0:x[1])||0,n[o++]=((m=t.bezierEndPoint)==null?void 0:m[0])||0,n[o++]=((y=t.bezierEndPoint)==null?void 0:y[1])||0,n}static _e(t){const r=t.length*U.FLOATS_PER_INSTANCE,i=new Float32Array(r);for(let n=0;n<t.length;n++){const o=n*U.FLOATS_PER_INSTANCE;U.pe(t[n],i,o)}return i}};u(U,"BYTES_PER_INSTANCE",140),u(U,"FLOATS_PER_INSTANCE",35);let P=U;const S=class S{};u(S,"STRIDE",P.BYTES_PER_INSTANCE),u(S,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:132,divisor:1}});let $=S;class ht{constructor(t,r=1e3,i=1.5){u(this,"S");u(this,"ge",[]);u(this,"me");u(this,"ve");u(this,"xe",null);u(this,"Ce",!0);u(this,"ye",0);u(this,"we",new Map);u(this,"$e",null);this.S=t,this.me=r,this.ve=i,this.be()}Kt(t){const r=this.ge.length;return this.ge.push(t),this.Ce=!0,r}get count(){return this.ge.length}get isEmpty(){return this.ge.length===0}clear(){this.ge.length=0,this.Ce=!0}ze(t){if(t<=this.me)return;const r=Math.ceil(t*this.ve);this.me=r,this.be()}be(){const t=this.S;this.xe&&t.deleteBuffer(this.xe),this.xe=t.createBuffer();const r=this.me*P.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.xe),t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Ce=!0,this.ye=0}Re(){if(!this.Ce||this.ge.length===0)return;const t=this.S,r=this.ge.length;this.ze(r),(!this.$e||this.$e.length<r*P.FLOATS_PER_INSTANCE)&&(this.$e=new Float32Array(r*P.FLOATS_PER_INSTANCE));const i=P._e(this.ge);t.bindBuffer(t.ARRAY_BUFFER,this.xe),r<=this.ye?t.bufferSubData(t.ARRAY_BUFFER,0,i):t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Ce=!1,this.ye=r}Te(t){let r=this.we.get(t);if(!r){r=new Map;const i=this.S;for(const n in $.ATTRIBUTES){const o=i.getAttribLocation(t,n);o!==-1&&r.set(n,o)}this.we.set(t,r)}return r}qt(t){if(!this.xe||this.ge.length===0)return;const r=this.S,i=t.ot;this.Re();const n=this.Te(i);r.bindBuffer(r.ARRAY_BUFFER,this.xe);for(const[o,a]of n){const h=$.ATTRIBUTES[o];h&&(r.enableVertexAttribArray(a),r.vertexAttribPointer(a,h.size,h.type,h.normalized,h.stride,h.offset),r.vertexAttribDivisor(a,h.divisor))}}Nt(t){const r=this.S,i=this.Te(t.ot);for(const[,n]of i)r.disableVertexAttribArray(n),r.vertexAttribDivisor(n,0)}Zt(t,r){this.ge.length!==0&&this.S.drawArraysInstanced(t,0,r,this.ge.length)}j(){const t=this.S;this.xe&&(t.deleteBuffer(this.xe),this.xe=null),this.ge.length=0,this.we.clear(),this.$e=null}}class M{constructor(t,r,i,n){u(this,"S");u(this,"Se");u(this,"Me");u(this,"Fe");u(this,"Ge",null);this.S=t,this.Se=r,this.Me=i,this.Fe=n;const o=this.S.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.S.bindBuffer(this.S.ARRAY_BUFFER,o),this.S.bufferData(this.S.ARRAY_BUFFER,this.Fe.vertices,this.S.STATIC_DRAW),this.S.bindBuffer(this.S.ARRAY_BUFFER,null),this.Ge=o}get type(){return this.Me}get unitGeometry(){return this.Fe}get unitBuffer(){return this.Ge}get batch(){return this.Se}Qt(){this.Se.clear()}Yt(){return!this.Se.isEmpty}j(){this.Se.j(),this.Ge&&(this.S.deleteBuffer(this.Ge),this.Ge=null)}De(t,r,i,n,o){const a=this.Pe(t,r,i,n,o.rotationX||0,o.rotationY||0,o.rotationZ||0);return{position:[t,r],size:[i,n],character:o.character||[0,0,0],primaryColor:o.charColor||[1,1,1,1],secondaryColor:o.bgColor||[0,0,0,1],rotation:o.charRotation||[0,0],transform:[o.invert?1:0,o.flipHorizontally?1:0,o.flipVertically?1:0],globalRotationX:a.radiansX,globalRotationY:a.radiansY,globalRotationZ:a.radiansZ,rotationCenter:[a.centerX,a.centerY]}}Ae(t,r){const i=D(this.S)||[0,0,this.S.canvas.width,this.S.canvas.height];return{nx:t/i[2]*2-1,ny:1-r/i[3]*2}}Be(t,r,i){const n=this.Ae(r,i);t.rotationCenter=[n.nx,n.ny]}Pe(t,r,i,n,o,a,h){const l=D(this.S)||[0,0,this.S.canvas.width,this.S.canvas.height],f=l[2],g=l[3];return{centerX:(t+i/2)/f*2-1,centerY:1-(r+n/2)/g*2,radiansX:-o*Math.PI/180,radiansY:-a*Math.PI/180,radiansZ:-h*Math.PI/180,aspectRatio:f/g}}}const ct={vertices: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]),vertexCount:6,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class lt extends M{constructor(t,r){super(t,r,C.RECTANGLE,ct)}Kt(t,r){const i=this.De(t.x,t.y,t.width,t.height,r);return this.Se.Kt(i)}}const ut={vertices: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]),vertexCount:6,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class ft extends M{constructor(t,r){super(t,r,C.LINE,ut)}Kt(t,r){const i=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(i,n),a=Math.atan2(n,i),h=t.thickness||r.lineWeight||1,l=t.x1+i/2,f=t.y1+n/2,g=l-o/2,d=f,p={character:r.character,charColor:r.charColor,bgColor:r.bgColor,charRotation:r.charRotation,flipHorizontally:r.flipHorizontally,flipVertically:r.flipVertically,invert:r.invert,rotationX:r.rotationX||0,rotationY:r.rotationY||0,rotationZ:(r.rotationZ||0)+180*a/Math.PI,lineWeight:h},x=this.De(g,d,o,h,p);return this.Be(x,l,f),this.Se.Kt(x)}}const dt={vertices:function(c=32){const t=[],r=2*Math.PI/c;for(let i=0;i<c;i++){const n=i*r,o=(i+1)%c*r,a=Math.cos(n),h=Math.sin(n),l=.5*(a+1),f=.5*(h+1),g=Math.cos(o),d=Math.sin(o),p=.5*(g+1),x=.5*(d+1);t.push(0,0,.5,.5,a,h,l,f,g,d,p,x)}return new Float32Array(t)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class pt extends M{constructor(t,r){super(t,r,C.ELLIPSE,dt)}Kt(t,r){const i=this.De(t.x,t.y,t.width,t.height,r);return this.Be(i,t.x,t.y),this.Se.Kt(i)}}let gt={vertices:function(c){const t=[];for(let r=0;r<c;r++){const i=r/c,n=(r+1)/c;t.push(i,0,i,0,i,1,i,1,n,1,n,1)}return new Float32Array(t)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class mt extends M{constructor(t,r){super(t,r,C.ARC,gt)}Kt(t,r){const i=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,a=t.stop*Math.PI/180,h=this.De(i,n,t.width,t.height,r);return this.Be(h,t.x,t.y),h.arcAngles=[o,a],this.Se.Kt(h)}}const xt={vertices:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),vertexCount:3,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class yt extends M{constructor(t,r){super(t,r,C.TRIANGLE,xt)}Kt(t,r){const i=Math.min(t.x1,t.x2,t.x3),n=Math.max(t.x1,t.x2,t.x3),o=Math.min(t.y1,t.y2,t.y3),a=n-i,h=Math.max(t.y1,t.y2,t.y3)-o,l=this.De(i,o,a,h,r),f=i+.5*a,g=o+h*(1/3);return this.Be(l,f,g),this.Se.Kt(l)}}function Q(c,t,r,i,n){const o=1-c,a=o*o,h=c*c;return a*o*t+3*a*c*r+3*o*h*i+h*c*n}const Ct={vertices:function(c=16){const t=[];for(let r=0;r<c;r++){const i=r/c,n=(r+1)/c;t.push(i,-.5,i,0),t.push(n,-.5,n,0),t.push(i,.5,i,1),t.push(i,.5,i,1),t.push(n,-.5,n,0),t.push(n,.5,n,1)}return new Float32Array(t)}(16),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class vt extends M{constructor(t,r){super(t,r,C.BEZIER_CURVE,Ct)}Kt(t,r){const i=r.lineWeight||1,n=Q(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=Q(.5,t.y1,t.cp1y,t.cp2y,t.y2),a={character:r.character,charColor:r.charColor,bgColor:r.bgColor,charRotation:r.charRotation,flipHorizontally:r.flipHorizontally,flipVertically:r.flipVertically,invert:r.invert,rotationX:r.rotationX||0,rotationY:r.rotationY||0,rotationZ:r.rotationZ||0,lineWeight:i},h=this.De(0,0,1,i,a);return this.Be(h,n,o),h.bezierStartPoint=[t.x1,t.y1],h.bezierControlPoint1=[t.cp1x,t.cp1y],h.bezierControlPoint2=[t.cp2x,t.cp2y],h.bezierEndPoint=[t.x2,t.y2],this.Se.Kt(h)}}class St{constructor(t){u(this,"S");u(this,"Ie",null);u(this,"Le",null);u(this,"Ee",{});u(this,"We",null);u(this,"ke",new Map);u(this,"Ue");u(this,"Ve");u(this,"Oe");this.S=t,this.Oe=new st,this.Ue=new ot(t),this.Ve=new at,this.We=t.createBuffer(),G(this.S,[0,0,this.S.canvas.width,this.S.canvas.height])}je(t){let r=this.ke.get(t);if(r)return r;const i=new ht(this.S);return r=(0,{[C.RECTANGLE]:()=>new lt(this.S,i),[C.LINE]:()=>new ft(this.S,i),[C.ELLIPSE]:()=>new pt(this.S,i),[C.ARC]:()=>new mt(this.S,i),[C.TRIANGLE]:()=>new yt(this.S,i),[C.BEZIER_CURVE]:()=>new vt(this.S,i)}[t])(),this.ke.set(t,r),r}He(t){this.Ie!==t&&(this.Ie=t,t.tt())}Xe(t,r){return new V(this.S,t,r)}Ye(t){this.Le=t,t&&(this.Ee={})}qe(t,r){this.Ee[t]=r}Ze(t){Object.assign(this.Ee,t)}Ne(t){return new V(this.S,X,t)}Qe(t,r,i,n){var y;const o=this.S,a=o.canvas.width,h=o.canvas.height,l=t/a*2-1,f=(t+i)/a*2-1,g=1-r/h*2,d=1-(r+n)/h*2,p=new Float32Array([l,d,f,d,l,g,f,d,f,g,l,g]);o.bindBuffer(o.ARRAY_BUFFER,this.We),o.bufferData(o.ARRAY_BUFFER,p,o.DYNAMIC_DRAW);const x=((y=this.Ie)==null?void 0:y.ot)||o.getParameter(o.CURRENT_PROGRAM),m=x?o.getAttribLocation(x,"a_position"):-1;m!==-1&&(o.enableVertexAttribArray(m),o.vertexAttribPointer(m,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),m!==-1&&o.disableVertexAttribArray(m)}Je(t,r,i,n){this.Le?(this.Ve.ae(t,r,i,n,this.Le,{...this.Ee},this.Oe),this.Le=null,this.Ee={}):this.Ve.oe(t,r,i,n,this.Oe)}Ke(t,r,i,n){this.Ve.he(t,r,i,n,this.Oe.lineWeight,this.Oe)}ts(t,r,i,n){this.Ve.ce(t,r,i,n,this.Oe)}es(t,r,i,n,o,a){this.Ve.ue(t,r,i,n,o,a,this.Oe)}ss(t,r,i,n,o,a,h,l){const f=this.Oe.lineWeight;this.Ve.fe(t,r,i,n,o,a,h,l,f,this.Oe)}rs(t,r,i=1,n={}){return new N(this.S,t,r,i,n)}ns(t,r,i,n,o,a){this.Ve.le(t,r,i,n,o,a,this.Oe)}hs(t,r=t,i=t,n=255){this.state.Et(t,r,i,n),this.de(t/255,r/255,i/255,n/255)}de(t=0,r=0,i=0,n=0){this.S.clearColor(t,r,i,n),this.S.clear(this.S.COLOR_BUFFER_BIT)}cs(){this.S.viewport(0,0,this.S.canvas.width,this.S.canvas.height),G(this.S,[0,0,this.S.canvas.width,this.S.canvas.height])}get context(){return this.S}get state(){return this.Oe}ls(t){const r=t,i=D(this.S)??this.S.getParameter(this.S.VIEWPORT),n={shader:r,gl:this.S,viewport:i};this.He(r);const o=new Set;for(const a of this.Ve)a.type===C.CUSTOM?o.add(C.RECTANGLE):o.add(a.type);for(const a of o)a!==C.CUSTOM&&this.je(a);this.Ue.Xt(n,this.Ve,this.ke),this.Ve.de()}j(){this.S.deleteBuffer(this.We),this.Ve.de();for(const t of this.ke.values())t.j()}}const _={readShort:(c,t)=>(_.t.uint16[0]=c[t]<<8|c[t+1],_.t.int16[0]),readUshort:(c,t)=>c[t]<<8|c[t+1],readUshorts(c,t,r){const i=[];for(let n=0;n<r;n++)i.push(_.readUshort(c,t+2*n));return i},readUint(c,t){const r=_.t.uint8;return r[3]=c[t],r[2]=c[t+1],r[1]=c[t+2],r[0]=c[t+3],_.t.uint32[0]},readASCII(c,t,r){let i="";for(let n=0;n<r;n++)i+=String.fromCharCode(c[t+n]);return i},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()},Rt={parseTab(c,t,r){const i={tables:[],ids:{},off:t};c=new Uint8Array(c.buffer,t,r),t=0;const n=_,o=n.readUshort,a=o(c,t+=2);t+=2;const h=[];for(let l=0;l<a;l++){const f=o(c,t),g=o(c,t+=2);t+=2;const d=n.readUint(c,t);t+=4;const p=`p${f}e${g}`;let x=h.indexOf(d);if(x===-1){let m;x=i.tables.length,h.push(d);const y=o(c,d);m=y===4?this.parse4(c,d):y===12?this.parse12(c,d):{format:y},i.tables.push(m)}i.ids[p]!=null&&console.warn("Multiple tables for one platform+encoding: "+p),i.ids[p]=x}return i},parse4(c,t){const r=_,i=r.readUshort,n=r.readUshorts,o=t,a=i(c,t+=2);t+=2;const h=i(c,t+=2)>>>1,l={format:4,searchRange:i(c,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,l.entrySelector=i(c,t),t+=2,l.rangeShift=i(c,t),t+=2,l.endCount=n(c,t,h),t+=2*h,t+=2,l.startCount=n(c,t,h),t+=2*h;for(let f=0;f<h;f++)l.idDelta.push(r.readShort(c,t)),t+=2;return l.idRangeOffset=n(c,t,h),t+=2*h,l.glyphIdArray=n(c,t,o+a-t>>1),l},parse12(c,t){const r=_.readUint;r(c,t+=4),r(c,t+=4);const i=r(c,t+=4);t+=4;const n=new Uint32Array(3*i);for(let o=0;o<3*i;o+=3)n[o]=r(c,t+(o<<2)),n[o+1]=r(c,t+(o<<2)+4),n[o+2]=r(c,t+(o<<2)+8);return{format:12,groups:n}}},Et={parseTab(c,t,r){const i=_;t+=18;const n=i.readUshort(c,t);t+=2,t+=16;const o=i.readShort(c,t);t+=2;const a=i.readShort(c,t);t+=2;const h=i.readShort(c,t);t+=2;const l=i.readShort(c,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:a,xMax:h,yMax:l,indexToLocFormat:i.readShort(c,t)}}},bt={parseTab(c,t,r){const i=_;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let a=0;a<n.length;a++){const h=n[a],l=h==="advanceWidthMax"||h==="numberOfHMetrics"?i.readUshort:i.readShort;o[h]=l(c,t+2*a)}return o}},_t={parseTab(c,t,r,i){const n=_,o=[],a=[],h=i.maxp.numGlyphs,l=i.hhea.numberOfHMetrics;let f=0,g=0,d=0;for(;d<l;)f=n.readUshort(c,t+(d<<2)),g=n.readShort(c,t+(d<<2)+2),o.push(f),a.push(g),d++;for(;d<h;)o.push(f),a.push(g),d++;return{aWidth:o,lsBearing:a}}},Z={cmap:Rt,head:Et,hhea:bt,maxp:{parseTab(c,t,r){const i=_;return i.readUint(c,t),t+=4,{numGlyphs:i.readUshort(c,t)}}},hmtx:_t,loca:{parseTab(c,t,r,i){const n=_,o=[],a=i.head.indexToLocFormat,h=i.maxp.numGlyphs+1;if(a===0)for(let l=0;l<h;l++)o.push(n.readUshort(c,t+(l<<1))<<1);else if(a===1)for(let l=0;l<h;l++)o.push(n.readUint(c,t+(l<<2)));return o}},glyf:{parseTab(c,t,r,i){const n=[],o=i.maxp.numGlyphs;for(let a=0;a<o;a++)n.push(null);return n},us(c,t){const r=_,i=c.fs,n=c.loca;if(n[t]===n[t+1])return null;const o=F.findTable(i,"glyf",c.ds);if(!o)return null;let a=o[0]+n[t];const h={};if(h.noc=r.readShort(i,a),a+=2,h.xMin=r.readShort(i,a),a+=2,h.yMin=r.readShort(i,a),a+=2,h.xMax=r.readShort(i,a),a+=2,h.yMax=r.readShort(i,a),a+=2,h.xMin>=h.xMax||h.yMin>=h.yMax)return null;if(h.noc>0){h.endPts=[];for(let p=0;p<h.noc;p++)h.endPts.push(r.readUshort(i,a)),a+=2;const l=r.readUshort(i,a);if(a+=2,i.length-a<l)return null;a+=l;const f=h.endPts[h.noc-1]+1;h.flags=[];for(let p=0;p<f;p++){const x=i[a];if(a++,h.flags.push(x),8&x){const m=i[a];a++;for(let y=0;y<m;y++)h.flags.push(x),p++}}h.xs=[];for(let p=0;p<f;p++){const x=h.flags[p],m=!!(16&x);2&x?(h.xs.push(m?i[a]:-i[a]),a++):m?h.xs.push(0):(h.xs.push(r.readShort(i,a)),a+=2)}h.ys=[];for(let p=0;p<f;p++){const x=h.flags[p],m=!!(32&x);4&x?(h.ys.push(m?i[a]:-i[a]),a++):m?h.ys.push(0):(h.ys.push(r.readShort(i,a)),a+=2)}let g=0,d=0;for(let p=0;p<f;p++)g+=h.xs[p],d+=h.ys[p],h.xs[p]=g,h.ys[p]=d}else h.parts=[],h.endPts=[],h.flags=[],h.xs=[],h.ys=[];return h}}},F={parse:c=>[((t,r,i,n)=>{const o=Z,a={fs:t,ps:r,ds:i};for(const h in o){const l=h,f=F.findTable(t,l,i);if(f){const[g,d]=f;let p=n[g];p==null&&(p=o[l].parseTab(t,g,d,a),n[g]=p),a[l]=p}}return a})(new Uint8Array(c),0,0,{})],findTable(c,t,r){const i=_,n=i.readUshort(c,r+4);let o=r+12;for(let a=0;a<n;a++){const h=i.readASCII(c,o,4);i.readUint(c,o+4);const l=i.readUint(c,o+8),f=i.readUint(c,o+12);if(h===t)return[l,f];o+=16}return null},T:Z,B:_};class O{constructor(){u(this,"_s",new Map);u(this,"gs",new Map)}vs(t,r){const i=`${this.Cs(t)}_${r}`;if(this._s.has(i))return this._s.get(i);const n=t.cmap;if(!n||!n.tables)return this._s.set(i,0),0;let o=0;for(const a of n.tables)if(a.format===4?o=this.ws(r,a):a.format===12&&(o=this.$s(r,a)),o>0)break;return this._s.set(i,o),o}bs(t,r){const i=r.codePointAt(0);return i===void 0?0:this.vs(t,i)}zs(t,r){const i=t.hmtx;return i&&i.aWidth&&i.aWidth.length!==0?r<i.aWidth.length?i.aWidth[r]:i.aWidth[i.aWidth.length-1]:0}Rs(t,r){const i=r/t.head.unitsPerEm,n=t.hhea.ascender*i,o=t.hhea.descender*i,a=t.hhea.lineGap*i;return{ascender:n,descender:o,lineGap:a,lineHeight:n-o+a,unitsPerEm:t.head.unitsPerEm,scale:i}}Ts(){this._s.clear(),this.gs.clear()}Cs(t){return`${t.ds}_${t.fs.length}`}ws(t,r){const i=r.endCount.length;let n=-1;for(let o=0;o<i;o++)if(t<=r.endCount[o]){n=o;break}if(n===-1||t<r.startCount[n])return 0;if(r.idRangeOffset[n]===0)return t+r.idDelta[n]&65535;{const o=r.idRangeOffset[n]/2+(t-r.startCount[n])-(i-n);if(o>=0&&o<r.glyphIdArray.length){const a=r.glyphIdArray[o];return a===0?0:a+r.idDelta[n]&65535}}return 0}$s(t,r){const i=r.groups.length/3;for(let n=0;n<i;n++){const o=r.groups[3*n],a=r.groups[3*n+1],h=r.groups[3*n+2];if(t>=o&&t<=a)return h+(t-o)}return 0}}class wt{constructor(t){u(this,"Ss");this.Ss=t}Ms(t){var i;const r=[];return(i=t.cmap)!=null&&i.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.Fs(n);r.push(...o)}else if(n.format===12){const o=this.Gs(n);r.push(...o)}}),[...new Set(r)]):[]}Ds(t,r){return this.Ss.bs(t,r)>0}Ps(t,r){for(const i of r)if(!this.Ds(t,i))return!1;return!0}As(t,r){return r.filter(i=>this.Ds(t,i))}Bs(t){return t.filter(r=>this.Is(r))}Fs(t){const r=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return r;for(let i=0;i<t.startCount.length;i++){const n=t.startCount[i],o=t.endCount[i];if(n!==65535||o!==65535){for(let a=n;a<=o;a++)if(this.Ls(t,a,i)>0)try{const h=String.fromCodePoint(a);r.push(h)}catch{}}}return r}Gs(t){const r=[];if(!t.groups)return r;for(let i=0;i<t.groups.length;i+=3){const n=t.groups[i],o=t.groups[i+1],a=t.groups[i+2];for(let h=n;h<=o;h++)if(a+(h-n)>0)try{const l=String.fromCodePoint(h);r.push(l)}catch{}}return r}Ls(t,r,i){if(t.idRangeOffset[i]===0)return r+t.idDelta[i]&65535;{const n=t.idRangeOffset[i]/2+(r-t.startCount[i])-(t.startCount.length-i);if(n>=0&&t.glyphIdArray&&n<t.glyphIdArray.length){const o=t.glyphIdArray[n];if(o!==0)return o+t.idDelta[i]&65535}}return 0}Is(t){const r=t.codePointAt(0)||0;return!(r>=0&&r<=31&&r!==9&&r!==10&&r!==13||r>=127&&r<=159)}}class Tt{constructor(){u(this,"Es");const t=new O;this.Es=new wt(t)}extractCharacters(t){return this.Es.Ms(t)}filterProblematicCharacters(t){return this.Es.Bs(t)}characterExists(t,r){return this.Es.Ds(t,r)}allCharactersExist(t,r){return this.Es.Ps(t,r)}}class At{constructor(t){u(this,"Ws");u(this,"ks");u(this,"Us");u(this,"Vs");this.Us=t,this.Vs=new O,this.Ws=document.createElement("canvas"),this.ks=this.Ws.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(t,r,i,n){const o=t.length,a=Math.ceil(Math.sqrt(o)),h=Math.ceil(o/a),l=r.width*a,f=r.height*h,g=typeof n=="object"?n:null;this.Os(l,f),this.js(t,r,a,i,g);const d=this.Us.rs(l,f,1,{filter:"nearest"});return d.L(this.Ws),{framebuffer:d,columns:a,rows:h}}Os(t,r){this.Ws.width=t,this.Ws.height=r,this.Ws.style.width=t+"px",this.Ws.style.height=t+"px",this.ks.imageSmoothingEnabled=!1,this.Ws.style.imageRendering="pixelated",this.ks.fillStyle="black",this.ks.fillRect(0,0,t,r),this.ks.textBaseline="top",this.ks.textAlign="left",this.ks.fillStyle="white"}js(t,r,i,n,o){const a=n/o.head.unitsPerEm;for(let h=0;h<t.length;h++){const l=h%i,f=Math.floor(h/i),g=t[h].character,d=this.Hs(o,g);if(!d)continue;const p=g.codePointAt(0)||0,x=this.Vs.vs(o,p),m=this.Xs(o,x)*a,y=l*r.width,w=f*r.height,b=y+.5*r.width,T=w+.5*r.height,A=Math.round(b-.5*r.width),R=Math.round(T-.5*n),B=A+.5*(r.width-m),Jt=R+o.hhea.ascender*a;this.Ys(d,B,Jt,a)}}Hs(t,r){const i=r.codePointAt(0)||0,n=this.Vs.vs(t,i);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(F&&F.T&&F.T.glyf){const o=F.T.glyf.us(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}Xs(t,r){const i=t.hmtx;return i&&i.aWidth?r<i.aWidth.length?i.aWidth[r]:i.aWidth[i.aWidth.length-1]:0}Ys(t,r,i,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:a,endPts:h,flags:l}=t;if(!(o&&a&&h&&l))return;this.ks.beginPath();let f=0;for(let g=0;g<h.length;g++){const d=h[g];if(!(d<f)){if(d>=f){const p=r+o[f]*n,x=i-a[f]*n;this.ks.moveTo(p,x);let m=f+1;for(;m<=d;)if(1&l[m]){const y=r+o[m]*n,w=i-a[m]*n;this.ks.lineTo(y,w),m++}else{const y=r+o[m]*n,w=i-a[m]*n;let b=m+1>d?f:m+1;if(1&l[b]){const T=r+o[b]*n,A=i-a[b]*n;this.ks.quadraticCurveTo(y,w,T,A),m=b+1}else{const T=(y+(r+o[b]*n))/2,A=(w+(i-a[b]*n))/2;this.ks.quadraticCurveTo(y,w,T,A),m=b}}this.ks.closePath()}f=d+1}}this.ks.fill()}}class Ft{constructor(){u(this,"Ss");this.Ss=new O}calculateMaxGlyphDimensions(t,r,i){let n=0;const o=this.Ss.Rs(i,r),a=o.lineHeight;for(const h of t){const l=this.Ss.bs(i,h);if(l===0)continue;const f=this.Ss.zs(i,l)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}getCharacterAdvanceWidth(t,r,i){const n=this.Ss.Rs(i,r),o=this.Ss.bs(i,t);return this.Ss.zs(i,o)*n.scale}getFontMetrics(t,r){return this.Ss.Rs(r,t)}Ts(){this.Ss.Ts()}}class Ut{constructor(){u(this,"Vs");this.Vs=new O}createCharacterObjects(t,r){return t.map((i,n)=>{const o=i.codePointAt(0)||0,a=this.qs(n);let h=0;if(r.hmtx&&r.hmtx.aWidth){const l=this.Vs.vs(r,o);l>0&&r.hmtx.aWidth[l]!==void 0&&(h=r.hmtx.aWidth[l])}return{character:i,unicode:o,color:a,advanceWidth:h}})}qs(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}Zs(t,r){if(!z.m(typeof t=="string","Character must be a string.",{method:"getCharacterColor",providedValue:t}))return[0,0,0];const i=r.find(n=>n.character===t);return i?i.color:[0,0,0]}Ns(t,r){return z.m(typeof t=="string"&&t.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:t})?Array.from(t).map(i=>this.Zs(i,r)||[0,0,0]):[[0,0,0]]}}class K{constructor(t,r=16){u(this,"Qs");u(this,"Js",[]);u(this,"Ks");u(this,"ti",16);u(this,"ei",0);u(this,"si",0);u(this,"ii",{width:0,height:0});u(this,"ri");u(this,"ni");u(this,"oi");u(this,"ai");u(this,"hi");this.ti=r,this.ni=new Tt,this.oi=new At(t),this.ai=new Ft,this.hi=new Ut}async ci(t){let r;if(!t)throw new v("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const i=await fetch(t);if(!i.ok)throw new v(`Failed to load font file: ${i.status} ${i.statusText}`);r=await i.arrayBuffer()}await this.li(r),this.Qs=F.parse(r)[0],await this.ui()}fi(t){if(t===void 0)return this.ti;this.ti=t,this.ii=this.ai.calculateMaxGlyphDimensions(this.Js.map(i=>i.character),this.ti,this.Qs);const r=this.oi.createTextureAtlas(this.Js,this.ii,this.ti,this.Qs);this.Ks=r.framebuffer,this.ei=r.columns,this.si=r.rows}async di(t){try{const r=await fetch(t);if(!r.ok)throw new v(`Failed to load font file: ${r.status} ${r.statusText}`);const i=await r.arrayBuffer();await this.li(i);const n=F.parse(i);if(!n||n.length===0)throw Error("Failed to parse font file");this.Qs=n[0],await this.ui()}catch(r){throw new v("Failed to load font: "+(r instanceof Error?r.message:"Unknown error"),r)}}async li(t){const r=Date.now();this.ri=new FontFace("CustomFont_"+r,t),await this.ri.load(),document.fonts.add(this.ri)}async ui(){const t=this.ni.extractCharacters(this.Qs),r=this.ni.filterProblematicCharacters(t);this.Js=this.hi.createCharacterObjects(r,this.Qs),this.ii=this.ai.calculateMaxGlyphDimensions(r,this.ti,this.Qs);const i=this.oi.createTextureAtlas(this.Js,this.ii,this.ti,this.Qs);this.Ks=i.framebuffer,this.ei=i.columns,this.si=i.rows}Zs(t){return this.hi.Zs(t,this.Js)}Ns(t){return this.hi.Ns(t,this.Js)}j(){this.Ks.j(),document.fonts.delete(this.ri)}get fontFramebuffer(){return this.Ks}get characters(){return this.Js}get textureColumns(){return this.ei}get textureRows(){return this.si}get maxGlyphDimensions(){return this.ii}get fontSize(){return this.ti}get font(){return this.Qs}}class q{constructor(t,r,i){u(this,"pi");u(this,"_i");u(this,"C");u(this,"$");u(this,"gi");u(this,"mi");u(this,"xi");u(this,"Ci");u(this,"yi");this.xi=t,this.Ci=r,this.yi=i,this.zt()}zt(){this.pi=Math.floor(this.xi.width/this.Ci),this._i=Math.floor(this.xi.height/this.yi),this.C=this.pi*this.Ci,this.$=this._i*this.yi,this.gi=Math.floor((this.xi.width-this.C)/2),this.mi=Math.floor((this.xi.height-this.$)/2)}wi(t,r){this.Ci=t,this.yi=r,this.zt()}get cellWidth(){return this.Ci}get cellHeight(){return this.yi}get cols(){return this.pi}get rows(){return this._i}get width(){return this.C}get height(){return this.$}get offsetX(){return this.gi}get offsetY(){return this.mi}}class J{constructor(t={}){u(this,"xi");u(this,"$i");u(this,"bi");t.canvas?(this.xi=t.canvas,this.bi=!1):(this.xi=this.zi(t.width,t.height),this.bi=!0),this.xi.style.imageRendering="pixelated"}zi(t,r){const i=document.createElement("canvas");return i.className="textmodeCanvas",i.style.imageRendering="pixelated",i.width=t||800,i.height=r||600,document.body.appendChild(i),i}W(t,r){this.xi.width=t??this.xi.width,this.xi.height=r??this.xi.height}Ri(){const t=this.xi.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new v("`textmode.js` requires WebGL2 support.");return t}j(){this.$i&&this.$i.disconnect();const t=this.xi.getContext("webgl")||this.xi.getContext("webgl2");if(t){const r=t.getExtension("WEBGL_lose_context");r&&r.loseContext()}this.bi&&this.xi.parentNode&&this.xi.parentNode.removeChild(this.xi)}get canvas(){return this.xi}get width(){return this.xi.width}get height(){return this.xi.height}}class Lt{constructor(t=60){u(this,"Ti");u(this,"Si");u(this,"Mi",null);u(this,"Fi",0);u(this,"Gi",!0);u(this,"Di",0);u(this,"Pi",0);u(this,"Ai",[]);u(this,"Bi",10);u(this,"Ii",0);this.Ti=t,this.Si=1e3/t}start(t){if(!this.Gi)return;this.Fi=performance.now();const r=i=>{if(!this.Gi)return void(this.Mi=null);const n=i-this.Fi;n>=this.Si&&(t(),this.Fi=i-n%this.Si),this.Gi&&(this.Mi=requestAnimationFrame(r))};this.Mi=requestAnimationFrame(r)}stop(){this.Mi&&(cancelAnimationFrame(this.Mi),this.Mi=null)}pause(){this.Gi&&(this.Gi=!1,this.stop())}resume(t){this.Gi||(this.Gi=!0,this.start(t))}frameRate(t,r){if(t===void 0)return this.Di;this.Ti=t,this.Si=1e3/t,this.Gi&&r&&(this.stop(),this.start(r))}measureFrameRate(){const t=performance.now();if(this.Pi>0){const r=t-this.Pi;this.Ai.push(r),this.Ai.length>this.Bi&&this.Ai.shift();const i=this.Ai.reduce((n,o)=>n+o,0)/this.Ai.length;this.Di=1e3/i}this.Pi=t}get isLooping(){return this.Gi}get frameRateLimit(){return this.Ti}get currentFrameRate(){return this.Di}get frameCount(){return this.Ii}set frameCount(t){this.Ii=t}incrementFrame(){this.Ii++}resetFrameCount(){this.Ii=0}}const Pt=c=>class extends c{rotate(t=0,r=0,i=0){this.Us.state.St(t),this.Us.state.Mt(r),this.Us.state.Ft(i)}rotateX(t){this.Us.state.St(t)}rotateY(t){this.Us.state.Mt(t)}rotateZ(t){this.Us.state.Ft(t)}push(){this.Us.state.$t()}pop(){this.Us.state.bt()}rect(t,r,i=1,n=1){this.Us.Je(t,r,i,n)}line(t,r,i,n){this.Us.Ke(t,r,i,n)}lineWeight(t){this.Us.state.Tt(t)}background(t,r=t,i=t,n=255){this.Us.hs(t,r,i,n)}char(t){this.Us.state.Gt(this.Qs.Zs(t))}charColor(t,r,i){this.Us.state.Dt(t,r,i)}cellColor(t,r,i){this.Us.state.Pt(t,r,i)}flipX(t){this.Us.state.At(t)}flipY(t){this.Us.state.Bt(t)}charRotation(t){this.Us.state.Lt(t)}invert(t){this.Us.state.It(t)}clear(){this.Us.hs(0,0,0,0)}ellipse(t,r,i,n){this.Us.ts(t,r,i/2,n/2)}triangle(t,r,i,n,o,a){this.Us.es(t,r,i,n,o,a)}bezierCurve(t,r,i,n,o,a,h,l){this.Us.ss(t,r,i,n,o,a,h,l)}arc(t,r,i,n,o,a){this.Us.ns(t,r,i,n,o,a)}shader(t){this.Us.Ye(t)}setUniform(t,r){this.Us.qe(t,r)}setUniforms(t){this.Us.Ze(t)}createFilterShader(t){return this.Us.Ne(t)}};class j{Li(t){const r=t.k(0),i=t.k(1),n=t.k(2),o=t.k(3);return{characterPixels:r,primaryColorPixels:i,secondaryColorPixels:n,transformPixels:t.k(4),rotationPixels:o}}Ei(t,r){return t[r]+(t[r+1]<<8)}Wi(t,r){return{r:t[r],g:t[r+1],b:t[r+2],a:t[r+3]}}}class Y{ki(t,r){return new Blob([t],{type:r})}Ui(t,r,i){try{const n=this.ki(t,i),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=r,a.style.display="none",a.rel="noopener",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(o)}catch(n){throw console.error("Failed to download file:",n),Error("File download failed: "+(n instanceof Error?n.message:"Unknown error"))}}Vi(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Oi(){const t=new Date;return{date:t.toISOString().split("T")[0],time:t.toTimeString().split(" ")[0].replace(/:/g,"-")}}ji(t){return t.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Hi(){return"textmode-export-"+this.Vi()}}class It extends j{Xi(t,r,i){const n=t[i]===255,o=t[i+1]===255,a=t[i+2]===255,h=r[i],l=r[i+1];return{isInverted:n,flipHorizontal:o,flipVertical:a,rotation:Math.round(360*(h+l/255)/255*100)/100}}Yi(t,r,i){return{x:t,y:r,cellX:t*i.cellWidth,cellY:r*i.cellHeight}}qi(t,r){const i=[];let n=0;for(let o=0;o<r.rows;o++)for(let a=0;a<r.cols;a++){const h=4*n,l=this.Ei(t.characterPixels,h);let f=this.Wi(t.primaryColorPixels,h),g=this.Wi(t.secondaryColorPixels,h);const d=this.Xi(t.transformPixels,t.rotationPixels,h);if(d.isInverted){const x=f;f=g,g=x}const p=this.Yi(a,o,r);i.push({charIndex:l,primaryColor:f,secondaryColor:g,transform:d,position:p}),n++}return i}}class Dt{Zi(t,r){const i=t.cmap;for(const n of i.tables)if(n.format===4){const o=n;for(let a=0;a<o.startCount.length;a++)if(r>=o.startCount[a]&&r<=o.endCount[a]){if(o.idRangeOffset[a]===0)return r+o.idDelta[a]&65535;{const h=o.idRangeOffset[a]/2+(r-o.startCount[a])-(o.startCount.length-a);if(h>=0&&h<o.glyphIdArray.length){const l=o.glyphIdArray[h];if(l!==0)return l+o.idDelta[a]&65535}}}}else if(n.format===12){const o=n;for(let a=0;a<o.groups.length;a+=3){const h=o.groups[a],l=o.groups[a+1],f=o.groups[a+2];if(r>=h&&r<=l)return f+(r-h)}}return 0}Ni(t,r,i,n,o){const a=o/t.head.unitsPerEm;return{getBoundingBox:()=>({x1:i+r.xMin*a,y1:n+-r.yMax*a,x2:i+r.xMax*a,y2:n+-r.yMin*a}),toSVG:()=>this.Qi(r,i,n,a)}}Qi(t,r,i,n){if(!t||!t.xs)return"";const{xs:o,ys:a,endPts:h,flags:l}=t;if(!(o&&a&&h&&l))return"";let f="",g=0;for(let d=0;d<h.length;d++){const p=h[d];if(!(p<g)){if(p>=g){const x=r+o[g]*n,m=i-a[g]*n;f+=`M${x.toFixed(2)},${m.toFixed(2)}`;let y=g+1;for(;y<=p;)if(1&l[y]){const w=r+o[y]*n,b=i-a[y]*n;f+=`L${w.toFixed(2)},${b.toFixed(2)}`,y++}else{const w=r+o[y]*n,b=i-a[y]*n;let T=y+1>p?g:y+1;if(1&l[T]){const A=r+o[T]*n,R=i-a[T]*n;f+=`Q${w.toFixed(2)},${b.toFixed(2)} ${A.toFixed(2)},${R.toFixed(2)}`,y=T+1}else{const A=(w+(r+o[T]*n))/2,R=(b+(i-a[T]*n))/2;f+=`Q${w.toFixed(2)},${b.toFixed(2)} ${A.toFixed(2)},${R.toFixed(2)}`,y=T}}f+="Z"}g=p+1}}return f}Ji(t,r,i,n,o){const a=t.codePointAt(0)||0,h=this.Zi(r,a);let l=null;return r.glyf&&r.glyf[h]!==null?l=r.glyf[h]:(l=F.T.glyf.us(r,h),r.glyf[h]=l),this.Ni(r,l,i,n,o)}Ki(t,r,i,n,o,a,h,l){const f=i+(o-l*(h/r.head.unitsPerEm))/2,g=n+(a+.7*h)/2;return this.Ji(t,r,f,g,h).toSVG()||null}}class Mt{constructor(){u(this,"tr");this.tr=new Dt}er(t){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
10
- <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
11
- <svg width="${t.width}" height="${t.height}" viewBox="0 0 ${t.width} ${t.height}"
12
- xmlns="http://www.w3.org/2000/svg" version="1.1">
13
- <title>textmode art generated via textmode.js</title>
14
- <desc>textmode art visualization generated by textmode.js library</desc>`}sr(){return`
15
- </g>
16
- </svg>`}ir(t,r){if(!r.includeBackgroundRectangles)return"";const i=r.backgroundColor,n=`rgba(${i[0]},${i[1]},${i[2]},${i[3]/255})`;return`
17
- <rect width="${t.width}" height="${t.height}" fill="${n}" />`}rr(t){return`rgba(${t.r},${t.g},${t.b},${t.a/255})`}nr(t,r){const{transform:i,position:n}=t,o=n.cellX+r.cellWidth/2,a=n.cellY+r.cellHeight/2,h=[];if(i.flipHorizontal||i.flipVertical){const l=i.flipHorizontal?-1:1,f=i.flipVertical?-1:1;h.push(`translate(${o} ${a})`),h.push(`scale(${l} ${f})`),h.push(`translate(${-o} ${-a})`)}return i.rotation&&h.push(`rotate(${i.rotation} ${o} ${a})`),h.length?` transform="${h.join(" ")}"`:""}ar(t,r,i){if(!i.includeBackgroundRectangles||t.secondaryColor.a===0)return"";const{position:n}=t,o=this.rr(t.secondaryColor);return i.drawMode==="stroke"?`
18
- <rect x="${n.cellX}" y="${n.cellY}" width="${r.cellWidth}" height="${r.cellHeight}" stroke="${o}" fill="none" stroke-width="${i.strokeWidth}" />`:`
19
- <rect x="${n.cellX}" y="${n.cellY}" width="${r.cellWidth}" height="${r.cellHeight}" fill="${o}" />`}Ji(t,r,i,n){const o=i.characters[t.charIndex];if(!o)return"";const a=this.tr.Ki(o.character,i.font,t.position.cellX,t.position.cellY,r.cellWidth,r.cellHeight,i.fontSize,o.advanceWidth);if(!a)return"";const h=this.rr(t.primaryColor);return n.drawMode==="stroke"?`
20
- <path id="${`path-${t.charIndex}-${t.position.cellX}-${t.position.cellY}`.replace(/\./g,"-")}" d="${a}" stroke="${h}" stroke-width="${n.strokeWidth}" fill="none" />`:`
21
- <path d="${a}" fill="${h}" />`}hr(t,r,i,n){let o="";o+=this.ar(t,r,n);const a=this.nr(t,r),h=this.Ji(t,r,i,n);return h&&(a?(o+=`
22
- <g${a}>`,o+=h,o+=`
23
- </g>`):o+=h),o}cr(t,r,i,n){let o=this.er(r);o+=this.ir(r,n),o+=`
24
- <g id="ascii-cells">`;for(const a of t)o+=this.hr(a,r,i,n);return o+=this.sr(),o}lr(t){return t.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\n\s*\n/g,`
25
- `).replace(/[ \t]+$/gm,"")}}class zt extends Y{ur(t){return this.ki(t,"image/svg+xml;charset=utf-8")}dr(t,r){this.Ui(t,this.ji(r)+".svg","image/svg+xml;charset=utf-8")}pr(t,r){this.dr(t,r||this.Hi())}}class tt{constructor(){u(this,"_r");u(this,"gr");u(this,"mr");this._r=new It,this.gr=new Mt,this.mr=new zt}vr(t){return{includeBackgroundRectangles:t.includeBackgroundRectangles??!0,drawMode:t.drawMode??"fill",strokeWidth:t.strokeWidth??1,backgroundColor:t.backgroundColor??[0,0,0,0],filename:t.filename||this.mr.Hi()}}Cr(t,r={}){const i=this._r.qi(this._r.Li(t.pipeline),t.grid),n=this.gr.cr(i,t.grid,t.font,this.vr(r));return this.gr.lr(n)}pr(t,r={}){this.mr.pr(this.Cr(t,r),r.filename)}}class Bt extends j{yr(t,r,i,n=" "){var h;const o=[];let a=0;for(let l=0;l<r.rows;l++){const f=[];for(let g=0;g<r.cols;g++){const d=4*a,p=this.Ei(t.characterPixels,d),x=((h=i.characters[p])==null?void 0:h.character)||n;f.push(x),a++}o.push(f)}return o}}class Gt{wr(t,r){const i=[];for(const o of t){let a=o.join("");r.preserveTrailingSpaces||(a=a.replace(/\s+$/,"")),i.push(a)}const n=r.lineEnding==="crlf"?`\r
6
+ ${"↓".repeat(24)}
7
+ `}static _(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="number"||typeof t=="boolean")return t+"";if(Array.isArray(t))return t.length===0?"[]":t.length<=5?`[${t.map(i=>v._(i)).join(", ")}]`:`[${t.slice(0,3).map(i=>v._(i)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const i=Object.keys(t);return i.length===0?"{}":i.length<=3?`{ ${i.map(r=>`${r}: ${v._(t[r])}`).join(", ")} }`:`{ ${i.slice(0,2).map(r=>`${r}: ${v._(t[r])}`).join(", ")}, ... +${i.length-2} more }`}return t+""}}var L=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(L||{});const M=class M{constructor(){l(this,"C",{globalLevel:3})}static $(){return M.v||(M.v=new M),M.v}R(t,i){const r="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",n="color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";switch(this.C.globalLevel){case 0:return!1;case 1:return console.group(r,n),console.warn(v.u(t,i)),console.groupEnd(),!1;case 2:return console.group(r,n),console.error(v.u(t,i)),console.groupEnd(),!1;default:throw new v(t,i)}}M(t,i,r){return!!t||(this.R(i,r),!1)}S(t){this.C.globalLevel=t}};l(M,"v",null);let k=M;const B=k.$(),Y=new WeakMap;function z(c,t){Y.set(c,t)}function O(c){return Y.get(c)}class V{constructor(){l(this,"F",1);l(this,"P",0);l(this,"G",0);l(this,"A",0);l(this,"L",[0,0,0]);l(this,"D",[1,1,1,1]);l(this,"W",[0,0,0,1]);l(this,"I",!1);l(this,"U",!1);l(this,"O",!1);l(this,"H",[0,0]);l(this,"V",[0,0,0,1]);l(this,"K",[])}N(){this.K.push({X:this.F,Y:this.P,Z:this.G,J:this.A,H:[...this.H],I:this.I,U:this.U,O:this.O,tt:[...this.L],et:[...this.D],st:[...this.W]})}it(){const t=this.K.pop();t?(this.F=t.X,this.P=t.Y,this.G=t.Z,this.A=t.J,this.H=t.H,this.I=t.I,this.U=t.U,this.O=t.O,this.L=t.tt,this.D=t.et,this.W=t.st):console.warn("pop() called without matching push()")}rt(){this.K=[],this.P=0,this.G=0,this.A=0}nt(t){t.lineWeight=this.F,t.rotationX=this.P,t.rotationY=this.G,t.rotationZ=this.A,t.character[0]=this.L[0],t.character[1]=this.L[1],t.character[2]=this.L[2],t.charColor[0]=this.D[0],t.charColor[1]=this.D[1],t.charColor[2]=this.D[2],t.charColor[3]=this.D[3],t.bgColor[0]=this.W[0],t.bgColor[1]=this.W[1],t.bgColor[2]=this.W[2],t.bgColor[3]=this.W[3],t.flipHorizontally=this.I,t.flipVertically=this.U,t.invert=this.O,t.charRotation[0]=this.H[0],t.charRotation[1]=this.H[1]}get lineWeight(){return this.F}get canvasBackgroundColor(){return this.V}ot(t){this.F=Math.abs(t)}ht(t){this.P=t}ct(t){this.G=t}lt(t){this.A=t}ut(t){this.L=t}ft(t,i,r,n=255){this.D=[t/255,i/255,r/255,n/255]}dt(t,i,r,n=255){this.W=[t/255,i/255,r/255,n/255]}_t(t){this.I=t}gt(t){this.U=t}vt(t){this.O=t}yt(t){const i=255*t/360,r=Math.floor(i)/255,n=Math.round(i-Math.floor(i));this.H=[r,n]}Ct(t,i,r,n){this.V=[t/255,i/255,r/255,n/255]}}class G{constructor(t,i,r=i,n=1,o={},a=null,h=!1){l(this,"$t");l(this,"wt");l(this,"C");l(this,"bt",null);l(this,"xt");l(this,"Rt");l(this,"Mt",[]);l(this,"St");l(this,"Ft",null);l(this,"zt",[]);l(this,"Pt",null);l(this,"kt",!1);l(this,"Gt",null);this.$t=i,this.wt=r,this.C={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.xt=t,this.St=Math.min(Math.max(1,n),8),this.Pt=a,this.kt=!!h,this.Gt=this.kt?new V:null;const u=t.getParameter(t.MAX_DRAW_BUFFERS),f=t.getParameter(t.MAX_COLOR_ATTACHMENTS);this.St=Math.min(this.St,u,f),this.Rt=t.createFramebuffer(),this.Tt(),this.At(),this.zt=Array(this.St).fill(null)}Tt(){const t=this.xt,i=this.C.filter==="linear"?t.LINEAR:t.NEAREST,r=this.C.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE,n=this.C.type==="float"?t.FLOAT:t.UNSIGNED_BYTE;for(let o=0;o<this.St;o++){const a=t.createTexture();t.bindTexture(t.TEXTURE_2D,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,r),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,this.$t,this.wt,0,t.RGBA,n,null),this.Mt.push(a)}t.bindTexture(t.TEXTURE_2D,null)}At(){const t=this.xt;if(t.bindFramebuffer(t.FRAMEBUFFER,this.Rt),this.St===1)t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.Mt[0],0);else{const r=[];for(let n=0;n<this.St;n++){const o=t.COLOR_ATTACHMENT0+n;t.framebufferTexture2D(t.FRAMEBUFFER,o,t.TEXTURE_2D,this.Mt[n],0),r.push(o)}t.drawBuffers(r)}const i=t.checkFramebufferStatus(t.FRAMEBUFFER);i!==t.FRAMEBUFFER_COMPLETE&&console.error("GLFramebuffer is not complete:",i),t.bindFramebuffer(t.FRAMEBUFFER,null)}Et(t){const i=this.xt;i.bindTexture(i.TEXTURE_2D,this.Mt[0]),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,1),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),i.bindTexture(i.TEXTURE_2D,null)}resize(t,i){this.$t=t,this.wt=i,this.bt=null,this.zt=Array(this.St).fill(null);const r=this.xt,n=this.C.type==="float"?r.FLOAT:r.UNSIGNED_BYTE;for(const o of this.Mt)r.bindTexture(r.TEXTURE_2D,o),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.$t,this.wt,0,r.RGBA,n,null);r.bindTexture(r.TEXTURE_2D,null)}Lt(t){const i=this.xt,r=this.zt[t];if(r)return r;const n=this.$t,o=this.wt,a=new Uint8Array(n*o*4),h=i.getParameter(i.READ_FRAMEBUFFER_BINDING);i.bindFramebuffer(i.READ_FRAMEBUFFER,this.Rt),i.readBuffer(i.COLOR_ATTACHMENT0+t),i.readPixels(0,0,n,o,i.RGBA,i.UNSIGNED_BYTE,a),i.bindFramebuffer(i.READ_FRAMEBUFFER,h);const u=4*n,f=new Uint8Array(a.length);for(let p=0;p<o;p++){const d=(o-1-p)*u,g=p*u;f.set(a.subarray(d,d+u),g)}return this.zt[t]=f,f}begin(){var i,r,n,o;const t=this.xt;if(this.Pt){const a=((r=(i=this.Pt).Bt)==null?void 0:r.call(i))??null;a&&this.Pt.Dt(a),this.kt&&this.Gt&&((o=(n=this.Pt).Wt)==null||o.call(n,this.Gt))}this.Ft={framebuffer:t.getParameter(t.FRAMEBUFFER_BINDING),viewport:t.getParameter(t.VIEWPORT)},t.bindFramebuffer(t.FRAMEBUFFER,this.Rt),this.zt=Array(this.St).fill(null);for(let a=0;a<this.St;a++)t.clearBufferfv(t.COLOR,a,new Float32Array([0,0,0,0]));t.viewport(0,0,this.$t,this.wt),z(t,[0,0,this.$t,this.wt])}end(){var i,r,n,o;if(!this.Ft)return;const t=this.xt;if(this.Pt){const a=((r=(i=this.Pt).Bt)==null?void 0:r.call(i))??null;a&&this.Pt.Dt(a)}t.bindFramebuffer(t.FRAMEBUFFER,this.Ft.framebuffer),t.viewport(...this.Ft.viewport),z(t,this.Ft.viewport),this.Ft=null,this.Pt&&this.kt&&this.Gt&&((o=(n=this.Pt).It)==null||o.call(n))}Ut(){const t=this.xt;t.deleteFramebuffer(this.Rt);for(const i of this.Mt)t.deleteTexture(i)}get width(){return this.$t}get height(){return this.wt}get pixels(){return this.bt}get options(){return{...this.C}}get framebuffer(){return this.Rt}get texture(){return this.Mt[0]}get textures(){return[...this.Mt]}get attachmentCount(){return this.St}}function K(c){return typeof c=="string"?c:c.sourceCode}class D{constructor(t,i,r){l(this,"xt");l(this,"Ot");l(this,"Ht",new Map);l(this,"Vt",0);this.xt=t,this.Ot=this.Kt(K(i),K(r)),this.jt()}jt(){const t=this.xt.getProgramParameter(this.Ot,this.xt.ACTIVE_UNIFORMS);for(let i=0;i<t;i++){const r=this.xt.getActiveUniform(this.Ot,i);if(r){const n=this.xt.getUniformLocation(this.Ot,r.name);n&&this.Ht.set(r.name,n)}}}Kt(t,i){const r=this.Nt(this.xt.VERTEX_SHADER,t),n=this.Nt(this.xt.FRAGMENT_SHADER,i),o=this.xt.createProgram();if(this.xt.attachShader(o,r),this.xt.attachShader(o,n),this.xt.linkProgram(o),!this.xt.getProgramParameter(o,this.xt.LINK_STATUS)){const a=this.xt.getProgramInfoLog(o);throw Error("Shader program link error: "+a)}return this.xt.deleteShader(r),this.xt.deleteShader(n),o}Nt(t,i){const r=this.xt.createShader(t);if(this.xt.shaderSource(r,i),this.xt.compileShader(r),!this.xt.getShaderParameter(r,this.xt.COMPILE_STATUS)){const n=this.xt.getShaderInfoLog(r);throw this.xt.deleteShader(r),Error("Shader compilation error: "+n)}return r}Xt(){this.xt.useProgram(this.Ot),this.Yt()}Yt(){this.Vt=0}qt(t){for(const[i,r]of Object.entries(t))this.Zt(i,r)}Qt(t){return this.Ht.has(t)}Zt(t,i){const r=this.Ht.get(t);if(r)if(typeof i=="number")this.xt.uniform1f(r,i);else if(typeof i=="boolean")this.xt.uniform1i(r,i?1:0);else if(Array.isArray(i))switch(i.length){case 2:this.xt.uniform2f(r,i[0],i[1]);break;case 3:this.xt.uniform3f(r,i[0],i[1],i[2]);break;case 4:this.xt.uniform4f(r,i[0],i[1],i[2],i[3]);break;default:return}else if(i instanceof WebGLTexture){const n=this.Jt();this.xt.uniform1i(r,n),this.xt.activeTexture(this.xt.TEXTURE0+n),this.xt.bindTexture(this.xt.TEXTURE_2D,i)}else if(i instanceof G){const n=this.Jt();this.xt.uniform1i(r,n),this.xt.activeTexture(this.xt.TEXTURE0+n),this.xt.bindTexture(this.xt.TEXTURE_2D,i.texture)}else if(typeof i=="object"&&"texture"in i){const n=this.Jt();this.xt.uniform1i(r,n),this.xt.activeTexture(this.xt.TEXTURE0+n),this.xt.bindTexture(this.xt.TEXTURE_2D,i.texture)}else console.warn(`Unsupported uniform type for '${t}':`,typeof i)}Jt(){return this.Vt++}get te(){return this.Ot}Ut(){this.xt.deleteProgram(this.Ot)}}const j=`#version 300 es
8
+ in vec2 a_position;in vec2 a_texCoord;in vec2 a_instancePosition;in vec2 a_instanceSize;in vec3 a_instanceCharacter;in vec4 a_instancePrimaryColor;in vec4 a_instanceSecondaryColor;in vec2 a_instanceRotation;in vec3 a_instanceTransform;in vec3 a_instanceGlobalRotation;in vec2 a_instanceRotationCenter;in vec2 a_instanceBezierCP1;in vec2 a_instanceBezierCP2;in vec2 a_instanceBezierStart;in vec2 a_instanceBezierEnd;in vec2 a_instanceArcAngles;uniform float k;uniform vec2 r;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/r)*2.-1.;a.y=-a.y;if(length(a_instanceGlobalRotation)>0.){vec3 b=vec3(a-a_instanceRotationCenter,0);b.x*=k;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/=k;a=b.xy+a_instanceRotationCenter;}gl_Position=vec4(a,0,1);}`;class nt{constructor(t){l(this,"ee",new Map);l(this,"xt");this.xt=t}se(t,i){if(!this.ee.has(t)){const r=i();this.ee.set(t,r)}return this.ee.get(t)}ie(){return this.se("mrt-copy",()=>new D(this.xt,j,`#version 300 es
9
+ precision highp float;in vec2 v_uv;uniform sampler2D l;uniform sampler2D m;uniform sampler2D n;uniform sampler2D o;uniform sampler2D p;uniform vec2 q;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){vec2 A=vec2(v_uv.x,1.-v_uv.y);vec2 B=A*q;vec2 C=(floor(B)+0.5f)/q;vec4 D=texture(l,C);vec4 E=texture(m,C);if(E.a==0.){discard;}vec4 F=texture(n,C);vec4 G=texture(o,C);vec4 H=texture(p,C);o_character=D;o_primaryColor=E;o_secondaryColor=F;o_rotation=G;o_transform=H;}`))}Bt(){return this.se("mrt-draw",()=>new D(this.xt,j,`#version 300 es
10
+ precision highp float;in vec2 v_uv;in vec3 v_character;in vec4 v_primaryColor;in vec4 v_secondaryColor;in vec2 v_rotation;in vec3 v_transform;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){o_character=vec4(v_character,1.);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.,1.);o_transform=vec4(v_transform,1.);}`))}re(){return this.se("ascii-conversion",()=>new D(this.xt,"attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.,1.);}","precision mediump float;uniform sampler2D a;uniform vec2 b;uniform sampler2D d;uniform sampler2D e;uniform sampler2D f;uniform sampler2D c;uniform sampler2D g;uniform vec2 h;uniform vec2 i;uniform vec2 j;mat2 A(float B){float C=sin(B);float c=cos(B);return mat2(c,-C,C,c);}void main(){vec2 D=(gl_FragCoord.xy-j)/i;vec2 E=D*h;vec2 F=floor(E);vec2 G=(F+0.5)/h;vec4 H=texture2D(d,G);vec4 I=texture2D(e,G);vec4 J=texture2D(f,G);bool K=J.r>0.5;bool L=J.g>0.5;bool M=J.b>0.5;vec4 N=texture2D(c,G);int O=int(N.r*255.+0.5)+int(N.g*255.+0.5)*256;int P=int(mod(float(O),b.x));int Q=O/int(b.x);float R=(b.y-1.)-float(Q);vec2 S=vec2(float(P),R)/b;vec4 T=texture2D(g,G);float U=T.r*255.+T.g;float V=-(U*360./255.)*0.017453292;vec2 W=fract(E)-0.5;if(L)W.x=-W.x;if(M)W.y=-W.y;W=A(V)*W+0.5;vec2 X=1./b;vec2 Y=S+W*X;vec2 Z=S+X;if(any(lessThan(Y,S))||any(greaterThan(Y,Z))){gl_FragColor=K?H:I;return;}vec4 a=texture2D(a,Y);if(K)a.rgb=1.-a.rgb;gl_FragColor=mix(I,H,a);}"))}ne(t){return new D(this.xt,j,t)}oe(t,i){return new D(this.xt,t,i)}Ut(){for(const t of this.ee.values())t.Ut();this.ee.clear()}}var y=(c=>(c.RECTANGLE="rectangle",c.LINE="line",c.ELLIPSE="ellipse",c.ARC="arc",c.TRIANGLE="triangle",c.BEZIER_CURVE="bezier_curve",c.CUSTOM="custom",c))(y||{});class ot{constructor(t){l(this,"xt");l(this,"ae",new Map);this.xt=t}he(t,i,r,n){const o=this.xt;let a=this.ae.get(t);a||(a=new Map,this.ae.set(t,a));let h=a.get(i)||null;if(!h){h=o.createVertexArray(),a.set(i,h),o.bindVertexArray(h),o.bindBuffer(o.ARRAY_BUFFER,n);const u=o.getAttribLocation(t,"a_position");u!==-1&&(o.enableVertexAttribArray(u),o.vertexAttribPointer(u,r.le.ce.size,o.FLOAT,!1,r.ue,r.le.ce.offset),o.vertexAttribDivisor(u,0));const f=o.getAttribLocation(t,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,r.le.fe.size,o.FLOAT,!1,r.ue,r.le.fe.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(h)}de(){this.xt.bindVertexArray(null)}Ut(){const t=this.xt;for(const[,i]of this.ae)for(const[,r]of i)r&&t.deleteVertexArray(r);this.ae.clear()}}class at{constructor(t,i){l(this,"_e");l(this,"xt");l(this,"Pt");l(this,"pe",null);l(this,"ge",null);this.xt=t,this._e=new ot(t),this.Pt=i}me(t,i,r){const{shader:n}=t,o=O(this.xt)||this.xt.getParameter(this.xt.VIEWPORT);n.qt({k:o[2]/o[3],r:[o[2],o[3]]});const a=f=>{if(!f||!f.ve())return;const p=f.unitGeometry,d=f.unitBuffer;try{this._e.he(n.te,f.type+"",p,d),f.batch.ye(n),f.batch.Ce(p.$e,p.we)}finally{f.batch.be(n),this._e.de(),f.xe()}};let h=null,u=null;for(const f of i){if(f.type===y.CUSTOM){u&&(a(u),h=null,u=null),this.Re(t,f.params,f.state,r.get(y.RECTANGLE));continue}h!==null&&f.type!==h&&(a(u),h=null,u=null);let p=u;p&&f.type===h||(p=r.get(f.type)||null,u=p,h=f.type),p&&p.Me(f.params,f.state)}a(u)}Re(t,i,r,n){const{x:o,y:a,width:h,height:u,shader:f,uniforms:p}=i;if(f===this.Se())return this.Fe(n,f,p,Math.floor(o),Math.floor(a),Math.max(1,Math.floor(h)),Math.max(1,Math.floor(u)),r),void t.shader.Xt();const d=this.ze(Math.max(1,Math.floor(h)),Math.max(1,Math.floor(u)));d.begin(),this.Fe(n,f,p,0,0,d.width,d.height,{}),d.end();const g=this.Se(),m={l:d.textures[0],m:d.textures[1],n:d.textures[2],o:d.textures[3],p:d.textures[4],q:[d.width,d.height]};this.Fe(n,g,m,Math.floor(o),Math.floor(a),Math.max(1,Math.floor(h)),Math.max(1,Math.floor(u)),r),t.shader.Xt()}Fe(t,i,r,n,o,a,h,u){i.Xt(),i.qt(r);const f=this.xt.getParameter(this.xt.VIEWPORT);if(i.qt({k:f[2]/f[3],r:[f[2],f[3]]}),t.xe(),t.Me({x:n,y:o,width:a,height:h},u),t.ve()){const p=t.unitGeometry,d=t.unitBuffer;try{this._e.he(i.te,t.type+"",p,d),t.batch.ye(i),t.batch.Ce(p.$e,p.we)}finally{t.batch.be(i),this._e.de(),t.xe()}}}Se(){return this.Pt.ie()}ze(t,i){return this.pe&&this.ge&&this.ge.w===t&&this.ge.h===i||(this.pe&&this.pe.Ut(),this.pe=new G(this.xt,t,i,5),this.ge={w:t,h:i}),this.pe}}class ht{constructor(){l(this,"Pe",[]);l(this,"ke",1);l(this,"Ge",0)}Te(t){if(this.Ge>=this.Pe.length){const r={id:this.ke++,type:t,params:{},state:{X:1,Y:0,Z:0,J:0,character:[0,0,0],charColor:[1,1,1,1],bgColor:[0,0,0,1],flipHorizontally:!1,flipVertically:!1,invert:!1,charRotation:[0,0]}};this.Pe.push(r)}const i=this.Pe[this.Ge];switch(i.id=this.ke++,i.type=t,t){case y.RECTANGLE:case y.ELLIPSE:i.params&&"width"in i.params||(i.params={x:0,y:0,width:0,height:0});break;case y.CUSTOM:i.params&&"shader"in i.params||(i.params={x:0,y:0,width:0,height:0,shader:void 0,uniforms:{}});break;case y.ARC:i.params&&"start"in i.params||(i.params={x:0,y:0,width:0,height:0,start:0,stop:0});break;case y.LINE:i.params&&"x2"in i.params||(i.params={x1:0,y1:0,x2:0,y2:0,thickness:void 0});break;case y.TRIANGLE:i.params&&"x3"in i.params||(i.params={x1:0,y1:0,x2:0,y2:0,x3:0,y3:0});break;case y.BEZIER_CURVE:i.params&&"cp2y"in i.params||(i.params={x1:0,y1:0,cp1x:0,cp1y:0,cp2x:0,cp2y:0,x2:0,y2:0,thickness:void 0});break;default:i.params||(i.params={})}return this.Ge++,i}Ae(t,i,r,n,o){const a=this.Te(y.RECTANGLE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.nt(a.state),a.id}Ee(t,i,r,n,o,a,h){const u=this.Te(y.CUSTOM);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.shader=o,u.params.uniforms=a,h.nt(u.state),u.id}Le(t,i,r,n,o,a){const h=this.Te(y.LINE);return h.params.x1=t,h.params.y1=i,h.params.x2=r,h.params.y2=n,h.params.thickness=o,a.nt(h.state),h.id}Be(t,i,r,n,o){const a=this.Te(y.ELLIPSE);return a.params.x=t,a.params.y=i,a.params.width=r,a.params.height=n,o.nt(a.state),a.id}De(t,i,r,n,o,a,h){const u=this.Te(y.ARC);return u.params.x=t,u.params.y=i,u.params.width=r,u.params.height=n,u.params.start=o,u.params.stop=a,h.nt(u.state),u.id}We(t,i,r,n,o,a,h){const u=this.Te(y.TRIANGLE);return u.params.x1=t,u.params.y1=i,u.params.x2=r,u.params.y2=n,u.params.x3=o,u.params.y3=a,h.nt(u.state),u.id}Ie(t,i,r,n,o,a,h,u,f,p){const d=this.Te(y.BEZIER_CURVE);return d.params.x1=t,d.params.y1=i,d.params.cp1x=r,d.params.cp1y=n,d.params.cp2x=o,d.params.cp2y=a,d.params.x2=h,d.params.y2=u,d.params.thickness=f,p.nt(d.state),d.id}get length(){return this.Ge}get isEmpty(){return this.Ge===0}Ue(){this.Ge=0}[Symbol.iterator](){let t=0;const i=this.Ge,r=this.Pe;return{next:()=>t<i?{value:r[t++],done:!1}:{value:void 0,done:!0}}}}const F=class F{static Oe(t,i,r=0){var a,h,u,f,p,d,g,m,x,R;const n=i||new Float32Array(F.FLOATS_PER_INSTANCE);let o=r;return n[o++]=t.position[0],n[o++]=t.position[1],n[o++]=t.size[0],n[o++]=t.size[1],n[o++]=t.tt[0],n[o++]=t.tt[1],n[o++]=t.tt[2],n[o++]=t.primaryColor[0],n[o++]=t.primaryColor[1],n[o++]=t.primaryColor[2],n[o++]=t.primaryColor[3],n[o++]=t.secondaryColor[0],n[o++]=t.secondaryColor[1],n[o++]=t.secondaryColor[2],n[o++]=t.secondaryColor[3],n[o++]=t.rotation[0],n[o++]=t.rotation[1],n[o++]=t.transform[0],n[o++]=t.transform[1],n[o++]=t.transform[2],n[o++]=t.globalRotationX,n[o++]=t.globalRotationY,n[o++]=t.globalRotationZ,n[o++]=t.rotationCenter[0],n[o++]=t.rotationCenter[1],n[o++]=((a=t.arcAngles)==null?void 0:a[0])||0,n[o++]=((h=t.arcAngles)==null?void 0:h[1])||0,n[o++]=((u=t.bezierControlPoint1)==null?void 0:u[0])||0,n[o++]=((f=t.bezierControlPoint1)==null?void 0:f[1])||0,n[o++]=((p=t.bezierControlPoint2)==null?void 0:p[0])||0,n[o++]=((d=t.bezierControlPoint2)==null?void 0:d[1])||0,n[o++]=((g=t.bezierStartPoint)==null?void 0:g[0])||0,n[o++]=((m=t.bezierStartPoint)==null?void 0:m[1])||0,n[o++]=((x=t.bezierEndPoint)==null?void 0:x[0])||0,n[o++]=((R=t.bezierEndPoint)==null?void 0:R[1])||0,n}static He(t){const i=t.length*F.FLOATS_PER_INSTANCE,r=new Float32Array(i);for(let n=0;n<t.length;n++){const o=n*F.FLOATS_PER_INSTANCE;F.Oe(t[n],r,o)}return r}};l(F,"BYTES_PER_INSTANCE",140),l(F,"FLOATS_PER_INSTANCE",35);let S=F;const E=class E{};l(E,"STRIDE",S.BYTES_PER_INSTANCE),l(E,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:E.STRIDE,offset:132,divisor:1}});let W=E;class ct{constructor(t,i=1e3,r=1.5){l(this,"xt");l(this,"Ve",[]);l(this,"Ke");l(this,"je");l(this,"Ne",null);l(this,"Xe",!0);l(this,"Ye",0);l(this,"qe",new Map);l(this,"Ze",null);this.xt=t,this.Ke=i,this.je=r,this.Qe()}Me(t){const i=this.Ve.length;return this.Ve.push(t),this.Xe=!0,i}get count(){return this.Ve.length}get isEmpty(){return this.Ve.length===0}clear(){this.Ve.length=0,this.Xe=!0}Je(t){if(t<=this.Ke)return;const i=Math.ceil(t*this.je);this.Ke=i,this.Qe()}Qe(){const t=this.xt;this.Ne&&t.deleteBuffer(this.Ne),this.Ne=t.createBuffer();const i=this.Ke*S.BYTES_PER_INSTANCE;t.bindBuffer(t.ARRAY_BUFFER,this.Ne),t.bufferData(t.ARRAY_BUFFER,i,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Xe=!0,this.Ye=0}ts(){if(!this.Xe||this.Ve.length===0)return;const t=this.xt,i=this.Ve.length;this.Je(i),(!this.Ze||this.Ze.length<i*S.FLOATS_PER_INSTANCE)&&(this.Ze=new Float32Array(i*S.FLOATS_PER_INSTANCE));const r=S.He(this.Ve);t.bindBuffer(t.ARRAY_BUFFER,this.Ne),i<=this.Ye?t.bufferSubData(t.ARRAY_BUFFER,0,r):t.bufferData(t.ARRAY_BUFFER,r,t.DYNAMIC_DRAW),t.bindBuffer(t.ARRAY_BUFFER,null),this.Xe=!1,this.Ye=i}es(t){let i=this.qe.get(t);if(!i){i=new Map;const r=this.xt;for(const n in W.ATTRIBUTES){const o=r.getAttribLocation(t,n);o!==-1&&i.set(n,o)}this.qe.set(t,i)}return i}ye(t){if(!this.Ne||this.Ve.length===0)return;const i=this.xt,r=t.te;this.ts();const n=this.es(r);i.bindBuffer(i.ARRAY_BUFFER,this.Ne);for(const[o,a]of n){const h=W.ATTRIBUTES[o];h&&(i.enableVertexAttribArray(a),i.vertexAttribPointer(a,h.size,h.type,h.normalized,h.stride,h.offset),i.vertexAttribDivisor(a,h.divisor))}}be(t){const i=this.xt,r=this.es(t.te);for(const[,n]of r)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}Ce(t,i){this.Ve.length!==0&&this.xt.drawArraysInstanced(t,0,i,this.Ve.length)}Ut(){const t=this.xt;this.Ne&&(t.deleteBuffer(this.Ne),this.Ne=null),this.Ve.length=0,this.qe.clear(),this.Ze=null}}class U{constructor(t,i,r,n){l(this,"xt");l(this,"ss");l(this,"rs");l(this,"ns");l(this,"hs",null);this.xt=t,this.ss=i,this.rs=r,this.ns=n;const o=this.xt.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.xt.bindBuffer(this.xt.ARRAY_BUFFER,o),this.xt.bufferData(this.xt.ARRAY_BUFFER,this.ns.cs,this.xt.STATIC_DRAW),this.xt.bindBuffer(this.xt.ARRAY_BUFFER,null),this.hs=o}get type(){return this.rs}get unitGeometry(){return this.ns}get unitBuffer(){return this.hs}get batch(){return this.ss}xe(){this.ss.clear()}ve(){return!this.ss.isEmpty}Ut(){this.ss.Ut(),this.hs&&(this.xt.deleteBuffer(this.hs),this.hs=null)}ls(t,i,r,n,o){const a=this.us(t,i,r,n,o.rotationX||0,o.rotationY||0,o.rotationZ||0);return{position:[t,i],size:[r,n],tt:o.character||[0,0,0],primaryColor:o.charColor||[1,1,1,1],secondaryColor:o.bgColor||[0,0,0,1],rotation:o.charRotation||[0,0],transform:[o.invert?1:0,o.flipHorizontally?1:0,o.flipVertically?1:0],globalRotationX:a.radiansX,globalRotationY:a.radiansY,globalRotationZ:a.radiansZ,rotationCenter:[a.centerX,a.centerY]}}fs(t,i){const r=O(this.xt)||[0,0,this.xt.canvas.width,this.xt.canvas.height];return{nx:t/r[2]*2-1,ny:1-i/r[3]*2}}ds(t,i,r){const n=this.fs(i,r);t.rotationCenter=[n.nx,n.ny]}us(t,i,r,n,o,a,h){const u=O(this.xt)||[0,0,this.xt.canvas.width,this.xt.canvas.height],f=u[2],p=u[3];return{centerX:(t+r/2)/f*2-1,centerY:1-(i+n/2)/p*2,radiansX:-o*Math.PI/180,radiansY:-a*Math.PI/180,radiansZ:-h*Math.PI/180,aspectRatio:f/p}}}const lt={cs:new Float32Array([0,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,1,1,1]),we:6,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class ut extends U{constructor(t,i){super(t,i,y.RECTANGLE,lt)}Me(t,i){const r=this.ls(t.x,t.y,t.width,t.height,i);return this.ss.Me(r)}}const ft={cs:new Float32Array([0,-.5,0,0,1,-.5,1,0,0,.5,0,1,0,.5,0,1,1,-.5,1,0,1,.5,1,1]),we:6,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class dt extends U{constructor(t,i){super(t,i,y.LINE,ft)}Me(t,i){const r=t.x2-t.x1,n=t.y2-t.y1,o=Math.hypot(r,n),a=Math.atan2(n,r),h=t.thickness||i.lineWeight||1,u=t.x1+r/2,f=t.y1+n/2,p=u-o/2,d=f,g={character:i.character,charColor:i.charColor,bgColor:i.bgColor,charRotation:i.charRotation,flipHorizontally:i.flipHorizontally,flipVertically:i.flipVertically,invert:i.invert,rotationX:i.rotationX||0,rotationY:i.rotationY||0,rotationZ:(i.rotationZ||0)+180*a/Math.PI,lineWeight:h},m=this.ls(p,d,o,h,g);return this.ds(m,u,f),this.ss.Me(m)}}const pt={cs:function(c=32){const t=[],i=2*Math.PI/c;for(let r=0;r<c;r++){const n=r*i,o=(r+1)%c*i,a=Math.cos(n),h=Math.sin(n),u=.5*(a+1),f=.5*(h+1),p=Math.cos(o),d=Math.sin(o),g=.5*(p+1),m=.5*(d+1);t.push(0,0,.5,.5,a,h,u,f,p,d,g,m)}return new Float32Array(t)}(32),we:96,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class gt extends U{constructor(t,i){super(t,i,y.ELLIPSE,pt)}Me(t,i){const r=this.ls(t.x,t.y,t.width,t.height,i);return this.ds(r,t.x,t.y),this.ss.Me(r)}}let mt={cs:function(c){const t=[];for(let i=0;i<c;i++){const r=i/c,n=(i+1)/c;t.push(r,0,r,0,r,1,r,1,n,1,n,1)}return new Float32Array(t)}(32),we:96,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class xt extends U{constructor(t,i){super(t,i,y.ARC,mt)}Me(t,i){const r=t.x-t.width/2,n=t.y-t.height/2,o=t.start*Math.PI/180,a=t.stop*Math.PI/180,h=this.ls(r,n,t.width,t.height,i);return this.ds(h,t.x,t.y),h.arcAngles=[o,a],this.ss.Me(h)}}const yt={cs:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),we:3,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class Rt extends U{constructor(t,i){super(t,i,y.TRIANGLE,yt)}Me(t,i){const r=Math.min(t.x1,t.x2,t.x3),n=Math.max(t.x1,t.x2,t.x3),o=Math.min(t.y1,t.y2,t.y3),a=n-r,h=Math.max(t.y1,t.y2,t.y3)-o,u=this.ls(r,o,a,h,i),f=r+.5*a,p=o+h*(1/3);return this.ds(u,f,p),this.ss.Me(u)}}function Z(c,t,i,r,n){const o=1-c,a=o*o,h=c*c;return a*o*t+3*a*c*i+3*o*h*r+h*c*n}const vt={cs:function(c=16){const t=[];for(let i=0;i<c;i++){const r=i/c,n=(i+1)/c;t.push(r,-.5,r,0),t.push(n,-.5,n,0),t.push(r,.5,r,1),t.push(r,.5,r,1),t.push(n,-.5,n,0),t.push(n,.5,n,1)}return new Float32Array(t)}(16),we:96,$e:WebGL2RenderingContext.TRIANGLES,ue:16,le:{ce:{size:2,offset:0},fe:{size:2,offset:8}}};class bt extends U{constructor(t,i){super(t,i,y.BEZIER_CURVE,vt)}Me(t,i){const r=i.lineWeight||1,n=Z(.5,t.x1,t.cp1x,t.cp2x,t.x2),o=Z(.5,t.y1,t.cp1y,t.cp2y,t.y2),a={character:i.character,charColor:i.charColor,bgColor:i.bgColor,charRotation:i.charRotation,flipHorizontally:i.flipHorizontally,flipVertically:i.flipVertically,invert:i.invert,rotationX:i.rotationX||0,rotationY:i.rotationY||0,rotationZ:i.rotationZ||0,lineWeight:r},h=this.ls(0,0,1,r,a);return this.ds(h,n,o),h.bezierStartPoint=[t.x1,t.y1],h.bezierControlPoint1=[t.cp1x,t.cp1y],h.bezierControlPoint2=[t.cp2x,t.cp2y],h.bezierEndPoint=[t.x2,t.y2],this.ss.Me(h)}}class Et{constructor(t){l(this,"xt");l(this,"_s",null);l(this,"ps");l(this,"gs",null);l(this,"vs",{});l(this,"Cs",null);l(this,"$s",new Map);l(this,"ws");l(this,"bs");l(this,"Rs");l(this,"K",[]);this.xt=t,this.ps=new nt(t),this.Rs=new V,this.ws=new at(t,this),this.bs=new ht,this.Cs=t.createBuffer(),z(this.xt,[0,0,this.xt.canvas.width,this.xt.canvas.height])}Ms(t){let i=this.$s.get(t);if(i)return i;const r=new ct(this.xt);return i=(0,{[y.RECTANGLE]:()=>new ut(this.xt,r),[y.LINE]:()=>new dt(this.xt,r),[y.ELLIPSE]:()=>new gt(this.xt,r),[y.ARC]:()=>new xt(this.xt,r),[y.TRIANGLE]:()=>new Rt(this.xt,r),[y.BEZIER_CURVE]:()=>new bt(this.xt,r)}[t])(),this.$s.set(t,i),i}Ss(t){this._s!==t&&(this._s=t,t.Xt())}Fs(t,i){return this.ps.oe(t,i)}ie(){return this.ps.ie()}Bt(){return this.ps.Bt()}re(){return this.ps.re()}zs(t){this.gs=t,t&&(this.vs={})}Zt(t,i){this.vs[t]=i}Ps(t){Object.assign(this.vs,t)}ne(t){return this.ps.ne(t)}ks(t,i,r,n,o){const a=this.ie(),h={l:t.textures[0],m:t.textures[1],n:t.textures[2],o:t.textures[3],p:t.textures[4],q:[t.width,t.height]};this.bs.Ee(i,r,n,o,a,h,this.Rs)}Gs(t,i,r,n){var R;const o=this.xt,a=o.canvas.width,h=o.canvas.height,u=t/a*2-1,f=(t+r)/a*2-1,p=1-i/h*2,d=1-(i+n)/h*2,g=new Float32Array([u,d,f,d,u,p,f,d,f,p,u,p]);o.bindBuffer(o.ARRAY_BUFFER,this.Cs),o.bufferData(o.ARRAY_BUFFER,g,o.DYNAMIC_DRAW);const m=((R=this._s)==null?void 0:R.te)||o.getParameter(o.CURRENT_PROGRAM),x=m?o.getAttribLocation(m,"a_position"):-1;x!==-1&&(o.enableVertexAttribArray(x),o.vertexAttribPointer(x,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),x!==-1&&o.disableVertexAttribArray(x)}Ts(t,i,r,n){this.gs?(this.bs.Ee(t,i,r,n,this.gs,{...this.vs},this.Rs),this.gs=null,this.vs={}):this.bs.Ae(t,i,r,n,this.Rs)}As(t,i,r,n){this.bs.Le(t,i,r,n,this.Rs.lineWeight,this.Rs)}Es(t,i,r,n){this.bs.Be(t,i,r,n,this.Rs)}Ls(t,i,r,n,o,a){this.bs.We(t,i,r,n,o,a,this.Rs)}Bs(t,i,r,n,o,a,h,u){const f=this.Rs.lineWeight;this.bs.Ie(t,i,r,n,o,a,h,u,f,this.Rs)}Ds(t,i,r=1,n={}){return new G(this.xt,t,i,r,n,this,!0)}Ws(t,i,r,n,o,a){this.bs.De(t,i,r,n,o,a,this.Rs)}Is(t,i=t,r=t,n=255){this.state.Ct(t,i,r,n),this.Ue(t/255,i/255,r/255,n/255)}Ue(t=0,i=0,r=0,n=0){this.xt.clearColor(t,i,r,n),this.xt.clear(this.xt.COLOR_BUFFER_BIT)}Us(){this.xt.viewport(0,0,this.xt.canvas.width,this.xt.canvas.height),z(this.xt,[0,0,this.xt.canvas.width,this.xt.canvas.height])}get context(){return this.xt}get state(){return this.Rs}Wt(t){this.K.push(this.Rs),this.Rs=t}It(){const t=this.K.pop();t&&(this.Rs=t)}Dt(t){const i=t,r=O(this.xt)??this.xt.getParameter(this.xt.VIEWPORT),n={shader:i,gl:this.xt,viewport:r};this.Ss(i);const o=new Set;for(const a of this.bs)a.type===y.CUSTOM?o.add(y.RECTANGLE):o.add(a.type);for(const a of o)a!==y.CUSTOM&&this.Ms(a);this.ws.me(n,this.bs,this.$s),this.bs.Ue()}Ut(){this.xt.deleteBuffer(this.Cs),this.bs.Ue();for(const t of this.$s.values())t.Ut();this.ps.Ut()}}const w={readShort:(c,t)=>(w.t.uint16[0]=c[t]<<8|c[t+1],w.t.int16[0]),readUshort:(c,t)=>c[t]<<8|c[t+1],readUshorts(c,t,i){const r=[];for(let n=0;n<i;n++)r.push(w.readUshort(c,t+2*n));return r},readUint(c,t){const i=w.t.uint8;return i[3]=c[t],i[2]=c[t+1],i[1]=c[t+2],i[0]=c[t+3],w.t.uint32[0]},readASCII(c,t,i){let r="";for(let n=0;n<i;n++)r+=String.fromCharCode(c[t+n]);return r},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()},wt={parseTab(c,t,i){const r={tables:[],ids:{},off:t};c=new Uint8Array(c.buffer,t,i),t=0;const n=w,o=n.readUshort,a=o(c,t+=2);t+=2;const h=[];for(let u=0;u<a;u++){const f=o(c,t),p=o(c,t+=2);t+=2;const d=n.readUint(c,t);t+=4;const g=`p${f}e${p}`;let m=h.indexOf(d);if(m===-1){let x;m=r.tables.length,h.push(d);const R=o(c,d);x=R===4?this.parse4(c,d):R===12?this.parse12(c,d):{format:R},r.tables.push(x)}r.ids[g]=m}return r},parse4(c,t){const i=w,r=i.readUshort,n=i.readUshorts,o=t,a=r(c,t+=2);t+=2;const h=r(c,t+=2)>>>1,u={format:4,searchRange:r(c,t+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};t+=2,u.entrySelector=r(c,t),t+=2,u.rangeShift=r(c,t),t+=2,u.endCount=n(c,t,h),t+=2*h,t+=2,u.startCount=n(c,t,h),t+=2*h;for(let f=0;f<h;f++)u.idDelta.push(i.readShort(c,t)),t+=2;return u.idRangeOffset=n(c,t,h),t+=2*h,u.glyphIdArray=n(c,t,o+a-t>>1),u},parse12(c,t){const i=w.readUint;i(c,t+=4),i(c,t+=4);const r=i(c,t+=4);t+=4;const n=new Uint32Array(3*r);for(let o=0;o<3*r;o+=3)n[o]=i(c,t+(o<<2)),n[o+1]=i(c,t+(o<<2)+4),n[o+2]=i(c,t+(o<<2)+8);return{format:12,groups:n}}},Ct={parseTab(c,t,i){const r=w;t+=18;const n=r.readUshort(c,t);t+=2,t+=16;const o=r.readShort(c,t);t+=2;const a=r.readShort(c,t);t+=2;const h=r.readShort(c,t);t+=2;const u=r.readShort(c,t);return t+=2,t+=6,{unitsPerEm:n,xMin:o,yMin:a,xMax:h,yMax:u,indexToLocFormat:r.readShort(c,t)}}},At={parseTab(c,t,i){const r=w;t+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let a=0;a<n.length;a++){const h=n[a],u=h==="advanceWidthMax"||h==="numberOfHMetrics"?r.readUshort:r.readShort;o[h]=u(c,t+2*a)}return o}},Tt={parseTab(c,t,i,r){const n=w,o=[],a=[],h=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics;let f=0,p=0,d=0;for(;d<u;)f=n.readUshort(c,t+(d<<2)),p=n.readShort(c,t+(d<<2)+2),o.push(f),a.push(p),d++;for(;d<h;)o.push(f),a.push(p),d++;return{aWidth:o,lsBearing:a}}},q={cmap:wt,head:Ct,hhea:At,maxp:{parseTab(c,t,i){const r=w;return r.readUint(c,t),t+=4,{numGlyphs:r.readUshort(c,t)}}},hmtx:Tt,loca:{parseTab(c,t,i,r){const n=w,o=[],a=r.head.indexToLocFormat,h=r.maxp.numGlyphs+1;if(a===0)for(let u=0;u<h;u++)o.push(n.readUshort(c,t+(u<<1))<<1);else if(a===1)for(let u=0;u<h;u++)o.push(n.readUint(c,t+(u<<2)));return o}},glyf:{parseTab(c,t,i,r){const n=[],o=r.maxp.numGlyphs;for(let a=0;a<o;a++)n.push(null);return n},Os(c,t){const i=w,r=c.Hs,n=c.loca;if(n[t]===n[t+1])return null;const o=_.findTable(r,"glyf",c.Vs);if(!o)return null;let a=o[0]+n[t];const h={};if(h.noc=i.readShort(r,a),a+=2,h.xMin=i.readShort(r,a),a+=2,h.yMin=i.readShort(r,a),a+=2,h.xMax=i.readShort(r,a),a+=2,h.yMax=i.readShort(r,a),a+=2,h.xMin>=h.xMax||h.yMin>=h.yMax)return null;if(h.noc>0){h.endPts=[];for(let g=0;g<h.noc;g++)h.endPts.push(i.readUshort(r,a)),a+=2;const u=i.readUshort(r,a);if(a+=2,r.length-a<u)return null;a+=u;const f=h.endPts[h.noc-1]+1;h.flags=[];for(let g=0;g<f;g++){const m=r[a];if(a++,h.flags.push(m),8&m){const x=r[a];a++;for(let R=0;R<x;R++)h.flags.push(m),g++}}h.xs=[];for(let g=0;g<f;g++){const m=h.flags[g],x=!!(16&m);2&m?(h.xs.push(x?r[a]:-r[a]),a++):x?h.xs.push(0):(h.xs.push(i.readShort(r,a)),a+=2)}h.ys=[];for(let g=0;g<f;g++){const m=h.flags[g],x=!!(32&m);4&m?(h.ys.push(x?r[a]:-r[a]),a++):x?h.ys.push(0):(h.ys.push(i.readShort(r,a)),a+=2)}let p=0,d=0;for(let g=0;g<f;g++)p+=h.xs[g],d+=h.ys[g],h.xs[g]=p,h.ys[g]=d}else h.parts=[],h.endPts=[],h.flags=[],h.xs=[],h.ys=[];return h}}},_={parse:c=>[((t,i,r,n)=>{const o=q,a={Hs:t,Ks:i,Vs:r};for(const h in o){const u=h,f=_.findTable(t,u,r);if(f){const[p,d]=f;let g=n[p];g==null&&(g=o[u].parseTab(t,p,d,a),n[p]=g),a[u]=g}}return a})(new Uint8Array(c),0,0,{})],findTable(c,t,i){const r=w,n=r.readUshort(c,i+4);let o=i+12;for(let a=0;a<n;a++){const h=r.readASCII(c,o,4);r.readUint(c,o+4);const u=r.readUint(c,o+8),f=r.readUint(c,o+12);if(h===t)return[u,f];o+=16}return null},T:q,B:w};class N{constructor(){l(this,"js",new Map);l(this,"Ns",new Map)}Xs(t,i){const r=`${this.Ys(t)}_${i}`;if(this.js.has(r))return this.js.get(r);const n=t.cmap;if(!n||!n.tables)return this.js.set(r,0),0;let o=0;for(const a of n.tables)if(a.format===4?o=this.qs(i,a):a.format===12&&(o=this.Zs(i,a)),o>0)break;return this.js.set(r,o),o}Qs(t,i){const r=i.codePointAt(0);return r===void 0?0:this.Xs(t,r)}Js(t,i){const r=t.hmtx;return r&&r.aWidth&&r.aWidth.length!==0?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}ti(t,i){const r=i/t.head.unitsPerEm,n=t.hhea.ascender*r,o=t.hhea.descender*r,a=t.hhea.lineGap*r;return{ascender:n,descender:o,lineGap:a,lineHeight:n-o+a,unitsPerEm:t.head.unitsPerEm,scale:r}}ei(){this.js.clear(),this.Ns.clear()}Ys(t){return`${t.Vs}_${t.Hs.length}`}qs(t,i){const r=i.endCount.length;let n=-1;for(let o=0;o<r;o++)if(t<=i.endCount[o]){n=o;break}if(n===-1||t<i.startCount[n])return 0;if(i.idRangeOffset[n]===0)return t+i.idDelta[n]&65535;{const o=i.idRangeOffset[n]/2+(t-i.startCount[n])-(r-n);if(o>=0&&o<i.glyphIdArray.length){const a=i.glyphIdArray[o];return a===0?0:a+i.idDelta[n]&65535}}return 0}Zs(t,i){const r=i.groups.length/3;for(let n=0;n<r;n++){const o=i.groups[3*n],a=i.groups[3*n+1],h=i.groups[3*n+2];if(t>=o&&t<=a)return h+(t-o)}return 0}}class _t{constructor(t){l(this,"si");this.si=t}ii(t){var r;const i=[];return(r=t.cmap)!=null&&r.tables?(t.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ri(n);i.push(...o)}else if(n.format===12){const o=this.ni(n);i.push(...o)}}),[...new Set(i)]):[]}oi(t,i){return this.si.Qs(t,i)>0}ai(t,i){for(const r of i)if(!this.oi(t,r))return!1;return!0}hi(t,i){return i.filter(r=>this.oi(t,r))}ci(t){return t.filter(i=>this.li(i))}ri(t){const i=[];if(!(t.startCount&&t.endCount&&t.idRangeOffset&&t.idDelta))return i;for(let r=0;r<t.startCount.length;r++){const n=t.startCount[r],o=t.endCount[r];if(n!==65535||o!==65535){for(let a=n;a<=o;a++)if(this.ui(t,a,r)>0)try{const h=String.fromCodePoint(a);i.push(h)}catch{}}}return i}ni(t){const i=[];if(!t.groups)return i;for(let r=0;r<t.groups.length;r+=3){const n=t.groups[r],o=t.groups[r+1],a=t.groups[r+2];for(let h=n;h<=o;h++)if(a+(h-n)>0)try{const u=String.fromCodePoint(h);i.push(u)}catch{}}return i}ui(t,i,r){if(t.idRangeOffset[r]===0)return i+t.idDelta[r]&65535;{const n=t.idRangeOffset[r]/2+(i-t.startCount[r])-(t.startCount.length-r);if(n>=0&&t.glyphIdArray&&n<t.glyphIdArray.length){const o=t.glyphIdArray[n];if(o!==0)return o+t.idDelta[r]&65535}}return 0}li(t){const i=t.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class Pt{constructor(){l(this,"fi");const t=new N;this.fi=new _t(t)}extractCharacters(t){return this.fi.ii(t)}filterProblematicCharacters(t){return this.fi.ci(t)}characterExists(t,i){return this.fi.oi(t,i)}allCharactersExist(t,i){return this.fi.ai(t,i)}}class Ft{constructor(t){l(this,"di");l(this,"_i");l(this,"Pt");l(this,"pi");this.Pt=t,this.pi=new N,this.di=document.createElement("canvas"),this._i=this.di.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(t,i,r,n){const o=t.length,a=Math.ceil(Math.sqrt(o)),h=Math.ceil(o/a),u=i.width*a,f=i.height*h,p=typeof n=="object"?n:null;this.gi(u,f),this.mi(t,i,a,r,p);const d=this.Pt.Ds(u,f,1,{filter:"nearest"});return d.Et(this.di),{framebuffer:d,columns:a,rows:h}}gi(t,i){this.di.width=t,this.di.height=i,this.di.style.width=t+"px",this.di.style.height=t+"px",this._i.imageSmoothingEnabled=!1,this.di.style.imageRendering="pixelated",this._i.fillStyle="black",this._i.fillRect(0,0,t,i),this._i.textBaseline="top",this._i.textAlign="left",this._i.fillStyle="white"}mi(t,i,r,n,o){const a=n/o.head.unitsPerEm;for(let h=0;h<t.length;h++){const u=h%r,f=Math.floor(h/r),p=t[h].character,d=this.yi(o,p);if(!d)continue;const g=p.codePointAt(0)||0,m=this.pi.Xs(o,g),x=this.Ci(o,m)*a,R=u*i.width,A=f*i.height,C=R+.5*i.width,T=A+.5*i.height,P=Math.round(C-.5*i.width),I=Math.round(T-.5*n),re=P+.5*(i.width-x),ne=I+o.hhea.ascender*a;this.$i(d,re,ne,a)}}yi(t,i){const r=i.codePointAt(0)||0,n=this.pi.Xs(t,r);if(n===0)return null;if(t.glyf&&t.glyf[n]!==null)return t.glyf[n];if(_&&_.T&&_.T.glyf){const o=_.T.glyf.Os(t,n);return t.glyf&&o&&(t.glyf[n]=o),o}return null}Ci(t,i){const r=t.hmtx;return r&&r.aWidth?i<r.aWidth.length?r.aWidth[i]:r.aWidth[r.aWidth.length-1]:0}$i(t,i,r,n){if(!t||!t.xs||t.noc===0)return;const{xs:o,ys:a,endPts:h,flags:u}=t;if(!(o&&a&&h&&u))return;this._i.beginPath();let f=0;for(let p=0;p<h.length;p++){const d=h[p];if(!(d<f)){if(d>=f){const g=i+o[f]*n,m=r-a[f]*n;this._i.moveTo(g,m);let x=f+1;for(;x<=d;)if(1&u[x]){const R=i+o[x]*n,A=r-a[x]*n;this._i.lineTo(R,A),x++}else{const R=i+o[x]*n,A=r-a[x]*n;let C=x+1>d?f:x+1;if(1&u[C]){const T=i+o[C]*n,P=r-a[C]*n;this._i.quadraticCurveTo(R,A,T,P),x=C+1}else{const T=(R+(i+o[C]*n))/2,P=(A+(r-a[C]*n))/2;this._i.quadraticCurveTo(R,A,T,P),x=C}}this._i.closePath()}f=d+1}}this._i.fill()}}class Lt{constructor(){l(this,"si");this.si=new N}calculateMaxGlyphDimensions(t,i,r){let n=0;const o=this.si.ti(r,i),a=o.lineHeight;for(const h of t){const u=this.si.Qs(r,h);if(u===0)continue;const f=this.si.Js(r,u)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}getCharacterAdvanceWidth(t,i,r){const n=this.si.ti(r,i),o=this.si.Qs(r,t);return this.si.Js(r,o)*n.scale}getFontMetrics(t,i){return this.si.ti(i,t)}ei(){this.si.ei()}}class St{constructor(){l(this,"pi");this.pi=new N}createCharacterObjects(t,i){return t.map((r,n)=>{const o=r.codePointAt(0)||0,a=this.wi(n);let h=0;if(i.hmtx&&i.hmtx.aWidth){const u=this.pi.Xs(i,o);u>0&&i.hmtx.aWidth[u]!==void 0&&(h=i.hmtx.aWidth[u])}return{character:r,unicode:o,color:a,advanceWidth:h}})}wi(t){return[t%256/255,Math.floor(t/256)%256/255,Math.floor(t/65536)%256/255]}bi(t,i){if(!B.M(typeof t=="string","Character must be a string.",{method:"getCharacterColor",providedValue:t}))return[0,0,0];const r=i.find(n=>n.character===t);return r?r.color:[0,0,0]}xi(t,i){return B.M(typeof t=="string"&&t.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:t})?Array.from(t).map(r=>this.bi(r,i)||[0,0,0]):[[0,0,0]]}}class Q{constructor(t,i=16){l(this,"Ri");l(this,"Mi",[]);l(this,"Si");l(this,"Fi",16);l(this,"zi",0);l(this,"Pi",0);l(this,"ki",{width:0,height:0});l(this,"Gi");l(this,"Ti");l(this,"Ai");l(this,"Ei");l(this,"Li");this.Fi=i,this.Ti=new Pt,this.Ai=new Ft(t),this.Ei=new Lt,this.Li=new St}async Bi(t){let i;if(!t)throw new v("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const r=await fetch(t);if(!r.ok)throw new v(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}await this.Di(i),this.Ri=_.parse(i)[0],await this.Wi()}Ii(t){if(t===void 0)return this.Fi;this.Fi=t,this.ki=this.Ei.calculateMaxGlyphDimensions(this.Mi.map(r=>r.character),this.Fi,this.Ri);const i=this.Ai.createTextureAtlas(this.Mi,this.ki,this.Fi,this.Ri);this.Si=i.framebuffer,this.zi=i.columns,this.Pi=i.rows}async Ui(t){try{const i=await fetch(t);if(!i.ok)throw new v(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.Di(r);const n=_.parse(r);if(!n||n.length===0)throw Error("Failed to parse font file");this.Ri=n[0],await this.Wi()}catch(i){throw new v("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async Di(t){const i=Date.now();this.Gi=new FontFace("CustomFont_"+i,t),await this.Gi.load(),document.fonts.add(this.Gi)}async Wi(){const t=this.Ti.extractCharacters(this.Ri),i=this.Ti.filterProblematicCharacters(t);this.Mi=this.Li.createCharacterObjects(i,this.Ri),this.ki=this.Ei.calculateMaxGlyphDimensions(i,this.Fi,this.Ri);const r=this.Ai.createTextureAtlas(this.Mi,this.ki,this.Fi,this.Ri);this.Si=r.framebuffer,this.zi=r.columns,this.Pi=r.rows}bi(t){return this.Li.bi(t,this.Mi)}xi(t){return this.Li.xi(t,this.Mi)}Ut(){this.Si.Ut(),document.fonts.delete(this.Gi)}get fontFramebuffer(){return this.Si}get characters(){return this.Mi}get textureColumns(){return this.zi}get textureRows(){return this.Pi}get maxGlyphDimensions(){return this.ki}get fontSize(){return this.Fi}get font(){return this.Ri}}class J{constructor(t,i,r){l(this,"Oi");l(this,"Hi");l(this,"$t");l(this,"wt");l(this,"Vi");l(this,"Ki");l(this,"ji");l(this,"Ni");l(this,"Xi");this.ji=t,this.Ni=i,this.Xi=r,this.rt()}rt(){this.Oi=Math.floor(this.ji.width/this.Ni),this.Hi=Math.floor(this.ji.height/this.Xi),this.$t=this.Oi*this.Ni,this.wt=this.Hi*this.Xi,this.Vi=Math.floor((this.ji.width-this.$t)/2),this.Ki=Math.floor((this.ji.height-this.wt)/2)}Yi(t,i){this.Ni=t,this.Xi=i,this.rt()}get cellWidth(){return this.Ni}get cellHeight(){return this.Xi}get cols(){return this.Oi}get rows(){return this.Hi}get width(){return this.$t}get height(){return this.wt}get offsetX(){return this.Vi}get offsetY(){return this.Ki}}class tt{constructor(t={}){l(this,"ji");l(this,"qi");l(this,"Zi");t.canvas?(this.ji=t.canvas,this.Zi=!1):(this.ji=this.Qi(t.width,t.height),this.Zi=!0),this.ji.style.imageRendering="pixelated"}Qi(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}Ji(t,i){this.ji.width=t??this.ji.width,this.ji.height=i??this.ji.height}tr(){const t=this.ji.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!t)throw new v("`textmode.js` requires WebGL2 support.");return t}Ut(){this.qi&&this.qi.disconnect();const t=this.ji.getContext("webgl")||this.ji.getContext("webgl2");if(t){const i=t.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.Zi&&this.ji.parentNode&&this.ji.parentNode.removeChild(this.ji)}get canvas(){return this.ji}get width(){return this.ji.width}get height(){return this.ji.height}}class Mt{constructor(t=60){l(this,"er");l(this,"sr");l(this,"ir",null);l(this,"rr",0);l(this,"nr",!0);l(this,"ar",0);l(this,"hr",0);l(this,"cr",[]);l(this,"lr",10);l(this,"ur",0);this.er=t,this.sr=1e3/t}start(t){if(!this.nr)return;this.rr=performance.now();const i=r=>{if(!this.nr)return void(this.ir=null);const n=r-this.rr;n>=this.sr&&(t(),this.rr=r-n%this.sr),this.nr&&(this.ir=requestAnimationFrame(i))};this.ir=requestAnimationFrame(i)}stop(){this.ir&&(cancelAnimationFrame(this.ir),this.ir=null)}pause(){this.nr&&(this.nr=!1,this.stop())}resume(t){this.nr||(this.nr=!0,this.start(t))}frameRate(t,i){if(t===void 0)return this.ar;this.er=t,this.sr=1e3/t,this.nr&&i&&(this.stop(),this.start(i))}measureFrameRate(){const t=performance.now();if(this.hr>0){const i=t-this.hr;this.cr.push(i),this.cr.length>this.lr&&this.cr.shift();const r=this.cr.reduce((n,o)=>n+o,0)/this.cr.length;this.ar=1e3/r}this.hr=t}get isLooping(){return this.nr}get frameRateLimit(){return this.er}get currentFrameRate(){return this.ar}get frameCount(){return this.ur}set frameCount(t){this.ur=t}incrementFrame(){this.ur++}resetFrameCount(){this.ur=0}}class Ut{constructor(){l(this,"dr",new Map);l(this,"_r",null);l(this,"pr",null);l(this,"gr");l(this,"mr");l(this,"vr",!1);l(this,"yr");l(this,"Cr");l(this,"$r",{ArrowUp:"UP_ARROW",ArrowDown:"DOWN_ARROW",ArrowLeft:"LEFT_ARROW",ArrowRight:"RIGHT_ARROW",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12",Enter:"ENTER",Return:"RETURN",Tab:"TAB",Escape:"ESCAPE",Backspace:"BACKSPACE",Delete:"DELETE",Insert:"INSERT",Home:"HOME",End:"END",PageUp:"PAGE_UP",PageDown:"PAGE_DOWN",Shift:"SHIFT",Control:"CONTROL",Alt:"ALT",Meta:"META"," ":"SPACE"})}wr(){this.vr||(this.gr=t=>{this.br(t)},this.mr=t=>{this.Rr(t)},window.addEventListener("keydown",this.gr,{passive:!1}),window.addEventListener("keyup",this.mr,{passive:!1}),this.vr=!0)}Mr(){this.vr&&(window.removeEventListener("keydown",this.gr),window.removeEventListener("keyup",this.mr),this.vr=!1,this.dr.clear(),this._r=null,this.pr=null)}Sr(t){this.yr=t}Fr(t){this.Cr=t}zr(t){const i=this.Pr(t),r=this.dr.get(t)||this.dr.get(i);return(r==null?void 0:r.isPressed)||!1}kr(){return this._r}Gr(){return this.pr}Tr(){const t=[];for(const[i,r]of this.dr)r.isPressed&&t.push(i);return t}Ar(){return{ctrl:this.zr("Control"),shift:this.zr("Shift"),alt:this.zr("Alt"),meta:this.zr("Meta")}}Er(){this.dr.clear(),this._r=null,this.pr=null}br(t){const i=t.key,r=Date.now();this.dr.has(i)||this.dr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.dr.get(i);if(!n.isPressed&&(n.isPressed=!0,n.lastPressTime=r,this._r=i,this.yr)){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!0,originalEvent:t};this.yr(o)}}Rr(t){const i=t.key,r=Date.now();this.dr.has(i)||this.dr.set(i,{isPressed:!1,lastPressTime:0,lastReleaseTime:0});const n=this.dr.get(i);if(n.isPressed=!1,n.lastReleaseTime=r,this.pr=i,this.Cr){const o={key:i,keyCode:t.keyCode,ctrlKey:t.ctrlKey,shiftKey:t.shiftKey,altKey:t.altKey,metaKey:t.metaKey,isPressed:!1,originalEvent:t};this.Cr(o)}}Pr(t){return this.$r[t]||t.toLowerCase()}}class Bt{constructor(t){l(this,"ji");l(this,"Lr");l(this,"Br",{x:-1,y:-1});l(this,"Dr",{x:-1,y:-1});l(this,"Wr",null);l(this,"Ir");l(this,"Ur");l(this,"Or");l(this,"Hr");l(this,"Vr");l(this,"Kr");l(this,"vr",!1);l(this,"jr");l(this,"Nr");l(this,"Xr");l(this,"Yr");l(this,"qr");this.ji=t}Bi(t){this.Lr=t,this.Zr()}wr(){if(this.vr)return;const t=this.ji.canvas;this.Ir=i=>{this.Qr(i),this.Jr(i)},this.Ur=()=>{this.Dr={...this.Br},this.Br.x=-1,this.Br.y=-1,this.Wr=null},this.Or=i=>{this.Qr(i),this.tn(i)},this.Hr=i=>{this.Qr(i),this.en(i)},this.Vr=i=>{this.Qr(i),this.sn(i)},this.Kr=i=>{this.Qr(i),this.rn(i)},t.addEventListener("mousemove",this.Ir,{passive:!0}),t.addEventListener("mouseleave",this.Ur,{passive:!0}),t.addEventListener("mousedown",this.Or,{passive:!0}),t.addEventListener("mouseup",this.Hr,{passive:!0}),t.addEventListener("click",this.Vr,{passive:!0}),t.addEventListener("wheel",this.Kr,{passive:!1}),this.vr=!0}Mr(){if(!this.vr)return;const t=this.ji.canvas;t.removeEventListener("mousemove",this.Ir),t.removeEventListener("mouseleave",this.Ur),t.removeEventListener("mousedown",this.Or),t.removeEventListener("mouseup",this.Hr),t.removeEventListener("click",this.Vr),t.removeEventListener("wheel",this.Kr),this.vr=!1}Zr(){if(this.vr)try{if(this.Wr){const t=new MouseEvent("mousemove",{clientX:this.Wr.x,clientY:this.Wr.y,bubbles:!1,cancelable:!1});this.Qr(t)}else this.Br.x!==-1&&this.Br.y!==-1&&(this.Br.x>=this.Lr.cols||this.Br.y>=this.Lr.rows)&&(this.Br.x=-1,this.Br.y=-1)}catch{this.Br.x=-1,this.Br.y=-1}}nn(t){this.jr=t}Sr(t){this.Nr=t}Fr(t){this.Xr=t}an(t){this.Yr=t}hn(t){this.qr=t}cn(){return{x:this.Br.x,y:this.Br.y}}Jr(t){if(this.Yr){const i={position:{...this.Br},previousPosition:{...this.Dr},originalEvent:t};this.Yr(i)}}tn(t){if(this.Nr){const i={position:{...this.Br},previousPosition:{...this.Dr},button:t.button,originalEvent:t};this.Nr(i)}}en(t){if(this.Xr){const i={position:{...this.Br},previousPosition:{...this.Dr},button:t.button,originalEvent:t};this.Xr(i)}}sn(t){if(this.jr){const i={position:{...this.Br},previousPosition:{...this.Dr},button:t.button,originalEvent:t};this.jr(i)}}rn(t){if(this.qr){const i={position:{...this.Br},previousPosition:{...this.Dr},delta:{x:t.deltaX,y:t.deltaY},originalEvent:t};this.qr(i)}}Qr(t){const i=this.ji.canvas;this.Dr={...this.Br},this.Wr={x:t.clientX,y:t.clientY};const r=i.getBoundingClientRect(),n=t.clientX-r.left,o=t.clientY-r.top,a=i.width/r.width,h=o*(i.height/r.height),u=n*a-this.Lr.offsetX,f=h-this.Lr.offsetY,p=Math.floor(u/this.Lr.cellWidth),d=Math.floor(f/this.Lr.cellHeight);p>=0&&p<this.Lr.cols&&d>=0&&d<this.Lr.rows?(this.Br.x=p,this.Br.y=d):(this.Br.x=-1,this.Br.y=-1)}}const Dt=c=>class extends c{rotate(t=0,i=0,r=0){this.Pt.state.ht(t),this.Pt.state.ct(i),this.Pt.state.lt(r)}rotateX(t){this.Pt.state.ht(t)}rotateY(t){this.Pt.state.ct(t)}rotateZ(t){this.Pt.state.lt(t)}push(){this.Pt.state.N()}pop(){this.Pt.state.it()}rect(t,i,r=1,n=1){this.Pt.Ts(t,i,r,n)}point(t,i){this.Pt.Ts(t,i,1,1)}line(t,i,r,n){this.Pt.As(t,i,r,n)}lineWeight(t){this.Pt.state.ot(t)}background(t,i=t,r=t,n=255){this.Pt.Is(t,i,r,n)}char(t){this.Pt.state.ut(this.Ri.bi(t))}charColor(t,i,r){this.Pt.state.ft(t,i,r)}cellColor(t,i,r){this.Pt.state.dt(t,i,r)}flipX(t){this.Pt.state._t(t)}flipY(t){this.Pt.state.gt(t)}charRotation(t){this.Pt.state.yt(t)}invert(t){this.Pt.state.vt(t)}clear(){this.Pt.Is(0,0,0,0)}ellipse(t,i,r,n){this.Pt.Es(t,i,r/2,n/2)}triangle(t,i,r,n,o,a){this.Pt.Ls(t,i,r,n,o,a)}bezierCurve(t,i,r,n,o,a,h,u){this.Pt.Bs(t,i,r,n,o,a,h,u)}arc(t,i,r,n,o,a){this.Pt.Ws(t,i,r,n,o,a)}shader(t){this.Pt.zs(t)}setUniform(t,i){this.Pt.Zt(t,i)}setUniforms(t){this.Pt.Ps(t)}createFilterShader(t){return this.Pt.ne(t)}createFramebuffer(t){return this.Pt.Ds(t.width,t.height,5,{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"})}image(t,i,r,n,o){this.Pt.ks(t,i,r,n??t.width,o??t.height)}};class X{ln(t){const i=t.Lt(0),r=t.Lt(1),n=t.Lt(2),o=t.Lt(3);return{characterPixels:i,primaryColorPixels:r,secondaryColorPixels:n,transformPixels:t.Lt(4),rotationPixels:o}}un(t,i){return t[i]+(t[i+1]<<8)}fn(t,i){return{r:t[i],g:t[i+1],b:t[i+2],a:t[i+3]}}}class H{dn(t,i){return new Blob([t],{type:i})}_n(t,i,r){try{const n=this.dn(t,r),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=i,a.style.display="none",a.rel="noopener",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(o)}catch(n){throw console.error("Failed to download file:",n),Error("File download failed: "+(n instanceof Error?n.message:"Unknown error"))}}pn(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}gn(){const t=new Date;return{date:t.toISOString().split("T")[0],time:t.toTimeString().split(" ")[0].replace(/:/g,"-")}}mn(t){return t.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}vn(){return"textmode-export-"+this.pn()}}class It extends X{yn(t,i,r){const n=t[r]===255,o=t[r+1]===255,a=t[r+2]===255,h=i[r],u=i[r+1];return{isInverted:n,flipHorizontal:o,flipVertical:a,rotation:Math.round(360*(h+u/255)/255*100)/100}}Cn(t,i,r){return{x:t,y:i,cellX:t*r.cellWidth,cellY:i*r.cellHeight}}$n(t,i){const r=[];let n=0;for(let o=0;o<i.rows;o++)for(let a=0;a<i.cols;a++){const h=4*n,u=this.un(t.characterPixels,h);let f=this.fn(t.primaryColorPixels,h),p=this.fn(t.secondaryColorPixels,h);const d=this.yn(t.transformPixels,t.rotationPixels,h);if(d.isInverted){const m=f;f=p,p=m}const g=this.Cn(a,o,i);r.push({charIndex:u,primaryColor:f,secondaryColor:p,transform:d,position:g}),n++}return r}}class zt{wn(t,i){const r=t.cmap;for(const n of r.tables)if(n.format===4){const o=n;for(let a=0;a<o.startCount.length;a++)if(i>=o.startCount[a]&&i<=o.endCount[a]){if(o.idRangeOffset[a]===0)return i+o.idDelta[a]&65535;{const h=o.idRangeOffset[a]/2+(i-o.startCount[a])-(o.startCount.length-a);if(h>=0&&h<o.glyphIdArray.length){const u=o.glyphIdArray[h];if(u!==0)return u+o.idDelta[a]&65535}}}}else if(n.format===12){const o=n;for(let a=0;a<o.groups.length;a+=3){const h=o.groups[a],u=o.groups[a+1],f=o.groups[a+2];if(i>=h&&i<=u)return f+(i-h)}}return 0}bn(t,i,r,n,o){const a=o/t.head.unitsPerEm;return{getBoundingBox:()=>({x1:r+i.xMin*a,y1:n+-i.yMax*a,x2:r+i.xMax*a,y2:n+-i.yMin*a}),toSVG:()=>this.xn(i,r,n,a)}}xn(t,i,r,n){if(!t||!t.xs)return"";const{xs:o,ys:a,endPts:h,flags:u}=t;if(!(o&&a&&h&&u))return"";let f="",p=0;for(let d=0;d<h.length;d++){const g=h[d];if(!(g<p)){if(g>=p){const m=i+o[p]*n,x=r-a[p]*n;f+=`M${m.toFixed(2)},${x.toFixed(2)}`;let R=p+1;for(;R<=g;)if(1&u[R]){const A=i+o[R]*n,C=r-a[R]*n;f+=`L${A.toFixed(2)},${C.toFixed(2)}`,R++}else{const A=i+o[R]*n,C=r-a[R]*n;let T=R+1>g?p:R+1;if(1&u[T]){const P=i+o[T]*n,I=r-a[T]*n;f+=`Q${A.toFixed(2)},${C.toFixed(2)} ${P.toFixed(2)},${I.toFixed(2)}`,R=T+1}else{const P=(A+(i+o[T]*n))/2,I=(C+(r-a[T]*n))/2;f+=`Q${A.toFixed(2)},${C.toFixed(2)} ${P.toFixed(2)},${I.toFixed(2)}`,R=T}}f+="Z"}p=g+1}}return f}Rn(t,i,r,n,o){const a=t.codePointAt(0)||0,h=this.wn(i,a);let u=null;return i.glyf&&i.glyf[h]!==null?u=i.glyf[h]:(u=_.T.glyf.Os(i,h),i.glyf[h]=u),this.bn(i,u,r,n,o)}Mn(t,i,r,n,o,a,h,u){const f=r+(o-u*(h/i.head.unitsPerEm))/2,p=n+(a+.7*h)/2;return this.Rn(t,i,f,p,h).toSVG()||null}}class Ot{constructor(){l(this,"Sn");this.Sn=new zt}Fn(t){const{width:i,height:r}=t;return`<?xml version="1.0" encoding="UTF-8"?><svg width="${i}" height="${r}" viewBox="0 0 ${i} ${r}" xmlns="http://www.w3.org/2000/svg"><title>textmode.js sketch</title>`}zn(){return"</g></svg>"}Pn(t,i){if(!i.includeBackgroundRectangles)return"";const[r,n,o,a]=i.backgroundColor;return`<rect width="${t.width}" height="${t.height}" fill="rgba(${r},${n},${o},${a/255})"/>`}kn(t,i){const{transform:r,position:n}=t;if(!r.flipHorizontal&&!r.flipVertical&&!r.rotation)return"";const o=n.cellX+i.cellWidth/2,a=n.cellY+i.cellHeight/2,h=[];if(r.flipHorizontal||r.flipVertical){const u=r.flipHorizontal?-1:1,f=r.flipVertical?-1:1;h.push(`translate(${o} ${a})scale(${u} ${f})translate(${-o} ${-a})`)}return r.rotation&&h.push(`rotate(${r.rotation} ${o} ${a})`),` transform="${h.join(" ")}"`}Gn(t,i,r){if(!r.includeBackgroundRectangles||t.secondaryColor.a===0)return"";const{position:n}=t,{r:o,g:a,b:h,a:u}=t.secondaryColor,f=`rgba(${o},${a},${h},${u/255})`;return r.drawMode==="stroke"?`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" stroke="${f}" fill="none" stroke-width="${r.strokeWidth}"/>`:`<rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" fill="${f}"/>`}Rn(t,i,r,n){const o=r.characters[t.charIndex];if(!o)return"";const a=this.Sn.Mn(o.character,r.font,t.position.cellX,t.position.cellY,i.cellWidth,i.cellHeight,r.fontSize,o.advanceWidth);if(!a)return"";const{r:h,g:u,b:f,a:p}=t.primaryColor,d=`rgba(${h},${u},${f},${p/255})`;return n.drawMode==="stroke"?`<path d="${a}" stroke="${d}" stroke-width="${n.strokeWidth}" fill="none"/>`:`<path d="${a}" fill="${d}"/>`}Tn(t,i,r,n){const o=[],a=this.Gn(t,i,n);a&&o.push(a);const h=this.Rn(t,i,r,n);if(h){const u=this.kn(t,i);o.push(u?`<g${u}>${h}</g>`:h)}return o.join("")}An(t,i,r,n){const o=[this.Fn(i),this.Pn(i,n),'<g id="ascii-cells">'];for(const a of t)o.push(this.Tn(a,i,r,n));return o.push(this.zn()),o.join("")}En(t){return t.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\s+/g," ").replace(/> </g,"><")}}class Gt extends H{Ln(t){return this.dn(t,"image/svg+xml;charset=utf-8")}Bn(t,i){this._n(t,this.mn(i)+".svg","image/svg+xml;charset=utf-8")}Dn(t,i){this.Bn(t,i||this.vn())}}class et{constructor(){l(this,"Wn");l(this,"In");l(this,"Un");this.Wn=new It,this.In=new Ot,this.Un=new Gt}On(t){return{includeBackgroundRectangles:t.includeBackgroundRectangles??!0,drawMode:t.drawMode??"fill",strokeWidth:t.strokeWidth??1,backgroundColor:t.backgroundColor??[0,0,0,0],filename:t.filename||this.Un.vn()}}Hn(t,i={}){const r=this.Wn.$n(this.Wn.ln(t.pipeline),t.grid),n=this.In.An(r,t.grid,t.font,this.On(i));return this.In.En(n)}Dn(t,i={}){this.Un.Dn(this.Hn(t,i),i.filename)}}class Wt extends X{Vn(t,i,r,n=" "){var h;const o=[];let a=0;for(let u=0;u<i.rows;u++){const f=[];for(let p=0;p<i.cols;p++){const d=4*a,g=this.un(t.characterPixels,d),m=((h=r.characters[g])==null?void 0:h.character)||n;f.push(m),a++}o.push(f)}return o}}class Nt{Kn(t,i){const r=[];for(const o of t){let a=o.join("");i.preserveTrailingSpaces||(a=a.replace(/\s+$/,"")),r.push(a)}const n=i.lineEnding==="crlf"?`\r
26
11
  `:`
27
- `;return i.join(n)}}class $t extends Y{$r(t,r){const i=this.br(r);this.Ui(t,i,"text/plain;charset=utf-8")}br(t){let r=this.ji(t);return r===".txt"||r.length<=4?this.Hi():r}}class et{constructor(){u(this,"_r");u(this,"gr");u(this,"mr");this._r=new Bt,this.gr=new Gt,this.mr=new $t}vr(t){return{preserveTrailingSpaces:t.preserveTrailingSpaces??!1,lineEnding:t.lineEnding??"lf",emptyCharacter:t.emptyCharacter??" ",filename:t.filename||this.mr.Hi()}}zr(t,r={}){const i=this.vr(r),n=this._r.yr(this._r.Li(t.pipeline),t.grid,t.font,i.emptyCharacter);return this.gr.wr(n,i)}$r(t,r={}){this.mr.$r(this.zr(t,r),r.filename)}}class Ot extends j{Rr(t,r=1,i="transparent"){const n=t.canvas;if(r===1&&i==="transparent")return n;const o=document.createElement("canvas"),a=o.getContext("2d"),h=Math.round(n.width*r),l=Math.round(n.height*r);return o.width=h,o.height=l,i!=="transparent"&&(a.fillStyle=i,a.fillRect(0,0,h,l)),a.imageSmoothingEnabled=!1,a.drawImage(n,0,0,n.width,n.height,0,0,h,l),o}}class Wt{Tr(t,r){const i=this.Sr(r.format);return r.format==="png"?t.toDataURL(i):t.toDataURL(i,r.quality)}async Mr(t,r){return new Promise((i,n)=>{const o=this.Sr(r.format),a=h=>{h?i(h):n(Error(`Failed to generate ${r.format.toUpperCase()} blob`))};r.format==="png"?t.toBlob(a,o):t.toBlob(a,o,r.quality)})}Sr(t){switch(t){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+t)}}}const kt={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},rt={png:".png",jpg:".jpg",webp:".webp"};class Nt extends Y{Fr(t,r,i){this.Gr(t,this.ji(r)+rt[i])}Gr(t,r){const i=URL.createObjectURL(t);try{const n=document.createElement("a");n.href=i,n.download=r,n.style.display="none",n.rel="noopener",document.body.appendChild(n),n.click(),document.body.removeChild(n)}finally{URL.revokeObjectURL(i)}}Dr(t){return t in kt&&t in rt}}class Vt{constructor(){u(this,"_r");u(this,"gr");u(this,"mr");this._r=new Ot,this.gr=new Wt,this.mr=new Nt}vr(t){return{format:t.format??"png",quality:t.quality??1,scale:t.scale??1,backgroundColor:t.backgroundColor??"transparent",filename:t.filename||this.mr.Hi()}}Pr(t){if(!this.mr.Dr(t.format))throw Error(`Saving '${t.format}' files is not supported`);if(t.quality<0||t.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(t.scale<=0)throw Error("Scale factor must be greater than 0");t.format==="jpg"&&t.backgroundColor==="transparent"&&(t.backgroundColor="black")}async Mr(t,r){if(r.scale===1&&r.backgroundColor==="transparent")return await this.gr.Mr(t.canvas,r);const i=this._r.Rr(t,r.scale,r.backgroundColor);return await this.gr.Mr(i,r)}async Fr(t,r={}){const i=this.vr(r);this.Pr(i);const n=await this.Mr(t,i);this.mr.Fr(n,i.filename,i.format)}}const Xt=c=>class extends c{Ar(){this.Us.ls(this.Br)}toString(t={}){return this.Ar(),new et().zr({pipeline:this.Ir,grid:this.Lr,font:this.Qs},t)}saveStrings(t={}){this.Ar(),new et().$r({pipeline:this.Ir,grid:this.Lr,font:this.Qs},t)}toSVG(t={}){return this.Ar(),new tt().Cr({pipeline:this.Ir,grid:this.Lr,font:this.Qs},t)}saveSVG(t={}){this.Ar(),new tt().pr({pipeline:this.Ir,grid:this.Lr,font:this.Qs},t)}async saveCanvas(t={}){await new Vt().Fr(this.xi,t)}},jt=c=>class extends c{async loadFont(t){return this.Qs.di(t).then(()=>{const r=this.Qs.maxGlyphDimensions;this.Lr.wi(r.width,r.height),this.Ir.W(this.Lr.cols,this.Lr.rows),this.Us.cs()})}fontSize(t){if(!z.m(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.Qs.fontSize===t)return;this.Qs.fi(t);const r=this.Qs.maxGlyphDimensions;this.Lr.wi(r.width,r.height),this.Ir.W(this.Lr.cols,this.Lr.rows),this.Us.cs()}},Yt=c=>class extends c{get frameCount(){return this.Er.frameCount}set frameCount(t){this.Er.frameCount=t}frameRate(t){return t===void 0?this.Er.currentFrameRate:this.Er.frameRate(t,()=>this.Wr())}noLoop(){this.Er.pause()}loop(){this.Er.resume(()=>this.Wr())}redraw(t=1){if(z.m(typeof t=="number"&&t>0&&Number.isInteger(t),"Redraw count must be a positive integer.",{method:"redraw",providedValue:t}))for(let r=0;r<t;r++)this.Wr()}isLooping(){return this.Er.isLooping}};class Ht{constructor(){u(this,"Us");u(this,"Qs");u(this,"xi");u(this,"Lr");u(this,"Er");u(this,"Br");u(this,"Ir");u(this,"kr")}Wr(){}}class it extends function(r,...i){return i.reduce((n,o)=>o(n),r)}(Ht,Pt,Xt,jt,Yt){constructor(r={}){super();u(this,"Ur",!1);u(this,"Vr",()=>{});u(this,"Or",()=>{});u(this,"jr",()=>{});u(this,"Hr");this.xi=new J(r),this.Us=new St(this.xi.Ri()),this.Qs=new K(this.Us,r.fontSize??16),this.Er=new Lt(r.frameRate??60),this.Br=this.Us.Xe(X,`#version 300 es
28
- 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.0);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.0,1.0);o_transform=vec4(v_transform,1.0);}`),this.kr=this.Us.Xe("attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.0,1.0);}","precision mediump float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D u_primaryColorTexture;uniform sampler2D u_secondaryColorTexture;uniform sampler2D u_transformTexture;uniform sampler2D u_asciiCharacterTexture;uniform sampler2D u_rotationTexture;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;uniform vec2 u_gridOffsetPixels;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){vec2 adjustedCoord=(gl_FragCoord.xy-u_gridOffsetPixels)/u_gridPixelDimensions;vec2 gridCoord=adjustedCoord*u_gridCellDimensions;vec2 cellCoord=floor(gridCoord);vec2 charIndexTexCoord=(cellCoord+0.5)/u_gridCellDimensions;vec4 primaryColor=texture2D(u_primaryColorTexture,charIndexTexCoord);vec4 secondaryColor=texture2D(u_secondaryColorTexture,charIndexTexCoord);vec4 transformColor=texture2D(u_transformTexture,charIndexTexCoord);bool isInverted=transformColor.r>0.5;bool flipHorizontal=transformColor.g>0.5;bool flipVertical=transformColor.b>0.5;vec4 encodedIndexVec=texture2D(u_asciiCharacterTexture,charIndexTexCoord);int charIndex=int(encodedIndexVec.r*255.0+0.5)+int(encodedIndexVec.g*255.0+0.5)*256;int charCol=int(mod(float(charIndex),u_charsetDimensions.x));int charRow=charIndex/int(u_charsetDimensions.x);float flippedRow=(u_charsetDimensions.y-1.0)-float(charRow);vec2 charCoord=vec2(float(charCol),flippedRow)/u_charsetDimensions;vec4 rotationColor=texture2D(u_rotationTexture,charIndexTexCoord);float scaledAngle=rotationColor.r*255.0+rotationColor.g;float rotationAngle=-(scaledAngle*360.0/255.0)*0.017453292;vec2 fractionalPart=fract(gridCoord)-0.5;if(flipHorizontal)fractionalPart.x=-fractionalPart.x;if(flipVertical)fractionalPart.y=-fractionalPart.y;fractionalPart=rotate2D(rotationAngle)*fractionalPart+0.5;vec2 cellSize=1.0/u_charsetDimensions;vec2 texCoord=charCoord+fractionalPart*cellSize;vec2 cellMax=charCoord+cellSize;if(any(lessThan(texCoord,charCoord))||any(greaterThan(texCoord,cellMax))){gl_FragColor=isInverted ? primaryColor : secondaryColor;return;}vec4 charTexel=texture2D(u_characterTexture,texCoord);if(isInverted)charTexel.rgb=1.0-charTexel.rgb;gl_FragColor=mix(secondaryColor,primaryColor,charTexel);}"),this.Xr(r)}async Xr(r){await this.Qs.ci(r.fontSource);const i=this.Qs.maxGlyphDimensions;this.Lr=new q(this.xi.canvas,i.width,i.height),this.Ir=this.Us.rs(this.Lr.cols,this.Lr.rows,5),this.Yr(),this.Vr(),this.Er.start(()=>this.Wr())}Yr(){this.Hr=()=>{this.jr()},window.addEventListener("resize",this.Hr)}Wr(){if(this.Er.measureFrameRate(),this.Er.incrementFrame(),this.Ur)return;this.Ir.V(),this.Us.He(this.Br),this.Or(),this.Us.ls(this.Br),this.Ir.O();const r=this.Us.state.canvasBackgroundColor;this.Us.de(r[0],r[1],r[2],r[3]),this.Us.He(this.kr),this.kr.st({u_characterTexture:this.Qs.fontFramebuffer,u_charsetDimensions:[this.Qs.textureColumns,this.Qs.textureRows],u_asciiCharacterTexture:this.Ir.textures[0],u_primaryColorTexture:this.Ir.textures[1],u_secondaryColorTexture:this.Ir.textures[2],u_transformTexture:this.Ir.textures[4],u_rotationTexture:this.Ir.textures[3],u_gridCellDimensions:[this.Lr.cols,this.Lr.rows],u_gridPixelDimensions:[this.Lr.width,this.Lr.height],u_gridOffsetPixels:[this.Lr.offsetX,this.Lr.offsetY],u_aspectRatio:this.Lr.width/this.Lr.height}),this.Us.Qe(this.Lr.offsetX,this.Lr.offsetY,this.Lr.width,this.Lr.height)}setup(r){this.Vr=r}draw(r){this.Or=r}windowResized(r){this.jr=r}resizeCanvas(r,i){this.xi.W(r,i),this.Lr.zt(),this.Ir.W(this.Lr.cols,this.Lr.rows),this.Us.cs(),this.Wr()}destroy(){this.Ur||(this.Er.stop(),window.removeEventListener("resize",this.Hr),this.Qs.j(),this.Us.j(),this.Ur=!0)}get grid(){return this.Lr}get font(){return this.Qs}get width(){return this.xi.width}get height(){return this.xi.height}get canvas(){return this.xi.canvas}get isDisposed(){return this.Ur}get drawFramebuffer(){return this.Ir}}class W{constructor(){}static create(t={}){return new it(t)}static setErrorLevel(t){z.v(t)}static get version(){return"0.2.0"}}const Qt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),Zt=W.create,Kt=W.setErrorLevel,qt=W.version;E.TextmodeCanvas=J,E.TextmodeErrorLevel=L,E.TextmodeFont=K,E.TextmodeGrid=q,E.Textmodifier=it,E.create=Zt,E.export=Qt,E.setErrorLevel=Kt,E.textmode=W,E.version=qt,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):s((e=typeof globalThis<"u"?globalThis:e||self).textmode={});
12
+ `;return r.join(n)}}class $t extends H{jn(t,i){const r=this.Nn(i);this._n(t,r,"text/plain;charset=utf-8")}Nn(t){let i=this.mn(t);return i===".txt"||i.length<=4?this.vn():i}}class it{constructor(){l(this,"Wn");l(this,"In");l(this,"Un");this.Wn=new Wt,this.In=new Nt,this.Un=new $t}On(t){return{preserveTrailingSpaces:t.preserveTrailingSpaces??!1,lineEnding:t.lineEnding??"lf",emptyCharacter:t.emptyCharacter??" ",filename:t.filename||this.Un.vn()}}Xn(t,i={}){const r=this.On(i),n=this.Wn.Vn(this.Wn.ln(t.pipeline),t.grid,t.font,r.emptyCharacter);return this.In.Kn(n,r)}jn(t,i={}){this.Un.jn(this.Xn(t,i),i.filename)}}class kt extends X{Yn(t,i=1,r="transparent"){const n=t.canvas;if(i===1&&r==="transparent")return n;const o=document.createElement("canvas"),a=o.getContext("2d"),h=Math.round(n.width*i),u=Math.round(n.height*i);return o.width=h,o.height=u,r!=="transparent"&&(a.fillStyle=r,a.fillRect(0,0,h,u)),a.imageSmoothingEnabled=!1,a.drawImage(n,0,0,n.width,n.height,0,0,h,u),o}}class jt{qn(t,i){const r=this.Zn(i.format);return i.format==="png"?t.toDataURL(r):t.toDataURL(r,i.quality)}async Qn(t,i){return new Promise((r,n)=>{const o=this.Zn(i.format),a=h=>{h?r(h):n(Error(`Failed to generate ${i.format.toUpperCase()} blob`))};i.format==="png"?t.toBlob(a,o):t.toBlob(a,o,i.quality)})}Zn(t){switch(t){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+t)}}}const Xt={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},st={png:".png",jpg:".jpg",webp:".webp"};class Ht extends H{Jn(t,i,r){this.eo(t,this.mn(i)+st[r])}eo(t,i){const r=URL.createObjectURL(t);try{const n=document.createElement("a");n.href=r,n.download=i,n.style.display="none",n.rel="noopener",document.body.appendChild(n),n.click(),document.body.removeChild(n)}finally{URL.revokeObjectURL(r)}}so(t){return t in Xt&&t in st}}class Yt{constructor(){l(this,"Wn");l(this,"In");l(this,"Un");this.Wn=new kt,this.In=new jt,this.Un=new Ht}On(t){return{format:t.format??"png",quality:t.quality??1,scale:t.scale??1,backgroundColor:t.backgroundColor??"transparent",filename:t.filename||this.Un.vn()}}io(t){if(!this.Un.so(t.format))throw Error(`Saving '${t.format}' files is not supported`);if(t.quality<0||t.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(t.scale<=0)throw Error("Scale factor must be greater than 0");t.format==="jpg"&&t.backgroundColor==="transparent"&&(t.backgroundColor="black")}async Qn(t,i){if(i.scale===1&&i.backgroundColor==="transparent")return await this.In.Qn(t.canvas,i);const r=this.Wn.Yn(t,i.scale,i.backgroundColor);return await this.In.Qn(r,i)}async Jn(t,i={}){const r=this.On(i);this.io(r);const n=await this.Qn(t,r);this.Un.Jn(n,r.filename,r.format)}}const Vt=c=>class extends c{ro(){this.Pt.Dt(this.no)}toString(t={}){return this.ro(),new it().Xn({pipeline:this.oo,grid:this.Lr,font:this.Ri},t)}saveStrings(t={}){this.ro(),new it().jn({pipeline:this.oo,grid:this.Lr,font:this.Ri},t)}toSVG(t={}){return this.ro(),new et().Hn({pipeline:this.oo,grid:this.Lr,font:this.Ri},t)}saveSVG(t={}){this.ro(),new et().Dn({pipeline:this.oo,grid:this.Lr,font:this.Ri},t)}async saveCanvas(t={}){await new Yt().Jn(this.ji,t)}},Kt=c=>class extends c{async loadFont(t){return this.Ri.Ui(t).then(()=>{const i=this.Ri.maxGlyphDimensions;this.Lr.Yi(i.width,i.height),this.oo.resize(this.Lr.cols,this.Lr.rows),this.Pt.Us(),this.ao.Zr()})}fontSize(t){if(!B.M(typeof t=="number"&&t>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:t})||this.Ri.fontSize===t)return;this.Ri.Ii(t);const i=this.Ri.maxGlyphDimensions;this.Lr.Yi(i.width,i.height),this.oo.resize(this.Lr.cols,this.Lr.rows),this.Pt.Us(),this.ao.Zr()}},Zt=c=>class extends c{get frameCount(){return this.ho.frameCount}set frameCount(t){this.ho.frameCount=t}frameRate(t){return t===void 0?this.ho.currentFrameRate:this.ho.frameRate(t,()=>this.co())}noLoop(){this.ho.pause()}loop(){this.ho.resume(()=>this.co())}redraw(t=1){if(B.M(typeof t=="number"&&t>0&&Number.isInteger(t),"Redraw count must be a positive integer.",{method:"redraw",providedValue:t}))for(let i=0;i<t;i++)this.co()}isLooping(){return this.ho.isLooping}},qt=c=>class extends c{constructor(...t){super(...t)}mouseClicked(t){this.ao.nn(t)}mousePressed(t){this.ao.Sr(t)}mouseReleased(t){this.ao.Fr(t)}mouseMoved(t){this.ao.an(t)}mouseScrolled(t){this.ao.hn(t)}get mouse(){return this.ao.cn()}},Qt=c=>class extends c{constructor(...t){super(...t)}keyPressed(t){this.lo.Sr(t)}keyReleased(t){this.lo.Fr(t)}isKeyPressed(t){return this.lo.zr(t)}clearKeyStates(){this.lo.Er()}get lastKeyPressed(){return this.lo.kr()}get lastKeyReleased(){return this.lo.Gr()}get pressedKeys(){return this.lo.Tr()}get modifierState(){return this.lo.Ar()}};class Jt{constructor(){l(this,"Pt");l(this,"Ri");l(this,"ji");l(this,"Lr");l(this,"ho");l(this,"ao");l(this,"lo");l(this,"no");l(this,"oo");l(this,"uo")}co(){}}class rt extends function(i,...r){return r.reduce((n,o)=>o(n),i)}(Jt,Dt,Vt,Kt,Zt,qt,Qt){constructor(i={}){super();l(this,"fo",!1);l(this,"do",()=>{});l(this,"_o",()=>{});l(this,"po",()=>{});l(this,"mo");this.ji=new tt(i),this.Pt=new Et(this.ji.tr()),this.Ri=new Q(this.Pt,i.fontSize??16),this.ho=new Mt(i.frameRate??60),this.ao=new Bt(this.ji),this.lo=new Ut,this.no=this.Pt.Bt(),this.uo=this.Pt.re(),this.vo(i)}async vo(i){await this.Ri.Bi(i.fontSource);const r=this.Ri.maxGlyphDimensions;this.Lr=new J(this.ji.canvas,r.width,r.height),this.ao.Bi(this.Lr),this.oo=this.Pt.Ds(this.Lr.cols,this.Lr.rows,5),this.yo(),this.do(),this.ho.start(()=>this.co())}yo(){this.mo=()=>{this.po()},window.addEventListener("resize",this.mo),this.ao.wr(),this.lo.wr(),window.addEventListener("blur",()=>{this.lo.Er()})}co(){if(this.ho.measureFrameRate(),this.ho.incrementFrame(),this.fo)return;this.oo.begin(),this.Pt.Ss(this.no),this._o(),this.Pt.Dt(this.no),this.oo.end();const i=this.Pt.state.canvasBackgroundColor;this.Pt.Ue(i[0],i[1],i[2],i[3]),this.Pt.Ss(this.uo),this.uo.qt({a:this.Ri.fontFramebuffer,b:[this.Ri.textureColumns,this.Ri.textureRows],c:this.oo.textures[0],d:this.oo.textures[1],e:this.oo.textures[2],f:this.oo.textures[4],g:this.oo.textures[3],h:[this.Lr.cols,this.Lr.rows],i:[this.Lr.width,this.Lr.height],j:[this.Lr.offsetX,this.Lr.offsetY],k:this.Lr.width/this.Lr.height}),this.Pt.Gs(this.Lr.offsetX,this.Lr.offsetY,this.Lr.width,this.Lr.height)}setup(i){this.do=i}draw(i){this._o=i}windowResized(i){this.po=i}resizeCanvas(i,r){this.ji.Ji(i,r),this.Lr.rt(),this.oo.resize(this.Lr.cols,this.Lr.rows),this.Pt.Us(),this.ao.Zr(),this.co()}destroy(){this.fo||(this.ho.stop(),window.removeEventListener("resize",this.mo),this.ao.Mr(),this.lo.Mr(),this.Ri.Ut(),this.Pt.Ut(),this.fo=!0)}get grid(){return this.Lr}get font(){return this.Ri}get width(){return this.ji.width}get height(){return this.ji.height}get canvas(){return this.ji.canvas}get isDisposed(){return this.fo}get drawFramebuffer(){return this.oo}}class ${constructor(){}static create(t={}){return new rt(t)}static setErrorLevel(t){B.S(t)}static get version(){return"0.2.1-beta.2"}}const te=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),ee=$.create,ie=$.setErrorLevel,se=$.version;b.GLFramebuffer=G,b.TextmodeCanvas=tt,b.TextmodeErrorLevel=L,b.TextmodeFont=Q,b.TextmodeGrid=J,b.Textmodifier=rt,b.create=ee,b.export=te,b.setErrorLevel=ie,b.textmode=$,b.version=se,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):s((e=typeof globalThis<"u"?globalThis:e||self).textmode={});
@@ -0,0 +1,14 @@
1
+ export interface ShaderData {
2
+ sourceCode: string;
3
+ originalCode?: string;
4
+ uniforms: Record<string, {
5
+ variableName: string;
6
+ variableType: string;
7
+ }>;
8
+ consts: Record<string, {
9
+ variableName: string;
10
+ variableType: string;
11
+ }>;
12
+ }
13
+ declare const shaderData: ShaderData;
14
+ export default shaderData;
@@ -0,0 +1,14 @@
1
+ export interface ShaderData {
2
+ sourceCode: string;
3
+ originalCode?: string;
4
+ uniforms: Record<string, {
5
+ variableName: string;
6
+ variableType: string;
7
+ }>;
8
+ consts: Record<string, {
9
+ variableName: string;
10
+ variableType: string;
11
+ }>;
12
+ }
13
+ declare const shaderData: ShaderData;
14
+ export default shaderData;
@@ -0,0 +1,14 @@
1
+ export interface ShaderData {
2
+ sourceCode: string;
3
+ originalCode?: string;
4
+ uniforms: Record<string, {
5
+ variableName: string;
6
+ variableType: string;
7
+ }>;
8
+ consts: Record<string, {
9
+ variableName: string;
10
+ variableType: string;
11
+ }>;
12
+ }
13
+ declare const shaderData: ShaderData;
14
+ export default shaderData;
@@ -0,0 +1,5 @@
1
+ export { default as frag_ascii } from './frag/ascii.ts';
2
+ export { default as frag_copy_mrt } from './frag/copy-mrt.ts';
3
+ export { default as frag_instanced_ascii_mrt } from './frag/instanced-ascii-mrt.ts';
4
+ export { default as vert_instanced_ascii_mrt } from './vert/instanced-ascii-mrt.ts';
5
+ export { default as vert_shader } from './vert/shader.ts';
@@ -0,0 +1,14 @@
1
+ export interface ShaderData {
2
+ sourceCode: string;
3
+ originalCode?: string;
4
+ uniforms: Record<string, {
5
+ variableName: string;
6
+ variableType: string;
7
+ }>;
8
+ consts: Record<string, {
9
+ variableName: string;
10
+ variableType: string;
11
+ }>;
12
+ }
13
+ declare const shaderData: ShaderData;
14
+ export default shaderData;
@@ -0,0 +1,14 @@
1
+ export interface ShaderData {
2
+ sourceCode: string;
3
+ originalCode?: string;
4
+ uniforms: Record<string, {
5
+ variableName: string;
6
+ variableType: string;
7
+ }>;
8
+ consts: Record<string, {
9
+ variableName: string;
10
+ variableType: string;
11
+ }>;
12
+ }
13
+ declare const shaderData: ShaderData;
14
+ export default shaderData;
@@ -25,12 +25,6 @@ export declare class SVGContentGenerator {
25
25
  * @returns Background rectangle SVG string or empty string
26
26
  */
27
27
  $generateBackground(gridInfo: TextmodeGrid, options: SVGGenerationOptions): string;
28
- /**
29
- * Converts RGBA object to CSS color string
30
- * @param color RGBA color object
31
- * @returns CSS color string
32
- */
33
- private _rgbaToColorString;
34
28
  /**
35
29
  * Generates SVG transform attribute string
36
30
  * @param cellData Cell data with transform information
@@ -1,9 +1,11 @@
1
1
  import { Textmode } from './Textmode';
2
2
  export { Textmodifier } from './textmode/Textmodifier';
3
3
  export { TextmodeFont } from './textmode/font';
4
+ export { GLFramebuffer } from './rendering';
4
5
  export { TextmodeCanvas } from './textmode/Canvas';
5
6
  export { TextmodeGrid } from './textmode/Grid';
6
7
  export type { TextmodeOptions } from './textmode/Textmodifier';
8
+ export type { UserFramebufferOptions } from './textmode/mixins/RenderingMixin';
7
9
  export type { TextmodeCharacter } from './textmode/font';
8
10
  /** All types related to export options for different formats. */
9
11
  export * as export from './export';
@@ -1,3 +1,5 @@
1
1
  export { GLShader as Shader } from './webgl/Shader';
2
2
  export { GLRenderer } from './webgl/Renderer';
3
3
  export { GLFramebuffer } from './webgl/Framebuffer';
4
+ export type { ShaderData, ShaderSource } from './webgl/types/ShaderTypes';
5
+ export { normalizeShaderData, getShaderCode } from './webgl/types/ShaderTypes';
@@ -1,3 +1,4 @@
1
+ import type { GLRenderer } from './Renderer';
1
2
  export type FramebufferOptions = {
2
3
  /** Texture filtering mode */
3
4
  filter?: 'nearest' | 'linear';
@@ -25,7 +26,10 @@ export declare class GLFramebuffer {
25
26
  private _attachmentCount;
26
27
  private _previousState;
27
28
  private _attachmentPixels;
28
- constructor(gl: WebGL2RenderingContext, width: number, height?: number, attachmentCount?: number, options?: FramebufferOptions);
29
+ private _renderer;
30
+ private _isolatedState;
31
+ private _stateForFBO;
32
+ constructor(gl: WebGL2RenderingContext, width: number, height?: number, attachmentCount?: number, options?: FramebufferOptions, renderer?: GLRenderer | null, isolatedState?: boolean);
29
33
  private _createTextures;
30
34
  private _attachTextures;
31
35
  /**
@@ -36,22 +40,20 @@ export declare class GLFramebuffer {
36
40
  /**
37
41
  * Resize the framebuffer
38
42
  */
39
- $resize(width: number, height: number): void;
43
+ resize(width: number, height: number): void;
40
44
  /**
41
45
  * Read pixels from a specific color attachment into an RGBA Uint8Array.
42
46
  * Rows are flipped to top-left origin to match row-major iteration in exporters.
43
47
  */
44
48
  $readAttachment(attachmentIndex: number): Uint8Array;
45
- /** Read and cache all attachments. */
46
- $readAll(): void;
47
49
  /**
48
50
  * Begin rendering to this framebuffer
49
51
  */
50
- $begin(): void;
52
+ begin(): void;
51
53
  /**
52
54
  * End rendering to this framebuffer and restore previous state
53
55
  */
54
- $end(): void;
56
+ end(): void;
55
57
  /**
56
58
  * Dispose of WebGL resources used by this framebuffer.
57
59
  * This method is idempotent and safe to call multiple times.
@@ -65,6 +67,4 @@ export declare class GLFramebuffer {
65
67
  get texture(): WebGLTexture;
66
68
  get textures(): WebGLTexture[];
67
69
  get attachmentCount(): number;
68
- /** Return a cached copy of pixels for an attachment if previously read, else null. */
69
- getAttachmentPixels(attachmentIndex: number): Uint8Array | null;
70
70
  }
@@ -5,7 +5,7 @@
5
5
  export interface InstanceData {
6
6
  position: [number, number];
7
7
  size: [number, number];
8
- character: [number, number, number];
8
+ _character: [number, number, number];
9
9
  primaryColor: [number, number, number, number];
10
10
  secondaryColor: [number, number, number, number];
11
11
  rotation: [number, number];