diff --git a/kayle/tests/innate.ts b/kayle/tests/innate.ts index 0770993..afde688 100644 --- a/kayle/tests/innate.ts +++ b/kayle/tests/innate.ts @@ -18,6 +18,7 @@ import { _audit_not_ready } from "kayle_innate"; origin: "https://www.drake.com", html: drakeMock, }); + const mock = html.replace( "Drake Industries | Custom, Durable, High-Quality Labels, Asset Tags and Custom Server Bezels", "" 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/engine/styles/rules.rs b/kayle_innate/src/engine/styles/rules.rs index ebe42f3..c00da29 100644 --- a/kayle_innate/src/engine/styles/rules.rs +++ b/kayle_innate/src/engine/styles/rules.rs @@ -4,11 +4,6 @@ use scraper::selector::Simple; use selectors::parser::ParseRelative; use std::sync::Arc; -impl<'i> selectors::parser::Parser<'i> for Parser { - type Impl = Simple; - type Error = RuleParseErrorKind<'i>; -} - #[derive(Debug)] pub enum CssRule { StyleRule { @@ -19,6 +14,11 @@ pub enum CssRule { pub struct Parser; +impl<'i> selectors::parser::Parser<'i> for Parser { + type Impl = Simple; + type Error = RuleParseErrorKind<'i>; +} + pub type SelectorList = selectors::SelectorList; // pub type Selector = selectors::parser::Selector; diff --git a/kayle_innate/src/lib.rs b/kayle_innate/src/lib.rs index 03ede58..f6f7a6c 100644 --- a/kayle_innate/src/lib.rs +++ b/kayle_innate/src/lib.rs @@ -230,7 +230,8 @@ pub fn parse_accessibility_tree( #[cfg(feature = "accessibility")] /// 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::matching::{MatchingContext, MatchingMode, QuirksMode}; + 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 +245,7 @@ pub fn _audit_not_ready(html: &str, _css_rules: &str) -> Result { @@ -252,13 +253,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 = selectors::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)?)