UNPKG

jade-garden

Version:

Class utilities to compose class names and variants

89 lines (88 loc) 2.81 kB
import { b as C, g as N, d as k, h as v } from "./utils-DleBZ90m.js"; const S = (t = C) => (a) => (n) => { const c = {}; if (typeof a?.slots != "object" || Object.keys(a.slots).length === 0 || typeof a.slots == "object" && Array.isArray(a.slots)) return c; const l = a.slots, A = a?.compoundSlots ?? [], m = (r) => { if (!Array.isArray(A)) return {}; const s = {}; for (const { slots: y = [], class: u, className: i, ...f } of A) if (v(f, r)) { for (const o of y) if (typeof o == "string") { const e = []; typeof u == "string" && e.push(u), Array.isArray(u) && e.push(...u), typeof i == "string" && e.push(i), Array.isArray(i) && e.push(...i), Object.hasOwn(s, o) || (s[o] = ""); const p = t(...e); s[o] += s[o].length === 0 ? p : ` ${p}`; } } return s; }; if (typeof a?.variants != "object" || typeof a.variants == "object" && Array.isArray(a.variants)) { for (const r of Object.keys(l)) c[r] = (s = {}) => t( l[r], m({ ...n, ...s })[r], s?.class, s?.className ); return c; } const V = a.variants, j = Array.isArray(a.compoundVariants) ? a.compoundVariants : [], d = typeof a?.defaultVariants == "object" && !Array.isArray(a.defaultVariants) ? a.defaultVariants : {}, O = { ...d, ...n ?? {} }, h = (r) => { if (!Array.isArray(j)) return {}; const s = {}; for (const { class: y, className: u, ...i } of j) if (v(i, r)) { const f = {}; Object.assign(f, typeof y == "object" ? y : {}), Object.assign(f, typeof u == "object" ? u : {}); for (const o of Object.keys(f)) { const e = f[o]; if (Object.hasOwn(s, o) || (s[o] = ""), typeof e == "string") { const p = t(e); s[o] += s[o].length === 0 ? p : ` ${p}`; } } } return s; }; for (const r of Object.keys(l)) c[r] = (s = {}) => { const y = { ...O, ...s }; return t( l[r], N({ defaultVariants: d, mergeClass: t, props: n, variants: V, slotKey: r, slotProps: s }), h(y)[r], m(y)[r], s?.class, s?.className ); }; return c; }, K = () => (t) => t, x = S(), F = (t) => (b) => { const n = {}; if (typeof t?.slots != "object" || Object.keys(t.slots).length === 0 || typeof t.slots == "object" && Array.isArray(t.slots)) return n; const c = t.slots; t.variants; for (const l of Object.keys(c)) n[l] = (A = {}) => k({ compoundVariants: t.compoundVariants, name: t.name, props: b, variants: t.variants, slotKey: l, slotProps: A }); return n; }; export { S as createSVA, K as defineSVA, F as rawSVA, x as sva };