Skip to main content

rspack_lightningcss/properties/
size.rs

1//! CSS properties related to box sizing.
2
3use crate::compat::Feature;
4use crate::context::PropertyHandlerContext;
5use crate::declaration::DeclarationList;
6use crate::error::{ParserError, PrinterError};
7use crate::logical::PropertyCategory;
8use crate::macros::{enum_property, property_bitflags};
9use crate::properties::{Property, PropertyId};
10use crate::targets::Targets;
11use crate::traits::{IsCompatible, Parse, PropertyHandler, ToCss};
12use crate::values::length::LengthPercentage;
13use crate::values::number::NonNegative;
14use crate::values::ratio::Ratio;
15use crate::vendor_prefix::VendorPrefix;
16#[cfg(feature = "visitor")]
17use crate::visitor::Visit;
18use cssparser::*;
19
20#[cfg(feature = "serde")]
21use crate::serialization::*;
22
23// https://drafts.csswg.org/css-sizing-3/#specifying-sizes
24// https://www.w3.org/TR/css-sizing-4/#sizing-values
25
26/// A value for the [preferred size properties](https://drafts.csswg.org/css-sizing-3/#preferred-size-properties),
27/// i.e. `width` and `height.
28#[derive(Debug, Clone, PartialEq)]
29#[cfg_attr(feature = "visitor", derive(Visit))]
30#[cfg_attr(
31  feature = "serde",
32  derive(serde::Serialize, serde::Deserialize),
33  serde(tag = "type", rename_all = "kebab-case")
34)]
35#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
36#[cfg_attr(feature = "into_owned", derive(rspack_lightningcss_static_self::IntoOwned))]
37pub enum Size {
38  /// The `auto` keyword.
39  Auto,
40  /// An explicit length or percentage.
41  #[cfg_attr(feature = "serde", serde(with = "ValueWrapper::<NonNegative<LengthPercentage>>"))]
42  LengthPercentage(NonNegative<LengthPercentage>),
43  /// The `min-content` keyword.
44  #[cfg_attr(feature = "serde", serde(with = "PrefixWrapper"))]
45  MinContent(VendorPrefix),
46  /// The `max-content` keyword.
47  #[cfg_attr(feature = "serde", serde(with = "PrefixWrapper"))]
48  MaxContent(VendorPrefix),
49  /// The `fit-content` keyword.
50  #[cfg_attr(feature = "serde", serde(with = "PrefixWrapper"))]
51  FitContent(VendorPrefix),
52  /// The `fit-content()` function.
53  #[cfg_attr(feature = "serde", serde(with = "ValueWrapper::<NonNegative<LengthPercentage>>"))]
54  FitContentFunction(NonNegative<LengthPercentage>),
55  /// The `stretch` keyword, or the `-webkit-fill-available` or `-moz-available` prefixed keywords.
56  #[cfg_attr(feature = "serde", serde(with = "PrefixWrapper"))]
57  Stretch(VendorPrefix),
58  /// The `contain` keyword.
59  Contain,
60}
61
62impl<'i> Parse<'i> for Size {
63  fn parse<'t>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i, ParserError<'i>>> {
64    let res = input.try_parse(|input| {
65      let ident = input.expect_ident()?;
66      Ok(match_ignore_ascii_case! { &*ident,
67        "auto" => Size::Auto,
68        "min-content" => Size::MinContent(VendorPrefix::None),
69        "-webkit-min-content" => Size::MinContent(VendorPrefix::WebKit),
70        "-moz-min-content" => Size::MinContent(VendorPrefix::Moz),
71        "max-content" => Size::MaxContent(VendorPrefix::None),
72        "-webkit-max-content" => Size::MaxContent(VendorPrefix::WebKit),
73        "-moz-max-content" => Size::MaxContent(VendorPrefix::Moz),
74        "stretch" => Size::Stretch(VendorPrefix::None),
75        "-webkit-fill-available" => Size::Stretch(VendorPrefix::WebKit),
76        "-moz-available" => Size::Stretch(VendorPrefix::Moz),
77        "fit-content" => Size::FitContent(VendorPrefix::None),
78        "-webkit-fit-content" => Size::FitContent(VendorPrefix::WebKit),
79        "-moz-fit-content" => Size::FitContent(VendorPrefix::Moz),
80        "contain" => Size::Contain,
81        _ => return Err(input.new_custom_error(ParserError::InvalidValue))
82      })
83    });
84
85    if res.is_ok() {
86      return res;
87    }
88
89    if let Ok(res) = input.try_parse(parse_fit_content) {
90      return Ok(Size::FitContentFunction(res));
91    }
92
93    let lp = input.try_parse(NonNegative::<LengthPercentage>::parse)?;
94    Ok(Size::LengthPercentage(lp))
95  }
96}
97
98impl ToCss for Size {
99  fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
100    use Size::*;
101    match self {
102      Auto => {
103        dest.write_str("auto")?;
104        Ok(())
105      }
106      Contain => {
107        dest.write_str("contain")?;
108        Ok(())
109      }
110      MinContent(vp) => {
111        vp.to_css(dest)?;
112        dest.write_str("min-content")?;
113        Ok(())
114      }
115      MaxContent(vp) => {
116        vp.to_css(dest)?;
117        dest.write_str("max-content")?;
118        Ok(())
119      }
120      FitContent(vp) => {
121        vp.to_css(dest)?;
122        dest.write_str("fit-content")?;
123        Ok(())
124      }
125      Stretch(vp) => match *vp {
126        VendorPrefix::None => {
127          dest.write_str("stretch")?;
128          Ok(())
129        }
130        VendorPrefix::WebKit => {
131          dest.write_str("-webkit-fill-available")?;
132          Ok(())
133        }
134        VendorPrefix::Moz => {
135          dest.write_str("-moz-available")?;
136          Ok(())
137        }
138        _ => unreachable!(),
139      },
140      FitContentFunction(l) => {
141        dest.write_str("fit-content(")?;
142        l.to_css(dest)?;
143        dest.write_str(")")?;
144        Ok(())
145      }
146      LengthPercentage(l) => l.to_css(dest),
147    }
148  }
149}
150
151impl IsCompatible for Size {
152  fn is_compatible(&self, browsers: crate::targets::Browsers) -> bool {
153    use Size::*;
154    match self {
155      LengthPercentage(l) => l.is_compatible(browsers),
156      MinContent(..) => Feature::MinContentSize.is_compatible(browsers),
157      MaxContent(..) => Feature::MaxContentSize.is_compatible(browsers),
158      FitContent(..) => Feature::FitContentSize.is_compatible(browsers),
159      FitContentFunction(l) => {
160        Feature::FitContentFunctionSize.is_compatible(browsers) && l.is_compatible(browsers)
161      }
162      Stretch(vp) => match *vp {
163        VendorPrefix::None => Feature::StretchSize,
164        VendorPrefix::WebKit | VendorPrefix::Moz => Feature::WebkitFillAvailableSize,
165        _ => return false,
166      }
167      .is_compatible(browsers),
168      Contain => false, // ??? no data in mdn
169      Auto => true,
170    }
171  }
172}
173
174/// A value for the [minimum](https://drafts.csswg.org/css-sizing-3/#min-size-properties)
175/// and [maximum](https://drafts.csswg.org/css-sizing-3/#max-size-properties) size properties,
176/// e.g. `min-width` and `max-height`.
177#[derive(Debug, Clone, PartialEq)]
178#[cfg_attr(feature = "visitor", derive(Visit))]
179#[cfg_attr(
180  feature = "serde",
181  derive(serde::Serialize, serde::Deserialize),
182  serde(tag = "type", rename_all = "kebab-case")
183)]
184#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
185#[cfg_attr(feature = "into_owned", derive(rspack_lightningcss_static_self::IntoOwned))]
186pub enum MaxSize {
187  /// The `none` keyword.
188  None,
189  /// An explicit length or percentage.
190  #[cfg_attr(feature = "serde", serde(with = "ValueWrapper::<NonNegative<LengthPercentage>>"))]
191  LengthPercentage(NonNegative<LengthPercentage>),
192  /// The `min-content` keyword.
193  #[cfg_attr(feature = "serde", serde(with = "PrefixWrapper"))]
194  MinContent(VendorPrefix),
195  /// The `max-content` keyword.
196  #[cfg_attr(feature = "serde", serde(with = "PrefixWrapper"))]
197  MaxContent(VendorPrefix),
198  /// The `fit-content` keyword.
199  #[cfg_attr(feature = "serde", serde(with = "PrefixWrapper"))]
200  FitContent(VendorPrefix),
201  /// The `fit-content()` function.
202  #[cfg_attr(feature = "serde", serde(with = "ValueWrapper::<NonNegative<LengthPercentage>>"))]
203  FitContentFunction(NonNegative<LengthPercentage>),
204  /// The `stretch` keyword, or the `-webkit-fill-available` or `-moz-available` prefixed keywords.
205  #[cfg_attr(feature = "serde", serde(with = "PrefixWrapper"))]
206  Stretch(VendorPrefix),
207  /// The `contain` keyword.
208  Contain,
209}
210
211impl<'i> Parse<'i> for MaxSize {
212  fn parse<'t>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i, ParserError<'i>>> {
213    let res = input.try_parse(|input| {
214      let ident = input.expect_ident()?;
215      Ok(match_ignore_ascii_case! { &*ident,
216        "none" => MaxSize::None,
217        "min-content" => MaxSize::MinContent(VendorPrefix::None),
218        "-webkit-min-content" => MaxSize::MinContent(VendorPrefix::WebKit),
219        "-moz-min-content" => MaxSize::MinContent(VendorPrefix::Moz),
220        "max-content" => MaxSize::MaxContent(VendorPrefix::None),
221        "-webkit-max-content" => MaxSize::MaxContent(VendorPrefix::WebKit),
222        "-moz-max-content" => MaxSize::MaxContent(VendorPrefix::Moz),
223        "stretch" => MaxSize::Stretch(VendorPrefix::None),
224        "-webkit-fill-available" => MaxSize::Stretch(VendorPrefix::WebKit),
225        "-moz-available" => MaxSize::Stretch(VendorPrefix::Moz),
226        "fit-content" => MaxSize::FitContent(VendorPrefix::None),
227        "-webkit-fit-content" => MaxSize::FitContent(VendorPrefix::WebKit),
228        "-moz-fit-content" => MaxSize::FitContent(VendorPrefix::Moz),
229        "contain" => MaxSize::Contain,
230        _ => return Err(input.new_custom_error(ParserError::InvalidValue))
231      })
232    });
233
234    if res.is_ok() {
235      return res;
236    }
237
238    if let Ok(res) = input.try_parse(parse_fit_content) {
239      return Ok(MaxSize::FitContentFunction(res));
240    }
241
242    let lp = input.try_parse(NonNegative::<LengthPercentage>::parse)?;
243    Ok(MaxSize::LengthPercentage(lp))
244  }
245}
246
247impl ToCss for MaxSize {
248  fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
249    use MaxSize::*;
250    match self {
251      None => {
252        dest.write_str("none")?;
253        Ok(())
254      }
255      Contain => {
256        dest.write_str("contain")?;
257        Ok(())
258      }
259      MinContent(vp) => {
260        vp.to_css(dest)?;
261        dest.write_str("min-content")?;
262        Ok(())
263      }
264      MaxContent(vp) => {
265        vp.to_css(dest)?;
266        dest.write_str("max-content")?;
267        Ok(())
268      }
269      FitContent(vp) => {
270        vp.to_css(dest)?;
271        dest.write_str("fit-content")?;
272        Ok(())
273      }
274      Stretch(vp) => match *vp {
275        VendorPrefix::None => {
276          dest.write_str("stretch")?;
277          Ok(())
278        }
279        VendorPrefix::WebKit => {
280          dest.write_str("-webkit-fill-available")?;
281          Ok(())
282        }
283        VendorPrefix::Moz => {
284          dest.write_str("-moz-available")?;
285          Ok(())
286        }
287        _ => unreachable!(),
288      },
289      FitContentFunction(l) => {
290        dest.write_str("fit-content(")?;
291        l.to_css(dest)?;
292        dest.write_str(")")?;
293        Ok(())
294      }
295      LengthPercentage(l) => l.to_css(dest),
296    }
297  }
298}
299
300impl IsCompatible for MaxSize {
301  fn is_compatible(&self, browsers: crate::targets::Browsers) -> bool {
302    use MaxSize::*;
303    match self {
304      LengthPercentage(l) => l.is_compatible(browsers),
305      MinContent(..) => Feature::MinContentSize.is_compatible(browsers),
306      MaxContent(..) => Feature::MaxContentSize.is_compatible(browsers),
307      FitContent(..) => Feature::FitContentSize.is_compatible(browsers),
308      FitContentFunction(l) => {
309        Feature::FitContentFunctionSize.is_compatible(browsers) && l.is_compatible(browsers)
310      }
311      Stretch(vp) => match *vp {
312        VendorPrefix::None => Feature::StretchSize,
313        VendorPrefix::WebKit | VendorPrefix::Moz => Feature::WebkitFillAvailableSize,
314        _ => return false,
315      }
316      .is_compatible(browsers),
317      Contain => false, // ??? no data in mdn
318      None => true,
319    }
320  }
321}
322
323// Keep prefix generation out of each property arm to avoid duplicating it in `flush`.
324#[derive(Clone, Copy)]
325enum SizeFallback {
326  Stretch,
327  MinContent,
328  MaxContent,
329  FitContent,
330}
331
332impl SizeFallback {
333  #[inline(never)]
334  fn prefixes(self, targets: Targets) -> VendorPrefix {
335    let feature = match self {
336      SizeFallback::Stretch => crate::prefixes::Feature::Stretch,
337      SizeFallback::MinContent => crate::prefixes::Feature::MinContent,
338      SizeFallback::MaxContent => crate::prefixes::Feature::MaxContent,
339      SizeFallback::FitContent => crate::prefixes::Feature::FitContent,
340    };
341    let prefixes = targets.prefixes(VendorPrefix::None, feature) - VendorPrefix::None;
342    match self {
343      // Only -webkit-fill-available and -moz-available exist, so drop any
344      // other prefix (e.g. from `include: Features::VendorPrefixes`).
345      SizeFallback::Stretch => prefixes & (VendorPrefix::WebKit | VendorPrefix::Moz),
346      _ => prefixes,
347    }
348  }
349
350  #[inline(never)]
351  fn size(self, prefix: VendorPrefix) -> Size {
352    match self {
353      SizeFallback::Stretch => Size::Stretch(prefix),
354      SizeFallback::MinContent => Size::MinContent(prefix),
355      SizeFallback::MaxContent => Size::MaxContent(prefix),
356      SizeFallback::FitContent => Size::FitContent(prefix),
357    }
358  }
359
360  #[inline(never)]
361  fn max_size(self, prefix: VendorPrefix) -> MaxSize {
362    match self {
363      SizeFallback::Stretch => MaxSize::Stretch(prefix),
364      SizeFallback::MinContent => MaxSize::MinContent(prefix),
365      SizeFallback::MaxContent => MaxSize::MaxContent(prefix),
366      SizeFallback::FitContent => MaxSize::FitContent(prefix),
367    }
368  }
369}
370
371#[inline(never)]
372fn size_fallback(value: &Size) -> Option<SizeFallback> {
373  match value {
374    Size::Stretch(VendorPrefix::None) => Some(SizeFallback::Stretch),
375    Size::MinContent(VendorPrefix::None) => Some(SizeFallback::MinContent),
376    Size::MaxContent(VendorPrefix::None) => Some(SizeFallback::MaxContent),
377    Size::FitContent(VendorPrefix::None) => Some(SizeFallback::FitContent),
378    _ => None,
379  }
380}
381
382#[inline(never)]
383fn max_size_fallback(value: &MaxSize) -> Option<SizeFallback> {
384  match value {
385    MaxSize::Stretch(VendorPrefix::None) => Some(SizeFallback::Stretch),
386    MaxSize::MinContent(VendorPrefix::None) => Some(SizeFallback::MinContent),
387    MaxSize::MaxContent(VendorPrefix::None) => Some(SizeFallback::MaxContent),
388    MaxSize::FitContent(VendorPrefix::None) => Some(SizeFallback::FitContent),
389    _ => None,
390  }
391}
392
393fn parse_fit_content<'i, 't>(
394  input: &mut Parser<'i, 't>,
395) -> Result<NonNegative<LengthPercentage>, ParseError<'i, ParserError<'i>>> {
396  input.expect_function_matching("fit-content")?;
397  input.parse_nested_block(|input| NonNegative::<LengthPercentage>::parse(input))
398}
399
400enum_property! {
401  /// A value for the [box-sizing](https://drafts.csswg.org/css-sizing-3/#box-sizing) property.
402  pub enum BoxSizing {
403    /// Exclude the margin/border/padding from the width and height.
404    ContentBox,
405    /// Include the padding and border (but not the margin) in the width and height.
406    BorderBox,
407  }
408}
409
410/// A value for the [aspect-ratio](https://drafts.csswg.org/css-sizing-4/#aspect-ratio) property.
411#[derive(Debug, Clone, PartialEq)]
412#[cfg_attr(feature = "visitor", derive(Visit))]
413#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
414#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
415#[cfg_attr(feature = "into_owned", derive(rspack_lightningcss_static_self::IntoOwned))]
416pub struct AspectRatio {
417  /// The `auto` keyword.
418  pub auto: bool,
419  /// A preferred aspect ratio for the box, specified as width / height.
420  pub ratio: Option<Ratio>,
421}
422
423impl<'i> Parse<'i> for AspectRatio {
424  fn parse<'t>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i, ParserError<'i>>> {
425    let location = input.current_source_location();
426    let mut auto = input.try_parse(|i| i.expect_ident_matching("auto"));
427    let ratio = input.try_parse(Ratio::parse);
428    if auto.is_err() {
429      auto = input.try_parse(|i| i.expect_ident_matching("auto"));
430    }
431    if auto.is_err() && ratio.is_err() {
432      return Err(location.new_custom_error(ParserError::InvalidValue));
433    }
434
435    Ok(AspectRatio {
436      auto: auto.is_ok(),
437      ratio: ratio.ok(),
438    })
439  }
440}
441
442impl ToCss for AspectRatio {
443  fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
444    if self.auto {
445      dest.write_str("auto")?;
446    }
447
448    if let Some(ratio) = &self.ratio {
449      if self.auto {
450        dest.write_char(' ')?;
451      }
452      ratio.to_css(dest)?;
453    }
454
455    Ok(())
456  }
457}
458
459property_bitflags! {
460  #[derive(Default)]
461  struct SizeProperty: u16 {
462    const Width = 1 << 0;
463    const Height = 1 << 1;
464    const MinWidth = 1 << 2;
465    const MinHeight = 1 << 3;
466    const MaxWidth = 1 << 4;
467    const MaxHeight = 1 << 5;
468    const BlockSize = 1 << 6;
469    const InlineSize = 1 << 7;
470    const MinBlockSize  = 1 << 8;
471    const MinInlineSize = 1 << 9;
472    const MaxBlockSize = 1 << 10;
473    const MaxInlineSize = 1 << 11;
474  }
475}
476
477#[derive(Default)]
478pub(crate) struct SizeHandler {
479  width: Option<Size>,
480  height: Option<Size>,
481  min_width: Option<Size>,
482  min_height: Option<Size>,
483  max_width: Option<MaxSize>,
484  max_height: Option<MaxSize>,
485  block_size: Option<Size>,
486  inline_size: Option<Size>,
487  min_block_size: Option<Size>,
488  min_inline_size: Option<Size>,
489  max_block_size: Option<MaxSize>,
490  max_inline_size: Option<MaxSize>,
491  has_any: bool,
492  flushed_properties: SizeProperty,
493  category: PropertyCategory,
494}
495
496impl<'i> PropertyHandler<'i> for SizeHandler {
497  fn handle_property(
498    &mut self,
499    property: &Property<'i>,
500    dest: &mut DeclarationList<'i>,
501    context: &mut PropertyHandlerContext<'i, '_>,
502  ) -> bool {
503    let logical_supported = !context.should_compile_logical(Feature::LogicalSize);
504
505    macro_rules! property {
506      ($prop: ident, $val: ident, $category: ident) => {{
507        // If the category changes betweet logical and physical,
508        // or if the value contains syntax that isn't supported across all targets,
509        // preserve the previous value as a fallback.
510        if PropertyCategory::$category != self.category || (self.$prop.is_some() && matches!(context.targets.browsers, Some(targets) if !$val.is_compatible(targets))) {
511          self.flush(dest, context);
512        }
513
514        self.$prop = Some($val.clone());
515        self.category = PropertyCategory::$category;
516        self.has_any = true;
517      }};
518    }
519
520    match property {
521      Property::Width(v) => property!(width, v, Physical),
522      Property::Height(v) => property!(height, v, Physical),
523      Property::MinWidth(v) => property!(min_width, v, Physical),
524      Property::MinHeight(v) => property!(min_height, v, Physical),
525      Property::MaxWidth(v) => property!(max_width, v, Physical),
526      Property::MaxHeight(v) => property!(max_height, v, Physical),
527      Property::BlockSize(size) => property!(block_size, size, Logical),
528      Property::MinBlockSize(size) => property!(min_block_size, size, Logical),
529      Property::MaxBlockSize(size) => property!(max_block_size, size, Logical),
530      Property::InlineSize(size) => property!(inline_size, size, Logical),
531      Property::MinInlineSize(size) => property!(min_inline_size, size, Logical),
532      Property::MaxInlineSize(size) => property!(max_inline_size, size, Logical),
533      Property::Unparsed(unparsed) => {
534        self.flush(dest, context);
535        macro_rules! logical_unparsed {
536          ($physical: ident) => {
537            if logical_supported {
538              self
539                .flushed_properties
540                .insert(SizeProperty::try_from(&unparsed.property_id).unwrap());
541              dest.push(property.clone());
542            } else {
543              dest.push(Property::Unparsed(
544                unparsed.with_property_id(PropertyId::$physical),
545              ));
546              self.flushed_properties.insert(SizeProperty::$physical);
547            }
548          };
549        }
550
551        match &unparsed.property_id {
552          PropertyId::Width
553          | PropertyId::Height
554          | PropertyId::MinWidth
555          | PropertyId::MaxWidth
556          | PropertyId::MinHeight
557          | PropertyId::MaxHeight => {
558            self
559              .flushed_properties
560              .insert(SizeProperty::try_from(&unparsed.property_id).unwrap());
561            dest.push(property.clone());
562          }
563          PropertyId::BlockSize => logical_unparsed!(Height),
564          PropertyId::MinBlockSize => logical_unparsed!(MinHeight),
565          PropertyId::MaxBlockSize => logical_unparsed!(MaxHeight),
566          PropertyId::InlineSize => logical_unparsed!(Width),
567          PropertyId::MinInlineSize => logical_unparsed!(MinWidth),
568          PropertyId::MaxInlineSize => logical_unparsed!(MaxWidth),
569          _ => return false,
570        }
571      }
572      _ => return false,
573    }
574
575    true
576  }
577
578  fn finalize(&mut self, dest: &mut DeclarationList, context: &mut PropertyHandlerContext<'i, '_>) {
579    self.flush(dest, context);
580    self.flushed_properties = SizeProperty::empty();
581  }
582}
583
584impl SizeHandler {
585  fn flush<'i>(&mut self, dest: &mut DeclarationList, context: &mut PropertyHandlerContext<'i, '_>) {
586    if !self.has_any {
587      return;
588    }
589
590    self.has_any = false;
591    let logical_supported = !context.should_compile_logical(Feature::LogicalSize);
592
593    macro_rules! property {
594      ($prop: ident, $val: ident, $fallback: ident, $constructor: ident) => {{
595        if let Some(val) = std::mem::take(&mut self.$val) {
596          if !self.flushed_properties.contains(SizeProperty::$prop) {
597            if let Some(fallback) = $fallback(&val) {
598              for prefix in fallback.prefixes(context.targets) {
599                dest.push(Property::$prop(fallback.$constructor(prefix)));
600              }
601            }
602          }
603          dest.push(Property::$prop(val));
604          self.flushed_properties.insert(SizeProperty::$prop);
605        }
606      }};
607    }
608
609    macro_rules! logical {
610      ($prop: ident, $val: ident, $physical: ident, $fallback: ident, $constructor: ident) => {
611        if logical_supported {
612          property!($prop, $val, $fallback, $constructor);
613        } else {
614          property!($physical, $val, $fallback, $constructor);
615        }
616      };
617    }
618
619    property!(Width, width, size_fallback, size);
620    property!(MinWidth, min_width, size_fallback, size);
621    property!(MaxWidth, max_width, max_size_fallback, max_size);
622    property!(Height, height, size_fallback, size);
623    property!(MinHeight, min_height, size_fallback, size);
624    property!(MaxHeight, max_height, max_size_fallback, max_size);
625    logical!(BlockSize, block_size, Height, size_fallback, size);
626    logical!(MinBlockSize, min_block_size, MinHeight, size_fallback, size);
627    logical!(MaxBlockSize, max_block_size, MaxHeight, max_size_fallback, max_size);
628    logical!(InlineSize, inline_size, Width, size_fallback, size);
629    logical!(MinInlineSize, min_inline_size, MinWidth, size_fallback, size);
630    logical!(MaxInlineSize, max_inline_size, MaxWidth, max_size_fallback, max_size);
631  }
632}