encre_css/plugins/transform/perspective_origin/
mod.rs

1#![doc = include_str!("README.md")]
2#![doc(alias = "layout")]
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                "bottom",
13                "center",
14                "left",
15                "bottom-left",
16                "top-left",
17                "right",
18                "bottom-right",
19                "top-right",
20                "top",
21            ]
22            .contains(value),
23            Modifier::Arbitrary { hint, value, .. } => {
24                *hint == "position" || (hint.is_empty() && is_matching_position(value))
25            }
26        }
27    }
28
29    fn handle(&self, context: &mut ContextHandle) {
30        match context.modifier {
31            Modifier::Builtin { value, .. } => {
32                context
33                    .buffer
34                    .line(format_args!("perspective-origin: {};", value.replace('-', " ")));
35            }
36            Modifier::Arbitrary { value, .. } => {
37                context
38                    .buffer
39                    .line(format_args!("perspective-origin: {value};"));
40            }
41        }
42    }
43}