UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

5 lines 1.65 kB
/*! * KoliBri - The accessible HTML-Standard */ import{L as r,k as t,b as e}from"./common-Cx_AGO_M.js";import{c as o}from"./contrast-DlURrMX4.js";const n=/^#((\d|[a-f]){8}|(\d|[a-f]){6}|(\d|[a-f]){3,4})$/i;function a(r){return n.test(r)}function l(r){if(r.startsWith("{")){try{const t=JSON.parse(r);if(s(t))return{type:"ColorPair",value:t}}catch(r){return{type:null,value:null}}}return{type:null,value:null}}function i(r){if(r){if(typeof r==="string"){if(a(r))return{type:"string",valid:true,value:r};else{const t=l(r);if(t.value)return{type:t.type,valid:true,value:t.value}}}else{const t=r;if(s(t))return{type:"ColorPair",valid:true,value:t}}}return{type:null,valid:false,value:""}}function s(r){return!!(typeof r==="object"&&r&&typeof r.backgroundColor==="string"&&typeof r.foregroundColor==="string")}function u(r){const t=i(r);switch(t.type){case null:return false;case"string":case"ColorPair":return t.valid}}const c=(r,t,o)=>{e(r,"_color",u,new Set(["rgb in hex","ColorPair"]),t,o)};const f=e=>{let n;const a=i(e);switch(a.type){case"string":n=o(a.value);break;case"ColorPair":{const r=a.value;let t="";if(typeof r.foregroundColor==="string")t=r.foregroundColor;if(!t||typeof t!=="string")t="#fff";n=o({background:r.backgroundColor,foreground:t});break}case null:r.warn(`_color was empty or invalid (${JSON.stringify(e)})`);n=o({background:"#000",foreground:"#000"})}if(n.contrast<7){t(`[KolBadge] The contrast of ${n.contrast} (≥7, AAA) is to low, between the color pair ${n.background} and ${n.foreground}.`)}return{backgroundColor:n.background,foregroundColor:n.foreground}};export{f as h,c as v}; //# sourceMappingURL=color-CAVnI0e-.js.map