css-variants 2.0.0 → 2.0.1
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/cjs/cv.js +17 -15
- package/dist/cjs/cv.js.map +1 -1
- package/dist/cjs/scv.js +20 -12
- package/dist/cjs/scv.js.map +1 -1
- package/dist/cjs/ssv.js +18 -10
- package/dist/cjs/ssv.js.map +1 -1
- package/dist/cjs/sv.js +14 -4
- package/dist/cjs/sv.js.map +1 -1
- package/dist/esm/cv.js +17 -15
- package/dist/esm/cv.js.map +1 -1
- package/dist/esm/scv.js +20 -12
- package/dist/esm/scv.js.map +1 -1
- package/dist/esm/ssv.js +18 -10
- package/dist/esm/ssv.js.map +1 -1
- package/dist/esm/sv.js +14 -4
- package/dist/esm/sv.js.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/utils/entries.d.ts +0 -1
- package/dist/cjs/utils/entries.js +0 -7
- package/dist/cjs/utils/entries.js.map +0 -1
- package/dist/esm/utils/entries.d.ts +0 -1
- package/dist/esm/utils/entries.js +0 -4
- package/dist/esm/utils/entries.js.map +0 -1
package/dist/cjs/cv.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cv = void 0;
|
|
4
4
|
const compact_1 = require("./utils/compact");
|
|
5
|
-
const entries_1 = require("./utils/entries");
|
|
6
5
|
const cx_1 = require("./cx");
|
|
7
6
|
/**
|
|
8
7
|
* Creates a class variant function that combines base classes, variants, compound variants, and default variants.
|
|
@@ -39,30 +38,33 @@ const cv = (config) => {
|
|
|
39
38
|
const { base, variants, compoundVariants, defaultVariants, classNameResolver = cx_1.cx } = config;
|
|
40
39
|
return (props) => {
|
|
41
40
|
const { className, ...rest } = props ?? {};
|
|
41
|
+
if (!variants)
|
|
42
|
+
return classNameResolver(base, className);
|
|
42
43
|
const mergedProps = { ...defaultVariants, ...(0, compact_1.compact)(rest) };
|
|
43
44
|
const classValues = [];
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
for (const [key, value] of (0, entries_1.entries)(mergedProps)) {
|
|
49
|
-
const classValue = variants[key][value];
|
|
50
|
-
if (classValue) {
|
|
51
|
-
classValues.push(classValue);
|
|
52
|
-
}
|
|
45
|
+
for (const key in mergedProps) {
|
|
46
|
+
const classValue = variants[key][mergedProps[key]];
|
|
47
|
+
if (classValue) {
|
|
48
|
+
classValues.push(classValue);
|
|
53
49
|
}
|
|
54
50
|
}
|
|
55
51
|
if (compoundVariants) {
|
|
56
52
|
for (const { className: classValue, ...compoundVariant } of compoundVariants) {
|
|
57
|
-
|
|
53
|
+
let matches = true;
|
|
54
|
+
for (const key in compoundVariant) {
|
|
55
|
+
const value = compoundVariant[key];
|
|
56
|
+
const propValue = mergedProps[key];
|
|
57
|
+
if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {
|
|
58
|
+
matches = false;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (matches) {
|
|
58
63
|
classValues.push(classValue);
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
}
|
|
62
|
-
|
|
63
|
-
classValues.push(className);
|
|
64
|
-
}
|
|
65
|
-
return classNameResolver(...classValues);
|
|
67
|
+
return classNameResolver(base, classValues, className);
|
|
66
68
|
};
|
|
67
69
|
};
|
|
68
70
|
exports.cv = cv;
|
package/dist/cjs/cv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cv.js","sourceRoot":"","sources":["../../src/cv.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"cv.js","sourceRoot":"","sources":["../../src/cv.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AACzC,6BAAqC;AAoBrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACI,MAAM,EAAE,GAA0B,CAAC,MAAM,EAAE,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AAC;gBACH,CAAC;gBACD,IAAI,OAAO,EAAE,CAAC;oBACZ,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,CAAC,CAAA;IACxD,CAAC,CAAA;AACH,CAAC,CAAA;AArCY,QAAA,EAAE,MAqCd;AAED,kBAAe,UAAE,CAAA"}
|
package/dist/cjs/scv.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.scv = void 0;
|
|
4
4
|
const cx_1 = require("./cx");
|
|
5
5
|
const compact_1 = require("./utils/compact");
|
|
6
|
-
const entries_1 = require("./utils/entries");
|
|
7
6
|
/**
|
|
8
7
|
* Creates a slot-based class variant function that manages class names for multiple slots with variants.
|
|
9
8
|
*
|
|
@@ -55,32 +54,41 @@ const scv = (config) => {
|
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
if (variants) {
|
|
58
|
-
for (const
|
|
59
|
-
const slotClassValue = variants[key]?.[
|
|
57
|
+
for (const key in mergedProps) {
|
|
58
|
+
const slotClassValue = variants[key]?.[mergedProps[key]];
|
|
60
59
|
if (slotClassValue) {
|
|
61
|
-
for (const
|
|
62
|
-
slotClassValues[slot].push(
|
|
60
|
+
for (const slot in slotClassValue) {
|
|
61
|
+
slotClassValues[slot].push(slotClassValue[slot]);
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
66
|
if (compoundVariants) {
|
|
68
67
|
for (const { classNames: slotClassValue, ...compoundVariant } of compoundVariants) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
let matches = true;
|
|
69
|
+
for (const key in compoundVariant) {
|
|
70
|
+
const value = compoundVariant[key];
|
|
71
|
+
const propValue = mergedProps[key];
|
|
72
|
+
if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {
|
|
73
|
+
matches = false;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (matches) {
|
|
78
|
+
for (const slot in slotClassValue) {
|
|
79
|
+
slotClassValues[slot].push(slotClassValue[slot]);
|
|
72
80
|
}
|
|
73
81
|
}
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
84
|
if (classNames) {
|
|
77
|
-
for (const
|
|
78
|
-
slotClassValues[slot].push(
|
|
85
|
+
for (const slot in classNames) {
|
|
86
|
+
slotClassValues[slot].push(classNames[slot]);
|
|
79
87
|
}
|
|
80
88
|
}
|
|
81
89
|
const result = {};
|
|
82
|
-
for (const
|
|
83
|
-
result[slot] = classNameResolver(
|
|
90
|
+
for (const slot in slotClassValues) {
|
|
91
|
+
result[slot] = classNameResolver(slotClassValues[slot]);
|
|
84
92
|
}
|
|
85
93
|
return result;
|
|
86
94
|
};
|
package/dist/cjs/scv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scv.js","sourceRoot":"","sources":["../../src/scv.ts"],"names":[],"mappings":";;;AACA,6BAAqC;AACrC,6CAAyC;
|
|
1
|
+
{"version":3,"file":"scv.js","sourceRoot":"","sources":["../../src/scv.ts"],"names":[],"mappings":";;;AACA,6BAAqC;AACrC,6CAAyC;AAuBzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACI,MAAM,GAAG,GAA8B,CAAC,MAAM,EAAE,EAAE;IACvD,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,GAAG,OAAE,EAAE,GAAG,MAAM,CAAA;IAEnG,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,IAAI,EAAE,CAAA;QAE3C,MAAM,WAAW,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,IAAA,iBAAO,E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AC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;wBAC5E,OAAO,GAAG,KAAK,CAAA;wBACf,MAAK;oBACP,CAAC;gBACH,CAAC;gBACD,IAAI,OAAO,EAAE,CAAC;oBACZ,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE,CAAC;wBAClC,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAA;oBAClD,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;gBAC9B,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;YAC9C,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,EAA4C,CAAA;QAE3D,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;YACnC,MAAM,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAA;QACzD,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC,CAAA;AA/DY,QAAA,GAAG,OA+Df;AAED,kBAAe,WAAG,CAAA"}
|
package/dist/cjs/ssv.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ssv = void 0;
|
|
4
4
|
const compact_1 = require("./utils/compact");
|
|
5
|
-
const entries_1 = require("./utils/entries");
|
|
6
5
|
/**
|
|
7
6
|
* Creates a slot-based style variant function that composes CSS properties based on variants and compound variants.
|
|
8
7
|
*
|
|
@@ -46,27 +45,36 @@ const ssv = (config) => {
|
|
|
46
45
|
result[slot] = base?.[slot] ?? {};
|
|
47
46
|
}
|
|
48
47
|
if (variants) {
|
|
49
|
-
for (const
|
|
50
|
-
const slotStyle = variants[key]?.[
|
|
48
|
+
for (const key in mergedProps) {
|
|
49
|
+
const slotStyle = variants[key]?.[mergedProps[key]];
|
|
51
50
|
if (slotStyle) {
|
|
52
|
-
for (const
|
|
53
|
-
result[slot] = { ...result[slot], ...
|
|
51
|
+
for (const slot in slotStyle) {
|
|
52
|
+
result[slot] = { ...result[slot], ...slotStyle[slot] };
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
if (compoundVariants) {
|
|
59
58
|
for (const { styles: slotStyle, ...compoundVariant } of compoundVariants) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
let matches = true;
|
|
60
|
+
for (const key in compoundVariant) {
|
|
61
|
+
const value = compoundVariant[key];
|
|
62
|
+
const propValue = mergedProps[key];
|
|
63
|
+
if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {
|
|
64
|
+
matches = false;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (matches) {
|
|
69
|
+
for (const slot in slotStyle) {
|
|
70
|
+
result[slot] = { ...result[slot], ...slotStyle[slot] };
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
if (styles) {
|
|
68
|
-
for (const
|
|
69
|
-
result[slot] = { ...result[slot], ...
|
|
76
|
+
for (const slot in styles) {
|
|
77
|
+
result[slot] = { ...result[slot], ...styles[slot] };
|
|
70
78
|
}
|
|
71
79
|
}
|
|
72
80
|
return result;
|
package/dist/cjs/ssv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssv.js","sourceRoot":"","sources":["../../src/ssv.ts"],"names":[],"mappings":";;;AACA,6CAAyC;
|
|
1
|
+
{"version":3,"file":"ssv.js","sourceRoot":"","sources":["../../src/ssv.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAsBzC;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,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;oBAClC,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;oBAElC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;wBAC5E,OAAO,GAAG,KAAK,CAAA;wBACf,MAAK;oBACP,CAAC;gBACH,CAAC;gBAED,IAAI,OAAO,EAAE,CAAC;oBACZ,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;wBAC7B,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,CAAA;oBACxD,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,MAAM,EAAE,CAAC;YACX,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;gBAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAA;YACrD,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC,CAAA;AAxDY,QAAA,GAAG,OAwDf;AAED,kBAAe,WAAG,CAAA"}
|
package/dist/cjs/sv.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sv = void 0;
|
|
4
4
|
const compact_1 = require("./utils/compact");
|
|
5
|
-
const entries_1 = require("./utils/entries");
|
|
6
5
|
/**
|
|
7
6
|
* Creates a style variant function based on the provided configuration.
|
|
8
7
|
*
|
|
@@ -35,11 +34,13 @@ const sv = (config) => {
|
|
|
35
34
|
const { base, variants, compoundVariants, defaultVariants } = config;
|
|
36
35
|
return (props) => {
|
|
37
36
|
const { style, ...rest } = props ?? {};
|
|
37
|
+
if (!variants)
|
|
38
|
+
return { ...base, ...style };
|
|
38
39
|
let result = { ...base };
|
|
39
40
|
const mergedProps = { ...defaultVariants, ...(0, compact_1.compact)(rest) };
|
|
40
41
|
if (variants) {
|
|
41
|
-
for (const
|
|
42
|
-
const s =
|
|
42
|
+
for (const key in mergedProps) {
|
|
43
|
+
const s = variants[key][mergedProps[key]];
|
|
43
44
|
if (s) {
|
|
44
45
|
result = { ...result, ...s };
|
|
45
46
|
}
|
|
@@ -47,7 +48,16 @@ const sv = (config) => {
|
|
|
47
48
|
}
|
|
48
49
|
if (compoundVariants) {
|
|
49
50
|
for (const { style: s, ...compoundVariant } of compoundVariants) {
|
|
50
|
-
|
|
51
|
+
let matches = true;
|
|
52
|
+
for (const key in compoundVariant) {
|
|
53
|
+
const value = compoundVariant[key];
|
|
54
|
+
const propValue = mergedProps[key];
|
|
55
|
+
if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {
|
|
56
|
+
matches = false;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (matches) {
|
|
51
61
|
result = { ...result, ...s };
|
|
52
62
|
}
|
|
53
63
|
}
|
package/dist/cjs/sv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sv.js","sourceRoot":"","sources":["../../src/sv.ts"],"names":[],"mappings":";;;AACA,6CAAyC;
|
|
1
|
+
{"version":3,"file":"sv.js","sourceRoot":"","sources":["../../src/sv.ts"],"names":[],"mappings":";;;AACA,6CAAyC;AAmBzC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACI,MAAM,EAAE,GAA0B,CAAC,MAAM,EAAE,EAAE;IAClD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,eAAe,EAAE,GAAG,MAAM,CAAA;IACpE,OAAO,CAAC,KAAK,EAAE,EA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,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,KAAK,EAAE,CAAA;QAClC,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC,CAAA;AA3CY,QAAA,EAAE,MA2Cd;AAED,kBAAe,UAAE,CAAA"}
|
package/dist/esm/cv.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { compact } from './utils/compact';
|
|
2
|
-
import { entries } from './utils/entries';
|
|
3
2
|
import { cx } from './cx';
|
|
4
3
|
/**
|
|
5
4
|
* Creates a class variant function that combines base classes, variants, compound variants, and default variants.
|
|
@@ -36,30 +35,33 @@ export const cv = (config) => {
|
|
|
36
35
|
const { base, variants, compoundVariants, defaultVariants, classNameResolver = cx } = config;
|
|
37
36
|
return (props) => {
|
|
38
37
|
const { className, ...rest } = props ?? {};
|
|
38
|
+
if (!variants)
|
|
39
|
+
return classNameResolver(base, className);
|
|
39
40
|
const mergedProps = { ...defaultVariants, ...compact(rest) };
|
|
40
41
|
const classValues = [];
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
for (const [key, value] of entries(mergedProps)) {
|
|
46
|
-
const classValue = variants[key][value];
|
|
47
|
-
if (classValue) {
|
|
48
|
-
classValues.push(classValue);
|
|
49
|
-
}
|
|
42
|
+
for (const key in mergedProps) {
|
|
43
|
+
const classValue = variants[key][mergedProps[key]];
|
|
44
|
+
if (classValue) {
|
|
45
|
+
classValues.push(classValue);
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
48
|
if (compoundVariants) {
|
|
53
49
|
for (const { className: classValue, ...compoundVariant } of compoundVariants) {
|
|
54
|
-
|
|
50
|
+
let matches = true;
|
|
51
|
+
for (const key in compoundVariant) {
|
|
52
|
+
const value = compoundVariant[key];
|
|
53
|
+
const propValue = mergedProps[key];
|
|
54
|
+
if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {
|
|
55
|
+
matches = false;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (matches) {
|
|
55
60
|
classValues.push(classValue);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
|
-
|
|
60
|
-
classValues.push(className);
|
|
61
|
-
}
|
|
62
|
-
return classNameResolver(...classValues);
|
|
64
|
+
return classNameResolver(base, classValues, className);
|
|
63
65
|
};
|
|
64
66
|
};
|
|
65
67
|
export default cv;
|
package/dist/esm/cv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cv.js","sourceRoot":"","sources":["../../src/cv.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"cv.js","sourceRoot":"","sources":["../../src/cv.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,EAAE,EAAc,MAAM,MAAM,CAAA;AAoBrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,EAAE,GAA0B,CAAC,MAAM,EAAE,EAAE;IAClD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,GAAG,EAAE,EAAE,GAAG,MAAM,CAAA;IAC5F,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,IAAI,EAAE,CAAA;QAE1C,IAAI,CAAC,QAAQ;YAAE,OAAO,iBAAiB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;QAExD,MAAM,WAAW,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,CAA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ries';
|
|
4
3
|
/**
|
|
5
4
|
* Creates a slot-based class variant function that manages class names for multiple slots with variants.
|
|
6
5
|
*
|
|
@@ -52,32 +51,41 @@ export const scv = (config) => {
|
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
if (variants) {
|
|
55
|
-
for (const
|
|
56
|
-
const slotClassValue = variants[key]?.[
|
|
54
|
+
for (const key in mergedProps) {
|
|
55
|
+
const slotClassValue = variants[key]?.[mergedProps[key]];
|
|
57
56
|
if (slotClassValue) {
|
|
58
|
-
for (const
|
|
59
|
-
slotClassValues[slot].push(
|
|
57
|
+
for (const slot in slotClassValue) {
|
|
58
|
+
slotClassValues[slot].push(slotClassValue[slot]);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
63
|
if (compoundVariants) {
|
|
65
64
|
for (const { classNames: slotClassValue, ...compoundVariant } of compoundVariants) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
let matches = true;
|
|
66
|
+
for (const key in compoundVariant) {
|
|
67
|
+
const value = compoundVariant[key];
|
|
68
|
+
const propValue = mergedProps[key];
|
|
69
|
+
if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {
|
|
70
|
+
matches = false;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (matches) {
|
|
75
|
+
for (const slot in slotClassValue) {
|
|
76
|
+
slotClassValues[slot].push(slotClassValue[slot]);
|
|
69
77
|
}
|
|
70
78
|
}
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
81
|
if (classNames) {
|
|
74
|
-
for (const
|
|
75
|
-
slotClassValues[slot].push(
|
|
82
|
+
for (const slot in classNames) {
|
|
83
|
+
slotClassValues[slot].push(classNames[slot]);
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
const result = {};
|
|
79
|
-
for (const
|
|
80
|
-
result[slot] = classNameResolver(
|
|
87
|
+
for (const slot in slotClassValues) {
|
|
88
|
+
result[slot] = classNameResolver(slotClassValues[slot]);
|
|
81
89
|
}
|
|
82
90
|
return result;
|
|
83
91
|
};
|
package/dist/esm/scv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scv.js","sourceRoot":"","sources":["../../src/scv.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAc,MAAM,MAAM,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"scv.js","sourceRoot":"","sources":["../../src/scv.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAc,MAAM,MAAM,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAuBzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,MAAM,GAAG,GAA8B,CAAC,MAAM,EAAE,EAAE;IACvD,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,GAAG,EAAE,EAAE,GAAG,MAAM,CAAA;IAEnG,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,IAAI,EAAE,CAAA;QAE3C,MAAM,WAAW,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;QAE5D,MAAM,eAAe,GAAG,EAAkD,CAAA;QAE1E,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;gBACjB,eAAe,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,I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CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;gBAC9B,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;YAC9C,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,EAA4C,CAAA;QAE3D,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;YACnC,MAAM,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAA;QACzD,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC,CAAA;AAED,eAAe,GAAG,CAAA"}
|
package/dist/esm/ssv.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { compact } from './utils/compact';
|
|
2
|
-
import { entries } from './utils/entries';
|
|
3
2
|
/**
|
|
4
3
|
* Creates a slot-based style variant function that composes CSS properties based on variants and compound variants.
|
|
5
4
|
*
|
|
@@ -43,27 +42,36 @@ export const ssv = (config) => {
|
|
|
43
42
|
result[slot] = base?.[slot] ?? {};
|
|
44
43
|
}
|
|
45
44
|
if (variants) {
|
|
46
|
-
for (const
|
|
47
|
-
const slotStyle = variants[key]?.[
|
|
45
|
+
for (const key in mergedProps) {
|
|
46
|
+
const slotStyle = variants[key]?.[mergedProps[key]];
|
|
48
47
|
if (slotStyle) {
|
|
49
|
-
for (const
|
|
50
|
-
result[slot] = { ...result[slot], ...
|
|
48
|
+
for (const slot in slotStyle) {
|
|
49
|
+
result[slot] = { ...result[slot], ...slotStyle[slot] };
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
if (compoundVariants) {
|
|
56
55
|
for (const { styles: slotStyle, ...compoundVariant } of compoundVariants) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
let matches = true;
|
|
57
|
+
for (const key in compoundVariant) {
|
|
58
|
+
const value = compoundVariant[key];
|
|
59
|
+
const propValue = mergedProps[key];
|
|
60
|
+
if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {
|
|
61
|
+
matches = false;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (matches) {
|
|
66
|
+
for (const slot in slotStyle) {
|
|
67
|
+
result[slot] = { ...result[slot], ...slotStyle[slot] };
|
|
60
68
|
}
|
|
61
69
|
}
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
if (styles) {
|
|
65
|
-
for (const
|
|
66
|
-
result[slot] = { ...result[slot], ...
|
|
73
|
+
for (const slot in styles) {
|
|
74
|
+
result[slot] = { ...result[slot], ...styles[slot] };
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
return result;
|
package/dist/esm/ssv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssv.js","sourceRoot":"","sources":["../../src/ssv.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"ssv.js","sourceRoot":"","sources":["../../src/ssv.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAsBzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,MAAM,GAAG,GAA8B,CAAC,MAAM,EAAE,EAAE;IACvD,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,eAAe,EAAE,GAAG,MAAM,CAAA;IAE3E,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,IAAI,EAAE,CAAA;QAEvC,MAAM,WAAW,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,OAA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K,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;wBAC7B,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,CAAA;oBACxD,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,MAAM,EAAE,CAAC;YACX,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;gBAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAA;YACrD,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC,CAAA;AAED,eAAe,GAAG,CAAA"}
|
package/dist/esm/sv.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { compact } from './utils/compact';
|
|
2
|
-
import { entries } from './utils/entries';
|
|
3
2
|
/**
|
|
4
3
|
* Creates a style variant function based on the provided configuration.
|
|
5
4
|
*
|
|
@@ -32,11 +31,13 @@ export const sv = (config) => {
|
|
|
32
31
|
const { base, variants, compoundVariants, defaultVariants } = config;
|
|
33
32
|
return (props) => {
|
|
34
33
|
const { style, ...rest } = props ?? {};
|
|
34
|
+
if (!variants)
|
|
35
|
+
return { ...base, ...style };
|
|
35
36
|
let result = { ...base };
|
|
36
37
|
const mergedProps = { ...defaultVariants, ...compact(rest) };
|
|
37
38
|
if (variants) {
|
|
38
|
-
for (const
|
|
39
|
-
const s =
|
|
39
|
+
for (const key in mergedProps) {
|
|
40
|
+
const s = variants[key][mergedProps[key]];
|
|
40
41
|
if (s) {
|
|
41
42
|
result = { ...result, ...s };
|
|
42
43
|
}
|
|
@@ -44,7 +45,16 @@ export const sv = (config) => {
|
|
|
44
45
|
}
|
|
45
46
|
if (compoundVariants) {
|
|
46
47
|
for (const { style: s, ...compoundVariant } of compoundVariants) {
|
|
47
|
-
|
|
48
|
+
let matches = true;
|
|
49
|
+
for (const key in compoundVariant) {
|
|
50
|
+
const value = compoundVariant[key];
|
|
51
|
+
const propValue = mergedProps[key];
|
|
52
|
+
if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {
|
|
53
|
+
matches = false;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (matches) {
|
|
48
58
|
result = { ...result, ...s };
|
|
49
59
|
}
|
|
50
60
|
}
|
package/dist/esm/sv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sv.js","sourceRoot":"","sources":["../../src/sv.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"sv.js","sourceRoot":"","sources":["../../src/sv.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAmBzC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,MAAM,EAAE,GAA0B,CAAC,MAAM,EAAE,EAAE;IAClD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,eAAe,EAAE,GAAG,MAAM,CAAA;IACpE,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,IAAI,EAAE,CAAA;QAEtC,IAAI,CAAC,QAAQ;YAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,EAAE,CAAA;QAE3C,IAAI,MAAM,GAAkB,EAAE,GAAG,IAAI,EAAE,CAAA;QAEvC,MAAM,WAAW,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,EAAE,CAAA;QAE5D,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;gBAC9B,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,GAAG,CAAW,CAAC,CAAA;gBACnD,IAAI,CAAC,EAAE,CAAC;oBACN,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,gBAAgB,EAAE,CAAC;YACrB,KAAK,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,eAAe,EAAE,IAAI,gBAAgB,EAAE,CAAC;gBAChE,IAAI,OAAO,GAAG,IAAI,CAAA;gBAClB,KAAK,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;oBAClC,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;oBAClC,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;oBAClC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;wBAC5E,OAAO,GAAG,KAAK,CAAA;wBACf,MAAK;oBACP,CAAC;gBACH,CAAC;gBACD,IAAI,OAAO,EAAE,CAAC;oBACZ,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;gBAC9B,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,KAAK,EAAE,CAAA;QAClC,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC,CAAA;AAED,eAAe,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function entries<T extends object, TK extends Extract<keyof T, string>, TV extends T[TK], TEntry extends [TK, TV]>(obj: T): TEntry[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entries.js","sourceRoot":"","sources":["../../../src/utils/entries.ts"],"names":[],"mappings":";;AAAA,0BAOC;AAPD,SAAgB,OAAO,CAKrB,GAAM;IACN,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAS,CAAC,CAAC,CAAa,CAAA;AACzE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function entries<T extends object, TK extends Extract<keyof T, string>, TV extends T[TK], TEntry extends [TK, TV]>(obj: T): TEntry[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entries.js","sourceRoot":"","sources":["../../../src/utils/entries.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,OAAO,CAKrB,GAAM;IACN,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAS,CAAC,CAAC,CAAa,CAAA;AACzE,CAAC"}
|