@visulima/colorize
Advanced tools
Comparing version 1.3.3 to 1.4.0
@@ -0,1 +1,8 @@ | ||
## @visulima/colorize [1.4.0](https://github.com/visulima/visulima/compare/@visulima/colorize@1.3.3...@visulima/colorize@1.4.0) (2024-04-10) | ||
### Features | ||
* add detection of color spaces support: TrueColor, 256 colors, 16 colors, no color ([#391](https://github.com/visulima/visulima/issues/391)) ([f35525c](https://github.com/visulima/visulima/commit/f35525c2a23558405408977745dd59aba9c58a3f)) | ||
## @visulima/colorize [1.3.3](https://github.com/visulima/visulima/compare/@visulima/colorize@1.3.2...@visulima/colorize@1.3.3) (2024-04-09) | ||
@@ -2,0 +9,0 @@ |
import { isStdoutColorSupported } from '@visulima/is-ansi-color-supported'; | ||
function S({onlyFirst:r=!1}={}){let e=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(e,r?void 0:"g")}var g=(r,e,t)=>e>r?e:r>t?t:r;var f=r=>{let e=r.replace("#","");if(e.length===3)e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2];else if(e.length!==6)return [0,0,0];let t=Number.parseInt(e,16);return [t>>16&255,t>>8&255,t&255]};var l=isStdoutColorSupported()>0?(r,e)=>({close:"\x1B["+e+"m",open:"\x1B["+r+"m"}):()=>({close:"",open:""}),V=r=>l("38;5;"+r,39),E=r=>l("48;5;"+r,49),z=(r,e,t)=>l("38;2;"+r+";"+e+";"+t,39),M=(r,e,t)=>l("48;2;"+r+";"+e+";"+t,49),R={bold:l(1,22),dim:l(2,22),hidden:l(8,28),inverse:l(7,27),italic:l(3,23),overline:l(53,55),reset:l(0,0),strike:l(9,29),strikethrough:l(9,29),underline:l(4,24),visible:{close:"",open:""}},k={bgBlack:l(40,49),bgBlackBright:l(100,49),bgBlue:l(44,49),bgBlueBright:l(104,49),bgCyan:l(46,49),bgCyanBright:l(106,49),bgGray:l(100,49),bgGreen:l(42,49),bgGreenBright:l(102,49),bgGrey:l(100,49),bgMagenta:l(45,49),bgMagentaBright:l(105,49),bgRed:l(41,49),bgRedBright:l(101,49),bgWhite:l(47,49),bgWhiteBright:l(107,49),bgYellow:l(43,49),bgYellowBright:l(103,49),black:l(30,39),blackBright:l(90,39),blue:l(34,39),blueBright:l(94,39),cyan:l(36,39),cyanBright:l(96,39),gray:l(90,39),green:l(32,39),greenBright:l(92,39),grey:l(90,39),magenta:l(35,39),magentaBright:l(95,39),red:l(31,39),redBright:l(91,39),white:l(37,39),whiteBright:l(97,39),yellow:l(33,39),yellowBright:l(93,39)},w={bg:r=>E(g(r,0,255)),bgHex:r=>M(...f(r)),bgRgb:(r,e,t)=>M(g(r,0,255),g(e,0,255),g(t,0,255)),fg:r=>V(g(r,0,255)),hex:r=>z(...f(r)),rgb:(r,e,t)=>z(g(r,0,255),g(e,0,255),g(t,0,255))};var H=(r,e,t)=>{if(e==="")return r;let n=r.indexOf(e);if(n<0)return r;let o=e.length,s=0,i="";for(;~n;)i+=r.slice(s,n)+t,s=n+o,n=r.indexOf(e,s);return i+r.slice(s)};var h={},B=null,L=(r,e,t)=>{if(!r)return "";let n=r.raw==null?r+"":String.raw(r,...e);if(n.includes("\x1B"))for(let o=t;o;o=o.props)n=H(n,o.close,o.open);return n.includes(` | ||
`)&&(n=n.replace(/(\r*\n)/g,t.closeStack+"$1"+t.openStack)),t.openStack+n+t.closeStack},x=({props:r},{close:e,open:t})=>{let n=(r?.openStack??"")+t,o=e+(r?.closeStack??""),s=(i,...u)=>L(i,u,s.props);return Object.setPrototypeOf(s,B),s.props={close:e,closeStack:o,open:t,openStack:n,props:r},s.open=n,s.close=o,s},Z=function(){let r=e=>e+"";r.strip=e=>e.replaceAll(S(),"");for(let e in k)h[e]={get(){let t=x(this,k[e]);return Object.defineProperty(this,e,{value:t}),t}};for(let e in R)h[e]={get(){let t=x(this,R[e]);return Object.defineProperty(this,e,{value:t}),t}};return B=Object.defineProperties({},h),Object.setPrototypeOf(r,B),r};for(let r in w)h[r]={get(){return (...e)=>x(this,w[r](...e))}};h.ansi256=h.fg;h.bgAnsi256=h.bg;var I=Z;var v={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};var G=(r,e)=>{let t=r.length;if(e=Number.parseInt(e.toString(),10),Number.isNaN(e)||e<2)throw new Error("Invalid number of steps (< 2)");if(e<t)throw new Error("Number of steps cannot be inferior to number of stops");let n=[];for(let s=1;s<t;s++){let i=(e-1)*(r[s].position-r[s-1].position);n.push(Math.max(1,Math.round(i)));}let o=1;for(let s=t-1;s--;)o+=n[s];for(;o!==e;)if(o<e){let s=Math.min(...n);n[n.indexOf(s)]++,o++;}else {let s=Math.max(...n);n[n.indexOf(s)]--,o--;}return n};var P=(r,e,t)=>{let n=0,o=0,s=0,i=Math.floor(r/60),u=r/60-i,a=t*(1-e),p=t*(1-u*e),b=t*(1-(1-u)*e);return i%6===0?(n=t,o=b,s=a):i%6===1?(n=p,o=t,s=a):i%6===2?(n=a,o=t,s=b):i%6===3?(n=a,o=p,s=t):i%6===4?(n=b,o=a,s=t):i%6===5&&(n=t,o=a,s=p),{b:Math.round(s*255),g:Math.round(o*255),r:Math.round(n*255)}};var O=({b:r,g:e,r:t})=>{let n,o,s,i=0,u=0;t/=255,e/=255,r/=255;let a=Math.max(t,e,r),p=a-Math.min(t,e,r),b=c=>(a-c)/6/p+1/2;return p!==0&&(u=p/a,n=b(t),o=b(e),s=b(r),a===t?i=s-o:a===e?i=.3333333333333333+n-s:a===r&&(i=.6666666666666666+o-n),i<0?i+=1:i>1&&(i-=1)),{h:i*360,s:u,v:a}};var W={b:256,g:256,r:256},X={h:360,s:1,v:1},D=(r,e,t)=>{let n={};for(let o in r)Object.prototype.hasOwnProperty.call(r,o)&&(n[o]=t===0?0:(e[o]-r[o])/t);return n},N=(r,e,t,n)=>{let o={};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&(o[s]=r[s]*t+e[s],o[s]=o[s]<0?o[s]+n[s]:n[s]===1?o[s]:o[s]%n[s]);return o},C=(r,e,t)=>{let n={b:r.color[2],g:r.color[1],r:r.color[0]},o={b:e.color[2],g:e.color[1],r:e.color[0]},s=D(n,o,t),i=[{...n}];for(let u=1;u<t;u++){let a=N(s,n,u,W);i.push({b:Math.floor(a.b),g:Math.floor(a.g),r:Math.floor(a.r)});}return i},A=(r,e,t,n)=>{let o=O({b:r.color[2],g:r.color[1],r:r.color[0]}),s=O({b:e.color[2],g:e.color[1],r:e.color[0]});if(o.s===0||s.s===0)return C(r,e,t);let i;if(typeof n=="boolean")i=n;else {let b=o.h<s.h&&s.h-o.h<180||o.h>s.h&&o.h-s.h>180;i=n==="long"&&b||n==="short"&&!b;}let u=D(o,s,t),a=[{b:r.color[2],g:r.color[1],r:r.color[0]}],p;o.h<=s.h&&!i||o.h>=s.h&&i?p=s.h-o.h:i?p=360-s.h+o.h:p=360-o.h+s.h,u.h=(-1)**(i?1:0)*Math.abs(p)/t;for(let b=1;b<t;b++){let c=N(u,o,b,X);a.push(P(c.h,c.s,c.v));}return a};var y=class r{#e;stops;constructor(e,t){if(this.#e=e,this.stops=[],t.length<2)throw new Error("Invalid number of stops (< 2)");let n=t[0].position!==void 0,o=t.length,s=-1,i=!1;for(let[u,a]of t.entries()){let p={},b=a.position!==void 0;if(n!==b)throw new Error("Cannot mix positioned and non-positioned color stops");if(b){let c=a,d=c.color!==void 0;if(!d&&(i||u===0||u===o-1))throw new Error("Cannot define two consecutive position-only stops");i=!d;let m;if(d&&(Array.isArray(c.color)?m=c.color:typeof c.color=="string"?m=c.color.includes("#")?f(c.color):v[c.color]:c.color.r!==void 0&&c.color.g!==void 0&&c.color.b&&(m=[c.color.r,c.color.g,c.color.b])),p={color:m,colorLess:!d,position:c.position},p.position<0||p.position>1)throw new Error("Color stops positions must be between 0 and 1");if(p.position<s)throw new Error("Color stops positions are not ordered");s=p.position;}else if(Array.isArray(a))p={color:a,position:u/(o-1)};else if(typeof a=="string")p={color:a.includes("#")?f(a):v[a],position:u/(o-1)};else if(a.r!==void 0&&a.g!==void 0&&a.b!==void 0)p={color:[a.r,a.g,a.b],position:u/(o-1)};else throw new Error("Invalid color stop");this.stops.push(p);}this.stops[0].position!==0&&(this.stops.unshift({color:this.stops[0].color,position:0}),o++),this.stops[o-1].position!==1&&this.stops.push({color:this.stops[o-1].color,position:1});}reverse(){let e=[];for(let t of this.stops){let n={...t};n.position=1-t.position,e.push(n);}return new r(this.#e,e.reverse())}loop(){let e=[],t=[];for(let n of this.stops)e.push({color:n.color,position:(n.position||0)/2});for(let n of this.stops.slice(0,-1))t.push({color:n.color,position:1-(n.position||0)/2});return new r(this.#e,[...e,...t.reverse()])}rgb(e){let t=G(this.stops,e),n=[];this.stops.forEach((o,s)=>{if(o.colorLess){let i=C(this.stops[s-1],this.stops[s+1],2);o.color=[i[1].r,i[1].g,i[1].b];}});for(let o=0,s=this.stops.length;o<s-1;o++){let i=C(this.stops[o],this.stops[o+1],t[o]);n.splice(n.length,0,...i.map(u=>this.#e.rgb(u.r,u.g,u.b)));}return n.push(this.#e.rgb(...this.stops.at(-1).color)),n}hsv(e,t=!1){let n=G(this.stops,e),o=[];this.stops.forEach((s,i)=>{if(s.colorLess){let u=A(this.stops[i-1],this.stops[i+1],2,t);s.color=[u[1].r,u[1].g,u[1].b];}});for(let s=0,i=this.stops.length;s<i-1;s++){let u=A(this.stops[s],this.stops[s+1],n[s],t);o.splice(o.length,0,...u.map(a=>this.#e.rgb(a.r,a.g,a.b)));}return o.push(this.#e.rgb(...this.stops.at(-1).color)),o}};var j=new I,T=/\s/g,ye=(r,e)=>{let{hsvSpin:t="short",interpolation:n="rgb"}=e??{},o=new y(j,r);return e?.loop?o=o.loop():e?.reverse&&(o=o.reverse()),s=>{let i=Math.max(s.replaceAll(T,"").length,o.stops.length),u=n==="rgb"?o.rgb(i):o.hsv(i,t),a="";for(let p of s)if(T.test(p))a+=p;else {let b=u.shift();a+=b(p);}return a}},Ce=(r,e)=>{let{hsvSpin:t="short",interpolation:n="rgb"}=e??{},o=new y(j,r);return e?.loop?o=o.loop():e?.reverse&&(o=o.reverse()),s=>{let i=s.split(` | ||
`),u=Reflect.apply(Math.max,null,[...i.map(b=>b.length),o.stops.length]),a=n==="rgb"?o.rgb(u):o.hsv(u,t),p=[];for(let b of i){let c=[...a],d="";for(let m of b)d+=T.test(m)?m:c.shift()(m);p.push(d);}return p.join(` | ||
function B({onlyFirst:r=!1}={}){let e=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(e,r?void 0:"g")}var h=(r,e,o)=>e>r?e:r>o?o:r;var S=r=>{let[,e]=/([a-f\d]{3,6})/i.exec(r)??[],o=e?e.length:0;if(o===3)e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2];else if(o!==6)return [0,0,0];let n=Number.parseInt(e,16);return [n>>16&255,n>>8&255,n&255]};var v=(r,e,o)=>r===e&&e===o?r<8?16:r>248?231:Math.round((r-8)/247*24)+232:16+36*Math.round(r/51)+6*Math.round(e/51)+Math.round(o/51),R=r=>{let e,o,n;if(r<8)return 30+r;if(r<16)return 90+(r-8);if(r>=232)e=o=n=((r-232)*10+8)/255;else {r-=16;let i=r%36;e=Math.floor(r/36)/5,o=Math.floor(i/6)/5,n=i%6/5;}let t=Math.max(e,o,n)*2;if(t===0)return 30;let s=30+(Math.round(n)<<2|Math.round(o)<<1|Math.round(e));return t===2?s+60:s},G=(r,e,o)=>R(v(r,e,o));var c=39,m=49,T=isStdoutColorSupported(),Z={close:"",open:""},l=T>0?(r,e)=>({close:"\x1B["+e+"m",open:"\x1B["+r+"m"}):()=>Z,L=r=>(e,o,n)=>r(v(Number(e),Number(o),Number(n))),E=r=>e=>{let[o,n,t]=S(e);return r(o,n,t)},A=r=>l("38;5;"+r,c),O=r=>l("48;5;"+r,m),x=(r,e,o)=>l("38;2;"+r+";"+e+";"+o,c),k=(r,e,o)=>l("48;2;"+r+";"+e+";"+o,m);T===1?(A=r=>l(R(Number(r)),c),O=r=>l(R(Number(r))+10,m),x=(r,e,o)=>l(G(Number(r),Number(e),Number(o)),c),k=(r,e,o)=>l(G(Number(r),Number(e),Number(o))+10,m)):T===2&&(x=L(A),k=L(O));var M={bold:l(1,22),dim:l(2,22),hidden:l(8,28),inverse:l(7,27),italic:l(3,23),overline:l(53,55),reset:l(0,0),strike:l(9,29),strikethrough:l(9,29),underline:l(4,24),visible:Z},z={bgBlack:l(40,m),bgBlackBright:l(100,m),bgBlue:l(44,m),bgBlueBright:l(104,m),bgCyan:l(46,m),bgCyanBright:l(106,m),bgGray:l(100,m),bgGreen:l(42,m),bgGreenBright:l(102,m),bgGrey:l(100,m),bgMagenta:l(45,m),bgMagentaBright:l(105,m),bgRed:l(41,m),bgRedBright:l(101,m),bgWhite:l(47,m),bgWhiteBright:l(107,m),bgYellow:l(43,m),bgYellowBright:l(103,m),black:l(30,c),blackBright:l(90,c),blue:l(34,c),blueBright:l(94,c),cyan:l(36,c),cyanBright:l(96,c),gray:l(90,c),green:l(32,c),greenBright:l(92,c),grey:l(90,c),magenta:l(35,c),magentaBright:l(95,c),red:l(31,c),redBright:l(91,c),white:l(37,c),whiteBright:l(97,c),yellow:l(33,c),yellowBright:l(93,c)},H={bg:r=>O(h(r,0,255)),bgHex:E(k),bgRgb:(r,e,o)=>k(h(r,0,255),h(e,0,255),h(o,0,255)),fg:r=>A(h(r,0,255)),hex:E(x),rgb:(r,e,o)=>x(h(r,0,255),h(e,0,255),h(o,0,255))};var F=(r,e,o)=>{if(e==="")return r;let n=r.indexOf(e);if(n<0)return r;let t=e.length,s=0,i="";for(;~n;)i+=r.slice(s,n)+o,s=n+t,n=r.indexOf(e,s);return i+r.slice(s)};var d={},N=null,Q=(r,e,o)=>{if(!r)return "";let n=r.raw==null?r+"":String.raw(r,...e);if(n.includes("\x1B"))for(let t=o;t;t=t.props)n=F(n,t.close,t.open);return n.includes(` | ||
`)&&(n=n.replace(/(\r*\n)/g,o.closeStack+"$1"+o.openStack)),o.openStack+n+o.closeStack},I=({props:r},{close:e,open:o})=>{let n=(r?.openStack??"")+o,t=e+(r?.closeStack??""),s=(i,...u)=>Q(i,u,s.props);return Object.setPrototypeOf(s,N),s.props={close:e,closeStack:t,open:o,openStack:n,props:r},s.open=n,s.close=t,s},U=function(){let r=e=>e+"";r.strip=e=>e.replaceAll(B(),"");for(let e in z)d[e]={get(){let o=I(this,z[e]);return Object.defineProperty(this,e,{value:o}),o}};for(let e in M)d[e]={get(){let o=I(this,M[e]);return Object.defineProperty(this,e,{value:o}),o}};return N=Object.defineProperties({},d),Object.setPrototypeOf(r,N),r};for(let r in H)d[r]={get(){return (...e)=>I(this,H[r](...e))}};d.ansi256=d.fg;d.bgAnsi256=d.bg;var W=U;var D={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};var P=(r,e)=>{let o=r.length;if(e=Number.parseInt(e.toString(),10),Number.isNaN(e)||e<2)throw new Error("Invalid number of steps (< 2)");if(e<o)throw new Error("Number of steps cannot be inferior to number of stops");let n=[];for(let s=1;s<o;s++){let i=(e-1)*(r[s].position-r[s-1].position);n.push(Math.max(1,Math.round(i)));}let t=1;for(let s=o-1;s--;)t+=n[s];for(;t!==e;)if(t<e){let s=Math.min(...n);n[n.indexOf(s)]++,t++;}else {let s=Math.max(...n);n[n.indexOf(s)]--,t--;}return n};var X=(r,e,o)=>{let n=0,t=0,s=0,i=Math.floor(r/60),u=r/60-i,a=o*(1-e),p=o*(1-u*e),b=o*(1-(1-u)*e);return i%6===0?(n=o,t=b,s=a):i%6===1?(n=p,t=o,s=a):i%6===2?(n=a,t=o,s=b):i%6===3?(n=a,t=p,s=o):i%6===4?(n=b,t=a,s=o):i%6===5&&(n=o,t=a,s=p),{b:Math.round(s*255),g:Math.round(t*255),r:Math.round(n*255)}};var j=({b:r,g:e,r:o})=>{let n,t,s,i=0,u=0;o/=255,e/=255,r/=255;let a=Math.max(o,e,r),p=a-Math.min(o,e,r),b=g=>(a-g)/6/p+1/2;return p!==0&&(u=p/a,n=b(o),t=b(e),s=b(r),a===o?i=s-t:a===e?i=.3333333333333333+n-s:a===r&&(i=.6666666666666666+t-n),i<0?i+=1:i>1&&(i-=1)),{h:i*360,s:u,v:a}};var _={b:256,g:256,r:256},ee={h:360,s:1,v:1},Y=(r,e,o)=>{let n={};for(let t in r)Object.prototype.hasOwnProperty.call(r,t)&&(n[t]=o===0?0:(e[t]-r[t])/o);return n},$=(r,e,o,n)=>{let t={};for(let s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=r[s]*o+e[s],t[s]=t[s]<0?t[s]+n[s]:n[s]===1?t[s]:t[s]%n[s]);return t},w=(r,e,o)=>{let n={b:r.color[2],g:r.color[1],r:r.color[0]},t={b:e.color[2],g:e.color[1],r:e.color[0]},s=Y(n,t,o),i=[{...n}];for(let u=1;u<o;u++){let a=$(s,n,u,_);i.push({b:Math.floor(a.b),g:Math.floor(a.g),r:Math.floor(a.r)});}return i},V=(r,e,o,n)=>{let t=j({b:r.color[2],g:r.color[1],r:r.color[0]}),s=j({b:e.color[2],g:e.color[1],r:e.color[0]});if(t.s===0||s.s===0)return w(r,e,o);let i;if(typeof n=="boolean")i=n;else {let b=t.h<s.h&&s.h-t.h<180||t.h>s.h&&t.h-s.h>180;i=n==="long"&&b||n==="short"&&!b;}let u=Y(t,s,o),a=[{b:r.color[2],g:r.color[1],r:r.color[0]}],p;t.h<=s.h&&!i||t.h>=s.h&&i?p=s.h-t.h:i?p=360-s.h+t.h:p=360-t.h+s.h,u.h=(-1)**(i?1:0)*Math.abs(p)/o;for(let b=1;b<o;b++){let g=$(u,t,b,ee);a.push(X(g.h,g.s,g.v));}return a};var C=class r{#e;stops;constructor(e,o){if(this.#e=e,this.stops=[],o.length<2)throw new Error("Invalid number of stops (< 2)");let n=o[0].position!==void 0,t=o.length,s=-1,i=!1;for(let[u,a]of o.entries()){let p={},b=a.position!==void 0;if(n!==b)throw new Error("Cannot mix positioned and non-positioned color stops");if(b){let g=a,y=g.color!==void 0;if(!y&&(i||u===0||u===t-1))throw new Error("Cannot define two consecutive position-only stops");i=!y;let f;if(y&&(Array.isArray(g.color)?f=g.color:typeof g.color=="string"?f=g.color.includes("#")?S(g.color):D[g.color]:g.color.r!==void 0&&g.color.g!==void 0&&g.color.b&&(f=[g.color.r,g.color.g,g.color.b])),p={color:f,colorLess:!y,position:g.position},p.position<0||p.position>1)throw new Error("Color stops positions must be between 0 and 1");if(p.position<s)throw new Error("Color stops positions are not ordered");s=p.position;}else if(Array.isArray(a))p={color:a,position:u/(t-1)};else if(typeof a=="string")p={color:a.includes("#")?S(a):D[a],position:u/(t-1)};else if(a.r!==void 0&&a.g!==void 0&&a.b!==void 0)p={color:[a.r,a.g,a.b],position:u/(t-1)};else throw new Error("Invalid color stop");this.stops.push(p);}this.stops[0].position!==0&&(this.stops.unshift({color:this.stops[0].color,position:0}),t++),this.stops[t-1].position!==1&&this.stops.push({color:this.stops[t-1].color,position:1});}reverse(){let e=[];for(let o of this.stops){let n={...o};n.position=1-o.position,e.push(n);}return new r(this.#e,e.reverse())}loop(){let e=[],o=[];for(let n of this.stops)e.push({color:n.color,position:(n.position||0)/2});for(let n of this.stops.slice(0,-1))o.push({color:n.color,position:1-(n.position||0)/2});return new r(this.#e,[...e,...o.reverse()])}rgb(e){let o=P(this.stops,e),n=[];this.stops.forEach((t,s)=>{if(t.colorLess){let i=w(this.stops[s-1],this.stops[s+1],2);t.color=[i[1].r,i[1].g,i[1].b];}});for(let t=0,s=this.stops.length;t<s-1;t++){let i=w(this.stops[t],this.stops[t+1],o[t]);n.splice(n.length,0,...i.map(u=>this.#e.rgb(u.r,u.g,u.b)));}return n.push(this.#e.rgb(...this.stops.at(-1).color)),n}hsv(e,o=!1){let n=P(this.stops,e),t=[];this.stops.forEach((s,i)=>{if(s.colorLess){let u=V(this.stops[i-1],this.stops[i+1],2,o);s.color=[u[1].r,u[1].g,u[1].b];}});for(let s=0,i=this.stops.length;s<i-1;s++){let u=V(this.stops[s],this.stops[s+1],n[s],o);t.splice(t.length,0,...u.map(a=>this.#e.rgb(a.r,a.g,a.b)));}return t.push(this.#e.rgb(...this.stops.at(-1).color)),t}};var J=new W,q=/\s/g,Ae=(r,e)=>{let{hsvSpin:o="short",interpolation:n="rgb"}=e??{},t=new C(J,r);return e?.loop?t=t.loop():e?.reverse&&(t=t.reverse()),s=>{let i=Math.max(s.replaceAll(q,"").length,t.stops.length),u=n==="rgb"?t.rgb(i):t.hsv(i,o),a="";for(let p of s)if(q.test(p))a+=p;else {let b=u.shift();a+=b(p);}return a}},Oe=(r,e)=>{let{hsvSpin:o="short",interpolation:n="rgb"}=e??{},t=new C(J,r);return e?.loop?t=t.loop():e?.reverse&&(t=t.reverse()),s=>{let i=s.split(` | ||
`),u=Reflect.apply(Math.max,null,[...i.map(b=>b.length),t.stops.length]),a=n==="rgb"?t.rgb(u):t.hsv(u,o),p=[];for(let b of i){let g=[...a],y="";for(let f of b)y+=q.test(f)?f:g.shift()(f);p.push(y);}return p.join(` | ||
`)}}; | ||
export { y as GradientBuilder, ye as gradient, Ce as multilineGradient }; | ||
export { C as GradientBuilder, Ae as gradient, Oe as multilineGradient }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=gradient.js.map |
import { isStdoutColorSupported } from '@visulima/is-ansi-color-supported'; | ||
function b({onlyFirst:e=!1}={}){let t=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(t,e?void 0:"g")}var g=(e,t,o)=>t>e?t:e>o?o:e;var c=e=>{let t=e.replace("#","");if(t.length===3)t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2];else if(t.length!==6)return [0,0,0];let o=Number.parseInt(t,16);return [o>>16&255,o>>8&255,o&255]};var r=isStdoutColorSupported()>0?(e,t)=>({close:"\x1B["+t+"m",open:"\x1B["+e+"m"}):()=>({close:"",open:""}),R=e=>r("38;5;"+e,39),w=e=>r("48;5;"+e,49),f=(e,t,o)=>r("38;2;"+e+";"+t+";"+o,39),C=(e,t,o)=>r("48;2;"+e+";"+t+";"+o,49),p={bold:r(1,22),dim:r(2,22),hidden:r(8,28),inverse:r(7,27),italic:r(3,23),overline:r(53,55),reset:r(0,0),strike:r(9,29),strikethrough:r(9,29),underline:r(4,24),visible:{close:"",open:""}},u={bgBlack:r(40,49),bgBlackBright:r(100,49),bgBlue:r(44,49),bgBlueBright:r(104,49),bgCyan:r(46,49),bgCyanBright:r(106,49),bgGray:r(100,49),bgGreen:r(42,49),bgGreenBright:r(102,49),bgGrey:r(100,49),bgMagenta:r(45,49),bgMagentaBright:r(105,49),bgRed:r(41,49),bgRedBright:r(101,49),bgWhite:r(47,49),bgWhiteBright:r(107,49),bgYellow:r(43,49),bgYellowBright:r(103,49),black:r(30,39),blackBright:r(90,39),blue:r(34,39),blueBright:r(94,39),cyan:r(36,39),cyanBright:r(96,39),gray:r(90,39),green:r(32,39),greenBright:r(92,39),grey:r(90,39),magenta:r(35,39),magentaBright:r(95,39),red:r(31,39),redBright:r(91,39),white:r(37,39),whiteBright:r(97,39),yellow:r(33,39),yellowBright:r(93,39)},y={bg:e=>w(g(e,0,255)),bgHex:e=>C(...c(e)),bgRgb:(e,t,o)=>C(g(e,0,255),g(t,0,255),g(o,0,255)),fg:e=>R(g(e,0,255)),hex:e=>f(...c(e)),rgb:(e,t,o)=>f(g(e,0,255),g(t,0,255),g(o,0,255))};var B=(e,t,o)=>{if(t==="")return e;let n=e.indexOf(t);if(n<0)return e;let i=t.length,s=0,a="";for(;~n;)a+=e.slice(s,n)+o,s=n+i,n=e.indexOf(t,s);return a+e.slice(s)};var l={},m=null,S=(e,t,o)=>{if(!e)return "";let n=e.raw==null?e+"":String.raw(e,...t);if(n.includes("\x1B"))for(let i=o;i;i=i.props)n=B(n,i.close,i.open);return n.includes(` | ||
`)&&(n=n.replace(/(\r*\n)/g,o.closeStack+"$1"+o.openStack)),o.openStack+n+o.closeStack},h=({props:e},{close:t,open:o})=>{let n=(e?.openStack??"")+o,i=t+(e?.closeStack??""),s=(a,...x)=>S(a,x,s.props);return Object.setPrototypeOf(s,m),s.props={close:t,closeStack:i,open:o,openStack:n,props:e},s.open=n,s.close=i,s},z=function(){let e=t=>t+"";e.strip=t=>t.replaceAll(b(),"");for(let t in u)l[t]={get(){let o=h(this,u[t]);return Object.defineProperty(this,t,{value:o}),o}};for(let t in p)l[t]={get(){let o=h(this,p[t]);return Object.defineProperty(this,t,{value:o}),o}};return m=Object.defineProperties({},l),Object.setPrototypeOf(e,m),e};for(let e in y)l[e]={get(){return (...t)=>h(this,y[e](...t))}};l.ansi256=l.fg;l.bgAnsi256=l.bg;var d=z;var k=new d,q=k,{ansi256:I,bg:V,bgAnsi256:E,bgBlack:N,bgBlackBright:$,bgBlue:F,bgBlueBright:J,bgCyan:K,bgCyanBright:Q,bgGray:U,bgGreen:X,bgGreenBright:_,bgGrey:ee,bgHex:re,bgMagenta:te,bgMagentaBright:oe,bgRed:ne,bgRedBright:se,bgRgb:ie,bgWhite:ge,bgWhiteBright:le,bgYellow:ae,bgYellowBright:be,black:ce,blackBright:pe,blue:ue,blueBright:ye,bold:me,cyan:he,cyanBright:de,dim:fe,fg:Ce,gray:Be,green:ke,greenBright:xe,grey:Ae,hex:Re,hidden:we,inverse:Se,italic:ze,magenta:De,magentaBright:Pe,overline:Te,red:je,redBright:ve,reset:Oe,rgb:Ge,strike:He,strikethrough:Me,strip:Le,underline:We,visible:Ye,white:Ze,whiteBright:qe,yellow:Ie,yellowBright:Ve}=k; | ||
function y({onlyFirst:r=!1}={}){let e=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(e,r?void 0:"g")}var l=(r,e,n)=>e>r?e:r>n?n:r;var z=r=>{let[,e]=/([a-f\d]{3,6})/i.exec(r)??[],n=e?e.length:0;if(n===3)e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2];else if(n!==6)return [0,0,0];let o=Number.parseInt(e,16);return [o>>16&255,o>>8&255,o&255]};var h=(r,e,n)=>r===e&&e===n?r<8?16:r>248?231:Math.round((r-8)/247*24)+232:16+36*Math.round(r/51)+6*Math.round(e/51)+Math.round(n/51),c=r=>{let e,n,o;if(r<8)return 30+r;if(r<16)return 90+(r-8);if(r>=232)e=n=o=((r-232)*10+8)/255;else {r-=16;let u=r%36;e=Math.floor(r/36)/5,n=Math.floor(u/6)/5,o=u%6/5;}let g=Math.max(e,n,o)*2;if(g===0)return 30;let a=30+(Math.round(o)<<2|Math.round(n)<<1|Math.round(e));return g===2?a+60:a},f=(r,e,n)=>c(h(r,e,n));var s=39,i=49,d=isStdoutColorSupported(),T={close:"",open:""},t=d>0?(r,e)=>({close:"\x1B["+e+"m",open:"\x1B["+r+"m"}):()=>T,D=r=>(e,n,o)=>r(h(Number(e),Number(n),Number(o))),M=r=>e=>{let[n,o,g]=z(e);return r(n,o,g)},C=r=>t("38;5;"+r,s),B=r=>t("48;5;"+r,i),m=(r,e,n)=>t("38;2;"+r+";"+e+";"+n,s),p=(r,e,n)=>t("48;2;"+r+";"+e+";"+n,i);d===1?(C=r=>t(c(Number(r)),s),B=r=>t(c(Number(r))+10,i),m=(r,e,n)=>t(f(Number(r),Number(e),Number(n)),s),p=(r,e,n)=>t(f(Number(r),Number(e),Number(n))+10,i)):d===2&&(m=D(C),p=D(B));var x={bold:t(1,22),dim:t(2,22),hidden:t(8,28),inverse:t(7,27),italic:t(3,23),overline:t(53,55),reset:t(0,0),strike:t(9,29),strikethrough:t(9,29),underline:t(4,24),visible:T},k={bgBlack:t(40,i),bgBlackBright:t(100,i),bgBlue:t(44,i),bgBlueBright:t(104,i),bgCyan:t(46,i),bgCyanBright:t(106,i),bgGray:t(100,i),bgGreen:t(42,i),bgGreenBright:t(102,i),bgGrey:t(100,i),bgMagenta:t(45,i),bgMagentaBright:t(105,i),bgRed:t(41,i),bgRedBright:t(101,i),bgWhite:t(47,i),bgWhiteBright:t(107,i),bgYellow:t(43,i),bgYellowBright:t(103,i),black:t(30,s),blackBright:t(90,s),blue:t(34,s),blueBright:t(94,s),cyan:t(36,s),cyanBright:t(96,s),gray:t(90,s),green:t(32,s),greenBright:t(92,s),grey:t(90,s),magenta:t(35,s),magentaBright:t(95,s),red:t(31,s),redBright:t(91,s),white:t(37,s),whiteBright:t(97,s),yellow:t(33,s),yellowBright:t(93,s)},A={bg:r=>B(l(r,0,255)),bgHex:M(p),bgRgb:(r,e,n)=>p(l(r,0,255),l(e,0,255),l(n,0,255)),fg:r=>C(l(r,0,255)),hex:M(m),rgb:(r,e,n)=>m(l(r,0,255),l(e,0,255),l(n,0,255))};var v=(r,e,n)=>{if(e==="")return r;let o=r.indexOf(e);if(o<0)return r;let g=e.length,a=0,u="";for(;~o;)u+=r.slice(a,o)+n,a=o+g,o=r.indexOf(e,a);return u+r.slice(a)};var b={},R=null,j=(r,e,n)=>{if(!r)return "";let o=r.raw==null?r+"":String.raw(r,...e);if(o.includes("\x1B"))for(let g=n;g;g=g.props)o=v(o,g.close,g.open);return o.includes(` | ||
`)&&(o=o.replace(/(\r*\n)/g,n.closeStack+"$1"+n.openStack)),n.openStack+o+n.closeStack},S=({props:r},{close:e,open:n})=>{let o=(r?.openStack??"")+n,g=e+(r?.closeStack??""),a=(u,...H)=>j(u,H,a.props);return Object.setPrototypeOf(a,R),a.props={close:e,closeStack:g,open:n,openStack:o,props:r},a.open=o,a.close=g,a},L=function(){let r=e=>e+"";r.strip=e=>e.replaceAll(y(),"");for(let e in k)b[e]={get(){let n=S(this,k[e]);return Object.defineProperty(this,e,{value:n}),n}};for(let e in x)b[e]={get(){let n=S(this,x[e]);return Object.defineProperty(this,e,{value:n}),n}};return R=Object.defineProperties({},b),Object.setPrototypeOf(r,R),r};for(let r in A)b[r]={get(){return (...e)=>S(this,A[r](...e))}};b.ansi256=b.fg;b.bgAnsi256=b.bg;var w=L;var P=new w,X=P,{ansi256:_,bg:rr,bgAnsi256:er,bgBlack:tr,bgBlackBright:nr,bgBlue:or,bgBlueBright:sr,bgCyan:ir,bgCyanBright:gr,bgGray:ar,bgGreen:lr,bgGreenBright:br,bgGrey:ur,bgHex:cr,bgMagenta:mr,bgMagentaBright:pr,bgRed:yr,bgRedBright:hr,bgRgb:fr,bgWhite:dr,bgWhiteBright:Cr,bgYellow:Br,bgYellowBright:xr,black:kr,blackBright:Ar,blue:Rr,blueBright:Sr,bold:wr,cyan:zr,cyanBright:Dr,dim:Mr,fg:Tr,gray:vr,green:Pr,greenBright:Hr,grey:Nr,hex:jr,hidden:Lr,inverse:Or,italic:Gr,magenta:Wr,magentaBright:Yr,overline:Zr,red:qr,redBright:Vr,reset:Fr,rgb:Ir,strike:Er,strikethrough:$r,strip:Jr,underline:Kr,visible:Qr,white:Ur,whiteBright:Xr,yellow:_r,yellowBright:re}=P; | ||
export { d as Colorize, I as ansi256, V as bg, E as bgAnsi256, N as bgBlack, $ as bgBlackBright, F as bgBlue, J as bgBlueBright, K as bgCyan, Q as bgCyanBright, U as bgGray, X as bgGreen, _ as bgGreenBright, ee as bgGrey, re as bgHex, te as bgMagenta, oe as bgMagentaBright, ne as bgRed, se as bgRedBright, ie as bgRgb, ge as bgWhite, le as bgWhiteBright, ae as bgYellow, be as bgYellowBright, ce as black, pe as blackBright, ue as blue, ye as blueBright, me as bold, he as cyan, de as cyanBright, q as default, fe as dim, Ce as fg, Be as gray, ke as green, xe as greenBright, Ae as grey, Re as hex, we as hidden, Se as inverse, ze as italic, De as magenta, Pe as magentaBright, Te as overline, je as red, ve as redBright, Oe as reset, Ge as rgb, He as strike, Me as strikethrough, Le as strip, We as underline, Ye as visible, Ze as white, qe as whiteBright, Ie as yellow, Ve as yellowBright }; | ||
export { w as Colorize, _ as ansi256, rr as bg, er as bgAnsi256, tr as bgBlack, nr as bgBlackBright, or as bgBlue, sr as bgBlueBright, ir as bgCyan, gr as bgCyanBright, ar as bgGray, lr as bgGreen, br as bgGreenBright, ur as bgGrey, cr as bgHex, mr as bgMagenta, pr as bgMagentaBright, yr as bgRed, hr as bgRedBright, fr as bgRgb, dr as bgWhite, Cr as bgWhiteBright, Br as bgYellow, xr as bgYellowBright, kr as black, Ar as blackBright, Rr as blue, Sr as blueBright, wr as bold, zr as cyan, Dr as cyanBright, X as default, Mr as dim, Tr as fg, vr as gray, Pr as green, Hr as greenBright, Nr as grey, jr as hex, Lr as hidden, Or as inverse, Gr as italic, Wr as magenta, Yr as magentaBright, Zr as overline, qr as red, Vr as redBright, Fr as reset, Ir as rgb, Er as strike, $r as strikethrough, Jr as strip, Kr as underline, Qr as visible, Ur as white, Xr as whiteBright, _r as yellow, re as yellowBright }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.server.js.map |
import { isStdoutColorSupported } from '@visulima/is-ansi-color-supported'; | ||
function b({onlyFirst:e=!1}={}){let r=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(r,e?void 0:"g")}var a=(e,r,t)=>r>e?r:e>t?t:e;var u=e=>{let r=e.replace("#","");if(r.length===3)r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2];else if(r.length!==6)return [0,0,0];let t=Number.parseInt(r,16);return [t>>16&255,t>>8&255,t&255]};var n=isStdoutColorSupported()>0?(e,r)=>({close:"\x1B["+r+"m",open:"\x1B["+e+"m"}):()=>({close:"",open:""}),j=e=>n("38;5;"+e,39),v=e=>n("48;5;"+e,49),S=(e,r,t)=>n("38;2;"+e+";"+r+";"+t,39),R=(e,r,t)=>n("48;2;"+e+";"+r+";"+t,49),y={bold:n(1,22),dim:n(2,22),hidden:n(8,28),inverse:n(7,27),italic:n(3,23),overline:n(53,55),reset:n(0,0),strike:n(9,29),strikethrough:n(9,29),underline:n(4,24),visible:{close:"",open:""}},f={bgBlack:n(40,49),bgBlackBright:n(100,49),bgBlue:n(44,49),bgBlueBright:n(104,49),bgCyan:n(46,49),bgCyanBright:n(106,49),bgGray:n(100,49),bgGreen:n(42,49),bgGreenBright:n(102,49),bgGrey:n(100,49),bgMagenta:n(45,49),bgMagentaBright:n(105,49),bgRed:n(41,49),bgRedBright:n(101,49),bgWhite:n(47,49),bgWhiteBright:n(107,49),bgYellow:n(43,49),bgYellowBright:n(103,49),black:n(30,39),blackBright:n(90,39),blue:n(34,39),blueBright:n(94,39),cyan:n(36,39),cyanBright:n(96,39),gray:n(90,39),green:n(32,39),greenBright:n(92,39),grey:n(90,39),magenta:n(35,39),magentaBright:n(95,39),red:n(31,39),redBright:n(91,39),white:n(37,39),whiteBright:n(97,39),yellow:n(33,39),yellowBright:n(93,39)},d={bg:e=>v(a(e,0,255)),bgHex:e=>R(...u(e)),bgRgb:(e,r,t)=>R(a(e,0,255),a(r,0,255),a(t,0,255)),fg:e=>j(a(e,0,255)),hex:e=>S(...u(e)),rgb:(e,r,t)=>S(a(e,0,255),a(r,0,255),a(t,0,255))};var T=(e,r,t)=>{if(r==="")return e;let s=e.indexOf(r);if(s<0)return e;let o=r.length,i=0,l="";for(;~s;)l+=e.slice(i,s)+t,i=s+o,s=e.indexOf(r,i);return l+e.slice(i)};var g={},h=null,H=(e,r,t)=>{if(!e)return "";let s=e.raw==null?e+"":String.raw(e,...r);if(s.includes("\x1B"))for(let o=t;o;o=o.props)s=T(s,o.close,o.open);return s.includes(` | ||
`)&&(s=s.replace(/(\r*\n)/g,t.closeStack+"$1"+t.openStack)),t.openStack+s+t.closeStack},C=({props:e},{close:r,open:t})=>{let s=(e?.openStack??"")+t,o=r+(e?.closeStack??""),i=(l,...c)=>H(l,c,i.props);return Object.setPrototypeOf(i,h),i.props={close:r,closeStack:o,open:t,openStack:s,props:e},i.open=s,i.close=o,i},O=function(){let e=r=>r+"";e.strip=r=>r.replaceAll(b(),"");for(let r in f)g[r]={get(){let t=C(this,f[r]);return Object.defineProperty(this,r,{value:t}),t}};for(let r in y)g[r]={get(){let t=C(this,y[r]);return Object.defineProperty(this,r,{value:t}),t}};return h=Object.defineProperties({},g),Object.setPrototypeOf(e,h),e};for(let e in d)g[e]={get(){return (...r)=>C(this,d[e](...r))}};g.ansi256=g.fg;g.bgAnsi256=g.bg;var B=O;var x=e=>(r,...t)=>{if(!Array.isArray(r)||!Array.isArray(r.raw))throw new TypeError("A tagged template literal must be provided");let s=[r.raw[0]];for(let o=1;o<r.raw.length;o++)s.push(String(t[o-1]).replaceAll(/[{}\\]/g,"\\$&"),String(r.raw[o]));return e(s.join(""))};var G=new Map([["\\","\\"],["0","\0"],["a","\x07"],["b","\b"],["e","\x1B"],["f","\f"],["n",` | ||
`],["r","\r"],["t"," "],["v","\v"]]),k=e=>{let r=e.startsWith("u"),t=e[1]==="{";return r&&!t&&e.length===5||e.startsWith("x")&&e.length===3?String.fromCodePoint(Number.parseInt(e.slice(1),16)):r&&t?String.fromCodePoint(Number.parseInt(e.slice(2,-1),16)):G.get(e)??e};var L=/\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|\{(~)?(#?[\w:]+(?:\([^)]*\))?(?:\.#?[\w:]+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n))|(\})|((?:.|[\r\n\f])+?)/gi,z=/(?:^|\.)(?:(\w+)(?:\(([^)]*)\))?|#(?=[:a-f\d]{2,})([a-f\d]{6})?(?::([a-f\d]{6}))?)/gi,N=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,M=/\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi,$=(e,r)=>{let t=[],s=r.trim().split(/\s*,\s*/),o;for(let i of s){let l=Number(i);if(!Number.isNaN(l))t.push(l);else if(o=N.exec(i))t.push(o[2].replace(M,(c,p,m)=>p?k(p):m));else throw new Error(`Invalid template style argument: ${i} (in style '${e}')`)}return t},I=e=>{z.lastIndex=0;let r=[],t;for(;(t=z.exec(e))!==null;){let s=t[1];t[2]?r.push([s,...$(s,t[2])]):t[3]||t[4]?(t[3]&&r.push(["rgb",...u(t[3])]),t[4]&&r.push(["bgRgb",...u(t[4])])):r.push([s]);}return r},E=(e,r)=>{let t={};for(let o of r)for(let i of o.styles)t[i[0]]=o.inverse?null:i.slice(1);let s=e;for(let[o,i]of Object.entries(t))if(Array.isArray(i)){if(!(o in s))throw new Error(`Unknown style: ${o}`);s=i.length>0?s[o](...i):s[o];}return s},A=e=>r=>{let t=[],s=[],o=[];if(r.replaceAll(L,(i,l,c,p,m,P)=>{if(l)o.push(k(l));else if(p){let w=o.join("");o=[],s.push(t.length===0?w:E(e,t)(w)),t.push({inverse:c,styles:I(p)});}else if(m){if(t.length===0)throw new Error("Found extraneous } in template literal");s.push(E(e,t)(o.join(""))),o=[],t.pop();}else o.push(P);}),s.push(o.join("")),t.length>0)throw new Error(`template literal is missing ${t.length} closing bracket${t.length===1?"":"s"} (\`}\`)`);return s.join("")};var V=new B,ue=e=>x(A(e)),W=A(V),pe=x(W); | ||
function C({onlyFirst:e=!1}={}){let r=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"].join("|");return new RegExp(r,e?void 0:"g")}var u=(e,r,t)=>r>e?r:e>t?t:e;var p=e=>{let[,r]=/([a-f\d]{3,6})/i.exec(e)??[],t=r?r.length:0;if(t===3)r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2];else if(t!==6)return [0,0,0];let s=Number.parseInt(r,16);return [s>>16&255,s>>8&255,s&255]};var x=(e,r,t)=>e===r&&r===t?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/51)+6*Math.round(r/51)+Math.round(t/51),f=e=>{let r,t,s;if(e<8)return 30+e;if(e<16)return 90+(e-8);if(e>=232)r=t=s=((e-232)*10+8)/255;else {e-=16;let g=e%36;r=Math.floor(e/36)/5,t=Math.floor(g/6)/5,s=g%6/5;}let o=Math.max(r,t,s)*2;if(o===0)return 30;let i=30+(Math.round(s)<<2|Math.round(t)<<1|Math.round(r));return o===2?i+60:i},A=(e,r,t)=>f(x(e,r,t));var l=39,a=49,k=isStdoutColorSupported(),H={close:"",open:""},n=k>0?(e,r)=>({close:"\x1B["+r+"m",open:"\x1B["+e+"m"}):()=>H,M=e=>(r,t,s)=>e(x(Number(r),Number(t),Number(s))),j=e=>r=>{let[t,s,o]=p(r);return e(t,s,o)},T=e=>n("38;5;"+e,l),w=e=>n("48;5;"+e,a),y=(e,r,t)=>n("38;2;"+e+";"+r+";"+t,l),d=(e,r,t)=>n("48;2;"+e+";"+r+";"+t,a);k===1?(T=e=>n(f(Number(e)),l),w=e=>n(f(Number(e))+10,a),y=(e,r,t)=>n(A(Number(e),Number(r),Number(t)),l),d=(e,r,t)=>n(A(Number(e),Number(r),Number(t))+10,a)):k===2&&(y=M(T),d=M(w));var S={bold:n(1,22),dim:n(2,22),hidden:n(8,28),inverse:n(7,27),italic:n(3,23),overline:n(53,55),reset:n(0,0),strike:n(9,29),strikethrough:n(9,29),underline:n(4,24),visible:H},R={bgBlack:n(40,a),bgBlackBright:n(100,a),bgBlue:n(44,a),bgBlueBright:n(104,a),bgCyan:n(46,a),bgCyanBright:n(106,a),bgGray:n(100,a),bgGreen:n(42,a),bgGreenBright:n(102,a),bgGrey:n(100,a),bgMagenta:n(45,a),bgMagentaBright:n(105,a),bgRed:n(41,a),bgRedBright:n(101,a),bgWhite:n(47,a),bgWhiteBright:n(107,a),bgYellow:n(43,a),bgYellowBright:n(103,a),black:n(30,l),blackBright:n(90,l),blue:n(34,l),blueBright:n(94,l),cyan:n(36,l),cyanBright:n(96,l),gray:n(90,l),green:n(32,l),greenBright:n(92,l),grey:n(90,l),magenta:n(35,l),magentaBright:n(95,l),red:n(31,l),redBright:n(91,l),white:n(37,l),whiteBright:n(97,l),yellow:n(33,l),yellowBright:n(93,l)},B={bg:e=>w(u(e,0,255)),bgHex:j(d),bgRgb:(e,r,t)=>d(u(e,0,255),u(r,0,255),u(t,0,255)),fg:e=>T(u(e,0,255)),hex:j(y),rgb:(e,r,t)=>y(u(e,0,255),u(r,0,255),u(t,0,255))};var L=(e,r,t)=>{if(r==="")return e;let s=e.indexOf(r);if(s<0)return e;let o=r.length,i=0,g="";for(;~s;)g+=e.slice(i,s)+t,i=s+o,s=e.indexOf(r,i);return g+e.slice(i)};var m={},z=null,_=(e,r,t)=>{if(!e)return "";let s=e.raw==null?e+"":String.raw(e,...r);if(s.includes("\x1B"))for(let o=t;o;o=o.props)s=L(s,o.close,o.open);return s.includes(` | ||
`)&&(s=s.replace(/(\r*\n)/g,t.closeStack+"$1"+t.openStack)),t.openStack+s+t.closeStack},E=({props:e},{close:r,open:t})=>{let s=(e?.openStack??"")+t,o=r+(e?.closeStack??""),i=(g,...c)=>_(g,c,i.props);return Object.setPrototypeOf(i,z),i.props={close:r,closeStack:o,open:t,openStack:s,props:e},i.open=s,i.close=o,i},W=function(){let e=r=>r+"";e.strip=r=>r.replaceAll(C(),"");for(let r in R)m[r]={get(){let t=E(this,R[r]);return Object.defineProperty(this,r,{value:t}),t}};for(let r in S)m[r]={get(){let t=E(this,S[r]);return Object.defineProperty(this,r,{value:t}),t}};return z=Object.defineProperties({},m),Object.setPrototypeOf(e,z),e};for(let e in B)m[e]={get(){return (...r)=>E(this,B[e](...r))}};m.ansi256=m.fg;m.bgAnsi256=m.bg;var O=W;var v=e=>(r,...t)=>{if(!Array.isArray(r)||!Array.isArray(r.raw))throw new TypeError("A tagged template literal must be provided");let s=[r.raw[0]];for(let o=1;o<r.raw.length;o++)s.push(String(t[o-1]).replaceAll(/[{}\\]/g,"\\$&"),String(r.raw[o]));return e(s.join(""))};var X=new Map([["\\","\\"],["0","\0"],["a","\x07"],["b","\b"],["e","\x1B"],["f","\f"],["n",` | ||
`],["r","\r"],["t"," "],["v","\v"]]),D=e=>{let r=e.startsWith("u"),t=e[1]==="{";return r&&!t&&e.length===5||e.startsWith("x")&&e.length===3?String.fromCodePoint(Number.parseInt(e.slice(1),16)):r&&t?String.fromCodePoint(Number.parseInt(e.slice(2,-1),16)):X.get(e)??e};var Z=/\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|\{(~)?(#?[\w:]+(?:\([^)]*\))?(?:\.#?[\w:]+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n))|(\})|((?:.|[\r\n\f])+?)/gi,G=/(?:^|\.)(?:(\w+)(?:\(([^)]*)\))?|#(?=[:a-f\d]{2,})([a-f\d]{6})?(?::([a-f\d]{6}))?)/gi,q=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,F=/\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi,Y=(e,r)=>{let t=[],s=r.trim().split(/\s*,\s*/),o;for(let i of s){let g=Number(i);if(!Number.isNaN(g))t.push(g);else if(o=q.exec(i))t.push(o[2].replace(F,(c,b,h)=>b?D(b):h));else throw new Error(`Invalid template style argument: ${i} (in style '${e}')`)}return t},U=e=>{G.lastIndex=0;let r=[],t;for(;(t=G.exec(e))!==null;){let s=t[1];t[2]?r.push([s,...Y(s,t[2])]):t[3]||t[4]?(t[3]&&r.push(["rgb",...p(t[3])]),t[4]&&r.push(["bgRgb",...p(t[4])])):r.push([s]);}return r},$=(e,r)=>{let t={};for(let o of r)for(let i of o.styles)t[i[0]]=o.inverse?null:i.slice(1);let s=e;for(let[o,i]of Object.entries(t))if(Array.isArray(i)){if(!(o in s))throw new Error(`Unknown style: ${o}`);s=i.length>0?s[o](...i):s[o];}return s},N=e=>r=>{let t=[],s=[],o=[];if(r.replaceAll(Z,(i,g,c,b,h,I)=>{if(g)o.push(D(g));else if(b){let P=o.join("");o=[],s.push(t.length===0?P:$(e,t)(P)),t.push({inverse:c,styles:U(b)});}else if(h){if(t.length===0)throw new Error("Found extraneous } in template literal");s.push($(e,t)(o.join(""))),o=[],t.pop();}else o.push(I);}),s.push(o.join("")),t.length>0)throw new Error(`template literal is missing ${t.length} closing bracket${t.length===1?"":"s"} (\`}\`)`);return s.join("")};var J=new O,Ae=e=>v(N(e)),K=N(J),ke=v(K); | ||
export { pe as default, ue as makeTaggedTemplate, W as template }; | ||
export { ke as default, Ae as makeTaggedTemplate, K as template }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=template.js.map |
{ | ||
"name": "@visulima/colorize", | ||
"version": "1.3.3", | ||
"version": "1.4.0", | ||
"description": "Terminal and Console string styling done right.", | ||
@@ -119,2 +119,12 @@ "keywords": [ | ||
}, | ||
"./utils": { | ||
"require": { | ||
"types": "./dist/utils.d.cts", | ||
"default": "./dist/utils.cjs" | ||
}, | ||
"import": { | ||
"types": "./dist/utils.d.ts", | ||
"default": "./dist/utils.js" | ||
} | ||
}, | ||
"./package.json": "./package.json" | ||
@@ -233,4 +243,12 @@ }, | ||
"format": "cjs" | ||
}, | ||
{ | ||
"source": "src/utils.ts", | ||
"format": "esm" | ||
}, | ||
{ | ||
"source": "src/utils.ts", | ||
"format": "cjs" | ||
} | ||
] | ||
} |
135
README.md
@@ -36,3 +36,15 @@ <div align="center"> | ||
- Supports both **ESM** and **CommonJS** | ||
- [Standard API](#base-colors) like **chalk** | ||
- **TypeScript** support out of the box | ||
- Supports **Deno**, **Next.JS** runtimes and **Browser** (not only chrome) (currently multi nesting is not supported) | ||
- [Standard API](#base-colors) compatible with **Chalk**, switch from **Chalk** to **Colorize** without changing your code | ||
```diff | ||
- import chalk from 'chalk'; | ||
+ import chalk, { red } from '@visulima/colorize'; | ||
chalk.red.bold('Error!'); // <- Chalk like syntax works fine with Colorize | ||
red.bold('Error!'); // <- the same result with Colorize | ||
red.bold`Error!`; // <- the same result with Colorize | ||
``` | ||
- Default import | ||
@@ -46,3 +58,7 @@ - `import colorize from '@visulima/colorize'` or `const colorize = require('@visulima/colorize')` | ||
- [Nested **template strings**](#nested-syntax) `` red`R ${green`G`} R` `` | ||
- [ANSI 256 colors](#256-colors) and [Truecolor](#truecolor) (**RGB**, **HEX**) `` rgb(224, 17, 95)`Ruby` ``, `` hex('#96C')`Amethyst` `` | ||
- [Base ANSI styles](#base-colors) `dim` **`bold`** _`italic`_ <u>`underline`</u> <s>`strikethrough`</s> | ||
- [Base ANSI 16 colors](#base-colors) `` red`Error!` `` `` redBright`Error!` `` `` bgRed`Error!` `` `` bgRedBright`Error!` `` | ||
- [ANSI 256 colors](#256-colors) and [TrueColor](#truecolor) (**RGB**, **HEX**) `` rgb(224, 17, 95)`Ruby` ``, `` hex('#96C')`Amethyst` `` | ||
- [TrueColor](#truecolor) (**RGB**, **HEX**) `` rgb(224, 17, 95)`Ruby` ``, `` hex('#96C')`Amethyst` `` | ||
- [Fallback](#fallback) to supported [color space](#color-support): TrueColor → 256 colors → 16 colors → no colors | ||
- [ANSI codes](#escape-codes) as `open` and `close` property for each style `` `Hello ${red.open}World${red.close}!` `` | ||
@@ -52,3 +68,2 @@ - [Strip ANSI codes](#strip) method `colorize.strip()` | ||
- Supports the [environment variables](#cli-vars) `NO_COLOR` `FORCE_COLOR` and flags `--no-color` `--color` | ||
- Supports **Deno**, **Next.JS** runtimes and **Browser** (not only chrome) (currently multi nesting is not supported) | ||
- Expressive API | ||
@@ -58,3 +73,2 @@ - Doesn't extend `String.prototype` | ||
- **Auto detects** color support | ||
- **TypeScript** support out of the box | ||
- Clean and focused | ||
@@ -174,27 +188,2 @@ - [String Gradient´s](#gradient) | ||
### API | ||
Colors and styles have standard names used by many popular libraries, such | ||
as [chalk][chalk], [colorette][colorette], [kleur][kleur]. | ||
| Foreground colors | Background colors | Styles | | ||
| :-------------------- | :------------------------ | ----------------------------------------------------------------------- | | ||
| `black` | `bgBlack` | `dim` | | ||
| `red` | `bgRed` | **`bold`** | | ||
| `green` | `bgGreen` | _`italic`_ | | ||
| `yellow` | `bgYellow` | <u>`underline`</u> | | ||
| `blue` | `bgBlue` | <s>`strikethrough`</s> (alias `strike`) | | ||
| `magenta` | `bgMagenta` | <s>`doubleUnderline`</s> (_not included, because not widely supported_) | | ||
| `cyan` | `bgCyan` | <s>`overline`</s> (_not included, because not widely supported_) | | ||
| `white` | `bgWhite` | <s>`frame`</s> (_not included, because not widely supported_) | | ||
| `gray` (alias `grey`) | `bgGray` (alias `bgGrey`) | <s>`encircle`</s> (_not included, because not widely supported_) | | ||
| `blackBright` | `bgBlackBright` | `inverse` | | ||
| `redBright` | `bgRedBright` | `visible` | | ||
| `greenBright` | `bgGreenBright` | `hidden` | | ||
| `yellowBright` | `bgYellowBright` | `reset` | | ||
| `blueBright` | `bgBlueBright` | | | ||
| `magentaBright` | `bgMagentaBright` | | | ||
| `cyanBright` | `bgCyanBright` | | | ||
| `whiteBright` | `bgWhiteBright` | | | ||
### Named import | ||
@@ -354,3 +343,3 @@ | ||
// defined a truecolor as the constant | ||
// defined a TrueColor as the constant | ||
const orange = hex("#FFAB40"); | ||
@@ -376,2 +365,28 @@ | ||
<a id="base-colors" name="base-colors"></a> | ||
## Base ANSI 16 colors and styles | ||
Colors and styles have standard names used by many popular libraries, such | ||
as [chalk][chalk], [colorette][colorette], [kleur][kleur]. | ||
| Foreground colors | Background colors | Styles | | ||
| :-------------------- | :------------------------ | ----------------------------------------------------------------------- | | ||
| `black` | `bgBlack` | `dim` | | ||
| `red` | `bgRed` | **`bold`** | | ||
| `green` | `bgGreen` | _`italic`_ | | ||
| `yellow` | `bgYellow` | <u>`underline`</u> | | ||
| `blue` | `bgBlue` | <s>`strikethrough`</s> (alias `strike`) | | ||
| `magenta` | `bgMagenta` | <s>`doubleUnderline`</s> (_not included, because not widely supported_) | | ||
| `cyan` | `bgCyan` | <s>`overline`</s> (_not included, because not widely supported_) | | ||
| `white` | `bgWhite` | <s>`frame`</s> (_not included, because not widely supported_) | | ||
| `gray` (alias `grey`) | `bgGray` (alias `bgGrey`) | <s>`encircle`</s> (_not included, because not widely supported_) | | ||
| `blackBright` | `bgBlackBright` | `inverse` | | ||
| `redBright` | `bgRedBright` | `visible` | | ||
| `greenBright` | `bgGreenBright` | `hidden` | | ||
| `yellowBright` | `bgYellowBright` | `reset` | | ||
| `blueBright` | `bgBlueBright` | | | ||
| `magentaBright` | `bgMagentaBright` | | | ||
| `cyanBright` | `bgCyanBright` | | | ||
| `whiteBright` | `bgWhiteBright` | | | ||
## ANSI 256 colors | ||
@@ -405,2 +420,8 @@ | ||
### Fallback | ||
If a terminal supports only 16 colors then ANSI 256 colors will be interpolated into base 16 colors. | ||
#### Usage Example | ||
```typescript | ||
@@ -411,2 +432,24 @@ import { bold, ansi256, fg, bgAnsi256, bg } from "@visulima/colorize"; | ||
ansi256(96)`Bright Cyan`; | ||
fg(96)`Bright Cyan`; // alias for ansi256 | ||
// background color | ||
bgAnsi256(105)`Bright Magenta`; | ||
bg(105)`Bright Magenta`; // alias for bgAnsi256 | ||
// function is chainable | ||
ansi256(96).bold`bold Bright Cyan`; | ||
// function is avaliable in each style | ||
bold.ansi256(96).underline`bold underline Bright Cyan`; | ||
// you can combine the functions and styles in any order | ||
bgAnsi256(105).ansi256(96)`cyan text on magenta background`; | ||
bg(105).fg(96)`cyan text on magenta background`; | ||
``` | ||
```typescript | ||
import { bold, ansi256, fg, bgAnsi256, bg } from "@visulima/colorize"; | ||
// foreground color | ||
ansi256(96)`Bright Cyan`; | ||
fg(96)`Bright Cyan`; | ||
@@ -453,2 +496,10 @@ | ||
## Fallback | ||
If a terminal does not support ANSI colors, the library will automatically fall back to the next supported color space. | ||
> TrueColor —> 256 colors —> 16 colors —> no colors (black & white) | ||
If you use the `hex()`, `rgb()` or `ansis256()` functions in a terminal not supported TrueColor or 256 colors, then colors will be interpolated. | ||
<!-- | ||
@@ -530,14 +581,14 @@ Copy of a readme example from https://github.com/webdiscus/ansis | ||
| Library<br>**\*\***\_\_**\*\***<br> - name<br> - named import | Code size | Naming colors | ANSI 256<br>colors | True-<br>color | Chained<br>syntax | Nested<br>template strings | New<br>Line | Supports<br>CLI params | | ||
| :---------------------------------------------------------------- | :----------------------------------------------------------------------------- | :----------------------------------------: | :----------------: | :------------: | :---------------: | :------------------------: | :---------: | :------------------------------------------------------: | | ||
| [`@visulima/colorize`][npm-url]<br><nobr>`✅ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/@visulima/colorize) | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ✅ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | | ||
| [`ansi-colors`][ansi-colors]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/ansi-colors) | **standard**<br>`16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | only<br>`FORCE_COLOR` | | ||
| [`ansis`][ansis]<br><nobr>`✅ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/ansis) | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ✅ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | | ||
| [`chalk`][chalk]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/chalk) | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ❌ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | | ||
| [`cli-color`][cli-color]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/cli-color) | **standard**<br>`16` colors | ✅ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR` | | ||
| [`colorette`][colorette]<br><nobr>`✅ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/colorette) | **standard**<br>`16` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | | ||
| [`colors-cli`][colors-cli]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/colors-cli) | <nobr>_non-standard_</nobr><br>`16` colors | ✅ | ❌ | ✅ | ❌ | ✅ | only<br>`--no-color`<br>`--color` | | ||
| [`colors.js`][colors.js]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/colors.js) | <nobr>_non-standard_</nobr><br>`16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | only<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | | ||
| [`kleur`][kleur]<br><nobr>`✅ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/kleur) | **standard**<br>`8` colors | ❌ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR`<br>`FORCE_COLOR` | | ||
| [`picocolors`][picocolors]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/picocolors) | **standard**<br>`8` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | | ||
| Library<br>**\*\***\_\_**\*\***<br> - name<br> - named import | Code size | Naming colors | ANSI 256<br>colors | True-<br>color | Chained<br>syntax | Nested<br>template strings | New<br>Line | Supports<br>CLI params<br>ENV vars | Fallbacks | | ||
| :---------------------------------------------------------------- | :----------------------------------------------------------------------------- | :----------------------------------------: | :----------------: | :------------: | :---------------: | :------------------------: | :---------: | :------------------------------------------------------: | ---------------------------------- | | ||
| [`@visulima/colorize`][npm-url]<br><nobr>`✅ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/@visulima/colorize) | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ✅ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | 256 color<br>16 colors<br>no color | | ||
| [`ansi-colors`][ansi-colors]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/ansi-colors) | **standard**<br>`16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | only<br>`FORCE_COLOR` | ❌ | | ||
| [`ansis`][ansis]<br><nobr>`✅ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/ansis) | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ✅ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | 256 color<br>16 colors<br>no color | | ||
| [`chalk`][chalk]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/chalk) | **standard**<br>`16` colors | ✅ | ✅ | ✅ | ❌ | ✅ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | 256 color<br>16 colors<br>no color | | ||
| [`cli-color`][cli-color]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/cli-color) | **standard**<br>`16` colors | ✅ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR` | 16 colors<br>no color | | ||
| [`colorette`][colorette]<br><nobr>`✅ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/colorette) | **standard**<br>`16` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | no color | | ||
| [`colors-cli`][colors-cli]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/colors-cli) | <nobr>_non-standard_</nobr><br>`16` colors | ✅ | ❌ | ✅ | ❌ | ✅ | only<br>`--no-color`<br>`--color` | no color | | ||
| [`colors.js`][colors.js]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/colors.js) | <nobr>_non-standard_</nobr><br>`16` colors | ❌ | ❌ | ✅ | ❌ | ✅ | only<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | no color | | ||
| [`kleur`][kleur]<br><nobr>`✅ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/kleur) | **standard**<br>`8` colors | ❌ | ❌ | ✅ | ❌ | ❌ | only<br>`NO_COLOR`<br>`FORCE_COLOR` | no color | | ||
| [`picocolors`][picocolors]<br><nobr>`❌ named import`</nobr> | ![npm bundle size](https://img.shields.io/bundlephobia/min/picocolors) | **standard**<br>`8` colors | ❌ | ❌ | ❌ | ❌ | ❌ | `NO_COLOR`<br>`FORCE_COLOR`<br>`--no-color`<br>`--color` | no color | | ||
@@ -544,0 +595,0 @@ > **Note** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
412265
31
693
746