@ctrl/tinycolor
Advanced tools
Comparing version 3.6.1 to 4.0.0
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).tinycolor=e()}(this,(function(){"use strict";var t={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",goldenrod:"#daa520",gold:"#ffd700",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavenderblush:"#fff0f5",lavender:"#e6e6fa",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};function e(t,e){(function(t){return"string"==typeof t&&-1!==t.indexOf(".")&&1===parseFloat(t)})(t)&&(t="100%");var r=function(t){return"string"==typeof t&&-1!==t.indexOf("%")}(t);return t=360===e?t:Math.min(e,Math.max(0,parseFloat(t))),r&&(t=parseInt(String(t*e),10)/100),Math.abs(t-e)<1e-6?1:t=360===e?(t<0?t%e+e:t%e)/parseFloat(String(e)):t%e/parseFloat(String(e))}function r(t){return Math.min(1,Math.max(0,t))}function n(t){return t=parseFloat(t),(isNaN(t)||t<0||t>1)&&(t=1),t}function a(t){return t<=1?"".concat(100*Number(t),"%"):t}function o(t){return 1===t.length?"0"+t:String(t)}function i(t,r,n){t=e(t,255),r=e(r,255),n=e(n,255);var a=Math.max(t,r,n),o=Math.min(t,r,n),i=0,s=0,h=(a+o)/2;if(a===o)s=0,i=0;else{var u=a-o;switch(s=h>.5?u/(2-a-o):u/(a+o),a){case t:i=(r-n)/u+(r<n?6:0);break;case r:i=(n-t)/u+2;break;case n:i=(t-r)/u+4}i/=6}return{h:i,s:s,l:h}}function s(t,e,r){return r<0&&(r+=1),r>1&&(r-=1),r<1/6?t+6*r*(e-t):r<.5?e:r<2/3?t+(e-t)*(2/3-r)*6:t}function h(t,r,n){t=e(t,255),r=e(r,255),n=e(n,255);var a=Math.max(t,r,n),o=Math.min(t,r,n),i=0,s=a,h=a-o,u=0===a?0:h/a;if(a===o)i=0;else{switch(a){case t:i=(r-n)/h+(r<n?6:0);break;case r:i=(n-t)/h+2;break;case n:i=(t-r)/h+4}i/=6}return{h:i,s:u,v:s}}function u(t,e,r,n){var a=[o(Math.round(t).toString(16)),o(Math.round(e).toString(16)),o(Math.round(r).toString(16))];return n&&a[0].startsWith(a[0].charAt(1))&&a[1].startsWith(a[1].charAt(1))&&a[2].startsWith(a[2].charAt(1))?a[0].charAt(0)+a[1].charAt(0)+a[2].charAt(0):a.join("")}function f(t,e,r,n){return[o(c(n)),o(Math.round(t).toString(16)),o(Math.round(e).toString(16)),o(Math.round(r).toString(16))].join("")}function c(t){return Math.round(255*parseFloat(t)).toString(16)}function l(t){return d(t)/255}function d(t){return parseInt(t,16)}function g(t){var r,o,i,h={r:0,g:0,b:0},u=1,f=null,c=null,l=null,d=!1,g=!1;return"string"==typeof t&&(t=y(t)),"object"==typeof t&&(w(t.r)&&w(t.g)&&w(t.b)?(r=t.r,o=t.g,i=t.b,h={r:255*e(r,255),g:255*e(o,255),b:255*e(i,255)},d=!0,g="%"===String(t.r).substr(-1)?"prgb":"rgb"):w(t.h)&&w(t.s)&&w(t.v)?(f=a(t.s),c=a(t.v),h=function(t,r,n){t=6*e(t,360),r=e(r,100),n=e(n,100);var a=Math.floor(t),o=t-a,i=n*(1-r),s=n*(1-o*r),h=n*(1-(1-o)*r),u=a%6;return{r:255*[n,s,i,i,h,n][u],g:255*[h,n,n,s,i,i][u],b:255*[i,i,h,n,n,s][u]}}(t.h,f,c),d=!0,g="hsv"):w(t.h)&&w(t.s)&&w(t.l)&&(f=a(t.s),l=a(t.l),h=function(t,r,n){var a,o,i;if(t=e(t,360),r=e(r,100),n=e(n,100),0===r)o=n,i=n,a=n;else{var h=n<.5?n*(1+r):n+r-n*r,u=2*n-h;a=s(u,h,t+1/3),o=s(u,h,t),i=s(u,h,t-1/3)}return{r:255*a,g:255*o,b:255*i}}(t.h,f,l),d=!0,g="hsl"),Object.prototype.hasOwnProperty.call(t,"a")&&(u=t.a)),u=n(u),{ok:d,format:t.format||g,r:Math.min(255,Math.max(h.r,0)),g:Math.min(255,Math.max(h.g,0)),b:Math.min(255,Math.max(h.b,0)),a:u}}var b="(?:".concat("[-\\+]?\\d*\\.\\d+%?",")|(?:").concat("[-\\+]?\\d+%?",")"),p="[\\s|\\(]+(".concat(b,")[,|\\s]+(").concat(b,")[,|\\s]+(").concat(b,")\\s*\\)?"),v="[\\s|\\(]+(".concat(b,")[,|\\s]+(").concat(b,")[,|\\s]+(").concat(b,")[,|\\s]+(").concat(b,")\\s*\\)?"),m={CSS_UNIT:new RegExp(b),rgb:new RegExp("rgb"+p),rgba:new RegExp("rgba"+v),hsl:new RegExp("hsl"+p),hsla:new RegExp("hsla"+v),hsv:new RegExp("hsv"+p),hsva:new RegExp("hsva"+v),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 y(e){if(0===(e=e.trim().toLowerCase()).length)return!1;var r=!1;if(t[e])e=t[e],r=!0;else if("transparent"===e)return{r:0,g:0,b:0,a:0,format:"name"};var n=m.rgb.exec(e);return n?{r:n[1],g:n[2],b:n[3]}:(n=m.rgba.exec(e))?{r:n[1],g:n[2],b:n[3],a:n[4]}:(n=m.hsl.exec(e))?{h:n[1],s:n[2],l:n[3]}:(n=m.hsla.exec(e))?{h:n[1],s:n[2],l:n[3],a:n[4]}:(n=m.hsv.exec(e))?{h:n[1],s:n[2],v:n[3]}:(n=m.hsva.exec(e))?{h:n[1],s:n[2],v:n[3],a:n[4]}:(n=m.hex8.exec(e))?{r:d(n[1]),g:d(n[2]),b:d(n[3]),a:l(n[4]),format:r?"name":"hex8"}:(n=m.hex6.exec(e))?{r:d(n[1]),g:d(n[2]),b:d(n[3]),format:r?"name":"hex"}:(n=m.hex4.exec(e))?{r:d(n[1]+n[1]),g:d(n[2]+n[2]),b:d(n[3]+n[3]),a:l(n[4]+n[4]),format:r?"name":"hex8"}:!!(n=m.hex3.exec(e))&&{r:d(n[1]+n[1]),g:d(n[2]+n[2]),b:d(n[3]+n[3]),format:r?"name":"hex"}}function w(t){return Boolean(m.CSS_UNIT.exec(String(t)))}var M=function(){function a(t,e){var r;if(void 0===t&&(t=""),void 0===e&&(e={}),t instanceof a)return t;"number"==typeof t&&(t=function(t){return{r:t>>16,g:(65280&t)>>8,b:255&t}}(t)),this.originalInput=t;var n=g(t);this.originalInput=t,this.r=n.r,this.g=n.g,this.b=n.b,this.a=n.a,this.roundA=Math.round(100*this.a)/100,this.format=null!==(r=e.format)&&void 0!==r?r:n.format,this.gradientType=e.gradientType,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=n.ok}return a.prototype.isDark=function(){return this.getBrightness()<128},a.prototype.isLight=function(){return!this.isDark()},a.prototype.getBrightness=function(){var t=this.toRgb();return(299*t.r+587*t.g+114*t.b)/1e3},a.prototype.getLuminance=function(){var t=this.toRgb(),e=t.r/255,r=t.g/255,n=t.b/255;return.2126*(e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4))+.7152*(r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4))+.0722*(n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4))},a.prototype.getAlpha=function(){return this.a},a.prototype.setAlpha=function(t){return this.a=n(t),this.roundA=Math.round(100*this.a)/100,this},a.prototype.isMonochrome=function(){return 0===this.toHsl().s},a.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}},a.prototype.toHsvString=function(){var t=h(this.r,this.g,this.b),e=Math.round(360*t.h),r=Math.round(100*t.s),n=Math.round(100*t.v);return 1===this.a?"hsv(".concat(e,", ").concat(r,"%, ").concat(n,"%)"):"hsva(".concat(e,", ").concat(r,"%, ").concat(n,"%, ").concat(this.roundA,")")},a.prototype.toHsl=function(){var t=i(this.r,this.g,this.b);return{h:360*t.h,s:t.s,l:t.l,a:this.a}},a.prototype.toHslString=function(){var t=i(this.r,this.g,this.b),e=Math.round(360*t.h),r=Math.round(100*t.s),n=Math.round(100*t.l);return 1===this.a?"hsl(".concat(e,", ").concat(r,"%, ").concat(n,"%)"):"hsla(".concat(e,", ").concat(r,"%, ").concat(n,"%, ").concat(this.roundA,")")},a.prototype.toHex=function(t){return void 0===t&&(t=!1),u(this.r,this.g,this.b,t)},a.prototype.toHexString=function(t){return void 0===t&&(t=!1),"#"+this.toHex(t)},a.prototype.toHex8=function(t){return void 0===t&&(t=!1),function(t,e,r,n,a){var i=[o(Math.round(t).toString(16)),o(Math.round(e).toString(16)),o(Math.round(r).toString(16)),o(c(n))];return a&&i[0].startsWith(i[0].charAt(1))&&i[1].startsWith(i[1].charAt(1))&&i[2].startsWith(i[2].charAt(1))&&i[3].startsWith(i[3].charAt(1))?i[0].charAt(0)+i[1].charAt(0)+i[2].charAt(0)+i[3].charAt(0):i.join("")}(this.r,this.g,this.b,this.a,t)},a.prototype.toHex8String=function(t){return void 0===t&&(t=!1),"#"+this.toHex8(t)},a.prototype.toHexShortString=function(t){return void 0===t&&(t=!1),1===this.a?this.toHexString(t):this.toHex8String(t)},a.prototype.toRgb=function(){return{r:Math.round(this.r),g:Math.round(this.g),b:Math.round(this.b),a:this.a}},a.prototype.toRgbString=function(){var t=Math.round(this.r),e=Math.round(this.g),r=Math.round(this.b);return 1===this.a?"rgb(".concat(t,", ").concat(e,", ").concat(r,")"):"rgba(".concat(t,", ").concat(e,", ").concat(r,", ").concat(this.roundA,")")},a.prototype.toPercentageRgb=function(){var t=function(t){return"".concat(Math.round(100*e(t,255)),"%")};return{r:t(this.r),g:t(this.g),b:t(this.b),a:this.a}},a.prototype.toPercentageRgbString=function(){var t=function(t){return Math.round(100*e(t,255))};return 1===this.a?"rgb(".concat(t(this.r),"%, ").concat(t(this.g),"%, ").concat(t(this.b),"%)"):"rgba(".concat(t(this.r),"%, ").concat(t(this.g),"%, ").concat(t(this.b),"%, ").concat(this.roundA,")")},a.prototype.toName=function(){if(0===this.a)return"transparent";if(this.a<1)return!1;for(var e="#"+u(this.r,this.g,this.b,!1),r=0,n=Object.entries(t);r<n.length;r++){var a=n[r],o=a[0];if(e===a[1])return o}return!1},a.prototype.toString=function(t){var e=Boolean(t);t=null!=t?t:this.format;var r=!1,n=this.a<1&&this.a>=0;return e||!n||!t.startsWith("hex")&&"name"!==t?("rgb"===t&&(r=this.toRgbString()),"prgb"===t&&(r=this.toPercentageRgbString()),"hex"!==t&&"hex6"!==t||(r=this.toHexString()),"hex3"===t&&(r=this.toHexString(!0)),"hex4"===t&&(r=this.toHex8String(!0)),"hex8"===t&&(r=this.toHex8String()),"name"===t&&(r=this.toName()),"hsl"===t&&(r=this.toHslString()),"hsv"===t&&(r=this.toHsvString()),r||this.toHexString()):"name"===t&&0===this.a?this.toName():this.toRgbString()},a.prototype.toNumber=function(){return(Math.round(this.r)<<16)+(Math.round(this.g)<<8)+Math.round(this.b)},a.prototype.clone=function(){return new a(this.toString())},a.prototype.lighten=function(t){void 0===t&&(t=10);var e=this.toHsl();return e.l+=t/100,e.l=r(e.l),new a(e)},a.prototype.brighten=function(t){void 0===t&&(t=10);var e=this.toRgb();return e.r=Math.max(0,Math.min(255,e.r-Math.round(-t/100*255))),e.g=Math.max(0,Math.min(255,e.g-Math.round(-t/100*255))),e.b=Math.max(0,Math.min(255,e.b-Math.round(-t/100*255))),new a(e)},a.prototype.darken=function(t){void 0===t&&(t=10);var e=this.toHsl();return e.l-=t/100,e.l=r(e.l),new a(e)},a.prototype.tint=function(t){return void 0===t&&(t=10),this.mix("white",t)},a.prototype.shade=function(t){return void 0===t&&(t=10),this.mix("black",t)},a.prototype.desaturate=function(t){void 0===t&&(t=10);var e=this.toHsl();return e.s-=t/100,e.s=r(e.s),new a(e)},a.prototype.saturate=function(t){void 0===t&&(t=10);var e=this.toHsl();return e.s+=t/100,e.s=r(e.s),new a(e)},a.prototype.greyscale=function(){return this.desaturate(100)},a.prototype.spin=function(t){var e=this.toHsl(),r=(e.h+t)%360;return e.h=r<0?360+r:r,new a(e)},a.prototype.mix=function(t,e){void 0===e&&(e=50);var r=this.toRgb(),n=new a(t).toRgb(),o=e/100;return new a({r:(n.r-r.r)*o+r.r,g:(n.g-r.g)*o+r.g,b:(n.b-r.b)*o+r.b,a:(n.a-r.a)*o+r.a})},a.prototype.analogous=function(t,e){void 0===t&&(t=6),void 0===e&&(e=30);var r=this.toHsl(),n=360/e,o=[this];for(r.h=(r.h-(n*t>>1)+720)%360;--t;)r.h=(r.h+n)%360,o.push(new a(r));return o},a.prototype.complement=function(){var t=this.toHsl();return t.h=(t.h+180)%360,new a(t)},a.prototype.monochromatic=function(t){void 0===t&&(t=6);for(var e=this.toHsv(),r=e.h,n=e.s,o=e.v,i=[],s=1/t;t--;)i.push(new a({h:r,s:n,v:o})),o=(o+s)%1;return i},a.prototype.splitcomplement=function(){var t=this.toHsl(),e=t.h;return[this,new a({h:(e+72)%360,s:t.s,l:t.l}),new a({h:(e+216)%360,s:t.s,l:t.l})]},a.prototype.onBackground=function(t){var e=this.toRgb(),r=new a(t).toRgb(),n=e.a+r.a*(1-e.a);return new a({r:(e.r*e.a+r.r*r.a*(1-e.a))/n,g:(e.g*e.a+r.g*r.a*(1-e.a))/n,b:(e.b*e.a+r.b*r.a*(1-e.a))/n,a:n})},a.prototype.triad=function(){return this.polyad(3)},a.prototype.tetrad=function(){return this.polyad(4)},a.prototype.polyad=function(t){for(var e=this.toHsl(),r=e.h,n=[this],o=360/t,i=1;i<t;i++)n.push(new a({h:(r+i*o)%360,s:e.s,l:e.l}));return n},a.prototype.equals=function(t){return this.toRgbString()===new a(t).toRgbString()},a}();function x(t){t>=334&&t<=360&&(t-=360);for(var e=0,r=S;e<r.length;e++){var n=A(r[e]);if(n.hueRange&&t>=n.hueRange[0]&&t<=n.hueRange[1])return n}throw Error("Color not found")}function k(t,e){if(void 0===e)return Math.floor(t[0]+Math.random()*(t[1]+1-t[0]));var r=t[1]||1,n=t[0]||0,a=(e=(9301*e+49297)%233280)/233280;return Math.floor(n+a*(r-n))}function A(t){var e=t.lowerBounds[0][0],r=t.lowerBounds[t.lowerBounds.length-1][0],n=t.lowerBounds[t.lowerBounds.length-1][1],a=t.lowerBounds[0][1];return{name:t.name,hueRange:t.hueRange,lowerBounds:t.lowerBounds,saturationRange:[e,r],brightnessRange:[n,a]}}var S=[{name:"monochrome",hueRange:null,lowerBounds:[[0,0],[100,0]]},{name:"red",hueRange:[-26,18],lowerBounds:[[20,100],[30,92],[40,89],[50,85],[60,78],[70,70],[80,60],[90,55],[100,50]]},{name:"orange",hueRange:[19,46],lowerBounds:[[20,100],[30,93],[40,88],[50,86],[60,85],[70,70],[100,70]]},{name:"yellow",hueRange:[47,62],lowerBounds:[[25,100],[40,94],[50,89],[60,86],[70,84],[80,82],[90,80],[100,75]]},{name:"green",hueRange:[63,178],lowerBounds:[[30,100],[40,90],[50,85],[60,81],[70,74],[80,64],[90,50],[100,40]]},{name:"blue",hueRange:[179,257],lowerBounds:[[20,100],[30,86],[40,80],[50,74],[60,60],[70,52],[80,44],[90,39],[100,35]]},{name:"purple",hueRange:[258,282],lowerBounds:[[20,100],[30,87],[40,79],[50,70],[60,65],[70,59],[80,52],[90,45],[100,42]]},{name:"pink",hueRange:[283,334],lowerBounds:[[20,100],[30,90],[40,86],[60,84],[80,80],[90,75],[100,73]]}];function R(t,e){var r=new M(t),n=new M(e);return(Math.max(r.getLuminance(),n.getLuminance())+.05)/(Math.min(r.getLuminance(),n.getLuminance())+.05)}var H=function(t,e){return void 0===t&&(t=""),void 0===e&&(e={}),new M(t,e)};return H.TinyColor=M,H.readability=R,H.mostReadable=function t(e,r,n){void 0===n&&(n={includeFallbackColors:!1,level:"AA",size:"small"});for(var a=null,o=0,i=n.includeFallbackColors,s=n.level,h=n.size,u=0,f=r;u<f.length;u++){var c=f[u],l=R(e,c);l>o&&(o=l,a=new M(c))}return function(t,e,r){var n,a;void 0===r&&(r={level:"AA",size:"small"});var o=R(t,e);switch((null!==(n=r.level)&&void 0!==n?n:"AA")+(null!==(a=r.size)&&void 0!==a?a:"small")){case"AAsmall":case"AAAlarge":return o>=4.5;case"AAlarge":return o>=3;case"AAAsmall":return o>=7;default:return!1}}(e,a,{level:s,size:h})||!i?a:(n.includeFallbackColors=!1,t(e,["#fff","#000"],n))},H.random=function t(e){if(void 0===e&&(e={}),void 0!==e.count&&null!==e.count){var r=e.count,n=[];for(e.count=void 0;r>n.length;)e.count=null,e.seed&&(e.seed+=1),n.push(t(e));return e.count=r,n}var a=function(t,e){var r=k(function(t){var e=parseInt(t,10);if(!Number.isNaN(e)&&e<360&&e>0)return[e,e];if("string"==typeof t){var r=S.find((function(e){return e.name===t}));if(r){var n=A(r);if(n.hueRange)return n.hueRange}var a=new M(t);if(a.isValid){var o=a.toHsv().h;return[o,o]}}return[0,360]}(t),e);r<0&&(r=360+r);return r}(e.hue,e.seed),o=function(t,e){if("monochrome"===e.hue)return 0;if("random"===e.luminosity)return k([0,100],e.seed);var r=x(t).saturationRange,n=r[0],a=r[1];switch(e.luminosity){case"bright":n=55;break;case"dark":n=a-10;break;case"light":a=55}return k([n,a],e.seed)}(a,e),i=function(t,e,r){var n=function(t,e){for(var r=x(t).lowerBounds,n=0;n<r.length-1;n++){var a=r[n][0],o=r[n][1],i=r[n+1][0],s=r[n+1][1];if(e>=a&&e<=i){var h=(s-o)/(i-a);return h*e+(o-h*a)}}return 0}(t,e),a=100;switch(r.luminosity){case"dark":a=n+20;break;case"light":n=(a+n)/2;break;case"random":n=0,a=100}return k([n,a],r.seed)}(a,o,e),s={h:a,s:o,v:i};return void 0!==e.alpha&&(s.a=e.alpha),new M(s)},H.names=t,H.fromRatio=function(t,e){var r={r:a(t.r),g:a(t.g),b:a(t.b)};return void 0!==t.a&&(r.a=Number(t.a)),new M(r,e)},H.legacyRandom=function(){return new M({r:Math.random(),g:Math.random(),b:Math.random()})},H.toMsFilter=function(t,e){var r=new M(t),n="#"+f(r.r,r.g,r.b,r.a),a=n,o=r.gradientType?"GradientType = 1, ":"";if(e){var i=new M(e);a="#"+f(i.r,i.g,i.b,i.a)}return"progid:DXImageTransform.Microsoft.gradient(".concat(o,"startColorstr=").concat(n,",endColorstr=").concat(a,")")},H.inputToRGB=g,H.stringInputToObject=y,H.isValidCSSUnit=w,H})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).tinycolor=e()}(this,(function(){"use strict";const t={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",goldenrod:"#daa520",gold:"#ffd700",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavenderblush:"#fff0f5",lavender:"#e6e6fa",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};function e(t,e){(function(t){return"string"==typeof t&&-1!==t.indexOf(".")&&1===parseFloat(t)})(t)&&(t="100%");const r=function(t){return"string"==typeof t&&-1!==t.indexOf("%")}(t);return t=360===e?t:Math.min(e,Math.max(0,parseFloat(t))),r&&(t=parseInt(String(t*e),10)/100),Math.abs(t-e)<1e-6?1:t=360===e?(t<0?t%e+e:t%e)/parseFloat(String(e)):t%e/parseFloat(String(e))}function r(t){return Math.min(1,Math.max(0,t))}function n(t){return t=parseFloat(t),(isNaN(t)||t<0||t>1)&&(t=1),t}function a(t){return Number(t)<=1?100*Number(t)+"%":t}function s(t){return 1===t.length?"0"+t:String(t)}function o(t,r,n){t=e(t,255),r=e(r,255),n=e(n,255);const a=Math.max(t,r,n),s=Math.min(t,r,n);let o=0,i=0;const h=(a+s)/2;if(a===s)i=0,o=0;else{const e=a-s;switch(i=h>.5?e/(2-a-s):e/(a+s),a){case t:o=(r-n)/e+(r<n?6:0);break;case r:o=(n-t)/e+2;break;case n:o=(t-r)/e+4}o/=6}return{h:o,s:i,l:h}}function i(t,e,r){return r<0&&(r+=1),r>1&&(r-=1),r<1/6?t+6*r*(e-t):r<.5?e:r<2/3?t+(e-t)*(2/3-r)*6:t}function h(t,r,n){t=e(t,255),r=e(r,255),n=e(n,255);const a=Math.max(t,r,n),s=Math.min(t,r,n);let o=0;const i=a,h=a-s,u=0===a?0:h/a;if(a===s)o=0;else{switch(a){case t:o=(r-n)/h+(r<n?6:0);break;case r:o=(n-t)/h+2;break;case n:o=(t-r)/h+4}o/=6}return{h:o,s:u,v:i}}function u(t,e,r,n){const a=[s(Math.round(t).toString(16)),s(Math.round(e).toString(16)),s(Math.round(r).toString(16))];return n&&a[0].startsWith(a[0].charAt(1))&&a[1].startsWith(a[1].charAt(1))&&a[2].startsWith(a[2].charAt(1))?a[0].charAt(0)+a[1].charAt(0)+a[2].charAt(0):a.join("")}function f(t,e,r,n){return[s(l(n)),s(Math.round(t).toString(16)),s(Math.round(e).toString(16)),s(Math.round(r).toString(16))].join("")}function l(t){return Math.round(255*parseFloat(t)).toString(16)}function c(t){return g(t)/255}function g(t){return parseInt(t,16)}function d(t){let r={r:0,g:0,b:0},s=1,o=null,h=null,u=null,f=!1,l=!1;var c,g,d;return"string"==typeof t&&(t=M(t)),"object"==typeof t&&(x(t.r)&&x(t.g)&&x(t.b)?(c=t.r,g=t.g,d=t.b,r={r:255*e(c,255),g:255*e(g,255),b:255*e(d,255)},f=!0,l="%"===String(t.r).substr(-1)?"prgb":"rgb"):x(t.h)&&x(t.s)&&x(t.v)?(o=a(t.s),h=a(t.v),r=function(t,r,n){t=6*e(t,360),r=e(r,100),n=e(n,100);const a=Math.floor(t),s=t-a,o=n*(1-r),i=n*(1-s*r),h=n*(1-(1-s)*r),u=a%6;return{r:255*[n,i,o,o,h,n][u],g:255*[h,n,n,i,o,o][u],b:255*[o,o,h,n,n,i][u]}}(t.h,o,h),f=!0,l="hsv"):x(t.h)&&x(t.s)&&x(t.l)&&(o=a(t.s),u=a(t.l),r=function(t,r,n){let a,s,o;if(t=e(t,360),r=e(r,100),n=e(n,100),0===r)s=n,o=n,a=n;else{const e=n<.5?n*(1+r):n+r-n*r,h=2*n-e;a=i(h,e,t+1/3),s=i(h,e,t),o=i(h,e,t-1/3)}return{r:255*a,g:255*s,b:255*o}}(t.h,o,u),f=!0,l="hsl"),Object.prototype.hasOwnProperty.call(t,"a")&&(s=t.a)),s=n(s),{ok:f,format:t.format||l,r:Math.min(255,Math.max(r.r,0)),g:Math.min(255,Math.max(r.g,0)),b:Math.min(255,Math.max(r.b,0)),a:s}}const b="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)",m=`[\\s|\\(]+(${b})[,|\\s]+(${b})[,|\\s]+(${b})\\s*\\)?`,p=`[\\s|\\(]+(${b})[,|\\s]+(${b})[,|\\s]+(${b})[,|\\s]+(${b})\\s*\\)?`,w={CSS_UNIT:new RegExp(b),rgb:new RegExp("rgb"+m),rgba:new RegExp("rgba"+p),hsl:new RegExp("hsl"+m),hsla:new RegExp("hsla"+p),hsv:new RegExp("hsv"+m),hsva:new RegExp("hsva"+p),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 M(e){if(0===(e=e.trim().toLowerCase()).length)return!1;let r=!1;if(t[e])e=t[e],r=!0;else if("transparent"===e)return{r:0,g:0,b:0,a:0,format:"name"};let n=w.rgb.exec(e);return n?{r:n[1],g:n[2],b:n[3]}:(n=w.rgba.exec(e),n?{r:n[1],g:n[2],b:n[3],a:n[4]}:(n=w.hsl.exec(e),n?{h:n[1],s:n[2],l:n[3]}:(n=w.hsla.exec(e),n?{h:n[1],s:n[2],l:n[3],a:n[4]}:(n=w.hsv.exec(e),n?{h:n[1],s:n[2],v:n[3]}:(n=w.hsva.exec(e),n?{h:n[1],s:n[2],v:n[3],a:n[4]}:(n=w.hex8.exec(e),n?{r:g(n[1]),g:g(n[2]),b:g(n[3]),a:c(n[4]),format:r?"name":"hex8"}:(n=w.hex6.exec(e),n?{r:g(n[1]),g:g(n[2]),b:g(n[3]),format:r?"name":"hex"}:(n=w.hex4.exec(e),n?{r:g(n[1]+n[1]),g:g(n[2]+n[2]),b:g(n[3]+n[3]),a:c(n[4]+n[4]),format:r?"name":"hex8"}:(n=w.hex3.exec(e),!!n&&{r:g(n[1]+n[1]),g:g(n[2]+n[2]),b:g(n[3]+n[3]),format:r?"name":"hex"})))))))))}function x(t){return Boolean(w.CSS_UNIT.exec(String(t)))}class y{constructor(t="",e={}){if(t instanceof y)return t;"number"==typeof t&&(t=function(t){return{r:t>>16,g:(65280&t)>>8,b:255&t}}(t)),this.originalInput=t;const r=d(t);this.originalInput=t,this.r=r.r,this.g=r.g,this.b=r.b,this.a=r.a,this.roundA=Math.round(100*this.a)/100,this.format=e.format??r.format,this.gradientType=e.gradientType,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=r.ok}isDark(){return this.getBrightness()<128}isLight(){return!this.isDark()}getBrightness(){const t=this.toRgb();return(299*t.r+587*t.g+114*t.b)/1e3}getLuminance(){const t=this.toRgb();let e,r,n;const a=t.r/255,s=t.g/255,o=t.b/255;return e=a<=.03928?a/12.92:Math.pow((a+.055)/1.055,2.4),r=s<=.03928?s/12.92:Math.pow((s+.055)/1.055,2.4),n=o<=.03928?o/12.92:Math.pow((o+.055)/1.055,2.4),.2126*e+.7152*r+.0722*n}getAlpha(){return this.a}setAlpha(t){return this.a=n(t),this.roundA=Math.round(100*this.a)/100,this}isMonochrome(){const{s:t}=this.toHsl();return 0===t}toHsv(){const t=h(this.r,this.g,this.b);return{h:360*t.h,s:t.s,v:t.v,a:this.a}}toHsvString(){const t=h(this.r,this.g,this.b),e=Math.round(360*t.h),r=Math.round(100*t.s),n=Math.round(100*t.v);return 1===this.a?`hsv(${e}, ${r}%, ${n}%)`:`hsva(${e}, ${r}%, ${n}%, ${this.roundA})`}toHsl(){const t=o(this.r,this.g,this.b);return{h:360*t.h,s:t.s,l:t.l,a:this.a}}toHslString(){const t=o(this.r,this.g,this.b),e=Math.round(360*t.h),r=Math.round(100*t.s),n=Math.round(100*t.l);return 1===this.a?`hsl(${e}, ${r}%, ${n}%)`:`hsla(${e}, ${r}%, ${n}%, ${this.roundA})`}toHex(t=!1){return u(this.r,this.g,this.b,t)}toHexString(t=!1){return"#"+this.toHex(t)}toHex8(t=!1){return function(t,e,r,n,a){const o=[s(Math.round(t).toString(16)),s(Math.round(e).toString(16)),s(Math.round(r).toString(16)),s(l(n))];return a&&o[0].startsWith(o[0].charAt(1))&&o[1].startsWith(o[1].charAt(1))&&o[2].startsWith(o[2].charAt(1))&&o[3].startsWith(o[3].charAt(1))?o[0].charAt(0)+o[1].charAt(0)+o[2].charAt(0)+o[3].charAt(0):o.join("")}(this.r,this.g,this.b,this.a,t)}toHex8String(t=!1){return"#"+this.toHex8(t)}toHexShortString(t=!1){return 1===this.a?this.toHexString(t):this.toHex8String(t)}toRgb(){return{r:Math.round(this.r),g:Math.round(this.g),b:Math.round(this.b),a:this.a}}toRgbString(){const t=Math.round(this.r),e=Math.round(this.g),r=Math.round(this.b);return 1===this.a?`rgb(${t}, ${e}, ${r})`:`rgba(${t}, ${e}, ${r}, ${this.roundA})`}toPercentageRgb(){const t=t=>`${Math.round(100*e(t,255))}%`;return{r:t(this.r),g:t(this.g),b:t(this.b),a:this.a}}toPercentageRgbString(){const t=t=>Math.round(100*e(t,255));return 1===this.a?`rgb(${t(this.r)}%, ${t(this.g)}%, ${t(this.b)}%)`:`rgba(${t(this.r)}%, ${t(this.g)}%, ${t(this.b)}%, ${this.roundA})`}toName(){if(0===this.a)return"transparent";if(this.a<1)return!1;const e="#"+u(this.r,this.g,this.b,!1);for(const[r,n]of Object.entries(t))if(e===n)return r;return!1}toString(t){const e=Boolean(t);t=t??this.format;let r=!1;const n=this.a<1&&this.a>=0;return e||!n||!t.startsWith("hex")&&"name"!==t?("rgb"===t&&(r=this.toRgbString()),"prgb"===t&&(r=this.toPercentageRgbString()),"hex"!==t&&"hex6"!==t||(r=this.toHexString()),"hex3"===t&&(r=this.toHexString(!0)),"hex4"===t&&(r=this.toHex8String(!0)),"hex8"===t&&(r=this.toHex8String()),"name"===t&&(r=this.toName()),"hsl"===t&&(r=this.toHslString()),"hsv"===t&&(r=this.toHsvString()),r||this.toHexString()):"name"===t&&0===this.a?this.toName():this.toRgbString()}toNumber(){return(Math.round(this.r)<<16)+(Math.round(this.g)<<8)+Math.round(this.b)}clone(){return new y(this.toString())}lighten(t=10){const e=this.toHsl();return e.l+=t/100,e.l=r(e.l),new y(e)}brighten(t=10){const e=this.toRgb();return e.r=Math.max(0,Math.min(255,e.r-Math.round(-t/100*255))),e.g=Math.max(0,Math.min(255,e.g-Math.round(-t/100*255))),e.b=Math.max(0,Math.min(255,e.b-Math.round(-t/100*255))),new y(e)}darken(t=10){const e=this.toHsl();return e.l-=t/100,e.l=r(e.l),new y(e)}tint(t=10){return this.mix("white",t)}shade(t=10){return this.mix("black",t)}desaturate(t=10){const e=this.toHsl();return e.s-=t/100,e.s=r(e.s),new y(e)}saturate(t=10){const e=this.toHsl();return e.s+=t/100,e.s=r(e.s),new y(e)}greyscale(){return this.desaturate(100)}spin(t){const e=this.toHsl(),r=(e.h+t)%360;return e.h=r<0?360+r:r,new y(e)}mix(t,e=50){const r=this.toRgb(),n=new y(t).toRgb(),a=e/100,s={r:(n.r-r.r)*a+r.r,g:(n.g-r.g)*a+r.g,b:(n.b-r.b)*a+r.b,a:(n.a-r.a)*a+r.a};return new y(s)}analogous(t=6,e=30){const r=this.toHsl(),n=360/e,a=[this];for(r.h=(r.h-(n*t>>1)+720)%360;--t;)r.h=(r.h+n)%360,a.push(new y(r));return a}complement(){const t=this.toHsl();return t.h=(t.h+180)%360,new y(t)}monochromatic(t=6){const e=this.toHsv(),{h:r}=e,{s:n}=e;let{v:a}=e;const s=[],o=1/t;for(;t--;)s.push(new y({h:r,s:n,v:a})),a=(a+o)%1;return s}splitcomplement(){const t=this.toHsl(),{h:e}=t;return[this,new y({h:(e+72)%360,s:t.s,l:t.l}),new y({h:(e+216)%360,s:t.s,l:t.l})]}onBackground(t){const e=this.toRgb(),r=new y(t).toRgb(),n=e.a+r.a*(1-e.a);return new y({r:(e.r*e.a+r.r*r.a*(1-e.a))/n,g:(e.g*e.a+r.g*r.a*(1-e.a))/n,b:(e.b*e.a+r.b*r.a*(1-e.a))/n,a:n})}triad(){return this.polyad(3)}tetrad(){return this.polyad(4)}polyad(t){const e=this.toHsl(),{h:r}=e,n=[this],a=360/t;for(let s=1;s<t;s++)n.push(new y({h:(r+s*a)%360,s:e.s,l:e.l}));return n}equals(t){return this.toRgbString()===new y(t).toRgbString()}}function k(t){t>=334&&t<=360&&(t-=360);for(const e of S){const r=v(e);if(r.hueRange&&t>=r.hueRange[0]&&t<=r.hueRange[1])return r}throw Error("Color not found")}function A(t,e){if(void 0===e)return Math.floor(t[0]+Math.random()*(t[1]+1-t[0]));const r=t[1]||1,n=t[0]||0,a=(e=(9301*e+49297)%233280)/233280;return Math.floor(n+a*(r-n))}function v(t){const e=t.lowerBounds[0][0],r=t.lowerBounds[t.lowerBounds.length-1][0],n=t.lowerBounds[t.lowerBounds.length-1][1],a=t.lowerBounds[0][1];return{name:t.name,hueRange:t.hueRange,lowerBounds:t.lowerBounds,saturationRange:[e,r],brightnessRange:[n,a]}}const S=[{name:"monochrome",hueRange:null,lowerBounds:[[0,0],[100,0]]},{name:"red",hueRange:[-26,18],lowerBounds:[[20,100],[30,92],[40,89],[50,85],[60,78],[70,70],[80,60],[90,55],[100,50]]},{name:"orange",hueRange:[19,46],lowerBounds:[[20,100],[30,93],[40,88],[50,86],[60,85],[70,70],[100,70]]},{name:"yellow",hueRange:[47,62],lowerBounds:[[25,100],[40,94],[50,89],[60,86],[70,84],[80,82],[90,80],[100,75]]},{name:"green",hueRange:[63,178],lowerBounds:[[30,100],[40,90],[50,85],[60,81],[70,74],[80,64],[90,50],[100,40]]},{name:"blue",hueRange:[179,257],lowerBounds:[[20,100],[30,86],[40,80],[50,74],[60,60],[70,52],[80,44],[90,39],[100,35]]},{name:"purple",hueRange:[258,282],lowerBounds:[[20,100],[30,87],[40,79],[50,70],[60,65],[70,59],[80,52],[90,45],[100,42]]},{name:"pink",hueRange:[283,334],lowerBounds:[[20,100],[30,90],[40,86],[60,84],[80,80],[90,75],[100,73]]}];function R(t,e){const r=new y(t),n=new y(e);return(Math.max(r.getLuminance(),n.getLuminance())+.05)/(Math.min(r.getLuminance(),n.getLuminance())+.05)}const $={TinyColor:y,readability:R,mostReadable:function t(e,r,n={includeFallbackColors:!1,level:"AA",size:"small"}){let a=null,s=0;const{includeFallbackColors:o,level:i,size:h}=n;for(const t of r){const r=R(e,t);r>s&&(s=r,a=new y(t))}return function(t,e,r={level:"AA",size:"small"}){const n=R(t,e);switch((r.level??"AA")+(r.size??"small")){case"AAsmall":case"AAAlarge":return n>=4.5;case"AAlarge":return n>=3;case"AAAsmall":return n>=7;default:return!1}}(e,a,{level:i,size:h})||!o?a:(n.includeFallbackColors=!1,t(e,["#fff","#000"],n))},random:function t(e={}){if(void 0!==e.count&&null!==e.count){const r=e.count,n=[];for(e.count=void 0;r>n.length;)e.count=null,e.seed&&(e.seed+=1),n.push(t(e));return e.count=r,n}const r=function(t,e){let r=A(function(t){const e=parseInt(t,10);if(!Number.isNaN(e)&&e<360&&e>0)return[e,e];if("string"==typeof t){const e=S.find((e=>e.name===t));if(e){const t=v(e);if(t.hueRange)return t.hueRange}const r=new y(t);if(r.isValid){const t=r.toHsv().h;return[t,t]}}return[0,360]}(t),e);r<0&&(r=360+r);return r}(e.hue,e.seed),n=function(t,e){if("monochrome"===e.hue)return 0;if("random"===e.luminosity)return A([0,100],e.seed);const{saturationRange:r}=k(t);let n=r[0],a=r[1];switch(e.luminosity){case"bright":n=55;break;case"dark":n=a-10;break;case"light":a=55}return A([n,a],e.seed)}(r,e),a=function(t,e,r){let n=function(t,e){const{lowerBounds:r}=k(t);for(let t=0;t<r.length-1;t++){const n=r[t][0],a=r[t][1],s=r[t+1][0],o=r[t+1][1];if(e>=n&&e<=s){const t=(o-a)/(s-n);return t*e+(a-t*n)}}return 0}(t,e),a=100;switch(r.luminosity){case"dark":a=n+20;break;case"light":n=(a+n)/2;break;case"random":n=0,a=100}return A([n,a],r.seed)}(r,n,e),s={h:r,s:n,v:a};return void 0!==e.alpha&&(s.a=e.alpha),new y(s)},names:t,fromRatio:function(t,e){const r={r:a(t.r),g:a(t.g),b:a(t.b)};return void 0!==t.a&&(r.a=Number(t.a)),new y(r,e)},legacyRandom:function(){return new y({r:Math.random(),g:Math.random(),b:Math.random()})},toMsFilter:function(t,e){const r=new y(t),n="#"+f(r.r,r.g,r.b,r.a);let a=n;const s=r.gradientType?"GradientType = 1, ":"";if(e){const t=new y(e);a="#"+f(t.r,t.g,t.b,t.a)}return`progid:DXImageTransform.Microsoft.gradient(${s}startColorstr=${n},endColorstr=${a})`},inputToRGB:d,stringInputToObject:M,isValidCSSUnit:x};return $})); | ||
//# sourceMappingURL=tinycolor.umd.min.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.numberInputToObject = exports.parseIntFromHex = exports.convertHexToDecimal = exports.convertDecimalToHex = exports.rgbaToArgbHex = exports.rgbaToHex = exports.rgbToHex = exports.hsvToRgb = exports.rgbToHsv = exports.hslToRgb = exports.rgbToHsl = exports.rgbToRgb = void 0; | ||
var util_js_1 = require("./util.js"); | ||
const util_js_1 = require("./util.js"); | ||
// `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from: | ||
@@ -30,7 +30,7 @@ // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript> | ||
b = (0, util_js_1.bound01)(b, 255); | ||
var max = Math.max(r, g, b); | ||
var min = Math.min(r, g, b); | ||
var h = 0; | ||
var s = 0; | ||
var l = (max + min) / 2; | ||
const max = Math.max(r, g, b); | ||
const min = Math.min(r, g, b); | ||
let h = 0; | ||
let s = 0; | ||
const l = (max + min) / 2; | ||
if (max === min) { | ||
@@ -41,3 +41,3 @@ s = 0; | ||
else { | ||
var d = max - min; | ||
const d = max - min; | ||
s = l > 0.5 ? d / (2 - max - min) : d / (max + min); | ||
@@ -59,3 +59,3 @@ switch (max) { | ||
} | ||
return { h: h, s: s, l: l }; | ||
return { h, s, l }; | ||
} | ||
@@ -88,5 +88,5 @@ exports.rgbToHsl = rgbToHsl; | ||
function hslToRgb(h, s, l) { | ||
var r; | ||
var g; | ||
var b; | ||
let r; | ||
let g; | ||
let b; | ||
h = (0, util_js_1.bound01)(h, 360); | ||
@@ -102,4 +102,4 @@ s = (0, util_js_1.bound01)(s, 100); | ||
else { | ||
var q = l < 0.5 ? l * (1 + s) : l + s - l * s; | ||
var p = 2 * l - q; | ||
const q = l < 0.5 ? l * (1 + s) : l + s - l * s; | ||
const p = 2 * l - q; | ||
r = hue2rgb(p, q, h + 1 / 3); | ||
@@ -122,8 +122,8 @@ g = hue2rgb(p, q, h); | ||
b = (0, util_js_1.bound01)(b, 255); | ||
var max = Math.max(r, g, b); | ||
var min = Math.min(r, g, b); | ||
var h = 0; | ||
var v = max; | ||
var d = max - min; | ||
var s = max === 0 ? 0 : d / max; | ||
const max = Math.max(r, g, b); | ||
const min = Math.min(r, g, b); | ||
let h = 0; | ||
const v = max; | ||
const d = max - min; | ||
const s = max === 0 ? 0 : d / max; | ||
if (max === min) { | ||
@@ -148,3 +148,3 @@ h = 0; // achromatic | ||
} | ||
return { h: h, s: s, v: v }; | ||
return { h, s, v }; | ||
} | ||
@@ -162,11 +162,11 @@ exports.rgbToHsv = rgbToHsv; | ||
v = (0, util_js_1.bound01)(v, 100); | ||
var i = Math.floor(h); | ||
var f = h - i; | ||
var p = v * (1 - s); | ||
var q = v * (1 - f * s); | ||
var t = v * (1 - (1 - f) * s); | ||
var mod = i % 6; | ||
var r = [v, q, p, p, t, v][mod]; | ||
var g = [t, v, v, q, p, p][mod]; | ||
var b = [p, p, t, v, v, q][mod]; | ||
const i = Math.floor(h); | ||
const f = h - i; | ||
const p = v * (1 - s); | ||
const q = v * (1 - f * s); | ||
const t = v * (1 - (1 - f) * s); | ||
const mod = i % 6; | ||
const r = [v, q, p, p, t, v][mod]; | ||
const g = [t, v, v, q, p, p][mod]; | ||
const b = [p, p, t, v, v, q][mod]; | ||
return { r: r * 255, g: g * 255, b: b * 255 }; | ||
@@ -182,3 +182,3 @@ } | ||
function rgbToHex(r, g, b, allow3Char) { | ||
var hex = [ | ||
const hex = [ | ||
(0, util_js_1.pad2)(Math.round(r).toString(16)), | ||
@@ -206,3 +206,3 @@ (0, util_js_1.pad2)(Math.round(g).toString(16)), | ||
function rgbaToHex(r, g, b, a, allow4Char) { | ||
var hex = [ | ||
const hex = [ | ||
(0, util_js_1.pad2)(Math.round(r).toString(16)), | ||
@@ -229,3 +229,3 @@ (0, util_js_1.pad2)(Math.round(g).toString(16)), | ||
function rgbaToArgbHex(r, g, b, a) { | ||
var hex = [ | ||
const hex = [ | ||
(0, util_js_1.pad2)(convertDecimalToHex(a)), | ||
@@ -232,0 +232,0 @@ (0, util_js_1.pad2)(Math.round(r).toString(16)), |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isValidCSSUnit = exports.stringInputToObject = exports.inputToRGB = void 0; | ||
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */ | ||
var conversion_js_1 = require("./conversion.js"); | ||
var css_color_names_js_1 = require("./css-color-names.js"); | ||
var util_js_1 = require("./util.js"); | ||
const conversion_js_1 = require("./conversion.js"); | ||
const css_color_names_js_1 = require("./css-color-names.js"); | ||
const util_js_1 = require("./util.js"); | ||
/** | ||
@@ -27,9 +26,9 @@ * Given a string or object, convert that input to RGB | ||
function inputToRGB(color) { | ||
var rgb = { r: 0, g: 0, b: 0 }; | ||
var a = 1; | ||
var s = null; | ||
var v = null; | ||
var l = null; | ||
var ok = false; | ||
var format = false; | ||
let rgb = { r: 0, g: 0, b: 0 }; | ||
let a = 1; | ||
let s = null; | ||
let v = null; | ||
let l = null; | ||
let ok = false; | ||
let format = false; | ||
if (typeof color === 'string') { | ||
@@ -64,3 +63,3 @@ color = stringInputToObject(color); | ||
return { | ||
ok: ok, | ||
ok, | ||
format: color.format || format, | ||
@@ -70,3 +69,3 @@ r: Math.min(255, Math.max(rgb.r, 0)), | ||
b: Math.min(255, Math.max(rgb.b, 0)), | ||
a: a, | ||
a, | ||
}; | ||
@@ -76,13 +75,13 @@ } | ||
// <http://www.w3.org/TR/css3-values/#integers> | ||
var CSS_INTEGER = '[-\\+]?\\d+%?'; | ||
const CSS_INTEGER = '[-\\+]?\\d+%?'; | ||
// <http://www.w3.org/TR/css3-values/#number-value> | ||
var CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?'; | ||
const CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?'; | ||
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome. | ||
var CSS_UNIT = "(?:".concat(CSS_NUMBER, ")|(?:").concat(CSS_INTEGER, ")"); | ||
const CSS_UNIT = `(?:${CSS_NUMBER})|(?:${CSS_INTEGER})`; | ||
// Actual matching. | ||
// Parentheses and commas are optional, but not required. | ||
// Whitespace can take the place of commas or opening paren | ||
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(".concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")\\s*\\)?"); | ||
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(".concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")\\s*\\)?"); | ||
var matchers = { | ||
const PERMISSIVE_MATCH3 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`; | ||
const PERMISSIVE_MATCH4 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`; | ||
const matchers = { | ||
CSS_UNIT: new RegExp(CSS_UNIT), | ||
@@ -109,3 +108,3 @@ rgb: new RegExp('rgb' + PERMISSIVE_MATCH3), | ||
} | ||
var named = false; | ||
let named = false; | ||
if (css_color_names_js_1.names[color]) { | ||
@@ -122,3 +121,3 @@ color = css_color_names_js_1.names[color]; | ||
// This way the result will be the same whether the tinycolor is initialized with string or object. | ||
var match = matchers.rgb.exec(color); | ||
let match = matchers.rgb.exec(color); | ||
if (match) { | ||
@@ -125,0 +124,0 @@ return { r: match[1], g: match[2], b: match[3] }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.legacyRandom = exports.fromRatio = void 0; | ||
var index_js_1 = require("./index.js"); | ||
var util_js_1 = require("./util.js"); | ||
const index_js_1 = require("./index.js"); | ||
const util_js_1 = require("./util.js"); | ||
/** | ||
@@ -11,3 +11,3 @@ * If input is an object, force 1 into "1.0" to handle ratios properly | ||
function fromRatio(ratio, opts) { | ||
var newColor = { | ||
const newColor = { | ||
r: (0, util_js_1.convertToPercentage)(ratio.r), | ||
@@ -14,0 +14,0 @@ g: (0, util_js_1.convertToPercentage)(ratio.g), |
@@ -207,2 +207,1 @@ import { HSL, HSLA, HSV, HSVA, Numberify, RGB, RGBA } from './interfaces.js'; | ||
} | ||
export declare function tinycolor(color?: ColorInput, opts?: Partial<TinyColorOptions>): TinyColor; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tinycolor = exports.TinyColor = void 0; | ||
var conversion_js_1 = require("./conversion.js"); | ||
var css_color_names_js_1 = require("./css-color-names.js"); | ||
var format_input_1 = require("./format-input"); | ||
var util_js_1 = require("./util.js"); | ||
var TinyColor = /** @class */ (function () { | ||
function TinyColor(color, opts) { | ||
if (color === void 0) { color = ''; } | ||
if (opts === void 0) { opts = {}; } | ||
var _a; | ||
exports.TinyColor = void 0; | ||
const conversion_js_1 = require("./conversion.js"); | ||
const css_color_names_js_1 = require("./css-color-names.js"); | ||
const format_input_1 = require("./format-input"); | ||
const util_js_1 = require("./util.js"); | ||
class TinyColor { | ||
constructor(color = '', opts = {}) { | ||
// If input is already a tinycolor, return itself | ||
@@ -22,3 +19,3 @@ if (color instanceof TinyColor) { | ||
this.originalInput = color; | ||
var rgb = (0, format_input_1.inputToRGB)(color); | ||
const rgb = (0, format_input_1.inputToRGB)(color); | ||
this.originalInput = color; | ||
@@ -30,3 +27,3 @@ this.r = rgb.r; | ||
this.roundA = Math.round(100 * this.a) / 100; | ||
this.format = (_a = opts.format) !== null && _a !== void 0 ? _a : rgb.format; | ||
this.format = opts.format ?? rgb.format; | ||
this.gradientType = opts.gradientType; | ||
@@ -48,28 +45,28 @@ // Don't let the range of [0,255] come back in [0,1]. | ||
} | ||
TinyColor.prototype.isDark = function () { | ||
isDark() { | ||
return this.getBrightness() < 128; | ||
}; | ||
TinyColor.prototype.isLight = function () { | ||
} | ||
isLight() { | ||
return !this.isDark(); | ||
}; | ||
} | ||
/** | ||
* Returns the perceived brightness of the color, from 0-255. | ||
*/ | ||
TinyColor.prototype.getBrightness = function () { | ||
getBrightness() { | ||
// http://www.w3.org/TR/AERT#color-contrast | ||
var rgb = this.toRgb(); | ||
const rgb = this.toRgb(); | ||
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000; | ||
}; | ||
} | ||
/** | ||
* Returns the perceived luminance of a color, from 0-1. | ||
*/ | ||
TinyColor.prototype.getLuminance = function () { | ||
getLuminance() { | ||
// http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef | ||
var rgb = this.toRgb(); | ||
var R; | ||
var G; | ||
var B; | ||
var RsRGB = rgb.r / 255; | ||
var GsRGB = rgb.g / 255; | ||
var BsRGB = rgb.b / 255; | ||
const rgb = this.toRgb(); | ||
let R; | ||
let G; | ||
let B; | ||
const RsRGB = rgb.r / 255; | ||
const GsRGB = rgb.g / 255; | ||
const BsRGB = rgb.b / 255; | ||
if (RsRGB <= 0.03928) { | ||
@@ -97,9 +94,9 @@ R = RsRGB / 12.92; | ||
return 0.2126 * R + 0.7152 * G + 0.0722 * B; | ||
}; | ||
} | ||
/** | ||
* Returns the alpha value of a color, from 0-1. | ||
*/ | ||
TinyColor.prototype.getAlpha = function () { | ||
getAlpha() { | ||
return this.a; | ||
}; | ||
} | ||
/** | ||
@@ -110,21 +107,21 @@ * Sets the alpha value on the current color. | ||
*/ | ||
TinyColor.prototype.setAlpha = function (alpha) { | ||
setAlpha(alpha) { | ||
this.a = (0, util_js_1.boundAlpha)(alpha); | ||
this.roundA = Math.round(100 * this.a) / 100; | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Returns whether the color is monochrome. | ||
*/ | ||
TinyColor.prototype.isMonochrome = function () { | ||
var s = this.toHsl().s; | ||
isMonochrome() { | ||
const { s } = this.toHsl(); | ||
return s === 0; | ||
}; | ||
} | ||
/** | ||
* Returns the object as a HSVA object. | ||
*/ | ||
TinyColor.prototype.toHsv = function () { | ||
var hsv = (0, conversion_js_1.rgbToHsv)(this.r, this.g, this.b); | ||
toHsv() { | ||
const hsv = (0, conversion_js_1.rgbToHsv)(this.r, this.g, this.b); | ||
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this.a }; | ||
}; | ||
} | ||
/** | ||
@@ -134,16 +131,16 @@ * Returns the hsva values interpolated into a string with the following format: | ||
*/ | ||
TinyColor.prototype.toHsvString = function () { | ||
var hsv = (0, conversion_js_1.rgbToHsv)(this.r, this.g, this.b); | ||
var h = Math.round(hsv.h * 360); | ||
var s = Math.round(hsv.s * 100); | ||
var v = Math.round(hsv.v * 100); | ||
return this.a === 1 ? "hsv(".concat(h, ", ").concat(s, "%, ").concat(v, "%)") : "hsva(".concat(h, ", ").concat(s, "%, ").concat(v, "%, ").concat(this.roundA, ")"); | ||
}; | ||
toHsvString() { | ||
const hsv = (0, conversion_js_1.rgbToHsv)(this.r, this.g, this.b); | ||
const h = Math.round(hsv.h * 360); | ||
const s = Math.round(hsv.s * 100); | ||
const v = Math.round(hsv.v * 100); | ||
return this.a === 1 ? `hsv(${h}, ${s}%, ${v}%)` : `hsva(${h}, ${s}%, ${v}%, ${this.roundA})`; | ||
} | ||
/** | ||
* Returns the object as a HSLA object. | ||
*/ | ||
TinyColor.prototype.toHsl = function () { | ||
var hsl = (0, conversion_js_1.rgbToHsl)(this.r, this.g, this.b); | ||
toHsl() { | ||
const hsl = (0, conversion_js_1.rgbToHsl)(this.r, this.g, this.b); | ||
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this.a }; | ||
}; | ||
} | ||
/** | ||
@@ -153,9 +150,9 @@ * Returns the hsla values interpolated into a string with the following format: | ||
*/ | ||
TinyColor.prototype.toHslString = function () { | ||
var hsl = (0, conversion_js_1.rgbToHsl)(this.r, this.g, this.b); | ||
var h = Math.round(hsl.h * 360); | ||
var s = Math.round(hsl.s * 100); | ||
var l = Math.round(hsl.l * 100); | ||
return this.a === 1 ? "hsl(".concat(h, ", ").concat(s, "%, ").concat(l, "%)") : "hsla(".concat(h, ", ").concat(s, "%, ").concat(l, "%, ").concat(this.roundA, ")"); | ||
}; | ||
toHslString() { | ||
const hsl = (0, conversion_js_1.rgbToHsl)(this.r, this.g, this.b); | ||
const h = Math.round(hsl.h * 360); | ||
const s = Math.round(hsl.s * 100); | ||
const l = Math.round(hsl.l * 100); | ||
return this.a === 1 ? `hsl(${h}, ${s}%, ${l}%)` : `hsla(${h}, ${s}%, ${l}%, ${this.roundA})`; | ||
} | ||
/** | ||
@@ -165,6 +162,5 @@ * Returns the hex value of the color. | ||
*/ | ||
TinyColor.prototype.toHex = function (allow3Char) { | ||
if (allow3Char === void 0) { allow3Char = false; } | ||
toHex(allow3Char = false) { | ||
return (0, conversion_js_1.rgbToHex)(this.r, this.g, this.b, allow3Char); | ||
}; | ||
} | ||
/** | ||
@@ -174,6 +170,5 @@ * Returns the hex value of the color -with a # prefixed. | ||
*/ | ||
TinyColor.prototype.toHexString = function (allow3Char) { | ||
if (allow3Char === void 0) { allow3Char = false; } | ||
toHexString(allow3Char = false) { | ||
return '#' + this.toHex(allow3Char); | ||
}; | ||
} | ||
/** | ||
@@ -183,6 +178,5 @@ * Returns the hex 8 value of the color. | ||
*/ | ||
TinyColor.prototype.toHex8 = function (allow4Char) { | ||
if (allow4Char === void 0) { allow4Char = false; } | ||
toHex8(allow4Char = false) { | ||
return (0, conversion_js_1.rgbaToHex)(this.r, this.g, this.b, this.a, allow4Char); | ||
}; | ||
} | ||
/** | ||
@@ -192,6 +186,5 @@ * Returns the hex 8 value of the color -with a # prefixed. | ||
*/ | ||
TinyColor.prototype.toHex8String = function (allow4Char) { | ||
if (allow4Char === void 0) { allow4Char = false; } | ||
toHex8String(allow4Char = false) { | ||
return '#' + this.toHex8(allow4Char); | ||
}; | ||
} | ||
/** | ||
@@ -201,10 +194,9 @@ * Returns the shorter hex value of the color depends on its alpha -with a # prefixed. | ||
*/ | ||
TinyColor.prototype.toHexShortString = function (allowShortChar) { | ||
if (allowShortChar === void 0) { allowShortChar = false; } | ||
toHexShortString(allowShortChar = false) { | ||
return this.a === 1 ? this.toHexString(allowShortChar) : this.toHex8String(allowShortChar); | ||
}; | ||
} | ||
/** | ||
* Returns the object as a RGBA object. | ||
*/ | ||
TinyColor.prototype.toRgb = function () { | ||
toRgb() { | ||
return { | ||
@@ -216,3 +208,3 @@ r: Math.round(this.r), | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -222,13 +214,13 @@ * Returns the RGBA values interpolated into a string with the following format: | ||
*/ | ||
TinyColor.prototype.toRgbString = function () { | ||
var r = Math.round(this.r); | ||
var g = Math.round(this.g); | ||
var b = Math.round(this.b); | ||
return this.a === 1 ? "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")") : "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(this.roundA, ")"); | ||
}; | ||
toRgbString() { | ||
const r = Math.round(this.r); | ||
const g = Math.round(this.g); | ||
const b = Math.round(this.b); | ||
return this.a === 1 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${this.roundA})`; | ||
} | ||
/** | ||
* Returns the object as a RGBA object. | ||
*/ | ||
TinyColor.prototype.toPercentageRgb = function () { | ||
var fmt = function (x) { return "".concat(Math.round((0, util_js_1.bound01)(x, 255) * 100), "%"); }; | ||
toPercentageRgb() { | ||
const fmt = (x) => `${Math.round((0, util_js_1.bound01)(x, 255) * 100)}%`; | ||
return { | ||
@@ -240,16 +232,16 @@ r: fmt(this.r), | ||
}; | ||
}; | ||
} | ||
/** | ||
* Returns the RGBA relative values interpolated into a string | ||
*/ | ||
TinyColor.prototype.toPercentageRgbString = function () { | ||
var rnd = function (x) { return Math.round((0, util_js_1.bound01)(x, 255) * 100); }; | ||
toPercentageRgbString() { | ||
const rnd = (x) => Math.round((0, util_js_1.bound01)(x, 255) * 100); | ||
return this.a === 1 | ||
? "rgb(".concat(rnd(this.r), "%, ").concat(rnd(this.g), "%, ").concat(rnd(this.b), "%)") | ||
: "rgba(".concat(rnd(this.r), "%, ").concat(rnd(this.g), "%, ").concat(rnd(this.b), "%, ").concat(this.roundA, ")"); | ||
}; | ||
? `rgb(${rnd(this.r)}%, ${rnd(this.g)}%, ${rnd(this.b)}%)` | ||
: `rgba(${rnd(this.r)}%, ${rnd(this.g)}%, ${rnd(this.b)}%, ${this.roundA})`; | ||
} | ||
/** | ||
* The 'real' name of the color -if there is one. | ||
*/ | ||
TinyColor.prototype.toName = function () { | ||
toName() { | ||
if (this.a === 0) { | ||
@@ -261,5 +253,4 @@ return 'transparent'; | ||
} | ||
var hex = '#' + (0, conversion_js_1.rgbToHex)(this.r, this.g, this.b, false); | ||
for (var _i = 0, _a = Object.entries(css_color_names_js_1.names); _i < _a.length; _i++) { | ||
var _b = _a[_i], key = _b[0], value = _b[1]; | ||
const hex = '#' + (0, conversion_js_1.rgbToHex)(this.r, this.g, this.b, false); | ||
for (const [key, value] of Object.entries(css_color_names_js_1.names)) { | ||
if (hex === value) { | ||
@@ -270,9 +261,9 @@ return key; | ||
return false; | ||
}; | ||
TinyColor.prototype.toString = function (format) { | ||
var formatSet = Boolean(format); | ||
format = format !== null && format !== void 0 ? format : this.format; | ||
var formattedString = false; | ||
var hasAlpha = this.a < 1 && this.a >= 0; | ||
var needsAlphaFormat = !formatSet && hasAlpha && (format.startsWith('hex') || format === 'name'); | ||
} | ||
toString(format) { | ||
const formatSet = Boolean(format); | ||
format = format ?? this.format; | ||
let formattedString = false; | ||
const hasAlpha = this.a < 1 && this.a >= 0; | ||
const needsAlphaFormat = !formatSet && hasAlpha && (format.startsWith('hex') || format === 'name'); | ||
if (needsAlphaFormat) { | ||
@@ -314,9 +305,9 @@ // Special case for "transparent", all other non-alpha formats | ||
return formattedString || this.toHexString(); | ||
}; | ||
TinyColor.prototype.toNumber = function () { | ||
} | ||
toNumber() { | ||
return (Math.round(this.r) << 16) + (Math.round(this.g) << 8) + Math.round(this.b); | ||
}; | ||
TinyColor.prototype.clone = function () { | ||
} | ||
clone() { | ||
return new TinyColor(this.toString()); | ||
}; | ||
} | ||
/** | ||
@@ -326,9 +317,8 @@ * Lighten the color a given amount. Providing 100 will always return white. | ||
*/ | ||
TinyColor.prototype.lighten = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
lighten(amount = 10) { | ||
const hsl = this.toHsl(); | ||
hsl.l += amount / 100; | ||
hsl.l = (0, util_js_1.clamp01)(hsl.l); | ||
return new TinyColor(hsl); | ||
}; | ||
} | ||
/** | ||
@@ -338,5 +328,4 @@ * Brighten the color a given amount, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.brighten = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var rgb = this.toRgb(); | ||
brighten(amount = 10) { | ||
const rgb = this.toRgb(); | ||
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100)))); | ||
@@ -346,3 +335,3 @@ rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100)))); | ||
return new TinyColor(rgb); | ||
}; | ||
} | ||
/** | ||
@@ -353,9 +342,8 @@ * Darken the color a given amount, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.darken = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
darken(amount = 10) { | ||
const hsl = this.toHsl(); | ||
hsl.l -= amount / 100; | ||
hsl.l = (0, util_js_1.clamp01)(hsl.l); | ||
return new TinyColor(hsl); | ||
}; | ||
} | ||
/** | ||
@@ -366,6 +354,5 @@ * Mix the color with pure white, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.tint = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
tint(amount = 10) { | ||
return this.mix('white', amount); | ||
}; | ||
} | ||
/** | ||
@@ -376,6 +363,5 @@ * Mix the color with pure black, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.shade = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
shade(amount = 10) { | ||
return this.mix('black', amount); | ||
}; | ||
} | ||
/** | ||
@@ -386,9 +372,8 @@ * Desaturate the color a given amount, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.desaturate = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
desaturate(amount = 10) { | ||
const hsl = this.toHsl(); | ||
hsl.s -= amount / 100; | ||
hsl.s = (0, util_js_1.clamp01)(hsl.s); | ||
return new TinyColor(hsl); | ||
}; | ||
} | ||
/** | ||
@@ -398,9 +383,8 @@ * Saturate the color a given amount, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.saturate = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
saturate(amount = 10) { | ||
const hsl = this.toHsl(); | ||
hsl.s += amount / 100; | ||
hsl.s = (0, util_js_1.clamp01)(hsl.s); | ||
return new TinyColor(hsl); | ||
}; | ||
} | ||
/** | ||
@@ -410,5 +394,5 @@ * Completely desaturates a color into greyscale. | ||
*/ | ||
TinyColor.prototype.greyscale = function () { | ||
greyscale() { | ||
return this.desaturate(100); | ||
}; | ||
} | ||
/** | ||
@@ -418,8 +402,8 @@ * Spin takes a positive or negative amount within [-360, 360] indicating the change of hue. | ||
*/ | ||
TinyColor.prototype.spin = function (amount) { | ||
var hsl = this.toHsl(); | ||
var hue = (hsl.h + amount) % 360; | ||
spin(amount) { | ||
const hsl = this.toHsl(); | ||
const hue = (hsl.h + amount) % 360; | ||
hsl.h = hue < 0 ? 360 + hue : hue; | ||
return new TinyColor(hsl); | ||
}; | ||
} | ||
/** | ||
@@ -429,8 +413,7 @@ * Mix the current color a given amount with another color, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.mix = function (color, amount) { | ||
if (amount === void 0) { amount = 50; } | ||
var rgb1 = this.toRgb(); | ||
var rgb2 = new TinyColor(color).toRgb(); | ||
var p = amount / 100; | ||
var rgba = { | ||
mix(color, amount = 50) { | ||
const rgb1 = this.toRgb(); | ||
const rgb2 = new TinyColor(color).toRgb(); | ||
const p = amount / 100; | ||
const rgba = { | ||
r: (rgb2.r - rgb1.r) * p + rgb1.r, | ||
@@ -442,9 +425,7 @@ g: (rgb2.g - rgb1.g) * p + rgb1.g, | ||
return new TinyColor(rgba); | ||
}; | ||
TinyColor.prototype.analogous = function (results, slices) { | ||
if (results === void 0) { results = 6; } | ||
if (slices === void 0) { slices = 30; } | ||
var hsl = this.toHsl(); | ||
var part = 360 / slices; | ||
var ret = [this]; | ||
} | ||
analogous(results = 6, slices = 30) { | ||
const hsl = this.toHsl(); | ||
const part = 360 / slices; | ||
const ret = [this]; | ||
for (hsl.h = (hsl.h - ((part * results) >> 1) + 720) % 360; --results;) { | ||
@@ -455,28 +436,27 @@ hsl.h = (hsl.h + part) % 360; | ||
return ret; | ||
}; | ||
} | ||
/** | ||
* taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js | ||
*/ | ||
TinyColor.prototype.complement = function () { | ||
var hsl = this.toHsl(); | ||
complement() { | ||
const hsl = this.toHsl(); | ||
hsl.h = (hsl.h + 180) % 360; | ||
return new TinyColor(hsl); | ||
}; | ||
TinyColor.prototype.monochromatic = function (results) { | ||
if (results === void 0) { results = 6; } | ||
var hsv = this.toHsv(); | ||
var h = hsv.h; | ||
var s = hsv.s; | ||
var v = hsv.v; | ||
var res = []; | ||
var modification = 1 / results; | ||
} | ||
monochromatic(results = 6) { | ||
const hsv = this.toHsv(); | ||
const { h } = hsv; | ||
const { s } = hsv; | ||
let { v } = hsv; | ||
const res = []; | ||
const modification = 1 / results; | ||
while (results--) { | ||
res.push(new TinyColor({ h: h, s: s, v: v })); | ||
res.push(new TinyColor({ h, s, v })); | ||
v = (v + modification) % 1; | ||
} | ||
return res; | ||
}; | ||
TinyColor.prototype.splitcomplement = function () { | ||
var hsl = this.toHsl(); | ||
var h = hsl.h; | ||
} | ||
splitcomplement() { | ||
const hsl = this.toHsl(); | ||
const { h } = hsl; | ||
return [ | ||
@@ -487,10 +467,10 @@ this, | ||
]; | ||
}; | ||
} | ||
/** | ||
* Compute how the color would appear on a background | ||
*/ | ||
TinyColor.prototype.onBackground = function (background) { | ||
var fg = this.toRgb(); | ||
var bg = new TinyColor(background).toRgb(); | ||
var alpha = fg.a + bg.a * (1 - fg.a); | ||
onBackground(background) { | ||
const fg = this.toRgb(); | ||
const bg = new TinyColor(background).toRgb(); | ||
const alpha = fg.a + bg.a * (1 - fg.a); | ||
return new TinyColor({ | ||
@@ -502,15 +482,15 @@ r: (fg.r * fg.a + bg.r * bg.a * (1 - fg.a)) / alpha, | ||
}); | ||
}; | ||
} | ||
/** | ||
* Alias for `polyad(3)` | ||
*/ | ||
TinyColor.prototype.triad = function () { | ||
triad() { | ||
return this.polyad(3); | ||
}; | ||
} | ||
/** | ||
* Alias for `polyad(4)` | ||
*/ | ||
TinyColor.prototype.tetrad = function () { | ||
tetrad() { | ||
return this.polyad(4); | ||
}; | ||
} | ||
/** | ||
@@ -520,27 +500,19 @@ * Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...) | ||
*/ | ||
TinyColor.prototype.polyad = function (n) { | ||
var hsl = this.toHsl(); | ||
var h = hsl.h; | ||
var result = [this]; | ||
var increment = 360 / n; | ||
for (var i = 1; i < n; i++) { | ||
polyad(n) { | ||
const hsl = this.toHsl(); | ||
const { h } = hsl; | ||
const result = [this]; | ||
const increment = 360 / n; | ||
for (let i = 1; i < n; i++) { | ||
result.push(new TinyColor({ h: (h + i * increment) % 360, s: hsl.s, l: hsl.l })); | ||
} | ||
return result; | ||
}; | ||
} | ||
/** | ||
* compare color vs current color | ||
*/ | ||
TinyColor.prototype.equals = function (color) { | ||
equals(color) { | ||
return this.toRgbString() === new TinyColor(color).toRgbString(); | ||
}; | ||
return TinyColor; | ||
}()); | ||
} | ||
} | ||
exports.TinyColor = TinyColor; | ||
// kept for backwards compatability with v1 | ||
function tinycolor(color, opts) { | ||
if (color === void 0) { color = ''; } | ||
if (opts === void 0) { opts = {}; } | ||
return new TinyColor(color, opts); | ||
} | ||
exports.tinycolor = tinycolor; |
@@ -26,7 +26,7 @@ import { bound01, pad2 } from './util.js'; | ||
b = bound01(b, 255); | ||
var max = Math.max(r, g, b); | ||
var min = Math.min(r, g, b); | ||
var h = 0; | ||
var s = 0; | ||
var l = (max + min) / 2; | ||
const max = Math.max(r, g, b); | ||
const min = Math.min(r, g, b); | ||
let h = 0; | ||
let s = 0; | ||
const l = (max + min) / 2; | ||
if (max === min) { | ||
@@ -37,3 +37,3 @@ s = 0; | ||
else { | ||
var d = max - min; | ||
const d = max - min; | ||
s = l > 0.5 ? d / (2 - max - min) : d / (max + min); | ||
@@ -55,3 +55,3 @@ switch (max) { | ||
} | ||
return { h: h, s: s, l: l }; | ||
return { h, s, l }; | ||
} | ||
@@ -83,5 +83,5 @@ function hue2rgb(p, q, t) { | ||
export function hslToRgb(h, s, l) { | ||
var r; | ||
var g; | ||
var b; | ||
let r; | ||
let g; | ||
let b; | ||
h = bound01(h, 360); | ||
@@ -97,4 +97,4 @@ s = bound01(s, 100); | ||
else { | ||
var q = l < 0.5 ? l * (1 + s) : l + s - l * s; | ||
var p = 2 * l - q; | ||
const q = l < 0.5 ? l * (1 + s) : l + s - l * s; | ||
const p = 2 * l - q; | ||
r = hue2rgb(p, q, h + 1 / 3); | ||
@@ -116,8 +116,8 @@ g = hue2rgb(p, q, h); | ||
b = bound01(b, 255); | ||
var max = Math.max(r, g, b); | ||
var min = Math.min(r, g, b); | ||
var h = 0; | ||
var v = max; | ||
var d = max - min; | ||
var s = max === 0 ? 0 : d / max; | ||
const max = Math.max(r, g, b); | ||
const min = Math.min(r, g, b); | ||
let h = 0; | ||
const v = max; | ||
const d = max - min; | ||
const s = max === 0 ? 0 : d / max; | ||
if (max === min) { | ||
@@ -142,3 +142,3 @@ h = 0; // achromatic | ||
} | ||
return { h: h, s: s, v: v }; | ||
return { h, s, v }; | ||
} | ||
@@ -155,11 +155,11 @@ /** | ||
v = bound01(v, 100); | ||
var i = Math.floor(h); | ||
var f = h - i; | ||
var p = v * (1 - s); | ||
var q = v * (1 - f * s); | ||
var t = v * (1 - (1 - f) * s); | ||
var mod = i % 6; | ||
var r = [v, q, p, p, t, v][mod]; | ||
var g = [t, v, v, q, p, p][mod]; | ||
var b = [p, p, t, v, v, q][mod]; | ||
const i = Math.floor(h); | ||
const f = h - i; | ||
const p = v * (1 - s); | ||
const q = v * (1 - f * s); | ||
const t = v * (1 - (1 - f) * s); | ||
const mod = i % 6; | ||
const r = [v, q, p, p, t, v][mod]; | ||
const g = [t, v, v, q, p, p][mod]; | ||
const b = [p, p, t, v, v, q][mod]; | ||
return { r: r * 255, g: g * 255, b: b * 255 }; | ||
@@ -174,3 +174,3 @@ } | ||
export function rgbToHex(r, g, b, allow3Char) { | ||
var hex = [ | ||
const hex = [ | ||
pad2(Math.round(r).toString(16)), | ||
@@ -197,3 +197,3 @@ pad2(Math.round(g).toString(16)), | ||
export function rgbaToHex(r, g, b, a, allow4Char) { | ||
var hex = [ | ||
const hex = [ | ||
pad2(Math.round(r).toString(16)), | ||
@@ -219,3 +219,3 @@ pad2(Math.round(g).toString(16)), | ||
export function rgbaToArgbHex(r, g, b, a) { | ||
var hex = [ | ||
const hex = [ | ||
pad2(convertDecimalToHex(a)), | ||
@@ -222,0 +222,0 @@ pad2(Math.round(r).toString(16)), |
@@ -5,3 +5,3 @@ // https://github.com/bahamas10/css-color-names/blob/master/css-color-names.json | ||
*/ | ||
export var names = { | ||
export const names = { | ||
aliceblue: '#f0f8ff', | ||
@@ -8,0 +8,0 @@ antiquewhite: '#faebd7', |
@@ -1,2 +0,1 @@ | ||
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */ | ||
import { convertHexToDecimal, hslToRgb, hsvToRgb, parseIntFromHex, rgbToRgb, } from './conversion.js'; | ||
@@ -24,9 +23,9 @@ import { names } from './css-color-names.js'; | ||
export function inputToRGB(color) { | ||
var rgb = { r: 0, g: 0, b: 0 }; | ||
var a = 1; | ||
var s = null; | ||
var v = null; | ||
var l = null; | ||
var ok = false; | ||
var format = false; | ||
let rgb = { r: 0, g: 0, b: 0 }; | ||
let a = 1; | ||
let s = null; | ||
let v = null; | ||
let l = null; | ||
let ok = false; | ||
let format = false; | ||
if (typeof color === 'string') { | ||
@@ -61,3 +60,3 @@ color = stringInputToObject(color); | ||
return { | ||
ok: ok, | ||
ok, | ||
format: color.format || format, | ||
@@ -67,17 +66,17 @@ r: Math.min(255, Math.max(rgb.r, 0)), | ||
b: Math.min(255, Math.max(rgb.b, 0)), | ||
a: a, | ||
a, | ||
}; | ||
} | ||
// <http://www.w3.org/TR/css3-values/#integers> | ||
var CSS_INTEGER = '[-\\+]?\\d+%?'; | ||
const CSS_INTEGER = '[-\\+]?\\d+%?'; | ||
// <http://www.w3.org/TR/css3-values/#number-value> | ||
var CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?'; | ||
const CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?'; | ||
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome. | ||
var CSS_UNIT = "(?:".concat(CSS_NUMBER, ")|(?:").concat(CSS_INTEGER, ")"); | ||
const CSS_UNIT = `(?:${CSS_NUMBER})|(?:${CSS_INTEGER})`; | ||
// Actual matching. | ||
// Parentheses and commas are optional, but not required. | ||
// Whitespace can take the place of commas or opening paren | ||
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(".concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")\\s*\\)?"); | ||
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(".concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")[,|\\s]+(").concat(CSS_UNIT, ")\\s*\\)?"); | ||
var matchers = { | ||
const PERMISSIVE_MATCH3 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`; | ||
const PERMISSIVE_MATCH4 = `[\\s|\\(]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})[,|\\s]+(${CSS_UNIT})\\s*\\)?`; | ||
const matchers = { | ||
CSS_UNIT: new RegExp(CSS_UNIT), | ||
@@ -104,3 +103,3 @@ rgb: new RegExp('rgb' + PERMISSIVE_MATCH3), | ||
} | ||
var named = false; | ||
let named = false; | ||
if (names[color]) { | ||
@@ -117,3 +116,3 @@ color = names[color]; | ||
// This way the result will be the same whether the tinycolor is initialized with string or object. | ||
var match = matchers.rgb.exec(color); | ||
let match = matchers.rgb.exec(color); | ||
if (match) { | ||
@@ -120,0 +119,0 @@ return { r: match[1], g: match[2], b: match[3] }; |
@@ -8,3 +8,3 @@ import { TinyColor } from './index.js'; | ||
export function fromRatio(ratio, opts) { | ||
var newColor = { | ||
const newColor = { | ||
r: convertToPercentage(ratio.r), | ||
@@ -11,0 +11,0 @@ g: convertToPercentage(ratio.g), |
@@ -5,7 +5,4 @@ import { numberInputToObject, rgbaToHex, rgbToHex, rgbToHsl, rgbToHsv } from './conversion.js'; | ||
import { bound01, boundAlpha, clamp01 } from './util.js'; | ||
var TinyColor = /** @class */ (function () { | ||
function TinyColor(color, opts) { | ||
if (color === void 0) { color = ''; } | ||
if (opts === void 0) { opts = {}; } | ||
var _a; | ||
export class TinyColor { | ||
constructor(color = '', opts = {}) { | ||
// If input is already a tinycolor, return itself | ||
@@ -20,3 +17,3 @@ if (color instanceof TinyColor) { | ||
this.originalInput = color; | ||
var rgb = inputToRGB(color); | ||
const rgb = inputToRGB(color); | ||
this.originalInput = color; | ||
@@ -28,3 +25,3 @@ this.r = rgb.r; | ||
this.roundA = Math.round(100 * this.a) / 100; | ||
this.format = (_a = opts.format) !== null && _a !== void 0 ? _a : rgb.format; | ||
this.format = opts.format ?? rgb.format; | ||
this.gradientType = opts.gradientType; | ||
@@ -46,28 +43,28 @@ // Don't let the range of [0,255] come back in [0,1]. | ||
} | ||
TinyColor.prototype.isDark = function () { | ||
isDark() { | ||
return this.getBrightness() < 128; | ||
}; | ||
TinyColor.prototype.isLight = function () { | ||
} | ||
isLight() { | ||
return !this.isDark(); | ||
}; | ||
} | ||
/** | ||
* Returns the perceived brightness of the color, from 0-255. | ||
*/ | ||
TinyColor.prototype.getBrightness = function () { | ||
getBrightness() { | ||
// http://www.w3.org/TR/AERT#color-contrast | ||
var rgb = this.toRgb(); | ||
const rgb = this.toRgb(); | ||
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000; | ||
}; | ||
} | ||
/** | ||
* Returns the perceived luminance of a color, from 0-1. | ||
*/ | ||
TinyColor.prototype.getLuminance = function () { | ||
getLuminance() { | ||
// http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef | ||
var rgb = this.toRgb(); | ||
var R; | ||
var G; | ||
var B; | ||
var RsRGB = rgb.r / 255; | ||
var GsRGB = rgb.g / 255; | ||
var BsRGB = rgb.b / 255; | ||
const rgb = this.toRgb(); | ||
let R; | ||
let G; | ||
let B; | ||
const RsRGB = rgb.r / 255; | ||
const GsRGB = rgb.g / 255; | ||
const BsRGB = rgb.b / 255; | ||
if (RsRGB <= 0.03928) { | ||
@@ -95,9 +92,9 @@ R = RsRGB / 12.92; | ||
return 0.2126 * R + 0.7152 * G + 0.0722 * B; | ||
}; | ||
} | ||
/** | ||
* Returns the alpha value of a color, from 0-1. | ||
*/ | ||
TinyColor.prototype.getAlpha = function () { | ||
getAlpha() { | ||
return this.a; | ||
}; | ||
} | ||
/** | ||
@@ -108,21 +105,21 @@ * Sets the alpha value on the current color. | ||
*/ | ||
TinyColor.prototype.setAlpha = function (alpha) { | ||
setAlpha(alpha) { | ||
this.a = boundAlpha(alpha); | ||
this.roundA = Math.round(100 * this.a) / 100; | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Returns whether the color is monochrome. | ||
*/ | ||
TinyColor.prototype.isMonochrome = function () { | ||
var s = this.toHsl().s; | ||
isMonochrome() { | ||
const { s } = this.toHsl(); | ||
return s === 0; | ||
}; | ||
} | ||
/** | ||
* Returns the object as a HSVA object. | ||
*/ | ||
TinyColor.prototype.toHsv = function () { | ||
var hsv = rgbToHsv(this.r, this.g, this.b); | ||
toHsv() { | ||
const hsv = rgbToHsv(this.r, this.g, this.b); | ||
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this.a }; | ||
}; | ||
} | ||
/** | ||
@@ -132,16 +129,16 @@ * Returns the hsva values interpolated into a string with the following format: | ||
*/ | ||
TinyColor.prototype.toHsvString = function () { | ||
var hsv = rgbToHsv(this.r, this.g, this.b); | ||
var h = Math.round(hsv.h * 360); | ||
var s = Math.round(hsv.s * 100); | ||
var v = Math.round(hsv.v * 100); | ||
return this.a === 1 ? "hsv(".concat(h, ", ").concat(s, "%, ").concat(v, "%)") : "hsva(".concat(h, ", ").concat(s, "%, ").concat(v, "%, ").concat(this.roundA, ")"); | ||
}; | ||
toHsvString() { | ||
const hsv = rgbToHsv(this.r, this.g, this.b); | ||
const h = Math.round(hsv.h * 360); | ||
const s = Math.round(hsv.s * 100); | ||
const v = Math.round(hsv.v * 100); | ||
return this.a === 1 ? `hsv(${h}, ${s}%, ${v}%)` : `hsva(${h}, ${s}%, ${v}%, ${this.roundA})`; | ||
} | ||
/** | ||
* Returns the object as a HSLA object. | ||
*/ | ||
TinyColor.prototype.toHsl = function () { | ||
var hsl = rgbToHsl(this.r, this.g, this.b); | ||
toHsl() { | ||
const hsl = rgbToHsl(this.r, this.g, this.b); | ||
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this.a }; | ||
}; | ||
} | ||
/** | ||
@@ -151,9 +148,9 @@ * Returns the hsla values interpolated into a string with the following format: | ||
*/ | ||
TinyColor.prototype.toHslString = function () { | ||
var hsl = rgbToHsl(this.r, this.g, this.b); | ||
var h = Math.round(hsl.h * 360); | ||
var s = Math.round(hsl.s * 100); | ||
var l = Math.round(hsl.l * 100); | ||
return this.a === 1 ? "hsl(".concat(h, ", ").concat(s, "%, ").concat(l, "%)") : "hsla(".concat(h, ", ").concat(s, "%, ").concat(l, "%, ").concat(this.roundA, ")"); | ||
}; | ||
toHslString() { | ||
const hsl = rgbToHsl(this.r, this.g, this.b); | ||
const h = Math.round(hsl.h * 360); | ||
const s = Math.round(hsl.s * 100); | ||
const l = Math.round(hsl.l * 100); | ||
return this.a === 1 ? `hsl(${h}, ${s}%, ${l}%)` : `hsla(${h}, ${s}%, ${l}%, ${this.roundA})`; | ||
} | ||
/** | ||
@@ -163,6 +160,5 @@ * Returns the hex value of the color. | ||
*/ | ||
TinyColor.prototype.toHex = function (allow3Char) { | ||
if (allow3Char === void 0) { allow3Char = false; } | ||
toHex(allow3Char = false) { | ||
return rgbToHex(this.r, this.g, this.b, allow3Char); | ||
}; | ||
} | ||
/** | ||
@@ -172,6 +168,5 @@ * Returns the hex value of the color -with a # prefixed. | ||
*/ | ||
TinyColor.prototype.toHexString = function (allow3Char) { | ||
if (allow3Char === void 0) { allow3Char = false; } | ||
toHexString(allow3Char = false) { | ||
return '#' + this.toHex(allow3Char); | ||
}; | ||
} | ||
/** | ||
@@ -181,6 +176,5 @@ * Returns the hex 8 value of the color. | ||
*/ | ||
TinyColor.prototype.toHex8 = function (allow4Char) { | ||
if (allow4Char === void 0) { allow4Char = false; } | ||
toHex8(allow4Char = false) { | ||
return rgbaToHex(this.r, this.g, this.b, this.a, allow4Char); | ||
}; | ||
} | ||
/** | ||
@@ -190,6 +184,5 @@ * Returns the hex 8 value of the color -with a # prefixed. | ||
*/ | ||
TinyColor.prototype.toHex8String = function (allow4Char) { | ||
if (allow4Char === void 0) { allow4Char = false; } | ||
toHex8String(allow4Char = false) { | ||
return '#' + this.toHex8(allow4Char); | ||
}; | ||
} | ||
/** | ||
@@ -199,10 +192,9 @@ * Returns the shorter hex value of the color depends on its alpha -with a # prefixed. | ||
*/ | ||
TinyColor.prototype.toHexShortString = function (allowShortChar) { | ||
if (allowShortChar === void 0) { allowShortChar = false; } | ||
toHexShortString(allowShortChar = false) { | ||
return this.a === 1 ? this.toHexString(allowShortChar) : this.toHex8String(allowShortChar); | ||
}; | ||
} | ||
/** | ||
* Returns the object as a RGBA object. | ||
*/ | ||
TinyColor.prototype.toRgb = function () { | ||
toRgb() { | ||
return { | ||
@@ -214,3 +206,3 @@ r: Math.round(this.r), | ||
}; | ||
}; | ||
} | ||
/** | ||
@@ -220,13 +212,13 @@ * Returns the RGBA values interpolated into a string with the following format: | ||
*/ | ||
TinyColor.prototype.toRgbString = function () { | ||
var r = Math.round(this.r); | ||
var g = Math.round(this.g); | ||
var b = Math.round(this.b); | ||
return this.a === 1 ? "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")") : "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(this.roundA, ")"); | ||
}; | ||
toRgbString() { | ||
const r = Math.round(this.r); | ||
const g = Math.round(this.g); | ||
const b = Math.round(this.b); | ||
return this.a === 1 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${this.roundA})`; | ||
} | ||
/** | ||
* Returns the object as a RGBA object. | ||
*/ | ||
TinyColor.prototype.toPercentageRgb = function () { | ||
var fmt = function (x) { return "".concat(Math.round(bound01(x, 255) * 100), "%"); }; | ||
toPercentageRgb() { | ||
const fmt = (x) => `${Math.round(bound01(x, 255) * 100)}%`; | ||
return { | ||
@@ -238,16 +230,16 @@ r: fmt(this.r), | ||
}; | ||
}; | ||
} | ||
/** | ||
* Returns the RGBA relative values interpolated into a string | ||
*/ | ||
TinyColor.prototype.toPercentageRgbString = function () { | ||
var rnd = function (x) { return Math.round(bound01(x, 255) * 100); }; | ||
toPercentageRgbString() { | ||
const rnd = (x) => Math.round(bound01(x, 255) * 100); | ||
return this.a === 1 | ||
? "rgb(".concat(rnd(this.r), "%, ").concat(rnd(this.g), "%, ").concat(rnd(this.b), "%)") | ||
: "rgba(".concat(rnd(this.r), "%, ").concat(rnd(this.g), "%, ").concat(rnd(this.b), "%, ").concat(this.roundA, ")"); | ||
}; | ||
? `rgb(${rnd(this.r)}%, ${rnd(this.g)}%, ${rnd(this.b)}%)` | ||
: `rgba(${rnd(this.r)}%, ${rnd(this.g)}%, ${rnd(this.b)}%, ${this.roundA})`; | ||
} | ||
/** | ||
* The 'real' name of the color -if there is one. | ||
*/ | ||
TinyColor.prototype.toName = function () { | ||
toName() { | ||
if (this.a === 0) { | ||
@@ -259,5 +251,4 @@ return 'transparent'; | ||
} | ||
var hex = '#' + rgbToHex(this.r, this.g, this.b, false); | ||
for (var _i = 0, _a = Object.entries(names); _i < _a.length; _i++) { | ||
var _b = _a[_i], key = _b[0], value = _b[1]; | ||
const hex = '#' + rgbToHex(this.r, this.g, this.b, false); | ||
for (const [key, value] of Object.entries(names)) { | ||
if (hex === value) { | ||
@@ -268,9 +259,9 @@ return key; | ||
return false; | ||
}; | ||
TinyColor.prototype.toString = function (format) { | ||
var formatSet = Boolean(format); | ||
format = format !== null && format !== void 0 ? format : this.format; | ||
var formattedString = false; | ||
var hasAlpha = this.a < 1 && this.a >= 0; | ||
var needsAlphaFormat = !formatSet && hasAlpha && (format.startsWith('hex') || format === 'name'); | ||
} | ||
toString(format) { | ||
const formatSet = Boolean(format); | ||
format = format ?? this.format; | ||
let formattedString = false; | ||
const hasAlpha = this.a < 1 && this.a >= 0; | ||
const needsAlphaFormat = !formatSet && hasAlpha && (format.startsWith('hex') || format === 'name'); | ||
if (needsAlphaFormat) { | ||
@@ -312,9 +303,9 @@ // Special case for "transparent", all other non-alpha formats | ||
return formattedString || this.toHexString(); | ||
}; | ||
TinyColor.prototype.toNumber = function () { | ||
} | ||
toNumber() { | ||
return (Math.round(this.r) << 16) + (Math.round(this.g) << 8) + Math.round(this.b); | ||
}; | ||
TinyColor.prototype.clone = function () { | ||
} | ||
clone() { | ||
return new TinyColor(this.toString()); | ||
}; | ||
} | ||
/** | ||
@@ -324,9 +315,8 @@ * Lighten the color a given amount. Providing 100 will always return white. | ||
*/ | ||
TinyColor.prototype.lighten = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
lighten(amount = 10) { | ||
const hsl = this.toHsl(); | ||
hsl.l += amount / 100; | ||
hsl.l = clamp01(hsl.l); | ||
return new TinyColor(hsl); | ||
}; | ||
} | ||
/** | ||
@@ -336,5 +326,4 @@ * Brighten the color a given amount, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.brighten = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var rgb = this.toRgb(); | ||
brighten(amount = 10) { | ||
const rgb = this.toRgb(); | ||
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100)))); | ||
@@ -344,3 +333,3 @@ rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100)))); | ||
return new TinyColor(rgb); | ||
}; | ||
} | ||
/** | ||
@@ -351,9 +340,8 @@ * Darken the color a given amount, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.darken = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
darken(amount = 10) { | ||
const hsl = this.toHsl(); | ||
hsl.l -= amount / 100; | ||
hsl.l = clamp01(hsl.l); | ||
return new TinyColor(hsl); | ||
}; | ||
} | ||
/** | ||
@@ -364,6 +352,5 @@ * Mix the color with pure white, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.tint = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
tint(amount = 10) { | ||
return this.mix('white', amount); | ||
}; | ||
} | ||
/** | ||
@@ -374,6 +361,5 @@ * Mix the color with pure black, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.shade = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
shade(amount = 10) { | ||
return this.mix('black', amount); | ||
}; | ||
} | ||
/** | ||
@@ -384,9 +370,8 @@ * Desaturate the color a given amount, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.desaturate = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
desaturate(amount = 10) { | ||
const hsl = this.toHsl(); | ||
hsl.s -= amount / 100; | ||
hsl.s = clamp01(hsl.s); | ||
return new TinyColor(hsl); | ||
}; | ||
} | ||
/** | ||
@@ -396,9 +381,8 @@ * Saturate the color a given amount, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.saturate = function (amount) { | ||
if (amount === void 0) { amount = 10; } | ||
var hsl = this.toHsl(); | ||
saturate(amount = 10) { | ||
const hsl = this.toHsl(); | ||
hsl.s += amount / 100; | ||
hsl.s = clamp01(hsl.s); | ||
return new TinyColor(hsl); | ||
}; | ||
} | ||
/** | ||
@@ -408,5 +392,5 @@ * Completely desaturates a color into greyscale. | ||
*/ | ||
TinyColor.prototype.greyscale = function () { | ||
greyscale() { | ||
return this.desaturate(100); | ||
}; | ||
} | ||
/** | ||
@@ -416,8 +400,8 @@ * Spin takes a positive or negative amount within [-360, 360] indicating the change of hue. | ||
*/ | ||
TinyColor.prototype.spin = function (amount) { | ||
var hsl = this.toHsl(); | ||
var hue = (hsl.h + amount) % 360; | ||
spin(amount) { | ||
const hsl = this.toHsl(); | ||
const hue = (hsl.h + amount) % 360; | ||
hsl.h = hue < 0 ? 360 + hue : hue; | ||
return new TinyColor(hsl); | ||
}; | ||
} | ||
/** | ||
@@ -427,8 +411,7 @@ * Mix the current color a given amount with another color, from 0 to 100. | ||
*/ | ||
TinyColor.prototype.mix = function (color, amount) { | ||
if (amount === void 0) { amount = 50; } | ||
var rgb1 = this.toRgb(); | ||
var rgb2 = new TinyColor(color).toRgb(); | ||
var p = amount / 100; | ||
var rgba = { | ||
mix(color, amount = 50) { | ||
const rgb1 = this.toRgb(); | ||
const rgb2 = new TinyColor(color).toRgb(); | ||
const p = amount / 100; | ||
const rgba = { | ||
r: (rgb2.r - rgb1.r) * p + rgb1.r, | ||
@@ -440,9 +423,7 @@ g: (rgb2.g - rgb1.g) * p + rgb1.g, | ||
return new TinyColor(rgba); | ||
}; | ||
TinyColor.prototype.analogous = function (results, slices) { | ||
if (results === void 0) { results = 6; } | ||
if (slices === void 0) { slices = 30; } | ||
var hsl = this.toHsl(); | ||
var part = 360 / slices; | ||
var ret = [this]; | ||
} | ||
analogous(results = 6, slices = 30) { | ||
const hsl = this.toHsl(); | ||
const part = 360 / slices; | ||
const ret = [this]; | ||
for (hsl.h = (hsl.h - ((part * results) >> 1) + 720) % 360; --results;) { | ||
@@ -453,28 +434,27 @@ hsl.h = (hsl.h + part) % 360; | ||
return ret; | ||
}; | ||
} | ||
/** | ||
* taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js | ||
*/ | ||
TinyColor.prototype.complement = function () { | ||
var hsl = this.toHsl(); | ||
complement() { | ||
const hsl = this.toHsl(); | ||
hsl.h = (hsl.h + 180) % 360; | ||
return new TinyColor(hsl); | ||
}; | ||
TinyColor.prototype.monochromatic = function (results) { | ||
if (results === void 0) { results = 6; } | ||
var hsv = this.toHsv(); | ||
var h = hsv.h; | ||
var s = hsv.s; | ||
var v = hsv.v; | ||
var res = []; | ||
var modification = 1 / results; | ||
} | ||
monochromatic(results = 6) { | ||
const hsv = this.toHsv(); | ||
const { h } = hsv; | ||
const { s } = hsv; | ||
let { v } = hsv; | ||
const res = []; | ||
const modification = 1 / results; | ||
while (results--) { | ||
res.push(new TinyColor({ h: h, s: s, v: v })); | ||
res.push(new TinyColor({ h, s, v })); | ||
v = (v + modification) % 1; | ||
} | ||
return res; | ||
}; | ||
TinyColor.prototype.splitcomplement = function () { | ||
var hsl = this.toHsl(); | ||
var h = hsl.h; | ||
} | ||
splitcomplement() { | ||
const hsl = this.toHsl(); | ||
const { h } = hsl; | ||
return [ | ||
@@ -485,10 +465,10 @@ this, | ||
]; | ||
}; | ||
} | ||
/** | ||
* Compute how the color would appear on a background | ||
*/ | ||
TinyColor.prototype.onBackground = function (background) { | ||
var fg = this.toRgb(); | ||
var bg = new TinyColor(background).toRgb(); | ||
var alpha = fg.a + bg.a * (1 - fg.a); | ||
onBackground(background) { | ||
const fg = this.toRgb(); | ||
const bg = new TinyColor(background).toRgb(); | ||
const alpha = fg.a + bg.a * (1 - fg.a); | ||
return new TinyColor({ | ||
@@ -500,15 +480,15 @@ r: (fg.r * fg.a + bg.r * bg.a * (1 - fg.a)) / alpha, | ||
}); | ||
}; | ||
} | ||
/** | ||
* Alias for `polyad(3)` | ||
*/ | ||
TinyColor.prototype.triad = function () { | ||
triad() { | ||
return this.polyad(3); | ||
}; | ||
} | ||
/** | ||
* Alias for `polyad(4)` | ||
*/ | ||
TinyColor.prototype.tetrad = function () { | ||
tetrad() { | ||
return this.polyad(4); | ||
}; | ||
} | ||
/** | ||
@@ -518,26 +498,18 @@ * Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...) | ||
*/ | ||
TinyColor.prototype.polyad = function (n) { | ||
var hsl = this.toHsl(); | ||
var h = hsl.h; | ||
var result = [this]; | ||
var increment = 360 / n; | ||
for (var i = 1; i < n; i++) { | ||
polyad(n) { | ||
const hsl = this.toHsl(); | ||
const { h } = hsl; | ||
const result = [this]; | ||
const increment = 360 / n; | ||
for (let i = 1; i < n; i++) { | ||
result.push(new TinyColor({ h: (h + i * increment) % 360, s: hsl.s, l: hsl.l })); | ||
} | ||
return result; | ||
}; | ||
} | ||
/** | ||
* compare color vs current color | ||
*/ | ||
TinyColor.prototype.equals = function (color) { | ||
equals(color) { | ||
return this.toRgbString() === new TinyColor(color).toRgbString(); | ||
}; | ||
return TinyColor; | ||
}()); | ||
export { TinyColor }; | ||
// kept for backwards compatability with v1 | ||
export function tinycolor(color, opts) { | ||
if (color === void 0) { color = ''; } | ||
if (opts === void 0) { opts = {}; } | ||
return new TinyColor(color, opts); | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
import { tinycolor } from './index.js'; | ||
export * from './index.js'; | ||
@@ -11,3 +10,1 @@ export * from './css-color-names.js'; | ||
export * from './conversion.js'; | ||
// kept for backwards compatability with v1 | ||
export default tinycolor; |
@@ -1,12 +0,10 @@ | ||
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */ | ||
// randomColor by David Merfield under the CC0 license | ||
// https://github.com/davidmerfield/randomColor/ | ||
import { TinyColor } from './index.js'; | ||
export function random(options) { | ||
if (options === void 0) { options = {}; } | ||
export function random(options = {}) { | ||
// Check if we need to generate multiple colors | ||
if (options.count !== undefined && | ||
options.count !== null) { | ||
var totalColors = options.count; | ||
var colors = []; | ||
const totalColors = options.count; | ||
const colors = []; | ||
options.count = undefined; | ||
@@ -27,8 +25,8 @@ while (totalColors > colors.length) { | ||
// First we pick a hue (H) | ||
var h = pickHue(options.hue, options.seed); | ||
const h = pickHue(options.hue, options.seed); | ||
// Then use H to determine saturation (S) | ||
var s = pickSaturation(h, options); | ||
const s = pickSaturation(h, options); | ||
// Then use S and H to determine brightness (B). | ||
var v = pickBrightness(h, s, options); | ||
var res = { h: h, s: s, v: v }; | ||
const v = pickBrightness(h, s, options); | ||
const res = { h, s, v }; | ||
if (options.alpha !== undefined) { | ||
@@ -41,4 +39,4 @@ res.a = options.alpha; | ||
function pickHue(hue, seed) { | ||
var hueRange = getHueRange(hue); | ||
var res = randomWithin(hueRange, seed); | ||
const hueRange = getHueRange(hue); | ||
let res = randomWithin(hueRange, seed); | ||
// Instead of storing red as two seperate ranges, | ||
@@ -58,5 +56,5 @@ // we group them, using negative numbers | ||
} | ||
var saturationRange = getColorInfo(hue).saturationRange; | ||
var sMin = saturationRange[0]; | ||
var sMax = saturationRange[1]; | ||
const { saturationRange } = getColorInfo(hue); | ||
let sMin = saturationRange[0]; | ||
let sMax = saturationRange[1]; | ||
switch (options.luminosity) { | ||
@@ -78,4 +76,4 @@ case 'bright': | ||
function pickBrightness(H, S, options) { | ||
var bMin = getMinimumBrightness(H, S); | ||
var bMax = 100; | ||
let bMin = getMinimumBrightness(H, S); | ||
let bMax = 100; | ||
switch (options.luminosity) { | ||
@@ -98,11 +96,11 @@ case 'dark': | ||
function getMinimumBrightness(H, S) { | ||
var lowerBounds = getColorInfo(H).lowerBounds; | ||
for (var i = 0; i < lowerBounds.length - 1; i++) { | ||
var s1 = lowerBounds[i][0]; | ||
var v1 = lowerBounds[i][1]; | ||
var s2 = lowerBounds[i + 1][0]; | ||
var v2 = lowerBounds[i + 1][1]; | ||
const { lowerBounds } = getColorInfo(H); | ||
for (let i = 0; i < lowerBounds.length - 1; i++) { | ||
const s1 = lowerBounds[i][0]; | ||
const v1 = lowerBounds[i][1]; | ||
const s2 = lowerBounds[i + 1][0]; | ||
const v2 = lowerBounds[i + 1][1]; | ||
if (S >= s1 && S <= s2) { | ||
var m = (v2 - v1) / (s2 - s1); | ||
var b = v1 - m * s1; | ||
const m = (v2 - v1) / (s2 - s1); | ||
const b = v1 - m * s1; | ||
return m * S + b; | ||
@@ -114,3 +112,3 @@ } | ||
function getHueRange(colorInput) { | ||
var num = parseInt(colorInput, 10); | ||
const num = parseInt(colorInput, 10); | ||
if (!Number.isNaN(num) && num < 360 && num > 0) { | ||
@@ -120,5 +118,5 @@ return [num, num]; | ||
if (typeof colorInput === 'string') { | ||
var namedColor = bounds.find(function (n) { return n.name === colorInput; }); | ||
const namedColor = bounds.find(n => n.name === colorInput); | ||
if (namedColor) { | ||
var color = defineColor(namedColor); | ||
const color = defineColor(namedColor); | ||
if (color.hueRange) { | ||
@@ -128,5 +126,5 @@ return color.hueRange; | ||
} | ||
var parsed = new TinyColor(colorInput); | ||
const parsed = new TinyColor(colorInput); | ||
if (parsed.isValid) { | ||
var hue = parsed.toHsv().h; | ||
const hue = parsed.toHsv().h; | ||
return [hue, hue]; | ||
@@ -142,5 +140,4 @@ } | ||
} | ||
for (var _i = 0, bounds_1 = bounds; _i < bounds_1.length; _i++) { | ||
var bound = bounds_1[_i]; | ||
var color = defineColor(bound); | ||
for (const bound of bounds) { | ||
const color = defineColor(bound); | ||
if (color.hueRange && hue >= color.hueRange[0] && hue <= color.hueRange[1]) { | ||
@@ -157,13 +154,13 @@ return color; | ||
// Seeded random algorithm from http://indiegamr.com/generate-repeatable-random-numbers-in-js/ | ||
var max = range[1] || 1; | ||
var min = range[0] || 0; | ||
const max = range[1] || 1; | ||
const min = range[0] || 0; | ||
seed = (seed * 9301 + 49297) % 233280; | ||
var rnd = seed / 233280.0; | ||
const rnd = seed / 233280.0; | ||
return Math.floor(min + rnd * (max - min)); | ||
} | ||
function defineColor(bound) { | ||
var sMin = bound.lowerBounds[0][0]; | ||
var sMax = bound.lowerBounds[bound.lowerBounds.length - 1][0]; | ||
var bMin = bound.lowerBounds[bound.lowerBounds.length - 1][1]; | ||
var bMax = bound.lowerBounds[0][1]; | ||
const sMin = bound.lowerBounds[0][0]; | ||
const sMax = bound.lowerBounds[bound.lowerBounds.length - 1][0]; | ||
const bMin = bound.lowerBounds[bound.lowerBounds.length - 1][1]; | ||
const bMax = bound.lowerBounds[0][1]; | ||
return { | ||
@@ -180,3 +177,3 @@ name: bound.name, | ||
*/ | ||
export var bounds = [ | ||
export const bounds = [ | ||
{ | ||
@@ -183,0 +180,0 @@ name: 'monochrome', |
@@ -11,4 +11,4 @@ import { TinyColor } from './index.js'; | ||
export function readability(color1, color2) { | ||
var c1 = new TinyColor(color1); | ||
var c2 = new TinyColor(color2); | ||
const c1 = new TinyColor(color1); | ||
const c2 = new TinyColor(color2); | ||
return ((Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / | ||
@@ -30,7 +30,5 @@ (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05)); | ||
*/ | ||
export function isReadable(color1, color2, wcag2) { | ||
var _a, _b; | ||
if (wcag2 === void 0) { wcag2 = { level: 'AA', size: 'small' }; } | ||
var readabilityLevel = readability(color1, color2); | ||
switch (((_a = wcag2.level) !== null && _a !== void 0 ? _a : 'AA') + ((_b = wcag2.size) !== null && _b !== void 0 ? _b : 'small')) { | ||
export function isReadable(color1, color2, wcag2 = { level: 'AA', size: 'small' }) { | ||
const readabilityLevel = readability(color1, color2); | ||
switch ((wcag2.level ?? 'AA') + (wcag2.size ?? 'small')) { | ||
case 'AAsmall': | ||
@@ -64,10 +62,8 @@ case 'AAAlarge': | ||
*/ | ||
export function mostReadable(baseColor, colorList, args) { | ||
if (args === void 0) { args = { includeFallbackColors: false, level: 'AA', size: 'small' }; } | ||
var bestColor = null; | ||
var bestScore = 0; | ||
var includeFallbackColors = args.includeFallbackColors, level = args.level, size = args.size; | ||
for (var _i = 0, colorList_1 = colorList; _i < colorList_1.length; _i++) { | ||
var color = colorList_1[_i]; | ||
var score = readability(baseColor, color); | ||
export function mostReadable(baseColor, colorList, args = { includeFallbackColors: false, level: 'AA', size: 'small' }) { | ||
let bestColor = null; | ||
let bestScore = 0; | ||
const { includeFallbackColors, level, size } = args; | ||
for (const color of colorList) { | ||
const score = readability(baseColor, color); | ||
if (score > bestScore) { | ||
@@ -78,3 +74,3 @@ bestScore = score; | ||
} | ||
if (isReadable(baseColor, bestColor, { level: level, size: size }) || !includeFallbackColors) { | ||
if (isReadable(baseColor, bestColor, { level, size }) || !includeFallbackColors) { | ||
return bestColor; | ||
@@ -81,0 +77,0 @@ } |
@@ -7,11 +7,11 @@ import { rgbaToArgbHex } from './conversion.js'; | ||
export function toMsFilter(firstColor, secondColor) { | ||
var color = new TinyColor(firstColor); | ||
var hex8String = '#' + rgbaToArgbHex(color.r, color.g, color.b, color.a); | ||
var secondHex8String = hex8String; | ||
var gradientType = color.gradientType ? 'GradientType = 1, ' : ''; | ||
const color = new TinyColor(firstColor); | ||
const hex8String = '#' + rgbaToArgbHex(color.r, color.g, color.b, color.a); | ||
let secondHex8String = hex8String; | ||
const gradientType = color.gradientType ? 'GradientType = 1, ' : ''; | ||
if (secondColor) { | ||
var s = new TinyColor(secondColor); | ||
const s = new TinyColor(secondColor); | ||
secondHex8String = '#' + rgbaToArgbHex(s.r, s.g, s.b, s.a); | ||
} | ||
return "progid:DXImageTransform.Microsoft.gradient(".concat(gradientType, "startColorstr=").concat(hex8String, ",endColorstr=").concat(secondHex8String, ")"); | ||
return `progid:DXImageTransform.Microsoft.gradient(${gradientType}startColorstr=${hex8String},endColorstr=${secondHex8String})`; | ||
} |
import { names } from './css-color-names.js'; | ||
import { inputToRGB, isValidCSSUnit, stringInputToObject } from './format-input.js'; | ||
import { fromRatio, legacyRandom } from './from-ratio.js'; | ||
import { TinyColor, tinycolor } from './index.js'; | ||
import { TinyColor } from './index.js'; | ||
import { random } from './random.js'; | ||
import { mostReadable, readability } from './readability.js'; | ||
import { toMsFilter } from './to-ms-filter.js'; | ||
var tinycolorumd = tinycolor; | ||
tinycolorumd.TinyColor = TinyColor; | ||
tinycolorumd.readability = readability; | ||
tinycolorumd.mostReadable = mostReadable; | ||
tinycolorumd.random = random; | ||
tinycolorumd.names = names; | ||
tinycolorumd.fromRatio = fromRatio; | ||
tinycolorumd.legacyRandom = legacyRandom; | ||
tinycolorumd.toMsFilter = toMsFilter; | ||
tinycolorumd.inputToRGB = inputToRGB; | ||
tinycolorumd.stringInputToObject = stringInputToObject; | ||
tinycolorumd.isValidCSSUnit = isValidCSSUnit; | ||
const tinycolorumd = { | ||
TinyColor, | ||
readability, | ||
mostReadable, | ||
random, | ||
names, | ||
fromRatio, | ||
legacyRandom, | ||
toMsFilter, | ||
inputToRGB, | ||
stringInputToObject, | ||
isValidCSSUnit, | ||
}; | ||
export default tinycolorumd; |
@@ -9,3 +9,3 @@ /** | ||
} | ||
var isPercent = isPercentage(n); | ||
const isPercent = isPercentage(n); | ||
n = max === 360 ? n : Math.min(max, Math.max(0, parseFloat(n))); | ||
@@ -72,4 +72,4 @@ // Automatically convert percentage into number | ||
export function convertToPercentage(n) { | ||
if (n <= 1) { | ||
return "".concat(Number(n) * 100, "%"); | ||
if (Number(n) <= 1) { | ||
return `${Number(n) * 100}%`; | ||
} | ||
@@ -76,0 +76,0 @@ return n; |
@@ -1,2 +0,1 @@ | ||
import { tinycolor } from './index.js'; | ||
export * from './index.js'; | ||
@@ -11,2 +10,1 @@ export * from './css-color-names.js'; | ||
export * from './conversion.js'; | ||
export default tinycolor; |
@@ -17,3 +17,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var index_js_1 = require("./index.js"); | ||
__exportStar(require("./index.js"), exports); | ||
@@ -28,3 +27,1 @@ __exportStar(require("./css-color-names.js"), exports); | ||
__exportStar(require("./conversion.js"), exports); | ||
// kept for backwards compatability with v1 | ||
exports.default = index_js_1.tinycolor; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.bounds = exports.random = void 0; | ||
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */ | ||
// randomColor by David Merfield under the CC0 license | ||
// https://github.com/davidmerfield/randomColor/ | ||
var index_js_1 = require("./index.js"); | ||
function random(options) { | ||
if (options === void 0) { options = {}; } | ||
const index_js_1 = require("./index.js"); | ||
function random(options = {}) { | ||
// Check if we need to generate multiple colors | ||
if (options.count !== undefined && | ||
options.count !== null) { | ||
var totalColors = options.count; | ||
var colors = []; | ||
const totalColors = options.count; | ||
const colors = []; | ||
options.count = undefined; | ||
@@ -30,8 +28,8 @@ while (totalColors > colors.length) { | ||
// First we pick a hue (H) | ||
var h = pickHue(options.hue, options.seed); | ||
const h = pickHue(options.hue, options.seed); | ||
// Then use H to determine saturation (S) | ||
var s = pickSaturation(h, options); | ||
const s = pickSaturation(h, options); | ||
// Then use S and H to determine brightness (B). | ||
var v = pickBrightness(h, s, options); | ||
var res = { h: h, s: s, v: v }; | ||
const v = pickBrightness(h, s, options); | ||
const res = { h, s, v }; | ||
if (options.alpha !== undefined) { | ||
@@ -45,4 +43,4 @@ res.a = options.alpha; | ||
function pickHue(hue, seed) { | ||
var hueRange = getHueRange(hue); | ||
var res = randomWithin(hueRange, seed); | ||
const hueRange = getHueRange(hue); | ||
let res = randomWithin(hueRange, seed); | ||
// Instead of storing red as two seperate ranges, | ||
@@ -62,5 +60,5 @@ // we group them, using negative numbers | ||
} | ||
var saturationRange = getColorInfo(hue).saturationRange; | ||
var sMin = saturationRange[0]; | ||
var sMax = saturationRange[1]; | ||
const { saturationRange } = getColorInfo(hue); | ||
let sMin = saturationRange[0]; | ||
let sMax = saturationRange[1]; | ||
switch (options.luminosity) { | ||
@@ -82,4 +80,4 @@ case 'bright': | ||
function pickBrightness(H, S, options) { | ||
var bMin = getMinimumBrightness(H, S); | ||
var bMax = 100; | ||
let bMin = getMinimumBrightness(H, S); | ||
let bMax = 100; | ||
switch (options.luminosity) { | ||
@@ -102,11 +100,11 @@ case 'dark': | ||
function getMinimumBrightness(H, S) { | ||
var lowerBounds = getColorInfo(H).lowerBounds; | ||
for (var i = 0; i < lowerBounds.length - 1; i++) { | ||
var s1 = lowerBounds[i][0]; | ||
var v1 = lowerBounds[i][1]; | ||
var s2 = lowerBounds[i + 1][0]; | ||
var v2 = lowerBounds[i + 1][1]; | ||
const { lowerBounds } = getColorInfo(H); | ||
for (let i = 0; i < lowerBounds.length - 1; i++) { | ||
const s1 = lowerBounds[i][0]; | ||
const v1 = lowerBounds[i][1]; | ||
const s2 = lowerBounds[i + 1][0]; | ||
const v2 = lowerBounds[i + 1][1]; | ||
if (S >= s1 && S <= s2) { | ||
var m = (v2 - v1) / (s2 - s1); | ||
var b = v1 - m * s1; | ||
const m = (v2 - v1) / (s2 - s1); | ||
const b = v1 - m * s1; | ||
return m * S + b; | ||
@@ -118,3 +116,3 @@ } | ||
function getHueRange(colorInput) { | ||
var num = parseInt(colorInput, 10); | ||
const num = parseInt(colorInput, 10); | ||
if (!Number.isNaN(num) && num < 360 && num > 0) { | ||
@@ -124,5 +122,5 @@ return [num, num]; | ||
if (typeof colorInput === 'string') { | ||
var namedColor = exports.bounds.find(function (n) { return n.name === colorInput; }); | ||
const namedColor = exports.bounds.find(n => n.name === colorInput); | ||
if (namedColor) { | ||
var color = defineColor(namedColor); | ||
const color = defineColor(namedColor); | ||
if (color.hueRange) { | ||
@@ -132,5 +130,5 @@ return color.hueRange; | ||
} | ||
var parsed = new index_js_1.TinyColor(colorInput); | ||
const parsed = new index_js_1.TinyColor(colorInput); | ||
if (parsed.isValid) { | ||
var hue = parsed.toHsv().h; | ||
const hue = parsed.toHsv().h; | ||
return [hue, hue]; | ||
@@ -146,5 +144,4 @@ } | ||
} | ||
for (var _i = 0, bounds_1 = exports.bounds; _i < bounds_1.length; _i++) { | ||
var bound = bounds_1[_i]; | ||
var color = defineColor(bound); | ||
for (const bound of exports.bounds) { | ||
const color = defineColor(bound); | ||
if (color.hueRange && hue >= color.hueRange[0] && hue <= color.hueRange[1]) { | ||
@@ -161,13 +158,13 @@ return color; | ||
// Seeded random algorithm from http://indiegamr.com/generate-repeatable-random-numbers-in-js/ | ||
var max = range[1] || 1; | ||
var min = range[0] || 0; | ||
const max = range[1] || 1; | ||
const min = range[0] || 0; | ||
seed = (seed * 9301 + 49297) % 233280; | ||
var rnd = seed / 233280.0; | ||
const rnd = seed / 233280.0; | ||
return Math.floor(min + rnd * (max - min)); | ||
} | ||
function defineColor(bound) { | ||
var sMin = bound.lowerBounds[0][0]; | ||
var sMax = bound.lowerBounds[bound.lowerBounds.length - 1][0]; | ||
var bMin = bound.lowerBounds[bound.lowerBounds.length - 1][1]; | ||
var bMax = bound.lowerBounds[0][1]; | ||
const sMin = bound.lowerBounds[0][0]; | ||
const sMax = bound.lowerBounds[bound.lowerBounds.length - 1][0]; | ||
const bMin = bound.lowerBounds[bound.lowerBounds.length - 1][1]; | ||
const bMax = bound.lowerBounds[0][1]; | ||
return { | ||
@@ -174,0 +171,0 @@ name: bound.name, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mostReadable = exports.isReadable = exports.readability = void 0; | ||
var index_js_1 = require("./index.js"); | ||
const index_js_1 = require("./index.js"); | ||
// Readability Functions | ||
@@ -14,4 +14,4 @@ // --------------------- | ||
function readability(color1, color2) { | ||
var c1 = new index_js_1.TinyColor(color1); | ||
var c2 = new index_js_1.TinyColor(color2); | ||
const c1 = new index_js_1.TinyColor(color1); | ||
const c2 = new index_js_1.TinyColor(color2); | ||
return ((Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / | ||
@@ -34,7 +34,5 @@ (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05)); | ||
*/ | ||
function isReadable(color1, color2, wcag2) { | ||
var _a, _b; | ||
if (wcag2 === void 0) { wcag2 = { level: 'AA', size: 'small' }; } | ||
var readabilityLevel = readability(color1, color2); | ||
switch (((_a = wcag2.level) !== null && _a !== void 0 ? _a : 'AA') + ((_b = wcag2.size) !== null && _b !== void 0 ? _b : 'small')) { | ||
function isReadable(color1, color2, wcag2 = { level: 'AA', size: 'small' }) { | ||
const readabilityLevel = readability(color1, color2); | ||
switch ((wcag2.level ?? 'AA') + (wcag2.size ?? 'small')) { | ||
case 'AAsmall': | ||
@@ -69,10 +67,8 @@ case 'AAAlarge': | ||
*/ | ||
function mostReadable(baseColor, colorList, args) { | ||
if (args === void 0) { args = { includeFallbackColors: false, level: 'AA', size: 'small' }; } | ||
var bestColor = null; | ||
var bestScore = 0; | ||
var includeFallbackColors = args.includeFallbackColors, level = args.level, size = args.size; | ||
for (var _i = 0, colorList_1 = colorList; _i < colorList_1.length; _i++) { | ||
var color = colorList_1[_i]; | ||
var score = readability(baseColor, color); | ||
function mostReadable(baseColor, colorList, args = { includeFallbackColors: false, level: 'AA', size: 'small' }) { | ||
let bestColor = null; | ||
let bestScore = 0; | ||
const { includeFallbackColors, level, size } = args; | ||
for (const color of colorList) { | ||
const score = readability(baseColor, color); | ||
if (score > bestScore) { | ||
@@ -83,3 +79,3 @@ bestScore = score; | ||
} | ||
if (isReadable(baseColor, bestColor, { level: level, size: size }) || !includeFallbackColors) { | ||
if (isReadable(baseColor, bestColor, { level, size }) || !includeFallbackColors) { | ||
return bestColor; | ||
@@ -86,0 +82,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toMsFilter = void 0; | ||
var conversion_js_1 = require("./conversion.js"); | ||
var index_js_1 = require("./index.js"); | ||
const conversion_js_1 = require("./conversion.js"); | ||
const index_js_1 = require("./index.js"); | ||
/** | ||
@@ -10,12 +10,12 @@ * Returns the color represented as a Microsoft filter for use in old versions of IE. | ||
function toMsFilter(firstColor, secondColor) { | ||
var color = new index_js_1.TinyColor(firstColor); | ||
var hex8String = '#' + (0, conversion_js_1.rgbaToArgbHex)(color.r, color.g, color.b, color.a); | ||
var secondHex8String = hex8String; | ||
var gradientType = color.gradientType ? 'GradientType = 1, ' : ''; | ||
const color = new index_js_1.TinyColor(firstColor); | ||
const hex8String = '#' + (0, conversion_js_1.rgbaToArgbHex)(color.r, color.g, color.b, color.a); | ||
let secondHex8String = hex8String; | ||
const gradientType = color.gradientType ? 'GradientType = 1, ' : ''; | ||
if (secondColor) { | ||
var s = new index_js_1.TinyColor(secondColor); | ||
const s = new index_js_1.TinyColor(secondColor); | ||
secondHex8String = '#' + (0, conversion_js_1.rgbaToArgbHex)(s.r, s.g, s.b, s.a); | ||
} | ||
return "progid:DXImageTransform.Microsoft.gradient(".concat(gradientType, "startColorstr=").concat(hex8String, ",endColorstr=").concat(secondHex8String, ")"); | ||
return `progid:DXImageTransform.Microsoft.gradient(${gradientType}startColorstr=${hex8String},endColorstr=${secondHex8String})`; | ||
} | ||
exports.toMsFilter = toMsFilter; |
@@ -9,3 +9,2 @@ import { names } from './css-color-names.js'; | ||
export interface TinyColorUMD { | ||
(): TinyColor; | ||
TinyColor: typeof TinyColor; | ||
@@ -12,0 +11,0 @@ readability: typeof readability; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var css_color_names_js_1 = require("./css-color-names.js"); | ||
var format_input_js_1 = require("./format-input.js"); | ||
var from_ratio_js_1 = require("./from-ratio.js"); | ||
var index_js_1 = require("./index.js"); | ||
var random_js_1 = require("./random.js"); | ||
var readability_js_1 = require("./readability.js"); | ||
var to_ms_filter_js_1 = require("./to-ms-filter.js"); | ||
var tinycolorumd = index_js_1.tinycolor; | ||
tinycolorumd.TinyColor = index_js_1.TinyColor; | ||
tinycolorumd.readability = readability_js_1.readability; | ||
tinycolorumd.mostReadable = readability_js_1.mostReadable; | ||
tinycolorumd.random = random_js_1.random; | ||
tinycolorumd.names = css_color_names_js_1.names; | ||
tinycolorumd.fromRatio = from_ratio_js_1.fromRatio; | ||
tinycolorumd.legacyRandom = from_ratio_js_1.legacyRandom; | ||
tinycolorumd.toMsFilter = to_ms_filter_js_1.toMsFilter; | ||
tinycolorumd.inputToRGB = format_input_js_1.inputToRGB; | ||
tinycolorumd.stringInputToObject = format_input_js_1.stringInputToObject; | ||
tinycolorumd.isValidCSSUnit = format_input_js_1.isValidCSSUnit; | ||
const css_color_names_js_1 = require("./css-color-names.js"); | ||
const format_input_js_1 = require("./format-input.js"); | ||
const from_ratio_js_1 = require("./from-ratio.js"); | ||
const index_js_1 = require("./index.js"); | ||
const random_js_1 = require("./random.js"); | ||
const readability_js_1 = require("./readability.js"); | ||
const to_ms_filter_js_1 = require("./to-ms-filter.js"); | ||
const tinycolorumd = { | ||
TinyColor: index_js_1.TinyColor, | ||
readability: readability_js_1.readability, | ||
mostReadable: readability_js_1.mostReadable, | ||
random: random_js_1.random, | ||
names: css_color_names_js_1.names, | ||
fromRatio: from_ratio_js_1.fromRatio, | ||
legacyRandom: from_ratio_js_1.legacyRandom, | ||
toMsFilter: to_ms_filter_js_1.toMsFilter, | ||
inputToRGB: format_input_js_1.inputToRGB, | ||
stringInputToObject: format_input_js_1.stringInputToObject, | ||
isValidCSSUnit: format_input_js_1.isValidCSSUnit, | ||
}; | ||
exports.default = tinycolorumd; |
@@ -12,3 +12,3 @@ "use strict"; | ||
} | ||
var isPercent = isPercentage(n); | ||
const isPercent = isPercentage(n); | ||
n = max === 360 ? n : Math.min(max, Math.max(0, parseFloat(n))); | ||
@@ -80,4 +80,4 @@ // Automatically convert percentage into number | ||
function convertToPercentage(n) { | ||
if (n <= 1) { | ||
return "".concat(Number(n) * 100, "%"); | ||
if (Number(n) <= 1) { | ||
return `${Number(n) * 100}%`; | ||
} | ||
@@ -84,0 +84,0 @@ return n; |
{ | ||
"name": "@ctrl/tinycolor", | ||
"version": "3.6.1", | ||
"version": "4.0.0", | ||
"description": "Fast, small color manipulation and conversion for JavaScript", | ||
@@ -28,4 +28,4 @@ "author": "Scott Cooper <scttcper@gmail.com>", | ||
"scripts": { | ||
"build:demo": "rollup -c rollup.demo.js", | ||
"watch:demo": "rollup -c rollup.demo.js -w", | ||
"demo:build": "npm run build --workspace=demo", | ||
"demo:watch": "npm run dev --workspace=demo", | ||
"lint": "eslint --ext .js,.ts, .", | ||
@@ -35,42 +35,22 @@ "lint:fix": "eslint --fix --ext .js,.ts, .", | ||
"build": "del-cli dist && tsc -p tsconfig.build.json && tsc -p tsconfig.module.json && ts-node build", | ||
"build:docs": "typedoc --out demo/public/docs --hideGenerator --tsconfig tsconfig.build.json src/public_api.ts", | ||
"test": "jest", | ||
"test:ci": "jest --ci --runInBand --reporters=default --reporters=jest-junit --coverage", | ||
"test:watch": "jest --watch" | ||
"docs:build": "typedoc --out demo/dist/docs --hideGenerator --tsconfig tsconfig.build.json src/public_api.ts", | ||
"test": "vitest run", | ||
"test:watch": "vitest", | ||
"test:ci": "vitest run --coverage --reporter=default --reporter=junit --outputFile=./junit.xml" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@babel/plugin-transform-modules-commonjs": "7.19.6", | ||
"@babel/preset-typescript": "7.18.6", | ||
"@ctrl/eslint-config": "3.5.6", | ||
"@jest/globals": "29.3.1", | ||
"@types/node": "18.11.11", | ||
"@ctrl/eslint-config": "4.0.3", | ||
"@rollup/plugin-terser": "0.4.3", | ||
"@types/node": "20.5.4", | ||
"@vitest/coverage-v8": "0.34.2", | ||
"del-cli": "5.0.0", | ||
"jest": "29.3.1", | ||
"jest-junit": "15.0.0", | ||
"rollup": "2.70.1", | ||
"rollup-plugin-livereload": "2.0.5", | ||
"rollup-plugin-serve": "1.1.0", | ||
"rollup-plugin-sourcemaps": "0.6.3", | ||
"rollup-plugin-terser": "7.0.2", | ||
"rollup-plugin-typescript2": "0.34.1", | ||
"rollup": "3.28.1", | ||
"ts-node": "10.9.1", | ||
"typedoc": "0.23.21", | ||
"typescript": "4.9.3" | ||
"typedoc": "0.24.8", | ||
"typescript": "5.1.6", | ||
"vitest": "0.34.2" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node", | ||
"coverageProvider": "v8", | ||
"moduleNameMapper": { | ||
"(.+)\\.js": "$1" | ||
} | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"@babel/preset-typescript" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-transform-modules-commonjs" | ||
] | ||
}, | ||
"workspaces": [ | ||
"demo" | ||
], | ||
"release": { | ||
@@ -80,4 +60,4 @@ "branch": "master" | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=14" | ||
} | ||
} |
# tinycolor | ||
[![npm](https://badgen.net/npm/v/@ctrl/tinycolor)](https://www.npmjs.com/package/@ctrl/tinycolor) | ||
[![CircleCI](https://badgen.net/circleci/github/scttcper/tinycolor)](https://circleci.com/gh/scttcper/tinycolor) | ||
[![coverage](https://badgen.net/codecov/c/github/scttcper/tinycolor)](https://codecov.io/gh/scttcper/tinycolor) | ||
@@ -19,2 +18,3 @@ [![bundlesize](https://badgen.net/bundlephobia/min/@ctrl/tinycolor)](https://bundlephobia.com/result?p=@ctrl/tinycolor) | ||
* `tinycolor` is now exported as a class called `TinyColor` | ||
* default export removed, use `import { TinyColor } from '@ctrl/tinycolor'` | ||
* new `random`, an implementation of [randomColor](https://github.com/davidmerfield/randomColor/) by David Merfield that returns a TinyColor object | ||
@@ -21,0 +21,0 @@ * several functions moved out of the tinycolor class and are no longer `TinyColor.<function>` |
Sorry, the diff of this file is not supported yet
10
232583
3764