const v=(t=0)=>e=>`\x1B[${e+t}m`,A=(t=0)=>e=>`\x1B[${38+t};5;${e}m`,O=(t=0)=>(e,r,o)=>`\x1B[${38+t};2;${e};${r};${o}m`,l={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},G=Object.keys(l.modifier),M=Object.keys(l.color),N=Object.keys(l.bgColor),$=[...M,...N];function x(){const t=new Map;for(const[e,r]of Object.entries(l)){for(const[o,n]of Object.entries(r))l[o]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},r[o]=l[o],t.set(n[0],n[1]);Object.defineProperty(l,e,{value:r,enumerable:!1})}return Object.defineProperty(l,"codes",{value:t,enumerable:!1}),l.color.close="\x1B[39m",l.bgColor.close="\x1B[49m",l.color.ansi=v(),l.color.ansi256=A(),l.color.ansi16m=O(),l.bgColor.ansi=v(10),l.bgColor.ansi256=A(10),l.bgColor.ansi16m=O(10),Object.defineProperties(l,{rgbToAnsi256:{value(e,r,o){return e===r&&r===o?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(r/255*5)+Math.round(o/255*5)},enumerable:!1},hexToRgb:{value(e){const r=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!r)return[0,0,0];let[o]=r;o.length===3&&(o=[...o].map(s=>s+s).join(""));const n=Number.parseInt(o,16);return[n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:e=>l.rgbToAnsi256(...l.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let r,o,n;if(e>=232)r=((e-232)*10+8)/255,o=r,n=r;else{e-=16;const y=e%36;r=Math.floor(e/36)/5,o=Math.floor(y/6)/5,n=y%6/5}const s=Math.max(r,o,n)*2;if(s===0)return 30;let a=30+(Math.round(n)<<2|Math.round(o)<<1|Math.round(r));return s===2&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,r,o)=>l.ansi256ToAnsi(l.rgbToAnsi256(e,r,o)),enumerable:!1},hexToAnsi:{value:e=>l.ansi256ToAnsi(l.hexToAnsi256(e)),enumerable:!1}}),l}const i=x(),f=(()=>{if(navigator.userAgentData){const t=navigator.userAgentData.brands.find(({brand:e})=>e==="Chromium");if(t&&t.version>93)return 3}return/\b(Chrome|Chromium)\//.test(navigator.userAgent)?1:0})(),B=f!==0&&{level:f,hasBasic:!0,has256:f>=2,has16m:f>=3},F={stdout:B,stderr:B};function R(t,e,r){let o=t.indexOf(e);if(o===-1)return t;const n=e.length;let s=0,a="";do a+=t.slice(s,o)+e+r,s=o+n,o=t.indexOf(e,s);while(o!==-1);return a+=t.slice(s),a}function k(t,e,r,o){let n=0,s="";do{const a=t[o-1]==="\r";s+=t.slice(n,a?o-1:o)+e+(a?`\r
`:`
`)+r,n=o+1,o=t.indexOf(`
`,n)}while(o!==-1);return s+=t.slice(n),s}const{stdout:C,stderr:T}=F,d=Symbol("GENERATOR"),c=Symbol("STYLER"),b=Symbol("IS_EMPTY"),S=["ansi","ansi","ansi256","ansi16m"],u=Object.create(null),w=(t,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const r=C?C.level:0;t.level=e.level===void 0?r:e.level};class D{constructor(e){return j(e)}}const j=t=>{const e=(...r)=>r.join(" ");return w(e,t),Object.setPrototypeOf(e,h.prototype),e};function h(t){return j(t)}Object.setPrototypeOf(h.prototype,Function.prototype);for(const[t,e]of Object.entries(i))u[t]={get(){const r=g(this,p(e.open,e.close,this[c]),this[b]);return Object.defineProperty(this,t,{value:r}),r}};u.visible={get(){const t=g(this,this[c],!0);return Object.defineProperty(this,"visible",{value:t}),t}};const m=(t,e,r,...o)=>t==="rgb"?e==="ansi16m"?i[r].ansi16m(...o):e==="ansi256"?i[r].ansi256(i.rgbToAnsi256(...o)):i[r].ansi(i.rgbToAnsi(...o)):t==="hex"?m("rgb",e,r,...i.hexToRgb(...o)):i[r][t](...o),E=["rgb","hex","ansi256"];for(const t of E){u[t]={get(){const{level:r}=this;return function(...o){const n=p(m(t,S[r],"color",...o),i.color.close,this[c]);return g(this,n,this[b])}}};const e="bg"+t[0].toUpperCase()+t.slice(1);u[e]={get(){const{level:r}=this;return function(...o){const n=p(m(t,S[r],"bgColor",...o),i.bgColor.close,this[c]);return g(this,n,this[b])}}}}const I=Object.defineProperties(()=>{},{...u,level:{enumerable:!0,get(){return this[d].level},set(t){this[d].level=t}}}),p=(t,e,r)=>{let o,n;return r===void 0?(o=t,n=e):(o=r.openAll+t,n=e+r.closeAll),{open:t,close:e,openAll:o,closeAll:n,parent:r}},g=(t,e,r)=>{const o=(...n)=>P(o,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(o,I),o[d]=t,o[c]=e,o[b]=r,o},P=(t,e)=>{if(t.level<=0||!e)return t[b]?"":e;let r=t[c];if(r===void 0)return e;const{openAll:o,closeAll:n}=r;if(e.includes("\x1B"))for(;r!==void 0;)e=R(e,r.close,r.open),r=r.parent;const s=e.indexOf(`
`);return s!==-1&&(e=k(e,n,o,s)),o+e+n};Object.defineProperties(h.prototype,u);const Y=h(),L=h({level:T?T.level:0});export{D as Chalk,N as backgroundColorNames,N as backgroundColors,L as chalkStderr,$ as colorNames,$ as colors,Y as default,M as foregroundColorNames,M as foregroundColors,G as modifierNames,G as modifiers,C as supportsColor,T as supportsColorStderr};
