PlotDirector/PlotLine/wwwroot/js/public-auth-theme.js

30 lines
1.5 KiB
JavaScript

// Only authentication may adopt the application palette, and only in an installed window.
(() => {
const root = document.documentElement;
const themes = ['warm-light', 'warm-dark', 'modern-light', 'modern-dark', 'rose-pink', 'baby-blue'];
const apply = () => {
const legacyStyles = document.getElementById("public-auth-base");
if (legacyStyles) legacyStyles.media = window.PlotDirectorPwa?.standalone ? "all" : "not all";
if (!window.PlotDirectorPwa?.standalone) {
delete root.dataset.appTheme;
root.dataset.siteTheme = 'public';
root.dataset.theme = root.dataset.bsTheme = 'light';
} else {
let cached = null, legacy = null;
try {
cached = localStorage.getItem('plotdirector.applicationTheme');
legacy = localStorage.getItem('plotline.theme');
} catch { }
const preferred = window.plotdirectorAuthTheme || cached;
const theme = themes.includes(preferred) ? preferred : legacy === 'dark' ? 'warm-dark' : 'warm-light';
delete root.dataset.siteTheme;
root.dataset.appTheme = theme;
root.dataset.theme = root.dataset.bsTheme = theme.endsWith('-dark') ? 'dark' : 'light';
}
document.querySelector('meta[name="theme-color"]')?.setAttribute('content', root.dataset.theme === 'dark' ? '#231e19' : '#f8f5ee');
};
apply();
window.addEventListener('plotdirector:pwa-mode-changed', apply);
window.addEventListener('pageshow', apply);
})();