encre_css/plugins/transform/skew/
mod.rs

1#![doc = include_str!("README.md")]
2#![doc(alias = "transform")]
3use super::CSS_TRANSFORM;
4use crate::prelude::build_plugin::*;
5
6fn skew_can_handle(context: &ContextCanHandle) -> bool {
7    match context.modifier {
8        Modifier::Builtin { value, .. } => value.parse::<usize>().is_ok_and(|v| v <= 360),
9        Modifier::Arbitrary { value, .. } => is_matching_angle(value),
10    }
11}
12
13fn skew_handle(css_prop: &str, context: &mut ContextHandle) {
14    match context.modifier {
15        Modifier::Builtin { is_negative, value } => context.buffer.line(format_args!(
16            "{}: {}{value}deg;",
17            css_prop,
18            format_negative(is_negative),
19        )),
20        Modifier::Arbitrary { value, .. } => {
21            context.buffer.line(format_args!("{css_prop}: {value};"));
22        }
23    }
24
25    context.buffer.line(CSS_TRANSFORM);
26}
27
28#[derive(Debug)]
29pub(crate) struct PluginXDefinition;
30
31impl Plugin for PluginXDefinition {
32    fn can_handle(&self, context: ContextCanHandle) -> bool {
33        skew_can_handle(&context)
34    }
35
36    fn handle(&self, context: &mut ContextHandle) {
37        skew_handle("--en-skew-x", context);
38    }
39}
40
41#[derive(Debug)]
42pub(crate) struct PluginYDefinition;
43
44impl Plugin for PluginYDefinition {
45    fn can_handle(&self, context: ContextCanHandle) -> bool {
46        skew_can_handle(&context)
47    }
48
49    fn handle(&self, context: &mut ContextHandle) {
50        skew_handle("--en-skew-y", context);
51    }
52}