Module

core.asset.css_transforms

CSS transformation utilities for asset processing.

Provides functions for transforming CSS syntax for browser compatibility:

  • Nesting syntax transformation (&:hover, &.class → .parent:hover, .parent.class)
  • Duplicate rule removal
  • Lossless minification (whitespace/comment removal only)

These are internal utilities used by the Asset class during CSS processing.

Functions

transform_css_nesting
Transform CSS nesting syntax (&:hover, &.class, etc.) to traditional selectors. Transforms pattern…
1 str
def transform_css_nesting(css: str) -> str

Transform CSS nesting syntax (&:hover, &.class, etc.) to traditional selectors.

Transforms patterns like:

.parent {
  color: red;
  &:hover { color: blue; }
}

Into:

.parent { color: red; }
.parent:hover { color: blue; }

This ensures browser compatibility for CSS nesting syntax.

NOTE: We should NOT write nested CSS in source files. Use traditional selectors instead. This is a safety net for any nested CSS that slips through.

Parameters 1

Name Type Default Description
css str

CSS content string

Returns

str

Transformed CSS with nesting syntax expanded

remove_duplicate_bare_h1_rules
Remove duplicate bare h1 rules that appear right after scoped h1 rules. CSS processing sometimes c…
1 str
def remove_duplicate_bare_h1_rules(css: str) -> str

Remove duplicate bare h1 rules that appear right after scoped h1 rules.

CSS processing sometimes creates duplicate rules like:

.browser-header h1 { font-size: var(--text-5xl); }
h1 { font-size: var(--text-5xl); }  # Duplicate!

The bare h1 rule overrides the base typography rule, breaking text sizing. This function removes the duplicate bare h1 rules.

Parameters 1

Name Type Default Description
css str

CSS content string

Returns

str

CSS with duplicate bare h1 rules removed

lossless_minify_css
Remove comments and redundant whitespace without touching selectors/properties. This intentionally…
1 str
def lossless_minify_css(css: str) -> str

Remove comments and redundant whitespace without touching selectors/properties.

This intentionally avoids aggressive rewrites so modern CSS (nesting, @layer, etc.) remains intact.

Parameters 1

Name Type Default Description
css str

CSS content string

Returns

str

Minified CSS with comments and extra whitespace removed