Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable sass parser in ui/build to parse indirect color assignments #16611

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions ui/.build/src/sass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,30 @@ async function parseScss(src: string) {
async function parseThemeColorDefs() {
const themeFiles = await globArray('./common/css/theme/_*.scss', { absolute: false });
const themes: string[] = ['dark'];
const capturedColors = new Map<string, string>();
for (const themeFile of themeFiles ?? []) {
const theme = /_([^/]+)\.scss/.exec(themeFile)?.[1];
if (!theme) {
env.log(`${errorMark} - invalid theme filename '${c.cyan(themeFile)}'`, { ctx: 'sass' });
continue;
}
const text = fs.readFileSync(themeFile, 'utf8');
const colorMap = new Map<string, clr.Instance>();
for (const match of text.matchAll(/\s\$c-([-a-z0-9]+):\s*([^;]+);/g)) {
colorMap.set(match[1], clr(match[2]));
capturedColors.set(match[1], match[2]);
}
const colorMap = new Map<string, clr.Instance>();
for (const [color, colorVal] of capturedColors) {
let val = colorVal;
const visitedVariables = new Set();
while (val.startsWith('$')) {
const inferredValue = capturedColors.get(val.substring(3)) ?? '#000';
if (visitedVariables.has(inferredValue)) {
break;
}
visitedVariables.add(inferredValue);
val = inferredValue;
}
colorMap.set(color, clr(val));
}
if (theme !== 'default') themes.push(theme);
themeColorMap.set(theme, colorMap);
Expand Down
Loading