@venix-sistemas/jade 1.4.1 → 1.4.2-alpha.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/LICENSE +21 -21
- package/README.md +994 -969
- package/dist/module.d.mts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +29 -8
- package/dist/runtime/components/VenixIcon.vue +20 -20
- package/dist/runtime/components/VenixThemeSwitcher.vue +336 -336
- package/dist/runtime/composables/useVenixTheme.d.ts +4 -4
- package/dist/runtime/composables/useVenixTheme.js +22 -0
- package/dist/runtime/nitro/theme-init.js +1 -1
- package/dist/runtime/scripts/theme-init.d.ts +4 -2
- package/dist/runtime/scripts/theme-init.js +14 -4
- package/dist/runtime/server/tsconfig.json +3 -3
- package/dist/shared/css/colors.d.ts +1 -1
- package/dist/shared/css/colors.js +11 -3
- package/dist/shared/css/index.js +1 -1
- package/dist/shared/css/tokens.d.ts +7 -0
- package/dist/shared/css/tokens.js +32 -5
- package/dist/shared/theme.json +314 -320
- package/dist/shared/token-names.d.ts +14 -5
- package/dist/shared/token-names.js +1 -1
- package/dist/shared/types/color-options.d.ts +24 -1
- package/dist/shared/types/colors.d.ts +2 -0
- package/dist/shared/types/index.d.ts +3 -1
- package/dist/shared/types/runtime-config.d.ts +2 -0
- package/dist/shared/types/theme-names.d.ts +23 -0
- package/dist/shared/types/theme-names.js +0 -0
- package/dist/shared/utils/base-url.d.ts +15 -0
- package/dist/shared/utils/base-url.js +32 -0
- package/dist/shared/utils/derive-seeds.d.ts +24 -0
- package/dist/shared/utils/derive-seeds.js +30 -0
- package/dist/shared/utils/oklab.d.ts +8 -0
- package/dist/shared/utils/oklab.js +15 -2
- package/dist/shared/utils/scale.d.ts +7 -2
- package/dist/shared/utils/scale.js +4 -3
- package/dist/shared/utils/theme-color.d.ts +9 -0
- package/dist/shared/utils/theme-color.js +10 -0
- package/dist/shared/utils/theme-types.d.ts +8 -0
- package/dist/shared/utils/theme-types.js +16 -0
- package/dist/types.d.mts +2 -0
- package/package.json +15 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ThemeMode, ThemeModePreference } from '../../shared/types/index.js';
|
|
1
|
+
import type { ThemeMode, ThemeModePreference, ThemeName, ThemeOrVariantName, TokenName } from '../../shared/types/index.js';
|
|
2
2
|
export declare const useVenixTheme: () => {
|
|
3
3
|
theme: {
|
|
4
4
|
value: import("vue").ComputedRef<string>;
|
|
@@ -9,8 +9,8 @@ export declare const useVenixTheme: () => {
|
|
|
9
9
|
icon: import("../../shared/utils/icon.js").ResolvedThemeIcon | null;
|
|
10
10
|
custom: boolean;
|
|
11
11
|
} | undefined>;
|
|
12
|
-
set: (name:
|
|
13
|
-
toggle: (forceTheme?:
|
|
12
|
+
set: (name: ThemeName) => void;
|
|
13
|
+
toggle: (forceTheme?: ThemeOrVariantName) => void;
|
|
14
14
|
isSeasonalActive: import("vue").ComputedRef<boolean>;
|
|
15
15
|
activeSeasonalTheme: import("vue").ComputedRef<string | null>;
|
|
16
16
|
shouldApplyColors: boolean;
|
|
@@ -32,7 +32,7 @@ export declare const useVenixTheme: () => {
|
|
|
32
32
|
tokens: {
|
|
33
33
|
all: Record<string, Record<string, string> | undefined>;
|
|
34
34
|
current: import("vue").ComputedRef<Record<string, string> | undefined>;
|
|
35
|
-
cssVar: (name: string) => string;
|
|
35
|
+
cssVar: (name: TokenName | (string & Record<never, never>)) => string;
|
|
36
36
|
};
|
|
37
37
|
mode: {
|
|
38
38
|
value: import("vue").ComputedRef<ThemeMode>;
|
|
@@ -6,6 +6,7 @@ import { useThemeLocale } from "./useThemeLocale.js";
|
|
|
6
6
|
import { useThemeSeasonal } from "./useThemeSeasonal.js";
|
|
7
7
|
import { useThemeColors } from "./useThemeColors.js";
|
|
8
8
|
import { hasCookieConsent } from "../../shared/utils/consent";
|
|
9
|
+
import { themeColorOf } from "../../shared/utils/theme-color";
|
|
9
10
|
import { buildResolvedTheme } from "../../shared/utils/theme-config";
|
|
10
11
|
import { findVariantOwner, isModePreference, isSelectableGroup, normalizeThemeSelection, resolveMode, resolveThemeSelection } from "../../shared/utils/theme-resolve";
|
|
11
12
|
function createThemeCore() {
|
|
@@ -62,6 +63,19 @@ function createThemeCore() {
|
|
|
62
63
|
const environmentVersion = useState("venix-theme-environment", () => 0);
|
|
63
64
|
const getPrefersDark = () => typeof window !== "undefined" ? window.matchMedia("(prefers-color-scheme: dark)").matches : true;
|
|
64
65
|
const getResolvedTheme = (selection = currentSelection()) => resolveThemeSelection(selection, theme.colors, getPrefersDark());
|
|
66
|
+
const applyThemeColorMeta = (variantId) => {
|
|
67
|
+
const colorName = themeConfig?.themeColorMeta;
|
|
68
|
+
if (!colorName) return;
|
|
69
|
+
const color = themeColorOf(theme.colors.themes, variantId, colorName);
|
|
70
|
+
if (!color) return;
|
|
71
|
+
let meta = document.head.querySelector('meta[name="theme-color"]:not([media])');
|
|
72
|
+
if (!meta) {
|
|
73
|
+
meta = document.createElement("meta");
|
|
74
|
+
meta.name = "theme-color";
|
|
75
|
+
document.head.append(meta);
|
|
76
|
+
}
|
|
77
|
+
meta.content = color;
|
|
78
|
+
};
|
|
65
79
|
const apply = (selection) => {
|
|
66
80
|
if (!shouldApplyColors) return;
|
|
67
81
|
const resolved = getResolvedTheme(selection);
|
|
@@ -71,6 +85,7 @@ function createThemeCore() {
|
|
|
71
85
|
html.classList.add(resolved);
|
|
72
86
|
html.setAttribute("data-theme", resolved);
|
|
73
87
|
window.__VENIX_INITIAL_THEME__ = resolved;
|
|
88
|
+
applyThemeColorMeta(resolved);
|
|
74
89
|
window.dispatchEvent(new CustomEvent(THEME_APPLIED_EVENT, { detail: resolved }));
|
|
75
90
|
}
|
|
76
91
|
};
|
|
@@ -114,6 +129,11 @@ function createThemeCore() {
|
|
|
114
129
|
};
|
|
115
130
|
const setTheme = (name) => {
|
|
116
131
|
if (name === SYSTEM_THEME || isSelectableGroup(theme.colors, name)) preference.value = name;
|
|
132
|
+
else warnUnknownTheme("theme.set", name);
|
|
133
|
+
};
|
|
134
|
+
const warnUnknownTheme = (caller, name) => {
|
|
135
|
+
if (!import.meta.dev) return;
|
|
136
|
+
console.warn(`[jade] ${caller}('${name}') did nothing: no such theme. Available: ${[SYSTEM_THEME, ...Object.keys(theme.colors.groups).filter((group) => isSelectableGroup(theme.colors, group))].join(", ")}.`);
|
|
117
137
|
};
|
|
118
138
|
const setMode = (mode) => {
|
|
119
139
|
if (isModePreference(mode)) modePreference.value = mode;
|
|
@@ -146,6 +166,8 @@ function createThemeCore() {
|
|
|
146
166
|
if (owner) {
|
|
147
167
|
preference.value = owner.theme;
|
|
148
168
|
modePreference.value = owner.mode;
|
|
169
|
+
} else {
|
|
170
|
+
warnUnknownTheme("theme.toggle", forceTheme);
|
|
149
171
|
}
|
|
150
172
|
};
|
|
151
173
|
const data = computed(
|
|
@@ -4,7 +4,7 @@ import { buildResolvedTheme } from "../../shared/utils/theme-config";
|
|
|
4
4
|
export default defineNitroPlugin((nitroApp) => {
|
|
5
5
|
const themeConfig = useRuntimeConfig().public.venixTheme;
|
|
6
6
|
const theme = buildResolvedTheme(themeConfig);
|
|
7
|
-
const scriptBody = renderInitThemeScript(theme, createInitThemeOptions(themeConfig?.requireConsent !== false));
|
|
7
|
+
const scriptBody = renderInitThemeScript(theme, createInitThemeOptions(themeConfig?.requireConsent !== false, themeConfig?.themeColorMeta ?? null));
|
|
8
8
|
const hookRenderHtml = nitroApp.hooks.hook;
|
|
9
9
|
hookRenderHtml("render:html", (html, { event }) => {
|
|
10
10
|
const nonce = event?.context?.security?.nonce;
|
|
@@ -25,6 +25,8 @@ export interface InitThemeOptions {
|
|
|
25
25
|
cursor: string;
|
|
26
26
|
font: string;
|
|
27
27
|
};
|
|
28
|
+
/** The color of each variant that drives `<meta name="theme-color">` (`color.themeColorMeta`), or `null` to leave the tag alone. */
|
|
29
|
+
themeColor: string | null;
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* Runs as an inline script in `<head>`, injected via Nitro's `render:html`
|
|
@@ -44,7 +46,7 @@ export interface InitThemeOptions {
|
|
|
44
46
|
* settings from `shared/constants.ts` in `options`.
|
|
45
47
|
*/
|
|
46
48
|
export default function initTheme(createThemeResolver: () => ThemeResolver, themeData: ResolvedTheme, options: InitThemeOptions): void;
|
|
47
|
-
export declare function createInitThemeOptions(requireConsent: boolean): InitThemeOptions;
|
|
49
|
+
export declare function createInitThemeOptions(requireConsent: boolean, themeColor?: string | null): InitThemeOptions;
|
|
48
50
|
/**
|
|
49
51
|
* Only what the script's theme resolution reads, so the HTML doesn't carry
|
|
50
52
|
* every color, translation and icon of every theme on each response: the
|
|
@@ -52,6 +54,6 @@ export declare function createInitThemeOptions(requireConsent: boolean): InitThe
|
|
|
52
54
|
* whether it is a color theme (`isColorTheme` looks at `primary` and
|
|
53
55
|
* `background`). `defaultColor` stays as is.
|
|
54
56
|
*/
|
|
55
|
-
export declare function toInitThemeData(themeData: ResolvedTheme): ResolvedTheme;
|
|
57
|
+
export declare function toInitThemeData(themeData: ResolvedTheme, themeColor?: string | null): ResolvedTheme;
|
|
56
58
|
/** The inline script's source: `initTheme` as an IIFE, with its arguments serialized. */
|
|
57
59
|
export declare function renderInitThemeScript(themeData: ResolvedTheme, options: InitThemeOptions): string;
|
|
@@ -52,6 +52,14 @@ export default function initTheme(createThemeResolver2, themeData, options) {
|
|
|
52
52
|
html.classList.add(theme);
|
|
53
53
|
html.setAttribute("data-theme", theme);
|
|
54
54
|
window.__VENIX_INITIAL_THEME__ = theme;
|
|
55
|
+
const themeColor = options.themeColor;
|
|
56
|
+
const barColor = themeColor ? colors.themes[theme]?.[themeColor] : void 0;
|
|
57
|
+
if (barColor && barColor.charAt(0) === "#") {
|
|
58
|
+
const meta = document.createElement("meta");
|
|
59
|
+
meta.setAttribute("name", "theme-color");
|
|
60
|
+
meta.setAttribute("content", barColor);
|
|
61
|
+
document.head.appendChild(meta);
|
|
62
|
+
}
|
|
55
63
|
for (const toggle of ["scrollbar", "cursor", "font"]) {
|
|
56
64
|
if (getCookie(cookies[toggle]) === "off") html.setAttribute(attributes[toggle], "off");
|
|
57
65
|
}
|
|
@@ -65,9 +73,10 @@ export default function initTheme(createThemeResolver2, themeData, options) {
|
|
|
65
73
|
setCookieIfConsented(cookies.mode, selection.mode);
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
|
-
export function createInitThemeOptions(requireConsent) {
|
|
76
|
+
export function createInitThemeOptions(requireConsent, themeColor = null) {
|
|
69
77
|
return {
|
|
70
78
|
requireConsent,
|
|
79
|
+
themeColor,
|
|
71
80
|
cookies: {
|
|
72
81
|
preference: THEME_PREFERENCE_COOKIE,
|
|
73
82
|
mode: THEME_MODE_COOKIE,
|
|
@@ -81,12 +90,13 @@ export function createInitThemeOptions(requireConsent) {
|
|
|
81
90
|
attributes: { scrollbar: SCROLLBAR_ATTRIBUTE, cursor: CURSOR_ATTRIBUTE, font: FONT_ATTRIBUTE }
|
|
82
91
|
};
|
|
83
92
|
}
|
|
84
|
-
export function toInitThemeData(themeData) {
|
|
93
|
+
export function toInitThemeData(themeData, themeColor = null) {
|
|
85
94
|
const { themes = {}, groups = {}, defaultColor } = themeData.colors ?? {};
|
|
86
95
|
const slimThemes = {};
|
|
87
96
|
for (const [id, colors] of Object.entries(themes)) {
|
|
88
97
|
const { primary, background } = colors;
|
|
89
|
-
|
|
98
|
+
const bar = themeColor ? colors[themeColor] : void 0;
|
|
99
|
+
slimThemes[id] = { ...themeColor && bar && { [themeColor]: bar }, ...primary && { primary }, ...background && { background } };
|
|
90
100
|
}
|
|
91
101
|
const slimGroups = {};
|
|
92
102
|
for (const [name, { variants, seasonal, dateRange }] of Object.entries(groups)) {
|
|
@@ -95,5 +105,5 @@ export function toInitThemeData(themeData) {
|
|
|
95
105
|
return { colors: { themes: slimThemes, groups: slimGroups, defaultColor } };
|
|
96
106
|
}
|
|
97
107
|
export function renderInitThemeScript(themeData, options) {
|
|
98
|
-
return `(${initTheme.toString()})(${createThemeResolver.toString()}, ${toInlineScriptJson(toInitThemeData(themeData))}, ${toInlineScriptJson(options)})`;
|
|
108
|
+
return `(${initTheme.toString()})(${createThemeResolver.toString()}, ${toInlineScriptJson(toInitThemeData(themeData, options.themeColor))}, ${toInlineScriptJson(options)})`;
|
|
99
109
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../.nuxt/tsconfig.server.json",
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../.nuxt/tsconfig.server.json",
|
|
3
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ContrastLevel, ThemeColors } from '../types/index.js';
|
|
2
|
-
export declare function generateThemeVars(mode: string, colors: ThemeColors, contrast?: ContrastLevel): string;
|
|
2
|
+
export declare function generateThemeVars(mode: string, colors: ThemeColors, contrast?: ContrastLevel, highContrast?: boolean): string;
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import { getThemeHexColors } from "../utils/theme-resolve.js";
|
|
2
2
|
import { tokensEnabled } from "../token-names.js";
|
|
3
|
-
import { generateTokenVars } from "./tokens.js";
|
|
4
|
-
export function generateThemeVars(mode, colors, contrast) {
|
|
3
|
+
import { generateHighContrastVars, generateTokenVars } from "./tokens.js";
|
|
4
|
+
export function generateThemeVars(mode, colors, contrast, highContrast = false) {
|
|
5
5
|
const colorVars = getThemeHexColors(colors).map(([key, value]) => ` --color-${key}: ${value};`).join("\n");
|
|
6
6
|
const tokenVars = tokensEnabled(colors) ? `
|
|
7
7
|
/* Semantic tokens */
|
|
8
8
|
${generateTokenVars(colors, contrast)}` : "";
|
|
9
|
+
const highContrastVars = highContrast && tokensEnabled(colors) ? generateHighContrastVars(colors, contrast) : "";
|
|
10
|
+
const highContrastBlock = highContrastVars ? `
|
|
11
|
+
@media (prefers-contrast: more) {
|
|
12
|
+
:root[data-theme='${mode}'] {
|
|
13
|
+
${highContrastVars}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
` : "";
|
|
9
17
|
const isDark = colors.dark === true;
|
|
10
18
|
const colorScheme = isDark ? "dark" : "light";
|
|
11
19
|
const inverseColor = isDark ? "#FFFFFF" : "#000000";
|
|
@@ -20,5 +28,5 @@ ${generateTokenVars(colors, contrast)}` : "";
|
|
|
20
28
|
--color-inverse: ${inverseColor};
|
|
21
29
|
` + colorVars + tokenVars + `
|
|
22
30
|
}
|
|
23
|
-
|
|
31
|
+
` + highContrastBlock;
|
|
24
32
|
}
|
package/dist/shared/css/index.js
CHANGED
|
@@ -15,7 +15,7 @@ export function processTheme(theme) {
|
|
|
15
15
|
output.push(generateThemeTransitionCSS());
|
|
16
16
|
for (const [themeName, themeColors] of Object.entries(theme.colors.themes)) {
|
|
17
17
|
if (themeName === "system" || !isColorTheme(themeColors)) continue;
|
|
18
|
-
output.push(generateThemeVars(themeName, themeColors, theme.colors.contrast || void 0));
|
|
18
|
+
output.push(generateThemeVars(themeName, themeColors, theme.colors.contrast || void 0, theme.colors.highContrast === true));
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -4,6 +4,13 @@ import type { ContrastLevel, ThemeColors } from '../types/index.js';
|
|
|
4
4
|
* written. Memoized: the CSS and the build check ask for the same variant.
|
|
5
5
|
*/
|
|
6
6
|
export declare function generateTokens(colors: ThemeColors, level?: ContrastLevel): Array<[string, string]>;
|
|
7
|
+
/**
|
|
8
|
+
* The `--jade-*` declarations for the AAA version of a variant, only for the
|
|
9
|
+
* tokens whose value differs from the `level` version, or an empty string when
|
|
10
|
+
* there is nothing to add (`level` is already AAA). Best effort: a pair that
|
|
11
|
+
* can't reach 7:1 keeps the best the scale can do.
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateHighContrastVars(colors: ThemeColors, level?: ContrastLevel): string;
|
|
7
14
|
/** The `--jade-*` declarations for `generateTokens`, one per line, indented for a theme block. */
|
|
8
15
|
export declare function generateTokenVars(colors: ThemeColors, level?: ContrastLevel): string;
|
|
9
16
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { contrastRatio } from "../utils/contrast.js";
|
|
2
|
+
import { deriveSeeds } from "../utils/derive-seeds.js";
|
|
2
3
|
import { generateScales } from "../utils/scale.js";
|
|
3
4
|
import { NEUTRAL_TOKENS, OVERRIDABLE_TOKEN_NAMES, ROLE_TOKENS, TOKEN_ROLES as ROLES, parseStepRef, roleTokenName, tokenOverrides, tokensEnabled } from "../token-names.js";
|
|
4
5
|
const FALLBACK_BACKGROUND = { light: "#FFFFFF", dark: "#121212" };
|
|
5
6
|
const tokenCache = /* @__PURE__ */ new Map();
|
|
6
7
|
export function generateTokens(colors, level = "AA") {
|
|
7
|
-
const key = JSON.stringify([colors.dark === true, colors.background,
|
|
8
|
+
const key = JSON.stringify([colors.dark === true, colors.background, ROLES.map((role) => colors[role]), level, colors.neutralTint !== false, tokenOverrides(colors)]);
|
|
8
9
|
let tokens = tokenCache.get(key);
|
|
9
10
|
if (!tokens) {
|
|
10
11
|
tokens = buildTokens(colors, level);
|
|
@@ -15,12 +16,22 @@ export function generateTokens(colors, level = "AA") {
|
|
|
15
16
|
function buildTokens(colors, level) {
|
|
16
17
|
const mode = colors.dark === true ? "dark" : "light";
|
|
17
18
|
const background = colors.background ?? FALLBACK_BACKGROUND[mode];
|
|
18
|
-
const
|
|
19
|
+
const given = {};
|
|
19
20
|
for (const role of ROLES) {
|
|
20
21
|
const seed = colors[role];
|
|
22
|
+
if (seed) given[role] = seed;
|
|
23
|
+
}
|
|
24
|
+
const derived = deriveSeeds(given, mode);
|
|
25
|
+
const seeds = {};
|
|
26
|
+
for (const role of ROLES) {
|
|
27
|
+
const seed = given[role] ?? derived[role];
|
|
21
28
|
if (seed) seeds[role] = seed;
|
|
22
29
|
}
|
|
23
|
-
const
|
|
30
|
+
const overrides = tokenOverrides(colors);
|
|
31
|
+
const { neutral, roles } = generateScales(background, seeds, mode, level, {
|
|
32
|
+
tint: colors.neutralTint !== false,
|
|
33
|
+
mutedOver: farthestNeutralSurface(overrides)
|
|
34
|
+
});
|
|
24
35
|
const tokens = NEUTRAL_TOKENS.map(([name, step]) => [name, neutral[step - 1]]);
|
|
25
36
|
const primary = roles.primary;
|
|
26
37
|
if (primary) tokens.push(["border-focus", primary.steps[10]]);
|
|
@@ -32,9 +43,17 @@ function buildTokens(colors, level) {
|
|
|
32
43
|
}
|
|
33
44
|
tokens.push([`on-${role}`, scale.on]);
|
|
34
45
|
}
|
|
35
|
-
applyOverrides(tokens,
|
|
46
|
+
applyOverrides(tokens, overrides, neutral, roles);
|
|
36
47
|
return tokens;
|
|
37
48
|
}
|
|
49
|
+
function farthestNeutralSurface(overrides) {
|
|
50
|
+
let farthest = 0;
|
|
51
|
+
for (const name of ["bg", "bg-subtle", "bg-muted"]) {
|
|
52
|
+
const parsed = parseStepRef(overrides[name]);
|
|
53
|
+
if (parsed?.scale === "neutral") farthest = Math.max(farthest, parsed.step);
|
|
54
|
+
}
|
|
55
|
+
return farthest;
|
|
56
|
+
}
|
|
38
57
|
function applyOverrides(tokens, overrides, neutral, roles) {
|
|
39
58
|
for (const [name, ref] of Object.entries(overrides)) {
|
|
40
59
|
const parsed = parseStepRef(ref);
|
|
@@ -45,6 +64,11 @@ function applyOverrides(tokens, overrides, neutral, roles) {
|
|
|
45
64
|
if (color) entry[1] = color;
|
|
46
65
|
}
|
|
47
66
|
}
|
|
67
|
+
export function generateHighContrastVars(colors, level = "AA") {
|
|
68
|
+
if (level === "AAA") return "";
|
|
69
|
+
const base = new Map(generateTokens(colors, level));
|
|
70
|
+
return generateTokens(colors, "AAA").filter(([name, value]) => base.get(name) !== value).map(([name, value]) => ` --jade-${name}: ${value};`).join("\n");
|
|
71
|
+
}
|
|
48
72
|
export function generateTokenVars(colors, level = "AA") {
|
|
49
73
|
return generateTokens(colors, level).map(([name, value]) => ` --jade-${name}: ${value};`).join("\n");
|
|
50
74
|
}
|
|
@@ -103,6 +127,9 @@ export function findTokenContrastIssues(themes, level) {
|
|
|
103
127
|
}
|
|
104
128
|
return messages;
|
|
105
129
|
}
|
|
130
|
+
function hasRole(colors, role) {
|
|
131
|
+
return Boolean(colors[role] || colors.primary);
|
|
132
|
+
}
|
|
106
133
|
export function findTokenOverrideIssues(themes) {
|
|
107
134
|
const messages = [];
|
|
108
135
|
for (const [id, colors] of Object.entries(themes)) {
|
|
@@ -111,7 +138,7 @@ export function findTokenOverrideIssues(themes) {
|
|
|
111
138
|
const parsed = parseStepRef(ref);
|
|
112
139
|
if (!OVERRIDABLE_TOKEN_NAMES.includes(name)) problems.push(`\`${name}\` is not a token that can be overridden`);
|
|
113
140
|
else if (!parsed) problems.push(`\`${name}\`: \`${String(ref)}\` is not a step (use \`neutral-1\` to \`neutral-12\`, \`primary-1\`\u2026)`);
|
|
114
|
-
else if (parsed.scale !== "neutral" && !colors
|
|
141
|
+
else if (parsed.scale !== "neutral" && !hasRole(colors, parsed.scale)) problems.push(`\`${name}\`: the variant has no \`${parsed.scale}\` seed and no \`primary\` to derive it from`);
|
|
115
142
|
}
|
|
116
143
|
if (problems.length) messages.push(`Some \`tokens\` overrides of \`${id}\` were ignored: ${problems.join("; ")}.`);
|
|
117
144
|
}
|