1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::elem::{HtmlProp, HtmlProps};
use std::borrow::Cow;
use web_sys::HtmlEmbedElement;

#[allow(non_camel_case_types)]
#[derive(Clone, PartialEq)]
pub enum EmbedProp {
    src(Cow<'static, str>),
    r#type(Cow<'static, str>),
    width(Cow<'static, str>),
    height(Cow<'static, str>),
    align(Cow<'static, str>),
    name(Cow<'static, str>),
}

#[sealed::sealed]
impl crate::elem::HtmlComponent for HtmlEmbedElement {
    type PropEnum = EmbedProp;
}
#[sealed::sealed]
impl crate::elem::PropEnum<HtmlEmbedElement> for EmbedProp {
    fn unset_on(&self, elem: &HtmlEmbedElement) {
        match self {
            EmbedProp::src(_) => elem.remove_attribute("src").unwrap(),
            EmbedProp::r#type(_) => elem.remove_attribute("type").unwrap(),
            EmbedProp::width(_) => elem.remove_attribute("width").unwrap(),
            EmbedProp::height(_) => elem.remove_attribute("height").unwrap(),
            EmbedProp::align(_) => elem.remove_attribute("align").unwrap(),
            EmbedProp::name(_) => elem.remove_attribute("name").unwrap(),
        }
    }

    fn set_on(&self, elem: &HtmlEmbedElement) {
        match self {
            EmbedProp::src(v) => elem.set_src(v),
            EmbedProp::r#type(v) => elem.set_type(v),
            EmbedProp::width(v) => elem.set_width(v),
            EmbedProp::height(v) => elem.set_height(v),
            EmbedProp::align(v) => elem.set_align(v),
            EmbedProp::name(v) => elem.set_name(v),
        }
    }
}

impl HtmlProps<HtmlEmbedElement> {
    pub fn src(mut self, val: impl Into<Cow<'static, str>>) -> Self {
        let val = val.into();
        self.0.push_back(HtmlProp::Own(EmbedProp::src(val)));
        self
    }

    pub fn r#type(mut self, val: Cow<'static, str>) -> Self {
        self.0.push_back(HtmlProp::Own(EmbedProp::r#type(val)));
        self
    }

    pub fn width(mut self, val: impl Into<Cow<'static, str>>) -> Self {
        let val = val.into();
        self.0.push_back(HtmlProp::Own(EmbedProp::width(val)));
        self
    }

    pub fn height(mut self, val: impl Into<Cow<'static, str>>) -> Self {
        let val = val.into();
        self.0.push_back(HtmlProp::Own(EmbedProp::height(val)));
        self
    }

    pub fn align(mut self, val: impl Into<Cow<'static, str>>) -> Self {
        let val = val.into();
        self.0.push_back(HtmlProp::Own(EmbedProp::align(val)));
        self
    }

    pub fn name(mut self, val: impl Into<Cow<'static, str>>) -> Self {
        let val = val.into();
        self.0.push_back(HtmlProp::Own(EmbedProp::name(val)));
        self
    }
}