Class: Counters

Counters(chunker, polisher, caller)

new Counters(chunker, polisher, caller)

Handles CSS counter properties for paged media.

Handles CSS counter properties for paged media.

Parameters:
Name Type Description
chunker Object

The chunker instance managing pagination.

polisher Object

The polisher instance managing CSS and styles.

caller Object

The caller instance (optional, context info).

Source:

Members

counters :Object.<string, {name:string, increments:Object.<string, Object>, resets:Object.<string, Object>}>

Stores counters keyed by counter name.

Stores counters keyed by counter name. Each counter has increments and resets keyed by selector.

Type:
  • Object.<string, {name:string, increments:Object.<string, Object>, resets:Object.<string, Object>}>
Source:

resetCountersMap :Map.<string, string>

Map tracking counters that have been reset by element reference.

Map tracking counters that have been reset by element reference.

Type:
  • Map.<string, string>
Source:

styleSheet :CSSStyleSheet

Type:
  • CSSStyleSheet
Source:

Methods

addCounter(name) → {Object}

Adds a new counter to the counters map or returns existing one.

Adds a new counter to the counters map or returns existing one.

Parameters:
Name Type Description
name string

The name of the counter.

Source:
Returns:

The counter object.

Type
Object

addCounterValues(parsed, counter)

Calculates and adds counter values on elements.

Calculates and adds counter values on elements.

Parameters:
Name Type Description
parsed DocumentFragment

The parsed DOM fragment.

counter Object

The counter object.

Source:

addFootnoteMarkerCounter(list)

Ensures the footnote marker counter is included in the counter list.

Ensures the footnote marker counter is included in the counter list. If "footnote-maker" is already present, it does nothing.

Parameters:
Name Type Description
list Object

The CSS AST list node to modify.

Source:

afterPageLayout(pageElement, page)

Called after page layout to apply counter-reset and counter-increment CSS rules based on page and footnote resets.

Called after page layout to apply counter-reset and counter-increment CSS rules based on page and footnote resets.

Parameters:
Name Type Description
pageElement HTMLElement

The page element after layout.

page Object

The page metadata (not used directly here).

Source:

afterParsed(parsed)

Called after the parsed document fragment is ready.

Called after the parsed document fragment is ready. Processes counters and scopes them appropriately.

Parameters:
Name Type Description
parsed DocumentFragment

The parsed DOM fragment.

Source:

handleIncrement(declaration, rule) → {Array.<Object>}

Parses and handles counter-increment declarations.

Parses and handles counter-increment declarations. Updates counters with increment info.

Parameters:
Name Type Description
declaration Object

The CSS declaration node.

rule Object

The CSS rule node.

Source:
Returns:

List of increments parsed.

Type
Array.<Object>

handleReset(declaration, rule)

Parses and handles counter-reset declarations.

Parses and handles counter-reset declarations. Updates counters with reset info.

Parameters:
Name Type Description
declaration Object

The CSS declaration node.

rule Object

The CSS rule node.

Source:

hasNonWhitespaceChildren(children) → {boolean}

Helper to check if node children contain non-whitespace tokens.

Helper to check if node children contain non-whitespace tokens.

Parameters:
Name Type Description
children Object

The children node list.

Source:
Returns:

True if any non-whitespace tokens found.

Type
boolean

incrementCounterForElement(element, incrementArray)

Increment the CSS counters for a specific element, merging with existing increments.

Increment the CSS counters for a specific element, merging with existing increments.

Parameters:
Name Type Description
element HTMLElement

The element to update.

incrementArray Array.<string>

Array of counter-increment strings, e.g. ['c1 1', 'c2 -3'].

Source:

insertRule(rule)

Inserts a CSS rule into the stylesheet.

Inserts a CSS rule into the stylesheet.

Parameters:
Name Type Description
rule string

The CSS rule string.

Source:

mergeIncrements(incrementArray, operator) → {string}

Merge multiple values of a counter-increment CSS rule, using the specified operator.

Merge multiple values of a counter-increment CSS rule, using the specified operator.

Parameters:
Name Type Description
incrementArray Array

the values to merge, e.g. ['c1 1', 'c1 -7 c2 1']

operator function

the function used to merge counter values (e.g. keep the last value of a counter or sum the counter values)

Source:
Returns:

the merged value of the counter-increment CSS rule

Type
string

onDeclaration(declaration, dItem, dList, rule)

Handles a CSS declaration related to counters.

Handles a CSS declaration related to counters. Cleans up declarations once processed.

Parameters:
Name Type Description
declaration Object

The CSS declaration node.

dItem Object

The item in the declaration list.

dList Object

The list of declarations.

rule Object

The CSS rule node containing the declaration.

Source:

processCounterIncrements(parsed, counter)

Adds data attributes for counter increments to matching elements.

Adds data attributes for counter increments to matching elements.

Parameters:
Name Type Description
parsed DocumentFragment

The parsed DOM fragment.

counter Object

The counter object.

Source:

processCounterResets(parsed, counter)

Adds data attributes for counter resets to matching elements.

Adds data attributes for counter resets to matching elements. Resolves CSS variables when possible.

Parameters:
Name Type Description
parsed DocumentFragment

The parsed DOM fragment.

counter Object

The counter object.

Source:

processCounters(parsed, counters)

Processes all counters on the parsed fragment.

Processes all counters on the parsed fragment. Calls handlers for increments, resets, and value assignment.

Parameters:
Name Type Description
parsed DocumentFragment

The parsed DOM fragment.

counters Object

The counters map.

Source:

scopeCounters(counters)

Adds counter-reset CSS rules scoped on pages to allow cross page scope.

Adds counter-reset CSS rules scoped on pages to allow cross page scope.

Parameters:
Name Type Description
counters Object

The counters map.

Source: