encre_css/plugins/flexbox/flex_basis/
mod.rs

1#![doc = include_str!("README.md")]
2#![doc(alias = "flexbox")]
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) || *value == "full" || *value == "auto"
15            }
16            Modifier::Arbitrary { value, .. } => is_matching_length(value),
17        }
18    }
19
20    fn handle(&self, context: &mut ContextHandle) {
21        match context.modifier {
22            Modifier::Builtin { is_negative, value } => context.buffer.line(format_args!(
23                "flex-basis: {};",
24                if *value == "auto" {
25                    Cow::from("auto")
26                } else if *value == "full" && *is_negative {
27                    Cow::from("-100%")
28                } else if *value == "full" {
29                    Cow::from("100%")
30                } else {
31                    spacing::get(value, *is_negative).unwrap()
32                },
33            )),
34            Modifier::Arbitrary { value, .. } => {
35                context.buffer.line(format_args!("flex-basis: {value};"));
36            }
37        }
38    }
39}