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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//! Provides macro for creating functions for tags
macro_rules! declare_svg_tags{

    ( $(
         $(#[$attr:meta])*
         $name:ident;
       )*
     ) => {
        $(
            doc_comment!{
                concat!("Creates an svg [",stringify!($name),"](/https://developer.mozilla.org/en-US/docs/Web/SVG/Element/",stringify!($name),") element"),

                $(#[$attr])*
                #[inline]
                #[allow(non_snake_case)]
                pub fn $name<MSG>(attrs: impl IntoIterator<Item = $crate::vdom::Attribute<MSG>>, children: impl IntoIterator<Item = $crate::vdom::Node<MSG>>) -> $crate::vdom::Node<MSG>
                    {
                        $crate::svg::svg_element(stringify!($name), attrs, children)
                }
            }
         )*
    };

    ( $(
         $(#[$attr:meta])*
         $name:ident => $tagname:tt;
       )*
     ) => {
        $(
            doc_comment!{
                concat!("Creates an svg [",$tagname,"](/https://developer.mozilla.org/en-US/docs/Web/SVG/Element/",$tagname,") element"),

                $(#[$attr])*
                #[inline]
                #[allow(non_snake_case)]
                pub fn $name<MSG>(attrs: impl IntoIterator<Item = $crate::vdom::Attribute<MSG>>, children: impl IntoIterator<Item = $crate::vdom::Node<MSG>>) -> $crate::vdom::Node<MSG>
                    {
                        $crate::svg::svg_element($tagname, attrs, children)
                 }
            }
         )*
    }

}

/// declare common svg tags that is not in conflict with the html tags
/// at the same time this also fills the SVG_TAGS const with all the svg tags
macro_rules! declare_common_svg_tags_and_macro {
    ($($(#[$attr:meta])* $name:ident;)*) => {

        declare_svg_tags! { $($name;)* }

        #[cfg(feature = "with-lookup")]
        /// These are the commonly used svg tags such as rect, circle, path, arc, ..etc.
        pub const SVG_TAGS: &[&'static str] = &[ $(stringify!($name),)* ];

    };
}

/// declare svg tags, at the same time this also
/// fills up the SVG_TAGS_SPECIAL const with the svg tags that are not
/// regular identifiers
macro_rules! declare_svg_tags_special{
    ( $(
         $(#[$attr:meta])*
         $name:ident => $attribute:tt;
       )*
     ) => {
        declare_svg_tags!{ $($name=>$attribute;)*}

        #[cfg(feature = "with-lookup")]
        /// These are svg tags which the tags are non proper rust identifier, so they are handled
        /// differently
        pub const SVG_TAGS_SPECIAL:&[(&'static str,&'static str)] = &[$((stringify!($name),$attribute),)*];
    }
}

macro_rules! declare_svg_tags_non_common{

    ( $(
         $(#[$attr:meta])*
         $name:ident;
       )*
     ) => {
        declare_svg_tags!{ $($name;)*}

        #[cfg(feature = "with-lookup")]
        /// These are collection of svg tags that are non commonly used put together in this
        /// collection so as not to create import conflicts with the common tags
        pub const SVG_TAGS_NON_COMMON:&[&'static str] = &[$(stringify!($name),)*];
    }
}

/// commonly used svg tags
pub mod commons {
    declare_common_svg_tags_and_macro! {
        animate;
        circle;
        clipPath;
        defs;
        desc;
        discard;
        ellipse;
        filter;
        g;
        hatch;
        hatchpath;
        image;
        line;
        marker;
        mask;
        mesh;
        meshgradient;
        meshpatch;
        meshrow;
        metadata;
        mpath;
        path;
        pattern;
        polygon;
        polyline;
        rect;
        set;
        solidcolor;
        stop;
        svg;
        switch;
        symbol;
        tspan;
        unknown;
        view;
    }
}

/// special svg tags
pub mod special {
    // These are svg tags that is exposed in such a way that is consistent to rust conventions
    // This includes exposing the following to snake_case
    // - reserved keywords
    // - kebab-case tags
    // - camelCase tags
    declare_svg_tags_special! {
        ////////////////////////////
        // reserved keywords in rust that are svg tags
        ////////////////////////////
        r#use => "use";

        ////////////////////////
        // kebab-case svg tags
        ////////////////////////
        color_profile => "color-profile";

        /////////////////////
        // camelCase svg tags
        ////////////////////
        animate_motion => "animateMotion";
        animate_transform => "animateTransform";
        fe_blend => "feBlend";
        fe_color_matrix => "feColorMatrix";
        fe_component_transfer => "feComponentTransfer";
        fe_composite => "feComposite";
        fe_convolve_matrix => "feConvolveMatrix";
        fe_diffuse_lighting => "feDiffuseLighting";
        fe_displacement_map => "feDisplacementMap";
        fe_distant_light => "feDistantLight";
        fe_drop_shadow => "feDropShadow";
        fe_flood => "feFlood";
        fe_func_a => "feFuncA";
        fe_func_b => "feFuncB";
        fe_func_g => "feFuncG";
        fe_func_r => "feFuncR";
        fe_gaussian_blur => "feGaussianBlur";
        fe_image => "feImage";
        fe_merge => "feMerge";
        fe_merge_node => "feMergeNode";
        fe_morphology => "feMorphology";
        fe_offset => "feOffset";
        fe_point_light => "fePointLight";
        fe_specular_lighting => "feSpecularLighting";
        fe_spot_light => "feSpotLight";
        fe_tile => "feTile";
        fe_turbulence => "feTurbulence";
        foreign_object => "foreignObject";
        linear_gradient => "linearGradient";
        radial_gradient => "radialGradient";
        text_path => "textPath";
    }
}

// These are non-common tags
// which the users need to explicitly import using
// svg::tags::style, svg::tags::text, svg::tags::title, etc
//
declare_svg_tags_non_common! {
    script;     //> svg::tags::script   conflicts with > html::tags::script
    style;      //> svg::tags::style    conflicts with > html::attributes::style
    text;       //> svg::tags::text     conflicts with > html::text
    a;          //> svg::tags::a        conflicts with > html::tags::a
    title;      //> svg::tags::title    conflicts with > html::attributes::title
}