'use strict'; var A = require('string-width'); var N = require('chalk'); var v = require('strip-ansi'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } var A__default = /*#__PURE__*/_interopDefault(A); var N__default = /*#__PURE__*/_interopDefault(N); var v__default = /*#__PURE__*/_interopDefault(v); var E={single:{topLeft:"\u250C",top:"\u2500",topRight:"\u2510",right:"\u2502",bottomRight:"\u2518",bottom:"\u2500",bottomLeft:"\u2514",left:"\u2502",leftMiddle:"\u251C",rightMiddle:"\u2524",topMiddle:"\u252C",bottomMiddle:"\u2534",middleMiddle:"\u253C"},double:{topLeft:"\u2554",top:"\u2550",topRight:"\u2557",right:"\u2551",bottomRight:"\u255D",bottom:"\u2550",bottomLeft:"\u255A",left:"\u2551",leftMiddle:"\u2560",rightMiddle:"\u2563",topMiddle:"\u2566",bottomMiddle:"\u2569",middleMiddle:"\u256C"},round:{topLeft:"\u256D",top:"\u2500",topRight:"\u256E",right:"\u2502",bottomRight:"\u256F",bottom:"\u2500",bottomLeft:"\u2570",left:"\u2502",leftMiddle:"\u251C",rightMiddle:"\u2524",topMiddle:"\u252C",bottomMiddle:"\u2534",middleMiddle:"\u253C"},bold:{topLeft:"\u250F",top:"\u2501",topRight:"\u2513",right:"\u2503",bottomRight:"\u251B",bottom:"\u2501",bottomLeft:"\u2517",left:"\u2503",leftMiddle:"\u2523",rightMiddle:"\u252B",topMiddle:"\u2533",bottomMiddle:"\u253B",middleMiddle:"\u254B"},singleDouble:{topLeft:"\u2553",top:"\u2500",topRight:"\u2556",right:"\u2551",bottomRight:"\u255C",bottom:"\u2500",bottomLeft:"\u2559",left:"\u2551",leftMiddle:"\u255F",rightMiddle:"\u2562",topMiddle:"\u2565",bottomMiddle:"\u2568",middleMiddle:"\u256B"},doubleSingle:{topLeft:"\u2552",top:"\u2550",topRight:"\u2555",right:"\u2502",bottomRight:"\u255B",bottom:"\u2550",bottomLeft:"\u2558",left:"\u2502",leftMiddle:"\u255E",rightMiddle:"\u2561",topMiddle:"\u2564",bottomMiddle:"\u2567",middleMiddle:"\u256A"},classic:{topLeft:"+",top:"-",topRight:"+",right:"|",bottomRight:"+",bottom:"-",bottomLeft:"+",left:"|",leftMiddle:"+",rightMiddle:"+",topMiddle:"+",bottomMiddle:"+",middleMiddle:"+"},arrow:{topLeft:"\u2198",top:"\u2193",topRight:"\u2199",right:"\u2190",bottomRight:"\u2196",bottom:"\u2191",bottomLeft:"\u2197",left:"\u2192",leftMiddle:"\u2192",rightMiddle:"\u2190",topMiddle:"\u2191",bottomMiddle:"\u2193",middleMiddle:"+"}},y=` `,l=" ",_={border:!1,borderStyle:"single",borderColor:"#fff"};function x(t,e){return Array.from({length:e}).fill(t)}function W(t,e,o){let i=e-A__default.default(t);return i<=0?t:o.repeat(i)+t}function k(t,e,o){let i=e-A__default.default(t);return i<=0?t:t+o.repeat(i)}function I(t,e,o){let i=(e-A__default.default(t))/2;return i<=0?t:o.repeat(Math.ceil(i))+t+o.repeat(Math.floor(i))}function H(t,e,o){let i=e-t.length;return i<=0?t:[...x(o,i),...t]}function z(t,e,o){let i=e-t.length;return i<=0?t:[...t,...x(o,i)]}function D(t,e,o){let i=(e-t.length)/2;return i<=0?t:[...x(o,Math.ceil(i)),...t,...x(o,Math.floor(i))]}function F(t){if(t?.length===1){let e=t[0]>0?t[0]:0;return {left:e,right:e,top:e,bottom:e}}else if(t?.length===2){let e=t[0]>0?t[0]:0,o=t[1]>0?t[1]:0;return {left:o,right:o,top:e,bottom:e}}else if(t?.length===3){let e=t[0]>0?t[0]:0,o=t[1]>0?t[1]:0,i=t[2]>0?t[2]:0;return {left:o,right:o,top:e,bottom:i}}else if(t?.length===4){let e=t[0]>0?t[0]:0,o=t[1]>0?t[1]:0,i=t[2]>0?t[2]:0;return {left:t[3]>0?t[3]:0,right:o,top:e,bottom:i}}else return {left:0,right:0,top:0,bottom:0}}function P(t){return typeof t=="string"?E[t]:t||{}}function T(t,e){return e?N__default.default.bgHex(e)(t):t}function O(t,e){return e?N__default.default.hex(e).bold(t):t}function S(t){let{width:e,padding:o,textAlign:i="left",background:g,border:f=!1,borderColor:n="#fff",borderStyle:s="single",content:m=" "}=t,d=[],{left:r,right:p,top:b,bottom:a}=F(o),h=A__default.default(m.split(y).sort((c,w)=>A__default.default(w)-A__default.default(c))[0]),u=e||h+r+p+(f?2:0),M=e?e-r-p-(f?2:0):h,L=m.split(y).reduce((c,w)=>{if(e&&A__default.default(w)>M){let V=new RegExp(`.{1,${M}}`,"g");c.push(...w.match(V)||[]);}else c.push(w);return c},[]),B=l.repeat(f?u-2:u);if(b&&d.push(...x(B,b)),L.forEach(c=>{i==="left"?d.push(l.repeat(r)+k(c,M,l)+l.repeat(p)):i==="center"?d.push(l.repeat(r)+I(c,M,l)+l.repeat(p)):d.push(l.repeat(r)+W(c,M,l)+l.repeat(p));}),a&&d.push(...x(B,a)),f){let{top:c,bottom:w,left:V,right:G,topLeft:J,topRight:K,bottomLeft:Q,bottomRight:U}=typeof s=="string"?E[s]:s,X=O(J+c.repeat(u-2)+K,n),Y=O(Q+w.repeat(u-2)+U,n);d=[X,...d.map(Z=>O(V,n)+T(Z,g)+O(G,n)),Y];}else d=d.map(c=>T(c,g));let C=d.join(y);return {content:C,width:u,height:b+a+(f?2:0)+L.length,border:f,padding:o,rows:d,render:()=>{console.log(C);}}}function R(t){let{contents:e,_views:o=[],direction:i="horizontal",...g}={..._,...t},f=[...e.map(s=>S({content:s,...g})),...o],n=[];if(i==="horizontal")for(let s=0;s{let b=p===f.length-1,a=p===0;if(t.border){let h=r.rows?.[s],{topMiddle:u,bottomMiddle:M,bottomRight:L,topRight:B}=P(g.borderStyle);!b&&m&&(h=h?.replace(B,u).replace(L,M)),a||(h=h?.replace(v__default.default(h)?.[0],"")),d=d+(h||l.repeat(r.width));}else d+=r.rows?.[s]||l.repeat(r.width);}),n.push(d);}else f.forEach((s,m)=>{let d=m===f.length-1,r=m===0;if(t.border){let{leftMiddle:p,rightMiddle:b,bottomLeft:a,bottomRight:h,middleMiddle:u,bottomMiddle:M}=P(g.borderStyle),L=d?s.rows.at(-1):s.rows.at(-1)?.replace(a,p).replace(h,b).replaceAll(M,u);n.push(...s.rows.slice(r?0:1,-1),L||"");}else n.push(...s.rows);});return {rows:n,width:f[0].width,height:n.length,border:g.border,padding:g.padding,render:()=>{console.log(n.join(y));}}}function $(t){let{data:e,...o}=t,i=e.map(g=>R({contents:g,...o}));return R({...o,_views:i,contents:[],direction:"vertical"})}function q(t){let{contents:e,alignItems:o="start",contentStyle:i={},gap:g=0,...f}=t;if(!e||e.length===0)return;let n=0,s=e[0],m=e.map(r=>{if(typeof r=="string"){let p=S({...i,content:r});return n=p.height>n?p.height:n,s=p.height>n?p:s,p}else return n=r.height>n?r.height:n,s=r.height>n?r:s,r}),d=[];o==="start"?m.forEach(r=>{r._rows=z(r.rows,n,l.repeat(r.width));}):o==="center"?m.forEach(r=>{r._rows=D(r.rows,n,l.repeat(r.width));}):m.forEach(r=>{r._rows=H(r.rows,n,l.repeat(r.width));});for(let r=0;r{let h=a===m.length-1;p+=(b._rows?.[r]||l.repeat(b.width))+(h?"":l.repeat(g));}),d.push(p);}return S({content:d.join(y),...f})}var Ot={View:S,Row:q,List:R,Table:$}; module.exports = Ot;