import { useEffect, useRef } from 'react'; import { usePrefs, FONT_SIZE_MAX, FONT_SIZE_MIN, type ReaderFont, type ReaderWidth, type ThemePref, } from '../../stores/prefsStore'; interface ReaderSettingsProps { onClose: () => void; } const THEMES: { value: ThemePref; label: string; swatch: string }[] = [ { value: 'light', label: 'Clair', swatch: '#FFFFFF' }, { value: 'sepia', label: 'Sépia', swatch: '#F4ECD8' }, { value: 'dark', label: 'Sombre', swatch: '#161D17' }, { value: 'system', label: 'Auto', swatch: 'linear-gradient(135deg,#fff 50%,#161D17 50%)' }, ]; const FONTS: { value: ReaderFont; label: string; family: string }[] = [ { value: 'serif', label: 'Serif', family: 'var(--font-reading)' }, { value: 'sans', label: 'Sans', family: 'var(--font-sans)' }, { value: 'legible', label: 'Lisible', family: 'var(--font-legible)' }, ]; const WIDTHS: { value: ReaderWidth; label: string }[] = [ { value: 'narrow', label: 'Étroite' }, { value: 'medium', label: 'Moyenne' }, { value: 'wide', label: 'Large' }, ]; const LEADINGS = [ { value: 1.5, label: 'Serré' }, { value: 1.65, label: 'Normal' }, { value: 1.85, label: 'Aéré' }, ]; /** "Aa" popover: theme, font, size, line height and line length. */ export function ReaderSettings({ onClose }: ReaderSettingsProps) { const prefs = usePrefs(); const panelRef = useRef(null); useEffect(() => { panelRef.current?.focus(); const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') { e.stopImmediatePropagation(); onClose(); } }; window.addEventListener('keydown', onKey, true); return () => window.removeEventListener('keydown', onKey, true); }, [onClose]); return ( <>