0 | module Text.CSS.Declaration
  1 |
  2 | import Data.List
  3 | import Data.Vect
  4 | import Text.CSS.Color
  5 | import Text.CSS.Cursor
  6 | import Text.CSS.Dir
  7 | import Text.CSS.Flexbox
  8 | import Text.CSS.Gradient
  9 | import Text.CSS.Grid
 10 | import Text.CSS.Length
 11 | import Text.CSS.ListStyleType
 12 | import Text.CSS.Percentage
 13 | import Text.CSS.Property
 14 |
 15 | %default total
 16 |
 17 | public export
 18 | data Declaration : Type where
 19 |   Decl : (property, value : String) -> Declaration
 20 |   Display : Display -> Declaration
 21 |
 22 | public export
 23 | 0 Declarations : Type
 24 | Declarations = List Declaration
 25 |
 26 | export
 27 | Interpolation Declaration where
 28 |   interpolate (Decl p v) = "\{p}: \{v};"
 29 |   interpolate (Display None) = "display: none;"
 30 |   interpolate (Display InlineBlock) = "display: inline-block;"
 31 |   interpolate (Display Flex) = "display: flex;"
 32 |   interpolate (Display Grid) = "display: grid;"
 33 |   interpolate (Display $ Area rs cs a) = "\{renderArea rs cs a};"
 34 |
 35 | export %inline
 36 | decl : Interpolation a => String -> a -> Declaration
 37 | decl s = Decl s . interpolate
 38 |
 39 | -- prefix
 40 | prfx : Dir a -> String
 41 | prfx (Left _)   = "-left"
 42 | prfx (Right _)  = "-right"
 43 | prfx (Top _)    = "-top"
 44 | prfx (Bottom _) = "-bottom"
 45 | prfx _          = ""
 46 |
 47 | export
 48 | dirDecl : (prop : String) -> (a -> String) -> Dir a -> Declaration
 49 | dirDecl prop f d =
 50 |   let vs := concat . intersperse " " . map f $ vals d
 51 |    in Decl "\{prop}\{prfx d}" vs
 52 |
 53 | export
 54 | dirDecl2 : (prop,suffix : String) -> (a -> String) -> Dir a -> Declaration
 55 | dirDecl2 prop suffix f d =
 56 |   let vs := concat . intersperse " " . map f $ vals d
 57 |    in Decl "\{prop}\{prfx d}-\{suffix}" vs
 58 |
 59 | --------------------------------------------------------------------------------
 60 | --          Predefined Properties
 61 | --------------------------------------------------------------------------------
 62 |
 63 | export %inline
 64 | alignItems : FlexAlign -> Declaration
 65 | alignItems = decl "align-items"
 66 |
 67 | export %inline
 68 | alignSelf : FlexAlign -> Declaration
 69 | alignSelf = decl "align-self"
 70 |
 71 | export %inline
 72 | aspectRatio : Ratio -> Declaration
 73 | aspectRatio = decl "aspect-ratio"
 74 |
 75 | export %inline
 76 | backgroundColor : Color -> Declaration
 77 | backgroundColor = decl "background-color"
 78 |
 79 | export %inline
 80 | backgroundImage : (url : String) -> Declaration
 81 | backgroundImage = Decl "background-image"
 82 |
 83 | export %inline
 84 | backgroundImageGradient : Gradient -> Declaration
 85 | backgroundImageGradient = decl "background-image"
 86 |
 87 | export %inline
 88 | backgroundSize : Width -> Declaration
 89 | backgroundSize = decl "background-size"
 90 |
 91 | export %inline
 92 | border : String -> Declaration
 93 | border = Decl "border"
 94 |
 95 | export %inline
 96 | borderColor : Dir Color -> Declaration
 97 | borderColor = dirDecl2 "border" "color" interpolate
 98 |
 99 | export %inline
