css_variable_utils.ts

CSS variable extraction utilities.

Provides shared helper functions for extracting CSS custom property references from CSS strings. Used by style_rule_parser, variable_graph, class_variable_index, and css_class_generation.

Declarations
#

2 declarations

view source

extract_css_variables
#

css_variable_utils.ts view source

(css: string): Set<string>

Extracts CSS variable names from a CSS string.

Parses var(--name) patterns and returns the variable names without the -- prefix. Handles fallback values by extracting only the primary variable reference.

css

CSS string potentially containing var(--*) references

type string

returns

Set<string>

set of variable names (without -- prefix)

examples

extract_css_variables('color: var(--text_color);') // → Set { 'text_color' } extract_css_variables('background: var(--bg_1, var(--bg_2));') // → Set { 'bg_1', 'bg_2' } extract_css_variables('padding: 1rem;') // → Set {}

has_css_variables
#

css_variable_utils.ts view source

(css: string): boolean

Checks if a CSS string contains any CSS variable references.

More efficient than extract_css_variables when you only need to know if variables exist, not what they are.

css

CSS string to check

type string

returns

boolean

true if the string contains var(--*) patterns

Imported by
#