From db6702abcea2249e18e1af8d8d2adf66ea65c90d Mon Sep 17 00:00:00 2001 From: j-mendez Date: Fri, 6 Oct 2023 17:45:55 -0400 Subject: [PATCH] chore(layout): add prep sheet layout handling --- .../kayle_innate/src/engine/audit/auditor.rs | 33 +++++++++---------- .../kayle_innate/src/engine/audit/tree.rs | 3 +- kayle_innate/kayle_innate/src/lib.rs | 2 +- .../kayle_scraper/src/element_ref/element.rs | 1 - kayle_innate/kayle_scraper/src/node.rs | 4 +-- kayle_innate/kayle_scraper/src/selector.rs | 11 ++++--- .../kayle_victor/victor/src/fonts/mod.rs | 2 +- 7 files changed, 29 insertions(+), 27 deletions(-) diff --git a/kayle_innate/kayle_innate/src/engine/audit/auditor.rs b/kayle_innate/kayle_innate/src/engine/audit/auditor.rs index d4886b1..3e5d69f 100644 --- a/kayle_innate/kayle_innate/src/engine/audit/auditor.rs +++ b/kayle_innate/kayle_innate/src/engine/audit/auditor.rs @@ -1,6 +1,8 @@ +use crate::{console_log, now}; use scraper_forky::ElementRef; use scraper_forky::Html; use victor_tree::style::StyleSet; +use markup5ever::local_name; use super::tree::parse_accessibility_tree; @@ -22,39 +24,36 @@ impl<'a> Auditor<'a> { css_rules: &str, match_context: selectors::matching::MatchingContext<'a, scraper_forky::selector::Simple>, ) -> Auditor<'a> { - use crate::{console_log, now}; - let t = now(); - let tree = parse_accessibility_tree(&document); - console_log!("Tree Build Time {:?}", now() - t); let tt = now(); - // TODO: make stylesheet building optional and only on first requirement let author = { let mut author = victor_tree::style::StyleSetBuilder::new(); if !css_rules.is_empty() { author.add_stylesheet(css_rules); } else { - use markup5ever::local_name; - match tree.get("style") { - Some(styles) => { - for node in styles { - // https://html.spec.whatwg.org/multipage/semantics.html#update-a-style-block - if let Some(type_attr) = node.attr(&local_name!("type")) { - if !type_attr.eq_ignore_ascii_case("text/css") { - continue; - } - author.add_stylesheet(&node.inner_html()) - } + let selector = + unsafe { scraper_forky::Selector::parse("style").unwrap_unchecked() }; + let mut s = document.select(&selector); + + while let Some(node) = s.next() { + if let Some(type_attr) = node.attr(&local_name!("type")) { + if !type_attr.eq_ignore_ascii_case("text/css") { + continue; } + author.add_stylesheet(&node.inner_html()) } - _ => (), } } author.finish() }; + // TODO: make stylesheet building optional and only on first requirement console_log!("StyleSheets Build Time {:?}", now() - tt); + let t = now(); + let tree = parse_accessibility_tree(&document); + console_log!("Tree Build Time {:?}", now() - t); + Auditor { document, tree, diff --git a/kayle_innate/kayle_innate/src/engine/audit/tree.rs b/kayle_innate/kayle_innate/src/engine/audit/tree.rs index 153f5c9..60c8de0 100644 --- a/kayle_innate/kayle_innate/src/engine/audit/tree.rs +++ b/kayle_innate/kayle_innate/src/engine/audit/tree.rs @@ -1,9 +1,10 @@ -use scraper_forky::ElementRef; +use scraper_forky::{ElementRef, Selector}; use std::collections::BTreeMap; /// try to fix all possible issues using a spec against the tree. pub fn parse_accessibility_tree( html: &scraper_forky::Html, + // css_rules: &str, // todo: return the nodes with a tuple of the layout node and the element node ) -> std::collections::BTreeMap<&str, Vec>> { // use taffy::prelude::*; diff --git a/kayle_innate/kayle_innate/src/lib.rs b/kayle_innate/kayle_innate/src/lib.rs index c66ad91..a1f851d 100644 --- a/kayle_innate/kayle_innate/src/lib.rs +++ b/kayle_innate/kayle_innate/src/lib.rs @@ -55,7 +55,7 @@ pub fn _audit_not_ready(html: &str, css_rules: &str) -> Result let ttt = now(); let _audit = engine::audit::wcag::WCAG3AA::audit(&auditor); console_log!("Audit Time {:?}", now() - ttt); - + // let mut _match_context = auditor.match_context; // for item in auditor.tree { diff --git a/kayle_innate/kayle_scraper/src/element_ref/element.rs b/kayle_innate/kayle_scraper/src/element_ref/element.rs index f9bf9c4..9e704e0 100644 --- a/kayle_innate/kayle_scraper/src/element_ref/element.rs +++ b/kayle_innate/kayle_scraper/src/element_ref/element.rs @@ -17,7 +17,6 @@ impl<'a> Element for ElementRef<'a> { fn namespace(&self) -> &Namespace { &self.value().name.ns - } fn opaque(&self) -> OpaqueElement { diff --git a/kayle_innate/kayle_scraper/src/node.rs b/kayle_innate/kayle_scraper/src/node.rs index 4da0aca..1cfc3bb 100644 --- a/kayle_innate/kayle_scraper/src/node.rs +++ b/kayle_innate/kayle_scraper/src/node.rs @@ -8,7 +8,7 @@ use std::fmt; use std::ops::Deref; use std::slice::Iter as SliceIter; -use crate::{selectors::attr::CaseSensitivity, StrTendril, selector::CssLocalName}; +use crate::{selector::CssLocalName, selectors::attr::CaseSensitivity, StrTendril}; use html5ever::{Attribute, LocalName, QualName}; use once_cell::unsync::OnceCell; @@ -235,7 +235,7 @@ pub struct Element { classes: OnceCell>, /// locale name - pub local_name: CssLocalName + pub local_name: CssLocalName, } impl Element { diff --git a/kayle_innate/kayle_scraper/src/selector.rs b/kayle_innate/kayle_scraper/src/selector.rs index b026f4b..5c6d8c0 100644 --- a/kayle_innate/kayle_scraper/src/selector.rs +++ b/kayle_innate/kayle_scraper/src/selector.rs @@ -56,7 +56,7 @@ impl Selector { context.scope_element = scope.map(|x| selectors::Element::opaque(&x)); self.selectors .iter() - .any(|s| matching::matches_selector(s, 0, None, element, &mut context, &mut |_, _| {} )) + .any(|s| matching::matches_selector(s, 0, None, element, &mut context, &mut |_, _| {})) } } @@ -118,14 +118,17 @@ impl cssparser::ToCss for CssString { pub struct CssLocalName(pub LocalName); impl std::fmt::Display for CssString { - fn fmt(&self, _: &mut core::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { Ok(()) } + fn fmt(&self, _: &mut core::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + Ok(()) + } } impl std::fmt::Display for CssLocalName { - fn fmt(&self, _: &mut core::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { Ok(()) } + fn fmt(&self, _: &mut core::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + Ok(()) + } } - impl<'a> From<&'a str> for CssLocalName { fn from(val: &'a str) -> Self { Self(val.into()) diff --git a/kayle_innate/kayle_victor/victor/src/fonts/mod.rs b/kayle_innate/kayle_victor/victor/src/fonts/mod.rs index 9043f3d..d3c627e 100644 --- a/kayle_innate/kayle_victor/victor/src/fonts/mod.rs +++ b/kayle_innate/kayle_victor/victor/src/fonts/mod.rs @@ -213,7 +213,7 @@ fn read_postscript_name( } }) .collect::() - }; + } let naming_table_header = table_directory.find_table::(bytes)?; let name_records = Slice::new(