Functions
transform_css_nesting
Transform CSS nesting syntax (&:hover, &.class, etc.) to traditional selectors.
Transforms pattern…
transform_css_nesting
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
Transformed CSS with nesting syntax expandedstr
—
remove_duplicate_bare_h1_rules
Remove duplicate bare h1 rules that appear right after scoped h1 rules.
CSS processing sometimes c…
remove_duplicate_bare_h1_rules
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
CSS with duplicate bare h1 rules removedstr
—
lossless_minify_css
Remove comments and redundant whitespace without touching selectors/properties.
This intentionally…
lossless_minify_css
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
Minified CSS with comments and extra whitespace removedstr
—