tailwind-variants 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var tailwindMerge = require('tailwind-merge');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var x=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,g=e=>!e||typeof e!="object"||Object.keys(e).length===0,L=(e,l)=>JSON.stringify(e)===JSON.stringify(l);function Q(e,l){e.forEach(function(t){Array.isArray(t)?Q(t,l):l.push(t);});}function q(e){let l=[];return Q(e,l),l}var X=(...e)=>q(e).filter(Boolean),k=(e,l)=>{let t={},C=Object.keys(e),O=Object.keys(l);for(let u of C)if(O.includes(u)){let V=e[u],h=l[u];typeof V=="object"&&typeof h=="object"?t[u]=k(V,h):t[u]=h+" "+V;}else t[u]=e[u];for(let u of O)C.includes(u)||(t[u]=l[u]);return t},J=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();var se={twMerge:!0,twMergeConfig:{},responsiveVariants:!1},Z=e=>e||void 0,S=(...e)=>Z(q(e).filter(Boolean).join(" ")),R=null,M={},F=!1,j=(...e)=>l=>l.twMerge?((!R||F)&&(F=!1,R=g(M)?tailwindMerge.twMerge:tailwindMerge.extendTailwindMerge(M)),Z(R(S(e)))):S(e),Y=(e,l)=>{for(let t in l)e.hasOwnProperty(t)?e[t]=S(e[t],l[t]):e[t]=l[t];return e},ce=(e,l)=>{let{extend:t=null,slots:C={},variants:O={},compoundVariants:u=[],compoundSlots:V=[],defaultVariants:h={}}=e,b={...se,...l},$=t!=null&&t.base?S(t.base,e==null?void 0:e.base):e==null?void 0:e.base,d=t!=null&&t.variants&&!g(t.variants)?k(O,t.variants):O,w=t!=null&&t.defaultVariants&&!g(t.defaultVariants)?{...t.defaultVariants,...h}:h;!g(b.twMergeConfig)&&!L(b.twMergeConfig,M)&&(F=!0,M=b.twMergeConfig);let E=g(C)?{}:{base:e==null?void 0:e.base,...C},N=g(t==null?void 0:t.slots)?E:Y({...t==null?void 0:t.slots},g(E)?{base:e==null?void 0:e.base}:E),A=f=>{if(g(d)&&g(C)&&g(t==null?void 0:t.slots))return j($,f==null?void 0:f.class,f==null?void 0:f.className)(b);if(u&&!Array.isArray(u))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof u}`);if(V&&!Array.isArray(V))throw new TypeError(`The "compoundSlots" prop must be an array. Received: ${typeof V}`);let p=(n,a,r=[],c)=>{let s=r;if(typeof a=="string")s=s.concat(J(a).split(" ").map(i=>`${n}:${i}`));else if(Array.isArray(a))s=s.concat(a.reduce((i,o)=>i.concat(`${n}:${o}`),[]));else if(typeof a=="object"&&typeof c=="string"){for(let i in a)if(a.hasOwnProperty(i)&&i===c){let o=a[i];if(o&&typeof o=="string"){let y=J(o);s[c]?s[c]=s[c].concat(y.split(" ").map(m=>`${n}:${m}`)):s[c]=y.split(" ").map(m=>`${n}:${m}`);}else Array.isArray(o)&&o.length>0&&(s[c]=o.reduce((y,m)=>y.concat(`${n}:${m}`),[]));}}return s},U=(n,a=d,r=null,c=null)=>{var H;let s=a[n];if(!s||g(s))return null;let i=(H=c==null?void 0:c[n])!=null?H:f==null?void 0:f[n];if(i===null)return null;let o=x(i),y=Array.isArray(b.responsiveVariants)&&b.responsiveVariants.length>0||b.responsiveVariants===!0,m=w==null?void 0:w[n],v=[];if(typeof o=="object"&&y)for(let[B,I]of Object.entries(o)){let ne=s[I];if(B==="initial"){m=I;continue}Array.isArray(b.responsiveVariants)&&!b.responsiveVariants.includes(B)||(v=p(B,ne,v,r));}let T=s[o]||s[x(m)];return typeof v=="object"&&typeof r=="string"&&v[r]?Y(v,T):v.length>0?(v.push(T),v):T},K=()=>d?Object.keys(d).map(n=>U(n,d)):null,P=(n,a)=>{if(!d||typeof d!="object")return null;let r=new Array;for(let c in d){let s=U(c,d,n,a),i=n==="base"&&typeof s=="string"?s:s&&s[n];i&&(r[r.length]=i);}return r},W={};for(let n in f)f[n]!==void 0&&(W[n]=f[n]);let z=(n,a)=>{var c;let r=typeof(f==null?void 0:f[n])=="object"?{[n]:(c=f[n])==null?void 0:c.initial}:{};return {...w,...W,...r,...a}},D=(n=[],a)=>{let r=[];for(let{class:c,className:s,...i}of n){let o=!0;for(let[y,m]of Object.entries(i)){let v=z(y,a);if(Array.isArray(m)){if(!m.includes(v[y])){o=!1;break}}else if(v[y]!==m){o=!1;break}}o&&(c&&r.push(c),s&&r.push(s));}return r},G=n=>{let a=D(u,n),r=D(t==null?void 0:t.compoundVariants,n);return X(r,a)},ee=n=>{let a=G(n);if(!Array.isArray(a))return a;let r={};for(let c of a)if(typeof c=="string"&&(r.base=j(r.base,c)(b)),typeof c=="object")for(let[s,i]of Object.entries(c))r[s]=j(r[s],i)(b);return r},te=n=>{if(V.length<1)return null;let a={};for(let{slots:r=[],class:c,className:s,...i}of V){if(!g(i)){let o=!0;for(let y of Object.keys(i)){let m=z(y,n)[y];if(m===void 0||(Array.isArray(i[y])?!i[y].includes(m):i[y]!==m)){o=!1;break}}if(!o)continue}for(let o of r)a[o]=a[o]||[],a[o].push([c,s]);}return a};if(!g(C)||!g(t==null?void 0:t.slots)){let n={};if(typeof N=="object"&&!g(N))for(let a of Object.keys(N))n[a]=r=>{var c,s;return j(N[a],P(a,r),((c=ee(r))!=null?c:[])[a],((s=te(r))!=null?s:[])[a],r==null?void 0:r.class,r==null?void 0:r.className)(b)};return n}return j($,K(),G(),f==null?void 0:f.class,f==null?void 0:f.className)(b)},_=()=>{if(!(!d||typeof d!="object"))return Object.keys(d)};return A.variantKeys=_(),A.extend=t,A.base=$,A.slots=N,A.variants=d,A.defaultVariants=w,A.compoundSlots=V,A.compoundVariants=u,A},le=e=>(l,t)=>ce(l,t?k(e,t):e);
|
|
6
6
|
|
|
7
7
|
exports.cn = j;
|
|
8
|
-
exports.cnBase =
|
|
8
|
+
exports.cnBase = S;
|
|
9
|
+
exports.createTV = le;
|
|
9
10
|
exports.defaultConfig = se;
|
|
10
|
-
exports.tv =
|
|
11
|
+
exports.tv = ce;
|
|
11
12
|
exports.voidEmpty = Z;
|
package/dist/index.d.ts
CHANGED
|
@@ -296,6 +296,8 @@ export type TV = {
|
|
|
296
296
|
// main function
|
|
297
297
|
export declare const tv: TV;
|
|
298
298
|
|
|
299
|
+
export declare function createTV(config: TVConfig): TV;
|
|
300
|
+
|
|
299
301
|
export declare const defaultConfig: TVConfig;
|
|
300
302
|
|
|
301
303
|
export type VariantProps<Component extends (...args: any) => any> = Omit<
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { e, b, g, c, f, a, h } from './chunk-T24HS5CV.js';
|
|
2
2
|
import { twMerge, extendTailwindMerge } from 'tailwind-merge';
|
|
3
3
|
|
|
4
|
-
var re={twMerge:!0,twMergeConfig:{},responsiveVariants:!1},Z=
|
|
4
|
+
var re={twMerge:!0,twMergeConfig:{},responsiveVariants:!1},Z=s=>s||void 0,j=(...s)=>Z(e(s).filter(Boolean).join(" ")),R=null,O={},q=!1,w=(...s)=>d=>d.twMerge?((!R||q)&&(q=!1,R=b(O)?twMerge:extendTailwindMerge(O)),Z(R(j(s)))):j(s),Y=(s,d)=>{for(let e in d)s.hasOwnProperty(e)?s[e]=j(s[e],d[e]):s[e]=d[e];return s},se=(s,d)=>{let{extend:e=null,slots:N={},variants:F={},compoundVariants:C=[],compoundSlots:V=[],defaultVariants:U={}}=s,m={...re,...d},M=e!=null&&e.base?j(e.base,s==null?void 0:s.base):s==null?void 0:s.base,g$1=e!=null&&e.variants&&!b(e.variants)?g(F,e.variants):F,A=e!=null&&e.defaultVariants&&!b(e.defaultVariants)?{...e.defaultVariants,...U}:U;!b(m.twMergeConfig)&&!c(m.twMergeConfig,O)&&(q=!0,O=m.twMergeConfig);let $=b(N)?{}:{base:s==null?void 0:s.base,...N},h$1=b(e==null?void 0:e.slots)?$:Y({...e==null?void 0:e.slots},b($)?{base:s==null?void 0:s.base}:$),v=l=>{if(b(g$1)&&b(N)&&b(e==null?void 0:e.slots))return w(M,l==null?void 0:l.class,l==null?void 0:l.className)(m);if(C&&!Array.isArray(C))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof C}`);if(V&&!Array.isArray(V))throw new TypeError(`The "compoundSlots" prop must be an array. Received: ${typeof V}`);let K=(t,n,a=[],i)=>{let r=a;if(typeof n=="string")r=r.concat(h(n).split(" ").map(c=>`${t}:${c}`));else if(Array.isArray(n))r=r.concat(n.reduce((c,f)=>c.concat(`${t}:${f}`),[]));else if(typeof n=="object"&&typeof i=="string"){for(let c in n)if(n.hasOwnProperty(c)&&c===i){let f=n[c];if(f&&typeof f=="string"){let o=h(f);r[i]?r[i]=r[i].concat(o.split(" ").map(u=>`${t}:${u}`)):r[i]=o.split(" ").map(u=>`${t}:${u}`);}else Array.isArray(f)&&f.length>0&&(r[i]=f.reduce((o,u)=>o.concat(`${t}:${u}`),[]));}}return r},W=(t,n=g$1,a$1=null,i=null)=>{var I;let r=n[t];if(!r||b(r))return null;let c=(I=i==null?void 0:i[t])!=null?I:l==null?void 0:l[t];if(c===null)return null;let f=a(c),o=Array.isArray(m.responsiveVariants)&&m.responsiveVariants.length>0||m.responsiveVariants===!0,u=A==null?void 0:A[t],b$1=[];if(typeof f=="object"&&o)for(let[T,J]of Object.entries(f)){let te=r[J];if(T==="initial"){u=J;continue}Array.isArray(m.responsiveVariants)&&!m.responsiveVariants.includes(T)||(b$1=K(T,te,b$1,a$1));}let S=r[f]||r[a(u)];return typeof b$1=="object"&&typeof a$1=="string"&&b$1[a$1]?Y(b$1,S):b$1.length>0?(b$1.push(S),b$1):S},x=()=>g$1?Object.keys(g$1).map(t=>W(t,g$1)):null,P=(t,n)=>{if(!g$1||typeof g$1!="object")return null;let a=new Array;for(let i in g$1){let r=W(i,g$1,t,n),c=t==="base"&&typeof r=="string"?r:r&&r[t];c&&(a[a.length]=c);}return a},z={};for(let t in l)l[t]!==void 0&&(z[t]=l[t]);let D=(t,n)=>{var i;let a=typeof(l==null?void 0:l[t])=="object"?{[t]:(i=l[t])==null?void 0:i.initial}:{};return {...A,...z,...a,...n}},G=(t=[],n)=>{let a=[];for(let{class:i,className:r,...c}of t){let f=!0;for(let[o,u]of Object.entries(c)){let b=D(o,n);if(Array.isArray(u)){if(!u.includes(b[o])){f=!1;break}}else if(b[o]!==u){f=!1;break}}f&&(i&&a.push(i),r&&a.push(r));}return a},H=t=>{let n=G(C,t),a=G(e==null?void 0:e.compoundVariants,t);return f(a,n)},p=t=>{let n=H(t);if(!Array.isArray(n))return n;let a={};for(let i of n)if(typeof i=="string"&&(a.base=w(a.base,i)(m)),typeof i=="object")for(let[r,c]of Object.entries(i))a[r]=w(a[r],c)(m);return a},ee=t=>{if(V.length<1)return null;let n={};for(let{slots:a=[],class:i,className:r,...c}of V){if(!b(c)){let f=!0;for(let o of Object.keys(c)){let u=D(o,t)[o];if(u===void 0||(Array.isArray(c[o])?!c[o].includes(u):c[o]!==u)){f=!1;break}}if(!f)continue}for(let f of a)n[f]=n[f]||[],n[f].push([i,r]);}return n};if(!b(N)||!b(e==null?void 0:e.slots)){let t={};if(typeof h$1=="object"&&!b(h$1))for(let n of Object.keys(h$1))t[n]=a=>{var i,r;return w(h$1[n],P(n,a),((i=p(a))!=null?i:[])[n],((r=ee(a))!=null?r:[])[n],a==null?void 0:a.class,a==null?void 0:a.className)(m)};return t}return w(M,x(),H(),l==null?void 0:l.class,l==null?void 0:l.className)(m)},_=()=>{if(!(!g$1||typeof g$1!="object"))return Object.keys(g$1)};return v.variantKeys=_(),v.extend=e,v.base=M,v.slots=h$1,v.variants=g$1,v.defaultVariants=A,v.compoundSlots=V,v.compoundVariants=C,v},fe=s=>(d,e)=>se(d,e?g(s,e):s);
|
|
5
5
|
|
|
6
|
-
export { w as cn, j as cnBase, re as defaultConfig,
|
|
6
|
+
export { w as cn, j as cnBase, fe as createTV, re as defaultConfig, se as tv, Z as voidEmpty };
|