css_variable_utils.ts

CSS variable extraction utilities.

Provides shared helper functions for extracting CSS custom property references from CSS strings, for the base-style index, the variable graph, generated classes, and the generators' source scans.

view source

Declarations
#

4 declarations

extract_css_variables
#

css_variable_utils.ts view source

(css: string): Set<string> import {extract_css_variables} from '@fuzdev/fuz_css/css_variable_utils.js';

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 {}

extract_declared_css_variables
#

css_variable_utils.ts view source

(css: string): Set<string> import {extract_declared_css_variables} from '@fuzdev/fuz_css/css_variable_utils.js';

Extracts the custom properties a CSS string declares.

css

CSS string potentially containing --name: value declarations

type string

returns

Set<string>

set of variable names (without -- prefix)

extract_required_css_variables
#

css_variable_utils.ts view source

(css: string): Set<string> import {extract_required_css_variables} from '@fuzdev/fuz_css/css_variable_utils.js';

Extracts the CSS variables a string references with no fallback - the ones that must be defined for the value to resolve. var(--a, 1px) can't resolve to nothing, so a is left out, while the b in var(--a, var(--b)) is required.

css

CSS string potentially containing var(--*) references

type string

returns

Set<string>

set of variable names (without -- prefix)

strip_css_comments
#

css_variable_utils.ts view source

(css: string): string import {strip_css_comments} from '@fuzdev/fuz_css/css_variable_utils.js';

Removes the comments from a CSS string, so text inside one isn't read as CSS. Quoted strings and unquoted url() values are left intact - a /* inside either is not a comment - and each comment becomes a space because a comment separates tokens. For analysis, not for output.

css

CSS string potentially containing comments

type string

returns

string

the string without its comments, or css itself when it has none

Imported by
#