1pub mod element {
2 #[doc(alias = "picture")]
6 #[non_exhaustive]
7 #[derive(PartialEq, Clone, Default)]
8 pub struct Picture {
9 sys: html_sys::embedded::Picture,
10 children: Vec<super::child::PictureChild>,
11 }
12 impl Picture {
13 pub fn builder() -> super::builder::PictureBuilder {
15 super::builder::PictureBuilder::new(Default::default())
16 }
17 }
18 impl Picture {
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 Picture {
29 pub fn aria_hidden(&self) -> bool {
31 self.sys.aria_hidden
32 }
33 pub fn set_aria_hidden(&mut self, value: bool) {
35 self.sys.aria_hidden = value;
36 }
37 pub fn access_key(&self) -> std::option::Option<&str> {
39 self.sys.access_key.as_deref()
40 }
41 pub fn set_access_key(
43 &mut self,
44 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
45 ) {
46 self.sys.access_key = value.map(|v| v.into());
47 }
48 pub fn auto_capitalize(&self) -> std::option::Option<&str> {
50 self.sys.auto_capitalize.as_deref()
51 }
52 pub fn set_auto_capitalize(
54 &mut self,
55 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
56 ) {
57 self.sys.auto_capitalize = value.map(|v| v.into());
58 }
59 pub fn autofocus(&self) -> bool {
61 self.sys.autofocus
62 }
63 pub fn set_autofocus(&mut self, value: bool) {
65 self.sys.autofocus = value;
66 }
67 pub fn class(&self) -> std::option::Option<&str> {
69 self.sys.class.as_deref()
70 }
71 pub fn set_class(
73 &mut self,
74 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
75 ) {
76 self.sys.class = value.map(|v| v.into());
77 }
78 pub fn content_editable(&self) -> std::option::Option<&str> {
80 self.sys.content_editable.as_deref()
81 }
82 pub fn set_content_editable(
84 &mut self,
85 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
86 ) {
87 self.sys.content_editable = value.map(|v| v.into());
88 }
89 pub fn direction(&self) -> std::option::Option<&str> {
91 self.sys.direction.as_deref()
92 }
93 pub fn set_direction(
95 &mut self,
96 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
97 ) {
98 self.sys.direction = value.map(|v| v.into());
99 }
100 pub fn draggable(&self) -> bool {
102 self.sys.draggable
103 }
104 pub fn set_draggable(&mut self, value: bool) {
106 self.sys.draggable = value;
107 }
108 pub fn enter_key_hint(&self) -> std::option::Option<&str> {
110 self.sys.enter_key_hint.as_deref()
111 }
112 pub fn set_enter_key_hint(
114 &mut self,
115 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
116 ) {
117 self.sys.enter_key_hint = value.map(|v| v.into());
118 }
119 pub fn export_parts(&self) -> std::option::Option<&str> {
121 self.sys.export_parts.as_deref()
122 }
123 pub fn set_export_parts(
125 &mut self,
126 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
127 ) {
128 self.sys.export_parts = value.map(|v| v.into());
129 }
130 pub fn hidden(&self) -> std::option::Option<&str> {
132 self.sys.hidden.as_deref()
133 }
134 pub fn set_hidden(
136 &mut self,
137 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
138 ) {
139 self.sys.hidden = value.map(|v| v.into());
140 }
141 pub fn id(&self) -> std::option::Option<&str> {
143 self.sys.id.as_deref()
144 }
145 pub fn set_id(
147 &mut self,
148 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
149 ) {
150 self.sys.id = value.map(|v| v.into());
151 }
152 pub fn inert(&self) -> bool {
154 self.sys.inert
155 }
156 pub fn set_inert(&mut self, value: bool) {
158 self.sys.inert = value;
159 }
160 pub fn input_mode(&self) -> std::option::Option<&str> {
162 self.sys.input_mode.as_deref()
163 }
164 pub fn set_input_mode(
166 &mut self,
167 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
168 ) {
169 self.sys.input_mode = value.map(|v| v.into());
170 }
171 pub fn is_(&self) -> std::option::Option<&str> {
173 self.sys.is_.as_deref()
174 }
175 pub fn set_is_(
177 &mut self,
178 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
179 ) {
180 self.sys.is_ = value.map(|v| v.into());
181 }
182 pub fn item_id(&self) -> std::option::Option<&str> {
184 self.sys.item_id.as_deref()
185 }
186 pub fn set_item_id(
188 &mut self,
189 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
190 ) {
191 self.sys.item_id = value.map(|v| v.into());
192 }
193 pub fn item_prop(&self) -> std::option::Option<&str> {
195 self.sys.item_prop.as_deref()
196 }
197 pub fn set_item_prop(
199 &mut self,
200 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
201 ) {
202 self.sys.item_prop = value.map(|v| v.into());
203 }
204 pub fn item_ref(&self) -> std::option::Option<&str> {
206 self.sys.item_ref.as_deref()
207 }
208 pub fn set_item_ref(
210 &mut self,
211 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
212 ) {
213 self.sys.item_ref = value.map(|v| v.into());
214 }
215 pub fn item_scope(&self) -> std::option::Option<&str> {
217 self.sys.item_scope.as_deref()
218 }
219 pub fn set_item_scope(
221 &mut self,
222 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
223 ) {
224 self.sys.item_scope = value.map(|v| v.into());
225 }
226 pub fn item_type(&self) -> std::option::Option<&str> {
228 self.sys.item_type.as_deref()
229 }
230 pub fn set_item_type(
232 &mut self,
233 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
234 ) {
235 self.sys.item_type = value.map(|v| v.into());
236 }
237 pub fn lang(&self) -> std::option::Option<&str> {
239 self.sys.lang.as_deref()
240 }
241 pub fn set_lang(
243 &mut self,
244 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
245 ) {
246 self.sys.lang = value.map(|v| v.into());
247 }
248 pub fn nonce(&self) -> std::option::Option<&str> {
250 self.sys.nonce.as_deref()
251 }
252 pub fn set_nonce(
254 &mut self,
255 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
256 ) {
257 self.sys.nonce = value.map(|v| v.into());
258 }
259 pub fn part(&self) -> std::option::Option<&str> {
261 self.sys.part.as_deref()
262 }
263 pub fn set_part(
265 &mut self,
266 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
267 ) {
268 self.sys.part = value.map(|v| v.into());
269 }
270 pub fn slot(&self) -> std::option::Option<&str> {
272 self.sys.slot.as_deref()
273 }
274 pub fn set_slot(
276 &mut self,
277 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
278 ) {
279 self.sys.slot = value.map(|v| v.into());
280 }
281 pub fn spellcheck(&self) -> std::option::Option<&str> {
283 self.sys.spellcheck.as_deref()
284 }
285 pub fn set_spellcheck(
287 &mut self,
288 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
289 ) {
290 self.sys.spellcheck = value.map(|v| v.into());
291 }
292 pub fn style(&self) -> std::option::Option<&str> {
294 self.sys.style.as_deref()
295 }
296 pub fn set_style(
298 &mut self,
299 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
300 ) {
301 self.sys.style = value.map(|v| v.into());
302 }
303 pub fn tab_index(&self) -> std::option::Option<i64> {
305 self.sys.tab_index
306 }
307 pub fn set_tab_index(&mut self, value: std::option::Option<i64>) {
309 self.sys.tab_index = value;
310 }
311 pub fn title(&self) -> std::option::Option<&str> {
313 self.sys.title.as_deref()
314 }
315 pub fn set_title(
317 &mut self,
318 value: std::option::Option<impl Into<std::borrow::Cow<'static, str>>>,
319 ) {
320 self.sys.title = value.map(|v| v.into());
321 }
322 pub fn translate(&self) -> bool {
324 self.sys.translate
325 }
326 pub fn set_translate(&mut self, value: bool) {
328 self.sys.translate = value;
329 }
330 }
331 impl Picture {
332 pub fn children(&self) -> &[super::child::PictureChild] {
334 self.children.as_ref()
335 }
336 pub fn children_mut(&mut self) -> &mut Vec<super::child::PictureChild> {
338 &mut self.children
339 }
340 }
341 impl crate::Render for Picture {
342 fn render(
343 &self,
344 f: &mut std::fmt::Formatter<'_>,
345 depth: usize,
346 ) -> std::fmt::Result {
347 write!(f, "{:level$}", "", level = depth * 4)?;
348 html_sys::RenderElement::write_opening_tag(&self.sys, f)?;
349 if !self.children.is_empty() {
350 write!(f, "\n")?;
351 }
352 for el in &self.children {
353 crate::Render::render(&el, f, depth)?;
354 write!(f, "\n")?;
355 }
356 write!(f, "{:level$}", "", level = depth * 4)?;
357 html_sys::RenderElement::write_closing_tag(&self.sys, f)?;
358 Ok(())
359 }
360 }
361 impl std::fmt::Debug for Picture {
362 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
363 crate::Render::render(self, f, 0)?;
364 Ok(())
365 }
366 }
367 impl std::fmt::Display for Picture {
368 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
369 html_sys::RenderElement::write_opening_tag(&self.sys, f)?;
370 for el in &self.children {
371 write!(f, "{el}")?;
372 }
373 html_sys::RenderElement::write_closing_tag(&self.sys, f)?;
374 Ok(())
375 }
376 }
377 impl crate::HtmlElement for Picture {}
378 impl crate::FlowContent for Picture {}
379 impl crate::PhrasingContent for Picture {}
380 impl crate::EmbeddedContent for Picture {}
381 impl crate::PalpableContent for Picture {}
382 impl std::convert::Into<html_sys::embedded::Picture> for Picture {
383 fn into(self) -> html_sys::embedded::Picture {
384 self.sys
385 }
386 }
387 impl From<html_sys::embedded::Picture> for Picture {
388 fn from(sys: html_sys::embedded::Picture) -> Self {
389 Self { sys, children: vec![] }
390 }
391 }
392}
393pub mod child {
394 #[derive(PartialEq, Clone)]
396 pub enum PictureChild {
397 Image(crate::generated::all::Image),
399 MediaSource(crate::generated::all::MediaSource),
401 Script(crate::generated::all::Script),
403 Template(crate::generated::all::Template),
405 }
406 impl std::convert::From<crate::generated::all::Image> for PictureChild {
407 fn from(value: crate::generated::all::Image) -> Self {
408 Self::Image(value)
409 }
410 }
411 impl std::convert::From<crate::generated::all::MediaSource> for PictureChild {
412 fn from(value: crate::generated::all::MediaSource) -> Self {
413 Self::MediaSource(value)
414 }
415 }
416 impl std::convert::From<crate::generated::all::Script> for PictureChild {
417 fn from(value: crate::generated::all::Script) -> Self {
418 Self::Script(value)
419 }
420 }
421 impl std::convert::From<crate::generated::all::Template> for PictureChild {
422 fn from(value: crate::generated::all::Template) -> Self {
423 Self::Template(value)
424 }
425 }
426 impl crate::Render for PictureChild {
427 fn render(
428 &self,
429 f: &mut std::fmt::Formatter<'_>,
430 depth: usize,
431 ) -> std::fmt::Result {
432 match self {
433 Self::Image(el) => crate::Render::render(el, f, depth + 1),
434 Self::MediaSource(el) => crate::Render::render(el, f, depth + 1),
435 Self::Script(el) => crate::Render::render(el, f, depth + 1),
436 Self::Template(el) => crate::Render::render(el, f, depth + 1),
437 }
438 }
439 }
440 impl std::fmt::Debug for PictureChild {
441 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
442 crate::Render::render(self, f, 0)?;
443 Ok(())
444 }
445 }
446 impl std::fmt::Display for PictureChild {
447 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
448 match self {
449 Self::Image(el) => write!(f, "{el}"),
450 Self::MediaSource(el) => write!(f, "{el}"),
451 Self::Script(el) => write!(f, "{el}"),
452 Self::Template(el) => write!(f, "{el}"),
453 }
454 }
455 }
456}
457pub mod builder {
458 pub struct PictureBuilder {
460 element: super::element::Picture,
461 }
462 impl PictureBuilder {
463 pub(crate) fn new(element: super::element::Picture) -> Self {
464 Self { element }
465 }
466 pub fn build(&mut self) -> super::element::Picture {
468 self.element.clone()
469 }
470 pub fn data(
472 &mut self,
473 data_key: impl Into<std::borrow::Cow<'static, str>>,
474 value: impl Into<std::borrow::Cow<'static, str>>,
475 ) -> &mut PictureBuilder {
476 self.element.data_map_mut().insert(data_key.into(), value.into());
477 self
478 }
479 pub fn image<F>(&mut self, f: F) -> &mut Self
481 where
482 F: for<'a> FnOnce(
483 &'a mut crate::generated::all::builders::ImageBuilder,
484 ) -> &'a mut crate::generated::all::builders::ImageBuilder,
485 {
486 let ty: crate::generated::all::Image = Default::default();
487 let mut ty_builder = crate::generated::all::builders::ImageBuilder::new(ty);
488 (f)(&mut ty_builder);
489 let ty = ty_builder.build();
490 self.element.children_mut().push(ty.into());
491 self
492 }
493 pub fn media_source<F>(&mut self, f: F) -> &mut Self
495 where
496 F: for<'a> FnOnce(
497 &'a mut crate::generated::all::builders::MediaSourceBuilder,
498 ) -> &'a mut crate::generated::all::builders::MediaSourceBuilder,
499 {
500 let ty: crate::generated::all::MediaSource = Default::default();
501 let mut ty_builder = crate::generated::all::builders::MediaSourceBuilder::new(
502 ty,
503 );
504 (f)(&mut ty_builder);
505 let ty = ty_builder.build();
506 self.element.children_mut().push(ty.into());
507 self
508 }
509 pub fn script<F>(&mut self, f: F) -> &mut Self
511 where
512 F: for<'a> FnOnce(
513 &'a mut crate::generated::all::builders::ScriptBuilder,
514 ) -> &'a mut crate::generated::all::builders::ScriptBuilder,
515 {
516 let ty: crate::generated::all::Script = Default::default();
517 let mut ty_builder = crate::generated::all::builders::ScriptBuilder::new(ty);
518 (f)(&mut ty_builder);
519 let ty = ty_builder.build();
520 self.element.children_mut().push(ty.into());
521 self
522 }
523 pub fn template<F>(&mut self, f: F) -> &mut Self
525 where
526 F: for<'a> FnOnce(
527 &'a mut crate::generated::all::builders::TemplateBuilder,
528 ) -> &'a mut crate::generated::all::builders::TemplateBuilder,
529 {
530 let ty: crate::generated::all::Template = Default::default();
531 let mut ty_builder = crate::generated::all::builders::TemplateBuilder::new(
532 ty,
533 );
534 (f)(&mut ty_builder);
535 let ty = ty_builder.build();
536 self.element.children_mut().push(ty.into());
537 self
538 }
539 pub fn aria_hidden(&mut self, value: bool) -> &mut Self {
541 self.element.set_aria_hidden(value);
542 self
543 }
544 pub fn access_key(
546 &mut self,
547 value: impl Into<std::borrow::Cow<'static, str>>,
548 ) -> &mut Self {
549 self.element.set_access_key(Some(value.into()));
550 self
551 }
552 pub fn auto_capitalize(
554 &mut self,
555 value: impl Into<std::borrow::Cow<'static, str>>,
556 ) -> &mut Self {
557 self.element.set_auto_capitalize(Some(value.into()));
558 self
559 }
560 pub fn autofocus(&mut self, value: bool) -> &mut Self {
562 self.element.set_autofocus(value);
563 self
564 }
565 pub fn class(
567 &mut self,
568 value: impl Into<std::borrow::Cow<'static, str>>,
569 ) -> &mut Self {
570 self.element.set_class(Some(value.into()));
571 self
572 }
573 pub fn content_editable(
575 &mut self,
576 value: impl Into<std::borrow::Cow<'static, str>>,
577 ) -> &mut Self {
578 self.element.set_content_editable(Some(value.into()));
579 self
580 }
581 pub fn direction(
583 &mut self,
584 value: impl Into<std::borrow::Cow<'static, str>>,
585 ) -> &mut Self {
586 self.element.set_direction(Some(value.into()));
587 self
588 }
589 pub fn draggable(&mut self, value: bool) -> &mut Self {
591 self.element.set_draggable(value);
592 self
593 }
594 pub fn enter_key_hint(
596 &mut self,
597 value: impl Into<std::borrow::Cow<'static, str>>,
598 ) -> &mut Self {
599 self.element.set_enter_key_hint(Some(value.into()));
600 self
601 }
602 pub fn export_parts(
604 &mut self,
605 value: impl Into<std::borrow::Cow<'static, str>>,
606 ) -> &mut Self {
607 self.element.set_export_parts(Some(value.into()));
608 self
609 }
610 pub fn hidden(
612 &mut self,
613 value: impl Into<std::borrow::Cow<'static, str>>,
614 ) -> &mut Self {
615 self.element.set_hidden(Some(value.into()));
616 self
617 }
618 pub fn id(
620 &mut self,
621 value: impl Into<std::borrow::Cow<'static, str>>,
622 ) -> &mut Self {
623 self.element.set_id(Some(value.into()));
624 self
625 }
626 pub fn inert(&mut self, value: bool) -> &mut Self {
628 self.element.set_inert(value);
629 self
630 }
631 pub fn input_mode(
633 &mut self,
634 value: impl Into<std::borrow::Cow<'static, str>>,
635 ) -> &mut Self {
636 self.element.set_input_mode(Some(value.into()));
637 self
638 }
639 pub fn is_(
641 &mut self,
642 value: impl Into<std::borrow::Cow<'static, str>>,
643 ) -> &mut Self {
644 self.element.set_is_(Some(value.into()));
645 self
646 }
647 pub fn item_id(
649 &mut self,
650 value: impl Into<std::borrow::Cow<'static, str>>,
651 ) -> &mut Self {
652 self.element.set_item_id(Some(value.into()));
653 self
654 }
655 pub fn item_prop(
657 &mut self,
658 value: impl Into<std::borrow::Cow<'static, str>>,
659 ) -> &mut Self {
660 self.element.set_item_prop(Some(value.into()));
661 self
662 }
663 pub fn item_ref(
665 &mut self,
666 value: impl Into<std::borrow::Cow<'static, str>>,
667 ) -> &mut Self {
668 self.element.set_item_ref(Some(value.into()));
669 self
670 }
671 pub fn item_scope(
673 &mut self,
674 value: impl Into<std::borrow::Cow<'static, str>>,
675 ) -> &mut Self {
676 self.element.set_item_scope(Some(value.into()));
677 self
678 }
679 pub fn item_type(
681 &mut self,
682 value: impl Into<std::borrow::Cow<'static, str>>,
683 ) -> &mut Self {
684 self.element.set_item_type(Some(value.into()));
685 self
686 }
687 pub fn lang(
689 &mut self,
690 value: impl Into<std::borrow::Cow<'static, str>>,
691 ) -> &mut Self {
692 self.element.set_lang(Some(value.into()));
693 self
694 }
695 pub fn nonce(
697 &mut self,
698 value: impl Into<std::borrow::Cow<'static, str>>,
699 ) -> &mut Self {
700 self.element.set_nonce(Some(value.into()));
701 self
702 }
703 pub fn part(
705 &mut self,
706 value: impl Into<std::borrow::Cow<'static, str>>,
707 ) -> &mut Self {
708 self.element.set_part(Some(value.into()));
709 self
710 }
711 pub fn slot(
713 &mut self,
714 value: impl Into<std::borrow::Cow<'static, str>>,
715 ) -> &mut Self {
716 self.element.set_slot(Some(value.into()));
717 self
718 }
719 pub fn spellcheck(
721 &mut self,
722 value: impl Into<std::borrow::Cow<'static, str>>,
723 ) -> &mut Self {
724 self.element.set_spellcheck(Some(value.into()));
725 self
726 }
727 pub fn style(
729 &mut self,
730 value: impl Into<std::borrow::Cow<'static, str>>,
731 ) -> &mut Self {
732 self.element.set_style(Some(value.into()));
733 self
734 }
735 pub fn tab_index(&mut self, value: i64) -> &mut Self {
737 self.element.set_tab_index(Some(value));
738 self
739 }
740 pub fn title(
742 &mut self,
743 value: impl Into<std::borrow::Cow<'static, str>>,
744 ) -> &mut Self {
745 self.element.set_title(Some(value.into()));
746 self
747 }
748 pub fn translate(&mut self, value: bool) -> &mut Self {
750 self.element.set_translate(value);
751 self
752 }
753 pub fn push<T>(&mut self, child_el: T) -> &mut Self
755 where
756 T: Into<crate::generated::all::children::PictureChild>,
757 {
758 let child_el = child_el.into();
759 self.element.children_mut().push(child_el);
760 self
761 }
762 pub fn extend<I, T>(&mut self, iter: I) -> &mut Self
764 where
765 I: IntoIterator<Item = T>,
766 T: Into<crate::generated::all::children::PictureChild>,
767 {
768 let iter = iter.into_iter().map(|child_el| child_el.into());
769 self.element.children_mut().extend(iter);
770 self
771 }
772 }
773}