encre_css/plugins/sizing/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                    || ["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 } => {
26                context.buffer.line(format_args!(
27                    "height: {};",
28                    match *value {
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            }
42            Modifier::Arbitrary { value, .. } => {
43                context.buffer.line(format_args!("height: {value};"));
44            }
45        }
46    }
47}