tailwind-variants 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -3
- package/dist/index.d.ts +27 -25
- package/dist/index.js +2 -3
- package/dist/utils.d.ts +12 -17
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var classVarianceAuthority = require('class-variance-authority');
|
|
4
3
|
var tailwindMerge = require('tailwind-merge');
|
|
5
4
|
|
|
6
|
-
var w=t=>typeof t=="boolean"?`${t}`:t===0?"0":t,
|
|
5
|
+
var O=(...t)=>t.flat(1/0).filter(Boolean).join(" "),w=t=>typeof t=="boolean"?`${t}`:t===0?"0":t,m=t=>t&&Object.keys(t).length>0,j=(...t)=>(u={})=>u.twMerge?(m(u.twMergeConfig)?tailwindMerge.extendTailwindMerge(u.twMergeConfig):tailwindMerge.twMerge)(O(t)):O(t),E=(t,u)=>{let e={};return typeof t!="object"||typeof u!="object"||Object.keys(t).forEach(s=>{u[s]?e[s]=O([t[s],u[s]]):e[s]=t[s];}),e},$=t=>!t||typeof t!="string"?t:t.replace(/\s+/g," ").trim();var D=(t,u={twMerge:!0,twMergeConfig:{}})=>e=>{var h;let{slots:s={},variants:b={},compoundVariants:g=[],defaultVariants:d={}}=t;if(b==null&&!m(s))return j(t==null?void 0:t.base,e==null?void 0:e.class,e==null?void 0:e.className)(u);if(g&&!Array.isArray(g))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof g}`);let x={base:t==null?void 0:t.base,...s},S=(r,n,f=[],i)=>{let a=f;if(typeof n=="string")a.push($(n).split(" ").map(c=>`${r}:${c}`));else if(Array.isArray(n))a.push(n.flatMap(c=>`${r}:${c}`));else if(typeof n=="object"&&typeof i=="string"){let c=n==null?void 0:n[i];if(c&&typeof c=="string"){let l=$(c);a[i]=a[i]?[...a[i],...l.split(" ").map(y=>`${r}:${y}`)]:l.split(" ").map(y=>`${r}:${y}`);}else Array.isArray(c)&&c.length>0&&(a[i]=c.flatMap(l=>`${r}:${l}`));}return a},o=(r,n=null)=>{let f=b==null?void 0:b[r];if(typeof f!="object"||!m(f))return null;let i=e==null?void 0:e[r],a=d==null?void 0:d[r],c=[];if(i===null)return null;let l=w(i);typeof l=="object"&&(c=Object.keys(l).reduce((A,M)=>{let N=l[M],I=f==null?void 0:f[N];return M==="initial"?(a=N,A):S(M,I,A,n)},[]));let y=f[l]||f[w(a)];return typeof c=="object"&&typeof n=="string"&&c[n]?E(c,y):c.length>0?[y,...c]:y},B=b?Object.keys(b).map(o):null,T=r=>!b||typeof b!="object"?null:Object.keys(b).map(n=>{let f=o(n,r);return r==="base"&&typeof f=="string"?f:f&&f[r]}).filter(Boolean),v=e&&Object.fromEntries(Object.entries(e).filter(([,r])=>r!==void 0)),C=g==null?void 0:g.filter(({class:r,className:n,...f})=>Object.entries(f).every(([i,a])=>{var y;let c=typeof(e==null?void 0:e[i])=="object"?(y=e[i])==null?void 0:y.initial:{},l={...d,...c,...v};return Array.isArray(a)?a.includes(l[i]):l[i]===a})).flatMap(({class:r,className:n})=>[r,n]),F=()=>{let r=C;return Array.isArray(r)?r.reduce((n,f)=>(typeof f=="string"&&(n.base=j(n.base,f)(u)),typeof f=="object"&&Object.entries(f).forEach(([i,a])=>{n[i]=j(n[i],a)(u);}),n),{}):r};if(m(s)){let r=(h=F())!=null?h:[];return {...typeof x=="object"&&m(x)?Object.keys(x).reduce((f,i)=>(f[i]=a=>j(x[i],T(i),r==null?void 0:r[i],a==null?void 0:a.class,a==null?void 0:a.className)(u),f),{}):{}}}return j(t==null?void 0:t.base,B,C,e==null?void 0:e.class,e==null?void 0:e.className)(u)};
|
|
7
6
|
|
|
8
|
-
exports.tv =
|
|
7
|
+
exports.tv = D;
|
package/dist/index.d.ts
CHANGED
|
@@ -41,33 +41,35 @@ export type TVScreenPropsValue<V extends TVVariants<S>, K extends keyof V> = {
|
|
|
41
41
|
|
|
42
42
|
export type TVProps<V extends TVVariants<S>, S extends TVSlots> = {
|
|
43
43
|
[K in keyof V]?: StringToBoolean<keyof V[K]> | TVScreenPropsValue<V, K>;
|
|
44
|
-
} & ClassProp
|
|
44
|
+
} & ClassProp<ClassValue>;
|
|
45
45
|
|
|
46
|
-
export type TVReturnType<V extends TVVariants<S>, S extends TVSlots, B extends ClassValue> =
|
|
47
|
-
props?: TVProps<V, S
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
[K in TVSlotsWithBase<S, B>]: (slotProps?: ClassProp) => string;
|
|
52
|
-
};
|
|
46
|
+
export type TVReturnType<V extends TVVariants<S>, S extends TVSlots, B extends ClassValue> = {
|
|
47
|
+
(props?: TVProps<V, S>): S extends undefined
|
|
48
|
+
? string
|
|
49
|
+
: {[K in TVSlotsWithBase<S, B>]: (slotProps?: ClassProp) => string};
|
|
50
|
+
};
|
|
53
51
|
|
|
54
|
-
export
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
52
|
+
export type TV = {
|
|
53
|
+
<
|
|
54
|
+
V extends TVVariants<S> = {},
|
|
55
|
+
CV extends TVCompoundVariants<V, S, B> = [],
|
|
56
|
+
DV extends TVDefaultVariants<V, S> = {},
|
|
57
|
+
C extends TVConfig,
|
|
58
|
+
B extends ClassValue = undefined,
|
|
59
|
+
S extends TVSlots = undefined,
|
|
60
|
+
>(
|
|
61
|
+
options: {
|
|
62
|
+
base?: B;
|
|
63
|
+
slots?: S;
|
|
64
|
+
variants?: V;
|
|
65
|
+
compoundVariants?: CV;
|
|
66
|
+
defaultVariants?: DV;
|
|
67
|
+
},
|
|
68
|
+
config?: C,
|
|
69
|
+
): TVReturnType<V, S, B>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export declare const tv: TV;
|
|
71
73
|
|
|
72
74
|
export type VariantProps<Component extends (...args: any) => any> = Omit<
|
|
73
75
|
OmitUndefined<Parameters<Component>[0]>,
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { cx } from 'class-variance-authority';
|
|
2
1
|
import { extendTailwindMerge, twMerge } from 'tailwind-merge';
|
|
3
2
|
|
|
4
|
-
var w=t=>typeof t=="boolean"?`${t}`:t===0?"0":t,
|
|
3
|
+
var O=(...t)=>t.flat(1/0).filter(Boolean).join(" "),w=t=>typeof t=="boolean"?`${t}`:t===0?"0":t,m=t=>t&&Object.keys(t).length>0,j=(...t)=>(u={})=>u.twMerge?(m(u.twMergeConfig)?extendTailwindMerge(u.twMergeConfig):twMerge)(O(t)):O(t),E=(t,u)=>{let e={};return typeof t!="object"||typeof u!="object"||Object.keys(t).forEach(s=>{u[s]?e[s]=O([t[s],u[s]]):e[s]=t[s];}),e},$=t=>!t||typeof t!="string"?t:t.replace(/\s+/g," ").trim();var D=(t,u={twMerge:!0,twMergeConfig:{}})=>e=>{var h;let{slots:s={},variants:b={},compoundVariants:g=[],defaultVariants:d={}}=t;if(b==null&&!m(s))return j(t==null?void 0:t.base,e==null?void 0:e.class,e==null?void 0:e.className)(u);if(g&&!Array.isArray(g))throw new TypeError(`The "compoundVariants" prop must be an array. Received: ${typeof g}`);let x={base:t==null?void 0:t.base,...s},S=(r,n,f=[],i)=>{let a=f;if(typeof n=="string")a.push($(n).split(" ").map(c=>`${r}:${c}`));else if(Array.isArray(n))a.push(n.flatMap(c=>`${r}:${c}`));else if(typeof n=="object"&&typeof i=="string"){let c=n==null?void 0:n[i];if(c&&typeof c=="string"){let l=$(c);a[i]=a[i]?[...a[i],...l.split(" ").map(y=>`${r}:${y}`)]:l.split(" ").map(y=>`${r}:${y}`);}else Array.isArray(c)&&c.length>0&&(a[i]=c.flatMap(l=>`${r}:${l}`));}return a},o=(r,n=null)=>{let f=b==null?void 0:b[r];if(typeof f!="object"||!m(f))return null;let i=e==null?void 0:e[r],a=d==null?void 0:d[r],c=[];if(i===null)return null;let l=w(i);typeof l=="object"&&(c=Object.keys(l).reduce((A,M)=>{let N=l[M],I=f==null?void 0:f[N];return M==="initial"?(a=N,A):S(M,I,A,n)},[]));let y=f[l]||f[w(a)];return typeof c=="object"&&typeof n=="string"&&c[n]?E(c,y):c.length>0?[y,...c]:y},B=b?Object.keys(b).map(o):null,T=r=>!b||typeof b!="object"?null:Object.keys(b).map(n=>{let f=o(n,r);return r==="base"&&typeof f=="string"?f:f&&f[r]}).filter(Boolean),v=e&&Object.fromEntries(Object.entries(e).filter(([,r])=>r!==void 0)),C=g==null?void 0:g.filter(({class:r,className:n,...f})=>Object.entries(f).every(([i,a])=>{var y;let c=typeof(e==null?void 0:e[i])=="object"?(y=e[i])==null?void 0:y.initial:{},l={...d,...c,...v};return Array.isArray(a)?a.includes(l[i]):l[i]===a})).flatMap(({class:r,className:n})=>[r,n]),F=()=>{let r=C;return Array.isArray(r)?r.reduce((n,f)=>(typeof f=="string"&&(n.base=j(n.base,f)(u)),typeof f=="object"&&Object.entries(f).forEach(([i,a])=>{n[i]=j(n[i],a)(u);}),n),{}):r};if(m(s)){let r=(h=F())!=null?h:[];return {...typeof x=="object"&&m(x)?Object.keys(x).reduce((f,i)=>(f[i]=a=>j(x[i],T(i),r==null?void 0:r[i],a==null?void 0:a.class,a==null?void 0:a.className)(u),f),{}):{}}}return j(t==null?void 0:t.base,B,C,e==null?void 0:e.class,e==null?void 0:e.className)(u)};
|
|
5
4
|
|
|
6
|
-
export {
|
|
5
|
+
export { D as tv };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import {CxOptions, CxReturn} from "class-variance-authority";
|
|
2
|
-
|
|
3
1
|
import {TVConfig} from "./config";
|
|
4
2
|
|
|
5
|
-
export declare const falsyToString: <T extends unknown>(value: T) => string | T;
|
|
6
|
-
|
|
7
|
-
export declare const isNotEmptyObject: (obj: object) => boolean;
|
|
8
|
-
|
|
9
|
-
export declare const cx: <T extends CxOptions>(...classes: T) => (config: TVConfig) => CxReturn;
|
|
10
|
-
|
|
11
|
-
export declare const joinObjects: (obj1: object, obj2: object) => object;
|
|
12
|
-
|
|
13
|
-
export declare const removeExtraSpaces: (str: string) => string;
|
|
14
|
-
|
|
15
|
-
export declare type ClassPropKey = "class" | "className";
|
|
16
3
|
export declare type ClassValue = string | string[] | null | undefined;
|
|
17
4
|
|
|
18
5
|
export declare type ClassProp<V extends unknown = ClassValue> =
|
|
@@ -27,8 +14,16 @@ export declare type OmitUndefined<T> = T extends undefined ? never : T;
|
|
|
27
14
|
|
|
28
15
|
export declare type StringToBoolean<T> = T extends "true" | "false" ? boolean : T;
|
|
29
16
|
|
|
30
|
-
export
|
|
31
|
-
[K in T[number]]: (props?: Props) => string;
|
|
32
|
-
};
|
|
17
|
+
export type CxOptions = ClassValue[];
|
|
33
18
|
|
|
34
|
-
export
|
|
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 isNotEmptyObject: (obj: object) => boolean;
|
|
26
|
+
|
|
27
|
+
export declare const joinObjects: (obj1: object, obj2: object) => object;
|
|
28
|
+
|
|
29
|
+
export declare const removeExtraSpaces: (str: string) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwind-variants",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "🦄 Tailwindcss first-class variant API",
|
|
5
5
|
"author": "Junior Garcia <jrgarciadev@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"test": "jest --verbose"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"class-variance-authority": "0.4.0",
|
|
38
37
|
"tailwind-merge": "^1.8.1"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|