encre_css/plugins/layout/object_position/
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 "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, .. } => context.buffer.line(format_args!(
32 "object-position: {};",
33 value.replace('-', " ")
34 )),
35 Modifier::Arbitrary { value, .. } => {
36 context
37 .buffer
38 .line(format_args!("object-position: {value};"));
39 }
40 }
41 }
42}