textmode.figlet.js 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/textmode.figlet.esm.js +1 -1
- package/dist/textmode.figlet.umd.js +1 -1
- package/dist/types/augmentations/textmode.d.ts +0 -2
- package/dist/types/figfont/FigFontParser.d.ts +0 -1
- package/dist/types/figfont/FigLayoutEngine.d.ts +3 -12
- package/dist/types/figfont/FigSmushRules.d.ts +1 -1
- package/dist/types/figfont/TextmodeFigFont.d.ts +19 -5
- package/dist/types/figfont/index.d.ts +1 -1
- package/dist/types/figfont/types.d.ts +12 -32
- package/dist/types/index.d.ts +0 -17
- package/dist/types/plugin/FigletPlugin.d.ts +0 -2
- package/package.json +11 -11
- package/dist/types/utils/Disposable.d.ts +0 -16
|
@@ -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.u(n[1],"height"),baseline:this.u(n[2],"baseline"),maxLength:this.u(n[3],"maxLength"),oldLayout:this.u(n[4],"oldLayout"),commentLines:this.u(n[5],"commentLines"),printDirection:this.u(n[6]??"0","printDirection"),fullLayout:this.u(n[7]??"0","fullLayout"),codetagCount:this.u(n[8]??"0","codetagCount")}}static o(t,e,r,i){let s=e;for(const o of n){const e=this.h(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.p(e);i+=1;const o=this.h(t,i,n.height,s);r.set(s,o),i+=n.height}}static h(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 p(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 u(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 _(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{k;H;M;constructor(t){this.k=t,this.H=i._(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.k.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)},u=o-this.O(s,o,c,n),h=Math.max(o,u+c.width),f=s.map(t=>Array.from({length:h},(e,n)=>t[n]));for(let t=0;t<this.k.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=u+s,h=n[a],f=this.P(a,t,s,r,c,l,o);if(!h){n[a]=f;continue}const d=i.I(h.char,o,this.k.hardblank,this.H);n[a]=this.D(h,f,d??o)}}s=f,o=h}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),u=Math.max(r,c.cols),h=Math.max(s,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 s=i.U(r.char,t.char,this.M);f[e][n]=this.D(r,{...t,row:e},s??t.char)}n=f,r=u,s=h,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.k.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.k.hardblank,this.H)}V(t,e={inputIndex:0,inputChar:String.fromCodePoint(t.code)},n=0){return Array.from({length:this.k.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.k.height;i+=1){const s=t[i]??[];for(let t=0;t<e;t+=1){const e=s[t];e&&e.char!==this.k.hardblank&&r.push({...e,col:t,row:i,lineIndex:n})}}return{lineIndex:n,cells:r,cols:e,rows:this.k.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;k;nt;rt;constructor(t,e,n){super(),this.et=t,this.k=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.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.k}}get characters(){return new Map(Array.from(this.nt,([t,e])=>[t,c(e)]))}get hardblank(){return this.k.hardblank}get height(){return this.k.height}get baseline(){return this.k.baseline}get defaultLayout(){return 128&this.k.fullLayout?"smushed":64&this.k.fullLayout?"fitted":-1===this.k.oldLayout?"full":0===this.k.oldLayout?"fitted":this.k.oldLayout>0?"smushed":"full"}get defaultPrintDirection(){return 1===this.k.printDirection?"rtl":"ltr"}get defaultVerticalLayout(){return 16384&this.k.fullLayout?"smushed":8192&this.k.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 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}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.wt(t,e,r)}wt(t,e,n){const r=this.gt(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._t(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._t(t,e)>n?(r.push(i),i=[s]):i=t}return 0===i.length?[[]]:(r.push(i),r)}_t(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}gt(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]}}function l(t,e){return u(t),t.ownedFonts.add(e),e}function u(t){if(t.disposed)throw new e("FIGlet plugin has been disposed.")}function h(t){if(!t.disposed){t.disposed=!0,t.activeFont=void 0;for(const e of t.ownedFonts)e.dispose();t.ownedFonts.clear()}}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 w(t){const n=t.activeFont;if(!n)throw new e("No FIGlet font is active. Call figFont() first.");return n}var g={name:"textmode.figlet.js",install(t,e){const n={activeFont:void 0,align:"left",baseline:"baseline",ownedFonts:/* @__PURE__ */new Set,disposed:!1};try{!function(t,e){t.defineExtension("textmodifier","loadFigFont",{value:async function(t){u(e);const n=await a.it(t);try{return l(e,n)}catch(r){throw n.dispose(),r}}}),t.defineExtension("textmodifier","parseFigFont",{value:function(t,n){const r=a.st(t,n);try{return l(e,r)}catch(i){throw r.dispose(),i}}}),t.defineExtension("textmodifier","figFont",{value:function(t){if(void 0===t)return e.activeFont;e.activeFont=t}}),t.defineExtension("textmodifier","figText",{value:function(t,n,r,i={}){const s=w(e),o=s.planText(t,i),a=n+(c=o.cols,"center"===(l=e.align)?-Math.floor(c/2):"right"===l?-(c-1):0);var c,l;const u=r+(h=o.rows,g=s.baseline,"top"===(p=e.baseline)?0:"center"===p?-Math.floor(h/2):"bottom"===p?-(h-1):-(g-1));var h,g,p;this.push();try{this.translate(a,u,0);for(const t of o.cells){this.push();try{this.translate(t.col,t.row,0);const e=f(i.charColor,t),n=f(i.cellColor,t);this.char(t.char),void 0!==e&&d(this,"charColor",e),void 0!==n&&d(this,"cellColor",n),this.point()}finally{this.pop()}}}finally{this.pop()}}}),t.defineExtension("textmodifier","figTextWidth",{value:function(t,n={}){return w(e).measureText(t,n).cols}}),t.defineExtension("textmodifier","figTextHeight",{value:function(t,n={}){return w(e).measureText(t,n).rows}}),t.defineExtension("textmodifier","figTextBounds",{value:function(t,n={}){return w(e).measureText(t,n)}}),t.defineExtension("textmodifier","figTextAlign",{value:function(t){if(void 0===t)return e.align;e.align=t}}),t.defineExtension("textmodifier","figTextBaseline",{value:function(t){if(void 0===t)return e.baseline;e.baseline=t}})}(e,n)}catch(r){throw h(n),r}return()=>h(n)}};"undefined"!=typeof window&&(window.FigletPlugin=g,window.TextmodeFigFont=a,window.FigFontParser=r,window.FigLayoutEngine=s,window.FigSmushRules=i,window.FIGFONT_REQUIRED_CODEPOINTS=n);export{n as FIGFONT_REQUIRED_CODEPOINTS,r as FigFontParser,s as FigLayoutEngine,i as FigSmushRules,g as FigletPlugin,a as TextmodeFigFont};
|
|
1
|
+
var t=class t extends Error{constructor(e,r){super(t.formatMessage(e,r)),this.name="FigletError"}static formatMessage(e,r){return r&&0!==Object.keys(r).length?`${e}\n\nContext:${Object.entries(r).map(([e,r])=>`\n - ${e}: ${t.formatValue(r)}`).join("")}`:e}static formatValue(t){return"string"==typeof t?`"${t}"`:String(t)}},e=[...Array.from({length:95},(t,e)=>e+32),196,214,220,228,246,252,223],r=class{static t(e){if(0===e.length)throw new t("Cannot parse an empty FIGfont file.");const r=e.replace(/\r\n?/g,"\n").split("\n"),n=r[0];if(!n)throw new t("Missing FIGfont header line.");const i=this.i(n);let s=1+i.commentLines;if(s>r.length)throw new t("FIGfont comment line count exceeds file length.",{commentLines:i.commentLines,totalLines:r.length});const o=/* @__PURE__ */new Map;return s=this.o(r,s,i,o),this.l(r,s,i,o),{header:i,characters:o}}static i(e){const r=e.trim().split(/\s+/),n=r[0]??"";if(n.length<6)throw new t("Invalid FIGfont header token.",{headerToken:n});const i=n.slice(0,5),s=n.slice(5);if("flf2a"!==i)throw new t("Unsupported FIGfont signature.",{signature:i});if(1!==s.length)throw new t("FIGfont hardblank must be a single character.",{hardblank:s});if(r.length<6)throw new t("Incomplete FIGfont header.",{headerLine:e});return{signature:i,hardblank:s,height:this.h(r[1],"height"),baseline:this.h(r[2],"baseline"),maxLength:this.h(r[3],"maxLength"),oldLayout:this.h(r[4],"oldLayout"),commentLines:this.h(r[5],"commentLines"),printDirection:this.h(r[6]??"0","printDirection"),fullLayout:this.h(r[7]??"0","fullLayout"),codetagCount:this.h(r[8]??"0","codetagCount")}}static o(t,r,n,i){let s=r;for(const o of e){const e=this.u(t,s,n.height,o);i.set(o,e),s+=n.height}return s}static l(t,e,r,n){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,r.height,s);n.set(s,o),i+=r.height}}static u(e,r,n,i){if(r+n>e.length)throw new t("Unexpected end of FIGfont character data.",{codePoint:i,startIndex:r,height:n,totalLines:e.length});const s=[];let o=0;for(let a=0;a<n;a+=1){const n=e[r+a]??"";if(0===n.length)throw new t("Encountered an empty FIGcharacter row.",{codePoint:i,row:a,startIndex:r});const c=n.at(-1);if(!c)throw new t("Failed to determine FIGcharacter endmark.",{codePoint:i,row:a});let l=n;for(;l.endsWith(c);)l=l.slice(0,-1);s.push(l),o=Math.max(o,l.length)}return{code:i,lines:s,width:o}}static _(e){const r=e.split(/\s+/,1)[0];if(/^[-+]?0x[0-9a-f]+$/i.test(r))return Number.parseInt(r,16);if(/^[-+]?0[0-7]+$/.test(r))return Number.parseInt(r,8);if(/^[-+]?\d+$/.test(r))return Number.parseInt(r,10);throw new t("Invalid FIGfont code tag.",{codetagLine:e})}static h(e,r){if(!/^-?\d+$/.test(e))throw new t("Invalid FIGfont header value.",{field:r,token:e});return Number.parseInt(e,10)}},n=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 m(t){return 0!==t.fullLayout?63&t.fullLayout:t.oldLayout>0?63&t.oldLayout:0}static p(t){return 7936&t.fullLayout}static I(t,e,r,n){return" "===t?e:" "===e?t:0===n?this.L(t,e):(0!==(n&this.RULE_EQUAL_CHARACTER)?this.R(t,e,r):null)??(0!==(n&this.RULE_UNDERSCORE)?this.v(t,e):null)??(0!==(n&this.RULE_HIERARCHY)?this.C(t,e):null)??(0!==(n&this.RULE_OPPOSITE_PAIR)?this.A(t,e):null)??(0!==(n&this.RULE_BIG_X)?this.F(t,e):null)??(0!==(n&this.RULE_HARDBLANK)?this.T(t,e,r):null)}static L(t,e){return" "===t?e:" "===e?t:e}static U(t,e,r){return" "===t?e:" "===e?t:0===r?this.L(t,e):(0!==(r&this.VERTICAL_RULE_EQUAL_CHARACTER)?this.R(t,e," "):null)??(0!==(r&this.VERTICAL_RULE_UNDERSCORE)?this.v(t,e):null)??(0!==(r&this.VERTICAL_RULE_HIERARCHY)?this.C(t,e):null)??(0!==(r&this.VERTICAL_RULE_HORIZONTAL_LINE)?this.k(t,e):null)??(0!==(r&this.VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH)?this.M(t,e):null)}static R(t,e,r){return t===e&&t!==r?t:null}static v(t,e){const r="|/\\[]{}()<>";return"_"===t&&r.includes(e)?e:"_"===e&&r.includes(t)?t:null}static C(t,e){const r=["|","/\\","[]","{}","()","<>"],n=r.findIndex(e=>e.includes(t)),i=r.findIndex(t=>t.includes(e));return-1===n||-1===i||n===i?null:n>i?t:e}static A(t,e){return["[]","][","{}","}{","()",")("].includes(`${t}${e}`)?"|":null}static F(t,e){const r=`${t}${e}`;return"/\\"===r?"|":"\\/"===r?"Y":"><"===r?"X":null}static T(t,e,r){return t===r&&e===r?r:null}static k(t,e){const r=`${t}${e}`;return"-_"===r||"_-"===r?"=":null}static M(t,e){return"|"===t&&"|"===e?"|":null}},i=class{G;H;S;constructor(t){this.G=t,this.H=n.m(t),this.S=n.p(t)}$(t,e,r){if(0===t.length)return{lineIndex:r,cells:[],cols:0,rows:this.G.height};const i=t[0];let s=this.V(i,r),o=i.figChar.width;for(let a=1;a<t.length;a+=1){const i=t[a],{figChar:c}=i,l=o-this.N(s,o,c,e),h=Math.max(o,l+c.width),u=s.map(t=>Array.from({length:h},(e,r)=>t[r]));for(let t=0;t<this.G.height;t+=1){const e=c.lines[t]??"",s=u[t];for(let o=0;o<c.width;o+=1){const a=e[o]??" ";if(" "===a)continue;const c=l+o,h=s[c],u=this.O(c,t,o,r,i,a);if(!h){s[c]=u;continue}const f=n.I(h.char,a,this.G.hardblank,this.H);s[c]=this.P(h,u,f??a)}}s=u,o=h}return this.B(s,o,r)}D(t,e){if(0===t.length)return{cells:[],lines:[],cols:0,rows:0};let r=this.W(t[0]),i=t[0].cols,s=t[0].rows;const o=[this.j(t[0],0)];for(let a=1;a<t.length;a+=1){const c=t[a],l=s-this.q(r,s,i,c,e),h=Math.max(i,c.cols),u=Math.max(s,l+c.rows),f=Array.from({length:u},(t,e)=>Array.from({length:h},(t,n)=>r[e]?.[n]));for(const t of c.cells){const e=l+t.row,r=t.col,i=f[e]?.[r];if(!i){f[e][r]={...t,row:e};continue}const s=n.U(i.char,t.char,this.S);f[e][r]=this.P(i,{...t,row:e},s??t.char)}r=f,i=h,s=u,o.push(this.j(c,l))}return this.X(r,i,s,o)}N(t,e,r,n){if("full"===n)return 0;for(let i=e;i>=0;i-=1){let s=!0;for(let o=0;o<this.G.height&&s;o+=1){const a=t[o]??[],c=r.lines[o]??"";for(let t=0;t<i;t+=1){const r=a[e-i+t]?.char??" ",o=c[t]??" ";if(!this.Y(r,o,n)){s=!1;break}}}if(s)return i}return 0}Y(t,e,r){return" "===t||" "===e||"fitted"!==r&&null!==n.I(t,e,this.G.hardblank,this.H)}V(t,e=0){const{figChar:r}=t;return Array.from({length:this.G.height},(n,i)=>{const s=r.lines[i]??"";return Array.from({length:r.width},(r,n)=>{const o=s[n]??" ";return" "===o?void 0:this.O(n,i,n,e,t,o)})})}O(t,e,r,n,i,s){return{char:s,col:t,row:e,inputIndex:i.inputIndex,inputChar:i.inputChar,figCharCode:i.figChar.code,subRow:e,subCol:r,lineIndex:n}}P(t,e,r){return r===t.char?t:{...e,char:r}}B(t,e,r){const n=[];for(let i=0;i<this.G.height;i+=1){const s=t[i]??[];for(let t=0;t<e;t+=1){const e=s[t];e&&e.char!==this.G.hardblank&&n.push({...e,col:t,row:i,lineIndex:r})}}return{lineIndex:r,cells:n,cols:e,rows:this.G.height}}q(t,e,r,n,i){if("full"===i)return 0;const s=this.W(n),o=Math.min(e,n.rows),a=Math.max(r,n.cols);for(let c=o;c>=0;c-=1){let r=!0;for(let n=0;n<c&&r;n+=1){const o=t[e-c+n]??[],l=s[n]??[];for(let t=0;t<a;t+=1){const e=o[t]?.char??" ",n=l[t]?.char??" ";if(!this.K(e,n,i)){r=!1;break}}}if(r)return c}return 0}K(t,e,r){return" "===t||" "===e||"fitted"!==r&&null!==n.U(t,e,this.S)}W(t){const e=Array.from({length:t.rows},()=>Array.from({length:t.cols},()=>{}));for(const r of t.cells)e[r.row][r.col]=r;return e}j(t,e){return{...t,cells:t.cells.map(t=>({...t,row:t.row+e}))}}X(t,e,r,n){const i=[];for(let s=0;s<r;s+=1)for(let r=0;r<e;r+=1){const e=t[s]?.[r];e&&i.push({...e,row:s,col:r})}return{cells:i,lines:n,cols:e,rows:r}}},s=class e{Z;G;J;tt;et=/* @__PURE__ */new Set;rt=!1;constructor(t,e,r){this.Z=t,this.G=e,this.J=r,this.tt=new i(e)}nt(t){this.rt?t():this.et.add(t)}dispose(){if(!this.rt){this.rt=!0;for(const t of this.et)t();this.et.clear()}}static async it(e){const r=await fetch(e);if(!r.ok)throw new t("Failed to load FIGfont file.",{source:String(e),status:r.status,statusText:r.statusText});const n=await r.text();return this.st(this.ot(e),n)}static st(t,n){const i=r.t(n);return new e(t,i.header,i.characters)}ct(t){const e="number"==typeof t?t:t.codePointAt(0);if(void 0!==e)return this.J.get(e)}getCharacter(t){return o(this.ct(t))}planText(t,e={}){const r=e.horizontalLayout??this.defaultLayout,n=e.verticalLayout??this.defaultVerticalLayout,i=this.lt(e.direction),s=this.ht(t).map(t=>"rtl"===i?[...t].reverse():t).flatMap(t=>this.ut(t,r,e)).map((t,e)=>{const n=this.ft(t);return this.tt.$(n,r,e)}),o=this.tt.D(s,n);return{cells:o.cells,lines:o.lines,cols:o.cols,rows:o.rows,direction:i}}renderText(t,e={}){const r=this.planText(t,e),n=Array.from({length:r.rows},()=>Array.from({length:r.cols},()=>" "));for(const i of r.cells)n[i.row][i.col]=i.char;return{grid:n,cols:r.cols,rows:r.rows}}measureText(t,e={}){const r=this.planText(t,e);return{cols:r.cols,rows:r.rows}}get name(){return this.Z}get header(){return{...this.G}}get characters(){return new Map(Array.from(this.J,([t,e])=>[t,o(e)]))}get hardblank(){return this.G.hardblank}get height(){return this.G.height}get baseline(){return this.G.baseline}get defaultLayout(){return 128&this.G.fullLayout?"smushed":64&this.G.fullLayout?"fitted":-1===this.G.oldLayout?"full":0===this.G.oldLayout?"fitted":this.G.oldLayout>0?"smushed":"full"}get defaultPrintDirection(){return 1===this.G.printDirection?"rtl":"ltr"}get defaultVerticalLayout(){return 16384&this.G.fullLayout?"smushed":8192&this.G.fullLayout?"fitted":"full"}static ot(t){const e=t instanceof URL?t.pathname:t,r=(e.split(/[?#]/,1)[0]??e).split("/").filter(Boolean).pop()??"figfont";return r.toLowerCase().endsWith(".flf")?r.slice(0,-4)||"figfont":r}ht(t){const e=[[]];for(const[r,n]of Array.from(t).entries())"\n"!==n?e[e.length-1].push({character:n,inputIndex:r}):e.push([]);return e}ft(e){const r=e.map(({character:t,inputIndex:e})=>({figChar:this.ct(t)??this.ct(32),inputChar:t,inputIndex:e})),n=r.find(t=>void 0===t.figChar);if(n)throw new t("FIGfont is missing a required character for layout.",{character:n.inputChar,index:n.inputIndex});return r}ut(t,e,r){const n="number"==typeof r.maxCols&&Number.isFinite(r.maxCols)?Math.floor(r.maxCols):void 0,i=r.wrap??"none";return 0===t.length||!n||n<1||"none"===i?[t]:"char"===i?this.dt(t,e,n):this.wt(t,e,n)}wt(t,e,r){const n=this._t(t);if(!n.some(t=>!t.isWhitespace))return[t];const i=[];let s=[],o=[];for(const a of n){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.gt(t,e)>r?(i.push(s),s=a.characters.slice()):s=t,o=[]}return 0===s.length?[[]]:(i.push(s),i)}dt(t,e,r){const n=[];let i=[];for(const s of t){const t=i.concat(s);i.length>0&&this.gt(t,e)>r?(n.push(i),i=[s]):i=t}return 0===i.length?[[]]:(n.push(i),n)}gt(t,e){const r=this.ft(t);return this.tt.$(r,e,0).cols}_t(t){const e=[];for(const r of t){const t=/\s/u.test(r.character),n=e[e.length-1];n&&n.isWhitespace===t?n.characters.push(r):e.push({isWhitespace:t,characters:[r]})}return e}lt(t){return"ltr"===t||"rtl"===t?t:this.defaultPrintDirection}};function o(t){if(t)return{...t,lines:[...t.lines]}}function a(t,e){return c(t),t.ownedFonts.add(e),e.nt(()=>{t.ownedFonts.delete(e),t.activeFont===e&&(t.activeFont=void 0)}),e}function c(e){if(e.disposed)throw new t("FIGlet plugin has been disposed.")}function l(t){if(!t.disposed){t.disposed=!0,t.activeFont=void 0;for(const e of[...t.ownedFonts])e.dispose();t.ownedFonts.clear()}}function h(t,e){if(void 0!==t)return"function"==typeof t?t(e):t}function u(t,e,r){if(Array.isArray(r))return 4===r.length?void t[e](r[0],r[1],r[2],r[3]):void t[e](r[0],r[1],r[2]);t[e](r)}function f(e){c(e);const r=e.activeFont;if(!r)throw new t("No FIGlet font is active. Call figFont() first.");return r}var d={name:"textmode.figlet.js",install(t,e){const r={activeFont:void 0,align:"left",baseline:"baseline",ownedFonts:/* @__PURE__ */new Set,disposed:!1};try{!function(t,e){t.defineExtension("textmodifier","loadFigFont",{value:async function(t){c(e);const r=await s.it(t);try{return a(e,r)}catch(n){throw r.dispose(),n}}}),t.defineExtension("textmodifier","parseFigFont",{value:function(t,r){const n=s.st(t,r);try{return a(e,n)}catch(i){throw n.dispose(),i}}}),t.defineExtension("textmodifier","figFont",{value:function(t){if(c(e),void 0===t)return e.activeFont;e.activeFont=t}}),t.defineExtension("textmodifier","figText",{value:function(t,r,n,i={}){const s=f(e),o=s.planText(t,i),a=r+(c=o.cols,"center"===(l=e.align)?-Math.floor(c/2):"right"===l?-(c-1):0);var c,l;const d=n+(w=o.rows,_=s.baseline,"top"===(g=e.baseline)?0:"center"===g?-Math.floor(w/2):"bottom"===g?-(w-1):-(_-1));var w,_,g;this.push();try{this.translate(a,d,0);for(const t of o.cells){this.push();try{this.translate(t.col,t.row,0);const e=h(i.charColor,t),r=h(i.cellColor,t);this.char(t.char),void 0!==e&&u(this,"charColor",e),void 0!==r&&u(this,"cellColor",r),this.point()}finally{this.pop()}}}finally{this.pop()}}}),t.defineExtension("textmodifier","figTextWidth",{value:function(t,r={}){return f(e).measureText(t,r).cols}}),t.defineExtension("textmodifier","figTextHeight",{value:function(t,r={}){return f(e).measureText(t,r).rows}}),t.defineExtension("textmodifier","figTextBounds",{value:function(t,r={}){return f(e).measureText(t,r)}}),t.defineExtension("textmodifier","figTextAlign",{value:function(t){if(c(e),void 0===t)return e.align;e.align=t}}),t.defineExtension("textmodifier","figTextBaseline",{value:function(t){if(c(e),void 0===t)return e.baseline;e.baseline=t}})}(e,r)}catch(n){throw l(r),n}return()=>l(r)}};"undefined"!=typeof window&&(window.FigletPlugin=d,window.TextmodeFigFont=s,window.FigFontParser=r,window.FigLayoutEngine=i,window.FigSmushRules=n,window.FIGFONT_REQUIRED_CODEPOINTS=e);export{e as FIGFONT_REQUIRED_CODEPOINTS,r as FigFontParser,i as FigLayoutEngine,n as FigSmushRules,d as FigletPlugin,s 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 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.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 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 S(t,e){const n=`${t}${e}`;return"-_"===n||"_-"===n?"=":null}static $(t,e){return"|"===t&&"|"===e?"|":null}},o=class{M;k;H;constructor(t){this.M=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.M.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.M.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.M.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.q(t[0]),r=t[0].cols,i=t[0].rows;const o=[this.W(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.W(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.M.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.M.hardblank,this.k)}O(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.q(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)}q(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}W(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;M;nt;rt;constructor(t,e,n){super(),this.et=t,this.M=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.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}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.wt(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._t(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._t(t,e)>n?(r.push(i),i=[s]):i=t}return 0===i.length?[[]]:(r.push(i),r)}_t(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}wt(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]}}function u(t,e){return h(t),t.ownedFonts.add(e),e}function h(t){if(t.disposed)throw new n("FIGlet plugin has been disposed.")}function f(t){if(!t.disposed){t.disposed=!0,t.activeFont=void 0;for(const e of t.ownedFonts)e.dispose();t.ownedFonts.clear()}}function d(t,e){if(void 0!==t)return"function"==typeof t?t(e):t}function p(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 g(t){const e=t.activeFont;if(!e)throw new n("No FIGlet font is active. Call figFont() first.");return e}var w={name:"textmode.figlet.js",install(t,e){const n={activeFont:void 0,align:"left",baseline:"baseline",ownedFonts:new Set,disposed:!1};try{!function(t,e){t.defineExtension("textmodifier","loadFigFont",{value:async function(t){h(e);const n=await l.it(t);try{return u(e,n)}catch(r){throw n.dispose(),r}}}),t.defineExtension("textmodifier","parseFigFont",{value:function(t,n){const r=l.st(t,n);try{return u(e,r)}catch(i){throw r.dispose(),i}}}),t.defineExtension("textmodifier","figFont",{value:function(t){if(void 0===t)return e.activeFont;e.activeFont=t}}),t.defineExtension("textmodifier","figText",{value:function(t,n,r,i={}){const s=g(e),o=s.planText(t,i),a=n+(l=o.cols,"center"===(c=e.align)?-Math.floor(l/2):"right"===c?-(l-1):0);var l,c;const u=r+(h=o.rows,f=s.baseline,"top"===(w=e.baseline)?0:"center"===w?-Math.floor(h/2):"bottom"===w?-(h-1):-(f-1));var h,f,w;this.push();try{this.translate(a,u,0);for(const t of o.cells){this.push();try{this.translate(t.col,t.row,0);const e=d(i.charColor,t),n=d(i.cellColor,t);this.char(t.char),void 0!==e&&p(this,"charColor",e),void 0!==n&&p(this,"cellColor",n),this.point()}finally{this.pop()}}}finally{this.pop()}}}),t.defineExtension("textmodifier","figTextWidth",{value:function(t,n={}){return g(e).measureText(t,n).cols}}),t.defineExtension("textmodifier","figTextHeight",{value:function(t,n={}){return g(e).measureText(t,n).rows}}),t.defineExtension("textmodifier","figTextBounds",{value:function(t,n={}){return g(e).measureText(t,n)}}),t.defineExtension("textmodifier","figTextAlign",{value:function(t){if(void 0===t)return e.align;e.align=t}}),t.defineExtension("textmodifier","figTextBaseline",{value:function(t){if(void 0===t)return e.baseline;e.baseline=t}})}(e,n)}catch(r){throw f(n),r}return()=>f(n)}};"undefined"!=typeof window&&(window.FigletPlugin=w,window.TextmodeFigFont=l,window.FigFontParser=i,window.FigLayoutEngine=o,window.FigSmushRules=s,window.FIGFONT_REQUIRED_CODEPOINTS=r),t.FIGFONT_REQUIRED_CODEPOINTS=r,t.FigFontParser=i,t.FigLayoutEngine=o,t.FigSmushRules=s,t.FigletPlugin=w,t.TextmodeFigFont=l});
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).TextmodeFiglet={})}(this,function(t){Object.defineProperty(t,Symbol.toStringTag,{value:"Module"});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(t){return"string"==typeof t?`"${t}"`:String(t)}},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=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});let l=r;for(;l.endsWith(c);)l=l.slice(0,-1);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)}},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 m(t){return 0!==t.fullLayout?63&t.fullLayout:t.oldLayout>0?63&t.oldLayout:0}static p(t){return 7936&t.fullLayout}static I(t,e,n,r){return" "===t?e:" "===e?t:0===r?this.L(t,e):(0!==(r&this.RULE_EQUAL_CHARACTER)?this.R(t,e,n):null)??(0!==(r&this.RULE_UNDERSCORE)?this.v(t,e):null)??(0!==(r&this.RULE_HIERARCHY)?this.C(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){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.R(t,e," "):null)??(0!==(n&this.VERTICAL_RULE_UNDERSCORE)?this.v(t,e):null)??(0!==(n&this.VERTICAL_RULE_HIERARCHY)?this.C(t,e):null)??(0!==(n&this.VERTICAL_RULE_HORIZONTAL_LINE)?this.M(t,e):null)??(0!==(n&this.VERTICAL_RULE_VERTICAL_LINE_SUPERSMUSH)?this.k(t,e):null)}static R(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 C(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 k(t,e){return"|"===t&&"|"===e?"|":null}},s=class{G;H;S;constructor(t){this.G=t,this.H=i.m(t),this.S=i.p(t)}$(t,e,n){if(0===t.length)return{lineIndex:n,cells:[],cols:0,rows:this.G.height};const r=t[0];let s=this.V(r,n),o=r.figChar.width;for(let a=1;a<t.length;a+=1){const r=t[a],{figChar:c}=r,l=o-this.N(s,o,c,e),h=Math.max(o,l+c.width),u=s.map(t=>Array.from({length:h},(e,n)=>t[n]));for(let t=0;t<this.G.height;t+=1){const e=c.lines[t]??"",s=u[t];for(let o=0;o<c.width;o+=1){const a=e[o]??" ";if(" "===a)continue;const c=l+o,h=s[c],u=this.O(c,t,o,n,r,a);if(!h){s[c]=u;continue}const f=i.I(h.char,a,this.G.hardblank,this.H);s[c]=this.P(h,u,f??a)}}s=u,o=h}return this.B(s,o,n)}D(t,e){if(0===t.length)return{cells:[],lines:[],cols:0,rows:0};let n=this.j(t[0]),r=t[0].cols,s=t[0].rows;const o=[this.W(t[0],0)];for(let a=1;a<t.length;a+=1){const c=t[a],l=s-this.q(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.S);f[e][n]=this.P(r,{...t,row:e},s??t.char)}n=f,r=h,s=u,o.push(this.W(c,l))}return this.X(n,r,s,o)}N(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.G.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.Y(n,o,r)){s=!1;break}}}if(s)return i}return 0}Y(t,e,n){return" "===t||" "===e||"fitted"!==n&&null!==i.I(t,e,this.G.hardblank,this.H)}V(t,e=0){const{figChar:n}=t;return Array.from({length:this.G.height},(r,i)=>{const s=n.lines[i]??"";return Array.from({length:n.width},(n,r)=>{const o=s[r]??" ";return" "===o?void 0:this.O(r,i,r,e,t,o)})})}O(t,e,n,r,i,s){return{char:s,col:t,row:e,inputIndex:i.inputIndex,inputChar:i.inputChar,figCharCode:i.figChar.code,subRow:e,subCol:n,lineIndex:r}}P(t,e,n){return n===t.char?t:{...e,char:n}}B(t,e,n){const r=[];for(let i=0;i<this.G.height;i+=1){const s=t[i]??[];for(let t=0;t<e;t+=1){const e=s[t];e&&e.char!==this.G.hardblank&&r.push({...e,col:t,row:i,lineIndex:n})}}return{lineIndex:n,cells:r,cols:e,rows:this.G.height}}q(t,e,n,r,i){if("full"===i)return 0;const s=this.j(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.S)}j(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}W(t,e){return{...t,cells:t.cells.map(t=>({...t,row:t.row+e}))}}X(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 t{Z;G;J;tt;et=new Set;nt=!1;constructor(t,e,n){this.Z=t,this.G=e,this.J=n,this.tt=new s(e)}rt(t){this.nt?t():this.et.add(t)}dispose(){if(!this.nt){this.nt=!0;for(const t of this.et)t();this.et.clear()}}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)}ct(t){const e="number"==typeof t?t:t.codePointAt(0);if(void 0!==e)return this.J.get(e)}getCharacter(t){return a(this.ct(t))}planText(t,e={}){const n=e.horizontalLayout??this.defaultLayout,r=e.verticalLayout??this.defaultVerticalLayout,i=this.lt(e.direction),s=this.ht(t).map(t=>"rtl"===i?[...t].reverse():t).flatMap(t=>this.ut(t,n,e)).map((t,e)=>{const r=this.ft(t);return this.tt.$(r,n,e)}),o=this.tt.D(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.Z}get header(){return{...this.G}}get characters(){return new Map(Array.from(this.J,([t,e])=>[t,a(e)]))}get hardblank(){return this.G.hardblank}get height(){return this.G.height}get baseline(){return this.G.baseline}get defaultLayout(){return 128&this.G.fullLayout?"smushed":64&this.G.fullLayout?"fitted":-1===this.G.oldLayout?"full":0===this.G.oldLayout?"fitted":this.G.oldLayout>0?"smushed":"full"}get defaultPrintDirection(){return 1===this.G.printDirection?"rtl":"ltr"}get defaultVerticalLayout(){return 16384&this.G.fullLayout?"smushed":8192&this.G.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}ht(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}ft(t){const n=t.map(({character:t,inputIndex:e})=>({figChar:this.ct(t)??this.ct(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.wt(t,e,r)}wt(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.gt(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.gt(t,e)>n?(r.push(i),i=[s]):i=t}return 0===i.length?[[]]:(r.push(i),r)}gt(t,e){const n=this.ft(t);return this.tt.$(n,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 a(t){if(t)return{...t,lines:[...t.lines]}}function c(t,e){return l(t),t.ownedFonts.add(e),e.rt(()=>{t.ownedFonts.delete(e),t.activeFont===e&&(t.activeFont=void 0)}),e}function l(t){if(t.disposed)throw new e("FIGlet plugin has been disposed.")}function h(t){if(!t.disposed){t.disposed=!0,t.activeFont=void 0;for(const e of[...t.ownedFonts])e.dispose();t.ownedFonts.clear()}}function u(t,e){if(void 0!==t)return"function"==typeof t?t(e):t}function f(t,e,n){if(Array.isArray(n))return 4===n.length?void t[e](n[0],n[1],n[2],n[3]):void t[e](n[0],n[1],n[2]);t[e](n)}function d(t){l(t);const n=t.activeFont;if(!n)throw new e("No FIGlet font is active. Call figFont() first.");return n}var w={name:"textmode.figlet.js",install(t,e){const n={activeFont:void 0,align:"left",baseline:"baseline",ownedFonts:new Set,disposed:!1};try{!function(t,e){t.defineExtension("textmodifier","loadFigFont",{value:async function(t){l(e);const n=await o.it(t);try{return c(e,n)}catch(r){throw n.dispose(),r}}}),t.defineExtension("textmodifier","parseFigFont",{value:function(t,n){const r=o.st(t,n);try{return c(e,r)}catch(i){throw r.dispose(),i}}}),t.defineExtension("textmodifier","figFont",{value:function(t){if(l(e),void 0===t)return e.activeFont;e.activeFont=t}}),t.defineExtension("textmodifier","figText",{value:function(t,n,r,i={}){const s=d(e),o=s.planText(t,i),a=n+(c=o.cols,"center"===(l=e.align)?-Math.floor(c/2):"right"===l?-(c-1):0);var c,l;const h=r+(w=o.rows,_=s.baseline,"top"===(g=e.baseline)?0:"center"===g?-Math.floor(w/2):"bottom"===g?-(w-1):-(_-1));var w,_,g;this.push();try{this.translate(a,h,0);for(const t of o.cells){this.push();try{this.translate(t.col,t.row,0);const e=u(i.charColor,t),n=u(i.cellColor,t);this.char(t.char),void 0!==e&&f(this,"charColor",e),void 0!==n&&f(this,"cellColor",n),this.point()}finally{this.pop()}}}finally{this.pop()}}}),t.defineExtension("textmodifier","figTextWidth",{value:function(t,n={}){return d(e).measureText(t,n).cols}}),t.defineExtension("textmodifier","figTextHeight",{value:function(t,n={}){return d(e).measureText(t,n).rows}}),t.defineExtension("textmodifier","figTextBounds",{value:function(t,n={}){return d(e).measureText(t,n)}}),t.defineExtension("textmodifier","figTextAlign",{value:function(t){if(l(e),void 0===t)return e.align;e.align=t}}),t.defineExtension("textmodifier","figTextBaseline",{value:function(t){if(l(e),void 0===t)return e.baseline;e.baseline=t}})}(e,n)}catch(r){throw h(n),r}return()=>h(n)}};"undefined"!=typeof window&&(window.FigletPlugin=w,window.TextmodeFigFont=o,window.FigFontParser=r,window.FigLayoutEngine=s,window.FigSmushRules=i,window.FIGFONT_REQUIRED_CODEPOINTS=n),t.FIGFONT_REQUIRED_CODEPOINTS=n,t.FigFontParser=r,t.FigLayoutEngine=s,t.FigSmushRules=i,t.FigletPlugin=w,t.TextmodeFigFont=o});
|
|
@@ -7,8 +7,6 @@ import type { FigTextAlign, FigTextBaseline, FigTextOptions } from '../figfont';
|
|
|
7
7
|
* FIGlet methods added to the `textmode.js` `Textmodifier` API when
|
|
8
8
|
* {@link FigletPlugin} is installed.
|
|
9
9
|
*
|
|
10
|
-
* @category Textmodifier extensions
|
|
11
|
-
*
|
|
12
10
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/TextmodifierFigletExtensions | TextmodifierFigletExtensions API reference}
|
|
13
11
|
*/
|
|
14
12
|
export interface TextmodifierFigletExtensions {
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
interface FigLayoutInput {
|
|
3
|
-
inputIndex: number;
|
|
4
|
-
inputChar: string;
|
|
5
|
-
}
|
|
1
|
+
import type { FigFontHeader, FigHorizontalLayout, FigRenderLine, FigTextCellContext, FigVerticalLayout, ResolvedFigInputCharacter } from './types';
|
|
6
2
|
/**
|
|
7
3
|
* Horizontal FIGlet layout engine for composing FIGcharacters into a character grid.
|
|
8
4
|
*
|
|
@@ -13,19 +9,15 @@ export declare class FigLayoutEngine {
|
|
|
13
9
|
private readonly _horizontalRuleMask;
|
|
14
10
|
private readonly _verticalRuleMask;
|
|
15
11
|
constructor(header: FigFontHeader);
|
|
16
|
-
/**
|
|
17
|
-
* Lay out a sequence of FIGcharacters into a combined 2D grid.
|
|
18
|
-
*/
|
|
19
|
-
_layoutHorizontal(figChars: readonly FigCharacter[], mode: FigHorizontalLayout): string[][];
|
|
20
12
|
/**
|
|
21
13
|
* Lay out a sequence of FIGcharacters into a positioned render line.
|
|
22
14
|
*/
|
|
23
|
-
_layoutHorizontalPlan(
|
|
15
|
+
_layoutHorizontalPlan(characters: readonly ResolvedFigInputCharacter[], mode: FigHorizontalLayout, lineIndex: number): FigRenderLine;
|
|
24
16
|
/**
|
|
25
17
|
* Compose multiple planned FIGlet lines vertically.
|
|
26
18
|
*/
|
|
27
19
|
_layoutVerticalPlan(lines: readonly FigRenderLine[], mode: FigVerticalLayout): {
|
|
28
|
-
cells:
|
|
20
|
+
cells: FigTextCellContext[];
|
|
29
21
|
lines: FigRenderLine[];
|
|
30
22
|
cols: number;
|
|
31
23
|
rows: number;
|
|
@@ -42,4 +34,3 @@ export declare class FigLayoutEngine {
|
|
|
42
34
|
private _offsetLine;
|
|
43
35
|
private _materializePlan;
|
|
44
36
|
}
|
|
45
|
-
export {};
|
|
@@ -33,7 +33,7 @@ export declare class FigSmushRules {
|
|
|
33
33
|
/**
|
|
34
34
|
* Universal smushing used when a font requests smushing without any rule bits enabled.
|
|
35
35
|
*/
|
|
36
|
-
static _smushUniversal(left: string, right: string
|
|
36
|
+
static _smushUniversal(left: string, right: string): string;
|
|
37
37
|
/**
|
|
38
38
|
* Attempt to smush two vertically overlapping characters.
|
|
39
39
|
*
|
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
import { Disposable } from '../utils/Disposable';
|
|
2
1
|
import type { FigCharacter, FigFontHeader, FigHorizontalLayout, FigRenderPlan, FigTextOptions, FigTextResult, FigVerticalLayout } from './types';
|
|
3
2
|
/**
|
|
4
3
|
* Parsed FIGfont resource used by `figText()` rendering.
|
|
5
4
|
*
|
|
6
|
-
* @category FIGfont resources
|
|
7
|
-
*
|
|
8
5
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/classes/TextmodeFigFont | TextmodeFigFont API reference}
|
|
9
6
|
*/
|
|
10
|
-
export declare class TextmodeFigFont
|
|
7
|
+
export declare class TextmodeFigFont {
|
|
11
8
|
private readonly _name;
|
|
12
9
|
private readonly _header;
|
|
13
10
|
private readonly _characters;
|
|
14
11
|
private readonly _layoutEngine;
|
|
12
|
+
private readonly _onDisposeCallbacks;
|
|
13
|
+
private _disposed;
|
|
15
14
|
private constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Register a callback to run when this font is disposed.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
_addOnDispose(callback: () => void): void;
|
|
21
|
+
/**
|
|
22
|
+
* Dispose resources associated with this FIGfont.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* {@includeCode ../../examples/TextmodeFigFont/dispose/sketch.js}
|
|
26
|
+
*
|
|
27
|
+
* @see {@link https://code.textmode.art/api/textmode.figlet.js/classes/TextmodeFigFont/methods/dispose | TextmodeFigFont.dispose API reference}
|
|
28
|
+
*/
|
|
29
|
+
dispose(): void;
|
|
16
30
|
/**
|
|
17
31
|
* Load a FIGfont from a URL or path.
|
|
18
32
|
*
|
|
@@ -32,6 +46,7 @@ export declare class TextmodeFigFont extends Disposable {
|
|
|
32
46
|
* @internal
|
|
33
47
|
*/
|
|
34
48
|
static _fromString(name: string, data: string): TextmodeFigFont;
|
|
49
|
+
private _getChar;
|
|
35
50
|
/**
|
|
36
51
|
* Look up a FIGcharacter by Unicode code point or by the first character in a string.
|
|
37
52
|
*
|
|
@@ -157,7 +172,6 @@ export declare class TextmodeFigFont extends Disposable {
|
|
|
157
172
|
get defaultVerticalLayout(): FigVerticalLayout;
|
|
158
173
|
private static _resolveName;
|
|
159
174
|
private _splitInputLines;
|
|
160
|
-
private _applyDirectionToInputLine;
|
|
161
175
|
private _resolveCharacters;
|
|
162
176
|
private _wrapInputLine;
|
|
163
177
|
private _wrapInputLineByWord;
|
|
@@ -2,5 +2,5 @@ export { FigFontParser } from './FigFontParser';
|
|
|
2
2
|
export { FigLayoutEngine } from './FigLayoutEngine';
|
|
3
3
|
export { FigSmushRules } from './FigSmushRules';
|
|
4
4
|
export { TextmodeFigFont } from './TextmodeFigFont';
|
|
5
|
-
export type { FigCharacter, FigFontHeader, FigHorizontalLayout, FigPrintDirection,
|
|
5
|
+
export type { FigCharacter, FigFontHeader, FigHorizontalLayout, FigPrintDirection, FigRenderLine, FigRenderPlan, FigTextAlign, FigTextBaseline, FigTextCellContext, FigTextColorResolver, FigTextColorValue, FigTextOptions, FigTextResult, FigVerticalLayout, FigWrapMode, ParsedFigFontData, ResolvedFigInputCharacter, } from './types';
|
|
6
6
|
export { FIGFONT_REQUIRED_CODEPOINTS } from './types';
|
|
@@ -9,8 +9,6 @@ export declare const FIGFONT_REQUIRED_CODEPOINTS: readonly number[];
|
|
|
9
9
|
/**
|
|
10
10
|
* Parsed FIGfont header metadata from the `.flf` header line.
|
|
11
11
|
*
|
|
12
|
-
* @category FIGfont resources
|
|
13
|
-
*
|
|
14
12
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/FigFontHeader | FigFontHeader API reference}
|
|
15
13
|
*/
|
|
16
14
|
export interface FigFontHeader {
|
|
@@ -78,8 +76,6 @@ export interface FigFontHeader {
|
|
|
78
76
|
/**
|
|
79
77
|
* A single parsed FIGcharacter from a FIGfont.
|
|
80
78
|
*
|
|
81
|
-
* @category FIGfont resources
|
|
82
|
-
*
|
|
83
79
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/FigCharacter | FigCharacter API reference}
|
|
84
80
|
*/
|
|
85
81
|
export interface FigCharacter {
|
|
@@ -112,9 +108,17 @@ export interface ParsedFigFontData {
|
|
|
112
108
|
characters: Map<number, FigCharacter>;
|
|
113
109
|
}
|
|
114
110
|
/**
|
|
115
|
-
*
|
|
111
|
+
* A resolved input character bound to its matching FIGcharacter glyph.
|
|
116
112
|
*
|
|
117
|
-
* @
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
export interface ResolvedFigInputCharacter {
|
|
116
|
+
figChar: FigCharacter;
|
|
117
|
+
inputChar: string;
|
|
118
|
+
inputIndex: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Supported horizontal layout modes for FIGlet rendering.
|
|
118
122
|
*
|
|
119
123
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/type-aliases/FigHorizontalLayout | FigHorizontalLayout API reference}
|
|
120
124
|
*/
|
|
@@ -122,40 +126,30 @@ export type FigHorizontalLayout = 'full' | 'fitted' | 'smushed';
|
|
|
122
126
|
/**
|
|
123
127
|
* Supported vertical layout modes for multi-line FIGlet rendering.
|
|
124
128
|
*
|
|
125
|
-
* @category Layout and rendering
|
|
126
|
-
*
|
|
127
129
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/type-aliases/FigVerticalLayout | FigVerticalLayout API reference}
|
|
128
130
|
*/
|
|
129
131
|
export type FigVerticalLayout = 'full' | 'fitted' | 'smushed';
|
|
130
132
|
/**
|
|
131
133
|
* Supported wrap modes for FIGlet text layout.
|
|
132
134
|
*
|
|
133
|
-
* @category Layout and rendering
|
|
134
|
-
*
|
|
135
135
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/type-aliases/FigWrapMode | FigWrapMode API reference}
|
|
136
136
|
*/
|
|
137
137
|
export type FigWrapMode = 'none' | 'word' | 'char';
|
|
138
138
|
/**
|
|
139
139
|
* Supported print directions for FIGlet text layout.
|
|
140
140
|
*
|
|
141
|
-
* @category Layout and rendering
|
|
142
|
-
*
|
|
143
141
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/type-aliases/FigPrintDirection | FigPrintDirection API reference}
|
|
144
142
|
*/
|
|
145
143
|
export type FigPrintDirection = 'font' | 'ltr' | 'rtl';
|
|
146
144
|
/**
|
|
147
145
|
* Accepted color input for per-cell FIGlet styling.
|
|
148
146
|
*
|
|
149
|
-
* @category Styling
|
|
150
|
-
*
|
|
151
147
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/type-aliases/FigTextColorValue | FigTextColorValue API reference}
|
|
152
148
|
*/
|
|
153
149
|
export type FigTextColorValue = number | string | color.TextmodeColor | [number, number, number] | [number, number, number, number];
|
|
154
150
|
/**
|
|
155
151
|
* Public cell metadata exposed to FIGlet styling callbacks.
|
|
156
152
|
*
|
|
157
|
-
* @category Styling
|
|
158
|
-
*
|
|
159
153
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/FigTextCellContext | FigTextCellContext API reference}
|
|
160
154
|
*/
|
|
161
155
|
export interface FigTextCellContext {
|
|
@@ -217,16 +211,12 @@ export interface FigTextCellContext {
|
|
|
217
211
|
/**
|
|
218
212
|
* Resolver for per-cell FIGlet colors.
|
|
219
213
|
*
|
|
220
|
-
* @category Styling
|
|
221
|
-
*
|
|
222
214
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/type-aliases/FigTextColorResolver | FigTextColorResolver API reference}
|
|
223
215
|
*/
|
|
224
216
|
export type FigTextColorResolver = FigTextColorValue | ((cell: FigTextCellContext) => FigTextColorValue | undefined);
|
|
225
217
|
/**
|
|
226
218
|
* Layout options for rendering FIGlet text.
|
|
227
219
|
*
|
|
228
|
-
* @category Layout and rendering
|
|
229
|
-
*
|
|
230
220
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/interfaces/FigTextOptions | FigTextOptions API reference}
|
|
231
221
|
*/
|
|
232
222
|
export interface FigTextOptions {
|
|
@@ -273,12 +263,6 @@ export interface FigTextOptions {
|
|
|
273
263
|
*/
|
|
274
264
|
cellColor?: FigTextColorResolver;
|
|
275
265
|
}
|
|
276
|
-
/**
|
|
277
|
-
* A single drawable cell produced by FIGlet layout.
|
|
278
|
-
*
|
|
279
|
-
* @internal
|
|
280
|
-
*/
|
|
281
|
-
export type FigRenderCell = FigTextCellContext;
|
|
282
266
|
/**
|
|
283
267
|
* A single logical line within a planned FIGlet render.
|
|
284
268
|
*
|
|
@@ -288,7 +272,7 @@ export interface FigRenderLine {
|
|
|
288
272
|
/** Logical line index. */
|
|
289
273
|
lineIndex: number;
|
|
290
274
|
/** Drawable cells in row-major order. */
|
|
291
|
-
cells:
|
|
275
|
+
cells: FigTextCellContext[];
|
|
292
276
|
/** Width of the line in grid cells, including blanks. */
|
|
293
277
|
cols: number;
|
|
294
278
|
/** Height of the line in grid cells. */
|
|
@@ -301,7 +285,7 @@ export interface FigRenderLine {
|
|
|
301
285
|
*/
|
|
302
286
|
export interface FigRenderPlan {
|
|
303
287
|
/** All drawable cells in row-major order. */
|
|
304
|
-
cells:
|
|
288
|
+
cells: FigTextCellContext[];
|
|
305
289
|
/** Logical lines included in the rendered output. */
|
|
306
290
|
lines: FigRenderLine[];
|
|
307
291
|
/** Total rendered width in grid cells. */
|
|
@@ -327,16 +311,12 @@ export interface FigTextResult {
|
|
|
327
311
|
/**
|
|
328
312
|
* Horizontal alignment options for `figText()` placement.
|
|
329
313
|
*
|
|
330
|
-
* @category Layout and rendering
|
|
331
|
-
*
|
|
332
314
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/type-aliases/FigTextAlign | FigTextAlign API reference}
|
|
333
315
|
*/
|
|
334
316
|
export type FigTextAlign = 'left' | 'center' | 'right';
|
|
335
317
|
/**
|
|
336
318
|
* Vertical alignment options for `figText()` placement.
|
|
337
319
|
*
|
|
338
|
-
* @category Layout and rendering
|
|
339
|
-
*
|
|
340
320
|
* @see {@link https://code.textmode.art/api/textmode.figlet.js/type-aliases/FigTextBaseline | FigTextBaseline API reference}
|
|
341
321
|
*/
|
|
342
322
|
export type FigTextBaseline = 'top' | 'center' | 'bottom' | 'baseline';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -21,23 +21,6 @@
|
|
|
21
21
|
* colors. Use {@link TextmodeFigFont} for reusable FIGfont resources and
|
|
22
22
|
* lower-level planning.
|
|
23
23
|
*
|
|
24
|
-
* @categoryDescription FIGfont resources
|
|
25
|
-
* Parsed FIGfont resources and metadata for inspecting characters and
|
|
26
|
-
* font-defined defaults.
|
|
27
|
-
*
|
|
28
|
-
* @categoryDescription Layout and rendering
|
|
29
|
-
* Options and value types that control FIGlet composition, wrapping,
|
|
30
|
-
* direction, and placement.
|
|
31
|
-
*
|
|
32
|
-
* @categoryDescription Styling
|
|
33
|
-
* Per-cell color values and callback context for styling rendered FIGlet text.
|
|
34
|
-
*
|
|
35
|
-
* @categoryDescription Textmodifier extensions
|
|
36
|
-
* Methods that {@link FigletPlugin} adds to a textmode.js sketch.
|
|
37
|
-
*
|
|
38
|
-
* @categoryDescription Workflow
|
|
39
|
-
* The plugin entrypoint that enables the FIGlet sketch workflow.
|
|
40
|
-
*
|
|
41
24
|
* @showCategories
|
|
42
25
|
*/
|
|
43
26
|
import './augmentations';
|
|
@@ -7,8 +7,6 @@ import type { TextmodePlugin } from 'textmode.js';
|
|
|
7
7
|
* detection and cleanup for the extension properties. Per-instance plugin state is
|
|
8
8
|
* cleared by the returned cleanup function.
|
|
9
9
|
*
|
|
10
|
-
* @category Workflow
|
|
11
|
-
*
|
|
12
10
|
* @example
|
|
13
11
|
* {@includeCode ../../examples/FigletPlugin/init/sketch.js}
|
|
14
12
|
*
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "textmode.figlet.js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "FIGlet font support for textmode.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"devEngines": {
|
|
7
7
|
"runtime": {
|
|
8
8
|
"name": "node",
|
|
9
|
-
"version": "
|
|
9
|
+
"version": ">=24.0.0",
|
|
10
10
|
"onFail": "error"
|
|
11
11
|
},
|
|
12
12
|
"packageManager": {
|
|
@@ -62,18 +62,18 @@
|
|
|
62
62
|
"release": "textmode-release release"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"textmode.js": "
|
|
65
|
+
"textmode.js": ">=0.18.0 <1.0.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@textmode/build": "^0.1.
|
|
69
|
-
"@textmode/docs": "^0.3
|
|
70
|
-
"@textmode/lint": "^0.1.
|
|
71
|
-
"@textmode/release": "^0.2.
|
|
72
|
-
"@textmode/tsconfig": "^0.2.
|
|
73
|
-
"@types/node": "^
|
|
74
|
-
"textmode.js": "^0.
|
|
68
|
+
"@textmode/build": "^0.1.2",
|
|
69
|
+
"@textmode/docs": "^0.4.3",
|
|
70
|
+
"@textmode/lint": "^0.1.3",
|
|
71
|
+
"@textmode/release": "^0.2.1",
|
|
72
|
+
"@textmode/tsconfig": "^0.2.2",
|
|
73
|
+
"@types/node": "^26.4.1",
|
|
74
|
+
"textmode.js": "^0.19.0",
|
|
75
75
|
"typescript": "^6.0.3",
|
|
76
|
-
"vitest": "^
|
|
76
|
+
"vitest": "^5.0.0"
|
|
77
77
|
},
|
|
78
78
|
"keywords": [
|
|
79
79
|
"ascii",
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base class for objects that support explicit disposal.
|
|
3
|
-
*/
|
|
4
|
-
export declare class Disposable {
|
|
5
|
-
private readonly _onDisposeCallbacks;
|
|
6
|
-
/**
|
|
7
|
-
* Register a callback to run when the resource is disposed.
|
|
8
|
-
*
|
|
9
|
-
* @param callback Callback to run on disposal.
|
|
10
|
-
*/
|
|
11
|
-
_addOnDispose(callback: () => void): void;
|
|
12
|
-
/**
|
|
13
|
-
* Dispose the resource and invoke all registered callbacks.
|
|
14
|
-
*/
|
|
15
|
-
dispose(): void;
|
|
16
|
-
}
|