Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

culori

Package Overview
Dependencies
Maintainers
1
Versions
256
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

culori - npm Package Compare versions

Comparing version 0.2.62 to 0.2.63

116

build/culori.js

@@ -45,12 +45,2 @@ (function (global, factory) {

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) {

@@ -77,3 +67,3 @@ return typeof obj;

var prepare = function prepare(color, mode) {
return (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : Array.isArray(color) ? fromArray(color, mode) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color;
return (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color;
};

@@ -117,10 +107,2 @@

var toArray$1 = (function () {
return function (color) {
return getChannels(color.mode).map(function (k) {
return color[k];
});
};
});
var rgb = converter('rgb');

@@ -135,15 +117,18 @@ var roundAlpha = round(2);

return function (c) {
var color = toArray$1()(rgb(c)).slice(0, 3).map(clamp).concat([c.alpha === 1 ? undefined : c.alpha]);
var color = rgb(c);
color.r = clamp(color.r);
color.b = clamp(color.b);
color.g = clamp(color.g);
if (format === 'hex') {
return '#' + (1 << 24 | color[0] << 16 | color[1] << 8 | color[2]).toString(16).slice(1);
return '#' + (1 << 24 | color.r << 16 | color.g << 8 | color.b).toString(16).slice(1);
}
if (format === 'rgb') {
if (color[3] === undefined) {
if (c.alpha === undefined || c.alpha === 1) {
// opaque color
return 'rgb(' + color[0] + ', ' + color[1] + ', ' + color[2] + ')';
return 'rgb(' + color.r + ', ' + color.g + ', ' + color.b + ')';
} else {
// transparent color
return 'rgba(' + color[0] + ', ' + color[1] + ', ' + color[2] + ', ' + roundAlpha(color[3]) + ')';
return 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + roundAlpha(color.alpha) + ')';
}

@@ -332,7 +317,8 @@ }

var method = function method(k) {
return k === 'h' ? hue : k === 'alpha' ? alpha : generic;
var method = {
'h': hue,
'alpha': alpha
};
var interpolate = (function (seeds) {
var interpolate = function interpolate(seeds) {
var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'rgb';

@@ -345,2 +331,10 @@

var colors = seeds.map(converter(mode));
var channels = getChannels(mode);
var startColor = void 0,
endColor = void 0,
cls = void 0,
idx = void 0,
t0 = void 0,
res = void 0,
val = void 0;

@@ -353,13 +347,18 @@ return function (t) {

// find out between which two colors we need to interpolate
var cls = t * (colors.length - 1);
var idx = Math.floor(cls);
var startColor = colors[idx];
var endColor = t === 1 ? colors[idx] : colors[idx + 1];
var t0 = cls - idx;
cls = t * (colors.length - 1);
idx = Math.floor(cls);
startColor = colors[idx];
endColor = t === 1 ? colors[idx] : colors[idx + 1];
t0 = cls - idx;
return fromArray(getChannels(mode).map(function (k) {
return method(k)(startColor[k], endColor[k], t0);
}), mode);
res = { mode: mode };
channels.forEach(function (k) {
if ((val = (method[k] || generic)(startColor[k], endColor[k], t0)) !== undefined) {
res[k] = val;
}
});
return res;
};
});
};

@@ -379,42 +378,2 @@ var samples = (function () {

var brighten = (function (beta) {
var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'rgb';
var gamma = beta > 0 ? 0 - beta : 1 / (2 + beta);
var conv = converter(mode);
return function (color) {
var conv_back = converter(color.mode);
var res = Object.assign({}, conv(color));
switch (mode) {
case 'rgb':
case 'lrgb':
res.r *= Math.pow(0.7, gamma);
res.g *= Math.pow(0.7, gamma);
res.b *= Math.pow(0.7, gamma);
break;
case 'hsl':
case 'lab':
case 'lch':
res.l *= exp;
break;
case 'hsv':
res.v *= exp;
break;
case 'hsi':
res.i *= exp;
break;
case 'hwb':
// ?
break;
}
return conv_back(res);
};
});
var parseNumber = (function (color, len) {

@@ -1242,3 +1201,2 @@

converter: converter,
brighten: brighten,
round: round,

@@ -1249,4 +1207,4 @@ parse: parse,

samples: samples,
fromArray: fromArray,
toArray: toArray$1,
defineMode: defineMode,
getChannels: getChannels,
default: culori

@@ -1253,0 +1211,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=[],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});
!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,h=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"),(h||[]).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"==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},l=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":i(r))?o(r):void 0===r.mode?l({},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}},u=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=h("rgb"),s=u(2),b=function(r){return Math.round(255*Math.max(0,Math.min(r,1)))},g={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},c=function(r){return(r%=360)<0?r+360:r},v=function(r,e,a){return r+a*(e-r)},p={h:function(r,e,a){return void 0!==r&&void 0!==e?(r=c(r),e=c(e),Math.abs(e-r)>180?c(v(r,e-360*Math.sign(e-r),a)):v(r,e,a)):void 0===r?e:r},alpha: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)}},f=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,""),y=m+"%",w="(?:"+m+"%|"+m+")",k="(?:"+m+"(deg|grad|rad|turn)|"+m+")",M="\\s*,\\s*",x="\\s+",E=new RegExp("^rgba?\\(\\s*"+m+M+m+M+m+"\\s*(?:,\\s*"+w+"\\s*)?\\)$"),$=new RegExp("^rgba?\\(\\s*"+y+M+y+M+y+"\\s*(?:,\\s*"+w+"\\s*)?\\)$"),q=new RegExp("^rgba?\\(\\s*"+m+x+m+x+m+"\\s*(?:\\/\\s*"+w+"\\s*)?\\)$"),R=new RegExp("^rgba?\\(\\s*"+y+x+y+x+y+"\\s*(?:\\/\\s*"+w+"\\s*)?\\)$"),j=new RegExp("^hsla?\\(\\s*"+k+M+y+M+y+"\\s*(?:,\\s*"+w+"\\s*)?\\)$"),O=new RegExp("^hsla?\\(\\s*"+k+x+y+x+y+"\\s*(?:\\/\\s*"+w+"\\s*)?\\)$"),z=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,S=new RegExp("^hwb\\(\\s*"+k+x+y+x+y+"\\s*(?:\\/\\s*"+w+"\\s*)?\\)$"),I=new RegExp("^lab\\(\\s*"+m+x+m+x+m+"\\s*(?:\\/\\s*"+w+"\\s*)?\\)$"),P=new RegExp("^lch\\(\\s*"+m+x+m+x+k+"\\s*(?:\\/\\s*"+w+"\\s*)?\\)$"),C=new RegExp("^gray\\(\\s*"+m+"()()\\s*(?:\\/\\s*"+w+"\\s*)?\\)$"),L={mode:"rgb",channels:["r","g","b"],parsers:[function(r){var e;return(e=r.match(z))?f(parseInt(e[1],16),e[1].length):void 0},function(r){var e=void 0,a=void 0;if(e=r.match(E)||r.match(q))a={mode:"rgb",r:e[1]/255,g:e[2]/255,b:e[3]/255};else{if(!(e=r.match($)||r.match(R)))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&&f(g[r.toLowerCase()],6)||void 0},function(r){return"transparent"===r?f(0,8):void 0}]},A=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:A(e),g:A(a),b:A(n)};return void 0!==t&&(o.alpha=t),o},D=function(r){return r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r},F=function(r){var e=r.r,a=r.g,n=r.b,t=r.alpha,o={mode:"rgb",r:D(e),g:D(a),b:D(n)};return void 0!==t&&(o.alpha=t),o},G={mode:"lrgb",output:{rgb:F},input:{rgb:B},channels:["r","g","b"]};var H=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}},J={mode:"hsl",output:{rgb:function(r){var e=r.h,a=r.s,n=r.l,t=r.alpha;e=c(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(j)||r.match(O);if(e){var a={mode:"hsl",h:void 0===e[3]?H(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 K(r){var e=r.h,a=r.s,n=r.v,t=r.alpha;e=c(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 N(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 Q={mode:"hsv",output:{rgb:K},input:{rgb:N},channels:["h","s","v"]};var T={mode:"hsi",output:{rgb:function(r){var e=r.h,a=r.s,n=r.i,t=r.alpha;e=c(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 U={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 K({h:e,s:1===n?1:1-a/(1-n),v:1-n,alpha:t})}},input:{rgb:function(r){var e=N(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(S);if(e){var a={mode:"hwb",h:void 0===e[3]?H(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=Math.pow(29,3)/Math.pow(3,3),W=Math.pow(6,3)/Math.pow(29,3),X=function(r){return Math.pow(r,3)>W?Math.pow(r,3):(116*r-16)/V},Y=function(r){var e,a,n,t,o,i=function(r){var e=r.x,a=r.y,n=r.z;return F({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*X(n/500+t),y:1*X(t),z:1.08883*X(o)}));return i.mode="rgb",void 0!==r.alpha&&(i.alpha=r.alpha),i},Z=function(r){return r>W?Math.cbrt(r):(V*r+16)/116},_=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=Z(a/.95047),{l:116*(i=Z(n/1))-16,a:500*(o-i),b:200*(i-Z(t/1.08883))});return l.mode="lab",void 0!==r.alpha&&(l.alpha=r.alpha),l},rr={mode:"lab",output:{rgb:Y},input:{rgb:_},channels:["l","a","b"],parsers:[function(r){var e=void 0,a=void 0;if(e=r.match(I))a={mode:"lab",l:+e[1],a:+e[2],b:+e[3]};else{if(!(e=r.match(C)))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}]},er=u(4),ar=function(r){var e=r.l,a=r.a,n=r.b,t=r.alpha,o=er(Math.sqrt(a*a+n*n)),i={mode:"lch",l:e,c:o};return o&&(i.h=c(180*Math.atan2(n,a)/Math.PI)),void 0!==t&&(i.alpha=t),i},nr=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},tr={mode:"lch",output:{lab:nr,rgb:function(r){return Y(nr(r))}},input:{rgb:function(r){return ar(_(r))},lch:ar},channels:["l","c","h"],parsers:[function(r){var e=r.match(P);if(e){var a={mode:"lch",l:+e[1],c:Math.max(0,+e[2]),h:void 0===e[5]?H(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(L),n(G),n(J),n(Q),n(T),n(U),n(rr),n(tr);var or=h("rgb"),ir=h("lrgb"),lr=h("hsl"),hr=h("hsv"),ur=h("hsi"),dr=h("hwb"),sr=h("lab"),br=h("lch"),gr=or,cr=Object.freeze({hsl:lr,hsv:hr,hsi:ur,hwb:dr,rgb:or,lab:sr,lch:br,lrgb:ir,css:function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"rgb";return function(e){var a=d(e);return a.r=b(a.r),a.b=b(a.b),a.g=b(a.g),"hex"===r?"#"+(1<<24|a.r<<16|a.g<<8|a.b).toString(16).slice(1):"rgb"===r?void 0===e.alpha||1===e.alpha?"rgb("+a.r+", "+a.g+", "+a.b+")":"rgba("+a.r+", "+a.g+", "+a.b+", "+s(a.alpha)+")":void 0}},converter:h,round:u,parse:o,named:g,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)),n=t(e),o=void 0,i=void 0,l=void 0,u=void 0,d=void 0,s=void 0,b=void 0;return function(r){return r=Math.min(Math.max(0,r),1),l=r*(a.length-1),u=Math.floor(l),o=a[u],i=1===r?a[u]:a[u+1],d=l-u,s={mode:e},n.forEach(function(r){void 0!==(b=(p[r]||function(r,e,a){return void 0!==r&&void 0!==e?v(r,e,a):void 0===r?e:r})(o[r],i[r],d))&&(s[r]=b)}),s}}},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},defineMode:n,getChannels:t,default:gr});return Object.assign(gr,cr),gr});

@@ -39,12 +39,2 @@ var converters = {};

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) {

@@ -71,3 +61,3 @@ return typeof obj;

var prepare = function prepare(color, mode) {
return (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : Array.isArray(color) ? fromArray(color, mode) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color;
return (typeof color === 'undefined' ? 'undefined' : _typeof(color)) !== 'object' ? parse(color) : color.mode === undefined ? _extends({}, color, { mode: mode }) : color;
};

@@ -111,10 +101,2 @@

var toArray$1 = (function () {
return function (color) {
return getChannels(color.mode).map(function (k) {
return color[k];
});
};
});
var rgb = converter('rgb');

@@ -129,15 +111,18 @@ var roundAlpha = round(2);

return function (c) {
var color = toArray$1()(rgb(c)).slice(0, 3).map(clamp).concat([c.alpha === 1 ? undefined : c.alpha]);
var color = rgb(c);
color.r = clamp(color.r);
color.b = clamp(color.b);
color.g = clamp(color.g);
if (format === 'hex') {
return '#' + (1 << 24 | color[0] << 16 | color[1] << 8 | color[2]).toString(16).slice(1);
return '#' + (1 << 24 | color.r << 16 | color.g << 8 | color.b).toString(16).slice(1);
}
if (format === 'rgb') {
if (color[3] === undefined) {
if (c.alpha === undefined || c.alpha === 1) {
// opaque color
return 'rgb(' + color[0] + ', ' + color[1] + ', ' + color[2] + ')';
return 'rgb(' + color.r + ', ' + color.g + ', ' + color.b + ')';
} else {
// transparent color
return 'rgba(' + color[0] + ', ' + color[1] + ', ' + color[2] + ', ' + roundAlpha(color[3]) + ')';
return 'rgba(' + color.r + ', ' + color.g + ', ' + color.b + ', ' + roundAlpha(color.alpha) + ')';
}

@@ -326,7 +311,8 @@ }

var method = function method(k) {
return k === 'h' ? hue : k === 'alpha' ? alpha : generic;
var method = {
'h': hue,
'alpha': alpha
};
var interpolate = (function (seeds) {
var interpolate = function interpolate(seeds) {
var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'rgb';

@@ -339,2 +325,10 @@

var colors = seeds.map(converter(mode));
var channels = getChannels(mode);
var startColor = void 0,
endColor = void 0,
cls = void 0,
idx = void 0,
t0 = void 0,
res = void 0,
val = void 0;

@@ -347,13 +341,18 @@ return function (t) {

// find out between which two colors we need to interpolate
var cls = t * (colors.length - 1);
var idx = Math.floor(cls);
var startColor = colors[idx];
var endColor = t === 1 ? colors[idx] : colors[idx + 1];
var t0 = cls - idx;
cls = t * (colors.length - 1);
idx = Math.floor(cls);
startColor = colors[idx];
endColor = t === 1 ? colors[idx] : colors[idx + 1];
t0 = cls - idx;
return fromArray(getChannels(mode).map(function (k) {
return method(k)(startColor[k], endColor[k], t0);
}), mode);
res = { mode: mode };
channels.forEach(function (k) {
if ((val = (method[k] || generic)(startColor[k], endColor[k], t0)) !== undefined) {
res[k] = val;
}
});
return res;
};
});
};

@@ -373,42 +372,2 @@ var samples = (function () {

var brighten = (function (beta) {
var mode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'rgb';
var gamma = beta > 0 ? 0 - beta : 1 / (2 + beta);
var conv = converter(mode);
return function (color) {
var conv_back = converter(color.mode);
var res = Object.assign({}, conv(color));
switch (mode) {
case 'rgb':
case 'lrgb':
res.r *= Math.pow(0.7, gamma);
res.g *= Math.pow(0.7, gamma);
res.b *= Math.pow(0.7, gamma);
break;
case 'hsl':
case 'lab':
case 'lch':
res.l *= exp;
break;
case 'hsv':
res.v *= exp;
break;
case 'hsi':
res.i *= exp;
break;
case 'hwb':
// ?
break;
}
return conv_back(res);
};
});
var parseNumber = (function (color, len) {

@@ -1226,2 +1185,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, interpolate, samples, fromArray, toArray$1 as toArray };
export { hsl, hsv, hsi, hwb$1 as hwb, rgb$1 as rgb, lab$1 as lab, lch$1 as lch, lrgb, css, converter, round, parse, named, interpolate, samples, defineMode, getChannels };
{
"name": "culori",
"version": "0.2.62",
"version": "0.2.63",
"main": "build/culori.js",

@@ -5,0 +5,0 @@ "module": "build/index.js",

import parse from './parse';
import { converters } from './modes';
import fromArray from './fromArray';

@@ -8,7 +7,5 @@ const prepare = (color, mode) =>

parse(color)
: Array.isArray(color) ?
fromArray(color, mode)
: color.mode === undefined ?
{...color, mode: mode }
: color;
: color.mode === undefined ?
{...color, mode: mode }
: color;

@@ -15,0 +12,0 @@ const converter = (target_mode = 'rgb') =>

import converter from './converter';
import round from './round';
import toArray from './toArray';
let rgb = converter('rgb');

@@ -11,20 +9,20 @@ let roundAlpha = round(2);

c => {
let color = toArray()(rgb(c))
.slice(0, 3)
.map(clamp)
.concat([c.alpha === 1 ? undefined : c.alpha ]);
let color = rgb(c);
color.r = clamp(color.r);
color.b = clamp(color.b);
color.g = clamp(color.g);
if (format === 'hex') {
return '#' + (1 << 24 | color[0] << 16 | color[1] << 8 | color[2]).toString(16).slice(1);
return '#' + (1 << 24 | color.r << 16 | color.g << 8 | color.b).toString(16).slice(1);
}
if (format === 'rgb') {
if (color[3] === undefined) {
if (c.alpha === undefined || c.alpha === 1) {
// opaque color
return `rgb(${color[0]}, ${color[1]}, ${color[2]})`;
return `rgb(${color.r}, ${color.g}, ${color.b})`;
} else {
// transparent color
return `rgba(${color[0]}, ${color[1]}, ${color[2]}, ${ roundAlpha(color[3]) })`;
return `rgba(${color.r}, ${color.g}, ${color.b}, ${ roundAlpha(color.alpha) })`;
}
}
}

@@ -7,9 +7,6 @@ import css from './css';

import samples from './samples';
import brighten from './brighten';
import fromArray from './fromArray';
import toArray from './toArray';
import parse from './parse';
import { defineMode } from './modes';
import { defineMode, getChannels } from './modes';

@@ -56,3 +53,2 @@ import rgbDef from './rgb/definition';

converter,
brighten,
round,

@@ -63,6 +59,7 @@ parse,

samples,
fromArray,
toArray
defineMode,
getChannels
};
export default culori;
import converter from './converter';
import normalizeHue from './util/normalizeHue';
import { getChannels } from './modes';
import fromArray from './fromArray';

@@ -32,5 +31,8 @@ const linear = (a, b, t) => a + t * (b - a);

let method = k => k === 'h' ? hue : k === 'alpha' ? alpha : generic;
const method = {
'h': hue,
'alpha': alpha
}
export default (seeds, mode = 'rgb') => {
const interpolate = (seeds, mode = 'rgb') => {
if (seeds.length < 2) {

@@ -41,2 +43,4 @@ return undefined;

let colors = seeds.map(converter(mode));
let channels = getChannels(mode);
let startColor, endColor, cls, idx, t0, res, val;

@@ -49,13 +53,19 @@ return t => {

// find out between which two colors we need to interpolate
let cls = t * (colors.length - 1);
let idx = Math.floor(cls);
let startColor = colors[idx];
let endColor = t === 1 ? colors[idx] : colors[idx + 1];
let t0 = (cls - idx);
cls = t * (colors.length - 1);
idx = Math.floor(cls);
startColor = colors[idx];
endColor = t === 1 ? colors[idx] : colors[idx + 1];
t0 = cls - idx;
return fromArray(
getChannels(mode).map(k => method(k)(startColor[k], endColor[k], t0)),
mode
);
res = { mode: mode };
channels.forEach(k => {
if ((val = (method[k] || generic)(startColor[k], endColor[k], t0)) !== undefined) {
res[k] = val;
}
});
return res;
};
};
};
export default interpolate;
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc