accessible-books-in-browsers

Web-book UI contract v0

A book stamped <html data-webbook-contract="0"> guarantees everything listed here. A UI release (the CSS and JS under template/src/, or a remote release on the v0/ channel) may rely on these and nothing else. Anything not listed must be feature-detected.

Compatible UI changes ship within the v0 channel. A new incompatible contract requires reconverting from the original EPUB; there is no webbook-upgrader. Keep the source EPUB. Optional reader features must feature-detect their supporting files in older books.

src/template-contract.ts checks the converter’s side: the hooks it fills in, and that the template declares contract 0.

Scope note

New v0 conversions contain plain content and standalone navigation pages. Reader controls are built by JS from the release’s shell before feature initialization. Compatible control/styling changes therefore do not require rewriting content. Earlier v0 books may contain embedded chrome; release code feature-detects that shape and keeps it working. The detailed chrome hooks below describe that legacy shape and the current reader’s internal DOM, not requirements on newly generated content pages. The authoring template still has converter hooks, validated by template-contract.ts; those are separate from the delivered-content contract.

Document

Offline reading (optional reader enhancement)

Search data — search-data.json (optional)

Version 1 is { version: 1, lang, pages, passages }. pages contains { href, title } in spine order. Each passage contains { page, heading, text, lang? }; page indexes pages, and lang is present only when it differs from the book language. A narrated passage has its cue’s Web Annotation selector (or an id when the cue target keeps one). A non-narrated passage instead has selector: { type: "TextQuoteSelector", exact, prefix?, suffix? }. The browser builds its own index from this data on first search and resolves selectors against <main>.

Book audio map — audio-map.json (optional)

Version 1 is { version: 1, duration, pages, chapters }. duration and all times are seconds. pages contains every spine page as { href, title, start, duration, audio }; unnarrated pages have a zero duration and no audio (the page’s narration file, relative to the book root). chapters contains ascending top-level TOC positions as { title, href, time }. toc contains every TOC entry, at every level and in TOC order, whose heading has narration, as { href, time, end }: the book time span that speaks the heading at that entry’s target (the target, or the first heading in it; without narration in a heading, the first phrase at or after the target). Its href matches the TOC link’s. Reserved for a talking TOC; nothing uses it yet. When present, the UI enhances the per-page narration slider into a full-book timeline; without it (no narration, or the map can’t be fetched) the slider stays per page.

Inline appearance script (frozen)

This runs before first paint and is baked into every page, so no release can change it. It reads:

Key Values Effect
webbook-appearance auto | dark | light webbook-dark or webbook-light class on <html>
webbook-font-size integer, clamped to 50–200 --webbook-main-font-size: N% on <html>
webbook-font-family system-ui | sans-serif | serif --webbook-main-font-family on <html>: the value itself, except serif, which is Charter, "Bitstream Charter", serif, and sans-serif, which is "Avenir Next", Verdana, sans-serif
webbook-caption-mode 'true' webbook-caption-mode class on <html>
webbook-writing-mode 'horizontal' with data-webbook-writing-mode set and this key not horizontal: webbook-vertical class on <html> (and webbook-vertical-lr for vertical-lr)

Releases must keep writing these keys with these meanings and value ranges, and CSS must honor these classes and custom properties.

Caption mode is global. Both this script and the UI read the shared webbook-caption-mode key. The former per-book caption and color keys are ignored; there is no migration of their values.

Content (<main>)

Narration

Chrome

All IDs below are present on every page unless marked optional.

The chrome is in the order it appears on screen, so Tab follows it: the skip link, the top toolbar, <main>, spine navigation, then the bottom toolbar.

Spine navigation — nav#webbook-spine-nav

Basic navigation (optional) — nav#webbook-basic-nav

For reading without JavaScript, the first element in <body>: a button[popovertarget="webbook-toc-nav"] (“Contents”), and a#webbook-basic-previous[rel=prev] and a#webbook-basic-next[rel=next] with the page titles as text (removed when there’s no such page). The TOC has a button.webbook-basic-close[popovertarget="webbook-toc-nav"][popovertargetaction=hide]. The toolbar’s <audio> has controls. CSS hides all of these, and shows the toolbars, when <html> has webbook-dark, webbook-light or webbook-js, i.e. when the reader’s script runs; without it, CSS hides the toolbars except the <audio>, which shows the browser’s player.

Table of contents — nav#webbook-toc-nav[popover].webbook

Top toolbar — section#webbook-top-toolbar.webbook

Escape — div#webbook-escape-container

Resume banner

Bottom toolbar — section#webbook-toolbar.webbook

In this order:

The two groups are present together or not at all.

