encre_css/plugins/transform/perspective/
mod.rs1#![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 ["dramatic", "near", "normal", "midrange", "distant", "none"].contains(value)
13 }
14 Modifier::Arbitrary { hint, value, .. } => {
15 *hint == "length" || (hint.is_empty() && is_matching_length(value))
16 }
17 }
18 }
19
20 fn handle(&self, context: &mut ContextHandle) {
21 match context.modifier {
22 Modifier::Builtin { value, .. } => {
23 let value = match *value {
24 "dramatic" => "100px",
25 "near" => "300px",
26 "normal" => "500px",
27 "midrange" => "800px",
28 "distant" => "1200px",
29 "none" => "none",
30 _ => unreachable!(),
31 };
32 context.buffer.line(format_args!("perspective: {value};"));
33 }
34 Modifier::Arbitrary { value, .. } => {
35 context.buffer.line(format_args!("perspective: {value};"));
36 }
37 }
38 }
39}