1pub mod element {
2 #[doc(alias = "style")]
6 #[non_exhaustive]
7 #[derive(PartialEq, Clone, Default)]
8 pub struct Style {
9 sys: html_sys::metadata::Style,
10 children: Vec<super::child::StyleChild>,
11 }
12 impl Style {
13 pub fn builder() -> super::builder::StyleBuilder {
15 super::builder::StyleBuilder::new(Default::default())
16 }
17 }
18 impl Style {
19 pub fn data_map(&self) -> &html_sys::DataMap {
21 &self.sys.data_map
22 }
23 pub fn data_map_mut(&mut self) -> &mut html_sys::DataMap {
25 &mut self.sys.data_map
26 }
27 }
28 impl Style {
29 pub fn media(&self) -> std::option::Option<&str> {
31 self.sys.media.as_deref()
32 }
33 pub fn set_media(
35 &mut self,
36 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
37 ) {
38 self.sys.media = value.map(|v| v.into());
39 }
40 pub fn blocking(&self) -> std::option::Option<&str> {
42 self.sys.blocking.as_deref()
43 }
44 pub fn set_blocking(
46 &mut self,
47 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
48 ) {
49 self.sys.blocking = value.map(|v| v.into());
50 }
51 pub fn access_key(&self) -> std::option::Option<&str> {
53 self.sys.access_key.as_deref()
54 }
55 pub fn set_access_key(
57 &mut self,
58 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
59 ) {
60 self.sys.access_key = value.map(|v| v.into());
61 }
62 pub fn auto_capitalize(&self) -> std::option::Option<&str> {
64 self.sys.auto_capitalize.as_deref()
65 }
66 pub fn set_auto_capitalize(
68 &mut self,
69 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
70 ) {
71 self.sys.auto_capitalize = value.map(|v| v.into());
72 }
73 pub fn autofocus(&self) -> bool {
75 self.sys.autofocus
76 }
77 pub fn set_autofocus(&mut self, value: bool) {
79 self.sys.autofocus = value;
80 }
81 pub fn class(&self) -> std::option::Option<&str> {
83 self.sys.class.as_deref()
84 }
85 pub fn set_class(
87 &mut self,
88 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
89 ) {
90 self.sys.class = value.map(|v| v.into());
91 }
92 pub fn content_editable(&self) -> std::option::Option<&str> {
94 self.sys.content_editable.as_deref()
95 }
96 pub fn set_content_editable(
98 &mut self,
99 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
100 ) {
101 self.sys.content_editable = value.map(|v| v.into());
102 }
103 pub fn direction(&self) -> std::option::Option<&str> {
105 self.sys.direction.as_deref()
106 }
107 pub fn set_direction(
109 &mut self,
110 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
111 ) {
112 self.sys.direction = value.map(|v| v.into());
113 }
114 pub fn draggable(&self) -> bool {
116 self.sys.draggable
117 }
118 pub fn set_draggable(&mut self, value: bool) {
120 self.sys.draggable = value;
121 }
122 pub fn enter_key_hint(&self) -> std::option::Option<&str> {
124 self.sys.enter_key_hint.as_deref()
125 }
126 pub fn set_enter_key_hint(
128 &mut self,
129 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
130 ) {
131 self.sys.enter_key_hint = value.map(|v| v.into());
132 }
133 pub fn export_parts(&self) -> std::option::Option<&str> {
135 self.sys.export_parts.as_deref()
136 }
137 pub fn set_export_parts(
139 &mut self,
140 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
141 ) {
142 self.sys.export_parts = value.map(|v| v.into());
143 }
144 pub fn hidden(&self) -> std::option::Option<&str> {
146 self.sys.hidden.as_deref()
147 }
148 pub fn set_hidden(
150 &mut self,
151 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
152 ) {
153 self.sys.hidden = value.map(|v| v.into());
154 }
155 pub fn id(&self) -> std::option::Option<&str> {
157 self.sys.id.as_deref()
158 }
159 pub fn set_id(
161 &mut self,
162 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
163 ) {
164 self.sys.id = value.map(|v| v.into());
165 }
166 pub fn inert(&self) -> bool {
168 self.sys.inert
169 }
170 pub fn set_inert(&mut self, value: bool) {
172 self.sys.inert = value;
173 }
174 pub fn input_mode(&self) -> std::option::Option<&str> {
176 self.sys.input_mode.as_deref()
177 }
178 pub fn set_input_mode(
180 &mut self,
181 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
182 ) {
183 self.sys.input_mode = value.map(|v| v.into());
184 }
185 pub fn is_(&self) -> std::option::Option<&str> {
187 self.sys.is_.as_deref()
188 }
189 pub fn set_is_(
191 &mut self,
192 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
193 ) {
194 self.sys.is_ = value.map(|v| v.into());
195 }
196 pub fn item_id(&self) -> std::option::Option<&str> {
198 self.sys.item_id.as_deref()
199 }
200 pub fn set_item_id(
202 &mut self,
203 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
204 ) {
205 self.sys.item_id = value.map(|v| v.into());
206 }
207 pub fn item_prop(&self) -> std::option::Option<&str> {
209 self.sys.item_prop.as_deref()
210 }
211 pub fn set_item_prop(
213 &mut self,
214 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
215 ) {
216 self.sys.item_prop = value.map(|v| v.into());
217 }
218 pub fn item_ref(&self) -> std::option::Option<&str> {
220 self.sys.item_ref.as_deref()
221 }
222 pub fn set_item_ref(
224 &mut self,
225 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
226 ) {
227 self.sys.item_ref = value.map(|v| v.into());
228 }
229 pub fn item_scope(&self) -> std::option::Option<&str> {
231 self.sys.item_scope.as_deref()
232 }
233 pub fn set_item_scope(
235 &mut self,
236 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
237 ) {
238 self.sys.item_scope = value.map(|v| v.into());
239 }
240 pub fn item_type(&self) -> std::option::Option<&str> {
242 self.sys.item_type.as_deref()
243 }
244 pub fn set_item_type(
246 &mut self,
247 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
248 ) {
249 self.sys.item_type = value.map(|v| v.into());
250 }
251 pub fn lang(&self) -> std::option::Option<&str> {
253 self.sys.lang.as_deref()
254 }
255 pub fn set_lang(
257 &mut self,
258 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
259 ) {
260 self.sys.lang = value.map(|v| v.into());
261 }
262 pub fn nonce(&self) -> std::option::Option<&str> {
264 self.sys.nonce.as_deref()
265 }
266 pub fn set_nonce(
268 &mut self,
269 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
270 ) {
271 self.sys.nonce = value.map(|v| v.into());
272 }
273 pub fn part(&self) -> std::option::Option<&str> {
275 self.sys.part.as_deref()
276 }
277 pub fn set_part(
279 &mut self,
280 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
281 ) {
282 self.sys.part = value.map(|v| v.into());
283 }
284 pub fn slot(&self) -> std::option::Option<&str> {
286 self.sys.slot.as_deref()
287 }
288 pub fn set_slot(
290 &mut self,
291 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
292 ) {
293 self.sys.slot = value.map(|v| v.into());
294 }
295 pub fn spellcheck(&self) -> std::option::Option<&str> {
297 self.sys.spellcheck.as_deref()
298 }
299 pub fn set_spellcheck(
301 &mut self,
302 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
303 ) {
304 self.sys.spellcheck = value.map(|v| v.into());
305 }
306 pub fn style(&self) -> std::option::Option<&str> {
308 self.sys.style.as_deref()
309 }
310 pub fn set_style(
312 &mut self,
313 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
314 ) {
315 self.sys.style = value.map(|v| v.into());
316 }
317 pub fn tab_index(&self) -> std::option::Option<i64> {
319 self.sys.tab_index
320 }
321 pub fn set_tab_index(&mut self, value: std::option::Option<i64>) {
323 self.sys.tab_index = value;
324 }
325 pub fn title(&self) -> std::option::Option<&str> {
327 self.sys.title.as_deref()
328 }
329 pub fn set_title(
331 &mut self,
332 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
333 ) {
334 self.sys.title = value.map(|v| v.into());
335 }
336 pub fn translate(&self) -> bool {
338 self.sys.translate
339 }
340 pub fn set_translate(&mut self, value: bool) {
342 self.sys.translate = value;
343 }
344 }
345 impl Style {
346 pub fn children(&self) -> &[super::child::StyleChild] {
348 self.children.as_ref()
349 }
350 pub fn children_mut(&mut self) -> &mut Vec<super::child::StyleChild> {
352 &mut self.children
353 }
354 }
355 impl crate::Render for Style {
356 fn render(
357 &self,
358 f: &mut std::fmt::Formatter<'_>,
359 depth: usize,
360 ) -> std::fmt::Result {
361 write!(f, "{:level$}", "", level = depth * 4)?;
362 html_sys::RenderElement::write_opening_tag(&self.sys, f)?;
363 if !self.children.is_empty() {
364 write!(f, "\n")?;
365 }
366 for el in &self.children {
367 crate::Render::render(&el, f, depth)?;
368 write!(f, "\n")?;
369 }
370 write!(f, "{:level$}", "", level = depth * 4)?;
371 html_sys::RenderElement::write_closing_tag(&self.sys, f)?;
372 Ok(())
373 }
374 }
375 impl std::fmt::Debug for Style {
376 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
377 crate::Render::render(self, f, 0)?;
378 Ok(())
379 }
380 }
381 impl std::fmt::Display for Style {
382 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
383 html_sys::RenderElement::write_opening_tag(&self.sys, f)?;
384 for el in &self.children {
385 write!(f, "{el}")?;
386 }
387 html_sys::RenderElement::write_closing_tag(&self.sys, f)?;
388 Ok(())
389 }
390 }
391 impl crate::HtmlElement for Style {}
392 impl crate::MetadataContent for Style {}
393 impl std::convert::Into<html_sys::metadata::Style> for Style {
394 fn into(self) -> html_sys::metadata::Style {
395 self.sys
396 }
397 }
398 impl From<html_sys::metadata::Style> for Style {
399 fn from(sys: html_sys::metadata::Style) -> Self {
400 Self { sys, children: vec![] }
401 }
402 }
403}
404pub mod child {
405 #[derive(PartialEq, Clone)]
407 pub enum StyleChild {
408 Text(std::borrow::Cow<'static, str>),
410 }
411 impl std::convert::From<std::borrow::Cow<'static, str>> for StyleChild {
412 fn from(value: std::borrow::Cow<'static, str>) -> Self {
413 Self::Text(value)
414 }
415 }
416 impl std::convert::From<&'static str> for StyleChild {
417 fn from(value: &'static str) -> Self {
418 Self::Text(value.into())
419 }
420 }
421 impl std::convert::From<String> for StyleChild {
422 fn from(value: String) -> Self {
423 Self::Text(value.into())
424 }
425 }
426 impl crate::Render for StyleChild {
427 fn render(
428 &self,
429 f: &mut std::fmt::Formatter<'_>,
430 depth: usize,
431 ) -> std::fmt::Result {
432 match self {
433 Self::Text(el) => crate::Render::render(el, f, depth + 1),
434 }
435 }
436 }
437 impl std::fmt::Debug for StyleChild {
438 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
439 crate::Render::render(self, f, 0)?;
440 Ok(())
441 }
442 }
443 impl std::fmt::Display for StyleChild {
444 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
445 match self {
446 Self::Text(el) => write!(f, "{el}"),
447 }
448 }
449 }
450}
451pub mod builder {
452 pub struct StyleBuilder {
454 element: super::element::Style,
455 }
456 impl StyleBuilder {
457 pub(crate) fn new(element: super::element::Style) -> Self {
458 Self { element }
459 }
460 pub fn build(&mut self) -> super::element::Style {
462 self.element.clone()
463 }
464 pub fn data(
466 &mut self,
467 data_key: impl Into<std::borrow::Cow<'static, str>>,
468 value: impl Into<std::borrow::Cow<'static, str>>,
469 ) -> &mut StyleBuilder {
470 self.element.data_map_mut().insert(data_key.into(), value.into());
471 self
472 }
473 pub fn text(
475 &mut self,
476 s: impl Into<std::borrow::Cow<'static, str>>,
477 ) -> &mut Self {
478 let cow = s.into();
479 self.element.children_mut().push(cow.into());
480 self
481 }
482 pub fn media(
484 &mut self,
485 value: impl Into<std::borrow::Cow<'static, str>>,
486 ) -> &mut Self {
487 self.element.set_media(Some(value.into()));
488 self
489 }
490 pub fn blocking(
492 &mut self,
493 value: impl Into<std::borrow::Cow<'static, str>>,
494 ) -> &mut Self {
495 self.element.set_blocking(Some(value.into()));
496 self
497 }
498 pub fn access_key(
500 &mut self,
501 value: impl Into<std::borrow::Cow<'static, str>>,
502 ) -> &mut Self {
503 self.element.set_access_key(Some(value.into()));
504 self
505 }
506 pub fn auto_capitalize(
508 &mut self,
509 value: impl Into<std::borrow::Cow<'static, str>>,
510 ) -> &mut Self {
511 self.element.set_auto_capitalize(Some(value.into()));
512 self
513 }
514 pub fn autofocus(&mut self, value: bool) -> &mut Self {
516 self.element.set_autofocus(value);
517 self
518 }
519 pub fn class(
521 &mut self,
522 value: impl Into<std::borrow::Cow<'static, str>>,
523 ) -> &mut Self {
524 self.element.set_class(Some(value.into()));
525 self
526 }
527 pub fn content_editable(
529 &mut self,
530 value: impl Into<std::borrow::Cow<'static, str>>,
531 ) -> &mut Self {
532 self.element.set_content_editable(Some(value.into()));
533 self
534 }
535 pub fn direction(
537 &mut self,
538 value: impl Into<std::borrow::Cow<'static, str>>,
539 ) -> &mut Self {
540 self.element.set_direction(Some(value.into()));
541 self
542 }
543 pub fn draggable(&mut self, value: bool) -> &mut Self {
545 self.element.set_draggable(value);
546 self
547 }
548 pub fn enter_key_hint(
550 &mut self,
551 value: impl Into<std::borrow::Cow<'static, str>>,
552 ) -> &mut Self {
553 self.element.set_enter_key_hint(Some(value.into()));
554 self
555 }
556 pub fn export_parts(
558 &mut self,
559 value: impl Into<std::borrow::Cow<'static, str>>,
560 ) -> &mut Self {
561 self.element.set_export_parts(Some(value.into()));
562 self
563 }
564 pub fn hidden(
566 &mut self,
567 value: impl Into<std::borrow::Cow<'static, str>>,
568 ) -> &mut Self {
569 self.element.set_hidden(Some(value.into()));
570 self
571 }
572 pub fn id(
574 &mut self,
575 value: impl Into<std::borrow::Cow<'static, str>>,
576 ) -> &mut Self {
577 self.element.set_id(Some(value.into()));
578 self
579 }
580 pub fn inert(&mut self, value: bool) -> &mut Self {
582 self.element.set_inert(value);
583 self
584 }
585 pub fn input_mode(
587 &mut self,
588 value: impl Into<std::borrow::Cow<'static, str>>,
589 ) -> &mut Self {
590 self.element.set_input_mode(Some(value.into()));
591 self
592 }
593 pub fn is_(
595 &mut self,
596 value: impl Into<std::borrow::Cow<'static, str>>,
597 ) -> &mut Self {
598 self.element.set_is_(Some(value.into()));
599 self
600 }
601 pub fn item_id(
603 &mut self,
604 value: impl Into<std::borrow::Cow<'static, str>>,
605 ) -> &mut Self {
606 self.element.set_item_id(Some(value.into()));
607 self
608 }
609 pub fn item_prop(
611 &mut self,
612 value: impl Into<std::borrow::Cow<'static, str>>,
613 ) -> &mut Self {
614 self.element.set_item_prop(Some(value.into()));
615 self
616 }
617 pub fn item_ref(
619 &mut self,
620 value: impl Into<std::borrow::Cow<'static, str>>,
621 ) -> &mut Self {
622 self.element.set_item_ref(Some(value.into()));
623 self
624 }
625 pub fn item_scope(
627 &mut self,
628 value: impl Into<std::borrow::Cow<'static, str>>,
629 ) -> &mut Self {
630 self.element.set_item_scope(Some(value.into()));
631 self
632 }
633 pub fn item_type(
635 &mut self,
636 value: impl Into<std::borrow::Cow<'static, str>>,
637 ) -> &mut Self {
638 self.element.set_item_type(Some(value.into()));
639 self
640 }
641 pub fn lang(
643 &mut self,
644 value: impl Into<std::borrow::Cow<'static, str>>,
645 ) -> &mut Self {
646 self.element.set_lang(Some(value.into()));
647 self
648 }
649 pub fn nonce(
651 &mut self,
652 value: impl Into<std::borrow::Cow<'static, str>>,
653 ) -> &mut Self {
654 self.element.set_nonce(Some(value.into()));
655 self
656 }
657 pub fn part(
659 &mut self,
660 value: impl Into<std::borrow::Cow<'static, str>>,
661 ) -> &mut Self {
662 self.element.set_part(Some(value.into()));
663 self
664 }
665 pub fn slot(
667 &mut self,
668 value: impl Into<std::borrow::Cow<'static, str>>,
669 ) -> &mut Self {
670 self.element.set_slot(Some(value.into()));
671 self
672 }
673 pub fn spellcheck(
675 &mut self,
676 value: impl Into<std::borrow::Cow<'static, str>>,
677 ) -> &mut Self {
678 self.element.set_spellcheck(Some(value.into()));
679 self
680 }
681 pub fn style(
683 &mut self,
684 value: impl Into<std::borrow::Cow<'static, str>>,
685 ) -> &mut Self {
686 self.element.set_style(Some(value.into()));
687 self
688 }
689 pub fn tab_index(&mut self, value: i64) -> &mut Self {
691 self.element.set_tab_index(Some(value));
692 self
693 }
694 pub fn title(
696 &mut self,
697 value: impl Into<std::borrow::Cow<'static, str>>,
698 ) -> &mut Self {
699 self.element.set_title(Some(value.into()));
700 self
701 }
702 pub fn translate(&mut self, value: bool) -> &mut Self {
704 self.element.set_translate(value);
705 self
706 }
707 pub fn push<T>(&mut self, child_el: T) -> &mut Self
709 where
710 T: Into<crate::generated::all::children::StyleChild>,
711 {
712 let child_el = child_el.into();
713 self.element.children_mut().push(child_el);
714 self
715 }
716 pub fn extend<I, T>(&mut self, iter: I) -> &mut Self
718 where
719 I: IntoIterator<Item = T>,
720 T: Into<crate::generated::all::children::StyleChild>,
721 {
722 let iter = iter.into_iter().map(|child_el| child_el.into());
723 self.element.children_mut().extend(iter);
724 self
725 }
726 }
727}