From 9155129ccd5e595b9fbc4531157769b2bd694250 Mon Sep 17 00:00:00 2001 From: patrick Date: Tue, 11 Aug 2026 22:45:14 -0400 Subject: [PATCH] fix: make the reader's typography, width and arrow keys work Typography was in the stylesheet foliate prepends, which the book overrides; moved to the appended one. The window keydown handler was never bound. Also: wider reading area, page on a card, arrows moved onto it, spread gutter, and the sidebar stays open on chapter clicks. --- .../lib/components/reader/epub-reader.svelte | 51 ++++++----- .../lib/components/reader/foliate-view.svelte | 40 +++++++- frontend/src/lib/reader/settings.ts | 7 +- frontend/src/lib/reader/stylesheet.ts | 91 ++++++++++++------- frontend/src/lib/schema/reader.ts | 8 +- 5 files changed, 135 insertions(+), 62 deletions(-) diff --git a/frontend/src/lib/components/reader/epub-reader.svelte b/frontend/src/lib/components/reader/epub-reader.svelte index bd38bcb..edb0040 100644 --- a/frontend/src/lib/components/reader/epub-reader.svelte +++ b/frontend/src/lib/components/reader/epub-reader.svelte @@ -95,8 +95,9 @@ } function navigateToChapter(href: string) { + // Deliberately leaves the sidebar open: picking a chapter is usually part of + // browsing several, and closing it each time made that tedious. void viewer?.goTo(href); - isSidebarOpen = false; } onMount(() => { @@ -191,18 +192,10 @@ {/if} -
- - -
+
+ +
{#if file} {/if} -
- + + + + +
{/if} diff --git a/frontend/src/lib/components/reader/foliate-view.svelte b/frontend/src/lib/components/reader/foliate-view.svelte index 55e82ff..ef122d8 100644 --- a/frontend/src/lib/components/reader/foliate-view.svelte +++ b/frontend/src/lib/components/reader/foliate-view.svelte @@ -48,6 +48,20 @@ // Reactive so the effects below re-run once the book is open — otherwise a // theme flip while it was still loading would never reach the book. let ready = $state(false); + let hostWidth = $state(0); + + /** + * How many columns the paginator will actually lay out. + * + * It decides this internally and exposes it only as a custom property inside + * its shadow root, so the formula is mirrored here to place the spread + * divider. Kept in step with paginator.js's `divisor`. + */ + const columns = $derived( + settings.flow === 'scrolled' || hostWidth === 0 + ? 1 + : Math.min(settings.maxColumnCount, Math.ceil(hostWidth / settings.maxInlineSize)) + ); /** * Where to resume from. @@ -130,6 +144,11 @@ onMount(() => { let disposed = false; + const resizeObserver = new ResizeObserver(([entry]) => { + hostWidth = entry.contentRect.width; + }); + if (container) resizeObserver.observe(container); + (async () => { try { await loadFoliate(); @@ -180,6 +199,7 @@ return () => { disposed = true; + resizeObserver.disconnect(); for (const { doc } of view?.renderer?.getContents?.() ?? []) { doc.removeEventListener('keydown', onKeydown); } @@ -211,9 +231,25 @@ }); - + + -
+
+
+ + {#if ready && columns === 2} + + + {/if} +