pub struct CssParser { /* private fields */ }Expand description
Parser for CSS files.
Implementations§
Source§impl CssParser
impl CssParser
Sourcepub fn parse(&mut self, css_content: &str) -> Result<WebUIFragmentRecords>
pub fn parse(&mut self, css_content: &str) -> Result<WebUIFragmentRecords>
Parse CSS content and return fragments.
Sourcepub fn process_css(
&mut self,
css_content: &str,
fragments: &mut WebUIFragmentRecords,
) -> Result<()>
pub fn process_css( &mut self, css_content: &str, fragments: &mut WebUIFragmentRecords, ) -> Result<()>
Process CSS content and merge it into fragments.
Sourcepub fn parse_inline_css(&mut self, style_content: &str) -> Result<String>
pub fn parse_inline_css(&mut self, style_content: &str) -> Result<String>
Parse inline CSS from style tags in HTML.
Sourcepub fn extract_tokens(&mut self, css_content: &str) -> Result<HashSet<String>>
pub fn extract_tokens(&mut self, css_content: &str) -> Result<HashSet<String>>
Extract CSS custom property token names used via var() in the given CSS.
Returns a set of variable names (without the -- prefix) that are
referenced through var(--name) calls. Variables that are only
defined (e.g., --bar: 12px) in the same CSS are excluded.
Handles nested fallbacks: var(--a, var(--b, var(--c))) yields
{"a", "b", "c"} because each nested var() is a separate
call_expression in the tree-sitter CSS AST.
Sourcepub fn extract_definitions(
&mut self,
css_content: &str,
) -> Result<HashSet<String>>
pub fn extract_definitions( &mut self, css_content: &str, ) -> Result<HashSet<String>>
Extract CSS custom property definitions from the given CSS.
Returns a set of variable names (without -- prefix) that are
defined via --name: value declarations. This is used to
exclude application-level token definitions (e.g., from <style>
in the entry HTML) from the hoisted token set.
Sourcepub fn extract_tokens_and_definitions(
&mut self,
css_content: &str,
) -> Result<(HashSet<String>, HashSet<String>)>
pub fn extract_tokens_and_definitions( &mut self, css_content: &str, ) -> Result<(HashSet<String>, HashSet<String>)>
Extract both token usages and definitions in a single parse.
Returns (tokens, definitions) where:
tokens: var() usages with locally-defined properties already excludeddefinitions: all custom property definitions (for global filtering)
Prefer this over calling extract_tokens + extract_definitions
separately on the same CSS content to avoid redundant tree-sitter parses.