Socket
Socket
Sign inDemoInstall

d3-color

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-color - npm Package Compare versions

Comparing version 0.3.4 to 0.4.0

2

build/bundle.js

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

var version = "0.3.4"; export * from "../index"; export {version};
var version = "0.4.0"; export * from "../index"; export {version};

@@ -16,3 +16,6 @@ (function (global, factory) {

var reRgbPercent = /^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
var reRgbaInteger = /^rgba\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
var reRgbaPercent = /^rgba\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
var reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
var reHslaPercent = /^hsla\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;
var named = {

@@ -183,6 +186,10 @@ aliceblue: 0xf0f8ff,

: (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
: (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3]) // rgb(255,0,0)
: (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100) // rgb(100%,0%,0%)
: (m = reHslPercent.exec(format)) ? new Hsl(m[1], m[2] / 100, m[3] / 100) // hsl(120,50%,50%)
: (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3]) // rgb(255, 0, 0)
: (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100) // rgb(100%, 0%, 0%)
: (m = reRgbaInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
: (m = reRgbaPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
: (m = reHslPercent.exec(format)) ? new Hsl(m[1], m[2] / 100, m[3] / 100) // hsl(120, 50%, 50%)
: (m = reHslaPercent.exec(format)) ? new Hsl(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
: named.hasOwnProperty(format) ? rgbn(named[format])
: format === "transparent" ? new Rgb(0, 0, 0, 0)
: null;

@@ -195,3 +202,3 @@ }

function rgb(r, g, b) {
function rgb(r, g, b, opacity) {
if (arguments.length === 1) {

@@ -201,2 +208,3 @@ if (!(r instanceof Color)) r = color(r);

r = r.rgb();
opacity = r.opacity;
b = r.b;

@@ -206,12 +214,13 @@ g = r.g;

} else {
r = g = b = NaN;
r = NaN;
}
}
return new Rgb(r, g, b);
return new Rgb(r, g, b, opacity);
}
function Rgb(r, g, b) {
function Rgb(r, g, b, opacity) {
this.r = +r;
this.g = +g;
this.b = +b;
this.opacity = opacity == null ? 1 : +opacity;
}

@@ -223,3 +232,3 @@

k = k == null ? brighter : Math.pow(brighter, k);
return new Rgb(this.r * k, this.g * k, this.b * k);
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
};

@@ -229,3 +238,3 @@

k = k == null ? darker : Math.pow(darker, k);
return new Rgb(this.r * k, this.g * k, this.b * k);
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
};

@@ -240,18 +249,19 @@

&& (0 <= this.g && this.g <= 255)
&& (0 <= this.b && this.b <= 255);
&& (0 <= this.b && this.b <= 255)
&& (0 <= this.opacity && this.opacity <= 1);
};
_rgb.toString = function() {
var r = Math.round(this.r),
g = Math.round(this.g),
b = Math.round(this.b);
return "#"
+ (isNaN(r) || r <= 0 ? "00" : r < 16 ? "0" + r.toString(16) : r >= 255 ? "ff" : r.toString(16))
+ (isNaN(g) || g <= 0 ? "00" : g < 16 ? "0" + g.toString(16) : g >= 255 ? "ff" : g.toString(16))
+ (isNaN(b) || b <= 0 ? "00" : b < 16 ? "0" + b.toString(16) : b >= 255 ? "ff" : b.toString(16));
var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
return (a === 1 ? "rgb(" : "rgba(")
+ Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
+ Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
+ Math.max(0, Math.min(255, Math.round(this.b) || 0))
+ (a === 1 ? ")" : ", " + a + ")");
};
function hsl(h, s, l) {
function hsl(h, s, l, opacity) {
if (arguments.length === 1) {
if (h instanceof Hsl) {
opacity = h.opacity;
l = h.l;

@@ -265,2 +275,3 @@ s = h.s;

h = h.rgb();
opacity = h.opacity;
var r = h.r / 255,

@@ -284,13 +295,14 @@ g = h.g / 255,

} else {
h = s = l = NaN;
h = NaN;
}
}
}
return new Hsl(h, s, l);
return new Hsl(h, s, l, opacity);
}
function Hsl(h, s, l) {
function Hsl(h, s, l, opacity) {
this.h = +h;
this.s = +s;
this.l = +l;
this.opacity = opacity == null ? 1 : +opacity;
}

@@ -302,3 +314,3 @@

k = k == null ? brighter : Math.pow(brighter, k);
return new Hsl(this.h, this.s, this.l * k);
return new Hsl(this.h, this.s, this.l * k, this.opacity);
};

@@ -308,3 +320,3 @@

k = k == null ? darker : Math.pow(darker, k);
return new Hsl(this.h, this.s, this.l * k);
return new Hsl(this.h, this.s, this.l * k, this.opacity);
};

@@ -321,3 +333,4 @@

hsl2rgb(h, m1, m2),
hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2)
hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
this.opacity
);

@@ -328,3 +341,4 @@ };

return (0 <= this.s && this.s <= 1 || isNaN(this.s))
&& (0 <= this.l && this.l <= 1);
&& (0 <= this.l && this.l <= 1)
&& (0 <= this.opacity && this.opacity <= 1);
};

@@ -351,5 +365,6 @@

