Class StyleParse
Index
Methods
Methods
StaticcssText
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).
Optionaloptions: { camelCase?: boolean }Optional parser settings.
OptionalcamelCase?: booleanConvert hyphen-case property names to camel case.
Returns { [key: string]: string }
An object mapping property names to their CSS values.
- cssText: string
Staticpixels
Parses a pixel string / computed styles. Ex.
100pxreturns100.Parameters
- value: string
Value to parse.
Returns number
The integer component of a pixel string.
- value: string
StaticremPixels
Returns the pixel value for
1rembased on the root document element. You may apply an optional multiplier.Parameters
Returns number
The pixel value for
1remwith or without a multiplier based on the root document element.
StaticselectorText
- 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.