encre_css/plugins/sizing/min_width/
mod.rs1#![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"].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 "min-width: {};",
28 match *value {
29 "auto" => Cow::Borrowed("auto"),
30 "full" => Cow::Borrowed("100%"),
31 "screen" => Cow::Borrowed("100vw"),
32 "min" => Cow::Borrowed("min-content"),
33 "max" => Cow::Borrowed("max-content"),
34 "fit" => Cow::Borrowed("fit-content"),
35 _ => spacing::get(value, *is_negative).unwrap(),
36 },
37 ));
38 }
39 Modifier::Arbitrary { value, .. } => {
40 context.buffer.line(format_args!("min-width: {value};"));
41 }
42 }
43 }
44}