textmode.js 0.2.0-beta.1 → 0.2.0-beta.3

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.
@@ -1,27 +1,28 @@
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+=`
1
+ var te=Object.defineProperty;var ee=(b,v,L)=>v in b?te(b,v,{enumerable:!0,configurable:!0,writable:!0,value:L}):b[v]=L;var u=(b,v,L)=>ee(b,typeof v!="symbol"?v+"":v,L);var t,e;t=this,e=function(b){class v extends Error{constructor(r,i={}){super(v.i(r,i)),this.name="TextmodeError"}static i(r,i){let s=r;if(i&&Object.keys(i).length>0){s+=`
2
2
 
3
- 📋 Context:`;for(const[n,o]of Object.entries(r))i+=`
4
- - ${n}: ${C.o(o)}`}return i+=`
3
+ 📋 Context:`;for(const[n,o]of Object.entries(i))s+=`
4
+ - ${n}: ${v.o(o)}`}return s+=`
5
5
 
6
- `,i+="↓".repeat(24)+`
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"?>
6
+ `,s+="↓".repeat(24)+`
7
+ `,s}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(i=>v.o(i)).join(", ")}]`:`[${r.slice(0,3).map(i=>v.o(i)).join(", ")}, ... +${r.length-3} more]`;if(typeof r=="object"){const i=Object.keys(r);return i.length===0?"{}":i.length<=3?`{ ${i.map(s=>`${s}: ${v.o(r[s])}`).join(", ")} }`:`{ ${i.slice(0,2).map(s=>`${s}: ${v.o(r[s])}`).join(", ")}, ... +${i.length-2} more }`}return r+""}}var L=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(L||{});const I=class I{constructor(){u(this,"u",{globalLevel:3})}static p(){return I.l||(I.l=new I),I.l}_(r,i){const s="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",n="color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";switch(this.u.globalLevel){case 0:return!1;case 1:return console.group(s,n),console.warn(v.i(r,i)),console.groupEnd(),!1;case 2:return console.group(s,n),console.error(v.i(r,i)),console.groupEnd(),!1;default:throw new v(r,i)}}m(r,i,s){return!!r||(this._(i,s),!1)}v(r){this.u.globalLevel=r}};u(I,"l",null);let k=I;const z=k.p(),H=new WeakMap;function G(c,r){H.set(c,r)}function D(c){return H.get(c)}class N{constructor(r,i,s=i,n=1,o={}){u(this,"C");u(this,"$");u(this,"u");u(this,"R",null);u(this,"S");u(this,"M");u(this,"F",[]);u(this,"G");u(this,"D",null);u(this,"P",[]);this.C=i,this.$=s,this.u={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.S=r,this.G=Math.min(Math.max(1,n),8);const a=r.getParameter(r.MAX_DRAW_BUFFERS),h=r.getParameter(r.MAX_COLOR_ATTACHMENTS);this.G=Math.min(this.G,a,h),this.M=r.createFramebuffer(),this.A(),this.I(),this.P=Array(this.G).fill(null)}A(){const r=this.S,i=this.u.filter==="linear"?r.LINEAR:r.NEAREST,s=this.u.wrap==="repeat"?r.REPEAT:r.CLAMP_TO_EDGE,n=this.u.type==="float"?r.FLOAT:r.UNSIGNED_BYTE;for(let o=0;o<this.G;o++){const a=r.createTexture();r.bindTexture(r.TEXTURE_2D,a),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,i),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,i),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,s),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,s),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.C,this.$,0,r.RGBA,n,null),this.F.push(a)}r.bindTexture(r.TEXTURE_2D,null)}I(){const r=this.S;if(r.bindFramebuffer(r.FRAMEBUFFER,this.M),this.G===1)r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,this.F[0],0);else{const s=[];for(let n=0;n<this.G;n++){const o=r.COLOR_ATTACHMENT0+n;r.framebufferTexture2D(r.FRAMEBUFFER,o,r.TEXTURE_2D,this.F[n],0),s.push(o)}r.drawBuffers(s)}const i=r.checkFramebufferStatus(r.FRAMEBUFFER);i!==r.FRAMEBUFFER_COMPLETE&&console.error("GLFramebuffer is not complete:",i),r.bindFramebuffer(r.FRAMEBUFFER,null)}L(r){const i=this.S;i.bindTexture(i.TEXTURE_2D,this.F[0]),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,1),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,r),i.bindTexture(i.TEXTURE_2D,null)}W(r,i){this.C=r,this.$=i,this.R=null,this.P=Array(this.G).fill(null);const s=this.S,n=this.u.type==="float"?s.FLOAT:s.UNSIGNED_BYTE;for(const o of this.F)s.bindTexture(s.TEXTURE_2D,o),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,this.C,this.$,0,s.RGBA,n,null);s.bindTexture(s.TEXTURE_2D,null)}k(r){const i=this.S;if(r<0||r>=this.G)throw Error(`GLFramebuffer: attachment index ${r} out of range (count=${this.G})`);const s=this.P[r];if(s)return s;const n=this.C,o=this.$,a=new Uint8Array(n*o*4),h=i.getParameter(i.READ_FRAMEBUFFER_BINDING);i.bindFramebuffer(i.READ_FRAMEBUFFER,this.M),i.readBuffer(i.COLOR_ATTACHMENT0+r),i.readPixels(0,0,n,o,i.RGBA,i.UNSIGNED_BYTE,a),i.bindFramebuffer(i.READ_FRAMEBUFFER,h);const l=4*n,f=new Uint8Array(a.length);for(let g=0;g<o;g++){const d=(o-1-g)*l,p=g*l;f.set(a.subarray(d,d+l),p)}return this.P[r]=f,f}U(){for(let r=0;r<this.G;r++)this.k(r)}V(){const r=this.S;this.D={framebuffer:r.getParameter(r.FRAMEBUFFER_BINDING),viewport:r.getParameter(r.VIEWPORT)},r.bindFramebuffer(r.FRAMEBUFFER,this.M),this.P=Array(this.G).fill(null);for(let i=0;i<this.G;i++)r.clearBufferfv(r.COLOR,i,new Float32Array([0,0,0,0]));r.viewport(0,0,this.C,this.$),G(r,[0,0,this.C,this.$])}O(){if(!this.D)return;const r=this.S;r.bindFramebuffer(r.FRAMEBUFFER,this.D.framebuffer),r.viewport(...this.D.viewport),G(r,this.D.viewport),this.D=null}j(){const r=this.S;this.M&&r.deleteFramebuffer(this.M);for(const i of this.F)r.deleteTexture(i);this.F=[],this.P=[]}get width(){return this.C}get height(){return this.$}get pixels(){return this.R}get options(){return{...this.u}}get framebuffer(){return this.M}get texture(){return this.F[0]}get textures(){return[...this.F]}get attachmentCount(){return this.G}getAttachmentPixels(r){return this.P[r]??null}}class V{constructor(r,i,s){u(this,"S");u(this,"H");u(this,"X",new Map);u(this,"Y",new Map);u(this,"q",0);u(this,"Z");this.S=r,this.H=this.N(i,s),this.Z=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),this.J()}J(){const r=this.S.getProgramParameter(this.H,this.S.ACTIVE_UNIFORMS);for(let i=0;i<r;i++){const s=this.S.getActiveUniform(this.H,i);if(s){const n=this.S.getUniformLocation(this.H,s.name);n&&(this.X.set(s.name,n),this.Y.set(s.name,s.type))}}}N(r,i){const s=this.K(this.S.VERTEX_SHADER,r),n=this.K(this.S.FRAGMENT_SHADER,i),o=this.S.createProgram();if(this.S.attachShader(o,s),this.S.attachShader(o,n),this.S.linkProgram(o),!this.S.getProgramParameter(o,this.S.LINK_STATUS)){const a=this.S.getProgramInfoLog(o);throw Error("Shader program link error: "+a)}return this.S.deleteShader(s),this.S.deleteShader(n),o}K(r,i){const s=this.S.createShader(r);if(this.S.shaderSource(s,i),this.S.compileShader(s),!this.S.getShaderParameter(s,this.S.COMPILE_STATUS)){const n=this.S.getShaderInfoLog(s);throw this.S.deleteShader(s),Error("Shader compilation error: "+n)}return s}tt(){this.S.useProgram(this.H),this.et()}et(){this.q=0}st(r){for(const[i,s]of Object.entries(r))this.it(i,s)}rt(r){return this.X.has(r)}it(r,i){if(this.S.getParameter(this.S.CURRENT_PROGRAM)!==this.H)return void console.warn(`Attempting to set uniform '${r}' on shader that is not currently bound`);const s=this.X.get(r);if(s)if(typeof i=="number")this.S.uniform1f(s,i);else if(typeof i=="boolean")this.S.uniform1i(s,i?1:0);else if(Array.isArray(i))switch(i.length){case 2:this.S.uniform2f(s,i[0],i[1]);break;case 3:this.S.uniform3f(s,i[0],i[1],i[2]);break;case 4:this.S.uniform4f(s,i[0],i[1],i[2],i[3]);break;default:console.warn(`Unsupported array length ${i.length} for uniform '${r}'`)}else if(i instanceof WebGLTexture){const n=this.nt();this.S.uniform1i(s,n),this.S.activeTexture(this.S.TEXTURE0+n),this.S.bindTexture(this.S.TEXTURE_2D,i)}else if(i instanceof N){const n=this.nt();this.S.uniform1i(s,n),this.S.activeTexture(this.S.TEXTURE0+n),this.S.bindTexture(this.S.TEXTURE_2D,i.texture)}else if(typeof i=="object"&&"texture"in i){const n=this.nt();this.S.uniform1i(s,n),this.S.activeTexture(this.S.TEXTURE0+n),this.S.bindTexture(this.S.TEXTURE_2D,i.texture)}else console.warn(`Unsupported uniform type for '${r}':`,typeof i)}nt(){return this.q>=this.Z&&console.warn(`Exceeded maximum texture units (${this.Z}). Texture may not render correctly.`),this.q++}get ot(){return this.H}j(){this.S.deleteProgram(this.H)}}class st{constructor(){u(this,"ht",1);u(this,"ct",0);u(this,"lt",0);u(this,"ut",0);u(this,"ft",[0,0,0]);u(this,"dt",[1,1,1,1]);u(this,"_t",[0,0,0,1]);u(this,"gt",!1);u(this,"vt",!1);u(this,"xt",!1);u(this,"Ct",[0,0]);u(this,"yt",[0,0,0,1]);u(this,"wt",[])}$t(){this.wt.push({lineWeight:this.ht,rotationX:this.ct,rotationY:this.lt,rotationZ:this.ut,charRotation:[...this.Ct],flipHorizontally:this.gt,flipVertically:this.vt,invert:this.xt,character:[...this.ft],charColor:[...this.dt],cellColor:[...this._t]})}bt(){const r=this.wt.pop();r?(this.ht=r.lineWeight,this.ct=r.rotationX,this.lt=r.rotationY,this.ut=r.rotationZ,this.Ct=r.charRotation,this.gt=r.flipHorizontally,this.vt=r.flipVertically,this.xt=r.invert,this.ft=r.character,this.dt=r.charColor,this._t=r.cellColor):console.warn("pop() called without matching push()")}zt(){this.wt=[],this.ct=0,this.lt=0,this.ut=0}Rt(r){r.lineWeight=this.ht,r.rotationX=this.ct,r.rotationY=this.lt,r.rotationZ=this.ut,r.character[0]=this.ft[0],r.character[1]=this.ft[1],r.character[2]=this.ft[2],r.charColor[0]=this.dt[0],r.charColor[1]=this.dt[1],r.charColor[2]=this.dt[2],r.charColor[3]=this.dt[3],r.bgColor[0]=this._t[0],r.bgColor[1]=this._t[1],r.bgColor[2]=this._t[2],r.bgColor[3]=this._t[3],r.flipHorizontally=this.gt,r.flipVertically=this.vt,r.invert=this.xt,r.charRotation[0]=this.Ct[0],r.charRotation[1]=this.Ct[1]}get lineWeight(){return this.ht}get canvasBackgroundColor(){return this.yt}Tt(r){this.ht=Math.abs(r)}St(r){this.ct=r}Mt(r){this.lt=r}Ft(r){this.ut=r}Gt(r){this.ft=r}Dt(r,i,s,n=255){this.dt=[r/255,i/255,s/255,n/255]}Pt(r,i,s,n=255){this._t=[r/255,i/255,s/255,n/255]}At(r){this.gt=r}Bt(r){this.vt=r}It(r){this.xt=r}Lt(r){const i=255*r/360,s=Math.floor(i)/255,n=Math.round(i-Math.floor(i));this.Ct=[s,n]}Et(r,i,s,n){this.yt=[r/255,i/255,s/255,n/255]}}var j=`#version 300 es
8
+ in vec2 a_position;in vec2 a_texCoord;in vec2 a_instancePosition;in vec2 a_instanceSize;in vec3 a_instanceCharacter;in vec4 a_instancePrimaryColor;in vec4 a_instanceSecondaryColor;in vec2 a_instanceRotation;in vec3 a_instanceTransform;in vec3 a_instanceGlobalRotation;in vec2 a_instanceRotationCenter;in vec2 a_instanceBezierCP1;in vec2 a_instanceBezierCP2;in vec2 a_instanceBezierStart;in vec2 a_instanceBezierEnd;in vec2 a_instanceArcAngles;uniform float u_aspectRatio;uniform vec2 u_viewportSize;out vec2 v_uv;out vec3 v_character;out vec4 v_primaryColor;out vec4 v_secondaryColor;out vec2 v_rotation;out vec3 v_transform;mat3 rotateX(float a){float s=sin(a),c=cos(a);return mat3(1,0,0,0,c,-s,0,s,c);}mat3 rotateY(float a){float s=sin(a),c=cos(a);return mat3(c,0,s,0,1,0,-s,0,c);}mat3 rotateZ(float a){float s=sin(a),c=cos(a);return mat3(c,-s,0,s,c,0,0,0,1);}vec2 evaluateBezier(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float u=1.-t,u2=u*u,t2=t*t;return u2*u*p0+3.*u2*t*p1+3.*u*t2*p2+t2*t*p3;}vec2 evaluateBezierDerivative(float t,vec2 p0,vec2 p1,vec2 p2,vec2 p3){float u=1.-t,u2=u*u,t2=t*t;return-3.*u2*p0+3.*u2*p1-6.*u*t*p1+6.*u*t*p2-3.*t2*p2+3.*t2*p3;}void main(){v_uv=a_texCoord;v_character=a_instanceCharacter;v_primaryColor=a_instancePrimaryColor;v_secondaryColor=a_instanceSecondaryColor;v_rotation=a_instanceRotation;v_transform=a_instanceTransform;vec2 worldPosition;bool isBezier=length(a_instanceBezierCP1)+length(a_instanceBezierCP2)+length(a_instanceBezierStart)+length(a_instanceBezierEnd)>0.;bool isArc=a_instanceArcAngles.x!=0.||a_instanceArcAngles.y!=0.;if(isBezier){float t=a_position.x;vec2 curvePoint=evaluateBezier(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);vec2 tangent=evaluateBezierDerivative(t,a_instanceBezierStart,a_instanceBezierCP1,a_instanceBezierCP2,a_instanceBezierEnd);float tLen=length(tangent);tangent=tLen>0.?tangent/tLen:vec2(1,0);worldPosition=curvePoint+vec2(-tangent.y,tangent.x)*a_position.y*a_instanceSize.y;}else if(isArc){float s=a_instanceArcAngles.x,e=a_instanceArcAngles.y;s=mod(s,6.28318530718);if(s<0.)s+=6.28318530718;e=mod(e,6.28318530718);if(e<0.)e+=6.28318530718;float d=s-e;if(d<=0.)d+=6.28318530718;float angle=s-a_position.x*d;vec2 local=vec2(cos(angle),sin(angle))*a_position.y;worldPosition=local*a_instanceSize*.5+a_instanceSize*.5+a_instancePosition;}else{worldPosition=a_position*a_instanceSize+a_instancePosition;}vec2 ndc=(worldPosition/u_viewportSize)*2.-1.;ndc.y=-ndc.y;if(length(a_instanceGlobalRotation)>0.){vec3 pos3D=vec3(ndc-a_instanceRotationCenter,0);pos3D.x*=u_aspectRatio;if(a_instanceGlobalRotation.x!=0.)pos3D=rotateX(-a_instanceGlobalRotation.x)*pos3D;if(a_instanceGlobalRotation.y!=0.)pos3D=rotateY(-a_instanceGlobalRotation.y)*pos3D;if(a_instanceGlobalRotation.z!=0.)pos3D=rotateZ(-a_instanceGlobalRotation.z)*pos3D;pos3D.x/=u_aspectRatio;ndc=pos3D.xy+a_instanceRotationCenter;}gl_Position=vec4(ndc,0,1);}`,C=(c=>(c.RECTANGLE="rectangle",c.LINE="line",c.ELLIPSE="ellipse",c.ARC="arc",c.TRIANGLE="triangle",c.BEZIER_CURVE="bezier_curve",c.CUSTOM="custom",c))(C||{});class nt{constructor(r){u(this,"S");u(this,"Wt",new Map);this.S=r}kt(r,i,s,n){const o=this.S;let a=this.Wt.get(r);a||(a=new Map,this.Wt.set(r,a));let h=a.get(i)||null;if(!h){h=o.createVertexArray(),a.set(i,h),o.bindVertexArray(h),o.bindBuffer(o.ARRAY_BUFFER,n);const l=o.getAttribLocation(r,"a_position");l!==-1&&(o.enableVertexAttribArray(l),o.vertexAttribPointer(l,s.attributes.position.size,o.FLOAT,!1,s.stride,s.attributes.position.offset),o.vertexAttribDivisor(l,0));const f=o.getAttribLocation(r,"a_texCoord");f!==-1&&(o.enableVertexAttribArray(f),o.vertexAttribPointer(f,s.attributes.texCoord.size,o.FLOAT,!1,s.stride,s.attributes.texCoord.offset),o.vertexAttribDivisor(f,0))}o.bindVertexArray(h)}Ut(){this.S.bindVertexArray(null)}j(){const r=this.S;for(const[,i]of this.Wt)for(const[,s]of i)s&&r.deleteVertexArray(s);this.Wt.clear()}}class ot{constructor(r){u(this,"Vt");u(this,"S");u(this,"Ot",null);u(this,"jt",null);u(this,"Ht",null);this.S=r,this.Vt=new nt(r)}Xt(r,i,s){const{shader:n}=r,o=D(this.S)||this.S.getParameter(this.S.VIEWPORT),a={u_aspectRatio:o[2]/o[3],u_viewportSize:[o[2],o[3]]},h={};for(const[d,p]of Object.entries(a))n.rt(d)&&(h[d]=p);Object.keys(h).length>0&&n.st(h);const l=d=>{if(!d||!d.Yt())return;const p=d.unitGeometry,x=d.unitBuffer;try{this.Vt.kt(n.ot,d.type+"",p,x),d.batch.qt(n),d.batch.Zt(p.primitiveType,p.vertexCount)}finally{d.batch.Nt(n),this.Vt.Ut(),d.Qt()}};let f=null,g=null;for(const d of i){if(d.type===C.CUSTOM){g&&(l(g),f=null,g=null),this.Jt(r,d.params,d.state,s.get(C.RECTANGLE)||null);continue}f!==null&&d.type!==f&&(l(g),f=null,g=null);let p=g;p&&d.type===f||(p=s.get(d.type)||null,g=p,f=d.type),p&&p.Kt(d.params,d.state)}l(g)}Jt(r,i,s,n){if(!n)return;const{x:o,y:a,width:h,height:l,shader:f,uniforms:g}=i,d=this.S;f.tt(),n.Qt();const p=this.te(Math.max(1,Math.floor(h)),Math.max(1,Math.floor(l)));p.V(),f.tt(),g&&Object.keys(g).length&&f.st(g);{const R=D(d)||d.getParameter(d.VIEWPORT);f.rt("u_aspectRatio")&&f.it("u_aspectRatio",R[2]/R[3]),f.rt("u_viewportSize")&&f.it("u_viewportSize",[R[2],R[3]])}const x={...s,rotationX:0,rotationY:0,rotationZ:0};if(n.Kt({x:0,y:0,width:p.width,height:p.height},x),n.Yt()){const R=n.unitGeometry,B=n.unitBuffer;try{this.Vt.kt(f.ot,n.type+"",R,B),n.batch.qt(f),n.batch.Zt(R.primitiveType,R.vertexCount)}finally{n.batch.Nt(f),this.Vt.Ut(),n.Qt()}}p.O();const m=this.ee();m.tt(),m.st({u_src0:p.textures[0],u_src1:p.textures[1],u_src2:p.textures[2],u_src3:p.textures[3],u_src4:p.textures[4],u_srcSize:[p.width,p.height]});const y=D(d)||d.getParameter(d.VIEWPORT);m.rt("u_aspectRatio")&&m.it("u_aspectRatio",y[2]/y[3]),m.rt("u_viewportSize")&&m.it("u_viewportSize",[y[2],y[3]]);const w=Math.floor(o),E=Math.floor(a),T=Math.max(1,Math.floor(h)),A=Math.max(1,Math.floor(l));if(n.Kt({x:w,y:E,width:T,height:A},s),n.Yt()){const R=n.unitGeometry,B=n.unitBuffer;try{this.Vt.kt(m.ot,n.type+"",R,B),n.batch.qt(m),n.batch.Zt(R.primitiveType,R.vertexCount)}finally{n.batch.Nt(m),this.Vt.Ut(),n.Qt()}}r.shader.tt()}ee(){return this.Ot||(this.Ot=new V(this.S,j,`#version 300 es
9
+ precision highp float;in vec2 v_uv;uniform sampler2D u_src0;uniform sampler2D u_src1;uniform sampler2D u_src2;uniform sampler2D u_src3;uniform sampler2D u_src4;uniform vec2 u_srcSize;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){vec2 uvTex=v_uv*u_srcSize;vec2 uvQ=(floor(uvTex)+0.5f)/u_srcSize;o_character=texture(u_src0,uvQ);o_primaryColor=texture(u_src1,uvQ);o_secondaryColor=texture(u_src2,uvQ);o_rotation=texture(u_src3,uvQ);o_transform=texture(u_src4,uvQ);}`)),this.Ot}te(r,i){return this.jt&&this.Ht&&this.Ht.w===r&&this.Ht.h===i||(this.jt&&this.jt.j(),this.jt=new N(this.S,r,i,5),this.Ht={w:r,h:i}),this.jt}}class at{constructor(){u(this,"se",[]);u(this,"ie",1);u(this,"re",0)}ne(r){if(this.re>=this.se.length){const s={id:this.ie++,type:r,params:{},state:{lineWeight:1,rotationX:0,rotationY:0,rotationZ:0,character:[0,0,0],charColor:[1,1,1,1],bgColor:[0,0,0,1],flipHorizontally:!1,flipVertically:!1,invert:!1,charRotation:[0,0]}};this.se.push(s)}const i=this.se[this.re];switch(i.id=this.ie++,i.type=r,r){case C.RECTANGLE:case C.ELLIPSE:i.params&&"width"in i.params||(i.params={x:0,y:0,width:0,height:0});break;case C.CUSTOM:i.params&&"shader"in i.params||(i.params={x:0,y:0,width:0,height:0,shader:void 0,uniforms:{}});break;case C.ARC:i.params&&"start"in i.params||(i.params={x:0,y:0,width:0,height:0,start:0,stop:0});break;case C.LINE:i.params&&"x2"in i.params||(i.params={x1:0,y1:0,x2:0,y2:0,thickness:void 0});break;case C.TRIANGLE:i.params&&"x3"in i.params||(i.params={x1:0,y1:0,x2:0,y2:0,x3:0,y3:0});break;case C.BEZIER_CURVE:i.params&&"cp2y"in i.params||(i.params={x1:0,y1:0,cp1x:0,cp1y:0,cp2x:0,cp2y:0,x2:0,y2:0,thickness:void 0});break;default:i.params||(i.params={})}return this.re++,i}oe(r,i,s,n,o){const a=this.ne(C.RECTANGLE);return a.params.x=r,a.params.y=i,a.params.width=s,a.params.height=n,o.Rt(a.state),a.id}ae(r,i,s,n,o,a,h){const l=this.ne(C.CUSTOM);return l.params.x=r,l.params.y=i,l.params.width=s,l.params.height=n,l.params.shader=o,l.params.uniforms=a,h.Rt(l.state),l.id}he(r,i,s,n,o,a){const h=this.ne(C.LINE);return h.params.x1=r,h.params.y1=i,h.params.x2=s,h.params.y2=n,h.params.thickness=o,a.Rt(h.state),h.id}ce(r,i,s,n,o){const a=this.ne(C.ELLIPSE);return a.params.x=r,a.params.y=i,a.params.width=s,a.params.height=n,o.Rt(a.state),a.id}le(r,i,s,n,o,a,h){const l=this.ne(C.ARC);return l.params.x=r,l.params.y=i,l.params.width=s,l.params.height=n,l.params.start=o,l.params.stop=a,h.Rt(l.state),l.id}ue(r,i,s,n,o,a,h){const l=this.ne(C.TRIANGLE);return l.params.x1=r,l.params.y1=i,l.params.x2=s,l.params.y2=n,l.params.x3=o,l.params.y3=a,h.Rt(l.state),l.id}fe(r,i,s,n,o,a,h,l,f,g){const d=this.ne(C.BEZIER_CURVE);return d.params.x1=r,d.params.y1=i,d.params.cp1x=s,d.params.cp1y=n,d.params.cp2x=o,d.params.cp2y=a,d.params.x2=h,d.params.y2=l,d.params.thickness=f,g.Rt(d.state),d.id}get length(){return this.re}get isEmpty(){return this.re===0}de(){this.re=0}[Symbol.iterator](){let r=0;const i=this.re,s=this.se;return{next:()=>r<i?{value:s[r++],done:!1}:{value:void 0,done:!0}}}}const U=class U{static pe(r,i,s=0){var a,h,l,f,g,d,p,x,m,y;const n=i||new Float32Array(U.FLOATS_PER_INSTANCE);let o=s;return n[o++]=r.position[0],n[o++]=r.position[1],n[o++]=r.size[0],n[o++]=r.size[1],n[o++]=r.character[0],n[o++]=r.character[1],n[o++]=r.character[2],n[o++]=r.primaryColor[0],n[o++]=r.primaryColor[1],n[o++]=r.primaryColor[2],n[o++]=r.primaryColor[3],n[o++]=r.secondaryColor[0],n[o++]=r.secondaryColor[1],n[o++]=r.secondaryColor[2],n[o++]=r.secondaryColor[3],n[o++]=r.rotation[0],n[o++]=r.rotation[1],n[o++]=r.transform[0],n[o++]=r.transform[1],n[o++]=r.transform[2],n[o++]=r.globalRotationX,n[o++]=r.globalRotationY,n[o++]=r.globalRotationZ,n[o++]=r.rotationCenter[0],n[o++]=r.rotationCenter[1],n[o++]=((a=r.arcAngles)==null?void 0:a[0])||0,n[o++]=((h=r.arcAngles)==null?void 0:h[1])||0,n[o++]=((l=r.bezierControlPoint1)==null?void 0:l[0])||0,n[o++]=((f=r.bezierControlPoint1)==null?void 0:f[1])||0,n[o++]=((g=r.bezierControlPoint2)==null?void 0:g[0])||0,n[o++]=((d=r.bezierControlPoint2)==null?void 0:d[1])||0,n[o++]=((p=r.bezierStartPoint)==null?void 0:p[0])||0,n[o++]=((x=r.bezierStartPoint)==null?void 0:x[1])||0,n[o++]=((m=r.bezierEndPoint)==null?void 0:m[0])||0,n[o++]=((y=r.bezierEndPoint)==null?void 0:y[1])||0,n}static _e(r){const i=r.length*U.FLOATS_PER_INSTANCE,s=new Float32Array(i);for(let n=0;n<r.length;n++){const o=n*U.FLOATS_PER_INSTANCE;U.pe(r[n],s,o)}return s}};u(U,"BYTES_PER_INSTANCE",140),u(U,"FLOATS_PER_INSTANCE",35);let P=U;const S=class S{};u(S,"STRIDE",P.BYTES_PER_INSTANCE),u(S,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:92,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:100,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:108,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:116,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:124,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:S.STRIDE,offset:132,divisor:1}});let $=S;class ht{constructor(r,i=1e3,s=1.5){u(this,"S");u(this,"ge",[]);u(this,"me");u(this,"ve");u(this,"xe",null);u(this,"Ce",!0);u(this,"ye",0);u(this,"we",new Map);u(this,"$e",null);this.S=r,this.me=i,this.ve=s,this.be()}Kt(r){const i=this.ge.length;return this.ge.push(r),this.Ce=!0,i}get count(){return this.ge.length}get isEmpty(){return this.ge.length===0}clear(){this.ge.length=0,this.Ce=!0}ze(r){if(r<=this.me)return;const i=Math.ceil(r*this.ve);this.me=i,this.be()}be(){const r=this.S;this.xe&&r.deleteBuffer(this.xe),this.xe=r.createBuffer();const i=this.me*P.BYTES_PER_INSTANCE;r.bindBuffer(r.ARRAY_BUFFER,this.xe),r.bufferData(r.ARRAY_BUFFER,i,r.DYNAMIC_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),this.Ce=!0,this.ye=0}Re(){if(!this.Ce||this.ge.length===0)return;const r=this.S,i=this.ge.length;this.ze(i),(!this.$e||this.$e.length<i*P.FLOATS_PER_INSTANCE)&&(this.$e=new Float32Array(i*P.FLOATS_PER_INSTANCE));const s=P._e(this.ge);r.bindBuffer(r.ARRAY_BUFFER,this.xe),i<=this.ye?r.bufferSubData(r.ARRAY_BUFFER,0,s):r.bufferData(r.ARRAY_BUFFER,s,r.DYNAMIC_DRAW),r.bindBuffer(r.ARRAY_BUFFER,null),this.Ce=!1,this.ye=i}Te(r){let i=this.we.get(r);if(!i){i=new Map;const s=this.S;for(const n in $.ATTRIBUTES){const o=s.getAttribLocation(r,n);o!==-1&&i.set(n,o)}this.we.set(r,i)}return i}qt(r){if(!this.xe||this.ge.length===0)return;const i=this.S,s=r.ot;this.Re();const n=this.Te(s);i.bindBuffer(i.ARRAY_BUFFER,this.xe);for(const[o,a]of n){const h=$.ATTRIBUTES[o];h&&(i.enableVertexAttribArray(a),i.vertexAttribPointer(a,h.size,h.type,h.normalized,h.stride,h.offset),i.vertexAttribDivisor(a,h.divisor))}}Nt(r){const i=this.S,s=this.Te(r.ot);for(const[,n]of s)i.disableVertexAttribArray(n),i.vertexAttribDivisor(n,0)}Zt(r,i){this.ge.length!==0&&this.S.drawArraysInstanced(r,0,i,this.ge.length)}j(){const r=this.S;this.xe&&(r.deleteBuffer(this.xe),this.xe=null),this.ge.length=0,this.we.clear(),this.$e=null}}class M{constructor(r,i,s,n){u(this,"S");u(this,"Se");u(this,"Me");u(this,"Fe");u(this,"Ge",null);this.S=r,this.Se=i,this.Me=s,this.Fe=n;const o=this.S.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.S.bindBuffer(this.S.ARRAY_BUFFER,o),this.S.bufferData(this.S.ARRAY_BUFFER,this.Fe.vertices,this.S.STATIC_DRAW),this.S.bindBuffer(this.S.ARRAY_BUFFER,null),this.Ge=o}get type(){return this.Me}get unitGeometry(){return this.Fe}get unitBuffer(){return this.Ge}get batch(){return this.Se}Qt(){this.Se.clear()}Yt(){return!this.Se.isEmpty}j(){this.Se.j(),this.Ge&&(this.S.deleteBuffer(this.Ge),this.Ge=null)}De(r,i,s,n,o){const a=this.Pe(r,i,s,n,o.rotationX||0,o.rotationY||0,o.rotationZ||0);return{position:[r,i],size:[s,n],character:o.character||[0,0,0],primaryColor:o.charColor||[1,1,1,1],secondaryColor:o.bgColor||[0,0,0,1],rotation:o.charRotation||[0,0],transform:[o.invert?1:0,o.flipHorizontally?1:0,o.flipVertically?1:0],globalRotationX:a.radiansX,globalRotationY:a.radiansY,globalRotationZ:a.radiansZ,rotationCenter:[a.centerX,a.centerY]}}Ae(r,i){const s=D(this.S)||[0,0,this.S.canvas.width,this.S.canvas.height];return{nx:r/s[2]*2-1,ny:1-i/s[3]*2}}Be(r,i,s){const n=this.Ae(i,s);r.rotationCenter=[n.nx,n.ny]}Pe(r,i,s,n,o,a,h){const l=D(this.S)||[0,0,this.S.canvas.width,this.S.canvas.height],f=l[2],g=l[3];return{centerX:(r+s/2)/f*2-1,centerY:1-(i+n/2)/g*2,radiansX:-o*Math.PI/180,radiansY:-a*Math.PI/180,radiansZ:-h*Math.PI/180,aspectRatio:f/g}}}const ct={vertices:new Float32Array([0,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1,0,1,1,1,1]),vertexCount:6,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class lt extends M{constructor(r,i){super(r,i,C.RECTANGLE,ct)}Kt(r,i){const s=this.De(r.x,r.y,r.width,r.height,i);return this.Se.Kt(s)}}const ut={vertices:new Float32Array([0,-.5,0,0,1,-.5,1,0,0,.5,0,1,0,.5,0,1,1,-.5,1,0,1,.5,1,1]),vertexCount:6,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class ft extends M{constructor(r,i){super(r,i,C.LINE,ut)}Kt(r,i){const s=r.x2-r.x1,n=r.y2-r.y1,o=Math.hypot(s,n),a=Math.atan2(n,s),h=r.thickness||i.lineWeight||1,l=r.x1+s/2,f=r.y1+n/2,g=l-o/2,d=f,p={character:i.character,charColor:i.charColor,bgColor:i.bgColor,charRotation:i.charRotation,flipHorizontally:i.flipHorizontally,flipVertically:i.flipVertically,invert:i.invert,rotationX:i.rotationX||0,rotationY:i.rotationY||0,rotationZ:(i.rotationZ||0)+180*a/Math.PI,lineWeight:h},x=this.De(g,d,o,h,p);return this.Be(x,l,f),this.Se.Kt(x)}}const dt={vertices:function(c=32){const r=[],i=2*Math.PI/c;for(let s=0;s<c;s++){const n=s*i,o=(s+1)%c*i,a=Math.cos(n),h=Math.sin(n),l=.5*(a+1),f=.5*(h+1),g=Math.cos(o),d=Math.sin(o),p=.5*(g+1),x=.5*(d+1);r.push(0,0,.5,.5,a,h,l,f,g,d,p,x)}return new Float32Array(r)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class pt extends M{constructor(r,i){super(r,i,C.ELLIPSE,dt)}Kt(r,i){const s=this.De(r.x,r.y,r.width,r.height,i);return this.Be(s,r.x,r.y),this.Se.Kt(s)}}let gt={vertices:function(c){const r=[];for(let i=0;i<c;i++){const s=i/c,n=(i+1)/c;r.push(s,0,s,0,s,1,s,1,n,1,n,1)}return new Float32Array(r)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class mt extends M{constructor(r,i){super(r,i,C.ARC,gt)}Kt(r,i){const s=r.x-r.width/2,n=r.y-r.height/2,o=r.start*Math.PI/180,a=r.stop*Math.PI/180,h=this.De(s,n,r.width,r.height,i);return this.Be(h,r.x,r.y),h.arcAngles=[o,a],this.Se.Kt(h)}}const xt={vertices:new Float32Array([0,0,0,0,1,0,1,0,.5,1,.5,1]),vertexCount:3,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class yt extends M{constructor(r,i){super(r,i,C.TRIANGLE,xt)}Kt(r,i){const s=Math.min(r.x1,r.x2,r.x3),n=Math.max(r.x1,r.x2,r.x3),o=Math.min(r.y1,r.y2,r.y3),a=n-s,h=Math.max(r.y1,r.y2,r.y3)-o,l=this.De(s,o,a,h,i),f=s+.5*a,g=o+h*(1/3);return this.Be(l,f,g),this.Se.Kt(l)}}function Q(c,r,i,s,n){const o=1-c,a=o*o,h=c*c;return a*o*r+3*a*c*i+3*o*h*s+h*c*n}const Ct={vertices:function(c=16){const r=[];for(let i=0;i<c;i++){const s=i/c,n=(i+1)/c;r.push(s,-.5,s,0),r.push(n,-.5,n,0),r.push(s,.5,s,1),r.push(s,.5,s,1),r.push(n,-.5,n,0),r.push(n,.5,n,1)}return new Float32Array(r)}(16),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class vt extends M{constructor(r,i){super(r,i,C.BEZIER_CURVE,Ct)}Kt(r,i){const s=i.lineWeight||1,n=Q(.5,r.x1,r.cp1x,r.cp2x,r.x2),o=Q(.5,r.y1,r.cp1y,r.cp2y,r.y2),a={character:i.character,charColor:i.charColor,bgColor:i.bgColor,charRotation:i.charRotation,flipHorizontally:i.flipHorizontally,flipVertically:i.flipVertically,invert:i.invert,rotationX:i.rotationX||0,rotationY:i.rotationY||0,rotationZ:i.rotationZ||0,lineWeight:s},h=this.De(0,0,1,s,a);return this.Be(h,n,o),h.bezierStartPoint=[r.x1,r.y1],h.bezierControlPoint1=[r.cp1x,r.cp1y],h.bezierControlPoint2=[r.cp2x,r.cp2y],h.bezierEndPoint=[r.x2,r.y2],this.Se.Kt(h)}}class St{constructor(r){u(this,"S");u(this,"Ie",null);u(this,"Le",null);u(this,"Ee",{});u(this,"We",null);u(this,"ke",new Map);u(this,"Ue");u(this,"Ve");u(this,"Oe");this.S=r,this.Oe=new st,this.Ue=new ot(r),this.Ve=new at,this.We=r.createBuffer(),G(this.S,[0,0,this.S.canvas.width,this.S.canvas.height])}je(r){let i=this.ke.get(r);if(i)return i;const s=new ht(this.S);return i=(0,{[C.RECTANGLE]:()=>new lt(this.S,s),[C.LINE]:()=>new ft(this.S,s),[C.ELLIPSE]:()=>new pt(this.S,s),[C.ARC]:()=>new mt(this.S,s),[C.TRIANGLE]:()=>new yt(this.S,s),[C.BEZIER_CURVE]:()=>new vt(this.S,s)}[r])(),this.ke.set(r,i),i}He(r){this.Ie!==r&&(this.Ie=r,r.tt())}Xe(r,i){return new V(this.S,r,i)}Ye(r){this.Le=r,r&&(this.Ee={})}qe(r,i){this.Ee[r]=i}Ze(r){Object.assign(this.Ee,r)}Ne(r){return new V(this.S,j,r)}Qe(r,i,s,n){var y;const o=this.S,a=o.canvas.width,h=o.canvas.height,l=r/a*2-1,f=(r+s)/a*2-1,g=1-i/h*2,d=1-(i+n)/h*2,p=new Float32Array([l,d,f,d,l,g,f,d,f,g,l,g]);o.bindBuffer(o.ARRAY_BUFFER,this.We),o.bufferData(o.ARRAY_BUFFER,p,o.DYNAMIC_DRAW);const x=((y=this.Ie)==null?void 0:y.ot)||o.getParameter(o.CURRENT_PROGRAM),m=x?o.getAttribLocation(x,"a_position"):-1;m!==-1&&(o.enableVertexAttribArray(m),o.vertexAttribPointer(m,2,o.FLOAT,!1,8,0)),o.drawArrays(o.TRIANGLES,0,6),m!==-1&&o.disableVertexAttribArray(m)}Je(r,i,s,n){this.Le?(this.Ve.ae(r,i,s,n,this.Le,{...this.Ee},this.Oe),this.Le=null,this.Ee={}):this.Ve.oe(r,i,s,n,this.Oe)}Ke(r,i,s,n){this.Ve.he(r,i,s,n,this.Oe.lineWeight,this.Oe)}ts(r,i,s,n){this.Ve.ce(r,i,s,n,this.Oe)}es(r,i,s,n,o,a){this.Ve.ue(r,i,s,n,o,a,this.Oe)}ss(r,i,s,n,o,a,h,l){const f=this.Oe.lineWeight;this.Ve.fe(r,i,s,n,o,a,h,l,f,this.Oe)}rs(r,i,s=1,n={}){return new N(this.S,r,i,s,n)}ns(r,i,s,n,o,a){this.Ve.le(r,i,s,n,o,a,this.Oe)}hs(r,i=r,s=r,n=255){this.state.Et(r,i,s,n),this.de(r/255,i/255,s/255,n/255)}de(r=0,i=0,s=0,n=0){this.S.clearColor(r,i,s,n),this.S.clear(this.S.COLOR_BUFFER_BIT)}cs(){this.S.viewport(0,0,this.S.canvas.width,this.S.canvas.height),G(this.S,[0,0,this.S.canvas.width,this.S.canvas.height])}get context(){return this.S}get state(){return this.Oe}ls(r){const i=r,s=D(this.S)??this.S.getParameter(this.S.VIEWPORT),n={shader:i,gl:this.S,viewport:s};this.He(i);const o=new Set;for(const a of this.Ve)a.type===C.CUSTOM?o.add(C.RECTANGLE):o.add(a.type);for(const a of o)a!==C.CUSTOM&&this.je(a);this.Ue.Xt(n,this.Ve,this.ke),this.Ve.de()}j(){this.S.deleteBuffer(this.We),this.Ve.de();for(const r of this.ke.values())r.j()}}const _={readShort:(c,r)=>(_.t.uint16[0]=c[r]<<8|c[r+1],_.t.int16[0]),readUshort:(c,r)=>c[r]<<8|c[r+1],readUshorts(c,r,i){const s=[];for(let n=0;n<i;n++)s.push(_.readUshort(c,r+2*n));return s},readUint(c,r){const i=_.t.uint8;return i[3]=c[r],i[2]=c[r+1],i[1]=c[r+2],i[0]=c[r+3],_.t.uint32[0]},readASCII(c,r,i){let s="";for(let n=0;n<i;n++)s+=String.fromCharCode(c[r+n]);return s},t:(()=>{const c=new ArrayBuffer(8);return{uint8:new Uint8Array(c),int16:new Int16Array(c),uint16:new Uint16Array(c),uint32:new Uint32Array(c)}})()},Rt={parseTab(c,r,i){const s={tables:[],ids:{},off:r};c=new Uint8Array(c.buffer,r,i),r=0;const n=_,o=n.readUshort,a=o(c,r+=2);r+=2;const h=[];for(let l=0;l<a;l++){const f=o(c,r),g=o(c,r+=2);r+=2;const d=n.readUint(c,r);r+=4;const p=`p${f}e${g}`;let x=h.indexOf(d);if(x===-1){let m;x=s.tables.length,h.push(d);const y=o(c,d);m=y===4?this.parse4(c,d):y===12?this.parse12(c,d):{format:y},s.tables.push(m)}s.ids[p]!=null&&console.warn("Multiple tables for one platform+encoding: "+p),s.ids[p]=x}return s},parse4(c,r){const i=_,s=i.readUshort,n=i.readUshorts,o=r,a=s(c,r+=2);r+=2;const h=s(c,r+=2)>>>1,l={format:4,searchRange:s(c,r+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};r+=2,l.entrySelector=s(c,r),r+=2,l.rangeShift=s(c,r),r+=2,l.endCount=n(c,r,h),r+=2*h,r+=2,l.startCount=n(c,r,h),r+=2*h;for(let f=0;f<h;f++)l.idDelta.push(i.readShort(c,r)),r+=2;return l.idRangeOffset=n(c,r,h),r+=2*h,l.glyphIdArray=n(c,r,o+a-r>>1),l},parse12(c,r){const i=_.readUint;i(c,r+=4),i(c,r+=4);const s=i(c,r+=4);r+=4;const n=new Uint32Array(3*s);for(let o=0;o<3*s;o+=3)n[o]=i(c,r+(o<<2)),n[o+1]=i(c,r+(o<<2)+4),n[o+2]=i(c,r+(o<<2)+8);return{format:12,groups:n}}},bt={parseTab(c,r,i){const s=_;r+=18;const n=s.readUshort(c,r);r+=2,r+=16;const o=s.readShort(c,r);r+=2;const a=s.readShort(c,r);r+=2;const h=s.readShort(c,r);r+=2;const l=s.readShort(c,r);return r+=2,r+=6,{unitsPerEm:n,xMin:o,yMin:a,xMax:h,yMax:l,indexToLocFormat:s.readShort(c,r)}}},Et={parseTab(c,r,i){const s=_;r+=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"?s.readUshort:s.readShort;o[h]=l(c,r+2*a)}return o}},_t={parseTab(c,r,i,s){const n=_,o=[],a=[],h=s.maxp.numGlyphs,l=s.hhea.numberOfHMetrics;let f=0,g=0,d=0;for(;d<l;)f=n.readUshort(c,r+(d<<2)),g=n.readShort(c,r+(d<<2)+2),o.push(f),a.push(g),d++;for(;d<h;)o.push(f),a.push(g),d++;return{aWidth:o,lsBearing:a}}},Z={cmap:Rt,head:bt,hhea:Et,maxp:{parseTab(c,r,i){const s=_;return s.readUint(c,r),r+=4,{numGlyphs:s.readUshort(c,r)}}},hmtx:_t,loca:{parseTab(c,r,i,s){const n=_,o=[],a=s.head.indexToLocFormat,h=s.maxp.numGlyphs+1;if(a===0)for(let l=0;l<h;l++)o.push(n.readUshort(c,r+(l<<1))<<1);else if(a===1)for(let l=0;l<h;l++)o.push(n.readUint(c,r+(l<<2)));return o}},glyf:{parseTab(c,r,i,s){const n=[],o=s.maxp.numGlyphs;for(let a=0;a<o;a++)n.push(null);return n},us(c,r){const i=_,s=c.fs,n=c.loca;if(n[r]===n[r+1])return null;const o=F.findTable(s,"glyf",c.ds);if(!o)return null;let a=o[0]+n[r];const h={};if(h.noc=i.readShort(s,a),a+=2,h.xMin=i.readShort(s,a),a+=2,h.yMin=i.readShort(s,a),a+=2,h.xMax=i.readShort(s,a),a+=2,h.yMax=i.readShort(s,a),a+=2,h.xMin>=h.xMax||h.yMin>=h.yMax)return null;if(h.noc>0){h.endPts=[];for(let p=0;p<h.noc;p++)h.endPts.push(i.readUshort(s,a)),a+=2;const l=i.readUshort(s,a);if(a+=2,s.length-a<l)return null;a+=l;const f=h.endPts[h.noc-1]+1;h.flags=[];for(let p=0;p<f;p++){const x=s[a];if(a++,h.flags.push(x),8&x){const m=s[a];a++;for(let y=0;y<m;y++)h.flags.push(x),p++}}h.xs=[];for(let p=0;p<f;p++){const x=h.flags[p],m=!!(16&x);2&x?(h.xs.push(m?s[a]:-s[a]),a++):m?h.xs.push(0):(h.xs.push(i.readShort(s,a)),a+=2)}h.ys=[];for(let p=0;p<f;p++){const x=h.flags[p],m=!!(32&x);4&x?(h.ys.push(m?s[a]:-s[a]),a++):m?h.ys.push(0):(h.ys.push(i.readShort(s,a)),a+=2)}let g=0,d=0;for(let p=0;p<f;p++)g+=h.xs[p],d+=h.ys[p],h.xs[p]=g,h.ys[p]=d}else h.parts=[],h.endPts=[],h.flags=[],h.xs=[],h.ys=[];return h}}},F={parse:c=>[((r,i,s,n)=>{const o=Z,a={fs:r,ps:i,ds:s};for(const h in o){const l=h,f=F.findTable(r,l,s);if(f){const[g,d]=f;let p=n[g];p==null&&(p=o[l].parseTab(r,g,d,a),n[g]=p),a[l]=p}}return a})(new Uint8Array(c),0,0,{})],findTable(c,r,i){const s=_,n=s.readUshort(c,i+4);let o=i+12;for(let a=0;a<n;a++){const h=s.readASCII(c,o,4);s.readUint(c,o+4);const l=s.readUint(c,o+8),f=s.readUint(c,o+12);if(h===r)return[l,f];o+=16}return null},T:Z,B:_};class O{constructor(){u(this,"_s",new Map);u(this,"gs",new Map)}vs(r,i){const s=`${this.Cs(r)}_${i}`;if(this._s.has(s))return this._s.get(s);const n=r.cmap;if(!n||!n.tables)return this._s.set(s,0),0;let o=0;for(const a of n.tables)if(a.format===4?o=this.ws(i,a):a.format===12&&(o=this.$s(i,a)),o>0)break;return this._s.set(s,o),o}bs(r,i){const s=i.codePointAt(0);return s===void 0?0:this.vs(r,s)}zs(r,i){const s=r.hmtx;return s&&s.aWidth&&s.aWidth.length!==0?i<s.aWidth.length?s.aWidth[i]:s.aWidth[s.aWidth.length-1]:0}Rs(r,i){const s=i/r.head.unitsPerEm,n=r.hhea.ascender*s,o=r.hhea.descender*s,a=r.hhea.lineGap*s;return{ascender:n,descender:o,lineGap:a,lineHeight:n-o+a,unitsPerEm:r.head.unitsPerEm,scale:s}}Ts(){this._s.clear(),this.gs.clear()}Cs(r){return`${r.ds}_${r.fs.length}`}ws(r,i){const s=i.endCount.length;let n=-1;for(let o=0;o<s;o++)if(r<=i.endCount[o]){n=o;break}if(n===-1||r<i.startCount[n])return 0;if(i.idRangeOffset[n]===0)return r+i.idDelta[n]&65535;{const o=i.idRangeOffset[n]/2+(r-i.startCount[n])-(s-n);if(o>=0&&o<i.glyphIdArray.length){const a=i.glyphIdArray[o];return a===0?0:a+i.idDelta[n]&65535}}return 0}$s(r,i){const s=i.groups.length/3;for(let n=0;n<s;n++){const o=i.groups[3*n],a=i.groups[3*n+1],h=i.groups[3*n+2];if(r>=o&&r<=a)return h+(r-o)}return 0}}class wt{constructor(r){u(this,"Ss");this.Ss=r}Ms(r){var s;const i=[];return(s=r.cmap)!=null&&s.tables?(r.cmap.tables.forEach(n=>{if(n.format===4){const o=this.Fs(n);i.push(...o)}else if(n.format===12){const o=this.Gs(n);i.push(...o)}}),[...new Set(i)]):[]}Ds(r,i){return this.Ss.bs(r,i)>0}Ps(r,i){for(const s of i)if(!this.Ds(r,s))return!1;return!0}As(r,i){return i.filter(s=>this.Ds(r,s))}Bs(r){return r.filter(i=>this.Is(i))}Fs(r){const i=[];if(!(r.startCount&&r.endCount&&r.idRangeOffset&&r.idDelta))return i;for(let s=0;s<r.startCount.length;s++){const n=r.startCount[s],o=r.endCount[s];if(n!==65535||o!==65535){for(let a=n;a<=o;a++)if(this.Ls(r,a,s)>0)try{const h=String.fromCodePoint(a);i.push(h)}catch{}}}return i}Gs(r){const i=[];if(!r.groups)return i;for(let s=0;s<r.groups.length;s+=3){const n=r.groups[s],o=r.groups[s+1],a=r.groups[s+2];for(let h=n;h<=o;h++)if(a+(h-n)>0)try{const l=String.fromCodePoint(h);i.push(l)}catch{}}return i}Ls(r,i,s){if(r.idRangeOffset[s]===0)return i+r.idDelta[s]&65535;{const n=r.idRangeOffset[s]/2+(i-r.startCount[s])-(r.startCount.length-s);if(n>=0&&r.glyphIdArray&&n<r.glyphIdArray.length){const o=r.glyphIdArray[n];if(o!==0)return o+r.idDelta[s]&65535}}return 0}Is(r){const i=r.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class Tt{constructor(){u(this,"Es");const r=new O;this.Es=new wt(r)}extractCharacters(r){return this.Es.Ms(r)}filterProblematicCharacters(r){return this.Es.Bs(r)}characterExists(r,i){return this.Es.Ds(r,i)}allCharactersExist(r,i){return this.Es.Ps(r,i)}}class At{constructor(r){u(this,"Ws");u(this,"ks");u(this,"Us");u(this,"Vs");this.Us=r,this.Vs=new O,this.Ws=document.createElement("canvas"),this.ks=this.Ws.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(r,i,s,n){const o=r.length,a=Math.ceil(Math.sqrt(o)),h=Math.ceil(o/a),l=i.width*a,f=i.height*h,g=typeof n=="object"?n:null;this.Os(l,f),this.js(r,i,a,s,g);const d=this.Us.rs(l,f,1,{filter:"nearest"});return d.L(this.Ws),{framebuffer:d,columns:a,rows:h}}Os(r,i){this.Ws.width=r,this.Ws.height=i,this.Ws.style.width=r+"px",this.Ws.style.height=r+"px",this.ks.imageSmoothingEnabled=!1,this.Ws.style.imageRendering="pixelated",this.ks.fillStyle="black",this.ks.fillRect(0,0,r,i),this.ks.textBaseline="top",this.ks.textAlign="left",this.ks.fillStyle="white"}js(r,i,s,n,o){const a=n/o.head.unitsPerEm;for(let h=0;h<r.length;h++){const l=h%s,f=Math.floor(h/s),g=r[h].character,d=this.Hs(o,g);if(!d)continue;const p=g.codePointAt(0)||0,x=this.Vs.vs(o,p),m=this.Xs(o,x)*a,y=l*i.width,w=f*i.height,E=y+.5*i.width,T=w+.5*i.height,A=Math.round(E-.5*i.width),R=Math.round(T-.5*n),B=A+.5*(i.width-m),Jt=R+o.hhea.ascender*a;this.Ys(d,B,Jt,a)}}Hs(r,i){const s=i.codePointAt(0)||0,n=this.Vs.vs(r,s);if(n===0)return null;if(r.glyf&&r.glyf[n]!==null)return r.glyf[n];if(F&&F.T&&F.T.glyf){const o=F.T.glyf.us(r,n);return r.glyf&&o&&(r.glyf[n]=o),o}return null}Xs(r,i){const s=r.hmtx;return s&&s.aWidth?i<s.aWidth.length?s.aWidth[i]:s.aWidth[s.aWidth.length-1]:0}Ys(r,i,s,n){if(!r||!r.xs||r.noc===0)return;const{xs:o,ys:a,endPts:h,flags:l}=r;if(!(o&&a&&h&&l))return;this.ks.beginPath();let f=0;for(let g=0;g<h.length;g++){const d=h[g];if(!(d<f)){if(d>=f){const p=i+o[f]*n,x=s-a[f]*n;this.ks.moveTo(p,x);let m=f+1;for(;m<=d;)if(1&l[m]){const y=i+o[m]*n,w=s-a[m]*n;this.ks.lineTo(y,w),m++}else{const y=i+o[m]*n,w=s-a[m]*n;let E=m+1>d?f:m+1;if(1&l[E]){const T=i+o[E]*n,A=s-a[E]*n;this.ks.quadraticCurveTo(y,w,T,A),m=E+1}else{const T=(y+(i+o[E]*n))/2,A=(w+(s-a[E]*n))/2;this.ks.quadraticCurveTo(y,w,T,A),m=E}}this.ks.closePath()}f=d+1}}this.ks.fill()}}class Ft{constructor(){u(this,"Ss");this.Ss=new O}calculateMaxGlyphDimensions(r,i,s){let n=0;const o=this.Ss.Rs(s,i),a=o.lineHeight;for(const h of r){const l=this.Ss.bs(s,h);if(l===0)continue;const f=this.Ss.zs(s,l)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}getCharacterAdvanceWidth(r,i,s){const n=this.Ss.Rs(s,i),o=this.Ss.bs(s,r);return this.Ss.zs(s,o)*n.scale}getFontMetrics(r,i){return this.Ss.Rs(i,r)}Ts(){this.Ss.Ts()}}class Ut{constructor(){u(this,"Vs");this.Vs=new O}createCharacterObjects(r,i){return r.map((s,n)=>{const o=s.codePointAt(0)||0,a=this.qs(n);let h=0;if(i.hmtx&&i.hmtx.aWidth){const l=this.Vs.vs(i,o);l>0&&i.hmtx.aWidth[l]!==void 0&&(h=i.hmtx.aWidth[l])}return{character:s,unicode:o,color:a,advanceWidth:h}})}qs(r){return[r%256/255,Math.floor(r/256)%256/255,Math.floor(r/65536)%256/255]}Zs(r,i){if(!z.m(typeof r=="string","Character must be a string.",{method:"getCharacterColor",providedValue:r}))return[0,0,0];const s=i.find(n=>n.character===r);return s?s.color:[0,0,0]}Ns(r,i){return z.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(s=>this.Zs(s,i)||[0,0,0]):[[0,0,0]]}}class K{constructor(r,i=16){u(this,"Qs");u(this,"Js",[]);u(this,"Ks");u(this,"ti",16);u(this,"ei",0);u(this,"si",0);u(this,"ii",{width:0,height:0});u(this,"ri");u(this,"ni");u(this,"oi");u(this,"ai");u(this,"hi");this.ti=i,this.ni=new Tt,this.oi=new At(r),this.ai=new Ft,this.hi=new Ut}async ci(r){let i;if(!r)throw new v("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const s=await fetch(r);if(!s.ok)throw new v(`Failed to load font file: ${s.status} ${s.statusText}`);i=await s.arrayBuffer()}await this.li(i),this.Qs=F.parse(i)[0],await this.ui()}fi(r){if(r===void 0)return this.ti;this.ti=r,this.ii=this.ai.calculateMaxGlyphDimensions(this.Js.map(s=>s.character),this.ti,this.Qs);const i=this.oi.createTextureAtlas(this.Js,this.ii,this.ti,this.Qs);this.Ks=i.framebuffer,this.ei=i.columns,this.si=i.rows}async di(r){try{const i=await fetch(r);if(!i.ok)throw new v(`Failed to load font file: ${i.status} ${i.statusText}`);const s=await i.arrayBuffer();await this.li(s);const n=F.parse(s);if(!n||n.length===0)throw Error("Failed to parse font file");this.Qs=n[0],await this.ui()}catch(i){throw new v("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async li(r){const i=Date.now();this.ri=new FontFace("CustomFont_"+i,r),await this.ri.load(),document.fonts.add(this.ri)}async ui(){const r=this.ni.extractCharacters(this.Qs),i=this.ni.filterProblematicCharacters(r);this.Js=this.hi.createCharacterObjects(i,this.Qs),this.ii=this.ai.calculateMaxGlyphDimensions(i,this.ti,this.Qs);const s=this.oi.createTextureAtlas(this.Js,this.ii,this.ti,this.Qs);this.Ks=s.framebuffer,this.ei=s.columns,this.si=s.rows}Zs(r){return this.hi.Zs(r,this.Js)}Ns(r){return this.hi.Ns(r,this.Js)}j(){this.Ks.j(),document.fonts.delete(this.ri)}get fontFramebuffer(){return this.Ks}get characters(){return this.Js}get textureColumns(){return this.ei}get textureRows(){return this.si}get maxGlyphDimensions(){return this.ii}get fontSize(){return this.ti}get font(){return this.Qs}}class q{constructor(r,i,s){u(this,"pi");u(this,"_i");u(this,"C");u(this,"$");u(this,"gi");u(this,"mi");u(this,"xi");u(this,"Ci");u(this,"yi");this.xi=r,this.Ci=i,this.yi=s,this.zt()}zt(){this.pi=Math.floor(this.xi.width/this.Ci),this._i=Math.floor(this.xi.height/this.yi),this.C=this.pi*this.Ci,this.$=this._i*this.yi,this.gi=Math.floor((this.xi.width-this.C)/2),this.mi=Math.floor((this.xi.height-this.$)/2)}wi(r,i){this.Ci=r,this.yi=i,this.zt()}get cellWidth(){return this.Ci}get cellHeight(){return this.yi}get cols(){return this.pi}get rows(){return this._i}get width(){return this.C}get height(){return this.$}get offsetX(){return this.gi}get offsetY(){return this.mi}}class J{constructor(r={}){u(this,"xi");u(this,"$i");u(this,"bi");r.canvas?(this.xi=r.canvas,this.bi=!1):(this.xi=this.zi(r.width,r.height),this.bi=!0),this.xi.style.imageRendering="pixelated"}zi(r,i){const s=document.createElement("canvas");return s.className="textmodeCanvas",s.style.imageRendering="pixelated",s.width=r||800,s.height=i||600,document.body.appendChild(s),s}W(r,i){this.xi.width=r??this.xi.width,this.xi.height=i??this.xi.height}Ri(){const r=this.xi.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!r)throw new v("`textmode.js` requires WebGL2 support.");return r}j(){this.$i&&this.$i.disconnect();const r=this.xi.getContext("webgl")||this.xi.getContext("webgl2");if(r){const i=r.getExtension("WEBGL_lose_context");i&&i.loseContext()}this.bi&&this.xi.parentNode&&this.xi.parentNode.removeChild(this.xi)}get canvas(){return this.xi}get width(){return this.xi.width}get height(){return this.xi.height}}class Lt{constructor(r=60){u(this,"Ti");u(this,"Si");u(this,"Mi",null);u(this,"Fi",0);u(this,"Gi",!0);u(this,"Di",0);u(this,"Pi",0);u(this,"Ai",[]);u(this,"Bi",10);u(this,"Ii",0);this.Ti=r,this.Si=1e3/r}start(r){if(!this.Gi)return;this.Fi=performance.now();const i=s=>{if(!this.Gi)return void(this.Mi=null);const n=s-this.Fi;n>=this.Si&&(r(),this.Fi=s-n%this.Si),this.Gi&&(this.Mi=requestAnimationFrame(i))};this.Mi=requestAnimationFrame(i)}stop(){this.Mi&&(cancelAnimationFrame(this.Mi),this.Mi=null)}pause(){this.Gi&&(this.Gi=!1,this.stop())}resume(r){this.Gi||(this.Gi=!0,this.start(r))}frameRate(r,i){if(r===void 0)return this.Di;this.Ti=r,this.Si=1e3/r,this.Gi&&i&&(this.stop(),this.start(i))}measureFrameRate(){const r=performance.now();if(this.Pi>0){const i=r-this.Pi;this.Ai.push(i),this.Ai.length>this.Bi&&this.Ai.shift();const s=this.Ai.reduce((n,o)=>n+o,0)/this.Ai.length;this.Di=1e3/s}this.Pi=r}get isLooping(){return this.Gi}get frameRateLimit(){return this.Ti}get currentFrameRate(){return this.Di}get frameCount(){return this.Ii}set frameCount(r){this.Ii=r}incrementFrame(){this.Ii++}resetFrameCount(){this.Ii=0}}const Pt=c=>class extends c{rotate(r=0,i=0,s=0){this.Us.state.St(r),this.Us.state.Mt(i),this.Us.state.Ft(s)}rotateX(r){this.Us.state.St(r)}rotateY(r){this.Us.state.Mt(r)}rotateZ(r){this.Us.state.Ft(r)}push(){this.Us.state.$t()}pop(){this.Us.state.bt()}rect(r,i,s=1,n=1){this.Us.Je(r,i,s,n)}line(r,i,s,n){this.Us.Ke(r,i,s,n)}lineWeight(r){this.Us.state.Tt(r)}background(r,i=r,s=r,n=255){this.Us.hs(r,i,s,n)}char(r){this.Us.state.Gt(this.Qs.Zs(r))}charColor(r,i,s){this.Us.state.Dt(r,i,s)}cellColor(r,i,s){this.Us.state.Pt(r,i,s)}flipHorizontally(r){this.Us.state.At(r)}flipVertically(r){this.Us.state.Bt(r)}charRotation(r){this.Us.state.Lt(r)}invert(r){this.Us.state.It(r)}clear(){this.Us.hs(0,0,0,0)}ellipse(r,i,s,n){this.Us.ts(r,i,s/2,n/2)}triangle(r,i,s,n,o,a){this.Us.es(r,i,s,n,o,a)}bezierCurve(r,i,s,n,o,a,h,l){this.Us.ss(r,i,s,n,o,a,h,l)}arc(r,i,s,n,o,a){this.Us.ns(r,i,s,n,o,a)}shader(r){this.Us.Ye(r)}setUniform(r,i){this.Us.qe(r,i)}setUniforms(r){this.Us.Ze(r)}createFilterShader(r){return this.Us.Ne(r)}};class X{Li(r){const i=r.k(0),s=r.k(1),n=r.k(2),o=r.k(3);return{characterPixels:i,primaryColorPixels:s,secondaryColorPixels:n,transformPixels:r.k(4),rotationPixels:o}}Ei(r,i){return r[i]+(r[i+1]<<8)}Wi(r,i){return{r:r[i],g:r[i+1],b:r[i+2],a:r[i+3]}}}class Y{ki(r,i){return new Blob([r],{type:i})}Ui(r,i,s){try{const n=this.ki(r,s),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=i,a.style.display="none",a.rel="noopener",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(o)}catch(n){throw console.error("Failed to download file:",n),Error("File download failed: "+(n instanceof Error?n.message:"Unknown error"))}}Vi(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Oi(){const r=new Date;return{date:r.toISOString().split("T")[0],time:r.toTimeString().split(" ")[0].replace(/:/g,"-")}}ji(r){return r.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Hi(){return"textmode-export-"+this.Vi()}}class It extends X{Xi(r,i,s){const n=r[s]===255,o=r[s+1]===255,a=r[s+2]===255,h=i[s],l=i[s+1];return{isInverted:n,flipHorizontal:o,flipVertical:a,rotation:Math.round(360*(h+l/255)/255*100)/100}}Yi(r,i,s){return{x:r,y:i,cellX:r*s.cellWidth,cellY:i*s.cellHeight}}qi(r,i){const s=[];let n=0;for(let o=0;o<i.rows;o++)for(let a=0;a<i.cols;a++){const h=4*n,l=this.Ei(r.characterPixels,h);let f=this.Wi(r.primaryColorPixels,h),g=this.Wi(r.secondaryColorPixels,h);const d=this.Xi(r.transformPixels,r.rotationPixels,h);if(d.isInverted){const x=f;f=g,g=x}const p=this.Yi(a,o,i);s.push({charIndex:l,primaryColor:f,secondaryColor:g,transform:d,position:p}),n++}return s}}class Dt{Zi(r,i){const s=r.cmap;for(const n of s.tables)if(n.format===4){const o=n;for(let a=0;a<o.startCount.length;a++)if(i>=o.startCount[a]&&i<=o.endCount[a]){if(o.idRangeOffset[a]===0)return i+o.idDelta[a]&65535;{const h=o.idRangeOffset[a]/2+(i-o.startCount[a])-(o.startCount.length-a);if(h>=0&&h<o.glyphIdArray.length){const l=o.glyphIdArray[h];if(l!==0)return l+o.idDelta[a]&65535}}}}else if(n.format===12){const o=n;for(let a=0;a<o.groups.length;a+=3){const h=o.groups[a],l=o.groups[a+1],f=o.groups[a+2];if(i>=h&&i<=l)return f+(i-h)}}return 0}Ni(r,i,s,n,o){const a=o/r.head.unitsPerEm;return{getBoundingBox:()=>({x1:s+i.xMin*a,y1:n+-i.yMax*a,x2:s+i.xMax*a,y2:n+-i.yMin*a}),toSVG:()=>this.Qi(i,s,n,a)}}Qi(r,i,s,n){if(!r||!r.xs)return"";const{xs:o,ys:a,endPts:h,flags:l}=r;if(!(o&&a&&h&&l))return"";let f="",g=0;for(let d=0;d<h.length;d++){const p=h[d];if(!(p<g)){if(p>=g){const x=i+o[g]*n,m=s-a[g]*n;f+=`M${x.toFixed(2)},${m.toFixed(2)}`;let y=g+1;for(;y<=p;)if(1&l[y]){const w=i+o[y]*n,E=s-a[y]*n;f+=`L${w.toFixed(2)},${E.toFixed(2)}`,y++}else{const w=i+o[y]*n,E=s-a[y]*n;let T=y+1>p?g:y+1;if(1&l[T]){const A=i+o[T]*n,R=s-a[T]*n;f+=`Q${w.toFixed(2)},${E.toFixed(2)} ${A.toFixed(2)},${R.toFixed(2)}`,y=T+1}else{const A=(w+(i+o[T]*n))/2,R=(E+(s-a[T]*n))/2;f+=`Q${w.toFixed(2)},${E.toFixed(2)} ${A.toFixed(2)},${R.toFixed(2)}`,y=T}}f+="Z"}g=p+1}}return f}Ji(r,i,s,n,o){const a=r.codePointAt(0)||0,h=this.Zi(i,a);let l=null;return i.glyf&&i.glyf[h]!==null?l=i.glyf[h]:(l=F.T.glyf.us(i,h),i.glyf[h]=l),this.Ni(i,l,s,n,o)}Ki(r,i,s,n,o,a,h,l){const f=s+(o-l*(h/i.head.unitsPerEm))/2,g=n+(a+.7*h)/2;return this.Ji(r,i,f,g,h).toSVG()||null}}class Mt{constructor(){u(this,"tr");this.tr=new Dt}er(r){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
8
10
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
9
- <svg width="${s.width}" height="${s.height}" viewBox="0 0 ${s.width} ${s.height}"
11
+ <svg width="${r.width}" height="${r.height}" viewBox="0 0 ${r.width} ${r.height}"
10
12
  xmlns="http://www.w3.org/2000/svg" version="1.1">
11
13
  <title>textmode art generated via textmode.js</title>
12
- <desc>textmode art visualization generated by textmode.js library</desc>`}Bi(){return`
14
+ <desc>textmode art visualization generated by textmode.js library</desc>`}sr(){return`
13
15
  </g>
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+=`
16
+ </svg>`}ir(r,i){if(!i.includeBackgroundRectangles)return"";const s=i.backgroundColor,n=`rgba(${s[0]},${s[1]},${s[2]},${s[3]/255})`;return`
17
+ <rect width="${r.width}" height="${r.height}" fill="${n}" />`}rr(r){return`rgba(${r.r},${r.g},${r.b},${r.a/255})`}nr(r,i){const{transform:s,position:n}=r,o=n.cellX+i.cellWidth/2,a=n.cellY+i.cellHeight/2,h=[];if(s.flipHorizontal||s.flipVertical){const l=s.flipHorizontal?-1:1,f=s.flipVertical?-1:1;h.push(`translate(${o} ${a})`),h.push(`scale(${l} ${f})`),h.push(`translate(${-o} ${-a})`)}return s.rotation&&h.push(`rotate(${s.rotation} ${o} ${a})`),h.length?` transform="${h.join(" ")}"`:""}ar(r,i,s){if(!s.includeBackgroundRectangles||r.secondaryColor.a===0)return"";const{position:n}=r,o=this.rr(r.secondaryColor);return s.drawMode==="stroke"?`
18
+ <rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" stroke="${o}" fill="none" stroke-width="${s.strokeWidth}" />`:`
19
+ <rect x="${n.cellX}" y="${n.cellY}" width="${i.cellWidth}" height="${i.cellHeight}" fill="${o}" />`}Ji(r,i,s,n){const o=s.characters[r.charIndex];if(!o)return"";const a=this.tr.Ki(o.character,s.font,r.position.cellX,r.position.cellY,i.cellWidth,i.cellHeight,s.fontSize,o.advanceWidth);if(!a)return"";const h=this.rr(r.primaryColor);return n.drawMode==="stroke"?`
20
+ <path id="${`path-${r.charIndex}-${r.position.cellX}-${r.position.cellY}`.replace(/\./g,"-")}" d="${a}" stroke="${h}" stroke-width="${n.strokeWidth}" fill="none" />`:`
21
+ <path d="${a}" fill="${h}" />`}hr(r,i,s,n){let o="";o+=this.ar(r,i,n);const a=this.nr(r,i),h=this.Ji(r,i,s,n);return h&&(a?(o+=`
20
22
  <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
23
+ </g>`):o+=h),o}cr(r,i,s,n){let o=this.er(i);o+=this.ir(i,n),o+=`
24
+ <g id="ascii-cells">`;for(const a of r)o+=this.hr(a,i,s,n);return o+=this.sr(),o}lr(r){return r.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\n\s*\n/g,`
25
+ `).replace(/[ \t]+$/gm,"")}}class zt extends Y{ur(r){return this.ki(r,"image/svg+xml;charset=utf-8")}dr(r,i){this.Ui(r,this.ji(i)+".svg","image/svg+xml;charset=utf-8")}pr(r,i){this.dr(r,i||this.Hi())}}class tt{constructor(){u(this,"_r");u(this,"gr");u(this,"mr");this._r=new It,this.gr=new Mt,this.mr=new zt}vr(r){return{includeBackgroundRectangles:r.includeBackgroundRectangles??!0,drawMode:r.drawMode??"fill",strokeWidth:r.strokeWidth??1,backgroundColor:r.backgroundColor??[0,0,0,0],filename:r.filename||this.mr.Hi()}}Cr(r,i={}){const s=this._r.qi(this._r.Li(r.pipeline),r.grid),n=this.gr.cr(s,r.grid,r.font,this.vr(i));return this.gr.lr(n)}pr(r,i={}){this.mr.pr(this.Cr(r,i),i.filename)}}class Bt extends X{yr(r,i,s,n=" "){var h;const o=[];let a=0;for(let l=0;l<i.rows;l++){const f=[];for(let g=0;g<i.cols;g++){const d=4*a,p=this.Ei(r.characterPixels,d),x=((h=s.characters[p])==null?void 0:h.character)||n;f.push(x),a++}o.push(f)}return o}}class Gt{wr(r,i){const s=[];for(const o of r){let a=o.join("");i.preserveTrailingSpaces||(a=a.replace(/\s+$/,"")),s.push(a)}const n=i.lineEnding==="crlf"?`\r
24
26
  `:`
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={});
27
+ `;return s.join(n)}}class $t extends Y{$r(r,i){const s=this.br(i);this.Ui(r,s,"text/plain;charset=utf-8")}br(r){let i=this.ji(r);return i===".txt"||i.length<=4?this.Hi():i}}class et{constructor(){u(this,"_r");u(this,"gr");u(this,"mr");this._r=new Bt,this.gr=new Gt,this.mr=new $t}vr(r){return{preserveTrailingSpaces:r.preserveTrailingSpaces??!1,lineEnding:r.lineEnding??"lf",emptyCharacter:r.emptyCharacter??" ",filename:r.filename||this.mr.Hi()}}zr(r,i={}){const s=this.vr(i),n=this._r.yr(this._r.Li(r.pipeline),r.grid,r.font,s.emptyCharacter);return this.gr.wr(n,s)}$r(r,i={}){this.mr.$r(this.zr(r,i),i.filename)}}class Ot extends X{Rr(r,i=1,s="transparent"){const n=r.canvas;if(i===1&&s==="transparent")return n;const o=document.createElement("canvas"),a=o.getContext("2d"),h=Math.round(n.width*i),l=Math.round(n.height*i);return o.width=h,o.height=l,s!=="transparent"&&(a.fillStyle=s,a.fillRect(0,0,h,l)),a.imageSmoothingEnabled=!1,a.drawImage(n,0,0,n.width,n.height,0,0,h,l),o}}class Wt{Tr(r,i){const s=this.Sr(i.format);return i.format==="png"?r.toDataURL(s):r.toDataURL(s,i.quality)}async Mr(r,i){return new Promise((s,n)=>{const o=this.Sr(i.format),a=h=>{h?s(h):n(Error(`Failed to generate ${i.format.toUpperCase()} blob`))};i.format==="png"?r.toBlob(a,o):r.toBlob(a,o,i.quality)})}Sr(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 kt={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},rt={png:".png",jpg:".jpg",webp:".webp"};class Nt extends Y{Fr(r,i,s){this.Gr(r,this.ji(i)+rt[s])}Gr(r,i){const s=URL.createObjectURL(r);try{const n=document.createElement("a");n.href=s,n.download=i,n.style.display="none",n.rel="noopener",document.body.appendChild(n),n.click(),document.body.removeChild(n)}finally{URL.revokeObjectURL(s)}}Dr(r){return r in kt&&r in rt}}class Vt{constructor(){u(this,"_r");u(this,"gr");u(this,"mr");this._r=new Ot,this.gr=new Wt,this.mr=new Nt}vr(r){return{format:r.format??"png",quality:r.quality??1,scale:r.scale??1,backgroundColor:r.backgroundColor??"transparent",filename:r.filename||this.mr.Hi()}}Pr(r){if(!this.mr.Dr(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.format==="jpg"&&r.backgroundColor==="transparent"&&(r.backgroundColor="black")}async Mr(r,i){if(i.scale===1&&i.backgroundColor==="transparent")return await this.gr.Mr(r.canvas,i);const s=this._r.Rr(r,i.scale,i.backgroundColor);return await this.gr.Mr(s,i)}async Fr(r,i={}){const s=this.vr(i);this.Pr(s);const n=await this.Mr(r,s);this.mr.Fr(n,s.filename,s.format)}}const jt=c=>class extends c{Ar(){this.Us.ls(this.Br)}toString(r={}){return this.Ar(),new et().zr({pipeline:this.Ir,grid:this.Lr,font:this.Qs},r)}saveStrings(r={}){this.Ar(),new et().$r({pipeline:this.Ir,grid:this.Lr,font:this.Qs},r)}toSVG(r={}){return this.Ar(),new tt().Cr({pipeline:this.Ir,grid:this.Lr,font:this.Qs},r)}saveSVG(r={}){this.Ar(),new tt().pr({pipeline:this.Ir,grid:this.Lr,font:this.Qs},r)}async saveCanvas(r={}){await new Vt().Fr(this.xi,r)}},Xt=c=>class extends c{async loadFont(r){return this.Qs.di(r).then(()=>{const i=this.Qs.maxGlyphDimensions;this.Lr.wi(i.width,i.height),this.Ir.W(this.Lr.cols,this.Lr.rows),this.Us.cs()})}fontSize(r){if(!z.m(typeof r=="number"&&r>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:r})||this.Qs.fontSize===r)return;this.Qs.fi(r);const i=this.Qs.maxGlyphDimensions;this.Lr.wi(i.width,i.height),this.Ir.W(this.Lr.cols,this.Lr.rows),this.Us.cs()}},Yt=c=>class extends c{get frameCount(){return this.Er.frameCount}set frameCount(r){this.Er.frameCount=r}frameRate(r){return r===void 0?this.Er.currentFrameRate:this.Er.frameRate(r,()=>this.Wr())}noLoop(){this.Er.pause()}loop(){this.Er.resume(()=>this.Wr())}redraw(r=1){if(z.m(typeof r=="number"&&r>0&&Number.isInteger(r),"Redraw count must be a positive integer.",{method:"redraw",providedValue:r}))for(let i=0;i<r;i++)this.Wr()}isLooping(){return this.Er.isLooping}};class Ht{constructor(){u(this,"Us");u(this,"Qs");u(this,"xi");u(this,"Lr");u(this,"Er");u(this,"Br");u(this,"Ir");u(this,"kr")}Wr(){}}class it extends function(i,...s){return s.reduce((n,o)=>o(n),i)}(Ht,Pt,jt,Xt,Yt){constructor(i={}){super();u(this,"Ur",!1);u(this,"Vr",()=>{});u(this,"Or",()=>{});u(this,"jr");this.xi=new J(i),this.Us=new St(this.xi.Ri()),this.Qs=new K(this.Us,i.fontSize??16),this.Er=new Lt(i.frameRate??60),this.Br=this.Us.Xe(j,`#version 300 es
28
+ precision highp float;in vec2 v_uv;in vec3 v_character;in vec4 v_primaryColor;in vec4 v_secondaryColor;in vec2 v_rotation;in vec3 v_transform;layout(location=0)out vec4 o_character;layout(location=1)out vec4 o_primaryColor;layout(location=2)out vec4 o_secondaryColor;layout(location=3)out vec4 o_rotation;layout(location=4)out vec4 o_transform;void main(){o_character=vec4(v_character,1.0);o_primaryColor=v_primaryColor;o_secondaryColor=v_secondaryColor;o_rotation=vec4(v_rotation,0.0,1.0);o_transform=vec4(v_transform,1.0);}`),this.kr=this.Us.Xe("attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;void main(){v_uv=a_texCoord;gl_Position=vec4(a_position,0.0,1.0);}","precision mediump float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D u_primaryColorTexture;uniform sampler2D u_secondaryColorTexture;uniform sampler2D u_transformTexture;uniform sampler2D u_asciiCharacterTexture;uniform sampler2D u_rotationTexture;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;uniform vec2 u_gridOffsetPixels;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){vec2 adjustedCoord=(gl_FragCoord.xy-u_gridOffsetPixels)/u_gridPixelDimensions;vec2 gridCoord=adjustedCoord*u_gridCellDimensions;vec2 cellCoord=floor(gridCoord);vec2 charIndexTexCoord=(cellCoord+0.5)/u_gridCellDimensions;vec4 primaryColor=texture2D(u_primaryColorTexture,charIndexTexCoord);vec4 secondaryColor=texture2D(u_secondaryColorTexture,charIndexTexCoord);vec4 transformColor=texture2D(u_transformTexture,charIndexTexCoord);bool isInverted=transformColor.r>0.5;bool flipHorizontal=transformColor.g>0.5;bool flipVertical=transformColor.b>0.5;vec4 encodedIndexVec=texture2D(u_asciiCharacterTexture,charIndexTexCoord);int charIndex=int(encodedIndexVec.r*255.0+0.5)+int(encodedIndexVec.g*255.0+0.5)*256;int charCol=int(mod(float(charIndex),u_charsetDimensions.x));int charRow=charIndex/int(u_charsetDimensions.x);float flippedRow=(u_charsetDimensions.y-1.0)-float(charRow);vec2 charCoord=vec2(float(charCol),flippedRow)/u_charsetDimensions;vec4 rotationColor=texture2D(u_rotationTexture,charIndexTexCoord);float scaledAngle=rotationColor.r*255.0+rotationColor.g;float rotationAngle=-(scaledAngle*360.0/255.0)*0.017453292;vec2 fractionalPart=fract(gridCoord)-0.5;if(flipHorizontal)fractionalPart.x=-fractionalPart.x;if(flipVertical)fractionalPart.y=-fractionalPart.y;fractionalPart=rotate2D(rotationAngle)*fractionalPart+0.5;vec2 cellSize=1.0/u_charsetDimensions;vec2 texCoord=charCoord+fractionalPart*cellSize;vec2 cellMax=charCoord+cellSize;if(any(lessThan(texCoord,charCoord))||any(greaterThan(texCoord,cellMax))){gl_FragColor=isInverted ? primaryColor : secondaryColor;return;}vec4 charTexel=texture2D(u_characterTexture,texCoord);if(isInverted)charTexel.rgb=1.0-charTexel.rgb;gl_FragColor=mix(secondaryColor,primaryColor,charTexel);}")}static async create(i={}){const s=new this(i);await s.Qs.ci(i.fontSource);const n=s.Qs.maxGlyphDimensions;return s.Lr=new q(s.xi.canvas,n.width,n.height),s.Ir=s.Us.rs(s.Lr.cols,s.Lr.rows,5),s.Hr(),s.Er.start(()=>s.Wr()),s}Hr(){this.jr=()=>{this.Or()},window.addEventListener("resize",this.jr)}Wr(){if(this.Er.measureFrameRate(),this.Er.incrementFrame(),this.Ur)return;this.Ir.V(),this.Us.He(this.Br),this.Vr(),this.Us.ls(this.Br),this.Ir.O();const i=this.Us.state.canvasBackgroundColor;this.Us.de(i[0],i[1],i[2],i[3]),this.Us.He(this.kr),this.kr.st({u_characterTexture:this.Qs.fontFramebuffer,u_charsetDimensions:[this.Qs.textureColumns,this.Qs.textureRows],u_asciiCharacterTexture:this.Ir.textures[0],u_primaryColorTexture:this.Ir.textures[1],u_secondaryColorTexture:this.Ir.textures[2],u_transformTexture:this.Ir.textures[4],u_rotationTexture:this.Ir.textures[3],u_gridCellDimensions:[this.Lr.cols,this.Lr.rows],u_gridPixelDimensions:[this.Lr.width,this.Lr.height],u_gridOffsetPixels:[this.Lr.offsetX,this.Lr.offsetY],u_aspectRatio:this.Lr.width/this.Lr.height}),this.Us.Qe(this.Lr.offsetX,this.Lr.offsetY,this.Lr.width,this.Lr.height)}draw(i){this.Vr=i}windowResized(i){this.Or=i}resizeCanvas(i,s){this.xi.W(i,s),this.Lr.zt(),this.Ir.W(this.Lr.cols,this.Lr.rows),this.Us.cs(),this.Wr()}destroy(){this.Ur||(this.Er.stop(),window.removeEventListener("resize",this.jr),this.Qs.j(),this.Us.j(),this.Ur=!0)}get grid(){return this.Lr}get font(){return this.Qs}get width(){return this.xi.width}get height(){return this.xi.height}get canvas(){return this.xi.canvas}get isDisposed(){return this.Ur}get drawFramebuffer(){return this.Ir}}class W{constructor(){throw new v("Textmode is a static class and cannot be instantiated.")}static async create(r){return it.create(r)}static setErrorLevel(r){z.v(r)}static get version(){return"0.2.0-beta.3"}}const Qt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),Zt=W.create,Kt=W.setErrorLevel,qt=W.version;b.TextmodeCanvas=J,b.TextmodeErrorLevel=L,b.TextmodeFont=K,b.TextmodeGrid=q,b.Textmodifier=it,b.create=Zt,b.export=Qt,b.setErrorLevel=Kt,b.textmode=W,b.version=qt,Object.defineProperty(b,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={});
@@ -1,4 +1,4 @@
1
- import type { SVGExportOptions } from './types';
1
+ import type { SVGExportOptions, TextmodeRenderingData } from './types';
2
2
  /**
3
3
  * Main SVG exporter for the textmode.js library.
4
4
  * Orchestrates the SVG export process by coordinating data extraction,
@@ -17,15 +17,15 @@ export declare class SVGExporter {
17
17
  private _applyDefaultOptions;
18
18
  /**
19
19
  * Generates SVG content from textmode rendering data without saving to file
20
- * @param textmodifier The textmodifier instance containing rendering data
20
+ * @param renderingData The textmode rendering data containing pipeline, grid, and font
21
21
  * @param options Export options (excluding filename)
22
22
  * @returns SVG content as string
23
23
  */
24
- $generateSVG(textmodifier: any, options?: SVGExportOptions): string;
24
+ $generateSVG(renderingData: TextmodeRenderingData, options?: SVGExportOptions): string;
25
25
  /**
26
26
  * Exports SVG content to a downloadable file
27
- * @param textmodifier The textmodifier instance containing rendering data
27
+ * @param renderingData The textmode rendering data containing pipeline, grid, and font
28
28
  * @param options Export options including filename
29
29
  */
30
- $saveSVG(textmodifier: any, options?: SVGExportOptions): void;
30
+ $saveSVG(renderingData: TextmodeRenderingData, options?: SVGExportOptions): void;
31
31
  }
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * SVG-specific type definitions for the textmode.js library.
3
3
  */
4
+ import type { TextmodeFont, TextmodeGrid } from '../..';
4
5
  /**
5
6
  * RGBA color representation.
6
7
  */
@@ -118,3 +119,11 @@ export interface SVGGenerationOptions {
118
119
  backgroundColor: [number, number, number, number];
119
120
  filename: string;
120
121
  }
122
+ /**
123
+ * Data required for textmode rendering export (shared shape with TXT exporter)
124
+ */
125
+ export interface TextmodeRenderingData {
126
+ pipeline: any;
127
+ grid: TextmodeGrid;
128
+ font: TextmodeFont;
129
+ }
@@ -10,6 +10,8 @@ export declare class DrawQueue implements Iterable<DrawCommand> {
10
10
  private _acquireSlot;
11
11
  /** Specialized enqueues (zero-alloc on steady state) */
12
12
  $enqueueRectangle(x: number, y: number, width: number, height: number, renderState: any): number;
13
+ /** Enqueue a custom-shaded rectangle preserving order */
14
+ $enqueueCustomRect(x: number, y: number, width: number, height: number, shader: any, uniforms: Record<string, any>, renderState: any): number;
13
15
  $enqueueLine(x1: number, y1: number, x2: number, y2: number, thickness: number | undefined, renderState: any): number;
14
16
  $enqueueEllipse(x: number, y: number, width: number, height: number, renderState: any): number;
15
17
  $enqueueArc(x: number, y: number, width: number, height: number, start: number, stop: number, renderState: any): number;
@@ -10,7 +10,9 @@ export interface InstanceData {
10
10
  secondaryColor: [number, number, number, number];
11
11
  rotation: [number, number];
12
12
  transform: [number, number, number];
13
- globalRotation: number;
13
+ globalRotationX: number;
14
+ globalRotationY: number;
15
+ globalRotationZ: number;
14
16
  rotationCenter: [number, number];
15
17
  arcAngles?: [number, number];
16
18
  bezierControlPoint1?: [number, number];
@@ -26,8 +28,8 @@ export interface InstanceData {
26
28
  * Layout designed to minimize GPU bandwidth and maximize cache efficiency.
27
29
  */
28
30
  export declare class PackedInstanceData {
29
- static readonly BYTES_PER_INSTANCE = 132;
30
- static readonly FLOATS_PER_INSTANCE = 33;
31
+ static readonly BYTES_PER_INSTANCE = 140;
32
+ static readonly FLOATS_PER_INSTANCE = 35;
31
33
  /**
32
34
  * Pack instance data into a Float32Array for efficient GPU upload.
33
35
  * @param instance The instance data to pack
@@ -60,6 +62,6 @@ export interface InstanceAttributeConfig {
60
62
  * Pre-configured attribute layouts for efficient WebGL setup.
61
63
  */
62
64
  export declare class InstanceAttributeLayout {
63
- static readonly STRIDE = 132;
65
+ static readonly STRIDE = 140;
64
66
  static readonly ATTRIBUTES: Record<string, InstanceAttributeConfig>;
65
67
  }
@@ -10,6 +10,13 @@ import type { DrawCommand } from './types/DrawCommand';
10
10
  export declare class RenderPipeline {
11
11
  private readonly _vaoMgr;
12
12
  private readonly _gl;
13
+ private _copyShader;
14
+ private _tempRectFBO;
15
+ private _tempRectFBOSize;
13
16
  constructor(gl: WebGL2RenderingContext);
14
17
  $execute(context: RenderContext, commands: Iterable<DrawCommand>, geometries: Map<GeometryType, IGeometry>): void;
18
+ /** Immediate custom-rect draw using provided shader/uniforms; mirrors prior GLRenderer path */
19
+ private _drawCustomRect;
20
+ private _getCopyShader;
21
+ private _getTempRectFBO;
15
22
  }
@@ -3,7 +3,9 @@
3
3
  */
4
4
  export interface IRenderState {
5
5
  lineWeight: number;
6
- rotation: number;
6
+ rotationX: number;
7
+ rotationY: number;
8
+ rotationZ: number;
7
9
  character: [number, number, number];
8
10
  charColor: [number, number, number, number];
9
11
  cellColor: [number, number, number, number];
@@ -17,7 +19,9 @@ export interface IRenderState {
17
19
  */
18
20
  export declare class RenderState {
19
21
  private _currentLineWeight;
20
- private _currentRotation;
22
+ private _currentRotationX;
23
+ private _currentRotationY;
24
+ private _currentRotationZ;
21
25
  private _currentCharacter;
22
26
  private _currentCharColor;
23
27
  private _currentCellColor;
@@ -25,6 +29,7 @@ export declare class RenderState {
25
29
  private _flipVertically;
26
30
  private _invert;
27
31
  private _charRotation;
32
+ private _canvasBackgroundColor;
28
33
  private _stateStack;
29
34
  /**
30
35
  * Save the current rendering state to the state stack
@@ -46,7 +51,9 @@ export declare class RenderState {
46
51
  */
47
52
  $writeSnapshotTo(target: {
48
53
  lineWeight: number;
49
- rotation: number;
54
+ rotationX: number;
55
+ rotationY: number;
56
+ rotationZ: number;
50
57
  character: number[];
51
58
  charColor: number[];
52
59
  bgColor: number[];
@@ -56,21 +63,17 @@ export declare class RenderState {
56
63
  charRotation: number[];
57
64
  }): void;
58
65
  get lineWeight(): number;
59
- get rotation(): number;
60
- get character(): [number, number, number];
61
- get charColor(): [number, number, number, number];
62
- get bgColor(): [number, number, number, number];
63
- get flipHorizontally(): boolean;
64
- get flipVertically(): boolean;
65
- get invert(): boolean;
66
- get charRotation(): [number, number];
66
+ get canvasBackgroundColor(): [number, number, number, number];
67
67
  $setLineWeight(weight: number): void;
68
- $setRotation(degrees: number): void;
68
+ $setRotationX(degrees: number): void;
69
+ $setRotationY(degrees: number): void;
70
+ $setRotationZ(degrees: number): void;
69
71
  $setCharacter(character: [number, number, number]): void;
70
72
  $setCharColor(r: number, g?: number, b?: number, a?: number): void;
71
- $setBgColor(r: number, g?: number, b?: number, a?: number): void;
73
+ $setCellColor(r: number, g?: number, b?: number, a?: number): void;
72
74
  $setFlipHorizontally(flip: boolean): void;
73
75
  $setFlipVertically(flip: boolean): void;
74
76
  $setInvert(invert: boolean): void;
75
77
  $setCharRotation(rotation: number): void;
78
+ $setCanvasBackground(r: number, g: number, b: number, a: number): void;
76
79
  }
@@ -8,7 +8,8 @@ import { RenderState } from "./RenderState";
8
8
  export declare class GLRenderer {
9
9
  private _gl;
10
10
  private _currentShader;
11
- private _fullscreenQuadBuffer;
11
+ private _userShader;
12
+ private _userUniforms;
12
13
  private _ndcQuadBuffer;
13
14
  private readonly _geometries;
14
15
  private readonly _renderPipeline;
@@ -22,6 +23,22 @@ export declare class GLRenderer {
22
23
  */
23
24
  $shader(shader: GLShader): void;
24
25
  $createShader(vertexSource: string, fragmentSource: string): GLShader;
26
+ /**
27
+ * Set a custom user shader for subsequent rendering operations
28
+ */
29
+ $setUserShader(shader: GLShader | null): void;
30
+ /**
31
+ * Set a uniform value for the current user shader
32
+ */
33
+ $setUserUniform(name: string, value: any): void;
34
+ /**
35
+ * Set multiple uniform values for the current user shader
36
+ */
37
+ $setUserUniforms(uniforms: Record<string, any>): void;
38
+ /**
39
+ * Create a filter shader using the standard instanced vertex shader
40
+ */
41
+ $createFilterShader(fragmentSource: string): GLShader;
25
42
  /**
26
43
  * Draw a quad covering the pixel rectangle (x, y, width, height) on the canvas.
27
44
  * The quad is converted to NDC and rendered with the current shader using only a_position.
@@ -34,6 +34,10 @@ export declare class GLShader {
34
34
  */
35
35
  private _resetState;
36
36
  $setUniforms(uniforms: Record<string, UniformValue>): void;
37
+ /**
38
+ * Check if a uniform exists in this shader
39
+ */
40
+ $hasUniform(name: string): boolean;
37
41
  /**
38
42
  * Set a single uniform value with automatic texture unit management
39
43
  */
@@ -0,0 +1 @@
1
+ export {};