Class StyleSheetResolve
Implements
- Iterable<[string, { [key: string]: string }]>
Constructors
constructor
Instantiate an empty
StyleSheetResolveinstance.Returns StyleSheetResolve
Accessors
frozen
- get frozen(): boolean
Returns boolean
Current frozen state; when true no more modifications are possible.
size
- get size(): number
Returns number
Returns the size / count of selector properties tracked.
Methods
[iterator]
Allows usage in
for ofloops directly.Returns MapIterator<[string, { [key: string]: string }]>
Entries Map iterator.
clear
Clears any existing parsed styles.
Returns void
clone
Clones this instance returning a new
StyleSheetResolveinstance with a copy of the data.Returns StyleSheetResolve
Cloned instance.
delete
Deletes an entry in the parsed stylesheet Map.
Parameters
- selector: string
Selector key to delete.
Returns boolean
Success state.
- selector: string
entries
Entries iterator of selector / style properties objects.
Returns MapIterator<[string, { [key: string]: string }]>
Tracked CSS selector key / value iterator.
freeze
Freezes this instance disallowing further modifications to the stylesheet data.
Returns this
This instance.
get
- get(
selector: string | Iterable<string, any, any>,
options?: StyleSheetResolve.Options.Get,
): { [key: string]: string }Gets all properties associated with the given selector(s). You may combine multiple selectors for a combined result. You may also provide additional selectors as the
resolveoption to substitute any CSS variables in the target selector(s).Parameters
- selector: string | Iterable<string, any, any>
A selector or list of selectors to retrieve.
Optionaloptions: StyleSheetResolve.Options.GetOptions.
Returns { [key: string]: string }
Style properties object or undefined.
- selector: string | Iterable<string, any, any>
getProperty
- getProperty(
selector: string | Iterable<string, any, any>,
property: string,
options?: StyleSheetResolve.Options.Get,
): stringGets a specific property value from the given
selectorandpropertykey.Parameters
- selector: string | Iterable<string, any, any>
A selector or list of selectors to retrieve.
- property: string
Specific property to locate.
Optionaloptions: StyleSheetResolve.Options.GetOptions.
Returns string
Style property value.
- selector: string | Iterable<string, any, any>
has
Test if
StyleSheetResolvetracks the given selector.Parameters
- selector: string
CSS selector to check.
Returns boolean
StyleSheetResolve tracks the given selector.
- selector: string
keys
Returns MapIterator<string>
Tracked CSS selector keys iterator.
merge
Merges selectors and style properties from another StyleSheetResolve instance into this one. By default, the source of the merge overrides existing properties. You may choose to preserve existing values along with specifying exact selector matches.
Parameters
- source: StyleSheetResolve
Another instance to merge from.
Optionaloptions: MergeOptions.
Returns this
This instance.
- source: StyleSheetResolve
parse
- parse(
styleSheetOrMap: CSSStyleSheet | Map<string, { [key: string]: string }>,
options?: Parse,
): thisClears existing stylesheet mapping and parses the given stylesheet or Map.
Parameters
- styleSheetOrMap: CSSStyleSheet | Map<string, { [key: string]: string }>
The stylesheet element to parse or an existing parsed stylesheet Map.
Optionaloptions: ParseOptions for parsing stylesheet.
Returns this
This instance.
- styleSheetOrMap: CSSStyleSheet | Map<string, { [key: string]: string }>
set
Directly sets a selector key with the given style properties object.
Parameters
- selector: string
A single selector key to set.
- styleObj: { [key: string]: string }
Style data object of property / value pairs.
Returns void
- selector: string
Staticparse
- parse(
styleSheetOrMap: CSSStyleSheet | Map<string, { [key: string]: string }>,
options?: Parse,
): StyleSheetResolveParse a CSSStyleSheet instance with the given options or accept a pre-filled Map generating a new
StyleSheetResolveinstance.Parameters
- styleSheetOrMap: CSSStyleSheet | Map<string, { [key: string]: string }>
The stylesheet instance to parse or an existing parsed stylesheet Map.
Optionaloptions: ParseOptions for parsing stylesheet.
Returns StyleSheetResolve
New instance with the given parsed data.
- styleSheetOrMap: CSSStyleSheet | Map<string, { [key: string]: string }>
Dynamically parses and indexes a
CSSStyleSheetat runtime, exposing a selector-to-style mapping by individual selector parts. CSS variable resolution is also possible which enables the ability to flatten and resolve complex nestedvar(--...)chains defined across multiple selectors and layers.When retrieving specific selector styles via StyleSheetResolve.get and StyleSheetResolve.getProperty it is possible to provide additional parent selectors that may define scoped CSS variables. These parent variable definitions will be substituted in the target selector data allowing specific element scoping of CSS variables to be flattened.
Current fallback support includes recursive var(--a, var(--b, ...)) chains with graceful partial substitution if some variables are undefined. This maintains correctness without introducing ambiguity or needing a complete AST based parser.
By default, when parsing CSSStyleSheet instances relative URL rewriting occurs converting
url(...)references to absolute paths based on theCSSStyleSheet.hrefor thebaseHrefparse option for inline / synthetic CSSStyleSheets. You may turn off relative URL rewriting via setting theurlRewriteparse option tofalse.By default, simple media queries /
@mediarules are parsed when all conditions areprefers-*features and the media query matches at runtime viawindow.matchMedia(...). Mixed conditions (IE with screen, width, etc.) are ignored by design. Only direct style rules under a media query are parsed. You may turn off media query parsing via setting themediaQueryparse option to false.The goal of this implementation is to realize a regex-based parser with small code size, minimal memory footprint, speed, and reasonable accuracy.
Core features:
@layerblocks..get()and.getProperty().url(...)references to absolute paths.Parse Options:
hreffor inline / synthetic CSSStyleSheets being processed viabaseHrefoption.excludeSelectorPartsoption.includeCSSLayersoption.includeSelectorPartSetoption.urlRewriteoption tofalse.Access Options:
camelCaseoption.depthoption.resolveoption.warnCyclesoption.warnResolveoption.Example