module Data.CSS.Properties.Layout
(
border,
borderColor,
borderStyle,
borderWidth,
lineHeight,
verticalAlign,
margin,
padding,
pageMargins,
pageBreakBefore,
pageBreakAfter,
pageBreakInside,
edgePos,
position,
zIndex,
clear,
float,
height,
minHeight,
maxHeight,
width,
minWidth,
maxWidth,
borderCollapse,
borderSpacing,
captionSide,
emptyCells,
tableLayout,
clip,
display,
overflow,
visibility
)
where
import qualified Data.ByteString as B
import Control.Monad.Reader
import Control.Monad.Writer.Class
import Data.Colour
import Data.CSS.Build
import Data.CSS.Properties.Types
import Data.CSS.Properties.Utils
import Data.CSS.Types
import Data.List
import Data.Set (Set)
border ::
(ColourOps f, Real a, ToPropValue (f b))
=> BorderWidth a
-> BorderStyle
-> f b
-> SetProp
border w s c = "border" $= (w, s, c)
borderCollapse :: Bool -> SetProp
borderCollapse c =
"border-collapse" $= PropValue (if c then "collapse" else "separate")
borderColor :: (ColourOps f, ToPropValue (f a)) => Edge (f a) -> SetProp
borderColor = byEdge "border" "-color"
borderSpacing :: (Real a) => [Length a] -> SetProp
borderSpacing = setProp "border-spacing"
borderStyle :: Edge BorderStyle -> SetProp
borderStyle = byEdge "border" "-style"
borderWidth :: (Real a) => Edge (BorderWidth a) -> SetProp
borderWidth = byEdge "border" "-width"
byEdge ::
(ToPropValue a)
=> PropName
-> PropName
-> Edge a
-> SetProp
byEdge (PropName pfx) (PropName sfx) edge =
case edge of
BottomEdge p -> PropName (B.append (B.append pfx "-bottom") sfx) $= p
Edges ps -> PropName (B.append pfx sfx) $= ps
LeftEdge p -> PropName (B.append (B.append pfx "-left") sfx) $= p
RightEdge p -> PropName (B.append (B.append pfx "-right") sfx) $= p
TopEdge p -> PropName (B.append (B.append pfx "-top") sfx) $= p
captionSide :: CaptionSide -> SetProp
captionSide = setProp "caption-side"
clear :: [FloatEdge] -> SetProp
clear es
| l && r = "clear" $= PropValue "both"
| l = "clear" $= PropValue "left"
| r = "clear" $= PropValue "right"
| otherwise = "clear" $= PropValue "none"
where
(l, r) = foldl' f (False, False) es
f (_, r') LeftFloat = (True, r')
f (l', _) RightFloat = (l', True)
clip :: (Real a) => Maybe (ClipMode a) -> SetProp
clip = setProp "clip" . maybeProp "auto"
display :: DisplayMode -> SetProp
display = setProp "display"
edgePos :: (Real a) => Edge (AutoLen (FactorLen Length) a) -> SetProp
edgePos (Edges ls) =
let edges l1 l2 l3 l4 = "top" $= l1 >> "right" $= l2 >> "bottom" $= l3 >> "left" $= l4 in
case ls of
l1:l2:l3:l4:_ -> edges l1 l2 l3 l4
l1:l2:l3:_ -> edges l1 l2 l3 l2
l1:l2:_ -> edges l1 l2 l1 l2
l1:_ -> edges l1 l1 l1 l1
[] -> return ()
edgePos (BottomEdge l) = "bottom" $= l
edgePos (LeftEdge l) = "left" $= l
edgePos (RightEdge l) = "right" $= l
edgePos (TopEdge l) = "top" $= l
emptyCells :: Bool -> SetProp
emptyCells s =
"empty-cells" $= PropValue (if s then "show" else "hide")
float :: Maybe FloatEdge -> SetProp
float = setProp "float" . maybeProp "none"
height :: (Real a) => AutoLen (FactorLen Length) a -> SetProp
height = setProp "height"
lineHeight :: (Real a) => Maybe (FactorLen Length a) -> SetProp
lineHeight = setProp "line-height" . maybeProp "normal"
margin :: (Real a) => Edge (AutoLen (FactorLen Length) a) -> SetProp
margin = byEdge "margin" ""
maxHeight :: (Real a) => Maybe (FactorLen Length a) -> SetProp
maxHeight = setProp "max-height" . maybeProp "none"
maxWidth :: (Real a) => Maybe (FactorLen Length a) -> SetProp
maxWidth = setProp "max-width" . maybeProp "none"
minHeight :: (Real a) => FactorLen Length a -> SetProp
minHeight = setProp "min-height"
minWidth :: (Real a) => FactorLen Length a -> SetProp
minWidth = setProp "min-width"
overflow :: OverflowMode -> SetProp
overflow = setProp "overflow"
padding :: (Real a) => Edge (FactorLen Length a) -> SetProp
padding = byEdge "padding" ""
pageMargins ::
(MonadWriter CSS m, Real a)
=> PageSelector
-> Edge (AutoLen (FactorLen Length) a)
-> ReaderT (Set MediaType) m ()
pageMargins pageSel = select (sel pageSel) . margin
where
sel AllPages = [Selector "@page"]
sel FirstPage = [Selector "@page :first"]
sel LeftPages = [Selector "@page :left"]
sel RightPages = [Selector "@page :right"]
pageBreakAfter :: Maybe (PageBreak a) -> SetProp
pageBreakAfter = setProp "page-break-after" . maybeProp "auto"
pageBreakBefore :: Maybe (PageBreak a) -> SetProp
pageBreakBefore = setProp "page-break-before" . maybeProp "auto"
pageBreakInside :: Maybe (PageBreak InsideBreak) -> SetProp
pageBreakInside = setProp "page-break-inside" . maybeProp "auto"
position :: PositionMode -> SetProp
position = setProp "position"
tableLayout :: TableLayout -> SetProp
tableLayout = setProp "table-layout"
verticalAlign :: (Real a) => VerticalAlign a -> SetProp
verticalAlign = setProp "vertical-align"
visibility :: VisibilityMode -> SetProp
visibility = setProp "visibility"
width :: (Real a) => AutoLen (FactorLen Length) a -> SetProp
width = setProp "width"
zIndex :: (Integral a) => Maybe a -> SetProp
zIndex = setProp "z-index" . maybeProp "auto" . fmap toInteger