tailwind-variants 0.0.29 → 0.0.31
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 +1 -1
- package/dist/chunk-X3I5ASPE.js +3 -0
- package/dist/index.cjs +5 -2
- package/dist/index.d.ts +43 -1
- package/dist/index.js +4 -3
- package/dist/utils.cjs +6 -11
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-C5RUXROF.js +0 -5
- package/dist/utils.d.ts +0 -33
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
|
|
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/index.cjs
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var tailwindMerge = require('tailwind-merge');
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var V=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,g=e=>!e||typeof e!="object"||Object.keys(e).length===0,G=(...e)=>[...e].flat().filter(Boolean),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 h=(...e)=>e.flat(1/0).filter(Boolean).join(" "),C=(...e)=>(l={})=>l.twMerge?(g(l.twMergeConfig)?tailwindMerge.twMerge:tailwindMerge.extendTailwindMerge(l.twMergeConfig))(h(e)):h(e),H=(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},p={twMerge:!0,twMergeConfig:{}},ae=(e,l=p)=>{var B,N,T,v,F;let{slots:y={},variants:c={},compoundVariants:x=[],defaultVariants:J={}}=e,j=h((B=e==null?void 0:e.extend)==null?void 0:B.base,e==null?void 0:e.base),i=E(c,(N=e==null?void 0:e.extend)==null?void 0:N.variants),M=Object.assign({},(T=e==null?void 0:e.extend)==null?void 0:T.defaultVariants,J),A=g(y)?{}:{base:e==null?void 0:e.base,...y},w=g((v=e==null?void 0:e.extend)==null?void 0:v.slots)?A:H((F=e==null?void 0:e.extend)==null?void 0:F.slots,g(A)?{base:e==null?void 0:e.base}:A),b=u=>{var U,W,q;if(g(i)&&g(y)&&g((U=e==null?void 0:e.extend)==null?void 0:U.slots))return C(j,u==null?void 0:u.class,u==null?void 0:u.className)(l);if(x&&!Array.isArray(x))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof x}`);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},k=(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=M==null?void 0:M[t],m=[];if(f===null)return null;let d=V(f);typeof d=="object"&&(m=Object.keys(d).reduce((z,$)=>{let D=d[$],_=n==null?void 0:n[D];return $==="initial"?(s=D,z):P($,_,z,a)},[]));let O=n[d]||n[V(s)];return typeof m=="object"&&typeof a=="string"&&m[a]?H(m,O):m.length>0?[O,...m]:O},Q=()=>i?Object.keys(i).map(t=>k(t,i)):null,X=t=>!i||typeof i!="object"?null:Object.keys(i).map(r=>{let a=k(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)),I=(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={...M,...m,...Y};return Array.isArray(s)?s.includes(d[f]):d[f]===s})).flatMap(({class:r,className:a})=>[r,a]),R=()=>{var a;let t=I(x),r=I((a=e==null?void 0:e.extend)==null?void 0:a.compoundVariants);return G(r,t)},Z=()=>{let t=R();return Array.isArray(t)?t.reduce((r,a)=>(typeof a=="string"&&(r.base=C(r.base,a)(l)),typeof a=="object"&&Object.entries(a).forEach(([n,f])=>{r[n]=C(r[n],f)(l);}),r),{}):t};if(!g(y)||!g((W=e==null?void 0:e.extend)==null?void 0:W.slots)){let t=(q=Z())!=null?q:[];return {...typeof w=="object"&&!g(w)?Object.keys(w).reduce((a,n)=>(a[n]=f=>C(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 C(j,Q(),R(),u==null?void 0:u.class,u==null?void 0:u.className)(l)},L=()=>{if(!(!i||typeof i!="object"))return Object.keys(i)};return b.variantKeys=L(),b.base=j,b.slots=w,b.variants=i,b.defaultVariants=M,b.compoundVariants=x,b};
|
|
6
6
|
|
|
7
|
-
exports.
|
|
7
|
+
exports.cx = C;
|
|
8
|
+
exports.cxBase = h;
|
|
9
|
+
exports.defaultConfig = p;
|
|
10
|
+
exports.tv = ae;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import {TVConfig} from "./config";
|
|
2
2
|
import {TVGeneratedScreens} from "./generated";
|
|
3
|
-
|
|
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,30 @@ 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
|
+
/**
|
|
45
|
+
* ----------------------------------------------------------------------
|
|
46
|
+
* TV Types
|
|
47
|
+
* ----------------------------------------------------------------------
|
|
48
|
+
*/
|
|
49
|
+
|
|
11
50
|
type TVSlotsWithBase<S extends TVSlots, B extends ClassValue> = B extends undefined
|
|
12
51
|
? keyof S
|
|
13
52
|
: keyof S | TVBaseName;
|
|
@@ -131,8 +170,11 @@ export type TV = {
|
|
|
131
170
|
): TVReturnType<V, EV, S, ES, B>;
|
|
132
171
|
};
|
|
133
172
|
|
|
173
|
+
// main function
|
|
134
174
|
export declare const tv: TV;
|
|
135
175
|
|
|
176
|
+
export declare const defaultConfig: TVConfig;
|
|
177
|
+
|
|
136
178
|
export type VariantProps<Component extends (...args: any) => any> = Omit<
|
|
137
179
|
OmitUndefined<Parameters<Component>[0]>,
|
|
138
180
|
"class" | "className"
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { b, d, c, a, e } from './chunk-X3I5ASPE.js';
|
|
2
|
+
import { twMerge, extendTailwindMerge } from 'tailwind-merge';
|
|
2
3
|
|
|
3
|
-
var
|
|
4
|
+
var w=(...e)=>e.flat(1/0).filter(Boolean).join(" "),O=(...e)=>(l={})=>l.twMerge?(b(l.twMergeConfig)?twMerge:extendTailwindMerge(l.twMergeConfig))(w(e)):w(e),J=(e,l)=>{let g={};return typeof e!="object"||typeof l!="object"||Object.keys(e).forEach(y=>{l[y]?g[y]=w([e[y],l[y]]):g[y]=e[y];}),g},p={twMerge:!0,twMergeConfig:{}},ae=(e$1,l=p)=>{var v,B,E,S,T;let{slots:g={},variants:y={},compoundVariants:j=[],defaultVariants:L={}}=e$1,A=w((v=e$1==null?void 0:e$1.extend)==null?void 0:v.base,e$1==null?void 0:e$1.base),s=d(y,(B=e$1==null?void 0:e$1.extend)==null?void 0:B.variants),M=Object.assign({},(E=e$1==null?void 0:e$1.extend)==null?void 0:E.defaultVariants,L),$=b(g)?{}:{base:e$1==null?void 0:e$1.base,...g},C=b((S=e$1==null?void 0:e$1.extend)==null?void 0:S.slots)?$:J((T=e$1==null?void 0:e$1.extend)==null?void 0:T.slots,b($)?{base:e$1==null?void 0:e$1.base}:$),i=u=>{var U,W,q;if(b(s)&&b(g)&&b((U=e$1==null?void 0:e$1.extend)==null?void 0:U.slots))return O(A,u==null?void 0:u.class,u==null?void 0:u.className)(l);if(j&&!Array.isArray(j))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof j}`);let X=(t,a,r=[],n)=>{let f=r;if(typeof a=="string")f.push(e(a).split(" ").map(c=>`${t}:${c}`));else if(Array.isArray(a))f.push(a.flatMap(c=>`${t}:${c}`));else if(typeof a=="object"&&typeof n=="string"){let c=a==null?void 0:a[n];if(c&&typeof c=="string"){let d=e(c);f[n]=f[n]?[...f[n],...d.split(" ").map(m=>`${t}:${m}`)]:d.split(" ").map(m=>`${t}:${m}`);}else Array.isArray(c)&&c.length>0&&(f[n]=c.flatMap(d=>`${t}:${d}`));}return f},F=(t,a$1=s,r=null)=>{let n=a$1==null?void 0:a$1[t];if(typeof n!="object"||b(n))return null;let f=u==null?void 0:u[t],c=M==null?void 0:M[t],d=[];if(f===null)return null;let m=a(f);typeof m=="object"&&(d=Object.keys(m).reduce((z,h)=>{let D=m[h],P=n==null?void 0:n[D];return h==="initial"?(c=D,z):X(h,P,z,r)},[]));let x=n[m]||n[a(c)];return typeof d=="object"&&typeof r=="string"&&d[r]?J(d,x):d.length>0?[x,...d]:x},Y=()=>s?Object.keys(s).map(t=>F(t,s)):null,Z=t=>!s||typeof s!="object"?null:Object.keys(s).map(a=>{let r=F(a,s,t);return t==="base"&&typeof r=="string"?r:r&&r[t]}).filter(Boolean),_=u&&Object.fromEntries(Object.entries(u).filter(([,t])=>t!==void 0)),I=(t=[])=>t==null?void 0:t.filter(({class:a,className:r,...n})=>Object.entries(n).every(([f,c])=>{var x;let d=typeof(u==null?void 0:u[f])=="object"?(x=u[f])==null?void 0:x.initial:{},m={...M,...d,..._};return Array.isArray(c)?c.includes(m[f]):m[f]===c})).flatMap(({class:a,className:r})=>[a,r]),R=()=>{var r;let t=I(j),a=I((r=e$1==null?void 0:e$1.extend)==null?void 0:r.compoundVariants);return c(a,t)},k=()=>{let t=R();return Array.isArray(t)?t.reduce((a,r)=>(typeof r=="string"&&(a.base=O(a.base,r)(l)),typeof r=="object"&&Object.entries(r).forEach(([n,f])=>{a[n]=O(a[n],f)(l);}),a),{}):t};if(!b(g)||!b((W=e$1==null?void 0:e$1.extend)==null?void 0:W.slots)){let t=(q=k())!=null?q:[];return {...typeof C=="object"&&!b(C)?Object.keys(C).reduce((r,n)=>(r[n]=f=>O(C[n],Z(n),t==null?void 0:t[n],f==null?void 0:f.class,f==null?void 0:f.className)(l),r),{}):{}}}return O(A,Y(),R(),u==null?void 0:u.class,u==null?void 0:u.className)(l)},Q=()=>{if(!(!s||typeof s!="object"))return Object.keys(s)};return i.variantKeys=Q(),i.base=A,i.slots=C,i.variants=s,i.defaultVariants=M,i.compoundVariants=j,i};
|
|
4
5
|
|
|
5
|
-
export {
|
|
6
|
+
export { O as cx, w as cxBase, p as defaultConfig, ae as tv };
|
package/dist/utils.cjs
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
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 {
|
|
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
package/dist/chunk-C5RUXROF.js
DELETED
|
@@ -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;
|