tailwind-rs-core 0.15.4

Core types and utilities for tailwind-rs
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
//! Mask utilities for tailwind-rs
//!
//! This module provides utilities for CSS mask properties.
//! It includes all Tailwind CSS mask variants.

use crate::classes::ClassBuilder;
use serde::{Deserialize, Serialize};
use std::fmt;

/// Mask type values
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MaskType {
    /// No mask
    None,
    /// Alpha mask
    Alpha,
    /// Luminance mask
    Luminance,
}

impl fmt::Display for MaskType {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            MaskType::None => write!(f, "none"),
            MaskType::Alpha => write!(f, "alpha"),
            MaskType::Luminance => write!(f, "luminance"),
        }
    }
}

/// Mask mode values
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MaskMode {
    /// Alpha mask mode
    Alpha,
    /// Luminance mask mode
    Luminance,
    /// Match source mask mode
    MatchSource,
}

impl fmt::Display for MaskMode {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            MaskMode::Alpha => write!(f, "alpha"),
            MaskMode::Luminance => write!(f, "luminance"),
            MaskMode::MatchSource => write!(f, "match-source"),
        }
    }
}

/// Mask composite values
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MaskComposite {
    /// Add composite
    Add,
    /// Subtract composite
    Subtract,
    /// Intersect composite
    Intersect,
    /// Exclude composite
    Exclude,
}

impl fmt::Display for MaskComposite {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            MaskComposite::Add => write!(f, "add"),
            MaskComposite::Subtract => write!(f, "subtract"),
            MaskComposite::Intersect => write!(f, "intersect"),
            MaskComposite::Exclude => write!(f, "exclude"),
        }
    }
}

/// Mask repeat values
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MaskRepeat {
    /// No repeat
    NoRepeat,
    /// Repeat
    Repeat,
    /// Repeat X
    RepeatX,
    /// Repeat Y
    RepeatY,
    /// Round repeat
    Round,
    /// Space repeat
    Space,
}

impl fmt::Display for MaskRepeat {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            MaskRepeat::NoRepeat => write!(f, "no-repeat"),
            MaskRepeat::Repeat => write!(f, "repeat"),
            MaskRepeat::RepeatX => write!(f, "repeat-x"),
            MaskRepeat::RepeatY => write!(f, "repeat-y"),
            MaskRepeat::Round => write!(f, "round"),
            MaskRepeat::Space => write!(f, "space"),
        }
    }
}

/// Mask size values
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MaskSize {
    /// Auto size
    Auto,
    /// Cover size
    Cover,
    /// Contain size
    Contain,
}

impl fmt::Display for MaskSize {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            MaskSize::Auto => write!(f, "auto"),
            MaskSize::Cover => write!(f, "cover"),
            MaskSize::Contain => write!(f, "contain"),
        }
    }
}

/// Mask position values
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MaskPosition {
    /// Center position
    Center,
    /// Top position
    Top,
    /// Bottom position
    Bottom,
    /// Left position
    Left,
    /// Right position
    Right,
    /// Top left position
    TopLeft,
    /// Top right position
    TopRight,
    /// Bottom left position
    BottomLeft,
    /// Bottom right position
    BottomRight,
}

impl fmt::Display for MaskPosition {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            MaskPosition::Center => write!(f, "center"),
            MaskPosition::Top => write!(f, "top"),
            MaskPosition::Bottom => write!(f, "bottom"),
            MaskPosition::Left => write!(f, "left"),
            MaskPosition::Right => write!(f, "right"),
            MaskPosition::TopLeft => write!(f, "top left"),
            MaskPosition::TopRight => write!(f, "top right"),
            MaskPosition::BottomLeft => write!(f, "bottom left"),
            MaskPosition::BottomRight => write!(f, "bottom right"),
        }
    }
}

/// Mask clip values
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MaskClip {
    /// Border box clip
    BorderBox,
    /// Padding box clip
    PaddingBox,
    /// Content box clip
    ContentBox,
    /// Text clip
    Text,
}

impl fmt::Display for MaskClip {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            MaskClip::BorderBox => write!(f, "border-box"),
            MaskClip::PaddingBox => write!(f, "padding-box"),
            MaskClip::ContentBox => write!(f, "content-box"),
            MaskClip::Text => write!(f, "text"),
        }
    }
}

/// Mask origin values
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MaskOrigin {
    /// Border box origin
    BorderBox,
    /// Padding box origin
    PaddingBox,
    /// Content box origin
    ContentBox,
}

impl fmt::Display for MaskOrigin {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            MaskOrigin::BorderBox => write!(f, "border-box"),
            MaskOrigin::PaddingBox => write!(f, "padding-box"),
            MaskOrigin::ContentBox => write!(f, "content-box"),
        }
    }
}

