1use 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#[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#[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#[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#[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#[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#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
182#[repr(C)]
183pub struct StyleTabSize {
184 pub inner: PixelValue, }
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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
217#[repr(C)]
218#[derive(Default)]
219pub enum StyleWhiteSpace {
220 #[default]
222 Normal,
223 Pre,
225 Nowrap,
227 PreWrap,
229 PreLine,
231 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
256#[repr(C)]
257#[derive(Default)]
258pub enum StyleHyphens {
259 None,
261 #[default]
264 Manual,
265 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
291#[repr(C)]
292#[derive(Default)]
293pub enum StyleLineBreak {
294 #[default]
296 Auto,
297 Loose,
299 Normal,
301 Strict,
303 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
331#[repr(C)]
332#[derive(Default)]
333pub enum StyleWordBreak {
334 #[default]
336 Normal,
337 BreakAll,
339 KeepAll,
341 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
368#[repr(C)]
369#[derive(Default)]
370pub enum StyleOverflowWrap {
371 #[default]
373 Normal,
374 Anywhere,
377 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
403#[repr(C)]
404#[derive(Default)]
405pub enum StyleTextAlignLast {
406 #[default]
408 Auto,
409 Start,
411 End,
413 Left,
415 Right,
417 Center,
419 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
447#[repr(C)]
448#[derive(Default)]
449pub enum StyleTextTransform {
450 #[default]
452 None,
453 Capitalize,
455 Uppercase,
457 Lowercase,
459 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
484#[repr(C)]
485#[derive(Default)]
486pub enum StyleDirection {
487 #[default]
489 Ltr,
490 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
512#[repr(C)]
513#[derive(Default)]
514pub enum StyleUserSelect {
515 #[default]
517 Auto,
518 Text,
520 None,
522 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
545#[repr(C)]
546#[derive(Default)]
547pub enum StyleTextDecoration {
548 #[default]
550 None,
551 Underline,
553 Overline,
555 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
578#[repr(C, u8)]
579#[derive(Default)]
580pub enum StyleVerticalAlign {
581 #[default]
583 Baseline,
584 Top,
586 Middle,
588 Bottom,
590 Sub,
592 Superscript,
594 TextTop,
596 TextBottom,
598 Percentage(PercentageValue),
600 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#[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")]
697pub 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")]
746pub 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")]
806pub 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#[derive(Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
821#[repr(C)]
822pub struct StyleTextIndent {
823 pub inner: PixelValue,
824 pub each_line: bool,
827 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")]
965pub 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#[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")]
1088pub 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 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 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#[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)] #[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")]
1199pub 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#[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")]
1309pub 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#[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")]
1431pub 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 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")]
1506pub 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")]
1557pub fn parse_style_line_height(input: &str) -> Result<StyleLineHeight, StyleLineHeightParseError> {
1561 if let Ok(inner) = crate::props::basic::length::parse_percentage_value(input) {
1563 return Ok(StyleLineHeight { inner });
1564 }
1565 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")]
1624pub 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")]
1682pub 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")]
1739pub 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#[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")]
1793pub 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#[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")]
1849pub 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#[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")]
1904pub 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#[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")]
1958pub 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#[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")]
2016pub 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")]
2070pub 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")]
2123pub 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")]
2183pub 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")]
2245pub 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#[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")]
2306pub fn parse_caret_color(input: &str) -> Result<CaretColor, CssColorParseError<'_>> {
2310 parse_css_color(input).map(|inner| CaretColor { inner })
2311}
2312
2313#[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 } }
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")]
2345pub 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#[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), }
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")]
2390pub 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
2399impl 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 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 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2532#[repr(C)]
2533#[derive(Default)]
2534pub enum StyleUnicodeBidi {
2535 #[default]
2537 Normal,
2538 Embed,
2540 Isolate,
2542 BidiOverride,
2544 IsolateOverride,
2546 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")]
2607pub 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2628#[repr(C)]
2629#[derive(Default)]
2630pub enum StyleTextBoxTrim {
2631 #[default]
2633 None,
2634 TrimStart,
2636 TrimEnd,
2638 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")]
2697pub 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2718#[repr(C)]
2719#[derive(Default)]
2720pub enum StyleTextBoxEdge {
2721 #[default]
2724 Auto,
2725 TextEdge,
2727 CapHeight,
2729 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")]
2788pub 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2807#[repr(C)]
2808#[derive(Default)]
2809pub enum StyleDominantBaseline {
2810 #[default]
2812 Auto,
2813 TextBottom,
2815 Alphabetic,
2817 Ideographic,
2819 Middle,
2821 Central,
2823 Mathematical,
2825 Hanging,
2827 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")]
2891pub 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2919#[repr(C)]
2920#[derive(Default)]
2921pub enum StyleAlignmentBaseline {
2922 #[default]
2924 Baseline,
2925 TextBottom,
2927 Alphabetic,
2929 Ideographic,
2931 Middle,
2933 Central,
2935 Mathematical,
2937 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")]
3000pub 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#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3025#[repr(C)]
3026#[derive(Default)]
3027pub enum StyleBaselineSource {
3028 #[default]
3030 Auto,
3031 First,
3033 Last,
3035}
3036impl_option!(
3037 StyleBaselineSource,
3038 OptionStyleBaselineSource,
3039 [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
3040);
3041impl PrintAsCssValue for StyleBaselineSource {
3042 fn print_as_css_value(&self) -> String {
3043 String::from(match self {
3044 Self::Auto => "auto",
3045 Self::First => "first",
3046 Self::Last => "last",
3047 })
3048 }
3049}
3050
3051#[cfg(feature = "parser")]
3052#[derive(Clone, PartialEq, Eq)]
3053pub enum StyleBaselineSourceParseError<'a> {
3054 InvalidValue(InvalidValueErr<'a>),
3055}
3056#[cfg(feature = "parser")]
3057impl_debug_as_display!(StyleBaselineSourceParseError<'a>);
3058#[cfg(feature = "parser")]
3059impl_display! { StyleBaselineSourceParseError<'a>, {
3060 InvalidValue(e) => format!("Invalid baseline-source value: \"{}\"", e.0),
3061}}
3062#[cfg(feature = "parser")]
3063impl_from!(InvalidValueErr<'a>, StyleBaselineSourceParseError::InvalidValue);
3064
3065#[cfg(feature = "parser")]
3066#[derive(Debug, Clone, PartialEq, Eq)]
3067#[repr(C, u8)]
3068pub enum StyleBaselineSourceParseErrorOwned {
3069 InvalidValue(InvalidValueErrOwned),
3070}
3071
3072#[cfg(feature = "parser")]
3073impl StyleBaselineSourceParseError<'_> {
3074 #[must_use] pub fn to_contained(&self) -> StyleBaselineSourceParseErrorOwned {
3075 match self {
3076 Self::InvalidValue(e) => StyleBaselineSourceParseErrorOwned::InvalidValue(e.to_contained()),
3077 }
3078 }
3079}
3080
3081#[cfg(feature = "parser")]
3082impl StyleBaselineSourceParseErrorOwned {
3083 #[must_use] pub fn to_shared(&self) -> StyleBaselineSourceParseError<'_> {
3084 match self {
3085 Self::InvalidValue(e) => StyleBaselineSourceParseError::InvalidValue(e.to_shared()),
3086 }
3087 }
3088}
3089
3090#[cfg(feature = "parser")]
3091pub fn parse_style_baseline_source(input: &str) -> Result<StyleBaselineSource, StyleBaselineSourceParseError<'_>> {
3095 match input.trim() {
3096 "auto" => Ok(StyleBaselineSource::Auto),
3097 "first" => Ok(StyleBaselineSource::First),
3098 "last" => Ok(StyleBaselineSource::Last),
3099 other => Err(StyleBaselineSourceParseError::InvalidValue(InvalidValueErr(other))),
3100 }
3101}
3102
3103#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3113#[repr(C)]
3114#[derive(Default)]
3115pub enum StyleLineFitEdge {
3116 #[default]
3118 Leading,
3119 Text,
3121 Cap,
3123 Ex,
3125 Ideographic,
3127 IdeographicInk,
3129 Alphabetic,
3131}
3132impl_option!(
3133 StyleLineFitEdge,
3134 OptionStyleLineFitEdge,
3135 [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
3136);
3137impl PrintAsCssValue for StyleLineFitEdge {
3138 fn print_as_css_value(&self) -> String {
3139 String::from(match self {
3140 Self::Leading => "leading",
3141 Self::Text => "text",
3142 Self::Cap => "cap",
3143 Self::Ex => "ex",
3144 Self::Ideographic => "ideographic",
3145 Self::IdeographicInk => "ideographic-ink",
3146 Self::Alphabetic => "alphabetic",
3147 })
3148 }
3149}
3150
3151#[cfg(feature = "parser")]
3152#[derive(Clone, PartialEq, Eq)]
3153pub enum StyleLineFitEdgeParseError<'a> {
3154 InvalidValue(InvalidValueErr<'a>),
3155}
3156#[cfg(feature = "parser")]
3157impl_debug_as_display!(StyleLineFitEdgeParseError<'a>);
3158#[cfg(feature = "parser")]
3159impl_display! { StyleLineFitEdgeParseError<'a>, {
3160 InvalidValue(e) => format!("Invalid line-fit-edge value: \"{}\"", e.0),
3161}}
3162#[cfg(feature = "parser")]
3163impl_from!(InvalidValueErr<'a>, StyleLineFitEdgeParseError::InvalidValue);
3164
3165#[cfg(feature = "parser")]
3166#[derive(Debug, Clone, PartialEq, Eq)]
3167#[repr(C, u8)]
3168pub enum StyleLineFitEdgeParseErrorOwned {
3169 InvalidValue(InvalidValueErrOwned),
3170}
3171
3172#[cfg(feature = "parser")]
3173impl StyleLineFitEdgeParseError<'_> {
3174 #[must_use] pub fn to_contained(&self) -> StyleLineFitEdgeParseErrorOwned {
3175 match self {
3176 Self::InvalidValue(e) => StyleLineFitEdgeParseErrorOwned::InvalidValue(e.to_contained()),
3177 }
3178 }
3179}
3180
3181#[cfg(feature = "parser")]
3182impl StyleLineFitEdgeParseErrorOwned {
3183 #[must_use] pub fn to_shared(&self) -> StyleLineFitEdgeParseError<'_> {
3184 match self {
3185 Self::InvalidValue(e) => StyleLineFitEdgeParseError::InvalidValue(e.to_shared()),
3186 }
3187 }
3188}
3189
3190#[cfg(feature = "parser")]
3191pub fn parse_style_line_fit_edge(input: &str) -> Result<StyleLineFitEdge, StyleLineFitEdgeParseError<'_>> {
3195 match input.trim() {
3196 "leading" => Ok(StyleLineFitEdge::Leading),
3197 "text" => Ok(StyleLineFitEdge::Text),
3198 "cap" => Ok(StyleLineFitEdge::Cap),
3199 "ex" => Ok(StyleLineFitEdge::Ex),
3200 "ideographic" => Ok(StyleLineFitEdge::Ideographic),
3201 "ideographic-ink" => Ok(StyleLineFitEdge::IdeographicInk),
3202 "alphabetic" => Ok(StyleLineFitEdge::Alphabetic),
3203 other => Err(StyleLineFitEdgeParseError::InvalidValue(InvalidValueErr(other))),
3204 }
3205}
3206
3207#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3213#[repr(C)]
3214#[derive(Default)]
3215pub enum StyleInitialLetterAlign {
3216 #[default]
3218 Auto,
3219 Alphabetic,
3221 Hanging,
3223 Ideographic,
3225}
3226impl_option!(
3227 StyleInitialLetterAlign,
3228 OptionStyleInitialLetterAlign,
3229 [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
3230);
3231impl PrintAsCssValue for StyleInitialLetterAlign {
3232 fn print_as_css_value(&self) -> String {
3233 String::from(match self {
3234 Self::Auto => "auto",
3235 Self::Alphabetic => "alphabetic",
3236 Self::Hanging => "hanging",
3237 Self::Ideographic => "ideographic",
3238 })
3239 }
3240}
3241
3242#[cfg(feature = "parser")]
3243#[derive(Clone, PartialEq, Eq)]
3244pub enum StyleInitialLetterAlignParseError<'a> {
3245 InvalidValue(InvalidValueErr<'a>),
3246}
3247#[cfg(feature = "parser")]
3248impl_debug_as_display!(StyleInitialLetterAlignParseError<'a>);
3249#[cfg(feature = "parser")]
3250impl_display! { StyleInitialLetterAlignParseError<'a>, {
3251 InvalidValue(e) => format!("Invalid initial-letter-align value: \"{}\"", e.0),
3252}}
3253#[cfg(feature = "parser")]
3254impl_from!(InvalidValueErr<'a>, StyleInitialLetterAlignParseError::InvalidValue);
3255
3256#[cfg(feature = "parser")]
3257#[derive(Debug, Clone, PartialEq, Eq)]
3258#[repr(C, u8)]
3259pub enum StyleInitialLetterAlignParseErrorOwned {
3260 InvalidValue(InvalidValueErrOwned),
3261}
3262
3263#[cfg(feature = "parser")]
3264impl StyleInitialLetterAlignParseError<'_> {
3265 #[must_use] pub fn to_contained(&self) -> StyleInitialLetterAlignParseErrorOwned {
3266 match self {
3267 Self::InvalidValue(e) => StyleInitialLetterAlignParseErrorOwned::InvalidValue(e.to_contained()),
3268 }
3269 }
3270}
3271
3272#[cfg(feature = "parser")]
3273impl StyleInitialLetterAlignParseErrorOwned {
3274 #[must_use] pub fn to_shared(&self) -> StyleInitialLetterAlignParseError<'_> {
3275 match self {
3276 Self::InvalidValue(e) => StyleInitialLetterAlignParseError::InvalidValue(e.to_shared()),
3277 }
3278 }
3279}
3280
3281#[cfg(feature = "parser")]
3282pub fn parse_style_initial_letter_align(input: &str) -> Result<StyleInitialLetterAlign, StyleInitialLetterAlignParseError<'_>> {
3286 match input.trim() {
3287 "auto" => Ok(StyleInitialLetterAlign::Auto),
3288 "alphabetic" => Ok(StyleInitialLetterAlign::Alphabetic),
3289 "hanging" => Ok(StyleInitialLetterAlign::Hanging),
3290 "ideographic" => Ok(StyleInitialLetterAlign::Ideographic),
3291 other => Err(StyleInitialLetterAlignParseError::InvalidValue(InvalidValueErr(other))),
3292 }
3293}
3294
3295#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3301#[repr(C)]
3302#[derive(Default)]
3303pub enum StyleInitialLetterWrap {
3304 #[default]
3306 None,
3307 First,
3309 All,
3311 Grid,
3313}
3314impl_option!(
3315 StyleInitialLetterWrap,
3316 OptionStyleInitialLetterWrap,
3317 [Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash]
3318);
3319impl PrintAsCssValue for StyleInitialLetterWrap {
3320 fn print_as_css_value(&self) -> String {
3321 String::from(match self {
3322 Self::None => "none",
3323 Self::First => "first",
3324 Self::All => "all",
3325 Self::Grid => "grid",
3326 })
3327 }
3328}
3329
3330#[cfg(feature = "parser")]
3331#[derive(Clone, PartialEq, Eq)]
3332pub enum StyleInitialLetterWrapParseError<'a> {
3333 InvalidValue(InvalidValueErr<'a>),
3334}
3335#[cfg(feature = "parser")]
3336impl_debug_as_display!(StyleInitialLetterWrapParseError<'a>);
3337#[cfg(feature = "parser")]
3338impl_display! { StyleInitialLetterWrapParseError<'a>, {
3339 InvalidValue(e) => format!("Invalid initial-letter-wrap value: \"{}\"", e.0),
3340}}
3341#[cfg(feature = "parser")]
3342impl_from!(InvalidValueErr<'a>, StyleInitialLetterWrapParseError::InvalidValue);
3343
3344#[cfg(feature = "parser")]
3345#[derive(Debug, Clone, PartialEq, Eq)]
3346#[repr(C, u8)]
3347pub enum StyleInitialLetterWrapParseErrorOwned {
3348 InvalidValue(InvalidValueErrOwned),
3349}
3350
3351#[cfg(feature = "parser")]
3352impl StyleInitialLetterWrapParseError<'_> {
3353 #[must_use] pub fn to_contained(&self) -> StyleInitialLetterWrapParseErrorOwned {
3354 match self {
3355 Self::InvalidValue(e) => StyleInitialLetterWrapParseErrorOwned::InvalidValue(e.to_contained()),
3356 }
3357 }
3358}
3359
3360#[cfg(feature = "parser")]
3361impl StyleInitialLetterWrapParseErrorOwned {
3362 #[must_use] pub fn to_shared(&self) -> StyleInitialLetterWrapParseError<'_> {
3363 match self {
3364 Self::InvalidValue(e) => StyleInitialLetterWrapParseError::InvalidValue(e.to_shared()),
3365 }
3366 }
3367}
3368
3369#[cfg(feature = "parser")]
3370pub fn parse_style_initial_letter_wrap(input: &str) -> Result<StyleInitialLetterWrap, StyleInitialLetterWrapParseError<'_>> {
3374 match input.trim() {
3375 "none" => Ok(StyleInitialLetterWrap::None),
3376 "first" => Ok(StyleInitialLetterWrap::First),
3377 "all" => Ok(StyleInitialLetterWrap::All),
3378 "grid" => Ok(StyleInitialLetterWrap::Grid),
3379 other => Err(StyleInitialLetterWrapParseError::InvalidValue(InvalidValueErr(other))),
3380 }
3381}
3382
3383#[cfg(test)]
3384#[allow(clippy::float_cmp, clippy::too_many_lines, clippy::cast_precision_loss)]
3385mod autotest_generated {
3386 use super::*;
3387 use crate::props::basic::length::SizeMetric;
3388
3389 const OPAQUE_BLACK: ColorU = ColorU { r: 0, g: 0, b: 0, a: 255 };
3390 const OPAQUE_WHITE: ColorU = ColorU { r: 255, g: 255, b: 255, a: 255 };
3391 const TRANSPARENT_BLACK: ColorU = ColorU { r: 0, g: 0, b: 0, a: 0 };
3392
3393 const SCALE: isize = 1000;
3395
3396 #[test]
3401 fn text_indent_zero_is_the_neutral_element() {
3402 let z = StyleTextIndent::zero();
3403 assert_eq!(z, StyleTextIndent::default());
3404 assert_eq!(z.inner.metric, SizeMetric::Px);
3405 assert_eq!(z.inner.number.get(), 0.0);
3406 assert!(!z.each_line);
3407 assert!(!z.hanging);
3408 assert_eq!(z.print_as_css_value(), "0px");
3409 }
3410
3411 #[test]
3412 fn text_indent_const_ctors_pin_metric_and_value() {
3413 for v in [0_isize, 1, -1, 42, -42] {
3415 let cases = [
3416 (StyleTextIndent::const_px(v), SizeMetric::Px),
3417 (StyleTextIndent::const_em(v), SizeMetric::Em),
3418 (StyleTextIndent::const_pt(v), SizeMetric::Pt),
3419 (StyleTextIndent::const_percent(v), SizeMetric::Percent),
3420 (StyleTextIndent::const_in(v), SizeMetric::In),
3421 (StyleTextIndent::const_cm(v), SizeMetric::Cm),
3422 (StyleTextIndent::const_mm(v), SizeMetric::Mm),
3423 ];
3424 for (got, metric) in cases {
3425 assert_eq!(got.inner.metric, metric, "metric for {v}");
3426 assert_eq!(got.inner.number.get(), v as f32, "value for {v} {metric:?}");
3427 assert!(!got.each_line && !got.hanging);
3429 }
3430 }
3431 }
3432
3433 #[test]
3434 fn text_indent_const_ctors_hold_the_whole_encodable_isize_range() {
3435 assert_eq!(StyleTextIndent::const_px(1).inner.number.number(), SCALE);
3438
3439 let max = isize::MAX / SCALE;
3440 let min = isize::MIN / SCALE;
3441 assert_eq!(StyleTextIndent::const_px(max).inner.number.number(), max * SCALE);
3442 assert_eq!(StyleTextIndent::const_px(min).inner.number.number(), min * SCALE);
3443 assert_eq!(
3444 StyleTextIndent::const_from_metric(SizeMetric::Em, max).inner.number.number(),
3445 max * SCALE
3446 );
3447 }
3451
3452 #[test]
3453 fn text_indent_float_ctors_saturate_on_nan_and_infinity() {
3454 assert_eq!(StyleTextIndent::px(f32::NAN).inner.number.get(), 0.0);
3456 assert_eq!(StyleTextIndent::em(f32::NAN).inner.number.get(), 0.0);
3457
3458 assert_eq!(StyleTextIndent::px(f32::INFINITY).inner.number.number(), isize::MAX);
3459 assert_eq!(StyleTextIndent::px(f32::NEG_INFINITY).inner.number.number(), isize::MIN);
3460 assert_eq!(StyleTextIndent::pt(f32::MAX).inner.number.number(), isize::MAX);
3461 assert_eq!(StyleTextIndent::pt(-f32::MAX).inner.number.number(), isize::MIN);
3462
3463 assert_eq!(StyleTextIndent::percent(f32::MIN_POSITIVE).inner.number.number(), 0);
3465 assert_eq!(StyleTextIndent::px(-0.0).inner.number.number(), 0);
3466
3467 for v in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY, f32::MAX, -f32::MAX] {
3469 assert!(StyleTextIndent::px(v).inner.number.get().is_finite());
3470 }
3471 }
3472
3473 #[test]
3474 fn text_indent_from_metric_agrees_with_the_typed_ctors() {
3475 assert_eq!(StyleTextIndent::from_metric(SizeMetric::Px, 1.5), StyleTextIndent::px(1.5));
3476 assert_eq!(StyleTextIndent::from_metric(SizeMetric::Em, -2.5), StyleTextIndent::em(-2.5));
3477 assert_eq!(StyleTextIndent::from_metric(SizeMetric::Pt, 0.0), StyleTextIndent::pt(0.0));
3478 assert_eq!(
3479 StyleTextIndent::from_metric(SizeMetric::Percent, 50.0),
3480 StyleTextIndent::percent(50.0)
3481 );
3482 assert_eq!(StyleTextIndent::const_from_metric(SizeMetric::Cm, 3), StyleTextIndent::const_cm(3));
3483 assert_eq!(StyleTextIndent::const_from_metric(SizeMetric::Mm, -3), StyleTextIndent::const_mm(-3));
3484
3485 let vw = StyleTextIndent::from_metric(SizeMetric::Vw, 10.0);
3487 assert_eq!(vw.inner.metric, SizeMetric::Vw);
3488 assert_eq!(vw.inner.number.get(), 10.0);
3489 }
3490
3491 #[test]
3492 fn text_indent_interpolate_endpoints_and_extrapolation() {
3493 let a = StyleTextIndent::px(0.0);
3494 let b = StyleTextIndent::px(100.0);
3495
3496 assert_eq!(a.interpolate(&b, 0.0).inner.number.get(), 0.0);
3497 assert_eq!(a.interpolate(&b, 1.0).inner.number.get(), 100.0);
3498 assert_eq!(a.interpolate(&b, 0.5).inner.number.get(), 50.0);
3499 assert_eq!(a.interpolate(&b, -1.0).inner.number.get(), -100.0);
3501 assert_eq!(a.interpolate(&b, 2.0).inner.number.get(), 200.0);
3502 assert_eq!(b.interpolate(&b, 0.25), b);
3504 }
3505
3506 #[test]
3507 fn text_indent_interpolate_with_nonfinite_t_is_defined() {
3508 let a = StyleTextIndent::px(0.0);
3509 let b = StyleTextIndent::px(100.0);
3510
3511 assert_eq!(a.interpolate(&b, f32::NAN).inner.number.get(), 0.0);
3513 assert_eq!(a.interpolate(&b, f32::INFINITY).inner.number.number(), isize::MAX);
3515 assert_eq!(a.interpolate(&b, f32::NEG_INFINITY).inner.number.number(), isize::MIN);
3516 assert_eq!(b.interpolate(&b, f32::INFINITY).inner.number.get(), 0.0);
3518
3519 for t in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY, f32::MAX] {
3520 assert!(a.interpolate(&b, t).inner.number.get().is_finite());
3521 }
3522 }
3523
3524 #[test]
3525 fn text_indent_interpolate_keeps_self_flags_and_normalizes_mixed_metrics() {
3526 let a = StyleTextIndent { each_line: true, hanging: true, ..StyleTextIndent::px(0.0) };
3527 let b = StyleTextIndent { each_line: false, hanging: false, ..StyleTextIndent::px(10.0) };
3528
3529 let mid = a.interpolate(&b, 0.5);
3531 assert!(mid.each_line && mid.hanging);
3532 assert!(!b.interpolate(&a, 0.5).each_line);
3533
3534 let mixed = StyleTextIndent::px(10.0).interpolate(&StyleTextIndent::em(2.0), 0.5);
3536 assert_eq!(mixed.inner.metric, SizeMetric::Px);
3537 assert!(mixed.inner.number.get().is_finite());
3538 }
3539
3540 #[test]
3545 fn text_color_interpolate_endpoints_are_exact() {
3546 let a = StyleTextColor { inner: OPAQUE_BLACK };
3547 let b = StyleTextColor { inner: OPAQUE_WHITE };
3548
3549 assert_eq!(a.interpolate(&b, 0.0), a);
3550 assert_eq!(a.interpolate(&b, 1.0), b);
3551 assert_eq!(a.interpolate(&b, 0.5).inner, ColorU { r: 128, g: 128, b: 128, a: 255 });
3553 assert_eq!(a.print_as_css_value(), "#000000ff");
3554 }
3555
3556 #[test]
3557 fn text_color_interpolate_saturates_out_of_range_t() {
3558 let a = StyleTextColor { inner: OPAQUE_BLACK };
3559 let b = StyleTextColor { inner: OPAQUE_WHITE };
3560
3561 assert_eq!(a.interpolate(&b, 2.0).inner, OPAQUE_WHITE);
3563 assert_eq!(a.interpolate(&b, -1.0).inner, OPAQUE_BLACK);
3565 }
3566
3567 #[test]
3568 fn text_color_interpolate_with_nonfinite_t_is_defined() {
3569 let a = StyleTextColor { inner: OPAQUE_BLACK };
3570 let b = StyleTextColor { inner: OPAQUE_WHITE };
3571
3572 assert_eq!(a.interpolate(&b, f32::NAN).inner, TRANSPARENT_BLACK);
3575
3576 assert_eq!(
3580 a.interpolate(&b, f32::INFINITY).inner,
3581 ColorU { r: 255, g: 255, b: 255, a: 0 }
3582 );
3583 assert_eq!(
3584 a.interpolate(&b, f32::NEG_INFINITY).inner,
3585 ColorU { r: 0, g: 0, b: 0, a: 0 }
3586 );
3587 }
3588
3589 #[test]
3594 fn hanging_punctuation_is_enabled_matches_its_flags_exhaustively() {
3595 assert!(!StyleHangingPunctuation::default().is_enabled());
3596
3597 for bits in 0_u8..16 {
3598 let hp = StyleHangingPunctuation {
3599 first: bits & 1 != 0,
3600 force_end: bits & 2 != 0,
3601 allow_end: bits & 4 != 0,
3602 last: bits & 8 != 0,
3603 };
3604 assert_eq!(hp.is_enabled(), bits != 0, "bits={bits}");
3605 assert_eq!(hp.print_as_css_value() == "none", !hp.is_enabled(), "bits={bits}");
3607 }
3608 }
3609
3610 #[test]
3611 fn hanging_punctuation_prints_flags_in_spec_order() {
3612 let all = StyleHangingPunctuation { first: true, force_end: true, allow_end: true, last: true };
3613 assert_eq!(all.print_as_css_value(), "first force-end allow-end last");
3614 assert_eq!(
3615 StyleHangingPunctuation { last: true, ..Default::default() }.print_as_css_value(),
3616 "last"
3617 );
3618 }
3619
3620 #[cfg(feature = "parser")]
3625 mod parser {
3626 use super::super::*;
3627 use crate::props::basic::length::SizeMetric;
3628
3629 const GARBAGE: &[&str] = &[
3630 "",
3631 " ",
3632 "\t\n",
3633 "!!!",
3634 "\0\0",
3635 "0",
3636 "-0",
3637 "9223372036854775807",
3638 "1e400",
3639 "NaN",
3640 "inf",
3641 "\u{1F600}",
3642 "e\u{0301}",
3643 "\u{202E}left",
3644 "left;garbage",
3645 "left garbage",
3646 ];
3647
3648 macro_rules! assert_keyword_round_trip {
3650 ($parse:ident, $variants:expr) => {{
3651 for v in $variants {
3652 let printed = v.print_as_css_value();
3653 assert_eq!($parse(&printed).as_ref(), Ok(&v), "round-trip of {printed:?}");
3654 assert_eq!($parse(&format!(" {printed} ")).as_ref(), Ok(&v));
3656 }
3657 for g in GARBAGE.iter().copied() {
3658 assert!($parse(g).is_err(), "{} accepted garbage {g:?}", stringify!($parse));
3659 }
3660 }};
3661 }
3662
3663 #[test]
3664 fn keyword_parsers_round_trip_every_variant_and_reject_garbage() {
3665 type TA = StyleTextAlign;
3666 assert_keyword_round_trip!(
3667 parse_style_text_align,
3668 [TA::Left, TA::Center, TA::Right, TA::Justify, TA::Start, TA::End]
3669 );
3670 type WS = StyleWhiteSpace;
3671 assert_keyword_round_trip!(
3672 parse_style_white_space,
3673 [WS::Normal, WS::Pre, WS::Nowrap, WS::PreWrap, WS::PreLine, WS::BreakSpaces]
3674 );
3675 type H = StyleHyphens;
3676 assert_keyword_round_trip!(parse_style_hyphens, [H::None, H::Manual, H::Auto]);
3677 type LB = StyleLineBreak;
3678 assert_keyword_round_trip!(
3679 parse_style_line_break,
3680 [LB::Auto, LB::Loose, LB::Normal, LB::Strict, LB::Anywhere]
3681 );
3682 type WB = StyleWordBreak;
3683 assert_keyword_round_trip!(
3684 parse_style_word_break,
3685 [WB::Normal, WB::BreakAll, WB::KeepAll, WB::BreakWord]
3686 );
3687 type OW = StyleOverflowWrap;
3688 assert_keyword_round_trip!(
3689 parse_style_overflow_wrap,
3690 [OW::Normal, OW::Anywhere, OW::BreakWord]
3691 );
3692 type Tal = StyleTextAlignLast;
3693 assert_keyword_round_trip!(
3694 parse_style_text_align_last,
3695 [Tal::Auto, Tal::Start, Tal::End, Tal::Left, Tal::Right, Tal::Center, Tal::Justify]
3696 );
3697 type TT = StyleTextTransform;
3698 assert_keyword_round_trip!(
3699 parse_style_text_transform,
3700 [TT::None, TT::Capitalize, TT::Uppercase, TT::Lowercase, TT::FullWidth]
3701 );
3702 type D = StyleDirection;
3703 assert_keyword_round_trip!(parse_style_direction, [D::Ltr, D::Rtl]);
3704 type US = StyleUserSelect;
3705 assert_keyword_round_trip!(
3706 parse_style_user_select,
3707 [US::Auto, US::Text, US::None, US::All]
3708 );
3709 type TD = StyleTextDecoration;
3710 assert_keyword_round_trip!(
3711 parse_style_text_decoration,
3712 [TD::None, TD::Underline, TD::Overline, TD::LineThrough]
3713 );
3714 type UB = StyleUnicodeBidi;
3715 assert_keyword_round_trip!(
3716 parse_style_unicode_bidi,
3717 [UB::Normal, UB::Embed, UB::Isolate, UB::BidiOverride, UB::IsolateOverride, UB::Plaintext]
3718 );
3719 type Tbt = StyleTextBoxTrim;
3720 assert_keyword_round_trip!(
3721 parse_style_text_box_trim,
3722 [Tbt::None, Tbt::TrimStart, Tbt::TrimEnd, Tbt::TrimBoth]
3723 );
3724 type Tbe = StyleTextBoxEdge;
3725 assert_keyword_round_trip!(
3726 parse_style_text_box_edge,
3727 [Tbe::Auto, Tbe::TextEdge, Tbe::CapHeight, Tbe::ExHeight]
3728 );
3729 type DB = StyleDominantBaseline;
3730 assert_keyword_round_trip!(
3731 parse_style_dominant_baseline,
3732 [
3733 DB::Auto, DB::TextBottom, DB::Alphabetic, DB::Ideographic, DB::Middle,
3734 DB::Central, DB::Mathematical, DB::Hanging, DB::TextTop
3735 ]
3736 );
3737 type AB = StyleAlignmentBaseline;
3738 assert_keyword_round_trip!(
3739 parse_style_alignment_baseline,
3740 [
3741 AB::Baseline, AB::TextBottom, AB::Alphabetic, AB::Ideographic, AB::Middle,
3742 AB::Central, AB::Mathematical, AB::TextTop
3743 ]
3744 );
3745 type Bs = StyleBaselineSource;
3746 assert_keyword_round_trip!(
3747 parse_style_baseline_source,
3748 [Bs::Auto, Bs::First, Bs::Last]
3749 );
3750 type Lfe = StyleLineFitEdge;
3751 assert_keyword_round_trip!(
3752 parse_style_line_fit_edge,
3753 [
3754 Lfe::Leading, Lfe::Text, Lfe::Cap, Lfe::Ex, Lfe::Ideographic,
3755 Lfe::IdeographicInk, Lfe::Alphabetic
3756 ]
3757 );
3758 type Ila = StyleInitialLetterAlign;
3759 assert_keyword_round_trip!(
3760 parse_style_initial_letter_align,
3761 [Ila::Auto, Ila::Alphabetic, Ila::Hanging, Ila::Ideographic]
3762 );
3763 type Ilw = StyleInitialLetterWrap;
3764 assert_keyword_round_trip!(
3765 parse_style_initial_letter_wrap,
3766 [Ilw::None, Ilw::First, Ilw::All, Ilw::Grid]
3767 );
3768 }
3769
3770 #[test]
3771 fn keyword_parsers_are_case_sensitive() {
3772 assert!(parse_style_text_align("LEFT").is_err());
3777 assert!(parse_style_text_align("Left").is_err());
3778 assert!(parse_style_white_space("Normal").is_err());
3779 assert!(parse_style_direction("LTR").is_err());
3780 assert!(parse_style_hanging_punctuation("FIRST").is_ok());
3782 assert!(parse_style_text_combine_upright("NONE").is_ok());
3783 }
3784
3785 #[test]
3786 fn extremely_long_and_deeply_nested_input_terminates_with_err() {
3787 let long = "a".repeat(1_000_000);
3788 assert!(parse_style_text_align(&long).is_err());
3789 assert!(parse_style_white_space(&long).is_err());
3790 assert!(parse_style_text_color(&long).is_err());
3791 assert!(parse_style_letter_spacing(&long).is_err());
3792 assert!(parse_style_word_spacing(&long).is_err());
3793 assert!(parse_style_tab_size(&long).is_err());
3794 assert!(parse_style_line_height(&long).is_err());
3795 assert!(parse_style_text_indent(&long).is_err());
3796 assert!(parse_style_hanging_punctuation(&long).is_err());
3797 assert!(parse_style_initial_letter(&long).is_err());
3798 assert!(parse_style_line_clamp(&long).is_err());
3799 assert!(parse_style_vertical_align(&long).is_err());
3800
3801 let huge_number = "9".repeat(1000);
3803 assert!(parse_style_line_clamp(&huge_number).is_err());
3804 assert!(parse_style_initial_letter(&huge_number).is_err());
3805
3806 let nested = format!("{}{}", "(".repeat(10_000), ")".repeat(10_000));
3808 assert!(parse_style_text_align(&nested).is_err());
3809 assert!(parse_style_letter_spacing(&nested).is_err());
3810 assert!(parse_style_text_indent(&nested).is_err());
3811 assert!(parse_style_line_height(&nested).is_err());
3812 }
3813
3814 #[test]
3817 fn spacing_and_tab_size_round_trip_through_their_printed_form() {
3818 for pv in [
3819 PixelValue::px(2.0),
3820 PixelValue::px(-3.0),
3821 PixelValue::em(0.5),
3822 PixelValue::pt(12.0),
3823 PixelValue::percent(10.0),
3824 PixelValue::zero(),
3825 ] {
3826 let ls = StyleLetterSpacing { inner: pv };
3827 assert_eq!(parse_style_letter_spacing(&ls.print_as_css_value()).unwrap(), ls);
3828 let ws = StyleWordSpacing { inner: pv };
3829 assert_eq!(parse_style_word_spacing(&ws.print_as_css_value()).unwrap(), ws);
3830 }
3831 let ts = StyleTabSize::default();
3833 assert_eq!(ts.inner, PixelValue::em(8.0));
3834 assert_eq!(parse_style_tab_size(&ts.print_as_css_value()).unwrap(), ts);
3835 assert_eq!(parse_style_tab_size("4").unwrap().inner, PixelValue::em(4.0));
3836 assert_eq!(parse_style_tab_size("20px").unwrap().inner, PixelValue::px(20.0));
3837 }
3838
3839 #[test]
3840 fn pixel_parsers_reject_empty_and_unit_only_input() {
3841 for bad in ["", " ", "\t\n", "px", "em", "abc", "px px", "10pxx", "\u{1F600}"] {
3842 assert!(parse_style_letter_spacing(bad).is_err(), "letter-spacing {bad:?}");
3843 assert!(parse_style_word_spacing(bad).is_err(), "word-spacing {bad:?}");
3844 }
3845 assert_eq!(parse_style_letter_spacing("10 px").unwrap().inner, PixelValue::px(10.0));
3848 }
3849
3850 #[test]
3851 fn pixel_parsers_accept_float_keywords_and_saturate_instead_of_panicking() {
3852 assert_eq!(parse_style_letter_spacing("NaN").unwrap().inner.number.number(), 0);
3856 assert_eq!(
3857 parse_style_letter_spacing("inf").unwrap().inner.number.number(),
3858 isize::MAX
3859 );
3860 assert_eq!(
3861 parse_style_letter_spacing("-inf").unwrap().inner.number.number(),
3862 isize::MIN
3863 );
3864 assert_eq!(
3865 parse_style_word_spacing("1e400px").unwrap().inner.number.number(),
3866 isize::MAX
3867 );
3868 assert_eq!(parse_style_tab_size("NaN").unwrap().inner, PixelValue::em(0.0));
3870 assert!(parse_style_tab_size("inf").unwrap().inner.number.get().is_finite());
3871
3872 assert_eq!(parse_style_letter_spacing("0").unwrap().inner, PixelValue::px(0.0));
3874 assert_eq!(parse_style_letter_spacing("-0").unwrap().inner.number.number(), 0);
3875 assert!(parse_style_letter_spacing("9223372036854775807px").unwrap().inner.number.get().is_finite());
3876 }
3877
3878 #[test]
3881 fn text_indent_round_trips_length_and_keywords() {
3882 for pv in [PixelValue::px(10.0), PixelValue::em(-2.0), PixelValue::percent(50.0)] {
3883 for (each_line, hanging) in [(false, false), (true, false), (false, true), (true, true)] {
3884 let ti = StyleTextIndent { inner: pv, each_line, hanging };
3885 let printed = ti.print_as_css_value();
3886 assert_eq!(parse_style_text_indent(&printed).unwrap(), ti, "{printed:?}");
3887 }
3888 }
3889 assert!(parse_style_text_indent("10px hanging").unwrap().hanging);
3890 assert!(parse_style_text_indent("each-line 10px").unwrap().each_line);
3891 }
3892
3893 #[test]
3894 fn text_indent_defaults_missing_length_to_zero_and_keeps_the_last_one() {
3895 assert_eq!(parse_style_text_indent("").unwrap(), StyleTextIndent::zero());
3899 assert_eq!(parse_style_text_indent(" ").unwrap(), StyleTextIndent::zero());
3900 assert_eq!(
3901 parse_style_text_indent("hanging").unwrap(),
3902 StyleTextIndent { hanging: true, ..StyleTextIndent::zero() }
3903 );
3904 assert_eq!(parse_style_text_indent("10px 20px").unwrap().inner, PixelValue::px(20.0));
3906
3907 assert!(parse_style_text_indent("garbage").is_err());
3909 assert!(parse_style_text_indent("hanging garbage").is_err());
3910 }
3911
3912 #[test]
3915 fn initial_letter_parses_size_and_optional_sink() {
3916 assert_eq!(
3917 parse_style_initial_letter("3").unwrap(),
3918 StyleInitialLetter { size: 3, sink: crate::corety::OptionU32::None }
3919 );
3920 let with_sink = StyleInitialLetter { size: 3, sink: crate::corety::OptionU32::Some(2) };
3921 assert_eq!(parse_style_initial_letter("3 2").unwrap(), with_sink);
3922 assert_eq!(parse_style_initial_letter(&with_sink.print_as_css_value()).unwrap(), with_sink);
3924 }
3925
3926 #[test]
3927 fn initial_letter_rejects_zero_negative_and_overflowing_sizes() {
3928 assert!(parse_style_initial_letter("0").is_err(), "size 0 must be rejected");
3929 assert!(parse_style_initial_letter("-1").is_err());
3930 assert!(parse_style_initial_letter("1.5").is_err());
3931 assert!(parse_style_initial_letter("4294967296").is_err(), "u32::MAX + 1");
3932 assert!(parse_style_initial_letter("3 -1").is_err(), "negative sink");
3933 assert!(parse_style_initial_letter("3 x").is_err());
3934 assert!(parse_style_initial_letter("").is_err());
3935 assert!(parse_style_initial_letter(" ").is_err());
3936 assert_eq!(parse_style_initial_letter("4294967295").unwrap().size, u32::MAX);
3938 assert_eq!(parse_style_initial_letter("3 2 9").unwrap(), StyleInitialLetter {
3940 size: 3,
3941 sink: crate::corety::OptionU32::Some(2),
3942 });
3943 }
3944
3945 #[test]
3948 fn line_clamp_rejects_zero_and_out_of_range_values() {
3949 assert_eq!(parse_style_line_clamp("3").unwrap(), StyleLineClamp { max_lines: 3 });
3950 assert_eq!(parse_style_line_clamp(" 7 ").unwrap().max_lines, 7);
3951 assert_eq!(
3952 parse_style_line_clamp("0").unwrap_err(),
3953 StyleLineClampParseError::ZeroValue
3954 );
3955 assert!(parse_style_line_clamp("-1").is_err());
3956 assert!(parse_style_line_clamp("1.0").is_err());
3957 assert!(parse_style_line_clamp("").is_err());
3958 assert!(parse_style_line_clamp(" ").is_err());
3959 assert!(parse_style_line_clamp("\u{1F600}").is_err());
3960 assert!(parse_style_line_clamp("99999999999999999999999").is_err());
3962 let max = usize::MAX.to_string();
3963 assert_eq!(parse_style_line_clamp(&max).unwrap().max_lines, usize::MAX);
3964 let lc = StyleLineClamp { max_lines: 42 };
3966 assert_eq!(parse_style_line_clamp(&lc.print_as_css_value()).unwrap(), lc);
3967 }
3968
3969 #[test]
3972 fn hanging_punctuation_round_trips_and_enforces_mutual_exclusion() {
3973 for bits in 0_u8..16 {
3974 let hp = StyleHangingPunctuation {
3975 first: bits & 1 != 0,
3976 force_end: bits & 2 != 0,
3977 allow_end: bits & 4 != 0,
3978 last: bits & 8 != 0,
3979 };
3980 let printed = hp.print_as_css_value();
3981 if hp.force_end && hp.allow_end {
3982 assert!(parse_style_hanging_punctuation(&printed).is_err(), "{printed:?}");
3984 } else {
3985 assert_eq!(parse_style_hanging_punctuation(&printed).unwrap(), hp, "{printed:?}");
3986 }
3987 }
3988 assert!(parse_style_hanging_punctuation("first bogus").is_err());
3989 assert!(parse_style_hanging_punctuation("\u{1F600}").is_err());
3990 assert!(parse_style_hanging_punctuation("none first").is_err());
3991 }
3992
3993 #[test]
3994 fn hanging_punctuation_accepts_empty_input_as_none() {
3995 assert_eq!(
3998 parse_style_hanging_punctuation("").unwrap(),
3999 StyleHangingPunctuation::default()
4000 );
4001 assert_eq!(
4002 parse_style_hanging_punctuation(" ").unwrap(),
4003 StyleHangingPunctuation::default()
4004 );
4005 assert!(parse_style_hanging_punctuation("first first").unwrap().first);
4007 }
4008
4009 #[test]
4012 fn text_combine_upright_bounds_the_digits_operand() {
4013 assert_eq!(parse_style_text_combine_upright("none").unwrap(), StyleTextCombineUpright::None);
4014 assert_eq!(parse_style_text_combine_upright("all").unwrap(), StyleTextCombineUpright::All);
4015 for n in 2_u8..=4 {
4016 let v = StyleTextCombineUpright::Digits(n);
4017 assert_eq!(parse_style_text_combine_upright(&v.print_as_css_value()).unwrap(), v);
4018 }
4019 for bad in ["digits 0", "digits 1", "digits 5", "digits 255", "digits 256", "digits -1"] {
4021 assert!(parse_style_text_combine_upright(bad).is_err(), "{bad:?} accepted");
4022 }
4023 assert!(parse_style_text_combine_upright("").is_err());
4024 assert!(parse_style_text_combine_upright("bogus").is_err());
4025 }
4026
4027 #[test]
4028 fn text_combine_upright_accepts_garbage_after_the_digits_prefix() {
4029 assert_eq!(
4033 parse_style_text_combine_upright("digits").unwrap(),
4034 StyleTextCombineUpright::Digits(2)
4035 );
4036 assert_eq!(
4037 parse_style_text_combine_upright("digitsgarbage").unwrap(),
4038 StyleTextCombineUpright::Digits(2)
4039 );
4040 assert_eq!(
4041 parse_style_text_combine_upright("digits 2 3").unwrap(),
4042 StyleTextCombineUpright::Digits(2)
4043 );
4044 }
4045
4046 #[test]
4049 fn line_height_parses_numbers_percentages_and_px() {
4050 assert_eq!(parse_style_line_height("1.5").unwrap().inner, PercentageValue::new(150.0));
4051 assert_eq!(parse_style_line_height("120%").unwrap().inner, PercentageValue::new(120.0));
4052 assert_eq!(parse_style_line_height("20px").unwrap().inner, PercentageValue::new(-2000.0));
4054 assert!(parse_style_line_height("").is_err());
4055 assert!(parse_style_line_height(" ").is_err());
4056 assert!(parse_style_line_height("abc").is_err());
4057 assert!(parse_style_line_height("\u{1F600}").is_err());
4058 let lh = StyleLineHeight::default();
4060 assert_eq!(parse_style_line_height(&lh.print_as_css_value()).unwrap(), lh);
4061 }
4062
4063 #[test]
4064 fn line_height_negative_numbers_alias_absolute_px_lengths() {
4065 assert_eq!(
4070 parse_style_line_height("-1").unwrap(),
4071 parse_style_line_height("1px").unwrap()
4072 );
4073 assert_eq!(
4074 parse_style_line_height("-100%").unwrap(),
4075 parse_style_line_height("1px").unwrap()
4076 );
4077 }
4078
4079 #[test]
4080 fn line_height_rejects_em_and_other_length_units() {
4081 assert!(parse_style_line_height("1.5em").is_err());
4084 assert!(parse_style_line_height("12pt").is_err());
4085 assert!(parse_style_line_height("2rem").is_err());
4086 }
4087
4088 #[test]
4089 fn line_height_rejects_non_ascii_numerals_without_panicking() {
4090 assert!(parse_style_line_height("\u{FF15}").is_err()); assert!(parse_style_line_height("\u{0665}").is_err()); assert!(parse_style_line_height("1\u{00B2}").is_err()); }
4098
4099 #[test]
4102 fn vertical_align_round_trips_keywords_percentages_and_lengths() {
4103 type VA = StyleVerticalAlign;
4104 for v in [
4105 VA::Baseline, VA::Top, VA::Middle, VA::Bottom, VA::Sub, VA::Superscript,
4106 VA::TextTop, VA::TextBottom,
4107 VA::Percentage(PercentageValue::new(50.0)),
4108 VA::Percentage(PercentageValue::new(-25.0)),
4109 VA::Length(PixelValue::px(12.0)),
4110 VA::Length(PixelValue::em(1.5)),
4111 ] {
4112 let printed = v.print_as_css_value();
4113 assert_eq!(parse_style_vertical_align(&printed).unwrap(), v, "{printed:?}");
4114 }
4115 assert!(parse_style_vertical_align("").is_err());
4116 assert!(parse_style_vertical_align("%").is_err());
4117 assert!(parse_style_vertical_align("bogus%").is_err());
4118 assert!(parse_style_vertical_align("\u{1F600}").is_err());
4119 }
4120
4121 #[test]
4124 fn caret_parsers_reject_garbage_and_accept_minimal_input() {
4125 assert_eq!(parse_caret_color("red").unwrap().inner, parse_style_text_color("red").unwrap().inner);
4126 assert!(parse_caret_color("").is_err());
4127 assert!(parse_caret_color("not-a-color").is_err());
4128 assert_eq!(parse_caret_width("2px").unwrap().inner, PixelValue::px(2.0));
4129 assert!(parse_caret_width("").is_err());
4130 assert!(parse_caret_animation_duration("bogus").is_err());
4131 assert!(parse_caret_animation_duration("500ms").is_ok());
4132 }
4133
4134 macro_rules! assert_error_round_trip {
4138 ($parse:ident, $($bad:expr),+ $(,)?) => {{
4139 $(
4140 let e = $parse($bad).expect_err(concat!(stringify!($parse), " accepted ", $bad));
4141 assert_eq!(e.to_contained().to_shared(), e, "{:?} via {}", $bad, stringify!($parse));
4142 )+
4143 }};
4144 }
4145
4146 #[test]
4147 fn invalid_value_errors_round_trip_through_their_owned_form() {
4148 assert_error_round_trip!(parse_style_text_align, "", "middle", "\u{1F600}");
4149 assert_error_round_trip!(parse_style_white_space, "", "wrap");
4150 assert_error_round_trip!(parse_style_hyphens, "", "always");
4151 assert_error_round_trip!(parse_style_line_break, "", "tight");
4152 assert_error_round_trip!(parse_style_word_break, "", "break");
4153 assert_error_round_trip!(parse_style_overflow_wrap, "", "wrap");
4154 assert_error_round_trip!(parse_style_text_align_last, "", "middle");
4155 assert_error_round_trip!(parse_style_text_transform, "", "smallcaps");
4156 assert_error_round_trip!(parse_style_direction, "", "sideways");
4157 assert_error_round_trip!(parse_style_user_select, "", "some");
4158 assert_error_round_trip!(parse_style_text_decoration, "", "blink");
4159 assert_error_round_trip!(parse_style_vertical_align, "", "bogus");
4160 assert_error_round_trip!(parse_style_unicode_bidi, "", "override");
4161 assert_error_round_trip!(parse_style_text_box_trim, "", "trim");
4162 assert_error_round_trip!(parse_style_text_box_edge, "", "edge");
4163 assert_error_round_trip!(parse_style_dominant_baseline, "", "bogus");
4164 assert_error_round_trip!(parse_style_alignment_baseline, "", "bogus");
4165 assert_error_round_trip!(parse_style_baseline_source, "", "bogus");
4166 assert_error_round_trip!(parse_style_line_fit_edge, "", "bogus");
4167 assert_error_round_trip!(parse_style_initial_letter_align, "", "bogus");
4168 assert_error_round_trip!(parse_style_initial_letter_wrap, "", "bogus");
4169 }
4170
4171 #[test]
4172 fn pixel_and_numeric_errors_round_trip_through_their_owned_form() {
4173 assert_error_round_trip!(parse_style_letter_spacing, "", "abcpx", "px", "zz");
4175 assert_error_round_trip!(parse_style_word_spacing, "", "abcem", "em", "zz");
4176 assert_error_round_trip!(parse_style_text_indent, "abcpx", "zz");
4177 assert_error_round_trip!(parse_style_tab_size, "", "abcpx", "zz");
4178 assert_error_round_trip!(parse_style_line_height, "", "abc", "1.5em");
4179 assert_error_round_trip!(parse_style_initial_letter, "", "x", "0", "3 x");
4180 assert_error_round_trip!(parse_style_line_clamp, "", "x", "0");
4181 assert_error_round_trip!(parse_style_hanging_punctuation, "bogus", "force-end allow-end");
4182 assert_error_round_trip!(parse_style_text_combine_upright, "bogus", "digits 9");
4183 }
4184
4185 #[test]
4186 fn text_color_error_round_trips_and_preserves_its_message() {
4187 let e = parse_style_text_color("not-a-color").unwrap_err();
4188 let owned = e.to_contained();
4189 let round_tripped = owned.to_shared();
4190 assert_eq!(format!("{e}"), format!("{round_tripped}"));
4191 assert!(parse_style_text_color("").is_err());
4192 assert!(parse_style_text_color("#gggggg").is_err());
4193 assert!(parse_style_text_color("\u{1F600}").is_err());
4194 assert_eq!(parse_style_text_color("#aabbcc").unwrap().inner.to_hash(), "#aabbccff");
4196 }
4197
4198 #[test]
4199 fn error_types_survive_a_default_ish_extreme_instance() {
4200 let long = "z".repeat(100_000);
4202 let e = parse_style_text_align(&long).unwrap_err();
4203 assert_eq!(e.to_contained().to_shared(), e);
4204 let e = parse_style_line_clamp(&long).unwrap_err();
4205 assert_eq!(e.to_contained().to_shared(), e);
4206 let e = parse_style_hanging_punctuation(&long).unwrap_err();
4207 assert_eq!(e.to_contained().to_shared(), e);
4208 let e = parse_style_letter_spacing("").unwrap_err();
4210 assert_eq!(e.to_contained().to_shared(), e);
4211 }
4212
4213 #[test]
4216 fn letter_spacing_accepts_every_size_metric_it_prints() {
4217 for (unit, metric) in [
4218 ("px", SizeMetric::Px),
4219 ("pt", SizeMetric::Pt),
4220 ("em", SizeMetric::Em),
4221 ("rem", SizeMetric::Rem),
4222 ("in", SizeMetric::In),
4223 ("cm", SizeMetric::Cm),
4224 ("mm", SizeMetric::Mm),
4225 ("%", SizeMetric::Percent),
4226 ("vw", SizeMetric::Vw),
4227 ("vh", SizeMetric::Vh),
4228 ("vmax", SizeMetric::Vmax),
4229 ("vmin", SizeMetric::Vmin),
4235 ] {
4236 let parsed = parse_style_letter_spacing(&format!("1{unit}")).unwrap();
4237 assert_eq!(parsed.inner.metric, metric, "unit {unit}");
4238 assert_eq!(parsed.inner.number.get(), 1.0);
4239 }
4240 }
4241 }
4242}