100 | borderRadius : BorderRadius -> Declaration
101 | borderRadius = decl "border-radius"
102 |
103 | export %inline
104 | borderTopLeftRadius : BorderRadius -> Declaration
105 | borderTopLeftRadius = decl "border-top-left-radius"
106 |
107 | export %inline
108 | borderTopRightRadius : BorderRadius -> Declaration
109 | borderTopRightRadius = decl "border-top-right-radius"
110 |
111 | export %inline
112 | borderBottomLeftRadius : BorderRadius -> Declaration
113 | borderBottomLeftRadius = decl "border-bottom-left-radius"
114 |
115 | export %inline
116 | borderBottomRightRadius : BorderRadius -> Declaration
117 | borderBottomRightRadius = decl "border-bottom-right-radius"
118 |
119 | export %inline
120 | borderStyle : Dir BorderStyle -> Declaration
121 | borderStyle = dirDecl2 "border" "style" interpolate
122 |
123 | export %inline
124 | borderWidth : Dir BorderWidth -> Declaration
125 | borderWidth = dirDecl2 "border" "width" interpolate
126 |
127 | export %inline
128 | boxSizing : BoxSizing -> Declaration
129 | boxSizing = decl "box-sizing"
130 |
131 | export %inline
132 | color : Color -> Declaration
133 | color = decl "color"
134 |
135 | export %inline
136 | columnGap : Length -> Declaration
137 | columnGap = decl "column-gap"
138 |
139 | export %inline
140 | containerType : ContainerType -> Declaration
141 | containerType = decl "container-type"
142 |
143 | export
144 | cursor : List Cursor -> Declaration
145 | cursor = decl "cursor" . fastConcat . intersperse "," . map interpolate
146 |
147 | export %inline
148 | direction : Direction -> Declaration
149 | direction = decl "direction"
150 |
151 | export %inline
152 | display : Display -> Declaration
153 | display = Display
154 |
155 | export %inline
156 | area :
157 |      {0 n,m : Nat}
158 |   -> {0 a : Type}
159 |   -> {auto as : Show a}
160 |   -> (rows    : Vect (S m) GridValue)
161 |   -> (columns : Vect (S n) GridValue)
162 |   -> (area    : Vect (S m) (Vect (S n) a))
163 |   -> Declaration
164 | area rs cs a = display (Area rs cs a)
165 |
166 | export
167 | fill : Maybe Color -> Declaration
168 | fill Nothing  = decl "fill" "none"
169 | fill (Just c) = decl "fill" c
170 |
171 | export %inline
172 | flex : String -> Declaration
173 | flex = Decl "flex"
174 |
175 | export %inline
176 | flexBasis : FlexBasis -> Declaration
177 | flexBasis = decl "flex-basis"
178 |
179 | export %inline
180 | flexDirection : FlexDirection -> Declaration
181 | flexDirection = decl "flex-direction"
182 |
183 | export %inline
184 | flexWrap : String -> Declaration
185 | flexWrap = Decl "flex-wrap"
186 |
187 | export %inline
188 | flexGrow : Nat -> Declaration
189 | flexGrow = Decl "flex-grow" . show
190 |
191 | export %inline
192 | flexFlow : List FlexFlow -> Declaration
193 | flexFlow = decl "flex-flow"
194 |
195 | export %inline
196 | fontFamily : String -> Declaration
197 | fontFamily = Decl "font-family"
198 |
199 | export %inline
200 | fontSize : FontSize -> Declaration
201 | fontSize = decl "font-size"
202 |
203 | export %inline
204 | fontStyle : FontStyle -> Declaration
205 | fontStyle = decl "font-style"
206 |
207 | export %inline
208 | fontWeight : FontWeight -> Declaration
209 | fontWeight = decl "font-weight"
210 |
211 | export %inline
212 | gridArea : Show a => a -> Declaration
213 | gridArea = Decl "grid-area" . showTag
214 |
215 | export %inline
216 | gridColumn : GridPosition -> Declaration
217 | gridColumn = decl "grid-column"
218 |
219 | export %inline
220 | gridRow : GridPosition -> Declaration
221 | gridRow = decl "grid-row"
222 |
223 | export %inline
224 | gridTemplateColumns : List GridValue -> Declaration
225 | gridTemplateColumns = decl "grid-template-columns"
226 |
227 | export %inline
228 | gridTemplateRows : List GridValue -> Declaration
229 | gridTemplateRows = decl "grid-template-rows"
230 |
231 | export %inline
232 | height : Width -> Declaration
233 | height = decl "height"
234 |
235 | export %inline
236 | justifyContent : FlexJustify -> Declaration
237 | justifyContent = decl "justify-content"
238 |
239 | export %inline
240 | justifySelf : FlexJustify -> Declaration
241 | justifySelf = decl "justify-self"
242 |
243 | export %inline
244 | lineHeight : LineHeight -> Declaration
245 | lineHeight = decl "line-height"
246 |
247 | export %inline
248 | listStyleType : ListStyleType -> Declaration
249 | listStyleType = decl "list-style-type"
250 |
251 | export %inline
252 | margin : Dir Length -> Declaration
253 | margin = dirDecl "margin" interpolate
254 |
255 | export %inline
256 | maxHeight : Width -> Declaration
257 | maxHeight = decl "max-height"
258 |
259 | export %inline
260 | maxWidth : Width -> Declaration
261 | maxWidth = decl "max-width"
262 |
263 | export %inline
264 | minHeight : Width -> Declaration
265 | minHeight = decl "min-height"
266 |
267 | export %inline
268 | minWidth : Width -> Declaration
269 | minWidth = decl "min-width"
270 |
271 | export %inline
272 | opacity : Percentage -> Declaration
273 | opacity = decl "opacity"
274 |
275 | export %inline
276 | outlineOffset : Length -> Declaration
277 | outlineOffset = decl "outline-offset"
278 |
279 | export %inline
280 | outlineColor : Color -> Declaration
281 | outlineColor = decl "outline-color"
282 |
283 | export %inline
284 | outlineStyle : BorderStyle -> Declaration
285 | outlineStyle = decl "outline-style"
286 |
287 | export %inline
288 | outlineWidth : BorderWidth -> Declaration
289 | outlineWidth = decl "outline-width"
290 |
291 | export %inline
292 | overflow : Overflow -> Declaration
293 | overflow = decl "overflow"
294 |
295 | export %inline
296 | overflowX : Overflow -> Declaration
297 | overflowX = decl "overflow-x"
298 |
299 | export %inline
300 | overflowY : Overflow -> Declaration
301 | overflowY = decl "overflow-y"
302 |
303 | export %inline
304 | padding : Dir Length -> Declaration
305 | padding = dirDecl "padding" interpolate
306 |
307 | export %inline
308 | position : Position -> Declaration
309 | position = decl "position"
310 |
311 | export %inline
312 | bottom : Pos -> Declaration
313 | bottom = decl "bottom"
314 |
315 | export %inline
316 | left : Pos -> Declaration
317 | left = decl "left"
318 |
319 | export %inline
320 | top : Pos -> Declaration
321 | top = decl "top"
322 |
323 | export %inline
324 | right : Pos -> Declaration
325 | right = decl "right"
326 |
327 | export %inline
328 | inset : Dir Pos -> Declaration
329 | inset = dirDecl "inset" interpolate
330 |
331 | export %inline
332 | resize : Resize -> Declaration
333 | resize = decl "resize"
334 |
335 | export %inline
336 | rowGap : Length -> Declaration
337 | rowGap = decl "row-gap"
338 |
339 | export
340 | stroke : Maybe Color -> Declaration
341 | stroke Nothing  = decl "stroke" "none"
342 | stroke (Just c) = decl "stroke" c
343 |
344 | export %inline
345 | scrollbarGutter : ScrollbarGutter -> Declaration
346 | scrollbarGutter = decl "scrollbar-gutter"
347 |
348 | export %inline
349 | strokeWidth : Width -> Declaration
350 | strokeWidth = decl "stroke-width"
351 |
352 | export %inline
353 | strokeLinecap : Linecap -> Declaration
354 | strokeLinecap = decl "stroke-linecap"
355 |
356 | export %inline
357 | strokeLinejoin : Linejoin -> Declaration
358 | strokeLinejoin = decl "stroke-linejoin"
359 |
360 | export %inline
361 | strokeMiterlimit : Double -> Declaration
362 | strokeMiterlimit = decl "stroke-miterlimit" . show
363 |
364 | export %inline
365 | textAlign : TextAlign -> Declaration
366 | textAlign = decl "text-align"
367 |
368 | export %inline
369 | textDecoration : String -> Declaration
370 | textDecoration = Decl "text-decoration"
371 |
372 | export %inline
373 | textDecorationColor : Color -> Declaration
374 | textDecorationColor = decl "text-decoration-color"
375 |
376 | export %inline
377 | textDecorationLine : TextDecorationLine -> Declaration
378 | textDecorationLine = decl "text-decoration-line"
379 |
380 | export %inline
381 | textDecorationStyle : TextDecorationStyle -> Declaration
382 | textDecorationStyle = decl "text-decoration-style"
383 |
384 | export %inline
385 | textOverflow : TextOverflow -> Declaration
386 | textOverflow = decl "text-overflow"
387 |
388 | export %inline
389 | textOverflow2 : TextOverflow -> TextOverflow -> Declaration
390 | textOverflow2 x y = Decl "text-overflow" "\{x} \{y}"
391 |
392 | export %inline
393 | visibility : Visibility -> Declaration
394 | visibility = decl "visibility"
395 |
396 | export %inline
397 | width : Width -> Declaration
398 | width = decl "width"
399 |
400 | export %inline
401 | whitespace : WhiteSpace -> Declaration
402 | whitespace = decl "white-space"
403 |