0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
<epub-reader> opens an EPUB book (the common e-book file format) and shows it with a contents sidebar, a toolbar, search, bookmarks and highlights. It reads Vanilla Breeze design tokens for its own controls and for the text of the book, so both follow the active theme.
Load the component from a CDN with one script tag. The package has no build step, so the file is served from its src/ folder and imports its sibling modules from there.
Or install it from npm and import it in your own script.
npm
npm install @profpowell/epub-reader
Import
import'@profpowell/epub-reader';
The component needs a browser with DecompressionStream, which it uses to unpack the book: Chrome 80, Firefox 113, Safari 16.4 or later.
Demo
The reader loads a short sample book from the component's own site. Change the site theme, then move to another chapter, to see the controls and the book text change with it.
Usage
Point src at an EPUB file. A file on another site must allow cross-origin requests.
The EPUB file to load. Changing it loads the new book.
start
Number
0
The spine index to open first.
hide-toc
Boolean
Off
Starts with the contents sidebar hidden.
allow-scripts
Boolean
Off
Lets scripts inside the book run, for interactive books such as quizzes. A script in the book can then reach the host page, so turn it on only for books you trust.
Methods and properties
Member
Purpose
open(source)
Loads a book from a URL, a File, a Blob or an ArrayBuffer. It replaces any open book.
close()
Unloads the book and frees the memory it used.
next(), prev()
Move to the next or previous chapter.
goToIndex(index, fragment?), goToPath(path)
Jump to a spine index, or to a file path inside the book such as chapter2.xhtml#sec1.
search(query, options?)
Searches the whole book. Resolves with a list of matches and the text around each one.
find(open)
Opens or closes the find bar for the current chapter.
typography, resetTypography()
Reading settings applied to the book text: typeface, text size, line height, paragraph spacing and justification. Assign an object with the settings you want to change.
Work with the library, the list of books the reader has stored in the browser.
getStorageEstimate()
Resolves with how much browser storage is in use, or null where the browser cannot say.
The reader saves reading settings in localStorage. It saves opened books, reading positions, bookmarks and highlights in IndexedDB, the browser's built-in database. Nothing is sent to a server.
Events
All events bubble and cross shadow DOM boundaries.
Event
Detail
Fires when
epub-loaded
{ metadata, spineLength, toc }
A book has loaded.
epub-navigate
{ index, path, title }
The reader moves to another chapter.
epub-error
{ error }
A book failed to load.
epub-position-restored
{ spineIndex, scrollFraction, bookId }
The reader returns to the place saved for this book.
epub-typography-change
{ typography }
A reading setting changes.
epub-bookmarks-change
{ bookmarks }
A bookmark is added or removed.
epub-highlights-change
{ highlights }
A highlight is added or removed.
epub-library-change
{ reason, id }
A book is added to or removed from the library, or the library is cleared.
The component has no CSS custom properties of its own. See the epub-reader documentation for the full detail.
With Vanilla Breeze
The reader renders in light DOM and its styles use Vanilla Breeze tokens directly. For the text of the book it reads four tokens from the element and applies them inside the chapter each time a chapter loads.
Token
Drives
--color-background
Reader background, and the page background of the book
--color-text
Reader text, and the text of the book
--color-interactive
Active buttons, the current contents entry, and links in the book
--color-border, --border-width-thin
Borders in the reader, and rules in the book
--color-surface, --color-surface-raised
Toolbar, sidebar and panel backgrounds, and button backgrounds
There is no component-level property to set first. Each value is the Vanilla Breeze token, then a built-in default. Without Vanilla Breeze the built-in defaults apply.
Two of the names the component looks for are not Vanilla Breeze tokens: --color-danger (error messages) and --color-interactive-text (text on active buttons). Those use the built-in defaults unless you define them.
To change one reader, set the tokens on the element. They apply to that reader and to the book inside it.