UNPKG

css-variants

Version:

Lightweight helpers to compose class names and inline styles using variants. Zero runtime deps, small bundle, and first-class TypeScript support.

2 lines 1.34 kB
function m(s){if(typeof s=="string")return s;if(typeof s=="number"||typeof s=="bigint")return String(s);if(s==null||typeof s=="boolean")return "";let e="";if(Array.isArray(s)){let t=0,a,n;for(;t<s.length;t++)(a=s[t])&&(n=m(a))&&(e&&(e+=" "),e+=n);return e}for(let t in s)s[t]&&(e&&(e+=" "),e+=t);return e}function p(...s){let e="",t=0,a,n;for(;t<s.length;t++)(a=s[t])&&(n=m(a))&&(e&&(e+=" "),e+=n);return e}function x(s,e,t){let a={...s};if(e)for(let n in e)e[n]!==void 0&&(!t||!t.includes(n))&&(a[n]=e[n]);return a}var g=s=>{let{slots:e,base:t,variants:a,compoundVariants:n,defaultVariants:V,classNameResolver:S=p}=s;return a?i=>{let c=x(V,i,["classNames"]),o={};for(let r of e)t?.[r]?o[r]=Array.isArray(t[r])?[...t[r]]:[t[r]]:o[r]=[];for(let r in c){let l=a[r]?.[c[r]];if(l)for(let d in l)o[d]?.push(l[d]);}if(n)for(let r=0;r<n.length;r++){let l=n[r],d=true;for(let f in l){if(f==="classNames")continue;let u=l[f],y=c[f];if(Array.isArray(u)?!u.includes(y):u!==y){d=false;break}}if(d&&l.classNames)for(let f in l.classNames)o[f]?.push(l.classNames[f]);}if(i?.classNames)for(let r in i.classNames)o[r]?.push(i.classNames[r]);let C={};for(let r in o)C[r]=S(o[r]);return C}:i=>{let c={};for(let o of e)c[o]=S(t?.[o],i?.classNames?.[o]);return c}},T=g;export{T as default,g as scv};//# sourceMappingURL=scv.js.map //# sourceMappingURL=scv.js.map