(function(c,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(c=typeof globalThis<"u"?globalThis:c||self,h(c.contrastrast={}))})(this,function(c){"use strict";const R={fallbackOption:"dark",throwErrorOnUnhandled:!1},E=t=>{let e=t;t.length===3&&(e=Array.from(t).map(s=>s+s).join(""));const n=parseInt(e.slice(0,2),16),r=parseInt(e.slice(2,4),16),o=parseInt(e.slice(4,6),16);return{r:n,g:r,b:o}},O=(t,e,n)=>{const r=parseInt(t,10)/360,o=parseInt(e,10)/100,s=parseInt(n,10)/100;let l,i,d;if(o==0)l=i=d=s;else{const u=(f,b,a)=>(a<0&&(a+=1),a>1&&(a-=1),a<.16666666666666666?f+(b-f)*6*a:a<.5?b:a<.6666666666666666?f+(b-f)*(.6666666666666666-a)*6:f),g=s<.5?s*(1+o):s+o-s*o,p=2*s-g;l=u(p,g,r+1/3)*255,i=u(p,g,r)*255,d=u(p,g,r-1/3)*255}return{r:l,g:i,b:d}},T=(t,e,n)=>({r:parseInt(t,10),b:parseInt(n,10),g:parseInt(e,10)}),m=/rgb\((0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),\s*(0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),\s*(0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d)\)/i,G=/^#?([a-f0-9]{6}|[a-f0-9]{3})$/i,H=/hsl\(\s*((?:360|3[0-5][0-9]|2[0-9][0-9]|1[0-9][0-9]|(?:100|0{0,1}[0-9][0-9]|0{0,1}0{0,1}[0-9])))(?:°|deg){0,1}\s*,{0,1}\s*((?:100|0{0,1}[0-9][0-9]|0{0,1}0{0,1}[0-9])(?:\.\d+)?)%{0,1}\s*,{0,1}\s*((?:100|0{0,1}[0-9][0-9]|0{0,1}0{0,1}[0-9])(?:\.\d+)?)%{0,1}\)/i,I=t=>{const[e,n,r,o]=t.match(m)||[];if(e)return T(n,r,o);const[,s]=t.match(G)||[];if(s)return E(s);const[l,i,d,u]=t.match(H)||[];if(l)return O(i,d,u);throw new Error(`Unsupported color string "${t}"`)},C=(t,e={})=>{const n={...R,...e};try{const r=I(t);return Math.round((r.r*299+r.g*587+r.b*114)/1e3)>124?"dark":"light"}catch(r){if(n.throwErrorOnUnhandled)throw new Error(`[contrastrast] Error while reading color, using default value "${n.fallbackOption}" `);return console.error(`[contrastrast] Error while reading color, using default value "${n.fallbackOption}" `,r),n.fallbackOption}};c.textContrastForBGColor=C,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});