diff --git a/macro_derive/src/lib.rs b/macro_derive/src/lib.rs index 4a29bfa..d654883 100644 --- a/macro_derive/src/lib.rs +++ b/macro_derive/src/lib.rs @@ -95,7 +95,7 @@ pub fn derive_enum_parser_fn(input: TokenStream) -> TokenStream { }) } -#[proc_macro_derive(ConfigurableParser, attributes(name, config))] +#[proc_macro_derive(ConfigurableParser, attributes(name, keyword, config))] pub fn derive_configurable_parser_fn(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); @@ -108,7 +108,7 @@ pub fn derive_configurable_parser_fn(input: TokenStream) -> TokenStream { nom::combinator::map( nom::branch::alt(( nom::sequence::delimited(nom::bytes::complete::tag("["), nom::bytes::complete::is_not("]"), nom::bytes::complete::tag("]")), - nom::combinator::map_opt(nom::bytes::complete::is_not(" "), move |v| config.#config().get(v).copied()), + nom::combinator::map_opt(nom::bytes::complete::is_not(" "), |v| config.#config().get(v).copied()), )), #out_type, )(input) @@ -116,6 +116,70 @@ pub fn derive_configurable_parser_fn(input: TokenStream) -> TokenStream { }) } +#[proc_macro_derive( + KeywordConfigurableParser, + attributes(name, keyword, config, empty_args) +)] +pub fn derive_keyword_configurable_parser_fn(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + + let parser_name = get_attr::(&input.attrs, "name"); + let config = get_attr::(&input.attrs, "config"); + let keyword = get_attr::(&input.attrs, "keyword"); + let empty_args = get_attr::(&input.attrs, "empty_args"); + + let empty_args = match empty_args { + Lit::Bool(b) => b.value, + _ => panic!("expected a bool"), + }; + + let out_type = &input.ident; + + if empty_args { + TokenStream::from(quote! { + fn #parser_name<'a>(input: &'a str, config: &'a crate::config::Config) -> nom::IResult<&'a str, #out_type<'a>> { + nom::branch::alt(( + nom::sequence::preceded( + nom::sequence::preceded( + nom::bytes::complete::tag(#keyword), + nom::bytes::complete::tag("-") + ), + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited(nom::bytes::complete::tag("["), nom::bytes::complete::is_not("]"), nom::bytes::complete::tag("]")), + nom::combinator::map_opt(nom::bytes::complete::is_not(" "), |v| config.#config().get(v).copied()), + )), + #out_type, + ) + ), + nom::combinator::map_opt( + nom::bytes::complete::tag(#keyword), + |_| config.#config().get("").map(|v| #out_type(v)) + ), + ))(input) + } + }) + } else { + TokenStream::from(quote! { + fn #parser_name<'a>(input: &'a str, config: &'a crate::config::Config) -> nom::IResult<&'a str, #out_type<'a>> { + nom::sequence::preceded( + nom::sequence::preceded( + nom::bytes::complete::tag(#keyword), + nom::bytes::complete::tag("-") + ), + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited(nom::bytes::complete::tag("["), nom::bytes::complete::is_not("]"), nom::bytes::complete::tag("]")), + nom::combinator::map_opt(nom::bytes::complete::is_not(" "), |v| config.#config().get(v).copied()), + )), + #out_type, + ) + )(input) + } + }) + } +} + #[proc_macro_derive(ConfigurableEnumParser, attributes(tag, name, config))] pub fn derive_configurable_enum_parser_fn(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); diff --git a/railwind/filters.rs b/railwind/filters.rs new file mode 100644 index 0000000..7637b89 --- /dev/null +++ b/railwind/filters.rs @@ -0,0 +1,1468 @@ +mod filters { + use macro_derive::{ConfigurableParser, KeywordConfigurableParser}; + use nom::branch::alt; + use nom::bytes::complete::tag; + use nom::combinator::{map, map_opt}; + use nom::sequence::preceded; + use nom::IResult; + use crate::class::Decl; + use crate::class::utils::neg_keyword_value; + use crate::class::IntoDeclaration; + use crate::config::Config; + const FILTER_STYLE: &str = "filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)"; + const WEBKIT_BACKDROP_FILTER_STYLE: &str = "-webkit-backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)"; + const BACKDROP_FILTER_STYLE: &str = " backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)"; + pub enum Filter<'a> { + Blur(Blur<'a>), + Brightness(Brightness<'a>), + Contrast(Contrast<'a>), + DropShadow(DropShadow<'a>), + Grayscale(Grayscale<'a>), + HueRotate(HueRotate), + Invert(Invert<'a>), + Saturate(Saturate<'a>), + Sepia(Sepia<'a>), + BackdropBlur(BackdropBlur<'a>), + BackdropBrightness(BackdropBrightness<'a>), + BackdropContrast(BackdropContrast<'a>), + BackdropGrayscale(BackdropGrayscale<'a>), + BackdropHueRotate(BackdropHueRotate), + BackdropInvert(BackdropInvert<'a>), + BackdropOpacity(BackdropOpacity<'a>), + BackdropSaturate(BackdropSaturate<'a>), + BackdropSepia(BackdropSepia<'a>), + } + #[automatically_derived] + impl<'a> ::core::fmt::Debug for Filter<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + match self { + Filter::Blur(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "Blur", + &__self_0, + ) + } + Filter::Brightness(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "Brightness", + &__self_0, + ) + } + Filter::Contrast(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "Contrast", + &__self_0, + ) + } + Filter::DropShadow(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "DropShadow", + &__self_0, + ) + } + Filter::Grayscale(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "Grayscale", + &__self_0, + ) + } + Filter::HueRotate(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "HueRotate", + &__self_0, + ) + } + Filter::Invert(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "Invert", + &__self_0, + ) + } + Filter::Saturate(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "Saturate", + &__self_0, + ) + } + Filter::Sepia(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "Sepia", + &__self_0, + ) + } + Filter::BackdropBlur(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropBlur", + &__self_0, + ) + } + Filter::BackdropBrightness(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropBrightness", + &__self_0, + ) + } + Filter::BackdropContrast(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropContrast", + &__self_0, + ) + } + Filter::BackdropGrayscale(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropGrayscale", + &__self_0, + ) + } + Filter::BackdropHueRotate(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropHueRotate", + &__self_0, + ) + } + Filter::BackdropInvert(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropInvert", + &__self_0, + ) + } + Filter::BackdropOpacity(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropOpacity", + &__self_0, + ) + } + Filter::BackdropSaturate(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropSaturate", + &__self_0, + ) + } + Filter::BackdropSepia(__self_0) => { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropSepia", + &__self_0, + ) + } + } + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for Filter<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for Filter<'a> { + #[inline] + fn eq(&self, other: &Filter<'a>) -> bool { + let __self_tag = ::core::intrinsics::discriminant_value(self); + let __arg1_tag = ::core::intrinsics::discriminant_value(other); + __self_tag == __arg1_tag + && match (self, other) { + (Filter::Blur(__self_0), Filter::Blur(__arg1_0)) => { + *__self_0 == *__arg1_0 + } + (Filter::Brightness(__self_0), Filter::Brightness(__arg1_0)) => { + *__self_0 == *__arg1_0 + } + (Filter::Contrast(__self_0), Filter::Contrast(__arg1_0)) => { + *__self_0 == *__arg1_0 + } + (Filter::DropShadow(__self_0), Filter::DropShadow(__arg1_0)) => { + *__self_0 == *__arg1_0 + } + (Filter::Grayscale(__self_0), Filter::Grayscale(__arg1_0)) => { + *__self_0 == *__arg1_0 + } + (Filter::HueRotate(__self_0), Filter::HueRotate(__arg1_0)) => { + *__self_0 == *__arg1_0 + } + (Filter::Invert(__self_0), Filter::Invert(__arg1_0)) => { + *__self_0 == *__arg1_0 + } + (Filter::Saturate(__self_0), Filter::Saturate(__arg1_0)) => { + *__self_0 == *__arg1_0 + } + (Filter::Sepia(__self_0), Filter::Sepia(__arg1_0)) => { + *__self_0 == *__arg1_0 + } + (Filter::BackdropBlur(__self_0), Filter::BackdropBlur(__arg1_0)) => { + *__self_0 == *__arg1_0 + } + ( + Filter::BackdropBrightness(__self_0), + Filter::BackdropBrightness(__arg1_0), + ) => *__self_0 == *__arg1_0, + ( + Filter::BackdropContrast(__self_0), + Filter::BackdropContrast(__arg1_0), + ) => *__self_0 == *__arg1_0, + ( + Filter::BackdropGrayscale(__self_0), + Filter::BackdropGrayscale(__arg1_0), + ) => *__self_0 == *__arg1_0, + ( + Filter::BackdropHueRotate(__self_0), + Filter::BackdropHueRotate(__arg1_0), + ) => *__self_0 == *__arg1_0, + ( + Filter::BackdropInvert(__self_0), + Filter::BackdropInvert(__arg1_0), + ) => *__self_0 == *__arg1_0, + ( + Filter::BackdropOpacity(__self_0), + Filter::BackdropOpacity(__arg1_0), + ) => *__self_0 == *__arg1_0, + ( + Filter::BackdropSaturate(__self_0), + Filter::BackdropSaturate(__arg1_0), + ) => *__self_0 == *__arg1_0, + ( + Filter::BackdropSepia(__self_0), + Filter::BackdropSepia(__arg1_0), + ) => *__self_0 == *__arg1_0, + _ => unsafe { ::core::intrinsics::unreachable() } + } + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for Filter<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + let __self_tag = ::core::intrinsics::discriminant_value(self); + ::core::hash::Hash::hash(&__self_tag, state); + match self { + Filter::Blur(__self_0) => ::core::hash::Hash::hash(__self_0, state), + Filter::Brightness(__self_0) => ::core::hash::Hash::hash(__self_0, state), + Filter::Contrast(__self_0) => ::core::hash::Hash::hash(__self_0, state), + Filter::DropShadow(__self_0) => ::core::hash::Hash::hash(__self_0, state), + Filter::Grayscale(__self_0) => ::core::hash::Hash::hash(__self_0, state), + Filter::HueRotate(__self_0) => ::core::hash::Hash::hash(__self_0, state), + Filter::Invert(__self_0) => ::core::hash::Hash::hash(__self_0, state), + Filter::Saturate(__self_0) => ::core::hash::Hash::hash(__self_0, state), + Filter::Sepia(__self_0) => ::core::hash::Hash::hash(__self_0, state), + Filter::BackdropBlur(__self_0) => { + ::core::hash::Hash::hash(__self_0, state) + } + Filter::BackdropBrightness(__self_0) => { + ::core::hash::Hash::hash(__self_0, state) + } + Filter::BackdropContrast(__self_0) => { + ::core::hash::Hash::hash(__self_0, state) + } + Filter::BackdropGrayscale(__self_0) => { + ::core::hash::Hash::hash(__self_0, state) + } + Filter::BackdropHueRotate(__self_0) => { + ::core::hash::Hash::hash(__self_0, state) + } + Filter::BackdropInvert(__self_0) => { + ::core::hash::Hash::hash(__self_0, state) + } + Filter::BackdropOpacity(__self_0) => { + ::core::hash::Hash::hash(__self_0, state) + } + Filter::BackdropSaturate(__self_0) => { + ::core::hash::Hash::hash(__self_0, state) + } + Filter::BackdropSepia(__self_0) => { + ::core::hash::Hash::hash(__self_0, state) + } + } + } + } + pub fn filter<'a>( + input: &'a str, + config: &'a Config, + ) -> IResult<&'a str, Filter<'a>> { + alt(( + preceded(tag("blur-"), map(|i| blur(i, config), Filter::Blur)), + map_opt( + tag("blur"), + |_| { config.filters.get_blur().get("").map(|v| Filter::Blur(Blur(v))) }, + ), + ))(input) + } + impl<'a> IntoDeclaration for Filter<'a> { + fn to_decl(self) -> Decl { + match self { + Filter::Blur(f) => f.to_decl(), + Filter::Brightness(f) => f.to_decl(), + Filter::Contrast(f) => f.to_decl(), + Filter::DropShadow(f) => f.to_decl(), + Filter::Grayscale(f) => f.to_decl(), + Filter::HueRotate(f) => f.to_decl(), + Filter::Invert(f) => f.to_decl(), + Filter::Saturate(f) => f.to_decl(), + Filter::Sepia(f) => f.to_decl(), + Filter::BackdropBlur(f) => f.to_decl(), + Filter::BackdropBrightness(f) => f.to_decl(), + Filter::BackdropContrast(f) => f.to_decl(), + Filter::BackdropGrayscale(f) => f.to_decl(), + Filter::BackdropHueRotate(f) => f.to_decl(), + Filter::BackdropInvert(f) => f.to_decl(), + Filter::BackdropOpacity(f) => f.to_decl(), + Filter::BackdropSaturate(f) => f.to_decl(), + Filter::BackdropSepia(f) => f.to_decl(), + } + } + } + #[name(blur)] + #[keyword("blur")] + #[no_args(false)] + #[config(filters.get_blur)] + pub struct Blur<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for Blur<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Blur", &&self.0) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for Blur<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for Blur<'a> { + #[inline] + fn eq(&self, other: &Blur<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for Blur<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn blur<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, Blur<'a>> { + nom::branch::alt(( + nom::sequence::preceded( + nom::sequence::preceded( + nom::bytes::complete::tag("blur"), + nom::bytes::complete::tag("-"), + ), + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_blur().get(v).copied(), + ), + )), + Blur, + ), + ), + nom::combinator::map_opt( + nom::bytes::complete::tag("blur"), + |_| config.filters.get_blur().get("").map(|v| Blur), + ), + ))(input) + } + impl<'a> IntoDeclaration for Blur<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-blur: blur({0})", self.0), + ); + res + }, + FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(brightness)] + #[config(filters.get_brightness)] + pub struct Brightness<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for Brightness<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Brightness", &&self.0) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for Brightness<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for Brightness<'a> { + #[inline] + fn eq(&self, other: &Brightness<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for Brightness<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn brightness<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, Brightness<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_brightness().get(v).copied(), + ), + )), + Brightness, + )(input) + } + impl<'a> IntoDeclaration for Brightness<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-brightness: brightness({0})", self.0), + ); + res + }, + FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(contrast)] + #[config(filters.get_contrast)] + pub struct Contrast<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for Contrast<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Contrast", &&self.0) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for Contrast<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for Contrast<'a> { + #[inline] + fn eq(&self, other: &Contrast<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for Contrast<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn contrast<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, Contrast<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_contrast().get(v).copied(), + ), + )), + Contrast, + )(input) + } + impl<'a> IntoDeclaration for Contrast<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-contrast: contrast({0})", self.0), + ); + res + }, + FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(drop_shadow)] + #[config(filters.get_drop_shadow)] + pub struct DropShadow<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for DropShadow<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "DropShadow", &&self.0) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for DropShadow<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for DropShadow<'a> { + #[inline] + fn eq(&self, other: &DropShadow<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for DropShadow<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn drop_shadow<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, DropShadow<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_drop_shadow().get(v).copied(), + ), + )), + DropShadow, + )(input) + } + impl<'a> IntoDeclaration for DropShadow<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-drop-shadow: drop-shadow({0})", self.0), + ); + res + }, + FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(grayscale)] + #[config(filters.get_grayscale)] + pub struct Grayscale<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for Grayscale<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Grayscale", &&self.0) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for Grayscale<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for Grayscale<'a> { + #[inline] + fn eq(&self, other: &Grayscale<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for Grayscale<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn grayscale<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, Grayscale<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_grayscale().get(v).copied(), + ), + )), + Grayscale, + )(input) + } + impl<'a> IntoDeclaration for Grayscale<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-grayscale: grayscale({0})", self.0), + ); + res + }, + FILTER_STYLE.into(), + ]), + ), + ) + } + } + pub struct HueRotate(pub String); + #[automatically_derived] + impl ::core::fmt::Debug for HueRotate { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "HueRotate", &&self.0) + } + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for HueRotate {} + #[automatically_derived] + impl ::core::cmp::PartialEq for HueRotate { + #[inline] + fn eq(&self, other: &HueRotate) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl ::core::hash::Hash for HueRotate { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn hue_rotate<'a>( + input: &'a str, + config: &'a Config, + ) -> IResult<&'a str, HueRotate> { + map( + neg_keyword_value("hue-rotate", config.filters.get_hue_rotate()), + HueRotate, + )(input) + } + impl IntoDeclaration for HueRotate { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-hue-rotate: hue-rotate({0})", self.0), + ); + res + }, + FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(invert)] + #[config(filters.get_invert)] + pub struct Invert<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for Invert<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Invert", &&self.0) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for Invert<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for Invert<'a> { + #[inline] + fn eq(&self, other: &Invert<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for Invert<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn invert<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, Invert<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_invert().get(v).copied(), + ), + )), + Invert, + )(input) + } + impl<'a> IntoDeclaration for Invert<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-invert: invert({0})", self.0), + ); + res + }, + FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(saturate)] + #[config(filters.get_saturate)] + pub struct Saturate<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for Saturate<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Saturate", &&self.0) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for Saturate<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for Saturate<'a> { + #[inline] + fn eq(&self, other: &Saturate<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for Saturate<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn saturate<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, Saturate<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_saturate().get(v).copied(), + ), + )), + Saturate, + )(input) + } + impl<'a> IntoDeclaration for Saturate<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-saturate: saturate({0})", self.0), + ); + res + }, + FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(sepia)] + #[config(filters.get_sepia)] + pub struct Sepia<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for Sepia<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Sepia", &&self.0) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for Sepia<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for Sepia<'a> { + #[inline] + fn eq(&self, other: &Sepia<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for Sepia<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn sepia<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, Sepia<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_sepia().get(v).copied(), + ), + )), + Sepia, + )(input) + } + impl<'a> IntoDeclaration for Sepia<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-sepia: sepia({0})", self.0), + ); + res + }, + FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(backdrop_blur)] + #[config(filters.get_blur)] + pub struct BackdropBlur<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for BackdropBlur<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropBlur", + &&self.0, + ) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for BackdropBlur<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for BackdropBlur<'a> { + #[inline] + fn eq(&self, other: &BackdropBlur<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for BackdropBlur<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn backdrop_blur<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, BackdropBlur<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_blur().get(v).copied(), + ), + )), + BackdropBlur, + )(input) + } + impl<'a> IntoDeclaration for BackdropBlur<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-backdrop-blur: blur({0})", self.0), + ); + res + }, + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(backdrop_brightness)] + #[config(filters.get_brightness)] + pub struct BackdropBrightness<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for BackdropBrightness<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropBrightness", + &&self.0, + ) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for BackdropBrightness<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for BackdropBrightness<'a> { + #[inline] + fn eq(&self, other: &BackdropBrightness<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for BackdropBrightness<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn backdrop_brightness<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, BackdropBrightness<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_brightness().get(v).copied(), + ), + )), + BackdropBrightness, + )(input) + } + impl<'a> IntoDeclaration for BackdropBrightness<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!( + "--tw-backdrop-brightness: brightness({0})", self.0 + ), + ); + res + }, + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(backdrop_contrast)] + #[config(filters.get_contrast)] + pub struct BackdropContrast<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for BackdropContrast<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropContrast", + &&self.0, + ) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for BackdropContrast<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for BackdropContrast<'a> { + #[inline] + fn eq(&self, other: &BackdropContrast<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for BackdropContrast<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn backdrop_contrast<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, BackdropContrast<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_contrast().get(v).copied(), + ), + )), + BackdropContrast, + )(input) + } + impl<'a> IntoDeclaration for BackdropContrast<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!( + "--tw-backdrop-contrast: contrast({0})", self.0 + ), + ); + res + }, + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(backdrop_grayscale)] + #[config(filters.get_grayscale)] + pub struct BackdropGrayscale<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for BackdropGrayscale<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropGrayscale", + &&self.0, + ) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for BackdropGrayscale<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for BackdropGrayscale<'a> { + #[inline] + fn eq(&self, other: &BackdropGrayscale<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for BackdropGrayscale<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn backdrop_grayscale<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, BackdropGrayscale<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_grayscale().get(v).copied(), + ), + )), + BackdropGrayscale, + )(input) + } + impl<'a> IntoDeclaration for BackdropGrayscale<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!( + "--tw-backdrop-grayscale: grayscale({0})", self.0 + ), + ); + res + }, + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]), + ), + ) + } + } + pub struct BackdropHueRotate(pub String); + #[automatically_derived] + impl ::core::fmt::Debug for BackdropHueRotate { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropHueRotate", + &&self.0, + ) + } + } + #[automatically_derived] + impl ::core::marker::StructuralPartialEq for BackdropHueRotate {} + #[automatically_derived] + impl ::core::cmp::PartialEq for BackdropHueRotate { + #[inline] + fn eq(&self, other: &BackdropHueRotate) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl ::core::hash::Hash for BackdropHueRotate { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn backdrop_hue_rotate<'a>( + input: &'a str, + config: &'a Config, + ) -> IResult<&'a str, BackdropHueRotate> { + map( + neg_keyword_value("backdrop_hue-rotate", config.filters.get_hue_rotate()), + BackdropHueRotate, + )(input) + } + impl<'a> IntoDeclaration for BackdropHueRotate { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!( + "--tw-backdrop-hue-rotate: hue-rotate({0})", self.0 + ), + ); + res + }, + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(backdrop_invert)] + #[config(filters.get_invert)] + pub struct BackdropInvert<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for BackdropInvert<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropInvert", + &&self.0, + ) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for BackdropInvert<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for BackdropInvert<'a> { + #[inline] + fn eq(&self, other: &BackdropInvert<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for BackdropInvert<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn backdrop_invert<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, BackdropInvert<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_invert().get(v).copied(), + ), + )), + BackdropInvert, + )(input) + } + impl<'a> IntoDeclaration for BackdropInvert<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-backdrop-invert: invert({0})", self.0), + ); + res + }, + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(backdrop_opacity)] + #[config(filters.get_opacity)] + pub struct BackdropOpacity<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for BackdropOpacity<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropOpacity", + &&self.0, + ) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for BackdropOpacity<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for BackdropOpacity<'a> { + #[inline] + fn eq(&self, other: &BackdropOpacity<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for BackdropOpacity<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn backdrop_opacity<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, BackdropOpacity<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_opacity().get(v).copied(), + ), + )), + BackdropOpacity, + )(input) + } + impl<'a> IntoDeclaration for BackdropOpacity<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-backdrop-opacity: opacity({0})", self.0), + ); + res + }, + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(backdrop_saturate)] + #[config(filters.get_saturate)] + pub struct BackdropSaturate<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for BackdropSaturate<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropSaturate", + &&self.0, + ) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for BackdropSaturate<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for BackdropSaturate<'a> { + #[inline] + fn eq(&self, other: &BackdropSaturate<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for BackdropSaturate<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn backdrop_saturate<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, BackdropSaturate<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_saturate().get(v).copied(), + ), + )), + BackdropSaturate, + )(input) + } + impl<'a> IntoDeclaration for BackdropSaturate<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!( + "--tw-backdrop-saturate: saturate({0})", self.0 + ), + ); + res + }, + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]), + ), + ) + } + } + #[name(backdrop_sepia)] + #[config(filters.get_sepia)] + pub struct BackdropSepia<'a>(pub &'a str); + #[automatically_derived] + impl<'a> ::core::fmt::Debug for BackdropSepia<'a> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + ::core::fmt::Formatter::debug_tuple_field1_finish( + f, + "BackdropSepia", + &&self.0, + ) + } + } + #[automatically_derived] + impl<'a> ::core::marker::StructuralPartialEq for BackdropSepia<'a> {} + #[automatically_derived] + impl<'a> ::core::cmp::PartialEq for BackdropSepia<'a> { + #[inline] + fn eq(&self, other: &BackdropSepia<'a>) -> bool { + self.0 == other.0 + } + } + #[automatically_derived] + impl<'a> ::core::hash::Hash for BackdropSepia<'a> { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + ::core::hash::Hash::hash(&self.0, state) + } + } + fn backdrop_sepia<'a>( + input: &'a str, + config: &'a crate::config::Config, + ) -> nom::IResult<&'a str, BackdropSepia<'a>> { + nom::combinator::map( + nom::branch::alt(( + nom::sequence::delimited( + nom::bytes::complete::tag("["), + nom::bytes::complete::is_not("]"), + nom::bytes::complete::tag("]"), + ), + nom::combinator::map_opt( + nom::bytes::complete::is_not(" "), + |v| config.filters.get_sepia().get(v).copied(), + ), + )), + BackdropSepia, + )(input) + } + impl<'a> IntoDeclaration for BackdropSepia<'a> { + fn to_decl(self) -> Decl { + Decl::Vec( + <[_]>::into_vec( + #[rustc_box] + ::alloc::boxed::Box::new([ + { + let res = ::alloc::fmt::format( + format_args!("--tw-backdrop-sepia: sepia({0})", self.0), + ); + res + }, + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]), + ), + ) + } + } +} diff --git a/railwind/src/class/borders.rs b/railwind/src/class/borders.rs index 0b62f9c..5a47230 100644 --- a/railwind/src/class/borders.rs +++ b/railwind/src/class/borders.rs @@ -101,7 +101,7 @@ pub enum BorderRadius<'a> { } fn border_radius<'a>(input: &'a str, config: &'a Config) -> IResult<&'a str, BorderRadius<'a>> { - let radius = || config.borders.get_border_radius(); + let radius = config.borders.get_border_radius(); alt(( map(keyword_value("t", radius), BorderRadius::Top), @@ -156,7 +156,7 @@ pub enum BorderWidth<'a> { } fn border_width<'a>(input: &'a str, config: &'a Config) -> IResult<&'a str, BorderWidth<'a>> { - let width = || config.borders.get_border_width(); + let width = config.borders.get_border_width(); alt(( map(keyword_value("x", width), BorderWidth::X), @@ -201,7 +201,7 @@ pub enum BorderColor<'a> { } fn border_color<'a>(input: &'a str, config: &'a Config) -> IResult<&'a str, BorderColor<'a>> { - let color = || config.borders.get_border_color(); + let color = config.borders.get_border_color(); alt(( map(keyword_value("x", color), BorderColor::X), @@ -308,7 +308,7 @@ pub enum DivideWidth<'a> { } fn divide_width<'a>(input: &'a str, config: &'a Config) -> IResult<&'a str, DivideWidth<'a>> { - let width = || config.borders.get_divide_width(); + let width = config.borders.get_divide_width(); alt(( map(keyword_value("x", width), DivideWidth::X), @@ -431,7 +431,7 @@ pub enum RingWidth<'a> { } fn ring_width<'a>(input: &'a str, config: &'a Config) -> IResult<&'a str, RingWidth<'a>> { - let w = || config.borders.get_ring_width(); + let w = config.borders.get_ring_width(); alt(( map(arbitrary_hashmap_value(w), RingWidth::Value), diff --git a/railwind/src/class/filters/mod.rs b/railwind/src/class/filters/mod.rs index 52f0806..ec0a01c 100644 --- a/railwind/src/class/filters/mod.rs +++ b/railwind/src/class/filters/mod.rs @@ -1,36 +1,19 @@ -mod types; - -use types::*; +use macro_derive::KeywordConfigurableParser; +use nom::branch::alt; +use nom::bytes::complete::tag; +use nom::combinator::map; +use nom::sequence::preceded; +use nom::IResult; use crate::class::Decl; -use crate::utils::{get_args, get_class_name}; -use crate::warning::WarningType; - -use lazy_static::lazy_static; -use std::collections::HashMap; - -lazy_static! { - pub static ref BLUR: HashMap<&'static str, &'static str> = - ron::from_str(include_str!("blur.ron")).unwrap(); - pub static ref BRIGHTNESS: HashMap<&'static str, &'static str> = - ron::from_str(include_str!("brightness.ron")).unwrap(); - pub static ref CONTRAST: HashMap<&'static str, &'static str> = - ron::from_str(include_str!("contrast.ron")).unwrap(); - pub static ref DROP_SHADOW: HashMap<&'static str, &'static str> = - ron::from_str(include_str!("drop_shadow.ron")).unwrap(); - pub static ref GRAYSCALE: HashMap<&'static str, &'static str> = - ron::from_str(include_str!("grayscale.ron")).unwrap(); - pub static ref HUE_ROTATE: HashMap<&'static str, &'static str> = - ron::from_str(include_str!("hue_rotate.ron")).unwrap(); - pub static ref INVERT: HashMap<&'static str, &'static str> = - ron::from_str(include_str!("invert.ron")).unwrap(); - pub static ref SATURATE: HashMap<&'static str, &'static str> = - ron::from_str(include_str!("saturate.ron")).unwrap(); - pub static ref SEPIA: HashMap<&'static str, &'static str> = - ron::from_str(include_str!("sepia.ron")).unwrap(); - pub static ref OPACITY: HashMap<&'static str, &'static str> = - ron::from_str(include_str!("opacity.ron")).unwrap(); -} + +use crate::class::utils::neg_keyword_value; +use crate::class::IntoDeclaration; +use crate::config::Config; + +const FILTER_STYLE: &str = "filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)"; +const WEBKIT_BACKDROP_FILTER_STYLE: &str = "-webkit-backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)"; +const BACKDROP_FILTER_STYLE: &str = " backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)"; #[derive(Debug, PartialEq, Hash)] pub enum Filter<'a> { @@ -39,7 +22,7 @@ pub enum Filter<'a> { Contrast(Contrast<'a>), DropShadow(DropShadow<'a>), Grayscale(Grayscale<'a>), - HueRotate(HueRotate<'a>), + HueRotate(HueRotate), Invert(Invert<'a>), Saturate(Saturate<'a>), Sepia(Sepia<'a>), @@ -47,171 +30,354 @@ pub enum Filter<'a> { BackdropBrightness(BackdropBrightness<'a>), BackdropContrast(BackdropContrast<'a>), BackdropGrayscale(BackdropGrayscale<'a>), - BackdropHueRotate(BackdropHueRotate<'a>), + BackdropHueRotate(BackdropHueRotate), BackdropInvert(BackdropInvert<'a>), BackdropOpacity(BackdropOpacity<'a>), BackdropSaturate(BackdropSaturate<'a>), BackdropSepia(BackdropSepia<'a>), } -impl<'a> Filter<'a> { - pub fn new(value: &'a str) -> Result, WarningType> { - let class_name = get_class_name(value); - - let filter = match class_name { - "blur" => { - if let Ok(args) = get_args(value) { - Self::Blur(Blur(args)) - } else { - Self::Blur(Blur("")) - } - } - "brightness" => Self::Brightness(Brightness(get_args(value)?)), - "contrast" => Self::Contrast(Contrast(get_args(value)?)), - "drop" => match get_class_name(get_args(value)?) { - "shadow" => { - if let Ok(args) = get_args(get_args(value)?) { - Self::DropShadow(DropShadow(args)) - } else { - Self::DropShadow(DropShadow("")) - } - } - v => { - return Err(WarningType::InvalidArg( - v.into(), - "Drop Shadow".into(), - vec!["shadow"], - )) - } - }, - "grayscale" => { - if let Ok(args) = get_args(value) { - Self::Grayscale(Grayscale(args)) - } else { - Self::Grayscale(Grayscale("")) - } - } - "hue" | "-hue" => match get_class_name(get_args(value)?) { - "rotate" => { - Self::HueRotate(HueRotate::new(class_name, get_args(get_args(value)?)?)) - } - v => { - return Err(WarningType::InvalidArg( - v.into(), - "Hue Rotate".into(), - vec!["rotate"], - )) - } - }, - "invert" => { - if let Ok(args) = get_args(value) { - Self::Invert(Invert(args)) - } else { - Self::Invert(Invert("")) - } - } - "saturate" => Self::Saturate(Saturate(get_args(value)?)), - "sepia" => { - if let Ok(args) = get_args(value) { - Self::Sepia(Sepia(args)) - } else { - Self::Sepia(Sepia("")) - } - } - "backdrop" | "-backdrop" => { - let args = get_args(value)?; - let sub_class_name = get_class_name(args); - match sub_class_name { - "blur" => { - if let Ok(args) = get_args(get_args(value)?) { - Self::BackdropBlur(BackdropBlur(args)) - } else { - Self::BackdropBlur(BackdropBlur("")) - } - } - "brightness" => Self::BackdropBrightness(BackdropBrightness(get_args(args)?)), - "contrast" => Self::BackdropContrast(BackdropContrast(get_args(args)?)), - "grayscale" => { - if let Ok(args) = get_args(args) { - Self::BackdropGrayscale(BackdropGrayscale(args)) - } else { - Self::BackdropGrayscale(BackdropGrayscale("")) - } - } - "hue" => match get_class_name(get_args(get_args(value)?)?) { - "rotate" => Self::BackdropHueRotate(BackdropHueRotate::new( - class_name, - get_args(get_args(args)?)?, - )), - v => { - return Err(WarningType::InvalidArg( - v.into(), - "Backdrop Hue Rotate".into(), - vec!["rotate"], - )) - } - }, - "invert" => { - if let Ok(args) = get_args(args) { - Self::BackdropInvert(BackdropInvert(args)) - } else { - Self::BackdropInvert(BackdropInvert("")) - } - } - "opacity" => Self::BackdropOpacity(BackdropOpacity(get_args(args)?)), - "saturate" => Self::BackdropSaturate(BackdropSaturate(get_args(args)?)), - "sepia" => { - if let Ok(args) = get_args(args) { - Self::BackdropSepia(BackdropSepia(args)) - } else { - Self::BackdropSepia(BackdropSepia("")) - } - } - v => { - return Err(WarningType::InvalidArg( - v.into(), - "Backdrop".into(), - vec![ - "blur", - "brightness", - "contrast", - "grayscale", - "hue", - "invert", - "opacity", - "saturate", - "sepia", - ], - )) - } - } - } - _ => return Ok(None), - }; - - Ok(Some(filter)) - } - - pub fn to_decl(self) -> Result { +pub fn filter<'a>(input: &'a str, config: &'a Config) -> IResult<&'a str, Filter<'a>> { + alt(( + map(|i| blur(i, config), Filter::Blur), + map(|i| brightness(i, config), Filter::Brightness), + map(|i| contrast(i, config), Filter::Contrast), + map(|i| drop_shadow(i, config), Filter::DropShadow), + map(|i| grayscale(i, config), Filter::Grayscale), + map(|i| hue_rotate(i, config), Filter::HueRotate), + map(|i| invert(i, config), Filter::Invert), + map(|i| saturate(i, config), Filter::Saturate), + map(|i| sepia(i, config), Filter::Sepia), + map(|i| backdrop_opacity(i, config), Filter::BackdropOpacity), + preceded( + tag("backdrop-"), + alt(( + map( + |i| blur(i, config), + |b| Filter::BackdropBlur(BackdropBlur(b.0)), + ), + map( + |i| brightness(i, config), + |b| Filter::BackdropBrightness(BackdropBrightness(b.0)), + ), + map( + |i| contrast(i, config), + |b| Filter::BackdropContrast(BackdropContrast(b.0)), + ), + map( + |i| grayscale(i, config), + |b| Filter::BackdropGrayscale(BackdropGrayscale(b.0)), + ), + map( + |i| hue_rotate(i, config), + |b| Filter::BackdropHueRotate(BackdropHueRotate(b.0)), + ), + map( + |i| invert(i, config), + |b| Filter::BackdropInvert(BackdropInvert(b.0)), + ), + map( + |i| saturate(i, config), + |b| Filter::BackdropSaturate(BackdropSaturate(b.0)), + ), + map( + |i| sepia(i, config), + |b| Filter::BackdropSepia(BackdropSepia(b.0)), + ), + )), + ), + ))(input) +} + +impl<'a> IntoDeclaration for Filter<'a> { + fn to_decl(self) -> Decl { match self { - Self::Blur(s) => s.to_decl(), - Self::Brightness(s) => s.to_decl(), - Self::Contrast(s) => s.to_decl(), - Self::DropShadow(s) => s.to_decl(), - Self::Grayscale(s) => s.to_decl(), - Self::HueRotate(s) => s.to_decl(), - Self::Invert(s) => s.to_decl(), - Self::Saturate(s) => s.to_decl(), - Self::Sepia(s) => s.to_decl(), - Self::BackdropBlur(s) => s.to_decl(), - Self::BackdropBrightness(s) => s.to_decl(), - Self::BackdropContrast(s) => s.to_decl(), - Self::BackdropGrayscale(s) => s.to_decl(), - Self::BackdropHueRotate(s) => s.to_decl(), - Self::BackdropInvert(s) => s.to_decl(), - Self::BackdropOpacity(s) => s.to_decl(), - Self::BackdropSaturate(s) => s.to_decl(), - Self::BackdropSepia(s) => s.to_decl(), + Filter::Blur(f) => f.to_decl(), + Filter::Brightness(f) => f.to_decl(), + Filter::Contrast(f) => f.to_decl(), + Filter::DropShadow(f) => f.to_decl(), + Filter::Grayscale(f) => f.to_decl(), + Filter::HueRotate(f) => f.to_decl(), + Filter::Invert(f) => f.to_decl(), + Filter::Saturate(f) => f.to_decl(), + Filter::Sepia(f) => f.to_decl(), + Filter::BackdropBlur(f) => f.to_decl(), + Filter::BackdropBrightness(f) => f.to_decl(), + Filter::BackdropContrast(f) => f.to_decl(), + Filter::BackdropGrayscale(f) => f.to_decl(), + Filter::BackdropHueRotate(f) => f.to_decl(), + Filter::BackdropInvert(f) => f.to_decl(), + Filter::BackdropOpacity(f) => f.to_decl(), + Filter::BackdropSaturate(f) => f.to_decl(), + Filter::BackdropSepia(f) => f.to_decl(), } } } + +#[derive(Debug, PartialEq, Hash, KeywordConfigurableParser)] +#[name(blur)] +#[keyword("blur")] +#[empty_args(true)] +#[config(filters.get_blur)] +pub struct Blur<'a>(pub &'a str); + +impl<'a> IntoDeclaration for Blur<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-blur: blur({})", self.0), + FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash, KeywordConfigurableParser)] +#[name(brightness)] +#[keyword("brightness")] +#[empty_args(false)] +#[config(filters.get_brightness)] +pub struct Brightness<'a>(pub &'a str); + +impl<'a> IntoDeclaration for Brightness<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-brightness: brightness({})", self.0), + FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash, KeywordConfigurableParser)] +#[name(contrast)] +#[keyword("contrast")] +#[empty_args(false)] +#[config(filters.get_contrast)] +pub struct Contrast<'a>(pub &'a str); + +impl<'a> IntoDeclaration for Contrast<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-contrast: contrast({})", self.0), + FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash, KeywordConfigurableParser)] +#[name(drop_shadow)] +#[keyword("drop-shadow")] +#[empty_args(true)] +#[config(filters.get_drop_shadow)] +pub struct DropShadow<'a>(pub &'a str); + +impl<'a> IntoDeclaration for DropShadow<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-drop-shadow: drop-shadow({})", self.0), + FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash, KeywordConfigurableParser)] +#[name(grayscale)] +#[keyword("grayscale")] +#[empty_args(true)] +#[config(filters.get_grayscale)] +pub struct Grayscale<'a>(pub &'a str); + +impl<'a> IntoDeclaration for Grayscale<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-grayscale: grayscale({})", self.0), + FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash)] +pub struct HueRotate(pub String); + +fn hue_rotate<'a>(input: &'a str, config: &'a Config) -> IResult<&'a str, HueRotate> { + map( + neg_keyword_value("hue-rotate", config.filters.get_hue_rotate()), + HueRotate, + )(input) +} + +impl IntoDeclaration for HueRotate { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-hue-rotate: hue-rotate({})", self.0), + FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash, KeywordConfigurableParser)] +#[name(invert)] +#[keyword("invert")] +#[empty_args(true)] +#[config(filters.get_invert)] +pub struct Invert<'a>(pub &'a str); + +impl<'a> IntoDeclaration for Invert<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-invert: invert({})", self.0), + FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash, KeywordConfigurableParser)] +#[name(saturate)] +#[keyword("saturate")] +#[empty_args(false)] +#[config(filters.get_saturate)] +pub struct Saturate<'a>(pub &'a str); + +impl<'a> IntoDeclaration for Saturate<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-saturate: saturate({})", self.0), + FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash, KeywordConfigurableParser)] +#[name(sepia)] +#[keyword("sepia")] +#[empty_args(true)] +#[config(filters.get_sepia)] +pub struct Sepia<'a>(pub &'a str); + +impl<'a> IntoDeclaration for Sepia<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-sepia: sepia({})", self.0), + FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash)] +pub struct BackdropBlur<'a>(pub &'a str); + +impl<'a> IntoDeclaration for BackdropBlur<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-backdrop-blur: blur({})", self.0), + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash)] +pub struct BackdropBrightness<'a>(pub &'a str); + +impl<'a> IntoDeclaration for BackdropBrightness<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-backdrop-brightness: brightness({})", self.0), + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash)] +pub struct BackdropContrast<'a>(pub &'a str); + +impl<'a> IntoDeclaration for BackdropContrast<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-backdrop-contrast: contrast({})", self.0), + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash)] +pub struct BackdropGrayscale<'a>(pub &'a str); + +impl<'a> IntoDeclaration for BackdropGrayscale<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-backdrop-grayscale: grayscale({})", self.0), + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash)] +pub struct BackdropHueRotate(pub String); + +impl<'a> IntoDeclaration for BackdropHueRotate { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-backdrop-hue-rotate: hue-rotate({})", self.0), + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash)] +pub struct BackdropInvert<'a>(pub &'a str); + +impl<'a> IntoDeclaration for BackdropInvert<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-backdrop-invert: invert({})", self.0), + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash, KeywordConfigurableParser)] +#[name(backdrop_opacity)] +#[keyword("backdrop-opacity")] +#[empty_args(false)] +#[config(filters.get_backdrop_opacity)] +pub struct BackdropOpacity<'a>(pub &'a str); + +impl<'a> IntoDeclaration for BackdropOpacity<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-backdrop-opacity: opacity({})", self.0), + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash)] +pub struct BackdropSaturate<'a>(pub &'a str); + +impl<'a> IntoDeclaration for BackdropSaturate<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-backdrop-saturate: saturate({})", self.0), + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]) + } +} + +#[derive(Debug, PartialEq, Hash)] +pub struct BackdropSepia<'a>(pub &'a str); + +impl<'a> IntoDeclaration for BackdropSepia<'a> { + fn to_decl(self) -> Decl { + Decl::Vec(vec![ + format!("--tw-backdrop-sepia: sepia({})", self.0), + WEBKIT_BACKDROP_FILTER_STYLE.into(), + BACKDROP_FILTER_STYLE.into(), + ]) + } +} diff --git a/railwind/src/class/filters/types.rs b/railwind/src/class/filters/types.rs deleted file mode 100644 index 1f1aa8a..0000000 --- a/railwind/src/class/filters/types.rs +++ /dev/null @@ -1,266 +0,0 @@ -use crate::class::utils::{get_value, get_value_neg}; -use crate::class::Decl; -use crate::warning::WarningType; -// use crate::utils::{get_args, get_class_name, get_opt_args}; - -use super::{ - BLUR, BRIGHTNESS, CONTRAST, DROP_SHADOW, GRAYSCALE, HUE_ROTATE, INVERT, OPACITY, SATURATE, - SEPIA, -}; - -const FILTER_STYLE: &str = "filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)"; -const WEBKIT_BACKDROP_FILTER_STYLE: &str = "-webkit-backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)"; -const BACKDROP_FILTER_STYLE: &str = " backdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia)"; - -#[derive(Debug, PartialEq, Hash)] -pub struct Blur<'a>(pub &'a str); - -impl<'a> Blur<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &BLUR)?; - Ok(Decl::Double([ - format!("--tw-blur: blur({})", value), - FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct Brightness<'a>(pub &'a str); - -impl<'a> Brightness<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &BRIGHTNESS)?; - Ok(Decl::Double([ - format!("--tw-brightness: brightness({})", value), - FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct Contrast<'a>(pub &'a str); - -impl<'a> Contrast<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &CONTRAST)?; - Ok(Decl::Double([ - format!("--tw-contrast: contrast({})", value), - FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct DropShadow<'a>(pub &'a str); - -impl<'a> DropShadow<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &DROP_SHADOW)?; - Ok(Decl::Double([ - format!("--tw-drop-shadow: drop-shadow({})", value), - FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct Grayscale<'a>(pub &'a str); - -impl<'a> Grayscale<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &GRAYSCALE)?; - Ok(Decl::Double([ - format!("--tw-grayscale: grayscale({})", value), - FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct HueRotate<'a>(pub &'a str, bool); - -impl<'a> HueRotate<'a> { - pub fn new(name: &'a str, arg: &'a str) -> Self { - let negative = name.starts_with('-'); - Self(arg, negative) - } - - pub fn to_decl(self) -> Result { - let value = get_value_neg(self.1, self.0, &HUE_ROTATE)?; - Ok(Decl::Double([ - format!("--tw-hue-rotate: hue-rotate({})", value), - FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct Invert<'a>(pub &'a str); - -impl<'a> Invert<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &INVERT)?; - Ok(Decl::Double([ - format!("--tw-invert: invert({})", value), - FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct Saturate<'a>(pub &'a str); - -impl<'a> Saturate<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &SATURATE)?; - Ok(Decl::Double([ - format!("--tw-saturate: saturate({})", value), - FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct Sepia<'a>(pub &'a str); - -impl<'a> Sepia<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &SEPIA)?; - Ok(Decl::Double([ - format!("--tw-sepia: sepia({})", value), - FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct BackdropBlur<'a>(pub &'a str); - -impl<'a> BackdropBlur<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &BLUR)?; - Ok(Decl::Triple([ - format!("--tw-backdrop-blur: blur({})", value), - WEBKIT_BACKDROP_FILTER_STYLE.into(), - BACKDROP_FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct BackdropBrightness<'a>(pub &'a str); - -impl<'a> BackdropBrightness<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &BRIGHTNESS)?; - Ok(Decl::Triple([ - format!("--tw-backdrop-brightness: brightness({})", value), - WEBKIT_BACKDROP_FILTER_STYLE.into(), - BACKDROP_FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct BackdropContrast<'a>(pub &'a str); - -impl<'a> BackdropContrast<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &CONTRAST)?; - Ok(Decl::Triple([ - format!("--tw-backdrop-contrast: contrast({})", value), - WEBKIT_BACKDROP_FILTER_STYLE.into(), - BACKDROP_FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct BackdropGrayscale<'a>(pub &'a str); - -impl<'a> BackdropGrayscale<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &GRAYSCALE)?; - Ok(Decl::Triple([ - format!("--tw-backdrop-grayscale: grayscale({})", value), - WEBKIT_BACKDROP_FILTER_STYLE.into(), - BACKDROP_FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct BackdropHueRotate<'a>(pub &'a str, bool); - -impl<'a> BackdropHueRotate<'a> { - pub fn new(name: &'a str, arg: &'a str) -> Self { - let negative = name.starts_with('-'); - Self(arg, negative) - } - - pub fn to_decl(self) -> Result { - let value = get_value_neg(self.1, self.0, &HUE_ROTATE)?; - Ok(Decl::Triple([ - format!("--tw-backdrop-hue-rotate: hue-rotate({})", value), - WEBKIT_BACKDROP_FILTER_STYLE.into(), - BACKDROP_FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct BackdropInvert<'a>(pub &'a str); - -impl<'a> BackdropInvert<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &INVERT)?; - Ok(Decl::Triple([ - format!("--tw-backdrop-invert: invert({})", value), - WEBKIT_BACKDROP_FILTER_STYLE.into(), - BACKDROP_FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct BackdropOpacity<'a>(pub &'a str); - -impl<'a> BackdropOpacity<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &OPACITY)?; - Ok(Decl::Triple([ - format!("--tw-backdrop-opacity: opacity({})", value), - WEBKIT_BACKDROP_FILTER_STYLE.into(), - BACKDROP_FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct BackdropSaturate<'a>(pub &'a str); - -impl<'a> BackdropSaturate<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &SATURATE)?; - Ok(Decl::Triple([ - format!("--tw-backdrop-saturate: saturate({})", value), - WEBKIT_BACKDROP_FILTER_STYLE.into(), - BACKDROP_FILTER_STYLE.into(), - ])) - } -} - -#[derive(Debug, PartialEq, Hash)] -pub struct BackdropSepia<'a>(pub &'a str); - -impl<'a> BackdropSepia<'a> { - pub fn to_decl(self) -> Result { - let value = get_value(self.0, &SEPIA)?; - Ok(Decl::Triple([ - format!("--tw-backdrop-sepia: sepia({})", value), - WEBKIT_BACKDROP_FILTER_STYLE.into(), - BACKDROP_FILTER_STYLE.into(), - ])) - } -} diff --git a/railwind/src/class/utils.rs b/railwind/src/class/utils.rs index f863c43..f8a626b 100644 --- a/railwind/src/class/utils.rs +++ b/railwind/src/class/utils.rs @@ -20,24 +20,18 @@ pub fn negative_keyword_dash<'a>(keyword: &'a str) -> impl FnMut(&'a str) -> IRe } pub fn arbitrary_hashmap_value<'a>( - hashmap: impl Fn() -> &'a HashMap<&'static str, &'static str>, + hashmap: &'a HashMap<&'static str, &'static str>, ) -> impl FnMut(&'a str) -> IResult<&str, &str> { - alt(( - arbitrary, - map_opt(is_not(" "), move |v| hashmap().get(v).copied()), - )) + alt((arbitrary, map_opt(is_not(" "), |v| hashmap.get(v).copied()))) } pub fn keyword_value<'a>( keyword: &'a str, - hashmap: impl Fn() -> &'a HashMap<&'static str, &'static str>, + hashmap: &'a HashMap<&'static str, &'static str>, ) -> impl FnMut(&'a str) -> IResult<&str, &str> { preceded( terminated(tag(keyword), tag("-")), - alt(( - arbitrary, - map_opt(is_not(" "), move |v| hashmap().get(v).copied()), - )), + alt((arbitrary, map_opt(is_not(" "), |v| hashmap.get(v).copied()))), ) } diff --git a/railwind/src/class/filters/blur.ron b/railwind/src/config/filters/blur.ron similarity index 100% rename from railwind/src/class/filters/blur.ron rename to railwind/src/config/filters/blur.ron diff --git a/railwind/src/class/filters/brightness.ron b/railwind/src/config/filters/brightness.ron similarity index 100% rename from railwind/src/class/filters/brightness.ron rename to railwind/src/config/filters/brightness.ron diff --git a/railwind/src/class/filters/contrast.ron b/railwind/src/config/filters/contrast.ron similarity index 100% rename from railwind/src/class/filters/contrast.ron rename to railwind/src/config/filters/contrast.ron diff --git a/railwind/src/class/filters/drop_shadow.ron b/railwind/src/config/filters/drop_shadow.ron similarity index 100% rename from railwind/src/class/filters/drop_shadow.ron rename to railwind/src/config/filters/drop_shadow.ron diff --git a/railwind/src/class/filters/grayscale.ron b/railwind/src/config/filters/grayscale.ron similarity index 100% rename from railwind/src/class/filters/grayscale.ron rename to railwind/src/config/filters/grayscale.ron diff --git a/railwind/src/class/filters/hue_rotate.ron b/railwind/src/config/filters/hue_rotate.ron similarity index 100% rename from railwind/src/class/filters/hue_rotate.ron rename to railwind/src/config/filters/hue_rotate.ron diff --git a/railwind/src/class/filters/invert.ron b/railwind/src/config/filters/invert.ron similarity index 100% rename from railwind/src/class/filters/invert.ron rename to railwind/src/config/filters/invert.ron diff --git a/railwind/src/class/filters/opacity.ron b/railwind/src/config/filters/opacity.ron similarity index 100% rename from railwind/src/class/filters/opacity.ron rename to railwind/src/config/filters/opacity.ron diff --git a/railwind/src/class/filters/saturate.ron b/railwind/src/config/filters/saturate.ron similarity index 100% rename from railwind/src/class/filters/saturate.ron rename to railwind/src/config/filters/saturate.ron diff --git a/railwind/src/class/filters/sepia.ron b/railwind/src/config/filters/sepia.ron similarity index 100% rename from railwind/src/class/filters/sepia.ron rename to railwind/src/config/filters/sepia.ron diff --git a/railwind/src/config/mod.rs b/railwind/src/config/mod.rs index 06bcd2d..d1fea7c 100644 --- a/railwind/src/config/mod.rs +++ b/railwind/src/config/mod.rs @@ -9,6 +9,7 @@ pub struct Config { pub spacing: SpacingConfig, pub borders: BordersConfig, pub effects: EffectsConfig, + pub filters: FiltersConfig, } #[derive(GetOnceCell, Default)] @@ -91,3 +92,36 @@ pub struct EffectsConfig { #[config_path("effects/opacity.ron")] opacity: OnceCell>, } + +#[derive(GetOnceCell, Default)] +pub struct FiltersConfig { + #[config_path("filters/blur.ron")] + blur: OnceCell>, + + #[config_path("filters/brightness.ron")] + brightness: OnceCell>, + + #[config_path("filters/contrast.ron")] + contrast: OnceCell>, + + #[config_path("filters/drop_shadow.ron")] + drop_shadow: OnceCell>, + + #[config_path("filters/grayscale.ron")] + grayscale: OnceCell>, + + #[config_path("filters/hue_rotate.ron")] + hue_rotate: OnceCell>, + + #[config_path("filters/invert.ron")] + invert: OnceCell>, + + #[config_path("filters/saturate.ron")] + saturate: OnceCell>, + + #[config_path("filters/sepia.ron")] + sepia: OnceCell>, + + #[config_path("filters/opacity.ron")] + backdrop_opacity: OnceCell>, +}