0 | module Text.CSS.Declaration
  1 |
  2 | import Data.List
  3 | import Text.CSS.Color
  4 | import Text.CSS.Dir
  5 | import Text.CSS.Flexbox
  6 | import Text.CSS.Gradient
  7 | import Text.CSS.Grid
  8 | import Text.CSS.Length
  9 | import Text.CSS.ListStyleType
 10 | import Text.CSS.Percentage
 11 | import Text.CSS.Property
 12 |
 13 | %default total
 14 |
 15 | public export
 16 | data Declaration : Type where
 17 |   Decl : (property, value : String) -> Declaration
 18 |   Display : Display -> Declaration
 19 |
 20 | export
 21 | Interpolation Declaration where
 22 |   interpolate (Decl p v) = "\{p}: \{v};"
 23 |   interpolate (Display Flex) = "display: flex;"
 24 |   interpolate (Display Grid) = "display: grid;"
 25 |   interpolate (Display $ Area rs cs a) = "\{renderArea rs cs a};"
 26 |
 27 | export %inline
 28 | decl : Interpolation a => String -> a -> Declaration
 29 | decl s = Decl s . interpolate
 30 |
 31 | -- prefix
 32 | prfx : Dir a -> String
 33 | prfx (Left _)   = "-left"
 34 | prfx (Right _)  = "-right"
 35 | prfx (Top _)    = "-top"
 36 | prfx (Bottom _) = "-bottom"
 37 | prfx _          = ""
 38 |
 39 | export
 40 | dirDecl : (prop : String) -> (a -> String) -> Dir a -> Declaration
 41 | dirDecl prop f d =
 42 |   let vs := concat . intersperse " " . map f $ vals d
 43 |    in Decl "\{prop}\{prfx d}" vs
 44 |
 45 | export
 46 | dirDecl2 : (prop,suffix : String) -> (a -> String) -> Dir a -> Declaration
 47 | dirDecl2 prop suffix f d =
 48 |   let vs := concat . intersperse " " . map f $ vals d
 49 |    in Decl "\{prop}\{prfx d}-\{suffix}" vs
 50 |
 51 | --------------------------------------------------------------------------------
 52 | --          Predefined Properties
 53 | --------------------------------------------------------------------------------
 54 |
 55 | export %inline
 56 | alignItems : FlexAlign -> Declaration
 57 | alignItems = decl "align-items"
 58 |
 59 | export %inline
 60 | alignSelf : FlexAlign -> Declaration
 61 | alignSelf = decl "align-self"
 62 |
 63 | export %inline
 64 | backgroundColor : Color -> Declaration
 65 | backgroundColor = decl "background-color"
 66 |
 67 | export %inline
 68 | backgroundImage : (url : String) -> Declaration
 69 | backgroundImage = Decl "background-image"
 70 |
 71 | export %inline
 72 | backgroundImageGradient : Gradient -> Declaration
 73 | backgroundImageGradient = decl "background-image"
 74 |
 75 | export %inline
 76 | backgroundSize : Width -> Declaration
 77 | backgroundSize = decl "background-size"
 78 |
 79 | export %inline
 80 | border : String -> Declaration
 81 | border = Decl "border"
 82 |
 83 | export %inline
 84 | borderColor : Dir Color -> Declaration
 85 | borderColor = dirDecl2 "border" "color" interpolate
 86 |
 87 | export %inline
 88 | borderRadius : BorderRadius -> Declaration
 89 | borderRadius = decl "border-radius"
 90 |
 91 | export %inline
 92 | borderStyle : Dir BorderStyle -> Declaration
 93 | borderStyle = dirDecl2 "border" "style" interpolate
 94 |
 95 | export %inline
 96 | borderWidth : Dir BorderWidth -> Declaration
 97 | borderWidth = dirDecl2 "border" "width" interpolate
 98 |
 99 | export %inline
