textmode.js 0.1.9 → 0.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +4 -4
  2. package/dist/textmode.esm.js +1431 -1480
  3. package/dist/textmode.esm.min.js +1491 -1540
  4. package/dist/textmode.umd.js +19 -56
  5. package/dist/textmode.umd.min.js +19 -56
  6. package/dist/types/Textmode.d.ts +10 -38
  7. package/dist/types/export/base/DataExtractor.d.ts +3 -3
  8. package/dist/types/export/image/ImageExporter.d.ts +4 -11
  9. package/dist/types/export/image/types.d.ts +2 -3
  10. package/dist/types/export/svg/SVGExporter.d.ts +1 -1
  11. package/dist/types/export/svg/types.d.ts +1 -0
  12. package/dist/types/export/txt/TXTExporter.d.ts +1 -1
  13. package/dist/types/export/txt/types.d.ts +2 -2
  14. package/dist/types/index.d.ts +1 -7
  15. package/dist/types/rendering/index.d.ts +0 -1
  16. package/dist/types/rendering/webgl/DrawQueue.d.ts +26 -0
  17. package/dist/types/rendering/webgl/Framebuffer.d.ts +41 -40
  18. package/dist/types/rendering/webgl/InstanceBatch.d.ts +91 -0
  19. package/dist/types/rendering/webgl/InstanceData.d.ts +65 -0
  20. package/dist/types/rendering/webgl/RenderPipeline.d.ts +15 -0
  21. package/dist/types/rendering/webgl/RenderState.d.ts +76 -0
  22. package/dist/types/rendering/webgl/Renderer.d.ts +54 -81
  23. package/dist/types/rendering/webgl/Shader.d.ts +11 -16
  24. package/dist/types/rendering/webgl/VAOManager.d.ts +15 -0
  25. package/dist/types/rendering/webgl/geometries/Arc.d.ts +16 -0
  26. package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +35 -29
  27. package/dist/types/rendering/webgl/geometries/BezierCurve.d.ts +22 -0
  28. package/dist/types/rendering/webgl/geometries/Ellipse.d.ts +20 -0
  29. package/dist/types/rendering/webgl/geometries/Line.d.ts +13 -4
  30. package/dist/types/rendering/webgl/geometries/Rectangle.d.ts +13 -8
  31. package/dist/types/rendering/webgl/geometries/Triangle.d.ts +20 -0
  32. package/dist/types/rendering/webgl/geometries/index.d.ts +4 -1
  33. package/dist/types/rendering/webgl/index.d.ts +17 -1
  34. package/dist/types/rendering/webgl/types/DrawCommand.d.ts +9 -0
  35. package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +144 -0
  36. package/dist/types/rendering/webgl/types/RenderTypes.d.ts +12 -0
  37. package/dist/types/textmode/AnimationController.d.ts +81 -0
  38. package/dist/types/textmode/Canvas.d.ts +18 -19
  39. package/dist/types/textmode/Grid.d.ts +1 -34
  40. package/dist/types/textmode/Textmodifier.d.ts +36 -277
  41. package/dist/types/textmode/font/CharacterColorMapper.d.ts +3 -3
  42. package/dist/types/textmode/font/TextmodeFont.d.ts +6 -11
  43. package/dist/types/textmode/font/types.d.ts +1 -1
  44. package/dist/types/textmode/font/typr/types.d.ts +1 -1
  45. package/dist/types/textmode/font/utils/index.d.ts +0 -1
  46. package/dist/types/textmode/mixins/AnimationMixin.d.ts +120 -0
  47. package/dist/types/textmode/mixins/ExportMixin.d.ts +4 -6
  48. package/dist/types/textmode/mixins/FontMixin.d.ts +4 -10
  49. package/dist/types/textmode/mixins/RenderingMixin.d.ts +224 -246
  50. package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +13 -4
  51. package/dist/types/textmode/mixins/index.d.ts +2 -2
  52. package/package.json +1 -1
  53. package/dist/types/ColorPalette.d.ts +0 -35
  54. package/dist/types/rendering/core/Framebuffer.d.ts +0 -140
  55. package/dist/types/rendering/core/Shader.d.ts +0 -59
  56. package/dist/types/rendering/core/index.d.ts +0 -2
  57. package/dist/types/textmode/ConversionPipeline.d.ts +0 -110
  58. package/dist/types/textmode/converters/BrightnessConverter.d.ts +0 -58
  59. package/dist/types/textmode/converters/Converter.d.ts +0 -69
  60. package/dist/types/textmode/converters/FeatureConverter.d.ts +0 -128
  61. package/dist/types/textmode/converters/index.d.ts +0 -3
  62. package/dist/types/textmode/font/utils/FontConstants.d.ts +0 -60
  63. package/dist/types/textmode/mixins/ConversionMixin.d.ts +0 -62
