Skip to content

Commit

Permalink
chore(innate): add layout setup
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 2, 2023
1 parent dc7f47f commit 1988fd4
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 3 deletions.
3 changes: 2 additions & 1 deletion kayle/tests/innate-playwright.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
43 changes: 43 additions & 0 deletions kayle_innate/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion kayle_innate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion kayle_innate/src/engine/rules/wcag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ impl WCAG3AA {
// allow tree mutation until threads or setup the tree with initial elements.
mut tree: std::collections::BTreeMap<String, Vec<scraper::node::Element>>,
_css: cssparser::Parser<'_, '_>,
// todo: get configs like viewport
) -> Vec<Issue> {

// pre populate must have keys
if !tree.contains_key("title") {
tree.insert("title".into(), Default::default());
Expand Down
47 changes: 47 additions & 0 deletions kayle_innate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Vec<scraper::node::Element>> {
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);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1988fd4

Please sign in to comment.