Comparing version 0.2.61 to 0.2.62
@@ -8,3 +8,3 @@ (function (global, factory) { | ||
var converters = {}; | ||
var components = {}; | ||
var _channels = {}; | ||
var parsers = []; | ||
@@ -16,3 +16,3 @@ | ||
output = _ref.output, | ||
keys = _ref.keys, | ||
channels = _ref.channels, | ||
p = _ref.parsers; | ||
@@ -27,3 +27,3 @@ | ||
}); | ||
components[mode] = keys; | ||
_channels[mode] = channels.concat('alpha'); | ||
(p || []).forEach(function (parser) { | ||
@@ -34,2 +34,6 @@ return parsers.push(parser); | ||
var getChannels = function getChannels(mode) { | ||
return _channels[mode]; | ||
}; | ||
var parse = function parse(color) { | ||
@@ -45,2 +49,12 @@ var result = void 0, | ||
var fromArray = (function (color, mode) { | ||
var res = { mode: mode }; | ||
getChannels(mode).forEach(function (k, idx) { | ||
if (color[idx] !== undefined) { | ||
res[k] = color[idx]; | ||
} | ||
}); | ||
return res; | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
@@ -67,3 +81,3 @@ return typeof obj; | ||
var prepare = function prepare(color, mode) { | ||
return (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color; | ||
return (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : Array.isArray(color) ? fromArray(color, mode) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color; | ||
}; | ||
@@ -107,26 +121,15 @@ | ||
var invariant = function invariant(k, v) { | ||
return v; | ||
}; | ||
var transform = (function () { | ||
var fn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : invariant; | ||
return function (color) { | ||
var res = { mode: color.mode }, | ||
mapped = void 0; | ||
components[color.mode].forEach(function (key) { | ||
if ((mapped = fn(color[key], key)) !== undefined) { | ||
res[key] = mapped; | ||
} | ||
}); | ||
return res; | ||
}; | ||
var toArray$1 = (function () { | ||
return function (color) { | ||
return getChannels(color.mode).map(function (k) { | ||
return color[k]; | ||
}); | ||
}; | ||
}); | ||
var clampRGB = transform(function (v, k) { | ||
return k === 'alpha' ? v : Math.round(Math.max(0, Math.min(v, 1)) * 255); | ||
}); | ||
var rgb = converter('rgb'); | ||
var roundAlpha = round(2); | ||
var clamp = function clamp(v) { | ||
return Math.round(Math.max(0, Math.min(v, 1)) * 255); | ||
}; | ||
@@ -136,15 +139,15 @@ var css = (function () { | ||
return function (c) { | ||
var color = clampRGB(rgb(c)); | ||
var color = toArray$1()(rgb(c)).slice(0, 3).map(clamp).concat([c.alpha === 1 ? undefined : c.alpha]); | ||
if (format === 'hex') { | ||
return '#' + (1 << 24 | color.r << 16 | color.g << 8 | color.b).toString(16).slice(1); | ||
return '#' + (1 << 24 | color[0] << 16 | color[1] << 8 | color[2]).toString(16).slice(1); | ||
} | ||
if (format === 'rgb') { | ||
if (color.alpha === undefined || color.alpha === 255) { | ||
if (color[3] === undefined) { | ||
// opaque color | ||
return 'rgb(' + color.r + ', ' + color.g + ', ' + color.b + ')'; | ||
return 'rgb(' + color[0] + ', ' + color[1] + ', ' + color[2] + ')'; | ||
} else { | ||
// transparent color | ||
return 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + roundAlpha(color.alpha) + ')'; | ||
return 'rgba(' + color[0] + ', ' + color[1] + ', ' + color[2] + ', ' + roundAlpha(color[3]) + ')'; | ||
} | ||
@@ -333,2 +336,6 @@ } | ||
var method = function method(k) { | ||
return k === 'h' ? hue : k === 'alpha' ? alpha : generic; | ||
}; | ||
var interpolate = (function (seeds) { | ||
@@ -355,7 +362,5 @@ var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'rgb'; | ||
// create a new color in the mode given, and map its values | ||
return transform(function (v, k) { | ||
var method = k === 'h' ? hue : k === 'alpha' ? alpha : generic; | ||
return method(startColor[k], endColor[k], t0); | ||
})({ mode: mode }); | ||
return fromArray(getChannels(mode).map(function (k) { | ||
return method(k)(startColor[k], endColor[k], t0); | ||
}), mode); | ||
}; | ||
@@ -569,3 +574,3 @@ }); | ||
mode: 'rgb', | ||
keys: ['r', 'g', 'b', 'alpha'], | ||
channels: ['r', 'g', 'b'], | ||
parsers: [parseHex, parseRgb, parseNamed, parseTransparent] | ||
@@ -622,3 +627,3 @@ }; | ||
}, | ||
keys: ['r', 'g', 'b', 'alpha'] | ||
channels: ['r', 'g', 'b'] | ||
}; | ||
@@ -718,3 +723,3 @@ | ||
}, | ||
keys: ['h', 's', 'l', 'alpha'], | ||
channels: ['h', 's', 'l'], | ||
parsers: [parseHsl] | ||
@@ -783,3 +788,3 @@ }; | ||
}, | ||
keys: ['h', 's', 'v', 'alpha'] | ||
channels: ['h', 's', 'v'] | ||
}; | ||
@@ -878,3 +883,3 @@ | ||
}, | ||
keys: ['h', 's', 'i', 'alpha'] | ||
channels: ['h', 's', 'i'] | ||
}; | ||
@@ -969,3 +974,3 @@ | ||
}, | ||
keys: ['h', 'w', 'b', 'alpha'], | ||
channels: ['h', 'w', 'b'], | ||
parsers: [parseHwb] | ||
@@ -1117,3 +1122,3 @@ }; | ||
}, | ||
keys: ['l', 'a', 'b', 'alpha'], | ||
channels: ['l', 'a', 'b'], | ||
parsers: [parseLab] | ||
@@ -1211,3 +1216,3 @@ }; | ||
}, | ||
keys: ['l', 'c', 'h', 'alpha'], | ||
channels: ['l', 'c', 'h'], | ||
parsers: [parseLch] | ||
@@ -1251,5 +1256,6 @@ }; | ||
named: named, | ||
transform: transform, | ||
interpolate: interpolate, | ||
samples: samples, | ||
fromArray: fromArray, | ||
toArray: toArray$1, | ||
default: culori | ||
@@ -1256,0 +1262,0 @@ }); |
@@ -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={},e={},a=[],t=function(t){var n=t.mode,o=t.input,i=t.output,l=t.keys,h=t.parsers;r[n]=Object.assign(r[n]||{},i),Object.keys(o||{}).forEach(function(e){r[e]||(r[e]={}),r[e][n]=o[e]}),e[n]=l,(h||[]).forEach(function(r){return a.push(r)})},n=function(r){for(var e=void 0,t=0,n=a.length;t<n&&void 0===(e=a[t++](r)););return e},o="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},i=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var t in a)Object.prototype.hasOwnProperty.call(a,t)&&(r[t]=a[t])}return r},l=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"rgb";return function(a){return void 0!==(a=function(r,e){return"object"!==(void 0===r?"undefined":o(r))?n(r):void 0===r.mode?i({},r,{mode:e}):r}(a,e))?a.mode===e?a:r[a.mode][e]?r[a.mode][e](a):"rgb"===e?r[a.mode].rgb(a):r.rgb[e](r[a.mode].rgb(a)):void 0}},h=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:4;return function(e){return"number"==typeof e?function(r,e){return Math.round(r*(e=Math.pow(10,e)))/e}(e,r):e}},u=function(r,e){return e},s=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:u;return function(a){var t={mode:a.mode},n=void 0;return e[a.mode].forEach(function(e){void 0!==(n=r(a[e],e))&&(t[e]=n)}),t}},d=s(function(r,e){return"alpha"===e?r:Math.round(255*Math.max(0,Math.min(r,1)))}),b=l("rgb"),g=h(2),c={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},p=function(r){return(r%=360)<0?r+360:r},v=function(r,e,a){return r+a*(e-r)},f=function(r,e,a){return void 0!==r&&void 0!==e?v(r,e,a):void 0===r?e:r},m=function(r,e,a){return void 0!==r&&void 0!==e?(r=p(r),e=p(e),Math.abs(e-r)>180?p(v(r,e-360*Math.sign(e-r),a)):v(r,e,a)):void 0===r?e:r},y=function(r,e,a){if(!(void 0===r&&void 0===e||void 0===r&&0===a||void 0===e&&1===a))return v(void 0===r?1:r,void 0===e?1:e,a)},k=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},w=(/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/+"").replace(/^\/|\/$/g,""),M=w+"%",x="(?:"+w+"%|"+w+")",E="(?:"+w+"(deg|grad|rad|turn)|"+w+")",$="\\s*,\\s*",j="\\s+",q=new RegExp("^rgba?\\(\\s*"+w+$+w+$+w+"\\s*(?:,\\s*"+x+"\\s*)?\\)$"),R=new RegExp("^rgba?\\(\\s*"+M+$+M+$+M+"\\s*(?:,\\s*"+x+"\\s*)?\\)$"),O=new RegExp("^rgba?\\(\\s*"+w+j+w+j+w+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),z=new RegExp("^rgba?\\(\\s*"+M+j+M+j+M+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),S=new RegExp("^hsla?\\(\\s*"+E+$+M+$+M+"\\s*(?:,\\s*"+x+"\\s*)?\\)$"),I=new RegExp("^hsla?\\(\\s*"+E+j+M+j+M+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),P=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,C=new RegExp("^hwb\\(\\s*"+E+j+M+j+M+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),L=new RegExp("^lab\\(\\s*"+w+j+w+j+w+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),A=new RegExp("^lch\\(\\s*"+w+j+w+j+E+"\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),B=new RegExp("^gray\\(\\s*"+w+"()()\\s*(?:\\/\\s*"+x+"\\s*)?\\)$"),D={mode:"rgb",keys:["r","g","b","alpha"],parsers:[function(r){var e;return(e=r.match(P))?k(parseInt(e[1],16),e[1].length):void 0},function(r){var e=void 0,a=void 0;if(e=r.match(q)||r.match(O))a={mode:"rgb",r:e[1]/255,g:e[2]/255,b:e[3]/255};else{if(!(e=r.match(R)||r.match(z)))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},function(r){return"string"==typeof r&&k(c[r.toLowerCase()],6)||void 0},function(r){return"transparent"===r?k(0,8):void 0}]},F=function(r){return r<.04045?r/12.92:Math.pow((r+.055)/1.055,2.4)},G=function(r){var e=r.r,a=r.g,t=r.b,n=r.alpha,o={mode:"lrgb",r:F(e),g:F(a),b:F(t)};return void 0!==n&&(o.alpha=n),o},H=function(r){return r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r},J=function(r){var e=r.r,a=r.g,t=r.b,n=r.alpha,o={mode:"rgb",r:H(e),g:H(a),b:H(t)};return void 0!==n&&(o.alpha=n),o},K={mode:"lrgb",output:{rgb:J},input:{rgb:G},keys:["r","g","b","alpha"]};var N=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}},Q={mode:"hsl",output:{rgb:function(r){var e=r.h,a=r.s,t=r.l,n=r.alpha;e=p(e);var o=t+a*(t<.5?t:1-t),i=o-2*(o-t)*Math.abs(e/60%2-1),l=void 0;switch(Math.floor(e/60)){case 0:l={r:o,g:i,b:2*t-o};break;case 1:l={r:i,g:o,b:2*t-o};break;case 2:l={r:2*t-o,g:o,b:i};break;case 3:l={r:2*t-o,g:i,b:o};break;case 4:l={r:i,g:2*t-o,b:o};break;case 5:l={r:o,g:2*t-o,b:i};break;default:l={r:2*t-o,g:2*t-o,b:2*t-o}}return l.mode="rgb",void 0!==n&&(l.alpha=n),l}},input:{rgb:function(r){var e=r.r,a=r.g,t=r.b,n=r.alpha,o=Math.max(e,a,t),i=Math.min(e,a,t),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-t)/(o-i)+6*(a<t):o===a?(t-e)/(o-i)+2:(e-a)/(o-i)+4)),void 0!==n&&(l.alpha=n),l}},keys:["h","s","l","alpha"],parsers:[function(r){if("string"==typeof r){var e=r.match(S)||r.match(I);if(e){var a={mode:"hsl",h:void 0===e[3]?N(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}}}]};function T(r){var e=r.h,a=r.s,t=r.v,n=r.alpha;e=p(e);var o=Math.abs(e/60%2-1),i=void 0;switch(Math.floor(e/60)){case 0:i={r:t,g:t*(1-a*o),b:t*(1-a)};break;case 1:i={r:t*(1-a*o),g:t,b:t*(1-a)};break;case 2:i={r:t*(1-a),g:t,b:t*(1-a*o)};break;case 3:i={r:t*(1-a),g:t*(1-a*o),b:t};break;case 4:i={r:t*(1-a*o),g:t*(1-a),b:t};break;case 5:i={r:t,g:t*(1-a),b:t*(1-a*o)};break;default:i={r:t*(1-a),g:t*(1-a),b:t*(1-a)}}return i.mode="rgb",void 0!==n&&(i.alpha=n),i}function U(r){var e=r.r,a=r.g,t=r.b,n=r.alpha,o=Math.max(e,a,t),i=Math.min(e,a,t),l={mode:"hsv",s:0===o?0:1-i/o,v:o};return o-i!=0&&(l.h=60*(o===e?(a-t)/(o-i)+6*(a<t):o===a?(t-e)/(o-i)+2:(e-a)/(o-i)+4)),void 0!==n&&(l.alpha=n),l}var V={mode:"hsv",output:{rgb:T},input:{rgb:U},keys:["h","s","v","alpha"]};var W={mode:"hsi",output:{rgb:function(r){var e=r.h,a=r.s,t=r.i,n=r.alpha;e=p(e);var o=Math.abs(e/60%2-1),i=void 0;switch(Math.floor(e/60)){case 0:i={r:t*(1+a*(3/(2-o)-1)),g:t*(1+a*(3*(1-o)/(2-o)-1)),b:t*(1-a)};break;case 1:i={r:t*(1+a*(3*(1-o)/(2-o)-1)),g:t*(1+a*(3/(2-o)-1)),b:t*(1-a)};break;case 2:i={r:t*(1-a),g:t*(1+a*(3/(2-o)-1)),b:t*(1+a*(3*(1-o)/(2-o)-1))};break;case 3:i={r:t*(1-a),g:t*(1+a*(3*(1-o)/(2-o)-1)),b:t*(1+a*(3/(2-o)-1))};break;case 4:i={r:t*(1+a*(3*(1-o)/(2-o)-1)),g:t*(1-a),b:t*(1+a*(3/(2-o)-1))};break;case 5:i={r:t*(1+a*(3/(2-o)-1)),g:t*(1-a),b:t*(1+a*(3*(1-o)/(2-o)-1))};break;default:i={r:t*(1-a),g:t*(1-a),b:t*(1-a)}}return i.mode="rgb",void 0!==n&&(i.alpha=n),i}},input:{rgb:function(r){var e=r.r,a=r.g,t=r.b,n=r.alpha,o=Math.max(e,a,t),i=Math.min(e,a,t),l={mode:"hsi",s:e+a+t===0?0:1-3*i/(e+a+t),i:(e+a+t)/3};return o-i!=0&&(l.h=60*(o===e?(a-t)/(o-i)+6*(a<t):o===a?(t-e)/(o-i)+2:(e-a)/(o-i)+4)),void 0!==n&&(l.alpha=n),l}},keys:["h","s","i","alpha"]};var X={mode:"hwb",output:{rgb:function(r){var e=r.h,a=r.w,t=r.b,n=r.alpha;if(a+t>1){var o=a+t;a/=o,t/=o}return T({h:e,s:1===t?1:1-a/(1-t),v:1-t,alpha:n})}},input:{rgb:function(r){var e=U(r);if(void 0!==e){var a={mode:"hwb",w:(1-e.s)*e.v,b:1-e.v};return void 0!==e.h&&(a.h=e.h),void 0!==e.alpha&&(a.alpha=e.alpha),a}}},keys:["h","w","b","alpha"],parsers:[function(r){if("string"==typeof r){var e=r.match(C);if(e){var a={mode:"hwb",h:void 0===e[3]?N(e[1],e[2]):+e[3],w:e[4]/100,b:e[5]/100};if(a.w+a.b>1){var t=a.w+a.b;a.w/=t,a.b/=t}return void 0!==e[6]?a.alpha=e[6]/100:void 0!==e[7]&&(a.alpha=e[7]/255),a}}}]},Y=Math.pow(29,3)/Math.pow(3,3),Z=Math.pow(6,3)/Math.pow(29,3),_=function(r){return Math.pow(r,3)>Z?Math.pow(r,3):(116*r-16)/Y},rr=function(r){var e,a,t,n,o,i=function(r){var e=r.x,a=r.y,t=r.z;return J({r:3.2404542*e-1.5371385*a-.4985314*t,g:-.969266*e+1.8760108*a+.041556*t,b:.0556434*e-.2040259*a+1.0572252*t})}((a=(e=r).l,t=e.a,o=(n=(a+16)/116)-e.b/200,{x:.95047*_(t/500+n),y:1*_(n),z:1.08883*_(o)}));return i.mode="rgb",void 0!==r.alpha&&(i.alpha=r.alpha),i},er=function(r){return r>Z?Math.cbrt(r):(Y*r+16)/116},ar=function(r){var e,a,t,n,o,i,l=(e=function(r){var e=G(r),a=e.r,t=e.g,n=e.b;return{x:.4124564*a+.3575761*t+.1804375*n,y:.2126729*a+.7151522*t+.072175*n,z:.0193339*a+.119192*t+.9503041*n}}(r),a=e.x,t=e.y,n=e.z,o=er(a/.95047),{l:116*(i=er(t/1))-16,a:500*(o-i),b:200*(i-er(n/1.08883))});return l.mode="lab",void 0!==r.alpha&&(l.alpha=r.alpha),l},tr={mode:"lab",output:{rgb:rr},input:{rgb:ar},keys:["l","a","b","alpha"],parsers:[function(r){var e=void 0,a=void 0;if(e=r.match(L))a={mode:"lab",l:+e[1],a:+e[2],b:+e[3]};else{if(!(e=r.match(B)))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}]},nr=h(4),or=function(r){var e=r.l,a=r.a,t=r.b,n=r.alpha,o=nr(Math.sqrt(a*a+t*t)),i={mode:"lch",l:e,c:o};return o&&(i.h=p(180*Math.atan2(t,a)/Math.PI)),void 0!==n&&(i.alpha=n),i},ir=function(r){var e=r.l,a=r.c,t=r.h,n=r.alpha,o={mode:"lab",l:e,a:0===a?0:a*Math.cos(t/180*Math.PI),b:0===a?0:a*Math.sin(t/180*Math.PI)};return void 0!==n&&(o.alpha=n),o},lr={mode:"lch",output:{lab:ir,rgb:function(r){return rr(ir(r))}},input:{rgb:function(r){return or(ar(r))},lch:or},keys:["l","c","h","alpha"],parsers:[function(r){var e=r.match(A);if(e){var a={mode:"lch",l:+e[1],c:Math.max(0,+e[2]),h:void 0===e[5]?N(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}}]};t(D),t(K),t(Q),t(V),t(W),t(X),t(tr),t(lr);var hr=l("rgb"),ur=l("lrgb"),sr=l("hsl"),dr=l("hsv"),br=l("hsi"),gr=l("hwb"),cr=l("lab"),pr=l("lch"),vr=hr,fr=Object.freeze({hsl:sr,hsv:dr,hsi:br,hwb:gr,rgb:hr,lab:cr,lch:pr,lrgb:ur,css:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"rgb";return function(e){var a=d(b(e));return"hex"===r?"#"+(1<<24|a.r<<16|a.g<<8|a.b).toString(16).slice(1):"rgb"===r?void 0===a.alpha||255===a.alpha?"rgb("+a.r+", "+a.g+", "+a.b+")":"rgba("+a.r+", "+a.g+", "+a.b+", "+g(a.alpha)+")":void 0}},converter:l,brighten:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb",a=r>0?0-r:1/(2+r),t=l(e);return function(r){var n=l(r.mode),o=Object.assign({},t(r));switch(e){case"rgb":case"lrgb":o.r*=Math.pow(.7,a),o.g*=Math.pow(.7,a),o.b*=Math.pow(.7,a);break;case"hsl":case"lab":case"lch":o.l*=exp;break;case"hsv":o.v*=exp;break;case"hsi":o.i*=exp}return n(o)}},round:h,parse:n,named:c,transform:s,interpolate:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb";if(!(r.length<2)){var a=r.map(l(e));return function(r){var t=(r=Math.min(Math.max(0,r),1))*(a.length-1),n=Math.floor(t),o=a[n],i=1===r?a[n]:a[n+1],l=t-n;return s(function(r,e){return("h"===e?m:"alpha"===e?y:f)(o[e],i[e],l)})({mode:e})}}},samples:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2;if(r<2)return r<1?[]:[.5];for(var e=[],a=0;a<r;a++)e.push(a/(r-1));return e},default:vr});return Object.assign(vr,fr),vr}); | ||
!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={},e={},a=[],n=function(n){var t=n.mode,o=n.input,i=n.output,l=n.channels,u=n.parsers;r[t]=Object.assign(r[t]||{},i),Object.keys(o||{}).forEach(function(e){r[e]||(r[e]={}),r[e][t]=o[e]}),e[t]=l.concat("alpha"),(u||[]).forEach(function(r){return a.push(r)})},t=function(r){return e[r]},o=function(r){for(var e=void 0,n=0,t=a.length;n<t&&void 0===(e=a[n++](r)););return e},i=function(r,e){var a={mode:e};return t(e).forEach(function(e,n){void 0!==r[n]&&(a[e]=r[n])}),a},l="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},u=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},h=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"rgb";return function(a){return void 0!==(a=function(r,e){return"object"!==(void 0===r?"undefined":l(r))?o(r):Array.isArray(r)?i(r,e):void 0===r.mode?u({},r,{mode:e}):r}(a,e))?a.mode===e?a:r[a.mode][e]?r[a.mode][e](a):"rgb"===e?r[a.mode].rgb(a):r.rgb[e](r[a.mode].rgb(a)):void 0}},s=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:4;return function(e){return"number"==typeof e?function(r,e){return Math.round(r*(e=Math.pow(10,e)))/e}(e,r):e}},d=function(){return function(r){return t(r.mode).map(function(e){return r[e]})}},b=h("rgb"),c=s(2),g=function(r){return Math.round(255*Math.max(0,Math.min(r,1)))},p={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},v=function(r){return(r%=360)<0?r+360:r},f=function(r,e,a){return r+a*(e-r)},m=function(r,e,a){return void 0!==r&&void 0!==e?f(r,e,a):void 0===r?e:r},y=function(r,e,a){return void 0!==r&&void 0!==e?(r=v(r),e=v(e),Math.abs(e-r)>180?v(f(r,e-360*Math.sign(e-r),a)):f(r,e,a)):void 0===r?e:r},w=function(r,e,a){if(!(void 0===r&&void 0===e||void 0===r&&0===a||void 0===e&&1===a))return f(void 0===r?1:r,void 0===e?1:e,a)},k=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},M=(/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/+"").replace(/^\/|\/$/g,""),x=M+"%",E="(?:"+M+"%|"+M+")",$="(?:"+M+"(deg|grad|rad|turn)|"+M+")",j="\\s*,\\s*",q="\\s+",R=new RegExp("^rgba?\\(\\s*"+M+j+M+j+M+"\\s*(?:,\\s*"+E+"\\s*)?\\)$"),O=new RegExp("^rgba?\\(\\s*"+x+j+x+j+x+"\\s*(?:,\\s*"+E+"\\s*)?\\)$"),z=new RegExp("^rgba?\\(\\s*"+M+q+M+q+M+"\\s*(?:\\/\\s*"+E+"\\s*)?\\)$"),S=new RegExp("^rgba?\\(\\s*"+x+q+x+q+x+"\\s*(?:\\/\\s*"+E+"\\s*)?\\)$"),I=new RegExp("^hsla?\\(\\s*"+$+j+x+j+x+"\\s*(?:,\\s*"+E+"\\s*)?\\)$"),P=new RegExp("^hsla?\\(\\s*"+$+q+x+q+x+"\\s*(?:\\/\\s*"+E+"\\s*)?\\)$"),A=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,C=new RegExp("^hwb\\(\\s*"+$+q+x+q+x+"\\s*(?:\\/\\s*"+E+"\\s*)?\\)$"),L=new RegExp("^lab\\(\\s*"+M+q+M+q+M+"\\s*(?:\\/\\s*"+E+"\\s*)?\\)$"),B=new RegExp("^lch\\(\\s*"+M+q+M+q+$+"\\s*(?:\\/\\s*"+E+"\\s*)?\\)$"),D=new RegExp("^gray\\(\\s*"+M+"()()\\s*(?:\\/\\s*"+E+"\\s*)?\\)$"),F={mode:"rgb",channels:["r","g","b"],parsers:[function(r){var e;return(e=r.match(A))?k(parseInt(e[1],16),e[1].length):void 0},function(r){var e=void 0,a=void 0;if(e=r.match(R)||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},function(r){return"string"==typeof r&&k(p[r.toLowerCase()],6)||void 0},function(r){return"transparent"===r?k(0,8):void 0}]},G=function(r){return r<.04045?r/12.92:Math.pow((r+.055)/1.055,2.4)},H=function(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o={mode:"lrgb",r:G(e),g:G(a),b:G(n)};return void 0!==t&&(o.alpha=t),o},J=function(r){return r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r},K=function(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o={mode:"rgb",r:J(e),g:J(a),b:J(n)};return void 0!==t&&(o.alpha=t),o},N={mode:"lrgb",output:{rgb:K},input:{rgb:H},channels:["r","g","b"]};var 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={mode:"hsl",output:{rgb:function(r){var e=r.h,a=r.s,n=r.l,t=r.alpha;e=v(e);var o=n+a*(n<.5?n:1-n),i=o-2*(o-n)*Math.abs(e/60%2-1),l=void 0;switch(Math.floor(e/60)){case 0:l={r:o,g:i,b:2*n-o};break;case 1:l={r:i,g:o,b:2*n-o};break;case 2:l={r:2*n-o,g:o,b:i};break;case 3:l={r:2*n-o,g:i,b:o};break;case 4:l={r:i,g:2*n-o,b:o};break;case 5:l={r:o,g:2*n-o,b:i};break;default:l={r:2*n-o,g:2*n-o,b:2*n-o}}return l.mode="rgb",void 0!==t&&(l.alpha=t),l}},input:{rgb: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}},channels:["h","s","l"],parsers:[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]?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}}}]};function U(r){var e=r.h,a=r.s,n=r.v,t=r.alpha;e=v(e);var o=Math.abs(e/60%2-1),i=void 0;switch(Math.floor(e/60)){case 0:i={r:n,g:n*(1-a*o),b:n*(1-a)};break;case 1:i={r:n*(1-a*o),g:n,b:n*(1-a)};break;case 2:i={r:n*(1-a),g:n,b:n*(1-a*o)};break;case 3:i={r:n*(1-a),g:n*(1-a*o),b:n};break;case 4:i={r:n*(1-a*o),g:n*(1-a),b:n};break;case 5:i={r:n,g:n*(1-a),b:n*(1-a*o)};break;default:i={r:n*(1-a),g:n*(1-a),b:n*(1-a)}}return i.mode="rgb",void 0!==t&&(i.alpha=t),i}function V(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 W={mode:"hsv",output:{rgb:U},input:{rgb:V},channels:["h","s","v"]};var X={mode:"hsi",output:{rgb:function(r){var e=r.h,a=r.s,n=r.i,t=r.alpha;e=v(e);var o=Math.abs(e/60%2-1),i=void 0;switch(Math.floor(e/60)){case 0:i={r:n*(1+a*(3/(2-o)-1)),g:n*(1+a*(3*(1-o)/(2-o)-1)),b:n*(1-a)};break;case 1:i={r:n*(1+a*(3*(1-o)/(2-o)-1)),g:n*(1+a*(3/(2-o)-1)),b:n*(1-a)};break;case 2:i={r:n*(1-a),g:n*(1+a*(3/(2-o)-1)),b:n*(1+a*(3*(1-o)/(2-o)-1))};break;case 3:i={r:n*(1-a),g:n*(1+a*(3*(1-o)/(2-o)-1)),b:n*(1+a*(3/(2-o)-1))};break;case 4:i={r:n*(1+a*(3*(1-o)/(2-o)-1)),g:n*(1-a),b:n*(1+a*(3/(2-o)-1))};break;case 5:i={r:n*(1+a*(3/(2-o)-1)),g:n*(1-a),b:n*(1+a*(3*(1-o)/(2-o)-1))};break;default:i={r:n*(1-a),g:n*(1-a),b:n*(1-a)}}return i.mode="rgb",void 0!==t&&(i.alpha=t),i}},input:{rgb: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}},channels:["h","s","i"]};var Y={mode:"hwb",output:{rgb:function(r){var e=r.h,a=r.w,n=r.b,t=r.alpha;if(a+n>1){var o=a+n;a/=o,n/=o}return U({h:e,s:1===n?1:1-a/(1-n),v:1-n,alpha:t})}},input:{rgb:function(r){var e=V(r);if(void 0!==e){var a={mode:"hwb",w:(1-e.s)*e.v,b:1-e.v};return void 0!==e.h&&(a.h=e.h),void 0!==e.alpha&&(a.alpha=e.alpha),a}}},channels:["h","w","b"],parsers:[function(r){if("string"==typeof r){var e=r.match(C);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}}}]},Z=Math.pow(29,3)/Math.pow(3,3),_=Math.pow(6,3)/Math.pow(29,3),rr=function(r){return Math.pow(r,3)>_?Math.pow(r,3):(116*r-16)/Z},er=function(r){var e,a,n,t,o,i=function(r){var e=r.x,a=r.y,n=r.z;return K({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*rr(n/500+t),y:1*rr(t),z:1.08883*rr(o)}));return i.mode="rgb",void 0!==r.alpha&&(i.alpha=r.alpha),i},ar=function(r){return r>_?Math.cbrt(r):(Z*r+16)/116},nr=function(r){var e,a,n,t,o,i,l=(e=function(r){var e=H(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=ar(a/.95047),{l:116*(i=ar(n/1))-16,a:500*(o-i),b:200*(i-ar(t/1.08883))});return l.mode="lab",void 0!==r.alpha&&(l.alpha=r.alpha),l},tr={mode:"lab",output:{rgb:er},input:{rgb:nr},channels:["l","a","b"],parsers:[function(r){var e=void 0,a=void 0;if(e=r.match(L))a={mode:"lab",l:+e[1],a:+e[2],b:+e[3]};else{if(!(e=r.match(D)))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}]},or=s(4),ir=function(r){var e=r.l,a=r.a,n=r.b,t=r.alpha,o=or(Math.sqrt(a*a+n*n)),i={mode:"lch",l:e,c:o};return o&&(i.h=v(180*Math.atan2(n,a)/Math.PI)),void 0!==t&&(i.alpha=t),i},lr=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},ur={mode:"lch",output:{lab:lr,rgb:function(r){return er(lr(r))}},input:{rgb:function(r){return ir(nr(r))},lch:ir},channels:["l","c","h"],parsers:[function(r){var e=r.match(B);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}}]};n(F),n(N),n(T),n(W),n(X),n(Y),n(tr),n(ur);var hr=h("rgb"),sr=h("lrgb"),dr=h("hsl"),br=h("hsv"),cr=h("hsi"),gr=h("hwb"),pr=h("lab"),vr=h("lch"),fr=hr,mr=Object.freeze({hsl:dr,hsv:br,hsi:cr,hwb:gr,rgb:hr,lab:pr,lch:vr,lrgb:sr,css:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"rgb";return function(e){var a=d()(b(e)).slice(0,3).map(g).concat([1===e.alpha?void 0:e.alpha]);return"hex"===r?"#"+(1<<24|a[0]<<16|a[1]<<8|a[2]).toString(16).slice(1):"rgb"===r?void 0===a[3]?"rgb("+a[0]+", "+a[1]+", "+a[2]+")":"rgba("+a[0]+", "+a[1]+", "+a[2]+", "+c(a[3])+")":void 0}},converter:h,brighten:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb",a=r>0?0-r:1/(2+r),n=h(e);return function(r){var t=h(r.mode),o=Object.assign({},n(r));switch(e){case"rgb":case"lrgb":o.r*=Math.pow(.7,a),o.g*=Math.pow(.7,a),o.b*=Math.pow(.7,a);break;case"hsl":case"lab":case"lch":o.l*=exp;break;case"hsv":o.v*=exp;break;case"hsi":o.i*=exp}return t(o)}},round:s,parse:o,named:p,interpolate:function(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb";if(!(r.length<2)){var a=r.map(h(e));return function(r){var n=(r=Math.min(Math.max(0,r),1))*(a.length-1),o=Math.floor(n),l=a[o],u=1===r?a[o]:a[o+1],h=n-o;return i(t(e).map(function(r){return function(r){return"h"===r?y:"alpha"===r?w:m}(r)(l[r],u[r],h)}),e)}}},samples:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2;if(r<2)return r<1?[]:[.5];for(var e=[],a=0;a<r;a++)e.push(a/(r-1));return e},fromArray:i,toArray:d,default:fr});return Object.assign(fr,mr),fr}); |
var converters = {}; | ||
var components = {}; | ||
var _channels = {}; | ||
var parsers = []; | ||
@@ -9,3 +9,3 @@ | ||
output = _ref.output, | ||
keys = _ref.keys, | ||
channels = _ref.channels, | ||
p = _ref.parsers; | ||
@@ -20,3 +20,3 @@ | ||
}); | ||
components[mode] = keys; | ||
_channels[mode] = channels.concat('alpha'); | ||
(p || []).forEach(function (parser) { | ||
@@ -27,2 +27,6 @@ return parsers.push(parser); | ||
var getChannels = function getChannels(mode) { | ||
return _channels[mode]; | ||
}; | ||
var parse = function parse(color) { | ||
@@ -38,2 +42,12 @@ var result = void 0, | ||
var fromArray = (function (color, mode) { | ||
var res = { mode: mode }; | ||
getChannels(mode).forEach(function (k, idx) { | ||
if (color[idx] !== undefined) { | ||
res[k] = color[idx]; | ||
} | ||
}); | ||
return res; | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
@@ -60,3 +74,3 @@ return typeof obj; | ||
var prepare = function prepare(color, mode) { | ||
return (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color; | ||
return (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : Array.isArray(color) ? fromArray(color, mode) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color; | ||
}; | ||
@@ -100,26 +114,15 @@ | ||
var invariant = function invariant(k, v) { | ||
return v; | ||
}; | ||
var transform = (function () { | ||
var fn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : invariant; | ||
return function (color) { | ||
var res = { mode: color.mode }, | ||
mapped = void 0; | ||
components[color.mode].forEach(function (key) { | ||
if ((mapped = fn(color[key], key)) !== undefined) { | ||
res[key] = mapped; | ||
} | ||
}); | ||
return res; | ||
}; | ||
var toArray$1 = (function () { | ||
return function (color) { | ||
return getChannels(color.mode).map(function (k) { | ||
return color[k]; | ||
}); | ||
}; | ||
}); | ||
var clampRGB = transform(function (v, k) { | ||
return k === 'alpha' ? v : Math.round(Math.max(0, Math.min(v, 1)) * 255); | ||
}); | ||
var rgb = converter('rgb'); | ||
var roundAlpha = round(2); | ||
var clamp = function clamp(v) { | ||
return Math.round(Math.max(0, Math.min(v, 1)) * 255); | ||
}; | ||
@@ -129,15 +132,15 @@ var css = (function () { | ||
return function (c) { | ||
var color = clampRGB(rgb(c)); | ||
var color = toArray$1()(rgb(c)).slice(0, 3).map(clamp).concat([c.alpha === 1 ? undefined : c.alpha]); | ||
if (format === 'hex') { | ||
return '#' + (1 << 24 | color.r << 16 | color.g << 8 | color.b).toString(16).slice(1); | ||
return '#' + (1 << 24 | color[0] << 16 | color[1] << 8 | color[2]).toString(16).slice(1); | ||
} | ||
if (format === 'rgb') { | ||
if (color.alpha === undefined || color.alpha === 255) { | ||
if (color[3] === undefined) { | ||
// opaque color | ||
return 'rgb(' + color.r + ', ' + color.g + ', ' + color.b + ')'; | ||
return 'rgb(' + color[0] + ', ' + color[1] + ', ' + color[2] + ')'; | ||
} else { | ||
// transparent color | ||
return 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + roundAlpha(color.alpha) + ')'; | ||
return 'rgba(' + color[0] + ', ' + color[1] + ', ' + color[2] + ', ' + roundAlpha(color[3]) + ')'; | ||
} | ||
@@ -326,2 +329,6 @@ } | ||
var method = function method(k) { | ||
return k === 'h' ? hue : k === 'alpha' ? alpha : generic; | ||
}; | ||
var interpolate = (function (seeds) { | ||
@@ -348,7 +355,5 @@ var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'rgb'; | ||
// create a new color in the mode given, and map its values | ||
return transform(function (v, k) { | ||
var method = k === 'h' ? hue : k === 'alpha' ? alpha : generic; | ||
return method(startColor[k], endColor[k], t0); | ||
})({ mode: mode }); | ||
return fromArray(getChannels(mode).map(function (k) { | ||
return method(k)(startColor[k], endColor[k], t0); | ||
}), mode); | ||
}; | ||
@@ -562,3 +567,3 @@ }); | ||
mode: 'rgb', | ||
keys: ['r', 'g', 'b', 'alpha'], | ||
channels: ['r', 'g', 'b'], | ||
parsers: [parseHex, parseRgb, parseNamed, parseTransparent] | ||
@@ -615,3 +620,3 @@ }; | ||
}, | ||
keys: ['r', 'g', 'b', 'alpha'] | ||
channels: ['r', 'g', 'b'] | ||
}; | ||
@@ -711,3 +716,3 @@ | ||
}, | ||
keys: ['h', 's', 'l', 'alpha'], | ||
channels: ['h', 's', 'l'], | ||
parsers: [parseHsl] | ||
@@ -776,3 +781,3 @@ }; | ||
}, | ||
keys: ['h', 's', 'v', 'alpha'] | ||
channels: ['h', 's', 'v'] | ||
}; | ||
@@ -871,3 +876,3 @@ | ||
}, | ||
keys: ['h', 's', 'i', 'alpha'] | ||
channels: ['h', 's', 'i'] | ||
}; | ||
@@ -962,3 +967,3 @@ | ||
}, | ||
keys: ['h', 'w', 'b', 'alpha'], | ||
channels: ['h', 'w', 'b'], | ||
parsers: [parseHwb] | ||
@@ -1110,3 +1115,3 @@ }; | ||
}, | ||
keys: ['l', 'a', 'b', 'alpha'], | ||
channels: ['l', 'a', 'b'], | ||
parsers: [parseLab] | ||
@@ -1204,3 +1209,3 @@ }; | ||
}, | ||
keys: ['l', 'c', 'h', 'alpha'], | ||
channels: ['l', 'c', 'h'], | ||
parsers: [parseLch] | ||
@@ -1230,2 +1235,2 @@ }; | ||
export default culori; | ||
export { hsl, hsv, hsi, hwb$1 as hwb, rgb$1 as rgb, lab$1 as lab, lch$1 as lch, lrgb, css, converter, brighten, round, parse, named, transform, interpolate, samples }; | ||
export { hsl, hsv, hsi, hwb$1 as hwb, rgb$1 as rgb, lab$1 as lab, lch$1 as lch, lrgb, css, converter, brighten, round, parse, named, interpolate, samples, fromArray, toArray$1 as toArray }; |
{ | ||
"name": "culori", | ||
"version": "0.2.61", | ||
"version": "0.2.62", | ||
"main": "build/culori.js", | ||
@@ -5,0 +5,0 @@ "module": "build/index.js", |
import parse from './parse'; | ||
import { converters } from './modes'; | ||
import fromArray from './fromArray'; | ||
@@ -7,5 +8,7 @@ const prepare = (color, mode) => | ||
parse(color) | ||
: color.mode === undefined ? | ||
{...color, mode: mode } | ||
: color; | ||
: Array.isArray(color) ? | ||
fromArray(color, mode) | ||
: color.mode === undefined ? | ||
{...color, mode: mode } | ||
: color; | ||
@@ -12,0 +15,0 @@ const converter = (target_mode = 'rgb') => |
import converter from './converter'; | ||
import round from './round'; | ||
import transform from './transform'; | ||
import toArray from './toArray'; | ||
let clampRGB = transform( | ||
(v, k) => k === 'alpha' ? v : Math.round(Math.max(0, Math.min(v, 1)) * 255) | ||
); | ||
let rgb = converter('rgb'); | ||
let roundAlpha = round(2); | ||
let clamp = v => Math.round(Math.max(0, Math.min(v, 1)) * 255); | ||
export default (format = 'rgb') => | ||
c => { | ||
let color = clampRGB(rgb(c)); | ||
let color = toArray()(rgb(c)) | ||
.slice(0, 3) | ||
.map(clamp) | ||
.concat([c.alpha === 1 ? undefined : c.alpha ]); | ||
if (format === 'hex') { | ||
return '#' + (1 << 24 | color.r << 16 | color.g << 8 | color.b).toString(16).slice(1); | ||
return '#' + (1 << 24 | color[0] << 16 | color[1] << 8 | color[2]).toString(16).slice(1); | ||
} | ||
if (format === 'rgb') { | ||
if (color.alpha === undefined || color.alpha === 255) { | ||
if (color[3] === undefined) { | ||
// opaque color | ||
return `rgb(${color.r}, ${color.g}, ${color.b})`; | ||
return `rgb(${color[0]}, ${color[1]}, ${color[2]})`; | ||
} else { | ||
// transparent color | ||
return `rgba(${color.r}, ${color.g}, ${color.b}, ${ roundAlpha(color.alpha) })`; | ||
return `rgba(${color[0]}, ${color[1]}, ${color[2]}, ${ roundAlpha(color[3]) })`; | ||
} | ||
} | ||
} |
@@ -12,3 +12,3 @@ import convertHsiToRgb from './convertHsiToRgb'; | ||
}, | ||
keys: ['h', 's', 'i', 'alpha'] | ||
channels: ['h', 's', 'i'] | ||
} |
@@ -13,4 +13,4 @@ import convertHslToRgb from './convertHslToRgb'; | ||
}, | ||
keys: ['h', 's', 'l', 'alpha'], | ||
channels: ['h', 's', 'l'], | ||
parsers: [ parseHsl ] | ||
}; |
@@ -12,3 +12,3 @@ import convertHsvToRgb from './convertHsvToRgb'; | ||
}, | ||
keys: ['h', 's', 'v', 'alpha'] | ||
channels: ['h', 's', 'v'] | ||
}; |
@@ -13,4 +13,4 @@ import convertHwbToRgb from './convertHwbToRgb'; | ||
}, | ||
keys: ['h', 'w', 'b', 'alpha'], | ||
channels: ['h', 'w', 'b'], | ||
parsers: [ parseHwb ] | ||
}; |
@@ -5,6 +5,7 @@ import css from './css'; | ||
import named from './colors/named'; | ||
import transform from './transform'; | ||
import interpolate from './interpolate'; | ||
import samples from './samples'; | ||
import brighten from './brighten'; | ||
import fromArray from './fromArray'; | ||
import toArray from './toArray'; | ||
@@ -59,7 +60,8 @@ import parse from './parse'; | ||
named, | ||
transform, | ||
interpolate, | ||
samples | ||
samples, | ||
fromArray, | ||
toArray | ||
}; | ||
export default culori; |
import converter from './converter'; | ||
import transform from './transform'; | ||
import normalizeHue from './util/normalizeHue'; | ||
import { getChannels } from './modes'; | ||
import fromArray from './fromArray'; | ||
@@ -31,2 +32,4 @@ const linear = (a, b, t) => a + t * (b - a); | ||
let method = k => k === 'h' ? hue : k === 'alpha' ? alpha : generic; | ||
export default (seeds, mode = 'rgb') => { | ||
@@ -51,10 +54,7 @@ if (seeds.length < 2) { | ||
// create a new color in the mode given, and map its values | ||
return transform( | ||
(v, k) => { | ||
let method = k === 'h' ? hue : k === 'alpha' ? alpha : generic; | ||
return method(startColor[k], endColor[k], t0); | ||
} | ||
)({ mode: mode }) ; | ||
return fromArray( | ||
getChannels(mode).map(k => method(k)(startColor[k], endColor[k], t0)), | ||
mode | ||
); | ||
}; | ||
}; |
@@ -13,4 +13,4 @@ import convertLabToRgb from './convertLabToRgb'; | ||
}, | ||
keys: ['l', 'a', 'b', 'alpha'], | ||
channels: ['l', 'a', 'b'], | ||
parsers: [ parseLab ] | ||
}; |
@@ -17,4 +17,4 @@ import convertLabToLch from './convertLabToLch'; | ||
}, | ||
keys: ['l', 'c', 'h', 'alpha'], | ||
channels: ['l', 'c', 'h'], | ||
parsers: [ parseLch ] | ||
}; |
@@ -12,3 +12,3 @@ import convertRgbToLrgb from './convertRgbToLrgb'; | ||
}, | ||
keys: ['r', 'g', 'b', 'alpha'] | ||
channels: ['r', 'g', 'b'] | ||
}; |
const converters = {}; | ||
const components = {}; | ||
const _channels = {}; | ||
const parsers = []; | ||
const defineMode = ({ mode, input, output, keys, parsers: p }) => { | ||
const defineMode = ({ mode, input, output, channels, parsers: p }) => { | ||
converters[mode] = Object.assign(converters[mode] || {}, output); | ||
@@ -13,6 +13,13 @@ Object.keys(input || {}).forEach(k => { | ||
}); | ||
components[mode] = keys; | ||
_channels[mode] = channels.concat('alpha'); | ||
(p || []).forEach(parser => parsers.push(parser)); | ||
} | ||
export { defineMode, components, converters, parsers }; | ||
const getChannels = (mode) => _channels[mode]; | ||
export { | ||
defineMode, | ||
getChannels, | ||
converters, | ||
parsers | ||
}; |
@@ -8,4 +8,4 @@ import parseNamed from './parseNamed'; | ||
mode: 'rgb', | ||
keys: ['r', 'g', 'b', 'alpha'], | ||
channels: ['r', 'g', 'b'], | ||
parsers: [ parseHex, parseRgb, parseNamed, parseTransparent ] | ||
}; |
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
110165
67
3362