textmode.js 0.1.6-beta.6 → 0.1.7
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 +1197 -1168
- package/dist/textmode.esm.min.js +1237 -1208
- package/dist/textmode.umd.js +56 -18
- package/dist/textmode.umd.min.js +56 -18
- package/dist/types/errors/Error.d.ts +3 -5
- package/dist/types/errors/ErrorHandler.d.ts +3 -3
- package/dist/types/export/base/DataExtractor.d.ts +3 -3
- package/dist/types/export/base/FileHandler.d.ts +6 -6
- package/dist/types/export/image/ImageContentGenerator.d.ts +3 -3
- package/dist/types/export/image/ImageDataExtractor.d.ts +1 -1
- package/dist/types/export/image/ImageExporter.d.ts +8 -8
- package/dist/types/export/image/ImageFileHandler.d.ts +3 -15
- package/dist/types/export/svg/SVGContentGenerator.d.ts +11 -11
- package/dist/types/export/svg/SVGDataExtractor.d.ts +3 -3
- package/dist/types/export/svg/SVGExporter.d.ts +6 -6
- package/dist/types/export/svg/SVGFileHandler.d.ts +3 -3
- package/dist/types/export/svg/SVGPathGenerator.d.ts +5 -6
- package/dist/types/export/txt/TXTContentGenerator.d.ts +1 -1
- package/dist/types/export/txt/TXTDataExtractor.d.ts +1 -1
- package/dist/types/export/txt/TXTExporter.d.ts +6 -6
- package/dist/types/export/txt/TXTFileHandler.d.ts +2 -2
- package/dist/types/rendering/webgl/Framebuffer.d.ts +8 -8
- package/dist/types/rendering/webgl/Renderer.d.ts +35 -35
- package/dist/types/rendering/webgl/Shader.d.ts +14 -14
- package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +10 -10
- package/dist/types/rendering/webgl/geometries/Line.d.ts +1 -1
- package/dist/types/rendering/webgl/geometries/Rectangle.d.ts +2 -2
- package/dist/types/textmode/Canvas.d.ts +9 -7
- package/dist/types/textmode/ConversionPipeline.d.ts +23 -15
- package/dist/types/textmode/Grid.d.ts +6 -6
- package/dist/types/textmode/Textmodifier.d.ts +15 -16
- package/dist/types/textmode/converters/BrightnessConverter.d.ts +8 -8
- package/dist/types/textmode/converters/Converter.d.ts +5 -5
- package/dist/types/textmode/converters/FeatureConverter.d.ts +6 -6
- package/dist/types/textmode/font/TextmodeFont.d.ts +8 -8
- package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +1 -1
- package/package.json +1 -1
package/dist/textmode.umd.min.js
CHANGED
|
@@ -1,25 +1,63 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Bt=Object.defineProperty;var kt=(C,x,R)=>x in C?Bt(C,x,{enumerable:!0,configurable:!0,writable:!0,value:R}):C[x]=R;var c=(C,x,R)=>kt(C,typeof x!="symbol"?x+"":x,R);var t,e;t=this,e=function(C){class x extends Error{constructor(r,s={}){super(x.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[n
|
|
4
|
-
- ${
|
|
3
|
+
📋 Context:`;for(const[o,n]of Object.entries(s))i+=`
|
|
4
|
+
- ${o}: ${x.o(n)}`}return i+=`
|
|
5
5
|
|
|
6
|
-
`,
|
|
7
|
-
`,o}static o(i){if(i===null)return"null";if(i===void 0)return"undefined";if(typeof i=="string")return`"${i}"`;if(typeof i=="number"||typeof i=="boolean")return i+"";if(Array.isArray(i))return i.length===0?"[]":i.length<=5?`[${i.map(r=>x.o(r)).join(", ")}]`:`[${i.slice(0,3).map(r=>x.o(r)).join(", ")}, ... +${i.length-3} more]`;if(typeof i=="object"){const r=Object.keys(i);return r.length===0?"{}":r.length<=3?`{ ${r.map(o=>`${o}: ${x.o(i[o])}`).join(", ")} }`:`{ ${r.slice(0,2).map(o=>`${o}: ${x.o(i[o])}`).join(", ")}, ... +${r.length-2} more }`}return i+""}}var L=(c=>(c[c.SILENT=0]="SILENT",c[c.WARNING=1]="WARNING",c[c.ERROR=2]="ERROR",c[c.THROW=3]="THROW",c))(L||{});const D=class D{constructor(){l(this,"l",{u:3})}static m(){return D.h||(D.h=new D),D.h}p(s,i,r){const o="%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.u){case 0:return!1;case 1:return console.group(o,n),console.warn(x.i(s,i)),console.groupEnd(),!1;case 2:return console.group(o,n),console.error(x.i(s,i)),console.groupEnd(),!1;default:throw new x(s,r,i)}}validate(s,i,r){return!!s||(this.p(i,r),!1)}v(s){this.l.u=s}};l(D,"h",null);let k=D;const y=k.m(),X=new WeakMap;function P(c,s){X.set(c,s)}function W(c){return X.get(c)}class q{constructor(s,i,r=i,o={}){l(this,"_");l(this,"C");l(this,"F");l(this,"$");l(this,"M");l(this,"options");l(this,"D",null);l(this,"S",null);this._=s,this.$=i,this.M=r,this.options={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...o},this.F=this.createTexture(),this.C=s.createFramebuffer(),this.V()}R(s){const{_:i}=this,r=i.getParameter(i.FRAMEBUFFER_BINDING);i.bindFramebuffer(i.FRAMEBUFFER,this.C);try{return s()}finally{i.bindFramebuffer(i.FRAMEBUFFER,r)}}createTexture(){const{_:s}=this,i=s.createTexture();s.bindTexture(s.TEXTURE_2D,i);const r=this.options.filter==="linear"?s.LINEAR:s.NEAREST,o=this.options.wrap==="repeat"?s.REPEAT:s.CLAMP_TO_EDGE;return s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,r),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,r),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,o),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,o),this.k(),i}k(){const{_:s}=this,i=this.options.type==="float"?s.FLOAT:s.UNSIGNED_BYTE;s.texImage2D(s.TEXTURE_2D,0,s.RGBA,this.$,this.M,0,s.RGBA,i,null)}V(){const{_:s}=this;s.bindFramebuffer(s.FRAMEBUFFER,this.C),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,this.F,0),s.bindFramebuffer(s.FRAMEBUFFER,null)}update(s){const{_:i}=this;i.bindTexture(i.TEXTURE_2D,this.F),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,1),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,s),i.bindTexture(i.TEXTURE_2D,null)}I(s,i,r){const{_:o}=this;o.bindTexture(o.TEXTURE_2D,this.F),o.texImage2D(o.TEXTURE_2D,0,o.RGBA,i,r,0,o.RGBA,o.UNSIGNED_BYTE,s),o.bindTexture(o.TEXTURE_2D,null)}resize(s,i){const{_:r}=this;this.$=s,this.M=i,this.S=null,r.bindTexture(r.TEXTURE_2D,this.F),this.k(),r.bindTexture(r.TEXTURE_2D,null)}P(){const{_:s}=this;this.D={framebuffer:s.getParameter(s.FRAMEBUFFER_BINDING),viewport:s.getParameter(s.VIEWPORT)},s.bindFramebuffer(s.FRAMEBUFFER,this.C),s.viewport(0,0,this.$,this.M),P(s,[0,0,this.$,this.M])}end(){if(!this.D)return;const{_:s}=this;s.bindFramebuffer(s.FRAMEBUFFER,this.D.framebuffer),s.viewport(...this.D.viewport),P(s,this.D.viewport),this.D=null}A(){const{_:s}=this;this.S||(this.S=new Uint8Array(this.$*this.M*4)),this.R(()=>{s.readPixels(0,0,this.$,this.M,s.RGBA,s.UNSIGNED_BYTE,this.S)})}get(s,i,r,o){const{_:n}=this;if(s===void 0&&i===void 0){const h=new Uint8Array(this.$*this.M*4);return this.R(()=>(n.readPixels(0,0,this.$,this.M,n.RGBA,n.UNSIGNED_BYTE,h),h))}if(r===void 0&&o===void 0){(s<0||i<0||s>=this.$||i>=this.M)&&(console.warn("The x and y values passed to Framebuffer.get are outside of its range and will be clamped."),s=Math.max(0,Math.min(s,this.$-1)),i=Math.max(0,Math.min(i,this.M-1)));const h=new Uint8Array(4);return this.R(()=>(n.readPixels(s,i,1,1,n.RGBA,n.UNSIGNED_BYTE,h),[h[0],h[1],h[2],h[3]]))}{s=Math.max(0,Math.min(s,this.$-1)),i=Math.max(0,Math.min(i,this.M-1)),r=Math.max(1,Math.min(r,this.$-s)),o=Math.max(1,Math.min(o,this.M-i));const h=new Uint8Array(r*o*4);return this.R(()=>(n.readPixels(s,i,r,o,n.RGBA,n.UNSIGNED_BYTE,h),h))}}dispose(){this.C&&this._.deleteFramebuffer(this.C),this.F&&this._.deleteTexture(this.F)}get framebuffer(){return this.C}get texture(){return this.F}get width(){return this.$}get height(){return this.M}get U(){return this.S}}class E{constructor(s,i,r){l(this,"_");l(this,"G");l(this,"L",new Map);l(this,"O",new Map);l(this,"H",0);l(this,"j");this._=s,this.G=this.createProgram(i,r),this.j=s.getParameter(s.MAX_TEXTURE_IMAGE_UNITS),this.W()}W(){const s=this._.getProgramParameter(this.G,this._.ACTIVE_UNIFORMS);for(let i=0;i<s;i++){const r=this._.getActiveUniform(this.G,i);if(r){const o=this._.getUniformLocation(this.G,r.name);o&&(this.L.set(r.name,o),this.O.set(r.name,r.type))}}}createProgram(s,i){const r=this.createShader(this._.VERTEX_SHADER,s),o=this.createShader(this._.FRAGMENT_SHADER,i),n=this._.createProgram();if(this._.attachShader(n,r),this._.attachShader(n,o),this._.linkProgram(n),!this._.getProgramParameter(n,this._.LINK_STATUS)){const h=this._.getProgramInfoLog(n);throw Error("Shader program link error: "+h)}return this._.deleteShader(r),this._.deleteShader(o),n}createShader(s,i){const r=this._.createShader(s);if(this._.shaderSource(r,i),this._.compileShader(r),!this._.getShaderParameter(r,this._.COMPILE_STATUS)){const o=this._.getShaderInfoLog(r);throw this._.deleteShader(r),Error("Shader compilation error: "+o)}return r}N(){this._.useProgram(this.G),this.X()}Y(s,i){const r=this.L.get(s);if(r)if(typeof i=="number")this.q(s)?this._.uniform1i(r,Math.floor(i)):this._.uniform1f(r,i);else if(typeof i=="boolean")this._.uniform1i(r,i?1:0);else if(Array.isArray(i))switch(i.length){case 2:this._.uniform2f(r,i[0],i[1]);break;case 3:this._.uniform3f(r,i[0],i[1],i[2]);break;case 4:this._.uniform4f(r,i[0],i[1],i[2],i[3]);break;default:console.warn(`Unsupported array length ${i.length} for uniform '${s}'`)}else if(i instanceof WebGLTexture){const o=this.Z();this._.uniform1i(r,o),this._.activeTexture(this._.TEXTURE0+o),this._.bindTexture(this._.TEXTURE_2D,i)}else if(i instanceof q){const o=this.Z();this._.uniform1i(r,o),this._.activeTexture(this._.TEXTURE0+o),this._.bindTexture(this._.TEXTURE_2D,i.texture)}else console.warn(`Unsupported uniform type for '${s}':`,typeof i)}Z(){return this.H>=this.j&&console.warn(`Exceeded maximum texture units (${this.j}). Texture may not render correctly.`),this.H++}q(s){const i=this.O.get(s);return!!i&&(i===this._.INT||i===this._.INT_VEC2||i===this._.INT_VEC3||i===this._.INT_VEC4||i===this._.SAMPLER_2D||i===this._.SAMPLER_CUBE)}get J(){return this.G}dispose(){this._.deleteProgram(this.G)}X(){this.H=0}}class J{constructor(s){l(this,"_");l(this,"K",null);l(this,"tt",16);l(this,"et",new Map);this._=s}st(){if(this.K)return;const s=this._;this.K=s.createBuffer(),s.bindBuffer(s.ARRAY_BUFFER,this.K)}it(){const s=this._,i=s.getParameter(s.CURRENT_PROGRAM);let r=this.et.get(i);return r||(r={rt:s.getAttribLocation(i,"a_position"),ot:s.getAttribLocation(i,"a_texCoord")},this.et.set(i,r)),s.enableVertexAttribArray(r.rt),s.vertexAttribPointer(r.rt,2,s.FLOAT,!1,this.tt,0),s.enableVertexAttribArray(r.ot),s.vertexAttribPointer(r.ot,2,s.FLOAT,!1,this.tt,8),{nt:r.rt,ht:r.ot}}lt(s,i){const r=this._;r.disableVertexAttribArray(s),r.disableVertexAttribArray(i)}ct(s,i){const r=this._,o=W(r)||[0,0,r.canvas.width,r.canvas.height];return{ut:s/o[2]*2-1,ft:1-i/o[3]*2}}dt(s,i,r,o){const n=this._;this.st(),n.bindBuffer(n.ARRAY_BUFFER,this.K);const h=new Float32Array([s,o,0,0,r,o,1,0,s,i,0,1,s,i,0,1,r,o,1,0,r,i,1,1]);n.bufferData(n.ARRAY_BUFFER,h,n.DYNAMIC_DRAW)}dispose(){this.K&&this._.deleteBuffer(this.K)}}class ot extends J{constructor(s){super(s)}gt(s,i,r,o){const n=this.ct(s,i),h=this.ct(s+r,i+o);this.dt(n.ut,n.ft,h.ut,h.ft);const a=this.it();this._.drawArrays(this._.TRIANGLES,0,6),this.lt(a.nt,a.ht)}vt(s,i,r,o,n){this.gt(s,i,r,n),this.gt(s+r-n,i,n,o),this.gt(s,i+o-n,r,n),this.gt(s,i,n,o)}}class nt extends J{constructor(s){super(s)}draw(s,i,r,o,n){const h=r-s,a=o-i,u=Math.hypot(h,a);if(u===0){const d=n/2,g=this.ct(s-d,i-d),p=this.ct(s+d,i+d);this.dt(g.ut,g.ft,p.ut,p.ft)}else{const d=-a/u,g=h/u,p=n/2,w=s+d*p,b=i+g*p,_=s-d*p,T=i-g*p,R=r+d*p,C=o+g*p,M=r-d*p,$=o-g*p,N=this.ct(w,b),A=this.ct(_,T),S=this.ct(R,C),rt=this.ct(M,$),Y=this._;this.st(),Y.bindBuffer(Y.ARRAY_BUFFER,this.K);const Bt=new Float32Array([N.ut,N.ft,0,0,A.ut,A.ft,0,1,S.ut,S.ft,1,0,A.ut,A.ft,0,1,rt.ut,rt.ft,1,1,S.ut,S.ft,1,0]);Y.bufferData(Y.ARRAY_BUFFER,Bt,Y.DYNAMIC_DRAW)}const f=this.it();this._.drawArrays(this._.TRIANGLES,0,6),this.lt(f.nt,f.ht)}}var F="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 ht{constructor(s){l(this,"_");l(this,"_t");l(this,"xt");l(this,"bt",null);l(this,"wt");l(this,"Ct");l(this,"yt",[1,1,1,1]);l(this,"Ft",!0);l(this,"Tt",[0,0,0,1]);l(this,"$t",1);l(this,"Mt",!0);l(this,"Dt",0);l(this,"St",[]);this._=s,this._t=new E(this._,F,"precision lowp float;uniform sampler2D u_texture;varying vec2 v_uv;void main(){gl_FragColor=texture2D(u_texture,v_uv);}"),this.xt=new E(this._,F,"precision lowp float;uniform vec4 u_color;void main(){gl_FragColor=u_color;}"),this.wt=new ot(this._),this.Ct=new nt(this._),this._.enable(this._.BLEND),this._.blendEquation(this._.FUNC_ADD),this._.blendFunc(this._.ONE,this._.ONE_MINUS_SRC_ALPHA),P(this._,[0,0,this._.canvas.width,this._.canvas.height])}Vt(s){this.bt!==s&&(this.bt=s,s.N())}fill(s,i,r,o){if(this.Ft=!0,i===void 0&&r===void 0&&o===void 0){const n=s/255;this.yt=[n,n,n,1]}else if(r!==void 0&&o===void 0)this.yt=[s/255,i/255,r/255,1];else{if(r===void 0||o===void 0)throw Error("Invalid fill parameters. Use fill(gray), fill(r,g,b), or fill(r,g,b,a)");this.yt=[s/255,i/255,r/255,o/255]}}stroke(s,i,r,o){if(this.Mt=!0,i===void 0&&r===void 0&&o===void 0){const n=s/255;this.Tt=[n,n,n,1]}else if(r!==void 0&&o===void 0)this.Tt=[s/255,i/255,r/255,1];else{if(r===void 0||o===void 0)throw Error("Invalid stroke parameters. Use stroke(gray), stroke(r,g,b), or stroke(r,g,b,a)");this.Tt=[s/255,i/255,r/255,o/255]}}Rt(s){if(s<0)throw Error("Stroke weight must be non-negative");this.$t=s}kt(){this.Mt=!1}zt(){this.Ft=!1}rotate(s){this.Dt=s}push(){this.St.push({It:[...this.yt],Ft:this.Ft,Pt:[...this.Tt],Rt:this.$t,Mt:this.Mt,rotation:this.Dt})}pop(){const s=this.St.pop();s?(this.yt=s.It,this.Ft=s.Ft,this.Tt=s.Pt,this.$t=s.Rt,this.Mt=s.Mt,this.Dt=s.rotation):console.warn("pop() called without matching push()")}reset(){this.bt=null,this.St=[],this.Dt=0}createShader(s,i){return new E(this._,s,i)}At(s){return new E(this._,F,s)}Y(s,i){this.bt.Y(s,i)}rect(s,i,r,o){if(this.bt!==null){const{Ut:g,Gt:p,Et:w,aspectRatio:b}=this.Lt(s,i,r,o);return this.Y("u_rotation",w),this.Y("u_center",[g,p]),this.Y("u_aspectRatio",b),this.wt.gt(s,i,r,o),void(this.bt=null)}const n=this.xt;let h=0,a=0,u=0,f=1;const d=this.Lt(s,i,r,o);h=d.Ut,a=d.Gt,u=d.Et,f=d.aspectRatio,this.Ft&&(this.Vt(n),this.Y("u_color",this.yt),this.Y("u_rotation",u),this.Y("u_center",[h,a]),this.Y("u_aspectRatio",f),this.wt.gt(s,i,r,o)),this.Mt&&this.$t>0&&(this.Vt(n),this.Y("u_color",this.Tt),this.Y("u_rotation",u),this.Y("u_center",[h,a]),this.Y("u_aspectRatio",f),this.wt.vt(s,i,r,o,this.$t)),this.bt=null}line(s,i,r,o){if(this.bt!==null){const _=(s+r)/2,T=(i+o)/2,R=Math.abs(r-s)||1,C=Math.abs(o-i)||1,{Ut:M,Gt:$,Et:N,aspectRatio:A}=this.Lt(_-R/2,T-C/2,R,C);this.Y("u_rotation",N),this.Y("u_center",[M,$]),this.Y("u_aspectRatio",A);const S=this.$t>0?this.$t:1;return this.Ct.draw(s,i,r,o,S),void(this.bt=null)}if(!this.Mt||this.$t<=0)return;const n=this.xt,h=(s+r)/2,a=(i+o)/2,u=Math.abs(r-s)||1,f=Math.abs(o-i)||1,d=this.Dt!==0;let g=0,p=0,w=0,b=1;if(d){const _=this.Lt(h-u/2,a-f/2,u,f);g=_.Ut,p=_.Gt,w=_.Et,b=_.aspectRatio}this.Vt(n),this.Y("u_color",this.Tt),d&&(this.Y("u_rotation",w),this.Y("u_center",[g,p]),this.Y("u_aspectRatio",b)),this.Ct.draw(s,i,r,o,this.$t)}Lt(s,i,r,o){const n=W(this._)||[0,0,this._.canvas.width,this._.canvas.height],h=n[2],a=n[3],u=h/a;return{Ut:(s+r/2)/h*2-1,Gt:1-(i+o/2)/a*2,Et:this.Dt*Math.PI/180,aspectRatio:u}}createFramebuffer(s,i,r={}){return new q(this._,s,i,r)}background(s,i=s,r=s,o=255){this.clear(s/255,i/255,r/255,o/255)}clear(s=0,i=0,r=0,o=0){this._.clearColor(s,i,r,o),this._.clear(this._.COLOR_BUFFER_BIT)}Ot(){this._.viewport(0,0,this._.canvas.width,this._.canvas.height),P(this._,[0,0,this._.canvas.width,this._.canvas.height])}get context(){return this._}dispose(){this._t.dispose(),this.xt.dispose(),this.wt.dispose(),this.Ct.dispose()}image(s,i,r,o,n){const h=this._,a=o??s.width,u=n??s.height;this.Vt(this._t),this.Y("u_texture",s.texture);const f=this.Lt(i,r,a,u);this.Y("u_rotation",f.Et),this.Y("u_center",[f.Ut,f.Gt]),this.Y("u_aspectRatio",f.aspectRatio),this.wt.gt(i,r,a,u),h.bindTexture(h.TEXTURE_2D,null),this.bt=null}}var U,m={parse:function(c){var s=function(i,r,o,n){var h=m.T,a={cmap:h.cmap,head:h.head,hhea:h.hhea,maxp:h.maxp,hmtx:h.hmtx,loca:h.loca,glyf:h.glyf},u={_data:i,_index:r,_offset:o};for(var f in a){var d=m.findTable(i,f,o);if(d){var g=d[0],p=n[g];p==null&&(p=a[f].Bt(i,g,d[1],u)),u[f]=n[g]=p}}return u}(new Uint8Array(c),0,0,{});return[s]},findTable:function(c,s,i){for(var r=m.B,o=r.Ht(c,i+4),n=i+12,h=0;h<o;h++){var a=r.jt(c,n,4);r.Wt(c,n+4);var u=r.Wt(c,n+8),f=r.Wt(c,n+12);if(a==s)return[u,f];n+=16}return null},T:{}};m.B={Nt:function(c,s){return m.B.Xt.uint16[0]=c[s]<<8|c[s+1],m.B.Xt.int16[0]},Ht:function(c,s){return c[s]<<8|c[s+1]},Yt:function(c,s,i){for(var r=[],o=0;o<i;o++)r.push(m.B.Ht(c,s+2*o));return r},Wt:function(c,s){var i=m.B.Xt.uint8;return i[3]=c[s],i[2]=c[s+1],i[1]=c[s+2],i[0]=c[s+3],m.B.Xt.uint32[0]},jt:function(c,s,i){for(var r="",o=0;o<i;o++)r+=String.fromCharCode(c[s+o]);return r},Xt:(U=new ArrayBuffer(8),{uint8:new Uint8Array(U),int16:new Int16Array(U),uint16:new Uint16Array(U),uint32:new Uint32Array(U)})},m.T.cmap={Bt:function(c,s,i){var r={qt:[],Qt:{},off:s};c=new Uint8Array(c.buffer,s,i),s=0;var o=m.B,n=o.Ht,h=m.T.cmap;n(c,s);var a=n(c,s+=2);s+=2;for(var u=[],f=0;f<a;f++){var d=n(c,s),g=n(c,s+=2);s+=2;var p=o.Wt(c,s);s+=4;var w="p"+d+"e"+g,b=u.indexOf(p);if(b==-1){b=r.qt.length;var _={};u.push(p);var T=_.format=n(c,p);T==4?_=h.Zt(c,p,_):T==12&&(_=h.Jt(c,p,_)),r.qt.push(_)}r.Qt[w]!=null&&console.log("multiple tables for one platform+encoding: "+w),r.Qt[w]=b}return r},Zt:function(c,s,i){var r=m.B,o=r.Ht,n=r.Yt,h=s,a=o(c,s+=2);o(c,s+=2);var u=o(c,s+=2);s+=2;var f=u>>>1;i.Kt=o(c,s),s+=2,i.te=o(c,s),s+=2,i.ee=o(c,s),s+=2,i.se=n(c,s,f),s+=2*f,s+=2,i.ie=n(c,s,f),s+=2*f,i.re=[];for(var d=0;d<f;d++)i.re.push(r.Nt(c,s)),s+=2;return i.oe=n(c,s,f),s+=2*f,i.ne=n(c,s,h+a-s>>1),i},Jt:function(c,s,i){var r=m.B.Wt;r(c,s+=4),r(c,s+=4);var o=3*r(c,s+=4);s+=4;for(var n=i.groups=new Uint32Array(o),h=0;h<o;h+=3)n[h]=r(c,s+(h<<2)),n[h+1]=r(c,s+(h<<2)+4),n[h+2]=r(c,s+(h<<2)+8);return i}},m.T.head={Bt:function(c,s,i){var r=m.B,o={};return s+=18,o.unitsPerEm=r.Ht(c,s),s+=2,s+=16,o.xMin=r.Nt(c,s),s+=2,o.yMin=r.Nt(c,s),s+=2,o.xMax=r.Nt(c,s),s+=2,o.yMax=r.Nt(c,s),s+=2,s+=6,o.indexToLocFormat=r.Nt(c,s),o}},m.T.hhea={Bt:function(c,s,i){var r=m.B,o={};s+=4;for(var n=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],h=0;h<n.length;h++){var a=n[h],u=a=="advanceWidthMax"||a=="numberOfHMetrics"?r.Ht:r.Nt;o[a]=u(c,s+2*h)}return o}},m.T.hmtx={Bt:function(c,s,i,r){for(var o=m.B,n=[],h=[],a=r.maxp.numGlyphs,u=r.hhea.numberOfHMetrics,f=0,d=0,g=0;g<u;)f=o.Ht(c,s+(g<<2)),d=o.Nt(c,s+(g<<2)+2),n.push(f),h.push(d),g++;for(;g<a;)n.push(f),h.push(d),g++;return{he:n,ae:h}}},m.T.maxp={Bt:function(c,s,i){var r=m.B,o=r.Ht,n={};return r.Wt(c,s),s+=4,n.numGlyphs=o(c,s),s+=2,n}},m.T.loca={Bt:function(c,s,i,r){var o=m.B,n=[],h=r.head.indexToLocFormat,a=r.maxp.numGlyphs+1;if(h==0)for(var u=0;u<a;u++)n.push(o.Ht(c,s+(u<<1))<<1);if(h==1)for(u=0;u<a;u++)n.push(o.Wt(c,s+(u<<2)));return n}},m.T.glyf={Bt:function(c,s,i,r){for(var o=[],n=r.maxp.numGlyphs,h=0;h<n;h++)o.push(null);return o},le:function(c,s){var i=m.B,r=c._data,o=c.loca;if(o[s]==o[s+1])return null;var n=m.findTable(r,"glyf",c._offset)[0]+o[s],h={};if(h.ce=i.Nt(r,n),n+=2,h.xMin=i.Nt(r,n),n+=2,h.yMin=i.Nt(r,n),n+=2,h.xMax=i.Nt(r,n),n+=2,h.yMax=i.Nt(r,n),n+=2,h.xMin>=h.xMax||h.yMin>=h.yMax)return null;if(h.ce>0){h.ue=[];for(var a=0;a<h.ce;a++)h.ue.push(i.Ht(r,n)),n+=2;var u=i.Ht(r,n);if(n+=2,r.length-n<u)return null;n+=u;var f=h.ue[h.ce-1]+1;for(h.flags=[],a=0;a<f;a++){var d=r[n];if(n++,h.flags.push(d),8&d){var g=r[n];n++;for(var p=0;p<g;p++)h.flags.push(d),a++}}for(h.fe=[],a=0;a<f;a++){var w=!!(2&h.flags[a]),b=!!(16&h.flags[a]);w?(h.fe.push(b?r[n]:-r[n]),n++):b?h.fe.push(0):(h.fe.push(i.Nt(r,n)),n+=2)}for(h.de=[],a=0;a<f;a++)w=!!(4&h.flags[a]),b=!!(32&h.flags[a]),w?(h.de.push(b?r[n]:-r[n]),n++):b?h.de.push(0):(h.de.push(i.Nt(r,n)),n+=2);var _=0,T=0;for(a=0;a<f;a++)_+=h.fe[a],T+=h.de[a],h.fe[a]=_,h.de[a]=T}else h.me=[];return h}},typeof module<"u"&&module.exports?module.exports=m:typeof window<"u"&&(window.Typr=m);class at{ge(s){var r;const i=[];return(r=s==null?void 0:s.cmap)!=null&&r.qt?(s.cmap.qt.forEach(o=>{if(o.format===4){const n=this.pe(o);i.push(...n)}else if(o.format===12){const n=this.ve(o);i.push(...n)}}),[...new Set(i)]):[]}pe(s){const i=[];if(!(s.ie&&s.se&&s.oe&&s.re))return i;for(let r=0;r<s.ie.length;r++){const o=s.ie[r],n=s.se[r];if(o!==65535||n!==65535){for(let h=o;h<=n;h++)if(this._e(s,h,r)>0){const a=String.fromCodePoint(h);i.push(a)}}}return i}ve(s){const i=[];if(!s.groups)return i;for(let r=0;r<s.groups.length;r+=3){const o=s.groups[r],n=s.groups[r+1],h=s.groups[r+2];for(let a=o;a<=n;a++)if(h+(a-o)>0){const u=String.fromCodePoint(a);i.push(u)}}return i}_e(s,i,r){if(s.oe[r]===0)return i+s.re[r]&65535;{const o=s.oe[r]/2+(i-s.ie[r])-(s.ie.length-r);if(o>=0&&s.ne&&o<s.ne.length){const n=s.ne[o];if(n!==0)return n+s.re[r]&65535}}return 0}xe(s){return s.filter(i=>this.be(i))}be(s){const i=s.codePointAt(0)||0;return!(i>=0&&i<=31&&i!==9&&i!==10&&i!==13||i>=127&&i<=159)}}class lt{constructor(s){l(this,"we");l(this,"Ce");l(this,"ye");this.ye=s,this.we=document.createElement("canvas"),this.Ce=this.we.getContext("2d",{Fe:!0,alpha:!1})}Te(s,i,r,o){const n=s.length,h=Math.ceil(Math.sqrt(n)),a=Math.ceil(n/h),u=i.width*h,f=i.height*a;this.$e(u,f,r,o),this.Me(s,i,h,r),this.De();const d=this.ye.createFramebuffer(u,f,{filter:"nearest"});return d.update(this.we),{framebuffer:d,columns:h,rows:a}}$e(s,i,r,o){this.we.width=s,this.we.height=i,this.we.style.width=s+"px",this.we.style.height=s+"px",this.Ce.imageSmoothingEnabled=!1,this.we.style.imageRendering="pixelated",this.Ce.fillStyle="black",this.Ce.fillRect(0,0,s,i),this.Ce.font=`${r}px ${o}`,this.Ce.textBaseline="top",this.Ce.textAlign="left",this.Ce.fillStyle="white"}Me(s,i,r,o){for(let n=0;n<s.length;n++){const h=n%r,a=Math.floor(n/r),u=h*i.width+.5*i.width,f=a*i.height+.5*i.height,d=Math.round(u-.5*i.width),g=Math.round(f-.5*o);this.Ce.fillText(s[n].Se,d,g)}}De(s=128){const i=this.Ce.getImageData(0,0,this.we.width,this.we.height),r=i.data;for(let o=0;o<r.length;o+=4){const n=.299*r[o]+.587*r[o+1]+.114*r[o+2]>s+32?255:0;r[o]=n,r[o+1]=n,r[o+2]=n}this.Ce.putImageData(i,0,0)}}class ct{constructor(){l(this,"Ve");l(this,"Re");this.Ve=document.createElement("canvas"),this.Re=this.Ve.getContext("2d")}ke(s,i,r){this.Re.font=`${i}px ${r}`;let o=0,n=0;for(const h of s){const a=this.Re.measureText(h);o=Math.max(o,a.width),n=Math.max(n,a.actualBoundingBoxAscent+a.actualBoundingBoxDescent)}return{width:o,height:n}}}class ut{ze(s,i){return s.map((r,o)=>{const n=r.codePointAt(0)||0,h=this.Ie(o);let a=0;if(i.hmtx&&i.hmtx.he){const u=this.Pe(i,n);u>0&&i.hmtx.he[u]!==void 0&&(a=i.hmtx.he[u])}return{Se:r,unicode:n,color:h,Ae:a}})}Pe(s,i){const r=s.cmap;if(!r||!r.qt)return 0;for(const o of r.qt)if(o.format===4){for(let n=0;n<o.ie.length;n++)if(i>=o.ie[n]&&i<=o.se[n]){if(o.oe[n]===0)return i+o.re[n]&65535;{const h=o.oe[n]/2+(i-o.ie[n])-(o.ie.length-n);if(h>=0&&h<o.ne.length){const a=o.ne[h];if(a!==0)return a+o.re[n]&65535}}}}return 0}Ie(s){return[s%256,Math.floor(s/256)%256,Math.floor(s/65536)%256]}Ue(s,i){if(!y.validate(typeof s=="string","Character must be a string.",{method:"getCharacterColor",Ge:s}))return[0,0,0];const r=i.find(o=>o.Se===s);return r?r.color:[0,0,0]}Ee(s,i){return y.validate(typeof s=="string"&&s.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",Ge:s})?s.split("").map(r=>this.Ue(r,i)||[0,0,0]):[[0,0,0]]}}class Z{constructor(s,i=16){l(this,"Le");l(this,"Oe",[]);l(this,"Be");l(this,"He",16);l(this,"je",0);l(this,"We",0);l(this,"Ne",{width:0,height:0});l(this,"Xe");l(this,"Ye","UrsaFont");l(this,"qe");l(this,"Qe");l(this,"Ze");l(this,"Je");this.He=i,this.qe=new at,this.Qe=new lt(s),this.Ze=new ct,this.Je=new ut}async initialize(s){let i;if(!s)throw new x("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");{const r=await fetch(s);if(!r.ok)throw new x(`Failed to load font file: ${r.status} ${r.statusText}`);i=await r.arrayBuffer()}await this.Ke(i),this.Le=m.parse(i)[0],await this.ts()}es(s){if(s===void 0)return this.He;this.He=s,this.Ne=this.Ze.ke(this.Oe.map(r=>r.Se),this.He,this.Ye);const i=this.Qe.Te(this.Oe,this.Ne,this.He,this.Ye);this.Be=i.framebuffer,this.je=i.columns,this.We=i.rows}async ss(s){try{const i=await fetch(s);if(!i.ok)throw new x(`Failed to load font file: ${i.status} ${i.statusText}`);const r=await i.arrayBuffer();await this.Ke(r);const o=m.parse(r);if(!o||o.length===0)throw Error("Failed to parse font file");this.Le=o[0],await this.ts()}catch(i){throw new x("Failed to load font: "+(i instanceof Error?i.message:"Unknown error"),i)}}async Ke(s){const i=Date.now();this.Ye=this.Ye==="UrsaFont"?"UrsaFont":"CustomFont_"+i,this.Xe=new FontFace(this.Ye,s),await this.Xe.load(),document.fonts.add(this.Xe)}async ts(){const s=this.qe.ge(this.Le),i=this.qe.xe(s);this.Oe=this.Je.ze(i,this.Le),this.Ne=this.Ze.ke(i,this.He,this.Ye);const r=this.Qe.Te(this.Oe,this.Ne,this.He,this.Ye);this.Be=r.framebuffer,this.je=r.columns,this.We=r.rows}Ue(s){return this.Je.Ue(s,this.Oe)}Ee(s){return this.Je.Ee(s,this.Oe)}rs(s){if(typeof s!="string"||s.length===0)return!1;const i=new Set(this.Oe.map(r=>r.Se));for(const r of s)if(!i.has(r))return!1;return!0}get ns(){return this.Be}get hs(){return this.Oe}get ls(){return this.je}get cs(){return this.We}get us(){return this.Ne}dispose(){this.Be.dispose(),document.fonts.delete(this.Xe)}get fontSize(){return this.He}get font(){return this.Le}}class K{constructor(s,i,r){l(this,"fs");l(this,"ds");l(this,"$");l(this,"M");l(this,"gs");l(this,"ps");l(this,"vs",!1);l(this,"_s");l(this,"xs");l(this,"bs");this._s=s,this.xs=i,this.bs=r,this.reset()}reset(){this.vs||(this.fs=Math.floor(this._s.width/this.xs),this.ds=Math.floor(this._s.height/this.bs)),this.ws()}ws(){this.$=this.fs*this.xs,this.M=this.ds*this.bs,this.gs=Math.floor((this._s.width-this.$)/2),this.ps=Math.floor((this._s.height-this.M)/2)}Cs(s,i){this.xs=s,this.bs=i,this.reset()}ys(s,i){this.vs=!0,this.fs=s,this.ds=i,this.ws()}Fs(){this.vs=!1,this.reset()}resize(){this.vs?this.ws():this.reset()}Ts(s){if(s===void 0)return this.vs;this.vs=s}get $s(){return this.xs}get Ms(){return this.bs}get cols(){return this.fs}get rows(){return this.ds}get width(){return this.$}get height(){return this.M}get offsetX(){return this.gs}get offsetY(){return this.ps}}class Q{constructor(s,i=!1,r={}){l(this,"_s");l(this,"Ds");l(this,"Ss");l(this,"Vs");l(this,"Rs");this.Ds=s,this.Ss=i,this._s=this.ks(r.width,r.height),i&&this.zs()}ks(s,i){var o;const r=document.createElement("canvas");if(r.className="textmodeCanvas",r.style.imageRendering="pixelated",this.Ss)r.width=s||800,r.height=i||600,document.body.appendChild(r);else{const n=this.Ds.getBoundingClientRect();let h=Math.round(n.width),a=Math.round(n.height);if(this.Ds instanceof HTMLVideoElement){const d=this.Ds;(h===0||a===0)&&d.videoWidth>0&&d.videoHeight>0&&(h=d.videoWidth,a=d.videoHeight)}r.width=h,r.height=a,r.style.position="absolute",r.style.pointerEvents="none";const u=window.getComputedStyle(this.Ds);let f=parseInt(u.zIndex||"0",10);isNaN(f)&&(f=0),r.style.zIndex=""+(f+1),this.Is(r),(o=this.Ds.parentNode)==null||o.insertBefore(r,this.Ds.nextSibling)}return r}Is(s){const i=this.Ds.getBoundingClientRect();let r=this.Ds.offsetParent;if(r&&r!==document.body){const o=r.getBoundingClientRect();s.style.top=i.top-o.top+"px",s.style.left=i.left-o.left+"px"}else s.style.top=i.top+window.scrollY+"px",s.style.left=i.left+window.scrollX+"px"}resize(s,i){if(this.Ss)this._s.width=s??this._s.width,this._s.height=i??this._s.height;else{const r=this.Ds.getBoundingClientRect();let o=Math.round(r.width),n=Math.round(r.height);if(this.Ds instanceof HTMLVideoElement){const h=this.Ds;(o===0||n===0)&&h.videoWidth>0&&h.videoHeight>0&&(o=h.videoWidth,n=h.videoHeight)}this._s.width=o,this._s.height=n,this.Is(this._s)}}Ps(){const s={alpha:!1,premultipliedAlpha:!1,As:!0,antialias:!1,Us:!1,Gs:!1,powerPreference:"high-performance"},i=this._s.getContext("webgl2",s)||this._s.getContext("webgl",s);if(!i)throw new x("WebGL context could not be created. Ensure your browser supports WebGL.");return i}zs(){this.Vs=new ResizeObserver(s=>{for(const i of s){const r=i.contentRect;!this.Rs||Math.round(r.width)===this._s.width&&Math.round(r.height)===this._s.height||this.Rs()}}),this.Vs.observe(this._s)}dispose(){if(this.Vs&&this.Vs.disconnect(),this._s){const s=this._s.getContext("webgl")||this._s.getContext("webgl2");if(s){const i=s.getExtension("WEBGL_lose_context");i&&i.Es()}this._s.parentNode&&this._s.parentNode.removeChild(this._s)}}get canvas(){return this._s}get width(){return this._s.width}get height(){return this._s.height}}class B{constructor(s,i,r,o={}){l(this,"Ls");l(this,"Os");l(this,"grid");l(this,"Bs");l(this,"Hs");l(this,"js");l(this,"Ws");l(this,"Ns");l(this,"l");this.Ls=s,this.Os=i,this.grid=r,this.l=o;const n=this.grid.cols,h=this.grid.rows;this.Bs=this.Ls.createFramebuffer(n,h),this.Hs=this.Ls.createFramebuffer(n,h),this.js=this.Ls.createFramebuffer(n,h),this.Ws=this.Ls.createFramebuffer(n,h),this.Ns=this.Ls.createFramebuffer(n,h)}resize(){const s=this.grid.cols,i=this.grid.rows;this.Bs.resize(s,i),this.Hs.resize(s,i),this.js.resize(s,i),this.Ws.resize(s,i),this.Ns.resize(s,i)}enabled(s){this.l.enabled=s}enable(){this.enabled(!0)}disable(){this.enabled(!1)}dispose(){this.Bs.dispose(),this.Hs.dispose(),this.js.dispose(),this.Ws.dispose(),this.Ns.dispose()}get Xs(){return this.Bs}get Ys(){return this.Hs}get qs(){return this.js}get Qs(){return this.Ws}get Zs(){return this.Ns}get options(){return this.l}}class ft{constructor(s,i){l(this,"C");l(this,"ye");l(this,"Js");this.ye=s,this.Js=i;const r=Math.max(this.Js.length,1);this.C=this.ye.createFramebuffer(r,1),this.Ks()}Ks(){const s=this.Js.length;this.C.width!==s&&this.C.resize(s,1);const i=new Uint8Array(1*s*4);for(let r=0;r<s;r++){const o=this.Js[r],n=4*r;i[n]=o[0],i[n+1]=o[1],i[n+2]=o[2],i[n+3]=255}this.C.I(i,s,1)}ti(s){this.Js=s,this.Ks()}get ei(){return this.Js}get framebuffer(){return this.C}get texture(){return this.C.texture}}class z extends B{constructor(i,r,o,n={}){super(i,r,o,n);l(this,"palette");this.palette=new ft(this.Ls,this.Os.Ee(" .:-=+*%@#"))}hs(i){y.validate(this.Os.rs(i),"One or more characters do not exist in the current font.",{method:"characters",Ge:i})&&(this.l.hs=i,this.palette.ti(this.Os.Ee(i)))}si(i,r,o,n=255){const h=this.ii(i,"characterColor",r,o,n);h&&(this.l.si=h)}ri(i){this.oi(i,"characterColorMode")}ni(i,r,o,n=255){const h=this.ii(i,"cellColor",r,o,n);h&&(this.l.ni=h)}hi(i){this.oi(i,"cellColorMode")}ai(i){this.li(i,"invert","Invert")}rotation(i){if(!y.validate(typeof i=="number","Rotation angle must be a number.",{method:"rotation",Ge:i}))return;(i%=360)<0&&(i+=360);const r=255*i/360,o=Math.floor(r)/255,n=Math.round(r-o);this.l.rotation=[o,n,0,1]}ci(i){this.li(i,"flipHorizontally","Flip horizontally")}ui(i){this.li(i,"flipVertically","Flip vertically")}ii(i,r,o,n,h=255){let a,u,f,d;if(typeof i=="string"){const g=this.fi(i);if(!g)return y.validate(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:r,Ge:i}),null;[a,u,f,d]=g}else if(a=i,u=o!==void 0?o:i,f=n!==void 0?n:i,d=h,!y.validate([a,u,f,d].every(g=>g>=0&&g<=255),r.charAt(0).toUpperCase()+r.slice(1)+" color values must be between 0 and 255",{method:r,di:{r:a,g:u,b:f,a:d}}))return null;return[a/255,u/255,f/255,d/255]}oi(i,r){y.validate(["sampled","fixed"].includes(i),"Invalid color mode. Must be 'sampled' or 'fixed'.",{method:r,Ge:i})&&(this.l[r]=i)}li(i,r,o){y.validate(typeof i=="boolean"||typeof i=="number"&&Number.isInteger(i),o+" must be a boolean value or an integer (0 for false, any other number for true).",{method:r,Ge:i})&&(this.l[r]=!!i)}fi(i){return i=i.replace(/^#/,""),/^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(i)?(i.length===3&&(i=i.split("").map(r=>r+r).join("")),[parseInt(i.slice(0,2),16),parseInt(i.slice(2,4),16),parseInt(i.slice(4,6),16),255]):null}}const dt={enabled:!0,hs:" .:-=+*%@#",si:[1,1,1,1],ri:"sampled",ni:[0,0,0,1],hi:"fixed",ai:!1,rotation:[0,0,0,255],ci:!1,ui:!1,mi:[0,255]};class V extends z{constructor(i,r,o){super(i,r,o,{...dt});l(this,"gi");l(this,"pi");l(this,"_i");l(this,"xi");l(this,"bi");l(this,"wi");this.gi=new E(i.context,F,"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.pi=new E(i.context,F,"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.xi=new E(i.context,F,"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.bi=new E(i.context,F,"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._i=new E(i.context,F,"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.wi=this.Ls.createFramebuffer(this.grid.cols,this.grid.rows)}Ci(i){const r=this.grid.cols,o=this.grid.rows;this.wi.P(),this.Ls.clear(),this.Ls.Vt(this.gi),this.Ls.Y("u_sketchTexture",i),this.Ls.Y("u_gridCellDimensions",[r,o]),this.Ls.Y("u_brightnessRange",this.l.mi),this.Ls.rect(0,0,r,o),this.wi.end(),this.Hs.P(),this.Ls.clear(),this.Ls.Vt(this.pi),this.Ls.Y("u_sampleTexture",this.wi),this.Ls.Y("u_fillColor",this.l.si),this.Ls.Y("u_useFixedColor",this.l.ri==="fixed"),this.Ls.rect(0,0,r,o),this.Hs.end(),this.js.P(),this.Ls.clear(),this.Ls.Vt(this.pi),this.Ls.Y("u_sampleTexture",this.wi),this.Ls.Y("u_fillColor",this.l.ni),this.Ls.Y("u_useFixedColor",this.l.hi==="fixed"),this.Ls.rect(0,0,r,o),this.js.end(),this.Ns.P(),this.Ls.clear(),this.Ls.Vt(this.xi),this.Ls.Y("u_sampleTexture",this.wi),this.Ls.Y("u_invert",this.l.ai),this.Ls.Y("u_flipHorizontally",this.l.ci),this.Ls.Y("u_flipVertically",this.l.ui),this.Ls.rect(0,0,r,o),this.Ns.end(),this.Ws.P(),this.Ls.clear(),this.Ls.Vt(this.bi),this.Ls.Y("u_sampleTexture",this.wi),this.Ls.Y("u_rotationColor",this.l.rotation),this.Ls.rect(0,0,r,o),this.Ws.end(),this.Bs.P(),this.Ls.clear(),this.Ls.Vt(this._i),this.Ls.Y("u_colorSampleFramebuffer",this.wi),this.Ls.Y("u_charPaletteTexture",this.palette.texture),this.Ls.Y("u_charPaletteSize",[this.palette.ei.length,1]),this.Ls.Y("u_brightnessRange",this.l.mi),this.Ls.rect(0,0,r,o),this.Bs.end()}resize(){super.resize(),this.wi.resize(this.grid.cols,this.grid.rows)}mi(i){y.validate(Array.isArray(i)&&i.length===2&&i.every(r=>typeof r=="number"&&r>=0&&r<=255),"Brightness range must be an array of two numbers between 0 and 255.",{method:"brightnessRange",Ge:i})&&(this.l.mi=i)}}const gt=Object.freeze(Object.defineProperty({__proto__:null,yi:V,Fi:B,Ti:z},Symbol.toStringTag,{value:"Module"}));class tt{constructor(s,i,r){l(this,"Ls");l(this,"font");l(this,"grid");l(this,"$i");l(this,"Mi");l(this,"Di");l(this,"Si");l(this,"Vi");l(this,"Bs");l(this,"Hs");l(this,"js");l(this,"Ws");l(this,"Ns");this.Ls=s,this.font=i,this.grid=r,this.Vi=this.Ls.createShader(F,"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.Mi=new V(s,i,r),this.Di=new B(s,i,r),this.$i=[this.Mi,this.Di],this.Bs=this.Ls.createFramebuffer(r.cols,r.rows),this.Hs=this.Ls.createFramebuffer(r.cols,r.rows),this.js=this.Ls.createFramebuffer(r.cols,r.rows),this.Ws=this.Ls.createFramebuffer(r.cols,r.rows),this.Ns=this.Ls.createFramebuffer(r.cols,r.rows),this.Si=this.Ls.createFramebuffer(this.grid.width,this.grid.height)}Ri(s){for(const r of this.$i)r.options.enabled&&r instanceof z&&r.Ci(s);const i=(r,o)=>{r.P(),this.Ls.clear();for(const n of this.$i)n.options.enabled&&this.Ls.image(o(n),0,0);r.end()};i(this.Bs,r=>r.Xs),i(this.Hs,r=>r.Ys),i(this.js,r=>r.qs),i(this.Ws,r=>r.Qs),i(this.Ns,r=>r.Zs),this.Si.P(),this.Ls.clear(),this.Ls.Vt(this.Vi),this.Ls.Y("u_characterTexture",this.font.ns),this.Ls.Y("u_charsetDimensions",[this.font.ls,this.font.cs]),this.Ls.Y("u_asciiCharacterTexture",this.Bs.texture),this.Ls.Y("u_primaryColorTexture",this.Hs.texture),this.Ls.Y("u_secondaryColorTexture",this.js.texture),this.Ls.Y("u_transformTexture",this.Ns.texture),this.Ls.Y("u_rotationTexture",this.Ws.texture),this.Ls.Y("u_captureTexture",s.texture),this.Ls.Y("u_backgroundMode",!1),this.Ls.Y("u_captureDimensions",[s.width,s.height]),this.Ls.Y("u_gridCellDimensions",[this.grid.cols,this.grid.rows]),this.Ls.Y("u_gridPixelDimensions",[this.grid.width,this.grid.height]),this.Ls.rect(0,0,this.Si.width,this.Si.height),this.Si.end()}add(s){if(!y.validate(s==="brightness"||s==="custom",'Converter type must be either "brightness" or "custom". Provided: '+s,{method:"add",Ge:s}))return;let i;return i=s==="brightness"?new V(this.Ls,this.font,this.grid):new B(this.Ls,this.font,this.grid),this.$i.push(i),i}remove(s){if(!y.validate(s instanceof B,"Parameter must be a TextmodeConverter instance.",{method:"remove",Ge:s}))return;const i=this.$i.indexOf(s);y.validate(i!==-1,"Converter instance not found in pipeline.",{method:"remove",Ge:s,ki:this.$i.length})&&this.$i.splice(i,1)}get texture(){return this.Si}resize(){this.Si.resize(this.grid.width,this.grid.height);const s=this.grid.cols,i=this.grid.rows;this.Bs.resize(s,i),this.Hs.resize(s,i),this.js.resize(s,i),this.Ws.resize(s,i),this.Ns.resize(s,i);for(const r of this.$i)r.resize()}zi(){return this.$i.some(s=>s.options.enabled)}disable(){for(const s of this.$i)s.disable()}enable(){for(const s of this.$i)s.enable()}dispose(){for(const s of this.$i)s.dispose();this.Bs.dispose(),this.Hs.dispose(),this.js.dispose(),this.Ws.dispose(),this.Ns.dispose(),this.Si.dispose(),this.Vi.dispose()}get Xs(){return this.Bs}get Ys(){return this.Hs}get qs(){return this.js}get Qs(){return this.Ws}get Zs(){return this.Ns}}const pt=c=>class extends c{fill(s,i,r,o){this.ye.fill(s,i,r,o)}stroke(s,i,r,o){this.ye.stroke(s,i,r,o)}Rt(s){this.ye.Rt(s)}kt(){this.ye.kt()}zt(){this.ye.zt()}rotate(s){this.ye.rotate(s)}push(){this.ye.push()}pop(){this.ye.pop()}rect(s,i,r=1,o=1){this.ye.rect(s,i,r,o)}line(s,i,r,o){this.ye.line(s,i,r,o)}background(s,i=s,r=s,o=255){this.ye.background(s,i,r,o)}createShader(s,i){return this.ye.createShader(s,i)}At(s){return this.ye.At(s)}Vt(s){this.ye.Vt(s)}Y(s,i){this.ye.Y(s,i)}};class G{Ii(s){const i=s.get("brightness"),r=i==null?void 0:i.Xs,o=i==null?void 0:i.Ys,n=i==null?void 0:i.qs,h=i==null?void 0:i.Zs,a=i==null?void 0:i.Qs;return r==null||r.A(),o==null||o.A(),n==null||n.A(),h==null||h.A(),a==null||a.A(),{Pi:(r==null?void 0:r.U)||new Uint8Array(0),Ai:(o==null?void 0:o.U)||new Uint8Array(0),Ui:(n==null?void 0:n.U)||new Uint8Array(0),Gi:(h==null?void 0:h.U)||new Uint8Array(0),Ei:(a==null?void 0:a.U)||new Uint8Array(0)}}Li(s,i){return s[i]+(s[i+1]<<8)}Oi(s,i){return{r:s[i],g:s[i+1],b:s[i+2],a:s[i+3]}}}class H{Bi(s,i){return new Blob([s],{type:i})}Hi(s,i,r){try{const o=this.Bi(s,r),n=URL.createObjectURL(o),h=document.createElement("a");h.href=n,h.download=i,h.style.display="none",h.rel="noopener",document.body.appendChild(h),h.click(),document.body.removeChild(h),URL.revokeObjectURL(n)}catch(o){throw console.error("Failed to download file:",o),Error("File download failed: "+(o instanceof Error?o.message:"Unknown error"))}}ji(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}Wi(){const s=new Date;return{Ni:s.toISOString().split("T")[0],time:s.toTimeString().split(" ")[0].replace(/:/g,"-")}}Xi(s){return s.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}Yi(){return"'textmode-export'-"+this.ji()}}class mt extends G{qi(s,i,r){const o=s[r]===255,n=s[r+1]===255,h=s[r+2]===255,a=i[r],u=i[r+1];return{Qi:o,Zi:n,Ji:h,rotation:Math.round(360*(a+u/255)/255*100)/100}}Ki(s,i,r){return{x:s,y:i,tr:s*r.$s,er:i*r.Ms}}sr(s,i){const r=[];let o=0;for(let n=0;n<i.rows;n++)for(let h=0;h<i.cols;h++){const a=4*o,u=this.Li(s.Pi,a);let f=this.Oi(s.Ai,a),d=this.Oi(s.Ui,a);const g=this.qi(s.Gi,s.Ei,a);if(g.Qi){const w=f;f=d,d=w}const p=this.Ki(h,n,i);r.push({charIndex:u,ir:f,rr:d,transform:g,position:p}),o++}return r}}class _t{nr(s,i){const r=s.cmap;for(const o of r.qt)if(o.format===4){for(let n=0;n<o.ie.length;n++)if(i>=o.ie[n]&&i<=o.se[n]){if(o.oe[n]===0)return i+o.re[n]&65535;{const h=o.oe[n]/2+(i-o.ie[n])-(o.ie.length-n);if(h>=0&&h<o.ne.length){const a=o.ne[h];if(a!==0)return a+o.re[n]&65535}}}}return 0}hr(s,i,r,o,n){const h=n/s.head.unitsPerEm;return{ar:()=>({x1:r+i.xMin*h,y1:o+-i.yMax*h,x2:r+i.xMax*h,y2:o+-i.yMin*h}),lr:()=>this.cr(i,r,o,h)}}cr(s,i,r,o){if(!s||!s.fe)return"";const{fe:n,de:h,ue:a,flags:u}=s;if(!(n&&h&&a&&u))return"";let f="",d=0;for(let g=0;g<a.length;g++){const p=a[g];if(!(p<d)){if(p>=d){const w=i+n[d]*o,b=r-h[d]*o;f+=`M${w.toFixed(2)},${b.toFixed(2)}`;let _=d+1;for(;_<=p;)if(1&u[_]){const T=i+n[_]*o,R=r-h[_]*o;f+=`L${T.toFixed(2)},${R.toFixed(2)}`,_++}else{const T=i+n[_]*o,R=r-h[_]*o;let C=_+1>p?d:_+1;if(1&u[C]){const M=i+n[C]*o,$=r-h[C]*o;f+=`Q${T.toFixed(2)},${R.toFixed(2)} ${M.toFixed(2)},${$.toFixed(2)}`,_=C+1}else{const M=(T+(i+n[C]*o))/2,$=(R+(r-h[C]*o))/2;f+=`Q${T.toFixed(2)},${R.toFixed(2)} ${M.toFixed(2)},${$.toFixed(2)}`,_=C}}f+="Z"}d=p+1}}return f}ur(s,i,r,o,n){const h=s.codePointAt(0)||0,a=this.nr(i,h);let u=null;return i.glyf&&i.glyf[a]!==null?u=i.glyf[a]:m&&m.T&&m.T.glyf&&m.T.glyf.le&&(u=m.T.glyf.le(i,a),i.glyf&&u&&(i.glyf[a]=u)),this.hr(i,u,r,o,n)}dr(s,i,r,o,n,h,a,u){const f=r+(n-u*(a/i.head.unitsPerEm))/2,d=o+(h+.7*a)/2;return this.ur(s,i,f,d,a).lr()||null}}class xt{constructor(){l(this,"mr");this.mr=new _t}gr(s){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
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 y=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,_=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,_),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,_=(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,_-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 _=v.format=n(l,p);_==4?v=a.parse4(l,p,v):_==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,_=0;for(h=0;h<d;h++)v+=a.xs[h],_+=a.ys[h],a.xs[h]=v,a.ys[h]=_}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(!y.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 y.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){y.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(!y.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 y.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,!y.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){y.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){y.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
|
|
8
|
+
attribute vec2 a_texCoord;\r
|
|
9
|
+
varying vec2 v_uv;\r
|
|
10
|
+
\r
|
|
11
|
+
uniform float u_rotation; // rotation angle in radians\r
|
|
12
|
+
uniform vec2 u_center; // rotation center in normalized coordinates\r
|
|
13
|
+
uniform float u_aspectRatio; // canvas width / canvas height\r
|
|
14
|
+
\r
|
|
15
|
+
mat2 rotate2D(float angle) {\r
|
|
16
|
+
float s = sin(angle);\r
|
|
17
|
+
float c = cos(angle);\r
|
|
18
|
+
return mat2(c, -s, s, c);\r
|
|
19
|
+
}\r
|
|
20
|
+
\r
|
|
21
|
+
void main() {\r
|
|
22
|
+
v_uv = a_texCoord;\r
|
|
23
|
+
\r
|
|
24
|
+
// Use the position directly (it's already in normalized device coordinates)\r
|
|
25
|
+
vec2 pos = a_position;\r
|
|
26
|
+
\r
|
|
27
|
+
// Translate to origin for rotation\r
|
|
28
|
+
pos -= u_center;\r
|
|
29
|
+
\r
|
|
30
|
+
// Correct for aspect ratio: scale X coordinate to make space square\r
|
|
31
|
+
pos.x *= u_aspectRatio;\r
|
|
32
|
+
\r
|
|
33
|
+
// Rotate in corrected space\r
|
|
34
|
+
// Negate rotation to make positive values rotate clockwise (like p5.js)\r
|
|
35
|
+
pos = rotate2D(-u_rotation) * pos;\r
|
|
36
|
+
\r
|
|
37
|
+
// Restore aspect ratio: scale X coordinate back\r
|
|
38
|
+
pos.x /= u_aspectRatio;\r
|
|
39
|
+
\r
|
|
40
|
+
// Translate back from origin\r
|
|
41
|
+
pos += u_center;\r
|
|
42
|
+
\r
|
|
43
|
+
gl_Position = vec4(pos, 0.0, 1.0);\r
|
|
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){y.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(!y.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(!y.p(r instanceof Z,"Parameter must be a TextmodeConverter instance.",{method:"remove",providedValue:r}))return;const s=this.ur.indexOf(r);y.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.get("brightness"),i=s==null?void 0:s.characterFramebuffer,o=s==null?void 0:s.primaryColorFramebuffer,n=s==null?void 0:s.secondaryColorFramebuffer,a=s==null?void 0:s.transformFramebuffer,h=s==null?void 0:s.rotationFramebuffer;return i==null||i.loadPixels(),o==null||o.loadPixels(),n==null||n.loadPixels(),a==null||a.loadPixels(),h==null||h.loadPixels(),{characterPixels:(i==null?void 0:i.pixels)||new Uint8Array(0),primaryColorPixels:(o==null?void 0:o.pixels)||new Uint8Array(0),secondaryColorPixels:(n==null?void 0:n.pixels)||new Uint8Array(0),transformPixels:(a==null?void 0:a.pixels)||new Uint8Array(0),rotationPixels:(h==null?void 0:h.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 _=s+n[v]*o,E=i-a[v]*o;d+=`L${_.toFixed(2)},${E.toFixed(2)}`,v++}else{const _=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${_.toFixed(2)},${E.toFixed(2)} ${F.toFixed(2)},${A.toFixed(2)}`,v=T+1}else{const F=(_+(s+n[T]*o))/2,A=(E+(i-a[T]*o))/2;d+=`Q${_.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"?>
|
|
8
46
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
9
|
-
<svg width="${
|
|
47
|
+
<svg width="${r.width}" height="${r.height}" viewBox="0 0 ${r.width} ${r.height}"
|
|
10
48
|
xmlns="http://www.w3.org/2000/svg" version="1.1">
|
|
11
49
|
<title>textmode art generated via textmode.js</title>
|
|
12
|
-
<desc>textmode art visualization generated by textmode.js library</desc>`}
|
|
50
|
+
<desc>textmode art visualization generated by textmode.js library</desc>`}Ar(){return`
|
|
13
51
|
</g>
|
|
14
|
-
</svg>`}
|
|
15
|
-
<rect width="${
|
|
16
|
-
<rect x="${o.
|
|
17
|
-
<rect x="${o.
|
|
18
|
-
<path id="${`path-${
|
|
19
|
-
<path d="${
|
|
20
|
-
<g${
|
|
21
|
-
</g>`):n+=
|
|
22
|
-
<g id="ascii-cells">`;for(const
|
|
23
|
-
`).replace(/[ \t]+$/gm,"")}}class
|
|
52
|
+
</svg>`}Gr(r,s){if(!s.includeBackgroundRectangles)return"";const i=s.backgroundColor,o=`rgba(${i[0]},${i[1]},${i[2]},${i[3]/255})`;return`
|
|
53
|
+
<rect width="${r.width}" height="${r.height}" fill="${o}" />`}Er(r){return`rgba(${r.r},${r.g},${r.b},${r.a/255})`}Lr(r,s){const{transform:i,position:o}=r,n=o.cellX+s.cellWidth/2,a=o.cellY+s.cellHeight/2,h=[];if(i.flipHorizontal||i.flipVertical){const u=i.flipHorizontal?-1:1,d=i.flipVertical?-1:1;h.push(`translate(${n} ${a})`),h.push(`scale(${u} ${d})`),h.push(`translate(${-n} ${-a})`)}return i.rotation&&h.push(`rotate(${i.rotation} ${n} ${a})`),h.length?` transform="${h.join(" ")}"`:""}Or(r,s,i){if(!i.includeBackgroundRectangles||r.secondaryColor.a===0)return"";const{position:o}=r,n=this.Er(r.secondaryColor);return i.drawMode==="stroke"?`
|
|
54
|
+
<rect x="${o.cellX}" y="${o.cellY}" width="${s.cellWidth}" height="${s.cellHeight}" stroke="${n}" fill="none" stroke-width="${i.strokeWidth}" />`:`
|
|
55
|
+
<rect x="${o.cellX}" y="${o.cellY}" width="${s.cellWidth}" height="${s.cellHeight}" fill="${n}" />`}zr(r,s,i,o){const n=i.characters[r.charIndex];if(!n)return"";const a=this.Pr.Ir(n.character,i.font,r.position.cellX,r.position.cellY,s.cellWidth,s.cellHeight,i.fontSize,n.advanceWidth);if(!a)return"";const h=this.Er(r.primaryColor);return o.drawMode==="stroke"?`
|
|
56
|
+
<path id="${`path-${r.charIndex}-${r.position.cellX}-${r.position.cellY}`.replace(/\./g,"-")}" d="${a}" stroke="${h}" stroke-width="${o.strokeWidth}" fill="none" />`:`
|
|
57
|
+
<path d="${a}" fill="${h}" />`}Br(r,s,i,o){let n="";n+=this.Or(r,s,o);const a=this.Lr(r,s),h=this.zr(r,s,i,o);return h&&(a?(n+=`
|
|
58
|
+
<g${a}>`,n+=h,n+=`
|
|
59
|
+
</g>`):n+=h),n}Hr(r,s,i,o){let n=this.Ur(s);n+=this.Gr(s,o),n+=`
|
|
60
|
+
<g id="ascii-cells">`;for(const a of r)n+=this.Br(a,s,i,o);return n+=this.Ar(),n}jr(r){return r.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\n\s*\n/g,`
|
|
61
|
+
`).replace(/[ \t]+$/gm,"")}}class bt extends Y{Wr(r){return this.Cr(r,"image/svg+xml;charset=utf-8")}Nr(r,s){this.yr(r,this.Tr(s)+".svg","image/svg+xml;charset=utf-8")}Xr(r,s){this.Nr(r,s||this.Dr())}}class et{constructor(){c(this,"qr");c(this,"Yr");c(this,"Qr");this.qr=new mt,this.Yr=new xt,this.Qr=new bt}Zr(r){return{includeBackgroundRectangles:r.includeBackgroundRectangles??!0,drawMode:r.drawMode??"fill",strokeWidth:r.strokeWidth??1,backgroundColor:r.backgroundColor??[0,0,0,0]}}Jr(r,s={}){const i=this.Zr(s),o=this.qr.vr(r.pipeline),n=this.qr.Rr(o,r.grid),a=this.Yr.Hr(n,r.grid,r.font,i);return this.Yr.jr(a)}Xr(r,s={}){const i=this.Jr(r,s),o=s.filename||this.Qr.Dr();this.Qr.Xr(i,o)}}class Ct extends V{Kr(r,s,i,o=" "){var h;const n=[];let a=0;for(let u=0;u<s.rows;u++){const d=[];for(let f=0;f<s.cols;f++){const g=4*a,p=this.br(r.characterPixels,g),b=((h=i.characters[p])==null?void 0:h.character)||o;d.push(b),a++}n.push(d)}return n}}class wt{ts(r,s){const i=[];for(const n of r){let a=n.join("");s.preserveTrailingSpaces||(a=a.replace(/\s+$/,"")),i.push(a)}const o=s.lineEnding==="crlf"?`\r
|
|
24
62
|
`:`
|
|
25
|
-
`;return
|
|
63
|
+
`;return i.join(o)}}class yt extends Y{es(r,s){const i=this.rs(s);this.yr(r,i,"text/plain;charset=utf-8")}rs(r){let s=this.Tr(r);return s===".txt"||s.length<=4?this.Dr():s}}class rt{constructor(){c(this,"qr");c(this,"Yr");c(this,"Qr");this.qr=new Ct,this.Yr=new wt,this.Qr=new yt}Zr(r){return{preserveTrailingSpaces:r.preserveTrailingSpaces??!1,lineEnding:r.lineEnding??"lf",emptyCharacter:r.emptyCharacter??" "}}ss(r,s={}){const i=this.Zr(s),o=this.qr.vr(r.pipeline),n=this.qr.Kr(o,r.grid,r.font,i.emptyCharacter);return this.Yr.ts(n,i)}es(r,s={}){const i=this.ss(r,s),o=s.filename||this.Qr.Dr();this.Qr.es(i,o)}}class _t extends V{ns(r,s=1,i="transparent"){const o=r.canvas;if(s===1&&i==="transparent")return o;const n=document.createElement("canvas"),a=n.getContext("2d"),h=Math.round(o.width*s),u=Math.round(o.height*s);return n.width=h,n.height=u,i!=="transparent"&&(a.fillStyle=i,a.fillRect(0,0,h,u)),a.imageSmoothingEnabled=!1,a.drawImage(o,0,0,o.width,o.height,0,0,h,u),n}}class Tt{hs(r,s){const i=this.ls(s.format);return s.format==="png"?r.toDataURL(i):r.toDataURL(i,s.quality)}async cs(r,s){return new Promise((i,o)=>{const n=this.ls(s.format),a=h=>{h?i(h):o(Error(`Failed to generate ${s.format.toUpperCase()} blob`))};s.format==="png"?r.toBlob(a,n):r.toBlob(a,n,s.quality)})}ls(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 Et={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},st={png:".png",jpg:".jpg",webp:".webp"};class Pt extends Y{us(r,s,i){this.fs(r,this.Tr(s)+st[i])}fs(r,s){const i=URL.createObjectURL(r);try{const o=document.createElement("a");o.href=i,o.download=s,o.style.display="none",o.rel="noopener",document.body.appendChild(o),o.click(),document.body.removeChild(o)}finally{URL.revokeObjectURL(i)}}ds(r){return r in Et&&r in st}}class Rt{constructor(){c(this,"qr");c(this,"Yr");c(this,"Qr");this.qr=new _t,this.Yr=new Tt,this.Qr=new Pt}Zr(r){return{format:r.format??"png",quality:r.quality??1,scale:r.scale??1,backgroundColor:r.backgroundColor??"transparent"}}ps(r){if(console.log("Validating image export options:",r),!this.Qr.ds(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")}gs(r,s={}){const i=this.Zr(s);if(this.ps(i),i.scale===1&&i.backgroundColor==="transparent")return this.Yr.hs(r.canvas,i);const o=this.qr.ns(r,i.scale,i.backgroundColor);return this.Yr.hs(o,i)}async cs(r,s={}){const i=this.Zr(s);if(this.ps(i),i.scale===1&&i.backgroundColor==="transparent")return await this.Yr.cs(r.canvas,i);const o=this.qr.ns(r,i.scale,i.backgroundColor);return await this.Yr.cs(o,i)}async us(r,s={}){const i=await this.cs(r,s),o=s.format??"png",n=s.filename||this.Qr.Dr();this.Qr.us(i,n,o)}}const Mt=l=>class extends l{toString(r={}){return new rt().ss(this,r)}saveStrings(r={}){new rt().es(this,r)}toSVG(r={}){return new et().Jr(this,r)}saveSVG(r={}){new et().Xr(this,r)}async saveCanvas(r,s="png",i={}){await new Rt().us(this.Me,{...i,filename:r,format:s})}},Ft=l=>class extends l{async loadFont(r){return this.oe.Ce(r).then(()=>{const s=this.oe.maxGlyphDimensions;this.je.ke(s.width,s.height),this._s.Pe()})}fontSize(r){if(!y.p(typeof r=="number"&&r>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:r})||this.oe.fontSize===r)return;this.oe.we(r);const s=this.oe.maxGlyphDimensions;this.je.ke(s.width,s.height),this._s.Pe(),this.Zt.Bt()}},At=l=>class extends l{addConverter(r){return this._s.add(r)}removeConverter(r){this._s.remove(r)}};class Dt{constructor(){c(this,"Zt");c(this,"oe");c(this,"_s");c(this,"Me");c(this,"je")}}class G extends function(s,...i){return i.reduce((o,n)=>n(o),s)}(Dt,pt,Mt,Ft,At){constructor(s=null,i={}){super();c(this,"Ae");c(this,"vs");c(this,"Ee");c(this,"bs");c(this,"ws");c(this,"Cs",null);c(this,"$s",0);c(this,"Fs");c(this,"Ts",!0);c(this,"Ds",0);c(this,"Ms",0);c(this,"Ss",0);c(this,"Rs",[]);c(this,"Vs",10);c(this,"ks",!1);c(this,"zs",!1);c(this,"Is",()=>{});c(this,"Ps",()=>{});c(this,"Us");this.Ae=s,this.zs=s===null,this.bs=i.renderMode??"auto",this.ws=i.frameRate??60,this.Fs=1e3/this.ws}static async create(s=null,i={}){const o=new this(s,i),n=o.zs?i:void 0;let a,h;o.Me=new K(o.captureSource,o.zs,n),o.Zt=new at(o.Me.Be()),o.zs?(a=i.width||800,h=i.height||600):(a=o.Me.width||800,h=o.Me.height||600),o.vs=o.Zt.Et(a,h),o.oe=new Q(o.Zt,i.fontSize??16),await o.oe.ve(i.fontSource);const u=o.oe.maxGlyphDimensions;return o.je=new J(o.Me.canvas,u.width,u.height),o._s=new tt(o.Zt,o.oe,o.je),o.As(),o.Gs(),o}As(){this.Us=()=>{this.zs?this.Ps():this.Es()},window.addEventListener("resize",this.Us),window.ResizeObserver&&this.Ae&&!this.zs&&(this.Ee=new ResizeObserver(()=>{this.Es()}),this.Ee.observe(this.Ae))}render(){this.Ls(),this.Ss++,this.ks?console.warn("Cannot render: Required resources have been disposed"):(this.zs?(this.vs.begin(),this.Is(),this.vs.end()):this.vs.update(this.Ae),this._s.hasEnabledConverters()?(this._s._r(this.vs),this.Zt.Lt(0),this.Zt.Ht(this._s.texture,this.je.offsetX,this.je.offsetY,this._s.texture.width,this._s.texture.height)):(this.Zt.Ot(),this.Zt.Ht(this.vs,this.je.offsetX,this.je.offsetY,this.vs.width,this.vs.height)))}Es(){this.Me.Pe(),this.vs.resize(this.Me.width,this.Me.height),this.je.Pe(),this._s.Pe(),this.Zt.Bt(),this.bs!=="manual"&&this.render()}Gs(){if(this.bs!=="auto"||!this.Ts)return;this.$s=performance.now();const s=i=>{if(!this.Ts)return void(this.Cs=null);const o=i-this.$s;o>=this.Fs&&(this.render(),this.$s=i-o%this.Fs),this.Ts&&(this.Cs=requestAnimationFrame(s))};this.Cs=requestAnimationFrame(s)}Ls(){const s=performance.now();if(this.Ms>0){const i=s-this.Ms;this.Rs.push(i),this.Rs.length>this.Vs&&this.Rs.shift();const o=this.Rs.reduce((n,a)=>n+a,0)/this.Rs.length;this.Ds=1e3/o}this.Ms=s}Os(){this.Cs&&(cancelAnimationFrame(this.Cs),this.Cs=null)}renderMode(s){this.bs!==s&&(this.Os(),this.bs=s,s==="auto"&&this.Ts&&this.Gs())}frameRate(s){if(s===void 0)return this.Ds;this.ws=s,this.Fs=1e3/s,this.bs==="auto"&&this.Ts&&(this.Os(),this.Gs())}noLoop(){this.Ts&&(this.Ts=!1,this.Cs&&(cancelAnimationFrame(this.Cs),this.Cs=null))}loop(){this.Ts||(this.Ts=!0,this.bs==="auto"&&this.Gs())}redraw(s=1){if(y.p(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.bs==="auto"&&this.Ts}draw(s){this.Is=s}windowResized(s){this.Ps=s}resizeCanvas(s,i){this.Me.Pe(s,i),this.vs.resize(this.Me.width,this.Me.height),this.je.Pe(),this._s.Pe(),this.Zt.Bt(),this.bs!=="manual"&&this.render()}destroy(){this.ks||(this.Os(),window.removeEventListener("resize",this.Us),this.Ee&&this.Ee.disconnect(),this._s.P(),this.oe.P(),this.vs.P(),this.Zt.P(),this.ks=!0)}get grid(){return this.je}get font(){return this.oe}get mode(){return this.bs}get pipeline(){return this._s}get frameCount(){return this.Ss}set frameCount(s){this.Ss=s}get width(){return this.Me.width}get height(){return this.Me.height}get canvas(){return this.Me}get isDisposed(){return this.ks}}class j{static async create(r,s={}){if(r instanceof HTMLCanvasElement||r instanceof HTMLVideoElement)return G.create(r,s);{const i=r||{};return G.create(null,i)}}static setErrorLevel(r){y._(r)}static get version(){return"0.1.7"}}const Ut=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),St=j.create,Zt=j.setErrorLevel,$t=j.version;C.TextmodeCanvas=K,C.TextmodeConversionPipeline=tt,C.TextmodeErrorLevel=R,C.TextmodeFont=Q,C.TextmodeGrid=J,C.Textmodifier=G,C.converters=gt,C.create=St,C.export=Ut,C.setErrorLevel=Zt,C.textmode=j,C.version=$t,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):e((t=typeof globalThis<"u"?globalThis:t||self).textmode={});
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
export declare class TextmodeError extends Error {
|
|
2
|
-
|
|
3
|
-
readonly context?: any;
|
|
4
|
-
constructor(message: string, originalError?: Error, context?: any);
|
|
2
|
+
constructor(message: string, context?: any);
|
|
5
3
|
/**
|
|
6
4
|
* Create a formatted error message that includes context
|
|
7
5
|
*/
|
|
8
|
-
static createFormattedMessage(message: string, context?: any): string;
|
|
6
|
+
static $createFormattedMessage(message: string, context?: any): string;
|
|
9
7
|
/**
|
|
10
8
|
* Format values for better display in error messages
|
|
11
9
|
*/
|
|
12
|
-
private static
|
|
10
|
+
private static _formatValue;
|
|
13
11
|
}
|
|
@@ -46,7 +46,7 @@ export declare class TextmodeErrorHandler {
|
|
|
46
46
|
private static _instance;
|
|
47
47
|
private _options;
|
|
48
48
|
private constructor();
|
|
49
|
-
static getInstance(): TextmodeErrorHandler;
|
|
49
|
+
static $getInstance(): TextmodeErrorHandler;
|
|
50
50
|
/**
|
|
51
51
|
* Handle an error based on the configured settings
|
|
52
52
|
* @returns true if execution should continue, false if error was handled
|
|
@@ -59,11 +59,11 @@ export declare class TextmodeErrorHandler {
|
|
|
59
59
|
* @param context Additional context for debugging
|
|
60
60
|
* @returns true if validation passed, false if validation failed and was handled
|
|
61
61
|
*/
|
|
62
|
-
validate(condition: boolean, message: string, context?: any): boolean;
|
|
62
|
+
$validate(condition: boolean, message: string, context?: any): boolean;
|
|
63
63
|
/**
|
|
64
64
|
* Set global error level
|
|
65
65
|
*/
|
|
66
|
-
setGlobalLevel(level: TextmodeErrorLevel): void;
|
|
66
|
+
$setGlobalLevel(level: TextmodeErrorLevel): void;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Singleton instance of the textmode.js error handler.
|
|
@@ -9,7 +9,7 @@ export declare abstract class DataExtractor {
|
|
|
9
9
|
* @param pipeline The conversion pipeline containing framebuffers
|
|
10
10
|
* @returns Object containing all pixel data arrays
|
|
11
11
|
*/
|
|
12
|
-
extractFramebufferData(pipeline: any): FramebufferData;
|
|
12
|
+
$extractFramebufferData(pipeline: any): FramebufferData;
|
|
13
13
|
/**
|
|
14
14
|
* Gets character index from character framebuffer pixels
|
|
15
15
|
* @param characterPixels Character framebuffer pixel data
|
|
@@ -17,14 +17,14 @@ export declare abstract class DataExtractor {
|
|
|
17
17
|
* @param charactersLength Total number of available characters
|
|
18
18
|
* @returns Character index
|
|
19
19
|
*/
|
|
20
|
-
protected
|
|
20
|
+
protected _getCharacterIndex(characterPixels: Uint8Array, pixelIndex: number): number;
|
|
21
21
|
/**
|
|
22
22
|
* Converts raw pixel data to RGBA color object
|
|
23
23
|
* @param pixels Pixel data array
|
|
24
24
|
* @param index Pixel index (already multiplied by 4 for RGBA)
|
|
25
25
|
* @returns RGBA color object with r, g, b, a properties
|
|
26
26
|
*/
|
|
27
|
-
protected
|
|
27
|
+
protected _pixelsToRGBA(pixels: Uint8Array, index: number): {
|
|
28
28
|
r: number;
|
|
29
29
|
g: number;
|
|
30
30
|
b: number;
|
|
@@ -9,24 +9,24 @@ export declare abstract class FileHandler {
|
|
|
9
9
|
* @param mimeType The MIME type for the blob
|
|
10
10
|
* @returns Blob object containing the content
|
|
11
11
|
*/
|
|
12
|
-
protected
|
|
12
|
+
protected _createBlob(content: string, mimeType: string): Blob;
|
|
13
13
|
/**
|
|
14
14
|
* Downloads content as a file
|
|
15
15
|
* @param content The content to download
|
|
16
16
|
* @param filename The filename (with extension)
|
|
17
17
|
* @param mimeType The MIME type for the content
|
|
18
18
|
*/
|
|
19
|
-
protected
|
|
19
|
+
protected _downloadFile(content: string, filename: string, mimeType: string): void;
|
|
20
20
|
/**
|
|
21
21
|
* Generates a timestamp string for filenames
|
|
22
22
|
* @returns Formatted timestamp string
|
|
23
23
|
*/
|
|
24
|
-
protected
|
|
24
|
+
protected _generateTimestamp(): string;
|
|
25
25
|
/**
|
|
26
26
|
* Generates a date-time string for filenames (alternative format)
|
|
27
27
|
* @returns Formatted date and time string
|
|
28
28
|
*/
|
|
29
|
-
protected
|
|
29
|
+
protected _generateDateTimeString(): {
|
|
30
30
|
date: string;
|
|
31
31
|
time: string;
|
|
32
32
|
};
|
|
@@ -35,12 +35,12 @@ export declare abstract class FileHandler {
|
|
|
35
35
|
* @param filename The filename to validate
|
|
36
36
|
* @returns Sanitized filename
|
|
37
37
|
*/
|
|
38
|
-
protected
|
|
38
|
+
protected _sanitizeFilename(filename: string): string;
|
|
39
39
|
/**
|
|
40
40
|
* Generates a default filename with prefix and timestamp
|
|
41
41
|
* @param prefix The prefix for the filename
|
|
42
42
|
* @param extension The file extension (with dot)
|
|
43
43
|
* @returns Generated filename
|
|
44
44
|
*/
|
|
45
|
-
generateDefaultFilename(): string;
|
|
45
|
+
$generateDefaultFilename(): string;
|
|
46
46
|
}
|
|
@@ -10,18 +10,18 @@ export declare class ImageContentGenerator {
|
|
|
10
10
|
* @param options Generation options with format, quality, etc.
|
|
11
11
|
* @returns Data URL string containing the image data
|
|
12
12
|
*/
|
|
13
|
-
generateImageData(canvas: HTMLCanvasElement, options: ImageGenerationOptions): string;
|
|
13
|
+
$generateImageData(canvas: HTMLCanvasElement, options: ImageGenerationOptions): string;
|
|
14
14
|
/**
|
|
15
15
|
* Generates image blob from canvas
|
|
16
16
|
* @param canvas The canvas containing the image data
|
|
17
17
|
* @param options Generation options with format, quality, etc.
|
|
18
18
|
* @returns Promise that resolves to a Blob containing the image data
|
|
19
19
|
*/
|
|
20
|
-
generateImageBlob(canvas: HTMLCanvasElement, options: ImageGenerationOptions): Promise<Blob>;
|
|
20
|
+
$generateImageBlob(canvas: HTMLCanvasElement, options: ImageGenerationOptions): Promise<Blob>;
|
|
21
21
|
/**
|
|
22
22
|
* Gets the MIME type for a given image format
|
|
23
23
|
* @param format The image format
|
|
24
24
|
* @returns The corresponding MIME type
|
|
25
25
|
*/
|
|
26
|
-
private
|
|
26
|
+
private _getMimeType;
|
|
27
27
|
}
|
|
@@ -12,5 +12,5 @@ export declare class ImageDataExtractor extends DataExtractor {
|
|
|
12
12
|
* @param backgroundColor Background color for formats that don't support transparency
|
|
13
13
|
* @returns Canvas element containing the captured image data
|
|
14
14
|
*/
|
|
15
|
-
captureCanvasData(canvas: TextmodeCanvas, scale?: number, backgroundColor?: string): HTMLCanvasElement;
|
|
15
|
+
$captureCanvasData(canvas: TextmodeCanvas, scale?: number, backgroundColor?: string): HTMLCanvasElement;
|
|
16
16
|
}
|
|
@@ -6,40 +6,40 @@ import type { TextmodeCanvas } from '../../index';
|
|
|
6
6
|
* format conversion, and file handling.
|
|
7
7
|
*/
|
|
8
8
|
export declare class ImageExporter {
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
private
|
|
9
|
+
private _dataExtractor;
|
|
10
|
+
private _contentGenerator;
|
|
11
|
+
private _fileHandler;
|
|
12
12
|
constructor();
|
|
13
13
|
/**
|
|
14
14
|
* Applies default values to image export options
|
|
15
15
|
* @param options User-provided options
|
|
16
16
|
* @returns Complete options with defaults applied
|
|
17
17
|
*/
|
|
18
|
-
private
|
|
18
|
+
private _applyDefaultOptions;
|
|
19
19
|
/**
|
|
20
20
|
* Validates export options and browser support
|
|
21
21
|
* @param options The options to validate
|
|
22
22
|
* @throws Error if options are invalid or format is not supported
|
|
23
23
|
*/
|
|
24
|
-
private
|
|
24
|
+
private _validateOptions;
|
|
25
25
|
/**
|
|
26
26
|
* Generates image data from textmode rendering without saving to file
|
|
27
27
|
* @param canvas The canvas data containing the rendered textmode graphics
|
|
28
28
|
* @param options Export options (excluding filename)
|
|
29
29
|
* @returns Data URL string containing the image data
|
|
30
30
|
*/
|
|
31
|
-
generateImage(canvas: TextmodeCanvas, options?: Omit<ImageExportOptions, 'filename'>): string;
|
|
31
|
+
$generateImage(canvas: TextmodeCanvas, options?: Omit<ImageExportOptions, 'filename'>): string;
|
|
32
32
|
/**
|
|
33
33
|
* Generates image blob from textmode rendering without saving to file
|
|
34
34
|
* @param canvasData The canvas data containing the rendered textmode graphics
|
|
35
35
|
* @param options Export options (excluding filename)
|
|
36
36
|
* @returns Promise that resolves to a Blob containing the image data
|
|
37
37
|
*/
|
|
38
|
-
generateImageBlob(canvas: TextmodeCanvas, options?: Omit<ImageExportOptions, 'filename'>): Promise<Blob>;
|
|
38
|
+
$generateImageBlob(canvas: TextmodeCanvas, options?: Omit<ImageExportOptions, 'filename'>): Promise<Blob>;
|
|
39
39
|
/**
|
|
40
40
|
* Exports image to a downloadable file
|
|
41
41
|
* @param canvas The canvas data containing the rendered textmode graphics
|
|
42
42
|
* @param options Export options including filename
|
|
43
43
|
*/
|
|
44
|
-
saveImage(canvas: TextmodeCanvas, options?: ImageExportOptions): Promise<void>;
|
|
44
|
+
$saveImage(canvas: TextmodeCanvas, options?: ImageExportOptions): Promise<void>;
|
|
45
45
|
}
|