encre_css/plugins/sizing/max_height/
mod.rs

1#![doc = include_str!("README.md")]
2#![doc(alias("sizing", "size"))]
3use crate::prelude::build_plugin::*;
4
5use std::borrow::Cow;
6
7#[derive(Debug)]
8pub(crate) struct PluginDefinition;
9
10impl Plugin for PluginDefinition {
11    fn can_handle(&self, context: ContextCanHandle) -> bool {
12        match context.modifier {
13            Modifier::Builtin { value, .. } => {
14                spacing::is_matching_builtin_spacing(value)
15                    || ["none", "full", "screen", "min", "max", "fit", "auto", "svh", "lvh", "dvh"].contains(value)
16            }
17            Modifier::Arbitrary { value, .. } => {
18                is_matching_length(value) || is_matching_percentage(value)
19            }
20        }
21    }
22
23    fn handle(&self, context: &mut ContextHandle) {
24        match context.modifier {
25            Modifier::Builtin { is_negative, value } => context.buffer.line(format_args!(
26                "max-height: {};",
27                match *value {
28                    "none" => Cow::Borrowed("none"),
29                    "auto" => Cow::Borrowed("auto"),
30                    "full" => Cow::Borrowed("100%"),
31                    "screen" => Cow::Borrowed("100vh"),
32                    "min" => Cow::Borrowed("min-content"),
33                    "max" => Cow::Borrowed("max-content"),
34                    "fit" => Cow::Borrowed("fit-content"),
35                    "svh" => Cow::Borrowed("100svh"),
36                    "lvh" => Cow::Borrowed("100lvh"),
37                    "dvh" => Cow::Borrowed("100dvh"),
38                    _ => spacing::get(value, *is_negative).unwrap(),
39                }
40            )),
41            Modifier::Arbitrary { value, .. } => {
42                context.buffer.line(format_args!("max-height: {value};"));
43            }
44        }
45    }
46}