/// Trait for adding mask utilities to ClassBuilder
pub trait MaskUtilities {
    /// Set mask to none
    fn mask_none(self) -> Self;
    /// Set mask to alpha
    fn mask_alpha(self) -> Self;
    /// Set mask to luminance
    fn mask_luminance(self) -> Self;
    /// Set mask repeat to none
    fn mask_repeat_none(self) -> Self;
    /// Set mask repeat to default
    fn mask_repeat(self) -> Self;
    /// Set mask repeat to X
    fn mask_repeat_x(self) -> Self;
    /// Set mask repeat to Y
    fn mask_repeat_y(self) -> Self;
    /// Set mask repeat to round
    fn mask_repeat_round(self) -> Self;
    /// Set mask repeat to space
    fn mask_repeat_space(self) -> Self;
    /// Set mask size to auto
    fn mask_size_auto(self) -> Self;
    /// Set mask size to cover
    fn mask_size_cover(self) -> Self;
    /// Set mask size to contain
    fn mask_size_contain(self) -> Self;
    /// Set mask position to center
    fn mask_center(self) -> Self;
    /// Set mask position to top
    fn mask_top(self) -> Self;
    /// Set mask position to bottom
    fn mask_bottom(self) -> Self;
    /// Set mask position to left
    fn mask_left(self) -> Self;
    /// Set mask position to right
    fn mask_right(self) -> Self;
    /// Set mask position to top left
    fn mask_top_left(self) -> Self;
    /// Set mask position to top right
    fn mask_top_right(self) -> Self;
    /// Set mask position to bottom left
    fn mask_bottom_left(self) -> Self;
    /// Set mask position to bottom right
    fn mask_bottom_right(self) -> Self;
    /// Set mask clip to border
    fn mask_clip_border(self) -> Self;
    /// Set mask clip to padding
    fn mask_clip_padding(self) -> Self;
    /// Set mask clip to content
    fn mask_clip_content(self) -> Self;
    /// Set mask clip to text
    fn mask_clip_text(self) -> Self;
    /// Set mask origin to border
    fn mask_origin_border(self) -> Self;
    /// Set mask origin to padding
    fn mask_origin_padding(self) -> Self;
    /// Set mask origin to content
    fn mask_origin_content(self) -> Self;
}

impl MaskUtilities for ClassBuilder {
    fn mask_none(self) -> Self {
        self.class("mask-none")
    }

    fn mask_alpha(self) -> Self {
        self.class("mask-alpha")
    }

    fn mask_luminance(self) -> Self {
        self.class("mask-luminance")
    }

    fn mask_repeat_none(self) -> Self {
        self.class("mask-repeat-none")
    }

    fn mask_repeat(self) -> Self {
        self.class("mask-repeat")
    }

    fn mask_repeat_x(self) -> Self {
        self.class("mask-repeat-x")
    }

    fn mask_repeat_y(self) -> Self {
        self.class("mask-repeat-y")
    }

    fn mask_repeat_round(self) -> Self {
        self.class("mask-repeat-round")
    }

    fn mask_repeat_space(self) -> Self {
        self.class("mask-repeat-space")
    }

    fn mask_size_auto(self) -> Self {
        self.class("mask-size-auto")
    }

    fn mask_size_cover(self) -> Self {
        self.class("mask-size-cover")
    }

    fn mask_size_contain(self) -> Self {
        self.class("mask-size-contain")
    }

    fn mask_center(self) -> Self {
        self.class("mask-center")
    }

    fn mask_top(self) -> Self {
        self.class("mask-top")
    }

    fn mask_bottom(self) -> Self {
        self.class("mask-bottom")
    }

    fn mask_left(self) -> Self {
        self.class("mask-left")
    }

    fn mask_right(self) -> Self {
        self.class("mask-right")
    }

    fn mask_top_left(self) -> Self {
        self.class("mask-top-left")
    }

    fn mask_top_right(self) -> Self {
        self.class("mask-top-right")
    }

    fn mask_bottom_left(self) -> Self {
        self.class("mask-bottom-left")
    }

    fn mask_bottom_right(self) -> Self {
        self.class("mask-bottom-right")
    }

    fn mask_clip_border(self) -> Self {
        self.class("mask-clip-border")
    }

    fn mask_clip_padding(self) -> Self {
        self.class("mask-clip-padding")
    }

    fn mask_clip_content(self) -> Self {
        self.class("mask-clip-content")
    }

    fn mask_clip_text(self) -> Self {
        self.class("mask-clip-text")
    }

    fn mask_origin_border(self) -> Self {
        self.class("mask-origin-border")
    }

    fn mask_origin_padding(self) -> Self {
        self.class("mask-origin-padding")
    }

