(function(d,x){typeof exports=="object"&&typeof module<"u"?x(exports):typeof define=="function"&&define.amd?define(["exports"],x):(d=typeof globalThis<"u"?globalThis:d||self,x(d.umbra={}))})(this,function(d){"use strict";var x={grad:.9,turn:360,rad:360/(2*Math.PI)},p=function(n){return typeof n=="string"?n.length>0:typeof n=="number"},b=function(n,t,r){return t===void 0&&(t=0),r===void 0&&(r=Math.pow(10,t)),Math.round(r*n)/r+0},h=function(n,t,r){return t===void 0&&(t=0),r===void 0&&(r=1),n>r?r:n>t?n:t},V=function(n){return(n=isFinite(n)?n%360:0)>0?n:n+360},j=function(n){return{r:h(n.r,0,255),g:h(n.g,0,255),b:h(n.b,0,255),a:h(n.a)}},N=function(n){return{r:b(n.r),g:b(n.g),b:b(n.b),a:b(n.a,3)}},kn=/^#([0-9a-f]{3,8})$/i,$=function(n){var t=n.toString(16);return t.length<2?"0"+t:t},q=function(n){var t=n.r,r=n.g,e=n.b,o=n.a,a=Math.max(t,r,e),s=a-Math.min(t,r,e),i=s?a===t?(r-e)/s:a===r?2+(e-t)/s:4+(t-r)/s:0;return{h:60*(i<0?i+6:i),s:a?s/a*100:0,v:a/255*100,a:o}},J=function(n){var t=n.h,r=n.s,e=n.v,o=n.a;t=t/360*6,r/=100,e/=100;var a=Math.floor(t),s=e*(1-r),i=e*(1-(t-a)*r),f=e*(1-(1-t+a)*r),c=a%6;return{r:255*[e,i,s,s,f,e][c],g:255*[f,e,e,i,s,s][c],b:255*[s,s,f,e,e,i][c],a:o}},K=function(n){return{h:V(n.h),s:h(n.s,0,100),l:h(n.l,0,100),a:h(n.a)}},Q=function(n){return{h:b(n.h),s:b(n.s),l:b(n.l),a:b(n.a,3)}},Z=function(n){return J((r=(t=n).s,{h:t.h,s:(r*=((e=t.l)<50?e:100-e)/100)>0?2*r/(e+r)*100:0,v:e+r,a:t.a}));var t,r,e},M=function(n){return{h:(t=q(n)).h,s:(o=(200-(r=t.s))*(e=t.v)/100)>0&&o<200?r*e/100/(o<=100?o:200-o)*100:0,l:o/2,a:t.a};var t,r,e,o},xn=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Mn=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Cn=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Sn=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,I={string:[[function(n){var t=kn.exec(n);return t?(n=t[1]).length<=4?{r:parseInt(n[0]+n[0],16),g:parseInt(n[1]+n[1],16),b:parseInt(n[2]+n[2],16),a:n.length===4?b(parseInt(n[3]+n[3],16)/255,2):1}:n.length===6||n.length===8?{r:parseInt(n.substr(0,2),16),g:parseInt(n.substr(2,2),16),b:parseInt(n.substr(4,2),16),a:n.length===8?b(parseInt(n.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(n){var t=Cn.exec(n)||Sn.exec(n);return t?t[2]!==t[4]||t[4]!==t[6]?null:j({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(n){var t=xn.exec(n)||Mn.exec(n);if(!t)return null;var r,e,o=K({h:(r=t[1],e=t[2],e===void 0&&(e="deg"),Number(r)*(x[e]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return Z(o)},"hsl"]],object:[[function(n){var t=n.r,r=n.g,e=n.b,o=n.a,a=o===void 0?1:o;return p(t)&&p(r)&&p(e)?j({r:Number(t),g:Number(r),b:Number(e),a:Number(a)}):null},"rgb"],[function(n){var t=n.h,r=n.s,e=n.l,o=n.a,a=o===void 0?1:o;if(!p(t)||!p(r)||!p(e))return null;var s=K({h:Number(t),s:Number(r),l:Number(e),a:Number(a)});return Z(s)},"hsl"],[function(n){var t=n.h,r=n.s,e=n.v,o=n.a,a=o===void 0?1:o;if(!p(t)||!p(r)||!p(e))return null;var s=function(i){return{h:V(i.h),s:h(i.s,0,100),v:h(i.v,0,100),a:h(i.a)}}({h:Number(t),s:Number(r),v:Number(e),a:Number(a)});return J(s)},"hsv"]]},_=function(n,t){for(var r=0;r=.5},n.prototype.toHex=function(){return t=N(this.rgba),r=t.r,e=t.g,o=t.b,s=(a=t.a)<1?$(b(255*a)):"","#"+$(r)+$(e)+$(o)+s;var t,r,e,o,a,s},n.prototype.toRgb=function(){return N(this.rgba)},n.prototype.toRgbString=function(){return t=N(this.rgba),r=t.r,e=t.g,o=t.b,(a=t.a)<1?"rgba("+r+", "+e+", "+o+", "+a+")":"rgb("+r+", "+e+", "+o+")";var t,r,e,o,a},n.prototype.toHsl=function(){return Q(M(this.rgba))},n.prototype.toHslString=function(){return t=Q(M(this.rgba)),r=t.h,e=t.s,o=t.l,(a=t.a)<1?"hsla("+r+", "+e+"%, "+o+"%, "+a+")":"hsl("+r+", "+e+"%, "+o+"%)";var t,r,e,o,a},n.prototype.toHsv=function(){return t=q(this.rgba),{h:b(t.h),s:b(t.s),v:b(t.v),a:b(t.a,3)};var t},n.prototype.invert=function(){return u({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},n.prototype.saturate=function(t){return t===void 0&&(t=.1),u(A(this.rgba,t))},n.prototype.desaturate=function(t){return t===void 0&&(t=.1),u(A(this.rgba,-t))},n.prototype.grayscale=function(){return u(A(this.rgba,-1))},n.prototype.lighten=function(t){return t===void 0&&(t=.1),u(Y(this.rgba,t))},n.prototype.darken=function(t){return t===void 0&&(t=.1),u(Y(this.rgba,-t))},n.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},n.prototype.alpha=function(t){return typeof t=="number"?u({r:(r=this.rgba).r,g:r.g,b:r.b,a:t}):b(this.rgba.a,3);var r},n.prototype.hue=function(t){var r=M(this.rgba);return typeof t=="number"?u({h:t,s:r.s,l:r.l,a:r.a}):b(r.h)},n.prototype.isEqual=function(t){return this.toHex()===u(t).toHex()},n}(),u=function(n){return n instanceof B?n:new B(n)},nn=[],Rn=function(n){n.forEach(function(t){nn.indexOf(t)<0&&(t(B,I),nn.push(t))})};const R={readability:70,insertion:9,shades:[5,5,5,5,15,10,10,25,30,25,25,25],tints:[5,10,10,10,15,15,25,15,15,15,15,25]},w={background:"#090233",foreground:"#ff5555",accents:["#5200ff"],settings:R,inversed:{background:"#ff5555",foreground:"#090233",accents:["#5200ff"]}},wn={background:"base","background-10":"base-10","background-20":"base-20","background-30":"base-30","background-40":"base-40","midground-50":"base-40","midground-60":"base-50","midground-70":"base-60","midground-80":"base-70","foreground-90":"base-70","foreground-100":"base-80","foreground-110":"base-90","foreground-120":"base-100",foreground:"base-contrast"};let tn=0,C=[];function Tn(n){if(!n)return;tn++;const t=C.find(e=>e.selector===n);return t?C[t.index].iterations++:C.push({index:C.length,selector:n,iterations:1}),`${t?`${C[t.index].iterations}`:"1"}-${tn}`}function rn({outputs:n,target:t,alias:r}){const e=Tn(t.selector),o=n.flattened.filter(({name:a})=>!Nn(a));if(t.element&&Dn(t.element,o),t.selector&&In(t.selector,o,e),r){const s=Object.entries(r===!0?wn:r).map(([i,f])=>({name:"--"+i,color:`var(--${f})`}));t.element&&Bn(t.element,s),t.selector&&An(t.selector,s,e)}return n}function Nn(n){return/(?:background|foreground).*contrast/i.test(n)}function en(n,{selector:t=":root",meta:r="1",marker:e="theme"}){const o=new CSSStyleSheet;return o.replace(`${e}-${r}, ${t} {${n.map(({name:a,color:s})=>`${a}: ${s};`).join("")}}`),o}function In(n=":root",t,r){const e="theme",o=en(t,{meta:r,marker:e,selector:n});on(o,n,e)}function An(n=":root",t,r){const e="alias",o=en(t,{meta:r,marker:e,selector:n});on(o,n,e)}function on(n,t,r="theme"){const e=[...document.adoptedStyleSheets].filter(o=>{const a=o.cssRules[0].cssText.includes(r),s=o.cssRules[0].cssText.includes(t);return!a||!s});document.adoptedStyleSheets=[...e,n]}const z=(n,{name:t,color:r})=>{n.style.setProperty(t,r)};function Dn(n,t){n&&(t.forEach(({name:r,color:e})=>z(n,{name:r,color:e})),z(n,{name:"color",color:"var(--base-contrast)"}))}function Bn(n,t){n&&t.forEach(r=>z(n,r))}const an=({input:n,output:t=X().output,formater:r=sn,callback:e})=>{let o=0;function a(g){return g!=="accent"?g:(o++,o>1?g+o:g)}function s(g,v=sn){return{name:a(g.name),background:v(g.background),shades:g.range.map(U=>v(U)),foreground:v(g.foreground)}}const i=t.map(g=>s(g,r)),c={flattened:En({prefix:"--",formated:i}),formated:i,output:t,input:n};return{...c,attach:({target:g,alias:v})=>document?(e&&e(c),rn({outputs:c,alias:v,target:g||{selector:":root"}})):c}},sn=un;function un(n){return n.toHex()}function zn(n){const t=n.toRgb();return`${t.r} ${t.g} ${t.b}`}function En({formated:n,prefix:t}){const r=[];n.forEach(o=>{const a=t?t+o.name:o.name;r.push({name:a,color:o.background}),r.push(...e(o.shades,a)),r.push({name:a+"-contrast",color:o.foreground})});function e(o,a){return o.map((s,i)=>{const f=(+i+1)*10;return{name:a+"-"+f,color:s}})}return Wn(r)}function Wn(n){const t="--foreground",r="--background",e=n.filter(c=>c.name.startsWith(r)),o=n.filter(c=>c.name.startsWith(t)),a=n.filter(c=>!c.name.startsWith(r)&&!c.name.startsWith(t)),i=[...e,...o.reverse(),...a].filter(({name:c})=>!f(c));function f(c){return/(?:background|foreground).*contrast/i.test(c)}return i}var m=function(n,t,r){return t===void 0&&(t=0),r===void 0&&(r=1),n>r?r:n>t?n:t},E=function(n){var t=n/255;return t<.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)},W=function(n){return 255*(n>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n)},F=96.422,H=100,G=82.521,Fn=function(n){var t,r,e={x:.9555766*(t=n).x+-.0230393*t.y+.0631636*t.z,y:-.0282895*t.x+1.0099416*t.y+.0210077*t.z,z:.0122982*t.x+-.020483*t.y+1.3299098*t.z};return r={r:W(.032404542*e.x-.015371385*e.y-.004985314*e.z),g:W(-.00969266*e.x+.018760108*e.y+41556e-8*e.z),b:W(556434e-9*e.x-.002040259*e.y+.010572252*e.z),a:n.a},{r:m(r.r,0,255),g:m(r.g,0,255),b:m(r.b,0,255),a:m(r.a)}},Hn=function(n){var t=E(n.r),r=E(n.g),e=E(n.b);return function(o){return{x:m(o.x,0,F),y:m(o.y,0,H),z:m(o.z,0,G),a:m(o.a)}}(function(o){return{x:1.0478112*o.x+.0228866*o.y+-.050127*o.z,y:.0295424*o.x+.9904844*o.y+-.0170491*o.z,z:-.0092345*o.x+.0150436*o.y+.7521316*o.z,a:o.a}}({x:100*(.4124564*t+.3575761*r+.1804375*e),y:100*(.2126729*t+.7151522*r+.072175*e),z:100*(.0193339*t+.119192*r+.9503041*e),a:n.a}))},S=216/24389,y=24389/27,cn=function(n){var t=Hn(n),r=t.x/F,e=t.y/H,o=t.z/G;return r=r>S?Math.cbrt(r):(y*r+16)/116,{l:116*(e=e>S?Math.cbrt(e):(y*e+16)/116)-16,a:500*(r-e),b:200*(e-(o=o>S?Math.cbrt(o):(y*o+16)/116)),alpha:t.a}},Gn=function(n,t,r){var e,o=cn(n),a=cn(t);return function(s){var i=(s.l+16)/116,f=s.a/500+i,c=i-s.b/200;return Fn({x:(Math.pow(f,3)>S?Math.pow(f,3):(116*f-16)/y)*F,y:(s.l>8?Math.pow((s.l+16)/116,3):s.l/y)*H,z:(Math.pow(c,3)>S?Math.pow(c,3):(116*c-16)/y)*G,a:s.alpha})}({l:m((e={l:o.l*(1-r)+a.l*r,a:o.a*(1-r)+a.a*r,b:o.b*(1-r)+a.b*r,alpha:o.alpha*(1-r)+a.alpha*r}).l,0,400),a:e.a,b:e.b,alpha:m(e.alpha)})};function Pn(n){function t(r,e,o){o===void 0&&(o=5);for(var a=[],s=1/(o-1),i=0;i<=o-1;i++)a.push(r.mix(e,s*i));return a}n.prototype.mix=function(r,e){e===void 0&&(e=.5);var o=r instanceof n?r:new n(r),a=Gn(this.toRgb(),o.toRgb(),e);return new n(a)},n.prototype.tints=function(r){return t(this,"#fff",r)},n.prototype.shades=function(r){return t(this,"#000",r)},n.prototype.tones=function(r){return t(this,"#808080",r)}}/** @preserve ///// SAPC APCA - Advanced Perceptual Contrast Algorithm ///// Beta 0.1.9 W3 • contrast function only ///// DIST: W3 • Revision date: July 3, 2022 ///// Function to parse color values and determine Lc contrast ///// Copyright © 2019-2022 by Andrew Somers. All Rights Reserved. ///// LICENSE: W3 LICENSE ///// CONTACT: Please use the ISSUES or DISCUSSIONS tab at: ///// https://github.com/Myndex/SAPC-APCA/ ///// /////////////////////////////////////////////////////////////////////////////// ///// ///// MINIMAL IMPORTS: ///// import { APCAcontrast, sRGBtoY, displayP3toY, ///// calcAPCA, fontLookupAPCA } from 'apca-w3'; ///// import { colorParsley } from 'colorparsley'; ///// ///// FORWARD CONTRAST USAGE: ///// Lc = APCAcontrast( sRGBtoY( TEXTcolor ) , sRGBtoY( BACKGNDcolor ) ); ///// Where the colors are sent as an rgba array [255,255,255,1] ///// ///// Retrieving an array of font sizes for the contrast: ///// fontArray = fontLookupAPCA(Lc); ///// ///// Live Demonstrator at https://www.myndex.com/APCA/ // */const l={mainTRC:2.4,get mainTRCencode(){return 1/this.mainTRC},sRco:.2126729,sGco:.7151522,sBco:.072175,normBG:.56,normTXT:.57,revTXT:.62,revBG:.65,blkThrs:.022,blkClmp:1.414,scaleBoW:1.14,scaleWoB:1.14,loBoWoffset:.027,loWoBoffset:.027,deltaYmin:5e-4,loClip:.1,mFactor:1.9468554433171,get mFactInv(){return 1/this.mFactor},mOffsetIn:.0387393816571401,mExpAdj:.283343396420869,get mExp(){return this.mExpAdj/this.blkClmp},mOffsetOut:.312865795870758};function Ln(n,t,r=-1){const e=[0,1.1];if(isNaN(n)||isNaN(t)||Math.min(n,t)e[1])return 0;let o=0,a=0,s="BoW";return n=n>l.blkThrs?n:n+Math.pow(l.blkThrs-n,l.blkClmp),t=t>l.blkThrs?t:t+Math.pow(l.blkThrs-t,l.blkClmp),Math.abs(t-n)n?(o=(Math.pow(t,l.normBG)-Math.pow(n,l.normTXT))*l.scaleBoW,a=o-l.loClip?0:o+l.loWoBoffset),r<0?a*100:r==0?Math.round(Math.abs(a)*100)+""+s+"":Number.isInteger(r)?(a*100).toFixed(r):0)}function fn(n=[0,0,0]){function t(r){return Math.pow(r/255,l.mainTRC)}return l.sRco*t(n[0])+l.sGco*t(n[1])+l.sBco*t(n[2])}function P(){return`#${Math.floor(Math.random()*16777215).toString(16)}`}function On(n={amount:1}){return{background:P(),foreground:P(),accents:Array.from({length:n.amount},()=>P()),settings:{...R,...n}}}function Xn(n,t,r){return{readability:k(n,t),index:r}}function Un({range:n,shades:t,color:r}){const e=t.map((a,s)=>Xn(a,r,s)).reduce((a,s)=>a.readability0?u(n[0]):t}function ln(n){return n.reduce((t,r)=>(typeof r=="string"&&t.push(r),t),[])}function dn({number:n,fallback:t}){return typeof n>"u"?t:n}Rn([Pn]);const jn={readability:R.readability||11};function qn(n,t){const r=u(n).toRgb(),e=u(t).toRgb();return Ln(fn([r.r,r.g,r.b]),fn([e.r,e.g,e.b]))}const k=(n,t)=>Math.abs(qn(n,t)),gn=n=>{const t=u(n.foreground),r=u(n.background);return bn({color:t,contrast:r,condition:e=>{const o=k(e,r),a=dn({fallback:jn.readability,number:n.readability});return o>=a}})};function bn({color:n,contrast:t,condition:r}){let a=n,s=0;if(r(a,s))return a;for(;!r(a,s)&&s<120;)s+=1,a=Jn({power:.01,color:a,contrast:t});return a}const Jn=({color:n,contrast:t,power:r})=>{const e=n.isDark()===t.isDark();function o(){return n.isDark()?n.lighten(r):n.darken(r)}function a(){return t.isDark()?n.lighten(r):n.darken(r)}return e?o():a()};function L(n,t){const r=t.map(o=>Math.abs(k(n,o))),e=r.indexOf(Math.max(...r));return t[e]}const Kn=(n,t)=>L(n,[t.background||u("white"),t.foreground||u("black")]);function hn(n,t,r=50){const e=u(n),o=u(t);return u(e).mix(o,r/100)}function Qn(n){var f;const t=u(n.foreground).isDark(),r=u(n.background).isDark(),e=u(n.background),o=u(n.foreground),a=(f=n.settings)==null?void 0:f.readability;if(t!==r)return{background:n.foreground,foreground:n.background};const s=gn({foreground:o,background:e,readability:a});if(s.isDark()!==r)return{background:s.toRgbString(),foreground:n.background};function i(){const c=e.isDark()?u("white"):u("black"),g=e.isDark()?u("black"):u("white"),v=k(e,g);return bn({color:e,contrast:o,condition:U=>k(U,c)t?{...t,inversed:n}:{...n,...Qn(n),inversed:n},pn=n=>u(n).isDark();function Zn(n,t){return L(n,[t.background||n,t.foreground||n])}function O({from:n,to:t,range:r}){const e=ln(r);let o=n,a=e.length>0?u(e[0]):t;return r.map(s=>{if(typeof s=="string"){const i=u(s);return o=i,e.shift(),i}else{a=Vn(e,t);const i=hn(o,a,s);return o=i,i}})}function _n({input:n,adjusted:t,range:r,color:e}){if(!e)return r;const o=O({from:t.background,to:t.foreground,range:T(t,n.settings)||[]});return Un({range:r,shades:o,color:u(e)})}function Yn(n,t,r){const e=t||(r?ln(r)[0]:void 0);return e?u(e):n}function nt(n,t,r){const e=n.slice();return e[t]=r,e}function tt(n,t,r){var f;const e=typeof t=="string",o=e?t:t.color,a=(f=r.settings)==null?void 0:f.insertion,s=T(n,r.settings)||[],i=e?s:T(n,t)||s;return a&&o?nt(i,a,o):!a&&o?_n({input:r,adjusted:n,range:i,color:o}):i}function rt(n,t){const{background:r,foreground:e}=t;function o(a){const s=typeof a=="string",i=s?void 0:a.name,f=s?a:a.color,c=tt(t,a,n);return{name:i||"accent",background:Yn(t.foreground,f,c),foreground:Kn(r,t),range:O({from:r,to:e,range:c})}}return t.accents.map(a=>o(a))}function T(n,t){return n.background.isDark()?t==null?void 0:t.shades:t==null?void 0:t.tints}function et(n,t){const{background:r,foreground:e}=t,o=T(t,n.settings)||[];return{name:"base",background:r,foreground:e,range:O({from:r,to:e,range:o})}}function vn(n,t){return[et(n,t),...rt(n,t)]}function X(n=w){const t=ot(n),r=at(t);return yn({input:t,output:vn(t,r),inversed:t.inversed})}function ot(n=w){var o;const t={...R,...n.settings},r={settings:t,inversed:{...t,...(o=n.inversed)==null?void 0:o.settings}},e=n.inversed&&{...n.inversed,settings:r.inversed};return{...w,...n,settings:r.settings,inversed:e}}function at(n=w){var o;const t=u(n.background),r=gn({readability:dn({number:(o=n.settings)==null?void 0:o.readability,fallback:4}),foreground:u(n.foreground),background:t});return{accents:Array.isArray(n.accents)?n.accents:[n.accents],background:t,foreground:r}}function st(n){if(!n)return;const t=typeof n=="string";return{element:n instanceof HTMLElement||n===null?n:void 0,selector:t?n:void 0}}function yn({input:n,output:t,inversed:r}){function e(o){var s,i;const a=o||((s=n.settings)==null?void 0:s.formater);return an({output:t,formater:a,input:n,callback:(i=n.settings)==null?void 0:i.callback})}return{input:n,output:t,isDark:()=>pn(n.background),format:o=>e(o),inverse:()=>X(mn(n,r)),apply:o=>{var g;const{alias:a,formater:s}=o||{},i=st(o==null?void 0:o.target),c=e(s).attach({alias:a,target:i});return(g=n.settings)!=null&&g.callback&&n.settings.callback(c),c}}}d.attach=rn,d.colorMix=hn,d.findContrast=Zn,d.format=an,d.getReadability=k,d.hex=un,d.inverse=mn,d.isDark=pn,d.mostReadable=L,d.randomScheme=On,d.rgb=zn,d.umbra=X,d.umbraGenerate=vn,d.umbraHydrate=yn,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});