UNPKG

@mnrendra/chalk-ansi-styles

Version:

Refactored ansi-styles code to support both CommonJS (CJS) and ES Modules (ESM) with mixed exports.

3 lines (2 loc) 4.84 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const C="\x1B[",h={foreground:38,background:48},o={reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29],overline:[53,55]},N=39,a={black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],gray:[90,39],grey:[90,39],blackBright:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},G=49,i={bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgGray:[100,49],bgGrey:[100,49],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]},c=r=>`${C}${r}m`,b=r=>c(`${r}`),v=(r,t)=>c(`${r};5;${t}`),k=(r,t,g,n)=>c(`${r};2;${t};${g};${n}`),e=(r,t)=>({open:b(r),close:b(t)}),P=r=>{const t=new Map;return Object.values(r).forEach(([g,n])=>{t.set(g,n)}),t},d=r=>{if(r<8)return 30+r;if(r<16)return 90+(r-8);let t,g,n;if(r>=232)t=((r-232)*10+8)/255,g=t,n=t;else{r-=16;const w=r%36;t=Math.floor(r/36)/5,g=Math.floor(w/6)/5,n=w%6/5}const u=Math.max(t,g,n)*2;if(u===0)return 30;let m=30+(Math.round(n)<<2|Math.round(g)<<1|Math.round(t));return u===2&&(m+=60),m},s=(r,t,g)=>r===t&&t===g?r<8?16:r>248?231:Math.round((r-8)/247*24)+232:16+36*Math.round(r/255*5)+6*Math.round(t/255*5)+Math.round(g/255*5),M=r=>{const t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(r.toString(16));if(t===null)return[0,0,0];let[g]=t;g.length===3&&(g=[...g].map(u=>u+u).join(""));const n=Number.parseInt(g,16);return[n>>16&255,n>>8&255,n&255]},p=r=>{const[t,g,n]=M(r);return s(t,g,n)},$=r=>{const t=p(r);return d(t)},x=(r,t,g)=>{const n=s(r,t,g);return d(n)},B={reset:e(...o.reset),bold:e(...o.bold),dim:e(...o.dim),italic:e(...o.italic),underline:e(...o.underline),inverse:e(...o.inverse),hidden:e(...o.hidden),strikethrough:e(...o.strikethrough),overline:e(...o.overline)},y={black:e(...a.black),red:e(...a.red),green:e(...a.green),yellow:e(...a.yellow),blue:e(...a.blue),magenta:e(...a.magenta),cyan:e(...a.cyan),white:e(...a.white),gray:e(...a.gray),grey:e(...a.grey),blackBright:e(...a.blackBright),redBright:e(...a.redBright),greenBright:e(...a.greenBright),yellowBright:e(...a.yellowBright),blueBright:e(...a.blueBright),magentaBright:e(...a.magentaBright),cyanBright:e(...a.cyanBright),whiteBright:e(...a.whiteBright)},f={bgBlack:e(...i.bgBlack),bgRed:e(...i.bgRed),bgGreen:e(...i.bgGreen),bgYellow:e(...i.bgYellow),bgBlue:e(...i.bgBlue),bgMagenta:e(...i.bgMagenta),bgCyan:e(...i.bgCyan),bgWhite:e(...i.bgWhite),bgGray:e(...i.bgGray),bgGrey:e(...i.bgGrey),bgBlackBright:e(...i.bgBlackBright),bgRedBright:e(...i.bgRedBright),bgGreenBright:e(...i.bgGreenBright),bgYellowBright:e(...i.bgYellowBright),bgBlueBright:e(...i.bgBlueBright),bgMagentaBright:e(...i.bgMagentaBright),bgCyanBright:e(...i.bgCyanBright),bgWhiteBright:e(...i.bgWhiteBright)},l={...B,...y,...f};Object.defineProperty(l,"modifier",{value:B,writable:!1,enumerable:!1,configurable:!1});const R={...y,close:b(N),ansi:b,ansi256:r=>v(h.foreground,r),ansi16m:(r,t,g)=>k(h.foreground,r,t,g)};Object.defineProperty(l,"color",{value:R,writable:!1,enumerable:!1,configurable:!1});const T={...f,close:b(G),ansi:b,ansi256:r=>v(h.background,r),ansi16m:(r,t,g)=>k(h.background,r,t,g)};Object.defineProperty(l,"bgColor",{value:T,writable:!1,enumerable:!1,configurable:!1});const W=P({...o,...a,...i});Object.defineProperty(l,"codes",{value:W,writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(l,"rgbToAnsi256",{value:s,writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(l,"hexToRgb",{value:M,writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(l,"hexToAnsi256",{value:p,writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(l,"ansi256ToAnsi",{value:d,writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(l,"rgbToAnsi",{value:x,writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(l,"hexToAnsi",{value:$,writable:!1,enumerable:!1,configurable:!1});const Y=Object.keys(B),j=Object.keys(y),O=Object.keys(f),_=[...j,...O],A=l;exports.ansiStyles=A,exports.backgroundColorNames=O,exports.colorNames=_,exports.default=l,exports.foregroundColorNames=j,exports.modifierNames=Y,module.exports=exports.default,Object.defineProperties(module.exports,{__esModule:{value:exports.__esModule},ansiStyles:{value:exports.ansiStyles},backgroundColorNames:{value:exports.backgroundColorNames},colorNames:{value:exports.colorNames},foregroundColorNames:{value:exports.foregroundColorNames},modifierNames:{value:exports.modifierNames},default:{value:exports.default}}); //# sourceMappingURL=index.js.map