var t3 = t1 * t1 * t1;
function lab(l, a, b) {
function lab(l, a, b, opacity) {
if (arguments.length === 1) {
if (l instanceof Lab) {
opacity = l.opacity;
b = l.b;

@@ -360,2 +375,3 @@ a = l.a;

var h = l.h * deg2rad;
opacity = l.opacity;
b = Math.sin(h) * l.c;

@@ -366,2 +382,3 @@ a = Math.cos(h) * l.c;

if (!(l instanceof Rgb)) l = rgb(l);
opacity = l.opacity;
b = rgb2xyz(l.r);

@@ -378,9 +395,10 @@ a = rgb2xyz(l.g);

}
return new Lab(l, a, b);
return new Lab(l, a, b, opacity);
}
function Lab(l, a, b) {
function Lab(l, a, b, opacity) {
this.l = +l;
this.a = +a;
this.b = +b;
this.opacity = opacity == null ? 1 : +opacity;
}

@@ -391,7 +409,7 @@

_lab.brighter = function(k) {
return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b);
return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
};
_lab.darker = function(k) {
return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b);
return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
};

@@ -409,3 +427,4 @@

xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z)
xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
this.opacity
);

@@ -430,5 +449,6 @@ };

function hcl(h, c, l) {
function hcl(h, c, l, opacity) {
if (arguments.length === 1) {
if (h instanceof Hcl) {
opacity = h.opacity;
l = h.l;

@@ -439,2 +459,3 @@ c = h.c;

if (!(h instanceof Lab)) h = lab(h);
opacity = h.opacity;
l = h.l;

@@ -446,9 +467,10 @@ c = Math.sqrt(h.a * h.a + h.b * h.b);

}
return new Hcl(h, c, l);
return new Hcl(h, c, l, opacity);
}
function Hcl(h, c, l) {
function Hcl(h, c, l, opacity) {
this.h = +h;
this.c = +c;
this.l = +l;
this.opacity = opacity == null ? 1 : +opacity;
}

@@ -459,7 +481,7 @@

_hcl.brighter = function(k) {
return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k));
return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
};
_hcl.darker = function(k) {
return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k));
return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
};

@@ -479,5 +501,6 @@

var BC_DA = B * C - D * A;
function cubehelix(h, s, l) {
function cubehelix(h, s, l, opacity) {
if (arguments.length === 1) {
if (h instanceof Cubehelix) {
opacity = h.opacity;
l = h.l;

@@ -488,2 +511,3 @@ s = h.s;

if (!(h instanceof Rgb)) h = rgb(h);
opacity = h.opacity;
var r = h.r / 255, g = h.g / 255, b = h.b / 255;

@@ -497,9 +521,10 @@ l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB);

}
return new Cubehelix(h, s, l);
return new Cubehelix(h, s, l, opacity);
}
function Cubehelix(h, s, l) {
function Cubehelix(h, s, l, opacity) {
this.h = +h;
this.s = +s;
this.l = +l;
this.opacity = opacity == null ? 1 : +opacity;
}

@@ -511,3 +536,3 @@

k = k == null ? brighter : Math.pow(brighter, k);
return new Cubehelix(this.h, this.s, this.l * k);
return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
};

@@ -517,3 +542,3 @@

k = k == null ? darker : Math.pow(darker, k);
return new Cubehelix(this.h, this.s, this.l * k);
return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
};

@@ -530,7 +555,8 @@

255 * (l + a * (C * cosh + D * sinh)),
255 * (l + a * (E * cosh))
255 * (l + a * (E * cosh)),
this.opacity
);
};
var version = "0.3.4";
var version = "0.4.0";

