From 62262dea320743f72e1352c15b93f8727a08b949 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 18 Sep 2021 20:14:24 -0700 Subject: [PATCH 1/4] Remove usages of Data.Tuple.Nested. Data.Tuple.Nested moved to meaning extensible tuples, which implies ending the Tuple in Unit. This added Unit causes an extra space to be added to a tuple-backed CSS rule, like animation. In addition, we aren't using tuple-combinators, which extensible tuples enables. --- src/CSS/Animation.purs | 4 +++- src/CSS/Border.purs | 8 ++++++-- src/CSS/Geometry.purs | 9 ++++++--- src/CSS/Property.purs | 2 -- test/Main.purs | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/CSS/Animation.purs b/src/CSS/Animation.purs index 3804225..6c45e51 100644 --- a/src/CSS/Animation.purs +++ b/src/CSS/Animation.purs @@ -7,7 +7,8 @@ import CSS.Stylesheet (CSS, key) import CSS.Time (Time) import CSS.Transition (TimingFunction) import Data.Foldable (for_) -import Data.Tuple.Nested (tuple7) +import Data.Generic (class Generic) +import Data.Tuple (Tuple(..)) newtype AnimationDirection = AnimationDirection Value @@ -68,6 +69,7 @@ animation p de f du i di fm = do , "-moz-animation" , "-o-animation" ] + tuple7 a b c d e f g = Tuple a ( Tuple b (Tuple c (Tuple d (Tuple e (Tuple f g))))) newtype AnimationName = AnimationName Value diff --git a/src/CSS/Border.purs b/src/CSS/Border.purs index 5a73227..86a7bf4 100644 --- a/src/CSS/Border.purs +++ b/src/CSS/Border.purs @@ -2,13 +2,13 @@ module CSS.Border where import Prelude -import Data.Tuple.Nested (tuple3, tuple4) - import CSS.Color (Color) import CSS.Property (class Val, Value) import CSS.Size (Size, Abs) import CSS.String (fromString) import CSS.Stylesheet (CSS, key) +import Data.Generic (class Generic) +import Data.Tuple (Tuple(..)) newtype Stroke = Stroke Value @@ -47,6 +47,8 @@ outset = Stroke $ fromString "outset" border :: Stroke -> Size Abs -> Color -> CSS border a b c = key (fromString "border") $ tuple3 a b c + where + tuple3 a b c = Tuple a (Tuple b c) borderTop :: Stroke -> Size Abs -> Color -> CSS borderTop a b c = key (fromString "border-top") $ tuple3 a b c @@ -65,6 +67,8 @@ borderColor = key $ fromString "border-color" borderRadius :: forall a. Size a -> Size a -> Size a -> Size a -> CSS borderRadius a b c d = key (fromString "border-radius") (tuple4 a b c d) + where + tuple4 a b c d = Tuple a (Tuple b (Tuple c d)) borderSpacing :: forall a. Size a -> CSS borderSpacing = key $ fromString "border-spacing" diff --git a/src/CSS/Geometry.purs b/src/CSS/Geometry.purs index ad31e00..0679d04 100644 --- a/src/CSS/Geometry.purs +++ b/src/CSS/Geometry.purs @@ -1,11 +1,10 @@ module CSS.Geometry where -import Data.Function (($)) -import Data.Tuple.Nested (tuple4) - import CSS.Size (Size) import CSS.String (fromString) import CSS.Stylesheet (CSS, key) +import Data.Function (($)) +import Data.Tuple (Tuple(..)) width :: forall a. Size a -> CSS width = key $ fromString "width" @@ -39,6 +38,8 @@ right = key $ fromString "right" padding :: forall a. Size a -> Size a -> Size a -> Size a -> CSS padding a b c d = key (fromString "padding") $ tuple4 a b c d + where + tuple4 a b c d = Tuple a (Tuple b (Tuple c d)) paddingTop :: forall a. Size a -> CSS paddingTop = key $ fromString "padding-top" @@ -54,6 +55,8 @@ paddingRight = key $ fromString "padding-right" margin :: forall a. Size a -> Size a -> Size a -> Size a -> CSS margin a b c d = key (fromString "margin") $ tuple4 a b c d + where + tuple4 a b c d = Tuple a (Tuple b (Tuple c d)) marginTop :: forall a. Size a -> CSS marginTop = key $ fromString "margin-top" diff --git a/src/CSS/Property.purs b/src/CSS/Property.purs index 921e04b..1beac6e 100644 --- a/src/CSS/Property.purs +++ b/src/CSS/Property.purs @@ -85,8 +85,6 @@ instance valString :: Val String where instance valUnit :: Val Unit where value _ = fromString "" --- When `b` is Unit, the rendered value will have an extra --- space appended to end. Shouldn't hurt. I'd fix if I knew how. instance valTuple :: (Val a, Val b) => Val (Tuple a b) where value (Tuple a b) = value a <> fromString " " <> value b diff --git a/test/Main.purs b/test/Main.purs index 60d32be..4ed4913 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -162,7 +162,7 @@ main :: Effect Unit main = do renderedInline example1 `assertEqual` Just "color: hsl(0.0, 100.0%, 50.0%); display: block" renderedInline example2 `assertEqual` Just "display: inline-block" - renderedInline example3 `assertEqual` Just "border: dashed 2.0px hsl(240.0, 100.0%, 50.0%) " + renderedInline example3 `assertEqual` Just "border: dashed 2.0px hsl(240.0, 100.0%, 50.0%)" selector (Selector (Refinement [Id "test"]) Star) `assertEqual` "#test" From d539dc225f7556128c36beda3eea285caddb05d4 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 18 Sep 2021 20:22:40 -0700 Subject: [PATCH 2/4] Inline nested tuples and use tree-based approach Current approach is list-like: Tuple a (Tuple b (Tuple c d)) New approach is tree-like Tuple (Tuple a b) (Tuple c d) --- src/CSS/Animation.purs | 3 +-- src/CSS/Border.purs | 16 ++++++---------- src/CSS/Geometry.purs | 8 ++------ src/CSS/ListStyle.purs | 4 ++-- src/CSS/Text/Shadow.purs | 4 ++-- src/CSS/Transform.purs | 4 ++-- 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/CSS/Animation.purs b/src/CSS/Animation.purs index 6c45e51..e0ab6b6 100644 --- a/src/CSS/Animation.purs +++ b/src/CSS/Animation.purs @@ -61,7 +61,7 @@ backwards = FillMode $ fromString "backwards" animation :: AnimationName -> Time -> TimingFunction -> Time -> IterationCount -> AnimationDirection -> FillMode -> CSS animation p de f du i di fm = do for_ animationKeys \k -> - key (fromString k) (tuple7 p de f du i di fm) + key (fromString k) (Tuple (Tuple (Tuple p de) (Tuple f du)) (Tuple (Tuple i di) fm)) where animationKeys = [ "animation" @@ -69,7 +69,6 @@ animation p de f du i di fm = do , "-moz-animation" , "-o-animation" ] - tuple7 a b c d e f g = Tuple a ( Tuple b (Tuple c (Tuple d (Tuple e (Tuple f g))))) newtype AnimationName = AnimationName Value diff --git a/src/CSS/Border.purs b/src/CSS/Border.purs index 86a7bf4..a0caa3f 100644 --- a/src/CSS/Border.purs +++ b/src/CSS/Border.purs @@ -46,29 +46,25 @@ outset :: Stroke outset = Stroke $ fromString "outset" border :: Stroke -> Size Abs -> Color -> CSS -border a b c = key (fromString "border") $ tuple3 a b c - where - tuple3 a b c = Tuple a (Tuple b c) +border a b c = key (fromString "border") (Tuple a (Tuple b c)) borderTop :: Stroke -> Size Abs -> Color -> CSS -borderTop a b c = key (fromString "border-top") $ tuple3 a b c +borderTop a b c = key (fromString "border-top") (Tuple a (Tuple b c)) borderBottom :: Stroke -> Size Abs -> Color -> CSS -borderBottom a b c = key (fromString "border-bottom") $ tuple3 a b c +borderBottom a b c = key (fromString "border-bottom") (Tuple a (Tuple b c)) borderLeft :: Stroke -> Size Abs -> Color -> CSS -borderLeft a b c = key (fromString "border-left") $ tuple3 a b c +borderLeft a b c = key (fromString "border-left") (Tuple a (Tuple b c)) borderRight :: Stroke -> Size Abs -> Color -> CSS -borderRight a b c = key (fromString "border-right") $ tuple3 a b c +borderRight a b c = key (fromString "border-right") (Tuple a (Tuple b c)) borderColor :: Color -> CSS borderColor = key $ fromString "border-color" borderRadius :: forall a. Size a -> Size a -> Size a -> Size a -> CSS -borderRadius a b c d = key (fromString "border-radius") (tuple4 a b c d) - where - tuple4 a b c d = Tuple a (Tuple b (Tuple c d)) +borderRadius a b c d = key (fromString "border-radius") (Tuple (Tuple a b) (Tuple c d)) borderSpacing :: forall a. Size a -> CSS borderSpacing = key $ fromString "border-spacing" diff --git a/src/CSS/Geometry.purs b/src/CSS/Geometry.purs index 0679d04..ef79662 100644 --- a/src/CSS/Geometry.purs +++ b/src/CSS/Geometry.purs @@ -37,9 +37,7 @@ right :: forall a. Size a -> CSS right = key $ fromString "right" padding :: forall a. Size a -> Size a -> Size a -> Size a -> CSS -padding a b c d = key (fromString "padding") $ tuple4 a b c d - where - tuple4 a b c d = Tuple a (Tuple b (Tuple c d)) +padding a b c d = key (fromString "padding") (Tuple (Tuple a b) (Tuple c d)) paddingTop :: forall a. Size a -> CSS paddingTop = key $ fromString "padding-top" @@ -54,9 +52,7 @@ paddingRight :: forall a. Size a -> CSS paddingRight = key $ fromString "padding-right" margin :: forall a. Size a -> Size a -> Size a -> Size a -> CSS -margin a b c d = key (fromString "margin") $ tuple4 a b c d - where - tuple4 a b c d = Tuple a (Tuple b (Tuple c d)) +margin a b c d = key (fromString "margin") (Tuple (Tuple a b) (Tuple c d)) marginTop :: forall a. Size a -> CSS marginTop = key $ fromString "margin-top" diff --git a/src/CSS/ListStyle.purs b/src/CSS/ListStyle.purs index 139a1e6..073ad21 100644 --- a/src/CSS/ListStyle.purs +++ b/src/CSS/ListStyle.purs @@ -6,12 +6,12 @@ import CSS.ListStyle.Type (ListStyleType) import CSS.Property (class Val, value) import CSS.String (fromString) import CSS.Stylesheet (CSS, key) -import Data.Tuple.Nested (tuple3) +import Data.Tuple (Tuple(..)) data ListStyle = ListStyle ListStyleType ListStylePosition ListStyleImage instance valueListStyle :: Val ListStyle where - value (ListStyle t p i) = value (tuple3 t p i) + value (ListStyle t p i) = value (Tuple t (Tuple p i)) listStyle :: ListStyleType -> ListStylePosition -> ListStyleImage -> CSS listStyle t p i = key (fromString "list-style") (ListStyle t p i) diff --git a/src/CSS/Text/Shadow.purs b/src/CSS/Text/Shadow.purs index 66bd67d..82d40f4 100644 --- a/src/CSS/Text/Shadow.purs +++ b/src/CSS/Text/Shadow.purs @@ -6,7 +6,7 @@ import CSS.Property (class Val, value) import CSS.Size (Size) import CSS.String (fromString) import CSS.Stylesheet (CSS, key) -import Data.Tuple.Nested (tuple4) +import Data.Tuple (Tuple(..)) data TextShadow :: Type -> Type data TextShadow a @@ -16,7 +16,7 @@ data TextShadow a | Inherit instance valTextShadow :: Val (TextShadow a) where - value (TextShadow h v b c) = value (tuple4 h v b c) + value (TextShadow h v b c) = value (Tuple (Tuple h v) (Tuple b c)) value (None) = fromString "none" value (Initial) = fromString "initial" value (Inherit) = fromString "inherit" diff --git a/src/CSS/Transform.purs b/src/CSS/Transform.purs index 4af4612..ab8d94f 100644 --- a/src/CSS/Transform.purs +++ b/src/CSS/Transform.purs @@ -6,7 +6,7 @@ import CSS.Property (class Val, Value, noCommas, value) import CSS.Size (Angle, Size) import CSS.String (fromString) import CSS.Stylesheet (CSS, key) -import Data.Tuple.Nested (tuple3) +import Data.Tuple (Tuple(..)) newtype Transformation = Transformation Value @@ -124,7 +124,7 @@ instance valTransformOriginOffset :: Val (TransformOriginOffset a) where value (OffsetCenter) = fromString "center" instance valTransformOrigin :: Val (TransformOrigin a) where - value (TransformOrigin x y z) = value (tuple3 x y z) + value (TransformOrigin x y z) = value (Tuple (Tuple x y) z) value (Initial) = fromString "initial" value (Inherit) = fromString "inherit" value (Unset) = fromString "unset" From f2c99ad7376657bdcf0e08051ca885081c447d35 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 18 Sep 2021 20:22:54 -0700 Subject: [PATCH 3/4] Remove unneeded generic import --- src/CSS/Animation.purs | 1 - src/CSS/Border.purs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/CSS/Animation.purs b/src/CSS/Animation.purs index e0ab6b6..c25d39a 100644 --- a/src/CSS/Animation.purs +++ b/src/CSS/Animation.purs @@ -7,7 +7,6 @@ import CSS.Stylesheet (CSS, key) import CSS.Time (Time) import CSS.Transition (TimingFunction) import Data.Foldable (for_) -import Data.Generic (class Generic) import Data.Tuple (Tuple(..)) newtype AnimationDirection = AnimationDirection Value diff --git a/src/CSS/Border.purs b/src/CSS/Border.purs index a0caa3f..8bb940d 100644 --- a/src/CSS/Border.purs +++ b/src/CSS/Border.purs @@ -7,7 +7,6 @@ import CSS.Property (class Val, Value) import CSS.Size (Size, Abs) import CSS.String (fromString) import CSS.Stylesheet (CSS, key) -import Data.Generic (class Generic) import Data.Tuple (Tuple(..)) newtype Stroke = Stroke Value From 352e83bba201eea5ac03027d117bbbbef5bdca4a Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 18 Sep 2021 20:24:51 -0700 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b7ce67..73cad52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ New features: Bugfixes: Other improvements: +- Remove ending space in css output (e.g. `padding: 1 2 3 4 `) (#135 by @chexxor and @JordanMartinez) ## [v5.0.1](https://github.com/purescript-contrib/purescript-css/releases/tag/v5.0.1) - 2021-04-19