UNPKG

@fefade/vue

Version:

Reusable Vue UI components powered by the fefade core system.

129 lines (126 loc) 5.27 kB
var l = "fefade", m = "ff", k = "x-library-name", p = `--${m}`, s = `${m}-theme`, c = "data-theme", $ = { light: `[${c}='light']`, dark: `[${c}='dark']` }, d = { light: { success: "#22c55e", onSuccess: "#124a28", error: "#ef4444", onError: "#511111", warning: "#f97316", onWarning: "#6c2710", info: "#58c5fcff", onInfo: "#003344" }, dark: { success: "#124a28", onSuccess: "#22c55e", error: "#511111", onError: "#ef4444", warning: "#6c2710", onWarning: "#f97316", info: "#003344ff", onInfo: "#a7dffc" } }, y = { light: { primary: "#171717", onPrimary: "#fafafa", secondary: "#f5f5f5", onSecondary: "#171717", muted: "#a3a3a3", bg: "#ffffff", onBg: "#262626", surface: "#f8f8f8", onSurface: "#0a0a0a", border: "#e5e5e5", disabled: "#d4d4d4", onDisabled: "#737373", skeleton: "#e5e5e5", onSkeleton: "#f9f9f9", overlay: "#00000066", shadow: "#0000001A", ...d.light }, dark: { primary: "#e5e5e5", onPrimary: "#171717", secondary: "#262626", onSecondary: "#fafafa", muted: "#a3a3a3", bg: "#0a0a0a", onBg: "#fafafa", surface: "#171717", onSurface: "#fafafa", border: "#ffffff1a", disabled: "#f0f0f033", onDisabled: "#e5e5e566", skeleton: "#525252cc", onSkeleton: "#737373", overlay: "#00000099", shadow: "#00000080", ...d.dark } }; Object.fromEntries(Object.keys(y.light).map((e) => [e, `var(${p}-${C(e)})`])); var A = { sm: "425px", md: "768px", lg: "1024px", xl: "1440px", "2xl": "2560px" }; function u(e, t) { for (let r in t) t[r] && typeof t[r] == "object" && !Array.isArray(t[r]) ? e[r] = u(e[r] || {}, t[r]) : e[r] = t[r]; return e; } function S() { let e = document.createElement("meta"); return e.name = k, e.content = l, e; } function w() { function e(n) { return document.documentElement.style.colorScheme = n, document.documentElement.setAttribute(c, n), localStorage.setItem(s, n), n; } function t(n) { let o = localStorage.getItem(s), a = document.documentElement.getAttribute(c); return o || a || (window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : n); } function r(n) { let o = t() === "light" ? "dark" : "light"; return e(o), n && typeof n == "function" && n?.(o), o; } return { applyThemeMode: e, storedTheme: t, toggleThemeMode: r }; } function j() { function e(n) { return `${p}-${n.replace(/([A-Z])/g, "-$1").toLowerCase()}`; } function t(n, o) { return ` ${e(n)}: ${o};`; } function r(n, o) { return `${n} { ${o.join(` `)} }`; } return { toCssDeclaration: t, createBlock: r }; } function x() { let { toCssDeclaration: e, createBlock: t } = j(); function r(o) { return o ? Object.entries(o).map(([a, f]) => { let i = $[a], g = Object.entries(f).map(([h, b]) => e(h, b)); return t(i, g); }).join(` `) : ""; } function n(o) { if (!o) return ""; let a = Object.entries(o).map(([f, i]) => e(f, i)); return t(":root", a); } return { themeCssString: r, breakpointCssString: n }; } function M() { function e(r) { return ` <script id="${l}-script"> (function () { const fallbackTheme = "${r}"; const storedTheme = localStorage.getItem("${s}"); const prefersDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; const theme = storedTheme || (prefersDark ? "dark" : fallbackTheme); document.documentElement.setAttribute("${c}", theme); document.documentElement.style.colorScheme = storedTheme; })() <\/script> `; } function t(r, ...n) { let { themeCssString: o, breakpointCssString: a } = x(), f = o(u(y, r?.colors || {})), i = a(u(A, r?.breakpoints || {})); return ` <style id="${l}-style"> ${f} ${i} ${n.join(` `)} </style> `; } return { ...w(), script: e, style: t, createMetaElement: S }; } function T(e) { return e; } function E(...e) { return e.flatMap((t) => { if (!t) return []; if (Array.isArray(t) && t.length === 2 && (Array.isArray(t[0]) || typeof t[0] == "string" || t[0] === void 0 || t[0] === null) && typeof t[1] == "object" && t[1] !== null && !Array.isArray(t[1])) { let [n, o] = t; return (Array.isArray(n) ? n.filter(Boolean) : typeof n == "string" ? n.trim().split(/\s+/) : []).map((a) => o[a] || a); } let r = t; return typeof r == "string" ? r.trim().split(/\s+/) : typeof r == "number" ? [r.toString()] : typeof r == "boolean" ? r ? ["true"] : [] : Array.isArray(r) ? r.filter(Boolean).flatMap((n) => E(n).split(/\s+/)).filter(Boolean) : typeof r == "object" && r !== null ? Object.entries(r).filter(([n, o]) => !!o).map(([n]) => n) : []; }).filter(Boolean).join(" "); } function v(e, t, r) { return e && typeof e == "object" && t in e ? e[t] ?? r : r; } function B(e) { if (typeof e == "number") return `${e}px`; if (typeof e == "string") { let t = e.trim(); return /^\d+(\.\d+)?$/.test(t) ? `${t}px` : t; } return "0px"; } function C(e) { return e.replace(/[A-Z]/g, (t) => `-${t.toLowerCase()}`); } function D({ href: e, download: t, target: r, onClick: n }) { if (t && e) { let o = document.createElement("a"); o.href = e, o.download = t, document.body.appendChild(o), o.click(), document.body.removeChild(o); } else e ? window.open(e, r) : n?.(); } export { T as J, D as P, B as R, M as Y, v as _, E as b };