tailwind-variants 0.1.0 → 0.1.1
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/config.d.ts +5 -2
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type {Config as TwMergeConfig} from "tailwind-merge";
|
|
|
2
2
|
import type {TVVariants} from "./index";
|
|
3
3
|
import type {TVGeneratedScreens} from "./generated";
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type TWMConfig = {
|
|
6
6
|
/**
|
|
7
7
|
* Whether to merge the class names with `tailwind-merge` library.
|
|
8
8
|
* It's avoid to have duplicate tailwind classes. (Recommended)
|
|
@@ -15,6 +15,9 @@ export type TVConfig<V extends TVVariants<S>, EV extends TVVariants> = {
|
|
|
15
15
|
* @see https://github.com/dcastil/tailwind-merge/blob/v1.8.1/docs/configuration.md
|
|
16
16
|
*/
|
|
17
17
|
twMergeConfig?: TwMergeConfig;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type TVConfig<V extends TVVariants<S>, EV extends TVVariants> = {
|
|
18
21
|
/**
|
|
19
22
|
* Whether to enable responsive variant transform.
|
|
20
23
|
* Which variants or screens(breakpoints) for responsive variant transform.
|
|
@@ -24,4 +27,4 @@ export type TVConfig<V extends TVVariants<S>, EV extends TVVariants> = {
|
|
|
24
27
|
| boolean
|
|
25
28
|
| TVGeneratedScreens[]
|
|
26
29
|
| {[K in keyof V | keyof EV]?: boolean | TVGeneratedScreens[]};
|
|
27
|
-
};
|
|
30
|
+
} & TWMConfig;
|
package/dist/index.cjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var tailwindMerge = require('tailwind-merge');
|
|
4
4
|
|
|
5
|
-
var S=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,d=e=>!e||typeof e!="object"||Object.keys(e).length===0,J=(...e)=>[...e].flat().filter(Boolean),E=(e,s)=>{let y={};for(let u in e)s!=null&&s.hasOwnProperty(u)?y[u]=typeof e[u]=="object"?E(e[u],s[u]):s[u]+" "+e[u]:y[u]=e[u];for(let u in s)y.hasOwnProperty(u)||(y[u]=s[u]);return y},B=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();var M=(...e)=>e.flat(1/0).filter(Boolean).join(" "),w=(...e)=>(s=
|
|
5
|
+
var S=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,d=e=>!e||typeof e!="object"||Object.keys(e).length===0,J=(...e)=>[...e].flat().filter(Boolean),E=(e,s)=>{let y={};for(let u in e)s!=null&&s.hasOwnProperty(u)?y[u]=typeof e[u]=="object"?E(e[u],s[u]):s[u]+" "+e[u]:y[u]=e[u];for(let u in s)y.hasOwnProperty(u)||(y[u]=s[u]);return y},B=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();var Q={twMerge:!0,twMergeConfig:{},responsiveVariants:!1},M=(...e)=>e.flat(1/0).filter(Boolean).join(" "),w=(...e)=>(s=Q)=>s.twMerge?(d(s.twMergeConfig)?tailwindMerge.twMerge:tailwindMerge.extendTailwindMerge(s.twMergeConfig))(M(e)):M(e),L=(e,s)=>{let y={...e};for(let u in s)y.hasOwnProperty(u)?y[u]=M(y[u],s[u]):y[u]=s[u];return y},ue=(e,s=Q)=>{var k,N,T,P,F;let{slots:y={},variants:u={},compoundVariants:x=[],compoundSlots:O=[],defaultVariants:X={}}=e,j=M((k=e==null?void 0:e.extend)==null?void 0:k.base,e==null?void 0:e.base),m=E(u,(N=e==null?void 0:e.extend)==null?void 0:N.variants),h=Object.assign({},(T=e==null?void 0:e.extend)==null?void 0:T.defaultVariants,X),$=d(y)?{}:{base:e==null?void 0:e.base,...y},Y=Array.isArray(s.responsiveVariants)&&s.responsiveVariants.length>0||s.responsiveVariants===!0,A=d((P=e==null?void 0:e.extend)==null?void 0:P.slots)?$:L((F=e==null?void 0:e.extend)==null?void 0:F.slots,d($)?{base:e==null?void 0:e.base}:$),b=c=>{var q,z,D,G;if(d(m)&&d(y)&&d((q=e==null?void 0:e.extend)==null?void 0:q.slots))return w(j,c==null?void 0:c.class,c==null?void 0:c.className)(s);if(x&&!Array.isArray(x))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof x}`);if(O&&!Array.isArray(O))throw new TypeError(`The "compoundSlots" prop must be an array. Received: ${typeof O}`);let _=(t,r,n=[],l)=>{let f=n;if(typeof r=="string")f.push(B(r).split(" ").map(a=>`${t}:${a}`));else if(Array.isArray(r))f.push(r.flatMap(a=>`${t}:${a}`));else if(typeof r=="object"&&typeof l=="string"){let a=r==null?void 0:r[l];if(a&&typeof a=="string"){let i=B(a);f[l]=f[l]?[...f[l],...i.split(" ").map(g=>`${t}:${g}`)]:i.split(" ").map(g=>`${t}:${g}`);}else Array.isArray(a)&&a.length>0&&(f[l]=a.flatMap(i=>`${t}:${i}`));}return f},R=(t,r=m,n=null)=>{let l=r==null?void 0:r[t];if(typeof l!="object"||d(l))return null;let f=c==null?void 0:c[t],a=h==null?void 0:h[t],i=[];if(f===null)return null;let g=S(f);typeof g=="object"&&Y&&(i=Object.keys(g).reduce((v,C)=>{let H=g[C],re=l==null?void 0:l[H];return C==="initial"?(a=H,v):Array.isArray(s.responsiveVariants)&&!s.responsiveVariants.includes(C)?v:_(C,re,v,n)},[]));let V=l[g]||l[S(a)];return typeof i=="object"&&typeof n=="string"&&i[n]?L(i,V):i.length>0?[V,...i]:V},o=()=>m?Object.keys(m).map(t=>R(t,m)):null,K=t=>!m||typeof m!="object"?null:Object.keys(m).map(r=>{let n=R(r,m,t);return t==="base"&&typeof n=="string"?n:n&&n[t]}).filter(Boolean),p=c&&Object.fromEntries(Object.entries(c).filter(([,t])=>t!==void 0)),I=t=>{var n;let r=typeof(c==null?void 0:c[t])=="object"?{[t]:(n=c[t])==null?void 0:n.initial}:{};return {...h,...p,...r}},U=(t=[])=>t==null?void 0:t.filter(({class:r,className:n,...l})=>Object.entries(l).every(([f,a])=>{let i=I(f);return Array.isArray(a)?a.includes(i[f]):i[f]===a})).flatMap(({class:r,className:n})=>[r,n]),W=()=>{var n;let t=U(x),r=U((n=e==null?void 0:e.extend)==null?void 0:n.compoundVariants);return J(r,t)},ee=()=>{let t=W();return Array.isArray(t)?t.reduce((r,n)=>(typeof n=="string"&&(r.base=w(r.base,n)(s)),typeof n=="object"&&Object.entries(n).forEach(([l,f])=>{r[l]=w(r[l],f)(s);}),r),{}):t},te=()=>O.length<1?null:O.reduce((t,r)=>{let{slots:n=[],class:l,className:f,...a}=r;if(!d(a)){let i=Object.keys(a);for(let g of i){let V=I(g)[g];if(!V||V!==a[g])return t}}return n.forEach(i=>{t[i]||(t[i]=[]),t[i].push([l,f]);}),t},{});if(!d(y)||!d((z=e==null?void 0:e.extend)==null?void 0:z.slots)){let t=(D=ee())!=null?D:[],r=(G=te())!=null?G:[];return {...typeof A=="object"&&!d(A)?Object.keys(A).reduce((l,f)=>(l[f]=a=>w(A[f],K(f),t==null?void 0:t[f],r==null?void 0:r[f],a==null?void 0:a.class,a==null?void 0:a.className)(s),l),{}):{}}}return w(j,o(),W(),c==null?void 0:c.class,c==null?void 0:c.className)(s)},Z=()=>{if(!(!m||typeof m!="object"))return Object.keys(m)};return b.variantKeys=Z(),b.base=j,b.slots=A,b.variants=m,b.defaultVariants=h,b.compoundSlots=O,b.compoundVariants=x,b};
|
|
6
6
|
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.defaultConfig =
|
|
7
|
+
exports.cn = w;
|
|
8
|
+
exports.cnBase = M;
|
|
9
|
+
exports.defaultConfig = Q;
|
|
10
10
|
exports.tv = ue;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {TVConfig} from "./config";
|
|
1
|
+
import {TVConfig, TWMConfig} from "./config";
|
|
2
2
|
import {TVGeneratedScreens} from "./generated";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -33,13 +33,13 @@ export type OmitUndefined<T> = T extends undefined ? never : T;
|
|
|
33
33
|
|
|
34
34
|
export type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
35
35
|
|
|
36
|
-
export type
|
|
36
|
+
export type CnOptions = ClassValue[];
|
|
37
37
|
|
|
38
|
-
export type
|
|
38
|
+
export type CnReturn = string;
|
|
39
39
|
|
|
40
|
-
export declare const
|
|
40
|
+
export declare const cnBase: <T extends CnOptions>(...classes: T) => CnReturn;
|
|
41
41
|
|
|
42
|
-
export declare const
|
|
42
|
+
export declare const cn: <T extends CnOptions>(...classes: T) => (config?: TWMConfig) => CnReturn;
|
|
43
43
|
|
|
44
44
|
// compare if the value is true or array of values
|
|
45
45
|
export type isTrueOrArray<T> = T extends true | (infer U)[] ? true : false;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { b, d, c, a, e } from './chunk-X3I5ASPE.js';
|
|
2
2
|
import { twMerge, extendTailwindMerge } from 'tailwind-merge';
|
|
3
3
|
|
|
4
|
-
var O=(...e)=>e.flat(1/0).filter(Boolean).join(" "),
|
|
4
|
+
var Q={twMerge:!0,twMergeConfig:{},responsiveVariants:!1},O=(...e)=>e.flat(1/0).filter(Boolean).join(" "),w=(...e)=>(c=Q)=>c.twMerge?(b(c.twMergeConfig)?twMerge:extendTailwindMerge(c.twMergeConfig))(O(e)):O(e),L=(e,c)=>{let m={...e};for(let b in c)m.hasOwnProperty(b)?m[b]=O(m[b],c[b]):m[b]=c[b];return m},ue=(e$1,c$1=Q)=>{var B,N,T,k,F;let{slots:m={},variants:b$1={},compoundVariants:j=[],compoundSlots:V=[],defaultVariants:X={}}=e$1,v=O((B=e$1==null?void 0:e$1.extend)==null?void 0:B.base,e$1==null?void 0:e$1.base),i=d(b$1,(N=e$1==null?void 0:e$1.extend)==null?void 0:N.variants),C=Object.assign({},(T=e$1==null?void 0:e$1.extend)==null?void 0:T.defaultVariants,X),M=b(m)?{}:{base:e$1==null?void 0:e$1.base,...m},Y=Array.isArray(c$1.responsiveVariants)&&c$1.responsiveVariants.length>0||c$1.responsiveVariants===!0,h=b((k=e$1==null?void 0:e$1.extend)==null?void 0:k.slots)?M:L((F=e$1==null?void 0:e$1.extend)==null?void 0:F.slots,b(M)?{base:e$1==null?void 0:e$1.base}:M),g=u=>{var W,q,z,D;if(b(i)&&b(m)&&b((W=e$1==null?void 0:e$1.extend)==null?void 0:W.slots))return w(v,u==null?void 0:u.class,u==null?void 0:u.className)(c$1);if(j&&!Array.isArray(j))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof j}`);if(V&&!Array.isArray(V))throw new TypeError(`The "compoundSlots" prop must be an array. Received: ${typeof V}`);let _=(t,r,n=[],s)=>{let l=n;if(typeof r=="string")l.push(e(r).split(" ").map(a=>`${t}:${a}`));else if(Array.isArray(r))l.push(r.flatMap(a=>`${t}:${a}`));else if(typeof r=="object"&&typeof s=="string"){let a=r==null?void 0:r[s];if(a&&typeof a=="string"){let f=e(a);l[s]=l[s]?[...l[s],...f.split(" ").map(d=>`${t}:${d}`)]:f.split(" ").map(d=>`${t}:${d}`);}else Array.isArray(a)&&a.length>0&&(l[s]=a.flatMap(f=>`${t}:${f}`));}return l},R=(t,r=i,n=null)=>{let s=r==null?void 0:r[t];if(typeof s!="object"||b(s))return null;let l=u==null?void 0:u[t],a$1=C==null?void 0:C[t],f=[];if(l===null)return null;let d=a(l);typeof d=="object"&&Y&&(f=Object.keys(d).reduce(($,x)=>{let G=d[x],re=s==null?void 0:s[G];return x==="initial"?(a$1=G,$):Array.isArray(c$1.responsiveVariants)&&!c$1.responsiveVariants.includes(x)?$:_(x,re,$,n)},[]));let A=s[d]||s[a(a$1)];return typeof f=="object"&&typeof n=="string"&&f[n]?L(f,A):f.length>0?[A,...f]:A},K=()=>i?Object.keys(i).map(t=>R(t,i)):null,o=t=>!i||typeof i!="object"?null:Object.keys(i).map(r=>{let n=R(r,i,t);return t==="base"&&typeof n=="string"?n:n&&n[t]}).filter(Boolean),p=u&&Object.fromEntries(Object.entries(u).filter(([,t])=>t!==void 0)),I=t=>{var n;let r=typeof(u==null?void 0:u[t])=="object"?{[t]:(n=u[t])==null?void 0:n.initial}:{};return {...C,...p,...r}},P=(t=[])=>t==null?void 0:t.filter(({class:r,className:n,...s})=>Object.entries(s).every(([l,a])=>{let f=I(l);return Array.isArray(a)?a.includes(f[l]):f[l]===a})).flatMap(({class:r,className:n})=>[r,n]),U=()=>{var n;let t=P(j),r=P((n=e$1==null?void 0:e$1.extend)==null?void 0:n.compoundVariants);return c(r,t)},ee=()=>{let t=U();return Array.isArray(t)?t.reduce((r,n)=>(typeof n=="string"&&(r.base=w(r.base,n)(c$1)),typeof n=="object"&&Object.entries(n).forEach(([s,l])=>{r[s]=w(r[s],l)(c$1);}),r),{}):t},te=()=>V.length<1?null:V.reduce((t,r)=>{let{slots:n=[],class:s,className:l,...a}=r;if(!b(a)){let f=Object.keys(a);for(let d of f){let A=I(d)[d];if(!A||A!==a[d])return t}}return n.forEach(f=>{t[f]||(t[f]=[]),t[f].push([s,l]);}),t},{});if(!b(m)||!b((q=e$1==null?void 0:e$1.extend)==null?void 0:q.slots)){let t=(z=ee())!=null?z:[],r=(D=te())!=null?D:[];return {...typeof h=="object"&&!b(h)?Object.keys(h).reduce((s,l)=>(s[l]=a=>w(h[l],o(l),t==null?void 0:t[l],r==null?void 0:r[l],a==null?void 0:a.class,a==null?void 0:a.className)(c$1),s),{}):{}}}return w(v,K(),U(),u==null?void 0:u.class,u==null?void 0:u.className)(c$1)},Z=()=>{if(!(!i||typeof i!="object"))return Object.keys(i)};return g.variantKeys=Z(),g.base=v,g.slots=h,g.variants=i,g.defaultVariants=C,g.compoundSlots=V,g.compoundVariants=j,g};
|
|
5
5
|
|
|
6
|
-
export {
|
|
6
|
+
export { w as cn, O as cnBase, Q as defaultConfig, ue as tv };
|