textmode.figlet.js 1.0.3-beta.1 → 1.0.4-beta.1
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/README.md +0 -10
- package/dist/textmode.figlet.esm.js +1 -1
- package/dist/textmode.figlet.umd.js +1 -1
- package/dist/types/extensions/index.d.ts +1 -1
- package/dist/types/extensions/textmodifier.d.ts +7 -8
- package/dist/types/plugin/FigletPlugin.d.ts +5 -0
- package/dist/types/state/figletState.d.ts +0 -4
- package/package.json +24 -71
package/README.md
CHANGED
|
@@ -93,13 +93,3 @@ Contribution details and profile links are maintained on the [textmode.js contri
|
|
|
93
93
|
## License
|
|
94
94
|
|
|
95
95
|
`textmode.figlet.js` is licensed under the [MIT License](./LICENSE).
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
<div align="center">
|
|
100
|
-
|
|
101
|
-
<br />
|
|
102
|
-
|
|
103
|
-
**[↑ back to top](#textmodefigletjs)**
|
|
104
|
-
|
|
105
|
-
</div>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{color as t}from"textmode.js";var e=class t extends Error{constructor(e,n){super(t.formatMessage(e,n)),this.name="FigletError"}static formatMessage(e,n){return n&&0!==Object.keys(n).length?`${e}\n\nContext:${Object.entries(n).map(([e,n])=>`\n - ${e}: ${t.formatValue(n)}`).join("")}`:e}static formatValue(e){return null===e?"null":void 0===e?"undefined":"string"==typeof e?`"${e}"`:"number"==typeof e||"boolean"==typeof e?String(e):Array.isArray(e)?`[${e.map(e=>t.formatValue(e)).join(", ")}]`:"object"==typeof e?JSON.stringify(e):String(e)}},n=[...Array.from({length:95},(t,e)=>e+32),196,214,220,228,246,252,223],r=class{static t(t){if(0===t.length)throw new e("Cannot parse an empty FIGfont file.");const n=t.replace(/\r\n?/g,"\n").split("\n"),r=n[0];if(!r)throw new e("Missing FIGfont header line.");const i=this.i(r);let s=1+i.commentLines;if(s>n.length)throw new e("FIGfont comment line count exceeds file length.",{commentLines:i.commentLines,totalLines:n.length});const o=/* @__PURE__ */new Map;return s=this.o(n,s,i,o),this.l(n,s,i,o),{header:i,characters:o}}static i(t){const n=t.trim().split(/\s+/),r=n[0]??"";if(r.length<6)throw new e("Invalid FIGfont header token.",{headerToken:r});const i=r.slice(0,5),s=r.slice(5);if("flf2a"!==i)throw new e("Unsupported FIGfont signature.",{signature:i});if(1!==s.length)throw new e("FIGfont hardblank must be a single character.",{hardblank:s});if(n.length<6)throw new e("Incomplete FIGfont header.",{headerLine:t});return{signature:i,hardblank:s,height:this.h(n[1],"height"),baseline:this.h(n[2],"baseline"),maxLength:this.h(n[3],"maxLength"),oldLayout:this.h(n[4],"oldLayout"),commentLines:this.h(n[5],"commentLines"),printDirection:this.h(n[6]??"0","printDirection"),fullLayout:this.h(n[7]??"0","fullLayout"),codetagCount:this.h(n[8]??"0","codetagCount")}}static o(t,e,r,i){let s=e;for(const o of n){const e=this.u(t,s,r.height,o);i.set(o,e),s+=r.height}return s}static l(t,e,n,r){let i=e;for(;i<t.length;){const e=t[i]?.trim()??"";if(0===e.length){i+=1;continue}const s=this._(e);i+=1;const o=this.u(t,i,n.height,s);r.set(s,o),i+=n.height}}static u(t,n,r,i){if(n+r>t.length)throw new e("Unexpected end of FIGfont character data.",{codePoint:i,startIndex:n,height:r,totalLines:t.length});const s=[];let o=0;for(let a=0;a<r;a+=1){const r=t[n+a]??"";if(0===r.length)throw new e("Encountered an empty FIGcharacter row.",{codePoint:i,row:a,startIndex:n});const c=r.at(-1);if(!c)throw new e("Failed to determine FIGcharacter endmark.",{codePoint:i,row:a});const l=r.replace(new RegExp(`${this.escapeForRegExp(c)}+$`),"");s.push(l),o=Math.max(o,l.length)}return{code:i,lines:s,width:o}}static _(t){const n=t.split(/\s+/,1)[0];if(/^[-+]?0x[0-9a-f]+$/i.test(n))return Number.parseInt(n,16);if(/^[-+]?0[0-7]+$/.test(n))return Number.parseInt(n,8);if(/^[-+]?\d+$/.test(n))return Number.parseInt(n,10);throw new e("Invalid FIGfont code tag.",{codetagLine:t})}static h(t,n){if(!/^-?\d+$/.test(t))throw new e("Invalid FIGfont header value.",{field:n,token:t});return Number.parseInt(t,10)}static escapeForRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}},i=class{static RULE_EQUAL_CHARACTER=1;static RULE_UNDERSCORE=2;static RULE_HIERARCHY=4;static RULE_OPPOSITE_PAIR=8;static RULE_BIG_X=16;static RULE_HARDBLANK=32;static VERTICAL_RULE_EQUAL_CHARACTER=256;static VERTICAL_RULE_UNDERSCORE=512;static VERTICAL_RULE_HIERARCHY=1024;static VERTICAL_RULE_HORIZONTAL_LINE=2048;static VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH=4096;static p(t){return 0!==t.fullLayout?63&t.fullLayout:t.oldLayout>0?63&t.oldLayout:0}static m(t){return 7936&t.fullLayout}static I(t,e,n,r){return" "===t?e:" "===e?t:0===r?this.L(t,e,n):(0!==(r&this.RULE_EQUAL_CHARACTER)?this.C(t,e,n):null)??(0!==(r&this.RULE_UNDERSCORE)?this.R(t,e):null)??(0!==(r&this.RULE_HIERARCHY)?this.v(t,e):null)??(0!==(r&this.RULE_OPPOSITE_PAIR)?this.A(t,e):null)??(0!==(r&this.RULE_BIG_X)?this.F(t,e):null)??(0!==(r&this.RULE_HARDBLANK)?this.T(t,e,n):null)}static L(t,e,n){return" "===t?e:" "===e?t:e}static U(t,e,n){return" "===t?e:" "===e?t:0===n?this.L(t,e," "):(0!==(n&this.VERTICAL_RULE_EQUAL_CHARACTER)?this.C(t,e," "):null)??(0!==(n&this.VERTICAL_RULE_UNDERSCORE)?this.R(t,e):null)??(0!==(n&this.VERTICAL_RULE_HIERARCHY)?this.v(t,e):null)??(0!==(n&this.VERTICAL_RULE_HORIZONTAL_LINE)?this.S(t,e):null)??(0!==(n&this.VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH)?this.$(t,e):null)}static C(t,e,n){return t===e&&t!==n?t:null}static R(t,e){const n="|/\\[]{}()<>";return"_"===t&&n.includes(e)?e:"_"===e&&n.includes(t)?t:null}static v(t,e){const n=["|","/\\","[]","{}","()","<>"],r=n.findIndex(e=>e.includes(t)),i=n.findIndex(t=>t.includes(e));return-1===r||-1===i||r===i?null:r>i?t:e}static A(t,e){return["[]","][","{}","}{","()",")("].includes(`${t}${e}`)?"|":null}static F(t,e){const n=`${t}${e}`;return"/\\"===n?"|":"\\/"===n?"Y":"><"===n?"X":null}static T(t,e,n){return t===n&&e===n?n:null}static S(t,e){const n=`${t}${e}`;return"-_"===n||"_-"===n?"=":null}static $(t,e){return"|"===t&&"|"===e?"|":null}},s=class{H;k;M;constructor(t){this.H=t,this.k=i.p(t),this.M=i.m(t)}G(t,e){const n=t.map((t,e)=>({inputIndex:e,inputChar:String.fromCodePoint(t.code)})),r=this.N(t,n,e,0),i=Array.from({length:r.rows},()=>Array.from({length:r.cols},()=>" "));for(const s of r.cells)i[s.row][s.col]=s.char;return i}N(t,e,n,r){if(0===t.length)return{lineIndex:r,cells:[],cols:0,rows:this.H.height};let s=this.O(t[0],e[0],r),o=t[0].width;for(let a=1;a<t.length;a+=1){const c=t[a],l=e[a]??{inputIndex:a,inputChar:String.fromCodePoint(c.code)},h=o-this.V(s,o,c,n),u=Math.max(o,h+c.width),f=s.map(t=>Array.from({length:u},(e,n)=>t[n]));for(let t=0;t<this.H.height;t+=1){const e=c.lines[t]??"",n=f[t];for(let s=0;s<c.width;s+=1){const o=e[s]??" ";if(" "===o)continue;const a=h+s,u=n[a],f=this.P(a,t,s,r,c,l,o);if(!u){n[a]=f;continue}const d=i.I(u.char,o,this.H.hardblank,this.k);n[a]=this.B(u,f,d??o)}}s=f,o=u}return this.D(s,o,r)}j(t,e){if(0===t.length)return{cells:[],lines:[],cols:0,rows:0};let n=this.W(t[0]),r=t[0].cols,s=t[0].rows;const o=[this.q(t[0],0)];for(let a=1;a<t.length;a+=1){const c=t[a],l=s-this.X(n,s,r,c,e),h=Math.max(r,c.cols),u=Math.max(s,l+c.rows),f=Array.from({length:u},(t,e)=>Array.from({length:h},(t,r)=>n[e]?.[r]));for(const t of c.cells){const e=l+t.row,n=t.col,r=f[e]?.[n];if(!r){f[e][n]={...t,row:e};continue}const s=i.U(r.char,t.char,this.M);f[e][n]=this.B(r,{...t,row:e},s??t.char)}n=f,r=h,s=u,o.push(this.q(c,l))}return this.Y(n,r,s,o)}V(t,e,n,r){if("full"===r)return 0;for(let i=e;i>=0;i-=1){let s=!0;for(let o=0;o<this.H.height&&s;o+=1){const a=t[o]??[],c=n.lines[o]??"";for(let t=0;t<i;t+=1){const n=a[e-i+t]?.char??" ",o=c[t]??" ";if(!this.J(n,o,r)){s=!1;break}}}if(s)return i}return 0}J(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==i.I(t,e,this.H.hardblank,this.k)}O(t,e={inputIndex:0,inputChar:String.fromCodePoint(t.code)},n=0){return Array.from({length:this.H.height},(r,i)=>{const s=t.lines[i]??"";return Array.from({length:t.width},(r,o)=>{const a=s[o]??" ";return" "===a?void 0:this.P(o,i,o,n,t,e,a)})})}P(t,e,n,r,i,s,o){return{char:o,col:t,row:e,inputIndex:s.inputIndex,inputChar:s.inputChar,figCharCode:i.code,subRow:e,subCol:n,lineIndex:r}}B(t,e,n){return n===t.char?t:{...e,char:n}}D(t,e,n){const r=[];for(let i=0;i<this.H.height;i+=1){const s=t[i]??[];for(let t=0;t<e;t+=1){const e=s[t];e&&e.char!==this.H.hardblank&&r.push({...e,col:t,row:i,lineIndex:n})}}return{lineIndex:n,cells:r,cols:e,rows:this.H.height}}X(t,e,n,r,i){if("full"===i)return 0;const s=this.W(r),o=Math.min(e,r.rows),a=Math.max(n,r.cols);for(let c=o;c>=0;c-=1){let n=!0;for(let r=0;r<c&&n;r+=1){const o=t[e-c+r]??[],l=s[r]??[];for(let t=0;t<a;t+=1){const e=o[t]?.char??" ",r=l[t]?.char??" ";if(!this.K(e,r,i)){n=!1;break}}}if(n)return c}return 0}K(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==i.U(t,e,this.M)}W(t){const e=Array.from({length:t.rows},()=>Array.from({length:t.cols},()=>{}));for(const n of t.cells)e[n.row][n.col]=n;return e}q(t,e){return{...t,cells:t.cells.map(t=>({...t,row:t.row+e}))}}Y(t,e,n,r){const i=[];for(let s=0;s<n;s+=1)for(let n=0;n<e;n+=1){const e=t[s]?.[n];e&&i.push({...e,row:s,col:n})}return{cells:i,lines:r,cols:e,rows:n}}},o=class{Z=/* @__PURE__ */new Set;tt(t){this.Z.add(t)}dispose(){for(const t of this.Z)t();this.Z.clear()}},a=class t extends o{et;H;nt;rt;constructor(t,e,n){super(),this.et=t,this.H=e,this.nt=n,this.rt=new s(e)}static async it(t){const n=await fetch(t);if(!n.ok)throw new e("Failed to load FIGfont file.",{source:String(t),status:n.status,statusText:n.statusText});const r=await n.text();return this.st(this.ot(t),r)}static st(e,n){const i=r.t(n);return new t(e,i.header,i.characters)}getCharacter(t){const e="number"==typeof t?t:Array.from(t)[0]?.codePointAt(0);if(void 0!==e)return c(this.nt.get(e))}planText(t,e={}){const n=e.horizontalLayout??this.defaultLayout,r=e.verticalLayout??this.defaultVerticalLayout,i=this.ct(e.direction),s=this.lt(t).map(t=>this.ht(t,i)).flatMap(t=>this.ut(t,n,e)).map((t,e)=>{const r=this.ft(t);return this.rt.N(r.map(t=>t.figChar),r.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),n,e)}),o=this.rt.j(s,r);return{cells:o.cells,lines:o.lines,cols:o.cols,rows:o.rows,direction:i}}renderText(t,e={}){const n=this.planText(t,e),r=Array.from({length:n.rows},()=>Array.from({length:n.cols},()=>" "));for(const i of n.cells)r[i.row][i.col]=i.char;return{grid:r,cols:n.cols,rows:n.rows}}measureText(t,e={}){const n=this.planText(t,e);return{cols:n.cols,rows:n.rows}}get name(){return this.et}get header(){return{...this.H}}get characters(){return new Map(Array.from(this.nt,([t,e])=>[t,c(e)]))}get hardblank(){return this.H.hardblank}get height(){return this.H.height}get baseline(){return this.H.baseline}get defaultLayout(){return 128&this.H.fullLayout?"smushed":64&this.H.fullLayout?"fitted":-1===this.H.oldLayout?"full":0===this.H.oldLayout?"fitted":this.H.oldLayout>0?"smushed":"full"}get defaultPrintDirection(){return 1===this.H.printDirection?"rtl":"ltr"}get defaultVerticalLayout(){return 16384&this.H.fullLayout?"smushed":8192&this.H.fullLayout?"fitted":"full"}static ot(t){const e=t instanceof URL?t.pathname:t,n=(e.split(/[?#]/,1)[0]??e).split("/").filter(Boolean).pop()??"figfont";return n.toLowerCase().endsWith(".flf")?n.slice(0,-4)||"figfont":n}lt(t){const e=[[]];for(const[n,r]of Array.from(t).entries())"\n"!==r?e[e.length-1].push({character:r,inputIndex:n}):e.push([]);return e}ht(t,e){return"rtl"===e?[...t].reverse():t}ft(t){const n=t.map(({character:t,inputIndex:e})=>({figChar:this.getCharacter(t)??this.getCharacter(32),inputChar:t,inputIndex:e})),r=n.find(t=>void 0===t.figChar);if(r)throw new e("FIGfont is missing a required character for layout.",{character:r.inputChar,index:r.inputIndex});return n}ut(t,e,n){const r="number"==typeof n.maxCols&&Number.isFinite(n.maxCols)?Math.floor(n.maxCols):void 0,i=n.wrap??"none";return 0===t.length||!r||r<1||"none"===i?[t]:"char"===i?this.dt(t,e,r):this.gt(t,e,r)}gt(t,e,n){const r=this._t(t);if(!r.some(t=>!t.isWhitespace))return[t];const i=[];let s=[],o=[];for(const a of r){if(a.isWhitespace){s.length>0&&(o=a.characters);continue}const t=0===s.length?a.characters:s.concat(o,a.characters);s.length>0&&this.wt(t,e)>n?(i.push(s),s=a.characters.slice()):s=t,o=[]}return 0===s.length?[[]]:(i.push(s),i)}dt(t,e,n){const r=[];let i=[];for(const s of t){const t=i.concat(s);i.length>0&&this.wt(t,e)>n?(r.push(i),i=[s]):i=t}return 0===i.length?[[]]:(r.push(i),r)}wt(t,e){const n=this.ft(t);return this.rt.N(n.map(t=>t.figChar),n.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),e,0).cols}_t(t){const e=[];for(const n of t){const t=/\s/u.test(n.character),r=e[e.length-1];r&&r.isWhitespace===t?r.characters.push(n):e.push({isWhitespace:t,characters:[n]})}return e}ct(t){return"ltr"===t||"rtl"===t?t:this.defaultPrintDirection}};function c(t){if(t)return{...t,lines:[...t.lines]}}var l=Symbol.for("textmode.figlet.state");function h(t){const e=t;return e[l]||(e[l]={activeFont:void 0,align:"left",baseline:"baseline"}),e[l]}var u=["loadFigFont","parseFigFont","figFont","figText","figTextWidth","figTextHeight","figTextBounds","figTextAlign","figTextBaseline"];function f(t,e){if(void 0!==t)return"function"==typeof t?t(e):t}function d(e,n,r){return r instanceof t.TextmodeColor||"string"==typeof r||"number"==typeof r?"charColor"===n?void e.charColor(r):void e.cellColor(r):4===r.length?"charColor"===n?void e.charColor(r[0],r[1],r[2],r[3]):void e.cellColor(r[0],r[1],r[2],r[3]):void("charColor"!==n?e.cellColor(r[0],r[1],r[2]):e.charColor(r[0],r[1],r[2]))}function g(t){const n=h(t).activeFont;if(!n)throw new e("No FIGlet font is active. Call figFont() first.");return n}function _(t,e){t.It?.(e)}function p(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,configurable:!0,enumerable:!1})}var w={name:"textmode.figlet.js",version:"1.0.3-beta.1",install(t,e){!function(t){p(t,"loadFigFont",async function(t){const e=await a.it(t);return _(this,e),e}),p(t,"parseFigFont",function(t,e){const n=a.st(t,e);return _(this,n),n}),p(t,"figFont",function(t){const e=h(this);if(void 0===t)return e.activeFont;e.activeFont=t}),p(t,"figText",function(t,e,n,r={}){const i=g(this),s=i.planText(t,r),o=h(this),a=e+(c=s.cols,"center"===(l=o.align)?-Math.floor(c/2):"right"===l?-(c-1):0);var c,l;const u=n+(_=s.rows,p=i.baseline,"top"===(w=o.baseline)?0:"center"===w?-Math.floor(_/2):"bottom"===w?-(_-1):-(p-1));var _,p,w;this.push(),this.translate(a,u,0);for(const h of s.cells){this.push(),this.translate(h.col,h.row,0);const t=f(r.charColor,h),e=f(r.cellColor,h);this.char(h.char),void 0!==t&&d(this,"charColor",t),void 0!==e&&d(this,"cellColor",e),this.point(),this.pop()}this.pop()}),p(t,"figTextWidth",function(t,e={}){return g(this).measureText(t,e).cols}),p(t,"figTextHeight",function(t,e={}){return g(this).measureText(t,e).rows}),p(t,"figTextBounds",function(t,e={}){return g(this).measureText(t,e)}),p(t,"figTextAlign",function(t){const e=h(this);if(void 0===t)return e.align;e.align=t}),p(t,"figTextBaseline",function(t){const e=h(this);if(void 0===t)return e.baseline;e.baseline=t})}(t)},uninstall(t,e){!function(t){for(const e of u)delete t[e];!function(t){delete t[l]}(t)}(t)}};if("undefined"!=typeof window){const t=window;t.FigletPlugin=w,t.TextmodeFigFont=a,t.FigFontParser=r,t.FigLayoutEngine=s,t.FigSmushRules=i,t.FIGFONT_REQUIRED_CODEPOINTS=n}export{n as FIGFONT_REQUIRED_CODEPOINTS,r as FigFontParser,s as FigLayoutEngine,i as FigSmushRules,w as FigletPlugin,a as TextmodeFigFont};
|
|
1
|
+
import{color as t}from"textmode.js";var e=class t extends Error{constructor(e,n){super(t.formatMessage(e,n)),this.name="FigletError"}static formatMessage(e,n){return n&&0!==Object.keys(n).length?`${e}\n\nContext:${Object.entries(n).map(([e,n])=>`\n - ${e}: ${t.formatValue(n)}`).join("")}`:e}static formatValue(e){return null===e?"null":void 0===e?"undefined":"string"==typeof e?`"${e}"`:"number"==typeof e||"boolean"==typeof e?String(e):Array.isArray(e)?`[${e.map(e=>t.formatValue(e)).join(", ")}]`:"object"==typeof e?JSON.stringify(e):String(e)}},n=[...Array.from({length:95},(t,e)=>e+32),196,214,220,228,246,252,223],r=class{static t(t){if(0===t.length)throw new e("Cannot parse an empty FIGfont file.");const n=t.replace(/\r\n?/g,"\n").split("\n"),r=n[0];if(!r)throw new e("Missing FIGfont header line.");const i=this.i(r);let s=1+i.commentLines;if(s>n.length)throw new e("FIGfont comment line count exceeds file length.",{commentLines:i.commentLines,totalLines:n.length});const o=/* @__PURE__ */new Map;return s=this.o(n,s,i,o),this.l(n,s,i,o),{header:i,characters:o}}static i(t){const n=t.trim().split(/\s+/),r=n[0]??"";if(r.length<6)throw new e("Invalid FIGfont header token.",{headerToken:r});const i=r.slice(0,5),s=r.slice(5);if("flf2a"!==i)throw new e("Unsupported FIGfont signature.",{signature:i});if(1!==s.length)throw new e("FIGfont hardblank must be a single character.",{hardblank:s});if(n.length<6)throw new e("Incomplete FIGfont header.",{headerLine:t});return{signature:i,hardblank:s,height:this.h(n[1],"height"),baseline:this.h(n[2],"baseline"),maxLength:this.h(n[3],"maxLength"),oldLayout:this.h(n[4],"oldLayout"),commentLines:this.h(n[5],"commentLines"),printDirection:this.h(n[6]??"0","printDirection"),fullLayout:this.h(n[7]??"0","fullLayout"),codetagCount:this.h(n[8]??"0","codetagCount")}}static o(t,e,r,i){let s=e;for(const o of n){const e=this.u(t,s,r.height,o);i.set(o,e),s+=r.height}return s}static l(t,e,n,r){let i=e;for(;i<t.length;){const e=t[i]?.trim()??"";if(0===e.length){i+=1;continue}const s=this._(e);i+=1;const o=this.u(t,i,n.height,s);r.set(s,o),i+=n.height}}static u(t,n,r,i){if(n+r>t.length)throw new e("Unexpected end of FIGfont character data.",{codePoint:i,startIndex:n,height:r,totalLines:t.length});const s=[];let o=0;for(let a=0;a<r;a+=1){const r=t[n+a]??"";if(0===r.length)throw new e("Encountered an empty FIGcharacter row.",{codePoint:i,row:a,startIndex:n});const c=r.at(-1);if(!c)throw new e("Failed to determine FIGcharacter endmark.",{codePoint:i,row:a});const l=r.replace(new RegExp(`${this.escapeForRegExp(c)}+$`),"");s.push(l),o=Math.max(o,l.length)}return{code:i,lines:s,width:o}}static _(t){const n=t.split(/\s+/,1)[0];if(/^[-+]?0x[0-9a-f]+$/i.test(n))return Number.parseInt(n,16);if(/^[-+]?0[0-7]+$/.test(n))return Number.parseInt(n,8);if(/^[-+]?\d+$/.test(n))return Number.parseInt(n,10);throw new e("Invalid FIGfont code tag.",{codetagLine:t})}static h(t,n){if(!/^-?\d+$/.test(t))throw new e("Invalid FIGfont header value.",{field:n,token:t});return Number.parseInt(t,10)}static escapeForRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}},i=class{static RULE_EQUAL_CHARACTER=1;static RULE_UNDERSCORE=2;static RULE_HIERARCHY=4;static RULE_OPPOSITE_PAIR=8;static RULE_BIG_X=16;static RULE_HARDBLANK=32;static VERTICAL_RULE_EQUAL_CHARACTER=256;static VERTICAL_RULE_UNDERSCORE=512;static VERTICAL_RULE_HIERARCHY=1024;static VERTICAL_RULE_HORIZONTAL_LINE=2048;static VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH=4096;static p(t){return 0!==t.fullLayout?63&t.fullLayout:t.oldLayout>0?63&t.oldLayout:0}static m(t){return 7936&t.fullLayout}static I(t,e,n,r){return" "===t?e:" "===e?t:0===r?this.L(t,e,n):(0!==(r&this.RULE_EQUAL_CHARACTER)?this.C(t,e,n):null)??(0!==(r&this.RULE_UNDERSCORE)?this.v(t,e):null)??(0!==(r&this.RULE_HIERARCHY)?this.R(t,e):null)??(0!==(r&this.RULE_OPPOSITE_PAIR)?this.A(t,e):null)??(0!==(r&this.RULE_BIG_X)?this.F(t,e):null)??(0!==(r&this.RULE_HARDBLANK)?this.T(t,e,n):null)}static L(t,e,n){return" "===t?e:" "===e?t:e}static U(t,e,n){return" "===t?e:" "===e?t:0===n?this.L(t,e," "):(0!==(n&this.VERTICAL_RULE_EQUAL_CHARACTER)?this.C(t,e," "):null)??(0!==(n&this.VERTICAL_RULE_UNDERSCORE)?this.v(t,e):null)??(0!==(n&this.VERTICAL_RULE_HIERARCHY)?this.R(t,e):null)??(0!==(n&this.VERTICAL_RULE_HORIZONTAL_LINE)?this.$(t,e):null)??(0!==(n&this.VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH)?this.k(t,e):null)}static C(t,e,n){return t===e&&t!==n?t:null}static v(t,e){const n="|/\\[]{}()<>";return"_"===t&&n.includes(e)?e:"_"===e&&n.includes(t)?t:null}static R(t,e){const n=["|","/\\","[]","{}","()","<>"],r=n.findIndex(e=>e.includes(t)),i=n.findIndex(t=>t.includes(e));return-1===r||-1===i||r===i?null:r>i?t:e}static A(t,e){return["[]","][","{}","}{","()",")("].includes(`${t}${e}`)?"|":null}static F(t,e){const n=`${t}${e}`;return"/\\"===n?"|":"\\/"===n?"Y":"><"===n?"X":null}static T(t,e,n){return t===n&&e===n?n:null}static $(t,e){const n=`${t}${e}`;return"-_"===n||"_-"===n?"=":null}static k(t,e){return"|"===t&&"|"===e?"|":null}},s=class{M;S;H;constructor(t){this.M=t,this.S=i.p(t),this.H=i.m(t)}G(t,e){const n=t.map((t,e)=>({inputIndex:e,inputChar:String.fromCodePoint(t.code)})),r=this.N(t,n,e,0),i=Array.from({length:r.rows},()=>Array.from({length:r.cols},()=>" "));for(const s of r.cells)i[s.row][s.col]=s.char;return i}N(t,e,n,r){if(0===t.length)return{lineIndex:r,cells:[],cols:0,rows:this.M.height};let s=this.V(t[0],e[0],r),o=t[0].width;for(let a=1;a<t.length;a+=1){const c=t[a],l=e[a]??{inputIndex:a,inputChar:String.fromCodePoint(c.code)},h=o-this.O(s,o,c,n),u=Math.max(o,h+c.width),f=s.map(t=>Array.from({length:u},(e,n)=>t[n]));for(let t=0;t<this.M.height;t+=1){const e=c.lines[t]??"",n=f[t];for(let s=0;s<c.width;s+=1){const o=e[s]??" ";if(" "===o)continue;const a=h+s,u=n[a],f=this.P(a,t,s,r,c,l,o);if(!u){n[a]=f;continue}const d=i.I(u.char,o,this.M.hardblank,this.S);n[a]=this.D(u,f,d??o)}}s=f,o=u}return this.B(s,o,r)}j(t,e){if(0===t.length)return{cells:[],lines:[],cols:0,rows:0};let n=this.W(t[0]),r=t[0].cols,s=t[0].rows;const o=[this.q(t[0],0)];for(let a=1;a<t.length;a+=1){const c=t[a],l=s-this.X(n,s,r,c,e),h=Math.max(r,c.cols),u=Math.max(s,l+c.rows),f=Array.from({length:u},(t,e)=>Array.from({length:h},(t,r)=>n[e]?.[r]));for(const t of c.cells){const e=l+t.row,n=t.col,r=f[e]?.[n];if(!r){f[e][n]={...t,row:e};continue}const s=i.U(r.char,t.char,this.H);f[e][n]=this.D(r,{...t,row:e},s??t.char)}n=f,r=h,s=u,o.push(this.q(c,l))}return this.Y(n,r,s,o)}O(t,e,n,r){if("full"===r)return 0;for(let i=e;i>=0;i-=1){let s=!0;for(let o=0;o<this.M.height&&s;o+=1){const a=t[o]??[],c=n.lines[o]??"";for(let t=0;t<i;t+=1){const n=a[e-i+t]?.char??" ",o=c[t]??" ";if(!this.J(n,o,r)){s=!1;break}}}if(s)return i}return 0}J(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==i.I(t,e,this.M.hardblank,this.S)}V(t,e={inputIndex:0,inputChar:String.fromCodePoint(t.code)},n=0){return Array.from({length:this.M.height},(r,i)=>{const s=t.lines[i]??"";return Array.from({length:t.width},(r,o)=>{const a=s[o]??" ";return" "===a?void 0:this.P(o,i,o,n,t,e,a)})})}P(t,e,n,r,i,s,o){return{char:o,col:t,row:e,inputIndex:s.inputIndex,inputChar:s.inputChar,figCharCode:i.code,subRow:e,subCol:n,lineIndex:r}}D(t,e,n){return n===t.char?t:{...e,char:n}}B(t,e,n){const r=[];for(let i=0;i<this.M.height;i+=1){const s=t[i]??[];for(let t=0;t<e;t+=1){const e=s[t];e&&e.char!==this.M.hardblank&&r.push({...e,col:t,row:i,lineIndex:n})}}return{lineIndex:n,cells:r,cols:e,rows:this.M.height}}X(t,e,n,r,i){if("full"===i)return 0;const s=this.W(r),o=Math.min(e,r.rows),a=Math.max(n,r.cols);for(let c=o;c>=0;c-=1){let n=!0;for(let r=0;r<c&&n;r+=1){const o=t[e-c+r]??[],l=s[r]??[];for(let t=0;t<a;t+=1){const e=o[t]?.char??" ",r=l[t]?.char??" ";if(!this.K(e,r,i)){n=!1;break}}}if(n)return c}return 0}K(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==i.U(t,e,this.H)}W(t){const e=Array.from({length:t.rows},()=>Array.from({length:t.cols},()=>{}));for(const n of t.cells)e[n.row][n.col]=n;return e}q(t,e){return{...t,cells:t.cells.map(t=>({...t,row:t.row+e}))}}Y(t,e,n,r){const i=[];for(let s=0;s<n;s+=1)for(let n=0;n<e;n+=1){const e=t[s]?.[n];e&&i.push({...e,row:s,col:n})}return{cells:i,lines:r,cols:e,rows:n}}},o=class{Z=/* @__PURE__ */new Set;tt(t){this.Z.add(t)}dispose(){for(const t of this.Z)t();this.Z.clear()}},a=class t extends o{et;M;nt;rt;constructor(t,e,n){super(),this.et=t,this.M=e,this.nt=n,this.rt=new s(e)}static async it(t){const n=await fetch(t);if(!n.ok)throw new e("Failed to load FIGfont file.",{source:String(t),status:n.status,statusText:n.statusText});const r=await n.text();return this.st(this.ot(t),r)}static st(e,n){const i=r.t(n);return new t(e,i.header,i.characters)}getCharacter(t){const e="number"==typeof t?t:Array.from(t)[0]?.codePointAt(0);if(void 0!==e)return c(this.nt.get(e))}planText(t,e={}){const n=e.horizontalLayout??this.defaultLayout,r=e.verticalLayout??this.defaultVerticalLayout,i=this.ct(e.direction),s=this.lt(t).map(t=>this.ht(t,i)).flatMap(t=>this.ut(t,n,e)).map((t,e)=>{const r=this.ft(t);return this.rt.N(r.map(t=>t.figChar),r.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),n,e)}),o=this.rt.j(s,r);return{cells:o.cells,lines:o.lines,cols:o.cols,rows:o.rows,direction:i}}renderText(t,e={}){const n=this.planText(t,e),r=Array.from({length:n.rows},()=>Array.from({length:n.cols},()=>" "));for(const i of n.cells)r[i.row][i.col]=i.char;return{grid:r,cols:n.cols,rows:n.rows}}measureText(t,e={}){const n=this.planText(t,e);return{cols:n.cols,rows:n.rows}}get name(){return this.et}get header(){return{...this.M}}get characters(){return new Map(Array.from(this.nt,([t,e])=>[t,c(e)]))}get hardblank(){return this.M.hardblank}get height(){return this.M.height}get baseline(){return this.M.baseline}get defaultLayout(){return 128&this.M.fullLayout?"smushed":64&this.M.fullLayout?"fitted":-1===this.M.oldLayout?"full":0===this.M.oldLayout?"fitted":this.M.oldLayout>0?"smushed":"full"}get defaultPrintDirection(){return 1===this.M.printDirection?"rtl":"ltr"}get defaultVerticalLayout(){return 16384&this.M.fullLayout?"smushed":8192&this.M.fullLayout?"fitted":"full"}static ot(t){const e=t instanceof URL?t.pathname:t,n=(e.split(/[?#]/,1)[0]??e).split("/").filter(Boolean).pop()??"figfont";return n.toLowerCase().endsWith(".flf")?n.slice(0,-4)||"figfont":n}lt(t){const e=[[]];for(const[n,r]of Array.from(t).entries())"\n"!==r?e[e.length-1].push({character:r,inputIndex:n}):e.push([]);return e}ht(t,e){return"rtl"===e?[...t].reverse():t}ft(t){const n=t.map(({character:t,inputIndex:e})=>({figChar:this.getCharacter(t)??this.getCharacter(32),inputChar:t,inputIndex:e})),r=n.find(t=>void 0===t.figChar);if(r)throw new e("FIGfont is missing a required character for layout.",{character:r.inputChar,index:r.inputIndex});return n}ut(t,e,n){const r="number"==typeof n.maxCols&&Number.isFinite(n.maxCols)?Math.floor(n.maxCols):void 0,i=n.wrap??"none";return 0===t.length||!r||r<1||"none"===i?[t]:"char"===i?this.dt(t,e,r):this.gt(t,e,r)}gt(t,e,n){const r=this._t(t);if(!r.some(t=>!t.isWhitespace))return[t];const i=[];let s=[],o=[];for(const a of r){if(a.isWhitespace){s.length>0&&(o=a.characters);continue}const t=0===s.length?a.characters:s.concat(o,a.characters);s.length>0&&this.wt(t,e)>n?(i.push(s),s=a.characters.slice()):s=t,o=[]}return 0===s.length?[[]]:(i.push(s),i)}dt(t,e,n){const r=[];let i=[];for(const s of t){const t=i.concat(s);i.length>0&&this.wt(t,e)>n?(r.push(i),i=[s]):i=t}return 0===i.length?[[]]:(r.push(i),r)}wt(t,e){const n=this.ft(t);return this.rt.N(n.map(t=>t.figChar),n.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),e,0).cols}_t(t){const e=[];for(const n of t){const t=/\s/u.test(n.character),r=e[e.length-1];r&&r.isWhitespace===t?r.characters.push(n):e.push({isWhitespace:t,characters:[n]})}return e}ct(t){return"ltr"===t||"rtl"===t?t:this.defaultPrintDirection}};function c(t){if(t)return{...t,lines:[...t.lines]}}var l=/* @__PURE__ */new WeakMap;function h(t){let e=l.get(t);return e||(e={activeFont:void 0,align:"left",baseline:"baseline"},l.set(t,e)),e}function u(t,e){if(void 0!==t)return"function"==typeof t?t(e):t}function f(e,n,r){return r instanceof t.TextmodeColor||"string"==typeof r||"number"==typeof r?"charColor"===n?void e.charColor(r):void e.cellColor(r):4===r.length?"charColor"===n?void e.charColor(r[0],r[1],r[2],r[3]):void e.cellColor(r[0],r[1],r[2],r[3]):void("charColor"!==n?e.cellColor(r[0],r[1],r[2]):e.charColor(r[0],r[1],r[2]))}function d(t){const n=h(t).activeFont;if(!n)throw new e("No FIGlet font is active. Call figFont() first.");return n}function g(t,e){t.It?.(e)}var _={name:"textmode.figlet.js",version:"1.0.4-beta.1",install(t,e){!function(t){t.defineExtension("textmodifier","loadFigFont",{value:async function(t){const e=await a.it(t);return g(this,e),e}}),t.defineExtension("textmodifier","parseFigFont",{value:function(t,e){const n=a.st(t,e);return g(this,n),n}}),t.defineExtension("textmodifier","figFont",{value:function(t){const e=h(this);if(void 0===t)return e.activeFont;e.activeFont=t}}),t.defineExtension("textmodifier","figText",{value:function(t,e,n,r={}){const i=d(this),s=i.planText(t,r),o=h(this),a=e+(c=s.cols,"center"===(l=o.align)?-Math.floor(c/2):"right"===l?-(c-1):0);var c,l;const g=n+(_=s.rows,p=i.baseline,"top"===(w=o.baseline)?0:"center"===w?-Math.floor(_/2):"bottom"===w?-(_-1):-(p-1));var _,p,w;this.push(),this.translate(a,g,0);for(const h of s.cells){this.push(),this.translate(h.col,h.row,0);const t=u(r.charColor,h),e=u(r.cellColor,h);this.char(h.char),void 0!==t&&f(this,"charColor",t),void 0!==e&&f(this,"cellColor",e),this.point(),this.pop()}this.pop()}}),t.defineExtension("textmodifier","figTextWidth",{value:function(t,e={}){return d(this).measureText(t,e).cols}}),t.defineExtension("textmodifier","figTextHeight",{value:function(t,e={}){return d(this).measureText(t,e).rows}}),t.defineExtension("textmodifier","figTextBounds",{value:function(t,e={}){return d(this).measureText(t,e)}}),t.defineExtension("textmodifier","figTextAlign",{value:function(t){const e=h(this);if(void 0===t)return e.align;e.align=t}}),t.defineExtension("textmodifier","figTextBaseline",{value:function(t){const e=h(this);if(void 0===t)return e.baseline;e.baseline=t}})}(e)},uninstall(t,e){!function(t){l.delete(t)}(t)}};if("undefined"!=typeof window){const t=window;t.FigletPlugin=_,t.TextmodeFigFont=a,t.FigFontParser=r,t.FigLayoutEngine=s,t.FigSmushRules=i,t.FIGFONT_REQUIRED_CODEPOINTS=n}export{n as FIGFONT_REQUIRED_CODEPOINTS,r as FigFontParser,s as FigLayoutEngine,i as FigSmushRules,_ as FigletPlugin,a as TextmodeFigFont};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("textmode.js")):"function"==typeof define&&define.amd?define(["exports","textmode.js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TextmodeFiglet={},t.textmode)}(this,function(t,e){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var n=class t extends Error{constructor(e,n){super(t.formatMessage(e,n)),this.name="FigletError"}static formatMessage(e,n){return n&&0!==Object.keys(n).length?`${e}\n\nContext:${Object.entries(n).map(([e,n])=>`\n - ${e}: ${t.formatValue(n)}`).join("")}`:e}static formatValue(e){return null===e?"null":void 0===e?"undefined":"string"==typeof e?`"${e}"`:"number"==typeof e||"boolean"==typeof e?String(e):Array.isArray(e)?`[${e.map(e=>t.formatValue(e)).join(", ")}]`:"object"==typeof e?JSON.stringify(e):String(e)}},r=[...Array.from({length:95},(t,e)=>e+32),196,214,220,228,246,252,223],i=class{static t(t){if(0===t.length)throw new n("Cannot parse an empty FIGfont file.");const e=t.replace(/\r\n?/g,"\n").split("\n"),r=e[0];if(!r)throw new n("Missing FIGfont header line.");const i=this.i(r);let s=1+i.commentLines;if(s>e.length)throw new n("FIGfont comment line count exceeds file length.",{commentLines:i.commentLines,totalLines:e.length});const o=new Map;return s=this.o(e,s,i,o),this.l(e,s,i,o),{header:i,characters:o}}static i(t){const e=t.trim().split(/\s+/),r=e[0]??"";if(r.length<6)throw new n("Invalid FIGfont header token.",{headerToken:r});const i=r.slice(0,5),s=r.slice(5);if("flf2a"!==i)throw new n("Unsupported FIGfont signature.",{signature:i});if(1!==s.length)throw new n("FIGfont hardblank must be a single character.",{hardblank:s});if(e.length<6)throw new n("Incomplete FIGfont header.",{headerLine:t});return{signature:i,hardblank:s,height:this.u(e[1],"height"),baseline:this.u(e[2],"baseline"),maxLength:this.u(e[3],"maxLength"),oldLayout:this.u(e[4],"oldLayout"),commentLines:this.u(e[5],"commentLines"),printDirection:this.u(e[6]??"0","printDirection"),fullLayout:this.u(e[7]??"0","fullLayout"),codetagCount:this.u(e[8]??"0","codetagCount")}}static o(t,e,n,i){let s=e;for(const o of r){const e=this.h(t,s,n.height,o);i.set(o,e),s+=n.height}return s}static l(t,e,n,r){let i=e;for(;i<t.length;){const e=t[i]?.trim()??"";if(0===e.length){i+=1;continue}const s=this.p(e);i+=1;const o=this.h(t,i,n.height,s);r.set(s,o),i+=n.height}}static h(t,e,r,i){if(e+r>t.length)throw new n("Unexpected end of FIGfont character data.",{codePoint:i,startIndex:e,height:r,totalLines:t.length});const s=[];let o=0;for(let a=0;a<r;a+=1){const r=t[e+a]??"";if(0===r.length)throw new n("Encountered an empty FIGcharacter row.",{codePoint:i,row:a,startIndex:e});const c=r.at(-1);if(!c)throw new n("Failed to determine FIGcharacter endmark.",{codePoint:i,row:a});const l=r.replace(new RegExp(`${this.escapeForRegExp(c)}+$`),"");s.push(l),o=Math.max(o,l.length)}return{code:i,lines:s,width:o}}static p(t){const e=t.split(/\s+/,1)[0];if(/^[-+]?0x[0-9a-f]+$/i.test(e))return Number.parseInt(e,16);if(/^[-+]?0[0-7]+$/.test(e))return Number.parseInt(e,8);if(/^[-+]?\d+$/.test(e))return Number.parseInt(e,10);throw new n("Invalid FIGfont code tag.",{codetagLine:t})}static u(t,e){if(!/^-?\d+$/.test(t))throw new n("Invalid FIGfont header value.",{field:e,token:t});return Number.parseInt(t,10)}static escapeForRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}},s=class{static RULE_EQUAL_CHARACTER=1;static RULE_UNDERSCORE=2;static RULE_HIERARCHY=4;static RULE_OPPOSITE_PAIR=8;static RULE_BIG_X=16;static RULE_HARDBLANK=32;static VERTICAL_RULE_EQUAL_CHARACTER=256;static VERTICAL_RULE_UNDERSCORE=512;static VERTICAL_RULE_HIERARCHY=1024;static VERTICAL_RULE_HORIZONTAL_LINE=2048;static VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH=4096;static _(t){return 0!==t.fullLayout?63&t.fullLayout:t.oldLayout>0?63&t.oldLayout:0}static m(t){return 7936&t.fullLayout}static I(t,e,n,r){return" "===t?e:" "===e?t:0===r?this.L(t,e,n):(0!==(r&this.RULE_EQUAL_CHARACTER)?this.C(t,e,n):null)??(0!==(r&this.RULE_UNDERSCORE)?this.R(t,e):null)??(0!==(r&this.RULE_HIERARCHY)?this.v(t,e):null)??(0!==(r&this.RULE_OPPOSITE_PAIR)?this.A(t,e):null)??(0!==(r&this.RULE_BIG_X)?this.F(t,e):null)??(0!==(r&this.RULE_HARDBLANK)?this.T(t,e,n):null)}static L(t,e,n){return" "===t?e:" "===e?t:e}static U(t,e,n){return" "===t?e:" "===e?t:0===n?this.L(t,e," "):(0!==(n&this.VERTICAL_RULE_EQUAL_CHARACTER)?this.C(t,e," "):null)??(0!==(n&this.VERTICAL_RULE_UNDERSCORE)?this.R(t,e):null)??(0!==(n&this.VERTICAL_RULE_HIERARCHY)?this.v(t,e):null)??(0!==(n&this.VERTICAL_RULE_HORIZONTAL_LINE)?this.S(t,e):null)??(0!==(n&this.VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH)?this.$(t,e):null)}static C(t,e,n){return t===e&&t!==n?t:null}static R(t,e){const n="|/\\[]{}()<>";return"_"===t&&n.includes(e)?e:"_"===e&&n.includes(t)?t:null}static v(t,e){const n=["|","/\\","[]","{}","()","<>"],r=n.findIndex(e=>e.includes(t)),i=n.findIndex(t=>t.includes(e));return-1===r||-1===i||r===i?null:r>i?t:e}static A(t,e){return["[]","][","{}","}{","()",")("].includes(`${t}${e}`)?"|":null}static F(t,e){const n=`${t}${e}`;return"/\\"===n?"|":"\\/"===n?"Y":"><"===n?"X":null}static T(t,e,n){return t===n&&e===n?n:null}static S(t,e){const n=`${t}${e}`;return"-_"===n||"_-"===n?"=":null}static $(t,e){return"|"===t&&"|"===e?"|":null}},o=class{H;M;k;constructor(t){this.H=t,this.M=s._(t),this.k=s.m(t)}G(t,e){const n=t.map((t,e)=>({inputIndex:e,inputChar:String.fromCodePoint(t.code)})),r=this.O(t,n,e,0),i=Array.from({length:r.rows},()=>Array.from({length:r.cols},()=>" "));for(const s of r.cells)i[s.row][s.col]=s.char;return i}O(t,e,n,r){if(0===t.length)return{lineIndex:r,cells:[],cols:0,rows:this.H.height};let i=this.N(t[0],e[0],r),o=t[0].width;for(let a=1;a<t.length;a+=1){const c=t[a],l=e[a]??{inputIndex:a,inputChar:String.fromCodePoint(c.code)},u=o-this.V(i,o,c,n),h=Math.max(o,u+c.width),f=i.map(t=>Array.from({length:h},(e,n)=>t[n]));for(let t=0;t<this.H.height;t+=1){const e=c.lines[t]??"",n=f[t];for(let i=0;i<c.width;i+=1){const o=e[i]??" ";if(" "===o)continue;const a=u+i,h=n[a],f=this.P(a,t,i,r,c,l,o);if(!h){n[a]=f;continue}const d=s.I(h.char,o,this.H.hardblank,this.M);n[a]=this.B(h,f,d??o)}}i=f,o=h}return this.D(i,o,r)}j(t,e){if(0===t.length)return{cells:[],lines:[],cols:0,rows:0};let n=this.W(t[0]),r=t[0].cols,i=t[0].rows;const o=[this.q(t[0],0)];for(let a=1;a<t.length;a+=1){const c=t[a],l=i-this.X(n,i,r,c,e),u=Math.max(r,c.cols),h=Math.max(i,l+c.rows),f=Array.from({length:h},(t,e)=>Array.from({length:u},(t,r)=>n[e]?.[r]));for(const t of c.cells){const e=l+t.row,n=t.col,r=f[e]?.[n];if(!r){f[e][n]={...t,row:e};continue}const i=s.U(r.char,t.char,this.k);f[e][n]=this.B(r,{...t,row:e},i??t.char)}n=f,r=u,i=h,o.push(this.q(c,l))}return this.Y(n,r,i,o)}V(t,e,n,r){if("full"===r)return 0;for(let i=e;i>=0;i-=1){let s=!0;for(let o=0;o<this.H.height&&s;o+=1){const a=t[o]??[],c=n.lines[o]??"";for(let t=0;t<i;t+=1){const n=a[e-i+t]?.char??" ",o=c[t]??" ";if(!this.J(n,o,r)){s=!1;break}}}if(s)return i}return 0}J(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==s.I(t,e,this.H.hardblank,this.M)}N(t,e={inputIndex:0,inputChar:String.fromCodePoint(t.code)},n=0){return Array.from({length:this.H.height},(r,i)=>{const s=t.lines[i]??"";return Array.from({length:t.width},(r,o)=>{const a=s[o]??" ";return" "===a?void 0:this.P(o,i,o,n,t,e,a)})})}P(t,e,n,r,i,s,o){return{char:o,col:t,row:e,inputIndex:s.inputIndex,inputChar:s.inputChar,figCharCode:i.code,subRow:e,subCol:n,lineIndex:r}}B(t,e,n){return n===t.char?t:{...e,char:n}}D(t,e,n){const r=[];for(let i=0;i<this.H.height;i+=1){const s=t[i]??[];for(let t=0;t<e;t+=1){const e=s[t];e&&e.char!==this.H.hardblank&&r.push({...e,col:t,row:i,lineIndex:n})}}return{lineIndex:n,cells:r,cols:e,rows:this.H.height}}X(t,e,n,r,i){if("full"===i)return 0;const s=this.W(r),o=Math.min(e,r.rows),a=Math.max(n,r.cols);for(let c=o;c>=0;c-=1){let n=!0;for(let r=0;r<c&&n;r+=1){const o=t[e-c+r]??[],l=s[r]??[];for(let t=0;t<a;t+=1){const e=o[t]?.char??" ",r=l[t]?.char??" ";if(!this.K(e,r,i)){n=!1;break}}}if(n)return c}return 0}K(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==s.U(t,e,this.k)}W(t){const e=Array.from({length:t.rows},()=>Array.from({length:t.cols},()=>{}));for(const n of t.cells)e[n.row][n.col]=n;return e}q(t,e){return{...t,cells:t.cells.map(t=>({...t,row:t.row+e}))}}Y(t,e,n,r){const i=[];for(let s=0;s<n;s+=1)for(let n=0;n<e;n+=1){const e=t[s]?.[n];e&&i.push({...e,row:s,col:n})}return{cells:i,lines:r,cols:e,rows:n}}},a=class{Z=new Set;tt(t){this.Z.add(t)}dispose(){for(const t of this.Z)t();this.Z.clear()}},c=class t extends a{et;H;nt;rt;constructor(t,e,n){super(),this.et=t,this.H=e,this.nt=n,this.rt=new o(e)}static async it(t){const e=await fetch(t);if(!e.ok)throw new n("Failed to load FIGfont file.",{source:String(t),status:e.status,statusText:e.statusText});const r=await e.text();return this.st(this.ot(t),r)}static st(e,n){const r=i.t(n);return new t(e,r.header,r.characters)}getCharacter(t){const e="number"==typeof t?t:Array.from(t)[0]?.codePointAt(0);if(void 0!==e)return l(this.nt.get(e))}planText(t,e={}){const n=e.horizontalLayout??this.defaultLayout,r=e.verticalLayout??this.defaultVerticalLayout,i=this.ct(e.direction),s=this.lt(t).map(t=>this.ut(t,i)).flatMap(t=>this.ht(t,n,e)).map((t,e)=>{const r=this.ft(t);return this.rt.O(r.map(t=>t.figChar),r.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),n,e)}),o=this.rt.j(s,r);return{cells:o.cells,lines:o.lines,cols:o.cols,rows:o.rows,direction:i}}renderText(t,e={}){const n=this.planText(t,e),r=Array.from({length:n.rows},()=>Array.from({length:n.cols},()=>" "));for(const i of n.cells)r[i.row][i.col]=i.char;return{grid:r,cols:n.cols,rows:n.rows}}measureText(t,e={}){const n=this.planText(t,e);return{cols:n.cols,rows:n.rows}}get name(){return this.et}get header(){return{...this.H}}get characters(){return new Map(Array.from(this.nt,([t,e])=>[t,l(e)]))}get hardblank(){return this.H.hardblank}get height(){return this.H.height}get baseline(){return this.H.baseline}get defaultLayout(){return 128&this.H.fullLayout?"smushed":64&this.H.fullLayout?"fitted":-1===this.H.oldLayout?"full":0===this.H.oldLayout?"fitted":this.H.oldLayout>0?"smushed":"full"}get defaultPrintDirection(){return 1===this.H.printDirection?"rtl":"ltr"}get defaultVerticalLayout(){return 16384&this.H.fullLayout?"smushed":8192&this.H.fullLayout?"fitted":"full"}static ot(t){const e=t instanceof URL?t.pathname:t,n=(e.split(/[?#]/,1)[0]??e).split("/").filter(Boolean).pop()??"figfont";return n.toLowerCase().endsWith(".flf")?n.slice(0,-4)||"figfont":n}lt(t){const e=[[]];for(const[n,r]of Array.from(t).entries())"\n"!==r?e[e.length-1].push({character:r,inputIndex:n}):e.push([]);return e}ut(t,e){return"rtl"===e?[...t].reverse():t}ft(t){const e=t.map(({character:t,inputIndex:e})=>({figChar:this.getCharacter(t)??this.getCharacter(32),inputChar:t,inputIndex:e})),r=e.find(t=>void 0===t.figChar);if(r)throw new n("FIGfont is missing a required character for layout.",{character:r.inputChar,index:r.inputIndex});return e}ht(t,e,n){const r="number"==typeof n.maxCols&&Number.isFinite(n.maxCols)?Math.floor(n.maxCols):void 0,i=n.wrap??"none";return 0===t.length||!r||r<1||"none"===i?[t]:"char"===i?this.dt(t,e,r):this.gt(t,e,r)}gt(t,e,n){const r=this._t(t);if(!r.some(t=>!t.isWhitespace))return[t];const i=[];let s=[],o=[];for(const a of r){if(a.isWhitespace){s.length>0&&(o=a.characters);continue}const t=0===s.length?a.characters:s.concat(o,a.characters);s.length>0&&this.wt(t,e)>n?(i.push(s),s=a.characters.slice()):s=t,o=[]}return 0===s.length?[[]]:(i.push(s),i)}dt(t,e,n){const r=[];let i=[];for(const s of t){const t=i.concat(s);i.length>0&&this.wt(t,e)>n?(r.push(i),i=[s]):i=t}return 0===i.length?[[]]:(r.push(i),r)}wt(t,e){const n=this.ft(t);return this.rt.O(n.map(t=>t.figChar),n.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),e,0).cols}_t(t){const e=[];for(const n of t){const t=/\s/u.test(n.character),r=e[e.length-1];r&&r.isWhitespace===t?r.characters.push(n):e.push({isWhitespace:t,characters:[n]})}return e}ct(t){return"ltr"===t||"rtl"===t?t:this.defaultPrintDirection}};function l(t){if(t)return{...t,lines:[...t.lines]}}var u=Symbol.for("textmode.figlet.state");function h(t){const e=t;return e[u]||(e[u]={activeFont:void 0,align:"left",baseline:"baseline"}),e[u]}var f=["loadFigFont","parseFigFont","figFont","figText","figTextWidth","figTextHeight","figTextBounds","figTextAlign","figTextBaseline"];function d(t,e){if(void 0!==t)return"function"==typeof t?t(e):t}function g(t,n,r){return r instanceof e.color.TextmodeColor||"string"==typeof r||"number"==typeof r?"charColor"===n?void t.charColor(r):void t.cellColor(r):4===r.length?"charColor"===n?void t.charColor(r[0],r[1],r[2],r[3]):void t.cellColor(r[0],r[1],r[2],r[3]):void("charColor"!==n?t.cellColor(r[0],r[1],r[2]):t.charColor(r[0],r[1],r[2]))}function p(t){const e=h(t).activeFont;if(!e)throw new n("No FIGlet font is active. Call figFont() first.");return e}function _(t,e){t.It?.(e)}function w(t,e,n){Object.defineProperty(t,e,{value:n,writable:!0,configurable:!0,enumerable:!1})}var m={name:"textmode.figlet.js",version:"1.0.3-beta.1",install(t,e){!function(t){w(t,"loadFigFont",async function(t){const e=await c.it(t);return _(this,e),e}),w(t,"parseFigFont",function(t,e){const n=c.st(t,e);return _(this,n),n}),w(t,"figFont",function(t){const e=h(this);if(void 0===t)return e.activeFont;e.activeFont=t}),w(t,"figText",function(t,e,n,r={}){const i=p(this),s=i.planText(t,r),o=h(this),a=e+(c=s.cols,"center"===(l=o.align)?-Math.floor(c/2):"right"===l?-(c-1):0);var c,l;const u=n+(f=s.rows,_=i.baseline,"top"===(w=o.baseline)?0:"center"===w?-Math.floor(f/2):"bottom"===w?-(f-1):-(_-1));var f,_,w;this.push(),this.translate(a,u,0);for(const h of s.cells){this.push(),this.translate(h.col,h.row,0);const t=d(r.charColor,h),e=d(r.cellColor,h);this.char(h.char),void 0!==t&&g(this,"charColor",t),void 0!==e&&g(this,"cellColor",e),this.point(),this.pop()}this.pop()}),w(t,"figTextWidth",function(t,e={}){return p(this).measureText(t,e).cols}),w(t,"figTextHeight",function(t,e={}){return p(this).measureText(t,e).rows}),w(t,"figTextBounds",function(t,e={}){return p(this).measureText(t,e)}),w(t,"figTextAlign",function(t){const e=h(this);if(void 0===t)return e.align;e.align=t}),w(t,"figTextBaseline",function(t){const e=h(this);if(void 0===t)return e.baseline;e.baseline=t})}(t)},uninstall(t,e){!function(t){for(const e of f)delete t[e];!function(t){delete t[u]}(t)}(t)}};if("undefined"!=typeof window){const t=window;t.FigletPlugin=m,t.TextmodeFigFont=c,t.FigFontParser=i,t.FigLayoutEngine=o,t.FigSmushRules=s,t.FIGFONT_REQUIRED_CODEPOINTS=r}t.FIGFONT_REQUIRED_CODEPOINTS=r,t.FigFontParser=i,t.FigLayoutEngine=o,t.FigSmushRules=s,t.FigletPlugin=m,t.TextmodeFigFont=c});
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("textmode.js")):"function"==typeof define&&define.amd?define(["exports","textmode.js"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TextmodeFiglet={},t.textmode)}(this,function(t,e){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});var n=class t extends Error{constructor(e,n){super(t.formatMessage(e,n)),this.name="FigletError"}static formatMessage(e,n){return n&&0!==Object.keys(n).length?`${e}\n\nContext:${Object.entries(n).map(([e,n])=>`\n - ${e}: ${t.formatValue(n)}`).join("")}`:e}static formatValue(e){return null===e?"null":void 0===e?"undefined":"string"==typeof e?`"${e}"`:"number"==typeof e||"boolean"==typeof e?String(e):Array.isArray(e)?`[${e.map(e=>t.formatValue(e)).join(", ")}]`:"object"==typeof e?JSON.stringify(e):String(e)}},r=[...Array.from({length:95},(t,e)=>e+32),196,214,220,228,246,252,223],i=class{static t(t){if(0===t.length)throw new n("Cannot parse an empty FIGfont file.");const e=t.replace(/\r\n?/g,"\n").split("\n"),r=e[0];if(!r)throw new n("Missing FIGfont header line.");const i=this.i(r);let s=1+i.commentLines;if(s>e.length)throw new n("FIGfont comment line count exceeds file length.",{commentLines:i.commentLines,totalLines:e.length});const o=new Map;return s=this.o(e,s,i,o),this.l(e,s,i,o),{header:i,characters:o}}static i(t){const e=t.trim().split(/\s+/),r=e[0]??"";if(r.length<6)throw new n("Invalid FIGfont header token.",{headerToken:r});const i=r.slice(0,5),s=r.slice(5);if("flf2a"!==i)throw new n("Unsupported FIGfont signature.",{signature:i});if(1!==s.length)throw new n("FIGfont hardblank must be a single character.",{hardblank:s});if(e.length<6)throw new n("Incomplete FIGfont header.",{headerLine:t});return{signature:i,hardblank:s,height:this.u(e[1],"height"),baseline:this.u(e[2],"baseline"),maxLength:this.u(e[3],"maxLength"),oldLayout:this.u(e[4],"oldLayout"),commentLines:this.u(e[5],"commentLines"),printDirection:this.u(e[6]??"0","printDirection"),fullLayout:this.u(e[7]??"0","fullLayout"),codetagCount:this.u(e[8]??"0","codetagCount")}}static o(t,e,n,i){let s=e;for(const o of r){const e=this.h(t,s,n.height,o);i.set(o,e),s+=n.height}return s}static l(t,e,n,r){let i=e;for(;i<t.length;){const e=t[i]?.trim()??"";if(0===e.length){i+=1;continue}const s=this.p(e);i+=1;const o=this.h(t,i,n.height,s);r.set(s,o),i+=n.height}}static h(t,e,r,i){if(e+r>t.length)throw new n("Unexpected end of FIGfont character data.",{codePoint:i,startIndex:e,height:r,totalLines:t.length});const s=[];let o=0;for(let a=0;a<r;a+=1){const r=t[e+a]??"";if(0===r.length)throw new n("Encountered an empty FIGcharacter row.",{codePoint:i,row:a,startIndex:e});const l=r.at(-1);if(!l)throw new n("Failed to determine FIGcharacter endmark.",{codePoint:i,row:a});const c=r.replace(new RegExp(`${this.escapeForRegExp(l)}+$`),"");s.push(c),o=Math.max(o,c.length)}return{code:i,lines:s,width:o}}static p(t){const e=t.split(/\s+/,1)[0];if(/^[-+]?0x[0-9a-f]+$/i.test(e))return Number.parseInt(e,16);if(/^[-+]?0[0-7]+$/.test(e))return Number.parseInt(e,8);if(/^[-+]?\d+$/.test(e))return Number.parseInt(e,10);throw new n("Invalid FIGfont code tag.",{codetagLine:t})}static u(t,e){if(!/^-?\d+$/.test(t))throw new n("Invalid FIGfont header value.",{field:e,token:t});return Number.parseInt(t,10)}static escapeForRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}},s=class{static RULE_EQUAL_CHARACTER=1;static RULE_UNDERSCORE=2;static RULE_HIERARCHY=4;static RULE_OPPOSITE_PAIR=8;static RULE_BIG_X=16;static RULE_HARDBLANK=32;static VERTICAL_RULE_EQUAL_CHARACTER=256;static VERTICAL_RULE_UNDERSCORE=512;static VERTICAL_RULE_HIERARCHY=1024;static VERTICAL_RULE_HORIZONTAL_LINE=2048;static VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH=4096;static _(t){return 0!==t.fullLayout?63&t.fullLayout:t.oldLayout>0?63&t.oldLayout:0}static m(t){return 7936&t.fullLayout}static I(t,e,n,r){return" "===t?e:" "===e?t:0===r?this.L(t,e,n):(0!==(r&this.RULE_EQUAL_CHARACTER)?this.C(t,e,n):null)??(0!==(r&this.RULE_UNDERSCORE)?this.v(t,e):null)??(0!==(r&this.RULE_HIERARCHY)?this.R(t,e):null)??(0!==(r&this.RULE_OPPOSITE_PAIR)?this.A(t,e):null)??(0!==(r&this.RULE_BIG_X)?this.F(t,e):null)??(0!==(r&this.RULE_HARDBLANK)?this.T(t,e,n):null)}static L(t,e,n){return" "===t?e:" "===e?t:e}static U(t,e,n){return" "===t?e:" "===e?t:0===n?this.L(t,e," "):(0!==(n&this.VERTICAL_RULE_EQUAL_CHARACTER)?this.C(t,e," "):null)??(0!==(n&this.VERTICAL_RULE_UNDERSCORE)?this.v(t,e):null)??(0!==(n&this.VERTICAL_RULE_HIERARCHY)?this.R(t,e):null)??(0!==(n&this.VERTICAL_RULE_HORIZONTAL_LINE)?this.M(t,e):null)??(0!==(n&this.VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH)?this.S(t,e):null)}static C(t,e,n){return t===e&&t!==n?t:null}static v(t,e){const n="|/\\[]{}()<>";return"_"===t&&n.includes(e)?e:"_"===e&&n.includes(t)?t:null}static R(t,e){const n=["|","/\\","[]","{}","()","<>"],r=n.findIndex(e=>e.includes(t)),i=n.findIndex(t=>t.includes(e));return-1===r||-1===i||r===i?null:r>i?t:e}static A(t,e){return["[]","][","{}","}{","()",")("].includes(`${t}${e}`)?"|":null}static F(t,e){const n=`${t}${e}`;return"/\\"===n?"|":"\\/"===n?"Y":"><"===n?"X":null}static T(t,e,n){return t===n&&e===n?n:null}static M(t,e){const n=`${t}${e}`;return"-_"===n||"_-"===n?"=":null}static S(t,e){return"|"===t&&"|"===e?"|":null}},o=class{$;k;H;constructor(t){this.$=t,this.k=s._(t),this.H=s.m(t)}G(t,e){const n=t.map((t,e)=>({inputIndex:e,inputChar:String.fromCodePoint(t.code)})),r=this.N(t,n,e,0),i=Array.from({length:r.rows},()=>Array.from({length:r.cols},()=>" "));for(const s of r.cells)i[s.row][s.col]=s.char;return i}N(t,e,n,r){if(0===t.length)return{lineIndex:r,cells:[],cols:0,rows:this.$.height};let i=this.O(t[0],e[0],r),o=t[0].width;for(let a=1;a<t.length;a+=1){const l=t[a],c=e[a]??{inputIndex:a,inputChar:String.fromCodePoint(l.code)},u=o-this.V(i,o,l,n),h=Math.max(o,u+l.width),f=i.map(t=>Array.from({length:h},(e,n)=>t[n]));for(let t=0;t<this.$.height;t+=1){const e=l.lines[t]??"",n=f[t];for(let i=0;i<l.width;i+=1){const o=e[i]??" ";if(" "===o)continue;const a=u+i,h=n[a],f=this.P(a,t,i,r,l,c,o);if(!h){n[a]=f;continue}const d=s.I(h.char,o,this.$.hardblank,this.k);n[a]=this.D(h,f,d??o)}}i=f,o=h}return this.B(i,o,r)}j(t,e){if(0===t.length)return{cells:[],lines:[],cols:0,rows:0};let n=this.W(t[0]),r=t[0].cols,i=t[0].rows;const o=[this.q(t[0],0)];for(let a=1;a<t.length;a+=1){const l=t[a],c=i-this.X(n,i,r,l,e),u=Math.max(r,l.cols),h=Math.max(i,c+l.rows),f=Array.from({length:h},(t,e)=>Array.from({length:u},(t,r)=>n[e]?.[r]));for(const t of l.cells){const e=c+t.row,n=t.col,r=f[e]?.[n];if(!r){f[e][n]={...t,row:e};continue}const i=s.U(r.char,t.char,this.H);f[e][n]=this.D(r,{...t,row:e},i??t.char)}n=f,r=u,i=h,o.push(this.q(l,c))}return this.Y(n,r,i,o)}V(t,e,n,r){if("full"===r)return 0;for(let i=e;i>=0;i-=1){let s=!0;for(let o=0;o<this.$.height&&s;o+=1){const a=t[o]??[],l=n.lines[o]??"";for(let t=0;t<i;t+=1){const n=a[e-i+t]?.char??" ",o=l[t]??" ";if(!this.J(n,o,r)){s=!1;break}}}if(s)return i}return 0}J(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==s.I(t,e,this.$.hardblank,this.k)}O(t,e={inputIndex:0,inputChar:String.fromCodePoint(t.code)},n=0){return Array.from({length:this.$.height},(r,i)=>{const s=t.lines[i]??"";return Array.from({length:t.width},(r,o)=>{const a=s[o]??" ";return" "===a?void 0:this.P(o,i,o,n,t,e,a)})})}P(t,e,n,r,i,s,o){return{char:o,col:t,row:e,inputIndex:s.inputIndex,inputChar:s.inputChar,figCharCode:i.code,subRow:e,subCol:n,lineIndex:r}}D(t,e,n){return n===t.char?t:{...e,char:n}}B(t,e,n){const r=[];for(let i=0;i<this.$.height;i+=1){const s=t[i]??[];for(let t=0;t<e;t+=1){const e=s[t];e&&e.char!==this.$.hardblank&&r.push({...e,col:t,row:i,lineIndex:n})}}return{lineIndex:n,cells:r,cols:e,rows:this.$.height}}X(t,e,n,r,i){if("full"===i)return 0;const s=this.W(r),o=Math.min(e,r.rows),a=Math.max(n,r.cols);for(let l=o;l>=0;l-=1){let n=!0;for(let r=0;r<l&&n;r+=1){const o=t[e-l+r]??[],c=s[r]??[];for(let t=0;t<a;t+=1){const e=o[t]?.char??" ",r=c[t]?.char??" ";if(!this.K(e,r,i)){n=!1;break}}}if(n)return l}return 0}K(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==s.U(t,e,this.H)}W(t){const e=Array.from({length:t.rows},()=>Array.from({length:t.cols},()=>{}));for(const n of t.cells)e[n.row][n.col]=n;return e}q(t,e){return{...t,cells:t.cells.map(t=>({...t,row:t.row+e}))}}Y(t,e,n,r){const i=[];for(let s=0;s<n;s+=1)for(let n=0;n<e;n+=1){const e=t[s]?.[n];e&&i.push({...e,row:s,col:n})}return{cells:i,lines:r,cols:e,rows:n}}},a=class{Z=new Set;tt(t){this.Z.add(t)}dispose(){for(const t of this.Z)t();this.Z.clear()}},l=class t extends a{et;$;nt;rt;constructor(t,e,n){super(),this.et=t,this.$=e,this.nt=n,this.rt=new o(e)}static async it(t){const e=await fetch(t);if(!e.ok)throw new n("Failed to load FIGfont file.",{source:String(t),status:e.status,statusText:e.statusText});const r=await e.text();return this.st(this.ot(t),r)}static st(e,n){const r=i.t(n);return new t(e,r.header,r.characters)}getCharacter(t){const e="number"==typeof t?t:Array.from(t)[0]?.codePointAt(0);if(void 0!==e)return c(this.nt.get(e))}planText(t,e={}){const n=e.horizontalLayout??this.defaultLayout,r=e.verticalLayout??this.defaultVerticalLayout,i=this.lt(e.direction),s=this.ct(t).map(t=>this.ut(t,i)).flatMap(t=>this.ht(t,n,e)).map((t,e)=>{const r=this.ft(t);return this.rt.N(r.map(t=>t.figChar),r.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),n,e)}),o=this.rt.j(s,r);return{cells:o.cells,lines:o.lines,cols:o.cols,rows:o.rows,direction:i}}renderText(t,e={}){const n=this.planText(t,e),r=Array.from({length:n.rows},()=>Array.from({length:n.cols},()=>" "));for(const i of n.cells)r[i.row][i.col]=i.char;return{grid:r,cols:n.cols,rows:n.rows}}measureText(t,e={}){const n=this.planText(t,e);return{cols:n.cols,rows:n.rows}}get name(){return this.et}get header(){return{...this.$}}get characters(){return new Map(Array.from(this.nt,([t,e])=>[t,c(e)]))}get hardblank(){return this.$.hardblank}get height(){return this.$.height}get baseline(){return this.$.baseline}get defaultLayout(){return 128&this.$.fullLayout?"smushed":64&this.$.fullLayout?"fitted":-1===this.$.oldLayout?"full":0===this.$.oldLayout?"fitted":this.$.oldLayout>0?"smushed":"full"}get defaultPrintDirection(){return 1===this.$.printDirection?"rtl":"ltr"}get defaultVerticalLayout(){return 16384&this.$.fullLayout?"smushed":8192&this.$.fullLayout?"fitted":"full"}static ot(t){const e=t instanceof URL?t.pathname:t,n=(e.split(/[?#]/,1)[0]??e).split("/").filter(Boolean).pop()??"figfont";return n.toLowerCase().endsWith(".flf")?n.slice(0,-4)||"figfont":n}ct(t){const e=[[]];for(const[n,r]of Array.from(t).entries())"\n"!==r?e[e.length-1].push({character:r,inputIndex:n}):e.push([]);return e}ut(t,e){return"rtl"===e?[...t].reverse():t}ft(t){const e=t.map(({character:t,inputIndex:e})=>({figChar:this.getCharacter(t)??this.getCharacter(32),inputChar:t,inputIndex:e})),r=e.find(t=>void 0===t.figChar);if(r)throw new n("FIGfont is missing a required character for layout.",{character:r.inputChar,index:r.inputIndex});return e}ht(t,e,n){const r="number"==typeof n.maxCols&&Number.isFinite(n.maxCols)?Math.floor(n.maxCols):void 0,i=n.wrap??"none";return 0===t.length||!r||r<1||"none"===i?[t]:"char"===i?this.dt(t,e,r):this.gt(t,e,r)}gt(t,e,n){const r=this._t(t);if(!r.some(t=>!t.isWhitespace))return[t];const i=[];let s=[],o=[];for(const a of r){if(a.isWhitespace){s.length>0&&(o=a.characters);continue}const t=0===s.length?a.characters:s.concat(o,a.characters);s.length>0&&this.wt(t,e)>n?(i.push(s),s=a.characters.slice()):s=t,o=[]}return 0===s.length?[[]]:(i.push(s),i)}dt(t,e,n){const r=[];let i=[];for(const s of t){const t=i.concat(s);i.length>0&&this.wt(t,e)>n?(r.push(i),i=[s]):i=t}return 0===i.length?[[]]:(r.push(i),r)}wt(t,e){const n=this.ft(t);return this.rt.N(n.map(t=>t.figChar),n.map(({inputChar:t,inputIndex:e})=>({inputChar:t,inputIndex:e})),e,0).cols}_t(t){const e=[];for(const n of t){const t=/\s/u.test(n.character),r=e[e.length-1];r&&r.isWhitespace===t?r.characters.push(n):e.push({isWhitespace:t,characters:[n]})}return e}lt(t){return"ltr"===t||"rtl"===t?t:this.defaultPrintDirection}};function c(t){if(t)return{...t,lines:[...t.lines]}}var u=new WeakMap;function h(t){let e=u.get(t);return e||(e={activeFont:void 0,align:"left",baseline:"baseline"},u.set(t,e)),e}function f(t,e){if(void 0!==t)return"function"==typeof t?t(e):t}function d(t,n,r){return r instanceof e.color.TextmodeColor||"string"==typeof r||"number"==typeof r?"charColor"===n?void t.charColor(r):void t.cellColor(r):4===r.length?"charColor"===n?void t.charColor(r[0],r[1],r[2],r[3]):void t.cellColor(r[0],r[1],r[2],r[3]):void("charColor"!==n?t.cellColor(r[0],r[1],r[2]):t.charColor(r[0],r[1],r[2]))}function p(t){const e=h(t).activeFont;if(!e)throw new n("No FIGlet font is active. Call figFont() first.");return e}function g(t,e){t.It?.(e)}var _={name:"textmode.figlet.js",version:"1.0.4-beta.1",install(t,e){!function(t){t.defineExtension("textmodifier","loadFigFont",{value:async function(t){const e=await l.it(t);return g(this,e),e}}),t.defineExtension("textmodifier","parseFigFont",{value:function(t,e){const n=l.st(t,e);return g(this,n),n}}),t.defineExtension("textmodifier","figFont",{value:function(t){const e=h(this);if(void 0===t)return e.activeFont;e.activeFont=t}}),t.defineExtension("textmodifier","figText",{value:function(t,e,n,r={}){const i=p(this),s=i.planText(t,r),o=h(this),a=e+(l=s.cols,"center"===(c=o.align)?-Math.floor(l/2):"right"===c?-(l-1):0);var l,c;const u=n+(g=s.rows,_=i.baseline,"top"===(w=o.baseline)?0:"center"===w?-Math.floor(g/2):"bottom"===w?-(g-1):-(_-1));var g,_,w;this.push(),this.translate(a,u,0);for(const h of s.cells){this.push(),this.translate(h.col,h.row,0);const t=f(r.charColor,h),e=f(r.cellColor,h);this.char(h.char),void 0!==t&&d(this,"charColor",t),void 0!==e&&d(this,"cellColor",e),this.point(),this.pop()}this.pop()}}),t.defineExtension("textmodifier","figTextWidth",{value:function(t,e={}){return p(this).measureText(t,e).cols}}),t.defineExtension("textmodifier","figTextHeight",{value:function(t,e={}){return p(this).measureText(t,e).rows}}),t.defineExtension("textmodifier","figTextBounds",{value:function(t,e={}){return p(this).measureText(t,e)}}),t.defineExtension("textmodifier","figTextAlign",{value:function(t){const e=h(this);if(void 0===t)return e.align;e.align=t}}),t.defineExtension("textmodifier","figTextBaseline",{value:function(t){const e=h(this);if(void 0===t)return e.baseline;e.baseline=t}})}(e)},uninstall(t,e){!function(t){u.delete(t)}(t)}};if("undefined"!=typeof window){const t=window;t.FigletPlugin=_,t.TextmodeFigFont=l,t.FigFontParser=i,t.FigLayoutEngine=o,t.FigSmushRules=s,t.FIGFONT_REQUIRED_CODEPOINTS=r}t.FIGFONT_REQUIRED_CODEPOINTS=r,t.FigFontParser=i,t.FigLayoutEngine=o,t.FigSmushRules=s,t.FigletPlugin=_,t.TextmodeFigFont=l});
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TextmodePluginContext } from 'textmode.js';
|
|
2
2
|
/**
|
|
3
3
|
* Install FIGlet Textmodifier extensions on a specific `Textmodifier` instance.
|
|
4
4
|
*
|
|
5
|
-
* @
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Remove FIGlet Textmodifier extensions from a specific `Textmodifier` instance.
|
|
5
|
+
* Methods are registered through {@link TextmodePluginContext.defineExtension} so the
|
|
6
|
+
* plugin runtime handles conflict detection and uninstall cleanup uniformly. The
|
|
7
|
+
* extension properties are defined as instance own-properties and are removed by the
|
|
8
|
+
* host when the plugin is uninstalled.
|
|
10
9
|
*
|
|
11
|
-
* @param
|
|
10
|
+
* @param api The textmode.js plugin context.
|
|
12
11
|
*/
|
|
13
|
-
export declare function
|
|
12
|
+
export declare function installTextmodifierFigletExtensions(api: TextmodePluginContext): void;
|
|
@@ -2,6 +2,11 @@ import type { TextmodePlugin } from 'textmode.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Plugin entrypoint for the FIGlet add-on.
|
|
4
4
|
*
|
|
5
|
+
* Installs FIGlet methods on the `Textmodifier` through
|
|
6
|
+
* {@link TextmodePluginContext.defineExtension}, so the plugin runtime owns conflict
|
|
7
|
+
* detection and uninstall cleanup for the extension properties. Per-instance plugin
|
|
8
|
+
* state is cleared on uninstall.
|
|
9
|
+
*
|
|
5
10
|
* @category Workflow
|
|
6
11
|
*
|
|
7
12
|
* @example
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import type { Textmodifier } from 'textmode.js';
|
|
2
2
|
import type { FigTextAlign, FigTextBaseline } from '../figfont';
|
|
3
3
|
import type { TextmodeFigFont } from '../figfont';
|
|
4
|
-
/**
|
|
5
|
-
* Symbol used to store per-instance FIGlet plugin state.
|
|
6
|
-
*/
|
|
7
|
-
export declare const FIGLET_STATE_KEY: unique symbol;
|
|
8
4
|
/**
|
|
9
5
|
* Per-textmodifier FIGlet plugin state.
|
|
10
6
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textmode.figlet.js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4-beta.1",
|
|
4
4
|
"description": "FIGlet font support for textmode.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"devEngines": {
|
|
@@ -33,59 +33,44 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
|
-
"dev": "
|
|
37
|
-
"build:bundle": "
|
|
36
|
+
"dev": "textmode-build dev --port 5175 --host",
|
|
37
|
+
"build:bundle": "textmode-build build",
|
|
38
38
|
"build:types": "textmode-types build",
|
|
39
39
|
"build": "npm run build:bundle && npm run build:types",
|
|
40
|
-
"check": "
|
|
40
|
+
"check": "npm run format:check && npm run lint && npm run lint:markdown && npm run typecheck && npm run docs:check && npm run test && npm run build && npm run types:verify",
|
|
41
41
|
"docs:links:add": "textmode-docs links add",
|
|
42
42
|
"docs:api:check": "textmode-docs api-check",
|
|
43
43
|
"docs:check": "textmode-docs check",
|
|
44
44
|
"docs:dev": "textmode-docs watch",
|
|
45
45
|
"docs:build": "textmode-docs build",
|
|
46
|
-
"preview": "
|
|
47
|
-
"test": "
|
|
48
|
-
"test:watch": "
|
|
49
|
-
"test:unit": "
|
|
50
|
-
"test:integration": "
|
|
51
|
-
"format": "
|
|
52
|
-
"format:check": "
|
|
46
|
+
"preview": "textmode-build preview",
|
|
47
|
+
"test": "textmode-build test",
|
|
48
|
+
"test:watch": "textmode-build test:watch",
|
|
49
|
+
"test:unit": "textmode-build test --project unit",
|
|
50
|
+
"test:integration": "textmode-build test --project integration",
|
|
51
|
+
"format": "textmode-lint format",
|
|
52
|
+
"format:check": "textmode-lint format:check",
|
|
53
53
|
"typecheck": "textmode-types check",
|
|
54
54
|
"types:verify": "textmode-types verify",
|
|
55
|
-
"lint:markdown": "
|
|
56
|
-
"lint:markdown:fix": "
|
|
57
|
-
"lint": "
|
|
58
|
-
"prepare": "
|
|
59
|
-
"prepack": "
|
|
60
|
-
"release": "
|
|
55
|
+
"lint:markdown": "textmode-lint lint:markdown",
|
|
56
|
+
"lint:markdown:fix": "textmode-lint lint:markdown --fix",
|
|
57
|
+
"lint": "textmode-lint lint src",
|
|
58
|
+
"prepare": "textmode-release hooks",
|
|
59
|
+
"prepack": "npm run build && npm run types:verify",
|
|
60
|
+
"release": "textmode-release release"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"textmode.js": ">=0.
|
|
63
|
+
"textmode.js": ">=0.17.2-beta.1 <0.20.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@
|
|
67
|
-
"@textmode/
|
|
68
|
-
"@textmode/
|
|
69
|
-
"@textmode/
|
|
70
|
-
"@textmode/markdownlint-config": "^0.1.1",
|
|
71
|
-
"@textmode/prettier-config": "^0.1.0",
|
|
72
|
-
"@textmode/release-config": "^0.1.2",
|
|
73
|
-
"@textmode/tooling-scripts": "^0.5.0",
|
|
66
|
+
"@textmode/build": "^0.1.0",
|
|
67
|
+
"@textmode/docs": "^0.3.0",
|
|
68
|
+
"@textmode/lint": "^0.1.0",
|
|
69
|
+
"@textmode/release": "^0.2.0",
|
|
74
70
|
"@textmode/tsconfig": "^0.2.0",
|
|
75
|
-
"@textmode/vite-config": "^0.1.0",
|
|
76
|
-
"@textmode/vitest-config": "^0.2.1",
|
|
77
71
|
"@types/node": "^24.0.0",
|
|
78
|
-
"
|
|
79
|
-
"eslint": "^10.6.0",
|
|
80
|
-
"jsdom": "^30.0.0",
|
|
81
|
-
"lint-staged": "^17.0.8",
|
|
82
|
-
"markdownlint-cli2": "^0.22.1",
|
|
83
|
-
"prettier": "^3.9.4",
|
|
84
|
-
"semantic-release": "^25.0.5",
|
|
85
|
-
"terser": "^5.46.1",
|
|
86
|
-
"textmode.js": "^0.17.0-beta.2",
|
|
72
|
+
"textmode.js": "^0.17.2-beta.1",
|
|
87
73
|
"typescript": "^6.0.3",
|
|
88
|
-
"vite": "^8.1.3",
|
|
89
74
|
"vitest": "^4.1.10"
|
|
90
75
|
},
|
|
91
76
|
"keywords": [
|
|
@@ -99,44 +84,12 @@
|
|
|
99
84
|
"author": "humanbydefinition <hello@textmode.art> (https://code.textmode.art)",
|
|
100
85
|
"license": "MIT",
|
|
101
86
|
"homepage": "https://code.textmode.art",
|
|
102
|
-
"
|
|
103
|
-
"*": "prettier --ignore-unknown --write"
|
|
104
|
-
},
|
|
105
|
-
"prettier": "@textmode/prettier-config",
|
|
106
|
-
"commitlint": {
|
|
107
|
-
"extends": [
|
|
108
|
-
"@textmode/commitlint-config"
|
|
109
|
-
]
|
|
110
|
-
},
|
|
87
|
+
"prettier": "@textmode/lint/prettier",
|
|
111
88
|
"repository": {
|
|
112
89
|
"type": "git",
|
|
113
90
|
"url": "git+https://github.com/humanbydefinition/textmode.figlet.js.git"
|
|
114
91
|
},
|
|
115
92
|
"bugs": {
|
|
116
93
|
"url": "https://github.com/humanbydefinition/textmode.figlet.js/issues"
|
|
117
|
-
},
|
|
118
|
-
"markdownlint-cli2": {
|
|
119
|
-
"globs": [
|
|
120
|
-
"**/*.md"
|
|
121
|
-
],
|
|
122
|
-
"ignores": [
|
|
123
|
-
"api/**",
|
|
124
|
-
"node_modules/**",
|
|
125
|
-
"dist/**",
|
|
126
|
-
"examples/**/*.md",
|
|
127
|
-
"**/CHANGELOG.md"
|
|
128
|
-
],
|
|
129
|
-
"fix": false,
|
|
130
|
-
"outputFormatters": [
|
|
131
|
-
[
|
|
132
|
-
"markdownlint-cli2-formatter-default"
|
|
133
|
-
]
|
|
134
|
-
],
|
|
135
|
-
"config": {
|
|
136
|
-
"extends": "@textmode/markdownlint-config"
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
"release": {
|
|
140
|
-
"extends": "@textmode/release-config"
|
|
141
94
|
}
|
|
142
95
|
}
|