Comparing version 0.2.45 to 0.2.46
@@ -252,2 +252,51 @@ (function (global, factory) { | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
// From: https://github.com/d3/d3-format/issues/32 | ||
var r = function r(value, precision) { | ||
return Math.round(value * (precision = Math.pow(10, precision))) / precision; | ||
}; | ||
function round(value) { | ||
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; | ||
if (value === undefined) { | ||
return undefined; | ||
} | ||
if (typeof value === 'number') { | ||
return r(value, precision); | ||
} | ||
if (typeof value === 'string') { | ||
return value; | ||
} | ||
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { | ||
return Object.keys(value).reduce(function (o, k) { | ||
return o[k] = round(value[k]), o; | ||
}, {}); | ||
} | ||
} | ||
/* | ||
@@ -264,8 +313,11 @@ References: | ||
// Fixes achromatic colors having a _slight_ chroma due to floating-point errors | ||
// and approximated computations in sRGB <-> CIELab. | ||
var c = round(Math.sqrt(a * a + b * b), 4); | ||
var res = { | ||
mode: 'lch', | ||
l: l, | ||
c: Math.sqrt(a * a + b * b), | ||
h: normalizeHue(Math.atan2(b, a) * 180 / Math.PI) | ||
c: c | ||
}; | ||
if (c) res.h = normalizeHue(Math.atan2(b, a) * 180 / Math.PI); | ||
if (alpha !== undefined) res.alpha = alpha; | ||
@@ -289,4 +341,4 @@ return res; | ||
l: l, | ||
a: c * Math.cos(h / 180 * Math.PI), | ||
b: c * Math.sin(h / 180 * Math.PI) | ||
a: c === 0 ? 0 : c * Math.cos(h / 180 * Math.PI), | ||
b: c === 0 ? 0 : c * Math.sin(h / 180 * Math.PI) | ||
}; | ||
@@ -914,22 +966,2 @@ if (alpha !== undefined) res.alpha = alpha; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var prepare = (function (color, mode) { | ||
@@ -971,31 +1003,2 @@ return (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color; | ||
// From: https://github.com/d3/d3-format/issues/32 | ||
var r = function r(value, precision) { | ||
return Math.round(value * (precision = Math.pow(10, precision))) / precision; | ||
}; | ||
function round(value) { | ||
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; | ||
if (value === undefined) { | ||
return undefined; | ||
} | ||
if (typeof value === 'number') { | ||
return r(value, precision); | ||
} | ||
if (typeof value === 'string') { | ||
return value; | ||
} | ||
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { | ||
return Object.keys(value).reduce(function (o, k) { | ||
return o[k] = round(value[k]), o; | ||
}, {}); | ||
} | ||
} | ||
var clamp = function clamp(v) { | ||
@@ -1002,0 +1005,0 @@ return Math.round(Math.max(0, Math.min(v, 1)) * 255); |
@@ -1,1 +0,1 @@ | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):r.culori=e()}(this,function(){"use strict";var r=function(r){return(r%=360)<0?r+360:r};function e(e){var a=e.h,n=e.s,t=e.v,o=e.alpha;a=r(a);var i=Math.abs(a/60%2-1),l=void 0;switch(Math.floor(a/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)};break;default:l={r:t*(1-n),g:t*(1-n),b:t*(1-n)}}return l.mode="rgb",void 0!==o&&(l.alpha=o),l}function a(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o=Math.max(e,a,n),i=Math.min(e,a,n),l={mode:"hsv",s:0===o?0:1-i/o,v:o};return o-i!=0&&(l.h=60*(o===e?(a-n)/(o-i)+6*(a<n):o===a?(n-e)/(o-i)+2:(e-a)/(o-i)+4)),void 0!==t&&(l.alpha=t),l}var n=function(e){var a=e.l,n=e.a,t=e.b,o=e.alpha,i={mode:"lch",l:a,c:Math.sqrt(n*n+t*t),h:r(180*Math.atan2(t,n)/Math.PI)};return void 0!==o&&(i.alpha=o),i},t=function(r){var e=r.l,a=r.c,n=r.h,t=r.alpha,o={mode:"lab",l:e,a:a*Math.cos(n/180*Math.PI),b:a*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(r){return Math.pow(r,3)>i?Math.pow(r,3):(116*r-16)/o},h=function(r){return r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r},u=function(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o={mode:"rgb",r:h(e),g:h(a),b:h(n)};return void 0!==t&&(o.alpha=t),o},s=function(r){var e,a,n,t,o,i=function(r){var e=r.x,a=r.y,n=r.z;return u({r:3.2404542*e-1.5371385*a-.4985314*n,g:-.969266*e+1.8760108*a+.041556*n,b:.0556434*e-.2040259*a+1.0572252*n})}((a=(e=r).l,n=e.a,o=(t=(a+16)/116)-e.b/200,{x:.95047*l(n/500+t),y:1*l(t),z:1.08883*l(o)}));return i.mode="rgb",void 0!==r.alpha&&(i.alpha=r.alpha),i},d=function(r){return r<.04045?r/12.92:Math.pow((r+.055)/1.055,2.4)},b=function(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o={mode:"lrgb",r:d(e),g:d(a),b:d(n)};return void 0!==t&&(o.alpha=t),o},g=Math.pow(29,3)/Math.pow(3,3),c=Math.pow(6,3)/Math.pow(29,3),p=function(r){return r>c?Math.cbrt(r):(g*r+16)/116},v=function(r){var e,a,n,t,o,i,l=(e=function(r){var e=b(r),a=e.r,n=e.g,t=e.b;return{x:.4124564*a+.3575761*n+.1804375*t,y:.2126729*a+.7151522*n+.072175*t,z:.0193339*a+.119192*n+.9503041*t}}(r),a=e.x,n=e.y,t=e.z,o=p(a/.95047),{l:116*(i=p(n/1))-16,a:500*(o-i),b:200*(i-p(t/1.08883))});return l.mode="lab",void 0!==r.alpha&&(l.alpha=r.alpha),l},f={hsi:{rgb:function(e){var a=e.h,n=e.s,t=e.i,o=e.alpha;a=r(a);var i=Math.abs(a/60%2-1),l=void 0;switch(Math.floor(a/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))};break;default:l={r:t*(1-n),g:t*(1-n),b:t*(1-n)}}return l.mode="rgb",void 0!==o&&(l.alpha=o),l}},hsl:{rgb:function(e){var a=e.h,n=e.s,t=e.l,o=e.alpha;a=r(a);var i=t+n*(t<.5?t:1-t),l=i-2*(i-t)*Math.abs(a/60%2-1),h=void 0;switch(Math.floor(a/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};break;default:h={r:2*t-i,g:2*t-i,b:2*t-i}}return h.mode="rgb",void 0!==o&&(h.alpha=o),h}},hsv:{rgb:e},hwb:{rgb:function(r){var a=r.h,n=r.w,t=r.b,o=r.alpha;if(n+t>1){var i=n+t;n/=i,t/=i}return e({h:a,s:1===t?1:1-n/(1-t),v:1-t,alpha:o})}},lab:{lch:n,rgb:s},lch:{lab:t,rgb:function(r){return s(t(r))}},rgb:{hsi:function(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o=Math.max(e,a,n),i=Math.min(e,a,n),l={mode:"hsi",s:e+a+n===0?0:1-3*i/(e+a+n),i:(e+a+n)/3};return o-i!=0&&(l.h=60*(o===e?(a-n)/(o-i)+6*(a<n):o===a?(n-e)/(o-i)+2:(e-a)/(o-i)+4)),void 0!==t&&(l.alpha=t),l},hsl:function(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o=Math.max(e,a,n),i=Math.min(e,a,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===e?(a-n)/(o-i)+6*(a<n):o===a?(n-e)/(o-i)+2:(e-a)/(o-i)+4)),void 0!==t&&(l.alpha=t),l},hsv:a,hwb:function(r){var e=a(r);if(void 0!==e){var n={mode:"hwb",w:(1-e.s)*e.v,b:1-e.v};return void 0!==e.h&&(n.h=e.h),void 0!==e.alpha&&(n.alpha=e.alpha),n}},lab:v,lch:function(r){return n(v(r))},lrgb:b},lrgb:{rgb:u}},m=function(r,e){return void 0!==r?r.mode===e?r:f[r.mode][e]?f[r.mode][e](r):"rgb"===mode?f[r.mode].rgb(r):f.rgb[e](f[r.mode].rgb(r)):void 0},w=function(r,e){if("number"==typeof r)return 3===e?{mode:"rgb",r:(r>>8&15|r>>4&240)/255,g:(r>>4&15|240&r)/255,b:(15&r|r<<4&240)/255}:4===e?{mode:"rgb",r:(r>>12&15|r>>8&240)/255,g:(r>>8&15|r>>4&240)/255,b:(r>>4&15|240&r)/255,alpha:(15&r|r<<4&240)/255}:6===e?{mode:"rgb",r:(r>>16&255)/255,g:(r>>8&255)/255,b:(255&r)/255}:8===e?{mode:"rgb",r:(r>>24&255)/255,g:(r>>16&255)/255,b:(r>>8&255)/255,alpha:(255&r)/255}:void 0},y={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},k=function(r){return"string"==typeof r&&w(y[r.toLowerCase()],6)||void 0},M=(/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/+"").replace(/^\/|\/$/g,""),x=M+"%",$="(?:"+M+"%|"+M+")",E="(?:"+M+"(deg|grad|rad|turn)|"+M+")",R="\\s*,\\s*",j="\\s+",q=new RegExp("^rgba?\\(\\s*"+M+R+M+R+M+"\\s*(?:,\\s*"+$+"\\s*)?\\)$"),O=new RegExp("^rgba?\\(\\s*"+x+R+x+R+x+"\\s*(?:,\\s*"+$+"\\s*)?\\)$"),z=new RegExp("^rgba?\\(\\s*"+M+j+M+j+M+"\\s*(?:\\/\\s*"+$+"\\s*)?\\)$"),S=new RegExp("^rgba?\\(\\s*"+x+j+x+j+x+"\\s*(?:\\/\\s*"+$+"\\s*)?\\)$"),I=new RegExp("^hsla?\\(\\s*"+E+R+x+R+x+"\\s*(?:,\\s*"+$+"\\s*)?\\)$"),P=new RegExp("^hsla?\\(\\s*"+E+j+x+j+x+"\\s*(?:\\/\\s*"+$+"\\s*)?\\)$"),H=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,N=new RegExp("^hwb\\(\\s*"+E+j+x+j+x+"\\s*(?:\\/\\s*"+$+"\\s*)?\\)$"),C=new RegExp("^lab\\(\\s*"+M+j+M+j+M+"\\s*(?:\\/\\s*"+$+"\\s*)?\\)$"),L=new RegExp("^lch\\(\\s*"+M+j+M+j+E+"\\s*(?:\\/\\s*"+$+"\\s*)?\\)$"),A=new RegExp("^gray\\(\\s*"+M+"()()\\s*(?:\\/\\s*"+$+"\\s*)?\\)$"),B=function(r){var e;return(e=r.match(H))?w(parseInt(e[1],16),e[1].length):void 0},D=function(r){var e=void 0,a=void 0;if(e=r.match(q)||r.match(z))a={mode:"rgb",r:e[1]/255,g:e[2]/255,b:e[3]/255};else{if(!(e=r.match(O)||r.match(S)))return;a={mode:"rgb",r:e[1]/100,g:e[2]/100,b:e[3]/100}}return void 0!==e[4]?a.alpha=e[4]/100:void 0!==e[5]&&(a.alpha=+e[5]),a},F=function(r,e){switch(e){case"deg":return+r;case"rad":return r/Math.PI*180;case"grad":return r/10*9;case"turn":return 360*r}},G=function(r){if("string"==typeof r){var e=r.match(I)||r.match(P);if(e){var a={mode:"hsl",h:void 0===e[3]?F(e[1],e[2]):+e[3],s:Math.min(Math.max(0,e[4]/100),1),l:Math.min(Math.max(0,e[5]/100),1)};return void 0!==e[6]?a.alpha=e[6]/100:void 0!==e[7]&&(a.alpha=e[7]/255),a}}},J=function(r){if("string"==typeof r){var e=r.match(N);if(e){var a={mode:"hwb",h:void 0===e[3]?F(e[1],e[2]):+e[3],w:e[4]/100,b:e[5]/100};if(a.w+a.b>1){var n=a.w+a.b;a.w/=n,a.b/=n}return void 0!==e[6]?a.alpha=e[6]/100:void 0!==e[7]&&(a.alpha=e[7]/255),a}}},K=function(r){return B(r)||D(r)||G(r)||k(r)||("transparent"===r?w(0,8):void 0)||J(r)||function(r){var e=void 0,a=void 0;if(e=r.match(C))a={mode:"lab",l:+e[1],a:+e[2],b:+e[3]};else{if(!(e=r.match(A)))return;a={mode:"lab",l:+e[1],a:0,b:0}}return void 0!==e[4]?a.alpha=e[4]/100:void 0!==e[5]&&(a.alpha=+e[5]),a}(r)||function(r){var e=r.match(L);if(e){var a={mode:"lch",l:+e[1],c:Math.max(0,+e[2]),h:void 0===e[5]?F(e[3],e[4]):+e[5]};return void 0!==e[6]?a.alpha=e[6]/100:void 0!==e[7]&&(a.alpha=+e[7]),a}}(r)},Q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},T=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(r[n]=a[n])}return r},U=function(r,e){return"object"!==(void 0===r?"undefined":Q(r))?K(r):void 0===r.mode?T({},r,{mode:e}):r},V=function(r){return m(U(r,"rgb"),"rgb")},W=function(r,e){return Math.round(r*(e=Math.pow(10,e)))/e};function X(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(void 0!==r)return"number"==typeof r?W(r,e):"string"==typeof r?r:"object"===(void 0===r?"undefined":Q(r))?Object.keys(r).reduce(function(e,a){return e[a]=X(r[a]),e},{}):void 0}var Y=function(r){return Math.round(255*Math.max(0,Math.min(r,1)))},Z={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"],lrgb:["r","g","b","alpha"]},_=function(r,e){var a=Z[r.mode].reduce(function(a,n){var t=e(n,r[n]);return void 0!==t&&(a[n]=t),a},{});return a.mode=r.mode,a},rr=function(r,e,a){return r+a*(e-r)},er=function(r){return V(r)},ar=Object.freeze({hsl:function(r){return m(U(r,"hsl"),"hsl")},hsv:function(r){return m(U(r,"hsv"),"hsv")},hsi:function(r){return m(U(r,"hsi"),"hsi")},hwb:function(r){return m(U(r,"hwb"),"hwb")},rgb:V,lab:function(r){return m(U(r,"lab"),"lab")},lch:function(r){return m(U(r,"lch"),"lch")},lrgb:function(r){return m(U(r,"lrgb"),"lrgb")},css:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb",a=V(r),n=Y(a.r),t=Y(a.g),o=Y(a.b);return"hex"===e?"#"+(1<<24|n<<16|t<<8|o).toString(16).slice(1):"rgb"===e?void 0===a.alpha||1===a.alpha?"rgb("+n+", "+t+", "+o+")":"rgba("+n+", "+t+", "+o+", "+X(a.alpha,2)+")":void 0},convert:m,prepare:U,round:X,parse:K,parseNumber:w,parseNamed:k,parseHex:B,parseRgb:D,parseHsl:G,parseHwb:J,named:y,map:_,interpolate:function(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb";if(!(e.length<2)){var n=e.map(function(r){return m(U(r,a),a)});return function(e){if(1===(e=Math.min(Math.max(0,e),1)))return Object.assign({},n[n.length-1]);var t=e*(n.length-1),o=Math.floor(t),i=n[o],l=n[o+1],h=t-o;return _({mode:a},function(e){return("h"===e?function(e,a,n){return void 0!==e&&void 0!==a?(e=r(e),a=r(a),Math.abs(a-e)>180?r(rr(e,a-360*Math.sign(a-e),n)):rr(e,a,n)):void 0===e?a:e}:"alpha"===e?function(r,e,a){if(!(void 0===r&&void 0===e||void 0===r&&0===a||void 0===e&&1===a))return rr(void 0===r?1:r,void 0===e?1:e,a)}:function(r,e,a){return void 0!==r&&void 0!==e?rr(r,e,a):void 0===r?e:r})(i[e],l[e],h)})}}},swatches:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;if(e<2)return e<1?[]:[r(.5)];for(var a=[],n=0;n<e;n++)a.push(r(n/(e-1)));return a},default:er});return Object.assign(er,ar),er}); | ||
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):r.culori=e()}(this,function(){"use strict";var r=function(r){return(r%=360)<0?r+360:r};function e(e){var a=e.h,n=e.s,t=e.v,o=e.alpha;a=r(a);var i=Math.abs(a/60%2-1),l=void 0;switch(Math.floor(a/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)};break;default:l={r:t*(1-n),g:t*(1-n),b:t*(1-n)}}return l.mode="rgb",void 0!==o&&(l.alpha=o),l}function a(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o=Math.max(e,a,n),i=Math.min(e,a,n),l={mode:"hsv",s:0===o?0:1-i/o,v:o};return o-i!=0&&(l.h=60*(o===e?(a-n)/(o-i)+6*(a<n):o===a?(n-e)/(o-i)+2:(e-a)/(o-i)+4)),void 0!==t&&(l.alpha=t),l}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},t=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(r[n]=a[n])}return r},o=function(r,e){return Math.round(r*(e=Math.pow(10,e)))/e};function i(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(void 0!==r)return"number"==typeof r?o(r,e):"string"==typeof r?r:"object"===(void 0===r?"undefined":n(r))?Object.keys(r).reduce(function(e,a){return e[a]=i(r[a]),e},{}):void 0}var l=function(e){var a=e.l,n=e.a,t=e.b,o=e.alpha,l=i(Math.sqrt(n*n+t*t),4),h={mode:"lch",l:a,c:l};return l&&(h.h=r(180*Math.atan2(t,n)/Math.PI)),void 0!==o&&(h.alpha=o),h},h=function(r){var e=r.l,a=r.c,n=r.h,t=r.alpha,o={mode:"lab",l:e,a:0===a?0:a*Math.cos(n/180*Math.PI),b:0===a?0:a*Math.sin(n/180*Math.PI)};return void 0!==t&&(o.alpha=t),o},u=Math.pow(29,3)/Math.pow(3,3),s=Math.pow(6,3)/Math.pow(29,3),d=function(r){return Math.pow(r,3)>s?Math.pow(r,3):(116*r-16)/u},b=function(r){return r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r},g=function(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o={mode:"rgb",r:b(e),g:b(a),b:b(n)};return void 0!==t&&(o.alpha=t),o},c=function(r){var e,a,n,t,o,i=function(r){var e=r.x,a=r.y,n=r.z;return g({r:3.2404542*e-1.5371385*a-.4985314*n,g:-.969266*e+1.8760108*a+.041556*n,b:.0556434*e-.2040259*a+1.0572252*n})}((a=(e=r).l,n=e.a,o=(t=(a+16)/116)-e.b/200,{x:.95047*d(n/500+t),y:1*d(t),z:1.08883*d(o)}));return i.mode="rgb",void 0!==r.alpha&&(i.alpha=r.alpha),i},p=function(r){return r<.04045?r/12.92:Math.pow((r+.055)/1.055,2.4)},v=function(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o={mode:"lrgb",r:p(e),g:p(a),b:p(n)};return void 0!==t&&(o.alpha=t),o},f=Math.pow(29,3)/Math.pow(3,3),m=Math.pow(6,3)/Math.pow(29,3),w=function(r){return r>m?Math.cbrt(r):(f*r+16)/116},y=function(r){var e,a,n,t,o,i,l=(e=function(r){var e=v(r),a=e.r,n=e.g,t=e.b;return{x:.4124564*a+.3575761*n+.1804375*t,y:.2126729*a+.7151522*n+.072175*t,z:.0193339*a+.119192*n+.9503041*t}}(r),a=e.x,n=e.y,t=e.z,o=w(a/.95047),{l:116*(i=w(n/1))-16,a:500*(o-i),b:200*(i-w(t/1.08883))});return l.mode="lab",void 0!==r.alpha&&(l.alpha=r.alpha),l},k={hsi:{rgb:function(e){var a=e.h,n=e.s,t=e.i,o=e.alpha;a=r(a);var i=Math.abs(a/60%2-1),l=void 0;switch(Math.floor(a/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))};break;default:l={r:t*(1-n),g:t*(1-n),b:t*(1-n)}}return l.mode="rgb",void 0!==o&&(l.alpha=o),l}},hsl:{rgb:function(e){var a=e.h,n=e.s,t=e.l,o=e.alpha;a=r(a);var i=t+n*(t<.5?t:1-t),l=i-2*(i-t)*Math.abs(a/60%2-1),h=void 0;switch(Math.floor(a/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};break;default:h={r:2*t-i,g:2*t-i,b:2*t-i}}return h.mode="rgb",void 0!==o&&(h.alpha=o),h}},hsv:{rgb:e},hwb:{rgb:function(r){var a=r.h,n=r.w,t=r.b,o=r.alpha;if(n+t>1){var i=n+t;n/=i,t/=i}return e({h:a,s:1===t?1:1-n/(1-t),v:1-t,alpha:o})}},lab:{lch:l,rgb:c},lch:{lab:h,rgb:function(r){return c(h(r))}},rgb:{hsi:function(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o=Math.max(e,a,n),i=Math.min(e,a,n),l={mode:"hsi",s:e+a+n===0?0:1-3*i/(e+a+n),i:(e+a+n)/3};return o-i!=0&&(l.h=60*(o===e?(a-n)/(o-i)+6*(a<n):o===a?(n-e)/(o-i)+2:(e-a)/(o-i)+4)),void 0!==t&&(l.alpha=t),l},hsl:function(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o=Math.max(e,a,n),i=Math.min(e,a,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===e?(a-n)/(o-i)+6*(a<n):o===a?(n-e)/(o-i)+2:(e-a)/(o-i)+4)),void 0!==t&&(l.alpha=t),l},hsv:a,hwb:function(r){var e=a(r);if(void 0!==e){var n={mode:"hwb",w:(1-e.s)*e.v,b:1-e.v};return void 0!==e.h&&(n.h=e.h),void 0!==e.alpha&&(n.alpha=e.alpha),n}},lab:y,lch:function(r){return l(y(r))},lrgb:v},lrgb:{rgb:g}},M=function(r,e){return void 0!==r?r.mode===e?r:k[r.mode][e]?k[r.mode][e](r):"rgb"===mode?k[r.mode].rgb(r):k.rgb[e](k[r.mode].rgb(r)):void 0},x=function(r,e){if("number"==typeof r)return 3===e?{mode:"rgb",r:(r>>8&15|r>>4&240)/255,g:(r>>4&15|240&r)/255,b:(15&r|r<<4&240)/255}:4===e?{mode:"rgb",r:(r>>12&15|r>>8&240)/255,g:(r>>8&15|r>>4&240)/255,b:(r>>4&15|240&r)/255,alpha:(15&r|r<<4&240)/255}:6===e?{mode:"rgb",r:(r>>16&255)/255,g:(r>>8&255)/255,b:(255&r)/255}:8===e?{mode:"rgb",r:(r>>24&255)/255,g:(r>>16&255)/255,b:(r>>8&255)/255,alpha:(255&r)/255}:void 0},$={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},E=function(r){return"string"==typeof r&&x($[r.toLowerCase()],6)||void 0},R=(/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/+"").replace(/^\/|\/$/g,""),j=R+"%",q="(?:"+R+"%|"+R+")",O="(?:"+R+"(deg|grad|rad|turn)|"+R+")",z="\\s*,\\s*",S="\\s+",I=new RegExp("^rgba?\\(\\s*"+R+z+R+z+R+"\\s*(?:,\\s*"+q+"\\s*)?\\)$"),P=new RegExp("^rgba?\\(\\s*"+j+z+j+z+j+"\\s*(?:,\\s*"+q+"\\s*)?\\)$"),H=new RegExp("^rgba?\\(\\s*"+R+S+R+S+R+"\\s*(?:\\/\\s*"+q+"\\s*)?\\)$"),N=new RegExp("^rgba?\\(\\s*"+j+S+j+S+j+"\\s*(?:\\/\\s*"+q+"\\s*)?\\)$"),C=new RegExp("^hsla?\\(\\s*"+O+z+j+z+j+"\\s*(?:,\\s*"+q+"\\s*)?\\)$"),L=new RegExp("^hsla?\\(\\s*"+O+S+j+S+j+"\\s*(?:\\/\\s*"+q+"\\s*)?\\)$"),A=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,B=new RegExp("^hwb\\(\\s*"+O+S+j+S+j+"\\s*(?:\\/\\s*"+q+"\\s*)?\\)$"),D=new RegExp("^lab\\(\\s*"+R+S+R+S+R+"\\s*(?:\\/\\s*"+q+"\\s*)?\\)$"),F=new RegExp("^lch\\(\\s*"+R+S+R+S+O+"\\s*(?:\\/\\s*"+q+"\\s*)?\\)$"),G=new RegExp("^gray\\(\\s*"+R+"()()\\s*(?:\\/\\s*"+q+"\\s*)?\\)$"),J=function(r){var e;return(e=r.match(A))?x(parseInt(e[1],16),e[1].length):void 0},K=function(r){var e=void 0,a=void 0;if(e=r.match(I)||r.match(H))a={mode:"rgb",r:e[1]/255,g:e[2]/255,b:e[3]/255};else{if(!(e=r.match(P)||r.match(N)))return;a={mode:"rgb",r:e[1]/100,g:e[2]/100,b:e[3]/100}}return void 0!==e[4]?a.alpha=e[4]/100:void 0!==e[5]&&(a.alpha=+e[5]),a},Q=function(r,e){switch(e){case"deg":return+r;case"rad":return r/Math.PI*180;case"grad":return r/10*9;case"turn":return 360*r}},T=function(r){if("string"==typeof r){var e=r.match(C)||r.match(L);if(e){var a={mode:"hsl",h:void 0===e[3]?Q(e[1],e[2]):+e[3],s:Math.min(Math.max(0,e[4]/100),1),l:Math.min(Math.max(0,e[5]/100),1)};return void 0!==e[6]?a.alpha=e[6]/100:void 0!==e[7]&&(a.alpha=e[7]/255),a}}},U=function(r){if("string"==typeof r){var e=r.match(B);if(e){var a={mode:"hwb",h:void 0===e[3]?Q(e[1],e[2]):+e[3],w:e[4]/100,b:e[5]/100};if(a.w+a.b>1){var n=a.w+a.b;a.w/=n,a.b/=n}return void 0!==e[6]?a.alpha=e[6]/100:void 0!==e[7]&&(a.alpha=e[7]/255),a}}},V=function(r){return J(r)||K(r)||T(r)||E(r)||("transparent"===r?x(0,8):void 0)||U(r)||function(r){var e=void 0,a=void 0;if(e=r.match(D))a={mode:"lab",l:+e[1],a:+e[2],b:+e[3]};else{if(!(e=r.match(G)))return;a={mode:"lab",l:+e[1],a:0,b:0}}return void 0!==e[4]?a.alpha=e[4]/100:void 0!==e[5]&&(a.alpha=+e[5]),a}(r)||function(r){var e=r.match(F);if(e){var a={mode:"lch",l:+e[1],c:Math.max(0,+e[2]),h:void 0===e[5]?Q(e[3],e[4]):+e[5]};return void 0!==e[6]?a.alpha=e[6]/100:void 0!==e[7]&&(a.alpha=+e[7]),a}}(r)},W=function(r,e){return"object"!==(void 0===r?"undefined":n(r))?V(r):void 0===r.mode?t({},r,{mode:e}):r},X=function(r){return M(W(r,"rgb"),"rgb")},Y=function(r){return Math.round(255*Math.max(0,Math.min(r,1)))},Z={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"],lrgb:["r","g","b","alpha"]},_=function(r,e){var a=Z[r.mode].reduce(function(a,n){var t=e(n,r[n]);return void 0!==t&&(a[n]=t),a},{});return a.mode=r.mode,a},rr=function(r,e,a){return r+a*(e-r)},er=function(r){return X(r)},ar=Object.freeze({hsl:function(r){return M(W(r,"hsl"),"hsl")},hsv:function(r){return M(W(r,"hsv"),"hsv")},hsi:function(r){return M(W(r,"hsi"),"hsi")},hwb:function(r){return M(W(r,"hwb"),"hwb")},rgb:X,lab:function(r){return M(W(r,"lab"),"lab")},lch:function(r){return M(W(r,"lch"),"lch")},lrgb:function(r){return M(W(r,"lrgb"),"lrgb")},css:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb",a=X(r),n=Y(a.r),t=Y(a.g),o=Y(a.b);return"hex"===e?"#"+(1<<24|n<<16|t<<8|o).toString(16).slice(1):"rgb"===e?void 0===a.alpha||1===a.alpha?"rgb("+n+", "+t+", "+o+")":"rgba("+n+", "+t+", "+o+", "+i(a.alpha,2)+")":void 0},convert:M,prepare:W,round:i,parse:V,parseNumber:x,parseNamed:E,parseHex:J,parseRgb:K,parseHsl:T,parseHwb:U,named:$,map:_,interpolate:function(e){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb";if(!(e.length<2)){var n=e.map(function(r){return M(W(r,a),a)});return function(e){if(1===(e=Math.min(Math.max(0,e),1)))return Object.assign({},n[n.length-1]);var t=e*(n.length-1),o=Math.floor(t),i=n[o],l=n[o+1],h=t-o;return _({mode:a},function(e){return("h"===e?function(e,a,n){return void 0!==e&&void 0!==a?(e=r(e),a=r(a),Math.abs(a-e)>180?r(rr(e,a-360*Math.sign(a-e),n)):rr(e,a,n)):void 0===e?a:e}:"alpha"===e?function(r,e,a){if(!(void 0===r&&void 0===e||void 0===r&&0===a||void 0===e&&1===a))return rr(void 0===r?1:r,void 0===e?1:e,a)}:function(r,e,a){return void 0!==r&&void 0!==e?rr(r,e,a):void 0===r?e:r})(i[e],l[e],h)})}}},swatches:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2;if(e<2)return e<1?[]:[r(.5)];for(var a=[],n=0;n<e;n++)a.push(r(n/(e-1)));return a},default:er});return Object.assign(er,ar),er}); |
@@ -246,2 +246,51 @@ var normalizeHue = (function (hue) { | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
// From: https://github.com/d3/d3-format/issues/32 | ||
var r = function r(value, precision) { | ||
return Math.round(value * (precision = Math.pow(10, precision))) / precision; | ||
}; | ||
function round(value) { | ||
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; | ||
if (value === undefined) { | ||
return undefined; | ||
} | ||
if (typeof value === 'number') { | ||
return r(value, precision); | ||
} | ||
if (typeof value === 'string') { | ||
return value; | ||
} | ||
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { | ||
return Object.keys(value).reduce(function (o, k) { | ||
return o[k] = round(value[k]), o; | ||
}, {}); | ||
} | ||
} | ||
/* | ||
@@ -258,8 +307,11 @@ References: | ||
// Fixes achromatic colors having a _slight_ chroma due to floating-point errors | ||
// and approximated computations in sRGB <-> CIELab. | ||
var c = round(Math.sqrt(a * a + b * b), 4); | ||
var res = { | ||
mode: 'lch', | ||
l: l, | ||
c: Math.sqrt(a * a + b * b), | ||
h: normalizeHue(Math.atan2(b, a) * 180 / Math.PI) | ||
c: c | ||
}; | ||
if (c) res.h = normalizeHue(Math.atan2(b, a) * 180 / Math.PI); | ||
if (alpha !== undefined) res.alpha = alpha; | ||
@@ -283,4 +335,4 @@ return res; | ||
l: l, | ||
a: c * Math.cos(h / 180 * Math.PI), | ||
b: c * Math.sin(h / 180 * Math.PI) | ||
a: c === 0 ? 0 : c * Math.cos(h / 180 * Math.PI), | ||
b: c === 0 ? 0 : c * Math.sin(h / 180 * Math.PI) | ||
}; | ||
@@ -908,22 +960,2 @@ if (alpha !== undefined) res.alpha = alpha; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var prepare = (function (color, mode) { | ||
@@ -965,31 +997,2 @@ return (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color; | ||
// From: https://github.com/d3/d3-format/issues/32 | ||
var r = function r(value, precision) { | ||
return Math.round(value * (precision = Math.pow(10, precision))) / precision; | ||
}; | ||
function round(value) { | ||
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4; | ||
if (value === undefined) { | ||
return undefined; | ||
} | ||
if (typeof value === 'number') { | ||
return r(value, precision); | ||
} | ||
if (typeof value === 'string') { | ||
return value; | ||
} | ||
if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') { | ||
return Object.keys(value).reduce(function (o, k) { | ||
return o[k] = round(value[k]), o; | ||
}, {}); | ||
} | ||
} | ||
var clamp = function clamp(v) { | ||
@@ -996,0 +999,0 @@ return Math.round(Math.max(0, Math.min(v, 1)) * 255); |
{ | ||
"name": "culori", | ||
"version": "0.2.45", | ||
"version": "0.2.46", | ||
"main": "build/culori.js", | ||
@@ -5,0 +5,0 @@ "module": "build/index.js", |
import normalizeHue from '../util/normalizeHue'; | ||
import round from '../api/round'; | ||
/* | ||
@@ -8,10 +9,13 @@ References: | ||
export default ({ l, a, b, alpha }) => { | ||
// Fixes achromatic colors having a _slight_ chroma due to floating-point errors | ||
// and approximated computations in sRGB <-> CIELab. | ||
let c = round(Math.sqrt(a * a + b * b), 4); | ||
let res = { | ||
mode: 'lch', | ||
l: l, | ||
c: Math.sqrt(a * a + b * b), | ||
h: normalizeHue(Math.atan2(b, a) * 180 / Math.PI) | ||
c: c | ||
} | ||
if (c) res.h = normalizeHue(Math.atan2(b, a) * 180 / Math.PI); | ||
if (alpha !== undefined) res.alpha = alpha; | ||
return res; | ||
}; |
@@ -10,4 +10,4 @@ /* | ||
l: l, | ||
a: c * Math.cos( h / 180 * Math.PI ), | ||
b: c * Math.sin( h / 180 * Math.PI ) | ||
a: c === 0 ? 0 : c * Math.cos( h / 180 * Math.PI ), | ||
b: c === 0 ? 0 : c * Math.sin( h / 180 * Math.PI ) | ||
} | ||
@@ -14,0 +14,0 @@ if (alpha !== undefined) res.alpha = alpha; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
107135
3035