Add theme settings, and remove the old theme system
This commit is contained in:
parent
567ac1a26d
commit
9f4a3197de
22 changed files with 2301 additions and 463 deletions
|
|
@ -5,13 +5,212 @@ import type {
|
|||
SavedRocketBlueprint,
|
||||
} from "../shared/types.js";
|
||||
|
||||
export type ShapeSet = "chamfered" | "smooth" | "sharp";
|
||||
export type ColorSet =
|
||||
| "eyebleed"
|
||||
| "subtle"
|
||||
| "low-contrast"
|
||||
| "catppuccin-mocha"
|
||||
| "daylight"
|
||||
| "gradient"
|
||||
| "custom";
|
||||
|
||||
export interface GradientThemeConfig {
|
||||
stops: string[];
|
||||
angle: number;
|
||||
mode: "linear" | "radial";
|
||||
surfaceBase: "dark" | "light";
|
||||
applyToPanels: boolean;
|
||||
}
|
||||
|
||||
export interface CustomThemeTokens {
|
||||
bgDeep: string;
|
||||
bgPanelSolid: string;
|
||||
bgElevated: string;
|
||||
border: string;
|
||||
text: string;
|
||||
textDim: string;
|
||||
accent: string;
|
||||
glow: string;
|
||||
green: string;
|
||||
amber: string;
|
||||
red: string;
|
||||
violet: string;
|
||||
panelOpacity: number;
|
||||
}
|
||||
|
||||
export interface ThemeConfig {
|
||||
shapeSet: ShapeSet;
|
||||
colorSet: ColorSet;
|
||||
uiEffects: boolean;
|
||||
motionEffects: boolean;
|
||||
dynamicAccent: boolean;
|
||||
gradient: GradientThemeConfig;
|
||||
custom: CustomThemeTokens;
|
||||
}
|
||||
|
||||
export interface ClientSettings {
|
||||
quality: "low" | "medium" | "high";
|
||||
sound: boolean;
|
||||
notifications: boolean;
|
||||
dynamicTheme: boolean;
|
||||
colorMode: "dark" | "light";
|
||||
reducedEffects: boolean;
|
||||
theme: ThemeConfig;
|
||||
}
|
||||
|
||||
interface LegacyClientSettings {
|
||||
quality?: "low" | "medium" | "high";
|
||||
sound?: boolean;
|
||||
notifications?: boolean;
|
||||
dynamicTheme?: boolean;
|
||||
colorMode?: "dark" | "light";
|
||||
reducedEffects?: boolean;
|
||||
theme?: Partial<ThemeConfig>;
|
||||
}
|
||||
|
||||
export const DEFAULT_GRADIENT_CONFIG: GradientThemeConfig = {
|
||||
stops: ["#0b1120", "#172554", "#0f172a"],
|
||||
angle: 135,
|
||||
mode: "linear",
|
||||
surfaceBase: "dark",
|
||||
applyToPanels: true,
|
||||
};
|
||||
|
||||
export const DEFAULT_CUSTOM_TOKENS: CustomThemeTokens = {
|
||||
bgDeep: "#0b0e14",
|
||||
bgPanelSolid: "#12161f",
|
||||
bgElevated: "#19202e",
|
||||
border: "#2a3449",
|
||||
text: "#e2e8f0",
|
||||
textDim: "#94a3b8",
|
||||
accent: "#60a5fa",
|
||||
glow: "#60a5fa",
|
||||
green: "#34d399",
|
||||
amber: "#f59e0b",
|
||||
red: "#f87171",
|
||||
violet: "#a78bfa",
|
||||
panelOpacity: 0.92,
|
||||
};
|
||||
|
||||
export const DEFAULT_THEME_CONFIG: ThemeConfig = {
|
||||
shapeSet: "chamfered",
|
||||
colorSet: "catppuccin-mocha",
|
||||
uiEffects: true,
|
||||
motionEffects: true,
|
||||
dynamicAccent: true,
|
||||
gradient: { ...DEFAULT_GRADIENT_CONFIG, stops: [...DEFAULT_GRADIENT_CONFIG.stops] },
|
||||
custom: { ...DEFAULT_CUSTOM_TOKENS },
|
||||
};
|
||||
|
||||
const VALID_SHAPE_SETS = new Set<ShapeSet>(["chamfered", "smooth", "sharp"]);
|
||||
const VALID_COLOR_SETS = new Set<ColorSet>([
|
||||
"eyebleed",
|
||||
"subtle",
|
||||
"low-contrast",
|
||||
"catppuccin-mocha",
|
||||
"daylight",
|
||||
"gradient",
|
||||
"custom",
|
||||
]);
|
||||
|
||||
function normalizeStoredHex(val: unknown, fallback: string): string {
|
||||
if (typeof val !== "string") return fallback;
|
||||
const trimmed = val.trim();
|
||||
if (/^#[0-9a-fA-F]{6}$/.test(trimmed)) return trimmed.toLowerCase();
|
||||
if (/^#[0-9a-fA-F]{3}$/.test(trimmed)) {
|
||||
const [, r, g, b] = trimmed;
|
||||
return `#${r}${r}${g}${g}${b}${b}`.toLowerCase();
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function normalizeThemeConfig(
|
||||
rawTheme?: Partial<ThemeConfig> | null,
|
||||
legacy?: LegacyClientSettings,
|
||||
): ThemeConfig {
|
||||
const legacyReduced = !!legacy?.reducedEffects;
|
||||
const legacyLight = legacy?.colorMode === "light";
|
||||
const legacyDyn = legacy?.dynamicTheme ?? true;
|
||||
|
||||
if (!rawTheme) {
|
||||
return {
|
||||
shapeSet: legacyReduced ? "smooth" : "chamfered",
|
||||
colorSet: legacyLight
|
||||
? "daylight"
|
||||
: legacyReduced
|
||||
? "subtle"
|
||||
: "catppuccin-mocha",
|
||||
uiEffects: !legacyReduced,
|
||||
motionEffects: !legacyReduced,
|
||||
dynamicAccent: legacyReduced ? false : legacyDyn,
|
||||
gradient: {
|
||||
...DEFAULT_GRADIENT_CONFIG,
|
||||
stops: [...DEFAULT_GRADIENT_CONFIG.stops],
|
||||
},
|
||||
custom: { ...DEFAULT_CUSTOM_TOKENS },
|
||||
};
|
||||
}
|
||||
|
||||
const rawGrad = rawTheme.gradient;
|
||||
const rawStops = Array.isArray(rawGrad?.stops)
|
||||
? rawGrad.stops
|
||||
.slice(0, 3)
|
||||
.map((s, idx) =>
|
||||
normalizeStoredHex(s, DEFAULT_GRADIENT_CONFIG.stops[idx] ?? "#0f172a"),
|
||||
)
|
||||
: [...DEFAULT_GRADIENT_CONFIG.stops];
|
||||
while (rawStops.length < 2) {
|
||||
rawStops.push(DEFAULT_GRADIENT_CONFIG.stops[rawStops.length] ?? "#172554");
|
||||
}
|
||||
|
||||
const rawCustom = rawTheme.custom;
|
||||
const angleNum = Number(rawGrad?.angle);
|
||||
const opacityNum = Number(rawCustom?.panelOpacity);
|
||||
|
||||
return {
|
||||
shapeSet: VALID_SHAPE_SETS.has(rawTheme.shapeSet as ShapeSet)
|
||||
? (rawTheme.shapeSet as ShapeSet)
|
||||
: "chamfered",
|
||||
colorSet: VALID_COLOR_SETS.has(rawTheme.colorSet as ColorSet)
|
||||
? (rawTheme.colorSet as ColorSet)
|
||||
: "catppuccin-mocha",
|
||||
uiEffects: rawTheme.uiEffects ?? true,
|
||||
motionEffects: rawTheme.motionEffects ?? true,
|
||||
dynamicAccent: rawTheme.dynamicAccent ?? true,
|
||||
gradient: {
|
||||
stops: rawStops,
|
||||
angle: Number.isFinite(angleNum)
|
||||
? Math.max(0, Math.min(360, Math.round(angleNum)))
|
||||
: DEFAULT_GRADIENT_CONFIG.angle,
|
||||
mode: rawGrad?.mode === "radial" ? "radial" : "linear",
|
||||
surfaceBase: rawGrad?.surfaceBase === "light" ? "light" : "dark",
|
||||
applyToPanels: rawGrad?.applyToPanels ?? true,
|
||||
},
|
||||
custom: {
|
||||
bgDeep: normalizeStoredHex(rawCustom?.bgDeep, DEFAULT_CUSTOM_TOKENS.bgDeep),
|
||||
bgPanelSolid: normalizeStoredHex(
|
||||
rawCustom?.bgPanelSolid,
|
||||
DEFAULT_CUSTOM_TOKENS.bgPanelSolid,
|
||||
),
|
||||
bgElevated: normalizeStoredHex(
|
||||
rawCustom?.bgElevated,
|
||||
DEFAULT_CUSTOM_TOKENS.bgElevated,
|
||||
),
|
||||
border: normalizeStoredHex(rawCustom?.border, DEFAULT_CUSTOM_TOKENS.border),
|
||||
text: normalizeStoredHex(rawCustom?.text, DEFAULT_CUSTOM_TOKENS.text),
|
||||
textDim: normalizeStoredHex(
|
||||
rawCustom?.textDim,
|
||||
DEFAULT_CUSTOM_TOKENS.textDim,
|
||||
),
|
||||
accent: normalizeStoredHex(rawCustom?.accent, DEFAULT_CUSTOM_TOKENS.accent),
|
||||
glow: normalizeStoredHex(rawCustom?.glow, DEFAULT_CUSTOM_TOKENS.glow),
|
||||
green: normalizeStoredHex(rawCustom?.green, DEFAULT_CUSTOM_TOKENS.green),
|
||||
amber: normalizeStoredHex(rawCustom?.amber, DEFAULT_CUSTOM_TOKENS.amber),
|
||||
red: normalizeStoredHex(rawCustom?.red, DEFAULT_CUSTOM_TOKENS.red),
|
||||
violet: normalizeStoredHex(rawCustom?.violet, DEFAULT_CUSTOM_TOKENS.violet),
|
||||
panelOpacity: Number.isFinite(opacityNum)
|
||||
? Math.max(0.65, Math.min(1, opacityNum))
|
||||
: DEFAULT_CUSTOM_TOKENS.panelOpacity,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const TOKEN_KEY = "spacegaem_proto_token";
|
||||
|
|
@ -36,39 +235,35 @@ export function setToken(t: string | null): void {
|
|||
else localStorage.removeItem(TOKEN_KEY);
|
||||
}
|
||||
|
||||
let cachedSettings: ClientSettings | null = null;
|
||||
|
||||
export function getSettings(): ClientSettings {
|
||||
if (cachedSettings) return cachedSettings;
|
||||
try {
|
||||
const raw = JSON.parse(
|
||||
localStorage.getItem(SETTINGS_KEY) ?? "{}",
|
||||
) as Partial<ClientSettings>;
|
||||
return {
|
||||
quality: raw.quality ?? "high",
|
||||
) as LegacyClientSettings;
|
||||
cachedSettings = {
|
||||
quality:
|
||||
raw.quality === "low" || raw.quality === "medium" ? raw.quality : "high",
|
||||
sound: raw.sound ?? true,
|
||||
notifications: raw.notifications ?? true,
|
||||
dynamicTheme: raw.dynamicTheme ?? true,
|
||||
colorMode: raw.colorMode === "light" ? "light" : "dark",
|
||||
reducedEffects: raw.reducedEffects ?? false,
|
||||
theme: normalizeThemeConfig(raw.theme, raw),
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
cachedSettings = {
|
||||
quality: "high",
|
||||
sound: true,
|
||||
notifications: true,
|
||||
dynamicTheme: true,
|
||||
colorMode: "dark",
|
||||
reducedEffects: false,
|
||||
theme: normalizeThemeConfig(null),
|
||||
};
|
||||
}
|
||||
return cachedSettings;
|
||||
}
|
||||
|
||||
export function saveSettings(s: ClientSettings): void {
|
||||
localStorage.setItem(SETTINGS_KEY, JSON.stringify(s));
|
||||
document.body.dataset.dynamicTheme = s.dynamicTheme ? "on" : "off";
|
||||
document.documentElement.dataset.colorMode = s.colorMode;
|
||||
document.documentElement.classList.toggle(
|
||||
"reduced-effects",
|
||||
!!s.reducedEffects,
|
||||
);
|
||||
cachedSettings = s;
|
||||
}
|
||||
|
||||
async function request<T = any>(
|
||||
|
|
|
|||
|
|
@ -15,15 +15,8 @@ import {
|
|||
state,
|
||||
type WikiScreenParams,
|
||||
} from "./state.js";
|
||||
import { applyVisualPreferences } from "./theme.js";
|
||||
import {
|
||||
getColorMode,
|
||||
isReducedEffects,
|
||||
toggleColorMode,
|
||||
toggleReducedEffects,
|
||||
} from "./theme.js";
|
||||
import {
|
||||
clear,
|
||||
h,
|
||||
initNotificationDrawer,
|
||||
initTooltipController,
|
||||
toast,
|
||||
|
|
@ -57,46 +50,6 @@ registerScreenRenderers({
|
|||
wiki: (el, p) => renderWiki(el, p as WikiScreenParams),
|
||||
});
|
||||
|
||||
function renderComfortToolbar(): void {
|
||||
const root = document.getElementById("comfort-controls-root");
|
||||
if (!root) return;
|
||||
clear(root);
|
||||
const mode = getColorMode();
|
||||
const reduced = isReducedEffects();
|
||||
root.appendChild(
|
||||
h(
|
||||
"div",
|
||||
{ class: "comfort-pill-bar" },
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: `comfort-btn ${mode === "light" ? "active" : ""}`,
|
||||
title: "Toggle Daylight Light Mode / Dark Mode",
|
||||
onClick: () => {
|
||||
toggleColorMode();
|
||||
renderComfortToolbar();
|
||||
},
|
||||
},
|
||||
mode === "light" ? "SUN LIGHT" : "DARK",
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: `comfort-btn ${reduced ? "active" : ""}`,
|
||||
title:
|
||||
"Toggle Eye-Saver (Reduced Effects: disables glows, scanlines & shake)",
|
||||
onClick: () => {
|
||||
toggleReducedEffects();
|
||||
applyThemeFromState();
|
||||
renderComfortToolbar();
|
||||
},
|
||||
},
|
||||
reduced ? "EYE-SAVER ON" : "EYE-SAVER",
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async function waitForStylesAndLoad(): Promise<void> {
|
||||
const pendingLinks = Array.from(
|
||||
document.querySelectorAll('link[rel="stylesheet"]'),
|
||||
|
|
@ -125,8 +78,7 @@ async function waitForStylesAndLoad(): Promise<void> {
|
|||
async function boot(): Promise<void> {
|
||||
saveSettings(getSettings());
|
||||
applyThemeFromState();
|
||||
renderComfortToolbar();
|
||||
window.addEventListener("sgywftp:theme-changed", renderComfortToolbar);
|
||||
applyVisualPreferences();
|
||||
initNotificationDrawer();
|
||||
initTooltipController();
|
||||
initWalkthroughController();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import * as THREE from "three";
|
|||
import { navigate } from "../router.js";
|
||||
import { refreshMe, refreshWorld } from "../session.js";
|
||||
import { currentContract, state } from "../state.js";
|
||||
import { getThemePalette } from "../theme.js";
|
||||
import { encodeModelPath, loadFittedModel } from "../three/modelLoader.js";
|
||||
import { buildLaunchComplex, buildRocketMesh } from "../three/rocketMesh.js";
|
||||
import { createView } from "../three/sceneManager.js";
|
||||
|
|
@ -12,7 +13,7 @@ import {
|
|||
isPartUnlocked,
|
||||
validateDesign,
|
||||
} from "../../shared/physics.js";
|
||||
import { h } from "../ui.js";
|
||||
import { h, openThemeSettingsModal } from "../ui.js";
|
||||
import {
|
||||
createFlightsPanel,
|
||||
createHazardPanel,
|
||||
|
|
@ -43,18 +44,24 @@ export function renderDashboard(root: HTMLElement): () => void {
|
|||
const sidebarEl = h("div", { class: "dash-sidebar" });
|
||||
const view = createView(viewportEl, { fov: 44, far: 15000 });
|
||||
view.addStars(2600, 5000);
|
||||
view.scene.fog = new THREE.FogExp2(0x0b0e14, 0.0028);
|
||||
const apron = new THREE.Mesh(
|
||||
new THREE.CircleGeometry(140, 48),
|
||||
new THREE.MeshStandardMaterial({
|
||||
color: 0x151b26,
|
||||
roughness: 0.9,
|
||||
metalness: 0.1,
|
||||
}),
|
||||
);
|
||||
const apronMat = new THREE.MeshStandardMaterial({
|
||||
color: 0x151b26,
|
||||
roughness: 0.9,
|
||||
metalness: 0.1,
|
||||
});
|
||||
const apron = new THREE.Mesh(new THREE.CircleGeometry(140, 48), apronMat);
|
||||
apron.rotation.x = -Math.PI / 2;
|
||||
apron.position.y = -0.15;
|
||||
view.scene.add(apron);
|
||||
const syncDashboardAtmosphere = () => {
|
||||
const pal = getThemePalette();
|
||||
view.scene.fog = pal.isGradient
|
||||
? null
|
||||
: new THREE.FogExp2(pal.sceneBgWithStars, 0.0028);
|
||||
apronMat.color.set(pal.isLight ? 0x64748b : 0x151b26);
|
||||
};
|
||||
syncDashboardAtmosphere();
|
||||
window.addEventListener("sgywftp:theme-changed", syncDashboardAtmosphere);
|
||||
let padSubject: THREE.Group | null = null;
|
||||
let disposed = false;
|
||||
async function populatePad() {
|
||||
|
|
@ -173,6 +180,14 @@ export function renderDashboard(root: HTMLElement): () => void {
|
|||
},
|
||||
"Wiki & Tutorial",
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "btn xs",
|
||||
onClick: () => openThemeSettingsModal(),
|
||||
},
|
||||
"Theme Settings",
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{ class: "btn xs ghost", onClick: () => navigate("mainMenu") },
|
||||
|
|
@ -358,6 +373,10 @@ export function renderDashboard(root: HTMLElement): () => void {
|
|||
return () => {
|
||||
disposed = true;
|
||||
window.clearInterval(poll);
|
||||
window.removeEventListener(
|
||||
"sgywftp:theme-changed",
|
||||
syncDashboardAtmosphere,
|
||||
);
|
||||
view.dispose();
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,20 @@
|
|||
// Effects so it looks cool and people ignore how broken things probably are
|
||||
import * as THREE from "three";
|
||||
import { setPlumeAtmosphere } from "../../three/rocketMesh.js";
|
||||
import { getColorMode, isReducedEffects } from "../../theme.js";
|
||||
import {
|
||||
getThemePalette,
|
||||
isReducedMotionEffects,
|
||||
type ResolvedThemePalette,
|
||||
} from "../../theme.js";
|
||||
import type { TelemetrySample } from "../../../shared/types.js";
|
||||
import type { LaunchContext } from "./context.js";
|
||||
import { advanceGpuPool, spawnExhaustParticle } from "./particles.js";
|
||||
|
||||
const skyLow = new THREE.Color(0x0c1a33);
|
||||
const skyMid = new THREE.Color(0x091020);
|
||||
const skySpace = new THREE.Color(0x0b0e14);
|
||||
let lastPalette: ResolvedThemePalette | null = null;
|
||||
const daySkyLowColor = new THREE.Color(0x0c1a33);
|
||||
const spaceColor = new THREE.Color(0x0b0e14);
|
||||
const tmpColor = new THREE.Color();
|
||||
const nozzleWorldPos = new THREE.Vector3();
|
||||
const exhaustDir = new THREE.Vector3();
|
||||
|
|
@ -38,8 +44,9 @@ export function updateAscentVisuals(
|
|||
const prevPos = ctx.rocketRoot.position.clone();
|
||||
ctx.rocketRoot.position.set(visDr, visAlt + ctx.cgPivotY, 0);
|
||||
ctx.rocketRoot.rotation.z = -((90 - sample.pitchDeg) * Math.PI) / 180;
|
||||
const reducedMotion = isReducedMotionEffects();
|
||||
const aoaBuffet =
|
||||
!isReducedEffects() &&
|
||||
!reducedMotion &&
|
||||
sample.dynamicPressure > 15000 &&
|
||||
Math.abs(sample.aoaDeg ?? 0) > 6
|
||||
? Math.sin(now * 0.045) * 0.025
|
||||
|
|
@ -78,7 +85,7 @@ export function updateAscentVisuals(
|
|||
const qShake = Math.max(0, sample.dynamicPressure / 65000 - 0.12) * 0.48;
|
||||
const gShake = Math.max(0, sample.gLoad - 2.2) * 0.09;
|
||||
const shakeAmp =
|
||||
ctx.paused || isReducedEffects()
|
||||
ctx.paused || reducedMotion
|
||||
? 0
|
||||
: Math.min(0.65, qShake + gShake + (sample.thrusting ? 0.04 : 0));
|
||||
if (shakeAmp > 0.01) {
|
||||
|
|
@ -89,12 +96,17 @@ export function updateAscentVisuals(
|
|||
);
|
||||
ctx.view.camera.position.add(ctx.prevShake);
|
||||
}
|
||||
const daySkyLow =
|
||||
getColorMode() === "light" ? new THREE.Color(0xcbdcf0) : skyLow;
|
||||
const pal = getThemePalette();
|
||||
if (pal !== lastPalette) {
|
||||
lastPalette = pal;
|
||||
daySkyLowColor.set(pal.isLight ? pal.daySkyLow : "#0c1a33");
|
||||
spaceColor.set(pal.isGradient ? "#0b0e14" : pal.sceneBgWithStars);
|
||||
}
|
||||
const daySkyLow = pal.isLight ? daySkyLowColor : skyLow;
|
||||
if (altKm < 25) {
|
||||
tmpColor.lerpColors(daySkyLow, skyMid, Math.min(1, altKm / 25));
|
||||
} else {
|
||||
tmpColor.lerpColors(skyMid, skySpace, Math.min(1, (altKm - 25) / 55));
|
||||
tmpColor.lerpColors(skyMid, spaceColor, Math.min(1, (altKm - 25) / 55));
|
||||
}
|
||||
ctx.view.scene.background = tmpColor;
|
||||
if (ctx.rocketHandle && sample.stage > ctx.highestStageShown) {
|
||||
|
|
@ -230,8 +242,8 @@ export function updateAscentVisuals(
|
|||
burning && (preIgnition ? idx === 0 : idx === activeIdx);
|
||||
plume.visible = shouldShow;
|
||||
if (shouldShow) {
|
||||
const effJitter = isReducedEffects() ? 1.0 : jitter;
|
||||
const yJit = isReducedEffects() ? 1.0 : 0.92 + Math.random() * 0.18;
|
||||
const effJitter = reducedMotion ? 1.0 : jitter;
|
||||
const yJit = reducedMotion ? 1.0 : 0.92 + Math.random() * 0.18;
|
||||
plume.scale.set(
|
||||
throttleScale * effJitter * vacExpand,
|
||||
throttleScale * yJit * (1 + Math.min(1.05, altKm / 55)),
|
||||
|
|
@ -249,7 +261,7 @@ export function updateAscentVisuals(
|
|||
.set(0, -1, 0)
|
||||
.applyEuler(ctx.rocketRoot.rotation)
|
||||
.normalize();
|
||||
const red = isReducedEffects();
|
||||
const red = reducedMotion;
|
||||
const spawns = (altM < 250 ? 5 : altKm < 38 ? 3 : 2) * (red ? 0.5 : 1);
|
||||
const spawnCount = Math.max(1, Math.round(spawns));
|
||||
for (let s = 0; s < spawnCount; s++) {
|
||||
|
|
@ -366,7 +378,7 @@ export function updateAscentVisuals(
|
|||
if (showMach) {
|
||||
const strength = Math.max(0, 1 - Math.abs(mach - 1.03) / 0.24);
|
||||
ctx.machConeMat.uniforms.uOpacity.value =
|
||||
strength * (isReducedEffects() ? 0.36 : 0.42 + Math.random() * 0.14);
|
||||
strength * (reducedMotion ? 0.36 : 0.42 + Math.random() * 0.14);
|
||||
const s = 0.9 + strength * 0.35;
|
||||
ctx.machCone.scale.set(s, s, s);
|
||||
}
|
||||
|
|
@ -375,7 +387,7 @@ export function updateAscentVisuals(
|
|||
const showPlasma = sample.heatFluxWcm2 > 5;
|
||||
ctx.plasmaGlow.visible = showPlasma;
|
||||
if (showPlasma) {
|
||||
const jit = isReducedEffects() ? 1.0 : 0.88 + Math.random() * 0.2;
|
||||
const jit = reducedMotion ? 1.0 : 0.88 + Math.random() * 0.2;
|
||||
ctx.plasmaGlowMat.uniforms.uOpacity.value = Math.min(
|
||||
0.68,
|
||||
((sample.heatFluxWcm2 - 5) / 36) * jit,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Ascent sky, curved Earth horizon, clouds, and supersonic aero shock shaders
|
||||
import * as THREE from "three";
|
||||
import { getSettings } from "../../api.js";
|
||||
import { isReducedEffects } from "../../theme.js";
|
||||
import { isReducedMotionEffects } from "../../theme.js";
|
||||
import type { RocketMeshHandle } from "../../three/rocketMesh.js";
|
||||
import { getSoftParticleTexture } from "../../three/sceneManager.js";
|
||||
import { createGpuParticlePool, type GpuParticlePool } from "./particles.js";
|
||||
|
|
@ -155,7 +155,7 @@ export function createAscentEnvironment(): {
|
|||
env.add(m);
|
||||
}
|
||||
const q = getSettings().quality;
|
||||
const red = isReducedEffects();
|
||||
const red = isReducedMotionEffects();
|
||||
const smokeCount = Math.round(
|
||||
(q === "low" ? 300 : q === "medium" ? 700 : 1200) * (red ? 0.5 : 1),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Cool lookin stuff
|
||||
import { navigate } from "../../router.js";
|
||||
import { state } from "../../state.js";
|
||||
import { getColorMode } from "../../theme.js";
|
||||
import { getThemePalette } from "../../theme.js";
|
||||
import { getUnlockedDiagnosticTier } from "../../../shared/physics.js";
|
||||
import type { TelemetrySample } from "../../../shared/types.js";
|
||||
import { clear, fmtNum, h, term } from "../../ui.js";
|
||||
|
|
@ -215,7 +215,7 @@ export function updateTelemetryHud(
|
|||
if (c2d) {
|
||||
const W = ctx.liveStripCanvas.width;
|
||||
const H = ctx.liveStripCanvas.height;
|
||||
c2d.fillStyle = getColorMode() === "light" ? "#f1f5f9" : "#090d14";
|
||||
c2d.fillStyle = getThemePalette().bgDeep;
|
||||
c2d.fillRect(0, 0, W, H);
|
||||
const drawLine = (
|
||||
col: string,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Spin
|
||||
import * as THREE from "three";
|
||||
import { applyThemeFromState, currentContract } from "../../state.js";
|
||||
import { getThemePalette } from "../../theme.js";
|
||||
import { BODY_RADIUS_KM } from "../../../shared/ephemeris.js";
|
||||
import type { SimResult, TelemetrySample } from "../../../shared/types.js";
|
||||
import type { LaunchContext } from "./context.js";
|
||||
|
|
@ -85,7 +86,10 @@ export function enterOrbitPhase(ctx: LaunchContext): void {
|
|||
ctx.debrisList.length = 0;
|
||||
ctx.jettisonedDropStages.clear();
|
||||
ctx.hudVals = null;
|
||||
ctx.view.scene.background = new THREE.Color(0x0b0e14);
|
||||
const pal = getThemePalette();
|
||||
ctx.view.scene.background = pal.isGradient
|
||||
? null
|
||||
: new THREE.Color(pal.sceneBgWithStars);
|
||||
ctx.orbitGroup = new THREE.Group();
|
||||
const target =
|
||||
ctx.trajectory?.target ??
|
||||
|
|
|
|||
|
|
@ -11,83 +11,97 @@ import {
|
|||
import { navigate } from "../router.js";
|
||||
import { refreshMe, refreshWorld, startEvents } from "../session.js";
|
||||
import { state } from "../state.js";
|
||||
import {
|
||||
COLOR_SET_OPTIONS,
|
||||
getThemeConfig,
|
||||
SHAPE_SET_OPTIONS,
|
||||
} from "../theme.js";
|
||||
import { createView } from "../three/sceneManager.js";
|
||||
import { buildSolarSystem } from "../three/solarSystem.js";
|
||||
import { h, modal, toast } from "../ui.js";
|
||||
import { h, modal, openThemeSettingsModal, toast } from "../ui.js";
|
||||
|
||||
function openSettingsModal(): void {
|
||||
const s = { ...getSettings() };
|
||||
const initial = getSettings();
|
||||
let quality = initial.quality;
|
||||
let sound = initial.sound;
|
||||
let notifications = initial.notifications;
|
||||
const qualitySel = h(
|
||||
"select",
|
||||
{
|
||||
class: "input",
|
||||
onChange: () => {
|
||||
s.quality = qualitySel.value as typeof s.quality;
|
||||
quality = qualitySel.value as typeof quality;
|
||||
},
|
||||
},
|
||||
h(
|
||||
"option",
|
||||
{ value: "low", selected: s.quality === "low" },
|
||||
{ value: "low", selected: quality === "low" },
|
||||
"Low (1x DPR, low shadow/antialias)",
|
||||
),
|
||||
h(
|
||||
"option",
|
||||
{ value: "medium", selected: s.quality === "medium" },
|
||||
{ value: "medium", selected: quality === "medium" },
|
||||
"Medium (1.5x DPR)",
|
||||
),
|
||||
h(
|
||||
"option",
|
||||
{ value: "high", selected: s.quality === "high" },
|
||||
{ value: "high", selected: quality === "high" },
|
||||
"High (Native DPR + antialias)",
|
||||
),
|
||||
);
|
||||
const colorModeSel = h(
|
||||
"select",
|
||||
{
|
||||
class: "input",
|
||||
onChange: () => {
|
||||
s.colorMode = colorModeSel.value as "dark" | "light";
|
||||
},
|
||||
},
|
||||
h(
|
||||
"option",
|
||||
{ value: "dark", selected: s.colorMode === "dark" },
|
||||
"Dark Slate (Default Night Ops)",
|
||||
),
|
||||
h(
|
||||
"option",
|
||||
{ value: "light", selected: s.colorMode === "light" },
|
||||
"Daylight Clean (Light Mode)",
|
||||
),
|
||||
);
|
||||
const reducedChk = h("input", {
|
||||
type: "checkbox",
|
||||
checked: s.reducedEffects,
|
||||
onChange: () => {
|
||||
s.reducedEffects = reducedChk.checked;
|
||||
},
|
||||
});
|
||||
const soundChk = h("input", {
|
||||
type: "checkbox",
|
||||
checked: s.sound,
|
||||
checked: sound,
|
||||
onChange: () => {
|
||||
s.sound = soundChk.checked;
|
||||
sound = soundChk.checked;
|
||||
},
|
||||
});
|
||||
const notifChk = h("input", {
|
||||
type: "checkbox",
|
||||
checked: s.notifications,
|
||||
checked: notifications,
|
||||
onChange: () => {
|
||||
s.notifications = notifChk.checked;
|
||||
},
|
||||
});
|
||||
const dynChk = h("input", {
|
||||
type: "checkbox",
|
||||
checked: s.dynamicTheme,
|
||||
onChange: () => {
|
||||
s.dynamicTheme = dynChk.checked;
|
||||
notifications = notifChk.checked;
|
||||
},
|
||||
});
|
||||
const themeSummaryBadge = h("span", { class: "badge info" }, "");
|
||||
const syncThemeBadge = () => {
|
||||
const t = getThemeConfig();
|
||||
const shapeLabel =
|
||||
SHAPE_SET_OPTIONS.find((o) => o.id === t.shapeSet)?.label ?? t.shapeSet;
|
||||
const colorLabel =
|
||||
COLOR_SET_OPTIONS.find((o) => o.id === t.colorSet)?.label ?? t.colorSet;
|
||||
themeSummaryBadge.textContent = `${shapeLabel} · ${colorLabel}`;
|
||||
};
|
||||
syncThemeBadge();
|
||||
window.addEventListener("sgywftp:theme-changed", syncThemeBadge);
|
||||
const themeRow = h(
|
||||
"div",
|
||||
{ class: "slot-group" },
|
||||
h(
|
||||
"div",
|
||||
{ class: "spread" },
|
||||
h("span", { class: "slot-title" }, "Theme & Appearance"),
|
||||
themeSummaryBadge,
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "spread" },
|
||||
h(
|
||||
"span",
|
||||
{ class: "dim", style: { fontSize: "11px" } },
|
||||
"Shape-set, color presets, gradients, custom palette & comfort effects",
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: "btn sm",
|
||||
onClick: () => openThemeSettingsModal(),
|
||||
},
|
||||
"Theme Settings",
|
||||
),
|
||||
),
|
||||
);
|
||||
const mlRow = h(
|
||||
"div",
|
||||
{ class: "slot-group", style: { marginTop: "6px" } },
|
||||
|
|
@ -153,17 +167,7 @@ function openSettingsModal(): void {
|
|||
"div",
|
||||
{ class: "col" },
|
||||
h("label", { class: "field" }, "3D Graphics Quality", qualitySel),
|
||||
h("label", { class: "field" }, "Color Theme", colorModeSel),
|
||||
h(
|
||||
"label",
|
||||
{ class: "row", style: { cursor: "pointer" } },
|
||||
reducedChk,
|
||||
h(
|
||||
"span",
|
||||
{},
|
||||
"Reduced Effects / Eye-Saver (disables glows, blur, chamfers, scanlines & camera shake)",
|
||||
),
|
||||
),
|
||||
themeRow,
|
||||
h(
|
||||
"label",
|
||||
{ class: "row", style: { cursor: "pointer" } },
|
||||
|
|
@ -176,26 +180,24 @@ function openSettingsModal(): void {
|
|||
notifChk,
|
||||
h("span", {}, "Mission & Space Weather Notifications"),
|
||||
),
|
||||
h(
|
||||
"label",
|
||||
{ class: "row", style: { cursor: "pointer" } },
|
||||
dynChk,
|
||||
h(
|
||||
"span",
|
||||
{},
|
||||
"Dynamic Simulation Color Palette (shifts with space weather & target)",
|
||||
),
|
||||
),
|
||||
mlRow,
|
||||
);
|
||||
const cleanupBadge = () =>
|
||||
window.removeEventListener("sgywftp:theme-changed", syncThemeBadge);
|
||||
modal("System & Graphics Settings", body, [
|
||||
{ label: "Cancel", kind: "ghost" },
|
||||
{ label: "Cancel", kind: "ghost", onClick: cleanupBadge },
|
||||
{
|
||||
label: "Save Settings",
|
||||
kind: "primary",
|
||||
onClick: () => {
|
||||
saveSettings(s);
|
||||
window.dispatchEvent(new CustomEvent("sgywftp:theme-changed"));
|
||||
cleanupBadge();
|
||||
const latest = getSettings();
|
||||
saveSettings({
|
||||
...latest,
|
||||
quality,
|
||||
sound,
|
||||
notifications,
|
||||
});
|
||||
toast("Settings saved.", "ok");
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ import {
|
|||
type MissionConfigContext,
|
||||
} from "./missionConfig/prelaunch.js";
|
||||
|
||||
export function renderMissionConfig(root: HTMLElement): void {
|
||||
export function renderMissionConfig(root: HTMLElement): () => void {
|
||||
const agency = state.agency;
|
||||
if (!agency) {
|
||||
navigate("auth");
|
||||
return;
|
||||
return () => {};
|
||||
}
|
||||
const contract = currentContract();
|
||||
const workingDesign = normalizeDesign(
|
||||
|
|
@ -377,5 +377,10 @@ export function renderMissionConfig(root: HTMLElement): void {
|
|||
),
|
||||
);
|
||||
recomputePreview();
|
||||
const onThemeChanged = () => renderDiagPanel(ctx);
|
||||
window.addEventListener("sgywftp:theme-changed", onThemeChanged);
|
||||
root.appendChild(h("div", { class: "screen param-root" }, mainCol, sideCol));
|
||||
return () => {
|
||||
window.removeEventListener("sgywftp:theme-changed", onThemeChanged);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import type {
|
|||
SimResult,
|
||||
TrajectoryResult,
|
||||
} from "../../../shared/types.js";
|
||||
import { getColorMode } from "../../theme.js";
|
||||
import { getThemePalette } from "../../theme.js";
|
||||
import { clear, fmtDuration, fmtNum, h } from "../../ui.js";
|
||||
|
||||
export function drawAscentChart(
|
||||
|
|
@ -17,12 +17,14 @@ export function drawAscentChart(
|
|||
): void {
|
||||
const ctx = ascentCanvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
const light = getColorMode() === "light";
|
||||
const pal = getThemePalette();
|
||||
const W = ascentCanvas.width;
|
||||
const H = ascentCanvas.height;
|
||||
ctx.fillStyle = light ? "#f8fafc" : "#0b0e14";
|
||||
ctx.fillStyle = pal.bgDeep;
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
ctx.strokeStyle = light ? "rgba(15, 23, 42, 0.12)" : "rgba(42, 52, 73, 0.55)";
|
||||
ctx.save();
|
||||
ctx.strokeStyle = pal.border;
|
||||
ctx.globalAlpha = 0.55;
|
||||
ctx.lineWidth = 1;
|
||||
for (let i = 1; i < 5; i++) {
|
||||
const y = (H / 5) * i;
|
||||
|
|
@ -31,6 +33,7 @@ export function drawAscentChart(
|
|||
ctx.lineTo(W - 14, y);
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
const pts = sim.telemetry;
|
||||
if (!pts.length) return;
|
||||
const maxDr = Math.max(250, ...pts.map((p) => p.downrange / 1000));
|
||||
|
|
@ -49,7 +52,7 @@ export function drawAscentChart(
|
|||
);
|
||||
const qx = toX(qPeak.downrange / 1000);
|
||||
const qy = toY(qPeak.altitude / 1000);
|
||||
ctx.strokeStyle = sim.success ? (light ? "#0284c7" : "#60a5fa") : "#ef4444";
|
||||
ctx.strokeStyle = sim.success ? pal.accent : pal.red;
|
||||
ctx.lineWidth = 2.4;
|
||||
ctx.beginPath();
|
||||
pts.forEach((p, idx) => {
|
||||
|
|
@ -59,7 +62,7 @@ export function drawAscentChart(
|
|||
else ctx.lineTo(x, y);
|
||||
});
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = "#f59e0b";
|
||||
ctx.fillStyle = pal.amber;
|
||||
ctx.beginPath();
|
||||
ctx.arc(qx, qy, 4.5, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
|
|
@ -69,11 +72,11 @@ export function drawAscentChart(
|
|||
Math.min(W - 140, qx + 8),
|
||||
Math.max(16, qy - 6),
|
||||
);
|
||||
ctx.fillStyle = light ? "#475569" : "#94a3b8";
|
||||
ctx.fillStyle = pal.textDim;
|
||||
ctx.fillText("0 km", 6, padT + ph);
|
||||
ctx.fillText(`${Math.round(maxAlt)} km`, 4, padT + 10);
|
||||
ctx.fillText(`Downrange ${Math.round(maxDr)} km`, W - 150, H - 6);
|
||||
ctx.fillStyle = sim.success ? (light ? "#059669" : "#34d399") : "#ef4444";
|
||||
ctx.fillStyle = sim.success ? pal.green : pal.red;
|
||||
ctx.fillText(
|
||||
sim.success
|
||||
? `ORBIT INSERTION ${Math.round(sim.periapsis / 1000)}×${Math.round(sim.apoapsis / 1000)} km`
|
||||
|
|
@ -90,12 +93,14 @@ export function drawMultiTelemetryChart(
|
|||
): void {
|
||||
const ctx = telemetryDiagCanvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
const light = getColorMode() === "light";
|
||||
const pal = getThemePalette();
|
||||
const W = telemetryDiagCanvas.width;
|
||||
const H = telemetryDiagCanvas.height;
|
||||
ctx.fillStyle = light ? "#f8fafc" : "#0b0e14";
|
||||
ctx.fillStyle = pal.bgDeep;
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
ctx.strokeStyle = light ? "rgba(15, 23, 42, 0.12)" : "rgba(42, 52, 73, 0.55)";
|
||||
ctx.save();
|
||||
ctx.strokeStyle = pal.border;
|
||||
ctx.globalAlpha = 0.55;
|
||||
ctx.lineWidth = 1;
|
||||
for (let i = 1; i < 4; i++) {
|
||||
const y = (H / 4) * i;
|
||||
|
|
@ -104,6 +109,7 @@ export function drawMultiTelemetryChart(
|
|||
ctx.lineTo(W - 16, y);
|
||||
ctx.stroke();
|
||||
}
|
||||
ctx.restore();
|
||||
const pts = sim.telemetry;
|
||||
if (!pts.length) return;
|
||||
const maxT = Math.max(10, pts[pts.length - 1].t);
|
||||
|
|
@ -158,7 +164,7 @@ export function drawMultiTelemetryChart(
|
|||
420,
|
||||
16,
|
||||
);
|
||||
ctx.fillStyle = light ? "#475569" : "#94a3b8";
|
||||
ctx.fillStyle = pal.textDim;
|
||||
ctx.fillText(`T+0s`, padL, H - 6);
|
||||
ctx.fillText(`T+${Math.round(maxT)}s`, W - 64, H - 6);
|
||||
const compFault =
|
||||
|
|
@ -239,10 +245,10 @@ export function drawOrbitChart(opts: OrbitChartOptions): void {
|
|||
opts;
|
||||
const ctx = orbitCanvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
const light = getColorMode() === "light";
|
||||
const pal = getThemePalette();
|
||||
const W = orbitCanvas.width;
|
||||
const H = orbitCanvas.height;
|
||||
ctx.fillStyle = light ? "#f8fafc" : "#0b0e14";
|
||||
ctx.fillStyle = pal.bgDeep;
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
const traj =
|
||||
trajInput ??
|
||||
|
|
@ -272,11 +278,11 @@ export function drawOrbitChart(opts: OrbitChartOptions): void {
|
|||
const x1 = cx + p1.x * scale;
|
||||
const y1 = cy + p1.z * scale;
|
||||
if (p1.inShadow) {
|
||||
ctx.strokeStyle = "#a855f7";
|
||||
ctx.strokeStyle = pal.violet;
|
||||
} else if ((p1.radBeltFlux ?? 0) > 1.0) {
|
||||
ctx.strokeStyle = "#f59e0b";
|
||||
ctx.strokeStyle = pal.amber;
|
||||
} else {
|
||||
ctx.strokeStyle = light ? "#0284c7" : "#60a5fa";
|
||||
ctx.strokeStyle = pal.accent;
|
||||
}
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x0, y0);
|
||||
|
|
@ -293,18 +299,18 @@ export function drawOrbitChart(opts: OrbitChartOptions): void {
|
|||
...traj.points.map((p) => p.perturbationDriftKm ?? 0),
|
||||
);
|
||||
const samplePt = traj.points[Math.floor(traj.points.length * 0.25)];
|
||||
ctx.fillStyle = light ? "#475569" : "#94a3b8";
|
||||
ctx.fillStyle = pal.textDim;
|
||||
ctx.font = "11px monospace";
|
||||
ctx.fillText(
|
||||
`[${traj.source.toUpperCase()}] Target ${(contract?.target ?? "leo").toUpperCase()} • Inc ${fp.targetInclinationDeg.toFixed(1)}° • Period ${fmtDuration(traj.period)}`,
|
||||
14,
|
||||
18,
|
||||
);
|
||||
ctx.fillStyle = "#a855f7";
|
||||
ctx.fillStyle = pal.violet;
|
||||
ctx.fillText(`Eclipse Shadow: ${eclipsePct}%`, 14, H - 10);
|
||||
ctx.fillStyle = "#f59e0b";
|
||||
ctx.fillStyle = pal.amber;
|
||||
ctx.fillText(`Peak Van Allen Flux: ${peakFlux.toFixed(2)}`, 190, H - 10);
|
||||
ctx.fillStyle = "#34d399";
|
||||
ctx.fillStyle = pal.green;
|
||||
ctx.fillText(`Perturbation Drift: ${maxDrift.toFixed(1)} km`, 420, H - 10);
|
||||
clear(gmatStatsBoxEl);
|
||||
gmatStatsBoxEl.append(
|
||||
|
|
|
|||
|
|
@ -1,55 +1,564 @@
|
|||
// The saviour you needed for your eyes, cus mine were burning before making this shit
|
||||
import { getSettings, saveSettings } from "./api.js";
|
||||
// Modular theme engine: Shape-Sets, Color-Sets (presets, gradients, custom tokens),
|
||||
// independent UI/3D comfort toggles, and live 2D/3D palette resolution.
|
||||
import {
|
||||
type ColorSet,
|
||||
type CustomThemeTokens,
|
||||
DEFAULT_THEME_CONFIG,
|
||||
type GradientThemeConfig,
|
||||
getSettings,
|
||||
saveSettings,
|
||||
type ShapeSet,
|
||||
type ThemeConfig,
|
||||
} from "./api.js";
|
||||
import type { SpaceWeather } from "../shared/types.js";
|
||||
|
||||
export function getColorMode(): "dark" | "light" {
|
||||
return getSettings().colorMode === "light" ? "light" : "dark";
|
||||
export type {
|
||||
ColorSet,
|
||||
CustomThemeTokens,
|
||||
GradientThemeConfig,
|
||||
ShapeSet,
|
||||
ThemeConfig,
|
||||
};
|
||||
|
||||
export interface PresetDescriptor<T extends string> {
|
||||
id: T;
|
||||
label: string;
|
||||
tagline: string;
|
||||
}
|
||||
|
||||
export function isReducedEffects(): boolean {
|
||||
return !!getSettings().reducedEffects;
|
||||
export const SHAPE_SET_OPTIONS: PresetDescriptor<ShapeSet>[] = [
|
||||
{
|
||||
id: "chamfered",
|
||||
label: "Chamfered",
|
||||
tagline: "Angled telemetry corner cuts (Default)",
|
||||
},
|
||||
{
|
||||
id: "smooth",
|
||||
label: "Smooth",
|
||||
tagline: "Soft rounded corners (Eye-Saver style)",
|
||||
},
|
||||
{
|
||||
id: "sharp",
|
||||
label: "Sharp / Square",
|
||||
tagline: "Crisp 90° edges, zero corner radius",
|
||||
},
|
||||
];
|
||||
|
||||
export interface ColorSetPreset extends PresetDescriptor<ColorSet> {
|
||||
swatches: [string, string, string, string];
|
||||
tokens?: CustomThemeTokens;
|
||||
}
|
||||
|
||||
export const COLOR_SET_OPTIONS: ColorSetPreset[] = [
|
||||
{
|
||||
id: "eyebleed",
|
||||
label: "Eyebleed",
|
||||
tagline: "High-contrast night ops & vivid accents (Classic)",
|
||||
swatches: ["#0b0e14", "#19202e", "#60a5fa", "#e2e8f0"],
|
||||
tokens: {
|
||||
bgDeep: "#0b0e14",
|
||||
bgPanelSolid: "#12161f",
|
||||
bgElevated: "#19202e",
|
||||
border: "#2a3449",
|
||||
text: "#e2e8f0",
|
||||
textDim: "#94a3b8",
|
||||
accent: "#60a5fa",
|
||||
glow: "#60a5fa",
|
||||
green: "#34d399",
|
||||
amber: "#f59e0b",
|
||||
red: "#f87171",
|
||||
violet: "#a78bfa",
|
||||
panelOpacity: 0.92,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "subtle",
|
||||
label: "Subtle",
|
||||
tagline: "Muted slate & softened accents (Eye-Saver)",
|
||||
swatches: ["#10141c", "#1e2531", "#648bb8", "#d5dde8"],
|
||||
tokens: {
|
||||
bgDeep: "#10141c",
|
||||
bgPanelSolid: "#161b24",
|
||||
bgElevated: "#1e2531",
|
||||
border: "#2b3444",
|
||||
text: "#d5dde8",
|
||||
textDim: "#8b9ab0",
|
||||
accent: "#648bb8",
|
||||
glow: "#648bb8",
|
||||
green: "#47a885",
|
||||
amber: "#c98e3b",
|
||||
red: "#c96b6b",
|
||||
violet: "#8b7cc8",
|
||||
panelOpacity: 0.96,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "low-contrast",
|
||||
label: "Low Contrast",
|
||||
tagline: "Gentle luminance spread for long sessions",
|
||||
swatches: ["#191d26", "#272d3a", "#6d90ba", "#b3becf"],
|
||||
tokens: {
|
||||
bgDeep: "#191d26",
|
||||
bgPanelSolid: "#202530",
|
||||
bgElevated: "#272d3a",
|
||||
border: "#343c4d",
|
||||
text: "#b3becf",
|
||||
textDim: "#838fa3",
|
||||
accent: "#6d90ba",
|
||||
glow: "#6d90ba",
|
||||
green: "#5fa88d",
|
||||
amber: "#c2944c",
|
||||
red: "#c47678",
|
||||
violet: "#9182c4",
|
||||
panelOpacity: 0.96,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "catppuccin-mocha",
|
||||
label: "Catppuccin Mocha",
|
||||
tagline: "Warm pastel dark palette on deep espresso (Default)",
|
||||
swatches: ["#1e1e2e", "#313244", "#89b4fa", "#cdd6f4"],
|
||||
tokens: {
|
||||
bgDeep: "#1e1e2e",
|
||||
bgPanelSolid: "#181825",
|
||||
bgElevated: "#313244",
|
||||
border: "#45475a",
|
||||
text: "#cdd6f4",
|
||||
textDim: "#a6adc8",
|
||||
accent: "#89b4fa",
|
||||
glow: "#74c7ec",
|
||||
green: "#a6e3a1",
|
||||
amber: "#f9e2af",
|
||||
red: "#f38ba8",
|
||||
violet: "#cba6f7",
|
||||
panelOpacity: 0.94,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "daylight",
|
||||
label: "Daylight Light",
|
||||
tagline: "Clean bright mode for high-ambient rooms",
|
||||
swatches: ["#f1f5f9", "#e2e8f0", "#0284c7", "#0f172a"],
|
||||
tokens: {
|
||||
bgDeep: "#f1f5f9",
|
||||
bgPanelSolid: "#ffffff",
|
||||
bgElevated: "#e2e8f0",
|
||||
border: "#cbd5e1",
|
||||
text: "#0f172a",
|
||||
textDim: "#475569",
|
||||
accent: "#0284c7",
|
||||
glow: "#0284c7",
|
||||
green: "#059669",
|
||||
amber: "#d97706",
|
||||
red: "#dc2626",
|
||||
violet: "#7c3aed",
|
||||
panelOpacity: 0.96,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "gradient",
|
||||
label: "Customizable Gradients",
|
||||
tagline: "Multi-stop backdrop & panel gradients",
|
||||
swatches: ["#0b1120", "#172554", "#38bdf8", "#e2e8f0"],
|
||||
},
|
||||
{
|
||||
id: "custom",
|
||||
label: "Fully Custom Set",
|
||||
tagline: "Edit every surface, text & semantic token",
|
||||
swatches: ["#12161f", "#34d399", "#f59e0b", "#a78bfa"],
|
||||
},
|
||||
];
|
||||
|
||||
export interface GradientStarter {
|
||||
id: string;
|
||||
label: string;
|
||||
config: GradientThemeConfig;
|
||||
}
|
||||
|
||||
export const GRADIENT_STARTERS: GradientStarter[] = [
|
||||
{
|
||||
id: "nebula",
|
||||
label: "Nebula",
|
||||
config: {
|
||||
stops: ["#0b1120", "#1e1b4b", "#0f172a"],
|
||||
angle: 135,
|
||||
mode: "linear",
|
||||
surfaceBase: "dark",
|
||||
applyToPanels: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "aurora",
|
||||
label: "Aurora",
|
||||
config: {
|
||||
stops: ["#071a1f", "#0f3d3e", "#1b1f3b"],
|
||||
angle: 150,
|
||||
mode: "linear",
|
||||
surfaceBase: "dark",
|
||||
applyToPanels: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "sunset",
|
||||
label: "Sunset",
|
||||
config: {
|
||||
stops: ["#1f1024", "#4c1d3d", "#2c1810"],
|
||||
angle: 125,
|
||||
mode: "linear",
|
||||
surfaceBase: "dark",
|
||||
applyToPanels: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "ocean",
|
||||
label: "Deep Ocean",
|
||||
config: {
|
||||
stops: ["#06131f", "#0c2d48", "#0b192c"],
|
||||
angle: 165,
|
||||
mode: "radial",
|
||||
surfaceBase: "dark",
|
||||
applyToPanels: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "dawn",
|
||||
label: "Solar Dawn",
|
||||
config: {
|
||||
stops: ["#f8fafc", "#e0f2fe", "#fef3c7"],
|
||||
angle: 135,
|
||||
mode: "linear",
|
||||
surfaceBase: "light",
|
||||
applyToPanels: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const CUSTOM_CSS_VAR_KEYS = [
|
||||
"--bg-deep",
|
||||
"--bg-panel",
|
||||
"--bg-panel-solid",
|
||||
"--bg-elevated",
|
||||
"--bg-hover",
|
||||
"--border",
|
||||
"--border-bright",
|
||||
"--border-subtle",
|
||||
"--text",
|
||||
"--text-dim",
|
||||
"--text-faint",
|
||||
"--brand-blue",
|
||||
"--brand-strong",
|
||||
"--sim-accent",
|
||||
"--sim-accent-dim",
|
||||
"--sim-glow",
|
||||
"--green",
|
||||
"--amber",
|
||||
"--red",
|
||||
"--violet",
|
||||
"--bg-glass",
|
||||
"--bg-inset",
|
||||
"--bg-header-fade",
|
||||
"--overlay-scrim",
|
||||
"--badge-bg",
|
||||
"--btn-primary-bg",
|
||||
"--btn-primary-hover",
|
||||
"--btn-primary-text",
|
||||
"--btn-warn-bg",
|
||||
"--btn-warn-text",
|
||||
"--btn-danger-bg",
|
||||
"--btn-danger-text",
|
||||
"--btn-ghost-bg",
|
||||
"--title-color",
|
||||
"--bg-gradient",
|
||||
"--panel-gradient",
|
||||
] as const;
|
||||
|
||||
export function normalizeHex(hex: string, fallback = "#0b0e14"): string {
|
||||
const trimmed = hex.trim();
|
||||
if (/^#[0-9a-fA-F]{6}$/.test(trimmed)) return trimmed.toLowerCase();
|
||||
if (/^#[0-9a-fA-F]{3}$/.test(trimmed)) {
|
||||
const [, r, g, b] = trimmed;
|
||||
return `#${r}${r}${g}${g}${b}${b}`.toLowerCase();
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function hexToRgb(hex: string): [number, number, number] {
|
||||
const clean = normalizeHex(hex).slice(1);
|
||||
return [
|
||||
parseInt(clean.slice(0, 2), 16),
|
||||
parseInt(clean.slice(2, 4), 16),
|
||||
parseInt(clean.slice(4, 6), 16),
|
||||
];
|
||||
}
|
||||
|
||||
export function rgbToHex(r: number, g: number, b: number): string {
|
||||
const clamp = (n: number) =>
|
||||
Math.max(0, Math.min(255, Math.round(n)))
|
||||
.toString(16)
|
||||
.padStart(2, "0");
|
||||
return `#${clamp(r)}${clamp(g)}${clamp(b)}`;
|
||||
}
|
||||
|
||||
export function hexToRgba(hex: string, alpha: number): string {
|
||||
const [r, g, b] = hexToRgb(hex);
|
||||
const a = Math.max(0, Math.min(1, alpha));
|
||||
return `rgba(${r}, ${g}, ${b}, ${Number(a.toFixed(3))})`;
|
||||
}
|
||||
|
||||
export function mixHex(hexA: string, hexB: string, weightB: number): string {
|
||||
const w = Math.max(0, Math.min(1, weightB));
|
||||
const [r1, g1, b1] = hexToRgb(hexA);
|
||||
const [r2, g2, b2] = hexToRgb(hexB);
|
||||
return rgbToHex(
|
||||
r1 + (r2 - r1) * w,
|
||||
g1 + (g2 - g1) * w,
|
||||
b1 + (b2 - b1) * w,
|
||||
);
|
||||
}
|
||||
|
||||
export function isLightHex(hex: string): boolean {
|
||||
const [r, g, b] = hexToRgb(hex).map((v) => {
|
||||
const s = v / 255;
|
||||
return s <= 0.03928 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
|
||||
});
|
||||
const lum = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
return lum > 0.42;
|
||||
}
|
||||
|
||||
export function buildCustomTokensFromPreset(
|
||||
presetId: Exclude<ColorSet, "gradient" | "custom">,
|
||||
): CustomThemeTokens {
|
||||
const found = COLOR_SET_OPTIONS.find((p) => p.id === presetId);
|
||||
const tokens = found?.tokens ?? COLOR_SET_OPTIONS[0].tokens!;
|
||||
return { ...tokens };
|
||||
}
|
||||
|
||||
export function formatGradientCss(g: GradientThemeConfig): string {
|
||||
const stops = g.stops.length >= 2 ? g.stops : ["#0b1120", "#172554"];
|
||||
if (g.mode === "radial") {
|
||||
return `radial-gradient(circle at 50% 25%, ${stops.join(", ")})`;
|
||||
}
|
||||
return `linear-gradient(${g.angle}deg, ${stops.join(", ")})`;
|
||||
}
|
||||
|
||||
let previewThemeOverride: ThemeConfig | null = null;
|
||||
|
||||
export function getThemeConfig(): ThemeConfig {
|
||||
return previewThemeOverride ?? getSettings().theme;
|
||||
}
|
||||
|
||||
export function setThemePreview(
|
||||
theme: ThemeConfig | null,
|
||||
dispatchEvent = true,
|
||||
): void {
|
||||
previewThemeOverride = theme ? structuredClone(theme) : null;
|
||||
applyThemeConfig(getThemeConfig(), dispatchEvent);
|
||||
}
|
||||
|
||||
export function saveThemeConfig(theme: ThemeConfig): void {
|
||||
previewThemeOverride = null;
|
||||
const s = getSettings();
|
||||
s.theme = structuredClone(theme);
|
||||
saveSettings(s);
|
||||
applyVisualPreferences();
|
||||
}
|
||||
|
||||
export function isLightSurface(): boolean {
|
||||
const t = getThemeConfig();
|
||||
if (t.colorSet === "daylight") return true;
|
||||
if (t.colorSet === "gradient") return t.gradient.surfaceBase === "light";
|
||||
if (t.colorSet === "custom") return isLightHex(t.custom.bgDeep);
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isReducedMotionEffects(): boolean {
|
||||
return !getThemeConfig().motionEffects;
|
||||
}
|
||||
|
||||
export function getColorMode(): "dark" | "light" {
|
||||
return isLightSurface() ? "light" : "dark";
|
||||
}
|
||||
|
||||
function clearCustomCssVars(): void {
|
||||
const style = document.documentElement.style;
|
||||
for (const key of CUSTOM_CSS_VAR_KEYS) {
|
||||
style.removeProperty(key);
|
||||
}
|
||||
}
|
||||
|
||||
function applyDerivedTokens(
|
||||
tokens: CustomThemeTokens,
|
||||
uiEffects: boolean,
|
||||
extras: { bgGradient?: string; panelGradient?: string } = {},
|
||||
): void {
|
||||
const light = isLightHex(tokens.bgDeep);
|
||||
const style = document.documentElement.style;
|
||||
const set = (k: string, v: string) => style.setProperty(k, v);
|
||||
|
||||
const bgHover = mixHex(tokens.bgElevated, tokens.text, light ? 0.1 : 0.08);
|
||||
const borderBright = mixHex(tokens.border, tokens.text, 0.18);
|
||||
const textFaint = mixHex(tokens.textDim, tokens.bgDeep, 0.35);
|
||||
const brandStrong = mixHex(tokens.accent, light ? "#000000" : "#0b0e14", 0.22);
|
||||
|
||||
set("--bg-deep", tokens.bgDeep);
|
||||
set("--bg-panel", hexToRgba(tokens.bgPanelSolid, tokens.panelOpacity));
|
||||
set("--bg-panel-solid", tokens.bgPanelSolid);
|
||||
set("--bg-elevated", tokens.bgElevated);
|
||||
set("--bg-hover", bgHover);
|
||||
set("--border", tokens.border);
|
||||
set("--border-bright", borderBright);
|
||||
set("--border-subtle", hexToRgba(tokens.border, 0.55));
|
||||
set("--text", tokens.text);
|
||||
set("--text-dim", tokens.textDim);
|
||||
set("--text-faint", textFaint);
|
||||
set("--brand-blue", tokens.accent);
|
||||
set("--brand-strong", brandStrong);
|
||||
set("--sim-accent", tokens.accent);
|
||||
set("--sim-accent-dim", hexToRgba(tokens.accent, 0.28));
|
||||
set(
|
||||
"--sim-glow",
|
||||
uiEffects ? hexToRgba(tokens.glow, light ? 0.14 : 0.18) : "transparent",
|
||||
);
|
||||
set("--green", tokens.green);
|
||||
set("--amber", tokens.amber);
|
||||
set("--red", tokens.red);
|
||||
set("--violet", tokens.violet);
|
||||
set("--bg-glass", hexToRgba(tokens.bgPanelSolid, Math.min(0.95, tokens.panelOpacity)));
|
||||
set("--bg-inset", hexToRgba(tokens.bgDeep, light ? 0.72 : 0.6));
|
||||
set("--bg-header-fade", light ? "transparent" : hexToRgba(tokens.bgDeep, 0.92));
|
||||
set("--overlay-scrim", light ? "rgba(15, 23, 42, 0.42)" : "rgba(7, 10, 15, 0.84)");
|
||||
set("--badge-bg", light ? tokens.bgPanelSolid : hexToRgba(tokens.bgDeep, 0.72));
|
||||
|
||||
const accentIsLight = isLightHex(tokens.accent);
|
||||
set(
|
||||
"--btn-primary-bg",
|
||||
light ? tokens.accent : hexToRgba(tokens.accent, 0.22),
|
||||
);
|
||||
set(
|
||||
"--btn-primary-hover",
|
||||
light ? brandStrong : hexToRgba(tokens.accent, 0.36),
|
||||
);
|
||||
set(
|
||||
"--btn-primary-text",
|
||||
light ? (accentIsLight ? "#0f172a" : "#ffffff") : mixHex(tokens.accent, "#ffffff", 0.75),
|
||||
);
|
||||
set(
|
||||
"--btn-warn-bg",
|
||||
hexToRgba(tokens.amber, 0.15),
|
||||
);
|
||||
set(
|
||||
"--btn-warn-text",
|
||||
light ? mixHex(tokens.amber, "#000000", 0.35) : mixHex(tokens.amber, "#ffffff", 0.65),
|
||||
);
|
||||
set("--btn-danger-bg", hexToRgba(tokens.red, 0.13));
|
||||
set(
|
||||
"--btn-danger-text",
|
||||
light ? mixHex(tokens.red, "#000000", 0.35) : mixHex(tokens.red, "#ffffff", 0.65),
|
||||
);
|
||||
set(
|
||||
"--btn-ghost-bg",
|
||||
light ? tokens.bgPanelSolid : hexToRgba(tokens.bgPanelSolid, 0.68),
|
||||
);
|
||||
set("--title-color", light ? tokens.text : mixHex(tokens.text, "#ffffff", 0.55));
|
||||
set("--bg-gradient", extras.bgGradient ?? "none");
|
||||
set("--panel-gradient", extras.panelGradient ?? "none");
|
||||
}
|
||||
|
||||
function buildGradientTokens(theme: ThemeConfig): {
|
||||
tokens: CustomThemeTokens;
|
||||
bgGradient: string;
|
||||
panelGradient: string;
|
||||
} {
|
||||
const g = theme.gradient;
|
||||
const s0 = normalizeHex(g.stops[0] ?? "#0b1120", "#0b1120");
|
||||
const s1 = normalizeHex(g.stops[1] ?? "#172554", "#172554");
|
||||
const sLast = normalizeHex(g.stops[g.stops.length - 1] ?? s1, s1);
|
||||
const light = g.surfaceBase === "light";
|
||||
|
||||
const bgDeep = light ? mixHex("#f1f5f9", s0, 0.16) : mixHex("#0b0e14", s0, 0.45);
|
||||
const bgPanelSolid = light
|
||||
? mixHex("#ffffff", s0, 0.08)
|
||||
: mixHex("#111622", s0, 0.42);
|
||||
const bgElevated = light
|
||||
? mixHex("#e2e8f0", s1, 0.14)
|
||||
: mixHex("#182032", s1, 0.4);
|
||||
const border = light
|
||||
? mixHex("#cbd5e1", s1, 0.25)
|
||||
: mixHex("#2a3449", s1, 0.42);
|
||||
|
||||
// Choose an accent that stays legible against the surface base
|
||||
const rawAccent = isLightHex(s1) === light ? sLast : s1;
|
||||
const accent = light
|
||||
? (isLightHex(rawAccent) ? "#0284c7" : rawAccent)
|
||||
: (isLightHex(rawAccent) ? rawAccent : mixHex(rawAccent, "#60a5fa", 0.62));
|
||||
|
||||
const tokens: CustomThemeTokens = {
|
||||
bgDeep,
|
||||
bgPanelSolid,
|
||||
bgElevated,
|
||||
border,
|
||||
text: light ? "#0f172a" : "#e2e8f0",
|
||||
textDim: light ? "#475569" : "#9fb0c7",
|
||||
accent,
|
||||
glow: accent,
|
||||
green: light ? "#059669" : "#34d399",
|
||||
amber: light ? "#d97706" : "#f59e0b",
|
||||
red: light ? "#dc2626" : "#f87171",
|
||||
violet: light ? "#7c3aed" : "#a78bfa",
|
||||
panelOpacity: light ? 0.9 : 0.86,
|
||||
};
|
||||
|
||||
const bgGradient = formatGradientCss(g);
|
||||
const panelGradient = g.applyToPanels
|
||||
? `linear-gradient(155deg, ${hexToRgba(s0, light ? 0.24 : 0.34)}, ${hexToRgba(sLast, light ? 0.16 : 0.22)})`
|
||||
: "none";
|
||||
|
||||
return { tokens, bgGradient, panelGradient };
|
||||
}
|
||||
|
||||
export function applyThemeConfig(
|
||||
theme: ThemeConfig,
|
||||
dispatchEvent = true,
|
||||
): void {
|
||||
const root = document.documentElement;
|
||||
const light =
|
||||
theme.colorSet === "daylight" ||
|
||||
(theme.colorSet === "gradient" && theme.gradient.surfaceBase === "light") ||
|
||||
(theme.colorSet === "custom" && isLightHex(theme.custom.bgDeep));
|
||||
|
||||
root.dataset.shapeSet = theme.shapeSet;
|
||||
root.dataset.colorSet = theme.colorSet;
|
||||
root.dataset.surfacePolarity = light ? "light" : "dark";
|
||||
root.classList.toggle("reduced-ui-effects", !theme.uiEffects);
|
||||
root.classList.toggle("reduced-motion-effects", !theme.motionEffects);
|
||||
document.body.dataset.dynamicTheme = theme.dynamicAccent ? "on" : "off";
|
||||
|
||||
clearCustomCssVars();
|
||||
if (theme.colorSet === "gradient") {
|
||||
const { tokens, bgGradient, panelGradient } = buildGradientTokens(theme);
|
||||
applyDerivedTokens(tokens, theme.uiEffects, { bgGradient, panelGradient });
|
||||
} else if (theme.colorSet === "custom") {
|
||||
applyDerivedTokens(theme.custom, theme.uiEffects);
|
||||
}
|
||||
|
||||
if (dispatchEvent) {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("sgywftp:theme-changed", {
|
||||
detail: {
|
||||
shapeSet: theme.shapeSet,
|
||||
colorSet: theme.colorSet,
|
||||
uiEffects: theme.uiEffects,
|
||||
motionEffects: theme.motionEffects,
|
||||
dynamicAccent: theme.dynamicAccent,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
paletteCache = null;
|
||||
}
|
||||
|
||||
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;
|
||||
applyThemeConfig(getThemeConfig(), true);
|
||||
}
|
||||
|
||||
export function syncSimulationTheme(opts: {
|
||||
|
|
@ -57,15 +566,9 @@ export function syncSimulationTheme(opts: {
|
|||
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) {
|
||||
const theme = getThemeConfig();
|
||||
applyThemeConfig(theme, false);
|
||||
if (!theme.dynamicAccent) {
|
||||
document.body.dataset.weather = "nominal";
|
||||
document.body.dataset.target = "earth";
|
||||
document.body.dataset.phase = "idle";
|
||||
|
|
@ -81,3 +584,78 @@ export function syncSimulationTheme(opts: {
|
|||
document.body.dataset.phase = opts.phase;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ResolvedThemePalette {
|
||||
bgDeep: string;
|
||||
bgPanelSolid: string;
|
||||
bgElevated: string;
|
||||
border: string;
|
||||
text: string;
|
||||
textDim: string;
|
||||
accent: string;
|
||||
green: string;
|
||||
amber: string;
|
||||
red: string;
|
||||
violet: string;
|
||||
isLight: boolean;
|
||||
isGradient: boolean;
|
||||
sceneBg: string;
|
||||
sceneBgWithStars: string;
|
||||
daySkyLow: string;
|
||||
}
|
||||
|
||||
let paletteCache: ResolvedThemePalette | null = null;
|
||||
|
||||
export function getThemePalette(): ResolvedThemePalette {
|
||||
if (paletteCache) return paletteCache;
|
||||
const cfg = getThemeConfig();
|
||||
const isLight = isLightSurface();
|
||||
const cs = getComputedStyle(document.documentElement);
|
||||
const bodyCs = getComputedStyle(document.body);
|
||||
const readVar = (name: string, fallback: string) =>
|
||||
cs.getPropertyValue(name).trim() || fallback;
|
||||
const readBodyVar = (name: string, fallback: string) =>
|
||||
bodyCs.getPropertyValue(name).trim() || fallback;
|
||||
|
||||
const bgDeep = readVar("--bg-deep", isLight ? "#f1f5f9" : "#0b0e14");
|
||||
const bgPanelSolid = readVar(
|
||||
"--bg-panel-solid",
|
||||
isLight ? "#ffffff" : "#12161f",
|
||||
);
|
||||
const bgElevated = readVar(
|
||||
"--bg-elevated",
|
||||
isLight ? "#e2e8f0" : "#19202e",
|
||||
);
|
||||
const border = readVar("--border", isLight ? "#cbd5e1" : "#2a3449");
|
||||
const text = readVar("--text", isLight ? "#0f172a" : "#e2e8f0");
|
||||
const textDim = readVar("--text-dim", isLight ? "#475569" : "#94a3b8");
|
||||
const accent = readBodyVar("--sim-accent", isLight ? "#0284c7" : "#60a5fa");
|
||||
const green = readVar("--green", isLight ? "#059669" : "#34d399");
|
||||
const amber = readVar("--amber", isLight ? "#d97706" : "#f59e0b");
|
||||
const red = readVar("--red", isLight ? "#dc2626" : "#f87171");
|
||||
const violet = readVar("--violet", isLight ? "#7c3aed" : "#a78bfa");
|
||||
|
||||
const sceneBg = isLight && cfg.colorSet === "daylight" ? "#dce5f0" : bgDeep;
|
||||
const sceneBgWithStars = isLight ? "#1e293b" : bgDeep;
|
||||
const daySkyLow = isLight ? "#cbdcf0" : mixHex("#0c1a33", bgDeep, 0.35);
|
||||
|
||||
paletteCache = {
|
||||
bgDeep,
|
||||
bgPanelSolid,
|
||||
bgElevated,
|
||||
border,
|
||||
text,
|
||||
textDim,
|
||||
accent,
|
||||
green,
|
||||
amber,
|
||||
red,
|
||||
violet,
|
||||
isLight,
|
||||
isGradient: cfg.colorSet === "gradient",
|
||||
sceneBg,
|
||||
sceneBgWithStars,
|
||||
daySkyLow,
|
||||
};
|
||||
return paletteCache;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Volumetric GLSL shader exhaust plumes, mach shock diamonds (this doesn't look so much better than p1), and altitude/throttle plume scaling.
|
||||
import * as THREE from "three";
|
||||
import { getSoftParticleTexture } from "../sceneManager.js";
|
||||
import { isReducedEffects } from "../../theme.js";
|
||||
import { isReducedMotionEffects } from "../../theme.js";
|
||||
import { getPlumeStyle, type NozzleEmitter } from "./materials.js";
|
||||
|
||||
const PLUME_VERTEX_SHADER = `
|
||||
|
|
@ -76,7 +76,7 @@ export function setPlumeAtmosphere(
|
|||
mat.uniforms.uVacuum.value = vacuum;
|
||||
mat.uniforms.uThrottle.value = thr;
|
||||
if (mat.uniforms.uReduced) {
|
||||
mat.uniforms.uReduced.value = isReducedEffects() ? 1.0 : 0.0;
|
||||
mat.uniforms.uReduced.value = isReducedMotionEffects() ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -129,7 +129,7 @@ export function buildStagePlume(
|
|||
uTime: { value: 0 },
|
||||
uVacuum: { value: 0 },
|
||||
uThrottle: { value: 1 },
|
||||
uReduced: { value: isReducedEffects() ? 1.0 : 0.0 },
|
||||
uReduced: { value: isReducedMotionEffects() ? 1.0 : 0.0 },
|
||||
uCoreColor: { value: new THREE.Color(style.core).multiplyScalar(1.35) },
|
||||
uInnerColor: {
|
||||
value: new THREE.Color(style.inner).multiplyScalar(1.15),
|
||||
|
|
@ -153,7 +153,7 @@ export function buildStagePlume(
|
|||
);
|
||||
envelope.position.y = -plumeLen * 0.5;
|
||||
envelope.onBeforeRender = () => {
|
||||
if (!isReducedEffects()) {
|
||||
if (!isReducedMotionEffects()) {
|
||||
shaderMat.uniforms.uTime.value = performance.now() * 0.001;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@ import { RenderPass } from "three/addons/postprocessing/RenderPass.js";
|
|||
import { UnrealBloomPass } from "three/addons/postprocessing/UnrealBloomPass.js";
|
||||
import { OutputPass } from "three/addons/postprocessing/OutputPass.js";
|
||||
import { getSettings } from "../../api.js";
|
||||
import { getColorMode, isReducedEffects } from "../../theme.js";
|
||||
import {
|
||||
getThemePalette,
|
||||
isLightSurface,
|
||||
isReducedMotionEffects,
|
||||
} from "../../theme.js";
|
||||
import {
|
||||
createStudioPMREMCubeTexture,
|
||||
getSoftParticleTexture,
|
||||
|
|
@ -71,7 +75,7 @@ export function createView(
|
|||
let bloomPass: UnrealBloomPass | null = null;
|
||||
let outputPass: OutputPass | null = null;
|
||||
const shouldUseBloom = () =>
|
||||
quality !== "low" && !isReducedEffects() && getColorMode() === "dark";
|
||||
quality !== "low" && !isReducedMotionEffects() && !isLightSurface();
|
||||
try {
|
||||
composer = new EffectComposer(renderer);
|
||||
composer.setPixelRatio(renderer.getPixelRatio());
|
||||
|
|
@ -92,22 +96,24 @@ export function createView(
|
|||
}
|
||||
let hasStars = false;
|
||||
const applyScenePalette = () => {
|
||||
const light = getColorMode() === "light";
|
||||
const reduced = isReducedEffects();
|
||||
const pal = getThemePalette();
|
||||
const reduced = isReducedMotionEffects();
|
||||
if (opts.background !== undefined) {
|
||||
scene.background = new THREE.Color(
|
||||
light && opts.background === 0x0b0e14
|
||||
pal.isLight && opts.background === 0x0b0e14
|
||||
? hasStars
|
||||
? 0x1e293b
|
||||
: 0xdce5f0
|
||||
? pal.sceneBgWithStars
|
||||
: pal.sceneBg
|
||||
: opts.background,
|
||||
);
|
||||
} else if (pal.isGradient) {
|
||||
scene.background = null;
|
||||
} else {
|
||||
scene.background = new THREE.Color(
|
||||
light ? (hasStars ? 0x1e293b : 0xdce5f0) : 0x0b0e14,
|
||||
hasStars ? pal.sceneBgWithStars : pal.sceneBg,
|
||||
);
|
||||
}
|
||||
renderer.toneMappingExposure = light ? (reduced ? 1.0 : 1.06) : 1.12;
|
||||
renderer.toneMappingExposure = pal.isLight ? (reduced ? 1.0 : 1.06) : 1.12;
|
||||
if (bloomPass) {
|
||||
bloomPass.enabled = shouldUseBloom();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,4 +15,5 @@ export {
|
|||
toast,
|
||||
} from "./ui/notifications.js";
|
||||
export { type ModalAction, modal } from "./ui/modal.js";
|
||||
export { openThemeSettingsModal } from "./ui/themeModal.js";
|
||||
export { hideTooltip, initTooltipController, term } from "./ui/tooltip.js";
|
||||
|
|
|
|||
758
src/client/ui/themeModal.ts
Normal file
758
src/client/ui/themeModal.ts
Normal file
|
|
@ -0,0 +1,758 @@
|
|||
// Theme & Appearance Settings modal with live preview, Shape-Sets, Color-Sets,
|
||||
// Customizable Gradients builder, Fully Custom token editor, and comfort toggles.
|
||||
import {
|
||||
DEFAULT_CUSTOM_TOKENS,
|
||||
DEFAULT_THEME_CONFIG,
|
||||
getSettings,
|
||||
normalizeThemeConfig,
|
||||
} from "../api.js";
|
||||
import { applyThemeFromState } from "../state.js";
|
||||
import {
|
||||
applyVisualPreferences,
|
||||
buildCustomTokensFromPreset,
|
||||
COLOR_SET_OPTIONS,
|
||||
type ColorSet,
|
||||
type CustomThemeTokens,
|
||||
formatGradientCss,
|
||||
GRADIENT_STARTERS,
|
||||
normalizeHex,
|
||||
saveThemeConfig,
|
||||
setThemePreview,
|
||||
SHAPE_SET_OPTIONS,
|
||||
type ThemeConfig,
|
||||
} from "../theme.js";
|
||||
import { clear, h } from "./dom.js";
|
||||
import { modal } from "./modal.js";
|
||||
import { toast } from "./notifications.js";
|
||||
|
||||
interface CustomFieldSpec {
|
||||
key: Exclude<keyof CustomThemeTokens, "panelOpacity">;
|
||||
label: string;
|
||||
}
|
||||
|
||||
const CUSTOM_SURFACE_FIELDS: CustomFieldSpec[] = [
|
||||
{ key: "bgDeep", label: "Background Deep" },
|
||||
{ key: "bgPanelSolid", label: "Panel Surface" },
|
||||
{ key: "bgElevated", label: "Elevated Card" },
|
||||
{ key: "border", label: "Border Line" },
|
||||
];
|
||||
|
||||
const CUSTOM_TEXT_FIELDS: CustomFieldSpec[] = [
|
||||
{ key: "text", label: "Primary Text" },
|
||||
{ key: "textDim", label: "Muted Text" },
|
||||
];
|
||||
|
||||
const CUSTOM_ACCENT_FIELDS: CustomFieldSpec[] = [
|
||||
{ key: "accent", label: "Primary Accent" },
|
||||
{ key: "glow", label: "Glow Tint" },
|
||||
{ key: "green", label: "Success / OK" },
|
||||
{ key: "amber", label: "Warning / Amber" },
|
||||
{ key: "red", label: "Danger / Red" },
|
||||
{ key: "violet", label: "Secondary / Violet" },
|
||||
];
|
||||
|
||||
function createColorRow(
|
||||
label: string,
|
||||
initialHex: string,
|
||||
onPick: (hex: string) => void,
|
||||
): HTMLElement {
|
||||
const hexReadout = h("span", { class: "theme-color-hex" }, initialHex);
|
||||
const picker = h("input", {
|
||||
type: "color",
|
||||
class: "theme-color-input",
|
||||
value: normalizeHex(initialHex),
|
||||
onInput: () => {
|
||||
const next = picker.value.toLowerCase();
|
||||
hexReadout.textContent = next;
|
||||
onPick(next);
|
||||
},
|
||||
}) as HTMLInputElement;
|
||||
picker.value = normalizeHex(initialHex);
|
||||
return h(
|
||||
"div",
|
||||
{ class: "theme-color-row" },
|
||||
h("span", { class: "theme-color-label" }, label),
|
||||
h("div", { class: "theme-color-picker-wrap" }, picker, hexReadout),
|
||||
);
|
||||
}
|
||||
|
||||
function createPreviewCard(draft: ThemeConfig): HTMLElement {
|
||||
const shapeLabel =
|
||||
SHAPE_SET_OPTIONS.find((s) => s.id === draft.shapeSet)?.label ??
|
||||
draft.shapeSet;
|
||||
const colorLabel =
|
||||
COLOR_SET_OPTIONS.find((c) => c.id === draft.colorSet)?.label ??
|
||||
draft.colorSet;
|
||||
return h(
|
||||
"div",
|
||||
{ class: "theme-preview-card" },
|
||||
h(
|
||||
"div",
|
||||
{ class: "spread" },
|
||||
h(
|
||||
"span",
|
||||
{ class: "mono accent", style: { fontSize: "11px", fontWeight: "700" } },
|
||||
"LIVE TELEMETRY PREVIEW",
|
||||
),
|
||||
h("span", { class: "badge info" }, `${shapeLabel} · ${colorLabel}`),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "row", style: { gap: "6px" } },
|
||||
h("span", { class: "badge ok" }, "ORBIT NOMINAL"),
|
||||
h("span", { class: "badge warn" }, "MAX-Q"),
|
||||
h("span", { class: "badge err" }, "ABORT"),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "row", style: { gap: "6px" } },
|
||||
h("button", { type: "button", class: "btn xs primary" }, "Launch"),
|
||||
h("button", { type: "button", class: "btn xs" }, "Inspect"),
|
||||
h("button", { type: "button", class: "btn xs warn" }, "Hold"),
|
||||
h("button", { type: "button", class: "btn xs danger" }, "Abort"),
|
||||
h("button", { type: "button", class: "btn xs ghost" }, "Cancel"),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "dim", style: { fontSize: "11px" } },
|
||||
"Sample muted telemetry readout and border framing across the active theme.",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function openThemeSettingsModal(): void {
|
||||
if (document.querySelector(".theme-modal")) return;
|
||||
|
||||
const initialTheme = structuredClone(getSettings().theme);
|
||||
let draft: ThemeConfig = structuredClone(initialTheme);
|
||||
let jsonEditorOpen = false;
|
||||
|
||||
const applyDraftLive = () => {
|
||||
setThemePreview(draft, false);
|
||||
applyThemeFromState();
|
||||
applyVisualPreferences();
|
||||
};
|
||||
|
||||
const bodyRoot = h("div", { class: "theme-sections" });
|
||||
|
||||
const renderShapeSection = (): HTMLElement =>
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-section" },
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-section-head" },
|
||||
h("span", { class: "slot-title" }, "Shape-Set"),
|
||||
h(
|
||||
"span",
|
||||
{ class: "mono dim", style: { fontSize: "10px" } },
|
||||
"Corner & framing geometry",
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-chip-grid" },
|
||||
...SHAPE_SET_OPTIONS.map((opt) =>
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: `theme-chip ${draft.shapeSet === opt.id ? "active" : ""}`,
|
||||
onClick: () => {
|
||||
draft.shapeSet = opt.id;
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-chip-title" },
|
||||
opt.label,
|
||||
draft.shapeSet === opt.id
|
||||
? h("span", { class: "badge info" }, "ACTIVE")
|
||||
: null,
|
||||
),
|
||||
h("div", { class: "theme-chip-sub" }, opt.tagline),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const renderColorSetSection = (): HTMLElement =>
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-section" },
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-section-head" },
|
||||
h("span", { class: "slot-title" }, "Color-Set"),
|
||||
h(
|
||||
"span",
|
||||
{ class: "mono dim", style: { fontSize: "10px" } },
|
||||
"Presets, gradients & custom palette",
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-chip-grid" },
|
||||
...COLOR_SET_OPTIONS.map((opt) =>
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: `theme-chip ${draft.colorSet === opt.id ? "active" : ""}`,
|
||||
onClick: () => {
|
||||
draft.colorSet = opt.id;
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-chip-title" },
|
||||
opt.label,
|
||||
draft.colorSet === opt.id
|
||||
? h("span", { class: "badge info" }, "ACTIVE")
|
||||
: null,
|
||||
),
|
||||
h("div", { class: "theme-chip-sub" }, opt.tagline),
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-swatches" },
|
||||
...opt.swatches.map((hex) =>
|
||||
h("span", {
|
||||
class: "theme-swatch",
|
||||
style: { backgroundColor: hex },
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const renderGradientSection = (): HTMLElement => {
|
||||
const g = draft.gradient;
|
||||
const previewStrip = h("div", {
|
||||
class: "theme-gradient-preview",
|
||||
style: { background: formatGradientCss(g) },
|
||||
});
|
||||
const angleLabel = h("span", { class: "mono accent" }, `${g.angle}°`);
|
||||
const angleSlider = h("input", {
|
||||
type: "range",
|
||||
class: "slider",
|
||||
min: 0,
|
||||
max: 360,
|
||||
step: 1,
|
||||
value: g.angle,
|
||||
disabled: g.mode === "radial",
|
||||
onInput: () => {
|
||||
g.angle = Number(angleSlider.value);
|
||||
angleLabel.textContent = `${g.angle}°`;
|
||||
previewStrip.style.background = formatGradientCss(g);
|
||||
applyDraftLive();
|
||||
},
|
||||
}) as HTMLInputElement;
|
||||
angleSlider.value = String(g.angle);
|
||||
|
||||
const stopPickers = g.stops.map((stopHex, idx) =>
|
||||
createColorRow(`Stop ${idx + 1}`, stopHex, (nextHex) => {
|
||||
g.stops[idx] = nextHex;
|
||||
previewStrip.style.background = formatGradientCss(g);
|
||||
applyDraftLive();
|
||||
}),
|
||||
);
|
||||
|
||||
const panelGradChk = h("input", {
|
||||
type: "checkbox",
|
||||
checked: g.applyToPanels,
|
||||
onChange: () => {
|
||||
g.applyToPanels = panelGradChk.checked;
|
||||
applyDraftLive();
|
||||
},
|
||||
}) as HTMLInputElement;
|
||||
|
||||
return h(
|
||||
"div",
|
||||
{ class: "theme-section" },
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-section-head" },
|
||||
h("span", { class: "slot-title" }, "Customizable Gradients"),
|
||||
h(
|
||||
"div",
|
||||
{ class: "row", style: { gap: "6px" } },
|
||||
g.stops.length < 3
|
||||
? h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: "btn xs",
|
||||
onClick: () => {
|
||||
g.stops.push("#1e3a8a");
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
"+ 3rd Stop",
|
||||
)
|
||||
: h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: "btn xs ghost",
|
||||
onClick: () => {
|
||||
g.stops.pop();
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
"− Remove 3rd Stop",
|
||||
),
|
||||
),
|
||||
),
|
||||
previewStrip,
|
||||
h(
|
||||
"div",
|
||||
{ class: "row", style: { gap: "6px" } },
|
||||
h("span", { class: "mono dim", style: { fontSize: "10px" } }, "Starters:"),
|
||||
...GRADIENT_STARTERS.map((starter) =>
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: "btn xs ghost",
|
||||
onClick: () => {
|
||||
draft.gradient = {
|
||||
...starter.config,
|
||||
stops: [...starter.config.stops],
|
||||
};
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
starter.label,
|
||||
),
|
||||
),
|
||||
),
|
||||
h("div", { class: "theme-color-grid" }, ...stopPickers),
|
||||
h(
|
||||
"div",
|
||||
{ class: "row", style: { gap: "12px" } },
|
||||
h(
|
||||
"div",
|
||||
{ class: "row", style: { gap: "6px" } },
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: `btn xs ${g.mode === "linear" ? "selected" : "ghost"}`,
|
||||
onClick: () => {
|
||||
g.mode = "linear";
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
"Linear",
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: `btn xs ${g.mode === "radial" ? "selected" : "ghost"}`,
|
||||
onClick: () => {
|
||||
g.mode = "radial";
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
"Radial",
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "row", style: { gap: "6px" } },
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: `btn xs ${g.surfaceBase === "dark" ? "selected" : "ghost"}`,
|
||||
onClick: () => {
|
||||
g.surfaceBase = "dark";
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
"Dark Panels",
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: `btn xs ${g.surfaceBase === "light" ? "selected" : "ghost"}`,
|
||||
onClick: () => {
|
||||
g.surfaceBase = "light";
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
"Light Panels",
|
||||
),
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "col", style: { gap: "4px" } },
|
||||
h(
|
||||
"div",
|
||||
{ class: "spread" },
|
||||
h(
|
||||
"span",
|
||||
{ class: "mono dim", style: { fontSize: "10px" } },
|
||||
g.mode === "radial" ? "Angle (Linear only)" : "Gradient Angle",
|
||||
),
|
||||
angleLabel,
|
||||
),
|
||||
angleSlider,
|
||||
),
|
||||
h(
|
||||
"label",
|
||||
{ class: "row", style: { cursor: "pointer", fontSize: "12px" } },
|
||||
panelGradChk,
|
||||
h("span", {}, "Apply subtle gradient tint to panels & cards"),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
const renderCustomSection = (): HTMLElement => {
|
||||
const c = draft.custom;
|
||||
const seedOptions: Array<{
|
||||
id: Exclude<ColorSet, "gradient" | "custom">;
|
||||
label: string;
|
||||
}> = [
|
||||
{ id: "eyebleed", label: "Eyebleed (Classic)" },
|
||||
{ id: "subtle", label: "Subtle (Eye-Saver)" },
|
||||
{ id: "low-contrast", label: "Low Contrast" },
|
||||
{ id: "catppuccin-mocha", label: "Catppuccin Mocha" },
|
||||
{ id: "daylight", label: "Daylight Light" },
|
||||
];
|
||||
const seedSelect = h(
|
||||
"select",
|
||||
{ class: "input", style: { width: "auto", padding: "4px 8px", fontSize: "11px" } },
|
||||
...seedOptions.map((o) => h("option", { value: o.id }, o.label)),
|
||||
) as HTMLSelectElement;
|
||||
|
||||
const opLabel = h(
|
||||
"span",
|
||||
{ class: "mono accent" },
|
||||
`${Math.round(c.panelOpacity * 100)}%`,
|
||||
);
|
||||
const opSlider = h("input", {
|
||||
type: "range",
|
||||
class: "slider",
|
||||
min: 0.65,
|
||||
max: 1.0,
|
||||
step: 0.01,
|
||||
value: c.panelOpacity,
|
||||
onInput: () => {
|
||||
c.panelOpacity = Number(opSlider.value);
|
||||
opLabel.textContent = `${Math.round(c.panelOpacity * 100)}%`;
|
||||
applyDraftLive();
|
||||
},
|
||||
}) as HTMLInputElement;
|
||||
opSlider.value = String(c.panelOpacity);
|
||||
|
||||
const makeGroup = (title: string, fields: CustomFieldSpec[]) =>
|
||||
h(
|
||||
"div",
|
||||
{ class: "col", style: { gap: "6px" } },
|
||||
h("span", { class: "mono dim", style: { fontSize: "10px" } }, title),
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-color-grid" },
|
||||
...fields.map((f) =>
|
||||
createColorRow(f.label, c[f.key], (hex) => {
|
||||
c[f.key] = hex;
|
||||
applyDraftLive();
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
let jsonDrawer: HTMLElement | null = null;
|
||||
if (jsonEditorOpen) {
|
||||
const jsonArea = h("textarea", {
|
||||
class: "input",
|
||||
rows: 5,
|
||||
style: { fontSize: "11px", resize: "vertical" },
|
||||
value: JSON.stringify(c, null, 2),
|
||||
}) as HTMLTextAreaElement;
|
||||
jsonArea.value = JSON.stringify(c, null, 2);
|
||||
jsonDrawer = h(
|
||||
"div",
|
||||
{ class: "col", style: { gap: "6px" } },
|
||||
jsonArea,
|
||||
h(
|
||||
"div",
|
||||
{ class: "row", style: { gap: "6px", justifyContent: "flex-end" } },
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: "btn xs ghost",
|
||||
onClick: async () => {
|
||||
try {
|
||||
await navigator.clipboard?.writeText(jsonArea.value);
|
||||
toast("Custom theme JSON copied.", "ok");
|
||||
} catch {
|
||||
toast("Select and copy the JSON text directly.", "info");
|
||||
}
|
||||
},
|
||||
},
|
||||
"Copy JSON",
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: "btn xs primary",
|
||||
onClick: () => {
|
||||
try {
|
||||
const parsed = JSON.parse(jsonArea.value);
|
||||
const normalized = normalizeThemeConfig({
|
||||
...draft,
|
||||
custom: parsed,
|
||||
});
|
||||
draft.custom = normalized.custom;
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
toast("Custom theme JSON imported.", "ok");
|
||||
} catch {
|
||||
toast("Invalid custom theme JSON.", "err");
|
||||
}
|
||||
},
|
||||
},
|
||||
"Apply JSON",
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return h(
|
||||
"div",
|
||||
{ class: "theme-section" },
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-section-head" },
|
||||
h("span", { class: "slot-title" }, "Fully Custom Set"),
|
||||
h(
|
||||
"div",
|
||||
{ class: "row", style: { gap: "6px" } },
|
||||
seedSelect,
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: "btn xs",
|
||||
onClick: () => {
|
||||
draft.custom = buildCustomTokensFromPreset(
|
||||
seedSelect.value as Exclude<ColorSet, "gradient" | "custom">,
|
||||
);
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
"Seed",
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: "btn xs ghost",
|
||||
onClick: () => {
|
||||
jsonEditorOpen = !jsonEditorOpen;
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
jsonEditorOpen ? "Hide JSON" : "JSON",
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
type: "button",
|
||||
class: "btn xs danger",
|
||||
onClick: () => {
|
||||
draft.custom = { ...DEFAULT_CUSTOM_TOKENS };
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
},
|
||||
},
|
||||
"Reset",
|
||||
),
|
||||
),
|
||||
),
|
||||
makeGroup("Surfaces & Borders", CUSTOM_SURFACE_FIELDS),
|
||||
h(
|
||||
"div",
|
||||
{ class: "col", style: { gap: "4px" } },
|
||||
h(
|
||||
"div",
|
||||
{ class: "spread" },
|
||||
h(
|
||||
"span",
|
||||
{ class: "mono dim", style: { fontSize: "10px" } },
|
||||
"Panel Opacity",
|
||||
),
|
||||
opLabel,
|
||||
),
|
||||
opSlider,
|
||||
),
|
||||
makeGroup("Typography", CUSTOM_TEXT_FIELDS),
|
||||
makeGroup("Accents & Status", CUSTOM_ACCENT_FIELDS),
|
||||
jsonDrawer,
|
||||
);
|
||||
};
|
||||
|
||||
const renderEffectsSection = (): HTMLElement => {
|
||||
const uiFxChk = h("input", {
|
||||
type: "checkbox",
|
||||
checked: draft.uiEffects,
|
||||
onChange: () => {
|
||||
draft.uiEffects = uiFxChk.checked;
|
||||
applyDraftLive();
|
||||
},
|
||||
}) as HTMLInputElement;
|
||||
|
||||
const motionFxChk = h("input", {
|
||||
type: "checkbox",
|
||||
checked: draft.motionEffects,
|
||||
onChange: () => {
|
||||
draft.motionEffects = motionFxChk.checked;
|
||||
applyDraftLive();
|
||||
},
|
||||
}) as HTMLInputElement;
|
||||
|
||||
const dynAccentChk = h("input", {
|
||||
type: "checkbox",
|
||||
checked: draft.dynamicAccent,
|
||||
onChange: () => {
|
||||
draft.dynamicAccent = dynAccentChk.checked;
|
||||
applyDraftLive();
|
||||
},
|
||||
}) as HTMLInputElement;
|
||||
|
||||
return h(
|
||||
"div",
|
||||
{ class: "theme-section" },
|
||||
h(
|
||||
"div",
|
||||
{ class: "theme-section-head" },
|
||||
h("span", { class: "slot-title" }, "Visual Effects & Motion"),
|
||||
h(
|
||||
"span",
|
||||
{ class: "mono dim", style: { fontSize: "10px" } },
|
||||
"Independent of color-set",
|
||||
),
|
||||
),
|
||||
h(
|
||||
"label",
|
||||
{ class: "row", style: { cursor: "pointer", fontSize: "12px" } },
|
||||
uiFxChk,
|
||||
h(
|
||||
"span",
|
||||
{},
|
||||
"UI Glows, Backdrop Blur, Shadows & Background Grid",
|
||||
),
|
||||
),
|
||||
h(
|
||||
"label",
|
||||
{ class: "row", style: { cursor: "pointer", fontSize: "12px" } },
|
||||
motionFxChk,
|
||||
h(
|
||||
"span",
|
||||
{},
|
||||
"Animations, 3D Bloom, Camera Shake & Plume Shimmer",
|
||||
),
|
||||
),
|
||||
h(
|
||||
"label",
|
||||
{ class: "row", style: { cursor: "pointer", fontSize: "12px" } },
|
||||
dynAccentChk,
|
||||
h(
|
||||
"span",
|
||||
{},
|
||||
"Dynamic Simulation Accent (shifts with space weather & target)",
|
||||
),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
const renderModalBody = () => {
|
||||
clear(bodyRoot);
|
||||
bodyRoot.append(
|
||||
createPreviewCard(draft),
|
||||
renderShapeSection(),
|
||||
renderColorSetSection(),
|
||||
);
|
||||
if (draft.colorSet === "gradient") bodyRoot.append(renderGradientSection());
|
||||
if (draft.colorSet === "custom") bodyRoot.append(renderCustomSection());
|
||||
bodyRoot.append(renderEffectsSection());
|
||||
};
|
||||
|
||||
renderModalBody();
|
||||
|
||||
const cleanupEscape = () => {
|
||||
window.removeEventListener("keydown", onKeyDown);
|
||||
};
|
||||
|
||||
const revertAndClose = () => {
|
||||
cleanupEscape();
|
||||
setThemePreview(null, false);
|
||||
applyThemeFromState();
|
||||
applyVisualPreferences();
|
||||
m.close();
|
||||
};
|
||||
|
||||
const onKeyDown = (ev: KeyboardEvent) => {
|
||||
if (ev.key === "Escape") {
|
||||
ev.preventDefault();
|
||||
revertAndClose();
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onKeyDown);
|
||||
|
||||
const m = modal("Theme & Appearance Settings", bodyRoot, [
|
||||
{
|
||||
label: "Reset Defaults",
|
||||
kind: "ghost",
|
||||
onClick: () => {
|
||||
draft = structuredClone(DEFAULT_THEME_CONFIG);
|
||||
applyDraftLive();
|
||||
renderModalBody();
|
||||
return false;
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Cancel",
|
||||
kind: "ghost",
|
||||
onClick: () => {
|
||||
cleanupEscape();
|
||||
setThemePreview(null, false);
|
||||
applyThemeFromState();
|
||||
applyVisualPreferences();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Save & Apply",
|
||||
kind: "primary",
|
||||
onClick: () => {
|
||||
cleanupEscape();
|
||||
saveThemeConfig(draft);
|
||||
applyThemeFromState();
|
||||
applyVisualPreferences();
|
||||
toast("Theme settings saved.", "ok");
|
||||
},
|
||||
},
|
||||
]);
|
||||
m.el.classList.add("theme-modal");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue