From c5ca4cc494719b6da3cb53d52306b96c9f4f58ad Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Fri, 20 Nov 2015 18:35:48 +0000 Subject: [PATCH] Fix many warnings, update to latest generics, update docs, etc --- .travis.yml | 13 +- README.md | 17 +- bower.json | 7 +- package.json | 4 +- site/Main.purs | 50 ++-- src/{Css => CSS}/Animation.purs | 14 +- src/{Css => CSS}/Background.purs | 14 +- src/{Css => CSS}/Border.purs | 18 +- src/CSS/Color.purs | 473 +++++++++++++++++++++++++++++++ src/{Css => CSS}/Display.purs | 12 +- src/{Css => CSS}/Elements.purs | 6 +- src/{Css => CSS}/Font.purs | 20 +- src/{Css => CSS}/FontFace.purs | 12 +- src/{Css => CSS}/Geometry.purs | 48 ++-- src/{Css => CSS}/Gradient.purs | 12 +- src/{Css => CSS}/Media.purs | 10 +- src/{Css => CSS}/Property.purs | 8 +- src/{Css => CSS}/Pseudo.purs | 6 +- src/{Css => CSS}/Render.purs | 10 +- src/{Css => CSS}/Selector.purs | 11 +- src/{Css => CSS}/Size.purs | 6 +- src/{Css => CSS}/String.purs | 2 +- src/{Css => CSS}/Stylesheet.purs | 24 +- src/{Css => CSS}/Text.purs | 10 +- src/{Css => CSS}/Time.purs | 6 +- src/{Css => CSS}/Transform.purs | 14 +- src/{Css => CSS}/Transition.purs | 6 +- src/Css/Color.purs | 177 ------------ test/Main.purs | 20 +- 29 files changed, 677 insertions(+), 353 deletions(-) rename src/{Css => CSS}/Animation.purs (89%) rename src/{Css => CSS}/Background.purs (59%) rename src/{Css => CSS}/Border.purs (81%) create mode 100644 src/CSS/Color.purs rename src/{Css => CSS}/Display.purs (93%) rename src/{Css => CSS}/Elements.purs (84%) rename src/{Css => CSS}/Font.purs (81%) rename src/{Css => CSS}/FontFace.purs (85%) rename src/{Css => CSS}/Geometry.purs (52%) rename src/{Css => CSS}/Gradient.purs (81%) rename src/{Css => CSS}/Media.purs (66%) rename src/{Css => CSS}/Property.purs (93%) rename src/{Css => CSS}/Pseudo.purs (51%) rename src/{Css => CSS}/Render.purs (98%) rename src/{Css => CSS}/Selector.purs (92%) rename src/{Css => CSS}/Size.purs (93%) rename src/{Css => CSS}/String.purs (85%) rename src/{Css => CSS}/Stylesheet.purs (79%) rename src/{Css => CSS}/Text.purs (83%) rename src/{Css => CSS}/Time.purs (79%) rename src/{Css => CSS}/Transform.purs (74%) rename src/{Css => CSS}/Transition.purs (81%) delete mode 100644 src/Css/Color.purs diff --git a/.travis.yml b/.travis.yml index 8604993..94728ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,17 @@ language: node_js sudo: false node_js: - - 0.10 -env: - - PATH=$HOME/bin:$PATH + - 4 install: - - mkdir $HOME/bin - npm install bower gulp -g - npm install && bower install script: - gulp +after_success: +- >- + test $TRAVIS_TAG && + node_modules/.bin/psc-publish > .pursuit.json && + curl -X POST http://pursuit.purescript.org/packages \ + -d @.pursuit.json \ + -H 'Accept: application/json' \ + -H "Authorization: token ${GITHUB_TOKEN}" diff --git a/README.md b/README.md index 711b880..86913f3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ # purescript-css -A clean, type-safe library for describing, manipulating and rendering CSS + +[![Latest release](http://img.shields.io/bower/v/purescript-css.svg)](https://github.com/slamdata/purescript-css/releases) +[![Build Status](https://travis-ci.org/slamdata/purescript-css.svg?branch=master)](https://travis-ci.org/slamdata/purescript-css) +[![Dependency Status](https://www.versioneye.com/user/projects/564f5f32ff016c002c00052d/badge.svg?style=flat)](https://www.versioneye.com/user/projects/564f5f32ff016c002c00052d) + +A type-safe library for describing, manipulating, and rendering CSS. + +## Installation + +``` +bower install purescript-css +``` + +## Documentation + +Module documentation is published on Pursuit: [http://pursuit.purescript.org/packages/purescript-css](http://pursuit.purescript.org/packages/purescript-css) diff --git a/bower.json b/bower.json index a6330ca..064e8ad 100644 --- a/bower.json +++ b/bower.json @@ -8,7 +8,11 @@ "purescript", "css" ], - "license": "MIT", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "git://github.com/slamdata/purescript-css.git" + }, "ignore": [ "**/.*", "node_modules", @@ -17,6 +21,7 @@ "tests" ], "dependencies": { + "purescript-generics": "^0.7.0", "purescript-nonempty": "^0.1.2", "purescript-profunctor": "^0.3.1", "purescript-strings": "^0.7.0", diff --git a/package.json b/package.json index a15e718..7c27cb6 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "private": true, "devDependencies": { - "purescript": "^0.7.4", "gulp": "^3.8.11", "gulp-jscs": "^1.6.0", "gulp-jshint": "^1.11.2", "gulp-purescript": "^0.7.0", - "gulp-run": "^1.6.8" + "gulp-run": "^1.6.8", + "purescript": "^0.7.6-rc.1" } } diff --git a/site/Main.purs b/site/Main.purs index 13c4c41..6ebe76c 100644 --- a/site/Main.purs +++ b/site/Main.purs @@ -1,27 +1,27 @@ module Site where import Control.Monad.Eff -import Css.Animation -import Css.Background -import Css.Border -import Css.Color -import Css.Display -import Css.Elements -import Css.Font -import Css.FontFace -import Css.Geometry -import Css.Gradient -import qualified Css.Media as M -import Css.Pseudo -import Css.Render -import Css.Selector -import Css.Size -import Css.String -import Css.Stylesheet -import Css.Text -import Css.Time -import Css.Transform -import Css.Transition +import CSS.Animation +import CSS.Background +import CSS.Border +import CSS.Color +import CSS.Display +import CSS.Elements +import CSS.Font +import CSS.FontFace +import CSS.Geometry +import CSS.Gradient +import qualified CSS.Media as M +import CSS.Pseudo +import CSS.Render +import CSS.Selector +import CSS.Size +import CSS.String +import CSS.Stylesheet +import CSS.Text +import CSS.Time +import CSS.Transform +import CSS.Transition import Data.Maybe import Data.Tuple.Nested import DOM @@ -63,13 +63,13 @@ blue1 = rgb 51 136 204 blue2 :: Color blue2 = rgb 238 238 255 -backgroundGradient :: forall a. Angle a -> Css +backgroundGradient :: forall a. Angle a -> CSS backgroundGradient a = backgroundImage $ linearGradient a (ColorPoint white (pct 0)) [] (ColorPoint blue2 (pct 100)) -shake :: (Number -> Number) -> Css +shake :: (Number -> Number) -> CSS shake f = transforms [translate (px (f 3)) nil, rotate (deg (f 2))] -style :: Css +style :: CSS style = do fontFace $ do fontFaceFamily $ fromString "Lato" @@ -108,7 +108,7 @@ style = do (h1 ## hover) ? animation (fromString "buzz-button") (sec 0.15) linear (sec 0) infinite normalAnimationDirection forwards -center :: Number -> Number -> Css +center :: Number -> Number -> CSS center width height = do marginLeft (px $ -width / 2) marginTop (px $ -height / 2) diff --git a/src/Css/Animation.purs b/src/CSS/Animation.purs similarity index 89% rename from src/Css/Animation.purs rename to src/CSS/Animation.purs index 85499e5..e27f41a 100644 --- a/src/Css/Animation.purs +++ b/src/CSS/Animation.purs @@ -1,14 +1,14 @@ -module Css.Animation where +module CSS.Animation where import Prelude import Data.Tuple.Nested (tuple7) -import Css.Property -import Css.String -import Css.Stylesheet -import Css.Time -import Css.Transition +import CSS.Property +import CSS.String +import CSS.Stylesheet +import CSS.Time +import CSS.Transition newtype AnimationDirection = AnimationDirection Value @@ -49,7 +49,7 @@ forwards = FillMode $ fromString "forwards" backwards :: FillMode backwards = FillMode $ fromString "backwards" -animation :: AnimationName -> Time -> TimingFunction -> Time -> IterationCount -> AnimationDirection -> FillMode -> Css +animation :: AnimationName -> Time -> TimingFunction -> Time -> IterationCount -> AnimationDirection -> FillMode -> CSS animation p de f du i di fm = key (fromString "-webkit-animation") (tuple7 p de f du i di fm) newtype AnimationName = AnimationName Value diff --git a/src/Css/Background.purs b/src/CSS/Background.purs similarity index 59% rename from src/Css/Background.purs rename to src/CSS/Background.purs index d5e59f7..4d70af8 100644 --- a/src/Css/Background.purs +++ b/src/CSS/Background.purs @@ -1,13 +1,13 @@ -module Css.Background where +module CSS.Background where import Prelude -import Css.Color -import Css.Property -import Css.String -import Css.Stylesheet +import CSS.Color +import CSS.Property +import CSS.String +import CSS.Stylesheet -backgroundColor :: Color -> Css +backgroundColor :: Color -> CSS backgroundColor = key $ fromString "background-color" newtype BackgroundImage = BackgroundImage Value @@ -15,5 +15,5 @@ newtype BackgroundImage = BackgroundImage Value instance valBackroundImage :: Val BackgroundImage where value (BackgroundImage v) = v -backgroundImage :: BackgroundImage -> Css +backgroundImage :: BackgroundImage -> CSS backgroundImage = key $ fromString "background-image" diff --git a/src/Css/Border.purs b/src/CSS/Border.purs similarity index 81% rename from src/Css/Border.purs rename to src/CSS/Border.purs index a13cc68..d392cca 100644 --- a/src/Css/Border.purs +++ b/src/CSS/Border.purs @@ -1,14 +1,14 @@ -module Css.Border where +module CSS.Border where import Prelude import Data.Tuple.Nested (tuple3, tuple4) -import Css.Color -import Css.Property -import Css.Size -import Css.String -import Css.Stylesheet +import CSS.Color +import CSS.Property +import CSS.Size +import CSS.String +import CSS.Stylesheet newtype Stroke = Stroke Value @@ -42,11 +42,11 @@ inset = Stroke $ fromString "inset" outset :: Stroke outset = Stroke $ fromString "outset" -border :: Stroke -> Size Abs -> Color -> Css +border :: Stroke -> Size Abs -> Color -> CSS border a b c = key (fromString "border") $ tuple3 a b c -borderColor :: Color -> Css +borderColor :: Color -> CSS borderColor = key $ fromString "border-color" -borderRadius :: forall a. Size a -> Size a -> Size a -> Size a -> Css +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) diff --git a/src/CSS/Color.purs b/src/CSS/Color.purs new file mode 100644 index 0000000..bd5d10a --- /dev/null +++ b/src/CSS/Color.purs @@ -0,0 +1,473 @@ +module CSS.Color where + +import Prelude + +import Data.Foldable (intercalate) + +import CSS.Property +import CSS.String + +data Color = Rgba Int Int Int Int + | Hsla Number Number Number Number + | Other Value + +instance isStringColor :: IsString Color where + fromString = Other <<< fromString + +instance valColor :: Val Color where + value (Rgba r g b 255) = Value <<< fromString $ "rgb(" <> intercalate ", " [show r, show g, show b] <> ")" + value (Rgba r g b a) = Value <<< fromString $ "rgba(" <> intercalate ", " [show r, show g, show b, show a] <> ")" + value (Hsla h s l 1.0) = Value <<< fromString $ "hsl(" <> intercalate ", " [show h, show s, show l] <> ")" + value (Hsla h s l a) = Value <<< fromString $ "hsla(" <> intercalate ", " [show h, show s, show l, show a] <> ")" + value (Other v) = v + +rgba :: Int -> Int -> Int -> Int -> Color +rgba = Rgba + +rgb :: Int -> Int -> Int -> Color +rgb r g b = Rgba r g b 255 + +clamp :: Int -> Int +clamp n = if n < 0 then 0 else if n > 255 then 255 else n + +aliceblue :: Color +aliceblue = rgb 240 248 255 + +antiquewhite :: Color +antiquewhite = rgb 250 235 215 + +aqua :: Color +aqua = rgb 0 255 255 + +aquamarine :: Color +aquamarine = rgb 127 255 212 + +azure :: Color +azure = rgb 240 255 255 + +beige :: Color +beige = rgb 245 245 220 + +bisque :: Color +bisque = rgb 255 228 196 + +black :: Color +black = rgb 0 0 0 + +blanchedalmond :: Color +blanchedalmond = rgb 255 235 205 + +blue :: Color +blue = rgb 0 0 255 + +blueviolet :: Color +blueviolet = rgb 138 43 226 + +brown :: Color +brown = rgb 165 42 42 + +burlywood :: Color +burlywood = rgb 222 184 135 + +cadetblue :: Color +cadetblue = rgb 95 158 160 + +chartreuse :: Color +chartreuse = rgb 127 255 0 + +chocolate :: Color +chocolate = rgb 210 105 30 + +coral :: Color +coral = rgb 255 127 80 + +cornflowerblue :: Color +cornflowerblue = rgb 100 149 237 + +cornsilk :: Color +cornsilk = rgb 255 248 220 + +crimson :: Color +crimson = rgb 220 20 60 + +cyan :: Color +cyan = rgb 0 255 255 + +darkblue :: Color +darkblue = rgb 0 0 139 + +darkcyan :: Color +darkcyan = rgb 0 139 139 + +darkgoldenrod :: Color +darkgoldenrod = rgb 184 134 11 + +darkgray :: Color +darkgray = rgb 169 169 169 + +darkgreen :: Color +darkgreen = rgb 0 100 0 + +darkgrey :: Color +darkgrey = rgb 169 169 169 + +darkkhaki :: Color +darkkhaki = rgb 189 183 107 + +darkmagenta :: Color +darkmagenta = rgb 139 0 139 + +darkolivegreen :: Color +darkolivegreen = rgb 85 107 47 + +darkorange :: Color +darkorange = rgb 255 140 0 + +darkorchid :: Color +darkorchid = rgb 153 50 204 + +darkred :: Color +darkred = rgb 139 0 0 + +darksalmon :: Color +darksalmon = rgb 233 150 122 + +darkseagreen :: Color +darkseagreen = rgb 143 188 143 + +darkslateblue :: Color +darkslateblue = rgb 72 61 139 + +darkslategray :: Color +darkslategray = rgb 47 79 79 + +darkslategrey :: Color +darkslategrey = rgb 47 79 79 + +darkturquoise :: Color +darkturquoise = rgb 0 206 209 + +darkviolet :: Color +darkviolet = rgb 148 0 211 + +deeppink :: Color +deeppink = rgb 255 20 147 + +deepskyblue :: Color +deepskyblue = rgb 0 191 255 + +dimgray :: Color +dimgray = rgb 105 105 105 + +dimgrey :: Color +dimgrey = rgb 105 105 105 + +dodgerblue :: Color +dodgerblue = rgb 30 144 255 + +firebrick :: Color +firebrick = rgb 178 34 34 + +floralwhite :: Color +floralwhite = rgb 255 250 240 + +forestgreen :: Color +forestgreen = rgb 34 139 34 + +fuchsia :: Color +fuchsia = rgb 255 0 255 + +gainsboro :: Color +gainsboro = rgb 220 220 220 + +ghostwhite :: Color +ghostwhite = rgb 248 248 255 + +gold :: Color +gold = rgb 255 215 0 + +goldenrod :: Color +goldenrod = rgb 218 165 32 + +gray :: Color +gray = rgb 128 128 128 + +green :: Color +green = rgb 0 128 0 + +greenyellow :: Color +greenyellow = rgb 173 255 47 + +grey :: Color +grey = rgb 128 128 128 + +honeydew :: Color +honeydew = rgb 240 255 240 + +hotpink :: Color +hotpink = rgb 255 105 180 + +indianred :: Color +indianred = rgb 205 92 92 + +indigo :: Color +indigo = rgb 75 0 130 + +ivory :: Color +ivory = rgb 255 255 240 + +khaki :: Color +khaki = rgb 240 230 140 + +lavender :: Color +lavender = rgb 230 230 250 + +lavenderblush :: Color +lavenderblush = rgb 255 240 245 + +lawngreen :: Color +lawngreen = rgb 124 252 0 + +lemonchiffon :: Color +lemonchiffon = rgb 255 250 205 + +lightblue :: Color +lightblue = rgb 173 216 230 + +lightcoral :: Color +lightcoral = rgb 240 128 128 + +lightcyan :: Color +lightcyan = rgb 224 255 255 + +lightgoldenrodyellow :: Color +lightgoldenrodyellow = rgb 250 250 210 + +lightgray :: Color +lightgray = rgb 211 211 211 + +lightgreen :: Color +lightgreen = rgb 144 238 144 + +lightgrey :: Color +lightgrey = rgb 211 211 211 + +lightpink :: Color +lightpink = rgb 255 182 193 + +lightsalmon :: Color +lightsalmon = rgb 255 160 122 + +lightseagreen :: Color +lightseagreen = rgb 32 178 170 + +lightskyblue :: Color +lightskyblue = rgb 135 206 250 + +lightslategray :: Color +lightslategray = rgb 119 136 153 + +lightslategrey :: Color +lightslategrey = rgb 119 136 153 + +lightsteelblue :: Color +lightsteelblue = rgb 176 196 222 + +lightyellow :: Color +lightyellow = rgb 255 255 224 + +lime :: Color +lime = rgb 0 255 0 + +limegreen :: Color +limegreen = rgb 50 205 50 + +linen :: Color +linen = rgb 250 240 230 + +magenta :: Color +magenta = rgb 255 0 255 + +maroon :: Color +maroon = rgb 128 0 0 + +mediumaquamarine :: Color +mediumaquamarine = rgb 102 205 170 + +mediumblue :: Color +mediumblue = rgb 0 0 205 + +mediumorchid :: Color +mediumorchid = rgb 186 85 211 + +mediumpurple :: Color +mediumpurple = rgb 147 112 219 + +mediumseagreen :: Color +mediumseagreen = rgb 60 179 113 + +mediumslateblue :: Color +mediumslateblue = rgb 123 104 238 + +mediumspringgreen :: Color +mediumspringgreen = rgb 0 250 154 + +mediumturquoise :: Color +mediumturquoise = rgb 72 209 204 + +mediumvioletred :: Color +mediumvioletred = rgb 199 21 133 + +midnightblue :: Color +midnightblue = rgb 25 25 112 + +mintcream :: Color +mintcream = rgb 245 255 250 + +mistyrose :: Color +mistyrose = rgb 255 228 225 + +moccasin :: Color +moccasin = rgb 255 228 181 + +navajowhite :: Color +navajowhite = rgb 255 222 173 + +navy :: Color +navy = rgb 0 0 128 + +oldlace :: Color +oldlace = rgb 253 245 230 + +olive :: Color +olive = rgb 128 128 0 + +olivedrab :: Color +olivedrab = rgb 107 142 35 + +orange :: Color +orange = rgb 255 165 0 + +orangered :: Color +orangered = rgb 255 69 0 + +orchid :: Color +orchid = rgb 218 112 214 + +palegoldenrod :: Color +palegoldenrod = rgb 238 232 170 + +palegreen :: Color +palegreen = rgb 152 251 152 + +paleturquoise :: Color +paleturquoise = rgb 175 238 238 + +palevioletred :: Color +palevioletred = rgb 219 112 147 + +papayawhip :: Color +papayawhip = rgb 255 239 213 + +peachpuff :: Color +peachpuff = rgb 255 218 185 + +peru :: Color +peru = rgb 205 133 63 + +pink :: Color +pink = rgb 255 192 203 + +plum :: Color +plum = rgb 221 160 221 + +powderblue :: Color +powderblue = rgb 176 224 230 + +purple :: Color +purple = rgb 128 0 128 + +red :: Color +red = rgb 255 0 0 + +rosybrown :: Color +rosybrown = rgb 188 143 143 + +royalblue :: Color +royalblue = rgb 65 105 225 + +saddlebrown :: Color +saddlebrown = rgb 139 69 19 + +salmon :: Color +salmon = rgb 250 128 114 + +sandybrown :: Color +sandybrown = rgb 244 164 96 + +seagreen :: Color +seagreen = rgb 46 139 87 + +seashell :: Color +seashell = rgb 255 245 238 + +sienna :: Color +sienna = rgb 160 82 45 + +silver :: Color +silver = rgb 192 192 192 + +skyblue :: Color +skyblue = rgb 135 206 235 + +slateblue :: Color +slateblue = rgb 106 90 205 + +slategray :: Color +slategray = rgb 112 128 144 + +slategrey :: Color +slategrey = rgb 112 128 144 + +snow :: Color +snow = rgb 255 250 250 + +springgreen :: Color +springgreen = rgb 0 255 127 + +steelblue :: Color +steelblue = rgb 70 130 180 + +tan :: Color +tan = rgb 210 180 140 + +teal :: Color +teal = rgb 0 128 128 + +thistle :: Color +thistle = rgb 216 191 216 + +tomato :: Color +tomato = rgb 255 99 71 + +turquoise :: Color +turquoise = rgb 64 224 208 + +violet :: Color +violet = rgb 238 130 238 + +wheat :: Color +wheat = rgb 245 222 179 + +white :: Color +white = rgb 255 255 255 + +whitesmoke :: Color +whitesmoke = rgb 245 245 245 + +yellow :: Color +yellow = rgb 255 255 0 + +yellowgreen :: Color +yellowgreen = rgb 154 205 50 + diff --git a/src/Css/Display.purs b/src/CSS/Display.purs similarity index 93% rename from src/Css/Display.purs rename to src/CSS/Display.purs index a85b768..ca48312 100644 --- a/src/Css/Display.purs +++ b/src/CSS/Display.purs @@ -1,17 +1,17 @@ -module Css.Display where +module CSS.Display where import Prelude -import Css.Property -import Css.String -import Css.Stylesheet +import CSS.Property +import CSS.String +import CSS.Stylesheet newtype Position = Position Value instance valPosition :: Val Position where value (Position v) = v -position :: Position -> Css +position :: Position -> CSS position = key $ fromString "position" static :: Position @@ -94,5 +94,5 @@ grid = Display $ fromString "grid" inlineGrid :: Display inlineGrid = Display $ fromString "inline-grid" -display :: Display -> Css +display :: Display -> CSS display = key $ fromString "display" diff --git a/src/Css/Elements.purs b/src/CSS/Elements.purs similarity index 84% rename from src/Css/Elements.purs rename to src/CSS/Elements.purs index b8d5336..e934363 100644 --- a/src/Css/Elements.purs +++ b/src/CSS/Elements.purs @@ -1,9 +1,9 @@ -module Css.Elements where +module CSS.Elements where import Prelude -import Css.Selector -import Css.String +import CSS.Selector +import CSS.String body :: Selector body = fromString "body" diff --git a/src/Css/Font.purs b/src/CSS/Font.purs similarity index 81% rename from src/Css/Font.purs rename to src/CSS/Font.purs index 68d6dab..65c4486 100644 --- a/src/Css/Font.purs +++ b/src/CSS/Font.purs @@ -1,17 +1,17 @@ -module Css.Font where +module CSS.Font where import Prelude import Data.NonEmpty (NonEmpty(), oneOf) -import Css.Color -import Css.Property -import Css.Size -import Css.String -import Css.Stylesheet +import CSS.Color +import CSS.Property +import CSS.Size +import CSS.String +import CSS.Stylesheet -color :: Color -> Css +color :: Color -> CSS color = key $ fromString "color" newtype GenericFontFamily = GenericFontFamily Value @@ -22,10 +22,10 @@ instance valGenericFontFamily :: Val GenericFontFamily where sansSerif :: GenericFontFamily sansSerif = GenericFontFamily $ fromString "sans-serif" -fontFamily :: Array String -> NonEmpty Array GenericFontFamily -> Css +fontFamily :: Array String -> NonEmpty Array GenericFontFamily -> CSS fontFamily a b = key (fromString "font-family") <<< value $ (value <<< quote <$> a) <> oneOf (value <$> b) -fontSize :: forall a. Size a -> Css +fontSize :: forall a. Size a -> CSS fontSize = key $ fromString "font-size" newtype FontWeight = FontWeight Value @@ -45,5 +45,5 @@ lighter = FontWeight $ fromString "lighter" weight :: Number -> FontWeight weight i = FontWeight $ value i -fontWeight :: FontWeight -> Css +fontWeight :: FontWeight -> CSS fontWeight = key $ fromString "font-weight" diff --git a/src/Css/FontFace.purs b/src/CSS/FontFace.purs similarity index 85% rename from src/Css/FontFace.purs rename to src/CSS/FontFace.purs index 5c82b1c..bb14e4f 100644 --- a/src/Css/FontFace.purs +++ b/src/CSS/FontFace.purs @@ -1,15 +1,15 @@ -module Css.FontFace where +module CSS.FontFace where import Prelude import Data.Maybe (Maybe(), maybe) import Data.NonEmpty (NonEmpty()) -import Css.Property -import Css.String -import Css.Stylesheet +import CSS.Property +import CSS.String +import CSS.Stylesheet -fontFaceFamily :: String -> Css +fontFaceFamily :: String -> CSS fontFaceFamily = key (fromString "font-family") <<< Literal data FontFaceFormat = WOFF @@ -34,5 +34,5 @@ instance valFontFaceSrc :: Val FontFaceSrc where value (FontFaceSrcUrl u f) = fromString $ "url(" <> quote u <> ")" <> maybe "" (\f' -> " format(" <> formatName f' <> ")") f value (FontFaceSrcLocal l) = fromString $ "local(" <> quote l <> ")" -fontFaceSrc :: NonEmpty Array FontFaceSrc -> Css +fontFaceSrc :: NonEmpty Array FontFaceSrc -> CSS fontFaceSrc = key $ fromString "src" diff --git a/src/Css/Geometry.purs b/src/CSS/Geometry.purs similarity index 52% rename from src/Css/Geometry.purs rename to src/CSS/Geometry.purs index 8b23d53..613f43e 100644 --- a/src/Css/Geometry.purs +++ b/src/CSS/Geometry.purs @@ -1,69 +1,69 @@ -module Css.Geometry where +module CSS.Geometry where import Prelude hiding (top, bottom) import Data.Tuple.Nested (tuple4) -import Css.Size -import Css.String -import Css.Stylesheet +import CSS.Size +import CSS.String +import CSS.Stylesheet -width :: forall a. Size a -> Css +width :: forall a. Size a -> CSS width = key $ fromString "width" -height :: forall a. Size a -> Css +height :: forall a. Size a -> CSS height = key $ fromString "height" -minWidth :: forall a. Size a -> Css +minWidth :: forall a. Size a -> CSS minWidth = key $ fromString "min-width" -minHeight :: forall a. Size a -> Css +minHeight :: forall a. Size a -> CSS minHeight = key $ fromString "min-height" -maxWidth :: forall a. Size a -> Css +maxWidth :: forall a. Size a -> CSS maxWidth = key $ fromString "max-width" -maxHeight :: forall a. Size a -> Css +maxHeight :: forall a. Size a -> CSS maxHeight = key $ fromString "max-height" -top :: forall a. Size a -> Css +top :: forall a. Size a -> CSS top = key $ fromString "top" -bottom :: forall a. Size a -> Css +bottom :: forall a. Size a -> CSS bottom = key $ fromString "bottom" -left :: forall a. Size a -> Css +left :: forall a. Size a -> CSS left = key $ fromString "left" -right :: forall a. Size a -> Css +right :: forall a. Size a -> CSS right = key $ fromString "right" -padding :: forall a. Size a -> Size a -> Size a -> Size a -> Css +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 -paddingTop :: forall a. Size a -> Css +paddingTop :: forall a. Size a -> CSS paddingTop = key $ fromString "padding-top" -paddingBottom :: forall a. Size a -> Css +paddingBottom :: forall a. Size a -> CSS paddingBottom = key $ fromString "padding-bottom" -paddingLeft :: forall a. Size a -> Css +paddingLeft :: forall a. Size a -> CSS paddingLeft = key $ fromString "padding-left" -paddingRight :: forall a. Size a -> Css +paddingRight :: forall a. Size a -> CSS paddingRight = key $ fromString "padding-right" -margin :: forall a. Size a -> Size a -> Size a -> Size a -> Css +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 -marginTop :: forall a. Size a -> Css +marginTop :: forall a. Size a -> CSS marginTop = key $ fromString "margin-top" -marginBottom :: forall a. Size a -> Css +marginBottom :: forall a. Size a -> CSS marginBottom = key $ fromString "margin-bottom" -marginLeft :: forall a. Size a -> Css +marginLeft :: forall a. Size a -> CSS marginLeft = key $ fromString "margin-left" -marginRight :: forall a. Size a -> Css +marginRight :: forall a. Size a -> CSS marginRight = key $ fromString "margin-right" diff --git a/src/Css/Gradient.purs b/src/CSS/Gradient.purs similarity index 81% rename from src/Css/Gradient.purs rename to src/CSS/Gradient.purs index 651afe2..81ab074 100644 --- a/src/Css/Gradient.purs +++ b/src/CSS/Gradient.purs @@ -1,14 +1,14 @@ -module Css.Gradient where +module CSS.Gradient where import Prelude import Data.Foldable (intercalate) -import Css.Background -import Css.Color -import Css.Property -import Css.Size -import Css.String +import CSS.Background +import CSS.Color +import CSS.Property +import CSS.Size +import CSS.String data ColorPoint = ColorPoint Color (Size Rel) diff --git a/src/Css/Media.purs b/src/CSS/Media.purs similarity index 66% rename from src/Css/Media.purs rename to src/CSS/Media.purs index 45e81a1..f4f0bc1 100644 --- a/src/Css/Media.purs +++ b/src/CSS/Media.purs @@ -1,13 +1,13 @@ -module Css.Media where +module CSS.Media where import Prelude import Data.Maybe (Maybe(..)) -import Css.Property -import Css.Size -import Css.String -import Css.Stylesheet +import CSS.Property +import CSS.Size +import CSS.String +import CSS.Stylesheet screen :: MediaType screen = MediaType $ fromString "screen" diff --git a/src/Css/Property.purs b/src/CSS/Property.purs similarity index 93% rename from src/Css/Property.purs rename to src/CSS/Property.purs index fb4ae67..28fd351 100644 --- a/src/Css/Property.purs +++ b/src/CSS/Property.purs @@ -1,15 +1,15 @@ -module Css.Property where +module CSS.Property where import Prelude import Data.Foldable (intercalate) -import Data.Maybe (Maybe(), fromMaybe) +import Data.Maybe (fromMaybe) import Data.Monoid (Monoid, mempty) import Data.NonEmpty (NonEmpty(), oneOf) import Data.Profunctor.Strong (second) import Data.Tuple (Tuple(..), lookup) -import Css.String +import CSS.String data Prefixed = Prefixed (Array (Tuple String String)) | Plain String @@ -21,7 +21,7 @@ instance semigroupPrefixed :: Semigroup Prefixed where append (Plain x) (Plain y) = Plain $ x <> y append (Plain x) (Prefixed ys) = Prefixed $ second (x <>) <$> ys append (Prefixed xs) (Plain y) = Prefixed $ second (y <>) <$> xs - -- (<>) (Prefixed xs) (Prefixed ys) + append (Prefixed xs) (Prefixed ys) = Prefixed $ xs <> ys instance monoidPrefixed :: Monoid Prefixed where mempty = Plain mempty diff --git a/src/Css/Pseudo.purs b/src/CSS/Pseudo.purs similarity index 51% rename from src/Css/Pseudo.purs rename to src/CSS/Pseudo.purs index b30c23b..9d00f0f 100644 --- a/src/Css/Pseudo.purs +++ b/src/CSS/Pseudo.purs @@ -1,9 +1,9 @@ -module Css.Pseudo where +module CSS.Pseudo where import Prelude -import Css.Selector -import Css.String +import CSS.Selector +import CSS.String hover :: Refinement hover = fromString ":hover" diff --git a/src/Css/Render.purs b/src/CSS/Render.purs similarity index 98% rename from src/Css/Render.purs rename to src/CSS/Render.purs index 3c716aa..83ea2cc 100644 --- a/src/Css/Render.purs +++ b/src/CSS/Render.purs @@ -1,4 +1,4 @@ -module Css.Render where +module CSS.Render where import Prelude @@ -11,10 +11,10 @@ import Data.NonEmpty (NonEmpty(..), (:|), foldl1, oneOf) import Data.These (These(..), theseLeft, theseRight) import Data.Tuple (Tuple(..), lookup, uncurry) -import Css.Property -import Css.Selector -import Css.String -import Css.Stylesheet +import CSS.Property +import CSS.Selector +import CSS.String +import CSS.Stylesheet newtype Inline = Inline String diff --git a/src/Css/Selector.purs b/src/CSS/Selector.purs similarity index 92% rename from src/Css/Selector.purs rename to src/CSS/Selector.purs index bff292c..97ed80f 100644 --- a/src/Css/Selector.purs +++ b/src/CSS/Selector.purs @@ -1,10 +1,11 @@ -module Css.Selector where +module CSS.Selector where import Prelude +import Data.Generic (Generic, gEq, gCompare) import Data.String (take, drop) -import Css.String +import CSS.String data Predicate = Id String | Class String @@ -18,11 +19,13 @@ data Predicate = Id String | Pseudo String | PseudoFunc String (Array String) +derive instance genericPredicate :: Generic Predicate + instance eqPredicate :: Eq Predicate where - eq (Id a) (Id b) = a == b + eq = gEq instance ordPredicate :: Ord Predicate where - compare (Id a) (Id b) = compare a b + compare = gCompare newtype Refinement = Refinement (Array Predicate) diff --git a/src/Css/Size.purs b/src/CSS/Size.purs similarity index 93% rename from src/Css/Size.purs rename to src/CSS/Size.purs index dcc86fb..a1816f9 100644 --- a/src/Css/Size.purs +++ b/src/CSS/Size.purs @@ -1,9 +1,9 @@ -module Css.Size where +module CSS.Size where import Prelude -import Css.Property -import Css.String +import CSS.Property +import CSS.String newtype Size a = Size Value diff --git a/src/Css/String.purs b/src/CSS/String.purs similarity index 85% rename from src/Css/String.purs rename to src/CSS/String.purs index 20780a3..308de75 100644 --- a/src/Css/String.purs +++ b/src/CSS/String.purs @@ -1,4 +1,4 @@ -module Css.String where +module CSS.String where import Prelude diff --git a/src/Css/Stylesheet.purs b/src/CSS/Stylesheet.purs similarity index 79% rename from src/Css/Stylesheet.purs rename to src/CSS/Stylesheet.purs index 5111f4c..17313dc 100644 --- a/src/Css/Stylesheet.purs +++ b/src/CSS/Stylesheet.purs @@ -1,4 +1,4 @@ -module Css.Stylesheet where +module CSS.Stylesheet where import Prelude @@ -11,8 +11,8 @@ import Data.NonEmpty (NonEmpty(), (:|)) import Data.Profunctor.Strong (second) import Data.Tuple (Tuple(..)) -import Css.Property (Val, Key(), Value(), cast, value) -import Css.Selector (Selector(), Refinement()) +import CSS.Property (Val, Key(), Value(), cast, value) +import CSS.Selector (Selector(), Refinement()) newtype MediaType = MediaType Value @@ -56,29 +56,29 @@ instance monadStyleM :: Monad StyleM runS :: forall a. StyleM a -> Array Rule runS (S s) = execWriter s -rule :: Rule -> Css +rule :: Rule -> CSS rule = S <<< tell <<< singleton -type Css = StyleM Unit +type CSS = StyleM Unit -key :: forall a. (Val a) => Key a -> a -> Css +key :: forall a. (Val a) => Key a -> a -> CSS key k v = rule $ Property (cast k) (value v) infixr 5 ? -(?) :: Selector -> Css -> Css +(?) :: Selector -> CSS -> CSS (?) sel rs = rule $ Nested (Sub sel) (runS rs) -query :: MediaType -> NonEmpty Array Feature -> Css -> Css +query :: MediaType -> NonEmpty Array Feature -> CSS -> CSS query ty fs = rule <<< Query (MediaQuery Nothing ty fs) <<< runS -keyframes :: String -> NonEmpty Array (Tuple Number Css) -> Css +keyframes :: String -> NonEmpty Array (Tuple Number CSS) -> CSS keyframes n xs = rule $ Keyframe (Keyframes n (second runS <$> xs)) -keyframesFromTo :: String -> Css -> Css -> Css +keyframesFromTo :: String -> CSS -> CSS -> CSS keyframesFromTo n a b = keyframes n $ Tuple 0.0 a :| [Tuple 100.0 b] -fontFace :: Css -> Css +fontFace :: CSS -> CSS fontFace = rule <<< Face <<< runS -importUrl :: String -> Css +importUrl :: String -> CSS importUrl = rule <<< Import diff --git a/src/Css/Text.purs b/src/CSS/Text.purs similarity index 83% rename from src/Css/Text.purs rename to src/CSS/Text.purs index 30df6bf..e595516 100644 --- a/src/Css/Text.purs +++ b/src/CSS/Text.purs @@ -1,10 +1,10 @@ -module Css.Text where +module CSS.Text where import Prelude -import Css.Property -import Css.String -import Css.Stylesheet +import CSS.Property +import CSS.String +import CSS.Stylesheet newtype TextDecoration = TextDecoration Value @@ -26,5 +26,5 @@ lineThrough = TextDecoration $ fromString "line-through" blink :: TextDecoration blink = TextDecoration $ fromString "blink" -textDecoration :: TextDecoration -> Css +textDecoration :: TextDecoration -> CSS textDecoration = key $ fromString "text-decoration" diff --git a/src/Css/Time.purs b/src/CSS/Time.purs similarity index 79% rename from src/Css/Time.purs rename to src/CSS/Time.purs index 179991e..7621e5c 100644 --- a/src/Css/Time.purs +++ b/src/CSS/Time.purs @@ -1,9 +1,9 @@ -module Css.Time where +module CSS.Time where import Prelude -import Css.Property -import Css.String +import CSS.Property +import CSS.String newtype Time = Time Value diff --git a/src/Css/Transform.purs b/src/CSS/Transform.purs similarity index 74% rename from src/Css/Transform.purs rename to src/CSS/Transform.purs index 1174454..ad8e80f 100644 --- a/src/Css/Transform.purs +++ b/src/CSS/Transform.purs @@ -1,21 +1,21 @@ -module Css.Transform where +module CSS.Transform where import Prelude -import Css.Property -import Css.Size -import Css.String -import Css.Stylesheet +import CSS.Property +import CSS.Size +import CSS.String +import CSS.Stylesheet newtype Transformation = Transformation Value instance valTransformation :: Val Transformation where value (Transformation v) = v -transform :: Transformation -> Css +transform :: Transformation -> CSS transform = key $ fromString "transform" -transforms :: Array Transformation -> Css +transforms :: Array Transformation -> CSS transforms = key (fromString "transform") <<< noCommas translate :: Size Abs -> Size Abs -> Transformation diff --git a/src/Css/Transition.purs b/src/CSS/Transition.purs similarity index 81% rename from src/Css/Transition.purs rename to src/CSS/Transition.purs index 3025a4e..6ed4cd1 100644 --- a/src/Css/Transition.purs +++ b/src/CSS/Transition.purs @@ -1,9 +1,9 @@ -module Css.Transition where +module CSS.Transition where import Prelude -import Css.String -import Css.Property +import CSS.String +import CSS.Property newtype TimingFunction = TimingFunction Value diff --git a/src/Css/Color.purs b/src/Css/Color.purs deleted file mode 100644 index 0bcff9c..0000000 --- a/src/Css/Color.purs +++ /dev/null @@ -1,177 +0,0 @@ -module Css.Color where - -import Prelude - -import Data.Foldable (intercalate) - -import Css.Property -import Css.String - -data Color = Rgba Int Int Int Int - | Hsla Number Number Number Number - | Other Value - -instance isStringColor :: IsString Color where - fromString = Other <<< fromString - -instance valColor :: Val Color where - value (Rgba r g b 255) = Value <<< fromString $ "rgb(" <> intercalate ", " [show r, show g, show b] <> ")" - value (Rgba r g b a) = Value <<< fromString $ "rgba(" <> intercalate ", " [show r, show g, show b, show a] <> ")" - value (Other v) = v - -rgba :: Int -> Int -> Int -> Int -> Color -rgba = Rgba - -rgb :: Int -> Int -> Int -> Color -rgb r g b = Rgba r g b 255 - -clamp :: Int -> Int -clamp n = if n < 0 then 0 else if n > 255 then 255 else n - -aliceblue = rgb 240 248 255 -antiquewhite = rgb 250 235 215 -aqua = rgb 0 255 255 -aquamarine = rgb 127 255 212 -azure = rgb 240 255 255 -beige = rgb 245 245 220 -bisque = rgb 255 228 196 -black = rgb 0 0 0 -blanchedalmond = rgb 255 235 205 -blue = rgb 0 0 255 -blueviolet = rgb 138 43 226 -brown = rgb 165 42 42 -burlywood = rgb 222 184 135 -cadetblue = rgb 95 158 160 -chartreuse = rgb 127 255 0 -chocolate = rgb 210 105 30 -coral = rgb 255 127 80 -cornflowerblue = rgb 100 149 237 -cornsilk = rgb 255 248 220 -crimson = rgb 220 20 60 -cyan = rgb 0 255 255 -darkblue = rgb 0 0 139 -darkcyan = rgb 0 139 139 -darkgoldenrod = rgb 184 134 11 -darkgray = rgb 169 169 169 -darkgreen = rgb 0 100 0 -darkgrey = rgb 169 169 169 -darkkhaki = rgb 189 183 107 -darkmagenta = rgb 139 0 139 -darkolivegreen = rgb 85 107 47 -darkorange = rgb 255 140 0 -darkorchid = rgb 153 50 204 -darkred = rgb 139 0 0 -darksalmon = rgb 233 150 122 -darkseagreen = rgb 143 188 143 -darkslateblue = rgb 72 61 139 -darkslategray = rgb 47 79 79 -darkslategrey = rgb 47 79 79 -darkturquoise = rgb 0 206 209 -darkviolet = rgb 148 0 211 -deeppink = rgb 255 20 147 -deepskyblue = rgb 0 191 255 -dimgray = rgb 105 105 105 -dimgrey = rgb 105 105 105 -dodgerblue = rgb 30 144 255 -firebrick = rgb 178 34 34 -floralwhite = rgb 255 250 240 -forestgreen = rgb 34 139 34 -fuchsia = rgb 255 0 255 -gainsboro = rgb 220 220 220 -ghostwhite = rgb 248 248 255 -gold = rgb 255 215 0 -goldenrod = rgb 218 165 32 -gray = rgb 128 128 128 -green = rgb 0 128 0 -greenyellow = rgb 173 255 47 -grey = rgb 128 128 128 -honeydew = rgb 240 255 240 -hotpink = rgb 255 105 180 -indianred = rgb 205 92 92 -indigo = rgb 75 0 130 -ivory = rgb 255 255 240 -khaki = rgb 240 230 140 -lavender = rgb 230 230 250 -lavenderblush = rgb 255 240 245 -lawngreen = rgb 124 252 0 -lemonchiffon = rgb 255 250 205 -lightblue = rgb 173 216 230 -lightcoral = rgb 240 128 128 -lightcyan = rgb 224 255 255 -lightgoldenrodyellow = rgb 250 250 210 -lightgray = rgb 211 211 211 -lightgreen = rgb 144 238 144 -lightgrey = rgb 211 211 211 -lightpink = rgb 255 182 193 -lightsalmon = rgb 255 160 122 -lightseagreen = rgb 32 178 170 -lightskyblue = rgb 135 206 250 -lightslategray = rgb 119 136 153 -lightslategrey = rgb 119 136 153 -lightsteelblue = rgb 176 196 222 -lightyellow = rgb 255 255 224 -lime = rgb 0 255 0 -limegreen = rgb 50 205 50 -linen = rgb 250 240 230 -magenta = rgb 255 0 255 -maroon = rgb 128 0 0 -mediumaquamarine = rgb 102 205 170 -mediumblue = rgb 0 0 205 -mediumorchid = rgb 186 85 211 -mediumpurple = rgb 147 112 219 -mediumseagreen = rgb 60 179 113 -mediumslateblue = rgb 123 104 238 -mediumspringgreen = rgb 0 250 154 -mediumturquoise = rgb 72 209 204 -mediumvioletred = rgb 199 21 133 -midnightblue = rgb 25 25 112 -mintcream = rgb 245 255 250 -mistyrose = rgb 255 228 225 -moccasin = rgb 255 228 181 -navajowhite = rgb 255 222 173 -navy = rgb 0 0 128 -oldlace = rgb 253 245 230 -olive = rgb 128 128 0 -olivedrab = rgb 107 142 35 -orange = rgb 255 165 0 -orangered = rgb 255 69 0 -orchid = rgb 218 112 214 -palegoldenrod = rgb 238 232 170 -palegreen = rgb 152 251 152 -paleturquoise = rgb 175 238 238 -palevioletred = rgb 219 112 147 -papayawhip = rgb 255 239 213 -peachpuff = rgb 255 218 185 -peru = rgb 205 133 63 -pink = rgb 255 192 203 -plum = rgb 221 160 221 -powderblue = rgb 176 224 230 -purple = rgb 128 0 128 -red = rgb 255 0 0 -rosybrown = rgb 188 143 143 -royalblue = rgb 65 105 225 -saddlebrown = rgb 139 69 19 -salmon = rgb 250 128 114 -sandybrown = rgb 244 164 96 -seagreen = rgb 46 139 87 -seashell = rgb 255 245 238 -sienna = rgb 160 82 45 -silver = rgb 192 192 192 -skyblue = rgb 135 206 235 -slateblue = rgb 106 90 205 -slategray = rgb 112 128 144 -slategrey = rgb 112 128 144 -snow = rgb 255 250 250 -springgreen = rgb 0 255 127 -steelblue = rgb 70 130 180 -tan = rgb 210 180 140 -teal = rgb 0 128 128 -thistle = rgb 216 191 216 -tomato = rgb 255 99 71 -turquoise = rgb 64 224 208 -violet = rgb 238 130 238 -wheat = rgb 245 222 179 -white = rgb 255 255 255 -whitesmoke = rgb 245 245 245 -yellow = rgb 255 255 0 -yellowgreen = rgb 154 205 50 diff --git a/test/Main.purs b/test/Main.purs index 682dce8..c447f52 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -4,16 +4,16 @@ import Prelude import Control.Monad import Control.Monad.Eff import Control.Monad.Eff.Exception -import Css.Border -import Css.Color -import Css.Display -import Css.Elements -import Css.Font -import Css.Render -import Css.Selector -import Css.Size -import Css.String -import Css.Stylesheet +import CSS.Border +import CSS.Color +import CSS.Display +import CSS.Elements +import CSS.Font +import CSS.Render +import CSS.Selector +import CSS.Size +import CSS.String +import CSS.Stylesheet import Data.Maybe import Data.These