spair 0.0.9

A framework for single-page application in Rust
Documentation
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
use super::SvgElementUpdater;
use crate::{
    component::Component,
    render::base::{ElementUpdater, ElementUpdaterMut, F64AttributeValue, StringAttributeValue},
};

make_traits_for_attribute_values! {
    LengthPercentage {
        i32, set_i32_attribute qr_attribute qrm_attribute qrmws_attribute,
        f64, set_f64_attribute qr_attribute qrm_attribute qrmws_attribute,
        &str, set_str_attribute NO_QUEUE_RENDER NO_QUEUE_RENDER NO_QUEUE_RENDER,
        String, set_string_attribute qr_attribute qrm_attribute qrmws_attribute,
    }
}

pub trait SamsHandMade<C: Component>: Sized + ElementUpdaterMut<C> {
    fn class(mut self, class_name: &str) -> Self {
        self.element_updater_mut().class(class_name);
        self
    }

    fn class_if(mut self, class_on: bool, class_name: &str) -> Self {
        self.element_updater_mut().class_if(class_on, class_name);
        self
    }

    /// Set the `first_class` if `first` is true, otherwise, set the `second_class`
    fn class_or(mut self, first: bool, first_class: &str, second_class: &str) -> Self {
        self.element_updater_mut()
            .class_or(first, first_class, second_class);
        self
    }

    fn focus(mut self, value: bool) -> Self {
        self.element_updater_mut().focus(value);
        self
    }

    /// This method only accepts a &Route. If you want set `href` with a str, please use `href_str()`.
    /// It is possible to make this method accept both a Route and a str, but I intentionally make
    /// them two separate methods. The purpose is to remind users to use a Route when it's possible.
    fn href(mut self, route: &C::Routes) -> Self {
        self.element_updater_mut().href(route);
        self
    }

    fn id(mut self, id: &str) -> Self {
        self.element_updater_mut().id(id);
        self
    }

    fn scroll_to_top_if(self, need_to_scroll: bool) -> Self {
        if need_to_scroll {
            self.element_updater()
                .element()
                .ws_element()
                .scroll_to_view_with_bool(true);
        }
        self
    }

    fn scroll_to_bottom_if(self, need_to_scroll: bool) -> Self {
        if need_to_scroll {
            self.element_updater()
                .element()
                .ws_element()
                .scroll_to_view_with_bool(false);
        }
        self
    }
}

