textmode.js 0.2.0-beta.2 → 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.
- package/dist/textmode.esm.js +1239 -1135
- package/dist/textmode.esm.min.js +1288 -1184
- package/dist/textmode.umd.js +20 -19
- package/dist/textmode.umd.min.js +19 -18
- package/dist/types/export/svg/SVGExporter.d.ts +5 -5
- package/dist/types/export/svg/types.d.ts +9 -0
- package/dist/types/rendering/webgl/DrawQueue.d.ts +2 -0
- package/dist/types/rendering/webgl/InstanceData.d.ts +6 -4
- package/dist/types/rendering/webgl/RenderPipeline.d.ts +7 -0
- package/dist/types/rendering/webgl/RenderState.d.ts +12 -4
- package/dist/types/rendering/webgl/Renderer.d.ts +18 -1
- package/dist/types/rendering/webgl/Shader.d.ts +4 -0
- package/dist/types/rendering/webgl/ShaderManager.d.ts +1 -0
- package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +4 -2
- package/dist/types/rendering/webgl/geometries/NoiseGrid.d.ts +1 -0
- package/dist/types/rendering/webgl/types/DrawCommand.d.ts +10 -1
- package/dist/types/rendering/webgl/types/RenderTypes.d.ts +2 -0
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +216 -4
- package/dist/types/textmode/mixins/ShaderMixin.d.ts +1 -0
- package/package.json +1 -1
package/dist/textmode.umd.min.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
var
|
|
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(
|
|
4
|
-
- ${n}: ${
|
|
3
|
+
📋 Context:`;for(const[n,o]of Object.entries(i))s+=`
|
|
4
|
+
- ${n}: ${v.o(o)}`}return s+=`
|
|
5
5
|
|
|
6
6
|
`,s+="↓".repeat(24)+`
|
|
7
|
-
`,s}static o(i){if(i===null)return"null";if(i===void 0)return"undefined";if(typeof i=="string")return`"${i}"`;if(typeof i=="number"||typeof i=="boolean")return i+"";if(Array.isArray(i))return i.length===0?"[]":i.length<=5?`[${i.map(r=>C.o(r)).join(", ")}]`:`[${i.slice(0,3).map(r=>C.o(r)).join(", ")}, ... +${i.length-3} more]`;if(typeof i=="object"){const r=Object.keys(i);return r.length===0?"{}":r.length<=3?`{ ${r.map(s=>`${s}: ${C.o(i[s])}`).join(", ")} }`:`{ ${r.slice(0,2).map(s=>`${s}: ${C.o(i[s])}`).join(", ")}, ... +${r.length-2} more }`}return i+""}}var F=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(F||{});const U=class U{constructor(){u(this,"l",{globalLevel:3})}static u(){return U.h||(U.h=new U),U.h}p(i,r){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.l.globalLevel){case 0:return!1;case 1:return console.group(s,n),console.warn(C.i(i,r)),console.groupEnd(),!1;case 2:return console.group(s,n),console.error(C.i(i,r)),console.groupEnd(),!1;default:throw new C(i,r)}}_(i,r,s){return!!i||(this.p(r,s),!1)}m(i){this.l.globalLevel=i}};u(U,"h",null);let O=U;const D=O.u(),V=new WeakMap;function $(c,i){V.set(c,i)}function B(c){return V.get(c)}class j{constructor(i,r,s=r,n=1,o={}){u(this,"v");u(this,"C");u(this,"l");u(this,"$",null);u(this,"M");u(this,"R");u(this,"S",[]);u(this,"A");u(this,"P",null);u(this,"F",[]);this.v=r,this.C=s,this.l={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.M=i,this.A=Math.min(Math.max(1,n),8);const a=i.getParameter(i.MAX_DRAW_BUFFERS),h=i.getParameter(i.MAX_COLOR_ATTACHMENTS);this.A=Math.min(this.A,a,h),this.R=i.createFramebuffer(),this.G(),this.D(),this.F=Array(this.A).fill(null)}G(){const i=this.M,r=this.l.filter==="linear"?i.LINEAR:i.NEAREST,s=this.l.wrap==="repeat"?i.REPEAT:i.CLAMP_TO_EDGE,n=this.l.type==="float"?i.FLOAT:i.UNSIGNED_BYTE;for(let o=0;o<this.A;o++){const a=i.createTexture();i.bindTexture(i.TEXTURE_2D,a),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,r),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,r),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,s),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,s),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,this.v,this.C,0,i.RGBA,n,null),this.S.push(a)}i.bindTexture(i.TEXTURE_2D,null)}D(){const i=this.M;if(i.bindFramebuffer(i.FRAMEBUFFER,this.R),this.A===1)i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,this.S[0],0);else{const s=[];for(let n=0;n<this.A;n++){const o=i.COLOR_ATTACHMENT0+n;i.framebufferTexture2D(i.FRAMEBUFFER,o,i.TEXTURE_2D,this.S[n],0),s.push(o)}i.drawBuffers(s)}const r=i.checkFramebufferStatus(i.FRAMEBUFFER);r!==i.FRAMEBUFFER_COMPLETE&&console.error("GLFramebuffer is not complete:",r),i.bindFramebuffer(i.FRAMEBUFFER,null)}I(i){const r=this.M;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,i),r.bindTexture(r.TEXTURE_2D,null)}L(i,r){this.v=i,this.C=r,this.$=null,this.F=Array(this.A).fill(null);const s=this.M,n=this.l.type==="float"?s.FLOAT:s.UNSIGNED_BYTE;for(const o of this.S)s.bindTexture(s.TEXTURE_2D,o),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,this.v,this.C,0,s.RGBA,n,null);s.bindTexture(s.TEXTURE_2D,null)}W(i){const r=this.M;if(i<0||i>=this.A)throw Error(`GLFramebuffer: attachment index ${i} out of range (count=${this.A})`);const s=this.F[i];if(s)return s;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.R),r.readBuffer(r.COLOR_ATTACHMENT0+i),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[i]=f,f}k(){for(let i=0;i<this.A;i++)this.W(i)}V(){const i=this.M;this.P={framebuffer:i.getParameter(i.FRAMEBUFFER_BINDING),viewport:i.getParameter(i.VIEWPORT)},i.bindFramebuffer(i.FRAMEBUFFER,this.R),this.F=Array(this.A).fill(null);for(let r=0;r<this.A;r++)i.clearBufferfv(i.COLOR,r,new Float32Array([0,0,0,0]));i.viewport(0,0,this.v,this.C),$(i,[0,0,this.v,this.C])}O(){if(!this.P)return;const i=this.M;i.bindFramebuffer(i.FRAMEBUFFER,this.P.framebuffer),i.viewport(...this.P.viewport),$(i,this.P.viewport),this.P=null}U(){const i=this.M;this.R&&i.deleteFramebuffer(this.R);for(const r of this.S)i.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.R}get texture(){return this.S[0]}get textures(){return[...this.S]}get attachmentCount(){return this.A}getAttachmentPixels(i){return this.F[i]??null}}class et{constructor(i,r,s){u(this,"M");u(this,"j");u(this,"H",new Map);u(this,"q",new Map);u(this,"N",0);u(this,"X");this.M=i,this.j=this.Y(r,s),this.X=i.getParameter(i.MAX_TEXTURE_IMAGE_UNITS),this.Z()}Z(){const i=this.M.getProgramParameter(this.j,this.M.ACTIVE_UNIFORMS);for(let r=0;r<i;r++){const s=this.M.getActiveUniform(this.j,r);if(s){const n=this.M.getUniformLocation(this.j,s.name);n&&(this.H.set(s.name,n),this.q.set(s.name,s.type))}}}Y(i,r){const s=this.J(this.M.VERTEX_SHADER,i),n=this.J(this.M.FRAGMENT_SHADER,r),o=this.M.createProgram();if(this.M.attachShader(o,s),this.M.attachShader(o,n),this.M.linkProgram(o),!this.M.getProgramParameter(o,this.M.LINK_STATUS)){const a=this.M.getProgramInfoLog(o);throw Error("Shader program link error: "+a)}return this.M.deleteShader(s),this.M.deleteShader(n),o}J(i,r){const s=this.M.createShader(i);if(this.M.shaderSource(s,r),this.M.compileShader(s),!this.M.getShaderParameter(s,this.M.COMPILE_STATUS)){const n=this.M.getShaderInfoLog(s);throw this.M.deleteShader(s),Error("Shader compilation error: "+n)}return s}K(){this.M.useProgram(this.j),this.tt()}tt(){this.N=0}et(i){for(const[r,s]of Object.entries(i))this.st(r,s)}st(i,r){const s=this.H.get(i);if(s)if(typeof r=="number")this.M.uniform1f(s,r);else if(typeof r=="boolean")this.M.uniform1i(s,r?1:0);else if(Array.isArray(r))switch(r.length){case 2:this.M.uniform2f(s,r[0],r[1]);break;case 3:this.M.uniform3f(s,r[0],r[1],r[2]);break;case 4:this.M.uniform4f(s,r[0],r[1],r[2],r[3]);break;default:console.warn(`Unsupported array length ${r.length} for uniform '${i}'`)}else if(r instanceof WebGLTexture){const n=this.it();this.M.uniform1i(s,n),this.M.activeTexture(this.M.TEXTURE0+n),this.M.bindTexture(this.M.TEXTURE_2D,r)}else if(r instanceof j){const n=this.it();this.M.uniform1i(s,n),this.M.activeTexture(this.M.TEXTURE0+n),this.M.bindTexture(this.M.TEXTURE_2D,r.texture)}else if(typeof r=="object"&&"texture"in r){const n=this.it();this.M.uniform1i(s,n),this.M.activeTexture(this.M.TEXTURE0+n),this.M.bindTexture(this.M.TEXTURE_2D,r.texture)}else console.warn(`Unsupported uniform type for '${i}':`,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.M.deleteProgram(this.j)}}class it{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",[0,0,0,1]);u(this,"vt",[])}xt(){this.vt.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]})}Ct(){const i=this.vt.pop();i?(this.nt=i.lineWeight,this.ot=i.rotation,this.gt=i.charRotation,this.ut=i.flipHorizontally,this.ft=i.flipVertically,this.dt=i.invert,this.ht=i.character,this.ct=i.charColor,this.lt=i.cellColor):console.warn("pop() called without matching push()")}yt(){this.vt=[],this.ot=0}wt(i){i.lineWeight=this.nt,i.rotation=this.ot,i.character[0]=this.ht[0],i.character[1]=this.ht[1],i.character[2]=this.ht[2],i.charColor[0]=this.ct[0],i.charColor[1]=this.ct[1],i.charColor[2]=this.ct[2],i.charColor[3]=this.ct[3],i.bgColor[0]=this.lt[0],i.bgColor[1]=this.lt[1],i.bgColor[2]=this.lt[2],i.bgColor[3]=this.lt[3],i.flipHorizontally=this.ut,i.flipVertically=this.ft,i.invert=this.dt,i.charRotation[0]=this.gt[0],i.charRotation[1]=this.gt[1]}get lineWeight(){return this.nt}get canvasBackgroundColor(){return this._t}$t(i){this.nt=Math.abs(i)}bt(i){this.ot=i}Tt(i){this.ht=i}zt(i,r,s,n=255){this.ct=[i/255,r/255,s/255,n/255]}Mt(i,r,s,n=255){this.lt=[i/255,r/255,s/255,n/255]}Rt(i){this.ut=i}St(i){this.ft=i}At(i){this.dt=i}Pt(i){const r=255*i/360,s=Math.floor(r)/255,n=Math.round(r-Math.floor(r));this.gt=[s,n]}Ft(i,r,s,n){this._t=[i/255,r/255,s/255,n/255]}}var v=(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))(v||{});class rt{constructor(i){u(this,"M");u(this,"Gt",new Map);this.M=i}Dt(i,r,s,n){const o=this.M;let a=this.Gt.get(i);a||(a=new Map,this.Gt.set(i,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(i,"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(i,"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)}It(){this.M.bindVertexArray(null)}U(){const i=this.M;for(const[,r]of this.Gt)for(const[,s]of r)s&&i.deleteVertexArray(s);this.Gt.clear()}}class st{constructor(i){u(this,"Bt");u(this,"M");this.M=i,this.Bt=new rt(i)}Lt(i,r,s){const{shader:n}=i,o=B(this.M)||this.M.getParameter(this.M.VIEWPORT);n.et({u_aspectRatio:o[2]/o[3],u_viewportSize:[o[2],o[3]]});const a=f=>{if(!f||!f.Et())return;const d=f.unitGeometry,p=f.unitBuffer;try{this.Bt.Dt(n.rt,f.type+"",d,p),f.batch.Wt(n),f.batch.kt(d.primitiveType,d.vertexCount)}finally{f.batch.Vt(n),this.Bt.It(),f.Ot()}};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=s.get(f.type)||null,l=d,h=f.type),d&&d.Ut(f.params,f.state)}a(l)}}class nt{constructor(){u(this,"jt",[]);u(this,"Ht",1);u(this,"qt",0)}Nt(i){if(this.qt>=this.jt.length){const s={id:this.Ht++,type:i,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.jt.push(s)}const r=this.jt[this.qt];switch(r.id=this.Ht++,r.type=i,i){case v.RECTANGLE:case v.ELLIPSE:r.params&&"width"in r.params||(r.params={x:0,y:0,width:0,height:0});break;case v.ARC:r.params&&"start"in r.params||(r.params={x:0,y:0,width:0,height:0,start:0,stop:0});break;case v.LINE:r.params&&"x2"in r.params||(r.params={x1:0,y1:0,x2:0,y2:0,thickness:void 0});break;case v.TRIANGLE:r.params&&"x3"in r.params||(r.params={x1:0,y1:0,x2:0,y2:0,x3:0,y3:0});break;case v.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.qt++,r}Xt(i,r,s,n,o){const a=this.Nt(v.RECTANGLE);return a.params.x=i,a.params.y=r,a.params.width=s,a.params.height=n,o.wt(a.state),a.id}Yt(i,r,s,n,o,a){const h=this.Nt(v.LINE);return h.params.x1=i,h.params.y1=r,h.params.x2=s,h.params.y2=n,h.params.thickness=o,a.wt(h.state),h.id}Qt(i,r,s,n,o){const a=this.Nt(v.ELLIPSE);return a.params.x=i,a.params.y=r,a.params.width=s,a.params.height=n,o.wt(a.state),a.id}Zt(i,r,s,n,o,a,h){const l=this.Nt(v.ARC);return l.params.x=i,l.params.y=r,l.params.width=s,l.params.height=n,l.params.start=o,l.params.stop=a,h.wt(l.state),l.id}Jt(i,r,s,n,o,a,h){const l=this.Nt(v.TRIANGLE);return l.params.x1=i,l.params.y1=r,l.params.x2=s,l.params.y2=n,l.params.x3=o,l.params.y3=a,h.wt(l.state),l.id}Kt(i,r,s,n,o,a,h,l,f,d){const p=this.Nt(v.BEZIER_CURVE);return p.params.x1=i,p.params.y1=r,p.params.cp1x=s,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.wt(p.state),p.id}get length(){return this.qt}get isEmpty(){return this.qt===0}te(){this.qt=0}[Symbol.iterator](){let i=0;const r=this.qt,s=this.jt;return{next:()=>i<r?{value:s[i++],done:!1}:{value:void 0,done:!0}}}}const S=class S{static ee(i,r,s=0){var a,h,l,f,d,p,g,x,m,y;const n=r||new Float32Array(S.FLOATS_PER_INSTANCE);let o=s;return n[o++]=i.position[0],n[o++]=i.position[1],n[o++]=i.size[0],n[o++]=i.size[1],n[o++]=i.character[0],n[o++]=i.character[1],n[o++]=i.character[2],n[o++]=i.primaryColor[0],n[o++]=i.primaryColor[1],n[o++]=i.primaryColor[2],n[o++]=i.primaryColor[3],n[o++]=i.secondaryColor[0],n[o++]=i.secondaryColor[1],n[o++]=i.secondaryColor[2],n[o++]=i.secondaryColor[3],n[o++]=i.rotation[0],n[o++]=i.rotation[1],n[o++]=i.transform[0],n[o++]=i.transform[1],n[o++]=i.transform[2],n[o++]=i.globalRotation,n[o++]=i.rotationCenter[0],n[o++]=i.rotationCenter[1],n[o++]=((a=i.arcAngles)==null?void 0:a[0])||0,n[o++]=((h=i.arcAngles)==null?void 0:h[1])||0,n[o++]=((l=i.bezierControlPoint1)==null?void 0:l[0])||0,n[o++]=((f=i.bezierControlPoint1)==null?void 0:f[1])||0,n[o++]=((d=i.bezierControlPoint2)==null?void 0:d[0])||0,n[o++]=((p=i.bezierControlPoint2)==null?void 0:p[1])||0,n[o++]=((g=i.bezierStartPoint)==null?void 0:g[0])||0,n[o++]=((x=i.bezierStartPoint)==null?void 0:x[1])||0,n[o++]=((m=i.bezierEndPoint)==null?void 0:m[0])||0,n[o++]=((y=i.bezierEndPoint)==null?void 0:y[1])||0,n}static se(i){const r=i.length*S.FLOATS_PER_INSTANCE,s=new Float32Array(r);for(let n=0;n<i.length;n++){const o=n*S.FLOATS_PER_INSTANCE;S.ee(i[n],s,o)}return s}};u(S,"BYTES_PER_INSTANCE",132),u(S,"FLOATS_PER_INSTANCE",33);let P=S;const R=class R{};u(R,"STRIDE",P.BYTES_PER_INSTANCE),u(R,"ATTRIBUTES",{a_instancePosition:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:0,divisor:1},a_instanceSize:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:8,divisor:1},a_instanceCharacter:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:16,divisor:1},a_instancePrimaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:28,divisor:1},a_instanceSecondaryColor:{location:-1,size:4,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:44,divisor:1},a_instanceRotation:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:60,divisor:1},a_instanceTransform:{location:-1,size:3,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:68,divisor:1},a_instanceGlobalRotation:{location:-1,size:1,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:80,divisor:1},a_instanceRotationCenter:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:84,divisor:1},a_instanceArcAngles:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:92,divisor:1},a_instanceBezierCP1:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:100,divisor:1},a_instanceBezierCP2:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:108,divisor:1},a_instanceBezierStart:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:116,divisor:1},a_instanceBezierEnd:{location:-1,size:2,type:WebGL2RenderingContext.FLOAT,normalized:!1,stride:R.STRIDE,offset:124,divisor:1}});let z=R;class ot{constructor(i,r=1e3,s=1.5){u(this,"M");u(this,"ie",[]);u(this,"re");u(this,"ne");u(this,"oe",null);u(this,"ae",!0);u(this,"he",0);u(this,"ce",new Map);u(this,"le",null);this.M=i,this.re=r,this.ne=s,this.ue()}Ut(i){const r=this.ie.length;return this.ie.push(i),this.ae=!0,r}get count(){return this.ie.length}get isEmpty(){return this.ie.length===0}clear(){this.ie.length=0,this.ae=!0}fe(i){if(i<=this.re)return;const r=Math.ceil(i*this.ne);this.re=r,this.ue(),console.log(`InstanceBatch: Grew buffer capacity to ${r} instances`)}ue(){const i=this.M;if(this.oe&&i.deleteBuffer(this.oe),this.oe=i.createBuffer(),!this.oe)throw Error("Failed to create instance buffer");const r=this.re*P.BYTES_PER_INSTANCE;i.bindBuffer(i.ARRAY_BUFFER,this.oe),i.bufferData(i.ARRAY_BUFFER,r,i.DYNAMIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),this.ae=!0,this.he=0}de(){if(!this.ae||this.ie.length===0)return;const i=this.M,r=this.ie.length;this.fe(r),(!this.le||this.le.length<r*P.FLOATS_PER_INSTANCE)&&(this.le=new Float32Array(r*P.FLOATS_PER_INSTANCE));const s=P.se(this.ie);i.bindBuffer(i.ARRAY_BUFFER,this.oe),r<=this.he?i.bufferSubData(i.ARRAY_BUFFER,0,s):i.bufferData(i.ARRAY_BUFFER,s,i.DYNAMIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),this.ae=!1,this.he=r}pe(i){let r=this.ce.get(i);if(!r){r=new Map;const s=this.M;for(const n in z.ATTRIBUTES){const o=s.getAttribLocation(i,n);o!==-1&&r.set(n,o)}this.ce.set(i,r)}return r}Wt(i){if(!this.oe||this.ie.length===0)return;const r=this.M,s=i.rt;if(!s)return void console.warn("InstanceBatch: Cannot bind attributes - invalid shader program");this.de();const n=this.pe(s);r.bindBuffer(r.ARRAY_BUFFER,this.oe);for(const[o,a]of n){const h=z.ATTRIBUTES[o];h&&(r.enableVertexAttribArray(a),r.vertexAttribPointer(a,h.size,h.type,h.normalized,h.stride,h.offset),r.vertexAttribDivisor(a,h.divisor))}}Vt(i){const r=this.M,s=this.pe(i.rt);for(const[,n]of s)r.disableVertexAttribArray(n),r.vertexAttribDivisor(n,0)}kt(i,r){this.ie.length!==0&&this.M.drawArraysInstanced(i,0,r,this.ie.length)}U(){const i=this.M;this.oe&&(i.deleteBuffer(this.oe),this.oe=null),this.ie.length=0,this.ce.clear(),this.le=null}}class I{constructor(i,r,s,n){u(this,"M");u(this,"ge");u(this,"_e");u(this,"me");u(this,"ve",null);this.M=i,this.ge=r,this._e=s,this.me=n;const o=this.M.createBuffer();if(!o)throw Error("Failed to create unit geometry buffer");this.M.bindBuffer(this.M.ARRAY_BUFFER,o),this.M.bufferData(this.M.ARRAY_BUFFER,this.me.vertices,this.M.STATIC_DRAW),this.M.bindBuffer(this.M.ARRAY_BUFFER,null),this.ve=o}get type(){return this._e}get unitGeometry(){return this.me}get unitBuffer(){return this.ve}get batch(){return this.ge}Ot(){this.ge.clear()}Et(){return!this.ge.isEmpty}U(){this.ge.U(),this.ve&&(this.M.deleteBuffer(this.ve),this.ve=null)}xe(i,r,s,n,o){const a=this.Ce(i,r,s,n,o.rotation||0);return{position:[i,r],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],globalRotation:a.radians,rotationCenter:[a.centerX,a.centerY]}}ye(i,r){const s=B(this.M)||[0,0,this.M.canvas.width,this.M.canvas.height];return{nx:i/s[2]*2-1,ny:1-r/s[3]*2}}we(i,r,s){const n=this.ye(r,s);i.rotationCenter=[n.nx,n.ny]}Ce(i,r,s,n,o){const a=B(this.M)||[0,0,this.M.canvas.width,this.M.canvas.height],h=a[2],l=a[3];return{centerX:(i+s/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 I{constructor(i,r){super(i,r,v.RECTANGLE,at)}Ut(i,r){const s=this.xe(i.x,i.y,i.width,i.height,r);return this.ge.Ut(s)}}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 I{constructor(i,r){super(i,r,v.LINE,ct)}Ut(i,r){const s=i.x2-i.x1,n=i.y2-i.y1,o=Math.hypot(s,n),a=Math.atan2(n,s),h=i.thickness||r.lineWeight||1,l=i.x1+s/2,f=i.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},x=this.xe(d,p,o,h,g);return this.we(x,l,f),this.ge.Ut(x)}}const ut={vertices:function(c=32){const i=[],r=2*Math.PI/c;for(let s=0;s<c;s++){const n=s*r,o=(s+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),x=.5*(p+1);i.push(0,0,.5,.5,a,h,l,f,d,p,g,x)}return new Float32Array(i)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class ft extends I{constructor(i,r){super(i,r,v.ELLIPSE,ut)}Ut(i,r){const s=this.xe(i.x,i.y,i.width,i.height,r);return this.we(s,i.x,i.y),this.ge.Ut(s)}}let dt={vertices:function(c){const i=[];for(let r=0;r<c;r++){const s=r/c,n=(r+1)/c;i.push(s,0,s,0,s,1,s,1,n,1,n,1)}return new Float32Array(i)}(32),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class pt extends I{constructor(i,r){super(i,r,v.ARC,dt)}Ut(i,r){const s=i.x-i.width/2,n=i.y-i.height/2,o=i.start*Math.PI/180,a=i.stop*Math.PI/180,h=this.xe(s,n,i.width,i.height,r);return this.we(h,i.x,i.y),h.arcAngles=[o,a],this.ge.Ut(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 I{constructor(i,r){super(i,r,v.TRIANGLE,gt)}Ut(i,r){const s=Math.min(i.x1,i.x2,i.x3),n=Math.max(i.x1,i.x2,i.x3),o=Math.min(i.y1,i.y2,i.y3),a=n-s,h=Math.max(i.y1,i.y2,i.y3)-o,l=this.xe(s,o,a,h,r),f=s+.5*a,d=o+h*(1/3);return this.we(l,f,d),this.ge.Ut(l)}}function X(c,i,r,s,n){const o=1-c,a=o*o,h=c*c;return a*o*i+3*a*c*r+3*o*h*s+h*c*n}const xt={vertices:function(c=16){const i=[];for(let r=0;r<c;r++){const s=r/c,n=(r+1)/c;i.push(s,-.5,s,0),i.push(n,-.5,n,0),i.push(s,.5,s,1),i.push(s,.5,s,1),i.push(n,-.5,n,0),i.push(n,.5,n,1)}return new Float32Array(i)}(16),vertexCount:96,primitiveType:WebGL2RenderingContext.TRIANGLES,stride:16,attributes:{position:{size:2,offset:0},texCoord:{size:2,offset:8}}};class yt extends I{constructor(i,r){super(i,r,v.BEZIER_CURVE,xt)}Ut(i,r){const s=r.lineWeight||1,n=X(.5,i.x1,i.cp1x,i.cp2x,i.x2),o=X(.5,i.y1,i.cp1y,i.cp2y,i.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:s},h=this.xe(0,0,1,s,a);return this.we(h,n,o),h.bezierStartPoint=[i.x1,i.y1],h.bezierControlPoint1=[i.cp1x,i.cp1y],h.bezierControlPoint2=[i.cp2x,i.cp2y],h.bezierEndPoint=[i.x2,i.y2],this.ge.Ut(h)}}class vt{constructor(i){u(this,"M");u(this,"$e",null);u(this,"be",null);u(this,"Te",null);u(this,"ze",new Map);u(this,"Me");u(this,"Re");u(this,"Se");this.M=i,this.Se=new it,this.Me=new st(i),this.Re=new nt,this.be=i.createBuffer(),i.bindBuffer(i.ARRAY_BUFFER,this.be),i.bufferData(i.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]),i.STATIC_DRAW),this.Te=i.createBuffer(),$(this.M,[0,0,this.M.canvas.width,this.M.canvas.height])}Ae(i){let r=this.ze.get(i);if(r)return r;const s=new ot(this.M);return r=(0,{[v.RECTANGLE]:()=>new ht(this.M,s),[v.LINE]:()=>new lt(this.M,s),[v.ELLIPSE]:()=>new ft(this.M,s),[v.ARC]:()=>new pt(this.M,s),[v.TRIANGLE]:()=>new mt(this.M,s),[v.BEZIER_CURVE]:()=>new yt(this.M,s)}[i])(),this.ze.set(i,r),r}Pe(i){this.$e!==i&&(this.$e=i,i.K())}Fe(i,r){return new et(this.M,i,r)}Ge(i,r,s,n){var y;const o=this.M,a=o.canvas.width,h=o.canvas.height,l=i/a*2-1,f=(i+s)/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.Te),o.bufferData(o.ARRAY_BUFFER,g,o.DYNAMIC_DRAW);const x=((y=this.$e)==null?void 0:y.rt)||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)}De(i,r,s,n){this.Re.Xt(i,r,s,n,this.Se)}Ie(i,r,s,n){this.Re.Yt(i,r,s,n,this.Se.lineWeight,this.Se)}Be(i,r,s,n){this.Re.Qt(i,r,s,n,this.Se)}Le(i,r,s,n,o,a){this.Re.Jt(i,r,s,n,o,a,this.Se)}Ee(i,r,s,n,o,a,h,l){const f=this.Se.lineWeight;this.Re.Kt(i,r,s,n,o,a,h,l,f,this.Se)}We(i,r,s=1,n={}){return new j(this.M,i,r,s,n)}ke(i,r,s,n,o,a){this.Re.Zt(i,r,s,n,o,a,this.Se)}Ve(i,r=i,s=i,n=255){this.state.Ft(i,r,s,n),this.te(i/255,r/255,s/255,n/255)}te(i=0,r=0,s=0,n=0){this.M.clearColor(i,r,s,n),this.M.clear(this.M.COLOR_BUFFER_BIT)}Oe(){this.M.viewport(0,0,this.M.canvas.width,this.M.canvas.height),$(this.M,[0,0,this.M.canvas.width,this.M.canvas.height])}get context(){return this.M}get state(){return this.Se}Ue(i){const r=B(this.M)??this.M.getParameter(this.M.VIEWPORT),s={shader:i,gl:this.M,viewport:r},n=new Set;for(const o of this.Re)n.add(o.type);for(const o of n)this.Ae(o);this.Me.Lt(s,this.Re,this.ze),this.Re.te()}U(){this.M.deleteBuffer(this.be),this.M.deleteBuffer(this.Te),this.Re.te();for(const i of this.ze.values())i.U()}}const T={readShort:(c,i)=>(T.t.uint16[0]=c[i]<<8|c[i+1],T.t.int16[0]),readUshort:(c,i)=>c[i]<<8|c[i+1],readUshorts(c,i,r){const s=[];for(let n=0;n<r;n++)s.push(T.readUshort(c,i+2*n));return s},readUint(c,i){const r=T.t.uint8;return r[3]=c[i],r[2]=c[i+1],r[1]=c[i+2],r[0]=c[i+3],T.t.uint32[0]},readASCII(c,i,r){let s="";for(let n=0;n<r;n++)s+=String.fromCharCode(c[i+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)}})()},Ct={parseTab(c,i,r){const s={tables:[],ids:{},off:i};c=new Uint8Array(c.buffer,i,r),i=0;const n=T,o=n.readUshort,a=o(c,i+=2);i+=2;const h=[];for(let l=0;l<a;l++){const f=o(c,i),d=o(c,i+=2);i+=2;const p=n.readUint(c,i);i+=4;const g=`p${f}e${d}`;let x=h.indexOf(p);if(x===-1){let m;x=s.tables.length,h.push(p);const y=o(c,p);m=y===4?this.parse4(c,p):y===12?this.parse12(c,p):{format:y},s.tables.push(m)}s.ids[g]!=null&&console.warn("Multiple tables for one platform+encoding: "+g),s.ids[g]=x}return s},parse4(c,i){const r=T,s=r.readUshort,n=r.readUshorts,o=i,a=s(c,i+=2);i+=2;const h=s(c,i+=2)>>>1,l={format:4,searchRange:s(c,i+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};i+=2,l.entrySelector=s(c,i),i+=2,l.rangeShift=s(c,i),i+=2,l.endCount=n(c,i,h),i+=2*h,i+=2,l.startCount=n(c,i,h),i+=2*h;for(let f=0;f<h;f++)l.idDelta.push(r.readShort(c,i)),i+=2;return l.idRangeOffset=n(c,i,h),i+=2*h,l.glyphIdArray=n(c,i,o+a-i>>1),l},parse12(c,i){const r=T.readUint;r(c,i+=4),r(c,i+=4);const s=r(c,i+=4);i+=4;const n=new Uint32Array(3*s);for(let o=0;o<3*s;o+=3)n[o]=r(c,i+(o<<2)),n[o+1]=r(c,i+(o<<2)+4),n[o+2]=r(c,i+(o<<2)+8);return{format:12,groups:n}}},Rt={parseTab(c,i,r){const s=T;i+=18;const n=s.readUshort(c,i);i+=2,i+=16;const o=s.readShort(c,i);i+=2;const a=s.readShort(c,i);i+=2;const h=s.readShort(c,i);i+=2;const l=s.readShort(c,i);return i+=2,i+=6,{unitsPerEm:n,xMin:o,yMin:a,xMax:h,yMax:l,indexToLocFormat:s.readShort(c,i)}}},wt={parseTab(c,i,r){const s=T;i+=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,i+2*a)}return o}},Tt={parseTab(c,i,r,s){const n=T,o=[],a=[],h=s.maxp.numGlyphs,l=s.hhea.numberOfHMetrics;let f=0,d=0,p=0;for(;p<l;)f=n.readUshort(c,i+(p<<2)),d=n.readShort(c,i+(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}}},Y={cmap:Ct,head:Rt,hhea:wt,maxp:{parseTab(c,i,r){const s=T;return s.readUint(c,i),i+=4,{numGlyphs:s.readUshort(c,i)}}},hmtx:Tt,loca:{parseTab(c,i,r,s){const n=T,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,i+(l<<1))<<1);else if(a===1)for(let l=0;l<h;l++)o.push(n.readUint(c,i+(l<<2)));return o}},glyf:{parseTab(c,i,r,s){const n=[],o=s.maxp.numGlyphs;for(let a=0;a<o;a++)n.push(null);return n},je(c,i){const r=T,s=c.He,n=c.loca;if(n[i]===n[i+1])return null;const o=M.findTable(s,"glyf",c.qe);if(!o)return null;let a=o[0]+n[i];const h={};if(h.noc=r.readShort(s,a),a+=2,h.xMin=r.readShort(s,a),a+=2,h.yMin=r.readShort(s,a),a+=2,h.xMax=r.readShort(s,a),a+=2,h.yMax=r.readShort(s,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(s,a)),a+=2;const l=r.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 g=0;g<f;g++){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),g++}}h.xs=[];for(let g=0;g<f;g++){const x=h.flags[g],m=!!(16&x);2&x?(h.xs.push(m?s[a]:-s[a]),a++):m?h.xs.push(0):(h.xs.push(r.readShort(s,a)),a+=2)}h.ys=[];for(let g=0;g<f;g++){const x=h.flags[g],m=!!(32&x);4&x?(h.ys.push(m?s[a]:-s[a]),a++):m?h.ys.push(0):(h.ys.push(r.readShort(s,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}}},M={parse:c=>[((i,r,s,n)=>{const o=Y,a={He:i,Ne:r,qe:s};for(const h in o){const l=h,f=M.findTable(i,l,s);if(f){const[d,p]=f;let g=n[d];g==null&&(g=o[l].parseTab(i,d,p,a),n[d]=g),a[l]=g}}return a})(new Uint8Array(c),0,0,{})],findTable(c,i,r){const s=T,n=s.readUshort(c,r+4);let o=r+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===i)return[l,f];o+=16}return null},T:Y,B:T};class G{constructor(){u(this,"Xe",new Map);u(this,"Ye",new Map)}Qe(i,r){const s=`${this.Ze(i)}_${r}`;if(this.Xe.has(s))return this.Xe.get(s);const n=i.cmap;if(!n||!n.tables)return this.Xe.set(s,0),0;let o=0;for(const a of n.tables)if(a.format===4?o=this.Je(r,a):a.format===12&&(o=this.Ke(r,a)),o>0)break;return this.Xe.set(s,o),o}ts(i,r){const s=r.codePointAt(0);return s===void 0?0:this.Qe(i,s)}es(i,r){const s=i.hmtx;return s&&s.aWidth&&s.aWidth.length!==0?r<s.aWidth.length?s.aWidth[r]:s.aWidth[s.aWidth.length-1]:0}ss(i,r){const s=r/i.head.unitsPerEm,n=i.hhea.ascender*s,o=i.hhea.descender*s,a=i.hhea.lineGap*s;return{ascender:n,descender:o,lineGap:a,lineHeight:n-o+a,unitsPerEm:i.head.unitsPerEm,scale:s}}rs(){this.Xe.clear(),this.Ye.clear()}Ze(i){return`${i.qe}_${i.He.length}`}Je(i,r){const s=r.endCount.length;let n=-1;for(let o=0;o<s;o++)if(i<=r.endCount[o]){n=o;break}if(n===-1||i<r.startCount[n])return 0;if(r.idRangeOffset[n]===0)return i+r.idDelta[n]&65535;{const o=r.idRangeOffset[n]/2+(i-r.startCount[n])-(s-n);if(o>=0&&o<r.glyphIdArray.length){const a=r.glyphIdArray[o];return a===0?0:a+r.idDelta[n]&65535}}return 0}Ke(i,r){const s=r.groups.length/3;for(let n=0;n<s;n++){const o=r.groups[3*n],a=r.groups[3*n+1],h=r.groups[3*n+2];if(i>=o&&i<=a)return h+(i-o)}return 0}}class bt{constructor(i){u(this,"ns");this.ns=i}hs(i){var s;const r=[];return(s=i.cmap)!=null&&s.tables?(i.cmap.tables.forEach(n=>{if(n.format===4){const o=this.cs(n);r.push(...o)}else if(n.format===12){const o=this.ls(n);r.push(...o)}}),[...new Set(r)]):[]}us(i,r){return this.ns.ts(i,r)>0}fs(i,r){for(const s of r)if(!this.us(i,s))return!1;return!0}ds(i,r){return r.filter(s=>this.us(i,s))}ps(i){return i.filter(r=>this.gs(r))}cs(i){const r=[];if(!(i.startCount&&i.endCount&&i.idRangeOffset&&i.idDelta))return r;for(let s=0;s<i.startCount.length;s++){const n=i.startCount[s],o=i.endCount[s];if(n!==65535||o!==65535){for(let a=n;a<=o;a++)if(this._s(i,a,s)>0)try{const h=String.fromCodePoint(a);r.push(h)}catch{}}}return r}ls(i){const r=[];if(!i.groups)return r;for(let s=0;s<i.groups.length;s+=3){const n=i.groups[s],o=i.groups[s+1],a=i.groups[s+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}_s(i,r,s){if(i.idRangeOffset[s]===0)return r+i.idDelta[s]&65535;{const n=i.idRangeOffset[s]/2+(r-i.startCount[s])-(i.startCount.length-s);if(n>=0&&i.glyphIdArray&&n<i.glyphIdArray.length){const o=i.glyphIdArray[n];if(o!==0)return o+i.idDelta[s]&65535}}return 0}gs(i){const r=i.codePointAt(0)||0;return!(r>=0&&r<=31&&r!==9&&r!==10&&r!==13||r>=127&&r<=159)}}class Et{constructor(){u(this,"vs");const i=new G;this.vs=new bt(i)}extractCharacters(i){return this.vs.hs(i)}filterProblematicCharacters(i){return this.vs.ps(i)}characterExists(i,r){return this.vs.us(i,r)}allCharactersExist(i,r){return this.vs.fs(i,r)}}class At{constructor(i){u(this,"Cs");u(this,"ws");u(this,"$s");u(this,"bs");this.$s=i,this.bs=new G,this.Cs=document.createElement("canvas"),this.ws=this.Cs.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(i,r,s,n){const o=i.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.Ts(l,f),this.zs(i,r,a,s,d);const p=this.$s.We(l,f,1,{filter:"nearest"});return p.I(this.Cs),{framebuffer:p,columns:a,rows:h}}Ts(i,r){this.Cs.width=i,this.Cs.height=r,this.Cs.style.width=i+"px",this.Cs.style.height=i+"px",this.ws.imageSmoothingEnabled=!1,this.Cs.style.imageRendering="pixelated",this.ws.fillStyle="black",this.ws.fillRect(0,0,i,r),this.ws.textBaseline="top",this.ws.textAlign="left",this.ws.fillStyle="white"}zs(i,r,s,n,o){const a=n/o.head.unitsPerEm;for(let h=0;h<i.length;h++){const l=h%s,f=Math.floor(h/s),d=i[h].character,p=this.Ms(o,d);if(!p)continue;const g=d.codePointAt(0)||0,x=this.bs.Qe(o,g),m=this.Rs(o,x)*a,y=l*r.width,E=f*r.height,b=y+.5*r.width,A=E+.5*r.height,_=Math.round(b-.5*r.width),L=Math.round(A-.5*n),Qt=_+.5*(r.width-m),Jt=L+o.hhea.ascender*a;this.Ss(p,Qt,Jt,a)}}Ms(i,r){const s=r.codePointAt(0)||0,n=this.bs.Qe(i,s);if(n===0)return null;if(i.glyf&&i.glyf[n]!==null)return i.glyf[n];if(M&&M.T&&M.T.glyf){const o=M.T.glyf.je(i,n);return i.glyf&&o&&(i.glyf[n]=o),o}return null}Rs(i,r){const s=i.hmtx;return s&&s.aWidth?r<s.aWidth.length?s.aWidth[r]:s.aWidth[s.aWidth.length-1]:0}Ss(i,r,s,n){if(!i||!i.xs||i.noc===0)return;const{xs:o,ys:a,endPts:h,flags:l}=i;if(!(o&&a&&h&&l))return;this.ws.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,x=s-a[f]*n;this.ws.moveTo(g,x);let m=f+1;for(;m<=p;)if(1&l[m]){const y=r+o[m]*n,E=s-a[m]*n;this.ws.lineTo(y,E),m++}else{const y=r+o[m]*n,E=s-a[m]*n;let b=m+1>p?f:m+1;if(1&l[b]){const A=r+o[b]*n,_=s-a[b]*n;this.ws.quadraticCurveTo(y,E,A,_),m=b+1}else{const A=(y+(r+o[b]*n))/2,_=(E+(s-a[b]*n))/2;this.ws.quadraticCurveTo(y,E,A,_),m=b}}this.ws.closePath()}f=p+1}}this.ws.fill()}}class Mt{constructor(){u(this,"ns");this.ns=new G}calculateMaxGlyphDimensions(i,r,s){let n=0;const o=this.ns.ss(s,r),a=o.lineHeight;for(const h of i){const l=this.ns.ts(s,h);if(l===0)continue;const f=this.ns.es(s,l)*o.scale;n=Math.max(n,f)}return{width:Math.ceil(n),height:Math.ceil(a)}}getCharacterAdvanceWidth(i,r,s){const n=this.ns.ss(s,r),o=this.ns.ts(s,i);return this.ns.es(s,o)*n.scale}getFontMetrics(i,r){return this.ns.ss(r,i)}rs(){this.ns.rs()}}class _t{constructor(){u(this,"bs");this.bs=new G}createCharacterObjects(i,r){return i.map((s,n)=>{const o=s.codePointAt(0)||0,a=this.As(n);let h=0;if(r.hmtx&&r.hmtx.aWidth){const l=this.bs.Qe(r,o);l>0&&r.hmtx.aWidth[l]!==void 0&&(h=r.hmtx.aWidth[l])}return{character:s,unicode:o,color:a,advanceWidth:h}})}As(i){return[i%256/255,Math.floor(i/256)%256/255,Math.floor(i/65536)%256/255]}Ps(i,r){if(!D._(typeof i=="string","Character must be a string.",{method:"getCharacterColor",providedValue:i}))return[0,0,0];const s=r.find(n=>n.character===i);return s?s.color:[0,0,0]}Fs(i,r){return D._(typeof i=="string"&&i.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:i})?Array.from(i).map(s=>this.Ps(s,r)||[0,0,0]):[[0,0,0]]}}class H{constructor(i,r=16){u(this,"Gs");u(this,"Ds",[]);u(this,"Is");u(this,"Bs",16);u(this,"Ls",0);u(this,"Es",0);u(this,"Ws",{width:0,height:0});u(this,"ks");u(this,"Vs");u(this,"Os");u(this,"Us");u(this,"js");this.Bs=r,this.Vs=new Et,this.Os=new At(i),this.Us=new Mt,this.js=new _t}async Hs(i){let r;if(!i)throw new C("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const s=await fetch(i);if(!s.ok)throw new C(`Failed to load font file: ${s.status} ${s.statusText}`);r=await s.arrayBuffer()}await this.qs(r),this.Gs=M.parse(r)[0],await this.Ns()}Xs(i){if(i===void 0)return this.Bs;this.Bs=i,this.Ws=this.Us.calculateMaxGlyphDimensions(this.Ds.map(s=>s.character),this.Bs,this.Gs);const r=this.Os.createTextureAtlas(this.Ds,this.Ws,this.Bs,this.Gs);this.Is=r.framebuffer,this.Ls=r.columns,this.Es=r.rows}async Ys(i){try{const r=await fetch(i);if(!r.ok)throw new C(`Failed to load font file: ${r.status} ${r.statusText}`);const s=await r.arrayBuffer();await this.qs(s);const n=M.parse(s);if(!n||n.length===0)throw Error("Failed to parse font file");this.Gs=n[0],await this.Ns()}catch(r){throw new C("Failed to load font: "+(r instanceof Error?r.message:"Unknown error"),r)}}async qs(i){const r=Date.now();this.ks=new FontFace("CustomFont_"+r,i),await this.ks.load(),document.fonts.add(this.ks)}async Ns(){const i=this.Vs.extractCharacters(this.Gs),r=this.Vs.filterProblematicCharacters(i);this.Ds=this.js.createCharacterObjects(r,this.Gs),this.Ws=this.Us.calculateMaxGlyphDimensions(r,this.Bs,this.Gs);const s=this.Os.createTextureAtlas(this.Ds,this.Ws,this.Bs,this.Gs);this.Is=s.framebuffer,this.Ls=s.columns,this.Es=s.rows}Ps(i){return this.js.Ps(i,this.Ds)}Fs(i){return this.js.Fs(i,this.Ds)}U(){this.Is.U(),document.fonts.delete(this.ks)}get fontFramebuffer(){return this.Is}get characters(){return this.Ds}get textureColumns(){return this.Ls}get textureRows(){return this.Es}get maxGlyphDimensions(){return this.Ws}get fontSize(){return this.Bs}get font(){return this.Gs}}class q{constructor(i,r,s){u(this,"Qs");u(this,"Zs");u(this,"v");u(this,"C");u(this,"Js");u(this,"Ks");u(this,"ti");u(this,"ei");u(this,"si");this.ti=i,this.ei=r,this.si=s,this.yt()}yt(){this.Qs=Math.floor(this.ti.width/this.ei),this.Zs=Math.floor(this.ti.height/this.si),this.v=this.Qs*this.ei,this.C=this.Zs*this.si,this.Js=Math.floor((this.ti.width-this.v)/2),this.Ks=Math.floor((this.ti.height-this.C)/2)}ii(i,r){this.ei=i,this.si=r,this.yt()}get cellWidth(){return this.ei}get cellHeight(){return this.si}get cols(){return this.Qs}get rows(){return this.Zs}get width(){return this.v}get height(){return this.C}get offsetX(){return this.Js}get offsetY(){return this.Ks}}class Z{constructor(i={}){u(this,"ti");u(this,"ri");u(this,"ni");i.canvas?(this.ti=i.canvas,this.ni=!1):(this.ti=this.oi(i.width,i.height),this.ni=!0),this.ti.style.imageRendering="pixelated"}oi(i,r){const s=document.createElement("canvas");return s.className="textmodeCanvas",s.style.imageRendering="pixelated",s.width=i||800,s.height=r||600,document.body.appendChild(s),s}L(i,r){this.ti.width=i??this.ti.width,this.ti.height=r??this.ti.height}ai(){const i=this.ti.getContext("webgl2",{alpha:!0,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"});if(!i)throw new C("`textmode.js` requires WebGL2 support.");return i}U(){this.ri&&this.ri.disconnect();const i=this.ti.getContext("webgl")||this.ti.getContext("webgl2");if(i){const r=i.getExtension("WEBGL_lose_context");r&&r.loseContext()}this.ni&&this.ti.parentNode&&this.ti.parentNode.removeChild(this.ti)}get canvas(){return this.ti}get width(){return this.ti.width}get height(){return this.ti.height}}class St{constructor(i=60){u(this,"hi");u(this,"ci");u(this,"li",null);u(this,"ui",0);u(this,"fi",!0);u(this,"di",0);u(this,"pi",0);u(this,"gi",[]);u(this,"_i",10);u(this,"mi",0);this.hi=i,this.ci=1e3/i}start(i){if(!this.fi)return;this.ui=performance.now();const r=s=>{if(!this.fi)return void(this.li=null);const n=s-this.ui;n>=this.ci&&(i(),this.ui=s-n%this.ci),this.fi&&(this.li=requestAnimationFrame(r))};this.li=requestAnimationFrame(r)}stop(){this.li&&(cancelAnimationFrame(this.li),this.li=null)}pause(){this.fi&&(this.fi=!1,this.stop())}resume(i){this.fi||(this.fi=!0,this.start(i))}frameRate(i,r){if(i===void 0)return this.di;this.hi=i,this.ci=1e3/i,this.fi&&r&&(this.stop(),this.start(r))}measureFrameRate(){const i=performance.now();if(this.pi>0){const r=i-this.pi;this.gi.push(r),this.gi.length>this._i&&this.gi.shift();const s=this.gi.reduce((n,o)=>n+o,0)/this.gi.length;this.di=1e3/s}this.pi=i}get isLooping(){return this.fi}get frameRateLimit(){return this.hi}get currentFrameRate(){return this.di}get frameCount(){return this.mi}set frameCount(i){this.mi=i}incrementFrame(){this.mi++}resetFrameCount(){this.mi=0}}const Ft=c=>class extends c{rotate(i){this.$s.state.bt(i)}push(){this.$s.state.xt()}pop(){this.$s.state.Ct()}rect(i,r,s=1,n=1){this.$s.De(i,r,s,n)}line(i,r,s,n){this.$s.Ie(i,r,s,n)}lineWeight(i){this.$s.state.$t(i)}background(i,r=i,s=i,n=255){this.$s.Ve(i,r,s,n)}char(i){this.$s.state.Tt(this.Gs.Ps(i))}charColor(i,r,s){this.$s.state.zt(i,r,s)}cellColor(i,r,s){this.$s.state.Mt(i,r,s)}flipHorizontally(i){this.$s.state.Rt(i)}flipVertically(i){this.$s.state.St(i)}charRotation(i){this.$s.state.Pt(i)}invert(i){this.$s.state.At(i)}clear(){this.$s.Ve(0,0,0,0)}ellipse(i,r,s,n){this.$s.Be(i,r,s/2,n/2)}triangle(i,r,s,n,o,a){this.$s.Le(i,r,s,n,o,a)}bezierCurve(i,r,s,n,o,a,h,l){this.$s.Ee(i,r,s,n,o,a,h,l)}arc(i,r,s,n,o,a){this.$s.ke(i,r,s,n,o,a)}};class N{xi(i){const r=i.W(0),s=i.W(1),n=i.W(2),o=i.W(3);return{characterPixels:r,primaryColorPixels:s,secondaryColorPixels:n,transformPixels:i.W(4),rotationPixels:o}}Ci(i,r){return i[r]+(i[r+1]<<8)}yi(i,r){return{r:i[r],g:i[r+1],b:i[r+2],a:i[r+3]}}}class k{wi(i,r){return new Blob([i],{type:r})}$i(i,r,s){try{const n=this.wi(i,s),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"))}}bi(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Ti(){const i=new Date;return{date:i.toISOString().split("T")[0],time:i.toTimeString().split(" ")[0].replace(/:/g,"-")}}zi(i){return i.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Mi(){return"'textmode-export'-"+this.bi()}}class Pt extends N{Ri(i,r,s){const n=i[s]===255,o=i[s+1]===255,a=i[s+2]===255,h=r[s],l=r[s+1];return{isInverted:n,flipHorizontal:o,flipVertical:a,rotation:Math.round(360*(h+l/255)/255*100)/100}}Si(i,r,s){return{x:i,y:r,cellX:i*s.cellWidth,cellY:r*s.cellHeight}}Ai(i,r){const s=[];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.Ci(i.characterPixels,h);let f=this.yi(i.primaryColorPixels,h),d=this.yi(i.secondaryColorPixels,h);const p=this.Ri(i.transformPixels,i.rotationPixels,h);if(p.isInverted){const x=f;f=d,d=x}const g=this.Si(a,o,r);s.push({charIndex:l,primaryColor:f,secondaryColor:d,transform:p,position:g}),n++}return s}}class Ut{Pi(i,r){const s=i.cmap;for(const n of s.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}Fi(i,r,s,n,o){const a=o/i.head.unitsPerEm;return{getBoundingBox:()=>({x1:s+r.xMin*a,y1:n+-r.yMax*a,x2:s+r.xMax*a,y2:n+-r.yMin*a}),toSVG:()=>this.Gi(r,s,n,a)}}Gi(i,r,s,n){if(!i||!i.xs)return"";const{xs:o,ys:a,endPts:h,flags:l}=i;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 x=r+o[d]*n,m=s-a[d]*n;f+=`M${x.toFixed(2)},${m.toFixed(2)}`;let y=d+1;for(;y<=g;)if(1&l[y]){const E=r+o[y]*n,b=s-a[y]*n;f+=`L${E.toFixed(2)},${b.toFixed(2)}`,y++}else{const E=r+o[y]*n,b=s-a[y]*n;let A=y+1>g?d:y+1;if(1&l[A]){const _=r+o[A]*n,L=s-a[A]*n;f+=`Q${E.toFixed(2)},${b.toFixed(2)} ${_.toFixed(2)},${L.toFixed(2)}`,y=A+1}else{const _=(E+(r+o[A]*n))/2,L=(b+(s-a[A]*n))/2;f+=`Q${E.toFixed(2)},${b.toFixed(2)} ${_.toFixed(2)},${L.toFixed(2)}`,y=A}}f+="Z"}d=g+1}}return f}Di(i,r,s,n,o){const a=i.codePointAt(0)||0,h=this.Pi(r,a);let l=null;return r.glyf&&r.glyf[h]!==null?l=r.glyf[h]:(l=M.T.glyf.je(r,h),r.glyf[h]=l),this.Fi(r,l,s,n,o)}Ii(i,r,s,n,o,a,h,l){const f=s+(o-l*(h/r.head.unitsPerEm))/2,d=n+(a+.7*h)/2;return this.Di(i,r,f,d,h).toSVG()||null}}class It{constructor(){u(this,"Bi");this.Bi=new Ut}Li(i){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
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="${
|
|
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>`}
|
|
14
|
+
<desc>textmode art visualization generated by textmode.js library</desc>`}sr(){return`
|
|
13
15
|
</g>
|
|
14
|
-
</svg>`}
|
|
15
|
-
<rect width="${
|
|
16
|
-
<rect x="${n.cellX}" y="${n.cellY}" width="${
|
|
17
|
-
<rect x="${n.cellX}" y="${n.cellY}" width="${
|
|
18
|
-
<path id="${`path-${
|
|
19
|
-
<path d="${a}" fill="${h}" />`}
|
|
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}
|
|
22
|
-
<g id="ascii-cells">`;for(const a of
|
|
23
|
-
`).replace(/[ \t]+$/gm,"")}}class
|
|
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 s.join(n)}}class
|
|
26
|
-
in vec2
|
|
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.wr=this.$s.Fe("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 s=new this(r);await s.Gs.Hs(r.fontSource);const n=s.Gs.maxGlyphDimensions;return s.vr=new q(s.ti.canvas,n.width,n.height),s.mr=s.$s.We(s.vr.cols,s.vr.rows,5),s.Mr(),s.Cr.start(()=>s.yr()),s}Mr(){this.zr=()=>{this.Tr()},window.addEventListener("resize",this.zr)}yr(){if(this.Cr.measureFrameRate(),this.Cr.incrementFrame(),this.$r)return;this.mr.V(),this.$s.Pe(this._r),this.br(),this.$s.Ue(this._r),this.mr.O();const r=this.$s.state.canvasBackgroundColor;this.$s.te(r[0],r[1],r[2],r[3]),this.$s.Pe(this.wr),this.wr.et({u_characterTexture:this.Gs.fontFramebuffer,u_charsetDimensions:[this.Gs.textureColumns,this.Gs.textureRows],u_asciiCharacterTexture:this.mr.textures[0],u_primaryColorTexture:this.mr.textures[1],u_secondaryColorTexture:this.mr.textures[2],u_transformTexture:this.mr.textures[4],u_rotationTexture:this.mr.textures[3],u_gridCellDimensions:[this.vr.cols,this.vr.rows],u_gridPixelDimensions:[this.vr.width,this.vr.height],u_gridOffsetPixels:[this.vr.offsetX,this.vr.offsetY],u_aspectRatio:this.vr.width/this.vr.height}),this.$s.Ge(this.vr.offsetX,this.vr.offsetY,this.vr.width,this.vr.height)}draw(r){this.br=r}windowResized(r){this.Tr=r}resizeCanvas(r,s){this.ti.L(r,s),this.vr.yt(),this.mr.L(this.vr.cols,this.vr.rows),this.$s.Oe(),this.yr()}destroy(){this.$r||(this.Cr.stop(),window.removeEventListener("resize",this.zr),this.Gs.U(),this.$s.U(),this.$r=!0)}get grid(){return this.vr}get font(){return this.Gs}get width(){return this.ti.width}get height(){return this.ti.height}get canvas(){return this.ti.canvas}get isDisposed(){return this.$r}get drawFramebuffer(){return this.mr}}class W{constructor(){throw new C("Textmode is a static class and cannot be instantiated.")}static async create(i){return tt.create(i)}static setErrorLevel(i){D.m(i)}static get version(){return"0.2.0-beta.2"}}const Yt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),Ht=W.create,qt=W.setErrorLevel,Zt=W.version;w.TextmodeCanvas=Z,w.TextmodeErrorLevel=F,w.TextmodeFont=H,w.TextmodeGrid=q,w.Textmodifier=tt,w.create=Ht,w.export=Yt,w.setErrorLevel=qt,w.textmode=W,w.version=Zt,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):e((t=typeof globalThis<"u"?globalThis:t||self).textmode={});
|
|
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
|
|
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(
|
|
24
|
+
$generateSVG(renderingData: TextmodeRenderingData, options?: SVGExportOptions): string;
|
|
25
25
|
/**
|
|
26
26
|
* Exports SVG content to a downloadable file
|
|
27
|
-
* @param
|
|
27
|
+
* @param renderingData The textmode rendering data containing pipeline, grid, and font
|
|
28
28
|
* @param options Export options including filename
|
|
29
29
|
*/
|
|
30
|
-
$saveSVG(
|
|
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
|
-
|
|
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 =
|
|
30
|
-
static readonly FLOATS_PER_INSTANCE =
|
|
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 =
|
|
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
|
-
|
|
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
|
|
22
|
+
private _currentRotationX;
|
|
23
|
+
private _currentRotationY;
|
|
24
|
+
private _currentRotationZ;
|
|
21
25
|
private _currentCharacter;
|
|
22
26
|
private _currentCharColor;
|
|
23
27
|
private _currentCellColor;
|
|
@@ -47,7 +51,9 @@ export declare class RenderState {
|
|
|
47
51
|
*/
|
|
48
52
|
$writeSnapshotTo(target: {
|
|
49
53
|
lineWeight: number;
|
|
50
|
-
|
|
54
|
+
rotationX: number;
|
|
55
|
+
rotationY: number;
|
|
56
|
+
rotationZ: number;
|
|
51
57
|
character: number[];
|
|
52
58
|
charColor: number[];
|
|
53
59
|
bgColor: number[];
|
|
@@ -59,7 +65,9 @@ export declare class RenderState {
|
|
|
59
65
|
get lineWeight(): number;
|
|
60
66
|
get canvasBackgroundColor(): [number, number, number, number];
|
|
61
67
|
$setLineWeight(weight: number): void;
|
|
62
|
-
$
|
|
68
|
+
$setRotationX(degrees: number): void;
|
|
69
|
+
$setRotationY(degrees: number): void;
|
|
70
|
+
$setRotationZ(degrees: number): void;
|
|
63
71
|
$setCharacter(character: [number, number, number]): void;
|
|
64
72
|
$setCharColor(r: number, g?: number, b?: number, a?: number): void;
|
|
65
73
|
$setCellColor(r: number, g?: number, b?: number, a?: number): void;
|
|
@@ -8,7 +8,8 @@ import { RenderState } from "./RenderState";
|
|
|
8
8
|
export declare class GLRenderer {
|
|
9
9
|
private _gl;
|
|
10
10
|
private _currentShader;
|
|
11
|
-
private
|
|
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 {};
|
|
@@ -37,10 +37,12 @@ export declare abstract class BaseGeometry implements IGeometry {
|
|
|
37
37
|
ny: number;
|
|
38
38
|
};
|
|
39
39
|
protected _setRotationCenter(instanceData: InstanceData, centerX: number, centerY: number): void;
|
|
40
|
-
protected _calculateRotationParams(x: number, y: number, width: number, height: number,
|
|
40
|
+
protected _calculateRotationParams(x: number, y: number, width: number, height: number, rotationXDegrees: number, rotationYDegrees: number, rotationZDegrees: number): {
|
|
41
41
|
centerX: number;
|
|
42
42
|
centerY: number;
|
|
43
|
-
|
|
43
|
+
radiansX: number;
|
|
44
|
+
radiansY: number;
|
|
45
|
+
radiansZ: number;
|
|
44
46
|
aspectRatio: number;
|
|
45
47
|
};
|
|
46
48
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|