<meta name="color-scheme" content="light dark">
<script>
(() => {
"use strict";
const storageKey = "{{ calepin_theme_storage_key | default("calepin-website-theme") }}";
const param = "{{ calepin_theme_param | default("theme") }}";
const normalize = (value) => (value === "light" || value === "dark" ? value : "");
const root = document.documentElement;
const media = window.matchMedia ? window.matchMedia("(prefers-color-scheme: dark)") : null;
const systemTheme = () => media && media.matches ? "dark" : "light";
let mode = "";
if (param) {
try {
mode = normalize(new URL(window.location.href).searchParams.get(param) || "");
} catch {
mode = "";
}
}
if (!mode) {
try {
mode = normalize(localStorage.getItem(storageKey) || "");
} catch {
mode = "";
}
}
const theme = mode || systemTheme();
root.dataset.calepinThemeMode = mode;
root.dataset.theme = theme;
root.style.colorScheme = theme;
})();
</script>