diff options
Diffstat (limited to 'web/src/lib/settings.ts')
| -rw-r--r-- | web/src/lib/settings.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/web/src/lib/settings.ts b/web/src/lib/settings.ts new file mode 100644 index 0000000..4238066 --- /dev/null +++ b/web/src/lib/settings.ts @@ -0,0 +1,33 @@ +/** + Client-side preferences (no server counterpart — these style the local + browser only). The reference app keeps them in `Settings` via + shared_preferences; here they live in localStorage. + */ +import { writable, type Writable } from 'svelte/store'; + +export type StyleTheme = 'frosthaven' | 'gloomhaven' | 'original'; + +const STYLE_KEY = 'x-haven-style'; + +function initialStyle(): StyleTheme { + try { + const stored = window.localStorage.getItem(STYLE_KEY); + if (stored === 'frosthaven' || stored === 'gloomhaven' || stored === 'original') { + return stored; + } + } catch { + /* private browsing / disabled storage */ + } + return 'frosthaven'; +} + +/** The visual style theme (PLAN.md Phase 3: the three style themes). */ +export const styleTheme: Writable<StyleTheme> = writable<StyleTheme>(initialStyle()); + +styleTheme.subscribe((value) => { + try { + window.localStorage.setItem(STYLE_KEY, value); + } catch { + /* ignore */ + } +}); |
