UNPKG

tailwind-variants

Version:

🦄 Tailwindcss first-class variant API

1 lines • 4.32 kB
import {k,b,d,e,g,j,c,a}from'./chunk-GQLG7IS2.js';var Q={twMerge:true,twMergeConfig:{},responsiveVariants:false};function ne(){let b=null,w={},A=false;return {get cachedTwMerge(){return b},set cachedTwMerge(u){b=u;},get cachedTwMergeConfig(){return w},set cachedTwMergeConfig(u){w=u;},get didTwMergeConfigChange(){return A},set didTwMergeConfigChange(u){A=u;},reset(){b=null,w={},A=false;}}}var S=ne();var le=b$1=>{let w=(u,$)=>{let{extend:c$1=null,slots:M={},variants:q={},compoundVariants:L=[],compoundSlots:v=[],defaultVariants:U={}}=u,d$1={...Q,...$},x=c$1?.base?b(c$1.base,u?.base):u?.base,p=c$1?.variants&&!d(c$1.variants)?k(q,c$1.variants):q,E=c$1?.defaultVariants&&!d(c$1.defaultVariants)?{...c$1.defaultVariants,...U}:U;!d(d$1.twMergeConfig)&&!e(d$1.twMergeConfig,S.cachedTwMergeConfig)&&(S.didTwMergeConfigChange=true,S.cachedTwMergeConfig=d$1.twMergeConfig);let N=d(c$1?.slots),O=d(M)?{}:{base:b(u?.base,N&&c$1?.base),...M},j$1=N?O:g({...c$1?.slots},d(O)?{base:u?.base}:O),T=d(c$1?.compoundVariants)?L:j(c$1?.compoundVariants,L),y=h=>{if(d(p)&&d(M)&&N)return b$1(x,h?.class,h?.className)(d$1);if(T&&!Array.isArray(T))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof T}`);if(v&&!Array.isArray(v))throw new TypeError(`The "compoundSlots" prop must be an array. Received: ${typeof v}`);let Y=(t,e,n=[],a$1)=>{let r=n;if(typeof e=="string"){let i=a(e).split(" ");for(let l=0;l<i.length;l++)r.push(`${t}:${i[l]}`);}else if(Array.isArray(e))for(let s=0;s<e.length;s++)r.push(`${t}:${e[s]}`);else if(typeof e=="object"&&typeof a$1=="string"&&a$1 in e){let s=e[a$1];if(s&&typeof s=="string"){let l=a(s).split(" "),f=[];for(let o=0;o<l.length;o++)f.push(`${t}:${l[o]}`);r[a$1]=r[a$1]?r[a$1].concat(f):f;}else if(Array.isArray(s)&&s.length>0){let i=[];for(let l=0;l<s.length;l++)i.push(`${t}:${s[l]}`);r[a$1]=i;}}return r},W=(t,e=p,n=null,a=null)=>{let r=e[t];if(!r||d(r))return null;let s=a?.[t]??h?.[t];if(s===null)return null;let i=c(s),l=Array.isArray(d$1.responsiveVariants)&&d$1.responsiveVariants.length>0||d$1.responsiveVariants===true,f=E?.[t],o=[];if(typeof i=="object"&&l)for(let[C,H]of Object.entries(i)){let te=r[H];if(C==="initial"){f=H;continue}Array.isArray(d$1.responsiveVariants)&&!d$1.responsiveVariants.includes(C)||(o=Y(C,te,o,n));}let V=i!=null&&typeof i!="object"?i:c(f),m=r[V||"false"];return typeof o=="object"&&typeof n=="string"&&o[n]?g(o,m):o.length>0?(o.push(m),n==="base"?o.join(" "):o):m},Z=()=>{if(!p)return null;let t=Object.keys(p),e=[];for(let n=0;n<t.length;n++){let a=W(t[n],p);a&&e.push(a);}return e},_=(t,e)=>{if(!p||typeof p!="object")return null;let n=[];for(let a in p){let r=W(a,p,t,e),s=t==="base"&&typeof r=="string"?r:r&&r[t];s&&n.push(s);}return n},z={};for(let t in h){let e=h[t];e!==void 0&&(z[t]=e);}let D=(t,e)=>{let n=typeof h?.[t]=="object"?{[t]:h[t]?.initial}:{};return {...E,...z,...n,...e}},G=(t=[],e)=>{let n=[],a=t.length;for(let r=0;r<a;r++){let{class:s,className:i,...l}=t[r],f=true,o=D(null,e);for(let V in l){let m=l[V],C=o[V];if(Array.isArray(m)){if(!m.includes(C)){f=false;break}}else {if((m==null||m===false)&&(C==null||C===false))continue;if(C!==m){f=false;break}}}f&&(s&&n.push(s),i&&n.push(i));}return n},K=t=>{let e=G(T,t);if(!Array.isArray(e))return e;let n={},a=b$1;for(let r=0;r<e.length;r++){let s=e[r];if(typeof s=="string")n.base=a(n.base,s)(d$1);else if(typeof s=="object")for(let i in s)n[i]=a(n[i],s[i])(d$1);}return n},ee=t=>{if(v.length<1)return null;let e={},n=D(null,t);for(let a=0;a<v.length;a++){let{slots:r=[],class:s,className:i,...l}=v[a];if(!d(l)){let f=true;for(let o in l){let V=n[o],m=l[o];if(V===void 0||(Array.isArray(m)?!m.includes(V):m!==V)){f=false;break}}if(!f)continue}for(let f=0;f<r.length;f++){let o=r[f];e[o]||(e[o]=[]),e[o].push([s,i]);}}return e};if(!d(M)||!N){let t={};if(typeof j$1=="object"&&!d(j$1)){let e=b$1;for(let n in j$1)t[n]=a=>{let r=K(a),s=ee(a);return e(j$1[n],_(n,a),r?r[n]:void 0,s?s[n]:void 0,a?.class,a?.className)(d$1)};}return t}return b$1(x,Z(),G(T),h?.class,h?.className)(d$1)},X=()=>{if(!(!p||typeof p!="object"))return Object.keys(p)};return y.variantKeys=X(),y.extend=c$1,y.base=x,y.slots=j$1,y.variants=p,y.defaultVariants=E,y.compoundSlots=v,y.compoundVariants=T,y};return {tv:w,createTV:u=>($,c)=>w($,c?k(u,c):u)}};export{Q as a,S as b,le as c};