git.iko.soy/rowtype-yoga/psfp
on a6e8f77 help sign in
92 lines 3.2 kB history raw
1module Theme where
3import Prelude
5import CSS (ColorSpace(..), blue, brightness, contrast, darken, desaturate, isLight, lighten, mix, rotateHue, toHexString)
6import Color (Color)
7import Data.Foldable (intercalate)
8import Data.Symbol (SProxy(..))
9import Record.Builder as RB
10import Theme.Types (Theme, CSSTheme)
12increaseContrast ∷ Color -> Color -> Color
13increaseContrast contrastWith = go 0
14 where
15 modify = if isLight contrastWith then darken else lighten
16 go i col
17 = if contrast contrastWith col >= 7.5 || i >= 20
18 then col
19 else go (i+1) (modify 0.1 col)
22f ∷ ∀ fieldName. SProxy fieldName
23f = SProxy
25fromTheme ∷ Theme -> CSSTheme
26fromTheme theme = RB.build (
27 -- background
28 RB.modify (f ∷ _ "backgroundColour") toHexString
29 >>> RB.insert (f ∷ _ "backgroundColourLighter")
30 (theme.backgroundColour # lighter >>> toHexString)
31 >>> RB.modify (f ∷ _ "interfaceColour") toHexString
32 >>> RB.insert (f ∷ _ "interfaceColourLighter")
33 (theme.interfaceColour # lighter >>> toHexString)
34 >>> RB.insert (f ∷ _ "interfaceColourLightest")
35 (theme.interfaceColour # lighter >>> lighter >>> toHexString)
36 >>> RB.insert (f ∷ _ "interfaceColourDarker")
37 (theme.interfaceColour # darker >>> toHexString)
38 >>> RB.insert (f ∷ _ "interfaceColourDarkest")
39 (theme.interfaceColour # darker >>> darker >>> toHexString)
40 -- foreground
41 >>> RB.modify (f ∷ _ "textColour") toHexString
42 >>> RB.insert (f ∷ _ "textColourLighter")
43 (theme.textColour # lighter >>> toHexString)
44 >>> RB.insert (f ∷ _ "textColourLightest")
45 (theme.textColour # lighter >>> lighter >>> toHexString)
46 >>> RB.insert (f ∷ _ "textColourDarker")
47 (theme.textColour # darker >>> toHexString)
48 >>> RB.insert (f ∷ _ "textColourDarkest")
49 (theme.textColour # darker >>> darker >>> toHexString)
50 -- highlight
51 >>> RB.modify (f ∷ _ "highlightColour") toHexString
52 >>> RB.insert (f ∷ _ "highlightColourDark")
53 (theme.highlightColour # darken 0.2 # rotateHue (-10.0) # toHexString)
54 -- altHighlight
55 >>> RB.modify (f ∷ _ "altHighlightColour") toHexString
56 >>> RB.insert (f ∷ _ "altHighlightColourDark")
57 (theme.altHighlightColour # darken 0.2 # toHexString)
58 -- palette
59 >>> RB.modify (f ∷ _ "yellow") toHexString
60 >>> RB.modify (f ∷ _ "green") toHexString
61 >>> RB.modify (f ∷ _ "pink") toHexString
62 >>> RB.modify (f ∷ _ "orange") toHexString
63 >>> RB.modify (f ∷ _ "turquoise") toHexString
64 >>> RB.modify (f ∷ _ "red") toHexString
65 >>> RB.modify (f ∷ _ "blue") toHexString
66 -- fonts
67 >>> RB.modify (f ∷ _ "textFontFamily") (intercalate ",")
68 >>> RB.modify (f ∷ _ "headingFontFamily") (intercalate ",")
69 >>> RB.insert (f ∷ _ "isLight") isLightTheme
70 ) theme
71 where
72 isLightTheme = isLight theme.backgroundColour
73 yellower ∷ Color -> Color
74 yellower col =
75 if brightness col > 0.8
76 then
77 lighten 0.02 col
78 else
79 col
80 # lighten 0.1
81 # desaturate 0.03
83 bluer col =
84 mix HSL col blue 0.05
85 # darken 0.1
86 # desaturate 0.03
88 lighter ∷ Color -> Color
89 lighter = yellower
91 darker ∷ Color -> Color
92 darker = bluer