encre_css/plugins/svg/stroke_width/
mod.rs1#![doc = include_str!("README.md")]
2#![doc(alias = "svg")]
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, .. } => value.parse::<usize>().is_ok(),
12 Modifier::Arbitrary { hint, value, .. } => {
13 *hint == "length"
14 || *hint == "percentage"
15 || (hint.is_empty()
16 && (is_matching_length(value) || is_matching_percentage(value)))
17 }
18 }
19 }
20
21 fn handle(&self, context: &mut ContextHandle) {
22 match context.modifier {
23 Modifier::Builtin { value, .. } => {
24 context
25 .buffer
26 .line(format_args!("stroke-width: {value}px;"));
27 }
28 Modifier::Arbitrary { value, .. } => {
29 context.buffer.line(format_args!("stroke-width: {value};"));
30 }
31 }
32 }
33}