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