tailwind-variants 0.0.30 → 0.1.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
@@ -101,7 +101,7 @@ module.exports = withTV({
101
101
  ## Acknowledgements
102
102
 
103
103
  - [**cva**](https://github.com/joe-bell/cva) ([Joe Bell](https://github.com/joe-bell))
104
- 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 if don't need any of the **Tailwind Variants** features listed [here](https://www.tailwind-variants.org/docs/comparison).
104
+ 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).
105
105
 
106
106
  - [**Stitches**](https://stitches.dev/) ([Modulz](https://modulz.app))
107
107
  The pioneers of the `variants` API movement. Inmense thanks to [Modulz](https://modulz.app) for their work on Stitches and the community around it. 🙏
@@ -0,0 +1,3 @@
1
+ var s=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,f=e=>!e||typeof e!="object"||Object.keys(e).length===0,c=(...e)=>[...e].flat().filter(Boolean),p=(e,r)=>{let n={};for(let t in e)r!=null&&r.hasOwnProperty(t)?n[t]=typeof e[t]=="object"?p(e[t],r[t]):r[t]+" "+e[t]:n[t]=e[t];for(let t in r)n.hasOwnProperty(t)||(n[t]=r[t]);return n},o=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();
2
+
3
+ export { s as a, f as b, c, p as d, o as e };
package/dist/config.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type {Config as TwMergeConfig} from "tailwind-merge";
2
+ import type {TVVariants} from "./index";
3
+ import type {TVGeneratedScreens} from "./generated";
2
4
 
3
- export type TVConfig = {
5
+ export type TVConfig<V extends TVVariants<S>, EV extends TVVariants> = {
4
6
  /**
5
7
  * Whether to merge the class names with `tailwind-merge` library.
6
8
  * It's avoid to have duplicate tailwind classes. (Recommended)
@@ -13,4 +15,13 @@ export type TVConfig = {
13
15
  * @see https://github.com/dcastil/tailwind-merge/blob/v1.8.1/docs/configuration.md
14
16
  */
15
17
  twMergeConfig?: TwMergeConfig;
18
+ /**
19
+ * Whether to enable responsive variant transform.
20
+ * Which variants or screens(breakpoints) for responsive variant transform.
21
+ * @default false
22
+ */
23
+ responsiveVariants?:
24
+ | boolean
25
+ | TVGeneratedScreens[]
26
+ | {[K in keyof V | keyof EV]?: boolean | TVGeneratedScreens[]};
16
27
  };
@@ -3,7 +3,12 @@
3
3
  var n = require('fs');
4
4
  var s = require('path');
5
5
 
6
- var t=e=>{n.writeFileSync(s.join(__dirname,"generated.d.ts"),e);},c=e=>`export type TVGeneratedScreens = ${Object.keys(e).map(r=>`"${r}"`).join(" | ")};
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var n__default = /*#__PURE__*/_interopDefault(n);
9
+ var s__default = /*#__PURE__*/_interopDefault(s);
10
+
11
+ var t=e=>{n__default.default.writeFileSync(s__default.default.join(__dirname,"generated.d.ts"),e);},c=e=>`export type TVGeneratedScreens = ${Object.keys(e).map(r=>`"${r}"`).join(" | ")};
7
12
  `,p=e=>{queueMicrotask(()=>{if(e!=null&&e.screens){let r=c(e.screens);t(r);}});};
8
13
 
9
14
  exports.generateTypes = p;
package/dist/index.cjs CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  var tailwindMerge = require('tailwind-merge');
4
4
 
5
- var h=(...e)=>e.flat(1/0).filter(Boolean).join(" "),V=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,g=e=>!e||typeof e!="object"||Object.keys(e).length===0,H=(...e)=>[...e].flat().filter(Boolean),M=(...e)=>(l={})=>l.twMerge?(g(l.twMergeConfig)?tailwindMerge.twMerge:tailwindMerge.extendTailwindMerge(l.twMergeConfig))(h(e)):h(e),B=(e,l)=>{let y={};return typeof e!="object"||typeof l!="object"||Object.keys(e).forEach(c=>{l[c]?y[c]=h([e[c],l[c]]):y[c]=e[c];}),y},E=(e,l)=>{let y={};for(let c in e)l!=null&&l.hasOwnProperty(c)?y[c]=typeof e[c]=="object"?E(e[c],l[c]):l[c]+" "+e[c]:y[c]=e[c];for(let c in l)y.hasOwnProperty(c)||(y[c]=l[c]);return y},S=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();var re=(e,l={twMerge:!0,twMergeConfig:{}})=>{var N,T,v,F,k;let{slots:y={},variants:c={},compoundVariants:b=[],defaultVariants:J={}}=e,A=h((N=e==null?void 0:e.extend)==null?void 0:N.base,e==null?void 0:e.base),i=E(c,(T=e==null?void 0:e.extend)==null?void 0:T.variants),j=Object.assign({},(v=e==null?void 0:e.extend)==null?void 0:v.defaultVariants,J),C=g(y)?{}:{base:e==null?void 0:e.base,...y},w=g((F=e==null?void 0:e.extend)==null?void 0:F.slots)?C:B((k=e==null?void 0:e.extend)==null?void 0:k.slots,g(C)?{base:e==null?void 0:e.base}:C),x=u=>{var W,q,z;if(g(i)&&g(y)&&g((W=e==null?void 0:e.extend)==null?void 0:W.slots))return M(A,u==null?void 0:u.class,u==null?void 0:u.className)(l);if(b&&!Array.isArray(b))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof b}`);let P=(t,r,a=[],n)=>{let f=a;if(typeof r=="string")f.push(S(r).split(" ").map(s=>`${t}:${s}`));else if(Array.isArray(r))f.push(r.flatMap(s=>`${t}:${s}`));else if(typeof r=="object"&&typeof n=="string"){let s=r==null?void 0:r[n];if(s&&typeof s=="string"){let m=S(s);f[n]=f[n]?[...f[n],...m.split(" ").map(d=>`${t}:${d}`)]:m.split(" ").map(d=>`${t}:${d}`);}else Array.isArray(s)&&s.length>0&&(f[n]=s.flatMap(m=>`${t}:${m}`));}return f},I=(t,r=i,a=null)=>{let n=r==null?void 0:r[t];if(typeof n!="object"||g(n))return null;let f=u==null?void 0:u[t],s=j==null?void 0:j[t],m=[];if(f===null)return null;let d=V(f);typeof d=="object"&&(m=Object.keys(d).reduce((D,$)=>{let G=d[$],_=n==null?void 0:n[G];return $==="initial"?(s=G,D):P($,_,D,a)},[]));let O=n[d]||n[V(s)];return typeof m=="object"&&typeof a=="string"&&m[a]?B(m,O):m.length>0?[O,...m]:O},Q=()=>i?Object.keys(i).map(t=>I(t,i)):null,X=t=>!i||typeof i!="object"?null:Object.keys(i).map(r=>{let a=I(r,i,t);return t==="base"&&typeof a=="string"?a:a&&a[t]}).filter(Boolean),Y=u&&Object.fromEntries(Object.entries(u).filter(([,t])=>t!==void 0)),R=(t=[])=>t==null?void 0:t.filter(({class:r,className:a,...n})=>Object.entries(n).every(([f,s])=>{var O;let m=typeof(u==null?void 0:u[f])=="object"?(O=u[f])==null?void 0:O.initial:{},d={...j,...m,...Y};return Array.isArray(s)?s.includes(d[f]):d[f]===s})).flatMap(({class:r,className:a})=>[r,a]),U=()=>{var a;let t=R(b),r=R((a=e==null?void 0:e.extend)==null?void 0:a.compoundVariants);return H(r,t)},Z=()=>{let t=U();return Array.isArray(t)?t.reduce((r,a)=>(typeof a=="string"&&(r.base=M(r.base,a)(l)),typeof a=="object"&&Object.entries(a).forEach(([n,f])=>{r[n]=M(r[n],f)(l);}),r),{}):t};if(!g(y)||!g((q=e==null?void 0:e.extend)==null?void 0:q.slots)){let t=(z=Z())!=null?z:[];return {...typeof w=="object"&&!g(w)?Object.keys(w).reduce((a,n)=>(a[n]=f=>M(w[n],X(n),t==null?void 0:t[n],f==null?void 0:f.class,f==null?void 0:f.className)(l),a),{}):{}}}return M(A,Q(),U(),u==null?void 0:u.class,u==null?void 0:u.className)(l)},L=()=>{if(!(!i||typeof i!="object"))return Object.keys(i)};return x.variantKeys=L(),x.base=A,x.slots=w,x.variants=i,x.defaultVariants=j,x.compoundVariants=b,x};
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={})=>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},ne={twMerge:!0,twMergeConfig:{},responsiveVariants:!1},ue=(e,s=ne)=>{var k,N,T,P,F;let{slots:y={},variants:u={},compoundVariants:x=[],compoundSlots:O=[],defaultVariants:Q={}}=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,Q),$=d(y)?{}:{base:e==null?void 0:e.base,...y},X=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 Z=(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"&&X&&(i=Object.keys(g).reduce((v,C)=>{let H=g[C],te=l==null?void 0:l[H];return C==="initial"?(a=H,v):Array.isArray(s.responsiveVariants)&&!s.responsiveVariants.includes(C)?v:Z(C,te,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},_=()=>m?Object.keys(m).map(t=>R(t,m)):null,o=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),K=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,...K,...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)},p=()=>{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},ee=()=>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=p())!=null?D:[],r=(G=ee())!=null?G:[];return {...typeof A=="object"&&!d(A)?Object.keys(A).reduce((l,f)=>(l[f]=a=>w(A[f],o(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,_(),W(),c==null?void 0:c.class,c==null?void 0:c.className)(s)},Y=()=>{if(!(!m||typeof m!="object"))return Object.keys(m)};return b.variantKeys=Y(),b.base=j,b.slots=A,b.variants=m,b.defaultVariants=h,b.compoundSlots=O,b.compoundVariants=x,b};
6
6
 
7
- exports.tv = re;
7
+ exports.cx = w;
8
+ exports.cxBase = M;
9
+ exports.defaultConfig = ne;
10
+ exports.tv = ue;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,21 @@
1
1
  import {TVConfig} from "./config";
2
2
  import {TVGeneratedScreens} from "./generated";
3
- import {ClassValue, ClassProp, OmitUndefined, StringToBoolean} from "./utils";
3
+
4
+ /**
5
+ * ----------------------------------------
6
+ * Base Types
7
+ * ----------------------------------------
8
+ */
9
+
10
+ export type ClassValue = string | string[] | null | undefined | ClassValue[];
11
+
12
+ export type ClassProp<V extends unknown = ClassValue> =
13
+ | {
14
+ class: V;
15
+ className?: never;
16
+ }
17
+ | {class?: never; className: V}
18
+ | {class?: never; className?: never};
4
19
 
5
20
  type TVBaseName = "base";
6
21
 
@@ -8,6 +23,37 @@ type TVScreens = "initial" | TVGeneratedScreens;
8
23
 
9
24
  type TVSlots = Record<string, ClassValue> | undefined;
10
25
 
26
+ /**
27
+ * ----------------------------------------------------------------------
28
+ * Utils
29
+ * ----------------------------------------------------------------------
30
+ */
31
+
32
+ export type OmitUndefined<T> = T extends undefined ? never : T;
33
+
34
+ export type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
35
+
36
+ export type CxOptions = ClassValue[];
37
+
38
+ export type CxReturn = string;
39
+
40
+ export declare const cxBase: <T extends CxOptions>(...classes: T) => CxReturn;
41
+
42
+ export declare const cx: <T extends CxOptions>(...classes: T) => (config: TVConfig) => CxReturn;
43
+
44
+ // compare if the value is true or array of values
45
+ export type isTrueOrArray<T> = T extends true | (infer U)[] ? true : false;
46
+
47
+ export type isStringArray<T> = T extends Array<string> ? true : false;
48
+
49
+ export type WithInitialScreen<T extends Array<string>> = ["initial", ...T];
50
+
51
+ /**
52
+ * ----------------------------------------------------------------------
53
+ * TV Types
54
+ * ----------------------------------------------------------------------
55
+ */
56
+
11
57
  type TVSlotsWithBase<S extends TVSlots, B extends ClassValue> = B extends undefined
12
58
  ? keyof S
13
59
  : keyof S | TVBaseName;
@@ -52,32 +98,61 @@ export type TVCompoundVariants<
52
98
  } & ClassProp<SlotsClassValue<S, B> | ClassValue>
