Class: NthOfType

NthOfType(chunker, polisher, caller)

Handler for emulating pseudo-selectors like :first-of-type, :last-of-type, and :nth-of-type by converting them into attribute-based selectors that can be used for styling after layout.

Constructor

new NthOfType(chunker, polisher, caller)

Constructs the NthOfType handler.

Constructs the NthOfType handler.

Parameters:
Name Type Description
chunker Object

The chunker instance used to split content into pages.

polisher Object

The polisher instance for handling styles.

caller Object

The caller instance managing lifecycle hooks.

Source:

Members

selectors :Object

Map of selectors and their associated UUID and declarations.

Map of selectors and their associated UUID and declarations.

Type:
  • Object
Source:

styleSheet :CSSStyleSheet

Type:
  • CSSStyleSheet
Source:

Methods

afterParsed(parsed)

Hook called after the entire content is parsed but before layout.

Hook called after the entire content is parsed but before layout. Applies the transformed attribute-based selectors to relevant elements.

Parameters:
Name Type Description
parsed Document | HTMLElement

The parsed document or content element.

Source:

onRule(ruleNode, ruleItem, rulelist)

Hook called during CSS rule parsing.

Hook called during CSS rule parsing. Intercepts :first-of-type, :last-of-type, and :nth-of-type selectors, removes the rule, and stores the relevant declarations and a UUID for later use.

Parameters:
Name Type Description
ruleNode Object

The AST node representing the CSS rule.

ruleItem Object

The rule item in the CSS rule list.

rulelist Object

The list of all CSS rules.

Source:

processSelectors(parsed, selectors)

Applies unique data-nth-of-type attributes to elements matching selectors, and dynamically inserts the converted rules into the stylesheet.

Applies unique data-nth-of-type attributes to elements matching selectors, and dynamically inserts the converted rules into the stylesheet.

Parameters:
Name Type Description
parsed Document | HTMLElement

The parsed content.

selectors Object

Map of selectors and their UUID + declarations.

Source: