summaryrefslogtreecommitdiff
path: root/web/src/lib/settings.ts
blob: 423806672f64cd2d0b614153e1c1e502381e468a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 */
	}
});