53
99
  >;
54
100
 
101
+ export type TVCompoundSlots<
102
+ V extends TVVariants<S>,
103
+ S extends TVSlots,
104
+ B extends ClassValue,
105
+ > = Array<
106
+ V extends undefined
107
+ ? {
108
+ slots: Array<TVSlotsWithBase<S, B>>;
109
+ } & ClassProp
110
+ : {
111
+ slots: Array<TVSlotsWithBase<S, B>>;
112
+ } & {
113
+ [K in keyof V]?: StringToBoolean<keyof V[K]> | StringToBoolean<keyof V[K]>[];
114
+ } & ClassProp
115
+ >;
116
+
55
117
  export type TVDefaultVariants<V extends TVVariants<S>, EV extends TVVariants, S extends TVSlots> = {
56
118
  [K in keyof V | keyof EV]?: StringToBoolean<keyof V[K] | keyof EV[K]>;
57
119
  };
58
120
 
59
- export type TVScreenPropsValue<V extends TVVariants, K extends keyof V> = {
60
- [Screen in TVScreens]?: StringToBoolean<keyof V[K]>;
61
- };
121
+ export type TVScreenPropsValue<
122
+ V extends TVVariants,
123
+ K extends keyof V,
124
+ C extends TVConfig,
125
+ > = isStringArray<C["responsiveVariants"]> extends true
126
+ ? {
127
+ [Screen in WithInitialScreen<C["responsiveVariants"]>[number]]?: StringToBoolean<keyof V[K]>;
128
+ }
129
+ : {
130
+ [Screen in TVScreens]?: StringToBoolean<keyof V[K]>;
131
+ };
62
132
 
