Class: Chunker

Chunker(content, renderToopt, optionsopt)

The Chunker class is responsible for processing and paginating HTML content into individual page layouts. It manages rendering, page flow, break handling, overflow detection, and layout cycles.

Constructor

new Chunker(content, renderToopt, optionsopt)

Create a new Chunker instance.

Create a new Chunker instance.

Parameters:
Name Type Attributes Default Description
content HTMLElement | Document

The DOM content to be paginated.

renderTo HTMLElement <optional>

Optional container element to render pages into.

options Object <optional>
{}

Configuration options.

Properties:
Name Type Description
hooks Object

Collection of lifecycle hooks.

pages Array.<Page>

Array of rendered pages.

total number

Total number of pages rendered.

stopped boolean

Whether rendering is currently stopped.

rendered boolean

Whether rendering has completed.

q Queue

Internal render queue.

content HTMLElement | Document

The original content passed to the chunker.

modifiedRules Object

Map of modified stylesheets during rendering.

charsPerBreak Array.<number>

Characters per page break for estimation.

maxChars number

Estimated maximum characters per page.

Source:

Members

rulesToDisable

Gathers and records rules that should be disabled during rendering.

Gathers and records rules that should be disabled during rendering.

Source:

Methods

addPage(blankopt) → {Page}

Adds a new page to the render flow.

Adds a new page to the render flow.

Parameters:
Name Type Attributes Default Description
blank boolean <optional>
false

Whether to add a blank page.

Source:
Returns:
  • The newly added Page instance.
Type
Page

(async) clonePage(originalPage)

Clones an existing page and appends it to the document.

Clones an existing page and appends it to the document.

Parameters:
Name Type Description
originalPage Page

The page to clone.

Source:

destroy()

Cleans up and removes all rendered elements and templates.

Cleans up and removes all rendered elements and templates.

Source:

disableRules(rendered)

Disables specific CSS rules that may interfere with rendering.

Disables specific CSS rules that may interfere with rendering.

Parameters:
Name Type Description
rendered HTMLElement

The rendered content container.

Source:

enableRules(rendered)

Re-enables the CSS rules that were previously disabled.

Re-enables the CSS rules that were previously disabled.

Parameters:
Name Type Description
rendered HTMLElement

The rendered content container.

Source:

(async) flow(content, renderTo) → {Promise.<Chunker>}

Starts the chunking and rendering process for the given content.

Starts the chunking and rendering process for the given content.

Parameters:
Name Type Description
content HTMLElement | Document

Content to be paginated.

renderTo HTMLElement

Element to render into.

Source:
Returns:
  • Returns itself once rendering is complete.
Type
Promise.<Chunker>

(async) handleBreaks(node, force)

Handles forced or conditional page breaks based on node metadata.

Handles forced or conditional page breaks based on node metadata.

Parameters:
Name Type Description
node Node

The node to inspect for break conditions.

force boolean

Force page break regardless of content.

Source:

(async, generator) layout(content, startAtopt) → {Object}

Generator that performs the layout step-by-step, yielding break tokens.

Generator that performs the layout step-by-step, yielding break tokens.

Parameters:
Name Type Attributes Description
content Document | HTMLElement

The parsed content.

startAt Object <optional>

Optional starting break token.

Source:
Yields:
- The current break token.
Type
Object

loadFonts() → {Promise.<Array.<string>>}

Waits for all fonts to load before rendering starts.

Waits for all fonts to load before rendering starts.

Source:
Returns:
  • A promise resolving to a list of font families loaded.
Type
Promise.<Array.<string>>

recoredCharLength(length)

Records the number of characters per page for average calculation.

Records the number of characters per page for average calculation.

Parameters:
Name Type Description
length number

Number of characters on the page.

Source:

removePages(fromIndexopt)

Removes rendered pages starting from the specified index.

Removes rendered pages starting from the specified index.

Parameters:
Name Type Attributes Default Description
fromIndex number <optional>
0

Index to start removing pages from.

Source:

(async) render(parsed, startAtopt) → {Promise.<Object>}

Main loop to handle the rendering lifecycle.

Main loop to handle the rendering lifecycle.

Parameters:
Name Type Attributes Description
parsed ContentParser

Parsed content.

startAt Object <optional>

Break token to resume from.

Source:
Returns:
  • Rendering result.
Type
Promise.<Object>

(async) renderAsync(renderer) → {Promise.<Object>}

Performs one asynchronous rendering step.

Performs one asynchronous rendering step.

Parameters:
Name Type Description
renderer AsyncGenerator

The renderer iterator.

Source:
Returns:
  • Result of rendering.
Type
Promise.<Object>

renderOnIdle(renderer) → {Promise.<Object>}

Renders a chunk of content when the browser is idle.

Renders a chunk of content when the browser is idle.

Parameters:
Name Type Description
renderer AsyncGenerator

The renderer iterator.

Source:
Returns:
  • Result of rendering.
Type
Promise.<Object>

setup(renderTo)

Sets up the page container and page template structure.

Sets up the page container and page template structure.

Parameters:
Name Type Description
renderTo HTMLElement

The DOM node to which pages should be rendered.

Source:

start()

Resets the rendering state.

Resets the rendering state.

Source:

stop()

Stop the rendering process.

Stop the rendering process.

Source: