UNPKG

jade-garden

Version:

Class utilities to compose class names and variants

96 lines (95 loc) 3.62 kB
function A(t) { var n, s, r = ""; if (typeof t == "string" || typeof t == "number") r += t; else if (typeof t == "object") if (Array.isArray(t)) { var e = t.length; for (n = 0; n < e; n++) t[n] && (s = A(t[n])) && (r && (r += " "), r += s); } else for (s in t) t[s] && (r && (r += " "), r += s); return r; } function u() { for (var t, n, s = 0, r = "", e = arguments.length; s < e; s++) (t = arguments[s]) && (n = A(t)) && (r && (r += " "), r += n); return r; } function b() { for (var t, n = 0, s = "", r = arguments.length; n < r; n++) (t = arguments[n]) && typeof t == "string" && (s += (s && " ") + t); return s; } const m = (t, n, s) => { if (typeof n > "u" && typeof s > "u") return u(t); let r = u(t).split(" "); return n && (typeof n == "string" ? r = r.filter((e) => !e.includes(n)) : Array.isArray(n) && (r = r.filter((e) => !n.includes(e)))), s && (typeof s == "string" ? r.push(s) : Array.isArray(s) && r.push(...s)), u(Array.from(new Set(r))); }, h = (t) => { const n = (e, i, a) => { const f = e.length ? " " : "", c = `data-[${i}]`; return Array.isArray(a) ? e + f + a.map((o) => `${c}:${o}`).join(" ") : typeof a == "string" && a.length ? `${e}${f}${c}:${a}` : e; }, s = (e, i, a) => { let f = e; for (const c in a) { const o = f.length ? " " : ""; if (Object.hasOwn(a, c)) { const y = a[c], l = `data-[${i}=${c}]`; Array.isArray(y) && (f += o + y.map((p) => `${l}:${p}`).join(" ")), typeof y == "string" && y.length && (f += `${o}${l}:${y}`); } } return f; }; let r = ""; if (typeof t?.data == "object" && !Array.isArray(t?.data) && Object.keys(t?.data).length > 0) for (const e of Object.keys(t?.data)) { const i = t?.data[e]; typeof i == "object" && !Array.isArray(i) ? r = s(r, e, i) : typeof i < "u" && (r = n(r, e, i)); } return u(t?.class, t?.className, r); }, $ = /\p{Lu}?\p{Ll}+|[0-9]+|\p{Lu}+(?!\p{Ll})|\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{L}+/gu; function j(t) { return Array.from(t.match($) ?? []); } function g(t) { return j(t).map((s) => s.toLowerCase()).join("-"); } const d = (t) => typeof t == "boolean" ? `${t}` : t === 0 ? "0" : t, v = (t) => { const { compoundVariants: n, name: s, props: r, slotKey: e, slotProps: i, variants: a } = t; if (!s) return u(r?.class, r?.className); const f = `${g(s)}${e ? `--${g(e)}` : ""}`; if (typeof a != "object" || typeof a == "object" && Array.isArray(a)) return u(f, r?.class, r?.className); let c = f; for (const o of Object.keys(a)) { const y = a[o]; if (!y || typeof y != "object" || Object.keys(y).length === 0) continue; const l = i?.[o] ?? r?.[o] ?? n?.[o], p = o ? `__${g(o)}${l ? `--${g(l)}` : ""}` : ""; c += ` ${f}${p}`; } return u(c, r?.class, r?.className); }, k = (t) => { const { defaultVariants: n, mergeClass: s, props: r, slotKey: e, slotProps: i, variants: a } = t; if (!a || typeof a != "object" || Array.isArray(a)) return ""; let f = ""; for (const c of Object.keys(a)) { const o = a[c]; if (!o || typeof o != "object" || Object.keys(o).length === 0) continue; const y = i?.[c] ?? r?.[c] ?? n?.[c], l = y !== void 0 ? d(y) : y, p = s(e ? o[l ?? "false"]?.[e] : o[l]); p && (f += f.length === 0 ? p : ` ${p}`); } return f; }, O = (t, n) => { let s = !0; for (const r of Object.keys(t)) { const e = t[r], i = Array.isArray(e), a = n[r]; if (i && !e.includes(a) || !i && e !== a) { s = !1; break; } } return s; }; export { b as a, u as b, m as c, v as d, k as g, O as h, h as t };