@tokenami/css 0.0.22 → 0.0.24
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/index.cjs +21 -12
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +21 -12
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -69,25 +69,34 @@ var css = (baseStyles, ...overrides) => {
|
|
|
69
69
|
return overriddenStyles;
|
|
70
70
|
};
|
|
71
71
|
css[_LONGHANDS] = Tokenami.mapShorthandToLonghands;
|
|
72
|
-
css.compose = (
|
|
73
|
-
const
|
|
74
|
-
return function generate(
|
|
75
|
-
const cacheId = JSON.stringify({
|
|
76
|
-
|
|
72
|
+
css.compose = (config) => {
|
|
73
|
+
const { variants, responsiveVariants, ...baseStyles } = config;
|
|
74
|
+
return function generate(selectedVariants, ...overrides) {
|
|
75
|
+
const cacheId = JSON.stringify({
|
|
76
|
+
baseStyles,
|
|
77
|
+
variants,
|
|
78
|
+
responsiveVariants,
|
|
79
|
+
selectedVariants,
|
|
80
|
+
overrides
|
|
81
|
+
});
|
|
82
|
+
const cached = cache[cacheId];
|
|
77
83
|
if (cached)
|
|
78
84
|
return cached;
|
|
79
|
-
const variantStyles =
|
|
80
|
-
var _a;
|
|
85
|
+
const variantStyles = selectedVariants ? Object.entries(selectedVariants).flatMap(([key, variant]) => {
|
|
86
|
+
var _a, _b, _c;
|
|
81
87
|
if (!variant)
|
|
82
88
|
return [];
|
|
83
89
|
const [type, bp] = key.split("_").reverse();
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
if (bp) {
|
|
91
|
+
const styles2 = (_a = responsiveVariants == null ? void 0 : responsiveVariants[type]) == null ? void 0 : _a[variant];
|
|
92
|
+
return styles2 ? [convertToMediaStyles(bp, styles2)] : [];
|
|
93
|
+
} else {
|
|
94
|
+
const styles2 = (_c = (_b = variants || responsiveVariants) == null ? void 0 : _b[type]) == null ? void 0 : _c[variant];
|
|
95
|
+
return styles2 ? [styles2] : [];
|
|
96
|
+
}
|
|
88
97
|
}) : [];
|
|
89
98
|
const styles = css(baseStyles, ...variantStyles, ...overrides);
|
|
90
|
-
|
|
99
|
+
cache[cacheId] = styles;
|
|
91
100
|
return styles;
|
|
92
101
|
};
|
|
93
102
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -8,21 +8,22 @@ type VariantValue<T> = T extends 'true' | 'false' ? boolean : T;
|
|
|
8
8
|
type ReponsiveKey = Extract<keyof TokenamiFinalConfig['responsive'], string>;
|
|
9
9
|
type ResponsiveValue<T> = T extends string ? `${ReponsiveKey}_${T}` : never;
|
|
10
10
|
type Override = TokenamiProperties | false | undefined;
|
|
11
|
-
type Variants$1<C> = {
|
|
11
|
+
type Variants$1<C> = undefined extends C ? {} : {
|
|
12
12
|
[V in keyof C]?: VariantValue<keyof C[V]>;
|
|
13
13
|
};
|
|
14
|
-
type ResponsiveVariants<C> = {
|
|
14
|
+
type ResponsiveVariants<C> = undefined extends C ? {} : {
|
|
15
15
|
[V in keyof C]: {
|
|
16
16
|
[M in ResponsiveValue<V>]?: VariantValue<keyof C[V]>;
|
|
17
17
|
};
|
|
18
18
|
}[keyof C];
|
|
19
|
-
type
|
|
19
|
+
type ComposeCSS<V, R> = TokenamiProperties & {
|
|
20
|
+
variants?: V & VariantsConfig;
|
|
21
|
+
responsiveVariants?: R & VariantsConfig;
|
|
22
|
+
};
|
|
20
23
|
interface CSS {
|
|
21
24
|
[_LONGHANDS]?: typeof Tokenami.mapShorthandToLonghands;
|
|
22
25
|
(baseStyles: TokenamiProperties, ...overrides: Override[]): {};
|
|
23
|
-
compose: <V extends VariantsConfig | undefined, R>(
|
|
24
|
-
responsive: R & boolean;
|
|
25
|
-
}) => (variants?: SelectedVariants<V, R>, ...overrides: Override[]) => {};
|
|
26
|
+
compose: <V extends VariantsConfig | undefined, R extends VariantsConfig | undefined>(config: ComposeCSS<V, R>) => (selectedVariants?: Variants$1<V> & Variants$1<R> & ResponsiveVariants<R>, ...overrides: Override[]) => {};
|
|
26
27
|
}
|
|
27
28
|
declare const css: CSS;
|
|
28
29
|
declare function createCss(config: Tokenami.Config): CSS;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,21 +8,22 @@ type VariantValue<T> = T extends 'true' | 'false' ? boolean : T;
|
|
|
8
8
|
type ReponsiveKey = Extract<keyof TokenamiFinalConfig['responsive'], string>;
|
|
9
9
|
type ResponsiveValue<T> = T extends string ? `${ReponsiveKey}_${T}` : never;
|
|
10
10
|
type Override = TokenamiProperties | false | undefined;
|
|
11
|
-
type Variants$1<C> = {
|
|
11
|
+
type Variants$1<C> = undefined extends C ? {} : {
|
|
12
12
|
[V in keyof C]?: VariantValue<keyof C[V]>;
|
|
13
13
|
};
|
|
14
|
-
type ResponsiveVariants<C> = {
|
|
14
|
+
type ResponsiveVariants<C> = undefined extends C ? {} : {
|
|
15
15
|
[V in keyof C]: {
|
|
16
16
|
[M in ResponsiveValue<V>]?: VariantValue<keyof C[V]>;
|
|
17
17
|
};
|
|
18
18
|
}[keyof C];
|
|
19
|
-
type
|
|
19
|
+
type ComposeCSS<V, R> = TokenamiProperties & {
|
|
20
|
+
variants?: V & VariantsConfig;
|
|
21
|
+
responsiveVariants?: R & VariantsConfig;
|
|
22
|
+
};
|
|
20
23
|
interface CSS {
|
|
21
24
|
[_LONGHANDS]?: typeof Tokenami.mapShorthandToLonghands;
|
|
22
25
|
(baseStyles: TokenamiProperties, ...overrides: Override[]): {};
|
|
23
|
-
compose: <V extends VariantsConfig | undefined, R>(
|
|
24
|
-
responsive: R & boolean;
|
|
25
|
-
}) => (variants?: SelectedVariants<V, R>, ...overrides: Override[]) => {};
|
|
26
|
+
compose: <V extends VariantsConfig | undefined, R extends VariantsConfig | undefined>(config: ComposeCSS<V, R>) => (selectedVariants?: Variants$1<V> & Variants$1<R> & ResponsiveVariants<R>, ...overrides: Override[]) => {};
|
|
26
27
|
}
|
|
27
28
|
declare const css: CSS;
|
|
28
29
|
declare function createCss(config: Tokenami.Config): CSS;
|
package/dist/index.js
CHANGED
|
@@ -32,25 +32,34 @@ var css = (baseStyles, ...overrides) => {
|
|
|
32
32
|
return overriddenStyles;
|
|
33
33
|
};
|
|
34
34
|
css[_LONGHANDS] = Tokenami.mapShorthandToLonghands;
|
|
35
|
-
css.compose = (
|
|
36
|
-
const
|
|
37
|
-
return function generate(
|
|
38
|
-
const cacheId = JSON.stringify({
|
|
39
|
-
|
|
35
|
+
css.compose = (config) => {
|
|
36
|
+
const { variants, responsiveVariants, ...baseStyles } = config;
|
|
37
|
+
return function generate(selectedVariants, ...overrides) {
|
|
38
|
+
const cacheId = JSON.stringify({
|
|
39
|
+
baseStyles,
|
|
40
|
+
variants,
|
|
41
|
+
responsiveVariants,
|
|
42
|
+
selectedVariants,
|
|
43
|
+
overrides
|
|
44
|
+
});
|
|
45
|
+
const cached = cache[cacheId];
|
|
40
46
|
if (cached)
|
|
41
47
|
return cached;
|
|
42
|
-
const variantStyles =
|
|
43
|
-
var _a;
|
|
48
|
+
const variantStyles = selectedVariants ? Object.entries(selectedVariants).flatMap(([key, variant]) => {
|
|
49
|
+
var _a, _b, _c;
|
|
44
50
|
if (!variant)
|
|
45
51
|
return [];
|
|
46
52
|
const [type, bp] = key.split("_").reverse();
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
if (bp) {
|
|
54
|
+
const styles2 = (_a = responsiveVariants == null ? void 0 : responsiveVariants[type]) == null ? void 0 : _a[variant];
|
|
55
|
+
return styles2 ? [convertToMediaStyles(bp, styles2)] : [];
|
|
56
|
+
} else {
|
|
57
|
+
const styles2 = (_c = (_b = variants || responsiveVariants) == null ? void 0 : _b[type]) == null ? void 0 : _c[variant];
|
|
58
|
+
return styles2 ? [styles2] : [];
|
|
59
|
+
}
|
|
51
60
|
}) : [];
|
|
52
61
|
const styles = css(baseStyles, ...variantStyles, ...overrides);
|
|
53
|
-
|
|
62
|
+
cache[cacheId] = styles;
|
|
54
63
|
return styles;
|
|
55
64
|
};
|
|
56
65
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenami/css",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@tokenami/config": "0.0.
|
|
15
|
+
"@tokenami/config": "0.0.24"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"tsup": "^7.0.0",
|
|
19
19
|
"typescript": "^5.1.3",
|
|
20
20
|
"vitest": "^0.34.6",
|
|
21
|
-
"@tokenami/dev": "0.0.
|
|
21
|
+
"@tokenami/dev": "0.0.24"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"typescript": ">= 5",
|
|
25
|
-
"@tokenami/dev": "0.0.
|
|
25
|
+
"@tokenami/dev": "0.0.24"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsup",
|