neo-neo-bblessed
Version:
A fork of neo-blessed (which is a fork of blessed) with bug fixes and maintenance.
3 lines (2 loc) • 4.48 kB
JavaScript
exports.match=function(r,e,n){if(typeof r=="string"){var u=r;if(u[0]!=="#")return-1;const a=exports.hexToRGB(u);r=a[0],e=a[1],n=a[2]}else Array.isArray(r)&&(n=r[2],e=r[1],r=r[0]);var o=r<<16|e<<8|n;if(exports._cache[o]!==null)return exports._cache[o];for(var f=1/0,t=-1,b=0,i,c,l,m,s;b<exports.vcolors.length;b++){if(i=exports.vcolors[b],c=i[0],l=i[1],m=i[2],s=h(r,e,n,c,l,m),s===0){t=b;break}s<f&&(f=s,t=b)}return exports._cache[o]=t,exports._cache[o]},exports.RGBToHex=function(r,e,n){Array.isArray(r)&&(n=r[2],e=r[1],r=r[0]);function u(o){let f=o.toString(16);return f.length<2&&(f="0"+f),f}return"#"+u(r)+u(e)+u(n)},exports.hexToRGB=function(r){r.length===4&&(r=r[0]+r[1]+r[1]+r[2]+r[2]+r[3]+r[3]);var e=parseInt(r.substring(1),16),n=e>>16&255,u=e>>8&255,o=e&255;return[n,u,o]};function h(r,e,n,u,o,f){return Math.pow(30*(r-u),2)+Math.pow(59*(e-o),2)+Math.pow(11*(n-f),2)}exports.mixColors=function(r,e,n){r===511&&(r=0),e===511&&(e=0),n===null&&(n=.5),r=exports.vcolors[r];var u=r[0],o=r[1],f=r[2];e=exports.vcolors[e];var t=e[0],b=e[1],i=e[2];return u+=(t-u)*n|0,o+=(b-o)*n|0,f+=(i-f)*n|0,exports.match([u,o,f])},exports.blend=function r(e,n,u){var o,f,t,b,i=e&511;if(n!==null){var c=n&511;i===511&&(i=0),c===511&&(c=0),i=exports.mixColors(i,c,u)}else if(r._cache[i]!==null)i=r._cache[i];else if(i>=8&&i<=15)i-=8;else if(o=exports.ncolors[i],o){for(f=0;f<exports.ncolors.length;f++)if(o===exports.ncolors[f]&&f!==i&&(t=exports.vcolors[i],b=exports.vcolors[f],b[0]+b[1]+b[2]<t[0]+t[1]+t[2])){r._cache[i]=f,i=f;break}}e&=-512,e|=i;var l=e>>9&511;if(n!==null){var m=n>>9&511;l===511?l=248:(l===511&&(l=7),m===511&&(m=7),l=exports.mixColors(l,m,u))}else if(r._cache[l]!==null)l=r._cache[l];else if(l>=8&&l<=15)l-=8;else if(o=exports.ncolors[l],o){for(f=0;f<exports.ncolors.length;f++)if(o===exports.ncolors[f]&&f!==l&&(t=exports.vcolors[l],b=exports.vcolors[f],b[0]+b[1]+b[2]<t[0]+t[1]+t[2])){r._cache[l]=f,l=f;break}}return e&=-261633,e|=l<<9,e},exports.blend._cache={},exports._cache={},exports.reduce=function(r,e){return r>=16&&e<=16?r=exports.ccolors[r]:r>=8&&e<=8?r-=8:r>=2&&e<=2&&(r%=2),r},exports.xterm=["#000000","#cd0000","#00cd00","#cdcd00","#0000ee","#cd00cd","#00cdcd","#e5e5e5","#7f7f7f","#ff0000","#00ff00","#ffff00","#5c5cff","#ff00ff","#00ffff","#ffffff"],exports.colors=function(){var r=exports.colors=[],e=exports.vcolors=[],n,u,o,f,t;function b(c){let l=c.toString(16);return l.length<2&&(l="0"+l),l}function i(c,l,m,s){r[c]="#"+b(l)+b(m)+b(s),e[c]=[l,m,s]}for(exports.xterm.forEach(function(c,l){c=parseInt(c.substring(1),16),i(l,c>>16&255,c>>8&255,c&255)}),n=0;n<6;n++)for(u=0;u<6;u++)for(o=0;o<6;o++)f=16+n*36+u*6+o,i(f,n?n*40+55:0,u?u*40+55:0,o?o*40+55:0);for(u=0;u<24;u++)t=u*10+8,f=232+u,i(f,t,t,t);return r}();var g=exports.colorNames={default:-1,normal:-1,bg:-1,fg:-1,black:0,red:1,green:2,yellow:3,blue:4,magenta:5,cyan:6,white:7,lightblack:8,lightred:9,lightgreen:10,lightyellow:11,lightblue:12,lightmagenta:13,lightcyan:14,lightwhite:15,brightblack:8,brightred:9,brightgreen:10,brightyellow:11,brightblue:12,brightmagenta:13,brightcyan:14,brightwhite:15,grey:8,gray:8,lightgrey:7,lightgray:7,brightgrey:7,brightgray:7};exports.convert=function(r){let e;if(typeof r=="number")e=r;else if(typeof r=="string"){let n=r.replace(/[\- ]/g,"");g[n]!==null?e=g[n]:e=exports.match(r)}else Array.isArray(r)?e=exports.match(r):e=-1;return e!==-1?e:511},exports.ccolors={blue:[4,12,[17,21],[24,27],[31,33],[38,39],45,[54,57],[60,63],[67,69],[74,75],81,[91,93],[97,99],[103,105],[110,111],117,[128,129],[134,135],[140,141],[146,147],153,165,171,177,183,189],green:[2,10,22,[28,29],[34,36],[40,43],[46,50],[64,65],[70,72],[76,79],[82,86],[106,108],[112,115],[118,122],[148,151],[154,158],[190,194]],cyan:[6,14,23,30,37,44,51,66,73,80,87,109,116,123,152,159,195],red:[1,9,52,[88,89],[94,95],[124,126],[130,132],[136,138],[160,163],[166,169],[172,175],[178,181],[196,200],[202,206],[208,212],[214,218],[220,224]],magenta:[5,13,53,90,96,127,133,139,164,170,176,182,201,207,213,219,225],yellow:[3,11,58,[100,101],[142,144],[184,187],[226,230]],black:[0,8,16,59,102,[232,243]],white:[7,15,145,188,231,[244,255]]},exports.ncolors=[],Object.keys(exports.ccolors).forEach(function(r){exports.ccolors[r].forEach(function(e){if(typeof e=="number"){exports.ncolors[e]=r,exports.ccolors[e]=exports.colorNames[r];return}for(var n=e[0],u=e[1];n<=u;n++)exports.ncolors[n]=r,exports.ccolors[n]=exports.colorNames[r]}),delete exports.ccolors[r]});
//# sourceMappingURL=colors.js.map