63
133
  export type TVProps<
64
134
  V extends TVVariants<S>,
65
135
  EV extends TVVariants,
66
136
  S extends TVSlots,
137
+ C extends TVConfig<V, EV>,
67
138
  > = EV extends undefined
68
139
  ? V extends undefined
69
140
  ? ClassProp<ClassValue>
70
141
  : {
71
- [K in keyof V]?: StringToBoolean<keyof V[K]> | TVScreenPropsValue<V, K>;
142
+ [K in keyof V]?: isTrueOrArray<C["responsiveVariants"]> extends true
143
+ ? StringToBoolean<keyof V[K]> | TVScreenPropsValue<V, K, C>
144
+ : StringToBoolean<keyof V[K]>;
72
145
  } & ClassProp<ClassValue>
73
146
  : V extends undefined
74
147
  ? {
75
- [K in keyof EV]?: StringToBoolean<keyof EV[K]> | TVScreenPropsValue<EV, K>;
148
+ [K in keyof EV]?: isTrueOrArray<C["responsiveVariants"]> extends true
149
+ ? StringToBoolean<keyof EV[K]> | TVScreenPropsValue<EV, K, C>
150
+ : StringToBoolean<keyof EV[K]>;
76
151
  } & ClassProp<ClassValue>
77
152
  : {
78
- [K in keyof V | keyof EV]?:
79
- | StringToBoolean<keyof V[K] | keyof EV[K]>
80
- | TVScreenPropsValue<EV & V, K>;
153
+ [K in keyof V | keyof EV]?: isTrueOrArray<C["responsiveVariants"]> extends true
154
+ ? StringToBoolean<keyof V[K] | keyof EV[K]> | TVScreenPropsValue<EV & V, K, C>
155
+ : StringToBoolean<keyof V[K] | keyof EV[K]>;
81
156
  } & ClassProp<ClassValue>;
82
157
 
83
158
  export type TVVariantKeys<V extends TVVariants<S>, S extends TVSlots> = V extends Object
@@ -90,6 +165,7 @@ export type TVReturnProps<V extends TVVariants<S>, S extends TVSlots, B extends
90
165
  variants: V;
91
166
  defaultVariants: TVDefaultVariants<V, S>;
92
167
  compoundVariants: TVCompoundVariants<V, S, B>;
168
+ compoundSlots: TVCompoundSlots<V, S, B>;
93
169
  variantKeys: TVVariantKeys<V, S>;
94
170
  };
95
171
 
@@ -99,8 +175,9 @@ export type TVReturnType<
99
175
  S extends TVSlots,
100
176
  ES extends TVSlots,
101
177
  B extends ClassValue,
