Skip to content

Commit

Permalink
feat: add backdrop-blur plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Jan 19, 2023
1 parent 4cfbaed commit 9783916
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
3 changes: 3 additions & 0 deletions crates/tailwind-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ pub struct TailwindTheme<'a> {
#[serde(borrow, alias = "strokeWidth")]
pub stroke_width: HashMap<&'a str, &'a str>,

#[serde(borrow, alias = "backdropBlur")]
pub backdrop_blur: HashMap<&'a str, &'a str>,

#[serde(borrow, alias = "aspectRatio")]
pub aspect_ratio: HashMap<&'a str, &'a str>,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/tailwind-parse/src/eval/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ macro_rules! lookup_plugin_arbitrary_opt {
Some(SubjectValue::Value(Value(v))) => {
simple_lookup_map(&theme.$map, v, $target, $closure)
}
Some(SubjectValue::Css(Css(v))) => to_lit(&[($target, v)]),
Some(SubjectValue::Css(Css(v))) => Ok(to_lit(&[($target, &$closure(v))])),
// if there is no value, attempt to look up the default
None => simple_lookup_map(&theme.$map, "DEFAULT", $target, $closure),
}
Expand Down
29 changes: 26 additions & 3 deletions crates/tailwind-parse/src/eval/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::HashMap;

use crate::{
AlignSelf, Border, Col, Css, Display, Divide, Flex, Grid, Object, Overflow, PluginResult,
Position, Rounded, Row, SubjectValue, TextDecoration, TextTransform, Translate, Value,
Visibility, Whitespace,
AlignSelf, Backdrop, Border, Col, Css, Display, Divide, Flex, Grid, Object, Overflow,
PluginResult, Position, Rounded, Row, SubjectValue, TextDecoration, TextTransform, Translate,
Value, Visibility, Whitespace,
};
use itertools::Itertools;
use stailwc_swc_utils::{merge_literals, to_lit};
Expand Down Expand Up @@ -702,6 +702,29 @@ pub fn grid<'a>(
Ok(to_lit(&pair))
}

lookup_plugin_arbitrary_opt!(backdrop_blur, backdrop_blur, "backdropBlur", |s| format!(
"blur({})",
s
));

pub fn backdrop<'a>(
o: Backdrop,
value: &Option<SubjectValue>,
theme: &'a TailwindTheme,
) -> PluginResult<'a> {
match o {
Backdrop::Blur => backdrop_blur(value.as_ref(), theme),
Backdrop::Brightness => todo!(),
Backdrop::Contrast => todo!(),
Backdrop::Grayscale => todo!(),
Backdrop::HueRotate => todo!(),
Backdrop::Invert => todo!(),
Backdrop::Opacity => todo!(),
Backdrop::Saturate => todo!(),
Backdrop::Sepia => todo!(),
}
}

pub fn object(
o: Object,
_rest: &Option<SubjectValue>,
Expand Down
1 change: 1 addition & 0 deletions crates/tailwind-parse/src/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ impl<'a> Literal<'a> {
Overflow(o) => RequiredBox(StdBox::new(move |v, t| plugin::overflow(o, v, t))),
Not(_) => todo!(),

Backdrop(b) => OptionalAbitraryBox(StdBox::new(move |v, t| plugin::backdrop(b, v, t))),
Auto(Auto::Cols) => Required(plugin::auto_cols),
Auto(Auto::Rows) => Required(plugin::auto_rows),

Expand Down
14 changes: 14 additions & 0 deletions crates/tailwind-parse/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ mod plugin {
Mx,
My,
Ml,
Backdrop(Backdrop),
Stroke,
Mr,
Mt,
Expand Down Expand Up @@ -132,6 +133,19 @@ mod plugin {
Not(Not),
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Backdrop {
Blur,
Brightness,
Contrast,
Grayscale,
HueRotate,
Invert,
Opacity,
Saturate,
Sepia,
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Auto {
Cols,
Expand Down

0 comments on commit 9783916

Please sign in to comment.