Global

Members

Paged

Expose the Paged API to the global window object.

Expose the Paged API to the global window object. Useful for debugging or for external scripts that want to access the API.

Source:

config :PagedConfig

Type:
Source:

previewer :Previewer

Initialize the previewer with optional settings from config.

Initialize the previewer with optional settings from config.

Type:
Source:

ready :Promise.<("interactive"|"complete")>

A promise that resolves when the DOM is ready (interactive or complete).

A promise that resolves when the DOM is ready (interactive or complete). Used to defer preview rendering until the page is ready.

Type:
  • Promise.<("interactive"|"complete")>
Source:

registeredHandlers :Array.<function()>

Array of all registered handler classes, composed from different modules.

Array of all registered handler classes, composed from different modules.

Type:
  • Array.<function()>
Source:

(constant) requestIdleCallback

Uses requestIdleCallback if available, otherwise falls back to requestAnimationFrame.

Uses requestIdleCallback if available, otherwise falls back to requestAnimationFrame.

Source:

Methods

CSSValueToString(obj) → {string}

Converts a CSSValue object to a string representation.

Converts a CSSValue object to a string representation.

Parameters:
Name Type Description
obj Object

The CSSValue object.

Source:
Returns:

The combined CSS value and unit string.

Type
string

UUID() → {string}

Generates a UUID (version 4).

Generates a UUID (version 4). Based on: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript

Source:
Returns:

A UUID string.

Type
string

attr(element, attributes) → {string|null|undefined}

Returns the value of the first attribute found from the given list on the element.

Returns the value of the first attribute found from the given list on the element.

Parameters:
Name Type Description
element Element

The element to check attributes on.

attributes Array.<string>

Array of attribute names to look for.

Source:
Returns:

The attribute value, or undefined if none found.

Type
string | null | undefined

breakInsideAvoidParentNode(node) → {Node|null}

Finds the closest ancestor of a node with a dataset.breakInside attribute equal to "avoid".

Finds the closest ancestor of a node with a dataset.breakInside attribute equal to "avoid". Traverses up the DOM tree until such a node is found or root is reached.

Parameters:
Name Type Description
node Node

The starting node to search from.

Source:
Returns:

The closest ancestor node with dataset.breakInside === "avoid", or null if none found.

Type
Node | null

child(node, index) → {Node}

Returns the child node at a specific index.

Returns the child node at a specific index.

Parameters:
Name Type Description
node Node

The parent node.

index number

The index of the child.

Source:
Returns:

The child node.

Type
Node

cleanPseudoContent(el, trimopt) → {string|undefined}

Cleans pseudo-element content strings by:

  • Trimming specified characters from the start and end (default: quotes and spaces).

Cleans pseudo-element content strings by:

  • Trimming specified characters from the start and end (default: quotes and spaces).
  • Escaping quotes.
  • Replacing newlines with CSS-compatible \00000A notation.
Parameters:
Name Type Attributes Default Description
el string | null

The pseudo-element content string (e.g., from content CSS property).

trim string <optional>
"\"' "

Characters to trim from both ends of the string.

Source:
Returns:

The cleaned content string, or undefined if input is null or undefined.

Type
string | undefined

cleanSelector(el) → {string|undefined}

Removes specific pseudo-elements from a CSS selector string.

Removes specific pseudo-elements from a CSS selector string. Currently strips:

  • ::footnote-call
  • ::footnote-marker
Parameters:
Name Type Description
el string | null

The CSS selector string to clean.

Source:
Returns:

The cleaned selector string, or undefined if input is null or undefined.

Type
string | undefined

cloneNode(n, deepopt) → {Node}

Clones a node.

Clones a node.

Parameters:
Name Type Attributes Default Description
n Node

The node to clone.

deep boolean <optional>
false

Whether to clone deeply.

Source:
Returns:

The cloned node.

Type
Node

cloneNodeAncestor(node, deepopt) → {Node}

Clones a node and removes certain attributes like 'id' and break-related attributes.

Clones a node and removes certain attributes like 'id' and break-related attributes.

