Documentation Index
Fetch the complete documentation index at: https://mintlify.com/johnfactotum/foliate-js/llms.txt
Use this file to discover all available pages before exploring further.
paginator.js registers the <foliate-paginator> custom element, the reflowable renderer for flowing-text e-books. It paginates content using CSS multi-column, supports both paginated and scrolled flows, handles vertical writing modes, and exposes header and footer regions for running heads. Under normal use the <foliate-view> element creates and manages a paginator automatically, but you can also instantiate it directly for standalone use.
Import
Core methods
open(book)
Opens a book object. Setspaginator.bookDir and paginator.sections from the book, and registers a CSS transform hook if book.transformTarget is present (it strips -epub- vendor prefixes and converts vw/vh units so they do not interfere with column layout).
A book object that satisfies the foliate-js book interface. At minimum,
book.sections must be present and each section must expose a .load() method.goTo(target)
Navigates to a resolved destination.An object (or a
Promise that resolves to an object) with the following shape:index(number, required) — the section index to navigate to.anchor(function | number, optional) — either a function(doc) => Range | Elementthat locates the target within the section document, or a fraction from 0 to 1.select(boolean, optional) — iftrue, selects the text at the anchor after navigation.
prev([distance]) / next([distance])
Turns the page backward or forward. In paginated mode, scrolls by one page. In scrolled mode, scrolls bydistance pixels (defaulting to the full scroll container height or width).
Scroll distance in pixels. Only used in scrolled flow mode.
getContents()
Returns an array describing the currently loaded section. The paginator renders one section at a time, so the array has at most one element. ReturnsArray<{ index: number, doc: Document, overlayer: Overlayer | undefined }>.
scrollToAnchor(anchor, select?)
Scrolls the view so thatanchor is visible. Used by view.js for TTS highlighting.
A DOM
Range, an Element, or a fraction (0–1).If
true, the scroll reason is recorded as 'selection' rather than 'navigation', which affects how the text selection is set after scrolling.setStyles(styles)
Injects custom CSS into the current section document. Use this to apply user-defined font, size, or colour preferences.Either a single CSS string (appended after the section’s own styles) or a two-element array
[beforeStyle, afterStyle] where beforeStyle is prepended before the section’s styles and afterStyle is appended after.destroy()
Disconnects the resize observer, destroys the inner view, and unloads the current section. Call this when removing the element from the DOM.Layout attributes
Layout is configured exclusively through HTML attributes — there is no JavaScript property API. Set attributes withsetAttribute() and remove them with removeAttribute(). The paginator re-renders automatically when observed attributes change.
static observedAttributes = ['flow', 'gap', 'margin', 'max-inline-size', 'max-block-size', 'max-column-count']
When present, page turns use a sliding animation. Remove the attribute to disable animation. This is a boolean attribute: its presence enables it, its absence disables it.
Either
"paginated" (CSS multi-column, page-at-a-time) or "scrolled" (continuous scroll). Switching between modes does not reload the section.Height of the header and footer regions in pixels (unit must be
px). Example: "48px". Defaults to 48px.Column gap as a CSS percentage relative to the container width. Example:
"7%". Defaults to 7%. The outer edge padding is adjusted to visually match the inner column gap.Maximum column width in pixels (unit must be
px). Controls how wide each text column can be before a second column is added. Example: "720px". Defaults to 720px.Maximum block-axis size in pixels (unit must be
px). For horizontal writing, this is the maximum height of the reading area. Example: "1440px". Defaults to 1440px.Maximum number of columns as an integer. Has no effect in scrolled mode or when the container is in portrait orientation. Example:
"2". Defaults to 2.Running heads and footers
In paginated mode the paginator creates header and footer elements, one per visible column, which you can use to display the current chapter title, page number, or any other marginal content. These elements are not available in scrolled mode.| Property | Description |
|---|---|
paginator.heads | An array of Elements, one per column. Each element is a child of the shadow DOM header region. null in scrolled mode. |
paginator.feet | An array of Elements, one per column, for the footer region. null in scrolled mode. |
::part() pseudo-element:
CSS filter part
Both renderer elements expose afilter part that applies CSS filters to the book content only, leaving annotation overlays unaffected.
Events
All events areCustomEvents dispatched on the <foliate-paginator> element. The <foliate-view> element listens to these internally and re-dispatches them (or handles them) at the view level.
load
Fired after a section document finishes loading.The loaded section’s
Document object.The section index.
relocate
Fired whenever the visible location changes.Why the relocation happened. One of
'page', 'snap', 'scroll', 'navigation', 'selection', or 'anchor'.A DOM
Range covering the currently visible text.The current section index.
Reading progress within the section (0–1). In paginated mode this is
(page - 1) / (pages - 2); in scrolled mode it is scrollTop / scrollHeight.The fraction of the section that a single page represents (paginated mode only). Useful for estimating section page count.
create-overlayer
Fired when the renderer creates a new overlay surface for a section. The handler must callevent.detail.attach(overlayer) with an Overlayer instance.
The section document.
The section index.
Call with an
Overlayer instance to attach it to the page: e.detail.attach(new Overlayer()).