textmode.js 0.1.8-beta.1 → 0.1.8-beta.2
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
|
@@ -1854,7 +1854,7 @@ class L {
|
|
|
1854
1854
|
P.u(A);
|
|
1855
1855
|
}
|
|
1856
1856
|
static get version() {
|
|
1857
|
-
return "0.1.
|
|
1857
|
+
return "0.1.8-beta.2";
|
|
1858
1858
|
}
|
|
1859
1859
|
}
|
|
1860
1860
|
const MA = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), RA = L.create, FA = L.setErrorLevel, UA = L.version;
|
package/dist/textmode.esm.min.js
CHANGED
|
@@ -1853,7 +1853,7 @@ class N {
|
|
|
1853
1853
|
C._(t);
|
|
1854
1854
|
}
|
|
1855
1855
|
static get version() {
|
|
1856
|
-
return "0.1.
|
|
1856
|
+
return "0.1.8-beta.2";
|
|
1857
1857
|
}
|
|
1858
1858
|
}
|
|
1859
1859
|
const St = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), Zt = N.create, $t = N.setErrorLevel, Bt = N.version;
|
package/dist/textmode.umd.js
CHANGED
|
@@ -61,4 +61,4 @@ void main() {\r
|
|
|
61
61
|
<g id="ascii-cells">`;for(const E of e)s+=this.Ue(E,r,B,i);return s+=this.Ye(),s}Ve(e){return e.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\n\s*\n/g,`
|
|
62
62
|
`).replace(/[ \t]+$/gm,"")}}class PA extends ${Re(e){return this.Pe(e,"image/svg+xml;charset=utf-8")}He(e,r){this.Ie(e,this.de(r)+".svg","image/svg+xml;charset=utf-8")}ze(e,r){this.He(e,r||this.me())}}class tA{constructor(){g(this,"Je");g(this,"Le");g(this,"Ke");this.Je=new CA,this.Le=new uA,this.Ke=new PA}We(e){return{includeBackgroundRectangles:e.includeBackgroundRectangles??!0,drawMode:e.drawMode??"fill",strokeWidth:e.strokeWidth??1,backgroundColor:e.backgroundColor??[0,0,0,0]}}je(e,r={}){const B=this.We(r),i=this.Je.Ce(e.pipeline),s=this.Je.ve(i,e.grid),E=this.Le.ke(s,e.grid,e.font,B);return this.Le.Ve(E)}ze(e,r={}){const B=this.je(e,r),i=r.filename||this.Ke.me();this.Ke.ze(B,i)}}class IA extends H{Ze(e,r,B,i=" "){var Q;const s=[];let E=0;for(let n=0;n<r.rows;n++){const a=[];for(let h=0;h<r.cols;h++){const l=4*E,c=this.ce(e.characterPixels,l),P=((Q=B.characters[c])==null?void 0:Q.character)||i;a.push(P),E++}s.push(a)}return s}}class dA{Ne(e,r){const B=[];for(const s of e){let E=s.join("");r.preserveTrailingSpaces||(E=E.replace(/\s+$/,"")),B.push(E)}const i=r.lineEnding==="crlf"?`\r
|
|
63
63
|
`:`
|
|
64
|
-
`;return B.join(i)}}class fA extends ${Xe(e,r){const B=this.qe(r);this.Ie(e,B,"text/plain;charset=utf-8")}qe(e){let r=this.de(e);return r===".txt"||r.length<=4?this.me():r}}class eA{constructor(){g(this,"Je");g(this,"Le");g(this,"Ke");this.Je=new IA,this.Le=new dA,this.Ke=new fA}We(e){return{preserveTrailingSpaces:e.preserveTrailingSpaces??!1,lineEnding:e.lineEnding??"lf",emptyCharacter:e.emptyCharacter??" "}}AB(e,r={}){const B=this.We(r),i=this.Je.Ce(e.pipeline),s=this.Je.Ze(i,e.grid,e.font,B.emptyCharacter);return this.Le.Ne(s,B)}Xe(e,r={}){const B=this.AB(e,r),i=r.filename||this.Ke.me();this.Ke.Xe(B,i)}}class wA extends H{tB(e,r=1,B="transparent"){const i=e.canvas;if(r===1&&B==="transparent")return i;const s=document.createElement("canvas"),E=s.getContext("2d"),Q=Math.round(i.width*r),n=Math.round(i.height*r);return s.width=Q,s.height=n,B!=="transparent"&&(E.fillStyle=B,E.fillRect(0,0,Q,n)),E.imageSmoothingEnabled=!1,E.drawImage(i,0,0,i.width,i.height,0,0,Q,n),s}}class mA{eB(e,r){const B=this.BB(r.format);return r.format==="png"?e.toDataURL(B):e.toDataURL(B,r.quality)}async QB(e,r){return new Promise((B,i)=>{const s=this.BB(r.format),E=Q=>{Q?B(Q):i(Error(`Failed to generate ${r.format.toUpperCase()} blob`))};r.format==="png"?e.toBlob(E,s):e.toBlob(E,s,r.quality)})}BB(e){switch(e){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+e)}}}const pA={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},rA={png:".png",jpg:".jpg",webp:".webp"};class xA extends ${sB(e,r,B){this.rB(e,this.de(r)+rA[B])}rB(e,r){const B=URL.createObjectURL(e);try{const i=document.createElement("a");i.href=B,i.download=r,i.style.display="none",i.rel="noopener",document.body.appendChild(i),i.click(),document.body.removeChild(i)}finally{URL.revokeObjectURL(B)}}iB(e){return e in pA&&e in rA}}class bA{constructor(){g(this,"Je");g(this,"Le");g(this,"Ke");this.Je=new wA,this.Le=new mA,this.Ke=new xA}We(e){return{format:e.format??"png",quality:e.quality??1,scale:e.scale??1,backgroundColor:e.backgroundColor??"transparent"}}EB(e){if(console.log("Validating image export options:",e),!this.Ke.iB(e.format))throw Error(`Saving '${e.format}' files is not supported`);if(e.quality<0||e.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(e.scale<=0)throw 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")}gB(e,r={}){const B=this.We(r);if(this.EB(B),B.scale===1&&B.backgroundColor==="transparent")return this.Le.eB(e.canvas,B);const i=this.Je.tB(e,B.scale,B.backgroundColor);return this.Le.eB(i,B)}async QB(e,r={}){const B=this.We(r);if(this.EB(B),B.scale===1&&B.backgroundColor==="transparent")return await this.Le.QB(e.canvas,B);const i=this.Je.tB(e,B.scale,B.backgroundColor);return await this.Le.QB(i,B)}async sB(e,r={}){const B=await this.QB(e,r),i=r.format??"png",s=r.filename||this.Ke.me();this.Ke.sB(B,s,i)}}const vA=o=>class extends o{toString(e={}){return new eA().AB({pipeline:this.oB,grid:this.zt,font:this.et},e)}saveStrings(e={}){new eA().Xe({pipeline:this.oB,grid:this.zt,font:this.et},e)}toSVG(e={}){return new tA().je(this,e)}saveSVG(e={}){new tA().ze(this,e)}async saveCanvas(e,r="png",B={}){await new bA().sB(this.bt,{...B,filename:e,format:r})}},yA=o=>class extends o{async loadFont(e){return this.et.It(e).then(()=>{const r=this.et.maxGlyphDimensions;this.zt.Gt(r.width,r.height),this.oB.$t()})}fontSize(e){if(!f.C(typeof e=="number"&&e>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:e})||this.et.fontSize===e)return;this.et.Pt(e);const r=this.et.maxGlyphDimensions;this.zt.Gt(r.width,r.height),this.oB.$t(),this.WA.UA()}},_A=o=>class extends o{addConverter(e){return this.oB.add(e)}removeConverter(e){this.oB.remove(e)}};class TA{constructor(){g(this,"WA");g(this,"et");g(this,"oB");g(this,"bt");g(this,"zt")}}class J extends function(r,...B){return B.reduce((i,s)=>s(i),r)}(TA,cA,vA,yA,_A){constructor(r=null,B={}){super();g(this,"St");g(this,"nB");g(this,"Ut");g(this,"aB");g(this,"hB");g(this,"DB",null);g(this,"lB",0);g(this,"CB");g(this,"cB",!0);g(this,"uB",0);g(this,"PB",0);g(this,"IB",0);g(this,"wB",[]);g(this,"fB",10);g(this,"dB",!1);g(this,"mB",!1);g(this,"pB",()=>{});g(this,"_B",()=>{});g(this,"vB");this.St=r,this.mB=r===null,this.aB=B.renderMode??"auto",this.hB=B.frameRate??60,this.CB=1e3/this.hB}static async create(r=null,B={}){const i=new this(r,B),s=i.mB?B:void 0;let E,Q;i.bt=new q(i.captureSource,i.mB,s),i.WA=new EA(i.bt.Rt()),i.mB?(E=B.width||800,Q=B.height||600):(E=i.bt.width||800,Q=i.bt.height||600),i.nB=i.WA.TA(E,Q),i.et=new j(i.WA,B.fontSize??16),await i.et.Ct(B.fontSource);const n=i.et.maxGlyphDimensions;return i.zt=new Z(i.bt.canvas,n.width,n.height),i.oB=new AA(i.WA,i.et,i.zt),i.bB(),i.xB(),i}bB(){this.vB=()=>{this.mB?this._B():this.yB()},window.addEventListener("resize",this.vB),window.ResizeObserver&&this.St&&!this.mB&&(this.Ut=new ResizeObserver(()=>{this.yB()}),this.Ut.observe(this.St))}render(){this.MB(),this.IB++,this.dB?console.warn("Cannot render: Required resources have been disposed"):(this.mB?(this.nB.begin(),this.pB(),this.nB.end()):this.nB.update(this.St),this.oB.hasEnabledConverters()?(this.oB.le(this.nB),this.WA.SA(0),this.WA.kA(this.oB.texture,this.zt.offsetX,this.zt.offsetY,this.oB.texture.width,this.oB.texture.height)):(this.WA.OA(),this.WA.kA(this.nB,this.zt.offsetX,this.zt.offsetY,this.nB.width,this.nB.height)))}yB(){this.bt.$t(),this.nB.resize(this.bt.width,this.bt.height),this.zt.$t(),this.oB.$t(),this.WA.UA(),this.aB!=="manual"&&this.render()}xB(){if(this.aB!=="auto"||!this.cB)return;this.lB=performance.now();const r=B=>{if(!this.cB)return void(this.DB=null);const i=B-this.lB;i>=this.CB&&(this.render(),this.lB=B-i%this.CB),this.cB&&(this.DB=requestAnimationFrame(r))};this.DB=requestAnimationFrame(r)}MB(){const r=performance.now();if(this.PB>0){const B=r-this.PB;this.wB.push(B),this.wB.length>this.fB&&this.wB.shift();const i=this.wB.reduce((s,E)=>s+E,0)/this.wB.length;this.uB=1e3/i}this.PB=r}GB(){this.DB&&(cancelAnimationFrame(this.DB),this.DB=null)}renderMode(r){this.aB!==r&&(this.GB(),this.aB=r,r==="auto"&&this.cB&&this.xB())}frameRate(r){if(r===void 0)return this.uB;this.hB=r,this.CB=1e3/r,this.aB==="auto"&&this.cB&&(this.GB(),this.xB())}noLoop(){this.cB&&(this.cB=!1,this.DB&&(cancelAnimationFrame(this.DB),this.DB=null))}loop(){this.cB||(this.cB=!0,this.aB==="auto"&&this.xB())}redraw(r=1){if(f.C(typeof r=="number"&&r>0&&Number.isInteger(r),"Redraw count must be a positive integer.",{method:"redraw",providedValue:r}))for(let B=0;B<r;B++)this.render()}isLooping(){return this.aB==="auto"&&this.cB}draw(r){this.pB=r}windowResized(r){this._B=r}resizeCanvas(r,B){this.bt.$t(r,B),this.nB.resize(this.bt.width,this.bt.height),this.zt.$t(),this.oB.$t(),this.WA.UA(),this.aB!=="manual"&&this.render()}destroy(){this.dB||(this.GB(),window.removeEventListener("resize",this.vB),this.Ut&&this.Ut.disconnect(),this.oB.S(),this.et.S(),this.nB.S(),this.WA.S(),this.dB=!0)}get grid(){return this.zt}get font(){return this.et}get mode(){return this.aB}get pipeline(){return this.oB}get frameCount(){return this.IB}set frameCount(r){this.IB=r}get width(){return this.bt.width}get height(){return this.bt.height}get canvas(){return this.bt}get isDisposed(){return this.dB}}class Y{static async create(e,r={}){if(e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement)return J.create(e,r);{const B=e||{};return J.create(null,B)}}static setErrorLevel(e){f.u(e)}static get version(){return"0.1.
|
|
64
|
+
`;return B.join(i)}}class fA extends ${Xe(e,r){const B=this.qe(r);this.Ie(e,B,"text/plain;charset=utf-8")}qe(e){let r=this.de(e);return r===".txt"||r.length<=4?this.me():r}}class eA{constructor(){g(this,"Je");g(this,"Le");g(this,"Ke");this.Je=new IA,this.Le=new dA,this.Ke=new fA}We(e){return{preserveTrailingSpaces:e.preserveTrailingSpaces??!1,lineEnding:e.lineEnding??"lf",emptyCharacter:e.emptyCharacter??" "}}AB(e,r={}){const B=this.We(r),i=this.Je.Ce(e.pipeline),s=this.Je.Ze(i,e.grid,e.font,B.emptyCharacter);return this.Le.Ne(s,B)}Xe(e,r={}){const B=this.AB(e,r),i=r.filename||this.Ke.me();this.Ke.Xe(B,i)}}class wA extends H{tB(e,r=1,B="transparent"){const i=e.canvas;if(r===1&&B==="transparent")return i;const s=document.createElement("canvas"),E=s.getContext("2d"),Q=Math.round(i.width*r),n=Math.round(i.height*r);return s.width=Q,s.height=n,B!=="transparent"&&(E.fillStyle=B,E.fillRect(0,0,Q,n)),E.imageSmoothingEnabled=!1,E.drawImage(i,0,0,i.width,i.height,0,0,Q,n),s}}class mA{eB(e,r){const B=this.BB(r.format);return r.format==="png"?e.toDataURL(B):e.toDataURL(B,r.quality)}async QB(e,r){return new Promise((B,i)=>{const s=this.BB(r.format),E=Q=>{Q?B(Q):i(Error(`Failed to generate ${r.format.toUpperCase()} blob`))};r.format==="png"?e.toBlob(E,s):e.toBlob(E,s,r.quality)})}BB(e){switch(e){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+e)}}}const pA={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},rA={png:".png",jpg:".jpg",webp:".webp"};class xA extends ${sB(e,r,B){this.rB(e,this.de(r)+rA[B])}rB(e,r){const B=URL.createObjectURL(e);try{const i=document.createElement("a");i.href=B,i.download=r,i.style.display="none",i.rel="noopener",document.body.appendChild(i),i.click(),document.body.removeChild(i)}finally{URL.revokeObjectURL(B)}}iB(e){return e in pA&&e in rA}}class bA{constructor(){g(this,"Je");g(this,"Le");g(this,"Ke");this.Je=new wA,this.Le=new mA,this.Ke=new xA}We(e){return{format:e.format??"png",quality:e.quality??1,scale:e.scale??1,backgroundColor:e.backgroundColor??"transparent"}}EB(e){if(console.log("Validating image export options:",e),!this.Ke.iB(e.format))throw Error(`Saving '${e.format}' files is not supported`);if(e.quality<0||e.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(e.scale<=0)throw 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")}gB(e,r={}){const B=this.We(r);if(this.EB(B),B.scale===1&&B.backgroundColor==="transparent")return this.Le.eB(e.canvas,B);const i=this.Je.tB(e,B.scale,B.backgroundColor);return this.Le.eB(i,B)}async QB(e,r={}){const B=this.We(r);if(this.EB(B),B.scale===1&&B.backgroundColor==="transparent")return await this.Le.QB(e.canvas,B);const i=this.Je.tB(e,B.scale,B.backgroundColor);return await this.Le.QB(i,B)}async sB(e,r={}){const B=await this.QB(e,r),i=r.format??"png",s=r.filename||this.Ke.me();this.Ke.sB(B,s,i)}}const vA=o=>class extends o{toString(e={}){return new eA().AB({pipeline:this.oB,grid:this.zt,font:this.et},e)}saveStrings(e={}){new eA().Xe({pipeline:this.oB,grid:this.zt,font:this.et},e)}toSVG(e={}){return new tA().je(this,e)}saveSVG(e={}){new tA().ze(this,e)}async saveCanvas(e,r="png",B={}){await new bA().sB(this.bt,{...B,filename:e,format:r})}},yA=o=>class extends o{async loadFont(e){return this.et.It(e).then(()=>{const r=this.et.maxGlyphDimensions;this.zt.Gt(r.width,r.height),this.oB.$t()})}fontSize(e){if(!f.C(typeof e=="number"&&e>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:e})||this.et.fontSize===e)return;this.et.Pt(e);const r=this.et.maxGlyphDimensions;this.zt.Gt(r.width,r.height),this.oB.$t(),this.WA.UA()}},_A=o=>class extends o{addConverter(e){return this.oB.add(e)}removeConverter(e){this.oB.remove(e)}};class TA{constructor(){g(this,"WA");g(this,"et");g(this,"oB");g(this,"bt");g(this,"zt")}}class J extends function(r,...B){return B.reduce((i,s)=>s(i),r)}(TA,cA,vA,yA,_A){constructor(r=null,B={}){super();g(this,"St");g(this,"nB");g(this,"Ut");g(this,"aB");g(this,"hB");g(this,"DB",null);g(this,"lB",0);g(this,"CB");g(this,"cB",!0);g(this,"uB",0);g(this,"PB",0);g(this,"IB",0);g(this,"wB",[]);g(this,"fB",10);g(this,"dB",!1);g(this,"mB",!1);g(this,"pB",()=>{});g(this,"_B",()=>{});g(this,"vB");this.St=r,this.mB=r===null,this.aB=B.renderMode??"auto",this.hB=B.frameRate??60,this.CB=1e3/this.hB}static async create(r=null,B={}){const i=new this(r,B),s=i.mB?B:void 0;let E,Q;i.bt=new q(i.captureSource,i.mB,s),i.WA=new EA(i.bt.Rt()),i.mB?(E=B.width||800,Q=B.height||600):(E=i.bt.width||800,Q=i.bt.height||600),i.nB=i.WA.TA(E,Q),i.et=new j(i.WA,B.fontSize??16),await i.et.Ct(B.fontSource);const n=i.et.maxGlyphDimensions;return i.zt=new Z(i.bt.canvas,n.width,n.height),i.oB=new AA(i.WA,i.et,i.zt),i.bB(),i.xB(),i}bB(){this.vB=()=>{this.mB?this._B():this.yB()},window.addEventListener("resize",this.vB),window.ResizeObserver&&this.St&&!this.mB&&(this.Ut=new ResizeObserver(()=>{this.yB()}),this.Ut.observe(this.St))}render(){this.MB(),this.IB++,this.dB?console.warn("Cannot render: Required resources have been disposed"):(this.mB?(this.nB.begin(),this.pB(),this.nB.end()):this.nB.update(this.St),this.oB.hasEnabledConverters()?(this.oB.le(this.nB),this.WA.SA(0),this.WA.kA(this.oB.texture,this.zt.offsetX,this.zt.offsetY,this.oB.texture.width,this.oB.texture.height)):(this.WA.OA(),this.WA.kA(this.nB,this.zt.offsetX,this.zt.offsetY,this.nB.width,this.nB.height)))}yB(){this.bt.$t(),this.nB.resize(this.bt.width,this.bt.height),this.zt.$t(),this.oB.$t(),this.WA.UA(),this.aB!=="manual"&&this.render()}xB(){if(this.aB!=="auto"||!this.cB)return;this.lB=performance.now();const r=B=>{if(!this.cB)return void(this.DB=null);const i=B-this.lB;i>=this.CB&&(this.render(),this.lB=B-i%this.CB),this.cB&&(this.DB=requestAnimationFrame(r))};this.DB=requestAnimationFrame(r)}MB(){const r=performance.now();if(this.PB>0){const B=r-this.PB;this.wB.push(B),this.wB.length>this.fB&&this.wB.shift();const i=this.wB.reduce((s,E)=>s+E,0)/this.wB.length;this.uB=1e3/i}this.PB=r}GB(){this.DB&&(cancelAnimationFrame(this.DB),this.DB=null)}renderMode(r){this.aB!==r&&(this.GB(),this.aB=r,r==="auto"&&this.cB&&this.xB())}frameRate(r){if(r===void 0)return this.uB;this.hB=r,this.CB=1e3/r,this.aB==="auto"&&this.cB&&(this.GB(),this.xB())}noLoop(){this.cB&&(this.cB=!1,this.DB&&(cancelAnimationFrame(this.DB),this.DB=null))}loop(){this.cB||(this.cB=!0,this.aB==="auto"&&this.xB())}redraw(r=1){if(f.C(typeof r=="number"&&r>0&&Number.isInteger(r),"Redraw count must be a positive integer.",{method:"redraw",providedValue:r}))for(let B=0;B<r;B++)this.render()}isLooping(){return this.aB==="auto"&&this.cB}draw(r){this.pB=r}windowResized(r){this._B=r}resizeCanvas(r,B){this.bt.$t(r,B),this.nB.resize(this.bt.width,this.bt.height),this.zt.$t(),this.oB.$t(),this.WA.UA(),this.aB!=="manual"&&this.render()}destroy(){this.dB||(this.GB(),window.removeEventListener("resize",this.vB),this.Ut&&this.Ut.disconnect(),this.oB.S(),this.et.S(),this.nB.S(),this.WA.S(),this.dB=!0)}get grid(){return this.zt}get font(){return this.et}get mode(){return this.aB}get pipeline(){return this.oB}get frameCount(){return this.IB}set frameCount(r){this.IB=r}get width(){return this.bt.width}get height(){return this.bt.height}get canvas(){return this.bt}get isDisposed(){return this.dB}}class Y{static async create(e,r={}){if(e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement)return J.create(e,r);{const B=e||{};return J.create(null,B)}}static setErrorLevel(e){f.u(e)}static get version(){return"0.1.8-beta.2"}}const GA=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),MA=Y.create,RA=Y.setErrorLevel,FA=Y.version;I.TextmodeCanvas=q,I.TextmodeConversionPipeline=AA,I.TextmodeErrorLevel=b,I.TextmodeFont=j,I.TextmodeGrid=Z,I.Textmodifier=J,I.converters=lA,I.create=MA,I.export=GA,I.setErrorLevel=RA,I.textmode=Y,I.version=FA,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):t((A=typeof globalThis<"u"?globalThis:A||self).textmode={});
|
package/dist/textmode.umd.min.js
CHANGED
|
@@ -60,4 +60,4 @@ void main() {\r
|
|
|
60
60
|
<g id="ascii-cells">`;for(const a of r)n+=this.Br(a,s,i,o);return n+=this.Ar(),n}jr(r){return r.replace(/<path[^>]*d=""[^>]*\/>/g,"").replace(/\n\s*\n/g,`
|
|
61
61
|
`).replace(/[ \t]+$/gm,"")}}class bt extends Y{Wr(r){return this.Cr(r,"image/svg+xml;charset=utf-8")}Nr(r,s){this.yr(r,this.Tr(s)+".svg","image/svg+xml;charset=utf-8")}Xr(r,s){this.Nr(r,s||this.Dr())}}class et{constructor(){c(this,"qr");c(this,"Yr");c(this,"Qr");this.qr=new mt,this.Yr=new xt,this.Qr=new bt}Zr(r){return{includeBackgroundRectangles:r.includeBackgroundRectangles??!0,drawMode:r.drawMode??"fill",strokeWidth:r.strokeWidth??1,backgroundColor:r.backgroundColor??[0,0,0,0]}}Jr(r,s={}){const i=this.Zr(s),o=this.qr.vr(r.pipeline),n=this.qr.Rr(o,r.grid),a=this.Yr.Hr(n,r.grid,r.font,i);return this.Yr.jr(a)}Xr(r,s={}){const i=this.Jr(r,s),o=s.filename||this.Qr.Dr();this.Qr.Xr(i,o)}}class Ct extends V{Kr(r,s,i,o=" "){var h;const n=[];let a=0;for(let u=0;u<s.rows;u++){const d=[];for(let f=0;f<s.cols;f++){const g=4*a,p=this.br(r.characterPixels,g),b=((h=i.characters[p])==null?void 0:h.character)||o;d.push(b),a++}n.push(d)}return n}}class wt{ts(r,s){const i=[];for(const n of r){let a=n.join("");s.preserveTrailingSpaces||(a=a.replace(/\s+$/,"")),i.push(a)}const o=s.lineEnding==="crlf"?`\r
|
|
62
62
|
`:`
|
|
63
|
-
`;return i.join(o)}}class _t extends Y{es(r,s){const i=this.rs(s);this.yr(r,i,"text/plain;charset=utf-8")}rs(r){let s=this.Tr(r);return s===".txt"||s.length<=4?this.Dr():s}}class rt{constructor(){c(this,"qr");c(this,"Yr");c(this,"Qr");this.qr=new Ct,this.Yr=new wt,this.Qr=new _t}Zr(r){return{preserveTrailingSpaces:r.preserveTrailingSpaces??!1,lineEnding:r.lineEnding??"lf",emptyCharacter:r.emptyCharacter??" "}}ss(r,s={}){const i=this.Zr(s),o=this.qr.vr(r.pipeline),n=this.qr.Kr(o,r.grid,r.font,i.emptyCharacter);return this.Yr.ts(n,i)}es(r,s={}){const i=this.ss(r,s),o=s.filename||this.Qr.Dr();this.Qr.es(i,o)}}class yt extends V{ns(r,s=1,i="transparent"){const o=r.canvas;if(s===1&&i==="transparent")return o;const n=document.createElement("canvas"),a=n.getContext("2d"),h=Math.round(o.width*s),u=Math.round(o.height*s);return n.width=h,n.height=u,i!=="transparent"&&(a.fillStyle=i,a.fillRect(0,0,h,u)),a.imageSmoothingEnabled=!1,a.drawImage(o,0,0,o.width,o.height,0,0,h,u),n}}class Tt{hs(r,s){const i=this.ls(s.format);return s.format==="png"?r.toDataURL(i):r.toDataURL(i,s.quality)}async cs(r,s){return new Promise((i,o)=>{const n=this.ls(s.format),a=h=>{h?i(h):o(Error(`Failed to generate ${s.format.toUpperCase()} blob`))};s.format==="png"?r.toBlob(a,n):r.toBlob(a,n,s.quality)})}ls(r){switch(r){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+r)}}}const Et={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},st={png:".png",jpg:".jpg",webp:".webp"};class Pt extends Y{us(r,s,i){this.fs(r,this.Tr(s)+st[i])}fs(r,s){const i=URL.createObjectURL(r);try{const o=document.createElement("a");o.href=i,o.download=s,o.style.display="none",o.rel="noopener",document.body.appendChild(o),o.click(),document.body.removeChild(o)}finally{URL.revokeObjectURL(i)}}ds(r){return r in Et&&r in st}}class Rt{constructor(){c(this,"qr");c(this,"Yr");c(this,"Qr");this.qr=new yt,this.Yr=new Tt,this.Qr=new Pt}Zr(r){return{format:r.format??"png",quality:r.quality??1,scale:r.scale??1,backgroundColor:r.backgroundColor??"transparent"}}ps(r){if(console.log("Validating image export options:",r),!this.Qr.ds(r.format))throw Error(`Saving '${r.format}' files is not supported`);if(r.quality<0||r.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(r.scale<=0)throw Error("Scale factor must be greater than 0");r.scale>10&&console.warn("Large scale factors may result in very large files and slow performance"),r.format==="jpg"&&r.backgroundColor==="transparent"&&(r.backgroundColor="black")}gs(r,s={}){const i=this.Zr(s);if(this.ps(i),i.scale===1&&i.backgroundColor==="transparent")return this.Yr.hs(r.canvas,i);const o=this.qr.ns(r,i.scale,i.backgroundColor);return this.Yr.hs(o,i)}async cs(r,s={}){const i=this.Zr(s);if(this.ps(i),i.scale===1&&i.backgroundColor==="transparent")return await this.Yr.cs(r.canvas,i);const o=this.qr.ns(r,i.scale,i.backgroundColor);return await this.Yr.cs(o,i)}async us(r,s={}){const i=await this.cs(r,s),o=s.format??"png",n=s.filename||this.Qr.Dr();this.Qr.us(i,n,o)}}const Mt=l=>class extends l{toString(r={}){return new rt().ss({pipeline:this._s,grid:this.je,font:this.oe},r)}saveStrings(r={}){new rt().es({pipeline:this._s,grid:this.je,font:this.oe},r)}toSVG(r={}){return new et().Jr(this,r)}saveSVG(r={}){new et().Xr(this,r)}async saveCanvas(r,s="png",i={}){await new Rt().us(this.Me,{...i,filename:r,format:s})}},Ft=l=>class extends l{async loadFont(r){return this.oe.Ce(r).then(()=>{const s=this.oe.maxGlyphDimensions;this.je.ke(s.width,s.height),this._s.Pe()})}fontSize(r){if(!_.p(typeof r=="number"&&r>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:r})||this.oe.fontSize===r)return;this.oe.we(r);const s=this.oe.maxGlyphDimensions;this.je.ke(s.width,s.height),this._s.Pe(),this.Zt.Bt()}},At=l=>class extends l{addConverter(r){return this._s.add(r)}removeConverter(r){this._s.remove(r)}};class Dt{constructor(){c(this,"Zt");c(this,"oe");c(this,"_s");c(this,"Me");c(this,"je")}}class G extends function(s,...i){return i.reduce((o,n)=>n(o),s)}(Dt,pt,Mt,Ft,At){constructor(s=null,i={}){super();c(this,"Ae");c(this,"vs");c(this,"Ee");c(this,"bs");c(this,"ws");c(this,"Cs",null);c(this,"$s",0);c(this,"Fs");c(this,"Ts",!0);c(this,"Ds",0);c(this,"Ms",0);c(this,"Ss",0);c(this,"Rs",[]);c(this,"Vs",10);c(this,"ks",!1);c(this,"zs",!1);c(this,"Is",()=>{});c(this,"Ps",()=>{});c(this,"Us");this.Ae=s,this.zs=s===null,this.bs=i.renderMode??"auto",this.ws=i.frameRate??60,this.Fs=1e3/this.ws}static async create(s=null,i={}){const o=new this(s,i),n=o.zs?i:void 0;let a,h;o.Me=new K(o.captureSource,o.zs,n),o.Zt=new at(o.Me.Be()),o.zs?(a=i.width||800,h=i.height||600):(a=o.Me.width||800,h=o.Me.height||600),o.vs=o.Zt.Et(a,h),o.oe=new Q(o.Zt,i.fontSize??16),await o.oe.ve(i.fontSource);const u=o.oe.maxGlyphDimensions;return o.je=new J(o.Me.canvas,u.width,u.height),o._s=new tt(o.Zt,o.oe,o.je),o.As(),o.Gs(),o}As(){this.Us=()=>{this.zs?this.Ps():this.Es()},window.addEventListener("resize",this.Us),window.ResizeObserver&&this.Ae&&!this.zs&&(this.Ee=new ResizeObserver(()=>{this.Es()}),this.Ee.observe(this.Ae))}render(){this.Ls(),this.Ss++,this.ks?console.warn("Cannot render: Required resources have been disposed"):(this.zs?(this.vs.begin(),this.Is(),this.vs.end()):this.vs.update(this.Ae),this._s.hasEnabledConverters()?(this._s._r(this.vs),this.Zt.Lt(0),this.Zt.Ht(this._s.texture,this.je.offsetX,this.je.offsetY,this._s.texture.width,this._s.texture.height)):(this.Zt.Ot(),this.Zt.Ht(this.vs,this.je.offsetX,this.je.offsetY,this.vs.width,this.vs.height)))}Es(){this.Me.Pe(),this.vs.resize(this.Me.width,this.Me.height),this.je.Pe(),this._s.Pe(),this.Zt.Bt(),this.bs!=="manual"&&this.render()}Gs(){if(this.bs!=="auto"||!this.Ts)return;this.$s=performance.now();const s=i=>{if(!this.Ts)return void(this.Cs=null);const o=i-this.$s;o>=this.Fs&&(this.render(),this.$s=i-o%this.Fs),this.Ts&&(this.Cs=requestAnimationFrame(s))};this.Cs=requestAnimationFrame(s)}Ls(){const s=performance.now();if(this.Ms>0){const i=s-this.Ms;this.Rs.push(i),this.Rs.length>this.Vs&&this.Rs.shift();const o=this.Rs.reduce((n,a)=>n+a,0)/this.Rs.length;this.Ds=1e3/o}this.Ms=s}Os(){this.Cs&&(cancelAnimationFrame(this.Cs),this.Cs=null)}renderMode(s){this.bs!==s&&(this.Os(),this.bs=s,s==="auto"&&this.Ts&&this.Gs())}frameRate(s){if(s===void 0)return this.Ds;this.ws=s,this.Fs=1e3/s,this.bs==="auto"&&this.Ts&&(this.Os(),this.Gs())}noLoop(){this.Ts&&(this.Ts=!1,this.Cs&&(cancelAnimationFrame(this.Cs),this.Cs=null))}loop(){this.Ts||(this.Ts=!0,this.bs==="auto"&&this.Gs())}redraw(s=1){if(_.p(typeof s=="number"&&s>0&&Number.isInteger(s),"Redraw count must be a positive integer.",{method:"redraw",providedValue:s}))for(let i=0;i<s;i++)this.render()}isLooping(){return this.bs==="auto"&&this.Ts}draw(s){this.Is=s}windowResized(s){this.Ps=s}resizeCanvas(s,i){this.Me.Pe(s,i),this.vs.resize(this.Me.width,this.Me.height),this.je.Pe(),this._s.Pe(),this.Zt.Bt(),this.bs!=="manual"&&this.render()}destroy(){this.ks||(this.Os(),window.removeEventListener("resize",this.Us),this.Ee&&this.Ee.disconnect(),this._s.P(),this.oe.P(),this.vs.P(),this.Zt.P(),this.ks=!0)}get grid(){return this.je}get font(){return this.oe}get mode(){return this.bs}get pipeline(){return this._s}get frameCount(){return this.Ss}set frameCount(s){this.Ss=s}get width(){return this.Me.width}get height(){return this.Me.height}get canvas(){return this.Me}get isDisposed(){return this.ks}}class j{static async create(r,s={}){if(r instanceof HTMLCanvasElement||r instanceof HTMLVideoElement)return G.create(r,s);{const i=r||{};return G.create(null,i)}}static setErrorLevel(r){_._(r)}static get version(){return"0.1.
|
|
63
|
+
`;return i.join(o)}}class _t extends Y{es(r,s){const i=this.rs(s);this.yr(r,i,"text/plain;charset=utf-8")}rs(r){let s=this.Tr(r);return s===".txt"||s.length<=4?this.Dr():s}}class rt{constructor(){c(this,"qr");c(this,"Yr");c(this,"Qr");this.qr=new Ct,this.Yr=new wt,this.Qr=new _t}Zr(r){return{preserveTrailingSpaces:r.preserveTrailingSpaces??!1,lineEnding:r.lineEnding??"lf",emptyCharacter:r.emptyCharacter??" "}}ss(r,s={}){const i=this.Zr(s),o=this.qr.vr(r.pipeline),n=this.qr.Kr(o,r.grid,r.font,i.emptyCharacter);return this.Yr.ts(n,i)}es(r,s={}){const i=this.ss(r,s),o=s.filename||this.Qr.Dr();this.Qr.es(i,o)}}class yt extends V{ns(r,s=1,i="transparent"){const o=r.canvas;if(s===1&&i==="transparent")return o;const n=document.createElement("canvas"),a=n.getContext("2d"),h=Math.round(o.width*s),u=Math.round(o.height*s);return n.width=h,n.height=u,i!=="transparent"&&(a.fillStyle=i,a.fillRect(0,0,h,u)),a.imageSmoothingEnabled=!1,a.drawImage(o,0,0,o.width,o.height,0,0,h,u),n}}class Tt{hs(r,s){const i=this.ls(s.format);return s.format==="png"?r.toDataURL(i):r.toDataURL(i,s.quality)}async cs(r,s){return new Promise((i,o)=>{const n=this.ls(s.format),a=h=>{h?i(h):o(Error(`Failed to generate ${s.format.toUpperCase()} blob`))};s.format==="png"?r.toBlob(a,n):r.toBlob(a,n,s.quality)})}ls(r){switch(r){case"png":return"image/png";case"jpg":return"image/jpeg";case"webp":return"image/webp";default:throw Error("Unsupported image format: "+r)}}}const Et={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},st={png:".png",jpg:".jpg",webp:".webp"};class Pt extends Y{us(r,s,i){this.fs(r,this.Tr(s)+st[i])}fs(r,s){const i=URL.createObjectURL(r);try{const o=document.createElement("a");o.href=i,o.download=s,o.style.display="none",o.rel="noopener",document.body.appendChild(o),o.click(),document.body.removeChild(o)}finally{URL.revokeObjectURL(i)}}ds(r){return r in Et&&r in st}}class Rt{constructor(){c(this,"qr");c(this,"Yr");c(this,"Qr");this.qr=new yt,this.Yr=new Tt,this.Qr=new Pt}Zr(r){return{format:r.format??"png",quality:r.quality??1,scale:r.scale??1,backgroundColor:r.backgroundColor??"transparent"}}ps(r){if(console.log("Validating image export options:",r),!this.Qr.ds(r.format))throw Error(`Saving '${r.format}' files is not supported`);if(r.quality<0||r.quality>1)throw Error("Image quality must be between 0.0 and 1.0");if(r.scale<=0)throw Error("Scale factor must be greater than 0");r.scale>10&&console.warn("Large scale factors may result in very large files and slow performance"),r.format==="jpg"&&r.backgroundColor==="transparent"&&(r.backgroundColor="black")}gs(r,s={}){const i=this.Zr(s);if(this.ps(i),i.scale===1&&i.backgroundColor==="transparent")return this.Yr.hs(r.canvas,i);const o=this.qr.ns(r,i.scale,i.backgroundColor);return this.Yr.hs(o,i)}async cs(r,s={}){const i=this.Zr(s);if(this.ps(i),i.scale===1&&i.backgroundColor==="transparent")return await this.Yr.cs(r.canvas,i);const o=this.qr.ns(r,i.scale,i.backgroundColor);return await this.Yr.cs(o,i)}async us(r,s={}){const i=await this.cs(r,s),o=s.format??"png",n=s.filename||this.Qr.Dr();this.Qr.us(i,n,o)}}const Mt=l=>class extends l{toString(r={}){return new rt().ss({pipeline:this._s,grid:this.je,font:this.oe},r)}saveStrings(r={}){new rt().es({pipeline:this._s,grid:this.je,font:this.oe},r)}toSVG(r={}){return new et().Jr(this,r)}saveSVG(r={}){new et().Xr(this,r)}async saveCanvas(r,s="png",i={}){await new Rt().us(this.Me,{...i,filename:r,format:s})}},Ft=l=>class extends l{async loadFont(r){return this.oe.Ce(r).then(()=>{const s=this.oe.maxGlyphDimensions;this.je.ke(s.width,s.height),this._s.Pe()})}fontSize(r){if(!_.p(typeof r=="number"&&r>0,"Font size must be a positive number greater than 0.",{method:"fontSize",providedValue:r})||this.oe.fontSize===r)return;this.oe.we(r);const s=this.oe.maxGlyphDimensions;this.je.ke(s.width,s.height),this._s.Pe(),this.Zt.Bt()}},At=l=>class extends l{addConverter(r){return this._s.add(r)}removeConverter(r){this._s.remove(r)}};class Dt{constructor(){c(this,"Zt");c(this,"oe");c(this,"_s");c(this,"Me");c(this,"je")}}class G extends function(s,...i){return i.reduce((o,n)=>n(o),s)}(Dt,pt,Mt,Ft,At){constructor(s=null,i={}){super();c(this,"Ae");c(this,"vs");c(this,"Ee");c(this,"bs");c(this,"ws");c(this,"Cs",null);c(this,"$s",0);c(this,"Fs");c(this,"Ts",!0);c(this,"Ds",0);c(this,"Ms",0);c(this,"Ss",0);c(this,"Rs",[]);c(this,"Vs",10);c(this,"ks",!1);c(this,"zs",!1);c(this,"Is",()=>{});c(this,"Ps",()=>{});c(this,"Us");this.Ae=s,this.zs=s===null,this.bs=i.renderMode??"auto",this.ws=i.frameRate??60,this.Fs=1e3/this.ws}static async create(s=null,i={}){const o=new this(s,i),n=o.zs?i:void 0;let a,h;o.Me=new K(o.captureSource,o.zs,n),o.Zt=new at(o.Me.Be()),o.zs?(a=i.width||800,h=i.height||600):(a=o.Me.width||800,h=o.Me.height||600),o.vs=o.Zt.Et(a,h),o.oe=new Q(o.Zt,i.fontSize??16),await o.oe.ve(i.fontSource);const u=o.oe.maxGlyphDimensions;return o.je=new J(o.Me.canvas,u.width,u.height),o._s=new tt(o.Zt,o.oe,o.je),o.As(),o.Gs(),o}As(){this.Us=()=>{this.zs?this.Ps():this.Es()},window.addEventListener("resize",this.Us),window.ResizeObserver&&this.Ae&&!this.zs&&(this.Ee=new ResizeObserver(()=>{this.Es()}),this.Ee.observe(this.Ae))}render(){this.Ls(),this.Ss++,this.ks?console.warn("Cannot render: Required resources have been disposed"):(this.zs?(this.vs.begin(),this.Is(),this.vs.end()):this.vs.update(this.Ae),this._s.hasEnabledConverters()?(this._s._r(this.vs),this.Zt.Lt(0),this.Zt.Ht(this._s.texture,this.je.offsetX,this.je.offsetY,this._s.texture.width,this._s.texture.height)):(this.Zt.Ot(),this.Zt.Ht(this.vs,this.je.offsetX,this.je.offsetY,this.vs.width,this.vs.height)))}Es(){this.Me.Pe(),this.vs.resize(this.Me.width,this.Me.height),this.je.Pe(),this._s.Pe(),this.Zt.Bt(),this.bs!=="manual"&&this.render()}Gs(){if(this.bs!=="auto"||!this.Ts)return;this.$s=performance.now();const s=i=>{if(!this.Ts)return void(this.Cs=null);const o=i-this.$s;o>=this.Fs&&(this.render(),this.$s=i-o%this.Fs),this.Ts&&(this.Cs=requestAnimationFrame(s))};this.Cs=requestAnimationFrame(s)}Ls(){const s=performance.now();if(this.Ms>0){const i=s-this.Ms;this.Rs.push(i),this.Rs.length>this.Vs&&this.Rs.shift();const o=this.Rs.reduce((n,a)=>n+a,0)/this.Rs.length;this.Ds=1e3/o}this.Ms=s}Os(){this.Cs&&(cancelAnimationFrame(this.Cs),this.Cs=null)}renderMode(s){this.bs!==s&&(this.Os(),this.bs=s,s==="auto"&&this.Ts&&this.Gs())}frameRate(s){if(s===void 0)return this.Ds;this.ws=s,this.Fs=1e3/s,this.bs==="auto"&&this.Ts&&(this.Os(),this.Gs())}noLoop(){this.Ts&&(this.Ts=!1,this.Cs&&(cancelAnimationFrame(this.Cs),this.Cs=null))}loop(){this.Ts||(this.Ts=!0,this.bs==="auto"&&this.Gs())}redraw(s=1){if(_.p(typeof s=="number"&&s>0&&Number.isInteger(s),"Redraw count must be a positive integer.",{method:"redraw",providedValue:s}))for(let i=0;i<s;i++)this.render()}isLooping(){return this.bs==="auto"&&this.Ts}draw(s){this.Is=s}windowResized(s){this.Ps=s}resizeCanvas(s,i){this.Me.Pe(s,i),this.vs.resize(this.Me.width,this.Me.height),this.je.Pe(),this._s.Pe(),this.Zt.Bt(),this.bs!=="manual"&&this.render()}destroy(){this.ks||(this.Os(),window.removeEventListener("resize",this.Us),this.Ee&&this.Ee.disconnect(),this._s.P(),this.oe.P(),this.vs.P(),this.Zt.P(),this.ks=!0)}get grid(){return this.je}get font(){return this.oe}get mode(){return this.bs}get pipeline(){return this._s}get frameCount(){return this.Ss}set frameCount(s){this.Ss=s}get width(){return this.Me.width}get height(){return this.Me.height}get canvas(){return this.Me}get isDisposed(){return this.ks}}class j{static async create(r,s={}){if(r instanceof HTMLCanvasElement||r instanceof HTMLVideoElement)return G.create(r,s);{const i=r||{};return G.create(null,i)}}static setErrorLevel(r){_._(r)}static get version(){return"0.1.8-beta.2"}}const Ut=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),St=j.create,Zt=j.setErrorLevel,$t=j.version;C.TextmodeCanvas=K,C.TextmodeConversionPipeline=tt,C.TextmodeErrorLevel=R,C.TextmodeFont=Q,C.TextmodeGrid=J,C.Textmodifier=G,C.converters=gt,C.create=St,C.export=Ut,C.setErrorLevel=Zt,C.textmode=j,C.version=$t,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})},typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):e((t=typeof globalThis<"u"?globalThis:t||self).textmode={});
|