Class StyleParse
Index
Methods
Methods
Static
cssText
- cssText(
cssText: string,
options?: { camelCase?: boolean },
): { [key: string]: string } Parse a CSS declaration block / CSSDeclarationBlock (IE
color: red; font-size: 14px;
) into an object of property / value pairs.This implementation is optimized for parsing the output of
CSSStyleRule.style.cssText
, which is always well-formed according to the CSSOM spec. It is designed to be:- **Fast**: minimal allocations, no regex in the hot loop.
- **Accurate**: ignores `;` inside quotes or parentheses.
- **Flexible**: supports optional camel case conversion.
- **CSS variable safe**: leaves `--*` properties untouched.Parameters
- cssText: string
A valid CSS declaration block (no selectors).
Optional
options: { camelCase?: boolean }Optional parser settings.
Optional
camelCase?: booleanConvert hyphen-case property names to camel case.
Returns { [key: string]: string }
An object mapping property names to their CSS values.
- cssText: string
Static
pixels
Static
remPixels
- remPixels(multiplier?: number, options?: { targetDocument?: Document }): number
Returns the pixel value for
1rem
based on the root document element. You may apply an optional multiplier.Parameters
Returns number
The pixel value for
1rem
with or without a multiplier based on the root document element.
Static
selectorText
- selectorText(
selectorText: string,
options?: {
excludeSelectorParts?: RegExp[];
includeSelectorPartSet?: Set<string>;
},
): string[] Split a CSS selector list into individual selectors, honoring commas that appear only at the top level (IE not inside (), [], or quotes). Additional options provide inclusion / exclusion filtering of selector parts.
Examples: '.a, .b' → ['.a', '.b'] ':is(.a, .b):not([data-x=","]) .c, .d' → [':is(.a, .b):not([data-x=","]) .c', '.d']
Parameters
Returns string[]
Array of trimmed selector strings w/ optional filtering of parts.
Provides resources for parsing style strings.