Comparing version 0.2.4 to 0.2.5
@@ -32,6 +32,4 @@ (function (global, factory) { | ||
} | ||
res['mode'] = 'rgb'; | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
res.mode = 'rgb'; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -64,6 +62,4 @@ } | ||
} | ||
res['mode'] = 'rgb'; | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
res.mode = 'rgb'; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -126,6 +122,5 @@ } | ||
} | ||
res['mode'] = 'rgb'; | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
res.mode = 'rgb'; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -150,8 +145,4 @@ } | ||
}; | ||
if (M - m !== 0) { | ||
res['h'] = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
} | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -176,8 +167,4 @@ } | ||
}; | ||
if (M - m !== 0) { | ||
res['h'] = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
} | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -202,8 +189,4 @@ } | ||
}; | ||
if (M - m !== 0) { | ||
res['h'] = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
} | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -488,2 +471,4 @@ } | ||
var hwb = new RegExp('^hwb\\(\\s*' + hue + '\\s+' + sp + '\\s+' + sp + '\\s*(?:\\/\\s*' + pn + '\\s*)?\\)$'); | ||
var parseHex = (function (color) { | ||
@@ -495,3 +480,3 @@ var match; | ||
var parseRgb = (function (color) { | ||
var match = match = color.match(rgb_legacy) || color.match(rgb_current); | ||
var match = color.match(rgb_legacy) || color.match(rgb_current); | ||
if (!match) return; | ||
@@ -506,5 +491,5 @@ var res = { | ||
if (match[7] !== undefined) { | ||
res['a'] = match[7] / 100; | ||
res.a = match[7] / 100; | ||
} else if (match[8] !== undefined) { | ||
res['a'] = +match[8]; | ||
res.a = +match[8]; | ||
} | ||
@@ -518,3 +503,3 @@ | ||
case 'deg': | ||
return val; | ||
return +val; | ||
case 'rad': | ||
@@ -535,3 +520,3 @@ return val / Math.PI * 180; | ||
mode: 'hsl', | ||
h: match[3] === undefined ? +hue$1(match[1], match[2]) : +match[3], | ||
h: match[3] === undefined ? hue$1(match[1], match[2]) : +match[3], | ||
s: match[4] / 100, | ||
@@ -541,5 +526,5 @@ l: match[5] / 100 | ||
if (match[6] !== undefined) { | ||
res['a'] = match[6] / 100; | ||
res.a = match[6] / 100; | ||
} else if (match[7] !== undefined) { | ||
res['a'] = match[7] / 255; | ||
res.a = match[7] / 255; | ||
} | ||
@@ -550,4 +535,30 @@ // TODO better way to normalize than via rgb? | ||
var parseHwb = (function (color) { | ||
if (typeof color !== 'string') return; | ||
var match = color.match(hwb); | ||
if (!match) return undefined; | ||
var res = { | ||
mode: 'hwb', | ||
h: match[3] === undefined ? hue$1(match[1], match[2]) : +match[3], | ||
w: match[4] / 100, | ||
b: match[5] / 100 | ||
}; | ||
// normalize w + b to at most 1 | ||
if (res.w + res.b > 1) { | ||
var s = res.w + res.b; | ||
res.w /= s; | ||
res.b /= s; | ||
} | ||
if (match[6] !== undefined) { | ||
res.a = match[6] / 100; | ||
} else if (match[7] !== undefined) { | ||
res.a = match[7] / 255; | ||
} | ||
return res; | ||
}); | ||
var parse = function parse(color) { | ||
return parseHex(color) || parseRgb(color) || parseHsl(color) || parseNamed(color) || (color === 'transparent' ? parseNumber(0, 8) : undefined); | ||
return parseHex(color) || parseRgb(color) || parseHsl(color) || parseNamed(color) || (color === 'transparent' ? parseNumber(0x00000000, 8) : undefined) || parseHwb(color); | ||
}; | ||
@@ -560,3 +571,4 @@ | ||
rgb: parseRgb, | ||
hsl: parseHsl | ||
hsl: parseHsl, | ||
hwb: parseHwb | ||
}); | ||
@@ -600,2 +612,6 @@ | ||
var hwb$1 = (function (color) { | ||
return convert(prepare(color, 'hwb'), 'hwb'); | ||
}); | ||
var rgb = (function (color) { | ||
@@ -671,2 +687,3 @@ return convert(prepare(color, 'rgb'), 'rgb'); | ||
hsi: hsi, | ||
hwb: hwb$1, | ||
rgb: rgb, | ||
@@ -673,0 +690,0 @@ css: css, |
@@ -1,1 +0,1 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.culori=r()}(this,function(){"use strict";function e(e){var r=e.h,a=e.s,n=e.l,t=e.a,o=n+a*(n<.5?n:1-n),i=o-2*(o-n)*Math.abs(r/60%2-1),s=void 0;switch(Math.floor(r/60)){case 0:s={r:o,g:i,b:2*n-o};break;case 1:s={r:i,g:o,b:2*n-o};break;case 2:s={r:2*n-o,g:o,b:i};break;case 3:s={r:2*n-o,g:i,b:o};break;case 4:s={r:i,g:2*n-o,b:o};break;case 5:s={r:o,g:2*n-o,b:i}}return s.mode="rgb",void 0!==t&&(s.a=t),s}function r(e){var r=e.r,a=e.g,n=e.b,t=e.a,o=Math.max(r,a,n),i=Math.min(r,a,n),s={mode:"hsl",s:o===i?0:(o-i)/(1-Math.abs(o+i-1)),l:.5*(o+i)};return o-i!=0&&(s.h=60*(o===r?(a-n)/(o-i)+6*(a<n):o===a?(n-r)/(o-i)+2:(r-a)/(o-i)+4)),void 0!==t&&(s.a=t),s}var a=function(a,n){if(void 0!==a){if(a.mode===n)return a;var t,o,i,s,d,l,u,g,b=void 0;switch(a.mode){case"rgb":b=a;break;case"hsl":b=e(a);break;case"hsv":b=function(e){var r=e.h,a=e.s,n=e.v,t=e.a,o=Math.abs(r/60%2-1),i=void 0;switch(Math.floor(r/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)}}return i.mode="rgb",void 0!==t&&(i.a=t),i}(a);break;case"hsi":b=function(e){var r=e.h,a=e.s,n=e.i,t=e.a,o=Math.abs(r/60%2-1),i=void 0;switch(Math.floor(r/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))}}return i.mode="rgb",void 0!==t&&(i.a=t),i}(a);break;default:return}switch(n){case"rgb":return b;case"hsl":return r(b);case"hsv":return o=(t=b).r,i=t.g,s=t.b,d=t.a,l=Math.max(o,i,s),u=Math.min(o,i,s),g={mode:"hsv",s:0===l?0:1-u/l,v:l},l-u!=0&&(g.h=60*(l===o?(i-s)/(l-u)+6*(i<s):l===i?(s-o)/(l-u)+2:(o-i)/(l-u)+4)),void 0!==d&&(g.a=d),g;case"hsi":return function(e){var r=e.r,a=e.g,n=e.b,t=e.a,o=Math.max(r,a,n),i=Math.min(r,a,n),s={mode:"hsi",s:r+a+n===0?0:1-3*i/(r+a+n),i:(r+a+n)/3};return o-i!=0&&(s.h=60*(o===r?(a-n)/(o-i)+6*(a<n):o===a?(n-r)/(o-i)+2:(r-a)/(o-i)+4)),void 0!==t&&(s.a=t),s}(b);default:return}}},n=function(e,r){if("number"==typeof e)return 3===r?{mode:"rgb",r:(e>>8&15|e>>4&240)/255,g:(e>>4&15|240&e)/255,b:(15&e|e<<4&240)/255}:4===r?{mode:"rgb",r:(e>>12&15|e>>8&240)/255,g:(e>>8&15|e>>4&240)/255,b:(e>>4&15|240&e)/255,a:(15&e|e<<4&240)/255}:6===r?{mode:"rgb",r:(e>>16&255)/255,g:(e>>8&255)/255,b:(255&e)/255}:8===r?{mode:"rgb",r:(e>>24&255)/255,g:(e>>16&255)/255,b:(e>>8&255)/255,a:(255&e)/255}:void 0},t={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},o=function(e){return"string"==typeof e&&n(t[e.toLowerCase()],6)||void 0},i=function(e){return e.toString().replace(/^\/|\/$/g,"")},s=/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/,d=/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)%/,l=i(d),u="(?:"+i(d)+"|"+i(s)+")",g="(?:"+i(s)+"(deg|grad|rad|turn)|"+i(s)+")",b=new RegExp("^rgba?\\(\\s*"+u+"\\s*,\\s*"+u+"\\s*,\\s*"+u+"\\s*(?:,\\s*"+u+"\\s*)?\\)$"),c=new RegExp("^rgba?\\(\\s*"+u+"\\s+"+u+"\\s+"+u+"\\s*(?:\\/\\s*"+u+"\\s*)?\\)$"),h=new RegExp("^hsla?\\(\\s*"+g+"\\s*,\\s*"+l+"\\s*,\\s*"+l+"\\s*(?:,\\s*"+u+"\\s*)?\\)$"),m=new RegExp("^hsla?\\(\\s*"+g+"\\s+"+l+"\\s+"+l+"\\s*(?:\\/\\s*"+u+"\\s*)?\\)$"),f=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,v=function(e){var r;return(r=e.match(f))?n(parseInt(r[1],16),r[1].length):void 0},y=function(e){var r=r=e.match(b)||e.match(c);if(r){var a={mode:"rgb",r:void 0===r[1]?r[2]/255:r[1]/100,g:void 0===r[3]?r[4]/255:r[3]/100,b:void 0===r[5]?r[6]/255:r[5]/100};return void 0!==r[7]?a.a=r[7]/100:void 0!==r[8]&&(a.a=+r[8]),a}},p=function(a){if("string"==typeof a){var n=a.match(h)||a.match(m);if(n){var t={mode:"hsl",h:void 0===n[3]?+function(e,r){switch(r){case"deg":return e;case"rad":return e/Math.PI*180;case"grad":return e/10*9;case"turn":return 360*e}}(n[1],n[2]):+n[3],s:n[4]/100,l:n[5]/100};return void 0!==n[6]?t.a=n[6]/100:void 0!==n[7]&&(t.a=n[7]/255),r(e(t))}}},k=function(e){return v(e)||y(e)||p(e)||o(e)||("transparent"===e?n(0,8):void 0)};Object.assign(k,{number:n,named:o,hex:v,rgb:y,hsl:p});var w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},M=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var a=arguments[r];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e},x=function(e,r){return"object"!==(void 0===e?"undefined":w(e))?k(e):void 0===e.mode?M({},e,{mode:r}):e},j=function(e){return a(x(e,"rgb"),"rgb")},q=function(e,r){return Math.round(e*(r=Math.pow(10,r)))/r};var S={named:t},E=function(e){return j(e)};return Object.assign(E,S,{hsl:function(e){return a(x(e,"hsl"),"hsl")},hsv:function(e){return a(x(e,"hsv"),"hsv")},hsi:function(e){return a(x(e,"hsi"),"hsi")},rgb:j,css:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb",a=j(e),n=Math.round(255*a.r),t=Math.round(255*a.g),o=Math.round(255*a.b);return"hex"===r?"#"+(1<<24|n<<16|t<<8|o).toString(16).slice(1):"rgb"===r?void 0===a.a||1===a.a?"rgb("+n+", "+t+", "+o+")":"rgba("+n+", "+t+", "+o+", "+a.a+")":void 0},convert:a,prepare:x,parse:k,round:function e(r){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(void 0!==r)return"number"==typeof r?q(r,a):"string"==typeof r?r:"object"===(void 0===r?"undefined":w(r))?Object.keys(r).reduce(function(a,n){return a[n]=e(r[n]),a},{}):void 0}}),E}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.culori=r()}(this,function(){"use strict";function e(e){var r=e.h,a=e.s,n=e.l,t=e.a,o=n+a*(n<.5?n:1-n),i=o-2*(o-n)*Math.abs(r/60%2-1),s=void 0;switch(Math.floor(r/60)){case 0:s={r:o,g:i,b:2*n-o};break;case 1:s={r:i,g:o,b:2*n-o};break;case 2:s={r:2*n-o,g:o,b:i};break;case 3:s={r:2*n-o,g:i,b:o};break;case 4:s={r:i,g:2*n-o,b:o};break;case 5:s={r:o,g:2*n-o,b:i}}return s.mode="rgb",void 0!==t&&(s.a=t),s}function r(e){var r=e.r,a=e.g,n=e.b,t=e.a,o=Math.max(r,a,n),i=Math.min(r,a,n),s={mode:"hsl",s:o===i?0:(o-i)/(1-Math.abs(o+i-1)),l:.5*(o+i)};return o-i!=0&&(s.h=60*(o===r?(a-n)/(o-i)+6*(a<n):o===a?(n-r)/(o-i)+2:(r-a)/(o-i)+4)),void 0!==t&&(s.a=t),s}var a=function(a,n){if(void 0!==a){if(a.mode===n)return a;var t,o,i,s,d,u,l,g,b=void 0;switch(a.mode){case"rgb":b=a;break;case"hsl":b=e(a);break;case"hsv":b=function(e){var r=e.h,a=e.s,n=e.v,t=e.a,o=Math.abs(r/60%2-1),i=void 0;switch(Math.floor(r/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)}}return i.mode="rgb",void 0!==t&&(i.a=t),i}(a);break;case"hsi":b=function(e){var r=e.h,a=e.s,n=e.i,t=e.a,o=Math.abs(r/60%2-1),i=void 0;switch(Math.floor(r/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))}}return i.mode="rgb",void 0!==t&&(i.a=t),i}(a);break;default:return}switch(n){case"rgb":return b;case"hsl":return r(b);case"hsv":return o=(t=b).r,i=t.g,s=t.b,d=t.a,u=Math.max(o,i,s),l=Math.min(o,i,s),g={mode:"hsv",s:0===u?0:1-l/u,v:u},u-l!=0&&(g.h=60*(u===o?(i-s)/(u-l)+6*(i<s):u===i?(s-o)/(u-l)+2:(o-i)/(u-l)+4)),void 0!==d&&(g.a=d),g;case"hsi":return function(e){var r=e.r,a=e.g,n=e.b,t=e.a,o=Math.max(r,a,n),i=Math.min(r,a,n),s={mode:"hsi",s:r+a+n===0?0:1-3*i/(r+a+n),i:(r+a+n)/3};return o-i!=0&&(s.h=60*(o===r?(a-n)/(o-i)+6*(a<n):o===a?(n-r)/(o-i)+2:(r-a)/(o-i)+4)),void 0!==t&&(s.a=t),s}(b);default:return}}},n=function(e,r){if("number"==typeof e)return 3===r?{mode:"rgb",r:(e>>8&15|e>>4&240)/255,g:(e>>4&15|240&e)/255,b:(15&e|e<<4&240)/255}:4===r?{mode:"rgb",r:(e>>12&15|e>>8&240)/255,g:(e>>8&15|e>>4&240)/255,b:(e>>4&15|240&e)/255,a:(15&e|e<<4&240)/255}:6===r?{mode:"rgb",r:(e>>16&255)/255,g:(e>>8&255)/255,b:(255&e)/255}:8===r?{mode:"rgb",r:(e>>24&255)/255,g:(e>>16&255)/255,b:(e>>8&255)/255,a:(255&e)/255}:void 0},t={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},o=function(e){return"string"==typeof e&&n(t[e.toLowerCase()],6)||void 0},i=function(e){return e.toString().replace(/^\/|\/$/g,"")},s=/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)/,d=/([+-]?\d*\.?\d+(?:[eE][+-]?\d+)?)%/,u=i(d),l="(?:"+i(d)+"|"+i(s)+")",g="(?:"+i(s)+"(deg|grad|rad|turn)|"+i(s)+")",b=new RegExp("^rgba?\\(\\s*"+l+"\\s*,\\s*"+l+"\\s*,\\s*"+l+"\\s*(?:,\\s*"+l+"\\s*)?\\)$"),c=new RegExp("^rgba?\\(\\s*"+l+"\\s+"+l+"\\s+"+l+"\\s*(?:\\/\\s*"+l+"\\s*)?\\)$"),h=new RegExp("^hsla?\\(\\s*"+g+"\\s*,\\s*"+u+"\\s*,\\s*"+u+"\\s*(?:,\\s*"+l+"\\s*)?\\)$"),m=new RegExp("^hsla?\\(\\s*"+g+"\\s+"+u+"\\s+"+u+"\\s*(?:\\/\\s*"+l+"\\s*)?\\)$"),f=/^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i,v=new RegExp("^hwb\\(\\s*"+g+"\\s+"+u+"\\s+"+u+"\\s*(?:\\/\\s*"+l+"\\s*)?\\)$"),p=function(e){var r;return(r=e.match(f))?n(parseInt(r[1],16),r[1].length):void 0},y=function(e){var r=e.match(b)||e.match(c);if(r){var a={mode:"rgb",r:void 0===r[1]?r[2]/255:r[1]/100,g:void 0===r[3]?r[4]/255:r[3]/100,b:void 0===r[5]?r[6]/255:r[5]/100};return void 0!==r[7]?a.a=r[7]/100:void 0!==r[8]&&(a.a=+r[8]),a}},k=function(e,r){switch(r){case"deg":return+e;case"rad":return e/Math.PI*180;case"grad":return e/10*9;case"turn":return 360*e}},w=function(a){if("string"==typeof a){var n=a.match(h)||a.match(m);if(n){var t={mode:"hsl",h:void 0===n[3]?k(n[1],n[2]):+n[3],s:n[4]/100,l:n[5]/100};return void 0!==n[6]?t.a=n[6]/100:void 0!==n[7]&&(t.a=n[7]/255),r(e(t))}}},M=function(e){if("string"==typeof e){var r=e.match(v);if(r){var a={mode:"hwb",h:void 0===r[3]?k(r[1],r[2]):+r[3],w:r[4]/100,b:r[5]/100};if(a.w+a.b>1){var n=a.w+a.b;a.w/=n,a.b/=n}return void 0!==r[6]?a.a=r[6]/100:void 0!==r[7]&&(a.a=r[7]/255),a}}},x=function(e){return p(e)||y(e)||w(e)||o(e)||("transparent"===e?n(0,8):void 0)||M(e)};Object.assign(x,{number:n,named:o,hex:p,rgb:y,hsl:w,hwb:M});var j="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},q=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var a=arguments[r];for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e},E=function(e,r){return"object"!==(void 0===e?"undefined":j(e))?x(e):void 0===e.mode?q({},e,{mode:r}):e},S=function(e){return a(E(e,"rgb"),"rgb")},$=function(e,r){return Math.round(e*(r=Math.pow(10,r)))/r};var O={named:t},R=function(e){return S(e)};return Object.assign(R,O,{hsl:function(e){return a(E(e,"hsl"),"hsl")},hsv:function(e){return a(E(e,"hsv"),"hsv")},hsi:function(e){return a(E(e,"hsi"),"hsi")},hwb:function(e){return a(E(e,"hwb"),"hwb")},rgb:S,css:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgb",a=S(e),n=Math.round(255*a.r),t=Math.round(255*a.g),o=Math.round(255*a.b);return"hex"===r?"#"+(1<<24|n<<16|t<<8|o).toString(16).slice(1):"rgb"===r?void 0===a.a||1===a.a?"rgb("+n+", "+t+", "+o+")":"rgba("+n+", "+t+", "+o+", "+a.a+")":void 0},convert:a,prepare:E,parse:x,round:function e(r){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(void 0!==r)return"number"==typeof r?$(r,a):"string"==typeof r?r:"object"===(void 0===r?"undefined":j(r))?Object.keys(r).reduce(function(a,n){return a[n]=e(r[n]),a},{}):void 0}}),R}); |
@@ -26,6 +26,4 @@ // Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB | ||
} | ||
res['mode'] = 'rgb'; | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
res.mode = 'rgb'; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -58,6 +56,4 @@ } | ||
} | ||
res['mode'] = 'rgb'; | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
res.mode = 'rgb'; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -120,6 +116,5 @@ } | ||
} | ||
res['mode'] = 'rgb'; | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
res.mode = 'rgb'; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -144,8 +139,4 @@ } | ||
}; | ||
if (M - m !== 0) { | ||
res['h'] = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
} | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -170,8 +161,4 @@ } | ||
}; | ||
if (M - m !== 0) { | ||
res['h'] = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
} | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -196,8 +183,4 @@ } | ||
}; | ||
if (M - m !== 0) { | ||
res['h'] = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
} | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
@@ -482,2 +465,4 @@ } | ||
var hwb = new RegExp('^hwb\\(\\s*' + hue + '\\s+' + sp + '\\s+' + sp + '\\s*(?:\\/\\s*' + pn + '\\s*)?\\)$'); | ||
var parseHex = (function (color) { | ||
@@ -489,3 +474,3 @@ var match; | ||
var parseRgb = (function (color) { | ||
var match = match = color.match(rgb_legacy) || color.match(rgb_current); | ||
var match = color.match(rgb_legacy) || color.match(rgb_current); | ||
if (!match) return; | ||
@@ -500,5 +485,5 @@ var res = { | ||
if (match[7] !== undefined) { | ||
res['a'] = match[7] / 100; | ||
res.a = match[7] / 100; | ||
} else if (match[8] !== undefined) { | ||
res['a'] = +match[8]; | ||
res.a = +match[8]; | ||
} | ||
@@ -512,3 +497,3 @@ | ||
case 'deg': | ||
return val; | ||
return +val; | ||
case 'rad': | ||
@@ -529,3 +514,3 @@ return val / Math.PI * 180; | ||
mode: 'hsl', | ||
h: match[3] === undefined ? +hue$1(match[1], match[2]) : +match[3], | ||
h: match[3] === undefined ? hue$1(match[1], match[2]) : +match[3], | ||
s: match[4] / 100, | ||
@@ -535,5 +520,5 @@ l: match[5] / 100 | ||
if (match[6] !== undefined) { | ||
res['a'] = match[6] / 100; | ||
res.a = match[6] / 100; | ||
} else if (match[7] !== undefined) { | ||
res['a'] = match[7] / 255; | ||
res.a = match[7] / 255; | ||
} | ||
@@ -544,4 +529,30 @@ // TODO better way to normalize than via rgb? | ||
var parseHwb = (function (color) { | ||
if (typeof color !== 'string') return; | ||
var match = color.match(hwb); | ||
if (!match) return undefined; | ||
var res = { | ||
mode: 'hwb', | ||
h: match[3] === undefined ? hue$1(match[1], match[2]) : +match[3], | ||
w: match[4] / 100, | ||
b: match[5] / 100 | ||
}; | ||
// normalize w + b to at most 1 | ||
if (res.w + res.b > 1) { | ||
var s = res.w + res.b; | ||
res.w /= s; | ||
res.b /= s; | ||
} | ||
if (match[6] !== undefined) { | ||
res.a = match[6] / 100; | ||
} else if (match[7] !== undefined) { | ||
res.a = match[7] / 255; | ||
} | ||
return res; | ||
}); | ||
var parse = function parse(color) { | ||
return parseHex(color) || parseRgb(color) || parseHsl(color) || parseNamed(color) || (color === 'transparent' ? parseNumber(0, 8) : undefined); | ||
return parseHex(color) || parseRgb(color) || parseHsl(color) || parseNamed(color) || (color === 'transparent' ? parseNumber(0x00000000, 8) : undefined) || parseHwb(color); | ||
}; | ||
@@ -554,3 +565,4 @@ | ||
rgb: parseRgb, | ||
hsl: parseHsl | ||
hsl: parseHsl, | ||
hwb: parseHwb | ||
}); | ||
@@ -594,2 +606,6 @@ | ||
var hwb$1 = (function (color) { | ||
return convert(prepare(color, 'hwb'), 'hwb'); | ||
}); | ||
var rgb = (function (color) { | ||
@@ -665,2 +681,3 @@ return convert(prepare(color, 'rgb'), 'rgb'); | ||
hsi: hsi, | ||
hwb: hwb$1, | ||
rgb: rgb, | ||
@@ -667,0 +684,0 @@ css: css, |
{ | ||
"name": "culori", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"main": "build/culori.js", | ||
@@ -5,0 +5,0 @@ "module": "build/index.js", |
@@ -33,4 +33,5 @@ # Culori | ||
* ✓ [HSL and HSLA](https://drafts.csswg.org/css-color/#the-hsl-notation) | ||
* [HWB](https://drafts.csswg.org/css-color/#the-hwb-notation) | ||
* ✓ [HWB](https://drafts.csswg.org/css-color/#the-hwb-notation) | ||
* [LAB and LCH](https://drafts.csswg.org/css-color/#lab-colors) | ||
* [Grays](https://drafts.csswg.org/css-color/#grays) | ||
@@ -37,0 +38,0 @@ Additionally, it supports: |
@@ -6,2 +6,3 @@ import parseNumber from '../parsers/number'; | ||
import parseHsl from '../parsers/hsl'; | ||
import parseHwb from '../parsers/hwb'; | ||
@@ -14,3 +15,4 @@ const parse = color => { | ||
parseNamed(color) || | ||
(color === 'transparent' ? parseNumber(0, 8) : undefined) | ||
(color === 'transparent' ? parseNumber(0x00000000, 8) : undefined) || | ||
parseHwb(color) | ||
); | ||
@@ -24,5 +26,6 @@ }; | ||
rgb: parseRgb, | ||
hsl: parseHsl | ||
hsl: parseHsl, | ||
hwb: parseHwb | ||
}); | ||
export default parse; |
@@ -50,7 +50,6 @@ // Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB | ||
} | ||
res['mode'] = 'rgb'; | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
res.mode = 'rgb'; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
} |
@@ -15,7 +15,5 @@ // Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB | ||
} | ||
res['mode'] = 'rgb'; | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
res.mode = 'rgb'; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
}; |
@@ -14,7 +14,5 @@ // Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB | ||
} | ||
res['mode'] = 'rgb'; | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
res.mode = 'rgb'; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
}; |
@@ -11,9 +11,5 @@ // Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Formal_derivation | ||
}; | ||
if (M - m !== 0) { | ||
res['h'] = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
} | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
} |
@@ -11,9 +11,5 @@ // Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Formal_derivation | ||
}; | ||
if (M - m !== 0) { | ||
res['h'] = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
} | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
} |
@@ -11,9 +11,5 @@ // Based on: https://en.wikipedia.org/wiki/HSL_and_HSV#Formal_derivation | ||
}; | ||
if (M - m !== 0) { | ||
res['h'] = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
} | ||
if (a !== undefined) { | ||
res['a'] = a; | ||
} | ||
if (M - m !== 0) res.h = (M === r ? (g - b) / (M - m) + (g < b) * 6 : M === g ? (b - r) / (M - m) + 2 : (r - g) / (M - m) + 4) * 60; | ||
if (a !== undefined) res.a = a; | ||
return res; | ||
} |
import hsl from './api/hsl'; | ||
import hsv from './api/hsv'; | ||
import hsi from './api/hsi'; | ||
import hwb from './api/hwb'; | ||
import rgb from './api/rgb'; | ||
@@ -21,2 +22,3 @@ import css from './api/css'; | ||
hsi, | ||
hwb, | ||
rgb, | ||
@@ -23,0 +25,0 @@ css, |
@@ -1,5 +0,3 @@ | ||
import { | ||
hsl_legacy, | ||
hsl_current | ||
} from '../util/regex'; | ||
import { hsl_legacy, hsl_current } from '../util/regex'; | ||
import { hue } from '../util/hue'; | ||
@@ -9,11 +7,2 @@ import from_hsl from '../converters/from_hsl'; | ||
const hue = (val, unit) => { | ||
switch (unit) { | ||
case 'deg': return val; | ||
case 'rad': return val / Math.PI * 180; | ||
case 'grad': return val / 10 * 9; | ||
case 'turn': return val * 360; | ||
} | ||
} | ||
export default color => { | ||
@@ -25,3 +14,3 @@ if (typeof color !== 'string') return; | ||
mode: 'hsl', | ||
h: match[3] === undefined ? +hue(match[1], match[2]) : +match[3], | ||
h: match[3] === undefined ? hue(match[1], match[2]) : +match[3], | ||
s: match[4] / 100, | ||
@@ -31,5 +20,5 @@ l: match[5] / 100 | ||
if (match[6] !== undefined) { | ||
res['a'] = match[6] / 100; | ||
res.a = match[6] / 100; | ||
} else if (match[7] !== undefined) { | ||
res['a'] = match[7] / 255; | ||
res.a = match[7] / 255; | ||
} | ||
@@ -36,0 +25,0 @@ // TODO better way to normalize than via rgb? |
@@ -7,3 +7,3 @@ import { | ||
export default color => { | ||
var match = match = color.match(rgb_legacy) || color.match(rgb_current); | ||
var match = color.match(rgb_legacy) || color.match(rgb_current); | ||
if (!match) return; | ||
@@ -18,5 +18,5 @@ let res = { | ||
if (match[7] !== undefined) { | ||
res['a'] = match[7] / 100; | ||
res.a = match[7] / 100; | ||
} else if (match[8] !== undefined) { | ||
res['a'] = +match[8]; | ||
res.a = +match[8]; | ||
} | ||
@@ -23,0 +23,0 @@ |
@@ -29,2 +29,4 @@ // converts a regexp to string | ||
export const hex = /^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i; | ||
export const hex = /^#?([0-9a-f]{8}|[0-9a-f]{6}|[0-9a-f]{4}|[0-9a-f]{3})$/i; | ||
export const hwb = new RegExp(`^hwb\\(\\s*${hue}\\s+${sp}\\s+${sp}\\s*(?:\\/\\s*${pn}\\s*)?\\)$`); |
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
69787
38
1870
179