1#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum Kind {
4 Text,
5 Attribute(&'static str),
6 Click,
7 Children,
8 Range,
9 Class(&'static str, bool),
10}
11#[derive(Clone, Debug, PartialEq, Eq)]
12pub struct Error(pub &'static str);
13impl std::fmt::Display for Error {
14 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15 f.write_str(self.0)
16 }
17}
18impl std::error::Error for Error {}
19
20pub(crate) fn attribute(name: &str) -> bool {
21 matches!(
22 name,
23 "id" | "class" | "role" | "title" | "disabled" | "type"
24 ) || name.starts_with("aria-")
25}
26pub(crate) fn class_token(token: &str) -> bool {
27 !token.is_empty()
28 && token.len() <= 128
29 && token
30 .bytes()
31 .all(|b| b.is_ascii_alphanumeric() || matches!(b, b'-' | b'_'))
32}
33pub(crate) fn context(parent: Option<&str>, child: &str, in_button: bool) -> bool {
34 matches!(
35 child,
36 "div" | "span" | "button" | "a" | "h1" | "table" | "tbody" | "tr" | "td"
37 ) && !(in_button && matches!(child, "button" | "a"))
38 && match parent {
39 Some("table") => child == "tbody",
40 Some("tbody") => child == "tr",
41 Some("tr") => child == "td",
42 Some("span" | "button" | "a" | "h1") => child == "span",
43 _ => !matches!(child, "tbody" | "tr" | "td") || parent.is_none(),
44 }
45}