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