encre_css/plugins/effect/text_shadow/
mod.rs1#![doc = include_str!("README.md")]
2#![doc(alias = "effect")]
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 ["2xs", "xs", "sm", "md", "lg", "xl", "2xl", "inner", "none"].contains(&&**value)
13 }
14 Modifier::Arbitrary { hint, value, .. } => {
15 *hint == "shadow" || (hint.is_empty() && is_matching_shadow(value))
16 }
17 }
18 }
19
20 fn handle(&self, context: &mut ContextHandle) {
21 match context.modifier {
22 Modifier::Builtin { value, .. } => match *value {
23 "2xs" => {
24 context.buffer.lines([
25 "text-shadow: 0px 1px 0px var(--en-text-shadow-color, rgb(0 0 0 / 0.15));",
26 ]);
27 }
28 "xs" => {
29 context.buffer.lines([
30 "text-shadow: 0px 1px 1px var(--en-text-shadow-color, rgb(0 0 0 / 0.2));",
31 ]);
32 }
33 "sm" => {
34 context.buffer.lines([
35 "text-shadow: 0px 1px 0px var(--en-text-shadow-color, rgb(0 0 0 / 0.075)), 0px 1px 1px var(--en-text-shadow-color, rgb(0 0 0 / 0.075)), 0px 2px 2px var(--en-text-shadow-color, rgb(0 0 0 / 0.075));",
36 ]);
37 }
38 "md" => {
39 context.buffer.lines([
40 "text-shadow: 0px 1px 1px var(--en-text-shadow-color, rgb(0 0 0 / 0.1)), 0px 1px 2px var(--en-text-shadow-color, rgb(0 0 0 / 0.1)), 0px 2px 4px var(--en-text-shadow-color, rgb(0 0 0 / 0.1));",
41 ]);
42 }
43 "lg" => {
44 context.buffer.lines([
45 "text-shadow: 0px 1px 2px var(--en-text-shadow-color, rgb(0 0 0 / 0.1)), 0px 3px 2px var(--en-text-shadow-color, rgb(0 0 0 / 0.1)), 0px 4px 8px var(--en-text-shadow-color, rgb(0 0 0 / 0.1));",
46 ]);
47 }
48 "none" => context.buffer.line("text-shadow: none;"),
49 _ => unreachable!(),
50 },
51 Modifier::Arbitrary { value, .. } => {
52 let mut shadow = shadow::ShadowList::parse(value).unwrap();
53 shadow.replace_all_colors("var(--en-text-shadow-color, {})");
54 context
55 .buffer
56 .line(format_args!("text-shadow: {shadow};"));
57 }
58 }
59 }
60}