boss-css 0.0.12 → 0.0.13
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/strategy/runtime-only/css.cjs +8 -1
- package/dist/strategy/runtime-only/css.mjs +8 -1
- package/dist/use/token/runtime-only.cjs +21 -3
- package/dist/use/token/runtime-only.mjs +21 -3
- package/dist/use/token/server.cjs +17 -15
- package/dist/use/token/server.mjs +17 -15
- package/package.json +1 -1
|
@@ -137,7 +137,14 @@ var RuntimeCSS = class {
|
|
|
137
137
|
return "";
|
|
138
138
|
}
|
|
139
139
|
addImport(_url) {}
|
|
140
|
-
addRoot(
|
|
140
|
+
addRoot(value, _source) {
|
|
141
|
+
if (!value) return;
|
|
142
|
+
if (this.root.has(value)) return;
|
|
143
|
+
this.root.add(value);
|
|
144
|
+
if (!canUseDom()) return;
|
|
145
|
+
const selector = typeof this.api.selectorScope === "string" && this.api.selectorScope.length > 0 ? this.api.selectorScope : ":root";
|
|
146
|
+
insertRule(`${selector} { ${value} }`, `root|${selector}|${value}`);
|
|
147
|
+
}
|
|
141
148
|
removeSource(_source) {}
|
|
142
149
|
reset() {}
|
|
143
150
|
selector({ className, selector = null, pseudos = [], query = null }) {
|
|
@@ -136,7 +136,14 @@ var RuntimeCSS = class {
|
|
|
136
136
|
return "";
|
|
137
137
|
}
|
|
138
138
|
addImport(_url) {}
|
|
139
|
-
addRoot(
|
|
139
|
+
addRoot(value, _source) {
|
|
140
|
+
if (!value) return;
|
|
141
|
+
if (this.root.has(value)) return;
|
|
142
|
+
this.root.add(value);
|
|
143
|
+
if (!canUseDom()) return;
|
|
144
|
+
const selector = typeof this.api.selectorScope === "string" && this.api.selectorScope.length > 0 ? this.api.selectorScope : ":root";
|
|
145
|
+
insertRule(`${selector} { ${value} }`, `root|${selector}|${value}`);
|
|
146
|
+
}
|
|
140
147
|
removeSource(_source) {}
|
|
141
148
|
reset() {}
|
|
142
149
|
selector({ className, selector = null, pseudos = [], query = null }) {
|
|
@@ -143,6 +143,11 @@ const getTokenPath = (api, prop, value) => {
|
|
|
143
143
|
selectorValue: value
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
+
if (resolveTokenParts(values, value.split(".")) !== void 0) return {
|
|
147
|
+
path: `${groupName}.${value}`,
|
|
148
|
+
source: "prop",
|
|
149
|
+
values
|
|
150
|
+
};
|
|
146
151
|
}
|
|
147
152
|
if (value in values) return {
|
|
148
153
|
path: `${groupName}.${value}`,
|
|
@@ -166,9 +171,22 @@ const resolveRuntimeToken = (api, prop, value) => {
|
|
|
166
171
|
const runtimeOnly = api.runtime?.only === true;
|
|
167
172
|
const hasServerToken = tokenPaths.has(tokenData.path);
|
|
168
173
|
const tokenKey = tokenData.selectorValue ?? tokenData.path.split(".").slice(1).join(".");
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
|
|
174
|
+
const varName = `--${api.selectorPrefix ?? ""}${tokenData.path.replace(/\./g, "-")}`;
|
|
175
|
+
const varValue = `var(${varName})`;
|
|
176
|
+
const mixValue = tokenData.alpha === void 0 ? null : `color-mix(in oklab, ${runtimeOnly || hasServerToken ? varValue : tokenValue} ${tokenData.alpha}%, transparent)`;
|
|
177
|
+
if (runtimeOnly) {
|
|
178
|
+
if (api.css && typeof api.css.addRoot === "function") {
|
|
179
|
+
const resolvedValue = api.dictionary.toValue(tokenValue);
|
|
180
|
+
if (resolvedValue !== void 0 && resolvedValue !== null) api.css.addRoot(`${varName}: ${resolvedValue};`);
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
value: mixValue ?? varValue,
|
|
184
|
+
selectorValue: tokenKey,
|
|
185
|
+
tokenKey,
|
|
186
|
+
tokenPath: tokenData.path
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (!hasServerToken) return {
|
|
172
190
|
value: mixValue ?? tokenValue,
|
|
173
191
|
selectorValue: tokenData.alpha === void 0 ? tokenValue : tokenKey,
|
|
174
192
|
tokenKey,
|
|
@@ -143,6 +143,11 @@ const getTokenPath = (api, prop, value) => {
|
|
|
143
143
|
selectorValue: value
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
+
if (resolveTokenParts(values, value.split(".")) !== void 0) return {
|
|
147
|
+
path: `${groupName}.${value}`,
|
|
148
|
+
source: "prop",
|
|
149
|
+
values
|
|
150
|
+
};
|
|
146
151
|
}
|
|
147
152
|
if (value in values) return {
|
|
148
153
|
path: `${groupName}.${value}`,
|
|
@@ -166,9 +171,22 @@ const resolveRuntimeToken = (api, prop, value) => {
|
|
|
166
171
|
const runtimeOnly = api.runtime?.only === true;
|
|
167
172
|
const hasServerToken = tokenPaths.has(tokenData.path);
|
|
168
173
|
const tokenKey = tokenData.selectorValue ?? tokenData.path.split(".").slice(1).join(".");
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
|
|
174
|
+
const varName = `--${api.selectorPrefix ?? ""}${tokenData.path.replace(/\./g, "-")}`;
|
|
175
|
+
const varValue = `var(${varName})`;
|
|
176
|
+
const mixValue = tokenData.alpha === void 0 ? null : `color-mix(in oklab, ${runtimeOnly || hasServerToken ? varValue : tokenValue} ${tokenData.alpha}%, transparent)`;
|
|
177
|
+
if (runtimeOnly) {
|
|
178
|
+
if (api.css && typeof api.css.addRoot === "function") {
|
|
179
|
+
const resolvedValue = api.dictionary.toValue(tokenValue);
|
|
180
|
+
if (resolvedValue !== void 0 && resolvedValue !== null) api.css.addRoot(`${varName}: ${resolvedValue};`);
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
value: mixValue ?? varValue,
|
|
184
|
+
selectorValue: tokenKey,
|
|
185
|
+
tokenKey,
|
|
186
|
+
tokenPath: tokenData.path
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (!hasServerToken) return {
|
|
172
190
|
value: mixValue ?? tokenValue,
|
|
173
191
|
selectorValue: tokenData.alpha === void 0 ? tokenValue : tokenKey,
|
|
174
192
|
tokenKey,
|
|
@@ -79,6 +79,22 @@ const warnAlpha = (message) => {
|
|
|
79
79
|
alphaWarnings.add(message);
|
|
80
80
|
console.warn(`[boss-css] ${message}`);
|
|
81
81
|
};
|
|
82
|
+
const emitAllTokenVars = (api) => {
|
|
83
|
+
if (emittedAllTokens) return;
|
|
84
|
+
emittedAllTokens = true;
|
|
85
|
+
hasTokens = true;
|
|
86
|
+
const addTokenVars = (prefix, value) => {
|
|
87
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
88
|
+
for (const [key, next] of Object.entries(value)) addTokenVars(prefix ? `${prefix}.${key}` : key, next);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!prefix) return;
|
|
92
|
+
const varName = `--${api.selectorPrefix ?? ""}${prefix.replace(/\./g, "-")}`;
|
|
93
|
+
api.css.addRoot(`${varName}: ${api.dictionary.toValue(value)};`);
|
|
94
|
+
browserResolvedPaths.add(prefix);
|
|
95
|
+
};
|
|
96
|
+
for (const [group, value] of Object.entries(originals)) addTokenVars(group, value);
|
|
97
|
+
};
|
|
82
98
|
const onBoot = async (api) => {
|
|
83
99
|
hasTokens = false;
|
|
84
100
|
hasProxyTokens = false;
|
|
@@ -230,21 +246,7 @@ const onPropTree = async (api, { tree, parser }) => {
|
|
|
230
246
|
hasTokenOverrides = true;
|
|
231
247
|
hasTokens = true;
|
|
232
248
|
}
|
|
233
|
-
if (api.emitAllTokens
|
|
234
|
-
emittedAllTokens = true;
|
|
235
|
-
hasTokens = true;
|
|
236
|
-
const addTokenVars = (prefix, value) => {
|
|
237
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
238
|
-
for (const [key, next] of Object.entries(value)) addTokenVars(prefix ? `${prefix}.${key}` : key, next);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if (!prefix) return;
|
|
242
|
-
const varName = `--${api.selectorPrefix ?? ""}${prefix.replace(/\./g, "-")}`;
|
|
243
|
-
api.css.addRoot(`${varName}: ${api.dictionary.toValue(value)};`);
|
|
244
|
-
browserResolvedPaths.add(prefix);
|
|
245
|
-
};
|
|
246
|
-
for (const [group, value] of Object.entries(originals)) addTokenVars(group, value);
|
|
247
|
-
}
|
|
249
|
+
if (api.emitAllTokens) emitAllTokenVars(api);
|
|
248
250
|
const groupsSizeBefore = usedTokenGroups.size;
|
|
249
251
|
api.walkPropTree(tree, (name, prop) => {
|
|
250
252
|
const descriptor = api.dictionary.get(name);
|
|
@@ -79,6 +79,22 @@ const warnAlpha = (message) => {
|
|
|
79
79
|
alphaWarnings.add(message);
|
|
80
80
|
console.warn(`[boss-css] ${message}`);
|
|
81
81
|
};
|
|
82
|
+
const emitAllTokenVars = (api) => {
|
|
83
|
+
if (emittedAllTokens) return;
|
|
84
|
+
emittedAllTokens = true;
|
|
85
|
+
hasTokens = true;
|
|
86
|
+
const addTokenVars = (prefix, value) => {
|
|
87
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
88
|
+
for (const [key, next] of Object.entries(value)) addTokenVars(prefix ? `${prefix}.${key}` : key, next);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!prefix) return;
|
|
92
|
+
const varName = `--${api.selectorPrefix ?? ""}${prefix.replace(/\./g, "-")}`;
|
|
93
|
+
api.css.addRoot(`${varName}: ${api.dictionary.toValue(value)};`);
|
|
94
|
+
browserResolvedPaths.add(prefix);
|
|
95
|
+
};
|
|
96
|
+
for (const [group, value] of Object.entries(originals)) addTokenVars(group, value);
|
|
97
|
+
};
|
|
82
98
|
const onBoot = async (api) => {
|
|
83
99
|
hasTokens = false;
|
|
84
100
|
hasProxyTokens = false;
|
|
@@ -230,21 +246,7 @@ const onPropTree = async (api, { tree, parser }) => {
|
|
|
230
246
|
hasTokenOverrides = true;
|
|
231
247
|
hasTokens = true;
|
|
232
248
|
}
|
|
233
|
-
if (api.emitAllTokens
|
|
234
|
-
emittedAllTokens = true;
|
|
235
|
-
hasTokens = true;
|
|
236
|
-
const addTokenVars = (prefix, value) => {
|
|
237
|
-
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
238
|
-
for (const [key, next] of Object.entries(value)) addTokenVars(prefix ? `${prefix}.${key}` : key, next);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if (!prefix) return;
|
|
242
|
-
const varName = `--${api.selectorPrefix ?? ""}${prefix.replace(/\./g, "-")}`;
|
|
243
|
-
api.css.addRoot(`${varName}: ${api.dictionary.toValue(value)};`);
|
|
244
|
-
browserResolvedPaths.add(prefix);
|
|
245
|
-
};
|
|
246
|
-
for (const [group, value] of Object.entries(originals)) addTokenVars(group, value);
|
|
247
|
-
}
|
|
249
|
+
if (api.emitAllTokens) emitAllTokenVars(api);
|
|
248
250
|
const groupsSizeBefore = usedTokenGroups.size;
|
|
249
251
|
api.walkPropTree(tree, (name, prop) => {
|
|
250
252
|
const descriptor = api.dictionary.get(name);
|