178
+ C extends TVConfig<V, EV>,
102
179
  > = {
103
- (props?: TVProps<V, EV, S>): ES extends undefined
180
+ (props?: TVProps<V, EV, S, C>): ES extends undefined
104
181
  ? S extends undefined
105
182
  ? string
106
183
  : {[K in TVSlotsWithBase<S, B>]: (slotProps?: ClassProp) => string}
@@ -112,7 +189,7 @@ export type TV = {
112
189
  V extends TVVariants<S, B, EV> = undefined,
113
190
  CV extends TVCompoundVariants<V, EV, S, B> = undefined,
114
191
  DV extends TVDefaultVariants<V, EV, S> = undefined,
115
- C extends TVConfig,
192
+ C extends TVConfig<V, EV> = undefined,
116
193
  B extends ClassValue = undefined,
117
194
  S extends TVSlots = undefined,
118
195
  E extends ReturnType<TV> = undefined,
@@ -120,19 +197,53 @@ export type TV = {
120
197
  ES extends TVSlots = E["slots"] extends TVSlots ? E["slots"] : undefined,
121
198
  >(
122
199
  options: {
200
+ /**
201
+ * Extend allows easily compose components.
202
+ * @see https://www.tailwind-variants.org/docs/composing-components
203
+ */
123
204
  extend?: E;
205
+ /**
206
+ * Base allows you to set a base class for a component.
207
+ */
124
208
  base?: B;
209
+ /**
210
+ * Slots allows you to separate an component into multiple parts.
211
+ * @see https://www.tailwind-variants.org/docs/slots
212
+ */
125
213
  slots?: S;
214
+ /**
215
+ * Variants allows you to create multiple versions of the same component.
216
+ * @see https://www.tailwind-variants.org/docs/variants#adding-variants
217
+ */
126
218
  variants?: V;
219
+ /**
220
+ * Compound variants allow apply classes to multiple variants at once.
221
+ * @see https://www.tailwind-variants.org/docs/variants#compound-variants
222
+ */
127
223
  compoundVariants?: CV;
224
+ /**
225
+ * Compound slots allow apply classes to multiple slots at once.
226
+ */
227
+ compoundSlots?: TVCompoundSlots<V, S, B>;
228
+ /**
229
+ * Default variants allow you to set default variants for a component.
230
+ * @see https://www.tailwind-variants.org/docs/variants#default-variants
231
+ */
128
232
  defaultVariants?: DV;
129
233
  },
234
+ /**
235
+ * The config object to modify the default configuration.
236
+ * @see https://www.tailwind-variants.org/docs/api-reference#config-optional
237
+ */
130
238
  config?: C,
131
- ): TVReturnType<V, EV, S, ES, B>;
239
+ ): TVReturnType<V, EV, S, ES, B, C>;
132
240
  };
133
241
 
242
+ // main function
134
243
  export declare const tv: TV;
135
244
 
245
+ export declare const defaultConfig: TVConfig;
246
+
136
247
  export type VariantProps<Component extends (...args: any) => any> = Omit<
137
248
  OmitUndefined<Parameters<Component>[0]>,
138
249
  "class" | "className"
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
- import { a, g, c, f, e, d, b, h } from './chunk-C5RUXROF.js';
1
+ import { b, d, c, a, e } from './chunk-X3I5ASPE.js';
2
+ import { twMerge, extendTailwindMerge } from 'tailwind-merge';
2
3
 
3
- var o=(e$1,i={twMerge:!0,twMergeConfig:{}})=>{var M,S,E,w,B;let{slots:A={},variants:I={},compoundVariants:s=[],defaultVariants:J={}}=e$1,$=a((M=e$1==null?void 0:e$1.extend)==null?void 0:M.base,e$1==null?void 0:e$1.base),l=g(I,(S=e$1==null?void 0:e$1.extend)==null?void 0:S.variants),x=Object.assign({},(E=e$1==null?void 0:e$1.extend)==null?void 0:E.defaultVariants,J),C=c(A)?{}:{base:e$1==null?void 0:e$1.base,...A},O=c((w=e$1==null?void 0:e$1.extend)==null?void 0:w.slots)?C:f((B=e$1==null?void 0:e$1.extend)==null?void 0:B.slots,c(C)?{base:e$1==null?void 0:e$1.base}:C),y=c$1=>{var R,U,W;if(c(l)&&c(A)&&c((R=e$1==null?void 0:e$1.extend)==null?void 0:R.slots))return e($,c$1==null?void 0:c$1.class,c$1==null?void 0:c$1.className)(i);if(s&&!Array.isArray(s))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof s}`);let Q=(t,a,r=[],n)=>{let u=r;if(typeof a=="string")u.push(h(a).split(" ").map(f=>`${t}:${f}`));else if(Array.isArray(a))u.push(a.flatMap(f=>`${t}:${f}`));else if(typeof a=="object"&&typeof n=="string"){let f=a==null?void 0:a[n];if(f&&typeof f=="string"){let b=h(f);u[n]=u[n]?[...u[n],...b.split(" ").map(d=>`${t}:${d}`)]:b.split(" ").map(d=>`${t}:${d}`);}else Array.isArray(f)&&f.length>0&&(u[n]=f.flatMap(b=>`${t}:${b}`));}return u},T=(t,a=l,r=null)=>{let n=a==null?void 0:a[t];if(typeof n!="object"||c(n))return null;let u=c$1==null?void 0:c$1[t],f$1=x==null?void 0:x[t],b$1=[];if(u===null)return null;let d=b(u);typeof d=="object"&&(b$1=Object.keys(d).reduce((q,V)=>{let z=d[V],P=n==null?void 0:n[z];return V==="initial"?(f$1=z,q):Q(V,P,q,r)},[]));let j=n[d]||n[b(f$1)];return typeof b$1=="object"&&typeof r=="string"&&b$1[r]?f(b$1,j):b$1.length>0?[j,...b$1]:j},X=()=>l?Object.keys(l).map(t=>T(t,l)):null,Y=t=>!l||typeof l!="object"?null:Object.keys(l).map(a=>{let r=T(a,l,t);return t==="base"&&typeof r=="string"?r:r&&r[t]}).filter(Boolean),Z=c$1&&Object.fromEntries(Object.entries(c$1).filter(([,t])=>t!==void 0)),k=(t=[])=>t==null?void 0:t.filter(({class:a,className:r,...n})=>Object.entries(n).every(([u,f])=>{var j;let b=typeof(c$1==null?void 0:c$1[u])=="object"?(j=c$1[u])==null?void 0:j.initial:{},d={...x,...b,...Z};return Array.isArray(f)?f.includes(d[u]):d[u]===f})).flatMap(({class:a,className:r})=>[a,r]),F=()=>{var r;let t=k(s),a=k((r=e$1==null?void 0:e$1.extend)==null?void 0:r.compoundVariants);return d(a,t)},_=()=>{let t=F();return Array.isArray(t)?t.reduce((a,r)=>(typeof r=="string"&&(a.base=e(a.base,r)(i)),typeof r=="object"&&Object.entries(r).forEach(([n,u])=>{a[n]=e(a[n],u)(i);}),a),{}):t};if(!c(A)||!c((U=e$1==null?void 0:e$1.extend)==null?void 0:U.slots)){let t=(W=_())!=null?W:[];return {...typeof O=="object"&&!c(O)?Object.keys(O).reduce((r,n)=>(r[n]=u=>e(O[n],Y(n),t==null?void 0:t[n],u==null?void 0:u.class,u==null?void 0:u.className)(i),r),{}):{}}}return e($,X(),F(),c$1==null?void 0:c$1.class,c$1==null?void 0:c$1.className)(i)},L=()=>{if(!(!l||typeof l!="object"))return Object.keys(l)};return y.variantKeys=L(),y.base=$,y.slots=O,y.variants=l,y.defaultVariants=x,y.compoundVariants=s,y};
4
+ var O=(...e)=>e.flat(1/0).filter(Boolean).join(" "),h=(...e)=>(c={})=>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},ne={twMerge:!0,twMergeConfig:{},responsiveVariants:!1},ue=(e$1,c$1=ne)=>{var B,N,T,k,F;let{slots:m={},variants:b$1={},compoundVariants:j=[],compoundSlots:V=[],defaultVariants:Q={}}=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),A=Object.assign({},(T=e$1==null?void 0:e$1.extend)==null?void 0:T.defaultVariants,Q),M=b(m)?{}:{base:e$1==null?void 0:e$1.base,...m},X=Array.isArray(c$1.responsiveVariants)&&c$1.responsiveVariants.length>0||c$1.responsiveVariants===!0,C=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 h(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 Z=(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=A==null?void 0:A[t],f=[];if(l===null)return null;let d=a(l);typeof d=="object"&&X&&(f=Object.keys(d).reduce(($,w)=>{let G=d[w],te=s==null?void 0:s[G];return w==="initial"?(a$1=G,$):Array.isArray(c$1.responsiveVariants)&&!c$1.responsiveVariants.includes(w)?$:Z(w,te,$,n)},[]));let x=s[d]||s[a(a$1)];return typeof f=="object"&&typeof n=="string"&&f[n]?L(f,x):f.length>0?[x,...f]:x},_=()=>i?Object.keys(i).map(t=>R(t,i)):null,K=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),o=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 {...A,...o,...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)},p=()=>{let t=U();return Array.isArray(t)?t.reduce((r,n)=>(typeof n=="string"&&(r.base=h(r.base,n)(c$1)),typeof n=="object"&&Object.entries(n).forEach(([s,l])=>{r[s]=h(r[s],l)(c$1);}),r),{}):t},ee=()=>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 x=I(d)[d];if(!x||x!==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=p())!=null?z:[],r=(D=ee())!=null?D:[];return {...typeof C=="object"&&!b(C)?Object.keys(C).reduce((s,l)=>(s[l]=a=>h(C[l],K(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 h(v,_(),U(),u==null?void 0:u.class,u==null?void 0:u.className)(c$1)},Y=()=>{if(!(!i||typeof i!="object"))return Object.keys(i)};return g.variantKeys=Y(),g.base=v,g.slots=C,g.variants=i,g.defaultVariants=A,g.compoundSlots=V,g.compoundVariants=j,g};
4
5
 
5
- export { o as tv };
6
+ export { h as cx, O as cxBase, ne as defaultConfig, ue as tv };
@@ -1,17 +1,26 @@
1
1
  'use strict';
2
2
 
3
- var w = require('tailwindcss/resolveConfig');
4
- var h = require('fs');
5
- var C = require('path');
3
+ var V = require('tailwindcss/resolveConfig');
4
+ var w = require('fs');
5
+ var O = require('path');
6
6
 
7
- var S=t=>{h.writeFileSync(C.join(__dirname,"generated.d.ts"),t);},j=t=>`export type TVGeneratedScreens = ${Object.keys(t).map(n=>`"${n}"`).join(" | ")};
8
- `,v=t=>{queueMicrotask(()=>{if(t!=null&&t.screens){let n=j(t.screens);S(n);}});};var m={tv:/tv\({[\s\S]*?}\)/g,tvContent:/\({[\s\S]*?}\)/g,comment:/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,blankLine:/^\s*$(?:\r\n?|\n)/gm,extension:/\.\w+/g},l=t=>Array.isArray(t),b=t=>typeof t=="string",u=t=>typeof t=="object",y=t=>typeof t=="function",a=t=>!!(!t||l(t)&&t.length===0||b(t)&&t.length===0||u(t)&&Object.keys(t).length===0),$=(t,n)=>{let e="https://github.com/nextui-org/tailwind-variants/issues/new/choose";console.log("\x1B[31m%s\x1B[0m",`${t}: ${n.message}`),console.log(`If you think this is an issue, please submit it at ${e}`);},x=(...t)=>n=>t.reduce((e,r)=>r(e),n),O=t=>t.replace(m.comment,"$1").toString().replace(m.blankLine,"").toString().match(m.tv),k=t=>{let n=O(t);if(!a(n))return n.map(e=>new Function(`return ${e.match(m.tvContent).toString()}`)())},E=t=>t.flatMap(n=>n).toString().replaceAll(","," ").split(" "),V=(t,n)=>{let e={};for(let[r,s]of Object.entries(t))e[r]={},e[r].original=s,!a(s)&&(e.temp=l(s)?E(s):s.split(" "),n.forEach(c=>{let o="";e.temp.forEach(i=>{o+=`${c}:${i} `;}),e[r][c]=o.trimEnd();}),delete e.temp);return e},A=(t,n)=>b(t)?t.split(" "):l(t)?E(t):u(t)?V(t,n):t,F=(t,n)=>{let{variants:e={}}=t;if(a(e))return;let r={};for(let[s,c]of Object.entries(e))if(r[s]={},!a(c))for(let[o,i]of Object.entries(c)){if(r[s][o]={},r[s][o].original=i,a(i))continue;let f=A(i,n);if(!a(f)){if(!l(f)){r[s][o]=f;continue}n.forEach(g=>{let d="";f.forEach(T=>{d+=`${g}:${T} `;}),r[s][o][g]=d.trimEnd();});}}return r},L=(t,n)=>{try{if(!t.includes("tailwind-variants"))return t;let e=k(t);if(a(e))return t;let r=JSON.stringify(e.map(o=>F(o,n)),void 0,2),s=`
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var V__default = /*#__PURE__*/_interopDefault(V);
10
+ var w__default = /*#__PURE__*/_interopDefault(w);
11
+ var O__default = /*#__PURE__*/_interopDefault(O);
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(n=>`"${n}"`).join(" | ")};
14
+ `,v=t=>{queueMicrotask(()=>{if(t!=null&&t.screens){let n=C(t.screens);S(n);}});};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,n)=>{let e={},r=n.length,s=Object.prototype.hasOwnProperty;for(let i=0;i<r;i++){let o=n[i];s.call(t,o)&&(e[o]=t[o]);}return e},A=(t,n)=>{let e="https://github.com/nextui-org/tailwind-variants/issues/new/choose";console.log("\x1B[31m%s\x1B[0m",`${t}: ${n.message}`),console.log(`If you think this is an issue, please submit it at ${e}`);},x=(...t)=>n=>t.reduce((e,r)=>r(e),n),F=t=>{let e=t.replace(u.comment,"$1").toString().replace(u.blankLine,"").toString(),r=s=>s[1].replace(u.tvExtend,"").toString();return Array.from(e.matchAll(u.tv),r)},B=t=>{let n=F(t);if(!c(n))return n.map(e=>new Function(`
15
+ const [options, config] = [${e.toString()}];
16
+ return {options, config};
17
+ `)())},h=t=>t.flatMap(n=>n).toString().replaceAll(","," ").split(" "),D=(t,n)=>{let e={};for(let[r,s]of Object.entries(t))e[r]={},e[r].original=s,!c(s)&&(e.temp=l(s)?h(s):s.split(" "),n.forEach(i=>{let o="";e.temp.forEach(a=>{o+=`${i}:${a} `;}),e[r][i]=o.trimEnd();}),delete e.temp);return e},L=(t,n)=>E(t)?t.split(" "):l(t)?h(t):p(t)?D(t,n):t,b=(t,n)=>{let e={};for(let[r,s]of Object.entries(t))if(e[r]={},!c(s))for(let[i,o]of Object.entries(s)){if(e[r][i]={},e[r][i].original=o,c(o))continue;let a=L(o,n);if(!c(a)){if(!l(a)){e[r][i]=a;continue}n.forEach(m=>{let f="";a.forEach(d=>{f+=`${m}:${d} `;}),e[r][i][m]=f.trimEnd();});}}return e},T=({options:t,config:n},e)=>{var i,o;let r=(i=t==null?void 0:t.variants)!=null?i:{},s=(o=n==null?void 0:n.responsiveVariants)!=null?o:!1;if(!(!s||c(r))){if($(s))return b(r,e);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,e));}return a}}},N=(t,n)=>{try{if(!t.includes("tailwind-variants"))return t;let e=B(t);if(c(e))return t;let r=JSON.stringify(e.map(o=>T(o,n)),void 0,2),s=`
9
18
  /* Tailwind Variants Transformed Content Start
10
19
 
11
- `,c=`
20
+ `,i=`
12
21
 
13
22
  Tailwind Variants Transformed Content End */
14
- `;return t.concat(s+r+c)}catch(e){return $("Tailwind Variants Transform Failed",e),t}},p=t=>{let n=t.map(e=>{if(u(e)&&e.extension)return e.extension;let r=e.match(m.extension);return r||(r=e.split("{"),r=r.pop().replace("}","").split(",")),r.map(s=>s.replace(".","").split(".")).flat()}).flatMap(e=>e);return Array.from(new Set(n)).filter(e=>e!=="html")},q=t=>{var s;let n=w(t);if(v(n.theme),a((s=n.content)==null?void 0:s.files)||!l(n.content.files))return n;let e=c=>{var o,i;return L(c,Object.keys((i=(o=n.theme)==null?void 0:o.screens)!=null?i:{}))},r=n.content.transform;if(a(r)){let o=p(n.content.files).map(i=>[i,e]);return n.content.transform=Object.fromEntries(o),n}if(y(r)){let o=p(n.content.files).map(i=>[i,x(e,r)]);return n.content.transform=Object.fromEntries(o),n}if(u(r)){let o=p(n.content.files).map(i=>y(r[i])?[i,x(e,r[i])]:[i,e]);return n.content.transform=Object.fromEntries(o),n}return n};
23
+ `;return t.concat(s+r+i)}catch(e){return A("Tailwind Variants Transform Failed",e),t}},g=t=>{let n=t.map(e=>{if(p(e)&&e.extension)return e.extension;let r=e.match(u.extension);return r||(r=e.split("{"),r=r.pop().replace("}","").split(",")),r.map(s=>s.replace(".","").split(".")).flat()}).flatMap(e=>e);return Array.from(new Set(n)).filter(e=>e!=="html")},G=t=>{var s;let n=V__default.default(t);if(v(n.theme),c((s=n.content)==null?void 0:s.files)||!l(n.content.files))return n;let e=i=>{var o,a;return N(i,Object.keys((a=(o=n.theme)==null?void 0:o.screens)!=null?a:{}))},r=n.content.transform;if(c(r)){let o=g(n.content.files).map(a=>[a,e]);return n.content.transform=Object.fromEntries(o),n}if(y(r)){let o=g(n.content.files).map(a=>[a,x(e,r)]);return n.content.transform=Object.fromEntries(o),n}if(p(r)){let o=g(n.content.files).map(a=>y(r[a])?[a,x(e,r[a])]:[a,e]);return n.content.transform=Object.fromEntries(o),n}return n};
15
24
 