@@ -1,64 +1,27 @@
1
- var jt=Object.defineProperty;var Zt=(w,v,M)=>v in w?jt(w,v,{enumerable:!0,configurable:!0,writable:!0,value:M}):w[v]=M;var c=(w,v,M)=>Zt(w,typeof v!="symbol"?v+"":v,M);var t,e;t=this,e=function(w){class v extends Error{constructor(r,s={}){super(v.i(r,s)),this.name="TextmodeError"}static i(r,s){let i=r;if(s&&Object.keys(s).length>0){i+=`
1
+ var Qt=Object.defineProperty;var te=(T,C,S)=>C in T?Qt(T,C,{enumerable:!0,configurable:!0,writable:!0,value:S}):T[C]=S;var u=(T,C,S)=>te(T,typeof C!="symbol"?C+"":C,S);var t,e;t=this,e=function(T){class C extends Error{constructor(s,r={}){super(C.i(s,r)),this.name="TextmodeError"}static i(s,r){let i=s;if(r&&Object.keys(r).length>0){i+=`
2
2
 
3
- 📋 Context:`;for(const[o,n]of Object.entries(s))i+=`
4
- - ${o}: ${v.o(n)}`}return i+=`
3
+ 📋 Context:`;for(const[n,o]of Object.entries(r))i+=`
4
+ - ${n}: ${C.o(o)}`}return i+=`
5
5
 
6
6
  `,i+="↓".repeat(24)+`
7
- `,i}static o(r){if(r===null)return"null";if(r===void 0)return"undefined";if(typeof r=="string")return`"${r}"`;if(typeof r=="number"||typeof r=="boolean")return r+"";if(Array.isArray(r))return r.length===0?"[]":r.length<=5?`[${r.map(s=>v.o(s)).join(", ")}]`:`[${r.slice(0,3).map(s=>v.o(s)).join(", ")}, ... +${r.length-3} more]`;if(typeof r=="object"){const s=Object.keys(r);return s.length===0?"{}":s.length<=3?`{ ${s.map(i=>`${i}: ${v.o(r[i])}`).join(", ")} }`:`{ ${s.slice(0,2).map(i=>`${i}: ${v.o(r[i])}`).join(", ")}, ... +${s.length-2} more }`}return r+""}}var M=(l=>(l[l.SILENT=0]="SILENT",l[l.WARNING=1]="WARNING",l[l.ERROR=2]="ERROR",l[l.THROW=3]="THROW",l))(M||{});const D=class D{constructor(){c(this,"l",{globalLevel:3})}static u(){return D.h||(D.h=new D),D.h}p(r,s){const i="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",o="color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";switch(this.l.globalLevel){case 0:return!1;case 1:return console.group(i,o),console.warn(v.i(r,s)),console.groupEnd(),!1;case 2:return console.group(i,o),console.error(v.i(r,s)),console.groupEnd(),!1;default:throw new v(r,s)}}m(r,s,i){return!!r||(this.p(s,i),!1)}_(r){this.l.globalLevel=r}};c(D,"h",null);let z=D;const _=z.u(),Z=new WeakMap;function O(l,r){Z.set(l,r)}function Y(l){return Z.get(l)}class q{constructor(r,s=r,i={}){c(this,"v");c(this,"C");c(this,"l");c(this,"$",null);this.v=r,this.C=s,this.l={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...i}}get width(){return this.v}get height(){return this.C}get pixels(){return this.$}get options(){return{...this.l}}validateCoordinates(r,s,i=!0){return(r<0||s<0||r>=this.v||s>=this.C)&&i&&console.warn("The x and y values passed to Framebuffer.get are outside of its range and will be clamped."),[Math.max(0,Math.min(r,this.v-1)),Math.max(0,Math.min(s,this.C-1))]}validateRegion(r,s,i,o){return[r=Math.max(0,Math.min(r,this.v-1)),s=Math.max(0,Math.min(s,this.C-1)),i=Math.max(1,Math.min(i,this.v-r)),o=Math.max(1,Math.min(o,this.C-s))]}updateDimensions(r,s){this.v=r,this.C=s,this.$=null}}class K extends q{constructor(s,i,o=i,n={}){super(i,o,n);c(this,"F");c(this,"M");c(this,"S");c(this,"D",null);this.F=s,this.S=this.R(),this.M=s.createFramebuffer(),this.V()}I(s){const{F:i}=this,o=i.getParameter(i.FRAMEBUFFER_BINDING);i.bindFramebuffer(i.FRAMEBUFFER,this.M);try{return s()}finally{i.bindFramebuffer(i.FRAMEBUFFER,o)}}R(){const{F:s}=this,i=s.createTexture();s.bindTexture(s.TEXTURE_2D,i);const o=this.l.filter==="linear"?s.LINEAR:s.NEAREST,n=this.l.wrap==="repeat"?s.REPEAT:s.CLAMP_TO_EDGE;return s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,o),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,o),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,n),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,n),this.k(),i}k(){const{F:s}=this,i=this.l.type==="float"?s.FLOAT:s.UNSIGNED_BYTE;s.texImage2D(s.TEXTURE_2D,0,s.RGBA,this.v,this.C,0,s.RGBA,i,null)}V(){const{F:s}=this;s.bindFramebuffer(s.FRAMEBUFFER,this.M),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,this.S,0),s.bindFramebuffer(s.FRAMEBUFFER,null)}P(s){const{F:i}=this;i.bindTexture(i.TEXTURE_2D,this.S),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,1),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,s),i.bindTexture(i.TEXTURE_2D,null)}updatePixels(s,i,o){const{F:n}=this;n.bindTexture(n.TEXTURE_2D,this.S),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,i,o,0,n.RGBA,n.UNSIGNED_BYTE,s),n.bindTexture(n.TEXTURE_2D,null)}resize(s,i){const{F:o}=this;this.updateDimensions(s,i),o.bindTexture(o.TEXTURE_2D,this.S),this.k(),o.bindTexture(o.TEXTURE_2D,null)}begin(){const{F:s}=this;this.D={framebuffer:s.getParameter(s.FRAMEBUFFER_BINDING),viewport:s.getParameter(s.VIEWPORT)},s.bindFramebuffer(s.FRAMEBUFFER,this.M),s.viewport(0,0,this.v,this.C),O(s,[0,0,this.v,this.C])}end(){if(!this.D)return;const{F:s}=this;s.bindFramebuffer(s.FRAMEBUFFER,this.D.framebuffer),s.viewport(...this.D.viewport),O(s,this.D.viewport),this.D=null}loadPixels(){const{F:s}=this;this.$||(this.$=new Uint8Array(this.v*this.C*4)),this.I(()=>{s.readPixels(0,0,this.v,this.C,s.RGBA,s.UNSIGNED_BYTE,this.$)})}get(s,i,o,n){const{F:a}=this;if(s===void 0&&i===void 0){const h=new Uint8Array(this.v*this.C*4);return this.I(()=>(a.readPixels(0,0,this.v,this.C,a.RGBA,a.UNSIGNED_BYTE,h),h))}if(o===void 0&&n===void 0){const[h,u]=this.validateCoordinates(s,i),d=new Uint8Array(4);return this.I(()=>(a.readPixels(h,u,1,1,a.RGBA,a.UNSIGNED_BYTE,d),[d[0],d[1],d[2],d[3]]))}{const[h,u,d,f]=this.validateRegion(s,i,o,n),p=new Uint8Array(d*f*4);return this.I(()=>(a.readPixels(h,u,d,f,a.RGBA,a.UNSIGNED_BYTE,p),p))}}A(){this.M&&this.F.deleteFramebuffer(this.M),this.S&&this.F.deleteTexture(this.S)}get framebuffer(){return this.M}get texture(){return this.S}}class Q{constructor(){c(this,"G",!1)}get isReady(){return this.G}setUniforms(r){for(const[s,i]of Object.entries(r))this.setUniform(s,i)}}class R extends Q{constructor(s,i,o){super();c(this,"F");c(this,"U");c(this,"L",new Map);c(this,"j",new Map);c(this,"O",0);c(this,"H");this.F=s,this.U=this.W(i,o),this.H=s.getParameter(s.MAX_TEXTURE_IMAGE_UNITS),this.N(),this.G=!0}static fromSource(s,i){return new R(s,i.vertex,i.fragment)}N(){const s=this.F.getProgramParameter(this.U,this.F.ACTIVE_UNIFORMS);for(let i=0;i<s;i++){const o=this.F.getActiveUniform(this.U,i);if(o){const n=this.F.getUniformLocation(this.U,o.name);n&&(this.L.set(o.name,n),this.j.set(o.name,o.type))}}}W(s,i){const o=this.X(this.F.VERTEX_SHADER,s),n=this.X(this.F.FRAGMENT_SHADER,i),a=this.F.createProgram();if(this.F.attachShader(a,o),this.F.attachShader(a,n),this.F.linkProgram(a),!this.F.getProgramParameter(a,this.F.LINK_STATUS)){const h=this.F.getProgramInfoLog(a);throw Error("Shader program link error: "+h)}return this.F.deleteShader(o),this.F.deleteShader(n),a}X(s,i){const o=this.F.createShader(s);if(this.F.shaderSource(o,i),this.F.compileShader(o),!this.F.getShaderParameter(o,this.F.COMPILE_STATUS)){const n=this.F.getShaderInfoLog(o);throw this.F.deleteShader(o),Error("Shader compilation error: "+n)}return o}q(){this.F.useProgram(this.U),this.Y()}Y(){this.O=0}setUniform(s,i){const o=this.L.get(s);if(o)if(typeof i=="number")this.Z(s)?this.F.uniform1i(o,Math.floor(i)):this.F.uniform1f(o,i);else if(typeof i=="boolean")this.F.uniform1i(o,i?1:0);else if(Array.isArray(i))switch(i.length){case 2:this.F.uniform2f(o,i[0],i[1]);break;case 3:this.F.uniform3f(o,i[0],i[1],i[2]);break;case 4:this.F.uniform4f(o,i[0],i[1],i[2],i[3]);break;default:console.warn(`Unsupported array length ${i.length} for uniform '${s}'`)}else if(i instanceof WebGLTexture){const n=this.J();this.F.uniform1i(o,n),this.F.activeTexture(this.F.TEXTURE0+n),this.F.bindTexture(this.F.TEXTURE_2D,i)}else if(i instanceof K){const n=this.J();this.F.uniform1i(o,n),this.F.activeTexture(this.F.TEXTURE0+n),this.F.bindTexture(this.F.TEXTURE_2D,i.texture)}else if(typeof i=="object"&&"texture"in i){const n=this.J();this.F.uniform1i(o,n),this.F.activeTexture(this.F.TEXTURE0+n),this.F.bindTexture(this.F.TEXTURE_2D,i.texture)}else console.warn(`Unsupported uniform type for '${s}':`,typeof i)}J(){return this.O>=this.H&&console.warn(`Exceeded maximum texture units (${this.H}). Texture may not render correctly.`),this.O++}Z(s){const i=this.j.get(s);return!!i&&(i===this.F.INT||i===this.F.INT_VEC2||i===this.F.INT_VEC3||i===this.F.INT_VEC4||i===this.F.SAMPLER_2D||i===this.F.SAMPLER_CUBE)}get glProgram(){return this.U}A(){this.F.deleteProgram(this.U)}}class J{constructor(r){c(this,"F");c(this,"K",null);c(this,"tt",16);c(this,"et",new Map);this.F=r}st(){if(this.K)return;const r=this.F;this.K=r.createBuffer(),r.bindBuffer(r.ARRAY_BUFFER,this.K)}rt(){const r=this.F,s=r.getParameter(r.CURRENT_PROGRAM);let i=this.et.get(s);return i||(i={a_position:r.getAttribLocation(s,"a_position"),a_texCoord:r.getAttribLocation(s,"a_texCoord")},this.et.set(s,i)),r.enableVertexAttribArray(i.a_position),r.vertexAttribPointer(i.a_position,2,r.FLOAT,!1,this.tt,0),r.enableVertexAttribArray(i.a_texCoord),r.vertexAttribPointer(i.a_texCoord,2,r.FLOAT,!1,this.tt,8),{positionLoc:i.a_position,texLoc:i.a_texCoord}}it(r,s){const i=this.F;i.disableVertexAttribArray(r),i.disableVertexAttribArray(s)}ot(r,s){const i=this.F,o=Y(i)||[0,0,i.canvas.width,i.canvas.height];return{nx:r/o[2]*2-1,ny:1-s/o[3]*2}}nt(r,s,i,o){const n=this.F;this.st(),n.bindBuffer(n.ARRAY_BUFFER,this.K);const a=new Float32Array([r,o,0,0,i,o,1,0,r,s,0,1,r,s,0,1,i,o,1,0,i,s,1,1]);n.bufferData(n.ARRAY_BUFFER,a,n.DYNAMIC_DRAW)}A(){this.K&&this.F.deleteBuffer(this.K)}}class ut extends J{constructor(r){super(r)}ht(r,s,i,o){const n=this.ot(r,s),a=this.ot(r+i,s+o);this.nt(n.nx,n.ny,a.nx,a.ny);const h=this.rt();this.F.drawArrays(this.F.TRIANGLES,0,6),this.it(h.positionLoc,h.texLoc)}lt(r,s,i,o,n){this.ht(r,s,i,n),this.ht(r+i-n,s,n,o),this.ht(r,s+o-n,i,n),this.ht(r,s,n,o)}}class dt extends J{constructor(r){super(r)}ct(r,s,i,o,n){const a=i-r,h=o-s,u=Math.hypot(a,h);if(u===0){const f=n/2,p=this.ot(r-f,s-f),g=this.ot(r+f,s+f);this.nt(p.nx,p.ny,g.nx,g.ny)}else{const f=-h/u,p=a/u,g=n/2,x=r+f*g,b=s+p*g,m=r-f*g,y=s-p*g,C=i+f*g,F=o+p*g,E=i-f*g,S=o-p*g,$=this.ot(x,b),U=this.ot(m,y),G=this.ot(C,F),ct=this.ot(E,S),B=this.F;this.st(),B.bindBuffer(B.ARRAY_BUFFER,this.K);const Xt=new Float32Array([$.nx,$.ny,0,0,U.nx,U.ny,0,1,G.nx,G.ny,1,0,U.nx,U.ny,0,1,ct.nx,ct.ny,1,1,G.nx,G.ny,1,0]);B.bufferData(B.ARRAY_BUFFER,Xt,B.DYNAMIC_DRAW)}const d=this.rt();this.F.drawArrays(this.F.TRIANGLES,0,6),this.it(d.positionLoc,d.texLoc)}}var L="attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;uniform float u_rotation;uniform vec2 u_center;uniform float u_aspectRatio;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){v_uv=a_texCoord;vec2 pos=a_position;pos-=u_center;pos.x*=u_aspectRatio;pos=rotate2D(-u_rotation)*pos;pos.x/=u_aspectRatio;pos+=u_center;gl_Position=vec4(pos,0.0,1.0);}";class ft{constructor(r){c(this,"F");c(this,"ut");c(this,"ft");c(this,"dt",null);c(this,"gt");c(this,"_t");c(this,"vt",[1,1,1,1]);c(this,"xt",!0);c(this,"bt",[0,0,0,1]);c(this,"wt",1);c(this,"Ct",!0);c(this,"yt",0);c(this,"$t",[]);this.F=r,this.ut=new R(this.F,L,"precision lowp float;uniform sampler2D u_texture;varying vec2 v_uv;void main(){gl_FragColor=texture2D(u_texture,v_uv);}"),this.ft=new R(this.F,L,"precision lowp float;uniform vec4 u_color;void main(){gl_FragColor=u_color;}"),this.gt=new ut(this.F),this._t=new dt(this.F),this.F.enable(this.F.BLEND),this.F.blendEquation(this.F.FUNC_ADD),this.F.blendFunc(this.F.ONE,this.F.ONE_MINUS_SRC_ALPHA),O(this.F,[0,0,this.F.canvas.width,this.F.canvas.height])}Ft(r){this.dt!==r&&(this.dt=r,r.q())}Tt(r,s,i,o){if(this.xt=!0,s===void 0&&i===void 0&&o===void 0){const n=r/255;this.vt=[n,n,n,1]}else if(i!==void 0&&o===void 0)this.vt=[r/255,s/255,i/255,1];else{if(i===void 0||o===void 0)throw Error("Invalid fill parameters. Use fill(gray), fill(r,g,b), or fill(r,g,b,a)");this.vt=[r/255,s/255,i/255,o/255]}}Mt(r,s,i,o){if(this.Ct=!0,s===void 0&&i===void 0&&o===void 0){const n=r/255;this.bt=[n,n,n,1]}else if(i!==void 0&&o===void 0)this.bt=[r/255,s/255,i/255,1];else{if(i===void 0||o===void 0)throw Error("Invalid stroke parameters. Use stroke(gray), stroke(r,g,b), or stroke(r,g,b,a)");this.bt=[r/255,s/255,i/255,o/255]}}St(r){if(r<0)throw Error("Stroke weight must be non-negative");this.wt=r}Dt(){this.Ct=!1}Rt(){this.xt=!1}Vt(r){this.yt=r}It(){this.$t.push({fillColor:[...this.vt],fillMode:this.xt,strokeColor:[...this.bt],strokeWeight:this.wt,strokeMode:this.Ct,rotation:this.yt})}kt(){const r=this.$t.pop();r?(this.vt=r.fillColor,this.xt=r.fillMode,this.bt=r.strokeColor,this.wt=r.strokeWeight,this.Ct=r.strokeMode,this.yt=r.rotation):console.warn("pop() called without matching push()")}Et(){this.dt=null,this.$t=[],this.yt=0}Pt(r){const s=r.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"").trim().match(/^#version\s+(\d+)\s+(es)?/i);return!!s&&parseInt(s[1],10)>=300}At(r,s){return new R(this.F,r,s)}zt(r){const s=this.Pt(r)?`#version 300 es
8
- in vec2 a_position;in vec2 a_texCoord;out vec2 v_uv;uniform float u_rotation;uniform vec2 u_center;uniform float u_aspectRatio;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){v_uv=a_texCoord;vec2 pos=a_position;pos-=u_center;pos.x*=u_aspectRatio;pos=rotate2D(-u_rotation)*pos;pos.x/=u_aspectRatio;pos+=u_center;gl_Position=vec4(pos,0.0,1.0);}`:L;return new R(this.F,s,r)}Gt(r,s){this.dt.setUniform(r,s)}Ut(r,s,i,o){if(this.dt!==null){const{centerX:p,centerY:g,radians:x,aspectRatio:b}=this.Lt(r,s,i,o);return this.Gt("u_rotation",x),this.Gt("u_center",[p,g]),this.Gt("u_aspectRatio",b),this.gt.ht(r,s,i,o),void(this.dt=null)}const n=this.ft;let a=0,h=0,u=0,d=1;const f=this.Lt(r,s,i,o);a=f.centerX,h=f.centerY,u=f.radians,d=f.aspectRatio,this.xt&&(this.Ft(n),this.Gt("u_color",this.vt),this.Gt("u_rotation",u),this.Gt("u_center",[a,h]),this.Gt("u_aspectRatio",d),this.gt.ht(r,s,i,o)),this.Ct&&this.wt>0&&(this.Ft(n),this.Gt("u_color",this.bt),this.Gt("u_rotation",u),this.Gt("u_center",[a,h]),this.Gt("u_aspectRatio",d),this.gt.lt(r,s,i,o,this.wt)),this.dt=null}jt(r,s,i,o){if(this.dt!==null){const m=(r+i)/2,y=(s+o)/2,C=Math.abs(i-r)||1,F=Math.abs(o-s)||1,{centerX:E,centerY:S,radians:$,aspectRatio:U}=this.Lt(m-C/2,y-F/2,C,F);this.Gt("u_rotation",$),this.Gt("u_center",[E,S]),this.Gt("u_aspectRatio",U);const G=this.wt>0?this.wt:1;return this._t.ct(r,s,i,o,G),void(this.dt=null)}if(!this.Ct||this.wt<=0)return;const n=this.ft,a=(r+i)/2,h=(s+o)/2,u=Math.abs(i-r)||1,d=Math.abs(o-s)||1,f=this.yt!==0;let p=0,g=0,x=0,b=1;if(f){const m=this.Lt(a-u/2,h-d/2,u,d);p=m.centerX,g=m.centerY,x=m.radians,b=m.aspectRatio}this.Ft(n),this.Gt("u_color",this.bt),f&&(this.Gt("u_rotation",x),this.Gt("u_center",[p,g]),this.Gt("u_aspectRatio",b)),this._t.ct(r,s,i,o,this.wt)}Lt(r,s,i,o){const n=Y(this.F)||[0,0,this.F.canvas.width,this.F.canvas.height],a=n[2],h=n[3],u=a/h;return{centerX:(r+i/2)/a*2-1,centerY:1-(s+o/2)/h*2,radians:this.yt*Math.PI/180,aspectRatio:u}}Ot(r,s,i={}){return new K(this.F,r,s,i)}Ht(r,s=r,i=r,o=255){this.Bt(r/255,s/255,i/255,o/255)}Bt(r=0,s=0,i=0,o=0){this.F.clearColor(r,s,i,o),this.F.clear(this.F.COLOR_BUFFER_BIT)}Wt(){this.F.viewport(0,0,this.F.canvas.width,this.F.canvas.height),O(this.F,[0,0,this.F.canvas.width,this.F.canvas.height])}get context(){return this.F}A(){this.ut.A(),this.ft.A(),this.gt.A(),this._t.A()}Nt(r,s,i,o,n){const a=this.F,h=o??r.width,u=n??r.height;this.Ft(this.ut),this.Gt("u_texture",r);const d=this.Lt(s,i,h,u);this.Gt("u_rotation",d.radians),this.Gt("u_center",[d.centerX,d.centerY]),this.Gt("u_aspectRatio",d.aspectRatio),this.gt.ht(s,i,h,u),a.bindTexture(a.TEXTURE_2D,null),this.dt=null}}const T={readShort:(l,r)=>(T.t.uint16[0]=l[r]<<8|l[r+1],T.t.int16[0]),readUshort:(l,r)=>l[r]<<8|l[r+1],readUshorts(l,r,s){const i=[];for(let o=0;o<s;o++)i.push(T.readUshort(l,r+2*o));return i},readUint(l,r){const s=T.t.uint8;return s[3]=l[r],s[2]=l[r+1],s[1]=l[r+2],s[0]=l[r+3],T.t.uint32[0]},readASCII(l,r,s){let i="";for(let o=0;o<s;o++)i+=String.fromCharCode(l[r+o]);return i},t:(()=>{const l=new ArrayBuffer(8);return{uint8:new Uint8Array(l),int16:new Int16Array(l),uint16:new Uint16Array(l),uint32:new Uint32Array(l)}})()},gt={parseTab(l,r,s){const i={tables:[],ids:{},off:r};l=new Uint8Array(l.buffer,r,s),r=0;const o=T,n=o.readUshort,a=n(l,r+=2);r+=2;const h=[];for(let u=0;u<a;u++){const d=n(l,r),f=n(l,r+=2);r+=2;const p=o.readUint(l,r);r+=4;const g=`p${d}e${f}`;let x=h.indexOf(p);if(x===-1){let b;x=i.tables.length,h.push(p);const m=n(l,p);b=m===4?this.parse4(l,p):m===12?this.parse12(l,p):{format:m},i.tables.push(b)}i.ids[g]!=null&&console.warn("Multiple tables for one platform+encoding: "+g),i.ids[g]=x}return i},parse4(l,r){const s=T,i=s.readUshort,o=s.readUshorts,n=r,a=i(l,r+=2);r+=2;const h=i(l,r+=2)>>>1,u={format:4,searchRange:i(l,r+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};r+=2,u.entrySelector=i(l,r),r+=2,u.rangeShift=i(l,r),r+=2,u.endCount=o(l,r,h),r+=2*h,r+=2,u.startCount=o(l,r,h),r+=2*h;for(let d=0;d<h;d++)u.idDelta.push(s.readShort(l,r)),r+=2;return u.idRangeOffset=o(l,r,h),r+=2*h,u.glyphIdArray=o(l,r,n+a-r>>1),u},parse12(l,r){const s=T.readUint;s(l,r+=4),s(l,r+=4);const i=s(l,r+=4);r+=4;const o=new Uint32Array(3*i);for(let n=0;n<3*i;n+=3)o[n]=s(l,r+(n<<2)),o[n+1]=s(l,r+(n<<2)+4),o[n+2]=s(l,r+(n<<2)+8);return{format:12,groups:o}}},pt={parseTab(l,r,s){const i=T;r+=18;const o=i.readUshort(l,r);r+=2,r+=16;const n=i.readShort(l,r);r+=2;const a=i.readShort(l,r);r+=2;const h=i.readShort(l,r);r+=2;const u=i.readShort(l,r);return r+=2,r+=6,{unitsPerEm:o,xMin:n,yMin:a,xMax:h,yMax:u,indexToLocFormat:i.readShort(l,r)}}},mt={parseTab(l,r,s){const i=T;r+=4;const o=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],n={};for(let a=0;a<o.length;a++){const h=o[a],u=h==="advanceWidthMax"||h==="numberOfHMetrics"?i.readUshort:i.readShort;n[h]=u(l,r+2*a)}return n}},bt={parseTab(l,r,s,i){if(!i)throw Error("Font object required for hmtx parsing");const o=T,n=[],a=[],h=i.maxp.numGlyphs,u=i.hhea.numberOfHMetrics;let d=0,f=0,p=0;for(;p<u;)d=o.readUshort(l,r+(p<<2)),f=o.readShort(l,r+(p<<2)+2),n.push(d),a.push(f),p++;for(;p<h;)n.push(d),a.push(f),p++;return{aWidth:n,lsBearing:a}}},tt={cmap:gt,head:pt,hhea:mt,maxp:{parseTab(l,r,s){const i=T;return i.readUint(l,r),r+=4,{numGlyphs:i.readUshort(l,r)}}},hmtx:bt,loca:{parseTab(l,r,s,i){if(!i)throw Error("Font object required for loca parsing");const o=T,n=[],a=i.head.indexToLocFormat,h=i.maxp.numGlyphs+1;if(a===0)for(let u=0;u<h;u++)n.push(o.readUshort(l,r+(u<<1))<<1);else if(a===1)for(let u=0;u<h;u++)n.push(o.readUint(l,r+(u<<2)));return n}},glyf:{parseTab(l,r,s,i){if(!i)throw Error("Font object required for glyf parsing");const o=[],n=i.maxp.numGlyphs;for(let a=0;a<n;a++)o.push(null);return o},Xt(l,r){const s=T,i=l.qt,o=l.loca;if(o[r]===o[r+1])return null;const n=A.findTable(i,"glyf",l.Yt);if(!n)return null;let a=n[0]+o[r];const h={};if(h.noc=s.readShort(i,a),a+=2,h.xMin=s.readShort(i,a),a+=2,h.yMin=s.readShort(i,a),a+=2,h.xMax=s.readShort(i,a),a+=2,h.yMax=s.readShort(i,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(s.readUshort(i,a)),a+=2;const u=s.readUshort(i,a);if(a+=2,i.length-a<u)return null;a+=u;const d=h.endPts[h.noc-1]+1;h.flags=[];for(let g=0;g<d;g++){const x=i[a];if(a++,h.flags.push(x),8&x){const b=i[a];a++;for(let m=0;m<b;m++)h.flags.push(x),g++}}h.xs=[];for(let g=0;g<d;g++){const x=h.flags[g],b=!!(16&x);2&x?(h.xs.push(b?i[a]:-i[a]),a++):b?h.xs.push(0):(h.xs.push(s.readShort(i,a)),a+=2)}h.ys=[];for(let g=0;g<d;g++){const x=h.flags[g],b=!!(32&x);4&x?(h.ys.push(b?i[a]:-i[a]),a++):b?h.ys.push(0):(h.ys.push(s.readShort(i,a)),a+=2)}let f=0,p=0;for(let g=0;g<d;g++)f+=h.xs[g],p+=h.ys[g],h.xs[g]=f,h.ys[g]=p}else h.parts=[],h.endPts=[],h.flags=[],h.xs=[],h.ys=[];return h}}},A={parse:l=>[((r,s,i,o)=>{const n=tt,a={qt:r,Qt:s,Yt:i};for(const h in n){const u=h,d=A.findTable(r,u,i);if(d){const[f,p]=d;let g=o[f];g==null&&(g=n[u].parseTab(r,f,p,a),o[f]=g),a[u]=g}}return a})(new Uint8Array(l),0,0,{})],findTable(l,r,s){const i=T,o=i.readUshort(l,s+4);let n=s+12;for(let a=0;a<o;a++){const h=i.readASCII(l,n,4);i.readUint(l,n+4);const u=i.readUint(l,n+8),d=i.readUint(l,n+12);if(h===r)return[u,d];n+=16}return null},T:tt,B:T};class k{constructor(){c(this,"Zt",new Map);c(this,"Jt",new Map)}Kt(r,s){const i=`${this.te(r)}_${s}`;if(this.Zt.has(i))return this.Zt.get(i);const o=r.cmap;if(!o||!o.tables)return this.Zt.set(i,0),0;let n=0;for(const a of o.tables)if(a.format===4?n=this.ee(s,a):a.format===12&&(n=this.se(s,a)),n>0)break;return this.Zt.set(i,n),n}re(r,s){const i=s.codePointAt(0);return i===void 0?0:this.Kt(r,i)}ie(r,s){const i=r.hmtx;return i&&i.aWidth&&i.aWidth.length!==0?s<i.aWidth.length?i.aWidth[s]:i.aWidth[i.aWidth.length-1]:0}oe(r,s){const i=s/r.head.unitsPerEm,o=r.hhea.ascender*i,n=r.hhea.descender*i,a=r.hhea.lineGap*i;return{ascender:o,descender:n,lineGap:a,lineHeight:o-n+a,unitsPerEm:r.head.unitsPerEm,scale:i}}ne(){this.Zt.clear(),this.Jt.clear()}te(r){return`${r.Yt}_${r.qt.length}`}ee(r,s){const i=s.endCount.length;let o=-1;for(let n=0;n<i;n++)if(r<=s.endCount[n]){o=n;break}if(o===-1||r<s.startCount[o])return 0;if(s.idRangeOffset[o]===0)return r+s.idDelta[o]&65535;{const n=s.idRangeOffset[o]/2+(r-s.startCount[o])-(i-o);if(n>=0&&n<s.glyphIdArray.length){const a=s.glyphIdArray[n];return a===0?0:a+s.idDelta[o]&65535}}return 0}se(r,s){const i=s.groups.length/3;for(let o=0;o<i;o++){const n=s.groups[3*o],a=s.groups[3*o+1],h=s.groups[3*o+2];if(r>=n&&r<=a)return h+(r-n)}return 0}}class xt{constructor(r){c(this,"ae");this.ae=r}he(r){var i;const s=[];return(i=r==null?void 0:r.cmap)!=null&&i.tables?(r.cmap.tables.forEach(o=>{if(o.format===4){const n=this.le(o);s.push(...n)}else if(o.format===12){const n=this.ce(o);s.push(...n)}}),[...new Set(s)]):[]}ue(r,s){return this.ae.re(r,s)>0}fe(r,s){for(const i of s)if(!this.ue(r,i))return!1;return!0}de(r,s){return s.filter(i=>this.ue(r,i))}pe(r){return r.filter(s=>this.me(s))}le(r){const s=[];if(!(r.startCount&&r.endCount&&r.idRangeOffset&&r.idDelta))return s;for(let i=0;i<r.startCount.length;i++){const o=r.startCount[i],n=r.endCount[i];if(o!==65535||n!==65535){for(let a=o;a<=n;a++)if(this.ge(r,a,i)>0)try{const h=String.fromCodePoint(a);s.push(h)}catch{}}}return s}ce(r){const s=[];if(!r.groups)return s;for(let i=0;i<r.groups.length;i+=3){const o=r.groups[i],n=r.groups[i+1],a=r.groups[i+2];for(let h=o;h<=n;h++)if(a+(h-o)>0)try{const u=String.fromCodePoint(h);s.push(u)}catch{}}return s}ge(r,s,i){if(r.idRangeOffset[i]===0)return s+r.idDelta[i]&65535;{const o=r.idRangeOffset[i]/2+(s-r.startCount[i])-(r.startCount.length-i);if(o>=0&&r.glyphIdArray&&o<r.glyphIdArray.length){const n=r.glyphIdArray[o];if(n!==0)return n+r.idDelta[i]&65535}}return 0}me(r){const s=r.codePointAt(0)||0;return!(s>=0&&s<=31&&s!==9&&s!==10&&s!==13||s>=127&&s<=159)}}class vt{constructor(){c(this,"_e");const r=new k;this._e=new xt(r)}extractCharacters(r){return this._e.he(r)}filterProblematicCharacters(r){return this._e.pe(r)}characterExists(r,s){return this._e.ue(r,s)}allCharactersExist(r,s){return this._e.fe(r,s)}}class wt{constructor(r){c(this,"ve");c(this,"xe");c(this,"be");c(this,"we");this.be=r,this.we=new k,this.ve=document.createElement("canvas"),this.xe=this.ve.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(r,s,i,o){const n=r.length,a=Math.ceil(Math.sqrt(n)),h=Math.ceil(n/a),u=s.width*a,d=s.height*h,f=typeof o=="object"?o:null;this.Ce(u,d),this.ye(r,s,a,i,f);const p=this.be.Ot(u,d,{filter:"nearest"});return p.P(this.ve),{framebuffer:p,columns:a,rows:h}}Ce(r,s){this.ve.width=r,this.ve.height=s,this.ve.style.width=r+"px",this.ve.style.height=r+"px",this.xe.imageSmoothingEnabled=!1,this.ve.style.imageRendering="pixelated",this.xe.fillStyle="black",this.xe.fillRect(0,0,r,s),this.xe.textBaseline="top",this.xe.textAlign="left",this.xe.fillStyle="white"}ye(r,s,i,o,n){const a=o/n.head.unitsPerEm;for(let h=0;h<r.length;h++){const u=h%i,d=Math.floor(h/i),f=r[h].character,p=this.$e(n,f);if(!p)continue;const g=f.codePointAt(0)||0,x=this.we.Kt(n,g),b=this.Fe(n,x)*a,m=u*s.width,y=d*s.height,C=m+.5*s.width,F=y+.5*s.height,E=Math.round(C-.5*s.width),S=Math.round(F-.5*o),$=E+.5*(s.width-b),U=S+n.hhea.ascender*a;this.Te(p,$,U,a)}}$e(r,s){const i=s.codePointAt(0)||0,o=this.we.Kt(r,i);if(o===0)return null;if(r.glyf&&r.glyf[o]!==null)return r.glyf[o];if(A&&A.T&&A.T.glyf){const n=A.T.glyf.Xt(r,o);return r.glyf&&n&&(r.glyf[o]=n),n}return null}Fe(r,s){const i=r.hmtx;return i&&i.aWidth?s<i.aWidth.length?i.aWidth[s]:i.aWidth[i.aWidth.length-1]:0}Te(r,s,i,o){if(!r||!r.xs||r.noc===0)return;const{xs:n,ys:a,endPts:h,flags:u}=r;if(!(n&&a&&h&&u))return;this.xe.beginPath();let d=0;for(let f=0;f<h.length;f++){const p=h[f];if(!(p<d)){if(p>=d){const g=s+n[d]*o,x=i-a[d]*o;this.xe.moveTo(g,x);let b=d+1;for(;b<=p;)if(1&u[b]){const m=s+n[b]*o,y=i-a[b]*o;this.xe.lineTo(m,y),b++}else{const m=s+n[b]*o,y=i-a[b]*o;let C=b+1>p?d:b+1;if(1&u[C]){const F=s+n[C]*o,E=i-a[C]*o;this.xe.quadraticCurveTo(m,y,F,E),b=C+1}else{const F=(m+(s+n[C]*o))/2,E=(y+(i-a[C]*o))/2;this.xe.quadraticCurveTo(m,y,F,E),b=C}}this.xe.closePath()}d=p+1}}this.xe.fill()}}class _t{constructor(){c(this,"ae");this.ae=new k}calculateMaxGlyphDimensions(r,s,i){let o=0;const n=this.ae.oe(i,s),a=n.lineHeight;for(const h of r){const u=this.ae.re(i,h);if(u===0)continue;const d=this.ae.ie(i,u)*n.scale;o=Math.max(o,d)}return{width:Math.ceil(o),height:Math.ceil(a)}}getCharacterAdvanceWidth(r,s,i){const o=this.ae.oe(i,s),n=this.ae.re(i,r);return this.ae.ie(i,n)*o.scale}getFontMetrics(r,s){return this.ae.oe(s,r)}ne(){this.ae.ne()}}class Ct{constructor(){c(this,"we");this.we=new k}createCharacterObjects(r,s){return r.map((i,o)=>{const n=i.codePointAt(0)||0,a=this.Me(o);let h=0;if(s.hmtx&&s.hmtx.aWidth){const u=this.we.Kt(s,n);u>0&&s.hmtx.aWidth[u]!==void 0&&(h=s.hmtx.aWidth[u])}return{character:i,unicode:n,color:a,advanceWidth:h}})}Me(r){return[r%256,Math.floor(r/256)%256,Math.floor(r/65536)%256]}getCharacterColor(r,s){if(!_.m(typeof r=="string","Character must be a string.",{method:"getCharacterColor",providedValue:r}))return[0,0,0];const i=s.find(o=>o.character===r);return i?i.color:[0,0,0]}getCharacterColors(r,s){return _.m(typeof r=="string"&&r.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:r})?Array.from(r).map(i=>this.getCharacterColor(i,s)||[0,0,0]):[[0,0,0]]}}class et{constructor(r,s=16){c(this,"Se");c(this,"De",[]);c(this,"Re");c(this,"Ve",16);c(this,"Ie",0);c(this,"ke",0);c(this,"Ee",{width:0,height:0});c(this,"Pe");c(this,"Ae","UrsaFont");c(this,"ze");c(this,"Ge");c(this,"Ue");c(this,"Le");this.Ve=s,this.ze=new vt,this.Ge=new wt(r),this.Ue=new _t,this.Le=new Ct}async je(r){let s;if(!r)throw new v("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const i=await fetch(r);if(!i.ok)throw new v(`Failed to load font file: ${i.status} ${i.statusText}`);s=await i.arrayBuffer()}await this.Oe(s),this.Se=A.parse(s)[0],await this.He()}Be(r){if(r===void 0)return this.Ve;this.Ve=r,this.Ee=this.Ue.calculateMaxGlyphDimensions(this.De.map(i=>i.character),this.Ve,this.Se);const s=this.Ge.createTextureAtlas(this.De,this.Ee,this.Ve,this.Se);this.Re=s.framebuffer,this.Ie=s.columns,this.ke=s.rows}async We(r){try{const s=await fetch(r);if(!s.ok)throw new v(`Failed to load font file: ${s.status} ${s.statusText}`);const i=await s.arrayBuffer();await this.Oe(i);const o=A.parse(i);if(!o||o.length===0)throw Error("Failed to parse font file");this.Se=o[0],await this.He()}catch(s){throw new v("Failed to load font: "+(s instanceof Error?s.message:"Unknown error"),s)}}async Oe(r){const s=Date.now();this.Ae=this.Ae==="UrsaFont"?"UrsaFont":"CustomFont_"+s,this.Pe=new FontFace(this.Ae,r),await this.Pe.load(),document.fonts.add(this.Pe)}async He(){const r=this.ze.extractCharacters(this.Se),s=this.ze.filterProblematicCharacters(r);this.De=this.Le.createCharacterObjects(s,this.Se),this.Ee=this.Ue.calculateMaxGlyphDimensions(s,this.Ve,this.Se);const i=this.Ge.createTextureAtlas(this.De,this.Ee,this.Ve,this.Se);this.Re=i.framebuffer,this.Ie=i.columns,this.ke=i.rows}getCharacterColor(r){return this.Le.getCharacterColor(r,this.De)}getCharacterColors(r){return this.Le.getCharacterColors(r,this.De)}hasAllCharacters(r){if(typeof r!="string"||r.length===0)return!1;const s=new Set(this.De.map(i=>i.character));for(const i of r)if(!s.has(i))return!1;return!0}A(){this.Re.A(),document.fonts.delete(this.Pe)}get fontFramebuffer(){return this.Re}get characters(){return this.De}get textureColumns(){return this.Ie}get textureRows(){return this.ke}get maxGlyphDimensions(){return this.Ee}get fontSize(){return this.Ve}get font(){return this.Se}}class rt{constructor(r,s,i){c(this,"Ne");c(this,"Xe");c(this,"v");c(this,"C");c(this,"qe");c(this,"Ye");c(this,"Qe",!1);c(this,"Ze");c(this,"Je");c(this,"Ke");this.Ze=r,this.Je=s,this.Ke=i,this.Et()}Et(){this.Qe||(this.Ne=Math.floor(this.Ze.width/this.Je),this.Xe=Math.floor(this.Ze.height/this.Ke)),this.ts()}ts(){this.v=this.Ne*this.Je,this.C=this.Xe*this.Ke,this.qe=Math.floor((this.Ze.width-this.v)/2),this.Ye=Math.floor((this.Ze.height-this.C)/2)}es(r,s){this.Je=r,this.Ke=s,this.Et()}ss(r,s){this.Qe=!0,this.Ne=r,this.Xe=s,this.ts()}rs(){this.Qe=!1,this.Et()}ns(){this.Qe?this.ts():this.Et()}hs(r){if(r===void 0)return this.Qe;this.Qe=r}get cellWidth(){return this.Je}get cellHeight(){return this.Ke}get cols(){return this.Ne}get rows(){return this.Xe}get width(){return this.v}get height(){return this.C}get offsetX(){return this.qe}get offsetY(){return this.Ye}}class st{constructor(r,s=!1,i={}){c(this,"Ze");c(this,"ls");c(this,"cs");c(this,"us");c(this,"onTransformChange");this.ls=r,this.cs=s,this.Ze=this.fs(i.width,i.height),s&&this.setupTransformObserver()}fs(r,s){var o;const i=document.createElement("canvas");if(i.className="textmodeCanvas",i.style.imageRendering="pixelated",this.cs)i.width=r||800,i.height=s||600,document.body.appendChild(i);else{const n=this.ls.getBoundingClientRect();let a=Math.round(n.width),h=Math.round(n.height);if(this.ls instanceof HTMLVideoElement){const f=this.ls;(a===0||h===0)&&f.videoWidth>0&&f.videoHeight>0&&(a=f.videoWidth,h=f.videoHeight)}i.width=a,i.height=h,i.style.position="absolute",i.style.pointerEvents="none";const u=window.getComputedStyle(this.ls);let d=parseInt(u.zIndex||"0",10);isNaN(d)&&(d=0),i.style.zIndex=""+(d+1),this.ds(i),(o=this.ls.parentNode)==null||o.insertBefore(i,this.ls.nextSibling)}return i}ds(r){const s=this.ls.getBoundingClientRect();let i=this.ls.offsetParent;if(i&&i!==document.body){const o=i.getBoundingClientRect();r.style.top=s.top-o.top+"px",r.style.left=s.left-o.left+"px"}else r.style.top=s.top+window.scrollY+"px",r.style.left=s.left+window.scrollX+"px"}ns(r,s){if(this.cs)this.Ze.width=r??this.Ze.width,this.Ze.height=s??this.Ze.height;else{const i=this.ls.getBoundingClientRect();let o=Math.round(i.width),n=Math.round(i.height);if(this.ls instanceof HTMLVideoElement){const a=this.ls;(o===0||n===0)&&a.videoWidth>0&&a.videoHeight>0&&(o=a.videoWidth,n=a.videoHeight)}this.Ze.width=o,this.Ze.height=n,this.ds(this.Ze)}}ps(){const r={alpha:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"},s=this.Ze.getContext("webgl2",r)||this.Ze.getContext("webgl",r);if(!s)throw new v("WebGL context could not be created. Ensure your browser supports WebGL.");return s}setupTransformObserver(){this.us=new ResizeObserver(r=>{for(const s of r){const i=s.contentRect;!this.onTransformChange||Math.round(i.width)===this.Ze.width&&Math.round(i.height)===this.Ze.height||this.onTransformChange()}}),this.us.observe(this.Ze)}A(){this.us&&this.us.disconnect();const r=this.Ze.getContext("webgl")||this.Ze.getContext("webgl2");if(r){const s=r.getExtension("WEBGL_lose_context");s&&s.loseContext()}this.Ze.parentNode&&this.Ze.parentNode.removeChild(this.Ze)}get canvas(){return this.Ze}get width(){return this.Ze.width}get height(){return this.Ze.height}}class P{constructor(r,s,i,o={}){c(this,"be");c(this,"gs");c(this,"_s");c(this,"vs");c(this,"bs");c(this,"ws");c(this,"Cs");c(this,"$s");c(this,"l");this.be=r,this.gs=s,this._s=i,this.l={enabled:!0,...o};const n=this._s.cols,a=this._s.rows;this.vs=this.be.Ot(n,a),this.bs=this.be.Ot(n,a),this.ws=this.be.Ot(n,a),this.Cs=this.be.Ot(n,a),this.$s=this.be.Ot(n,a)}ns(){const r=this._s.cols,s=this._s.rows;this.vs.resize(r,s),this.bs.resize(r,s),this.ws.resize(r,s),this.Cs.resize(r,s),this.$s.resize(r,s)}enabled(r){_.m(typeof r=="boolean"||typeof r=="number"&&Number.isInteger(r),"Enabled must be a boolean value or an integer (0 for false, any other number for true).",{method:"enabled",providedValue:r})&&(this.l.enabled=!!r)}enable(){this.enabled(!0)}disable(){this.enabled(!1)}A(){this.vs.A(),this.bs.A(),this.ws.A(),this.Cs.A(),this.$s.A()}get characterFramebuffer(){return this.vs}get primaryColorFramebuffer(){return this.bs}get secondaryColorFramebuffer(){return this.ws}get rotationFramebuffer(){return this.Cs}get transformFramebuffer(){return this.$s}get options(){return this.l}}class it{constructor(r,s){c(this,"M");c(this,"be");c(this,"Fs");this.be=r,this.Fs=s;const i=Math.max(this.Fs.length,1);this.M=this.be.Ot(i,1),this.Ts()}Ts(){const r=this.Fs.length;this.M.width!==r&&this.M.resize(r,1);const s=new Uint8Array(1*r*4);for(let i=0;i<r;i++){const o=this.Fs[i],n=4*i;s[n]=o[0],s[n+1]=o[1],s[n+2]=o[2],s[n+3]=255}this.M.updatePixels(s,r,1)}setColors(r){this.Fs=r,this.Ts()}get colors(){return this.Fs}get framebuffer(){return this.M}}class N extends P{constructor(s,i,o,n={}){super(s,i,o,{enabled:!0,characters:" .:-=+*%@#",characterColor:[1,1,1,1],characterColorMode:"sampled",cellColor:[0,0,0,1],cellColorMode:"fixed",invert:!1,rotation:[0,0,0,1],flipHorizontally:!1,flipVertically:!1,...n});c(this,"Ms");this.Ms=new it(this.be,this.gs.getCharacterColors(" .:-=+*%@#"))}characters(s){_.m(this.gs.hasAllCharacters(s),"One or more characters do not exist in the current font.",{method:"characters",providedValue:s})&&(this.l.characters=s,this.Ms.setColors(this.gs.getCharacterColors(s)))}characterColor(s,i,o,n=255){const a=this.Ss(s,"characterColor",i,o,n);a&&(this.l.characterColor=a)}characterColorMode(s){this.Ds(s,"characterColorMode")}cellColor(s,i,o,n=255){const a=this.Ss(s,"cellColor",i,o,n);a&&(this.l.cellColor=a)}cellColorMode(s){this.Ds(s,"cellColorMode")}invert(s){this.Rs(s,"invert","Invert")}rotation(s){if(!_.m(typeof s=="number","Rotation angle must be a number.",{method:"rotation",providedValue:s}))return;(s%=360)<0&&(s+=360);const i=255*s/360,o=Math.floor(i)/255,n=Math.round(i-o);this.l.rotation=[o,n,0,1]}flipHorizontally(s){this.Rs(s,"flipHorizontally","Flip horizontally")}flipVertically(s){this.Rs(s,"flipVertically","Flip vertically")}Ss(s,i,o,n,a=255){let h,u,d,f;if(typeof s=="string"){const p=this.Vs(s);if(!p)return _.m(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:i,providedValue:s}),null;[h,u,d,f]=p}else if(h=s,u=o!==void 0?o:s,d=n!==void 0?n:s,f=a,!_.m([h,u,d,f].every(p=>p>=0&&p<=255),i.charAt(0).toUpperCase()+i.slice(1)+" color values must be between 0 and 255",{method:i,providedValues:{r:h,g:u,b:d,a:f}}))return null;return[h/255,u/255,d/255,f/255]}Ds(s,i){_.m(["sampled","fixed"].includes(s),"Invalid color mode. Must be 'sampled' or 'fixed'.",{method:i,providedValue:s})&&(this.l[i]=s)}Rs(s,i,o){_.m(typeof s=="boolean"||typeof s=="number"&&Number.isInteger(s),o+" must be a boolean value or an integer (0 for false, any other number for true).",{method:i,providedValue:s})&&(this.l[i]=!!s)}Vs(s){return s=s.replace(/^#/,""),/^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(s)?(s.length===3&&(s=s.split("").map(i=>i+i).join("")),[parseInt(s.slice(0,2),16),parseInt(s.slice(2,4),16),parseInt(s.slice(4,6),16),255]):null}}const I=`attribute vec2 a_position;\r
9
- attribute vec2 a_texCoord;\r
10
- varying vec2 v_uv;\r
11
- \r
12
- uniform float u_rotation; // rotation angle in radians\r
13
- uniform vec2 u_center; // rotation center in normalized coordinates\r
14
- uniform float u_aspectRatio; // canvas width / canvas height\r
15
- \r
16
- mat2 rotate2D(float angle) {\r
17
- float s = sin(angle);\r
18
- float c = cos(angle);\r
19
- return mat2(c, -s, s, c);\r
20
- }\r
21
- \r
22
- void main() {\r
23
- v_uv = a_texCoord;\r
24
- \r
25
- // Use the position directly (it's already in normalized device coordinates)\r
26
- vec2 pos = a_position;\r
27
- \r
28
- // Translate to origin for rotation\r
29
- pos -= u_center;\r
30
- \r
31
- // Correct for aspect ratio: scale X coordinate to make space square\r
32
- pos.x *= u_aspectRatio;\r
33
- \r
34
- // Rotate in corrected space\r
35
- // Negate rotation to make positive values rotate clockwise (like p5.js)\r
36
- pos = rotate2D(-u_rotation) * pos;\r
37
- \r
38
- // Restore aspect ratio: scale X coordinate back\r
39
- pos.x /= u_aspectRatio;\r
40
- \r
41
- // Translate back from origin\r
42
- pos += u_center;\r
43
- \r
44
- gl_Position = vec4(pos, 0.0, 1.0);\r
45
- }\r
46
- `,ot={enabled:!0,characters:" .:-=+*%@#",characterColor:[1,1,1,1],characterColorMode:"sampled",cellColor:[0,0,0,1],cellColorMode:"fixed",invert:!1,rotation:[0,0,0,255],flipHorizontally:!1,flipVertically:!1,brightnessRange:[0,255]};class H extends N{constructor(s,i,o){super(s,i,o,ot);c(this,"Is");c(this,"ks");c(this,"Es");c(this,"Ps");c(this,"As");c(this,"zs");this.Is=new R(s.context,I,"precision lowp float;uniform sampler2D u_sketchTexture;uniform vec2 u_gridCellDimensions;uniform vec2 u_brightnessRange;varying vec2 v_uv;void main(){vec2 cellCenter=(floor(v_uv*u_gridCellDimensions)+vec2(0.5))/u_gridCellDimensions;vec4 color=texture2D(u_sketchTexture,cellCenter);float brightness=dot(color.rgb,vec3(0.299,0.587,0.114));float brightnessValue=brightness*255.0;if(brightnessValue>=u_brightnessRange.x&&brightnessValue<=u_brightnessRange.y){gl_FragColor=color;}else{gl_FragColor=vec4(0.0);}}"),this.ks=new R(s.context,I,"precision lowp float;uniform sampler2D u_sampleTexture;uniform vec4 u_fillColor;uniform bool u_useFixedColor;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){if(u_useFixedColor){gl_FragColor=u_fillColor;}else{gl_FragColor=sampleColor;}}else{gl_FragColor=vec4(0.0);}}"),this.Ps=new R(s.context,I,"precision lowp float;uniform sampler2D u_sampleTexture;uniform bool u_invert;uniform bool u_flipHorizontally;uniform bool u_flipVertically;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){float invertValue=u_invert ? 1.0 : 0.0;float flipHValue=u_flipHorizontally ? 1.0 : 0.0;float flipVValue=u_flipVertically ? 1.0 : 0.0;gl_FragColor=vec4(invertValue,flipHValue,flipVValue,1.0);}else{gl_FragColor=vec4(0.0);}}"),this.As=new R(s.context,I,"precision lowp float;uniform sampler2D u_sampleTexture;uniform vec4 u_rotationColor;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){gl_FragColor=u_rotationColor;}else{gl_FragColor=vec4(0.0);}}"),this.Es=new R(s.context,I,"precision lowp float;uniform sampler2D u_colorSampleFramebuffer;uniform sampler2D u_charPaletteTexture;uniform vec2 u_charPaletteSize;uniform vec2 u_brightnessRange;varying vec2 v_uv;void main(){vec4 color=texture2D(u_colorSampleFramebuffer,v_uv);if(color.a==0.0){gl_FragColor=vec4(0.0);return;}float brightness=dot(color.rgb,vec3(0.299,0.587,0.114))*255.0;vec2 range=u_brightnessRange;if(brightness<range.x||brightness>range.y){gl_FragColor=vec4(0.0);return;}float t=(brightness-range.x)/(range.y-range.x);float idx=clamp(floor(t*u_charPaletteSize.x),0.0,u_charPaletteSize.x-1.0);vec3 charColor=texture2D(u_charPaletteTexture,vec2((idx+0.5)/u_charPaletteSize.x,0.0)).rgb;gl_FragColor=vec4(charColor,1.0);}"),this.zs=this.be.Ot(this._s.cols,this._s.rows)}Gs(s){const i=this._s.cols,o=this._s.rows;this.zs.begin(),this.be.Bt(),this.be.Ft(this.Is),this.be.Gt("u_sketchTexture",s),this.be.Gt("u_gridCellDimensions",[i,o]),this.be.Gt("u_brightnessRange",this.l.brightnessRange),this.be.Ut(0,0,i,o),this.zs.end(),this.bs.begin(),this.be.Bt(),this.be.Ft(this.ks),this.be.Gt("u_sampleTexture",this.zs),this.be.Gt("u_fillColor",this.l.characterColor),this.be.Gt("u_useFixedColor",this.l.characterColorMode==="fixed"),this.be.Ut(0,0,i,o),this.bs.end(),this.ws.begin(),this.be.Bt(),this.be.Ft(this.ks),this.be.Gt("u_sampleTexture",this.zs),this.be.Gt("u_fillColor",this.l.cellColor),this.be.Gt("u_useFixedColor",this.l.cellColorMode==="fixed"),this.be.Ut(0,0,i,o),this.ws.end(),this.$s.begin(),this.be.Bt(),this.be.Ft(this.Ps),this.be.Gt("u_sampleTexture",this.zs),this.be.Gt("u_invert",this.l.invert),this.be.Gt("u_flipHorizontally",this.l.flipHorizontally),this.be.Gt("u_flipVertically",this.l.flipVertically),this.be.Ut(0,0,i,o),this.$s.end(),this.Cs.begin(),this.be.Bt(),this.be.Ft(this.As),this.be.Gt("u_sampleTexture",this.zs),this.be.Gt("u_rotationColor",this.l.rotation),this.be.Ut(0,0,i,o),this.Cs.end(),this.vs.begin(),this.be.Bt(),this.be.Ft(this.Es),this.be.Gt("u_colorSampleFramebuffer",this.zs),this.be.Gt("u_charPaletteTexture",this.Ms.framebuffer),this.be.Gt("u_charPaletteSize",[this.Ms.colors.length,1]),this.be.Gt("u_brightnessRange",this.l.brightnessRange),this.be.Ut(0,0,i,o),this.vs.end()}ns(){super.ns(),this.zs.resize(this._s.cols,this._s.rows)}brightnessRange(s){_.m(Array.isArray(s)&&s.length===2&&s.every(i=>typeof i=="number"&&i>=0&&i<=255),"Brightness range must be an array of two numbers between 0 and 255.",{method:"brightnessRange",providedValue:s})&&(this.l.brightnessRange=s)}}const Ft=Object.freeze(Object.defineProperty({__proto__:null,BRIGHTNESS_DEFAULT_OPTIONS:ot,TextmodeBrightnessConverter:H,TextmodeConverter:P,TextmodeFeatureConverter:N},Symbol.toStringTag,{value:"Module"}));class nt{constructor(r,s,i){c(this,"be");c(this,"Se");c(this,"_s");c(this,"Us");c(this,"Ls");c(this,"js");c(this,"Os");c(this,"Hs");c(this,"vs");c(this,"bs");c(this,"ws");c(this,"Cs");c(this,"$s");this.be=r,this.Se=s,this._s=i,this.Hs=this.be.At(L,"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 sampler2D u_captureTexture;uniform vec2 u_captureDimensions;uniform int u_backgroundMode;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;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_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);if(encodedIndexVec.a<0.01){gl_FragColor=(u_backgroundMode==0)? vec4(0.0):texture2D(u_captureTexture,gl_FragCoord.xy/u_captureDimensions);return;}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.Ls=new H(r,s,i),this.js=new P(r,s,i),this.Us=[this.Ls,this.js],this.vs=this.be.Ot(i.cols,i.rows),this.bs=this.be.Ot(i.cols,i.rows),this.ws=this.be.Ot(i.cols,i.rows),this.Cs=this.be.Ot(i.cols,i.rows),this.$s=this.be.Ot(i.cols,i.rows),this.Os=this.be.Ot(this._s.width,this._s.height)}Bs(r){for(const i of this.Us)i.options.enabled&&i instanceof N&&i.Gs(r);const s=(i,o)=>{i.begin(),this.be.Bt();for(const n of this.Us)n.options.enabled&&this.be.Nt(o(n),0,0);i.end()};s(this.vs,i=>i.characterFramebuffer),s(this.bs,i=>i.primaryColorFramebuffer),s(this.ws,i=>i.secondaryColorFramebuffer),s(this.Cs,i=>i.rotationFramebuffer),s(this.$s,i=>i.transformFramebuffer),this.Os.begin(),this.be.Bt(),this.be.Ft(this.Hs),this.be.Gt("u_characterTexture",this.Se.fontFramebuffer),this.be.Gt("u_charsetDimensions",[this.Se.textureColumns,this.Se.textureRows]),this.be.Gt("u_asciiCharacterTexture",this.vs),this.be.Gt("u_primaryColorTexture",this.bs),this.be.Gt("u_secondaryColorTexture",this.ws),this.be.Gt("u_transformTexture",this.$s),this.be.Gt("u_rotationTexture",this.Cs),this.be.Gt("u_captureTexture",r),this.be.Gt("u_backgroundMode",!1),this.be.Gt("u_captureDimensions",[r.width,r.height]),this.be.Gt("u_gridCellDimensions",[this._s.cols,this._s.rows]),this.be.Gt("u_gridPixelDimensions",[this._s.width,this._s.height]),this.be.Ut(0,0,this.Os.width,this.Os.height),this.Os.end()}add(r){if(!_.m(r==="brightness"||r==="custom",'Converter type must be either "brightness" or "custom".',{method:"add",providedValue:r}))return;let s;return s=r==="brightness"?new H(this.be,this.Se,this._s):new P(this.be,this.Se,this._s),this.Us.push(s),s}remove(r){if(!_.m(r instanceof P,"Parameter must be a TextmodeConverter instance.",{method:"remove",providedValue:r}))return;const s=this.Us.indexOf(r);_.m(s!==-1,"Converter instance not found in pipeline.",{method:"remove",providedValue:r,convertersCount:this.Us.length})&&this.Us.splice(s,1)}swap(r,s){const i=(h,u)=>{if(typeof h=="number")return _.m(Number.isInteger(h)&&h>=0&&h<this.Us.length,u+" index must be a valid integer within the converter array bounds.",{method:"swap",providedValue:h,convertersCount:this.Us.length})?h:null;if(h instanceof P){const d=this.Us.indexOf(h);return _.m(d!==-1,u+" converter instance not found in pipeline.",{method:"swap",providedValue:h,convertersCount:this.Us.length})?d:null}return _.m(!1,u+" parameter must be either an integer index or a TextmodeConverter instance.",{method:"swap",providedValue:h}),null},o=i(r,"First"),n=i(s,"Second");if(o===null||n===null||!_.m(o!==n,"Cannot swap a converter with itself.",{method:"swap",firstIndex:o,secondIndex:n}))return;const a=this.Us[o];this.Us[o]=this.Us[n],this.Us[n]=a}ns(){this.Os.resize(this._s.width,this._s.height);const r=this._s.cols,s=this._s.rows;this.vs.resize(r,s),this.bs.resize(r,s),this.ws.resize(r,s),this.Cs.resize(r,s),this.$s.resize(r,s);for(const i of this.Us)i.ns()}hasEnabledConverters(){return this.Us.some(r=>r.options.enabled)}disable(){for(const r of this.Us)r.disable()}enable(){for(const r of this.Us)r.enable()}A(){for(const r of this.Us)r.A();this.vs.A(),this.bs.A(),this.ws.A(),this.Cs.A(),this.$s.A(),this.Os.A(),this.Hs.A()}get texture(){return this.Os}get characterFramebuffer(){return this.vs}get primaryColorFramebuffer(){return this.bs}get secondaryColorFramebuffer(){return this.ws}get rotationFramebuffer(){return this.Cs}get transformFramebuffer(){return this.$s}get brightness(){return this.Ls}get custom(){return this.js}}const yt=l=>class extends l{fill(r,s,i,o){this.be.Tt(r,s,i,o)}stroke(r,s,i,o){this.be.Mt(r,s,i,o)}strokeWeight(r){this.be.St(r)}noStroke(){this.be.Dt()}noFill(){this.be.Rt()}rotate(r){this.be.Vt(r)}push(){this.be.It()}pop(){this.be.kt()}rect(r,s,i=1,o=1){this.be.Ut(r,s,i,o)}line(r,s,i,o){this.be.jt(r,s,i,o)}background(r,s=r,i=r,o=255){this.be.Ht(r,s,i,o)}createShader(r,s){return this.be.At(r,s)}createFilterShader(r){return this.be.zt(r)}shader(r){this.be.Ft(r)}setUniform(r,s){this.be.Gt(r,s)}image(r,s,i,o,n){this.be.Nt(r,s,i,o,n)}clear(){this.be.Bt()}createFramebuffer(r,s,i={}){return this.be.Ot(r,s,i)}};class W{Ws(r){const s=r.characterFramebuffer,i=r.primaryColorFramebuffer,o=r.secondaryColorFramebuffer,n=r.transformFramebuffer,a=r.rotationFramebuffer;return s==null||s.loadPixels(),i==null||i.loadPixels(),o==null||o.loadPixels(),n==null||n.loadPixels(),a==null||a.loadPixels(),{characterPixels:(s==null?void 0:s.pixels)||new Uint8Array(0),primaryColorPixels:(i==null?void 0:i.pixels)||new Uint8Array(0),secondaryColorPixels:(o==null?void 0:o.pixels)||new Uint8Array(0),transformPixels:(n==null?void 0:n.pixels)||new Uint8Array(0),rotationPixels:(a==null?void 0:a.pixels)||new Uint8Array(0)}}Ns(r,s){return r[s]+(r[s+1]<<8)}Xs(r,s){return{r:r[s],g:r[s+1],b:r[s+2],a:r[s+3]}}}class X{qs(r,s){return new Blob([r],{type:s})}Ys(r,s,i){try{const o=this.qs(r,i),n=URL.createObjectURL(o),a=document.createElement("a");a.href=n,a.download=s,a.style.display="none",a.rel="noopener",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(n)}catch(o){throw console.error("Failed to download file:",o),Error("File download failed: "+(o instanceof Error?o.message:"Unknown error"))}}Qs(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Zs(){const r=new Date;return{date:r.toISOString().split("T")[0],time:r.toTimeString().split(" ")[0].replace(/:/g,"-")}}Js(r){return r.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Ks(){return"'textmode-export'-"+this.Qs()}}class Tt extends W{tr(r,s,i){const o=r[i]===255,n=r[i+1]===255,a=r[i+2]===255,h=s[i],u=s[i+1];return{isInverted:o,flipHorizontal:n,flipVertical:a,rotation:Math.round(360*(h+u/255)/255*100)/100}}er(r,s,i){return{x:r,y:s,cellX:r*i.cellWidth,cellY:s*i.cellHeight}}sr(r,s){const i=[];let o=0;for(let n=0;n<s.rows;n++)for(let a=0;a<s.cols;a++){const h=4*o,u=this.Ns(r.characterPixels,h);let d=this.Xs(r.primaryColorPixels,h),f=this.Xs(r.secondaryColorPixels,h);const p=this.tr(r.transformPixels,r.rotationPixels,h);if(p.isInverted){const x=d;d=f,f=x}const g=this.er(a,n,s);i.push({charIndex:u,primaryColor:d,secondaryColor:f,transform:p,position:g}),o++}return i}}class Et{rr(r,s){const i=r.cmap;for(const o of i.tables)if(o.format===4){const n=o;for(let a=0;a<n.startCount.length;a++)if(s>=n.startCount[a]&&s<=n.endCount[a]){if(n.idRangeOffset[a]===0)return s+n.idDelta[a]&65535;{const h=n.idRangeOffset[a]/2+(s-n.startCount[a])-(n.startCount.length-a);if(h>=0&&h<n.glyphIdArray.length){const u=n.glyphIdArray[h];if(u!==0)return u+n.idDelta[a]&65535}}}}else if(o.format===12){const n=o;for(let a=0;a<n.groups.length;a+=3){const h=n.groups[a],u=n.groups[a+1],d=n.groups[a+2];if(s>=h&&s<=u)return d+(s-h)}}return 0}ir(r,s,i,o,n){const a=n/r.head.unitsPerEm;return{getBoundingBox:()=>({x1:i+s.xMin*a,y1:o+-s.yMax*a,x2:i+s.xMax*a,y2:o+-s.yMin*a}),toSVG:()=>this.nr(s,i,o,a)}}nr(r,s,i,o){if(!r||!r.xs)return"";const{xs:n,ys:a,endPts:h,flags:u}=r;if(!(n&&a&&h&&u))return"";let d="",f=0;for(let p=0;p<h.length;p++){const g=h[p];if(!(g<f)){if(g>=f){const x=s+n[f]*o,b=i-a[f]*o;d+=`M${x.toFixed(2)},${b.toFixed(2)}`;let m=f+1;for(;m<=g;)if(1&u[m]){const y=s+n[m]*o,C=i-a[m]*o;d+=`L${y.toFixed(2)},${C.toFixed(2)}`,m++}else{const y=s+n[m]*o,C=i-a[m]*o;let F=m+1>g?f:m+1;if(1&u[F]){const E=s+n[F]*o,S=i-a[F]*o;d+=`Q${y.toFixed(2)},${C.toFixed(2)} ${E.toFixed(2)},${S.toFixed(2)}`,m=F+1}else{const E=(y+(s+n[F]*o))/2,S=(C+(i-a[F]*o))/2;d+=`Q${y.toFixed(2)},${C.toFixed(2)} ${E.toFixed(2)},${S.toFixed(2)}`,m=F}}d+="Z"}f=g+1}}return d}ar(r,s,i,o,n){const a=r.codePointAt(0)||0,h=this.rr(s,a);let u=null;return s.glyf&&s.glyf[h]!==null?u=s.glyf[h]:(u=A.T.glyf.Xt(s,h),s.glyf[h]=u),this.ir(s,u,i,o,n)}hr(r,s,i,o,n,a,h,u){const d=i+(n-u*(h/s.head.unitsPerEm))/2,f=o+(a+.7*h)/2;return this.ar(r,s,d,f,h).toSVG()||null}}class Rt{constructor(){c(this,"lr");this.lr=new Et}cr(r){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
7
+ `,i}static o(s){if(s===null)return"null";if(s===void 0)return"undefined";if(typeof s=="string")return`"${s}"`;if(typeof s=="number"||typeof s=="boolean")return s+"";if(Array.isArray(s))return s.length===0?"[]":s.length<=5?`[${s.map(r=>C.o(r)).join(", ")}]`:`[${s.slice(0,3).map(r=>C.o(r)).join(", ")}, ... +${s.length-3} more]`;if(typeof s=="object"){const r=Object.keys(s);return r.length===0?"{}":r.length<=3?`{ ${r.map(i=>`${i}: ${C.o(s[i])}`).join(", ")} }`:`{ ${r.slice(0,2).map(i=>`${i}: ${C.o(s[i])}`).join(", ")}, ... +${r.length-2} more }`}return s+""}}var S=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(S||{});const D=class D{constructor(){u(this,"l",{globalLevel:3})}static u(){return D.h||(D.h=new D),D.h}p(s,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.l.globalLevel){case 0:return!1;case 1:return console.group(i,n),console.warn(C.i(s,r)),console.groupEnd(),!1;case 2:return console.group(i,n),console.error(C.i(s,r)),console.groupEnd(),!1;default:throw new C(s,r)}}_(s,r,i){return!!s||(this.p(r,i),!1)}m(s){this.l.globalLevel=s}};u(D,"h",null);let G=D;const M=G.u(),k=new WeakMap;function z(c,s){k.set(c,s)}function B(c){return k.get(c)}class X{constructor(s,r,i=r,n=1,o={}){u(this,"v");u(this,"C");u(this,"l");u(this,"$",null);u(this,"R");u(this,"M");u(this,"S",[]);u(this,"A");u(this,"P",null);u(this,"F",[]);this.v=r,this.C=i,this.l={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.R=s,this.A=Math.min(Math.max(1,n),8);const a=s.getParameter(s.MAX_DRAW_BUFFERS),h=s.getParameter(s.MAX_COLOR_ATTACHMENTS);this.A=Math.min(this.A,a,h),this.M=s.createFramebuffer(),this.G(),this.D(),this.F=Array(this.A).fill(null)}G(){const s=this.R,r=this.l.filter==="linear"?s.LINEAR:s.NEAREST,i=this.l.wrap==="repeat"?s.REPEAT:s.CLAMP_TO_EDGE,n=this.l.type==="float"?s.FLOAT:s.UNSIGNED_BYTE;for(let o=0;o<this.A;o++){const a=s.createTexture();s.bindTexture(s.TEXTURE_2D,a),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,r),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,r),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,i),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,i),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,this.v,this.C,0,s.RGBA,n,null),this.S.push(a)}s.bindTexture(s.TEXTURE_2D,null)}D(){const s=this.R;if(s.bindFramebuffer(s.FRAMEBUFFER,this.M),this.A===1)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,this.S[0],0);else{const i=[];for(let n=0;n<this.A;n++){const o=s.COLOR_ATTACHMENT0+n;s.framebufferTexture2D(s.FRAMEBUFFER,o,s.TEXTURE_2D,this.S[n],0),i.push(o)}s.drawBuffers(i)}const r=s.checkFramebufferStatus(s.FRAMEBUFFER);r!==s.FRAMEBUFFER_COMPLETE&&console.error("GLFramebuffer is not complete:",r),s.bindFramebuffer(s.FRAMEBUFFER,null)}I(s){const r=this.R;r.bindTexture(r.TEXTURE_2D,this.S[0]),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,1),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,s),r.bindTexture(r.TEXTURE_2D,null)}L(s,r){this.v=s,this.C=r,this.$=null,this.F=Array(this.A).fill(null);const i=this.R,n=this.l.type==="float"?i.FLOAT:i.UNSIGNED_BYTE;for(const o of this.S)i.bindTexture(i.TEXTURE_2D,o),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,this.v,this.C,0,i.RGBA,n,null);i.bindTexture(i.TEXTURE_2D,null)}W(s){const r=this.R;if(s<0||s>=this.A)throw Error(`GLFramebuffer: attachment index ${s} out of range (count=${this.A})`);const i=this.F[s];if(i)return i;const n=this.v,o=this.C,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+s),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 d=0;d<o;d++){const p=(o-1-d)*l,g=d*l;f.set(a.subarray(p,p+l),g)}return this.F[s]=f,f}k(){for(let s=0;s<this.A;s++)this.W(s)}V(){const s=this.R;this.P={framebuffer:s.getParameter(s.FRAMEBUFFER_BINDING),viewport:s.getParameter(s.VIEWPORT)},s.bindFramebuffer(s.FRAMEBUFFER,this.M),this.F=Array(this.A).fill(null);for(let r=0;r<this.A;r++)s.clearBufferfv(s.COLOR,r,new Float32Array([0,0,0,0]));s.viewport(0,0,this.v,this.C),z(s,[0,0,this.v,this.C])}O(){if(!this.P)return;const s=this.R;s.bindFramebuffer(s.FRAMEBUFFER,this.P.framebuffer),s.viewport(...this.P.viewport),z(s,this.P.viewport),this.P=null}U(){const s=this.R;this.M&&s.deleteFramebuffer(this.M);for(const r of this.S)s.deleteTexture(r);this.S=[],this.F=[]}get width(){return this.v}get height(){return this.C}get pixels(){return this.$}get options(){return{...this.l}}get framebuffer(){return this.M}get texture(){return this.S[0]}get textures(){return[...this.S]}get attachmentCount(){return this.A}getAttachmentPixels(s){return this.F[s]??null}}class et{constructor(s,r,i){u(this,"R");u(this,"j");u(this,"H",new Map);u(this,"q",new Map);u(this,"N",0);u(this,"X");this.R=s,this.j=this.Y(r,i),this.X=s.getParameter(s.MAX_TEXTURE_IMAGE_UNITS),this.Z()}Z(){const s=this.R.getProgramParameter(this.j,this.R.ACTIVE_UNIFORMS);for(let r=0;r<s;r++){const i=this.R.getActiveUniform(this.j,r);if(i){const n=this.R.getUniformLocation(this.j,i.name);n&&(this.H.set(i.name,n),this.q.set(i.name,i.type))}}}Y(s,r){const i=this.J(this.R.VERTEX_SHADER,s),n=this.J(this.R.FRAGMENT_SHADER,r),o=this.R.createProgram();if(this.R.attachShader(o,i),this.R.attachShader(o,n),this.R.linkProgram(o),!this.R.getProgramParameter(o,this.R.LINK_STATUS)){const a=this.R.getProgramInfoLog(o);throw Error("Shader program link error: "+a)}return this.R.deleteShader(i),this.R.deleteShader(n),o}J(s,r){const i=this.R.createShader(s);if(this.R.shaderSource(i,r),this.R.compileShader(i),!this.R.getShaderParameter(i,this.R.COMPILE_STATUS)){const n=this.R.getShaderInfoLog(i);throw this.R.deleteShader(i),Error("Shader compilation error: "+n)}return i}K(){this.R.useProgram(this.j),this.tt()}tt(){this.N=0}et(s){for(const[r,i]of Object.entries(s))this.st(r,i)}st(s,r){const i=this.H.get(s);if(i)if(typeof r=="number")this.R.uniform1f(i,r);else if(typeof r=="boolean")this.R.uniform1i(i,r?1:0);else if(Array.isArray(r))switch(r.length){case 2:this.R.uniform2f(i,r[0],r[1]);break;case 3:this.R.uniform3f(i,r[0],r[1],r[2]);break;case 4:this.R.uniform4f(i,r[0],r[1],r[2],r[3]);break;default:console.warn(`Unsupported array length ${r.length} for uniform '${s}'`)}else if(r instanceof WebGLTexture){const n=this.it();this.R.uniform1i(i,n),this.R.activeTexture(this.R.TEXTURE0+n),this.R.bindTexture(this.R.TEXTURE_2D,r)}else if(r instanceof X){const n=this.it();this.R.uniform1i(i,n),this.R.activeTexture(this.R.TEXTURE0+n),this.R.bindTexture(this.R.TEXTURE_2D,r.texture)}else if(typeof r=="object"&&"texture"in r){const n=this.it();this.R.uniform1i(i,n),this.R.activeTexture(this.R.TEXTURE0+n),this.R.bindTexture(this.R.TEXTURE_2D,r.texture)}else console.warn(`Unsupported uniform type for '${s}':`,typeof r)}it(){return this.N>=this.X&&console.warn(`Exceeded maximum texture units (${this.X}). Texture may not render correctly.`),this.N++}get rt(){return this.j}U(){this.R.deleteProgram(this.j)}}class st{constructor(){u(this,"nt",1);u(this,"ot",0);u(this,"ht",[0,0,0]);u(this,"ct",[1,1,1,1]);u(this,"lt",[0,0,0,1]);u(this,"ut",!1);u(this,"ft",!1);u(this,"dt",!1);u(this,"gt",[0,0]);u(this,"_t",[])}vt(){this._t.push({lineWeight:this.nt,rotation:this.ot,charRotation:[...this.gt],flipHorizontally:this.ut,flipVertically:this.ft,invert:this.dt,character:[...this.ht],charColor:[...this.ct],cellColor:[...this.lt]})}xt(){const s=this._t.pop();s?(this.nt=s.lineWeight,this.ot=s.rotation,this.gt=s.charRotation,this.ut=s.flipHorizontally,this.ft=s.flipVertically,this.dt=s.invert,this.ht=s.character,this.ct=s.charColor,this.lt=s.cellColor):console.warn("pop() called without matching push()")}Ct(){this._t=[],this.ot=0}yt(s){s.lineWeight=this.nt,s.rotation=this.ot,s.character[0]=this.ht[0],s.character[1]=this.ht[1],s.character[2]=this.ht[2],s.charColor[0]=this.ct[0],s.charColor[1]=this.ct[1],s.charColor[2]=this.ct[2],s.charColor[3]=this.ct[3],s.bgColor[0]=this.lt[0],s.bgColor[1]=this.lt[1],s.bgColor[2]=this.lt[2],s.bgColor[3]=this.lt[3],s.flipHorizontally=this.ut,s.flipVertically=this.ft,s.invert=this.dt,s.charRotation[0]=this.gt[0],s.charRotation[1]=this.gt[1]}get lineWeight(){return this.nt}get rotation(){return this.ot}get character(){return this.ht}get charColor(){return this.ct}get bgColor(){return this.lt}get flipHorizontally(){return this.ut}get flipVertically(){return this.ft}get invert(){return this.dt}get charRotation(){return this.gt}wt(s){this.nt=Math.abs(s)}$t(s){this.ot=s}bt(s){this.ht=s}Tt(s,r,i,n=255){this.ct=[s/255,r/255,i/255,n/255]}zt(s,r,i,n=255){this.lt=[s/255,r/255,i/255,n/255]}Rt(s){this.ut=s}Mt(s){this.ft=s}St(s){this.dt=s}At(s){const r=255*s/360,i=Math.floor(r)/255,n=Math.round(r-Math.floor(r));this.gt=[i,n]}}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 rt{constructor(s){u(this,"R");u(this,"Pt",new Map);this.R=s}Ft(s,r,i,n){const o=this.R;let a=this.Pt.get(s);a||(a=new Map,this.Pt.set(s,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(s,"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(s,"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)}Gt(){this.R.bindVertexArray(null)}U(){const s=this.R;for(const[,r]of this.Pt)for(const[,i]of r)i&&s.deleteVertexArray(i);this.Pt.clear()}}class it{constructor(s){u(this,"Dt");u(this,"R");this.R=s,this.Dt=new rt(s)}It(s,r,i){const{shader:n}=s,o=B(this.R)||this.R.getParameter(this.R.VIEWPORT);n.et({u_aspectRatio:o[2]/o[3],u_viewportSize:[o[2],o[3]]});const a=f=>{if(!f||!f.Bt())return;const d=f.unitGeometry,p=f.unitBuffer;try{this.Dt.Ft(n.rt,f.type+"",d,p),f.batch.Lt(n),f.batch.Et(d.primitiveType,d.vertexCount)}finally{f.batch.Wt(n),this.Dt.Gt(),f.kt()}};let h=null,l=null;for(const f of r){h!==null&&f.type!==h&&(a(l),h=null,l=null);let d=l;d&&f.type===h||(d=i.get(f.type)||null,l=d,h=f.type),d&&d.Vt(f.params,f.state)}a(l)}}class nt{constructor(){u(this,"Ot",[]);u(this,"Ut",1);u(this,"jt",0)}Ht(s){if(this.jt>=this.Ot.length){const i={id:this.Ut++,type:s,params:{},state:{lineWeight:1,rotation: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.Ot.push(i)}const r=this.Ot[this.jt];switch(r.id=this.Ut++,r.type=s,s){case y.RECTANGLE:case y.ELLIPSE:r.params&&"width"in r.params||(r.params={x:0,y:0,width:0,height:0});break;case y.ARC:r.params&&"start"in r.params||(r.params={x:0,y:0,width:0,height:0,start:0,stop:0});break;case y.LINE:r.params&&"x2"in r.params||(r.params={x1:0,y1:0,x2:0,y2:0,thickness:void 0});break;case y.TRIANGLE:r.params&&"x3"in r.params||(r.params={x1:0,y1:0,x2:0,y2:0,x3:0,y3:0});break;case y.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.jt++,r}qt(s,r,i,n,o){const a=this.Ht(y.RECTANGLE);return a.params.x=s,a.params.y=r,a.params.width=i,a.params.height=n,o.yt(a.state),a.id}Nt(s,r,i,n,o,a){const h=this.Ht(y.LINE);return h.params.x1=s,h.params.y1=r,h.params.x2=i,h.params.y2=n,h.params.thickness=o,a.yt(h.state),h.id}Xt(s,r,i,n,o){const a=this.Ht(y.ELLIPSE);return a.params.x=s,a.params.y=r,a.params.width=i,a.params.height=n,o.yt(a.state),a.id}Yt(s,r,i,n,o,a,h){const l=this.Ht(y.ARC);return l.params.x=s,l.params.y=r,l.params.width=i,l.params.height=n,l.params.start=o,l.params.stop=a,h.yt(l.state),l.id}Qt(s,r,i,n,o,a,h){const l=this.Ht(y.TRIANGLE);return l.params.x1=s,l.params.y1=r,l.params.x2=i,l.params.y2=n,l.params.x3=o,l.params.y3=a,h.yt(l.state),l.id}Zt(s,r,i,n,o,a,h,l,f,d){const p=this.Ht(y.BEZIER_CURVE);return p.params.x1=s,p.params.y1=r,p.params.cp1x=i,p.params.cp1y=n,p.params.cp2x=o,p.params.cp2y=a,p.params.x2=h,p.params.y2=l,p.params.thickness=f,d.yt(p.state),p.id}get length(){return this.jt}get isEmpty(){return this.jt===0}Jt(){this.jt=0}[Symbol.iterator](){let s=0;const r=this.jt,i=this.Ot;return{next:()=>s<r?{value:i[s++],done:!1}:{value:void 0,done:!0}}}}const F=class F{static Kt(s,r,i=0){var a,h,l,f,d,p,g,R,m,x;const n=r||new Float32Array(F.FLOATS_PER_INSTANCE);let o=i;return n[o++]=s.position[0],n[o++]=s.position[1],n[o++]=s.size[0],n[o++]=s.size[1],n[o++]=s.character[0],n[o++]=s.character[1],n[o++]=s.character[2],n[o++]=s.primaryColor[0],n[o++]=s.primaryColor[1],n[o++]=s.primaryColor[2],n[o++]=s.primaryColor[3],n[o++]=s.secondaryColor[0],n[o++]=s.secondaryColor[1],n[o++]=s.secondaryColor[2],n[o++]=s.secondaryColor[3],n[o++]=s.rotation[0],n[o++]=s.rotation[1],n[o++]=s.transform[0],n[o++]=s.transform[1],n[o++]=s.transform[2],n[o++]=s.globalRotation,n[o++]=s.rotationCenter[0],n[o++]=s.rotationCenter[1],n[o++]=((a=s.arcAngles)==null?void 0:a[0])||0,n[o++]=((h=s.arcAngles)==null?void 0:h[1])||0,n[o++]=((l=s.bezierControlPoint1)==null?void 0:l[0])||0,n[o++]=((f=s.bezierControlPoint1)==null?void 0:f[1])||0,n[o++]=((d=s.bezierControlPoint2)==null?void 0:d[0])||0,n[o++]=((p=s.bezierControlPoint2)==null?void 0:p[1])||0,n[o++]=((g=s.bezierStartPoint)==null?void 0:g[0])||0,n[o++]=((R=s.bezierStartPoint)==null?void 0:R[1])||0,n[o++]=((m=s.bezierEndPoint)==null?void 0:m[0])||0,n[o++]=((x=s.bezierEndPoint)==null?void 0:x[1])||0,n}static te(s){const r=s.length*F.FLOATS_PER_INSTANCE,i=new Float32Array(r);for(let n=0;n<s.length;n++){const o=n*F.FLOATS_PER_INSTANCE;F.Kt(s[n],i,o)}return i}};u(F,"BYTES_PER_INSTANCE",132),u(F,"FLOATS_PER_INSTANCE",33);let I=F;const v=class v{};u(v,"STRIDE",I.BYTES_PER_INSTANCE),u(v,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:1,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:84,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:92,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:100,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:108,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:116,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:v.STRIDE,offset:124,divisor:1}});let O=v;class ot{constructor(s,r=1e3,i=1.5){u(this,"R");u(this,"ee",[]);u(this,"se");u(this,"ie");u(this,"re",null);u(this,"ne",!0);u(this,"oe",0);u(this,"ae",new Map);u(this,"he",null);this.R=s,this.se=r,this.ie=i,this.ce()}Vt(s){const r=this.ee.length;return this.ee.push(s),this.ne=!0,r}get count(){return this.ee.length}get isEmpty(){return this.ee.length===0}clear(){this.ee.length=0,this.ne=!0}le(s){if(s<=this.se)return;const r=Math.ceil(s*this.ie);this.se=r,this.ce(),console.log(`InstanceBatch: Grew buffer capacity to ${r} instances`)}ce(){const s=this.R;if(this.re&&s.deleteBuffer(this.re),this.re=s.createBuffer(),!this.re)throw Error("Failed to create instance buffer");const r=this.se*I.BYTES_PER_INSTANCE;s.bindBuffer(s.ARRAY_BUFFER,this.re),s.bufferData(s.ARRAY_BUFFER,r,s.DYNAMIC_DRAW),s.bindBuffer(s.ARRAY_BUFFER,null),this.ne=!0,this.oe=0}ue(){if(!this.ne||this.ee.length===0)return;const s=this.R,r=this.ee.length;this.le(r),(!this.he||this.he.length<r*I.FLOATS_PER_INSTANCE)&&(this.he=new Float32Array(r*I.FLOATS_PER_INSTANCE));const i=I.te(this.ee);s.bindBuffer(s.ARRAY_BUFFER,this.re),r<=this.oe?s.bufferSubData(s.ARRAY_BUFFER,0,i):s.bufferData(s.ARRAY_BUFFER,i,s.DYNAMIC_DRAW),s.bindBuffer(s.ARRAY_BUFFER,null),this.ne=!1,this.oe=r}fe(s){let r=this.ae.get(s);if(!r){r=new Map;const i=this.R;for(const n in O.ATTRIBUTES){const o=i.getAttribLocation(s,n);o!==-1&&r.set(n,o)}this.ae.set(s,r)}return r}Lt(s){if(!this.re||this.ee.length===0)return;const r=this.R,i=s.rt;if(!i)return void console.warn("InstanceBatch: Cannot bind attributes - invalid shader program");this.ue();const n=this.fe(i);r.bindBuffer(r.ARRAY_BUFFER,this.re);for(const[o,a]of n){const h=O.ATTRIBUTES[o];h&&(r.enableVertexAttribArray(a),r.vertexAttribPointer(a,h.size,h.type,h.normalized,h.stride,h.offset),r.vertexAttribDivisor(a,h.divisor))}}Wt(s){const r=this.R,i=this.fe(s.rt);for(const[,n]of i)r.disableVertexAttribArray(n),r.vertexAttribDivisor(n,0)}Et(s,r){this.ee.length!==0&&this.R.drawArraysInstanced(s,0,r,this.ee.length)}U(){const s=this.R;this.re&&(s.deleteBuffer(this.re),this.re=null),this.ee.length=0,this.ae.clear(),this.he=null}}class L{constructor(s,r,i,n){u(this,"R");u(this,"de");u(this,"pe");u(this,"ge");u(this,"_e",null);this.R=s,this.de=r,this.pe=i,this.ge=n;const o=this.R.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.R.bindBuffer(this.R.ARRAY_BUFFER,o),this.R.bufferData(this.R.ARRAY_BUFFER,this.ge.vertices,this.R.STATIC_DRAW),this.R.bindBuffer(this.R.ARRAY_BUFFER,null),this._e=o}get type(){return this.pe}get unitGeometry(){return this.ge}get unitBuffer(){return this._e}get batch(){return this.de}kt(){this.de.clear()}Bt(){return!this.de.isEmpty}U(){this.de.U(),this._e&&(this.R.deleteBuffer(this._e),this._e=null)}me(s,r,i,n,o){const a=this.ve(s,r,i,n,o.rotation||0);return{position:[s,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],globalRotation:a.radians,rotationCenter:[a.centerX,a.centerY]}}xe(s,r){const i=B(this.R)||[0,0,this.R.canvas.width,this.R.canvas.height];return{nx:s/i[2]*2-1,ny:1-r/i[3]*2}}Ce(s,r,i){const n=this.xe(r,i);s.rotationCenter=[n.nx,n.ny]}ve(s,r,i,n,o){const a=B(this.R)||[0,0,this.R.canvas.width,this.R.canvas.height],h=a[2],l=a[3];return{centerX:(s+i/2)/h*2-1,centerY:1-(r+n/2)/l*2,radians:-o*Math.PI/180,aspectRatio:h/l}}}const at={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 ht extends L{constructor(s,r){super(s,r,y.RECTANGLE,at)}Vt(s,r){const i=this.me(s.x,s.y,s.width,s.height,r);return this.de.Vt(i)}}const ct={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 lt extends L{constructor(s,r){super(s,r,y.LINE,ct)}Vt(s,r){const i=s.x2-s.x1,n=s.y2-s.y1,o=Math.hypot(i,n),a=Math.atan2(n,i),h=s.thickness||r.lineWeight||1,l=s.x1+i/2,f=s.y1+n/2,d=l-o/2,p=f,g={character:r.character,charColor:r.charColor,bgColor:r.bgColor,charRotation:r.charRotation,flipHorizontally:r.flipHorizontally,flipVertically:r.flipVertically,invert:r.invert,rotation:(r.rotation||0)+180*a/Math.PI,lineWeight:h},R=this.me(d,p,o,h,g);return this.Ce(R,l,f),this.de.Vt(R)}}const ut={vertices:function(c=32){const s=[],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),d=Math.cos(o),p=Math.sin(o),g=.5*(d+1),R=.5*(p+1);s.push(0,0,.5,.5,a,h,l,f,d,p,g,R)}return new Float32Array(s)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class ft extends L{constructor(s,r){super(s,r,y.ELLIPSE,ut)}Vt(s,r){const i=this.me(s.x,s.y,s.width,s.height,r);return this.Ce(i,s.x,s.y),this.de.Vt(i)}}let dt={vertices:function(c){const s=[];for(let r=0;r<c;r++){const i=r/c,n=(r+1)/c;s.push(i,0,i,0,i,1,i,1,n,1,n,1)}return new Float32Array(s)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class pt extends L{constructor(s,r){super(s,r,y.ARC,dt)}Vt(s,r){const i=s.x-s.width/2,n=s.y-s.height/2,o=s.start*Math.PI/180,a=s.stop*Math.PI/180,h=this.me(i,n,s.width,s.height,r);return this.Ce(h,s.x,s.y),h.arcAngles=[o,a],this.de.Vt(h)}}const gt={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 mt extends L{constructor(s,r){super(s,r,y.TRIANGLE,gt)}Vt(s,r){const i=Math.min(s.x1,s.x2,s.x3),n=Math.max(s.x1,s.x2,s.x3),o=Math.min(s.y1,s.y2,s.y3),a=n-i,h=Math.max(s.y1,s.y2,s.y3)-o,l=this.me(i,o,a,h,r),f=i+.5*a,d=o+h*(1/3);return this.Ce(l,f,d),this.de.Vt(l)}}function Y(c,s,r,i,n){const o=1-c,a=o*o,h=c*c;return a*o*s+3*a*c*r+3*o*h*i+h*c*n}const Rt={vertices:function(c=16){const s=[];for(let r=0;r<c;r++){const i=r/c,n=(r+1)/c;s.push(i,-.5,i,0),s.push(n,-.5,n,0),s.push(i,.5,i,1),s.push(i,.5,i,1),s.push(n,-.5,n,0),s.push(n,.5,n,1)}return new Float32Array(s)}(16),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class xt extends L{constructor(s,r){super(s,r,y.BEZIER_CURVE,Rt)}Vt(s,r){const i=r.lineWeight||1,n=Y(.5,s.x1,s.cp1x,s.cp2x,s.x2),o=Y(.5,s.y1,s.cp1y,s.cp2y,s.y2),a={character:r.character,charColor:r.charColor,bgColor:r.bgColor,charRotation:r.charRotation,flipHorizontally:r.flipHorizontally,flipVertically:r.flipVertically,invert:r.invert,rotation:r.rotation||0,lineWeight:i},h=this.me(0,0,1,i,a);return this.Ce(h,n,o),h.bezierStartPoint=[s.x1,s.y1],h.bezierControlPoint1=[s.cp1x,s.cp1y],h.bezierControlPoint2=[s.cp2x,s.cp2y],h.bezierEndPoint=[s.x2,s.y2],this.de.Vt(h)}}class yt{constructor(s){u(this,"R");u(this,"ye",null);u(this,"we",null);u(this,"$e",null);u(this,"be",new Map);u(this,"Te");u(this,"ze");u(this,"Re");this.R=s,this.Re=new st,this.Te=new it(s),this.ze=new nt,this.we=s.createBuffer(),s.bindBuffer(s.ARRAY_BUFFER,this.we),s.bufferData(s.ARRAY_BUFFER,new Float32Array([-1,-1,0,0,1,-1,1,0,-1,1,0,1,1,-1,1,0,1,1,1,1,-1,1,0,1]),s.STATIC_DRAW),this.$e=s.createBuffer(),this.R.enable(this.R.BLEND),this.R.blendEquation(this.R.FUNC_ADD),this.R.blendFunc(this.R.ONE,this.R.ONE_MINUS_SRC_ALPHA),z(this.R,[0,0,this.R.canvas.width,this.R.canvas.height])}Me(s){let r=this.be.get(s);if(r)return r;const i=new ot(this.R);return r=(0,{[y.RECTANGLE]:()=>new ht(this.R,i),[y.LINE]:()=>new lt(this.R,i),[y.ELLIPSE]:()=>new ft(this.R,i),[y.ARC]:()=>new pt(this.R,i),[y.TRIANGLE]:()=>new mt(this.R,i),[y.BEZIER_CURVE]:()=>new xt(this.R,i)}[s])(),this.be.set(s,r),r}Se(s){this.ye!==s&&(this.ye=s,s.K())}Ae(s,r){return new et(this.R,s,r)}Pe(s,r,i,n){var x;const o=this.R,a=o.canvas.width,h=o.canvas.height,l=s/a*2-1,f=(s+i)/a*2-1,d=1-r/h*2,p=1-(r+n)/h*2,g=new Float32Array([l,p,f,p,l,d,f,p,f,d,l,d]);o.bindBuffer(o.ARRAY_BUFFER,this.$e),o.bufferData(o.ARRAY_BUFFER,g,o.DYNAMIC_DRAW);const R=((x=this.ye)==null?void 0:x.rt)||o.getParameter(o.CURRENT_PROGRAM),m=R?o.getAttribLocation(R,"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)}Fe(s,r,i,n){this.ze.qt(s,r,i,n,this.Re)}Ge(s,r,i,n){this.ze.Nt(s,r,i,n,this.Re.lineWeight,this.Re)}De(s,r,i,n){this.ze.Xt(s,r,i,n,this.Re)}Ie(s,r,i,n,o,a){this.ze.Qt(s,r,i,n,o,a,this.Re)}Be(s,r,i,n,o,a,h,l){const f=this.Re.lineWeight;this.ze.Zt(s,r,i,n,o,a,h,l,f,this.Re)}Le(s,r,i=1,n={}){return new X(this.R,s,r,i,n)}Ee(s,r,i,n,o,a){this.ze.Yt(s,r,i,n,o,a,this.Re)}We(s,r=s,i=s,n=255){this.Jt(s/255,r/255,i/255,n/255)}Jt(s=0,r=0,i=0,n=0){this.R.clearColor(s,r,i,n),this.R.clear(this.R.COLOR_BUFFER_BIT)}ke(){this.R.viewport(0,0,this.R.canvas.width,this.R.canvas.height),z(this.R,[0,0,this.R.canvas.width,this.R.canvas.height])}get context(){return this.R}get state(){return this.Re}Ve(s){const r=B(this.R)??this.R.getParameter(this.R.VIEWPORT),i={shader:s,gl:this.R,viewport:r},n=new Set;for(const o of this.ze)n.add(o.type);for(const o of n)this.Me(o);this.Te.It(i,this.ze,this.be),this.ze.Jt()}U(){this.R.deleteBuffer(this.we),this.R.deleteBuffer(this.$e),this.ze.Jt();for(const s of this.be.values())s.U()}}const b={readShort:(c,s)=>(b.t.uint16[0]=c[s]<<8|c[s+1],b.t.int16[0]),readUshort:(c,s)=>c[s]<<8|c[s+1],readUshorts(c,s,r){const i=[];for(let n=0;n<r;n++)i.push(b.readUshort(c,s+2*n));return i},readUint(c,s){const r=b.t.uint8;return r[3]=c[s],r[2]=c[s+1],r[1]=c[s+2],r[0]=c[s+3],b.t.uint32[0]},readASCII(c,s,r){let i="";for(let n=0;n<r;n++)i+=String.fromCharCode(c[s+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)}})()},Ct={parseTab(c,s,r){const i={tables:[],ids:{},off:s};c=new Uint8Array(c.buffer,s,r),s=0;const n=b,o=n.readUshort,a=o(c,s+=2);s+=2;const h=[];for(let l=0;l<a;l++){const f=o(c,s),d=o(c,s+=2);s+=2;const p=n.readUint(c,s);s+=4;const g=`p${f}e${d}`;let R=h.indexOf(p);if(R===-1){let m;R=i.tables.length,h.push(p);const x=o(c,p);m=x===4?this.parse4(c,p):x===12?this.parse12(c,p):{format:x},i.tables.push(m)}i.ids[g]!=null&&console.warn("Multiple tables for one platform+encoding: "+g),i.ids[g]=R}return i},parse4(c,s){const r=b,i=r.readUshort,n=r.readUshorts,o=s,a=i(c,s+=2);s+=2;const h=i(c,s+=2)>>>1,l={format:4,searchRange:i(c,s+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};s+=2,l.entrySelector=i(c,s),s+=2,l.rangeShift=i(c,s),s+=2,l.endCount=n(c,s,h),s+=2*h,s+=2,l.startCount=n(c,s,h),s+=2*h;for(let f=0;f<h;f++)l.idDelta.push(r.readShort(c,s)),s+=2;return l.idRangeOffset=n(c,s,h),s+=2*h,l.glyphIdArray=n(c,s,o+a-s>>1),l},parse12(c,s){const r=b.readUint;r(c,s+=4),r(c,s+=4);const i=r(c,s+=4);s+=4;const n=new Uint32Array(3*i);for(let o=0;o<3*i;o+=3)n[o]=r(c,s+(o<<2)),n[o+1]=r(c,s+(o<<2)+4),n[o+2]=r(c,s+(o<<2)+8);return{format:12,groups:n}}},vt={parseTab(c,s,r){const i=b;s+=18;const n=i.readUshort(c,s);s+=2,s+=16;const o=i.readShort(c,s);s+=2;const a=i.readShort(c,s);s+=2;const h=i.readShort(c,s);s+=2;const l=i.readShort(c,s);return s+=2,s+=6,{unitsPerEm:n,xMin:o,yMin:a,xMax:h,yMax:l,indexToLocFormat:i.readShort(c,s)}}},Tt={parseTab(c,s,r){const i=b;s+=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,s+2*a)}return o}},bt={parseTab(c,s,r,i){const n=b,o=[],a=[],h=i.maxp.numGlyphs,l=i.hhea.numberOfHMetrics;let f=0,d=0,p=0;for(;p<l;)f=n.readUshort(c,s+(p<<2)),d=n.readShort(c,s+(p<<2)+2),o.push(f),a.push(d),p++;for(;p<h;)o.push(f),a.push(d),p++;return{aWidth:o,lsBearing:a}}},j={cmap:Ct,head:vt,hhea:Tt,maxp:{parseTab(c,s,r){const i=b;return i.readUint(c,s),s+=4,{numGlyphs:i.readUshort(c,s)}}},hmtx:bt,loca:{parseTab(c,s,r,i){const n=b,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,s+(l<<1))<<1);else if(a===1)for(let l=0;l<h;l++)o.push(n.readUint(c,s+(l<<2)));return o}},glyf:{parseTab(c,s,r,i){const n=[],o=i.maxp.numGlyphs;for(let a=0;a<o;a++)n.push(null);return n},Oe(c,s){const r=b,i=c.Ue,n=c.loca;if(n[s]===n[s+1])return null;const o=w.findTable(i,"glyf",c.je);if(!o)return null;let a=o[0]+n[s];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 g=0;g<h.noc;g++)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 g=0;g<f;g++){const R=i[a];if(a++,h.flags.push(R),8&R){const m=i[a];a++;for(let x=0;x<m;x++)h.flags.push(R),g++}}h.xs=[];for(let g=0;g<f;g++){const R=h.flags[g],m=!!(16&R);2&R?(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 g=0;g<f;g++){const R=h.flags[g],m=!!(32&R);4&R?(h.ys.push(m?i[a]:-i[a]),a++):m?h.ys.push(0):(h.ys.push(r.readShort(i,a)),a+=2)}let d=0,p=0;for(let g=0;g<f;g++)d+=h.xs[g],p+=h.ys[g],h.xs[g]=d,h.ys[g]=p}else h.parts=[],h.endPts=[],h.flags=[],h.xs=[],h.ys=[];return h}}},w={parse:c=>[((s,r,i,n)=>{const o=j,a={Ue:s,He:r,je:i};for(const h in o){const l=h,f=w.findTable(s,l,i);if(f){const[d,p]=f;let g=n[d];g==null&&(g=o[l].parseTab(s,d,p,a),n[d]=g),a[l]=g}}return a})(new Uint8Array(c),0,0,{})],findTable(c,s,r){const i=b,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===s)return[l,f];o+=16}return null},T:j,B:b};class ${constructor(){u(this,"qe",new Map);u(this,"Ne",new Map)}Xe(s,r){const i=`${this.Ye(s)}_${r}`;if(this.qe.has(i))return this.qe.get(i);const n=s.cmap;if(!n||!n.tables)return this.qe.set(i,0),0;let o=0;for(const a of n.tables)if(a.format===4?o=this.Qe(r,a):a.format===12&&(o=this.Ze(r,a)),o>0)break;return this.qe.set(i,o),o}Je(s,r){const i=r.codePointAt(0);return i===void 0?0:this.Xe(s,i)}Ke(s,r){const i=s.hmtx;return i&&i.aWidth&&i.aWidth.length!==0?r<i.aWidth.length?i.aWidth[r]:i.aWidth[i.aWidth.length-1]:0}ts(s,r){const i=r/s.head.unitsPerEm,n=s.hhea.ascender*i,o=s.hhea.descender*i,a=s.hhea.lineGap*i;return{ascender:n,descender:o,lineGap:a,lineHeight:n-o+a,unitsPerEm:s.head.unitsPerEm,scale:i}}es(){this.qe.clear(),this.Ne.clear()}Ye(s){return`${s.je}_${s.Ue.length}`}Qe(s,r){const i=r.endCount.length;let n=-1;for(let o=0;o<i;o++)if(s<=r.endCount[o]){n=o;break}if(n===-1||s<r.startCount[n])return 0;if(r.idRangeOffset[n]===0)return s+r.idDelta[n]&65535;{const o=r.idRangeOffset[n]/2+(s-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}Ze(s,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(s>=o&&s<=a)return h+(s-o)}return 0}}class Et{constructor(s){u(this,"ss");this.ss=s}rs(s){var i;const r=[];return(i=s.cmap)!=null&&i.tables?(s.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ns(n);r.push(...o)}else if(n.format===12){const o=this.hs(n);r.push(...o)}}),[...new Set(r)]):[]}cs(s,r){return this.ss.Je(s,r)>0}ls(s,r){for(const i of r)if(!this.cs(s,i))return!1;return!0}us(s,r){return r.filter(i=>this.cs(s,i))}fs(s){return s.filter(r=>this.ds(r))}ns(s){const r=[];if(!(s.startCount&&s.endCount&&s.idRangeOffset&&s.idDelta))return r;for(let i=0;i<s.startCount.length;i++){const n=s.startCount[i],o=s.endCount[i];if(n!==65535||o!==65535){for(let a=n;a<=o;a++)if(this.ps(s,a,i)>0)try{const h=String.fromCodePoint(a);r.push(h)}catch{}}}return r}hs(s){const r=[];if(!s.groups)return r;for(let i=0;i<s.groups.length;i+=3){const n=s.groups[i],o=s.groups[i+1],a=s.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}ps(s,r,i){if(s.idRangeOffset[i]===0)return r+s.idDelta[i]&65535;{const n=s.idRangeOffset[i]/2+(r-s.startCount[i])-(s.startCount.length-i);if(n>=0&&s.glyphIdArray&&n<s.glyphIdArray.length){const o=s.glyphIdArray[n];if(o!==0)return o+s.idDelta[i]&65535}}return 0}ds(s){const r=s.codePointAt(0)||0;return!(r>=0&&r<=31&&r!==9&&r!==10&&r!==13||r>=127&&r<=159)}}class At{constructor(){u(this,"gs");const s=new $;this.gs=new Et(s)}extractCharacters(s){return this.gs.rs(s)}filterProblematicCharacters(s){return this.gs.fs(s)}characterExists(s,r){return this.gs.cs(s,r)}allCharactersExist(s,r){return this.gs.ls(s,r)}}class _t{constructor(s){u(this,"_s");u(this,"vs");u(this,"Cs");u(this,"ws");this.Cs=s,this.ws=new $,this._s=document.createElement("canvas"),this.vs=this._s.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(s,r,i,n){const o=s.length,a=Math.ceil(Math.sqrt(o)),h=Math.ceil(o/a),l=r.width*a,f=r.height*h,d=typeof n=="object"?n:null;this.$s(l,f),this.bs(s,r,a,i,d);const p=this.Cs.Le(l,f,1,{filter:"nearest"});return p.I(this._s),{framebuffer:p,columns:a,rows:h}}$s(s,r){this._s.width=s,this._s.height=r,this._s.style.width=s+"px",this._s.style.height=s+"px",this.vs.imageSmoothingEnabled=!1,this._s.style.imageRendering="pixelated",this.vs.fillStyle="black",this.vs.fillRect(0,0,s,r),this.vs.textBaseline="top",this.vs.textAlign="left",this.vs.fillStyle="white"}bs(s,r,i,n,o){const a=n/o.head.unitsPerEm;for(let h=0;h<s.length;h++){const l=h%i,f=Math.floor(h/i),d=s[h].character,p=this.Ts(o,d);if(!p)continue;const g=d.codePointAt(0)||0,R=this.ws.Xe(o,g),m=this.zs(o,R)*a,x=l*r.width,A=f*r.height,E=x+.5*r.width,_=A+.5*r.height,P=Math.round(E-.5*r.width),U=Math.round(_-.5*n),Zt=P+.5*(r.width-m),Kt=U+o.hhea.ascender*a;this.Rs(p,Zt,Kt,a)}}Ts(s,r){const i=r.codePointAt(0)||0,n=this.ws.Xe(s,i);if(n===0)return null;if(s.glyf&&s.glyf[n]!==null)return s.glyf[n];if(w&&w.T&&w.T.glyf){const o=w.T.glyf.Oe(s,n);return s.glyf&&o&&(s.glyf[n]=o),o}return null}zs(s,r){const i=s.hmtx;return i&&i.aWidth?r<i.aWidth.length?i.aWidth[r]:i.aWidth[i.aWidth.length-1]:0}Rs(s,r,i,n){if(!s||!s.xs||s.noc===0)return;const{xs:o,ys:a,endPts:h,flags:l}=s;if(!(o&&a&&h&&l))return;this.vs.beginPath();let f=0;for(let d=0;d<h.length;d++){const p=h[d];if(!(p<f)){if(p>=f){const g=r+o[f]*n,R=i-a[f]*n;this.vs.moveTo(g,R);let m=f+1;for(;m<=p;)if(1&l[m]){const x=r+o[m]*n,A=i-a[m]*n;this.vs.lineTo(x,A),m++}else{const x=r+o[m]*n,A=i-a[m]*n;let E=m+1>p?f:m+1;if(1&l[E]){const _=r+o[E]*n,P=i-a[E]*n;this.vs.quadraticCurveTo(x,A,_,P),m=E+1}else{const _=(x+(r+o[E]*n))/2,P=(A+(i-a[E]*n))/2;this.vs.quadraticCurveTo(x,A,_,P),m=E}}this.vs.closePath()}f=p+1}}this.vs.fill()}}class wt{constructor(){u(this,"ss");this.ss=new $}calculateMaxGlyphDimensions(s,r,i){let n=0;const o=this.ss.ts(i,r),a=o.lineHeight;for(const h of s){const l=this.ss.Je(i,h);if(l===0)continue;const f=this.ss.Ke(i,l)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}getCharacterAdvanceWidth(s,r,i){const n=this.ss.ts(i,r),o=this.ss.Je(i,s);return this.ss.Ke(i,o)*n.scale}getFontMetrics(s,r){return this.ss.ts(r,s)}es(){this.ss.es()}}class Pt{constructor(){u(this,"ws");this.ws=new $}createCharacterObjects(s,r){return s.map((i,n)=>{const o=i.codePointAt(0)||0,a=this.Ms(n);let h=0;if(r.hmtx&&r.hmtx.aWidth){const l=this.ws.Xe(r,o);l>0&&r.hmtx.aWidth[l]!==void 0&&(h=r.hmtx.aWidth[l])}return{character:i,unicode:o,color:a,advanceWidth:h}})}Ms(s){return[s%256/255,Math.floor(s/256)%256/255,Math.floor(s/65536)%256/255]}Ss(s,r){if(!M._(typeof s=="string","Character must be a string.",{method:"getCharacterColor",providedValue:s}))return[0,0,0];const i=r.find(n=>n.character===s);return i?i.color:[0,0,0]}As(s,r){return M._(typeof s=="string"&&s.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:s})?Array.from(s).map(i=>this.Ss(i,r)||[0,0,0]):[[0,0,0]]}}class H{constructor(s,r=16){u(this,"Ps");u(this,"Fs",[]);u(this,"Gs");u(this,"Ds",16);u(this,"Is",0);u(this,"Bs",0);u(this,"Ls",{width:0,height:0});u(this,"Es");u(this,"Ws");u(this,"ks");u(this,"Vs");u(this,"Os");this.Ds=r,this.Ws=new At,this.ks=new _t(s),this.Vs=new wt,this.Os=new Pt}async Us(s){let r;if(!s)throw new C("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const i=await fetch(s);if(!i.ok)throw new C(`Failed to load font file: ${i.status} ${i.statusText}`);r=await i.arrayBuffer()}await this.js(r),this.Ps=w.parse(r)[0],await this.Hs()}qs(s){if(s===void 0)return this.Ds;this.Ds=s,this.Ls=this.Vs.calculateMaxGlyphDimensions(this.Fs.map(i=>i.character),this.Ds,this.Ps);const r=this.ks.createTextureAtlas(this.Fs,this.Ls,this.Ds,this.Ps);this.Gs=r.framebuffer,this.Is=r.columns,this.Bs=r.rows}async Ns(s){try{const r=await fetch(s);if(!r.ok)throw new C(`Failed to load font file: ${r.status} ${r.statusText}`);const i=await r.arrayBuffer();await this.js(i);const n=w.parse(i);if(!n||n.length===0)throw Error("Failed to parse font file");this.Ps=n[0],await this.Hs()}catch(r){throw new C("Failed to load font: "+(r instanceof Error?r.message:"Unknown error"),r)}}async js(s){const r=Date.now();this.Es=new FontFace("CustomFont_"+r,s),await this.Es.load(),document.fonts.add(this.Es)}async Hs(){const s=this.Ws.extractCharacters(this.Ps),r=this.Ws.filterProblematicCharacters(s);this.Fs=this.Os.createCharacterObjects(r,this.Ps),this.Ls=this.Vs.calculateMaxGlyphDimensions(r,this.Ds,this.Ps);const i=this.ks.createTextureAtlas(this.Fs,this.Ls,this.Ds,this.Ps);this.Gs=i.framebuffer,this.Is=i.columns,this.Bs=i.rows}Ss(s){return this.Os.Ss(s,this.Fs)}As(s){return this.Os.As(s,this.Fs)}U(){this.Gs.U(),document.fonts.delete(this.Es)}get fontFramebuffer(){return this.Gs}get characters(){return this.Fs}get textureColumns(){return this.Is}get textureRows(){return this.Bs}get maxGlyphDimensions(){return this.Ls}get fontSize(){return this.Ds}get font(){return this.Ps}}class J{constructor(s,r,i){u(this,"Xs");u(this,"Ys");u(this,"v");u(this,"C");u(this,"Qs");u(this,"Zs");u(this,"Js");u(this,"Ks");u(this,"ti");this.Js=s,this.Ks=r,this.ti=i,this.Ct()}Ct(){this.Xs=Math.floor(this.Js.width/this.Ks),this.Ys=Math.floor(this.Js.height/this.ti),this.v=this.Xs*this.Ks,this.C=this.Ys*this.ti,this.Qs=Math.floor((this.Js.width-this.v)/2),this.Zs=Math.floor((this.Js.height-this.C)/2)}ei(s,r){this.Ks=s,this.ti=r,this.Ct()}get cellWidth(){return this.Ks}get cellHeight(){return this.ti}get cols(){return this.Xs}get rows(){return this.Ys}get width(){return this.v}get height(){return this.C}get offsetX(){return this.Qs}get offsetY(){return this.Zs}}class q{constructor(s={}){u(this,"Js");u(this,"si");u(this,"ii");s.canvas?(this.Js=s.canvas,this.ii=!1):(this.Js=this.ri(s.width,s.height),this.ii=!0),this.Js.style.imageRendering="pixelated"}ri(s,r){const i=document.createElement("canvas");return i.className="textmodeCanvas",i.style.imageRendering="pixelated",i.width=s||800,i.height=r||600,document.body.appendChild(i),i}L(s,r){this.Js.width=s??this.Js.width,this.Js.height=r??this.Js.height}ni(){const s=this.Js.getContext("webgl2",{alpha:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!s)throw new C("`textmode.js` requires WebGL2 support.");return s}U(){this.si&&this.si.disconnect();const s=this.Js.getContext("webgl")||this.Js.getContext("webgl2");if(s){const r=s.getExtension("WEBGL_lose_context");r&&r.loseContext()}this.ii&&this.Js.parentNode&&this.Js.parentNode.removeChild(this.Js)}get canvas(){return this.Js}get width(){return this.Js.width}get height(){return this.Js.height}}class Ft{constructor(s=60){u(this,"oi");u(this,"ai");u(this,"hi",null);u(this,"ci",0);u(this,"li",!0);u(this,"ui",0);u(this,"fi",0);u(this,"di",[]);u(this,"pi",10);u(this,"gi",0);this.oi=s,this.ai=1e3/s}start(s){if(!this.li)return;this.ci=performance.now();const r=i=>{if(!this.li)return void(this.hi=null);const n=i-this.ci;n>=this.ai&&(s(),this.ci=i-n%this.ai),this.li&&(this.hi=requestAnimationFrame(r))};this.hi=requestAnimationFrame(r)}stop(){this.hi&&(cancelAnimationFrame(this.hi),this.hi=null)}pause(){this.li&&(this.li=!1,this.stop())}resume(s){this.li||(this.li=!0,this.start(s))}frameRate(s,r){if(s===void 0)return this.ui;this.oi=s,this.ai=1e3/s,this.li&&r&&(this.stop(),this.start(r))}measureFrameRate(){const s=performance.now();if(this.fi>0){const r=s-this.fi;this.di.push(r),this.di.length>this.pi&&this.di.shift();const i=this.di.reduce((n,o)=>n+o,0)/this.di.length;this.ui=1e3/i}this.fi=s}get isLooping(){return this.li}get frameRateLimit(){return this.oi}get currentFrameRate(){return this.ui}get frameCount(){return this.gi}set frameCount(s){this.gi=s}incrementFrame(){this.gi++}resetFrameCount(){this.gi=0}}const St=c=>class extends c{rotate(s){this.Cs.state.$t(s)}push(){this.Cs.state.vt()}pop(){this.Cs.state.xt()}rect(s,r,i=1,n=1){this.Cs.Fe(s,r,i,n)}line(s,r,i,n){this.Cs.Ge(s,r,i,n)}lineWeight(s){this.Cs.state.wt(s)}background(s,r=s,i=s,n=255){this.Cs.We(s,r,i,n)}char(s){this.Cs.state.bt(this.Ps.Ss(s))}charColor(s,r,i,n){this.Cs.state.Tt(s,r,i,n)}cellColor(s,r,i,n){this.Cs.state.zt(s,r,i,n)}flipHorizontally(s){this.Cs.state.Rt(s)}flipVertically(s){this.Cs.state.Mt(s)}charRotation(s){this.Cs.state.At(s)}invert(s){this.Cs.state.St(s)}clear(){this.Cs.Jt()}ellipse(s,r,i,n){this.Cs.De(s,r,i/2,n/2)}triangle(s,r,i,n,o,a){this.Cs.Ie(s,r,i,n,o,a)}bezierCurve(s,r,i,n,o,a,h,l){this.Cs.Be(s,r,i,n,o,a,h,l)}arc(s,r,i,n,o,a){this.Cs.Ee(s,r,i,n,o,a)}};class N{_i(s){const r=s.W(0),i=s.W(1),n=s.W(2),o=s.W(3);return{characterPixels:r,primaryColorPixels:i,secondaryColorPixels:n,transformPixels:s.W(4),rotationPixels:o}}mi(s,r){return s[r]+(s[r+1]<<8)}xi(s,r){return{r:s[r],g:s[r+1],b:s[r+2],a:s[r+3]}}}class V{Ci(s,r){return new Blob([s],{type:r})}yi(s,r,i){try{const n=this.Ci(s,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"))}}wi(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}$i(){const s=new Date;return{date:s.toISOString().split("T")[0],time:s.toTimeString().split(" ")[0].replace(/:/g,"-")}}bi(s){return s.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Ti(){return"'textmode-export'-"+this.wi()}}class It extends N{zi(s,r,i){const n=s[i]===255,o=s[i+1]===255,a=s[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}}Ri(s,r,i){return{x:s,y:r,cellX:s*i.cellWidth,cellY:r*i.cellHeight}}Mi(s,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.mi(s.characterPixels,h);let f=this.xi(s.primaryColorPixels,h),d=this.xi(s.secondaryColorPixels,h);const p=this.zi(s.transformPixels,s.rotationPixels,h);if(p.isInverted){const R=f;f=d,d=R}const g=this.Ri(a,o,r);i.push({charIndex:l,primaryColor:f,secondaryColor:d,transform:p,position:g}),n++}return i}}class Dt{Si(s,r){const i=s.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}Ai(s,r,i,n,o){const a=o/s.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.Pi(r,i,n,a)}}Pi(s,r,i,n){if(!s||!s.xs)return"";const{xs:o,ys:a,endPts:h,flags:l}=s;if(!(o&&a&&h&&l))return"";let f="",d=0;for(let p=0;p<h.length;p++){const g=h[p];if(!(g<d)){if(g>=d){const R=r+o[d]*n,m=i-a[d]*n;f+=`M${R.toFixed(2)},${m.toFixed(2)}`;let x=d+1;for(;x<=g;)if(1&l[x]){const A=r+o[x]*n,E=i-a[x]*n;f+=`L${A.toFixed(2)},${E.toFixed(2)}`,x++}else{const A=r+o[x]*n,E=i-a[x]*n;let _=x+1>g?d:x+1;if(1&l[_]){const P=r+o[_]*n,U=i-a[_]*n;f+=`Q${A.toFixed(2)},${E.toFixed(2)} ${P.toFixed(2)},${U.toFixed(2)}`,x=_+1}else{const P=(A+(r+o[_]*n))/2,U=(E+(i-a[_]*n))/2;f+=`Q${A.toFixed(2)},${E.toFixed(2)} ${P.toFixed(2)},${U.toFixed(2)}`,x=_}}f+="Z"}d=g+1}}return f}Fi(s,r,i,n,o){const a=s.codePointAt(0)||0,h=this.Si(r,a);let l=null;return r.glyf&&r.glyf[h]!==null?l=r.glyf[h]:(l=w.T.glyf.Oe(r,h),r.glyf[h]=l),this.Ai(r,l,i,n,o)}Gi(s,r,i,n,o,a,h,l){const f=i+(o-l*(h/r.head.unitsPerEm))/2,d=n+(a+.7*h)/2;return this.Fi(s,r,f,d,h).toSVG()||null}}class Lt{constructor(){u(this,"Di");this.Di=new Dt}Ii(s){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
47
8
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
48
- <svg width="${r.width}" height="${r.height}" viewBox="0 0 ${r.width} ${r.height}"
9
+ <svg width="${s.width}" height="${s.height}" viewBox="0 0 ${s.width} ${s.height}"
49
10
  xmlns="http://www.w3.org/2000/svg" version="1.1">
50
11
  <title>textmode art generated via textmode.js</title>
51
- <desc>textmode art visualization generated by textmode.js library</desc>`}ur(){return`
12
+ <desc>textmode art visualization generated by textmode.js library</desc>`}Bi(){return`
52
13
  </g>
53
- </svg>`}dr(r,s){if(!s.includeBackgroundRectangles)return"";const i=s.backgroundColor,o=`rgba(${i[0]},${i[1]},${i[2]},${i[3]/255})`;return`
54
- <rect width="${r.width}" height="${r.height}" fill="${o}" />`}pr(r){return`rgba(${r.r},${r.g},${r.b},${r.a/255})`}mr(r,s){const{transform:i,position:o}=r,n=o.cellX+s.cellWidth/2,a=o.cellY+s.cellHeight/2,h=[];if(i.flipHorizontal||i.flipVertical){const u=i.flipHorizontal?-1:1,d=i.flipVertical?-1:1;h.push(`translate(${n} ${a})`),h.push(`scale(${u} ${d})`),h.push(`translate(${-n} ${-a})`)}return i.rotation&&h.push(`rotate(${i.rotation} ${n} ${a})`),h.length?` transform="${h.join(" ")}"`:""}gr(r,s,i){if(!i.includeBackgroundRectangles||r.secondaryColor.a===0)return"";const{position:o}=r,n=this.pr(r.secondaryColor);return i.drawMode==="stroke"?`
55
- <rect x="${o.cellX}" y="${o.cellY}" width="${s.cellWidth}" height="${s.cellHeight}" stroke="${n}" fill="none" stroke-width="${i.strokeWidth}" />`:`
56
- <rect x="${o.cellX}" y="${o.cellY}" width="${s.cellWidth}" height="${s.cellHeight}" fill="${n}" />`}ar(r,s,i,o){const n=i.characters[r.charIndex];if(!n)return"";const a=this.lr.hr(n.character,i.font,r.position.cellX,r.position.cellY,s.cellWidth,s.cellHeight,i.fontSize,n.advanceWidth);if(!a)return"";const h=this.pr(r.primaryColor);return o.drawMode==="stroke"?`
57
- <path id="${`path-${r.charIndex}-${r.position.cellX}-${r.position.cellY}`.replace(/\./g,"-")}" d="${a}" stroke="${h}" stroke-width="${o.strokeWidth}" fill="none" />`:`
58
- <path d="${a}" fill="${h}" />`}_r(r,s,i,o){let n="";n+=this.gr(r,s,o);const a=this.mr(r,s),h=this.ar(r,s,i,o);return h&&(a?(n+=`
59
- <g${a}>`,n+=h,n+=`
60
- </g>`):n+=h),n}vr(r,s,i,o){let n=this.cr(s);n+=this.dr(s,o),n+=`
61
- <g id="ascii-cells">`;for(const a of r)n+=this._r(a,s,i,o);return n+=this.ur(),n}br(r){return r.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\n\s*\n/g,`
62
- `).replace(/[ \t]+$/gm,"")}}class At extends X{wr(r){return this.qs(r,"image/svg+xml;charset=utf-8")}Cr(r,s){this.Ys(r,this.Js(s)+".svg","image/svg+xml;charset=utf-8")}yr(r,s){this.Cr(r,s||this.Ks())}}class at{constructor(){c(this,"$r");c(this,"Fr");c(this,"Tr");this.$r=new Tt,this.Fr=new Rt,this.Tr=new At}Mr(r){return{includeBackgroundRectangles:r.includeBackgroundRectangles??!0,drawMode:r.drawMode??"fill",strokeWidth:r.strokeWidth??1,backgroundColor:r.backgroundColor??[0,0,0,0]}}Sr(r,s={}){const i=this.Mr(s),o=this.$r.Ws(r.pipeline),n=this.$r.sr(o,r.grid),a=this.Fr.vr(n,r.grid,r.font,i);return this.Fr.br(a)}yr(r,s={}){const i=this.Sr(r,s),o=s.filename||this.Tr.Ks();this.Tr.yr(i,o)}}class St extends W{Dr(r,s,i,o=" "){var h;const n=[];let a=0;for(let u=0;u<s.rows;u++){const d=[];for(let f=0;f<s.cols;f++){const p=4*a,g=this.Ns(r.characterPixels,p),x=((h=i.characters[g])==null?void 0:h.character)||o;d.push(x),a++}n.push(d)}return n}}class Ut{Rr(r,s){const i=[];for(const n of r){let a=n.join("");s.preserveTrailingSpaces||(a=a.replace(/\s+$/,"")),i.push(a)}const o=s.lineEnding==="crlf"?`\r
14
+ </svg>`}Li(s,r){if(!r.includeBackgroundRectangles)return"";const i=r.backgroundColor,n=`rgba(${i[0]},${i[1]},${i[2]},${i[3]/255})`;return`
15
+ <rect width="${s.width}" height="${s.height}" fill="${n}" />`}Ei(s){return`rgba(${s.r},${s.g},${s.b},${s.a/255})`}Wi(s,r){const{transform:i,position:n}=s,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(" ")}"`:""}ki(s,r,i){if(!i.includeBackgroundRectangles||s.secondaryColor.a===0)return"";const{position:n}=s,o=this.Ei(s.secondaryColor);return i.drawMode==="stroke"?`
16
+ <rect x="${n.cellX}" y="${n.cellY}" width="${r.cellWidth}" height="${r.cellHeight}" stroke="${o}" fill="none" stroke-width="${i.strokeWidth}" />`:`
17
+ <rect x="${n.cellX}" y="${n.cellY}" width="${r.cellWidth}" height="${r.cellHeight}" fill="${o}" />`}Fi(s,r,i,n){const o=i.characters[s.charIndex];if(!o)return"";const a=this.Di.Gi(o.character,i.font,s.position.cellX,s.position.cellY,r.cellWidth,r.cellHeight,i.fontSize,o.advanceWidth);if(!a)return"";const h=this.Ei(s.primaryColor);return n.drawMode==="stroke"?`
18
+ <path id="${`path-${s.charIndex}-${s.position.cellX}-${s.position.cellY}`.replace(/\./g,"-")}" d="${a}" stroke="${h}" stroke-width="${n.strokeWidth}" fill="none" />`:`
19
+ <path d="${a}" fill="${h}" />`}Vi(s,r,i,n){let o="";o+=this.ki(s,r,n);const a=this.Wi(s,r),h=this.Fi(s,r,i,n);return h&&(a?(o+=`
20
+ <g${a}>`,o+=h,o+=`
21
+ </g>`):o+=h),o}Oi(s,r,i,n){let o=this.Ii(r);o+=this.Li(r,n),o+=`
22
+ <g id="ascii-cells">`;for(const a of s)o+=this.Vi(a,r,i,n);return o+=this.Bi(),o}Ui(s){return s.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\n\s*\n/g,`
23
+ `).replace(/[ \t]+$/gm,"")}}class Mt extends V{ji(s){return this.Ci(s,"image/svg+xml;charset=utf-8")}Hi(s,r){this.yi(s,this.bi(r)+".svg","image/svg+xml;charset=utf-8")}qi(s,r){this.Hi(s,r||this.Ti())}}class Z{constructor(){u(this,"Ni");u(this,"Xi");u(this,"Yi");this.Ni=new It,this.Xi=new Lt,this.Yi=new Mt}Qi(s){return{includeBackgroundRectangles:s.includeBackgroundRectangles??!0,drawMode:s.drawMode??"fill",strokeWidth:s.strokeWidth??1,backgroundColor:s.backgroundColor??[0,0,0,0],filename:s.filename||this.Yi.Ti()}}Zi(s,r={}){const i=this.Ni.Mi(this.Ni._i(s.pipeline),s.grid),n=this.Xi.Oi(i,s.grid,s.font,this.Qi(r));return this.Xi.Ui(n)}qi(s,r={}){this.Yi.qi(this.Zi(s,r),r.filename)}}class Ut extends N{Ji(s,r,i,n=" "){var h;const o=[];let a=0;for(let l=0;l<r.rows;l++){const f=[];for(let d=0;d<r.cols;d++){const p=4*a,g=this.mi(s.characterPixels,p),R=((h=i.characters[g])==null?void 0:h.character)||n;f.push(R),a++}o.push(f)}return o}}class zt{Ki(s,r){const i=[];for(const o of s){let a=o.join("");r.preserveTrailingSpaces||(a=a.replace(/\s+$/,"")),i.push(a)}const n=r.lineEnding==="crlf"?`\r
63
24
  `:`
64
- `;return i.join(o)}}class Mt extends X{Vr(r,s){const i=this.Ir(s);this.Ys(r,i,"text/plain;charset=utf-8")}Ir(r){let s=this.Js(r);return s===".txt"||s.length<=4?this.Ks():s}}class ht{constructor(){c(this,"$r");c(this,"Fr");c(this,"Tr");this.$r=new St,this.Fr=new Ut,this.Tr=new Mt}Mr(r){return{preserveTrailingSpaces:r.preserveTrailingSpaces??!1,lineEnding:r.lineEnding??"lf",emptyCharacter:r.emptyCharacter??" "}}kr(r,s={}){const i=this.Mr(s),o=this.$r.Ws(r.pipeline),n=this.$r.Dr(o,r.grid,r.font,i.emptyCharacter);return this.Fr.Rr(n,i)}Vr(r,s={}){const i=this.kr(r,s),o=s.filename||this.Tr.Ks();this.Tr.Vr(i,o)}}class Dt extends W{Er(r,s=1,i="transparent"){const o=r.canvas;if(s===1&&i==="transparent")return o;const n=document.createElement("canvas"),a=n.getContext("2d"),h=Math.round(o.width*s),u=Math.round(o.height*s);return n.width=h,n.height=u,i!=="transparent"&&(a.fillStyle=i,a.fillRect(0,0,h,u)),a.imageSmoothingEnabled=!1,a.drawImage(o,0,0,o.width,o.height,0,0,h,u),n}}class Pt{Pr(r,s){const i=this.Ar(s.format);return s.format==="png"?r.toDataURL(i):r.toDataURL(i,s.quality)}async zr(r,s){return new Promise((i,o)=>{const n=this.Ar(s.format),a=h=>{h?i(h):o(Error(`Failed to generate ${s.format.toUpperCase()} blob`))};s.format==="png"?r.toBlob(a,n):r.toBlob(a,n,s.quality)})}Ar(r){switch(r){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+r)}}}const $t={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},lt={png:".png",jpg:".jpg",webp:".webp"};class Gt extends X{Gr(r,s,i){this.Ur(r,this.Js(s)+lt[i])}Ur(r,s){const i=URL.createObjectURL(r);try{const o=document.createElement("a");o.href=i,o.download=s,o.style.display="none",o.rel="noopener",document.body.appendChild(o),o.click(),document.body.removeChild(o)}finally{URL.revokeObjectURL(i)}}Lr(r){return r in $t&&r in lt}}class It{constructor(){c(this,"$r");c(this,"Fr");c(this,"Tr");this.$r=new Dt,this.Fr=new Pt,this.Tr=new Gt}Mr(r){return{format:r.format??"png",quality:r.quality??1,scale:r.scale??1,backgroundColor:r.backgroundColor??"transparent"}}jr(r){if(console.log("Validating image export options:",r),!this.Tr.Lr(r.format))throw Error(`Saving '${r.format}' files is not supported`);if(r.quality<0||r.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(r.scale<=0)throw Error("Scale factor must be greater than 0");r.scale>10&&console.warn("Large scale factors may result in very large files and slow performance"),r.format==="jpg"&&r.backgroundColor==="transparent"&&(r.backgroundColor="black")}Or(r,s={}){const i=this.Mr(s);if(this.jr(i),i.scale===1&&i.backgroundColor==="transparent")return this.Fr.Pr(r.canvas,i);const o=this.$r.Er(r,i.scale,i.backgroundColor);return this.Fr.Pr(o,i)}async zr(r,s={}){const i=this.Mr(s);if(this.jr(i),i.scale===1&&i.backgroundColor==="transparent")return await this.Fr.zr(r.canvas,i);const o=this.$r.Er(r,i.scale,i.backgroundColor);return await this.Fr.zr(o,i)}async Gr(r,s={}){const i=await this.zr(r,s),o=s.format??"png",n=s.filename||this.Tr.Ks();this.Tr.Gr(i,n,o)}}const Bt=l=>class extends l{toString(r={}){return new ht().kr({pipeline:this.Hr,grid:this._s,font:this.Se},r)}saveStrings(r={}){new ht().Vr({pipeline:this.Hr,grid:this._s,font:this.Se},r)}toSVG(r={}){return new at().Sr(this,r)}saveSVG(r={}){new at().yr(this,r)}async saveCanvas(r,s="png",i={}){await new It().Gr(this.Ze,{...i,filename:r,format:s})}},Ot=l=>class extends l{async loadFont(r){return this.Se.We(r).then(()=>{const s=this.Se.maxGlyphDimensions;this._s.es(s.width,s.height),this.Hr.ns()})}fontSize(r){if(!_.m(typeof r=="number"&&r>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:r})||this.Se.fontSize===r)return;this.Se.Be(r);const s=this.Se.maxGlyphDimensions;this._s.es(s.width,s.height),this.Hr.ns(),this.be.Wt()}},Lt=l=>class extends l{addConverter(r){return this.Hr.add(r)}removeConverter(r){this.Hr.remove(r)}};class kt{constructor(){c(this,"be");c(this,"Se");c(this,"Hr");c(this,"Ze");c(this,"_s")}}class j extends function(s,...i){return i.reduce((o,n)=>n(o),s)}(kt,yt,Bt,Ot,Lt){constructor(s=null,i={}){super();c(this,"ls");c(this,"Br");c(this,"us");c(this,"Wr");c(this,"Nr");c(this,"Xr",null);c(this,"qr",0);c(this,"Yr");c(this,"Qr",!0);c(this,"Zr",0);c(this,"Jr",0);c(this,"Kr",0);c(this,"ti",[]);c(this,"ei",10);c(this,"si",!1);c(this,"ri",!1);c(this,"ii",()=>{});c(this,"oi",()=>{});c(this,"ni");this.ls=s,this.ri=s===null,this.Wr=i.renderMode??"auto",this.Nr=i.frameRate??60,this.Yr=1e3/this.Nr}static async create(s=null,i={}){const o=new this(s,i),n=o.ri?i:void 0;let a,h;o.Ze=new st(o.ls,o.ri,n),o.be=new ft(o.Ze.ps()),o.ri?(a=i.width||800,h=i.height||600):(a=o.Ze.width||800,h=o.Ze.height||600),o.Br=o.be.Ot(a,h),o.Se=new et(o.be,i.fontSize??16),await o.Se.je(i.fontSource);const u=o.Se.maxGlyphDimensions;return o._s=new rt(o.Ze.canvas,u.width,u.height),o.Hr=new nt(o.be,o.Se,o._s),o.ai(),o.hi(),o}ai(){this.ni=()=>{this.ri?this.oi():this.li()},window.addEventListener("resize",this.ni),window.ResizeObserver&&this.ls&&!this.ri&&(this.us=new ResizeObserver(()=>{this.li()}),this.us.observe(this.ls))}render(){this.ci(),this.Kr++,this.si?console.warn("Cannot render: Required resources have been disposed"):(this.ri?(this.Br.begin(),this.ii(),this.Br.end()):this.Br.P(this.ls),this.Hr.hasEnabledConverters()?(this.Hr.Bs(this.Br),this.be.Ht(0),this.be.Nt(this.Hr.texture,this._s.offsetX,this._s.offsetY,this.Hr.texture.width,this.Hr.texture.height)):(this.be.Bt(),this.be.Nt(this.Br,this._s.offsetX,this._s.offsetY,this.Br.width,this.Br.height)))}li(){this.Ze.ns(),this.Br.resize(this.Ze.width,this.Ze.height),this._s.ns(),this.Hr.ns(),this.be.Wt(),this.Wr!=="manual"&&this.render()}hi(){if(this.Wr!=="auto"||!this.Qr)return;this.qr=performance.now();const s=i=>{if(!this.Qr)return void(this.Xr=null);const o=i-this.qr;o>=this.Yr&&(this.render(),this.qr=i-o%this.Yr),this.Qr&&(this.Xr=requestAnimationFrame(s))};this.Xr=requestAnimationFrame(s)}ci(){const s=performance.now();if(this.Jr>0){const i=s-this.Jr;this.ti.push(i),this.ti.length>this.ei&&this.ti.shift();const o=this.ti.reduce((n,a)=>n+a,0)/this.ti.length;this.Zr=1e3/o}this.Jr=s}ui(){this.Xr&&(cancelAnimationFrame(this.Xr),this.Xr=null)}renderMode(s){this.Wr!==s&&(this.ui(),this.Wr=s,s==="auto"&&this.Qr&&this.hi())}frameRate(s){if(s===void 0)return this.Zr;this.Nr=s,this.Yr=1e3/s,this.Wr==="auto"&&this.Qr&&(this.ui(),this.hi())}noLoop(){this.Qr&&(this.Qr=!1,this.Xr&&(cancelAnimationFrame(this.Xr),this.Xr=null))}loop(){this.Qr||(this.Qr=!0,this.Wr==="auto"&&this.hi())}redraw(s=1){if(_.m(typeof s=="number"&&s>0&&Number.isInteger(s),"Redraw count must be a positive integer.",{method:"redraw",providedValue:s}))for(let i=0;i<s;i++)this.render()}isLooping(){return this.Wr==="auto"&&this.Qr}draw(s){this.ii=s}windowResized(s){this.oi=s}resizeCanvas(s,i){this.ri&&(this.Ze.ns(s,i),this.Br.resize(this.Ze.width,this.Ze.height),this._s.ns(),this.Hr.ns(),this.be.Wt(),this.Wr!=="manual"&&this.render())}destroy(){this.si||(this.ui(),window.removeEventListener("resize",this.ni),this.us&&this.us.disconnect(),this.Hr.A(),this.Se.A(),this.Br.A(),this.be.A(),this.si=!0)}get grid(){return this._s}get font(){return this.Se}get mode(){return this.Wr}get pipeline(){return this.Hr}get frameCount(){return this.Kr}get renderer(){return this.be}set frameCount(s){this.Kr=s}get width(){return this.Ze.width}get height(){return this.Ze.height}get canvas(){return this.Ze}get isDisposed(){return this.si}}class V{constructor(){throw new v("Textmode is a static class and cannot be instantiated.")}static async create(r,s={}){if(!(r==null||r instanceof HTMLCanvasElement||r instanceof HTMLVideoElement||typeof r=="object"))throw new v("First parameter must be HTMLCanvasElement, HTMLVideoElement, or options object.");if(typeof s!="object")throw new v("Second parameter must be an options object.");if(r instanceof HTMLCanvasElement||r instanceof HTMLVideoElement)return j.create(r,s);{const i=r||{};return j.create(null,i)}}static setErrorLevel(r){_._(r)}static get version(){return"0.1.9"}}const Vt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),zt=Object.freeze(Object.defineProperty({__proto__:null,DEFAULT_FRAMEBUFFER_OPTIONS:{filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte"},Framebuffer:q,Shader:Q},Symbol.toStringTag,{value:"Module"})),Nt=V.create,Ht=V.setErrorLevel,Wt=V.version;w.TextmodeCanvas=st,w.TextmodeColorPalette=it,w.TextmodeConversionPipeline=nt,w.TextmodeErrorLevel=M,w.TextmodeFont=et,w.TextmodeGrid=rt,w.Textmodifier=j,w.converters=Ft,w.create=Nt,w.export=Vt,w.rendering=zt,w.setErrorLevel=Ht,w.textmode=V,w.version=Wt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):e((t=typeof globalThis<"u"?globalThis:t||self).textmode={});
25
+ `;return i.join(n)}}class Bt extends V{tr(s,r){const i=this.er(r);this.yi(s,i,"text/plain;charset=utf-8")}er(s){let r=this.bi(s);return r===".txt"||r.length<=4?this.Ti():r}}class K{constructor(){u(this,"Ni");u(this,"Xi");u(this,"Yi");this.Ni=new Ut,this.Xi=new zt,this.Yi=new Bt}Qi(s){return{preserveTrailingSpaces:s.preserveTrailingSpaces??!1,lineEnding:s.lineEnding??"lf",emptyCharacter:s.emptyCharacter??" ",filename:s.filename||this.Yi.Ti()}}sr(s,r={}){const i=this.Qi(r),n=this.Ni.Ji(this.Ni._i(s.pipeline),s.grid,s.font,i.emptyCharacter);return this.Xi.Ki(n,i)}tr(s,r={}){this.Yi.tr(this.sr(s,r),r.filename)}}class Ot extends N{ir(s,r=1,i="transparent"){const n=s.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 $t{rr(s,r){const i=this.nr(r.format);return r.format==="png"?s.toDataURL(i):s.toDataURL(i,r.quality)}async ar(s,r){return new Promise((i,n)=>{const o=this.nr(r.format),a=h=>{h?i(h):n(Error(`Failed to generate ${r.format.toUpperCase()} blob`))};r.format==="png"?s.toBlob(a,o):s.toBlob(a,o,r.quality)})}nr(s){switch(s){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+s)}}}const Wt={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},Q={png:".png",jpg:".jpg",webp:".webp"};class Gt extends V{hr(s,r,i){this.cr(s,this.bi(r)+Q[i])}cr(s,r){const i=URL.createObjectURL(s);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)}}lr(s){return s in Wt&&s in Q}}class Nt{constructor(){u(this,"Ni");u(this,"Xi");u(this,"Yi");this.Ni=new Ot,this.Xi=new $t,this.Yi=new Gt}Qi(s){return{format:s.format??"png",quality:s.quality??1,scale:s.scale??1,backgroundColor:s.backgroundColor??"transparent",filename:s.filename||this.Yi.Ti()}}ur(s){if(!this.Yi.lr(s.format))throw Error(`Saving '${s.format}' files is not supported`);if(s.quality<0||s.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(s.scale<=0)throw Error("Scale factor must be greater than 0");s.format==="jpg"&&s.backgroundColor==="transparent"&&(s.backgroundColor="black")}async ar(s,r){if(r.scale===1&&r.backgroundColor==="transparent")return await this.Xi.ar(s.canvas,r);const i=this.Ni.ir(s,r.scale,r.backgroundColor);return await this.Xi.ar(i,r)}async hr(s,r={}){const i=this.Qi(r);this.ur(i);const n=await this.ar(s,i);this.Yi.hr(n,i.filename,i.format)}}const Vt=c=>class extends c{dr(){this.Cs.Ve(this.pr)}toString(s={}){return this.dr(),new K().sr({pipeline:this.gr,grid:this._r,font:this.Ps},s)}saveStrings(s={}){this.dr(),new K().tr({pipeline:this.gr,grid:this._r,font:this.Ps},s)}toSVG(s={}){return this.dr(),new Z().Zi(this,s)}saveSVG(s={}){this.dr(),new Z().qi(this,s)}async saveCanvas(s={}){await new Nt().hr(this.Js,s)}},kt=c=>class extends c{async loadFont(s){return this.Ps.Ns(s).then(()=>{const r=this.Ps.maxGlyphDimensions;this._r.ei(r.width,r.height),this.Cs.ke()})}fontSize(s){if(!M._(typeof s=="number"&&s>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:s})||this.Ps.fontSize===s)return;this.Ps.qs(s);const r=this.Ps.maxGlyphDimensions;this._r.ei(r.width,r.height),this.Cs.ke()}},Xt=c=>class extends c{get frameCount(){return this.mr.frameCount}set frameCount(s){this.mr.frameCount=s}frameRate(s){return s===void 0?this.mr.currentFrameRate:this.mr.frameRate(s,()=>this.vr())}noLoop(){this.mr.pause()}loop(){this.mr.resume(()=>this.vr())}redraw(s=1){if(M._(typeof s=="number"&&s>0&&Number.isInteger(s),"Redraw count must be a positive integer.",{method:"redraw",providedValue:s}))for(let r=0;r<s;r++)this.vr()}isLooping(){return this.mr.isLooping}};class Yt{constructor(){u(this,"Cs");u(this,"Ps");u(this,"Js");u(this,"_r");u(this,"mr");u(this,"pr");u(this,"gr");u(this,"Cr")}vr(){}}class tt extends function(r,...i){return i.reduce((n,o)=>o(n),r)}(Yt,St,Vt,kt,Xt){constructor(r={}){super();u(this,"yr",!1);u(this,"wr",()=>{});u(this,"$r",()=>{});u(this,"br");this.Js=new q(r),this.Cs=new yt(this.Js.ni()),this.Ps=new H(this.Cs,r.fontSize??16),this.mr=new Ft(r.frameRate??60),this.pr=this.Cs.Ae(`#version 300 es
26
+ 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 float 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;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}vec2 evaluateBezier(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float oneMinusT=1.0-t;float oneMinusT2=oneMinusT*oneMinusT;float oneMinusT3=oneMinusT2*oneMinusT;float t2=t*t;float t3=t2*t;return oneMinusT3*p0+3.0*oneMinusT2*t*p1+3.0*oneMinusT*t2*p2+t3*p3;}vec2 evaluateBezierDerivative(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float oneMinusT=1.0-t;float oneMinusT2=oneMinusT*oneMinusT;float t2=t*t;return-3.0*oneMinusT2*p0+3.0*oneMinusT2*p1-6.0*oneMinusT*t*p1+6.0*oneMinusT*t*p2-3.0*t2*p2+3.0*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 isBezierCurve=length(a_instanceBezierCP1)>0.0||length(a_instanceBezierCP2)>0.0||length(a_instanceBezierStart)>0.0||length(a_instanceBezierEnd)>0.0;bool isArc=a_instanceArcAngles.x!=0.0||a_instanceArcAngles.y!=0.0;if(isBezierCurve){float t=a_position.x;float thicknessOffset=a_position.y;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 tangentLength=length(tangent);if(tangentLength>0.0){tangent=tangent/tangentLength;}else{tangent=vec2(1.0,0.0);}vec2 normal=vec2(-tangent.y,tangent.x);float thickness=a_instanceSize.y;vec2 thicknessVector=normal*thicknessOffset*thickness;worldPosition=curvePoint+thicknessVector;}else if(isArc){float startA=a_instanceArcAngles.x;float stopA=a_instanceArcAngles.y;float TWO_PI=6.28318530718;startA=mod(startA,TWO_PI);if(startA<0.0)startA+=TWO_PI;stopA=mod(stopA,TWO_PI);if(stopA<0.0)stopA+=TWO_PI;float cwDelta=startA-stopA;if(cwDelta<=0.0)cwDelta+=TWO_PI;float angle=startA-a_position.x*cwDelta;float r=a_position.y;vec2 local=vec2(cos(angle),sin(angle))*r;vec2 scaledPosition=local*a_instanceSize*0.5+vec2(a_instanceSize.x*0.5,a_instanceSize.y*0.5);worldPosition=scaledPosition+a_instancePosition;}else{vec2 scaledPosition=a_position*a_instanceSize;worldPosition=scaledPosition+a_instancePosition;}vec2 ndc=(worldPosition/u_viewportSize)*2.0-1.0;ndc.y=-ndc.y;if(a_instanceGlobalRotation!=0.0){ndc-=a_instanceRotationCenter;ndc.x*=u_aspectRatio;ndc=rotate2D(-a_instanceGlobalRotation)*ndc;ndc.x/=u_aspectRatio;ndc+=a_instanceRotationCenter;}gl_Position=vec4(ndc,0.0,1.0);}`,`#version 300 es
27
+ 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.Cr=this.Cs.Ae("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);}")}static async create(r={}){const i=new this(r);await i.Ps.Us(r.fontSource);const n=i.Ps.maxGlyphDimensions;return i._r=new J(i.Js.canvas,n.width,n.height),i.gr=i.Cs.Le(i._r.cols,i._r.rows,5),i.Tr(),i.mr.start(()=>i.vr()),i}Tr(){this.br=()=>{this.$r()},window.addEventListener("resize",this.br)}vr(){this.mr.measureFrameRate(),this.mr.incrementFrame(),this.yr||(this.gr.V(),this.Cs.Se(this.pr),this.wr(),this.Cs.Ve(this.pr),this.gr.O(),this.Cs.We(0),this.Cs.Se(this.Cr),this.Cr.et({u_characterTexture:this.Ps.fontFramebuffer,u_charsetDimensions:[this.Ps.textureColumns,this.Ps.textureRows],u_asciiCharacterTexture:this.gr.textures[0],u_primaryColorTexture:this.gr.textures[1],u_secondaryColorTexture:this.gr.textures[2],u_transformTexture:this.gr.textures[4],u_rotationTexture:this.gr.textures[3],u_gridCellDimensions:[this._r.cols,this._r.rows],u_gridPixelDimensions:[this._r.width,this._r.height],u_gridOffsetPixels:[this._r.offsetX,this._r.offsetY],u_aspectRatio:this._r.width/this._r.height}),this.Cs.Pe(this._r.offsetX,this._r.offsetY,this._r.width,this._r.height))}draw(r){this.wr=r}windowResized(r){this.$r=r}resizeCanvas(r,i){this.Js.L(r,i),this._r.Ct(),this.gr.L(this._r.cols,this._r.rows),this.Cs.ke(),this.vr()}destroy(){this.yr||(this.mr.stop(),window.removeEventListener("resize",this.br),this.Ps.U(),this.Cs.U(),this.yr=!0)}get grid(){return this._r}get font(){return this.Ps}get width(){return this.Js.width}get height(){return this.Js.height}get canvas(){return this.Js.canvas}get isDisposed(){return this.yr}get drawFramebuffer(){return this.gr}}class W{constructor(){throw new C("Textmode is a static class and cannot be instantiated.")}static async create(s){return tt.create(s)}static setErrorLevel(s){M.m(s)}static get version(){return"0.2.0-beta.1"}}const jt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),Ht=W.create,Jt=W.setErrorLevel,qt=W.version;T.TextmodeCanvas=q,T.TextmodeErrorLevel=S,T.TextmodeFont=H,T.TextmodeGrid=J,T.Textmodifier=tt,T.create=Ht,T.export=jt,T.setErrorLevel=Jt,T.textmode=W,T.version=qt,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):e((t=typeof globalThis<"u"?globalThis:t||self).textmode={});
@@ -8,53 +8,25 @@ import { Textmodifier, type TextmodeOptions } from './textmode/Textmodifier';
8
8
  export declare class Textmode {
9
9
  private constructor();
10
10
  /**
11
- * Create a {@link Textmodifier} instance for textmode rendering.
11
+ * Create a new Textmodifier instance with optional configuration.
12
12
  *
13
- * @param sourceOrOptions - Either a `HTMLCanvasElement` or `HTMLVideoElement` for capturing content, or options for standalone mode.
14
- * @param opts - Optional configuration options *(only used when first parameter is a `HTMLCanvasElement` or `HTMLVideoElement`)*.
15
- * @returns A Promise that resolves to a {@link Textmodifier} instance.
13
+ * @param opts Configuration options for the Textmodifier instance
14
+ * @returns Promise that resolves to a new Textmodifier instance
16
15
  *
17
16
  * @example
18
- * Creating a {@link Textmodifier} for an existing canvas:
19
17
  * ```javascript
20
- * const canvas = document.querySelector('canvas#myCanvas');
21
- * const textmodifier = await textmode.create(canvas);
22
- * ```
23
- *
24
- * @example
25
- * Creating a {@link Textmodifier} for a video element:
26
- * ```javascript
27
- * const video = document.querySelector('video#myVideo');
28
- * const textmodifier = await textmode.create(video);
29
- * ```
30
- *
31
- * @example
32
- * Creating a standalone {@link Textmodifier} with animation:
33
- * ```javascript
34
- * const t = await textmode.create({ width: 800, height: 600 });
35
- *
36
- * // Set up a draw loop for standalone usage
37
- * t.draw(() => {
38
- * t.background(0);
39
- *
40
- * const centerX = t.width / 2;
41
- * const centerY = t.height / 2;
42
- * const radius = Math.min(t.width, t.height) / 3;
43
- * const speed = 0.02; // Adjust speed of rotation
18
+ * // Create with default canvas
19
+ * const textmodifier = await textmode.create();
44
20
  *
45
- * const angle = t.frameCount * speed;
46
- * const x = centerX + Math.cos(angle) * radius - 100;
47
- * const y = centerY + Math.sin(angle) * radius - 50;
48
21
  *
49
- * // Set the fill color to white
50
- * t.fill(255);
22
+ * // Create with options
23
+ * const textmodifier = await textmode.create({ width: 1920, height: 1080 });
51
24
  *
52
- * // Draw a rectangle with the fill color
53
- * t.rect(x, y, 200, 150);
54
- * });
25
+ * // Create with canvas and options
26
+ * const textmodifier = await textmode.create({ canvas: canvas, fontSize: 20 });
55
27
  * ```
56
28
  */
57
- static create(sourceOrOptions?: HTMLCanvasElement | HTMLVideoElement | TextmodeOptions, opts?: TextmodeOptions): Promise<Textmodifier>;
29
+ static create(opts: TextmodeOptions): Promise<Textmodifier>;
58
30
  /**
59
31
  * Set the global error handling level for the library. This applies to all {@link Textmodifier} instances present.
60
32
  *
@@ -1,4 +1,4 @@
1
- import type { TextmodeConversionPipeline } from '../../textmode/ConversionPipeline';
1
+ import type { GLFramebuffer } from '../../rendering';
2
2
  import type { FramebufferData } from '../svg/types';
3
3
  /**
4
4
  * Base class for data extraction from textmode framebuffers.
@@ -7,10 +7,10 @@ import type { FramebufferData } from '../svg/types';
7
7
  export declare abstract class DataExtractor {
8
8
  /**
9
9
  * Extracts pixel data from all framebuffers needed for export
10
- * @param pipeline The conversion pipeline containing framebuffers
10
+ * @param framebuffer The conversion pipeline containing framebuffers
11
11
  * @returns Object containing all pixel data arrays
12
12
  */
13
- $extractFramebufferData(pipeline: TextmodeConversionPipeline): FramebufferData;
13
+ $extractFramebufferData(framebuffer: GLFramebuffer): FramebufferData;
14
14
  /**
15
15
  * Gets character index from character framebuffer pixels
16
16
  * @param characterPixels Character framebuffer pixel data
@@ -1,4 +1,4 @@
1
- import type { ImageExportOptions } from './types';
1
+ import type { ImageExportOptions, ImageGenerationOptions } from './types';
2
2
  import type { TextmodeCanvas } from '../../index';
3
3
  /**
4
4
  * Main image exporter for the textmode.js library.
@@ -22,24 +22,17 @@ export declare class ImageExporter {
22
22
  * @throws Error if options are invalid or format is not supported
23
23
  */
24
24
  private _validateOptions;
25
- /**
26
- * Generates image data from textmode rendering without saving to file
27
- * @param canvas The canvas data containing the rendered textmode graphics
28
- * @param options Export options (excluding filename)
29
- * @returns Data URL string containing the image data
30
- */
31
- $generateImage(canvas: TextmodeCanvas, options?: Omit<ImageExportOptions, 'filename'>): string;
32
25
  /**
33
26
  * Generates image blob from textmode rendering without saving to file
34
27
  * @param canvasData The canvas data containing the rendered textmode graphics
35
- * @param options Export options (excluding filename)
28
+ * @param options Export options
36
29
  * @returns Promise that resolves to a Blob containing the image data
37
30
  */
38
- $generateImageBlob(canvas: TextmodeCanvas, options?: Omit<ImageExportOptions, 'filename'>): Promise<Blob>;
31
+ $generateImageBlob(canvas: TextmodeCanvas, options: ImageGenerationOptions): Promise<Blob>;
39
32
  /**
40
33
  * Exports image to a downloadable file
41
34
  * @param canvas The canvas data containing the rendered textmode graphics
42
- * @param options Export options including filename
35
+ * @param options Export options
43
36
  */
44
37
  $saveImage(canvas: TextmodeCanvas, options?: ImageExportOptions): Promise<void>;
45
38
  }
@@ -11,14 +11,12 @@ export type ImageFormat = 'png' | 'jpg' | 'webp';
11
11
  export type ImageExportOptions = {
12
12
  /**
13
13
  * The filename to save the image file as (without extension).
14
- * @ignore
15
14
  */
16
15
  filename?: string;
17
16
  /**
18
17
  * The image format to export (`'png'`, `'jpg'`, or `'webp'`).
19
- * @ignore
20
18
  */
21
- format?: ImageFormat;
19
+ format?: 'png' | 'jpg' | 'webp';
22
20
  /**
23
21
  * Image quality for lossy formats (`'jpg'`, `'webp'`).
24
22
  *
@@ -48,6 +46,7 @@ export type ImageExportOptions = {
48
46
  * Internal options used by image generation (with all defaults applied).
49
47
  */
50
48
  export interface ImageGenerationOptions {
49
+ filename: string;
51
50
  format: ImageFormat;
52
51
  quality: number;
53
52
  scale: number;
@@ -21,7 +21,7 @@ export declare class SVGExporter {
21
21
  * @param options Export options (excluding filename)
22
22
  * @returns SVG content as string
23
23
  */
24
- $generateSVG(textmodifier: any, options?: Omit<SVGExportOptions, 'filename'>): string;
24
+ $generateSVG(textmodifier: any, options?: SVGExportOptions): string;
25
25
  /**
26
26
  * Exports SVG content to a downloadable file
27
27
  * @param textmodifier The textmodifier instance containing rendering data
@@ -116,4 +116,5 @@ export interface SVGGenerationOptions {
116
116
  drawMode: 'fill' | 'stroke';
117
117
  strokeWidth: number;
118
118
  backgroundColor: [number, number, number, number];
119
+ filename: string;
119
120
  }
@@ -21,7 +21,7 @@ export declare class TXTExporter {
21
21
  * @param options Export options (excluding filename)
22
22
  * @returns TXT content as string
23
23
  */
24
- $generateTXT(renderingData: TextmodeRenderingData, options?: Omit<TXTExportOptions, 'filename'>): string;
24
+ $generateTXT(renderingData: TextmodeRenderingData, options?: TXTExportOptions): string;
25
25
  /**
26
26
  * Exports TXT content to a downloadable file
27
27
  * @param renderingData The textmode rendering data containing pipeline, grid, and font