Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(cssom): use native Stylo content alternative counters
ldm0c560d8fcfb66
diff --git a/Cargo.lock b/Cargo.lockindex 752f43df3..cdd63494c 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4607,7 +4607,7 @@ dependencies = [[[package]]name = "selectors"version = "0.40.0"-source = "git+https://github.com/ldm0/stylo?rev=671d13d31b3b00e7b1e0088ba2b36a4e35c0858c#671d13d31b3b00e7b1e0088ba2b36a4e35c0858c"+source = "git+https://github.com/lexmount/stylo?branch=moli#e741cb3095b4657834ec7ba3d559e03e19350c49"dependencies = ["bitflags","cssparser",@@ -4739,7 +4739,7 @@ dependencies = [[[package]]name = "servo_arc"version = "0.4.3"-source = "git+https://github.com/ldm0/stylo?rev=671d13d31b3b00e7b1e0088ba2b36a4e35c0858c#671d13d31b3b00e7b1e0088ba2b36a4e35c0858c"+source = "git+https://github.com/lexmount/stylo?branch=moli#e741cb3095b4657834ec7ba3d559e03e19350c49"dependencies = ["serde","stable_deref_trait",@@ -4992,7 +4992,7 @@ dependencies = [[[package]]name = "stylo"version = "0.20.0"-source = "git+https://github.com/ldm0/stylo?rev=671d13d31b3b00e7b1e0088ba2b36a4e35c0858c#671d13d31b3b00e7b1e0088ba2b36a4e35c0858c"+source = "git+https://github.com/lexmount/stylo?branch=moli#e741cb3095b4657834ec7ba3d559e03e19350c49"dependencies = ["app_units","arrayvec",@@ -5048,7 +5048,7 @@ dependencies = [[[package]]name = "stylo_atoms"version = "0.20.0"-source = "git+https://github.com/ldm0/stylo?rev=671d13d31b3b00e7b1e0088ba2b36a4e35c0858c#671d13d31b3b00e7b1e0088ba2b36a4e35c0858c"+source = "git+https://github.com/lexmount/stylo?branch=moli#e741cb3095b4657834ec7ba3d559e03e19350c49"dependencies = ["string_cache","string_cache_codegen",@@ -5057,7 +5057,7 @@ dependencies = [[[package]]name = "stylo_derive"version = "0.20.0"-source = "git+https://github.com/ldm0/stylo?rev=671d13d31b3b00e7b1e0088ba2b36a4e35c0858c#671d13d31b3b00e7b1e0088ba2b36a4e35c0858c"+source = "git+https://github.com/lexmount/stylo?branch=moli#e741cb3095b4657834ec7ba3d559e03e19350c49"dependencies = ["darling","proc-macro2",@@ -5069,7 +5069,7 @@ dependencies = [[[package]]name = "stylo_dom"version = "0.20.0"-source = "git+https://github.com/ldm0/stylo?rev=671d13d31b3b00e7b1e0088ba2b36a4e35c0858c#671d13d31b3b00e7b1e0088ba2b36a4e35c0858c"+source = "git+https://github.com/lexmount/stylo?branch=moli#e741cb3095b4657834ec7ba3d559e03e19350c49"dependencies = ["bitflags","stylo_malloc_size_of",@@ -5078,7 +5078,7 @@ dependencies = [[[package]]name = "stylo_malloc_size_of"version = "0.20.0"-source = "git+https://github.com/ldm0/stylo?rev=671d13d31b3b00e7b1e0088ba2b36a4e35c0858c#671d13d31b3b00e7b1e0088ba2b36a4e35c0858c"+source = "git+https://github.com/lexmount/stylo?branch=moli#e741cb3095b4657834ec7ba3d559e03e19350c49"dependencies = ["app_units","cssparser",@@ -5095,7 +5095,7 @@ dependencies = [[[package]]name = "stylo_static_prefs"version = "0.20.0"-source = "git+https://github.com/ldm0/stylo?rev=671d13d31b3b00e7b1e0088ba2b36a4e35c0858c#671d13d31b3b00e7b1e0088ba2b36a4e35c0858c"+source = "git+https://github.com/lexmount/stylo?branch=moli#e741cb3095b4657834ec7ba3d559e03e19350c49"dependencies = ["toml",]@@ -5113,7 +5113,7 @@ dependencies = [[[package]]name = "stylo_traits"version = "0.20.0"-source = "git+https://github.com/ldm0/stylo?rev=671d13d31b3b00e7b1e0088ba2b36a4e35c0858c#671d13d31b3b00e7b1e0088ba2b36a4e35c0858c"+source = "git+https://github.com/lexmount/stylo?branch=moli#e741cb3095b4657834ec7ba3d559e03e19350c49"dependencies = ["app_units","bitflags",@@ -5413,7 +5413,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"[[package]]name = "to_shmem"version = "0.5.0"-source = "git+https://github.com/ldm0/stylo?rev=671d13d31b3b00e7b1e0088ba2b36a4e35c0858c#671d13d31b3b00e7b1e0088ba2b36a4e35c0858c"+source = "git+https://github.com/lexmount/stylo?branch=moli#e741cb3095b4657834ec7ba3d559e03e19350c49"dependencies = ["cssparser","servo_arc",@@ -5426,7 +5426,7 @@ dependencies = [[[package]]name = "to_shmem_derive"version = "0.1.0"-source = "git+https://github.com/ldm0/stylo?rev=671d13d31b3b00e7b1e0088ba2b36a4e35c0858c#671d13d31b3b00e7b1e0088ba2b36a4e35c0858c"+source = "git+https://github.com/lexmount/stylo?branch=moli#e741cb3095b4657834ec7ba3d559e03e19350c49"dependencies = ["darling","proc-macro2",diff --git a/Cargo.toml b/Cargo.tomlindex a6da1555a..b95609f73 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -101,13 +101,13 @@ curl-sys = { git = "https://github.com/lexmount/curl-rust", rev = "a0ea59f5ca1b1cookie = { git = "https://github.com/ldm0/cookie-rs", branch = "priority" }v8 = { path = "vendor/v8-152.2.0" }deno_v8 = { path = "vendor/deno_v8-0.3.0" }-selectors = { git = "https://github.com/ldm0/stylo", rev = "671d13d31b3b00e7b1e0088ba2b36a4e35c0858c" }-servo_arc = { git = "https://github.com/ldm0/stylo", rev = "671d13d31b3b00e7b1e0088ba2b36a4e35c0858c" }-stylo = { git = "https://github.com/ldm0/stylo", rev = "671d13d31b3b00e7b1e0088ba2b36a4e35c0858c" }-stylo_atoms = { git = "https://github.com/ldm0/stylo", rev = "671d13d31b3b00e7b1e0088ba2b36a4e35c0858c" }-stylo_dom = { git = "https://github.com/ldm0/stylo", rev = "671d13d31b3b00e7b1e0088ba2b36a4e35c0858c" }-stylo_static_prefs = { git = "https://github.com/ldm0/stylo", rev = "671d13d31b3b00e7b1e0088ba2b36a4e35c0858c" }-stylo_traits = { git = "https://github.com/ldm0/stylo", rev = "671d13d31b3b00e7b1e0088ba2b36a4e35c0858c" }+selectors = { git = "https://github.com/lexmount/stylo", branch = "moli" }+servo_arc = { git = "https://github.com/lexmount/stylo", branch = "moli" }+stylo = { git = "https://github.com/lexmount/stylo", branch = "moli" }+stylo_atoms = { git = "https://github.com/lexmount/stylo", branch = "moli" }+stylo_dom = { git = "https://github.com/lexmount/stylo", branch = "moli" }+stylo_static_prefs = { git = "https://github.com/lexmount/stylo", branch = "moli" }+stylo_traits = { git = "https://github.com/lexmount/stylo", branch = "moli" }taffy = { git = "https://github.com/ldm0/taffy", rev = "645bf5a49df607a8bff34ec90c5343901d04f10e" }[workspace.lints.clippy]diff --git a/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse.rs b/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse.rsindex 321151a38..b578acafb 100644--- a/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse.rs+++ b/moli-renderer-v8/src/native_bridge/element/styles/declaration/parse.rs@@ -2346,9 +2346,6 @@ fn parse_pdb_supplemental_entries(value: &str,priority: bool,) -> Option<ParsedStylePropertyEntries> {- if let Some(entries) = parse_content_alt_counter_supplemental_entries(name, value, priority) {- return Some(entries);- }if let Some(entries) = parse_preferred_pdb_supplemental_entries(name, value, priority) {return Some(entries);}@@ -2373,140 +2370,6 @@ fn parse_pdb_supplemental_entries(parse_transition_numeric_property_entries(name, value, priority)}-fn parse_content_alt_counter_supplemental_entries(- name: &str,- value: &str,- priority: bool,-) -> Option<ParsedStylePropertyEntries> {- if name != "content" {- return None;- }- let (content, alt) = split_content_alt_text(value)?;- if !content_alt_text_contains_only_strings_attrs_and_counters(alt)? {- return None;- }-- // Stylo already owns the grammar on both sides of the slash. Its current- // content parser only has one narrower restriction: counter() and- // counters() are rejected after the alt marker. Validate the main list- // with an ordinary string alt, then validate the alt list as an ordinary- // content list. This keeps images and quote keywords out of alt text while- // retaining Stylo's counter argument and counter-style validation.- stylo_pdb_single_property_value(name, &format!("{content} / \"\""), priority)?;- let content = stylo_pdb_single_property_value(name, content, priority)?;- let alt = stylo_pdb_single_property_value(name, alt, priority)?;- Some(ParsedStylePropertyEntries {- entries: vec![StyleEntry {- name: name.to_owned(),- value: format!("{content} / {alt}"),- priority,- }],- affected_names: vec![name.to_owned()],- })-}--fn stylo_pdb_single_property_value(name: &str, value: &str, priority: bool) -> Option<String> {- let parsed = stylo_pdb_entries_for_property(name, value, priority)?;- let [entry] = parsed.entries.as_slice() else {- return None;- };- (entry.name == name && entry.priority == priority).then(|| entry.value.clone())-}--fn split_content_alt_text(value: &str) -> Option<(&str, &str)> {- let mut parser_input = cssparser::ParserInput::new(value);- let mut input = cssparser::Parser::new(&mut parser_input);- let value_start = input.position();- let mut slash = None;-- loop {- let token_start = input.position();- let Ok(token) = input.next_including_whitespace_and_comments().cloned() else {- break;- };- let token_end = input.position();- match token {- cssparser::Token::Delim('/') => {- if slash.replace((token_start, token_end)).is_some() {- return None;- }- }- token if content_component_starts_nested_block(&token) => {- let nested: Result<(), cssparser::ParseError<'_, ()>> =- input.parse_nested_block(|input| {- consume_nested_content_components(input)- .ok_or_else(|| input.new_custom_error::<(), ()>(()))- });- nested.ok()?;- }- _ => {}- }- }- if !input.is_exhausted() {- return None;- }-- let value_end = input.position();- let (slash_start, slash_end) = slash?;- let content = input.slice(value_start..slash_start).trim();- let alt = input.slice(slash_end..value_end).trim();- (!content.is_empty() && !alt.is_empty()).then_some((content, alt))-}--fn content_alt_text_contains_only_strings_attrs_and_counters(value: &str) -> Option<bool> {- let mut parser_input = cssparser::ParserInput::new(value);- let mut input = cssparser::Parser::new(&mut parser_input);- let mut has_counter = false;-- while let Ok(token) = input.next_including_whitespace_and_comments().cloned() {- match token {- cssparser::Token::WhiteSpace(_)- | cssparser::Token::Comment(_)- | cssparser::Token::QuotedString(_) => {}- cssparser::Token::Function(name)- if name.eq_ignore_ascii_case("attr")- || name.eq_ignore_ascii_case("counter")- || name.eq_ignore_ascii_case("counters") =>- {- has_counter |=- name.eq_ignore_ascii_case("counter") || name.eq_ignore_ascii_case("counters");- let nested: Result<(), cssparser::ParseError<'_, ()>> =- input.parse_nested_block(|input| {- consume_nested_content_components(input)- .ok_or_else(|| input.new_custom_error::<(), ()>(()))- });- nested.ok()?;- }- _ => return None,- }- }- input.is_exhausted().then_some(has_counter)-}--fn content_component_starts_nested_block(token: &cssparser::Token<'_>) -> bool {- matches!(- token,- cssparser::Token::Function(_)- | cssparser::Token::ParenthesisBlock- | cssparser::Token::SquareBracketBlock- | cssparser::Token::CurlyBracketBlock- )-}--fn consume_nested_content_components(input: &mut cssparser::Parser<'_, '_>) -> Option<()> {- while let Ok(token) = input.next_including_whitespace_and_comments().cloned() {- if content_component_starts_nested_block(&token) {- let nested: Result<(), cssparser::ParseError<'_, ()>> =- input.parse_nested_block(|input| {- consume_nested_content_components(input)- .ok_or_else(|| input.new_custom_error::<(), ()>(()))- });- nested.ok()?;- }- }- input.is_exhausted().then_some(())-}-fn parse_text_decoration_line_supplemental_entries(name: &str,value: &str,@@ -7503,7 +7366,7 @@ mod tests {}#[test]- fn content_alt_counters_use_validated_supplemental_entries() {+ fn content_alt_counters_use_stylo_declaration_blocks() {for (input, expected) in [("\"\" / counter(cnt)", "\"\" / counter(cnt)"),(@@ -7532,8 +7395,8 @@ mod tests {assert_eq!(parsed.affected_names, vec!["content".to_owned()]);assert!(style_entry_is_pdb_safe(&parsed.entries[0]));assert!(- style_entry_is_pdb_supplemental_side_entry(&parsed.entries[0]),- "content: {input} should use side storage until Stylo parses alt counters"+ !style_entry_is_pdb_supplemental_side_entry(&parsed.entries[0]),+ "content: {input} should use the native Stylo declaration block");}diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rsindex 53df860ce..3eadb7ae2 100644--- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rs+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/computed_style.rs@@ -2,6 +2,51 @@ use super::*;mod child_list;+#[test]+fn content_alt_counters_compute_from_stylesheets_variables_and_cssom_updates() {+ let mut vm = new_parsed_test_vm(+ "https://content-alt-counter-computed.test/",+ r#"<!doctype html><html><head><style>+ #target {+ --alt: "Chapter " counter(chapter);+ content: "sheet" / "Chapter " counter(chapter);+ }+ #target::before { content: "before" / var(--alt); }+ </style></head><body><div id="target"></div></body></html>"#,+ );++ let result = vm+ .eval(+ r#"+(() => {+ const target = document.getElementById('target');+ const values = [+ getComputedStyle(target).content,+ getComputedStyle(target, '::before').content+ ];+ target.style.setProperty(+ 'content', '"inline" / counters(chapter, ".", DECIMAL)', 'important'+ );+ values.push(getComputedStyle(target).content);+ document.styleSheets[0].cssRules[0].style.content =+ '"updated" / counter(chapter, upper-roman)';+ values.push(getComputedStyle(target).content);+ target.style.removeProperty('content');+ values.push(getComputedStyle(target).content);+ target.style.setProperty('--alt', '"Section " counters(chapter, ".")');+ values.push(getComputedStyle(target, '::before').content);+ return values.join('|');+})()+"#,+ )+ .expect("content alternative counters should flow through Stylo computed values");++ assert_eq!(+ result,+ r#""sheet" / "Chapter " counter(chapter)|"before" / "Chapter " counter(chapter)|"inline" / counters(chapter, ".")|"inline" / counters(chapter, ".")|"updated" / counter(chapter, upper-roman)|"before" / "Section " counters(chapter, ".")"#+ );+}+#[test]fn element_current_css_zoom_observes_fresh_effective_style_for_rendered_boxes() {let mut vm = new_parsed_test_vm(