/* 阅读器设置:字号 / 背景 / 日夜模式 / 预设样式,持久化到 localStorage。 */ const STORAGE_KEY = 'reader_settings'; export const READER_PRESETS = [ { id: 'default', name: '默认', bg: '#ffffff', color: '#26221f', dark: false }, { id: 'paper', name: '羊皮纸', bg: '#f6eed9', color: '#3b3628', dark: false }, { id: 'green', name: '护眼绿', bg: '#cfe8cf', color: '#2f3b2f', dark: false }, { id: 'dark', name: '夜间', bg: '#1b1b1d', color: '#b9b9bd', dark: true }, ]; export const DEFAULT_SETTINGS = { fontSize: 18, preset: 'default', bg: '#ffffff', color: '#26221f', dark: false, }; export function loadSettings() { try { const raw = localStorage.getItem(STORAGE_KEY); if (!raw) return { ...DEFAULT_SETTINGS }; return { ...DEFAULT_SETTINGS, ...JSON.parse(raw) }; } catch { return { ...DEFAULT_SETTINGS }; } } export function saveSettings(settings) { try { localStorage.setItem(STORAGE_KEY, JSON.stringify(settings)); } catch { // 存储不可用时静默忽略 } } export function clampFontSize(size) { return Math.min(30, Math.max(14, size)); }