crate
weft_tailwind
weft-tailwind
A native, just-in-time Tailwind CSS engine written in Rust. It turns class names into CSS on demand — in the browser (inside the Wasm module, as elements appear) or on the server (for prerendered pages) — with no Node.js toolchain and no content scanning.
use weft_tailwind::{Stylesheet, Theme};
let mut sheet = Stylesheet::new(Theme::default());
sheet.add_classes("flex items-center gap-4 rounded-xl bg-gradient-to-r from-pink-500 to-violet-500 md:hover:scale-105");
assert!(sheet.css().contains(".gap-4{gap:1rem}"));Supported: the full default palette with /opacity modifiers, spacing and sizing scales, typography, flexbox/grid, borders/radius/rings, shadows (with colored shadows), gradients (bg-linear-*, bg-radial, from/via/to), filters & backdrop filters, transforms (incl. 3D), transitions and animations, arbitrary values (w-[37px]), CSS-variable values (bg-(--brand)), arbitrary properties ([mask-type:luminance]), !important, negative values, and variants: responsive (sm:…2xl:, max-*:), states (hover:, focus-visible:, disabled:…), structural (first:, odd:…), group-*:/peer-*:, aria-*:, data-*:, pseudo-elements (before:, placeholder:…), dark:, motion-safe:, motion-reduce:, contrast-more:, print:, *: and [&_selector]:.
Structs
- Engine
Turns class names into rules using a
Theme. - Rule
A generated CSS rule for one class.
- SortKey
Ordering key: media (breakpoints, then other media) → variants → utility rank, mirroring Tailwind's precedence rules.
- Stylesheet
Rules for every class seen so far, emitted in precedence order.
- Theme
Colors and fonts available to utilities.
Functions
escape_class
pub fn escape_class(class: &str) -> StringEscape a class name for use in a CSS selector.
merge
pub fn merge(classes: &str, engine: &Engine) -> StringMerge a space-separated class list; later classes win.
merge_override
pub fn merge_override(component: &str, caller: &str, engine: &Engine) -> StringCombine a component's own classes with the caller's so the caller's win — including over the component's responsive and state variants.
A component class is dropped when a caller class sets all of its properties wherever it applies (px-4 removes px-6, md:px-8 and hover:px-2; md:px-4 removes lg:px-8 but not px-6). When they only share some properties (md:p-8 against px-4), the component class stays for the rest and the caller's is made !important. The caller's own classes are then merged normally (later wins).
mix_hex
pub fn mix_hex(a: &str, b: &str, t: f64) -> StringLinear blend of two hex colors (t = 0 → a, 1 → b).
split_modifier
pub fn split_modifier(v: &str) -> (&str, Option<&str>)Split value/modifier at the last top-level /.
split_variants
pub fn split_variants(class: &str) -> Vec<&str>Split md:hover:p-4 into variants and the utility, ignoring : inside […] / (…).
stylesheet_for
pub fn stylesheet_for<'a>(classes: impl IntoIterator<Item = &'a str>, theme: &Theme) -> StringOne-shot stylesheet (with preflight) for a set of classes.
with_alpha
pub fn with_alpha(color: &str, alpha: f64) -> StringA color with an alpha channel applied.
Constants
FONT_SERIF
pub const FONT_SERIF: &str = "ui-serif, Georgia, Cambria, \"Times New Roman\", Times, serif";Tailwind's default font-serif stack.
PREFLIGHT
pub const PREFLIGHT: &str = …;Tailwind's base reset (modern-normalize + opinionated defaults).
SHADES
pub const SHADES: [&str; 11] = _;The shades of a colour scale, lightest first: brand-50 to brand-950.