From 70a30d1580ff9e422ef2f257dce08b2ca52ffa6e Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Sun, 3 Mar 2024 15:51:33 +0000 Subject: [PATCH] support all descre media queries, add some webkit prefixes, and other stuff --- crates/hdx_ast/src/css/properties.rs | 16 +- crates/hdx_ast/src/css/rules/charset.rs | 4 +- .../src/css/rules/media/features/any_hover.rs | 30 ++++ .../css/rules/media/features/any_pointer.rs | 34 ++++ .../src/css/rules/media/features/anyhover.rs | 86 --------- .../css/rules/media/features/anypointer.rs | 99 ---------- .../css/rules/media/features/color_gamut.rs | 39 ++++ .../css/rules/media/features/colorgamut.rs | 4 - .../css/rules/media/features/display_mode.rs | 43 +++++ .../css/rules/media/features/dynamic_range.rs | 37 ++++ .../media/features/environment_blending.rs | 40 +++++ .../css/rules/media/features/forced_colors.rs | 37 ++++ .../src/css/rules/media/features/grid.rs | 16 +- .../features/horizontal_viewport_segments.rs | 0 .../src/css/rules/media/features/hover.rs | 79 ++------ .../rules/media/features/inverted_colors.rs | 37 ++++ .../src/css/rules/media/features/mod.rs | 96 ++++++---- .../css/rules/media/features/nav_controls.rs | 37 ++++ .../css/rules/media/features/orientation.rs | 37 +++- .../rules/media/features/overflow_block.rs | 40 ++++- .../rules/media/features/overflow_inline.rs | 37 +++- .../src/css/rules/media/features/pointer.rs | 95 ++-------- .../media/features/prefers_color_scheme.rs | 36 ++++ .../rules/media/features/prefers_contrast.rs | 42 +++++ .../media/features/prefers_reduced_data.rs | 36 ++++ .../media/features/prefers_reduced_motion.rs | 37 ++++ .../features/prefers_reduced_transparency.rs | 37 ++++ .../src/css/rules/media/features/scan.rs | 37 +++- .../src/css/rules/media/features/scripting.rs | 40 +++++ .../features/vertical_viewport_segments.rs | 0 .../rules/media/features/video_color_gamut.rs | 39 ++++ .../media/features/video_dynamic_range.rs | 36 ++++ crates/hdx_ast/src/css/rules/media/mod.rs | 170 ++++++++---------- crates/hdx_ast/src/css/rules/page.rs | 20 +-- crates/hdx_ast/src/css/rules/supports.rs | 18 +- crates/hdx_ast/src/css/selector/attribute.rs | 12 +- crates/hdx_ast/src/css/selector/mod.rs | 28 ++- .../hdx_ast/src/css/selector/pseudo_class.rs | 5 +- crates/hdx_ast/src/css/stylerule.rs | 6 +- crates/hdx_ast/src/css/stylesheet.rs | 8 +- .../css/values/animations/animation_delay.rs | 4 +- .../values/animations/animation_duration.rs | 4 +- .../values/animations/animation_fill_mode.rs | 6 +- .../animations/animation_iteration_count.rs | 6 +- .../values/backgrounds/border_top_style.rs | 5 +- crates/hdx_ast/src/css/values/box/margin.rs | 25 ++- .../hdx_ast/src/css/values/box/margin_trim.rs | 4 +- crates/hdx_ast/src/css/values/box/padding.rs | 25 ++- .../css/values/break/box_decoration_break.rs | 5 +- .../src/css/values/break/break_before.rs | 5 +- .../src/css/values/break/break_inside.rs | 5 +- .../src/css/values/break/margin_break.rs | 5 +- crates/hdx_ast/src/css/values/cascade/all.rs | 4 +- .../css/values/color_adjust/color_scheme.rs | 10 +- .../css/values/compositing/mix_blend_mode.rs | 5 +- .../hdx_ast/src/css/values/content/content.rs | 10 +- crates/hdx_ast/src/css/values/css2/z_index.rs | 5 +- .../hdx_ast/src/css/values/display/display.rs | 4 +- .../src/css/values/display/visibility.rs | 5 +- .../src/css/values/fonts/font_family.rs | 6 +- .../hdx_ast/src/css/values/fonts/font_size.rs | 5 +- .../src/css/values/fonts/font_weight.rs | 9 +- .../css/values/inline/alignment_baseline.rs | 5 +- .../src/css/values/inline/baseline_shift.rs | 11 +- .../src/css/values/inline/baseline_source.rs | 12 +- .../css/values/inline/dominant_baseline.rs | 5 +- .../src/css/values/inline/line_height.rs | 5 +- .../src/css/values/inline/vertical_align.rs | 4 +- .../css/values/lists/list_style_position.rs | 7 +- crates/hdx_ast/src/css/values/mod.rs | 27 ++- .../src/css/values/non_standard/mod.rs | 3 + .../src/css/values/non_standard/webkit.rs | 6 + .../src/css/values/non_standard/zoom.rs | 5 +- .../src/css/values/overflow/overflow_block.rs | 5 +- .../src/css/values/page_floats/clear.rs | 5 +- .../src/css/values/page_floats/float.rs | 9 +- .../src/css/values/page_floats/float_defer.rs | 5 +- .../css/values/page_floats/float_reference.rs | 5 +- .../hdx_ast/src/css/values/position/bottom.rs | 5 +- .../hdx_ast/src/css/values/position/left.rs | 5 +- .../src/css/values/position/position.rs | 5 +- .../hdx_ast/src/css/values/position/right.rs | 5 +- crates/hdx_ast/src/css/values/position/top.rs | 5 +- .../values/size_adjust/text_size_adjust.rs | 5 +- .../src/css/values/sizing/box_sizing.rs | 5 +- .../src/css/values/sizing/max_width.rs | 7 +- .../css/values/sizing/min_intrinsic_sizing.rs | 5 +- crates/hdx_ast/src/css/values/sizing/width.rs | 5 +- .../src/css/values/tables/border_collapse.rs | 5 +- .../src/css/values/tables/caption_side.rs | 5 +- .../src/css/values/tables/empty_cells.rs | 5 +- .../src/css/values/tables/table_layout.rs | 5 +- .../hdx_ast/src/css/values/text/text_align.rs | 5 +- .../src/css/values/text/text_align_all.rs | 5 +- .../src/css/values/text/text_align_last.rs | 5 +- .../hdx_ast/src/css/values/text/text_wrap.rs | 5 +- .../css/values/text/white_space_collapse.rs | 5 +- .../src/css/values/text/white_space_trim.rs | 4 +- .../values/text_decor/text_decoration_line.rs | 4 +- .../text_decor/text_decoration_skip_ink.rs | 5 +- .../text_decor/text_decoration_style.rs | 5 +- .../hdx_ast/src/css/values/ui/appearance.rs | 5 +- crates/hdx_ast/src/css/values/ui/cursor.rs | 5 +- .../src/css/values/ui/pointer_events.rs | 5 +- crates/hdx_ast/src/css/values/units/angles.rs | 5 +- crates/hdx_ast/src/css/values/units/custom.rs | 4 +- crates/hdx_ast/src/css/values/units/float.rs | 4 +- .../hdx_ast/src/css/values/units/frequency.rs | 4 +- crates/hdx_ast/src/css/values/units/length.rs | 8 +- .../hdx_ast/src/css/values/units/percent.rs | 5 +- .../src/css/values/units/resolution.rs | 5 +- crates/hdx_ast/src/css/values/units/time.rs | 4 +- .../css/values/writing_modes/writing_mode.rs | 5 +- crates/hdx_ast/src/macros.rs | 55 ++++++ crates/hdx_ast/src/syntax.rs | 20 +-- crates/hdx_parser/src/traits.rs | 7 +- 116 files changed, 1210 insertions(+), 877 deletions(-) create mode 100644 crates/hdx_ast/src/css/rules/media/features/any_hover.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/any_pointer.rs delete mode 100644 crates/hdx_ast/src/css/rules/media/features/anyhover.rs delete mode 100644 crates/hdx_ast/src/css/rules/media/features/anypointer.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/color_gamut.rs delete mode 100644 crates/hdx_ast/src/css/rules/media/features/colorgamut.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/display_mode.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/dynamic_range.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/environment_blending.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/forced_colors.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/horizontal_viewport_segments.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/inverted_colors.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/nav_controls.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/prefers_color_scheme.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/prefers_contrast.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/prefers_reduced_data.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/prefers_reduced_motion.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/prefers_reduced_transparency.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/scripting.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/vertical_viewport_segments.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/video_color_gamut.rs create mode 100644 crates/hdx_ast/src/css/rules/media/features/video_dynamic_range.rs create mode 100644 crates/hdx_ast/src/css/values/non_standard/webkit.rs diff --git a/crates/hdx_ast/src/css/properties.rs b/crates/hdx_ast/src/css/properties.rs index 48996288..8e99d13c 100644 --- a/crates/hdx_ast/src/css/properties.rs +++ b/crates/hdx_ast/src/css/properties.rs @@ -6,13 +6,11 @@ use hdx_parser::{ unexpected, unexpected_ident, Declaration, DeclarationValue, Parse, Parser, Result as ParserResult, State, }; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::{css::values, syntax::ComponentValues}; #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct Custom<'a>(pub ComponentValues<'a>); impl<'a> WriteCss<'a> for Custom<'a> { @@ -31,7 +29,7 @@ impl<'a> Parse<'a> for Custom<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct Computed<'a>(pub ComponentValues<'a>); impl<'a> WriteCss<'a> for Computed<'a> { @@ -50,7 +48,7 @@ impl<'a> Parse<'a> for Computed<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct Unknown<'a>(pub ComponentValues<'a>); impl<'a> Parse<'a> for Unknown<'a> { @@ -69,7 +67,7 @@ impl<'a> WriteCss<'a> for Unknown<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct Property<'a> { name: Atom, value: StyleValue<'a>, @@ -186,7 +184,7 @@ macro_rules! properties { $name: ident$(<$a: lifetime>)?: $atom: pat, )+ ) => { #[derive(PartialEq, Debug, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize), serde())] + #[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum StyleValue<'a> { Initial, Inherit, @@ -1328,6 +1326,10 @@ properties! { Zoom: atom!("zoom"), // Webkit NonStandards + WebkitAnimationDuration: atom!("-webkit-animation-duration"), + WebkitAnimationDelay: atom!("-webkit-animation-delay"), + WebkitAnimationFillMode: atom!("-webkit-animation-fill-mode"), + WebkitAnimationIterationCount: atom!("-webkit-animation-iteration-count"), // WebkitTextSizeAdjust: atom!("-webkit-text-size-adjust"), // WebkitTextDecoration: atom!("-webkit-text-decoration"), // WebkitTapHighlightColor: atom!("-webkit-tap-highlight-color"), diff --git a/crates/hdx_ast/src/css/rules/charset.rs b/crates/hdx_ast/src/css/rules/charset.rs index f741410c..f168d87b 100644 --- a/crates/hdx_ast/src/css/rules/charset.rs +++ b/crates/hdx_ast/src/css/rules/charset.rs @@ -6,11 +6,9 @@ use hdx_parser::{ expect, unexpected, Parse, Parser, Result as ParserResult, }; use hdx_writer::{CssWriter, OutputOption, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; #[derive(Atomizable, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub enum CharsetRule { #[atomizable("utf-8")] Utf8, diff --git a/crates/hdx_ast/src/css/rules/media/features/any_hover.rs b/crates/hdx_ast/src/css/rules/media/features/any_hover.rs new file mode 100644 index 00000000..6db5ebfb --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/any_hover.rs @@ -0,0 +1,30 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(AnyHoverMediaFeature[atom!("any-hover")] { + None: atom!("none"), + Hover: atom!("hover"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(AnyHoverMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(AnyHoverMediaFeature, "any-hover"); + assert_parse!(AnyHoverMediaFeature, "any-hover: hover"); + assert_parse!(AnyHoverMediaFeature, "any-hover: none"); + } + + #[test] + fn test_minify() { + assert_minify!(AnyHoverMediaFeature, "any-hover: hover", "any-hover:hover"); + assert_minify!(AnyHoverMediaFeature, "any-hover: none", "any-hover:none"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/any_pointer.rs b/crates/hdx_ast/src/css/rules/media/features/any_pointer.rs new file mode 100644 index 00000000..cce14237 --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/any_pointer.rs @@ -0,0 +1,34 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(AnyPointerMediaFeature[atom!("any-pointer")] { + None: atom!("none"), + Coarse: atom!("coarse"), + Fine: atom!("fine"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(AnyPointerMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(AnyPointerMediaFeature, "any-pointer"); + assert_parse!(AnyPointerMediaFeature, "any-pointer: none"); + assert_parse!(AnyPointerMediaFeature, "any-pointer: coarse"); + assert_parse!(AnyPointerMediaFeature, "any-pointer: fine"); + } + + #[test] + fn test_minify() { + assert_minify!(AnyPointerMediaFeature, "any-pointer", "any-pointer"); + assert_minify!(AnyPointerMediaFeature, "any-pointer: none", "any-pointer:none"); + assert_minify!(AnyPointerMediaFeature, "any-pointer: coarse", "any-pointer:coarse"); + assert_minify!(AnyPointerMediaFeature, "any-pointer: fine", "any-pointer:fine"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/anyhover.rs b/crates/hdx_ast/src/css/rules/media/features/anyhover.rs deleted file mode 100644 index 8dcaf844..00000000 --- a/crates/hdx_ast/src/css/rules/media/features/anyhover.rs +++ /dev/null @@ -1,86 +0,0 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - -use hdx_atom::atom; -use hdx_lexer::Token; -use hdx_parser::{unexpected, MediaFeature, Parse, Parser, Result as ParserResult, unexpected_ident}; -use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; - -#[derive(PartialEq, Default, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] -pub enum AnyHoverMediaFeature { - #[default] - Any, - None, - Hover, -} - -impl<'a> Parse<'a> for AnyHoverMediaFeature { - fn parse(parser: &mut Parser<'a>) -> ParserResult { - Self::parse_media_feature(atom!("any-hover"), parser) - } -} - -impl<'a> MediaFeature<'a> for AnyHoverMediaFeature { - fn parse_media_feature_value(parser: &mut Parser<'a>) -> ParserResult { - match parser.cur() { - Token::Ident(ident) => match ident.to_ascii_lowercase() { - atom!("none") => { - parser.advance(); - Ok(Self::None) - } - atom!("hover") => { - parser.advance(); - Ok(Self::Hover) - } - _ => unexpected_ident!(parser, ident), - } - token => unexpected!(parser, token), - } - } -} - -impl<'a> WriteCss<'a> for AnyHoverMediaFeature { - fn write_css(&self, sink: &mut W) -> WriterResult { - sink.write_char('(')?; - atom!("any-hover").write_css(sink)?; - match self { - Self::None => { - sink.write_char(':')?; - sink.write_whitespace()?; - atom!("none").write_css(sink)?; - }, - Self::Hover => { - sink.write_char(':')?; - sink.write_whitespace()?; - atom!("hover").write_css(sink)?; - } - Self::Any => {} - } - sink.write_char(')') - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::test_helpers::*; - - #[test] - fn size_test() { - assert_size!(AnyHoverMediaFeature, 1); - } - - #[test] - fn test_writes() { - assert_parse!(AnyHoverMediaFeature, "(any-hover)"); - assert_parse!(AnyHoverMediaFeature, "(any-hover: hover)"); - assert_parse!(AnyHoverMediaFeature, "(any-hover: none)"); - } - - #[test] - fn test_minify() { - assert_minify!(AnyHoverMediaFeature, "(any-hover: hover)", "(any-hover:hover)"); - assert_minify!(AnyHoverMediaFeature, "(any-hover: none)", "(any-hover:none)"); - } -} diff --git a/crates/hdx_ast/src/css/rules/media/features/anypointer.rs b/crates/hdx_ast/src/css/rules/media/features/anypointer.rs deleted file mode 100644 index 41cba6ca..00000000 --- a/crates/hdx_ast/src/css/rules/media/features/anypointer.rs +++ /dev/null @@ -1,99 +0,0 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - -use hdx_atom::atom; -use hdx_lexer::Token; -use hdx_parser::{unexpected, MediaFeature, Parse, Parser, Result as ParserResult, unexpected_ident}; -use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; - -#[derive(PartialEq, Default, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] -pub enum AnyPointerMediaFeature { - #[default] - Any, - None, - Coarse, - Fine, -} - -impl<'a> Parse<'a> for AnyPointerMediaFeature { - fn parse(parser: &mut Parser<'a>) -> ParserResult { - Self::parse_media_feature(atom!("any-pointer"), parser) - } -} - -impl<'a> MediaFeature<'a> for AnyPointerMediaFeature { - fn parse_media_feature_value(parser: &mut Parser<'a>) -> ParserResult { - match parser.cur() { - Token::Ident(ident) => match ident.to_ascii_lowercase() { - atom!("none") => { - parser.advance(); - Ok(Self::None) - } - atom!("coarse") => { - parser.advance(); - Ok(Self::Coarse) - } - atom!("fine") => { - parser.advance(); - Ok(Self::Fine) - } - _ => unexpected_ident!(parser, ident), - } - token => unexpected!(parser, token), - } - } -} - -impl<'a> WriteCss<'a> for AnyPointerMediaFeature { - fn write_css(&self, sink: &mut W) -> WriterResult { - sink.write_char('(')?; - atom!("any-pointer").write_css(sink)?; - match self { - Self::None => { - sink.write_char(':')?; - sink.write_whitespace()?; - atom!("none").write_css(sink)?; - }, - Self::Coarse => { - sink.write_char(':')?; - sink.write_whitespace()?; - atom!("coarse").write_css(sink)?; - } - Self::Fine => { - sink.write_char(':')?; - sink.write_whitespace()?; - atom!("fine").write_css(sink)?; - } - Self::Any => {} - } - sink.write_char(')') - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::test_helpers::*; - - #[test] - fn size_test() { - assert_size!(AnyPointerMediaFeature, 1); - } - - #[test] - fn test_writes() { - assert_parse!(AnyPointerMediaFeature, "(any-pointer)"); - assert_parse!(AnyPointerMediaFeature, "(any-pointer: none)"); - assert_parse!(AnyPointerMediaFeature, "(any-pointer: coarse)"); - assert_parse!(AnyPointerMediaFeature, "(any-pointer: fine)"); - } - - #[test] - fn test_minify() { - assert_minify!(AnyPointerMediaFeature, "(any-pointer)", "(any-pointer)"); - assert_minify!(AnyPointerMediaFeature, "(any-pointer: none)", "(any-pointer:none)"); - assert_minify!(AnyPointerMediaFeature, "(any-pointer: coarse)", "(any-pointer:coarse)"); - assert_minify!(AnyPointerMediaFeature, "(any-pointer: fine)", "(any-pointer:fine)"); - } -} diff --git a/crates/hdx_ast/src/css/rules/media/features/color_gamut.rs b/crates/hdx_ast/src/css/rules/media/features/color_gamut.rs new file mode 100644 index 00000000..17d8091d --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/color_gamut.rs @@ -0,0 +1,39 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(ColorGamutMediaFeature[atom!("color-gamut")] { + Srgb: atom!("srgb"), + P3: atom!("p3"), + Rec2020: atom!("rec2020"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(ColorGamutMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(ColorGamutMediaFeature, "color-gamut"); + assert_parse!(ColorGamutMediaFeature, "color-gamut: srgb"); + assert_parse!(ColorGamutMediaFeature, "color-gamut: p3"); + assert_parse!(ColorGamutMediaFeature, "color-gamut: rec2020"); + } + + #[test] + fn test_minify() { + assert_minify!(ColorGamutMediaFeature, "color-gamut: srgb", "color-gamut:srgb"); + assert_minify!(ColorGamutMediaFeature, "color-gamut: p3", "color-gamut:p3"); + assert_minify!(ColorGamutMediaFeature, "color-gamut: rec2020", "color-gamut:rec2020"); + } + + #[test] + fn test_errors() { + assert_parse_error!(ColorGamutMediaFeature, "color-gamut:"); + assert_parse_error!(ColorGamutMediaFeature, "color-gamut: pointer"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/colorgamut.rs b/crates/hdx_ast/src/css/rules/media/features/colorgamut.rs deleted file mode 100644 index 32149e8f..00000000 --- a/crates/hdx_ast/src/css/rules/media/features/colorgamut.rs +++ /dev/null @@ -1,4 +0,0 @@ -use crate::css::values::Todo; - - -pub type ColorGamutMediaFeature = Todo; diff --git a/crates/hdx_ast/src/css/rules/media/features/display_mode.rs b/crates/hdx_ast/src/css/rules/media/features/display_mode.rs new file mode 100644 index 00000000..6dc94ea3 --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/display_mode.rs @@ -0,0 +1,43 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(DisplayModeMediaFeature[atom!("display-mode")] { + Fullscreen: atom!("fullscreen"), + Standalone: atom!("standalone"), + MinimalUi: atom!("minimal-ui"), + Browser: atom!("browser"), + PictureInPicture: atom!("picture-in-picture"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(DisplayModeMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(DisplayModeMediaFeature, "display-mode"); + assert_parse!(DisplayModeMediaFeature, "display-mode: fullscreen"); + assert_parse!(DisplayModeMediaFeature, "display-mode: minimal-ui"); + } + + #[test] + fn test_minify() { + assert_minify!(DisplayModeMediaFeature, "display-mode: fullscreen", "display-mode:fullscreen"); + assert_minify!(DisplayModeMediaFeature, "display-mode: standalone", "display-mode:standalone"); + assert_minify!(DisplayModeMediaFeature, "display-mode: minimal-ui", "display-mode:minimal-ui"); + assert_minify!(DisplayModeMediaFeature, "display-mode: browser", "display-mode:browser"); + assert_minify!(DisplayModeMediaFeature, "display-mode: picture-in-picture", "display-mode:picture-in-picture"); + } + + #[test] + fn test_errors() { + assert_parse_error!(DisplayModeMediaFeature, "display-mode:"); + assert_parse_error!(DisplayModeMediaFeature, "display-mode: pointer"); + assert_parse_error!(DisplayModeMediaFeature, "pointer: standalone"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/dynamic_range.rs b/crates/hdx_ast/src/css/rules/media/features/dynamic_range.rs new file mode 100644 index 00000000..f4b746c9 --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/dynamic_range.rs @@ -0,0 +1,37 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(DynamicRangeMediaFeature[atom!("dynamic-range")] { + Standard: atom!("standard"), + High: atom!("high"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(DynamicRangeMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(DynamicRangeMediaFeature, "dynamic-range"); + assert_parse!(DynamicRangeMediaFeature, "dynamic-range: standard"); + assert_parse!(DynamicRangeMediaFeature, "dynamic-range: high"); + } + + #[test] + fn test_minify() { + assert_minify!(DynamicRangeMediaFeature, "dynamic-range: standard", "dynamic-range:standard"); + assert_minify!(DynamicRangeMediaFeature, "dynamic-range: high", "dynamic-range:high"); + } + + #[test] + fn test_errors() { + assert_parse_error!(DynamicRangeMediaFeature, "dynamic-range:"); + assert_parse_error!(DynamicRangeMediaFeature, "dynamic-range: pointer"); + assert_parse_error!(DynamicRangeMediaFeature, "pointer: standard"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/environment_blending.rs b/crates/hdx_ast/src/css/rules/media/features/environment_blending.rs new file mode 100644 index 00000000..989b016a --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/environment_blending.rs @@ -0,0 +1,40 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(EnvironmentBlendingMediaFeature[atom!("environment-blending")] { + Opaque: atom!("opaque"), + Additive: atom!("additive"), + Subtractive: atom!("subtractive"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(EnvironmentBlendingMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(EnvironmentBlendingMediaFeature, "environment-blending"); + assert_parse!(EnvironmentBlendingMediaFeature, "environment-blending: opaque"); + assert_parse!(EnvironmentBlendingMediaFeature, "environment-blending: additive"); + assert_parse!(EnvironmentBlendingMediaFeature, "environment-blending: subtractive"); + } + + #[test] + fn test_minify() { + assert_minify!(EnvironmentBlendingMediaFeature, "environment-blending: opaque", "environment-blending:opaque"); + assert_minify!(EnvironmentBlendingMediaFeature, "environment-blending: additive", "environment-blending:additive"); + assert_minify!(EnvironmentBlendingMediaFeature, "environment-blending: subtractive", "environment-blending:subtractive"); + } + + #[test] + fn test_errors() { + assert_parse_error!(EnvironmentBlendingMediaFeature, "environment-blending:"); + assert_parse_error!(EnvironmentBlendingMediaFeature, "environment-blending: pointer"); + assert_parse_error!(EnvironmentBlendingMediaFeature, "pointer: subtractive"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/forced_colors.rs b/crates/hdx_ast/src/css/rules/media/features/forced_colors.rs new file mode 100644 index 00000000..77909a04 --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/forced_colors.rs @@ -0,0 +1,37 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(ForcedColorsMediaFeature[atom!("forced-colors")] { + None: atom!("none"), + Active: atom!("active"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(ForcedColorsMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(ForcedColorsMediaFeature, "forced-colors"); + assert_parse!(ForcedColorsMediaFeature, "forced-colors: none"); + assert_parse!(ForcedColorsMediaFeature, "forced-colors: active"); + } + + #[test] + fn test_minify() { + assert_minify!(ForcedColorsMediaFeature, "forced-colors: none", "forced-colors:none"); + assert_minify!(ForcedColorsMediaFeature, "forced-colors: active", "forced-colors:active"); + } + + #[test] + fn test_errors() { + assert_parse_error!(ForcedColorsMediaFeature, "forced-colors:"); + assert_parse_error!(ForcedColorsMediaFeature, "forced-colors: pointer"); + assert_parse_error!(ForcedColorsMediaFeature, "pointer: none"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/grid.rs b/crates/hdx_ast/src/css/rules/media/features/grid.rs index b7aba00f..ebd8df6c 100644 --- a/crates/hdx_ast/src/css/rules/media/features/grid.rs +++ b/crates/hdx_ast/src/css/rules/media/features/grid.rs @@ -1,13 +1,10 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use hdx_atom::atom; use hdx_lexer::Token; use hdx_parser::{unexpected, MediaFeature, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; #[derive(PartialEq, Default, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub enum GridMediaFeature { #[default] Zero, @@ -41,14 +38,13 @@ impl<'a> MediaFeature<'a> for GridMediaFeature { impl<'a> WriteCss<'a> for GridMediaFeature { fn write_css(&self, sink: &mut W) -> WriterResult { - sink.write_char('(')?; atom!("grid").write_css(sink)?; if matches!(self, Self::One) { sink.write_char(':')?; sink.write_whitespace()?; sink.write_char('1')?; } - sink.write_char(')') + Ok(()) } } @@ -64,13 +60,13 @@ mod tests { #[test] fn test_writes() { - assert_parse!(GridMediaFeature, "(grid: 1)"); - assert_parse!(GridMediaFeature, "(grid)"); + assert_parse!(GridMediaFeature, "grid: 1"); + assert_parse!(GridMediaFeature, "grid"); } #[test] fn test_minify() { - assert_minify!(GridMediaFeature, "(grid: 1)", "(grid:1)"); - assert_minify!(GridMediaFeature, "(grid: 0)", "(grid)"); + assert_minify!(GridMediaFeature, "grid: 1", "grid:1"); + assert_minify!(GridMediaFeature, "grid: 0", "grid"); } } diff --git a/crates/hdx_ast/src/css/rules/media/features/horizontal_viewport_segments.rs b/crates/hdx_ast/src/css/rules/media/features/horizontal_viewport_segments.rs new file mode 100644 index 00000000..e69de29b diff --git a/crates/hdx_ast/src/css/rules/media/features/hover.rs b/crates/hdx_ast/src/css/rules/media/features/hover.rs index 4375f90a..297fbb59 100644 --- a/crates/hdx_ast/src/css/rules/media/features/hover.rs +++ b/crates/hdx_ast/src/css/rules/media/features/hover.rs @@ -1,65 +1,10 @@ #[cfg(feature = "serde")] -use serde::Serialize; +use crate::macros::discrete_media_feature; -use hdx_atom::atom; -use hdx_lexer::Token; -use hdx_parser::{unexpected, unexpected_ident, MediaFeature, Parse, Parser, Result as ParserResult}; -use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; - -#[derive(PartialEq, Default, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] -pub enum HoverMediaFeature { - #[default] - Any, - None, - Hover, -} - -impl<'a> Parse<'a> for HoverMediaFeature { - fn parse(parser: &mut Parser<'a>) -> ParserResult { - Self::parse_media_feature(atom!("hover"), parser) - } -} - -impl<'a> MediaFeature<'a> for HoverMediaFeature { - fn parse_media_feature_value(parser: &mut Parser<'a>) -> ParserResult { - match parser.cur() { - Token::Ident(ident) => match ident.to_ascii_lowercase() { - atom!("none") => { - parser.advance(); - Ok(Self::None) - } - atom!("hover") => { - parser.advance(); - Ok(Self::Hover) - } - _ => unexpected_ident!(parser, ident), - }, - token => unexpected!(parser, token), - } - } -} - -impl<'a> WriteCss<'a> for HoverMediaFeature { - fn write_css(&self, sink: &mut W) -> WriterResult { - sink.write_char('(')?; - atom!("hover").write_css(sink)?; - match self { - Self::None => { - sink.write_char(':')?; - sink.write_whitespace()?; - atom!("none").write_css(sink)?; - } - Self::Hover => { - sink.write_char(':')?; - sink.write_whitespace()?; - atom!("hover").write_css(sink)?; - } - Self::Any => {} - } - sink.write_char(')') - } -} +discrete_media_feature!(HoverMediaFeature[atom!("hover")] { + None: atom!("none"), + Hover: atom!("hover"), +}); #[cfg(test)] mod tests { @@ -73,20 +18,20 @@ mod tests { #[test] fn test_writes() { - assert_parse!(HoverMediaFeature, "(hover)"); - assert_parse!(HoverMediaFeature, "(hover: hover)"); - assert_parse!(HoverMediaFeature, "(hover: none)"); + assert_parse!(HoverMediaFeature, "hover"); + assert_parse!(HoverMediaFeature, "hover: hover"); + assert_parse!(HoverMediaFeature, "hover: none"); } #[test] fn test_minify() { - assert_minify!(HoverMediaFeature, "(hover: hover)", "(hover:hover)"); - assert_minify!(HoverMediaFeature, "(hover: none)", "(hover:none)"); + assert_minify!(HoverMediaFeature, "hover: hover", "hover:hover"); + assert_minify!(HoverMediaFeature, "hover: none", "hover:none"); } #[test] fn test_errors() { - assert_parse_error!(HoverMediaFeature, "(hover:)"); - assert_parse_error!(HoverMediaFeature, "(hover: hoover)"); + assert_parse_error!(HoverMediaFeature, "hover:"); + assert_parse_error!(HoverMediaFeature, "hover: hoover"); } } diff --git a/crates/hdx_ast/src/css/rules/media/features/inverted_colors.rs b/crates/hdx_ast/src/css/rules/media/features/inverted_colors.rs new file mode 100644 index 00000000..b104b7fa --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/inverted_colors.rs @@ -0,0 +1,37 @@ +#[cfg(feature = "serde")] +use crate::macros::discrete_media_feature; + +discrete_media_feature!(InvertedColorsMediaFeature[atom!("inverted-colors")] { + None: atom!("none"), + Inverted: atom!("inverted"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(InvertedColorsMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(InvertedColorsMediaFeature, "inverted-colors"); + assert_parse!(InvertedColorsMediaFeature, "inverted-colors: inverted"); + assert_parse!(InvertedColorsMediaFeature, "inverted-colors: none"); + } + + #[test] + fn test_minify() { + assert_minify!(InvertedColorsMediaFeature, "inverted-colors: inverted", "inverted-colors:inverted"); + assert_minify!(InvertedColorsMediaFeature, "inverted-colors: none", "inverted-colors:none"); + } + + #[test] + fn test_errors() { + assert_parse_error!(InvertedColorsMediaFeature, "inverted-colors:"); + assert_parse_error!(InvertedColorsMediaFeature, "inverted-colors: invited"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/mod.rs b/crates/hdx_ast/src/css/rules/media/features/mod.rs index 9d6abbc7..448c3be8 100644 --- a/crates/hdx_ast/src/css/rules/media/features/mod.rs +++ b/crates/hdx_ast/src/css/rules/media/features/mod.rs @@ -1,43 +1,75 @@ -mod height; -mod width; +mod any_hover; +mod any_pointer; mod aspect_ratio; -mod orientation; -mod resolution; -mod scan; -mod grid; -mod update; -mod overflow_block; -mod overflow_inline; mod color; +mod color_gamut; mod color_index; +mod device_aspect_ratio; +mod device_height; +mod device_width; +mod display_mode; +mod dynamic_range; +mod environment_blending; +mod forced_colors; +mod grid; +mod height; +mod horizontal_viewport_segments; +mod hover; +mod inverted_colors; mod monochrome; -mod colorgamut; +mod nav_controls; +mod orientation; +mod overflow_block; +mod overflow_inline; mod pointer; -mod hover; -mod anypointer; -mod anyhover; -mod device_width; -mod device_height; -mod device_aspect_ratio; +mod prefers_color_scheme; +mod prefers_contrast; +mod prefers_reduced_data; +mod prefers_reduced_motion; +mod prefers_reduced_transparency; +mod resolution; +mod scan; +mod scripting; +mod update; +mod vertical_viewport_segments; +mod video_color_gamut; +mod video_dynamic_range; +mod width; -pub use height::*; -pub use width::*; +pub use any_hover::*; +pub use any_pointer::*; pub use aspect_ratio::*; -pub use orientation::*; -pub use resolution::*; -pub use scan::*; -pub use grid::*; -pub use update::*; -pub use overflow_block::*; -pub use overflow_inline::*; pub use color::*; +pub use color_gamut::*; pub use color_index::*; +pub use device_aspect_ratio::*; +pub use device_height::*; +pub use device_width::*; +pub use display_mode::*; +pub use dynamic_range::*; +pub use environment_blending::*; +pub use forced_colors::*; +pub use grid::*; +pub use height::*; +pub use horizontal_viewport_segments::*; +pub use hover::*; +pub use inverted_colors::*; pub use monochrome::*; -pub use colorgamut::*; +pub use nav_controls::*; +pub use orientation::*; +pub use overflow_block::*; +pub use overflow_inline::*; pub use pointer::*; -pub use hover::*; -pub use anypointer::*; -pub use anyhover::*; -pub use device_width::*; -pub use device_height::*; -pub use device_aspect_ratio::*; +pub use prefers_color_scheme::*; +pub use prefers_contrast::*; +pub use prefers_reduced_data::*; +pub use prefers_reduced_motion::*; +pub use prefers_reduced_transparency::*; +pub use resolution::*; +pub use scan::*; +pub use scripting::*; +pub use update::*; +pub use vertical_viewport_segments::*; +pub use video_color_gamut::*; +pub use video_dynamic_range::*; +pub use width::*; diff --git a/crates/hdx_ast/src/css/rules/media/features/nav_controls.rs b/crates/hdx_ast/src/css/rules/media/features/nav_controls.rs new file mode 100644 index 00000000..440534a6 --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/nav_controls.rs @@ -0,0 +1,37 @@ +#[cfg(feature = "serde")] +use crate::macros::discrete_media_feature; + +discrete_media_feature!(NavControlsMediaFeature[atom!("nav-controls")] { + None: atom!("none"), + Back: atom!("back"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(NavControlsMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(NavControlsMediaFeature, "nav-controls"); + assert_parse!(NavControlsMediaFeature, "nav-controls: back"); + assert_parse!(NavControlsMediaFeature, "nav-controls: none"); + } + + #[test] + fn test_minify() { + assert_minify!(NavControlsMediaFeature, "nav-controls: back", "nav-controls:back"); + assert_minify!(NavControlsMediaFeature, "nav-controls: none", "nav-controls:none"); + } + + #[test] + fn test_errors() { + assert_parse_error!(NavControlsMediaFeature, "nav-controls:"); + assert_parse_error!(NavControlsMediaFeature, "nav-controls: hoover"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/orientation.rs b/crates/hdx_ast/src/css/rules/media/features/orientation.rs index 7ee353b7..15998b94 100644 --- a/crates/hdx_ast/src/css/rules/media/features/orientation.rs +++ b/crates/hdx_ast/src/css/rules/media/features/orientation.rs @@ -1,4 +1,37 @@ -use crate::css::values::Todo; +#[cfg(feature = "serde")] +use crate::macros::discrete_media_feature; +discrete_media_feature!(OrientationMediaFeature[atom!("orientation")] { + Portrait: atom!("portrait"), + Landscape: atom!("landscape"), +}); -pub type OrientationMediaFeature = Todo; +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(OrientationMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(OrientationMediaFeature, "orientation"); + assert_parse!(OrientationMediaFeature, "orientation: portrait"); + assert_parse!(OrientationMediaFeature, "orientation: landscape"); + } + + #[test] + fn test_minify() { + assert_minify!(OrientationMediaFeature, "orientation: portrait", "orientation:portrait"); + assert_minify!(OrientationMediaFeature, "orientation: landscape", "orientation:landscape"); + } + + #[test] + fn test_errors() { + assert_parse_error!(OrientationMediaFeature, "orientation:"); + assert_parse_error!(OrientationMediaFeature, "orientation: landscope"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/overflow_block.rs b/crates/hdx_ast/src/css/rules/media/features/overflow_block.rs index 0f84b6af..dbd7c2a3 100644 --- a/crates/hdx_ast/src/css/rules/media/features/overflow_block.rs +++ b/crates/hdx_ast/src/css/rules/media/features/overflow_block.rs @@ -1,4 +1,40 @@ -use crate::css::values::Todo; +#[cfg(feature = "serde")] +use crate::macros::discrete_media_feature; +discrete_media_feature!(OverflowBlockMediaFeature[atom!("overflow-block")] { + None: atom!("none"), + Scroll: atom!("scroll"), + Paged: atom!("paged"), +}); -pub type OverflowBlockMediaFeature = Todo; +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(OverflowBlockMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(OverflowBlockMediaFeature, "overflow-block"); + assert_parse!(OverflowBlockMediaFeature, "overflow-block: none"); + assert_parse!(OverflowBlockMediaFeature, "overflow-block: scroll"); + assert_parse!(OverflowBlockMediaFeature, "overflow-block: paged"); + } + + #[test] + fn test_minify() { + assert_minify!(OverflowBlockMediaFeature, "overflow-block: none", "overflow-block:none"); + assert_minify!(OverflowBlockMediaFeature, "overflow-block: scroll", "overflow-block:scroll"); + assert_minify!(OverflowBlockMediaFeature, "overflow-block: paged", "overflow-block:paged"); + } + + #[test] + fn test_errors() { + assert_parse_error!(OverflowBlockMediaFeature, "overflow-block:"); + assert_parse_error!(OverflowBlockMediaFeature, "overflow-block: page"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/overflow_inline.rs b/crates/hdx_ast/src/css/rules/media/features/overflow_inline.rs index dbe2056d..45fcc29f 100644 --- a/crates/hdx_ast/src/css/rules/media/features/overflow_inline.rs +++ b/crates/hdx_ast/src/css/rules/media/features/overflow_inline.rs @@ -1,4 +1,37 @@ -use crate::css::values::Todo; +#[cfg(feature = "serde")] +use crate::macros::discrete_media_feature; +discrete_media_feature!(OverflowInlineMediaFeature[atom!("overflow-inline")] { + None: atom!("none"), + Scroll: atom!("scroll"), +}); -pub type OverflowInlineMediaFeature = Todo; +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(OverflowInlineMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(OverflowInlineMediaFeature, "overflow-inline"); + assert_parse!(OverflowInlineMediaFeature, "overflow-inline: none"); + assert_parse!(OverflowInlineMediaFeature, "overflow-inline: scroll"); + } + + #[test] + fn test_minify() { + assert_minify!(OverflowInlineMediaFeature, "overflow-inline: none", "overflow-inline:none"); + assert_minify!(OverflowInlineMediaFeature, "overflow-inline: scroll", "overflow-inline:scroll"); + } + + #[test] + fn test_errors() { + assert_parse_error!(OverflowInlineMediaFeature, "overflow-inline:"); + assert_parse_error!(OverflowInlineMediaFeature, "overflow-inline: page"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/pointer.rs b/crates/hdx_ast/src/css/rules/media/features/pointer.rs index 8127c708..a209bbca 100644 --- a/crates/hdx_ast/src/css/rules/media/features/pointer.rs +++ b/crates/hdx_ast/src/css/rules/media/features/pointer.rs @@ -1,75 +1,10 @@ -#[cfg(feature = "serde")] -use serde::Serialize; +use crate::macros::discrete_media_feature; -use hdx_atom::atom; -use hdx_lexer::Token; -use hdx_parser::{unexpected, unexpected_ident, MediaFeature, Parse, Parser, Result as ParserResult}; -use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; - -#[derive(PartialEq, Default, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] -pub enum PointerMediaFeature { - #[default] - Any, - None, - Coarse, - Fine, -} - -impl<'a> Parse<'a> for PointerMediaFeature { - fn parse(parser: &mut Parser<'a>) -> ParserResult { - Self::parse_media_feature(atom!("pointer"), parser) - } -} - -impl<'a> MediaFeature<'a> for PointerMediaFeature { - fn parse_media_feature_value(parser: &mut Parser<'a>) -> ParserResult { - match parser.cur() { - Token::Ident(ident) => match ident.to_ascii_lowercase() { - atom!("none") => { - parser.advance(); - Ok(Self::None) - } - atom!("coarse") => { - parser.advance(); - Ok(Self::Coarse) - } - atom!("fine") => { - parser.advance(); - Ok(Self::Fine) - } - _ => unexpected_ident!(parser, ident), - }, - token => unexpected!(parser, token), - } - } -} - -impl<'a> WriteCss<'a> for PointerMediaFeature { - fn write_css(&self, sink: &mut W) -> WriterResult { - sink.write_char('(')?; - atom!("pointer").write_css(sink)?; - match self { - Self::None => { - sink.write_char(':')?; - sink.write_whitespace()?; - atom!("none").write_css(sink)?; - } - Self::Coarse => { - sink.write_char(':')?; - sink.write_whitespace()?; - atom!("coarse").write_css(sink)?; - } - Self::Fine => { - sink.write_char(':')?; - sink.write_whitespace()?; - atom!("fine").write_css(sink)?; - } - Self::Any => {} - } - sink.write_char(')') - } -} +discrete_media_feature!(PointerMediaFeature[atom!("pointer")] { + None: atom!("none"), + Coarse: atom!("coarse"), + Fine: atom!("fine"), +}); #[cfg(test)] mod tests { @@ -83,22 +18,22 @@ mod tests { #[test] fn test_writes() { - assert_parse!(PointerMediaFeature, "(pointer)"); - assert_parse!(PointerMediaFeature, "(pointer: none)"); - assert_parse!(PointerMediaFeature, "(pointer: coarse)"); - assert_parse!(PointerMediaFeature, "(pointer: fine)"); + assert_parse!(PointerMediaFeature, "pointer"); + assert_parse!(PointerMediaFeature, "pointer: none"); + assert_parse!(PointerMediaFeature, "pointer: coarse"); + assert_parse!(PointerMediaFeature, "pointer: fine"); } #[test] fn test_minify() { - assert_minify!(PointerMediaFeature, "(pointer: none)", "(pointer:none)"); - assert_minify!(PointerMediaFeature, "(pointer: coarse)", "(pointer:coarse)"); - assert_minify!(PointerMediaFeature, "(pointer: fine)", "(pointer:fine)"); + assert_minify!(PointerMediaFeature, "pointer: none", "pointer:none"); + assert_minify!(PointerMediaFeature, "pointer: coarse", "pointer:coarse"); + assert_minify!(PointerMediaFeature, "pointer: fine", "pointer:fine"); } #[test] fn test_errors() { - assert_parse_error!(PointerMediaFeature, "(pointer:)"); - assert_parse_error!(PointerMediaFeature, "(pointer: pointer)"); + assert_parse_error!(PointerMediaFeature, "pointer:"); + assert_parse_error!(PointerMediaFeature, "pointer: pointer"); } } diff --git a/crates/hdx_ast/src/css/rules/media/features/prefers_color_scheme.rs b/crates/hdx_ast/src/css/rules/media/features/prefers_color_scheme.rs new file mode 100644 index 00000000..7da55f1e --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/prefers_color_scheme.rs @@ -0,0 +1,36 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(PrefersColorSchemeMediaFeature[atom!("prefers-color-scheme")] { + Light: atom!("light"), + Dark: atom!("dark"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(PrefersColorSchemeMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(PrefersColorSchemeMediaFeature, "prefers-color-scheme"); + assert_parse!(PrefersColorSchemeMediaFeature, "prefers-color-scheme: light"); + assert_parse!(PrefersColorSchemeMediaFeature, "prefers-color-scheme: dark"); + } + + #[test] + fn test_minify() { + assert_minify!(PrefersColorSchemeMediaFeature, "prefers-color-scheme: light", "prefers-color-scheme:light"); + assert_minify!(PrefersColorSchemeMediaFeature, "prefers-color-scheme: dark", "prefers-color-scheme:dark"); + } + + #[test] + fn test_errors() { + assert_parse_error!(PrefersColorSchemeMediaFeature, "prefers-color-scheme:"); + assert_parse_error!(PrefersColorSchemeMediaFeature, "prefers-color-scheme: dimmed"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/prefers_contrast.rs b/crates/hdx_ast/src/css/rules/media/features/prefers_contrast.rs new file mode 100644 index 00000000..bd79c51c --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/prefers_contrast.rs @@ -0,0 +1,42 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(PrefersContrastMediaFeature[atom!("prefers-contrast")] { + NoPreference: atom!("no-preference"), + Less: atom!("less"), + More: atom!("more"), + Custom: atom!("custom"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(PrefersContrastMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(PrefersContrastMediaFeature, "prefers-contrast"); + assert_parse!(PrefersContrastMediaFeature, "prefers-contrast: no-preference"); + assert_parse!(PrefersContrastMediaFeature, "prefers-contrast: less"); + assert_parse!(PrefersContrastMediaFeature, "prefers-contrast: more"); + assert_parse!(PrefersContrastMediaFeature, "prefers-contrast: custom"); + } + + #[test] + fn test_minify() { + assert_minify!(PrefersContrastMediaFeature, "prefers-contrast: no-preference", "prefers-contrast:no-preference"); + assert_minify!(PrefersContrastMediaFeature, "prefers-contrast: less", "prefers-contrast:less"); + assert_minify!(PrefersContrastMediaFeature, "prefers-contrast: more", "prefers-contrast:more"); + assert_minify!(PrefersContrastMediaFeature, "prefers-contrast: custom", "prefers-contrast:custom"); + } + + #[test] + fn test_errors() { + assert_parse_error!(PrefersContrastMediaFeature, "prefers-contrast:"); + assert_parse_error!(PrefersContrastMediaFeature, "prefers-contrast: no-pref"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/prefers_reduced_data.rs b/crates/hdx_ast/src/css/rules/media/features/prefers_reduced_data.rs new file mode 100644 index 00000000..6bfa3d10 --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/prefers_reduced_data.rs @@ -0,0 +1,36 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(PrefersReducedDataMediaFeature[atom!("prefers-reduced-data")] { + NoPreference: atom!("no-preference"), + Reduce: atom!("reduce"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(PrefersReducedDataMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(PrefersReducedDataMediaFeature, "prefers-reduced-data"); + assert_parse!(PrefersReducedDataMediaFeature, "prefers-reduced-data: no-preference"); + assert_parse!(PrefersReducedDataMediaFeature, "prefers-reduced-data: reduce"); + } + + #[test] + fn test_minify() { + assert_minify!(PrefersReducedDataMediaFeature, "prefers-reduced-data: no-preference", "prefers-reduced-data:no-preference"); + assert_minify!(PrefersReducedDataMediaFeature, "prefers-reduced-data: reduce", "prefers-reduced-data:reduce"); + } + + #[test] + fn test_errors() { + assert_parse_error!(PrefersReducedDataMediaFeature, "prefers-reduced-data:"); + assert_parse_error!(PrefersReducedDataMediaFeature, "prefers-reduced-data: reduced"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/prefers_reduced_motion.rs b/crates/hdx_ast/src/css/rules/media/features/prefers_reduced_motion.rs new file mode 100644 index 00000000..e0dd230d --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/prefers_reduced_motion.rs @@ -0,0 +1,37 @@ +#[cfg(feature = "serde")] +use crate::macros::discrete_media_feature; + +discrete_media_feature!(PrefersReducedMotionMediaFeature[atom!("prefers-reduced-motion")] { + NoPreference: atom!("no-preference"), + Reduce: atom!("reduce"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(PrefersReducedMotionMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(PrefersReducedMotionMediaFeature, "prefers-reduced-motion"); + assert_parse!(PrefersReducedMotionMediaFeature, "prefers-reduced-motion: no-preference"); + assert_parse!(PrefersReducedMotionMediaFeature, "prefers-reduced-motion: reduce"); + } + + #[test] + fn test_minify() { + assert_minify!(PrefersReducedMotionMediaFeature, "prefers-reduced-motion: no-preference", "prefers-reduced-motion:no-preference"); + assert_minify!(PrefersReducedMotionMediaFeature, "prefers-reduced-motion: reduce", "prefers-reduced-motion:reduce"); + } + + #[test] + fn test_errors() { + assert_parse_error!(PrefersReducedMotionMediaFeature, "prefers-reduced-motion:"); + assert_parse_error!(PrefersReducedMotionMediaFeature, "prefers-reduced-motion: reduced"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/prefers_reduced_transparency.rs b/crates/hdx_ast/src/css/rules/media/features/prefers_reduced_transparency.rs new file mode 100644 index 00000000..198edb04 --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/prefers_reduced_transparency.rs @@ -0,0 +1,37 @@ +#[cfg(feature = "serde")] +use crate::macros::discrete_media_feature; + +discrete_media_feature!(PrefersReducedTransparencyMediaFeature[atom!("prefers-reduced-transparency")] { + NoPreference: atom!("no-preference"), + Reduce: atom!("reduce"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(PrefersReducedTransparencyMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(PrefersReducedTransparencyMediaFeature, "prefers-reduced-transparency"); + assert_parse!(PrefersReducedTransparencyMediaFeature, "prefers-reduced-transparency: no-preference"); + assert_parse!(PrefersReducedTransparencyMediaFeature, "prefers-reduced-transparency: reduce"); + } + + #[test] + fn test_minify() { + assert_minify!(PrefersReducedTransparencyMediaFeature, "prefers-reduced-transparency: no-preference", "prefers-reduced-transparency:no-preference"); + assert_minify!(PrefersReducedTransparencyMediaFeature, "prefers-reduced-transparency: reduce", "prefers-reduced-transparency:reduce"); + } + + #[test] + fn test_errors() { + assert_parse_error!(PrefersReducedTransparencyMediaFeature, "prefers-reduced-transparency:"); + assert_parse_error!(PrefersReducedTransparencyMediaFeature, "prefers-reduced-transparency: reduced"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/scan.rs b/crates/hdx_ast/src/css/rules/media/features/scan.rs index f1c92c86..dbb1552b 100644 --- a/crates/hdx_ast/src/css/rules/media/features/scan.rs +++ b/crates/hdx_ast/src/css/rules/media/features/scan.rs @@ -1,4 +1,37 @@ -use crate::css::values::Todo; +#[cfg(feature = "serde")] +use crate::macros::discrete_media_feature; +discrete_media_feature!(ScanMediaFeature[atom!("scan")] { + Interlace: atom!("interlace"), + Progressive: atom!("progressive"), +}); -pub type ScanMediaFeature = Todo; +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(ScanMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(ScanMediaFeature, "scan"); + assert_parse!(ScanMediaFeature, "scan: interlace"); + assert_parse!(ScanMediaFeature, "scan: progressive"); + } + + #[test] + fn test_minify() { + assert_minify!(ScanMediaFeature, "scan: interlace", "scan:interlace"); + assert_minify!(ScanMediaFeature, "scan: progressive", "scan:progressive"); + } + + #[test] + fn test_errors() { + assert_parse_error!(ScanMediaFeature, "scan:"); + assert_parse_error!(ScanMediaFeature, "scan: landscope"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/scripting.rs b/crates/hdx_ast/src/css/rules/media/features/scripting.rs new file mode 100644 index 00000000..8f320f77 --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/scripting.rs @@ -0,0 +1,40 @@ +#[cfg(feature = "serde")] +use crate::macros::discrete_media_feature; + +discrete_media_feature!(ScriptingMediaFeature[atom!("scripting")] { + None: atom!("none"), + InitialOnly: atom!("initial-only"), + Enabled: atom!("enabled"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(ScriptingMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(ScriptingMediaFeature, "scripting"); + assert_parse!(ScriptingMediaFeature, "scripting: none"); + assert_parse!(ScriptingMediaFeature, "scripting: initial-only"); + assert_parse!(ScriptingMediaFeature, "scripting: enabled"); + } + + #[test] + fn test_minify() { + assert_minify!(ScriptingMediaFeature, "scripting: none", "scripting:none"); + assert_minify!(ScriptingMediaFeature, "scripting: initial-only", "scripting:initial-only"); + assert_minify!(ScriptingMediaFeature, "scripting: enabled", "scripting:enabled"); + } + + #[test] + fn test_errors() { + assert_parse_error!(ScriptingMediaFeature, "scripting:"); + assert_parse_error!(ScriptingMediaFeature, "scripting: yes"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/vertical_viewport_segments.rs b/crates/hdx_ast/src/css/rules/media/features/vertical_viewport_segments.rs new file mode 100644 index 00000000..e69de29b diff --git a/crates/hdx_ast/src/css/rules/media/features/video_color_gamut.rs b/crates/hdx_ast/src/css/rules/media/features/video_color_gamut.rs new file mode 100644 index 00000000..5e825db3 --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/video_color_gamut.rs @@ -0,0 +1,39 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(VideoColorGamutMediaFeature[atom!("video-color-gamut")] { + Srgb: atom!("srgb"), + P3: atom!("p3"), + Rec2020: atom!("rec2020"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(VideoColorGamutMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(VideoColorGamutMediaFeature, "video-color-gamut"); + assert_parse!(VideoColorGamutMediaFeature, "video-color-gamut: srgb"); + assert_parse!(VideoColorGamutMediaFeature, "video-color-gamut: p3"); + assert_parse!(VideoColorGamutMediaFeature, "video-color-gamut: rec2020"); + } + + #[test] + fn test_minify() { + assert_minify!(VideoColorGamutMediaFeature, "video-color-gamut: srgb", "video-color-gamut:srgb"); + assert_minify!(VideoColorGamutMediaFeature, "video-color-gamut: p3", "video-color-gamut:p3"); + assert_minify!(VideoColorGamutMediaFeature, "video-color-gamut: rec2020", "video-color-gamut:rec2020"); + } + + #[test] + fn test_errors() { + assert_parse_error!(VideoColorGamutMediaFeature, "video-color-gamut:"); + assert_parse_error!(VideoColorGamutMediaFeature, "video-color-gamut: rec"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/features/video_dynamic_range.rs b/crates/hdx_ast/src/css/rules/media/features/video_dynamic_range.rs new file mode 100644 index 00000000..d0ec2107 --- /dev/null +++ b/crates/hdx_ast/src/css/rules/media/features/video_dynamic_range.rs @@ -0,0 +1,36 @@ +use crate::macros::discrete_media_feature; + +discrete_media_feature!(VideoDynamicRangeMediaFeature[atom!("video-dynamic-range")] { + Standard: atom!("standard"), + Hight: atom!("high"), +}); + +#[cfg(test)] +mod tests { + use super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(VideoDynamicRangeMediaFeature, 1); + } + + #[test] + fn test_writes() { + assert_parse!(VideoDynamicRangeMediaFeature, "video-dynamic-range"); + assert_parse!(VideoDynamicRangeMediaFeature, "video-dynamic-range: standard"); + assert_parse!(VideoDynamicRangeMediaFeature, "video-dynamic-range: high"); + } + + #[test] + fn test_minify() { + assert_minify!(VideoDynamicRangeMediaFeature, "video-dynamic-range: standard", "video-dynamic-range:standard"); + assert_minify!(VideoDynamicRangeMediaFeature, "video-dynamic-range: high", "video-dynamic-range:high"); + } + + #[test] + fn test_errors() { + assert_parse_error!(VideoDynamicRangeMediaFeature, "video-dynamic-range:"); + assert_parse_error!(VideoDynamicRangeMediaFeature, "video-dynamic-range: low"); + } +} diff --git a/crates/hdx_ast/src/css/rules/media/mod.rs b/crates/hdx_ast/src/css/rules/media/mod.rs index d8fed971..65c5cde4 100644 --- a/crates/hdx_ast/src/css/rules/media/mod.rs +++ b/crates/hdx_ast/src/css/rules/media/mod.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use smallvec::{smallvec, SmallVec}; use hdx_atom::{atom, Atom}; use hdx_lexer::Token; use hdx_parser::{ - diagnostics, expect_ignore_case, match_ident_ignore_case, peek, unexpected, unexpected_ident, AtRule, RuleGroup, + diagnostics, expect, expect_ignore_case, match_ident_ignore_case, peek, unexpected, unexpected_ident, AtRule, RuleGroup, FromToken, Parse, Parser, Result as ParserResult, Spanned, Vec, }; use hdx_writer::{CssWriter, OutputOption, Result as WriterResult, WriteCss}; @@ -18,7 +15,7 @@ use features::*; // https://drafts.csswg.org/mediaqueries-4/ #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct MediaRule<'a> { pub query: Spanned, pub rules: Spanned>, @@ -69,7 +66,7 @@ impl<'a> WriteCss<'a> for MediaRule<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MediaRules<'a>(pub Vec<'a, Spanned>>); impl<'a> Parse<'a> for MediaRules<'a> { @@ -96,7 +93,7 @@ impl<'a> WriteCss<'a> for MediaRules<'a> { } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MediaQueryList(pub SmallVec<[Spanned; 1]>); impl<'a> Parse<'a> for MediaQueryList { @@ -129,7 +126,7 @@ impl<'a> WriteCss<'a> for MediaQueryList { } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum MediaQuery { Condition(MediaCondition), Typed(MediaType), @@ -249,7 +246,7 @@ impl<'a> WriteCss<'a> for MediaQuery { } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub enum MediaCondition { Is(MediaFeature), Not(MediaFeature), @@ -332,96 +329,86 @@ impl<'a> WriteCss<'a> for MediaCondition { } } -#[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] -pub enum MediaFeature { - Height(HeightMediaFeature), - Width(WidthMediaFeature), - AspectRatio(AspectRatioMediaFeature), - Orientation(OrientationMediaFeature), - Resolution(ResolutionMediaFeature), - Scan(ScanMediaFeature), - Grid(GridMediaFeature), - Update(UpdateMediaFeature), - OverflowBlock(OverflowBlockMediaFeature), - OverflowInline(OverflowInlineMediaFeature), - Color(ColorMediaFeature), - ColorIndex(ColorIndexMediaFeature), - Monochrome(MonochromeMediaFeature), - ColorGamut(ColorGamutMediaFeature), - Pointer(PointerMediaFeature), - Hover(HoverMediaFeature), - AnyPointer(AnyPointerMediaFeature), - AnyHover(AnyHoverMediaFeature), - DeviceWidth(DeviceWidthMediaFeature), - DeviceHeight(DeviceHeightMediaFeature), - DeviceAspectRatio(DeviceAspectRatioMediaFeature), -} +macro_rules! media_features { + ( $($name: ident($typ: ident): atom!($atom: tt),)+ ) => { + // https://drafts.csswg.org/mediaqueries-5/#media-descriptor-table + #[derive(Debug, PartialEq, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] + pub enum MediaFeature { + $($name($typ),)+ + } -impl<'a> Parse<'a> for MediaFeature { - fn parse(parser: &mut Parser<'a>) -> ParserResult { - match parser.peek().clone() { - Token::Ident(ident) => match ident.to_ascii_lowercase() { - atom!("height") => Ok(Self::Height(HeightMediaFeature::parse(parser)?)), - atom!("width") => Ok(Self::Width(WidthMediaFeature::parse(parser)?)), - atom!("aspect-ratio") => Ok(Self::AspectRatio(AspectRatioMediaFeature::parse(parser)?)), - atom!("orientation") => Ok(Self::Orientation(OrientationMediaFeature::parse(parser)?)), - atom!("resolution") => Ok(Self::Resolution(ResolutionMediaFeature::parse(parser)?)), - atom!("scan") => Ok(Self::Scan(ScanMediaFeature::parse(parser)?)), - atom!("grid") => Ok(Self::Grid(GridMediaFeature::parse(parser)?)), - atom!("update") => Ok(Self::Update(UpdateMediaFeature::parse(parser)?)), - atom!("overflow-block") => Ok(Self::OverflowBlock(OverflowBlockMediaFeature::parse(parser)?)), - atom!("overflow-inline") => Ok(Self::OverflowInline(OverflowInlineMediaFeature::parse(parser)?)), - atom!("color") => Ok(Self::Color(ColorMediaFeature::parse(parser)?)), - atom!("color-index") => Ok(Self::ColorIndex(ColorIndexMediaFeature::parse(parser)?)), - atom!("monochrome") => Ok(Self::Monochrome(MonochromeMediaFeature::parse(parser)?)), - atom!("color-gamut") => Ok(Self::ColorGamut(ColorGamutMediaFeature::parse(parser)?)), - atom!("pointer") => Ok(Self::Pointer(PointerMediaFeature::parse(parser)?)), - atom!("hover") => Ok(Self::Hover(HoverMediaFeature::parse(parser)?)), - atom!("any-pointer") => Ok(Self::AnyPointer(AnyPointerMediaFeature::parse(parser)?)), - atom!("any-hover") => Ok(Self::AnyHover(AnyHoverMediaFeature::parse(parser)?)), - atom!("device-width") => Ok(Self::DeviceWidth(DeviceWidthMediaFeature::parse(parser)?)), - atom!("device-height") => Ok(Self::DeviceHeight(DeviceHeightMediaFeature::parse(parser)?)), - atom!("device-aspect-ratio") => { - Ok(Self::DeviceAspectRatio(DeviceAspectRatioMediaFeature::parse(parser)?)) - } - _ => unexpected_ident!(parser, ident), - }, - token => unexpected!(parser, token), + impl<'a> Parse<'a> for MediaFeature { + fn parse(parser: &mut Parser<'a>) -> ParserResult { + expect!(parser, Token::LeftParen); + parser.advance(); + let value = match parser.cur() { + Token::Ident(ident) => match ident.to_ascii_lowercase() { + $(atom!($atom) => Self::$name($typ::parse(parser)?),)+ + _ => unexpected_ident!(parser, ident), + }, + token => unexpected!(parser, token), + }; + expect!(parser, Token::RightParen); + parser.advance(); + Ok(value) + } } - } -} -impl<'a> WriteCss<'a> for MediaFeature { - fn write_css(&self, sink: &mut W) -> WriterResult { - match self { - Self::Height(f) => f.write_css(sink), - Self::Width(f) => f.write_css(sink), - Self::AspectRatio(f) => f.write_css(sink), - Self::Orientation(f) => f.write_css(sink), - Self::Resolution(f) => f.write_css(sink), - Self::Scan(f) => f.write_css(sink), - Self::Grid(f) => f.write_css(sink), - Self::Update(f) => f.write_css(sink), - Self::OverflowBlock(f) => f.write_css(sink), - Self::OverflowInline(f) => f.write_css(sink), - Self::Color(f) => f.write_css(sink), - Self::ColorIndex(f) => f.write_css(sink), - Self::Monochrome(f) => f.write_css(sink), - Self::ColorGamut(f) => f.write_css(sink), - Self::Pointer(f) => f.write_css(sink), - Self::Hover(f) => f.write_css(sink), - Self::AnyPointer(f) => f.write_css(sink), - Self::AnyHover(f) => f.write_css(sink), - Self::DeviceWidth(f) => f.write_css(sink), - Self::DeviceHeight(f) => f.write_css(sink), - Self::DeviceAspectRatio(f) => f.write_css(sink), + impl<'a> WriteCss<'a> for MediaFeature { + fn write_css(&self, sink: &mut W) -> WriterResult { + sink.write_char('(')?; + match self { + $(Self::$name(f) => f.write_css(sink)?,)+ + } + sink.write_char(')') + } } } } +media_features!( + AnyHover(AnyHoverMediaFeature): atom!("any-hover"), + AnyPointer(AnyPointerMediaFeature): atom!("any-pointer"), + AspectRatio(AspectRatioMediaFeature): atom!("aspect-ratio"), + Color(ColorMediaFeature): atom!("color"), + ColorGamut(ColorGamutMediaFeature): atom!("color-gamut"), + ColorIndex(ColorIndexMediaFeature): atom!("color-index"), + DeviceAspectRatio(DeviceAspectRatioMediaFeature): atom!("device-aspect-ratio"), + DeviceHeight(DeviceHeightMediaFeature): atom!("device-height"), + DeviceWidth(DeviceWidthMediaFeature): atom!("device-width"), + DisplayMode(DisplayModeMediaFeature): atom!("display-mode"), + DynamicRange(DynamicRangeMediaFeature): atom!("dynamic-range"), + EnvironmentBlending(EnvironmentBlendingMediaFeature): atom!("environment-blending"), + ForcedColors(ForcedColorsMediaFeature): atom!("forced-colors"), + Grid(GridMediaFeature): atom!("grid"), + Height(HeightMediaFeature): atom!("height"), + // HorizontalViewportSegments(HorizontalViewportSegmentsMediaFeature): atom!("horizontal-viewport-segments"), + Hover(HoverMediaFeature): atom!("hover"), + InvertedColors(InvertedColorsMediaFeature): atom!("inverted-colors"), + Monochrome(MonochromeMediaFeature): atom!("monochrome"), + NavControls(NavControlsMediaFeature): atom!("nav-controls"), + Orientation(OrientationMediaFeature): atom!("orientation"), + OverflowBlock(OverflowBlockMediaFeature): atom!("overflow-block"), + OverflowInline(OverflowInlineMediaFeature): atom!("overflow-inline"), + Pointer(PointerMediaFeature): atom!("pointer"), + PrefersColorScheme(PrefersColorSchemeMediaFeature): atom!("prefers-color-scheme"), + PrefersContrast(PrefersContrastMediaFeature): atom!("prefers-contrast"), + PrefersReducedData(PrefersReducedDataMediaFeature): atom!("prefers-reduced-data"), + PrefersReducedMotion(PrefersReducedMotionMediaFeature): atom!("prefers-reduced-motion"), + PrefersReducedTransparency(PrefersReducedTransparencyMediaFeature): atom!("prefers-reduced-transparency"), + Resolution(ResolutionMediaFeature): atom!("resolution"), + Scan(ScanMediaFeature): atom!("scan"), + Scripting(ScriptingMediaFeature): atom!("scripting"), + Update(UpdateMediaFeature): atom!("update"), + // VerticalViewportSegments(VerticalViewportSegmentsMediaFeature): atom!("vertical-viewport-segments"), + VideoColorGamut(VideoColorGamutMediaFeature): atom!("video-color-gamut"), + VideoDynamicRange(VideoDynamicRangeMediaFeature): atom!("video-dynamic-range"), + Width(WidthMediaFeature): atom!("width"), +); + #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub enum MediaType { All, // atom!("all") Print, // atom!("print") @@ -482,6 +469,7 @@ mod tests { assert_parse!(MediaQuery, "screen and (hover) and (pointer)"); // assert_parse!(MediaQuery, "screen and (orientation: landscape)"); assert_parse!(MediaRule, "@media print {\n\n}"); + assert_parse!(MediaRule, "@media print, (prefers-reduced-motion: reduce) {\n\n}"); // assert_parse!(MediaRule, "@media (min-width: 1200px) {\n\n}"); // assert_parse!(MediaRUle, "@media only screen and (max-device-width: 800px), only screen and (device-width: 1024px) and (device-height: 600px), only screen and (width: 1280px) and (orientation: landscape), only screen and (device-width: 800px), only screen and (max-width: 767px)"); } diff --git a/crates/hdx_ast/src/css/rules/page.rs b/crates/hdx_ast/src/css/rules/page.rs index 90a06950..9eb29917 100644 --- a/crates/hdx_ast/src/css/rules/page.rs +++ b/crates/hdx_ast/src/css/rules/page.rs @@ -3,9 +3,7 @@ use hdx_parser::{ diagnostics, expect, unexpected, AtRule, DeclarationRuleList, Parse, Parser, Result as ParserResult, Spanned, Vec, }; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; -use smallvec::{SmallVec, smallvec}; +use smallvec::{smallvec, SmallVec}; use super::NoPreludeAllowed; use crate::{atom, css::properties::Property, Atom, Atomizable, Specificity, ToSpecificity}; @@ -13,7 +11,7 @@ use crate::{atom, css::properties::Property, Atom, Atomizable, Specificity, ToSp // https://drafts.csswg.org/cssom-1/#csspagerule // https://drafts.csswg.org/css-page-3/#at-page-rule #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct PageRule<'a> { pub selectors: Option>, pub style: Spanned>, @@ -49,7 +47,7 @@ impl<'a> WriteCss<'a> for PageRule<'a> { } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct PageSelectorList(pub SmallVec<[Spanned; 1]>); impl<'a> Parse<'a> for PageSelectorList { @@ -82,7 +80,7 @@ impl<'a> WriteCss<'a> for PageSelectorList { } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct PageSelector { pub page_type: Option, pub pseudos: SmallVec<[Spanned; 1]>, @@ -143,7 +141,7 @@ impl<'a> PageSelector { } #[derive(Atomizable, Debug, Clone, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(rename_all = "kebab-case"))] pub enum PagePseudoClass { Left, Right, @@ -177,7 +175,7 @@ impl ToSpecificity for PagePseudoClass { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct PageDeclaration<'a> { #[cfg_attr(feature = "serde", serde(borrow))] pub properties: Vec<'a, Spanned>>, @@ -226,7 +224,7 @@ impl<'a> WriteCss<'a> for PageDeclaration<'a> { // https://drafts.csswg.org/cssom-1/#cssmarginrule #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct MarginRule<'a> { pub name: PageMarginBox, #[cfg_attr(feature = "serde", serde(borrow))] @@ -273,7 +271,7 @@ impl<'a> WriteCss<'a> for MarginRule<'a> { } #[derive(Atomizable, Debug, Clone, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(rename_all = "kebab-case"))] pub enum PageMarginBox { TopLeftCorner, // atom!("top-left-corner") TopLeft, // atom!("top-left") @@ -294,7 +292,7 @@ pub enum PageMarginBox { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct MarginDeclaration<'a> { #[cfg_attr(feature = "serde", serde(borrow))] pub properties: Vec<'a, Spanned>>, diff --git a/crates/hdx_ast/src/css/rules/supports.rs b/crates/hdx_ast/src/css/rules/supports.rs index 7a39f523..bd5fbedc 100644 --- a/crates/hdx_ast/src/css/rules/supports.rs +++ b/crates/hdx_ast/src/css/rules/supports.rs @@ -10,11 +10,9 @@ use hdx_parser::{ Result as ParserResult, RuleGroup, RuleList, Spanned, Vec, }; use hdx_writer::{CssWriter, OutputOption, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct SupportsRule<'a> { pub condition: Spanned>, pub rules: Spanned>, @@ -65,7 +63,7 @@ impl<'a> WriteCss<'a> for SupportsRule<'a> { } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct SupportsRules<'a>(pub Vec<'a, Spanned>>); impl<'a> Parse<'a> for SupportsRules<'a> { @@ -93,7 +91,7 @@ impl<'a> WriteCss<'a> for SupportsRules<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub enum SupportsCondition<'a> { Is(SupportsFeature<'a>), Not(SupportsFeature<'a>), @@ -223,7 +221,7 @@ impl<'a> WriteCss<'a> for SupportsCondition<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct SupportsFeature<'a>(pub SimpleBlock<'a>); impl<'a> Parse<'a> for SupportsFeature<'a> { @@ -240,7 +238,7 @@ impl<'a> WriteCss<'a> for SupportsFeature<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct SupportsDeclaration<'a> { #[cfg_attr(feature = "serde", serde(borrow))] pub rules: Vec<'a, Spanned>>, @@ -286,7 +284,11 @@ mod tests { #[test] fn test_minify() { - assert_minify!(SupportsRule, "@supports (width: 1px) { body { width:1px; } }", "@supports(width: 1px){body{width:1px}}"); + assert_minify!( + SupportsRule, + "@supports (width: 1px) { body { width:1px; } }", + "@supports(width: 1px){body{width:1px}}" + ); assert_minify!( SupportsRule, "@supports not (width: 1--foo) { a { width:1px } }", diff --git a/crates/hdx_ast/src/css/selector/attribute.rs b/crates/hdx_ast/src/css/selector/attribute.rs index 8627fd0d..76e03846 100644 --- a/crates/hdx_ast/src/css/selector/attribute.rs +++ b/crates/hdx_ast/src/css/selector/attribute.rs @@ -1,14 +1,12 @@ use hdx_atom::{atom, Atom}; -use hdx_lexer::{Token, QuoteStyle}; +use hdx_lexer::{QuoteStyle, Token}; use hdx_parser::{discard, expect, unexpected, unexpected_ident, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use super::{parse_wq_name, NSPrefix}; #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct Attribute { pub ns_prefix: NSPrefix, pub name: Atom, @@ -80,7 +78,7 @@ impl<'a> Parse<'a> for Attribute { Token::Ident(value) => { parser.advance(); value - }, + } Token::String(value, q) => { quote = q; parser.advance(); @@ -163,7 +161,7 @@ impl<'a> WriteCss<'a> for Attribute { } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", content = "value"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", content = "value"))] pub enum AttributeMatch { Any, // [attr] Exact, // [attr=val] @@ -175,7 +173,7 @@ pub enum AttributeMatch { } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub enum AttributeModifier { None, Sensitive, diff --git a/crates/hdx_ast/src/css/selector/mod.rs b/crates/hdx_ast/src/css/selector/mod.rs index 3582ab14..af6d7b0e 100644 --- a/crates/hdx_ast/src/css/selector/mod.rs +++ b/crates/hdx_ast/src/css/selector/mod.rs @@ -5,8 +5,6 @@ use hdx_parser::{ Spanned, }; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use smallvec::{smallvec, SmallVec}; use crate::{Atomizable, Vec}; @@ -18,7 +16,7 @@ use attribute::Attribute; use pseudo_class::PseudoClass; #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct Selectors<'a>(pub SmallVec<[Spanned>; 1]>); impl<'a> Parse<'a> for Selectors<'a> { @@ -57,7 +55,7 @@ impl<'a> WriteCss<'a> for Selectors<'a> { // Having `Selector` be both ` simple-selector` and `compound-selector` makes // parsing and visiting more practical. #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct Selector<'a> { pub components: Vec<'a, Spanned>>, } @@ -127,13 +125,13 @@ impl<'a> WriteCss<'a> for Selector<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct ForgivingSelector<'a> { pub components: Vec<'a, Spanned>>, } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct RelativeSelector<'a> { pub components: Vec<'a, Spanned>>, } @@ -142,7 +140,7 @@ pub struct RelativeSelector<'a> { // `id-selector`) into one enum, as it makes parsing and visiting much more // practical. #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", content = "value"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", content = "value"))] pub enum Component<'a> { Id(Atom), Class(Atom), @@ -294,7 +292,7 @@ impl<'a> WriteCss<'a> for Component<'a> { // https://drafts.csswg.org/css-pseudo/#index-defined-here #[derive(Atomizable, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum PseudoElement { After, // atom!("after") Backdrop, // atom!("backdrop") @@ -313,7 +311,7 @@ pub enum PseudoElement { } #[derive(Atomizable, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum LegacyPseudoElement { After, // atom!("after") Before, // atom!("before") @@ -322,7 +320,7 @@ pub enum LegacyPseudoElement { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub enum PseudoFunction<'a> { Dir(DirValue), // atom!("dir") Has(RelativeSelector<'a>), // atom!("has") @@ -341,14 +339,14 @@ pub enum PseudoFunction<'a> { } #[derive(Atomizable, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum DirValue { Rtl, // atom!("rtl") Ltr, // atom!("ltr") } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", content = "value"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", content = "value"))] pub enum NSPrefix { None, Wildcard, @@ -356,7 +354,7 @@ pub enum NSPrefix { } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] // https://drafts.csswg.org/selectors/#combinators pub enum Combinator { Descendant, // (Space) @@ -367,13 +365,13 @@ pub enum Combinator { } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct ANB { string: Atom, } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct ANBEvenOdd { string: Atom, } diff --git a/crates/hdx_ast/src/css/selector/pseudo_class.rs b/crates/hdx_ast/src/css/selector/pseudo_class.rs index 96818a35..aad5a791 100644 --- a/crates/hdx_ast/src/css/selector/pseudo_class.rs +++ b/crates/hdx_ast/src/css/selector/pseudo_class.rs @@ -1,10 +1,7 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::Atomizable; #[derive(Atomizable, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(rename_all = "kebab-case"))] pub enum PseudoClass { Active, // atom!("active") AnyLink, // atom!("any-link") diff --git a/crates/hdx_ast/src/css/stylerule.rs b/crates/hdx_ast/src/css/stylerule.rs index 032c0229..d44920d7 100644 --- a/crates/hdx_ast/src/css/stylerule.rs +++ b/crates/hdx_ast/src/css/stylerule.rs @@ -1,7 +1,5 @@ use hdx_parser::{Block, Parse, Parser, QualifiedRule, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss, OutputOption}; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::{ css::{properties::Property, selector::Selectors}, @@ -10,7 +8,7 @@ use crate::{ // https://drafts.csswg.org/cssom-1/#the-cssstylerule-interface #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct StyleRule<'a> { pub selectors: Spanned>, pub style: Spanned>, @@ -48,7 +46,7 @@ impl<'a> WriteCss<'a> for StyleRule<'a> { // https://drafts.csswg.org/cssom-1/#the-cssstylerule-interface #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct StyleDeclaration<'a> { pub declarations: Vec<'a, Spanned>>, pub rules: Vec<'a, Spanned>>, diff --git a/crates/hdx_ast/src/css/stylesheet.rs b/crates/hdx_ast/src/css/stylesheet.rs index 8b94d3d9..582ef814 100644 --- a/crates/hdx_ast/src/css/stylesheet.rs +++ b/crates/hdx_ast/src/css/stylesheet.rs @@ -3,8 +3,6 @@ use hdx_derive::Atomizable; use hdx_lexer::Token; use hdx_parser::{diagnostics, Parse, Parser, Result as ParserResult, StyleSheet as StyleSheetTrait}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::{ css::{ @@ -17,7 +15,7 @@ use crate::{ // https://drafts.csswg.org/cssom-1/#the-cssstylesheet-interface #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct StyleSheet<'a> { pub rules: Vec<'a, Spanned>>, } @@ -48,7 +46,7 @@ impl<'a> WriteCss<'a> for StyleSheet<'a> { // https://drafts.csswg.org/cssom-1/#the-cssrule-interface #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(untagged))] pub enum Rule<'a> { Charset(CharsetRule), Page(PageRule<'a>), @@ -107,7 +105,7 @@ impl<'a> WriteCss<'a> for Rule<'a> { } #[derive(Atomizable, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(untagged))] pub enum AtRuleId { Charset, // atom!("charset") Page, // atom!("page") diff --git a/crates/hdx_ast/src/css/values/animations/animation_delay.rs b/crates/hdx_ast/src/css/values/animations/animation_delay.rs index 47b6726a..b905add9 100644 --- a/crates/hdx_ast/src/css/values/animations/animation_delay.rs +++ b/crates/hdx_ast/src/css/values/animations/animation_delay.rs @@ -1,8 +1,6 @@ use hdx_lexer::Token; use hdx_parser::{unexpected, FromToken, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use super::super::units::Time; use crate::Value; @@ -10,7 +8,7 @@ use smallvec::{smallvec, SmallVec}; // https://drafts.csswg.org/css-animations-2/#animation-duration #[derive(Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct AnimationDelay(pub SmallVec<[Time; 2]>); impl<'a> Value for AnimationDelay {} diff --git a/crates/hdx_ast/src/css/values/animations/animation_duration.rs b/crates/hdx_ast/src/css/values/animations/animation_duration.rs index f4f47fb2..015ab150 100644 --- a/crates/hdx_ast/src/css/values/animations/animation_duration.rs +++ b/crates/hdx_ast/src/css/values/animations/animation_duration.rs @@ -2,8 +2,6 @@ use hdx_atom::atom; use hdx_lexer::Token; use hdx_parser::{unexpected, unexpected_ident, FromToken, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use super::super::units::Time; use crate::Value; @@ -11,7 +9,7 @@ use smallvec::{smallvec, SmallVec}; // https://drafts.csswg.org/css-animations-2/#animation-duration #[derive(Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum AnimationDuration { #[default] Auto, diff --git a/crates/hdx_ast/src/css/values/animations/animation_fill_mode.rs b/crates/hdx_ast/src/css/values/animations/animation_fill_mode.rs index 6ba86cf0..ce387f1a 100644 --- a/crates/hdx_ast/src/css/values/animations/animation_fill_mode.rs +++ b/crates/hdx_ast/src/css/values/animations/animation_fill_mode.rs @@ -1,19 +1,17 @@ use hdx_lexer::Token; use hdx_parser::{unexpected, unexpected_ident, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::{Atomizable, Value, Writable}; use smallvec::{smallvec, SmallVec}; // https://drafts.csswg.org/css-animations-2/#animation-fill-mode #[derive(Value, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct AnimationFillMode(pub SmallVec<[SingleAnimationFillMode; 8]>); #[derive(Atomizable, Writable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum SingleAnimationFillMode { #[default] None, // atom!("none") diff --git a/crates/hdx_ast/src/css/values/animations/animation_iteration_count.rs b/crates/hdx_ast/src/css/values/animations/animation_iteration_count.rs index dc733ce4..79ed01b0 100644 --- a/crates/hdx_ast/src/css/values/animations/animation_iteration_count.rs +++ b/crates/hdx_ast/src/css/values/animations/animation_iteration_count.rs @@ -2,19 +2,17 @@ use hdx_atom::atom; use hdx_lexer::Token; use hdx_parser::{unexpected, unexpected_ident, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::{css::values::units::CSSFloat, Value, Writable}; use smallvec::{smallvec, SmallVec}; // https://drafts.csswg.org/css-animations-2/#animation-fill-mode #[derive(Value, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct AnimationIterationCount(pub SmallVec<[SingleAnimationIterationCount; 1]>); #[derive(Writable, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum SingleAnimationIterationCount { Infinite, // atom!("infinite") Number(CSSFloat), diff --git a/crates/hdx_ast/src/css/values/backgrounds/border_top_style.rs b/crates/hdx_ast/src/css/values/backgrounds/border_top_style.rs index c1d00509..2af6666d 100644 --- a/crates/hdx_ast/src/css/values/backgrounds/border_top_style.rs +++ b/crates/hdx_ast/src/css/values/backgrounds/border_top_style.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-backgrounds-3/#propdef-border-top-style #[derive(Parsable, Writable, Atomizable, Debug, Default, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum BorderTopStyle { #[default] None, // atom!("none") diff --git a/crates/hdx_ast/src/css/values/box/margin.rs b/crates/hdx_ast/src/css/values/box/margin.rs index 1849010a..e869e963 100644 --- a/crates/hdx_ast/src/css/values/box/margin.rs +++ b/crates/hdx_ast/src/css/values/box/margin.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::LengthPercentageOrAuto, macros::*, Parsable, Value, Writable}; // https://drafts.csswg.org/css-box-4/#margin-physical #[derive(Value, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct Margin(pub MarginBlockStart, pub MarginBlockEnd, pub MarginInlineStart, pub MarginInlineEnd); parse_rect!(Margin, LengthPercentageOrAuto, MarginBlockStart, MarginBlockEnd, MarginInlineStart, MarginInlineEnd); @@ -13,7 +10,7 @@ write_rect!(Margin); // https://drafts.csswg.org/css-logical-1/#propdef-margin-inline #[derive(Value, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MarginInline(pub MarginInlineStart, pub MarginInlineEnd); parse_logical_sides!(MarginInline, LengthPercentageOrAuto, MarginInlineStart, MarginInlineEnd); @@ -21,42 +18,42 @@ write_logical_sides!(MarginInline); // https://drafts.csswg.org/css-logical-1/#propdef-margin-inline #[derive(Value, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MarginBlock(pub MarginBlockStart, pub MarginBlockEnd); parse_logical_sides!(MarginBlock, LengthPercentageOrAuto, MarginBlockStart, MarginBlockEnd); write_logical_sides!(MarginBlock); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MarginBlockStart(#[parsable(FromToken)] pub LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MarginBlockEnd(#[parsable(FromToken)] pub LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MarginInlineStart(#[parsable(FromToken)] pub LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MarginInlineEnd(#[parsable(FromToken)] pub LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MarginTop(#[parsable(FromToken)] LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MarginBottom(#[parsable(FromToken)] LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MarginLeft(#[parsable(FromToken)] LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct MarginRight(#[parsable(FromToken)] LengthPercentageOrAuto); #[cfg(test)] diff --git a/crates/hdx_ast/src/css/values/box/margin_trim.rs b/crates/hdx_ast/src/css/values/box/margin_trim.rs index 6012e33b..15ec1c93 100644 --- a/crates/hdx_ast/src/css/values/box/margin_trim.rs +++ b/crates/hdx_ast/src/css/values/box/margin_trim.rs @@ -2,15 +2,13 @@ use hdx_atom::atom; use hdx_lexer::Token; use hdx_parser::{unexpected, unexpected_ident, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::{bitmask, Atomizable, Value}; // https://drafts.csswg.org/css-box-4/#propdef-margin-trim #[derive(Value, Atomizable, Default)] #[bitmask(u8)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum MarginTrim { #[default] None, diff --git a/crates/hdx_ast/src/css/values/box/padding.rs b/crates/hdx_ast/src/css/values/box/padding.rs index 11aada2d..20ac8392 100644 --- a/crates/hdx_ast/src/css/values/box/padding.rs +++ b/crates/hdx_ast/src/css/values/box/padding.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::LengthPercentageOrAuto, macros::*, Parsable, Value, Writable}; // https://drafts.csswg.org/css-box-4/#padding-physical #[derive(Value, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct Padding(pub PaddingBlockStart, pub PaddingBlockEnd, pub PaddingInlineStart, pub PaddingInlineEnd); parse_rect!(Padding, LengthPercentageOrAuto, PaddingBlockStart, PaddingBlockEnd, PaddingInlineStart, PaddingInlineEnd); @@ -13,7 +10,7 @@ write_rect!(Padding); // https://drafts.csswg.org/css-logical-1/#propdef-padding-inline #[derive(Value, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct PaddingInline(pub PaddingInlineStart, pub PaddingInlineEnd); parse_logical_sides!(PaddingInline, LengthPercentageOrAuto, PaddingInlineStart, PaddingInlineEnd); @@ -21,42 +18,42 @@ write_logical_sides!(PaddingInline); // https://drafts.csswg.org/css-logical-1/#propdef-padding-inline #[derive(Value, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct PaddingBlock(pub PaddingBlockStart, pub PaddingBlockEnd); parse_logical_sides!(PaddingBlock, LengthPercentageOrAuto, PaddingBlockStart, PaddingBlockEnd); write_logical_sides!(PaddingBlock); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct PaddingBlockStart(#[parsable(FromToken)] pub LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct PaddingBlockEnd(#[parsable(FromToken)] pub LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct PaddingInlineStart(#[parsable(FromToken)] pub LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct PaddingInlineEnd(#[parsable(FromToken)] pub LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct PaddingTop(#[parsable(FromToken)] LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct PaddingBottom(#[parsable(FromToken)] LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct PaddingLeft(#[parsable(FromToken)] LengthPercentageOrAuto); #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct PaddingRight(#[parsable(FromToken)] LengthPercentageOrAuto); #[cfg(test)] diff --git a/crates/hdx_ast/src/css/values/break/box_decoration_break.rs b/crates/hdx_ast/src/css/values/break/box_decoration_break.rs index da8576b1..bf831be7 100644 --- a/crates/hdx_ast/src/css/values/break/box_decoration_break.rs +++ b/crates/hdx_ast/src/css/values/break/box_decoration_break.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-box-4/#propdef-margin-trim #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum BoxDecorationBreak { #[default] Slice, // atom!("slice") diff --git a/crates/hdx_ast/src/css/values/break/break_before.rs b/crates/hdx_ast/src/css/values/break/break_before.rs index 81bea56d..4c02b351 100644 --- a/crates/hdx_ast/src/css/values/break/break_before.rs +++ b/crates/hdx_ast/src/css/values/break/break_before.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-break-4/#propdef-break-before #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum BreakBefore { #[default] Auto, // atom!("auto") diff --git a/crates/hdx_ast/src/css/values/break/break_inside.rs b/crates/hdx_ast/src/css/values/break/break_inside.rs index f6589e85..f01588d5 100644 --- a/crates/hdx_ast/src/css/values/break/break_inside.rs +++ b/crates/hdx_ast/src/css/values/break/break_inside.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-break-4/#propdef-break-inside #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum BreakInside { #[default] Auto, // atom!("auto") diff --git a/crates/hdx_ast/src/css/values/break/margin_break.rs b/crates/hdx_ast/src/css/values/break/margin_break.rs index 5dbbca6b..a183ce83 100644 --- a/crates/hdx_ast/src/css/values/break/margin_break.rs +++ b/crates/hdx_ast/src/css/values/break/margin_break.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-break-4/#propdef-margin-break #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum MarginBreak { #[default] Auto, // atom!("auto") diff --git a/crates/hdx_ast/src/css/values/cascade/all.rs b/crates/hdx_ast/src/css/values/cascade/all.rs index daf0d833..88b5a613 100644 --- a/crates/hdx_ast/src/css/values/cascade/all.rs +++ b/crates/hdx_ast/src/css/values/cascade/all.rs @@ -1,11 +1,9 @@ use hdx_parser::{Parse, Parser, Result as ParserResult, Span, Spanned}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; // https://drafts.csswg.org/css-cascade-5/#propdef-all #[derive(Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct All(); impl<'a> Parse<'a> for All { diff --git a/crates/hdx_ast/src/css/values/color_adjust/color_scheme.rs b/crates/hdx_ast/src/css/values/color_adjust/color_scheme.rs index 810ec7ad..af7724a4 100644 --- a/crates/hdx_ast/src/css/values/color_adjust/color_scheme.rs +++ b/crates/hdx_ast/src/css/values/color_adjust/color_scheme.rs @@ -3,14 +3,16 @@ use hdx_atom::{atom, Atom}; use hdx_lexer::Token; use hdx_parser::{unexpected, unexpected_ident, FromToken, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use smallvec::{smallvec, SmallVec}; // https://drafts.csswg.org/css-color-adjust/#color-scheme-prop #[derive(Value, Default, Debug, PartialEq, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", content = "value", rename_all = "kebab-case"))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize), + serde(tag = "type", content = "value", rename_all = "kebab-case") +)] pub enum ColorScheme { #[default] Normal, @@ -83,7 +85,7 @@ impl<'a> WriteCss<'a> for ColorScheme { } #[derive(Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(rename_all = "kebab-case"))] pub enum ColorSchemeKeyword { Light, Dark, diff --git a/crates/hdx_ast/src/css/values/compositing/mix_blend_mode.rs b/crates/hdx_ast/src/css/values/compositing/mix_blend_mode.rs index 10f1765a..3bead704 100644 --- a/crates/hdx_ast/src/css/values/compositing/mix_blend_mode.rs +++ b/crates/hdx_ast/src/css/values/compositing/mix_blend_mode.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.fxtf.org/compositing/#propdef-mix-blend-mode #[derive(Parsable, Writable, Atomizable, Debug, Default, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum MixBlendMode { #[default] Normal, // atom!("normal") diff --git a/crates/hdx_ast/src/css/values/content/content.rs b/crates/hdx_ast/src/css/values/content/content.rs index 279f0c1f..c2f4e3f0 100644 --- a/crates/hdx_ast/src/css/values/content/content.rs +++ b/crates/hdx_ast/src/css/values/content/content.rs @@ -1,15 +1,13 @@ use hdx_atom::{atom, Atom}; -use hdx_lexer::{Token, QuoteStyle}; +use hdx_lexer::{QuoteStyle, Token}; use hdx_parser::{unexpected, unexpected_ident, Parse, Parser, Result as ParserResult}; use hdx_writer::WriteCss; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::Value; #[derive(Value, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Content { #[default] Normal, @@ -51,9 +49,7 @@ impl<'a> WriteCss<'a> for Content { match self { Self::None => atom!("none").write_css(sink), Self::Normal => atom!("normal").write_css(sink), - Self::String(str, quote) => { - sink.write_with_quotes(str.as_ref(), *quote, false) - } + Self::String(str, quote) => sink.write_with_quotes(str.as_ref(), *quote, false), } } } diff --git a/crates/hdx_ast/src/css/values/css2/z_index.rs b/crates/hdx_ast/src/css/values/css2/z_index.rs index 2972befc..0f78eef3 100644 --- a/crates/hdx_ast/src/css/values/css2/z_index.rs +++ b/crates/hdx_ast/src/css/values/css2/z_index.rs @@ -1,10 +1,7 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::CSSFloat, Parsable, Value, Writable}; #[derive(Value, Parsable, Writable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", content = "value"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", content = "value"))] pub enum ZIndex { #[default] Auto, diff --git a/crates/hdx_ast/src/css/values/display/display.rs b/crates/hdx_ast/src/css/values/display/display.rs index 11dff6e3..ed99d64e 100644 --- a/crates/hdx_ast/src/css/values/display/display.rs +++ b/crates/hdx_ast/src/css/values/display/display.rs @@ -2,15 +2,13 @@ use hdx_atom::{atom, Atom}; use hdx_lexer::Token; use hdx_parser::{diagnostics, unexpected_ident, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::{bitmask, Value}; // https://drafts.csswg.org/css-display-4/#propdef-display #[derive(Value, Default)] #[bitmask(u8)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Display { // The anatomy of the u8 for Display values is: // diff --git a/crates/hdx_ast/src/css/values/display/visibility.rs b/crates/hdx_ast/src/css/values/display/visibility.rs index 55300544..454d09b5 100644 --- a/crates/hdx_ast/src/css/values/display/visibility.rs +++ b/crates/hdx_ast/src/css/values/display/visibility.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Parsable, Value, Writable}; #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Visibility { #[default] Visible, // atom!("visible"), diff --git a/crates/hdx_ast/src/css/values/fonts/font_family.rs b/crates/hdx_ast/src/css/values/fonts/font_family.rs index 9a7b371b..abe3b8cd 100644 --- a/crates/hdx_ast/src/css/values/fonts/font_family.rs +++ b/crates/hdx_ast/src/css/values/fonts/font_family.rs @@ -2,19 +2,17 @@ use hdx_atom::{atom, Atom}; use hdx_lexer::{QuoteStyle, Token}; use hdx_parser::{unexpected, Parse, Parser, Result as ParserResult, Spanned}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::{Value, Writable}; use smallvec::{smallvec, SmallVec}; // https://drafts.csswg.org/css-animations-2/#animation-duration #[derive(Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct FontFamily(pub SmallVec<[Spanned; 1]>); #[derive(Writable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum SingleFontFamily { #[writable(String)] Named(Atom, QuoteStyle), diff --git a/crates/hdx_ast/src/css/values/fonts/font_size.rs b/crates/hdx_ast/src/css/values/fonts/font_size.rs index f10fe26e..5406e338 100644 --- a/crates/hdx_ast/src/css/values/fonts/font_size.rs +++ b/crates/hdx_ast/src/css/values/fonts/font_size.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::LengthPercentage, Parsable, Value, Writable}; #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum FontSize { XxSmall, // atom!("xx-small") XSmall, // atom!("x-small") diff --git a/crates/hdx_ast/src/css/values/fonts/font_weight.rs b/crates/hdx_ast/src/css/values/fonts/font_weight.rs index d5cbefed..f1aacf1f 100644 --- a/crates/hdx_ast/src/css/values/fonts/font_weight.rs +++ b/crates/hdx_ast/src/css/values/fonts/font_weight.rs @@ -1,16 +1,13 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::CSSFloat, Parsable, Value, Writable}; // https://drafts.csswg.org/css-inline/#propdef-alignment-baseline #[derive(Value, Parsable, Writable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum FontWeight { #[parsable(Number, Check::Range(1.0..=1000.0), Check::Int)] Number(CSSFloat), - #[default] - Normal, // atom!("normal") + #[default] + Normal, // atom!("normal") Bold, // atom!("bold") Bolder, // atom!("bolder") Lighter, // atom!("lighter") diff --git a/crates/hdx_ast/src/css/values/inline/alignment_baseline.rs b/crates/hdx_ast/src/css/values/inline/alignment_baseline.rs index b61b7d79..2c17109c 100644 --- a/crates/hdx_ast/src/css/values/inline/alignment_baseline.rs +++ b/crates/hdx_ast/src/css/values/inline/alignment_baseline.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-inline/#propdef-alignment-baseline #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum AlignmentBaseline { #[default] Baseline, // atom!("baseline") diff --git a/crates/hdx_ast/src/css/values/inline/baseline_shift.rs b/crates/hdx_ast/src/css/values/inline/baseline_shift.rs index af199721..71370211 100644 --- a/crates/hdx_ast/src/css/values/inline/baseline_shift.rs +++ b/crates/hdx_ast/src/css/values/inline/baseline_shift.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - -use crate::{Parsable, Value, Writable, css::values::units::LengthPercentage}; +use crate::{css::values::units::LengthPercentage, Parsable, Value, Writable}; // https://drafts.csswg.org/css-inline/#propdef-alignment-baseline #[derive(Value, Parsable, Writable, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum BaselineShift { #[parsable(DimensionOrZero, FromToken)] LengthPercentage(LengthPercentage), @@ -17,9 +14,9 @@ pub enum BaselineShift { } impl Default for BaselineShift { - fn default() -> Self { + fn default() -> Self { Self::LengthPercentage(LengthPercentage::Zero) - } + } } #[cfg(test)] diff --git a/crates/hdx_ast/src/css/values/inline/baseline_source.rs b/crates/hdx_ast/src/css/values/inline/baseline_source.rs index b2b8f4e3..8c5348a7 100644 --- a/crates/hdx_ast/src/css/values/inline/baseline_source.rs +++ b/crates/hdx_ast/src/css/values/inline/baseline_source.rs @@ -1,13 +1,11 @@ use hdx_lexer::Token; use hdx_parser::FromToken; -#[cfg(feature = "serde")] -use serde::Serialize; -use crate::{Value, Atomizable, Writable}; +use crate::{Atomizable, Value, Writable}; // https://drafts.csswg.org/css-inline/#propdef-baseline-source #[derive(Value, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum BaselineSource { #[default] Auto, // atom!("auto") @@ -16,12 +14,12 @@ pub enum BaselineSource { } impl FromToken for BaselineSource { - fn from_token(token: Token) -> Option { + fn from_token(token: Token) -> Option { match token { Token::Ident(atom) => Self::from_atom(atom), - _ => None + _ => None, } - } + } } #[cfg(test)] diff --git a/crates/hdx_ast/src/css/values/inline/dominant_baseline.rs b/crates/hdx_ast/src/css/values/inline/dominant_baseline.rs index b21115ac..729047cc 100644 --- a/crates/hdx_ast/src/css/values/inline/dominant_baseline.rs +++ b/crates/hdx_ast/src/css/values/inline/dominant_baseline.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-inline/#propdef-dominant-baseline #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum DominantBaseline { #[default] Auto, // atom!("auto") diff --git a/crates/hdx_ast/src/css/values/inline/line_height.rs b/crates/hdx_ast/src/css/values/inline/line_height.rs index b3b64b86..def1010d 100644 --- a/crates/hdx_ast/src/css/values/inline/line_height.rs +++ b/crates/hdx_ast/src/css/values/inline/line_height.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{ css::values::units::{CSSFloat, LengthPercentage}, Parsable, Value, Writable, @@ -8,7 +5,7 @@ use crate::{ #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum LineHeight { #[default] Normal, // atom!("normal") diff --git a/crates/hdx_ast/src/css/values/inline/vertical_align.rs b/crates/hdx_ast/src/css/values/inline/vertical_align.rs index a3e1d430..75d920a1 100644 --- a/crates/hdx_ast/src/css/values/inline/vertical_align.rs +++ b/crates/hdx_ast/src/css/values/inline/vertical_align.rs @@ -1,6 +1,4 @@ use hdx_parser::{FromToken, Parse, Parser, Result as ParserResult, Span, Spanned}; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::{macros::*, Value}; @@ -8,7 +6,7 @@ use super::{AlignmentBaseline, BaselineShift, BaselineSource}; // https://drafts.csswg.org/css-box-4/#padding-physical #[derive(Value, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct VerticalAlign(pub Spanned, pub Spanned, pub Spanned); impl<'a> Parse<'a> for VerticalAlign { diff --git a/crates/hdx_ast/src/css/values/lists/list_style_position.rs b/crates/hdx_ast/src/css/values/lists/list_style_position.rs index e365a570..a5d04cbd 100644 --- a/crates/hdx_ast/src/css/values/lists/list_style_position.rs +++ b/crates/hdx_ast/src/css/values/lists/list_style_position.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - -use crate::{Value, Atomizable, Parsable, Writable}; +use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-inline/#propdef-baseline-source #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum ListStylePosition { #[default] Outside, // atom!("outside") diff --git a/crates/hdx_ast/src/css/values/mod.rs b/crates/hdx_ast/src/css/values/mod.rs index e6d37786..eb9aad37 100644 --- a/crates/hdx_ast/src/css/values/mod.rs +++ b/crates/hdx_ast/src/css/values/mod.rs @@ -1,8 +1,5 @@ use hdx_parser::{diagnostics, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; - /// Values mod align; mod anchor_position; @@ -126,7 +123,7 @@ mod units; // TODO! #[derive(Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(untagged))] pub enum Todo { #[default] Todo, @@ -145,7 +142,7 @@ impl<'a> WriteCss<'a> for Todo { } // #[derive(Debug, PartialEq, Hash)] -// #[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))] +// #[cfg_attr(feature = "serde", derive(serde::Serialize), serde(untagged))] // pub enum ValueLike<'a> { // Color(Box<'a, Spanned>>>), // Length(Box<'a, Spanned>>), @@ -156,14 +153,14 @@ impl<'a> WriteCss<'a> for Todo { // // // https://drafts.csswg.org/css-values-4/#typedef-position // #[derive(Debug, PartialEq, Hash)] -// #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +// #[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] // pub struct PositionXY { // pub x: HorizontalPosition, // pub y: VerticalPosition, // } // // #[derive(Debug, PartialEq, Hash)] -// #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +// #[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] // pub enum HorizontalPosition { // Center, // Length(LengthPercentage), @@ -172,7 +169,7 @@ impl<'a> WriteCss<'a> for Todo { // } // // #[derive(Debug, PartialEq, Hash)] -// #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +// #[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] // pub enum VerticalPosition { // Center, // Length(LengthPercentage), @@ -181,11 +178,11 @@ impl<'a> WriteCss<'a> for Todo { // } // // #[derive(Default, Debug, PartialEq, Hash)] -// #[cfg_attr(feature = "serde", derive(Serialize), serde())] +// #[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] // pub struct NoNonGlobalValuesAllowed; // // #[derive(Atomizable, Default, Debug, PartialEq, Hash)] -// #[cfg_attr(feature = "serde", derive(Serialize), serde())] +// #[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] // pub enum AutoOrNone { // #[default] // Auto, @@ -194,11 +191,11 @@ impl<'a> WriteCss<'a> for Todo { // // // https://drafts.csswg.org/css-values-4/#ratio-value // #[derive(Default, Debug, PartialEq, Hash)] -// #[cfg_attr(feature = "serde", derive(Serialize), serde())] +// #[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] // pub struct Ratio(u8, u8); // // #[derive(Default, Debug, PartialEq, Hash)] -// #[cfg_attr(feature = "serde", derive(Serialize), serde())] +// #[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] // pub enum TimeOrAuto { // #[default] // Auto, @@ -207,7 +204,7 @@ impl<'a> WriteCss<'a> for Todo { // // // https://drafts.csswg.org/css-values/#typedef-length-percentage // #[derive(Debug, PartialEq)] -// #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +// #[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] // pub enum FrequencyPercentage { // Frequency(Frequency), // Percentage(f32), @@ -225,7 +222,7 @@ impl<'a> WriteCss<'a> for Todo { // // // https://drafts.csswg.org/css-values/#typedef-length-percentage // #[derive(Debug, PartialEq)] -// #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +// #[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] // pub enum AnglePercentage { // Angle(Angle), // Percentage(f32), @@ -243,7 +240,7 @@ impl<'a> WriteCss<'a> for Todo { // // // https://drafts.csswg.org/css-values/#typedef-length-percentage // #[derive(Debug, PartialEq)] -// #[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +// #[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] // pub enum TimePercentage { // Time(Time), // Percentage(f32), diff --git a/crates/hdx_ast/src/css/values/non_standard/mod.rs b/crates/hdx_ast/src/css/values/non_standard/mod.rs index 5730b9e5..88eac2eb 100644 --- a/crates/hdx_ast/src/css/values/non_standard/mod.rs +++ b/crates/hdx_ast/src/css/values/non_standard/mod.rs @@ -1,2 +1,5 @@ mod zoom; pub use zoom::*; + +mod webkit; +pub use webkit::*; diff --git a/crates/hdx_ast/src/css/values/non_standard/webkit.rs b/crates/hdx_ast/src/css/values/non_standard/webkit.rs new file mode 100644 index 00000000..4dc90366 --- /dev/null +++ b/crates/hdx_ast/src/css/values/non_standard/webkit.rs @@ -0,0 +1,6 @@ +use crate::css::values::{AnimationDuration, AnimationFillMode, AnimationIterationCount, AnimationDelay}; + +pub type WebkitAnimationDuration = AnimationDuration; +pub type WebkitAnimationDelay = AnimationDelay; +pub type WebkitAnimationFillMode = AnimationFillMode; +pub type WebkitAnimationIterationCount = AnimationIterationCount; diff --git a/crates/hdx_ast/src/css/values/non_standard/zoom.rs b/crates/hdx_ast/src/css/values/non_standard/zoom.rs index 57cf2791..a5376aba 100644 --- a/crates/hdx_ast/src/css/values/non_standard/zoom.rs +++ b/crates/hdx_ast/src/css/values/non_standard/zoom.rs @@ -1,10 +1,7 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::CSSFloat, Parsable, Writable}; #[derive(Parsable, Writable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", content = "value"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", content = "value"))] pub enum Zoom { #[default] Normal, // atom!("normal") diff --git a/crates/hdx_ast/src/css/values/overflow/overflow_block.rs b/crates/hdx_ast/src/css/values/overflow/overflow_block.rs index 2ab24763..fc1aa915 100644 --- a/crates/hdx_ast/src/css/values/overflow/overflow_block.rs +++ b/crates/hdx_ast/src/css/values/overflow/overflow_block.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-overflow-3/#propdef-overflow-block #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum OverflowBlock { #[default] Visible, // atom!("visible") diff --git a/crates/hdx_ast/src/css/values/page_floats/clear.rs b/crates/hdx_ast/src/css/values/page_floats/clear.rs index aae4e565..8997cb8e 100644 --- a/crates/hdx_ast/src/css/values/page_floats/clear.rs +++ b/crates/hdx_ast/src/css/values/page_floats/clear.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-page-floats-3/#propdef-clear #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum Clear { InlineStart, // atom!("inline-start") InlineEnd, // atom!("inline-end") diff --git a/crates/hdx_ast/src/css/values/page_floats/float.rs b/crates/hdx_ast/src/css/values/page_floats/float.rs index ea84cc09..4a43cbd9 100644 --- a/crates/hdx_ast/src/css/values/page_floats/float.rs +++ b/crates/hdx_ast/src/css/values/page_floats/float.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use hdx_atom::atom; use hdx_lexer::Token; use hdx_parser::{diagnostics, expect, unexpected, unexpected_ident, FromToken, Parse, Parser, Result as ParserResult}; @@ -10,7 +7,7 @@ use crate::{css::values::units::Length, Atomizable, Value}; // https://drafts.csswg.org/css-page-floats-3/#float-property #[derive(Value, Debug, PartialEq, Default, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Float { #[default] None, @@ -182,7 +179,7 @@ impl<'a> WriteCss<'a> for Float { } #[derive(Atomizable, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum SnapBlockDirection { Start, // atom!("start") End, // atom!("end") @@ -190,7 +187,7 @@ pub enum SnapBlockDirection { } #[derive(Atomizable, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum SnapInlineDirection { Left, // atom!("left") Right, // atom!("right") diff --git a/crates/hdx_ast/src/css/values/page_floats/float_defer.rs b/crates/hdx_ast/src/css/values/page_floats/float_defer.rs index c787f7c2..5a271cb1 100644 --- a/crates/hdx_ast/src/css/values/page_floats/float_defer.rs +++ b/crates/hdx_ast/src/css/values/page_floats/float_defer.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::CSSFloat, Parsable, Writable}; // https://drafts.csswg.org/css-page-floats-3/#propdef-float-defer #[derive(Parsable, Writable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum FloatDefer { #[default] Last, diff --git a/crates/hdx_ast/src/css/values/page_floats/float_reference.rs b/crates/hdx_ast/src/css/values/page_floats/float_reference.rs index ffe60dc1..15a908ba 100644 --- a/crates/hdx_ast/src/css/values/page_floats/float_reference.rs +++ b/crates/hdx_ast/src/css/values/page_floats/float_reference.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-page-floats-3/#propdef-float-reference #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum FloatReference { #[default] Inline, // atom!("inline") diff --git a/crates/hdx_ast/src/css/values/position/bottom.rs b/crates/hdx_ast/src/css/values/position/bottom.rs index 613ee985..294045f1 100644 --- a/crates/hdx_ast/src/css/values/position/bottom.rs +++ b/crates/hdx_ast/src/css/values/position/bottom.rs @@ -1,10 +1,7 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::LengthPercentage, Parsable, Value, Writable}; #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Bottom { #[default] Auto, // atom!("auto"), diff --git a/crates/hdx_ast/src/css/values/position/left.rs b/crates/hdx_ast/src/css/values/position/left.rs index 15bb7708..23da82cb 100644 --- a/crates/hdx_ast/src/css/values/position/left.rs +++ b/crates/hdx_ast/src/css/values/position/left.rs @@ -1,10 +1,7 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::LengthPercentage, Parsable, Value, Writable}; #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Left { #[default] Auto, // atom!("auto"), diff --git a/crates/hdx_ast/src/css/values/position/position.rs b/crates/hdx_ast/src/css/values/position/position.rs index 3aa47bc0..80d27003 100644 --- a/crates/hdx_ast/src/css/values/position/position.rs +++ b/crates/hdx_ast/src/css/values/position/position.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-position-3/#propdef-position #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum Position { #[default] Static, // atom!("static") diff --git a/crates/hdx_ast/src/css/values/position/right.rs b/crates/hdx_ast/src/css/values/position/right.rs index 93b8c311..5949ce11 100644 --- a/crates/hdx_ast/src/css/values/position/right.rs +++ b/crates/hdx_ast/src/css/values/position/right.rs @@ -1,10 +1,7 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::LengthPercentage, Parsable, Value, Writable}; #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Right { #[default] Auto, // atom!("auto"), diff --git a/crates/hdx_ast/src/css/values/position/top.rs b/crates/hdx_ast/src/css/values/position/top.rs index eb72a6aa..966dec6f 100644 --- a/crates/hdx_ast/src/css/values/position/top.rs +++ b/crates/hdx_ast/src/css/values/position/top.rs @@ -1,10 +1,7 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::LengthPercentage, Parsable, Value, Writable}; #[derive(Value, Parsable, Writable, Default, PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Top { #[default] Auto, // atom!("auto"), diff --git a/crates/hdx_ast/src/css/values/size_adjust/text_size_adjust.rs b/crates/hdx_ast/src/css/values/size_adjust/text_size_adjust.rs index e8484acc..1ec88d5e 100644 --- a/crates/hdx_ast/src/css/values/size_adjust/text_size_adjust.rs +++ b/crates/hdx_ast/src/css/values/size_adjust/text_size_adjust.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{css::values::units::CSSFloat, Parsable, Writable}; // https://drafts.csswg.org/css-size-adjust-1/#propdef-text-size-adjust #[derive(Parsable, Writable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum TextSizeAdjust { None, #[default] diff --git a/crates/hdx_ast/src/css/values/sizing/box_sizing.rs b/crates/hdx_ast/src/css/values/sizing/box_sizing.rs index dae5c08c..f5207af9 100644 --- a/crates/hdx_ast/src/css/values/sizing/box_sizing.rs +++ b/crates/hdx_ast/src/css/values/sizing/box_sizing.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-sizing/#propdef-box-sizing #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum BoxSizing { #[default] ContentBox, // atom!("content-box") diff --git a/crates/hdx_ast/src/css/values/sizing/max_width.rs b/crates/hdx_ast/src/css/values/sizing/max_width.rs index 0e390527..26187845 100644 --- a/crates/hdx_ast/src/css/values/sizing/max_width.rs +++ b/crates/hdx_ast/src/css/values/sizing/max_width.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use super::super::units::LengthPercentage; -use crate::{Value, Parsable, Writable}; +use crate::{Parsable, Value, Writable}; // https://drafts.csswg.org/css-sizing-4/#sizing-values #[derive(Value, Parsable, Writable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum MaxWidth { #[default] None, // atom!("none") diff --git a/crates/hdx_ast/src/css/values/sizing/min_intrinsic_sizing.rs b/crates/hdx_ast/src/css/values/sizing/min_intrinsic_sizing.rs index 0ce9c418..a3b7b45e 100644 --- a/crates/hdx_ast/src/css/values/sizing/min_intrinsic_sizing.rs +++ b/crates/hdx_ast/src/css/values/sizing/min_intrinsic_sizing.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-sizing-4/#propdef-min-intrinsic-sizing #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum MinIntrinsicSizing { #[default] Legacy, // atom!("legacy") diff --git a/crates/hdx_ast/src/css/values/sizing/width.rs b/crates/hdx_ast/src/css/values/sizing/width.rs index f1d83af7..52259df7 100644 --- a/crates/hdx_ast/src/css/values/sizing/width.rs +++ b/crates/hdx_ast/src/css/values/sizing/width.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use super::super::units::LengthPercentage; use crate::{Parsable, Value, Writable}; // https://drafts.csswg.org/css-sizing-4/#sizing-values #[derive(Value, Parsable, Writable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum Width { #[default] Auto, // atom!("auto") diff --git a/crates/hdx_ast/src/css/values/tables/border_collapse.rs b/crates/hdx_ast/src/css/values/tables/border_collapse.rs index b8abaf27..e19ce715 100644 --- a/crates/hdx_ast/src/css/values/tables/border_collapse.rs +++ b/crates/hdx_ast/src/css/values/tables/border_collapse.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-tables-3/#propdef-border-collapse #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum BorderCollapse { #[default] Separate, // atom!("separate") diff --git a/crates/hdx_ast/src/css/values/tables/caption_side.rs b/crates/hdx_ast/src/css/values/tables/caption_side.rs index 390ee1d5..54ee58b4 100644 --- a/crates/hdx_ast/src/css/values/tables/caption_side.rs +++ b/crates/hdx_ast/src/css/values/tables/caption_side.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-tables-3/#propdef-caption-side #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum CaptionSide { #[default] Top, // atom!("top") diff --git a/crates/hdx_ast/src/css/values/tables/empty_cells.rs b/crates/hdx_ast/src/css/values/tables/empty_cells.rs index 901c3b5d..2ce19d13 100644 --- a/crates/hdx_ast/src/css/values/tables/empty_cells.rs +++ b/crates/hdx_ast/src/css/values/tables/empty_cells.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-tables-3/#propdef-empty-cells #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum EmptyCells { #[default] Show, // atom!("show") diff --git a/crates/hdx_ast/src/css/values/tables/table_layout.rs b/crates/hdx_ast/src/css/values/tables/table_layout.rs index c9ca54ef..bd7b1690 100644 --- a/crates/hdx_ast/src/css/values/tables/table_layout.rs +++ b/crates/hdx_ast/src/css/values/tables/table_layout.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-tables-3/#propdef-table-layout #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum TableLayout { #[default] Auto, // atom!("auto") diff --git a/crates/hdx_ast/src/css/values/text/text_align.rs b/crates/hdx_ast/src/css/values/text/text_align.rs index 0948d771..e64e6311 100644 --- a/crates/hdx_ast/src/css/values/text/text_align.rs +++ b/crates/hdx_ast/src/css/values/text/text_align.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-text-4/#propdef-text-align #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum TextAlign { #[default] Start, // atom!("start") diff --git a/crates/hdx_ast/src/css/values/text/text_align_all.rs b/crates/hdx_ast/src/css/values/text/text_align_all.rs index 587dbc78..26dddff5 100644 --- a/crates/hdx_ast/src/css/values/text/text_align_all.rs +++ b/crates/hdx_ast/src/css/values/text/text_align_all.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-text-4/#propdef-text-align-all #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum TextAlignAll { #[default] Start, // atom!("start") diff --git a/crates/hdx_ast/src/css/values/text/text_align_last.rs b/crates/hdx_ast/src/css/values/text/text_align_last.rs index dbda2387..46fac2c5 100644 --- a/crates/hdx_ast/src/css/values/text/text_align_last.rs +++ b/crates/hdx_ast/src/css/values/text/text_align_last.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-text-4/#propdef-text-align-last #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum TextAlignLast { #[default] Auto, // atom!("auto") diff --git a/crates/hdx_ast/src/css/values/text/text_wrap.rs b/crates/hdx_ast/src/css/values/text/text_wrap.rs index 70b5b145..2e58f895 100644 --- a/crates/hdx_ast/src/css/values/text/text_wrap.rs +++ b/crates/hdx_ast/src/css/values/text/text_wrap.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-text-4/#propdef-text-wrap #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum TextWrap { #[default] Wrap, // atom!("wrap") diff --git a/crates/hdx_ast/src/css/values/text/white_space_collapse.rs b/crates/hdx_ast/src/css/values/text/white_space_collapse.rs index 322d253c..5bb1986f 100644 --- a/crates/hdx_ast/src/css/values/text/white_space_collapse.rs +++ b/crates/hdx_ast/src/css/values/text/white_space_collapse.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-text-4/#propdef-white-space-collapse #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum WhiteSpaceCollapse { #[default] Collapse, // atom!("collapse") diff --git a/crates/hdx_ast/src/css/values/text/white_space_trim.rs b/crates/hdx_ast/src/css/values/text/white_space_trim.rs index f9f7c584..402e4a42 100644 --- a/crates/hdx_ast/src/css/values/text/white_space_trim.rs +++ b/crates/hdx_ast/src/css/values/text/white_space_trim.rs @@ -2,15 +2,13 @@ use hdx_atom::atom; use hdx_lexer::Token; use hdx_parser::{unexpected, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::{bitmask, Atomizable, Value}; // https://drafts.csswg.org/css-text-4/#propdef-white-space-trim #[derive(Value, Default, Atomizable)] #[bitmask(u8)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum WhiteSpaceTrim { #[default] None = 0b0000, // atom!("none") diff --git a/crates/hdx_ast/src/css/values/text_decor/text_decoration_line.rs b/crates/hdx_ast/src/css/values/text_decor/text_decoration_line.rs index f3ce8e07..4ea4fb93 100644 --- a/crates/hdx_ast/src/css/values/text_decor/text_decoration_line.rs +++ b/crates/hdx_ast/src/css/values/text_decor/text_decoration_line.rs @@ -2,15 +2,13 @@ use hdx_atom::atom; use hdx_lexer::Token; use hdx_parser::{unexpected, Parse, Parser, Result as ParserResult}; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use crate::{bitmask, Value}; // https://drafts.csswg.org/css-text/#text-align-property #[derive(Value, Default)] #[bitmask(u8)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum TextDecorationLine { #[default] None = 0b0000, diff --git a/crates/hdx_ast/src/css/values/text_decor/text_decoration_skip_ink.rs b/crates/hdx_ast/src/css/values/text_decor/text_decoration_skip_ink.rs index 2d60fa72..ecd6dcd4 100644 --- a/crates/hdx_ast/src/css/values/text_decor/text_decoration_skip_ink.rs +++ b/crates/hdx_ast/src/css/values/text_decor/text_decoration_skip_ink.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-text/#text-align-property #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum TextDecorationSkipInk { #[default] Auto, // atom!("auto") diff --git a/crates/hdx_ast/src/css/values/text_decor/text_decoration_style.rs b/crates/hdx_ast/src/css/values/text_decor/text_decoration_style.rs index 4142cfa3..b4949312 100644 --- a/crates/hdx_ast/src/css/values/text_decor/text_decoration_style.rs +++ b/crates/hdx_ast/src/css/values/text_decor/text_decoration_style.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-text/#text-align-property #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum TextDecorationStyle { #[default] Solid, // atom!("solid"), diff --git a/crates/hdx_ast/src/css/values/ui/appearance.rs b/crates/hdx_ast/src/css/values/ui/appearance.rs index fcf79e8c..24e7f168 100644 --- a/crates/hdx_ast/src/css/values/ui/appearance.rs +++ b/crates/hdx_ast/src/css/values/ui/appearance.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-ui/#appearance-switching #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum Appearance { None, // atom!("none") #[default] diff --git a/crates/hdx_ast/src/css/values/ui/cursor.rs b/crates/hdx_ast/src/css/values/ui/cursor.rs index 6f31dd28..85304519 100644 --- a/crates/hdx_ast/src/css/values/ui/cursor.rs +++ b/crates/hdx_ast/src/css/values/ui/cursor.rs @@ -1,12 +1,9 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Value, Writable}; // https://drafts.csswg.org/css-ui-4/#propdef-cursor #[derive(Value, Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] #[value(Inherits)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum Cursor { #[default] Auto, // atom!("auto") diff --git a/crates/hdx_ast/src/css/values/ui/pointer_events.rs b/crates/hdx_ast/src/css/values/ui/pointer_events.rs index 3c03948c..62124e1a 100644 --- a/crates/hdx_ast/src/css/values/ui/pointer_events.rs +++ b/crates/hdx_ast/src/css/values/ui/pointer_events.rs @@ -1,10 +1,7 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; #[derive(Parsable, Writable, Atomizable, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub enum PointerEvents { Auto, // atom!("auto") None, // atom!("none") diff --git a/crates/hdx_ast/src/css/values/units/angles.rs b/crates/hdx_ast/src/css/values/units/angles.rs index e3752da9..654c380b 100644 --- a/crates/hdx_ast/src/css/values/units/angles.rs +++ b/crates/hdx_ast/src/css/values/units/angles.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - const DEG_GRAD: f32 = 0.9; const DEG_RAD: f32 = 57.29577951308232; const DEG_TURN: f32 = 360.0; @@ -10,7 +7,7 @@ use crate::{Parsable, Writable}; // https://drafts.csswg.org/css-values/#angles #[derive(Parsable, Writable, Debug, Clone, Copy, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Angle { #[writable(suffix = "grad")] #[parsable(Dimension)] diff --git a/crates/hdx_ast/src/css/values/units/custom.rs b/crates/hdx_ast/src/css/values/units/custom.rs index 5eca8087..9d88f6fa 100644 --- a/crates/hdx_ast/src/css/values/units/custom.rs +++ b/crates/hdx_ast/src/css/values/units/custom.rs @@ -1,12 +1,10 @@ use hdx_atom::Atom; -#[cfg(feature = "serde")] -use serde::Serialize; use super::CSSFloat; use crate::Writable; #[derive(Writable, Debug, Clone, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct Custom(CSSFloat, Atom); impl Into for Custom { diff --git a/crates/hdx_ast/src/css/values/units/float.rs b/crates/hdx_ast/src/css/values/units/float.rs index 93bac8a0..91799447 100644 --- a/crates/hdx_ast/src/css/values/units/float.rs +++ b/crates/hdx_ast/src/css/values/units/float.rs @@ -5,12 +5,10 @@ use std::{ }; use hdx_derive::Writable; -#[cfg(feature = "serde")] -use serde::Serialize; // CSS floats are different to f32s in that they do not represent NaN #[derive(Writable, Debug, Clone, Copy, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(transparent))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(transparent))] pub struct CSSFloat(f32); impl CSSFloat { diff --git a/crates/hdx_ast/src/css/values/units/frequency.rs b/crates/hdx_ast/src/css/values/units/frequency.rs index 167a6649..663eda3c 100644 --- a/crates/hdx_ast/src/css/values/units/frequency.rs +++ b/crates/hdx_ast/src/css/values/units/frequency.rs @@ -1,14 +1,12 @@ use hdx_atom::atom; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; use super::{AbsoluteUnit, CSSFloat}; use crate::Parsable; // https://drafts.csswg.org/css-values/#resolution #[derive(Parsable, Debug, Clone, Copy, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Frequency { #[parsable(Dimension)] Hz(CSSFloat), diff --git a/crates/hdx_ast/src/css/values/units/length.rs b/crates/hdx_ast/src/css/values/units/length.rs index 6b0ba8b5..8de85daf 100644 --- a/crates/hdx_ast/src/css/values/units/length.rs +++ b/crates/hdx_ast/src/css/values/units/length.rs @@ -1,8 +1,6 @@ use hdx_atom::{atom, Atom}; use hdx_lexer::Token; use hdx_parser::FromToken; -#[cfg(feature = "serde")] -use serde::Serialize; use super::CSSFloat; use crate::Writable; @@ -20,7 +18,7 @@ macro_rules! length { )+ ) => { #[derive(Writable, Default, Debug, Clone, Copy, PartialEq, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize), serde())] + #[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Length { #[writable(rename = "0")] #[default] @@ -60,7 +58,7 @@ macro_rules! length { } #[derive(Writable, Default, Debug, Clone, Copy, PartialEq, Hash)] - #[cfg_attr(feature = "serde", derive(Serialize), serde())] + #[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum LengthPercentage { #[default] #[writable(rename = "0")] @@ -165,7 +163,7 @@ length! { } #[derive(Writable, Default, Debug, Clone, Copy, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum LengthPercentageOrAuto { #[default] Auto, diff --git a/crates/hdx_ast/src/css/values/units/percent.rs b/crates/hdx_ast/src/css/values/units/percent.rs index 660b1a9f..f9c09e4d 100644 --- a/crates/hdx_ast/src/css/values/units/percent.rs +++ b/crates/hdx_ast/src/css/values/units/percent.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use super::CSSFloat; use crate::Writable; #[derive(Writable, Debug, Clone, Copy, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] #[writable(suffix = "%")] pub struct Percent(CSSFloat); diff --git a/crates/hdx_ast/src/css/values/units/resolution.rs b/crates/hdx_ast/src/css/values/units/resolution.rs index 1a16ff7b..3736c3c5 100644 --- a/crates/hdx_ast/src/css/values/units/resolution.rs +++ b/crates/hdx_ast/src/css/values/units/resolution.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - const DPPX_IN: f32 = 96.0; const DPPX_CM: f32 = DPPX_IN / 2.54; @@ -9,7 +6,7 @@ use crate::{Parsable, Writable}; // https://drafts.csswg.org/css-values/#resolution #[derive(Parsable, Writable, Debug, Clone, Copy, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Resolution { #[writable(suffix = "dpi")] #[parsable(Dimension)] diff --git a/crates/hdx_ast/src/css/values/units/time.rs b/crates/hdx_ast/src/css/values/units/time.rs index 158b9066..d423390a 100644 --- a/crates/hdx_ast/src/css/values/units/time.rs +++ b/crates/hdx_ast/src/css/values/units/time.rs @@ -1,7 +1,5 @@ use hdx_atom::{atom, Atom}; use hdx_lexer::Token; -#[cfg(feature = "serde")] -use serde::Serialize; use super::{AbsoluteUnit, CSSFloat}; use crate::Writable; @@ -9,7 +7,7 @@ use hdx_parser::FromToken; // https://drafts.csswg.org/css-values/#resolution #[derive(Writable, Debug, Clone, Copy, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub enum Time { #[writable(suffix = "ms")] Ms(CSSFloat), diff --git a/crates/hdx_ast/src/css/values/writing_modes/writing_mode.rs b/crates/hdx_ast/src/css/values/writing_modes/writing_mode.rs index 5798597f..621a503d 100644 --- a/crates/hdx_ast/src/css/values/writing_modes/writing_mode.rs +++ b/crates/hdx_ast/src/css/values/writing_modes/writing_mode.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "serde")] -use serde::Serialize; - use crate::{Atomizable, Parsable, Writable}; // https://drafts.csswg.org/css-position-3/#propdef-position #[derive(Parsable, Writable, Atomizable, Default, Debug, PartialEq, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type", rename_all = "kebab-case"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type", rename_all = "kebab-case"))] pub enum WritingMode { #[default] HorizontalTb, // atom!("horizontal-tb") diff --git a/crates/hdx_ast/src/macros.rs b/crates/hdx_ast/src/macros.rs index 1240f17a..4300207e 100644 --- a/crates/hdx_ast/src/macros.rs +++ b/crates/hdx_ast/src/macros.rs @@ -157,3 +157,58 @@ macro_rules! write_simple_shorthand { } pub(crate) use write_simple_shorthand; + +macro_rules! discrete_media_feature { + ($feat: tt[atom!($atom: tt)] { $( $name: ident: atom!($name_atom: tt),)+ }) => { + #[derive(PartialEq, Default, Debug, Hash)] + #[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] + pub enum $feat { + #[default] + Any, + $( $name, )+ + } + + impl<'a> hdx_parser::Parse<'a> for $feat { + fn parse(parser: &mut hdx_parser::Parser<'a>) -> hdx_parser::Result { + use hdx_parser::MediaFeature; + Self::parse_media_feature(hdx_atom::atom!($atom), parser) + } + } + + impl<'a> hdx_parser::MediaFeature<'a> for $feat { + fn parse_media_feature_value(parser: &mut hdx_parser::Parser<'a>) -> hdx_parser::Result { + match parser.cur() { + hdx_lexer::Token::Ident(ident) => match ident.to_ascii_lowercase() { + $( + hdx_atom::atom!($name_atom) => { + parser.advance(); + Ok(Self::$name) + } + )+ + _ => hdx_parser::unexpected_ident!(parser, ident), + }, + token => hdx_parser::unexpected!(parser, token), + } + } + } + + impl<'a> hdx_writer::WriteCss<'a> for $feat { + fn write_css(&self, sink: &mut W) -> hdx_writer::Result { + hdx_atom::atom!($atom).write_css(sink)?; + match self { + $( + Self::$name => { + sink.write_char(':')?; + sink.write_whitespace()?; + hdx_atom::atom!($name_atom).write_css(sink) + } + )+ + Self::Any => Ok(()) + } + } + } + + }; +} + +pub(crate) use discrete_media_feature; diff --git a/crates/hdx_ast/src/syntax.rs b/crates/hdx_ast/src/syntax.rs index 42d18c95..f1158375 100644 --- a/crates/hdx_ast/src/syntax.rs +++ b/crates/hdx_ast/src/syntax.rs @@ -5,12 +5,10 @@ use hdx_parser::{ Result as ParserResult, Span, Spanned, State, Vec, }; use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; -#[cfg(feature = "serde")] -use serde::Serialize; // https://drafts.csswg.org/css-syntax-3/#consume-list-of-components #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde())] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] pub struct ComponentValues<'a>(pub Vec<'a, Spanned>>); impl<'a> Parse<'a> for ComponentValues<'a> { @@ -43,7 +41,7 @@ impl<'a> WriteCss<'a> for ComponentValues<'a> { // https://drafts.csswg.org/css-syntax-3/#consume-component-value #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(untagged))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(untagged))] pub enum ComponentValue<'a> { SimpleBlock(SimpleBlock<'a>), Function(Function<'a>), @@ -126,7 +124,7 @@ impl<'a> WriteCss<'a> for ComponentValue<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct SimpleBlock<'a> { pub pairwise: PairWise, pub values: Vec<'a, Spanned>>, @@ -178,7 +176,7 @@ impl<'a> WriteCss<'a> for SimpleBlock<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub enum Rule<'a> { AtRule(AtRule<'a>), QualifiedRule(QualifiedRule<'a>), @@ -203,7 +201,7 @@ impl<'a> WriteCss<'a> for Rule<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct Block<'a> { pub declarations: Vec<'a, Spanned>>, pub rules: Vec<'a, Spanned>>, @@ -222,7 +220,7 @@ impl<'a> BlockTrait<'a> for Block<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct Declaration<'a> { pub name: Atom, pub value: Spanned>, @@ -293,7 +291,7 @@ impl<'a> WriteCss<'a> for Block<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct AtRule<'a> { pub name: Atom, pub prelude: Spanned>, @@ -336,7 +334,7 @@ impl<'a> WriteCss<'a> for AtRule<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct QualifiedRule<'a> { pub prelude: Spanned>, pub block: Spanned>, @@ -365,7 +363,7 @@ impl<'a> WriteCss<'a> for QualifiedRule<'a> { } #[derive(PartialEq, Debug, Hash)] -#[cfg_attr(feature = "serde", derive(Serialize), serde(tag = "type"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))] pub struct Function<'a> { pub name: Atom, pub values: Vec<'a, Spanned>>, diff --git a/crates/hdx_parser/src/traits.rs b/crates/hdx_parser/src/traits.rs index 20f473a8..674f1aad 100644 --- a/crates/hdx_parser/src/traits.rs +++ b/crates/hdx_parser/src/traits.rs @@ -330,20 +330,15 @@ pub trait MediaFeature<'a>: Sized + Default { fn parse_media_feature_value(parser: &mut Parser<'a>) -> Result; fn parse_media_feature(name: Atom, parser: &mut Parser<'a>) -> Result { - expect!(parser, Token::LeftParen); - parser.advance(); expect_ignore_case!(parser, name); parser.advance(); let value = match parser.cur() { - Token::RightParen => Self::default(), Token::Colon => { parser.advance(); Self::parse_media_feature_value(parser)? } - token => unexpected!(parser, token), + _ => Self::default(), }; - expect!(parser, Token::RightParen); - parser.advance(); Ok(value) } }