Skip to content

Commit

Permalink
chore(innate): add accessibility tree building
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Sep 29, 2023
1 parent d3aa4a3 commit a4c16d7
Show file tree
Hide file tree
Showing 6 changed files with 1,003 additions and 66 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ✨ kayle

The futuristic web accessibility engine.
The blazing fast and accurate web accessibility engine.

## Getting Started

Expand Down Expand Up @@ -218,6 +218,10 @@ Run the following to install on ^node@18

Use the command `yarn build` to compile all the scripts for each locale.

## Rust Runner

We are building a rust based runner called [kayle_innate](./kayle_innate/) that can port to wasm that will take the audits into the nanoseconds - low milliseconds zone.

## Discord

If you want to chat about the project checkout our [Discord](https://discord.gg/ukmJcjQ5).
Expand Down
6 changes: 6 additions & 0 deletions kayle_innate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ In order to test the accessibility parser in Rust run.

1. Port expensive functions to wasm with preloading capabilities injection into browsers.
1. Reborn the accessibility testing in rust.

## Notes

For creating a rust based wasm accessibility runner we have a high surface level of getting 35ms audits [medium](./tests/mock.rs) case
from the fastesdt audits `fast_htmlcs` 200-300ms on a large run. This leads us to the possibility of porting this over
to get the drastic benefits from a re-write.
1 change: 1 addition & 0 deletions kayle_innate/src/engine/rules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// accessibility rules todo:
49 changes: 25 additions & 24 deletions kayle_innate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate lazy_static;
mod utils;
use case_insensitive_string::CaseInsensitiveString;
use std::collections::HashSet;
use utils::{convert_abs_path, convert_base_path, set_panic_hook, domain_name};
use utils::{convert_abs_path, convert_base_path, domain_name, set_panic_hook};
use wasm_bindgen::prelude::*;

#[cfg(feature = "wee_alloc")]
Expand Down Expand Up @@ -130,6 +130,7 @@ 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) {
set_panic_hook();
use std::collections::BTreeMap;

#[wasm_bindgen]
extern "C" {
Expand Down Expand Up @@ -158,50 +159,50 @@ pub fn parse_accessibility_tree(html: &str) {
// The chrome browser we can set to ignore all assets and fetch them here but, it would be re-doing the wheel.
// If we can send the Stylesheets from node to rust this could leverage the sheets attached since we just need the node references.

let mut n = 0;
let t = now();
let mut n = 0;
let mut accessibility_tree: BTreeMap<Option<&str>, Vec<_>> = BTreeMap::new();
let d = select::document::Document::from(html);

// measure select parsing doc 1:1 around 34ms - gets slower when using methods possibly due to clones
while let Some(node) = select::document::Document::from(html).nth(n) {
while let Some(node) = d.nth(n) {
let element_name = node.name();
console_log!("{:?}", element_name);
// console_log!("{:?}", element_name);
accessibility_tree
.entry(element_name)
.and_modify(|n| n.push(node))
.or_insert(Vec::from([node]));
n += 1;
}

console_log!("Select Parser duration {:?}ms", now() - t);
// console_log!("Tree {:?}", accessibility_tree);

let t = now();

// parse doc will start from html downwards
let h = scraper::Html::parse_document(html);
let mut hh = h.tree.nodes();
// accessibility tree for ordered element mappings
let mut accessibility_tree: BTreeMap<&str, Vec<_>> = BTreeMap::new();

// measure select parsing doc 1:1 around 10ms
while let Some(node) = hh.next() {
if let Some(element) = node.value().as_element() {
let element_name = element.name();
console_log!("{:?}", element_name);
// console_log!("{:?}", element_name);
accessibility_tree
.entry(element_name)
.and_modify(|n| n.push(element))
.or_insert(Vec::from([element]));
}
}
// "html"
// "head"
// "title"
// "meta"
// "link"
// "style"
// "body"
// "header"
// "nav"
// "a"
// "a"
// "main"
// "h1"
// "p"
// "input"
// "footer"
// "ul"
// "li"

console_log!("Scraper Parser: duration {:?}ms", now() - t);
console_log!(
"Getting tree links {:?}",
accessibility_tree.get(&"a")
);
// console_log!("Tree {:?}", accessibility_tree);
}

#[wasm_bindgen]
Expand Down
Loading

0 comments on commit a4c16d7

Please sign in to comment.