/** * Take input from [0, n] and return it as [0, 1] * @hidden */ function t(t,r){( /** * Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1 * * @hidden */ function(t){return"string"==typeof t&&-1!==t.indexOf(".")&&1===parseFloat(t)} /** * Check to see if string passed in is a percentage * @hidden */)(t)&&(t="100%");var e=function(t){return"string"==typeof t&&-1!==t.indexOf("%")} /** * Return a valid alpha value [0,1] with all invalid values being set to 1 * @hidden */(t); // Handle floating point rounding errors return t=360===r?t:Math.min(r,Math.max(0,parseFloat(t))), // Automatically convert percentage into number e&&(t=parseInt(String(t*r),10)/100),Math.abs(t-r)<1e-6?1: // Convert into [0, 1] range if it isn't already // If n is a hue given in degrees, // wrap around out-of-range values into [0, 360] range // then convert into [0, 1]. t=360===r?(t<0?t%r+r:t%r)/parseFloat(String(r)):t%r/parseFloat(String(r))} /** * Force a number between 0 and 1 * @hidden */function r(t){return Math.min(1,Math.max(0,t))}function e(t){return t=parseFloat(t),(isNaN(t)||t<0||t>1)&&(t=1),t} /** * Replace a decimal with it's percentage value * @hidden */function n(t){return t<=1?"".concat(100*Number(t),"%"):t} /** * Force a hex value to have 2 characters * @hidden */function a(t){return 1===t.length?"0"+t:String(t)} // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from: // /** * Handle bounds / percentage checking to conform to CSS color spec * * *Assumes:* r, g, b in [0, 255] or [0, 1] * *Returns:* { r, g, b } in [0, 255] */ /** * Converts an RGB color value to HSL. * *Assumes:* r, g, and b are contained in [0, 255] or [0, 1] * *Returns:* { h, s, l } in [0,1] */ function o(r,e,n){r=t(r,255),e=t(e,255),n=t(n,255);var a=Math.max(r,e,n),o=Math.min(r,e,n),i=0,h=0,s=(a+o)/2;if(a===o)h=0,i=0;else{var f=a-o;switch(h=s>.5?f/(2-a-o):f/(a+o),a){case r:i=(e-n)/f+(e1&&(e-=1),e<1/6?t+6*e*(r-t):e<.5?r:e<2/3?t+(r-t)*(2/3-e)*6:t} /** * Converts an HSL color value to RGB. * * *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100] * *Returns:* { r, g, b } in the set [0, 255] */ /** * Converts an RGB color value to HSV * * *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1] * *Returns:* { h, s, v } in [0,1] */ function h(r,e,n){r=t(r,255),e=t(e,255),n=t(n,255);var a=Math.max(r,e,n),o=Math.min(r,e,n),i=0,h=a,s=a-o,f=0===a?0:s/a;if(a===o)i=0;// achromatic else{switch(a){case r:i=(e-n)/s+(e var d="(?:".concat("[-\\+]?\\d*\\.\\d+%?",")|(?:").concat("[-\\+]?\\d+%?",")"),l="[\\s|\\(]+(".concat(d,")[,|\\s]+(").concat(d,")[,|\\s]+(").concat(d,")\\s*\\)?"),b="[\\s|\\(]+(".concat(d,")[,|\\s]+(").concat(d,")[,|\\s]+(").concat(d,")[,|\\s]+(").concat(d,")\\s*\\)?"),p={CSS_UNIT:new RegExp(d),rgb:new RegExp("rgb"+l),rgba:new RegExp("rgba"+b),hsl:new RegExp("hsl"+l),hsla:new RegExp("hsla"+b),hsv:new RegExp("hsv"+l),hsva:new RegExp("hsva"+b),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/}; // function v(t){return Boolean(p.CSS_UNIT.exec(String(t)))}var m=/** @class */function(){function n(t,r){var e; // If input is already a tinycolor, return itself if(void 0===t&&(t=""),void 0===r&&(r={}),t instanceof n) // eslint-disable-next-line no-constructor-return return t;"number"==typeof t&&(t=function(t){return{r:t>>16,g:(65280&t)>>8,b:255&t}}(t)),this.originalInput=t;var a=g(t);this.originalInput=t,this.r=a.r,this.g=a.g,this.b=a.b,this.a=a.a,this.roundA=Math.round(100*this.a)/100,this.format=null!==(e=r.format)&&void 0!==e?e:a.format,this.gradientType=r.gradientType, // Don't let the range of [0,255] come back in [0,1]. // Potentially lose a little bit of precision here, but will fix issues where // .5 gets interpreted as half of the total, instead of half of 1 // If it was supposed to be 128, this was already taken care of by `inputToRgb` this.r<1&&(this.r=Math.round(this.r)),this.g<1&&(this.g=Math.round(this.g)),this.b<1&&(this.b=Math.round(this.b)),this.isValid=a.ok}return n.prototype.isDark=function(){return this.getBrightness()<128},n.prototype.isLight=function(){return!this.isDark()}, /** * Returns the perceived brightness of the color, from 0-255. */ n.prototype.getBrightness=function(){ // http://www.w3.org/TR/AERT#color-contrast var t=this.toRgb();return(299*t.r+587*t.g+114*t.b)/1e3}, /** * Returns the perceived luminance of a color, from 0-1. */ n.prototype.getLuminance=function(){ // http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef var t=this.toRgb(),r=t.r/255,e=t.g/255,n=t.b/255;return.2126*(r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4))+.7152*(e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4))+.0722*(n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4))}, /** * Returns the alpha value of a color, from 0-1. */ n.prototype.getAlpha=function(){return this.a}, /** * Sets the alpha value on the current color. * * @param alpha - The new alpha value. The accepted range is 0-1. */ n.prototype.setAlpha=function(t){return this.a=e(t),this.roundA=Math.round(100*this.a)/100,this}, /** * Returns whether the color is monochrome. */ n.prototype.isMonochrome=function(){return 0===this.toHsl().s}, /** * Returns the object as a HSVA object. */ n.prototype.toHsv=function(){var t=h(this.r,this.g,this.b);return{h:360*t.h,s:t.s,v:t.v,a:this.a}}, /** * Returns the hsva values interpolated into a string with the following format: * "hsva(xxx, xxx, xxx, xx)". */ n.prototype.toHsvString=function(){var t=h(this.r,this.g,this.b),r=Math.round(360*t.h),e=Math.round(100*t.s),n=Math.round(100*t.v);return 1===this.a?"hsv(".concat(r,", ").concat(e,"%, ").concat(n,"%)"):"hsva(".concat(r,", ").concat(e,"%, ").concat(n,"%, ").concat(this.roundA,")")}, /** * Returns the object as a HSLA object. */ n.prototype.toHsl=function(){var t=o(this.r,this.g,this.b);return{h:360*t.h,s:t.s,l:t.l,a:this.a}}, /** * Returns the hsla values interpolated into a string with the following format: * "hsla(xxx, xxx, xxx, xx)". */ n.prototype.toHslString=function(){var t=o(this.r,this.g,this.b),r=Math.round(360*t.h),e=Math.round(100*t.s),n=Math.round(100*t.l);return 1===this.a?"hsl(".concat(r,", ").concat(e,"%, ").concat(n,"%)"):"hsla(".concat(r,", ").concat(e,"%, ").concat(n,"%, ").concat(this.roundA,")")}, /** * Returns the hex value of the color. * @param allow3Char will shorten hex value to 3 char if possible */ n.prototype.toHex=function(t){return void 0===t&&(t=!1),s(this.r,this.g,this.b,t)}, /** * Returns the hex value of the color -with a # prefixed. * @param allow3Char will shorten hex value to 3 char if possible */ n.prototype.toHexString=function(t){return void 0===t&&(t=!1),"#"+this.toHex(t)}, /** * Returns the hex 8 value of the color. * @param allow4Char will shorten hex value to 4 char if possible */ n.prototype.toHex8=function(t){return void 0===t&&(t=!1),function(t,r,e,n,o){var i,h=[a(Math.round(t).toString(16)),a(Math.round(r).toString(16)),a(Math.round(e).toString(16)),a((i=n,Math.round(255*parseFloat(i)).toString(16)))]; // Return a 4 character hex if possible return o&&h[0].startsWith(h[0].charAt(1))&&h[1].startsWith(h[1].charAt(1))&&h[2].startsWith(h[2].charAt(1))&&h[3].startsWith(h[3].charAt(1))?h[0].charAt(0)+h[1].charAt(0)+h[2].charAt(0)+h[3].charAt(0):h.join("")} /** Converts a decimal to a hex value */(this.r,this.g,this.b,this.a,t)}, /** * Returns the hex 8 value of the color -with a # prefixed. * @param allow4Char will shorten hex value to 4 char if possible */ n.prototype.toHex8String=function(t){return void 0===t&&(t=!1),"#"+this.toHex8(t)}, /** * Returns the shorter hex value of the color depends on its alpha -with a # prefixed. * @param allowShortChar will shorten hex value to 3 or 4 char if possible */ n.prototype.toHexShortString=function(t){return void 0===t&&(t=!1),1===this.a?this.toHexString(t):this.toHex8String(t)}, /** * Returns the object as a RGBA object. */ n.prototype.toRgb=function(){return{r:Math.round(this.r),g:Math.round(this.g),b:Math.round(this.b),a:this.a}}, /** * Returns the RGBA values interpolated into a string with the following format: * "RGBA(xxx, xxx, xxx, xx)". */ n.prototype.toRgbString=function(){var t=Math.round(this.r),r=Math.round(this.g),e=Math.round(this.b);return 1===this.a?"rgb(".concat(t,", ").concat(r,", ").concat(e,")"):"rgba(".concat(t,", ").concat(r,", ").concat(e,", ").concat(this.roundA,")")}, /** * Returns the object as a RGBA object. */ n.prototype.toPercentageRgb=function(){var r=function(r){return"".concat(Math.round(100*t(r,255)),"%")};return{r:r(this.r),g:r(this.g),b:r(this.b),a:this.a}}, /** * Returns the RGBA relative values interpolated into a string */ n.prototype.toPercentageRgbString=function(){var r=function(r){return Math.round(100*t(r,255))};return 1===this.a?"rgb(".concat(r(this.r),"%, ").concat(r(this.g),"%, ").concat(r(this.b),"%)"):"rgba(".concat(r(this.r),"%, ").concat(r(this.g),"%, ").concat(r(this.b),"%, ").concat(this.roundA,")")}, /** * The 'real' name of the color -if there is one. */ n.prototype.toName=function(){if(0===this.a)return"transparent";if(this.a<1)return!1;for(var t="#"+s(this.r,this.g,this.b,!1),r=0,e=Object.entries(u);r=0;return r||!n||!t.startsWith("hex")&&"name"!==t?("rgb"===t&&(e=this.toRgbString()),"prgb"===t&&(e=this.toPercentageRgbString()),"hex"!==t&&"hex6"!==t||(e=this.toHexString()),"hex3"===t&&(e=this.toHexString(!0)),"hex4"===t&&(e=this.toHex8String(!0)),"hex8"===t&&(e=this.toHex8String()),"name"===t&&(e=this.toName()),"hsl"===t&&(e=this.toHslString()),"hsv"===t&&(e=this.toHsvString()),e||this.toHexString()): // Special case for "transparent", all other non-alpha formats // will return rgba when there is transparency. "name"===t&&0===this.a?this.toName():this.toRgbString()},n.prototype.toNumber=function(){return(Math.round(this.r)<<16)+(Math.round(this.g)<<8)+Math.round(this.b)},n.prototype.clone=function(){return new n(this.toString())}, /** * Lighten the color a given amount. Providing 100 will always return white. * @param amount - valid between 1-100 */ n.prototype.lighten=function(t){void 0===t&&(t=10);var e=this.toHsl();return e.l+=t/100,e.l=r(e.l),new n(e)}, /** * Brighten the color a given amount, from 0 to 100. * @param amount - valid between 1-100 */ n.prototype.brighten=function(t){void 0===t&&(t=10);var r=this.toRgb();return r.r=Math.max(0,Math.min(255,r.r-Math.round(-t/100*255))),r.g=Math.max(0,Math.min(255,r.g-Math.round(-t/100*255))),r.b=Math.max(0,Math.min(255,r.b-Math.round(-t/100*255))),new n(r)}, /** * Darken the color a given amount, from 0 to 100. * Providing 100 will always return black. * @param amount - valid between 1-100 */ n.prototype.darken=function(t){void 0===t&&(t=10);var e=this.toHsl();return e.l-=t/100,e.l=r(e.l),new n(e)}, /** * Mix the color with pure white, from 0 to 100. * Providing 0 will do nothing, providing 100 will always return white. * @param amount - valid between 1-100 */ n.prototype.tint=function(t){return void 0===t&&(t=10),this.mix("white",t)}, /** * Mix the color with pure black, from 0 to 100. * Providing 0 will do nothing, providing 100 will always return black. * @param amount - valid between 1-100 */ n.prototype.shade=function(t){return void 0===t&&(t=10),this.mix("black",t)}, /** * Desaturate the color a given amount, from 0 to 100. * Providing 100 will is the same as calling greyscale * @param amount - valid between 1-100 */ n.prototype.desaturate=function(t){void 0===t&&(t=10);var e=this.toHsl();return e.s-=t/100,e.s=r(e.s),new n(e)}, /** * Saturate the color a given amount, from 0 to 100. * @param amount - valid between 1-100 */ n.prototype.saturate=function(t){void 0===t&&(t=10);var e=this.toHsl();return e.s+=t/100,e.s=r(e.s),new n(e)}, /** * Completely desaturates a color into greyscale. * Same as calling `desaturate(100)` */ n.prototype.greyscale=function(){return this.desaturate(100)}, /** * Spin takes a positive or negative amount within [-360, 360] indicating the change of hue. * Values outside of this range will be wrapped into this range. */ n.prototype.spin=function(t){var r=this.toHsl(),e=(r.h+t)%360;return r.h=e<0?360+e:e,new n(r)}, /** * Mix the current color a given amount with another color, from 0 to 100. * 0 means no mixing (return current color). */ n.prototype.mix=function(t,r){void 0===r&&(r=50);var e=this.toRgb(),a=new n(t).toRgb(),o=r/100;return new n({r:(a.r-e.r)*o+e.r,g:(a.g-e.g)*o+e.g,b:(a.b-e.b)*o+e.b,a:(a.a-e.a)*o+e.a})},n.prototype.analogous=function(t,r){void 0===t&&(t=6),void 0===r&&(r=30);var e=this.toHsl(),a=360/r,o=[this];for(e.h=(e.h-(a*t>>1)+720)%360;--t;)e.h=(e.h+a)%360,o.push(new n(e));return o}, /** * taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js */ n.prototype.complement=function(){var t=this.toHsl();return t.h=(t.h+180)%360,new n(t)},n.prototype.monochromatic=function(t){void 0===t&&(t=6);for(var r=this.toHsv(),e=r.h,a=r.s,o=r.v,i=[],h=1/t;t--;)i.push(new n({h:e,s:a,v:o})),o=(o+h)%1;return i},n.prototype.splitcomplement=function(){var t=this.toHsl(),r=t.h;return[this,new n({h:(r+72)%360,s:t.s,l:t.l}),new n({h:(r+216)%360,s:t.s,l:t.l})]}, /** * Compute how the color would appear on a background */ n.prototype.onBackground=function(t){var r=this.toRgb(),e=new n(t).toRgb(),a=r.a+e.a*(1-r.a);return new n({r:(r.r*r.a+e.r*e.a*(1-r.a))/a,g:(r.g*r.a+e.g*e.a*(1-r.a))/a,b:(r.b*r.a+e.b*e.a*(1-r.a))/a,a:a})}, /** * Alias for `polyad(3)` */ n.prototype.triad=function(){return this.polyad(3)}, /** * Alias for `polyad(4)` */ n.prototype.tetrad=function(){return this.polyad(4)}, /** * Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...) * monad, dyad, triad, tetrad, pentad, hexad, heptad, octad, etc... */ n.prototype.polyad=function(t){for(var r=this.toHsl(),e=r.h,a=[this],o=360/t,i=1;i