1use std::borrow::Cow;
2use std::fmt;
3
4use cabin_macros::Attribute;
5
6use crate::html::attributes::WithAttribute;
7
8pub trait Global: WithAttribute {
9 fn access_key(self, access_key: impl Into<Cow<'static, str>>) -> Self::Output<AccessKey> {
12 self.with_attribute(AccessKey(access_key.into()))
13 }
14
15 fn auto_capitalize(self, auto_capitalize: AutoCapitalize) -> Self::Output<AutoCapitalize> {
17 self.with_attribute(auto_capitalize)
18 }
19
20 fn auto_focus(self) -> Self::Output<AutoFocus> {
22 self.with_auto_focus(true)
23 }
24
25 fn with_auto_focus(self, auto_focus: bool) -> Self::Output<AutoFocus> {
27 self.with_attribute(AutoFocus(auto_focus))
28 }
29
30 fn content_editable(self) -> Self::Output<ContentEditable> {
32 self.with_content_editable(true)
33 }
34
35 fn with_content_editable(self, content_editable: bool) -> Self::Output<ContentEditable> {
37 self.with_attribute(ContentEditable(content_editable))
38 }
39
40 fn dir(self, dir: Dir) -> Self::Output<Dir> {
42 self.with_attribute(dir)
43 }
44
45 fn draggable(self) -> Self::Output<Draggable> {
47 self.with_draggable(true)
48 }
49
50 fn with_draggable(self, draggable: bool) -> Self::Output<Draggable> {
52 self.with_attribute(Draggable(draggable))
53 }
54
55 fn enter_key_hint(self, enter_key_hint: EnterKeyHint) -> Self::Output<EnterKeyHint> {
57 self.with_attribute(enter_key_hint)
58 }
59
60 fn hidden(self, hidden: Hidden) -> Self::Output<Hidden> {
62 self.with_attribute(hidden)
63 }
64
65 fn inert(self) -> Self::Output<Inert> {
67 self.with_inert(true)
68 }
69
70 fn with_inert(self, inert: bool) -> Self::Output<Inert> {
72 self.with_attribute(Inert(inert))
73 }
74
75 fn input_mode(self, input_mode: InputMode) -> Self::Output<InputMode> {
77 self.with_attribute(input_mode)
78 }
79
80 fn is(self, is: impl Into<Cow<'static, str>>) -> Self::Output<Is> {
82 self.with_attribute(Is(is.into()))
83 }
84
85 fn item_id(self, item_id: impl Into<Cow<'static, str>>) -> Self::Output<ItemId> {
87 self.with_attribute(ItemId(item_id.into()))
88 }
89
90 fn item_prop(self, item_prop: impl Into<Cow<'static, str>>) -> Self::Output<ItemProp> {
93 self.with_attribute(ItemProp(item_prop.into()))
94 }
95
96 fn item_ref(self, item_ref: impl Into<Cow<'static, str>>) -> Self::Output<ItemRef> {
98 self.with_attribute(ItemRef(item_ref.into()))
99 }
100
101 fn item_scope(self) -> Self::Output<ItemScope> {
104 self.with_item_scope(true)
105 }
106
107 fn with_item_scope(self, item_scope: bool) -> Self::Output<ItemScope> {
110 self.with_attribute(ItemScope(item_scope))
111 }
112
113 fn item_type(self, item_type: impl Into<Cow<'static, str>>) -> Self::Output<ItemType> {
115 self.with_attribute(ItemType(item_type.into()))
116 }
117
118 fn lang(self, lang: impl Into<Cow<'static, str>>) -> Self::Output<Lang> {
120 self.with_attribute(Lang(lang.into()))
121 }
122
123 fn nonce(self, nonce: impl Into<Cow<'static, str>>) -> Self::Output<Nonce> {
126 self.with_attribute(Nonce(nonce.into()))
127 }
128
129 fn popover(self) -> Self::Output<Popover> {
132 self.with_popover(true)
133 }
134
135 fn with_popover(self, popover: bool) -> Self::Output<Popover> {
138 self.with_attribute(Popover(popover))
139 }
140
141 fn slot(self, slot: impl Into<Cow<'static, str>>) -> Self::Output<Slot> {
143 self.with_attribute(Slot(slot.into()))
144 }
145
146 fn spellcheck(self, spellcheck: bool) -> Self::Output<Spellcheck> {
148 self.with_attribute(Spellcheck(spellcheck))
149 }
150
151 fn style(self, style: impl Into<Cow<'static, str>>) -> Self::Output<Style> {
153 self.with_attribute(Style(style.into()))
154 }
155
156 fn tab_index(self, tab_index: TabIndex) -> Self::Output<TabIndex> {
158 self.with_attribute(tab_index)
159 }
160
161 fn title(self, title: impl Into<Cow<'static, str>>) -> Self::Output<Title> {
163 self.with_attribute(Title(title.into()))
164 }
165
166 fn translate(self, translate: bool) -> Self::Output<Translate> {
169 self.with_attribute(Translate(translate))
170 }
171}
172
173#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
176pub struct AccessKey(pub Cow<'static, str>);
177
178#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
180pub struct AutoFocus(pub bool);
181
182#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
184pub struct ContentEditable(pub bool);
185
186#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
188pub struct Draggable(pub bool);
189
190#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
192pub struct Inert(pub bool);
193
194#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
196pub struct Is(pub Cow<'static, str>);
197
198#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
200pub struct ItemId(pub Cow<'static, str>);
201
202#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
205pub struct ItemProp(pub Cow<'static, str>);
206
207#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
209pub struct ItemRef(pub Cow<'static, str>);
210
211#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
214pub struct ItemScope(pub bool);
215
216#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
218pub struct ItemType(pub Cow<'static, str>);
219
220#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
222pub struct Lang(pub Cow<'static, str>);
223
224#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
227pub struct Nonce(pub Cow<'static, str>);
228
229#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
232pub struct Popover(pub bool);
233
234#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
236pub struct Slot(pub Cow<'static, str>);
237
238#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
240pub struct Spellcheck(pub bool);
241
242#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
244pub struct Style(pub Cow<'static, str>);
245
246#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
248pub struct Title(pub Cow<'static, str>);
249
250#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
252pub enum AutoCapitalize {
253 #[default]
255 None,
256
257 Sentences,
259
260 Words,
262
263 Characters,
265}
266
267impl fmt::Display for AutoCapitalize {
268 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
269 match self {
270 Self::None => f.write_str("none"),
271 Self::Sentences => f.write_str("sentences"),
272 Self::Words => f.write_str("words"),
273 Self::Characters => f.write_str("characters"),
274 }
275 }
276}
277
278#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
280pub enum Dir {
281 Ltr,
283
284 Rtl,
286
287 Auto,
289}
290
291impl fmt::Display for Dir {
292 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
293 match self {
294 Self::Ltr => f.write_str("ltr"),
295 Self::Rtl => f.write_str("rtl"),
296 Self::Auto => f.write_str("auto"),
297 }
298 }
299}
300
301#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
303pub enum EnterKeyHint {
304 Enter,
306
307 Done,
309
310 Go,
312
313 Next,
315
316 Previous,
318
319 Search,
321
322 Send,
324}
325
326impl fmt::Display for EnterKeyHint {
327 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
328 match self {
329 Self::Enter => f.write_str("enter"),
330 Self::Done => f.write_str("done"),
331 Self::Go => f.write_str("go"),
332 Self::Next => f.write_str("next"),
333 Self::Previous => f.write_str("previous"),
334 Self::Search => f.write_str("search"),
335 Self::Send => f.write_str("send"),
336 }
337 }
338}
339
340#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
342pub enum Hidden {
343 Hidden,
345
346 UntilFound,
348}
349
350impl fmt::Display for Hidden {
351 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
352 match self {
353 Self::Hidden => f.write_str("hidden"),
354 Self::UntilFound => f.write_str("until-found"),
355 }
356 }
357}
358
359#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
361pub enum InputMode {
362 None,
364
365 Text,
367
368 Tel,
370
371 Url,
373
374 Email,
376
377 Numeric,
379
380 Decimal,
382
383 Search,
385}
386
387impl fmt::Display for InputMode {
388 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
389 match self {
390 Self::None => f.write_str("none"),
391 Self::Text => f.write_str("text"),
392 Self::Tel => f.write_str("tel"),
393 Self::Url => f.write_str("url"),
394 Self::Email => f.write_str("email"),
395 Self::Numeric => f.write_str("numeric"),
396 Self::Decimal => f.write_str("decimal"),
397 Self::Search => f.write_str("search"),
398 }
399 }
400}
401
402#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
404pub enum TabIndex {
405 Skip,
407
408 Order(u32),
411}
412
413impl fmt::Display for TabIndex {
414 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
415 match self {
416 Self::Skip => f.write_str("-1"),
417 Self::Order(order) => order.fmt(f),
418 }
419 }
420}
421
422#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Attribute)]
423#[attribute(outer)]
424pub struct Translate(bool);
425
426impl fmt::Display for Translate {
427 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
428 if !self.0 {
429 f.write_str("no")?;
430 }
431 Ok(())
432 }
433}