diff --git a/static/js/app.js b/static/js/app.js index 5ca46fc..822d78b 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -4064,13 +4064,32 @@ function jumpToTocEntry(href) { // Reader Settings // --------------------------------------------------------------------------- +// Typography defaults. Phones keep the long-standing ones; a wide screen +// (desktop browser, diora desktop) starts bigger and wider. +const _READER_TYPE_DEFAULTS_NARROW = { fontSize: 16, lineHeight: 1.8, maxWidth: 65, fontWeight: null }; +const _READER_TYPE_DEFAULTS_WIDE = { fontSize: 20, lineHeight: 1.6, maxWidth: 90, fontWeight: 375 }; +const _READER_WIDTH_MAX = 140; // ch, the width slider's upper end ("Full" stays separate) + +function _readerTypeDefaults() { + return window.matchMedia('(min-width: 900px)').matches + ? _READER_TYPE_DEFAULTS_WIDE : _READER_TYPE_DEFAULTS_NARROW; +} + function loadReaderSettings(bookId) { // Reset to defaults, then apply per-book overrides - Object.assign(readerSettings, { fontSize: 16, lineHeight: 1.8, maxWidth: 65, theme: 'dark', - fontFamily: 'serif', noBold: false, fontWeight: null, - pdfZoom: 100, pdfInverted: false, pdfPaginated: false, pdfSpread: false }); + Object.assign(readerSettings, { theme: 'dark', fontFamily: 'serif', noBold: false, + pdfZoom: 100, pdfInverted: false, pdfPaginated: false, pdfSpread: false }, + _readerTypeDefaults()); try { const saved = JSON.parse(localStorage.getItem(`diora_reader_settings_${bookId}`) || '{}'); + // Settings saved before v2 hold every value, changed or not. A value equal + // to the old default was never chosen, so it gives way to today's default. + if (!saved.v) { + for (const [key, old] of Object.entries(_READER_TYPE_DEFAULTS_NARROW)) { + if (saved[key] === old) delete saved[key]; + } + } + delete saved.v; Object.assign(readerSettings, saved); if (saved.pdfPaginated === undefined) { readerSettings.pdfPaginated = window.innerWidth < 768; @@ -4080,7 +4099,7 @@ function loadReaderSettings(bookId) { function saveReaderSettings() { if (currentBookId) { - localStorage.setItem(`diora_reader_settings_${currentBookId}`, JSON.stringify(readerSettings)); + localStorage.setItem(`diora_reader_settings_${currentBookId}`, JSON.stringify({ ...readerSettings, v: 2 })); } } @@ -4170,7 +4189,7 @@ function toggleSettingsPanel() { panel.innerHTML = ` - +