    fn mask_origin_content(self) -> Self {
        self.class("mask-origin-content")
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::classes::ClassBuilder;

    #[test]
    fn test_mask_type_enum_values() {
        assert_eq!(MaskType::None.to_string(), "none");
        assert_eq!(MaskType::Alpha.to_string(), "alpha");
        assert_eq!(MaskType::Luminance.to_string(), "luminance");
    }

    #[test]
    fn test_mask_mode_enum_values() {
        assert_eq!(MaskMode::Alpha.to_string(), "alpha");
        assert_eq!(MaskMode::Luminance.to_string(), "luminance");
        assert_eq!(MaskMode::MatchSource.to_string(), "match-source");
    }

    #[test]
    fn test_mask_composite_enum_values() {
        assert_eq!(MaskComposite::Add.to_string(), "add");
        assert_eq!(MaskComposite::Subtract.to_string(), "subtract");
        assert_eq!(MaskComposite::Intersect.to_string(), "intersect");
        assert_eq!(MaskComposite::Exclude.to_string(), "exclude");
    }

    #[test]
    fn test_mask_repeat_enum_values() {
        assert_eq!(MaskRepeat::NoRepeat.to_string(), "no-repeat");
        assert_eq!(MaskRepeat::Repeat.to_string(), "repeat");
        assert_eq!(MaskRepeat::RepeatX.to_string(), "repeat-x");
        assert_eq!(MaskRepeat::RepeatY.to_string(), "repeat-y");
        assert_eq!(MaskRepeat::Round.to_string(), "round");
        assert_eq!(MaskRepeat::Space.to_string(), "space");
    }

    #[test]
    fn test_mask_size_enum_values() {
        assert_eq!(MaskSize::Auto.to_string(), "auto");
        assert_eq!(MaskSize::Cover.to_string(), "cover");
        assert_eq!(MaskSize::Contain.to_string(), "contain");
    }

    #[test]
    fn test_mask_position_enum_values() {
        assert_eq!(MaskPosition::Center.to_string(), "center");
        assert_eq!(MaskPosition::Top.to_string(), "top");
        assert_eq!(MaskPosition::Bottom.to_string(), "bottom");
        assert_eq!(MaskPosition::Left.to_string(), "left");
        assert_eq!(MaskPosition::Right.to_string(), "right");
        assert_eq!(MaskPosition::TopLeft.to_string(), "top left");
        assert_eq!(MaskPosition::TopRight.to_string(), "top right");
        assert_eq!(MaskPosition::BottomLeft.to_string(), "bottom left");
        assert_eq!(MaskPosition::BottomRight.to_string(), "bottom right");
    }

    #[test]
    fn test_mask_clip_enum_values() {
        assert_eq!(MaskClip::BorderBox.to_string(), "border-box");
        assert_eq!(MaskClip::PaddingBox.to_string(), "padding-box");
        assert_eq!(MaskClip::ContentBox.to_string(), "content-box");
        assert_eq!(MaskClip::Text.to_string(), "text");
    }

    #[test]
    fn test_mask_origin_enum_values() {
        assert_eq!(MaskOrigin::BorderBox.to_string(), "border-box");
        assert_eq!(MaskOrigin::PaddingBox.to_string(), "padding-box");
        assert_eq!(MaskOrigin::ContentBox.to_string(), "content-box");
    }

    #[test]
    fn test_mask_utilities() {
        let classes = ClassBuilder::new()
            .mask_alpha()
            .mask_repeat_round()
            .mask_size_cover()
            .mask_center()
            .mask_clip_border()
            .mask_origin_padding();

        let result = classes.build();
        assert!(result.classes.contains("mask-alpha"));
        assert!(result.classes.contains("mask-repeat-round"));
        assert!(result.classes.contains("mask-size-cover"));
        assert!(result.classes.contains("mask-center"));
        assert!(result.classes.contains("mask-clip-border"));
        assert!(result.classes.contains("mask-origin-padding"));
    }

    #[test]
    fn test_mask_serialization() {
        let mask_type = MaskType::Alpha;
        let serialized = serde_json::to_string(&mask_type).unwrap();
        let deserialized: MaskType = serde_json::from_str(&serialized).unwrap();
        assert_eq!(mask_type, deserialized);
    }

    #[test]
    fn test_mask_comprehensive_usage() {
        let classes = ClassBuilder::new()
            .mask_luminance()
            .mask_repeat_round()
            .mask_size_contain()
            .mask_top_left();

        let result = classes.build();
        assert!(result.classes.contains("mask-luminance"));
        assert!(result.classes.contains("mask-repeat-round"));
        assert!(result.classes.contains("mask-size-contain"));
        assert!(result.classes.contains("mask-top-left"));
    }
}