forked from d3/d3.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3-color.v0.3.min.js
1 lines (1 loc) · 7.98 KB
/
d3-color.v0.3.min.js
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});