use std::collections::HashSet;
use std::sync::LazyLock;
use syn::parse::{Parse, ParseStream};
use super::{Prop, Props, SpecialProps};
pub struct ElementProps {
pub attributes: Vec<Prop>,
pub listeners: Vec<Prop>,
pub classes: Option<Prop>,
pub booleans: Vec<Prop>,
pub value: Option<Prop>,
pub defaultvalue: Option<Prop>,
pub checked: Option<Prop>,
pub special: SpecialProps,
}
impl Parse for ElementProps {
fn parse(input: ParseStream) -> syn::Result<Self> {
let mut props = input.parse::<Props>()?;
let listeners =
props.drain_filter(|prop| LISTENER_SET.contains(prop.label.to_string().as_str()));
props.check_no_duplicates()?;
let booleans =
props.drain_filter(|prop| BOOLEAN_SET.contains(prop.label.to_string().as_str()));
let classes = props.pop("class");
let value = props.pop("value");
let checked = props.pop("checked");
let defaultvalue = props.pop("defaultvalue");
let special = props.special;
Ok(Self {
attributes: props.prop_list.into_vec(),
classes,
listeners: listeners.into_vec(),
checked,
booleans: booleans.into_vec(),
value,
special,
defaultvalue,
})
}
}
static BOOLEAN_SET: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
[
"allowfullscreen",
"async",
"autofocus",
"autoplay",
"controls",
"default",
"defer",
"disabled",
"formnovalidate",
"hidden",
"inert",
"ismap",
"itemscope",
"loop",
"multiple",
"muted",
"nomodule",
"novalidate",
"open",
"playsinline",
"readonly",
"required",
"reversed",
"selected",
"truespeed",
"webkitdirectory",
]
.into()
});
static LISTENER_SET: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
[
"onabort",
"onauxclick",
"onblur",
"oncancel",
"oncanplay",
"oncanplaythrough",
"onchange",
"onclick",
"onclose",
"oncontextmenu",
"oncuechange",
"ondblclick",
"ondrag",
"ondragend",
"ondragenter",
"ondragexit",
"ondragleave",
"ondragover",
"ondragstart",
"ondrop",
"ondurationchange",
"onemptied",
"onended",
"onerror",
"onfocus",
"onfocusin",
"onfocusout",
"onformdata",
"oninput",
"oninvalid",
"onkeydown",
"onkeypress",
"onkeyup",
"onload",
"onloadeddata",
"onloadedmetadata",
"onloadstart",
"onmousedown",
"onmouseenter",
"onmouseleave",
"onmousemove",
"onmouseout",
"onmouseover",
"onmouseup",
"onpause",
"onplay",
"onplaying",
"onprogress",
"onratechange",
"onreset",
"onresize",
"onscroll",
"onsecuritypolicyviolation",
"onseeked",
"onseeking",
"onselect",
"onslotchange",
"onstalled",
"onsubmit",
"onsuspend",
"ontimeupdate",
"ontoggle",
"onvolumechange",
"onwaiting",
"onwheel",
"oncopy",
"oncut",
"onpaste",
"onanimationcancel",
"onanimationend",
"onanimationiteration",
"onanimationstart",
"ongotpointercapture",
"onloadend",
"onlostpointercapture",
"onpointercancel",
"onpointerdown",
"onpointerenter",
"onpointerleave",
"onpointerlockchange",
"onpointerlockerror",
"onpointermove",
"onpointerout",
"onpointerover",
"onpointerup",
"onselectionchange",
"onselectstart",
"onshow",
"ontouchcancel",
"ontouchend",
"ontouchmove",
"ontouchstart",
"ontransitioncancel",
"ontransitionend",
"ontransitionrun",
"ontransitionstart",
]
.into()
});