/*!
 * KoliBri - The accessible HTML-Standard
 */
import{l as t,m as r,r as a,n,q as o}from"./common-DEEjER7G.js";function s(n){if(Array.isArray(n)&&n.raw)n=String.raw(...arguments);var o;var s=t(n);if(!s.space)return[];const e=s.space[0]==="h"?r.min:a.min;const h=s.space[0]==="h"?r.max:a.max;o=Array(3);o[0]=Math.min(Math.max(s.values[0],e[0]),h[0]);o[1]=Math.min(Math.max(s.values[1],e[1]),h[1]);o[2]=Math.min(Math.max(s.values[2],e[2]),h[2]);if(s.space[0]==="h"){o=r.rgb(o)}o.push(Math.min(Math.max(s.alpha,0),1));return o}const e=(t,r,a)=>{const n=(t*299+r*587+a*114)/1e3;return n>=128?-1:1};const h=(t,r,a,s=1)=>{const e=[Math.max(Math.min(Math.round(r[0]+s*Math.max(1,r[0]/100)),255),0),Math.max(Math.min(Math.round(r[1]+s*Math.max(1,r[1]/100)),255),0),Math.max(Math.min(Math.round(r[2]+s*Math.max(1,r[2]/100)),255),0)];const c=o(n.hex(`rgba(${t.join(",")},1)`),n.hex(`rgba(${e.join(",")},1)`));const M=e[0]+e[1]+e[2];if(M===0||M===765||c>a){return{background:t,foreground:e,contrast:c}}else{return h(t,e,a,s)}};const c=new Map;const M=(t,r,a,n=1)=>{if(c.has(t)){return c.get(t)}const o=h(t,r,a,n);c.set(t,o);return o};const f=(t,r=7)=>{let a=[0,0,0,1];let o=[255,255,255,1];if(typeof t==="string"){a=s(t);o=a}else if(typeof t==="object"&&t!==null&&typeof t.background==="string"&&typeof t.foreground==="string"){a=s(t.background);if(typeof t.foreground==="string"){o=s(t.foreground)}else{o=a}}const h=e(a[0],a[1],a[2]);const c=M([a[0],a[1],a[2]],[o[0],o[1],o[2]],r,h);o=[...c.foreground,1];return{background:n.hex(`rgba(${a.join(",")})`),foreground:n.hex(`rgba(${o.join(",")})`),contrast:c.contrast}};export{f as c,s as r};
//# sourceMappingURL=contrast-C0oqtcfU.js.map