encre_css/plugins/typography/letter_spacing/
mod.rs1#![doc = include_str!("README.md")]
2#![doc(alias = "typography")]
3use crate::prelude::build_plugin::*;
4
5#[derive(Debug)]
6pub(crate) struct PluginDefinition;
7
8impl Plugin for PluginDefinition {
9 fn can_handle(&self, context: ContextCanHandle) -> bool {
10 match context.modifier {
11 Modifier::Builtin { value, .. } => {
12 ["tighter", "tight", "normal", "wide", "wider", "widest"].contains(&&**value)
13 }
14 Modifier::Arbitrary { value, .. } => *value == "normal" || is_matching_length(value),
15 }
16 }
17
18 fn handle(&self, context: &mut ContextHandle) {
19 match context.modifier {
20 Modifier::Builtin { value, .. } => context.buffer.line(format_args!(
21 "letter-spacing: {};",
22 match *value {
23 "tighter" => "-0.05em",
24 "tight" => "-0.025em",
25 "normal" => "0",
26 "wide" => "0.025em",
27 "wider" => "0.05em",
28 "widest" => "0.1em",
29 _ => unreachable!(),
30 }
31 )),
32 Modifier::Arbitrary { value, .. } => {
33 context
34 .buffer
35 .line(format_args!("letter-spacing: {value};"));
36 }
37 }
38 }
39}