Add theme settings, and remove the old theme system

This commit is contained in:
tyuXX 2026-11-15 20:48:49 +03:00
parent 567ac1a26d
commit 9f4a3197de
22 changed files with 2301 additions and 463 deletions

View file

@ -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(