textmode.js 0.1.4-beta.7 → 0.1.4-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/textmode.esm.js
CHANGED
|
@@ -1932,7 +1932,7 @@ class z extends x {
|
|
|
1932
1932
|
{ method: "characterColor", providedValues: { r: s, g: o, b: g, a: B } }
|
|
1933
1933
|
))
|
|
1934
1934
|
return;
|
|
1935
|
-
this._options.characterColor = [s, o, g, B];
|
|
1935
|
+
this._options.characterColor = [s / 255, o / 255, g / 255, B / 255];
|
|
1936
1936
|
}
|
|
1937
1937
|
/**
|
|
1938
1938
|
* Sets the character color mode.
|
|
@@ -1974,7 +1974,7 @@ class z extends x {
|
|
|
1974
1974
|
{ method: "cellColor", providedValues: { r: s, g: o, b: g, a: B } }
|
|
1975
1975
|
))
|
|
1976
1976
|
return;
|
|
1977
|
-
this._options.cellColor = [s, o, g, B];
|
|
1977
|
+
this._options.cellColor = [s / 255, o / 255, g / 255, B / 255];
|
|
1978
1978
|
}
|
|
1979
1979
|
/**
|
|
1980
1980
|
* Sets the cell color mode.
|
|
@@ -2057,11 +2057,13 @@ const vA = {
|
|
|
2057
2057
|
/** Characters used for brightness mapping (from darkest to brightest) */
|
|
2058
2058
|
characters: " .:-=+*%@#",
|
|
2059
2059
|
/** Color of the ASCII characters. Only used when `characterColorMode` is set to `fixed` */
|
|
2060
|
-
characterColor: [
|
|
2060
|
+
characterColor: [1, 1, 1, 1],
|
|
2061
|
+
// White
|
|
2061
2062
|
/** Character color mode */
|
|
2062
2063
|
characterColorMode: "sampled",
|
|
2063
2064
|
/** Cell background color. Only used when `characterColorMode` is set to `fixed` */
|
|
2064
|
-
cellColor: [0, 0, 0,
|
|
2065
|
+
cellColor: [0, 0, 0, 1],
|
|
2066
|
+
// Black
|
|
2065
2067
|
/** Background color mode */
|
|
2066
2068
|
cellColorMode: "fixed",
|
|
2067
2069
|
/** Swap the cells ASCII character colors with it's cell background colors */
|
|
@@ -4363,7 +4365,7 @@ class N {
|
|
|
4363
4365
|
* ```
|
|
4364
4366
|
*/
|
|
4365
4367
|
static get version() {
|
|
4366
|
-
return "0.1.4-beta.
|
|
4368
|
+
return "0.1.4-beta.8";
|
|
4367
4369
|
}
|
|
4368
4370
|
constructor() {
|
|
4369
4371
|
throw new Error("Textmode is a static class and cannot be instantiated.");
|
package/dist/textmode.esm.min.js
CHANGED
|
@@ -1930,7 +1930,7 @@ class H extends U {
|
|
|
1930
1930
|
{ method: "characterColor", providedValues: { r: a, g: n, b: l, a: c } }
|
|
1931
1931
|
))
|
|
1932
1932
|
return;
|
|
1933
|
-
this._options.characterColor = [a, n, l, c];
|
|
1933
|
+
this._options.characterColor = [a / 255, n / 255, l / 255, c / 255];
|
|
1934
1934
|
}
|
|
1935
1935
|
/**
|
|
1936
1936
|
* Sets the character color mode.
|
|
@@ -1972,7 +1972,7 @@ class H extends U {
|
|
|
1972
1972
|
{ method: "cellColor", providedValues: { r: a, g: n, b: l, a: c } }
|
|
1973
1973
|
))
|
|
1974
1974
|
return;
|
|
1975
|
-
this._options.cellColor = [a, n, l, c];
|
|
1975
|
+
this._options.cellColor = [a / 255, n / 255, l / 255, c / 255];
|
|
1976
1976
|
}
|
|
1977
1977
|
/**
|
|
1978
1978
|
* Sets the cell color mode.
|
|
@@ -2055,11 +2055,13 @@ const Re = {
|
|
|
2055
2055
|
/** Characters used for brightness mapping (from darkest to brightest) */
|
|
2056
2056
|
characters: " .:-=+*%@#",
|
|
2057
2057
|
/** Color of the ASCII characters. Only used when `characterColorMode` is set to `fixed` */
|
|
2058
|
-
characterColor: [
|
|
2058
|
+
characterColor: [1, 1, 1, 1],
|
|
2059
|
+
// White
|
|
2059
2060
|
/** Character color mode */
|
|
2060
2061
|
characterColorMode: "sampled",
|
|
2061
2062
|
/** Cell background color. Only used when `characterColorMode` is set to `fixed` */
|
|
2062
|
-
cellColor: [0, 0, 0,
|
|
2063
|
+
cellColor: [0, 0, 0, 1],
|
|
2064
|
+
// Black
|
|
2063
2065
|
/** Background color mode */
|
|
2064
2066
|
cellColorMode: "fixed",
|
|
2065
2067
|
/** Swap the cells ASCII character colors with it's cell background colors */
|
|
@@ -4361,7 +4363,7 @@ class N {
|
|
|
4361
4363
|
* ```
|
|
4362
4364
|
*/
|
|
4363
4365
|
static get version() {
|
|
4364
|
-
return "0.1.4-beta.
|
|
4366
|
+
return "0.1.4-beta.8";
|
|
4365
4367
|
}
|
|
4366
4368
|
constructor() {
|
|
4367
4369
|
throw new Error("Textmode is a static class and cannot be instantiated.");
|
package/dist/textmode.umd.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
`,r+="↓".repeat(24)+`
|
|
7
7
|
`,r}static formatValue(e){if(e===null)return"null";if(e===void 0)return"undefined";if(typeof e=="string")return`"${e}"`;if(typeof e=="number"||typeof e=="boolean")return String(e);if(Array.isArray(e))return e.length===0?"[]":e.length<=5?`[${e.map(t=>f.formatValue(t)).join(", ")}]`:`[${e.slice(0,3).map(t=>f.formatValue(t)).join(", ")}, ... +${e.length-3} more]`;if(typeof e=="object"){const t=Object.keys(e);return t.length===0?"{}":t.length<=3?`{ ${t.map(s=>`${s}: ${f.formatValue(e[s])}`).join(", ")} }`:`{ ${t.slice(0,2).map(i=>`${i}: ${f.formatValue(e[i])}`).join(", ")}, ... +${t.length-2} more }`}return String(e)}}var v=(n=>(n[n.SILENT=0]="SILENT",n[n.WARNING=1]="WARNING",n[n.ERROR=2]="ERROR",n[n.THROW=3]="THROW",n))(v||{});const x=class x{constructor(){a(this,"_options",{globalLevel:3})}static getInstance(){return x._instance||(x._instance=new x),x._instance}_handle(A,e,t){const r="[textmode.js]";switch(this._options.globalLevel){case 0:return!1;case 1:return console.group(`%c${r} Oops! (╯°□°)╯︵ Something went wrong in your code.`,"color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;"),console.warn(f.createFormattedMessage(A,e)),console.groupEnd(),!1;case 2:return console.group(`%c${r} Oops! (╯°□°)╯︵ Something went wrong in your code.`,"color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;"),console.error(f.createFormattedMessage(A,e)),console.groupEnd(),!1;case 3:default:const i=new f(A,t,e);throw console.group(`%c${r} Oops! (╯°□°)╯︵ Something went wrong in your code.`,"color: #d32f2f; font-weight: bold; background: #ffcdd2; padding: 2px 6px; border-radius: 3px;"),i}}validate(A,e,t){return A?!0:(this._handle(e,t),!1)}setGlobalLevel(A){this._options.globalLevel=A}};a(x,"_instance",null);let U=x;const m=U.getInstance();class rA{constructor(A,e,t=e,r={}){a(this,"gl");a(this,"_framebuffer");a(this,"_texture");a(this,"_width");a(this,"_height");a(this,"options");a(this,"previousState",null);a(this,"_pixels",null);this.gl=A,this._width=e,this._height=t,this.options={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...r},this._texture=this.createTexture(),this._framebuffer=A.createFramebuffer(),this.attachTexture()}createTexture(){const{gl:A}=this,e=A.createTexture();A.bindTexture(A.TEXTURE_2D,e);const t=this.options.filter==="linear"?A.LINEAR:A.NEAREST,r=this.options.wrap==="repeat"?A.REPEAT:A.CLAMP_TO_EDGE;return A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MIN_FILTER,t),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_MAG_FILTER,t),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_S,r),A.texParameteri(A.TEXTURE_2D,A.TEXTURE_WRAP_T,r),this.updateTextureSize(),e}updateTextureSize(){const{gl:A}=this,e=A.RGBA,t=A.RGBA,r=this.options.type==="float"?A.FLOAT:A.UNSIGNED_BYTE;A.texImage2D(A.TEXTURE_2D,0,e,this._width,this._height,0,t,r,null)}attachTexture(){const{gl:A}=this;A.bindFramebuffer(A.FRAMEBUFFER,this._framebuffer),A.framebufferTexture2D(A.FRAMEBUFFER,A.COLOR_ATTACHMENT0,A.TEXTURE_2D,this._texture,0),A.bindFramebuffer(A.FRAMEBUFFER,null)}update(A){const{gl:e}=this;A instanceof HTMLVideoElement&&A.readyState<2||(e.bindTexture(e.TEXTURE_2D,this._texture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,A),e.bindTexture(e.TEXTURE_2D,null))}updatePixels(A,e,t){const{gl:r}=this;r.bindTexture(r.TEXTURE_2D,this._texture),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,A),r.bindTexture(r.TEXTURE_2D,null)}resize(A,e){const{gl:t}=this;this._width=A,this._height=e,t.bindTexture(t.TEXTURE_2D,this._texture),this.updateTextureSize(),t.bindTexture(t.TEXTURE_2D,null)}begin(){const{gl:A}=this;this.previousState={framebuffer:A.getParameter(A.FRAMEBUFFER_BINDING),viewport:A.getParameter(A.VIEWPORT)},A.bindFramebuffer(A.FRAMEBUFFER,this._framebuffer),A.viewport(0,0,this._width,this._height)}end(){if(!this.previousState)return;const{gl:A}=this;A.bindFramebuffer(A.FRAMEBUFFER,this.previousState.framebuffer),A.viewport(...this.previousState.viewport),this.previousState=null}loadPixels(){const{gl:A}=this;this._pixels||(this._pixels=new Uint8Array(this._width*this._height*4));const e=A.getParameter(A.FRAMEBUFFER_BINDING);A.bindFramebuffer(A.FRAMEBUFFER,this._framebuffer),A.readPixels(0,0,this._width,this._height,A.RGBA,A.UNSIGNED_BYTE,this._pixels),A.bindFramebuffer(A.FRAMEBUFFER,e)}get(A,e,t,r){const{gl:i}=this;if(A===void 0&&e===void 0){const s=new Uint8Array(this._width*this._height*4),o=i.getParameter(i.FRAMEBUFFER_BINDING);return i.bindFramebuffer(i.FRAMEBUFFER,this._framebuffer),i.readPixels(0,0,this._width,this._height,i.RGBA,i.UNSIGNED_BYTE,s),i.bindFramebuffer(i.FRAMEBUFFER,o),s}else if(t===void 0&&r===void 0){(A<0||e<0||A>=this._width||e>=this._height)&&(console.warn("The x and y values passed to Framebuffer.get are outside of its range and will be clamped."),A=Math.max(0,Math.min(A,this._width-1)),e=Math.max(0,Math.min(e,this._height-1)));const s=new Uint8Array(4),o=i.getParameter(i.FRAMEBUFFER_BINDING);return i.bindFramebuffer(i.FRAMEBUFFER,this._framebuffer),i.readPixels(A,e,1,1,i.RGBA,i.UNSIGNED_BYTE,s),i.bindFramebuffer(i.FRAMEBUFFER,o),[s[0],s[1],s[2],s[3]]}else{A=Math.max(0,Math.min(A,this._width-1)),e=Math.max(0,Math.min(e,this._height-1)),t=Math.max(1,Math.min(t,this._width-A)),r=Math.max(1,Math.min(r,this._height-e));const s=new Uint8Array(t*r*4),o=i.getParameter(i.FRAMEBUFFER_BINDING);return i.bindFramebuffer(i.FRAMEBUFFER,this._framebuffer),i.readPixels(A,e,t,r,i.RGBA,i.UNSIGNED_BYTE,s),i.bindFramebuffer(i.FRAMEBUFFER,o),s}}dispose(){const{gl:A}=this;this._framebuffer&&(A.deleteFramebuffer(this._framebuffer),this._framebuffer=null),this._texture&&(A.deleteTexture(this._texture),this._texture=null),this._pixels=null}get framebuffer(){return this._framebuffer}get texture(){return this._texture}get width(){return this._width}get height(){return this._height}get pixels(){return this._pixels}}class ${constructor(A,e,t){a(this,"gl");a(this,"x");a(this,"y");this.gl=A,this.x=e,this.y=t}}class T{constructor(A,e,t,r,i){a(this,"gl");a(this,"vertexBuffer");a(this,"vertexCount",6);a(this,"bytesPerVertex");this.gl=A,this.bytesPerVertex=16;const s=A.getParameter(A.VIEWPORT),o=s[2],g=s[3],B=A.getParameter(A.FRAMEBUFFER_BINDING)!==null,E=e/o*2-1,l=(e+r)/o*2-1;let h,c;B?(h=t/g*2-1,c=(t+i)/g*2-1):(h=1-t/g*2,c=1-(t+i)/g*2);let d,u,P,p;d=E,P=l,u=h,p=c;const D=this.generateVertices(d,u,P,p);this.vertexBuffer=A.createBuffer(),A.bindBuffer(A.ARRAY_BUFFER,this.vertexBuffer),A.bufferData(A.ARRAY_BUFFER,D,A.STATIC_DRAW)}generateVertices(A,e,t,r){return new Float32Array([A,r,0,1,t,r,1,1,A,e,0,0,A,e,0,0,t,r,1,1,t,e,1,0])}render(){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);const A=this.gl.getParameter(this.gl.CURRENT_PROGRAM);let e=this.gl.getAttribLocation(A,"a_position"),t=this.gl.getAttribLocation(A,"a_texCoord");this.gl.enableVertexAttribArray(e),this.gl.vertexAttribPointer(e,2,this.gl.FLOAT,!1,this.bytesPerVertex,0),this.gl.enableVertexAttribArray(t),this.gl.vertexAttribPointer(t,2,this.gl.FLOAT,!1,this.bytesPerVertex,8),this.gl.drawArrays(this.gl.TRIANGLES,0,this.vertexCount),this.gl.disableVertexAttribArray(e),this.gl.disableVertexAttribArray(t)}}class iA extends ${constructor(e,t,r,i,s){super(e,t,r);a(this,"width");a(this,"height");this.width=i,this.height=s}renderFill(){new T(this.gl,this.x,this.y,this.width,this.height).render()}renderStroke(e){if(e<=0)return;const t=new T(this.gl,this.x,this.y,this.width,e),r=new T(this.gl,this.x+this.width-e,this.y,e,this.height),i=new T(this.gl,this.x,this.y+this.height-e,this.width,e),s=new T(this.gl,this.x,this.y,e,this.height);t.render(),r.render(),i.render(),s.render()}}class sA{constructor(A,e,t,r,i,s){a(this,"gl");a(this,"vertexBuffer");a(this,"vertexCount",6);a(this,"bytesPerVertex");this.gl=A,this.bytesPerVertex=16;const o=A.getParameter(A.VIEWPORT),g=o[2],B=o[3],E=A.getParameter(A.FRAMEBUFFER_BINDING)!==null,l=r-e,h=i-t,c=Math.sqrt(l*l+h*h);if(c===0){const NA=this.generateVertices(0,0,0,0);this.vertexBuffer=A.createBuffer(),A.bindBuffer(A.ARRAY_BUFFER,this.vertexBuffer),A.bufferData(A.ARRAY_BUFFER,NA,A.STATIC_DRAW);return}const d=l/c,P=-(h/c),p=d,D=s/2,I=e+P*D,G=t+p*D,F=e-P*D,b=t-p*D,L=r+P*D,M=i+p*D,kA=r-P*D,tA=i-p*D,VA=I/g*2-1,OA=F/g*2-1,zA=L/g*2-1,LA=kA/g*2-1;let H,N,X,W;E?(H=G/B*2-1,N=b/B*2-1,X=M/B*2-1,W=tA/B*2-1):(H=1-G/B*2,N=1-b/B*2,X=1-M/B*2,W=1-tA/B*2);const HA=this.generateLineVertices(VA,H,OA,N,zA,X,LA,W);this.vertexBuffer=A.createBuffer(),A.bindBuffer(A.ARRAY_BUFFER,this.vertexBuffer),A.bufferData(A.ARRAY_BUFFER,HA,A.STATIC_DRAW)}generateVertices(A,e,t,r){return new Float32Array([A,r,0,1,t,r,1,1,A,e,0,0,A,e,0,0,t,r,1,1,t,e,1,0])}generateLineVertices(A,e,t,r,i,s,o,g){return new Float32Array([A,e,0,0,t,r,0,1,i,s,1,0,t,r,0,1,o,g,1,1,i,s,1,0])}render(){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);const A=this.gl.getParameter(this.gl.CURRENT_PROGRAM);let e=this.gl.getAttribLocation(A,"a_position"),t=this.gl.getAttribLocation(A,"a_texCoord");this.gl.enableVertexAttribArray(e),this.gl.vertexAttribPointer(e,2,this.gl.FLOAT,!1,this.bytesPerVertex,0),this.gl.enableVertexAttribArray(t),this.gl.vertexAttribPointer(t,2,this.gl.FLOAT,!1,this.bytesPerVertex,8),this.gl.drawArrays(this.gl.TRIANGLES,0,this.vertexCount),this.gl.disableVertexAttribArray(e),this.gl.disableVertexAttribArray(t)}}class oA extends ${constructor(e,t,r,i,s){super(e,t,r);a(this,"x2");a(this,"y2");this.x2=i,this.y2=s}renderFill(){}renderStroke(e){if(e<=0)return;new sA(this.gl,this.x,this.y,this.x2,this.y2,e).render()}}class w{constructor(A,e,t){a(this,"gl");a(this,"program");a(this,"uniformLocations",new Map);a(this,"attributeLocations",new Map);a(this,"textureUnitCounter",0);this.gl=A,this.program=this.createProgram(e,t),this.cacheLocations()}createProgram(A,e){const t=this.createShader(this.gl.VERTEX_SHADER,A),r=this.createShader(this.gl.FRAGMENT_SHADER,e),i=this.gl.createProgram();if(this.gl.attachShader(i,t),this.gl.attachShader(i,r),this.gl.linkProgram(i),!this.gl.getProgramParameter(i,this.gl.LINK_STATUS)){const s=this.gl.getProgramInfoLog(i);throw new Error(`Shader program link error: ${s}`)}return this.gl.deleteShader(t),this.gl.deleteShader(r),i}createShader(A,e){const t=this.gl.createShader(A);if(this.gl.shaderSource(t,e),this.gl.compileShader(t),!this.gl.getShaderParameter(t,this.gl.COMPILE_STATUS)){const r=this.gl.getShaderInfoLog(t);throw this.gl.deleteShader(t),new Error(`Shader compilation error: ${r}`)}return t}cacheLocations(){const A=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_UNIFORMS);for(let t=0;t<A;t++){const r=this.gl.getActiveUniform(this.program,t);if(r){const i=this.gl.getUniformLocation(this.program,r.name);i&&this.uniformLocations.set(r.name,i)}}const e=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_ATTRIBUTES);for(let t=0;t<e;t++){const r=this.gl.getActiveAttrib(this.program,t);if(r){const i=this.gl.getAttribLocation(this.program,r.name);this.attributeLocations.set(r.name,i)}}}use(){this.gl.useProgram(this.program),this.resetTextureUnits()}setUniform(A,e){const t=this.uniformLocations.get(A);if(!t)return;const r=this.getUniformInfo(A);if(typeof e=="number")r&&r.type===this.gl.INT?this.gl.uniform1i(t,Math.floor(e)):this.gl.uniform1f(t,e);else if(typeof e=="boolean")this.gl.uniform1i(t,e?1:0);else if(Array.isArray(e))if(r&&(r.type===this.gl.INT_VEC2||r.type===this.gl.INT_VEC3||r.type===this.gl.INT_VEC4)){const i=e.map(s=>Math.floor(s));switch(i.length){case 2:this.gl.uniform2iv(t,i);break;case 3:this.gl.uniform3iv(t,i);break;case 4:this.gl.uniform4iv(t,i);break;default:console.warn(`Unsupported array length ${i.length} for uniform '${A}'`)}}else switch(e.length){case 2:this.gl.uniform2f(t,e[0],e[1]);break;case 3:this.gl.uniform3f(t,e[0],e[1],e[2]);break;case 4:this.gl.uniform4f(t,e[0],e[1],e[2],e[3]);break;default:console.warn(`Unsupported array length ${e.length} for uniform '${A}'`)}else if(e instanceof WebGLTexture){const i=this.getNextTextureUnit();this.gl.uniform1i(t,i),this.gl.activeTexture(this.gl.TEXTURE0+i),this.gl.bindTexture(this.gl.TEXTURE_2D,e)}else if(e&&typeof e=="object"&&"texture"in e){const i=this.getNextTextureUnit();this.gl.uniform1i(t,i),this.gl.activeTexture(this.gl.TEXTURE0+i),this.gl.bindTexture(this.gl.TEXTURE_2D,e.texture)}else console.warn(`Unsupported uniform type for '${A}':`,typeof e)}getUniformInfo(A){const e=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_UNIFORMS);for(let t=0;t<e;t++){const r=this.gl.getActiveUniform(this.program,t);if(r&&r.name===A)return r}return null}getNextTextureUnit(){return this.textureUnitCounter++}hasUniform(A){return this.uniformLocations.has(A)}hasAttribute(A){return this.attributeLocations.has(A)}get glProgram(){return this.program}dispose(){this.program&&(this.gl.deleteProgram(this.program),this.program=null),this.uniformLocations.clear(),this.attributeLocations.clear(),this.textureUnitCounter=0}resetTextureUnits(){this.textureUnitCounter=0}}var _="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);}",aA="precision lowp float;uniform sampler2D u_texture;varying vec2 v_uv;void main(){gl_FragColor=texture2D(u_texture,v_uv);}",nA="precision lowp float;uniform vec4 u_color;void main(){gl_FragColor=u_color;}";class gA{constructor(A){a(this,"gl");a(this,"imageShader");a(this,"solidColorShader");a(this,"currentShader",null);a(this,"currentFillColor",[1,1,1,1]);a(this,"fillMode",!0);a(this,"currentStrokeColor",[0,0,0,1]);a(this,"currentStrokeWeight",1);a(this,"strokeMode",!0);a(this,"currentRotation",0);a(this,"stateStack",[]);this.gl=A,this.imageShader=new w(this.gl,_,aA),this.solidColorShader=new w(this.gl,_,nA),this.gl.enable(this.gl.BLEND),this.gl.blendEquation(this.gl.FUNC_ADD),this.gl.blendFunc(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}shader(A){this.currentShader=A,A.use()}fill(A,e,t,r){if(this.fillMode=!0,e===void 0&&t===void 0&&r===void 0){const i=A/255;this.currentFillColor=[i,i,i,1]}else if(t!==void 0&&r===void 0)this.currentFillColor=[A/255,e/255,t/255,1];else if(t!==void 0&&r!==void 0)this.currentFillColor=[A/255,e/255,t/255,r/255];else throw new Error("Invalid fill parameters. Use fill(gray), fill(r,g,b), or fill(r,g,b,a)")}stroke(A,e,t,r){if(this.strokeMode=!0,e===void 0&&t===void 0&&r===void 0){const i=A/255;this.currentStrokeColor=[i,i,i,1]}else if(t!==void 0&&r===void 0)this.currentStrokeColor=[A/255,e/255,t/255,1];else if(t!==void 0&&r!==void 0)this.currentStrokeColor=[A/255,e/255,t/255,r/255];else throw new Error("Invalid stroke parameters. Use stroke(gray), stroke(r,g,b), or stroke(r,g,b,a)")}strokeWeight(A){if(A<0)throw new Error("Stroke weight must be non-negative");this.currentStrokeWeight=A}noStroke(){this.strokeMode=!1}noFill(){this.fillMode=!1}rotate(A){this.currentRotation=A}push(){this.stateStack.push({fillColor:[...this.currentFillColor],fillMode:this.fillMode,strokeColor:[...this.currentStrokeColor],strokeWeight:this.currentStrokeWeight,strokeMode:this.strokeMode,rotation:this.currentRotation})}pop(){const A=this.stateStack.pop();A?(this.currentFillColor=A.fillColor,this.fillMode=A.fillMode,this.currentStrokeColor=A.strokeColor,this.currentStrokeWeight=A.strokeWeight,this.strokeMode=A.strokeMode,this.currentRotation=A.rotation):console.warn("pop() called without matching push()")}reset(){this.currentShader=null,this.stateStack=[],this.currentRotation=0,this.fillMode=!0,this.strokeMode=!0,this.currentFillColor=[1,1,1,1],this.currentStrokeColor=[0,0,0,1],this.currentStrokeWeight=1}createShader(A,e){return new w(this.gl,A,e)}createFilterShader(A){return new w(this.gl,_,A)}setUniform(A,e){this.currentShader.setUniform(A,e)}rect(A,e,t,r){const i=new iA(this.gl,A,e,t,r);if(this.currentShader!==null){if(this.currentRotation!==0){const{centerX:l,centerY:h,radians:c,aspectRatio:d}=this.calculateRotationParams(A,e,t,r);this.setUniform("u_rotation",c),this.setUniform("u_center",[l,h]),this.setUniform("u_aspectRatio",d)}else this.setUniform("u_rotation",0),this.setUniform("u_center",[0,0]),this.setUniform("u_aspectRatio",1);i.renderFill(),this.currentShader=null;return}const s=this.solidColorShader,{centerX:o,centerY:g,radians:B,aspectRatio:E}=this.calculateRotationParams(A,e,t,r);this.fillMode&&(this.shader(s),this.setUniform("u_color",this.currentFillColor),this.setUniform("u_rotation",B),this.setUniform("u_center",[o,g]),this.setUniform("u_aspectRatio",E),i.renderFill()),this.strokeMode&&(this.shader(s),this.setUniform("u_color",this.currentStrokeColor),this.setUniform("u_rotation",B),this.setUniform("u_center",[o,g]),this.setUniform("u_aspectRatio",E),i.renderStroke(this.currentStrokeWeight)),this.currentShader=null}line(A,e,t,r){if(!this.strokeMode)return;const i=new oA(this.gl,A,e,t,r);if(this.currentShader!==null){if(this.currentRotation!==0){const u=(A+t)/2,P=(e+r)/2,p=Math.abs(t-A),D=Math.abs(r-e),{centerX:I,centerY:G,radians:F,aspectRatio:b}=this.calculateRotationParams(u-p/2,P-D/2,p,D);this.setUniform("u_rotation",F),this.setUniform("u_center",[I,G]),this.setUniform("u_aspectRatio",b)}else this.setUniform("u_rotation",0),this.setUniform("u_center",[0,0]),this.setUniform("u_aspectRatio",1);i.renderStroke(this.currentStrokeWeight),this.currentShader=null;return}const s=this.solidColorShader,o=(A+t)/2,g=(e+r)/2,B=Math.abs(t-A),E=Math.abs(r-e),{centerX:l,centerY:h,radians:c,aspectRatio:d}=this.calculateRotationParams(o-B/2,g-E/2,B,E);this.shader(s),this.setUniform("u_color",this.currentStrokeColor),this.setUniform("u_rotation",c),this.setUniform("u_center",[l,h]),this.setUniform("u_aspectRatio",d),i.renderStroke(this.currentStrokeWeight),this.currentShader=null}calculateRotationParams(A,e,t,r){const i=this.gl.getParameter(this.gl.VIEWPORT),s=i[2],o=i[3],g=s/o,B=this.gl.getParameter(this.gl.FRAMEBUFFER_BINDING)!==null,E=A+t/2,l=e+r/2,h=E/s*2-1;let c;B?c=l/o*2-1:c=1-l/o*2;const d=this.currentRotation*Math.PI/180;return{centerX:h,centerY:c,radians:d,aspectRatio:g}}createFramebuffer(A,e,t={}){return new rA(this.gl,A,e,t)}background(A,e=A,t=A,r=255){this.clear(A/255,e/255,t/255,r/255)}clear(A=0,e=0,t=0,r=0){this.gl.clearColor(A,e,t,r),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}resetViewport(){this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height)}get context(){return this.gl}dispose(){this.imageShader.dispose(),this.solidColorShader.dispose(),this.imageShader=null,this.solidColorShader=null,this.currentShader=null,this.stateStack=[]}image(A,e,t,r,i){this.shader(this.imageShader),this.setUniform("u_texture",A.texture);const{centerX:s,centerY:o,radians:g,aspectRatio:B}=this.calculateRotationParams(e,t,r??A.width,i??A.height);this.setUniform("u_rotation",g),this.setUniform("u_center",[s,o]),this.setUniform("u_aspectRatio",B),this.rect(e,t,r??A.width,i??A.height)}}var Q={};Q.parse=function(n){var A=function(i,s,o,g){var B=Q.T,E={cmap:B.cmap,head:B.head,hhea:B.hhea,maxp:B.maxp,hmtx:B.hmtx,loca:B.loca,glyf:B.glyf},l={_data:i,_index:s,_offset:o};for(var h in E){var c=Q.findTable(i,h,o);if(c){var d=c[0],u=g[d];u==null&&(u=E[h].parseTab(i,d,c[1],l)),l[h]=g[d]=u}}return l},e=new Uint8Array(n),t={},r=A(e,0,0,t);return[r]},Q.findTable=function(n,A,e){for(var t=Q.B,r=t.readUshort(n,e+4),i=e+12,s=0;s<r;s++){var o=t.readASCII(n,i,4);t.readUint(n,i+4);var g=t.readUint(n,i+8),B=t.readUint(n,i+12);if(o==A)return[g,B];i+=16}return null},Q.T={},Q.B={readShort:function(n,A){var e=Q.B.t.uint16;return e[0]=n[A]<<8|n[A+1],Q.B.t.int16[0]},readUshort:function(n,A){return n[A]<<8|n[A+1]},readUshorts:function(n,A,e){for(var t=[],r=0;r<e;r++)t.push(Q.B.readUshort(n,A+r*2));return t},readUint:function(n,A){var e=Q.B.t.uint8;return e[3]=n[A],e[2]=n[A+1],e[1]=n[A+2],e[0]=n[A+3],Q.B.t.uint32[0]},readASCII:function(n,A,e){for(var t="",r=0;r<e;r++)t+=String.fromCharCode(n[A+r]);return t},t:function(){var n=new ArrayBuffer(8);return{uint8:new Uint8Array(n),int16:new Int16Array(n),uint16:new Uint16Array(n),uint32:new Uint32Array(n)}}()},Q.T.cmap={parseTab:function(n,A,e){var t={tables:[],ids:{},off:A};n=new Uint8Array(n.buffer,A,e),A=0;var r=Q.B,i=r.readUshort,s=Q.T.cmap;i(n,A),A+=2;var o=i(n,A);A+=2;for(var g=[],B=0;B<o;B++){var E=i(n,A);A+=2;var l=i(n,A);A+=2;var h=r.readUint(n,A);A+=4;var c="p"+E+"e"+l,d=g.indexOf(h);if(d==-1){d=t.tables.length;var u={};g.push(h);var P=u.format=i(n,h);P==4?u=s.parse4(n,h,u):P==12&&(u=s.parse12(n,h,u)),t.tables.push(u)}t.ids[c]!=null&&console.log("multiple tables for one platform+encoding: "+c),t.ids[c]=d}return t},parse4:function(n,A,e){var t=Q.B,r=t.readUshort,i=t.readUshorts,s=A;A+=2;var o=r(n,A);A+=2,r(n,A),A+=2;var g=r(n,A);A+=2;var B=g>>>1;e.searchRange=r(n,A),A+=2,e.entrySelector=r(n,A),A+=2,e.rangeShift=r(n,A),A+=2,e.endCount=i(n,A,B),A+=B*2,A+=2,e.startCount=i(n,A,B),A+=B*2,e.idDelta=[];for(var E=0;E<B;E++)e.idDelta.push(t.readShort(n,A)),A+=2;return e.idRangeOffset=i(n,A,B),A+=B*2,e.glyphIdArray=i(n,A,s+o-A>>1),e},parse12:function(n,A,e){var t=Q.B,r=t.readUint;A+=4,r(n,A),A+=4,r(n,A),A+=4;var i=r(n,A)*3;A+=4;for(var s=e.groups=new Uint32Array(i),o=0;o<i;o+=3)s[o]=r(n,A+(o<<2)),s[o+1]=r(n,A+(o<<2)+4),s[o+2]=r(n,A+(o<<2)+8);return e}},Q.T.head={parseTab:function(n,A,e){var t=Q.B,r={};return A+=18,r.unitsPerEm=t.readUshort(n,A),A+=2,A+=16,r.xMin=t.readShort(n,A),A+=2,r.yMin=t.readShort(n,A),A+=2,r.xMax=t.readShort(n,A),A+=2,r.yMax=t.readShort(n,A),A+=2,A+=6,r.indexToLocFormat=t.readShort(n,A),r}},Q.T.hhea={parseTab:function(n,A,e){var t=Q.B,r={};A+=4;for(var i=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],s=0;s<i.length;s++){var o=i[s],g=o=="advanceWidthMax"||o=="numberOfHMetrics"?t.readUshort:t.readShort;r[o]=g(n,A+s*2)}return r}},Q.T.hmtx={parseTab:function(n,A,e,t){for(var r=Q.B,i=[],s=[],o=t.maxp.numGlyphs,g=t.hhea.numberOfHMetrics,B=0,E=0,l=0;l<g;)B=r.readUshort(n,A+(l<<2)),E=r.readShort(n,A+(l<<2)+2),i.push(B),s.push(E),l++;for(;l<o;)i.push(B),s.push(E),l++;return{aWidth:i,lsBearing:s}}},Q.T.maxp={parseTab:function(n,A,e){var t=Q.B,r=t.readUshort,i={};return t.readUint(n,A),A+=4,i.numGlyphs=r(n,A),A+=2,i}},Q.T.loca={parseTab:function(n,A,e,t){var r=Q.B,i=[],s=t.head.indexToLocFormat,o=t.maxp.numGlyphs+1;if(s==0)for(var g=0;g<o;g++)i.push(r.readUshort(n,A+(g<<1))<<1);if(s==1)for(var g=0;g<o;g++)i.push(r.readUint(n,A+(g<<2)));return i}},Q.T.glyf={parseTab:function(n,A,e,t){for(var r=[],i=t.maxp.numGlyphs,s=0;s<i;s++)r.push(null);return r},_parseGlyf:function(n,A){var e=Q.B,t=n._data,r=n.loca;if(r[A]==r[A+1])return null;var i=Q.findTable(t,"glyf",n._offset)[0]+r[A],s={};if(s.noc=e.readShort(t,i),i+=2,s.xMin=e.readShort(t,i),i+=2,s.yMin=e.readShort(t,i),i+=2,s.xMax=e.readShort(t,i),i+=2,s.yMax=e.readShort(t,i),i+=2,s.xMin>=s.xMax||s.yMin>=s.yMax)return null;if(s.noc>0){s.endPts=[];for(var o=0;o<s.noc;o++)s.endPts.push(e.readUshort(t,i)),i+=2;var g=e.readUshort(t,i);if(i+=2,t.length-i<g)return null;i+=g;var B=s.endPts[s.noc-1]+1;s.flags=[];for(var o=0;o<B;o++){var E=t[i];if(i++,s.flags.push(E),E&8){var l=t[i];i++;for(var h=0;h<l;h++)s.flags.push(E),o++}}s.xs=[];for(var o=0;o<B;o++){var c=(s.flags[o]&2)!=0,d=(s.flags[o]&16)!=0;c?(s.xs.push(d?t[i]:-t[i]),i++):d?s.xs.push(0):(s.xs.push(e.readShort(t,i)),i+=2)}s.ys=[];for(var o=0;o<B;o++){var c=(s.flags[o]&4)!=0,d=(s.flags[o]&32)!=0;c?(s.ys.push(d?t[i]:-t[i]),i++):d?s.ys.push(0):(s.ys.push(e.readShort(t,i)),i+=2)}for(var u=0,P=0,o=0;o<B;o++)u+=s.xs[o],P+=s.ys[o],s.xs[o]=u,s.ys[o]=P}else s.parts=[];return s}},typeof module<"u"&&module.exports?module.exports=Q:typeof window<"u"&&(window.Typr=Q);const BA=`data:font/truetype;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMs+QEyQAAAEoAAAAYGNtYXAg7yVJAAAFjAAACSBnbHlmuHLTdAAAErQAAGi0aGVhZFvXdUwAAACsAAAANmhoZWELAQUCAAAA5AAAACRobXR4BACDgAAAAYgAAAQEbG9jYQAy54AAAA6sAAAECG1heHABIgCCAAABCAAAACBuYW1lVs/OSgAAe2gAAAOicG9zdABpADQAAH8MAAAAIAABAAAAAQAAzOWHqV8PPPUAAAQAAAAAAHxiGCcAAAAAfGIYJwAAAAAEAAQAAAAACAACAAEAAAAAAAEAAAQAAAAAAAQAAAAAAAcAAAEAAAAAAAAAAAAAAAAAAAEBAAEAAAEBAIAAIAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAgQAAZAABQAEAgACAAAAAAACAAIAAAACAAAzAMwAAAAABAAAAAAAAACAAACLAABw4wAAAAAAAAAAWUFMLgBAACAmawQAAAAAAAQAAAAAAAFRAAAAAAMABAAAAAAgAAAEAAAABAAAAAQAAAAEAAGABAABAAQAAIAEAACABAAAgAQAAIAEAAGABAABAAQAAQAEAACABAABAAQAAIAEAACABAABAAQAAIAEAACABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAABAAQAAIAEAAEABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAABAAQAAIAEAAEABAAAgAQAAIAEAAEABAAAgAQAAIAEAACABAAAgAQAAIAEAAEABAAAgAQAAIAEAAGABAAAgAQAAIAEAAGABAAAgAQAAIAEAACABAAAgAQAAIAEAAEABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAAAgAQAAIAEAACABAABgAQAAQAEAACABAAAAAQAAgAEAACABAAAgAQAAIAEAACABAACAAQAAAAEAAIABAABgAQAAgAEAACABAAAgAQAAAAEAACABAAAAAQAAAAEAAAABAAAAAQAAAAEAAIABAADAAQAAAAEAAAABAAAgAQAAYAEAAAABAAAAAQAAIAEAAAABAAAgAQAAIAEAACABAAAAAQAAIAEAAAABAAAAAQAAIAEAAGABAAAAAQAAAAEAAAABAAAAAQAAIAEAACABAAAAAQAAIA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==\r
|
|
8
|
-
`;class EA{extractCharacters(A){var t;const e=[];return(t=A==null?void 0:A.cmap)!=null&&t.tables?(A.cmap.tables.forEach(r=>{if(r.format===4){const i=this._extractCharactersFromFormat4Table(r);e.push(...i)}else if(r.format===12){const i=this._extractCharactersFromFormat12Table(r);e.push(...i)}}),[...new Set(e)]):[]}_extractCharactersFromFormat4Table(A){const e=[];if(!A.startCount||!A.endCount||!A.idRangeOffset||!A.idDelta)return e;for(let t=0;t<A.startCount.length;t++){const r=A.startCount[t],i=A.endCount[t];if(!(r===65535&&i===65535)){for(let s=r;s<=i;s++)if(this._calculateGlyphIndexFormat4(A,s,t)>0){const g=String.fromCodePoint(s);e.push(g)}}}return e}_extractCharactersFromFormat12Table(A){const e=[];if(!A.groups)return e;for(let t=0;t<A.groups.length;t+=3){const r=A.groups[t],i=A.groups[t+1],s=A.groups[t+2];for(let o=r;o<=i;o++)if(s+(o-r)>0){const B=String.fromCodePoint(o);e.push(B)}}return e}_calculateGlyphIndexFormat4(A,e,t){if(A.idRangeOffset[t]===0)return e+A.idDelta[t]&65535;{const r=A.idRangeOffset[t]/2+(e-A.startCount[t])-(A.startCount.length-t);if(r>=0&&A.glyphIdArray&&r<A.glyphIdArray.length){const i=A.glyphIdArray[r];if(i!==0)return i+A.idDelta[t]&65535}}return 0}filterProblematicCharacters(A){return A.filter(e=>this._isValidCharacter(e))}_isValidCharacter(A){const e=A.codePointAt(0)||0;return!(e>=0&&e<=31&&e!==9&&e!==10&&e!==13||e>=127&&e<=159)}}class lA{constructor(A){a(this,"_textureCanvas");a(this,"_textureContext");a(this,"_renderer");this._renderer=A,this._textureCanvas=document.createElement("canvas"),this._textureContext=this._textureCanvas.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(A,e,t,r){const i=A.length,s=Math.ceil(Math.sqrt(i)),o=Math.ceil(i/s),g=e.width*s,B=e.height*o;this._setupCanvas(g,B,t,r),this._renderCharactersToCanvas(A,e,s,t),this._applyBlackWhiteThreshold();const E=this._renderer.createFramebuffer(g,B,{filter:"nearest"});return E.update(this._textureCanvas),{framebuffer:E,columns:s,rows:o}}_setupCanvas(A,e,t,r){this._textureCanvas.width=A,this._textureCanvas.height=e,this._textureCanvas.style.width=A+"px",this._textureCanvas.style.height=A+"px",this._textureContext.imageSmoothingEnabled=!1,this._textureCanvas.style.imageRendering="pixelated",this._textureContext.fillStyle="black",this._textureContext.fillRect(0,0,A,e),this._textureContext.font=`${t}px ${r}`,this._textureContext.textBaseline="top",this._textureContext.textAlign="left",this._textureContext.fillStyle="white"}_renderCharactersToCanvas(A,e,t,r){for(let i=0;i<A.length;i++){const s=i%t,o=Math.floor(i/t),g=s*e.width+e.width*.5,B=o*e.height+e.height*.5,E=Math.round(g-e.width*.5),l=Math.round(B-r*.5);this._textureContext.fillText(A[i].character,E,l)}}_applyBlackWhiteThreshold(A=128){const e=this._textureContext.getImageData(0,0,this._textureCanvas.width,this._textureCanvas.height),t=e.data;for(let r=0;r<t.length;r+=4){const i=.299*t[r]+.587*t[r+1]+.114*t[r+2],s=A+32,o=i>s?255:0;t[r]=o,t[r+1]=o,t[r+2]=o}this._textureContext.putImageData(e,0,0)}}class hA{constructor(){a(this,"_tempCanvas");a(this,"_tempContext");this._tempCanvas=document.createElement("canvas"),this._tempContext=this._tempCanvas.getContext("2d")}calculateMaxGlyphDimensions(A,e,t){this._tempContext.font=`${e}px ${t}`;let r=0,i=0;for(const s of A){const o=this._tempContext.measureText(s),g=o.width,B=o.actualBoundingBoxAscent+o.actualBoundingBoxDescent;g>0&&(r=Math.max(r,g),i=Math.max(i,B))}return{width:Math.ceil(r),height:Math.ceil(i)}}}class QA{createCharacterObjects(A,e){return A.map((t,r)=>{const i=t.codePointAt(0)||0,s=this._generateCharacterColor(r);let o=0;if(e.hmtx&&e.hmtx.aWidth){const g=this._getGlyphIndex(e,i);g>0&&e.hmtx.aWidth[g]!==void 0&&(o=e.hmtx.aWidth[g])}return{character:t,unicode:i,color:s,advanceWidth:o}})}_getGlyphIndex(A,e){const t=A.cmap;if(!t||!t.tables)return 0;for(const r of t.tables)if(r.format===4){for(let i=0;i<r.startCount.length;i++)if(e>=r.startCount[i]&&e<=r.endCount[i]){if(r.idRangeOffset[i]===0)return e+r.idDelta[i]&65535;{const s=r.idRangeOffset[i]/2+(e-r.startCount[i])-(r.startCount.length-i);if(s>=0&&s<r.glyphIdArray.length){const o=r.glyphIdArray[s];if(o!==0)return o+r.idDelta[i]&65535}}}}return 0}_generateCharacterColor(A){const e=A%256,t=Math.floor(A/256)%256,r=Math.floor(A/65536)%256;return[e,t,r]}getCharacterColor(A,e){if(!m.validate(typeof A=="string"&&A.length===1,"Character must be a single character string.",{method:"getCharacterColor",providedValue:A}))return[0,0,0];const t=e.find(r=>r.character===A);return t?t.color:[0,0,0]}getCharacterColors(A,e){return m.validate(typeof A=="string"&&A.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:A})?A.split("").map(t=>this.getCharacterColor(t,e)||[0,0,0]):[[0,0,0]]}}class J{constructor(A,e=16){a(this,"_font");a(this,"_characters",[]);a(this,"_fontFramebuffer");a(this,"_fontSize",16);a(this,"_textureColumns",0);a(this,"_textureRows",0);a(this,"_maxGlyphDimensions",{width:0,height:0});a(this,"_fontFace");a(this,"_fontFamilyName","UrsaFont");a(this,"_characterExtractor");a(this,"_textureAtlas");a(this,"_metricsCalculator");a(this,"_characterColorMapper");this._fontSize=e,this._characterExtractor=new EA,this._textureAtlas=new lA(A),this._metricsCalculator=new hA,this._characterColorMapper=new QA}async initialize(A){let e;if(A){const t=await fetch(A);if(!t.ok)throw new f(`Failed to load font file: ${t.status} ${t.statusText}`);e=await t.arrayBuffer()}else e=await(await fetch(BA)).arrayBuffer();await this._loadFontFace(e),this._font=Q.parse(e)[0],await this._initializeFont()}setFontSize(A){if(A===void 0)return this._fontSize;this._fontSize=A,this._maxGlyphDimensions=this._metricsCalculator.calculateMaxGlyphDimensions(this._characters.map(t=>t.character),this._fontSize,this._fontFamilyName);const e=this._textureAtlas.createTextureAtlas(this._characters,this._maxGlyphDimensions,this._fontSize,this._fontFamilyName);this._fontFramebuffer=e.framebuffer,this._textureColumns=e.columns,this._textureRows=e.rows}async loadFont(A){try{const e=await fetch(A);if(!e.ok)throw new f(`Failed to load font file: ${e.status} ${e.statusText}`);const t=await e.arrayBuffer();await this._loadFontFace(t);const r=Q.parse(t);if(!r||r.length===0)throw new Error("Failed to parse font file");this._font=r[0],await this._initializeFont()}catch(e){throw new f(`Failed to load font: ${e instanceof Error?e.message:"Unknown error"}`,e)}}async _loadFontFace(A){const e=Date.now();this._fontFamilyName=this._fontFamilyName==="UrsaFont"?"UrsaFont":`CustomFont_${e}`,this._fontFace=new FontFace(this._fontFamilyName,A),await this._fontFace.load(),document.fonts.add(this._fontFace)}async _initializeFont(){const A=this._characterExtractor.extractCharacters(this._font),e=this._characterExtractor.filterProblematicCharacters(A);this._characters=this._characterColorMapper.createCharacterObjects(e,this._font),this._maxGlyphDimensions=this._metricsCalculator.calculateMaxGlyphDimensions(e,this._fontSize,this._fontFamilyName);const t=this._textureAtlas.createTextureAtlas(this._characters,this._maxGlyphDimensions,this._fontSize,this._fontFamilyName);this._fontFramebuffer=t.framebuffer,this._textureColumns=t.columns,this._textureRows=t.rows}getCharacterColor(A){return this._characterColorMapper.getCharacterColor(A,this._characters)}getCharacterColors(A){return this._characterColorMapper.getCharacterColors(A,this._characters)}hasAllCharacters(A){if(typeof A!="string"||A.length===0)return!1;const e=new Set(this._characters.map(t=>t.character));for(const t of A)if(!e.has(t))return!1;return!0}get fontFramebuffer(){return this._fontFramebuffer}get characters(){return this._characters}get textureColumns(){return this._textureColumns}get textureRows(){return this._textureRows}get maxGlyphDimensions(){return this._maxGlyphDimensions}dispose(){this._fontFramebuffer.dispose(),document.fonts.delete(this._fontFace),this._fontFramebuffer=null,this._fontFace=null,this._font=null,this._characters=[],this._maxGlyphDimensions={width:0,height:0},this._textureColumns=0,this._textureRows=0}get fontSize(){return this._fontSize}get font(){return this._font}}class j{constructor(A,e,t){a(this,"_cols");a(this,"_rows");a(this,"_width");a(this,"_height");a(this,"_offsetX");a(this,"_offsetY");a(this,"_fixedDimensions",!1);a(this,"_canvas");a(this,"_cellWidth");a(this,"_cellHeight");this._canvas=A,this._cellWidth=e,this._cellHeight=t,this.reset()}reset(){if(!this._fixedDimensions){const A=this._canvas.getBoundingClientRect();let e=Math.round(A.width),t=Math.round(A.height);[this._cols,this._rows]=[Math.floor(e/this._cellWidth),Math.floor(t/this._cellHeight)]}this._resizeGrid()}_resizeGrid(){const A=this._canvas.getBoundingClientRect();let e=Math.round(A.width),t=Math.round(A.height);this._width=this._cols*this._cellWidth,this._height=this._rows*this._cellHeight,this._offsetX=Math.floor((e-this._width)/2),this._offsetY=Math.floor((t-this._height)/2)}resizeCellPixelDimensions(A,e){[this._cellWidth,this._cellHeight]=[A,e],this.reset()}resizeGridDimensions(A,e){this._fixedDimensions=!0,[this._cols,this._rows]=[A,e],this._resizeGrid()}resetGridDimensions(){this._fixedDimensions=!1,this.reset()}resize(){this._fixedDimensions?this._resizeGrid():this.reset()}fixedDimensions(A){if(A===void 0)return this._fixedDimensions;this._fixedDimensions=A}get cellWidth(){return this._cellWidth}get cellHeight(){return this._cellHeight}dispose(){this._canvas=null,this._cols=0,this._rows=0,this._width=0,this._height=0,this._offsetX=0,this._offsetY=0,this._cellWidth=0,this._cellHeight=0}get cols(){return this._cols}get rows(){return this._rows}get width(){return this._width}get height(){return this._height}get offsetX(){return this._offsetX}get offsetY(){return this._offsetY}}class K{constructor(A,e=!1,t={}){a(this,"_canvas");a(this,"captureSource");a(this,"_isStandalone");this.captureSource=A,this._isStandalone=e,this._canvas=this.createCanvas(t.width,t.height)}createCanvas(A,e){var r;const t=document.createElement("canvas");if(t.className="textmodeCanvas",t.style.imageRendering="pixelated",this._isStandalone)t.width=A||800,t.height=e||600,document.body.appendChild(t);else{const i=this.captureSource.getBoundingClientRect();let s=Math.round(i.width),o=Math.round(i.height);if(this.captureSource instanceof HTMLVideoElement){const E=this.captureSource;(s===0||o===0)&&E.videoWidth>0&&E.videoHeight>0&&(s=E.videoWidth,o=E.videoHeight)}t.width=s,t.height=o,t.style.position="absolute",t.style.pointerEvents="none";const g=window.getComputedStyle(this.captureSource);let B=parseInt(g.zIndex||"0",10);isNaN(B)&&(B=0),t.style.zIndex=(B+1).toString(),this.positionOverlayCanvas(t),(r=this.captureSource.parentNode)==null||r.insertBefore(t,this.captureSource.nextSibling)}return t}positionOverlayCanvas(A){const e=this.captureSource.getBoundingClientRect();let t=this.captureSource.offsetParent;if(t&&t!==document.body){const r=t.getBoundingClientRect();A.style.top=e.top-r.top+"px",A.style.left=e.left-r.left+"px"}else A.style.top=e.top+window.scrollY+"px",A.style.left=e.left+window.scrollX+"px"}resize(A,e){if(this._isStandalone)this._canvas.width=A??this._canvas.width,this._canvas.height=e??this._canvas.height;else{const t=this.captureSource.getBoundingClientRect();let r=Math.round(t.width),i=Math.round(t.height);if(this.captureSource instanceof HTMLVideoElement){const s=this.captureSource;(r===0||i===0)&&s.videoWidth>0&&s.videoHeight>0&&(r=s.videoWidth,i=s.videoHeight)}this._canvas.width=r,this._canvas.height=i,this.positionOverlayCanvas(this._canvas)}}getWebGLContext(){const A={alpha:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"},e=this._canvas.getContext("webgl2",A)||this._canvas.getContext("webgl",A);if(!e)throw new f("WebGL context could not be created. Ensure your browser supports WebGL.");return e}dispose(){if(this._canvas){const A=this._canvas.getContext("webgl")||this._canvas.getContext("webgl2");if(A){const e=A.getExtension("WEBGL_lose_context");e&&e.loseContext()}this._canvas.parentNode&&this._canvas.parentNode.removeChild(this._canvas),this._canvas=null}this.captureSource=null}get canvas(){return this._canvas}get width(){return this._canvas.width}get height(){return this._canvas.height}}class y{constructor(A,e,t,r={}){a(this,"renderer");a(this,"fontManager");a(this,"grid");a(this,"_characterFramebuffer");a(this,"_primaryColorFramebuffer");a(this,"_secondaryColorFramebuffer");a(this,"_rotationFramebuffer");a(this,"_transformFramebuffer");a(this,"_options");this.renderer=A,this.fontManager=e,this.grid=t,this._options=r,this._characterFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._rotationFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._transformFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows)}resize(){this._characterFramebuffer.resize(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._rotationFramebuffer.resize(this.grid.cols,this.grid.rows),this._transformFramebuffer.resize(this.grid.cols,this.grid.rows)}enabled(A){this._options.enabled=A}enable(){this.enabled(!0)}disable(){this.enabled(!1)}dispose(){this._characterFramebuffer.dispose(),this._primaryColorFramebuffer.dispose(),this._secondaryColorFramebuffer.dispose(),this._rotationFramebuffer.dispose(),this._transformFramebuffer.dispose(),this._characterFramebuffer=null,this._primaryColorFramebuffer=null,this._secondaryColorFramebuffer=null,this._rotationFramebuffer=null,this._transformFramebuffer=null}get characterFramebuffer(){return this._characterFramebuffer}get primaryColorFramebuffer(){return this._primaryColorFramebuffer}get secondaryColorFramebuffer(){return this._secondaryColorFramebuffer}get rotationFramebuffer(){return this._rotationFramebuffer}get transformFramebuffer(){return this._transformFramebuffer}get options(){return this._options}}class cA{constructor(A,e){a(this,"_framebuffer");a(this,"_renderer");a(this,"_colors");this._renderer=A,this._colors=e;const t=Math.max(this._colors.length,1);this._framebuffer=this._renderer.createFramebuffer(t,1),this._updateFramebuffer()}_updateFramebuffer(){if(!this._framebuffer)return;const A=Math.max(this._colors.length,1),e=1;this._framebuffer.width!==A&&this._framebuffer.resize(A,e);const t=new Uint8Array(A*e*4);for(let r=0;r<A;r++){const i=r<this._colors.length?this._colors[r]:[0,0,0],s=r*4;t[s]=i[0],t[s+1]=i[1],t[s+2]=i[2],t[s+3]=255}this._framebuffer.updatePixels(t,A,e)}setColors(A){this._colors=A,this._updateFramebuffer()}get colors(){return this._colors}get framebuffer(){return this._framebuffer}get texture(){return this._framebuffer.texture}}class Y extends y{constructor(e,t,r,i={}){super(e,t,r,i);a(this,"palette");this.palette=new cA(this.renderer,this.fontManager.getCharacterColors(" .:-=+*%@#"))}characters(e){m.validate(this.fontManager.hasAllCharacters(e),"One or more characters do not exist in the current font.",{method:"characters",providedValue:e})&&(this._options.characters=e,this.palette.setColors(this.fontManager.getCharacterColors(e)))}characterColor(e,t,r,i=255){let s,o,g,B;if(typeof e=="string"){const E=this.parseHexColor(e);if(!E){m.validate(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:"characterColor",providedValue:e});return}[s,o,g,B]=E}else if(s=e,o=t!==void 0?t:e,g=r!==void 0?r:e,B=i,!m.validate([s,o,g,B].every(E=>E>=0&&E<=255),"Character color values must be between 0 and 255",{method:"characterColor",providedValues:{r:s,g:o,b:g,a:B}}))return;this._options.characterColor=[s,o,g,B]}characterColorMode(e){m.validate(["sampled","fixed"].includes(e),"Invalid character color mode. Must be 'sampled' or 'fixed'.",{method:"characterColorMode",providedValue:e})&&(this._options.characterColorMode=e)}cellColor(e,t,r,i=255){let s,o,g,B;if(typeof e=="string"){const E=this.parseHexColor(e);if(!E){m.validate(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:"cellColor",providedValue:e});return}[s,o,g,B]=E}else if(s=e,o=t!==void 0?t:e,g=r!==void 0?r:e,B=i,!m.validate([s,o,g,B].every(E=>E>=0&&E<=255),"Cell color values must be between 0 and 255",{method:"cellColor",providedValues:{r:s,g:o,b:g,a:B}}))return;this._options.cellColor=[s,o,g,B]}cellColorMode(e){m.validate(["sampled","fixed"].includes(e),"Invalid cell color mode. Must be 'sampled' or 'fixed'.",{method:"cellColorMode",providedValue:e})&&(this._options.cellColorMode=e)}invert(e){m.validate(typeof e=="boolean"||typeof e=="number"&&Number.isInteger(e),"Invert must be a boolean value or an integer (0 for false, any other number for true).",{method:"invert",providedValue:e})&&(this._options.invert=!!e)}rotation(e){if(!m.validate(typeof e=="number","Rotation angle must be a number.",{method:"rotation",providedValue:e}))return;e=e%360,e<0&&(e+=360);const t=e*255/360,r=Math.floor(t)/255,i=Math.round(t-r);this._options.rotation=[r,i,0,1]}flipHorizontally(e){m.validate(typeof e=="boolean"||typeof e=="number"&&Number.isInteger(e),"Flip horizontally must be a boolean value or an integer (0 for false, any other number for true).",{method:"flipHorizontally",providedValue:e})&&(this._options.flipHorizontally=!!e)}flipVertically(e){m.validate(typeof e=="boolean"||typeof e=="number"&&Number.isInteger(e),"Flip vertically must be a boolean value or an integer (0 for false, any other number for true).",{method:"flipVertically",providedValue:e})&&(this._options.flipVertically=!!e)}parseHexColor(e){if(e=e.replace(/^#/,""),!/^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(e))return null;e.length===3&&(e=e.split("").map(s=>s+s).join(""));const t=parseInt(e.slice(0,2),16),r=parseInt(e.slice(2,4),16),i=parseInt(e.slice(4,6),16);return[t,r,i,255]}}var uA="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);}}",dA="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);}}",fA="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);}}",CA="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);}}",mA="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);}";const DA={enabled:!0,characters:" .:-=+*%@#",characterColor:[255,255,255,255],characterColorMode:"sampled",cellColor:[0,0,0,255],cellColorMode:"fixed",invert:!1,rotation:[0,0,0,255],flipHorizontally:!1,flipVertically:!1,brightnessRange:[0,255]};class k extends Y{constructor(e,t,r){super(e,t,r,{...DA});a(this,"sampleShader");a(this,"colorFillShader");a(this,"charMappingShader");a(this,"transformFillShader");a(this,"rotationFillShader");a(this,"sampleFramebuffer");this.sampleShader=new w(e.context,_,uA),this.colorFillShader=new w(e.context,_,dA),this.transformFillShader=new w(e.context,_,fA),this.rotationFillShader=new w(e.context,_,CA),this.charMappingShader=new w(e.context,_,mA),this.sampleFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows)}convert(e){this.sampleFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.sampleShader),this.renderer.setUniform("u_sketchTexture",e),this.renderer.setUniform("u_gridCellDimensions",[this.grid.cols,this.grid.rows]),this.renderer.setUniform("u_brightnessRange",this._options.brightnessRange),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this.sampleFramebuffer.end(),this._primaryColorFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.colorFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_fillColor",this._options.characterColor),this.renderer.setUniform("u_useFixedColor",this._options.characterColorMode==="fixed"),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.end(),this._secondaryColorFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.colorFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_fillColor",this._options.cellColor),this.renderer.setUniform("u_useFixedColor",this._options.cellColorMode==="fixed"),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.end(),this._transformFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.transformFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_invert",this._options.invert),this.renderer.setUniform("u_flipHorizontally",this._options.flipHorizontally),this.renderer.setUniform("u_flipVertically",this._options.flipVertically),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._transformFramebuffer.end(),this._rotationFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.rotationFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_rotationColor",this._options.rotation),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._rotationFramebuffer.end(),this._characterFramebuffer.begin(),this.renderer.clear(0,0,0,0),this.renderer.shader(this.charMappingShader),this.renderer.setUniform("u_colorSampleFramebuffer",this.sampleFramebuffer.texture),this.renderer.setUniform("u_charPaletteTexture",this.palette.texture),this.renderer.setUniform("u_charPaletteSize",[this.palette.colors.length,1]),this.renderer.setUniform("u_brightnessRange",this._options.brightnessRange),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._characterFramebuffer.end()}resize(){super.resize(),this.sampleFramebuffer.resize(this.grid.cols,this.grid.rows)}brightnessRange(e){m.validate(Array.isArray(e)&&e.length===2&&e.every(t=>typeof t=="number"&&t>=0&&t<=255),"Brightness range must be an array of two numbers between 0 and 255.",{method:"brightnessRange",providedValue:e})&&(this._options.brightnessRange=e)}}const PA=Object.freeze(Object.defineProperty({__proto__:null,TextmodeBrightnessConverter:k,TextmodeConverter:y,TextmodeFeatureConverter:Y},Symbol.toStringTag,{value:"Module"}));var pA="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);vec2 charCoord=vec2(charCol,charRow)/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);}";class Z{constructor(A,e,t){a(this,"renderer");a(this,"font");a(this,"grid");a(this,"converters");a(this,"_resultFramebuffer");a(this,"_asciiShader");a(this,"_characterFramebuffer");a(this,"_primaryColorFramebuffer");a(this,"_secondaryColorFramebuffer");a(this,"_rotationFramebuffer");a(this,"_transformFramebuffer");this.renderer=A,this.font=e,this.grid=t,this._asciiShader=this.renderer.createShader(_,pA),this.converters=[{name:"brightness",converter:new k(A,e,t)},{name:"custom",converter:new y(A,e,t)}],this._characterFramebuffer=this.renderer.createFramebuffer(t.cols,t.rows),this._primaryColorFramebuffer=this.renderer.createFramebuffer(t.cols,t.rows),this._secondaryColorFramebuffer=this.renderer.createFramebuffer(t.cols,t.rows),this._rotationFramebuffer=this.renderer.createFramebuffer(t.cols,t.rows),this._transformFramebuffer=this.renderer.createFramebuffer(t.cols,t.rows),this._resultFramebuffer=this.renderer.createFramebuffer(this.grid.width,this.grid.height)}render(A){for(const t of this.converters){const r=t.converter;r.options.enabled&&r instanceof Y&&r.convert(A)}const e=(t,r)=>{t.begin(),this.renderer.clear();for(const i of this.converters){const s=i.converter;s.options.enabled&&this.renderer.image(r(s),0,0)}t.end()};e(this._characterFramebuffer,t=>t.characterFramebuffer),e(this._primaryColorFramebuffer,t=>t.primaryColorFramebuffer),e(this._secondaryColorFramebuffer,t=>t.secondaryColorFramebuffer),e(this._rotationFramebuffer,t=>t.rotationFramebuffer),e(this._transformFramebuffer,t=>t.transformFramebuffer),this._resultFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this._asciiShader),this.renderer.setUniform("u_characterTexture",this.font.fontFramebuffer),this.renderer.setUniform("u_charsetDimensions",[this.font.textureColumns,this.font.textureRows]),this.renderer.setUniform("u_asciiCharacterTexture",this._characterFramebuffer.texture),this.renderer.setUniform("u_primaryColorTexture",this._primaryColorFramebuffer.texture),this.renderer.setUniform("u_secondaryColorTexture",this._secondaryColorFramebuffer.texture),this.renderer.setUniform("u_transformTexture",this._transformFramebuffer.texture),this.renderer.setUniform("u_rotationTexture",this._rotationFramebuffer.texture),this.renderer.setUniform("u_captureTexture",A.texture),this.renderer.setUniform("u_backgroundMode",!1),this.renderer.setUniform("u_captureDimensions",[A.width,A.height]),this.renderer.setUniform("u_gridCellDimensions",[this.grid.cols,this.grid.rows]),this.renderer.setUniform("u_gridPixelDimensions",[this.grid.width,this.grid.height]),this.renderer.rect(0,0,this._resultFramebuffer.width,this._resultFramebuffer.height),this._resultFramebuffer.end()}get(A){if(!m.validate(typeof A=="string"&&A.length>0,"Converter name must be a non-empty string.",{method:"converter",providedValue:A}))return;const e=this.converters.find(r=>r.name===A),t=e==null?void 0:e.converter;if(m.validate(t instanceof y,`Converter "${A}" is not a valid TextmodeConverter.`,{method:"converter",providedValue:A,converterInstance:t}))return t}add(A,e){if(!m.validate(typeof A=="string"&&A.length>0,"Converter name must be a non-empty string.",{method:"add",providedValue:A})||!m.validate(e==="brightness"||e==="custom",`Converter type must be either "brightness" or "custom". Provided: ${e}`,{method:"add",providedValue:e}))return;let t;return e==="brightness"?t=new k(this.renderer,this.font,this.grid):t=new y(this.renderer,this.font,this.grid),this.converters.push({name:A,converter:t}),t}remove(A){if(!m.validate(typeof A=="string"||A instanceof y,"Parameter must be either a string (converter name) or a TextmodeConverter instance.",{method:"remove",providedValue:A}))return;let e=-1;if(typeof A=="string"){if(!m.validate(A.length>0,"Converter name must be a non-empty string.",{method:"remove",providedValue:A}))return;e=this.converters.findIndex(t=>t.name===A)}else e=this.converters.findIndex(t=>t.converter===A);m.validate(e!==-1,typeof A=="string"?`Converter with name "${A}" not found in pipeline.`:"Converter instance not found in pipeline.",{method:"remove",providedValue:A,convertersCount:this.converters.length})&&this.converters.splice(e,1)}get texture(){return this._resultFramebuffer}resize(){this._resultFramebuffer.resize(this.grid.width,this.grid.height),this._characterFramebuffer.resize(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._rotationFramebuffer.resize(this.grid.cols,this.grid.rows),this._transformFramebuffer.resize(this.grid.cols,this.grid.rows);for(const A of this.converters)A.converter.resize()}hasEnabledConverters(){return this.converters.some(A=>A.converter.options.enabled)}disable(){for(const A of this.converters)A.converter.disable()}enable(){for(const A of this.converters)A.converter.enable()}dispose(){for(const A of this.converters)A.converter.dispose();this._characterFramebuffer.dispose(),this._primaryColorFramebuffer.dispose(),this._secondaryColorFramebuffer.dispose(),this._rotationFramebuffer.dispose(),this._transformFramebuffer.dispose(),this._resultFramebuffer.dispose(),this._asciiShader.dispose(),this.converters=[],this._characterFramebuffer=null,this._primaryColorFramebuffer=null,this._secondaryColorFramebuffer=null,this._rotationFramebuffer=null,this._transformFramebuffer=null,this._resultFramebuffer=null,this._asciiShader=null}get characterFramebuffer(){return this._characterFramebuffer}get primaryColorFramebuffer(){return this._primaryColorFramebuffer}get secondaryColorFramebuffer(){return this._secondaryColorFramebuffer}get rotationFramebuffer(){return this._rotationFramebuffer}get transformFramebuffer(){return this._transformFramebuffer}}class V{extractFramebufferData(A){const e=A.get("brightness"),t=e==null?void 0:e.characterFramebuffer,r=e==null?void 0:e.primaryColorFramebuffer,i=e==null?void 0:e.secondaryColorFramebuffer,s=e==null?void 0:e.transformFramebuffer,o=e==null?void 0:e.rotationFramebuffer;return t==null||t.loadPixels(),r==null||r.loadPixels(),i==null||i.loadPixels(),s==null||s.loadPixels(),o==null||o.loadPixels(),{characterPixels:(t==null?void 0:t.pixels)||new Uint8Array(0),primaryColorPixels:(r==null?void 0:r.pixels)||new Uint8Array(0),secondaryColorPixels:(i==null?void 0:i.pixels)||new Uint8Array(0),transformPixels:(s==null?void 0:s.pixels)||new Uint8Array(0),rotationPixels:(o==null?void 0:o.pixels)||new Uint8Array(0)}}getCharacterIndex(A,e){const t=A[e],r=A[e+1];return t+(r<<8)}pixelsToRGBA(A,e){return{r:A[e],g:A[e+1],b:A[e+2],a:A[e+3]}}}class O{createBlob(A,e){return new Blob([A],{type:e})}downloadFile(A,e,t){try{const r=this.createBlob(A,t),i=URL.createObjectURL(r),s=document.createElement("a");s.href=i,s.download=e,s.style.display="none",s.rel="noopener",document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(i)}catch(r){throw console.error("Failed to download file:",r),new Error(`File download failed: ${r instanceof Error?r.message:"Unknown error"}`)}}generateTimestamp(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}generateDateTimeString(){const A=new Date,e=A.toISOString().split("T")[0],t=A.toTimeString().split(" ")[0].replace(/:/g,"-");return{date:e,time:t}}sanitizeFilename(A){return A.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}generateDefaultFilename(){return`'textmode-export'-${this.generateTimestamp()}`}}class IA extends V{extractTransformData(A,e,t){const r=A[t],i=A[t+1],s=A[t+2],o=r===255,g=i===255,B=s===255,E=e[t],l=e[t+1],h=E+l/255,c=Math.round(h*360/255*100)/100;return{isInverted:o,flipHorizontal:g,flipVertical:B,rotation:c}}calculateCellPosition(A,e,t){return{x:A,y:e,cellX:A*t.cellWidth,cellY:e*t.cellHeight}}extractSVGCellData(A,e){const t=[];let r=0;for(let i=0;i<e.rows;i++)for(let s=0;s<e.cols;s++){const o=r*4,g=this.getCharacterIndex(A.characterPixels,o);let B=this.pixelsToRGBA(A.primaryColorPixels,o),E=this.pixelsToRGBA(A.secondaryColorPixels,o);const l=this.extractTransformData(A.transformPixels,A.rotationPixels,o);if(l.isInverted){const c=B;B=E,E=c}const h=this.calculateCellPosition(s,i,e);t.push({charIndex:g,primaryColor:B,secondaryColor:E,transform:l,position:h}),r++}return t}}class wA{getGlyphIndex(A,e){const t=A.cmap;if(!t||!t.tables)return 0;for(const r of t.tables)if(r.format===4){for(let i=0;i<r.startCount.length;i++)if(e>=r.startCount[i]&&e<=r.endCount[i]){if(r.idRangeOffset[i]===0)return e+r.idDelta[i]&65535;{const s=r.idRangeOffset[i]/2+(e-r.startCount[i])-(r.startCount.length-i);if(s>=0&&s<r.glyphIdArray.length){const o=r.glyphIdArray[s];if(o!==0)return o+r.idDelta[i]&65535}}}}return 0}createEmptyPath(){return{getBoundingBox:()=>({x1:0,y1:0,x2:0,y2:0}),toSVG:()=>""}}createGlyphPath(A,e,t,r,i){if(!e||!e.xs||e.xs.length===0)return this.createEmptyPath();const s=i/A.head.unitsPerEm;return{getBoundingBox:()=>({x1:t+e.xMin*s,y1:r+-e.yMax*s,x2:t+e.xMax*s,y2:r+-e.yMin*s}),toSVG:()=>this.glyphToSVGPath(e,t,r,s)}}glyphToSVGPath(A,e,t,r){if(!A||!A.xs)return"";const{xs:i,ys:s,endPts:o,flags:g}=A;if(!i||!s||!o||!g)return"";let B="",E=0;for(let l=0;l<o.length;l++){const h=o[l];if(!(h<E)){if(h>=E){const c=e+i[E]*r,d=t-s[E]*r;B+=`M${c.toFixed(2)},${d.toFixed(2)}`;let u=E+1;for(;u<=h;)if((g[u]&1)!==0){const p=e+i[u]*r,D=t-s[u]*r;B+=`L${p.toFixed(2)},${D.toFixed(2)}`,u++}else{const p=e+i[u]*r,D=t-s[u]*r;let I=u+1>h?E:u+1;if((g[I]&1)!==0){const F=e+i[I]*r,b=t-s[I]*r;B+=`Q${p.toFixed(2)},${D.toFixed(2)} ${F.toFixed(2)},${b.toFixed(2)}`,u=I+1}else{const F=e+i[I]*r,b=t-s[I]*r,L=(p+F)/2,M=(D+b)/2;B+=`Q${p.toFixed(2)},${D.toFixed(2)} ${L.toFixed(2)},${M.toFixed(2)}`,u=I}}B+="Z"}E=h+1}}return B}generateCharacterPath(A,e,t,r,i){try{const s=A.codePointAt(0)||0,o=this.getGlyphIndex(e,s);if(o===0)return this.createEmptyPath();let g=null;try{e.glyf&&e.glyf[o]!==null?g=e.glyf[o]:Q&&Q.T&&Q.T.glyf&&Q.T.glyf._parseGlyf&&(g=Q.T.glyf._parseGlyf(e,o),e.glyf&&g&&(e.glyf[o]=g))}catch(B){console.warn(`Failed to parse glyph ${o}:`,B)}return g?this.createGlyphPath(e,g,t,r,i):this.createEmptyPath()}catch(s){return console.warn(`Failed to generate path for character "${A}":`,s),this.createEmptyPath()}}generatePositionedCharacterPath(A,e,t,r,i,s,o,g){try{const B=o/e.head.unitsPerEm,E=g*B,l=t+(i-E)/2,h=r+(s+o*.7)/2;return this.generateCharacterPath(A,e,l,h,o).toSVG()||null}catch(B){return console.warn(`Failed to generate positioned character path for "${A}":`,B),null}}}class _A{constructor(){a(this,"pathGenerator");this.pathGenerator=new wA}generateSVGHeader(A){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
8
|
+
`;class EA{extractCharacters(A){var t;const e=[];return(t=A==null?void 0:A.cmap)!=null&&t.tables?(A.cmap.tables.forEach(r=>{if(r.format===4){const i=this._extractCharactersFromFormat4Table(r);e.push(...i)}else if(r.format===12){const i=this._extractCharactersFromFormat12Table(r);e.push(...i)}}),[...new Set(e)]):[]}_extractCharactersFromFormat4Table(A){const e=[];if(!A.startCount||!A.endCount||!A.idRangeOffset||!A.idDelta)return e;for(let t=0;t<A.startCount.length;t++){const r=A.startCount[t],i=A.endCount[t];if(!(r===65535&&i===65535)){for(let s=r;s<=i;s++)if(this._calculateGlyphIndexFormat4(A,s,t)>0){const g=String.fromCodePoint(s);e.push(g)}}}return e}_extractCharactersFromFormat12Table(A){const e=[];if(!A.groups)return e;for(let t=0;t<A.groups.length;t+=3){const r=A.groups[t],i=A.groups[t+1],s=A.groups[t+2];for(let o=r;o<=i;o++)if(s+(o-r)>0){const B=String.fromCodePoint(o);e.push(B)}}return e}_calculateGlyphIndexFormat4(A,e,t){if(A.idRangeOffset[t]===0)return e+A.idDelta[t]&65535;{const r=A.idRangeOffset[t]/2+(e-A.startCount[t])-(A.startCount.length-t);if(r>=0&&A.glyphIdArray&&r<A.glyphIdArray.length){const i=A.glyphIdArray[r];if(i!==0)return i+A.idDelta[t]&65535}}return 0}filterProblematicCharacters(A){return A.filter(e=>this._isValidCharacter(e))}_isValidCharacter(A){const e=A.codePointAt(0)||0;return!(e>=0&&e<=31&&e!==9&&e!==10&&e!==13||e>=127&&e<=159)}}class lA{constructor(A){a(this,"_textureCanvas");a(this,"_textureContext");a(this,"_renderer");this._renderer=A,this._textureCanvas=document.createElement("canvas"),this._textureContext=this._textureCanvas.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(A,e,t,r){const i=A.length,s=Math.ceil(Math.sqrt(i)),o=Math.ceil(i/s),g=e.width*s,B=e.height*o;this._setupCanvas(g,B,t,r),this._renderCharactersToCanvas(A,e,s,t),this._applyBlackWhiteThreshold();const E=this._renderer.createFramebuffer(g,B,{filter:"nearest"});return E.update(this._textureCanvas),{framebuffer:E,columns:s,rows:o}}_setupCanvas(A,e,t,r){this._textureCanvas.width=A,this._textureCanvas.height=e,this._textureCanvas.style.width=A+"px",this._textureCanvas.style.height=A+"px",this._textureContext.imageSmoothingEnabled=!1,this._textureCanvas.style.imageRendering="pixelated",this._textureContext.fillStyle="black",this._textureContext.fillRect(0,0,A,e),this._textureContext.font=`${t}px ${r}`,this._textureContext.textBaseline="top",this._textureContext.textAlign="left",this._textureContext.fillStyle="white"}_renderCharactersToCanvas(A,e,t,r){for(let i=0;i<A.length;i++){const s=i%t,o=Math.floor(i/t),g=s*e.width+e.width*.5,B=o*e.height+e.height*.5,E=Math.round(g-e.width*.5),l=Math.round(B-r*.5);this._textureContext.fillText(A[i].character,E,l)}}_applyBlackWhiteThreshold(A=128){const e=this._textureContext.getImageData(0,0,this._textureCanvas.width,this._textureCanvas.height),t=e.data;for(let r=0;r<t.length;r+=4){const i=.299*t[r]+.587*t[r+1]+.114*t[r+2],s=A+32,o=i>s?255:0;t[r]=o,t[r+1]=o,t[r+2]=o}this._textureContext.putImageData(e,0,0)}}class hA{constructor(){a(this,"_tempCanvas");a(this,"_tempContext");this._tempCanvas=document.createElement("canvas"),this._tempContext=this._tempCanvas.getContext("2d")}calculateMaxGlyphDimensions(A,e,t){this._tempContext.font=`${e}px ${t}`;let r=0,i=0;for(const s of A){const o=this._tempContext.measureText(s),g=o.width,B=o.actualBoundingBoxAscent+o.actualBoundingBoxDescent;g>0&&(r=Math.max(r,g),i=Math.max(i,B))}return{width:Math.ceil(r),height:Math.ceil(i)}}}class QA{createCharacterObjects(A,e){return A.map((t,r)=>{const i=t.codePointAt(0)||0,s=this._generateCharacterColor(r);let o=0;if(e.hmtx&&e.hmtx.aWidth){const g=this._getGlyphIndex(e,i);g>0&&e.hmtx.aWidth[g]!==void 0&&(o=e.hmtx.aWidth[g])}return{character:t,unicode:i,color:s,advanceWidth:o}})}_getGlyphIndex(A,e){const t=A.cmap;if(!t||!t.tables)return 0;for(const r of t.tables)if(r.format===4){for(let i=0;i<r.startCount.length;i++)if(e>=r.startCount[i]&&e<=r.endCount[i]){if(r.idRangeOffset[i]===0)return e+r.idDelta[i]&65535;{const s=r.idRangeOffset[i]/2+(e-r.startCount[i])-(r.startCount.length-i);if(s>=0&&s<r.glyphIdArray.length){const o=r.glyphIdArray[s];if(o!==0)return o+r.idDelta[i]&65535}}}}return 0}_generateCharacterColor(A){const e=A%256,t=Math.floor(A/256)%256,r=Math.floor(A/65536)%256;return[e,t,r]}getCharacterColor(A,e){if(!m.validate(typeof A=="string"&&A.length===1,"Character must be a single character string.",{method:"getCharacterColor",providedValue:A}))return[0,0,0];const t=e.find(r=>r.character===A);return t?t.color:[0,0,0]}getCharacterColors(A,e){return m.validate(typeof A=="string"&&A.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:A})?A.split("").map(t=>this.getCharacterColor(t,e)||[0,0,0]):[[0,0,0]]}}class J{constructor(A,e=16){a(this,"_font");a(this,"_characters",[]);a(this,"_fontFramebuffer");a(this,"_fontSize",16);a(this,"_textureColumns",0);a(this,"_textureRows",0);a(this,"_maxGlyphDimensions",{width:0,height:0});a(this,"_fontFace");a(this,"_fontFamilyName","UrsaFont");a(this,"_characterExtractor");a(this,"_textureAtlas");a(this,"_metricsCalculator");a(this,"_characterColorMapper");this._fontSize=e,this._characterExtractor=new EA,this._textureAtlas=new lA(A),this._metricsCalculator=new hA,this._characterColorMapper=new QA}async initialize(A){let e;if(A){const t=await fetch(A);if(!t.ok)throw new f(`Failed to load font file: ${t.status} ${t.statusText}`);e=await t.arrayBuffer()}else e=await(await fetch(BA)).arrayBuffer();await this._loadFontFace(e),this._font=Q.parse(e)[0],await this._initializeFont()}setFontSize(A){if(A===void 0)return this._fontSize;this._fontSize=A,this._maxGlyphDimensions=this._metricsCalculator.calculateMaxGlyphDimensions(this._characters.map(t=>t.character),this._fontSize,this._fontFamilyName);const e=this._textureAtlas.createTextureAtlas(this._characters,this._maxGlyphDimensions,this._fontSize,this._fontFamilyName);this._fontFramebuffer=e.framebuffer,this._textureColumns=e.columns,this._textureRows=e.rows}async loadFont(A){try{const e=await fetch(A);if(!e.ok)throw new f(`Failed to load font file: ${e.status} ${e.statusText}`);const t=await e.arrayBuffer();await this._loadFontFace(t);const r=Q.parse(t);if(!r||r.length===0)throw new Error("Failed to parse font file");this._font=r[0],await this._initializeFont()}catch(e){throw new f(`Failed to load font: ${e instanceof Error?e.message:"Unknown error"}`,e)}}async _loadFontFace(A){const e=Date.now();this._fontFamilyName=this._fontFamilyName==="UrsaFont"?"UrsaFont":`CustomFont_${e}`,this._fontFace=new FontFace(this._fontFamilyName,A),await this._fontFace.load(),document.fonts.add(this._fontFace)}async _initializeFont(){const A=this._characterExtractor.extractCharacters(this._font),e=this._characterExtractor.filterProblematicCharacters(A);this._characters=this._characterColorMapper.createCharacterObjects(e,this._font),this._maxGlyphDimensions=this._metricsCalculator.calculateMaxGlyphDimensions(e,this._fontSize,this._fontFamilyName);const t=this._textureAtlas.createTextureAtlas(this._characters,this._maxGlyphDimensions,this._fontSize,this._fontFamilyName);this._fontFramebuffer=t.framebuffer,this._textureColumns=t.columns,this._textureRows=t.rows}getCharacterColor(A){return this._characterColorMapper.getCharacterColor(A,this._characters)}getCharacterColors(A){return this._characterColorMapper.getCharacterColors(A,this._characters)}hasAllCharacters(A){if(typeof A!="string"||A.length===0)return!1;const e=new Set(this._characters.map(t=>t.character));for(const t of A)if(!e.has(t))return!1;return!0}get fontFramebuffer(){return this._fontFramebuffer}get characters(){return this._characters}get textureColumns(){return this._textureColumns}get textureRows(){return this._textureRows}get maxGlyphDimensions(){return this._maxGlyphDimensions}dispose(){this._fontFramebuffer.dispose(),document.fonts.delete(this._fontFace),this._fontFramebuffer=null,this._fontFace=null,this._font=null,this._characters=[],this._maxGlyphDimensions={width:0,height:0},this._textureColumns=0,this._textureRows=0}get fontSize(){return this._fontSize}get font(){return this._font}}class j{constructor(A,e,t){a(this,"_cols");a(this,"_rows");a(this,"_width");a(this,"_height");a(this,"_offsetX");a(this,"_offsetY");a(this,"_fixedDimensions",!1);a(this,"_canvas");a(this,"_cellWidth");a(this,"_cellHeight");this._canvas=A,this._cellWidth=e,this._cellHeight=t,this.reset()}reset(){if(!this._fixedDimensions){const A=this._canvas.getBoundingClientRect();let e=Math.round(A.width),t=Math.round(A.height);[this._cols,this._rows]=[Math.floor(e/this._cellWidth),Math.floor(t/this._cellHeight)]}this._resizeGrid()}_resizeGrid(){const A=this._canvas.getBoundingClientRect();let e=Math.round(A.width),t=Math.round(A.height);this._width=this._cols*this._cellWidth,this._height=this._rows*this._cellHeight,this._offsetX=Math.floor((e-this._width)/2),this._offsetY=Math.floor((t-this._height)/2)}resizeCellPixelDimensions(A,e){[this._cellWidth,this._cellHeight]=[A,e],this.reset()}resizeGridDimensions(A,e){this._fixedDimensions=!0,[this._cols,this._rows]=[A,e],this._resizeGrid()}resetGridDimensions(){this._fixedDimensions=!1,this.reset()}resize(){this._fixedDimensions?this._resizeGrid():this.reset()}fixedDimensions(A){if(A===void 0)return this._fixedDimensions;this._fixedDimensions=A}get cellWidth(){return this._cellWidth}get cellHeight(){return this._cellHeight}dispose(){this._canvas=null,this._cols=0,this._rows=0,this._width=0,this._height=0,this._offsetX=0,this._offsetY=0,this._cellWidth=0,this._cellHeight=0}get cols(){return this._cols}get rows(){return this._rows}get width(){return this._width}get height(){return this._height}get offsetX(){return this._offsetX}get offsetY(){return this._offsetY}}class K{constructor(A,e=!1,t={}){a(this,"_canvas");a(this,"captureSource");a(this,"_isStandalone");this.captureSource=A,this._isStandalone=e,this._canvas=this.createCanvas(t.width,t.height)}createCanvas(A,e){var r;const t=document.createElement("canvas");if(t.className="textmodeCanvas",t.style.imageRendering="pixelated",this._isStandalone)t.width=A||800,t.height=e||600,document.body.appendChild(t);else{const i=this.captureSource.getBoundingClientRect();let s=Math.round(i.width),o=Math.round(i.height);if(this.captureSource instanceof HTMLVideoElement){const E=this.captureSource;(s===0||o===0)&&E.videoWidth>0&&E.videoHeight>0&&(s=E.videoWidth,o=E.videoHeight)}t.width=s,t.height=o,t.style.position="absolute",t.style.pointerEvents="none";const g=window.getComputedStyle(this.captureSource);let B=parseInt(g.zIndex||"0",10);isNaN(B)&&(B=0),t.style.zIndex=(B+1).toString(),this.positionOverlayCanvas(t),(r=this.captureSource.parentNode)==null||r.insertBefore(t,this.captureSource.nextSibling)}return t}positionOverlayCanvas(A){const e=this.captureSource.getBoundingClientRect();let t=this.captureSource.offsetParent;if(t&&t!==document.body){const r=t.getBoundingClientRect();A.style.top=e.top-r.top+"px",A.style.left=e.left-r.left+"px"}else A.style.top=e.top+window.scrollY+"px",A.style.left=e.left+window.scrollX+"px"}resize(A,e){if(this._isStandalone)this._canvas.width=A??this._canvas.width,this._canvas.height=e??this._canvas.height;else{const t=this.captureSource.getBoundingClientRect();let r=Math.round(t.width),i=Math.round(t.height);if(this.captureSource instanceof HTMLVideoElement){const s=this.captureSource;(r===0||i===0)&&s.videoWidth>0&&s.videoHeight>0&&(r=s.videoWidth,i=s.videoHeight)}this._canvas.width=r,this._canvas.height=i,this.positionOverlayCanvas(this._canvas)}}getWebGLContext(){const A={alpha:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"},e=this._canvas.getContext("webgl2",A)||this._canvas.getContext("webgl",A);if(!e)throw new f("WebGL context could not be created. Ensure your browser supports WebGL.");return e}dispose(){if(this._canvas){const A=this._canvas.getContext("webgl")||this._canvas.getContext("webgl2");if(A){const e=A.getExtension("WEBGL_lose_context");e&&e.loseContext()}this._canvas.parentNode&&this._canvas.parentNode.removeChild(this._canvas),this._canvas=null}this.captureSource=null}get canvas(){return this._canvas}get width(){return this._canvas.width}get height(){return this._canvas.height}}class y{constructor(A,e,t,r={}){a(this,"renderer");a(this,"fontManager");a(this,"grid");a(this,"_characterFramebuffer");a(this,"_primaryColorFramebuffer");a(this,"_secondaryColorFramebuffer");a(this,"_rotationFramebuffer");a(this,"_transformFramebuffer");a(this,"_options");this.renderer=A,this.fontManager=e,this.grid=t,this._options=r,this._characterFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._rotationFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._transformFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows)}resize(){this._characterFramebuffer.resize(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._rotationFramebuffer.resize(this.grid.cols,this.grid.rows),this._transformFramebuffer.resize(this.grid.cols,this.grid.rows)}enabled(A){this._options.enabled=A}enable(){this.enabled(!0)}disable(){this.enabled(!1)}dispose(){this._characterFramebuffer.dispose(),this._primaryColorFramebuffer.dispose(),this._secondaryColorFramebuffer.dispose(),this._rotationFramebuffer.dispose(),this._transformFramebuffer.dispose(),this._characterFramebuffer=null,this._primaryColorFramebuffer=null,this._secondaryColorFramebuffer=null,this._rotationFramebuffer=null,this._transformFramebuffer=null}get characterFramebuffer(){return this._characterFramebuffer}get primaryColorFramebuffer(){return this._primaryColorFramebuffer}get secondaryColorFramebuffer(){return this._secondaryColorFramebuffer}get rotationFramebuffer(){return this._rotationFramebuffer}get transformFramebuffer(){return this._transformFramebuffer}get options(){return this._options}}class cA{constructor(A,e){a(this,"_framebuffer");a(this,"_renderer");a(this,"_colors");this._renderer=A,this._colors=e;const t=Math.max(this._colors.length,1);this._framebuffer=this._renderer.createFramebuffer(t,1),this._updateFramebuffer()}_updateFramebuffer(){if(!this._framebuffer)return;const A=Math.max(this._colors.length,1),e=1;this._framebuffer.width!==A&&this._framebuffer.resize(A,e);const t=new Uint8Array(A*e*4);for(let r=0;r<A;r++){const i=r<this._colors.length?this._colors[r]:[0,0,0],s=r*4;t[s]=i[0],t[s+1]=i[1],t[s+2]=i[2],t[s+3]=255}this._framebuffer.updatePixels(t,A,e)}setColors(A){this._colors=A,this._updateFramebuffer()}get colors(){return this._colors}get framebuffer(){return this._framebuffer}get texture(){return this._framebuffer.texture}}class Y extends y{constructor(e,t,r,i={}){super(e,t,r,i);a(this,"palette");this.palette=new cA(this.renderer,this.fontManager.getCharacterColors(" .:-=+*%@#"))}characters(e){m.validate(this.fontManager.hasAllCharacters(e),"One or more characters do not exist in the current font.",{method:"characters",providedValue:e})&&(this._options.characters=e,this.palette.setColors(this.fontManager.getCharacterColors(e)))}characterColor(e,t,r,i=255){let s,o,g,B;if(typeof e=="string"){const E=this.parseHexColor(e);if(!E){m.validate(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:"characterColor",providedValue:e});return}[s,o,g,B]=E}else if(s=e,o=t!==void 0?t:e,g=r!==void 0?r:e,B=i,!m.validate([s,o,g,B].every(E=>E>=0&&E<=255),"Character color values must be between 0 and 255",{method:"characterColor",providedValues:{r:s,g:o,b:g,a:B}}))return;this._options.characterColor=[s/255,o/255,g/255,B/255]}characterColorMode(e){m.validate(["sampled","fixed"].includes(e),"Invalid character color mode. Must be 'sampled' or 'fixed'.",{method:"characterColorMode",providedValue:e})&&(this._options.characterColorMode=e)}cellColor(e,t,r,i=255){let s,o,g,B;if(typeof e=="string"){const E=this.parseHexColor(e);if(!E){m.validate(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:"cellColor",providedValue:e});return}[s,o,g,B]=E}else if(s=e,o=t!==void 0?t:e,g=r!==void 0?r:e,B=i,!m.validate([s,o,g,B].every(E=>E>=0&&E<=255),"Cell color values must be between 0 and 255",{method:"cellColor",providedValues:{r:s,g:o,b:g,a:B}}))return;this._options.cellColor=[s/255,o/255,g/255,B/255]}cellColorMode(e){m.validate(["sampled","fixed"].includes(e),"Invalid cell color mode. Must be 'sampled' or 'fixed'.",{method:"cellColorMode",providedValue:e})&&(this._options.cellColorMode=e)}invert(e){m.validate(typeof e=="boolean"||typeof e=="number"&&Number.isInteger(e),"Invert must be a boolean value or an integer (0 for false, any other number for true).",{method:"invert",providedValue:e})&&(this._options.invert=!!e)}rotation(e){if(!m.validate(typeof e=="number","Rotation angle must be a number.",{method:"rotation",providedValue:e}))return;e=e%360,e<0&&(e+=360);const t=e*255/360,r=Math.floor(t)/255,i=Math.round(t-r);this._options.rotation=[r,i,0,1]}flipHorizontally(e){m.validate(typeof e=="boolean"||typeof e=="number"&&Number.isInteger(e),"Flip horizontally must be a boolean value or an integer (0 for false, any other number for true).",{method:"flipHorizontally",providedValue:e})&&(this._options.flipHorizontally=!!e)}flipVertically(e){m.validate(typeof e=="boolean"||typeof e=="number"&&Number.isInteger(e),"Flip vertically must be a boolean value or an integer (0 for false, any other number for true).",{method:"flipVertically",providedValue:e})&&(this._options.flipVertically=!!e)}parseHexColor(e){if(e=e.replace(/^#/,""),!/^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(e))return null;e.length===3&&(e=e.split("").map(s=>s+s).join(""));const t=parseInt(e.slice(0,2),16),r=parseInt(e.slice(2,4),16),i=parseInt(e.slice(4,6),16);return[t,r,i,255]}}var uA="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);}}",dA="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);}}",fA="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);}}",CA="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);}}",mA="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);}";const DA={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 k extends Y{constructor(e,t,r){super(e,t,r,{...DA});a(this,"sampleShader");a(this,"colorFillShader");a(this,"charMappingShader");a(this,"transformFillShader");a(this,"rotationFillShader");a(this,"sampleFramebuffer");this.sampleShader=new w(e.context,_,uA),this.colorFillShader=new w(e.context,_,dA),this.transformFillShader=new w(e.context,_,fA),this.rotationFillShader=new w(e.context,_,CA),this.charMappingShader=new w(e.context,_,mA),this.sampleFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows)}convert(e){this.sampleFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.sampleShader),this.renderer.setUniform("u_sketchTexture",e),this.renderer.setUniform("u_gridCellDimensions",[this.grid.cols,this.grid.rows]),this.renderer.setUniform("u_brightnessRange",this._options.brightnessRange),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this.sampleFramebuffer.end(),this._primaryColorFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.colorFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_fillColor",this._options.characterColor),this.renderer.setUniform("u_useFixedColor",this._options.characterColorMode==="fixed"),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.end(),this._secondaryColorFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.colorFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_fillColor",this._options.cellColor),this.renderer.setUniform("u_useFixedColor",this._options.cellColorMode==="fixed"),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.end(),this._transformFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.transformFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_invert",this._options.invert),this.renderer.setUniform("u_flipHorizontally",this._options.flipHorizontally),this.renderer.setUniform("u_flipVertically",this._options.flipVertically),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._transformFramebuffer.end(),this._rotationFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.rotationFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_rotationColor",this._options.rotation),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._rotationFramebuffer.end(),this._characterFramebuffer.begin(),this.renderer.clear(0,0,0,0),this.renderer.shader(this.charMappingShader),this.renderer.setUniform("u_colorSampleFramebuffer",this.sampleFramebuffer.texture),this.renderer.setUniform("u_charPaletteTexture",this.palette.texture),this.renderer.setUniform("u_charPaletteSize",[this.palette.colors.length,1]),this.renderer.setUniform("u_brightnessRange",this._options.brightnessRange),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._characterFramebuffer.end()}resize(){super.resize(),this.sampleFramebuffer.resize(this.grid.cols,this.grid.rows)}brightnessRange(e){m.validate(Array.isArray(e)&&e.length===2&&e.every(t=>typeof t=="number"&&t>=0&&t<=255),"Brightness range must be an array of two numbers between 0 and 255.",{method:"brightnessRange",providedValue:e})&&(this._options.brightnessRange=e)}}const PA=Object.freeze(Object.defineProperty({__proto__:null,TextmodeBrightnessConverter:k,TextmodeConverter:y,TextmodeFeatureConverter:Y},Symbol.toStringTag,{value:"Module"}));var pA="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);vec2 charCoord=vec2(charCol,charRow)/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);}";class Z{constructor(A,e,t){a(this,"renderer");a(this,"font");a(this,"grid");a(this,"converters");a(this,"_resultFramebuffer");a(this,"_asciiShader");a(this,"_characterFramebuffer");a(this,"_primaryColorFramebuffer");a(this,"_secondaryColorFramebuffer");a(this,"_rotationFramebuffer");a(this,"_transformFramebuffer");this.renderer=A,this.font=e,this.grid=t,this._asciiShader=this.renderer.createShader(_,pA),this.converters=[{name:"brightness",converter:new k(A,e,t)},{name:"custom",converter:new y(A,e,t)}],this._characterFramebuffer=this.renderer.createFramebuffer(t.cols,t.rows),this._primaryColorFramebuffer=this.renderer.createFramebuffer(t.cols,t.rows),this._secondaryColorFramebuffer=this.renderer.createFramebuffer(t.cols,t.rows),this._rotationFramebuffer=this.renderer.createFramebuffer(t.cols,t.rows),this._transformFramebuffer=this.renderer.createFramebuffer(t.cols,t.rows),this._resultFramebuffer=this.renderer.createFramebuffer(this.grid.width,this.grid.height)}render(A){for(const t of this.converters){const r=t.converter;r.options.enabled&&r instanceof Y&&r.convert(A)}const e=(t,r)=>{t.begin(),this.renderer.clear();for(const i of this.converters){const s=i.converter;s.options.enabled&&this.renderer.image(r(s),0,0)}t.end()};e(this._characterFramebuffer,t=>t.characterFramebuffer),e(this._primaryColorFramebuffer,t=>t.primaryColorFramebuffer),e(this._secondaryColorFramebuffer,t=>t.secondaryColorFramebuffer),e(this._rotationFramebuffer,t=>t.rotationFramebuffer),e(this._transformFramebuffer,t=>t.transformFramebuffer),this._resultFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this._asciiShader),this.renderer.setUniform("u_characterTexture",this.font.fontFramebuffer),this.renderer.setUniform("u_charsetDimensions",[this.font.textureColumns,this.font.textureRows]),this.renderer.setUniform("u_asciiCharacterTexture",this._characterFramebuffer.texture),this.renderer.setUniform("u_primaryColorTexture",this._primaryColorFramebuffer.texture),this.renderer.setUniform("u_secondaryColorTexture",this._secondaryColorFramebuffer.texture),this.renderer.setUniform("u_transformTexture",this._transformFramebuffer.texture),this.renderer.setUniform("u_rotationTexture",this._rotationFramebuffer.texture),this.renderer.setUniform("u_captureTexture",A.texture),this.renderer.setUniform("u_backgroundMode",!1),this.renderer.setUniform("u_captureDimensions",[A.width,A.height]),this.renderer.setUniform("u_gridCellDimensions",[this.grid.cols,this.grid.rows]),this.renderer.setUniform("u_gridPixelDimensions",[this.grid.width,this.grid.height]),this.renderer.rect(0,0,this._resultFramebuffer.width,this._resultFramebuffer.height),this._resultFramebuffer.end()}get(A){if(!m.validate(typeof A=="string"&&A.length>0,"Converter name must be a non-empty string.",{method:"converter",providedValue:A}))return;const e=this.converters.find(r=>r.name===A),t=e==null?void 0:e.converter;if(m.validate(t instanceof y,`Converter "${A}" is not a valid TextmodeConverter.`,{method:"converter",providedValue:A,converterInstance:t}))return t}add(A,e){if(!m.validate(typeof A=="string"&&A.length>0,"Converter name must be a non-empty string.",{method:"add",providedValue:A})||!m.validate(e==="brightness"||e==="custom",`Converter type must be either "brightness" or "custom". Provided: ${e}`,{method:"add",providedValue:e}))return;let t;return e==="brightness"?t=new k(this.renderer,this.font,this.grid):t=new y(this.renderer,this.font,this.grid),this.converters.push({name:A,converter:t}),t}remove(A){if(!m.validate(typeof A=="string"||A instanceof y,"Parameter must be either a string (converter name) or a TextmodeConverter instance.",{method:"remove",providedValue:A}))return;let e=-1;if(typeof A=="string"){if(!m.validate(A.length>0,"Converter name must be a non-empty string.",{method:"remove",providedValue:A}))return;e=this.converters.findIndex(t=>t.name===A)}else e=this.converters.findIndex(t=>t.converter===A);m.validate(e!==-1,typeof A=="string"?`Converter with name "${A}" not found in pipeline.`:"Converter instance not found in pipeline.",{method:"remove",providedValue:A,convertersCount:this.converters.length})&&this.converters.splice(e,1)}get texture(){return this._resultFramebuffer}resize(){this._resultFramebuffer.resize(this.grid.width,this.grid.height),this._characterFramebuffer.resize(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._rotationFramebuffer.resize(this.grid.cols,this.grid.rows),this._transformFramebuffer.resize(this.grid.cols,this.grid.rows);for(const A of this.converters)A.converter.resize()}hasEnabledConverters(){return this.converters.some(A=>A.converter.options.enabled)}disable(){for(const A of this.converters)A.converter.disable()}enable(){for(const A of this.converters)A.converter.enable()}dispose(){for(const A of this.converters)A.converter.dispose();this._characterFramebuffer.dispose(),this._primaryColorFramebuffer.dispose(),this._secondaryColorFramebuffer.dispose(),this._rotationFramebuffer.dispose(),this._transformFramebuffer.dispose(),this._resultFramebuffer.dispose(),this._asciiShader.dispose(),this.converters=[],this._characterFramebuffer=null,this._primaryColorFramebuffer=null,this._secondaryColorFramebuffer=null,this._rotationFramebuffer=null,this._transformFramebuffer=null,this._resultFramebuffer=null,this._asciiShader=null}get characterFramebuffer(){return this._characterFramebuffer}get primaryColorFramebuffer(){return this._primaryColorFramebuffer}get secondaryColorFramebuffer(){return this._secondaryColorFramebuffer}get rotationFramebuffer(){return this._rotationFramebuffer}get transformFramebuffer(){return this._transformFramebuffer}}class V{extractFramebufferData(A){const e=A.get("brightness"),t=e==null?void 0:e.characterFramebuffer,r=e==null?void 0:e.primaryColorFramebuffer,i=e==null?void 0:e.secondaryColorFramebuffer,s=e==null?void 0:e.transformFramebuffer,o=e==null?void 0:e.rotationFramebuffer;return t==null||t.loadPixels(),r==null||r.loadPixels(),i==null||i.loadPixels(),s==null||s.loadPixels(),o==null||o.loadPixels(),{characterPixels:(t==null?void 0:t.pixels)||new Uint8Array(0),primaryColorPixels:(r==null?void 0:r.pixels)||new Uint8Array(0),secondaryColorPixels:(i==null?void 0:i.pixels)||new Uint8Array(0),transformPixels:(s==null?void 0:s.pixels)||new Uint8Array(0),rotationPixels:(o==null?void 0:o.pixels)||new Uint8Array(0)}}getCharacterIndex(A,e){const t=A[e],r=A[e+1];return t+(r<<8)}pixelsToRGBA(A,e){return{r:A[e],g:A[e+1],b:A[e+2],a:A[e+3]}}}class O{createBlob(A,e){return new Blob([A],{type:e})}downloadFile(A,e,t){try{const r=this.createBlob(A,t),i=URL.createObjectURL(r),s=document.createElement("a");s.href=i,s.download=e,s.style.display="none",s.rel="noopener",document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(i)}catch(r){throw console.error("Failed to download file:",r),new Error(`File download failed: ${r instanceof Error?r.message:"Unknown error"}`)}}generateTimestamp(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}generateDateTimeString(){const A=new Date,e=A.toISOString().split("T")[0],t=A.toTimeString().split(" ")[0].replace(/:/g,"-");return{date:e,time:t}}sanitizeFilename(A){return A.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}generateDefaultFilename(){return`'textmode-export'-${this.generateTimestamp()}`}}class IA extends V{extractTransformData(A,e,t){const r=A[t],i=A[t+1],s=A[t+2],o=r===255,g=i===255,B=s===255,E=e[t],l=e[t+1],h=E+l/255,c=Math.round(h*360/255*100)/100;return{isInverted:o,flipHorizontal:g,flipVertical:B,rotation:c}}calculateCellPosition(A,e,t){return{x:A,y:e,cellX:A*t.cellWidth,cellY:e*t.cellHeight}}extractSVGCellData(A,e){const t=[];let r=0;for(let i=0;i<e.rows;i++)for(let s=0;s<e.cols;s++){const o=r*4,g=this.getCharacterIndex(A.characterPixels,o);let B=this.pixelsToRGBA(A.primaryColorPixels,o),E=this.pixelsToRGBA(A.secondaryColorPixels,o);const l=this.extractTransformData(A.transformPixels,A.rotationPixels,o);if(l.isInverted){const c=B;B=E,E=c}const h=this.calculateCellPosition(s,i,e);t.push({charIndex:g,primaryColor:B,secondaryColor:E,transform:l,position:h}),r++}return t}}class wA{getGlyphIndex(A,e){const t=A.cmap;if(!t||!t.tables)return 0;for(const r of t.tables)if(r.format===4){for(let i=0;i<r.startCount.length;i++)if(e>=r.startCount[i]&&e<=r.endCount[i]){if(r.idRangeOffset[i]===0)return e+r.idDelta[i]&65535;{const s=r.idRangeOffset[i]/2+(e-r.startCount[i])-(r.startCount.length-i);if(s>=0&&s<r.glyphIdArray.length){const o=r.glyphIdArray[s];if(o!==0)return o+r.idDelta[i]&65535}}}}return 0}createEmptyPath(){return{getBoundingBox:()=>({x1:0,y1:0,x2:0,y2:0}),toSVG:()=>""}}createGlyphPath(A,e,t,r,i){if(!e||!e.xs||e.xs.length===0)return this.createEmptyPath();const s=i/A.head.unitsPerEm;return{getBoundingBox:()=>({x1:t+e.xMin*s,y1:r+-e.yMax*s,x2:t+e.xMax*s,y2:r+-e.yMin*s}),toSVG:()=>this.glyphToSVGPath(e,t,r,s)}}glyphToSVGPath(A,e,t,r){if(!A||!A.xs)return"";const{xs:i,ys:s,endPts:o,flags:g}=A;if(!i||!s||!o||!g)return"";let B="",E=0;for(let l=0;l<o.length;l++){const h=o[l];if(!(h<E)){if(h>=E){const c=e+i[E]*r,d=t-s[E]*r;B+=`M${c.toFixed(2)},${d.toFixed(2)}`;let u=E+1;for(;u<=h;)if((g[u]&1)!==0){const p=e+i[u]*r,D=t-s[u]*r;B+=`L${p.toFixed(2)},${D.toFixed(2)}`,u++}else{const p=e+i[u]*r,D=t-s[u]*r;let I=u+1>h?E:u+1;if((g[I]&1)!==0){const F=e+i[I]*r,b=t-s[I]*r;B+=`Q${p.toFixed(2)},${D.toFixed(2)} ${F.toFixed(2)},${b.toFixed(2)}`,u=I+1}else{const F=e+i[I]*r,b=t-s[I]*r,L=(p+F)/2,M=(D+b)/2;B+=`Q${p.toFixed(2)},${D.toFixed(2)} ${L.toFixed(2)},${M.toFixed(2)}`,u=I}}B+="Z"}E=h+1}}return B}generateCharacterPath(A,e,t,r,i){try{const s=A.codePointAt(0)||0,o=this.getGlyphIndex(e,s);if(o===0)return this.createEmptyPath();let g=null;try{e.glyf&&e.glyf[o]!==null?g=e.glyf[o]:Q&&Q.T&&Q.T.glyf&&Q.T.glyf._parseGlyf&&(g=Q.T.glyf._parseGlyf(e,o),e.glyf&&g&&(e.glyf[o]=g))}catch(B){console.warn(`Failed to parse glyph ${o}:`,B)}return g?this.createGlyphPath(e,g,t,r,i):this.createEmptyPath()}catch(s){return console.warn(`Failed to generate path for character "${A}":`,s),this.createEmptyPath()}}generatePositionedCharacterPath(A,e,t,r,i,s,o,g){try{const B=o/e.head.unitsPerEm,E=g*B,l=t+(i-E)/2,h=r+(s+o*.7)/2;return this.generateCharacterPath(A,e,l,h,o).toSVG()||null}catch(B){return console.warn(`Failed to generate positioned character path for "${A}":`,B),null}}}class _A{constructor(){a(this,"pathGenerator");this.pathGenerator=new wA}generateSVGHeader(A){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
9
9
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
10
10
|
<svg width="${A.width}" height="${A.height}" viewBox="0 0 ${A.width} ${A.height}"
|
|
11
11
|
xmlns="http://www.w3.org/2000/svg" version="1.1">
|
|
@@ -23,4 +23,4 @@
|
|
|
23
23
|
<g id="ascii-cells">`;for(const s of A)i+=this.generateCellContent(s,e,t,r);return i+=this.generateSVGFooter(),i}optimizeSVGContent(A){return A.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\n\s*\n/g,`
|
|
24
24
|
`).replace(/[ \t]+$/gm,"")}}class bA extends O{createSVGBlob(A){return this.createBlob(A,"image/svg+xml;charset=utf-8")}downloadSVG(A,e){try{this.downloadFile(A,this.sanitizeFilename(e)+".svg","image/svg+xml;charset=utf-8")}catch(t){throw console.error("Failed to download SVG file:",t),new Error(`SVG download failed: ${t instanceof Error?t.message:"Unknown error"}`)}}saveSVG(A,e){this.downloadSVG(A,e||this.generateDefaultFilename())}}class q{constructor(){a(this,"dataExtractor");a(this,"contentGenerator");a(this,"fileHandler");this.dataExtractor=new IA,this.contentGenerator=new _A,this.fileHandler=new bA}applyDefaultOptions(A){return{includeBackgroundRectangles:A.includeBackgroundRectangles??!0,drawMode:A.drawMode??"fill",strokeWidth:A.strokeWidth??1,backgroundColor:A.backgroundColor??[0,0,0,0]}}generateSVG(A,e={}){const t=this.applyDefaultOptions(e),r=this.dataExtractor.extractFramebufferData(A.pipeline),i=this.dataExtractor.extractSVGCellData(r,A.grid),s=this.contentGenerator.generateSVGContent(i,A.grid,A.font,t);return this.contentGenerator.optimizeSVGContent(s)}saveSVG(A,e={}){try{const t=this.generateSVG(A,e),r=e.filename||this.fileHandler.generateDefaultFilename();this.fileHandler.saveSVG(t,r)}catch(t){throw console.error("Failed to save SVG:",t),new Error(`SVG save failed: ${t instanceof Error?t.message:"Unknown error"}`)}}}class vA extends V{extractCharacterGrid(A,e,t,r=" "){var o;const i=[];let s=0;for(let g=0;g<e.rows;g++){const B=[];for(let E=0;E<e.cols;E++){const l=s*4,h=this.getCharacterIndex(A.characterPixels,l),c=((o=t.characters[h])==null?void 0:o.character)||r;B.push(c),s++}i.push(B)}return i}}class xA{generateTXTContent(A,e){const t=[];for(const i of A){let s=i.join("");e.preserveTrailingSpaces||(s=s.replace(/\s+$/,"")),t.push(s)}const r=e.lineEnding==="crlf"?`\r
|
|
25
25
|
`:`
|
|
26
|
-
`;return t.join(r)}}class FA extends O{saveTXT(A,e){try{const t=this.ensureValidFilename(e);this.downloadFile(A,t,"text/plain;charset=utf-8")}catch(t){throw console.error("Failed to save TXT file:",t),new Error(`TXT file save failed: ${t instanceof Error?t.message:"Unknown error"}`)}}ensureValidFilename(A){let e=this.sanitizeFilename(A);return e===".txt"||e.length<=4?this.generateDefaultFilename():e}}class AA{constructor(){a(this,"dataExtractor");a(this,"contentGenerator");a(this,"fileHandler");this.dataExtractor=new vA,this.contentGenerator=new xA,this.fileHandler=new FA}applyDefaultOptions(A){return{preserveTrailingSpaces:A.preserveTrailingSpaces??!1,lineEnding:A.lineEnding??"lf",emptyCharacter:A.emptyCharacter??" "}}generateTXT(A,e={}){const t=this.applyDefaultOptions(e),r=this.dataExtractor.extractFramebufferData(A.pipeline),i=this.dataExtractor.extractCharacterGrid(r,A.grid,A.font,t.emptyCharacter);return this.contentGenerator.generateTXTContent(i,t)}saveTXT(A,e={}){try{const t=this.generateTXT(A,e),r=e.filename||this.fileHandler.generateDefaultFilename();this.fileHandler.saveTXT(t,r)}catch(t){throw console.error("Failed to save TXT:",t),new Error(`TXT save failed: ${t instanceof Error?t.message:"Unknown error"}`)}}}class yA extends V{captureCanvasData(A,e=1,t="transparent"){const r=A.canvas;if(e===1&&t==="transparent")return r;const i=document.createElement("canvas"),s=i.getContext("2d"),o=Math.round(r.width*e),g=Math.round(r.height*e);return i.width=o,i.height=g,t!=="transparent"&&(s.fillStyle=t,s.fillRect(0,0,o,g)),s.imageSmoothingEnabled=!1,s.drawImage(r,0,0,r.width,r.height,0,0,o,g),i}}class TA{generateImageData(A,e){const t=this.getMimeType(e.format);return e.format==="png"?A.toDataURL(t):A.toDataURL(t,e.quality)}async generateImageBlob(A,e){return new Promise((t,r)=>{const i=this.getMimeType(e.format),s=o=>{o?t(o):r(new Error(`Failed to generate ${e.format.toUpperCase()} blob`))};e.format==="png"?A.toBlob(s,i):A.toBlob(s,i,e.quality)})}getMimeType(A){switch(A){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw new Error(`Unsupported image format: ${A}`)}}}const eA={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},z={png:".png",jpg:".jpg",webp:".webp"};class SA extends O{saveImage(A,e,t){try{const r=z[t];typeof A=="string"?this.saveImageFromDataURL(A,this.sanitizeFilename(e)+r):this.saveImageFromBlob(A,this.sanitizeFilename(e)+r)}catch(r){throw console.error(`Failed to save ${t.toUpperCase()} image:`,r),new Error(`Image save failed: ${r instanceof Error?r.message:"Unknown error"}`)}}saveImageFromDataURL(A,e){const t=document.createElement("a");t.href=A,t.download=e,t.style.display="none",t.rel="noopener",document.body.appendChild(t),t.click(),document.body.removeChild(t)}saveImageFromBlob(A,e){const t=URL.createObjectURL(A);try{const r=document.createElement("a");r.href=t,r.download=e,r.style.display="none",r.rel="noopener",document.body.appendChild(r),r.click(),document.body.removeChild(r)}finally{URL.revokeObjectURL(t)}}validateSaveSupport(A){return A in eA&&A in z}getMimeType(A){return eA[A]}getFileExtension(A){return z[A]}}class RA{constructor(){a(this,"dataExtractor");a(this,"contentGenerator");a(this,"fileHandler");this.dataExtractor=new yA,this.contentGenerator=new TA,this.fileHandler=new SA}applyDefaultOptions(A){return{format:A.format??"png",quality:A.quality??1,scale:A.scale??1,backgroundColor:A.backgroundColor??"transparent"}}validateOptions(A){if(console.log("Validating image export options:",A),!this.fileHandler.validateSaveSupport(A.format))throw new Error(`Saving '${A.format}' files is not supported`);if(A.quality<0||A.quality>1)throw new Error("Image quality must be between 0.0 and 1.0");if(A.scale<=0)throw new Error("Scale factor must be greater than 0");A.scale>10&&console.warn("Large scale factors may result in very large files and slow performance"),A.format==="jpg"&&A.backgroundColor==="transparent"&&(A.backgroundColor="black")}generateImage(A,e={}){const t=this.applyDefaultOptions(e);if(this.validateOptions(t),t.scale===1&&t.backgroundColor==="transparent")return this.contentGenerator.generateImageData(A.canvas,t);const r=this.dataExtractor.captureCanvasData(A,t.scale,t.backgroundColor);return this.contentGenerator.generateImageData(r,t)}async generateImageBlob(A,e={}){const t=this.applyDefaultOptions(e);if(this.validateOptions(t),t.scale===1&&t.backgroundColor==="transparent")return await this.contentGenerator.generateImageBlob(A.canvas,t);const r=this.dataExtractor.captureCanvasData(A,t.scale,t.backgroundColor);return await this.contentGenerator.generateImageBlob(r,t)}async saveImage(A,e={}){try{const t=await this.generateImageBlob(A,e),r=e.format??"png",i=e.filename||this.fileHandler.generateDefaultFilename();this.fileHandler.saveImage(t,i,r)}catch(t){throw console.error("Failed to save image:",t),new Error(`Image save failed: ${t instanceof Error?t.message:"Unknown error"}`)}}}class S{constructor(A=null,e={}){a(this,"captureSource");a(this,"textmodeCanvas");a(this,"_renderer");a(this,"_canvasFramebuffer");a(this,"_font");a(this,"_grid");a(this,"resizeObserver");a(this,"_mode");a(this,"_frameRateLimit");a(this,"animationFrameId",null);a(this,"lastFrameTime",0);a(this,"frameInterval");a(this,"_isLooping",!0);a(this,"_frameRate",0);a(this,"lastRenderTime",0);a(this,"_frameCount",0);a(this,"frameTimeHistory",[]);a(this,"frameTimeHistorySize",10);a(this,"_pipeline");a(this,"_isDisposed",!1);a(this,"_standalone",!1);a(this,"_drawCallback",()=>{});a(this,"_resizedCallback",()=>{});a(this,"_windowResizeListener",null);a(this,"_printDebug",!1);this.captureSource=A,this._standalone=A===null,this._mode=e.renderMode??"auto",this._frameRateLimit=e.frameRate??60,this.frameInterval=1e3/this._frameRateLimit}static async create(A=null,e={}){const t=new S(A,e),r=t._standalone?e:void 0;t.textmodeCanvas=new K(t.captureSource,t._standalone,r),t._renderer=new gA(t.textmodeCanvas.getWebGLContext());let i,s;t._standalone?(i=e.width||800,s=e.height||600):(i=t.textmodeCanvas.width||800,s=t.textmodeCanvas.height||600),t._canvasFramebuffer=t._renderer.createFramebuffer(i,s),t._font=new J(t._renderer,e.fontSize??16),await t._font.initialize(e.fontSource);const o=t._font.maxGlyphDimensions;return t._grid=new j(t.textmodeCanvas.canvas,o.width,o.height),t._pipeline=new Z(t._renderer,t._font,t._grid),t.setupEventListeners(),t.startAutoRendering(),t}setupEventListeners(){this._windowResizeListener=()=>{this._standalone?this._resizedCallback():this.resize()},window.addEventListener("resize",this._windowResizeListener),window.ResizeObserver&&this.captureSource&&!this._standalone&&(this.resizeObserver=new ResizeObserver(()=>{this.resize()}),this.resizeObserver.observe(this.captureSource))}toString(A={}){return new AA().generateTXT(this,A)}saveStrings(A={}){new AA().saveTXT(this,A)}toSVG(A={}){return new q().generateSVG(this,A)}saveSVG(A={}){new q().saveSVG(this,A)}async saveCanvas(A,e="png",t={}){await new RA().saveImage(this.textmodeCanvas,{...t,filename:A,format:e})}async loadFont(A){return this._font.loadFont(A).then(()=>{const e=this._font.maxGlyphDimensions;this._grid.resizeCellPixelDimensions(e.width,e.height),this._pipeline.resize()})}render(){if(this.measureFrameRate(),this._frameCount++,this._isDisposed){console.warn("Cannot render: Required resources have been disposed");return}if(this._standalone?this._canvasFramebuffer&&(this._canvasFramebuffer.begin(),this._drawCallback(),this._renderer&&this._renderer.reset(),this._canvasFramebuffer&&this._canvasFramebuffer.end()):this.captureSource&&this._canvasFramebuffer&&this._canvasFramebuffer.update(this.captureSource),!this._pipeline||!this._renderer){console.warn("Cannot complete render: Pipeline or renderer has been disposed");return}if(this._pipeline.render(this._canvasFramebuffer),this._pipeline.hasEnabledConverters()?(this._renderer.background(0),this._renderer.image(this._pipeline.texture,this._grid.offsetX,this._grid.offsetY,this._pipeline.texture.width,this._pipeline.texture.height)):(this._renderer.clear(),this._renderer.image(this._canvasFramebuffer,this._grid.offsetX,this._grid.offsetY,this._canvasFramebuffer.width,this._canvasFramebuffer.height)),this._printDebug){let A=0;this._renderer.image(this._pipeline.characterFramebuffer,A,0,this._pipeline.characterFramebuffer.width,this._pipeline.characterFramebuffer.height),A+=this._pipeline.characterFramebuffer.width,this._renderer.image(this._pipeline.primaryColorFramebuffer,A,0,this._pipeline.primaryColorFramebuffer.width,this._pipeline.primaryColorFramebuffer.height),A+=this._pipeline.primaryColorFramebuffer.width,this._renderer.image(this._pipeline.secondaryColorFramebuffer,A,0,this._pipeline.secondaryColorFramebuffer.width,this._pipeline.secondaryColorFramebuffer.height),A+=this._pipeline.secondaryColorFramebuffer.width,this._renderer.image(this._pipeline.transformFramebuffer,A,0,this._pipeline.transformFramebuffer.width,this._pipeline.transformFramebuffer.height),A+=this._pipeline.transformFramebuffer.width,this._renderer.image(this._pipeline.rotationFramebuffer,A,0,this._pipeline.rotationFramebuffer.width,this._pipeline.rotationFramebuffer.height)}}resize(){this.textmodeCanvas.resize(),this._canvasFramebuffer.resize(this.textmodeCanvas.width,this.textmodeCanvas.height),this._grid.resize(),this._pipeline.resize(),this._renderer.resetViewport(),this._mode!=="manual"&&this.render()}startAutoRendering(){if(this._mode!=="auto"||!this._isLooping)return;this.lastFrameTime=performance.now();const A=e=>{if(!this._isLooping){this.animationFrameId=null;return}const t=e-this.lastFrameTime;t>=this.frameInterval&&(this.render(),this.lastFrameTime=e-t%this.frameInterval),this._isLooping&&(this.animationFrameId=requestAnimationFrame(A))};this.animationFrameId=requestAnimationFrame(A)}measureFrameRate(){const A=performance.now();if(this.lastRenderTime>0){const e=A-this.lastRenderTime;this.frameTimeHistory.push(e),this.frameTimeHistory.length>this.frameTimeHistorySize&&this.frameTimeHistory.shift();const t=this.frameTimeHistory.reduce((r,i)=>r+i,0)/this.frameTimeHistory.length;this._frameRate=1e3/t}this.lastRenderTime=A}stopAutoRendering(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}renderMode(A){this._mode!==A&&(this.stopAutoRendering(),this._mode=A,A==="auto"&&this._isLooping&&this.startAutoRendering())}frameRate(A){if(A===void 0)return this._frameRate;this._frameRateLimit=A,this.frameInterval=1e3/A,this._mode==="auto"&&this._isLooping&&(this.stopAutoRendering(),this.startAutoRendering())}noLoop(){this._isLooping&&(this._isLooping=!1,this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null))}loop(){this._isLooping||(this._isLooping=!0,this._mode==="auto"&&this.startAutoRendering())}isLooping(){return this._mode==="auto"&&this._isLooping}fontSize(A){m.validate(typeof A=="number"&&A>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:A})&&this._font.fontSize!==A&&(this._font.setFontSize(A),this._grid.resizeCellPixelDimensions(this._font.maxGlyphDimensions.width,this._font.maxGlyphDimensions.height),this._pipeline.resize(),this._renderer.resetViewport())}draw(A){this._drawCallback=A}windowResized(A){this._resizedCallback=A}resizeCanvas(A,e){this.textmodeCanvas.resize(A,e),this._canvasFramebuffer.resize(this.textmodeCanvas.width,this.textmodeCanvas.height),this._grid.resize(),this._pipeline.resize(),this._renderer.resetViewport(),this._mode!=="manual"&&this.render()}converter(A){return this._pipeline.get(A)}fill(A,e,t,r){this._renderer.fill(A,e,t,r)}stroke(A,e,t,r){this._renderer.stroke(A,e,t,r)}strokeWeight(A){this._renderer.strokeWeight(A)}noStroke(){this._renderer.noStroke()}noFill(){this._renderer.noFill()}rotate(A){this._renderer.rotate(A)}push(){this._renderer.push()}pop(){this._renderer.pop()}rect(A,e,t=1,r=1){this._renderer.rect(A,e,t,r)}line(A,e,t,r){this._renderer.line(A,e,t,r)}background(A,e=A,t=A,r=255){this._renderer.background(A,e,t,r)}createShader(A,e){return this._renderer.createShader(A,e)}createFilterShader(A){return this._renderer.createFilterShader(A)}shader(A){this._renderer.shader(A)}setUniform(A,e){this._renderer.setUniform(A,e)}destroy(){this._isDisposed=!0,this.stopAutoRendering(),this._windowResizeListener&&(window.removeEventListener("resize",this._windowResizeListener),this._windowResizeListener=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this._pipeline.dispose(),this._font.dispose(),this._grid.dispose(),this._canvasFramebuffer.dispose(),this._renderer.dispose(),this.textmodeCanvas.dispose(),this.captureSource=null,this.textmodeCanvas=null,this._renderer=null,this._canvasFramebuffer=null,this._font=null,this._grid=null,this._pipeline=null,this.resizeObserver=null,this._drawCallback=()=>{},this._resizedCallback=()=>{},this.animationFrameId=null,this.lastFrameTime=0,this.lastRenderTime=0,this._frameCount=0,this._frameRate=0,this.frameTimeHistory=[],this._isLooping=!1}debug(A){this._printDebug=A}get grid(){return this._grid}get font(){return this._font}get mode(){return this._mode}get pipeline(){return this._pipeline}get frameCount(){return this._frameCount}set frameCount(A){this._frameCount=A}get width(){return this.textmodeCanvas.width}get height(){return this.textmodeCanvas.height}get isDisposed(){return this._isDisposed}}class R{static async create(A,e={}){if(A instanceof HTMLCanvasElement||A instanceof HTMLVideoElement)return S.create(A,e);{const t=A||{};return S.create(null,t)}}static setErrorLevel(A){m.setGlobalLevel(A)}static get version(){return"0.1.4-beta.5"}constructor(){throw new Error("Textmode is a static class and cannot be instantiated.")}}const GA=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),MA=R.create,UA=R.setErrorLevel,YA=R.version;C.TextmodeCanvas=K,C.TextmodeConversionPipeline=Z,C.TextmodeErrorLevel=v,C.TextmodeFont=J,C.TextmodeGrid=j,C.Textmodifier=S,C.converters=PA,C.create=MA,C.default=R,C.export=GA,C.setErrorLevel=UA,C.textmode=R,C.version=YA,Object.defineProperties(C,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
26
|
+
`;return t.join(r)}}class FA extends O{saveTXT(A,e){try{const t=this.ensureValidFilename(e);this.downloadFile(A,t,"text/plain;charset=utf-8")}catch(t){throw console.error("Failed to save TXT file:",t),new Error(`TXT file save failed: ${t instanceof Error?t.message:"Unknown error"}`)}}ensureValidFilename(A){let e=this.sanitizeFilename(A);return e===".txt"||e.length<=4?this.generateDefaultFilename():e}}class AA{constructor(){a(this,"dataExtractor");a(this,"contentGenerator");a(this,"fileHandler");this.dataExtractor=new vA,this.contentGenerator=new xA,this.fileHandler=new FA}applyDefaultOptions(A){return{preserveTrailingSpaces:A.preserveTrailingSpaces??!1,lineEnding:A.lineEnding??"lf",emptyCharacter:A.emptyCharacter??" "}}generateTXT(A,e={}){const t=this.applyDefaultOptions(e),r=this.dataExtractor.extractFramebufferData(A.pipeline),i=this.dataExtractor.extractCharacterGrid(r,A.grid,A.font,t.emptyCharacter);return this.contentGenerator.generateTXTContent(i,t)}saveTXT(A,e={}){try{const t=this.generateTXT(A,e),r=e.filename||this.fileHandler.generateDefaultFilename();this.fileHandler.saveTXT(t,r)}catch(t){throw console.error("Failed to save TXT:",t),new Error(`TXT save failed: ${t instanceof Error?t.message:"Unknown error"}`)}}}class yA extends V{captureCanvasData(A,e=1,t="transparent"){const r=A.canvas;if(e===1&&t==="transparent")return r;const i=document.createElement("canvas"),s=i.getContext("2d"),o=Math.round(r.width*e),g=Math.round(r.height*e);return i.width=o,i.height=g,t!=="transparent"&&(s.fillStyle=t,s.fillRect(0,0,o,g)),s.imageSmoothingEnabled=!1,s.drawImage(r,0,0,r.width,r.height,0,0,o,g),i}}class TA{generateImageData(A,e){const t=this.getMimeType(e.format);return e.format==="png"?A.toDataURL(t):A.toDataURL(t,e.quality)}async generateImageBlob(A,e){return new Promise((t,r)=>{const i=this.getMimeType(e.format),s=o=>{o?t(o):r(new Error(`Failed to generate ${e.format.toUpperCase()} blob`))};e.format==="png"?A.toBlob(s,i):A.toBlob(s,i,e.quality)})}getMimeType(A){switch(A){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw new Error(`Unsupported image format: ${A}`)}}}const eA={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},z={png:".png",jpg:".jpg",webp:".webp"};class SA extends O{saveImage(A,e,t){try{const r=z[t];typeof A=="string"?this.saveImageFromDataURL(A,this.sanitizeFilename(e)+r):this.saveImageFromBlob(A,this.sanitizeFilename(e)+r)}catch(r){throw console.error(`Failed to save ${t.toUpperCase()} image:`,r),new Error(`Image save failed: ${r instanceof Error?r.message:"Unknown error"}`)}}saveImageFromDataURL(A,e){const t=document.createElement("a");t.href=A,t.download=e,t.style.display="none",t.rel="noopener",document.body.appendChild(t),t.click(),document.body.removeChild(t)}saveImageFromBlob(A,e){const t=URL.createObjectURL(A);try{const r=document.createElement("a");r.href=t,r.download=e,r.style.display="none",r.rel="noopener",document.body.appendChild(r),r.click(),document.body.removeChild(r)}finally{URL.revokeObjectURL(t)}}validateSaveSupport(A){return A in eA&&A in z}getMimeType(A){return eA[A]}getFileExtension(A){return z[A]}}class RA{constructor(){a(this,"dataExtractor");a(this,"contentGenerator");a(this,"fileHandler");this.dataExtractor=new yA,this.contentGenerator=new TA,this.fileHandler=new SA}applyDefaultOptions(A){return{format:A.format??"png",quality:A.quality??1,scale:A.scale??1,backgroundColor:A.backgroundColor??"transparent"}}validateOptions(A){if(console.log("Validating image export options:",A),!this.fileHandler.validateSaveSupport(A.format))throw new Error(`Saving '${A.format}' files is not supported`);if(A.quality<0||A.quality>1)throw new Error("Image quality must be between 0.0 and 1.0");if(A.scale<=0)throw new Error("Scale factor must be greater than 0");A.scale>10&&console.warn("Large scale factors may result in very large files and slow performance"),A.format==="jpg"&&A.backgroundColor==="transparent"&&(A.backgroundColor="black")}generateImage(A,e={}){const t=this.applyDefaultOptions(e);if(this.validateOptions(t),t.scale===1&&t.backgroundColor==="transparent")return this.contentGenerator.generateImageData(A.canvas,t);const r=this.dataExtractor.captureCanvasData(A,t.scale,t.backgroundColor);return this.contentGenerator.generateImageData(r,t)}async generateImageBlob(A,e={}){const t=this.applyDefaultOptions(e);if(this.validateOptions(t),t.scale===1&&t.backgroundColor==="transparent")return await this.contentGenerator.generateImageBlob(A.canvas,t);const r=this.dataExtractor.captureCanvasData(A,t.scale,t.backgroundColor);return await this.contentGenerator.generateImageBlob(r,t)}async saveImage(A,e={}){try{const t=await this.generateImageBlob(A,e),r=e.format??"png",i=e.filename||this.fileHandler.generateDefaultFilename();this.fileHandler.saveImage(t,i,r)}catch(t){throw console.error("Failed to save image:",t),new Error(`Image save failed: ${t instanceof Error?t.message:"Unknown error"}`)}}}class S{constructor(A=null,e={}){a(this,"captureSource");a(this,"textmodeCanvas");a(this,"_renderer");a(this,"_canvasFramebuffer");a(this,"_font");a(this,"_grid");a(this,"resizeObserver");a(this,"_mode");a(this,"_frameRateLimit");a(this,"animationFrameId",null);a(this,"lastFrameTime",0);a(this,"frameInterval");a(this,"_isLooping",!0);a(this,"_frameRate",0);a(this,"lastRenderTime",0);a(this,"_frameCount",0);a(this,"frameTimeHistory",[]);a(this,"frameTimeHistorySize",10);a(this,"_pipeline");a(this,"_isDisposed",!1);a(this,"_standalone",!1);a(this,"_drawCallback",()=>{});a(this,"_resizedCallback",()=>{});a(this,"_windowResizeListener",null);a(this,"_printDebug",!1);this.captureSource=A,this._standalone=A===null,this._mode=e.renderMode??"auto",this._frameRateLimit=e.frameRate??60,this.frameInterval=1e3/this._frameRateLimit}static async create(A=null,e={}){const t=new S(A,e),r=t._standalone?e:void 0;t.textmodeCanvas=new K(t.captureSource,t._standalone,r),t._renderer=new gA(t.textmodeCanvas.getWebGLContext());let i,s;t._standalone?(i=e.width||800,s=e.height||600):(i=t.textmodeCanvas.width||800,s=t.textmodeCanvas.height||600),t._canvasFramebuffer=t._renderer.createFramebuffer(i,s),t._font=new J(t._renderer,e.fontSize??16),await t._font.initialize(e.fontSource);const o=t._font.maxGlyphDimensions;return t._grid=new j(t.textmodeCanvas.canvas,o.width,o.height),t._pipeline=new Z(t._renderer,t._font,t._grid),t.setupEventListeners(),t.startAutoRendering(),t}setupEventListeners(){this._windowResizeListener=()=>{this._standalone?this._resizedCallback():this.resize()},window.addEventListener("resize",this._windowResizeListener),window.ResizeObserver&&this.captureSource&&!this._standalone&&(this.resizeObserver=new ResizeObserver(()=>{this.resize()}),this.resizeObserver.observe(this.captureSource))}toString(A={}){return new AA().generateTXT(this,A)}saveStrings(A={}){new AA().saveTXT(this,A)}toSVG(A={}){return new q().generateSVG(this,A)}saveSVG(A={}){new q().saveSVG(this,A)}async saveCanvas(A,e="png",t={}){await new RA().saveImage(this.textmodeCanvas,{...t,filename:A,format:e})}async loadFont(A){return this._font.loadFont(A).then(()=>{const e=this._font.maxGlyphDimensions;this._grid.resizeCellPixelDimensions(e.width,e.height),this._pipeline.resize()})}render(){if(this.measureFrameRate(),this._frameCount++,this._isDisposed){console.warn("Cannot render: Required resources have been disposed");return}if(this._standalone?this._canvasFramebuffer&&(this._canvasFramebuffer.begin(),this._drawCallback(),this._renderer&&this._renderer.reset(),this._canvasFramebuffer&&this._canvasFramebuffer.end()):this.captureSource&&this._canvasFramebuffer&&this._canvasFramebuffer.update(this.captureSource),!this._pipeline||!this._renderer){console.warn("Cannot complete render: Pipeline or renderer has been disposed");return}if(this._pipeline.render(this._canvasFramebuffer),this._pipeline.hasEnabledConverters()?(this._renderer.background(0),this._renderer.image(this._pipeline.texture,this._grid.offsetX,this._grid.offsetY,this._pipeline.texture.width,this._pipeline.texture.height)):(this._renderer.clear(),this._renderer.image(this._canvasFramebuffer,this._grid.offsetX,this._grid.offsetY,this._canvasFramebuffer.width,this._canvasFramebuffer.height)),this._printDebug){let A=0;this._renderer.image(this._pipeline.characterFramebuffer,A,0,this._pipeline.characterFramebuffer.width,this._pipeline.characterFramebuffer.height),A+=this._pipeline.characterFramebuffer.width,this._renderer.image(this._pipeline.primaryColorFramebuffer,A,0,this._pipeline.primaryColorFramebuffer.width,this._pipeline.primaryColorFramebuffer.height),A+=this._pipeline.primaryColorFramebuffer.width,this._renderer.image(this._pipeline.secondaryColorFramebuffer,A,0,this._pipeline.secondaryColorFramebuffer.width,this._pipeline.secondaryColorFramebuffer.height),A+=this._pipeline.secondaryColorFramebuffer.width,this._renderer.image(this._pipeline.transformFramebuffer,A,0,this._pipeline.transformFramebuffer.width,this._pipeline.transformFramebuffer.height),A+=this._pipeline.transformFramebuffer.width,this._renderer.image(this._pipeline.rotationFramebuffer,A,0,this._pipeline.rotationFramebuffer.width,this._pipeline.rotationFramebuffer.height)}}resize(){this.textmodeCanvas.resize(),this._canvasFramebuffer.resize(this.textmodeCanvas.width,this.textmodeCanvas.height),this._grid.resize(),this._pipeline.resize(),this._renderer.resetViewport(),this._mode!=="manual"&&this.render()}startAutoRendering(){if(this._mode!=="auto"||!this._isLooping)return;this.lastFrameTime=performance.now();const A=e=>{if(!this._isLooping){this.animationFrameId=null;return}const t=e-this.lastFrameTime;t>=this.frameInterval&&(this.render(),this.lastFrameTime=e-t%this.frameInterval),this._isLooping&&(this.animationFrameId=requestAnimationFrame(A))};this.animationFrameId=requestAnimationFrame(A)}measureFrameRate(){const A=performance.now();if(this.lastRenderTime>0){const e=A-this.lastRenderTime;this.frameTimeHistory.push(e),this.frameTimeHistory.length>this.frameTimeHistorySize&&this.frameTimeHistory.shift();const t=this.frameTimeHistory.reduce((r,i)=>r+i,0)/this.frameTimeHistory.length;this._frameRate=1e3/t}this.lastRenderTime=A}stopAutoRendering(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}renderMode(A){this._mode!==A&&(this.stopAutoRendering(),this._mode=A,A==="auto"&&this._isLooping&&this.startAutoRendering())}frameRate(A){if(A===void 0)return this._frameRate;this._frameRateLimit=A,this.frameInterval=1e3/A,this._mode==="auto"&&this._isLooping&&(this.stopAutoRendering(),this.startAutoRendering())}noLoop(){this._isLooping&&(this._isLooping=!1,this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null))}loop(){this._isLooping||(this._isLooping=!0,this._mode==="auto"&&this.startAutoRendering())}isLooping(){return this._mode==="auto"&&this._isLooping}fontSize(A){m.validate(typeof A=="number"&&A>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:A})&&this._font.fontSize!==A&&(this._font.setFontSize(A),this._grid.resizeCellPixelDimensions(this._font.maxGlyphDimensions.width,this._font.maxGlyphDimensions.height),this._pipeline.resize(),this._renderer.resetViewport())}draw(A){this._drawCallback=A}windowResized(A){this._resizedCallback=A}resizeCanvas(A,e){this.textmodeCanvas.resize(A,e),this._canvasFramebuffer.resize(this.textmodeCanvas.width,this.textmodeCanvas.height),this._grid.resize(),this._pipeline.resize(),this._renderer.resetViewport(),this._mode!=="manual"&&this.render()}converter(A){return this._pipeline.get(A)}fill(A,e,t,r){this._renderer.fill(A,e,t,r)}stroke(A,e,t,r){this._renderer.stroke(A,e,t,r)}strokeWeight(A){this._renderer.strokeWeight(A)}noStroke(){this._renderer.noStroke()}noFill(){this._renderer.noFill()}rotate(A){this._renderer.rotate(A)}push(){this._renderer.push()}pop(){this._renderer.pop()}rect(A,e,t=1,r=1){this._renderer.rect(A,e,t,r)}line(A,e,t,r){this._renderer.line(A,e,t,r)}background(A,e=A,t=A,r=255){this._renderer.background(A,e,t,r)}createShader(A,e){return this._renderer.createShader(A,e)}createFilterShader(A){return this._renderer.createFilterShader(A)}shader(A){this._renderer.shader(A)}setUniform(A,e){this._renderer.setUniform(A,e)}destroy(){this._isDisposed=!0,this.stopAutoRendering(),this._windowResizeListener&&(window.removeEventListener("resize",this._windowResizeListener),this._windowResizeListener=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this._pipeline.dispose(),this._font.dispose(),this._grid.dispose(),this._canvasFramebuffer.dispose(),this._renderer.dispose(),this.textmodeCanvas.dispose(),this.captureSource=null,this.textmodeCanvas=null,this._renderer=null,this._canvasFramebuffer=null,this._font=null,this._grid=null,this._pipeline=null,this.resizeObserver=null,this._drawCallback=()=>{},this._resizedCallback=()=>{},this.animationFrameId=null,this.lastFrameTime=0,this.lastRenderTime=0,this._frameCount=0,this._frameRate=0,this.frameTimeHistory=[],this._isLooping=!1}debug(A){this._printDebug=A}get grid(){return this._grid}get font(){return this._font}get mode(){return this._mode}get pipeline(){return this._pipeline}get frameCount(){return this._frameCount}set frameCount(A){this._frameCount=A}get width(){return this.textmodeCanvas.width}get height(){return this.textmodeCanvas.height}get isDisposed(){return this._isDisposed}}class R{static async create(A,e={}){if(A instanceof HTMLCanvasElement||A instanceof HTMLVideoElement)return S.create(A,e);{const t=A||{};return S.create(null,t)}}static setErrorLevel(A){m.setGlobalLevel(A)}static get version(){return"0.1.4-beta.8"}constructor(){throw new Error("Textmode is a static class and cannot be instantiated.")}}const GA=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),MA=R.create,UA=R.setErrorLevel,YA=R.version;C.TextmodeCanvas=K,C.TextmodeConversionPipeline=Z,C.TextmodeErrorLevel=v,C.TextmodeFont=J,C.TextmodeGrid=j,C.Textmodifier=S,C.converters=PA,C.create=MA,C.default=R,C.export=GA,C.setErrorLevel=UA,C.textmode=R,C.version=YA,Object.defineProperties(C,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/textmode.umd.min.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
- ${s}: ${n}`}}return i+=`
|
|
5
5
|
|
|
6
6
|
`,i+="↓".repeat(24)+`
|
|
7
|
-
`,i}static formatValue(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="number"||typeof t=="boolean")return String(t);if(Array.isArray(t))return t.length===0?"[]":t.length<=5?`[${t.map(r=>_.formatValue(r)).join(", ")}]`:`[${t.slice(0,3).map(r=>_.formatValue(r)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const r=Object.keys(t);return r.length===0?"{}":r.length<=3?`{ ${r.map(a=>`${a}: ${_.formatValue(t[a])}`).join(", ")} }`:`{ ${r.slice(0,2).map(s=>`${s}: ${_.formatValue(t[s])}`).join(", ")}, ... +${r.length-2} more }`}return String(t)}}var E=(l=>(l[l.SILENT=0]="SILENT",l[l.WARNING=1]="WARNING",l[l.ERROR=2]="ERROR",l[l.THROW=3]="THROW",l))(E||{});const U=class U{constructor(){o(this,"_options",{globalLevel:3})}static getInstance(){return U._instance||(U._instance=new U),U._instance}_handle(e,t,r){const i="[textmode.js]";switch(this._options.globalLevel){case 0:return!1;case 1:return console.group(`%c${i} Oops! (╯°□°)╯︵ Something went wrong in your code.`,"color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;"),console.warn(_.createFormattedMessage(e,t)),console.groupEnd(),!1;case 2:return console.group(`%c${i} Oops! (╯°□°)╯︵ Something went wrong in your code.`,"color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;"),console.error(_.createFormattedMessage(e,t)),console.groupEnd(),!1;case 3:default:const s=new _(e,r,t);throw console.group(`%c${i} Oops! (╯°□°)╯︵ Something went wrong in your code.`,"color: #d32f2f; font-weight: bold; background: #ffcdd2; padding: 2px 6px; border-radius: 3px;"),s}}validate(e,t,r){return e?!0:(this._handle(t,r),!1)}setGlobalLevel(e){this._options.globalLevel=e}};o(U,"_instance",null);let V=U;const b=V.getInstance();class ie{constructor(e,t,r=t,i={}){o(this,"gl");o(this,"_framebuffer");o(this,"_texture");o(this,"_width");o(this,"_height");o(this,"options");o(this,"previousState",null);o(this,"_pixels",null);this.gl=e,this._width=t,this._height=r,this.options={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...i},this._texture=this.createTexture(),this._framebuffer=e.createFramebuffer(),this.attachTexture()}createTexture(){const{gl:e}=this,t=e.createTexture();e.bindTexture(e.TEXTURE_2D,t);const r=this.options.filter==="linear"?e.LINEAR:e.NEAREST,i=this.options.wrap==="repeat"?e.REPEAT:e.CLAMP_TO_EDGE;return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,i),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,i),this.updateTextureSize(),t}updateTextureSize(){const{gl:e}=this,t=e.RGBA,r=e.RGBA,i=this.options.type==="float"?e.FLOAT:e.UNSIGNED_BYTE;e.texImage2D(e.TEXTURE_2D,0,t,this._width,this._height,0,r,i,null)}attachTexture(){const{gl:e}=this;e.bindFramebuffer(e.FRAMEBUFFER,this._framebuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this._texture,0),e.bindFramebuffer(e.FRAMEBUFFER,null)}update(e){const{gl:t}=this;e instanceof HTMLVideoElement&&e.readyState<2||(t.bindTexture(t.TEXTURE_2D,this._texture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.bindTexture(t.TEXTURE_2D,null))}updatePixels(e,t,r){const{gl:i}=this;i.bindTexture(i.TEXTURE_2D,this._texture),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t,r,0,i.RGBA,i.UNSIGNED_BYTE,e),i.bindTexture(i.TEXTURE_2D,null)}resize(e,t){const{gl:r}=this;this._width=e,this._height=t,r.bindTexture(r.TEXTURE_2D,this._texture),this.updateTextureSize(),r.bindTexture(r.TEXTURE_2D,null)}begin(){const{gl:e}=this;this.previousState={framebuffer:e.getParameter(e.FRAMEBUFFER_BINDING),viewport:e.getParameter(e.VIEWPORT)},e.bindFramebuffer(e.FRAMEBUFFER,this._framebuffer),e.viewport(0,0,this._width,this._height)}end(){if(!this.previousState)return;const{gl:e}=this;e.bindFramebuffer(e.FRAMEBUFFER,this.previousState.framebuffer),e.viewport(...this.previousState.viewport),this.previousState=null}loadPixels(){const{gl:e}=this;this._pixels||(this._pixels=new Uint8Array(this._width*this._height*4));const t=e.getParameter(e.FRAMEBUFFER_BINDING);e.bindFramebuffer(e.FRAMEBUFFER,this._framebuffer),e.readPixels(0,0,this._width,this._height,e.RGBA,e.UNSIGNED_BYTE,this._pixels),e.bindFramebuffer(e.FRAMEBUFFER,t)}get(e,t,r,i){const{gl:s}=this;if(e===void 0&&t===void 0){const a=new Uint8Array(this._width*this._height*4),n=s.getParameter(s.FRAMEBUFFER_BINDING);return s.bindFramebuffer(s.FRAMEBUFFER,this._framebuffer),s.readPixels(0,0,this._width,this._height,s.RGBA,s.UNSIGNED_BYTE,a),s.bindFramebuffer(s.FRAMEBUFFER,n),a}else if(r===void 0&&i===void 0){(e<0||t<0||e>=this._width||t>=this._height)&&(console.warn("The x and y values passed to Framebuffer.get are outside of its range and will be clamped."),e=Math.max(0,Math.min(e,this._width-1)),t=Math.max(0,Math.min(t,this._height-1)));const a=new Uint8Array(4),n=s.getParameter(s.FRAMEBUFFER_BINDING);return s.bindFramebuffer(s.FRAMEBUFFER,this._framebuffer),s.readPixels(e,t,1,1,s.RGBA,s.UNSIGNED_BYTE,a),s.bindFramebuffer(s.FRAMEBUFFER,n),[a[0],a[1],a[2],a[3]]}else{e=Math.max(0,Math.min(e,this._width-1)),t=Math.max(0,Math.min(t,this._height-1)),r=Math.max(1,Math.min(r,this._width-e)),i=Math.max(1,Math.min(i,this._height-t));const a=new Uint8Array(r*i*4),n=s.getParameter(s.FRAMEBUFFER_BINDING);return s.bindFramebuffer(s.FRAMEBUFFER,this._framebuffer),s.readPixels(e,t,r,i,s.RGBA,s.UNSIGNED_BYTE,a),s.bindFramebuffer(s.FRAMEBUFFER,n),a}}dispose(){const{gl:e}=this;this._framebuffer&&(e.deleteFramebuffer(this._framebuffer),this._framebuffer=null),this._texture&&(e.deleteTexture(this._texture),this._texture=null),this._pixels=null}get framebuffer(){return this._framebuffer}get texture(){return this._texture}get width(){return this._width}get height(){return this._height}get pixels(){return this._pixels}}class j{constructor(e,t,r){o(this,"gl");o(this,"x");o(this,"y");this.gl=e,this.x=t,this.y=r}}class D{constructor(e,t,r,i,s){o(this,"gl");o(this,"vertexBuffer");o(this,"vertexCount",6);o(this,"bytesPerVertex");this.gl=e,this.bytesPerVertex=16;const a=e.getParameter(e.VIEWPORT),n=a[2],h=a[3],c=e.getParameter(e.FRAMEBUFFER_BINDING)!==null,u=t/n*2-1,d=(t+i)/n*2-1;let f,g;c?(f=r/h*2-1,g=(r+s)/h*2-1):(f=1-r/h*2,g=1-(r+s)/h*2);let x,p,F,w;x=u,F=d,p=f,w=g;const C=this.generateVertices(x,p,F,w);this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,C,e.STATIC_DRAW)}generateVertices(e,t,r,i){return new Float32Array([e,i,0,1,r,i,1,1,e,t,0,0,e,t,0,0,r,i,1,1,r,t,1,0])}render(){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);const e=this.gl.getParameter(this.gl.CURRENT_PROGRAM);let t=this.gl.getAttribLocation(e,"a_position"),r=this.gl.getAttribLocation(e,"a_texCoord");this.gl.enableVertexAttribArray(t),this.gl.vertexAttribPointer(t,2,this.gl.FLOAT,!1,this.bytesPerVertex,0),this.gl.enableVertexAttribArray(r),this.gl.vertexAttribPointer(r,2,this.gl.FLOAT,!1,this.bytesPerVertex,8),this.gl.drawArrays(this.gl.TRIANGLES,0,this.vertexCount),this.gl.disableVertexAttribArray(t),this.gl.disableVertexAttribArray(r)}}class se extends j{constructor(t,r,i,s,a){super(t,r,i);o(this,"width");o(this,"height");this.width=s,this.height=a}renderFill(){new D(this.gl,this.x,this.y,this.width,this.height).render()}renderStroke(t){if(t<=0)return;const r=new D(this.gl,this.x,this.y,this.width,t),i=new D(this.gl,this.x+this.width-t,this.y,t,this.height),s=new D(this.gl,this.x,this.y+this.height-t,this.width,t),a=new D(this.gl,this.x,this.y,t,this.height);r.render(),i.render(),s.render(),a.render()}}class ae{constructor(e,t,r,i,s,a){o(this,"gl");o(this,"vertexBuffer");o(this,"vertexCount",6);o(this,"bytesPerVertex");this.gl=e,this.bytesPerVertex=16;const n=e.getParameter(e.VIEWPORT),h=n[2],c=n[3],u=e.getParameter(e.FRAMEBUFFER_BINDING)!==null,d=i-t,f=s-r,g=Math.sqrt(d*d+f*f);if(g===0){const Oe=this.generateVertices(0,0,0,0);this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,Oe,e.STATIC_DRAW);return}const x=d/g,F=-(f/g),w=x,C=a/2,y=t+F*C,B=r+w*C,A=t-F*C,R=r-w*C,X=i+F*C,G=s+w*C,ke=i-F*C,re=s-w*C,ze=y/h*2-1,$e=A/h*2-1,Le=X/h*2-1,He=ke/h*2-1;let O,N,W,Y;u?(O=B/c*2-1,N=R/c*2-1,W=G/c*2-1,Y=re/c*2-1):(O=1-B/c*2,N=1-R/c*2,W=1-G/c*2,Y=1-re/c*2);const Xe=this.generateLineVertices(ze,O,$e,N,Le,W,He,Y);this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,Xe,e.STATIC_DRAW)}generateVertices(e,t,r,i){return new Float32Array([e,i,0,1,r,i,1,1,e,t,0,0,e,t,0,0,r,i,1,1,r,t,1,0])}generateLineVertices(e,t,r,i,s,a,n,h){return new Float32Array([e,t,0,0,r,i,0,1,s,a,1,0,r,i,0,1,n,h,1,1,s,a,1,0])}render(){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);const e=this.gl.getParameter(this.gl.CURRENT_PROGRAM);let t=this.gl.getAttribLocation(e,"a_position"),r=this.gl.getAttribLocation(e,"a_texCoord");this.gl.enableVertexAttribArray(t),this.gl.vertexAttribPointer(t,2,this.gl.FLOAT,!1,this.bytesPerVertex,0),this.gl.enableVertexAttribArray(r),this.gl.vertexAttribPointer(r,2,this.gl.FLOAT,!1,this.bytesPerVertex,8),this.gl.drawArrays(this.gl.TRIANGLES,0,this.vertexCount),this.gl.disableVertexAttribArray(t),this.gl.disableVertexAttribArray(r)}}class ne extends j{constructor(t,r,i,s,a){super(t,r,i);o(this,"x2");o(this,"y2");this.x2=s,this.y2=a}renderFill(){}renderStroke(t){if(t<=0)return;new ae(this.gl,this.x,this.y,this.x2,this.y2,t).render()}}class T{constructor(e,t,r){o(this,"gl");o(this,"program");o(this,"uniformLocations",new Map);o(this,"attributeLocations",new Map);o(this,"textureUnitCounter",0);this.gl=e,this.program=this.createProgram(t,r),this.cacheLocations()}createProgram(e,t){const r=this.createShader(this.gl.VERTEX_SHADER,e),i=this.createShader(this.gl.FRAGMENT_SHADER,t),s=this.gl.createProgram();if(this.gl.attachShader(s,r),this.gl.attachShader(s,i),this.gl.linkProgram(s),!this.gl.getProgramParameter(s,this.gl.LINK_STATUS)){const a=this.gl.getProgramInfoLog(s);throw new Error(`Shader program link error: ${a}`)}return this.gl.deleteShader(r),this.gl.deleteShader(i),s}createShader(e,t){const r=this.gl.createShader(e);if(this.gl.shaderSource(r,t),this.gl.compileShader(r),!this.gl.getShaderParameter(r,this.gl.COMPILE_STATUS)){const i=this.gl.getShaderInfoLog(r);throw this.gl.deleteShader(r),new Error(`Shader compilation error: ${i}`)}return r}cacheLocations(){const e=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_UNIFORMS);for(let r=0;r<e;r++){const i=this.gl.getActiveUniform(this.program,r);if(i){const s=this.gl.getUniformLocation(this.program,i.name);s&&this.uniformLocations.set(i.name,s)}}const t=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_ATTRIBUTES);for(let r=0;r<t;r++){const i=this.gl.getActiveAttrib(this.program,r);if(i){const s=this.gl.getAttribLocation(this.program,i.name);this.attributeLocations.set(i.name,s)}}}use(){this.gl.useProgram(this.program),this.resetTextureUnits()}setUniform(e,t){const r=this.uniformLocations.get(e);if(!r)return;const i=this.getUniformInfo(e);if(typeof t=="number")i&&i.type===this.gl.INT?this.gl.uniform1i(r,Math.floor(t)):this.gl.uniform1f(r,t);else if(typeof t=="boolean")this.gl.uniform1i(r,t?1:0);else if(Array.isArray(t))if(i&&(i.type===this.gl.INT_VEC2||i.type===this.gl.INT_VEC3||i.type===this.gl.INT_VEC4)){const s=t.map(a=>Math.floor(a));switch(s.length){case 2:this.gl.uniform2iv(r,s);break;case 3:this.gl.uniform3iv(r,s);break;case 4:this.gl.uniform4iv(r,s);break;default:console.warn(`Unsupported array length ${s.length} for uniform '${e}'`)}}else switch(t.length){case 2:this.gl.uniform2f(r,t[0],t[1]);break;case 3:this.gl.uniform3f(r,t[0],t[1],t[2]);break;case 4:this.gl.uniform4f(r,t[0],t[1],t[2],t[3]);break;default:console.warn(`Unsupported array length ${t.length} for uniform '${e}'`)}else if(t instanceof WebGLTexture){const s=this.getNextTextureUnit();this.gl.uniform1i(r,s),this.gl.activeTexture(this.gl.TEXTURE0+s),this.gl.bindTexture(this.gl.TEXTURE_2D,t)}else if(t&&typeof t=="object"&&"texture"in t){const s=this.getNextTextureUnit();this.gl.uniform1i(r,s),this.gl.activeTexture(this.gl.TEXTURE0+s),this.gl.bindTexture(this.gl.TEXTURE_2D,t.texture)}else console.warn(`Unsupported uniform type for '${e}':`,typeof t)}getUniformInfo(e){const t=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_UNIFORMS);for(let r=0;r<t;r++){const i=this.gl.getActiveUniform(this.program,r);if(i&&i.name===e)return i}return null}getNextTextureUnit(){return this.textureUnitCounter++}hasUniform(e){return this.uniformLocations.has(e)}hasAttribute(e){return this.attributeLocations.has(e)}get glProgram(){return this.program}dispose(){this.program&&(this.gl.deleteProgram(this.program),this.program=null),this.uniformLocations.clear(),this.attributeLocations.clear(),this.textureUnitCounter=0}resetTextureUnits(){this.textureUnitCounter=0}}var S="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);}",oe="precision lowp float;uniform sampler2D u_texture;varying vec2 v_uv;void main(){gl_FragColor=texture2D(u_texture,v_uv);}",le="precision lowp float;uniform vec4 u_color;void main(){gl_FragColor=u_color;}";class he{constructor(e){o(this,"gl");o(this,"imageShader");o(this,"solidColorShader");o(this,"currentShader",null);o(this,"currentFillColor",[1,1,1,1]);o(this,"fillMode",!0);o(this,"currentStrokeColor",[0,0,0,1]);o(this,"currentStrokeWeight",1);o(this,"strokeMode",!0);o(this,"currentRotation",0);o(this,"stateStack",[]);this.gl=e,this.imageShader=new T(this.gl,S,oe),this.solidColorShader=new T(this.gl,S,le),this.gl.enable(this.gl.BLEND),this.gl.blendEquation(this.gl.FUNC_ADD),this.gl.blendFunc(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}shader(e){this.currentShader=e,e.use()}fill(e,t,r,i){if(this.fillMode=!0,t===void 0&&r===void 0&&i===void 0){const s=e/255;this.currentFillColor=[s,s,s,1]}else if(r!==void 0&&i===void 0)this.currentFillColor=[e/255,t/255,r/255,1];else if(r!==void 0&&i!==void 0)this.currentFillColor=[e/255,t/255,r/255,i/255];else throw new Error("Invalid fill parameters. Use fill(gray), fill(r,g,b), or fill(r,g,b,a)")}stroke(e,t,r,i){if(this.strokeMode=!0,t===void 0&&r===void 0&&i===void 0){const s=e/255;this.currentStrokeColor=[s,s,s,1]}else if(r!==void 0&&i===void 0)this.currentStrokeColor=[e/255,t/255,r/255,1];else if(r!==void 0&&i!==void 0)this.currentStrokeColor=[e/255,t/255,r/255,i/255];else throw new Error("Invalid stroke parameters. Use stroke(gray), stroke(r,g,b), or stroke(r,g,b,a)")}strokeWeight(e){if(e<0)throw new Error("Stroke weight must be non-negative");this.currentStrokeWeight=e}noStroke(){this.strokeMode=!1}noFill(){this.fillMode=!1}rotate(e){this.currentRotation=e}push(){this.stateStack.push({fillColor:[...this.currentFillColor],fillMode:this.fillMode,strokeColor:[...this.currentStrokeColor],strokeWeight:this.currentStrokeWeight,strokeMode:this.strokeMode,rotation:this.currentRotation})}pop(){const e=this.stateStack.pop();e?(this.currentFillColor=e.fillColor,this.fillMode=e.fillMode,this.currentStrokeColor=e.strokeColor,this.currentStrokeWeight=e.strokeWeight,this.strokeMode=e.strokeMode,this.currentRotation=e.rotation):console.warn("pop() called without matching push()")}reset(){this.currentShader=null,this.stateStack=[],this.currentRotation=0,this.fillMode=!0,this.strokeMode=!0,this.currentFillColor=[1,1,1,1],this.currentStrokeColor=[0,0,0,1],this.currentStrokeWeight=1}createShader(e,t){return new T(this.gl,e,t)}createFilterShader(e){return new T(this.gl,S,e)}setUniform(e,t){this.currentShader.setUniform(e,t)}rect(e,t,r,i){const s=new se(this.gl,e,t,r,i);if(this.currentShader!==null){if(this.currentRotation!==0){const{centerX:d,centerY:f,radians:g,aspectRatio:x}=this.calculateRotationParams(e,t,r,i);this.setUniform("u_rotation",g),this.setUniform("u_center",[d,f]),this.setUniform("u_aspectRatio",x)}else this.setUniform("u_rotation",0),this.setUniform("u_center",[0,0]),this.setUniform("u_aspectRatio",1);s.renderFill(),this.currentShader=null;return}const a=this.solidColorShader,{centerX:n,centerY:h,radians:c,aspectRatio:u}=this.calculateRotationParams(e,t,r,i);this.fillMode&&(this.shader(a),this.setUniform("u_color",this.currentFillColor),this.setUniform("u_rotation",c),this.setUniform("u_center",[n,h]),this.setUniform("u_aspectRatio",u),s.renderFill()),this.strokeMode&&(this.shader(a),this.setUniform("u_color",this.currentStrokeColor),this.setUniform("u_rotation",c),this.setUniform("u_center",[n,h]),this.setUniform("u_aspectRatio",u),s.renderStroke(this.currentStrokeWeight)),this.currentShader=null}line(e,t,r,i){if(!this.strokeMode)return;const s=new ne(this.gl,e,t,r,i);if(this.currentShader!==null){if(this.currentRotation!==0){const p=(e+r)/2,F=(t+i)/2,w=Math.abs(r-e),C=Math.abs(i-t),{centerX:y,centerY:B,radians:A,aspectRatio:R}=this.calculateRotationParams(p-w/2,F-C/2,w,C);this.setUniform("u_rotation",A),this.setUniform("u_center",[y,B]),this.setUniform("u_aspectRatio",R)}else this.setUniform("u_rotation",0),this.setUniform("u_center",[0,0]),this.setUniform("u_aspectRatio",1);s.renderStroke(this.currentStrokeWeight),this.currentShader=null;return}const a=this.solidColorShader,n=(e+r)/2,h=(t+i)/2,c=Math.abs(r-e),u=Math.abs(i-t),{centerX:d,centerY:f,radians:g,aspectRatio:x}=this.calculateRotationParams(n-c/2,h-u/2,c,u);this.shader(a),this.setUniform("u_color",this.currentStrokeColor),this.setUniform("u_rotation",g),this.setUniform("u_center",[d,f]),this.setUniform("u_aspectRatio",x),s.renderStroke(this.currentStrokeWeight),this.currentShader=null}calculateRotationParams(e,t,r,i){const s=this.gl.getParameter(this.gl.VIEWPORT),a=s[2],n=s[3],h=a/n,c=this.gl.getParameter(this.gl.FRAMEBUFFER_BINDING)!==null,u=e+r/2,d=t+i/2,f=u/a*2-1;let g;c?g=d/n*2-1:g=1-d/n*2;const x=this.currentRotation*Math.PI/180;return{centerX:f,centerY:g,radians:x,aspectRatio:h}}createFramebuffer(e,t,r={}){return new ie(this.gl,e,t,r)}background(e,t=e,r=e,i=255){this.clear(e/255,t/255,r/255,i/255)}clear(e=0,t=0,r=0,i=0){this.gl.clearColor(e,t,r,i),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}resetViewport(){this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height)}get context(){return this.gl}dispose(){this.imageShader.dispose(),this.solidColorShader.dispose(),this.imageShader=null,this.solidColorShader=null,this.currentShader=null,this.stateStack=[]}image(e,t,r,i,s){this.shader(this.imageShader),this.setUniform("u_texture",e.texture);const{centerX:a,centerY:n,radians:h,aspectRatio:c}=this.calculateRotationParams(t,r,i??e.width,s??e.height);this.setUniform("u_rotation",h),this.setUniform("u_center",[a,n]),this.setUniform("u_aspectRatio",c),this.rect(t,r,i??e.width,s??e.height)}}var m={};m.parse=function(l){var e=function(s,a,n,h){var c=m.T,u={cmap:c.cmap,head:c.head,hhea:c.hhea,maxp:c.maxp,hmtx:c.hmtx,loca:c.loca,glyf:c.glyf},d={_data:s,_index:a,_offset:n};for(var f in u){var g=m.findTable(s,f,n);if(g){var x=g[0],p=h[x];p==null&&(p=u[f].parseTab(s,x,g[1],d)),d[f]=h[x]=p}}return d},t=new Uint8Array(l),r={},i=e(t,0,0,r);return[i]},m.findTable=function(l,e,t){for(var r=m.B,i=r.readUshort(l,t+4),s=t+12,a=0;a<i;a++){var n=r.readASCII(l,s,4);r.readUint(l,s+4);var h=r.readUint(l,s+8),c=r.readUint(l,s+12);if(n==e)return[h,c];s+=16}return null},m.T={},m.B={readShort:function(l,e){var t=m.B.t.uint16;return t[0]=l[e]<<8|l[e+1],m.B.t.int16[0]},readUshort:function(l,e){return l[e]<<8|l[e+1]},readUshorts:function(l,e,t){for(var r=[],i=0;i<t;i++)r.push(m.B.readUshort(l,e+i*2));return r},readUint:function(l,e){var t=m.B.t.uint8;return t[3]=l[e],t[2]=l[e+1],t[1]=l[e+2],t[0]=l[e+3],m.B.t.uint32[0]},readASCII:function(l,e,t){for(var r="",i=0;i<t;i++)r+=String.fromCharCode(l[e+i]);return r},t:function(){var l=new ArrayBuffer(8);return{uint8:new Uint8Array(l),int16:new Int16Array(l),uint16:new Uint16Array(l),uint32:new Uint32Array(l)}}()},m.T.cmap={parseTab:function(l,e,t){var r={tables:[],ids:{},off:e};l=new Uint8Array(l.buffer,e,t),e=0;var i=m.B,s=i.readUshort,a=m.T.cmap;s(l,e),e+=2;var n=s(l,e);e+=2;for(var h=[],c=0;c<n;c++){var u=s(l,e);e+=2;var d=s(l,e);e+=2;var f=i.readUint(l,e);e+=4;var g="p"+u+"e"+d,x=h.indexOf(f);if(x==-1){x=r.tables.length;var p={};h.push(f);var F=p.format=s(l,f);F==4?p=a.parse4(l,f,p):F==12&&(p=a.parse12(l,f,p)),r.tables.push(p)}r.ids[g]!=null&&console.log("multiple tables for one platform+encoding: "+g),r.ids[g]=x}return r},parse4:function(l,e,t){var r=m.B,i=r.readUshort,s=r.readUshorts,a=e;e+=2;var n=i(l,e);e+=2,i(l,e),e+=2;var h=i(l,e);e+=2;var c=h>>>1;t.searchRange=i(l,e),e+=2,t.entrySelector=i(l,e),e+=2,t.rangeShift=i(l,e),e+=2,t.endCount=s(l,e,c),e+=c*2,e+=2,t.startCount=s(l,e,c),e+=c*2,t.idDelta=[];for(var u=0;u<c;u++)t.idDelta.push(r.readShort(l,e)),e+=2;return t.idRangeOffset=s(l,e,c),e+=c*2,t.glyphIdArray=s(l,e,a+n-e>>1),t},parse12:function(l,e,t){var r=m.B,i=r.readUint;e+=4,i(l,e),e+=4,i(l,e),e+=4;var s=i(l,e)*3;e+=4;for(var a=t.groups=new Uint32Array(s),n=0;n<s;n+=3)a[n]=i(l,e+(n<<2)),a[n+1]=i(l,e+(n<<2)+4),a[n+2]=i(l,e+(n<<2)+8);return t}},m.T.head={parseTab:function(l,e,t){var r=m.B,i={};return e+=18,i.unitsPerEm=r.readUshort(l,e),e+=2,e+=16,i.xMin=r.readShort(l,e),e+=2,i.yMin=r.readShort(l,e),e+=2,i.xMax=r.readShort(l,e),e+=2,i.yMax=r.readShort(l,e),e+=2,e+=6,i.indexToLocFormat=r.readShort(l,e),i}},m.T.hhea={parseTab:function(l,e,t){var r=m.B,i={};e+=4;for(var s=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],a=0;a<s.length;a++){var n=s[a],h=n=="advanceWidthMax"||n=="numberOfHMetrics"?r.readUshort:r.readShort;i[n]=h(l,e+a*2)}return i}},m.T.hmtx={parseTab:function(l,e,t,r){for(var i=m.B,s=[],a=[],n=r.maxp.numGlyphs,h=r.hhea.numberOfHMetrics,c=0,u=0,d=0;d<h;)c=i.readUshort(l,e+(d<<2)),u=i.readShort(l,e+(d<<2)+2),s.push(c),a.push(u),d++;for(;d<n;)s.push(c),a.push(u),d++;return{aWidth:s,lsBearing:a}}},m.T.maxp={parseTab:function(l,e,t){var r=m.B,i=r.readUshort,s={};return r.readUint(l,e),e+=4,s.numGlyphs=i(l,e),e+=2,s}},m.T.loca={parseTab:function(l,e,t,r){var i=m.B,s=[],a=r.head.indexToLocFormat,n=r.maxp.numGlyphs+1;if(a==0)for(var h=0;h<n;h++)s.push(i.readUshort(l,e+(h<<1))<<1);if(a==1)for(var h=0;h<n;h++)s.push(i.readUint(l,e+(h<<2)));return s}},m.T.glyf={parseTab:function(l,e,t,r){for(var i=[],s=r.maxp.numGlyphs,a=0;a<s;a++)i.push(null);return i},_parseGlyf:function(l,e){var t=m.B,r=l._data,i=l.loca;if(i[e]==i[e+1])return null;var s=m.findTable(r,"glyf",l._offset)[0]+i[e],a={};if(a.noc=t.readShort(r,s),s+=2,a.xMin=t.readShort(r,s),s+=2,a.yMin=t.readShort(r,s),s+=2,a.xMax=t.readShort(r,s),s+=2,a.yMax=t.readShort(r,s),s+=2,a.xMin>=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(var n=0;n<a.noc;n++)a.endPts.push(t.readUshort(r,s)),s+=2;var h=t.readUshort(r,s);if(s+=2,r.length-s<h)return null;s+=h;var c=a.endPts[a.noc-1]+1;a.flags=[];for(var n=0;n<c;n++){var u=r[s];if(s++,a.flags.push(u),u&8){var d=r[s];s++;for(var f=0;f<d;f++)a.flags.push(u),n++}}a.xs=[];for(var n=0;n<c;n++){var g=(a.flags[n]&2)!=0,x=(a.flags[n]&16)!=0;g?(a.xs.push(x?r[s]:-r[s]),s++):x?a.xs.push(0):(a.xs.push(t.readShort(r,s)),s+=2)}a.ys=[];for(var n=0;n<c;n++){var g=(a.flags[n]&4)!=0,x=(a.flags[n]&32)!=0;g?(a.ys.push(x?r[s]:-r[s]),s++):x?a.ys.push(0):(a.ys.push(t.readShort(r,s)),s+=2)}for(var p=0,F=0,n=0;n<c;n++)p+=a.xs[n],F+=a.ys[n],a.xs[n]=p,a.ys[n]=F}else a.parts=[];return a}},typeof module<"u"&&module.exports?module.exports=m:typeof window<"u"&&(window.Typr=m);class ce{extractCharacters(e){var r;const t=[];return(r=e==null?void 0:e.cmap)!=null&&r.tables?(e.cmap.tables.forEach(i=>{if(i.format===4){const s=this._extractCharactersFromFormat4Table(i);t.push(...s)}else if(i.format===12){const s=this._extractCharactersFromFormat12Table(i);t.push(...s)}}),[...new Set(t)]):[]}_extractCharactersFromFormat4Table(e){const t=[];if(!e.startCount||!e.endCount||!e.idRangeOffset||!e.idDelta)return t;for(let r=0;r<e.startCount.length;r++){const i=e.startCount[r],s=e.endCount[r];if(!(i===65535&&s===65535)){for(let a=i;a<=s;a++)if(this._calculateGlyphIndexFormat4(e,a,r)>0){const h=String.fromCodePoint(a);t.push(h)}}}return t}_extractCharactersFromFormat12Table(e){const t=[];if(!e.groups)return t;for(let r=0;r<e.groups.length;r+=3){const i=e.groups[r],s=e.groups[r+1],a=e.groups[r+2];for(let n=i;n<=s;n++)if(a+(n-i)>0){const c=String.fromCodePoint(n);t.push(c)}}return t}_calculateGlyphIndexFormat4(e,t,r){if(e.idRangeOffset[r]===0)return t+e.idDelta[r]&65535;{const i=e.idRangeOffset[r]/2+(t-e.startCount[r])-(e.startCount.length-r);if(i>=0&&e.glyphIdArray&&i<e.glyphIdArray.length){const s=e.glyphIdArray[i];if(s!==0)return s+e.idDelta[r]&65535}}return 0}filterProblematicCharacters(e){return e.filter(t=>this._isValidCharacter(t))}_isValidCharacter(e){const t=e.codePointAt(0)||0;return!(t>=0&&t<=31&&t!==9&&t!==10&&t!==13||t>=127&&t<=159)}}class ue{constructor(e){o(this,"_textureCanvas");o(this,"_textureContext");o(this,"_renderer");this._renderer=e,this._textureCanvas=document.createElement("canvas"),this._textureContext=this._textureCanvas.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(e,t,r,i){const s=e.length,a=Math.ceil(Math.sqrt(s)),n=Math.ceil(s/a),h=t.width*a,c=t.height*n;this._setupCanvas(h,c,r,i),this._renderCharactersToCanvas(e,t,a,r),this._applyBlackWhiteThreshold();const u=this._renderer.createFramebuffer(h,c,{filter:"nearest"});return u.update(this._textureCanvas),{framebuffer:u,columns:a,rows:n}}_setupCanvas(e,t,r,i){this._textureCanvas.width=e,this._textureCanvas.height=t,this._textureCanvas.style.width=e+"px",this._textureCanvas.style.height=e+"px",this._textureContext.imageSmoothingEnabled=!1,this._textureCanvas.style.imageRendering="pixelated",this._textureContext.fillStyle="black",this._textureContext.fillRect(0,0,e,t),this._textureContext.font=`${r}px ${i}`,this._textureContext.textBaseline="top",this._textureContext.textAlign="left",this._textureContext.fillStyle="white"}_renderCharactersToCanvas(e,t,r,i){for(let s=0;s<e.length;s++){const a=s%r,n=Math.floor(s/r),h=a*t.width+t.width*.5,c=n*t.height+t.height*.5,u=Math.round(h-t.width*.5),d=Math.round(c-i*.5);this._textureContext.fillText(e[s].character,u,d)}}_applyBlackWhiteThreshold(e=128){const t=this._textureContext.getImageData(0,0,this._textureCanvas.width,this._textureCanvas.height),r=t.data;for(let i=0;i<r.length;i+=4){const s=.299*r[i]+.587*r[i+1]+.114*r[i+2],a=e+32,n=s>a?255:0;r[i]=n,r[i+1]=n,r[i+2]=n}this._textureContext.putImageData(t,0,0)}}class de{constructor(){o(this,"_tempCanvas");o(this,"_tempContext");this._tempCanvas=document.createElement("canvas"),this._tempContext=this._tempCanvas.getContext("2d")}calculateMaxGlyphDimensions(e,t,r){this._tempContext.font=`${t}px ${r}`;let i=0,s=0;for(const a of e){const n=this._tempContext.measureText(a),h=n.width,c=n.actualBoundingBoxAscent+n.actualBoundingBoxDescent;h>0&&(i=Math.max(i,h),s=Math.max(s,c))}return{width:Math.ceil(i),height:Math.ceil(s)}}}class fe{createCharacterObjects(e,t){return e.map((r,i)=>{const s=r.codePointAt(0)||0,a=this._generateCharacterColor(i);let n=0;if(t.hmtx&&t.hmtx.aWidth){const h=this._getGlyphIndex(t,s);h>0&&t.hmtx.aWidth[h]!==void 0&&(n=t.hmtx.aWidth[h])}return{character:r,unicode:s,color:a,advanceWidth:n}})}_getGlyphIndex(e,t){const r=e.cmap;if(!r||!r.tables)return 0;for(const i of r.tables)if(i.format===4){for(let s=0;s<i.startCount.length;s++)if(t>=i.startCount[s]&&t<=i.endCount[s]){if(i.idRangeOffset[s]===0)return t+i.idDelta[s]&65535;{const a=i.idRangeOffset[s]/2+(t-i.startCount[s])-(i.startCount.length-s);if(a>=0&&a<i.glyphIdArray.length){const n=i.glyphIdArray[a];if(n!==0)return n+i.idDelta[s]&65535}}}}return 0}_generateCharacterColor(e){const t=e%256,r=Math.floor(e/256)%256,i=Math.floor(e/65536)%256;return[t,r,i]}getCharacterColor(e,t){if(!b.validate(typeof e=="string"&&e.length===1,"Character must be a single character string.",{method:"getCharacterColor",providedValue:e}))return[0,0,0];const r=t.find(i=>i.character===e);return r?r.color:[0,0,0]}getCharacterColors(e,t){return b.validate(typeof e=="string"&&e.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:e})?e.split("").map(r=>this.getCharacterColor(r,t)||[0,0,0]):[[0,0,0]]}}class q{constructor(e,t=16){o(this,"_font");o(this,"_characters",[]);o(this,"_fontFramebuffer");o(this,"_fontSize",16);o(this,"_textureColumns",0);o(this,"_textureRows",0);o(this,"_maxGlyphDimensions",{width:0,height:0});o(this,"_fontFace");o(this,"_fontFamilyName","UrsaFont");o(this,"_characterExtractor");o(this,"_textureAtlas");o(this,"_metricsCalculator");o(this,"_characterColorMapper");this._fontSize=t,this._characterExtractor=new ce,this._textureAtlas=new ue(e),this._metricsCalculator=new de,this._characterColorMapper=new fe}async initialize(e){let t;if(e){const r=await fetch(e);if(!r.ok)throw new _(`Failed to load font file: ${r.status} ${r.statusText}`);t=await r.arrayBuffer()}else throw new _("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");await this._loadFontFace(t),this._font=m.parse(t)[0],await this._initializeFont()}setFontSize(e){if(e===void 0)return this._fontSize;this._fontSize=e,this._maxGlyphDimensions=this._metricsCalculator.calculateMaxGlyphDimensions(this._characters.map(r=>r.character),this._fontSize,this._fontFamilyName);const t=this._textureAtlas.createTextureAtlas(this._characters,this._maxGlyphDimensions,this._fontSize,this._fontFamilyName);this._fontFramebuffer=t.framebuffer,this._textureColumns=t.columns,this._textureRows=t.rows}async loadFont(e){try{const t=await fetch(e);if(!t.ok)throw new _(`Failed to load font file: ${t.status} ${t.statusText}`);const r=await t.arrayBuffer();await this._loadFontFace(r);const i=m.parse(r);if(!i||i.length===0)throw new Error("Failed to parse font file");this._font=i[0],await this._initializeFont()}catch(t){throw new _(`Failed to load font: ${t instanceof Error?t.message:"Unknown error"}`,t)}}async _loadFontFace(e){const t=Date.now();this._fontFamilyName=this._fontFamilyName==="UrsaFont"?"UrsaFont":`CustomFont_${t}`,this._fontFace=new FontFace(this._fontFamilyName,e),await this._fontFace.load(),document.fonts.add(this._fontFace)}async _initializeFont(){const e=this._characterExtractor.extractCharacters(this._font),t=this._characterExtractor.filterProblematicCharacters(e);this._characters=this._characterColorMapper.createCharacterObjects(t,this._font),this._maxGlyphDimensions=this._metricsCalculator.calculateMaxGlyphDimensions(t,this._fontSize,this._fontFamilyName);const r=this._textureAtlas.createTextureAtlas(this._characters,this._maxGlyphDimensions,this._fontSize,this._fontFamilyName);this._fontFramebuffer=r.framebuffer,this._textureColumns=r.columns,this._textureRows=r.rows}getCharacterColor(e){return this._characterColorMapper.getCharacterColor(e,this._characters)}getCharacterColors(e){return this._characterColorMapper.getCharacterColors(e,this._characters)}hasAllCharacters(e){if(typeof e!="string"||e.length===0)return!1;const t=new Set(this._characters.map(r=>r.character));for(const r of e)if(!t.has(r))return!1;return!0}get fontFramebuffer(){return this._fontFramebuffer}get characters(){return this._characters}get textureColumns(){return this._textureColumns}get textureRows(){return this._textureRows}get maxGlyphDimensions(){return this._maxGlyphDimensions}dispose(){this._fontFramebuffer.dispose(),document.fonts.delete(this._fontFace),this._fontFramebuffer=null,this._fontFace=null,this._font=null,this._characters=[],this._maxGlyphDimensions={width:0,height:0},this._textureColumns=0,this._textureRows=0}get fontSize(){return this._fontSize}get font(){return this._font}}class Q{constructor(e,t,r){o(this,"_cols");o(this,"_rows");o(this,"_width");o(this,"_height");o(this,"_offsetX");o(this,"_offsetY");o(this,"_fixedDimensions",!1);o(this,"_canvas");o(this,"_cellWidth");o(this,"_cellHeight");this._canvas=e,this._cellWidth=t,this._cellHeight=r,this.reset()}reset(){if(!this._fixedDimensions){const e=this._canvas.getBoundingClientRect();let t=Math.round(e.width),r=Math.round(e.height);[this._cols,this._rows]=[Math.floor(t/this._cellWidth),Math.floor(r/this._cellHeight)]}this._resizeGrid()}_resizeGrid(){const e=this._canvas.getBoundingClientRect();let t=Math.round(e.width),r=Math.round(e.height);this._width=this._cols*this._cellWidth,this._height=this._rows*this._cellHeight,this._offsetX=Math.floor((t-this._width)/2),this._offsetY=Math.floor((r-this._height)/2)}resizeCellPixelDimensions(e,t){[this._cellWidth,this._cellHeight]=[e,t],this.reset()}resizeGridDimensions(e,t){this._fixedDimensions=!0,[this._cols,this._rows]=[e,t],this._resizeGrid()}resetGridDimensions(){this._fixedDimensions=!1,this.reset()}resize(){this._fixedDimensions?this._resizeGrid():this.reset()}fixedDimensions(e){if(e===void 0)return this._fixedDimensions;this._fixedDimensions=e}get cellWidth(){return this._cellWidth}get cellHeight(){return this._cellHeight}dispose(){this._canvas=null,this._cols=0,this._rows=0,this._width=0,this._height=0,this._offsetX=0,this._offsetY=0,this._cellWidth=0,this._cellHeight=0}get cols(){return this._cols}get rows(){return this._rows}get width(){return this._width}get height(){return this._height}get offsetX(){return this._offsetX}get offsetY(){return this._offsetY}}class Z{constructor(e,t=!1,r={}){o(this,"_canvas");o(this,"captureSource");o(this,"_isStandalone");this.captureSource=e,this._isStandalone=t,this._canvas=this.createCanvas(r.width,r.height)}createCanvas(e,t){var i;const r=document.createElement("canvas");if(r.className="textmodeCanvas",r.style.imageRendering="pixelated",this._isStandalone)r.width=e||800,r.height=t||600,document.body.appendChild(r);else{const s=this.captureSource.getBoundingClientRect();let a=Math.round(s.width),n=Math.round(s.height);if(this.captureSource instanceof HTMLVideoElement){const u=this.captureSource;(a===0||n===0)&&u.videoWidth>0&&u.videoHeight>0&&(a=u.videoWidth,n=u.videoHeight)}r.width=a,r.height=n,r.style.position="absolute",r.style.pointerEvents="none";const h=window.getComputedStyle(this.captureSource);let c=parseInt(h.zIndex||"0",10);isNaN(c)&&(c=0),r.style.zIndex=(c+1).toString(),this.positionOverlayCanvas(r),(i=this.captureSource.parentNode)==null||i.insertBefore(r,this.captureSource.nextSibling)}return r}positionOverlayCanvas(e){const t=this.captureSource.getBoundingClientRect();let r=this.captureSource.offsetParent;if(r&&r!==document.body){const i=r.getBoundingClientRect();e.style.top=t.top-i.top+"px",e.style.left=t.left-i.left+"px"}else e.style.top=t.top+window.scrollY+"px",e.style.left=t.left+window.scrollX+"px"}resize(e,t){if(this._isStandalone)this._canvas.width=e??this._canvas.width,this._canvas.height=t??this._canvas.height;else{const r=this.captureSource.getBoundingClientRect();let i=Math.round(r.width),s=Math.round(r.height);if(this.captureSource instanceof HTMLVideoElement){const a=this.captureSource;(i===0||s===0)&&a.videoWidth>0&&a.videoHeight>0&&(i=a.videoWidth,s=a.videoHeight)}this._canvas.width=i,this._canvas.height=s,this.positionOverlayCanvas(this._canvas)}}getWebGLContext(){const e={alpha:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"},t=this._canvas.getContext("webgl2",e)||this._canvas.getContext("webgl",e);if(!t)throw new _("WebGL context could not be created. Ensure your browser supports WebGL.");return t}dispose(){if(this._canvas){const e=this._canvas.getContext("webgl")||this._canvas.getContext("webgl2");if(e){const t=e.getExtension("WEBGL_lose_context");t&&t.loseContext()}this._canvas.parentNode&&this._canvas.parentNode.removeChild(this._canvas),this._canvas=null}this.captureSource=null}get canvas(){return this._canvas}get width(){return this._canvas.width}get height(){return this._canvas.height}}class M{constructor(e,t,r,i={}){o(this,"renderer");o(this,"fontManager");o(this,"grid");o(this,"_characterFramebuffer");o(this,"_primaryColorFramebuffer");o(this,"_secondaryColorFramebuffer");o(this,"_rotationFramebuffer");o(this,"_transformFramebuffer");o(this,"_options");this.renderer=e,this.fontManager=t,this.grid=r,this._options=i,this._characterFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._rotationFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._transformFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows)}resize(){this._characterFramebuffer.resize(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._rotationFramebuffer.resize(this.grid.cols,this.grid.rows),this._transformFramebuffer.resize(this.grid.cols,this.grid.rows)}enabled(e){this._options.enabled=e}enable(){this.enabled(!0)}disable(){this.enabled(!1)}dispose(){this._characterFramebuffer.dispose(),this._primaryColorFramebuffer.dispose(),this._secondaryColorFramebuffer.dispose(),this._rotationFramebuffer.dispose(),this._transformFramebuffer.dispose(),this._characterFramebuffer=null,this._primaryColorFramebuffer=null,this._secondaryColorFramebuffer=null,this._rotationFramebuffer=null,this._transformFramebuffer=null}get characterFramebuffer(){return this._characterFramebuffer}get primaryColorFramebuffer(){return this._primaryColorFramebuffer}get secondaryColorFramebuffer(){return this._secondaryColorFramebuffer}get rotationFramebuffer(){return this._rotationFramebuffer}get transformFramebuffer(){return this._transformFramebuffer}get options(){return this._options}}class me{constructor(e,t){o(this,"_framebuffer");o(this,"_renderer");o(this,"_colors");this._renderer=e,this._colors=t;const r=Math.max(this._colors.length,1);this._framebuffer=this._renderer.createFramebuffer(r,1),this._updateFramebuffer()}_updateFramebuffer(){if(!this._framebuffer)return;const e=Math.max(this._colors.length,1),t=1;this._framebuffer.width!==e&&this._framebuffer.resize(e,t);const r=new Uint8Array(e*t*4);for(let i=0;i<e;i++){const s=i<this._colors.length?this._colors[i]:[0,0,0],a=i*4;r[a]=s[0],r[a+1]=s[1],r[a+2]=s[2],r[a+3]=255}this._framebuffer.updatePixels(r,e,t)}setColors(e){this._colors=e,this._updateFramebuffer()}get colors(){return this._colors}get framebuffer(){return this._framebuffer}get texture(){return this._framebuffer.texture}}class k extends M{constructor(t,r,i,s={}){super(t,r,i,s);o(this,"palette");this.palette=new me(this.renderer,this.fontManager.getCharacterColors(" .:-=+*%@#"))}characters(t){b.validate(this.fontManager.hasAllCharacters(t),"One or more characters do not exist in the current font.",{method:"characters",providedValue:t})&&(this._options.characters=t,this.palette.setColors(this.fontManager.getCharacterColors(t)))}characterColor(t,r,i,s=255){let a,n,h,c;if(typeof t=="string"){const u=this.parseHexColor(t);if(!u){b.validate(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:"characterColor",providedValue:t});return}[a,n,h,c]=u}else if(a=t,n=r!==void 0?r:t,h=i!==void 0?i:t,c=s,!b.validate([a,n,h,c].every(u=>u>=0&&u<=255),"Character color values must be between 0 and 255",{method:"characterColor",providedValues:{r:a,g:n,b:h,a:c}}))return;this._options.characterColor=[a,n,h,c]}characterColorMode(t){b.validate(["sampled","fixed"].includes(t),"Invalid character color mode. Must be 'sampled' or 'fixed'.",{method:"characterColorMode",providedValue:t})&&(this._options.characterColorMode=t)}cellColor(t,r,i,s=255){let a,n,h,c;if(typeof t=="string"){const u=this.parseHexColor(t);if(!u){b.validate(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:"cellColor",providedValue:t});return}[a,n,h,c]=u}else if(a=t,n=r!==void 0?r:t,h=i!==void 0?i:t,c=s,!b.validate([a,n,h,c].every(u=>u>=0&&u<=255),"Cell color values must be between 0 and 255",{method:"cellColor",providedValues:{r:a,g:n,b:h,a:c}}))return;this._options.cellColor=[a,n,h,c]}cellColorMode(t){b.validate(["sampled","fixed"].includes(t),"Invalid cell color mode. Must be 'sampled' or 'fixed'.",{method:"cellColorMode",providedValue:t})&&(this._options.cellColorMode=t)}invert(t){b.validate(typeof t=="boolean"||typeof t=="number"&&Number.isInteger(t),"Invert must be a boolean value or an integer (0 for false, any other number for true).",{method:"invert",providedValue:t})&&(this._options.invert=!!t)}rotation(t){if(!b.validate(typeof t=="number","Rotation angle must be a number.",{method:"rotation",providedValue:t}))return;t=t%360,t<0&&(t+=360);const r=t*255/360,i=Math.floor(r)/255,s=Math.round(r-i);this._options.rotation=[i,s,0,1]}flipHorizontally(t){b.validate(typeof t=="boolean"||typeof t=="number"&&Number.isInteger(t),"Flip horizontally must be a boolean value or an integer (0 for false, any other number for true).",{method:"flipHorizontally",providedValue:t})&&(this._options.flipHorizontally=!!t)}flipVertically(t){b.validate(typeof t=="boolean"||typeof t=="number"&&Number.isInteger(t),"Flip vertically must be a boolean value or an integer (0 for false, any other number for true).",{method:"flipVertically",providedValue:t})&&(this._options.flipVertically=!!t)}parseHexColor(t){if(t=t.replace(/^#/,""),!/^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(t))return null;t.length===3&&(t=t.split("").map(a=>a+a).join(""));const r=parseInt(t.slice(0,2),16),i=parseInt(t.slice(2,4),16),s=parseInt(t.slice(4,6),16);return[r,i,s,255]}}var ge="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);}}",pe="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);}}",_e="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);}}",xe="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);}}",ve="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);}";const be={enabled:!0,characters:" .:-=+*%@#",characterColor:[255,255,255,255],characterColorMode:"sampled",cellColor:[0,0,0,255],cellColorMode:"fixed",invert:!1,rotation:[0,0,0,255],flipHorizontally:!1,flipVertically:!1,brightnessRange:[0,255]};class z extends k{constructor(t,r,i){super(t,r,i,{...be});o(this,"sampleShader");o(this,"colorFillShader");o(this,"charMappingShader");o(this,"transformFillShader");o(this,"rotationFillShader");o(this,"sampleFramebuffer");this.sampleShader=new T(t.context,S,ge),this.colorFillShader=new T(t.context,S,pe),this.transformFillShader=new T(t.context,S,_e),this.rotationFillShader=new T(t.context,S,xe),this.charMappingShader=new T(t.context,S,ve),this.sampleFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows)}convert(t){this.sampleFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.sampleShader),this.renderer.setUniform("u_sketchTexture",t),this.renderer.setUniform("u_gridCellDimensions",[this.grid.cols,this.grid.rows]),this.renderer.setUniform("u_brightnessRange",this._options.brightnessRange),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this.sampleFramebuffer.end(),this._primaryColorFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.colorFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_fillColor",this._options.characterColor),this.renderer.setUniform("u_useFixedColor",this._options.characterColorMode==="fixed"),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.end(),this._secondaryColorFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.colorFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_fillColor",this._options.cellColor),this.renderer.setUniform("u_useFixedColor",this._options.cellColorMode==="fixed"),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.end(),this._transformFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.transformFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_invert",this._options.invert),this.renderer.setUniform("u_flipHorizontally",this._options.flipHorizontally),this.renderer.setUniform("u_flipVertically",this._options.flipVertically),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._transformFramebuffer.end(),this._rotationFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.rotationFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_rotationColor",this._options.rotation),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._rotationFramebuffer.end(),this._characterFramebuffer.begin(),this.renderer.clear(0,0,0,0),this.renderer.shader(this.charMappingShader),this.renderer.setUniform("u_colorSampleFramebuffer",this.sampleFramebuffer.texture),this.renderer.setUniform("u_charPaletteTexture",this.palette.texture),this.renderer.setUniform("u_charPaletteSize",[this.palette.colors.length,1]),this.renderer.setUniform("u_brightnessRange",this._options.brightnessRange),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._characterFramebuffer.end()}resize(){super.resize(),this.sampleFramebuffer.resize(this.grid.cols,this.grid.rows)}brightnessRange(t){b.validate(Array.isArray(t)&&t.length===2&&t.every(r=>typeof r=="number"&&r>=0&&r<=255),"Brightness range must be an array of two numbers between 0 and 255.",{method:"brightnessRange",providedValue:t})&&(this._options.brightnessRange=t)}}const Ce=Object.freeze(Object.defineProperty({__proto__:null,TextmodeBrightnessConverter:z,TextmodeConverter:M,TextmodeFeatureConverter:k},Symbol.toStringTag,{value:"Module"}));var Fe="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);vec2 charCoord=vec2(charCol,charRow)/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);}";class J{constructor(e,t,r){o(this,"renderer");o(this,"font");o(this,"grid");o(this,"converters");o(this,"_resultFramebuffer");o(this,"_asciiShader");o(this,"_characterFramebuffer");o(this,"_primaryColorFramebuffer");o(this,"_secondaryColorFramebuffer");o(this,"_rotationFramebuffer");o(this,"_transformFramebuffer");this.renderer=e,this.font=t,this.grid=r,this._asciiShader=this.renderer.createShader(S,Fe),this.converters=[{name:"brightness",converter:new z(e,t,r)},{name:"custom",converter:new M(e,t,r)}],this._characterFramebuffer=this.renderer.createFramebuffer(r.cols,r.rows),this._primaryColorFramebuffer=this.renderer.createFramebuffer(r.cols,r.rows),this._secondaryColorFramebuffer=this.renderer.createFramebuffer(r.cols,r.rows),this._rotationFramebuffer=this.renderer.createFramebuffer(r.cols,r.rows),this._transformFramebuffer=this.renderer.createFramebuffer(r.cols,r.rows),this._resultFramebuffer=this.renderer.createFramebuffer(this.grid.width,this.grid.height)}render(e){for(const r of this.converters){const i=r.converter;i.options.enabled&&i instanceof k&&i.convert(e)}const t=(r,i)=>{r.begin(),this.renderer.clear();for(const s of this.converters){const a=s.converter;a.options.enabled&&this.renderer.image(i(a),0,0)}r.end()};t(this._characterFramebuffer,r=>r.characterFramebuffer),t(this._primaryColorFramebuffer,r=>r.primaryColorFramebuffer),t(this._secondaryColorFramebuffer,r=>r.secondaryColorFramebuffer),t(this._rotationFramebuffer,r=>r.rotationFramebuffer),t(this._transformFramebuffer,r=>r.transformFramebuffer),this._resultFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this._asciiShader),this.renderer.setUniform("u_characterTexture",this.font.fontFramebuffer),this.renderer.setUniform("u_charsetDimensions",[this.font.textureColumns,this.font.textureRows]),this.renderer.setUniform("u_asciiCharacterTexture",this._characterFramebuffer.texture),this.renderer.setUniform("u_primaryColorTexture",this._primaryColorFramebuffer.texture),this.renderer.setUniform("u_secondaryColorTexture",this._secondaryColorFramebuffer.texture),this.renderer.setUniform("u_transformTexture",this._transformFramebuffer.texture),this.renderer.setUniform("u_rotationTexture",this._rotationFramebuffer.texture),this.renderer.setUniform("u_captureTexture",e.texture),this.renderer.setUniform("u_backgroundMode",!1),this.renderer.setUniform("u_captureDimensions",[e.width,e.height]),this.renderer.setUniform("u_gridCellDimensions",[this.grid.cols,this.grid.rows]),this.renderer.setUniform("u_gridPixelDimensions",[this.grid.width,this.grid.height]),this.renderer.rect(0,0,this._resultFramebuffer.width,this._resultFramebuffer.height),this._resultFramebuffer.end()}get(e){if(!b.validate(typeof e=="string"&&e.length>0,"Converter name must be a non-empty string.",{method:"converter",providedValue:e}))return;const t=this.converters.find(i=>i.name===e),r=t==null?void 0:t.converter;if(b.validate(r instanceof M,`Converter "${e}" is not a valid TextmodeConverter.`,{method:"converter",providedValue:e,converterInstance:r}))return r}add(e,t){if(!b.validate(typeof e=="string"&&e.length>0,"Converter name must be a non-empty string.",{method:"add",providedValue:e})||!b.validate(t==="brightness"||t==="custom",`Converter type must be either "brightness" or "custom". Provided: ${t}`,{method:"add",providedValue:t}))return;let r;return t==="brightness"?r=new z(this.renderer,this.font,this.grid):r=new M(this.renderer,this.font,this.grid),this.converters.push({name:e,converter:r}),r}remove(e){if(!b.validate(typeof e=="string"||e instanceof M,"Parameter must be either a string (converter name) or a TextmodeConverter instance.",{method:"remove",providedValue:e}))return;let t=-1;if(typeof e=="string"){if(!b.validate(e.length>0,"Converter name must be a non-empty string.",{method:"remove",providedValue:e}))return;t=this.converters.findIndex(r=>r.name===e)}else t=this.converters.findIndex(r=>r.converter===e);b.validate(t!==-1,typeof e=="string"?`Converter with name "${e}" not found in pipeline.`:"Converter instance not found in pipeline.",{method:"remove",providedValue:e,convertersCount:this.converters.length})&&this.converters.splice(t,1)}get texture(){return this._resultFramebuffer}resize(){this._resultFramebuffer.resize(this.grid.width,this.grid.height),this._characterFramebuffer.resize(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._rotationFramebuffer.resize(this.grid.cols,this.grid.rows),this._transformFramebuffer.resize(this.grid.cols,this.grid.rows);for(const e of this.converters)e.converter.resize()}hasEnabledConverters(){return this.converters.some(e=>e.converter.options.enabled)}disable(){for(const e of this.converters)e.converter.disable()}enable(){for(const e of this.converters)e.converter.enable()}dispose(){for(const e of this.converters)e.converter.dispose();this._characterFramebuffer.dispose(),this._primaryColorFramebuffer.dispose(),this._secondaryColorFramebuffer.dispose(),this._rotationFramebuffer.dispose(),this._transformFramebuffer.dispose(),this._resultFramebuffer.dispose(),this._asciiShader.dispose(),this.converters=[],this._characterFramebuffer=null,this._primaryColorFramebuffer=null,this._secondaryColorFramebuffer=null,this._rotationFramebuffer=null,this._transformFramebuffer=null,this._resultFramebuffer=null,this._asciiShader=null}get characterFramebuffer(){return this._characterFramebuffer}get primaryColorFramebuffer(){return this._primaryColorFramebuffer}get secondaryColorFramebuffer(){return this._secondaryColorFramebuffer}get rotationFramebuffer(){return this._rotationFramebuffer}get transformFramebuffer(){return this._transformFramebuffer}}class ${extractFramebufferData(e){const t=e.get("brightness"),r=t==null?void 0:t.characterFramebuffer,i=t==null?void 0:t.primaryColorFramebuffer,s=t==null?void 0:t.secondaryColorFramebuffer,a=t==null?void 0:t.transformFramebuffer,n=t==null?void 0:t.rotationFramebuffer;return r==null||r.loadPixels(),i==null||i.loadPixels(),s==null||s.loadPixels(),a==null||a.loadPixels(),n==null||n.loadPixels(),{characterPixels:(r==null?void 0:r.pixels)||new Uint8Array(0),primaryColorPixels:(i==null?void 0:i.pixels)||new Uint8Array(0),secondaryColorPixels:(s==null?void 0:s.pixels)||new Uint8Array(0),transformPixels:(a==null?void 0:a.pixels)||new Uint8Array(0),rotationPixels:(n==null?void 0:n.pixels)||new Uint8Array(0)}}getCharacterIndex(e,t){const r=e[t],i=e[t+1];return r+(i<<8)}pixelsToRGBA(e,t){return{r:e[t],g:e[t+1],b:e[t+2],a:e[t+3]}}}class L{createBlob(e,t){return new Blob([e],{type:t})}downloadFile(e,t,r){try{const i=this.createBlob(e,r),s=URL.createObjectURL(i),a=document.createElement("a");a.href=s,a.download=t,a.style.display="none",a.rel="noopener",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(s)}catch(i){throw console.error("Failed to download file:",i),new Error(`File download failed: ${i instanceof Error?i.message:"Unknown error"}`)}}generateTimestamp(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}generateDateTimeString(){const e=new Date,t=e.toISOString().split("T")[0],r=e.toTimeString().split(" ")[0].replace(/:/g,"-");return{date:t,time:r}}sanitizeFilename(e){return e.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}generateDefaultFilename(){return`'textmode-export'-${this.generateTimestamp()}`}}class we extends ${extractTransformData(e,t,r){const i=e[r],s=e[r+1],a=e[r+2],n=i===255,h=s===255,c=a===255,u=t[r],d=t[r+1],f=u+d/255,g=Math.round(f*360/255*100)/100;return{isInverted:n,flipHorizontal:h,flipVertical:c,rotation:g}}calculateCellPosition(e,t,r){return{x:e,y:t,cellX:e*r.cellWidth,cellY:t*r.cellHeight}}extractSVGCellData(e,t){const r=[];let i=0;for(let s=0;s<t.rows;s++)for(let a=0;a<t.cols;a++){const n=i*4,h=this.getCharacterIndex(e.characterPixels,n);let c=this.pixelsToRGBA(e.primaryColorPixels,n),u=this.pixelsToRGBA(e.secondaryColorPixels,n);const d=this.extractTransformData(e.transformPixels,e.rotationPixels,n);if(d.isInverted){const g=c;c=u,u=g}const f=this.calculateCellPosition(a,s,t);r.push({charIndex:h,primaryColor:c,secondaryColor:u,transform:d,position:f}),i++}return r}}class ye{getGlyphIndex(e,t){const r=e.cmap;if(!r||!r.tables)return 0;for(const i of r.tables)if(i.format===4){for(let s=0;s<i.startCount.length;s++)if(t>=i.startCount[s]&&t<=i.endCount[s]){if(i.idRangeOffset[s]===0)return t+i.idDelta[s]&65535;{const a=i.idRangeOffset[s]/2+(t-i.startCount[s])-(i.startCount.length-s);if(a>=0&&a<i.glyphIdArray.length){const n=i.glyphIdArray[a];if(n!==0)return n+i.idDelta[s]&65535}}}}return 0}createEmptyPath(){return{getBoundingBox:()=>({x1:0,y1:0,x2:0,y2:0}),toSVG:()=>""}}createGlyphPath(e,t,r,i,s){if(!t||!t.xs||t.xs.length===0)return this.createEmptyPath();const a=s/e.head.unitsPerEm;return{getBoundingBox:()=>({x1:r+t.xMin*a,y1:i+-t.yMax*a,x2:r+t.xMax*a,y2:i+-t.yMin*a}),toSVG:()=>this.glyphToSVGPath(t,r,i,a)}}glyphToSVGPath(e,t,r,i){if(!e||!e.xs)return"";const{xs:s,ys:a,endPts:n,flags:h}=e;if(!s||!a||!n||!h)return"";let c="",u=0;for(let d=0;d<n.length;d++){const f=n[d];if(!(f<u)){if(f>=u){const g=t+s[u]*i,x=r-a[u]*i;c+=`M${g.toFixed(2)},${x.toFixed(2)}`;let p=u+1;for(;p<=f;)if((h[p]&1)!==0){const w=t+s[p]*i,C=r-a[p]*i;c+=`L${w.toFixed(2)},${C.toFixed(2)}`,p++}else{const w=t+s[p]*i,C=r-a[p]*i;let y=p+1>f?u:p+1;if((h[y]&1)!==0){const A=t+s[y]*i,R=r-a[y]*i;c+=`Q${w.toFixed(2)},${C.toFixed(2)} ${A.toFixed(2)},${R.toFixed(2)}`,p=y+1}else{const A=t+s[y]*i,R=r-a[y]*i,X=(w+A)/2,G=(C+R)/2;c+=`Q${w.toFixed(2)},${C.toFixed(2)} ${X.toFixed(2)},${G.toFixed(2)}`,p=y}}c+="Z"}u=f+1}}return c}generateCharacterPath(e,t,r,i,s){try{const a=e.codePointAt(0)||0,n=this.getGlyphIndex(t,a);if(n===0)return this.createEmptyPath();let h=null;try{t.glyf&&t.glyf[n]!==null?h=t.glyf[n]:m&&m.T&&m.T.glyf&&m.T.glyf._parseGlyf&&(h=m.T.glyf._parseGlyf(t,n),t.glyf&&h&&(t.glyf[n]=h))}catch(c){console.warn(`Failed to parse glyph ${n}:`,c)}return h?this.createGlyphPath(t,h,r,i,s):this.createEmptyPath()}catch(a){return console.warn(`Failed to generate path for character "${e}":`,a),this.createEmptyPath()}}generatePositionedCharacterPath(e,t,r,i,s,a,n,h){try{const c=n/t.head.unitsPerEm,u=h*c,d=r+(s-u)/2,f=i+(a+n*.7)/2;return this.generateCharacterPath(e,t,d,f,n).toSVG()||null}catch(c){return console.warn(`Failed to generate positioned character path for "${e}":`,c),null}}}class Te{constructor(){o(this,"pathGenerator");this.pathGenerator=new ye}generateSVGHeader(e){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
7
|
+
`,i}static formatValue(t){if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string")return`"${t}"`;if(typeof t=="number"||typeof t=="boolean")return String(t);if(Array.isArray(t))return t.length===0?"[]":t.length<=5?`[${t.map(r=>_.formatValue(r)).join(", ")}]`:`[${t.slice(0,3).map(r=>_.formatValue(r)).join(", ")}, ... +${t.length-3} more]`;if(typeof t=="object"){const r=Object.keys(t);return r.length===0?"{}":r.length<=3?`{ ${r.map(a=>`${a}: ${_.formatValue(t[a])}`).join(", ")} }`:`{ ${r.slice(0,2).map(s=>`${s}: ${_.formatValue(t[s])}`).join(", ")}, ... +${r.length-2} more }`}return String(t)}}var E=(l=>(l[l.SILENT=0]="SILENT",l[l.WARNING=1]="WARNING",l[l.ERROR=2]="ERROR",l[l.THROW=3]="THROW",l))(E||{});const U=class U{constructor(){o(this,"_options",{globalLevel:3})}static getInstance(){return U._instance||(U._instance=new U),U._instance}_handle(e,t,r){const i="[textmode.js]";switch(this._options.globalLevel){case 0:return!1;case 1:return console.group(`%c${i} Oops! (╯°□°)╯︵ Something went wrong in your code.`,"color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;"),console.warn(_.createFormattedMessage(e,t)),console.groupEnd(),!1;case 2:return console.group(`%c${i} Oops! (╯°□°)╯︵ Something went wrong in your code.`,"color: #f44336; font-weight: bold; background: #ffebee; padding: 2px 6px; border-radius: 3px;"),console.error(_.createFormattedMessage(e,t)),console.groupEnd(),!1;case 3:default:const s=new _(e,r,t);throw console.group(`%c${i} Oops! (╯°□°)╯︵ Something went wrong in your code.`,"color: #d32f2f; font-weight: bold; background: #ffcdd2; padding: 2px 6px; border-radius: 3px;"),s}}validate(e,t,r){return e?!0:(this._handle(t,r),!1)}setGlobalLevel(e){this._options.globalLevel=e}};o(U,"_instance",null);let V=U;const b=V.getInstance();class ie{constructor(e,t,r=t,i={}){o(this,"gl");o(this,"_framebuffer");o(this,"_texture");o(this,"_width");o(this,"_height");o(this,"options");o(this,"previousState",null);o(this,"_pixels",null);this.gl=e,this._width=t,this._height=r,this.options={filter:"nearest",wrap:"clamp",format:"rgba",type:"unsigned_byte",...i},this._texture=this.createTexture(),this._framebuffer=e.createFramebuffer(),this.attachTexture()}createTexture(){const{gl:e}=this,t=e.createTexture();e.bindTexture(e.TEXTURE_2D,t);const r=this.options.filter==="linear"?e.LINEAR:e.NEAREST,i=this.options.wrap==="repeat"?e.REPEAT:e.CLAMP_TO_EDGE;return e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,i),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,i),this.updateTextureSize(),t}updateTextureSize(){const{gl:e}=this,t=e.RGBA,r=e.RGBA,i=this.options.type==="float"?e.FLOAT:e.UNSIGNED_BYTE;e.texImage2D(e.TEXTURE_2D,0,t,this._width,this._height,0,r,i,null)}attachTexture(){const{gl:e}=this;e.bindFramebuffer(e.FRAMEBUFFER,this._framebuffer),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,this._texture,0),e.bindFramebuffer(e.FRAMEBUFFER,null)}update(e){const{gl:t}=this;e instanceof HTMLVideoElement&&e.readyState<2||(t.bindTexture(t.TEXTURE_2D,this._texture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),t.bindTexture(t.TEXTURE_2D,null))}updatePixels(e,t,r){const{gl:i}=this;i.bindTexture(i.TEXTURE_2D,this._texture),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t,r,0,i.RGBA,i.UNSIGNED_BYTE,e),i.bindTexture(i.TEXTURE_2D,null)}resize(e,t){const{gl:r}=this;this._width=e,this._height=t,r.bindTexture(r.TEXTURE_2D,this._texture),this.updateTextureSize(),r.bindTexture(r.TEXTURE_2D,null)}begin(){const{gl:e}=this;this.previousState={framebuffer:e.getParameter(e.FRAMEBUFFER_BINDING),viewport:e.getParameter(e.VIEWPORT)},e.bindFramebuffer(e.FRAMEBUFFER,this._framebuffer),e.viewport(0,0,this._width,this._height)}end(){if(!this.previousState)return;const{gl:e}=this;e.bindFramebuffer(e.FRAMEBUFFER,this.previousState.framebuffer),e.viewport(...this.previousState.viewport),this.previousState=null}loadPixels(){const{gl:e}=this;this._pixels||(this._pixels=new Uint8Array(this._width*this._height*4));const t=e.getParameter(e.FRAMEBUFFER_BINDING);e.bindFramebuffer(e.FRAMEBUFFER,this._framebuffer),e.readPixels(0,0,this._width,this._height,e.RGBA,e.UNSIGNED_BYTE,this._pixels),e.bindFramebuffer(e.FRAMEBUFFER,t)}get(e,t,r,i){const{gl:s}=this;if(e===void 0&&t===void 0){const a=new Uint8Array(this._width*this._height*4),n=s.getParameter(s.FRAMEBUFFER_BINDING);return s.bindFramebuffer(s.FRAMEBUFFER,this._framebuffer),s.readPixels(0,0,this._width,this._height,s.RGBA,s.UNSIGNED_BYTE,a),s.bindFramebuffer(s.FRAMEBUFFER,n),a}else if(r===void 0&&i===void 0){(e<0||t<0||e>=this._width||t>=this._height)&&(console.warn("The x and y values passed to Framebuffer.get are outside of its range and will be clamped."),e=Math.max(0,Math.min(e,this._width-1)),t=Math.max(0,Math.min(t,this._height-1)));const a=new Uint8Array(4),n=s.getParameter(s.FRAMEBUFFER_BINDING);return s.bindFramebuffer(s.FRAMEBUFFER,this._framebuffer),s.readPixels(e,t,1,1,s.RGBA,s.UNSIGNED_BYTE,a),s.bindFramebuffer(s.FRAMEBUFFER,n),[a[0],a[1],a[2],a[3]]}else{e=Math.max(0,Math.min(e,this._width-1)),t=Math.max(0,Math.min(t,this._height-1)),r=Math.max(1,Math.min(r,this._width-e)),i=Math.max(1,Math.min(i,this._height-t));const a=new Uint8Array(r*i*4),n=s.getParameter(s.FRAMEBUFFER_BINDING);return s.bindFramebuffer(s.FRAMEBUFFER,this._framebuffer),s.readPixels(e,t,r,i,s.RGBA,s.UNSIGNED_BYTE,a),s.bindFramebuffer(s.FRAMEBUFFER,n),a}}dispose(){const{gl:e}=this;this._framebuffer&&(e.deleteFramebuffer(this._framebuffer),this._framebuffer=null),this._texture&&(e.deleteTexture(this._texture),this._texture=null),this._pixels=null}get framebuffer(){return this._framebuffer}get texture(){return this._texture}get width(){return this._width}get height(){return this._height}get pixels(){return this._pixels}}class j{constructor(e,t,r){o(this,"gl");o(this,"x");o(this,"y");this.gl=e,this.x=t,this.y=r}}class D{constructor(e,t,r,i,s){o(this,"gl");o(this,"vertexBuffer");o(this,"vertexCount",6);o(this,"bytesPerVertex");this.gl=e,this.bytesPerVertex=16;const a=e.getParameter(e.VIEWPORT),n=a[2],h=a[3],c=e.getParameter(e.FRAMEBUFFER_BINDING)!==null,u=t/n*2-1,d=(t+i)/n*2-1;let f,g;c?(f=r/h*2-1,g=(r+s)/h*2-1):(f=1-r/h*2,g=1-(r+s)/h*2);let x,p,F,w;x=u,F=d,p=f,w=g;const C=this.generateVertices(x,p,F,w);this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,C,e.STATIC_DRAW)}generateVertices(e,t,r,i){return new Float32Array([e,i,0,1,r,i,1,1,e,t,0,0,e,t,0,0,r,i,1,1,r,t,1,0])}render(){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);const e=this.gl.getParameter(this.gl.CURRENT_PROGRAM);let t=this.gl.getAttribLocation(e,"a_position"),r=this.gl.getAttribLocation(e,"a_texCoord");this.gl.enableVertexAttribArray(t),this.gl.vertexAttribPointer(t,2,this.gl.FLOAT,!1,this.bytesPerVertex,0),this.gl.enableVertexAttribArray(r),this.gl.vertexAttribPointer(r,2,this.gl.FLOAT,!1,this.bytesPerVertex,8),this.gl.drawArrays(this.gl.TRIANGLES,0,this.vertexCount),this.gl.disableVertexAttribArray(t),this.gl.disableVertexAttribArray(r)}}class se extends j{constructor(t,r,i,s,a){super(t,r,i);o(this,"width");o(this,"height");this.width=s,this.height=a}renderFill(){new D(this.gl,this.x,this.y,this.width,this.height).render()}renderStroke(t){if(t<=0)return;const r=new D(this.gl,this.x,this.y,this.width,t),i=new D(this.gl,this.x+this.width-t,this.y,t,this.height),s=new D(this.gl,this.x,this.y+this.height-t,this.width,t),a=new D(this.gl,this.x,this.y,t,this.height);r.render(),i.render(),s.render(),a.render()}}class ae{constructor(e,t,r,i,s,a){o(this,"gl");o(this,"vertexBuffer");o(this,"vertexCount",6);o(this,"bytesPerVertex");this.gl=e,this.bytesPerVertex=16;const n=e.getParameter(e.VIEWPORT),h=n[2],c=n[3],u=e.getParameter(e.FRAMEBUFFER_BINDING)!==null,d=i-t,f=s-r,g=Math.sqrt(d*d+f*f);if(g===0){const Oe=this.generateVertices(0,0,0,0);this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,Oe,e.STATIC_DRAW);return}const x=d/g,F=-(f/g),w=x,C=a/2,y=t+F*C,B=r+w*C,A=t-F*C,R=r-w*C,X=i+F*C,G=s+w*C,ke=i-F*C,re=s-w*C,ze=y/h*2-1,$e=A/h*2-1,Le=X/h*2-1,He=ke/h*2-1;let O,N,W,Y;u?(O=B/c*2-1,N=R/c*2-1,W=G/c*2-1,Y=re/c*2-1):(O=1-B/c*2,N=1-R/c*2,W=1-G/c*2,Y=1-re/c*2);const Xe=this.generateLineVertices(ze,O,$e,N,Le,W,He,Y);this.vertexBuffer=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,Xe,e.STATIC_DRAW)}generateVertices(e,t,r,i){return new Float32Array([e,i,0,1,r,i,1,1,e,t,0,0,e,t,0,0,r,i,1,1,r,t,1,0])}generateLineVertices(e,t,r,i,s,a,n,h){return new Float32Array([e,t,0,0,r,i,0,1,s,a,1,0,r,i,0,1,n,h,1,1,s,a,1,0])}render(){this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer);const e=this.gl.getParameter(this.gl.CURRENT_PROGRAM);let t=this.gl.getAttribLocation(e,"a_position"),r=this.gl.getAttribLocation(e,"a_texCoord");this.gl.enableVertexAttribArray(t),this.gl.vertexAttribPointer(t,2,this.gl.FLOAT,!1,this.bytesPerVertex,0),this.gl.enableVertexAttribArray(r),this.gl.vertexAttribPointer(r,2,this.gl.FLOAT,!1,this.bytesPerVertex,8),this.gl.drawArrays(this.gl.TRIANGLES,0,this.vertexCount),this.gl.disableVertexAttribArray(t),this.gl.disableVertexAttribArray(r)}}class ne extends j{constructor(t,r,i,s,a){super(t,r,i);o(this,"x2");o(this,"y2");this.x2=s,this.y2=a}renderFill(){}renderStroke(t){if(t<=0)return;new ae(this.gl,this.x,this.y,this.x2,this.y2,t).render()}}class T{constructor(e,t,r){o(this,"gl");o(this,"program");o(this,"uniformLocations",new Map);o(this,"attributeLocations",new Map);o(this,"textureUnitCounter",0);this.gl=e,this.program=this.createProgram(t,r),this.cacheLocations()}createProgram(e,t){const r=this.createShader(this.gl.VERTEX_SHADER,e),i=this.createShader(this.gl.FRAGMENT_SHADER,t),s=this.gl.createProgram();if(this.gl.attachShader(s,r),this.gl.attachShader(s,i),this.gl.linkProgram(s),!this.gl.getProgramParameter(s,this.gl.LINK_STATUS)){const a=this.gl.getProgramInfoLog(s);throw new Error(`Shader program link error: ${a}`)}return this.gl.deleteShader(r),this.gl.deleteShader(i),s}createShader(e,t){const r=this.gl.createShader(e);if(this.gl.shaderSource(r,t),this.gl.compileShader(r),!this.gl.getShaderParameter(r,this.gl.COMPILE_STATUS)){const i=this.gl.getShaderInfoLog(r);throw this.gl.deleteShader(r),new Error(`Shader compilation error: ${i}`)}return r}cacheLocations(){const e=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_UNIFORMS);for(let r=0;r<e;r++){const i=this.gl.getActiveUniform(this.program,r);if(i){const s=this.gl.getUniformLocation(this.program,i.name);s&&this.uniformLocations.set(i.name,s)}}const t=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_ATTRIBUTES);for(let r=0;r<t;r++){const i=this.gl.getActiveAttrib(this.program,r);if(i){const s=this.gl.getAttribLocation(this.program,i.name);this.attributeLocations.set(i.name,s)}}}use(){this.gl.useProgram(this.program),this.resetTextureUnits()}setUniform(e,t){const r=this.uniformLocations.get(e);if(!r)return;const i=this.getUniformInfo(e);if(typeof t=="number")i&&i.type===this.gl.INT?this.gl.uniform1i(r,Math.floor(t)):this.gl.uniform1f(r,t);else if(typeof t=="boolean")this.gl.uniform1i(r,t?1:0);else if(Array.isArray(t))if(i&&(i.type===this.gl.INT_VEC2||i.type===this.gl.INT_VEC3||i.type===this.gl.INT_VEC4)){const s=t.map(a=>Math.floor(a));switch(s.length){case 2:this.gl.uniform2iv(r,s);break;case 3:this.gl.uniform3iv(r,s);break;case 4:this.gl.uniform4iv(r,s);break;default:console.warn(`Unsupported array length ${s.length} for uniform '${e}'`)}}else switch(t.length){case 2:this.gl.uniform2f(r,t[0],t[1]);break;case 3:this.gl.uniform3f(r,t[0],t[1],t[2]);break;case 4:this.gl.uniform4f(r,t[0],t[1],t[2],t[3]);break;default:console.warn(`Unsupported array length ${t.length} for uniform '${e}'`)}else if(t instanceof WebGLTexture){const s=this.getNextTextureUnit();this.gl.uniform1i(r,s),this.gl.activeTexture(this.gl.TEXTURE0+s),this.gl.bindTexture(this.gl.TEXTURE_2D,t)}else if(t&&typeof t=="object"&&"texture"in t){const s=this.getNextTextureUnit();this.gl.uniform1i(r,s),this.gl.activeTexture(this.gl.TEXTURE0+s),this.gl.bindTexture(this.gl.TEXTURE_2D,t.texture)}else console.warn(`Unsupported uniform type for '${e}':`,typeof t)}getUniformInfo(e){const t=this.gl.getProgramParameter(this.program,this.gl.ACTIVE_UNIFORMS);for(let r=0;r<t;r++){const i=this.gl.getActiveUniform(this.program,r);if(i&&i.name===e)return i}return null}getNextTextureUnit(){return this.textureUnitCounter++}hasUniform(e){return this.uniformLocations.has(e)}hasAttribute(e){return this.attributeLocations.has(e)}get glProgram(){return this.program}dispose(){this.program&&(this.gl.deleteProgram(this.program),this.program=null),this.uniformLocations.clear(),this.attributeLocations.clear(),this.textureUnitCounter=0}resetTextureUnits(){this.textureUnitCounter=0}}var S="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);}",oe="precision lowp float;uniform sampler2D u_texture;varying vec2 v_uv;void main(){gl_FragColor=texture2D(u_texture,v_uv);}",le="precision lowp float;uniform vec4 u_color;void main(){gl_FragColor=u_color;}";class he{constructor(e){o(this,"gl");o(this,"imageShader");o(this,"solidColorShader");o(this,"currentShader",null);o(this,"currentFillColor",[1,1,1,1]);o(this,"fillMode",!0);o(this,"currentStrokeColor",[0,0,0,1]);o(this,"currentStrokeWeight",1);o(this,"strokeMode",!0);o(this,"currentRotation",0);o(this,"stateStack",[]);this.gl=e,this.imageShader=new T(this.gl,S,oe),this.solidColorShader=new T(this.gl,S,le),this.gl.enable(this.gl.BLEND),this.gl.blendEquation(this.gl.FUNC_ADD),this.gl.blendFunc(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)}shader(e){this.currentShader=e,e.use()}fill(e,t,r,i){if(this.fillMode=!0,t===void 0&&r===void 0&&i===void 0){const s=e/255;this.currentFillColor=[s,s,s,1]}else if(r!==void 0&&i===void 0)this.currentFillColor=[e/255,t/255,r/255,1];else if(r!==void 0&&i!==void 0)this.currentFillColor=[e/255,t/255,r/255,i/255];else throw new Error("Invalid fill parameters. Use fill(gray), fill(r,g,b), or fill(r,g,b,a)")}stroke(e,t,r,i){if(this.strokeMode=!0,t===void 0&&r===void 0&&i===void 0){const s=e/255;this.currentStrokeColor=[s,s,s,1]}else if(r!==void 0&&i===void 0)this.currentStrokeColor=[e/255,t/255,r/255,1];else if(r!==void 0&&i!==void 0)this.currentStrokeColor=[e/255,t/255,r/255,i/255];else throw new Error("Invalid stroke parameters. Use stroke(gray), stroke(r,g,b), or stroke(r,g,b,a)")}strokeWeight(e){if(e<0)throw new Error("Stroke weight must be non-negative");this.currentStrokeWeight=e}noStroke(){this.strokeMode=!1}noFill(){this.fillMode=!1}rotate(e){this.currentRotation=e}push(){this.stateStack.push({fillColor:[...this.currentFillColor],fillMode:this.fillMode,strokeColor:[...this.currentStrokeColor],strokeWeight:this.currentStrokeWeight,strokeMode:this.strokeMode,rotation:this.currentRotation})}pop(){const e=this.stateStack.pop();e?(this.currentFillColor=e.fillColor,this.fillMode=e.fillMode,this.currentStrokeColor=e.strokeColor,this.currentStrokeWeight=e.strokeWeight,this.strokeMode=e.strokeMode,this.currentRotation=e.rotation):console.warn("pop() called without matching push()")}reset(){this.currentShader=null,this.stateStack=[],this.currentRotation=0,this.fillMode=!0,this.strokeMode=!0,this.currentFillColor=[1,1,1,1],this.currentStrokeColor=[0,0,0,1],this.currentStrokeWeight=1}createShader(e,t){return new T(this.gl,e,t)}createFilterShader(e){return new T(this.gl,S,e)}setUniform(e,t){this.currentShader.setUniform(e,t)}rect(e,t,r,i){const s=new se(this.gl,e,t,r,i);if(this.currentShader!==null){if(this.currentRotation!==0){const{centerX:d,centerY:f,radians:g,aspectRatio:x}=this.calculateRotationParams(e,t,r,i);this.setUniform("u_rotation",g),this.setUniform("u_center",[d,f]),this.setUniform("u_aspectRatio",x)}else this.setUniform("u_rotation",0),this.setUniform("u_center",[0,0]),this.setUniform("u_aspectRatio",1);s.renderFill(),this.currentShader=null;return}const a=this.solidColorShader,{centerX:n,centerY:h,radians:c,aspectRatio:u}=this.calculateRotationParams(e,t,r,i);this.fillMode&&(this.shader(a),this.setUniform("u_color",this.currentFillColor),this.setUniform("u_rotation",c),this.setUniform("u_center",[n,h]),this.setUniform("u_aspectRatio",u),s.renderFill()),this.strokeMode&&(this.shader(a),this.setUniform("u_color",this.currentStrokeColor),this.setUniform("u_rotation",c),this.setUniform("u_center",[n,h]),this.setUniform("u_aspectRatio",u),s.renderStroke(this.currentStrokeWeight)),this.currentShader=null}line(e,t,r,i){if(!this.strokeMode)return;const s=new ne(this.gl,e,t,r,i);if(this.currentShader!==null){if(this.currentRotation!==0){const p=(e+r)/2,F=(t+i)/2,w=Math.abs(r-e),C=Math.abs(i-t),{centerX:y,centerY:B,radians:A,aspectRatio:R}=this.calculateRotationParams(p-w/2,F-C/2,w,C);this.setUniform("u_rotation",A),this.setUniform("u_center",[y,B]),this.setUniform("u_aspectRatio",R)}else this.setUniform("u_rotation",0),this.setUniform("u_center",[0,0]),this.setUniform("u_aspectRatio",1);s.renderStroke(this.currentStrokeWeight),this.currentShader=null;return}const a=this.solidColorShader,n=(e+r)/2,h=(t+i)/2,c=Math.abs(r-e),u=Math.abs(i-t),{centerX:d,centerY:f,radians:g,aspectRatio:x}=this.calculateRotationParams(n-c/2,h-u/2,c,u);this.shader(a),this.setUniform("u_color",this.currentStrokeColor),this.setUniform("u_rotation",g),this.setUniform("u_center",[d,f]),this.setUniform("u_aspectRatio",x),s.renderStroke(this.currentStrokeWeight),this.currentShader=null}calculateRotationParams(e,t,r,i){const s=this.gl.getParameter(this.gl.VIEWPORT),a=s[2],n=s[3],h=a/n,c=this.gl.getParameter(this.gl.FRAMEBUFFER_BINDING)!==null,u=e+r/2,d=t+i/2,f=u/a*2-1;let g;c?g=d/n*2-1:g=1-d/n*2;const x=this.currentRotation*Math.PI/180;return{centerX:f,centerY:g,radians:x,aspectRatio:h}}createFramebuffer(e,t,r={}){return new ie(this.gl,e,t,r)}background(e,t=e,r=e,i=255){this.clear(e/255,t/255,r/255,i/255)}clear(e=0,t=0,r=0,i=0){this.gl.clearColor(e,t,r,i),this.gl.clear(this.gl.COLOR_BUFFER_BIT)}resetViewport(){this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height)}get context(){return this.gl}dispose(){this.imageShader.dispose(),this.solidColorShader.dispose(),this.imageShader=null,this.solidColorShader=null,this.currentShader=null,this.stateStack=[]}image(e,t,r,i,s){this.shader(this.imageShader),this.setUniform("u_texture",e.texture);const{centerX:a,centerY:n,radians:h,aspectRatio:c}=this.calculateRotationParams(t,r,i??e.width,s??e.height);this.setUniform("u_rotation",h),this.setUniform("u_center",[a,n]),this.setUniform("u_aspectRatio",c),this.rect(t,r,i??e.width,s??e.height)}}var m={};m.parse=function(l){var e=function(s,a,n,h){var c=m.T,u={cmap:c.cmap,head:c.head,hhea:c.hhea,maxp:c.maxp,hmtx:c.hmtx,loca:c.loca,glyf:c.glyf},d={_data:s,_index:a,_offset:n};for(var f in u){var g=m.findTable(s,f,n);if(g){var x=g[0],p=h[x];p==null&&(p=u[f].parseTab(s,x,g[1],d)),d[f]=h[x]=p}}return d},t=new Uint8Array(l),r={},i=e(t,0,0,r);return[i]},m.findTable=function(l,e,t){for(var r=m.B,i=r.readUshort(l,t+4),s=t+12,a=0;a<i;a++){var n=r.readASCII(l,s,4);r.readUint(l,s+4);var h=r.readUint(l,s+8),c=r.readUint(l,s+12);if(n==e)return[h,c];s+=16}return null},m.T={},m.B={readShort:function(l,e){var t=m.B.t.uint16;return t[0]=l[e]<<8|l[e+1],m.B.t.int16[0]},readUshort:function(l,e){return l[e]<<8|l[e+1]},readUshorts:function(l,e,t){for(var r=[],i=0;i<t;i++)r.push(m.B.readUshort(l,e+i*2));return r},readUint:function(l,e){var t=m.B.t.uint8;return t[3]=l[e],t[2]=l[e+1],t[1]=l[e+2],t[0]=l[e+3],m.B.t.uint32[0]},readASCII:function(l,e,t){for(var r="",i=0;i<t;i++)r+=String.fromCharCode(l[e+i]);return r},t:function(){var l=new ArrayBuffer(8);return{uint8:new Uint8Array(l),int16:new Int16Array(l),uint16:new Uint16Array(l),uint32:new Uint32Array(l)}}()},m.T.cmap={parseTab:function(l,e,t){var r={tables:[],ids:{},off:e};l=new Uint8Array(l.buffer,e,t),e=0;var i=m.B,s=i.readUshort,a=m.T.cmap;s(l,e),e+=2;var n=s(l,e);e+=2;for(var h=[],c=0;c<n;c++){var u=s(l,e);e+=2;var d=s(l,e);e+=2;var f=i.readUint(l,e);e+=4;var g="p"+u+"e"+d,x=h.indexOf(f);if(x==-1){x=r.tables.length;var p={};h.push(f);var F=p.format=s(l,f);F==4?p=a.parse4(l,f,p):F==12&&(p=a.parse12(l,f,p)),r.tables.push(p)}r.ids[g]!=null&&console.log("multiple tables for one platform+encoding: "+g),r.ids[g]=x}return r},parse4:function(l,e,t){var r=m.B,i=r.readUshort,s=r.readUshorts,a=e;e+=2;var n=i(l,e);e+=2,i(l,e),e+=2;var h=i(l,e);e+=2;var c=h>>>1;t.searchRange=i(l,e),e+=2,t.entrySelector=i(l,e),e+=2,t.rangeShift=i(l,e),e+=2,t.endCount=s(l,e,c),e+=c*2,e+=2,t.startCount=s(l,e,c),e+=c*2,t.idDelta=[];for(var u=0;u<c;u++)t.idDelta.push(r.readShort(l,e)),e+=2;return t.idRangeOffset=s(l,e,c),e+=c*2,t.glyphIdArray=s(l,e,a+n-e>>1),t},parse12:function(l,e,t){var r=m.B,i=r.readUint;e+=4,i(l,e),e+=4,i(l,e),e+=4;var s=i(l,e)*3;e+=4;for(var a=t.groups=new Uint32Array(s),n=0;n<s;n+=3)a[n]=i(l,e+(n<<2)),a[n+1]=i(l,e+(n<<2)+4),a[n+2]=i(l,e+(n<<2)+8);return t}},m.T.head={parseTab:function(l,e,t){var r=m.B,i={};return e+=18,i.unitsPerEm=r.readUshort(l,e),e+=2,e+=16,i.xMin=r.readShort(l,e),e+=2,i.yMin=r.readShort(l,e),e+=2,i.xMax=r.readShort(l,e),e+=2,i.yMax=r.readShort(l,e),e+=2,e+=6,i.indexToLocFormat=r.readShort(l,e),i}},m.T.hhea={parseTab:function(l,e,t){var r=m.B,i={};e+=4;for(var s=["ascender","descender","lineGap","advanceWidthMax","minLeftSideBearing","minRightSideBearing","xMaxExtent","caretSlopeRise","caretSlopeRun","caretOffset","res0","res1","res2","res3","metricDataFormat","numberOfHMetrics"],a=0;a<s.length;a++){var n=s[a],h=n=="advanceWidthMax"||n=="numberOfHMetrics"?r.readUshort:r.readShort;i[n]=h(l,e+a*2)}return i}},m.T.hmtx={parseTab:function(l,e,t,r){for(var i=m.B,s=[],a=[],n=r.maxp.numGlyphs,h=r.hhea.numberOfHMetrics,c=0,u=0,d=0;d<h;)c=i.readUshort(l,e+(d<<2)),u=i.readShort(l,e+(d<<2)+2),s.push(c),a.push(u),d++;for(;d<n;)s.push(c),a.push(u),d++;return{aWidth:s,lsBearing:a}}},m.T.maxp={parseTab:function(l,e,t){var r=m.B,i=r.readUshort,s={};return r.readUint(l,e),e+=4,s.numGlyphs=i(l,e),e+=2,s}},m.T.loca={parseTab:function(l,e,t,r){var i=m.B,s=[],a=r.head.indexToLocFormat,n=r.maxp.numGlyphs+1;if(a==0)for(var h=0;h<n;h++)s.push(i.readUshort(l,e+(h<<1))<<1);if(a==1)for(var h=0;h<n;h++)s.push(i.readUint(l,e+(h<<2)));return s}},m.T.glyf={parseTab:function(l,e,t,r){for(var i=[],s=r.maxp.numGlyphs,a=0;a<s;a++)i.push(null);return i},_parseGlyf:function(l,e){var t=m.B,r=l._data,i=l.loca;if(i[e]==i[e+1])return null;var s=m.findTable(r,"glyf",l._offset)[0]+i[e],a={};if(a.noc=t.readShort(r,s),s+=2,a.xMin=t.readShort(r,s),s+=2,a.yMin=t.readShort(r,s),s+=2,a.xMax=t.readShort(r,s),s+=2,a.yMax=t.readShort(r,s),s+=2,a.xMin>=a.xMax||a.yMin>=a.yMax)return null;if(a.noc>0){a.endPts=[];for(var n=0;n<a.noc;n++)a.endPts.push(t.readUshort(r,s)),s+=2;var h=t.readUshort(r,s);if(s+=2,r.length-s<h)return null;s+=h;var c=a.endPts[a.noc-1]+1;a.flags=[];for(var n=0;n<c;n++){var u=r[s];if(s++,a.flags.push(u),u&8){var d=r[s];s++;for(var f=0;f<d;f++)a.flags.push(u),n++}}a.xs=[];for(var n=0;n<c;n++){var g=(a.flags[n]&2)!=0,x=(a.flags[n]&16)!=0;g?(a.xs.push(x?r[s]:-r[s]),s++):x?a.xs.push(0):(a.xs.push(t.readShort(r,s)),s+=2)}a.ys=[];for(var n=0;n<c;n++){var g=(a.flags[n]&4)!=0,x=(a.flags[n]&32)!=0;g?(a.ys.push(x?r[s]:-r[s]),s++):x?a.ys.push(0):(a.ys.push(t.readShort(r,s)),s+=2)}for(var p=0,F=0,n=0;n<c;n++)p+=a.xs[n],F+=a.ys[n],a.xs[n]=p,a.ys[n]=F}else a.parts=[];return a}},typeof module<"u"&&module.exports?module.exports=m:typeof window<"u"&&(window.Typr=m);class ce{extractCharacters(e){var r;const t=[];return(r=e==null?void 0:e.cmap)!=null&&r.tables?(e.cmap.tables.forEach(i=>{if(i.format===4){const s=this._extractCharactersFromFormat4Table(i);t.push(...s)}else if(i.format===12){const s=this._extractCharactersFromFormat12Table(i);t.push(...s)}}),[...new Set(t)]):[]}_extractCharactersFromFormat4Table(e){const t=[];if(!e.startCount||!e.endCount||!e.idRangeOffset||!e.idDelta)return t;for(let r=0;r<e.startCount.length;r++){const i=e.startCount[r],s=e.endCount[r];if(!(i===65535&&s===65535)){for(let a=i;a<=s;a++)if(this._calculateGlyphIndexFormat4(e,a,r)>0){const h=String.fromCodePoint(a);t.push(h)}}}return t}_extractCharactersFromFormat12Table(e){const t=[];if(!e.groups)return t;for(let r=0;r<e.groups.length;r+=3){const i=e.groups[r],s=e.groups[r+1],a=e.groups[r+2];for(let n=i;n<=s;n++)if(a+(n-i)>0){const c=String.fromCodePoint(n);t.push(c)}}return t}_calculateGlyphIndexFormat4(e,t,r){if(e.idRangeOffset[r]===0)return t+e.idDelta[r]&65535;{const i=e.idRangeOffset[r]/2+(t-e.startCount[r])-(e.startCount.length-r);if(i>=0&&e.glyphIdArray&&i<e.glyphIdArray.length){const s=e.glyphIdArray[i];if(s!==0)return s+e.idDelta[r]&65535}}return 0}filterProblematicCharacters(e){return e.filter(t=>this._isValidCharacter(t))}_isValidCharacter(e){const t=e.codePointAt(0)||0;return!(t>=0&&t<=31&&t!==9&&t!==10&&t!==13||t>=127&&t<=159)}}class ue{constructor(e){o(this,"_textureCanvas");o(this,"_textureContext");o(this,"_renderer");this._renderer=e,this._textureCanvas=document.createElement("canvas"),this._textureContext=this._textureCanvas.getContext("2d",{willReadFrequently:!0,alpha:!1})}createTextureAtlas(e,t,r,i){const s=e.length,a=Math.ceil(Math.sqrt(s)),n=Math.ceil(s/a),h=t.width*a,c=t.height*n;this._setupCanvas(h,c,r,i),this._renderCharactersToCanvas(e,t,a,r),this._applyBlackWhiteThreshold();const u=this._renderer.createFramebuffer(h,c,{filter:"nearest"});return u.update(this._textureCanvas),{framebuffer:u,columns:a,rows:n}}_setupCanvas(e,t,r,i){this._textureCanvas.width=e,this._textureCanvas.height=t,this._textureCanvas.style.width=e+"px",this._textureCanvas.style.height=e+"px",this._textureContext.imageSmoothingEnabled=!1,this._textureCanvas.style.imageRendering="pixelated",this._textureContext.fillStyle="black",this._textureContext.fillRect(0,0,e,t),this._textureContext.font=`${r}px ${i}`,this._textureContext.textBaseline="top",this._textureContext.textAlign="left",this._textureContext.fillStyle="white"}_renderCharactersToCanvas(e,t,r,i){for(let s=0;s<e.length;s++){const a=s%r,n=Math.floor(s/r),h=a*t.width+t.width*.5,c=n*t.height+t.height*.5,u=Math.round(h-t.width*.5),d=Math.round(c-i*.5);this._textureContext.fillText(e[s].character,u,d)}}_applyBlackWhiteThreshold(e=128){const t=this._textureContext.getImageData(0,0,this._textureCanvas.width,this._textureCanvas.height),r=t.data;for(let i=0;i<r.length;i+=4){const s=.299*r[i]+.587*r[i+1]+.114*r[i+2],a=e+32,n=s>a?255:0;r[i]=n,r[i+1]=n,r[i+2]=n}this._textureContext.putImageData(t,0,0)}}class de{constructor(){o(this,"_tempCanvas");o(this,"_tempContext");this._tempCanvas=document.createElement("canvas"),this._tempContext=this._tempCanvas.getContext("2d")}calculateMaxGlyphDimensions(e,t,r){this._tempContext.font=`${t}px ${r}`;let i=0,s=0;for(const a of e){const n=this._tempContext.measureText(a),h=n.width,c=n.actualBoundingBoxAscent+n.actualBoundingBoxDescent;h>0&&(i=Math.max(i,h),s=Math.max(s,c))}return{width:Math.ceil(i),height:Math.ceil(s)}}}class fe{createCharacterObjects(e,t){return e.map((r,i)=>{const s=r.codePointAt(0)||0,a=this._generateCharacterColor(i);let n=0;if(t.hmtx&&t.hmtx.aWidth){const h=this._getGlyphIndex(t,s);h>0&&t.hmtx.aWidth[h]!==void 0&&(n=t.hmtx.aWidth[h])}return{character:r,unicode:s,color:a,advanceWidth:n}})}_getGlyphIndex(e,t){const r=e.cmap;if(!r||!r.tables)return 0;for(const i of r.tables)if(i.format===4){for(let s=0;s<i.startCount.length;s++)if(t>=i.startCount[s]&&t<=i.endCount[s]){if(i.idRangeOffset[s]===0)return t+i.idDelta[s]&65535;{const a=i.idRangeOffset[s]/2+(t-i.startCount[s])-(i.startCount.length-s);if(a>=0&&a<i.glyphIdArray.length){const n=i.glyphIdArray[a];if(n!==0)return n+i.idDelta[s]&65535}}}}return 0}_generateCharacterColor(e){const t=e%256,r=Math.floor(e/256)%256,i=Math.floor(e/65536)%256;return[t,r,i]}getCharacterColor(e,t){if(!b.validate(typeof e=="string"&&e.length===1,"Character must be a single character string.",{method:"getCharacterColor",providedValue:e}))return[0,0,0];const r=t.find(i=>i.character===e);return r?r.color:[0,0,0]}getCharacterColors(e,t){return b.validate(typeof e=="string"&&e.length>0,"Characters must be a string with at least one character.",{method:"getCharacterColors",providedValue:e})?e.split("").map(r=>this.getCharacterColor(r,t)||[0,0,0]):[[0,0,0]]}}class q{constructor(e,t=16){o(this,"_font");o(this,"_characters",[]);o(this,"_fontFramebuffer");o(this,"_fontSize",16);o(this,"_textureColumns",0);o(this,"_textureRows",0);o(this,"_maxGlyphDimensions",{width:0,height:0});o(this,"_fontFace");o(this,"_fontFamilyName","UrsaFont");o(this,"_characterExtractor");o(this,"_textureAtlas");o(this,"_metricsCalculator");o(this,"_characterColorMapper");this._fontSize=t,this._characterExtractor=new ce,this._textureAtlas=new ue(e),this._metricsCalculator=new de,this._characterColorMapper=new fe}async initialize(e){let t;if(e){const r=await fetch(e);if(!r.ok)throw new _(`Failed to load font file: ${r.status} ${r.statusText}`);t=await r.arrayBuffer()}else throw new _("Embedded font not available. This appears to be a minified build - please provide `fontSource`.");await this._loadFontFace(t),this._font=m.parse(t)[0],await this._initializeFont()}setFontSize(e){if(e===void 0)return this._fontSize;this._fontSize=e,this._maxGlyphDimensions=this._metricsCalculator.calculateMaxGlyphDimensions(this._characters.map(r=>r.character),this._fontSize,this._fontFamilyName);const t=this._textureAtlas.createTextureAtlas(this._characters,this._maxGlyphDimensions,this._fontSize,this._fontFamilyName);this._fontFramebuffer=t.framebuffer,this._textureColumns=t.columns,this._textureRows=t.rows}async loadFont(e){try{const t=await fetch(e);if(!t.ok)throw new _(`Failed to load font file: ${t.status} ${t.statusText}`);const r=await t.arrayBuffer();await this._loadFontFace(r);const i=m.parse(r);if(!i||i.length===0)throw new Error("Failed to parse font file");this._font=i[0],await this._initializeFont()}catch(t){throw new _(`Failed to load font: ${t instanceof Error?t.message:"Unknown error"}`,t)}}async _loadFontFace(e){const t=Date.now();this._fontFamilyName=this._fontFamilyName==="UrsaFont"?"UrsaFont":`CustomFont_${t}`,this._fontFace=new FontFace(this._fontFamilyName,e),await this._fontFace.load(),document.fonts.add(this._fontFace)}async _initializeFont(){const e=this._characterExtractor.extractCharacters(this._font),t=this._characterExtractor.filterProblematicCharacters(e);this._characters=this._characterColorMapper.createCharacterObjects(t,this._font),this._maxGlyphDimensions=this._metricsCalculator.calculateMaxGlyphDimensions(t,this._fontSize,this._fontFamilyName);const r=this._textureAtlas.createTextureAtlas(this._characters,this._maxGlyphDimensions,this._fontSize,this._fontFamilyName);this._fontFramebuffer=r.framebuffer,this._textureColumns=r.columns,this._textureRows=r.rows}getCharacterColor(e){return this._characterColorMapper.getCharacterColor(e,this._characters)}getCharacterColors(e){return this._characterColorMapper.getCharacterColors(e,this._characters)}hasAllCharacters(e){if(typeof e!="string"||e.length===0)return!1;const t=new Set(this._characters.map(r=>r.character));for(const r of e)if(!t.has(r))return!1;return!0}get fontFramebuffer(){return this._fontFramebuffer}get characters(){return this._characters}get textureColumns(){return this._textureColumns}get textureRows(){return this._textureRows}get maxGlyphDimensions(){return this._maxGlyphDimensions}dispose(){this._fontFramebuffer.dispose(),document.fonts.delete(this._fontFace),this._fontFramebuffer=null,this._fontFace=null,this._font=null,this._characters=[],this._maxGlyphDimensions={width:0,height:0},this._textureColumns=0,this._textureRows=0}get fontSize(){return this._fontSize}get font(){return this._font}}class Q{constructor(e,t,r){o(this,"_cols");o(this,"_rows");o(this,"_width");o(this,"_height");o(this,"_offsetX");o(this,"_offsetY");o(this,"_fixedDimensions",!1);o(this,"_canvas");o(this,"_cellWidth");o(this,"_cellHeight");this._canvas=e,this._cellWidth=t,this._cellHeight=r,this.reset()}reset(){if(!this._fixedDimensions){const e=this._canvas.getBoundingClientRect();let t=Math.round(e.width),r=Math.round(e.height);[this._cols,this._rows]=[Math.floor(t/this._cellWidth),Math.floor(r/this._cellHeight)]}this._resizeGrid()}_resizeGrid(){const e=this._canvas.getBoundingClientRect();let t=Math.round(e.width),r=Math.round(e.height);this._width=this._cols*this._cellWidth,this._height=this._rows*this._cellHeight,this._offsetX=Math.floor((t-this._width)/2),this._offsetY=Math.floor((r-this._height)/2)}resizeCellPixelDimensions(e,t){[this._cellWidth,this._cellHeight]=[e,t],this.reset()}resizeGridDimensions(e,t){this._fixedDimensions=!0,[this._cols,this._rows]=[e,t],this._resizeGrid()}resetGridDimensions(){this._fixedDimensions=!1,this.reset()}resize(){this._fixedDimensions?this._resizeGrid():this.reset()}fixedDimensions(e){if(e===void 0)return this._fixedDimensions;this._fixedDimensions=e}get cellWidth(){return this._cellWidth}get cellHeight(){return this._cellHeight}dispose(){this._canvas=null,this._cols=0,this._rows=0,this._width=0,this._height=0,this._offsetX=0,this._offsetY=0,this._cellWidth=0,this._cellHeight=0}get cols(){return this._cols}get rows(){return this._rows}get width(){return this._width}get height(){return this._height}get offsetX(){return this._offsetX}get offsetY(){return this._offsetY}}class Z{constructor(e,t=!1,r={}){o(this,"_canvas");o(this,"captureSource");o(this,"_isStandalone");this.captureSource=e,this._isStandalone=t,this._canvas=this.createCanvas(r.width,r.height)}createCanvas(e,t){var i;const r=document.createElement("canvas");if(r.className="textmodeCanvas",r.style.imageRendering="pixelated",this._isStandalone)r.width=e||800,r.height=t||600,document.body.appendChild(r);else{const s=this.captureSource.getBoundingClientRect();let a=Math.round(s.width),n=Math.round(s.height);if(this.captureSource instanceof HTMLVideoElement){const u=this.captureSource;(a===0||n===0)&&u.videoWidth>0&&u.videoHeight>0&&(a=u.videoWidth,n=u.videoHeight)}r.width=a,r.height=n,r.style.position="absolute",r.style.pointerEvents="none";const h=window.getComputedStyle(this.captureSource);let c=parseInt(h.zIndex||"0",10);isNaN(c)&&(c=0),r.style.zIndex=(c+1).toString(),this.positionOverlayCanvas(r),(i=this.captureSource.parentNode)==null||i.insertBefore(r,this.captureSource.nextSibling)}return r}positionOverlayCanvas(e){const t=this.captureSource.getBoundingClientRect();let r=this.captureSource.offsetParent;if(r&&r!==document.body){const i=r.getBoundingClientRect();e.style.top=t.top-i.top+"px",e.style.left=t.left-i.left+"px"}else e.style.top=t.top+window.scrollY+"px",e.style.left=t.left+window.scrollX+"px"}resize(e,t){if(this._isStandalone)this._canvas.width=e??this._canvas.width,this._canvas.height=t??this._canvas.height;else{const r=this.captureSource.getBoundingClientRect();let i=Math.round(r.width),s=Math.round(r.height);if(this.captureSource instanceof HTMLVideoElement){const a=this.captureSource;(i===0||s===0)&&a.videoWidth>0&&a.videoHeight>0&&(i=a.videoWidth,s=a.videoHeight)}this._canvas.width=i,this._canvas.height=s,this.positionOverlayCanvas(this._canvas)}}getWebGLContext(){const e={alpha:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0,antialias:!1,depth:!1,stencil:!1,powerPreference:"high-performance"},t=this._canvas.getContext("webgl2",e)||this._canvas.getContext("webgl",e);if(!t)throw new _("WebGL context could not be created. Ensure your browser supports WebGL.");return t}dispose(){if(this._canvas){const e=this._canvas.getContext("webgl")||this._canvas.getContext("webgl2");if(e){const t=e.getExtension("WEBGL_lose_context");t&&t.loseContext()}this._canvas.parentNode&&this._canvas.parentNode.removeChild(this._canvas),this._canvas=null}this.captureSource=null}get canvas(){return this._canvas}get width(){return this._canvas.width}get height(){return this._canvas.height}}class M{constructor(e,t,r,i={}){o(this,"renderer");o(this,"fontManager");o(this,"grid");o(this,"_characterFramebuffer");o(this,"_primaryColorFramebuffer");o(this,"_secondaryColorFramebuffer");o(this,"_rotationFramebuffer");o(this,"_transformFramebuffer");o(this,"_options");this.renderer=e,this.fontManager=t,this.grid=r,this._options=i,this._characterFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._rotationFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows),this._transformFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows)}resize(){this._characterFramebuffer.resize(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._rotationFramebuffer.resize(this.grid.cols,this.grid.rows),this._transformFramebuffer.resize(this.grid.cols,this.grid.rows)}enabled(e){this._options.enabled=e}enable(){this.enabled(!0)}disable(){this.enabled(!1)}dispose(){this._characterFramebuffer.dispose(),this._primaryColorFramebuffer.dispose(),this._secondaryColorFramebuffer.dispose(),this._rotationFramebuffer.dispose(),this._transformFramebuffer.dispose(),this._characterFramebuffer=null,this._primaryColorFramebuffer=null,this._secondaryColorFramebuffer=null,this._rotationFramebuffer=null,this._transformFramebuffer=null}get characterFramebuffer(){return this._characterFramebuffer}get primaryColorFramebuffer(){return this._primaryColorFramebuffer}get secondaryColorFramebuffer(){return this._secondaryColorFramebuffer}get rotationFramebuffer(){return this._rotationFramebuffer}get transformFramebuffer(){return this._transformFramebuffer}get options(){return this._options}}class me{constructor(e,t){o(this,"_framebuffer");o(this,"_renderer");o(this,"_colors");this._renderer=e,this._colors=t;const r=Math.max(this._colors.length,1);this._framebuffer=this._renderer.createFramebuffer(r,1),this._updateFramebuffer()}_updateFramebuffer(){if(!this._framebuffer)return;const e=Math.max(this._colors.length,1),t=1;this._framebuffer.width!==e&&this._framebuffer.resize(e,t);const r=new Uint8Array(e*t*4);for(let i=0;i<e;i++){const s=i<this._colors.length?this._colors[i]:[0,0,0],a=i*4;r[a]=s[0],r[a+1]=s[1],r[a+2]=s[2],r[a+3]=255}this._framebuffer.updatePixels(r,e,t)}setColors(e){this._colors=e,this._updateFramebuffer()}get colors(){return this._colors}get framebuffer(){return this._framebuffer}get texture(){return this._framebuffer.texture}}class k extends M{constructor(t,r,i,s={}){super(t,r,i,s);o(this,"palette");this.palette=new me(this.renderer,this.fontManager.getCharacterColors(" .:-=+*%@#"))}characters(t){b.validate(this.fontManager.hasAllCharacters(t),"One or more characters do not exist in the current font.",{method:"characters",providedValue:t})&&(this._options.characters=t,this.palette.setColors(this.fontManager.getCharacterColors(t)))}characterColor(t,r,i,s=255){let a,n,h,c;if(typeof t=="string"){const u=this.parseHexColor(t);if(!u){b.validate(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:"characterColor",providedValue:t});return}[a,n,h,c]=u}else if(a=t,n=r!==void 0?r:t,h=i!==void 0?i:t,c=s,!b.validate([a,n,h,c].every(u=>u>=0&&u<=255),"Character color values must be between 0 and 255",{method:"characterColor",providedValues:{r:a,g:n,b:h,a:c}}))return;this._options.characterColor=[a/255,n/255,h/255,c/255]}characterColorMode(t){b.validate(["sampled","fixed"].includes(t),"Invalid character color mode. Must be 'sampled' or 'fixed'.",{method:"characterColorMode",providedValue:t})&&(this._options.characterColorMode=t)}cellColor(t,r,i,s=255){let a,n,h,c;if(typeof t=="string"){const u=this.parseHexColor(t);if(!u){b.validate(!1,"Invalid hex color format. Use '#FF0000', '#F00', 'FF0000', or 'F00'.",{method:"cellColor",providedValue:t});return}[a,n,h,c]=u}else if(a=t,n=r!==void 0?r:t,h=i!==void 0?i:t,c=s,!b.validate([a,n,h,c].every(u=>u>=0&&u<=255),"Cell color values must be between 0 and 255",{method:"cellColor",providedValues:{r:a,g:n,b:h,a:c}}))return;this._options.cellColor=[a/255,n/255,h/255,c/255]}cellColorMode(t){b.validate(["sampled","fixed"].includes(t),"Invalid cell color mode. Must be 'sampled' or 'fixed'.",{method:"cellColorMode",providedValue:t})&&(this._options.cellColorMode=t)}invert(t){b.validate(typeof t=="boolean"||typeof t=="number"&&Number.isInteger(t),"Invert must be a boolean value or an integer (0 for false, any other number for true).",{method:"invert",providedValue:t})&&(this._options.invert=!!t)}rotation(t){if(!b.validate(typeof t=="number","Rotation angle must be a number.",{method:"rotation",providedValue:t}))return;t=t%360,t<0&&(t+=360);const r=t*255/360,i=Math.floor(r)/255,s=Math.round(r-i);this._options.rotation=[i,s,0,1]}flipHorizontally(t){b.validate(typeof t=="boolean"||typeof t=="number"&&Number.isInteger(t),"Flip horizontally must be a boolean value or an integer (0 for false, any other number for true).",{method:"flipHorizontally",providedValue:t})&&(this._options.flipHorizontally=!!t)}flipVertically(t){b.validate(typeof t=="boolean"||typeof t=="number"&&Number.isInteger(t),"Flip vertically must be a boolean value or an integer (0 for false, any other number for true).",{method:"flipVertically",providedValue:t})&&(this._options.flipVertically=!!t)}parseHexColor(t){if(t=t.replace(/^#/,""),!/^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(t))return null;t.length===3&&(t=t.split("").map(a=>a+a).join(""));const r=parseInt(t.slice(0,2),16),i=parseInt(t.slice(2,4),16),s=parseInt(t.slice(4,6),16);return[r,i,s,255]}}var ge="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);}}",pe="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);}}",_e="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);}}",xe="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);}}",ve="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);}";const be={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 k{constructor(t,r,i){super(t,r,i,{...be});o(this,"sampleShader");o(this,"colorFillShader");o(this,"charMappingShader");o(this,"transformFillShader");o(this,"rotationFillShader");o(this,"sampleFramebuffer");this.sampleShader=new T(t.context,S,ge),this.colorFillShader=new T(t.context,S,pe),this.transformFillShader=new T(t.context,S,_e),this.rotationFillShader=new T(t.context,S,xe),this.charMappingShader=new T(t.context,S,ve),this.sampleFramebuffer=this.renderer.createFramebuffer(this.grid.cols,this.grid.rows)}convert(t){this.sampleFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.sampleShader),this.renderer.setUniform("u_sketchTexture",t),this.renderer.setUniform("u_gridCellDimensions",[this.grid.cols,this.grid.rows]),this.renderer.setUniform("u_brightnessRange",this._options.brightnessRange),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this.sampleFramebuffer.end(),this._primaryColorFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.colorFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_fillColor",this._options.characterColor),this.renderer.setUniform("u_useFixedColor",this._options.characterColorMode==="fixed"),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.end(),this._secondaryColorFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.colorFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_fillColor",this._options.cellColor),this.renderer.setUniform("u_useFixedColor",this._options.cellColorMode==="fixed"),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.end(),this._transformFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.transformFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_invert",this._options.invert),this.renderer.setUniform("u_flipHorizontally",this._options.flipHorizontally),this.renderer.setUniform("u_flipVertically",this._options.flipVertically),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._transformFramebuffer.end(),this._rotationFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this.rotationFillShader),this.renderer.setUniform("u_sampleTexture",this.sampleFramebuffer.texture),this.renderer.setUniform("u_rotationColor",this._options.rotation),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._rotationFramebuffer.end(),this._characterFramebuffer.begin(),this.renderer.clear(0,0,0,0),this.renderer.shader(this.charMappingShader),this.renderer.setUniform("u_colorSampleFramebuffer",this.sampleFramebuffer.texture),this.renderer.setUniform("u_charPaletteTexture",this.palette.texture),this.renderer.setUniform("u_charPaletteSize",[this.palette.colors.length,1]),this.renderer.setUniform("u_brightnessRange",this._options.brightnessRange),this.renderer.rect(0,0,this.grid.cols,this.grid.rows),this._characterFramebuffer.end()}resize(){super.resize(),this.sampleFramebuffer.resize(this.grid.cols,this.grid.rows)}brightnessRange(t){b.validate(Array.isArray(t)&&t.length===2&&t.every(r=>typeof r=="number"&&r>=0&&r<=255),"Brightness range must be an array of two numbers between 0 and 255.",{method:"brightnessRange",providedValue:t})&&(this._options.brightnessRange=t)}}const Ce=Object.freeze(Object.defineProperty({__proto__:null,TextmodeBrightnessConverter:z,TextmodeConverter:M,TextmodeFeatureConverter:k},Symbol.toStringTag,{value:"Module"}));var Fe="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);vec2 charCoord=vec2(charCol,charRow)/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);}";class J{constructor(e,t,r){o(this,"renderer");o(this,"font");o(this,"grid");o(this,"converters");o(this,"_resultFramebuffer");o(this,"_asciiShader");o(this,"_characterFramebuffer");o(this,"_primaryColorFramebuffer");o(this,"_secondaryColorFramebuffer");o(this,"_rotationFramebuffer");o(this,"_transformFramebuffer");this.renderer=e,this.font=t,this.grid=r,this._asciiShader=this.renderer.createShader(S,Fe),this.converters=[{name:"brightness",converter:new z(e,t,r)},{name:"custom",converter:new M(e,t,r)}],this._characterFramebuffer=this.renderer.createFramebuffer(r.cols,r.rows),this._primaryColorFramebuffer=this.renderer.createFramebuffer(r.cols,r.rows),this._secondaryColorFramebuffer=this.renderer.createFramebuffer(r.cols,r.rows),this._rotationFramebuffer=this.renderer.createFramebuffer(r.cols,r.rows),this._transformFramebuffer=this.renderer.createFramebuffer(r.cols,r.rows),this._resultFramebuffer=this.renderer.createFramebuffer(this.grid.width,this.grid.height)}render(e){for(const r of this.converters){const i=r.converter;i.options.enabled&&i instanceof k&&i.convert(e)}const t=(r,i)=>{r.begin(),this.renderer.clear();for(const s of this.converters){const a=s.converter;a.options.enabled&&this.renderer.image(i(a),0,0)}r.end()};t(this._characterFramebuffer,r=>r.characterFramebuffer),t(this._primaryColorFramebuffer,r=>r.primaryColorFramebuffer),t(this._secondaryColorFramebuffer,r=>r.secondaryColorFramebuffer),t(this._rotationFramebuffer,r=>r.rotationFramebuffer),t(this._transformFramebuffer,r=>r.transformFramebuffer),this._resultFramebuffer.begin(),this.renderer.clear(),this.renderer.shader(this._asciiShader),this.renderer.setUniform("u_characterTexture",this.font.fontFramebuffer),this.renderer.setUniform("u_charsetDimensions",[this.font.textureColumns,this.font.textureRows]),this.renderer.setUniform("u_asciiCharacterTexture",this._characterFramebuffer.texture),this.renderer.setUniform("u_primaryColorTexture",this._primaryColorFramebuffer.texture),this.renderer.setUniform("u_secondaryColorTexture",this._secondaryColorFramebuffer.texture),this.renderer.setUniform("u_transformTexture",this._transformFramebuffer.texture),this.renderer.setUniform("u_rotationTexture",this._rotationFramebuffer.texture),this.renderer.setUniform("u_captureTexture",e.texture),this.renderer.setUniform("u_backgroundMode",!1),this.renderer.setUniform("u_captureDimensions",[e.width,e.height]),this.renderer.setUniform("u_gridCellDimensions",[this.grid.cols,this.grid.rows]),this.renderer.setUniform("u_gridPixelDimensions",[this.grid.width,this.grid.height]),this.renderer.rect(0,0,this._resultFramebuffer.width,this._resultFramebuffer.height),this._resultFramebuffer.end()}get(e){if(!b.validate(typeof e=="string"&&e.length>0,"Converter name must be a non-empty string.",{method:"converter",providedValue:e}))return;const t=this.converters.find(i=>i.name===e),r=t==null?void 0:t.converter;if(b.validate(r instanceof M,`Converter "${e}" is not a valid TextmodeConverter.`,{method:"converter",providedValue:e,converterInstance:r}))return r}add(e,t){if(!b.validate(typeof e=="string"&&e.length>0,"Converter name must be a non-empty string.",{method:"add",providedValue:e})||!b.validate(t==="brightness"||t==="custom",`Converter type must be either "brightness" or "custom". Provided: ${t}`,{method:"add",providedValue:t}))return;let r;return t==="brightness"?r=new z(this.renderer,this.font,this.grid):r=new M(this.renderer,this.font,this.grid),this.converters.push({name:e,converter:r}),r}remove(e){if(!b.validate(typeof e=="string"||e instanceof M,"Parameter must be either a string (converter name) or a TextmodeConverter instance.",{method:"remove",providedValue:e}))return;let t=-1;if(typeof e=="string"){if(!b.validate(e.length>0,"Converter name must be a non-empty string.",{method:"remove",providedValue:e}))return;t=this.converters.findIndex(r=>r.name===e)}else t=this.converters.findIndex(r=>r.converter===e);b.validate(t!==-1,typeof e=="string"?`Converter with name "${e}" not found in pipeline.`:"Converter instance not found in pipeline.",{method:"remove",providedValue:e,convertersCount:this.converters.length})&&this.converters.splice(t,1)}get texture(){return this._resultFramebuffer}resize(){this._resultFramebuffer.resize(this.grid.width,this.grid.height),this._characterFramebuffer.resize(this.grid.cols,this.grid.rows),this._primaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._secondaryColorFramebuffer.resize(this.grid.cols,this.grid.rows),this._rotationFramebuffer.resize(this.grid.cols,this.grid.rows),this._transformFramebuffer.resize(this.grid.cols,this.grid.rows);for(const e of this.converters)e.converter.resize()}hasEnabledConverters(){return this.converters.some(e=>e.converter.options.enabled)}disable(){for(const e of this.converters)e.converter.disable()}enable(){for(const e of this.converters)e.converter.enable()}dispose(){for(const e of this.converters)e.converter.dispose();this._characterFramebuffer.dispose(),this._primaryColorFramebuffer.dispose(),this._secondaryColorFramebuffer.dispose(),this._rotationFramebuffer.dispose(),this._transformFramebuffer.dispose(),this._resultFramebuffer.dispose(),this._asciiShader.dispose(),this.converters=[],this._characterFramebuffer=null,this._primaryColorFramebuffer=null,this._secondaryColorFramebuffer=null,this._rotationFramebuffer=null,this._transformFramebuffer=null,this._resultFramebuffer=null,this._asciiShader=null}get characterFramebuffer(){return this._characterFramebuffer}get primaryColorFramebuffer(){return this._primaryColorFramebuffer}get secondaryColorFramebuffer(){return this._secondaryColorFramebuffer}get rotationFramebuffer(){return this._rotationFramebuffer}get transformFramebuffer(){return this._transformFramebuffer}}class ${extractFramebufferData(e){const t=e.get("brightness"),r=t==null?void 0:t.characterFramebuffer,i=t==null?void 0:t.primaryColorFramebuffer,s=t==null?void 0:t.secondaryColorFramebuffer,a=t==null?void 0:t.transformFramebuffer,n=t==null?void 0:t.rotationFramebuffer;return r==null||r.loadPixels(),i==null||i.loadPixels(),s==null||s.loadPixels(),a==null||a.loadPixels(),n==null||n.loadPixels(),{characterPixels:(r==null?void 0:r.pixels)||new Uint8Array(0),primaryColorPixels:(i==null?void 0:i.pixels)||new Uint8Array(0),secondaryColorPixels:(s==null?void 0:s.pixels)||new Uint8Array(0),transformPixels:(a==null?void 0:a.pixels)||new Uint8Array(0),rotationPixels:(n==null?void 0:n.pixels)||new Uint8Array(0)}}getCharacterIndex(e,t){const r=e[t],i=e[t+1];return r+(i<<8)}pixelsToRGBA(e,t){return{r:e[t],g:e[t+1],b:e[t+2],a:e[t+3]}}}class L{createBlob(e,t){return new Blob([e],{type:t})}downloadFile(e,t,r){try{const i=this.createBlob(e,r),s=URL.createObjectURL(i),a=document.createElement("a");a.href=s,a.download=t,a.style.display="none",a.rel="noopener",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(s)}catch(i){throw console.error("Failed to download file:",i),new Error(`File download failed: ${i instanceof Error?i.message:"Unknown error"}`)}}generateTimestamp(){return new Date().toISOString().slice(0,19).replace(/:/g,"-")}generateDateTimeString(){const e=new Date,t=e.toISOString().split("T")[0],r=e.toTimeString().split(" ")[0].replace(/:/g,"-");return{date:t,time:r}}sanitizeFilename(e){return e.replace(/[<>:"/\\|?*]/g,"_").replace(/\s+/g,"_").replace(/_{2,}/g,"_").replace(/^_+|_+$/g,"").substring(0,255)}generateDefaultFilename(){return`'textmode-export'-${this.generateTimestamp()}`}}class we extends ${extractTransformData(e,t,r){const i=e[r],s=e[r+1],a=e[r+2],n=i===255,h=s===255,c=a===255,u=t[r],d=t[r+1],f=u+d/255,g=Math.round(f*360/255*100)/100;return{isInverted:n,flipHorizontal:h,flipVertical:c,rotation:g}}calculateCellPosition(e,t,r){return{x:e,y:t,cellX:e*r.cellWidth,cellY:t*r.cellHeight}}extractSVGCellData(e,t){const r=[];let i=0;for(let s=0;s<t.rows;s++)for(let a=0;a<t.cols;a++){const n=i*4,h=this.getCharacterIndex(e.characterPixels,n);let c=this.pixelsToRGBA(e.primaryColorPixels,n),u=this.pixelsToRGBA(e.secondaryColorPixels,n);const d=this.extractTransformData(e.transformPixels,e.rotationPixels,n);if(d.isInverted){const g=c;c=u,u=g}const f=this.calculateCellPosition(a,s,t);r.push({charIndex:h,primaryColor:c,secondaryColor:u,transform:d,position:f}),i++}return r}}class ye{getGlyphIndex(e,t){const r=e.cmap;if(!r||!r.tables)return 0;for(const i of r.tables)if(i.format===4){for(let s=0;s<i.startCount.length;s++)if(t>=i.startCount[s]&&t<=i.endCount[s]){if(i.idRangeOffset[s]===0)return t+i.idDelta[s]&65535;{const a=i.idRangeOffset[s]/2+(t-i.startCount[s])-(i.startCount.length-s);if(a>=0&&a<i.glyphIdArray.length){const n=i.glyphIdArray[a];if(n!==0)return n+i.idDelta[s]&65535}}}}return 0}createEmptyPath(){return{getBoundingBox:()=>({x1:0,y1:0,x2:0,y2:0}),toSVG:()=>""}}createGlyphPath(e,t,r,i,s){if(!t||!t.xs||t.xs.length===0)return this.createEmptyPath();const a=s/e.head.unitsPerEm;return{getBoundingBox:()=>({x1:r+t.xMin*a,y1:i+-t.yMax*a,x2:r+t.xMax*a,y2:i+-t.yMin*a}),toSVG:()=>this.glyphToSVGPath(t,r,i,a)}}glyphToSVGPath(e,t,r,i){if(!e||!e.xs)return"";const{xs:s,ys:a,endPts:n,flags:h}=e;if(!s||!a||!n||!h)return"";let c="",u=0;for(let d=0;d<n.length;d++){const f=n[d];if(!(f<u)){if(f>=u){const g=t+s[u]*i,x=r-a[u]*i;c+=`M${g.toFixed(2)},${x.toFixed(2)}`;let p=u+1;for(;p<=f;)if((h[p]&1)!==0){const w=t+s[p]*i,C=r-a[p]*i;c+=`L${w.toFixed(2)},${C.toFixed(2)}`,p++}else{const w=t+s[p]*i,C=r-a[p]*i;let y=p+1>f?u:p+1;if((h[y]&1)!==0){const A=t+s[y]*i,R=r-a[y]*i;c+=`Q${w.toFixed(2)},${C.toFixed(2)} ${A.toFixed(2)},${R.toFixed(2)}`,p=y+1}else{const A=t+s[y]*i,R=r-a[y]*i,X=(w+A)/2,G=(C+R)/2;c+=`Q${w.toFixed(2)},${C.toFixed(2)} ${X.toFixed(2)},${G.toFixed(2)}`,p=y}}c+="Z"}u=f+1}}return c}generateCharacterPath(e,t,r,i,s){try{const a=e.codePointAt(0)||0,n=this.getGlyphIndex(t,a);if(n===0)return this.createEmptyPath();let h=null;try{t.glyf&&t.glyf[n]!==null?h=t.glyf[n]:m&&m.T&&m.T.glyf&&m.T.glyf._parseGlyf&&(h=m.T.glyf._parseGlyf(t,n),t.glyf&&h&&(t.glyf[n]=h))}catch(c){console.warn(`Failed to parse glyph ${n}:`,c)}return h?this.createGlyphPath(t,h,r,i,s):this.createEmptyPath()}catch(a){return console.warn(`Failed to generate path for character "${e}":`,a),this.createEmptyPath()}}generatePositionedCharacterPath(e,t,r,i,s,a,n,h){try{const c=n/t.head.unitsPerEm,u=h*c,d=r+(s-u)/2,f=i+(a+n*.7)/2;return this.generateCharacterPath(e,t,d,f,n).toSVG()||null}catch(c){return console.warn(`Failed to generate positioned character path for "${e}":`,c),null}}}class Te{constructor(){o(this,"pathGenerator");this.pathGenerator=new ye}generateSVGHeader(e){return`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
8
8
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
|
9
9
|
<svg width="${e.width}" height="${e.height}" viewBox="0 0 ${e.width} ${e.height}"
|
|
10
10
|
xmlns="http://www.w3.org/2000/svg" version="1.1">
|
|
@@ -22,4 +22,4 @@
|
|
|
22
22
|
<g id="ascii-cells">`;for(const a of e)s+=this.generateCellContent(a,t,r,i);return s+=this.generateSVGFooter(),s}optimizeSVGContent(e){return e.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\n\s*\n/g,`
|
|
23
23
|
`).replace(/[ \t]+$/gm,"")}}class Se extends L{createSVGBlob(e){return this.createBlob(e,"image/svg+xml;charset=utf-8")}downloadSVG(e,t){try{this.downloadFile(e,this.sanitizeFilename(t)+".svg","image/svg+xml;charset=utf-8")}catch(r){throw console.error("Failed to download SVG file:",r),new Error(`SVG download failed: ${r instanceof Error?r.message:"Unknown error"}`)}}saveSVG(e,t){this.downloadSVG(e,t||this.generateDefaultFilename())}}class K{constructor(){o(this,"dataExtractor");o(this,"contentGenerator");o(this,"fileHandler");this.dataExtractor=new we,this.contentGenerator=new Te,this.fileHandler=new Se}applyDefaultOptions(e){return{includeBackgroundRectangles:e.includeBackgroundRectangles??!0,drawMode:e.drawMode??"fill",strokeWidth:e.strokeWidth??1,backgroundColor:e.backgroundColor??[0,0,0,0]}}generateSVG(e,t={}){const r=this.applyDefaultOptions(t),i=this.dataExtractor.extractFramebufferData(e.pipeline),s=this.dataExtractor.extractSVGCellData(i,e.grid),a=this.contentGenerator.generateSVGContent(s,e.grid,e.font,r);return this.contentGenerator.optimizeSVGContent(a)}saveSVG(e,t={}){try{const r=this.generateSVG(e,t),i=t.filename||this.fileHandler.generateDefaultFilename();this.fileHandler.saveSVG(r,i)}catch(r){throw console.error("Failed to save SVG:",r),new Error(`SVG save failed: ${r instanceof Error?r.message:"Unknown error"}`)}}}class Re extends ${extractCharacterGrid(e,t,r,i=" "){var n;const s=[];let a=0;for(let h=0;h<t.rows;h++){const c=[];for(let u=0;u<t.cols;u++){const d=a*4,f=this.getCharacterIndex(e.characterPixels,d),g=((n=r.characters[f])==null?void 0:n.character)||i;c.push(g),a++}s.push(c)}return s}}class Ee{generateTXTContent(e,t){const r=[];for(const s of e){let a=s.join("");t.preserveTrailingSpaces||(a=a.replace(/\s+$/,"")),r.push(a)}const i=t.lineEnding==="crlf"?`\r
|
|
24
24
|
`:`
|
|
25
|
-
`;return r.join(i)}}class Ue extends L{saveTXT(e,t){try{const r=this.ensureValidFilename(t);this.downloadFile(e,r,"text/plain;charset=utf-8")}catch(r){throw console.error("Failed to save TXT file:",r),new Error(`TXT file save failed: ${r instanceof Error?r.message:"Unknown error"}`)}}ensureValidFilename(e){let t=this.sanitizeFilename(e);return t===".txt"||t.length<=4?this.generateDefaultFilename():t}}class ee{constructor(){o(this,"dataExtractor");o(this,"contentGenerator");o(this,"fileHandler");this.dataExtractor=new Re,this.contentGenerator=new Ee,this.fileHandler=new Ue}applyDefaultOptions(e){return{preserveTrailingSpaces:e.preserveTrailingSpaces??!1,lineEnding:e.lineEnding??"lf",emptyCharacter:e.emptyCharacter??" "}}generateTXT(e,t={}){const r=this.applyDefaultOptions(t),i=this.dataExtractor.extractFramebufferData(e.pipeline),s=this.dataExtractor.extractCharacterGrid(i,e.grid,e.font,r.emptyCharacter);return this.contentGenerator.generateTXTContent(s,r)}saveTXT(e,t={}){try{const r=this.generateTXT(e,t),i=t.filename||this.fileHandler.generateDefaultFilename();this.fileHandler.saveTXT(r,i)}catch(r){throw console.error("Failed to save TXT:",r),new Error(`TXT save failed: ${r instanceof Error?r.message:"Unknown error"}`)}}}class Ae extends ${captureCanvasData(e,t=1,r="transparent"){const i=e.canvas;if(t===1&&r==="transparent")return i;const s=document.createElement("canvas"),a=s.getContext("2d"),n=Math.round(i.width*t),h=Math.round(i.height*t);return s.width=n,s.height=h,r!=="transparent"&&(a.fillStyle=r,a.fillRect(0,0,n,h)),a.imageSmoothingEnabled=!1,a.drawImage(i,0,0,i.width,i.height,0,0,n,h),s}}class Me{generateImageData(e,t){const r=this.getMimeType(t.format);return t.format==="png"?e.toDataURL(r):e.toDataURL(r,t.quality)}async generateImageBlob(e,t){return new Promise((r,i)=>{const s=this.getMimeType(t.format),a=n=>{n?r(n):i(new Error(`Failed to generate ${t.format.toUpperCase()} blob`))};t.format==="png"?e.toBlob(a,s):e.toBlob(a,s,t.quality)})}getMimeType(e){switch(e){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw new Error(`Unsupported image format: ${e}`)}}}const te={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},H={png:".png",jpg:".jpg",webp:".webp"};class De extends L{saveImage(e,t,r){try{const i=H[r];typeof e=="string"?this.saveImageFromDataURL(e,this.sanitizeFilename(t)+i):this.saveImageFromBlob(e,this.sanitizeFilename(t)+i)}catch(i){throw console.error(`Failed to save ${r.toUpperCase()} image:`,i),new Error(`Image save failed: ${i instanceof Error?i.message:"Unknown error"}`)}}saveImageFromDataURL(e,t){const r=document.createElement("a");r.href=e,r.download=t,r.style.display="none",r.rel="noopener",document.body.appendChild(r),r.click(),document.body.removeChild(r)}saveImageFromBlob(e,t){const r=URL.createObjectURL(e);try{const i=document.createElement("a");i.href=r,i.download=t,i.style.display="none",i.rel="noopener",document.body.appendChild(i),i.click(),document.body.removeChild(i)}finally{URL.revokeObjectURL(r)}}validateSaveSupport(e){return e in te&&e in H}getMimeType(e){return te[e]}getFileExtension(e){return H[e]}}class Ie{constructor(){o(this,"dataExtractor");o(this,"contentGenerator");o(this,"fileHandler");this.dataExtractor=new Ae,this.contentGenerator=new Me,this.fileHandler=new De}applyDefaultOptions(e){return{format:e.format??"png",quality:e.quality??1,scale:e.scale??1,backgroundColor:e.backgroundColor??"transparent"}}validateOptions(e){if(console.log("Validating image export options:",e),!this.fileHandler.validateSaveSupport(e.format))throw new Error(`Saving '${e.format}' files is not supported`);if(e.quality<0||e.quality>1)throw new Error("Image quality must be between 0.0 and 1.0");if(e.scale<=0)throw new Error("Scale factor must be greater than 0");e.scale>10&&console.warn("Large scale factors may result in very large files and slow performance"),e.format==="jpg"&&e.backgroundColor==="transparent"&&(e.backgroundColor="black")}generateImage(e,t={}){const r=this.applyDefaultOptions(t);if(this.validateOptions(r),r.scale===1&&r.backgroundColor==="transparent")return this.contentGenerator.generateImageData(e.canvas,r);const i=this.dataExtractor.captureCanvasData(e,r.scale,r.backgroundColor);return this.contentGenerator.generateImageData(i,r)}async generateImageBlob(e,t={}){const r=this.applyDefaultOptions(t);if(this.validateOptions(r),r.scale===1&&r.backgroundColor==="transparent")return await this.contentGenerator.generateImageBlob(e.canvas,r);const i=this.dataExtractor.captureCanvasData(e,r.scale,r.backgroundColor);return await this.contentGenerator.generateImageBlob(i,r)}async saveImage(e,t={}){try{const r=await this.generateImageBlob(e,t),i=t.format??"png",s=t.filename||this.fileHandler.generateDefaultFilename();this.fileHandler.saveImage(r,s,i)}catch(r){throw console.error("Failed to save image:",r),new Error(`Image save failed: ${r instanceof Error?r.message:"Unknown error"}`)}}}class I{constructor(e=null,t={}){o(this,"captureSource");o(this,"textmodeCanvas");o(this,"_renderer");o(this,"_canvasFramebuffer");o(this,"_font");o(this,"_grid");o(this,"resizeObserver");o(this,"_mode");o(this,"_frameRateLimit");o(this,"animationFrameId",null);o(this,"lastFrameTime",0);o(this,"frameInterval");o(this,"_isLooping",!0);o(this,"_frameRate",0);o(this,"lastRenderTime",0);o(this,"_frameCount",0);o(this,"frameTimeHistory",[]);o(this,"frameTimeHistorySize",10);o(this,"_pipeline");o(this,"_isDisposed",!1);o(this,"_standalone",!1);o(this,"_drawCallback",()=>{});o(this,"_resizedCallback",()=>{});o(this,"_windowResizeListener",null);o(this,"_printDebug",!1);this.captureSource=e,this._standalone=e===null,this._mode=t.renderMode??"auto",this._frameRateLimit=t.frameRate??60,this.frameInterval=1e3/this._frameRateLimit}static async create(e=null,t={}){const r=new I(e,t),i=r._standalone?t:void 0;r.textmodeCanvas=new Z(r.captureSource,r._standalone,i),r._renderer=new he(r.textmodeCanvas.getWebGLContext());let s,a;r._standalone?(s=t.width||800,a=t.height||600):(s=r.textmodeCanvas.width||800,a=r.textmodeCanvas.height||600),r._canvasFramebuffer=r._renderer.createFramebuffer(s,a),r._font=new q(r._renderer,t.fontSize??16),await r._font.initialize(t.fontSource);const n=r._font.maxGlyphDimensions;return r._grid=new Q(r.textmodeCanvas.canvas,n.width,n.height),r._pipeline=new J(r._renderer,r._font,r._grid),r.setupEventListeners(),r.startAutoRendering(),r}setupEventListeners(){this._windowResizeListener=()=>{this._standalone?this._resizedCallback():this.resize()},window.addEventListener("resize",this._windowResizeListener),window.ResizeObserver&&this.captureSource&&!this._standalone&&(this.resizeObserver=new ResizeObserver(()=>{this.resize()}),this.resizeObserver.observe(this.captureSource))}toString(e={}){return new ee().generateTXT(this,e)}saveStrings(e={}){new ee().saveTXT(this,e)}toSVG(e={}){return new K().generateSVG(this,e)}saveSVG(e={}){new K().saveSVG(this,e)}async saveCanvas(e,t="png",r={}){await new Ie().saveImage(this.textmodeCanvas,{...r,filename:e,format:t})}async loadFont(e){return this._font.loadFont(e).then(()=>{const t=this._font.maxGlyphDimensions;this._grid.resizeCellPixelDimensions(t.width,t.height),this._pipeline.resize()})}render(){if(this.measureFrameRate(),this._frameCount++,this._isDisposed){console.warn("Cannot render: Required resources have been disposed");return}if(this._standalone?this._canvasFramebuffer&&(this._canvasFramebuffer.begin(),this._drawCallback(),this._renderer&&this._renderer.reset(),this._canvasFramebuffer&&this._canvasFramebuffer.end()):this.captureSource&&this._canvasFramebuffer&&this._canvasFramebuffer.update(this.captureSource),!this._pipeline||!this._renderer){console.warn("Cannot complete render: Pipeline or renderer has been disposed");return}if(this._pipeline.render(this._canvasFramebuffer),this._pipeline.hasEnabledConverters()?(this._renderer.background(0),this._renderer.image(this._pipeline.texture,this._grid.offsetX,this._grid.offsetY,this._pipeline.texture.width,this._pipeline.texture.height)):(this._renderer.clear(),this._renderer.image(this._canvasFramebuffer,this._grid.offsetX,this._grid.offsetY,this._canvasFramebuffer.width,this._canvasFramebuffer.height)),this._printDebug){let e=0;this._renderer.image(this._pipeline.characterFramebuffer,e,0,this._pipeline.characterFramebuffer.width,this._pipeline.characterFramebuffer.height),e+=this._pipeline.characterFramebuffer.width,this._renderer.image(this._pipeline.primaryColorFramebuffer,e,0,this._pipeline.primaryColorFramebuffer.width,this._pipeline.primaryColorFramebuffer.height),e+=this._pipeline.primaryColorFramebuffer.width,this._renderer.image(this._pipeline.secondaryColorFramebuffer,e,0,this._pipeline.secondaryColorFramebuffer.width,this._pipeline.secondaryColorFramebuffer.height),e+=this._pipeline.secondaryColorFramebuffer.width,this._renderer.image(this._pipeline.transformFramebuffer,e,0,this._pipeline.transformFramebuffer.width,this._pipeline.transformFramebuffer.height),e+=this._pipeline.transformFramebuffer.width,this._renderer.image(this._pipeline.rotationFramebuffer,e,0,this._pipeline.rotationFramebuffer.width,this._pipeline.rotationFramebuffer.height)}}resize(){this.textmodeCanvas.resize(),this._canvasFramebuffer.resize(this.textmodeCanvas.width,this.textmodeCanvas.height),this._grid.resize(),this._pipeline.resize(),this._renderer.resetViewport(),this._mode!=="manual"&&this.render()}startAutoRendering(){if(this._mode!=="auto"||!this._isLooping)return;this.lastFrameTime=performance.now();const e=t=>{if(!this._isLooping){this.animationFrameId=null;return}const r=t-this.lastFrameTime;r>=this.frameInterval&&(this.render(),this.lastFrameTime=t-r%this.frameInterval),this._isLooping&&(this.animationFrameId=requestAnimationFrame(e))};this.animationFrameId=requestAnimationFrame(e)}measureFrameRate(){const e=performance.now();if(this.lastRenderTime>0){const t=e-this.lastRenderTime;this.frameTimeHistory.push(t),this.frameTimeHistory.length>this.frameTimeHistorySize&&this.frameTimeHistory.shift();const r=this.frameTimeHistory.reduce((i,s)=>i+s,0)/this.frameTimeHistory.length;this._frameRate=1e3/r}this.lastRenderTime=e}stopAutoRendering(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}renderMode(e){this._mode!==e&&(this.stopAutoRendering(),this._mode=e,e==="auto"&&this._isLooping&&this.startAutoRendering())}frameRate(e){if(e===void 0)return this._frameRate;this._frameRateLimit=e,this.frameInterval=1e3/e,this._mode==="auto"&&this._isLooping&&(this.stopAutoRendering(),this.startAutoRendering())}noLoop(){this._isLooping&&(this._isLooping=!1,this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null))}loop(){this._isLooping||(this._isLooping=!0,this._mode==="auto"&&this.startAutoRendering())}isLooping(){return this._mode==="auto"&&this._isLooping}fontSize(e){b.validate(typeof e=="number"&&e>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:e})&&this._font.fontSize!==e&&(this._font.setFontSize(e),this._grid.resizeCellPixelDimensions(this._font.maxGlyphDimensions.width,this._font.maxGlyphDimensions.height),this._pipeline.resize(),this._renderer.resetViewport())}draw(e){this._drawCallback=e}windowResized(e){this._resizedCallback=e}resizeCanvas(e,t){this.textmodeCanvas.resize(e,t),this._canvasFramebuffer.resize(this.textmodeCanvas.width,this.textmodeCanvas.height),this._grid.resize(),this._pipeline.resize(),this._renderer.resetViewport(),this._mode!=="manual"&&this.render()}converter(e){return this._pipeline.get(e)}fill(e,t,r,i){this._renderer.fill(e,t,r,i)}stroke(e,t,r,i){this._renderer.stroke(e,t,r,i)}strokeWeight(e){this._renderer.strokeWeight(e)}noStroke(){this._renderer.noStroke()}noFill(){this._renderer.noFill()}rotate(e){this._renderer.rotate(e)}push(){this._renderer.push()}pop(){this._renderer.pop()}rect(e,t,r=1,i=1){this._renderer.rect(e,t,r,i)}line(e,t,r,i){this._renderer.line(e,t,r,i)}background(e,t=e,r=e,i=255){this._renderer.background(e,t,r,i)}createShader(e,t){return this._renderer.createShader(e,t)}createFilterShader(e){return this._renderer.createFilterShader(e)}shader(e){this._renderer.shader(e)}setUniform(e,t){this._renderer.setUniform(e,t)}destroy(){this._isDisposed=!0,this.stopAutoRendering(),this._windowResizeListener&&(window.removeEventListener("resize",this._windowResizeListener),this._windowResizeListener=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this._pipeline.dispose(),this._font.dispose(),this._grid.dispose(),this._canvasFramebuffer.dispose(),this._renderer.dispose(),this.textmodeCanvas.dispose(),this.captureSource=null,this.textmodeCanvas=null,this._renderer=null,this._canvasFramebuffer=null,this._font=null,this._grid=null,this._pipeline=null,this.resizeObserver=null,this._drawCallback=()=>{},this._resizedCallback=()=>{},this.animationFrameId=null,this.lastFrameTime=0,this.lastRenderTime=0,this._frameCount=0,this._frameRate=0,this.frameTimeHistory=[],this._isLooping=!1}debug(e){this._printDebug=e}get grid(){return this._grid}get font(){return this._font}get mode(){return this._mode}get pipeline(){return this._pipeline}get frameCount(){return this._frameCount}set frameCount(e){this._frameCount=e}get width(){return this.textmodeCanvas.width}get height(){return this.textmodeCanvas.height}get isDisposed(){return this._isDisposed}}class P{static async create(e,t={}){if(e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement)return I.create(e,t);{const r=e||{};return I.create(null,r)}}static setErrorLevel(e){b.setGlobalLevel(e)}static get version(){return"0.1.4-beta.5"}constructor(){throw new Error("Textmode is a static class and cannot be instantiated.")}}const Pe=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),Be=P.create,Ge=P.setErrorLevel,Ve=P.version;v.TextmodeCanvas=Z,v.TextmodeConversionPipeline=J,v.TextmodeErrorLevel=E,v.TextmodeFont=q,v.TextmodeGrid=Q,v.Textmodifier=I,v.converters=Ce,v.create=Be,v.default=P,v.export=Pe,v.setErrorLevel=Ge,v.textmode=P,v.version=Ve,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
25
|
+
`;return r.join(i)}}class Ue extends L{saveTXT(e,t){try{const r=this.ensureValidFilename(t);this.downloadFile(e,r,"text/plain;charset=utf-8")}catch(r){throw console.error("Failed to save TXT file:",r),new Error(`TXT file save failed: ${r instanceof Error?r.message:"Unknown error"}`)}}ensureValidFilename(e){let t=this.sanitizeFilename(e);return t===".txt"||t.length<=4?this.generateDefaultFilename():t}}class ee{constructor(){o(this,"dataExtractor");o(this,"contentGenerator");o(this,"fileHandler");this.dataExtractor=new Re,this.contentGenerator=new Ee,this.fileHandler=new Ue}applyDefaultOptions(e){return{preserveTrailingSpaces:e.preserveTrailingSpaces??!1,lineEnding:e.lineEnding??"lf",emptyCharacter:e.emptyCharacter??" "}}generateTXT(e,t={}){const r=this.applyDefaultOptions(t),i=this.dataExtractor.extractFramebufferData(e.pipeline),s=this.dataExtractor.extractCharacterGrid(i,e.grid,e.font,r.emptyCharacter);return this.contentGenerator.generateTXTContent(s,r)}saveTXT(e,t={}){try{const r=this.generateTXT(e,t),i=t.filename||this.fileHandler.generateDefaultFilename();this.fileHandler.saveTXT(r,i)}catch(r){throw console.error("Failed to save TXT:",r),new Error(`TXT save failed: ${r instanceof Error?r.message:"Unknown error"}`)}}}class Ae extends ${captureCanvasData(e,t=1,r="transparent"){const i=e.canvas;if(t===1&&r==="transparent")return i;const s=document.createElement("canvas"),a=s.getContext("2d"),n=Math.round(i.width*t),h=Math.round(i.height*t);return s.width=n,s.height=h,r!=="transparent"&&(a.fillStyle=r,a.fillRect(0,0,n,h)),a.imageSmoothingEnabled=!1,a.drawImage(i,0,0,i.width,i.height,0,0,n,h),s}}class Me{generateImageData(e,t){const r=this.getMimeType(t.format);return t.format==="png"?e.toDataURL(r):e.toDataURL(r,t.quality)}async generateImageBlob(e,t){return new Promise((r,i)=>{const s=this.getMimeType(t.format),a=n=>{n?r(n):i(new Error(`Failed to generate ${t.format.toUpperCase()} blob`))};t.format==="png"?e.toBlob(a,s):e.toBlob(a,s,t.quality)})}getMimeType(e){switch(e){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw new Error(`Unsupported image format: ${e}`)}}}const te={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},H={png:".png",jpg:".jpg",webp:".webp"};class De extends L{saveImage(e,t,r){try{const i=H[r];typeof e=="string"?this.saveImageFromDataURL(e,this.sanitizeFilename(t)+i):this.saveImageFromBlob(e,this.sanitizeFilename(t)+i)}catch(i){throw console.error(`Failed to save ${r.toUpperCase()} image:`,i),new Error(`Image save failed: ${i instanceof Error?i.message:"Unknown error"}`)}}saveImageFromDataURL(e,t){const r=document.createElement("a");r.href=e,r.download=t,r.style.display="none",r.rel="noopener",document.body.appendChild(r),r.click(),document.body.removeChild(r)}saveImageFromBlob(e,t){const r=URL.createObjectURL(e);try{const i=document.createElement("a");i.href=r,i.download=t,i.style.display="none",i.rel="noopener",document.body.appendChild(i),i.click(),document.body.removeChild(i)}finally{URL.revokeObjectURL(r)}}validateSaveSupport(e){return e in te&&e in H}getMimeType(e){return te[e]}getFileExtension(e){return H[e]}}class Ie{constructor(){o(this,"dataExtractor");o(this,"contentGenerator");o(this,"fileHandler");this.dataExtractor=new Ae,this.contentGenerator=new Me,this.fileHandler=new De}applyDefaultOptions(e){return{format:e.format??"png",quality:e.quality??1,scale:e.scale??1,backgroundColor:e.backgroundColor??"transparent"}}validateOptions(e){if(console.log("Validating image export options:",e),!this.fileHandler.validateSaveSupport(e.format))throw new Error(`Saving '${e.format}' files is not supported`);if(e.quality<0||e.quality>1)throw new Error("Image quality must be between 0.0 and 1.0");if(e.scale<=0)throw new Error("Scale factor must be greater than 0");e.scale>10&&console.warn("Large scale factors may result in very large files and slow performance"),e.format==="jpg"&&e.backgroundColor==="transparent"&&(e.backgroundColor="black")}generateImage(e,t={}){const r=this.applyDefaultOptions(t);if(this.validateOptions(r),r.scale===1&&r.backgroundColor==="transparent")return this.contentGenerator.generateImageData(e.canvas,r);const i=this.dataExtractor.captureCanvasData(e,r.scale,r.backgroundColor);return this.contentGenerator.generateImageData(i,r)}async generateImageBlob(e,t={}){const r=this.applyDefaultOptions(t);if(this.validateOptions(r),r.scale===1&&r.backgroundColor==="transparent")return await this.contentGenerator.generateImageBlob(e.canvas,r);const i=this.dataExtractor.captureCanvasData(e,r.scale,r.backgroundColor);return await this.contentGenerator.generateImageBlob(i,r)}async saveImage(e,t={}){try{const r=await this.generateImageBlob(e,t),i=t.format??"png",s=t.filename||this.fileHandler.generateDefaultFilename();this.fileHandler.saveImage(r,s,i)}catch(r){throw console.error("Failed to save image:",r),new Error(`Image save failed: ${r instanceof Error?r.message:"Unknown error"}`)}}}class I{constructor(e=null,t={}){o(this,"captureSource");o(this,"textmodeCanvas");o(this,"_renderer");o(this,"_canvasFramebuffer");o(this,"_font");o(this,"_grid");o(this,"resizeObserver");o(this,"_mode");o(this,"_frameRateLimit");o(this,"animationFrameId",null);o(this,"lastFrameTime",0);o(this,"frameInterval");o(this,"_isLooping",!0);o(this,"_frameRate",0);o(this,"lastRenderTime",0);o(this,"_frameCount",0);o(this,"frameTimeHistory",[]);o(this,"frameTimeHistorySize",10);o(this,"_pipeline");o(this,"_isDisposed",!1);o(this,"_standalone",!1);o(this,"_drawCallback",()=>{});o(this,"_resizedCallback",()=>{});o(this,"_windowResizeListener",null);o(this,"_printDebug",!1);this.captureSource=e,this._standalone=e===null,this._mode=t.renderMode??"auto",this._frameRateLimit=t.frameRate??60,this.frameInterval=1e3/this._frameRateLimit}static async create(e=null,t={}){const r=new I(e,t),i=r._standalone?t:void 0;r.textmodeCanvas=new Z(r.captureSource,r._standalone,i),r._renderer=new he(r.textmodeCanvas.getWebGLContext());let s,a;r._standalone?(s=t.width||800,a=t.height||600):(s=r.textmodeCanvas.width||800,a=r.textmodeCanvas.height||600),r._canvasFramebuffer=r._renderer.createFramebuffer(s,a),r._font=new q(r._renderer,t.fontSize??16),await r._font.initialize(t.fontSource);const n=r._font.maxGlyphDimensions;return r._grid=new Q(r.textmodeCanvas.canvas,n.width,n.height),r._pipeline=new J(r._renderer,r._font,r._grid),r.setupEventListeners(),r.startAutoRendering(),r}setupEventListeners(){this._windowResizeListener=()=>{this._standalone?this._resizedCallback():this.resize()},window.addEventListener("resize",this._windowResizeListener),window.ResizeObserver&&this.captureSource&&!this._standalone&&(this.resizeObserver=new ResizeObserver(()=>{this.resize()}),this.resizeObserver.observe(this.captureSource))}toString(e={}){return new ee().generateTXT(this,e)}saveStrings(e={}){new ee().saveTXT(this,e)}toSVG(e={}){return new K().generateSVG(this,e)}saveSVG(e={}){new K().saveSVG(this,e)}async saveCanvas(e,t="png",r={}){await new Ie().saveImage(this.textmodeCanvas,{...r,filename:e,format:t})}async loadFont(e){return this._font.loadFont(e).then(()=>{const t=this._font.maxGlyphDimensions;this._grid.resizeCellPixelDimensions(t.width,t.height),this._pipeline.resize()})}render(){if(this.measureFrameRate(),this._frameCount++,this._isDisposed){console.warn("Cannot render: Required resources have been disposed");return}if(this._standalone?this._canvasFramebuffer&&(this._canvasFramebuffer.begin(),this._drawCallback(),this._renderer&&this._renderer.reset(),this._canvasFramebuffer&&this._canvasFramebuffer.end()):this.captureSource&&this._canvasFramebuffer&&this._canvasFramebuffer.update(this.captureSource),!this._pipeline||!this._renderer){console.warn("Cannot complete render: Pipeline or renderer has been disposed");return}if(this._pipeline.render(this._canvasFramebuffer),this._pipeline.hasEnabledConverters()?(this._renderer.background(0),this._renderer.image(this._pipeline.texture,this._grid.offsetX,this._grid.offsetY,this._pipeline.texture.width,this._pipeline.texture.height)):(this._renderer.clear(),this._renderer.image(this._canvasFramebuffer,this._grid.offsetX,this._grid.offsetY,this._canvasFramebuffer.width,this._canvasFramebuffer.height)),this._printDebug){let e=0;this._renderer.image(this._pipeline.characterFramebuffer,e,0,this._pipeline.characterFramebuffer.width,this._pipeline.characterFramebuffer.height),e+=this._pipeline.characterFramebuffer.width,this._renderer.image(this._pipeline.primaryColorFramebuffer,e,0,this._pipeline.primaryColorFramebuffer.width,this._pipeline.primaryColorFramebuffer.height),e+=this._pipeline.primaryColorFramebuffer.width,this._renderer.image(this._pipeline.secondaryColorFramebuffer,e,0,this._pipeline.secondaryColorFramebuffer.width,this._pipeline.secondaryColorFramebuffer.height),e+=this._pipeline.secondaryColorFramebuffer.width,this._renderer.image(this._pipeline.transformFramebuffer,e,0,this._pipeline.transformFramebuffer.width,this._pipeline.transformFramebuffer.height),e+=this._pipeline.transformFramebuffer.width,this._renderer.image(this._pipeline.rotationFramebuffer,e,0,this._pipeline.rotationFramebuffer.width,this._pipeline.rotationFramebuffer.height)}}resize(){this.textmodeCanvas.resize(),this._canvasFramebuffer.resize(this.textmodeCanvas.width,this.textmodeCanvas.height),this._grid.resize(),this._pipeline.resize(),this._renderer.resetViewport(),this._mode!=="manual"&&this.render()}startAutoRendering(){if(this._mode!=="auto"||!this._isLooping)return;this.lastFrameTime=performance.now();const e=t=>{if(!this._isLooping){this.animationFrameId=null;return}const r=t-this.lastFrameTime;r>=this.frameInterval&&(this.render(),this.lastFrameTime=t-r%this.frameInterval),this._isLooping&&(this.animationFrameId=requestAnimationFrame(e))};this.animationFrameId=requestAnimationFrame(e)}measureFrameRate(){const e=performance.now();if(this.lastRenderTime>0){const t=e-this.lastRenderTime;this.frameTimeHistory.push(t),this.frameTimeHistory.length>this.frameTimeHistorySize&&this.frameTimeHistory.shift();const r=this.frameTimeHistory.reduce((i,s)=>i+s,0)/this.frameTimeHistory.length;this._frameRate=1e3/r}this.lastRenderTime=e}stopAutoRendering(){this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null)}renderMode(e){this._mode!==e&&(this.stopAutoRendering(),this._mode=e,e==="auto"&&this._isLooping&&this.startAutoRendering())}frameRate(e){if(e===void 0)return this._frameRate;this._frameRateLimit=e,this.frameInterval=1e3/e,this._mode==="auto"&&this._isLooping&&(this.stopAutoRendering(),this.startAutoRendering())}noLoop(){this._isLooping&&(this._isLooping=!1,this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null))}loop(){this._isLooping||(this._isLooping=!0,this._mode==="auto"&&this.startAutoRendering())}isLooping(){return this._mode==="auto"&&this._isLooping}fontSize(e){b.validate(typeof e=="number"&&e>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:e})&&this._font.fontSize!==e&&(this._font.setFontSize(e),this._grid.resizeCellPixelDimensions(this._font.maxGlyphDimensions.width,this._font.maxGlyphDimensions.height),this._pipeline.resize(),this._renderer.resetViewport())}draw(e){this._drawCallback=e}windowResized(e){this._resizedCallback=e}resizeCanvas(e,t){this.textmodeCanvas.resize(e,t),this._canvasFramebuffer.resize(this.textmodeCanvas.width,this.textmodeCanvas.height),this._grid.resize(),this._pipeline.resize(),this._renderer.resetViewport(),this._mode!=="manual"&&this.render()}converter(e){return this._pipeline.get(e)}fill(e,t,r,i){this._renderer.fill(e,t,r,i)}stroke(e,t,r,i){this._renderer.stroke(e,t,r,i)}strokeWeight(e){this._renderer.strokeWeight(e)}noStroke(){this._renderer.noStroke()}noFill(){this._renderer.noFill()}rotate(e){this._renderer.rotate(e)}push(){this._renderer.push()}pop(){this._renderer.pop()}rect(e,t,r=1,i=1){this._renderer.rect(e,t,r,i)}line(e,t,r,i){this._renderer.line(e,t,r,i)}background(e,t=e,r=e,i=255){this._renderer.background(e,t,r,i)}createShader(e,t){return this._renderer.createShader(e,t)}createFilterShader(e){return this._renderer.createFilterShader(e)}shader(e){this._renderer.shader(e)}setUniform(e,t){this._renderer.setUniform(e,t)}destroy(){this._isDisposed=!0,this.stopAutoRendering(),this._windowResizeListener&&(window.removeEventListener("resize",this._windowResizeListener),this._windowResizeListener=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this._pipeline.dispose(),this._font.dispose(),this._grid.dispose(),this._canvasFramebuffer.dispose(),this._renderer.dispose(),this.textmodeCanvas.dispose(),this.captureSource=null,this.textmodeCanvas=null,this._renderer=null,this._canvasFramebuffer=null,this._font=null,this._grid=null,this._pipeline=null,this.resizeObserver=null,this._drawCallback=()=>{},this._resizedCallback=()=>{},this.animationFrameId=null,this.lastFrameTime=0,this.lastRenderTime=0,this._frameCount=0,this._frameRate=0,this.frameTimeHistory=[],this._isLooping=!1}debug(e){this._printDebug=e}get grid(){return this._grid}get font(){return this._font}get mode(){return this._mode}get pipeline(){return this._pipeline}get frameCount(){return this._frameCount}set frameCount(e){this._frameCount=e}get width(){return this.textmodeCanvas.width}get height(){return this.textmodeCanvas.height}get isDisposed(){return this._isDisposed}}class P{static async create(e,t={}){if(e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement)return I.create(e,t);{const r=e||{};return I.create(null,r)}}static setErrorLevel(e){b.setGlobalLevel(e)}static get version(){return"0.1.4-beta.8"}constructor(){throw new Error("Textmode is a static class and cannot be instantiated.")}}const Pe=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),Be=P.create,Ge=P.setErrorLevel,Ve=P.version;v.TextmodeCanvas=Z,v.TextmodeConversionPipeline=J,v.TextmodeErrorLevel=E,v.TextmodeFont=q,v.TextmodeGrid=Q,v.Textmodifier=I,v.converters=Ce,v.create=Be,v.default=P,v.export=Pe,v.setErrorLevel=Ge,v.textmode=P,v.version=Ve,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|