// ============================================================ // client/ui-state.ts — sub-pill / sub-tab persistence across browser restart. // // First file migrated out of public/js/ as ES module + TypeScript. // Tab-level selection (ped_last_tab) is handled in app.js (still legacy). // This file persists finer-grained choices that would otherwise reset // to defaults when the user closes the browser, signs out / back in, // or reloads the page — because _componentCache is in-memory only. // // All keys live under "ped_ui/" in localStorage. Reads and writes are // wrapped in try/catch — localStorage can throw in some contexts // (Safari private mode, storage quotas), and a persistence failure // must never break the UI. // // Compat: window.UIState is still assigned for the 10+ legacy consumers // (app.js, sub-nav.js, several IIFE modules). Once those are migrated // to ES module imports, the window assignment can be removed. // ============================================================ const PREFIX = 'ped_ui/'; export function get(key: string): string | null { try { return localStorage.getItem(PREFIX + key); } catch (e) { return null; } } export function set(key: string, value: string): void { try { localStorage.setItem(PREFIX + key, value); } catch (e) { /* swallow — see header */ } } export function del(key: string): void { try { localStorage.removeItem(PREFIX + key); } catch (e) { /* swallow */ } } export const UIState = { get, set, del }; // Legacy bridge — kept until every consumer is migrated to ES imports. (window as any).UIState = UIState;