@scalar/api-client
Version:
the open source API testing client
22 lines (21 loc) • 772 B
JavaScript
import { z as n } from "zod";
const f = async (a) => {
const i = new CSSStyleSheet();
return await i.replace(a), Array.from(i.cssRules).reduce(
(e, r) => {
if (!(r instanceof CSSStyleRule))
return e;
const l = Object.values(r.style).reduce((t, s) => {
if (!s.startsWith("--"))
return t;
const o = n.string().regex(/^(?:#(?:[0-9A-F]{6}|[0-9A-F]{8}))$/i).safeParse(r.style.getPropertyValue(s).toUpperCase().trim());
return o.error || (t[s] = o.data), t;
}, {});
return r.selectorText.includes(".light-mode") && (e.light = { ...e.light, ...l }), r.selectorText.includes(".dark-mode") && (e.dark = { ...e.dark, ...l }), e;
},
{ light: {}, dark: {} }
);
};
export {
f as loadCssVariables
};