diff --git a/cptr/frontend/src/lib/i18n/locales/de.json b/cptr/frontend/src/lib/i18n/locales/de.json
index bccfe6a..58291d8 100644
--- a/cptr/frontend/src/lib/i18n/locales/de.json
+++ b/cptr/frontend/src/lib/i18n/locales/de.json
@@ -84,6 +84,7 @@
"search.noRecentChats": "Keine letzten Chats",
"settings.back": "Zurรผck",
"settings.general": "Allgemein",
+ "settings.appearance": "Appearance",
"settings.memory": "Speicher",
"pwa.settingsTitle": "Progressive Web App",
"intent.chooseWorkspace": "Arbeitsbereich",
@@ -863,5 +864,18 @@
"general.uiScale": "UI Scale",
"general.default": "Default",
"general.decreaseUiScale": "Decrease UI Scale",
- "general.increaseUiScale": "Increase UI Scale"
+ "general.increaseUiScale": "Increase UI Scale",
+ "appearance.title": "Appearance",
+ "appearance.colors": "Colors",
+ "appearance.interface": "Interface",
+ "appearance.import": "Import",
+ "appearance.exportTheme": "Export",
+ "appearance.reset": "Reset",
+ "appearance.background": "Background",
+ "appearance.foreground": "Foreground",
+ "appearance.uiFont": "UI font",
+ "appearance.exported": "Theme exported",
+ "appearance.exportFailed": "Failed to export theme",
+ "appearance.imported": "Theme imported",
+ "appearance.importFailed": "Failed to import theme"
}
diff --git a/cptr/frontend/src/lib/i18n/locales/en.json b/cptr/frontend/src/lib/i18n/locales/en.json
index d67b9d7..ebfb7ca 100644
--- a/cptr/frontend/src/lib/i18n/locales/en.json
+++ b/cptr/frontend/src/lib/i18n/locales/en.json
@@ -84,6 +84,7 @@
"search.noRecentChats": "No recent chats",
"settings.back": "Back",
"settings.general": "General",
+ "settings.appearance": "Appearance",
"settings.memory": "Memory",
"pwa.settingsTitle": "Progressive Web App",
"intent.chooseWorkspace": "Workspace",
@@ -863,5 +864,18 @@
"general.uiScale": "UI Scale",
"general.default": "Default",
"general.decreaseUiScale": "Decrease UI Scale",
- "general.increaseUiScale": "Increase UI Scale"
+ "general.increaseUiScale": "Increase UI Scale",
+ "appearance.title": "Appearance",
+ "appearance.colors": "Colors",
+ "appearance.interface": "Interface",
+ "appearance.import": "Import",
+ "appearance.exportTheme": "Export",
+ "appearance.reset": "Reset",
+ "appearance.background": "Background",
+ "appearance.foreground": "Foreground",
+ "appearance.uiFont": "UI font",
+ "appearance.exported": "Theme exported",
+ "appearance.exportFailed": "Failed to export theme",
+ "appearance.imported": "Theme imported",
+ "appearance.importFailed": "Failed to import theme"
}
diff --git a/cptr/frontend/src/lib/i18n/locales/es.json b/cptr/frontend/src/lib/i18n/locales/es.json
index c41fd87..f44cf56 100644
--- a/cptr/frontend/src/lib/i18n/locales/es.json
+++ b/cptr/frontend/src/lib/i18n/locales/es.json
@@ -84,6 +84,7 @@
"search.noRecentChats": "Sin chats recientes",
"settings.back": "Atrรกs",
"settings.general": "General",
+ "settings.appearance": "Appearance",
"settings.memory": "Memoria",
"pwa.settingsTitle": "Aplicaciรณn web progresiva",
"intent.chooseWorkspace": "Espacio de trabajo",
@@ -863,5 +864,18 @@
"general.uiScale": "UI Scale",
"general.default": "Default",
"general.decreaseUiScale": "Decrease UI Scale",
- "general.increaseUiScale": "Increase UI Scale"
+ "general.increaseUiScale": "Increase UI Scale",
+ "appearance.title": "Appearance",
+ "appearance.colors": "Colors",
+ "appearance.interface": "Interface",
+ "appearance.import": "Import",
+ "appearance.exportTheme": "Export",
+ "appearance.reset": "Reset",
+ "appearance.background": "Background",
+ "appearance.foreground": "Foreground",
+ "appearance.uiFont": "UI font",
+ "appearance.exported": "Theme exported",
+ "appearance.exportFailed": "Failed to export theme",
+ "appearance.imported": "Theme imported",
+ "appearance.importFailed": "Failed to import theme"
}
diff --git a/cptr/frontend/src/lib/i18n/locales/fr.json b/cptr/frontend/src/lib/i18n/locales/fr.json
index 4c78e20..d3efec1 100644
--- a/cptr/frontend/src/lib/i18n/locales/fr.json
+++ b/cptr/frontend/src/lib/i18n/locales/fr.json
@@ -84,6 +84,7 @@
"search.noRecentChats": "Aucune conversation rรฉcente",
"settings.back": "Retour",
"settings.general": "Gรฉnรฉral",
+ "settings.appearance": "Appearance",
"settings.memory": "Mรฉmoire",
"pwa.settingsTitle": "Application web progressive",
"intent.chooseWorkspace": "Espace de travail",
@@ -863,5 +864,18 @@
"general.uiScale": "UI Scale",
"general.default": "Default",
"general.decreaseUiScale": "Decrease UI Scale",
- "general.increaseUiScale": "Increase UI Scale"
+ "general.increaseUiScale": "Increase UI Scale",
+ "appearance.title": "Appearance",
+ "appearance.colors": "Colors",
+ "appearance.interface": "Interface",
+ "appearance.import": "Import",
+ "appearance.exportTheme": "Export",
+ "appearance.reset": "Reset",
+ "appearance.background": "Background",
+ "appearance.foreground": "Foreground",
+ "appearance.uiFont": "UI font",
+ "appearance.exported": "Theme exported",
+ "appearance.exportFailed": "Failed to export theme",
+ "appearance.imported": "Theme imported",
+ "appearance.importFailed": "Failed to import theme"
}
diff --git a/cptr/frontend/src/lib/i18n/locales/ja.json b/cptr/frontend/src/lib/i18n/locales/ja.json
index 47d181b..f0bdc82 100644
--- a/cptr/frontend/src/lib/i18n/locales/ja.json
+++ b/cptr/frontend/src/lib/i18n/locales/ja.json
@@ -84,6 +84,7 @@
"search.noRecentChats": "ๆ่ฟใฎใใฃใใใฏใใใพใใ",
"settings.back": "ๆปใ",
"settings.general": "ไธ่ฌ",
+ "settings.appearance": "Appearance",
"settings.memory": "ใกใขใช",
"pwa.settingsTitle": "ใใญใฐใฌใใทใ Web ใขใใช",
"intent.chooseWorkspace": "ใฏใผใฏในใใผใน",
@@ -863,5 +864,18 @@
"general.uiScale": "UI Scale",
"general.default": "Default",
"general.decreaseUiScale": "Decrease UI Scale",
- "general.increaseUiScale": "Increase UI Scale"
+ "general.increaseUiScale": "Increase UI Scale",
+ "appearance.title": "Appearance",
+ "appearance.colors": "Colors",
+ "appearance.interface": "Interface",
+ "appearance.import": "Import",
+ "appearance.exportTheme": "Export",
+ "appearance.reset": "Reset",
+ "appearance.background": "Background",
+ "appearance.foreground": "Foreground",
+ "appearance.uiFont": "UI font",
+ "appearance.exported": "Theme exported",
+ "appearance.exportFailed": "Failed to export theme",
+ "appearance.imported": "Theme imported",
+ "appearance.importFailed": "Failed to import theme"
}
diff --git a/cptr/frontend/src/lib/i18n/locales/ko.json b/cptr/frontend/src/lib/i18n/locales/ko.json
index e2fd22c..d08fcf5 100644
--- a/cptr/frontend/src/lib/i18n/locales/ko.json
+++ b/cptr/frontend/src/lib/i18n/locales/ko.json
@@ -84,6 +84,7 @@
"search.noRecentChats": "์ต๊ทผ ์ฑํ
์์",
"settings.back": "๋ค๋ก",
"settings.general": "์ผ๋ฐ",
+ "settings.appearance": "Appearance",
"settings.memory": "๋ฉ๋ชจ๋ฆฌ",
"pwa.settingsTitle": "ํ๋ก๊ทธ๋ ์๋ธ ์น ์ฑ",
"intent.chooseWorkspace": "์์
๊ณต๊ฐ",
@@ -863,5 +864,18 @@
"general.uiScale": "UI Scale",
"general.default": "Default",
"general.decreaseUiScale": "Decrease UI Scale",
- "general.increaseUiScale": "Increase UI Scale"
+ "general.increaseUiScale": "Increase UI Scale",
+ "appearance.title": "Appearance",
+ "appearance.colors": "Colors",
+ "appearance.interface": "Interface",
+ "appearance.import": "Import",
+ "appearance.exportTheme": "Export",
+ "appearance.reset": "Reset",
+ "appearance.background": "Background",
+ "appearance.foreground": "Foreground",
+ "appearance.uiFont": "UI font",
+ "appearance.exported": "Theme exported",
+ "appearance.exportFailed": "Failed to export theme",
+ "appearance.imported": "Theme imported",
+ "appearance.importFailed": "Failed to import theme"
}
diff --git a/cptr/frontend/src/lib/i18n/locales/pt-BR.json b/cptr/frontend/src/lib/i18n/locales/pt-BR.json
index d8b117f..b26bd4f 100644
--- a/cptr/frontend/src/lib/i18n/locales/pt-BR.json
+++ b/cptr/frontend/src/lib/i18n/locales/pt-BR.json
@@ -84,6 +84,7 @@
"search.noRecentChats": "Sem conversas recentes",
"settings.back": "Voltar",
"settings.general": "Geral",
+ "settings.appearance": "Appearance",
"settings.memory": "Memรณria",
"pwa.settingsTitle": "Aplicativo Web Progressivo",
"intent.chooseWorkspace": "Workspace",
@@ -863,5 +864,18 @@
"general.uiScale": "UI Scale",
"general.default": "Default",
"general.decreaseUiScale": "Decrease UI Scale",
- "general.increaseUiScale": "Increase UI Scale"
+ "general.increaseUiScale": "Increase UI Scale",
+ "appearance.title": "Appearance",
+ "appearance.colors": "Colors",
+ "appearance.interface": "Interface",
+ "appearance.import": "Import",
+ "appearance.exportTheme": "Export",
+ "appearance.reset": "Reset",
+ "appearance.background": "Background",
+ "appearance.foreground": "Foreground",
+ "appearance.uiFont": "UI font",
+ "appearance.exported": "Theme exported",
+ "appearance.exportFailed": "Failed to export theme",
+ "appearance.imported": "Theme imported",
+ "appearance.importFailed": "Failed to import theme"
}
diff --git a/cptr/frontend/src/lib/i18n/locales/ru.json b/cptr/frontend/src/lib/i18n/locales/ru.json
index 942eee5..0bb9a77 100644
--- a/cptr/frontend/src/lib/i18n/locales/ru.json
+++ b/cptr/frontend/src/lib/i18n/locales/ru.json
@@ -84,6 +84,7 @@
"search.noRecentChats": "ะะตั ะฝะตะดะฐะฒะฝะธั
ัะฐัะพะฒ",
"settings.back": "ะะฐะทะฐะด",
"settings.general": "ะัะฝะพะฒะฝัะต",
+ "settings.appearance": "Appearance",
"settings.memory": "ะะฐะผััั",
"pwa.settingsTitle": "ะัะพะณัะตััะธะฒะฝะพะต ะฒะตะฑ-ะฟัะธะปะพะถะตะฝะธะต",
"intent.chooseWorkspace": "ะ ะฐะฑะพัะฐั ะพะฑะปะฐััั",
@@ -863,5 +864,18 @@
"general.uiScale": "UI Scale",
"general.default": "Default",
"general.decreaseUiScale": "Decrease UI Scale",
- "general.increaseUiScale": "Increase UI Scale"
+ "general.increaseUiScale": "Increase UI Scale",
+ "appearance.title": "Appearance",
+ "appearance.colors": "Colors",
+ "appearance.interface": "Interface",
+ "appearance.import": "Import",
+ "appearance.exportTheme": "Export",
+ "appearance.reset": "Reset",
+ "appearance.background": "Background",
+ "appearance.foreground": "Foreground",
+ "appearance.uiFont": "UI font",
+ "appearance.exported": "Theme exported",
+ "appearance.exportFailed": "Failed to export theme",
+ "appearance.imported": "Theme imported",
+ "appearance.importFailed": "Failed to import theme"
}
diff --git a/cptr/frontend/src/lib/i18n/locales/zh-CN.json b/cptr/frontend/src/lib/i18n/locales/zh-CN.json
index 888646b..d7c377f 100644
--- a/cptr/frontend/src/lib/i18n/locales/zh-CN.json
+++ b/cptr/frontend/src/lib/i18n/locales/zh-CN.json
@@ -84,6 +84,7 @@
"search.noRecentChats": "ๆฒกๆๆ่ฟๅฏน่ฏ",
"settings.back": "่ฟๅ",
"settings.general": "้็จ",
+ "settings.appearance": "Appearance",
"settings.memory": "่ฎฐๅฟ",
"pwa.settingsTitle": "ๆธ่ฟๅผ Web ๅบ็จ",
"intent.chooseWorkspace": "ๅทฅไฝๅบ",
@@ -863,5 +864,18 @@
"general.uiScale": "UI Scale",
"general.default": "Default",
"general.decreaseUiScale": "Decrease UI Scale",
- "general.increaseUiScale": "Increase UI Scale"
+ "general.increaseUiScale": "Increase UI Scale",
+ "appearance.title": "Appearance",
+ "appearance.colors": "Colors",
+ "appearance.interface": "Interface",
+ "appearance.import": "Import",
+ "appearance.exportTheme": "Export",
+ "appearance.reset": "Reset",
+ "appearance.background": "Background",
+ "appearance.foreground": "Foreground",
+ "appearance.uiFont": "UI font",
+ "appearance.exported": "Theme exported",
+ "appearance.exportFailed": "Failed to export theme",
+ "appearance.imported": "Theme imported",
+ "appearance.importFailed": "Failed to import theme"
}
diff --git a/cptr/frontend/src/lib/i18n/locales/zh-TW.json b/cptr/frontend/src/lib/i18n/locales/zh-TW.json
index 2e149c2..554df7c 100644
--- a/cptr/frontend/src/lib/i18n/locales/zh-TW.json
+++ b/cptr/frontend/src/lib/i18n/locales/zh-TW.json
@@ -84,6 +84,7 @@
"search.noRecentChats": "ๆฒๆๆ่ฟๅฐ่ฉฑ",
"settings.back": "่ฟๅ",
"settings.general": "ไธ่ฌ",
+ "settings.appearance": "Appearance",
"settings.memory": "่จๆถ",
"pwa.settingsTitle": "ๆผธ้ฒๅผ Web ๆ็จ็จๅผ",
"intent.chooseWorkspace": "ๅทฅไฝๅ",
@@ -863,5 +864,18 @@
"general.uiScale": "UI Scale",
"general.default": "Default",
"general.decreaseUiScale": "Decrease UI Scale",
- "general.increaseUiScale": "Increase UI Scale"
+ "general.increaseUiScale": "Increase UI Scale",
+ "appearance.title": "Appearance",
+ "appearance.colors": "Colors",
+ "appearance.interface": "Interface",
+ "appearance.import": "Import",
+ "appearance.exportTheme": "Export",
+ "appearance.reset": "Reset",
+ "appearance.background": "Background",
+ "appearance.foreground": "Foreground",
+ "appearance.uiFont": "UI font",
+ "appearance.exported": "Theme exported",
+ "appearance.exportFailed": "Failed to export theme",
+ "appearance.imported": "Theme imported",
+ "appearance.importFailed": "Failed to import theme"
}
diff --git a/cptr/frontend/src/lib/stores.ts b/cptr/frontend/src/lib/stores.ts
index 797bfdd..ec69575 100644
--- a/cptr/frontend/src/lib/stores.ts
+++ b/cptr/frontend/src/lib/stores.ts
@@ -30,7 +30,15 @@ import { streamingChatTabs } from '$lib/stores/chat';
import { keybindings, loadKeybindings } from '$lib/stores/keybindings';
import { defaultPwaPreferences, type PwaPreferences } from '$lib/intents/types';
import { getPathDisplayName, isSupportedWorkspacePath } from '$lib/utils/paths';
-import { setTextScale } from '$lib/utils/text-scale';
+import {
+ applyAppearance,
+ sanitizeThemeConfig,
+ type AppearancePreferences,
+ type Theme,
+ type ThemeConfig
+} from '$lib/utils/appearance';
+
+export type { AppearancePreferences, Theme, ThemeConfig };
// โโ Types โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
@@ -70,7 +78,8 @@ export interface WorkspaceState {
export type ToolApprovalMode = 'ask' | 'auto' | 'full';
export interface UserPreferences {
- theme: Theme;
+ theme?: Theme;
+ appearance?: AppearancePreferences;
sidebarOpen: boolean;
sidebarWidth: number;
toolApprovalMode: ToolApprovalMode;
@@ -86,8 +95,6 @@ export interface UserPreferences {
textScale?: number | null;
}
-export type Theme = 'dark' | 'light' | 'system';
-
// โโ ID generation โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
let _idCounter = Date.now();
@@ -174,6 +181,7 @@ export type StreamingBehavior = 'queue' | 'interrupt';
export const streamingBehavior = writable
('queue');
export const selectedModelId = writable('');
export const pwaPreferences = writable(defaultPwaPreferences);
+export const themeConfig = writable(null);
export const textScale = writable(null);
/** Saved workspace path order for sidebar drag-reorder. */
@@ -300,6 +308,11 @@ function persistPreferences(): void {
_savePrefTimer = setTimeout(() => {
const prefs: UserPreferences = {
theme: get(theme),
+ appearance: {
+ theme: get(theme),
+ themeConfig: sanitizeThemeConfig(get(themeConfig)),
+ textScale: get(textScale) ?? undefined
+ },
sidebarOpen: get(sidebarOpen),
sidebarWidth: get(sidebarWidth),
toolApprovalMode: get(toolApprovalMode),
@@ -328,6 +341,9 @@ function subscribeForPersistence() {
theme.subscribe(() => {
if (get(stateLoaded)) persistPreferences();
});
+ themeConfig.subscribe(() => {
+ if (get(stateLoaded)) persistPreferences();
+ });
sidebarOpen.subscribe(() => {
if (get(stateLoaded)) persistPreferences();
});
@@ -374,7 +390,11 @@ function subscribeForPersistence() {
export async function loadPreferences(): Promise {
try {
const prefs = await getPreferences();
- if (prefs.theme) theme.set(prefs.theme as Theme);
+ const appearance = (
+ prefs.appearance && typeof prefs.appearance === 'object' ? prefs.appearance : {}
+ ) as AppearancePreferences;
+ if (appearance.theme || prefs.theme) theme.set((appearance.theme ?? prefs.theme) as Theme);
+ themeConfig.set(sanitizeThemeConfig(appearance.themeConfig));
if (prefs.sidebarOpen !== undefined) sidebarOpen.set(prefs.sidebarOpen as boolean);
if (prefs.sidebarWidth !== undefined) sidebarWidth.set(prefs.sidebarWidth as number);
// Support new toolApprovalMode and legacy boolean autoApproveTools
@@ -393,7 +413,13 @@ export async function loadPreferences(): Promise {
if (prefs.requestParams) requestParams.set(prefs.requestParams as Record);
if (prefs.showUpdateToast !== undefined)
showUpdateToastPref.set(prefs.showUpdateToast as boolean);
- textScale.set(typeof prefs.textScale === 'number' ? (prefs.textScale as number) : null);
+ textScale.set(
+ typeof appearance.textScale === 'number'
+ ? appearance.textScale
+ : typeof prefs.textScale === 'number'
+ ? (prefs.textScale as number)
+ : null
+ );
const pwaPrefs = prefs.pwa;
if (pwaPrefs)
pwaPreferences.set({
@@ -496,26 +522,19 @@ export async function initState(): Promise {
/** @deprecated Use initState */
export const loadStateFromServer = initState;
-// โโ Theme application โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
+// โโ Appearance application โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
-function applyTheme(t: Theme) {
- if (typeof window === 'undefined') return;
- let resolved = t;
- if (t === 'system') {
- resolved = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
- }
- document.documentElement.classList.toggle('dark', resolved === 'dark');
- document.documentElement.style.colorScheme = resolved;
- const meta = document.querySelector('meta[name="theme-color"]');
- if (meta) meta.setAttribute('content', resolved === 'dark' ? '#0d0d0d' : '#ffffff');
+function applyCurrentAppearance() {
+ applyAppearance(get(theme), get(themeConfig), get(textScale));
}
-theme.subscribe(applyTheme);
-textScale.subscribe((scale) => setTextScale(scale ?? 1));
+theme.subscribe(applyCurrentAppearance);
+themeConfig.subscribe(applyCurrentAppearance);
+textScale.subscribe(applyCurrentAppearance);
if (typeof window !== 'undefined') {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
- if (get(theme) === 'system') applyTheme('system');
+ if (get(theme) === 'system') applyCurrentAppearance();
});
}
@@ -534,6 +553,10 @@ if (typeof BroadcastChannel !== 'undefined') {
try {
if (type === 'theme' && value) {
theme.set(value);
+ } else if (type === 'appearance' && value) {
+ if (value.theme) theme.set(value.theme);
+ themeConfig.set(sanitizeThemeConfig(value.themeConfig));
+ textScale.set(typeof value.textScale === 'number' ? value.textScale : null);
} else if (type === 'locale' && value) {
changeLocale(value);
}
@@ -545,6 +568,28 @@ if (typeof BroadcastChannel !== 'undefined') {
theme.subscribe((t) => {
if (!_syncingFromBroadcast) {
channel.postMessage({ type: 'theme', value: t });
+ channel.postMessage({
+ type: 'appearance',
+ value: { theme: t, themeConfig: get(themeConfig), textScale: get(textScale) }
+ });
+ }
+ });
+
+ themeConfig.subscribe((config) => {
+ if (!_syncingFromBroadcast) {
+ channel.postMessage({
+ type: 'appearance',
+ value: { theme: get(theme), themeConfig: config, textScale: get(textScale) }
+ });
+ }
+ });
+
+ textScale.subscribe((scale) => {
+ if (!_syncingFromBroadcast) {
+ channel.postMessage({
+ type: 'appearance',
+ value: { theme: get(theme), themeConfig: get(themeConfig), textScale: scale }
+ });
}
});
diff --git a/cptr/frontend/src/lib/utils/appearance.ts b/cptr/frontend/src/lib/utils/appearance.ts
new file mode 100644
index 0000000..9e5f013
--- /dev/null
+++ b/cptr/frontend/src/lib/utils/appearance.ts
@@ -0,0 +1,125 @@
+import { setTextScale } from '$lib/utils/text-scale';
+
+export type Theme = 'dark' | 'light' | 'system';
+
+export type ThemeColors = {
+ background?: string;
+ foreground?: string;
+};
+
+export type ThemeConfig = {
+ light?: ThemeColors;
+ dark?: ThemeColors;
+ uiFont?: string;
+};
+
+export type AppearancePreferences = {
+ theme?: Theme;
+ themeConfig?: ThemeConfig | null;
+ textScale?: number | null;
+};
+
+type ResolvedTheme = 'dark' | 'light';
+
+const DEFAULT_UI_FONT =
+ "'Inter', -apple-system, BlinkMacSystemFont, ui-sans-serif, system-ui, sans-serif";
+
+export function resolveThemeMode(theme: Theme): ResolvedTheme {
+ if (theme === 'system' && typeof window !== 'undefined') {
+ return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
+ }
+ return theme === 'light' ? 'light' : 'dark';
+}
+
+export function normalizeHexColor(value: unknown): string | undefined {
+ if (typeof value !== 'string') return undefined;
+ const color = value.trim();
+ const short = /^#([0-9a-f]{3})$/i.exec(color);
+ if (short) {
+ return `#${short[1]
+ .split('')
+ .map((char) => char + char)
+ .join('')}`.toLowerCase();
+ }
+ if (/^#[0-9a-f]{6}$/i.test(color)) return color.toLowerCase();
+ return undefined;
+}
+
+function sanitizeThemeColors(value: unknown): ThemeColors | null {
+ if (!value || typeof value !== 'object') return null;
+ const raw = value as Record;
+ const next: ThemeColors = {};
+ const background = normalizeHexColor(raw.background);
+ const foreground = normalizeHexColor(raw.foreground);
+ if (background) next.background = background;
+ if (foreground) next.foreground = foreground;
+ return Object.keys(next).length ? next : null;
+}
+
+export function sanitizeThemeConfig(value: unknown): ThemeConfig | null {
+ if (!value || typeof value !== 'object') return null;
+ const raw = value as Record;
+ const next: ThemeConfig = {};
+ const light = sanitizeThemeColors(raw.light);
+ const dark = sanitizeThemeColors(raw.dark);
+ const legacy = sanitizeThemeColors(raw);
+ if (light) next.light = light;
+ if (dark) next.dark = dark;
+ if (legacy && !light && !dark) {
+ next.light = legacy;
+ next.dark = legacy;
+ }
+ if (typeof raw.uiFont === 'string' && raw.uiFont.trim()) {
+ next.uiFont = raw.uiFont.trim().slice(0, 240);
+ }
+ return Object.keys(next).length ? next : null;
+}
+
+export function defaultThemeConfig(theme: Theme): Required & { uiFont: string } {
+ const resolved = resolveThemeMode(theme);
+ return {
+ background: resolved === 'dark' ? '#000000' : '#ffffff',
+ foreground: resolved === 'dark' ? '#d4d4d4' : '#525252',
+ uiFont: DEFAULT_UI_FONT
+ };
+}
+
+export function resolveThemeConfig(
+ theme: Theme,
+ config: ThemeConfig | null
+): Required & { uiFont: string } {
+ const resolved = resolveThemeMode(theme);
+ return {
+ ...defaultThemeConfig(theme),
+ ...(config?.[resolved] ?? {}),
+ uiFont: config?.uiFont ?? DEFAULT_UI_FONT
+ };
+}
+
+function setVar(name: string, value: string) {
+ document.documentElement.style.setProperty(name, value);
+}
+
+export function applyAppearance(
+ theme: Theme,
+ config: ThemeConfig | null,
+ textScale: number | null
+) {
+ if (typeof document === 'undefined') return;
+
+ const resolved = resolveThemeMode(theme);
+ const merged = resolveThemeConfig(theme, config);
+
+ document.documentElement.classList.toggle('dark', resolved === 'dark');
+ document.documentElement.style.colorScheme = resolved;
+
+ setVar('--app-bg', merged.background);
+ setVar('--app-fg', merged.foreground);
+ setVar('--app-ui-font', merged.uiFont);
+ setVar('--font-sans', merged.uiFont);
+
+ setTextScale(textScale ?? 1);
+
+ const meta = document.querySelector('meta[name="theme-color"]');
+ if (meta) meta.setAttribute('content', merged.background);
+}
diff --git a/cptr/frontend/src/routes/+layout.svelte b/cptr/frontend/src/routes/+layout.svelte
index 1fbc6bc..7263f6b 100644
--- a/cptr/frontend/src/routes/+layout.svelte
+++ b/cptr/frontend/src/routes/+layout.svelte
@@ -421,7 +421,10 @@
{#if authState === 'checking'}
-
+
{:else if authState === 'needs_setup' || authState === 'needs_login'}
@@ -441,7 +444,8 @@
/>
{:else if $stateLoaded}
@@ -483,7 +487,10 @@
/>
{/if}
{:else}
-
+
{/if}
diff --git a/cptr/frontend/src/routes/+page.svelte b/cptr/frontend/src/routes/+page.svelte
index a2d0f29..12edf3b 100644
--- a/cptr/frontend/src/routes/+page.svelte
+++ b/cptr/frontend/src/routes/+page.svelte
@@ -982,6 +982,8 @@
height: 100%;
position: relative;
overflow: hidden;
+ background: var(--app-bg);
+ color: var(--app-fg);
}
.split-horizontal {
@@ -1014,6 +1016,8 @@
min-width: 0;
overflow: hidden;
position: relative;
+ background: var(--app-bg);
+ color: var(--app-fg);
}
/* โโ Divider โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */