textmode.js 0.1.8-beta.2 → 0.1.8
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 +1144 -953
- package/dist/textmode.esm.min.js +1108 -917
- package/dist/textmode.umd.js +19 -19
- package/dist/textmode.umd.min.js +17 -17
- package/dist/types/Textmode.d.ts +21 -31
- package/dist/types/export/image/types.d.ts +1 -1
- package/dist/types/export/svg/SVGPathGenerator.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/textmode/Canvas.d.ts +3 -3
- package/dist/types/textmode/ConversionPipeline.d.ts +7 -2
- package/dist/types/textmode/Textmodifier.d.ts +29 -20
- package/dist/types/textmode/converters/Converter.d.ts +4 -4
- package/dist/types/textmode/converters/FeatureConverter.d.ts +3 -3
- package/dist/types/textmode/font/CharacterColorMapper.d.ts +4 -9
- package/dist/types/textmode/font/CharacterExtractor.d.ts +15 -25
- package/dist/types/textmode/font/MetricsCalculator.d.ts +34 -9
- package/dist/types/textmode/font/TextmodeFont.d.ts +3 -2
- package/dist/types/textmode/font/TextureAtlas.d.ts +29 -13
- package/dist/types/textmode/font/index.d.ts +3 -1
- package/dist/types/textmode/font/types.d.ts +2 -136
- package/dist/types/textmode/font/typr/Typr.d.ts +18 -0
- package/dist/types/textmode/font/typr/types.d.ts +254 -0
- package/dist/types/textmode/font/utils/CmapParser.d.ts +47 -0
- package/dist/types/textmode/font/utils/FontConstants.d.ts +60 -0
- package/dist/types/textmode/font/utils/FontTableReader.d.ts +56 -0
- package/dist/types/textmode/font/utils/index.d.ts +9 -0
- package/dist/types/textmode/mixins/ConversionMixin.d.ts +3 -4
- package/dist/types/textmode/mixins/ExportMixin.d.ts +2 -14
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +1 -0
- package/package.json +1 -1
package/dist/textmode.umd.min.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Wt=Object.defineProperty;var Nt=(w,b,U)=>b in w?Wt(w,b,{enumerable:!0,configurable:!0,writable:!0,value:U}):w[b]=U;var c=(w,b,U)=>Nt(w,typeof b!="symbol"?b+"":b,U);var t,e;t=this,e=function(w){class b extends Error{constructor(r,s={}){super(b.i(r,s)),this.name="TextmodeError"}static i(r,s){let i=r;if(s&&Object.keys(s).length>0){i+=`
|
|
2
2
|
|
|
3
|
-
📋 Context:`;for(const[o
|
|
4
|
-
- ${
|
|
3
|
+
📋 Context:`;for(const[n,o]of Object.entries(s))i+=`
|
|
4
|
+
- ${n}: ${b.o(o)}`}return i+=`
|
|
5
5
|
|
|
6
6
|
`,i+="↓".repeat(24)+`
|
|
7
|
-
`,i}static o(r){if(r===null)return"null";if(r===void 0)return"undefined";if(typeof r=="string")return`"${r}"`;if(typeof r=="number"||typeof r=="boolean")return r+"";if(Array.isArray(r))return r.length===0?"[]":r.length<=5?`[${r.map(s=>x.o(s)).join(", ")}]`:`[${r.slice(0,3).map(s=>x.o(s)).join(", ")}, ... +${r.length-3} more]`;if(typeof r=="object"){const s=Object.keys(r);return s.length===0?"{}":s.length<=3?`{ ${s.map(i=>`${i}: ${x.o(r[i])}`).join(", ")} }`:`{ ${s.slice(0,2).map(i=>`${i}: ${x.o(r[i])}`).join(", ")}, ... +${s.length-2} more }`}return r+""}}var R=(l=>(l[l.SILENT=0]="SILENT",l[l.WARNING=1]="WARNING",l[l.ERROR=2]="ERROR",l[l.THROW=3]="THROW",l))(R||{});const M=class M{constructor(){c(this,"l",{globalLevel:3})}static u(){return M.h||(M.h=new M),M.h}m(r,s){const i="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",o="color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";switch(this.l.globalLevel){case 0:return!1;case 1:return console.group(i,o),console.warn(x.i(r,s)),console.groupEnd(),!1;case 2:return console.group(i,o),console.error(x.i(r,s)),console.groupEnd(),!1;default:throw new x(r,s)}}p(r,s,i){return!!r||(this.m(s,i),!1)}_(r){this.l.globalLevel=r}};c(M,"h",null);let O=M;const _=O.u(),X=new WeakMap;function B(l,r){X.set(l,r)}function W(l){return X.get(l)}class H{constructor(r,s,i=s,o={}){c(this,"v");c(this,"C");c(this,"$");c(this,"F");c(this,"D");c(this,"l");c(this,"M",null);c(this,"S",null);this.v=r,this.F=s,this.D=i,this.l={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.$=this.R(),this.C=r.createFramebuffer(),this.V()}k(r){const{v:s}=this,i=s.getParameter(s.FRAMEBUFFER_BINDING);s.bindFramebuffer(s.FRAMEBUFFER,this.C);try{return r()}finally{s.bindFramebuffer(s.FRAMEBUFFER,i)}}R(){const{v:r}=this,s=r.createTexture();r.bindTexture(r.TEXTURE_2D,s);const i=this.l.filter==="linear"?r.LINEAR:r.NEAREST,o=this.l.wrap==="repeat"?r.REPEAT:r.CLAMP_TO_EDGE;return 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,o),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,o),this.I(),s}I(){const{v:r}=this,s=this.l.type==="float"?r.FLOAT:r.UNSIGNED_BYTE;r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.F,this.D,0,r.RGBA,s,null)}V(){const{v:r}=this;r.bindFramebuffer(r.FRAMEBUFFER,this.C),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,this.$,0),r.bindFramebuffer(r.FRAMEBUFFER,null)}update(r){const{v:s}=this;s.bindTexture(s.TEXTURE_2D,this.$),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,1),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,r),s.bindTexture(s.TEXTURE_2D,null)}updatePixels(r,s,i){const{v:o}=this;o.bindTexture(o.TEXTURE_2D,this.$),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,s,i,0,o.RGBA,o.UNSIGNED_BYTE,r),o.bindTexture(o.TEXTURE_2D,null)}resize(r,s){const{v:i}=this;this.F=r,this.D=s,this.S=null,i.bindTexture(i.TEXTURE_2D,this.$),this.I(),i.bindTexture(i.TEXTURE_2D,null)}begin(){const{v:r}=this;this.M={framebuffer:r.getParameter(r.FRAMEBUFFER_BINDING),viewport:r.getParameter(r.VIEWPORT)},r.bindFramebuffer(r.FRAMEBUFFER,this.C),r.viewport(0,0,this.F,this.D),B(r,[0,0,this.F,this.D])}end(){if(!this.M)return;const{v:r}=this;r.bindFramebuffer(r.FRAMEBUFFER,this.M.framebuffer),r.viewport(...this.M.viewport),B(r,this.M.viewport),this.M=null}loadPixels(){const{v:r}=this;this.S||(this.S=new Uint8Array(this.F*this.D*4)),this.k(()=>{r.readPixels(0,0,this.F,this.D,r.RGBA,r.UNSIGNED_BYTE,this.S)})}get(r,s,i,o){const{v:n}=this;if(r===void 0&&s===void 0){const a=new Uint8Array(this.F*this.D*4);return this.k(()=>(n.readPixels(0,0,this.F,this.D,n.RGBA,n.UNSIGNED_BYTE,a),a))}if(i===void 0&&o===void 0){(r<0||s<0||r>=this.F||s>=this.D)&&(console.warn("The x and y values passed to Framebuffer.get are outside of its range and will be clamped."),r=Math.max(0,Math.min(r,this.F-1)),s=Math.max(0,Math.min(s,this.D-1)));const a=new Uint8Array(4);return this.k(()=>(n.readPixels(r,s,1,1,n.RGBA,n.UNSIGNED_BYTE,a),[a[0],a[1],a[2],a[3]]))}{r=Math.max(0,Math.min(r,this.F-1)),s=Math.max(0,Math.min(s,this.D-1)),i=Math.max(1,Math.min(i,this.F-r)),o=Math.max(1,Math.min(o,this.D-s));const a=new Uint8Array(i*o*4);return this.k(()=>(n.readPixels(r,s,i,o,n.RGBA,n.UNSIGNED_BYTE,a),a))}}P(){this.C&&this.v.deleteFramebuffer(this.C),this.$&&this.v.deleteTexture(this.$)}get framebuffer(){return this.C}get texture(){return this.$}get width(){return this.F}get height(){return this.D}get pixels(){return this.S}}class P{constructor(r,s,i){c(this,"v");c(this,"U");c(this,"A",new Map);c(this,"G",new Map);c(this,"L",0);c(this,"O");this.v=r,this.U=this.H(s,i),this.O=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),this.j()}j(){const r=this.v.getProgramParameter(this.U,this.v.ACTIVE_UNIFORMS);for(let s=0;s<r;s++){const i=this.v.getActiveUniform(this.U,s);if(i){const o=this.v.getUniformLocation(this.U,i.name);o&&(this.A.set(i.name,o),this.G.set(i.name,i.type))}}}H(r,s){const i=this.W(this.v.VERTEX_SHADER,r),o=this.W(this.v.FRAGMENT_SHADER,s),n=this.v.createProgram();if(this.v.attachShader(n,i),this.v.attachShader(n,o),this.v.linkProgram(n),!this.v.getProgramParameter(n,this.v.LINK_STATUS)){const a=this.v.getProgramInfoLog(n);throw Error("Shader program link error: "+a)}return this.v.deleteShader(i),this.v.deleteShader(o),n}W(r,s){const i=this.v.createShader(r);if(this.v.shaderSource(i,s),this.v.compileShader(i),!this.v.getShaderParameter(i,this.v.COMPILE_STATUS)){const o=this.v.getShaderInfoLog(i);throw this.v.deleteShader(i),Error("Shader compilation error: "+o)}return i}N(){this.v.useProgram(this.U),this.X()}setUniform(r,s){const i=this.A.get(r);if(i)if(typeof s=="number")this.q(r)?this.v.uniform1i(i,Math.floor(s)):this.v.uniform1f(i,s);else if(typeof s=="boolean")this.v.uniform1i(i,s?1:0);else if(Array.isArray(s))switch(s.length){case 2:this.v.uniform2f(i,s[0],s[1]);break;case 3:this.v.uniform3f(i,s[0],s[1],s[2]);break;case 4:this.v.uniform4f(i,s[0],s[1],s[2],s[3]);break;default:console.warn(`Unsupported array length ${s.length} for uniform '${r}'`)}else if(s instanceof WebGLTexture){const o=this.Y();this.v.uniform1i(i,o),this.v.activeTexture(this.v.TEXTURE0+o),this.v.bindTexture(this.v.TEXTURE_2D,s)}else if(s instanceof H){const o=this.Y();this.v.uniform1i(i,o),this.v.activeTexture(this.v.TEXTURE0+o),this.v.bindTexture(this.v.TEXTURE_2D,s.texture)}else console.warn(`Unsupported uniform type for '${r}':`,typeof s)}Y(){return this.L>=this.O&&console.warn(`Exceeded maximum texture units (${this.O}). Texture may not render correctly.`),this.L++}q(r){const s=this.G.get(r);return!!s&&(s===this.v.INT||s===this.v.INT_VEC2||s===this.v.INT_VEC3||s===this.v.INT_VEC4||s===this.v.SAMPLER_2D||s===this.v.SAMPLER_CUBE)}get glProgram(){return this.U}P(){this.v.deleteProgram(this.U)}X(){this.L=0}}class q{constructor(r){c(this,"v");c(this,"Z",null);c(this,"J",16);c(this,"K",new Map);this.v=r}tt(){if(this.Z)return;const r=this.v;this.Z=r.createBuffer(),r.bindBuffer(r.ARRAY_BUFFER,this.Z)}et(){const r=this.v,s=r.getParameter(r.CURRENT_PROGRAM);let i=this.K.get(s);return i||(i={a_position:r.getAttribLocation(s,"a_position"),a_texCoord:r.getAttribLocation(s,"a_texCoord")},this.K.set(s,i)),r.enableVertexAttribArray(i.a_position),r.vertexAttribPointer(i.a_position,2,r.FLOAT,!1,this.J,0),r.enableVertexAttribArray(i.a_texCoord),r.vertexAttribPointer(i.a_texCoord,2,r.FLOAT,!1,this.J,8),{positionLoc:i.a_position,texLoc:i.a_texCoord}}rt(r,s){const i=this.v;i.disableVertexAttribArray(r),i.disableVertexAttribArray(s)}st(r,s){const i=this.v,o=W(i)||[0,0,i.canvas.width,i.canvas.height];return{nx:r/o[2]*2-1,ny:1-s/o[3]*2}}it(r,s,i,o){const n=this.v;this.tt(),n.bindBuffer(n.ARRAY_BUFFER,this.Z);const a=new Float32Array([r,o,0,0,i,o,1,0,r,s,0,1,r,s,0,1,i,o,1,0,i,s,1,1]);n.bufferData(n.ARRAY_BUFFER,a,n.DYNAMIC_DRAW)}P(){this.Z&&this.v.deleteBuffer(this.Z)}}class ot extends q{constructor(r){super(r)}ot(r,s,i,o){const n=this.st(r,s),a=this.st(r+i,s+o);this.it(n.nx,n.ny,a.nx,a.ny);const h=this.et();this.v.drawArrays(this.v.TRIANGLES,0,6),this.rt(h.positionLoc,h.texLoc)}nt(r,s,i,o,n){this.ot(r,s,i,n),this.ot(r+i-n,s,n,o),this.ot(r,s+o-n,i,n),this.ot(r,s,n,o)}}class nt extends q{constructor(r){super(r)}ht(r,s,i,o,n){const a=i-r,h=o-s,u=Math.hypot(a,h);if(u===0){const f=n/2,g=this.st(r-f,s-f),p=this.st(r+f,s+f);this.it(g.nx,g.ny,p.nx,p.ny)}else{const f=-h/u,g=a/u,p=n/2,b=r+f*p,w=s+g*p,v=r-f*p,y=s-g*p,E=i+f*p,T=o+g*p,F=i-f*p,A=o-g*p,L=this.st(b,w),D=this.st(v,y),U=this.st(E,T),it=this.st(F,A),I=this.v;this.tt(),I.bindBuffer(I.ARRAY_BUFFER,this.Z);const It=new Float32Array([L.nx,L.ny,0,0,D.nx,D.ny,0,1,U.nx,U.ny,1,0,D.nx,D.ny,0,1,it.nx,it.ny,1,1,U.nx,U.ny,1,0]);I.bufferData(I.ARRAY_BUFFER,It,I.DYNAMIC_DRAW)}const d=this.et();this.v.drawArrays(this.v.TRIANGLES,0,6),this.rt(d.positionLoc,d.texLoc)}}var k="attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;uniform float u_rotation;uniform vec2 u_center;uniform float u_aspectRatio;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){v_uv=a_texCoord;vec2 pos=a_position;pos-=u_center;pos.x*=u_aspectRatio;pos=rotate2D(-u_rotation)*pos;pos.x/=u_aspectRatio;pos+=u_center;gl_Position=vec4(pos,0.0,1.0);}";class at{constructor(r){c(this,"v");c(this,"lt");c(this,"ct");c(this,"ut",null);c(this,"ft");c(this,"dt");c(this,"gt",[1,1,1,1]);c(this,"_t",!0);c(this,"vt",[0,0,0,1]);c(this,"xt",1);c(this,"bt",!0);c(this,"wt",0);c(this,"Ct",[]);this.v=r,this.lt=new P(this.v,k,"precision lowp float;uniform sampler2D u_texture;varying vec2 v_uv;void main(){gl_FragColor=texture2D(u_texture,v_uv);}"),this.ct=new P(this.v,k,"precision lowp float;uniform vec4 u_color;void main(){gl_FragColor=u_color;}"),this.ft=new ot(this.v),this.dt=new nt(this.v),this.v.enable(this.v.BLEND),this.v.blendEquation(this.v.FUNC_ADD),this.v.blendFunc(this.v.ONE,this.v.ONE_MINUS_SRC_ALPHA),B(this.v,[0,0,this.v.canvas.width,this.v.canvas.height])}yt(r){this.ut!==r&&(this.ut=r,r.N())}$t(r,s,i,o){if(this._t=!0,s===void 0&&i===void 0&&o===void 0){const n=r/255;this.gt=[n,n,n,1]}else if(i!==void 0&&o===void 0)this.gt=[r/255,s/255,i/255,1];else{if(i===void 0||o===void 0)throw Error("Invalid fill parameters. Use fill(gray), fill(r,g,b), or fill(r,g,b,a)");this.gt=[r/255,s/255,i/255,o/255]}}Ft(r,s,i,o){if(this.bt=!0,s===void 0&&i===void 0&&o===void 0){const n=r/255;this.vt=[n,n,n,1]}else if(i!==void 0&&o===void 0)this.vt=[r/255,s/255,i/255,1];else{if(i===void 0||o===void 0)throw Error("Invalid stroke parameters. Use stroke(gray), stroke(r,g,b), or stroke(r,g,b,a)");this.vt=[r/255,s/255,i/255,o/255]}}Tt(r){if(r<0)throw Error("Stroke weight must be non-negative");this.xt=r}Dt(){this.bt=!1}Mt(){this._t=!1}St(r){this.wt=r}Rt(){this.Ct.push({fillColor:[...this.gt],fillMode:this._t,strokeColor:[...this.vt],strokeWeight:this.xt,strokeMode:this.bt,rotation:this.wt})}Vt(){const r=this.Ct.pop();r?(this.gt=r.fillColor,this._t=r.fillMode,this.vt=r.strokeColor,this.xt=r.strokeWeight,this.bt=r.strokeMode,this.wt=r.rotation):console.warn("pop() called without matching push()")}kt(){this.ut=null,this.Ct=[],this.wt=0}zt(r,s){return new P(this.v,r,s)}It(r){return new P(this.v,k,r)}Pt(r,s){this.ut.setUniform(r,s)}Ut(r,s,i,o){if(this.ut!==null){const{centerX:g,centerY:p,radians:b,aspectRatio:w}=this.At(r,s,i,o);return this.Pt("u_rotation",b),this.Pt("u_center",[g,p]),this.Pt("u_aspectRatio",w),this.ft.ot(r,s,i,o),void(this.ut=null)}const n=this.ct;let a=0,h=0,u=0,d=1;const f=this.At(r,s,i,o);a=f.centerX,h=f.centerY,u=f.radians,d=f.aspectRatio,this._t&&(this.yt(n),this.Pt("u_color",this.gt),this.Pt("u_rotation",u),this.Pt("u_center",[a,h]),this.Pt("u_aspectRatio",d),this.ft.ot(r,s,i,o)),this.bt&&this.xt>0&&(this.yt(n),this.Pt("u_color",this.vt),this.Pt("u_rotation",u),this.Pt("u_center",[a,h]),this.Pt("u_aspectRatio",d),this.ft.nt(r,s,i,o,this.xt)),this.ut=null}Gt(r,s,i,o){if(this.ut!==null){const v=(r+i)/2,y=(s+o)/2,E=Math.abs(i-r)||1,T=Math.abs(o-s)||1,{centerX:F,centerY:A,radians:L,aspectRatio:D}=this.At(v-E/2,y-T/2,E,T);this.Pt("u_rotation",L),this.Pt("u_center",[F,A]),this.Pt("u_aspectRatio",D);const U=this.xt>0?this.xt:1;return this.dt.ht(r,s,i,o,U),void(this.ut=null)}if(!this.bt||this.xt<=0)return;const n=this.ct,a=(r+i)/2,h=(s+o)/2,u=Math.abs(i-r)||1,d=Math.abs(o-s)||1,f=this.wt!==0;let g=0,p=0,b=0,w=1;if(f){const v=this.At(a-u/2,h-d/2,u,d);g=v.centerX,p=v.centerY,b=v.radians,w=v.aspectRatio}this.yt(n),this.Pt("u_color",this.vt),f&&(this.Pt("u_rotation",b),this.Pt("u_center",[g,p]),this.Pt("u_aspectRatio",w)),this.dt.ht(r,s,i,o,this.xt)}At(r,s,i,o){const n=W(this.v)||[0,0,this.v.canvas.width,this.v.canvas.height],a=n[2],h=n[3],u=a/h;return{centerX:(r+i/2)/a*2-1,centerY:1-(s+o/2)/h*2,radians:this.wt*Math.PI/180,aspectRatio:u}}Et(r,s,i={}){return new H(this.v,r,s,i)}Lt(r,s=r,i=r,o=255){this.Ot(r/255,s/255,i/255,o/255)}Ot(r=0,s=0,i=0,o=0){this.v.clearColor(r,s,i,o),this.v.clear(this.v.COLOR_BUFFER_BIT)}Bt(){this.v.viewport(0,0,this.v.canvas.width,this.v.canvas.height),B(this.v,[0,0,this.v.canvas.width,this.v.canvas.height])}get context(){return this.v}P(){this.lt.P(),this.ct.P(),this.ft.P(),this.dt.P()}Ht(r,s,i,o,n){const a=this.v,h=o??r.width,u=n??r.height;this.yt(this.lt),this.Pt("u_texture",r.texture);const d=this.At(s,i,h,u);this.Pt("u_rotation",d.radians),this.Pt("u_center",[d.centerX,d.centerY]),this.Pt("u_aspectRatio",d.aspectRatio),this.ft.ot(s,i,h,u),a.bindTexture(a.TEXTURE_2D,null),this.ut=null}}var S,m={parse:function(l){var r=function(s,i,o,n){var a=m.T,h={cmap:a.cmap,head:a.head,hhea:a.hhea,maxp:a.maxp,hmtx:a.hmtx,loca:a.loca,glyf:a.glyf},u={_data:s,_index:i,_offset:o};for(var d in h){var f=m.findTable(s,d,o);if(f){var g=f[0],p=n[g];p==null&&(p=h[d].parseTab(s,g,f[1],u)),u[d]=n[g]=p}}return u}(new Uint8Array(l),0,0,{});return[r]},findTable:function(l,r,s){for(var i=m.B,o=i.readUshort(l,s+4),n=s+12,a=0;a<o;a++){var h=i.readASCII(l,n,4);i.readUint(l,n+4);var u=i.readUint(l,n+8),d=i.readUint(l,n+12);if(h==r)return[u,d];n+=16}return null},T:{}};m.B={readShort:function(l,r){return m.B.t.uint16[0]=l[r]<<8|l[r+1],m.B.t.int16[0]},readUshort:function(l,r){return l[r]<<8|l[r+1]},readUshorts:function(l,r,s){for(var i=[],o=0;o<s;o++)i.push(m.B.readUshort(l,r+2*o));return i},readUint:function(l,r){var s=m.B.t.uint8;return s[3]=l[r],s[2]=l[r+1],s[1]=l[r+2],s[0]=l[r+3],m.B.t.uint32[0]},readASCII:function(l,r,s){for(var i="",o=0;o<s;o++)i+=String.fromCharCode(l[r+o]);return i},t:(S=new ArrayBuffer(8),{uint8:new Uint8Array(S),int16:new Int16Array(S),uint16:new Uint16Array(S),uint32:new Uint32Array(S)})},m.T.cmap={parseTab:function(l,r,s){var i={tables:[],ids:{},off:r};l=new Uint8Array(l.buffer,r,s),r=0;var o=m.B,n=o.readUshort,a=m.T.cmap;n(l,r);var h=n(l,r+=2);r+=2;for(var u=[],d=0;d<h;d++){var f=n(l,r),g=n(l,r+=2);r+=2;var p=o.readUint(l,r);r+=4;var b="p"+f+"e"+g,w=u.indexOf(p);if(w==-1){w=i.tables.length;var v={};u.push(p);var y=v.format=n(l,p);y==4?v=a.parse4(l,p,v):y==12&&(v=a.parse12(l,p,v)),i.tables.push(v)}i.ids[b]!=null&&console.log("multiple tables for one platform+encoding: "+b),i.ids[b]=w}return i},parse4:function(l,r,s){var i=m.B,o=i.readUshort,n=i.readUshorts,a=r,h=o(l,r+=2);o(l,r+=2);var u=o(l,r+=2);r+=2;var d=u>>>1;s.searchRange=o(l,r),r+=2,s.entrySelector=o(l,r),r+=2,s.rangeShift=o(l,r),r+=2,s.endCount=n(l,r,d),r+=2*d,r+=2,s.startCount=n(l,r,d),r+=2*d,s.idDelta=[];for(var f=0;f<d;f++)s.idDelta.push(i.readShort(l,r)),r+=2;return s.idRangeOffset=n(l,r,d),r+=2*d,s.glyphIdArray=n(l,r,a+h-r>>1),s},parse12:function(l,r,s){var i=m.B.readUint;i(l,r+=4),i(l,r+=4);var o=3*i(l,r+=4);r+=4;for(var n=s.groups=new Uint32Array(o),a=0;a<o;a+=3)n[a]=i(l,r+(a<<2)),n[a+1]=i(l,r+(a<<2)+4),n[a+2]=i(l,r+(a<<2)+8);return s}},m.T.head={parseTab:function(l,r,s){var i=m.B,o={};return r+=18,o.unitsPerEm=i.readUshort(l,r),r+=2,r+=16,o.xMin=i.readShort(l,r),r+=2,o.yMin=i.readShort(l,r),r+=2,o.xMax=i.readShort(l,r),r+=2,o.yMax=i.readShort(l,r),r+=2,r+=6,o.indexToLocFormat=i.readShort(l,r),o}},m.T.hhea={parseTab:function(l,r,s){var i=m.B,o={};r+=4;for(var n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],a=0;a<n.length;a++){var h=n[a],u=h=="advanceWidthMax"||h=="numberOfHMetrics"?i.readUshort:i.readShort;o[h]=u(l,r+2*a)}return o}},m.T.hmtx={parseTab:function(l,r,s,i){for(var o=m.B,n=[],a=[],h=i.maxp.numGlyphs,u=i.hhea.numberOfHMetrics,d=0,f=0,g=0;g<u;)d=o.readUshort(l,r+(g<<2)),f=o.readShort(l,r+(g<<2)+2),n.push(d),a.push(f),g++;for(;g<h;)n.push(d),a.push(f),g++;return{aWidth:n,lsBearing:a}}},m.T.maxp={parseTab:function(l,r,s){var i=m.B,o=i.readUshort,n={};return i.readUint(l,r),r+=4,n.numGlyphs=o(l,r),r+=2,n}},m.T.loca={parseTab:function(l,r,s,i){var o=m.B,n=[],a=i.head.indexToLocFormat,h=i.maxp.numGlyphs+1;if(a==0)for(var u=0;u<h;u++)n.push(o.readUshort(l,r+(u<<1))<<1);if(a==1)for(u=0;u<h;u++)n.push(o.readUint(l,r+(u<<2)));return n}},m.T.glyf={parseTab:function(l,r,s,i){for(var o=[],n=i.maxp.numGlyphs,a=0;a<n;a++)o.push(null);return o},jt:function(l,r){var s=m.B,i=l._data,o=l.loca;if(o[r]==o[r+1])return null;var n=m.findTable(i,"glyf",l._offset)[0]+o[r],a={};if(a.noc=s.readShort(i,n),n+=2,a.xMin=s.readShort(i,n),n+=2,a.yMin=s.readShort(i,n),n+=2,a.xMax=s.readShort(i,n),n+=2,a.yMax=s.readShort(i,n),n+=2,a.xMin>=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(var h=0;h<a.noc;h++)a.endPts.push(s.readUshort(i,n)),n+=2;var u=s.readUshort(i,n);if(n+=2,i.length-n<u)return null;n+=u;var d=a.endPts[a.noc-1]+1;for(a.flags=[],h=0;h<d;h++){var f=i[n];if(n++,a.flags.push(f),8&f){var g=i[n];n++;for(var p=0;p<g;p++)a.flags.push(f),h++}}for(a.xs=[],h=0;h<d;h++){var b=!!(2&a.flags[h]),w=!!(16&a.flags[h]);b?(a.xs.push(w?i[n]:-i[n]),n++):w?a.xs.push(0):(a.xs.push(s.readShort(i,n)),n+=2)}for(a.ys=[],h=0;h<d;h++)b=!!(4&a.flags[h]),w=!!(32&a.flags[h]),b?(a.ys.push(w?i[n]:-i[n]),n++):w?a.ys.push(0):(a.ys.push(s.readShort(i,n)),n+=2);var v=0,y=0;for(h=0;h<d;h++)v+=a.xs[h],y+=a.ys[h],a.xs[h]=v,a.ys[h]=y}else a.parts=[];return a}},typeof module<"u"&&module.exports?module.exports=m:typeof window<"u"&&(window.Typr=m);class ht{extractCharacters(r){var i;const s=[];return(i=r==null?void 0:r.cmap)!=null&&i.tables?(r.cmap.tables.forEach(o=>{if(o.format===4){const n=this.Wt(o);s.push(...n)}else if(o.format===12){const n=this.Nt(o);s.push(...n)}}),[...new Set(s)]):[]}Wt(r){const s=[];if(!(r.startCount&&r.endCount&&r.idRangeOffset&&r.idDelta))return s;for(let i=0;i<r.startCount.length;i++){const o=r.startCount[i],n=r.endCount[i];if(o!==65535||n!==65535){for(let a=o;a<=n;a++)if(this.Xt(r,a,i)>0){const h=String.fromCodePoint(a);s.push(h)}}}return s}Nt(r){const s=[];if(!r.groups)return s;for(let i=0;i<r.groups.length;i+=3){const o=r.groups[i],n=r.groups[i+1],a=r.groups[i+2];for(let h=o;h<=n;h++)if(a+(h-o)>0){const u=String.fromCodePoint(h);s.push(u)}}return s}Xt(r,s,i){if(r.idRangeOffset[i]===0)return s+r.idDelta[i]&65535;{const o=r.idRangeOffset[i]/2+(s-r.startCount[i])-(r.startCount.length-i);if(o>=0&&r.glyphIdArray&&o<r.glyphIdArray.length){const n=r.glyphIdArray[o];if(n!==0)return n+r.idDelta[i]&65535}}return 0}filterProblematicCharacters(r){return r.filter(s=>this.qt(s))}qt(r){const s=r.codePointAt(0)||0;return!(s>=0&&s<=31&&s!==9&&s!==10&&s!==13||s>=127&&s<=159)}}class lt{constructor(r){c(this,"Yt");c(this,"Qt");c(this,"Zt");this.Zt=r,this.Yt=document.createElement("canvas"),this.Qt=this.Yt.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(r,s,i,o){const n=r.length,a=Math.ceil(Math.sqrt(n)),h=Math.ceil(n/a),u=s.width*a,d=s.height*h;this.Jt(u,d,i,o),this.Kt(r,s,a,i),this.te();const f=this.Zt.Et(u,d,{filter:"nearest"});return f.update(this.Yt),{framebuffer:f,columns:a,rows:h}}Jt(r,s,i,o){this.Yt.width=r,this.Yt.height=s,this.Yt.style.width=r+"px",this.Yt.style.height=r+"px",this.Qt.imageSmoothingEnabled=!1,this.Yt.style.imageRendering="pixelated",this.Qt.fillStyle="black",this.Qt.fillRect(0,0,r,s),this.Qt.font=`${i}px ${o}`,this.Qt.textBaseline="top",this.Qt.textAlign="left",this.Qt.fillStyle="white"}Kt(r,s,i,o){for(let n=0;n<r.length;n++){const a=n%i,h=Math.floor(n/i),u=a*s.width+.5*s.width,d=h*s.height+.5*s.height,f=Math.round(u-.5*s.width),g=Math.round(d-.5*o);this.Qt.fillText(r[n].character,f,g)}}te(r=128){const s=this.Qt.getImageData(0,0,this.Yt.width,this.Yt.height),i=s.data;for(let o=0;o<i.length;o+=4){const n=.299*i[o]+.587*i[o+1]+.114*i[o+2]>r+32?255:0;i[o]=n,i[o+1]=n,i[o+2]=n}this.Qt.putImageData(s,0,0)}}class ct{constructor(){c(this,"ee");c(this,"re");this.ee=document.createElement("canvas"),this.re=this.ee.getContext("2d")}calculateMaxGlyphDimensions(r,s,i){this.re.font=`${s}px ${i}`;let o=0,n=0;for(const a of r){const h=this.re.measureText(a);o=Math.max(o,h.width),n=Math.max(n,h.actualBoundingBoxAscent+h.actualBoundingBoxDescent)}return{width:o,height:n}}}class ut{createCharacterObjects(r,s){return r.map((i,o)=>{const n=i.codePointAt(0)||0,a=this.se(o);let h=0;if(s.hmtx&&s.hmtx.aWidth){const u=this.ie(s,n);u>0&&s.hmtx.aWidth[u]!==void 0&&(h=s.hmtx.aWidth[u])}return{character:i,unicode:n,color:a,advanceWidth:h}})}ie(r,s){const i=r.cmap;if(!i||!i.tables)return 0;for(const o of i.tables)if(o.format===4){for(let n=0;n<o.startCount.length;n++)if(s>=o.startCount[n]&&s<=o.endCount[n]){if(o.idRangeOffset[n]===0)return s+o.idDelta[n]&65535;{const a=o.idRangeOffset[n]/2+(s-o.startCount[n])-(o.startCount.length-n);if(a>=0&&a<o.glyphIdArray.length){const h=o.glyphIdArray[a];if(h!==0)return h+o.idDelta[n]&65535}}}}return 0}se(r){return[r%256,Math.floor(r/256)%256,Math.floor(r/65536)%256]}getCharacterColor(r,s){if(!_.p(typeof r=="string","Character must be a string.",{method:"getCharacterColor",providedValue:r}))return[0,0,0];const i=s.find(o=>o.character===r);return i?i.color:[0,0,0]}getCharacterColors(r,s){return _.p(typeof r=="string"&&r.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:r})?r.split("").map(i=>this.getCharacterColor(i,s)||[0,0,0]):[[0,0,0]]}}class Q{constructor(r,s=16){c(this,"oe");c(this,"ne",[]);c(this,"ae");c(this,"he",16);c(this,"le",0);c(this,"ce",0);c(this,"ue",{width:0,height:0});c(this,"fe");c(this,"de","UrsaFont");c(this,"me");c(this,"pe");c(this,"ge");c(this,"_e");this.he=s,this.me=new ht,this.pe=new lt(r),this.ge=new ct,this._e=new ut}async ve(r){let s;if(!r)throw new x("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const i=await fetch(r);if(!i.ok)throw new x(`Failed to load font file: ${i.status} ${i.statusText}`);s=await i.arrayBuffer()}await this.xe(s),this.oe=m.parse(s)[0],await this.be()}we(r){if(r===void 0)return this.he;this.he=r,this.ue=this.ge.calculateMaxGlyphDimensions(this.ne.map(i=>i.character),this.he,this.de);const s=this.pe.createTextureAtlas(this.ne,this.ue,this.he,this.de);this.ae=s.framebuffer,this.le=s.columns,this.ce=s.rows}async Ce(r){try{const s=await fetch(r);if(!s.ok)throw new x(`Failed to load font file: ${s.status} ${s.statusText}`);const i=await s.arrayBuffer();await this.xe(i);const o=m.parse(i);if(!o||o.length===0)throw Error("Failed to parse font file");this.oe=o[0],await this.be()}catch(s){throw new x("Failed to load font: "+(s instanceof Error?s.message:"Unknown error"),s)}}async xe(r){const s=Date.now();this.de=this.de==="UrsaFont"?"UrsaFont":"CustomFont_"+s,this.fe=new FontFace(this.de,r),await this.fe.load(),document.fonts.add(this.fe)}async be(){const r=this.me.extractCharacters(this.oe),s=this.me.filterProblematicCharacters(r);this.ne=this._e.createCharacterObjects(s,this.oe),this.ue=this.ge.calculateMaxGlyphDimensions(s,this.he,this.de);const i=this.pe.createTextureAtlas(this.ne,this.ue,this.he,this.de);this.ae=i.framebuffer,this.le=i.columns,this.ce=i.rows}getCharacterColor(r){return this._e.getCharacterColor(r,this.ne)}getCharacterColors(r){return this._e.getCharacterColors(r,this.ne)}hasAllCharacters(r){if(typeof r!="string"||r.length===0)return!1;const s=new Set(this.ne.map(i=>i.character));for(const i of r)if(!s.has(i))return!1;return!0}P(){this.ae.P(),document.fonts.delete(this.fe)}get fontFramebuffer(){return this.ae}get characters(){return this.ne}get textureColumns(){return this.le}get textureRows(){return this.ce}get maxGlyphDimensions(){return this.ue}get fontSize(){return this.he}get font(){return this.oe}}class J{constructor(r,s,i){c(this,"ye");c(this,"$e");c(this,"F");c(this,"D");c(this,"Fe");c(this,"Te");c(this,"De",!1);c(this,"Me");c(this,"Se");c(this,"Re");this.Me=r,this.Se=s,this.Re=i,this.kt()}kt(){this.De||(this.ye=Math.floor(this.Me.width/this.Se),this.$e=Math.floor(this.Me.height/this.Re)),this.Ve()}Ve(){this.F=this.ye*this.Se,this.D=this.$e*this.Re,this.Fe=Math.floor((this.Me.width-this.F)/2),this.Te=Math.floor((this.Me.height-this.D)/2)}ke(r,s){this.Se=r,this.Re=s,this.kt()}ze(r,s){this.De=!0,this.ye=r,this.$e=s,this.Ve()}Ie(){this.De=!1,this.kt()}Pe(){this.De?this.Ve():this.kt()}Ue(r){if(r===void 0)return this.De;this.De=r}get cellWidth(){return this.Se}get cellHeight(){return this.Re}get cols(){return this.ye}get rows(){return this.$e}get width(){return this.F}get height(){return this.D}get offsetX(){return this.Fe}get offsetY(){return this.Te}}class K{constructor(r,s=!1,i={}){c(this,"Me");c(this,"Ae");c(this,"Ge");c(this,"Ee");c(this,"onTransformChange");this.Ae=r,this.Ge=s,this.Me=this.Le(i.width,i.height),s&&this.setupTransformObserver()}Le(r,s){var o;const i=document.createElement("canvas");if(i.className="textmodeCanvas",i.style.imageRendering="pixelated",this.Ge)i.width=r||800,i.height=s||600,document.body.appendChild(i);else{const n=this.Ae.getBoundingClientRect();let a=Math.round(n.width),h=Math.round(n.height);if(this.Ae instanceof HTMLVideoElement){const f=this.Ae;(a===0||h===0)&&f.videoWidth>0&&f.videoHeight>0&&(a=f.videoWidth,h=f.videoHeight)}i.width=a,i.height=h,i.style.position="absolute",i.style.pointerEvents="none";const u=window.getComputedStyle(this.Ae);let d=parseInt(u.zIndex||"0",10);isNaN(d)&&(d=0),i.style.zIndex=""+(d+1),this.Oe(i),(o=this.Ae.parentNode)==null||o.insertBefore(i,this.Ae.nextSibling)}return i}Oe(r){const s=this.Ae.getBoundingClientRect();let i=this.Ae.offsetParent;if(i&&i!==document.body){const o=i.getBoundingClientRect();r.style.top=s.top-o.top+"px",r.style.left=s.left-o.left+"px"}else r.style.top=s.top+window.scrollY+"px",r.style.left=s.left+window.scrollX+"px"}Pe(r,s){if(this.Ge)this.Me.width=r??this.Me.width,this.Me.height=s??this.Me.height;else{const i=this.Ae.getBoundingClientRect();let o=Math.round(i.width),n=Math.round(i.height);if(this.Ae instanceof HTMLVideoElement){const a=this.Ae;(o===0||n===0)&&a.videoWidth>0&&a.videoHeight>0&&(o=a.videoWidth,n=a.videoHeight)}this.Me.width=o,this.Me.height=n,this.Oe(this.Me)}}Be(){const r={alpha:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"},s=this.Me.getContext("webgl2",r)||this.Me.getContext("webgl",r);if(!s)throw new x("WebGL context could not be created. Ensure your browser supports WebGL.");return s}setupTransformObserver(){this.Ee=new ResizeObserver(r=>{for(const s of r){const i=s.contentRect;!this.onTransformChange||Math.round(i.width)===this.Me.width&&Math.round(i.height)===this.Me.height||this.onTransformChange()}}),this.Ee.observe(this.Me)}P(){this.Ee&&this.Ee.disconnect();const r=this.Me.getContext("webgl")||this.Me.getContext("webgl2");if(r){const s=r.getExtension("WEBGL_lose_context");s&&s.loseContext()}this.Me.parentNode&&this.Me.parentNode.removeChild(this.Me)}get canvas(){return this.Me}get width(){return this.Me.width}get height(){return this.Me.height}}class Z{constructor(r,s,i,o={}){c(this,"Zt");c(this,"He");c(this,"je");c(this,"We");c(this,"Ne");c(this,"Xe");c(this,"qe");c(this,"Ye");c(this,"l");this.Zt=r,this.He=s,this.je=i,this.l=o;const n=this.je.cols,a=this.je.rows;this.We=this.Zt.Et(n,a),this.Ne=this.Zt.Et(n,a),this.Xe=this.Zt.Et(n,a),this.qe=this.Zt.Et(n,a),this.Ye=this.Zt.Et(n,a)}Pe(){const r=this.je.cols,s=this.je.rows;this.We.resize(r,s),this.Ne.resize(r,s),this.Xe.resize(r,s),this.qe.resize(r,s),this.Ye.resize(r,s)}enabled(r){this.l.enabled=r}enable(){this.enabled(!0)}disable(){this.enabled(!1)}P(){this.We.P(),this.Ne.P(),this.Xe.P(),this.qe.P(),this.Ye.P()}get characterFramebuffer(){return this.We}get primaryColorFramebuffer(){return this.Ne}get secondaryColorFramebuffer(){return this.Xe}get rotationFramebuffer(){return this.qe}get transformFramebuffer(){return this.Ye}get options(){return this.l}}class dt{constructor(r,s){c(this,"C");c(this,"Zt");c(this,"Qe");this.Zt=r,this.Qe=s;const i=Math.max(this.Qe.length,1);this.C=this.Zt.Et(i,1),this.Ze()}Ze(){const r=this.Qe.length;this.C.width!==r&&this.C.resize(r,1);const s=new Uint8Array(1*r*4);for(let i=0;i<r;i++){const o=this.Qe[i],n=4*i;s[n]=o[0],s[n+1]=o[1],s[n+2]=o[2],s[n+3]=255}this.C.updatePixels(s,r,1)}setColors(r){this.Qe=r,this.Ze()}get colors(){return this.Qe}get framebuffer(){return this.C}get texture(){return this.C.texture}}class N extends Z{constructor(s,i,o,n={}){super(s,i,o,n);c(this,"Je");this.Je=new dt(this.Zt,this.He.getCharacterColors(" .:-=+*%@#"))}characters(s){_.p(this.He.hasAllCharacters(s),"One or more characters do not exist in the current font.",{method:"characters",providedValue:s})&&(this.l.characters=s,this.Je.setColors(this.He.getCharacterColors(s)))}characterColor(s,i,o,n=255){const a=this.Ke(s,"characterColor",i,o,n);a&&(this.l.characterColor=a)}characterColorMode(s){this.tr(s,"characterColorMode")}cellColor(s,i,o,n=255){const a=this.Ke(s,"cellColor",i,o,n);a&&(this.l.cellColor=a)}cellColorMode(s){this.tr(s,"cellColorMode")}invert(s){this.er(s,"invert","Invert")}rotation(s){if(!_.p(typeof s=="number","Rotation angle must be a number.",{method:"rotation",providedValue:s}))return;(s%=360)<0&&(s+=360);const i=255*s/360,o=Math.floor(i)/255,n=Math.round(i-o);this.l.rotation=[o,n,0,1]}flipHorizontally(s){this.er(s,"flipHorizontally","Flip horizontally")}flipVertically(s){this.er(s,"flipVertically","Flip vertically")}Ke(s,i,o,n,a=255){let h,u,d,f;if(typeof s=="string"){const g=this.rr(s);if(!g)return _.p(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:i,providedValue:s}),null;[h,u,d,f]=g}else if(h=s,u=o!==void 0?o:s,d=n!==void 0?n:s,f=a,!_.p([h,u,d,f].every(g=>g>=0&&g<=255),i.charAt(0).toUpperCase()+i.slice(1)+" color values must be between 0 and 255",{method:i,providedValues:{r:h,g:u,b:d,a:f}}))return null;return[h/255,u/255,d/255,f/255]}tr(s,i){_.p(["sampled","fixed"].includes(s),"Invalid color mode. Must be 'sampled' or 'fixed'.",{method:i,providedValue:s})&&(this.l[i]=s)}er(s,i,o){_.p(typeof s=="boolean"||typeof s=="number"&&Number.isInteger(s),o+" must be a boolean value or an integer (0 for false, any other number for true).",{method:i,providedValue:s})&&(this.l[i]=!!s)}rr(s){return s=s.replace(/^#/,""),/^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(s)?(s.length===3&&(s=s.split("").map(i=>i+i).join("")),[parseInt(s.slice(0,2),16),parseInt(s.slice(2,4),16),parseInt(s.slice(4,6),16),255]):null}}const $=`attribute vec2 a_position;\r
|
|
7
|
+
`,i}static o(r){if(r===null)return"null";if(r===void 0)return"undefined";if(typeof r=="string")return`"${r}"`;if(typeof r=="number"||typeof r=="boolean")return r+"";if(Array.isArray(r))return r.length===0?"[]":r.length<=5?`[${r.map(s=>b.o(s)).join(", ")}]`:`[${r.slice(0,3).map(s=>b.o(s)).join(", ")}, ... +${r.length-3} more]`;if(typeof r=="object"){const s=Object.keys(r);return s.length===0?"{}":s.length<=3?`{ ${s.map(i=>`${i}: ${b.o(r[i])}`).join(", ")} }`:`{ ${s.slice(0,2).map(i=>`${i}: ${b.o(r[i])}`).join(", ")}, ... +${s.length-2} more }`}return r+""}}var U=(l=>(l[l.SILENT=0]="SILENT",l[l.WARNING=1]="WARNING",l[l.ERROR=2]="ERROR",l[l.THROW=3]="THROW",l))(U||{});const D=class D{constructor(){c(this,"l",{globalLevel:3})}static u(){return D.h||(D.h=new D),D.h}p(r,s){const i="%c[textmode.js] Oops! (╯°□°)╯︵ Something went wrong in your code.",n="color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;";switch(this.l.globalLevel){case 0:return!1;case 1:return console.group(i,n),console.warn(b.i(r,s)),console.groupEnd(),!1;case 2:return console.group(i,n),console.error(b.i(r,s)),console.groupEnd(),!1;default:throw new b(r,s)}}m(r,s,i){return!!r||(this.p(s,i),!1)}_(r){this.l.globalLevel=r}};c(D,"h",null);let V=D;const C=V.u(),X=new WeakMap;function Y(l,r){X.set(l,r)}function q(l){return X.get(l)}class Z{constructor(r,s,i=s,n={}){c(this,"v");c(this,"C");c(this,"$");c(this,"F");c(this,"M");c(this,"l");c(this,"S",null);c(this,"D",null);this.v=r,this.F=s,this.M=i,this.l={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...n},this.$=this.R(),this.C=r.createFramebuffer(),this.V()}k(r){const{v:s}=this,i=s.getParameter(s.FRAMEBUFFER_BINDING);s.bindFramebuffer(s.FRAMEBUFFER,this.C);try{return r()}finally{s.bindFramebuffer(s.FRAMEBUFFER,i)}}R(){const{v:r}=this,s=r.createTexture();r.bindTexture(r.TEXTURE_2D,s);const i=this.l.filter==="linear"?r.LINEAR:r.NEAREST,n=this.l.wrap==="repeat"?r.REPEAT:r.CLAMP_TO_EDGE;return 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,n),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,n),this.I(),s}I(){const{v:r}=this,s=this.l.type==="float"?r.FLOAT:r.UNSIGNED_BYTE;r.texImage2D(r.TEXTURE_2D,0,r.RGBA,this.F,this.M,0,r.RGBA,s,null)}V(){const{v:r}=this;r.bindFramebuffer(r.FRAMEBUFFER,this.C),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,this.$,0),r.bindFramebuffer(r.FRAMEBUFFER,null)}update(r){const{v:s}=this;s.bindTexture(s.TEXTURE_2D,this.$),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,1),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,s.RGBA,s.UNSIGNED_BYTE,r),s.bindTexture(s.TEXTURE_2D,null)}updatePixels(r,s,i){const{v:n}=this;n.bindTexture(n.TEXTURE_2D,this.$),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,s,i,0,n.RGBA,n.UNSIGNED_BYTE,r),n.bindTexture(n.TEXTURE_2D,null)}resize(r,s){const{v:i}=this;this.F=r,this.M=s,this.D=null,i.bindTexture(i.TEXTURE_2D,this.$),this.I(),i.bindTexture(i.TEXTURE_2D,null)}begin(){const{v:r}=this;this.S={framebuffer:r.getParameter(r.FRAMEBUFFER_BINDING),viewport:r.getParameter(r.VIEWPORT)},r.bindFramebuffer(r.FRAMEBUFFER,this.C),r.viewport(0,0,this.F,this.M),Y(r,[0,0,this.F,this.M])}end(){if(!this.S)return;const{v:r}=this;r.bindFramebuffer(r.FRAMEBUFFER,this.S.framebuffer),r.viewport(...this.S.viewport),Y(r,this.S.viewport),this.S=null}loadPixels(){const{v:r}=this;this.D||(this.D=new Uint8Array(this.F*this.M*4)),this.k(()=>{r.readPixels(0,0,this.F,this.M,r.RGBA,r.UNSIGNED_BYTE,this.D)})}get(r,s,i,n){const{v:o}=this;if(r===void 0&&s===void 0){const h=new Uint8Array(this.F*this.M*4);return this.k(()=>(o.readPixels(0,0,this.F,this.M,o.RGBA,o.UNSIGNED_BYTE,h),h))}if(i===void 0&&n===void 0){(r<0||s<0||r>=this.F||s>=this.M)&&(console.warn("The x and y values passed to Framebuffer.get are outside of its range and will be clamped."),r=Math.max(0,Math.min(r,this.F-1)),s=Math.max(0,Math.min(s,this.M-1)));const h=new Uint8Array(4);return this.k(()=>(o.readPixels(r,s,1,1,o.RGBA,o.UNSIGNED_BYTE,h),[h[0],h[1],h[2],h[3]]))}{r=Math.max(0,Math.min(r,this.F-1)),s=Math.max(0,Math.min(s,this.M-1)),i=Math.max(1,Math.min(i,this.F-r)),n=Math.max(1,Math.min(n,this.M-s));const h=new Uint8Array(i*n*4);return this.k(()=>(o.readPixels(r,s,i,n,o.RGBA,o.UNSIGNED_BYTE,h),h))}}G(){this.C&&this.v.deleteFramebuffer(this.C),this.$&&this.v.deleteTexture(this.$)}get framebuffer(){return this.C}get texture(){return this.$}get width(){return this.F}get height(){return this.M}get pixels(){return this.D}}class M{constructor(r,s,i){c(this,"v");c(this,"P");c(this,"A",new Map);c(this,"U",new Map);c(this,"L",0);c(this,"j");this.v=r,this.P=this.H(s,i),this.j=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),this.O()}O(){const r=this.v.getProgramParameter(this.P,this.v.ACTIVE_UNIFORMS);for(let s=0;s<r;s++){const i=this.v.getActiveUniform(this.P,s);if(i){const n=this.v.getUniformLocation(this.P,i.name);n&&(this.A.set(i.name,n),this.U.set(i.name,i.type))}}}H(r,s){const i=this.W(this.v.VERTEX_SHADER,r),n=this.W(this.v.FRAGMENT_SHADER,s),o=this.v.createProgram();if(this.v.attachShader(o,i),this.v.attachShader(o,n),this.v.linkProgram(o),!this.v.getProgramParameter(o,this.v.LINK_STATUS)){const h=this.v.getProgramInfoLog(o);throw Error("Shader program link error: "+h)}return this.v.deleteShader(i),this.v.deleteShader(n),o}W(r,s){const i=this.v.createShader(r);if(this.v.shaderSource(i,s),this.v.compileShader(i),!this.v.getShaderParameter(i,this.v.COMPILE_STATUS)){const n=this.v.getShaderInfoLog(i);throw this.v.deleteShader(i),Error("Shader compilation error: "+n)}return i}N(){this.v.useProgram(this.P),this.X()}setUniform(r,s){const i=this.A.get(r);if(i)if(typeof s=="number")this.q(r)?this.v.uniform1i(i,Math.floor(s)):this.v.uniform1f(i,s);else if(typeof s=="boolean")this.v.uniform1i(i,s?1:0);else if(Array.isArray(s))switch(s.length){case 2:this.v.uniform2f(i,s[0],s[1]);break;case 3:this.v.uniform3f(i,s[0],s[1],s[2]);break;case 4:this.v.uniform4f(i,s[0],s[1],s[2],s[3]);break;default:console.warn(`Unsupported array length ${s.length} for uniform '${r}'`)}else if(s instanceof WebGLTexture){const n=this.Y();this.v.uniform1i(i,n),this.v.activeTexture(this.v.TEXTURE0+n),this.v.bindTexture(this.v.TEXTURE_2D,s)}else if(s instanceof Z){const n=this.Y();this.v.uniform1i(i,n),this.v.activeTexture(this.v.TEXTURE0+n),this.v.bindTexture(this.v.TEXTURE_2D,s.texture)}else console.warn(`Unsupported uniform type for '${r}':`,typeof s)}Y(){return this.L>=this.j&&console.warn(`Exceeded maximum texture units (${this.j}). Texture may not render correctly.`),this.L++}q(r){const s=this.U.get(r);return!!s&&(s===this.v.INT||s===this.v.INT_VEC2||s===this.v.INT_VEC3||s===this.v.INT_VEC4||s===this.v.SAMPLER_2D||s===this.v.SAMPLER_CUBE)}get glProgram(){return this.P}G(){this.v.deleteProgram(this.P)}X(){this.L=0}}class J{constructor(r){c(this,"v");c(this,"Z",null);c(this,"J",16);c(this,"K",new Map);this.v=r}tt(){if(this.Z)return;const r=this.v;this.Z=r.createBuffer(),r.bindBuffer(r.ARRAY_BUFFER,this.Z)}et(){const r=this.v,s=r.getParameter(r.CURRENT_PROGRAM);let i=this.K.get(s);return i||(i={a_position:r.getAttribLocation(s,"a_position"),a_texCoord:r.getAttribLocation(s,"a_texCoord")},this.K.set(s,i)),r.enableVertexAttribArray(i.a_position),r.vertexAttribPointer(i.a_position,2,r.FLOAT,!1,this.J,0),r.enableVertexAttribArray(i.a_texCoord),r.vertexAttribPointer(i.a_texCoord,2,r.FLOAT,!1,this.J,8),{positionLoc:i.a_position,texLoc:i.a_texCoord}}st(r,s){const i=this.v;i.disableVertexAttribArray(r),i.disableVertexAttribArray(s)}rt(r,s){const i=this.v,n=q(i)||[0,0,i.canvas.width,i.canvas.height];return{nx:r/n[2]*2-1,ny:1-s/n[3]*2}}it(r,s,i,n){const o=this.v;this.tt(),o.bindBuffer(o.ARRAY_BUFFER,this.Z);const h=new Float32Array([r,n,0,0,i,n,1,0,r,s,0,1,r,s,0,1,i,n,1,0,i,s,1,1]);o.bufferData(o.ARRAY_BUFFER,h,o.DYNAMIC_DRAW)}G(){this.Z&&this.v.deleteBuffer(this.Z)}}class ht extends J{constructor(r){super(r)}nt(r,s,i,n){const o=this.rt(r,s),h=this.rt(r+i,s+n);this.it(o.nx,o.ny,h.nx,h.ny);const a=this.et();this.v.drawArrays(this.v.TRIANGLES,0,6),this.st(a.positionLoc,a.texLoc)}ot(r,s,i,n,o){this.nt(r,s,i,o),this.nt(r+i-o,s,o,n),this.nt(r,s+n-o,i,o),this.nt(r,s,o,n)}}class at extends J{constructor(r){super(r)}ht(r,s,i,n,o){const h=i-r,a=n-s,u=Math.hypot(h,a);if(u===0){const f=o/2,p=this.rt(r-f,s-f),g=this.rt(r+f,s+f);this.it(p.nx,p.ny,g.nx,g.ny)}else{const f=-a/u,p=h/u,g=o/2,x=r+f*g,v=s+p*g,m=r-f*g,T=s-p*g,y=i+f*g,_=n+p*g,F=i-f*g,A=n-p*g,$=this.rt(x,v),P=this.rt(m,T),I=this.rt(y,_),ot=this.rt(F,A),L=this.v;this.tt(),L.bindBuffer(L.ARRAY_BUFFER,this.Z);const Ot=new Float32Array([$.nx,$.ny,0,0,P.nx,P.ny,0,1,I.nx,I.ny,1,0,P.nx,P.ny,0,1,ot.nx,ot.ny,1,1,I.nx,I.ny,1,0]);L.bufferData(L.ARRAY_BUFFER,Ot,L.DYNAMIC_DRAW)}const d=this.et();this.v.drawArrays(this.v.TRIANGLES,0,6),this.st(d.positionLoc,d.texLoc)}}var B="attribute vec2 a_position;attribute vec2 a_texCoord;varying vec2 v_uv;uniform float u_rotation;uniform vec2 u_center;uniform float u_aspectRatio;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){v_uv=a_texCoord;vec2 pos=a_position;pos-=u_center;pos.x*=u_aspectRatio;pos=rotate2D(-u_rotation)*pos;pos.x/=u_aspectRatio;pos+=u_center;gl_Position=vec4(pos,0.0,1.0);}";class lt{constructor(r){c(this,"v");c(this,"lt");c(this,"ct");c(this,"ut",null);c(this,"ft");c(this,"dt");c(this,"gt",[1,1,1,1]);c(this,"_t",!0);c(this,"vt",[0,0,0,1]);c(this,"xt",1);c(this,"bt",!0);c(this,"wt",0);c(this,"Ct",[]);this.v=r,this.lt=new M(this.v,B,"precision lowp float;uniform sampler2D u_texture;varying vec2 v_uv;void main(){gl_FragColor=texture2D(u_texture,v_uv);}"),this.ct=new M(this.v,B,"precision lowp float;uniform vec4 u_color;void main(){gl_FragColor=u_color;}"),this.ft=new ht(this.v),this.dt=new at(this.v),this.v.enable(this.v.BLEND),this.v.blendEquation(this.v.FUNC_ADD),this.v.blendFunc(this.v.ONE,this.v.ONE_MINUS_SRC_ALPHA),Y(this.v,[0,0,this.v.canvas.width,this.v.canvas.height])}yt(r){this.ut!==r&&(this.ut=r,r.N())}$t(r,s,i,n){if(this._t=!0,s===void 0&&i===void 0&&n===void 0){const o=r/255;this.gt=[o,o,o,1]}else if(i!==void 0&&n===void 0)this.gt=[r/255,s/255,i/255,1];else{if(i===void 0||n===void 0)throw Error("Invalid fill parameters. Use fill(gray), fill(r,g,b), or fill(r,g,b,a)");this.gt=[r/255,s/255,i/255,n/255]}}Ft(r,s,i,n){if(this.bt=!0,s===void 0&&i===void 0&&n===void 0){const o=r/255;this.vt=[o,o,o,1]}else if(i!==void 0&&n===void 0)this.vt=[r/255,s/255,i/255,1];else{if(i===void 0||n===void 0)throw Error("Invalid stroke parameters. Use stroke(gray), stroke(r,g,b), or stroke(r,g,b,a)");this.vt=[r/255,s/255,i/255,n/255]}}Tt(r){if(r<0)throw Error("Stroke weight must be non-negative");this.xt=r}Mt(){this.bt=!1}St(){this._t=!1}Dt(r){this.wt=r}Rt(){this.Ct.push({fillColor:[...this.gt],fillMode:this._t,strokeColor:[...this.vt],strokeWeight:this.xt,strokeMode:this.bt,rotation:this.wt})}Vt(){const r=this.Ct.pop();r?(this.gt=r.fillColor,this._t=r.fillMode,this.vt=r.strokeColor,this.xt=r.strokeWeight,this.bt=r.strokeMode,this.wt=r.rotation):console.warn("pop() called without matching push()")}kt(){this.ut=null,this.Ct=[],this.wt=0}It(r,s){return new M(this.v,r,s)}zt(r){return new M(this.v,B,r)}Et(r,s){this.ut.setUniform(r,s)}Gt(r,s,i,n){if(this.ut!==null){const{centerX:p,centerY:g,radians:x,aspectRatio:v}=this.Pt(r,s,i,n);return this.Et("u_rotation",x),this.Et("u_center",[p,g]),this.Et("u_aspectRatio",v),this.ft.nt(r,s,i,n),void(this.ut=null)}const o=this.ct;let h=0,a=0,u=0,d=1;const f=this.Pt(r,s,i,n);h=f.centerX,a=f.centerY,u=f.radians,d=f.aspectRatio,this._t&&(this.yt(o),this.Et("u_color",this.gt),this.Et("u_rotation",u),this.Et("u_center",[h,a]),this.Et("u_aspectRatio",d),this.ft.nt(r,s,i,n)),this.bt&&this.xt>0&&(this.yt(o),this.Et("u_color",this.vt),this.Et("u_rotation",u),this.Et("u_center",[h,a]),this.Et("u_aspectRatio",d),this.ft.ot(r,s,i,n,this.xt)),this.ut=null}At(r,s,i,n){if(this.ut!==null){const m=(r+i)/2,T=(s+n)/2,y=Math.abs(i-r)||1,_=Math.abs(n-s)||1,{centerX:F,centerY:A,radians:$,aspectRatio:P}=this.Pt(m-y/2,T-_/2,y,_);this.Et("u_rotation",$),this.Et("u_center",[F,A]),this.Et("u_aspectRatio",P);const I=this.xt>0?this.xt:1;return this.dt.ht(r,s,i,n,I),void(this.ut=null)}if(!this.bt||this.xt<=0)return;const o=this.ct,h=(r+i)/2,a=(s+n)/2,u=Math.abs(i-r)||1,d=Math.abs(n-s)||1,f=this.wt!==0;let p=0,g=0,x=0,v=1;if(f){const m=this.Pt(h-u/2,a-d/2,u,d);p=m.centerX,g=m.centerY,x=m.radians,v=m.aspectRatio}this.yt(o),this.Et("u_color",this.vt),f&&(this.Et("u_rotation",x),this.Et("u_center",[p,g]),this.Et("u_aspectRatio",v)),this.dt.ht(r,s,i,n,this.xt)}Pt(r,s,i,n){const o=q(this.v)||[0,0,this.v.canvas.width,this.v.canvas.height],h=o[2],a=o[3],u=h/a;return{centerX:(r+i/2)/h*2-1,centerY:1-(s+n/2)/a*2,radians:this.wt*Math.PI/180,aspectRatio:u}}Ut(r,s,i={}){return new Z(this.v,r,s,i)}Lt(r,s=r,i=r,n=255){this.jt(r/255,s/255,i/255,n/255)}jt(r=0,s=0,i=0,n=0){this.v.clearColor(r,s,i,n),this.v.clear(this.v.COLOR_BUFFER_BIT)}Ht(){this.v.viewport(0,0,this.v.canvas.width,this.v.canvas.height),Y(this.v,[0,0,this.v.canvas.width,this.v.canvas.height])}get context(){return this.v}G(){this.lt.G(),this.ct.G(),this.ft.G(),this.dt.G()}Ot(r,s,i,n,o){const h=this.v,a=n??r.width,u=o??r.height;this.yt(this.lt),this.Et("u_texture",r.texture);const d=this.Pt(s,i,a,u);this.Et("u_rotation",d.radians),this.Et("u_center",[d.centerX,d.centerY]),this.Et("u_aspectRatio",d.aspectRatio),this.ft.nt(s,i,a,u),h.bindTexture(h.TEXTURE_2D,null),this.ut=null}}const E={readShort:(l,r)=>(E.t.uint16[0]=l[r]<<8|l[r+1],E.t.int16[0]),readUshort:(l,r)=>l[r]<<8|l[r+1],readUshorts(l,r,s){const i=[];for(let n=0;n<s;n++)i.push(E.readUshort(l,r+2*n));return i},readUint(l,r){const s=E.t.uint8;return s[3]=l[r],s[2]=l[r+1],s[1]=l[r+2],s[0]=l[r+3],E.t.uint32[0]},readASCII(l,r,s){let i="";for(let n=0;n<s;n++)i+=String.fromCharCode(l[r+n]);return i},t:(()=>{const l=new ArrayBuffer(8);return{uint8:new Uint8Array(l),int16:new Int16Array(l),uint16:new Uint16Array(l),uint32:new Uint32Array(l)}})()},ct={parseTab(l,r,s){const i={tables:[],ids:{},off:r};l=new Uint8Array(l.buffer,r,s),r=0;const n=E,o=n.readUshort,h=o(l,r+=2);r+=2;const a=[];for(let u=0;u<h;u++){const d=o(l,r),f=o(l,r+=2);r+=2;const p=n.readUint(l,r);r+=4;const g=`p${d}e${f}`;let x=a.indexOf(p);if(x===-1){let v;x=i.tables.length,a.push(p);const m=o(l,p);v=m===4?this.parse4(l,p):m===12?this.parse12(l,p):{format:m},i.tables.push(v)}i.ids[g]!=null&&console.warn("Multiple tables for one platform+encoding: "+g),i.ids[g]=x}return i},parse4(l,r){const s=E,i=s.readUshort,n=s.readUshorts,o=r,h=i(l,r+=2);r+=2;const a=i(l,r+=2)>>>1,u={format:4,searchRange:i(l,r+=2),entrySelector:0,rangeShift:0,endCount:[],startCount:[],idDelta:[],idRangeOffset:[],glyphIdArray:[]};r+=2,u.entrySelector=i(l,r),r+=2,u.rangeShift=i(l,r),r+=2,u.endCount=n(l,r,a),r+=2*a,r+=2,u.startCount=n(l,r,a),r+=2*a;for(let d=0;d<a;d++)u.idDelta.push(s.readShort(l,r)),r+=2;return u.idRangeOffset=n(l,r,a),r+=2*a,u.glyphIdArray=n(l,r,o+h-r>>1),u},parse12(l,r){const s=E.readUint;s(l,r+=4),s(l,r+=4);const i=s(l,r+=4);r+=4;const n=new Uint32Array(3*i);for(let o=0;o<3*i;o+=3)n[o]=s(l,r+(o<<2)),n[o+1]=s(l,r+(o<<2)+4),n[o+2]=s(l,r+(o<<2)+8);return{format:12,groups:n}}},ut={parseTab(l,r,s){const i=E;r+=18;const n=i.readUshort(l,r);r+=2,r+=16;const o=i.readShort(l,r);r+=2;const h=i.readShort(l,r);r+=2;const a=i.readShort(l,r);r+=2;const u=i.readShort(l,r);return r+=2,r+=6,{unitsPerEm:n,xMin:o,yMin:h,xMax:a,yMax:u,indexToLocFormat:i.readShort(l,r)}}},dt={parseTab(l,r,s){const i=E;r+=4;const n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],o={};for(let h=0;h<n.length;h++){const a=n[h],u=a==="advanceWidthMax"||a==="numberOfHMetrics"?i.readUshort:i.readShort;o[a]=u(l,r+2*h)}return o}},ft={parseTab(l,r,s,i){if(!i)throw Error("Font object required for hmtx parsing");const n=E,o=[],h=[],a=i.maxp.numGlyphs,u=i.hhea.numberOfHMetrics;let d=0,f=0,p=0;for(;p<u;)d=n.readUshort(l,r+(p<<2)),f=n.readShort(l,r+(p<<2)+2),o.push(d),h.push(f),p++;for(;p<a;)o.push(d),h.push(f),p++;return{aWidth:o,lsBearing:h}}},Q={cmap:ct,head:ut,hhea:dt,maxp:{parseTab(l,r,s){const i=E;return i.readUint(l,r),r+=4,{numGlyphs:i.readUshort(l,r)}}},hmtx:ft,loca:{parseTab(l,r,s,i){if(!i)throw Error("Font object required for loca parsing");const n=E,o=[],h=i.head.indexToLocFormat,a=i.maxp.numGlyphs+1;if(h===0)for(let u=0;u<a;u++)o.push(n.readUshort(l,r+(u<<1))<<1);else if(h===1)for(let u=0;u<a;u++)o.push(n.readUint(l,r+(u<<2)));return o}},glyf:{parseTab(l,r,s,i){if(!i)throw Error("Font object required for glyf parsing");const n=[],o=i.maxp.numGlyphs;for(let h=0;h<o;h++)n.push(null);return n},Bt(l,r){const s=E,i=l.Wt,n=l.loca;if(n[r]===n[r+1])return null;const o=R.findTable(i,"glyf",l.Nt);if(!o)return null;let h=o[0]+n[r];const a={};if(a.noc=s.readShort(i,h),h+=2,a.xMin=s.readShort(i,h),h+=2,a.yMin=s.readShort(i,h),h+=2,a.xMax=s.readShort(i,h),h+=2,a.yMax=s.readShort(i,h),h+=2,a.xMin>=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(let g=0;g<a.noc;g++)a.endPts.push(s.readUshort(i,h)),h+=2;const u=s.readUshort(i,h);if(h+=2,i.length-h<u)return null;h+=u;const d=a.endPts[a.noc-1]+1;a.flags=[];for(let g=0;g<d;g++){const x=i[h];if(h++,a.flags.push(x),8&x){const v=i[h];h++;for(let m=0;m<v;m++)a.flags.push(x),g++}}a.xs=[];for(let g=0;g<d;g++){const x=a.flags[g],v=!!(16&x);2&x?(a.xs.push(v?i[h]:-i[h]),h++):v?a.xs.push(0):(a.xs.push(s.readShort(i,h)),h+=2)}a.ys=[];for(let g=0;g<d;g++){const x=a.flags[g],v=!!(32&x);4&x?(a.ys.push(v?i[h]:-i[h]),h++):v?a.ys.push(0):(a.ys.push(s.readShort(i,h)),h+=2)}let f=0,p=0;for(let g=0;g<d;g++)f+=a.xs[g],p+=a.ys[g],a.xs[g]=f,a.ys[g]=p}else a.parts=[],a.endPts=[],a.flags=[],a.xs=[],a.ys=[];return a}}},R={parse:l=>[((r,s,i,n)=>{const o=Q,h={Wt:r,Xt:s,Nt:i};for(const a in o){const u=a,d=R.findTable(r,u,i);if(d){const[f,p]=d;let g=n[f];g==null&&(g=o[u].parseTab(r,f,p,h),n[f]=g),h[u]=g}}return h})(new Uint8Array(l),0,0,{})],findTable(l,r,s){const i=E,n=i.readUshort(l,s+4);let o=s+12;for(let h=0;h<n;h++){const a=i.readASCII(l,o,4);i.readUint(l,o+4);const u=i.readUint(l,o+8),d=i.readUint(l,o+12);if(a===r)return[u,d];o+=16}return null},T:Q,B:E};class j{constructor(){c(this,"qt",new Map);c(this,"Yt",new Map)}Qt(r){const s=this.Zt(r);if(this.Yt.has(s))return this.Yt.get(s);const i=r.cmap;if(!i||!i.tables)return this.Yt.set(s,null),null;const n=["p3e1","p3e10","p0e3","p0e4"];for(const h of n)if(i.ids[h]!==void 0){const a=i.tables[i.ids[h]];return this.Yt.set(s,a),a}const o=i.tables[0]||null;return this.Yt.set(s,o),o}Jt(r,s){const i=`${this.Zt(r)}_${s}`;if(this.qt.has(i))return this.qt.get(i);const n=this.Qt(r);if(!n)return this.qt.set(i,0),0;let o=0;return n.format===4?o=this.Kt(s,n):n.format===12&&(o=this.te(s,n)),this.qt.set(i,o),o}ee(r,s){const i=s.codePointAt(0);return i===void 0?0:this.Jt(r,i)}se(r,s){const i=r.hmtx;return i&&i.aWidth&&i.aWidth.length!==0?s<i.aWidth.length?i.aWidth[s]:i.aWidth[i.aWidth.length-1]:0}re(r,s){const i=s/r.head.unitsPerEm,n=r.hhea.ascender*i,o=r.hhea.descender*i,h=r.hhea.lineGap*i;return{ascender:n,descender:o,lineGap:h,lineHeight:n-o+h,unitsPerEm:r.head.unitsPerEm,scale:i}}ie(){this.qt.clear(),this.Yt.clear()}Zt(r){return`${r.Nt}_${r.Wt.length}`}Kt(r,s){const i=s.endCount.length;let n=-1;for(let o=0;o<i;o++)if(r<=s.endCount[o]){n=o;break}if(n===-1||r<s.startCount[n])return 0;if(s.idRangeOffset[n]===0)return r+s.idDelta[n]&65535;{const o=s.idRangeOffset[n]/2+(r-s.startCount[n])-(i-n);if(o>=0&&o<s.glyphIdArray.length){const h=s.glyphIdArray[o];return h===0?0:h+s.idDelta[n]&65535}}return 0}te(r,s){const i=s.groups.length/3;for(let n=0;n<i;n++){const o=s.groups[3*n],h=s.groups[3*n+1],a=s.groups[3*n+2];if(r>=o&&r<=h)return a+(r-o)}return 0}}class gt{constructor(r){c(this,"ne");this.ne=r}oe(r){var i;const s=[];return(i=r==null?void 0:r.cmap)!=null&&i.tables?(r.cmap.tables.forEach(n=>{if(n.format===4){const o=this.ae(n);s.push(...o)}else if(n.format===12){const o=this.he(n);s.push(...o)}}),[...new Set(s)]):[]}le(r,s){return this.ne.ee(r,s)>0}ce(r,s){for(const i of s)if(!this.le(r,i))return!1;return!0}ue(r,s){return s.filter(i=>this.le(r,i))}fe(r){return r.filter(s=>this.de(s))}ae(r){const s=[];if(!(r.startCount&&r.endCount&&r.idRangeOffset&&r.idDelta))return s;for(let i=0;i<r.startCount.length;i++){const n=r.startCount[i],o=r.endCount[i];if(n!==65535||o!==65535){for(let h=n;h<=o;h++)if(this.pe(r,h,i)>0)try{const a=String.fromCodePoint(h);s.push(a)}catch{}}}return s}he(r){const s=[];if(!r.groups)return s;for(let i=0;i<r.groups.length;i+=3){const n=r.groups[i],o=r.groups[i+1],h=r.groups[i+2];for(let a=n;a<=o;a++)if(h+(a-n)>0)try{const u=String.fromCodePoint(a);s.push(u)}catch{}}return s}pe(r,s,i){if(r.idRangeOffset[i]===0)return s+r.idDelta[i]&65535;{const n=r.idRangeOffset[i]/2+(s-r.startCount[i])-(r.startCount.length-i);if(n>=0&&r.glyphIdArray&&n<r.glyphIdArray.length){const o=r.glyphIdArray[n];if(o!==0)return o+r.idDelta[i]&65535}}return 0}de(r){const s=r.codePointAt(0)||0;return!(s>=0&&s<=31&&s!==9&&s!==10&&s!==13||s>=127&&s<=159)}}class pt{constructor(){c(this,"me");const r=new j;this.me=new gt(r)}extractCharacters(r){return this.me.oe(r)}filterProblematicCharacters(r){return this.me.fe(r)}characterExists(r,s){return this.me.le(r,s)}allCharactersExist(r,s){return this.me.ce(r,s)}}class mt{constructor(r){c(this,"ge");c(this,"_e");c(this,"ve");c(this,"xe");this.ve=r,this.xe=new j,this.ge=document.createElement("canvas"),this._e=this.ge.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(r,s,i,n){const o=r.length,h=Math.ceil(Math.sqrt(o)),a=Math.ceil(o/h),u=s.width*h,d=s.height*a,f=typeof n=="object"?n:null;this.be(u,d),this.we(r,s,h,i,f);const p=this.ve.Ut(u,d,{filter:"nearest"});return p.update(this.ge),{framebuffer:p,columns:h,rows:a}}be(r,s){this.ge.width=r,this.ge.height=s,this.ge.style.width=r+"px",this.ge.style.height=r+"px",this._e.imageSmoothingEnabled=!1,this.ge.style.imageRendering="pixelated",this._e.fillStyle="black",this._e.fillRect(0,0,r,s),this._e.textBaseline="top",this._e.textAlign="left",this._e.fillStyle="white"}we(r,s,i,n,o){const h=n/o.head.unitsPerEm;for(let a=0;a<r.length;a++){const u=a%i,d=Math.floor(a/i),f=r[a].character,p=this.Ce(o,f);if(!p)continue;const g=f.codePointAt(0)||0,x=this.xe.Jt(o,g),v=this.ye(o,x)*h,m=u*s.width,T=d*s.height,y=m+.5*s.width,_=T+.5*s.height,F=Math.round(y-.5*s.width),A=Math.round(_-.5*n),$=F+.5*(s.width-v),P=A+o.hhea.ascender*h;this.$e(p,$,P,h)}}Ce(r,s){const i=s.codePointAt(0)||0,n=this.xe.Jt(r,i);if(n===0)return null;if(r.glyf&&r.glyf[n]!==null)return r.glyf[n];if(R&&R.T&&R.T.glyf&&R.T.glyf.Bt){const o=R.T.glyf.Bt(r,n);return r.glyf&&o&&(r.glyf[n]=o),o}return null}ye(r,s){const i=r.hmtx;return i&&i.aWidth?s<i.aWidth.length?i.aWidth[s]:i.aWidth[i.aWidth.length-1]:0}$e(r,s,i,n){if(!r||!r.xs||r.noc===0)return;const{xs:o,ys:h,endPts:a,flags:u}=r;if(!(o&&h&&a&&u))return;this._e.beginPath();let d=0;for(let f=0;f<a.length;f++){const p=a[f];if(!(p<d)){if(p>=d){const g=s+o[d]*n,x=i-h[d]*n;this._e.moveTo(g,x);let v=d+1;for(;v<=p;)if(1&u[v]){const m=s+o[v]*n,T=i-h[v]*n;this._e.lineTo(m,T),v++}else{const m=s+o[v]*n,T=i-h[v]*n;let y=v+1>p?d:v+1;if(1&u[y]){const _=s+o[y]*n,F=i-h[y]*n;this._e.quadraticCurveTo(m,T,_,F),v=y+1}else{const _=(m+(s+o[y]*n))/2,F=(T+(i-h[y]*n))/2;this._e.quadraticCurveTo(m,T,_,F),v=y}}this._e.closePath()}d=p+1}}this._e.fill()}}class vt{constructor(){c(this,"ne");this.ne=new j}calculateMaxGlyphDimensions(r,s,i){let n=0;const o=this.ne.re(i,s),h=o.lineHeight;for(const a of r){const u=this.ne.ee(i,a);if(u===0)continue;const d=this.ne.se(i,u)*o.scale;n=Math.max(n,d)}return{width:Math.ceil(n),height:Math.ceil(h)}}getCharacterAdvanceWidth(r,s,i){const n=this.ne.re(i,s),o=this.ne.ee(i,r);return this.ne.se(i,o)*n.scale}getFontMetrics(r,s){return this.ne.re(s,r)}ie(){this.ne.ie()}}class xt{constructor(){c(this,"xe");this.xe=new j}createCharacterObjects(r,s){return r.map((i,n)=>{const o=i.codePointAt(0)||0,h=this.Fe(n);let a=0;if(s.hmtx&&s.hmtx.aWidth){const u=this.xe.Jt(s,o);u>0&&s.hmtx.aWidth[u]!==void 0&&(a=s.hmtx.aWidth[u])}return{character:i,unicode:o,color:h,advanceWidth:a}})}Fe(r){return[r%256,Math.floor(r/256)%256,Math.floor(r/65536)%256]}getCharacterColor(r,s){if(!C.m(typeof r=="string","Character must be a string.",{method:"getCharacterColor",providedValue:r}))return[0,0,0];const i=s.find(n=>n.character===r);return i?i.color:[0,0,0]}getCharacterColors(r,s){return C.m(typeof r=="string"&&r.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:r})?r.split("").map(i=>this.getCharacterColor(i,s)||[0,0,0]):[[0,0,0]]}}class K{constructor(r,s=16){c(this,"Te");c(this,"Me",[]);c(this,"Se");c(this,"De",16);c(this,"Re",0);c(this,"Ve",0);c(this,"ke",{width:0,height:0});c(this,"Ie");c(this,"ze","UrsaFont");c(this,"Ee");c(this,"Ge");c(this,"Pe");c(this,"Ae");this.De=s,this.Ee=new pt,this.Ge=new mt(r),this.Pe=new vt,this.Ae=new xt}async Ue(r){let s;if(!r)throw new b("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const i=await fetch(r);if(!i.ok)throw new b(`Failed to load font file: ${i.status} ${i.statusText}`);s=await i.arrayBuffer()}await this.Le(s),this.Te=R.parse(s)[0],await this.je()}He(r){if(r===void 0)return this.De;this.De=r,this.ke=this.Pe.calculateMaxGlyphDimensions(this.Me.map(i=>i.character),this.De,this.Te);const s=this.Ge.createTextureAtlas(this.Me,this.ke,this.De,this.Te);this.Se=s.framebuffer,this.Re=s.columns,this.Ve=s.rows}async Oe(r){try{const s=await fetch(r);if(!s.ok)throw new b(`Failed to load font file: ${s.status} ${s.statusText}`);const i=await s.arrayBuffer();await this.Le(i);const n=R.parse(i);if(!n||n.length===0)throw Error("Failed to parse font file");this.Te=n[0],await this.je()}catch(s){throw new b("Failed to load font: "+(s instanceof Error?s.message:"Unknown error"),s)}}async Le(r){const s=Date.now();this.ze=this.ze==="UrsaFont"?"UrsaFont":"CustomFont_"+s,this.Ie=new FontFace(this.ze,r),await this.Ie.load(),document.fonts.add(this.Ie)}async je(){const r=this.Ee.extractCharacters(this.Te),s=this.Ee.filterProblematicCharacters(r);this.Me=this.Ae.createCharacterObjects(s,this.Te),this.ke=this.Pe.calculateMaxGlyphDimensions(s,this.De,this.Te);const i=this.Ge.createTextureAtlas(this.Me,this.ke,this.De,this.Te);this.Se=i.framebuffer,this.Re=i.columns,this.Ve=i.rows}getCharacterColor(r){return this.Ae.getCharacterColor(r,this.Me)}getCharacterColors(r){return this.Ae.getCharacterColors(r,this.Me)}hasAllCharacters(r){if(typeof r!="string"||r.length===0)return!1;const s=new Set(this.Me.map(i=>i.character));for(const i of r)if(!s.has(i))return!1;return!0}G(){this.Se.G(),document.fonts.delete(this.Ie)}get fontFramebuffer(){return this.Se}get characters(){return this.Me}get textureColumns(){return this.Re}get textureRows(){return this.Ve}get maxGlyphDimensions(){return this.ke}get fontSize(){return this.De}get font(){return this.Te}}class tt{constructor(r,s,i){c(this,"Be");c(this,"We");c(this,"F");c(this,"M");c(this,"Ne");c(this,"Xe");c(this,"qe",!1);c(this,"Ye");c(this,"Qe");c(this,"Ze");this.Ye=r,this.Qe=s,this.Ze=i,this.kt()}kt(){this.qe||(this.Be=Math.floor(this.Ye.width/this.Qe),this.We=Math.floor(this.Ye.height/this.Ze)),this.Je()}Je(){this.F=this.Be*this.Qe,this.M=this.We*this.Ze,this.Ne=Math.floor((this.Ye.width-this.F)/2),this.Xe=Math.floor((this.Ye.height-this.M)/2)}Ke(r,s){this.Qe=r,this.Ze=s,this.kt()}ts(r,s){this.qe=!0,this.Be=r,this.We=s,this.Je()}es(){this.qe=!1,this.kt()}ss(){this.qe?this.Je():this.kt()}rs(r){if(r===void 0)return this.qe;this.qe=r}get cellWidth(){return this.Qe}get cellHeight(){return this.Ze}get cols(){return this.Be}get rows(){return this.We}get width(){return this.F}get height(){return this.M}get offsetX(){return this.Ne}get offsetY(){return this.Xe}}class et{constructor(r,s=!1,i={}){c(this,"Ye");c(this,"ns");c(this,"hs");c(this,"ls");c(this,"onTransformChange");this.ns=r,this.hs=s,this.Ye=this.cs(i.width,i.height),s&&this.setupTransformObserver()}cs(r,s){var n;const i=document.createElement("canvas");if(i.className="textmodeCanvas",i.style.imageRendering="pixelated",this.hs)i.width=r||800,i.height=s||600,document.body.appendChild(i);else{const o=this.ns.getBoundingClientRect();let h=Math.round(o.width),a=Math.round(o.height);if(this.ns instanceof HTMLVideoElement){const f=this.ns;(h===0||a===0)&&f.videoWidth>0&&f.videoHeight>0&&(h=f.videoWidth,a=f.videoHeight)}i.width=h,i.height=a,i.style.position="absolute",i.style.pointerEvents="none";const u=window.getComputedStyle(this.ns);let d=parseInt(u.zIndex||"0",10);isNaN(d)&&(d=0),i.style.zIndex=""+(d+1),this.us(i),(n=this.ns.parentNode)==null||n.insertBefore(i,this.ns.nextSibling)}return i}us(r){const s=this.ns.getBoundingClientRect();let i=this.ns.offsetParent;if(i&&i!==document.body){const n=i.getBoundingClientRect();r.style.top=s.top-n.top+"px",r.style.left=s.left-n.left+"px"}else r.style.top=s.top+window.scrollY+"px",r.style.left=s.left+window.scrollX+"px"}ss(r,s){if(this.hs)this.Ye.width=r??this.Ye.width,this.Ye.height=s??this.Ye.height;else{const i=this.ns.getBoundingClientRect();let n=Math.round(i.width),o=Math.round(i.height);if(this.ns instanceof HTMLVideoElement){const h=this.ns;(n===0||o===0)&&h.videoWidth>0&&h.videoHeight>0&&(n=h.videoWidth,o=h.videoHeight)}this.Ye.width=n,this.Ye.height=o,this.us(this.Ye)}}fs(){const r={alpha:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"},s=this.Ye.getContext("webgl2",r)||this.Ye.getContext("webgl",r);if(!s)throw new b("WebGL context could not be created. Ensure your browser supports WebGL.");return s}setupTransformObserver(){this.ls=new ResizeObserver(r=>{for(const s of r){const i=s.contentRect;!this.onTransformChange||Math.round(i.width)===this.Ye.width&&Math.round(i.height)===this.Ye.height||this.onTransformChange()}}),this.ls.observe(this.Ye)}G(){this.ls&&this.ls.disconnect();const r=this.Ye.getContext("webgl")||this.Ye.getContext("webgl2");if(r){const s=r.getExtension("WEBGL_lose_context");s&&s.loseContext()}this.Ye.parentNode&&this.Ye.parentNode.removeChild(this.Ye)}get canvas(){return this.Ye}get width(){return this.Ye.width}get height(){return this.Ye.height}}class S{constructor(r,s,i,n={}){c(this,"ve");c(this,"ds");c(this,"ps");c(this,"gs");c(this,"_s");c(this,"vs");c(this,"bs");c(this,"ws");c(this,"l");this.ve=r,this.ds=s,this.ps=i,this.l=n;const o=this.ps.cols,h=this.ps.rows;this.gs=this.ve.Ut(o,h),this._s=this.ve.Ut(o,h),this.vs=this.ve.Ut(o,h),this.bs=this.ve.Ut(o,h),this.ws=this.ve.Ut(o,h)}ss(){const r=this.ps.cols,s=this.ps.rows;this.gs.resize(r,s),this._s.resize(r,s),this.vs.resize(r,s),this.bs.resize(r,s),this.ws.resize(r,s)}enabled(r){C.m(typeof r=="boolean"||typeof r=="number"&&Number.isInteger(r),"Enabled must be a boolean value or an integer (0 for false, any other number for true).",{method:"enabled",providedValue:r})&&(this.l.enabled=!!r)}enable(){this.enabled(!0)}disable(){this.enabled(!1)}G(){this.gs.G(),this._s.G(),this.vs.G(),this.bs.G(),this.ws.G()}get characterFramebuffer(){return this.gs}get primaryColorFramebuffer(){return this._s}get secondaryColorFramebuffer(){return this.vs}get rotationFramebuffer(){return this.bs}get transformFramebuffer(){return this.ws}get options(){return this.l}}class bt{constructor(r,s){c(this,"C");c(this,"ve");c(this,"Cs");this.ve=r,this.Cs=s;const i=Math.max(this.Cs.length,1);this.C=this.ve.Ut(i,1),this.$s()}$s(){const r=this.Cs.length;this.C.width!==r&&this.C.resize(r,1);const s=new Uint8Array(1*r*4);for(let i=0;i<r;i++){const n=this.Cs[i],o=4*i;s[o]=n[0],s[o+1]=n[1],s[o+2]=n[2],s[o+3]=255}this.C.updatePixels(s,r,1)}setColors(r){this.Cs=r,this.$s()}get colors(){return this.Cs}get framebuffer(){return this.C}get texture(){return this.C.texture}}class O extends S{constructor(s,i,n,o={}){super(s,i,n,o);c(this,"Fs");this.Fs=new bt(this.ve,this.ds.getCharacterColors(" .:-=+*%@#"))}characters(s){C.m(this.ds.hasAllCharacters(s),"One or more characters do not exist in the current font.",{method:"characters",providedValue:s})&&(this.l.characters=s,this.Fs.setColors(this.ds.getCharacterColors(s)))}characterColor(s,i,n,o=255){const h=this.Ts(s,"characterColor",i,n,o);h&&(this.l.characterColor=h)}characterColorMode(s){this.Ms(s,"characterColorMode")}cellColor(s,i,n,o=255){const h=this.Ts(s,"cellColor",i,n,o);h&&(this.l.cellColor=h)}cellColorMode(s){this.Ms(s,"cellColorMode")}invert(s){this.Ss(s,"invert","Invert")}rotation(s){if(!C.m(typeof s=="number","Rotation angle must be a number.",{method:"rotation",providedValue:s}))return;(s%=360)<0&&(s+=360);const i=255*s/360,n=Math.floor(i)/255,o=Math.round(i-n);this.l.rotation=[n,o,0,1]}flipHorizontally(s){this.Ss(s,"flipHorizontally","Flip horizontally")}flipVertically(s){this.Ss(s,"flipVertically","Flip vertically")}Ts(s,i,n,o,h=255){let a,u,d,f;if(typeof s=="string"){const p=this.Ds(s);if(!p)return C.m(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:i,providedValue:s}),null;[a,u,d,f]=p}else if(a=s,u=n!==void 0?n:s,d=o!==void 0?o:s,f=h,!C.m([a,u,d,f].every(p=>p>=0&&p<=255),i.charAt(0).toUpperCase()+i.slice(1)+" color values must be between 0 and 255",{method:i,providedValues:{r:a,g:u,b:d,a:f}}))return null;return[a/255,u/255,d/255,f/255]}Ms(s,i){C.m(["sampled","fixed"].includes(s),"Invalid color mode. Must be 'sampled' or 'fixed'.",{method:i,providedValue:s})&&(this.l[i]=s)}Ss(s,i,n){C.m(typeof s=="boolean"||typeof s=="number"&&Number.isInteger(s),n+" must be a boolean value or an integer (0 for false, any other number for true).",{method:i,providedValue:s})&&(this.l[i]=!!s)}Ds(s){return s=s.replace(/^#/,""),/^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(s)?(s.length===3&&(s=s.split("").map(i=>i+i).join("")),[parseInt(s.slice(0,2),16),parseInt(s.slice(2,4),16),parseInt(s.slice(4,6),16),255]):null}}const G=`attribute vec2 a_position;\r
|
|
8
8
|
attribute vec2 a_texCoord;\r
|
|
9
9
|
varying vec2 v_uv;\r
|
|
10
10
|
\r
|
|
@@ -42,22 +42,22 @@ void main() {\r
|
|
|
42
42
|
\r
|
|
43
43
|
gl_Position = vec4(pos, 0.0, 1.0);\r
|
|
44
44
|
}\r
|
|
45
|
-
`,ft={enabled:!0,characters:" .:-=+*%@#",characterColor:[1,1,1,1],characterColorMode:"sampled",cellColor:[0,0,0,1],cellColorMode:"fixed",invert:!1,rotation:[0,0,0,255],flipHorizontally:!1,flipVertically:!1,brightnessRange:[0,255]};class z extends N{constructor(s,i,o){super(s,i,o,{...ft});c(this,"sr");c(this,"ir");c(this,"nr");c(this,"ar");c(this,"hr");c(this,"lr");this.sr=new P(s.context,$,"precision lowp float;uniform sampler2D u_sketchTexture;uniform vec2 u_gridCellDimensions;uniform vec2 u_brightnessRange;varying vec2 v_uv;void main(){vec2 cellCenter=(floor(v_uv*u_gridCellDimensions)+vec2(0.5))/u_gridCellDimensions;vec4 color=texture2D(u_sketchTexture,cellCenter);float brightness=dot(color.rgb,vec3(0.299,0.587,0.114));float brightnessValue=brightness*255.0;if(brightnessValue>=u_brightnessRange.x&&brightnessValue<=u_brightnessRange.y){gl_FragColor=color;}else{gl_FragColor=vec4(0.0);}}"),this.ir=new P(s.context,$,"precision lowp float;uniform sampler2D u_sampleTexture;uniform vec4 u_fillColor;uniform bool u_useFixedColor;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){if(u_useFixedColor){gl_FragColor=u_fillColor;}else{gl_FragColor=sampleColor;}}else{gl_FragColor=vec4(0.0);}}"),this.ar=new P(s.context,$,"precision lowp float;uniform sampler2D u_sampleTexture;uniform bool u_invert;uniform bool u_flipHorizontally;uniform bool u_flipVertically;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){float invertValue=u_invert ? 1.0 : 0.0;float flipHValue=u_flipHorizontally ? 1.0 : 0.0;float flipVValue=u_flipVertically ? 1.0 : 0.0;gl_FragColor=vec4(invertValue,flipHValue,flipVValue,1.0);}else{gl_FragColor=vec4(0.0);}}"),this.hr=new P(s.context,$,"precision lowp float;uniform sampler2D u_sampleTexture;uniform vec4 u_rotationColor;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){gl_FragColor=u_rotationColor;}else{gl_FragColor=vec4(0.0);}}"),this.nr=new P(s.context,$,"precision lowp float;uniform sampler2D u_colorSampleFramebuffer;uniform sampler2D u_charPaletteTexture;uniform vec2 u_charPaletteSize;uniform vec2 u_brightnessRange;varying vec2 v_uv;void main(){vec4 color=texture2D(u_colorSampleFramebuffer,v_uv);if(color.a==0.0){gl_FragColor=vec4(0.0);return;}float brightness=dot(color.rgb,vec3(0.299,0.587,0.114))*255.0;vec2 range=u_brightnessRange;if(brightness<range.x||brightness>range.y){gl_FragColor=vec4(0.0);return;}float t=(brightness-range.x)/(range.y-range.x);float idx=clamp(floor(t*u_charPaletteSize.x),0.0,u_charPaletteSize.x-1.0);vec3 charColor=texture2D(u_charPaletteTexture,vec2((idx+0.5)/u_charPaletteSize.x,0.0)).rgb;gl_FragColor=vec4(charColor,1.0);}"),this.lr=this.Zt.Et(this.je.cols,this.je.rows)}cr(s){const i=this.je.cols,o=this.je.rows;this.lr.begin(),this.Zt.Ot(),this.Zt.yt(this.sr),this.Zt.Pt("u_sketchTexture",s),this.Zt.Pt("u_gridCellDimensions",[i,o]),this.Zt.Pt("u_brightnessRange",this.l.brightnessRange),this.Zt.Ut(0,0,i,o),this.lr.end(),this.Ne.begin(),this.Zt.Ot(),this.Zt.yt(this.ir),this.Zt.Pt("u_sampleTexture",this.lr),this.Zt.Pt("u_fillColor",this.l.characterColor),this.Zt.Pt("u_useFixedColor",this.l.characterColorMode==="fixed"),this.Zt.Ut(0,0,i,o),this.Ne.end(),this.Xe.begin(),this.Zt.Ot(),this.Zt.yt(this.ir),this.Zt.Pt("u_sampleTexture",this.lr),this.Zt.Pt("u_fillColor",this.l.cellColor),this.Zt.Pt("u_useFixedColor",this.l.cellColorMode==="fixed"),this.Zt.Ut(0,0,i,o),this.Xe.end(),this.Ye.begin(),this.Zt.Ot(),this.Zt.yt(this.ar),this.Zt.Pt("u_sampleTexture",this.lr),this.Zt.Pt("u_invert",this.l.invert),this.Zt.Pt("u_flipHorizontally",this.l.flipHorizontally),this.Zt.Pt("u_flipVertically",this.l.flipVertically),this.Zt.Ut(0,0,i,o),this.Ye.end(),this.qe.begin(),this.Zt.Ot(),this.Zt.yt(this.hr),this.Zt.Pt("u_sampleTexture",this.lr),this.Zt.Pt("u_rotationColor",this.l.rotation),this.Zt.Ut(0,0,i,o),this.qe.end(),this.We.begin(),this.Zt.Ot(),this.Zt.yt(this.nr),this.Zt.Pt("u_colorSampleFramebuffer",this.lr),this.Zt.Pt("u_charPaletteTexture",this.Je.texture),this.Zt.Pt("u_charPaletteSize",[this.Je.colors.length,1]),this.Zt.Pt("u_brightnessRange",this.l.brightnessRange),this.Zt.Ut(0,0,i,o),this.We.end()}Pe(){super.Pe(),this.lr.resize(this.je.cols,this.je.rows)}brightnessRange(s){_.p(Array.isArray(s)&&s.length===2&&s.every(i=>typeof i=="number"&&i>=0&&i<=255),"Brightness range must be an array of two numbers between 0 and 255.",{method:"brightnessRange",providedValue:s})&&(this.l.brightnessRange=s)}}const gt=Object.freeze(Object.defineProperty({__proto__:null,TextmodeBrightnessConverter:z,TextmodeConverter:Z,TextmodeFeatureConverter:N},Symbol.toStringTag,{value:"Module"}));class tt{constructor(r,s,i){c(this,"Zt");c(this,"oe");c(this,"je");c(this,"ur");c(this,"dr");c(this,"mr");c(this,"pr");c(this,"gr");c(this,"We");c(this,"Ne");c(this,"Xe");c(this,"qe");c(this,"Ye");this.Zt=r,this.oe=s,this.je=i,this.gr=this.Zt.zt(k,"precision mediump float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D u_primaryColorTexture;uniform sampler2D u_secondaryColorTexture;uniform sampler2D u_transformTexture;uniform sampler2D u_asciiCharacterTexture;uniform sampler2D u_rotationTexture;uniform sampler2D u_captureTexture;uniform vec2 u_captureDimensions;uniform int u_backgroundMode;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){vec2 adjustedCoord=gl_FragCoord.xy/u_gridPixelDimensions;vec2 gridCoord=adjustedCoord*u_gridCellDimensions;vec2 cellCoord=floor(gridCoord);vec2 charIndexTexCoord=(cellCoord+0.5)/u_gridCellDimensions;vec4 primaryColor=texture2D(u_primaryColorTexture,charIndexTexCoord);vec4 secondaryColor=texture2D(u_secondaryColorTexture,charIndexTexCoord);vec4 transformColor=texture2D(u_transformTexture,charIndexTexCoord);bool isInverted=transformColor.r>0.5;bool flipHorizontal=transformColor.g>0.5;bool flipVertical=transformColor.b>0.5;vec4 encodedIndexVec=texture2D(u_asciiCharacterTexture,charIndexTexCoord);if(encodedIndexVec.a<0.01){gl_FragColor=(u_backgroundMode==0)? vec4(0.0):texture2D(u_captureTexture,gl_FragCoord.xy/u_captureDimensions);return;}int charIndex=int(encodedIndexVec.r*255.0+0.5)+int(encodedIndexVec.g*255.0+0.5)*256;int charCol=int(mod(float(charIndex),u_charsetDimensions.x));int charRow=charIndex/int(u_charsetDimensions.x);float flippedRow=(u_charsetDimensions.y-1.0)-float(charRow);vec2 charCoord=vec2(float(charCol),flippedRow)/u_charsetDimensions;vec4 rotationColor=texture2D(u_rotationTexture,charIndexTexCoord);float scaledAngle=rotationColor.r*255.0+rotationColor.g;float rotationAngle=(scaledAngle*360.0/255.0)*0.017453292;vec2 fractionalPart=fract(gridCoord)-0.5;if(flipHorizontal)fractionalPart.x=-fractionalPart.x;if(flipVertical)fractionalPart.y=-fractionalPart.y;fractionalPart=rotate2D(rotationAngle)*fractionalPart+0.5;vec2 cellSize=1.0/u_charsetDimensions;vec2 texCoord=charCoord+fractionalPart*cellSize;vec2 cellMax=charCoord+cellSize;if(any(lessThan(texCoord,charCoord))||any(greaterThan(texCoord,cellMax))){gl_FragColor=isInverted ? primaryColor : secondaryColor;return;}vec4 charTexel=texture2D(u_characterTexture,texCoord);if(isInverted)charTexel.rgb=1.0-charTexel.rgb;gl_FragColor=mix(secondaryColor,primaryColor,charTexel);}"),this.dr=new z(r,s,i),this.mr=new Z(r,s,i),this.ur=[this.dr,this.mr],this.We=this.Zt.Et(i.cols,i.rows),this.Ne=this.Zt.Et(i.cols,i.rows),this.Xe=this.Zt.Et(i.cols,i.rows),this.qe=this.Zt.Et(i.cols,i.rows),this.Ye=this.Zt.Et(i.cols,i.rows),this.pr=this.Zt.Et(this.je.width,this.je.height)}_r(r){for(const i of this.ur)i.options.enabled&&i instanceof N&&i.cr(r);const s=(i,o)=>{i.begin(),this.Zt.Ot();for(const n of this.ur)n.options.enabled&&this.Zt.Ht(o(n),0,0);i.end()};s(this.We,i=>i.characterFramebuffer),s(this.Ne,i=>i.primaryColorFramebuffer),s(this.Xe,i=>i.secondaryColorFramebuffer),s(this.qe,i=>i.rotationFramebuffer),s(this.Ye,i=>i.transformFramebuffer),this.pr.begin(),this.Zt.Ot(),this.Zt.yt(this.gr),this.Zt.Pt("u_characterTexture",this.oe.fontFramebuffer),this.Zt.Pt("u_charsetDimensions",[this.oe.textureColumns,this.oe.textureRows]),this.Zt.Pt("u_asciiCharacterTexture",this.We.texture),this.Zt.Pt("u_primaryColorTexture",this.Ne.texture),this.Zt.Pt("u_secondaryColorTexture",this.Xe.texture),this.Zt.Pt("u_transformTexture",this.Ye.texture),this.Zt.Pt("u_rotationTexture",this.qe.texture),this.Zt.Pt("u_captureTexture",r.texture),this.Zt.Pt("u_backgroundMode",!1),this.Zt.Pt("u_captureDimensions",[r.width,r.height]),this.Zt.Pt("u_gridCellDimensions",[this.je.cols,this.je.rows]),this.Zt.Pt("u_gridPixelDimensions",[this.je.width,this.je.height]),this.Zt.Ut(0,0,this.pr.width,this.pr.height),this.pr.end()}add(r){if(!_.p(r==="brightness"||r==="custom",'Converter type must be either "brightness" or "custom".',{method:"add",providedValue:r}))return;let s;return s=r==="brightness"?new z(this.Zt,this.oe,this.je):new Z(this.Zt,this.oe,this.je),this.ur.push(s),s}remove(r){if(!_.p(r instanceof Z,"Parameter must be a TextmodeConverter instance.",{method:"remove",providedValue:r}))return;const s=this.ur.indexOf(r);_.p(s!==-1,"Converter instance not found in pipeline.",{method:"remove",providedValue:r,convertersCount:this.ur.length})&&this.ur.splice(s,1)}Pe(){this.pr.resize(this.je.width,this.je.height);const r=this.je.cols,s=this.je.rows;this.We.resize(r,s),this.Ne.resize(r,s),this.Xe.resize(r,s),this.qe.resize(r,s),this.Ye.resize(r,s);for(const i of this.ur)i.Pe()}hasEnabledConverters(){return this.ur.some(r=>r.options.enabled)}disable(){for(const r of this.ur)r.disable()}enable(){for(const r of this.ur)r.enable()}P(){for(const r of this.ur)r.P();this.We.P(),this.Ne.P(),this.Xe.P(),this.qe.P(),this.Ye.P(),this.pr.P(),this.gr.P()}get texture(){return this.pr}get characterFramebuffer(){return this.We}get primaryColorFramebuffer(){return this.Ne}get secondaryColorFramebuffer(){return this.Xe}get rotationFramebuffer(){return this.qe}get transformFramebuffer(){return this.Ye}get brightness(){return this.dr}get custom(){return this.mr}}const pt=l=>class extends l{fill(r,s,i,o){this.Zt.$t(r,s,i,o)}stroke(r,s,i,o){this.Zt.Ft(r,s,i,o)}strokeWeight(r){this.Zt.Tt(r)}noStroke(){this.Zt.Dt()}noFill(){this.Zt.Mt()}rotate(r){this.Zt.St(r)}push(){this.Zt.Rt()}pop(){this.Zt.Vt()}rect(r,s,i=1,o=1){this.Zt.Ut(r,s,i,o)}line(r,s,i,o){this.Zt.Gt(r,s,i,o)}background(r,s=r,i=r,o=255){this.Zt.Lt(r,s,i,o)}createShader(r,s){return this.Zt.zt(r,s)}createFilterShader(r){return this.Zt.It(r)}shader(r){this.Zt.yt(r)}setUniform(r,s){this.Zt.Pt(r,s)}};class V{vr(r){const s=r.characterFramebuffer,i=r.primaryColorFramebuffer,o=r.secondaryColorFramebuffer,n=r.transformFramebuffer,a=r.rotationFramebuffer;return s==null||s.loadPixels(),i==null||i.loadPixels(),o==null||o.loadPixels(),n==null||n.loadPixels(),a==null||a.loadPixels(),{characterPixels:(s==null?void 0:s.pixels)||new Uint8Array(0),primaryColorPixels:(i==null?void 0:i.pixels)||new Uint8Array(0),secondaryColorPixels:(o==null?void 0:o.pixels)||new Uint8Array(0),transformPixels:(n==null?void 0:n.pixels)||new Uint8Array(0),rotationPixels:(a==null?void 0:a.pixels)||new Uint8Array(0)}}br(r,s){return r[s]+(r[s+1]<<8)}wr(r,s){return{r:r[s],g:r[s+1],b:r[s+2],a:r[s+3]}}}class Y{Cr(r,s){return new Blob([r],{type:s})}yr(r,s,i){try{const o=this.Cr(r,i),n=URL.createObjectURL(o),a=document.createElement("a");a.href=n,a.download=s,a.style.display="none",a.rel="noopener",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(n)}catch(o){throw console.error("Failed to download file:",o),Error("File download failed: "+(o instanceof Error?o.message:"Unknown error"))}}$r(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Fr(){const r=new Date;return{date:r.toISOString().split("T")[0],time:r.toTimeString().split(" ")[0].replace(/:/g,"-")}}Tr(r){return r.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Dr(){return"'textmode-export'-"+this.$r()}}class mt extends V{Mr(r,s,i){const o=r[i]===255,n=r[i+1]===255,a=r[i+2]===255,h=s[i],u=s[i+1];return{isInverted:o,flipHorizontal:n,flipVertical:a,rotation:Math.round(360*(h+u/255)/255*100)/100}}Sr(r,s,i){return{x:r,y:s,cellX:r*i.cellWidth,cellY:s*i.cellHeight}}Rr(r,s){const i=[];let o=0;for(let n=0;n<s.rows;n++)for(let a=0;a<s.cols;a++){const h=4*o,u=this.br(r.characterPixels,h);let d=this.wr(r.primaryColorPixels,h),f=this.wr(r.secondaryColorPixels,h);const g=this.Mr(r.transformPixels,r.rotationPixels,h);if(g.isInverted){const b=d;d=f,f=b}const p=this.Sr(a,n,s);i.push({charIndex:u,primaryColor:d,secondaryColor:f,transform:g,position:p}),o++}return i}}class vt{ie(r,s){const i=r.cmap;for(const o of i.tables)if(o.format===4){for(let n=0;n<o.startCount.length;n++)if(s>=o.startCount[n]&&s<=o.endCount[n]){if(o.idRangeOffset[n]===0)return s+o.idDelta[n]&65535;{const a=o.idRangeOffset[n]/2+(s-o.startCount[n])-(o.startCount.length-n);if(a>=0&&a<o.glyphIdArray.length){const h=o.glyphIdArray[a];if(h!==0)return h+o.idDelta[n]&65535}}}}return 0}Vr(r,s,i,o,n){const a=n/r.head.unitsPerEm;return{getBoundingBox:()=>({x1:i+s.xMin*a,y1:o+-s.yMax*a,x2:i+s.xMax*a,y2:o+-s.yMin*a}),toSVG:()=>this.kr(s,i,o,a)}}kr(r,s,i,o){if(!r||!r.xs)return"";const{xs:n,ys:a,endPts:h,flags:u}=r;if(!(n&&a&&h&&u))return"";let d="",f=0;for(let g=0;g<h.length;g++){const p=h[g];if(!(p<f)){if(p>=f){const b=s+n[f]*o,w=i-a[f]*o;d+=`M${b.toFixed(2)},${w.toFixed(2)}`;let v=f+1;for(;v<=p;)if(1&u[v]){const y=s+n[v]*o,E=i-a[v]*o;d+=`L${y.toFixed(2)},${E.toFixed(2)}`,v++}else{const y=s+n[v]*o,E=i-a[v]*o;let T=v+1>p?f:v+1;if(1&u[T]){const F=s+n[T]*o,A=i-a[T]*o;d+=`Q${y.toFixed(2)},${E.toFixed(2)} ${F.toFixed(2)},${A.toFixed(2)}`,v=T+1}else{const F=(y+(s+n[T]*o))/2,A=(E+(i-a[T]*o))/2;d+=`Q${y.toFixed(2)},${E.toFixed(2)} ${F.toFixed(2)},${A.toFixed(2)}`,v=T}}d+="Z"}f=p+1}}return d}zr(r,s,i,o,n){const a=r.codePointAt(0)||0,h=this.ie(s,a);let u=null;return s.glyf&&s.glyf[h]!==null?u=s.glyf[h]:m&&m.T&&m.T.glyf&&m.T.glyf.jt&&(u=m.T.glyf.jt(s,h),s.glyf&&u&&(s.glyf[h]=u)),this.Vr(s,u,i,o,n)}Ir(r,s,i,o,n,a,h,u){const d=i+(n-u*(h/s.head.unitsPerEm))/2,f=o+(a+.7*h)/2;return this.zr(r,s,d,f,h).toSVG()||null}}class xt{constructor(){c(this,"Pr");this.Pr=new vt}Ur(r){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
45
|
+
`,wt={enabled:!0,characters:" .:-=+*%@#",characterColor:[1,1,1,1],characterColorMode:"sampled",cellColor:[0,0,0,1],cellColorMode:"fixed",invert:!1,rotation:[0,0,0,255],flipHorizontally:!1,flipVertically:!1,brightnessRange:[0,255]};class W extends O{constructor(s,i,n){super(s,i,n,{...wt});c(this,"Rs");c(this,"Vs");c(this,"ks");c(this,"Is");c(this,"zs");c(this,"Es");this.Rs=new M(s.context,G,"precision lowp float;uniform sampler2D u_sketchTexture;uniform vec2 u_gridCellDimensions;uniform vec2 u_brightnessRange;varying vec2 v_uv;void main(){vec2 cellCenter=(floor(v_uv*u_gridCellDimensions)+vec2(0.5))/u_gridCellDimensions;vec4 color=texture2D(u_sketchTexture,cellCenter);float brightness=dot(color.rgb,vec3(0.299,0.587,0.114));float brightnessValue=brightness*255.0;if(brightnessValue>=u_brightnessRange.x&&brightnessValue<=u_brightnessRange.y){gl_FragColor=color;}else{gl_FragColor=vec4(0.0);}}"),this.Vs=new M(s.context,G,"precision lowp float;uniform sampler2D u_sampleTexture;uniform vec4 u_fillColor;uniform bool u_useFixedColor;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){if(u_useFixedColor){gl_FragColor=u_fillColor;}else{gl_FragColor=sampleColor;}}else{gl_FragColor=vec4(0.0);}}"),this.Is=new M(s.context,G,"precision lowp float;uniform sampler2D u_sampleTexture;uniform bool u_invert;uniform bool u_flipHorizontally;uniform bool u_flipVertically;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){float invertValue=u_invert ? 1.0 : 0.0;float flipHValue=u_flipHorizontally ? 1.0 : 0.0;float flipVValue=u_flipVertically ? 1.0 : 0.0;gl_FragColor=vec4(invertValue,flipHValue,flipVValue,1.0);}else{gl_FragColor=vec4(0.0);}}"),this.zs=new M(s.context,G,"precision lowp float;uniform sampler2D u_sampleTexture;uniform vec4 u_rotationColor;varying vec2 v_uv;void main(){vec4 sampleColor=texture2D(u_sampleTexture,v_uv);if(sampleColor.a>0.0){gl_FragColor=u_rotationColor;}else{gl_FragColor=vec4(0.0);}}"),this.ks=new M(s.context,G,"precision lowp float;uniform sampler2D u_colorSampleFramebuffer;uniform sampler2D u_charPaletteTexture;uniform vec2 u_charPaletteSize;uniform vec2 u_brightnessRange;varying vec2 v_uv;void main(){vec4 color=texture2D(u_colorSampleFramebuffer,v_uv);if(color.a==0.0){gl_FragColor=vec4(0.0);return;}float brightness=dot(color.rgb,vec3(0.299,0.587,0.114))*255.0;vec2 range=u_brightnessRange;if(brightness<range.x||brightness>range.y){gl_FragColor=vec4(0.0);return;}float t=(brightness-range.x)/(range.y-range.x);float idx=clamp(floor(t*u_charPaletteSize.x),0.0,u_charPaletteSize.x-1.0);vec3 charColor=texture2D(u_charPaletteTexture,vec2((idx+0.5)/u_charPaletteSize.x,0.0)).rgb;gl_FragColor=vec4(charColor,1.0);}"),this.Es=this.ve.Ut(this.ps.cols,this.ps.rows)}Gs(s){const i=this.ps.cols,n=this.ps.rows;this.Es.begin(),this.ve.jt(),this.ve.yt(this.Rs),this.ve.Et("u_sketchTexture",s),this.ve.Et("u_gridCellDimensions",[i,n]),this.ve.Et("u_brightnessRange",this.l.brightnessRange),this.ve.Gt(0,0,i,n),this.Es.end(),this._s.begin(),this.ve.jt(),this.ve.yt(this.Vs),this.ve.Et("u_sampleTexture",this.Es),this.ve.Et("u_fillColor",this.l.characterColor),this.ve.Et("u_useFixedColor",this.l.characterColorMode==="fixed"),this.ve.Gt(0,0,i,n),this._s.end(),this.vs.begin(),this.ve.jt(),this.ve.yt(this.Vs),this.ve.Et("u_sampleTexture",this.Es),this.ve.Et("u_fillColor",this.l.cellColor),this.ve.Et("u_useFixedColor",this.l.cellColorMode==="fixed"),this.ve.Gt(0,0,i,n),this.vs.end(),this.ws.begin(),this.ve.jt(),this.ve.yt(this.Is),this.ve.Et("u_sampleTexture",this.Es),this.ve.Et("u_invert",this.l.invert),this.ve.Et("u_flipHorizontally",this.l.flipHorizontally),this.ve.Et("u_flipVertically",this.l.flipVertically),this.ve.Gt(0,0,i,n),this.ws.end(),this.bs.begin(),this.ve.jt(),this.ve.yt(this.zs),this.ve.Et("u_sampleTexture",this.Es),this.ve.Et("u_rotationColor",this.l.rotation),this.ve.Gt(0,0,i,n),this.bs.end(),this.gs.begin(),this.ve.jt(),this.ve.yt(this.ks),this.ve.Et("u_colorSampleFramebuffer",this.Es),this.ve.Et("u_charPaletteTexture",this.Fs.texture),this.ve.Et("u_charPaletteSize",[this.Fs.colors.length,1]),this.ve.Et("u_brightnessRange",this.l.brightnessRange),this.ve.Gt(0,0,i,n),this.gs.end()}ss(){super.ss(),this.Es.resize(this.ps.cols,this.ps.rows)}brightnessRange(s){C.m(Array.isArray(s)&&s.length===2&&s.every(i=>typeof i=="number"&&i>=0&&i<=255),"Brightness range must be an array of two numbers between 0 and 255.",{method:"brightnessRange",providedValue:s})&&(this.l.brightnessRange=s)}}const Ct=Object.freeze(Object.defineProperty({__proto__:null,TextmodeBrightnessConverter:W,TextmodeConverter:S,TextmodeFeatureConverter:O},Symbol.toStringTag,{value:"Module"}));class rt{constructor(r,s,i){c(this,"ve");c(this,"Te");c(this,"ps");c(this,"Ps");c(this,"As");c(this,"Us");c(this,"Ls");c(this,"js");c(this,"gs");c(this,"_s");c(this,"vs");c(this,"bs");c(this,"ws");this.ve=r,this.Te=s,this.ps=i,this.js=this.ve.It(B,"precision mediump float;uniform sampler2D u_characterTexture;uniform vec2 u_charsetDimensions;uniform sampler2D u_primaryColorTexture;uniform sampler2D u_secondaryColorTexture;uniform sampler2D u_transformTexture;uniform sampler2D u_asciiCharacterTexture;uniform sampler2D u_rotationTexture;uniform sampler2D u_captureTexture;uniform vec2 u_captureDimensions;uniform int u_backgroundMode;uniform vec2 u_gridCellDimensions;uniform vec2 u_gridPixelDimensions;mat2 rotate2D(float angle){float s=sin(angle);float c=cos(angle);return mat2(c,-s,s,c);}void main(){vec2 adjustedCoord=gl_FragCoord.xy/u_gridPixelDimensions;vec2 gridCoord=adjustedCoord*u_gridCellDimensions;vec2 cellCoord=floor(gridCoord);vec2 charIndexTexCoord=(cellCoord+0.5)/u_gridCellDimensions;vec4 primaryColor=texture2D(u_primaryColorTexture,charIndexTexCoord);vec4 secondaryColor=texture2D(u_secondaryColorTexture,charIndexTexCoord);vec4 transformColor=texture2D(u_transformTexture,charIndexTexCoord);bool isInverted=transformColor.r>0.5;bool flipHorizontal=transformColor.g>0.5;bool flipVertical=transformColor.b>0.5;vec4 encodedIndexVec=texture2D(u_asciiCharacterTexture,charIndexTexCoord);if(encodedIndexVec.a<0.01){gl_FragColor=(u_backgroundMode==0)? vec4(0.0):texture2D(u_captureTexture,gl_FragCoord.xy/u_captureDimensions);return;}int charIndex=int(encodedIndexVec.r*255.0+0.5)+int(encodedIndexVec.g*255.0+0.5)*256;int charCol=int(mod(float(charIndex),u_charsetDimensions.x));int charRow=charIndex/int(u_charsetDimensions.x);float flippedRow=(u_charsetDimensions.y-1.0)-float(charRow);vec2 charCoord=vec2(float(charCol),flippedRow)/u_charsetDimensions;vec4 rotationColor=texture2D(u_rotationTexture,charIndexTexCoord);float scaledAngle=rotationColor.r*255.0+rotationColor.g;float rotationAngle=(scaledAngle*360.0/255.0)*0.017453292;vec2 fractionalPart=fract(gridCoord)-0.5;if(flipHorizontal)fractionalPart.x=-fractionalPart.x;if(flipVertical)fractionalPart.y=-fractionalPart.y;fractionalPart=rotate2D(rotationAngle)*fractionalPart+0.5;vec2 cellSize=1.0/u_charsetDimensions;vec2 texCoord=charCoord+fractionalPart*cellSize;vec2 cellMax=charCoord+cellSize;if(any(lessThan(texCoord,charCoord))||any(greaterThan(texCoord,cellMax))){gl_FragColor=isInverted ? primaryColor : secondaryColor;return;}vec4 charTexel=texture2D(u_characterTexture,texCoord);if(isInverted)charTexel.rgb=1.0-charTexel.rgb;gl_FragColor=mix(secondaryColor,primaryColor,charTexel);}"),this.As=new W(r,s,i),this.Us=new S(r,s,i),this.Ps=[this.As,this.Us],this.gs=this.ve.Ut(i.cols,i.rows),this._s=this.ve.Ut(i.cols,i.rows),this.vs=this.ve.Ut(i.cols,i.rows),this.bs=this.ve.Ut(i.cols,i.rows),this.ws=this.ve.Ut(i.cols,i.rows),this.Ls=this.ve.Ut(this.ps.width,this.ps.height)}Hs(r){for(const i of this.Ps)i.options.enabled&&i instanceof O&&i.Gs(r);const s=(i,n)=>{i.begin(),this.ve.jt();for(const o of this.Ps)o.options.enabled&&this.ve.Ot(n(o),0,0);i.end()};s(this.gs,i=>i.characterFramebuffer),s(this._s,i=>i.primaryColorFramebuffer),s(this.vs,i=>i.secondaryColorFramebuffer),s(this.bs,i=>i.rotationFramebuffer),s(this.ws,i=>i.transformFramebuffer),this.Ls.begin(),this.ve.jt(),this.ve.yt(this.js),this.ve.Et("u_characterTexture",this.Te.fontFramebuffer),this.ve.Et("u_charsetDimensions",[this.Te.textureColumns,this.Te.textureRows]),this.ve.Et("u_asciiCharacterTexture",this.gs.texture),this.ve.Et("u_primaryColorTexture",this._s.texture),this.ve.Et("u_secondaryColorTexture",this.vs.texture),this.ve.Et("u_transformTexture",this.ws.texture),this.ve.Et("u_rotationTexture",this.bs.texture),this.ve.Et("u_captureTexture",r.texture),this.ve.Et("u_backgroundMode",!1),this.ve.Et("u_captureDimensions",[r.width,r.height]),this.ve.Et("u_gridCellDimensions",[this.ps.cols,this.ps.rows]),this.ve.Et("u_gridPixelDimensions",[this.ps.width,this.ps.height]),this.ve.Gt(0,0,this.Ls.width,this.Ls.height),this.Ls.end()}add(r){if(!C.m(r==="brightness"||r==="custom",'Converter type must be either "brightness" or "custom".',{method:"add",providedValue:r}))return;let s;return s=r==="brightness"?new W(this.ve,this.Te,this.ps):new S(this.ve,this.Te,this.ps),this.Ps.push(s),s}remove(r){if(!C.m(r instanceof S,"Parameter must be a TextmodeConverter instance.",{method:"remove",providedValue:r}))return;const s=this.Ps.indexOf(r);C.m(s!==-1,"Converter instance not found in pipeline.",{method:"remove",providedValue:r,convertersCount:this.Ps.length})&&this.Ps.splice(s,1)}swap(r,s){const i=(a,u)=>{if(typeof a=="number")return C.m(Number.isInteger(a)&&a>=0&&a<this.Ps.length,u+" index must be a valid integer within the converter array bounds.",{method:"swap",providedValue:a,convertersCount:this.Ps.length})?a:null;if(a instanceof S){const d=this.Ps.indexOf(a);return C.m(d!==-1,u+" converter instance not found in pipeline.",{method:"swap",providedValue:a,convertersCount:this.Ps.length})?d:null}return C.m(!1,u+" parameter must be either an integer index or a TextmodeConverter instance.",{method:"swap",providedValue:a}),null},n=i(r,"First"),o=i(s,"Second");if(n===null||o===null||!C.m(n!==o,"Cannot swap a converter with itself.",{method:"swap",firstIndex:n,secondIndex:o}))return;const h=this.Ps[n];this.Ps[n]=this.Ps[o],this.Ps[o]=h}ss(){this.Ls.resize(this.ps.width,this.ps.height);const r=this.ps.cols,s=this.ps.rows;this.gs.resize(r,s),this._s.resize(r,s),this.vs.resize(r,s),this.bs.resize(r,s),this.ws.resize(r,s);for(const i of this.Ps)i.ss()}hasEnabledConverters(){return this.Ps.some(r=>r.options.enabled)}disable(){for(const r of this.Ps)r.disable()}enable(){for(const r of this.Ps)r.enable()}G(){for(const r of this.Ps)r.G();this.gs.G(),this._s.G(),this.vs.G(),this.bs.G(),this.ws.G(),this.Ls.G(),this.js.G()}get texture(){return this.Ls}get characterFramebuffer(){return this.gs}get primaryColorFramebuffer(){return this._s}get secondaryColorFramebuffer(){return this.vs}get rotationFramebuffer(){return this.bs}get transformFramebuffer(){return this.ws}get brightness(){return this.As}get custom(){return this.Us}}const yt=l=>class extends l{fill(r,s,i,n){this.ve.$t(r,s,i,n)}stroke(r,s,i,n){this.ve.Ft(r,s,i,n)}strokeWeight(r){this.ve.Tt(r)}noStroke(){this.ve.Mt()}noFill(){this.ve.St()}rotate(r){this.ve.Dt(r)}push(){this.ve.Rt()}pop(){this.ve.Vt()}rect(r,s,i=1,n=1){this.ve.Gt(r,s,i,n)}line(r,s,i,n){this.ve.At(r,s,i,n)}background(r,s=r,i=r,n=255){this.ve.Lt(r,s,i,n)}createShader(r,s){return this.ve.It(r,s)}createFilterShader(r){return this.ve.zt(r)}shader(r){this.ve.yt(r)}setUniform(r,s){this.ve.Et(r,s)}};class N{Os(r){const s=r.characterFramebuffer,i=r.primaryColorFramebuffer,n=r.secondaryColorFramebuffer,o=r.transformFramebuffer,h=r.rotationFramebuffer;return s==null||s.loadPixels(),i==null||i.loadPixels(),n==null||n.loadPixels(),o==null||o.loadPixels(),h==null||h.loadPixels(),{characterPixels:(s==null?void 0:s.pixels)||new Uint8Array(0),primaryColorPixels:(i==null?void 0:i.pixels)||new Uint8Array(0),secondaryColorPixels:(n==null?void 0:n.pixels)||new Uint8Array(0),transformPixels:(o==null?void 0:o.pixels)||new Uint8Array(0),rotationPixels:(h==null?void 0:h.pixels)||new Uint8Array(0)}}Bs(r,s){return r[s]+(r[s+1]<<8)}Ws(r,s){return{r:r[s],g:r[s+1],b:r[s+2],a:r[s+3]}}}class z{Ns(r,s){return new Blob([r],{type:s})}Xs(r,s,i){try{const n=this.Ns(r,i),o=URL.createObjectURL(n),h=document.createElement("a");h.href=o,h.download=s,h.style.display="none",h.rel="noopener",document.body.appendChild(h),h.click(),document.body.removeChild(h),URL.revokeObjectURL(o)}catch(n){throw console.error("Failed to download file:",n),Error("File download failed: "+(n instanceof Error?n.message:"Unknown error"))}}qs(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Ys(){const r=new Date;return{date:r.toISOString().split("T")[0],time:r.toTimeString().split(" ")[0].replace(/:/g,"-")}}Qs(r){return r.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Zs(){return"'textmode-export'-"+this.qs()}}class _t extends N{Js(r,s,i){const n=r[i]===255,o=r[i+1]===255,h=r[i+2]===255,a=s[i],u=s[i+1];return{isInverted:n,flipHorizontal:o,flipVertical:h,rotation:Math.round(360*(a+u/255)/255*100)/100}}Ks(r,s,i){return{x:r,y:s,cellX:r*i.cellWidth,cellY:s*i.cellHeight}}tr(r,s){const i=[];let n=0;for(let o=0;o<s.rows;o++)for(let h=0;h<s.cols;h++){const a=4*n,u=this.Bs(r.characterPixels,a);let d=this.Ws(r.primaryColorPixels,a),f=this.Ws(r.secondaryColorPixels,a);const p=this.Js(r.transformPixels,r.rotationPixels,a);if(p.isInverted){const x=d;d=f,f=x}const g=this.Ks(h,o,s);i.push({charIndex:u,primaryColor:d,secondaryColor:f,transform:p,position:g}),n++}return i}}class Tt{er(r,s){const i=r.cmap;for(const n of i.tables)if(n.format===4){for(let o=0;o<n.startCount.length;o++)if(s>=n.startCount[o]&&s<=n.endCount[o]){if(n.idRangeOffset[o]===0)return s+n.idDelta[o]&65535;{const h=n.idRangeOffset[o]/2+(s-n.startCount[o])-(n.startCount.length-o);if(h>=0&&h<n.glyphIdArray.length){const a=n.glyphIdArray[h];if(a!==0)return a+n.idDelta[o]&65535}}}}return 0}sr(r,s,i,n,o){const h=o/r.head.unitsPerEm;return{getBoundingBox:()=>({x1:i+s.xMin*h,y1:n+-s.yMax*h,x2:i+s.xMax*h,y2:n+-s.yMin*h}),toSVG:()=>this.rr(s,i,n,h)}}rr(r,s,i,n){if(!r||!r.xs)return"";const{xs:o,ys:h,endPts:a,flags:u}=r;if(!(o&&h&&a&&u))return"";let d="",f=0;for(let p=0;p<a.length;p++){const g=a[p];if(!(g<f)){if(g>=f){const x=s+o[f]*n,v=i-h[f]*n;d+=`M${x.toFixed(2)},${v.toFixed(2)}`;let m=f+1;for(;m<=g;)if(1&u[m]){const T=s+o[m]*n,y=i-h[m]*n;d+=`L${T.toFixed(2)},${y.toFixed(2)}`,m++}else{const T=s+o[m]*n,y=i-h[m]*n;let _=m+1>g?f:m+1;if(1&u[_]){const F=s+o[_]*n,A=i-h[_]*n;d+=`Q${T.toFixed(2)},${y.toFixed(2)} ${F.toFixed(2)},${A.toFixed(2)}`,m=_+1}else{const F=(T+(s+o[_]*n))/2,A=(y+(i-h[_]*n))/2;d+=`Q${T.toFixed(2)},${y.toFixed(2)} ${F.toFixed(2)},${A.toFixed(2)}`,m=_}}d+="Z"}f=g+1}}return d}ir(r,s,i,n,o){const h=r.codePointAt(0)||0,a=this.er(s,h);let u=null;return s.glyf&&s.glyf[a]!==null?u=s.glyf[a]:R&&R.T&&R.T.glyf&&R.T.glyf.Bt&&(u=R.T.glyf.Bt(s,a),s.glyf&&u&&(s.glyf[a]=u)),this.sr(s,u,i,n,o)}nr(r,s,i,n,o,h,a,u){const d=i+(o-u*(a/s.head.unitsPerEm))/2,f=n+(h+.7*a)/2;return this.ir(r,s,d,f,a).toSVG()||null}}class Et{constructor(){c(this,"ar");this.ar=new Tt}hr(r){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
46
46
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
47
47
|
<svg width="${r.width}" height="${r.height}" viewBox="0 0 ${r.width} ${r.height}"
|
|
48
48
|
xmlns="http://www.w3.org/2000/svg" version="1.1">
|
|
49
49
|
<title>textmode art generated via textmode.js</title>
|
|
50
|
-
<desc>textmode art visualization generated by textmode.js library</desc>`}
|
|
50
|
+
<desc>textmode art visualization generated by textmode.js library</desc>`}lr(){return`
|
|
51
51
|
</g>
|
|
52
|
-
</svg>`}
|
|
53
|
-
<rect width="${r.width}" height="${r.height}" fill="${
|
|
54
|
-
<rect x="${
|
|
55
|
-
<rect x="${
|
|
56
|
-
<path id="${`path-${r.charIndex}-${r.position.cellX}-${r.position.cellY}`.replace(/\./g,"-")}" d="${
|
|
57
|
-
<path d="${
|
|
58
|
-
<g${
|
|
59
|
-
</g>`):
|
|
60
|
-
<g id="ascii-cells">`;for(const
|
|
61
|
-
`).replace(/[ \t]+$/gm,"")}}class
|
|
52
|
+
</svg>`}cr(r,s){if(!s.includeBackgroundRectangles)return"";const i=s.backgroundColor,n=`rgba(${i[0]},${i[1]},${i[2]},${i[3]/255})`;return`
|
|
53
|
+
<rect width="${r.width}" height="${r.height}" fill="${n}" />`}ur(r){return`rgba(${r.r},${r.g},${r.b},${r.a/255})`}dr(r,s){const{transform:i,position:n}=r,o=n.cellX+s.cellWidth/2,h=n.cellY+s.cellHeight/2,a=[];if(i.flipHorizontal||i.flipVertical){const u=i.flipHorizontal?-1:1,d=i.flipVertical?-1:1;a.push(`translate(${o} ${h})`),a.push(`scale(${u} ${d})`),a.push(`translate(${-o} ${-h})`)}return i.rotation&&a.push(`rotate(${i.rotation} ${o} ${h})`),a.length?` transform="${a.join(" ")}"`:""}pr(r,s,i){if(!i.includeBackgroundRectangles||r.secondaryColor.a===0)return"";const{position:n}=r,o=this.ur(r.secondaryColor);return i.drawMode==="stroke"?`
|
|
54
|
+
<rect x="${n.cellX}" y="${n.cellY}" width="${s.cellWidth}" height="${s.cellHeight}" stroke="${o}" fill="none" stroke-width="${i.strokeWidth}" />`:`
|
|
55
|
+
<rect x="${n.cellX}" y="${n.cellY}" width="${s.cellWidth}" height="${s.cellHeight}" fill="${o}" />`}ir(r,s,i,n){const o=i.characters[r.charIndex];if(!o)return"";const h=this.ar.nr(o.character,i.font,r.position.cellX,r.position.cellY,s.cellWidth,s.cellHeight,i.fontSize,o.advanceWidth);if(!h)return"";const a=this.ur(r.primaryColor);return n.drawMode==="stroke"?`
|
|
56
|
+
<path id="${`path-${r.charIndex}-${r.position.cellX}-${r.position.cellY}`.replace(/\./g,"-")}" d="${h}" stroke="${a}" stroke-width="${n.strokeWidth}" fill="none" />`:`
|
|
57
|
+
<path d="${h}" fill="${a}" />`}mr(r,s,i,n){let o="";o+=this.pr(r,s,n);const h=this.dr(r,s),a=this.ir(r,s,i,n);return a&&(h?(o+=`
|
|
58
|
+
<g${h}>`,o+=a,o+=`
|
|
59
|
+
</g>`):o+=a),o}gr(r,s,i,n){let o=this.hr(s);o+=this.cr(s,n),o+=`
|
|
60
|
+
<g id="ascii-cells">`;for(const h of r)o+=this.mr(h,s,i,n);return o+=this.lr(),o}_r(r){return r.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\n\s*\n/g,`
|
|
61
|
+
`).replace(/[ \t]+$/gm,"")}}class Rt extends z{vr(r){return this.Ns(r,"image/svg+xml;charset=utf-8")}br(r,s){this.Xs(r,this.Qs(s)+".svg","image/svg+xml;charset=utf-8")}wr(r,s){this.br(r,s||this.Zs())}}class st{constructor(){c(this,"Cr");c(this,"yr");c(this,"$r");this.Cr=new _t,this.yr=new Et,this.$r=new Rt}Fr(r){return{includeBackgroundRectangles:r.includeBackgroundRectangles??!0,drawMode:r.drawMode??"fill",strokeWidth:r.strokeWidth??1,backgroundColor:r.backgroundColor??[0,0,0,0]}}Tr(r,s={}){const i=this.Fr(s),n=this.Cr.Os(r.pipeline),o=this.Cr.tr(n,r.grid),h=this.yr.gr(o,r.grid,r.font,i);return this.yr._r(h)}wr(r,s={}){const i=this.Tr(r,s),n=s.filename||this.$r.Zs();this.$r.wr(i,n)}}class Ft extends N{Mr(r,s,i,n=" "){var a;const o=[];let h=0;for(let u=0;u<s.rows;u++){const d=[];for(let f=0;f<s.cols;f++){const p=4*h,g=this.Bs(r.characterPixels,p),x=((a=i.characters[g])==null?void 0:a.character)||n;d.push(x),h++}o.push(d)}return o}}class Mt{Sr(r,s){const i=[];for(const o of r){let h=o.join("");s.preserveTrailingSpaces||(h=h.replace(/\s+$/,"")),i.push(h)}const n=s.lineEnding==="crlf"?`\r
|
|
62
62
|
`:`
|
|
63
|
-
`;return i.join(
|
|
63
|
+
`;return i.join(n)}}class At extends z{Dr(r,s){const i=this.Rr(s);this.Xs(r,i,"text/plain;charset=utf-8")}Rr(r){let s=this.Qs(r);return s===".txt"||s.length<=4?this.Zs():s}}class it{constructor(){c(this,"Cr");c(this,"yr");c(this,"$r");this.Cr=new Ft,this.yr=new Mt,this.$r=new At}Fr(r){return{preserveTrailingSpaces:r.preserveTrailingSpaces??!1,lineEnding:r.lineEnding??"lf",emptyCharacter:r.emptyCharacter??" "}}Vr(r,s={}){const i=this.Fr(s),n=this.Cr.Os(r.pipeline),o=this.Cr.Mr(n,r.grid,r.font,i.emptyCharacter);return this.yr.Sr(o,i)}Dr(r,s={}){const i=this.Vr(r,s),n=s.filename||this.$r.Zs();this.$r.Dr(i,n)}}class Pt extends N{kr(r,s=1,i="transparent"){const n=r.canvas;if(s===1&&i==="transparent")return n;const o=document.createElement("canvas"),h=o.getContext("2d"),a=Math.round(n.width*s),u=Math.round(n.height*s);return o.width=a,o.height=u,i!=="transparent"&&(h.fillStyle=i,h.fillRect(0,0,a,u)),h.imageSmoothingEnabled=!1,h.drawImage(n,0,0,n.width,n.height,0,0,a,u),o}}class Ut{Ir(r,s){const i=this.zr(s.format);return s.format==="png"?r.toDataURL(i):r.toDataURL(i,s.quality)}async Er(r,s){return new Promise((i,n)=>{const o=this.zr(s.format),h=a=>{a?i(a):n(Error(`Failed to generate ${s.format.toUpperCase()} blob`))};s.format==="png"?r.toBlob(h,o):r.toBlob(h,o,s.quality)})}zr(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 Dt={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},nt={png:".png",jpg:".jpg",webp:".webp"};class St extends z{Gr(r,s,i){this.Pr(r,this.Qs(s)+nt[i])}Pr(r,s){const i=URL.createObjectURL(r);try{const n=document.createElement("a");n.href=i,n.download=s,n.style.display="none",n.rel="noopener",document.body.appendChild(n),n.click(),document.body.removeChild(n)}finally{URL.revokeObjectURL(i)}}Ar(r){return r in Dt&&r in nt}}class $t{constructor(){c(this,"Cr");c(this,"yr");c(this,"$r");this.Cr=new Pt,this.yr=new Ut,this.$r=new St}Fr(r){return{format:r.format??"png",quality:r.quality??1,scale:r.scale??1,backgroundColor:r.backgroundColor??"transparent"}}Ur(r){if(console.log("Validating image export options:",r),!this.$r.Ar(r.format))throw Error(`Saving '${r.format}' files is not supported`);if(r.quality<0||r.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(r.scale<=0)throw Error("Scale factor must be greater than 0");r.scale>10&&console.warn("Large scale factors may result in very large files and slow performance"),r.format==="jpg"&&r.backgroundColor==="transparent"&&(r.backgroundColor="black")}Lr(r,s={}){const i=this.Fr(s);if(this.Ur(i),i.scale===1&&i.backgroundColor==="transparent")return this.yr.Ir(r.canvas,i);const n=this.Cr.kr(r,i.scale,i.backgroundColor);return this.yr.Ir(n,i)}async Er(r,s={}){const i=this.Fr(s);if(this.Ur(i),i.scale===1&&i.backgroundColor==="transparent")return await this.yr.Er(r.canvas,i);const n=this.Cr.kr(r,i.scale,i.backgroundColor);return await this.yr.Er(n,i)}async Gr(r,s={}){const i=await this.Er(r,s),n=s.format??"png",o=s.filename||this.$r.Zs();this.$r.Gr(i,o,n)}}const It=l=>class extends l{toString(r={}){return new it().Vr({pipeline:this.jr,grid:this.ps,font:this.Te},r)}saveStrings(r={}){new it().Dr({pipeline:this.jr,grid:this.ps,font:this.Te},r)}toSVG(r={}){return new st().Tr(this,r)}saveSVG(r={}){new st().wr(this,r)}async saveCanvas(r,s="png",i={}){await new $t().Gr(this.Ye,{...i,filename:r,format:s})}},Gt=l=>class extends l{async loadFont(r){return this.Te.Oe(r).then(()=>{const s=this.Te.maxGlyphDimensions;this.ps.Ke(s.width,s.height),this.jr.ss()})}fontSize(r){if(!C.m(typeof r=="number"&&r>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:r})||this.Te.fontSize===r)return;this.Te.He(r);const s=this.Te.maxGlyphDimensions;this.ps.Ke(s.width,s.height),this.jr.ss(),this.ve.Ht()}},kt=l=>class extends l{addConverter(r){return this.jr.add(r)}removeConverter(r){this.jr.remove(r)}};class Lt{constructor(){c(this,"ve");c(this,"Te");c(this,"jr");c(this,"Ye");c(this,"ps")}}class H extends function(s,...i){return i.reduce((n,o)=>o(n),s)}(Lt,yt,It,Gt,kt){constructor(s=null,i={}){super();c(this,"ns");c(this,"Hr");c(this,"ls");c(this,"Or");c(this,"Br");c(this,"Wr",null);c(this,"Nr",0);c(this,"Xr");c(this,"qr",!0);c(this,"Yr",0);c(this,"Qr",0);c(this,"Zr",0);c(this,"Jr",[]);c(this,"Kr",10);c(this,"ti",!1);c(this,"ei",!1);c(this,"si",()=>{});c(this,"ri",()=>{});c(this,"ii");this.ns=s,this.ei=s===null,this.Or=i.renderMode??"auto",this.Br=i.frameRate??60,this.Xr=1e3/this.Br}static async create(s=null,i={}){const n=new this(s,i),o=n.ei?i:void 0;let h,a;n.Ye=new et(n.ns,n.ei,o),n.ve=new lt(n.Ye.fs()),n.ei?(h=i.width||800,a=i.height||600):(h=n.Ye.width||800,a=n.Ye.height||600),n.Hr=n.ve.Ut(h,a),n.Te=new K(n.ve,i.fontSize??16),await n.Te.Ue(i.fontSource);const u=n.Te.maxGlyphDimensions;return n.ps=new tt(n.Ye.canvas,u.width,u.height),n.jr=new rt(n.ve,n.Te,n.ps),n.ni(),n.oi(),n}ni(){this.ii=()=>{this.ei?this.ri():this.ai()},window.addEventListener("resize",this.ii),window.ResizeObserver&&this.ns&&!this.ei&&(this.ls=new ResizeObserver(()=>{this.ai()}),this.ls.observe(this.ns))}render(){this.hi(),this.Zr++,this.ti?console.warn("Cannot render: Required resources have been disposed"):(this.ei?(this.Hr.begin(),this.si(),this.Hr.end()):this.Hr.update(this.ns),this.jr.hasEnabledConverters()?(this.jr.Hs(this.Hr),this.ve.Lt(0),this.ve.Ot(this.jr.texture,this.ps.offsetX,this.ps.offsetY,this.jr.texture.width,this.jr.texture.height)):(this.ve.jt(),this.ve.Ot(this.Hr,this.ps.offsetX,this.ps.offsetY,this.Hr.width,this.Hr.height)))}ai(){this.Ye.ss(),this.Hr.resize(this.Ye.width,this.Ye.height),this.ps.ss(),this.jr.ss(),this.ve.Ht(),this.Or!=="manual"&&this.render()}oi(){if(this.Or!=="auto"||!this.qr)return;this.Nr=performance.now();const s=i=>{if(!this.qr)return void(this.Wr=null);const n=i-this.Nr;n>=this.Xr&&(this.render(),this.Nr=i-n%this.Xr),this.qr&&(this.Wr=requestAnimationFrame(s))};this.Wr=requestAnimationFrame(s)}hi(){const s=performance.now();if(this.Qr>0){const i=s-this.Qr;this.Jr.push(i),this.Jr.length>this.Kr&&this.Jr.shift();const n=this.Jr.reduce((o,h)=>o+h,0)/this.Jr.length;this.Yr=1e3/n}this.Qr=s}li(){this.Wr&&(cancelAnimationFrame(this.Wr),this.Wr=null)}renderMode(s){this.Or!==s&&(this.li(),this.Or=s,s==="auto"&&this.qr&&this.oi())}frameRate(s){if(s===void 0)return this.Yr;this.Br=s,this.Xr=1e3/s,this.Or==="auto"&&this.qr&&(this.li(),this.oi())}noLoop(){this.qr&&(this.qr=!1,this.Wr&&(cancelAnimationFrame(this.Wr),this.Wr=null))}loop(){this.qr||(this.qr=!0,this.Or==="auto"&&this.oi())}redraw(s=1){if(C.m(typeof s=="number"&&s>0&&Number.isInteger(s),"Redraw count must be a positive integer.",{method:"redraw",providedValue:s}))for(let i=0;i<s;i++)this.render()}isLooping(){return this.Or==="auto"&&this.qr}draw(s){this.si=s}windowResized(s){this.ri=s}resizeCanvas(s,i){this.ei&&(this.Ye.ss(s,i),this.Hr.resize(this.Ye.width,this.Ye.height),this.ps.ss(),this.jr.ss(),this.ve.Ht(),this.Or!=="manual"&&this.render())}destroy(){this.ti||(this.li(),window.removeEventListener("resize",this.ii),this.ls&&this.ls.disconnect(),this.jr.G(),this.Te.G(),this.Hr.G(),this.ve.G(),this.ti=!0)}get grid(){return this.ps}get font(){return this.Te}get mode(){return this.Or}get pipeline(){return this.jr}get frameCount(){return this.Zr}set frameCount(s){this.Zr=s}get width(){return this.Ye.width}get height(){return this.Ye.height}get canvas(){return this.Ye}get isDisposed(){return this.ti}}class k{constructor(){throw new b("Textmode is a static class and cannot be instantiated.")}static async create(r,s={}){if(!(r==null||r instanceof HTMLCanvasElement||r instanceof HTMLVideoElement||typeof r=="object"))throw new b("First parameter must be HTMLCanvasElement, HTMLVideoElement, or options object.");if(typeof s!="object")throw new b("Second parameter must be an options object.");if(r instanceof HTMLCanvasElement||r instanceof HTMLVideoElement)return H.create(r,s);{const i=r||{};return H.create(null,i)}}static setErrorLevel(r){C._(r)}static get version(){return"0.1.8"}}const Yt=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),Bt=k.create,jt=k.setErrorLevel,Vt=k.version;w.TextmodeCanvas=et,w.TextmodeConversionPipeline=rt,w.TextmodeErrorLevel=U,w.TextmodeFont=K,w.TextmodeGrid=tt,w.Textmodifier=H,w.converters=Ct,w.create=Bt,w.default=k,w.export=Yt,w.setErrorLevel=jt,w.textmode=k,w.version=Vt,Object.defineProperties(w,{ci:{value:!0},[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={});
|
package/dist/types/Textmode.d.ts
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { Textmodifier, type TextmodeOptions
|
|
1
|
+
import { type TextmodeErrorLevel } from './errors';
|
|
2
|
+
import { Textmodifier, type TextmodeOptions } from './textmode/Textmodifier';
|
|
3
3
|
/**
|
|
4
4
|
* The main entry point for the `textmode.js` library.
|
|
5
5
|
*
|
|
6
|
-
* Provides static methods for creating
|
|
6
|
+
* Provides static methods for creating {@link Textmodifier} instances and managing global settings.
|
|
7
7
|
*/
|
|
8
8
|
export declare class Textmode {
|
|
9
|
+
private constructor();
|
|
9
10
|
/**
|
|
10
11
|
* Create a {@link Textmodifier} instance for textmode rendering.
|
|
11
12
|
*
|
|
12
|
-
* @param sourceOrOptions - Either
|
|
13
|
-
* @param opts - Optional configuration options *(only used when first parameter is a
|
|
14
|
-
* @returns A Promise that resolves to a Textmodifier instance.
|
|
13
|
+
* @param sourceOrOptions - Either a `HTMLCanvasElement` or `HTMLVideoElement` for capturing content, or options for standalone mode.
|
|
14
|
+
* @param opts - Optional configuration options *(only used when first parameter is a `HTMLCanvasElement` or `HTMLVideoElement`)*.
|
|
15
|
+
* @returns A Promise that resolves to a {@link Textmodifier} instance.
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
18
|
+
* Creating a {@link Textmodifier} for an existing canvas:
|
|
17
19
|
* ```javascript
|
|
18
|
-
* // Create a Textmodifier for an existing canvas
|
|
19
20
|
* const canvas = document.querySelector('canvas#myCanvas');
|
|
20
21
|
* const textmodifier = await textmode.create(canvas);
|
|
22
|
+
* ```
|
|
21
23
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
24
|
+
* @example
|
|
25
|
+
* Creating a {@link Textmodifier} for a video element:
|
|
26
|
+
* ```javascript
|
|
25
27
|
* const video = document.querySelector('video#myVideo');
|
|
26
28
|
* const textmodifier = await textmode.create(video);
|
|
29
|
+
* ```
|
|
27
30
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
+
* @example
|
|
32
|
+
* Creating a standalone {@link Textmodifier} with animation:
|
|
33
|
+
* ```javascript
|
|
31
34
|
* const t = await textmode.create({ width: 800, height: 600 });
|
|
32
35
|
*
|
|
33
36
|
* // Set up a draw loop for standalone usage
|
|
@@ -36,7 +39,7 @@ export declare class Textmode {
|
|
|
36
39
|
*
|
|
37
40
|
* const centerX = t.width / 2;
|
|
38
41
|
* const centerY = t.height / 2;
|
|
39
|
-
* const radius = Math.min(t.width, t
|
|
42
|
+
* const radius = Math.min(t.width, t.height) / 3;
|
|
40
43
|
* const speed = 0.02; // Adjust speed of rotation
|
|
41
44
|
*
|
|
42
45
|
* const angle = t.frameCount * speed;
|
|
@@ -49,25 +52,12 @@ export declare class Textmode {
|
|
|
49
52
|
* // Draw a rectangle with the fill color
|
|
50
53
|
* t.rect(x, y, 200, 150);
|
|
51
54
|
* });
|
|
52
|
-
*
|
|
53
|
-
* ////////
|
|
54
|
-
*
|
|
55
|
-
* // Resource management example
|
|
56
|
-
* const textmodifier = await textmode.create(canvas);
|
|
57
|
-
*
|
|
58
|
-
* // Use the textmodifier...
|
|
59
|
-
* textmodifier.render();
|
|
60
|
-
*
|
|
61
|
-
* // When done, completely clean up all resources
|
|
62
|
-
* textmodifier.destroy();
|
|
63
|
-
*
|
|
64
|
-
* // The instance is now safely disposed and ready for garbage collection
|
|
65
|
-
* console.log(textmodifier.isDestroyed); // true
|
|
66
55
|
* ```
|
|
67
56
|
*/
|
|
68
|
-
static create(sourceOrOptions?:
|
|
57
|
+
static create(sourceOrOptions?: HTMLCanvasElement | HTMLVideoElement | TextmodeOptions, opts?: TextmodeOptions): Promise<Textmodifier>;
|
|
69
58
|
/**
|
|
70
|
-
* Set the global error handling level for the library. This applies to all
|
|
59
|
+
* Set the global error handling level for the library. This applies to all {@link Textmodifier} instances present.
|
|
60
|
+
*
|
|
71
61
|
* @param level The error handling level to set.
|
|
72
62
|
*
|
|
73
63
|
* @example
|
|
@@ -78,7 +68,7 @@ export declare class Textmode {
|
|
|
78
68
|
*/
|
|
79
69
|
static setErrorLevel(level: TextmodeErrorLevel): void;
|
|
80
70
|
/**
|
|
81
|
-
* Returns the
|
|
71
|
+
* Returns the version of `textmode.js` being used.
|
|
82
72
|
*
|
|
83
73
|
* @example
|
|
84
74
|
* ```javascript
|
|
@@ -38,7 +38,7 @@ export type ImageExportOptions = {
|
|
|
38
38
|
/**
|
|
39
39
|
* Background color for formats that don't support transparency (`'jpg'`).
|
|
40
40
|
*
|
|
41
|
-
* Format
|
|
41
|
+
* **Format:** CSS color string.
|
|
42
42
|
*
|
|
43
43
|
* Default is `'black'`.
|
|
44
44
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TyprFont } from '../../textmode/font/types.ts';
|
|
1
|
+
import type { TyprFont } from '../../textmode/font/typr/types.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Handles SVG path generation for character glyphs.
|
|
4
4
|
* This class is responsible for converting font glyph data into SVG path strings.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { Textmodifier } from './textmode/Textmodifier';
|
|
|
3
3
|
export { TextmodeFont } from './textmode/font';
|
|
4
4
|
export { TextmodeCanvas } from './textmode/Canvas';
|
|
5
5
|
export { TextmodeGrid } from './textmode/Grid';
|
|
6
|
-
export type { TextmodeOptions,
|
|
6
|
+
export type { TextmodeOptions, TextmodeCaptureSource } from './textmode/Textmodifier';
|
|
7
7
|
export type { TextmodeCharacter } from './textmode/font';
|
|
8
8
|
/** All types related to export options for different formats. */
|
|
9
9
|
export * as export from './export';
|
|
@@ -12,6 +12,7 @@ export { TextmodeErrorLevel } from './errors/ErrorHandler';
|
|
|
12
12
|
/** Contains all converters that can be added to a rendering pipeline to shape the textmode output. */
|
|
13
13
|
export * as converters from './textmode/converters';
|
|
14
14
|
export { Textmode as textmode } from './Textmode';
|
|
15
|
+
export default Textmode;
|
|
15
16
|
/**
|
|
16
17
|
* Exports the create, setErrorLevel, and version functions from the Textmode class for UMD compatibility,
|
|
17
18
|
* so calls like `textmode.create()` can be used.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { TextmodeOptions } from "./Textmodifier";
|
|
2
2
|
/**
|
|
3
|
-
* Supported capture sources for textmode rendering
|
|
3
|
+
* Supported capture sources for textmode rendering.
|
|
4
4
|
*/
|
|
5
|
-
export type
|
|
5
|
+
export type TextmodeCaptureSource = HTMLCanvasElement | HTMLVideoElement;
|
|
6
6
|
/**
|
|
7
7
|
* TextmodeCanvas is a utility class that creates an overlay canvas
|
|
8
8
|
* for rendering textmode graphics on top of an existing HTML canvas or video element,
|
|
@@ -15,7 +15,7 @@ export declare class TextmodeCanvas {
|
|
|
15
15
|
private _isStandalone;
|
|
16
16
|
private _resizeObserver?;
|
|
17
17
|
onTransformChange?: () => void;
|
|
18
|
-
constructor(captureSource:
|
|
18
|
+
constructor(captureSource: TextmodeCaptureSource, isStandalone?: boolean, opts?: TextmodeOptions);
|
|
19
19
|
private _createCanvas;
|
|
20
20
|
private _positionOverlayCanvas;
|
|
21
21
|
$resize(width?: number, height?: number): void;
|
|
@@ -45,7 +45,6 @@ export declare class TextmodeConversionPipeline {
|
|
|
45
45
|
*/
|
|
46
46
|
/**
|
|
47
47
|
* Adds a new converter to the pipeline.
|
|
48
|
-
* @param name A unique name for the converter.
|
|
49
48
|
* @param type The type of converter to add. Can be either "brightness" or "custom".
|
|
50
49
|
* @returns The newly created {@link TextmodeConverter} instance or `void` if the addition failed.
|
|
51
50
|
*/
|
|
@@ -55,6 +54,12 @@ export declare class TextmodeConversionPipeline {
|
|
|
55
54
|
* @param converter The converter instance to remove.
|
|
56
55
|
*/
|
|
57
56
|
remove(converter: TextmodeConverter): void;
|
|
57
|
+
/**
|
|
58
|
+
* Swaps two converters in the pipeline.
|
|
59
|
+
* @param first Either an index *(integer)* or a {@link TextmodeConverter} instance.
|
|
60
|
+
* @param second Either an index *(integer)* or a {@link TextmodeConverter} instance.
|
|
61
|
+
*/
|
|
62
|
+
swap(first: number | TextmodeConverter, second: number | TextmodeConverter): void;
|
|
58
63
|
/**
|
|
59
64
|
* Resizes all internal framebuffers.
|
|
60
65
|
* @ignore
|
|
@@ -75,7 +80,7 @@ export declare class TextmodeConversionPipeline {
|
|
|
75
80
|
enable(): void;
|
|
76
81
|
/**
|
|
77
82
|
* Dispose of all resources used by this conversion pipeline.
|
|
78
|
-
*
|
|
83
|
+
* @ignore
|
|
79
84
|
*/
|
|
80
85
|
$dispose(): void;
|
|
81
86
|
/** Returns the framebuffer containing the textmode conversion result.*/
|