Skip to content

Commit

Permalink
chore(deps): update [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Mar 18, 2024
1 parent 3c81723 commit e4544c1
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 40 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions accessibility-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 3 additions & 4 deletions accessibility-rs/src/engine/audit/auditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DefaultKey>)>>,
pub tree: std::collections::BTreeMap<&'a str, Vec<(ElementRef<'a>, Option<taffy::NodeId>)>>,
/// 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<Taffy>,
pub taffy: Option<TaffyTree>,
/// language to get results in
pub locale: &'a str,
}
Expand Down
21 changes: 10 additions & 11 deletions accessibility-rs/src/engine/audit/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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<DefaultKey>)>>,
Option<Taffy>,
BTreeMap<&'a str, Vec<(ElementRef<'a>, Option<NodeId>)>>,
Option<TaffyTree>,
MatchingContext<'c, Simple>,
) {
let mut accessibility_tree: BTreeMap<&str, Vec<(ElementRef<'_>, Option<DefaultKey>)>> =
let mut accessibility_tree: BTreeMap<&str, Vec<(ElementRef<'_>, Option<NodeId>)>> =
BTreeMap::from(if document.root_element().value().name() == "html" {
[("title".into(), Default::default())]
} else {
Expand Down Expand Up @@ -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<DefaultKey>)>>,
Option<Taffy>,
BTreeMap<&'a str, Vec<(ElementRef<'a>, Option<NodeId>)>>,
Option<TaffyTree>,
MatchingContext<'c, Simple>,
) {
let mut taffy = Taffy::new();
let mut accessibility_tree: BTreeMap<&str, Vec<(ElementRef<'_>, Option<DefaultKey>)>> =
let mut taffy = TaffyTree::new();
let mut accessibility_tree: BTreeMap<&str, Vec<(ElementRef<'_>, Option<NodeId>)>> =
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<Node> = vec![];
let mut layout_leafs: Vec<NodeId> = vec![];

// push taffy layout in order from elements
for node in document.tree.nodes() {
Expand Down Expand Up @@ -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()
},
Expand Down
4 changes: 1 addition & 3 deletions accessibility-rs/src/engine/rules/rule.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -104,7 +102,7 @@ impl From<Vec<Validation>> for RuleValidation {
}

type ValidateFn =
fn(&Vec<(ElementRef<'_>, Option<DefaultKey>)>, &mut crate::Auditor<'_>) -> RuleValidation;
fn(&Vec<(ElementRef<'_>, Option<taffy::NodeId>)>, &mut crate::Auditor<'_>) -> RuleValidation;

/// the rule validation method that should be performed.
#[derive(Debug)]
Expand Down
3 changes: 1 addition & 2 deletions accessibility-rs/src/engine/rules/utils/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DefaultKey>)>;
type ElementNodes<'a> = Vec<(ElementRef<'a>, Option<taffy::NodeId>)>;

/// a valid alt attribute for image
pub fn has_alt(ele: ElementRef<'_>) -> bool {
Expand Down
25 changes: 12 additions & 13 deletions accessibility-rs/src/engine/styles/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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,
}
Expand All @@ -44,7 +43,7 @@ pub fn node_layout_style(style: Arc<ComputedValues>, element: &ElementRef) -> St
let w = w.parse::<f32>();
match w {
Ok(w) => {
size.width = points(w);
size.width = length(w);
}
_ => (),
}
Expand All @@ -59,7 +58,7 @@ pub fn node_layout_style(style: Arc<ComputedValues>, element: &ElementRef) -> St

match h {
Ok(h) => {
size.height = points(h);
size.height = length(h);
}
_ => (),
}
Expand All @@ -72,9 +71,9 @@ pub fn node_layout_style(style: Arc<ComputedValues>, 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()
}
}
Expand All @@ -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<Node>,
taffy: &mut TaffyTree,
l_leafs: &mut Vec<NodeId>,
) {
match ElementRef::wrap(*node) {
Some(element) => {
Expand All @@ -101,7 +100,7 @@ pub fn push_leaf<'a, 'b, 'c>(

if node.has_children() {
let children = node.children();
let mut child_leafs: Vec<Node> = vec![];
let mut child_leafs: Vec<NodeId> = vec![];

// iterate all children and push into one leaf
for child in children {
Expand Down Expand Up @@ -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<Node> = vec![];
taffy: &mut TaffyTree,
) -> NodeId {
let mut l_leafs: Vec<NodeId> = vec![];
let mut children = element.children();

while let Some(child) = children.next() {
Expand Down
25 changes: 25 additions & 0 deletions accessibility-rs/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit e4544c1

Please sign in to comment.