encre_css/plugins/transform/scale/
mod.rs

1#![doc = include_str!("README.md")]
2#![doc(alias = "transform")]
3use super::CSS_TRANSFORM;
4use crate::prelude::build_plugin::*;
5
6fn scale_can_handle(context: &ContextCanHandle) -> bool {
7    matches!(context.modifier, Modifier::Builtin { value, .. } if value.parse::<usize>().is_ok())
8}
9
10fn scale_handle(css_properties: &[&str], context: &mut ContextHandle) {
11    if let Modifier::Builtin { is_negative, value } = context.modifier {
12        for css_prop in css_properties {
13            #[allow(clippy::cast_precision_loss)]
14            context.buffer.line(format_args!(
15                "{}: {}{};",
16                css_prop,
17                format_negative(is_negative),
18                value.parse::<usize>().unwrap() as f32 / 100.,
19            ));
20        }
21
22        context.buffer.line(CSS_TRANSFORM);
23    }
24}
25
26#[derive(Debug)]
27pub(crate) struct PluginDefinition;
28
29impl Plugin for PluginDefinition {
30    fn can_handle(&self, context: ContextCanHandle) -> bool {
31        scale_can_handle(&context)
32    }
33
34    fn handle(&self, context: &mut ContextHandle) {
35        scale_handle(&["--en-scale-x", "--en-scale-y"], context);
36    }
37}
38
39#[derive(Debug)]
40pub(crate) struct PluginXDefinition;
41
42impl Plugin for PluginXDefinition {
43    fn can_handle(&self, context: ContextCanHandle) -> bool {
44        scale_can_handle(&context)
45    }
46
47    fn handle(&self, context: &mut ContextHandle) {
48        scale_handle(&["--en-scale-x"], context);
49    }
50}
51
52#[derive(Debug)]
53pub(crate) struct PluginYDefinition;
54
55impl Plugin for PluginYDefinition {
56    fn can_handle(&self, context: ContextCanHandle) -> bool {
57        scale_can_handle(&context)
58    }
59
60    fn handle(&self, context: &mut ContextHandle) {
61        scale_handle(&["--en-scale-y"], context);
62    }
63}