tailwind-variants 0.2.0 → 0.3.0

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/README.md CHANGED
@@ -17,7 +17,6 @@
17
17
  </a>
18
18
  </p>
19
19
 
20
-
21
20
  ## Features
22
21
 
23
22
  - First-class variant API
@@ -34,8 +33,8 @@ For full documentation, visit [tailwind-variants.org](https://tailwind-variants.
34
33
 
35
34
  ## Quick Start
36
35
 
37
- 1. Installation:
38
- To use Tailwind Variants in your project, you can install it as a dependency:
36
+ 1. Installation:
37
+ To use Tailwind Variants in your project, you can install it as a dependency:
39
38
 
40
39
  ```bash
41
40
  yarn add tailwind-variants
@@ -46,8 +45,8 @@ npm i tailwind-variants
46
45
  2. Usage:
47
46
 
48
47
  ```js
49
- import { tv } from 'tailwind-variants';
50
-
48
+ import {tv} from "tailwind-variants";
49
+
51
50
  const button = tv({
52
51
  base: "font-medium bg-blue-500 text-white rounded-full active:opacity-80",
53
52
  variants: {
@@ -70,42 +69,60 @@ const button = tv({
70
69
  defaultVariants: {
71
70
  size: "md",
72
71
  color: "primary",
73
- }
72
+ },
74
73
  });
75
-
76
- return (
77
- <button className={button({ size: 'sm', color: 'secondary' })}>Click me</button>
78
- )
74
+
75
+ return <button className={button({size: "sm", color: "secondary"})}>Click me</button>;
79
76
  ```
80
77
 
81
78
  3. Responsive variants configuration (optional): If you want to use responsive variants
82
- you need to add the Tailwind Variants `wrapper` to your TailwindCSS config file `tailwind.config.js`.
79
+ you need to add the Tailwind Variants `wrapper` to your TailwindCSS config file `tailwind.config.js`.
83
80
 
84
81
  ```js
85
82
  // tailwind.config.js
86
-
87
- const { withTV } = require('tailwind-variants/transformer')
88
-
83
+
84
+ const {withTV} = require("tailwind-variants/transformer");
85
+
89
86
  /** @type {import('tailwindcss').Config} */
90
87
  module.exports = withTV({
91
- content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
88
+ content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
92
89
  theme: {
93
90
  extend: {},
94
91
  },
95
92
  plugins: [],
96
- })
93
+ });
97
94
  ```
98
95
 
96
+ If you're using a custom path to import Tailwind variants, such as creating a custom tv instance with `createTV`, it's recommended to include this path in the transformer configuration:
97
+
98
+ ```js
99
+ // tailwind.config.js
100
+
101
+ const {withTV} = require("tailwind-variants/transformer");
102
+
103
+ /** @type {import('tailwindcss').Config} */
104
+ module.exports = withTV(
105
+ {
106
+ content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
107
+ theme: {
108
+ extend: {},
109
+ },
110
+ plugins: [],
111
+ },
112
+ {
113
+ aliases: ["@/lib/tv"],
114
+ },
115
+ );
116
+ ```
99
117
 
100
118
  ## Acknowledgements
101
119
 
102
- - [**cva**](https://github.com/joe-bell/cva) ([Joe Bell](https://github.com/joe-bell))
120
+ - [**cva**](https://github.com/joe-bell/cva) ([Joe Bell](https://github.com/joe-bell))
103
121
  This project as started as an extension of Joe's work on `cva` – a great tool for generating variants for a single element with Tailwind CSS. Big shoutout to [Joe Bell](https://github.com/joe-bell) and [contributors](https://github.com/joe-bell/cva/graphs/contributors) you guys rock! 🤘 - we recommend to use `cva` if don't need any of the **Tailwind Variants** features listed [here](https://www.tailwind-variants.org/docs/comparison).
104
122
 
105
123
  - [**Stitches**](https://stitches.dev/) ([Modulz](https://modulz.app))
106
124
  The pioneers of the `variants` API movement. Inmense thanks to [Modulz](https://modulz.app) for their work on Stitches and the community around it. 🙏
107
125
 
108
-
109
126
  ## Community
110
127
 
111
128
  We're excited to see the community adopt NextUI, raise issues, and provide feedback. Whether it's a feature request, bug report, or a project to showcase, please get involved!
@@ -1,3 +1,3 @@
1
- var l=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,u=e=>!e||typeof e!="object"||Object.keys(e).length===0,x=(e,o)=>JSON.stringify(e)===JSON.stringify(o),A=e=>typeof e=="boolean";function i(e,o){e.forEach(function(r){Array.isArray(r)?i(r,o):o.push(r);});}function y(e){let o=[];return i(e,o),o}var a=(...e)=>y(e).filter(Boolean),p=(e,o)=>{let r={},c=Object.keys(e),f=Object.keys(o);for(let t of c)if(f.includes(t)){let s=e[t],n=o[t];typeof s=="object"&&typeof n=="object"?r[t]=p(s,n):Array.isArray(s)||Array.isArray(n)?r[t]=a(n,s):r[t]=n+" "+s;}else r[t]=e[t];for(let t of f)c.includes(t)||(r[t]=o[t]);return r},g=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();
1
+ var l=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,u=e=>!e||typeof e!="object"||Object.keys(e).length===0,x=(e,o)=>JSON.stringify(e)===JSON.stringify(o),A=e=>typeof e=="boolean";function i(e,o){e.forEach(function(r){Array.isArray(r)?i(r,o):o.push(r);});}function y(e){let o=[];return i(e,o),o}var a=(...e)=>y(e).filter(Boolean),p=(e,o)=>{let r={},c=Object.keys(e),f=Object.keys(o);for(let t of c)if(f.includes(t)){let s=e[t],n=o[t];Array.isArray(s)||Array.isArray(n)?r[t]=a(n,s):typeof s=="object"&&typeof n=="object"?r[t]=p(s,n):r[t]=n+" "+s;}else r[t]=e[t];for(let t of f)c.includes(t)||(r[t]=o[t]);return r},g=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();
2
2
 
3
3
  export { l as a, u as b, x as c, A as d, y as e, a as f, p as g, g as h };
package/dist/index.cjs CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  var tailwindMerge = require('tailwind-merge');
4
4
 
5
- var p=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,g=e=>!e||typeof e!="object"||Object.keys(e).length===0,Q=(e,l)=>JSON.stringify(e)===JSON.stringify(l);function X(e,l){e.forEach(function(t){Array.isArray(t)?X(t,l):l.push(t);});}function G(e){let l=[];return X(e,l),l}var q=(...e)=>G(e).filter(Boolean),E=(e,l)=>{let t={},O=Object.keys(e),w=Object.keys(l);for(let u of O)if(w.includes(u)){let v=e[u],h=l[u];typeof v=="object"&&typeof h=="object"?t[u]=E(v,h):Array.isArray(v)||Array.isArray(h)?t[u]=q(h,v):t[u]=h+" "+v;}else t[u]=e[u];for(let u of w)O.includes(u)||(t[u]=l[u]);return t},J=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();var ie={twMerge:!0,twMergeConfig:{},responsiveVariants:!1},Z=e=>e||void 0,M=(...e)=>Z(G(e).filter(Boolean).join(" ")),R=null,V={},F=!1,k=(...e)=>l=>l.twMerge?((!R||F)&&(F=!1,R=g(V)?tailwindMerge.twMerge:tailwindMerge.extendTailwindMerge({...V,extend:{theme:V.theme,classGroups:V.classGroups,conflictingClassGroupModifiers:V.conflictingClassGroupModifiers,conflictingClassGroups:V.conflictingClassGroups,...V.extend}})),Z(R(M(e)))):M(e),Y=(e,l)=>{for(let t in l)e.hasOwnProperty(t)?e[t]=M(e[t],l[t]):e[t]=l[t];return e},oe=(e,l)=>{let{extend:t=null,slots:O={},variants:w={},compoundVariants:u=[],compoundSlots:v=[],defaultVariants:h={}}=e,d={...ie,...l},$=t!=null&&t.base?M(t.base,e==null?void 0:e.base):e==null?void 0:e.base,b=t!=null&&t.variants&&!g(t.variants)?E(w,t.variants):w,j=t!=null&&t.defaultVariants&&!g(t.defaultVariants)?{...t.defaultVariants,...h}:h;!g(d.twMergeConfig)&&!Q(d.twMergeConfig,V)&&(F=!0,V=d.twMergeConfig);let S=g(t==null?void 0:t.slots),T=g(O)?{}:{base:M(e==null?void 0:e.base,S&&(t==null?void 0:t.base)),...O},N=S?T:Y({...t==null?void 0:t.slots},g(T)?{base:e==null?void 0:e.base}:T),C=f=>{if(g(b)&&g(O)&&S)return k($,f==null?void 0:f.class,f==null?void 0:f.className)(d);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 K=(n,s,r=[],c)=>{let a=r;if(typeof s=="string")a=a.concat(J(s).split(" ").map(o=>`${n}:${o}`));else if(Array.isArray(s))a=a.concat(s.reduce((o,i)=>o.concat(`${n}:${i}`),[]));else if(typeof s=="object"&&typeof c=="string"){for(let o in s)if(s.hasOwnProperty(o)&&o===c){let i=s[o];if(i&&typeof i=="string"){let y=J(i);a[c]?a[c]=a[c].concat(y.split(" ").map(m=>`${n}:${m}`)):a[c]=y.split(" ").map(m=>`${n}:${m}`);}else Array.isArray(i)&&i.length>0&&(a[c]=i.reduce((y,m)=>y.concat(`${n}:${m}`),[]));}}return a},U=(n,s=b,r=null,c=null)=>{var I;let a=s[n];if(!a||g(a))return null;let o=(I=c==null?void 0:c[n])!=null?I:f==null?void 0:f[n];if(o===null)return null;let i=p(o),y=Array.isArray(d.responsiveVariants)&&d.responsiveVariants.length>0||d.responsiveVariants===!0,m=j==null?void 0:j[n],A=[];if(typeof i=="object"&&y)for(let[B,L]of Object.entries(i)){let se=a[L];if(B==="initial"){m=L;continue}Array.isArray(d.responsiveVariants)&&!d.responsiveVariants.includes(B)||(A=K(B,se,A,r));}let re=i!=null&&typeof i!="object"?i:p(m),x=a[re]||a.false;return typeof A=="object"&&typeof r=="string"&&A[r]?Y(A,x):A.length>0?(A.push(x),A):x},P=()=>b?Object.keys(b).map(n=>U(n,b)):null,ee=(n,s)=>{if(!b||typeof b!="object")return null;let r=new Array;for(let c in b){let a=U(c,b,n,s),o=n==="base"&&typeof a=="string"?a:a&&a[n];o&&(r[r.length]=o);}return r},W={};for(let n in f)f[n]!==void 0&&(W[n]=f[n]);let z=(n,s)=>{var c;let r=typeof(f==null?void 0:f[n])=="object"?{[n]:(c=f[n])==null?void 0:c.initial}:{};return {...j,...W,...r,...s}},D=(n=[],s)=>{let r=[];for(let{class:c,className:a,...o}of n){let i=!0;for(let[y,m]of Object.entries(o)){let A=z(y,s);if(Array.isArray(m)){if(!m.includes(A[y])){i=!1;break}}else if(A[y]!==m){i=!1;break}}i&&(c&&r.push(c),a&&r.push(a));}return r},H=n=>{let s=D(u,n),r=D(t==null?void 0:t.compoundVariants,n);return q(r,s)},te=n=>{let s=H(n);if(!Array.isArray(s))return s;let r={};for(let c of s)if(typeof c=="string"&&(r.base=k(r.base,c)(d)),typeof c=="object")for(let[a,o]of Object.entries(c))r[a]=k(r[a],o)(d);return r},ne=n=>{if(v.length<1)return null;let s={};for(let{slots:r=[],class:c,className:a,...o}of v){if(!g(o)){let i=!0;for(let y of Object.keys(o)){let m=z(y,n)[y];if(m===void 0||(Array.isArray(o[y])?!o[y].includes(m):o[y]!==m)){i=!1;break}}if(!i)continue}for(let i of r)s[i]=s[i]||[],s[i].push([c,a]);}return s};if(!g(O)||!S){let n={};if(typeof N=="object"&&!g(N))for(let s of Object.keys(N))n[s]=r=>{var c,a;return k(N[s],ee(s,r),((c=te(r))!=null?c:[])[s],((a=ne(r))!=null?a:[])[s],r==null?void 0:r.class,r==null?void 0:r.className)(d)};return n}return k($,P(),H(),f==null?void 0:f.class,f==null?void 0:f.className)(d)},_=()=>{if(!(!b||typeof b!="object"))return Object.keys(b)};return C.variantKeys=_(),C.extend=t,C.base=$,C.slots=N,C.variants=b,C.defaultVariants=j,C.compoundSlots=v,C.compoundVariants=u,C},ye=e=>(l,t)=>oe(l,t?E(e,t):e);
5
+ var q=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,g=e=>!e||typeof e!="object"||Object.keys(e).length===0,X=(e,l)=>JSON.stringify(e)===JSON.stringify(l);function Y(e,l){e.forEach(function(t){Array.isArray(t)?Y(t,l):l.push(t);});}function F(e){let l=[];return Y(e,l),l}var J=(...e)=>F(e).filter(Boolean),T=(e,l)=>{let t={},O=Object.keys(e),k=Object.keys(l);for(let y of O)if(k.includes(y)){let V=e[y],h=l[y];Array.isArray(V)||Array.isArray(h)?t[y]=J(h,V):typeof V=="object"&&typeof h=="object"?t[y]=T(V,h):t[y]=h+" "+V;}else t[y]=e[y];for(let y of k)O.includes(y)||(t[y]=l[y]);return t},R=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();var ce={twMerge:!0,twMergeConfig:{},responsiveVariants:!1},_=e=>e||void 0,E=(...e)=>_(F(e).filter(Boolean).join(" ")),U=null,C={},W=!1,S=(...e)=>l=>l.twMerge?((!U||W)&&(W=!1,U=g(C)?tailwindMerge.twMerge:tailwindMerge.extendTailwindMerge({...C,extend:{theme:C.theme,classGroups:C.classGroups,conflictingClassGroupModifiers:C.conflictingClassGroupModifiers,conflictingClassGroups:C.conflictingClassGroups,...C.extend}})),_(U(E(e)))):E(e),Z=(e,l)=>{for(let t in l)e.hasOwnProperty(t)?e[t]=E(e[t],l[t]):e[t]=l[t];return e},oe=(e,l)=>{let{extend:t=null,slots:O={},variants:k={},compoundVariants:y=[],compoundSlots:V=[],defaultVariants:h={}}=e,d={...ce,...l},B=t!=null&&t.base?E(t.base,e==null?void 0:e.base):e==null?void 0:e.base,b=t!=null&&t.variants&&!g(t.variants)?T(k,t.variants):k,N=t!=null&&t.defaultVariants&&!g(t.defaultVariants)?{...t.defaultVariants,...h}:h;!g(d.twMergeConfig)&&!X(d.twMergeConfig,C)&&(W=!0,C=d.twMergeConfig);let $=g(t==null?void 0:t.slots),x=g(O)?{}:{base:E(e==null?void 0:e.base,$&&(t==null?void 0:t.base)),...O},M=$?x:Z({...t==null?void 0:t.slots},g(x)?{base:e==null?void 0:e.base}:x),j=g(t==null?void 0:t.compoundVariants)?y:J(t==null?void 0:t.compoundVariants,y),v=f=>{if(g(b)&&g(O)&&$)return S(B,f==null?void 0:f.class,f==null?void 0:f.className)(d);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 P=(r,a,n=[],i)=>{let s=n;if(typeof a=="string")s=s.concat(R(a).split(" ").map(o=>`${r}:${o}`));else if(Array.isArray(a))s=s.concat(a.reduce((o,c)=>o.concat(`${r}:${c}`),[]));else if(typeof a=="object"&&typeof i=="string"){for(let o in a)if(a.hasOwnProperty(o)&&o===i){let c=a[o];if(c&&typeof c=="string"){let m=R(c);s[i]?s[i]=s[i].concat(m.split(" ").map(u=>`${r}:${u}`)):s[i]=m.split(" ").map(u=>`${r}:${u}`);}else Array.isArray(c)&&c.length>0&&(s[i]=c.reduce((m,u)=>m.concat(`${r}:${u}`),[]));}}return s},z=(r,a=b,n=null,i=null)=>{var L;let s=a[r];if(!s||g(s))return null;let o=(L=i==null?void 0:i[r])!=null?L:f==null?void 0:f[r];if(o===null)return null;let c=q(o),m=Array.isArray(d.responsiveVariants)&&d.responsiveVariants.length>0||d.responsiveVariants===!0,u=N==null?void 0:N[r],A=[];if(typeof c=="object"&&m)for(let[G,Q]of Object.entries(c)){let ae=s[Q];if(G==="initial"){u=Q;continue}Array.isArray(d.responsiveVariants)&&!d.responsiveVariants.includes(G)||(A=P(G,ae,A,n));}let p=c!=null&&typeof c!="object"?c:q(u),w=s[p||"false"];return typeof A=="object"&&typeof n=="string"&&A[n]?Z(A,w):A.length>0?(A.push(w),n==="base"?A.join(" "):A):w},ee=()=>b?Object.keys(b).map(r=>z(r,b)):null,te=(r,a)=>{if(!b||typeof b!="object")return null;let n=new Array;for(let i in b){let s=z(i,b,r,a),o=r==="base"&&typeof s=="string"?s:s&&s[r];o&&(n[n.length]=o);}return n},D={};for(let r in f)f[r]!==void 0&&(D[r]=f[r]);let H=(r,a)=>{var i;let n=typeof(f==null?void 0:f[r])=="object"?{[r]:(i=f[r])==null?void 0:i.initial}:{};return {...N,...D,...n,...a}},I=(r=[],a)=>{let n=[];for(let{class:i,className:s,...o}of r){let c=!0;for(let[m,u]of Object.entries(o)){let A=H(m,a)[m];if(Array.isArray(u)){if(!u.includes(A)){c=!1;break}}else {let p=w=>w==null||w===!1;if(p(u)&&p(A))continue;if(A!==u){c=!1;break}}}c&&(i&&n.push(i),s&&n.push(s));}return n},ne=r=>{let a=I(j,r);if(!Array.isArray(a))return a;let n={};for(let i of a)if(typeof i=="string"&&(n.base=S(n.base,i)(d)),typeof i=="object")for(let[s,o]of Object.entries(i))n[s]=S(n[s],o)(d);return n},re=r=>{if(V.length<1)return null;let a={};for(let{slots:n=[],class:i,className:s,...o}of V){if(!g(o)){let c=!0;for(let m of Object.keys(o)){let u=H(m,r)[m];if(u===void 0||(Array.isArray(o[m])?!o[m].includes(u):o[m]!==u)){c=!1;break}}if(!c)continue}for(let c of n)a[c]=a[c]||[],a[c].push([i,s]);}return a};if(!g(O)||!$){let r={};if(typeof M=="object"&&!g(M))for(let a of Object.keys(M))r[a]=n=>{var i,s;return S(M[a],te(a,n),((i=ne(n))!=null?i:[])[a],((s=re(n))!=null?s:[])[a],n==null?void 0:n.class,n==null?void 0:n.className)(d)};return r}return S(B,ee(),I(j),f==null?void 0:f.class,f==null?void 0:f.className)(d)},K=()=>{if(!(!b||typeof b!="object"))return Object.keys(b)};return v.variantKeys=K(),v.extend=t,v.base=B,v.slots=M,v.variants=b,v.defaultVariants=N,v.compoundSlots=V,v.compoundVariants=j,v},ye=e=>(l,t)=>oe(l,t?T(e,t):e);
6
6
 
7
- exports.cn = k;
8
- exports.cnBase = M;
7
+ exports.cn = S;
8
+ exports.cnBase = E;
9
9
  exports.createTV = ye;
10
- exports.defaultConfig = ie;
10
+ exports.defaultConfig = ce;
11
11
  exports.tv = oe;
12
- exports.voidEmpty = Z;
12
+ exports.voidEmpty = _;
package/dist/index.d.ts CHANGED
@@ -153,23 +153,23 @@ export type TVProps<
153
153
  : StringToBoolean<keyof V[K]> | undefined;
154
154
  } & ClassProp<ClassValue>
155
155
  : V extends undefined
156
- ? {
157
- [K in keyof EV]?: isTrueOrArray<C["responsiveVariants"]> extends true
158
- ? StringToBoolean<keyof EV[K]> | TVScreenPropsValue<EV, ES, K, C> | undefined
159
- : StringToBoolean<keyof EV[K]> | undefined;
160
- } & ClassProp<ClassValue>
161
- : {
162
- [K in keyof V | keyof EV]?: isTrueOrArray<C["responsiveVariants"]> extends true
163
- ?
164
- | (K extends keyof V ? StringToBoolean<keyof V[K]> : never)
165
- | (K extends keyof EV ? StringToBoolean<keyof EV[K]> : never)
166
- | TVScreenPropsValue<EV & V, S, K, C>
167
- | undefined
168
- :
169
- | (K extends keyof V ? StringToBoolean<keyof V[K]> : never)
170
- | (K extends keyof EV ? StringToBoolean<keyof EV[K]> : never)
171
- | undefined;
172
- } & ClassProp<ClassValue>;
156
+ ? {
157
+ [K in keyof EV]?: isTrueOrArray<C["responsiveVariants"]> extends true
158
+ ? StringToBoolean<keyof EV[K]> | TVScreenPropsValue<EV, ES, K, C> | undefined
159
+ : StringToBoolean<keyof EV[K]> | undefined;
160
+ } & ClassProp<ClassValue>
161
+ : {
162
+ [K in keyof V | keyof EV]?: isTrueOrArray<C["responsiveVariants"]> extends true
163
+ ?
164
+ | (K extends keyof V ? StringToBoolean<keyof V[K]> : never)
165
+ | (K extends keyof EV ? StringToBoolean<keyof EV[K]> : never)
166
+ | TVScreenPropsValue<EV & V, S, K, C>
167
+ | undefined
168
+ :
169
+ | (K extends keyof V ? StringToBoolean<keyof V[K]> : never)
170
+ | (K extends keyof EV ? StringToBoolean<keyof EV[K]> : never)
171
+ | undefined;
172
+ } & ClassProp<ClassValue>;
173
173
 
174
174
  export type TVVariantKeys<V extends TVVariants<S>, S extends TVSlots> = V extends Object
175
175
  ? Array<keyof V>
@@ -290,10 +290,77 @@ export type TV = {
290
290
  ): TVReturnType<V, S, B, C, EV, ES, E>;
291
291
  };
292
292
 
293
+ export type CreateTV<RV extends TVConfig["responsiveVariants"] = undefined> = {
294
+ <
295
+ V extends TVVariants<S, B, EV>,
296
+ CV extends TVCompoundVariants<V, S, B, EV, ES>,
297
+ DV extends TVDefaultVariants<V, S, EV, ES>,
298
+ C extends TVConfig<V, EV>,
299
+ B extends ClassValue = undefined,
300
+ S extends TVSlots = undefined,
301
+ // @ts-expect-error
302
+ E extends TVReturnType = TVReturnType<
303
+ V,
304
+ S,
305
+ B,
306
+ C,
307
+ // @ts-expect-error
308
+ EV extends undefined ? {} : EV,
309
+ // @ts-expect-error
310
+ ES extends undefined ? {} : ES
311
+ >,
312
+ EV extends TVVariants<ES, B, E["variants"], ES> = E["variants"],
313
+ ES extends TVSlots = E["slots"] extends TVSlots ? E["slots"] : undefined,
314
+ >(
315
+ options: {
316
+ /**
317
+ * Extend allows for easy composition of components.
318
+ * @see https://www.tailwind-variants.org/docs/composing-components
319
+ */
320
+ extend?: E;
321
+ /**
322
+ * Base allows you to set a base class for a component.
323
+ */
324
+ base?: B;
325
+ /**
326
+ * Slots allow you to separate a component into multiple parts.
327
+ * @see https://www.tailwind-variants.org/docs/slots
328
+ */
329
+ slots?: S;
330
+ /**
331
+ * Variants allow you to create multiple versions of the same component.
332
+ * @see https://www.tailwind-variants.org/docs/variants#adding-variants
333
+ */
334
+ variants?: V;
335
+ /**
336
+ * Compound variants allow you to apply classes to multiple variants at once.
337
+ * @see https://www.tailwind-variants.org/docs/variants#compound-variants
338
+ */
339
+ compoundVariants?: CV;
340
+ /**
341
+ * Compound slots allow you to apply classes to multiple slots at once.
342
+ */
343
+ compoundSlots?: TVCompoundSlots<V, S, B>;
344
+ /**
345
+ * Default variants allow you to set default variants for a component.
346
+ * @see https://www.tailwind-variants.org/docs/variants#default-variants
347
+ */
348
+ defaultVariants?: DV;
349
+ },
350
+ /**
351
+ * The config object allows you to modify the default configuration.
352
+ * @see https://www.tailwind-variants.org/docs/api-reference#config-optional
353
+ */
354
+ config?: C,
355
+ ): TVReturnType<V, S, B, C & RV, EV, ES, E>;
356
+ };
357
+
293
358
  // main function
294
359
  export declare const tv: TV;
295
360
 
296
- export declare function createTV(config: TVConfig): TV;
361
+ export declare function createTV<T extends TVConfig["responsiveVariants"]>(
362
+ config: TVConfig & T,
363
+ ): CreateTV<T>;
297
364
 
298
365
  export declare const defaultConfig: TVConfig;
299
366
 
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { e, b, g, c, f, a, h } from './chunk-JXBJZR5A.js';
1
+ import { e, b, g, c, f, a, h } from './chunk-I2QGXAA3.js';
2
2
  import { twMerge, extendTailwindMerge } from 'tailwind-merge';
3
3
 
4
- var ie={twMerge:!0,twMergeConfig:{},responsiveVariants:!1},Z=s=>s||void 0,N=(...s)=>Z(e(s).filter(Boolean).join(" ")),R=null,C={},q=!1,j=(...s)=>b$1=>b$1.twMerge?((!R||q)&&(q=!1,R=b(C)?twMerge:extendTailwindMerge({...C,extend:{theme:C.theme,classGroups:C.classGroups,conflictingClassGroupModifiers:C.conflictingClassGroupModifiers,conflictingClassGroups:C.conflictingClassGroups,...C.extend}})),Z(R(N(s)))):N(s),Y=(s,b)=>{for(let e in b)s.hasOwnProperty(e)?s[e]=N(s[e],b[e]):s[e]=b[e];return s},ce=(s,b$1)=>{let{extend:e=null,slots:M={},variants:F={},compoundVariants:h$1=[],compoundSlots:V=[],defaultVariants:U={}}=s,m={...ie,...b$1},S=e!=null&&e.base?N(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,C)&&(q=!0,C=m.twMergeConfig);let O=b(e==null?void 0:e.slots),$=b(M)?{}:{base:N(s==null?void 0:s.base,O&&(e==null?void 0:e.base)),...M},w=O?$:Y({...e==null?void 0:e.slots},b($)?{base:s==null?void 0:s.base}:$),v=f$1=>{if(b(g$1)&&b(M)&&O)return j(S,f$1==null?void 0:f$1.class,f$1==null?void 0:f$1.className)(m);if(h$1&&!Array.isArray(h$1))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof h$1}`);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(l=>`${t}:${l}`));else if(Array.isArray(n))r=r.concat(n.reduce((l,c)=>l.concat(`${t}:${c}`),[]));else if(typeof n=="object"&&typeof i=="string"){for(let l in n)if(n.hasOwnProperty(l)&&l===i){let c=n[l];if(c&&typeof c=="string"){let o=h(c);r[i]?r[i]=r[i].concat(o.split(" ").map(u=>`${t}:${u}`)):r[i]=o.split(" ").map(u=>`${t}:${u}`);}else Array.isArray(c)&&c.length>0&&(r[i]=c.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 l=(I=i==null?void 0:i[t])!=null?I:f$1==null?void 0:f$1[t];if(l===null)return null;let c=a(l),o=Array.isArray(m.responsiveVariants)&&m.responsiveVariants.length>0||m.responsiveVariants===!0,u=A==null?void 0:A[t],d=[];if(typeof c=="object"&&o)for(let[T,J]of Object.entries(c)){let ne=r[J];if(T==="initial"){u=J;continue}Array.isArray(m.responsiveVariants)&&!m.responsiveVariants.includes(T)||(d=K(T,ne,d,a$1));}let ae=c!=null&&typeof c!="object"?c:a(u),k=r[ae]||r.false;return typeof d=="object"&&typeof a$1=="string"&&d[a$1]?Y(d,k):d.length>0?(d.push(k),d):k},P=()=>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),l=t==="base"&&typeof r=="string"?r:r&&r[t];l&&(a[a.length]=l);}return a},x={};for(let t in f$1)f$1[t]!==void 0&&(x[t]=f$1[t]);let z=(t,n)=>{var i;let a=typeof(f$1==null?void 0:f$1[t])=="object"?{[t]:(i=f$1[t])==null?void 0:i.initial}:{};return {...A,...x,...a,...n}},D=(t=[],n)=>{let a=[];for(let{class:i,className:r,...l}of t){let c=!0;for(let[o,u]of Object.entries(l)){let d=z(o,n);if(Array.isArray(u)){if(!u.includes(d[o])){c=!1;break}}else if(d[o]!==u){c=!1;break}}c&&(i&&a.push(i),r&&a.push(r));}return a},H=t=>{let n=D(h$1,t),a=D(e==null?void 0:e.compoundVariants,t);return f(a,n)},ee=t=>{let n=H(t);if(!Array.isArray(n))return n;let a={};for(let i of n)if(typeof i=="string"&&(a.base=j(a.base,i)(m)),typeof i=="object")for(let[r,l]of Object.entries(i))a[r]=j(a[r],l)(m);return a},te=t=>{if(V.length<1)return null;let n={};for(let{slots:a=[],class:i,className:r,...l}of V){if(!b(l)){let c=!0;for(let o of Object.keys(l)){let u=z(o,t)[o];if(u===void 0||(Array.isArray(l[o])?!l[o].includes(u):l[o]!==u)){c=!1;break}}if(!c)continue}for(let c of a)n[c]=n[c]||[],n[c].push([i,r]);}return n};if(!b(M)||!O){let t={};if(typeof w=="object"&&!b(w))for(let n of Object.keys(w))t[n]=a=>{var i,r;return j(w[n],p(n,a),((i=ee(a))!=null?i:[])[n],((r=te(a))!=null?r:[])[n],a==null?void 0:a.class,a==null?void 0:a.className)(m)};return t}return j(S,P(),H(),f$1==null?void 0:f$1.class,f$1==null?void 0:f$1.className)(m)},_=()=>{if(!(!g$1||typeof g$1!="object"))return Object.keys(g$1)};return v.variantKeys=_(),v.extend=e,v.base=S,v.slots=w,v.variants=g$1,v.defaultVariants=A,v.compoundSlots=V,v.compoundVariants=h$1,v},oe=s=>(b,e)=>ce(b,e?g(s,e):s);
4
+ var ie={twMerge:!0,twMergeConfig:{},responsiveVariants:!1},x=s=>s||void 0,N=(...s)=>x(e(s).filter(Boolean).join(" ")),R=null,v={},q=!1,M=(...s)=>b$1=>b$1.twMerge?((!R||q)&&(q=!1,R=b(v)?twMerge:extendTailwindMerge({...v,extend:{theme:v.theme,classGroups:v.classGroups,conflictingClassGroupModifiers:v.conflictingClassGroupModifiers,conflictingClassGroups:v.conflictingClassGroups,...v.extend}})),x(R(N(s)))):N(s),_=(s,b)=>{for(let e in b)s.hasOwnProperty(e)?s[e]=N(s[e],b[e]):s[e]=b[e];return s},ce=(s,b$1)=>{let{extend:e=null,slots:O={},variants:U={},compoundVariants:W=[],compoundSlots:C=[],defaultVariants:z={}}=s,m={...ie,...b$1},k=e!=null&&e.base?N(e.base,s==null?void 0:s.base):s==null?void 0:s.base,g$1=e!=null&&e.variants&&!b(e.variants)?g(U,e.variants):U,w=e!=null&&e.defaultVariants&&!b(e.defaultVariants)?{...e.defaultVariants,...z}:z;!b(m.twMergeConfig)&&!c(m.twMergeConfig,v)&&(q=!0,v=m.twMergeConfig);let S=b(e==null?void 0:e.slots),T=b(O)?{}:{base:N(s==null?void 0:s.base,S&&(e==null?void 0:e.base)),...O},j=S?T:_({...e==null?void 0:e.slots},b(T)?{base:s==null?void 0:s.base}:T),h$1=b(e==null?void 0:e.compoundVariants)?W:f(e==null?void 0:e.compoundVariants,W),V=l=>{if(b(g$1)&&b(O)&&S)return M(k,l==null?void 0:l.class,l==null?void 0:l.className)(m);if(h$1&&!Array.isArray(h$1))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof h$1}`);if(C&&!Array.isArray(C))throw new TypeError(`The "compoundSlots" prop must be an array. Received: ${typeof C}`);let P=(a,n,t=[],i)=>{let r=t;if(typeof n=="string")r=r.concat(h(n).split(" ").map(o=>`${a}:${o}`));else if(Array.isArray(n))r=r.concat(n.reduce((o,c)=>o.concat(`${a}:${c}`),[]));else if(typeof n=="object"&&typeof i=="string"){for(let o in n)if(n.hasOwnProperty(o)&&o===i){let c=n[o];if(c&&typeof c=="string"){let u=h(c);r[i]?r[i]=r[i].concat(u.split(" ").map(f=>`${a}:${f}`)):r[i]=u.split(" ").map(f=>`${a}:${f}`);}else Array.isArray(c)&&c.length>0&&(r[i]=c.reduce((u,f)=>u.concat(`${a}:${f}`),[]));}}return r},D=(a$1,n=g$1,t=null,i=null)=>{var L;let r=n[a$1];if(!r||b(r))return null;let o=(L=i==null?void 0:i[a$1])!=null?L:l==null?void 0:l[a$1];if(o===null)return null;let c=a(o),u=Array.isArray(m.responsiveVariants)&&m.responsiveVariants.length>0||m.responsiveVariants===!0,f=w==null?void 0:w[a$1],d=[];if(typeof c=="object"&&u)for(let[E,Q]of Object.entries(c)){let ne=r[Q];if(E==="initial"){f=Q;continue}Array.isArray(m.responsiveVariants)&&!m.responsiveVariants.includes(E)||(d=P(E,ne,d,t));}let $=c!=null&&typeof c!="object"?c:a(f),A=r[$||"false"];return typeof d=="object"&&typeof t=="string"&&d[t]?_(d,A):d.length>0?(d.push(A),t==="base"?d.join(" "):d):A},p=()=>g$1?Object.keys(g$1).map(a=>D(a,g$1)):null,ee=(a,n)=>{if(!g$1||typeof g$1!="object")return null;let t=new Array;for(let i in g$1){let r=D(i,g$1,a,n),o=a==="base"&&typeof r=="string"?r:r&&r[a];o&&(t[t.length]=o);}return t},H={};for(let a in l)l[a]!==void 0&&(H[a]=l[a]);let I=(a,n)=>{var i;let t=typeof(l==null?void 0:l[a])=="object"?{[a]:(i=l[a])==null?void 0:i.initial}:{};return {...w,...H,...t,...n}},J=(a=[],n)=>{let t=[];for(let{class:i,className:r,...o}of a){let c=!0;for(let[u,f]of Object.entries(o)){let d=I(u,n)[u];if(Array.isArray(f)){if(!f.includes(d)){c=!1;break}}else {let $=A=>A==null||A===!1;if($(f)&&$(d))continue;if(d!==f){c=!1;break}}}c&&(i&&t.push(i),r&&t.push(r));}return t},te=a=>{let n=J(h$1,a);if(!Array.isArray(n))return n;let t={};for(let i of n)if(typeof i=="string"&&(t.base=M(t.base,i)(m)),typeof i=="object")for(let[r,o]of Object.entries(i))t[r]=M(t[r],o)(m);return t},ae=a=>{if(C.length<1)return null;let n={};for(let{slots:t=[],class:i,className:r,...o}of C){if(!b(o)){let c=!0;for(let u of Object.keys(o)){let f=I(u,a)[u];if(f===void 0||(Array.isArray(o[u])?!o[u].includes(f):o[u]!==f)){c=!1;break}}if(!c)continue}for(let c of t)n[c]=n[c]||[],n[c].push([i,r]);}return n};if(!b(O)||!S){let a={};if(typeof j=="object"&&!b(j))for(let n of Object.keys(j))a[n]=t=>{var i,r;return M(j[n],ee(n,t),((i=te(t))!=null?i:[])[n],((r=ae(t))!=null?r:[])[n],t==null?void 0:t.class,t==null?void 0:t.className)(m)};return a}return M(k,p(),J(h$1),l==null?void 0:l.class,l==null?void 0:l.className)(m)},K=()=>{if(!(!g$1||typeof g$1!="object"))return Object.keys(g$1)};return V.variantKeys=K(),V.extend=e,V.base=k,V.slots=j,V.variants=g$1,V.defaultVariants=w,V.compoundSlots=C,V.compoundVariants=h$1,V},fe=s=>(b,e)=>ce(b,e?g(s,e):s);
5
5
 
6
- export { j as cn, N as cnBase, oe as createTV, ie as defaultConfig, ce as tv, Z as voidEmpty };
6
+ export { M as cn, N as cnBase, fe as createTV, ie as defaultConfig, ce as tv, x as voidEmpty };
@@ -10,17 +10,17 @@ var V__default = /*#__PURE__*/_interopDefault(V);
10
10
  var w__default = /*#__PURE__*/_interopDefault(w);
11
11
  var O__default = /*#__PURE__*/_interopDefault(O);
12
12
 
13
- var S=t=>{w__default.default.writeFileSync(O__default.default.join(__dirname,"generated.d.ts"),t);},C=t=>`export type TVGeneratedScreens = ${Object.keys(t).map(e=>`"${e}"`).join(" | ")};
14
- `,v=t=>{queueMicrotask(()=>{if(t!=null&&t.screens){let e=C(t.screens);S(e);}});};var u={tv:/tv\s*\(((\([^\)]*?\)|\[[^\]]*?\]|.)*?)\)/gs,tvExtend:/extend:\s*\w+(,| )\s*/,comment:/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,blankLine:/^\s*$(?:\r\n?|\n)/gm,extension:/\.\w+/g},l=t=>Array.isArray(t),E=t=>typeof t=="string",p=t=>typeof t=="object",$=t=>typeof t=="boolean",y=t=>typeof t=="function",c=t=>!!(!t||l(t)&&t.length===0||E(t)&&t.length===0||p(t)&&Object.keys(t).length===0),k=(t,e)=>{let n={},r=e.length,s=Object.prototype.hasOwnProperty;for(let i=0;i<r;i++){let o=e[i];s.call(t,o)&&(n[o]=t[o]);}return n},A=(t,e)=>{let n="https://github.com/nextui-org/tailwind-variants/issues/new/choose";console.log("\x1B[31m%s\x1B[0m",`${t}: ${e.message}`),console.log(`If you think this is an issue, please submit it at ${n}`);},x=(...t)=>e=>t.reduce((n,r)=>r(n),e),F=t=>{let n=t.replace(u.comment,"$1").toString().replace(u.blankLine,"").toString(),r=s=>s[1].replace(u.tvExtend,"").toString();return Array.from(n.matchAll(u.tv),r)},B=t=>{let e=F(t);if(!c(e))return e.map(n=>n.includes("responsiveVariants")?new Function(`
13
+ var S=t=>{w__default.default.writeFileSync(O__default.default.join(__dirname,"generated.d.ts"),t);},C=t=>`export type TVGeneratedScreens = ${Object.keys(t).map(r=>`"${r}"`).join(" | ")};
14
+ `,v=t=>{queueMicrotask(()=>{if(t!=null&&t.screens){let r=C(t.screens);S(r);}});};var p={tv:/tv\s*\(((\([^\)]*?\)|\[[^\]]*?\]|.)*?)\)/gs,tvExtend:/extend:\s*\w+(,| )\s*/,comment:/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,blankLine:/^\s*$(?:\r\n?|\n)/gm,extension:/\.\w+/g},l=t=>Array.isArray(t),b=t=>typeof t=="string",d=t=>typeof t=="object",$=t=>typeof t=="boolean",y=t=>typeof t=="function",f=t=>!!(!t||l(t)&&t.length===0||b(t)&&t.length===0||d(t)&&Object.keys(t).length===0),k=(t,r)=>{let n={},e=r.length,s=Object.prototype.hasOwnProperty;for(let a=0;a<e;a++){let o=r[a];s.call(t,o)&&(n[o]=t[o]);}return n},A=(t,r)=>{let n="https://github.com/nextui-org/tailwind-variants/issues/new/choose";console.log("\x1B[31m%s\x1B[0m",`${t}: ${r.message}`),console.log(`If you think this is an issue, please submit it at ${n}`);},h=(...t)=>r=>t.reduce((n,e)=>e(n),r),P=t=>{let n=t.replace(p.comment,"$1").toString().replace(p.blankLine,"").toString(),e=s=>s[1].replace(p.tvExtend,"").toString();return Array.from(n.matchAll(p.tv),e)},F=t=>{let r=P(t);if(!f(r))return r.map(n=>n.includes("responsiveVariants")?new Function(`
15
15
  const [options, config] = [${n.toString()}];
16
16
  return {options, config};
17
- `)():{})},h=t=>t.flatMap(e=>e).toString().replaceAll(","," ").split(" "),D=(t,e)=>{let n={};for(let[r,s]of Object.entries(t))n[r]={},n[r].original=s,!c(s)&&(n.temp=l(s)?h(s):s.split(" "),e.forEach(i=>{let o="";n.temp.forEach(a=>{o+=`${i}:${a} `;}),n[r][i]=o.trimEnd();}),delete n.temp);return n},L=(t,e)=>E(t)?t.split(" "):l(t)?h(t):p(t)?D(t,e):t,b=(t,e)=>{let n={};for(let[r,s]of Object.entries(t))if(n[r]={},!c(s))for(let[i,o]of Object.entries(s)){if(n[r][i]={},n[r][i].original=o,c(o))continue;let a=L(o,e);if(!c(a)){if(!l(a)){n[r][i]=a;continue}e.forEach(m=>{let f="";a.forEach(d=>{f+=`${m}:${d} `;}),n[r][i][m]=f.trimEnd();});}}return n},T=({options:t,config:e},n)=>{var i,o;let r=(i=t==null?void 0:t.variants)!=null?i:{},s=(o=e==null?void 0:e.responsiveVariants)!=null?o:!1;if(!(!s||c(r))){if($(s))return b(r,n);if(l(s))return b(r,s);if(p(s)){let a=[];for(let[m,f]of Object.entries(s)){if(!f||c(f))continue;let j={options:{variants:k(r,[m])},config:{responsiveVariants:f}};a.push(T(j,n));}return a}}},N=(t,e)=>{try{if(!t.includes("tailwind-variants"))return t;let n=B(t);if(c(n))return t;let r=JSON.stringify(n.map(o=>T(o,e)),void 0,2),s=`
17
+ `)():{})},E=t=>t.flatMap(r=>r).toString().replaceAll(","," ").split(" "),I=(t,r)=>{let n={};for(let[e,s]of Object.entries(t))n[e]={},n[e].original=s,!f(s)&&(n.temp=l(s)?E(s):s.split(" "),r.forEach(a=>{let o="";n.temp.forEach(i=>{o+=`${a}:${i} `;}),n[e][a]=o.trimEnd();}),delete n.temp);return n},B=(t,r)=>b(t)?t.split(" "):l(t)?E(t):d(t)?I(t,r):t,x=(t,r)=>{let n={};for(let[e,s]of Object.entries(t))if(n[e]={},!f(s))for(let[a,o]of Object.entries(s)){if(n[e][a]={},n[e][a].original=o,f(o))continue;let i=B(o,r);if(!f(i)){if(!l(i)){n[e][a]=i;continue}r.forEach(c=>{let m="";i.forEach(u=>{m+=`${c}:${u} `;}),n[e][a][c]=m.trimEnd();});}}return n},T=({options:t,config:r},n)=>{var a,o;let e=(a=t==null?void 0:t.variants)!=null?a:{},s=(o=r==null?void 0:r.responsiveVariants)!=null?o:!1;if(!(!s||f(e))){if($(s))return x(e,n);if(l(s))return x(e,s);if(d(s)){let i=[];for(let[c,m]of Object.entries(s)){if(!m||f(m))continue;let j={options:{variants:k(e,[c])},config:{responsiveVariants:m}};i.push(T(j,n));}return i}}},D=(t,r,n)=>{try{let e=["tailwind-variants"];if(!(l(n==null?void 0:n.aliases)?[...n.aliases,...e]:e).some(u=>t.includes(u)))return t;let o=F(t);if(f(o))return t;let i=JSON.stringify(o.map(u=>T(u,r)),void 0,2),c=`
18
18
  /* Tailwind Variants Transformed Content Start
19
19
 
20
- `,i=`
20
+ `,m=`
21
21
 
22
22
  Tailwind Variants Transformed Content End */
23
- `;return t.concat(s+r+i)}catch(n){return A("Tailwind Variants Transform Failed",n),t}},g=t=>{let e=t.map(n=>{if(p(n)&&n.extension)return n.extension;let r=n.match(u.extension);return r||(r=n.split("{"),r=r.pop().replace("}","").split(",")),r.map(s=>s.replace(".","").split(".")).flat()}).flatMap(n=>n);return Array.from(new Set(e)).filter(n=>n!=="html")},G=t=>{var s;let e=V__default.default(t);if(v(e.theme),c((s=e.content)==null?void 0:s.files)||!l(e.content.files))return e;let n=i=>{var o,a;return N(i,Object.keys((a=(o=e.theme)==null?void 0:o.screens)!=null?a:{}))},r=e.content.transform;if(c(r)){let o=g(e.content.files).map(a=>[a,n]);return e.content.transform=Object.fromEntries(o),e}if(y(r)){let o=g(e.content.files).map(a=>[a,x(n,r)]);return e.content.transform=Object.fromEntries(o),e}if(p(r)){let o=g(e.content.files).map(a=>y(r[a])?[a,x(n,r[a])]:[a,n]);return e.content.transform=Object.fromEntries(o),e}return e};
23
+ `;return t.concat(c+i+m)}catch(e){return A("Tailwind Variants Transform Failed",e),t}},g=t=>{let r=t.map(n=>{if(d(n)&&n.extension)return n.extension;let e=n.match(p.extension);return e||(e=n.split("{"),e=e.pop().replace("}","").split(",")),e.map(s=>s.replace(".","").split(".")).flat()}).flatMap(n=>n);return Array.from(new Set(r)).filter(n=>n!=="html")},G=(t,r)=>{var a;let n=V__default.default(t);if(v(n.theme),f((a=n.content)==null?void 0:a.files)||!l(n.content.files))return n;let e=o=>{var i,c;return D(o,Object.keys((c=(i=n.theme)==null?void 0:i.screens)!=null?c:{}),r)},s=n.content.transform;if(f(s)){let i=g(n.content.files).map(c=>[c,e]);return n.content.transform=Object.fromEntries(i),n}if(y(s)){let i=g(n.content.files).map(c=>[c,h(e,s)]);return n.content.transform=Object.fromEntries(i),n}if(d(s)){let i=g(n.content.files).map(c=>y(s[c])?[c,h(e,s[c])]:[c,e]);return n.content.transform=Object.fromEntries(i),n}return n};
24
24
 
25
- exports.tvTransformer = N;
25
+ exports.tvTransformer = D;
26
26
  exports.withTV = G;
@@ -4,13 +4,23 @@ import type {DefaultTheme} from "tailwindcss/types/generated/default-theme";
4
4
  export type DefaultScreens = keyof DefaultTheme["screens"];
5
5
 
6
6
  export type WithTV = {
7
- <C extends Config>(tvConfig: C): C;
7
+ <C extends Config>(tvConfig: C, config?: TVTransformerConfig): C;
8
8
  };
9
9
 
10
10
  export declare const withTV: WithTV;
11
11
 
12
+ export type TVTransformerConfig = {
13
+ /**
14
+ * Optional array of custom aliases where Tailwind Variants might be resolved.
15
+ * This can be useful if you're using a custom path to import Tailwind Variants.
16
+ *
17
+ * @example ["@/lib/tv"]
18
+ */
19
+ aliases?: string[];
20
+ };
21
+
12
22
  export type TVTransformer = {
13
- (content: string, screens?: string[] | DefaultScreens[]): string;
23
+ (content: string, screens?: string[] | DefaultScreens[], config?: TVTransformerConfig): string;
14
24
  };
15
25
 
16
26
  export declare const tvTransformer: TVTransformer;
@@ -1,15 +1,15 @@
1
1
  import { a } from './chunk-FUBUDMV2.js';
2
2
  import w from 'tailwindcss/resolveConfig';
3
3
 
4
- var u={tv:/tv\s*\(((\([^\)]*?\)|\[[^\]]*?\]|.)*?)\)/gs,tvExtend:/extend:\s*\w+(,| )\s*/,comment:/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,blankLine:/^\s*$(?:\r\n?|\n)/gm,extension:/\.\w+/g},l=t=>Array.isArray(t),E=t=>typeof t=="string",p=t=>typeof t=="object",T=t=>typeof t=="boolean",h=t=>typeof t=="function",c=t=>!!(!t||l(t)&&t.length===0||E(t)&&t.length===0||p(t)&&Object.keys(t).length===0),j=(t,e)=>{let n={},r=e.length,s=Object.prototype.hasOwnProperty;for(let i=0;i<r;i++){let o=e[i];s.call(t,o)&&(n[o]=t[o]);}return n},V=(t,e)=>{let n="https://github.com/nextui-org/tailwind-variants/issues/new/choose";console.log("\x1B[31m%s\x1B[0m",`${t}: ${e.message}`),console.log(`If you think this is an issue, please submit it at ${n}`);},x=(...t)=>e=>t.reduce((n,r)=>r(n),e),S=t=>{let n=t.replace(u.comment,"$1").toString().replace(u.blankLine,"").toString(),r=s=>s[1].replace(u.tvExtend,"").toString();return Array.from(n.matchAll(u.tv),r)},$=t=>{let e=S(t);if(!c(e))return e.map(n=>n.includes("responsiveVariants")?new Function(`
5
- const [options, config] = [${n.toString()}];
4
+ var p={tv:/tv\s*\(((\([^\)]*?\)|\[[^\]]*?\]|.)*?)\)/gs,tvExtend:/extend:\s*\w+(,| )\s*/,comment:/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,blankLine:/^\s*$(?:\r\n?|\n)/gm,extension:/\.\w+/g},l=n=>Array.isArray(n),E=n=>typeof n=="string",d=n=>typeof n=="object",T=n=>typeof n=="boolean",g=n=>typeof n=="function",f=n=>!!(!n||l(n)&&n.length===0||E(n)&&n.length===0||d(n)&&Object.keys(n).length===0),j=(n,r)=>{let t={},e=r.length,s=Object.prototype.hasOwnProperty;for(let a=0;a<e;a++){let o=r[a];s.call(n,o)&&(t[o]=n[o]);}return t},V=(n,r)=>{let t="https://github.com/nextui-org/tailwind-variants/issues/new/choose";console.log("\x1B[31m%s\x1B[0m",`${n}: ${r.message}`),console.log(`If you think this is an issue, please submit it at ${t}`);},x=(...n)=>r=>n.reduce((t,e)=>e(t),r),S=n=>{let t=n.replace(p.comment,"$1").toString().replace(p.blankLine,"").toString(),e=s=>s[1].replace(p.tvExtend,"").toString();return Array.from(t.matchAll(p.tv),e)},$=n=>{let r=S(n);if(!f(r))return r.map(t=>t.includes("responsiveVariants")?new Function(`
5
+ const [options, config] = [${t.toString()}];
6
6
  return {options, config};
7
- `)():{})},b=t=>t.flatMap(e=>e).toString().replaceAll(","," ").split(" "),k=(t,e)=>{let n={};for(let[r,s]of Object.entries(t))n[r]={},n[r].original=s,!c(s)&&(n.temp=l(s)?b(s):s.split(" "),e.forEach(i=>{let o="";n.temp.forEach(a=>{o+=`${i}:${a} `;}),n[r][i]=o.trimEnd();}),delete n.temp);return n},A=(t,e)=>E(t)?t.split(" "):l(t)?b(t):p(t)?k(t,e):t,y=(t,e)=>{let n={};for(let[r,s]of Object.entries(t))if(n[r]={},!c(s))for(let[i,o]of Object.entries(s)){if(n[r][i]={},n[r][i].original=o,c(o))continue;let a=A(o,e);if(!c(a)){if(!l(a)){n[r][i]=a;continue}e.forEach(m=>{let f="";a.forEach(v=>{f+=`${m}:${v} `;}),n[r][i][m]=f.trimEnd();});}}return n},C=({options:t,config:e},n)=>{var i,o;let r=(i=t==null?void 0:t.variants)!=null?i:{},s=(o=e==null?void 0:e.responsiveVariants)!=null?o:!1;if(!(!s||c(r))){if(T(s))return y(r,n);if(l(s))return y(r,s);if(p(s)){let a=[];for(let[m,f]of Object.entries(s)){if(!f||c(f))continue;let O={options:{variants:j(r,[m])},config:{responsiveVariants:f}};a.push(C(O,n));}return a}}},B=(t,e)=>{try{if(!t.includes("tailwind-variants"))return t;let n=$(t);if(c(n))return t;let r=JSON.stringify(n.map(o=>C(o,e)),void 0,2),s=`
7
+ `)():{})},b=n=>n.flatMap(r=>r).toString().replaceAll(","," ").split(" "),k=(n,r)=>{let t={};for(let[e,s]of Object.entries(n))t[e]={},t[e].original=s,!f(s)&&(t.temp=l(s)?b(s):s.split(" "),r.forEach(a=>{let o="";t.temp.forEach(i=>{o+=`${a}:${i} `;}),t[e][a]=o.trimEnd();}),delete t.temp);return t},A=(n,r)=>E(n)?n.split(" "):l(n)?b(n):d(n)?k(n,r):n,y=(n,r)=>{let t={};for(let[e,s]of Object.entries(n))if(t[e]={},!f(s))for(let[a,o]of Object.entries(s)){if(t[e][a]={},t[e][a].original=o,f(o))continue;let i=A(o,r);if(!f(i)){if(!l(i)){t[e][a]=i;continue}r.forEach(c=>{let m="";i.forEach(u=>{m+=`${c}:${u} `;}),t[e][a][c]=m.trimEnd();});}}return t},C=({options:n,config:r},t)=>{var a,o;let e=(a=n==null?void 0:n.variants)!=null?a:{},s=(o=r==null?void 0:r.responsiveVariants)!=null?o:!1;if(!(!s||f(e))){if(T(s))return y(e,t);if(l(s))return y(e,s);if(d(s)){let i=[];for(let[c,m]of Object.entries(s)){if(!m||f(m))continue;let O={options:{variants:j(e,[c])},config:{responsiveVariants:m}};i.push(C(O,t));}return i}}},P=(n,r,t)=>{try{let e=["tailwind-variants"];if(!(l(t==null?void 0:t.aliases)?[...t.aliases,...e]:e).some(u=>n.includes(u)))return n;let o=$(n);if(f(o))return n;let i=JSON.stringify(o.map(u=>C(u,r)),void 0,2),c=`
8
8
  /* Tailwind Variants Transformed Content Start
9
9
 
10
- `,i=`
10
+ `,m=`
11
11
 
12
12
  Tailwind Variants Transformed Content End */
13
- `;return t.concat(s+r+i)}catch(n){return V("Tailwind Variants Transform Failed",n),t}},g=t=>{let e=t.map(n=>{if(p(n)&&n.extension)return n.extension;let r=n.match(u.extension);return r||(r=n.split("{"),r=r.pop().replace("}","").split(",")),r.map(s=>s.replace(".","").split(".")).flat()}).flatMap(n=>n);return Array.from(new Set(e)).filter(n=>n!=="html")},N=t=>{var s;let e=w(t);if(a(e.theme),c((s=e.content)==null?void 0:s.files)||!l(e.content.files))return e;let n=i=>{var o,a;return B(i,Object.keys((a=(o=e.theme)==null?void 0:o.screens)!=null?a:{}))},r=e.content.transform;if(c(r)){let o=g(e.content.files).map(a=>[a,n]);return e.content.transform=Object.fromEntries(o),e}if(h(r)){let o=g(e.content.files).map(a=>[a,x(n,r)]);return e.content.transform=Object.fromEntries(o),e}if(p(r)){let o=g(e.content.files).map(a=>h(r[a])?[a,x(n,r[a])]:[a,n]);return e.content.transform=Object.fromEntries(o),e}return e};
13
+ `;return n.concat(c+i+m)}catch(e){return V("Tailwind Variants Transform Failed",e),n}},v=n=>{let r=n.map(t=>{if(d(t)&&t.extension)return t.extension;let e=t.match(p.extension);return e||(e=t.split("{"),e=e.pop().replace("}","").split(",")),e.map(s=>s.replace(".","").split(".")).flat()}).flatMap(t=>t);return Array.from(new Set(r)).filter(t=>t!=="html")},D=(n,r)=>{var a$1;let t=w(n);if(a(t.theme),f((a$1=t.content)==null?void 0:a$1.files)||!l(t.content.files))return t;let e=o=>{var i,c;return P(o,Object.keys((c=(i=t.theme)==null?void 0:i.screens)!=null?c:{}),r)},s=t.content.transform;if(f(s)){let i=v(t.content.files).map(c=>[c,e]);return t.content.transform=Object.fromEntries(i),t}if(g(s)){let i=v(t.content.files).map(c=>[c,x(e,s)]);return t.content.transform=Object.fromEntries(i),t}if(d(s)){let i=v(t.content.files).map(c=>g(s[c])?[c,x(e,s[c])]:[c,e]);return t.content.transform=Object.fromEntries(i),t}return t};
14
14
 
15
- export { B as tvTransformer, N as withTV };
15
+ export { P as tvTransformer, D as withTV };
package/dist/utils.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var l=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,u=e=>!e||typeof e!="object"||Object.keys(e).length===0,x=(e,o)=>JSON.stringify(e)===JSON.stringify(o),A=e=>typeof e=="boolean";function i(e,o){e.forEach(function(r){Array.isArray(r)?i(r,o):o.push(r);});}function y(e){let o=[];return i(e,o),o}var a=(...e)=>y(e).filter(Boolean),p=(e,o)=>{let r={},c=Object.keys(e),f=Object.keys(o);for(let t of c)if(f.includes(t)){let s=e[t],n=o[t];typeof s=="object"&&typeof n=="object"?r[t]=p(s,n):Array.isArray(s)||Array.isArray(n)?r[t]=a(n,s):r[t]=n+" "+s;}else r[t]=e[t];for(let t of f)c.includes(t)||(r[t]=o[t]);return r},g=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();
3
+ var l=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,u=e=>!e||typeof e!="object"||Object.keys(e).length===0,x=(e,o)=>JSON.stringify(e)===JSON.stringify(o),A=e=>typeof e=="boolean";function i(e,o){e.forEach(function(r){Array.isArray(r)?i(r,o):o.push(r);});}function y(e){let o=[];return i(e,o),o}var a=(...e)=>y(e).filter(Boolean),p=(e,o)=>{let r={},c=Object.keys(e),f=Object.keys(o);for(let t of c)if(f.includes(t)){let s=e[t],n=o[t];Array.isArray(s)||Array.isArray(n)?r[t]=a(n,s):typeof s=="object"&&typeof n=="object"?r[t]=p(s,n):r[t]=n+" "+s;}else r[t]=e[t];for(let t of f)c.includes(t)||(r[t]=o[t]);return r},g=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();
4
4
 
5
5
  exports.falsyToString = l;
6
6
  exports.flatArray = y;
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- export { a as falsyToString, e as flatArray, f as flatMergeArrays, d as isBoolean, b as isEmptyObject, c as isEqual, g as mergeObjects, h as removeExtraSpaces } from './chunk-JXBJZR5A.js';
1
+ export { a as falsyToString, e as flatArray, f as flatMergeArrays, d as isBoolean, b as isEmptyObject, c as isEqual, g as mergeObjects, h as removeExtraSpaces } from './chunk-I2QGXAA3.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-variants",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "🦄 Tailwindcss first-class variant API",
5
5
  "author": "Junior Garcia <jrgarciadev@gmail.com>",
6
6
  "license": "MIT",
@@ -31,12 +31,13 @@
31
31
  "prepack": "clean-package",
32
32
  "benchmark": "node benchmark.js",
33
33
  "postpack": "clean-package restore",
34
- "lint": "eslint -c .eslintrc.json ./src/**/*.{ts,tsx}",
35
- "lint:fix": "eslint --fix -c .eslintrc.json ./src/**/*.{ts,tsx}",
36
- "test": "jest --verbose"
34
+ "lint": "eslint . src/**/*.{js,ts}",
35
+ "lint:fix": "eslint --fix . src/**/*.{js,ts}",
36
+ "test": "jest --verbose",
37
+ "test:watch": "jest --watch --no-verbose"
37
38
  },
38
39
  "dependencies": {
39
- "tailwind-merge": "^2.2.0"
40
+ "tailwind-merge": "^2.5.4"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@commitlint/cli": "^17.2.0",
@@ -48,31 +49,29 @@
48
49
  "@swc/helpers": "^0.4.14",
49
50
  "@types/jest": "28.1.1",
50
51
  "@types/node": "^18.11.18",
51
- "@typescript-eslint/eslint-plugin": "^5.42.0",
52
- "@typescript-eslint/parser": "^5.42.0",
52
+ "@typescript-eslint/eslint-plugin": "^7.3.1",
53
+ "@typescript-eslint/parser": "^7.3.1",
53
54
  "benchmark": "2.1.4",
55
+ "class-variance-authority": "^0.7.0",
54
56
  "clean-package": "2.1.1",
55
- "eslint": "^7.29.0",
56
- "eslint-config-prettier": "^8.2.0",
57
+ "eslint": "^8.57.0",
58
+ "eslint-config-prettier": "^9.1.0",
57
59
  "eslint-config-ts-lambdas": "^1.2.3",
58
- "eslint-import-resolver-typescript": "^2.4.0",
59
- "eslint-loader": "^4.0.2",
60
- "eslint-plugin-import": "^2.26.0",
61
- "eslint-plugin-jest": "^24.3.6",
60
+ "eslint-import-resolver-typescript": "^3.6.1",
61
+ "eslint-plugin-import": "^2.29.1",
62
+ "eslint-plugin-jest": "^27.9.0",
62
63
  "eslint-plugin-node": "^11.1.0",
63
- "eslint-plugin-prettier": "^4.0.0",
64
- "eslint-plugin-promise": "^6.0.0",
64
+ "eslint-plugin-prettier": "^5.1.3",
65
+ "eslint-plugin-promise": "^6.1.1",
65
66
  "expect": "^29.7.0",
66
67
  "jest": "28.1.1",
67
- "prettier": "^2.2.1",
68
- "prettier-eslint": "^12.0.0",
69
- "prettier-eslint-cli": "^5.0.1",
68
+ "prettier": "^3.2.5",
69
+ "prettier-eslint": "^16.3.0",
70
+ "prettier-eslint-cli": "^8.0.1",
70
71
  "tailwindcss": "^3.2.7",
71
72
  "ts-node": "^10.9.1",
72
- "tslib": "^2.4.1",
73
73
  "tsup": "6.6.3",
74
- "typescript": "5.1.3",
75
- "webpack": "^5.53.0"
74
+ "typescript": "5.1.3"
76
75
  },
77
76
  "peerDependencies": {
78
77
  "tailwindcss": "*"
@@ -94,7 +93,7 @@
94
93
  ".": {
95
94
  "require": "./dist/index.cjs",
96
95
  "import": "./dist/index.js",
97
- "types": "./types/index.d.ts"
96
+ "types": "./dist/index.d.ts"
98
97
  },
99
98
  "./dist/*": "./dist/*",
100
99
  "./transformer": {