Parameters:
Name Type Attributes Default Description
node Node

The node to clone.

deep boolean <optional>
false

Whether to perform a deep clone.

Source:
Returns:

The cloned node with adjusted attributes.

Type
Node

copyWidth(originalElement, destElement)

Copies the width style from an original element to a destination element.

Copies the width style from an original element to a destination element. The width is computed using getComputedStyle and fallback bounding rect if needed.

Parameters:
Name Type Description
originalElement Element

The element to copy width from.

destElement Element

The element to apply the copied width to.

Source:

defer() → {object}

Creates a deferred object with promise, resolve, and reject.

Creates a deferred object with promise, resolve, and reject.

Source:
Returns:

Deferred object with properties:

  • promise: {Promise} The promise object.
  • resolve: {function} Function to resolve the promise.
  • reject: {function} Function to reject the promise.
  • id: {string} Unique identifier.
Type
object

displayedElementAfter(node, limiteropt, descendopt) → {Element|undefined}

Finds the next displayed Element node after the given node.

Finds the next displayed Element node after the given node. Skips elements marked as undisplayed via dataset.undisplayed.

Parameters:
Name Type Attributes Default Description
node Node

The reference node.

limiter Node <optional>

Optional node at which traversal stops.

descend boolean <optional>
false

Whether to descend into child nodes.

Source:
Returns:

The next displayed Element node or undefined if none found.

Type
Element | undefined

displayedElementBefore(node, limiteropt, descendopt) → {Element|undefined}

Finds the previous displayed Element node before the given node.

Finds the previous displayed Element node before the given node. Skips elements marked as undisplayed via dataset.undisplayed.

Parameters:
Name Type Attributes Default Description
node Node

The reference node.

limiter Node <optional>

Optional node at which traversal stops.

descend boolean <optional>
false

Whether to descend into child nodes.

Source:
Returns:

The previous displayed Element node or undefined if none found.

Type
Element | undefined

elementAfter(node, limiteropt, descendopt) → {Element|undefined}

Finds the next Element node after the given node.

Finds the next Element node after the given node. Skips non-element nodes.

Parameters:
Name Type Attributes Default Description
node Node

The reference node.

limiter Node <optional>

Optional node at which traversal stops.

descend boolean <optional>
false

Whether to descend into child nodes.

Source:
Returns:

The next Element node or undefined if none found.

Type
Element | undefined

elementBefore(node, limiteropt, descendopt) → {Element|undefined}

Finds the previous Element node before the given node.

Finds the previous Element node before the given node. Skips non-element nodes.

Parameters:
Name Type Attributes Default Description
node Node

The reference node.

limiter Node <optional>

Optional node at which traversal stops.

descend boolean <optional>
false

Whether to descend into child nodes.

Source:
Returns:

The previous Element node or undefined if none found.

Type
Element | undefined

filterTree(content, funcopt, whatopt)

Traverses a DOM subtree and removes nodes that match a filter function.

Traverses a DOM subtree and removes nodes that match a filter function.

Parameters:
Name Type Attributes Default Description
content Node

The root node to start traversal from. If falsy, defaults to this.dom.

func function <optional>

Optional filter function used by the TreeWalker. Should return one of the constants from NodeFilter: - NodeFilter.FILTER_ACCEPT to keep the node, - NodeFilter.FILTER_REJECT or FILTER_SKIP to exclude it.

what number <optional>
NodeFilter.SHOW_ALL

Optional mask specifying which node types to show. Defaults to all nodes.

Source:

findCssSelector(ele) → {string}

Finds a unique CSS selector for a given element.

Finds a unique CSS selector for a given element. The selector is unique within the element's document.

Parameters:
Name Type Description
ele Element

The element to find a selector for.

Source:
Returns:

A unique CSS selector string.

Type
string

findElement(node, doc, forceQueryopt) → {Element|undefined}

Finds an element in the document by the node's data-ref attribute.

Finds an element in the document by the node's data-ref attribute.

Parameters:
Name Type Attributes Default Description
node Node

The node with a data-ref attribute.

