diff --git a/kayle_innate/Cargo.lock b/kayle_innate/Cargo.lock index 0c9ebe6..f9d610c 100644 --- a/kayle_innate/Cargo.lock +++ b/kayle_innate/Cargo.lock @@ -238,6 +238,7 @@ dependencies = [ "case_insensitive_string", "console_error_panic_hook", "cssparser", + "ego-tree", "getrandom", "js-sys", "lazy_static", diff --git a/kayle_innate/Cargo.toml b/kayle_innate/Cargo.toml index b9f4395..c0dbc50 100644 --- a/kayle_innate/Cargo.toml +++ b/kayle_innate/Cargo.toml @@ -29,6 +29,7 @@ serde-wasm-bindgen = "0.4" js-sys = "0.3.64" selectors = "0.25.0" smallvec = "1.11.1" +ego-tree = "0.6.2" [dependencies.cssparser] version = "^0.31.0" diff --git a/kayle_innate/src/engine/audit/wcag.rs b/kayle_innate/src/engine/audit/wcag.rs index 65e729f..b5de802 100644 --- a/kayle_innate/src/engine/audit/wcag.rs +++ b/kayle_innate/src/engine/audit/wcag.rs @@ -12,7 +12,7 @@ impl WCAG3AA { /// init the rules pub fn audit( // allow tree mutation until threads or setup the tree with initial elements. - tree: std::collections::BTreeMap<&str, Vec>>, + tree: &std::collections::BTreeMap<&str, Vec>>, _css: cssparser::Parser<'_, '_>, // todo: get configs like viewport ) -> Vec { diff --git a/kayle_innate/src/lib.rs b/kayle_innate/src/lib.rs index 03ede58..8969863 100644 --- a/kayle_innate/src/lib.rs +++ b/kayle_innate/src/lib.rs @@ -18,6 +18,9 @@ use std::collections::BTreeMap; use std::collections::HashSet; use utils::{convert_abs_path, convert_base_path, domain_name, set_panic_hook}; +#[cfg(feature = "accessibility")] +use selectors::matching::{MatchingContext, MatchingMode, QuirksMode}; + #[cfg(feature = "accessibility")] #[wasm_bindgen] extern "C" { @@ -231,6 +234,8 @@ pub fn parse_accessibility_tree( /// audit a web page passing the html and css rules. pub fn _audit_not_ready(html: &str, _css_rules: &str) -> Result { // majority of time is spent on initial parse_document. + + use selectors::NthIndexCache; let html = scraper::Html::parse_document(html); let _tree = parse_accessibility_tree(&html); // TODO: if the css rules are empty extract the css from the HTML @@ -244,7 +249,7 @@ pub fn _audit_not_ready(html: &str, _css_rules: &str) -> Result { @@ -252,13 +257,45 @@ pub fn _audit_not_ready(html: &str, _css_rules: &str) -> Result () + _ => (), }; } console_log!("CSS RULES: {:?}", rules); - let _audit = engine::audit::wcag::WCAG3AA::audit(_tree, _css_parser); + let _audit = engine::audit::wcag::WCAG3AA::audit(&_tree, _css_parser); + + // TODO: build struct that can keep lifetimes + // let mut nth_index_cache = NthIndexCache::from(Default::default()); + // let mut match_context = MatchingContext::new( + // MatchingMode::Normal, + // None, + // &mut nth_index_cache, + // QuirksMode::NoQuirks, + // selectors::matching::NeedsSelectorFlags::No, + // selectors::matching::IgnoreNthChildForInvalidation::No, + // ); + + // for item in _tree { + // for node in item.1 { + // let id = node.id(); + + // // todo: use the css block style to get computations + // for &(ref selector, ref _block) in &rules { + // if selectors::matching::matches_selector( + // selector, + // 0, + // None, + // &node, + // &mut match_context, + // ) { + // console_log!("Style Match {:?}", id); + // // build all the styles for the element based on the match + // // into.push(_block) + // } + // } + // } + // } // todo: map to JsValues instead of serde Ok(serde_wasm_bindgen::to_value(&_audit)?)