UNPKG

adverich-kun-ui

Version:

Una librería de componentes Vue.js con Tailwind CSS

95 lines (94 loc) 2.02 kB
import { inject as l, reactive as u, readonly as f } from "vue"; const a = { locale: "es-AR", precision: 2, currency: { value: "ARS", name: "Pesos Argentinos", symbol: "$" }, date: { dateFormat: { weekday: "short", day: "2-digit", month: "short", year: "2-digit" }, dateTimeFormat: { weekday: "short", day: "2-digit", month: "short", year: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23" } } }; function s(e, r) { const i = { ...e }; for (const t of Object.keys(r)) r[t] !== null && typeof r[t] == "object" && !Array.isArray(r[t]) && e[t] !== null && typeof e[t] == "object" && !Array.isArray(e[t]) ? i[t] = s(e[t], r[t]) : i[t] = r[t]; return i; } const n = u({ ...a }), y = Symbol("kunConfig"), d = { // Acceso readonly para evitar mutaciones directas get current() { return f(n); }, // Acceso directo a valores (reactivo) get locale() { return n.locale; }, get precision() { return n.precision; }, get currency() { return n.currency; }, get date() { return n.date; }, // Configurar (merge profundo) configure(e = {}) { const r = s(n, e); Object.assign(n, r); }, // Reset a valores por defecto reset() { Object.assign(n, s({}, a)); }, // Setters individuales para configuración dinámica setLocale(e) { n.locale = e; }, setPrecision(e) { n.precision = e; }, setCurrency(e) { typeof e == "string" ? n.currency.value = e : typeof e == "object" && Object.assign(n.currency, e); } }; function m() { const e = l(y, null); return e || d.current; } function p(e, r, i) { if (e != null) return e; const t = r.split("."); let o = n; for (const c of t) if (o && typeof o == "object" && c in o) o = o[c]; else return i; return o ?? i; } export { y as KUN_CONFIG_KEY, d as kunConfig, p as resolveConfigValue, m as useKunConfig };