Skip to main content

azul_css/props/style/
text.rs

1//! CSS properties for styling text.
2//!
3//! Each property type implements `PrintAsCssValue` for CSS serialization and
4//! (behind the `parser` feature) has a corresponding `parse_style_*` function
5//! with borrowed/owned error type pairs.
6
7use alloc::string::{String, ToString};
8use core::fmt;
9use crate::corety::AzString;
10
11use crate::{
12    codegen::format::FormatAsRustCode,
13    props::{
14        basic::{
15            error::{InvalidValueErr, InvalidValueErrOwned},
16            length::{PercentageParseError, PercentageParseErrorOwned, PercentageValue},
17            pixel::{CssPixelValueParseError, CssPixelValueParseErrorOwned, PixelValue},
18            ColorU, CssDuration,
19        },
20        formatter::PrintAsCssValue,
21        macros::PixelValueTaker,
22    },
23};
24
25// -- StyleTextColor (color property) --
26// NOTE: `color` is a text property, but the `ColorU` type itself is in `basic/color.rs`.
27// This is a newtype wrapper for type safety.
28
29/// Represents a `color` attribute.
30#[derive(Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
31#[repr(C)]
32pub struct StyleTextColor {
33    pub inner: ColorU,
34}
35
36impl fmt::Debug for StyleTextColor {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        write!(f, "{}", self.print_as_css_value())
39    }
40}
41
42impl StyleTextColor {
43    #[must_use] pub fn interpolate(&self, other: &Self, t: f32) -> Self {
44        Self {
45            inner: self.inner.interpolate(&other.inner, t),
46        }
47    }
48}
49
50impl PrintAsCssValue for StyleTextColor {
51    fn print_as_css_value(&self) -> String {
52        self.inner.to_hash()
53    }
54}
55
56// -- StyleTextAlign --
57
58/// Horizontal text alignment enum (left, center, right) - default: `Left`
59#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
60#[repr(C)]
61pub enum StyleTextAlign {
62    Left,
63    Center,
64    Right,
65    Justify,
66    #[default]
67    Start,
68    End,
69}
70
71impl_option!(
72    StyleTextAlign,
73    OptionStyleTextAlign,
74    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
75);
76
77impl PrintAsCssValue for StyleTextAlign {
78    fn print_as_css_value(&self) -> String {
79        String::from(match self {
80            Self::Left => "left",
81            Self::Center => "center",
82            Self::Right => "right",
83            Self::Justify => "justify",
84            Self::Start => "start",
85            Self::End => "end",
86        })
87    }
88}
89
90// -- StyleLetterSpacing --
91
92/// Represents a `letter-spacing` attribute
93#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
94#[repr(C)]
95pub struct StyleLetterSpacing {
96    pub inner: PixelValue,
97}
98
99impl fmt::Debug for StyleLetterSpacing {
100    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
101        write!(f, "{}", self.inner)
102    }
103}
104impl Default for StyleLetterSpacing {
105    fn default() -> Self {
106        Self {
107            inner: PixelValue::const_px(0),
108        }
109    }
110}
111impl_pixel_value!(StyleLetterSpacing);
112impl PixelValueTaker for StyleLetterSpacing {
113    fn from_pixel_value(inner: PixelValue) -> Self {
114        Self { inner }
115    }
116}
117impl PrintAsCssValue for StyleLetterSpacing {
118    fn print_as_css_value(&self) -> String {
119        format!("{}", self.inner)
120    }
121}
122
123// -- StyleWordSpacing --
124
125/// Represents a `word-spacing` attribute
126#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
127#[repr(C)]
128pub struct StyleWordSpacing {
129    pub inner: PixelValue,
130}
131
132impl fmt::Debug for StyleWordSpacing {
133    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
134        write!(f, "{}", self.inner)
135    }
136}
137impl Default for StyleWordSpacing {
138    fn default() -> Self {
139        Self {
140            inner: PixelValue::const_px(0),
141        }
142    }
143}
144impl_pixel_value!(StyleWordSpacing);
145impl PixelValueTaker for StyleWordSpacing {
146    fn from_pixel_value(inner: PixelValue) -> Self {
147        Self { inner }
148    }
149}
150impl PrintAsCssValue for StyleWordSpacing {
151    fn print_as_css_value(&self) -> String {
152        format!("{}", self.inner)
153    }
154}
155
156// -- StyleLineHeight --
157
158/// Represents a `line-height` attribute
159#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
160#[repr(C)]
161pub struct StyleLineHeight {
162    pub inner: PercentageValue,
163}
164impl Default for StyleLineHeight {
165    fn default() -> Self {
166        Self {
167            inner: PercentageValue::const_new(120),
168        }
169    }
170}
171impl_percentage_value!(StyleLineHeight);
172impl PrintAsCssValue for StyleLineHeight {
173    fn print_as_css_value(&self) -> String {
174        format!("{}", self.inner)
175    }
176}
177
178// -- StyleTabSize --
179
180/// Represents a `tab-size` attribute
181#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
182#[repr(C)]
183pub struct StyleTabSize {
184    pub inner: PixelValue, // Can be a number (space characters, em-based) or a length
185}
186
187impl fmt::Debug for StyleTabSize {
188    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
189        write!(f, "{}", self.inner)
190    }
191}
192impl Default for StyleTabSize {
193    fn default() -> Self {
194        Self {
195            inner: PixelValue::em(8.0),
196        }
197    }
198}
199impl_pixel_value!(StyleTabSize);
200impl PixelValueTaker for StyleTabSize {
201    fn from_pixel_value(inner: PixelValue) -> Self {
202        Self { inner }
203    }
204}
205impl PrintAsCssValue for StyleTabSize {
206    fn print_as_css_value(&self) -> String {
207        format!("{}", self.inner)
208    }
209}
210
211// -- StyleWhiteSpace --
212
213/// How to handle white space inside an element.
214/// 
215/// CSS Text Level 3: <https://www.w3.org/TR/css-text-3/#white-space-property>
216#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
217#[repr(C)]
218#[derive(Default)]
219pub enum StyleWhiteSpace {
220    /// Collapse whitespace, wrap lines
221    #[default]
222    Normal,
223    /// Preserve whitespace, no wrap (except for explicit breaks)
224    Pre,
225    /// Collapse whitespace, no wrap
226    Nowrap,
227    /// Preserve whitespace, wrap lines
228    PreWrap,
229    /// Collapse whitespace (except newlines), wrap lines
230    PreLine,
231    /// Preserve whitespace, allow breaking at spaces
232    BreakSpaces,
233}
234impl_option!(
235    StyleWhiteSpace,
236    OptionStyleWhiteSpace,
237    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
238);
239impl PrintAsCssValue for StyleWhiteSpace {
240    fn print_as_css_value(&self) -> String {
241        String::from(match self {
242            Self::Normal => "normal",
243            Self::Pre => "pre",
244            Self::Nowrap => "nowrap",
245            Self::PreWrap => "pre-wrap",
246            Self::PreLine => "pre-line",
247            Self::BreakSpaces => "break-spaces",
248        })
249    }
250}
251
252// -- StyleHyphens --
253
254/// Hyphenation rules.
255#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
256#[repr(C)]
257#[derive(Default)]
258pub enum StyleHyphens {
259    /// No hyphenation: words are not broken at hyphenation opportunities.
260    None,
261    /// Manual hyphenation: words are only broken at explicit soft hyphens (U+00AD)
262    /// or unconditional hyphens (U+2010).
263    #[default]
264    Manual,
265    /// Automatic hyphenation: words may be broken at automatic hyphenation
266    /// opportunities determined by a language-appropriate hyphenation resource,
267    /// in addition to explicit opportunities.
268    Auto,
269}
270impl_option!(
271    StyleHyphens,
272    OptionStyleHyphens,
273    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
274);
275impl PrintAsCssValue for StyleHyphens {
276    fn print_as_css_value(&self) -> String {
277        String::from(match self {
278            Self::None => "none",
279            Self::Manual => "manual",
280            Self::Auto => "auto",
281        })
282    }
283}
284
285// -- StyleLineBreak --
286
287/// Controls the strictness of line breaking rules.
288///
289/// CSS Text Level 3: <https://www.w3.org/TR/css-text-3/#line-break-property>
290#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
291#[repr(C)]
292#[derive(Default)]
293pub enum StyleLineBreak {
294    /// The browser determines the set of line-breaking restrictions to use.
295    #[default]
296    Auto,
297    /// Breaks text using the least restrictive set of line-breaking rules.
298    Loose,
299    /// Breaks text using the most common set of line-breaking rules.
300    Normal,
301    /// Breaks text using the most stringent set of line-breaking rules.
302    Strict,
303    /// There is a soft wrap opportunity around every typographic character unit,
304    /// including around any punctuation character or preserved white spaces,
305    /// or in the middle of words, disregarding any prohibition against line breaks.
306    Anywhere,
307}
308impl_option!(
309    StyleLineBreak,
310    OptionStyleLineBreak,
311    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
312);
313impl PrintAsCssValue for StyleLineBreak {
314    fn print_as_css_value(&self) -> String {
315        String::from(match self {
316            Self::Auto => "auto",
317            Self::Loose => "loose",
318            Self::Normal => "normal",
319            Self::Strict => "strict",
320            Self::Anywhere => "anywhere",
321        })
322    }
323}
324
325// -- StyleWordBreak --
326
327/// Controls line breaking rules within words.
328///
329/// CSS Text Level 3 §5.2: <https://www.w3.org/TR/css-text-3/#word-break-property>
330#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
331#[repr(C)]
332#[derive(Default)]
333pub enum StyleWordBreak {
334    /// Use default line break rules.
335    #[default]
336    Normal,
337    /// Allow break opportunities between any two characters (CJK and non-CJK).
338    BreakAll,
339    /// Forbid break opportunities within CJK character sequences.
340    KeepAll,
341    // +spec:line-breaking:815882 - deprecated break-word keyword: same as normal + overflow-wrap: anywhere
342    /// Deprecated: equivalent to word-break: normal and overflow-wrap: anywhere.
343    BreakWord,
344}
345impl_option!(
346    StyleWordBreak,
347    OptionStyleWordBreak,
348    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
349);
350impl PrintAsCssValue for StyleWordBreak {
351    fn print_as_css_value(&self) -> String {
352        String::from(match self {
353            Self::Normal => "normal",
354            Self::BreakAll => "break-all",
355            Self::KeepAll => "keep-all",
356            Self::BreakWord => "break-word",
357        })
358    }
359}
360
361// -- StyleOverflowWrap --
362
363/// Controls whether the browser may break at otherwise disallowed points
364/// to prevent overflow.
365///
366/// CSS Text Level 3 §3.3: <https://www.w3.org/TR/css-text-3/#overflow-wrap-property>
367#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
368#[repr(C)]
369#[derive(Default)]
370pub enum StyleOverflowWrap {
371    /// Lines may only break at allowed break points.
372    #[default]
373    Normal,
374    /// An otherwise unbreakable sequence may be broken at an arbitrary point
375    /// if there are no otherwise acceptable break points.
376    Anywhere,
377    /// Same as `anywhere` but soft wrap opportunities introduced are not
378    /// considered when calculating min-content intrinsic sizes.
379    BreakWord,
380}
381impl_option!(
382    StyleOverflowWrap,
383    OptionStyleOverflowWrap,
384    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
385);
386impl PrintAsCssValue for StyleOverflowWrap {
387    fn print_as_css_value(&self) -> String {
388        String::from(match self {
389            Self::Normal => "normal",
390            Self::Anywhere => "anywhere",
391            Self::BreakWord => "break-word",
392        })
393    }
394}
395
396// -- StyleTextAlignLast --
397
398/// Controls alignment of the last line of a block or a line right before
399/// a forced line break.
400///
401/// CSS Text Level 3 §7.2: <https://www.w3.org/TR/css-text-3/#text-align-last-property>
402#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
403#[repr(C)]
404#[derive(Default)]
405pub enum StyleTextAlignLast {
406    /// Alignment of the last line is determined by text-align (or start if justify).
407    #[default]
408    Auto,
409    /// Align to the start edge of the line box.
410    Start,
411    /// Align to the end edge of the line box.
412    End,
413    /// Align to the line left.
414    Left,
415    /// Align to the line right.
416    Right,
417    /// Center the content.
418    Center,
419    /// Justify the content.
420    Justify,
421}
422impl_option!(
423    StyleTextAlignLast,
424    OptionStyleTextAlignLast,
425    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
426);
427impl PrintAsCssValue for StyleTextAlignLast {
428    fn print_as_css_value(&self) -> String {
429        String::from(match self {
430            Self::Auto => "auto",
431            Self::Start => "start",
432            Self::End => "end",
433            Self::Left => "left",
434            Self::Right => "right",
435            Self::Center => "center",
436            Self::Justify => "justify",
437        })
438    }
439}
440
441// -- StyleTextTransform --
442
443/// Controls capitalization of a text run (applied before shaping).
444///
445/// CSS Text Level 3 §2.1: <https://www.w3.org/TR/css-text-3/#text-transform-property>
446#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
447#[repr(C)]
448#[derive(Default)]
449pub enum StyleTextTransform {
450    /// No capitalization effect.
451    #[default]
452    None,
453    /// Uppercase the first typographic letter unit of each word.
454    Capitalize,
455    /// Uppercase every typographic letter unit.
456    Uppercase,
457    /// Lowercase every typographic letter unit.
458    Lowercase,
459    /// Map to the full-width form where available.
460    FullWidth,
461}
462impl_option!(
463    StyleTextTransform,
464    OptionStyleTextTransform,
465    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
466);
467impl PrintAsCssValue for StyleTextTransform {
468    fn print_as_css_value(&self) -> String {
469        String::from(match self {
470            Self::None => "none",
471            Self::Capitalize => "capitalize",
472            Self::Uppercase => "uppercase",
473            Self::Lowercase => "lowercase",
474            Self::FullWidth => "full-width",
475        })
476    }
477}
478
479// -- StyleDirection --
480
481/// Text direction.
482// +spec:writing-modes:46fed3 - direction property provides explicit bidi controls in CSS
483#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
484#[repr(C)]
485#[derive(Default)]
486pub enum StyleDirection {
487    /// Left-to-right text direction
488    #[default]
489    Ltr,
490    /// Right-to-left text direction
491    Rtl,
492}
493impl_option!(
494    StyleDirection,
495    OptionStyleDirection,
496    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
497);
498impl PrintAsCssValue for StyleDirection {
499    fn print_as_css_value(&self) -> String {
500        String::from(match self {
501            Self::Ltr => "ltr",
502            Self::Rtl => "rtl",
503        })
504    }
505}
506
507// -- StyleUserSelect --
508
509/// Controls whether the user can select text.
510/// Used to prevent accidental text selection on UI controls like buttons.
511#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
512#[repr(C)]
513#[derive(Default)]
514pub enum StyleUserSelect {
515    /// Browser determines selectability (default)
516    #[default]
517    Auto,
518    /// Text is selectable
519    Text,
520    /// Text is not selectable
521    None,
522    /// User can select all text with a single action
523    All,
524}
525impl_option!(
526    StyleUserSelect,
527    OptionStyleUserSelect,
528    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
529);
530impl PrintAsCssValue for StyleUserSelect {
531    fn print_as_css_value(&self) -> String {
532        String::from(match self {
533            Self::Auto => "auto",
534            Self::Text => "text",
535            Self::None => "none",
536            Self::All => "all",
537        })
538    }
539}
540
541// -- StyleTextDecoration --
542
543/// Text decoration (underline, overline, line-through).
544#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
545#[repr(C)]
546#[derive(Default)]
547pub enum StyleTextDecoration {
548    /// No decoration
549    #[default]
550    None,
551    /// Underline
552    Underline,
553    /// Line above text
554    Overline,
555    /// Strike-through line
556    LineThrough,
557}
558impl_option!(
559    StyleTextDecoration,
560    OptionStyleTextDecoration,
561    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
562);
563impl PrintAsCssValue for StyleTextDecoration {
564    fn print_as_css_value(&self) -> String {
565        String::from(match self {
566            Self::None => "none",
567            Self::Underline => "underline",
568            Self::Overline => "overline",
569            Self::LineThrough => "line-through",
570        })
571    }
572}
573
574// -- StyleVerticalAlign --
575
576/// CSS 2.2 §10.8.1 vertical-align property values
577#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
578#[repr(C, u8)]
579#[derive(Default)]
580pub enum StyleVerticalAlign {
581    /// CSS default - align baselines
582    #[default]
583    Baseline,
584    /// Align top of element with top of line box
585    Top,
586    /// Align middle of element with baseline + half x-height
587    Middle,
588    /// Align bottom of element with bottom of line box
589    Bottom,
590    /// Align baseline with parent's subscript baseline
591    Sub,
592    /// Align baseline with parent's superscript baseline
593    Superscript,
594    /// Align top with top of parent's font
595    TextTop,
596    /// Align bottom with bottom of parent's font
597    TextBottom,
598    /// <percentage> refers to line-height of the element itself
599    Percentage(PercentageValue),
600    /// <length> offset from baseline
601    Length(PixelValue),
602}
603
604impl_option!(
605    StyleVerticalAlign,
606    OptionStyleVerticalAlign,
607    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
608);
609
610impl PrintAsCssValue for StyleVerticalAlign {
611    fn print_as_css_value(&self) -> String {
612        match self {
613            Self::Baseline => String::from("baseline"),
614            Self::Top => String::from("top"),
615            Self::Middle => String::from("middle"),
616            Self::Bottom => String::from("bottom"),
617            Self::Sub => String::from("sub"),
618            Self::Superscript => String::from("super"),
619            Self::TextTop => String::from("text-top"),
620            Self::TextBottom => String::from("text-bottom"),
621            Self::Percentage(p) => format!("{}%", p.normalized() * 100.0),
622            Self::Length(l) => l.print_as_css_value(),
623        }
624    }
625}
626
627impl FormatAsRustCode for StyleVerticalAlign {
628    fn format_as_rust_code(&self, indent: usize) -> String {
629        match self {
630            Self::Baseline => "StyleVerticalAlign::Baseline".to_string(),
631            Self::Top => "StyleVerticalAlign::Top".to_string(),
632            Self::Middle => "StyleVerticalAlign::Middle".to_string(),
633            Self::Bottom => "StyleVerticalAlign::Bottom".to_string(),
634            Self::Sub => "StyleVerticalAlign::Sub".to_string(),
635            Self::Superscript => "StyleVerticalAlign::Superscript".to_string(),
636            Self::TextTop => "StyleVerticalAlign::TextTop".to_string(),
637            Self::TextBottom => "StyleVerticalAlign::TextBottom".to_string(),
638            Self::Percentage(p) => format!("StyleVerticalAlign::Percentage(PercentageValue::new({}))", p.normalized() * 100.0),
639            Self::Length(l) => format!("StyleVerticalAlign::Length({l})"),
640        }
641    }
642}
643
644// --- PARSERS ---
645
646#[cfg(feature = "parser")]
647use crate::props::basic::{
648    color::{parse_css_color, CssColorParseError, CssColorParseErrorOwned},
649    DurationParseError,
650};
651
652#[cfg(feature = "parser")]
653#[derive(Clone, PartialEq)]
654pub enum StyleTextColorParseError<'a> {
655    ColorParseError(CssColorParseError<'a>),
656}
657#[cfg(feature = "parser")]
658impl_debug_as_display!(StyleTextColorParseError<'a>);
659#[cfg(feature = "parser")]
660impl_display! { StyleTextColorParseError<'a>, {
661    ColorParseError(e) => format!("Invalid color: {}", e),
662}}
663#[cfg(feature = "parser")]
664impl_from!(
665    CssColorParseError<'a>,
666    StyleTextColorParseError::ColorParseError
667);
668
669#[cfg(feature = "parser")]
670#[derive(Debug, Clone, PartialEq)]
671#[repr(C, u8)]
672pub enum StyleTextColorParseErrorOwned {
673    ColorParseError(CssColorParseErrorOwned),
674}
675
676#[cfg(feature = "parser")]
677impl StyleTextColorParseError<'_> {
678    #[must_use] pub fn to_contained(&self) -> StyleTextColorParseErrorOwned {
679        match self {
680            Self::ColorParseError(e) => {
681                StyleTextColorParseErrorOwned::ColorParseError(e.to_contained())
682            }
683        }
684    }
685}
686
687#[cfg(feature = "parser")]
688impl StyleTextColorParseErrorOwned {
689    #[must_use] pub fn to_shared(&self) -> StyleTextColorParseError<'_> {
690        match self {
691            Self::ColorParseError(e) => StyleTextColorParseError::ColorParseError(e.to_shared()),
692        }
693    }
694}
695
696#[cfg(feature = "parser")]
697/// # Errors
698///
699/// Returns an error if `input` is not a valid CSS `text-color` value.
700pub fn parse_style_text_color(input: &str) -> Result<StyleTextColor, StyleTextColorParseError<'_>> {
701    parse_css_color(input)
702        .map(|inner| StyleTextColor { inner })
703        .map_err(StyleTextColorParseError::ColorParseError)
704}
705
706#[cfg(feature = "parser")]
707#[derive(Clone, PartialEq, Eq)]
708pub enum StyleTextAlignParseError<'a> {
709    InvalidValue(InvalidValueErr<'a>),
710}
711#[cfg(feature = "parser")]
712impl_debug_as_display!(StyleTextAlignParseError<'a>);
713#[cfg(feature = "parser")]
714impl_display! { StyleTextAlignParseError<'a>, {
715    InvalidValue(e) => format!("Invalid text-align value: \"{}\"", e.0),
716}}
717#[cfg(feature = "parser")]
718impl_from!(InvalidValueErr<'a>, StyleTextAlignParseError::InvalidValue);
719
720#[cfg(feature = "parser")]
721#[derive(Debug, Clone, PartialEq, Eq)]
722#[repr(C, u8)]
723pub enum StyleTextAlignParseErrorOwned {
724    InvalidValue(InvalidValueErrOwned),
725}
726
727#[cfg(feature = "parser")]
728impl StyleTextAlignParseError<'_> {
729    #[must_use] pub fn to_contained(&self) -> StyleTextAlignParseErrorOwned {
730        match self {
731            Self::InvalidValue(e) => StyleTextAlignParseErrorOwned::InvalidValue(e.to_contained()),
732        }
733    }
734}
735
736#[cfg(feature = "parser")]
737impl StyleTextAlignParseErrorOwned {
738    #[must_use] pub fn to_shared(&self) -> StyleTextAlignParseError<'_> {
739        match self {
740            Self::InvalidValue(e) => StyleTextAlignParseError::InvalidValue(e.to_shared()),
741        }
742    }
743}
744
745#[cfg(feature = "parser")]
746/// # Errors
747///
748/// Returns an error if `input` is not a valid CSS `text-align` value.
749pub fn parse_style_text_align(input: &str) -> Result<StyleTextAlign, StyleTextAlignParseError<'_>> {
750    match input.trim() {
751        "left" => Ok(StyleTextAlign::Left),
752        "center" => Ok(StyleTextAlign::Center),
753        "right" => Ok(StyleTextAlign::Right),
754        "justify" => Ok(StyleTextAlign::Justify),
755        "start" => Ok(StyleTextAlign::Start),
756        "end" => Ok(StyleTextAlign::End),
757        other => Err(StyleTextAlignParseError::InvalidValue(InvalidValueErr(
758            other,
759        ))),
760    }
761}
762
763#[cfg(feature = "parser")]
764#[derive(Clone, PartialEq, Eq)]
765pub enum StyleLetterSpacingParseError<'a> {
766    PixelValue(CssPixelValueParseError<'a>),
767}
768#[cfg(feature = "parser")]
769impl_debug_as_display!(StyleLetterSpacingParseError<'a>);
770#[cfg(feature = "parser")]
771impl_display! { StyleLetterSpacingParseError<'a>, {
772    PixelValue(e) => format!("Invalid letter-spacing value: {}", e),
773}}
774#[cfg(feature = "parser")]
775impl_from!(
776    CssPixelValueParseError<'a>,
777    StyleLetterSpacingParseError::PixelValue
778);
779
780#[cfg(feature = "parser")]
781#[derive(Debug, Clone, PartialEq, Eq)]
782#[repr(C, u8)]
783pub enum StyleLetterSpacingParseErrorOwned {
784    PixelValue(CssPixelValueParseErrorOwned),
785}
786
787#[cfg(feature = "parser")]
788impl StyleLetterSpacingParseError<'_> {
789    #[must_use] pub fn to_contained(&self) -> StyleLetterSpacingParseErrorOwned {
790        match self {
791            Self::PixelValue(e) => StyleLetterSpacingParseErrorOwned::PixelValue(e.to_contained()),
792        }
793    }
794}
795
796#[cfg(feature = "parser")]
797impl StyleLetterSpacingParseErrorOwned {
798    #[must_use] pub fn to_shared(&self) -> StyleLetterSpacingParseError<'_> {
799        match self {
800            Self::PixelValue(e) => StyleLetterSpacingParseError::PixelValue(e.to_shared()),
801        }
802    }
803}
804
805#[cfg(feature = "parser")]
806/// # Errors
807///
808/// Returns an error if `input` is not a valid CSS `letter-spacing` value.
809pub fn parse_style_letter_spacing(
810    input: &str,
811) -> Result<StyleLetterSpacing, StyleLetterSpacingParseError<'_>> {
812    crate::props::basic::pixel::parse_pixel_value(input)
813        .map(|inner| StyleLetterSpacing { inner })
814        .map_err(StyleLetterSpacingParseError::PixelValue)
815}
816
817// -- StyleTextIndent (text-indent property) --
818
819/// Represents a `text-indent` attribute (indentation of first line in a block).
820#[derive(Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
821#[repr(C)]
822pub struct StyleTextIndent {
823    pub inner: PixelValue,
824    /// `each-line` keyword: indent first line of each block container
825    /// AND each line after a forced line break (but not after soft wrap).
826    pub each_line: bool,
827    /// `hanging` keyword: inverts which lines are affected by the indent.
828    pub hanging: bool,
829}
830
831impl fmt::Debug for StyleTextIndent {
832    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
833        write!(f, "{}", self.print_as_css_value())
834    }
835}
836
837impl StyleTextIndent {
838    #[inline]
839    #[must_use] pub const fn zero() -> Self {
840        Self { inner: PixelValue::zero(), each_line: false, hanging: false }
841    }
842    #[inline]
843    #[must_use] pub const fn const_px(value: isize) -> Self {
844        Self { inner: PixelValue::const_px(value), each_line: false, hanging: false }
845    }
846    #[inline]
847    #[must_use] pub const fn const_em(value: isize) -> Self {
848        Self { inner: PixelValue::const_em(value), each_line: false, hanging: false }
849    }
850    #[inline]
851    #[must_use] pub const fn const_pt(value: isize) -> Self {
852        Self { inner: PixelValue::const_pt(value), each_line: false, hanging: false }
853    }
854    #[inline]
855    #[must_use] pub const fn const_percent(value: isize) -> Self {
856        Self { inner: PixelValue::const_percent(value), each_line: false, hanging: false }
857    }
858    #[inline]
859    #[must_use] pub const fn const_in(value: isize) -> Self {
860        Self { inner: PixelValue::const_in(value), each_line: false, hanging: false }
861    }
862    #[inline]
863    #[must_use] pub const fn const_cm(value: isize) -> Self {
864        Self { inner: PixelValue::const_cm(value), each_line: false, hanging: false }
865    }
866    #[inline]
867    #[must_use] pub const fn const_mm(value: isize) -> Self {
868        Self { inner: PixelValue::const_mm(value), each_line: false, hanging: false }
869    }
870    #[inline]
871    #[must_use] pub const fn const_from_metric(metric: crate::props::basic::length::SizeMetric, value: isize) -> Self {
872        Self { inner: PixelValue::const_from_metric(metric, value), each_line: false, hanging: false }
873    }
874    #[inline]
875    #[must_use] pub fn px(value: f32) -> Self {
876        Self { inner: PixelValue::px(value), each_line: false, hanging: false }
877    }
878    #[inline]
879    #[must_use] pub fn em(value: f32) -> Self {
880        Self { inner: PixelValue::em(value), each_line: false, hanging: false }
881    }
882    #[inline]
883    #[must_use] pub fn pt(value: f32) -> Self {
884        Self { inner: PixelValue::pt(value), each_line: false, hanging: false }
885    }
886    #[inline]
887    #[must_use] pub fn percent(value: f32) -> Self {
888        Self { inner: PixelValue::percent(value), each_line: false, hanging: false }
889    }
890    #[inline]
891    #[must_use] pub fn from_metric(metric: crate::props::basic::length::SizeMetric, value: f32) -> Self {
892        Self { inner: PixelValue::from_metric(metric, value), each_line: false, hanging: false }
893    }
894    #[inline]
895    #[must_use] pub fn interpolate(&self, other: &Self, t: f32) -> Self {
896        Self { inner: self.inner.interpolate(&other.inner, t), each_line: self.each_line, hanging: self.hanging }
897    }
898}
899
900impl PrintAsCssValue for StyleTextIndent {
901    fn print_as_css_value(&self) -> String {
902        let mut s = self.inner.to_string();
903        if self.hanging {
904            s.push_str(" hanging");
905        }
906        if self.each_line {
907            s.push_str(" each-line");
908        }
909        s
910    }
911}
912
913impl FormatAsRustCode for StyleTextIndent {
914    fn format_as_rust_code(&self, _tabs: usize) -> String {
915        format!(
916            "StyleTextIndent {{ inner: {}, each_line: {}, hanging: {} }}",
917            self.inner.format_as_rust_code(0), self.each_line, self.hanging
918        )
919    }
920}
921
922#[cfg(feature = "parser")]
923#[derive(Clone, PartialEq, Eq)]
924pub enum StyleTextIndentParseError<'a> {
925    PixelValue(CssPixelValueParseError<'a>),
926}
927#[cfg(feature = "parser")]
928impl_debug_as_display!(StyleTextIndentParseError<'a>);
929#[cfg(feature = "parser")]
930impl_display! { StyleTextIndentParseError<'a>, {
931    PixelValue(e) => format!("Invalid text-indent value: {}", e),
932}}
933#[cfg(feature = "parser")]
934impl_from!(
935    CssPixelValueParseError<'a>,
936    StyleTextIndentParseError::PixelValue
937);
938
939#[cfg(feature = "parser")]
940#[derive(Debug, Clone, PartialEq, Eq)]
941#[repr(C, u8)]
942pub enum StyleTextIndentParseErrorOwned {
943    PixelValue(CssPixelValueParseErrorOwned),
944}
945
946#[cfg(feature = "parser")]
947impl StyleTextIndentParseError<'_> {
948    #[must_use] pub fn to_contained(&self) -> StyleTextIndentParseErrorOwned {
949        match self {
950            Self::PixelValue(e) => StyleTextIndentParseErrorOwned::PixelValue(e.to_contained()),
951        }
952    }
953}
954
955#[cfg(feature = "parser")]
956impl StyleTextIndentParseErrorOwned {
957    #[must_use] pub fn to_shared(&self) -> StyleTextIndentParseError<'_> {
958        match self {
959            Self::PixelValue(e) => StyleTextIndentParseError::PixelValue(e.to_shared()),
960        }
961    }
962}
963
964#[cfg(feature = "parser")]
965/// # Errors
966///
967/// Returns an error if `input` is not a valid CSS `text-indent` value.
968pub fn parse_style_text_indent(input: &str) -> Result<StyleTextIndent, StyleTextIndentParseError<'_>> {
969    let mut each_line = false;
970    let mut hanging = false;
971    let mut pixel_part: Option<&str> = None;
972
973    for token in input.split_whitespace() {
974        match token {
975            "each-line" => each_line = true,
976            "hanging" => hanging = true,
977            _ => {
978                pixel_part = Some(token);
979            }
980        }
981    }
982
983    let pixel_str = pixel_part.unwrap_or("0px");
984
985    crate::props::basic::pixel::parse_pixel_value(pixel_str)
986        .map(|inner| StyleTextIndent { inner, each_line, hanging })
987        .map_err(StyleTextIndentParseError::PixelValue)
988}
989
990/// initial-letter property for drop caps
991#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
992#[repr(C)]
993pub struct StyleInitialLetter {
994    pub size: u32,
995    pub sink: crate::corety::OptionU32,
996}
997
998impl FormatAsRustCode for StyleInitialLetter {
999    fn format_as_rust_code(&self, _tabs: usize) -> String {
1000        format!("{self:?}")
1001    }
1002}
1003
1004impl PrintAsCssValue for StyleInitialLetter {
1005    fn print_as_css_value(&self) -> String {
1006        if let crate::corety::OptionU32::Some(sink) = self.sink {
1007            format!("{} {}", self.size, sink)
1008        } else {
1009            format!("{}", self.size)
1010        }
1011    }
1012}
1013
1014#[cfg(feature = "parser")]
1015#[derive(Clone, PartialEq, Eq)]
1016pub enum StyleInitialLetterParseError<'a> {
1017    InvalidFormat(&'a str),
1018    InvalidSize(&'a str),
1019    InvalidSink(&'a str),
1020}
1021#[cfg(feature = "parser")]
1022impl_debug_as_display!(StyleInitialLetterParseError<'a>);
1023#[cfg(feature = "parser")]
1024impl_display! { StyleInitialLetterParseError<'a>, {
1025    InvalidFormat(e) => format!("Invalid initial-letter format: {}", e),
1026    InvalidSize(e) => format!("Invalid initial-letter size: {}", e),
1027    InvalidSink(e) => format!("Invalid initial-letter sink: {}", e),
1028}}
1029
1030#[cfg(feature = "parser")]
1031#[derive(Debug, Clone, PartialEq, Eq)]
1032#[repr(C, u8)]
1033pub enum StyleInitialLetterParseErrorOwned {
1034    InvalidFormat(AzString),
1035    InvalidSize(AzString),
1036    InvalidSink(AzString),
1037}
1038
1039#[cfg(feature = "parser")]
1040impl StyleInitialLetterParseError<'_> {
1041    #[must_use] pub fn to_contained(&self) -> StyleInitialLetterParseErrorOwned {
1042        match self {
1043            Self::InvalidFormat(s) => {
1044                StyleInitialLetterParseErrorOwned::InvalidFormat((*s).to_string().into())
1045            }
1046            Self::InvalidSize(s) => StyleInitialLetterParseErrorOwned::InvalidSize((*s).to_string().into()),
1047            Self::InvalidSink(s) => StyleInitialLetterParseErrorOwned::InvalidSink((*s).to_string().into()),
1048        }
1049    }
1050}
1051
1052#[cfg(feature = "parser")]
1053impl StyleInitialLetterParseErrorOwned {
1054    #[must_use] pub fn to_shared(&self) -> StyleInitialLetterParseError<'_> {
1055        match self {
1056            Self::InvalidFormat(s) => StyleInitialLetterParseError::InvalidFormat(s.as_str()),
1057            Self::InvalidSize(s) => StyleInitialLetterParseError::InvalidSize(s.as_str()),
1058            Self::InvalidSink(s) => StyleInitialLetterParseError::InvalidSink(s.as_str()),
1059        }
1060    }
1061}
1062
1063#[cfg(feature = "parser")]
1064impl From<StyleInitialLetterParseError<'_>> for StyleInitialLetterParseErrorOwned {
1065    fn from(e: StyleInitialLetterParseError<'_>) -> Self {
1066        match e {
1067            StyleInitialLetterParseError::InvalidFormat(s) => {
1068                Self::InvalidFormat(s.to_string().into())
1069            }
1070            StyleInitialLetterParseError::InvalidSize(s) => {
1071                Self::InvalidSize(s.to_string().into())
1072            }
1073            StyleInitialLetterParseError::InvalidSink(s) => {
1074                Self::InvalidSink(s.to_string().into())
1075            }
1076        }
1077    }
1078}
1079
1080#[cfg(feature = "parser")]
1081impl_display! { StyleInitialLetterParseErrorOwned, {
1082    InvalidFormat(e) => format!("Invalid initial-letter format: {}", e),
1083    InvalidSize(e) => format!("Invalid initial-letter size: {}", e),
1084    InvalidSink(e) => format!("Invalid initial-letter sink: {}", e),
1085}}
1086
1087#[cfg(feature = "parser")]
1088/// # Errors
1089///
1090/// Returns an error if `input` is not a valid CSS `initial-letter` value.
1091pub fn parse_style_initial_letter(
1092    input: &str,
1093) -> Result<StyleInitialLetter, StyleInitialLetterParseError<'_>> {
1094    let input = input.trim();
1095    let parts: Vec<&str> = input.split_whitespace().collect();
1096
1097    if parts.is_empty() {
1098        return Err(StyleInitialLetterParseError::InvalidFormat(input));
1099    }
1100
1101    // Parse size (required)
1102    let size = parts[0]
1103        .parse::<u32>()
1104        .map_err(|_| StyleInitialLetterParseError::InvalidSize(parts[0]))?;
1105
1106    if size == 0 {
1107        return Err(StyleInitialLetterParseError::InvalidSize(parts[0]));
1108    }
1109
1110    // Parse sink (optional)
1111    let sink = if parts.len() > 1 {
1112        crate::corety::OptionU32::Some(
1113            parts[1]
1114                .parse::<u32>()
1115                .map_err(|_| StyleInitialLetterParseError::InvalidSink(parts[1]))?,
1116        )
1117    } else {
1118        crate::corety::OptionU32::None
1119    };
1120
1121    Ok(StyleInitialLetter { size, sink })
1122}
1123
1124/// line-clamp property for limiting visible lines
1125#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1126#[repr(C)]
1127pub struct StyleLineClamp {
1128    pub max_lines: usize,
1129}
1130
1131impl FormatAsRustCode for StyleLineClamp {
1132    fn format_as_rust_code(&self, _tabs: usize) -> String {
1133        format!("{self:?}")
1134    }
1135}
1136
1137impl PrintAsCssValue for StyleLineClamp {
1138    fn print_as_css_value(&self) -> String {
1139        format!("{}", self.max_lines)
1140    }
1141}
1142
1143#[cfg(feature = "parser")]
1144#[derive(Clone, PartialEq, Eq)]
1145pub enum StyleLineClampParseError<'a> {
1146    InvalidValue(&'a str),
1147    ZeroValue,
1148}
1149#[cfg(feature = "parser")]
1150impl_debug_as_display!(StyleLineClampParseError<'a>);
1151#[cfg(feature = "parser")]
1152impl_display! { StyleLineClampParseError<'a>, {
1153    InvalidValue(e) => format!("Invalid line-clamp value: {}", e),
1154    ZeroValue => format!("line-clamp cannot be zero"),
1155}}
1156#[allow(variant_size_differences)] // repr(C,u8) FFI enum: boxing the large variant would change the C ABI (api.json bindings); size disparity accepted
1157#[cfg(feature = "parser")]
1158#[derive(Debug, Clone, PartialEq, Eq)]
1159#[repr(C, u8)]
1160pub enum StyleLineClampParseErrorOwned {
1161    InvalidValue(AzString),
1162    ZeroValue,
1163}
1164
1165#[cfg(feature = "parser")]
1166impl StyleLineClampParseError<'_> {
1167    #[must_use] pub fn to_contained(&self) -> StyleLineClampParseErrorOwned {
1168        match self {
1169            Self::InvalidValue(s) => StyleLineClampParseErrorOwned::InvalidValue((*s).to_string().into()),
1170            Self::ZeroValue => StyleLineClampParseErrorOwned::ZeroValue,
1171        }
1172    }
1173}
1174
1175#[cfg(feature = "parser")]
1176impl StyleLineClampParseErrorOwned {
1177    #[must_use] pub fn to_shared(&self) -> StyleLineClampParseError<'_> {
1178        match self {
1179            Self::InvalidValue(s) => StyleLineClampParseError::InvalidValue(s.as_str()),
1180            Self::ZeroValue => StyleLineClampParseError::ZeroValue,
1181        }
1182    }
1183}
1184
1185#[cfg(feature = "parser")]
1186impl From<StyleLineClampParseError<'_>> for StyleLineClampParseErrorOwned {
1187    fn from(e: StyleLineClampParseError<'_>) -> Self {
1188        e.to_contained()
1189    }
1190}
1191
1192#[cfg(feature = "parser")]
1193impl_display! { StyleLineClampParseErrorOwned, {
1194    InvalidValue(e) => format!("Invalid line-clamp value: {}", e),
1195    ZeroValue => format!("line-clamp cannot be zero"),
1196}}
1197
1198#[cfg(feature = "parser")]
1199/// # Errors
1200///
1201/// Returns an error if `input` is not a valid CSS `line-clamp` value.
1202pub fn parse_style_line_clamp(
1203    input: &str,
1204) -> Result<StyleLineClamp, StyleLineClampParseError<'_>> {
1205    let input = input.trim();
1206
1207    let max_lines = input
1208        .parse::<usize>()
1209        .map_err(|_| StyleLineClampParseError::InvalidValue(input))?;
1210
1211    if max_lines == 0 {
1212        return Err(StyleLineClampParseError::ZeroValue);
1213    }
1214
1215    Ok(StyleLineClamp { max_lines })
1216}
1217
1218/// hanging-punctuation property for hanging punctuation marks
1219///
1220/// CSS Text 3 §8: `none | [ first || [ force-end | allow-end ] || last ]`
1221#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1222#[repr(C)]
1223#[derive(Default)]
1224pub struct StyleHangingPunctuation {
1225    pub first: bool,
1226    pub force_end: bool,
1227    pub allow_end: bool,
1228    pub last: bool,
1229}
1230
1231impl StyleHangingPunctuation {
1232    #[must_use] pub const fn is_enabled(&self) -> bool {
1233        self.first || self.force_end || self.allow_end || self.last
1234    }
1235}
1236
1237impl FormatAsRustCode for StyleHangingPunctuation {
1238    fn format_as_rust_code(&self, _tabs: usize) -> String {
1239        format!("{self:?}")
1240    }
1241}
1242
1243impl PrintAsCssValue for StyleHangingPunctuation {
1244    fn print_as_css_value(&self) -> String {
1245        if !self.is_enabled() {
1246            return "none".to_string();
1247        }
1248        let mut parts = Vec::new();
1249        if self.first { parts.push("first"); }
1250        if self.force_end { parts.push("force-end"); }
1251        if self.allow_end { parts.push("allow-end"); }
1252        if self.last { parts.push("last"); }
1253        parts.join(" ")
1254    }
1255}
1256
1257#[cfg(feature = "parser")]
1258#[derive(Clone, PartialEq, Eq)]
1259pub enum StyleHangingPunctuationParseError<'a> {
1260    InvalidValue(&'a str),
1261}
1262#[cfg(feature = "parser")]
1263impl_debug_as_display!(StyleHangingPunctuationParseError<'a>);
1264#[cfg(feature = "parser")]
1265impl_display! { StyleHangingPunctuationParseError<'a>, {
1266    InvalidValue(e) => format!("Invalid hanging-punctuation value: {}", e),
1267}}
1268
1269#[cfg(feature = "parser")]
1270#[derive(Debug, Clone, PartialEq, Eq)]
1271#[repr(C, u8)]
1272pub enum StyleHangingPunctuationParseErrorOwned {
1273    InvalidValue(AzString),
1274}
1275
1276#[cfg(feature = "parser")]
1277impl StyleHangingPunctuationParseError<'_> {
1278    #[must_use] pub fn to_contained(&self) -> StyleHangingPunctuationParseErrorOwned {
1279        match self {
1280            Self::InvalidValue(s) => {
1281                StyleHangingPunctuationParseErrorOwned::InvalidValue((*s).to_string().into())
1282            }
1283        }
1284    }
1285}
1286
1287#[cfg(feature = "parser")]
1288impl StyleHangingPunctuationParseErrorOwned {
1289    #[must_use] pub fn to_shared(&self) -> StyleHangingPunctuationParseError<'_> {
1290        match self {
1291            Self::InvalidValue(s) => StyleHangingPunctuationParseError::InvalidValue(s.as_str()),
1292        }
1293    }
1294}
1295
1296#[cfg(feature = "parser")]
1297impl From<StyleHangingPunctuationParseError<'_>> for StyleHangingPunctuationParseErrorOwned {
1298    fn from(e: StyleHangingPunctuationParseError<'_>) -> Self {
1299        e.to_contained()
1300    }
1301}
1302
1303#[cfg(feature = "parser")]
1304impl_display! { StyleHangingPunctuationParseErrorOwned, {
1305    InvalidValue(e) => format!("Invalid hanging-punctuation value: {}", e),
1306}}
1307
1308#[cfg(feature = "parser")]
1309/// # Errors
1310///
1311/// Returns an error if `input` is not a valid CSS `hanging-punctuation` value.
1312pub fn parse_style_hanging_punctuation(
1313    input: &str,
1314) -> Result<StyleHangingPunctuation, StyleHangingPunctuationParseError<'_>> {
1315    let input = input.trim();
1316
1317    if input.eq_ignore_ascii_case("none") {
1318        return Ok(StyleHangingPunctuation::default());
1319    }
1320
1321    let mut first = false;
1322    let mut force_end = false;
1323    let mut allow_end = false;
1324    let mut last = false;
1325
1326    for token in input.split_whitespace() {
1327        match token.to_lowercase().as_str() {
1328            "first" => first = true,
1329            "force-end" => force_end = true,
1330            "allow-end" => allow_end = true,
1331            "last" => last = true,
1332            _ => return Err(StyleHangingPunctuationParseError::InvalidValue(input)),
1333        }
1334    }
1335
1336    if force_end && allow_end {
1337        return Err(StyleHangingPunctuationParseError::InvalidValue(input));
1338    }
1339
1340    Ok(StyleHangingPunctuation { first, force_end, allow_end, last })
1341}
1342
1343/// text-combine-upright property for combining horizontal text in vertical layout
1344#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1345#[repr(C, u8)]
1346#[derive(Default)]
1347pub enum StyleTextCombineUpright {
1348    #[default]
1349    None,
1350    All,
1351    Digits(u8),
1352}
1353
1354
1355impl FormatAsRustCode for StyleTextCombineUpright {
1356    fn format_as_rust_code(&self, _tabs: usize) -> String {
1357        format!("{self:?}")
1358    }
1359}
1360
1361impl PrintAsCssValue for StyleTextCombineUpright {
1362    fn print_as_css_value(&self) -> String {
1363        match self {
1364            Self::None => "none".to_string(),
1365            Self::All => "all".to_string(),
1366            Self::Digits(n) => format!("digits {n}"),
1367        }
1368    }
1369}
1370
1371#[cfg(feature = "parser")]
1372#[derive(Clone, PartialEq, Eq)]
1373pub enum StyleTextCombineUprightParseError<'a> {
1374    InvalidValue(&'a str),
1375    InvalidDigits(&'a str),
1376}
1377#[cfg(feature = "parser")]
1378impl_debug_as_display!(StyleTextCombineUprightParseError<'a>);
1379#[cfg(feature = "parser")]
1380impl_display! { StyleTextCombineUprightParseError<'a>, {
1381    InvalidValue(e) => format!("Invalid text-combine-upright value: {}", e),
1382    InvalidDigits(e) => format!("Invalid text-combine-upright digits: {}", e),
1383}}
1384
1385#[cfg(feature = "parser")]
1386#[derive(Debug, Clone, PartialEq, Eq)]
1387#[repr(C, u8)]
1388pub enum StyleTextCombineUprightParseErrorOwned {
1389    InvalidValue(AzString),
1390    InvalidDigits(AzString),
1391}
1392
1393#[cfg(feature = "parser")]
1394impl StyleTextCombineUprightParseError<'_> {
1395    #[must_use] pub fn to_contained(&self) -> StyleTextCombineUprightParseErrorOwned {
1396        match self {
1397            Self::InvalidValue(s) => {
1398                StyleTextCombineUprightParseErrorOwned::InvalidValue((*s).to_string().into())
1399            }
1400            Self::InvalidDigits(s) => {
1401                StyleTextCombineUprightParseErrorOwned::InvalidDigits((*s).to_string().into())
1402            }
1403        }
1404    }
1405}
1406
1407#[cfg(feature = "parser")]
1408impl StyleTextCombineUprightParseErrorOwned {
1409    #[must_use] pub fn to_shared(&self) -> StyleTextCombineUprightParseError<'_> {
1410        match self {
1411            Self::InvalidValue(s) => StyleTextCombineUprightParseError::InvalidValue(s.as_str()),
1412            Self::InvalidDigits(s) => StyleTextCombineUprightParseError::InvalidDigits(s.as_str()),
1413        }
1414    }
1415}
1416
1417#[cfg(feature = "parser")]
1418impl From<StyleTextCombineUprightParseError<'_>> for StyleTextCombineUprightParseErrorOwned {
1419    fn from(e: StyleTextCombineUprightParseError<'_>) -> Self {
1420        e.to_contained()
1421    }
1422}
1423
1424#[cfg(feature = "parser")]
1425impl_display! { StyleTextCombineUprightParseErrorOwned, {
1426    InvalidValue(e) => format!("Invalid text-combine-upright value: {}", e),
1427    InvalidDigits(e) => format!("Invalid text-combine-upright digits: {}", e),
1428}}
1429
1430#[cfg(feature = "parser")]
1431/// # Errors
1432///
1433/// Returns an error if `input` is not a valid CSS `text-combine-upright` value.
1434pub fn parse_style_text_combine_upright(
1435    input: &str,
1436) -> Result<StyleTextCombineUpright, StyleTextCombineUprightParseError<'_>> {
1437    let trimmed = input.trim();
1438
1439    if trimmed.eq_ignore_ascii_case("none") {
1440        Ok(StyleTextCombineUpright::None)
1441    } else if trimmed.eq_ignore_ascii_case("all") {
1442        Ok(StyleTextCombineUpright::All)
1443    } else if trimmed.starts_with("digits") {
1444        let parts: Vec<&str> = trimmed.split_whitespace().collect();
1445        if parts.len() == 2 {
1446            let n = parts[1]
1447                .parse::<u8>()
1448                .map_err(|_| StyleTextCombineUprightParseError::InvalidDigits(input))?;
1449            if (2..=4).contains(&n) {
1450                Ok(StyleTextCombineUpright::Digits(n))
1451            } else {
1452                Err(StyleTextCombineUprightParseError::InvalidDigits(input))
1453            }
1454        } else {
1455            // Default to "digits 2"
1456            Ok(StyleTextCombineUpright::Digits(2))
1457        }
1458    } else {
1459        Err(StyleTextCombineUprightParseError::InvalidValue(input))
1460    }
1461}
1462
1463#[cfg(feature = "parser")]
1464#[derive(Clone, PartialEq, Eq)]
1465pub enum StyleWordSpacingParseError<'a> {
1466    PixelValue(CssPixelValueParseError<'a>),
1467}
1468#[cfg(feature = "parser")]
1469impl_debug_as_display!(StyleWordSpacingParseError<'a>);
1470#[cfg(feature = "parser")]
1471impl_display! { StyleWordSpacingParseError<'a>, {
1472    PixelValue(e) => format!("Invalid word-spacing value: {}", e),
1473}}
1474#[cfg(feature = "parser")]
1475impl_from!(
1476    CssPixelValueParseError<'a>,
1477    StyleWordSpacingParseError::PixelValue
1478);
1479
1480#[cfg(feature = "parser")]
1481#[derive(Debug, Clone, PartialEq, Eq)]
1482#[repr(C, u8)]
1483pub enum StyleWordSpacingParseErrorOwned {
1484    PixelValue(CssPixelValueParseErrorOwned),
1485}
1486
1487#[cfg(feature = "parser")]
1488impl StyleWordSpacingParseError<'_> {
1489    #[must_use] pub fn to_contained(&self) -> StyleWordSpacingParseErrorOwned {
1490        match self {
1491            Self::PixelValue(e) => StyleWordSpacingParseErrorOwned::PixelValue(e.to_contained()),
1492        }
1493    }
1494}
1495
1496#[cfg(feature = "parser")]
1497impl StyleWordSpacingParseErrorOwned {
1498    #[must_use] pub fn to_shared(&self) -> StyleWordSpacingParseError<'_> {
1499        match self {
1500            Self::PixelValue(e) => StyleWordSpacingParseError::PixelValue(e.to_shared()),
1501        }
1502    }
1503}
1504
1505#[cfg(feature = "parser")]
1506/// # Errors
1507///
1508/// Returns an error if `input` is not a valid CSS `word-spacing` value.
1509pub fn parse_style_word_spacing(
1510    input: &str,
1511) -> Result<StyleWordSpacing, StyleWordSpacingParseError<'_>> {
1512    crate::props::basic::pixel::parse_pixel_value(input)
1513        .map(|inner| StyleWordSpacing { inner })
1514        .map_err(StyleWordSpacingParseError::PixelValue)
1515}
1516
1517#[cfg(feature = "parser")]
1518#[derive(Clone, PartialEq, Eq)]
1519#[repr(C, u8)]
1520pub enum StyleLineHeightParseError {
1521    Percentage(PercentageParseError),
1522}
1523#[cfg(feature = "parser")]
1524impl_debug_as_display!(StyleLineHeightParseError);
1525#[cfg(feature = "parser")]
1526impl_display! { StyleLineHeightParseError, {
1527    Percentage(e) => format!("Invalid line-height value: {}", e),
1528}}
1529#[cfg(feature = "parser")]
1530impl_from!(PercentageParseError, StyleLineHeightParseError::Percentage);
1531
1532#[cfg(feature = "parser")]
1533#[derive(Debug, Clone, PartialEq, Eq)]
1534pub enum StyleLineHeightParseErrorOwned {
1535    Percentage(PercentageParseErrorOwned),
1536}
1537
1538#[cfg(feature = "parser")]
1539impl StyleLineHeightParseError {
1540    #[must_use] pub fn to_contained(&self) -> StyleLineHeightParseErrorOwned {
1541        match self {
1542            Self::Percentage(e) => StyleLineHeightParseErrorOwned::Percentage(e.to_contained()),
1543        }
1544    }
1545}
1546
1547#[cfg(feature = "parser")]
1548impl StyleLineHeightParseErrorOwned {
1549    #[must_use] pub fn to_shared(&self) -> StyleLineHeightParseError {
1550        match self {
1551            Self::Percentage(e) => StyleLineHeightParseError::Percentage(e.to_shared()),
1552        }
1553    }
1554}
1555
1556#[cfg(feature = "parser")]
1557/// # Errors
1558///
1559/// Returns an error if `input` is not a valid CSS `line-height` value.
1560pub fn parse_style_line_height(input: &str) -> Result<StyleLineHeight, StyleLineHeightParseError> {
1561    // Try <number> or <percentage> first (multiplier of font-size)
1562    if let Ok(inner) = crate::props::basic::length::parse_percentage_value(input) {
1563        return Ok(StyleLineHeight { inner });
1564    }
1565    // Try <length> (e.g., "50px") — store as NEGATIVE PercentageValue to signal absolute px.
1566    // Convention: negative normalized() = absolute pixel value (CSS line-height can't be negative).
1567    // Resolved at layout time in fc.rs where font_size is known.
1568    if let Ok(px) = crate::props::basic::pixel::parse_pixel_value(input) {
1569        if px.metric == crate::props::basic::length::SizeMetric::Px {
1570            let px_val = px.number.get();
1571            return Ok(StyleLineHeight {
1572                inner: PercentageValue::new(-px_val * 100.0),
1573            });
1574        }
1575    }
1576    Err(StyleLineHeightParseError::Percentage(
1577        PercentageParseError::InvalidUnit(String::new().into()),
1578    ))
1579}
1580
1581#[cfg(feature = "parser")]
1582#[derive(Clone, PartialEq, Eq)]
1583pub enum StyleTabSizeParseError<'a> {
1584    PixelValue(CssPixelValueParseError<'a>),
1585}
1586#[cfg(feature = "parser")]
1587impl_debug_as_display!(StyleTabSizeParseError<'a>);
1588#[cfg(feature = "parser")]
1589impl_display! { StyleTabSizeParseError<'a>, {
1590    PixelValue(e) => format!("Invalid tab-size value: {}", e),
1591}}
1592#[cfg(feature = "parser")]
1593impl_from!(
1594    CssPixelValueParseError<'a>,
1595    StyleTabSizeParseError::PixelValue
1596);
1597
1598#[cfg(feature = "parser")]
1599#[derive(Debug, Clone, PartialEq, Eq)]
1600#[repr(C, u8)]
1601pub enum StyleTabSizeParseErrorOwned {
1602    PixelValue(CssPixelValueParseErrorOwned),
1603}
1604
1605#[cfg(feature = "parser")]
1606impl StyleTabSizeParseError<'_> {
1607    #[must_use] pub fn to_contained(&self) -> StyleTabSizeParseErrorOwned {
1608        match self {
1609            Self::PixelValue(e) => StyleTabSizeParseErrorOwned::PixelValue(e.to_contained()),
1610        }
1611    }
1612}
1613
1614#[cfg(feature = "parser")]
1615impl StyleTabSizeParseErrorOwned {
1616    #[must_use] pub fn to_shared(&self) -> StyleTabSizeParseError<'_> {
1617        match self {
1618            Self::PixelValue(e) => StyleTabSizeParseError::PixelValue(e.to_shared()),
1619        }
1620    }
1621}
1622
1623#[cfg(feature = "parser")]
1624/// # Errors
1625///
1626/// Returns an error if `input` is not a valid CSS `tab-size` value.
1627pub fn parse_style_tab_size(input: &str) -> Result<StyleTabSize, StyleTabSizeParseError<'_>> {
1628    input.trim().parse::<f32>().map_or_else(
1629        |_| {
1630            crate::props::basic::pixel::parse_pixel_value(input)
1631                .map(|v| StyleTabSize { inner: v })
1632                .map_err(StyleTabSizeParseError::PixelValue)
1633        },
1634        |number| {
1635            Ok(StyleTabSize {
1636                inner: PixelValue::em(number),
1637            })
1638        },
1639    )
1640}
1641
1642#[cfg(feature = "parser")]
1643#[derive(Clone, PartialEq, Eq)]
1644pub enum StyleWhiteSpaceParseError<'a> {
1645    InvalidValue(InvalidValueErr<'a>),
1646}
1647#[cfg(feature = "parser")]
1648impl_debug_as_display!(StyleWhiteSpaceParseError<'a>);
1649#[cfg(feature = "parser")]
1650impl_display! { StyleWhiteSpaceParseError<'a>, {
1651    InvalidValue(e) => format!("Invalid white-space value: \"{}\"", e.0),
1652}}
1653#[cfg(feature = "parser")]
1654impl_from!(InvalidValueErr<'a>, StyleWhiteSpaceParseError::InvalidValue);
1655
1656#[cfg(feature = "parser")]
1657#[derive(Debug, Clone, PartialEq, Eq)]
1658#[repr(C, u8)]
1659pub enum StyleWhiteSpaceParseErrorOwned {
1660    InvalidValue(InvalidValueErrOwned),
1661}
1662
1663#[cfg(feature = "parser")]
1664impl StyleWhiteSpaceParseError<'_> {
1665    #[must_use] pub fn to_contained(&self) -> StyleWhiteSpaceParseErrorOwned {
1666        match self {
1667            Self::InvalidValue(e) => StyleWhiteSpaceParseErrorOwned::InvalidValue(e.to_contained()),
1668        }
1669    }
1670}
1671
1672#[cfg(feature = "parser")]
1673impl StyleWhiteSpaceParseErrorOwned {
1674    #[must_use] pub fn to_shared(&self) -> StyleWhiteSpaceParseError<'_> {
1675        match self {
1676            Self::InvalidValue(e) => StyleWhiteSpaceParseError::InvalidValue(e.to_shared()),
1677        }
1678    }
1679}
1680
1681#[cfg(feature = "parser")]
1682/// # Errors
1683///
1684/// Returns an error if `input` is not a valid CSS `white-space` value.
1685pub fn parse_style_white_space(input: &str) -> Result<StyleWhiteSpace, StyleWhiteSpaceParseError<'_>> {
1686    match input.trim() {
1687        "normal" => Ok(StyleWhiteSpace::Normal),
1688        "pre" => Ok(StyleWhiteSpace::Pre),
1689        "nowrap" | "no-wrap" => Ok(StyleWhiteSpace::Nowrap),
1690        "pre-wrap" => Ok(StyleWhiteSpace::PreWrap),
1691        "pre-line" => Ok(StyleWhiteSpace::PreLine),
1692        "break-spaces" => Ok(StyleWhiteSpace::BreakSpaces),
1693        other => Err(StyleWhiteSpaceParseError::InvalidValue(InvalidValueErr(
1694            other,
1695        ))),
1696    }
1697}
1698
1699#[cfg(feature = "parser")]
1700#[derive(Clone, PartialEq, Eq)]
1701pub enum StyleHyphensParseError<'a> {
1702    InvalidValue(InvalidValueErr<'a>),
1703}
1704#[cfg(feature = "parser")]
1705impl_debug_as_display!(StyleHyphensParseError<'a>);
1706#[cfg(feature = "parser")]
1707impl_display! { StyleHyphensParseError<'a>, {
1708    InvalidValue(e) => format!("Invalid hyphens value: \"{}\"", e.0),
1709}}
1710#[cfg(feature = "parser")]
1711impl_from!(InvalidValueErr<'a>, StyleHyphensParseError::InvalidValue);
1712
1713#[cfg(feature = "parser")]
1714#[derive(Debug, Clone, PartialEq, Eq)]
1715#[repr(C, u8)]
1716pub enum StyleHyphensParseErrorOwned {
1717    InvalidValue(InvalidValueErrOwned),
1718}
1719
1720#[cfg(feature = "parser")]
1721impl StyleHyphensParseError<'_> {
1722    #[must_use] pub fn to_contained(&self) -> StyleHyphensParseErrorOwned {
1723        match self {
1724            Self::InvalidValue(e) => StyleHyphensParseErrorOwned::InvalidValue(e.to_contained()),
1725        }
1726    }
1727}
1728
1729#[cfg(feature = "parser")]
1730impl StyleHyphensParseErrorOwned {
1731    #[must_use] pub fn to_shared(&self) -> StyleHyphensParseError<'_> {
1732        match self {
1733            Self::InvalidValue(e) => StyleHyphensParseError::InvalidValue(e.to_shared()),
1734        }
1735    }
1736}
1737
1738#[cfg(feature = "parser")]
1739/// # Errors
1740///
1741/// Returns an error if `input` is not a valid CSS `hyphens` value.
1742pub fn parse_style_hyphens(input: &str) -> Result<StyleHyphens, StyleHyphensParseError<'_>> {
1743    match input.trim() {
1744        "none" => Ok(StyleHyphens::None),
1745        "manual" => Ok(StyleHyphens::Manual),
1746        "auto" => Ok(StyleHyphens::Auto),
1747        other => Err(StyleHyphensParseError::InvalidValue(InvalidValueErr(other))),
1748    }
1749}
1750
1751// -- StyleLineBreak parse --
1752
1753#[cfg(feature = "parser")]
1754#[derive(Clone, PartialEq, Eq)]
1755pub enum StyleLineBreakParseError<'a> {
1756    InvalidValue(InvalidValueErr<'a>),
1757}
1758#[cfg(feature = "parser")]
1759impl_debug_as_display!(StyleLineBreakParseError<'a>);
1760#[cfg(feature = "parser")]
1761impl_display! { StyleLineBreakParseError<'a>, {
1762    InvalidValue(e) => format!("Invalid line-break value: \"{}\"", e.0),
1763}}
1764#[cfg(feature = "parser")]
1765impl_from!(InvalidValueErr<'a>, StyleLineBreakParseError::InvalidValue);
1766
1767#[cfg(feature = "parser")]
1768#[derive(Debug, Clone, PartialEq, Eq)]
1769#[repr(C, u8)]
1770pub enum StyleLineBreakParseErrorOwned {
1771    InvalidValue(InvalidValueErrOwned),
1772}
1773
1774#[cfg(feature = "parser")]
1775impl StyleLineBreakParseError<'_> {
1776    #[must_use] pub fn to_contained(&self) -> StyleLineBreakParseErrorOwned {
1777        match self {
1778            Self::InvalidValue(e) => StyleLineBreakParseErrorOwned::InvalidValue(e.to_contained()),
1779        }
1780    }
1781}
1782
1783#[cfg(feature = "parser")]
1784impl StyleLineBreakParseErrorOwned {
1785    #[must_use] pub fn to_shared(&self) -> StyleLineBreakParseError<'_> {
1786        match self {
1787            Self::InvalidValue(e) => StyleLineBreakParseError::InvalidValue(e.to_shared()),
1788        }
1789    }
1790}
1791
1792#[cfg(feature = "parser")]
1793/// # Errors
1794///
1795/// Returns an error if `input` is not a valid CSS `line-break` value.
1796pub fn parse_style_line_break(input: &str) -> Result<StyleLineBreak, StyleLineBreakParseError<'_>> {
1797    match input.trim() {
1798        "auto" => Ok(StyleLineBreak::Auto),
1799        "loose" => Ok(StyleLineBreak::Loose),
1800        "normal" => Ok(StyleLineBreak::Normal),
1801        "strict" => Ok(StyleLineBreak::Strict),
1802        "anywhere" => Ok(StyleLineBreak::Anywhere),
1803        other => Err(StyleLineBreakParseError::InvalidValue(InvalidValueErr(other))),
1804    }
1805}
1806
1807// -- StyleWordBreak parse --
1808
1809#[cfg(feature = "parser")]
1810#[derive(Clone, PartialEq, Eq)]
1811pub enum StyleWordBreakParseError<'a> {
1812    InvalidValue(InvalidValueErr<'a>),
1813}
1814#[cfg(feature = "parser")]
1815impl_debug_as_display!(StyleWordBreakParseError<'a>);
1816#[cfg(feature = "parser")]
1817impl_display! { StyleWordBreakParseError<'a>, {
1818    InvalidValue(e) => format!("Invalid word-break value: \"{}\"", e.0),
1819}}
1820#[cfg(feature = "parser")]
1821impl_from!(InvalidValueErr<'a>, StyleWordBreakParseError::InvalidValue);
1822
1823#[cfg(feature = "parser")]
1824#[derive(Debug, Clone, PartialEq, Eq)]
1825#[repr(C, u8)]
1826pub enum StyleWordBreakParseErrorOwned {
1827    InvalidValue(InvalidValueErrOwned),
1828}
1829
1830#[cfg(feature = "parser")]
1831impl StyleWordBreakParseError<'_> {
1832    #[must_use] pub fn to_contained(&self) -> StyleWordBreakParseErrorOwned {
1833        match self {
1834            Self::InvalidValue(e) => StyleWordBreakParseErrorOwned::InvalidValue(e.to_contained()),
1835        }
1836    }
1837}
1838
1839#[cfg(feature = "parser")]
1840impl StyleWordBreakParseErrorOwned {
1841    #[must_use] pub fn to_shared(&self) -> StyleWordBreakParseError<'_> {
1842        match self {
1843            Self::InvalidValue(e) => StyleWordBreakParseError::InvalidValue(e.to_shared()),
1844        }
1845    }
1846}
1847
1848#[cfg(feature = "parser")]
1849/// # Errors
1850///
1851/// Returns an error if `input` is not a valid CSS `word-break` value.
1852pub fn parse_style_word_break(input: &str) -> Result<StyleWordBreak, StyleWordBreakParseError<'_>> {
1853    match input.trim() {
1854        "normal" => Ok(StyleWordBreak::Normal),
1855        "break-all" => Ok(StyleWordBreak::BreakAll),
1856        "keep-all" => Ok(StyleWordBreak::KeepAll),
1857        "break-word" => Ok(StyleWordBreak::BreakWord),
1858        other => Err(StyleWordBreakParseError::InvalidValue(InvalidValueErr(other))),
1859    }
1860}
1861
1862// -- StyleOverflowWrap parse --
1863
1864#[cfg(feature = "parser")]
1865#[derive(Clone, PartialEq, Eq)]
1866pub enum StyleOverflowWrapParseError<'a> {
1867    InvalidValue(InvalidValueErr<'a>),
1868}
1869#[cfg(feature = "parser")]
1870impl_debug_as_display!(StyleOverflowWrapParseError<'a>);
1871#[cfg(feature = "parser")]
1872impl_display! { StyleOverflowWrapParseError<'a>, {
1873    InvalidValue(e) => format!("Invalid overflow-wrap value: \"{}\"", e.0),
1874}}
1875#[cfg(feature = "parser")]
1876impl_from!(InvalidValueErr<'a>, StyleOverflowWrapParseError::InvalidValue);
1877
1878#[cfg(feature = "parser")]
1879#[derive(Debug, Clone, PartialEq, Eq)]
1880#[repr(C, u8)]
1881pub enum StyleOverflowWrapParseErrorOwned {
1882    InvalidValue(InvalidValueErrOwned),
1883}
1884
1885#[cfg(feature = "parser")]
1886impl StyleOverflowWrapParseError<'_> {
1887    #[must_use] pub fn to_contained(&self) -> StyleOverflowWrapParseErrorOwned {
1888        match self {
1889            Self::InvalidValue(e) => StyleOverflowWrapParseErrorOwned::InvalidValue(e.to_contained()),
1890        }
1891    }
1892}
1893
1894#[cfg(feature = "parser")]
1895impl StyleOverflowWrapParseErrorOwned {
1896    #[must_use] pub fn to_shared(&self) -> StyleOverflowWrapParseError<'_> {
1897        match self {
1898            Self::InvalidValue(e) => StyleOverflowWrapParseError::InvalidValue(e.to_shared()),
1899        }
1900    }
1901}
1902
1903#[cfg(feature = "parser")]
1904/// # Errors
1905///
1906/// Returns an error if `input` is not a valid CSS `overflow-wrap` value.
1907pub fn parse_style_overflow_wrap(input: &str) -> Result<StyleOverflowWrap, StyleOverflowWrapParseError<'_>> {
1908    match input.trim() {
1909        "normal" => Ok(StyleOverflowWrap::Normal),
1910        "anywhere" => Ok(StyleOverflowWrap::Anywhere),
1911        "break-word" => Ok(StyleOverflowWrap::BreakWord),
1912        other => Err(StyleOverflowWrapParseError::InvalidValue(InvalidValueErr(other))),
1913    }
1914}
1915
1916// -- StyleTextAlignLast parse --
1917
1918#[cfg(feature = "parser")]
1919#[derive(Clone, PartialEq, Eq)]
1920pub enum StyleTextAlignLastParseError<'a> {
1921    InvalidValue(InvalidValueErr<'a>),
1922}
1923#[cfg(feature = "parser")]
1924impl_debug_as_display!(StyleTextAlignLastParseError<'a>);
1925#[cfg(feature = "parser")]
1926impl_display! { StyleTextAlignLastParseError<'a>, {
1927    InvalidValue(e) => format!("Invalid text-align-last value: \"{}\"", e.0),
1928}}
1929#[cfg(feature = "parser")]
1930impl_from!(InvalidValueErr<'a>, StyleTextAlignLastParseError::InvalidValue);
1931
1932#[cfg(feature = "parser")]
1933#[derive(Debug, Clone, PartialEq, Eq)]
1934#[repr(C, u8)]
1935pub enum StyleTextAlignLastParseErrorOwned {
1936    InvalidValue(InvalidValueErrOwned),
1937}
1938
1939#[cfg(feature = "parser")]
1940impl StyleTextAlignLastParseError<'_> {
1941    #[must_use] pub fn to_contained(&self) -> StyleTextAlignLastParseErrorOwned {
1942        match self {
1943            Self::InvalidValue(e) => StyleTextAlignLastParseErrorOwned::InvalidValue(e.to_contained()),
1944        }
1945    }
1946}
1947
1948#[cfg(feature = "parser")]
1949impl StyleTextAlignLastParseErrorOwned {
1950    #[must_use] pub fn to_shared(&self) -> StyleTextAlignLastParseError<'_> {
1951        match self {
1952            Self::InvalidValue(e) => StyleTextAlignLastParseError::InvalidValue(e.to_shared()),
1953        }
1954    }
1955}
1956
1957#[cfg(feature = "parser")]
1958/// # Errors
1959///
1960/// Returns an error if `input` is not a valid CSS `text-align-last` value.
1961pub fn parse_style_text_align_last(input: &str) -> Result<StyleTextAlignLast, StyleTextAlignLastParseError<'_>> {
1962    match input.trim() {
1963        "auto" => Ok(StyleTextAlignLast::Auto),
1964        "start" => Ok(StyleTextAlignLast::Start),
1965        "end" => Ok(StyleTextAlignLast::End),
1966        "left" => Ok(StyleTextAlignLast::Left),
1967        "right" => Ok(StyleTextAlignLast::Right),
1968        "center" => Ok(StyleTextAlignLast::Center),
1969        "justify" => Ok(StyleTextAlignLast::Justify),
1970        other => Err(StyleTextAlignLastParseError::InvalidValue(InvalidValueErr(other))),
1971    }
1972}
1973
1974// -- StyleTextTransform parse --
1975
1976#[cfg(feature = "parser")]
1977#[derive(Clone, PartialEq, Eq)]
1978pub enum StyleTextTransformParseError<'a> {
1979    InvalidValue(InvalidValueErr<'a>),
1980}
1981#[cfg(feature = "parser")]
1982impl_debug_as_display!(StyleTextTransformParseError<'a>);
1983#[cfg(feature = "parser")]
1984impl_display! { StyleTextTransformParseError<'a>, {
1985    InvalidValue(e) => format!("Invalid text-transform value: \"{}\"", e.0),
1986}}
1987#[cfg(feature = "parser")]
1988impl_from!(InvalidValueErr<'a>, StyleTextTransformParseError::InvalidValue);
1989
1990#[cfg(feature = "parser")]
1991#[derive(Debug, Clone, PartialEq, Eq)]
1992#[repr(C, u8)]
1993pub enum StyleTextTransformParseErrorOwned {
1994    InvalidValue(InvalidValueErrOwned),
1995}
1996
1997#[cfg(feature = "parser")]
1998impl StyleTextTransformParseError<'_> {
1999    #[must_use] pub fn to_contained(&self) -> StyleTextTransformParseErrorOwned {
2000        match self {
2001            Self::InvalidValue(e) => StyleTextTransformParseErrorOwned::InvalidValue(e.to_contained()),
2002        }
2003    }
2004}
2005
2006#[cfg(feature = "parser")]
2007impl StyleTextTransformParseErrorOwned {
2008    #[must_use] pub fn to_shared(&self) -> StyleTextTransformParseError<'_> {
2009        match self {
2010            Self::InvalidValue(e) => StyleTextTransformParseError::InvalidValue(e.to_shared()),
2011        }
2012    }
2013}
2014
2015#[cfg(feature = "parser")]
2016/// # Errors
2017///
2018/// Returns an error if `input` is not a valid CSS `text-transform` value.
2019pub fn parse_style_text_transform(input: &str) -> Result<StyleTextTransform, StyleTextTransformParseError<'_>> {
2020    match input.trim() {
2021        "none" => Ok(StyleTextTransform::None),
2022        "capitalize" => Ok(StyleTextTransform::Capitalize),
2023        "uppercase" => Ok(StyleTextTransform::Uppercase),
2024        "lowercase" => Ok(StyleTextTransform::Lowercase),
2025        "full-width" => Ok(StyleTextTransform::FullWidth),
2026        other => Err(StyleTextTransformParseError::InvalidValue(InvalidValueErr(other))),
2027    }
2028}
2029
2030#[cfg(feature = "parser")]
2031#[derive(Clone, PartialEq, Eq)]
2032pub enum StyleDirectionParseError<'a> {
2033    InvalidValue(InvalidValueErr<'a>),
2034}
2035#[cfg(feature = "parser")]
2036impl_debug_as_display!(StyleDirectionParseError<'a>);
2037#[cfg(feature = "parser")]
2038impl_display! { StyleDirectionParseError<'a>, {
2039    InvalidValue(e) => format!("Invalid direction value: \"{}\"", e.0),
2040}}
2041#[cfg(feature = "parser")]
2042impl_from!(InvalidValueErr<'a>, StyleDirectionParseError::InvalidValue);
2043
2044#[cfg(feature = "parser")]
2045#[derive(Debug, Clone, PartialEq, Eq)]
2046#[repr(C, u8)]
2047pub enum StyleDirectionParseErrorOwned {
2048    InvalidValue(InvalidValueErrOwned),
2049}
2050
2051#[cfg(feature = "parser")]
2052impl StyleDirectionParseError<'_> {
2053    #[must_use] pub fn to_contained(&self) -> StyleDirectionParseErrorOwned {
2054        match self {
2055            Self::InvalidValue(e) => StyleDirectionParseErrorOwned::InvalidValue(e.to_contained()),
2056        }
2057    }
2058}
2059
2060#[cfg(feature = "parser")]
2061impl StyleDirectionParseErrorOwned {
2062    #[must_use] pub fn to_shared(&self) -> StyleDirectionParseError<'_> {
2063        match self {
2064            Self::InvalidValue(e) => StyleDirectionParseError::InvalidValue(e.to_shared()),
2065        }
2066    }
2067}
2068
2069#[cfg(feature = "parser")]
2070/// # Errors
2071///
2072/// Returns an error if `input` is not a valid CSS `direction` value.
2073pub fn parse_style_direction(input: &str) -> Result<StyleDirection, StyleDirectionParseError<'_>> {
2074    match input.trim() {
2075        "ltr" => Ok(StyleDirection::Ltr),
2076        "rtl" => Ok(StyleDirection::Rtl),
2077        other => Err(StyleDirectionParseError::InvalidValue(InvalidValueErr(
2078            other,
2079        ))),
2080    }
2081}
2082
2083#[cfg(feature = "parser")]
2084#[derive(Clone, PartialEq, Eq)]
2085pub enum StyleUserSelectParseError<'a> {
2086    InvalidValue(InvalidValueErr<'a>),
2087}
2088#[cfg(feature = "parser")]
2089impl_debug_as_display!(StyleUserSelectParseError<'a>);
2090#[cfg(feature = "parser")]
2091impl_display! { StyleUserSelectParseError<'a>, {
2092    InvalidValue(e) => format!("Invalid user-select value: \"{}\"", e.0),
2093}}
2094#[cfg(feature = "parser")]
2095impl_from!(InvalidValueErr<'a>, StyleUserSelectParseError::InvalidValue);
2096
2097#[cfg(feature = "parser")]
2098#[derive(Debug, Clone, PartialEq, Eq)]
2099#[repr(C, u8)]
2100pub enum StyleUserSelectParseErrorOwned {
2101    InvalidValue(InvalidValueErrOwned),
2102}
2103
2104#[cfg(feature = "parser")]
2105impl StyleUserSelectParseError<'_> {
2106    #[must_use] pub fn to_contained(&self) -> StyleUserSelectParseErrorOwned {
2107        match self {
2108            Self::InvalidValue(e) => StyleUserSelectParseErrorOwned::InvalidValue(e.to_contained()),
2109        }
2110    }
2111}
2112
2113#[cfg(feature = "parser")]
2114impl StyleUserSelectParseErrorOwned {
2115    #[must_use] pub fn to_shared(&self) -> StyleUserSelectParseError<'_> {
2116        match self {
2117            Self::InvalidValue(e) => StyleUserSelectParseError::InvalidValue(e.to_shared()),
2118        }
2119    }
2120}
2121
2122#[cfg(feature = "parser")]
2123/// # Errors
2124///
2125/// Returns an error if `input` is not a valid CSS `user-select` value.
2126pub fn parse_style_user_select(input: &str) -> Result<StyleUserSelect, StyleUserSelectParseError<'_>> {
2127    match input.trim() {
2128        "auto" => Ok(StyleUserSelect::Auto),
2129        "text" => Ok(StyleUserSelect::Text),
2130        "none" => Ok(StyleUserSelect::None),
2131        "all" => Ok(StyleUserSelect::All),
2132        other => Err(StyleUserSelectParseError::InvalidValue(InvalidValueErr(
2133            other,
2134        ))),
2135    }
2136}
2137
2138#[cfg(feature = "parser")]
2139#[derive(Clone, PartialEq, Eq)]
2140pub enum StyleTextDecorationParseError<'a> {
2141    InvalidValue(InvalidValueErr<'a>),
2142}
2143#[cfg(feature = "parser")]
2144impl_debug_as_display!(StyleTextDecorationParseError<'a>);
2145#[cfg(feature = "parser")]
2146impl_display! { StyleTextDecorationParseError<'a>, {
2147    InvalidValue(e) => format!("Invalid text-decoration value: \"{}\"", e.0),
2148}}
2149#[cfg(feature = "parser")]
2150impl_from!(
2151    InvalidValueErr<'a>,
2152    StyleTextDecorationParseError::InvalidValue
2153);
2154
2155#[cfg(feature = "parser")]
2156#[derive(Debug, Clone, PartialEq, Eq)]
2157#[repr(C, u8)]
2158pub enum StyleTextDecorationParseErrorOwned {
2159    InvalidValue(InvalidValueErrOwned),
2160}
2161
2162#[cfg(feature = "parser")]
2163impl StyleTextDecorationParseError<'_> {
2164    #[must_use] pub fn to_contained(&self) -> StyleTextDecorationParseErrorOwned {
2165        match self {
2166            Self::InvalidValue(e) => {
2167                StyleTextDecorationParseErrorOwned::InvalidValue(e.to_contained())
2168            }
2169        }
2170    }
2171}
2172
2173#[cfg(feature = "parser")]
2174impl StyleTextDecorationParseErrorOwned {
2175    #[must_use] pub fn to_shared(&self) -> StyleTextDecorationParseError<'_> {
2176        match self {
2177            Self::InvalidValue(e) => StyleTextDecorationParseError::InvalidValue(e.to_shared()),
2178        }
2179    }
2180}
2181
2182#[cfg(feature = "parser")]
2183/// # Errors
2184///
2185/// Returns an error if `input` is not a valid CSS `text-decoration` value.
2186pub fn parse_style_text_decoration(
2187    input: &str,
2188) -> Result<StyleTextDecoration, StyleTextDecorationParseError<'_>> {
2189    match input.trim() {
2190        "none" => Ok(StyleTextDecoration::None),
2191        "underline" => Ok(StyleTextDecoration::Underline),
2192        "overline" => Ok(StyleTextDecoration::Overline),
2193        "line-through" => Ok(StyleTextDecoration::LineThrough),
2194        other => Err(StyleTextDecorationParseError::InvalidValue(
2195            InvalidValueErr(other),
2196        )),
2197    }
2198}
2199
2200#[cfg(feature = "parser")]
2201#[derive(Clone, PartialEq, Eq)]
2202pub enum StyleVerticalAlignParseError<'a> {
2203    InvalidValue(InvalidValueErr<'a>),
2204}
2205#[cfg(feature = "parser")]
2206impl_debug_as_display!(StyleVerticalAlignParseError<'a>);
2207#[cfg(feature = "parser")]
2208impl_display! { StyleVerticalAlignParseError<'a>, {
2209    InvalidValue(e) => format!("Invalid vertical-align value: \"{}\"", e.0),
2210}}
2211#[cfg(feature = "parser")]
2212impl_from!(
2213    InvalidValueErr<'a>,
2214    StyleVerticalAlignParseError::InvalidValue
2215);
2216
2217#[cfg(feature = "parser")]
2218#[derive(Debug, Clone, PartialEq, Eq)]
2219#[repr(C, u8)]
2220pub enum StyleVerticalAlignParseErrorOwned {
2221    InvalidValue(InvalidValueErrOwned),
2222}
2223
2224#[cfg(feature = "parser")]
2225impl StyleVerticalAlignParseError<'_> {
2226    #[must_use] pub fn to_contained(&self) -> StyleVerticalAlignParseErrorOwned {
2227        match self {
2228            Self::InvalidValue(e) => {
2229                StyleVerticalAlignParseErrorOwned::InvalidValue(e.to_contained())
2230            }
2231        }
2232    }
2233}
2234
2235#[cfg(feature = "parser")]
2236impl StyleVerticalAlignParseErrorOwned {
2237    #[must_use] pub fn to_shared(&self) -> StyleVerticalAlignParseError<'_> {
2238        match self {
2239            Self::InvalidValue(e) => StyleVerticalAlignParseError::InvalidValue(e.to_shared()),
2240        }
2241    }
2242}
2243
2244#[cfg(feature = "parser")]
2245/// # Errors
2246///
2247/// Returns an error if `input` is not a valid CSS `vertical-align` value.
2248pub fn parse_style_vertical_align(
2249    input: &str,
2250) -> Result<StyleVerticalAlign, StyleVerticalAlignParseError<'_>> {
2251    match input.trim() {
2252        "baseline" => Ok(StyleVerticalAlign::Baseline),
2253        "top" => Ok(StyleVerticalAlign::Top),
2254        "middle" => Ok(StyleVerticalAlign::Middle),
2255        "bottom" => Ok(StyleVerticalAlign::Bottom),
2256        "sub" => Ok(StyleVerticalAlign::Sub),
2257        "super" => Ok(StyleVerticalAlign::Superscript),
2258        "text-top" => Ok(StyleVerticalAlign::TextTop),
2259        "text-bottom" => Ok(StyleVerticalAlign::TextBottom),
2260        other if other.ends_with('%') => {
2261            let num_str = other.trim_end_matches('%').trim();
2262            num_str.parse::<f32>().map_or_else(
2263                |_| Err(StyleVerticalAlignParseError::InvalidValue(InvalidValueErr(other))),
2264                |val| Ok(StyleVerticalAlign::Percentage(PercentageValue::new(val))),
2265            )
2266        }
2267        other => crate::props::basic::pixel::parse_pixel_value(other).map_or_else(
2268            |_| Err(StyleVerticalAlignParseError::InvalidValue(InvalidValueErr(other))),
2269            |pv| Ok(StyleVerticalAlign::Length(pv)),
2270        ),
2271    }
2272}
2273
2274// --- CaretColor ---
2275
2276#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2277#[repr(C)]
2278pub struct CaretColor {
2279    pub inner: ColorU,
2280}
2281
2282impl Default for CaretColor {
2283    fn default() -> Self {
2284        Self {
2285            inner: ColorU::BLACK,
2286        }
2287    }
2288}
2289
2290impl PrintAsCssValue for CaretColor {
2291    fn print_as_css_value(&self) -> String {
2292        self.inner.to_hash()
2293    }
2294}
2295
2296impl FormatAsRustCode for CaretColor {
2297    fn format_as_rust_code(&self, _tabs: usize) -> String {
2298        format!(
2299            "CaretColor {{ inner: {} }}",
2300            crate::codegen::format::format_color_value(&self.inner)
2301        )
2302    }
2303}
2304
2305#[cfg(feature = "parser")]
2306/// # Errors
2307///
2308/// Returns an error if `input` is not a valid CSS `caret-color` value.
2309pub fn parse_caret_color(input: &str) -> Result<CaretColor, CssColorParseError<'_>> {
2310    parse_css_color(input).map(|inner| CaretColor { inner })
2311}
2312
2313// --- CaretAnimationDuration ---
2314
2315#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2316#[repr(C)]
2317pub struct CaretAnimationDuration {
2318    pub inner: CssDuration,
2319}
2320
2321impl Default for CaretAnimationDuration {
2322    fn default() -> Self {
2323        Self {
2324            inner: CssDuration { inner: 500 },
2325        } // Default 500ms blink time
2326    }
2327}
2328
2329impl PrintAsCssValue for CaretAnimationDuration {
2330    fn print_as_css_value(&self) -> String {
2331        self.inner.print_as_css_value()
2332    }
2333}
2334
2335impl FormatAsRustCode for CaretAnimationDuration {
2336    fn format_as_rust_code(&self, _tabs: usize) -> String {
2337        format!(
2338            "CaretAnimationDuration {{ inner: {} }}",
2339            self.inner.format_as_rust_code(0)
2340        )
2341    }
2342}
2343
2344#[cfg(feature = "parser")]
2345/// # Errors
2346///
2347/// Returns an error if `input` is not a valid CSS `caret-animation-duration` value.
2348pub fn parse_caret_animation_duration(
2349    input: &str,
2350) -> Result<CaretAnimationDuration, DurationParseError<'_>> {
2351    use crate::props::basic::parse_duration;
2352
2353    parse_duration(input).map(|inner| CaretAnimationDuration { inner })
2354}
2355
2356// --- CaretWidth ---
2357
2358/// Width of the text cursor (caret) in pixels.
2359/// CSS doesn't have a standard property for this, so we use `-azul-caret-width`.
2360#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2361#[repr(C)]
2362pub struct CaretWidth {
2363    pub inner: PixelValue,
2364}
2365
2366impl Default for CaretWidth {
2367    fn default() -> Self {
2368        Self {
2369            inner: PixelValue::px(2.0), // Default 2px caret width
2370        }
2371    }
2372}
2373
2374impl PrintAsCssValue for CaretWidth {
2375    fn print_as_css_value(&self) -> String {
2376        self.inner.print_as_css_value()
2377    }
2378}
2379
2380impl FormatAsRustCode for CaretWidth {
2381    fn format_as_rust_code(&self, _tabs: usize) -> String {
2382        format!(
2383            "CaretWidth {{ inner: {} }}",
2384            self.inner.format_as_rust_code(0)
2385        )
2386    }
2387}
2388
2389#[cfg(feature = "parser")]
2390/// # Errors
2391///
2392/// Returns an error if `input` is not a valid CSS `caret-width` value.
2393pub fn parse_caret_width(input: &str) -> Result<CaretWidth, CssPixelValueParseError<'_>> {
2394    use crate::props::basic::pixel::parse_pixel_value;
2395
2396    parse_pixel_value(input).map(|inner| CaretWidth { inner })
2397}
2398
2399// --- From implementations for CssProperty ---
2400
2401impl From<StyleUserSelect> for crate::props::property::CssProperty {
2402    fn from(value: StyleUserSelect) -> Self {
2403        use crate::props::property::CssProperty;
2404        Self::user_select(value)
2405    }
2406}
2407
2408impl From<StyleTextDecoration> for crate::props::property::CssProperty {
2409    fn from(value: StyleTextDecoration) -> Self {
2410        use crate::props::property::CssProperty;
2411        Self::text_decoration(value)
2412    }
2413}
2414
2415#[cfg(all(test, feature = "parser"))]
2416mod tests {
2417    use super::*;
2418    use crate::props::basic::{color::ColorU, length::PercentageValue, pixel::PixelValue};
2419
2420    #[test]
2421    fn test_parse_style_text_color() {
2422        assert_eq!(
2423            parse_style_text_color("red").unwrap().inner,
2424            ColorU::new_rgb(255, 0, 0)
2425        );
2426        assert_eq!(
2427            parse_style_text_color("#aabbcc").unwrap().inner,
2428            ColorU::new_rgb(170, 187, 204)
2429        );
2430        assert!(parse_style_text_color("not-a-color").is_err());
2431    }
2432
2433    #[test]
2434    fn test_parse_style_text_align() {
2435        assert_eq!(
2436            parse_style_text_align("left").unwrap(),
2437            StyleTextAlign::Left
2438        );
2439        assert_eq!(
2440            parse_style_text_align("center").unwrap(),
2441            StyleTextAlign::Center
2442        );
2443        assert_eq!(
2444            parse_style_text_align("right").unwrap(),
2445            StyleTextAlign::Right
2446        );
2447        assert_eq!(
2448            parse_style_text_align("justify").unwrap(),
2449            StyleTextAlign::Justify
2450        );
2451        assert_eq!(
2452            parse_style_text_align("start").unwrap(),
2453            StyleTextAlign::Start
2454        );
2455        assert_eq!(parse_style_text_align("end").unwrap(), StyleTextAlign::End);
2456        assert!(parse_style_text_align("middle").is_err());
2457    }
2458
2459    #[test]
2460    fn test_parse_spacing() {
2461        assert_eq!(
2462            parse_style_letter_spacing("2px").unwrap().inner,
2463            PixelValue::px(2.0)
2464        );
2465        assert_eq!(
2466            parse_style_letter_spacing("-0.1em").unwrap().inner,
2467            PixelValue::em(-0.1)
2468        );
2469        assert_eq!(
2470            parse_style_word_spacing("0.5em").unwrap().inner,
2471            PixelValue::em(0.5)
2472        );
2473    }
2474
2475    #[test]
2476    fn test_parse_line_height() {
2477        assert_eq!(
2478            parse_style_line_height("1.5").unwrap().inner,
2479            PercentageValue::new(150.0)
2480        );
2481        assert_eq!(
2482            parse_style_line_height("120%").unwrap().inner,
2483            PercentageValue::new(120.0)
2484        );
2485        // px values stored as negative PercentageValue (convention: negative = absolute px)
2486        assert_eq!(
2487            parse_style_line_height("20px").unwrap().inner,
2488            PercentageValue::new(-20.0 * 100.0)
2489        );
2490    }
2491
2492    #[test]
2493    fn test_parse_tab_size() {
2494        // Unitless number is treated as `em`
2495        assert_eq!(
2496            parse_style_tab_size("4").unwrap().inner,
2497            PixelValue::em(4.0)
2498        );
2499        assert_eq!(
2500            parse_style_tab_size("20px").unwrap().inner,
2501            PixelValue::px(20.0)
2502        );
2503    }
2504
2505    #[test]
2506    fn test_parse_white_space() {
2507        assert_eq!(
2508            parse_style_white_space("normal").unwrap(),
2509            StyleWhiteSpace::Normal
2510        );
2511        assert_eq!(
2512            parse_style_white_space("pre").unwrap(),
2513            StyleWhiteSpace::Pre
2514        );
2515        assert_eq!(
2516            parse_style_white_space("nowrap").unwrap(),
2517            StyleWhiteSpace::Nowrap
2518        );
2519        assert_eq!(
2520            parse_style_white_space("pre-wrap").unwrap(),
2521            StyleWhiteSpace::PreWrap
2522        );
2523    }
2524}
2525
2526// -- StyleUnicodeBidi --
2527
2528/// Represents the `unicode-bidi` CSS property.
2529///
2530/// Controls how bidirectional text is handled within an element.
2531#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2532#[repr(C)]
2533#[derive(Default)]
2534pub enum StyleUnicodeBidi {
2535    /// No additional level of embedding
2536    #[default]
2537    Normal,
2538    /// Open an additional level of embedding
2539    Embed,
2540    /// Isolate the element from surrounding bidirectional text
2541    Isolate,
2542    /// Override the bidirectional algorithm for inline content
2543    BidiOverride,
2544    /// Combine isolation and override
2545    IsolateOverride,
2546    /// Determine paragraph direction from content without bidi algorithm
2547    Plaintext,
2548}
2549impl_option!(
2550    StyleUnicodeBidi,
2551    OptionStyleUnicodeBidi,
2552    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
2553);
2554impl PrintAsCssValue for StyleUnicodeBidi {
2555    fn print_as_css_value(&self) -> String {
2556        String::from(match self {
2557            Self::Normal => "normal",
2558            Self::Embed => "embed",
2559            Self::Isolate => "isolate",
2560            Self::BidiOverride => "bidi-override",
2561            Self::IsolateOverride => "isolate-override",
2562            Self::Plaintext => "plaintext",
2563        })
2564    }
2565}
2566
2567#[cfg(feature = "parser")]
2568#[derive(Clone, PartialEq, Eq)]
2569pub enum StyleUnicodeBidiParseError<'a> {
2570    InvalidValue(InvalidValueErr<'a>),
2571}
2572#[cfg(feature = "parser")]
2573impl_debug_as_display!(StyleUnicodeBidiParseError<'a>);
2574#[cfg(feature = "parser")]
2575impl_display! { StyleUnicodeBidiParseError<'a>, {
2576    InvalidValue(e) => format!("Invalid unicode-bidi value: \"{}\"", e.0),
2577}}
2578#[cfg(feature = "parser")]
2579impl_from!(InvalidValueErr<'a>, StyleUnicodeBidiParseError::InvalidValue);
2580
2581#[cfg(feature = "parser")]
2582#[derive(Debug, Clone, PartialEq, Eq)]
2583#[repr(C, u8)]
2584pub enum StyleUnicodeBidiParseErrorOwned {
2585    InvalidValue(InvalidValueErrOwned),
2586}
2587
2588#[cfg(feature = "parser")]
2589impl StyleUnicodeBidiParseError<'_> {
2590    #[must_use] pub fn to_contained(&self) -> StyleUnicodeBidiParseErrorOwned {
2591        match self {
2592            Self::InvalidValue(e) => StyleUnicodeBidiParseErrorOwned::InvalidValue(e.to_contained()),
2593        }
2594    }
2595}
2596
2597#[cfg(feature = "parser")]
2598impl StyleUnicodeBidiParseErrorOwned {
2599    #[must_use] pub fn to_shared(&self) -> StyleUnicodeBidiParseError<'_> {
2600        match self {
2601            Self::InvalidValue(e) => StyleUnicodeBidiParseError::InvalidValue(e.to_shared()),
2602        }
2603    }
2604}
2605
2606#[cfg(feature = "parser")]
2607/// # Errors
2608///
2609/// Returns an error if `input` is not a valid CSS `unicode-bidi` value.
2610pub fn parse_style_unicode_bidi(input: &str) -> Result<StyleUnicodeBidi, StyleUnicodeBidiParseError<'_>> {
2611    match input.trim() {
2612        "normal" => Ok(StyleUnicodeBidi::Normal),
2613        "embed" => Ok(StyleUnicodeBidi::Embed),
2614        "isolate" => Ok(StyleUnicodeBidi::Isolate),
2615        "bidi-override" => Ok(StyleUnicodeBidi::BidiOverride),
2616        "isolate-override" => Ok(StyleUnicodeBidi::IsolateOverride),
2617        "plaintext" => Ok(StyleUnicodeBidi::Plaintext),
2618        other => Err(StyleUnicodeBidiParseError::InvalidValue(InvalidValueErr(other))),
2619    }
2620}
2621
2622// -- StyleTextBoxTrim --
2623
2624/// Represents the `text-box-trim` CSS property.
2625///
2626/// Controls whether the leading is trimmed at the start/end of a block container.
2627#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2628#[repr(C)]
2629#[derive(Default)]
2630pub enum StyleTextBoxTrim {
2631    /// No trimming
2632    #[default]
2633    None,
2634    /// Trim leading over the first formatted line
2635    TrimStart,
2636    /// Trim leading under the last formatted line
2637    TrimEnd,
2638    /// Trim both start and end
2639    TrimBoth,
2640}
2641impl_option!(
2642    StyleTextBoxTrim,
2643    OptionStyleTextBoxTrim,
2644    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
2645);
2646impl PrintAsCssValue for StyleTextBoxTrim {
2647    fn print_as_css_value(&self) -> String {
2648        String::from(match self {
2649            Self::None => "none",
2650            Self::TrimStart => "trim-start",
2651            Self::TrimEnd => "trim-end",
2652            Self::TrimBoth => "trim-both",
2653        })
2654    }
2655}
2656
2657#[cfg(feature = "parser")]
2658#[derive(Clone, PartialEq, Eq)]
2659pub enum StyleTextBoxTrimParseError<'a> {
2660    InvalidValue(InvalidValueErr<'a>),
2661}
2662#[cfg(feature = "parser")]
2663impl_debug_as_display!(StyleTextBoxTrimParseError<'a>);
2664#[cfg(feature = "parser")]
2665impl_display! { StyleTextBoxTrimParseError<'a>, {
2666    InvalidValue(e) => format!("Invalid text-box-trim value: \"{}\"", e.0),
2667}}
2668#[cfg(feature = "parser")]
2669impl_from!(InvalidValueErr<'a>, StyleTextBoxTrimParseError::InvalidValue);
2670
2671#[cfg(feature = "parser")]
2672#[derive(Debug, Clone, PartialEq, Eq)]
2673#[repr(C, u8)]
2674pub enum StyleTextBoxTrimParseErrorOwned {
2675    InvalidValue(InvalidValueErrOwned),
2676}
2677
2678#[cfg(feature = "parser")]
2679impl StyleTextBoxTrimParseError<'_> {
2680    #[must_use] pub fn to_contained(&self) -> StyleTextBoxTrimParseErrorOwned {
2681        match self {
2682            Self::InvalidValue(e) => StyleTextBoxTrimParseErrorOwned::InvalidValue(e.to_contained()),
2683        }
2684    }
2685}
2686
2687#[cfg(feature = "parser")]
2688impl StyleTextBoxTrimParseErrorOwned {
2689    #[must_use] pub fn to_shared(&self) -> StyleTextBoxTrimParseError<'_> {
2690        match self {
2691            Self::InvalidValue(e) => StyleTextBoxTrimParseError::InvalidValue(e.to_shared()),
2692        }
2693    }
2694}
2695
2696#[cfg(feature = "parser")]
2697/// # Errors
2698///
2699/// Returns an error if `input` is not a valid CSS `text-box-trim` value.
2700pub fn parse_style_text_box_trim(input: &str) -> Result<StyleTextBoxTrim, StyleTextBoxTrimParseError<'_>> {
2701    match input.trim() {
2702        "none" => Ok(StyleTextBoxTrim::None),
2703        "trim-start" => Ok(StyleTextBoxTrim::TrimStart),
2704        "trim-end" => Ok(StyleTextBoxTrim::TrimEnd),
2705        "trim-both" => Ok(StyleTextBoxTrim::TrimBoth),
2706        other => Err(StyleTextBoxTrimParseError::InvalidValue(InvalidValueErr(other))),
2707    }
2708}
2709
2710// -- StyleTextBoxEdge --
2711
2712/// Represents the `text-box-edge` CSS property.
2713///
2714/// Specifies the metrics used for determining the over/under edges of text
2715/// for the purposes of `text-box-trim`.
2716// +spec:writing-modes:daad86 - first value = over edge, second = under edge; single value applies to both (else "text" assumed for missing)
2717#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2718#[repr(C)]
2719#[derive(Default)]
2720pub enum StyleTextBoxEdge {
2721    // +spec:line-height:cc03df - Auto uses line-fit-edge value, interpreting leading (initial) as text
2722    /// Use the line-fit-edge value (initial: text)
2723    #[default]
2724    Auto,
2725    /// Use the text-over / text-under baselines
2726    TextEdge,
2727    /// Use the cap-height baseline
2728    CapHeight,
2729    /// Use the x-height baseline
2730    ExHeight,
2731}
2732impl_option!(
2733    StyleTextBoxEdge,
2734    OptionStyleTextBoxEdge,
2735    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
2736);
2737impl PrintAsCssValue for StyleTextBoxEdge {
2738    fn print_as_css_value(&self) -> String {
2739        String::from(match self {
2740            Self::Auto => "auto",
2741            Self::TextEdge => "text",
2742            Self::CapHeight => "cap",
2743            Self::ExHeight => "ex",
2744        })
2745    }
2746}
2747
2748#[cfg(feature = "parser")]
2749#[derive(Clone, PartialEq, Eq)]
2750pub enum StyleTextBoxEdgeParseError<'a> {
2751    InvalidValue(InvalidValueErr<'a>),
2752}
2753#[cfg(feature = "parser")]
2754impl_debug_as_display!(StyleTextBoxEdgeParseError<'a>);
2755#[cfg(feature = "parser")]
2756impl_display! { StyleTextBoxEdgeParseError<'a>, {
2757    InvalidValue(e) => format!("Invalid text-box-edge value: \"{}\"", e.0),
2758}}
2759#[cfg(feature = "parser")]
2760impl_from!(InvalidValueErr<'a>, StyleTextBoxEdgeParseError::InvalidValue);
2761
2762#[cfg(feature = "parser")]
2763#[derive(Debug, Clone, PartialEq, Eq)]
2764#[repr(C, u8)]
2765pub enum StyleTextBoxEdgeParseErrorOwned {
2766    InvalidValue(InvalidValueErrOwned),
2767}
2768
2769#[cfg(feature = "parser")]
2770impl StyleTextBoxEdgeParseError<'_> {
2771    #[must_use] pub fn to_contained(&self) -> StyleTextBoxEdgeParseErrorOwned {
2772        match self {
2773            Self::InvalidValue(e) => StyleTextBoxEdgeParseErrorOwned::InvalidValue(e.to_contained()),
2774        }
2775    }
2776}
2777
2778#[cfg(feature = "parser")]
2779impl StyleTextBoxEdgeParseErrorOwned {
2780    #[must_use] pub fn to_shared(&self) -> StyleTextBoxEdgeParseError<'_> {
2781        match self {
2782            Self::InvalidValue(e) => StyleTextBoxEdgeParseError::InvalidValue(e.to_shared()),
2783        }
2784    }
2785}
2786
2787#[cfg(feature = "parser")]
2788/// # Errors
2789///
2790/// Returns an error if `input` is not a valid CSS `text-box-edge` value.
2791pub fn parse_style_text_box_edge(input: &str) -> Result<StyleTextBoxEdge, StyleTextBoxEdgeParseError<'_>> {
2792    match input.trim() {
2793        "auto" => Ok(StyleTextBoxEdge::Auto),
2794        "text" => Ok(StyleTextBoxEdge::TextEdge),
2795        "cap" => Ok(StyleTextBoxEdge::CapHeight),
2796        "ex" => Ok(StyleTextBoxEdge::ExHeight),
2797        other => Err(StyleTextBoxEdgeParseError::InvalidValue(InvalidValueErr(other))),
2798    }
2799}
2800
2801// -- StyleDominantBaseline --
2802
2803/// Represents the `dominant-baseline` CSS property.
2804///
2805/// Specifies the dominant baseline used to align inline-level contents.
2806#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2807#[repr(C)]
2808#[derive(Default)]
2809pub enum StyleDominantBaseline {
2810    /// Use the dominant baseline of the parent
2811    #[default]
2812    Auto,
2813    /// Use the text-under baseline
2814    TextBottom,
2815    /// Use the alphabetic baseline
2816    Alphabetic,
2817    /// Use the ideographic baseline
2818    Ideographic,
2819    /// Use the middle baseline
2820    Middle,
2821    /// Use the central baseline
2822    Central,
2823    /// Use the mathematical baseline
2824    Mathematical,
2825    /// Use the hanging baseline
2826    Hanging,
2827    /// Use the text-over baseline
2828    TextTop,
2829}
2830impl_option!(
2831    StyleDominantBaseline,
2832    OptionStyleDominantBaseline,
2833    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
2834);
2835impl PrintAsCssValue for StyleDominantBaseline {
2836    fn print_as_css_value(&self) -> String {
2837        String::from(match self {
2838            Self::Auto => "auto",
2839            Self::TextBottom => "text-bottom",
2840            Self::Alphabetic => "alphabetic",
2841            Self::Ideographic => "ideographic",
2842            Self::Middle => "middle",
2843            Self::Central => "central",
2844            Self::Mathematical => "mathematical",
2845            Self::Hanging => "hanging",
2846            Self::TextTop => "text-top",
2847        })
2848    }
2849}
2850
2851#[cfg(feature = "parser")]
2852#[derive(Clone, PartialEq, Eq)]
2853pub enum StyleDominantBaselineParseError<'a> {
2854    InvalidValue(InvalidValueErr<'a>),
2855}
2856#[cfg(feature = "parser")]
2857impl_debug_as_display!(StyleDominantBaselineParseError<'a>);
2858#[cfg(feature = "parser")]
2859impl_display! { StyleDominantBaselineParseError<'a>, {
2860    InvalidValue(e) => format!("Invalid dominant-baseline value: \"{}\"", e.0),
2861}}
2862#[cfg(feature = "parser")]
2863impl_from!(InvalidValueErr<'a>, StyleDominantBaselineParseError::InvalidValue);
2864
2865#[cfg(feature = "parser")]
2866#[derive(Debug, Clone, PartialEq, Eq)]
2867#[repr(C, u8)]
2868pub enum StyleDominantBaselineParseErrorOwned {
2869    InvalidValue(InvalidValueErrOwned),
2870}
2871
2872#[cfg(feature = "parser")]
2873impl StyleDominantBaselineParseError<'_> {
2874    #[must_use] pub fn to_contained(&self) -> StyleDominantBaselineParseErrorOwned {
2875        match self {
2876            Self::InvalidValue(e) => StyleDominantBaselineParseErrorOwned::InvalidValue(e.to_contained()),
2877        }
2878    }
2879}
2880
2881#[cfg(feature = "parser")]
2882impl StyleDominantBaselineParseErrorOwned {
2883    #[must_use] pub fn to_shared(&self) -> StyleDominantBaselineParseError<'_> {
2884        match self {
2885            Self::InvalidValue(e) => StyleDominantBaselineParseError::InvalidValue(e.to_shared()),
2886        }
2887    }
2888}
2889
2890#[cfg(feature = "parser")]
2891/// # Errors
2892///
2893/// Returns an error if `input` is not a valid CSS `dominant-baseline` value.
2894pub fn parse_style_dominant_baseline(input: &str) -> Result<StyleDominantBaseline, StyleDominantBaselineParseError<'_>> {
2895    match input.trim() {
2896        "auto" => Ok(StyleDominantBaseline::Auto),
2897        "text-bottom" => Ok(StyleDominantBaseline::TextBottom),
2898        "alphabetic" => Ok(StyleDominantBaseline::Alphabetic),
2899        "ideographic" => Ok(StyleDominantBaseline::Ideographic),
2900        "middle" => Ok(StyleDominantBaseline::Middle),
2901        "central" => Ok(StyleDominantBaseline::Central),
2902        "mathematical" => Ok(StyleDominantBaseline::Mathematical),
2903        "hanging" => Ok(StyleDominantBaseline::Hanging),
2904        "text-top" => Ok(StyleDominantBaseline::TextTop),
2905        other => Err(StyleDominantBaselineParseError::InvalidValue(InvalidValueErr(other))),
2906    }
2907}
2908
2909// -- StyleAlignmentBaseline --
2910
2911// +spec:display-property:c90924 - alignment-baseline property: values, initial value, and applies-to per CSS Inline 3 §4.2.2
2912// +spec:font-metrics:fa4489 - alignment-baseline property: specifies box's alignment baseline used before post-alignment shift
2913// +spec:inline-block:939f05 - alignment-baseline property definition with all spec values (baseline, text-bottom, alphabetic, ideographic, middle, central, mathematical, text-top)
2914/// Represents the `alignment-baseline` CSS property.
2915///
2916/// Specifies which baseline of the element is aligned with the dominant baseline.
2917// +spec:writing-modes:cc8e70 - alignment-baseline values for inline baseline alignment
2918#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2919#[repr(C)]
2920#[derive(Default)]
2921pub enum StyleAlignmentBaseline {
2922    /// Use the dominant baseline of the parent
2923    #[default]
2924    Baseline,
2925    /// Align to the text-under baseline
2926    TextBottom,
2927    /// Align to the alphabetic baseline
2928    Alphabetic,
2929    /// Align to the ideographic baseline
2930    Ideographic,
2931    /// Align to the middle baseline
2932    Middle,
2933    /// Align to the central baseline
2934    Central,
2935    /// Align to the mathematical baseline
2936    Mathematical,
2937    /// Align to the text-over baseline
2938    TextTop,
2939}
2940impl_option!(
2941    StyleAlignmentBaseline,
2942    OptionStyleAlignmentBaseline,
2943    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
2944);
2945impl PrintAsCssValue for StyleAlignmentBaseline {
2946    fn print_as_css_value(&self) -> String {
2947        String::from(match self {
2948            Self::Baseline => "baseline",
2949            Self::TextBottom => "text-bottom",
2950            Self::Alphabetic => "alphabetic",
2951            Self::Ideographic => "ideographic",
2952            Self::Middle => "middle",
2953            Self::Central => "central",
2954            Self::Mathematical => "mathematical",
2955            Self::TextTop => "text-top",
2956        })
2957    }
2958}
2959
2960#[cfg(feature = "parser")]
2961#[derive(Clone, PartialEq, Eq)]
2962pub enum StyleAlignmentBaselineParseError<'a> {
2963    InvalidValue(InvalidValueErr<'a>),
2964}
2965#[cfg(feature = "parser")]
2966impl_debug_as_display!(StyleAlignmentBaselineParseError<'a>);
2967#[cfg(feature = "parser")]
2968impl_display! { StyleAlignmentBaselineParseError<'a>, {
2969    InvalidValue(e) => format!("Invalid alignment-baseline value: \"{}\"", e.0),
2970}}
2971#[cfg(feature = "parser")]
2972impl_from!(InvalidValueErr<'a>, StyleAlignmentBaselineParseError::InvalidValue);
2973
2974#[cfg(feature = "parser")]
2975#[derive(Debug, Clone, PartialEq, Eq)]
2976#[repr(C, u8)]
2977pub enum StyleAlignmentBaselineParseErrorOwned {
2978    InvalidValue(InvalidValueErrOwned),
2979}
2980
2981#[cfg(feature = "parser")]
2982impl StyleAlignmentBaselineParseError<'_> {
2983    #[must_use] pub fn to_contained(&self) -> StyleAlignmentBaselineParseErrorOwned {
2984        match self {
2985            Self::InvalidValue(e) => StyleAlignmentBaselineParseErrorOwned::InvalidValue(e.to_contained()),
2986        }
2987    }
2988}
2989
2990#[cfg(feature = "parser")]
2991impl StyleAlignmentBaselineParseErrorOwned {
2992    #[must_use] pub fn to_shared(&self) -> StyleAlignmentBaselineParseError<'_> {
2993        match self {
2994            Self::InvalidValue(e) => StyleAlignmentBaselineParseError::InvalidValue(e.to_shared()),
2995        }
2996    }
2997}
2998
2999#[cfg(feature = "parser")]
3000/// # Errors
3001///
3002/// Returns an error if `input` is not a valid CSS `alignment-baseline` value.
3003pub fn parse_style_alignment_baseline(input: &str) -> Result<StyleAlignmentBaseline, StyleAlignmentBaselineParseError<'_>> {
3004    match input.trim() {
3005        "baseline" => Ok(StyleAlignmentBaseline::Baseline),
3006        "text-bottom" => Ok(StyleAlignmentBaseline::TextBottom),
3007        "alphabetic" => Ok(StyleAlignmentBaseline::Alphabetic),
3008        "ideographic" => Ok(StyleAlignmentBaseline::Ideographic),
3009        "middle" => Ok(StyleAlignmentBaseline::Middle),
3010        "central" => Ok(StyleAlignmentBaseline::Central),
3011        "mathematical" => Ok(StyleAlignmentBaseline::Mathematical),
3012        "text-top" => Ok(StyleAlignmentBaseline::TextTop),
3013        other => Err(StyleAlignmentBaselineParseError::InvalidValue(InvalidValueErr(other))),
3014    }
3015}
3016
3017// -- StyleInitialLetterAlign --
3018
3019/// Represents the `initial-letter-align` CSS property.
3020///
3021/// Specifies the alignment points used to align an initial letter.
3022#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3023#[repr(C)]
3024#[derive(Default)]
3025pub enum StyleInitialLetterAlign {
3026    /// Automatically determine alignment based on script
3027    #[default]
3028    Auto,
3029    /// Align to the alphabetic baseline
3030    Alphabetic,
3031    /// Align to the hanging baseline
3032    Hanging,
3033    /// Align to the ideographic baseline
3034    Ideographic,
3035}
3036impl_option!(
3037    StyleInitialLetterAlign,
3038    OptionStyleInitialLetterAlign,
3039    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
3040);
3041impl PrintAsCssValue for StyleInitialLetterAlign {
3042    fn print_as_css_value(&self) -> String {
3043        String::from(match self {
3044            Self::Auto => "auto",
3045            Self::Alphabetic => "alphabetic",
3046            Self::Hanging => "hanging",
3047            Self::Ideographic => "ideographic",
3048        })
3049    }
3050}
3051
3052#[cfg(feature = "parser")]
3053#[derive(Clone, PartialEq, Eq)]
3054pub enum StyleInitialLetterAlignParseError<'a> {
3055    InvalidValue(InvalidValueErr<'a>),
3056}
3057#[cfg(feature = "parser")]
3058impl_debug_as_display!(StyleInitialLetterAlignParseError<'a>);
3059#[cfg(feature = "parser")]
3060impl_display! { StyleInitialLetterAlignParseError<'a>, {
3061    InvalidValue(e) => format!("Invalid initial-letter-align value: \"{}\"", e.0),
3062}}
3063#[cfg(feature = "parser")]
3064impl_from!(InvalidValueErr<'a>, StyleInitialLetterAlignParseError::InvalidValue);
3065
3066#[cfg(feature = "parser")]
3067#[derive(Debug, Clone, PartialEq, Eq)]
3068#[repr(C, u8)]
3069pub enum StyleInitialLetterAlignParseErrorOwned {
3070    InvalidValue(InvalidValueErrOwned),
3071}
3072
3073#[cfg(feature = "parser")]
3074impl StyleInitialLetterAlignParseError<'_> {
3075    #[must_use] pub fn to_contained(&self) -> StyleInitialLetterAlignParseErrorOwned {
3076        match self {
3077            Self::InvalidValue(e) => StyleInitialLetterAlignParseErrorOwned::InvalidValue(e.to_contained()),
3078        }
3079    }
3080}
3081
3082#[cfg(feature = "parser")]
3083impl StyleInitialLetterAlignParseErrorOwned {
3084    #[must_use] pub fn to_shared(&self) -> StyleInitialLetterAlignParseError<'_> {
3085        match self {
3086            Self::InvalidValue(e) => StyleInitialLetterAlignParseError::InvalidValue(e.to_shared()),
3087        }
3088    }
3089}
3090
3091#[cfg(feature = "parser")]
3092/// # Errors
3093///
3094/// Returns an error if `input` is not a valid CSS `initial-letter-align` value.
3095pub fn parse_style_initial_letter_align(input: &str) -> Result<StyleInitialLetterAlign, StyleInitialLetterAlignParseError<'_>> {
3096    match input.trim() {
3097        "auto" => Ok(StyleInitialLetterAlign::Auto),
3098        "alphabetic" => Ok(StyleInitialLetterAlign::Alphabetic),
3099        "hanging" => Ok(StyleInitialLetterAlign::Hanging),
3100        "ideographic" => Ok(StyleInitialLetterAlign::Ideographic),
3101        other => Err(StyleInitialLetterAlignParseError::InvalidValue(InvalidValueErr(other))),
3102    }
3103}
3104
3105// -- StyleInitialLetterWrap --
3106
3107/// Represents the `initial-letter-wrap` CSS property.
3108///
3109/// Specifies how text adjacent to an initial letter wraps.
3110#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3111#[repr(C)]
3112#[derive(Default)]
3113pub enum StyleInitialLetterWrap {
3114    /// No special wrapping around the initial letter
3115    #[default]
3116    None,
3117    /// Wrap only the first line adjacent to the initial letter
3118    First,
3119    /// Wrap all lines adjacent to the initial letter
3120    All,
3121    /// Wrap using a grid-based layout
3122    Grid,
3123}
3124impl_option!(
3125    StyleInitialLetterWrap,
3126    OptionStyleInitialLetterWrap,
3127    [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
3128);
3129impl PrintAsCssValue for StyleInitialLetterWrap {
3130    fn print_as_css_value(&self) -> String {
3131        String::from(match self {
3132            Self::None => "none",
3133            Self::First => "first",
3134            Self::All => "all",
3135            Self::Grid => "grid",
3136        })
3137    }
3138}
3139
3140#[cfg(feature = "parser")]
3141#[derive(Clone, PartialEq, Eq)]
3142pub enum StyleInitialLetterWrapParseError<'a> {
3143    InvalidValue(InvalidValueErr<'a>),
3144}
3145#[cfg(feature = "parser")]
3146impl_debug_as_display!(StyleInitialLetterWrapParseError<'a>);
3147#[cfg(feature = "parser")]
3148impl_display! { StyleInitialLetterWrapParseError<'a>, {
3149    InvalidValue(e) => format!("Invalid initial-letter-wrap value: \"{}\"", e.0),
3150}}
3151#[cfg(feature = "parser")]
3152impl_from!(InvalidValueErr<'a>, StyleInitialLetterWrapParseError::InvalidValue);
3153
3154#[cfg(feature = "parser")]
3155#[derive(Debug, Clone, PartialEq, Eq)]
3156#[repr(C, u8)]
3157pub enum StyleInitialLetterWrapParseErrorOwned {
3158    InvalidValue(InvalidValueErrOwned),
3159}
3160
3161#[cfg(feature = "parser")]
3162impl StyleInitialLetterWrapParseError<'_> {
3163    #[must_use] pub fn to_contained(&self) -> StyleInitialLetterWrapParseErrorOwned {
3164        match self {
3165            Self::InvalidValue(e) => StyleInitialLetterWrapParseErrorOwned::InvalidValue(e.to_contained()),
3166        }
3167    }
3168}
3169
3170#[cfg(feature = "parser")]
3171impl StyleInitialLetterWrapParseErrorOwned {
3172    #[must_use] pub fn to_shared(&self) -> StyleInitialLetterWrapParseError<'_> {
3173        match self {
3174            Self::InvalidValue(e) => StyleInitialLetterWrapParseError::InvalidValue(e.to_shared()),
3175        }
3176    }
3177}
3178
3179#[cfg(feature = "parser")]
3180/// # Errors
3181///
3182/// Returns an error if `input` is not a valid CSS `initial-letter-wrap` value.
3183pub fn parse_style_initial_letter_wrap(input: &str) -> Result<StyleInitialLetterWrap, StyleInitialLetterWrapParseError<'_>> {
3184    match input.trim() {
3185        "none" => Ok(StyleInitialLetterWrap::None),
3186        "first" => Ok(StyleInitialLetterWrap::First),
3187        "all" => Ok(StyleInitialLetterWrap::All),
3188        "grid" => Ok(StyleInitialLetterWrap::Grid),
3189        other => Err(StyleInitialLetterWrapParseError::InvalidValue(InvalidValueErr(other))),
3190    }
3191}