Add Svelte 5 frontend (App, TitleBar, BlockRing, ModelStack, WeeklyBar, Settings)

This commit is contained in:
megaproxy 2026-05-09 00:07:02 +01:00
parent 14ffcf4bd3
commit 0e8a87fbc5
17 changed files with 779 additions and 0 deletions

30
src/format.ts Normal file
View file

@ -0,0 +1,30 @@
// Number formatting that fits a 280px-wide widget.
export function formatTokens(n: number): string {
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(2)}M`;
if (n >= 10_000) return `${(n / 1_000).toFixed(0)}k`;
if (n >= 1_000) return `${(n / 1_000).toFixed(1)}k`;
return n.toString();
}
export function formatPct(num: number, denom: number): string {
if (denom <= 0) return "0%";
const pct = Math.min(999, Math.round((num / denom) * 100));
return `${pct}%`;
}
export function formatCountdown(seconds: number): string {
const s = Math.max(0, Math.floor(seconds));
const h = Math.floor(s / 3600);
const m = Math.floor((s % 3600) / 60);
const sec = s % 60;
if (h > 0) return `${h}h ${m.toString().padStart(2, "0")}m`;
return `${m.toString().padStart(2, "0")}:${sec.toString().padStart(2, "0")}`;
}
/// "2026-05-09" → "Sat" (weekday in user's local).
export function weekdayShort(date_local: string): string {
// date_local is already a calendar day; treat it as local midnight.
const d = new Date(`${date_local}T00:00:00`);
return d.toLocaleDateString(undefined, { weekday: "short" });
}