From e4544c128261ba975be7827e722763e98e44202d Mon Sep 17 00:00:00 2001 From: j-mendez Date: Mon, 18 Mar 2024 11:42:51 -0400 Subject: [PATCH] chore(deps): update taffy@0.4.0 --- Cargo.lock | 10 ++++---- accessibility-rs/Cargo.toml | 3 +-- accessibility-rs/src/engine/audit/auditor.rs | 7 +++--- accessibility-rs/src/engine/audit/tree.rs | 21 ++++++++-------- accessibility-rs/src/engine/rules/rule.rs | 4 +-- .../src/engine/rules/utils/nodes.rs | 3 +-- accessibility-rs/src/engine/styles/layout.rs | 25 +++++++++---------- accessibility-rs/tests/integration_test.rs | 25 +++++++++++++++++++ 8 files changed, 58 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f0ba6ab..00f7a03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,7 +19,6 @@ dependencies = [ "rust-i18n", "selectors", "serde", - "slotmap", "smallvec", "strum", "strum_macros", @@ -596,9 +595,9 @@ dependencies = [ [[package]] name = "grid" -version = "0.10.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eec1c01eb1de97451ee0d60de7d81cf1e72aabefb021616027f3d1c3ec1c723c" +checksum = "d196ffc1627db18a531359249b2bf8416178d84b729f3cebeb278f285fb9b58c" [[package]] name = "half" @@ -1576,13 +1575,14 @@ dependencies = [ [[package]] name = "taffy" -version = "0.3.18" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c2287b6d7f721ada4cddf61ade5e760b2c6207df041cac9bfaa192897362fd3" +checksum = "fddbee94e20bc4612dcb789953324236eebd4fc6a08c650ccbf7f615e59a0d6a" dependencies = [ "arrayvec", "grid", "num-traits", + "serde", "slotmap", ] diff --git a/accessibility-rs/Cargo.toml b/accessibility-rs/Cargo.toml index 2e2ac8a..f5c23cd 100644 --- a/accessibility-rs/Cargo.toml +++ b/accessibility-rs/Cargo.toml @@ -18,14 +18,13 @@ lazy_static = { workspace = true } accessibility-scraper = { version = "0.0.6", features = ["main"], default-features = false, path = "../accessibility-scraper" } accessibility-tree = { version = "0.0.6", path = "../accessibility-tree/victor" } getrandom = { version = "0.2", features = ["js"] } -taffy = { version = "0.3.13" } +taffy = { version = "0.4.0" } serde = { version = "1.0", features = ["derive"] } selectors = { workspace = true } smallvec = { workspace = true } ego-tree = { workspace = true } markup5ever = "0.11.0" cssparser = { workspace = true } -slotmap = "1.0.6" strum = "0.25" strum_macros = "0.25" rust-i18n = "2" diff --git a/accessibility-rs/src/engine/audit/auditor.rs b/accessibility-rs/src/engine/audit/auditor.rs index e8d59f3..29d126d 100644 --- a/accessibility-rs/src/engine/audit/auditor.rs +++ b/accessibility-rs/src/engine/audit/auditor.rs @@ -4,22 +4,21 @@ use accessibility_scraper::ElementRef; use accessibility_scraper::Html; use accessibility_tree::style::StyleSet; use markup5ever::local_name; -use slotmap::DefaultKey; -use taffy::Taffy; +use taffy::TaffyTree; /// The configuration for auditing pub struct Auditor<'a> { /// the html document pub document: &'a Html, /// the tree to map to nodes - pub tree: std::collections::BTreeMap<&'a str, Vec<(ElementRef<'a>, Option)>>, + pub tree: std::collections::BTreeMap<&'a str, Vec<(ElementRef<'a>, Option)>>, /// styles for the audit pub author: StyleSet, /// the matching context for css selectors pub match_context: selectors::matching::MatchingContext<'a, accessibility_scraper::selector::Simple>, /// layout handling - pub taffy: Option, + pub taffy: Option, /// language to get results in pub locale: &'a str, } diff --git a/accessibility-rs/src/engine/audit/tree.rs b/accessibility-rs/src/engine/audit/tree.rs index 24085cd..4e94434 100644 --- a/accessibility-rs/src/engine/audit/tree.rs +++ b/accessibility-rs/src/engine/audit/tree.rs @@ -4,7 +4,6 @@ use accessibility_scraper::ElementRef; use accessibility_scraper::Html; use accessibility_tree::style::StyleSet; use selectors::matching::MatchingContext; -use slotmap::DefaultKey; use std::collections::BTreeMap; use std::collections::HashSet; use taffy::prelude::*; @@ -20,11 +19,11 @@ pub fn parse_accessibility_tree<'a, 'b, 'c>( _author: &StyleSet, match_context: MatchingContext<'c, Simple>, // todo: return the nodes with a tuple of the layout node and the element node ) -> ( - BTreeMap<&'a str, Vec<(ElementRef<'a>, Option)>>, - Option, + BTreeMap<&'a str, Vec<(ElementRef<'a>, Option)>>, + Option, MatchingContext<'c, Simple>, ) { - let mut accessibility_tree: BTreeMap<&str, Vec<(ElementRef<'_>, Option)>> = + let mut accessibility_tree: BTreeMap<&str, Vec<(ElementRef<'_>, Option)>> = BTreeMap::from(if document.root_element().value().name() == "html" { [("title".into(), Default::default())] } else { @@ -52,19 +51,19 @@ pub fn parse_accessibility_tree_bounded<'a, 'b, 'c>( author: &StyleSet, match_context: MatchingContext<'c, Simple>, // todo: return the nodes with a tuple of the layout node and the element node ) -> ( - BTreeMap<&'a str, Vec<(ElementRef<'a>, Option)>>, - Option, + BTreeMap<&'a str, Vec<(ElementRef<'a>, Option)>>, + Option, MatchingContext<'c, Simple>, ) { - let mut taffy = Taffy::new(); - let mut accessibility_tree: BTreeMap<&str, Vec<(ElementRef<'_>, Option)>> = + let mut taffy = TaffyTree::new(); + let mut accessibility_tree: BTreeMap<&str, Vec<(ElementRef<'_>, Option)>> = BTreeMap::from(if document.root_element().value().name() == "html" { [("title".into(), Default::default())] } else { [(Default::default(), Default::default())] }); let mut matching_context = match_context; - let mut layout_leafs: Vec = vec![]; + let mut layout_leafs: Vec = vec![]; // push taffy layout in order from elements for node in document.tree.nodes() { @@ -123,8 +122,8 @@ pub fn parse_accessibility_tree_bounded<'a, 'b, 'c>( flex_direction: FlexDirection::Column, // compute the default layout from CDP size: Size { - width: points(800.0), - height: points(600.0), + width: length(800.0), + height: length(600.0), }, ..Default::default() }, diff --git a/accessibility-rs/src/engine/rules/rule.rs b/accessibility-rs/src/engine/rules/rule.rs index 669d729..0ca6100 100644 --- a/accessibility-rs/src/engine/rules/rule.rs +++ b/accessibility-rs/src/engine/rules/rule.rs @@ -1,5 +1,3 @@ -use slotmap::DefaultKey; - use crate::engine::rules::techniques::Techniques; use crate::engine::rules::wcag_base::{Guideline, IssueType, Principle}; use crate::ElementRef; @@ -104,7 +102,7 @@ impl From> for RuleValidation { } type ValidateFn = - fn(&Vec<(ElementRef<'_>, Option)>, &mut crate::Auditor<'_>) -> RuleValidation; + fn(&Vec<(ElementRef<'_>, Option)>, &mut crate::Auditor<'_>) -> RuleValidation; /// the rule validation method that should be performed. #[derive(Debug)] diff --git a/accessibility-rs/src/engine/rules/utils/nodes.rs b/accessibility-rs/src/engine/rules/utils/nodes.rs index b229ce5..628b0ec 100644 --- a/accessibility-rs/src/engine/rules/utils/nodes.rs +++ b/accessibility-rs/src/engine/rules/utils/nodes.rs @@ -2,9 +2,8 @@ use crate::engine::rules::rule::Validation; use crate::ElementRef; use accessibility_scraper::Selector; use selectors::Element; -use slotmap::DefaultKey; -type ElementNodes<'a> = Vec<(ElementRef<'a>, Option)>; +type ElementNodes<'a> = Vec<(ElementRef<'a>, Option)>; /// a valid alt attribute for image pub fn has_alt(ele: ElementRef<'_>) -> bool { diff --git a/accessibility-rs/src/engine/styles/layout.rs b/accessibility-rs/src/engine/styles/layout.rs index 4587d97..2527f88 100644 --- a/accessibility-rs/src/engine/styles/layout.rs +++ b/accessibility-rs/src/engine/styles/layout.rs @@ -6,7 +6,6 @@ use accessibility_tree::style::ComputedValues; use accessibility_tree::style::StyleSet; use ego_tree::NodeRef; use selectors::matching::MatchingContext; -use slotmap::DefaultKey; use std::collections::HashSet; use std::sync::Arc; use taffy::prelude::*; @@ -20,7 +19,7 @@ lazy_static! { /// length to taffy dimensions pub fn length_dimensions(v: &LengthOrPercentageOrAuto) -> Dimension { match v { - LengthOrPercentageOrAuto::Length(l) => Dimension::Points(l.px), + LengthOrPercentageOrAuto::Length(l) => Dimension::Length(l.px), LengthOrPercentageOrAuto::Percentage(l) => Dimension::Percent(l.unit_value), LengthOrPercentageOrAuto::Auto => Dimension::Auto, } @@ -44,7 +43,7 @@ pub fn node_layout_style(style: Arc, element: &ElementRef) -> St let w = w.parse::(); match w { Ok(w) => { - size.width = points(w); + size.width = length(w); } _ => (), } @@ -59,7 +58,7 @@ pub fn node_layout_style(style: Arc, element: &ElementRef) -> St match h { Ok(h) => { - size.height = points(h); + size.height = length(h); } _ => (), } @@ -72,9 +71,9 @@ pub fn node_layout_style(style: Arc, element: &ElementRef) -> St // todo: determine if all children at the top level have floats set to use flex-row Style { size, - border: points(style.border_width().inner_px()), - padding: points(style.padding().inner_px()), - margin: points(style.margin().inner_px()), + border: length(style.border_width().inner_px()), + padding: length(style.padding().inner_px()), + margin: length(style.margin().inner_px()), ..Default::default() } } @@ -85,8 +84,8 @@ pub fn push_leaf<'a, 'b, 'c>( author: &StyleSet, document: &'a Html, mut matching_context: &mut MatchingContext<'c, Simple>, - taffy: &mut Taffy, - l_leafs: &mut Vec, + taffy: &mut TaffyTree, + l_leafs: &mut Vec, ) { match ElementRef::wrap(*node) { Some(element) => { @@ -101,7 +100,7 @@ pub fn push_leaf<'a, 'b, 'c>( if node.has_children() { let children = node.children(); - let mut child_leafs: Vec = vec![]; + let mut child_leafs: Vec = vec![]; // iterate all children and push into one leaf for child in children { @@ -135,9 +134,9 @@ pub fn leaf<'a, 'b, 'c>( author: &StyleSet, document: &'a Html, mut matching_context: &mut MatchingContext<'c, Simple>, - taffy: &mut Taffy, -) -> DefaultKey { - let mut l_leafs: Vec = vec![]; + taffy: &mut TaffyTree, +) -> NodeId { + let mut l_leafs: Vec = vec![]; let mut children = element.children(); while let Some(child) = children.next() { diff --git a/accessibility-rs/tests/integration_test.rs b/accessibility-rs/tests/integration_test.rs index d4b70f7..49d2c3b 100644 --- a/accessibility-rs/tests/integration_test.rs +++ b/accessibility-rs/tests/integration_test.rs @@ -25,3 +25,28 @@ fn _audit_large() { )); println!("{:?}", report) } + + + +#[test] +fn _audit_with_layout() { + let report = accessibility_rs::audit(AuditConfig::new( + mock::MOCK_WEBSITE_HTML, + &mock::MOCK_CSS_RULES, + true, + "en", + )); + println!("{:?}", report) +} + +#[test] +fn _audit_large_with_layout() { + let report = accessibility_rs::audit(AuditConfig::new( + mock::MOCK_HTML_LARGE_PAGE, + &mock::MOCK_CSS_RULES_LARGE, + true, + "en", + )); + println!("{:?}", report) +} +