doc Document

The document to search in.

forceQuery boolean <optional>
false

Whether to force a querySelector search.

Source:
Returns:

The found element or undefined.

Type
Element | undefined

findRef(ref, doc, forceQueryopt) → {Element|null}

Finds an element in the document by data-ref value.

Finds an element in the document by data-ref value.

Parameters:
Name Type Attributes Default Description
ref string

The data-ref string to find.

doc Document

The document to search in.

forceQuery boolean <optional>
false

Whether to force querySelector search.

Source:
Returns:

The found element or null.

Type
Element | null

getBoundingClientRect(element) → {DOMRect|undefined}

Gets the bounding client rectangle of an element.

Gets the bounding client rectangle of an element. Falls back to using Range if element.getBoundingClientRect is undefined.

Parameters:
Name Type Description
element Element

The DOM element to get the bounding rectangle for.

Source:
Returns:

The bounding client rectangle or undefined if no element.

Type
DOMRect | undefined

getClientRects(element) → {DOMRectList|undefined}

Gets the client rectangles of an element.

Gets the client rectangles of an element. Falls back to using Range if element.getClientRects is undefined.

Parameters:
Name Type Description
element Element

The DOM element to get client rectangles for.

Source:
Returns:

The client rectangles or undefined if no element.

Type
DOMRectList | undefined

getNodeWithNamedPage(node, limiteropt) → {Node|null|undefined}

Finds the closest ancestor (including the node itself) that has a dataset.page attribute.

Finds the closest ancestor (including the node itself) that has a dataset.page attribute. Traverses up the DOM tree until the optional limiter node is reached.

Parameters:
Name Type Attributes Description
node Node

The starting node to search from.

limiter Node <optional>

Optional ancestor node to stop the search at (exclusive).

Source:
Returns:

The closest node with dataset.page, null if none found, or undefined if limiter is reached without finding.

Type
Node | null | undefined

hasContent(node) → {boolean}

Checks if a node has any content.

Checks if a node has any content. Returns true for element nodes or non-empty text nodes.

Parameters:
Name Type Description
node Node

The node to check.

Source:
Returns:

True if the node has content, false otherwise.

Type
boolean

hasTextContent(node) → {boolean}

Checks if a node or any of its immediate child text nodes have non-empty text content.

Checks if a node or any of its immediate child text nodes have non-empty text content.

Parameters:
Name Type Description
node Node

The node to check.

Source:
Returns:

True if the node or any child text node has non-empty text content, false otherwise.

Type
boolean

inIndexOfRefs(node, doc) → {number|undefined}

Retrieves the index of a node's reference in the document's indexOfRefs.

Retrieves the index of a node's reference in the document's indexOfRefs.

Parameters:
Name Type Description
node Node

The node with a data-ref attribute.

doc Document

The document containing indexOfRefs.

Source:
Returns:

The index of the reference, or undefined if not found.

Type
number | undefined

indexOf(node) → {number}

Gets the index of a node among its siblings.

Gets the index of a node among its siblings.

Parameters:
Name Type Description
node Node

The node to find the index for.

Source:
Returns:

The index of the node.

Type
number

indexOfTextNode(node, parent, hyphen) → {number}

Finds the index of a text node within its parent's child nodes.

Finds the index of a text node within its parent's child nodes. If the text node has a previous sibling, tries to find the matching element by data-ref attribute and returns its index + 1. Otherwise, matches by text content. Optionally considers hyphenation removal in the text.

Parameters:
Name Type Description
node Node

The text node to find the index for.

parent Node

The parent node containing the child nodes.

hyphen string

The hyphenation string to remove if present at the end of the text.

Source:
Returns:

The index of the text node within the parent's child nodes, or -1 if not found.

Type
number

initializeHandlers(chunker, polisher, caller) → {Handlers}

Creates and initializes a new Handlers instance.

Creates and initializes a new Handlers instance.

Parameters:
Name Type Description
chunker Object

The chunker object to pass to handlers.

polisher Object

The polisher object to pass to handlers.

caller Object

