From 53866802ef7ee8cd97fd161a29d71c5a9c571c3f Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Thu, 3 Nov 2022 08:48:58 +0000 Subject: [PATCH] feat: add the whitespace plugin --- crates/tailwind-parse/src/lib.rs | 10 ++++++++++ src/parse/literal.rs | 1 + src/plugin.rs | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/tailwind-parse/src/lib.rs b/crates/tailwind-parse/src/lib.rs index 39f6d30..d12c1e1 100644 --- a/crates/tailwind-parse/src/lib.rs +++ b/crates/tailwind-parse/src/lib.rs @@ -66,6 +66,7 @@ mod plugin { Pointer, Ease, Order, + Whitespace(Whitespace), From, To, Outline, @@ -101,6 +102,15 @@ mod plugin { Sr, } + #[derive(Copy, Clone, Eq, PartialEq, Debug)] + pub enum Whitespace { + Normal, + Nowrap, + Pre, + PreLine, + PreWrap, + } + #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum Gap { X, diff --git a/src/parse/literal.rs b/src/parse/literal.rs index 3e4ce96..e070a05 100644 --- a/src/parse/literal.rs +++ b/src/parse/literal.rs @@ -29,6 +29,7 @@ pub fn parse_literal<'a>(theme: &TailwindTheme, lit: Literal<'a>) -> Result return plugin::flex(f, lit.value, theme).ok_or(lit.full), Grid(g) => return plugin::grid(g, lit.value, theme).ok_or(lit.full), Object(o) => return plugin::object(o, lit.value, theme).ok_or(lit.full), + Whitespace(ws) => return plugin::white_space(ws, lit.value, theme).ok_or(lit.full), // all other plugins Text => Required(plugin::text), diff --git a/src/plugin.rs b/src/plugin.rs index 877fb37..115edb1 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -12,7 +12,7 @@ use swc_core::{ }; use tailwind_parse::{ Border, Display, Flex, Grid, Object, Position, Rounded, TextDecoration, TextTransform, - Visibility, + Visibility, Whitespace, }; macro_rules! lookup_plugin { @@ -525,6 +525,21 @@ pub fn object(o: Object, _rest: Option, _theme: &TailwindTheme) -> Some(to_lit(&rule)) } +pub fn white_space( + o: Whitespace, + _rest: Option, + _theme: &TailwindTheme, +) -> Option { + let rule = match o { + Whitespace::Normal => [("whiteSpace", "normal")], + Whitespace::Nowrap => [("whiteSpace", "nowrap")], + Whitespace::Pre => [("whiteSpace", "pre")], + Whitespace::PreLine => [("whiteSpace", "pre-line")], + Whitespace::PreWrap => [("whiteSpace", "pre-wrap")], + }; + Some(to_lit(&rule)) +} + pub fn col(rest: &str, theme: &TailwindTheme) -> Option { simple_lookup(&theme.grid_column, rest, "gridColumn").or_else(|| match rest.split_once('-') { Some(("start", rest)) => simple_lookup(&theme.grid_column_start, rest, "gridColumnStart"),