main[data-webbook-print-page-before] optionally carries the last print-page label from an earlier web page. The value is the publication’s label, which may be roman or otherwise non-numeric. It is omitted before the publication’s first pagebreak.

Go to page — section#webbook-menu[popover].webbook

Search — section#webbook-search[popover].webbook

About — section#webbook-info[popover].webbook

Settings — section#webbook-settings[popover].webbook

Control Type
#webbook-highlight-auto-toggle checkbox
#webbook-color-picker color
#webbook-font-size-range (50–200, step 5), #webbook-font-size-value, #webbook-reset-font-size range, text, button
#webbook-font-family-options (system-ui, sans-serif, serif) select
#webbook-appearance-options (auto, dark, light) select
#webbook-dialog-blur-toggle checkbox
#webbook-caption-mode-toggle checkbox
#webbook-rate-range (50–200, step 5), #webbook-rate-value, #webbook-reset-rate range, text, button
#webbook-skip-pagebreak-toggle, #webbook-skip-footnote-toggle (“Skip notes”: footnotes, endnotes and generic notes), #webbook-skip-sidebar-toggle checkbox
#webbook-resume-toggle checkbox

The panel retains h2#webbook-settings-hd. Section headings and containers are created by the UI; there is no fieldset around the whole panel.

Created by the UI (not part of the contract)

The JS creates these, so a release may change them freely:

Copying equations and code

The reader also creates equation/code Copy controls (not publication contract ids): span.webbook-copy-unit around display MathML, or div.webbook-copy-unit.webbook-copy-code around a pre, with a button after the source, never inside a code listing. MathML includes math[display=block], .webbook-equation math, .disp-formula math, and an expression that is the only content of its block. Wrapping and focus hooks are added only after narration cue elements are resolved. Inline math has no Copy button; tabindex=-1 permits screen reader focus, with a temporary Tab stop when the expression needs keyboard scrolling. An overflowing display equation or code listing gets a temporary Tab stop for keyboard scrolling; it is removed when the source fits again. Copy controls add no text to a narrated phrase’s textContent. Copy equation, Copy selection and Copy code are reader actions registered without default keys (no menu: selecting text and the browser’s own Copy covers inline math). Controls are hidden without a secure context and Clipboard API. The Text section creates select#webbook-copy-math-options; webbook-copy-math-format stores mathml (default) or latex and participates in settings export/import/reset.

Equation clipboard payloads include MathML in text/html, with reader attributes removed, and LaTeX or MathML in text/plain. LaTeX uses a non-empty annotation[encoding=application/x-tex], then non-empty alttext, then lazy reader-side conversion; failure preserves complete MathML. Text selections containing math keep complete expressions in HTML and use $…$ around LaTeX. Code is plain text from pre.textContent, without buttons. Conversion preserves MathML fallback images by copying/rewriting math[altimg] through the image registry. alttext stays as the book has it, empty or not; no alternatives or TeX are added to publication content.

The vendored converter is mathml-to-latex 1.8.0 (MIT), 169,560 bytes with its license and native DOMParser adaptation, 36,975 bytes gzipped. It loads on the first copy that needs conversion.

Settings file

Other tools may use this versioned format. Export downloads webbook-settings.json:

{
  "format": "webbook-settings",
  "version": 1,
  "exported": "2026-11-10T12:00:00.000Z",
  "settings": { "webbook-colors": "sepia", "webbook-font-size": null }
}

settings maps the preference keys in settings-file.js to localStorage strings or null (unset, use the default). Export includes every registered key; shortcut mappings retain their JSON string representation. Reading positions, one-shot navigation flags and tab state are excluded. Import validates the complete file before writing: wrong formats, unsupported versions and invalid known values are rejected; unknown keys are ignored, missing keys retain their current values, and null removes a preference. Import and reset reload the current page while keeping its position and narration time. Reset removes only registered preference keys. The UI’s sections, jump links, transfer buttons and two-press reset confirmation are not publication contract ids. The three transfer actions (export-settings, import-settings, reset-settings) have no default shortcuts and can be assigned in the shortcut editor.

Agent tools

When enabled and the browser implements WebMCP, the UI registers these stable imperative tools on document.modelContext (with the older navigator.modelContext as a fallback): reader_status, list_contents, go_to, narration, set_reading_option, search_book, and read_text. Registration is progressive enhancement and failures do not affect reading. Turning the global setting off aborts all registrations. Search results and returned publication text carry WebMCP’s untrusted-content annotation; no tool exposes state from another book or arbitrary storage.

Reader state (localStorage)

Books from different releases, and different books on the same origin, share these keys, so a release must keep reading values written by earlier v0 releases.

Key Values
webbook-appearance auto | dark | light, read by the inline script to choose the light or dark base before the first paint. Written by the Colors setting to match its choice (auto for Automatic, otherwise by the chosen background), so pages load without a flash. A light or dark value from before the Colors setting becomes its choice once
webbook-appearance-migrated 'true' once that has happened
webbook-font-size integer string, 50–200 in steps of 5
webbook-font-family system-ui | sans-serif | serif
webbook-copy-math-format mathml (default) | latex: plain-text form for equations; HTML always contains MathML
webbook-caption-mode 'true' | 'false' (default false): global caption mode, also read by the inline appearance script
webbook-caption-entry 'first' | 'last' (one-shot, cross-page): the phrase to start at after stepping across a page boundary, in or out of caption mode
webbook-highlight-auto 'true' | 'false' (default true)
webbook-highlight-color CSS hex color
webbook-highlight-style background | underline | both (default background)
webbook-line-height 1.8 | 2; unset is 1.6, the reader’s own
webbook-letter-spacing, webbook-word-spacing wider | widest; unset is no extra spacing
webbook-line-length narrow | medium | wide; unset is medium. Horizontal text: 50 and 65 characters, within half and three quarters of the text’s width, and all of it; vertical text: columns of 20 and 30 characters, and the whole height
webbook-writing-mode horizontal: a book with vertical text is shown horizontally; unset follows the book (global)
webbook-colors unset (Automatic) | light | dark | cream | sepia | gray | blue | custom, globally. Legacy auto, white and black read as Automatic, Light and Dark.
webbook-colors-text, webbook-colors-background CSS hex colors for the shared custom choice
webbook-colors-text-auto 'true' | 'false' (default true): automatic custom text color, globally
webbook-dialog-backdrop-blur 'true' | 'false' (default true)
webbook-toolbar-auto-hide 'false' while the toolbars stay shown; unset hides them automatically (global)
webbook-rate integer string, 50–200 in steps of 5
webbook-time-display elapsed | chapter | book (default elapsed)
webbook-skip-pagebreak, webbook-skip-footnote, webbook-skip-sidebar 'true' means skip, 'false' means play; when unset, notes (webbook-skip-footnote: footnotes, endnotes, a book’s endnotes section, and generic notes) are skipped and the others played
webbook-resume-enabled 'true' | 'false' (default true)
webbook-keyboard-shortcuts 'true' | 'false' (default true)
webbook-note-references What narration does at the end of a phrase with note references: 'button' (default; carry on, with the note button), 'pause' (pause for 2 seconds), 'follow' (go to each note, then back)
webbook-note-auto-return 'true' | 'false' (default true): after reading a note it went to, narration goes back to the text, or stops at the end of the note
webbook-note-wait-sound 'true' | 'false' (default false): play quiet ticks during the brief pause at a phrase with notes
webbook-sound-headings, webbook-sound-notes, webbook-sound-lists-tables 'true' | 'false' (default false): a tone at headings, a bell at footnotes and endnotes, knocks entering and leaving lists and tables
webbook-agent-tools 'true' | 'false' (default true), shared across books
webbook-keyboard-shortcut-map JSON { "version": 1, "bindings": { "<action id>": [keySpec, …] } }; only custom bindings, with [] disabling an action. Missing actions use their defaults. Shared across books; malformed data and unknown actions/fields are ignored.
webbook-toc-depth 1 | 2 | 3 | all (default all), shared across books
webbook-appearance:<book-id> 'settings' | 'published' (default settings): this book’s Appearance; only for books with publisher styles
webbook-resume:<book-id> JSON { page, anchorId?, audioTime?, ts }; older elementId values remain readable
webbook-resume-banner-pending 'true' (one-shot)
webbook-autoplay, webbook-autoplay-target 'true', absolute URL without hash (one-shot)

Each shortcut keySpec stores a physical KeyboardEvent.code and exact boolean modifiers, e.g. { "code": "KeyF", "shift": true, "alt": false, "ctrl": false, "meta": false }.

sessionStorage: webbook-resume-checked; webbook-search-highlight is a one-shot search target used to preserve matched-word highlighting across a full page load when in-place navigation is unavailable.

URLs

The saved-books management page is src/offline-books.html, linked from About. It reads the same-origin offline database and sends per-book operations to each existing registered worker. Refresh uses that book’s foreground lease and stages an update; activation remains explicit and requires other book tabs to close. Removal keeps preferences. A webbook-offline-library- cache retains the hosting reader’s src/ files so the management page can reopen after all books are removed; it contains no publication text/audio/images. The root worker serves this shell only for the management page and its subresources when the hosting book has no active snapshot.

Remote delivery and plain book shape (bootstrap API 1)

See REMOTE_UI.md for release tooling, retained artifacts, verification receipts, rollback, the selected repository, publication and outstanding device checks.