The caller object to pass to handlers.

Source:
Returns:

The initialized Handlers instance.

Type
Handlers

isAllWhitespace(node) → {boolean}

Determine whether a node's text content is entirely whitespace.

Determine whether a node's text content is entirely whitespace.

Parameters:
Name Type Description
node Node

A node implementing the |CharacterData| interface (i.e., a |Text|, |Comment|, or |CDATASection| node

Source:
Returns:

true if all of the text content of |nod| is whitespace, otherwise false.

Type
boolean

isContainer(node) → {boolean}

Determines if a node is considered a container (block) element.

Determines if a node is considered a container (block) element.

Parameters:
Name Type Description
node Node

The node to check.

Source:
Returns:

True if the node is a container, false if it is inline or hidden.

Type
boolean

isElement(node) → {boolean}

Checks if a given node is an Element node.

Checks if a given node is an Element node.

Parameters:
Name Type Description
node Node

The node to check.

Source:
Returns:

True if the node is an Element (nodeType === 1), else false.

Type
boolean

isIgnorable(node) → {boolean}

Determine if a node should be ignored by the iterator functions.

Determine if a node should be ignored by the iterator functions. taken from https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace#Whitespace_helper_functions

Parameters:
Name Type Description
node Node

An object implementing the DOM1 |Node| interface.

Source:
Returns:

true if the node is:

  1. A |Text| node that is all whitespace
  2. A |Comment| node and otherwise false.
Type
boolean

isText(node) → {boolean}

Checks if a given node is a Text node.

Checks if a given node is a Text node.

Parameters:
Name Type Description
node Node

The node to check.

Source:
Returns:

True if the node is a Text node (nodeType === 3), else false.

Type
boolean

isVisible(node) → {boolean}

Checks if a node is visible (not display:none).

Checks if a node is visible (not display:none).

Parameters:
Name Type Description
node Node

The node to check.

Source:
Returns:

True if visible, false otherwise.

Type
boolean

letters(wordRange) → {Range}

Generator function to yield letter ranges from a word range.

Generator function to yield letter ranges from a word range.

Parameters:
Name Type Description
wordRange Range

The Range object representing a word.

Source:
Yields:
A Range object for each letter in the word.
Type
Range

needsBreakAfter(node) → {boolean}

Checks if a node requires a break before it according to dataset.breakBefore attribute.

Checks if a node requires a break before it according to dataset.breakBefore attribute.

Parameters:
Name Type Description
node Node

The node to check.

Source:
Returns:

True if a break before is needed, false otherwise.

Type
boolean

needsBreakBefore(node) → {boolean}

Checks if a node requires a break before it according to dataset.breakBefore attribute.

Checks if a node requires a break before it according to dataset.breakBefore attribute.

Parameters:
Name Type Description
node Node

The node to check.

Source:
Returns:

True if a break before is needed, false otherwise.

Type
boolean

needsPageBreak(node, previousSignificantNode) → {boolean}

Determines if a page break is needed between the given node and the previous significant node.

Determines if a page break is needed between the given node and the previous significant node.

Parameters:
Name Type Description
node Node

The current node.

previousSignificantNode Node

The previous significant node.

Source:
Returns:

True if a page break is needed, false otherwise.

Type
boolean

needsPreviousBreakAfter(node) → {boolean}

Checks if a node's previous sibling requires a break after it according to dataset.previousBreakAfter attribute.

Checks if a node's previous sibling requires a break after it according to dataset.previousBreakAfter attribute.

Parameters:
Name Type Description
node Node

The node to check.

Source:
Returns:

True if the previous break after is needed, false otherwise.

Type
boolean

nextSignificantNode(sib) → {Node|null}

Version of |nextSibling| that skips nodes that are entirely whitespace or comments.

Version of |nextSibling| that skips nodes that are entirely whitespace or comments.

Parameters:
Name Type Description
sib ChildNode

The reference node.

Source:
Returns:

Either:

  1. The closest next sibling to |sib| that is not ignorable according to |is_ignorable|, or
  2. null if no such node exists.
Type
Node | null

nextValidNode(node) → {Node|null}

Finds the next valid node in the sibling/parent chain.

Finds the next valid node in the sibling/parent chain.

Parameters:
Name Type Description
node Node

The starting node.

Source:
Returns:

The next valid node or null.

Type
Node | null

nodeAfter(node, limiteropt, descendopt) → {Node|undefined}

Finds the next significant node after the given node, optionally descending into children.

Finds the next significant node after the given node, optionally descending into children. Returns undefined if the limiter node is reached.

Parameters:
Name Type Attributes Default Description
node Node

The reference node.

limiter Node <optional>

Optional node at which traversal stops.

descend boolean <optional>
false

Whether to descend into child nodes.

Source:
Returns:

The next significant node or undefined if none found.

Type
Node | undefined

nodeBefore(node, limiteropt, descendopt) → {Node|undefined}

Finds the previous significant node before the given node, optionally descending into children.

Finds the previous significant node before the given node, optionally descending into children. Returns undefined if the limiter node is reached.

Parameters:
Name Type Attributes Default Description
node Node

The reference node.

limiter Node <optional>

Optional node at which traversal stops.

descend boolean <optional>
false

Whether to descend into child nodes.

Source:
Returns:

The previous significant node or undefined if none found.

Type
Node | undefined

parentOf(node, nodeName, limiter) → {Node|undefined}

Find a parent with a given node name.

Find a parent with a given node name.

Parameters:
Name Type Description
node Node

initial Node

nodeName string

node name (eg. "TD", "TABLE", "STRONG"...)

limiter Node

go up to the parent until there's no more parent or the current node is equals to the limiter

Source:
Returns:
  • Either:
  1. The closest parent for a the given node name, or
  2. undefined if no such node exists.
Type
Node | undefined

positionInNodeList(element, nodeList) → {number}

Find the position of an element in a NodeList.

Find the position of an element in a NodeList.

Parameters:
Name Type Description
element Element

The element to find.

nodeList NodeList

The NodeList to search within.

Source:
Returns:

The index of the element in the NodeList, or -1 if not found.

Type
number

prevValidNode(node) → {Node|null}

Finds the previous valid node in the sibling/parent chain.

Finds the previous valid node in the sibling/parent chain.

Parameters:
Name Type Description
node Node

The starting node.

Source:
Returns:

The previous valid node or null.

Type
Node | null

previousSignificantNode(sib) → {Node|null}

Version of |previousSibling| that skips nodes that are entirely whitespace or comments.

Version of |previousSibling| that skips nodes that are entirely whitespace or comments. (Normally |previousSibling| is a property of all DOM nodes that gives the sibling node, the node that is a child of the same parent, that occurs immediately before the reference node.)

Parameters:
Name Type Description
sib ChildNode

The reference node.

Source:
Returns:

Either:

  1. The closest previous sibling to |sib| that is not ignorable according to |is_ignorable|, or
  2. null if no such node exists.
Type
Node | null

querySelectorEscape(value) → {string}

Escapes a string for use in a CSS selector.

Escapes a string for use in a CSS selector. Allows # and . characters.

Parameters:
Name Type Description
value string

The string to escape.

Source:
Throws:

If no argument is provided.

Type
TypeError
Returns:

The escaped string.

Type
string

rebuildAncestors(node) → {DocumentFragment}

Rebuilds the ancestor tree of a given node as a document fragment.

Rebuilds the ancestor tree of a given node as a document fragment.

Parameters:
Name Type Description
node Node

The node for which ancestors are rebuilt.

Source:
Returns:

A fragment containing cloned ancestors of the node.

Type
DocumentFragment

rebuildTableRow(node, alreadyRendered, existingChildrenopt) → {HTMLTableRowElement}

Rebuilds a table row element by cloning and adjusting its columns, including handling rowspans.

Rebuilds a table row element by cloning and adjusting its columns, including handling rowspans. Uses an existing rendered DOM tree to maintain styles and structure.

Parameters:
Name Type Attributes Description
node HTMLTableRowElement

The table row element to rebuild.

alreadyRendered Element

The root element containing the already rendered content for reference.

existingChildren number <optional>

Number of existing children in the container (optional).

Source:
Returns:

A new cloned and rebuilt table row element.

Type
HTMLTableRowElement

rebuildTree(node, fragmentopt, alreadyRenderedopt) → {DocumentFragment}

Rebuilds the ancestor tree for a given node, appending clones or existing elements to a document fragment.

Rebuilds the ancestor tree for a given node, appending clones or existing elements to a document fragment. Handles table rows, siblings duplication, and other special cases.

Parameters:
Name Type Attributes Description
node Node

The starting node for rebuilding.

fragment DocumentFragment <optional>

Optional document fragment to append rebuilt nodes to. Created if omitted.

alreadyRendered Element <optional>

Root element with already rendered DOM for reference and style copying.

Source:
Returns:

The fragment containing the rebuilt ancestor tree.

Type
DocumentFragment

registerHandlers(…handlers)

Adds new handler classes to the list of registered handlers.

Adds new handler classes to the list of registered handlers.

Parameters:
Name Type Attributes Description
handlers function <repeatable>

One or more handler classes to register.

Source:

replaceOrAppendElement(parentNode, child)

Replaces a child element in the parent node if a child with the same data-ref exists, otherwise appends the child.

Replaces a child element in the parent node if a child with the same data-ref exists, otherwise appends the child.

Parameters:
Name Type Description
parentNode HTMLElement

The parent element.

child Node

The child element to replace or append.

Source:

setSplit(orig, clone)

Sets split attributes between original and clone elements for table splitting.

Sets split attributes between original and clone elements for table splitting.

Parameters:
Name Type Description
orig HTMLElement

The original element to be split.

clone HTMLElement

The cloned element that receives attributes.

Source:

stackChildren(currentNode, stackedopt) → {Array.<Element>}

Recursively builds a stack (array) of a node and all its descendant elements, in depth-first order, starting with the current node at the front.

Recursively builds a stack (array) of a node and all its descendant elements, in depth-first order, starting with the current node at the front.

Parameters:
Name Type Attributes Description
currentNode Element

The current node to add and process.

stacked Array.<Element> <optional>

The accumulator array to hold stacked nodes.

Source:
Returns:

An array with the current node and all descendants stacked.

Type
Array.<Element>

validNode(node) → {boolean}

Validates if a node is either a text node or an element with a data-ref attribute.

Validates if a node is either a text node or an element with a data-ref attribute.

Parameters:
Name Type Description
node Node

The node to validate.

Source:
Returns:

True if valid, false otherwise.

Type
boolean

walk(start, limiteropt) → {Node}

Generator function that walks the DOM tree starting from the given node, traversing depth-first and yielding nodes until the limiter node is reached (if provided).

Generator function that walks the DOM tree starting from the given node, traversing depth-first and yielding nodes until the limiter node is reached (if provided).

Parameters:
Name Type Attributes Description
start Node

The starting node for traversal.

limiter Node <optional>

Optional node at which traversal stops.

Source:
Yields:
Nodes in the DOM tree in depth-first order.
Type
Node

words(node) → {Range}

Generator function to yield word ranges from a text node.

Generator function to yield word ranges from a text node.

Parameters:
Name Type Description
node Text

The text node to extract words from.

Source:
Yields:
A Range object for each word found.
Type
Range

Type Definitions

PagedConfig

Configuration object for controlling the preview behavior.

Configuration object for controlling the preview behavior. Can be set via the global window.PagedConfig or defaults are used.

Type:
  • Object
Properties:
Name Type Attributes Default Description
auto boolean <optional>
true

Whether to automatically render on load.

before function <optional>

Function to run before rendering.

after function <optional>

Function to run after rendering, receives result.

content string | HTMLElement <optional>

Selector or element to render.

stylesheets Array.<string> <optional>

Array of stylesheet URLs or paths.

renderTo HTMLElement | string <optional>

Where to render the output.

settings Object <optional>

Additional settings passed to the Previewer.

Source: