@tokenami/css 0.0.99--canary.514.27870246935.0 → 0.0.99
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 +55 -55
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +55 -55
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -26,28 +26,28 @@ var Tokenami__namespace = /*#__PURE__*/_interopNamespace(Tokenami);
|
|
|
26
26
|
var _TOKENAMI_CSS = Symbol.for("@tokenami/css");
|
|
27
27
|
function createCss(config, options = { escapeSpecialChars: true }) {
|
|
28
28
|
globalThis[_TOKENAMI_CSS] = options;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
let cssCache = Tokenami__namespace.createLRUCache();
|
|
30
|
+
let propCache = Tokenami__namespace.createLRUCache();
|
|
31
|
+
let composeMap = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
let calcStore = /* @__PURE__ */ new Set();
|
|
33
33
|
function css2(...allStyles) {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
let id = generateSxId(allStyles);
|
|
35
|
+
let cached = cssCache.get(id);
|
|
36
36
|
if (cached) return cached;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
let opts = globalThis[_TOKENAMI_CSS];
|
|
38
|
+
let result = {};
|
|
39
|
+
let composeResult = {};
|
|
40
40
|
composeMap.set(result, composeResult);
|
|
41
41
|
function add(key, value, composed) {
|
|
42
|
-
|
|
42
|
+
let config2 = getProperty(key, opts);
|
|
43
43
|
if (!config2) {
|
|
44
44
|
result[key] = value;
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
for (
|
|
48
|
-
overrideLonghands(result, overrides);
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
for (let [prop, overrides] of config2) {
|
|
48
|
+
if (overrides.length) overrideLonghands(result, overrides);
|
|
49
|
+
let prop__calc = Tokenami__namespace.calcProperty(prop);
|
|
50
|
+
let target = composed && composeResult[prop] == null ? composeResult : result;
|
|
51
51
|
target[prop] = value;
|
|
52
52
|
if (composed) continue;
|
|
53
53
|
if (typeof value === "number" && value !== 0) {
|
|
@@ -60,63 +60,63 @@ function createCss(config, options = { escapeSpecialChars: true }) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
for (
|
|
63
|
+
for (let styles of allStyles) {
|
|
64
64
|
if (!styles) continue;
|
|
65
|
-
|
|
66
|
-
for (
|
|
67
|
-
for (
|
|
65
|
+
let composeSx = composeMap.get(styles) ?? {};
|
|
66
|
+
for (let key in composeSx) add(key, composeSx[key], true);
|
|
67
|
+
for (let key in styles) add(key, styles[key], composeSx[key] != null);
|
|
68
68
|
}
|
|
69
69
|
cssCache.set(id, result);
|
|
70
70
|
return result;
|
|
71
71
|
}
|
|
72
72
|
css2.compose = (input) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
let { includes = [], variants, ...composeSx } = input;
|
|
74
|
+
let cn = Tokenami__namespace.generateClassName(composeSx);
|
|
75
|
+
let cache = Tokenami__namespace.createLRUCache();
|
|
76
76
|
return function generate(currVariants = {}) {
|
|
77
77
|
let id = stringId(currVariants);
|
|
78
|
-
|
|
78
|
+
let cached = cache.get(id);
|
|
79
79
|
if (cached) return cached;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
let baseSx = {};
|
|
81
|
+
let variantSx = [];
|
|
82
|
+
let includeSx = [];
|
|
83
|
+
let includeCn = [];
|
|
84
|
+
for (let incl of includes) {
|
|
84
85
|
if (typeof incl === "function") {
|
|
85
|
-
|
|
86
|
+
let [cn2, sx] = incl(currVariants);
|
|
86
87
|
includeCn.push(cn2());
|
|
87
88
|
includeSx.push(sx());
|
|
88
89
|
} else {
|
|
89
90
|
includeSx.push(incl);
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
|
-
for (const
|
|
93
|
+
for (const key in currVariants) {
|
|
94
|
+
const variant = currVariants[key];
|
|
93
95
|
const group = variants?.[key];
|
|
94
96
|
const value = group?.[variant];
|
|
95
97
|
if (value) variantSx.push(value);
|
|
96
98
|
}
|
|
97
|
-
|
|
99
|
+
let result = [
|
|
98
100
|
(...cns) => [...includeCn, cn, ...cns].filter(Boolean).join(" "),
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
composeMap.set(base, baseSx);
|
|
102
|
-
return css2(...includeSx, base, ...variantSx, ...sx);
|
|
103
|
-
}
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
(...sx) => css2(...includeSx, baseSx, ...variantSx, ...sx)
|
|
104
103
|
];
|
|
104
|
+
composeMap.set(baseSx, composeSx);
|
|
105
105
|
cache.set(id, result);
|
|
106
106
|
return result;
|
|
107
107
|
};
|
|
108
108
|
};
|
|
109
109
|
function getProperty(key, opts) {
|
|
110
|
-
|
|
110
|
+
let cached = propCache.get(key);
|
|
111
111
|
if (cached !== void 0) return cached;
|
|
112
|
-
|
|
112
|
+
let tokenProperty = Tokenami__namespace.TokenProperty.safeParse(key);
|
|
113
113
|
if (!tokenProperty.success) return propCache.set(key, 0);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
for (
|
|
118
|
-
|
|
119
|
-
|
|
114
|
+
let parts = Tokenami__namespace.getTokenPropertySplit(tokenProperty.output);
|
|
115
|
+
let cssProperties = config.aliases?.[parts.alias] || [parts.alias];
|
|
116
|
+
let properties = [];
|
|
117
|
+
for (let cssProperty of cssProperties) {
|
|
118
|
+
let longProperty = Tokenami__namespace.createLonghandProperty(tokenProperty.output, cssProperty);
|
|
119
|
+
let parsedProperty = Tokenami__namespace.parseProperty(longProperty, opts);
|
|
120
120
|
properties.push([parsedProperty, getLonghandOverrides(parsedProperty)]);
|
|
121
121
|
}
|
|
122
122
|
propCache.set(key, properties);
|
|
@@ -124,9 +124,9 @@ function createCss(config, options = { escapeSpecialChars: true }) {
|
|
|
124
124
|
}
|
|
125
125
|
function generateSxId(objs) {
|
|
126
126
|
let id = "";
|
|
127
|
-
for (
|
|
127
|
+
for (let obj of objs) {
|
|
128
128
|
if (!obj) continue;
|
|
129
|
-
|
|
129
|
+
let composeSx = composeMap.get(obj);
|
|
130
130
|
if (composeSx) id += stringId(composeSx);
|
|
131
131
|
id += stringId(obj);
|
|
132
132
|
}
|
|
@@ -134,15 +134,15 @@ function createCss(config, options = { escapeSpecialChars: true }) {
|
|
|
134
134
|
}
|
|
135
135
|
function stringId(obj) {
|
|
136
136
|
let id = "";
|
|
137
|
-
for (
|
|
137
|
+
for (let key in obj) id += key + ":" + String(obj[key]) + ";";
|
|
138
138
|
return id;
|
|
139
139
|
}
|
|
140
140
|
function overrideLonghands(result, overrides) {
|
|
141
|
-
|
|
142
|
-
for (
|
|
143
|
-
|
|
141
|
+
let composeSx = composeMap.get(result);
|
|
142
|
+
for (let [longProp, calcProp] of overrides) {
|
|
143
|
+
let composeValue = composeSx?.[longProp];
|
|
144
144
|
if (composeValue) {
|
|
145
|
-
|
|
145
|
+
let value = composeValue ?? result[longProp];
|
|
146
146
|
if (typeof value === "number") result[calcProp] = "initial";
|
|
147
147
|
result[longProp] = "initial";
|
|
148
148
|
} else {
|
|
@@ -152,12 +152,12 @@ function createCss(config, options = { escapeSpecialChars: true }) {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
function getLonghandOverrides(tokenProperty) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
for (
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
let parts = Tokenami__namespace.getTokenPropertySplit(tokenProperty);
|
|
156
|
+
let longhands = Tokenami__namespace.mapShorthandToLonghands.get(parts.alias) || [];
|
|
157
|
+
let overrides = [];
|
|
158
|
+
for (let long of longhands) {
|
|
159
|
+
let longProp = Tokenami__namespace.createLonghandProperty(tokenProperty, long);
|
|
160
|
+
let calcProp = Tokenami__namespace.calcProperty(longProp);
|
|
161
161
|
overrides.push([longProp, calcProp], ...getLonghandOverrides(longProp));
|
|
162
162
|
}
|
|
163
163
|
return overrides;
|
package/dist/index.d.cts
CHANGED
|
@@ -41,7 +41,7 @@ declare function createCss(config: Pick<Tokenami.Config, 'aliases'>, options?: C
|
|
|
41
41
|
(allStyles_0: TokenamiProperties, ...allStyles_1: TokenamiOverride[]): TokenamiCSS;
|
|
42
42
|
compose<T>(input: TokenamiComposeInput<T>): TokenamiComposeOutput<T>;
|
|
43
43
|
};
|
|
44
|
-
declare
|
|
44
|
+
declare let css: {
|
|
45
45
|
(allStyles_0: TokenamiProperties, ...allStyles_1: TokenamiOverride[]): TokenamiCSS;
|
|
46
46
|
compose<T>(input: TokenamiComposeInput<T>): TokenamiComposeOutput<T>;
|
|
47
47
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ declare function createCss(config: Pick<Tokenami.Config, 'aliases'>, options?: C
|
|
|
41
41
|
(allStyles_0: TokenamiProperties, ...allStyles_1: TokenamiOverride[]): TokenamiCSS;
|
|
42
42
|
compose<T>(input: TokenamiComposeInput<T>): TokenamiComposeOutput<T>;
|
|
43
43
|
};
|
|
44
|
-
declare
|
|
44
|
+
declare let css: {
|
|
45
45
|
(allStyles_0: TokenamiProperties, ...allStyles_1: TokenamiOverride[]): TokenamiCSS;
|
|
46
46
|
compose<T>(input: TokenamiComposeInput<T>): TokenamiComposeOutput<T>;
|
|
47
47
|
};
|
package/dist/index.js
CHANGED
|
@@ -5,28 +5,28 @@ export { createConfig } from '@tokenami/config';
|
|
|
5
5
|
var _TOKENAMI_CSS = Symbol.for("@tokenami/css");
|
|
6
6
|
function createCss(config, options = { escapeSpecialChars: true }) {
|
|
7
7
|
globalThis[_TOKENAMI_CSS] = options;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
let cssCache = Tokenami.createLRUCache();
|
|
9
|
+
let propCache = Tokenami.createLRUCache();
|
|
10
|
+
let composeMap = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
let calcStore = /* @__PURE__ */ new Set();
|
|
12
12
|
function css2(...allStyles) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
let id = generateSxId(allStyles);
|
|
14
|
+
let cached = cssCache.get(id);
|
|
15
15
|
if (cached) return cached;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
let opts = globalThis[_TOKENAMI_CSS];
|
|
17
|
+
let result = {};
|
|
18
|
+
let composeResult = {};
|
|
19
19
|
composeMap.set(result, composeResult);
|
|
20
20
|
function add(key, value, composed) {
|
|
21
|
-
|
|
21
|
+
let config2 = getProperty(key, opts);
|
|
22
22
|
if (!config2) {
|
|
23
23
|
result[key] = value;
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
for (
|
|
27
|
-
overrideLonghands(result, overrides);
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
for (let [prop, overrides] of config2) {
|
|
27
|
+
if (overrides.length) overrideLonghands(result, overrides);
|
|
28
|
+
let prop__calc = Tokenami.calcProperty(prop);
|
|
29
|
+
let target = composed && composeResult[prop] == null ? composeResult : result;
|
|
30
30
|
target[prop] = value;
|
|
31
31
|
if (composed) continue;
|
|
32
32
|
if (typeof value === "number" && value !== 0) {
|
|
@@ -39,63 +39,63 @@ function createCss(config, options = { escapeSpecialChars: true }) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
for (
|
|
42
|
+
for (let styles of allStyles) {
|
|
43
43
|
if (!styles) continue;
|
|
44
|
-
|
|
45
|
-
for (
|
|
46
|
-
for (
|
|
44
|
+
let composeSx = composeMap.get(styles) ?? {};
|
|
45
|
+
for (let key in composeSx) add(key, composeSx[key], true);
|
|
46
|
+
for (let key in styles) add(key, styles[key], composeSx[key] != null);
|
|
47
47
|
}
|
|
48
48
|
cssCache.set(id, result);
|
|
49
49
|
return result;
|
|
50
50
|
}
|
|
51
51
|
css2.compose = (input) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
let { includes = [], variants, ...composeSx } = input;
|
|
53
|
+
let cn = Tokenami.generateClassName(composeSx);
|
|
54
|
+
let cache = Tokenami.createLRUCache();
|
|
55
55
|
return function generate(currVariants = {}) {
|
|
56
56
|
let id = stringId(currVariants);
|
|
57
|
-
|
|
57
|
+
let cached = cache.get(id);
|
|
58
58
|
if (cached) return cached;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
let baseSx = {};
|
|
60
|
+
let variantSx = [];
|
|
61
|
+
let includeSx = [];
|
|
62
|
+
let includeCn = [];
|
|
63
|
+
for (let incl of includes) {
|
|
63
64
|
if (typeof incl === "function") {
|
|
64
|
-
|
|
65
|
+
let [cn2, sx] = incl(currVariants);
|
|
65
66
|
includeCn.push(cn2());
|
|
66
67
|
includeSx.push(sx());
|
|
67
68
|
} else {
|
|
68
69
|
includeSx.push(incl);
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
|
-
for (const
|
|
72
|
+
for (const key in currVariants) {
|
|
73
|
+
const variant = currVariants[key];
|
|
72
74
|
const group = variants?.[key];
|
|
73
75
|
const value = group?.[variant];
|
|
74
76
|
if (value) variantSx.push(value);
|
|
75
77
|
}
|
|
76
|
-
|
|
78
|
+
let result = [
|
|
77
79
|
(...cns) => [...includeCn, cn, ...cns].filter(Boolean).join(" "),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
composeMap.set(base, baseSx);
|
|
81
|
-
return css2(...includeSx, base, ...variantSx, ...sx);
|
|
82
|
-
}
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
(...sx) => css2(...includeSx, baseSx, ...variantSx, ...sx)
|
|
83
82
|
];
|
|
83
|
+
composeMap.set(baseSx, composeSx);
|
|
84
84
|
cache.set(id, result);
|
|
85
85
|
return result;
|
|
86
86
|
};
|
|
87
87
|
};
|
|
88
88
|
function getProperty(key, opts) {
|
|
89
|
-
|
|
89
|
+
let cached = propCache.get(key);
|
|
90
90
|
if (cached !== void 0) return cached;
|
|
91
|
-
|
|
91
|
+
let tokenProperty = Tokenami.TokenProperty.safeParse(key);
|
|
92
92
|
if (!tokenProperty.success) return propCache.set(key, 0);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
for (
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
let parts = Tokenami.getTokenPropertySplit(tokenProperty.output);
|
|
94
|
+
let cssProperties = config.aliases?.[parts.alias] || [parts.alias];
|
|
95
|
+
let properties = [];
|
|
96
|
+
for (let cssProperty of cssProperties) {
|
|
97
|
+
let longProperty = Tokenami.createLonghandProperty(tokenProperty.output, cssProperty);
|
|
98
|
+
let parsedProperty = Tokenami.parseProperty(longProperty, opts);
|
|
99
99
|
properties.push([parsedProperty, getLonghandOverrides(parsedProperty)]);
|
|
100
100
|
}
|
|
101
101
|
propCache.set(key, properties);
|
|
@@ -103,9 +103,9 @@ function createCss(config, options = { escapeSpecialChars: true }) {
|
|
|
103
103
|
}
|
|
104
104
|
function generateSxId(objs) {
|
|
105
105
|
let id = "";
|
|
106
|
-
for (
|
|
106
|
+
for (let obj of objs) {
|
|
107
107
|
if (!obj) continue;
|
|
108
|
-
|
|
108
|
+
let composeSx = composeMap.get(obj);
|
|
109
109
|
if (composeSx) id += stringId(composeSx);
|
|
110
110
|
id += stringId(obj);
|
|
111
111
|
}
|
|
@@ -113,15 +113,15 @@ function createCss(config, options = { escapeSpecialChars: true }) {
|
|
|
113
113
|
}
|
|
114
114
|
function stringId(obj) {
|
|
115
115
|
let id = "";
|
|
116
|
-
for (
|
|
116
|
+
for (let key in obj) id += key + ":" + String(obj[key]) + ";";
|
|
117
117
|
return id;
|
|
118
118
|
}
|
|
119
119
|
function overrideLonghands(result, overrides) {
|
|
120
|
-
|
|
121
|
-
for (
|
|
122
|
-
|
|
120
|
+
let composeSx = composeMap.get(result);
|
|
121
|
+
for (let [longProp, calcProp] of overrides) {
|
|
122
|
+
let composeValue = composeSx?.[longProp];
|
|
123
123
|
if (composeValue) {
|
|
124
|
-
|
|
124
|
+
let value = composeValue ?? result[longProp];
|
|
125
125
|
if (typeof value === "number") result[calcProp] = "initial";
|
|
126
126
|
result[longProp] = "initial";
|
|
127
127
|
} else {
|
|
@@ -131,12 +131,12 @@ function createCss(config, options = { escapeSpecialChars: true }) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
function getLonghandOverrides(tokenProperty) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
for (
|
|
138
|
-
|
|
139
|
-
|
|
134
|
+
let parts = Tokenami.getTokenPropertySplit(tokenProperty);
|
|
135
|
+
let longhands = Tokenami.mapShorthandToLonghands.get(parts.alias) || [];
|
|
136
|
+
let overrides = [];
|
|
137
|
+
for (let long of longhands) {
|
|
138
|
+
let longProp = Tokenami.createLonghandProperty(tokenProperty, long);
|
|
139
|
+
let calcProp = Tokenami.calcProperty(longProp);
|
|
140
140
|
overrides.push([longProp, calcProp], ...getLonghandOverrides(longProp));
|
|
141
141
|
}
|
|
142
142
|
return overrides;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokenami/css",
|
|
3
|
-
"version": "0.0.99
|
|
3
|
+
"version": "0.0.99",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"typecheck": "tsc --noEmit"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@tokenami/config": "0.0.99
|
|
37
|
+
"@tokenami/config": "0.0.99"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"tokenami": "0.0.99
|
|
40
|
+
"tokenami": "0.0.99",
|
|
41
41
|
"tsup": "^8.4.0",
|
|
42
42
|
"typescript": "^5.1.3",
|
|
43
43
|
"vitest": "^3.2.6"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"tokenami": ">= 0",
|
|
47
47
|
"typescript": ">= 5"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "67c7e835e51a37c13a112d736a951f834e120d07"
|
|
50
50
|
}
|