Files
nmemmertandClaude Sonnet 5.5 d13f55faf7 Add Outline stage, parallel reading, offline saves, backup, sync-conflict handling and more
Study
- New Outline stage (hierarchical I./A./1. points, linked to chunks, in all exports);
  the chunk stage is now "Chunks"
- Home cards: passages shown as ranges, tags capped with "+N more"

Reader
- Side-by-side translations and a Compare tab per verse
- Typeface, line spacing, verse-number settings; text and column scale with the screen
- Highlights/bookmarks sheet with named colours (synced); BSB footnote spacing fix
- Cmd-K palette (passages, studies, notes, marks), keyboard shortcuts and "?" help

Flow and safety
- Toasts with Undo replace most confirm()/alert()
- Back/Forward move between pages
- Server refuses saves over a newer copy (409); keep-mine / use-other banner;
  opening a study no longer re-stamps it
- Latest chapter request wins when flipping quickly

Offline and data
- Save books, plan days or a whole BSB/NET for offline
- Service worker fixes: helloao /api/ URLs were skipped and responses cloned too late
- Settings: download/restore a full backup

Accessibility
- Sheets trap focus and close on Escape, skip link, focus ring, reduced motion,
  theme contrast raised to 4.5:1 (with a test)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-01 14:08:08 -04:00

58 lines
2.6 KiB
JavaScript

// A user's synced display preferences: theme, default Reader translation, verse layout, the
// commentary they last chose, and where they left off in the Reader. Each preference carries
// its own timestamp ({ v, at }) so the most recent change to each one wins, device by device.
const ENUMS = {
theme: ['paper', 'sepia', 'dark'],
translation: ['BSB', 'ESV', 'NLT', 'CSB', 'NASB', 'NET'],
layout: ['flow', 'verses'],
startPage: ['studies', 'reader', 'plans'], // where the app opens and where Home buttons go
planTranslation: ['same', 'BSB', 'ESV', 'NLT', 'CSB', 'NASB', 'NET'], // which Bible new reading plans start in
commentarySource: ['matthew-henry', 'john-gill', 'jamieson-fausset-brown', 'tyndale', 'adam-clarke', 'john-calvin', 'keil-delitzsch'],
};
const DAY_MS = 86_400_000;
const COLOR = /^#[0-9a-fA-F]{3,8}$/;
// A cleaned value, or undefined when it isn't acceptable for that preference.
export function cleanPrefValue(key, value) {
if (ENUMS[key]) return ENUMS[key].includes(value) ? value : undefined;
if (key === 'colorLabels') {
// What each highlight colour means to the reader: { "#fef08a": "Promises", ... }
if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined;
const out = {};
for (const [color, label] of Object.entries(value).slice(0, 12)) {
if (COLOR.test(color) && typeof label === 'string' && label.trim()) out[color] = label.trim().slice(0, 30);
}
return out;
}
if (key === 'position') {
if (!value || typeof value !== 'object') return undefined;
const book = String(value.book ?? '').toUpperCase();
if (!/^[1-3A-Z]{3}$/.test(book) || !Number.isInteger(value.chapter) || value.chapter < 1 || value.chapter > 200) return undefined;
return { book, chapter: value.chapter };
}
return undefined;
}
// Body -> { key: { v, at } } with only known keys, valid values and sane timestamps.
export function cleanPrefsPatch(body, now = Date.now()) {
const out = {};
const prefs = body?.prefs;
if (!prefs || typeof prefs !== 'object' || Array.isArray(prefs)) return out;
for (const [key, entry] of Object.entries(prefs)) {
const v = cleanPrefValue(key, entry?.v);
const at = entry?.at;
if (v === undefined || !Number.isFinite(at) || at < 0 || at > now + DAY_MS) continue;
out[key] = { v, at };
}
return out;
}
// Per key, the entry with the newer timestamp wins (the stored one on a tie).
export function mergePrefs(existing = {}, patch = {}) {
const merged = { ...existing };
for (const [key, entry] of Object.entries(patch)) {
if (!merged[key] || entry.at > merged[key].at) merged[key] = entry;
}
return merged;
}