diff --git a/kayle/tests/innate-playwright.spec.ts b/kayle/tests/innate-playwright.spec.ts index b5cfda1..246e6a8 100644 --- a/kayle/tests/innate-playwright.spec.ts +++ b/kayle/tests/innate-playwright.spec.ts @@ -11,14 +11,15 @@ test("kayle_innate, fast_htmlcs, fast_axecore, and ace audit drakeMock profiling if (process.env.LOG_ENABLED) { page.on("console", (msg) => console.log("PAGE LOG:", msg.text())); } + const { html, css } = await innateBuilder({ page, browser, - runners: ["htmlcs"], includeWarnings: true, origin: "https://www.drake.com", html: drakeMock, }); + const startTime = performance.now(); // 8 - after building end engine optimized most likely will be at 12 ms await _audit_not_ready(html, css); diff --git a/kayle_innate/Cargo.lock b/kayle_innate/Cargo.lock index a3c8ddf..0ceefe5 100644 --- a/kayle_innate/Cargo.lock +++ b/kayle_innate/Cargo.lock @@ -14,6 +14,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "autocfg" version = "1.1.0" @@ -190,6 +196,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "grid" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eec1c01eb1de97451ee0d60de7d81cf1e72aabefb021616027f3d1c3ec1c723c" + [[package]] name = "html5ever" version = "0.26.0" @@ -239,6 +251,7 @@ dependencies = [ "getrandom", "lazy_static", "scraper", + "taffy", "url", "wasm-bindgen", "wasm-bindgen-test", @@ -305,6 +318,15 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +[[package]] +name = "num-traits" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.18.0" @@ -552,6 +574,15 @@ version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" +[[package]] +name = "slotmap" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" +dependencies = [ + "version_check", +] + [[package]] name = "smallvec" version = "1.11.1" @@ -612,6 +643,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "taffy" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82870da09c57a8a5a50f830ce8993a6637b9a4932f69257f12aea3fa68f588c9" +dependencies = [ + "arrayvec", + "grid", + "num-traits", + "slotmap", +] + [[package]] name = "tendril" version = "0.4.3" diff --git a/kayle_innate/Cargo.toml b/kayle_innate/Cargo.toml index 19e4e27..8c3dab3 100644 --- a/kayle_innate/Cargo.toml +++ b/kayle_innate/Cargo.toml @@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"] [features] default = ["console_error_panic_hook", "accessibility"] -accessibility = ["cssparser"] +accessibility = ["cssparser", "taffy"] [dependencies] wasm-bindgen = "0.2.63" @@ -24,6 +24,7 @@ case_insensitive_string = "0.1.0" scraper = { version = "0.17.1" } getrandom = { version = "0.2", features = ["js"] } cssparser = { version = "0.33.0", optional = true } +taffy = { version = "0.3.13", optional = true } [dev-dependencies] wasm-bindgen-test = "0.3.37" diff --git a/kayle_innate/src/engine/rules/wcag.rs b/kayle_innate/src/engine/rules/wcag.rs index b02ecaa..ffc5659 100644 --- a/kayle_innate/src/engine/rules/wcag.rs +++ b/kayle_innate/src/engine/rules/wcag.rs @@ -66,8 +66,8 @@ impl WCAG3AA { // allow tree mutation until threads or setup the tree with initial elements. mut tree: std::collections::BTreeMap>, _css: cssparser::Parser<'_, '_>, + // todo: get configs like viewport ) -> Vec { - // pre populate must have keys if !tree.contains_key("title") { tree.insert("title".into(), Default::default()); diff --git a/kayle_innate/src/lib.rs b/kayle_innate/src/lib.rs index 3bf800a..4ed3d7e 100644 --- a/kayle_innate/src/lib.rs +++ b/kayle_innate/src/lib.rs @@ -150,9 +150,56 @@ pub fn get_document_links(res: &str, domain: &str) -> Box<[JsValue]> { /// try to fix all possible issues using a spec against the tree. pub fn parse_accessibility_tree( html: &str, + // todo: return the nodes with a tuple of the layout node and the element node ) -> std::collections::BTreeMap> { + use taffy::prelude::*; + console_log!("Starting accessibility tree parsing. This is incomplete and should not be used in production."); + // todo: use optional variable for clips or layout creation + let mut taffy = Taffy::new(); + + let header_node = taffy + .new_leaf(Style { + size: Size { + width: points(800.0), + height: points(100.0), + }, + ..Default::default() + }) + .unwrap(); + + let body_node = taffy + .new_leaf(Style { + size: Size { + width: points(800.0), + height: auto(), + }, + flex_grow: 1.0, + ..Default::default() + }) + .unwrap(); + + let root_node = taffy + .new_with_children( + Style { + flex_direction: FlexDirection::Column, + size: Size { + width: points(800.0), + height: points(600.0), + }, + ..Default::default() + }, + &[header_node, body_node], + ) + .unwrap(); + + // Call compute_layout on the root of your tree to run the layout algorithm + taffy.compute_layout(root_node, Size::MAX_CONTENT).unwrap(); + + // We can get the x,y, and height, width of the element on proper tree insert + console_log!("Header Layout {:?}", taffy.layout(header_node).unwrap()); + let t = now(); // parse doc will start from html downwards let h = scraper::Html::parse_document(html); diff --git a/package.json b/package.json index 7d18f6c..031683d 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "build:test:fast_htmlcs": "yarn build:fast_htmlcs && yarn test:playwright:htmlcs", "build:test:axe": "yarn build:fast_axecore && yarn test:axe", "build:test:playwright:axe": "yarn build:fast_axecore && yarn test:playwright:axe", + "build:innate": "cd kayle_innate && wasm-pack build --target nodejs", "pub:fast_htmlcs": "yarn build:fast_htmlcs && yarn npm publish", "pub:fast_axecore": "yarn build:fast_axecore && yarn npm publish", "pub:kayle": "yarn build:kayle && yarn npm publish",