@@ -537,0 +563,0 @@ exports.version = version;

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.d3_color={})}(this,function(e){"use strict";function t(){}function n(e){var t;return e=(e+"").trim().toLowerCase(),(t=v.exec(e))?(t=parseInt(t[1],16),new s(t>>8&15|t>>4&240,t>>4&15|240&t,(15&t)<<4|15&t)):(t=N.exec(e))?r(parseInt(t[1],16)):(t=M.exec(e))?new s(t[1],t[2],t[3]):(t=q.exec(e))?new s(255*t[1]/100,255*t[2]/100,255*t[3]/100):(t=x.exec(e))?new o(t[1],t[2]/100,t[3]/100):S.hasOwnProperty(e)?r(S[e]):null}function r(e){return new s(e>>16&255,e>>8&255,255&e)}function i(e,r,i){return 1===arguments.length&&(e instanceof t||(e=n(e)),e?(e=e.rgb(),i=e.b,r=e.g,e=e.r):e=r=i=NaN),new s(e,r,i)}function s(e,t,n){this.r=+e,this.g=+t,this.b=+n}function a(e,r,i){if(1===arguments.length)if(e instanceof o)i=e.l,r=e.s,e=e.h;else if(e instanceof t||(e=n(e)),e){if(e instanceof o)return e;e=e.rgb();var s=e.r/255,a=e.g/255,l=e.b/255,h=Math.min(s,a,l),u=Math.max(s,a,l),g=u-h;i=(u+h)/2,g?(r=.5>i?g/(u+h):g/(2-u-h),e=s===u?(a-l)/g+6*(l>a):a===u?(l-s)/g+2:(s-a)/g+4,e*=60):(e=NaN,r=i>0&&1>i?0:e)}else e=r=i=NaN;return new o(e,r,i)}function o(e,t,n){this.h=+e,this.s=+t,this.l=+n}function l(e,t,n){return 255*(60>e?t+(n-t)*e/60:180>e?n:240>e?t+(n-t)*(240-e)/60:t)}function h(e,t,n){if(1===arguments.length)if(e instanceof u)n=e.b,t=e.a,e=e.l;else if(e instanceof p){var r=e.h*P;n=Math.sin(r)*e.c,t=Math.cos(r)*e.c,e=e.l}else{e instanceof s||(e=i(e)),n=f(e.r),t=f(e.g),e=f(e.b);var a=g((.4124564*n+.3575761*t+.1804375*e)/C),o=g((.2126729*n+.7151522*t+.072175*e)/L),l=g((.0193339*n+.119192*t+.9503041*e)/O);n=200*(o-l),t=500*(a-o),e=116*o-16}return new u(e,t,n)}function u(e,t,n){this.l=+e,this.a=+t,this.b=+n}function g(e){return e>D?Math.pow(e,1/3):e/B+_}function d(e){return e>A?e*e*e:B*(e-_)}function c(e){return 255*(.0031308>=e?12.92*e:1.055*Math.pow(e,1/2.4)-.055)}function f(e){return(e/=255)<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function b(e,t,n){return 1===arguments.length&&(e instanceof p?(n=e.l,t=e.c,e=e.h):(e instanceof u||(e=h(e)),n=e.l,t=Math.sqrt(e.a*e.a+e.b*e.b),e=Math.atan2(e.b,e.a)*j,0>e&&(e+=360))),new p(e,t,n)}function p(e,t,n){this.h=+e,this.c=+t,this.l=+n}function w(e,t,n){if(1===arguments.length)if(e instanceof y)n=e.l,t=e.s,e=e.h;else{e instanceof s||(e=i(e));var r=e.r/255,a=e.g/255,o=e.b/255;n=(U*o+R*r-T*a)/(U+R-T);var l=o-n,h=(Q*(a-n)-J*l)/K;t=Math.sqrt(h*h+l*l)/(Q*n*(1-n)),e=t?Math.atan2(h,l)*j-120:NaN,0>e&&(e+=360)}return new y(e,t,n)}function y(e,t,n){this.h=+e,this.s=+t,this.l=+n}var m=.7,k=1/m,v=/^#([0-9a-f]{3})$/,N=/^#([0-9a-f]{6})$/,M=/^rgb\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*\)$/,q=/^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/,x=/^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/,S={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};n.prototype=t.prototype={displayable:function(){return this.rgb().displayable()},toString:function(){return this.rgb()+""}};var $=i.prototype=s.prototype=new t;$.brighter=function(e){return e=null==e?k:Math.pow(k,e),new s(this.r*e,this.g*e,this.b*e)},$.darker=function(e){return e=null==e?m:Math.pow(m,e),new s(this.r*e,this.g*e,this.b*e)},$.rgb=function(){return this},$.displayable=function(){return 0<=this.r&&this.r<=255&&0<=this.g&&this.g<=255&&0<=this.b&&this.b<=255},$.toString=function(){var e=Math.round(this.r),t=Math.round(this.g),n=Math.round(this.b);return"#"+(isNaN(e)||0>=e?"00":16>e?"0"+e.toString(16):e>=255?"ff":e.toString(16))+(isNaN(t)||0>=t?"00":16>t?"0"+t.toString(16):t>=255?"ff":t.toString(16))+(isNaN(n)||0>=n?"00":16>n?"0"+n.toString(16):n>=255?"ff":n.toString(16))};var I=a.prototype=o.prototype=new t;I.brighter=function(e){return e=null==e?k:Math.pow(k,e),new o(this.h,this.s,this.l*e)},I.darker=function(e){return e=null==e?m:Math.pow(m,e),new o(this.h,this.s,this.l*e)},I.rgb=function(){var e=this.h%360+360*(this.h<0),t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(.5>n?n:1-n)*t,i=2*n-r;return new s(l(e>=240?e-240:e+120,i,r),l(e,i,r),l(120>e?e+240:e-120,i,r))},I.displayable=function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1};var P=Math.PI/180,j=180/Math.PI,z=18,C=.95047,L=1,O=1.08883,_=4/29,A=6/29,B=3*A*A,D=A*A*A,E=h.prototype=u.prototype=new t;E.brighter=function(e){return new u(this.l+z*(null==e?1:e),this.a,this.b)},E.darker=function(e){return new u(this.l-z*(null==e?1:e),this.a,this.b)},E.rgb=function(){var e=(this.l+16)/116,t=isNaN(this.a)?e:e+this.a/500,n=isNaN(this.b)?e:e-this.b/200;return e=L*d(e),t=C*d(t),n=O*d(n),new s(c(3.2404542*t-1.5371385*e-.4985314*n),c(-.969266*t+1.8760108*e+.041556*n),c(.0556434*t-.2040259*e+1.0572252*n))};var F=b.prototype=p.prototype=new t;F.brighter=function(e){return new p(this.h,this.c,this.l+z*(null==e?1:e))},F.darker=function(e){return new p(this.h,this.c,this.l-z*(null==e?1:e))},F.rgb=function(){return h(this).rgb()};var G=-.14861,H=1.78277,J=-.29227,K=-.90649,Q=1.97294,R=Q*K,T=Q*H,U=H*J-K*G,V=w.prototype=y.prototype=new t;V.brighter=function(e){return e=null==e?k:Math.pow(k,e),new y(this.h,this.s,this.l*e)},V.darker=function(e){return e=null==e?m:Math.pow(m,e),new y(this.h,this.s,this.l*e)},V.rgb=function(){var e=isNaN(this.h)?0:(this.h+120)*P,t=+this.l,n=isNaN(this.s)?0:this.s*t*(1-t),r=Math.cos(e),i=Math.sin(e);return new s(255*(t+n*(G*r+H*i)),255*(t+n*(J*r+K*i)),255*(t+n*(Q*r)))};var W="0.3.4";e.version=W,e.color=n,e.rgb=i,e.hsl=a,e.lab=h,e.hcl=b,e.cubehelix=w});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.d3_color={})}(this,function(t){"use strict";function e(){}function i(t){var e;return t=(t+"").trim().toLowerCase(),(e=v.exec(t))?(e=parseInt(e[1],16),new a(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e)):(e=M.exec(t))?n(parseInt(e[1],16)):(e=N.exec(t))?new a(e[1],e[2],e[3]):(e=x.exec(t))?new a(255*e[1]/100,255*e[2]/100,255*e[3]/100):(e=q.exec(t))?new a(e[1],e[2],e[3],e[4]):(e=$.exec(t))?new a(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=I.exec(t))?new o(e[1],e[2]/100,e[3]/100):(e=P.exec(t))?new o(e[1],e[2]/100,e[3]/100,e[4]):j.hasOwnProperty(t)?n(j[t]):"transparent"===t?new a(0,0,0,0):null}function n(t){return new a(t>>16&255,t>>8&255,255&t)}function r(t,n,r,s){return 1===arguments.length&&(t instanceof e||(t=i(t)),t?(t=t.rgb(),s=t.opacity,r=t.b,n=t.g,t=t.r):t=NaN),new a(t,n,r,s)}function a(t,e,i,n){this.r=+t,this.g=+e,this.b=+i,this.opacity=null==n?1:+n}function s(t,n,r,a){if(1===arguments.length)if(t instanceof o)a=t.opacity,r=t.l,n=t.s,t=t.h;else if(t instanceof e||(t=i(t)),t){if(t instanceof o)return t;t=t.rgb(),a=t.opacity;var s=t.r/255,h=t.g/255,l=t.b/255,u=Math.min(s,h,l),c=Math.max(s,h,l),d=c-u;r=(c+u)/2,d?(n=.5>r?d/(c+u):d/(2-c-u),t=s===c?(h-l)/d+6*(l>h):h===c?(l-s)/d+2:(s-h)/d+4,t*=60):(t=NaN,n=r>0&&1>r?0:t)}else t=NaN;return new o(t,n,r,a)}function o(t,e,i,n){this.h=+t,this.s=+e,this.l=+i,this.opacity=null==n?1:+n}function h(t,e,i){return 255*(60>t?e+(i-e)*t/60:180>t?i:240>t?e+(i-e)*(240-t)/60:e)}function l(t,e,i,n){if(1===arguments.length)if(t instanceof u)n=t.opacity,i=t.b,e=t.a,t=t.l;else if(t instanceof b){var s=t.h*C;n=t.opacity,i=Math.sin(s)*t.c,e=Math.cos(s)*t.c,t=t.l}else{t instanceof a||(t=r(t)),n=t.opacity,i=p(t.r),e=p(t.g),t=p(t.b);var o=c((.4124564*i+.3575761*e+.1804375*t)/_),h=c((.2126729*i+.7151522*e+.072175*t)/A),l=c((.0193339*i+.119192*e+.9503041*t)/B);i=200*(h-l),e=500*(o-h),t=116*h-16}return new u(t,e,i,n)}function u(t,e,i,n){this.l=+t,this.a=+e,this.b=+i,this.opacity=null==n?1:+n}function c(t){return t>G?Math.pow(t,1/3):t/F+D}function d(t){return t>E?t*t*t:F*(t-D)}function g(t){return 255*(.0031308>=t?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function p(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function y(t,e,i,n){return 1===arguments.length&&(t instanceof b?(n=t.opacity,i=t.l,e=t.c,t=t.h):(t instanceof u||(t=l(t)),n=t.opacity,i=t.l,e=Math.sqrt(t.a*t.a+t.b*t.b),t=Math.atan2(t.b,t.a)*L,0>t&&(t+=360))),new b(t,e,i,n)}function b(t,e,i,n){this.h=+t,this.c=+e,this.l=+i,this.opacity=null==n?1:+n}function f(t,e,i,n){if(1===arguments.length)if(t instanceof w)n=t.opacity,i=t.l,e=t.s,t=t.h;else{t instanceof a||(t=r(t)),n=t.opacity;var s=t.r/255,o=t.g/255,h=t.b/255;i=(X*h+V*s-W*o)/(X+V-W);var l=h-i,u=(U*(o-i)-R*l)/T;e=Math.sqrt(u*u+l*l)/(U*i*(1-i)),t=e?Math.atan2(u,l)*L-120:NaN,0>t&&(t+=360)}return new w(t,e,i,n)}function w(t,e,i,n){this.h=+t,this.s=+e,this.l=+i,this.opacity=null==n?1:+n}var m=.7,k=1/m,v=/^#([0-9a-f]{3})$/,M=/^#([0-9a-f]{6})$/,N=/^rgb\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*\)$/,x=/^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/,q=/^rgba\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/,$=/^rgba\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/,I=/^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/,P=/^hsla\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/,j={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};i.prototype=e.prototype={displayable:function(){return this.rgb().displayable()},toString:function(){return this.rgb()+""}};var S=r.prototype=a.prototype=new e;S.brighter=function(t){return t=null==t?k:Math.pow(k,t),new a(this.r*t,this.g*t,this.b*t,this.opacity)},S.darker=function(t){return t=null==t?m:Math.pow(m,t),new a(this.r*t,this.g*t,this.b*t,this.opacity)},S.rgb=function(){return this},S.displayable=function(){return 0<=this.r&&this.r<=255&&0<=this.g&&this.g<=255&&0<=this.b&&this.b<=255&&0<=this.opacity&&this.opacity<=1},S.toString=function(){var t=this.opacity;return t=isNaN(t)?1:Math.max(0,Math.min(1,t)),(1===t?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")};var z=s.prototype=o.prototype=new e;z.brighter=function(t){return t=null==t?k:Math.pow(k,t),new o(this.h,this.s,this.l*t,this.opacity)},z.darker=function(t){return t=null==t?m:Math.pow(m,t),new o(this.h,this.s,this.l*t,this.opacity)},z.rgb=function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,i=this.l,n=i+(.5>i?i:1-i)*e,r=2*i-n;return new a(h(t>=240?t-240:t+120,r,n),h(t,r,n),h(120>t?t+240:t-120,r,n),this.opacity)},z.displayable=function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1};var C=Math.PI/180,L=180/Math.PI,O=18,_=.95047,A=1,B=1.08883,D=4/29,E=6/29,F=3*E*E,G=E*E*E,H=l.prototype=u.prototype=new e;H.brighter=function(t){return new u(this.l+O*(null==t?1:t),this.a,this.b,this.opacity)},H.darker=function(t){return new u(this.l-O*(null==t?1:t),this.a,this.b,this.opacity)},H.rgb=function(){var t=(this.l+16)/116,e=isNaN(this.a)?t:t+this.a/500,i=isNaN(this.b)?t:t-this.b/200;return t=A*d(t),e=_*d(e),i=B*d(i),new a(g(3.2404542*e-1.5371385*t-.4985314*i),g(-.969266*e+1.8760108*t+.041556*i),g(.0556434*e-.2040259*t+1.0572252*i),this.opacity)};var J=y.prototype=b.prototype=new e;J.brighter=function(t){return new b(this.h,this.c,this.l+O*(null==t?1:t),this.opacity)},J.darker=function(t){return new b(this.h,this.c,this.l-O*(null==t?1:t),this.opacity)},J.rgb=function(){return l(this).rgb()};var K=-.14861,Q=1.78277,R=-.29227,T=-.90649,U=1.97294,V=U*T,W=U*Q,X=Q*R-T*K,Y=f.prototype=w.prototype=new e;Y.brighter=function(t){return t=null==t?k:Math.pow(k,t),new w(this.h,this.s,this.l*t,this.opacity)},Y.darker=function(t){return t=null==t?m:Math.pow(m,t),new w(this.h,this.s,this.l*t,this.opacity)},Y.rgb=function(){var t=isNaN(this.h)?0:(this.h+120)*C,e=+this.l,i=isNaN(this.s)?0:this.s*e*(1-e),n=Math.cos(t),r=Math.sin(t);return new a(255*(e+i*(K*n+Q*r)),255*(e+i*(R*n+T*r)),255*(e+i*(U*n)),this.opacity)};var Z="0.4.0";t.version=Z,t.color=i,t.rgb=r,t.hsl=s,t.lab=l,t.hcl=y,t.cubehelix=f});
{
"name": "d3-color",
"version": "0.3.4",
"version": "0.4.0",
"description": "Color spaces! RGB, HSL, Cubehelix, Lab and HCL (Lch).",

@@ -29,5 +29,5 @@ "keywords": [

"pretest": "mkdir -p build && node -e 'process.stdout.write(\"var version = \\\"\" + require(\"./package.json\").version + \"\\\"; export * from \\\"../index\\\"; export {version};\");' > build/bundle.js && rollup -f umd -n d3_color -o build/d3-color.js -- build/bundle.js",
"test": "faucet `find test -name '*-test.js'` && eslint index.js src",
"test": "faucet `find test -name '*-test.js'` && eslint index.js src test",
"prepublish": "npm run test && uglifyjs build/d3-color.js -c -m -o build/d3-color.min.js && rm -f build/d3-color.zip && zip -j build/d3-color.zip -- LICENSE README.md build/d3-color.js build/d3-color.min.js",
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git tag -am \"Release $VERSION.\" v${VERSION} && git push --tags && cp build/d3-color.js ../d3.github.com/d3-color.v0.3.js && cp build/d3-color.min.js ../d3.github.com/d3-color.v0.3.min.js && cd ../d3.github.com && git add d3-color.v0.3.js d3-color.v0.3.min.js && git commit -m \"d3-color ${VERSION}\" && git push"
"postpublish": "VERSION=`node -e 'console.log(require(\"./package.json\").version)'`; git push && git tag -am \"Release $VERSION.\" v${VERSION} && git push --tags && cp build/d3-color.js ../d3.github.com/d3-color.v0.4.js && cp build/d3-color.min.js ../d3.github.com/d3-color.v0.4.min.js && cd ../d3.github.com && git add d3-color.v0.4.js d3-color.v0.4.min.js && git commit -m \"d3-color ${VERSION}\" && git push"
},

@@ -34,0 +34,0 @@ "devDependencies": {

@@ -8,3 +8,3 @@ # d3-color

```js
var c = d3.color("steelblue"); // {r: 70, g: 130, b: 180}
var c = d3.color("steelblue"); // {r: 70, g: 130, b: 180, opacity: 1}
```

@@ -15,6 +15,6 @@

```js
var c = d3.hsl("steelblue"); // {h: 207.27272727272728, s: 0.44, l: 0.4901960784313726}
var c = d3.hsl("steelblue"); // {h: 207.27272727272728, s: 0.44, l: 0.4901960784313726, opacity: 1}
```
Now rotate the hue by 90°, bump up the saturation, and format as hex:
Now rotate the hue by 90°, bump up the saturation, and format as a string for CSS:

@@ -24,5 +24,12 @@ ```js

c.s += 0.2;
c + ""; // #c62dcd
c + ""; // rgb(198, 45, 205)
```
To fade the color slightly:
```js
c.opacity = 0.8;
c + ""; // rgba(198, 45, 205, 0.8)
```
In addition to the ubiquitous and machine-friendly [RGB](#rgb) and [HSL](#hsl) color space, d3-color supports two color spaces that are designed for humans:

@@ -40,3 +47,3 @@

```html
<script src="https://d3js.org/d3-color.v0.3.min.js"></script>
<script src="https://d3js.org/d3-color.v0.4.min.js"></script>
```

@@ -52,7 +59,11 @@

* `"rgb(255,255,255)"`
* `"hsl(120,50%,20%)"`
* `"#ffeeaa"`
* `"#fea"`
* `"steelblue"`
* `rgb(255, 255, 255)`
* `rgb(10%, 20%, 30%)`
* `rgba(255, 255, 255, 0.4)`
* `rgba(10%, 20%, 30%, 0.4)`
* `hsl(120, 50%, 20%)`
* `hsla(120, 50%, 20%, 0.4)`
* `#ffeeaa`
* `#fea`
* `steelblue`

@@ -63,2 +74,6 @@ The list of supported [named colors](http://www.w3.org/TR/SVG/types.html#ColorKeywords) is specified by CSS.

<a name="color_opacity" href="#color_opacity">#</a> *color*.<b>opacity</b>
This color’s opacity, typically in the range [0, 1].
<a name="color_rgb" href="#color_rgb">#</a> *color*.<b>rgb</b>()

@@ -78,9 +93,9 @@

Returns true if and only if the color is displayable on standard hardware. For example, this returns false for an RGB color if any channel value is less than zero or greater than 255.
Returns true if and only if the color is displayable on standard hardware. For example, this returns false for an RGB color if any channel value is less than zero or greater than 255, or if the opacity is not in the range [0, 1].
<a name="color_toString" href="#color_toString">#</a> *color*.<b>toString</b>()
Returns the RGB hexadecimal string representing this color, such as `"#f7eaba"`. If this color is not displayable, a suitable displayable color is returned instead. For example, RGB channel values greater than 255 are clamped to 255.
Returns a string representing this color according to the [CSS Object Model specification](https://drafts.csswg.org/cssom/#serialize-a-css-component-value), such as `rgb(247, 234, 186)`. If this color is not displayable, a suitable displayable color is returned instead. For example, RGB channel values greater than 255 are clamped to 255.
<a name="rgb" href="#rgb">#</a> d3.<b>rgb</b>(<i>r</i>, <i>g</i>, <i>b</i>)<br>
<a name="rgb" href="#rgb">#</a> d3.<b>rgb</b>(<i>r</i>, <i>g</i>, <i>b</i>[, <i>opacity</i>])<br>
<a href="#rgb">#</a> d3.<b>rgb</b>(<i>specifier</i>)<br>

@@ -91,5 +106,5 @@ <a href="#rgb">#</a> d3.<b>rgb</b>(<i>color</i>)<br>

If *r*, *g* and *b* are specified, these represent the channel values of the returned color. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the RGB color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb). Note that unlike [*color*.rgb](#color_rgb) this method *always* returns a new instance, even if *color* is already an RGB color.
If *r*, *g* and *b* are specified, these represent the channel values of the returned color; an *opacity* may also be specified. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the RGB color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb). Note that unlike [*color*.rgb](#color_rgb) this method *always* returns a new instance, even if *color* is already an RGB color.
<a name="hsl" href="#hsl">#</a> d3.<b>hsl</b>(<i>h</i>, <i>s</i>, <i>l</i>)<br>
<a name="hsl" href="#hsl">#</a> d3.<b>hsl</b>(<i>h</i>, <i>s</i>, <i>l</i>[, <i>opacity</i>])<br>
<a href="#hsl">#</a> d3.<b>hsl</b>(<i>specifier</i>)<br>

@@ -100,5 +115,5 @@ <a href="#hsl">#</a> d3.<b>hsl</b>(<i>color</i>)<br>

If *h*, *s* and *l* are specified, these represent the channel values of the returned color. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the HSL color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to HSL. (Colors already in the HSL color space skip the conversion to RGB.)
If *h*, *s* and *l* are specified, these represent the channel values of the returned color; an *opacity* may also be specified. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the HSL color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to HSL. (Colors already in the HSL color space skip the conversion to RGB.)
<a name="lab" href="#lab">#</a> d3.<b>lab</b>(<i>l</i>, <i>a</i>, <i>b</i>)<br>
<a name="lab" href="#lab">#</a> d3.<b>lab</b>(<i>l</i>, <i>a</i>, <i>b</i>[, <i>opacity</i>])<br>
<a href="#lab">#</a> d3.<b>lab</b>(<i>specifier</i>)<br>

@@ -109,5 +124,5 @@ <a href="#lab">#</a> d3.<b>lab</b>(<i>color</i>)<br>

If *l*, *a* and *b* are specified, these represent the channel values of the returned color. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the Lab color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to Lab. (Colors already in the Lab color space skip the conversion to RGB, and colors in the HCL color space are converted directly to Lab.)
If *l*, *a* and *b* are specified, these represent the channel values of the returned color; an *opacity* may also be specified. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the Lab color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to Lab. (Colors already in the Lab color space skip the conversion to RGB, and colors in the HCL color space are converted directly to Lab.)
<a name="hcl" href="#hcl">#</a> d3.<b>hcl</b>(<i>h</i>, <i>c</i>, <i>l</i>)<br>
<a name="hcl" href="#hcl">#</a> d3.<b>hcl</b>(<i>h</i>, <i>c</i>, <i>l</i>[, <i>opacity</i>])<br>
<a href="#hcl">#</a> d3.<b>hcl</b>(<i>specifier</i>)<br>

@@ -118,5 +133,5 @@ <a href="#hcl">#</a> d3.<b>hcl</b>(<i>color</i>)<br>

If *h*, *c* and *l* are specified, these represent the channel values of the returned color. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the HCL color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to HCL. (Colors already in the HCL color space skip the conversion to RGB, and colors in the Lab color space are converted directly to HCL.)
If *h*, *c* and *l* are specified, these represent the channel values of the returned color; an *opacity* may also be specified. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the HCL color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to HCL. (Colors already in the HCL color space skip the conversion to RGB, and colors in the Lab color space are converted directly to HCL.)
<a name="cubehelix" href="#cubehelix">#</a> d3.<b>cubehelix</b>(<i>h</i>, <i>s</i>, <i>l</i>)<br>
<a name="cubehelix" href="#cubehelix">#</a> d3.<b>cubehelix</b>(<i>h</i>, <i>s</i>, <i>l</i>[, <i>opacity</i>])<br>
<a href="#cubehelix">#</a> d3.<b>cubehelix</b>(<i>specifier</i>)<br>

@@ -127,2 +142,2 @@ <a href="#cubehelix">#</a> d3.<b>cubehelix</b>(<i>color</i>)<br>

If *h*, *s* and *l* are specified, these represent the channel values of the returned color. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the Cubehelix color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to Cubehelix. (Colors already in the Cubehelix color space skip the conversion to RGB.)
If *h*, *s* and *l* are specified, these represent the channel values of the returned color; an *opacity* may also be specified. If a CSS Color Module Level 3 *specifier* string is specified, it is parsed and then converted to the Cubehelix color space. See [color](#color) for examples. If a [*color*](#color) instance is specified, it is converted to the RGB color space using [*color*.rgb](#color_rgb) and then converted to Cubehelix. (Colors already in the Cubehelix color space skip the conversion to RGB.)

@@ -10,3 +10,6 @@ export function Color() {}

reRgbPercent = /^rgb\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/,
reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
reRgbaInteger = /^rgba\(\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+)\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/,
reRgbaPercent = /^rgba\(\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/,
reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/,
reHslaPercent = /^hsla\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)\s*\)$/;

@@ -178,6 +181,10 @@ var named = {

: (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
: (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3]) // rgb(255,0,0)
: (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100) // rgb(100%,0%,0%)
: (m = reHslPercent.exec(format)) ? new Hsl(m[1], m[2] / 100, m[3] / 100) // hsl(120,50%,50%)
: (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3]) // rgb(255, 0, 0)
: (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100) // rgb(100%, 0%, 0%)
: (m = reRgbaInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
: (m = reRgbaPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
: (m = reHslPercent.exec(format)) ? new Hsl(m[1], m[2] / 100, m[3] / 100) // hsl(120, 50%, 50%)
: (m = reHslaPercent.exec(format)) ? new Hsl(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
: named.hasOwnProperty(format) ? rgbn(named[format])
: format === "transparent" ? new Rgb(0, 0, 0, 0)
: null;

@@ -190,3 +197,3 @@ }

export function rgb(r, g, b) {
export function rgb(r, g, b, opacity) {
if (arguments.length === 1) {

@@ -196,2 +203,3 @@ if (!(r instanceof Color)) r = color(r);

r = r.rgb();
opacity = r.opacity;
b = r.b;

@@ -201,12 +209,13 @@ g = r.g;

} else {
r = g = b = NaN;
r = NaN;
}
}
return new Rgb(r, g, b);
return new Rgb(r, g, b, opacity);
}
export function Rgb(r, g, b) {
export function Rgb(r, g, b, opacity) {
this.r = +r;
this.g = +g;
this.b = +b;
this.opacity = opacity == null ? 1 : +opacity;
}

@@ -218,3 +227,3 @@

k = k == null ? brighter : Math.pow(brighter, k);
return new Rgb(this.r * k, this.g * k, this.b * k);
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
};

@@ -224,3 +233,3 @@

k = k == null ? darker : Math.pow(darker, k);
return new Rgb(this.r * k, this.g * k, this.b * k);
return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
};

@@ -235,18 +244,19 @@

&& (0 <= this.g && this.g <= 255)
&& (0 <= this.b && this.b <= 255);
&& (0 <= this.b && this.b <= 255)
&& (0 <= this.opacity && this.opacity <= 1);
};
_rgb.toString = function() {
var r = Math.round(this.r),
g = Math.round(this.g),
b = Math.round(this.b);
return "#"
+ (isNaN(r) || r <= 0 ? "00" : r < 16 ? "0" + r.toString(16) : r >= 255 ? "ff" : r.toString(16))
+ (isNaN(g) || g <= 0 ? "00" : g < 16 ? "0" + g.toString(16) : g >= 255 ? "ff" : g.toString(16))
+ (isNaN(b) || b <= 0 ? "00" : b < 16 ? "0" + b.toString(16) : b >= 255 ? "ff" : b.toString(16));
var a = this.opacity; a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
return (a === 1 ? "rgb(" : "rgba(")
+ Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", "
+ Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", "
+ Math.max(0, Math.min(255, Math.round(this.b) || 0))
+ (a === 1 ? ")" : ", " + a + ")");
};
export function hsl(h, s, l) {
export function hsl(h, s, l, opacity) {
if (arguments.length === 1) {
if (h instanceof Hsl) {
opacity = h.opacity;
l = h.l;

@@ -260,2 +270,3 @@ s = h.s;

h = h.rgb();
opacity = h.opacity;
var r = h.r / 255,

@@ -279,13 +290,14 @@ g = h.g / 255,

} else {
h = s = l = NaN;
h = NaN;
}
}
}
return new Hsl(h, s, l);
return new Hsl(h, s, l, opacity);
}
export function Hsl(h, s, l) {
function Hsl(h, s, l, opacity) {
this.h = +h;
this.s = +s;
this.l = +l;
this.opacity = opacity == null ? 1 : +opacity;
}

@@ -297,3 +309,3 @@

k = k == null ? brighter : Math.pow(brighter, k);
return new Hsl(this.h, this.s, this.l * k);
return new Hsl(this.h, this.s, this.l * k, this.opacity);
};

@@ -303,3 +315,3 @@

k = k == null ? darker : Math.pow(darker, k);
return new Hsl(this.h, this.s, this.l * k);
return new Hsl(this.h, this.s, this.l * k, this.opacity);
};

@@ -316,3 +328,4 @@

hsl2rgb(h, m1, m2),
hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2)
hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2),
this.opacity
);

@@ -323,3 +336,4 @@ };

return (0 <= this.s && this.s <= 1 || isNaN(this.s))
&& (0 <= this.l && this.l <= 1);
&& (0 <= this.l && this.l <= 1)
&& (0 <= this.opacity && this.opacity <= 1);
};

@@ -326,0 +340,0 @@

@@ -13,5 +13,6 @@ import {Color, rgb, Rgb, darker, brighter} from "./color";

export default function cubehelix(h, s, l) {
export default function cubehelix(h, s, l, opacity) {
if (arguments.length === 1) {
if (h instanceof Cubehelix) {
opacity = h.opacity;
l = h.l;

@@ -22,2 +23,3 @@ s = h.s;

if (!(h instanceof Rgb)) h = rgb(h);
opacity = h.opacity;
var r = h.r / 255, g = h.g / 255, b = h.b / 255;

@@ -31,9 +33,10 @@ l = (BC_DA * b + ED * r - EB * g) / (BC_DA + ED - EB);

}
return new Cubehelix(h, s, l);
return new Cubehelix(h, s, l, opacity);
}
export function Cubehelix(h, s, l) {
export function Cubehelix(h, s, l, opacity) {
this.h = +h;
this.s = +s;
this.l = +l;
this.opacity = opacity == null ? 1 : +opacity;
}

@@ -45,3 +48,3 @@

k = k == null ? brighter : Math.pow(brighter, k);
return new Cubehelix(this.h, this.s, this.l * k);
return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
};

@@ -51,3 +54,3 @@

k = k == null ? darker : Math.pow(darker, k);
return new Cubehelix(this.h, this.s, this.l * k);
return new Cubehelix(this.h, this.s, this.l * k, this.opacity);
};

@@ -64,4 +67,5 @@

255 * (l + a * (C * cosh + D * sinh)),
255 * (l + a * (E * cosh))
255 * (l + a * (E * cosh)),
this.opacity
);
};

@@ -13,5 +13,6 @@ import {Color, rgb, Rgb} from "./color";

export default function lab(l, a, b) {
export default function lab(l, a, b, opacity) {
if (arguments.length === 1) {
if (l instanceof Lab) {
opacity = l.opacity;
b = l.b;

@@ -22,2 +23,3 @@ a = l.a;

var h = l.h * deg2rad;
opacity = l.opacity;
b = Math.sin(h) * l.c;

@@ -28,2 +30,3 @@ a = Math.cos(h) * l.c;

if (!(l instanceof Rgb)) l = rgb(l);
opacity = l.opacity;
b = rgb2xyz(l.r);

@@ -40,9 +43,10 @@ a = rgb2xyz(l.g);

}
return new Lab(l, a, b);
return new Lab(l, a, b, opacity);
}
export function Lab(l, a, b) {
export function Lab(l, a, b, opacity) {
this.l = +l;
this.a = +a;
this.b = +b;
this.opacity = opacity == null ? 1 : +opacity;
}

@@ -53,7 +57,7 @@

_lab.brighter = function(k) {
return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b);
return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
};
_lab.darker = function(k) {
return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b);
return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b, this.opacity);
};

@@ -71,3 +75,4 @@

xyz2rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z)
xyz2rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
this.opacity
);

@@ -92,5 +97,6 @@ };

export function hcl(h, c, l) {
export function hcl(h, c, l, opacity) {
if (arguments.length === 1) {
if (h instanceof Hcl) {
opacity = h.opacity;
l = h.l;

@@ -101,2 +107,3 @@ c = h.c;

if (!(h instanceof Lab)) h = lab(h);
opacity = h.opacity;
l = h.l;

@@ -108,9 +115,10 @@ c = Math.sqrt(h.a * h.a + h.b * h.b);

}
return new Hcl(h, c, l);
return new Hcl(h, c, l, opacity);
}
export function Hcl(h, c, l) {
export function Hcl(h, c, l, opacity) {
this.h = +h;
this.c = +c;
this.l = +l;
this.opacity = opacity == null ? 1 : +opacity;
}

@@ -121,7 +129,7 @@

_hcl.brighter = function(k) {
return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k));
return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k), this.opacity);
};
_hcl.darker = function(k) {
return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k));
return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k), this.opacity);
};

@@ -128,0 +136,0 @@

Sorry, the diff of this file is not supported yet

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