@marianmeres/design-tokens 1.5.1 → 1.6.0
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/generate.js +28 -17
- package/package.json +1 -1
package/dist/generate.js
CHANGED
|
@@ -55,10 +55,10 @@ function generatePairedColorTokens(tokens, key, pair, prefix) {
|
|
|
55
55
|
tokens[`${prefix}color-${key}-hover`] = pair.hover ?? pair.DEFAULT;
|
|
56
56
|
tokens[`${prefix}color-${key}-active`] = pair.active ?? pair.DEFAULT;
|
|
57
57
|
tokens[`${prefix}color-${key}-foreground`] = pair.foreground;
|
|
58
|
-
tokens[`${prefix}color-${key}-foreground-hover`] =
|
|
59
|
-
pair.foreground;
|
|
60
|
-
tokens[`${prefix}color-${key}-foreground-active`] =
|
|
61
|
-
pair.foreground;
|
|
58
|
+
tokens[`${prefix}color-${key}-foreground-hover`] =
|
|
59
|
+
pair.foregroundHover ?? pair.foreground;
|
|
60
|
+
tokens[`${prefix}color-${key}-foreground-active`] =
|
|
61
|
+
pair.foregroundActive ?? pair.foreground;
|
|
62
62
|
}
|
|
63
63
|
/** Generate color tokens for a single color */
|
|
64
64
|
function generateSingleColorTokens(tokens, key, color, prefix) {
|
|
@@ -85,9 +85,7 @@ function generateSingleColorTokens(tokens, key, color, prefix) {
|
|
|
85
85
|
* @param options - Generation options, or a shorthand `"light"`/`"dark"` mode string
|
|
86
86
|
*/
|
|
87
87
|
export function generateCssTokens(schema, prefix, options = {}) {
|
|
88
|
-
const opts = typeof options === "string"
|
|
89
|
-
? { mode: options }
|
|
90
|
-
: options;
|
|
88
|
+
const opts = typeof options === "string" ? { mode: options } : options;
|
|
91
89
|
const mode = opts.mode ?? "light";
|
|
92
90
|
const deriveStates = opts.deriveStates ?? true;
|
|
93
91
|
const surfaceContrast = opts.surfaceForegroundContrast ?? 50;
|
|
@@ -174,20 +172,33 @@ export function toCssString(tokens, selector = ":root") {
|
|
|
174
172
|
*/
|
|
175
173
|
export function generateThemeCss(schema, prefix, options = {}) {
|
|
176
174
|
const { cssLayer, prettierIgnore, ...genOptions } = options;
|
|
177
|
-
|
|
175
|
+
const PRETTIER_IGNORE_PREFIX = "/* prettier-ignore */\n";
|
|
176
|
+
let css = toCssString(generateCssTokens(schema.light, prefix, {
|
|
177
|
+
...genOptions,
|
|
178
|
+
mode: "light",
|
|
179
|
+
}));
|
|
180
|
+
if (!cssLayer && prettierIgnore) {
|
|
181
|
+
css = PRETTIER_IGNORE_PREFIX + css;
|
|
182
|
+
}
|
|
178
183
|
if (schema.dark) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
let darkCss = toCssString(generateCssTokens(schema.dark, prefix, {
|
|
185
|
+
...genOptions,
|
|
186
|
+
mode: "dark",
|
|
187
|
+
}), ":root.dark");
|
|
188
|
+
if (!cssLayer && prettierIgnore) {
|
|
189
|
+
darkCss = PRETTIER_IGNORE_PREFIX + darkCss;
|
|
190
|
+
}
|
|
191
|
+
css += "\n" + darkCss;
|
|
184
192
|
}
|
|
185
193
|
if (cssLayer) {
|
|
186
|
-
const indented = css
|
|
194
|
+
const indented = css
|
|
195
|
+
.split("\n")
|
|
196
|
+
.map((l) => (l ? "\t" + l : l))
|
|
197
|
+
.join("\n");
|
|
187
198
|
css = `@layer ${cssLayer} {\n${indented}}\n`;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
199
|
+
if (prettierIgnore) {
|
|
200
|
+
css = PRETTIER_IGNORE_PREFIX + css;
|
|
201
|
+
}
|
|
191
202
|
}
|
|
192
203
|
return css;
|
|
193
204
|
}
|