fix(editor): init default theme observer value according to data-theme (#9698)

This commit is contained in:
donteatfriedrice
2025-01-15 04:04:06 +00:00
parent 419611f44c
commit 4f421efb22

View File

@@ -161,10 +161,17 @@ export class ThemeService extends Extension {
export class ThemeObserver {
private readonly observer: MutationObserver;
theme$ = signal(ColorScheme.Light);
theme$: Signal<ColorScheme>;
constructor() {
const COLOR_SCHEMES: string[] = Object.values(ColorScheme);
// Set initial theme according to the data-theme attribute
const initialMode = document.documentElement.dataset.theme;
this.theme$ = signal(
initialMode && COLOR_SCHEMES.includes(initialMode)
? (initialMode as ColorScheme)
: ColorScheme.Light
);
this.observer = new MutationObserver(() => {
const mode = document.documentElement.dataset.theme;
if (!mode) return;