Choose a font in Settings, beside the theme (#359)

Kept as the theme is, in a cookie each browser its own, and put on the
page by boot.js before the first frame. Theme's own, the default, adds
no rule, so Modern's Inter, Classic's Lucida Grande and Glass's system
face are as they were. The others are on the device already or served
by ipx (Inter), so choosing one downloads nothing. Their rules are
last in app.css, where they tie with each theme's own body font and win.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 01:10:28 +00:00
parent c6ca4d1a91
commit 6f38c0ad9b
7 changed files with 56 additions and 2 deletions

View File

@@ -52,6 +52,21 @@ function setTheme(name = theme.name, mode = theme.mode, save = false){
function saveTheme(){
document.cookie = `ipx_theme=${theme.name}.${theme.mode}; Path=/; Max-Age=31536000; SameSite=Lax`;
}
// A font chosen in Settings, kept as the theme is, each browser its own (#359). Theme's own is
// what each theme sets, Lucida Grande for Classic and the system's for Glass; the rest are on the
// device already or served by ipx, so choosing one downloads nothing.
const FONTS: Record<string, string> = {theme: "Theme's own", inter: 'Inter', system: 'System', serif: 'Serif', mono: 'Monospace'};
let font = 'theme';
function setFont(name = font, save = false){
font = FONTS[name] ? name : 'theme';
const root = document.documentElement;
if(font === 'theme') delete root.dataset.font; else root.dataset.font = font;
const sel = $<HTMLSelectElement>('#sfont'); if(sel) sel.value = font;
if(save) document.cookie = `ipx_font=${font}; Path=/; Max-Age=31536000; SameSite=Lax`;
}
setFont(document.documentElement.dataset.font);
systemDark?.addEventListener?.('change', () => { if(theme.mode === 'auto') setTheme(); });
(() => {
const root = document.documentElement;