tailwind-variants 0.3.1 → 2.0.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 +19 -41
- package/dist/chunk-BDOHQXGU.cjs +19 -0
- package/dist/chunk-GVHG2OMS.js +17 -0
- package/dist/chunk-L4Q3BGWH.cjs +82 -0
- package/dist/chunk-YWS777Q5.js +73 -0
- package/dist/cn.cjs +11 -0
- package/dist/cn.js +2 -0
- package/dist/config.d.ts +1 -18
- package/dist/index.cjs +329 -8
- package/dist/index.d.ts +20 -50
- package/dist/index.js +325 -4
- package/dist/utils.cjs +36 -10
- package/dist/utils.js +1 -1
- package/package.json +21 -16
- package/dist/chunk-FUBUDMV2.js +0 -7
- package/dist/chunk-I2QGXAA3.js +0 -3
- package/dist/generated.d.ts +0 -3
- package/dist/generator.cjs +0 -14
- package/dist/generator.d.ts +0 -7
- package/dist/generator.js +0 -1
- package/dist/transformer.cjs +0 -26
- package/dist/transformer.d.ts +0 -26
- package/dist/transformer.js +0 -15
- package/transformer.d.ts +0 -1
- package/transformer.js +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type {ClassNameValue as ClassValue} from "tailwind-merge";
|
|
2
2
|
|
|
3
3
|
import {TVConfig, TWMConfig} from "./config";
|
|
4
|
-
import {TVGeneratedScreens} from "./generated";
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* ----------------------------------------
|
|
@@ -17,7 +16,7 @@ export type ClassProp<V extends unknown = ClassValue> =
|
|
|
17
16
|
|
|
18
17
|
type TVBaseName = "base";
|
|
19
18
|
|
|
20
|
-
type TVScreens = "initial"
|
|
19
|
+
type TVScreens = "initial";
|
|
21
20
|
|
|
22
21
|
type TVSlots = Record<string, ClassValue> | undefined;
|
|
23
22
|
|
|
@@ -125,50 +124,30 @@ export type TVDefaultVariants<
|
|
|
125
124
|
| (K extends keyof EV ? StringToBoolean<keyof EV[K]> : never);
|
|
126
125
|
};
|
|
127
126
|
|
|
128
|
-
export type TVScreenPropsValue<
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
K extends keyof V,
|
|
132
|
-
C extends TVConfig,
|
|
133
|
-
> = C["responsiveVariants"] extends string[]
|
|
134
|
-
? {
|
|
135
|
-
[Screen in WithInitialScreen<C["responsiveVariants"]>[number]]?: StringToBoolean<keyof V[K]>;
|
|
136
|
-
}
|
|
137
|
-
: {
|
|
138
|
-
[Screen in TVScreens]?: StringToBoolean<keyof V[K]>;
|
|
139
|
-
};
|
|
127
|
+
export type TVScreenPropsValue<V extends TVVariants<S>, S extends TVSlots, K extends keyof V> = {
|
|
128
|
+
[Screen in TVScreens]?: StringToBoolean<keyof V[K]>;
|
|
129
|
+
};
|
|
140
130
|
|
|
141
131
|
export type TVProps<
|
|
142
132
|
V extends TVVariants<S>,
|
|
143
133
|
S extends TVSlots,
|
|
144
|
-
C extends TVConfig<V, EV>,
|
|
145
134
|
EV extends TVVariants<ES>,
|
|
146
135
|
ES extends TVSlots,
|
|
147
136
|
> = EV extends undefined
|
|
148
137
|
? V extends undefined
|
|
149
138
|
? ClassProp<ClassValue>
|
|
150
139
|
: {
|
|
151
|
-
[K in keyof V]?:
|
|
152
|
-
? StringToBoolean<keyof V[K]> | TVScreenPropsValue<V, S, K, C> | undefined
|
|
153
|
-
: StringToBoolean<keyof V[K]> | undefined;
|
|
140
|
+
[K in keyof V]?: StringToBoolean<keyof V[K]> | undefined;
|
|
154
141
|
} & ClassProp<ClassValue>
|
|
155
142
|
: V extends undefined
|
|
156
143
|
? {
|
|
157
|
-
[K in keyof EV]?:
|
|
158
|
-
? StringToBoolean<keyof EV[K]> | TVScreenPropsValue<EV, ES, K, C> | undefined
|
|
159
|
-
: StringToBoolean<keyof EV[K]> | undefined;
|
|
144
|
+
[K in keyof EV]?: StringToBoolean<keyof EV[K]> | undefined;
|
|
160
145
|
} & ClassProp<ClassValue>
|
|
161
146
|
: {
|
|
162
|
-
[K in keyof V | keyof EV]?:
|
|
163
|
-
?
|
|
164
|
-
|
|
165
|
-
|
|
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;
|
|
147
|
+
[K in keyof V | keyof EV]?:
|
|
148
|
+
| (K extends keyof V ? StringToBoolean<keyof V[K]> : never)
|
|
149
|
+
| (K extends keyof EV ? StringToBoolean<keyof EV[K]> : never)
|
|
150
|
+
| undefined;
|
|
172
151
|
} & ClassProp<ClassValue>;
|
|
173
152
|
|
|
174
153
|
export type TVVariantKeys<V extends TVVariants<S>, S extends TVSlots> = V extends Object
|
|
@@ -204,23 +183,20 @@ export type TVReturnType<
|
|
|
204
183
|
V extends TVVariants<S>,
|
|
205
184
|
S extends TVSlots,
|
|
206
185
|
B extends ClassValue,
|
|
207
|
-
C extends TVConfig<V, EV>,
|
|
208
186
|
EV extends TVVariants<ES>,
|
|
209
187
|
ES extends TVSlots,
|
|
210
188
|
// @ts-expect-error
|
|
211
189
|
E extends TVReturnType = undefined,
|
|
212
190
|
> = {
|
|
213
|
-
(props?: TVProps<V, S,
|
|
191
|
+
(props?: TVProps<V, S, EV, ES>): HasSlots<S, ES> extends true
|
|
214
192
|
? {
|
|
215
193
|
[K in keyof (ES extends undefined ? {} : ES)]: (
|
|
216
|
-
slotProps?: TVProps<V, S,
|
|
194
|
+
slotProps?: TVProps<V, S, EV, ES>,
|
|
217
195
|
) => string;
|
|
218
196
|
} & {
|
|
219
|
-
[K in keyof (S extends undefined ? {} : S)]: (
|
|
220
|
-
slotProps?: TVProps<V, S, C, EV, ES>,
|
|
221
|
-
) => string;
|
|
197
|
+
[K in keyof (S extends undefined ? {} : S)]: (slotProps?: TVProps<V, S, EV, ES>) => string;
|
|
222
198
|
} & {
|
|
223
|
-
[K in TVSlotsWithBase<{}, B>]: (slotProps?: TVProps<V, S,
|
|
199
|
+
[K in TVSlotsWithBase<{}, B>]: (slotProps?: TVProps<V, S, EV, ES>) => string;
|
|
224
200
|
}
|
|
225
201
|
: string;
|
|
226
202
|
} & TVReturnProps<V, S, B, EV, ES, E>;
|
|
@@ -230,7 +206,6 @@ export type TV = {
|
|
|
230
206
|
V extends TVVariants<S, B, EV>,
|
|
231
207
|
CV extends TVCompoundVariants<V, S, B, EV, ES>,
|
|
232
208
|
DV extends TVDefaultVariants<V, S, EV, ES>,
|
|
233
|
-
C extends TVConfig<V, EV>,
|
|
234
209
|
B extends ClassValue = undefined,
|
|
235
210
|
S extends TVSlots = undefined,
|
|
236
211
|
// @ts-expect-error
|
|
@@ -238,7 +213,6 @@ export type TV = {
|
|
|
238
213
|
V,
|
|
239
214
|
S,
|
|
240
215
|
B,
|
|
241
|
-
C,
|
|
242
216
|
// @ts-expect-error
|
|
243
217
|
EV extends undefined ? {} : EV,
|
|
244
218
|
// @ts-expect-error
|
|
@@ -286,16 +260,15 @@ export type TV = {
|
|
|
286
260
|
* The config object allows you to modify the default configuration.
|
|
287
261
|
* @see https://www.tailwind-variants.org/docs/api-reference#config-optional
|
|
288
262
|
*/
|
|
289
|
-
config?:
|
|
290
|
-
): TVReturnType<V, S, B,
|
|
263
|
+
config?: TVConfig,
|
|
264
|
+
): TVReturnType<V, S, B, EV, ES, E>;
|
|
291
265
|
};
|
|
292
266
|
|
|
293
|
-
export type CreateTV
|
|
267
|
+
export type CreateTV = {
|
|
294
268
|
<
|
|
295
269
|
V extends TVVariants<S, B, EV>,
|
|
296
270
|
CV extends TVCompoundVariants<V, S, B, EV, ES>,
|
|
297
271
|
DV extends TVDefaultVariants<V, S, EV, ES>,
|
|
298
|
-
C extends TVConfig<V, EV>,
|
|
299
272
|
B extends ClassValue = undefined,
|
|
300
273
|
S extends TVSlots = undefined,
|
|
301
274
|
// @ts-expect-error
|
|
@@ -303,7 +276,6 @@ export type CreateTV<RV extends TVConfig["responsiveVariants"] = undefined> = {
|
|
|
303
276
|
V,
|
|
304
277
|
S,
|
|
305
278
|
B,
|
|
306
|
-
C,
|
|
307
279
|
// @ts-expect-error
|
|
308
280
|
EV extends undefined ? {} : EV,
|
|
309
281
|
// @ts-expect-error
|
|
@@ -351,16 +323,14 @@ export type CreateTV<RV extends TVConfig["responsiveVariants"] = undefined> = {
|
|
|
351
323
|
* The config object allows you to modify the default configuration.
|
|
352
324
|
* @see https://www.tailwind-variants.org/docs/api-reference#config-optional
|
|
353
325
|
*/
|
|
354
|
-
config?:
|
|
355
|
-
): TVReturnType<V, S, B,
|
|
326
|
+
config?: TVConfig,
|
|
327
|
+
): TVReturnType<V, S, B, EV, ES, E>;
|
|
356
328
|
};
|
|
357
329
|
|
|
358
330
|
// main function
|
|
359
331
|
export declare const tv: TV;
|
|
360
332
|
|
|
361
|
-
export declare function createTV
|
|
362
|
-
config: TVConfig & T,
|
|
363
|
-
): CreateTV<T>;
|
|
333
|
+
export declare function createTV(config: TVConfig): CreateTV;
|
|
364
334
|
|
|
365
335
|
export declare const defaultConfig: TVConfig;
|
|
366
336
|
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,327 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createTwMerge } from './chunk-GVHG2OMS.js';
|
|
2
|
+
import { isEmptyObject, mergeObjects, isEqual, flatMergeArrays, falsyToString, removeExtraSpaces } from './chunk-YWS777Q5.js';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/index.js
|
|
5
|
+
var defaultConfig = {
|
|
6
|
+
twMerge: true,
|
|
7
|
+
twMergeConfig: {},
|
|
8
|
+
responsiveVariants: false
|
|
9
|
+
};
|
|
10
|
+
var cnBase = (...classes) => {
|
|
11
|
+
const result = [];
|
|
12
|
+
flat(classes, result);
|
|
13
|
+
let str = "";
|
|
14
|
+
for (let i = 0; i < result.length; i++) {
|
|
15
|
+
if (result[i]) {
|
|
16
|
+
if (str) str += " ";
|
|
17
|
+
str += result[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return str || void 0;
|
|
21
|
+
};
|
|
22
|
+
function flat(arr, target) {
|
|
23
|
+
for (let i = 0; i < arr.length; i++) {
|
|
24
|
+
const el = arr[i];
|
|
25
|
+
if (Array.isArray(el)) flat(el, target);
|
|
26
|
+
else if (el) target.push(el);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var cachedTwMerge = null;
|
|
30
|
+
var cachedTwMergeConfig = {};
|
|
31
|
+
var didTwMergeConfigChange = false;
|
|
32
|
+
var cn = (...classes) => (config) => {
|
|
33
|
+
const base = cnBase(classes);
|
|
34
|
+
if (!base || !config.twMerge) return base;
|
|
35
|
+
if (!cachedTwMerge || didTwMergeConfigChange) {
|
|
36
|
+
didTwMergeConfigChange = false;
|
|
37
|
+
cachedTwMerge = createTwMerge(cachedTwMergeConfig);
|
|
38
|
+
}
|
|
39
|
+
return cachedTwMerge(base) || void 0;
|
|
40
|
+
};
|
|
41
|
+
var joinObjects = (obj1, obj2) => {
|
|
42
|
+
for (const key in obj2) {
|
|
43
|
+
if (key in obj1) {
|
|
44
|
+
obj1[key] = cnBase(obj1[key], obj2[key]);
|
|
45
|
+
} else {
|
|
46
|
+
obj1[key] = obj2[key];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return obj1;
|
|
50
|
+
};
|
|
51
|
+
var tv = (options, configProp) => {
|
|
52
|
+
const {
|
|
53
|
+
extend = null,
|
|
54
|
+
slots: slotProps = {},
|
|
55
|
+
variants: variantsProps = {},
|
|
56
|
+
compoundVariants: compoundVariantsProps = [],
|
|
57
|
+
compoundSlots = [],
|
|
58
|
+
defaultVariants: defaultVariantsProps = {}
|
|
59
|
+
} = options;
|
|
60
|
+
const config = { ...defaultConfig, ...configProp };
|
|
61
|
+
const base = extend?.base ? cnBase(extend.base, options?.base) : options?.base;
|
|
62
|
+
const variants = extend?.variants && !isEmptyObject(extend.variants) ? mergeObjects(variantsProps, extend.variants) : variantsProps;
|
|
63
|
+
const defaultVariants = extend?.defaultVariants && !isEmptyObject(extend.defaultVariants) ? { ...extend.defaultVariants, ...defaultVariantsProps } : defaultVariantsProps;
|
|
64
|
+
if (!isEmptyObject(config.twMergeConfig) && !isEqual(config.twMergeConfig, cachedTwMergeConfig)) {
|
|
65
|
+
didTwMergeConfigChange = true;
|
|
66
|
+
cachedTwMergeConfig = config.twMergeConfig;
|
|
67
|
+
}
|
|
68
|
+
const isExtendedSlotsEmpty = isEmptyObject(extend?.slots);
|
|
69
|
+
const componentSlots = !isEmptyObject(slotProps) ? {
|
|
70
|
+
// add "base" to the slots object
|
|
71
|
+
base: cnBase(options?.base, isExtendedSlotsEmpty && extend?.base),
|
|
72
|
+
...slotProps
|
|
73
|
+
} : {};
|
|
74
|
+
const slots = isExtendedSlotsEmpty ? componentSlots : joinObjects(
|
|
75
|
+
{ ...extend?.slots },
|
|
76
|
+
isEmptyObject(componentSlots) ? { base: options?.base } : componentSlots
|
|
77
|
+
);
|
|
78
|
+
const compoundVariants = isEmptyObject(extend?.compoundVariants) ? compoundVariantsProps : flatMergeArrays(extend?.compoundVariants, compoundVariantsProps);
|
|
79
|
+
const component = (props) => {
|
|
80
|
+
if (isEmptyObject(variants) && isEmptyObject(slotProps) && isExtendedSlotsEmpty) {
|
|
81
|
+
return cn(base, props?.class, props?.className)(config);
|
|
82
|
+
}
|
|
83
|
+
if (compoundVariants && !Array.isArray(compoundVariants)) {
|
|
84
|
+
throw new TypeError(
|
|
85
|
+
`The "compoundVariants" prop must be an array. Received: ${typeof compoundVariants}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
if (compoundSlots && !Array.isArray(compoundSlots)) {
|
|
89
|
+
throw new TypeError(
|
|
90
|
+
`The "compoundSlots" prop must be an array. Received: ${typeof compoundSlots}`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const getScreenVariantValues = (screen, screenVariantValue, acc = [], slotKey) => {
|
|
94
|
+
let result = acc;
|
|
95
|
+
if (typeof screenVariantValue === "string") {
|
|
96
|
+
const cleaned = removeExtraSpaces(screenVariantValue);
|
|
97
|
+
const parts = cleaned.split(" ");
|
|
98
|
+
for (let i = 0; i < parts.length; i++) {
|
|
99
|
+
result.push(`${screen}:${parts[i]}`);
|
|
100
|
+
}
|
|
101
|
+
} else if (Array.isArray(screenVariantValue)) {
|
|
102
|
+
for (let i = 0; i < screenVariantValue.length; i++) {
|
|
103
|
+
result.push(`${screen}:${screenVariantValue[i]}`);
|
|
104
|
+
}
|
|
105
|
+
} else if (typeof screenVariantValue === "object" && typeof slotKey === "string") {
|
|
106
|
+
if (slotKey in screenVariantValue) {
|
|
107
|
+
const value = screenVariantValue[slotKey];
|
|
108
|
+
if (value && typeof value === "string") {
|
|
109
|
+
const fixedValue = removeExtraSpaces(value);
|
|
110
|
+
const parts = fixedValue.split(" ");
|
|
111
|
+
const arr = [];
|
|
112
|
+
for (let i = 0; i < parts.length; i++) {
|
|
113
|
+
arr.push(`${screen}:${parts[i]}`);
|
|
114
|
+
}
|
|
115
|
+
result[slotKey] = result[slotKey] ? result[slotKey].concat(arr) : arr;
|
|
116
|
+
} else if (Array.isArray(value) && value.length > 0) {
|
|
117
|
+
const arr = [];
|
|
118
|
+
for (let i = 0; i < value.length; i++) {
|
|
119
|
+
arr.push(`${screen}:${value[i]}`);
|
|
120
|
+
}
|
|
121
|
+
result[slotKey] = arr;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
};
|
|
127
|
+
const getVariantValue = (variant, vrs = variants, slotKey = null, slotProps2 = null) => {
|
|
128
|
+
const variantObj = vrs[variant];
|
|
129
|
+
if (!variantObj || isEmptyObject(variantObj)) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const variantProp = slotProps2?.[variant] ?? props?.[variant];
|
|
133
|
+
if (variantProp === null) return null;
|
|
134
|
+
const variantKey = falsyToString(variantProp);
|
|
135
|
+
const responsiveVarsEnabled = Array.isArray(config.responsiveVariants) && config.responsiveVariants.length > 0 || config.responsiveVariants === true;
|
|
136
|
+
let defaultVariantProp = defaultVariants?.[variant];
|
|
137
|
+
let screenValues = [];
|
|
138
|
+
if (typeof variantKey === "object" && responsiveVarsEnabled) {
|
|
139
|
+
for (const [screen, screenVariantKey] of Object.entries(variantKey)) {
|
|
140
|
+
const screenVariantValue = variantObj[screenVariantKey];
|
|
141
|
+
if (screen === "initial") {
|
|
142
|
+
defaultVariantProp = screenVariantKey;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (Array.isArray(config.responsiveVariants) && !config.responsiveVariants.includes(screen)) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
screenValues = getScreenVariantValues(screen, screenVariantValue, screenValues, slotKey);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const key = variantKey != null && typeof variantKey != "object" ? variantKey : falsyToString(defaultVariantProp);
|
|
152
|
+
const value = variantObj[key || "false"];
|
|
153
|
+
if (typeof screenValues === "object" && typeof slotKey === "string" && screenValues[slotKey]) {
|
|
154
|
+
return joinObjects(screenValues, value);
|
|
155
|
+
}
|
|
156
|
+
if (screenValues.length > 0) {
|
|
157
|
+
screenValues.push(value);
|
|
158
|
+
if (slotKey === "base") {
|
|
159
|
+
return screenValues.join(" ");
|
|
160
|
+
}
|
|
161
|
+
return screenValues;
|
|
162
|
+
}
|
|
163
|
+
return value;
|
|
164
|
+
};
|
|
165
|
+
const getVariantClassNames = () => {
|
|
166
|
+
if (!variants) return null;
|
|
167
|
+
const keys = Object.keys(variants);
|
|
168
|
+
const result = [];
|
|
169
|
+
for (let i = 0; i < keys.length; i++) {
|
|
170
|
+
const value = getVariantValue(keys[i], variants);
|
|
171
|
+
if (value) result.push(value);
|
|
172
|
+
}
|
|
173
|
+
return result;
|
|
174
|
+
};
|
|
175
|
+
const getVariantClassNamesBySlotKey = (slotKey, slotProps2) => {
|
|
176
|
+
if (!variants || typeof variants !== "object") return null;
|
|
177
|
+
const result = [];
|
|
178
|
+
for (const variant in variants) {
|
|
179
|
+
const variantValue = getVariantValue(variant, variants, slotKey, slotProps2);
|
|
180
|
+
const value = slotKey === "base" && typeof variantValue === "string" ? variantValue : variantValue && variantValue[slotKey];
|
|
181
|
+
if (value) result.push(value);
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
};
|
|
185
|
+
const propsWithoutUndefined = {};
|
|
186
|
+
for (const prop in props) {
|
|
187
|
+
const value = props[prop];
|
|
188
|
+
if (value !== void 0) propsWithoutUndefined[prop] = value;
|
|
189
|
+
}
|
|
190
|
+
const getCompleteProps = (key, slotProps2) => {
|
|
191
|
+
const initialProp = typeof props?.[key] === "object" ? {
|
|
192
|
+
[key]: props[key]?.initial
|
|
193
|
+
} : {};
|
|
194
|
+
return {
|
|
195
|
+
...defaultVariants,
|
|
196
|
+
...propsWithoutUndefined,
|
|
197
|
+
...initialProp,
|
|
198
|
+
...slotProps2
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
const getCompoundVariantsValue = (cv = [], slotProps2) => {
|
|
202
|
+
const result = [];
|
|
203
|
+
const cvLength = cv.length;
|
|
204
|
+
for (let i = 0; i < cvLength; i++) {
|
|
205
|
+
const { class: tvClass, className: tvClassName, ...compoundVariantOptions } = cv[i];
|
|
206
|
+
let isValid = true;
|
|
207
|
+
const completeProps = getCompleteProps(null, slotProps2);
|
|
208
|
+
for (const key in compoundVariantOptions) {
|
|
209
|
+
const value = compoundVariantOptions[key];
|
|
210
|
+
const completePropsValue = completeProps[key];
|
|
211
|
+
if (Array.isArray(value)) {
|
|
212
|
+
if (!value.includes(completePropsValue)) {
|
|
213
|
+
isValid = false;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
if ((value == null || value === false) && (completePropsValue == null || completePropsValue === false))
|
|
218
|
+
continue;
|
|
219
|
+
if (completePropsValue !== value) {
|
|
220
|
+
isValid = false;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (isValid) {
|
|
226
|
+
if (tvClass) result.push(tvClass);
|
|
227
|
+
if (tvClassName) result.push(tvClassName);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
};
|
|
232
|
+
const getCompoundVariantClassNamesBySlot = (slotProps2) => {
|
|
233
|
+
const compoundClassNames = getCompoundVariantsValue(compoundVariants, slotProps2);
|
|
234
|
+
if (!Array.isArray(compoundClassNames)) return compoundClassNames;
|
|
235
|
+
const result = {};
|
|
236
|
+
const cnFn = cn;
|
|
237
|
+
for (let i = 0; i < compoundClassNames.length; i++) {
|
|
238
|
+
const className = compoundClassNames[i];
|
|
239
|
+
if (typeof className === "string") {
|
|
240
|
+
result.base = cnFn(result.base, className)(config);
|
|
241
|
+
} else if (typeof className === "object") {
|
|
242
|
+
for (const slot in className) {
|
|
243
|
+
result[slot] = cnFn(result[slot], className[slot])(config);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return result;
|
|
248
|
+
};
|
|
249
|
+
const getCompoundSlotClassNameBySlot = (slotProps2) => {
|
|
250
|
+
if (compoundSlots.length < 1) return null;
|
|
251
|
+
const result = {};
|
|
252
|
+
const completeProps = getCompleteProps(null, slotProps2);
|
|
253
|
+
for (let i = 0; i < compoundSlots.length; i++) {
|
|
254
|
+
const {
|
|
255
|
+
slots: slots2 = [],
|
|
256
|
+
class: slotClass,
|
|
257
|
+
className: slotClassName,
|
|
258
|
+
...slotVariants
|
|
259
|
+
} = compoundSlots[i];
|
|
260
|
+
if (!isEmptyObject(slotVariants)) {
|
|
261
|
+
let isValid = true;
|
|
262
|
+
for (const key in slotVariants) {
|
|
263
|
+
const completePropsValue = completeProps[key];
|
|
264
|
+
const slotVariantValue = slotVariants[key];
|
|
265
|
+
if (completePropsValue === void 0 || (Array.isArray(slotVariantValue) ? !slotVariantValue.includes(completePropsValue) : slotVariantValue !== completePropsValue)) {
|
|
266
|
+
isValid = false;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (!isValid) continue;
|
|
271
|
+
}
|
|
272
|
+
for (let j = 0; j < slots2.length; j++) {
|
|
273
|
+
const slotName = slots2[j];
|
|
274
|
+
if (!result[slotName]) result[slotName] = [];
|
|
275
|
+
result[slotName].push([slotClass, slotClassName]);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
279
|
+
};
|
|
280
|
+
if (!isEmptyObject(slotProps) || !isExtendedSlotsEmpty) {
|
|
281
|
+
const slotsFns = {};
|
|
282
|
+
if (typeof slots === "object" && !isEmptyObject(slots)) {
|
|
283
|
+
const cnFn = cn;
|
|
284
|
+
for (const slotKey in slots) {
|
|
285
|
+
slotsFns[slotKey] = (slotProps2) => {
|
|
286
|
+
const compoundVariantClasses = getCompoundVariantClassNamesBySlot(slotProps2);
|
|
287
|
+
const compoundSlotClasses = getCompoundSlotClassNameBySlot(slotProps2);
|
|
288
|
+
return cnFn(
|
|
289
|
+
slots[slotKey],
|
|
290
|
+
getVariantClassNamesBySlotKey(slotKey, slotProps2),
|
|
291
|
+
compoundVariantClasses ? compoundVariantClasses[slotKey] : void 0,
|
|
292
|
+
compoundSlotClasses ? compoundSlotClasses[slotKey] : void 0,
|
|
293
|
+
slotProps2?.class,
|
|
294
|
+
slotProps2?.className
|
|
295
|
+
)(config);
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return slotsFns;
|
|
300
|
+
}
|
|
301
|
+
return cn(
|
|
302
|
+
base,
|
|
303
|
+
getVariantClassNames(),
|
|
304
|
+
getCompoundVariantsValue(compoundVariants),
|
|
305
|
+
props?.class,
|
|
306
|
+
props?.className
|
|
307
|
+
)(config);
|
|
308
|
+
};
|
|
309
|
+
const getVariantKeys = () => {
|
|
310
|
+
if (!variants || typeof variants !== "object") return;
|
|
311
|
+
return Object.keys(variants);
|
|
312
|
+
};
|
|
313
|
+
component.variantKeys = getVariantKeys();
|
|
314
|
+
component.extend = extend;
|
|
315
|
+
component.base = base;
|
|
316
|
+
component.slots = slots;
|
|
317
|
+
component.variants = variants;
|
|
318
|
+
component.defaultVariants = defaultVariants;
|
|
319
|
+
component.compoundSlots = compoundSlots;
|
|
320
|
+
component.compoundVariants = compoundVariants;
|
|
321
|
+
return component;
|
|
322
|
+
};
|
|
323
|
+
var createTV = (configProp) => {
|
|
324
|
+
return (options, config) => tv(options, config ? mergeObjects(configProp, config) : configProp);
|
|
325
|
+
};
|
|
5
326
|
|
|
6
|
-
export {
|
|
327
|
+
export { cn, cnBase, createTV, defaultConfig, tv };
|
package/dist/utils.cjs
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
exports
|
|
12
|
-
|
|
3
|
+
var chunkL4Q3BGWH_cjs = require('./chunk-L4Q3BGWH.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "falsyToString", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkL4Q3BGWH_cjs.falsyToString; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "flatArray", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkL4Q3BGWH_cjs.flatArray; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "flatMergeArrays", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkL4Q3BGWH_cjs.flatMergeArrays; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "isBoolean", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return chunkL4Q3BGWH_cjs.isBoolean; }
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "isEmptyObject", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return chunkL4Q3BGWH_cjs.isEmptyObject; }
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(exports, "isEqual", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return chunkL4Q3BGWH_cjs.isEqual; }
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "mergeObjects", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return chunkL4Q3BGWH_cjs.mergeObjects; }
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "removeExtraSpaces", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return chunkL4Q3BGWH_cjs.removeExtraSpaces; }
|
|
38
|
+
});
|
package/dist/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { falsyToString, flatArray, flatMergeArrays, isBoolean, isEmptyObject, isEqual, mergeObjects, removeExtraSpaces } from './chunk-YWS777Q5.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwind-variants",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "🦄 Tailwindcss first-class variant API",
|
|
5
5
|
"author": "Junior Garcia <jrgarciadev@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,12 +20,11 @@
|
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"files": [
|
|
22
22
|
"dist",
|
|
23
|
-
"transformer.js",
|
|
24
|
-
"transformer.d.ts",
|
|
25
23
|
"README.md",
|
|
26
24
|
"LICENSE"
|
|
27
25
|
],
|
|
28
26
|
"scripts": {
|
|
27
|
+
"dev": "tsup --watch",
|
|
29
28
|
"build": "tsup && node copy-types.cjs",
|
|
30
29
|
"typecheck": "tsc --noEmit",
|
|
31
30
|
"prepack": "clean-package",
|
|
@@ -34,10 +33,11 @@
|
|
|
34
33
|
"lint": "eslint . src/**/*.{js,ts}",
|
|
35
34
|
"lint:fix": "eslint --fix . src/**/*.{js,ts}",
|
|
36
35
|
"test": "jest --verbose",
|
|
37
|
-
"test:watch": "jest --watch --no-verbose"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
36
|
+
"test:watch": "jest --watch --no-verbose",
|
|
37
|
+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .",
|
|
38
|
+
"release": "bumpp --execute='pnpm run changelog' --all",
|
|
39
|
+
"prepublishOnly": "pnpm run build",
|
|
40
|
+
"release:check": "pnpm run lint && pnpm run typecheck && pnpm run test && pnpm run build"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@commitlint/cli": "19.5.0",
|
|
@@ -53,8 +53,11 @@
|
|
|
53
53
|
"@typescript-eslint/eslint-plugin": "8.14.0",
|
|
54
54
|
"@typescript-eslint/parser": "8.14.0",
|
|
55
55
|
"benchmark": "2.1.4",
|
|
56
|
+
"bumpp": "10.2.0",
|
|
57
|
+
"changelogithub": "13.16.0",
|
|
56
58
|
"class-variance-authority": "0.7.0",
|
|
57
59
|
"clean-package": "2.2.0",
|
|
60
|
+
"conventional-changelog-cli": "5.0.0",
|
|
58
61
|
"eslint": "8.57.0",
|
|
59
62
|
"eslint-config-prettier": "9.1.0",
|
|
60
63
|
"eslint-config-ts-lambdas": "1.2.3",
|
|
@@ -66,17 +69,24 @@
|
|
|
66
69
|
"eslint-plugin-promise": "7.1.0",
|
|
67
70
|
"expect": "29.7.0",
|
|
68
71
|
"jest": "29.7.0",
|
|
72
|
+
"postcss": "8.5.6",
|
|
69
73
|
"prettier": "3.3.3",
|
|
70
74
|
"prettier-eslint": "16.3.0",
|
|
71
75
|
"prettier-eslint-cli": "8.0.1",
|
|
72
|
-
"tailwindcss": "
|
|
76
|
+
"tailwindcss": "4.1.11",
|
|
73
77
|
"ts-node": "10.9.2",
|
|
74
|
-
"tsup": "8.
|
|
78
|
+
"tsup": "8.5.0",
|
|
75
79
|
"typescript": "5.6.3"
|
|
76
80
|
},
|
|
77
81
|
"peerDependencies": {
|
|
82
|
+
"tailwind-merge": ">=3.0.0",
|
|
78
83
|
"tailwindcss": "*"
|
|
79
84
|
},
|
|
85
|
+
"peerDependenciesMeta": {
|
|
86
|
+
"tailwind-merge": {
|
|
87
|
+
"optional": true
|
|
88
|
+
}
|
|
89
|
+
},
|
|
80
90
|
"keywords": [
|
|
81
91
|
"tailwindcss",
|
|
82
92
|
"classes",
|
|
@@ -92,16 +102,11 @@
|
|
|
92
102
|
"module": "dist/index.js",
|
|
93
103
|
"exports": {
|
|
94
104
|
".": {
|
|
95
|
-
"
|
|
105
|
+
"types": "./dist/index.d.ts",
|
|
96
106
|
"import": "./dist/index.js",
|
|
97
|
-
"
|
|
107
|
+
"require": "./dist/index.cjs"
|
|
98
108
|
},
|
|
99
109
|
"./dist/*": "./dist/*",
|
|
100
|
-
"./transformer": {
|
|
101
|
-
"require": "./dist/transformer.cjs",
|
|
102
|
-
"types": "./dist/transformer.d.ts",
|
|
103
|
-
"default": "./dist/transformer.js"
|
|
104
|
-
},
|
|
105
110
|
"./package.json": "./package.json"
|
|
106
111
|
}
|
|
107
112
|
}
|
package/dist/chunk-FUBUDMV2.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import n from 'fs';
|
|
2
|
-
import s from 'path';
|
|
3
|
-
|
|
4
|
-
var t=e=>{n.writeFileSync(s.join(__dirname,"generated.d.ts"),e);},c=e=>`export type TVGeneratedScreens = ${Object.keys(e).map(r=>`"${r}"`).join(" | ")};
|
|
5
|
-
`,p=e=>{queueMicrotask(()=>{if(e!=null&&e.screens){let r=c(e.screens);t(r);}});};
|
|
6
|
-
|
|
7
|
-
export { p as a };
|
package/dist/chunk-I2QGXAA3.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
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
|
-
|
|
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/generated.d.ts
DELETED