Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Social Engine & Remote Navigator8 * File : apps/navigator-web/src/prefs.ts9 * Module : navigator-web10 * Repository : https://git.spboucher.ai/maclustr-social11 * Project Website : https://social.spboucher.ai12 * Created : 2026-12-0113 * Last Modified : 2026-12-0114 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Local display preferences (language, theme, viewer sizing). Nothing else is ever stored in the browser.43import type { Lang } from './i18n.ts';4445export type Theme = 'light' | 'dark';46const read = (k: string): string | null => { try { return localStorage.getItem(k); } catch { return null; } };47const write = (k: string, v: string) => { try { localStorage.setItem(k, v); } catch { /* private mode: the preference just does not persist */ } };4849export const storedTheme = (): Theme | null => { const v = read('mln.theme'); return v === 'light' || v === 'dark' ? v : null; };50export const systemTheme = (): Theme => (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');51export function applyTheme(t: Theme | null) { const el = document.documentElement; if (t) el.setAttribute('data-theme', t); else el.removeAttribute('data-theme'); }52export function saveTheme(t: Theme) { write('mln.theme', t); applyTheme(t); }5354export const storedLang = (): Lang => { const v = read('mln.lang'); if (v === 'fr' || v === 'en') return v; return 'fr'; };55export const saveLang = (l: Lang) => write('mln.lang', l);5657export const storedFit = (): boolean => read('mln.fit') !== '0';58export const saveFit = (fit: boolean) => write('mln.fit', fit ? '1' : '0');59