#[cfg(test)]
use crate::render::svg::TestSvgMethods;
make_trait_for_attribute_methods! {
    TestStructs: (TestSvgMethods)
    TraitName: SamsForDistinctNames
    attributes:
        str          accent_height "accent-height"
        str          accumulate
        str          additive
        str          alignment_baseline "alignment-baseline"
        str          allow_reorder "allowReorder"
        str          alphabetic
        str          amplitude
        str          arabic_form "arabic-form"
        str          ascent
        str          attribute_name "attributeName"
        str          attribute_type "attributeType"
        str          auto_reverse "autoReverse"
        str          azimuth
        str          base_frequency "baseFrequency"
        str          base_profile "baseProfile"
        str          baseline_shift "baseline-shift"
        str          bbox
        str          begin
        str          bias
        str          by
        str          calc_mode "calcMode"
        str          cap_height "cap-height"
        //str          class
        str          clip
        // ambiguous
        // str          clip_path "clip-path"
        str          clip_path_units "clipPathUnits"
        str          clip_rule "clip-rule"
        str          color
        str          color_interpolation "color-interpolation"
        str          color_interpolation_filters "color-interpolation-filters"
        str          color_profile "color-profile"
        str          color_rendering "color-rendering"
        str          content_script_type "contentScriptType"
        str          content_style_type "contentStyleType"
        str          cursor
        LengthPercentage          cx
        LengthPercentage          cy
        str          d
        str          decelerate
        str          descent
        str          diffuse_constant "diffuseConstant"
        str          direction
        str          display
        str          divisor
        str          dominant_baseline "dominant-baseline"
        str          dur
        LengthPercentage          dx
        LengthPercentage          dy
        str          edge_mode "edgeMode"
        str          elevation
        str          enable_background "enable-background"
        str          end
        str          exponent
        str          external_resources_required "externalResourcesRequired"
        str          fill
        str          fill_opacity "fill-opacity"
        str          fill_rule "fill-rule"
        str          filter_attr "filter"   // rename `filter` to `filter_attr` because conflicting with <filter> element
        str          filter_res "filterRes"
        str          filter_units "filterUnits"
        str          flood_color "flood-color"
        str          flood_opacity "flood-opacity"
        str          font_family "font-family"
        str          font_size "font-size"
        str          font_size_adjust "font-size-adjust"
        str          font_stretch "font-stretch"
        str          font_style "font-style"
        str          font_variant "font-variant"
        str          font_weight "font-weight"
        str          format
        str          fr
        str          from
        str          fx
        str          fy
        str          g1
        str          g2
        str          glyph_name "glyph-name"
        str          glyph_orientation_horizontal "glyph-orientation-horizontal"
        str          glyph_orientation_vertical "glyph-orientation-vertical"
        str          glyph_ref "glyphRef"
        str          gradient_transform "gradientTransform"
        str          gradient_units "gradientUnits"
        str          hanging
        LengthPercentage          height
        str          horiz_adv_x "horiz-adv-x"
        str          horiz_origin_x "horiz-origin-x"
        str          href
        str          hreflang
        //str          id
        str          ideographic
        str          image_rendering "image-rendering"
        str          r#in "in"
        str          in2
        str          intercept
        str          k
        str          k1
        str          k2
        str          k3
        str          k4
        str          kernel_matrix "kernelMatrix"
        str          kernel_unit_length "kernelUnitLength"
        str          kerning
        str          key_points "keyPoints"
        str          key_splines "keySplines"
        str          key_times "keyTimes"
        str          lang
        str          length_adjust "lengthAdjust"
        str          letter_spacing "letter-spacing"
        str          lighting_color "lighting-color"
        str          limiting_cone_angle "limitingConeAngle"
        str          local
        str          marker_end "marker-end"
        str          marker_mid "marker-mid"
        str          marker_start "marker-start"
        str          marker_height "markerHeight"
        str          marker_units "markerUnits"
        str          marker_width "markerWidth"
        // ambiguous
        // str          mask
        str          mask_content_units "maskContentUnits"
        str          mask_units "maskUnits"
        str          mathematical
        str          max
        str          media
        str          method
        str          min
        str          mode
        str          name
        str          num_octaves "numOctaves"
        str          offset
        str          opacity
        str          operator
        str          order
        str          orient
        str          orientation
        str          origin
        str          overflow
        str          overline_position "overline-position"
        str          overline_thickness "overline-thickness"
        str          paint_order "paint-order"
        str          panose_1 "panose-1"
        // ambiguous
        // str          path
        str          path_length "pathLength"
        str          pattern_content_units "patternContentUnits"
        str          pattern_transform "patternTransform"
        str          pattern_units "patternUnits"
        str          ping
        str          pointer_events "pointer-events"
        str          points
        str          points_at_x "pointsAtX"
        str          points_at_y "pointsAtY"
        str          points_at_z "pointsAtZ"
        str          preserve_alpha "preserveAlpha"
        str          preserve_aspect_ratio "preserveAspectRatio"
        str          primitive_units "primitiveUnits"
        f64          r
        str          radius
        str          ref_x "refX"
        str          ref_y "refY"
        str          referrer_policy "referrerPolicy"
        str          rel
        str          rendering_intent "rendering-intent"
        str          repeat_count "repeatCount"
        str          repeat_dur "repeatDur"
        str          required_extensions "requiredExtensions"
        str          required_features "requiredFeatures"
        str          restart
        str          result
        str          rotate
        str          rx
        str          ry
        str          scale
        str          seed
        str          shape_rendering "shape-rendering"
        str          slope
        str          spacing
        str          specular_constant "specularConstant"
        str          specular_exponent "specularExponent"
        str          speed
        str          spread_method "spreadMethod"
        str          start_offset "startOffset"
        f64          std_deviation "stdDeviation"
        str          stemh
        str          stemv
        str          stitch_tiles "stitchTiles"
        str          stop_color "stop-color"
        str          stop_opacity "stop-opacity"
        str          strikethrough_position "strikethrough-position"
        str          strikethrough_thickness "strikethrough-thickness"
        str          string
        str          stroke
        str          stroke_dasharray "stroke-dasharray"
        str          stroke_dashoffset "stroke-dashoffset"
        str          stroke_linecap "stroke-linecap"
        str          stroke_linejoin "stroke-linejoin"
        str          stroke_miterlimit "stroke-miterlimit"
        str          stroke_opacity "stroke-opacity"
        f64          stroke_width "stroke-width"
        str          style
        str          surface_scale "surfaceScale"
        str          system_language "systemLanguage"
        str          tabindex
        str          table_values "tableValues"
        str          target
        str          target_x "targetX"
        str          target_y "targetY"
        str          text_anchor "text-anchor"
        str          text_decoration "text-decoration"
        str          text_rendering "text-rendering"
        str          text_length "textLength"
        str          to
        str          transform
        str          transform_origin "transform-origin"
        str          r#type "type"
        str          u1
        str          u2
        str          underline_position "underline-position"
        str          underline_thickness "underline-thickness"
        str          unicode
        str          unicode_bidi "unicode-bidi"
        str          unicode_range "unicode-range"
        str          units_per_em "units-per-em"
        str          v_alphabetic "v-alphabetic"
        str          v_hanging "v-hanging"
        str          v_ideographic "v-ideographic"
        str          v_mathematical "v-mathematical"
        str          values
        str          vector_effect "vector-effect"
        str          version
        str          vert_adv_y "vert-adv-y"
        str          vert_origin_x "vert-origin-x"
        str          vert_origin_y "vert-origin-y"
        str          view_box "viewBox"
        str          view_target "viewTarget"
        str          visibility
        LengthPercentage          width
        str          widths
        str          word_spacing "word-spacing"
        str          writing_mode "writing-mode"
        LengthPercentage          x
        LengthPercentage          x1
        LengthPercentage          x2
        str          x_height "x-height"
        str          x_channel_selector "xChannelSelector"
        // str          xml_base "xml:base"
        str          xml_lang "xml:lang"
        // str          xml_space "xml:space"
        // str          xmlns
        // str          xmlns_xlink "xmlns:xlink"
        LengthPercentage          y
        LengthPercentage          y1
        LengthPercentage          y2
        str          y_channel_selector "yChannelSelector"
        str          z
        str          zoom_and_pan "zoomAndPan"
}

