tailwind-variants 3.2.2 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -80
- package/dist/chunk-2BFDQGZN.cjs +160 -0
- package/dist/chunk-AUQ4UGQK.js +673 -0
- package/dist/chunk-ICHZ2N3R.cjs +677 -0
- package/dist/chunk-OYFAXDFZ.js +147 -0
- package/dist/config-bO3A8WhU.d.cts +112 -0
- package/dist/config-bO3A8WhU.d.ts +112 -0
- package/dist/config.cjs +2 -0
- package/dist/config.d.cts +1 -0
- package/dist/config.d.ts +1 -23
- package/dist/config.js +1 -0
- package/dist/index.cjs +3312 -32
- package/dist/index.d.cts +35 -0
- package/dist/index.d.ts +17 -121
- package/dist/index.js +3309 -25
- package/dist/lite.cjs +17 -12
- package/dist/lite.d.cts +10 -0
- package/dist/lite.d.ts +8 -11
- package/dist/lite.js +15 -8
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +168 -0
- package/dist/types.d.ts +122 -291
- package/dist/types.js +1 -0
- package/dist/utils.cjs +12 -12
- package/dist/utils.d.cts +16 -0
- package/dist/utils.d.ts +16 -32
- package/dist/utils.js +1 -1
- package/package.json +62 -66
- package/dist/chunk-2JY7EID6.cjs +0 -124
- package/dist/chunk-52Z2HSI4.cjs +0 -273
- package/dist/chunk-LQJYWU4O.js +0 -112
- package/dist/chunk-RZF76H2U.js +0 -269
package/dist/chunk-RZF76H2U.js
DELETED
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { cx, isEmptyObject, mergeObjects, isEqual, joinObjects, flatMergeArrays, falsyToString } from './chunk-LQJYWU4O.js';
|
|
2
|
-
|
|
3
|
-
// src/config.js
|
|
4
|
-
var defaultConfig = {
|
|
5
|
-
twMerge: true,
|
|
6
|
-
twMergeConfig: {}
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
// src/state.js
|
|
10
|
-
function createState() {
|
|
11
|
-
let cachedTwMerge = null;
|
|
12
|
-
let cachedTwMergeConfig = {};
|
|
13
|
-
let didTwMergeConfigChange = false;
|
|
14
|
-
return {
|
|
15
|
-
get cachedTwMerge() {
|
|
16
|
-
return cachedTwMerge;
|
|
17
|
-
},
|
|
18
|
-
set cachedTwMerge(value) {
|
|
19
|
-
cachedTwMerge = value;
|
|
20
|
-
},
|
|
21
|
-
get cachedTwMergeConfig() {
|
|
22
|
-
return cachedTwMergeConfig;
|
|
23
|
-
},
|
|
24
|
-
set cachedTwMergeConfig(value) {
|
|
25
|
-
cachedTwMergeConfig = value;
|
|
26
|
-
},
|
|
27
|
-
get didTwMergeConfigChange() {
|
|
28
|
-
return didTwMergeConfigChange;
|
|
29
|
-
},
|
|
30
|
-
set didTwMergeConfigChange(value) {
|
|
31
|
-
didTwMergeConfigChange = value;
|
|
32
|
-
},
|
|
33
|
-
reset() {
|
|
34
|
-
cachedTwMerge = null;
|
|
35
|
-
cachedTwMergeConfig = {};
|
|
36
|
-
didTwMergeConfigChange = false;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
var state = createState();
|
|
41
|
-
|
|
42
|
-
// src/core.js
|
|
43
|
-
var getTailwindVariants = (cn) => {
|
|
44
|
-
const tv = (options, configProp) => {
|
|
45
|
-
const {
|
|
46
|
-
extend = null,
|
|
47
|
-
slots: slotProps = {},
|
|
48
|
-
variants: variantsProps = {},
|
|
49
|
-
compoundVariants: compoundVariantsProps = [],
|
|
50
|
-
compoundSlots = [],
|
|
51
|
-
defaultVariants: defaultVariantsProps = {}
|
|
52
|
-
} = options;
|
|
53
|
-
const config = { ...defaultConfig, ...configProp };
|
|
54
|
-
const base = extend?.base ? cx(extend.base, options?.base) : options?.base;
|
|
55
|
-
const variants = extend?.variants && !isEmptyObject(extend.variants) ? mergeObjects(variantsProps, extend.variants) : variantsProps;
|
|
56
|
-
const defaultVariants = extend?.defaultVariants && !isEmptyObject(extend.defaultVariants) ? { ...extend.defaultVariants, ...defaultVariantsProps } : defaultVariantsProps;
|
|
57
|
-
if (!isEmptyObject(config.twMergeConfig) && !isEqual(config.twMergeConfig, state.cachedTwMergeConfig)) {
|
|
58
|
-
state.didTwMergeConfigChange = true;
|
|
59
|
-
state.cachedTwMergeConfig = config.twMergeConfig;
|
|
60
|
-
}
|
|
61
|
-
const isExtendedSlotsEmpty = isEmptyObject(extend?.slots);
|
|
62
|
-
const componentSlots = !isEmptyObject(slotProps) ? {
|
|
63
|
-
// add "base" to the slots object
|
|
64
|
-
base: cx(options?.base, isExtendedSlotsEmpty && extend?.base),
|
|
65
|
-
...slotProps
|
|
66
|
-
} : {};
|
|
67
|
-
const slots = isExtendedSlotsEmpty ? componentSlots : joinObjects(
|
|
68
|
-
{ ...extend?.slots },
|
|
69
|
-
isEmptyObject(componentSlots) ? { base: options?.base } : componentSlots
|
|
70
|
-
);
|
|
71
|
-
const compoundVariants = isEmptyObject(extend?.compoundVariants) ? compoundVariantsProps : flatMergeArrays(extend?.compoundVariants, compoundVariantsProps);
|
|
72
|
-
const component = (props) => {
|
|
73
|
-
if (isEmptyObject(variants) && isEmptyObject(slotProps) && isExtendedSlotsEmpty) {
|
|
74
|
-
return cn(base, props?.class, props?.className)(config);
|
|
75
|
-
}
|
|
76
|
-
if (compoundVariants && !Array.isArray(compoundVariants)) {
|
|
77
|
-
throw new TypeError(
|
|
78
|
-
`The "compoundVariants" prop must be an array. Received: ${typeof compoundVariants}`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
if (compoundSlots && !Array.isArray(compoundSlots)) {
|
|
82
|
-
throw new TypeError(
|
|
83
|
-
`The "compoundSlots" prop must be an array. Received: ${typeof compoundSlots}`
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
const getVariantValue = (variant, vrs = variants, _slotKey = null, slotProps2 = null) => {
|
|
87
|
-
const variantObj = vrs[variant];
|
|
88
|
-
if (!variantObj || isEmptyObject(variantObj)) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
const variantProp = slotProps2?.[variant] ?? props?.[variant];
|
|
92
|
-
if (variantProp === null) return null;
|
|
93
|
-
const variantKey = falsyToString(variantProp);
|
|
94
|
-
if (typeof variantKey === "object") {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
const defaultVariantProp = defaultVariants?.[variant];
|
|
98
|
-
const key = variantKey != null ? variantKey : falsyToString(defaultVariantProp);
|
|
99
|
-
const value = variantObj[key || "false"];
|
|
100
|
-
return value;
|
|
101
|
-
};
|
|
102
|
-
const getVariantClassNames = () => {
|
|
103
|
-
if (!variants) return null;
|
|
104
|
-
const keys = Object.keys(variants);
|
|
105
|
-
const result = [];
|
|
106
|
-
for (let i = 0; i < keys.length; i++) {
|
|
107
|
-
const value = getVariantValue(keys[i], variants);
|
|
108
|
-
if (value) result.push(value);
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
};
|
|
112
|
-
const getVariantClassNamesBySlotKey = (slotKey, slotProps2) => {
|
|
113
|
-
if (!variants || typeof variants !== "object") return null;
|
|
114
|
-
const result = [];
|
|
115
|
-
for (const variant in variants) {
|
|
116
|
-
const variantValue = getVariantValue(variant, variants, slotKey, slotProps2);
|
|
117
|
-
const value = slotKey === "base" && typeof variantValue === "string" ? variantValue : variantValue && variantValue[slotKey];
|
|
118
|
-
if (value) result.push(value);
|
|
119
|
-
}
|
|
120
|
-
return result;
|
|
121
|
-
};
|
|
122
|
-
const propsWithoutUndefined = {};
|
|
123
|
-
for (const prop in props) {
|
|
124
|
-
const value = props[prop];
|
|
125
|
-
if (value !== void 0) propsWithoutUndefined[prop] = value;
|
|
126
|
-
}
|
|
127
|
-
const getCompleteProps = (key, slotProps2) => {
|
|
128
|
-
const initialProp = typeof props?.[key] === "object" ? {
|
|
129
|
-
[key]: props[key]?.initial
|
|
130
|
-
} : {};
|
|
131
|
-
return {
|
|
132
|
-
...defaultVariants,
|
|
133
|
-
...propsWithoutUndefined,
|
|
134
|
-
...initialProp,
|
|
135
|
-
...slotProps2
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
const getCompoundVariantsValue = (cv = [], slotProps2) => {
|
|
139
|
-
const result = [];
|
|
140
|
-
const cvLength = cv.length;
|
|
141
|
-
for (let i = 0; i < cvLength; i++) {
|
|
142
|
-
const { class: tvClass, className: tvClassName, ...compoundVariantOptions } = cv[i];
|
|
143
|
-
let isValid = true;
|
|
144
|
-
const completeProps = getCompleteProps(null, slotProps2);
|
|
145
|
-
for (const key in compoundVariantOptions) {
|
|
146
|
-
const value = compoundVariantOptions[key];
|
|
147
|
-
const completePropsValue = completeProps[key];
|
|
148
|
-
if (Array.isArray(value)) {
|
|
149
|
-
if (!value.includes(completePropsValue)) {
|
|
150
|
-
isValid = false;
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
} else {
|
|
154
|
-
if ((value == null || value === false) && (completePropsValue == null || completePropsValue === false))
|
|
155
|
-
continue;
|
|
156
|
-
if (completePropsValue !== value) {
|
|
157
|
-
isValid = false;
|
|
158
|
-
break;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (isValid) {
|
|
163
|
-
if (tvClass) result.push(tvClass);
|
|
164
|
-
if (tvClassName) result.push(tvClassName);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return result;
|
|
168
|
-
};
|
|
169
|
-
const getCompoundVariantClassNamesBySlot = (slotProps2) => {
|
|
170
|
-
const compoundClassNames = getCompoundVariantsValue(compoundVariants, slotProps2);
|
|
171
|
-
if (!Array.isArray(compoundClassNames)) return compoundClassNames;
|
|
172
|
-
const result = {};
|
|
173
|
-
const cnFn = cn;
|
|
174
|
-
for (let i = 0; i < compoundClassNames.length; i++) {
|
|
175
|
-
const className = compoundClassNames[i];
|
|
176
|
-
if (typeof className === "string") {
|
|
177
|
-
result.base = cnFn(result.base, className)(config);
|
|
178
|
-
} else if (typeof className === "object") {
|
|
179
|
-
for (const slot in className) {
|
|
180
|
-
result[slot] = cnFn(result[slot], className[slot])(config);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return result;
|
|
185
|
-
};
|
|
186
|
-
const getCompoundSlotClassNameBySlot = (slotProps2) => {
|
|
187
|
-
if (compoundSlots.length < 1) return null;
|
|
188
|
-
const result = {};
|
|
189
|
-
const completeProps = getCompleteProps(null, slotProps2);
|
|
190
|
-
for (let i = 0; i < compoundSlots.length; i++) {
|
|
191
|
-
const {
|
|
192
|
-
slots: slots2 = [],
|
|
193
|
-
class: slotClass,
|
|
194
|
-
className: slotClassName,
|
|
195
|
-
...slotVariants
|
|
196
|
-
} = compoundSlots[i];
|
|
197
|
-
if (!isEmptyObject(slotVariants)) {
|
|
198
|
-
let isValid = true;
|
|
199
|
-
for (const key in slotVariants) {
|
|
200
|
-
const completePropsValue = completeProps[key];
|
|
201
|
-
const slotVariantValue = slotVariants[key];
|
|
202
|
-
if (completePropsValue === void 0 || (Array.isArray(slotVariantValue) ? !slotVariantValue.includes(completePropsValue) : slotVariantValue !== completePropsValue)) {
|
|
203
|
-
isValid = false;
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (!isValid) continue;
|
|
208
|
-
}
|
|
209
|
-
for (let j = 0; j < slots2.length; j++) {
|
|
210
|
-
const slotName = slots2[j];
|
|
211
|
-
if (!result[slotName]) result[slotName] = [];
|
|
212
|
-
result[slotName].push([slotClass, slotClassName]);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return result;
|
|
216
|
-
};
|
|
217
|
-
if (!isEmptyObject(slotProps) || !isExtendedSlotsEmpty) {
|
|
218
|
-
const slotsFns = {};
|
|
219
|
-
if (typeof slots === "object" && !isEmptyObject(slots)) {
|
|
220
|
-
const cnFn = cn;
|
|
221
|
-
for (const slotKey in slots) {
|
|
222
|
-
slotsFns[slotKey] = (slotProps2) => {
|
|
223
|
-
const compoundVariantClasses = getCompoundVariantClassNamesBySlot(slotProps2);
|
|
224
|
-
const compoundSlotClasses = getCompoundSlotClassNameBySlot(slotProps2);
|
|
225
|
-
return cnFn(
|
|
226
|
-
slots[slotKey],
|
|
227
|
-
getVariantClassNamesBySlotKey(slotKey, slotProps2),
|
|
228
|
-
compoundVariantClasses ? compoundVariantClasses[slotKey] : void 0,
|
|
229
|
-
compoundSlotClasses ? compoundSlotClasses[slotKey] : void 0,
|
|
230
|
-
slotProps2?.class,
|
|
231
|
-
slotProps2?.className
|
|
232
|
-
)(config);
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return slotsFns;
|
|
237
|
-
}
|
|
238
|
-
return cn(
|
|
239
|
-
base,
|
|
240
|
-
getVariantClassNames(),
|
|
241
|
-
getCompoundVariantsValue(compoundVariants),
|
|
242
|
-
props?.class,
|
|
243
|
-
props?.className
|
|
244
|
-
)(config);
|
|
245
|
-
};
|
|
246
|
-
const getVariantKeys = () => {
|
|
247
|
-
if (!variants || typeof variants !== "object") return;
|
|
248
|
-
return Object.keys(variants);
|
|
249
|
-
};
|
|
250
|
-
component.variantKeys = getVariantKeys();
|
|
251
|
-
component.extend = extend;
|
|
252
|
-
component.base = base;
|
|
253
|
-
component.slots = slots;
|
|
254
|
-
component.variants = variants;
|
|
255
|
-
component.defaultVariants = defaultVariants;
|
|
256
|
-
component.compoundSlots = compoundSlots;
|
|
257
|
-
component.compoundVariants = compoundVariants;
|
|
258
|
-
return component;
|
|
259
|
-
};
|
|
260
|
-
const createTV = (configProp) => {
|
|
261
|
-
return (options, config) => tv(options, config ? mergeObjects(configProp, config) : configProp);
|
|
262
|
-
};
|
|
263
|
-
return {
|
|
264
|
-
tv,
|
|
265
|
-
createTV
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
export { defaultConfig, getTailwindVariants, state };
|