15dcb09036
* Migrate check_copyright to Rust * Add a new lint to check accidental usages of /// in ts/svelte comments * Fix a bunch of incorrect jdoc comments * Move contributor check into minilints Will allow users to detect the issue locally with './ninja check' before pushing to CI. * Make Cargo.toml consistent with other crates
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
import { registerPackage } from "@tslib/runtime-require";
|
|
import { get, readable } from "svelte/store";
|
|
|
|
interface ThemeInfo {
|
|
isDark: boolean;
|
|
}
|
|
|
|
function getThemeFromRoot(): ThemeInfo {
|
|
return {
|
|
isDark: document.documentElement.classList.contains("night-mode"),
|
|
};
|
|
}
|
|
|
|
let setPageTheme: ((theme: ThemeInfo) => void) | null = null;
|
|
/** The current theme that applies to this document/shadow root. When
|
|
previewing cards in the card layout screen, this may not match the
|
|
theme Anki is using in its UI. */
|
|
export const pageTheme = readable(getThemeFromRoot(), (set) => {
|
|
setPageTheme = set;
|
|
});
|
|
// ensure setPageTheme is set immediately
|
|
get(pageTheme);
|
|
|
|
// Update theme when root element's class changes.
|
|
const observer = new MutationObserver((_mutationsList, _observer) => {
|
|
setPageTheme!(getThemeFromRoot());
|
|
});
|
|
observer.observe(document.documentElement, { attributeFilter: ["class"] });
|
|
|
|
registerPackage("anki/theme", {
|
|
pageTheme,
|
|
});
|