@tokenami/css 0.0.36 → 0.0.37
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 +25 -5
- package/dist/index.js +25 -5
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -41,11 +41,31 @@ var import_config = require("@tokenami/config");
|
|
|
41
41
|
// src/css.ts
|
|
42
42
|
var Tokenami = __toESM(require("@tokenami/config"), 1);
|
|
43
43
|
var _ALIASES = Symbol();
|
|
44
|
-
var cache = {
|
|
44
|
+
var cache = {
|
|
45
|
+
limit: 500,
|
|
46
|
+
cache: /* @__PURE__ */ new Map(),
|
|
47
|
+
get(key) {
|
|
48
|
+
if (!this.cache.has(key))
|
|
49
|
+
return null;
|
|
50
|
+
const value = this.cache.get(key);
|
|
51
|
+
this.cache.delete(key);
|
|
52
|
+
this.cache.set(key, value);
|
|
53
|
+
return value;
|
|
54
|
+
},
|
|
55
|
+
set(key, value) {
|
|
56
|
+
if (this.cache.has(key)) {
|
|
57
|
+
this.cache.delete(key);
|
|
58
|
+
} else if (this.cache.size === this.limit) {
|
|
59
|
+
const oldestKey = this.cache.keys().next().value;
|
|
60
|
+
this.cache.delete(oldestKey);
|
|
61
|
+
}
|
|
62
|
+
this.cache.set(key, value);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
45
65
|
var css = (baseStyles, ...overrides) => {
|
|
46
66
|
let overriddenStyles = {};
|
|
47
67
|
const cacheId = JSON.stringify({ baseStyles, overrides });
|
|
48
|
-
const cached = cache
|
|
68
|
+
const cached = cache.get(cacheId);
|
|
49
69
|
if (cached)
|
|
50
70
|
return cached;
|
|
51
71
|
[baseStyles, ...overrides].forEach((originalStyles) => {
|
|
@@ -68,7 +88,7 @@ var css = (baseStyles, ...overrides) => {
|
|
|
68
88
|
});
|
|
69
89
|
});
|
|
70
90
|
});
|
|
71
|
-
cache
|
|
91
|
+
cache.set(cacheId, overriddenStyles);
|
|
72
92
|
return overriddenStyles;
|
|
73
93
|
};
|
|
74
94
|
css[_ALIASES] = {};
|
|
@@ -82,7 +102,7 @@ css.compose = (config) => {
|
|
|
82
102
|
selectedVariants,
|
|
83
103
|
overrides
|
|
84
104
|
});
|
|
85
|
-
const cached = cache
|
|
105
|
+
const cached = cache.get(cacheId);
|
|
86
106
|
if (cached)
|
|
87
107
|
return cached;
|
|
88
108
|
const variantStyles = selectedVariants ? Object.entries(selectedVariants).flatMap(([key, variant]) => {
|
|
@@ -99,7 +119,7 @@ css.compose = (config) => {
|
|
|
99
119
|
}
|
|
100
120
|
}) : [];
|
|
101
121
|
const styles = css(baseStyles, ...variantStyles, ...overrides);
|
|
102
|
-
cache
|
|
122
|
+
cache.set(cacheId, styles);
|
|
103
123
|
return styles;
|
|
104
124
|
};
|
|
105
125
|
};
|
package/dist/index.js
CHANGED
|
@@ -4,11 +4,31 @@ import { createConfig, defaultConfig } from "@tokenami/config";
|
|
|
4
4
|
// src/css.ts
|
|
5
5
|
import * as Tokenami from "@tokenami/config";
|
|
6
6
|
var _ALIASES = Symbol();
|
|
7
|
-
var cache = {
|
|
7
|
+
var cache = {
|
|
8
|
+
limit: 500,
|
|
9
|
+
cache: /* @__PURE__ */ new Map(),
|
|
10
|
+
get(key) {
|
|
11
|
+
if (!this.cache.has(key))
|
|
12
|
+
return null;
|
|
13
|
+
const value = this.cache.get(key);
|
|
14
|
+
this.cache.delete(key);
|
|
15
|
+
this.cache.set(key, value);
|
|
16
|
+
return value;
|
|
17
|
+
},
|
|
18
|
+
set(key, value) {
|
|
19
|
+
if (this.cache.has(key)) {
|
|
20
|
+
this.cache.delete(key);
|
|
21
|
+
} else if (this.cache.size === this.limit) {
|
|
22
|
+
const oldestKey = this.cache.keys().next().value;
|
|
23
|
+
this.cache.delete(oldestKey);
|
|
24
|
+
}
|
|
25
|
+
this.cache.set(key, value);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
8
28
|
var css = (baseStyles, ...overrides) => {
|
|
9
29
|
let overriddenStyles = {};
|
|
10
30
|
const cacheId = JSON.stringify({ baseStyles, overrides });
|
|
11
|
-
const cached = cache
|
|
31
|
+
const cached = cache.get(cacheId);
|
|
12
32
|
if (cached)
|
|
13
33
|
return cached;
|
|
14
34
|
[baseStyles, ...overrides].forEach((originalStyles) => {
|
|
@@ -31,7 +51,7 @@ var css = (baseStyles, ...overrides) => {
|
|
|
31
51
|
});
|
|
32
52
|
});
|
|
33
53
|
});
|
|
34
|
-
cache
|
|
54
|
+
cache.set(cacheId, overriddenStyles);
|
|
35
55
|
return overriddenStyles;
|
|
36
56
|
};
|
|
37
57
|
css[_ALIASES] = {};
|
|
@@ -45,7 +65,7 @@ css.compose = (config) => {
|
|
|
45
65
|
selectedVariants,
|
|
46
66
|
overrides
|
|
47
67
|
});
|
|
48
|
-
const cached = cache
|
|
68
|
+
const cached = cache.get(cacheId);
|
|
49
69
|
if (cached)
|
|
50
70
|
return cached;
|
|
51
71
|
const variantStyles = selectedVariants ? Object.entries(selectedVariants).flatMap(([key, variant]) => {
|
|
@@ -62,7 +82,7 @@ css.compose = (config) => {
|
|
|
62
82
|
}
|
|
63
83
|
}) : [];
|
|
64
84
|
const styles = css(baseStyles, ...variantStyles, ...overrides);
|
|
65
|
-
cache
|
|
85
|
+
cache.set(cacheId, styles);
|
|
66
86
|
return styles;
|
|
67
87
|
};
|
|
68
88
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenami/css",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
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.37"
|
|
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.37"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"typescript": ">= 5",
|
|
25
|
-
"@tokenami/dev": "0.0.
|
|
25
|
+
"@tokenami/dev": "0.0.37"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsup",
|