encre_css/plugins/sizing/max_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 || [
16 "xs",
17 "sm",
18 "md",
19 "lg",
20 "xl",
21 "2xl",
22 "3xl",
23 "4xl",
24 "5xl",
25 "6xl",
26 "7xl",
27 "full",
28 "min",
29 "max",
30 "fit",
31 "prose",
32 "screen",
33 "screen-sm",
34 "screen-md",
35 "screen-lg",
36 "screen-lg",
37 "screen-xl",
38 "screen-2xl",
39 "none",
40 ]
41 .contains(&&**value)
42 }
43 Modifier::Arbitrary { value, .. } => {
44 is_matching_length(value) || is_matching_percentage(value)
45 }
46 }
47 }
48
49 fn handle(&self, context: &mut ContextHandle) {
50 match context.modifier {
51 Modifier::Builtin { is_negative, value } => context.buffer.line(format_args!(
52 "max-width: {};",
53 match *value {
54 "none" => Cow::Borrowed("none"),
55 "xs" => Cow::Borrowed("20rem"),
56 "sm" => Cow::Borrowed("24rem"),
57 "md" => Cow::Borrowed("28rem"),
58 "lg" => Cow::Borrowed("32rem"),
59 "xl" => Cow::Borrowed("36rem"),
60 "2xl" => Cow::Borrowed("42rem"),
61 "3xl" => Cow::Borrowed("48rem"),
62 "4xl" => Cow::Borrowed("56rem"),
63 "5xl" => Cow::Borrowed("64rem"),
64 "6xl" => Cow::Borrowed("72rem"),
65 "7xl" => Cow::Borrowed("80rem"),
66 "full" => Cow::Borrowed("100%"),
67 "min" => Cow::Borrowed("min-content"),
68 "max" => Cow::Borrowed("max-content"),
69 "fit" => Cow::Borrowed("fit-content"),
70 "prose" => Cow::Borrowed("65ch"),
71 "screen" => Cow::Borrowed("100vw"),
72 "screen-sm" => Cow::Borrowed("640px"),
73 "screen-md" => Cow::Borrowed("768px"),
74 "screen-lg" => Cow::Borrowed("1024px"),
75 "screen-xl" => Cow::Borrowed("1280px"),
76 "screen-2xl" => Cow::Borrowed("1536px"),
77 _ => spacing::get(value, *is_negative).unwrap(),
78 }
79 )),
80 Modifier::Arbitrary { value, .. } => {
81 context.buffer.line(format_args!("max-width: {value};"));
82 }
83 }
84 }
85}