From fb4bdf2458218f334f8ee5f7958ad05d681355b3 Mon Sep 17 00:00:00 2001 From: Gregor Aisch Date: Mon, 19 Aug 2024 20:55:32 +0000 Subject: [PATCH] feat: add chroma.contrastAPCA (#353) * feat: add chroma.contrastAPCA resolves #302 * docs: fix rendering of transparent css colors in docs * build --- dist/chroma.cjs | 66 +++++++++++++++++++++++++++++++++++++ dist/chroma.min.cjs | 16 ++++++++- docs/index.html | 9 +++++- docs/libs/chroma.cjs | 66 +++++++++++++++++++++++++++++++++++++ docs/libs/chroma.min.cjs | 16 ++++++++- docs/src/footer.inc.html | 2 +- docs/src/index.md | 13 ++++++++ index.js | 3 ++ index.umd.js | 2 ++ src/utils/contrastAPCA.js | 68 +++++++++++++++++++++++++++++++++++++++ test/contrast.test.js | 31 ++++++++++++++++++ 11 files changed, 288 insertions(+), 4 deletions(-) create mode 100644 src/utils/contrastAPCA.js diff --git a/dist/chroma.cjs b/dist/chroma.cjs index ffedf6db..d618ccfc 100644 --- a/dist/chroma.cjs +++ b/dist/chroma.cjs @@ -3687,6 +3687,71 @@ return l1 > l2 ? (l1 + 0.05) / (l2 + 0.05) : (l2 + 0.05) / (l1 + 0.05); } + /** + * @license + * + * The APCA contrast prediction algorithm is based of the formulas published + * in the APCA-1.0.98G specification by Myndex. The specification is available at: + * https://raw.githubusercontent.com/Myndex/apca-w3/master/images/APCAw3_0.1.17_APCA0.0.98G.svg + * + * Note that the APCA implementation is still beta, so please update to + * future versions of chroma.js when they become available. + * + * You can read more about the APCA Readability Criterion at + * https://readtech.org/ARC/ + */ + + // constants + var W_offset = 0.027; + var P_in = 0.0005; + var P_out = 0.1; + var R_scale = 1.14; + var B_threshold = 0.022; + var B_exp = 1.414; + + function contrastAPCA (text, bg) { + // parse input colors + text = new Color(text); + bg = new Color(bg); + // if text color has alpha, blend against background + if (text.alpha() < 1) { + text = mix(bg, text, text.alpha(), 'rgb'); + } + var l_text = lum.apply(void 0, text.rgb()); + var l_bg = lum.apply(void 0, bg.rgb()); + + // soft clamp black levels + var Y_text = + l_text >= B_threshold + ? l_text + : l_text + Math.pow(B_threshold - l_text, B_exp); + var Y_bg = + l_bg >= B_threshold ? l_bg : l_bg + Math.pow(B_threshold - l_bg, B_exp); + + // normal polarity (dark text on light background) + var S_norm = Math.pow(Y_bg, 0.56) - Math.pow(Y_text, 0.57); + // reverse polarity (light text on dark background) + var S_rev = Math.pow(Y_bg, 0.65) - Math.pow(Y_text, 0.62); + // clamp noise then scale + var C = + Math.abs(Y_bg - Y_text) < P_in + ? 0 + : Y_text < Y_bg + ? S_norm * R_scale + : S_rev * R_scale; + // clamp minimum contrast then offset + var S_apc = Math.abs(C) < P_out ? 0 : C > 0 ? C - W_offset : C + W_offset; + // scale to 100 + return S_apc * 100; + } + function lum(r, g, b) { + return ( + 0.2126729 * Math.pow(r / 255, 2.4) + + 0.7151522 * Math.pow(g / 255, 2.4) + + 0.072175 * Math.pow(b / 255, 2.4) + ); + } + var sqrt = Math.sqrt; var pow = Math.pow; var min = Math.min; @@ -3904,6 +3969,7 @@ Color: Color, colors: w3cx11, contrast: contrast, + contrastAPCA: contrastAPCA, cubehelix: cubehelix, deltaE: deltaE, distance: distance, diff --git a/dist/chroma.min.cjs b/dist/chroma.min.cjs index 2e50806f..d7407ce0 100644 --- a/dist/chroma.min.cjs +++ b/dist/chroma.min.cjs @@ -55,4 +55,18 @@ * @preserve */ -!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(r="undefined"!=typeof globalThis?globalThis:r||self).chroma=e()}(this,(function(){"use strict";var r=Math.min,e=Math.max;function n(n,t,a){return void 0===t&&(t=0),void 0===a&&(a=1),r(e(t,n),a)}function t(r){r._clipped=!1,r._unclipped=r.slice(0);for(var e=0;e<=3;e++)e<3?((r[e]<0||r[e]>255)&&(r._clipped=!0),r[e]=n(r[e],0,255)):3===e&&(r[e]=n(r[e],0,1));return r}for(var a={},f=0,o=["Boolean","Number","String","Function","Array","Date","RegExp","Undefined","Null"];f=3?Array.prototype.slice.call(r):"object"==c(r[0])&&e?e.split("").filter((function(e){return void 0!==r[0][e]})).map((function(e){return r[0][e]})):r[0].slice(0)}function l(r){if(r.length<2)return null;var e=r.length-1;return"string"==c(r[e])?r[e].toLowerCase():null}var h=Math.PI,s=Math.min,d=Math.max,b=function(r){return Math.round(100*r)/100},g=function(r){return Math.round(100*r)/100},v=2*h,p=h/3,m=h/180,y=180/h,w={format:{},autodetect:[]},k=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=this;if("object"===c(r[0])&&r[0].constructor&&r[0].constructor===this.constructor)return r[0];var a=l(r),f=!1;if(!a){f=!0,w.sorted||(w.autodetect=w.autodetect.sort((function(r,e){return e.p-r.p})),w.sorted=!0);for(var o=0,u=w.autodetect;o4?r[4]:1;return 1===f?[0,0,0,o]:[n>=1?0:255*(1-n)*(1-f),t>=1?0:255*(1-t)*(1-f),a>=1?0:255*(1-a)*(1-f),o]},w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"cmyk"))&&4===r.length)return"cmyk"}});var _=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t,a=(r=i(r,"rgba"))[0],f=r[1],o=r[2],u=s(a/=255,f/=255,o/=255),c=d(a,f,o),l=(c+u)/2;return c===u?(n=0,t=Number.NaN):n=l<.5?(c-u)/(c+u):(c-u)/(2-c-u),a==c?t=(f-o)/(c-u):f==c?t=2+(o-a)/(c-u):o==c&&(t=4+(a-f)/(c-u)),(t*=60)<0&&(t+=360),r.length>3&&void 0!==r[3]?[t,n,l,r[3]]:[t,n,l]},j={Kn:18,labWhitePoint:"d65",Xn:.95047,Yn:1,Zn:1.08883,t0:.137931034,t1:.206896552,t2:.12841855,t3:.008856452,kE:216/24389,kKE:8,kK:24389/27,RefWhiteRGB:{X:.95047,Y:1,Z:1.08883},MtxRGB2XYZ:{m00:.4124564390896922,m01:.21267285140562253,m02:.0193338955823293,m10:.357576077643909,m11:.715152155287818,m12:.11919202588130297,m20:.18043748326639894,m21:.07217499330655958,m22:.9503040785363679},MtxXYZ2RGB:{m00:3.2404541621141045,m01:-.9692660305051868,m02:.055643430959114726,m10:-1.5371385127977166,m11:1.8760108454466942,m12:-.2040259135167538,m20:-.498531409556016,m21:.041556017530349834,m22:1.0572251882231791},As:.9414285350000001,Bs:1.040417467,Cs:1.089532651,MtxAdaptMa:{m00:.8951,m01:-.7502,m02:.0389,m10:.2664,m11:1.7135,m12:-.0685,m20:-.1614,m21:.0367,m22:1.0296},MtxAdaptMaI:{m00:.9869929054667123,m01:.43230526972339456,m02:-.008528664575177328,m10:-.14705425642099013,m11:.5183602715367776,m12:.04004282165408487,m20:.15996265166373125,m21:.0492912282128556,m22:.9684866957875502}},A=new Map([["a",[1.0985,.35585]],["b",[1.0985,.35585]],["c",[.98074,1.18232]],["d50",[.96422,.82521]],["d55",[.95682,.92149]],["d65",[.95047,1.08883]],["e",[1,1,1]],["f2",[.99186,.67393]],["f7",[.95041,1.08747]],["f11",[1.00962,.6435]],["icc",[.96422,.82521]]]);function E(r){var e=A.get(String(r).toLowerCase());if(!e)throw new Error("unknown Lab illuminant "+r);j.labWhitePoint=r,j.Xn=e[0],j.Zn=e[1]}function R(){return j.labWhitePoint}var O=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgb"),t=n[0],a=n[1],f=n[2],o=n.slice(3),u=F(t,a,f),c=function(r,e,n){var t=j.Xn,a=j.Yn,f=j.Zn,o=j.kE,u=j.kK,c=r/t,i=e/a,l=n/f,h=c>o?Math.pow(c,1/3):(u*c+16)/116,s=i>o?Math.pow(i,1/3):(u*i+16)/116,d=l>o?Math.pow(l,1/3):(u*l+16)/116;return[116*s-16,500*(h-s),200*(s-d)]}(u[0],u[1],u[2]);return[c[0],c[1],c[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])};function P(r){var e=Math.sign(r);return((r=Math.abs(r))<=.04045?r/12.92:Math.pow((r+.055)/1.055,2.4))*e}var F=function(r,e,n){r=P(r/255),e=P(e/255),n=P(n/255);var t=j.MtxRGB2XYZ,a=j.MtxAdaptMa,f=j.MtxAdaptMaI,o=j.Xn,u=j.Yn,c=j.Zn,i=j.As,l=j.Bs,h=j.Cs,s=r*t.m00+e*t.m10+n*t.m20,d=r*t.m01+e*t.m11+n*t.m21,b=r*t.m02+e*t.m12+n*t.m22,g=o*a.m00+u*a.m10+c*a.m20,v=o*a.m01+u*a.m11+c*a.m21,p=o*a.m02+u*a.m12+c*a.m22,m=s*a.m00+d*a.m10+b*a.m20,y=s*a.m01+d*a.m11+b*a.m21,w=s*a.m02+d*a.m12+b*a.m22;return y*=v/l,w*=p/h,[s=(m*=g/i)*f.m00+y*f.m10+w*f.m20,d=m*f.m01+y*f.m11+w*f.m21,b=m*f.m02+y*f.m12+w*f.m22]},L=Math.sqrt,B=Math.atan2,G=Math.round,Y=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lab"),t=n[0],a=n[1],f=n[2],o=L(a*a+f*f),u=(B(f,a)*y+360)%360;return 0===G(1e4*o)&&(u=Number.NaN),[t,o,u]},q=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgb"),t=n[0],a=n[1],f=n[2],o=n.slice(3),u=O(t,a,f),c=u[0],l=u[1],h=u[2],s=Y(c,l,h);return[s[0],s[1],s[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])};function X(r,e){var n=r.length;Array.isArray(r[0])||(r=[r]),Array.isArray(e[0])||(e=e.map((function(r){return[r]})));var t=e[0].length,a=e[0].map((function(r,n){return e.map((function(r){return r[n]}))})),f=r.map((function(r){return a.map((function(e){return Array.isArray(r)?r.reduce((function(r,n,t){return r+n*(e[t]||0)}),0):e.reduce((function(e,n){return e+n*r}),0)}))}));return 1===n&&(f=f[0]),1===t?f.map((function(r){return r[0]})):f}var C=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t,a=i(r,"rgb"),f=a[0],o=a[1],u=a[2],c=a.slice(3),l=F(f,o,u);return(n=[[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],t=X([[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.9292868615863434,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],l),X(n,t.map((function(r){return Math.cbrt(r)})))).concat(c.length>0&&c[0]<1?[c[0]]:[])};var Z=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgb"),t=n[0],a=n[1],f=n[2],o=n.slice(3),u=C(t,a,f),c=u[0],l=u[1],h=u[2],s=Y(c,l,h);return[s[0],s[1],s[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])},$=Math.round,S=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgba"),t=l(r)||"rgb";if("hsl"===t.substr(0,3))return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"hsla"),t=l(r)||"lsa";return n[0]=b(n[0]||0)+"deg",n[1]=b(100*n[1])+"%",n[2]=b(100*n[2])+"%","hsla"===t||n.length>3&&n[3]<1?(n[3]="/ "+(n.length>3?n[3]:1),t="hsla"):n.length=3,t.substr(0,3)+"("+n.join(" ")+")"}(_(n),t);if("lab"===t.substr(0,3)){var a=R();E("d50");var f=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lab"),t=l(r)||"lab";return n[0]=b(n[0])+"%",n[1]=b(n[1]),n[2]=b(n[2]),"laba"===t||n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"lab("+n.join(" ")+")"}(O(n),t);return E(a),f}if("lch"===t.substr(0,3)){var o=R();E("d50");var u=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lch"),t=l(r)||"lab";return n[0]=b(n[0])+"%",n[1]=b(n[1]),n[2]=b(n[2])+"deg","lcha"===t||n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"lch("+n.join(" ")+")"}(q(n),t);return E(o),u}return"oklab"===t.substr(0,5)?function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lab");return n[0]=b(100*n[0])+"%",n[1]=g(n[1]),n[2]=g(n[2]),n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"oklab("+n.join(" ")+")"}(C(n)):"oklch"===t.substr(0,5)?function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lab");return n[0]=b(100*n[0])+"%",n[1]=g(n[1]),n[2]=b(n[2])+"deg",n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"oklch("+n.join(" ")+")"}(Z(n)):(n[0]=$(n[0]),n[1]=$(n[1]),n[2]=$(n[2]),("rgba"===t||n.length>3&&n[3]<1)&&(n[3]="/ "+(n.length>3?n[3]:1),t="rgba"),t.substr(0,3)+"("+n.slice(0,"rgb"===t?3:4).join(" ")+")")},W=function(){for(var r,e=[],n=arguments.length;n--;)e[n]=arguments[n];var t,a,f,o=(e=i(e,"hsl"))[0],u=e[1],c=e[2];if(0===u)t=a=f=255*c;else{var l=[0,0,0],h=[0,0,0],s=c<.5?c*(1+u):c+u-c*u,d=2*c-s,b=o/360;l[0]=b+1/3,l[1]=b,l[2]=b-1/3;for(var g=0;g<3;g++)l[g]<0&&(l[g]+=1),l[g]>1&&(l[g]-=1),6*l[g]<1?h[g]=d+6*(s-d)*l[g]:2*l[g]<1?h[g]=s:3*l[g]<2?h[g]=d+(s-d)*(2/3-l[g])*6:h[g]=d;t=(r=[255*h[0],255*h[1],255*h[2]])[0],a=r[1],f=r[2]}return e.length>3?[t,a,f,e[3]]:[t,a,f,1]},I=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=(r=i(r,"lab"))[0],t=r[1],a=r[2],f=K(n,t,a),o=f[0],u=f[1],c=f[2],l=U(o,u,c);return[l[0],l[1],l[2],r.length>3?r[3]:1]},K=function(r,e,n){var t=j.kE,a=j.kK,f=j.kKE,o=j.Xn,u=j.Yn,c=j.Zn,i=(r+16)/116,l=.002*e+i,h=i-.005*n,s=l*l*l,d=h*h*h;return[(s>t?s:(116*l-16)/a)*o,(r>f?Math.pow((r+16)/116,3):r/a)*u,(d>t?d:(116*h-16)/a)*c]},z=function(r){var e=Math.sign(r);return((r=Math.abs(r))<=.0031308?12.92*r:1.055*Math.pow(r,1/2.4)-.055)*e},U=function(r,e,n){var t=j.MtxAdaptMa,a=j.MtxAdaptMaI,f=j.MtxXYZ2RGB,o=j.RefWhiteRGB,u=j.Xn,c=j.Yn,i=j.Zn,l=u*t.m00+c*t.m10+i*t.m20,h=u*t.m01+c*t.m11+i*t.m21,s=u*t.m02+c*t.m12+i*t.m22,d=o.X*t.m00+o.Y*t.m10+o.Z*t.m20,b=o.X*t.m01+o.Y*t.m11+o.Z*t.m21,g=o.X*t.m02+o.Y*t.m12+o.Z*t.m22,v=(r*t.m00+e*t.m10+n*t.m20)*(d/l),p=(r*t.m01+e*t.m11+n*t.m21)*(b/h),m=(r*t.m02+e*t.m12+n*t.m22)*(g/s),y=v*a.m00+p*a.m10+m*a.m20,w=v*a.m01+p*a.m11+m*a.m21,k=v*a.m02+p*a.m12+m*a.m22;return[255*z(y*f.m00+w*f.m10+k*f.m20),255*z(y*f.m01+w*f.m11+k*f.m21),255*z(y*f.m02+w*f.m12+k*f.m22)]},V=Math.sin,D=Math.cos,T=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lch"),t=n[0],a=n[1],f=n[2];return isNaN(f)&&(f=0),[t,D(f*=m)*a,V(f)*a]},H=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=(r=i(r,"lch"))[0],t=r[1],a=r[2],f=T(n,t,a),o=f[0],u=f[1],c=f[2],l=I(o,u,c);return[l[0],l[1],l[2],r.length>3?r[3]:1]},J=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t,a=(r=i(r,"lab"))[0],f=r[1],o=r[2],u=r.slice(3),c=(n=[[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],t=X([[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]],[a,f,o]),X(n,t.map((function(r){return Math.pow(r,3)})))),l=c[0],h=c[1],s=c[2],d=U(l,h,s);return[d[0],d[1],d[2]].concat(u.length>0&&u[0]<1?[u[0]]:[])};var Q=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=(r=i(r,"lch"))[0],t=r[1],a=r[2],f=r.slice(3),o=T(n,t,a),u=o[0],c=o[1],l=o[2],h=J(u,c,l);return[h[0],h[1],h[2]].concat(f.length>0&&f[0]<1?[f[0]]:[])},rr=/((?:-?\d+)|(?:-?\d+(?:\.\d+)?)%|none)/.source,er=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%?)|none)/.source,nr=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%)|none)/.source,tr=/\s*/.source,ar=/\s+/.source,fr=/\s*,\s*/.source,or=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:deg)?)|none)/.source,ur=/\s*(?:\/\s*((?:[01]|[01]?\.\d+)|\d+(?:\.\d+)?%))?/.source,cr=new RegExp("^rgba?\\("+tr+[rr,rr,rr].join(ar)+ur+"\\)$"),ir=new RegExp("^rgb\\("+tr+[rr,rr,rr].join(fr)+tr+"\\)$"),lr=new RegExp("^rgba\\("+tr+[rr,rr,rr,er].join(fr)+tr+"\\)$"),hr=new RegExp("^hsla?\\("+tr+[or,nr,nr].join(ar)+ur+"\\)$"),sr=new RegExp("^hsl?\\("+tr+[or,nr,nr].join(fr)+tr+"\\)$"),dr=/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,br=new RegExp("^lab\\("+tr+[er,er,er].join(ar)+ur+"\\)$"),gr=new RegExp("^lch\\("+tr+[er,er,or].join(ar)+ur+"\\)$"),vr=new RegExp("^oklab\\("+tr+[er,er,er].join(ar)+ur+"\\)$"),pr=new RegExp("^oklch\\("+tr+[er,er,or].join(ar)+ur+"\\)$"),mr=Math.round,yr=function(r){return r.map((function(r,e){return e<=2?n(mr(r),0,255):r}))},wr=function(r,e,n,t){return void 0===e&&(e=0),void 0===n&&(n=100),void 0===t&&(t=!1),"string"==typeof r&&r.endsWith("%")&&(r=parseFloat(r.substring(0,r.length-1))/100,r=t?e+.5*(r+1)*(n-e):e+r*(n-e)),+r},kr=function(r,e){return"none"===r?e:r},Mr=function(r){var e;if(r=r.toLowerCase().trim(),w.format.named)try{return w.format.named(r)}catch(r){}if((e=r.match(cr))||(e=r.match(ir))){for(var n=e.slice(1,4),t=0;t<3;t++)n[t]=+wr(kr(n[t],0),0,255);n=yr(n);var a=void 0!==e[4]?+wr(e[4],0,1):1;return n[3]=a,n}if(e=r.match(lr)){for(var f=e.slice(1,5),o=0;o<4;o++)f[o]=+wr(f[o],0,255);return f}if((e=r.match(hr))||(e=r.match(sr))){var u=e.slice(1,4);u[0]=+kr(u[0].replace("deg",""),0),u[1]=.01*+wr(kr(u[1],0),0,100),u[2]=.01*+wr(kr(u[2],0),0,100);var c=yr(W(u)),i=void 0!==e[4]?+wr(e[4],0,1):1;return c[3]=i,c}if(e=r.match(dr)){var l=e.slice(1,4);l[1]*=.01,l[2]*=.01;for(var h=W(l),s=0;s<3;s++)h[s]=mr(h[s]);return h[3]=+e[4],h}if(e=r.match(br)){var d=e.slice(1,4);d[0]=wr(kr(d[0],0),0,100),d[1]=wr(kr(d[1],0),-125,125,!0),d[2]=wr(kr(d[2],0),-125,125,!0);var b=R();E("d50");var g=yr(I(d));E(b);var v=void 0!==e[4]?+wr(e[4],0,1):1;return g[3]=v,g}if(e=r.match(gr)){var p=e.slice(1,4);p[0]=wr(p[0],0,100),p[1]=wr(kr(p[1],0),0,150,!1),p[2]=+kr(p[2].replace("deg",""),0);var m=R();E("d50");var y=yr(H(p));E(m);var k=void 0!==e[4]?+wr(e[4],0,1):1;return y[3]=k,y}if(e=r.match(vr)){var M=e.slice(1,4);M[0]=wr(kr(M[0],0),0,1),M[1]=wr(kr(M[1],0),-.4,.4,!0),M[2]=wr(kr(M[2],0),-.4,.4,!0);var x=yr(J(M)),N=void 0!==e[4]?+wr(e[4],0,1):1;return x[3]=N,x}if(e=r.match(pr)){var _=e.slice(1,4);_[0]=wr(kr(_[0],0),0,1),_[1]=wr(kr(_[1],0),0,.4,!1),_[2]=+kr(_[2].replace("deg",""),0);var j=yr(Q(_)),A=void 0!==e[4]?+wr(e[4],0,1):1;return j[3]=A,j}};Mr.test=function(r){return cr.test(r)||hr.test(r)||br.test(r)||gr.test(r)||vr.test(r)||pr.test(r)||ir.test(r)||lr.test(r)||sr.test(r)||dr.test(r)},k.prototype.css=function(r){return S(this._rgb,r)};var xr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["css"])))};M.css=xr,w.format.css=Mr,w.autodetect.push({p:5,test:function(r){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];if(!e.length&&"string"===c(r)&&Mr.test(r))return"css"}}),w.format.gl=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgba");return n[0]*=255,n[1]*=255,n[2]*=255,n};var Nr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["gl"])))};M.gl=Nr,k.prototype.gl=function(){var r=this._rgb;return[r[0]/255,r[1]/255,r[2]/255,r[3]]};var _r=Math.floor;k.prototype.hcg=function(){return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t=i(r,"rgb"),a=t[0],f=t[1],o=t[2],u=s(a,f,o),c=d(a,f,o),l=c-u,h=100*l/255,b=u/(255-l)*100;return 0===l?n=Number.NaN:(a===c&&(n=(f-o)/l),f===c&&(n=2+(o-a)/l),o===c&&(n=4+(a-f)/l),(n*=60)<0&&(n+=360)),[n,h,b]}(this._rgb)};var jr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hcg"])))};M.hcg=jr,w.format.hcg=function(){for(var r,e,n,t,a,f,o=[],u=arguments.length;u--;)o[u]=arguments[u];var c,l,h,s=(o=i(o,"hcg"))[0],d=o[1],b=o[2];b*=255;var g=255*d;if(0===d)c=l=h=b;else{360===s&&(s=0),s>360&&(s-=360),s<0&&(s+=360);var v=_r(s/=60),p=s-v,m=b*(1-d),y=m+g*(1-p),w=m+g*p,k=m+g;switch(v){case 0:c=(r=[k,w,m])[0],l=r[1],h=r[2];break;case 1:c=(e=[y,k,m])[0],l=e[1],h=e[2];break;case 2:c=(n=[m,k,w])[0],l=n[1],h=n[2];break;case 3:c=(t=[m,y,k])[0],l=t[1],h=t[2];break;case 4:c=(a=[w,m,k])[0],l=a[1],h=a[2];break;case 5:c=(f=[k,m,y])[0],l=f[1],h=f[2]}}return[c,l,h,o.length>3?o[3]:1]},w.autodetect.push({p:1,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"hcg"))&&3===r.length)return"hcg"}});var Ar=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,Er=/^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/,Rr=function(r){if(r.match(Ar)){4!==r.length&&7!==r.length||(r=r.substr(1)),3===r.length&&(r=(r=r.split(""))[0]+r[0]+r[1]+r[1]+r[2]+r[2]);var e=parseInt(r,16);return[e>>16,e>>8&255,255&e,1]}if(r.match(Er)){5!==r.length&&9!==r.length||(r=r.substr(1)),4===r.length&&(r=(r=r.split(""))[0]+r[0]+r[1]+r[1]+r[2]+r[2]+r[3]+r[3]);var n=parseInt(r,16);return[n>>24&255,n>>16&255,n>>8&255,Math.round((255&n)/255*100)/100]}throw new Error("unknown hex color: "+r)},Or=Math.round,Pr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgba"),t=n[0],a=n[1],f=n[2],o=n[3],u=l(r)||"auto";void 0===o&&(o=1),"auto"===u&&(u=o<1?"rgba":"rgb");var c="000000"+((t=Or(t))<<16|(a=Or(a))<<8|(f=Or(f))).toString(16);c=c.substr(c.length-6);var h="0"+Or(255*o).toString(16);switch(h=h.substr(h.length-2),u.toLowerCase()){case"rgba":return"#"+c+h;case"argb":return"#"+h+c;default:return"#"+c}};k.prototype.hex=function(r){return Pr(this._rgb,r)};var Fr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hex"])))};M.hex=Fr,w.format.hex=Rr,w.autodetect.push({p:4,test:function(r){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];if(!e.length&&"string"===c(r)&&[3,4,5,6,7,8,9].indexOf(r.length)>=0)return"hex"}});var Lr=Math.cos,Br=Math.min,Gr=Math.sqrt,Yr=Math.acos;k.prototype.hsi=function(){return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t=i(r,"rgb"),a=t[0],f=t[1],o=t[2],u=Br(a/=255,f/=255,o/=255),c=(a+f+o)/3,l=c>0?1-u/c:0;return 0===l?n=NaN:(n=(a-f+(a-o))/2,n/=Gr((a-f)*(a-f)+(a-o)*(f-o)),n=Yr(n),o>f&&(n=v-n),n/=v),[360*n,l,c]}(this._rgb)};var qr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsi"])))};M.hsi=qr,w.format.hsi=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var t,a,f,o=(r=i(r,"hsi"))[0],u=r[1],c=r[2];return isNaN(o)&&(o=0),isNaN(u)&&(u=0),o>360&&(o-=360),o<0&&(o+=360),(o/=360)<1/3?a=1-((f=(1-u)/3)+(t=(1+u*Lr(v*o)/Lr(p-v*o))/3)):o<2/3?f=1-((t=(1-u)/3)+(a=(1+u*Lr(v*(o-=1/3))/Lr(p-v*o))/3)):t=1-((a=(1-u)/3)+(f=(1+u*Lr(v*(o-=2/3))/Lr(p-v*o))/3)),[255*(t=n(c*t*3)),255*(a=n(c*a*3)),255*(f=n(c*f*3)),r.length>3?r[3]:1]},w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"hsi"))&&3===r.length)return"hsi"}}),k.prototype.hsl=function(){return _(this._rgb)};var Xr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsl"])))};M.hsl=Xr,w.format.hsl=W,w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"hsl"))&&3===r.length)return"hsl"}});var Cr=Math.floor,Zr=Math.min,$r=Math.max;k.prototype.hsv=function(){return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t,a,f=(r=i(r,"rgb"))[0],o=r[1],u=r[2],c=Zr(f,o,u),l=$r(f,o,u),h=l-c;return a=l/255,0===l?(n=Number.NaN,t=0):(t=h/l,f===l&&(n=(o-u)/h),o===l&&(n=2+(u-f)/h),u===l&&(n=4+(f-o)/h),(n*=60)<0&&(n+=360)),[n,t,a]}(this._rgb)};var Sr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsv"])))};M.hsv=Sr,w.format.hsv=function(){for(var r,e,n,t,a,f,o=[],u=arguments.length;u--;)o[u]=arguments[u];var c,l,h,s=(o=i(o,"hsv"))[0],d=o[1],b=o[2];if(b*=255,0===d)c=l=h=b;else{360===s&&(s=0),s>360&&(s-=360),s<0&&(s+=360);var g=Cr(s/=60),v=s-g,p=b*(1-d),m=b*(1-d*v),y=b*(1-d*(1-v));switch(g){case 0:c=(r=[b,y,p])[0],l=r[1],h=r[2];break;case 1:c=(e=[m,b,p])[0],l=e[1],h=e[2];break;case 2:c=(n=[p,b,y])[0],l=n[1],h=n[2];break;case 3:c=(t=[p,m,b])[0],l=t[1],h=t[2];break;case 4:c=(a=[y,p,b])[0],l=a[1],h=a[2];break;case 5:c=(f=[b,p,m])[0],l=f[1],h=f[2]}}return[c,l,h,o.length>3?o[3]:1]},w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"hsv"))&&3===r.length)return"hsv"}}),k.prototype.lab=function(){return O(this._rgb)};var Wr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["lab"])))};Object.assign(M,{lab:Wr,getLabWhitePoint:R,setLabWhitePoint:E}),w.format.lab=I,w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"lab"))&&3===r.length)return"lab"}});k.prototype.lch=function(){return q(this._rgb)},k.prototype.hcl=function(){return q(this._rgb).reverse()};var Ir=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["lch"])))},Kr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hcl"])))};Object.assign(M,{lch:Ir,hcl:Kr}),w.format.lch=H,w.format.hcl=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"hcl").reverse();return H.apply(void 0,n)},["lch","hcl"].forEach((function(r){return w.autodetect.push({p:2,test:function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];if("array"===c(e=i(e,r))&&3===e.length)return r}})}));k.prototype.num=function(){return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgb");return(n[0]<<16)+(n[1]<<8)+n[2]}(this._rgb)};var zr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["num"])))};Object.assign(M,{num:zr}),w.format.num=function(r){if("number"==c(r)&&r>=0&&r<=16777215)return[r>>16,r>>8&255,255&r,1];throw new Error("unknown num color: "+r)},w.autodetect.push({p:5,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if(1===r.length&&"number"===c(r[0])&&r[0]>=0&&r[0]<=16777215)return"num"}});var Ur=Math.round;k.prototype.rgb=function(r){return void 0===r&&(r=!0),!1===r?this._rgb.slice(0,3):this._rgb.slice(0,3).map(Ur)},k.prototype.rgba=function(r){return void 0===r&&(r=!0),this._rgb.slice(0,4).map((function(e,n){return n<3?!1===r?e:Ur(e):e}))};var Vr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["rgb"])))};Object.assign(M,{rgb:Vr}),w.format.rgb=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgba");return void 0===n[3]&&(n[3]=1),n},w.autodetect.push({p:3,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"rgba"))&&(3===r.length||4===r.length&&"number"==c(r[3])&&r[3]>=0&&r[3]<=1))return"rgb"}});var Dr=Math.log,Tr=function(r){var e,n,t,a=r/100;return a<66?(e=255,n=a<6?0:-155.25485562709179-.44596950469579133*(n=a-2)+104.49216199393888*Dr(n),t=a<20?0:.8274096064007395*(t=a-10)-254.76935184120902+115.67994401066147*Dr(t)):(e=351.97690566805693+.114206453784165*(e=a-55)-40.25366309332127*Dr(e),n=325.4494125711974+.07943456536662342*(n=a-50)-28.0852963507957*Dr(n),t=255),[e,n,t,1]},Hr=Math.round;k.prototype.temp=k.prototype.kelvin=k.prototype.temperature=function(){return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];for(var n,t=i(r,"rgb"),a=t[0],f=t[2],o=1e3,u=4e4;u-o>.4;){var c=Tr(n=.5*(u+o));c[2]/c[0]>=f/a?u=n:o=n}return Hr(n)}(this._rgb)};var Jr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["temp"])))};Object.assign(M,{temp:Jr,kelvin:Jr,temperature:Jr}),w.format.temp=w.format.kelvin=w.format.temperature=Tr,k.prototype.oklab=function(){return C(this._rgb)};var Qr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["oklab"])))};Object.assign(M,{oklab:Qr}),w.format.oklab=J,w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"oklab"))&&3===r.length)return"oklab"}}),k.prototype.oklch=function(){return Z(this._rgb)};var re=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["oklch"])))};Object.assign(M,{oklch:re}),w.format.oklch=Q,w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"oklch"))&&3===r.length)return"oklch"}});var ee={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",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",laserlemon:"#ffff54",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrod:"#fafad2",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",maroon2:"#7f0000",maroon3:"#b03060",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",purple2:"#7f007f",purple3:"#a020f0",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"};k.prototype.name=function(){for(var r=Pr(this._rgb,"rgb"),e=0,n=Object.keys(ee);e0;)e[n]=arguments[n+1];if(!e.length&&"string"===c(r)&&ee[r.toLowerCase()])return"named"}}),k.prototype.alpha=function(r,e){return void 0===e&&(e=!1),void 0!==r&&"number"===c(r)?e?(this._rgb[3]=r,this):new k([this._rgb[0],this._rgb[1],this._rgb[2],r],"rgb"):this._rgb[3]},k.prototype.clipped=function(){return this._rgb._clipped||!1},k.prototype.darken=function(r){void 0===r&&(r=1);var e=this.lab();return e[0]-=j.Kn*r,new k(e,"lab").alpha(this.alpha(),!0)},k.prototype.brighten=function(r){return void 0===r&&(r=1),this.darken(-r)},k.prototype.darker=k.prototype.darken,k.prototype.brighter=k.prototype.brighten,k.prototype.get=function(r){var e=r.split("."),n=e[0],t=e[1],a=this[n]();if(t){var f=n.indexOf(t)-("ok"===n.substr(0,2)?2:0);if(f>-1)return a[f];throw new Error("unknown channel "+t+" in mode "+n)}return a};var ne=Math.pow;k.prototype.luminance=function(r,e){if(void 0===e&&(e="rgb"),void 0!==r&&"number"===c(r)){if(0===r)return new k([0,0,0,this._rgb[3]],"rgb");if(1===r)return new k([255,255,255,this._rgb[3]],"rgb");var n=this.luminance(),t=20,a=function(n,f){var o=n.interpolate(f,.5,e),u=o.luminance();return Math.abs(r-u)<1e-7||!t--?o:u>r?a(n,o):a(o,f)},f=(n>r?a(new k([0,0,0]),this):a(this,new k([255,255,255]))).rgb();return new k(f.concat([this._rgb[3]]))}return te.apply(void 0,this._rgb.slice(0,3))};var te=function(r,e,n){return.2126*(r=ae(r))+.7152*(e=ae(e))+.0722*(n=ae(n))},ae=function(r){return(r/=255)<=.03928?r/12.92:ne((r+.055)/1.055,2.4)},fe={};function oe(r,e,n){void 0===n&&(n=.5);for(var t=[],a=arguments.length-3;a-- >0;)t[a]=arguments[a+3];var f=t[0]||"lrgb";if(fe[f]||t.length||(f=Object.keys(fe)[0]),!fe[f])throw new Error("interpolation mode "+f+" is not defined");return"object"!==c(r)&&(r=new k(r)),"object"!==c(e)&&(e=new k(e)),fe[f](r,e,n).alpha(r.alpha()+n*(e.alpha()-r.alpha()))}k.prototype.mix=k.prototype.interpolate=function(r,e){void 0===e&&(e=.5);for(var n=[],t=arguments.length-2;t-- >0;)n[t]=arguments[t+2];return oe.apply(void 0,[this,r,e].concat(n))},k.prototype.premultiply=function(r){void 0===r&&(r=!1);var e=this._rgb,n=e[3];return r?(this._rgb=[e[0]*n,e[1]*n,e[2]*n,n],this):new k([e[0]*n,e[1]*n,e[2]*n,n],"rgb")},k.prototype.saturate=function(r){void 0===r&&(r=1);var e=this.lch();return e[1]+=j.Kn*r,e[1]<0&&(e[1]=0),new k(e,"lch").alpha(this.alpha(),!0)},k.prototype.desaturate=function(r){return void 0===r&&(r=1),this.saturate(-r)},k.prototype.set=function(r,e,n){void 0===n&&(n=!1);var t=r.split("."),a=t[0],f=t[1],o=this[a]();if(f){var u=a.indexOf(f)-("ok"===a.substr(0,2)?2:0);if(u>-1){if("string"==c(e))switch(e.charAt(0)){case"+":case"-":o[u]+=+e;break;case"*":o[u]*=+e.substr(1);break;case"/":o[u]/=+e.substr(1);break;default:o[u]=+e}else{if("number"!==c(e))throw new Error("unsupported value for Color.set");o[u]=e}var i=new k(o,a);return n?(this._rgb=i._rgb,this):i}throw new Error("unknown channel "+f+" in mode "+a)}return o},k.prototype.tint=function(r){void 0===r&&(r=.5);for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return oe.apply(void 0,[this,"white",r].concat(e))},k.prototype.shade=function(r){void 0===r&&(r=.5);for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return oe.apply(void 0,[this,"black",r].concat(e))};fe.rgb=function(r,e,n){var t=r._rgb,a=e._rgb;return new k(t[0]+n*(a[0]-t[0]),t[1]+n*(a[1]-t[1]),t[2]+n*(a[2]-t[2]),"rgb")};var ue=Math.sqrt,ce=Math.pow;fe.lrgb=function(r,e,n){var t=r._rgb,a=t[0],f=t[1],o=t[2],u=e._rgb,c=u[0],i=u[1],l=u[2];return new k(ue(ce(a,2)*(1-n)+ce(c,2)*n),ue(ce(f,2)*(1-n)+ce(i,2)*n),ue(ce(o,2)*(1-n)+ce(l,2)*n),"rgb")};function ie(r,e,n,t){var a,f,o,u,c,i,l,h,s,d,b,g,v;return"hsl"===t?(o=r.hsl(),u=e.hsl()):"hsv"===t?(o=r.hsv(),u=e.hsv()):"hcg"===t?(o=r.hcg(),u=e.hcg()):"hsi"===t?(o=r.hsi(),u=e.hsi()):"lch"===t||"hcl"===t?(t="hcl",o=r.hcl(),u=e.hcl()):"oklch"===t&&(o=r.oklch().reverse(),u=e.oklch().reverse()),"h"!==t.substr(0,1)&&"oklch"!==t||(c=(a=o)[0],l=a[1],s=a[2],i=(f=u)[0],h=f[1],d=f[2]),isNaN(c)||isNaN(i)?isNaN(c)?isNaN(i)?g=Number.NaN:(g=i,1!=s&&0!=s||"hsv"==t||(b=h)):(g=c,1!=d&&0!=d||"hsv"==t||(b=l)):g=c+n*(i>c&&i-c>180?i-(c+360):i180?i+360-c:i-c),void 0===b&&(b=l+n*(h-l)),v=s+n*(d-s),new k("oklch"===t?[v,b,g]:[g,b,v],t)}fe.lab=function(r,e,n){var t=r.lab(),a=e.lab();return new k(t[0]+n*(a[0]-t[0]),t[1]+n*(a[1]-t[1]),t[2]+n*(a[2]-t[2]),"lab")};var le=function(r,e,n){return ie(r,e,n,"lch")};fe.lch=le,fe.hcl=le;fe.num=function(r,e,n){var t=r.num(),a=e.num();return new k(t+n*(a-t),"num")};fe.hcg=function(r,e,n){return ie(r,e,n,"hcg")};fe.hsi=function(r,e,n){return ie(r,e,n,"hsi")};fe.hsl=function(r,e,n){return ie(r,e,n,"hsl")};fe.hsv=function(r,e,n){return ie(r,e,n,"hsv")};fe.oklab=function(r,e,n){var t=r.oklab(),a=e.oklab();return new k(t[0]+n*(a[0]-t[0]),t[1]+n*(a[1]-t[1]),t[2]+n*(a[2]-t[2]),"oklab")};fe.oklch=function(r,e,n){return ie(r,e,n,"oklch")};var he=Math.pow,se=Math.sqrt,de=Math.PI,be=Math.cos,ge=Math.sin,ve=Math.atan2;var pe=function(r,e){for(var n=r.length,a=[0,0,0,0],f=0;f.9999999&&(a[3]=1),new k(t(a))},me=Math.pow;function ye(r){var e="rgb",t=M("#ccc"),a=0,f=[0,1],o=[],u=[0,0],i=!1,l=[],h=!1,s=0,d=1,b=!1,g={},v=!0,p=1,m=function(r){if((r=r||["#fff","#000"])&&"string"===c(r)&&M.brewer&&M.brewer[r.toLowerCase()]&&(r=M.brewer[r.toLowerCase()]),"array"===c(r)){1===r.length&&(r=[r[0],r[0]]),r=r.slice(0);for(var e=0;e2){var b=function(r){if(null!=i){for(var e=i.length-1,n=0;n=i[n];)n++;return n-1}return 0}(r);h=b/(i.length-2)}else h=d!==s?(r-s)/(d-s):1;h=w(h),a||(h=y(h)),1!==p&&(h=me(h,p)),h=n(h=u[0]+h*(1-u[0]-u[1]),0,1);var m=Math.floor(1e4*h);if(v&&g[m])f=g[m];else{if("array"===c(l))for(var k=0;k=x&&k===o.length-1){f=l[k];break}if(h>x&&h2){var c=r.map((function(e,n){return n/(r.length-1)})),i=r.map((function(r){return(r-s)/(d-s)}));i.every((function(r,e){return c[e]===r}))||(w=function(r){if(r<=0||r>=1)return r;for(var e=0;r>=i[e+1];)e++;var n=(r-i[e])/(i[e+1]-i[e]);return c[e]+n*(c[e+1]-c[e])})}}return f=[s,d],N},N.mode=function(r){return arguments.length?(e=r,x(),N):e},N.range=function(r,e){return m(r),N},N.out=function(r){return h=r,N},N.spread=function(r){return arguments.length?(a=r,N):a},N.correctLightness=function(r){return null==r&&(r=!0),b=r,x(),y=b?function(r){for(var e=k(0,!0).lab()[0],n=k(1,!0).lab()[0],t=e>n,a=k(r,!0).lab()[0],f=e+(n-e)*r,o=a-f,u=0,c=1,i=20;Math.abs(o)>.01&&i-- >0;)t&&(o*=-1),o<0?(u=r,r+=.5*(c-r)):(c=r,r+=.5*(u-r)),a=k(r,!0).lab()[0],o=a-f;return r}:function(r){return r},N},N.padding=function(r){return null!=r?("number"===c(r)&&(r=[r,r]),u=r,N):u},N.colors=function(e,n){arguments.length<2&&(n="hex");var t=[];if(0===arguments.length)t=l.slice(0);else if(1===e)t=[N(.5)];else if(e>1){var a=f[0],o=f[1]-a;t=function(r,e){for(var n=[],t=ra;t?f++:f--)n.push(f);return n}(0,e).map((function(r){return N(a+r/(e-1)*o)}))}else{r=[];var u=[];if(i&&i.length>2)for(var c=1,h=i.length,s=1<=h;s?ch;s?c++:c--)u.push(.5*(i[c-1]+i[c]));else u=f;t=u.map((function(r){return N(r)}))}return M[n]&&(t=t.map((function(r){return r[n]()}))),t},N.cache=function(r){return null!=r?(v=r,N):v},N.gamma=function(r){return null!=r?(p=r,N):p},N.nodata=function(r){return null!=r?(t=M(r),N):t},N}var we=function(r,e,n){if(!we[n])throw new Error("unknown blend mode "+n);return we[n](r,e)},ke=function(r){return function(e,n){var t=M(n).rgb(),a=M(e).rgb();return M.rgb(r(t,a))}},Me=function(r){return function(e,n){var t=[];return t[0]=r(e[0],n[0]),t[1]=r(e[1],n[1]),t[2]=r(e[2],n[2]),t}};we.normal=ke(Me((function(r){return r}))),we.multiply=ke(Me((function(r,e){return r*e/255}))),we.screen=ke(Me((function(r,e){return 255*(1-(1-r/255)*(1-e/255))}))),we.overlay=ke(Me((function(r,e){return e<128?2*r*e/255:255*(1-2*(1-r/255)*(1-e/255))}))),we.darken=ke(Me((function(r,e){return r>e?e:r}))),we.lighten=ke(Me((function(r,e){return r>e?r:e}))),we.dodge=ke(Me((function(r,e){return 255===r||(r=e/255*255/(1-r/255))>255?255:r}))),we.burn=ke(Me((function(r,e){return 255*(1-(1-e/255)/(r/255))})));var xe=Math.pow,Ne=Math.sin,_e=Math.cos;var je=Math.floor,Ae=Math.random;var Ee=Math.log,Re=Math.pow,Oe=Math.floor,Pe=Math.abs;function Fe(r,e){void 0===e&&(e=null);var n={min:Number.MAX_VALUE,max:-1*Number.MAX_VALUE,sum:0,values:[],count:0};return"object"===c(r)&&(r=Object.values(r)),r.forEach((function(r){e&&"object"===c(r)&&(r=r[e]),null==r||isNaN(r)||(n.values.push(r),n.sum+=r,rn.max&&(n.max=r),n.count+=1)})),n.domain=[n.min,n.max],n.limits=function(r,e){return Le(n,r,e)},n}function Le(r,e,n){void 0===e&&(e="equal"),void 0===n&&(n=7),"array"==c(r)&&(r=Fe(r));var t=r.min,a=r.max,f=r.values.sort((function(r,e){return r-e}));if(1===n)return[t,a];var o=[];if("c"===e.substr(0,1)&&(o.push(t),o.push(a)),"e"===e.substr(0,1)){o.push(t);for(var u=1;u 0");var i=Math.LOG10E*Ee(t),l=Math.LOG10E*Ee(a);o.push(t);for(var h=1;h200&&(w=!1)}for(var Y={},q=0;q=360;)b-=360;o[d]=b}else o[d]=o[d]/u[d];return s/=t,new k(o,e).alpha(s>.99999?1:s,!0)},bezier:function(r){var e=function(r){var e,n,t,a,f,o,u;if(2===(r=r.map((function(r){return new k(r)}))).length)e=r.map((function(r){return r.lab()})),f=e[0],o=e[1],a=function(r){var e=[0,1,2].map((function(e){return f[e]+r*(o[e]-f[e])}));return new k(e,"lab")};else if(3===r.length)n=r.map((function(r){return r.lab()})),f=n[0],o=n[1],u=n[2],a=function(r){var e=[0,1,2].map((function(e){return(1-r)*(1-r)*f[e]+2*(1-r)*r*o[e]+r*r*u[e]}));return new k(e,"lab")};else if(4===r.length){var c;t=r.map((function(r){return r.lab()})),f=t[0],o=t[1],u=t[2],c=t[3],a=function(r){var e=[0,1,2].map((function(e){return(1-r)*(1-r)*(1-r)*f[e]+3*(1-r)*(1-r)*r*o[e]+3*(1-r)*r*r*u[e]+r*r*r*c[e]}));return new k(e,"lab")}}else{if(!(r.length>=5))throw new RangeError("No point in running bezier with only one color.");var i,l,h;i=r.map((function(r){return r.lab()})),h=r.length-1,l=function(r){for(var e=[1,1],n=1;nt?(n+.05)/(t+.05):(t+.05)/(n+.05)},cubehelix:function(r,e,n,a,f){void 0===r&&(r=300),void 0===e&&(e=-1.5),void 0===n&&(n=1),void 0===a&&(a=1),void 0===f&&(f=[0,1]);var o,u=0;"array"===c(f)?o=f[1]-f[0]:(o=0,f=[f,f]);var i=function(c){var i=v*((r+120)/360+e*c),l=xe(f[0]+o*c,a),h=(0!==u?n[0]+c*u:n)*l*(1-l)/2,s=_e(i),d=Ne(i);return M(t([255*(l+h*(-.14861*s+1.78277*d)),255*(l+h*(-.29227*s-.90649*d)),255*(l+h*(1.97294*s)),1]))};return i.start=function(e){return null==e?r:(r=e,i)},i.rotations=function(r){return null==r?e:(e=r,i)},i.gamma=function(r){return null==r?a:(a=r,i)},i.hue=function(r){return null==r?n:("array"===c(n=r)?0===(u=n[1]-n[0])&&(n=n[1]):u=0,i)},i.lightness=function(r){return null==r?f:("array"===c(r)?(f=r,o=r[1]-r[0]):(f=[r,r],o=0),i)},i.scale=function(){return M.scale(i)},i.hue(n),i},deltaE:function(r,e,n,t,a){void 0===n&&(n=1),void 0===t&&(t=1),void 0===a&&(a=1);var f=function(r){return 360*r/(2*We)},o=function(r){return 2*We*r/360};r=new k(r),e=new k(e);var u=Array.from(r.lab()),c=u[0],i=u[1],l=u[2],h=Array.from(e.lab()),s=h[0],d=h[1],b=h[2],g=(c+s)/2,v=(Be(Ge(i,2)+Ge(l,2))+Be(Ge(d,2)+Ge(b,2)))/2,p=.5*(1-Be(Ge(v,7)/(Ge(v,7)+Ge(25,7)))),m=i*(1+p),y=d*(1+p),w=Be(Ge(m,2)+Ge(l,2)),M=Be(Ge(y,2)+Ge(b,2)),x=(w+M)/2,N=f(Xe(l,m)),_=f(Xe(b,y)),j=N>=0?N:N+360,A=_>=0?_:_+360,E=Ce(j-A)>180?(j+A+360)/2:(j+A)/2,R=1-.17*Ze(o(E-30))+.24*Ze(o(2*E))+.32*Ze(o(3*E+6))-.2*Ze(o(4*E-63)),O=A-j;O=Ce(O)<=180?O:A<=j?O+360:O-360,O=2*Be(w*M)*$e(o(O)/2);var P=s-c,F=M-w,L=1+.015*Ge(g-50,2)/Be(20+Ge(g-50,2)),B=1+.045*x,G=1+.015*x*R,Y=30*Se(-Ge((E-275)/25,2)),q=-(2*Be(Ge(x,7)/(Ge(x,7)+Ge(25,7))))*$e(2*o(Y)),X=Be(Ge(P/(n*L),2)+Ge(F/(t*B),2)+Ge(O/(a*G),2)+q*(F/(t*B))*(O/(a*G)));return qe(0,Ye(100,X))},distance:function(r,e,n){void 0===n&&(n="lab"),r=new k(r),e=new k(e);var t=r.get(n),a=e.get(n),f=0;for(var o in t){var u=(t[o]||0)-(a[o]||0);f+=u*u}return Math.sqrt(f)},input:w,interpolate:oe,limits:Le,mix:oe,random:function(){for(var r="#",e=0;e<6;e++)r+="0123456789abcdef".charAt(je(16*Ae()));return new k(r,"hex")},scale:ye,scales:Ie,valid:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];try{return new(Function.prototype.bind.apply(k,[null].concat(r))),!0}catch(r){return!1}},cmyk:N,css:xr,gl:Nr,hcg:jr,hex:Fr,hsi:qr,hsl:Xr,hsv:Sr,lab:Wr,lch:Ir,hcl:Kr,num:zr,rgb:Vr,temp:Jr,kelvin:Jr,temperature:Jr,oklab:Qr,oklch:re,getLabWhitePoint:R,setLabWhitePoint:E}),M})); +!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(r="undefined"!=typeof globalThis?globalThis:r||self).chroma=n()}(this,(function(){"use strict";var r=Math.min,n=Math.max;function e(e,t,a){return void 0===t&&(t=0),void 0===a&&(a=1),r(n(t,e),a)}function t(r){r._clipped=!1,r._unclipped=r.slice(0);for(var n=0;n<=3;n++)n<3?((r[n]<0||r[n]>255)&&(r._clipped=!0),r[n]=e(r[n],0,255)):3===n&&(r[n]=e(r[n],0,1));return r}for(var a={},f=0,o=["Boolean","Number","String","Function","Array","Date","RegExp","Undefined","Null"];f=3?Array.prototype.slice.call(r):"object"==c(r[0])&&n?n.split("").filter((function(n){return void 0!==r[0][n]})).map((function(n){return r[0][n]})):r[0].slice(0)}function l(r){if(r.length<2)return null;var n=r.length-1;return"string"==c(r[n])?r[n].toLowerCase():null}var h=Math.PI,s=Math.min,d=Math.max,b=function(r){return Math.round(100*r)/100},g=function(r){return Math.round(100*r)/100},v=2*h,p=h/3,m=h/180,y=180/h,w={format:{},autodetect:[]},k=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=this;if("object"===c(r[0])&&r[0].constructor&&r[0].constructor===this.constructor)return r[0];var a=l(r),f=!1;if(!a){f=!0,w.sorted||(w.autodetect=w.autodetect.sort((function(r,n){return n.p-r.p})),w.sorted=!0);for(var o=0,u=w.autodetect;o4?r[4]:1;return 1===f?[0,0,0,o]:[e>=1?0:255*(1-e)*(1-f),t>=1?0:255*(1-t)*(1-f),a>=1?0:255*(1-a)*(1-f),o]},w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"cmyk"))&&4===r.length)return"cmyk"}});var _=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t,a=(r=i(r,"rgba"))[0],f=r[1],o=r[2],u=s(a/=255,f/=255,o/=255),c=d(a,f,o),l=(c+u)/2;return c===u?(e=0,t=Number.NaN):e=l<.5?(c-u)/(c+u):(c-u)/(2-c-u),a==c?t=(f-o)/(c-u):f==c?t=2+(o-a)/(c-u):o==c&&(t=4+(a-f)/(c-u)),(t*=60)<0&&(t+=360),r.length>3&&void 0!==r[3]?[t,e,l,r[3]]:[t,e,l]},A={Kn:18,labWhitePoint:"d65",Xn:.95047,Yn:1,Zn:1.08883,t0:.137931034,t1:.206896552,t2:.12841855,t3:.008856452,kE:216/24389,kKE:8,kK:24389/27,RefWhiteRGB:{X:.95047,Y:1,Z:1.08883},MtxRGB2XYZ:{m00:.4124564390896922,m01:.21267285140562253,m02:.0193338955823293,m10:.357576077643909,m11:.715152155287818,m12:.11919202588130297,m20:.18043748326639894,m21:.07217499330655958,m22:.9503040785363679},MtxXYZ2RGB:{m00:3.2404541621141045,m01:-.9692660305051868,m02:.055643430959114726,m10:-1.5371385127977166,m11:1.8760108454466942,m12:-.2040259135167538,m20:-.498531409556016,m21:.041556017530349834,m22:1.0572251882231791},As:.9414285350000001,Bs:1.040417467,Cs:1.089532651,MtxAdaptMa:{m00:.8951,m01:-.7502,m02:.0389,m10:.2664,m11:1.7135,m12:-.0685,m20:-.1614,m21:.0367,m22:1.0296},MtxAdaptMaI:{m00:.9869929054667123,m01:.43230526972339456,m02:-.008528664575177328,m10:-.14705425642099013,m11:.5183602715367776,m12:.04004282165408487,m20:.15996265166373125,m21:.0492912282128556,m22:.9684866957875502}},j=new Map([["a",[1.0985,.35585]],["b",[1.0985,.35585]],["c",[.98074,1.18232]],["d50",[.96422,.82521]],["d55",[.95682,.92149]],["d65",[.95047,1.08883]],["e",[1,1,1]],["f2",[.99186,.67393]],["f7",[.95041,1.08747]],["f11",[1.00962,.6435]],["icc",[.96422,.82521]]]);function E(r){var n=j.get(String(r).toLowerCase());if(!n)throw new Error("unknown Lab illuminant "+r);A.labWhitePoint=r,A.Xn=n[0],A.Zn=n[1]}function R(){return A.labWhitePoint}var O=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgb"),t=e[0],a=e[1],f=e[2],o=e.slice(3),u=F(t,a,f),c=function(r,n,e){var t=A.Xn,a=A.Yn,f=A.Zn,o=A.kE,u=A.kK,c=r/t,i=n/a,l=e/f,h=c>o?Math.pow(c,1/3):(u*c+16)/116,s=i>o?Math.pow(i,1/3):(u*i+16)/116,d=l>o?Math.pow(l,1/3):(u*l+16)/116;return[116*s-16,500*(h-s),200*(s-d)]}(u[0],u[1],u[2]);return[c[0],c[1],c[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])};function P(r){var n=Math.sign(r);return((r=Math.abs(r))<=.04045?r/12.92:Math.pow((r+.055)/1.055,2.4))*n}var F=function(r,n,e){r=P(r/255),n=P(n/255),e=P(e/255);var t=A.MtxRGB2XYZ,a=A.MtxAdaptMa,f=A.MtxAdaptMaI,o=A.Xn,u=A.Yn,c=A.Zn,i=A.As,l=A.Bs,h=A.Cs,s=r*t.m00+n*t.m10+e*t.m20,d=r*t.m01+n*t.m11+e*t.m21,b=r*t.m02+n*t.m12+e*t.m22,g=o*a.m00+u*a.m10+c*a.m20,v=o*a.m01+u*a.m11+c*a.m21,p=o*a.m02+u*a.m12+c*a.m22,m=s*a.m00+d*a.m10+b*a.m20,y=s*a.m01+d*a.m11+b*a.m21,w=s*a.m02+d*a.m12+b*a.m22;return y*=v/l,w*=p/h,[s=(m*=g/i)*f.m00+y*f.m10+w*f.m20,d=m*f.m01+y*f.m11+w*f.m21,b=m*f.m02+y*f.m12+w*f.m22]},L=Math.sqrt,B=Math.atan2,G=Math.round,Y=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lab"),t=e[0],a=e[1],f=e[2],o=L(a*a+f*f),u=(B(f,a)*y+360)%360;return 0===G(1e4*o)&&(u=Number.NaN),[t,o,u]},q=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgb"),t=e[0],a=e[1],f=e[2],o=e.slice(3),u=O(t,a,f),c=u[0],l=u[1],h=u[2],s=Y(c,l,h);return[s[0],s[1],s[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])};function C(r,n){var e=r.length;Array.isArray(r[0])||(r=[r]),Array.isArray(n[0])||(n=n.map((function(r){return[r]})));var t=n[0].length,a=n[0].map((function(r,e){return n.map((function(r){return r[e]}))})),f=r.map((function(r){return a.map((function(n){return Array.isArray(r)?r.reduce((function(r,e,t){return r+e*(n[t]||0)}),0):n.reduce((function(n,e){return n+e*r}),0)}))}));return 1===e&&(f=f[0]),1===t?f.map((function(r){return r[0]})):f}var X=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t,a=i(r,"rgb"),f=a[0],o=a[1],u=a[2],c=a.slice(3),l=F(f,o,u);return(e=[[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],t=C([[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.9292868615863434,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],l),C(e,t.map((function(r){return Math.cbrt(r)})))).concat(c.length>0&&c[0]<1?[c[0]]:[])};var Z=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgb"),t=e[0],a=e[1],f=e[2],o=e.slice(3),u=X(t,a,f),c=u[0],l=u[1],h=u[2],s=Y(c,l,h);return[s[0],s[1],s[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])},$=Math.round,S=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgba"),t=l(r)||"rgb";if("hsl"===t.substr(0,3))return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"hsla"),t=l(r)||"lsa";return e[0]=b(e[0]||0)+"deg",e[1]=b(100*e[1])+"%",e[2]=b(100*e[2])+"%","hsla"===t||e.length>3&&e[3]<1?(e[3]="/ "+(e.length>3?e[3]:1),t="hsla"):e.length=3,t.substr(0,3)+"("+e.join(" ")+")"}(_(e),t);if("lab"===t.substr(0,3)){var a=R();E("d50");var f=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lab"),t=l(r)||"lab";return e[0]=b(e[0])+"%",e[1]=b(e[1]),e[2]=b(e[2]),"laba"===t||e.length>3&&e[3]<1?e[3]="/ "+(e.length>3?e[3]:1):e.length=3,"lab("+e.join(" ")+")"}(O(e),t);return E(a),f}if("lch"===t.substr(0,3)){var o=R();E("d50");var u=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lch"),t=l(r)||"lab";return e[0]=b(e[0])+"%",e[1]=b(e[1]),e[2]=b(e[2])+"deg","lcha"===t||e.length>3&&e[3]<1?e[3]="/ "+(e.length>3?e[3]:1):e.length=3,"lch("+e.join(" ")+")"}(q(e),t);return E(o),u}return"oklab"===t.substr(0,5)?function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lab");return e[0]=b(100*e[0])+"%",e[1]=g(e[1]),e[2]=g(e[2]),e.length>3&&e[3]<1?e[3]="/ "+(e.length>3?e[3]:1):e.length=3,"oklab("+e.join(" ")+")"}(X(e)):"oklch"===t.substr(0,5)?function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lab");return e[0]=b(100*e[0])+"%",e[1]=g(e[1]),e[2]=b(e[2])+"deg",e.length>3&&e[3]<1?e[3]="/ "+(e.length>3?e[3]:1):e.length=3,"oklch("+e.join(" ")+")"}(Z(e)):(e[0]=$(e[0]),e[1]=$(e[1]),e[2]=$(e[2]),("rgba"===t||e.length>3&&e[3]<1)&&(e[3]="/ "+(e.length>3?e[3]:1),t="rgba"),t.substr(0,3)+"("+e.slice(0,"rgb"===t?3:4).join(" ")+")")},W=function(){for(var r,n=[],e=arguments.length;e--;)n[e]=arguments[e];var t,a,f,o=(n=i(n,"hsl"))[0],u=n[1],c=n[2];if(0===u)t=a=f=255*c;else{var l=[0,0,0],h=[0,0,0],s=c<.5?c*(1+u):c+u-c*u,d=2*c-s,b=o/360;l[0]=b+1/3,l[1]=b,l[2]=b-1/3;for(var g=0;g<3;g++)l[g]<0&&(l[g]+=1),l[g]>1&&(l[g]-=1),6*l[g]<1?h[g]=d+6*(s-d)*l[g]:2*l[g]<1?h[g]=s:3*l[g]<2?h[g]=d+(s-d)*(2/3-l[g])*6:h[g]=d;t=(r=[255*h[0],255*h[1],255*h[2]])[0],a=r[1],f=r[2]}return n.length>3?[t,a,f,n[3]]:[t,a,f,1]},I=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=(r=i(r,"lab"))[0],t=r[1],a=r[2],f=K(e,t,a),o=f[0],u=f[1],c=f[2],l=U(o,u,c);return[l[0],l[1],l[2],r.length>3?r[3]:1]},K=function(r,n,e){var t=A.kE,a=A.kK,f=A.kKE,o=A.Xn,u=A.Yn,c=A.Zn,i=(r+16)/116,l=.002*n+i,h=i-.005*e,s=l*l*l,d=h*h*h;return[(s>t?s:(116*l-16)/a)*o,(r>f?Math.pow((r+16)/116,3):r/a)*u,(d>t?d:(116*h-16)/a)*c]},z=function(r){var n=Math.sign(r);return((r=Math.abs(r))<=.0031308?12.92*r:1.055*Math.pow(r,1/2.4)-.055)*n},U=function(r,n,e){var t=A.MtxAdaptMa,a=A.MtxAdaptMaI,f=A.MtxXYZ2RGB,o=A.RefWhiteRGB,u=A.Xn,c=A.Yn,i=A.Zn,l=u*t.m00+c*t.m10+i*t.m20,h=u*t.m01+c*t.m11+i*t.m21,s=u*t.m02+c*t.m12+i*t.m22,d=o.X*t.m00+o.Y*t.m10+o.Z*t.m20,b=o.X*t.m01+o.Y*t.m11+o.Z*t.m21,g=o.X*t.m02+o.Y*t.m12+o.Z*t.m22,v=(r*t.m00+n*t.m10+e*t.m20)*(d/l),p=(r*t.m01+n*t.m11+e*t.m21)*(b/h),m=(r*t.m02+n*t.m12+e*t.m22)*(g/s),y=v*a.m00+p*a.m10+m*a.m20,w=v*a.m01+p*a.m11+m*a.m21,k=v*a.m02+p*a.m12+m*a.m22;return[255*z(y*f.m00+w*f.m10+k*f.m20),255*z(y*f.m01+w*f.m11+k*f.m21),255*z(y*f.m02+w*f.m12+k*f.m22)]},V=Math.sin,D=Math.cos,T=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lch"),t=e[0],a=e[1],f=e[2];return isNaN(f)&&(f=0),[t,D(f*=m)*a,V(f)*a]},H=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=(r=i(r,"lch"))[0],t=r[1],a=r[2],f=T(e,t,a),o=f[0],u=f[1],c=f[2],l=I(o,u,c);return[l[0],l[1],l[2],r.length>3?r[3]:1]},J=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t,a=(r=i(r,"lab"))[0],f=r[1],o=r[2],u=r.slice(3),c=(e=[[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],t=C([[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]],[a,f,o]),C(e,t.map((function(r){return Math.pow(r,3)})))),l=c[0],h=c[1],s=c[2],d=U(l,h,s);return[d[0],d[1],d[2]].concat(u.length>0&&u[0]<1?[u[0]]:[])};var Q=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=(r=i(r,"lch"))[0],t=r[1],a=r[2],f=r.slice(3),o=T(e,t,a),u=o[0],c=o[1],l=o[2],h=J(u,c,l);return[h[0],h[1],h[2]].concat(f.length>0&&f[0]<1?[f[0]]:[])},rr=/((?:-?\d+)|(?:-?\d+(?:\.\d+)?)%|none)/.source,nr=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%?)|none)/.source,er=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%)|none)/.source,tr=/\s*/.source,ar=/\s+/.source,fr=/\s*,\s*/.source,or=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:deg)?)|none)/.source,ur=/\s*(?:\/\s*((?:[01]|[01]?\.\d+)|\d+(?:\.\d+)?%))?/.source,cr=new RegExp("^rgba?\\("+tr+[rr,rr,rr].join(ar)+ur+"\\)$"),ir=new RegExp("^rgb\\("+tr+[rr,rr,rr].join(fr)+tr+"\\)$"),lr=new RegExp("^rgba\\("+tr+[rr,rr,rr,nr].join(fr)+tr+"\\)$"),hr=new RegExp("^hsla?\\("+tr+[or,er,er].join(ar)+ur+"\\)$"),sr=new RegExp("^hsl?\\("+tr+[or,er,er].join(fr)+tr+"\\)$"),dr=/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,br=new RegExp("^lab\\("+tr+[nr,nr,nr].join(ar)+ur+"\\)$"),gr=new RegExp("^lch\\("+tr+[nr,nr,or].join(ar)+ur+"\\)$"),vr=new RegExp("^oklab\\("+tr+[nr,nr,nr].join(ar)+ur+"\\)$"),pr=new RegExp("^oklch\\("+tr+[nr,nr,or].join(ar)+ur+"\\)$"),mr=Math.round,yr=function(r){return r.map((function(r,n){return n<=2?e(mr(r),0,255):r}))},wr=function(r,n,e,t){return void 0===n&&(n=0),void 0===e&&(e=100),void 0===t&&(t=!1),"string"==typeof r&&r.endsWith("%")&&(r=parseFloat(r.substring(0,r.length-1))/100,r=t?n+.5*(r+1)*(e-n):n+r*(e-n)),+r},kr=function(r,n){return"none"===r?n:r},Mr=function(r){var n;if(r=r.toLowerCase().trim(),w.format.named)try{return w.format.named(r)}catch(r){}if((n=r.match(cr))||(n=r.match(ir))){for(var e=n.slice(1,4),t=0;t<3;t++)e[t]=+wr(kr(e[t],0),0,255);e=yr(e);var a=void 0!==n[4]?+wr(n[4],0,1):1;return e[3]=a,e}if(n=r.match(lr)){for(var f=n.slice(1,5),o=0;o<4;o++)f[o]=+wr(f[o],0,255);return f}if((n=r.match(hr))||(n=r.match(sr))){var u=n.slice(1,4);u[0]=+kr(u[0].replace("deg",""),0),u[1]=.01*+wr(kr(u[1],0),0,100),u[2]=.01*+wr(kr(u[2],0),0,100);var c=yr(W(u)),i=void 0!==n[4]?+wr(n[4],0,1):1;return c[3]=i,c}if(n=r.match(dr)){var l=n.slice(1,4);l[1]*=.01,l[2]*=.01;for(var h=W(l),s=0;s<3;s++)h[s]=mr(h[s]);return h[3]=+n[4],h}if(n=r.match(br)){var d=n.slice(1,4);d[0]=wr(kr(d[0],0),0,100),d[1]=wr(kr(d[1],0),-125,125,!0),d[2]=wr(kr(d[2],0),-125,125,!0);var b=R();E("d50");var g=yr(I(d));E(b);var v=void 0!==n[4]?+wr(n[4],0,1):1;return g[3]=v,g}if(n=r.match(gr)){var p=n.slice(1,4);p[0]=wr(p[0],0,100),p[1]=wr(kr(p[1],0),0,150,!1),p[2]=+kr(p[2].replace("deg",""),0);var m=R();E("d50");var y=yr(H(p));E(m);var k=void 0!==n[4]?+wr(n[4],0,1):1;return y[3]=k,y}if(n=r.match(vr)){var M=n.slice(1,4);M[0]=wr(kr(M[0],0),0,1),M[1]=wr(kr(M[1],0),-.4,.4,!0),M[2]=wr(kr(M[2],0),-.4,.4,!0);var x=yr(J(M)),N=void 0!==n[4]?+wr(n[4],0,1):1;return x[3]=N,x}if(n=r.match(pr)){var _=n.slice(1,4);_[0]=wr(kr(_[0],0),0,1),_[1]=wr(kr(_[1],0),0,.4,!1),_[2]=+kr(_[2].replace("deg",""),0);var A=yr(Q(_)),j=void 0!==n[4]?+wr(n[4],0,1):1;return A[3]=j,A}};Mr.test=function(r){return cr.test(r)||hr.test(r)||br.test(r)||gr.test(r)||vr.test(r)||pr.test(r)||ir.test(r)||lr.test(r)||sr.test(r)||dr.test(r)},k.prototype.css=function(r){return S(this._rgb,r)};var xr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["css"])))};M.css=xr,w.format.css=Mr,w.autodetect.push({p:5,test:function(r){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];if(!n.length&&"string"===c(r)&&Mr.test(r))return"css"}}),w.format.gl=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgba");return e[0]*=255,e[1]*=255,e[2]*=255,e};var Nr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["gl"])))};M.gl=Nr,k.prototype.gl=function(){var r=this._rgb;return[r[0]/255,r[1]/255,r[2]/255,r[3]]};var _r=Math.floor;k.prototype.hcg=function(){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t=i(r,"rgb"),a=t[0],f=t[1],o=t[2],u=s(a,f,o),c=d(a,f,o),l=c-u,h=100*l/255,b=u/(255-l)*100;return 0===l?e=Number.NaN:(a===c&&(e=(f-o)/l),f===c&&(e=2+(o-a)/l),o===c&&(e=4+(a-f)/l),(e*=60)<0&&(e+=360)),[e,h,b]}(this._rgb)};var Ar=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hcg"])))};M.hcg=Ar,w.format.hcg=function(){for(var r,n,e,t,a,f,o=[],u=arguments.length;u--;)o[u]=arguments[u];var c,l,h,s=(o=i(o,"hcg"))[0],d=o[1],b=o[2];b*=255;var g=255*d;if(0===d)c=l=h=b;else{360===s&&(s=0),s>360&&(s-=360),s<0&&(s+=360);var v=_r(s/=60),p=s-v,m=b*(1-d),y=m+g*(1-p),w=m+g*p,k=m+g;switch(v){case 0:c=(r=[k,w,m])[0],l=r[1],h=r[2];break;case 1:c=(n=[y,k,m])[0],l=n[1],h=n[2];break;case 2:c=(e=[m,k,w])[0],l=e[1],h=e[2];break;case 3:c=(t=[m,y,k])[0],l=t[1],h=t[2];break;case 4:c=(a=[w,m,k])[0],l=a[1],h=a[2];break;case 5:c=(f=[k,m,y])[0],l=f[1],h=f[2]}}return[c,l,h,o.length>3?o[3]:1]},w.autodetect.push({p:1,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"hcg"))&&3===r.length)return"hcg"}});var jr=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,Er=/^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/,Rr=function(r){if(r.match(jr)){4!==r.length&&7!==r.length||(r=r.substr(1)),3===r.length&&(r=(r=r.split(""))[0]+r[0]+r[1]+r[1]+r[2]+r[2]);var n=parseInt(r,16);return[n>>16,n>>8&255,255&n,1]}if(r.match(Er)){5!==r.length&&9!==r.length||(r=r.substr(1)),4===r.length&&(r=(r=r.split(""))[0]+r[0]+r[1]+r[1]+r[2]+r[2]+r[3]+r[3]);var e=parseInt(r,16);return[e>>24&255,e>>16&255,e>>8&255,Math.round((255&e)/255*100)/100]}throw new Error("unknown hex color: "+r)},Or=Math.round,Pr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgba"),t=e[0],a=e[1],f=e[2],o=e[3],u=l(r)||"auto";void 0===o&&(o=1),"auto"===u&&(u=o<1?"rgba":"rgb");var c="000000"+((t=Or(t))<<16|(a=Or(a))<<8|(f=Or(f))).toString(16);c=c.substr(c.length-6);var h="0"+Or(255*o).toString(16);switch(h=h.substr(h.length-2),u.toLowerCase()){case"rgba":return"#"+c+h;case"argb":return"#"+h+c;default:return"#"+c}};k.prototype.hex=function(r){return Pr(this._rgb,r)};var Fr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hex"])))};M.hex=Fr,w.format.hex=Rr,w.autodetect.push({p:4,test:function(r){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];if(!n.length&&"string"===c(r)&&[3,4,5,6,7,8,9].indexOf(r.length)>=0)return"hex"}});var Lr=Math.cos,Br=Math.min,Gr=Math.sqrt,Yr=Math.acos;k.prototype.hsi=function(){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t=i(r,"rgb"),a=t[0],f=t[1],o=t[2],u=Br(a/=255,f/=255,o/=255),c=(a+f+o)/3,l=c>0?1-u/c:0;return 0===l?e=NaN:(e=(a-f+(a-o))/2,e/=Gr((a-f)*(a-f)+(a-o)*(f-o)),e=Yr(e),o>f&&(e=v-e),e/=v),[360*e,l,c]}(this._rgb)};var qr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsi"])))};M.hsi=qr,w.format.hsi=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var t,a,f,o=(r=i(r,"hsi"))[0],u=r[1],c=r[2];return isNaN(o)&&(o=0),isNaN(u)&&(u=0),o>360&&(o-=360),o<0&&(o+=360),(o/=360)<1/3?a=1-((f=(1-u)/3)+(t=(1+u*Lr(v*o)/Lr(p-v*o))/3)):o<2/3?f=1-((t=(1-u)/3)+(a=(1+u*Lr(v*(o-=1/3))/Lr(p-v*o))/3)):t=1-((a=(1-u)/3)+(f=(1+u*Lr(v*(o-=2/3))/Lr(p-v*o))/3)),[255*(t=e(c*t*3)),255*(a=e(c*a*3)),255*(f=e(c*f*3)),r.length>3?r[3]:1]},w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"hsi"))&&3===r.length)return"hsi"}}),k.prototype.hsl=function(){return _(this._rgb)};var Cr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsl"])))};M.hsl=Cr,w.format.hsl=W,w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"hsl"))&&3===r.length)return"hsl"}});var Xr=Math.floor,Zr=Math.min,$r=Math.max;k.prototype.hsv=function(){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t,a,f=(r=i(r,"rgb"))[0],o=r[1],u=r[2],c=Zr(f,o,u),l=$r(f,o,u),h=l-c;return a=l/255,0===l?(e=Number.NaN,t=0):(t=h/l,f===l&&(e=(o-u)/h),o===l&&(e=2+(u-f)/h),u===l&&(e=4+(f-o)/h),(e*=60)<0&&(e+=360)),[e,t,a]}(this._rgb)};var Sr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsv"])))};M.hsv=Sr,w.format.hsv=function(){for(var r,n,e,t,a,f,o=[],u=arguments.length;u--;)o[u]=arguments[u];var c,l,h,s=(o=i(o,"hsv"))[0],d=o[1],b=o[2];if(b*=255,0===d)c=l=h=b;else{360===s&&(s=0),s>360&&(s-=360),s<0&&(s+=360);var g=Xr(s/=60),v=s-g,p=b*(1-d),m=b*(1-d*v),y=b*(1-d*(1-v));switch(g){case 0:c=(r=[b,y,p])[0],l=r[1],h=r[2];break;case 1:c=(n=[m,b,p])[0],l=n[1],h=n[2];break;case 2:c=(e=[p,b,y])[0],l=e[1],h=e[2];break;case 3:c=(t=[p,m,b])[0],l=t[1],h=t[2];break;case 4:c=(a=[y,p,b])[0],l=a[1],h=a[2];break;case 5:c=(f=[b,p,m])[0],l=f[1],h=f[2]}}return[c,l,h,o.length>3?o[3]:1]},w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"hsv"))&&3===r.length)return"hsv"}}),k.prototype.lab=function(){return O(this._rgb)};var Wr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["lab"])))};Object.assign(M,{lab:Wr,getLabWhitePoint:R,setLabWhitePoint:E}),w.format.lab=I,w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"lab"))&&3===r.length)return"lab"}});k.prototype.lch=function(){return q(this._rgb)},k.prototype.hcl=function(){return q(this._rgb).reverse()};var Ir=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["lch"])))},Kr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hcl"])))};Object.assign(M,{lch:Ir,hcl:Kr}),w.format.lch=H,w.format.hcl=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"hcl").reverse();return H.apply(void 0,e)},["lch","hcl"].forEach((function(r){return w.autodetect.push({p:2,test:function(){for(var n=[],e=arguments.length;e--;)n[e]=arguments[e];if("array"===c(n=i(n,r))&&3===n.length)return r}})}));k.prototype.num=function(){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgb");return(e[0]<<16)+(e[1]<<8)+e[2]}(this._rgb)};var zr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["num"])))};Object.assign(M,{num:zr}),w.format.num=function(r){if("number"==c(r)&&r>=0&&r<=16777215)return[r>>16,r>>8&255,255&r,1];throw new Error("unknown num color: "+r)},w.autodetect.push({p:5,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if(1===r.length&&"number"===c(r[0])&&r[0]>=0&&r[0]<=16777215)return"num"}});var Ur=Math.round;k.prototype.rgb=function(r){return void 0===r&&(r=!0),!1===r?this._rgb.slice(0,3):this._rgb.slice(0,3).map(Ur)},k.prototype.rgba=function(r){return void 0===r&&(r=!0),this._rgb.slice(0,4).map((function(n,e){return e<3?!1===r?n:Ur(n):n}))};var Vr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["rgb"])))};Object.assign(M,{rgb:Vr}),w.format.rgb=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgba");return void 0===e[3]&&(e[3]=1),e},w.autodetect.push({p:3,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"rgba"))&&(3===r.length||4===r.length&&"number"==c(r[3])&&r[3]>=0&&r[3]<=1))return"rgb"}});var Dr=Math.log,Tr=function(r){var n,e,t,a=r/100;return a<66?(n=255,e=a<6?0:-155.25485562709179-.44596950469579133*(e=a-2)+104.49216199393888*Dr(e),t=a<20?0:.8274096064007395*(t=a-10)-254.76935184120902+115.67994401066147*Dr(t)):(n=351.97690566805693+.114206453784165*(n=a-55)-40.25366309332127*Dr(n),e=325.4494125711974+.07943456536662342*(e=a-50)-28.0852963507957*Dr(e),t=255),[n,e,t,1]},Hr=Math.round;k.prototype.temp=k.prototype.kelvin=k.prototype.temperature=function(){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];for(var e,t=i(r,"rgb"),a=t[0],f=t[2],o=1e3,u=4e4;u-o>.4;){var c=Tr(e=.5*(u+o));c[2]/c[0]>=f/a?u=e:o=e}return Hr(e)}(this._rgb)};var Jr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["temp"])))};Object.assign(M,{temp:Jr,kelvin:Jr,temperature:Jr}),w.format.temp=w.format.kelvin=w.format.temperature=Tr,k.prototype.oklab=function(){return X(this._rgb)};var Qr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["oklab"])))};Object.assign(M,{oklab:Qr}),w.format.oklab=J,w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"oklab"))&&3===r.length)return"oklab"}}),k.prototype.oklch=function(){return Z(this._rgb)};var rn=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["oklch"])))};Object.assign(M,{oklch:rn}),w.format.oklch=Q,w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"oklch"))&&3===r.length)return"oklch"}});var nn={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",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",laserlemon:"#ffff54",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrod:"#fafad2",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",maroon2:"#7f0000",maroon3:"#b03060",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",purple2:"#7f007f",purple3:"#a020f0",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"};k.prototype.name=function(){for(var r=Pr(this._rgb,"rgb"),n=0,e=Object.keys(nn);n0;)n[e]=arguments[e+1];if(!n.length&&"string"===c(r)&&nn[r.toLowerCase()])return"named"}}),k.prototype.alpha=function(r,n){return void 0===n&&(n=!1),void 0!==r&&"number"===c(r)?n?(this._rgb[3]=r,this):new k([this._rgb[0],this._rgb[1],this._rgb[2],r],"rgb"):this._rgb[3]},k.prototype.clipped=function(){return this._rgb._clipped||!1},k.prototype.darken=function(r){void 0===r&&(r=1);var n=this.lab();return n[0]-=A.Kn*r,new k(n,"lab").alpha(this.alpha(),!0)},k.prototype.brighten=function(r){return void 0===r&&(r=1),this.darken(-r)},k.prototype.darker=k.prototype.darken,k.prototype.brighter=k.prototype.brighten,k.prototype.get=function(r){var n=r.split("."),e=n[0],t=n[1],a=this[e]();if(t){var f=e.indexOf(t)-("ok"===e.substr(0,2)?2:0);if(f>-1)return a[f];throw new Error("unknown channel "+t+" in mode "+e)}return a};var en=Math.pow;k.prototype.luminance=function(r,n){if(void 0===n&&(n="rgb"),void 0!==r&&"number"===c(r)){if(0===r)return new k([0,0,0,this._rgb[3]],"rgb");if(1===r)return new k([255,255,255,this._rgb[3]],"rgb");var e=this.luminance(),t=20,a=function(e,f){var o=e.interpolate(f,.5,n),u=o.luminance();return Math.abs(r-u)<1e-7||!t--?o:u>r?a(e,o):a(o,f)},f=(e>r?a(new k([0,0,0]),this):a(this,new k([255,255,255]))).rgb();return new k(f.concat([this._rgb[3]]))}return tn.apply(void 0,this._rgb.slice(0,3))};var tn=function(r,n,e){return.2126*(r=an(r))+.7152*(n=an(n))+.0722*(e=an(e))},an=function(r){return(r/=255)<=.03928?r/12.92:en((r+.055)/1.055,2.4)},fn={};function on(r,n,e){void 0===e&&(e=.5);for(var t=[],a=arguments.length-3;a-- >0;)t[a]=arguments[a+3];var f=t[0]||"lrgb";if(fn[f]||t.length||(f=Object.keys(fn)[0]),!fn[f])throw new Error("interpolation mode "+f+" is not defined");return"object"!==c(r)&&(r=new k(r)),"object"!==c(n)&&(n=new k(n)),fn[f](r,n,e).alpha(r.alpha()+e*(n.alpha()-r.alpha()))}k.prototype.mix=k.prototype.interpolate=function(r,n){void 0===n&&(n=.5);for(var e=[],t=arguments.length-2;t-- >0;)e[t]=arguments[t+2];return on.apply(void 0,[this,r,n].concat(e))},k.prototype.premultiply=function(r){void 0===r&&(r=!1);var n=this._rgb,e=n[3];return r?(this._rgb=[n[0]*e,n[1]*e,n[2]*e,e],this):new k([n[0]*e,n[1]*e,n[2]*e,e],"rgb")},k.prototype.saturate=function(r){void 0===r&&(r=1);var n=this.lch();return n[1]+=A.Kn*r,n[1]<0&&(n[1]=0),new k(n,"lch").alpha(this.alpha(),!0)},k.prototype.desaturate=function(r){return void 0===r&&(r=1),this.saturate(-r)},k.prototype.set=function(r,n,e){void 0===e&&(e=!1);var t=r.split("."),a=t[0],f=t[1],o=this[a]();if(f){var u=a.indexOf(f)-("ok"===a.substr(0,2)?2:0);if(u>-1){if("string"==c(n))switch(n.charAt(0)){case"+":case"-":o[u]+=+n;break;case"*":o[u]*=+n.substr(1);break;case"/":o[u]/=+n.substr(1);break;default:o[u]=+n}else{if("number"!==c(n))throw new Error("unsupported value for Color.set");o[u]=n}var i=new k(o,a);return e?(this._rgb=i._rgb,this):i}throw new Error("unknown channel "+f+" in mode "+a)}return o},k.prototype.tint=function(r){void 0===r&&(r=.5);for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return on.apply(void 0,[this,"white",r].concat(n))},k.prototype.shade=function(r){void 0===r&&(r=.5);for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return on.apply(void 0,[this,"black",r].concat(n))};fn.rgb=function(r,n,e){var t=r._rgb,a=n._rgb;return new k(t[0]+e*(a[0]-t[0]),t[1]+e*(a[1]-t[1]),t[2]+e*(a[2]-t[2]),"rgb")};var un=Math.sqrt,cn=Math.pow;fn.lrgb=function(r,n,e){var t=r._rgb,a=t[0],f=t[1],o=t[2],u=n._rgb,c=u[0],i=u[1],l=u[2];return new k(un(cn(a,2)*(1-e)+cn(c,2)*e),un(cn(f,2)*(1-e)+cn(i,2)*e),un(cn(o,2)*(1-e)+cn(l,2)*e),"rgb")};function ln(r,n,e,t){var a,f,o,u,c,i,l,h,s,d,b,g,v;return"hsl"===t?(o=r.hsl(),u=n.hsl()):"hsv"===t?(o=r.hsv(),u=n.hsv()):"hcg"===t?(o=r.hcg(),u=n.hcg()):"hsi"===t?(o=r.hsi(),u=n.hsi()):"lch"===t||"hcl"===t?(t="hcl",o=r.hcl(),u=n.hcl()):"oklch"===t&&(o=r.oklch().reverse(),u=n.oklch().reverse()),"h"!==t.substr(0,1)&&"oklch"!==t||(c=(a=o)[0],l=a[1],s=a[2],i=(f=u)[0],h=f[1],d=f[2]),isNaN(c)||isNaN(i)?isNaN(c)?isNaN(i)?g=Number.NaN:(g=i,1!=s&&0!=s||"hsv"==t||(b=h)):(g=c,1!=d&&0!=d||"hsv"==t||(b=l)):g=c+e*(i>c&&i-c>180?i-(c+360):i180?i+360-c:i-c),void 0===b&&(b=l+e*(h-l)),v=s+e*(d-s),new k("oklch"===t?[v,b,g]:[g,b,v],t)}fn.lab=function(r,n,e){var t=r.lab(),a=n.lab();return new k(t[0]+e*(a[0]-t[0]),t[1]+e*(a[1]-t[1]),t[2]+e*(a[2]-t[2]),"lab")};var hn=function(r,n,e){return ln(r,n,e,"lch")};fn.lch=hn,fn.hcl=hn;fn.num=function(r,n,e){var t=r.num(),a=n.num();return new k(t+e*(a-t),"num")};fn.hcg=function(r,n,e){return ln(r,n,e,"hcg")};fn.hsi=function(r,n,e){return ln(r,n,e,"hsi")};fn.hsl=function(r,n,e){return ln(r,n,e,"hsl")};fn.hsv=function(r,n,e){return ln(r,n,e,"hsv")};fn.oklab=function(r,n,e){var t=r.oklab(),a=n.oklab();return new k(t[0]+e*(a[0]-t[0]),t[1]+e*(a[1]-t[1]),t[2]+e*(a[2]-t[2]),"oklab")};fn.oklch=function(r,n,e){return ln(r,n,e,"oklch")};var sn=Math.pow,dn=Math.sqrt,bn=Math.PI,gn=Math.cos,vn=Math.sin,pn=Math.atan2;var mn=function(r,n){for(var e=r.length,a=[0,0,0,0],f=0;f.9999999&&(a[3]=1),new k(t(a))},yn=Math.pow;function wn(r){var n="rgb",t=M("#ccc"),a=0,f=[0,1],o=[],u=[0,0],i=!1,l=[],h=!1,s=0,d=1,b=!1,g={},v=!0,p=1,m=function(r){if((r=r||["#fff","#000"])&&"string"===c(r)&&M.brewer&&M.brewer[r.toLowerCase()]&&(r=M.brewer[r.toLowerCase()]),"array"===c(r)){1===r.length&&(r=[r[0],r[0]]),r=r.slice(0);for(var n=0;n2){var b=function(r){if(null!=i){for(var n=i.length-1,e=0;e=i[e];)e++;return e-1}return 0}(r);h=b/(i.length-2)}else h=d!==s?(r-s)/(d-s):1;h=w(h),a||(h=y(h)),1!==p&&(h=yn(h,p)),h=e(h=u[0]+h*(1-u[0]-u[1]),0,1);var m=Math.floor(1e4*h);if(v&&g[m])f=g[m];else{if("array"===c(l))for(var k=0;k=x&&k===o.length-1){f=l[k];break}if(h>x&&h2){var c=r.map((function(n,e){return e/(r.length-1)})),i=r.map((function(r){return(r-s)/(d-s)}));i.every((function(r,n){return c[n]===r}))||(w=function(r){if(r<=0||r>=1)return r;for(var n=0;r>=i[n+1];)n++;var e=(r-i[n])/(i[n+1]-i[n]);return c[n]+e*(c[n+1]-c[n])})}}return f=[s,d],N},N.mode=function(r){return arguments.length?(n=r,x(),N):n},N.range=function(r,n){return m(r),N},N.out=function(r){return h=r,N},N.spread=function(r){return arguments.length?(a=r,N):a},N.correctLightness=function(r){return null==r&&(r=!0),b=r,x(),y=b?function(r){for(var n=k(0,!0).lab()[0],e=k(1,!0).lab()[0],t=n>e,a=k(r,!0).lab()[0],f=n+(e-n)*r,o=a-f,u=0,c=1,i=20;Math.abs(o)>.01&&i-- >0;)t&&(o*=-1),o<0?(u=r,r+=.5*(c-r)):(c=r,r+=.5*(u-r)),a=k(r,!0).lab()[0],o=a-f;return r}:function(r){return r},N},N.padding=function(r){return null!=r?("number"===c(r)&&(r=[r,r]),u=r,N):u},N.colors=function(n,e){arguments.length<2&&(e="hex");var t=[];if(0===arguments.length)t=l.slice(0);else if(1===n)t=[N(.5)];else if(n>1){var a=f[0],o=f[1]-a;t=function(r,n){for(var e=[],t=ra;t?f++:f--)e.push(f);return e}(0,n).map((function(r){return N(a+r/(n-1)*o)}))}else{r=[];var u=[];if(i&&i.length>2)for(var c=1,h=i.length,s=1<=h;s?ch;s?c++:c--)u.push(.5*(i[c-1]+i[c]));else u=f;t=u.map((function(r){return N(r)}))}return M[e]&&(t=t.map((function(r){return r[e]()}))),t},N.cache=function(r){return null!=r?(v=r,N):v},N.gamma=function(r){return null!=r?(p=r,N):p},N.nodata=function(r){return null!=r?(t=M(r),N):t},N}var kn=function(r,n,e){if(!kn[e])throw new Error("unknown blend mode "+e);return kn[e](r,n)},Mn=function(r){return function(n,e){var t=M(e).rgb(),a=M(n).rgb();return M.rgb(r(t,a))}},xn=function(r){return function(n,e){var t=[];return t[0]=r(n[0],e[0]),t[1]=r(n[1],e[1]),t[2]=r(n[2],e[2]),t}};kn.normal=Mn(xn((function(r){return r}))),kn.multiply=Mn(xn((function(r,n){return r*n/255}))),kn.screen=Mn(xn((function(r,n){return 255*(1-(1-r/255)*(1-n/255))}))),kn.overlay=Mn(xn((function(r,n){return n<128?2*r*n/255:255*(1-2*(1-r/255)*(1-n/255))}))),kn.darken=Mn(xn((function(r,n){return r>n?n:r}))),kn.lighten=Mn(xn((function(r,n){return r>n?r:n}))),kn.dodge=Mn(xn((function(r,n){return 255===r||(r=n/255*255/(1-r/255))>255?255:r}))),kn.burn=Mn(xn((function(r,n){return 255*(1-(1-n/255)/(r/255))})));var Nn=Math.pow,_n=Math.sin,An=Math.cos;var jn=Math.floor,En=Math.random;var Rn=Math.log,On=Math.pow,Pn=Math.floor,Fn=Math.abs;function Ln(r,n){void 0===n&&(n=null);var e={min:Number.MAX_VALUE,max:-1*Number.MAX_VALUE,sum:0,values:[],count:0};return"object"===c(r)&&(r=Object.values(r)),r.forEach((function(r){n&&"object"===c(r)&&(r=r[n]),null==r||isNaN(r)||(e.values.push(r),e.sum+=r,re.max&&(e.max=r),e.count+=1)})),e.domain=[e.min,e.max],e.limits=function(r,n){return Bn(e,r,n)},e}function Bn(r,n,e){void 0===n&&(n="equal"),void 0===e&&(e=7),"array"==c(r)&&(r=Ln(r));var t=r.min,a=r.max,f=r.values.sort((function(r,n){return r-n}));if(1===e)return[t,a];var o=[];if("c"===n.substr(0,1)&&(o.push(t),o.push(a)),"e"===n.substr(0,1)){o.push(t);for(var u=1;u 0");var i=Math.LOG10E*Rn(t),l=Math.LOG10E*Rn(a);o.push(t);for(var h=1;h200&&(w=!1)}for(var Y={},q=0;q=360;)b-=360;o[d]=b}else o[d]=o[d]/u[d];return s/=t,new k(o,n).alpha(s>.99999?1:s,!0)},bezier:function(r){var n=function(r){var n,e,t,a,f,o,u;if(2===(r=r.map((function(r){return new k(r)}))).length)n=r.map((function(r){return r.lab()})),f=n[0],o=n[1],a=function(r){var n=[0,1,2].map((function(n){return f[n]+r*(o[n]-f[n])}));return new k(n,"lab")};else if(3===r.length)e=r.map((function(r){return r.lab()})),f=e[0],o=e[1],u=e[2],a=function(r){var n=[0,1,2].map((function(n){return(1-r)*(1-r)*f[n]+2*(1-r)*r*o[n]+r*r*u[n]}));return new k(n,"lab")};else if(4===r.length){var c;t=r.map((function(r){return r.lab()})),f=t[0],o=t[1],u=t[2],c=t[3],a=function(r){var n=[0,1,2].map((function(n){return(1-r)*(1-r)*(1-r)*f[n]+3*(1-r)*(1-r)*r*o[n]+3*(1-r)*r*r*u[n]+r*r*r*c[n]}));return new k(n,"lab")}}else{if(!(r.length>=5))throw new RangeError("No point in running bezier with only one color.");var i,l,h;i=r.map((function(r){return r.lab()})),h=r.length-1,l=function(r){for(var n=[1,1],e=1;et?(e+.05)/(t+.05):(t+.05)/(e+.05)},contrastAPCA:function(r,n){r=new k(r),n=new k(n),r.alpha()<1&&(r=on(n,r,r.alpha(),"rgb"));var e=Yn.apply(void 0,r.rgb()),t=Yn.apply(void 0,n.rgb()),a=e>=Gn?e:e+Math.pow(Gn-e,1.414),f=t>=Gn?t:t+Math.pow(Gn-t,1.414),o=Math.pow(f,.56)-Math.pow(a,.57),u=Math.pow(f,.65)-Math.pow(a,.62),c=Math.abs(f-a)<5e-4?0:a0?c-.027:c+.027)},cubehelix:function(r,n,e,a,f){void 0===r&&(r=300),void 0===n&&(n=-1.5),void 0===e&&(e=1),void 0===a&&(a=1),void 0===f&&(f=[0,1]);var o,u=0;"array"===c(f)?o=f[1]-f[0]:(o=0,f=[f,f]);var i=function(c){var i=v*((r+120)/360+n*c),l=Nn(f[0]+o*c,a),h=(0!==u?e[0]+c*u:e)*l*(1-l)/2,s=An(i),d=_n(i);return M(t([255*(l+h*(-.14861*s+1.78277*d)),255*(l+h*(-.29227*s-.90649*d)),255*(l+h*(1.97294*s)),1]))};return i.start=function(n){return null==n?r:(r=n,i)},i.rotations=function(r){return null==r?n:(n=r,i)},i.gamma=function(r){return null==r?a:(a=r,i)},i.hue=function(r){return null==r?e:("array"===c(e=r)?0===(u=e[1]-e[0])&&(e=e[1]):u=0,i)},i.lightness=function(r){return null==r?f:("array"===c(r)?(f=r,o=r[1]-r[0]):(f=[r,r],o=0),i)},i.scale=function(){return M.scale(i)},i.hue(e),i},deltaE:function(r,n,e,t,a){void 0===e&&(e=1),void 0===t&&(t=1),void 0===a&&(a=1);var f=function(r){return 360*r/(2*zn)},o=function(r){return 2*zn*r/360};r=new k(r),n=new k(n);var u=Array.from(r.lab()),c=u[0],i=u[1],l=u[2],h=Array.from(n.lab()),s=h[0],d=h[1],b=h[2],g=(c+s)/2,v=(qn(Cn(i,2)+Cn(l,2))+qn(Cn(d,2)+Cn(b,2)))/2,p=.5*(1-qn(Cn(v,7)/(Cn(v,7)+Cn(25,7)))),m=i*(1+p),y=d*(1+p),w=qn(Cn(m,2)+Cn(l,2)),M=qn(Cn(y,2)+Cn(b,2)),x=(w+M)/2,N=f($n(l,m)),_=f($n(b,y)),A=N>=0?N:N+360,j=_>=0?_:_+360,E=Sn(A-j)>180?(A+j+360)/2:(A+j)/2,R=1-.17*Wn(o(E-30))+.24*Wn(o(2*E))+.32*Wn(o(3*E+6))-.2*Wn(o(4*E-63)),O=j-A;O=Sn(O)<=180?O:j<=A?O+360:O-360,O=2*qn(w*M)*In(o(O)/2);var P=s-c,F=M-w,L=1+.015*Cn(g-50,2)/qn(20+Cn(g-50,2)),B=1+.045*x,G=1+.015*x*R,Y=30*Kn(-Cn((E-275)/25,2)),q=-(2*qn(Cn(x,7)/(Cn(x,7)+Cn(25,7))))*In(2*o(Y)),C=qn(Cn(P/(e*L),2)+Cn(F/(t*B),2)+Cn(O/(a*G),2)+q*(F/(t*B))*(O/(a*G)));return Zn(0,Xn(100,C))},distance:function(r,n,e){void 0===e&&(e="lab"),r=new k(r),n=new k(n);var t=r.get(e),a=n.get(e),f=0;for(var o in t){var u=(t[o]||0)-(a[o]||0);f+=u*u}return Math.sqrt(f)},input:w,interpolate:on,limits:Bn,mix:on,random:function(){for(var r="#",n=0;n<6;n++)r+="0123456789abcdef".charAt(jn(16*En()));return new k(r,"hex")},scale:wn,scales:Un,valid:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];try{return new(Function.prototype.bind.apply(k,[null].concat(r))),!0}catch(r){return!1}},cmyk:N,css:xr,gl:Nr,hcg:Ar,hex:Fr,hsi:qr,hsl:Cr,hsv:Sr,lab:Wr,lch:Ir,hcl:Kr,num:zr,rgb:Vr,temp:Jr,kelvin:Jr,temperature:Jr,oklab:Qr,oklch:rn,getLabWhitePoint:R,setLabWhitePoint:E}),M})); diff --git a/docs/index.html b/docs/index.html index a3f2c335..854588bd 100644 --- a/docs/index.html +++ b/docs/index.html @@ -256,6 +256,13 @@

(color1, color2)

// contrast greater than 4.5 = high enough chroma.contrast('pink', 'purple'); +

chroma.contrastAPCA

+

(text, background)

+

New (3.1): Computes the APCA contrast ratio of a text color against its background color. The basic idea is that you check the contrast between the text and background color and then use this lookup table to find the minimum font size you're allowed to use (given the font weight and purpose of the text).

+
chroma.contrastAPCA('hotpink', 'pink');
+chroma.contrastAPCA('purple', 'pink');
+
+

Read more about how to interpret and use this metric at APCA Readability Criterion. Please note that the APCA algorithm is still in beta and may change be subject to changes in the future.

chroma.distance

(color1, color2, mode='lab')

Computes the Euclidean distance between two colors in a given color space (default is Lab).

@@ -1007,7 +1014,7 @@

1.0.0

[ 'background-color:' + (isCSS ? val : col.hex()), 'color:' + (l < 0.7 ? 'white' : 'black'), - 'opacity:' + col.alpha() + ...(isCSS ? [] : ['opacity:' + col.alpha()]) ].join(';') ); diff --git a/docs/libs/chroma.cjs b/docs/libs/chroma.cjs index ffedf6db..d618ccfc 100644 --- a/docs/libs/chroma.cjs +++ b/docs/libs/chroma.cjs @@ -3687,6 +3687,71 @@ return l1 > l2 ? (l1 + 0.05) / (l2 + 0.05) : (l2 + 0.05) / (l1 + 0.05); } + /** + * @license + * + * The APCA contrast prediction algorithm is based of the formulas published + * in the APCA-1.0.98G specification by Myndex. The specification is available at: + * https://raw.githubusercontent.com/Myndex/apca-w3/master/images/APCAw3_0.1.17_APCA0.0.98G.svg + * + * Note that the APCA implementation is still beta, so please update to + * future versions of chroma.js when they become available. + * + * You can read more about the APCA Readability Criterion at + * https://readtech.org/ARC/ + */ + + // constants + var W_offset = 0.027; + var P_in = 0.0005; + var P_out = 0.1; + var R_scale = 1.14; + var B_threshold = 0.022; + var B_exp = 1.414; + + function contrastAPCA (text, bg) { + // parse input colors + text = new Color(text); + bg = new Color(bg); + // if text color has alpha, blend against background + if (text.alpha() < 1) { + text = mix(bg, text, text.alpha(), 'rgb'); + } + var l_text = lum.apply(void 0, text.rgb()); + var l_bg = lum.apply(void 0, bg.rgb()); + + // soft clamp black levels + var Y_text = + l_text >= B_threshold + ? l_text + : l_text + Math.pow(B_threshold - l_text, B_exp); + var Y_bg = + l_bg >= B_threshold ? l_bg : l_bg + Math.pow(B_threshold - l_bg, B_exp); + + // normal polarity (dark text on light background) + var S_norm = Math.pow(Y_bg, 0.56) - Math.pow(Y_text, 0.57); + // reverse polarity (light text on dark background) + var S_rev = Math.pow(Y_bg, 0.65) - Math.pow(Y_text, 0.62); + // clamp noise then scale + var C = + Math.abs(Y_bg - Y_text) < P_in + ? 0 + : Y_text < Y_bg + ? S_norm * R_scale + : S_rev * R_scale; + // clamp minimum contrast then offset + var S_apc = Math.abs(C) < P_out ? 0 : C > 0 ? C - W_offset : C + W_offset; + // scale to 100 + return S_apc * 100; + } + function lum(r, g, b) { + return ( + 0.2126729 * Math.pow(r / 255, 2.4) + + 0.7151522 * Math.pow(g / 255, 2.4) + + 0.072175 * Math.pow(b / 255, 2.4) + ); + } + var sqrt = Math.sqrt; var pow = Math.pow; var min = Math.min; @@ -3904,6 +3969,7 @@ Color: Color, colors: w3cx11, contrast: contrast, + contrastAPCA: contrastAPCA, cubehelix: cubehelix, deltaE: deltaE, distance: distance, diff --git a/docs/libs/chroma.min.cjs b/docs/libs/chroma.min.cjs index 2e50806f..d7407ce0 100644 --- a/docs/libs/chroma.min.cjs +++ b/docs/libs/chroma.min.cjs @@ -55,4 +55,18 @@ * @preserve */ -!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(r="undefined"!=typeof globalThis?globalThis:r||self).chroma=e()}(this,(function(){"use strict";var r=Math.min,e=Math.max;function n(n,t,a){return void 0===t&&(t=0),void 0===a&&(a=1),r(e(t,n),a)}function t(r){r._clipped=!1,r._unclipped=r.slice(0);for(var e=0;e<=3;e++)e<3?((r[e]<0||r[e]>255)&&(r._clipped=!0),r[e]=n(r[e],0,255)):3===e&&(r[e]=n(r[e],0,1));return r}for(var a={},f=0,o=["Boolean","Number","String","Function","Array","Date","RegExp","Undefined","Null"];f=3?Array.prototype.slice.call(r):"object"==c(r[0])&&e?e.split("").filter((function(e){return void 0!==r[0][e]})).map((function(e){return r[0][e]})):r[0].slice(0)}function l(r){if(r.length<2)return null;var e=r.length-1;return"string"==c(r[e])?r[e].toLowerCase():null}var h=Math.PI,s=Math.min,d=Math.max,b=function(r){return Math.round(100*r)/100},g=function(r){return Math.round(100*r)/100},v=2*h,p=h/3,m=h/180,y=180/h,w={format:{},autodetect:[]},k=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=this;if("object"===c(r[0])&&r[0].constructor&&r[0].constructor===this.constructor)return r[0];var a=l(r),f=!1;if(!a){f=!0,w.sorted||(w.autodetect=w.autodetect.sort((function(r,e){return e.p-r.p})),w.sorted=!0);for(var o=0,u=w.autodetect;o4?r[4]:1;return 1===f?[0,0,0,o]:[n>=1?0:255*(1-n)*(1-f),t>=1?0:255*(1-t)*(1-f),a>=1?0:255*(1-a)*(1-f),o]},w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"cmyk"))&&4===r.length)return"cmyk"}});var _=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t,a=(r=i(r,"rgba"))[0],f=r[1],o=r[2],u=s(a/=255,f/=255,o/=255),c=d(a,f,o),l=(c+u)/2;return c===u?(n=0,t=Number.NaN):n=l<.5?(c-u)/(c+u):(c-u)/(2-c-u),a==c?t=(f-o)/(c-u):f==c?t=2+(o-a)/(c-u):o==c&&(t=4+(a-f)/(c-u)),(t*=60)<0&&(t+=360),r.length>3&&void 0!==r[3]?[t,n,l,r[3]]:[t,n,l]},j={Kn:18,labWhitePoint:"d65",Xn:.95047,Yn:1,Zn:1.08883,t0:.137931034,t1:.206896552,t2:.12841855,t3:.008856452,kE:216/24389,kKE:8,kK:24389/27,RefWhiteRGB:{X:.95047,Y:1,Z:1.08883},MtxRGB2XYZ:{m00:.4124564390896922,m01:.21267285140562253,m02:.0193338955823293,m10:.357576077643909,m11:.715152155287818,m12:.11919202588130297,m20:.18043748326639894,m21:.07217499330655958,m22:.9503040785363679},MtxXYZ2RGB:{m00:3.2404541621141045,m01:-.9692660305051868,m02:.055643430959114726,m10:-1.5371385127977166,m11:1.8760108454466942,m12:-.2040259135167538,m20:-.498531409556016,m21:.041556017530349834,m22:1.0572251882231791},As:.9414285350000001,Bs:1.040417467,Cs:1.089532651,MtxAdaptMa:{m00:.8951,m01:-.7502,m02:.0389,m10:.2664,m11:1.7135,m12:-.0685,m20:-.1614,m21:.0367,m22:1.0296},MtxAdaptMaI:{m00:.9869929054667123,m01:.43230526972339456,m02:-.008528664575177328,m10:-.14705425642099013,m11:.5183602715367776,m12:.04004282165408487,m20:.15996265166373125,m21:.0492912282128556,m22:.9684866957875502}},A=new Map([["a",[1.0985,.35585]],["b",[1.0985,.35585]],["c",[.98074,1.18232]],["d50",[.96422,.82521]],["d55",[.95682,.92149]],["d65",[.95047,1.08883]],["e",[1,1,1]],["f2",[.99186,.67393]],["f7",[.95041,1.08747]],["f11",[1.00962,.6435]],["icc",[.96422,.82521]]]);function E(r){var e=A.get(String(r).toLowerCase());if(!e)throw new Error("unknown Lab illuminant "+r);j.labWhitePoint=r,j.Xn=e[0],j.Zn=e[1]}function R(){return j.labWhitePoint}var O=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgb"),t=n[0],a=n[1],f=n[2],o=n.slice(3),u=F(t,a,f),c=function(r,e,n){var t=j.Xn,a=j.Yn,f=j.Zn,o=j.kE,u=j.kK,c=r/t,i=e/a,l=n/f,h=c>o?Math.pow(c,1/3):(u*c+16)/116,s=i>o?Math.pow(i,1/3):(u*i+16)/116,d=l>o?Math.pow(l,1/3):(u*l+16)/116;return[116*s-16,500*(h-s),200*(s-d)]}(u[0],u[1],u[2]);return[c[0],c[1],c[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])};function P(r){var e=Math.sign(r);return((r=Math.abs(r))<=.04045?r/12.92:Math.pow((r+.055)/1.055,2.4))*e}var F=function(r,e,n){r=P(r/255),e=P(e/255),n=P(n/255);var t=j.MtxRGB2XYZ,a=j.MtxAdaptMa,f=j.MtxAdaptMaI,o=j.Xn,u=j.Yn,c=j.Zn,i=j.As,l=j.Bs,h=j.Cs,s=r*t.m00+e*t.m10+n*t.m20,d=r*t.m01+e*t.m11+n*t.m21,b=r*t.m02+e*t.m12+n*t.m22,g=o*a.m00+u*a.m10+c*a.m20,v=o*a.m01+u*a.m11+c*a.m21,p=o*a.m02+u*a.m12+c*a.m22,m=s*a.m00+d*a.m10+b*a.m20,y=s*a.m01+d*a.m11+b*a.m21,w=s*a.m02+d*a.m12+b*a.m22;return y*=v/l,w*=p/h,[s=(m*=g/i)*f.m00+y*f.m10+w*f.m20,d=m*f.m01+y*f.m11+w*f.m21,b=m*f.m02+y*f.m12+w*f.m22]},L=Math.sqrt,B=Math.atan2,G=Math.round,Y=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lab"),t=n[0],a=n[1],f=n[2],o=L(a*a+f*f),u=(B(f,a)*y+360)%360;return 0===G(1e4*o)&&(u=Number.NaN),[t,o,u]},q=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgb"),t=n[0],a=n[1],f=n[2],o=n.slice(3),u=O(t,a,f),c=u[0],l=u[1],h=u[2],s=Y(c,l,h);return[s[0],s[1],s[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])};function X(r,e){var n=r.length;Array.isArray(r[0])||(r=[r]),Array.isArray(e[0])||(e=e.map((function(r){return[r]})));var t=e[0].length,a=e[0].map((function(r,n){return e.map((function(r){return r[n]}))})),f=r.map((function(r){return a.map((function(e){return Array.isArray(r)?r.reduce((function(r,n,t){return r+n*(e[t]||0)}),0):e.reduce((function(e,n){return e+n*r}),0)}))}));return 1===n&&(f=f[0]),1===t?f.map((function(r){return r[0]})):f}var C=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t,a=i(r,"rgb"),f=a[0],o=a[1],u=a[2],c=a.slice(3),l=F(f,o,u);return(n=[[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],t=X([[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.9292868615863434,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],l),X(n,t.map((function(r){return Math.cbrt(r)})))).concat(c.length>0&&c[0]<1?[c[0]]:[])};var Z=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgb"),t=n[0],a=n[1],f=n[2],o=n.slice(3),u=C(t,a,f),c=u[0],l=u[1],h=u[2],s=Y(c,l,h);return[s[0],s[1],s[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])},$=Math.round,S=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgba"),t=l(r)||"rgb";if("hsl"===t.substr(0,3))return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"hsla"),t=l(r)||"lsa";return n[0]=b(n[0]||0)+"deg",n[1]=b(100*n[1])+"%",n[2]=b(100*n[2])+"%","hsla"===t||n.length>3&&n[3]<1?(n[3]="/ "+(n.length>3?n[3]:1),t="hsla"):n.length=3,t.substr(0,3)+"("+n.join(" ")+")"}(_(n),t);if("lab"===t.substr(0,3)){var a=R();E("d50");var f=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lab"),t=l(r)||"lab";return n[0]=b(n[0])+"%",n[1]=b(n[1]),n[2]=b(n[2]),"laba"===t||n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"lab("+n.join(" ")+")"}(O(n),t);return E(a),f}if("lch"===t.substr(0,3)){var o=R();E("d50");var u=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lch"),t=l(r)||"lab";return n[0]=b(n[0])+"%",n[1]=b(n[1]),n[2]=b(n[2])+"deg","lcha"===t||n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"lch("+n.join(" ")+")"}(q(n),t);return E(o),u}return"oklab"===t.substr(0,5)?function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lab");return n[0]=b(100*n[0])+"%",n[1]=g(n[1]),n[2]=g(n[2]),n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"oklab("+n.join(" ")+")"}(C(n)):"oklch"===t.substr(0,5)?function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lab");return n[0]=b(100*n[0])+"%",n[1]=g(n[1]),n[2]=b(n[2])+"deg",n.length>3&&n[3]<1?n[3]="/ "+(n.length>3?n[3]:1):n.length=3,"oklch("+n.join(" ")+")"}(Z(n)):(n[0]=$(n[0]),n[1]=$(n[1]),n[2]=$(n[2]),("rgba"===t||n.length>3&&n[3]<1)&&(n[3]="/ "+(n.length>3?n[3]:1),t="rgba"),t.substr(0,3)+"("+n.slice(0,"rgb"===t?3:4).join(" ")+")")},W=function(){for(var r,e=[],n=arguments.length;n--;)e[n]=arguments[n];var t,a,f,o=(e=i(e,"hsl"))[0],u=e[1],c=e[2];if(0===u)t=a=f=255*c;else{var l=[0,0,0],h=[0,0,0],s=c<.5?c*(1+u):c+u-c*u,d=2*c-s,b=o/360;l[0]=b+1/3,l[1]=b,l[2]=b-1/3;for(var g=0;g<3;g++)l[g]<0&&(l[g]+=1),l[g]>1&&(l[g]-=1),6*l[g]<1?h[g]=d+6*(s-d)*l[g]:2*l[g]<1?h[g]=s:3*l[g]<2?h[g]=d+(s-d)*(2/3-l[g])*6:h[g]=d;t=(r=[255*h[0],255*h[1],255*h[2]])[0],a=r[1],f=r[2]}return e.length>3?[t,a,f,e[3]]:[t,a,f,1]},I=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=(r=i(r,"lab"))[0],t=r[1],a=r[2],f=K(n,t,a),o=f[0],u=f[1],c=f[2],l=U(o,u,c);return[l[0],l[1],l[2],r.length>3?r[3]:1]},K=function(r,e,n){var t=j.kE,a=j.kK,f=j.kKE,o=j.Xn,u=j.Yn,c=j.Zn,i=(r+16)/116,l=.002*e+i,h=i-.005*n,s=l*l*l,d=h*h*h;return[(s>t?s:(116*l-16)/a)*o,(r>f?Math.pow((r+16)/116,3):r/a)*u,(d>t?d:(116*h-16)/a)*c]},z=function(r){var e=Math.sign(r);return((r=Math.abs(r))<=.0031308?12.92*r:1.055*Math.pow(r,1/2.4)-.055)*e},U=function(r,e,n){var t=j.MtxAdaptMa,a=j.MtxAdaptMaI,f=j.MtxXYZ2RGB,o=j.RefWhiteRGB,u=j.Xn,c=j.Yn,i=j.Zn,l=u*t.m00+c*t.m10+i*t.m20,h=u*t.m01+c*t.m11+i*t.m21,s=u*t.m02+c*t.m12+i*t.m22,d=o.X*t.m00+o.Y*t.m10+o.Z*t.m20,b=o.X*t.m01+o.Y*t.m11+o.Z*t.m21,g=o.X*t.m02+o.Y*t.m12+o.Z*t.m22,v=(r*t.m00+e*t.m10+n*t.m20)*(d/l),p=(r*t.m01+e*t.m11+n*t.m21)*(b/h),m=(r*t.m02+e*t.m12+n*t.m22)*(g/s),y=v*a.m00+p*a.m10+m*a.m20,w=v*a.m01+p*a.m11+m*a.m21,k=v*a.m02+p*a.m12+m*a.m22;return[255*z(y*f.m00+w*f.m10+k*f.m20),255*z(y*f.m01+w*f.m11+k*f.m21),255*z(y*f.m02+w*f.m12+k*f.m22)]},V=Math.sin,D=Math.cos,T=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"lch"),t=n[0],a=n[1],f=n[2];return isNaN(f)&&(f=0),[t,D(f*=m)*a,V(f)*a]},H=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=(r=i(r,"lch"))[0],t=r[1],a=r[2],f=T(n,t,a),o=f[0],u=f[1],c=f[2],l=I(o,u,c);return[l[0],l[1],l[2],r.length>3?r[3]:1]},J=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t,a=(r=i(r,"lab"))[0],f=r[1],o=r[2],u=r.slice(3),c=(n=[[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],t=X([[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]],[a,f,o]),X(n,t.map((function(r){return Math.pow(r,3)})))),l=c[0],h=c[1],s=c[2],d=U(l,h,s);return[d[0],d[1],d[2]].concat(u.length>0&&u[0]<1?[u[0]]:[])};var Q=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=(r=i(r,"lch"))[0],t=r[1],a=r[2],f=r.slice(3),o=T(n,t,a),u=o[0],c=o[1],l=o[2],h=J(u,c,l);return[h[0],h[1],h[2]].concat(f.length>0&&f[0]<1?[f[0]]:[])},rr=/((?:-?\d+)|(?:-?\d+(?:\.\d+)?)%|none)/.source,er=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%?)|none)/.source,nr=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%)|none)/.source,tr=/\s*/.source,ar=/\s+/.source,fr=/\s*,\s*/.source,or=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:deg)?)|none)/.source,ur=/\s*(?:\/\s*((?:[01]|[01]?\.\d+)|\d+(?:\.\d+)?%))?/.source,cr=new RegExp("^rgba?\\("+tr+[rr,rr,rr].join(ar)+ur+"\\)$"),ir=new RegExp("^rgb\\("+tr+[rr,rr,rr].join(fr)+tr+"\\)$"),lr=new RegExp("^rgba\\("+tr+[rr,rr,rr,er].join(fr)+tr+"\\)$"),hr=new RegExp("^hsla?\\("+tr+[or,nr,nr].join(ar)+ur+"\\)$"),sr=new RegExp("^hsl?\\("+tr+[or,nr,nr].join(fr)+tr+"\\)$"),dr=/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,br=new RegExp("^lab\\("+tr+[er,er,er].join(ar)+ur+"\\)$"),gr=new RegExp("^lch\\("+tr+[er,er,or].join(ar)+ur+"\\)$"),vr=new RegExp("^oklab\\("+tr+[er,er,er].join(ar)+ur+"\\)$"),pr=new RegExp("^oklch\\("+tr+[er,er,or].join(ar)+ur+"\\)$"),mr=Math.round,yr=function(r){return r.map((function(r,e){return e<=2?n(mr(r),0,255):r}))},wr=function(r,e,n,t){return void 0===e&&(e=0),void 0===n&&(n=100),void 0===t&&(t=!1),"string"==typeof r&&r.endsWith("%")&&(r=parseFloat(r.substring(0,r.length-1))/100,r=t?e+.5*(r+1)*(n-e):e+r*(n-e)),+r},kr=function(r,e){return"none"===r?e:r},Mr=function(r){var e;if(r=r.toLowerCase().trim(),w.format.named)try{return w.format.named(r)}catch(r){}if((e=r.match(cr))||(e=r.match(ir))){for(var n=e.slice(1,4),t=0;t<3;t++)n[t]=+wr(kr(n[t],0),0,255);n=yr(n);var a=void 0!==e[4]?+wr(e[4],0,1):1;return n[3]=a,n}if(e=r.match(lr)){for(var f=e.slice(1,5),o=0;o<4;o++)f[o]=+wr(f[o],0,255);return f}if((e=r.match(hr))||(e=r.match(sr))){var u=e.slice(1,4);u[0]=+kr(u[0].replace("deg",""),0),u[1]=.01*+wr(kr(u[1],0),0,100),u[2]=.01*+wr(kr(u[2],0),0,100);var c=yr(W(u)),i=void 0!==e[4]?+wr(e[4],0,1):1;return c[3]=i,c}if(e=r.match(dr)){var l=e.slice(1,4);l[1]*=.01,l[2]*=.01;for(var h=W(l),s=0;s<3;s++)h[s]=mr(h[s]);return h[3]=+e[4],h}if(e=r.match(br)){var d=e.slice(1,4);d[0]=wr(kr(d[0],0),0,100),d[1]=wr(kr(d[1],0),-125,125,!0),d[2]=wr(kr(d[2],0),-125,125,!0);var b=R();E("d50");var g=yr(I(d));E(b);var v=void 0!==e[4]?+wr(e[4],0,1):1;return g[3]=v,g}if(e=r.match(gr)){var p=e.slice(1,4);p[0]=wr(p[0],0,100),p[1]=wr(kr(p[1],0),0,150,!1),p[2]=+kr(p[2].replace("deg",""),0);var m=R();E("d50");var y=yr(H(p));E(m);var k=void 0!==e[4]?+wr(e[4],0,1):1;return y[3]=k,y}if(e=r.match(vr)){var M=e.slice(1,4);M[0]=wr(kr(M[0],0),0,1),M[1]=wr(kr(M[1],0),-.4,.4,!0),M[2]=wr(kr(M[2],0),-.4,.4,!0);var x=yr(J(M)),N=void 0!==e[4]?+wr(e[4],0,1):1;return x[3]=N,x}if(e=r.match(pr)){var _=e.slice(1,4);_[0]=wr(kr(_[0],0),0,1),_[1]=wr(kr(_[1],0),0,.4,!1),_[2]=+kr(_[2].replace("deg",""),0);var j=yr(Q(_)),A=void 0!==e[4]?+wr(e[4],0,1):1;return j[3]=A,j}};Mr.test=function(r){return cr.test(r)||hr.test(r)||br.test(r)||gr.test(r)||vr.test(r)||pr.test(r)||ir.test(r)||lr.test(r)||sr.test(r)||dr.test(r)},k.prototype.css=function(r){return S(this._rgb,r)};var xr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["css"])))};M.css=xr,w.format.css=Mr,w.autodetect.push({p:5,test:function(r){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];if(!e.length&&"string"===c(r)&&Mr.test(r))return"css"}}),w.format.gl=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgba");return n[0]*=255,n[1]*=255,n[2]*=255,n};var Nr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["gl"])))};M.gl=Nr,k.prototype.gl=function(){var r=this._rgb;return[r[0]/255,r[1]/255,r[2]/255,r[3]]};var _r=Math.floor;k.prototype.hcg=function(){return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t=i(r,"rgb"),a=t[0],f=t[1],o=t[2],u=s(a,f,o),c=d(a,f,o),l=c-u,h=100*l/255,b=u/(255-l)*100;return 0===l?n=Number.NaN:(a===c&&(n=(f-o)/l),f===c&&(n=2+(o-a)/l),o===c&&(n=4+(a-f)/l),(n*=60)<0&&(n+=360)),[n,h,b]}(this._rgb)};var jr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hcg"])))};M.hcg=jr,w.format.hcg=function(){for(var r,e,n,t,a,f,o=[],u=arguments.length;u--;)o[u]=arguments[u];var c,l,h,s=(o=i(o,"hcg"))[0],d=o[1],b=o[2];b*=255;var g=255*d;if(0===d)c=l=h=b;else{360===s&&(s=0),s>360&&(s-=360),s<0&&(s+=360);var v=_r(s/=60),p=s-v,m=b*(1-d),y=m+g*(1-p),w=m+g*p,k=m+g;switch(v){case 0:c=(r=[k,w,m])[0],l=r[1],h=r[2];break;case 1:c=(e=[y,k,m])[0],l=e[1],h=e[2];break;case 2:c=(n=[m,k,w])[0],l=n[1],h=n[2];break;case 3:c=(t=[m,y,k])[0],l=t[1],h=t[2];break;case 4:c=(a=[w,m,k])[0],l=a[1],h=a[2];break;case 5:c=(f=[k,m,y])[0],l=f[1],h=f[2]}}return[c,l,h,o.length>3?o[3]:1]},w.autodetect.push({p:1,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"hcg"))&&3===r.length)return"hcg"}});var Ar=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,Er=/^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/,Rr=function(r){if(r.match(Ar)){4!==r.length&&7!==r.length||(r=r.substr(1)),3===r.length&&(r=(r=r.split(""))[0]+r[0]+r[1]+r[1]+r[2]+r[2]);var e=parseInt(r,16);return[e>>16,e>>8&255,255&e,1]}if(r.match(Er)){5!==r.length&&9!==r.length||(r=r.substr(1)),4===r.length&&(r=(r=r.split(""))[0]+r[0]+r[1]+r[1]+r[2]+r[2]+r[3]+r[3]);var n=parseInt(r,16);return[n>>24&255,n>>16&255,n>>8&255,Math.round((255&n)/255*100)/100]}throw new Error("unknown hex color: "+r)},Or=Math.round,Pr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgba"),t=n[0],a=n[1],f=n[2],o=n[3],u=l(r)||"auto";void 0===o&&(o=1),"auto"===u&&(u=o<1?"rgba":"rgb");var c="000000"+((t=Or(t))<<16|(a=Or(a))<<8|(f=Or(f))).toString(16);c=c.substr(c.length-6);var h="0"+Or(255*o).toString(16);switch(h=h.substr(h.length-2),u.toLowerCase()){case"rgba":return"#"+c+h;case"argb":return"#"+h+c;default:return"#"+c}};k.prototype.hex=function(r){return Pr(this._rgb,r)};var Fr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hex"])))};M.hex=Fr,w.format.hex=Rr,w.autodetect.push({p:4,test:function(r){for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];if(!e.length&&"string"===c(r)&&[3,4,5,6,7,8,9].indexOf(r.length)>=0)return"hex"}});var Lr=Math.cos,Br=Math.min,Gr=Math.sqrt,Yr=Math.acos;k.prototype.hsi=function(){return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t=i(r,"rgb"),a=t[0],f=t[1],o=t[2],u=Br(a/=255,f/=255,o/=255),c=(a+f+o)/3,l=c>0?1-u/c:0;return 0===l?n=NaN:(n=(a-f+(a-o))/2,n/=Gr((a-f)*(a-f)+(a-o)*(f-o)),n=Yr(n),o>f&&(n=v-n),n/=v),[360*n,l,c]}(this._rgb)};var qr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsi"])))};M.hsi=qr,w.format.hsi=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var t,a,f,o=(r=i(r,"hsi"))[0],u=r[1],c=r[2];return isNaN(o)&&(o=0),isNaN(u)&&(u=0),o>360&&(o-=360),o<0&&(o+=360),(o/=360)<1/3?a=1-((f=(1-u)/3)+(t=(1+u*Lr(v*o)/Lr(p-v*o))/3)):o<2/3?f=1-((t=(1-u)/3)+(a=(1+u*Lr(v*(o-=1/3))/Lr(p-v*o))/3)):t=1-((a=(1-u)/3)+(f=(1+u*Lr(v*(o-=2/3))/Lr(p-v*o))/3)),[255*(t=n(c*t*3)),255*(a=n(c*a*3)),255*(f=n(c*f*3)),r.length>3?r[3]:1]},w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"hsi"))&&3===r.length)return"hsi"}}),k.prototype.hsl=function(){return _(this._rgb)};var Xr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsl"])))};M.hsl=Xr,w.format.hsl=W,w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"hsl"))&&3===r.length)return"hsl"}});var Cr=Math.floor,Zr=Math.min,$r=Math.max;k.prototype.hsv=function(){return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n,t,a,f=(r=i(r,"rgb"))[0],o=r[1],u=r[2],c=Zr(f,o,u),l=$r(f,o,u),h=l-c;return a=l/255,0===l?(n=Number.NaN,t=0):(t=h/l,f===l&&(n=(o-u)/h),o===l&&(n=2+(u-f)/h),u===l&&(n=4+(f-o)/h),(n*=60)<0&&(n+=360)),[n,t,a]}(this._rgb)};var Sr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsv"])))};M.hsv=Sr,w.format.hsv=function(){for(var r,e,n,t,a,f,o=[],u=arguments.length;u--;)o[u]=arguments[u];var c,l,h,s=(o=i(o,"hsv"))[0],d=o[1],b=o[2];if(b*=255,0===d)c=l=h=b;else{360===s&&(s=0),s>360&&(s-=360),s<0&&(s+=360);var g=Cr(s/=60),v=s-g,p=b*(1-d),m=b*(1-d*v),y=b*(1-d*(1-v));switch(g){case 0:c=(r=[b,y,p])[0],l=r[1],h=r[2];break;case 1:c=(e=[m,b,p])[0],l=e[1],h=e[2];break;case 2:c=(n=[p,b,y])[0],l=n[1],h=n[2];break;case 3:c=(t=[p,m,b])[0],l=t[1],h=t[2];break;case 4:c=(a=[y,p,b])[0],l=a[1],h=a[2];break;case 5:c=(f=[b,p,m])[0],l=f[1],h=f[2]}}return[c,l,h,o.length>3?o[3]:1]},w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"hsv"))&&3===r.length)return"hsv"}}),k.prototype.lab=function(){return O(this._rgb)};var Wr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["lab"])))};Object.assign(M,{lab:Wr,getLabWhitePoint:R,setLabWhitePoint:E}),w.format.lab=I,w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"lab"))&&3===r.length)return"lab"}});k.prototype.lch=function(){return q(this._rgb)},k.prototype.hcl=function(){return q(this._rgb).reverse()};var Ir=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["lch"])))},Kr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["hcl"])))};Object.assign(M,{lch:Ir,hcl:Kr}),w.format.lch=H,w.format.hcl=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"hcl").reverse();return H.apply(void 0,n)},["lch","hcl"].forEach((function(r){return w.autodetect.push({p:2,test:function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];if("array"===c(e=i(e,r))&&3===e.length)return r}})}));k.prototype.num=function(){return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgb");return(n[0]<<16)+(n[1]<<8)+n[2]}(this._rgb)};var zr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["num"])))};Object.assign(M,{num:zr}),w.format.num=function(r){if("number"==c(r)&&r>=0&&r<=16777215)return[r>>16,r>>8&255,255&r,1];throw new Error("unknown num color: "+r)},w.autodetect.push({p:5,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if(1===r.length&&"number"===c(r[0])&&r[0]>=0&&r[0]<=16777215)return"num"}});var Ur=Math.round;k.prototype.rgb=function(r){return void 0===r&&(r=!0),!1===r?this._rgb.slice(0,3):this._rgb.slice(0,3).map(Ur)},k.prototype.rgba=function(r){return void 0===r&&(r=!0),this._rgb.slice(0,4).map((function(e,n){return n<3?!1===r?e:Ur(e):e}))};var Vr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["rgb"])))};Object.assign(M,{rgb:Vr}),w.format.rgb=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];var n=i(r,"rgba");return void 0===n[3]&&(n[3]=1),n},w.autodetect.push({p:3,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"rgba"))&&(3===r.length||4===r.length&&"number"==c(r[3])&&r[3]>=0&&r[3]<=1))return"rgb"}});var Dr=Math.log,Tr=function(r){var e,n,t,a=r/100;return a<66?(e=255,n=a<6?0:-155.25485562709179-.44596950469579133*(n=a-2)+104.49216199393888*Dr(n),t=a<20?0:.8274096064007395*(t=a-10)-254.76935184120902+115.67994401066147*Dr(t)):(e=351.97690566805693+.114206453784165*(e=a-55)-40.25366309332127*Dr(e),n=325.4494125711974+.07943456536662342*(n=a-50)-28.0852963507957*Dr(n),t=255),[e,n,t,1]},Hr=Math.round;k.prototype.temp=k.prototype.kelvin=k.prototype.temperature=function(){return function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];for(var n,t=i(r,"rgb"),a=t[0],f=t[2],o=1e3,u=4e4;u-o>.4;){var c=Tr(n=.5*(u+o));c[2]/c[0]>=f/a?u=n:o=n}return Hr(n)}(this._rgb)};var Jr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["temp"])))};Object.assign(M,{temp:Jr,kelvin:Jr,temperature:Jr}),w.format.temp=w.format.kelvin=w.format.temperature=Tr,k.prototype.oklab=function(){return C(this._rgb)};var Qr=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["oklab"])))};Object.assign(M,{oklab:Qr}),w.format.oklab=J,w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"oklab"))&&3===r.length)return"oklab"}}),k.prototype.oklch=function(){return Z(this._rgb)};var re=function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];return new(Function.prototype.bind.apply(k,[null].concat(r,["oklch"])))};Object.assign(M,{oklch:re}),w.format.oklch=Q,w.autodetect.push({p:2,test:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];if("array"===c(r=i(r,"oklch"))&&3===r.length)return"oklch"}});var ee={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",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",laserlemon:"#ffff54",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrod:"#fafad2",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",maroon2:"#7f0000",maroon3:"#b03060",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",purple2:"#7f007f",purple3:"#a020f0",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"};k.prototype.name=function(){for(var r=Pr(this._rgb,"rgb"),e=0,n=Object.keys(ee);e0;)e[n]=arguments[n+1];if(!e.length&&"string"===c(r)&&ee[r.toLowerCase()])return"named"}}),k.prototype.alpha=function(r,e){return void 0===e&&(e=!1),void 0!==r&&"number"===c(r)?e?(this._rgb[3]=r,this):new k([this._rgb[0],this._rgb[1],this._rgb[2],r],"rgb"):this._rgb[3]},k.prototype.clipped=function(){return this._rgb._clipped||!1},k.prototype.darken=function(r){void 0===r&&(r=1);var e=this.lab();return e[0]-=j.Kn*r,new k(e,"lab").alpha(this.alpha(),!0)},k.prototype.brighten=function(r){return void 0===r&&(r=1),this.darken(-r)},k.prototype.darker=k.prototype.darken,k.prototype.brighter=k.prototype.brighten,k.prototype.get=function(r){var e=r.split("."),n=e[0],t=e[1],a=this[n]();if(t){var f=n.indexOf(t)-("ok"===n.substr(0,2)?2:0);if(f>-1)return a[f];throw new Error("unknown channel "+t+" in mode "+n)}return a};var ne=Math.pow;k.prototype.luminance=function(r,e){if(void 0===e&&(e="rgb"),void 0!==r&&"number"===c(r)){if(0===r)return new k([0,0,0,this._rgb[3]],"rgb");if(1===r)return new k([255,255,255,this._rgb[3]],"rgb");var n=this.luminance(),t=20,a=function(n,f){var o=n.interpolate(f,.5,e),u=o.luminance();return Math.abs(r-u)<1e-7||!t--?o:u>r?a(n,o):a(o,f)},f=(n>r?a(new k([0,0,0]),this):a(this,new k([255,255,255]))).rgb();return new k(f.concat([this._rgb[3]]))}return te.apply(void 0,this._rgb.slice(0,3))};var te=function(r,e,n){return.2126*(r=ae(r))+.7152*(e=ae(e))+.0722*(n=ae(n))},ae=function(r){return(r/=255)<=.03928?r/12.92:ne((r+.055)/1.055,2.4)},fe={};function oe(r,e,n){void 0===n&&(n=.5);for(var t=[],a=arguments.length-3;a-- >0;)t[a]=arguments[a+3];var f=t[0]||"lrgb";if(fe[f]||t.length||(f=Object.keys(fe)[0]),!fe[f])throw new Error("interpolation mode "+f+" is not defined");return"object"!==c(r)&&(r=new k(r)),"object"!==c(e)&&(e=new k(e)),fe[f](r,e,n).alpha(r.alpha()+n*(e.alpha()-r.alpha()))}k.prototype.mix=k.prototype.interpolate=function(r,e){void 0===e&&(e=.5);for(var n=[],t=arguments.length-2;t-- >0;)n[t]=arguments[t+2];return oe.apply(void 0,[this,r,e].concat(n))},k.prototype.premultiply=function(r){void 0===r&&(r=!1);var e=this._rgb,n=e[3];return r?(this._rgb=[e[0]*n,e[1]*n,e[2]*n,n],this):new k([e[0]*n,e[1]*n,e[2]*n,n],"rgb")},k.prototype.saturate=function(r){void 0===r&&(r=1);var e=this.lch();return e[1]+=j.Kn*r,e[1]<0&&(e[1]=0),new k(e,"lch").alpha(this.alpha(),!0)},k.prototype.desaturate=function(r){return void 0===r&&(r=1),this.saturate(-r)},k.prototype.set=function(r,e,n){void 0===n&&(n=!1);var t=r.split("."),a=t[0],f=t[1],o=this[a]();if(f){var u=a.indexOf(f)-("ok"===a.substr(0,2)?2:0);if(u>-1){if("string"==c(e))switch(e.charAt(0)){case"+":case"-":o[u]+=+e;break;case"*":o[u]*=+e.substr(1);break;case"/":o[u]/=+e.substr(1);break;default:o[u]=+e}else{if("number"!==c(e))throw new Error("unsupported value for Color.set");o[u]=e}var i=new k(o,a);return n?(this._rgb=i._rgb,this):i}throw new Error("unknown channel "+f+" in mode "+a)}return o},k.prototype.tint=function(r){void 0===r&&(r=.5);for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return oe.apply(void 0,[this,"white",r].concat(e))},k.prototype.shade=function(r){void 0===r&&(r=.5);for(var e=[],n=arguments.length-1;n-- >0;)e[n]=arguments[n+1];return oe.apply(void 0,[this,"black",r].concat(e))};fe.rgb=function(r,e,n){var t=r._rgb,a=e._rgb;return new k(t[0]+n*(a[0]-t[0]),t[1]+n*(a[1]-t[1]),t[2]+n*(a[2]-t[2]),"rgb")};var ue=Math.sqrt,ce=Math.pow;fe.lrgb=function(r,e,n){var t=r._rgb,a=t[0],f=t[1],o=t[2],u=e._rgb,c=u[0],i=u[1],l=u[2];return new k(ue(ce(a,2)*(1-n)+ce(c,2)*n),ue(ce(f,2)*(1-n)+ce(i,2)*n),ue(ce(o,2)*(1-n)+ce(l,2)*n),"rgb")};function ie(r,e,n,t){var a,f,o,u,c,i,l,h,s,d,b,g,v;return"hsl"===t?(o=r.hsl(),u=e.hsl()):"hsv"===t?(o=r.hsv(),u=e.hsv()):"hcg"===t?(o=r.hcg(),u=e.hcg()):"hsi"===t?(o=r.hsi(),u=e.hsi()):"lch"===t||"hcl"===t?(t="hcl",o=r.hcl(),u=e.hcl()):"oklch"===t&&(o=r.oklch().reverse(),u=e.oklch().reverse()),"h"!==t.substr(0,1)&&"oklch"!==t||(c=(a=o)[0],l=a[1],s=a[2],i=(f=u)[0],h=f[1],d=f[2]),isNaN(c)||isNaN(i)?isNaN(c)?isNaN(i)?g=Number.NaN:(g=i,1!=s&&0!=s||"hsv"==t||(b=h)):(g=c,1!=d&&0!=d||"hsv"==t||(b=l)):g=c+n*(i>c&&i-c>180?i-(c+360):i180?i+360-c:i-c),void 0===b&&(b=l+n*(h-l)),v=s+n*(d-s),new k("oklch"===t?[v,b,g]:[g,b,v],t)}fe.lab=function(r,e,n){var t=r.lab(),a=e.lab();return new k(t[0]+n*(a[0]-t[0]),t[1]+n*(a[1]-t[1]),t[2]+n*(a[2]-t[2]),"lab")};var le=function(r,e,n){return ie(r,e,n,"lch")};fe.lch=le,fe.hcl=le;fe.num=function(r,e,n){var t=r.num(),a=e.num();return new k(t+n*(a-t),"num")};fe.hcg=function(r,e,n){return ie(r,e,n,"hcg")};fe.hsi=function(r,e,n){return ie(r,e,n,"hsi")};fe.hsl=function(r,e,n){return ie(r,e,n,"hsl")};fe.hsv=function(r,e,n){return ie(r,e,n,"hsv")};fe.oklab=function(r,e,n){var t=r.oklab(),a=e.oklab();return new k(t[0]+n*(a[0]-t[0]),t[1]+n*(a[1]-t[1]),t[2]+n*(a[2]-t[2]),"oklab")};fe.oklch=function(r,e,n){return ie(r,e,n,"oklch")};var he=Math.pow,se=Math.sqrt,de=Math.PI,be=Math.cos,ge=Math.sin,ve=Math.atan2;var pe=function(r,e){for(var n=r.length,a=[0,0,0,0],f=0;f.9999999&&(a[3]=1),new k(t(a))},me=Math.pow;function ye(r){var e="rgb",t=M("#ccc"),a=0,f=[0,1],o=[],u=[0,0],i=!1,l=[],h=!1,s=0,d=1,b=!1,g={},v=!0,p=1,m=function(r){if((r=r||["#fff","#000"])&&"string"===c(r)&&M.brewer&&M.brewer[r.toLowerCase()]&&(r=M.brewer[r.toLowerCase()]),"array"===c(r)){1===r.length&&(r=[r[0],r[0]]),r=r.slice(0);for(var e=0;e2){var b=function(r){if(null!=i){for(var e=i.length-1,n=0;n=i[n];)n++;return n-1}return 0}(r);h=b/(i.length-2)}else h=d!==s?(r-s)/(d-s):1;h=w(h),a||(h=y(h)),1!==p&&(h=me(h,p)),h=n(h=u[0]+h*(1-u[0]-u[1]),0,1);var m=Math.floor(1e4*h);if(v&&g[m])f=g[m];else{if("array"===c(l))for(var k=0;k=x&&k===o.length-1){f=l[k];break}if(h>x&&h2){var c=r.map((function(e,n){return n/(r.length-1)})),i=r.map((function(r){return(r-s)/(d-s)}));i.every((function(r,e){return c[e]===r}))||(w=function(r){if(r<=0||r>=1)return r;for(var e=0;r>=i[e+1];)e++;var n=(r-i[e])/(i[e+1]-i[e]);return c[e]+n*(c[e+1]-c[e])})}}return f=[s,d],N},N.mode=function(r){return arguments.length?(e=r,x(),N):e},N.range=function(r,e){return m(r),N},N.out=function(r){return h=r,N},N.spread=function(r){return arguments.length?(a=r,N):a},N.correctLightness=function(r){return null==r&&(r=!0),b=r,x(),y=b?function(r){for(var e=k(0,!0).lab()[0],n=k(1,!0).lab()[0],t=e>n,a=k(r,!0).lab()[0],f=e+(n-e)*r,o=a-f,u=0,c=1,i=20;Math.abs(o)>.01&&i-- >0;)t&&(o*=-1),o<0?(u=r,r+=.5*(c-r)):(c=r,r+=.5*(u-r)),a=k(r,!0).lab()[0],o=a-f;return r}:function(r){return r},N},N.padding=function(r){return null!=r?("number"===c(r)&&(r=[r,r]),u=r,N):u},N.colors=function(e,n){arguments.length<2&&(n="hex");var t=[];if(0===arguments.length)t=l.slice(0);else if(1===e)t=[N(.5)];else if(e>1){var a=f[0],o=f[1]-a;t=function(r,e){for(var n=[],t=ra;t?f++:f--)n.push(f);return n}(0,e).map((function(r){return N(a+r/(e-1)*o)}))}else{r=[];var u=[];if(i&&i.length>2)for(var c=1,h=i.length,s=1<=h;s?ch;s?c++:c--)u.push(.5*(i[c-1]+i[c]));else u=f;t=u.map((function(r){return N(r)}))}return M[n]&&(t=t.map((function(r){return r[n]()}))),t},N.cache=function(r){return null!=r?(v=r,N):v},N.gamma=function(r){return null!=r?(p=r,N):p},N.nodata=function(r){return null!=r?(t=M(r),N):t},N}var we=function(r,e,n){if(!we[n])throw new Error("unknown blend mode "+n);return we[n](r,e)},ke=function(r){return function(e,n){var t=M(n).rgb(),a=M(e).rgb();return M.rgb(r(t,a))}},Me=function(r){return function(e,n){var t=[];return t[0]=r(e[0],n[0]),t[1]=r(e[1],n[1]),t[2]=r(e[2],n[2]),t}};we.normal=ke(Me((function(r){return r}))),we.multiply=ke(Me((function(r,e){return r*e/255}))),we.screen=ke(Me((function(r,e){return 255*(1-(1-r/255)*(1-e/255))}))),we.overlay=ke(Me((function(r,e){return e<128?2*r*e/255:255*(1-2*(1-r/255)*(1-e/255))}))),we.darken=ke(Me((function(r,e){return r>e?e:r}))),we.lighten=ke(Me((function(r,e){return r>e?r:e}))),we.dodge=ke(Me((function(r,e){return 255===r||(r=e/255*255/(1-r/255))>255?255:r}))),we.burn=ke(Me((function(r,e){return 255*(1-(1-e/255)/(r/255))})));var xe=Math.pow,Ne=Math.sin,_e=Math.cos;var je=Math.floor,Ae=Math.random;var Ee=Math.log,Re=Math.pow,Oe=Math.floor,Pe=Math.abs;function Fe(r,e){void 0===e&&(e=null);var n={min:Number.MAX_VALUE,max:-1*Number.MAX_VALUE,sum:0,values:[],count:0};return"object"===c(r)&&(r=Object.values(r)),r.forEach((function(r){e&&"object"===c(r)&&(r=r[e]),null==r||isNaN(r)||(n.values.push(r),n.sum+=r,rn.max&&(n.max=r),n.count+=1)})),n.domain=[n.min,n.max],n.limits=function(r,e){return Le(n,r,e)},n}function Le(r,e,n){void 0===e&&(e="equal"),void 0===n&&(n=7),"array"==c(r)&&(r=Fe(r));var t=r.min,a=r.max,f=r.values.sort((function(r,e){return r-e}));if(1===n)return[t,a];var o=[];if("c"===e.substr(0,1)&&(o.push(t),o.push(a)),"e"===e.substr(0,1)){o.push(t);for(var u=1;u 0");var i=Math.LOG10E*Ee(t),l=Math.LOG10E*Ee(a);o.push(t);for(var h=1;h200&&(w=!1)}for(var Y={},q=0;q=360;)b-=360;o[d]=b}else o[d]=o[d]/u[d];return s/=t,new k(o,e).alpha(s>.99999?1:s,!0)},bezier:function(r){var e=function(r){var e,n,t,a,f,o,u;if(2===(r=r.map((function(r){return new k(r)}))).length)e=r.map((function(r){return r.lab()})),f=e[0],o=e[1],a=function(r){var e=[0,1,2].map((function(e){return f[e]+r*(o[e]-f[e])}));return new k(e,"lab")};else if(3===r.length)n=r.map((function(r){return r.lab()})),f=n[0],o=n[1],u=n[2],a=function(r){var e=[0,1,2].map((function(e){return(1-r)*(1-r)*f[e]+2*(1-r)*r*o[e]+r*r*u[e]}));return new k(e,"lab")};else if(4===r.length){var c;t=r.map((function(r){return r.lab()})),f=t[0],o=t[1],u=t[2],c=t[3],a=function(r){var e=[0,1,2].map((function(e){return(1-r)*(1-r)*(1-r)*f[e]+3*(1-r)*(1-r)*r*o[e]+3*(1-r)*r*r*u[e]+r*r*r*c[e]}));return new k(e,"lab")}}else{if(!(r.length>=5))throw new RangeError("No point in running bezier with only one color.");var i,l,h;i=r.map((function(r){return r.lab()})),h=r.length-1,l=function(r){for(var e=[1,1],n=1;nt?(n+.05)/(t+.05):(t+.05)/(n+.05)},cubehelix:function(r,e,n,a,f){void 0===r&&(r=300),void 0===e&&(e=-1.5),void 0===n&&(n=1),void 0===a&&(a=1),void 0===f&&(f=[0,1]);var o,u=0;"array"===c(f)?o=f[1]-f[0]:(o=0,f=[f,f]);var i=function(c){var i=v*((r+120)/360+e*c),l=xe(f[0]+o*c,a),h=(0!==u?n[0]+c*u:n)*l*(1-l)/2,s=_e(i),d=Ne(i);return M(t([255*(l+h*(-.14861*s+1.78277*d)),255*(l+h*(-.29227*s-.90649*d)),255*(l+h*(1.97294*s)),1]))};return i.start=function(e){return null==e?r:(r=e,i)},i.rotations=function(r){return null==r?e:(e=r,i)},i.gamma=function(r){return null==r?a:(a=r,i)},i.hue=function(r){return null==r?n:("array"===c(n=r)?0===(u=n[1]-n[0])&&(n=n[1]):u=0,i)},i.lightness=function(r){return null==r?f:("array"===c(r)?(f=r,o=r[1]-r[0]):(f=[r,r],o=0),i)},i.scale=function(){return M.scale(i)},i.hue(n),i},deltaE:function(r,e,n,t,a){void 0===n&&(n=1),void 0===t&&(t=1),void 0===a&&(a=1);var f=function(r){return 360*r/(2*We)},o=function(r){return 2*We*r/360};r=new k(r),e=new k(e);var u=Array.from(r.lab()),c=u[0],i=u[1],l=u[2],h=Array.from(e.lab()),s=h[0],d=h[1],b=h[2],g=(c+s)/2,v=(Be(Ge(i,2)+Ge(l,2))+Be(Ge(d,2)+Ge(b,2)))/2,p=.5*(1-Be(Ge(v,7)/(Ge(v,7)+Ge(25,7)))),m=i*(1+p),y=d*(1+p),w=Be(Ge(m,2)+Ge(l,2)),M=Be(Ge(y,2)+Ge(b,2)),x=(w+M)/2,N=f(Xe(l,m)),_=f(Xe(b,y)),j=N>=0?N:N+360,A=_>=0?_:_+360,E=Ce(j-A)>180?(j+A+360)/2:(j+A)/2,R=1-.17*Ze(o(E-30))+.24*Ze(o(2*E))+.32*Ze(o(3*E+6))-.2*Ze(o(4*E-63)),O=A-j;O=Ce(O)<=180?O:A<=j?O+360:O-360,O=2*Be(w*M)*$e(o(O)/2);var P=s-c,F=M-w,L=1+.015*Ge(g-50,2)/Be(20+Ge(g-50,2)),B=1+.045*x,G=1+.015*x*R,Y=30*Se(-Ge((E-275)/25,2)),q=-(2*Be(Ge(x,7)/(Ge(x,7)+Ge(25,7))))*$e(2*o(Y)),X=Be(Ge(P/(n*L),2)+Ge(F/(t*B),2)+Ge(O/(a*G),2)+q*(F/(t*B))*(O/(a*G)));return qe(0,Ye(100,X))},distance:function(r,e,n){void 0===n&&(n="lab"),r=new k(r),e=new k(e);var t=r.get(n),a=e.get(n),f=0;for(var o in t){var u=(t[o]||0)-(a[o]||0);f+=u*u}return Math.sqrt(f)},input:w,interpolate:oe,limits:Le,mix:oe,random:function(){for(var r="#",e=0;e<6;e++)r+="0123456789abcdef".charAt(je(16*Ae()));return new k(r,"hex")},scale:ye,scales:Ie,valid:function(){for(var r=[],e=arguments.length;e--;)r[e]=arguments[e];try{return new(Function.prototype.bind.apply(k,[null].concat(r))),!0}catch(r){return!1}},cmyk:N,css:xr,gl:Nr,hcg:jr,hex:Fr,hsi:qr,hsl:Xr,hsv:Sr,lab:Wr,lch:Ir,hcl:Kr,num:zr,rgb:Vr,temp:Jr,kelvin:Jr,temperature:Jr,oklab:Qr,oklch:re,getLabWhitePoint:R,setLabWhitePoint:E}),M})); +!function(r,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(r="undefined"!=typeof globalThis?globalThis:r||self).chroma=n()}(this,(function(){"use strict";var r=Math.min,n=Math.max;function e(e,t,a){return void 0===t&&(t=0),void 0===a&&(a=1),r(n(t,e),a)}function t(r){r._clipped=!1,r._unclipped=r.slice(0);for(var n=0;n<=3;n++)n<3?((r[n]<0||r[n]>255)&&(r._clipped=!0),r[n]=e(r[n],0,255)):3===n&&(r[n]=e(r[n],0,1));return r}for(var a={},f=0,o=["Boolean","Number","String","Function","Array","Date","RegExp","Undefined","Null"];f=3?Array.prototype.slice.call(r):"object"==c(r[0])&&n?n.split("").filter((function(n){return void 0!==r[0][n]})).map((function(n){return r[0][n]})):r[0].slice(0)}function l(r){if(r.length<2)return null;var n=r.length-1;return"string"==c(r[n])?r[n].toLowerCase():null}var h=Math.PI,s=Math.min,d=Math.max,b=function(r){return Math.round(100*r)/100},g=function(r){return Math.round(100*r)/100},v=2*h,p=h/3,m=h/180,y=180/h,w={format:{},autodetect:[]},k=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=this;if("object"===c(r[0])&&r[0].constructor&&r[0].constructor===this.constructor)return r[0];var a=l(r),f=!1;if(!a){f=!0,w.sorted||(w.autodetect=w.autodetect.sort((function(r,n){return n.p-r.p})),w.sorted=!0);for(var o=0,u=w.autodetect;o4?r[4]:1;return 1===f?[0,0,0,o]:[e>=1?0:255*(1-e)*(1-f),t>=1?0:255*(1-t)*(1-f),a>=1?0:255*(1-a)*(1-f),o]},w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"cmyk"))&&4===r.length)return"cmyk"}});var _=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t,a=(r=i(r,"rgba"))[0],f=r[1],o=r[2],u=s(a/=255,f/=255,o/=255),c=d(a,f,o),l=(c+u)/2;return c===u?(e=0,t=Number.NaN):e=l<.5?(c-u)/(c+u):(c-u)/(2-c-u),a==c?t=(f-o)/(c-u):f==c?t=2+(o-a)/(c-u):o==c&&(t=4+(a-f)/(c-u)),(t*=60)<0&&(t+=360),r.length>3&&void 0!==r[3]?[t,e,l,r[3]]:[t,e,l]},A={Kn:18,labWhitePoint:"d65",Xn:.95047,Yn:1,Zn:1.08883,t0:.137931034,t1:.206896552,t2:.12841855,t3:.008856452,kE:216/24389,kKE:8,kK:24389/27,RefWhiteRGB:{X:.95047,Y:1,Z:1.08883},MtxRGB2XYZ:{m00:.4124564390896922,m01:.21267285140562253,m02:.0193338955823293,m10:.357576077643909,m11:.715152155287818,m12:.11919202588130297,m20:.18043748326639894,m21:.07217499330655958,m22:.9503040785363679},MtxXYZ2RGB:{m00:3.2404541621141045,m01:-.9692660305051868,m02:.055643430959114726,m10:-1.5371385127977166,m11:1.8760108454466942,m12:-.2040259135167538,m20:-.498531409556016,m21:.041556017530349834,m22:1.0572251882231791},As:.9414285350000001,Bs:1.040417467,Cs:1.089532651,MtxAdaptMa:{m00:.8951,m01:-.7502,m02:.0389,m10:.2664,m11:1.7135,m12:-.0685,m20:-.1614,m21:.0367,m22:1.0296},MtxAdaptMaI:{m00:.9869929054667123,m01:.43230526972339456,m02:-.008528664575177328,m10:-.14705425642099013,m11:.5183602715367776,m12:.04004282165408487,m20:.15996265166373125,m21:.0492912282128556,m22:.9684866957875502}},j=new Map([["a",[1.0985,.35585]],["b",[1.0985,.35585]],["c",[.98074,1.18232]],["d50",[.96422,.82521]],["d55",[.95682,.92149]],["d65",[.95047,1.08883]],["e",[1,1,1]],["f2",[.99186,.67393]],["f7",[.95041,1.08747]],["f11",[1.00962,.6435]],["icc",[.96422,.82521]]]);function E(r){var n=j.get(String(r).toLowerCase());if(!n)throw new Error("unknown Lab illuminant "+r);A.labWhitePoint=r,A.Xn=n[0],A.Zn=n[1]}function R(){return A.labWhitePoint}var O=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgb"),t=e[0],a=e[1],f=e[2],o=e.slice(3),u=F(t,a,f),c=function(r,n,e){var t=A.Xn,a=A.Yn,f=A.Zn,o=A.kE,u=A.kK,c=r/t,i=n/a,l=e/f,h=c>o?Math.pow(c,1/3):(u*c+16)/116,s=i>o?Math.pow(i,1/3):(u*i+16)/116,d=l>o?Math.pow(l,1/3):(u*l+16)/116;return[116*s-16,500*(h-s),200*(s-d)]}(u[0],u[1],u[2]);return[c[0],c[1],c[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])};function P(r){var n=Math.sign(r);return((r=Math.abs(r))<=.04045?r/12.92:Math.pow((r+.055)/1.055,2.4))*n}var F=function(r,n,e){r=P(r/255),n=P(n/255),e=P(e/255);var t=A.MtxRGB2XYZ,a=A.MtxAdaptMa,f=A.MtxAdaptMaI,o=A.Xn,u=A.Yn,c=A.Zn,i=A.As,l=A.Bs,h=A.Cs,s=r*t.m00+n*t.m10+e*t.m20,d=r*t.m01+n*t.m11+e*t.m21,b=r*t.m02+n*t.m12+e*t.m22,g=o*a.m00+u*a.m10+c*a.m20,v=o*a.m01+u*a.m11+c*a.m21,p=o*a.m02+u*a.m12+c*a.m22,m=s*a.m00+d*a.m10+b*a.m20,y=s*a.m01+d*a.m11+b*a.m21,w=s*a.m02+d*a.m12+b*a.m22;return y*=v/l,w*=p/h,[s=(m*=g/i)*f.m00+y*f.m10+w*f.m20,d=m*f.m01+y*f.m11+w*f.m21,b=m*f.m02+y*f.m12+w*f.m22]},L=Math.sqrt,B=Math.atan2,G=Math.round,Y=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lab"),t=e[0],a=e[1],f=e[2],o=L(a*a+f*f),u=(B(f,a)*y+360)%360;return 0===G(1e4*o)&&(u=Number.NaN),[t,o,u]},q=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgb"),t=e[0],a=e[1],f=e[2],o=e.slice(3),u=O(t,a,f),c=u[0],l=u[1],h=u[2],s=Y(c,l,h);return[s[0],s[1],s[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])};function C(r,n){var e=r.length;Array.isArray(r[0])||(r=[r]),Array.isArray(n[0])||(n=n.map((function(r){return[r]})));var t=n[0].length,a=n[0].map((function(r,e){return n.map((function(r){return r[e]}))})),f=r.map((function(r){return a.map((function(n){return Array.isArray(r)?r.reduce((function(r,e,t){return r+e*(n[t]||0)}),0):n.reduce((function(n,e){return n+e*r}),0)}))}));return 1===e&&(f=f[0]),1===t?f.map((function(r){return r[0]})):f}var X=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t,a=i(r,"rgb"),f=a[0],o=a[1],u=a[2],c=a.slice(3),l=F(f,o,u);return(e=[[.210454268309314,.7936177747023054,-.0040720430116193],[1.9779985324311684,-2.42859224204858,.450593709617411],[.0259040424655478,.7827717124575296,-.8086757549230774]],t=C([[.819022437996703,.3619062600528904,-.1288737815209879],[.0329836539323885,.9292868615863434,.0361446663506424],[.0481771893596242,.2642395317527308,.6335478284694309]],l),C(e,t.map((function(r){return Math.cbrt(r)})))).concat(c.length>0&&c[0]<1?[c[0]]:[])};var Z=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgb"),t=e[0],a=e[1],f=e[2],o=e.slice(3),u=X(t,a,f),c=u[0],l=u[1],h=u[2],s=Y(c,l,h);return[s[0],s[1],s[2]].concat(o.length>0&&o[0]<1?[o[0]]:[])},$=Math.round,S=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgba"),t=l(r)||"rgb";if("hsl"===t.substr(0,3))return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"hsla"),t=l(r)||"lsa";return e[0]=b(e[0]||0)+"deg",e[1]=b(100*e[1])+"%",e[2]=b(100*e[2])+"%","hsla"===t||e.length>3&&e[3]<1?(e[3]="/ "+(e.length>3?e[3]:1),t="hsla"):e.length=3,t.substr(0,3)+"("+e.join(" ")+")"}(_(e),t);if("lab"===t.substr(0,3)){var a=R();E("d50");var f=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lab"),t=l(r)||"lab";return e[0]=b(e[0])+"%",e[1]=b(e[1]),e[2]=b(e[2]),"laba"===t||e.length>3&&e[3]<1?e[3]="/ "+(e.length>3?e[3]:1):e.length=3,"lab("+e.join(" ")+")"}(O(e),t);return E(a),f}if("lch"===t.substr(0,3)){var o=R();E("d50");var u=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lch"),t=l(r)||"lab";return e[0]=b(e[0])+"%",e[1]=b(e[1]),e[2]=b(e[2])+"deg","lcha"===t||e.length>3&&e[3]<1?e[3]="/ "+(e.length>3?e[3]:1):e.length=3,"lch("+e.join(" ")+")"}(q(e),t);return E(o),u}return"oklab"===t.substr(0,5)?function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lab");return e[0]=b(100*e[0])+"%",e[1]=g(e[1]),e[2]=g(e[2]),e.length>3&&e[3]<1?e[3]="/ "+(e.length>3?e[3]:1):e.length=3,"oklab("+e.join(" ")+")"}(X(e)):"oklch"===t.substr(0,5)?function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lab");return e[0]=b(100*e[0])+"%",e[1]=g(e[1]),e[2]=b(e[2])+"deg",e.length>3&&e[3]<1?e[3]="/ "+(e.length>3?e[3]:1):e.length=3,"oklch("+e.join(" ")+")"}(Z(e)):(e[0]=$(e[0]),e[1]=$(e[1]),e[2]=$(e[2]),("rgba"===t||e.length>3&&e[3]<1)&&(e[3]="/ "+(e.length>3?e[3]:1),t="rgba"),t.substr(0,3)+"("+e.slice(0,"rgb"===t?3:4).join(" ")+")")},W=function(){for(var r,n=[],e=arguments.length;e--;)n[e]=arguments[e];var t,a,f,o=(n=i(n,"hsl"))[0],u=n[1],c=n[2];if(0===u)t=a=f=255*c;else{var l=[0,0,0],h=[0,0,0],s=c<.5?c*(1+u):c+u-c*u,d=2*c-s,b=o/360;l[0]=b+1/3,l[1]=b,l[2]=b-1/3;for(var g=0;g<3;g++)l[g]<0&&(l[g]+=1),l[g]>1&&(l[g]-=1),6*l[g]<1?h[g]=d+6*(s-d)*l[g]:2*l[g]<1?h[g]=s:3*l[g]<2?h[g]=d+(s-d)*(2/3-l[g])*6:h[g]=d;t=(r=[255*h[0],255*h[1],255*h[2]])[0],a=r[1],f=r[2]}return n.length>3?[t,a,f,n[3]]:[t,a,f,1]},I=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=(r=i(r,"lab"))[0],t=r[1],a=r[2],f=K(e,t,a),o=f[0],u=f[1],c=f[2],l=U(o,u,c);return[l[0],l[1],l[2],r.length>3?r[3]:1]},K=function(r,n,e){var t=A.kE,a=A.kK,f=A.kKE,o=A.Xn,u=A.Yn,c=A.Zn,i=(r+16)/116,l=.002*n+i,h=i-.005*e,s=l*l*l,d=h*h*h;return[(s>t?s:(116*l-16)/a)*o,(r>f?Math.pow((r+16)/116,3):r/a)*u,(d>t?d:(116*h-16)/a)*c]},z=function(r){var n=Math.sign(r);return((r=Math.abs(r))<=.0031308?12.92*r:1.055*Math.pow(r,1/2.4)-.055)*n},U=function(r,n,e){var t=A.MtxAdaptMa,a=A.MtxAdaptMaI,f=A.MtxXYZ2RGB,o=A.RefWhiteRGB,u=A.Xn,c=A.Yn,i=A.Zn,l=u*t.m00+c*t.m10+i*t.m20,h=u*t.m01+c*t.m11+i*t.m21,s=u*t.m02+c*t.m12+i*t.m22,d=o.X*t.m00+o.Y*t.m10+o.Z*t.m20,b=o.X*t.m01+o.Y*t.m11+o.Z*t.m21,g=o.X*t.m02+o.Y*t.m12+o.Z*t.m22,v=(r*t.m00+n*t.m10+e*t.m20)*(d/l),p=(r*t.m01+n*t.m11+e*t.m21)*(b/h),m=(r*t.m02+n*t.m12+e*t.m22)*(g/s),y=v*a.m00+p*a.m10+m*a.m20,w=v*a.m01+p*a.m11+m*a.m21,k=v*a.m02+p*a.m12+m*a.m22;return[255*z(y*f.m00+w*f.m10+k*f.m20),255*z(y*f.m01+w*f.m11+k*f.m21),255*z(y*f.m02+w*f.m12+k*f.m22)]},V=Math.sin,D=Math.cos,T=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"lch"),t=e[0],a=e[1],f=e[2];return isNaN(f)&&(f=0),[t,D(f*=m)*a,V(f)*a]},H=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=(r=i(r,"lch"))[0],t=r[1],a=r[2],f=T(e,t,a),o=f[0],u=f[1],c=f[2],l=I(o,u,c);return[l[0],l[1],l[2],r.length>3?r[3]:1]},J=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t,a=(r=i(r,"lab"))[0],f=r[1],o=r[2],u=r.slice(3),c=(e=[[1.2268798758459243,-.5578149944602171,.2813910456659647],[-.0405757452148008,1.112286803280317,-.0717110580655164],[-.0763729366746601,-.4214933324022432,1.5869240198367816]],t=C([[1,.3963377773761749,.2158037573099136],[1,-.1055613458156586,-.0638541728258133],[1,-.0894841775298119,-1.2914855480194092]],[a,f,o]),C(e,t.map((function(r){return Math.pow(r,3)})))),l=c[0],h=c[1],s=c[2],d=U(l,h,s);return[d[0],d[1],d[2]].concat(u.length>0&&u[0]<1?[u[0]]:[])};var Q=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=(r=i(r,"lch"))[0],t=r[1],a=r[2],f=r.slice(3),o=T(e,t,a),u=o[0],c=o[1],l=o[2],h=J(u,c,l);return[h[0],h[1],h[2]].concat(f.length>0&&f[0]<1?[f[0]]:[])},rr=/((?:-?\d+)|(?:-?\d+(?:\.\d+)?)%|none)/.source,nr=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%?)|none)/.source,er=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)%)|none)/.source,tr=/\s*/.source,ar=/\s+/.source,fr=/\s*,\s*/.source,or=/((?:-?(?:\d+(?:\.\d*)?|\.\d+)(?:deg)?)|none)/.source,ur=/\s*(?:\/\s*((?:[01]|[01]?\.\d+)|\d+(?:\.\d+)?%))?/.source,cr=new RegExp("^rgba?\\("+tr+[rr,rr,rr].join(ar)+ur+"\\)$"),ir=new RegExp("^rgb\\("+tr+[rr,rr,rr].join(fr)+tr+"\\)$"),lr=new RegExp("^rgba\\("+tr+[rr,rr,rr,nr].join(fr)+tr+"\\)$"),hr=new RegExp("^hsla?\\("+tr+[or,er,er].join(ar)+ur+"\\)$"),sr=new RegExp("^hsl?\\("+tr+[or,er,er].join(fr)+tr+"\\)$"),dr=/^hsla\(\s*(-?\d+(?:\.\d+)?),\s*(-?\d+(?:\.\d+)?)%\s*,\s*(-?\d+(?:\.\d+)?)%\s*,\s*([01]|[01]?\.\d+)\)$/,br=new RegExp("^lab\\("+tr+[nr,nr,nr].join(ar)+ur+"\\)$"),gr=new RegExp("^lch\\("+tr+[nr,nr,or].join(ar)+ur+"\\)$"),vr=new RegExp("^oklab\\("+tr+[nr,nr,nr].join(ar)+ur+"\\)$"),pr=new RegExp("^oklch\\("+tr+[nr,nr,or].join(ar)+ur+"\\)$"),mr=Math.round,yr=function(r){return r.map((function(r,n){return n<=2?e(mr(r),0,255):r}))},wr=function(r,n,e,t){return void 0===n&&(n=0),void 0===e&&(e=100),void 0===t&&(t=!1),"string"==typeof r&&r.endsWith("%")&&(r=parseFloat(r.substring(0,r.length-1))/100,r=t?n+.5*(r+1)*(e-n):n+r*(e-n)),+r},kr=function(r,n){return"none"===r?n:r},Mr=function(r){var n;if(r=r.toLowerCase().trim(),w.format.named)try{return w.format.named(r)}catch(r){}if((n=r.match(cr))||(n=r.match(ir))){for(var e=n.slice(1,4),t=0;t<3;t++)e[t]=+wr(kr(e[t],0),0,255);e=yr(e);var a=void 0!==n[4]?+wr(n[4],0,1):1;return e[3]=a,e}if(n=r.match(lr)){for(var f=n.slice(1,5),o=0;o<4;o++)f[o]=+wr(f[o],0,255);return f}if((n=r.match(hr))||(n=r.match(sr))){var u=n.slice(1,4);u[0]=+kr(u[0].replace("deg",""),0),u[1]=.01*+wr(kr(u[1],0),0,100),u[2]=.01*+wr(kr(u[2],0),0,100);var c=yr(W(u)),i=void 0!==n[4]?+wr(n[4],0,1):1;return c[3]=i,c}if(n=r.match(dr)){var l=n.slice(1,4);l[1]*=.01,l[2]*=.01;for(var h=W(l),s=0;s<3;s++)h[s]=mr(h[s]);return h[3]=+n[4],h}if(n=r.match(br)){var d=n.slice(1,4);d[0]=wr(kr(d[0],0),0,100),d[1]=wr(kr(d[1],0),-125,125,!0),d[2]=wr(kr(d[2],0),-125,125,!0);var b=R();E("d50");var g=yr(I(d));E(b);var v=void 0!==n[4]?+wr(n[4],0,1):1;return g[3]=v,g}if(n=r.match(gr)){var p=n.slice(1,4);p[0]=wr(p[0],0,100),p[1]=wr(kr(p[1],0),0,150,!1),p[2]=+kr(p[2].replace("deg",""),0);var m=R();E("d50");var y=yr(H(p));E(m);var k=void 0!==n[4]?+wr(n[4],0,1):1;return y[3]=k,y}if(n=r.match(vr)){var M=n.slice(1,4);M[0]=wr(kr(M[0],0),0,1),M[1]=wr(kr(M[1],0),-.4,.4,!0),M[2]=wr(kr(M[2],0),-.4,.4,!0);var x=yr(J(M)),N=void 0!==n[4]?+wr(n[4],0,1):1;return x[3]=N,x}if(n=r.match(pr)){var _=n.slice(1,4);_[0]=wr(kr(_[0],0),0,1),_[1]=wr(kr(_[1],0),0,.4,!1),_[2]=+kr(_[2].replace("deg",""),0);var A=yr(Q(_)),j=void 0!==n[4]?+wr(n[4],0,1):1;return A[3]=j,A}};Mr.test=function(r){return cr.test(r)||hr.test(r)||br.test(r)||gr.test(r)||vr.test(r)||pr.test(r)||ir.test(r)||lr.test(r)||sr.test(r)||dr.test(r)},k.prototype.css=function(r){return S(this._rgb,r)};var xr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["css"])))};M.css=xr,w.format.css=Mr,w.autodetect.push({p:5,test:function(r){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];if(!n.length&&"string"===c(r)&&Mr.test(r))return"css"}}),w.format.gl=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgba");return e[0]*=255,e[1]*=255,e[2]*=255,e};var Nr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["gl"])))};M.gl=Nr,k.prototype.gl=function(){var r=this._rgb;return[r[0]/255,r[1]/255,r[2]/255,r[3]]};var _r=Math.floor;k.prototype.hcg=function(){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t=i(r,"rgb"),a=t[0],f=t[1],o=t[2],u=s(a,f,o),c=d(a,f,o),l=c-u,h=100*l/255,b=u/(255-l)*100;return 0===l?e=Number.NaN:(a===c&&(e=(f-o)/l),f===c&&(e=2+(o-a)/l),o===c&&(e=4+(a-f)/l),(e*=60)<0&&(e+=360)),[e,h,b]}(this._rgb)};var Ar=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hcg"])))};M.hcg=Ar,w.format.hcg=function(){for(var r,n,e,t,a,f,o=[],u=arguments.length;u--;)o[u]=arguments[u];var c,l,h,s=(o=i(o,"hcg"))[0],d=o[1],b=o[2];b*=255;var g=255*d;if(0===d)c=l=h=b;else{360===s&&(s=0),s>360&&(s-=360),s<0&&(s+=360);var v=_r(s/=60),p=s-v,m=b*(1-d),y=m+g*(1-p),w=m+g*p,k=m+g;switch(v){case 0:c=(r=[k,w,m])[0],l=r[1],h=r[2];break;case 1:c=(n=[y,k,m])[0],l=n[1],h=n[2];break;case 2:c=(e=[m,k,w])[0],l=e[1],h=e[2];break;case 3:c=(t=[m,y,k])[0],l=t[1],h=t[2];break;case 4:c=(a=[w,m,k])[0],l=a[1],h=a[2];break;case 5:c=(f=[k,m,y])[0],l=f[1],h=f[2]}}return[c,l,h,o.length>3?o[3]:1]},w.autodetect.push({p:1,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"hcg"))&&3===r.length)return"hcg"}});var jr=/^#?([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/,Er=/^#?([A-Fa-f0-9]{8}|[A-Fa-f0-9]{4})$/,Rr=function(r){if(r.match(jr)){4!==r.length&&7!==r.length||(r=r.substr(1)),3===r.length&&(r=(r=r.split(""))[0]+r[0]+r[1]+r[1]+r[2]+r[2]);var n=parseInt(r,16);return[n>>16,n>>8&255,255&n,1]}if(r.match(Er)){5!==r.length&&9!==r.length||(r=r.substr(1)),4===r.length&&(r=(r=r.split(""))[0]+r[0]+r[1]+r[1]+r[2]+r[2]+r[3]+r[3]);var e=parseInt(r,16);return[e>>24&255,e>>16&255,e>>8&255,Math.round((255&e)/255*100)/100]}throw new Error("unknown hex color: "+r)},Or=Math.round,Pr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgba"),t=e[0],a=e[1],f=e[2],o=e[3],u=l(r)||"auto";void 0===o&&(o=1),"auto"===u&&(u=o<1?"rgba":"rgb");var c="000000"+((t=Or(t))<<16|(a=Or(a))<<8|(f=Or(f))).toString(16);c=c.substr(c.length-6);var h="0"+Or(255*o).toString(16);switch(h=h.substr(h.length-2),u.toLowerCase()){case"rgba":return"#"+c+h;case"argb":return"#"+h+c;default:return"#"+c}};k.prototype.hex=function(r){return Pr(this._rgb,r)};var Fr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hex"])))};M.hex=Fr,w.format.hex=Rr,w.autodetect.push({p:4,test:function(r){for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];if(!n.length&&"string"===c(r)&&[3,4,5,6,7,8,9].indexOf(r.length)>=0)return"hex"}});var Lr=Math.cos,Br=Math.min,Gr=Math.sqrt,Yr=Math.acos;k.prototype.hsi=function(){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t=i(r,"rgb"),a=t[0],f=t[1],o=t[2],u=Br(a/=255,f/=255,o/=255),c=(a+f+o)/3,l=c>0?1-u/c:0;return 0===l?e=NaN:(e=(a-f+(a-o))/2,e/=Gr((a-f)*(a-f)+(a-o)*(f-o)),e=Yr(e),o>f&&(e=v-e),e/=v),[360*e,l,c]}(this._rgb)};var qr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsi"])))};M.hsi=qr,w.format.hsi=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var t,a,f,o=(r=i(r,"hsi"))[0],u=r[1],c=r[2];return isNaN(o)&&(o=0),isNaN(u)&&(u=0),o>360&&(o-=360),o<0&&(o+=360),(o/=360)<1/3?a=1-((f=(1-u)/3)+(t=(1+u*Lr(v*o)/Lr(p-v*o))/3)):o<2/3?f=1-((t=(1-u)/3)+(a=(1+u*Lr(v*(o-=1/3))/Lr(p-v*o))/3)):t=1-((a=(1-u)/3)+(f=(1+u*Lr(v*(o-=2/3))/Lr(p-v*o))/3)),[255*(t=e(c*t*3)),255*(a=e(c*a*3)),255*(f=e(c*f*3)),r.length>3?r[3]:1]},w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"hsi"))&&3===r.length)return"hsi"}}),k.prototype.hsl=function(){return _(this._rgb)};var Cr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsl"])))};M.hsl=Cr,w.format.hsl=W,w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"hsl"))&&3===r.length)return"hsl"}});var Xr=Math.floor,Zr=Math.min,$r=Math.max;k.prototype.hsv=function(){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e,t,a,f=(r=i(r,"rgb"))[0],o=r[1],u=r[2],c=Zr(f,o,u),l=$r(f,o,u),h=l-c;return a=l/255,0===l?(e=Number.NaN,t=0):(t=h/l,f===l&&(e=(o-u)/h),o===l&&(e=2+(u-f)/h),u===l&&(e=4+(f-o)/h),(e*=60)<0&&(e+=360)),[e,t,a]}(this._rgb)};var Sr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hsv"])))};M.hsv=Sr,w.format.hsv=function(){for(var r,n,e,t,a,f,o=[],u=arguments.length;u--;)o[u]=arguments[u];var c,l,h,s=(o=i(o,"hsv"))[0],d=o[1],b=o[2];if(b*=255,0===d)c=l=h=b;else{360===s&&(s=0),s>360&&(s-=360),s<0&&(s+=360);var g=Xr(s/=60),v=s-g,p=b*(1-d),m=b*(1-d*v),y=b*(1-d*(1-v));switch(g){case 0:c=(r=[b,y,p])[0],l=r[1],h=r[2];break;case 1:c=(n=[m,b,p])[0],l=n[1],h=n[2];break;case 2:c=(e=[p,b,y])[0],l=e[1],h=e[2];break;case 3:c=(t=[p,m,b])[0],l=t[1],h=t[2];break;case 4:c=(a=[y,p,b])[0],l=a[1],h=a[2];break;case 5:c=(f=[b,p,m])[0],l=f[1],h=f[2]}}return[c,l,h,o.length>3?o[3]:1]},w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"hsv"))&&3===r.length)return"hsv"}}),k.prototype.lab=function(){return O(this._rgb)};var Wr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["lab"])))};Object.assign(M,{lab:Wr,getLabWhitePoint:R,setLabWhitePoint:E}),w.format.lab=I,w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"lab"))&&3===r.length)return"lab"}});k.prototype.lch=function(){return q(this._rgb)},k.prototype.hcl=function(){return q(this._rgb).reverse()};var Ir=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["lch"])))},Kr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["hcl"])))};Object.assign(M,{lch:Ir,hcl:Kr}),w.format.lch=H,w.format.hcl=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"hcl").reverse();return H.apply(void 0,e)},["lch","hcl"].forEach((function(r){return w.autodetect.push({p:2,test:function(){for(var n=[],e=arguments.length;e--;)n[e]=arguments[e];if("array"===c(n=i(n,r))&&3===n.length)return r}})}));k.prototype.num=function(){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgb");return(e[0]<<16)+(e[1]<<8)+e[2]}(this._rgb)};var zr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["num"])))};Object.assign(M,{num:zr}),w.format.num=function(r){if("number"==c(r)&&r>=0&&r<=16777215)return[r>>16,r>>8&255,255&r,1];throw new Error("unknown num color: "+r)},w.autodetect.push({p:5,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if(1===r.length&&"number"===c(r[0])&&r[0]>=0&&r[0]<=16777215)return"num"}});var Ur=Math.round;k.prototype.rgb=function(r){return void 0===r&&(r=!0),!1===r?this._rgb.slice(0,3):this._rgb.slice(0,3).map(Ur)},k.prototype.rgba=function(r){return void 0===r&&(r=!0),this._rgb.slice(0,4).map((function(n,e){return e<3?!1===r?n:Ur(n):n}))};var Vr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["rgb"])))};Object.assign(M,{rgb:Vr}),w.format.rgb=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];var e=i(r,"rgba");return void 0===e[3]&&(e[3]=1),e},w.autodetect.push({p:3,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"rgba"))&&(3===r.length||4===r.length&&"number"==c(r[3])&&r[3]>=0&&r[3]<=1))return"rgb"}});var Dr=Math.log,Tr=function(r){var n,e,t,a=r/100;return a<66?(n=255,e=a<6?0:-155.25485562709179-.44596950469579133*(e=a-2)+104.49216199393888*Dr(e),t=a<20?0:.8274096064007395*(t=a-10)-254.76935184120902+115.67994401066147*Dr(t)):(n=351.97690566805693+.114206453784165*(n=a-55)-40.25366309332127*Dr(n),e=325.4494125711974+.07943456536662342*(e=a-50)-28.0852963507957*Dr(e),t=255),[n,e,t,1]},Hr=Math.round;k.prototype.temp=k.prototype.kelvin=k.prototype.temperature=function(){return function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];for(var e,t=i(r,"rgb"),a=t[0],f=t[2],o=1e3,u=4e4;u-o>.4;){var c=Tr(e=.5*(u+o));c[2]/c[0]>=f/a?u=e:o=e}return Hr(e)}(this._rgb)};var Jr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["temp"])))};Object.assign(M,{temp:Jr,kelvin:Jr,temperature:Jr}),w.format.temp=w.format.kelvin=w.format.temperature=Tr,k.prototype.oklab=function(){return X(this._rgb)};var Qr=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["oklab"])))};Object.assign(M,{oklab:Qr}),w.format.oklab=J,w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"oklab"))&&3===r.length)return"oklab"}}),k.prototype.oklch=function(){return Z(this._rgb)};var rn=function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];return new(Function.prototype.bind.apply(k,[null].concat(r,["oklch"])))};Object.assign(M,{oklch:rn}),w.format.oklch=Q,w.autodetect.push({p:2,test:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];if("array"===c(r=i(r,"oklch"))&&3===r.length)return"oklch"}});var nn={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",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",laserlemon:"#ffff54",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrod:"#fafad2",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",maroon2:"#7f0000",maroon3:"#b03060",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",purple2:"#7f007f",purple3:"#a020f0",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"};k.prototype.name=function(){for(var r=Pr(this._rgb,"rgb"),n=0,e=Object.keys(nn);n0;)n[e]=arguments[e+1];if(!n.length&&"string"===c(r)&&nn[r.toLowerCase()])return"named"}}),k.prototype.alpha=function(r,n){return void 0===n&&(n=!1),void 0!==r&&"number"===c(r)?n?(this._rgb[3]=r,this):new k([this._rgb[0],this._rgb[1],this._rgb[2],r],"rgb"):this._rgb[3]},k.prototype.clipped=function(){return this._rgb._clipped||!1},k.prototype.darken=function(r){void 0===r&&(r=1);var n=this.lab();return n[0]-=A.Kn*r,new k(n,"lab").alpha(this.alpha(),!0)},k.prototype.brighten=function(r){return void 0===r&&(r=1),this.darken(-r)},k.prototype.darker=k.prototype.darken,k.prototype.brighter=k.prototype.brighten,k.prototype.get=function(r){var n=r.split("."),e=n[0],t=n[1],a=this[e]();if(t){var f=e.indexOf(t)-("ok"===e.substr(0,2)?2:0);if(f>-1)return a[f];throw new Error("unknown channel "+t+" in mode "+e)}return a};var en=Math.pow;k.prototype.luminance=function(r,n){if(void 0===n&&(n="rgb"),void 0!==r&&"number"===c(r)){if(0===r)return new k([0,0,0,this._rgb[3]],"rgb");if(1===r)return new k([255,255,255,this._rgb[3]],"rgb");var e=this.luminance(),t=20,a=function(e,f){var o=e.interpolate(f,.5,n),u=o.luminance();return Math.abs(r-u)<1e-7||!t--?o:u>r?a(e,o):a(o,f)},f=(e>r?a(new k([0,0,0]),this):a(this,new k([255,255,255]))).rgb();return new k(f.concat([this._rgb[3]]))}return tn.apply(void 0,this._rgb.slice(0,3))};var tn=function(r,n,e){return.2126*(r=an(r))+.7152*(n=an(n))+.0722*(e=an(e))},an=function(r){return(r/=255)<=.03928?r/12.92:en((r+.055)/1.055,2.4)},fn={};function on(r,n,e){void 0===e&&(e=.5);for(var t=[],a=arguments.length-3;a-- >0;)t[a]=arguments[a+3];var f=t[0]||"lrgb";if(fn[f]||t.length||(f=Object.keys(fn)[0]),!fn[f])throw new Error("interpolation mode "+f+" is not defined");return"object"!==c(r)&&(r=new k(r)),"object"!==c(n)&&(n=new k(n)),fn[f](r,n,e).alpha(r.alpha()+e*(n.alpha()-r.alpha()))}k.prototype.mix=k.prototype.interpolate=function(r,n){void 0===n&&(n=.5);for(var e=[],t=arguments.length-2;t-- >0;)e[t]=arguments[t+2];return on.apply(void 0,[this,r,n].concat(e))},k.prototype.premultiply=function(r){void 0===r&&(r=!1);var n=this._rgb,e=n[3];return r?(this._rgb=[n[0]*e,n[1]*e,n[2]*e,e],this):new k([n[0]*e,n[1]*e,n[2]*e,e],"rgb")},k.prototype.saturate=function(r){void 0===r&&(r=1);var n=this.lch();return n[1]+=A.Kn*r,n[1]<0&&(n[1]=0),new k(n,"lch").alpha(this.alpha(),!0)},k.prototype.desaturate=function(r){return void 0===r&&(r=1),this.saturate(-r)},k.prototype.set=function(r,n,e){void 0===e&&(e=!1);var t=r.split("."),a=t[0],f=t[1],o=this[a]();if(f){var u=a.indexOf(f)-("ok"===a.substr(0,2)?2:0);if(u>-1){if("string"==c(n))switch(n.charAt(0)){case"+":case"-":o[u]+=+n;break;case"*":o[u]*=+n.substr(1);break;case"/":o[u]/=+n.substr(1);break;default:o[u]=+n}else{if("number"!==c(n))throw new Error("unsupported value for Color.set");o[u]=n}var i=new k(o,a);return e?(this._rgb=i._rgb,this):i}throw new Error("unknown channel "+f+" in mode "+a)}return o},k.prototype.tint=function(r){void 0===r&&(r=.5);for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return on.apply(void 0,[this,"white",r].concat(n))},k.prototype.shade=function(r){void 0===r&&(r=.5);for(var n=[],e=arguments.length-1;e-- >0;)n[e]=arguments[e+1];return on.apply(void 0,[this,"black",r].concat(n))};fn.rgb=function(r,n,e){var t=r._rgb,a=n._rgb;return new k(t[0]+e*(a[0]-t[0]),t[1]+e*(a[1]-t[1]),t[2]+e*(a[2]-t[2]),"rgb")};var un=Math.sqrt,cn=Math.pow;fn.lrgb=function(r,n,e){var t=r._rgb,a=t[0],f=t[1],o=t[2],u=n._rgb,c=u[0],i=u[1],l=u[2];return new k(un(cn(a,2)*(1-e)+cn(c,2)*e),un(cn(f,2)*(1-e)+cn(i,2)*e),un(cn(o,2)*(1-e)+cn(l,2)*e),"rgb")};function ln(r,n,e,t){var a,f,o,u,c,i,l,h,s,d,b,g,v;return"hsl"===t?(o=r.hsl(),u=n.hsl()):"hsv"===t?(o=r.hsv(),u=n.hsv()):"hcg"===t?(o=r.hcg(),u=n.hcg()):"hsi"===t?(o=r.hsi(),u=n.hsi()):"lch"===t||"hcl"===t?(t="hcl",o=r.hcl(),u=n.hcl()):"oklch"===t&&(o=r.oklch().reverse(),u=n.oklch().reverse()),"h"!==t.substr(0,1)&&"oklch"!==t||(c=(a=o)[0],l=a[1],s=a[2],i=(f=u)[0],h=f[1],d=f[2]),isNaN(c)||isNaN(i)?isNaN(c)?isNaN(i)?g=Number.NaN:(g=i,1!=s&&0!=s||"hsv"==t||(b=h)):(g=c,1!=d&&0!=d||"hsv"==t||(b=l)):g=c+e*(i>c&&i-c>180?i-(c+360):i180?i+360-c:i-c),void 0===b&&(b=l+e*(h-l)),v=s+e*(d-s),new k("oklch"===t?[v,b,g]:[g,b,v],t)}fn.lab=function(r,n,e){var t=r.lab(),a=n.lab();return new k(t[0]+e*(a[0]-t[0]),t[1]+e*(a[1]-t[1]),t[2]+e*(a[2]-t[2]),"lab")};var hn=function(r,n,e){return ln(r,n,e,"lch")};fn.lch=hn,fn.hcl=hn;fn.num=function(r,n,e){var t=r.num(),a=n.num();return new k(t+e*(a-t),"num")};fn.hcg=function(r,n,e){return ln(r,n,e,"hcg")};fn.hsi=function(r,n,e){return ln(r,n,e,"hsi")};fn.hsl=function(r,n,e){return ln(r,n,e,"hsl")};fn.hsv=function(r,n,e){return ln(r,n,e,"hsv")};fn.oklab=function(r,n,e){var t=r.oklab(),a=n.oklab();return new k(t[0]+e*(a[0]-t[0]),t[1]+e*(a[1]-t[1]),t[2]+e*(a[2]-t[2]),"oklab")};fn.oklch=function(r,n,e){return ln(r,n,e,"oklch")};var sn=Math.pow,dn=Math.sqrt,bn=Math.PI,gn=Math.cos,vn=Math.sin,pn=Math.atan2;var mn=function(r,n){for(var e=r.length,a=[0,0,0,0],f=0;f.9999999&&(a[3]=1),new k(t(a))},yn=Math.pow;function wn(r){var n="rgb",t=M("#ccc"),a=0,f=[0,1],o=[],u=[0,0],i=!1,l=[],h=!1,s=0,d=1,b=!1,g={},v=!0,p=1,m=function(r){if((r=r||["#fff","#000"])&&"string"===c(r)&&M.brewer&&M.brewer[r.toLowerCase()]&&(r=M.brewer[r.toLowerCase()]),"array"===c(r)){1===r.length&&(r=[r[0],r[0]]),r=r.slice(0);for(var n=0;n2){var b=function(r){if(null!=i){for(var n=i.length-1,e=0;e=i[e];)e++;return e-1}return 0}(r);h=b/(i.length-2)}else h=d!==s?(r-s)/(d-s):1;h=w(h),a||(h=y(h)),1!==p&&(h=yn(h,p)),h=e(h=u[0]+h*(1-u[0]-u[1]),0,1);var m=Math.floor(1e4*h);if(v&&g[m])f=g[m];else{if("array"===c(l))for(var k=0;k=x&&k===o.length-1){f=l[k];break}if(h>x&&h2){var c=r.map((function(n,e){return e/(r.length-1)})),i=r.map((function(r){return(r-s)/(d-s)}));i.every((function(r,n){return c[n]===r}))||(w=function(r){if(r<=0||r>=1)return r;for(var n=0;r>=i[n+1];)n++;var e=(r-i[n])/(i[n+1]-i[n]);return c[n]+e*(c[n+1]-c[n])})}}return f=[s,d],N},N.mode=function(r){return arguments.length?(n=r,x(),N):n},N.range=function(r,n){return m(r),N},N.out=function(r){return h=r,N},N.spread=function(r){return arguments.length?(a=r,N):a},N.correctLightness=function(r){return null==r&&(r=!0),b=r,x(),y=b?function(r){for(var n=k(0,!0).lab()[0],e=k(1,!0).lab()[0],t=n>e,a=k(r,!0).lab()[0],f=n+(e-n)*r,o=a-f,u=0,c=1,i=20;Math.abs(o)>.01&&i-- >0;)t&&(o*=-1),o<0?(u=r,r+=.5*(c-r)):(c=r,r+=.5*(u-r)),a=k(r,!0).lab()[0],o=a-f;return r}:function(r){return r},N},N.padding=function(r){return null!=r?("number"===c(r)&&(r=[r,r]),u=r,N):u},N.colors=function(n,e){arguments.length<2&&(e="hex");var t=[];if(0===arguments.length)t=l.slice(0);else if(1===n)t=[N(.5)];else if(n>1){var a=f[0],o=f[1]-a;t=function(r,n){for(var e=[],t=ra;t?f++:f--)e.push(f);return e}(0,n).map((function(r){return N(a+r/(n-1)*o)}))}else{r=[];var u=[];if(i&&i.length>2)for(var c=1,h=i.length,s=1<=h;s?ch;s?c++:c--)u.push(.5*(i[c-1]+i[c]));else u=f;t=u.map((function(r){return N(r)}))}return M[e]&&(t=t.map((function(r){return r[e]()}))),t},N.cache=function(r){return null!=r?(v=r,N):v},N.gamma=function(r){return null!=r?(p=r,N):p},N.nodata=function(r){return null!=r?(t=M(r),N):t},N}var kn=function(r,n,e){if(!kn[e])throw new Error("unknown blend mode "+e);return kn[e](r,n)},Mn=function(r){return function(n,e){var t=M(e).rgb(),a=M(n).rgb();return M.rgb(r(t,a))}},xn=function(r){return function(n,e){var t=[];return t[0]=r(n[0],e[0]),t[1]=r(n[1],e[1]),t[2]=r(n[2],e[2]),t}};kn.normal=Mn(xn((function(r){return r}))),kn.multiply=Mn(xn((function(r,n){return r*n/255}))),kn.screen=Mn(xn((function(r,n){return 255*(1-(1-r/255)*(1-n/255))}))),kn.overlay=Mn(xn((function(r,n){return n<128?2*r*n/255:255*(1-2*(1-r/255)*(1-n/255))}))),kn.darken=Mn(xn((function(r,n){return r>n?n:r}))),kn.lighten=Mn(xn((function(r,n){return r>n?r:n}))),kn.dodge=Mn(xn((function(r,n){return 255===r||(r=n/255*255/(1-r/255))>255?255:r}))),kn.burn=Mn(xn((function(r,n){return 255*(1-(1-n/255)/(r/255))})));var Nn=Math.pow,_n=Math.sin,An=Math.cos;var jn=Math.floor,En=Math.random;var Rn=Math.log,On=Math.pow,Pn=Math.floor,Fn=Math.abs;function Ln(r,n){void 0===n&&(n=null);var e={min:Number.MAX_VALUE,max:-1*Number.MAX_VALUE,sum:0,values:[],count:0};return"object"===c(r)&&(r=Object.values(r)),r.forEach((function(r){n&&"object"===c(r)&&(r=r[n]),null==r||isNaN(r)||(e.values.push(r),e.sum+=r,re.max&&(e.max=r),e.count+=1)})),e.domain=[e.min,e.max],e.limits=function(r,n){return Bn(e,r,n)},e}function Bn(r,n,e){void 0===n&&(n="equal"),void 0===e&&(e=7),"array"==c(r)&&(r=Ln(r));var t=r.min,a=r.max,f=r.values.sort((function(r,n){return r-n}));if(1===e)return[t,a];var o=[];if("c"===n.substr(0,1)&&(o.push(t),o.push(a)),"e"===n.substr(0,1)){o.push(t);for(var u=1;u 0");var i=Math.LOG10E*Rn(t),l=Math.LOG10E*Rn(a);o.push(t);for(var h=1;h200&&(w=!1)}for(var Y={},q=0;q=360;)b-=360;o[d]=b}else o[d]=o[d]/u[d];return s/=t,new k(o,n).alpha(s>.99999?1:s,!0)},bezier:function(r){var n=function(r){var n,e,t,a,f,o,u;if(2===(r=r.map((function(r){return new k(r)}))).length)n=r.map((function(r){return r.lab()})),f=n[0],o=n[1],a=function(r){var n=[0,1,2].map((function(n){return f[n]+r*(o[n]-f[n])}));return new k(n,"lab")};else if(3===r.length)e=r.map((function(r){return r.lab()})),f=e[0],o=e[1],u=e[2],a=function(r){var n=[0,1,2].map((function(n){return(1-r)*(1-r)*f[n]+2*(1-r)*r*o[n]+r*r*u[n]}));return new k(n,"lab")};else if(4===r.length){var c;t=r.map((function(r){return r.lab()})),f=t[0],o=t[1],u=t[2],c=t[3],a=function(r){var n=[0,1,2].map((function(n){return(1-r)*(1-r)*(1-r)*f[n]+3*(1-r)*(1-r)*r*o[n]+3*(1-r)*r*r*u[n]+r*r*r*c[n]}));return new k(n,"lab")}}else{if(!(r.length>=5))throw new RangeError("No point in running bezier with only one color.");var i,l,h;i=r.map((function(r){return r.lab()})),h=r.length-1,l=function(r){for(var n=[1,1],e=1;et?(e+.05)/(t+.05):(t+.05)/(e+.05)},contrastAPCA:function(r,n){r=new k(r),n=new k(n),r.alpha()<1&&(r=on(n,r,r.alpha(),"rgb"));var e=Yn.apply(void 0,r.rgb()),t=Yn.apply(void 0,n.rgb()),a=e>=Gn?e:e+Math.pow(Gn-e,1.414),f=t>=Gn?t:t+Math.pow(Gn-t,1.414),o=Math.pow(f,.56)-Math.pow(a,.57),u=Math.pow(f,.65)-Math.pow(a,.62),c=Math.abs(f-a)<5e-4?0:a0?c-.027:c+.027)},cubehelix:function(r,n,e,a,f){void 0===r&&(r=300),void 0===n&&(n=-1.5),void 0===e&&(e=1),void 0===a&&(a=1),void 0===f&&(f=[0,1]);var o,u=0;"array"===c(f)?o=f[1]-f[0]:(o=0,f=[f,f]);var i=function(c){var i=v*((r+120)/360+n*c),l=Nn(f[0]+o*c,a),h=(0!==u?e[0]+c*u:e)*l*(1-l)/2,s=An(i),d=_n(i);return M(t([255*(l+h*(-.14861*s+1.78277*d)),255*(l+h*(-.29227*s-.90649*d)),255*(l+h*(1.97294*s)),1]))};return i.start=function(n){return null==n?r:(r=n,i)},i.rotations=function(r){return null==r?n:(n=r,i)},i.gamma=function(r){return null==r?a:(a=r,i)},i.hue=function(r){return null==r?e:("array"===c(e=r)?0===(u=e[1]-e[0])&&(e=e[1]):u=0,i)},i.lightness=function(r){return null==r?f:("array"===c(r)?(f=r,o=r[1]-r[0]):(f=[r,r],o=0),i)},i.scale=function(){return M.scale(i)},i.hue(e),i},deltaE:function(r,n,e,t,a){void 0===e&&(e=1),void 0===t&&(t=1),void 0===a&&(a=1);var f=function(r){return 360*r/(2*zn)},o=function(r){return 2*zn*r/360};r=new k(r),n=new k(n);var u=Array.from(r.lab()),c=u[0],i=u[1],l=u[2],h=Array.from(n.lab()),s=h[0],d=h[1],b=h[2],g=(c+s)/2,v=(qn(Cn(i,2)+Cn(l,2))+qn(Cn(d,2)+Cn(b,2)))/2,p=.5*(1-qn(Cn(v,7)/(Cn(v,7)+Cn(25,7)))),m=i*(1+p),y=d*(1+p),w=qn(Cn(m,2)+Cn(l,2)),M=qn(Cn(y,2)+Cn(b,2)),x=(w+M)/2,N=f($n(l,m)),_=f($n(b,y)),A=N>=0?N:N+360,j=_>=0?_:_+360,E=Sn(A-j)>180?(A+j+360)/2:(A+j)/2,R=1-.17*Wn(o(E-30))+.24*Wn(o(2*E))+.32*Wn(o(3*E+6))-.2*Wn(o(4*E-63)),O=j-A;O=Sn(O)<=180?O:j<=A?O+360:O-360,O=2*qn(w*M)*In(o(O)/2);var P=s-c,F=M-w,L=1+.015*Cn(g-50,2)/qn(20+Cn(g-50,2)),B=1+.045*x,G=1+.015*x*R,Y=30*Kn(-Cn((E-275)/25,2)),q=-(2*qn(Cn(x,7)/(Cn(x,7)+Cn(25,7))))*In(2*o(Y)),C=qn(Cn(P/(e*L),2)+Cn(F/(t*B),2)+Cn(O/(a*G),2)+q*(F/(t*B))*(O/(a*G)));return Zn(0,Xn(100,C))},distance:function(r,n,e){void 0===e&&(e="lab"),r=new k(r),n=new k(n);var t=r.get(e),a=n.get(e),f=0;for(var o in t){var u=(t[o]||0)-(a[o]||0);f+=u*u}return Math.sqrt(f)},input:w,interpolate:on,limits:Bn,mix:on,random:function(){for(var r="#",n=0;n<6;n++)r+="0123456789abcdef".charAt(jn(16*En()));return new k(r,"hex")},scale:wn,scales:Un,valid:function(){for(var r=[],n=arguments.length;n--;)r[n]=arguments[n];try{return new(Function.prototype.bind.apply(k,[null].concat(r))),!0}catch(r){return!1}},cmyk:N,css:xr,gl:Nr,hcg:Ar,hex:Fr,hsi:qr,hsl:Cr,hsv:Sr,lab:Wr,lch:Ir,hcl:Kr,num:zr,rgb:Vr,temp:Jr,kelvin:Jr,temperature:Jr,oklab:Qr,oklch:rn,getLabWhitePoint:R,setLabWhitePoint:E}),M})); diff --git a/docs/src/footer.inc.html b/docs/src/footer.inc.html index aa3f2ef6..1512869e 100644 --- a/docs/src/footer.inc.html +++ b/docs/src/footer.inc.html @@ -180,7 +180,7 @@ [ 'background-color:' + (isCSS ? val : col.hex()), 'color:' + (l < 0.7 ? 'white' : 'black'), - 'opacity:' + col.alpha() + ...(isCSS ? [] : ['opacity:' + col.alpha()]) ].join(';') ); diff --git a/docs/src/index.md b/docs/src/index.md index 0aa8a68d..6473e597 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -349,6 +349,19 @@ chroma.contrast('pink', 'hotpink'); chroma.contrast('pink', 'purple'); ``` +### chroma.contrastAPCA +#### (text, background) + +**New (3.1):** Computes the [APCA contrast](https://www.myndex.com/APCA/) ratio of a text color against its background color. The basic idea is that you check the contrast between the text and background color and then use [this lookup table](https://raw.githubusercontent.com/Myndex/apca-w3/master/images/APCAlookupByContrast.jpeg) to find the minimum font size you're allowed to use (given the font weight and purpose of the text). + +```js +chroma.contrastAPCA('hotpink', 'pink'); +chroma.contrastAPCA('purple', 'pink'); +``` + +Read more about how to interpret and use this metric at [APCA Readability Criterion](https://readtech.org/ARC). Please note that the APCA algorithm is still in beta and may change be subject to changes in the future. + + ### chroma.distance #### (color1, color2, mode='lab') diff --git a/index.js b/index.js index 3b117ce8..588cfac3 100644 --- a/index.js +++ b/index.js @@ -42,6 +42,7 @@ import scale from './src/generator/scale.js'; // other utility methods import { analyze } from './src/utils/analyze.js'; import contrast from './src/utils/contrast.js'; +import contrastAPCA from './src/utils/contrastAPCA.js'; import deltaE from './src/utils/delta-e.js'; import distance from './src/utils/distance.js'; import { limits } from './src/utils/analyze.js'; @@ -65,6 +66,7 @@ Object.assign(chroma, { Color, colors, contrast, + contrastAPCA, cubehelix, deltaE, distance, @@ -89,6 +91,7 @@ export { Color, colors, contrast, + contrastAPCA, cubehelix, deltaE, distance, diff --git a/index.umd.js b/index.umd.js index 0dc10314..08aaa994 100644 --- a/index.umd.js +++ b/index.umd.js @@ -58,6 +58,7 @@ import scale from './src/generator/scale.js'; // other utility methods import { analyze } from './src/utils/analyze.js'; import contrast from './src/utils/contrast.js'; +import contrastAPCA from './src/utils/contrastAPCA.js'; import deltaE from './src/utils/delta-e.js'; import distance from './src/utils/distance.js'; import { limits } from './src/utils/analyze.js'; @@ -81,6 +82,7 @@ Object.assign(chroma, { Color, colors, contrast, + contrastAPCA, cubehelix, deltaE, distance, diff --git a/src/utils/contrastAPCA.js b/src/utils/contrastAPCA.js new file mode 100644 index 00000000..05e05cd5 --- /dev/null +++ b/src/utils/contrastAPCA.js @@ -0,0 +1,68 @@ +import Color from '../Color.js'; +import mix from '../generator/mix.js'; + +/** + * @license + * + * The APCA contrast prediction algorithm is based of the formulas published + * in the APCA-1.0.98G specification by Myndex. The specification is available at: + * https://raw.githubusercontent.com/Myndex/apca-w3/master/images/APCAw3_0.1.17_APCA0.0.98G.svg + * + * Note that the APCA implementation is still beta, so please update to + * future versions of chroma.js when they become available. + * + * You can read more about the APCA Readability Criterion at + * https://readtech.org/ARC/ + */ + +// constants +const W_offset = 0.027; +const P_in = 0.0005; +const P_out = 0.1; +const R_scale = 1.14; +const B_threshold = 0.022; +const B_exp = 1.414; + +export default (text, bg) => { + // parse input colors + text = new Color(text); + bg = new Color(bg); + // if text color has alpha, blend against background + if (text.alpha() < 1) { + text = mix(bg, text, text.alpha(), 'rgb'); + } + const l_text = lum(...text.rgb()); + const l_bg = lum(...bg.rgb()); + + // soft clamp black levels + const Y_text = + l_text >= B_threshold + ? l_text + : l_text + Math.pow(B_threshold - l_text, B_exp); + const Y_bg = + l_bg >= B_threshold ? l_bg : l_bg + Math.pow(B_threshold - l_bg, B_exp); + + // normal polarity (dark text on light background) + const S_norm = Math.pow(Y_bg, 0.56) - Math.pow(Y_text, 0.57); + // reverse polarity (light text on dark background) + const S_rev = Math.pow(Y_bg, 0.65) - Math.pow(Y_text, 0.62); + // clamp noise then scale + const C = + Math.abs(Y_bg - Y_text) < P_in + ? 0 + : Y_text < Y_bg + ? S_norm * R_scale + : S_rev * R_scale; + // clamp minimum contrast then offset + const S_apc = Math.abs(C) < P_out ? 0 : C > 0 ? C - W_offset : C + W_offset; + // scale to 100 + return S_apc * 100; +}; + +function lum(r, g, b) { + return ( + 0.2126729 * Math.pow(r / 255, 2.4) + + 0.7151522 * Math.pow(g / 255, 2.4) + + 0.072175 * Math.pow(b / 255, 2.4) + ); +} diff --git a/test/contrast.test.js b/test/contrast.test.js index 7ed5eaeb..51ec8be0 100644 --- a/test/contrast.test.js +++ b/test/contrast.test.js @@ -1,4 +1,5 @@ import { describe, it, expect } from 'vitest'; +import contrastAPCA from '../src/utils/contrastAPCA.js'; import chroma from 'chroma-js'; const contrast = chroma.contrast; @@ -24,3 +25,33 @@ describe('Testing contrast ratio', () => { expect(contrast('black', '#222').toFixed(2)).toBe('1.32'); }); }); + +describe('Testing contrast ratio with APCA', () => { + it('maximum contrast', () => { + expect(+contrastAPCA('black', 'white').toFixed(1)).toBe(106); + expect(+contrastAPCA('white', 'black').toFixed(1)).toBe(-107.9); + }); + + it('minimum contrast', () => { + expect(+contrastAPCA('gray', 'gray').toFixed(1)).toBe(0); + }); + + it('contrast without alpha', () => { + expect(+contrastAPCA('#594d45', '#ffd4d4').toFixed(1)).toBe(69.0); + expect(+contrastAPCA('#b04646', '#d6d6d6').toFixed(1)).toBe(52.9); + expect(+contrastAPCA('#c2afaf', '#d6d6d6').toFixed(1)).toBe(17.0); + }); + + it('contrast with alpha', () => { + // todo: there's a slight difference to the values shown in the APCA demo + // when computing contrast between colors with alpha + expect(+contrastAPCA('#00000044', 'white').toFixed(1)).toBe(37.3); // 36.7 + expect(+contrastAPCA('#ffffffc0', 'black').toFixed(1)).toBe(-68); // -68.6 + }); + + it('inverse contrast', () => { + expect(+contrastAPCA('#f5f5b3', '#614f63').toFixed(1)).toBe(-81.7); + expect(+contrastAPCA('#67a7d6', '#4f6357').toFixed(1)).toBe(-30.5); + expect(+contrastAPCA('#d667cb', '#b04646').toFixed(1)).toBe(-17.9); + }); +});