100 | boxSizing : BoxSizing -> Declaration
101 | boxSizing = decl "box-sizing"
102 |
103 | export %inline
104 | color : Color -> Declaration
105 | color = decl "color"
106 |
107 | export %inline
108 | columnGap : Length -> Declaration
109 | columnGap = decl "column-gap"
110 |
111 | export %inline
112 | direction : Direction -> Declaration
113 | direction = decl "direction"
114 |
115 | export %inline
116 | display : Display -> Declaration
117 | display = Display
118 |
119 | export %inline
120 | flex : String -> Declaration
121 | flex = Decl "flex"
122 |
123 | export %inline
124 | flexBasis : FlexBasis -> Declaration
125 | flexBasis = decl "flex-basis"
126 |
127 | export %inline
128 | flexDirection : FlexDirection -> Declaration
129 | flexDirection = decl "flex-direction"
130 |
131 | export %inline
132 | flexWrap : String -> Declaration
133 | flexWrap = Decl "flex-wrap"
134 |
135 | export %inline
136 | flexGrow : Nat -> Declaration
137 | flexGrow = Decl "flex-grow" . show
138 |
139 | export %inline
140 | flexFlow : List FlexFlow -> Declaration
141 | flexFlow = decl "flex-flow"
142 |
143 | export %inline
144 | fontFamily : String -> Declaration
145 | fontFamily = Decl "font-family"
146 |
147 | export %inline
148 | fontSize : FontSize -> Declaration
149 | fontSize = decl "font-size"
150 |
151 | export %inline
152 | fontWeight : FontWeight -> Declaration
153 | fontWeight = decl "font-weight"
154 |
155 | export %inline
156 | gridArea : AreaTag a => a -> Declaration
157 | gridArea = Decl "grid-area" . showTag
158 |
159 | export %inline
160 | gridColumn : GridPosition -> Declaration
161 | gridColumn = decl "grid-column"
162 |
163 | export %inline
164 | gridRow : GridPosition -> Declaration
165 | gridRow = decl "grid-row"
166 |
167 | export %inline
168 | gridTemplateColumns : List GridValue -> Declaration
169 | gridTemplateColumns = decl "grid-template-columns"
170 |
171 | export %inline
172 | gridTemplateRows : List GridValue -> Declaration
173 | gridTemplateRows = decl "grid-template-rows"
174 |
175 | export %inline
176 | height : Width -> Declaration
177 | height = decl "height"
178 |
179 | export %inline
180 | justifyContent : FlexJustify -> Declaration
181 | justifyContent = decl "justify-content"
182 |
183 | export %inline
184 | justifySelf : FlexJustify -> Declaration
185 | justifySelf = decl "justify-self"
186 |
187 | export %inline
188 | listStyleType : ListStyleType -> Declaration
189 | listStyleType = decl "list-style-type"
190 |
191 | export %inline
192 | margin : Dir Length -> Declaration
193 | margin = dirDecl "margin" interpolate
194 |
195 | export %inline
196 | maxHeight : Width -> Declaration
197 | maxHeight = decl "max-height"
198 |
199 | export %inline
200 | maxWidth : Width -> Declaration
201 | maxWidth = decl "max-width"
202 |
203 | export %inline
204 | minHeight : Width -> Declaration
205 | minHeight = decl "min-height"
206 |
207 | export %inline
208 | minWidth : Width -> Declaration
209 | minWidth = decl "min-width"
210 |
211 | export %inline
212 | overflowX : Overflow -> Declaration
213 | overflowX = decl "overflow-x"
214 |
215 | export %inline
216 | overflowY : Overflow -> Declaration
217 | overflowY = decl "overflow-y"
218 |
219 | export %inline
220 | padding : Dir Length -> Declaration
221 | padding = dirDecl "padding" interpolate
222 |
223 | export %inline
224 | rowGap : Length -> Declaration
225 | rowGap = decl "row-gap"
226 |
227 | export %inline
228 | textAlign : TextAlign -> Declaration
229 | textAlign = decl "text-align"
230 |
231 | export %inline
232 | textDecoration : String -> Declaration
233 | textDecoration = Decl "text-decoration"
234 |
235 | export %inline
236 | textDecorationColor : Color -> Declaration
237 | textDecorationColor = decl "text-decoration-color"
238 |
239 | export %inline
240 | textDecorationLine : TextDecorationLine -> Declaration
241 | textDecorationLine = decl "text-decoration-line"
242 |
243 | export %inline
244 | textDecorationStyle : TextDecorationStyle -> Declaration
245 | textDecorationStyle = decl "text-decoration-style"
246 |
247 | export %inline
248 | textOverflow : TextOverflow -> Declaration
249 | textOverflow = decl "text-overflow"
250 |
251 | export %inline
252 | textOverflow2 : TextOverflow -> TextOverflow -> Declaration
253 | textOverflow2 x y = Decl "text-overflow" "\{x} \{y}"
254 |
255 | export %inline
256 | width : Width -> Declaration
257 | width = decl "width"
258 |
259 | export %inline
260 | whitespace : WhiteSpace -> Declaration
261 | whitespace = decl "white-space"
262 |