import{w as y,L as p,C as h,A as s,D as i,E as C}from"./index-yJ8X--q8.js";/*!
 * KoliBri - The accessible HTML-Standard
 */const b=(r,o,t)=>(r*299+o*587+t*114)/1e3>=128?-1:1,g=(r,o,t,n=1)=>{const e=[Math.max(Math.min(Math.round(o[0]+n*Math.max(1,o[0]/100)),255),0),Math.max(Math.min(Math.round(o[1]+n*Math.max(1,o[1]/100)),255),0),Math.max(Math.min(Math.round(o[2]+n*Math.max(1,o[2]/100)),255),0)],a=C(i.hex(`rgba(${r.join(",")},1)`),i.hex(`rgba(${e.join(",")},1)`)),l=e[0]+e[1]+e[2];return l===0||l===765||a>t?{background:r,foreground:e,contrast:a}:g(r,e,t,n)},u=new Map,m=(r,o,t,n=1)=>{if(u.has(r))return u.get(r);const e=g(r,o,t,n);return u.set(r,e),e},f=(r,o=7)=>{let t=[0,0,0,1],n=[255,255,255,1];typeof r=="string"?(t=s(r),n=t):typeof r=="object"&&r!==null&&typeof r.background=="string"&&typeof r.foreground=="string"&&(t=s(r.background),typeof r.foreground=="string"?n=s(r.foreground):n=t);const e=b(t[0],t[1],t[2]),a=m([t[0],t[1],t[2]],[n[0],n[1],n[2]],o,e);return n=[...a.foreground,1],{background:i.hex(`rgba(${t.join(",")})`),foreground:i.hex(`rgba(${n.join(",")})`),contrast:a.contrast}},k=/^#((\d|[a-f]){8}|(\d|[a-f]){6}|(\d|[a-f]){3,4})$/i;function x(r){return k.test(r)}function M(r){if(r.startsWith("{"))try{const o=JSON.parse(r);if(d(o))return{type:"ColorPair",value:o}}catch{return{type:null,value:null}}return{type:null,value:null}}function c(r){if(r)if(typeof r=="string"){if(x(r))return{type:"string",valid:!0,value:r};{const o=M(r);if(o.value)return{type:o.type,valid:!0,value:o.value}}}else{const o=r;if(d(o))return{type:"ColorPair",valid:!0,value:o}}return{type:null,valid:!1,value:""}}function d(r){return!!(typeof r=="object"&&r&&typeof r.backgroundColor=="string"&&(typeof r.foregroundColor=="string"||r.foregroundColor&&typeof r.foregroundColor.primary=="string"&&typeof r.foregroundColor.secondary=="string"&&typeof r.foregroundColor.neutral=="string"))}function v(r){const o=c(r);switch(o.type){case null:return!1;case"string":case"ColorPair":return o.valid}}const $=(r,o,t)=>{y(r,"_color",v,new Set(["rgb in hex","ColorPair"]),o,t)},P=r=>{var o;let t;const n=c(r);switch(n.type){case"string":t=f(n.value);break;case"ColorPair":{const e=n.value;let a="";typeof e.foregroundColor=="string"?a=e.foregroundColor:!((o=e.foregroundColor)===null||o===void 0)&&o.primary&&(a=e.foregroundColor.primary),(!a||typeof a!="string")&&(a="#fff"),t=f({background:e.backgroundColor,foreground:a});break}case null:p.warn(`_color was empty or invalid (${JSON.stringify(r)})`),t=f({background:"#000",foreground:"#000"})}return t.contrast<7&&h(`[KolBadge] The contrast of ${t.contrast} (≥7, AAA) is to low, between the color pair ${t.background} and ${t.foreground}.`),{backgroundColor:t.background,foregroundColor:t.foreground}};export{P as h,$ as v};
//# sourceMappingURL=color-DLr6p32D-joX86x11.js.map
