diff --git a/Cargo.lock b/Cargo.lock index 81077d0..8e3e62d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,7 +10,7 @@ dependencies = [ "accessibility-tree", "cssparser", "ego-tree", - "getrandom", + "getrandom 0.2.10", "lazy_static", "markup5ever", "maud", @@ -18,7 +18,7 @@ dependencies = [ "selectors", "serde", "slotmap", - "smallvec 1.11.1", + "smallvec", "strum", "strum_macros", "taffy", @@ -36,7 +36,7 @@ dependencies = [ "indexmap 2.0.2", "once_cell", "selectors", - "smallvec 0.6.14", + "smallvec", "tendril", ] @@ -58,7 +58,7 @@ dependencies = [ "rayon_croissant", "selectors", "smallbitvec", - "smallvec 1.11.1", + "smallvec", "victor-tree-internal-proc-macros", "xi-unicode", "xml-rs", @@ -86,7 +86,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" dependencies = [ "cfg-if", - "getrandom", + "getrandom 0.2.10", "once_cell", "version_check", ] @@ -150,15 +150,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -311,13 +302,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] -name = "cloudabi" -version = "0.0.3" +name = "convert_case" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags 1.3.2", -] +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "criterion" @@ -374,7 +362,7 @@ version = "0.9.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cfg-if", "crossbeam-utils", "memoffset", @@ -392,33 +380,41 @@ dependencies = [ [[package]] name = "cssparser" -version = "0.25.9" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbe18ca4efb9ba3716c6da66cc3d7e673bf59fa576353011f48c4cfddbdd740e" +checksum = "754b69d351cdc2d8ee09ae203db831e005560fc6030da058f86ad60c92a9cb0a" dependencies = [ - "autocfg 0.1.8", "cssparser-macros", "dtoa-short", "itoa 0.4.8", "matches", - "phf 0.7.24", + "phf 0.8.0", "proc-macro2 1.0.69", - "procedural-masquerade", "quote 1.0.33", - "smallvec 0.6.14", + "smallvec", "syn 1.0.109", ] [[package]] name = "cssparser-macros" -version = "0.3.6" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote 1.0.33", + "syn 2.0.38", +] + +[[package]] +name = "derive_more" +version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bb1c84e87c717666564ec056105052331431803d606bd45529b28547b611eef" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ - "phf_codegen 0.7.24", + "convert_case", "proc-macro2 1.0.69", - "procedural-masquerade", "quote 1.0.33", + "rustc_version", "syn 1.0.109", ] @@ -498,12 +494,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "futf" version = "0.1.5" @@ -593,6 +583,17 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.2.10" @@ -602,7 +603,7 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "wasm-bindgen", ] @@ -724,7 +725,7 @@ version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ - "autocfg 1.1.0", + "autocfg", "hashbrown 0.12.3", ] @@ -818,7 +819,7 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" dependencies = [ - "autocfg 1.1.0", + "autocfg", "scopeguard 1.2.0", ] @@ -876,12 +877,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - [[package]] name = "memchr" version = "2.6.4" @@ -894,7 +889,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -939,7 +934,7 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -982,17 +977,19 @@ dependencies = [ "cfg-if", "libc", "redox_syscall", - "smallvec 1.11.1", + "smallvec", "windows-targets", ] [[package]] name = "phf" -version = "0.7.24" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18" +checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12" dependencies = [ - "phf_shared 0.7.24", + "phf_macros", + "phf_shared 0.8.0", + "proc-macro-hack", ] [[package]] @@ -1006,12 +1003,12 @@ dependencies = [ [[package]] name = "phf_codegen" -version = "0.7.24" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e" +checksum = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815" dependencies = [ - "phf_generator 0.7.24", - "phf_shared 0.7.24", + "phf_generator 0.8.0", + "phf_shared 0.8.0", ] [[package]] @@ -1026,12 +1023,12 @@ dependencies = [ [[package]] name = "phf_generator" -version = "0.7.24" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09364cc93c159b8b06b1f4dd8a4398984503483891b0c26b867cf431fb132662" +checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" dependencies = [ - "phf_shared 0.7.24", - "rand 0.6.5", + "phf_shared 0.8.0", + "rand 0.7.3", ] [[package]] @@ -1044,13 +1041,27 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "phf_macros" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6fde18ff429ffc8fe78e2bf7f8b7a5a5a6e2a8b58bc5a9ac69198bbda9189c" +dependencies = [ + "phf_generator 0.8.0", + "phf_shared 0.8.0", + "proc-macro-hack", + "proc-macro2 1.0.69", + "quote 1.0.33", + "syn 1.0.109", +] + [[package]] name = "phf_shared" -version = "0.7.24" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "234f71a15de2288bcb7e3b6515828d22af7ec8598ee6d24c3b526fa0a80b67a0" +checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" dependencies = [ - "siphasher 0.2.3", + "siphasher", ] [[package]] @@ -1059,7 +1070,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" dependencies = [ - "siphasher 0.3.11", + "siphasher", ] [[package]] @@ -1138,6 +1149,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.20+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" + [[package]] name = "proc-macro2" version = "0.4.30" @@ -1156,12 +1173,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "procedural-masquerade" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1383dff4092fe903ac180e391a8d4121cc48f08ccf850614b0290c6673b69d" - [[package]] name = "quote" version = "0.6.13" @@ -1182,21 +1193,16 @@ dependencies = [ [[package]] name = "rand" -version = "0.6.5" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "autocfg 0.1.8", + "getrandom 0.1.16", "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", + "rand_chacha 0.2.2", + "rand_core 0.5.1", "rand_hc", - "rand_isaac", - "rand_jitter", - "rand_os", "rand_pcg", - "rand_xorshift", - "winapi", ] [[package]] @@ -1212,12 +1218,12 @@ dependencies = [ [[package]] name = "rand_chacha" -version = "0.1.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ - "autocfg 0.1.8", - "rand_core 0.3.1", + "ppv-lite86", + "rand_core 0.5.1", ] [[package]] @@ -1232,88 +1238,38 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.3.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "rand_core 0.4.2", + "getrandom 0.1.16", ] -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.10", ] [[package]] name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi", -] - -[[package]] -name = "rand_os" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi", + "rand_core 0.5.1", ] [[package]] name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" dependencies = [ - "rand_core 0.3.1", + "rand_core 0.5.1", ] [[package]] @@ -1346,15 +1302,6 @@ dependencies = [ "rayon", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.3.5" @@ -1474,6 +1421,15 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.38.19" @@ -1522,23 +1478,30 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "selectors" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b86b100bede4f651059740afc3b6cb83458d7401cb7c1ad96d8a11e91742c86" +checksum = "df320f1889ac4ba6bc0cdc9c9af7af4bd64bb927bccdf32d81140dc1f9be12fe" dependencies = [ "bitflags 1.3.2", "cssparser", + "derive_more", "fxhash", "log", "matches", - "phf 0.7.24", - "phf_codegen 0.7.24", + "phf 0.8.0", + "phf_codegen 0.8.0", "precomputed-hash", "servo_arc", - "smallvec 0.6.14", + "smallvec", "thin-slice", ] +[[package]] +name = "semver" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" + [[package]] name = "serde" version = "1.0.188" @@ -1601,12 +1564,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "siphasher" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" - [[package]] name = "siphasher" version = "0.3.11" @@ -1628,15 +1585,6 @@ version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75ce4f9dc4a41b4c3476cc925f1efb11b66df373a8fde5d4b8915fa91b5d995e" -[[package]] -name = "smallvec" -version = "0.6.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0" -dependencies = [ - "maybe-uninit", -] - [[package]] name = "smallvec" version = "1.11.1" @@ -1890,6 +1838,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index cfba4ba..9e1cfb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ members = [ [workspace.dependencies] smallvec = "1" -selectors = "0.21.0" -cssparser = "0.25.0" +selectors = "0.22.0" +cssparser = "0.27.0" html5ever = "0.26" ego-tree = "0.6.2" lazy_static = "1.4" diff --git a/accessibility-rs/src/engine/rules/utils/nodes.rs b/accessibility-rs/src/engine/rules/utils/nodes.rs index a466149..b229ce5 100644 --- a/accessibility-rs/src/engine/rules/utils/nodes.rs +++ b/accessibility-rs/src/engine/rules/utils/nodes.rs @@ -97,7 +97,7 @@ pub fn get_unique_selector(ele: &ElementRef<'_>) -> String { let node_name = ele.value().name(); if selector.is_empty() && ele.has_attribute("class") { - let node_selector = node_name.to_string() + &ele.local_name().to_string(); + let node_selector = node_name.to_string() + &ele.value().local_name.to_string(); let only_selector = single_selector(ele, &node_selector); if only_selector { selector = node_selector; diff --git a/accessibility-rs/tests/integration_test.rs b/accessibility-rs/tests/integration_test.rs index 5fe7141..df544c4 100644 --- a/accessibility-rs/tests/integration_test.rs +++ b/accessibility-rs/tests/integration_test.rs @@ -6,10 +6,11 @@ use mocks::mock; #[test] fn _audit() { - let _ = accessibility_rs::audit(AuditConfig::new( + let report = accessibility_rs::audit(AuditConfig::new( mock::MOCK_WEBSITE_HTML, &mock::MOCK_CSS_RULES, false, "en", )); + println!("{:?}", report) } diff --git a/accessibility-scraper/Cargo.toml b/accessibility-scraper/Cargo.toml index 76c19a2..1db7f66 100644 --- a/accessibility-scraper/Cargo.toml +++ b/accessibility-scraper/Cargo.toml @@ -20,7 +20,7 @@ cssparser = { workspace = true } ego-tree = { workspace = true } html5ever = { workspace = true } selectors = { workspace = true } -smallvec = "0.6.14" +smallvec = "1" tendril = "0.4.3" ahash = "0.8" indexmap = { version = "2.0.0", optional = true } diff --git a/accessibility-scraper/src/element_ref/element.rs b/accessibility-scraper/src/element_ref/element.rs index 329b2a4..de4102d 100644 --- a/accessibility-scraper/src/element_ref/element.rs +++ b/accessibility-scraper/src/element_ref/element.rs @@ -1,22 +1,48 @@ -use html5ever::Namespace; +use super::ElementRef; +use crate::selector::{CssLocalName, CssString, NonTSPseudoClass, PseudoElement, Simple}; +use html5ever::{LocalName, Namespace}; use selectors::{ attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint}, matching, Element, OpaqueElement, }; -use super::ElementRef; -use crate::selector::{CssLocalName, CssString, NonTSPseudoClass, PseudoElement, Simple}; - /// Note: will never match against non-tree-structure pseudo-classes. impl<'a> Element for ElementRef<'a> { type Impl = Simple; - fn local_name(&self) -> &::BorrowedLocalName { - &self.value().local_name + #[inline] + fn is_part(&self, _name: &LocalName) -> bool { + false + } + + #[inline] + fn imported_part(&self, _: &LocalName) -> Option { + None } - fn namespace(&self) -> &Namespace { - &self.value().name.ns + #[inline] + fn exported_part(&self, _: &LocalName) -> Option { + None + } + + #[inline] + fn is_same_type(&self, other: &Self) -> bool { + self.value().name == other.value().name + } + + #[inline] + fn is_pseudo_element(&self) -> bool { + false + } + + #[inline] + fn has_local_name(&self, name: &CssLocalName) -> bool { + self.value().name.local == *name.0 + } + + #[inline] + fn has_namespace(&self, namespace: &Namespace) -> bool { + &self.value().name.ns == *&namespace } fn opaque(&self) -> OpaqueElement { @@ -35,22 +61,6 @@ impl<'a> Element for ElementRef<'a> { None } - // fn is_pseudo_element(&self) -> bool { - // false - // } - - // fn is_part(&self, _name: &CssLocalName) -> bool { - // false - // } - - // fn is_same_type(&self, other: &Self) -> bool { - // self.value().name == other.value().name - // } - - // fn imported_part(&self, _: &CssLocalName) -> Option { - // None - // } - fn prev_sibling_element(&self) -> Option { self.prev_siblings() .find(|sibling| sibling.value().is_element()) @@ -63,25 +73,11 @@ impl<'a> Element for ElementRef<'a> { .map(ElementRef::new) } - // fn first_element_child(&self) -> Option { - // self.children() - // .find(|child| child.value().is_element()) - // .map(ElementRef::new) - // } - fn is_html_element_in_html_document(&self) -> bool { // FIXME: Is there more to this? self.value().name.ns == ns!(html) } - // fn has_local_name(&self, name: &CssLocalName) -> bool { - // self.value().name.local == name.0 - // } - - // fn has_namespace(&self, namespace: &Namespace) -> bool { - // &self.value().name.ns == namespace - // } - fn attr_matches( &self, ns: &NamespaceConstraint<&Namespace>, @@ -104,7 +100,21 @@ impl<'a> Element for ElementRef<'a> { where F: FnMut(&Self, selectors::matching::ElementSelectorFlags), { - match *pseudo_class {} + use self::NonTSPseudoClass::*; + + match *pseudo_class { + Active | Focus | Hover | Enabled | Disabled | Checked | Indeterminate | Visited => { + false + } + AnyLink | Link => { + self.value().name.ns == ns!(html) + && matches!( + self.value().name.local, + local_name!("a") | local_name!("area") | local_name!("link") + ) + && self.has_attribute("href") + } + } } fn match_pseudo_element( diff --git a/accessibility-scraper/src/element_ref/mod.rs b/accessibility-scraper/src/element_ref/mod.rs index 2757ae8..8a45718 100644 --- a/accessibility-scraper/src/element_ref/mod.rs +++ b/accessibility-scraper/src/element_ref/mod.rs @@ -20,11 +20,13 @@ pub struct ElementRef<'a> { impl<'a> ElementRef<'a> { /// Create a new element reference + #[inline] pub fn new(node: NodeRef<'a, Node>) -> Self { ElementRef { node } } /// Wraps a `NodeRef` only if it references a `Node::Element`. + #[inline] pub fn wrap(node: NodeRef<'a, Node>) -> Option { if node.value().is_element() { Some(ElementRef::new(node)) @@ -34,11 +36,13 @@ impl<'a> ElementRef<'a> { } /// Returns the `Element` referenced by `self`. + #[inline] pub fn value(&self) -> &'a Element { self.node.value().as_element().unwrap() } /// Returns an iterator over descendent elements matching a selector. + #[inline] pub fn select<'b>(&self, selector: &'b Selector) -> Select<'a, 'b> { let mut inner = self.traverse(); inner.next(); // Skip Edge::Open(self). @@ -72,6 +76,7 @@ impl<'a> ElementRef<'a> { } /// Returns the value of an attribute. + #[inline] pub fn attr(&self, attr: &str) -> Option<&str> { self.value().attr(attr) } @@ -84,6 +89,7 @@ impl<'a> ElementRef<'a> { } /// Returns if the element has the attibute and not empty + #[inline] pub fn has_attribute(&self, attr: &str) -> bool { match self.attr(attr) { Some(val) => !val.trim().is_empty(), diff --git a/accessibility-scraper/src/selector.rs b/accessibility-scraper/src/selector.rs index 5c6d8c0..f3b7637 100644 --- a/accessibility-scraper/src/selector.rs +++ b/accessibility-scraper/src/selector.rs @@ -76,6 +76,7 @@ impl parser::SelectorImpl for Simple { type Identifier = CssLocalName; type ClassName = CssLocalName; type LocalName = CssLocalName; + type PartName = LocalName; type NamespacePrefix = CssLocalName; type NamespaceUrl = Namespace; type BorrowedNamespaceUrl = Namespace; @@ -145,19 +146,41 @@ impl cssparser::ToCss for CssLocalName { } /// Non Tree-Structural Pseudo-Class. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum NonTSPseudoClass {} +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum NonTSPseudoClass { + /// any link + AnyLink, + /// a link + Link, + /// a visited link + Visited, + /// a active element + Active, + /// a focused element + Focus, + /// a element that is hovered + Hover, + /// a element that has enabled checked + Enabled, + /// a element that has disabled prop + Disabled, + /// a element that has the checked property + Checked, + /// an indeterminate element + Indeterminate, +} impl parser::NonTSPseudoClass for NonTSPseudoClass { type Impl = Simple; - fn is_active_or_hover(&self) -> bool { false } - - // fn is_user_action_state(&self) -> bool { - // false - // } + fn is_user_action_state(&self) -> bool { + false + } + fn has_zero_specificity(&self) -> bool { + false + } } impl cssparser::ToCss for NonTSPseudoClass { @@ -165,7 +188,18 @@ impl cssparser::ToCss for NonTSPseudoClass { where W: fmt::Write, { - dest.write_str("") + dest.write_str(match *self { + NonTSPseudoClass::AnyLink => ":any-link", + NonTSPseudoClass::Link => ":link", + NonTSPseudoClass::Visited => ":visited", + NonTSPseudoClass::Active => ":active", + NonTSPseudoClass::Focus => ":focus", + NonTSPseudoClass::Hover => ":hover", + NonTSPseudoClass::Enabled => ":enabled", + NonTSPseudoClass::Disabled => ":disabled", + NonTSPseudoClass::Checked => ":checked", + NonTSPseudoClass::Indeterminate => ":indeterminate", + }) } } diff --git a/accessibility-tree/victor/src/style/properties/definitions.rs b/accessibility-tree/victor/src/style/properties/definitions.rs index ad414d2..7bff340 100644 --- a/accessibility-tree/victor/src/style/properties/definitions.rs +++ b/accessibility-tree/victor/src/style/properties/definitions.rs @@ -1,6 +1,12 @@ use crate::style::values::*; use cssparser::{Color, RGBA}; +type FourSidesAuto = FourSides; +type FourSidesAutoPercentage = FourSides; +type FourSidesLineStyle = FourSides; +type FourSidesColor = FourSides; +type FourSidesLineWidth = FourSides; + properties! { type Discriminant = u8; @@ -61,31 +67,31 @@ properties! { } @shorthands { - "margin" => FourSides { + "margin" => FourSidesAuto { top: margin_top, left: margin_left, bottom: margin_bottom, right: margin_right, } - "padding" => FourSides { + "padding" => FourSidesAutoPercentage { top: padding_top, left: padding_left, bottom: padding_bottom, right: padding_right, } - "border-style" => FourSides { + "border-style" => FourSidesLineStyle { top: border_top_style, left: border_left_style, bottom: border_bottom_style, right: border_right_style, } - "border-color" => FourSides { + "border-color" => FourSidesColor { top: border_top_color, left: border_left_color, bottom: border_bottom_color, right: border_right_color, } - "border-width" => FourSides { + "border-width" => FourSidesLineWidth { top: border_top_width, left: border_left_width, bottom: border_bottom_width, diff --git a/accessibility-tree/victor/src/style/selectors.rs b/accessibility-tree/victor/src/style/selectors.rs index bf54aa4..0c63e89 100644 --- a/accessibility-tree/victor/src/style/selectors.rs +++ b/accessibility-tree/victor/src/style/selectors.rs @@ -3,7 +3,7 @@ use crate::style::errors::RuleParseErrorKind; use accessibility_scraper::selector::CssLocalName; use accessibility_scraper::selector::Simple; use cssparser::ToCss; -use html5ever::Namespace; +use html5ever::{LocalName, Namespace}; use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint}; use selectors::context::{MatchingContext, MatchingMode, QuirksMode}; use selectors::matching::{matches_selector, ElementSelectorFlags}; @@ -39,6 +39,12 @@ impl selectors::parser::NonTSPseudoClass for PseudoClass { fn is_active_or_hover(&self) -> bool { match *self {} } + fn is_user_action_state(&self) -> bool { + false + } + fn has_zero_specificity(&self) -> bool { + false + } } impl<'i> selectors::parser::Parser<'i> for Parser { @@ -84,6 +90,21 @@ impl<'a> NodeRef<'a> { fn node(self) -> &'a Node { &self.document[self.node] } + /// Returns the `Element` referenced by `self`. + pub fn value(&self) -> &crate::dom::ElementData { + self.node().as_element().unwrap() + } + /// Returns the value of an attribute. + pub fn attr(&self, attr: &str) -> Option<&str> { + self.value().get_attr(&LocalName::from(attr)) + } + /// Returns if the element has the attibute and not empty + pub fn has_attribute(&self, attr: &str) -> bool { + match self.attr(attr) { + Some(val) => !val.trim().is_empty(), + None => false, + } + } } fn find_element<'a, F>( @@ -106,6 +127,11 @@ where impl<'a> selectors::Element for NodeRef<'a> { type Impl = Simple; + #[inline] + fn is_part(&self, _name: &LocalName) -> bool { + false + } + fn opaque(&self) -> selectors::OpaqueElement { selectors::OpaqueElement::new::(self.node()) } @@ -135,12 +161,34 @@ impl<'a> selectors::Element for NodeRef<'a> { self.node().as_element().unwrap().name.ns == ns!(html) && self.node().in_html_document() } - fn local_name(&self) -> &accessibility_scraper::selector::CssLocalName { - &self.node().as_element().unwrap().css_local_name + #[inline] + fn imported_part(&self, _: &LocalName) -> Option { + None } - fn namespace(&self) -> &Namespace { - &self.node().as_element().unwrap().name.ns + #[inline] + fn exported_part(&self, _: &LocalName) -> Option { + None + } + + #[inline] + fn is_same_type(&self, other: &Self) -> bool { + self.value().name == other.value().name + } + + #[inline] + fn is_pseudo_element(&self) -> bool { + false + } + + #[inline] + fn has_local_name(&self, name: &CssLocalName) -> bool { + self.value().name.local == *name.0 + } + + #[inline] + fn has_namespace(&self, namespace: &Namespace) -> bool { + &self.value().name.ns == *&namespace } fn is_html_slot_element(&self) -> bool { @@ -180,7 +228,21 @@ impl<'a> selectors::Element for NodeRef<'a> { where F: FnMut(&Self, ElementSelectorFlags), { - match *pseudo_class {} + use accessibility_scraper::selector::NonTSPseudoClass::*; + + match *pseudo_class { + Active | Focus | Hover | Enabled | Disabled | Checked | Indeterminate | Visited => { + false + } + AnyLink | Link => { + self.value().name.ns == ns!(html) + && matches!( + self.value().name.local, + local_name!("a") | local_name!("area") | local_name!("link") + ) + && self.has_attribute("href") + } + } } fn match_pseudo_element( diff --git a/benches/audit.rs b/benches/audit.rs index b749ec1..8af8182 100644 --- a/benches/audit.rs +++ b/benches/audit.rs @@ -9,27 +9,15 @@ pub fn bench_speed(c: &mut Criterion) { group.sample_size(50); group.bench_function(format!("audit: {}", "small html"), |b| { - b.iter(|| { - black_box( - audit(AuditConfig::basic(mock::MOCK_WEBSITE_SMALL_HTML)), - ) - }) + b.iter(|| black_box(audit(AuditConfig::basic(mock::MOCK_WEBSITE_SMALL_HTML)))) }); group.bench_function(format!("audit: {}", "medium html"), |b| { - b.iter(|| { - black_box( - audit(AuditConfig::basic(mock::MOCK_WEBSITE_A11YWATCH_HTML)), - ) - }) + b.iter(|| black_box(audit(AuditConfig::basic(mock::MOCK_WEBSITE_A11YWATCH_HTML)))) }); group.bench_function(format!("audit: {}", "medium-large html"), |b| { - b.iter(|| { - black_box( - audit(AuditConfig::basic(mock::MOCK_WEBSITE_HTML)), - ) - }) + b.iter(|| black_box(audit(AuditConfig::basic(mock::MOCK_WEBSITE_HTML)))) }); group.finish(); diff --git a/benches/mock.rs b/benches/mock.rs index 4fb7c79..d28fd6a 100644 --- a/benches/mock.rs +++ b/benches/mock.rs @@ -7,6 +7,3 @@ pub static MOCK_WEBSITE_A11YWATCH_HTML: &'static str = r###" Jeff Mendez - Software Engineer

My name Jeff

Hi, my name is Jeff Mendez and I am software engineer residing in Florida.

Checkout A11yWatch to improve your web inclusion.

Use the website accessibility checker for free to evaluate your page.

Blog posts

You can view some of my blog content at A11yWatch Blog.

Open Source Work

One of the main projects I contribute to the OSS community is Spider which is the fastest web crawler to gather data. It is a huge foundation block for A11yWatch allowing audits to be done at impressive speeds concurrently.

Github
"###; - - -