Init Main project
This commit is contained in:
commit
9e581ae67f
220 changed files with 253987 additions and 0 deletions
83
src/client/theme.ts
Normal file
83
src/client/theme.ts
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
// The saviour you needed for your eyes, cus mine were burning before making this shit
|
||||
import { getSettings, saveSettings } from "./api.js";
|
||||
import type { SpaceWeather } from "../shared/types.js";
|
||||
|
||||
export function getColorMode(): "dark" | "light" {
|
||||
return getSettings().colorMode === "light" ? "light" : "dark";
|
||||
}
|
||||
|
||||
export function isReducedEffects(): boolean {
|
||||
return !!getSettings().reducedEffects;
|
||||
}
|
||||
|
||||
export function applyVisualPreferences(): void {
|
||||
const s = getSettings();
|
||||
document.documentElement.dataset.colorMode = s.colorMode;
|
||||
document.documentElement.classList.toggle(
|
||||
"reduced-effects",
|
||||
!!s.reducedEffects,
|
||||
);
|
||||
document.body.dataset.dynamicTheme =
|
||||
s.dynamicTheme && !s.reducedEffects ? "on" : "off";
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("sgywftp:theme-changed", {
|
||||
detail: { colorMode: s.colorMode, reducedEffects: !!s.reducedEffects },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function setColorMode(mode: "dark" | "light"): void {
|
||||
const s = getSettings();
|
||||
s.colorMode = mode;
|
||||
saveSettings(s);
|
||||
applyVisualPreferences();
|
||||
}
|
||||
|
||||
export function toggleColorMode(): "dark" | "light" {
|
||||
const next = getColorMode() === "light" ? "dark" : "light";
|
||||
setColorMode(next);
|
||||
return next;
|
||||
}
|
||||
|
||||
export function setReducedEffects(on: boolean): void {
|
||||
const s = getSettings();
|
||||
s.reducedEffects = on;
|
||||
saveSettings(s);
|
||||
applyVisualPreferences();
|
||||
}
|
||||
|
||||
export function toggleReducedEffects(): boolean {
|
||||
const next = !isReducedEffects();
|
||||
setReducedEffects(next);
|
||||
return next;
|
||||
}
|
||||
|
||||
export function syncSimulationTheme(opts: {
|
||||
weather?: SpaceWeather | null;
|
||||
target?: string | null;
|
||||
phase?: "idle" | "ascent" | "orbit" | "failed";
|
||||
}): void {
|
||||
const s = getSettings();
|
||||
document.documentElement.dataset.colorMode = s.colorMode;
|
||||
document.documentElement.classList.toggle(
|
||||
"reduced-effects",
|
||||
!!s.reducedEffects,
|
||||
);
|
||||
document.body.dataset.dynamicTheme =
|
||||
s.dynamicTheme && !s.reducedEffects ? "on" : "off";
|
||||
if (s.reducedEffects) {
|
||||
document.body.dataset.weather = "nominal";
|
||||
document.body.dataset.target = "earth";
|
||||
document.body.dataset.phase = "idle";
|
||||
return;
|
||||
}
|
||||
if (opts.weather) {
|
||||
document.body.dataset.weather = opts.weather;
|
||||
}
|
||||
if (opts.target) {
|
||||
document.body.dataset.target = opts.target;
|
||||
}
|
||||
if (opts.phase) {
|
||||
document.body.dataset.phase = opts.phase;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue