forked from mdgriffith/elm-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Accumulator.elm
57 lines (38 loc) · 934 Bytes
/
Accumulator.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
module Accumulation exposing (..)
{-| -}
import Set
type Style
= Color String Float Float Float Float
| Spacing String Float
| Font String (List String)
key style =
case style of
Color k _ _ _ _ ->
k
Spacing k _ ->
k
Font k _ ->
k
type Element
= Element (List Style) (List Element)
| None
render element =
case element of
None ->
[]
Element styles children ->
let
childrenStyles =
List.foldr render [] children
in
styles ++ childrenStyles
finalize styles =
List.foldl deduplicate ( Set.empty, [] ) styles
deduplicate style ( cached, styles ) =
if Set.member (key style) then
( cached, styles )
else
( Set.insert (key style), style :: styles )
toHtml element =
render element
|> finalize