16
- exports.tvTransformer = L;
17
- exports.withTV = q;
25
+ exports.tvTransformer = N;
26
+ exports.withTV = G;
@@ -1,12 +1,15 @@
1
1
  import { a } from './chunk-FUBUDMV2.js';
2
- import y from 'tailwindcss/resolveConfig';
2
+ import w from 'tailwindcss/resolveConfig';
3
3
 
4
- var m={tv:/tv\({[\s\S]*?}\)/g,tvContent:/\({[\s\S]*?}\)/g,comment:/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$/gm,blankLine:/^\s*$(?:\r\n?|\n)/gm,extension:/\.\w+/g},l=t=>Array.isArray(t),E=t=>typeof t=="string",u=t=>typeof t=="object",h=t=>typeof t=="function",c=t=>!!(!t||l(t)&&t.length===0||E(t)&&t.length===0||u(t)&&Object.keys(t).length===0),T=(t,n)=>{let e="https://github.com/nextui-org/tailwind-variants/issues/new/choose";console.log("\x1B[31m%s\x1B[0m",`${t}: ${n.message}`),console.log(`If you think this is an issue, please submit it at ${e}`);},x=(...t)=>n=>t.reduce((e,r)=>r(e),n),S=t=>t.replace(m.comment,"$1").toString().replace(m.blankLine,"").toString().match(m.tv),j=t=>{let n=S(t);if(!c(n))return n.map(e=>new Function(`return ${e.match(m.tvContent).toString()}`)())},b=t=>t.flatMap(n=>n).toString().replaceAll(","," ").split(" "),w=(t,n)=>{let e={};for(let[r,o]of Object.entries(t))e[r]={},e[r].original=o,!c(o)&&(e.temp=l(o)?b(o):o.split(" "),n.forEach(a=>{let s="";e.temp.forEach(i=>{s+=`${a}:${i} `;}),e[r][a]=s.trimEnd();}),delete e.temp);return e},O=(t,n)=>E(t)?t.split(" "):l(t)?b(t):u(t)?w(t,n):t,$=(t,n)=>{let{variants:e={}}=t;if(c(e))return;let r={};for(let[o,a]of Object.entries(e))if(r[o]={},!c(a))for(let[s,i]of Object.entries(a)){if(r[o][s]={},r[o][s].original=i,c(i))continue;let f=O(i,n);if(!c(f)){if(!l(f)){r[o][s]=f;continue}n.forEach(g=>{let v="";f.forEach(C=>{v+=`${g}:${C} `;}),r[o][s][g]=v.trimEnd();});}}return r},k=(t,n)=>{try{if(!t.includes("tailwind-variants"))return t;let e=j(t);if(c(e))return t;let r=JSON.stringify(e.map(s=>$(s,n)),void 0,2),o=`
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},S=(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),V=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=V(t);if(!c(e))return e.map(n=>new Function(`
5
+ const [options, config] = [${n.toString()}];
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=`
5
8
  /* Tailwind Variants Transformed Content Start
6
9
 
7
- `,a=`
10
+ `,i=`
8
11
 
9
12
  Tailwind Variants Transformed Content End */
10
- `;return t.concat(o+r+a)}catch(e){return T("Tailwind Variants Transform Failed",e),t}},p=t=>{let n=t.map(e=>{if(u(e)&&e.extension)return e.extension;let r=e.match(m.extension);return r||(r=e.split("{"),r=r.pop().replace("}","").split(",")),r.map(o=>o.replace(".","").split(".")).flat()}).flatMap(e=>e);return Array.from(new Set(n)).filter(e=>e!=="html")},L=t=>{var o;let n=y(t);if(a(n.theme),c((o=n.content)==null?void 0:o.files)||!l(n.content.files))return n;let e=a=>{var s,i;return k(a,Object.keys((i=(s=n.theme)==null?void 0:s.screens)!=null?i:{}))},r=n.content.transform;if(c(r)){let s=p(n.content.files).map(i=>[i,e]);return n.content.transform=Object.fromEntries(s),n}if(h(r)){let s=p(n.content.files).map(i=>[i,x(e,r)]);return n.content.transform=Object.fromEntries(s),n}if(u(r)){let s=p(n.content.files).map(i=>h(r[i])?[i,x(e,r[i])]:[i,e]);return n.content.transform=Object.fromEntries(s),n}return n};
13
+ `;return t.concat(s+r+i)}catch(n){return S("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};
11
14
 
12
- export { k as tvTransformer, L as withTV };
15
+ export { B as tvTransformer, N as withTV };
package/dist/utils.cjs CHANGED
@@ -1,14 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var tailwindMerge = require('tailwind-merge');
3
+ var s=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,f=e=>!e||typeof e!="object"||Object.keys(e).length===0,c=(...e)=>[...e].flat().filter(Boolean),p=(e,r)=>{let n={};for(let t in e)r!=null&&r.hasOwnProperty(t)?n[t]=typeof e[t]=="object"?p(e[t],r[t]):r[t]+" "+e[t]:n[t]=e[t];for(let t in r)n.hasOwnProperty(t)||(n[t]=r[t]);return n},o=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();
4
4
 
5
- var o=(...e)=>e.flat(1/0).filter(Boolean).join(" "),l=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,c=e=>!e||typeof e!="object"||Object.keys(e).length===0,a=(...e)=>[...e].flat().filter(Boolean),g=(...e)=>(r={})=>r.twMerge?(c(r.twMergeConfig)?tailwindMerge.twMerge:tailwindMerge.extendTailwindMerge(r.twMergeConfig))(o(e)):o(e),x=(e,r)=>{let n={};return typeof e!="object"||typeof r!="object"||Object.keys(e).forEach(t=>{r[t]?n[t]=o([e[t],r[t]]):n[t]=e[t];}),n},i=(e,r)=>{let n={};for(let t in e)r!=null&&r.hasOwnProperty(t)?n[t]=typeof e[t]=="object"?i(e[t],r[t]):r[t]+" "+e[t]:n[t]=e[t];for(let t in r)n.hasOwnProperty(t)||(n[t]=r[t]);return n},y=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();
6
-
7
- exports.cx = g;
8
- exports.cxBase = o;
9
- exports.falsyToString = l;
10
- exports.flatMergeArrays = a;
11
- exports.isEmptyObject = c;
12
- exports.joinObjects = x;
13
- exports.mergeObjects = i;
14
- exports.removeExtraSpaces = y;
5
+ exports.falsyToString = s;
6
+ exports.flatMergeArrays = c;
7
+ exports.isEmptyObject = f;
8
+ exports.mergeObjects = p;
9
+ exports.removeExtraSpaces = o;
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- export { e as cx, a as cxBase, b as falsyToString, d as flatMergeArrays, c as isEmptyObject, f as joinObjects, g as mergeObjects, h as removeExtraSpaces } from './chunk-C5RUXROF.js';
1
+ export { a as falsyToString, c as flatMergeArrays, b as isEmptyObject, d as mergeObjects, e as removeExtraSpaces } from './chunk-X3I5ASPE.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-variants",
3
- "version": "0.0.30",
3
+ "version": "0.1.0",
4
4
  "description": "🦄 Tailwindcss first-class variant API",
5
5
  "author": "Junior Garcia <jrgarciadev@gmail.com>",
6
6
  "license": "MIT",
@@ -22,8 +22,6 @@
22
22
  "dist",
23
23
  "transformer.js",
24
24
  "transformer.d.ts",
25
- "utils.js",
26
- "utils.d.ts",
27
25
  "README.md",
28
26
  "LICENSE"
29
27
  ],
@@ -37,7 +35,7 @@
37
35
  "test": "jest --verbose"
38
36
  },
39
37
  "dependencies": {
40
- "tailwind-merge": "^1.8.1"
38
+ "tailwind-merge": "^1.10.0"
41
39
  },
42
40
  "devDependencies": {
43
41
  "@commitlint/cli": "^17.2.0",
@@ -65,11 +63,11 @@
65
63
  "prettier": "^2.2.1",
66
64
  "prettier-eslint": "^12.0.0",
67
65
  "prettier-eslint-cli": "^5.0.1",
68
- "tailwindcss": "^3.2.4",
66
+ "tailwindcss": "^3.2.7",
69
67
  "ts-node": "^10.9.1",
70
68
  "tslib": "^2.4.1",
71
- "tsup": "6.4.0",
72
- "typescript": "4.6.2",
69
+ "tsup": "6.6.3",
70
+ "typescript": "4.9.5",
73
71
  "webpack": "^5.53.0"
74
72
  },
75
73
  "peerDependencies": {
@@ -1,5 +0,0 @@
1
- import { twMerge, extendTailwindMerge } from 'tailwind-merge';
2
-
3
- var o=(...e)=>e.flat(1/0).filter(Boolean).join(" "),l=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,c=e=>!e||typeof e!="object"||Object.keys(e).length===0,a=(...e)=>[...e].flat().filter(Boolean),g=(...e)=>(r={})=>r.twMerge?(c(r.twMergeConfig)?twMerge:extendTailwindMerge(r.twMergeConfig))(o(e)):o(e),x=(e,r)=>{let n={};return typeof e!="object"||typeof r!="object"||Object.keys(e).forEach(t=>{r[t]?n[t]=o([e[t],r[t]]):n[t]=e[t];}),n},i=(e,r)=>{let n={};for(let t in e)r!=null&&r.hasOwnProperty(t)?n[t]=typeof e[t]=="object"?i(e[t],r[t]):r[t]+" "+e[t]:n[t]=e[t];for(let t in r)n.hasOwnProperty(t)||(n[t]=r[t]);return n},y=e=>!e||typeof e!="string"?e:e.replace(/\s+/g," ").trim();
4
-
5
- export { o as a, l as b, c, a as d, g as e, x as f, i as g, y as h };
package/dist/utils.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import {TVConfig} from "./config";
2
-
3
- export declare type ClassValue = string | string[] | null | undefined | ClassValue[];
4
-
5
- export declare type ClassProp<V extends unknown = ClassValue> =
6
- | {
7
- class: V;
8
- className?: never;
9
- }
10
- | {class?: never; className: V}
11
- | {class?: never; className?: never};
12
-
13
- export declare type OmitUndefined<T> = T extends undefined ? never : T;
14
-
15
- export declare type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
16
-
17
- export type CxOptions = ClassValue[];
18
-
19
- export type CxReturn = string;
20
-
21
- export declare const cx: <T extends CxOptions>(...classes: T) => (config: TVConfig) => CxReturn;
22
-
23
- export declare const falsyToString: <T extends unknown>(value: T) => string | T;
24
-
25
- export declare const isEmptyObject: (obj: object) => boolean;
26
-
27
- export declare const joinObjects: (obj1: object, obj2: object) => object;
28
-
29
- export declare const mergeObjects: (obj1: object, obj2: object) => object;
30
-
31
- export declare const removeExtraSpaces: (str: string) => string;
32
-
33
- export declare const flatMergeArrays: <T>(...arrays: T[]) => T;
package/utils.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./dist/utils";
package/utils.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require("./dist/utils");