// 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' export const ACCENTS = ['#e3a33b', '#3fb950', '#58a6ff', '#f778ba', '#ff7b72', '#a371f7', '#39c5cf', '#d4d44a', '#ff9e64', '#9aa7b4'] const KEY = 'hamlab.accents' export function getAccents(): Record { 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, 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() }).catch(() => { /* local still applied */ }) }