@tokenami/css 0.0.22 → 0.0.23

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 CHANGED
@@ -69,25 +69,34 @@ var css = (baseStyles, ...overrides) => {
69
69
  return overriddenStyles;
70
70
  };
71
71
  css[_LONGHANDS] = Tokenami.mapShorthandToLonghands;
72
- css.compose = (baseStyles, variantsConfig, options) => {
73
- const cache2 = {};
74
- return function generate(variants, ...overrides) {
75
- const cacheId = JSON.stringify({ baseStyles, variants, overrides });
76
- const cached = cache2[cacheId];
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 = variants ? Object.entries(variants).flatMap(([key, variant]) => {
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
- const styles2 = (_a = variantsConfig == null ? void 0 : variantsConfig[type]) == null ? void 0 : _a[variant];
85
- const responsive = options == null ? void 0 : options.responsive;
86
- const updated = responsive && bp && styles2 ? convertToMediaStyles(bp, styles2) : styles2;
87
- return updated ? [updated] : [];
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
- cache2[cacheId] = styles;
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 SelectedVariants<V, R> = null | (undefined extends V ? null : Variants$1<V> & (R extends true ? ResponsiveVariants<V> : {}));
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>(baseStyles: TokenamiProperties, variantsConfig?: V & VariantsConfig, options?: undefined extends V ? never : {
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 SelectedVariants<V, R> = null | (undefined extends V ? null : Variants$1<V> & (R extends true ? ResponsiveVariants<V> : {}));
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>(baseStyles: TokenamiProperties, variantsConfig?: V & VariantsConfig, options?: undefined extends V ? never : {
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 = (baseStyles, variantsConfig, options) => {
36
- const cache2 = {};
37
- return function generate(variants, ...overrides) {
38
- const cacheId = JSON.stringify({ baseStyles, variants, overrides });
39
- const cached = cache2[cacheId];
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 = variants ? Object.entries(variants).flatMap(([key, variant]) => {
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
- const styles2 = (_a = variantsConfig == null ? void 0 : variantsConfig[type]) == null ? void 0 : _a[variant];
48
- const responsive = options == null ? void 0 : options.responsive;
49
- const updated = responsive && bp && styles2 ? convertToMediaStyles(bp, styles2) : styles2;
50
- return updated ? [updated] : [];
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
- cache2[cacheId] = styles;
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.22",
3
+ "version": "0.0.23",
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.22"
15
+ "@tokenami/config": "0.0.23"
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.22"
21
+ "@tokenami/dev": "0.0.23"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "typescript": ">= 5",
25
- "@tokenami/dev": "0.0.22"
25
+ "@tokenami/dev": "0.0.23"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "tsup",