This commit is contained in:
Adorian Doran 2026-02-26 15:52:27 +02:00
parent 6a3c4fec98
commit 44dc8cf00d

View File

@ -34,6 +34,7 @@ export default class RootContainer extends FlexContainer<BasicWidget> {
window.visualViewport?.addEventListener("resize", () => this.#onMobileResize());
}
this.#initTheme();
this.#setDeviceSpecificClasses();
this.#setMaxContentWidth();
this.#setMotion();
@ -67,6 +68,20 @@ export default class RootContainer extends FlexContainer<BasicWidget> {
}
}
#initTheme() {
const colorSchemeChangeObserver = matchMedia("(prefers-color-scheme: dark)")
colorSchemeChangeObserver.addEventListener("change", () => this.#updateColorScheme());
this.#updateColorScheme();
}
#updateColorScheme() {
const colorScheme = readCssVar(document.body, "theme-style").asString();
document.body.classList.toggle("light-theme", colorScheme === "light");
document.body.classList.toggle("dark-theme", colorScheme === "dark");
}
#onMobileResize() {
const viewportHeight = window.visualViewport?.height ?? window.innerHeight;
const windowHeight = Math.max(window.innerHeight, this.originalWindowHeight); // inner height changes when keyboard is opened, we need to compare with the original height to detect it.