Socket
Socket
Sign inDemoInstall

d3-color

Package Overview
Dependencies
0
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.2 to 0.3.3

src/math.js

2

build/bundle.js

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

var version = "0.3.2"; export * from "../index"; export {version};
var version = "0.3.3"; export * from "../index"; export {version};

@@ -9,2 +9,5 @@ (function (global, factory) {

var darker = 0.7;
var brighter = 1 / darker;
var reHex3 = /^#([0-9a-f]{3})$/;

@@ -15,27 +18,2 @@ var reHex6 = /^#([0-9a-f]{6})$/;

var reHslPercent = /^hsl\(\s*([-+]?\d+(?:\.\d+)?)\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*,\s*([-+]?\d+(?:\.\d+)?)%\s*\)$/;
color.prototype = Color.prototype = {
displayable: function() {
return this.rgb().displayable();
},
toString: function() {
return this.rgb() + "";
}
};
function color(format) {
var m;
format = (format + "").trim().toLowerCase();
return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf))) // #f00
: (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
: (m = reRgbInteger.exec(format)) ? rgb(m[1], m[2], m[3]) // rgb(255,0,0)
: (m = reRgbPercent.exec(format)) ? rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100) // rgb(100%,0%,0%)
: (m = reHslPercent.exec(format)) ? hsl(m[1], m[2] / 100, m[3] / 100) // hsl(120,50%,50%)
: named.hasOwnProperty(format) ? rgbn(named[format])
: null;
};
function rgbn(n) {
return rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff);
}
var named = {

@@ -192,5 +170,27 @@ aliceblue: 0xf0f8ff,

var darker = .7;
var brighter = 1 / darker;
color.prototype = Color.prototype = {
displayable: function() {
return this.rgb().displayable();
},
toString: function() {
return this.rgb() + "";
}
};
function color(format) {
var m;
format = (format + "").trim().toLowerCase();
return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf))) // #f00
: (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%)
: named.hasOwnProperty(format) ? rgbn(named[format])
: null;
};
function rgbn(n) {
return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff);
}
function rgb(r, g, b) {

@@ -217,5 +217,5 @@ if (arguments.length === 1) {

var prototype = rgb.prototype = Rgb.prototype = new Color;
var _rgb = rgb.prototype = Rgb.prototype = new Color;
prototype.brighter = function(k) {
_rgb.brighter = function(k) {
k = k == null ? brighter : Math.pow(brighter, k);

@@ -225,3 +225,3 @@ return new Rgb(this.r * k, this.g * k, this.b * k);

prototype.darker = function(k) {
_rgb.darker = function(k) {
k = k == null ? darker : Math.pow(darker, k);

@@ -231,7 +231,7 @@ return new Rgb(this.r * k, this.g * k, this.b * k);

prototype.rgb = function() {
_rgb.rgb = function() {
return this;
};
prototype.displayable = function() {
_rgb.displayable = function() {
return (0 <= this.r && this.r <= 255)

@@ -242,3 +242,3 @@ && (0 <= this.g && this.g <= 255)

prototype.toString = function() {
_rgb.toString = function() {
var r = Math.round(this.r),

@@ -272,3 +272,3 @@ g = Math.round(this.g),

if (range) {
s = l < .5 ? range / (max + min) : range / (2 - max - min);
s = l < 0.5 ? range / (max + min) : range / (2 - max - min);
if (r === max) h = (g - b) / range + (g < b) * 6;

@@ -296,5 +296,5 @@ else if (g === max) h = (b - r) / range + 2;

var prototype$1 = hsl.prototype = Hsl.prototype = new Color;
var _hsl = hsl.prototype = Hsl.prototype = new Color;
prototype$1.brighter = function(k) {
_hsl.brighter = function(k) {
k = k == null ? brighter : Math.pow(brighter, k);

@@ -304,3 +304,3 @@ return new Hsl(this.h, this.s, this.l * k);

prototype$1.darker = function(k) {
_hsl.darker = function(k) {
k = k == null ? darker : Math.pow(darker, k);

@@ -310,7 +310,7 @@ return new Hsl(this.h, this.s, this.l * k);

prototype$1.rgb = function() {
_hsl.rgb = function() {
var h = this.h % 360 + (this.h < 0) * 360,
s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
l = this.l,
m2 = l + (l < .5 ? l : 1 - l) * s,
m2 = l + (l < 0.5 ? l : 1 - l) * s,
m1 = 2 * l - m2;

@@ -324,3 +324,3 @@ return new Rgb(

prototype$1.displayable = function() {
_hsl.displayable = function() {
return (0 <= this.s && this.s <= 1 || isNaN(this.s))

@@ -341,41 +341,3 @@ && (0 <= this.l && this.l <= 1);

function hcl(h, c, l) {
if (arguments.length === 1) {
if (h instanceof Hcl) {
l = h.l;
c = h.c;
h = h.h;
} else {
if (!(h instanceof Lab)) h = lab(h);
l = h.l;
c = Math.sqrt(h.a * h.a + h.b * h.b);
h = Math.atan2(h.b, h.a) * rad2deg;
if (h < 0) h += 360;
}
}
return new Hcl(h, c, l);
};
function Hcl(h, c, l) {
this.h = +h;
this.c = +c;
this.l = +l;
};
var prototype$3 = hcl.prototype = Hcl.prototype = new Color;
prototype$3.brighter = function(k) {
return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k));
};
prototype$3.darker = function(k) {
return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k));
};
prototype$3.rgb = function() {
return lab(this).rgb();
};
var Kn = 18;
var Xn = 0.950470;

@@ -421,13 +383,13 @@ var Yn = 1;

var prototype$2 = lab.prototype = Lab.prototype = new Color;
var _lab = lab.prototype = Lab.prototype = new Color;
prototype$2.brighter = function(k) {
_lab.brighter = function(k) {
return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b);
};
prototype$2.darker = function(k) {
_lab.darker = function(k) {
return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b);
};
prototype$2.rgb = function() {
_lab.rgb = function() {
var y = (this.l + 16) / 116,

@@ -462,2 +424,39 @@ x = isNaN(this.a) ? y : y + this.a / 500,

function hcl(h, c, l) {
if (arguments.length === 1) {
if (h instanceof Hcl) {
l = h.l;
c = h.c;
h = h.h;
} else {
if (!(h instanceof Lab)) h = lab(h);
l = h.l;
c = Math.sqrt(h.a * h.a + h.b * h.b);
h = Math.atan2(h.b, h.a) * rad2deg;
if (h < 0) h += 360;
}
}
return new Hcl(h, c, l);
};
function Hcl(h, c, l) {
this.h = +h;
this.c = +c;
this.l = +l;
};
var _hcl = hcl.prototype = Hcl.prototype = new Color;
_hcl.brighter = function(k) {
return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k));
};
_hcl.darker = function(k) {
return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k));
};
_hcl.rgb = function() {
return lab(this).rgb();
};
var A = -0.14861;

@@ -496,5 +495,5 @@ var B = +1.78277;

var prototype$4 = cubehelix.prototype = Cubehelix.prototype = new Color;
var _cubehelix = cubehelix.prototype = Cubehelix.prototype = new Color;
prototype$4.brighter = function(k) {
_cubehelix.brighter = function(k) {
k = k == null ? brighter : Math.pow(brighter, k);

@@ -504,3 +503,3 @@ return new Cubehelix(this.h, this.s, this.l * k);

prototype$4.darker = function(k) {
_cubehelix.darker = function(k) {
k = k == null ? darker : Math.pow(darker, k);

@@ -510,3 +509,3 @@ return new Cubehelix(this.h, this.s, this.l * k);

prototype$4.rgb = function() {
_cubehelix.rgb = function() {
var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,

@@ -524,3 +523,3 @@ l = +this.l,

var version = "0.3.2";
var version = "0.3.3";

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

@@ -1,6 +0,3 @@

export {default as color} from "./src/color";
export {default as rgb} from "./src/rgb";
export {default as hsl} from "./src/hsl";
export {default as lab} from "./src/lab";
export {default as hcl} from "./src/hcl";
export {default as color, rgb, hsl} from "./src/color";
export {default as lab, hcl} from "./src/lab";
export {default as cubehelix} from "./src/cubehelix";
{
"name": "d3-color",
"version": "0.3.2",
"version": "0.3.3",
"description": "Color spaces! RGB, HSL, Cubehelix, Lab and HCL (Lch).",

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

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

import rgb from "./rgb";
import hsl from "./hsl";
export function Color() {};
export var darker = 0.7;
export var brighter = 1 / darker;
var reHex3 = /^#([0-9a-f]{3})$/,

@@ -12,27 +12,2 @@ reHex6 = /^#([0-9a-f]{6})$/,

color.prototype = Color.prototype = {
displayable: function() {
return this.rgb().displayable();
},
toString: function() {
return this.rgb() + "";
}
};
export default function color(format) {
var m;
format = (format + "").trim().toLowerCase();
return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf))) // #f00
: (m = reHex6.exec(format)) ? rgbn(parseInt(m[1], 16)) // #ff0000
: (m = reRgbInteger.exec(format)) ? rgb(m[1], m[2], m[3]) // rgb(255,0,0)
: (m = reRgbPercent.exec(format)) ? rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100) // rgb(100%,0%,0%)
: (m = reHslPercent.exec(format)) ? hsl(m[1], m[2] / 100, m[3] / 100) // hsl(120,50%,50%)
: named.hasOwnProperty(format) ? rgbn(named[format])
: null;
};
function rgbn(n) {
return rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff);
}
var named = {

@@ -188,1 +163,159 @@ aliceblue: 0xf0f8ff,

};
color.prototype = Color.prototype = {
displayable: function() {
return this.rgb().displayable();
},
toString: function() {
return this.rgb() + "";
}
};
export default function color(format) {
var m;
format = (format + "").trim().toLowerCase();
return (m = reHex3.exec(format)) ? (m = parseInt(m[1], 16), new Rgb((m >> 8 & 0xf) | (m >> 4 & 0x0f0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf))) // #f00
: (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%)
: named.hasOwnProperty(format) ? rgbn(named[format])
: null;
};
function rgbn(n) {
return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff);
}
export function rgb(r, g, b) {
if (arguments.length === 1) {
if (!(r instanceof Color)) r = color(r);
if (r) {
r = r.rgb();
b = r.b;
g = r.g;
r = r.r;
} else {
r = g = b = NaN;
}
}
return new Rgb(r, g, b);
};
export function Rgb(r, g, b) {
this.r = +r;
this.g = +g;
this.b = +b;
};
var _rgb = rgb.prototype = Rgb.prototype = new Color;
_rgb.brighter = function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Rgb(this.r * k, this.g * k, this.b * k);
};
_rgb.darker = function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Rgb(this.r * k, this.g * k, this.b * k);
};
_rgb.rgb = function() {
return this;
};
_rgb.displayable = function() {
return (0 <= this.r && this.r <= 255)
&& (0 <= this.g && this.g <= 255)
&& (0 <= this.b && this.b <= 255);
};
_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));
};
export function hsl(h, s, l) {
if (arguments.length === 1) {
if (h instanceof Hsl) {
l = h.l;
s = h.s;
h = h.h;
} else {
if (!(h instanceof Color)) h = color(h);
if (h) {
if (h instanceof Hsl) return h;
h = h.rgb();
var r = h.r / 255,
g = h.g / 255,
b = h.b / 255,
min = Math.min(r, g, b),
max = Math.max(r, g, b),
range = max - min;
l = (max + min) / 2;
if (range) {
s = l < 0.5 ? range / (max + min) : range / (2 - max - min);
if (r === max) h = (g - b) / range + (g < b) * 6;
else if (g === max) h = (b - r) / range + 2;
else h = (r - g) / range + 4;
h *= 60;
} else {
h = NaN;
s = l > 0 && l < 1 ? 0 : h;
}
} else {
h = s = l = NaN;
}
}
}
return new Hsl(h, s, l);
};
export function Hsl(h, s, l) {
this.h = +h;
this.s = +s;
this.l = +l;
};
var _hsl = hsl.prototype = Hsl.prototype = new Color;
_hsl.brighter = function(k) {
k = k == null ? brighter : Math.pow(brighter, k);
return new Hsl(this.h, this.s, this.l * k);
};
_hsl.darker = function(k) {
k = k == null ? darker : Math.pow(darker, k);
return new Hsl(this.h, this.s, this.l * k);
};
_hsl.rgb = function() {
var h = this.h % 360 + (this.h < 0) * 360,
s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
l = this.l,
m2 = l + (l < 0.5 ? l : 1 - l) * s,
m1 = 2 * l - m2;
return new Rgb(
hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2),
hsl2rgb(h, m1, m2),
hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2)
);
};
_hsl.displayable = function() {
return (0 <= this.s && this.s <= 1 || isNaN(this.s))
&& (0 <= this.l && this.l <= 1);
};
/* From FvD 13.37, CSS Color Module Level 3 */
function hsl2rgb(h, m1, m2) {
return (h < 60 ? m1 + (m2 - m1) * h / 60
: h < 180 ? m2
: h < 240 ? m1 + (m2 - m1) * (240 - h) / 60
: m1) * 255;
}

@@ -1,4 +0,3 @@

import {default as color, Color} from "./color";
import {default as rgb, Rgb, darker, brighter} from "./rgb";
import {deg2rad, rad2deg} from "./hcl";
import {Color, rgb, Rgb, darker, brighter} from "./color";
import {deg2rad, rad2deg} from "./math";

@@ -39,5 +38,5 @@ var A = -0.14861,

var prototype = cubehelix.prototype = Cubehelix.prototype = new Color;
var _cubehelix = cubehelix.prototype = Cubehelix.prototype = new Color;
prototype.brighter = function(k) {
_cubehelix.brighter = function(k) {
k = k == null ? brighter : Math.pow(brighter, k);

@@ -47,3 +46,3 @@ return new Cubehelix(this.h, this.s, this.l * k);

prototype.darker = function(k) {
_cubehelix.darker = function(k) {
k = k == null ? darker : Math.pow(darker, k);

@@ -53,3 +52,3 @@ return new Cubehelix(this.h, this.s, this.l * k);

prototype.rgb = function() {
_cubehelix.rgb = function() {
var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad,

@@ -56,0 +55,0 @@ l = +this.l,

@@ -1,8 +0,6 @@

import {default as color, Color} from "./color";
import {default as rgb, Rgb} from "./rgb";
import {default as hcl, Hcl, deg2rad} from "./hcl";
import {Color, rgb, Rgb} from "./color";
import {deg2rad, rad2deg} from "./math";
export var Kn = 18;
var Xn = 0.950470, // D65 standard referent
var Kn = 18,
Xn = 0.950470, // D65 standard referent
Yn = 1,

@@ -48,13 +46,13 @@ Zn = 1.088830,

var prototype = lab.prototype = Lab.prototype = new Color;
var _lab = lab.prototype = Lab.prototype = new Color;
prototype.brighter = function(k) {
_lab.brighter = function(k) {
return new Lab(this.l + Kn * (k == null ? 1 : k), this.a, this.b);
};
prototype.darker = function(k) {
_lab.darker = function(k) {
return new Lab(this.l - Kn * (k == null ? 1 : k), this.a, this.b);
};
prototype.rgb = function() {
_lab.rgb = function() {
var y = (this.l + 16) / 116,

@@ -88,1 +86,38 @@ x = isNaN(this.a) ? y : y + this.a / 500,

}
export function hcl(h, c, l) {
if (arguments.length === 1) {
if (h instanceof Hcl) {
l = h.l;
c = h.c;
h = h.h;
} else {
if (!(h instanceof Lab)) h = lab(h);
l = h.l;
c = Math.sqrt(h.a * h.a + h.b * h.b);
h = Math.atan2(h.b, h.a) * rad2deg;
if (h < 0) h += 360;
}
}
return new Hcl(h, c, l);
};
export function Hcl(h, c, l) {
this.h = +h;
this.c = +c;
this.l = +l;
};
var _hcl = hcl.prototype = Hcl.prototype = new Color;
_hcl.brighter = function(k) {
return new Hcl(this.h, this.c, this.l + Kn * (k == null ? 1 : k));
};
_hcl.darker = function(k) {
return new Hcl(this.h, this.c, this.l - Kn * (k == null ? 1 : k));
};
_hcl.rgb = function() {
return lab(this).rgb();
};
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc