forked from stayradiated/colr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolr.min.js
1 lines (1 loc) · 7.03 KB
/
colr.min.js
1
var colr=function(r){function t(n){if(o[n])return o[n].exports;var e=o[n]={exports:{},id:n,loaded:!1};return r[n].call(e.exports,e,e.exports,t),e.loaded=!0,e.exports}var o={};return t.m=r,t.c=o,t.p="",t(0)}([function(r,t,o){"use strict";function n(){return this instanceof n==!1?new n:void(this._={})}function e(r){return Math.max(Math.min(r,100),0)}function s(r){return Math.max(Math.min(r,255),0)}function i(r,t,o){return[Math.max(Math.min(r,255),0),Math.max(Math.min(t,255),0),Math.max(Math.min(o,255),0)]}function a(r,t,o){return[Math.max(Math.min(r,360),0),Math.max(Math.min(t,100),0),Math.max(Math.min(o,100),0)]}var h=o(1);n.fromHex=function(r){return(new n).fromHex(r)},n.fromGrayscale=function(r){return(new n).fromGrayscale(r)},n.fromRgb=function(r,t,o){return(new n).fromRgb(r,t,o)},n.fromRgbArray=function(r){return(new n).fromRgb(r[0],r[1],r[2])},n.fromRgbObject=function(r){return(new n).fromRgb(r.r,r.g,r.b)},n.fromHsl=function(r,t,o){return(new n).fromHsl(r,t,o)},n.fromHslArray=function(r){return(new n).fromHsl(r[0],r[1],r[2])},n.fromHslObject=function(r){return(new n).fromHsl(r.h,r.s,r.l)},n.fromHsv=function(r,t,o){return(new n).fromHsv(r,t,o)},n.fromHsvArray=function(r){return(new n).fromHsv(r[0],r[1],r[2])},n.fromHsvObject=function(r){return(new n).fromHsv(r.h,r.s,r.v)},n.prototype.fromHex=function(r){var t=h.hex.rgb(r);return this._={rgb:t},this},n.prototype.fromGrayscale=function(r){r=s(r);var t=h.grayscale.rgb(r);return this._={rgb:t},this},n.prototype.fromRgb=function(r,t,o){if("number"!=typeof r||"number"!=typeof t||"number"!=typeof o)throw new Error("Arguments must be numbers");var n=i(r,t,o);return this._={rgb:n},this},n.prototype.fromRgbArray=function(r){return this.fromRgb(r[0],r[1],r[2])},n.prototype.fromRgbObject=function(r){return this.fromRgb(r.r,r.g,r.b)},n.prototype.fromHsl=function(r,t,o){if("number"!=typeof r||"number"!=typeof t||"number"!=typeof o)throw new Error("Arguments must be numbers");return this._={hsl:a(r,t,o)},this},n.prototype.fromHslArray=function(r){return this.fromHsl(r[0],r[1],r[2])},n.prototype.fromHslObject=function(r){return this.fromHsl(r.h,r.s,r.l)},n.prototype.fromHsv=function(r,t,o){if("number"!=typeof r||"number"!=typeof t||"number"!=typeof o)throw new Error("Arguments must be numbers");return this._={hsv:a(r,t,o)},this},n.prototype.fromHsvArray=function(r){return this.fromHsv(r[0],r[1],r[2])},n.prototype.fromHsvObject=function(r){return this.fromHsv(r.h,r.s,r.v)},n.prototype.toHex=function(){var r=this._.hex;if(void 0!==r)return r;var t,o=this._.rgb;t=void 0!==o?o:this.toRawRgbArray(),t[0]=Math.round(t[0]),t[1]=Math.round(t[1]),t[2]=Math.round(t[2]);var n=h.rgb.hex(t);return this._.hex=n,n},n.prototype.toGrayscale=function(){var r=this._.grayscale;if(void 0!==r)return r;var t,o=this._.rgb;t=void 0!==o?o:this.toRawRgbArray();var n=h.rgb.grayscale(t);return this._.grayscale=n,n},n.prototype.toRawRgbArray=function(){var r=this._.rgb;if(void 0!==r)return r;var t;if(void 0!==(t=this._.hsv))t=h.hsv.rgb(t);else{if(void 0===(t=this._.hsl))throw new Error("No data to convert");t=h.hsl.rgb(t)}return this._.rgb=t,t},n.prototype.toRawRgbObject=function(){var r=this.toRawRgbArray();return{r:r[0],g:r[1],b:r[2]}},n.prototype.toRgbArray=function(){var r=this.toRawRgbArray();return[Math.round(r[0]),Math.round(r[1]),Math.round(r[2])]},n.prototype.toRgbObject=function(){var r=this.toRgbArray();return{r:r[0],g:r[1],b:r[2]}},n.prototype.toRawHslArray=function(){var r=this._.hsl;if(void 0!==r)return r;var t;if(void 0!==(t=this._.hsv))t=h.hsv.hsl(t);else{if(void 0===(t=this._.rgb))throw new Error("No data to convert");t=h.rgb.hsl(t)}return this._.hsl=t,t},n.prototype.toRawHslObject=function(){var r=this.toRawHslArray();return{h:r[0],s:r[1],l:r[2]}},n.prototype.toHslArray=function(){var r=this.toRawHslArray();return[Math.round(r[0]),Math.round(r[1]),Math.round(r[2])]},n.prototype.toHslObject=function(){var r=this.toHslArray();return{h:r[0],s:r[1],l:r[2]}},n.prototype.toRawHsvArray=function(){var r=this._.hsv;if(void 0!==r)return r;var t;if(void 0!==(t=this._.hsl))t=h.hsl.hsv(t);else{if(void 0===(t=this._.rgb))throw new Error("No data to convert");t=h.rgb.hsv(t)}return this._.hsv=t,t},n.prototype.toRawHsvObject=function(){var r=this.toRawHsvArray();return{h:r[0],s:r[1],v:r[2]}},n.prototype.toHsvArray=function(){var r=this.toRawHsvArray();return[Math.round(r[0]),Math.round(r[1]),Math.round(r[2])]},n.prototype.toHsvObject=function(){var r=this.toHsvArray();return{h:r[0],s:r[1],v:r[2]}},n.prototype.lighten=function(r){var t=this.toRawHslArray();return t[2]=e(t[2]+r),this._={hsl:t},this},n.prototype.darken=function(r){var t=this.toRawHslArray();return t[2]=e(t[2]-r),this._={hsl:t},this},n.prototype.clone=function(){var r=new n;return r._.hex=this._.hex,r._.grayscale=this._.grayscale,void 0!==this._.rgb&&(r._.rgb=this._.rgb.slice(0)),void 0!==this._.hsv&&(r._.hsv=this._.hsv.slice(0)),void 0!==this._.hsl&&(r._.hsl=this._.hsl.slice(0)),r},r.exports=n},function(r,t){"use strict";function o(r){return 58>r?r-48:71>r?r-55:r-87}function n(r){var t="#"===r[0]?1:0,n=r.length;if(3>n-t)throw new Error("hex input must be at least three chars long");var e,s,i,a=o(r.charCodeAt(0+t)),h=o(r.charCodeAt(1+t)),u=o(r.charCodeAt(2+t));if(n-t>=6?(e=(a<<4)+h,s=(u<<4)+o(r.charCodeAt(3+t)),i=(o(r.charCodeAt(4+t))<<4)+o(r.charCodeAt(5+t))):(e=(a<<4)+a,s=(h<<4)+h,i=(u<<4)+u),0>e||e>255||0>s||s>255||0>i||i>255)throw new Error("hex input is invalid");return[e,s,i]}function e(r){return"#"+("000000"+((r[0]<<16)+(r[1]<<8)+r[2]).toString(16)).slice(-6)}function s(r){var t,o,n,e=r[0]/255,s=r[1]/255,i=r[2]/255,a=Math.min(e,s,i),h=Math.max(e,s,i),u=h-a;return h===a?t=0:e===h?t=(s-i)/u:s===h?t=2+(i-e)/u:i===h&&(t=4+(e-s)/u),t=Math.min(60*t,360),0>t&&(t+=360),n=(a+h)/2,o=h===a?0:.5>=n?u/(h+a):u/(2-h-a),[t,100*o,100*n]}function i(r){var t,o,n,e=r[0],s=r[1],i=r[2],a=Math.min(e,s,i),h=Math.max(e,s,i),u=h-a;return o=0===h?0:u/h*100,h===a?t=0:e===h?t=(s-i)/u:s===h?t=2+(i-e)/u:i===h&&(t=4+(e-s)/u),t=Math.min(60*t,360),0>t&&(t+=360),n=h/255*100,[t,o,n]}function a(r){var t,o,n,e=r[0]/360,s=r[1]/100,i=r[2]/100;if(0===s)t=o=n=i;else{var a,h=.5>i?i*(s+1):i+s-i*s,u=2*i-h;a=e+1/3,0>a?a+=1:a>1&&(a-=1),t=1/6>a?u+(h-u)*a*6:.5>a?h:2/3>a?u+(h-u)*(2/3-a)*6:u,a=e,0>a?a+=1:a>1&&(a-=1),o=1/6>a?u+(h-u)*a*6:.5>a?h:2/3>a?u+(h-u)*(2/3-a)*6:u,a=e-1/3,0>a?a+=1:a>1&&(a-=1),n=1/6>a?u+(h-u)*a*6:.5>a?h:2/3>a?u+(h-u)*(2/3-a)*6:u}return[255*t,255*o,255*n]}function h(r){var t,o,n=r[0],e=r[1]/100,s=r[2]/100;return 0===e?[n,0,100*s]:0===s?[n,0,0]:(s*=2,e*=1>=s?s:2-s,o=(s+e)/2,t=2*e/(s+e),[n,100*t,100*o])}function u(r){var t=r[0]/60,o=r[1]/100,n=r[2]/100,e=Math.floor(t)%6,s=t-Math.floor(t),i=255*n*(1-o),a=255*n*(1-o*s),h=255*n*(1-o*(1-s));switch(n=255*n,e){case 0:return[n,h,i];case 1:return[a,n,i];case 2:return[i,n,h];case 3:return[i,a,n];case 4:return[h,i,n];case 5:return[n,i,a]}}function f(r){var t,o,n=r[0],e=r[1]/100,s=r[2]/100;return 0===e?[n,0,100*s]:0===s?[n,0,0]:(o=(2-e)*s,t=e*s,t/=1>=o?o:2-o,o/=2,[n,100*t,100*o])}function c(r){return[r,r,r]}function v(r){return(299*r[0]+587*r[1]+114*r[2])/1e3}r.exports={grayscale:{rgb:c},hex:{rgb:n},rgb:{hsl:s,hsv:i,hex:e,grayscale:v},hsl:{rgb:a,hsv:h},hsv:{rgb:u,hsl:f}}}]);