The close cross on a detail pane is drawn, not a glyph, and sits in no box. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
27 lines
1.5 KiB
TypeScript
27 lines
1.5 KiB
TypeScript
// Each machine wears a colour — a stripe across the header, its name in the switcher — so
|
|
// you always know which box you are typing into. A colour you pick wins; otherwise the
|
|
// machine's name picks one, the same one on every device.
|
|
import { api } from './api'
|
|
import { currentThemeId } from './themes'
|
|
import { getRefreshMs } from './prefs'
|
|
import { getRailOrder } from './railorder'
|
|
|
|
export const ACCENTS = ['#e3a33b', '#3fb950', '#58a6ff', '#f778ba', '#ff7b72', '#a371f7', '#39c5cf', '#d4d44a', '#ff9e64', '#9aa7b4']
|
|
const KEY = 'hamlab.accents'
|
|
|
|
export function getAccents(): Record<string, string> { try { return JSON.parse(localStorage.getItem(KEY) ?? '{}') ?? {} } catch { return {} } }
|
|
export function accentFor(name: string): string {
|
|
const picked = getAccents()[name]
|
|
if (picked && /^#[0-9a-f]{6}$/i.test(picked)) return picked
|
|
let h = 0; for (const c of name) h = (h * 31 + c.charCodeAt(0)) >>> 0
|
|
return ACCENTS[h % ACCENTS.length]
|
|
}
|
|
export function applyAccent(name: string) { document.documentElement.style.setProperty('--machine', accentFor(name)) }
|
|
export function setAccents(all: Record<string, string>, save = true) {
|
|
localStorage.setItem(KEY, JSON.stringify(all))
|
|
window.dispatchEvent(new Event('hamlab:accents'))
|
|
if (save) savePrefs()
|
|
}
|
|
// Everything the hub remembers about how the console looks, saved as one object.
|
|
export function savePrefs() { return api.saveUIPrefs({ theme: currentThemeId(), refreshMs: getRefreshMs(), accents: getAccents(), rail: getRailOrder() }).catch(() => { /* local still applied */ }) }
|