2026-10-03 14:29:28 +02:00
|
|
|
import type { Lang } from './types';
|
|
|
|
|
|
|
|
|
|
export interface Settings {
|
|
|
|
|
lang: Lang;
|
|
|
|
|
textScale: 100 | 125 | 150;
|
|
|
|
|
highContrast: boolean;
|
|
|
|
|
reduceMotion: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const defaultSettings = (lang: Lang): Settings => ({
|
2026-10-03 19:56:49 +02:00
|
|
|
lang, textScale: 100, highContrast: false, reduceMotion: false,
|
2026-10-03 14:29:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export function isSettings(v: unknown): v is Settings {
|
|
|
|
|
if (typeof v !== 'object' || v === null) return false;
|
|
|
|
|
const s = v as Record<string, unknown>;
|
|
|
|
|
return (
|
|
|
|
|
(s.lang === 'pl' || s.lang === 'en') && (s.textScale === 100 || s.textScale === 125 || s.textScale === 150) &&
|
2026-10-03 19:56:49 +02:00
|
|
|
typeof s.highContrast === 'boolean' && typeof s.reduceMotion === 'boolean'
|
2026-10-03 14:29:28 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Applies display settings to the document root. */
|
|
|
|
|
export function applySettings(s: Settings) {
|
|
|
|
|
const root = document.documentElement;
|
|
|
|
|
root.lang = s.lang;
|
|
|
|
|
root.style.fontSize = `${s.textScale}%`;
|
|
|
|
|
root.dataset.contrast = s.highContrast ? 'high' : 'default';
|
|
|
|
|
root.dataset.motion = s.reduceMotion ? 'reduce' : 'default';
|
|
|
|
|
}
|