unocss_classes/
lib.rs

1/// Builds a single [String] from provided string-like arguments and transforms
2/// Variant Groups in string literals. The transformation is executed at compile time,
3/// so dynamic values are not supported. In such scenario, use [to_uno!] instead.
4///
5/// # Example
6///
7/// ```
8/// use unocss_classes::uno;
9///
10/// assert_eq!(uno!["text-red"], "text-red");
11///
12/// assert_eq!(
13///     uno!["text-(blue lg)", "placeholder:(italic text-(red sm))"],
14///     "text-blue text-lg placeholder:italic placeholder:text-red placeholder:text-sm"
15/// );
16///
17/// let some = Some("text-red");
18/// let none = None::<String>;
19/// let truthy = true;
20/// let falsy = false;
21/// assert_eq!(uno![
22///         some,
23///         none,
24///         "text-green" => truthy,
25///         "text-black" => falsy,
26///         "",
27///         Some("text-white").map(|_| "text-blue"),
28///         None::<String>,
29///     ],
30///     "text-red text-green text-blue"
31/// );
32///
33/// let truthy = true;
34/// assert_eq!(uno!["text-(sm center)" => truthy], "text-sm text-center");
35/// ```
36#[cfg(not(feature = "dioxus"))]
37#[macro_export]
38macro_rules! uno {
39    ($($t:tt)*) => {
40        unocss_classes::exports::__uno_classes!($($t)*)
41    };
42}
43#[cfg(feature = "dioxus")]
44#[macro_export]
45macro_rules! uno {
46    ($cx:expr; $($t:tt)*) => {
47        {
48            let bump_string =
49                dioxus::core::exports::bumpalo::collections::String::from_str_in(
50                    &unocss_classes::uno!($($t)*),
51                    $cx.bump()
52                );
53            bump_string.into_bump_str()
54        }
55    };
56
57    ($($t:tt)*) => {
58        unocss_classes::exports::__uno_classes!($($t)*)
59    };
60}
61
62/// Builds a single [String] from provided string-like arguments and transforms
63/// Variant Groups in string literals. **The transformation is executed at runtime**,
64/// so unlike [uno!] it has a performace penalty, but can handle dynamic text.
65/// Use it only when necessary.
66///
67/// # Example
68///
69/// ```
70/// use unocss_classes::to_uno;
71///
72/// let mut dynamic_string = String::from("text-(");
73/// dynamic_string.push_str("red sm)");
74/// assert_eq!(
75///     to_uno![
76///         dynamic_string,
77///         Some("fw500"),
78///         "op".to_string() + "-50"
79///     ],
80///     "text-red text-sm fw500 op-50"
81/// );
82/// ```
83#[cfg(feature = "runtime")]
84#[macro_export]
85macro_rules! to_uno {
86    ($cx:expr; $($t:tt)*) => {
87        unocss_classes::uno!(
88            $cx;
89            unocss_classes::to_uno!($($t)*)
90        )
91    };
92
93    ($($t:tt)*) => {
94        unocss_classes::exports::__transform_variant_groups(
95            unocss_classes::uno!($($t)*)
96        )
97    };
98}
99
100pub mod exports {
101    pub use classes;
102    pub use unocss_classes_macros::uno_classes as __uno_classes;
103
104    #[cfg(feature = "runtime")]
105    pub use unocss_classes_utils::transform_variant_groups as __transform_variant_groups;
106}