From 4e20e1f36d006e02507025976745f4150e56e3e6 Mon Sep 17 00:00:00 2001 From: Keith Cirkel Date: Wed, 6 Nov 2024 23:34:55 +0000 Subject: [PATCH] (ast/values) implement sizing properties --- crates/hdx_ast/src/css/values/sizing/impls.rs | 26 ++++ crates/hdx_ast/src/css/values/sizing/mod.rs | 130 ++++++++++-------- crates/hdx_ast/src/css/values/sizing/types.rs | 32 +++++ crates/hdx_proc_macro/src/def.rs | 1 + ...st__custom_function_variant_with_args.snap | 1 + 5 files changed, 131 insertions(+), 59 deletions(-) diff --git a/crates/hdx_ast/src/css/values/sizing/impls.rs b/crates/hdx_ast/src/css/values/sizing/impls.rs index 63d13520..0423d3c2 100644 --- a/crates/hdx_ast/src/css/values/sizing/impls.rs +++ b/crates/hdx_ast/src/css/values/sizing/impls.rs @@ -1,2 +1,28 @@ pub(crate) use crate::traits::StyleValue; pub(crate) use hdx_proc_macro::*; + + +#[cfg(test)] +mod tests { + use super::super::*; + use crate::test_helpers::*; + + #[test] + fn size_test() { + assert_size!(Width, 12); + assert_size!(Height, 12); + assert_size!(MinWidth, 12); + assert_size!(MinHeight, 12); + assert_size!(MaxWidth, 12); + assert_size!(MaxHeight, 12); + } + + #[test] + fn test_writes() { + assert_parse!(Width, "0"); + assert_parse!(Width, "1px"); + assert_parse!(Width, "fit-content"); + assert_parse!(Width, "fit-content(20rem)"); + assert_parse!(Width, "fit-content(0)"); + } +} diff --git a/crates/hdx_ast/src/css/values/sizing/mod.rs b/crates/hdx_ast/src/css/values/sizing/mod.rs index ed75f650..21d220df 100644 --- a/crates/hdx_ast/src/css/values/sizing/mod.rs +++ b/crates/hdx_ast/src/css/values/sizing/mod.rs @@ -8,65 +8,77 @@ use impls::*; * CSS Box Sizing Module Level 4 */ -// // https://drafts.csswg.org/css-sizing-4/#width -// #[value(" auto | | min-content | max-content | fit-content() | ")] -// #[initial("auto")] -// #[applies_to("all elements except non-replaced inlines")] -// #[inherited("no")] -// #[percentages("relative to width/height of containing block")] -// #[canonical_order("per grammar")] -// #[animation_type("by computed value type, recursing into fit-content()")] -// pub enum Width {} - -// // https://drafts.csswg.org/css-sizing-4/#height -// #[value(" auto | | min-content | max-content | fit-content() | ")] -// #[initial("auto")] -// #[applies_to("all elements except non-replaced inlines")] -// #[inherited("no")] -// #[percentages("relative to width/height of containing block")] -// #[canonical_order("per grammar")] -// #[animation_type("by computed value type, recursing into fit-content()")] -// pub enum Height {} - -// // https://drafts.csswg.org/css-sizing-4/#min-width -// #[value(" auto | | min-content | max-content | fit-content() | ")] -// #[initial("auto")] -// #[applies_to("all elements that accept width or height")] -// #[inherited("no")] -// #[percentages("relative to width/height of containing block")] -// #[canonical_order("per grammar")] -// #[animation_type("by computed value, recursing into fit-content()")] -// pub enum MinWidth {} - -// // https://drafts.csswg.org/css-sizing-4/#min-height -// #[value(" auto | | min-content | max-content | fit-content() | ")] -// #[initial("auto")] -// #[applies_to("all elements that accept width or height")] -// #[inherited("no")] -// #[percentages("relative to width/height of containing block")] -// #[canonical_order("per grammar")] -// #[animation_type("by computed value, recursing into fit-content()")] -// pub enum MinHeight {} - -// // https://drafts.csswg.org/css-sizing-4/#max-width -// #[value(" none | | min-content | max-content | fit-content() | ")] -// #[initial("none")] -// #[applies_to("all elements that accept width or height")] -// #[inherited("no")] -// #[percentages("relative to width/height of containing block")] -// #[canonical_order("per grammar")] -// #[animation_type("by computed value, recursing into fit-content()")] -// pub enum MaxWidth {} - -// // https://drafts.csswg.org/css-sizing-4/#max-height -// #[value(" none | | min-content | max-content | fit-content() | ")] -// #[initial("none")] -// #[applies_to("all elements that accept width or height")] -// #[inherited("no")] -// #[percentages("relative to width/height of containing block")] -// #[canonical_order("per grammar")] -// #[animation_type("by computed value, recursing into fit-content()")] -// pub enum MaxHeight {} +// https://drafts.csswg.org/css-sizing-3/#width +// https://drafts.csswg.org/css-sizing-4/#sizing-values +// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords +#[value(" auto | | min-content | max-content | fit-content() | | stretch | fit-content | contain ")] +#[initial("auto")] +#[applies_to("all elements except non-replaced inlines")] +#[inherited("no")] +#[percentages("relative to width/height of containing block")] +#[canonical_order("per grammar")] +#[animation_type("by computed value type, recursing into fit-content()")] +pub enum Width {} + +// https://drafts.csswg.org/css-sizing-3/#height +// https://drafts.csswg.org/css-sizing-4/#sizing-values +// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords +#[value(" auto | | min-content | max-content | fit-content() | | stretch | fit-content | contain ")] +#[initial("auto")] +#[applies_to("all elements except non-replaced inlines")] +#[inherited("no")] +#[percentages("relative to width/height of containing block")] +#[canonical_order("per grammar")] +#[animation_type("by computed value type, recursing into fit-content()")] +pub enum Height {} + +// https://drafts.csswg.org/css-sizing-3/#min-width +// https://drafts.csswg.org/css-sizing-4/#sizing-values +// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords +#[value(" auto | | min-content | max-content | fit-content() | | stretch | fit-content | contain ")] +#[initial("auto")] +#[applies_to("all elements that accept width or height")] +#[inherited("no")] +#[percentages("relative to width/height of containing block")] +#[canonical_order("per grammar")] +#[animation_type("by computed value, recursing into fit-content()")] +pub enum MinWidth {} + +// https://drafts.csswg.org/css-sizing-3/#min-height +// https://drafts.csswg.org/css-sizing-4/#sizing-values +// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords +#[value(" auto | | min-content | max-content | fit-content() | | stretch | fit-content | contain ")] +#[initial("auto")] +#[applies_to("all elements that accept width or height")] +#[inherited("no")] +#[percentages("relative to width/height of containing block")] +#[canonical_order("per grammar")] +#[animation_type("by computed value, recursing into fit-content()")] +pub enum MinHeight {} + +// https://drafts.csswg.org/css-sizing-3/#max-width +// https://drafts.csswg.org/css-sizing-4/#sizing-values +// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords +#[value(" none | | min-content | max-content | fit-content() | | stretch | fit-content | contain ")] +#[initial("none")] +#[applies_to("all elements that accept width or height")] +#[inherited("no")] +#[percentages("relative to width/height of containing block")] +#[canonical_order("per grammar")] +#[animation_type("by computed value, recursing into fit-content()")] +pub enum MaxWidth {} + +// https://drafts.csswg.org/css-sizing-3/#max-height +// https://drafts.csswg.org/css-sizing-4/#sizing-values +// XXX: sizing-4 includes new Sizing Values: the stretch, fit-content, and contain keywords +#[value(" none | | min-content | max-content | fit-content() | | stretch | fit-content | contain ")] +#[initial("none")] +#[applies_to("all elements that accept width or height")] +#[inherited("no")] +#[percentages("relative to width/height of containing block")] +#[canonical_order("per grammar")] +#[animation_type("by computed value, recursing into fit-content()")] +pub enum MaxHeight {} // https://drafts.csswg.org/css-sizing-4/#box-sizing #[value(" content-box | border-box ")] diff --git a/crates/hdx_ast/src/css/values/sizing/types.rs b/crates/hdx_ast/src/css/values/sizing/types.rs index 8b137891..8e80c1ae 100644 --- a/crates/hdx_ast/src/css/values/sizing/types.rs +++ b/crates/hdx_ast/src/css/values/sizing/types.rs @@ -1 +1,33 @@ +use hdx_parser::{Parse, Parser, Peek, Result as ParserResult, Token}; +use hdx_writer::{CssWriter, Result as WriterResult, WriteCss}; +pub use crate::css::units::*; + +mod func { + use hdx_parser::custom_function; + custom_function!(CalcSize, atom!("calc-size")); + custom_function!(FitContent, atom!("fit-content")); +} + +#[derive(Debug, PartialEq, Hash, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(serde::Serialize), serde())] +pub struct CalcSize; + +impl<'a> Peek<'a> for CalcSize { + fn peek(parser: &Parser<'a>) -> Option { + parser.peek::() + } +} + +impl<'a> Parse<'a> for CalcSize { + fn parse(parser: &mut Parser<'a>) -> ParserResult { + parser.parse::()?; + todo!(); + } +} + +impl<'a> WriteCss<'a> for CalcSize { + fn write_css(&self, _sink: &mut W) -> WriterResult { + todo!(); + } +} diff --git a/crates/hdx_proc_macro/src/def.rs b/crates/hdx_proc_macro/src/def.rs index 977c0af2..14701ab1 100644 --- a/crates/hdx_proc_macro/src/def.rs +++ b/crates/hdx_proc_macro/src/def.rs @@ -948,6 +948,7 @@ impl GenerateParseImpl for Def { return Err(::hdx_parser::diagnostics::UnexpectedFunction(atom, token.span()))? } #inner + parser.parse::<::hdx_parser::token::RightParen>()?; } } Self::Multiplier( diff --git a/crates/hdx_proc_macro/src/snapshots/hdx_proc_macro__test__custom_function_variant_with_args.snap b/crates/hdx_proc_macro/src/snapshots/hdx_proc_macro__test__custom_function_variant_with_args.snap index 02f9ac58..38dd1c08 100644 --- a/crates/hdx_proc_macro/src/snapshots/hdx_proc_macro__test__custom_function_variant_with_args.snap +++ b/crates/hdx_proc_macro/src/snapshots/hdx_proc_macro__test__custom_function_variant_with_args.snap @@ -48,6 +48,7 @@ impl<'a> ::hdx_parser::Parse<'a> for Foo { ), )?; } + parser.parse::<::hdx_parser::token::RightParen>()?; Ok(Self::FitContentFunction(val)) } }