forked from authgear/authgear-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolorscheme.ts
More file actions
32 lines (26 loc) · 919 Bytes
/
colorscheme.ts
File metadata and controls
32 lines (26 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(function () {
const queryResult = window.matchMedia("(prefers-color-scheme: dark)");
function onChange() {
const htmlElement = document.documentElement;
const darkThemeEnabled =
htmlElement.getAttribute("data-dark-theme-enabled") === "true";
let explicitColorScheme = "";
const metaElement = document.querySelector("meta[name=x-color-scheme]");
if (metaElement instanceof HTMLMetaElement) {
explicitColorScheme = metaElement.content;
}
const implicitColorScheme = queryResult.matches ? "dark" : "light";
const colorScheme = !darkThemeEnabled
? "light"
: explicitColorScheme !== ""
? explicitColorScheme
: implicitColorScheme;
if (colorScheme === "dark") {
htmlElement.classList.add("dark");
} else {
htmlElement.classList.remove("dark");
}
}
queryResult.addEventListener("change", onChange);
onChange();
})();