UNPKG

@visulima/boxen

Version:

Util.format-like string formatting utility.

13 lines (12 loc) 28.8 kB
var Fe=Object.defineProperty;var w=(e,r)=>Fe(e,"name",{value:r,configurable:!0});import k from"node:process";import{execFileSync as Me}from"node:child_process";import _ from"node:fs";import Ne from"node:tty";var Le=Object.defineProperty,Pe=w((e,r)=>Le(e,"name",{value:r,configurable:!0}),"p$3"),_e=Object.defineProperty,ve=Pe((e,r)=>_e(e,"name",{value:r,configurable:!0}),"R"),De=Object.defineProperty,He=ve((e,r)=>De(e,"name",{value:r,configurable:!0}),"E");const xe=String.raw,ce=xe`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`,ze=He(()=>new RegExp(xe`\p{RI}{2}|(?![#*\d](?!\uFE0F?\u20E3))${ce}(?:\u200D${ce})*`,"gu"),"default");var qe=Object.defineProperty,Ke=ve((e,r)=>qe(e,"name",{value:r,configurable:!0}),"p");const O=new Set(["\x1B","›"]),G="\x07",$e="[",ae="m",V="]8;;",Ve=39,Ge=/[\u200B\uFEFF\u2060-\u2064]/g,Ue=new RegExp(`(?:\\${$e}(?<code>\\d+)m|\\${V}(?<uri>.*)${G})`),Ye=Object.freeze(new Map([[0,0],[1,22],[2,22],[3,23],[4,24],[7,27],[8,28],[9,29],[30,39],[31,39],[32,39],[33,39],[34,39],[35,39],[36,39],[37,39],[40,49],[41,49],[42,49],[43,49],[44,49],[45,49],[46,49],[47,49],[90,39]])),C=/[\u001B\u009B](?:[[()#;?]{0,10}(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><]|\]8;;[^\u0007\u001B]{0,100}(?:\u0007|\u001B\\))/g,D=/[\u0000-\u0008\n-\u001F\u007F-\u009F]{1,1000}/y,z=ze();Ke(e=>e.replace(z,""),"stripEmoji");var Ze=Object.defineProperty,S=w((e,r)=>Ze(e,"name",{value:r,configurable:!0}),"f$1"),Je=Object.defineProperty,$=S((e,r)=>Je(e,"name",{value:r,configurable:!0}),"c"),Qe=Object.defineProperty,U=$((e,r)=>Qe(e,"name",{value:r,configurable:!0}),"E");function N(e){return e===161||e===164||e===167||e===168||e===170||e===173||e===174||e>=176&&e<=180||e>=182&&e<=186||e>=188&&e<=191||e===198||e===208||e===215||e===216||e>=222&&e<=225||e===230||e>=232&&e<=234||e===236||e===237||e===240||e===242||e===243||e>=247&&e<=250||e===252||e===254||e===257||e===273||e===275||e===283||e===294||e===295||e===299||e>=305&&e<=307||e===312||e>=319&&e<=322||e===324||e>=328&&e<=331||e===333||e===338||e===339||e===358||e===359||e===363||e===462||e===464||e===466||e===468||e===470||e===472||e===474||e===476||e===593||e===609||e===708||e===711||e>=713&&e<=715||e===717||e===720||e>=728&&e<=731||e===733||e===735||e>=768&&e<=879||e>=913&&e<=929||e>=931&&e<=937||e>=945&&e<=961||e>=963&&e<=969||e===1025||e>=1040&&e<=1103||e===1105||e===8208||e>=8211&&e<=8214||e===8216||e===8217||e===8220||e===8221||e>=8224&&e<=8226||e>=8228&&e<=8231||e===8240||e===8242||e===8243||e===8245||e===8251||e===8254||e===8308||e===8319||e>=8321&&e<=8324||e===8364||e===8451||e===8453||e===8457||e===8467||e===8470||e===8481||e===8482||e===8486||e===8491||e===8531||e===8532||e>=8539&&e<=8542||e>=8544&&e<=8555||e>=8560&&e<=8569||e===8585||e>=8592&&e<=8601||e===8632||e===8633||e===8658||e===8660||e===8679||e===8704||e===8706||e===8707||e===8711||e===8712||e===8715||e===8719||e===8721||e===8725||e===8730||e>=8733&&e<=8736||e===8739||e===8741||e>=8743&&e<=8748||e===8750||e>=8756&&e<=8759||e===8764||e===8765||e===8776||e===8780||e===8786||e===8800||e===8801||e>=8804&&e<=8807||e===8810||e===8811||e===8814||e===8815||e===8834||e===8835||e===8838||e===8839||e===8853||e===8857||e===8869||e===8895||e===8978||e>=9312&&e<=9449||e>=9451&&e<=9547||e>=9552&&e<=9587||e>=9600&&e<=9615||e>=9618&&e<=9621||e===9632||e===9633||e>=9635&&e<=9641||e===9650||e===9651||e===9654||e===9655||e===9660||e===9661||e===9664||e===9665||e>=9670&&e<=9672||e===9675||e>=9678&&e<=9681||e>=9698&&e<=9701||e===9711||e===9733||e===9734||e===9737||e===9742||e===9743||e===9756||e===9758||e===9792||e===9794||e===9824||e===9825||e>=9827&&e<=9829||e>=9831&&e<=9834||e===9836||e===9837||e===9839||e===9886||e===9887||e===9919||e>=9926&&e<=9933||e>=9935&&e<=9939||e>=9941&&e<=9953||e===9955||e===9960||e===9961||e>=9963&&e<=9969||e===9972||e>=9974&&e<=9977||e===9979||e===9980||e===9982||e===9983||e===10045||e>=10102&&e<=10111||e>=11094&&e<=11097||e>=12872&&e<=12879||e>=57344&&e<=63743||e>=65024&&e<=65039||e===65533||e>=127232&&e<=127242||e>=127248&&e<=127277||e>=127280&&e<=127337||e>=127344&&e<=127373||e===127375||e===127376||e>=127387&&e<=127404||e>=917760&&e<=917999||e>=983040&&e<=1048573||e>=1048576&&e<=1114109}w(N,"A$1");S(N,"j");$(N,"A");U(N,"isAmbiguous");function I(e){return e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510}w(I,"p$2");S(I,"x");$(I,"B");U(I,"isFullWidth");function j(e){return e>=4352&&e<=4447||e===8986||e===8987||e===9001||e===9002||e>=9193&&e<=9196||e===9200||e===9203||e===9725||e===9726||e===9748||e===9749||e>=9776&&e<=9783||e>=9800&&e<=9811||e===9855||e>=9866&&e<=9871||e===9875||e===9889||e===9898||e===9899||e===9917||e===9918||e===9924||e===9925||e===9934||e===9940||e===9962||e===9970||e===9971||e===9973||e===9978||e===9981||e===9989||e===9994||e===9995||e===10024||e===10060||e===10062||e>=10067&&e<=10069||e===10071||e>=10133&&e<=10135||e===10160||e===10175||e===11035||e===11036||e===11088||e===11093||e>=11904&&e<=11929||e>=11931&&e<=12019||e>=12032&&e<=12245||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12353&&e<=12438||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12773||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=42124||e>=42128&&e<=42182||e>=43360&&e<=43388||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=94176&&e<=94180||e===94192||e===94193||e>=94208&&e<=100343||e>=100352&&e<=101589||e>=101631&&e<=101640||e>=110576&&e<=110579||e>=110581&&e<=110587||e===110589||e===110590||e>=110592&&e<=110882||e===110898||e>=110928&&e<=110930||e===110933||e>=110948&&e<=110951||e>=110960&&e<=111355||e>=119552&&e<=119638||e>=119648&&e<=119670||e===126980||e===127183||e===127374||e>=127377&&e<=127386||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e===127568||e===127569||e>=127584&&e<=127589||e>=127744&&e<=127776||e>=127789&&e<=127797||e>=127799&&e<=127868||e>=127870&&e<=127891||e>=127904&&e<=127946||e>=127951&&e<=127955||e>=127968&&e<=127984||e===127988||e>=127992&&e<=128062||e===128064||e>=128066&&e<=128252||e>=128255&&e<=128317||e>=128331&&e<=128334||e>=128336&&e<=128359||e===128378||e===128405||e===128406||e===128420||e>=128507&&e<=128591||e>=128640&&e<=128709||e===128716||e>=128720&&e<=128722||e>=128725&&e<=128727||e>=128732&&e<=128735||e===128747||e===128748||e>=128756&&e<=128764||e>=128992&&e<=129003||e===129008||e>=129292&&e<=129338||e>=129340&&e<=129349||e>=129351&&e<=129535||e>=129648&&e<=129660||e>=129664&&e<=129673||e>=129679&&e<=129734||e>=129742&&e<=129756||e>=129759&&e<=129769||e>=129776&&e<=129784||e>=131072&&e<=196605||e>=196608&&e<=262141}w(j,"I");S(j,"k");$(j,"C");U(j,"isWide");function Y(e){return N(e)?"ambiguous":I(e)?"fullwidth":e===8361||e>=65377&&e<=65470||e>=65474&&e<=65479||e>=65482&&e<=65487||e>=65490&&e<=65495||e>=65498&&e<=65500||e>=65512&&e<=65518?"halfwidth":e>=32&&e<=126||e===162||e===163||e===165||e===166||e===172||e===175||e>=10214&&e<=10221||e===10629||e===10630?"narrow":j(e)?"wide":"neutral"}w(Y,"B$2");S(Y,"R");$(Y,"t$1");U(Y,"getCategory");var Xe=Object.defineProperty,Z=$((e,r)=>Xe(e,"name",{value:r,configurable:!0}),"t");function L(e){if(!Number.isSafeInteger(e))throw new TypeError(`Expected a code point, got \`${typeof e}\`.`)}w(L,"y$3");S(L,"O");$(L,"a");Z(L,"validate");function P(e){return L(e),Y(e)}w(P,"C$1");S(P,"v");$(P,"eastAsianWidthType");Z(P,"eastAsianWidthType");function te(e,{ambiguousAsWide:r=!1}={}){return L(e),I(e)||j(e)||r&&N(e)?2:1}w(te,"V$1");S(te,"q");$(te,"eastAsianWidth");Z(te,"eastAsianWidth");Z(e=>!(I(e)||j(e)),"_isNarrowWidth");var ei=Object.defineProperty,J=$((e,r)=>ei(e,"name",{value:r,configurable:!0}),"b");const he=new Map,H=/(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y,q=J(e=>e>=32&&e<=126?"latin":e===8203||e===8204||e===8205||e===8288?"zero":e<=31||e>=127&&e<=159?"control":e>=160&&e<=255||e>=9472&&e<=9599?"latin":e>=4352&&e<=4607||e>=11904&&e<=40959||e>=44032&&e<=55215||e>=63744&&e<=64255||e>=65280&&e<=65519&&!(e>=65377&&e<=65439)||e>=12352&&e<=12543?"wide":e===8230?"latin":"other","getCharType"),ii=J((e,r)=>{const i=Math.floor(e/65536),o=e%65536;let s=he.get(i);if(s||(s=new Map,he.set(i,s)),s.has(o))return s.get(o);let t;if(q(e)==="latin")t=r.width.regular;else if(q(e)==="control")t=r.width.control;else if(q(e)==="wide")t=r.width.wide;else switch(P(e)){case"ambiguous":{t=r.width.ambiguousIsNarrow?r.width.regular:r.width.wide;break}case"fullwidth":{t=r.width.fullWidth;break}case"wide":{t=r.width.wide;break}default:t=r.width.regular}return s.set(o,t),t},"getCachedCharWidth"),ri=J(e=>e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071||e>=917760&&e<=917999||e>=65024&&e<=65039||e>=3633&&e<=3642||e>=3655&&e<=3662||e>=3761&&e<=3769||e>=3771&&e<=3772||e>=3784&&e<=3789||e>=2304&&e<=2307||e>=2362&&e<=2383||e>=2385&&e<=2391||e>=2402&&e<=2403||e>=2433&&e<=2435||e>=2492&&e<=2500||e>=2509&&e<=2509||e>=2561&&e<=2563||e>=2620&&e<=2637||e>=1611&&e<=1631||e>=1648&&e<=1648||e>=1750&&e<=1773||e>=2276&&e<=2302||e>=1425&&e<=1469||e>=1471&&e<=1471||e>=1473&&e<=1474||e>=1476&&e<=1477||e>=1479&&e<=1479||e>=3893&&e<=3893||e>=3895&&e<=3895||e>=3897&&e<=3897||e>=3953&&e<=3966||e>=3968&&e<=3972||e>=3974&&e<=3975?!0:e>=768&&e<=777||e>=803&&e<=803,"isCombiningCharacter"),oe=J((e,r={})=>{if(!e||e.length===0)return{ellipsed:!1,index:0,truncated:!1,width:0};const i={truncation:{countAnsiEscapeCodes:r.countAnsiEscapeCodes??!1,ellipsis:r.ellipsis??"",ellipsisWidth:r.ellipsisWidth??(r.ellipsis?oe(r.ellipsis,{...r,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width:0),limit:r.limit??Number.POSITIVE_INFINITY},width:{ambiguousIsNarrow:r.ambiguousIsNarrow??!1,ansi:r.ansiWidth??0,control:r.controlWidth??0,emoji:r.emojiWidth??2,fullWidth:r.fullWidth??2,halfWidth:r.halfWidth??1,regular:r.regularWidth??1,tab:r.tabWidth??8,wide:r.wideWidth??2}},o=Math.max(0,i.truncation.limit-i.truncation.ellipsisWidth),{length:s}=e,t=s>1e4;let n=0,a=0,l=s,c=!1;const u=e.includes("\x1B")||e.includes("›");for(;n<s;){if(u&&(e[n]==="\x1B"||e[n]==="›")){if(e.startsWith("\x1B]8;;",n)){const b="\x07",E=`\x1B]8;;${b}`,Ie=E.length,Q=e.indexOf(b,n+5);if(Q!==-1){const X=e.indexOf(E,Q+1);if(X!==-1){const je=X+Ie,Ce=e.slice(Q+1,X).replace(C,""),ue=oe(Ce,{ambiguousIsNarrow:i.width.ambiguousIsNarrow,ansiWidth:i.width.ansi,controlWidth:i.width.control,countAnsiEscapeCodes:!1,ellipsis:i.truncation.ellipsis,ellipsisWidth:i.truncation.ellipsisWidth,emojiWidth:i.width.emoji,fullWidth:i.width.fullWidth,halfWidth:i.width.halfWidth,limit:Math.max(0,o-a),regularWidth:i.width.regular,tabWidth:i.width.tab,wideWidth:i.width.wide}),ee=ue.width;if(ue.truncated)c=!0,l=Math.min(l,n);else if(a+ee>o&&(l=Math.min(l,n),c=!0,a+ee>i.truncation.limit))break;if(a+=ee,n=je,c&&a>=i.truncation.limit)break;continue}}}if(C.lastIndex=n,C.test(e)){const b=C.lastIndex-n,E=i.truncation.countAnsiEscapeCodes?b:i.width.ansi;if(a+E>o&&(l=Math.min(l,n),a+E>i.truncation.limit)){c=!0;break}a+=E,n=C.lastIndex;continue}}const d=e.codePointAt(n);if(d===8203||d===65279||d>=8288&&d<=8292){n+=1;continue}if(d===9){if(a+i.width.tab>o&&(l=Math.min(l,n),a+i.width.tab>i.truncation.limit)){c=!0;break}a+=i.width.tab,n+=1;continue}if(H.lastIndex=n,H.test(e)){const b=(H.lastIndex-n)*i.width.regular;if(a+b>o){const E=Math.floor((o-a)/i.width.regular);if(l=Math.min(l,n+E),a+b>i.truncation.limit){c=!0;break}}a+=b,n=H.lastIndex;continue}if((d<=31||d>=127&&d<=159)&&(D.lastIndex=n,D.test(e))){const b=(D.lastIndex-n)*i.width.control;if(a+b>o&&(l=Math.min(l,n+Math.floor((o-a)/i.width.control)),a+b>i.truncation.limit)){c=!0;break}a+=b,n=D.lastIndex;continue}if(z.lastIndex=n,z.test(e)){if(a+i.width.emoji>o&&(l=Math.min(l,n),a+i.width.emoji>i.truncation.limit)){c=!0;break}a+=i.width.emoji,n=z.lastIndex;continue}const p=e.codePointAt(n)??0;if(ri(p)){n+=p>65535?2:1;continue}let g;if(t)g=ii(p,i);else switch(q(p)){case"control":{g=i.width.control;break}case"latin":{g=i.width.regular;break}case"wide":{g=i.width.wide;break}case"zero":{g=0;break}default:switch(P(p)){case"ambiguous":{g=i.width.ambiguousIsNarrow?i.width.regular:i.width.wide;break}case"fullwidth":{g=i.width.fullWidth;break}case"wide":{g=i.width.wide;break}default:g=i.width.regular}}if(a+g>o&&(l=Math.min(l,n),a+g>i.truncation.limit)){c=!0;break}a+=g,n+=p>65535?2:1}let h=a,f=!1;return c&&i.truncation.limit>=i.truncation.ellipsisWidth&&(h=i.truncation.limit,f=!0),{ellipsed:f,index:c?l:s,truncated:c,width:h}},"getStringTruncatedWidth");var oi=Object.defineProperty,ni=w((e,r)=>oi(e,"name",{value:r,configurable:!0}),"i$1"),ai=Object.defineProperty,ti=ni((e,r)=>ai(e,"name",{value:r,configurable:!0}),"e"),li=Object.defineProperty,si=ti((e,r)=>li(e,"name",{value:r,configurable:!0}),"r");const m=si((e,r={})=>oe(e,{...r,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width,"getStringWidth");var ui=Object.defineProperty,ci=w((e,r)=>ui(e,"name",{value:r,configurable:!0}),"g"),hi=Object.defineProperty,fi=ci((e,r)=>hi(e,"name",{value:r,configurable:!0}),"s"),di=Object.defineProperty,le=fi((e,r)=>di(e,"name",{value:r,configurable:!0}),"n");const gi=le((e,r)=>Math.floor((e-r)/2),"halfDiff"),pi=le((e,r)=>e-r,"fullDiff"),fe=le((e,r={})=>{const i=r.align??"center";if(i==="left")return e;const o=r.split??` `,s=r.pad??" ",t=i==="right"?pi:gi;let n=!1;Array.isArray(e)||(n=!0,e=String(e).split(o));let a,l=0;return e=e.map(c=>(c=String(c),a=m(c,r.stringWidthOptions),l=Math.max(a,l),{str:c,width:a})).map(c=>Array.from({length:t(l,c.width)+1}).join(s)+c.str),n?e.join(o):e},"alignText");var mi=Object.defineProperty,Ee=w((e,r)=>mi(e,"name",{value:r,configurable:!0}),"x$1"),bi=Object.defineProperty,W=Ee((e,r)=>bi(e,"name",{value:r,configurable:!0}),"m"),wi=Object.defineProperty,vi=W((e,r)=>wi(e,"name",{value:r,configurable:!0}),"n");class ye{static{w(this,"T")}static{Ee(this,"w")}static{W(this,"u")}static{vi(this,"AnsiStateTracker")}activeForeground=null;activeBackground=null;activeFormatting=[];processEscape(r){const i=/\x1B\[(\d+)m/.exec(r);if(!i)return;const o=Number.parseInt(i[1],10);switch(o){case 0:{this.activeForeground=null,this.activeBackground=null,this.activeFormatting=[];break}case 39:{this.activeForeground=null;break}case 49:{this.activeBackground=null;break}default:if(o>=30&&o<=37||o>=90&&o<=97)this.activeForeground=r;else if(o>=40&&o<=47||o>=100&&o<=107)this.activeBackground=r;else if([1,2,3,4,7,8,9].includes(o))this.activeFormatting.push(r);else if([22,23,24,27,28,29].includes(o)){const s={22:"[1m",23:"[3m",24:"[4m",27:"[7m",28:"[8m",29:"[9m"}[o];s&&(this.activeFormatting=this.activeFormatting.filter(t=>!t.includes(s)))}}}getStartEscapesForAllActiveAttributes(){return[this.activeBackground,this.activeForeground,...this.activeFormatting].filter(Boolean).join("")}getEndEscapesForAllActiveAttributes(){const r=[];if(this.activeFormatting.length>0){const i={"\x1B[1m":"\x1B[22m","\x1B[2m":"\x1B[22m","\x1B[3m":"\x1B[23m","\x1B[4m":"\x1B[24m","\x1B[7m":"\x1B[27m","\x1B[8m":"\x1B[28m","\x1B[9m":"\x1B[29m"};[...this.activeFormatting].reverse().forEach(o=>{const s=i[o];s&&r.push(s)})}return this.activeForeground&&r.push("\x1B[39m"),this.activeBackground&&r.push("\x1B[49m"),r.join("")}}var xi=Object.defineProperty,Ae=W((e,r)=>xi(e,"name",{value:r,configurable:!0}),"o");const Se=Ae((e,r)=>{if(!O.has(e[r]))return{isInsideEscape:!1,isInsideLinkEscape:!1};const i=!0,o=e.slice(r+1,r+1+V.length).join("")===V;return{isInsideEscape:i,isInsideLinkEscape:o}},"checkEscapeSequence"),$i=Ae((e,r={})=>{const i=new ye;let o="",s=!1,t=!1,n="",a="",l=!1;const c=[...e];for(let u=0;u<c.length;u++){const h=c[u];if(h&&O.has(h)){if(o){const p=r.getWidth?.(o)??0,g={isEscapeSequence:!1,isGrapheme:!0,text:o,width:p};if(l&&(g.isHyperlink=!0,g.hyperlinkUrl=a),r.onSegment?.(g,i)===!1)return;o=""}if(s=!0,n=h,t=Se(c,u).isInsideLinkEscape,t){let p=u+1;for(a="";p<c.length;){const b=c[p];if(b===G)break;a+=b,p+=1}a=a.slice(4);const g={hyperlinkUrl:a,isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkStart:!0,width:0};if(r.onSegment?.(g,i)===!1)return;u=p,l=!0,s=!1,t=!1,n="";continue}if(u+1<c.length&&c[u+1]==="\\"&&l){const p={isEscapeSequence:!0,isGrapheme:!1,isHyperlink:!0,isHyperlinkEnd:!0,width:0};if(r.onSegment?.(p,i)===!1)return;l=!1,a="",u+=1,s=!1,n="";continue}}if(s){if(n!==h&&(n+=h),h===ae){s=!1,i.processEscape(n);const p={isEscapeSequence:!0,isGrapheme:!1,text:n,width:0};if(r.onSegment?.(p,i)===!1)return;n=""}continue}o+=h;const f=r.getWidth?.(o)??0,d={isEscapeSequence:!1,isGrapheme:!0,text:o,width:f};if(l&&(d.isHyperlink=!0,d.hyperlinkUrl=a),r.onSegment?.(d,i)===!1)return;o=""}if(o){const u=r.getWidth?.(o)??0,h={isEscapeSequence:!1,isGrapheme:!0,text:o,width:u};l&&(h.isHyperlink=!0,h.hyperlinkUrl=a),r.onSegment?.(h,i)}if(n){const u={isEscapeSequence:!0,isGrapheme:!1,text:n,width:0};r.onSegment?.(u,i)}},"processAnsiString");var Ei=Object.defineProperty,yi=W((e,r)=>Ei(e,"name",{value:r,configurable:!0}),"t$1");const de=yi(e=>`${O.values().next().value}${$e}${e}${ae}`,"wrapAnsiCode");var Ai=Object.defineProperty,Si=W((e,r)=>Ai(e,"name",{value:r,configurable:!0}),"t");const ge=Si(e=>`${O.values().next().value}${V}${e}${G}`,"wrapAnsiHyperlink");var Ti=Object.defineProperty,Wi=W((e,r)=>Ti(e,"name",{value:r,configurable:!0}),"l");const Ri=Wi(e=>{if(e.length===0)return"";if(e.length===1)return e[0];let r="",i,o;const s=e.join(` `),t=[...s];let n=0;for(const[a,l]of t.entries()){if(r+=l,O.has(l)){const u=Ue.exec(s.slice(n))?.groups??{};if(u.code!==void 0){const h=Number.parseFloat(u.code);i=h===Ve?void 0:h}else u.uri!==void 0&&(o=u.uri.length===0?void 0:u.uri)}const c=Ye.get(Number(i));t[a+1]===` `?(o&&(r+=ge("")),i&&c&&(r+=de(c))):l===` `&&(i&&c&&(r+=de(i)),o&&(r+=ge(o))),n+=l.length}return r},"preserveAnsi");var Bi=Object.defineProperty,A=W((e,r)=>Bi(e,"name",{value:r,configurable:!0}),"h");const ie=A(e=>{if(!e.includes("\x1B"))return e;let r=e;return e.includes("\x1B[30m")&&(r+="\x1B[39m"),e.includes("\x1B[42m")&&(r+="\x1B[49m"),r},"resetAnsiAtLineBreak"),T=A(e=>{const r=e.split(" ");let i=r.length;for(;i>0&&m(r[i-1])===0;)i--;return i===r.length?e:r.slice(0,i).join(" ")+r.slice(i).join("")},"stringVisibleTrimSpacesRight"),Te=A((e,r,i)=>{if(e.length===0)return[""];if(r<=0)return[e];const o=[],s=new ye;let t="",n=0,a=!1,l=!1,c="";for(let u=0;u<e.length;u++){const h=e[u];if(O.has(h)){a=!0,c=h,t+=h,l=Se([...e],u).isInsideLinkEscape;continue}if(a){c+=h,t+=h,l?h===G&&(a=l=!1):h===ae&&(a=!1,s.processEscape(c));continue}const f=m(h),d=h===" ";if(f===0){t+=h;continue}if(n+f>r&&(t&&o.push(t+s.getEndEscapesForAllActiveAttributes()),t=s.getStartEscapesForAllActiveAttributes(),n=m(t),d&&i)){for(;u<e.length&&e[u]===" "&&(u+=1,!(u>=e.length)););u<e.length&&u--;continue}if(t+=h,n+=f,n===r&&u<e.length-1&&(o.push(t+s.getEndEscapesForAllActiveAttributes()),t=s.getStartEscapesForAllActiveAttributes(),n=m(t),u+1<e.length&&e[u+1]===" "&&i)){for(u+=1;u<e.length&&e[u]===" ";)u+=1;u--}}return t&&o.push(t+s.getEndEscapesForAllActiveAttributes()),i?o.map(u=>T(u)):o},"wrapWithBreakAtWidth"),ki=A((e,r,i)=>{if(e.length===0)return[];const o=i?e.trim():e;if(o.length===0)return[];const s=[];let t="",n=0;return $i(o,{getWidth:m,onSegment:A((a,l)=>{if(a.isEscapeSequence)t+=a.text;else{const c=a.text===" ";if(a.width===0)return t+=a.text,!0;if(n+a.width>r&&(t&&s.push(t),t=l.getStartEscapesForAllActiveAttributes(),n=0,c))return i||s.push(l.getStartEscapesForAllActiveAttributes()+a.text),!0;t+=a.text,n+=a.width}return!0},"onSegment")}),t&&s.push(t),i?s.map(a=>T(a)):s},"wrapCharByChar"),Oi=A((e,r,i)=>{if(e.length===0)return[];const o=i?e.trim():e;if(o.length===0)return[];const s=o.split(/(?=\s)|(?<=\s)/),t=[];let n="",a=0,l=0;for(;l<s.length;){const c=s[l],u=/^\s+$/.test(c),h=m(c);if(c.length===0){l+=1;continue}if(i&&u&&a===0){l+=1;continue}if(a+h>r&&a>0){i?t.push(T(n)):t.push(n),n="",a=0;continue}n+=c,a+=h,l+=1}return n&&(i?t.push(T(n)):t.push(n)),t},"wrapWithWordBoundaries"),Ii=A((e,r,i)=>{if(e.length===0)return[];const o=i?e.trim():e;if(o.length===0)return[];const s=o.split(/(?=\s)|(?<=\s)/),t=[];let n="",a=0,l=0;for(;l<s.length;){const c=s[l],u=/^\s+$/.test(c),h=m(c);if(c.length===0){l+=1;continue}if(i&&u&&a===0){l+=1;continue}if(h>r){n&&t.push(ie(i?T(n):n));const f=Te(c,r,i);if(f.length>0){for(let d=0;d<f.length-1;d++)t.push(f[d]);n=f[f.length-1],a=m(n)}else n="",a=0;l+=1;continue}if(a+h>r&&a>0&&(t.push(ie(i?T(n):n)),n="",a=0,i&&u)){l+=1;continue}n+=c,a+=h,l+=1}return n&&t.push(ie(i?T(n):n)),t},"wrapAndBreakWords"),B={BREAK_AT_CHARACTERS:"BREAK_AT_CHARACTERS",BREAK_WORDS:"BREAK_WORDS",PRESERVE_WORDS:"PRESERVE_WORDS",STRICT_WIDTH:"STRICT_WIDTH"},We=A((e,r={})=>{const{removeZeroWidthCharacters:i=!0,trim:o=!0,width:s=80,wrapMode:t=B.PRESERVE_WORDS}=r;if(o&&e.trim()==="")return"";let n=String(e).normalize("NFC").replaceAll(`\r `,` `);return i&&(n=n.replaceAll(Ge,"")),n.split(` `).map(a=>{if(o&&a.trim()==="")return"";let l;switch(t){case B.BREAK_AT_CHARACTERS:{l=ki(a,s,o);break}case B.BREAK_WORDS:{l=Ii(a,s,o);break}case B.STRICT_WIDTH:{l=Te(a,s,o);break}default:l=Oi(a,s,o)}return Ri(l)}).join(` `)},"wordWrap");var ji=Object.defineProperty,R=w((e,r)=>ji(e,"name",{value:r,configurable:!0}),"e");const Re=80,Be=24,ne=R((e,r,{shell:i,env:o}={})=>Me(e,r,{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:500,shell:i,env:o}).trim(),"exec"),K=R((e,r)=>({columns:Number.parseInt(e,10),rows:Number.parseInt(r,10)}),"create"),ke=R((e,r)=>{const{columns:i,rows:o}=K(e,r);if(!(Number.isNaN(i)||Number.isNaN(o))&&!(i===Re&&o===Be))return{columns:i,rows:o}},"createIfNotDefault");function se(){const{env:e,stdout:r,stderr:i}=k;if(r?.columns&&r?.rows)return K(r.columns,r.rows);if(i?.columns&&i?.rows)return K(i.columns,i.rows);if(e.COLUMNS&&e.LINES)return K(e.COLUMNS,e.LINES);const o={columns:Re,rows:Be};return k.platform==="win32"?re()??o:k.platform==="darwin"?pe()??re()??o:pe()??re()??Ci()??o}w(se,"O");R(se,"terminalSize");const pe=R(()=>{try{const e=k.platform==="darwin"?_.constants.O_EVTONLY|_.constants.O_NONBLOCK:_.constants.O_NONBLOCK,{columns:r,rows:i}=Ne.WriteStream(_.openSync("/dev/tty",e));return{columns:r,rows:i}}catch{}},"devTty"),re=R(()=>{try{const e=ne("tput",["cols"],{env:{TERM:"dumb",...k.env}}),r=ne("tput",["lines"],{env:{TERM:"dumb",...k.env}});if(e&&r)return ke(e,r)}catch{}},"tput"),Ci=R(()=>{try{const e=ne("resize",["-u"]).match(/\d+/g);if(e.length===2)return ke(e[0],e[1])}catch{}},"resize"),Fi={arrow:{bottom:"↑",bottomLeft:"↗",bottomRight:"↖",left:"→",right:"←",top:"↓",topLeft:"↘",topRight:"↙"},bold:{bottom:"━",bottomLeft:"┗",bottomRight:"┛",left:"┃",right:"┃",top:"━",topLeft:"┏",topRight:"┓"},classic:{bottom:"-",bottomLeft:"+",bottomRight:"+",left:"|",right:"|",top:"-",topLeft:"+",topRight:"+"},double:{bottom:"═",bottomLeft:"╚",bottomRight:"╝",left:"║",right:"║",top:"═",topLeft:"╔",topRight:"╗"},doubleSingle:{bottom:"═",bottomLeft:"╘",bottomRight:"╛",left:"│",right:"│",top:"═",topLeft:"╒",topRight:"╕"},round:{bottom:"─",bottomLeft:"╰",bottomRight:"╯",left:"│",right:"│",top:"─",topLeft:"╭",topRight:"╮"},single:{bottom:"─",bottomLeft:"└",bottomRight:"┘",left:"│",right:"│",top:"─",topLeft:"┌",topRight:"┐"},singleDouble:{bottom:"─",bottomLeft:"╙",bottomRight:"╜",left:"║",right:"║",top:"─",topLeft:"╓",topRight:"╖"}};var Mi=Object.defineProperty,Ni=w((e,r)=>Mi(e,"name",{value:r,configurable:!0}),"n");const Oe=Ni(e=>{let r=0;for(const i of e.split(` `))r=Math.max(r,m(i));return r},"widestLine");var Li=Object.defineProperty,v=w((e,r)=>Li(e,"name",{value:r,configurable:!0}),"s");const y=` `,x=" ",F="none",me=v(e=>typeof e=="number"?{bottom:e,left:e*3,right:e*3,top:e}:{bottom:0,left:0,right:0,top:0,...e},"getObject"),M=v(e=>e===F?0:2,"getBorderWidth"),Pi=v(e=>{const r=["topLeft","topRight","bottomRight","bottomLeft","left","right","top","bottom"];let i;if(e===F){e={};for(const o of r)e[o]=""}if(typeof e=="string"){const o=Fi[e];if(o===void 0)throw new TypeError(`Invalid border style: ${e}`);i=o}else{typeof e.vertical=="string"&&(e.left=e.vertical,e.right=e.vertical),typeof e.horizontal=="string"&&(e.top=e.horizontal,e.bottom=e.horizontal);for(const o of r)if(e[o]===null||typeof e[o]!="string")throw new TypeError(`Invalid border style: ${o}`);i=e}return i},"getBorderChars"),be=v((e,r,i,o,s)=>{let t="";e=r(e);const n=m(e);switch(s){case"left":{t=e+o(i.slice(n),m(i.slice(n)));break}case"right":{t=`${o(i.slice(n+2),m(i.slice(n))+2)} ${e} `;break}default:{if(i=i.slice(n),i.length%2===1)i=i.slice(Math.floor(i.length/2)),t=o(i.slice(1),m(i.slice(1)))+e+o(i,m(i));else{i=i.slice(i.length/2);const a=m(i);t=o(i,a)+e+o(i,a)}break}}return t},"wrapText"),_i=v((e,{height:r,padding:i,textAlignment:o,width:s})=>{e=fe(e,{align:o});let t=e.split(y);const n=Oe(e),a=s-i.left-i.right;if(n>a){const u=[];for(const h of t){const f=We(h,{width:a,wrapMode:B.BREAK_WORDS}),d=fe(f,{align:o}).split(` `),p=Math.max(...d.map(g=>m(g)));for(const g of d){let b;switch(o){case"center":{b=x.repeat((a-p)/2)+g;break}case"right":{b=x.repeat(a-p)+g;break}default:{b=g;break}}u.push(b)}}t=u}o==="center"&&n<a?t=t.map(u=>x.repeat((a-n)/2)+u):o==="right"&&n<a&&(t=t.map(u=>x.repeat(a-n)+u));const l=x.repeat(i.left),c=x.repeat(i.right);return t=t.map(u=>{const h=l+u+c,f=s-m(h);return h+x.repeat(Math.max(f,0))}),i.top>0&&(t=[...Array.from({length:i.top}).fill(x.repeat(s)),...t]),i.bottom>0&&(t=[...t,...Array.from({length:i.bottom}).fill(x.repeat(s))]),r&&t.length>r?t=t.slice(0,r):r&&t.length<r&&(t=[...t,...Array.from({length:r-t.length}).fill(x.repeat(s))]),t.join(y)},"makeContentText"),Di=v((e,r,i,o)=>{const s=v((f,d,p)=>o.borderColor?o.borderColor(f,d,p):f,"colorizeBorder"),t=v(f=>o.headerTextColor?o.headerTextColor(f):f,"colorizeHeaderText"),n=v(f=>o.footerTextColor?o.footerTextColor(f):f,"colorizeFooterText"),a=v(f=>o.textColor?o.textColor(f):f,"colorizeContent"),l=Pi(o.borderStyle);let c=x.repeat(o.margin.left);if(o.float==="center"){const f=Math.max((i-r-M(o.borderStyle))/2,0);c=x.repeat(f)}else if(o.float==="right"){const f=Math.max(i-r-o.margin.right-M(o.borderStyle),0);c=x.repeat(f)}let u="";if(o.margin.top&&(u+=y.repeat(o.margin.top)),o.borderStyle!==F||o.headerText){let f=s(l.top.repeat(r),"top",r);o.headerText&&(f=be(o.headerText,t,l.top.repeat(r),(p,g)=>s(p,"top",g),o.headerAlignment));const d=s(c+l.topLeft,"topLeft",m(c+l.topLeft));u+=d+f+s(l.topRight,"topRight",m(l.topRight))+y}const h=e.split(y);if(u+=h.map(f=>c+s(l.left,"left",m(l.left))+a(f)+s(l.right,"right",m(l.right))).join(y),o.borderStyle!==F||o.footerText){const f=y+s(c+l.bottomLeft,"bottomLeft",m(c+l.bottomLeft));let d=s(l.bottom.repeat(r),"bottom",r);o.footerText&&(d=be(o.footerText,n,l.bottom.repeat(r),(p,g)=>s(p,"bottom",g),o.footerAlignment)),u+=f+d+s(l.bottomRight,"bottomRight",m(l.bottomRight))}return o.margin.bottom&&(u+=y.repeat(o.margin.bottom)),u},"boxContent"),Hi=v(e=>{if(e.fullscreen){let r=se();typeof e.fullscreen=="function"&&(r=e.fullscreen(r.columns,r.rows)),e.width||(e.width=r.columns),e.height||(e.height=r.rows)}return e.width&&(e.width=Math.max(1,e.width-M(e.borderStyle))),e.height&&(e.height=Math.max(1,e.height-M(e.borderStyle))),e},"sanitizeOptions"),we=v((e,r)=>r===F?e:` ${e} `,"formatTitle"),zi=v((e,r,i)=>{i=Hi(i);const o=i.width!==void 0,s=M(i.borderStyle),t=r-i.margin.left-i.margin.right-s,n=Oe(We(e,{trim:!1,width:r-s,wrapMode:B.BREAK_WORDS}))+i.padding.left+i.padding.right;if(i.headerText&&o?(i.headerText=i.headerText.slice(0,Math.max(0,i.width-2)),i.headerText&&(i.headerText=we(i.headerText,i.borderStyle))):i.headerText&&(i.headerText=i.headerText.slice(0,Math.max(0,t-2)),i.headerText&&(i.headerText=we(i.headerText,i.borderStyle),m(i.headerText)>n&&(i.width=m(i.headerText)))),i.width=i.width||n,!o){if(i.margin.left&&i.margin.right&&i.width>t){const a=(r-i.width-s)/(i.margin.left+i.margin.right);i.margin.left=Math.max(0,Math.floor(i.margin.left*a)),i.margin.right=Math.max(0,Math.floor(i.margin.right*a))}i.width=Math.min(i.width,r-s-i.margin.left-i.margin.right)}return i.width-(i.padding.left+i.padding.right)<=0&&(i.padding.left=0,i.padding.right=0),i.height&&i.height-(i.padding.top+i.padding.bottom)<=0&&(i.padding.top=0,i.padding.bottom=0),i},"determineDimensions"),Yi=v((e,r={})=>{if(r.borderColor!==void 0&&typeof r.borderColor!="function")throw new Error('"borderColor" is not a valid function');if(r.textColor!==void 0&&typeof r.textColor!="function")throw new Error('"textColor" is not a valid function');let i={borderStyle:"single",dimBorder:!1,float:"left",footerAlignment:"right",headerAlignment:"left",textAlignment:"left",transformTabToSpace:4,...r};i.padding=me(r.padding??0),i.margin=me(r.margin),i.transformTabToSpace&&(e=e.replaceAll(" "," ".repeat(i.transformTabToSpace)));const{columns:o}=se();return i=zi(e,o,i),Di(_i(e,i),i.width,o,i)},"boxen");export{Yi as boxen};