Class: StyleProcessor

StyleProcessor(optionsopt, configopt)

StyleProcessor is responsible for handling all CSS-related logic during the build process. This includes managing global CSS variables, scoping component-specific styles using hashes, and extracting CSS rules into a global stylesheet.

Constructor

new StyleProcessor(optionsopt, configopt)

Creates an instance of StyleProcessor.

Parameters:
Name Type Attributes Default Description
options object <optional>

Configuration options.

config object <optional>
null

Project configuration object.

Source:

Members

cssVariables :Object:.<string:, string:>

A map of CSS variable names to their values.

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

generatedLines :Array:.<object:>

Accumulated list of all generated CSS lines with their mapping metadata.

Type:
  • Array:.<object:>
Source:

globalStyles :string

The accumulated global stylesheet content.

Type:
  • string
Source:

rawGlobalCSS :Set:.<string:>

Raw global CSS rules added via addGlobalCSS.

Type:
  • Set:.<string:>
Source:

rawGlobalCSSSourceInfo :Array:.<object:>

Raw global CSS rules metadata mapping.

Type:
  • Array:.<object:>
Source:

scopedRules :Array:.<object:>

List of scoped CSS rules to build the source map lines.

Type:
  • Array:.<object:>
Source:

scopedStyles :string

Scoped CSS rules.

Type:
  • string
Source:

sourcesCache :Map:.<string:, string:>

Cache mapping original CSS file path to its content string.

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

Methods

addGlobalCSS(css, sourceFileopt, startLineopt)

Adds raw global CSS rules to the stylesheet.

Parameters:
Name Type Attributes Default Description
css string

The raw CSS string.

sourceFile string <optional>

Source file path.

startLine number <optional>
1

Start line number in the source file.

Source:

addVariable(name, value)

Adds a global CSS variable to the processor.

Parameters:
Name Type Description
name string

The name of the variable (without the @ prefix).

value string

The value of the variable.

Source:

appendGeneratedLine(text, sourceFileopt, sourceLineopt)

Helper to append a generated CSS line.

Parameters:
Name Type Attributes Default Description
text string

Line contents.

sourceFile string | null <optional>
null

Original stylesheet file path.

sourceLine number | null <optional>
null

Original line number (1-based).

Source:

applyVariables(cssContent) → {string}

Replaces CSS variables (e.g., @primary) with their values.

Parameters:
Name Type Description
cssContent string

The CSS content to process.

Source:
Returns:

The CSS content with variables replaced.

Type
string

filterScopedRules(compiledCss, placeholder) → {string}

Filters compiled CSS rules to keep only those targeting the placeholder class.

Parameters:
Name Type Description
compiledCss string

The compiled CSS.

placeholder string

The placeholder class name.

Source:
Returns:

The filtered rules with placeholder replaced by parent selector &.

Type
string

getGlobalStyles(optionsopt) → {string}

Retrieves the accumulated global styles.

Parameters:
Name Type Attributes Description
options object | boolean <optional>

Options or boolean indicating if dev inline source maps should be included.

Properties
Name Type Attributes Description
includeSources Set:.<string:> <optional>

Stylesheet paths that reached the bundle. When given, styles from any other source file are left out.

Source:
Returns:

The complete CSS string for the application.

Type
string

getHash(cssContent, componentName) → {string}

Generates a unique hash for a CSS block.

Parameters:
Name Type Description
cssContent string

The CSS content.

componentName string

The name of the component.

Source:
Returns:

The generated hash.

Type
string

getInlineSourceMapComment(distDiropt, cssFileNameopt) → {string}

Generates a base64 inline source map comment.

Parameters:
Name Type Attributes Default Description
distDir string <optional>

Output directory.

cssFileName string <optional>
bundle.css

Output CSS filename.

Source:
Returns:

The base64 inline source map comment string.

Type
string

getSourceMap(distDir, cssFileName) → {object}

Generates the Source Map v3 JSON object.

Parameters:
Name Type Default Description
distDir string

The absolute directory path of the output bundle.

cssFileName string bundle.css

The name of the CSS bundle file (e.g., 'bundle.css').

Source:
Returns:

The source map object.

Type
object

preprocessBlock(rawGlobalCss, blockBody, preprocessor) → {string}

Preprocesses an individual CSS block by wrapping it and compiling.

Parameters:
Name Type Description
rawGlobalCss string

The raw global CSS content.

blockBody string

The raw CSS block body.

preprocessor string

The preprocessor type.

Source:
Returns:

The preprocessed and filtered CSS block body.

Type
string

preprocessCss(cssContent, type) → {string}

Preprocesses CSS content using the configured preprocessor.

Parameters:
Name Type Description
cssContent string

The raw CSS/SCSS content.

type string

The preprocessor type.

Source:
Returns:

The compiled CSS.

Type
string

process(html, desBlocksopt, componentNameopt, desPathopt) → {string}

Processes the CSS within an HTML template. It identifies @css attributes, scopes the rules with a unique hash, replaces variables, and updates the HTML.

Parameters:
Name Type Attributes Description
html string

The HTML template.

desBlocks object <optional>

Pre-defined style blocks from a .component.css file.

componentName string <optional>

The name of the component for hash generation.

desPath string <optional>

The original CSS file path.

Source:
Returns:

The modified HTML.

Type
string

registerSourceFile(filePath, content)

Registers a source stylesheet content for source map generation.

Parameters:
Name Type Description
filePath string

Absolute file path of the style source.

content string

CSS content of the source.

Source:

reset()

Resets the processor state, clearing all accumulated styles and variables.

Source: