1use std::collections::HashSet;
2
3use once_cell::sync::Lazy;
4use syn::parse::{Parse, ParseStream};
5
6use super::{Prop, Props, SpecialProps};
7
8pub struct ElementProps {
9 pub attributes: Vec<Prop>,
10 pub listeners: Vec<Prop>,
11 pub classes: Option<Prop>,
12 pub booleans: Vec<Prop>,
13 pub value: Option<Prop>,
14 pub defaultvalue: Option<Prop>,
15 pub checked: Option<Prop>,
16 pub special: SpecialProps,
17}
18
19impl Parse for ElementProps {
20 fn parse(input: ParseStream) -> syn::Result<Self> {
21 let mut props = input.parse::<Props>()?;
22
23 let listeners =
24 props.drain_filter(|prop| LISTENER_SET.contains(prop.label.to_string().as_str()));
25
26 props.check_no_duplicates()?;
28
29 let booleans =
30 props.drain_filter(|prop| BOOLEAN_SET.contains(prop.label.to_string().as_str()));
31
32 let classes = props.pop("class");
33 let value = props.pop("value");
34 let checked = props.pop("checked");
35 let defaultvalue = props.pop("defaultvalue");
36 let special = props.special;
37
38 Ok(Self {
39 attributes: props.prop_list.into_vec(),
40 classes,
41 listeners: listeners.into_vec(),
42 checked,
43 booleans: booleans.into_vec(),
44 value,
45 special,
46 defaultvalue,
47 })
48 }
49}
50
51static BOOLEAN_SET: Lazy<HashSet<&'static str>> = Lazy::new(|| {
52 [
53 "allowfullscreen",
58 "async",
59 "autofocus",
60 "autoplay",
61 "controls",
62 "default",
63 "defer",
64 "disabled",
65 "formnovalidate",
66 "hidden",
67 "inert",
68 "ismap",
69 "itemscope",
70 "loop",
71 "multiple",
72 "muted",
73 "nomodule",
74 "novalidate",
75 "open",
76 "playsinline",
77 "readonly",
78 "required",
79 "reversed",
80 "selected",
81 "truespeed",
82 "webkitdirectory",
84 ]
85 .into()
86});
87
88static LISTENER_SET: Lazy<HashSet<&'static str>> = Lazy::new(|| {
89 [
90 "onabort",
93 "onauxclick",
94 "onblur",
95 "oncancel",
96 "oncanplay",
97 "oncanplaythrough",
98 "onchange",
99 "onclick",
100 "onclose",
101 "oncontextmenu",
102 "oncuechange",
103 "ondblclick",
104 "ondrag",
105 "ondragend",
106 "ondragenter",
107 "ondragexit",
108 "ondragleave",
109 "ondragover",
110 "ondragstart",
111 "ondrop",
112 "ondurationchange",
113 "onemptied",
114 "onended",
115 "onerror",
116 "onfocus",
117 "onfocusin",
120 "onfocusout",
121 "onformdata",
122 "oninput",
123 "oninvalid",
124 "onkeydown",
125 "onkeypress",
126 "onkeyup",
127 "onload",
128 "onloadeddata",
129 "onloadedmetadata",
130 "onloadstart",
131 "onmousedown",
132 "onmouseenter",
133 "onmouseleave",
134 "onmousemove",
135 "onmouseout",
136 "onmouseover",
137 "onmouseup",
138 "onpause",
139 "onplay",
140 "onplaying",
141 "onprogress",
142 "onratechange",
143 "onreset",
144 "onresize",
145 "onscroll",
146 "onsecuritypolicyviolation",
147 "onseeked",
148 "onseeking",
149 "onselect",
150 "onslotchange",
151 "onstalled",
152 "onsubmit",
153 "onsuspend",
154 "ontimeupdate",
155 "ontoggle",
156 "onvolumechange",
157 "onwaiting",
158 "onwheel",
159 "oncopy",
162 "oncut",
163 "onpaste",
164 "onanimationcancel",
167 "onanimationend",
168 "onanimationiteration",
169 "onanimationstart",
170 "ongotpointercapture",
171 "onloadend",
172 "onlostpointercapture",
173 "onpointercancel",
174 "onpointerdown",
175 "onpointerenter",
176 "onpointerleave",
177 "onpointerlockchange",
178 "onpointerlockerror",
179 "onpointermove",
180 "onpointerout",
181 "onpointerover",
182 "onpointerup",
183 "onselectionchange",
184 "onselectstart",
185 "onshow",
186 "ontouchcancel",
187 "ontouchend",
188 "ontouchmove",
189 "ontouchstart",
190 "ontransitioncancel",
191 "ontransitionend",
192 "ontransitionrun",
193 "ontransitionstart",
194 ]
195 .into()
196});