diff --git a/kayle_innate/kayle_innate/src/engine/audit/auditor.rs b/kayle_innate/kayle_innate/src/engine/audit/auditor.rs index 3e5d69f..d060e53 100644 --- a/kayle_innate/kayle_innate/src/engine/audit/auditor.rs +++ b/kayle_innate/kayle_innate/src/engine/audit/auditor.rs @@ -51,7 +51,7 @@ impl<'a> Auditor<'a> { console_log!("StyleSheets Build Time {:?}", now() - tt); let t = now(); - let tree = parse_accessibility_tree(&document); + let tree = parse_accessibility_tree(&document, &author); console_log!("Tree Build Time {:?}", now() - t); Auditor { diff --git a/kayle_innate/kayle_innate/src/engine/audit/tree.rs b/kayle_innate/kayle_innate/src/engine/audit/tree.rs index 60c8de0..0b06fb4 100644 --- a/kayle_innate/kayle_innate/src/engine/audit/tree.rs +++ b/kayle_innate/kayle_innate/src/engine/audit/tree.rs @@ -1,12 +1,14 @@ -use scraper_forky::{ElementRef, Selector}; +use scraper_forky::ElementRef; +use victor_tree::style::StyleSet; +use scraper_forky::Html; 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, +pub fn parse_accessibility_tree<'a, 'b>( + html: &'a Html, + _author: &StyleSet, // todo: return the nodes with a tuple of the layout node and the element node -) -> std::collections::BTreeMap<&str, Vec>> { +) -> std::collections::BTreeMap<&'a str, Vec>> { // use taffy::prelude::*; // // todo: use optional variable for clips or layout creation // let mut taffy = Taffy::new(); diff --git a/kayle_innate/kayle_innate/src/engine/styles/mod.rs b/kayle_innate/kayle_innate/src/engine/styles/mod.rs index ec5fbc3..aa4c4dc 100644 --- a/kayle_innate/kayle_innate/src/engine/styles/mod.rs +++ b/kayle_innate/kayle_innate/src/engine/styles/mod.rs @@ -1,90 +1,3 @@ pub mod css_cache; pub mod errors; -pub mod rules; - -use crate::console_log; -use cssparser::{Parser, ParserInput}; -use markup5ever::local_name; -use markup5ever::namespace_url; -use markup5ever::ns; -use scraper_forky::selector::Simple; -use scraper_forky::{ElementRef, Html}; -use selectors::matching::MatchingContext; -use std::sync::Arc; -use victor_tree::style::cascade::USER_AGENT_STYLESHEET; -use victor_tree::style::declaration_block::DeclarationBlock; -use victor_tree::style::values::{Direction, WritingMode}; -use victor_tree::style::{ComputedValues, StyleSet}; - -/// get the style for an element -pub fn style_for_element<'a>( - author: &StyleSet, - _document: &Html, - node: ElementRef<'a>, - parent_style: Option<&ComputedValues>, - match_context: &mut MatchingContext<'_, Simple>, -) -> Arc { - use smallvec::SmallVec; - let style_attr_block; - let mut matching = victor_tree::style::cascade::MatchingDeclarations { - ua: SmallVec::new(), - author: SmallVec::new(), - }; - - // let mut nth_index_cache = selectors::NthIndexCache::from(Default::default()); - // let mut match_context = selectors::matching::MatchingContext::new( - // selectors::matching::MatchingMode::Normal, - // None, - // Some(&mut nth_index_cache), - // selectors::matching::QuirksMode::NoQuirks, - // // selectors::matching::NeedsSelectorFlags::No, - // // selectors::matching::IgnoreNthChildForInvalidation::No, - // ); - - for &(ref selector, ref block) in &USER_AGENT_STYLESHEET.rules { - if selectors::matching::matches_selector( - selector, - 0, - None, - &node, - match_context, - &mut |_, _| {}, - ) { - matching.ua.push(block) - } - } - - // push author style sheet - for &(ref selector, ref block) in &author.rules { - if selectors::matching::matches_selector( - selector, - 0, - None, - &node, - match_context, - &mut |_, _| {}, - ) { - matching.author.push(block) - } - } - - if let ns!(html) | ns!(svg) | ns!(mathml) = node.value().name.ns { - if let Some(style_attr) = node.value().attr(&local_name!("style")) { - let mut input = ParserInput::new(style_attr); - let mut parser = Parser::new(&mut input); - style_attr_block = DeclarationBlock::parse(&mut parser); - matching.author.push(&style_attr_block); - } - } - - let styles = ComputedValues::new(parent_style, Some(&matching)); - - console_log!( - "{:?}", - styles - .box_size() - .size_to_physical((WritingMode::SidewaysLr, Direction::Ltr)) - ); - - styles -} +pub mod rules; \ No newline at end of file diff --git a/kayle_innate/kayle_victor/victor/src/main.rs b/kayle_innate/kayle_victor/victor/src/main.rs deleted file mode 100644 index ae5355d..0000000 --- a/kayle_innate/kayle_victor/victor/src/main.rs +++ /dev/null @@ -1,10 +0,0 @@ -fn main() -> Result<(), Box> { - let mut args = std::env::args_os(); - let mut next = || args.next().ok_or("Usage: victor input.html output.pdf"); - let _self = next()?; - let input = next()?; - let output = next()?; - let bytes = std::fs::read(&input)?; - let doc = victor_tree::dom::Document::parse_html(&bytes); - Ok(()) -}