Socket
Socket
Sign inDemoInstall

culori

Package Overview
Dependencies
Maintainers
1
Versions
256
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

culori - npm Package Compare versions

Comparing version 0.2.32 to 0.2.33

37

build/culori.js

@@ -7,2 +7,6 @@ (function (global, factory) {

var normalizeHue = (function (hue) {
return (hue = hue % 360) < 0 ? hue + 360 : hue;
});
// Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB

@@ -16,3 +20,3 @@

h = (h < 0 ? h + 360 : h) % 360;
h = normalizeHue(h);
var f = Math.abs(h / 60 % 2 - 1);

@@ -78,3 +82,3 @@ var res = void 0;

h = (h < 0 ? h + 360 : h) % 360;
h = normalizeHue(h);
var m1 = l + s * (l < 0.5 ? l : 1 - l);

@@ -110,4 +114,3 @@ var m2 = m1 - (m1 - l) * 2 * Math.abs(h / 60 % 2 - 1);

h = h % 360;
if (h < 0) h += 360;
h = normalizeHue(h);
var f = Math.abs(h / 60 % 2 - 1);

@@ -262,5 +265,4 @@ var res = void 0;

c: Math.sqrt(a * a + b * b),
h: Math.atan2(b, a) * 180 / Math.PI
h: normalizeHue(Math.atan2(b, a) * 180 / Math.PI)
};
if (res.h < 0) res.h += 360;
if (alpha !== undefined) res.alpha = alpha;

@@ -999,16 +1001,21 @@ return res;

var normalizeHue = (function (hue) {
return (hue = hue % 360) < 0 ? hue + 360 : hue;
});
var linear = function linear(a, b, t) {
return a + t * (b - a);
};
var generic = function generic(a, b, t) {
if (a !== undefined && b !== undefined) return linear(a, b, t);
return a === undefined ? b : a;
};
var hue$2 = function hue(a, b, t) {
a = normalizeHue(a);b = normalizeHue(b);
return Math.abs(b - a) > 180 ? normalizeHue(linear(a, b - 360 * Math.sign(b - a), t)) : linear(a, b, t);
if (a !== undefined && b !== undefined) {
a = normalizeHue(a);b = normalizeHue(b);
return Math.abs(b - a) > 180 ? normalizeHue(linear(a, b - 360 * Math.sign(b - a), t)) : linear(a, b, t);
}
return a === undefined ? b : a;
};
var interpolator = function interpolator(key) {
return key === 'h' ? hue$2 : linear;
var alpha$1 = function alpha(a, b, t) {
if (a === undefined && b === undefined) return undefined;
return linear(a === undefined ? 1 : a, b === undefined ? 1 : b, t);
};

@@ -1048,3 +1055,3 @@

return map({ mode: mode }, function (key) {
return interpolator(key)(startColor[key], endColor[key], t0);
return (key === 'h' ? hue$2 : key === 'alpha' ? alpha$1 : generic)(startColor[key], endColor[key], t0);
});

@@ -1051,0 +1058,0 @@ };

@@ -1,1 +0,1 @@

!function(e,a){"object"==typeof exports&&"undefined"!=typeof module?module.exports=a():"function"==typeof define&&define.amd?define(a):e.culori=a()}(this,function(){"use strict";function e(e){var a=e.h,r=e.s,n=e.v,t=e.alpha;(a%=360)<0&&(a+=360);var o=Math.abs(a/60%2-1),i=void 0;switch(Math.floor(a/60)){case 0:i={r:n,g:n*(1-r*o),b:n*(1-r)};break;case 1:i={r:n*(1-r*o),g:n,b:n*(1-r)};break;case 2:i={r:n*(1-r),g:n,b:n*(1-r*o)};break;case 3:i={r:n*(1-r),g:n*(1-r*o),b:n};break;case 4:i={r:n*(1-r*o),g:n*(1-r),b:n};break;case 5:i={r:n,g:n*(1-r),b:n*(1-r*o)}}return i.mode="rgb",void 0!==t&&(i.alpha=t),i}function a(e){var a=e.r,r=e.g,n=e.b,t=e.alpha,o=Math.max(a,r,n),i=Math.min(a,r,n),h={mode:"hsv",s:0===o?0:1-i/o,v:o};return o-i!=0&&(h.h=60*(o===a?(r-n)/(o-i)+6*(r<n):o===r?(n-a)/(o-i)+2:(a-r)/(o-i)+4)),void 0!==t&&(h.alpha=t),h}var r=function(e){var a=e.l,r=e.a,n=e.b,t=e.alpha,o={mode:"lch",l:a,c:Math.sqrt(r*r+n*n),h:180*Math.atan2(n,r)/Math.PI};return o.h<0&&(o.h+=360),void 0!==t&&(o.alpha=t),o},n=function(e){var a=e.l,r=e.c,n=e.h,t=e.alpha,o={mode:"lab",l:a,a:r*Math.cos(n/180*Math.PI),b:r*Math.sin(n/180*Math.PI)};return void 0!==t&&(o.alpha=t),o},t=Math.pow(29,3)/Math.pow(3,3),o=Math.pow(6,3)/Math.pow(29,3),i=function(e){return e>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e},h=function(e){var a,r,n,h,l=function(e){var a=e.x,r=e.y,n=e.z;return{r:i(3.1338561*a-1.6168667*r-.4906146*n),g:i(-.9787684*a+1.9161415*r+.033454*n),b:i(.0719453*a-.2289914*r+1.4052427*n)}}((r=(a=e).l,n=a.a/500+(r+16)/116,h=(r+16)/116-a.b/200,{x:.9642*(Math.pow(n,3)>o?Math.pow(n,3):(116*n-16)/t),y:1*(r>8?Math.pow((r+16)/116,3):r/t),z:.82521*(Math.pow(h,3)>o?Math.pow(h,3):(116*h-16)/t)}));return l.mode="rgb",void 0!==e.alpha&&(l.alpha=e.alpha),l},l=function(e){return e<.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)},s=Math.pow(29,3)/Math.pow(3,3),u=Math.pow(6,3)/Math.pow(29,3),d=function(e){return e>u?Math.cbrt(e):(s*e+16)/116},b=function(e){var a,r,n,t,o=function(e){var a=e.x,r=e.y,n=e.z,t=d(a/.9642),o=d(r/1);return{l:116*o-16,a:500*(t-o),b:200*(o-d(n/.82521))}}((r=(a=e).r,n=a.g,t=a.b,{x:.4360747*(r=l(r))+.3850649*(n=l(n))+.1430804*(t=l(t)),y:.2225045*r+.7168786*n+.0606169*t,z:.0139322*r+.0971045*n+.7141733*t}));return o.mode="lab",void 0!==e.alpha&&(o.alpha=e.alpha),o},c={hsi:{rgb:function(e){var a=e.h,r=e.s,n=e.i,t=e.alpha;a=(a<0?a+360:a)%360;var o=Math.abs(a/60%2-1),i=void 0;switch(Math.floor(a/60)){case 0:i={r:n*(1+r*(3/(2-o)-1)),g:n*(1+r*(3*(1-o)/(2-o)-1)),b:n*(1-r)};break;case 1:i={r:n*(1+r*(3*(1-o)/(2-o)-1)),g:n*(1+r*(3/(2-o)-1)),b:n*(1-r)};break;case 2:i={r:n*(1-r),g:n*(1+r*(3/(2-o)-1)),b:n*(1+r*(3*(1-o)/(2-o)-1))};break;case 3:i={r:n*(1-r),g:n*(1+r*(3*(1-o)/(2-o)-1)),b:n*(1+r*(3/(2-o)-1))};break;case 4:i={r:n*(1+r*(3*(1-o)/(2-o)-1)),g:n*(1-r),b:n*(1+r*(3/(2-o)-1))};break;case 5:i={r:n*(1+r*(3/(2-o)-1)),g:n*(1-r),b:n*(1+r*(3*(1-o)/(2-o)-1))}}return i.mode="rgb",void 0!==t&&(i.alpha=t),i}},hsl:{rgb:function(e){var a=e.h,r=e.s,n=e.l,t=e.alpha;a=(a<0?a+360:a)%360;var o=n+r*(n<.5?n:1-n),i=o-2*(o-n)*Math.abs(a/60%2-1),h=void 0;switch(Math.floor(a/60)){case 0:h={r:o,g:i,b:2*n-o};break;case 1:h={r:i,g:o,b:2*n-o};break;case 2:h={r:2*n-o,g:o,b:i};break;case 3:h={r:2*n-o,g:i,b:o};break;case 4:h={r:i,g:2*n-o,b:o};break;case 5:h={r:o,g:2*n-o,b:i}}return h.mode="rgb",void 0!==t&&(h.alpha=t),h}},hsv:{rgb:e},hwb:{rgb:function(a){var r=a.h,n=a.w,t=a.b,o=a.alpha;if(n+t>1){var i=n+t;n/=i,t/=i}return e({h:r,s:1===t?1:1-n/(1-t),v:1-t,alpha:o})}},lab:{lch:r,rgb:h},lch:{lab:n,rgb:function(e){return h(n(e))}},rgb:{hsi:function(e){var a=e.r,r=e.g,n=e.b,t=e.alpha,o=Math.max(a,r,n),i=Math.min(a,r,n),h={mode:"hsi",s:a+r+n===0?0:1-3*i/(a+r+n),i:(a+r+n)/3};return o-i!=0&&(h.h=60*(o===a?(r-n)/(o-i)+6*(r<n):o===r?(n-a)/(o-i)+2:(a-r)/(o-i)+4)),void 0!==t&&(h.alpha=t),h},hsl:function(e){var a=e.r,r=e.g,n=e.b,t=e.alpha,o=Math.max(a,r,n),i=Math.min(a,r,n),h={mode:"hsl",s:o===i?0:(o-i)/(1-Math.abs(o+i-1)),l:.5*(o+i)};return o-i!=0&&(h.h=60*(o===a?(r-n)/(o-i)+6*(r<n):o===r?(n-a)/(o-i)+2:(a-r)/(o-i)+4)),void 0!==t&&(h.alpha=t),h},hsv:a,hwb:function(e){var r=a(e);if(void 0!==r){var n={mode:"hwb",w:(1-r.s)*r.v,b:1-r.v};return void 0!==r.h&&(n.h=r.h),void 0!==r.alpha&&(n.alpha=r.alpha),n}},lab:b,lch:function(e){return r(b(e))}}},g=function(e,a){return void 0!==e?e.mode===a?e:c[e.mode][a]?c[e.mode][a](e):"rgb"===mode?c[e.mode].rgb(e):c.rgb[a](c[e.mode].rgb(e)):void 0},p=function(e,a){if("number"==typeof e)return 3===a?{mode:"rgb",r:(e>>8&15|e>>4&240)/255,g:(e>>4&15|240&e)/255,b:(15&e|e<<4&240)/255}:4===a?{mode:"rgb",r:(e>>12&15|e>>8&240)/255,g:(e>>8&15|e>>4&240)/255,b:(e>>4&15|240&e)/255,alpha:(15&e|e<<4&240)/255}:6===a?{mode:"rgb",r:(e>>16&255)/255,g:(e>>8&255)/255,b:(255&e)/255}:8===a?{mode:"rgb",r:(e>>24&255)/255,g:(e>>16&255)/255,b:(e>>8&255)/255,alpha:(255&e)/255}:void 0},f={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},v=function(e){return"string"==typeof e&&p(f[e.toLowerCase()],6)||void 0},m=(/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/+"").replace(/^\/|\/$/g,""),w=m+"%",y="(?:"+m+"%|"+m+")",M="(?:"+m+"(deg|grad|rad|turn)|"+m+")",k="\\s*,\\s*",x="\\s+",$=new RegExp("^rgba?\\(\\s*"+m+k+m+k+m+"\\s*(?:,\\s*"+y+"\\s*)?\\)$"),E=new RegExp("^rgba?\\(\\s*"+w+k+w+k+w+"\\s*(?:,\\s*"+y+"\\s*)?\\)$"),R=new RegExp("^rgba?\\(\\s*"+m+x+m+x+m+"\\s*(?:\\/\\s*"+y+"\\s*)?\\)$"),j=new RegExp("^rgba?\\(\\s*"+w+x+w+x+w+"\\s*(?:\\/\\s*"+y+"\\s*)?\\)$"),q=new RegExp("^hsla?\\(\\s*"+M+k+w+k+w+"\\s*(?:,\\s*"+y+"\\s*)?\\)$"),O=new RegExp("^hsla?\\(\\s*"+M+x+w+x+w+"\\s*(?:\\/\\s*"+y+"\\s*)?\\)$"),z=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,S=new RegExp("^hwb\\(\\s*"+M+x+w+x+w+"\\s*(?:\\/\\s*"+y+"\\s*)?\\)$"),I=new RegExp("^lab\\(\\s*"+m+x+m+x+m+"\\s*(?:\\/\\s*"+y+"\\s*)?\\)$"),P=new RegExp("^lch\\(\\s*"+m+x+m+x+M+"\\s*(?:\\/\\s*"+y+"\\s*)?\\)$"),H=new RegExp("^gray\\(\\s*"+m+"()()\\s*(?:\\/\\s*"+y+"\\s*)?\\)$"),N=function(e){var a;return(a=e.match(z))?p(parseInt(a[1],16),a[1].length):void 0},C=function(e){var a=void 0,r=void 0;if(a=e.match($)||e.match(R))r={mode:"rgb",r:a[1]/255,g:a[2]/255,b:a[3]/255};else{if(!(a=e.match(E)||e.match(j)))return;r={mode:"rgb",r:a[1]/100,g:a[2]/100,b:a[3]/100}}return void 0!==a[4]?r.alpha=a[4]/100:void 0!==a[5]&&(r.alpha=+a[5]),r},L=function(e,a){switch(a){case"deg":return+e;case"rad":return e/Math.PI*180;case"grad":return e/10*9;case"turn":return 360*e}},A=function(e){if("string"==typeof e){var a=e.match(q)||e.match(O);if(a){var r={mode:"hsl",h:void 0===a[3]?L(a[1],a[2]):+a[3],s:Math.min(Math.max(0,a[4]/100),1),l:Math.min(Math.max(0,a[5]/100),1)};return void 0!==a[6]?r.alpha=a[6]/100:void 0!==a[7]&&(r.alpha=a[7]/255),r}}},B=function(e){if("string"==typeof e){var a=e.match(S);if(a){var r={mode:"hwb",h:void 0===a[3]?L(a[1],a[2]):+a[3],w:a[4]/100,b:a[5]/100};if(r.w+r.b>1){var n=r.w+r.b;r.w/=n,r.b/=n}return void 0!==a[6]?r.alpha=a[6]/100:void 0!==a[7]&&(r.alpha=a[7]/255),r}}},D=function(e){return N(e)||C(e)||A(e)||v(e)||("transparent"===e?p(0,8):void 0)||B(e)||function(e){var a=void 0,r=void 0;if(a=e.match(I))r={mode:"lab",l:+a[1],a:+a[2],b:+a[3]};else{if(!(a=e.match(H)))return;r={mode:"lab",l:+a[1],a:0,b:0}}return void 0!==a[4]?r.alpha=a[4]/100:void 0!==a[5]&&(r.alpha=+a[5]),r}(e)||function(e){var a=e.match(P);if(a){var r={mode:"lch",l:+a[1],c:Math.max(0,+a[2]),h:void 0===a[5]?L(a[3],a[4]):+a[5]};return void 0!==a[6]?r.alpha=a[6]/100:void 0!==a[7]&&(r.alpha=+a[7]),r}}(e)},F="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},G=Object.assign||function(e){for(var a=1;a<arguments.length;a++){var r=arguments[a];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},J=function(e,a){return"object"!==(void 0===e?"undefined":F(e))?D(e):void 0===e.mode?G({},e,{mode:a}):e},K=function(e){return g(J(e,"rgb"),"rgb")},Q=function(e,a){return Math.round(e*(a=Math.pow(10,a)))/a};function T(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(void 0!==e)return"number"==typeof e?Q(e,a):"string"==typeof e?e:"object"===(void 0===e?"undefined":F(e))?Object.keys(e).reduce(function(a,r){return a[r]=T(e[r]),a},{}):void 0}var U=function(e){return Math.round(255*Math.max(0,Math.min(e,1)))},V={rgb:["r","g","b","alpha"],hsl:["h","s","l","alpha"],hsv:["h","s","v","alpha"],hsi:["h","s","i","alpha"],lab:["l","a","b","alpha"],lch:["l","c","h","alpha"],hwb:["h","w","b","alpha"]},W=function(e,a){var r=V[e.mode].reduce(function(r,n){var t=a(n,e[n]);return void 0!==t&&(r[n]=t),r},{});return r.mode=e.mode,r},X=function(e){return(e%=360)<0?e+360:e},Y=function(e,a,r){return e+r*(a-e)},Z=function(e,a,r){return e=X(e),a=X(a),Math.abs(a-e)>180?X(Y(e,a-360*Math.sign(a-e),r)):Y(e,a,r)},_=function(e){return K(e)},ee=Object.freeze({hsl:function(e){return g(J(e,"hsl"),"hsl")},hsv:function(e){return g(J(e,"hsv"),"hsv")},hsi:function(e){return g(J(e,"hsi"),"hsi")},hwb:function(e){return g(J(e,"hwb"),"hwb")},rgb:K,lab:function(e){return g(J(e,"lab"),"lab")},lch:function(e){return g(J(e,"lch"),"lch")},css:function(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb",r=K(e),n=U(r.r),t=U(r.g),o=U(r.b);return"hex"===a?"#"+(1<<24|n<<16|t<<8|o).toString(16).slice(1):"rgb"===a?void 0===r.alpha||1===r.alpha?"rgb("+n+", "+t+", "+o+")":"rgba("+n+", "+t+", "+o+", "+T(r.alpha,2)+")":void 0},convert:g,prepare:J,round:T,parse:D,parseNumber:p,parseNamed:v,parseHex:N,parseRgb:C,parseHsl:A,parseHwb:B,named:f,map:W,interpolate:function(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb";if(!(e.length<2)){var r=e.map(function(e){return g(J(e,a),a)});return function(e){if(1===(e=Math.min(Math.max(0,e),1)))return Object.assign({},r[r.length-1]);var n=e*(r.length-1),t=Math.floor(n),o=r[t],i=r[t+1],h=n-t;return W({mode:a},function(e){return function(e){return"h"===e?Z:Y}(e)(o[e],i[e],h)})}}},swatches:function(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;if(a<2)return a<1?[e(0),e(1)]:[e(.5)];for(var r=[],n=0;n<a;n++)r.push(e(n/(a-1)));return r},default:_});return Object.assign(_,ee),_});
!function(e,a){"object"==typeof exports&&"undefined"!=typeof module?module.exports=a():"function"==typeof define&&define.amd?define(a):e.culori=a()}(this,function(){"use strict";var e=function(e){return(e%=360)<0?e+360:e};function a(a){var r=a.h,n=a.s,t=a.v,o=a.alpha;r=e(r);var i=Math.abs(r/60%2-1),l=void 0;switch(Math.floor(r/60)){case 0:l={r:t,g:t*(1-n*i),b:t*(1-n)};break;case 1:l={r:t*(1-n*i),g:t,b:t*(1-n)};break;case 2:l={r:t*(1-n),g:t,b:t*(1-n*i)};break;case 3:l={r:t*(1-n),g:t*(1-n*i),b:t};break;case 4:l={r:t*(1-n*i),g:t*(1-n),b:t};break;case 5:l={r:t,g:t*(1-n),b:t*(1-n*i)}}return l.mode="rgb",void 0!==o&&(l.alpha=o),l}function r(e){var a=e.r,r=e.g,n=e.b,t=e.alpha,o=Math.max(a,r,n),i=Math.min(a,r,n),l={mode:"hsv",s:0===o?0:1-i/o,v:o};return o-i!=0&&(l.h=60*(o===a?(r-n)/(o-i)+6*(r<n):o===r?(n-a)/(o-i)+2:(a-r)/(o-i)+4)),void 0!==t&&(l.alpha=t),l}var n=function(a){var r=a.l,n=a.a,t=a.b,o=a.alpha,i={mode:"lch",l:r,c:Math.sqrt(n*n+t*t),h:e(180*Math.atan2(t,n)/Math.PI)};return void 0!==o&&(i.alpha=o),i},t=function(e){var a=e.l,r=e.c,n=e.h,t=e.alpha,o={mode:"lab",l:a,a:r*Math.cos(n/180*Math.PI),b:r*Math.sin(n/180*Math.PI)};return void 0!==t&&(o.alpha=t),o},o=Math.pow(29,3)/Math.pow(3,3),i=Math.pow(6,3)/Math.pow(29,3),l=function(e){return e>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e},h=function(e){var a,r,n,t,h=function(e){var a=e.x,r=e.y,n=e.z;return{r:l(3.1338561*a-1.6168667*r-.4906146*n),g:l(-.9787684*a+1.9161415*r+.033454*n),b:l(.0719453*a-.2289914*r+1.4052427*n)}}((r=(a=e).l,n=a.a/500+(r+16)/116,t=(r+16)/116-a.b/200,{x:.9642*(Math.pow(n,3)>i?Math.pow(n,3):(116*n-16)/o),y:1*(r>8?Math.pow((r+16)/116,3):r/o),z:.82521*(Math.pow(t,3)>i?Math.pow(t,3):(116*t-16)/o)}));return h.mode="rgb",void 0!==e.alpha&&(h.alpha=e.alpha),h},u=function(e){return e<.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)},s=Math.pow(29,3)/Math.pow(3,3),d=Math.pow(6,3)/Math.pow(29,3),b=function(e){return e>d?Math.cbrt(e):(s*e+16)/116},c=function(e){var a,r,n,t,o=function(e){var a=e.x,r=e.y,n=e.z,t=b(a/.9642),o=b(r/1);return{l:116*o-16,a:500*(t-o),b:200*(o-b(n/.82521))}}((r=(a=e).r,n=a.g,t=a.b,{x:.4360747*(r=u(r))+.3850649*(n=u(n))+.1430804*(t=u(t)),y:.2225045*r+.7168786*n+.0606169*t,z:.0139322*r+.0971045*n+.7141733*t}));return o.mode="lab",void 0!==e.alpha&&(o.alpha=e.alpha),o},g={hsi:{rgb:function(a){var r=a.h,n=a.s,t=a.i,o=a.alpha;r=e(r);var i=Math.abs(r/60%2-1),l=void 0;switch(Math.floor(r/60)){case 0:l={r:t*(1+n*(3/(2-i)-1)),g:t*(1+n*(3*(1-i)/(2-i)-1)),b:t*(1-n)};break;case 1:l={r:t*(1+n*(3*(1-i)/(2-i)-1)),g:t*(1+n*(3/(2-i)-1)),b:t*(1-n)};break;case 2:l={r:t*(1-n),g:t*(1+n*(3/(2-i)-1)),b:t*(1+n*(3*(1-i)/(2-i)-1))};break;case 3:l={r:t*(1-n),g:t*(1+n*(3*(1-i)/(2-i)-1)),b:t*(1+n*(3/(2-i)-1))};break;case 4:l={r:t*(1+n*(3*(1-i)/(2-i)-1)),g:t*(1-n),b:t*(1+n*(3/(2-i)-1))};break;case 5:l={r:t*(1+n*(3/(2-i)-1)),g:t*(1-n),b:t*(1+n*(3*(1-i)/(2-i)-1))}}return l.mode="rgb",void 0!==o&&(l.alpha=o),l}},hsl:{rgb:function(a){var r=a.h,n=a.s,t=a.l,o=a.alpha;r=e(r);var i=t+n*(t<.5?t:1-t),l=i-2*(i-t)*Math.abs(r/60%2-1),h=void 0;switch(Math.floor(r/60)){case 0:h={r:i,g:l,b:2*t-i};break;case 1:h={r:l,g:i,b:2*t-i};break;case 2:h={r:2*t-i,g:i,b:l};break;case 3:h={r:2*t-i,g:l,b:i};break;case 4:h={r:l,g:2*t-i,b:i};break;case 5:h={r:i,g:2*t-i,b:l}}return h.mode="rgb",void 0!==o&&(h.alpha=o),h}},hsv:{rgb:a},hwb:{rgb:function(e){var r=e.h,n=e.w,t=e.b,o=e.alpha;if(n+t>1){var i=n+t;n/=i,t/=i}return a({h:r,s:1===t?1:1-n/(1-t),v:1-t,alpha:o})}},lab:{lch:n,rgb:h},lch:{lab:t,rgb:function(e){return h(t(e))}},rgb:{hsi:function(e){var a=e.r,r=e.g,n=e.b,t=e.alpha,o=Math.max(a,r,n),i=Math.min(a,r,n),l={mode:"hsi",s:a+r+n===0?0:1-3*i/(a+r+n),i:(a+r+n)/3};return o-i!=0&&(l.h=60*(o===a?(r-n)/(o-i)+6*(r<n):o===r?(n-a)/(o-i)+2:(a-r)/(o-i)+4)),void 0!==t&&(l.alpha=t),l},hsl:function(e){var a=e.r,r=e.g,n=e.b,t=e.alpha,o=Math.max(a,r,n),i=Math.min(a,r,n),l={mode:"hsl",s:o===i?0:(o-i)/(1-Math.abs(o+i-1)),l:.5*(o+i)};return o-i!=0&&(l.h=60*(o===a?(r-n)/(o-i)+6*(r<n):o===r?(n-a)/(o-i)+2:(a-r)/(o-i)+4)),void 0!==t&&(l.alpha=t),l},hsv:r,hwb:function(e){var a=r(e);if(void 0!==a){var n={mode:"hwb",w:(1-a.s)*a.v,b:1-a.v};return void 0!==a.h&&(n.h=a.h),void 0!==a.alpha&&(n.alpha=a.alpha),n}},lab:c,lch:function(e){return n(c(e))}}},p=function(e,a){return void 0!==e?e.mode===a?e:g[e.mode][a]?g[e.mode][a](e):"rgb"===mode?g[e.mode].rgb(e):g.rgb[a](g[e.mode].rgb(e)):void 0},v=function(e,a){if("number"==typeof e)return 3===a?{mode:"rgb",r:(e>>8&15|e>>4&240)/255,g:(e>>4&15|240&e)/255,b:(15&e|e<<4&240)/255}:4===a?{mode:"rgb",r:(e>>12&15|e>>8&240)/255,g:(e>>8&15|e>>4&240)/255,b:(e>>4&15|240&e)/255,alpha:(15&e|e<<4&240)/255}:6===a?{mode:"rgb",r:(e>>16&255)/255,g:(e>>8&255)/255,b:(255&e)/255}:8===a?{mode:"rgb",r:(e>>24&255)/255,g:(e>>16&255)/255,b:(e>>8&255)/255,alpha:(255&e)/255}:void 0},f={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},m=function(e){return"string"==typeof e&&v(f[e.toLowerCase()],6)||void 0},w=(/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/+"").replace(/^\/|\/$/g,""),y=w+"%",M="(?:"+w+"%|"+w+")",k="(?:"+w+"(deg|grad|rad|turn)|"+w+")",x="\\s*,\\s*",$="\\s+",E=new RegExp("^rgba?\\(\\s*"+w+x+w+x+w+"\\s*(?:,\\s*"+M+"\\s*)?\\)$"),R=new RegExp("^rgba?\\(\\s*"+y+x+y+x+y+"\\s*(?:,\\s*"+M+"\\s*)?\\)$"),j=new RegExp("^rgba?\\(\\s*"+w+$+w+$+w+"\\s*(?:\\/\\s*"+M+"\\s*)?\\)$"),q=new RegExp("^rgba?\\(\\s*"+y+$+y+$+y+"\\s*(?:\\/\\s*"+M+"\\s*)?\\)$"),O=new RegExp("^hsla?\\(\\s*"+k+x+y+x+y+"\\s*(?:,\\s*"+M+"\\s*)?\\)$"),z=new RegExp("^hsla?\\(\\s*"+k+$+y+$+y+"\\s*(?:\\/\\s*"+M+"\\s*)?\\)$"),S=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,I=new RegExp("^hwb\\(\\s*"+k+$+y+$+y+"\\s*(?:\\/\\s*"+M+"\\s*)?\\)$"),P=new RegExp("^lab\\(\\s*"+w+$+w+$+w+"\\s*(?:\\/\\s*"+M+"\\s*)?\\)$"),H=new RegExp("^lch\\(\\s*"+w+$+w+$+k+"\\s*(?:\\/\\s*"+M+"\\s*)?\\)$"),N=new RegExp("^gray\\(\\s*"+w+"()()\\s*(?:\\/\\s*"+M+"\\s*)?\\)$"),C=function(e){var a;return(a=e.match(S))?v(parseInt(a[1],16),a[1].length):void 0},L=function(e){var a=void 0,r=void 0;if(a=e.match(E)||e.match(j))r={mode:"rgb",r:a[1]/255,g:a[2]/255,b:a[3]/255};else{if(!(a=e.match(R)||e.match(q)))return;r={mode:"rgb",r:a[1]/100,g:a[2]/100,b:a[3]/100}}return void 0!==a[4]?r.alpha=a[4]/100:void 0!==a[5]&&(r.alpha=+a[5]),r},A=function(e,a){switch(a){case"deg":return+e;case"rad":return e/Math.PI*180;case"grad":return e/10*9;case"turn":return 360*e}},B=function(e){if("string"==typeof e){var a=e.match(O)||e.match(z);if(a){var r={mode:"hsl",h:void 0===a[3]?A(a[1],a[2]):+a[3],s:Math.min(Math.max(0,a[4]/100),1),l:Math.min(Math.max(0,a[5]/100),1)};return void 0!==a[6]?r.alpha=a[6]/100:void 0!==a[7]&&(r.alpha=a[7]/255),r}}},D=function(e){if("string"==typeof e){var a=e.match(I);if(a){var r={mode:"hwb",h:void 0===a[3]?A(a[1],a[2]):+a[3],w:a[4]/100,b:a[5]/100};if(r.w+r.b>1){var n=r.w+r.b;r.w/=n,r.b/=n}return void 0!==a[6]?r.alpha=a[6]/100:void 0!==a[7]&&(r.alpha=a[7]/255),r}}},F=function(e){return C(e)||L(e)||B(e)||m(e)||("transparent"===e?v(0,8):void 0)||D(e)||function(e){var a=void 0,r=void 0;if(a=e.match(P))r={mode:"lab",l:+a[1],a:+a[2],b:+a[3]};else{if(!(a=e.match(N)))return;r={mode:"lab",l:+a[1],a:0,b:0}}return void 0!==a[4]?r.alpha=a[4]/100:void 0!==a[5]&&(r.alpha=+a[5]),r}(e)||function(e){var a=e.match(H);if(a){var r={mode:"lch",l:+a[1],c:Math.max(0,+a[2]),h:void 0===a[5]?A(a[3],a[4]):+a[5]};return void 0!==a[6]?r.alpha=a[6]/100:void 0!==a[7]&&(r.alpha=+a[7]),r}}(e)},G="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},J=Object.assign||function(e){for(var a=1;a<arguments.length;a++){var r=arguments[a];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},K=function(e,a){return"object"!==(void 0===e?"undefined":G(e))?F(e):void 0===e.mode?J({},e,{mode:a}):e},Q=function(e){return p(K(e,"rgb"),"rgb")},T=function(e,a){return Math.round(e*(a=Math.pow(10,a)))/a};function U(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(void 0!==e)return"number"==typeof e?T(e,a):"string"==typeof e?e:"object"===(void 0===e?"undefined":G(e))?Object.keys(e).reduce(function(a,r){return a[r]=U(e[r]),a},{}):void 0}var V=function(e){return Math.round(255*Math.max(0,Math.min(e,1)))},W={rgb:["r","g","b","alpha"],hsl:["h","s","l","alpha"],hsv:["h","s","v","alpha"],hsi:["h","s","i","alpha"],lab:["l","a","b","alpha"],lch:["l","c","h","alpha"],hwb:["h","w","b","alpha"]},X=function(e,a){var r=W[e.mode].reduce(function(r,n){var t=a(n,e[n]);return void 0!==t&&(r[n]=t),r},{});return r.mode=e.mode,r},Y=function(e,a,r){return e+r*(a-e)},Z=function(e){return Q(e)},_=Object.freeze({hsl:function(e){return p(K(e,"hsl"),"hsl")},hsv:function(e){return p(K(e,"hsv"),"hsv")},hsi:function(e){return p(K(e,"hsi"),"hsi")},hwb:function(e){return p(K(e,"hwb"),"hwb")},rgb:Q,lab:function(e){return p(K(e,"lab"),"lab")},lch:function(e){return p(K(e,"lch"),"lch")},css:function(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb",r=Q(e),n=V(r.r),t=V(r.g),o=V(r.b);return"hex"===a?"#"+(1<<24|n<<16|t<<8|o).toString(16).slice(1):"rgb"===a?void 0===r.alpha||1===r.alpha?"rgb("+n+", "+t+", "+o+")":"rgba("+n+", "+t+", "+o+", "+U(r.alpha,2)+")":void 0},convert:p,prepare:K,round:U,parse:F,parseNumber:v,parseNamed:m,parseHex:C,parseRgb:L,parseHsl:B,parseHwb:D,named:f,map:X,interpolate:function(a){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb";if(!(a.length<2)){var n=a.map(function(e){return p(K(e,r),r)});return function(a){if(1===(a=Math.min(Math.max(0,a),1)))return Object.assign({},n[n.length-1]);var t=a*(n.length-1),o=Math.floor(t),i=n[o],l=n[o+1],h=t-o;return X({mode:r},function(a){return("h"===a?function(a,r,n){return void 0!==a&&void 0!==r?(a=e(a),r=e(r),Math.abs(r-a)>180?e(Y(a,r-360*Math.sign(r-a),n)):Y(a,r,n)):void 0===a?r:a}:"alpha"===a?function(e,a,r){if(void 0!==e||void 0!==a)return Y(void 0===e?1:e,void 0===a?1:a,r)}:function(e,a,r){return void 0!==e&&void 0!==a?Y(e,a,r):void 0===e?a:e})(i[a],l[a],h)})}}},swatches:function(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;if(a<2)return a<1?[e(0),e(1)]:[e(.5)];for(var r=[],n=0;n<a;n++)r.push(e(n/(a-1)));return r},default:Z});return Object.assign(Z,_),Z});

@@ -0,1 +1,5 @@

var normalizeHue = (function (hue) {
return (hue = hue % 360) < 0 ? hue + 360 : hue;
});
// Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB

@@ -9,3 +13,3 @@

h = (h < 0 ? h + 360 : h) % 360;
h = normalizeHue(h);
var f = Math.abs(h / 60 % 2 - 1);

@@ -71,3 +75,3 @@ var res = void 0;

h = (h < 0 ? h + 360 : h) % 360;
h = normalizeHue(h);
var m1 = l + s * (l < 0.5 ? l : 1 - l);

@@ -103,4 +107,3 @@ var m2 = m1 - (m1 - l) * 2 * Math.abs(h / 60 % 2 - 1);

h = h % 360;
if (h < 0) h += 360;
h = normalizeHue(h);
var f = Math.abs(h / 60 % 2 - 1);

@@ -255,5 +258,4 @@ var res = void 0;

c: Math.sqrt(a * a + b * b),
h: Math.atan2(b, a) * 180 / Math.PI
h: normalizeHue(Math.atan2(b, a) * 180 / Math.PI)
};
if (res.h < 0) res.h += 360;
if (alpha !== undefined) res.alpha = alpha;

@@ -992,16 +994,21 @@ return res;

var normalizeHue = (function (hue) {
return (hue = hue % 360) < 0 ? hue + 360 : hue;
});
var linear = function linear(a, b, t) {
return a + t * (b - a);
};
var generic = function generic(a, b, t) {
if (a !== undefined && b !== undefined) return linear(a, b, t);
return a === undefined ? b : a;
};
var hue$2 = function hue(a, b, t) {
a = normalizeHue(a);b = normalizeHue(b);
return Math.abs(b - a) > 180 ? normalizeHue(linear(a, b - 360 * Math.sign(b - a), t)) : linear(a, b, t);
if (a !== undefined && b !== undefined) {
a = normalizeHue(a);b = normalizeHue(b);
return Math.abs(b - a) > 180 ? normalizeHue(linear(a, b - 360 * Math.sign(b - a), t)) : linear(a, b, t);
}
return a === undefined ? b : a;
};
var interpolator = function interpolator(key) {
return key === 'h' ? hue$2 : linear;
var alpha$1 = function alpha(a, b, t) {
if (a === undefined && b === undefined) return undefined;
return linear(a === undefined ? 1 : a, b === undefined ? 1 : b, t);
};

@@ -1041,3 +1048,3 @@

return map({ mode: mode }, function (key) {
return interpolator(key)(startColor[key], endColor[key], t0);
return (key === 'h' ? hue$2 : key === 'alpha' ? alpha$1 : generic)(startColor[key], endColor[key], t0);
});

@@ -1044,0 +1051,0 @@ };

{
"name": "culori",
"version": "0.2.32",
"version": "0.2.33",
"main": "build/culori.js",

@@ -5,0 +5,0 @@ "module": "build/index.js",

@@ -7,10 +7,21 @@ import convert from './convert';

const linear = (a, b, t) => a + t * (b - a);
const generic = (a, b, t) => {
if (a !== undefined && b !== undefined) return linear(a, b, t);
return a === undefined ? b : a;
}
const hue = (a, b, t) => {
a = normalizeHue(a); b = normalizeHue(b);
return Math.abs(b - a) > 180 ?
normalizeHue(linear(a, b - 360 * Math.sign(b - a), t))
: linear(a, b, t);
if (a !== undefined && b !== undefined) {
a = normalizeHue(a); b = normalizeHue(b);
return Math.abs(b - a) > 180 ?
normalizeHue(linear(a, b - 360 * Math.sign(b - a), t))
: linear(a, b, t);
}
return a === undefined ? b : a;
};
const interpolator = key => key === 'h' ? hue : linear;
const alpha = (a, b, t) => {
if (a === undefined && b === undefined) return undefined;
return linear(a === undefined ? 1 : a, b === undefined ? 1: b, t);
}

@@ -45,5 +56,5 @@ export default (seeds, mode = 'rgb') => {

{ mode: mode },
key => interpolator(key)(startColor[key], endColor[key], t0)
key => (key === 'h' ? hue : key === 'alpha' ? alpha : generic)(startColor[key], endColor[key], t0)
);
};
};

@@ -0,5 +1,7 @@

import normalizeHue from '../util/normalizeHue';
// Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB
export default function ({ h, s, i, alpha }) {
h = (h < 0 ? h + 360 : h) % 360;
h = normalizeHue(h);
let f = Math.abs(h/60 % 2 - 1);

@@ -6,0 +8,0 @@ let res;

@@ -0,5 +1,6 @@

import normalizeHue from '../util/normalizeHue';
// Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB
export default function({ h, s, l, alpha }) {
h = (h < 0 ? h + 360 : h) % 360;
h = normalizeHue(h);
let m1 = l + s * (l < 0.5 ? l : 1 - l);

@@ -6,0 +7,0 @@ let m2 = m1 - (m1 - l) * 2 * Math.abs(h/60 % 2 - 1);

@@ -0,6 +1,7 @@

import normalizeHue from '../util/normalizeHue';
// Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB
export default function({ h, s, v, alpha }) {
h = h % 360;
if (h < 0) h += 360;
h = normalizeHue(h);
let f = Math.abs(h/60 % 2 - 1);

@@ -7,0 +8,0 @@ let res;

@@ -0,1 +1,2 @@

import normalizeHue from '../util/normalizeHue';
/*

@@ -11,7 +12,6 @@ References:

c: Math.sqrt(a * a + b * b),
h: Math.atan2(b, a) * 180 / Math.PI
h: normalizeHue(Math.atan2(b, a) * 180 / Math.PI)
}
if (res.h < 0) res.h += 360;
if (alpha !== undefined) res.alpha = alpha;
return res;
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc