Viewport Host — window presentation, fullscreen and colour scheme — implementation plan
Scope: make the document and media hosts usable for real reading and watching, on a phone or otherwise: a window presentation that owns the viewport, a fullscreen state on top of it, the application colour scheme applied to the chrome and to the Content, and a paginated-or-scrolled flow setting. Vocabulary and the two load-bearing decisions are in CONTEXT.md and ADR-0062.
Status: ratified 2026-09-24; S1 landed 2026-09-24 (b932eb82); S2 landed 2026-09-24; S3 landed 2026-09-24; S4 landed 2026-09-24; S5 landed 2026-09-24. Shape agreed with the maintainer in
conversation against the predecessor’s BookReader (route-level shell removal, 48px header and
footer, theme injected into the chapter iframe, Fullscreen API on the document root).
Grounding (verified 2026-09-24)
Section titled “Grounding (verified 2026-09-24)”- Two routes render
DocumentHost:/documents/$bindingId(offering materials, back to/offerings) and/lang/read/$contentId(personal library, back to/lang/library)./media/$bindingIdrendersMediaHost.ViewportWidget.tsx:54renders<DocumentHost embedded/>inside the Surface Experienceviewportslot. __root.tsxRootLayoutwraps every route: a header (brand, locale switcher, colour-scheme toggle, nav) then<Container size="xl" component="main" py="lg"><Outlet/>. No route opts out.ReaderChrome.tsx:206sizes the readerh="100vh"when not embedded, inside that header and padding.ExperienceScreenView.tsx:50-79, 191-250already has enter/exit fullscreen with a native Fullscreen API path and aposition:fixed; 100dvhfallback for iPhone; it covers the whole experience box and hides the surfaceheaderslot.- The reader is foliate-js: one iframe per spine section with an injected CSP (
sandbox.ts). Noflowattribute is set, so foliate paginates: max line length 720px, two columns above it, one in portrait, touch swipe built in (foliate-js/paginator.js:417-419, 461-490, 560-561). Arrow keys turn pages from the parent and from inside a section (ReaderChrome.tsx:149-168,use-section-keyboard.ts:53-73). CFI resume exists (DocumentHost.tsx:246-265). - Chrome today (
ReaderChrome.tsx:207-348): awrap="nowrap"toolbar — contents, title, history back/forward, previous/next, settings (language mode only), offline pin, back link — and a footer with chapter label, “section n/total”, aProgressbar and a stats line. The contents drawer is a left MantineDrawer. Nothing in the reader is responsive: nouseMediaQuery,visibleFrom, breakpoints,dvhorvisualViewport. Playwright runs desktop Chrome and desktop Safari only (playwright.config.ts:27-28). The PWA manifest isstandalone, portrait. - Colour scheme:
EmergentMantineProvider(packages/ui/src/provider.tsx:7-15) setsdefaultColorScheme="auto"withColorSchemeScript; nocolorSchemeManageris passed, so Mantine’s default localStorage manager applies.ColorSchemeToggleis mounted only in the root header. Book content is unthemed: nothing setscolor-scheme, a background or a text colour on section documents; enriched-text styles useinherit(styles.ts:113-127); foliate reacts toprefers-color-schemeonly when the book itself defines--theme-bg-color. - Reader settings:
lang_reader_configkeyed(person, language_tag, content_ref?), 13 fields, content row over language row (reader-config.ts:165-178), applied as CSS custom properties on each section’sdocumentElement(use-language-sections.ts:335-336,styles.ts:141-179). No flow, margin or theme field. Generic documents have no settings. - Media:
MediaHostis aStack maw=900with title, react-player at a fixed 480px with native controls, and back to/offerings. Fullscreen is observed for telemetry only (ADR-0045).
Rulings (ratified 2026-09-24)
Section titled “Rulings (ratified 2026-09-24)”- R1 — What goes to window presentation. The two standalone reader routes, the media route,
and the Surface Experience
viewportslot. The slot keeps its embedded presentation and gains an “open in window” control; the Experience screen’s own fullscreen control is untouched. - R2 — Presentation is host state. Both hosts carry
presentation: "embedded" | "window". Window presentation is a fixed layer covering the viewport, sized in dynamic viewport units, owning header, content, footer and drawers. The standalone routes render the host already in window presentation and sit under a shell-less layout route, so nothing renders beneath the layer. Entering window presentation from an Experience does not change the URL and pushes one history entry so back exits the presentation; leaving returns to the slot without navigation. - R3 — Fullscreen. Available only in window presentation: the Fullscreen API on the host’s layer where it exists (desktop, Android), with the collapsed-chrome behaviour alone on iPhone. Header and footer collapse; a tap or click in the centre of the page, or the pointer reaching the top edge, reveals them for a few seconds; contents and settings remain reachable through the revealed header; page turns keep working with the chrome hidden. Exit by the same control, Escape, or the browser leaving fullscreen; the host tracks the browser’s state, never its own flag. Not persisted.
- R4 — One colour scheme. The application’s, surfaced in the reader chrome with the existing
toggle. The host injects into every section document as it renders, and again when the scheme
flips:
color-scheme, page background, text colour, link colour; and keeps atheme-colormeta in the parent document in step. Gloss and tone colours become scheme-aware pairs. No sepia, no reader-only override. - R5 — Chrome inventory. Header, one row: close, title (one line, truncated), contents, settings, colour scheme, fullscreen; icons only at phone width, labels from tablet width up. History back/forward are dropped. Footer: previous, progress bar with the section label and “n of total” beneath it, next. The stats line and the offline pin move into the contents drawer’s header. Drawers are full-width sheets at phone width, side drawers above it. Close returns to where the host was opened from: library, offering, or the Experience slot.
- R6 — Page model and gestures. Paginated is the default and foliate’s swipe is the swipe. Tap zones: the left and right fifths of the page turn pages; the centre toggles the chrome in fullscreen and does nothing otherwise, so a tap on a word still opens the word popup outside the edge strips. Scrolled flow is offered as a setting.
- R7 — Flow lives on the language reader settings. A
flow: "paginated" | "scrolled"field onlang_reader_config, defaultpaginated, with the existing content-over-language precedence, edited in the Reader section of the settings drawer. Generic documents stay setting-less; splitting a generic reader-settings row waits for evidence of which fields belong to whom. - R8 — Vocabulary. Viewport Host, Presentation (embedded, window), Fullscreen, Colour Scheme, as entered in CONTEXT.md. “Reader shell” means the chrome of a document host in window presentation and is not a separate noun.
- R9 — Media host. Same window presentation and the header of R5 minus contents and settings; no footer; the player fills the width and sizes by aspect ratio; fullscreen is the player’s native fullscreen. No subtitles and no language mode for video in this plan.
- R10 — Delivery. One implementer run and one commit per slice, reviewed before the next
starts. Nothing under
packages/db/src/lang-enrichment/**ortests/characterization/**is touched. Thelang_reader_configmigration (S4) is generated in the slice and applied by the maintainer.
Slices
Section titled “Slices”- S1 — Window presentation. The presentation state on both hosts; a shell-less pathless layout route that the standalone reader and media routes move under; the R5 header, footer and drawers with phone-width behaviour; close semantics per origin; the Experience slot’s “open in window” control with the history entry. Adds a phone-viewport project to Playwright (Pixel and iPhone presets) so every later slice is exercised at phone width, with one flow that opens a book, turns a page by swipe and closes.
- S2 — Colour scheme in the reader. The toggle in the chrome; section-document theming
through foliate’s per-section hook, re-run on scheme change; the
theme-colormeta; scheme-aware gloss and tone colour pairs instyles.ts. Verified against foliate’s actual styling API at grounding, not assumed. - S3 — Fullscreen and tap zones. The fullscreen state with the Fullscreen API and the iPhone fallback, collapsed chrome with the reveal rules, the centre tap and the edge tap zones, and the keyboard exits.
- S4 — Flow setting. The field and migration on
lang_reader_config, the drawer control, foliate’sflowattribute driven from the resolved config, and the scrolled-mode advance on the footer’s previous/next. - S5 — Media host. Window presentation with the reduced header, aspect-ratio sizing, native player fullscreen through the same header control.
Out of scope
Section titled “Out of scope”A reader-only appearance or sepia; syncing the colour scheme; settings for generic documents; subtitles or language mode for media; the Experience screen’s own fullscreen control; any change to the enrichment pipeline.
Open items
Section titled “Open items”-
S3: a reader layer that takes native fullscreen inside an Experience that is itself in native fullscreen confuses the Experience’s own
fullscreenchangehandling (it sees a different element and drops to “off” while its box is still in the fullscreen stack). Two nested native fullscreens is the case to design out, most simply by having the reader use the overlay path when an ancestor is already fullscreen. -
S3: collapsing and revealing the chrome changes the page height, so foliate re-paginates on every toggle; the position is kept but text moves under the finger. Floating the chrome over the page instead would avoid it and is a design call for after real-device use.
-
S3:
viewport-fit=coveris app-wide and only the window layer pads for safe areas, so the application shell can run under a notch in landscape. -
Answered at S2: foliate’s paginator has
renderer.setStyles([before, after]), re-applied to every section before itsloadevent, and it repaints its own page background from the section root’s--theme-bg-color; the fixed-layout (PDF) renderer has no such hook, so a PDF page stays as painted. -
Learner-chosen word, gloss and unsure-background colours are single values and are exempt from the forced dark sheet, so a dark pick stays dark on a dark page. Making them scheme-aware pairs is a data-model change (two columns or a per-scheme row) and waits for evidence that learners hit it.
-
Whether the shell-less layout route should also drop the root
Containerpadding for the Experience routes, which today render the experience box inside it. Not this plan; noted for the surface-experience owner.