pub struct SvgAttributesOnly<'er, C: Component>(ElementUpdater<'er, C>);
pub struct SvgStaticAttributesOnly<'er, C: Component>(ElementUpdater<'er, C>);
pub struct SvgStaticAttributes<'er, C: Component>(ElementUpdater<'er, C>);

impl<'er, C: Component> SvgAttributesOnly<'er, C> {
    pub(super) fn new(er: ElementUpdater<'er, C>) -> Self {
        Self(er)
    }
    pub(super) fn into_inner(self) -> ElementUpdater<'er, C> {
        self.0
    }

    pub fn static_attributes_only(self) -> SvgStaticAttributesOnly<'er, C> {
        SvgStaticAttributesOnly::new(self.0)
    }
}

impl<'er, C: Component> SvgStaticAttributesOnly<'er, C> {
    pub(super) fn new(mut er: ElementUpdater<'er, C>) -> Self {
        er.set_static_mode();
        Self(er)
    }
    pub(super) fn into_inner(self) -> ElementUpdater<'er, C> {
        self.0
    }
}

impl<'er, C: Component> SvgStaticAttributes<'er, C> {
    pub(super) fn new(mut er: ElementUpdater<'er, C>) -> Self {
        er.set_static_mode();
        Self(er)
    }
    pub(super) fn into_inner(self) -> ElementUpdater<'er, C> {
        self.0
    }
    pub fn static_attributes_only(self) -> SvgStaticAttributesOnly<'er, C> {
        SvgStaticAttributesOnly::new(self.0)
    }
}

impl<'er, C: Component> ElementUpdaterMut<C> for SvgAttributesOnly<'er, C> {
    fn element_updater(&self) -> &ElementUpdater<C> {
        &self.0
    }
    fn element_updater_mut(&mut self) -> &'er mut ElementUpdater<C> {
        &mut self.0
    }
}

impl<'er, C: Component> ElementUpdaterMut<C> for SvgStaticAttributesOnly<'er, C> {
    fn element_updater(&self) -> &ElementUpdater<C> {
        &self.0
    }
    fn element_updater_mut(&mut self) -> &'er mut ElementUpdater<C> {
        &mut self.0
    }
}

impl<'er, C: Component> ElementUpdaterMut<C> for SvgStaticAttributes<'er, C> {
    fn element_updater(&self) -> &ElementUpdater<C> {
        &self.0
    }
    fn element_updater_mut(&mut self) -> &'er mut ElementUpdater<C> {
        &mut self.0
    }
}

impl<'er, C: Component> SamsHandMade<C> for SvgElementUpdater<'er, C> {}
impl<'er, C: Component> SamsForDistinctNames<C> for SvgElementUpdater<'er, C> {}

impl<'er, C: Component> SamsForDistinctNames<C> for SvgStaticAttributes<'er, C> {}
impl<'er, C: Component> SamsHandMade<C> for SvgStaticAttributes<'er, C> {}

impl<'er, C: Component> SamsForDistinctNames<C> for SvgStaticAttributesOnly<'er, C> {}
impl<'er, C: Component> SamsHandMade<C> for SvgStaticAttributesOnly<'er, C> {}

impl<'er, C: Component> SamsForDistinctNames<C> for SvgAttributesOnly<'er, C> {}
impl<'er, C: Component> SamsHandMade<C> for SvgAttributesOnly<'er, C> {}