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/README.md
CHANGED
|
@@ -20,17 +20,21 @@
|
|
|
20
20
|
## Features
|
|
21
21
|
|
|
22
22
|
- First-class variant API
|
|
23
|
-
- Responsive variants
|
|
24
23
|
- Slots support
|
|
25
24
|
- Composition support
|
|
26
25
|
- Fully typed
|
|
27
26
|
- Framework agnostic
|
|
28
27
|
- Automatic conflict resolution
|
|
28
|
+
- Tailwindcss V4 support
|
|
29
29
|
|
|
30
30
|
## Documentation
|
|
31
31
|
|
|
32
32
|
For full documentation, visit [tailwind-variants.org](https://tailwind-variants.org)
|
|
33
33
|
|
|
34
|
+
> ❕ Note: `Tailwindcss V4` no longer supports the `config.content.transform` so we remove the `responsive variants` feature
|
|
35
|
+
>
|
|
36
|
+
> If you want to use `responsive variants`, you need to add it manually to your classname.
|
|
37
|
+
|
|
34
38
|
## Quick Start
|
|
35
39
|
|
|
36
40
|
1. Installation:
|
|
@@ -40,8 +44,22 @@ For full documentation, visit [tailwind-variants.org](https://tailwind-variants.
|
|
|
40
44
|
yarn add tailwind-variants
|
|
41
45
|
# or
|
|
42
46
|
npm i tailwind-variants
|
|
47
|
+
# or
|
|
48
|
+
pnpm add tailwind-variants
|
|
43
49
|
```
|
|
44
50
|
|
|
51
|
+
**Optional:** If you want automatic conflict resolution, also install `tailwind-merge`:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
yarn add tailwind-merge
|
|
55
|
+
# or
|
|
56
|
+
npm i tailwind-merge
|
|
57
|
+
# or
|
|
58
|
+
pnpm add tailwind-merge
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> **⚠️ Upgrading from v1?** Please read the [migration guide](./MIGRATION-V2.md) for breaking changes and performance improvements.
|
|
62
|
+
|
|
45
63
|
2. Usage:
|
|
46
64
|
|
|
47
65
|
```js
|
|
@@ -75,46 +93,6 @@ const button = tv({
|
|
|
75
93
|
return <button className={button({size: "sm", color: "secondary"})}>Click me</button>;
|
|
76
94
|
```
|
|
77
95
|
|
|
78
|
-
3. Responsive variants configuration (optional): If you want to use responsive variants
|
|
79
|
-
you need to add the Tailwind Variants `wrapper` to your TailwindCSS config file `tailwind.config.js`.
|
|
80
|
-
|
|
81
|
-
```js
|
|
82
|
-
// tailwind.config.js
|
|
83
|
-
|
|
84
|
-
const {withTV} = require("tailwind-variants/transformer");
|
|
85
|
-
|
|
86
|
-
/** @type {import('tailwindcss').Config} */
|
|
87
|
-
module.exports = withTV({
|
|
88
|
-
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
|
|
89
|
-
theme: {
|
|
90
|
-
extend: {},
|
|
91
|
-
},
|
|
92
|
-
plugins: [],
|
|
93
|
-
});
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
If you're using a custom path to import Tailwind variants, such as creating a custom tv instance with `createTV`, it's recommended to include this path in the transformer configuration:
|
|
97
|
-
|
|
98
|
-
```js
|
|
99
|
-
// tailwind.config.js
|
|
100
|
-
|
|
101
|
-
const {withTV} = require("tailwind-variants/transformer");
|
|
102
|
-
|
|
103
|
-
/** @type {import('tailwindcss').Config} */
|
|
104
|
-
module.exports = withTV(
|
|
105
|
-
{
|
|
106
|
-
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
|
|
107
|
-
theme: {
|
|
108
|
-
extend: {},
|
|
109
|
-
},
|
|
110
|
-
plugins: [],
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
aliases: ["@/lib/tv"],
|
|
114
|
-
},
|
|
115
|
-
);
|
|
116
|
-
```
|
|
117
|
-
|
|
118
96
|
## Acknowledgements
|
|
119
97
|
|
|
120
98
|
- [**cva**](https://github.com/joe-bell/cva) ([Joe Bell](https://github.com/joe-bell))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkL4Q3BGWH_cjs = require('./chunk-L4Q3BGWH.cjs');
|
|
4
|
+
var tailwindMerge = require('tailwind-merge');
|
|
5
|
+
|
|
6
|
+
var createTwMerge = (cachedTwMergeConfig) => {
|
|
7
|
+
return chunkL4Q3BGWH_cjs.isEmptyObject(cachedTwMergeConfig) ? tailwindMerge.twMerge : tailwindMerge.extendTailwindMerge({
|
|
8
|
+
...cachedTwMergeConfig,
|
|
9
|
+
extend: {
|
|
10
|
+
theme: cachedTwMergeConfig.theme,
|
|
11
|
+
classGroups: cachedTwMergeConfig.classGroups,
|
|
12
|
+
conflictingClassGroupModifiers: cachedTwMergeConfig.conflictingClassGroupModifiers,
|
|
13
|
+
conflictingClassGroups: cachedTwMergeConfig.conflictingClassGroups,
|
|
14
|
+
...cachedTwMergeConfig.extend
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.createTwMerge = createTwMerge;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isEmptyObject } from './chunk-YWS777Q5.js';
|
|
2
|
+
import { twMerge, extendTailwindMerge } from 'tailwind-merge';
|
|
3
|
+
|
|
4
|
+
var createTwMerge = (cachedTwMergeConfig) => {
|
|
5
|
+
return isEmptyObject(cachedTwMergeConfig) ? twMerge : extendTailwindMerge({
|
|
6
|
+
...cachedTwMergeConfig,
|
|
7
|
+
extend: {
|
|
8
|
+
theme: cachedTwMergeConfig.theme,
|
|
9
|
+
classGroups: cachedTwMergeConfig.classGroups,
|
|
10
|
+
conflictingClassGroupModifiers: cachedTwMergeConfig.conflictingClassGroupModifiers,
|
|
11
|
+
conflictingClassGroups: cachedTwMergeConfig.conflictingClassGroups,
|
|
12
|
+
...cachedTwMergeConfig.extend
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { createTwMerge };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils.js
|
|
4
|
+
var falsyToString = (value) => value === false ? "false" : value === true ? "true" : value === 0 ? "0" : value;
|
|
5
|
+
var isEmptyObject = (obj) => {
|
|
6
|
+
if (!obj || typeof obj !== "object") return true;
|
|
7
|
+
for (const _ in obj) return false;
|
|
8
|
+
return true;
|
|
9
|
+
};
|
|
10
|
+
var isEqual = (obj1, obj2) => {
|
|
11
|
+
if (obj1 === obj2) return true;
|
|
12
|
+
if (!obj1 || !obj2) return false;
|
|
13
|
+
const keys1 = Object.keys(obj1);
|
|
14
|
+
const keys2 = Object.keys(obj2);
|
|
15
|
+
if (keys1.length !== keys2.length) return false;
|
|
16
|
+
for (let i = 0; i < keys1.length; i++) {
|
|
17
|
+
const key = keys1[i];
|
|
18
|
+
if (!keys2.includes(key)) return false;
|
|
19
|
+
if (obj1[key] !== obj2[key]) return false;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
var isBoolean = (value) => value === true || value === false;
|
|
24
|
+
function flat(arr, target) {
|
|
25
|
+
for (let i = 0; i < arr.length; i++) {
|
|
26
|
+
const el = arr[i];
|
|
27
|
+
if (Array.isArray(el)) flat(el, target);
|
|
28
|
+
else target.push(el);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function flatArray(arr) {
|
|
32
|
+
const flattened = [];
|
|
33
|
+
flat(arr, flattened);
|
|
34
|
+
return flattened;
|
|
35
|
+
}
|
|
36
|
+
var flatMergeArrays = (...arrays) => {
|
|
37
|
+
const result = [];
|
|
38
|
+
flat(arrays, result);
|
|
39
|
+
const filtered = [];
|
|
40
|
+
for (let i = 0; i < result.length; i++) {
|
|
41
|
+
if (result[i]) filtered.push(result[i]);
|
|
42
|
+
}
|
|
43
|
+
return filtered;
|
|
44
|
+
};
|
|
45
|
+
var mergeObjects = (obj1, obj2) => {
|
|
46
|
+
const result = {};
|
|
47
|
+
for (const key in obj1) {
|
|
48
|
+
const val1 = obj1[key];
|
|
49
|
+
if (key in obj2) {
|
|
50
|
+
const val2 = obj2[key];
|
|
51
|
+
if (Array.isArray(val1) || Array.isArray(val2)) {
|
|
52
|
+
result[key] = flatMergeArrays(val2, val1);
|
|
53
|
+
} else if (typeof val1 === "object" && typeof val2 === "object" && val1 && val2) {
|
|
54
|
+
result[key] = mergeObjects(val1, val2);
|
|
55
|
+
} else {
|
|
56
|
+
result[key] = val2 + " " + val1;
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
result[key] = val1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const key in obj2) {
|
|
63
|
+
if (!(key in obj1)) {
|
|
64
|
+
result[key] = obj2[key];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
};
|
|
69
|
+
var SPACE_REGEX = /\s+/g;
|
|
70
|
+
var removeExtraSpaces = (str) => {
|
|
71
|
+
if (!str || typeof str !== "string") return str;
|
|
72
|
+
return str.replace(SPACE_REGEX, " ").trim();
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
exports.falsyToString = falsyToString;
|
|
76
|
+
exports.flatArray = flatArray;
|
|
77
|
+
exports.flatMergeArrays = flatMergeArrays;
|
|
78
|
+
exports.isBoolean = isBoolean;
|
|
79
|
+
exports.isEmptyObject = isEmptyObject;
|
|
80
|
+
exports.isEqual = isEqual;
|
|
81
|
+
exports.mergeObjects = mergeObjects;
|
|
82
|
+
exports.removeExtraSpaces = removeExtraSpaces;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/utils.js
|
|
2
|
+
var falsyToString = (value) => value === false ? "false" : value === true ? "true" : value === 0 ? "0" : value;
|
|
3
|
+
var isEmptyObject = (obj) => {
|
|
4
|
+
if (!obj || typeof obj !== "object") return true;
|
|
5
|
+
for (const _ in obj) return false;
|
|
6
|
+
return true;
|
|
7
|
+
};
|
|
8
|
+
var isEqual = (obj1, obj2) => {
|
|
9
|
+
if (obj1 === obj2) return true;
|
|
10
|
+
if (!obj1 || !obj2) return false;
|
|
11
|
+
const keys1 = Object.keys(obj1);
|
|
12
|
+
const keys2 = Object.keys(obj2);
|
|
13
|
+
if (keys1.length !== keys2.length) return false;
|
|
14
|
+
for (let i = 0; i < keys1.length; i++) {
|
|
15
|
+
const key = keys1[i];
|
|
16
|
+
if (!keys2.includes(key)) return false;
|
|
17
|
+
if (obj1[key] !== obj2[key]) return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
21
|
+
var isBoolean = (value) => value === true || value === false;
|
|
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 target.push(el);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function flatArray(arr) {
|
|
30
|
+
const flattened = [];
|
|
31
|
+
flat(arr, flattened);
|
|
32
|
+
return flattened;
|
|
33
|
+
}
|
|
34
|
+
var flatMergeArrays = (...arrays) => {
|
|
35
|
+
const result = [];
|
|
36
|
+
flat(arrays, result);
|
|
37
|
+
const filtered = [];
|
|
38
|
+
for (let i = 0; i < result.length; i++) {
|
|
39
|
+
if (result[i]) filtered.push(result[i]);
|
|
40
|
+
}
|
|
41
|
+
return filtered;
|
|
42
|
+
};
|
|
43
|
+
var mergeObjects = (obj1, obj2) => {
|
|
44
|
+
const result = {};
|
|
45
|
+
for (const key in obj1) {
|
|
46
|
+
const val1 = obj1[key];
|
|
47
|
+
if (key in obj2) {
|
|
48
|
+
const val2 = obj2[key];
|
|
49
|
+
if (Array.isArray(val1) || Array.isArray(val2)) {
|
|
50
|
+
result[key] = flatMergeArrays(val2, val1);
|
|
51
|
+
} else if (typeof val1 === "object" && typeof val2 === "object" && val1 && val2) {
|
|
52
|
+
result[key] = mergeObjects(val1, val2);
|
|
53
|
+
} else {
|
|
54
|
+
result[key] = val2 + " " + val1;
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
result[key] = val1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const key in obj2) {
|
|
61
|
+
if (!(key in obj1)) {
|
|
62
|
+
result[key] = obj2[key];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
var SPACE_REGEX = /\s+/g;
|
|
68
|
+
var removeExtraSpaces = (str) => {
|
|
69
|
+
if (!str || typeof str !== "string") return str;
|
|
70
|
+
return str.replace(SPACE_REGEX, " ").trim();
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export { falsyToString, flatArray, flatMergeArrays, isBoolean, isEmptyObject, isEqual, mergeObjects, removeExtraSpaces };
|
package/dist/cn.cjs
ADDED
package/dist/cn.js
ADDED
package/dist/config.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type {extendTailwindMerge} from "tailwind-merge";
|
|
2
|
-
import type {TVVariants} from "./index";
|
|
3
|
-
import type {TVGeneratedScreens} from "./generated";
|
|
4
2
|
|
|
5
3
|
type MergeConfig = Parameters<typeof extendTailwindMerge>[0];
|
|
6
4
|
type LegacyMergeConfig = Extract<MergeConfig, {extend?: unknown}>["extend"];
|
|
@@ -20,19 +18,4 @@ export type TWMConfig = {
|
|
|
20
18
|
twMergeConfig?: MergeConfig & LegacyMergeConfig;
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
export type TVConfig
|
|
24
|
-
// @ts-expect-error
|
|
25
|
-
V extends TVVariants | undefined = undefined,
|
|
26
|
-
// @ts-expect-error
|
|
27
|
-
EV extends TVVariants | undefined = undefined,
|
|
28
|
-
> = {
|
|
29
|
-
/**
|
|
30
|
-
* Whether to enable responsive variant transform.
|
|
31
|
-
* Which variants or screens(breakpoints) for responsive variant transform.
|
|
32
|
-
* @default false
|
|
33
|
-
*/
|
|
34
|
-
responsiveVariants?:
|
|
35
|
-
| boolean
|
|
36
|
-
| TVGeneratedScreens[]
|
|
37
|
-
| {[K in keyof V | keyof EV]?: boolean | TVGeneratedScreens[]};
|
|
38
|
-
} & TWMConfig;
|
|
21
|
+
export type TVConfig = TWMConfig;
|
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,333 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkBDOHQXGU_cjs = require('./chunk-BDOHQXGU.cjs');
|
|
4
|
+
var chunkL4Q3BGWH_cjs = require('./chunk-L4Q3BGWH.cjs');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
// src/index.js
|
|
7
|
+
var defaultConfig = {
|
|
8
|
+
twMerge: true,
|
|
9
|
+
twMergeConfig: {},
|
|
10
|
+
responsiveVariants: false
|
|
11
|
+
};
|
|
12
|
+
var cnBase = (...classes) => {
|
|
13
|
+
const result = [];
|
|
14
|
+
flat(classes, result);
|
|
15
|
+
let str = "";
|
|
16
|
+
for (let i = 0; i < result.length; i++) {
|
|
17
|
+
if (result[i]) {
|
|
18
|
+
if (str) str += " ";
|
|
19
|
+
str += result[i];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return str || void 0;
|
|
23
|
+
};
|
|
24
|
+
function flat(arr, target) {
|
|
25
|
+
for (let i = 0; i < arr.length; i++) {
|
|
26
|
+
const el = arr[i];
|
|
27
|
+
if (Array.isArray(el)) flat(el, target);
|
|
28
|
+
else if (el) target.push(el);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
var cachedTwMerge = null;
|
|
32
|
+
var cachedTwMergeConfig = {};
|
|
33
|
+
var didTwMergeConfigChange = false;
|
|
34
|
+
var cn = (...classes) => (config) => {
|
|
35
|
+
const base = cnBase(classes);
|
|
36
|
+
if (!base || !config.twMerge) return base;
|
|
37
|
+
if (!cachedTwMerge || didTwMergeConfigChange) {
|
|
38
|
+
didTwMergeConfigChange = false;
|
|
39
|
+
cachedTwMerge = chunkBDOHQXGU_cjs.createTwMerge(cachedTwMergeConfig);
|
|
40
|
+
}
|
|
41
|
+
return cachedTwMerge(base) || void 0;
|
|
42
|
+
};
|
|
43
|
+
var joinObjects = (obj1, obj2) => {
|
|
44
|
+
for (const key in obj2) {
|
|
45
|
+
if (key in obj1) {
|
|
46
|
+
obj1[key] = cnBase(obj1[key], obj2[key]);
|
|
47
|
+
} else {
|
|
48
|
+
obj1[key] = obj2[key];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return obj1;
|
|
52
|
+
};
|
|
53
|
+
var tv = (options, configProp) => {
|
|
54
|
+
const {
|
|
55
|
+
extend = null,
|
|
56
|
+
slots: slotProps = {},
|
|
57
|
+
variants: variantsProps = {},
|
|
58
|
+
compoundVariants: compoundVariantsProps = [],
|
|
59
|
+
compoundSlots = [],
|
|
60
|
+
defaultVariants: defaultVariantsProps = {}
|
|
61
|
+
} = options;
|
|
62
|
+
const config = { ...defaultConfig, ...configProp };
|
|
63
|
+
const base = extend?.base ? cnBase(extend.base, options?.base) : options?.base;
|
|
64
|
+
const variants = extend?.variants && !chunkL4Q3BGWH_cjs.isEmptyObject(extend.variants) ? chunkL4Q3BGWH_cjs.mergeObjects(variantsProps, extend.variants) : variantsProps;
|
|
65
|
+
const defaultVariants = extend?.defaultVariants && !chunkL4Q3BGWH_cjs.isEmptyObject(extend.defaultVariants) ? { ...extend.defaultVariants, ...defaultVariantsProps } : defaultVariantsProps;
|
|
66
|
+
if (!chunkL4Q3BGWH_cjs.isEmptyObject(config.twMergeConfig) && !chunkL4Q3BGWH_cjs.isEqual(config.twMergeConfig, cachedTwMergeConfig)) {
|
|
67
|
+
didTwMergeConfigChange = true;
|
|
68
|
+
cachedTwMergeConfig = config.twMergeConfig;
|
|
69
|
+
}
|
|
70
|
+
const isExtendedSlotsEmpty = chunkL4Q3BGWH_cjs.isEmptyObject(extend?.slots);
|
|
71
|
+
const componentSlots = !chunkL4Q3BGWH_cjs.isEmptyObject(slotProps) ? {
|
|
72
|
+
// add "base" to the slots object
|
|
73
|
+
base: cnBase(options?.base, isExtendedSlotsEmpty && extend?.base),
|
|
74
|
+
...slotProps
|
|
75
|
+
} : {};
|
|
76
|
+
const slots = isExtendedSlotsEmpty ? componentSlots : joinObjects(
|
|
77
|
+
{ ...extend?.slots },
|
|
78
|
+
chunkL4Q3BGWH_cjs.isEmptyObject(componentSlots) ? { base: options?.base } : componentSlots
|
|
79
|
+
);
|
|
80
|
+
const compoundVariants = chunkL4Q3BGWH_cjs.isEmptyObject(extend?.compoundVariants) ? compoundVariantsProps : chunkL4Q3BGWH_cjs.flatMergeArrays(extend?.compoundVariants, compoundVariantsProps);
|
|
81
|
+
const component = (props) => {
|
|
82
|
+
if (chunkL4Q3BGWH_cjs.isEmptyObject(variants) && chunkL4Q3BGWH_cjs.isEmptyObject(slotProps) && isExtendedSlotsEmpty) {
|
|
83
|
+
return cn(base, props?.class, props?.className)(config);
|
|
84
|
+
}
|
|
85
|
+
if (compoundVariants && !Array.isArray(compoundVariants)) {
|
|
86
|
+
throw new TypeError(
|
|
87
|
+
`The "compoundVariants" prop must be an array. Received: ${typeof compoundVariants}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
if (compoundSlots && !Array.isArray(compoundSlots)) {
|
|
91
|
+
throw new TypeError(
|
|
92
|
+
`The "compoundSlots" prop must be an array. Received: ${typeof compoundSlots}`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
const getScreenVariantValues = (screen, screenVariantValue, acc = [], slotKey) => {
|
|
96
|
+
let result = acc;
|
|
97
|
+
if (typeof screenVariantValue === "string") {
|
|
98
|
+
const cleaned = chunkL4Q3BGWH_cjs.removeExtraSpaces(screenVariantValue);
|
|
99
|
+
const parts = cleaned.split(" ");
|
|
100
|
+
for (let i = 0; i < parts.length; i++) {
|
|
101
|
+
result.push(`${screen}:${parts[i]}`);
|
|
102
|
+
}
|
|
103
|
+
} else if (Array.isArray(screenVariantValue)) {
|
|
104
|
+
for (let i = 0; i < screenVariantValue.length; i++) {
|
|
105
|
+
result.push(`${screen}:${screenVariantValue[i]}`);
|
|
106
|
+
}
|
|
107
|
+
} else if (typeof screenVariantValue === "object" && typeof slotKey === "string") {
|
|
108
|
+
if (slotKey in screenVariantValue) {
|
|
109
|
+
const value = screenVariantValue[slotKey];
|
|
110
|
+
if (value && typeof value === "string") {
|
|
111
|
+
const fixedValue = chunkL4Q3BGWH_cjs.removeExtraSpaces(value);
|
|
112
|
+
const parts = fixedValue.split(" ");
|
|
113
|
+
const arr = [];
|
|
114
|
+
for (let i = 0; i < parts.length; i++) {
|
|
115
|
+
arr.push(`${screen}:${parts[i]}`);
|
|
116
|
+
}
|
|
117
|
+
result[slotKey] = result[slotKey] ? result[slotKey].concat(arr) : arr;
|
|
118
|
+
} else if (Array.isArray(value) && value.length > 0) {
|
|
119
|
+
const arr = [];
|
|
120
|
+
for (let i = 0; i < value.length; i++) {
|
|
121
|
+
arr.push(`${screen}:${value[i]}`);
|
|
122
|
+
}
|
|
123
|
+
result[slotKey] = arr;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
};
|
|
129
|
+
const getVariantValue = (variant, vrs = variants, slotKey = null, slotProps2 = null) => {
|
|
130
|
+
const variantObj = vrs[variant];
|
|
131
|
+
if (!variantObj || chunkL4Q3BGWH_cjs.isEmptyObject(variantObj)) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const variantProp = slotProps2?.[variant] ?? props?.[variant];
|
|
135
|
+
if (variantProp === null) return null;
|
|
136
|
+
const variantKey = chunkL4Q3BGWH_cjs.falsyToString(variantProp);
|
|
137
|
+
const responsiveVarsEnabled = Array.isArray(config.responsiveVariants) && config.responsiveVariants.length > 0 || config.responsiveVariants === true;
|
|
138
|
+
let defaultVariantProp = defaultVariants?.[variant];
|
|
139
|
+
let screenValues = [];
|
|
140
|
+
if (typeof variantKey === "object" && responsiveVarsEnabled) {
|
|
141
|
+
for (const [screen, screenVariantKey] of Object.entries(variantKey)) {
|
|
142
|
+
const screenVariantValue = variantObj[screenVariantKey];
|
|
143
|
+
if (screen === "initial") {
|
|
144
|
+
defaultVariantProp = screenVariantKey;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (Array.isArray(config.responsiveVariants) && !config.responsiveVariants.includes(screen)) {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
screenValues = getScreenVariantValues(screen, screenVariantValue, screenValues, slotKey);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const key = variantKey != null && typeof variantKey != "object" ? variantKey : chunkL4Q3BGWH_cjs.falsyToString(defaultVariantProp);
|
|
154
|
+
const value = variantObj[key || "false"];
|
|
155
|
+
if (typeof screenValues === "object" && typeof slotKey === "string" && screenValues[slotKey]) {
|
|
156
|
+
return joinObjects(screenValues, value);
|
|
157
|
+
}
|
|
158
|
+
if (screenValues.length > 0) {
|
|
159
|
+
screenValues.push(value);
|
|
160
|
+
if (slotKey === "base") {
|
|
161
|
+
return screenValues.join(" ");
|
|
162
|
+
}
|
|
163
|
+
return screenValues;
|
|
164
|
+
}
|
|
165
|
+
return value;
|
|
166
|
+
};
|
|
167
|
+
const getVariantClassNames = () => {
|
|
168
|
+
if (!variants) return null;
|
|
169
|
+
const keys = Object.keys(variants);
|
|
170
|
+
const result = [];
|
|
171
|
+
for (let i = 0; i < keys.length; i++) {
|
|
172
|
+
const value = getVariantValue(keys[i], variants);
|
|
173
|
+
if (value) result.push(value);
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
};
|
|
177
|
+
const getVariantClassNamesBySlotKey = (slotKey, slotProps2) => {
|
|
178
|
+
if (!variants || typeof variants !== "object") return null;
|
|
179
|
+
const result = [];
|
|
180
|
+
for (const variant in variants) {
|
|
181
|
+
const variantValue = getVariantValue(variant, variants, slotKey, slotProps2);
|
|
182
|
+
const value = slotKey === "base" && typeof variantValue === "string" ? variantValue : variantValue && variantValue[slotKey];
|
|
183
|
+
if (value) result.push(value);
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
};
|
|
187
|
+
const propsWithoutUndefined = {};
|
|
188
|
+
for (const prop in props) {
|
|
189
|
+
const value = props[prop];
|
|
190
|
+
if (value !== void 0) propsWithoutUndefined[prop] = value;
|
|
191
|
+
}
|
|
192
|
+
const getCompleteProps = (key, slotProps2) => {
|
|
193
|
+
const initialProp = typeof props?.[key] === "object" ? {
|
|
194
|
+
[key]: props[key]?.initial
|
|
195
|
+
} : {};
|
|
196
|
+
return {
|
|
197
|
+
...defaultVariants,
|
|
198
|
+
...propsWithoutUndefined,
|
|
199
|
+
...initialProp,
|
|
200
|
+
...slotProps2
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
const getCompoundVariantsValue = (cv = [], slotProps2) => {
|
|
204
|
+
const result = [];
|
|
205
|
+
const cvLength = cv.length;
|
|
206
|
+
for (let i = 0; i < cvLength; i++) {
|
|
207
|
+
const { class: tvClass, className: tvClassName, ...compoundVariantOptions } = cv[i];
|
|
208
|
+
let isValid = true;
|
|
209
|
+
const completeProps = getCompleteProps(null, slotProps2);
|
|
210
|
+
for (const key in compoundVariantOptions) {
|
|
211
|
+
const value = compoundVariantOptions[key];
|
|
212
|
+
const completePropsValue = completeProps[key];
|
|
213
|
+
if (Array.isArray(value)) {
|
|
214
|
+
if (!value.includes(completePropsValue)) {
|
|
215
|
+
isValid = false;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
} else {
|
|
219
|
+
if ((value == null || value === false) && (completePropsValue == null || completePropsValue === false))
|
|
220
|
+
continue;
|
|
221
|
+
if (completePropsValue !== value) {
|
|
222
|
+
isValid = false;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (isValid) {
|
|
228
|
+
if (tvClass) result.push(tvClass);
|
|
229
|
+
if (tvClassName) result.push(tvClassName);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return result;
|
|
233
|
+
};
|
|
234
|
+
const getCompoundVariantClassNamesBySlot = (slotProps2) => {
|
|
235
|
+
const compoundClassNames = getCompoundVariantsValue(compoundVariants, slotProps2);
|
|
236
|
+
if (!Array.isArray(compoundClassNames)) return compoundClassNames;
|
|
237
|
+
const result = {};
|
|
238
|
+
const cnFn = cn;
|
|
239
|
+
for (let i = 0; i < compoundClassNames.length; i++) {
|
|
240
|
+
const className = compoundClassNames[i];
|
|
241
|
+
if (typeof className === "string") {
|
|
242
|
+
result.base = cnFn(result.base, className)(config);
|
|
243
|
+
} else if (typeof className === "object") {
|
|
244
|
+
for (const slot in className) {
|
|
245
|
+
result[slot] = cnFn(result[slot], className[slot])(config);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return result;
|
|
250
|
+
};
|
|
251
|
+
const getCompoundSlotClassNameBySlot = (slotProps2) => {
|
|
252
|
+
if (compoundSlots.length < 1) return null;
|
|
253
|
+
const result = {};
|
|
254
|
+
const completeProps = getCompleteProps(null, slotProps2);
|
|
255
|
+
for (let i = 0; i < compoundSlots.length; i++) {
|
|
256
|
+
const {
|
|
257
|
+
slots: slots2 = [],
|
|
258
|
+
class: slotClass,
|
|
259
|
+
className: slotClassName,
|
|
260
|
+
...slotVariants
|
|
261
|
+
} = compoundSlots[i];
|
|
262
|
+
if (!chunkL4Q3BGWH_cjs.isEmptyObject(slotVariants)) {
|
|
263
|
+
let isValid = true;
|
|
264
|
+
for (const key in slotVariants) {
|
|
265
|
+
const completePropsValue = completeProps[key];
|
|
266
|
+
const slotVariantValue = slotVariants[key];
|
|
267
|
+
if (completePropsValue === void 0 || (Array.isArray(slotVariantValue) ? !slotVariantValue.includes(completePropsValue) : slotVariantValue !== completePropsValue)) {
|
|
268
|
+
isValid = false;
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (!isValid) continue;
|
|
273
|
+
}
|
|
274
|
+
for (let j = 0; j < slots2.length; j++) {
|
|
275
|
+
const slotName = slots2[j];
|
|
276
|
+
if (!result[slotName]) result[slotName] = [];
|
|
277
|
+
result[slotName].push([slotClass, slotClassName]);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
};
|
|
282
|
+
if (!chunkL4Q3BGWH_cjs.isEmptyObject(slotProps) || !isExtendedSlotsEmpty) {
|
|
283
|
+
const slotsFns = {};
|
|
284
|
+
if (typeof slots === "object" && !chunkL4Q3BGWH_cjs.isEmptyObject(slots)) {
|
|
285
|
+
const cnFn = cn;
|
|
286
|
+
for (const slotKey in slots) {
|
|
287
|
+
slotsFns[slotKey] = (slotProps2) => {
|
|
288
|
+
const compoundVariantClasses = getCompoundVariantClassNamesBySlot(slotProps2);
|
|
289
|
+
const compoundSlotClasses = getCompoundSlotClassNameBySlot(slotProps2);
|
|
290
|
+
return cnFn(
|
|
291
|
+
slots[slotKey],
|
|
292
|
+
getVariantClassNamesBySlotKey(slotKey, slotProps2),
|
|
293
|
+
compoundVariantClasses ? compoundVariantClasses[slotKey] : void 0,
|
|
294
|
+
compoundSlotClasses ? compoundSlotClasses[slotKey] : void 0,
|
|
295
|
+
slotProps2?.class,
|
|
296
|
+
slotProps2?.className
|
|
297
|
+
)(config);
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return slotsFns;
|
|
302
|
+
}
|
|
303
|
+
return cn(
|
|
304
|
+
base,
|
|
305
|
+
getVariantClassNames(),
|
|
306
|
+
getCompoundVariantsValue(compoundVariants),
|
|
307
|
+
props?.class,
|
|
308
|
+
props?.className
|
|
309
|
+
)(config);
|
|
310
|
+
};
|
|
311
|
+
const getVariantKeys = () => {
|
|
312
|
+
if (!variants || typeof variants !== "object") return;
|
|
313
|
+
return Object.keys(variants);
|
|
314
|
+
};
|
|
315
|
+
component.variantKeys = getVariantKeys();
|
|
316
|
+
component.extend = extend;
|
|
317
|
+
component.base = base;
|
|
318
|
+
component.slots = slots;
|
|
319
|
+
component.variants = variants;
|
|
320
|
+
component.defaultVariants = defaultVariants;
|
|
321
|
+
component.compoundSlots = compoundSlots;
|
|
322
|
+
component.compoundVariants = compoundVariants;
|
|
323
|
+
return component;
|
|
324
|
+
};
|
|
325
|
+
var createTV = (configProp) => {
|
|
326
|
+
return (options, config) => tv(options, config ? chunkL4Q3BGWH_cjs.mergeObjects(configProp, config) : configProp);
|
|
327
|
+
};
|
|
6
328
|
|
|
7
|
-
exports.cn =
|
|
8
|
-
exports.cnBase =
|
|
9
|
-
exports.createTV =
|
|
10
|
-
exports.defaultConfig =
|
|
11
|
-
exports.tv =
|
|
12
|
-
exports.voidEmpty = _;
|
|
329
|
+
exports.cn = cn;
|
|
330
|
+
exports.cnBase = cnBase;
|
|
331
|
+
exports.createTV = createTV;
|
|
332
|
+
exports.defaultConfig = defaultConfig;
|
|
333
|
+
exports.tv = tv;
|