Skip to content

Commit

Permalink
chore(layout): add prep sheet layout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 6, 2023
1 parent 8e23dc0 commit 33e216d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 27 deletions.
33 changes: 16 additions & 17 deletions kayle_innate/kayle_innate/src/engine/audit/auditor.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion kayle_innate/kayle_innate/src/engine/audit/tree.rs
Original file line number Diff line number Diff line change
@@ -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<ElementRef<'_>>> {
// use taffy::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion kayle_innate/kayle_innate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn _audit_not_ready(html: &str, css_rules: &str) -> Result<JsValue, JsValue>
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 {
Expand Down
1 change: 0 additions & 1 deletion kayle_innate/kayle_scraper/src/element_ref/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ impl<'a> Element for ElementRef<'a> {

fn namespace(&self) -> &Namespace {
&self.value().name.ns

}

fn opaque(&self) -> OpaqueElement {
Expand Down
4 changes: 2 additions & 2 deletions kayle_innate/kayle_scraper/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -235,7 +235,7 @@ pub struct Element {
classes: OnceCell<Vec<LocalName>>,

/// locale name
pub local_name: CssLocalName
pub local_name: CssLocalName,
}

impl Element {
Expand Down
11 changes: 7 additions & 4 deletions kayle_innate/kayle_scraper/src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 |_, _| {}))
}
}

Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion kayle_innate/kayle_victor/victor/src/fonts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn read_postscript_name(
}
})
.collect::<String>()
};
}

let naming_table_header = table_directory.find_table::<NamingTableHeader>(bytes)?;
let name_records = Slice::new(
Expand Down

0 comments on commit 33e216d

Please sign in to comment.