encre_css/plugins/transform/rotate/
mod.rs1#![doc = include_str!("README.md")]
2#![doc(alias = "transform")]
3use super::CSS_TRANSFORM;
4use crate::prelude::build_plugin::*;
5
6fn rotate_can_handle(context: &ContextCanHandle) -> bool {
7 match context.modifier {
8 Modifier::Builtin { value, .. } => value.parse::<usize>().is_ok(),
9 Modifier::Arbitrary { value, .. } => is_matching_angle(value),
10 }
11}
12
13fn rotate_handle(css_properties: &[&str], context: &mut ContextHandle) {
14 match context.modifier {
15 Modifier::Builtin { is_negative, value } => {
16 for css_prop in css_properties {
17 context.buffer.line(format_args!(
18 "{}: {}{}deg;",
19 css_prop,
20 format_negative(is_negative),
21 value.parse::<usize>().unwrap(),
22 ));
23 }
24 }
25 Modifier::Arbitrary { value, .. } => {
26 for css_prop in css_properties {
27 context
28 .buffer
29 .line(format_args!("{css_prop}: {value};"));
30 }
31 }
32 }
33
34 context.buffer.line(CSS_TRANSFORM);
35}
36
37#[derive(Debug)]
38pub(crate) struct PluginDefinition;
39
40impl Plugin for PluginDefinition {
41 fn can_handle(&self, context: ContextCanHandle) -> bool {
42 rotate_can_handle(&context)
43 }
44
45 fn handle(&self, context: &mut ContextHandle) {
46 rotate_handle(&["--en-rotate-x", "--en-rotate-y"], context);
47 }
48}
49
50#[derive(Debug)]
51pub(crate) struct PluginXDefinition;
52
53impl Plugin for PluginXDefinition {
54 fn can_handle(&self, context: ContextCanHandle) -> bool {
55 rotate_can_handle(&context)
56 }
57
58 fn handle(&self, context: &mut ContextHandle) {
59 rotate_handle(&["--en-rotate-x"], context);
60 }
61}
62
63#[derive(Debug)]
64pub(crate) struct PluginYDefinition;
65
66impl Plugin for PluginYDefinition {
67 fn can_handle(&self, context: ContextCanHandle) -> bool {
68 rotate_can_handle(&context)
69 }
70
71 fn handle(&self, context: &mut ContextHandle) {
72 rotate_handle(&["--en-rotate-y"], context);
73 }
74}
75
76#[derive(Debug)]
77pub(crate) struct PluginZDefinition;
78
79impl Plugin for PluginZDefinition {
80 fn can_handle(&self, context: ContextCanHandle) -> bool {
81 rotate_can_handle(&context)
82 }
83
84 fn handle(&self, context: &mut ContextHandle) {
85 rotate_handle(&["--en-rotate-z"], context);
86 }
87}