feat: ranges with units, loading vars from settings

This commit is contained in:
Lewis Crichton 2023-09-02 22:02:11 +01:00
parent c0dff86cb2
commit 19a87e3e94
No known key found for this signature in database
2 changed files with 13 additions and 3 deletions

View file

@ -61,6 +61,8 @@ export interface Settings {
settingsSync: boolean; settingsSync: boolean;
settingsSyncVersion: number; settingsSyncVersion: number;
}; };
userCssVars: Record<string, string>;
} }
const DefaultSettings: Settings = { const DefaultSettings: Settings = {
@ -91,7 +93,9 @@ const DefaultSettings: Settings = {
url: "https://api.vencord.dev/", url: "https://api.vencord.dev/",
settingsSync: false, settingsSync: false,
settingsSyncVersion: 0 settingsSyncVersion: 0
} },
userCssVars: {}
}; };
try { try {

View file

@ -46,7 +46,7 @@ async function initThemes() {
document.documentElement.appendChild(themesStyle); document.documentElement.appendChild(themesStyle);
} }
const { themeLinks, enabledThemes } = Settings; const { themeLinks, enabledThemes, userCssVars } = Settings;
const links: string[] = [...themeLinks]; const links: string[] = [...themeLinks];
@ -74,7 +74,13 @@ async function initThemes() {
const { vars } = usercssParse(themeData, theme); const { vars } = usercssParse(themeData, theme);
for (const [id, meta] of Object.entries(vars)) { for (const [id, meta] of Object.entries(vars)) {
cssVars.push(`--${id}: ${meta.default};`); let normalizedValue: string = userCssVars[id] ?? meta.default;
if (meta.type === "range") {
normalizedValue = `${normalizedValue}${meta.units ?? ""}`;
}
cssVars.push(`--${id}: ${normalizedValue};`);
} }
} }