@tokenami/css 0.0.64 → 0.0.66

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
@@ -28,20 +28,17 @@ var cache = {
28
28
  limit: 500,
29
29
  cache: /* @__PURE__ */ new Map(),
30
30
  get(key) {
31
- if (!this.cache.has(key))
32
- return null;
33
31
  const value = this.cache.get(key);
32
+ if (!value)
33
+ return;
34
34
  this.cache.delete(key);
35
35
  this.cache.set(key, value);
36
36
  return value;
37
37
  },
38
38
  set(key, value) {
39
- if (this.cache.has(key)) {
40
- this.cache.delete(key);
41
- } else if (this.cache.size === this.limit) {
42
- const oldestKey = this.cache.keys().next().value;
43
- this.cache.delete(oldestKey);
44
- }
39
+ this.cache.delete(key);
40
+ if (this.cache.size === this.limit)
41
+ this.cache.delete(this.cache.keys().next().value);
45
42
  this.cache.set(key, value);
46
43
  }
47
44
  };
@@ -58,23 +55,21 @@ function createCss(config, options) {
58
55
  for (const originalStyles of allStyles) {
59
56
  if (!originalStyles)
60
57
  continue;
61
- for (const [key, value] of Object.entries(originalStyles)) {
62
- const tokenProperty2 = Tokenami__namespace.TokenProperty.safeParse(key);
63
- if (!tokenProperty2.success) {
58
+ for (let [key, value] of Object.entries(originalStyles)) {
59
+ if (!key.startsWith("--")) {
64
60
  overriddenStyles[key] = value;
65
61
  continue;
66
62
  }
67
- const parts = Tokenami__namespace.getTokenPropertySplit(tokenProperty2.output);
63
+ const tokenProperty2 = key;
64
+ const parts = Tokenami__namespace.getTokenPropertySplit(tokenProperty2);
68
65
  const cssProperties = Tokenami__namespace.getCSSPropertiesForAlias(parts.alias, config.aliases);
69
66
  for (const cssProperty of cssProperties) {
70
- const long = createLonghandProperty(tokenProperty2.output, cssProperty);
67
+ const longProperty = createLonghandProperty(tokenProperty2, cssProperty);
71
68
  const isNumber = typeof value === "number" && value > 0;
72
- const tokenPropertyLong = Tokenami__namespace.parseProperty(long, {
73
- escapeSpecialChars: globalOptions == null ? void 0 : globalOptions.escapeSpecialChars
74
- });
75
- overrideLonghands(overriddenStyles, tokenPropertyLong);
76
- overriddenStyles[tokenPropertyLong] = value;
77
- overriddenStyles[calcProperty(tokenPropertyLong)] = isNumber ? "/*on*/" : void 0;
69
+ const parsedProperty = Tokenami__namespace.parseProperty(longProperty, globalOptions);
70
+ overrideLonghands(overriddenStyles, parsedProperty);
71
+ overriddenStyles[parsedProperty] = value;
72
+ overriddenStyles[calcProperty(parsedProperty)] = isNumber ? "/*on*/" : void 0;
78
73
  }
79
74
  }
80
75
  }
@@ -83,30 +78,24 @@ function createCss(config, options) {
83
78
  };
84
79
  css2.compose = (config2) => {
85
80
  const { variants, responsiveVariants, ...baseStyles } = config2;
86
- return function generate(selectedVariants, ...overrides) {
87
- const cacheId = JSON.stringify({
88
- baseStyles,
89
- variants,
90
- responsiveVariants,
91
- selectedVariants,
92
- overrides
93
- });
81
+ return function generate(selectedVariants = {}, ...overrides) {
82
+ var _a, _b;
83
+ const cacheId = JSON.stringify({ config: config2, selectedVariants, overrides });
94
84
  const cached = cache.get(cacheId);
95
85
  if (cached)
96
86
  return cached;
97
- const variantStyles = selectedVariants ? Object.entries(selectedVariants).flatMap(([key, variant]) => {
98
- var _a, _b, _c;
87
+ let variantStyles = [];
88
+ for (const [key, variant] of Object.entries(selectedVariants)) {
99
89
  if (!variant)
100
- return [];
90
+ continue;
101
91
  const [type, bp] = key.split("_").reverse();
102
- if (bp) {
103
- const styles2 = (_a = responsiveVariants == null ? void 0 : responsiveVariants[type]) == null ? void 0 : _a[variant];
104
- return styles2 ? [convertToMediaStyles(bp, styles2)] : [];
92
+ const responsive = (_a = responsiveVariants == null ? void 0 : responsiveVariants[type]) == null ? void 0 : _a[variant];
93
+ if (bp && responsive) {
94
+ variantStyles.push(convertToMediaStyles(bp, responsive));
105
95
  } else {
106
- const styles2 = (_c = (_b = variants || responsiveVariants) == null ? void 0 : _b[type]) == null ? void 0 : _c[variant];
107
- return styles2 ? [styles2] : [];
96
+ variantStyles.push(((_b = variants == null ? void 0 : variants[type]) == null ? void 0 : _b[variant]) ?? responsive);
108
97
  }
109
- }) : [];
98
+ }
110
99
  const styles = css2(baseStyles, ...variantStyles, ...overrides);
111
100
  cache.set(cacheId, styles);
112
101
  return styles;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { TokenamiProperties, TokenamiFinalConfig } from '@tokenami/dev';
2
+ export { TokenamiProperties } from '@tokenami/dev';
2
3
  import * as Tokenami from '@tokenami/config';
3
4
  export { Config, createConfig } from '@tokenami/config';
4
5
 
@@ -39,8 +40,8 @@ type CreateCssOptions = {
39
40
  declare function createCss(config: Tokenami.Config, options?: CreateCssOptions): CSS;
40
41
  declare const css: CSS;
41
42
 
42
- type TokenamiStyle<P> = {
43
- [K in keyof P]: K extends 'style' ? TokenamiCSS & P[K] : P[K];
43
+ type TokenamiStyle<P> = Omit<P, 'style'> & {
44
+ style?: (TokenamiProperties | TokenamiCSS) & ('style' extends keyof P ? P['style'] : {});
44
45
  };
45
46
  type Variants<T extends (...args: any) => any> = Parameters<T>[0] extends undefined | null ? {} : NonNullable<Parameters<T>[0]>;
46
47
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { TokenamiProperties, TokenamiFinalConfig } from '@tokenami/dev';
2
+ export { TokenamiProperties } from '@tokenami/dev';
2
3
  import * as Tokenami from '@tokenami/config';
3
4
  export { Config, createConfig } from '@tokenami/config';
4
5
 
@@ -39,8 +40,8 @@ type CreateCssOptions = {
39
40
  declare function createCss(config: Tokenami.Config, options?: CreateCssOptions): CSS;
40
41
  declare const css: CSS;
41
42
 
42
- type TokenamiStyle<P> = {
43
- [K in keyof P]: K extends 'style' ? TokenamiCSS & P[K] : P[K];
43
+ type TokenamiStyle<P> = Omit<P, 'style'> & {
44
+ style?: (TokenamiProperties | TokenamiCSS) & ('style' extends keyof P ? P['style'] : {});
44
45
  };
45
46
  type Variants<T extends (...args: any) => any> = Parameters<T>[0] extends undefined | null ? {} : NonNullable<Parameters<T>[0]>;
46
47
 
package/dist/index.js CHANGED
@@ -7,20 +7,17 @@ var cache = {
7
7
  limit: 500,
8
8
  cache: /* @__PURE__ */ new Map(),
9
9
  get(key) {
10
- if (!this.cache.has(key))
11
- return null;
12
10
  const value = this.cache.get(key);
11
+ if (!value)
12
+ return;
13
13
  this.cache.delete(key);
14
14
  this.cache.set(key, value);
15
15
  return value;
16
16
  },
17
17
  set(key, value) {
18
- if (this.cache.has(key)) {
19
- this.cache.delete(key);
20
- } else if (this.cache.size === this.limit) {
21
- const oldestKey = this.cache.keys().next().value;
22
- this.cache.delete(oldestKey);
23
- }
18
+ this.cache.delete(key);
19
+ if (this.cache.size === this.limit)
20
+ this.cache.delete(this.cache.keys().next().value);
24
21
  this.cache.set(key, value);
25
22
  }
26
23
  };
@@ -37,23 +34,21 @@ function createCss(config, options) {
37
34
  for (const originalStyles of allStyles) {
38
35
  if (!originalStyles)
39
36
  continue;
40
- for (const [key, value] of Object.entries(originalStyles)) {
41
- const tokenProperty2 = Tokenami.TokenProperty.safeParse(key);
42
- if (!tokenProperty2.success) {
37
+ for (let [key, value] of Object.entries(originalStyles)) {
38
+ if (!key.startsWith("--")) {
43
39
  overriddenStyles[key] = value;
44
40
  continue;
45
41
  }
46
- const parts = Tokenami.getTokenPropertySplit(tokenProperty2.output);
42
+ const tokenProperty2 = key;
43
+ const parts = Tokenami.getTokenPropertySplit(tokenProperty2);
47
44
  const cssProperties = Tokenami.getCSSPropertiesForAlias(parts.alias, config.aliases);
48
45
  for (const cssProperty of cssProperties) {
49
- const long = createLonghandProperty(tokenProperty2.output, cssProperty);
46
+ const longProperty = createLonghandProperty(tokenProperty2, cssProperty);
50
47
  const isNumber = typeof value === "number" && value > 0;
51
- const tokenPropertyLong = Tokenami.parseProperty(long, {
52
- escapeSpecialChars: globalOptions == null ? void 0 : globalOptions.escapeSpecialChars
53
- });
54
- overrideLonghands(overriddenStyles, tokenPropertyLong);
55
- overriddenStyles[tokenPropertyLong] = value;
56
- overriddenStyles[calcProperty(tokenPropertyLong)] = isNumber ? "/*on*/" : void 0;
48
+ const parsedProperty = Tokenami.parseProperty(longProperty, globalOptions);
49
+ overrideLonghands(overriddenStyles, parsedProperty);
50
+ overriddenStyles[parsedProperty] = value;
51
+ overriddenStyles[calcProperty(parsedProperty)] = isNumber ? "/*on*/" : void 0;
57
52
  }
58
53
  }
59
54
  }
@@ -62,30 +57,24 @@ function createCss(config, options) {
62
57
  };
63
58
  css2.compose = (config2) => {
64
59
  const { variants, responsiveVariants, ...baseStyles } = config2;
65
- return function generate(selectedVariants, ...overrides) {
66
- const cacheId = JSON.stringify({
67
- baseStyles,
68
- variants,
69
- responsiveVariants,
70
- selectedVariants,
71
- overrides
72
- });
60
+ return function generate(selectedVariants = {}, ...overrides) {
61
+ var _a, _b;
62
+ const cacheId = JSON.stringify({ config: config2, selectedVariants, overrides });
73
63
  const cached = cache.get(cacheId);
74
64
  if (cached)
75
65
  return cached;
76
- const variantStyles = selectedVariants ? Object.entries(selectedVariants).flatMap(([key, variant]) => {
77
- var _a, _b, _c;
66
+ let variantStyles = [];
67
+ for (const [key, variant] of Object.entries(selectedVariants)) {
78
68
  if (!variant)
79
- return [];
69
+ continue;
80
70
  const [type, bp] = key.split("_").reverse();
81
- if (bp) {
82
- const styles2 = (_a = responsiveVariants == null ? void 0 : responsiveVariants[type]) == null ? void 0 : _a[variant];
83
- return styles2 ? [convertToMediaStyles(bp, styles2)] : [];
71
+ const responsive = (_a = responsiveVariants == null ? void 0 : responsiveVariants[type]) == null ? void 0 : _a[variant];
72
+ if (bp && responsive) {
73
+ variantStyles.push(convertToMediaStyles(bp, responsive));
84
74
  } else {
85
- const styles2 = (_c = (_b = variants || responsiveVariants) == null ? void 0 : _b[type]) == null ? void 0 : _c[variant];
86
- return styles2 ? [styles2] : [];
75
+ variantStyles.push(((_b = variants == null ? void 0 : variants[type]) == null ? void 0 : _b[variant]) ?? responsive);
87
76
  }
88
- }) : [];
77
+ }
89
78
  const styles = css2(baseStyles, ...variantStyles, ...overrides);
90
79
  cache.set(cacheId, styles);
91
80
  return styles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenami/css",
3
- "version": "0.0.64",
3
+ "version": "0.0.66",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -30,15 +30,14 @@
30
30
  "build": "tsup",
31
31
  "dev": "tsup --watch",
32
32
  "typecheck": "tsc --noEmit",
33
- "typecheck:ci": "tsc --noEmit",
34
33
  "test": "vitest --run",
35
34
  "test:watch": "vitest"
36
35
  },
37
36
  "dependencies": {
38
- "@tokenami/config": "0.0.64"
37
+ "@tokenami/config": "0.0.66"
39
38
  },
40
39
  "devDependencies": {
41
- "@tokenami/dev": "0.0.64",
40
+ "@tokenami/dev": "0.0.66",
42
41
  "tsup": "^7.0.0",
43
42
  "typescript": "^5.1.3",
44
43
  "vitest": "^0.34.6"
@@ -47,5 +46,5 @@
47
46
  "@tokenami/dev": ">= 0",
48
47
  "typescript": ">= 5"
49
48
  },
50
- "gitHead": "fd4d8ff6ba1164960836ee1df95192482ea7285d"
49
+ "gitHead": "1cc71d193a6de3a694eca1f28876219dc9b80524"
51
50
  }