css-variants 2.2.2 → 2.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/dist/cv.cjs +2 -0
- package/dist/cv.cjs.map +1 -0
- package/dist/{esm/cv.d.ts → cv.d.cts} +13 -10
- package/dist/{cjs/cv.d.ts → cv.d.ts} +13 -10
- package/dist/cv.js +2 -0
- package/dist/cv.js.map +1 -0
- package/dist/cx.cjs +2 -0
- package/dist/cx.cjs.map +1 -0
- package/dist/cx.d.cts +6 -0
- package/dist/cx.d.ts +6 -0
- package/dist/cx.js +2 -0
- package/dist/cx.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/scv.cjs +2 -0
- package/dist/scv.cjs.map +1 -0
- package/dist/scv.d.cts +59 -0
- package/dist/scv.d.ts +59 -0
- package/dist/scv.js +2 -0
- package/dist/scv.js.map +1 -0
- package/dist/ssv.cjs +2 -0
- package/dist/ssv.cjs.map +1 -0
- package/dist/ssv.d.cts +54 -0
- package/dist/ssv.d.ts +54 -0
- package/dist/ssv.js +2 -0
- package/dist/ssv.js.map +1 -0
- package/dist/sv.cjs +2 -0
- package/dist/sv.cjs.map +1 -0
- package/dist/{cjs/sv.d.ts → sv.d.cts} +12 -9
- package/dist/{esm/sv.d.ts → sv.d.ts} +12 -9
- package/dist/sv.js +2 -0
- package/dist/sv.js.map +1 -0
- package/dist/types-BXKyjXhG.d.cts +16 -0
- package/dist/types-BXKyjXhG.d.ts +16 -0
- package/package.json +34 -13
- package/dist/cjs/cv.js +0 -75
- package/dist/cjs/cv.js.map +0 -1
- package/dist/cjs/cx.d.ts +0 -5
- package/dist/cjs/cx.js +0 -57
- package/dist/cjs/cx.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -5
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/scv.d.ts +0 -56
- package/dist/cjs/scv.js +0 -107
- package/dist/cjs/scv.js.map +0 -1
- package/dist/cjs/ssv.d.ts +0 -51
- package/dist/cjs/ssv.js +0 -94
- package/dist/cjs/ssv.js.map +0 -1
- package/dist/cjs/sv.js +0 -74
- package/dist/cjs/sv.js.map +0 -1
- package/dist/cjs/utils/merge-props.d.ts +0 -1
- package/dist/cjs/utils/merge-props.js +0 -15
- package/dist/cjs/utils/merge-props.js.map +0 -1
- package/dist/cjs/utils/types.d.ts +0 -16
- package/dist/cjs/utils/types.js +0 -3
- package/dist/cjs/utils/types.js.map +0 -1
- package/dist/esm/cv.js +0 -71
- package/dist/esm/cv.js.map +0 -1
- package/dist/esm/cx.d.ts +0 -5
- package/dist/esm/cx.js +0 -54
- package/dist/esm/cx.js.map +0 -1
- package/dist/esm/index.d.ts +0 -5
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/scv.d.ts +0 -56
- package/dist/esm/scv.js +0 -103
- package/dist/esm/scv.js.map +0 -1
- package/dist/esm/ssv.d.ts +0 -51
- package/dist/esm/ssv.js +0 -90
- package/dist/esm/ssv.js.map +0 -1
- package/dist/esm/sv.js +0 -70
- package/dist/esm/sv.js.map +0 -1
- package/dist/esm/utils/merge-props.d.ts +0 -1
- package/dist/esm/utils/merge-props.js +0 -12
- package/dist/esm/utils/merge-props.js.map +0 -1
- package/dist/esm/utils/types.d.ts +0 -16
- package/dist/esm/utils/types.js +0 -2
- package/dist/esm/utils/types.js.map +0 -1
package/dist/cjs/scv.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.scv = void 0;
|
|
4
|
-
const cx_1 = require("./cx");
|
|
5
|
-
const merge_props_1 = require("./utils/merge-props");
|
|
6
|
-
/**
|
|
7
|
-
* Creates a slot-based class variant function that manages class names for multiple slots with variants.
|
|
8
|
-
*
|
|
9
|
-
* @param config - Configuration object for creating the variant function
|
|
10
|
-
* @returns A function that accepts variant props and returns class names for each slot
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const button = scv({
|
|
15
|
-
* slots: ['root', 'icon'],
|
|
16
|
-
* base: {
|
|
17
|
-
* root: 'btn',
|
|
18
|
-
* icon: 'btn-icon'
|
|
19
|
-
* },
|
|
20
|
-
* variants: {
|
|
21
|
-
* size: {
|
|
22
|
-
* sm: {
|
|
23
|
-
* root: 'btn-sm',
|
|
24
|
-
* icon: 'icon-sm'
|
|
25
|
-
* },
|
|
26
|
-
* lg: {
|
|
27
|
-
* root: 'btn-lg',
|
|
28
|
-
* icon: 'icon-lg'
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* },
|
|
32
|
-
* defaultVariants: {
|
|
33
|
-
* size: 'sm'
|
|
34
|
-
* }
|
|
35
|
-
* })
|
|
36
|
-
*
|
|
37
|
-
* // Usage
|
|
38
|
-
* const classes = button({ size: 'lg' })
|
|
39
|
-
* // Result: { root: 'btn btn-lg', icon: 'btn-icon icon-lg' }
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
const scv = (config) => {
|
|
43
|
-
const { slots, base, variants, compoundVariants, defaultVariants, classNameResolver = cx_1.cx } = config;
|
|
44
|
-
if (!variants) {
|
|
45
|
-
return (props) => {
|
|
46
|
-
const result = {};
|
|
47
|
-
for (const slot of slots) {
|
|
48
|
-
result[slot] = classNameResolver(base?.[slot], props?.classNames?.[slot]);
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return (props) => {
|
|
54
|
-
const mergedProps = (0, merge_props_1.mergeProps)(defaultVariants, props, ['classNames']);
|
|
55
|
-
const slotClassValues = {};
|
|
56
|
-
for (const slot of slots) {
|
|
57
|
-
if (base?.[slot]) {
|
|
58
|
-
slotClassValues[slot] = Array.isArray(base[slot]) ? [...base[slot]] : [base[slot]];
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
slotClassValues[slot] = [];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
for (const key in mergedProps) {
|
|
65
|
-
const cls = variants[key]?.[mergedProps[key]];
|
|
66
|
-
if (cls) {
|
|
67
|
-
for (const slot in cls) {
|
|
68
|
-
slotClassValues[slot]?.push(cls[slot]);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (compoundVariants) {
|
|
73
|
-
for (let i = 0; i < compoundVariants.length; i++) {
|
|
74
|
-
const compound = compoundVariants[i];
|
|
75
|
-
let matches = true;
|
|
76
|
-
for (const key in compound) {
|
|
77
|
-
if (key === 'classNames')
|
|
78
|
-
continue;
|
|
79
|
-
const value = compound[key];
|
|
80
|
-
const propValue = mergedProps[key];
|
|
81
|
-
if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {
|
|
82
|
-
matches = false;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (matches && compound.classNames) {
|
|
87
|
-
for (const slot in compound.classNames) {
|
|
88
|
-
slotClassValues[slot]?.push(compound.classNames[slot]);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (props?.classNames) {
|
|
94
|
-
for (const slot in props.classNames) {
|
|
95
|
-
slotClassValues[slot]?.push(props.classNames[slot]);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const result = {};
|
|
99
|
-
for (const slot in slotClassValues) {
|
|
100
|
-
result[slot] = classNameResolver(slotClassValues[slot]);
|
|
101
|
-
}
|
|
102
|
-
return result;
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
exports.scv = scv;
|
|
106
|
-
exports.default = exports.scv;
|
|
107
|
-
//# sourceMappingURL=scv.js.map
|
package/dist/cjs/scv.js.map
DELETED
|
@@ -1 +0,0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AAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;oBACxD,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,KAAK,EAAE,UAAU,EAAE,CAAC;YACtB,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;gBACpC,eAAe,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;YACrD,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;AAzEY,QAAA,GAAG,OAyEf;AAED,kBAAe,WAAG,CAAA"}
|
package/dist/cjs/ssv.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ObjectKeyPicker, ObjectKeyArrayPicker, PartialRecord, CssProperties } from './utils/types';
|
|
2
|
-
export type SlotStyleRecord<S extends string> = PartialRecord<S, CssProperties>;
|
|
3
|
-
export type SlotStyleVariantRecord<S extends string> = Record<string, Record<string, SlotStyleRecord<S>>>;
|
|
4
|
-
export type SlotStyleVariantExtendProps<S extends string> = {
|
|
5
|
-
styles: SlotStyleRecord<S>;
|
|
6
|
-
};
|
|
7
|
-
export interface SlotStyleVariantDefinition<S extends string, T extends SlotStyleVariantRecord<S> | undefined> {
|
|
8
|
-
slots: S[];
|
|
9
|
-
base?: SlotStyleRecord<S>;
|
|
10
|
-
variants?: T;
|
|
11
|
-
compoundVariants?: (ObjectKeyArrayPicker<T> & SlotStyleVariantExtendProps<S>)[];
|
|
12
|
-
defaultVariants?: ObjectKeyPicker<T>;
|
|
13
|
-
}
|
|
14
|
-
export type SlotStyleVariantFnProps<S extends string, T extends SlotStyleVariantRecord<S> | undefined> = T extends undefined ? Partial<SlotStyleVariantExtendProps<S>> : ObjectKeyPicker<T> & Partial<SlotStyleVariantExtendProps<S>>;
|
|
15
|
-
export type SlotStyleVariantFn<S extends string, T extends SlotStyleVariantRecord<S> | undefined> = (props?: SlotStyleVariantFnProps<S, T>) => Record<S, CssProperties>;
|
|
16
|
-
export type SlotStyleVariantCreatorFn = <S extends string, T extends SlotStyleVariantRecord<S> | undefined>(config: SlotStyleVariantDefinition<S, T>) => SlotStyleVariantFn<S, T>;
|
|
17
|
-
/**
|
|
18
|
-
* Creates a slot-based style variant function that composes CSS properties based on variants and compound variants.
|
|
19
|
-
*
|
|
20
|
-
* @param config - Configuration object for creating style variants
|
|
21
|
-
* @returns A function that accepts variant props and returns composed styles for each slot
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const buttonStyles = csv({
|
|
26
|
-
* slots: ['root', 'icon'],
|
|
27
|
-
* base: {
|
|
28
|
-
* root: { padding: '8px' },
|
|
29
|
-
* icon: { size: '16px' }
|
|
30
|
-
* },
|
|
31
|
-
* variants: {
|
|
32
|
-
* size: {
|
|
33
|
-
* small: {
|
|
34
|
-
* root: { padding: '4px' },
|
|
35
|
-
* icon: { size: '12px' }
|
|
36
|
-
* },
|
|
37
|
-
* large: {
|
|
38
|
-
* root: { padding: '12px' },
|
|
39
|
-
* icon: { size: '20px' }
|
|
40
|
-
* }
|
|
41
|
-
* }
|
|
42
|
-
* }
|
|
43
|
-
* });
|
|
44
|
-
*
|
|
45
|
-
* // Usage
|
|
46
|
-
* const styles = buttonStyles({ size: 'small' });
|
|
47
|
-
* // => { root: { padding: '4px' }, icon: { size: '12px' } }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export declare const ssv: SlotStyleVariantCreatorFn;
|
|
51
|
-
export default ssv;
|
package/dist/cjs/ssv.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ssv = void 0;
|
|
4
|
-
const merge_props_1 = require("./utils/merge-props");
|
|
5
|
-
/**
|
|
6
|
-
* Creates a slot-based style variant function that composes CSS properties based on variants and compound variants.
|
|
7
|
-
*
|
|
8
|
-
* @param config - Configuration object for creating style variants
|
|
9
|
-
* @returns A function that accepts variant props and returns composed styles for each slot
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const buttonStyles = csv({
|
|
14
|
-
* slots: ['root', 'icon'],
|
|
15
|
-
* base: {
|
|
16
|
-
* root: { padding: '8px' },
|
|
17
|
-
* icon: { size: '16px' }
|
|
18
|
-
* },
|
|
19
|
-
* variants: {
|
|
20
|
-
* size: {
|
|
21
|
-
* small: {
|
|
22
|
-
* root: { padding: '4px' },
|
|
23
|
-
* icon: { size: '12px' }
|
|
24
|
-
* },
|
|
25
|
-
* large: {
|
|
26
|
-
* root: { padding: '12px' },
|
|
27
|
-
* icon: { size: '20px' }
|
|
28
|
-
* }
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* // Usage
|
|
34
|
-
* const styles = buttonStyles({ size: 'small' });
|
|
35
|
-
* // => { root: { padding: '4px' }, icon: { size: '12px' } }
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
const ssv = (config) => {
|
|
39
|
-
const { slots, base, variants, compoundVariants, defaultVariants } = config;
|
|
40
|
-
if (!variants) {
|
|
41
|
-
return (props) => {
|
|
42
|
-
const result = {};
|
|
43
|
-
for (const slot of slots) {
|
|
44
|
-
result[slot] = { ...base?.[slot], ...props?.styles?.[slot] };
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
return (props) => {
|
|
50
|
-
const mergedProps = (0, merge_props_1.mergeProps)(defaultVariants, props, ['styles']);
|
|
51
|
-
const result = {};
|
|
52
|
-
for (const slot of slots) {
|
|
53
|
-
result[slot] = { ...base?.[slot] };
|
|
54
|
-
}
|
|
55
|
-
for (const key in mergedProps) {
|
|
56
|
-
const slotStyle = variants[key]?.[mergedProps[key]];
|
|
57
|
-
if (slotStyle) {
|
|
58
|
-
for (const slot in slotStyle) {
|
|
59
|
-
Object.assign(result[slot], slotStyle[slot]);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (compoundVariants) {
|
|
64
|
-
for (let i = 0; i < compoundVariants.length; i++) {
|
|
65
|
-
const compound = compoundVariants[i];
|
|
66
|
-
let matches = true;
|
|
67
|
-
for (const key in compound) {
|
|
68
|
-
if (key === 'styles')
|
|
69
|
-
continue;
|
|
70
|
-
const value = compound[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 && compound.styles) {
|
|
78
|
-
for (const slot in compound.styles) {
|
|
79
|
-
Object.assign(result[slot], compound.styles[slot]);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
if (props?.styles) {
|
|
85
|
-
for (const slot in props.styles) {
|
|
86
|
-
Object.assign(result[slot], props.styles[slot]);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return result;
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
exports.ssv = ssv;
|
|
93
|
-
exports.default = exports.ssv;
|
|
94
|
-
//# sourceMappingURL=ssv.js.map
|
package/dist/cjs/ssv.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ssv.js","sourceRoot":"","sources":["../../src/ssv.ts"],"names":[],"mappings":";;;AACA,qDAAgD;AA+BhD;;;;;;;;;;;;;;;;;;;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QAAA,GAAG,OAkEf;AAED,kBAAe,WAAG,CAAA"}
|
package/dist/cjs/sv.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sv = void 0;
|
|
4
|
-
const merge_props_1 = require("./utils/merge-props");
|
|
5
|
-
/**
|
|
6
|
-
* Creates a style variant function based on the provided configuration.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of the style variant record.
|
|
9
|
-
* @param {StyleVariantDefinition<T>} config - The configuration object for style variants.
|
|
10
|
-
* @returns {StyleVariantFn<T>} A function that takes props and returns the computed CSS properties.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
*
|
|
15
|
-
* const makeStyle = sv({
|
|
16
|
-
* base: { color: 'black' },
|
|
17
|
-
* variants: {
|
|
18
|
-
* size: {
|
|
19
|
-
* small: { fontSize: '12px' },
|
|
20
|
-
* large: { fontSize: '24px' }
|
|
21
|
-
* }
|
|
22
|
-
* },
|
|
23
|
-
* compoundVariants: [
|
|
24
|
-
* { size: 'large', style: { fontWeight: 'bold' } }
|
|
25
|
-
* ],
|
|
26
|
-
* defaultVariants: { size: 'small' }
|
|
27
|
-
* });
|
|
28
|
-
*
|
|
29
|
-
* const style = makeStyle({ size: 'large' });
|
|
30
|
-
* // style = { color: 'black', fontSize: '24px', fontWeight: 'bold' }
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
const sv = (config) => {
|
|
34
|
-
const { base, variants, compoundVariants, defaultVariants } = config;
|
|
35
|
-
if (!variants) {
|
|
36
|
-
return (props) => ({ ...base, ...props?.style });
|
|
37
|
-
}
|
|
38
|
-
return (props) => {
|
|
39
|
-
const result = { ...base };
|
|
40
|
-
const mergedProps = (0, merge_props_1.mergeProps)(defaultVariants, props, ['style']);
|
|
41
|
-
for (const key in mergedProps) {
|
|
42
|
-
const styleValue = variants[key]?.[mergedProps[key]];
|
|
43
|
-
if (styleValue) {
|
|
44
|
-
Object.assign(result, styleValue);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (compoundVariants) {
|
|
48
|
-
for (let i = 0; i < compoundVariants.length; i++) {
|
|
49
|
-
const compound = compoundVariants[i];
|
|
50
|
-
let matches = true;
|
|
51
|
-
for (const key in compound) {
|
|
52
|
-
if (key === 'style')
|
|
53
|
-
continue;
|
|
54
|
-
const value = compound[key];
|
|
55
|
-
const propValue = mergedProps[key];
|
|
56
|
-
if (Array.isArray(value) ? !value.includes(propValue) : value !== propValue) {
|
|
57
|
-
matches = false;
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (matches && compound.style) {
|
|
62
|
-
Object.assign(result, compound.style);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (props?.style) {
|
|
67
|
-
Object.assign(result, props.style);
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
exports.sv = sv;
|
|
73
|
-
exports.default = exports.sv;
|
|
74
|
-
//# sourceMappingURL=sv.js.map
|
package/dist/cjs/sv.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sv.js","sourceRoot":"","sources":["../../src/sv.ts"],"names":[],"mappings":";;;AACA,qDAAgD;AAuBhD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACI,MAAM,EAAE,GAA0B,CAAC,MAAM,EAAE,EAAE;IAClD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,eAAe,EAAE,GAAG,MAAM,CAAA;IAEpE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IAClD,CAAC;IAED,OAAO,CAAC,KAA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gBACvC,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,KAAK,EAAE,KAAK,EAAE,CAAC;YACjB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;QACpC,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;AACH,CAAC,CAAA;AA5CY,QAAA,EAAE,MA4Cd;AAED,kBAAe,UAAE,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function mergeProps<T extends Record<string, unknown>, P extends Record<string, unknown>>(defaultProps: T | undefined, props: P | undefined, omitKeys?: (keyof P)[]): Record<string, unknown>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeProps = mergeProps;
|
|
4
|
-
function mergeProps(defaultProps, props, omitKeys) {
|
|
5
|
-
const merged = { ...defaultProps };
|
|
6
|
-
if (props) {
|
|
7
|
-
for (const k in props) {
|
|
8
|
-
if (props[k] !== undefined && (!omitKeys || !omitKeys.includes(k))) {
|
|
9
|
-
merged[k] = props[k];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return merged;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=merge-props.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merge-props.js","sourceRoot":"","sources":["../../../src/utils/merge-props.ts"],"names":[],"mappings":";;AAAA,gCAgBC;AAhBD,SAAgB,UAAU,CACxB,YAA2B,EAC3B,KAAoB,EACpB,QAAsB;IAEtB,MAAM,MAAM,GAA4B,EAAE,GAAG,YAAY,EAAE,CAAA;IAE3D,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACtB,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnE,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;YACtB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Properties } from 'csstype';
|
|
2
|
-
export type OneOrMore<T> = T | T[];
|
|
3
|
-
export type PartialRecord<S extends string, T> = Partial<Record<S, T>>;
|
|
4
|
-
export type RequireAtLeastOne<T> = {
|
|
5
|
-
[K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>;
|
|
6
|
-
}[keyof T];
|
|
7
|
-
export type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T;
|
|
8
|
-
export type ObjectKeyPicker<T> = [keyof T] extends [never] ? Record<string, unknown> : {
|
|
9
|
-
[K in keyof T]?: StringToBoolean<keyof T[K]> | undefined;
|
|
10
|
-
};
|
|
11
|
-
export type ObjectKeyArrayPicker<T> = [keyof T] extends [never] ? Record<string, unknown> : {
|
|
12
|
-
[K in keyof T]?: OneOrMore<StringToBoolean<keyof T[K]>> | undefined;
|
|
13
|
-
};
|
|
14
|
-
export type CssProperties = Properties<string | number> & {
|
|
15
|
-
[key: `--${string}`]: string | number;
|
|
16
|
-
};
|
package/dist/cjs/utils/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":""}
|
package/dist/esm/cv.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { cx } from './cx';
|
|
2
|
-
import { mergeProps } from './utils/merge-props';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a class variant function that combines base classes, variants, compound variants, and default variants.
|
|
5
|
-
*
|
|
6
|
-
* @template T - Type of the variant record
|
|
7
|
-
* @param config - Configuration object for creating class variants
|
|
8
|
-
* @returns A function that accepts variant props and returns a combined class string
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const button = cv({
|
|
13
|
-
* base: 'px-4 py-2 rounded',
|
|
14
|
-
* variants: {
|
|
15
|
-
* color: {
|
|
16
|
-
* primary: 'bg-blue-500 text-white',
|
|
17
|
-
* secondary: 'bg-gray-500 text-white'
|
|
18
|
-
* },
|
|
19
|
-
* size: {
|
|
20
|
-
* sm: 'text-sm',
|
|
21
|
-
* lg: 'text-lg'
|
|
22
|
-
* }
|
|
23
|
-
* },
|
|
24
|
-
* defaultVariants: {
|
|
25
|
-
* color: 'primary',
|
|
26
|
-
* size: 'sm'
|
|
27
|
-
* }
|
|
28
|
-
* });
|
|
29
|
-
*
|
|
30
|
-
* button(); // => 'px-4 py-2 rounded bg-blue-500 text-white text-sm'
|
|
31
|
-
* button({ color: 'secondary' }); // => 'px-4 py-2 rounded bg-gray-500 text-white text-sm'
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export const cv = (config) => {
|
|
35
|
-
const { base, variants, compoundVariants, defaultVariants, classNameResolver = cx } = config;
|
|
36
|
-
if (!variants) {
|
|
37
|
-
return (props) => classNameResolver(base, props?.className);
|
|
38
|
-
}
|
|
39
|
-
return (props) => {
|
|
40
|
-
const mergedProps = mergeProps(defaultVariants, props, ['className']);
|
|
41
|
-
const classValues = [];
|
|
42
|
-
for (const key in mergedProps) {
|
|
43
|
-
const classValue = variants[key]?.[mergedProps[key]];
|
|
44
|
-
if (classValue) {
|
|
45
|
-
classValues.push(classValue);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (compoundVariants) {
|
|
49
|
-
for (let i = 0; i < compoundVariants.length; i++) {
|
|
50
|
-
const compound = compoundVariants[i];
|
|
51
|
-
let matches = true;
|
|
52
|
-
for (const key in compound) {
|
|
53
|
-
if (key === 'className')
|
|
54
|
-
continue;
|
|
55
|
-
const value = compound[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 && compound.className) {
|
|
63
|
-
classValues.push(compound.className);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return classNameResolver(base, classValues, props?.className);
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
export default cv;
|
|
71
|
-
//# sourceMappingURL=cv.js.map
|
package/dist/esm/cv.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cv.js","sourceRoot":"","sources":["../../src/cv.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAc,MAAM,MAAM,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAwBhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;IAE5F,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;IAC7D,CAAC;IAED,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,WAAW,GAAG,UAAU,CAAC,eAAe,EAAE,KAAK,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;QAErE,MAAM,WAAW,GAAiB,EAAE,CAAA;QAEpC,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,MAAM,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,WAAW,CAAC,GAAG,CAAW,CAAC,CAAA;YAC9D,IAAI,UAAU,EAAE,CAAC;gBACf,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAC9B,CAAC;QACH,CAAC;QAED,IAAI,gBAAgB,EAAE,CAAC;YACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,gBAAgB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACjD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAA;gBACpC,IAAI,OAAO,GAAG,IAAI,CAAA;gBAClB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;oBAC3B,IAAI,GAAG,KAAK,WAAW;wBAAE,SAAQ;oBACjC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAA4B,CAAC,CAAA;oBACpD,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,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;oBAClC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;gBACtC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,iBAAiB,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;IAC/D,CAAC,CAAA;AACH,CAAC,CAAA;AAED,eAAe,EAAE,CAAA"}
|
package/dist/esm/cx.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export type ClassDictionary = Record<string, unknown>;
|
|
2
|
-
export type ClassValue = ClassValue[] | string | number | bigint | ClassDictionary | null | boolean | undefined;
|
|
3
|
-
export type ClassArray = ClassValue[];
|
|
4
|
-
export declare function cx(...args: ClassValue[]): string;
|
|
5
|
-
export default cx;
|
package/dist/esm/cx.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// credit: https://github.com/lukeed/clsx
|
|
2
|
-
function toVal(input) {
|
|
3
|
-
if (typeof input === 'string') {
|
|
4
|
-
return input;
|
|
5
|
-
}
|
|
6
|
-
if (typeof input === 'number' || typeof input === 'bigint') {
|
|
7
|
-
return String(input);
|
|
8
|
-
}
|
|
9
|
-
if (input === null || input === undefined || typeof input === 'boolean') {
|
|
10
|
-
return '';
|
|
11
|
-
}
|
|
12
|
-
let result = '';
|
|
13
|
-
if (Array.isArray(input)) {
|
|
14
|
-
let i = 0;
|
|
15
|
-
let tmpClassValue;
|
|
16
|
-
let tmpClassName;
|
|
17
|
-
for (; i < input.length; i++) {
|
|
18
|
-
if ((tmpClassValue = input[i])) {
|
|
19
|
-
if ((tmpClassName = toVal(tmpClassValue))) {
|
|
20
|
-
if (result)
|
|
21
|
-
result += ' ';
|
|
22
|
-
result += tmpClassName;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
for (const key in input) {
|
|
29
|
-
if (input[key]) {
|
|
30
|
-
if (result)
|
|
31
|
-
result += ' ';
|
|
32
|
-
result += key;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
export function cx(...args) {
|
|
38
|
-
let result = '';
|
|
39
|
-
let i = 0;
|
|
40
|
-
let tmpClassValue;
|
|
41
|
-
let tmpClassName;
|
|
42
|
-
for (; i < args.length; i++) {
|
|
43
|
-
if ((tmpClassValue = args[i])) {
|
|
44
|
-
if ((tmpClassName = toVal(tmpClassValue))) {
|
|
45
|
-
if (result)
|
|
46
|
-
result += ' ';
|
|
47
|
-
result += tmpClassName;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
export default cx;
|
|
54
|
-
//# sourceMappingURL=cx.js.map
|
package/dist/esm/cx.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cx.js","sourceRoot":"","sources":["../../src/cx.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAMzC,SAAS,KAAK,CAAC,KAAiB;IAC9B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC3D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACtB,CAAC;IAED,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QACxE,OAAO,EAAE,CAAA;IACX,CAAC;IAED,IAAI,MAAM,GAAG,EAAE,CAAA;IAEf,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,IAAI,aAAyB,CAAA;QAC7B,IAAI,YAAoB,CAAA;QACxB,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7B,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC/B,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC;oBAC1C,IAAI,MAAM;wBAAE,MAAM,IAAI,GAAG,CAAA;oBACzB,MAAM,IAAI,YAAY,CAAA;gBACxB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACf,IAAI,MAAM;gBAAE,MAAM,IAAI,GAAG,CAAA;YACzB,MAAM,IAAI,GAAG,CAAA;QACf,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,EAAE,CAAC,GAAG,IAAkB;IACtC,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,IAAI,aAAyB,CAAA;IAC7B,IAAI,YAAoB,CAAA;IAExB,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC;gBAC1C,IAAI,MAAM;oBAAE,MAAM,IAAI,GAAG,CAAA;gBACzB,MAAM,IAAI,YAAY,CAAA;YACxB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,eAAe,EAAE,CAAA"}
|
package/dist/esm/index.d.ts
DELETED
package/dist/esm/index.js
DELETED
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAA;AACpB,cAAc,MAAM,CAAA;AACpB,cAAc,OAAO,CAAA;AACrB,cAAc,MAAM,CAAA;AACpB,cAAc,OAAO,CAAA"}
|
package/dist/esm/scv.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { ObjectKeyPicker, ObjectKeyArrayPicker, PartialRecord } from './utils/types';
|
|
2
|
-
import { cx, ClassValue } from './cx';
|
|
3
|
-
export type SlotClassRecord<S extends string> = PartialRecord<S, ClassValue>;
|
|
4
|
-
export type SlotClassVariantRecord<S extends string> = Record<string, Record<string, SlotClassRecord<S>>>;
|
|
5
|
-
export type SlotClassVariantExtendProps<S extends string> = {
|
|
6
|
-
classNames: SlotClassRecord<S>;
|
|
7
|
-
};
|
|
8
|
-
export interface SlotClassVariantDefinition<S extends string, T extends SlotClassVariantRecord<S> | undefined> {
|
|
9
|
-
slots: S[];
|
|
10
|
-
base?: SlotClassRecord<S>;
|
|
11
|
-
variants?: T;
|
|
12
|
-
compoundVariants?: (ObjectKeyArrayPicker<T> & SlotClassVariantExtendProps<S>)[];
|
|
13
|
-
defaultVariants?: ObjectKeyPicker<T>;
|
|
14
|
-
classNameResolver?: typeof cx;
|
|
15
|
-
}
|
|
16
|
-
export type SlotClassVariantFnProps<S extends string, T extends SlotClassVariantRecord<S> | undefined> = T extends undefined ? Partial<SlotClassVariantExtendProps<S>> : ObjectKeyPicker<T> & Partial<SlotClassVariantExtendProps<S>>;
|
|
17
|
-
export type SlotClassVariantFn<S extends string, T extends SlotClassVariantRecord<S> | undefined> = (props?: SlotClassVariantFnProps<S, T>) => Record<S, string>;
|
|
18
|
-
export type SlotClassVariantCreatorFn = <S extends string, T extends SlotClassVariantRecord<S> | undefined>(config: SlotClassVariantDefinition<S, T>) => SlotClassVariantFn<S, T>;
|
|
19
|
-
/**
|
|
20
|
-
* Creates a slot-based class variant function that manages class names for multiple slots with variants.
|
|
21
|
-
*
|
|
22
|
-
* @param config - Configuration object for creating the variant function
|
|
23
|
-
* @returns A function that accepts variant props and returns class names for each slot
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* const button = scv({
|
|
28
|
-
* slots: ['root', 'icon'],
|
|
29
|
-
* base: {
|
|
30
|
-
* root: 'btn',
|
|
31
|
-
* icon: 'btn-icon'
|
|
32
|
-
* },
|
|
33
|
-
* variants: {
|
|
34
|
-
* size: {
|
|
35
|
-
* sm: {
|
|
36
|
-
* root: 'btn-sm',
|
|
37
|
-
* icon: 'icon-sm'
|
|
38
|
-
* },
|
|
39
|
-
* lg: {
|
|
40
|
-
* root: 'btn-lg',
|
|
41
|
-
* icon: 'icon-lg'
|
|
42
|
-
* }
|
|
43
|
-
* }
|
|
44
|
-
* },
|
|
45
|
-
* defaultVariants: {
|
|
46
|
-
* size: 'sm'
|
|
47
|
-
* }
|
|
48
|
-
* })
|
|
49
|
-
*
|
|
50
|
-
* // Usage
|
|
51
|
-
* const classes = button({ size: 'lg' })
|
|
52
|
-
* // Result: { root: 'btn btn-lg', icon: 'btn-icon icon-lg' }
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export declare const scv: SlotClassVariantCreatorFn;
|
|
56
|
-
export default scv;
|