git.iko.soy/rowtype-yoga/psfp
on 6d7f609 help sign in
100 lines 3.7 kB history raw
1module Yoga.Theme where
3import Prelude
4import CSS (contrast, darken, isLight, lighten, rotateHue)
5import Color (Color)
6import Color as Color
7import Data.Foldable (intercalate)
8import Data.Maybe (fromMaybe)
9import Data.Symbol (SProxy(..))
10import Record.Builder as RB
11import Yoga.Theme.Types (Theme, CSSTheme)
13increaseContrast ∷ Color -> Color -> Color
14increaseContrast contrastWith = go 0
15 where
16 modify = if isLight contrastWith then darken else lighten
17 go i col =
18 if contrast contrastWith col >= 7.5 || i >= 20 then
19 col
20 else
21 go (i + 1) (modify 0.1 col)
23withAlpha ∷ Number -> Color -> Color
24withAlpha alpha c1 = Color.rgba' r g b alpha
25 where
26 { r, g, b } = Color.toRGBA' c1
28unsafeWithAlpha ∷ Number -> String -> String
29unsafeWithAlpha alpha s1 =
30 fromMaybe "yellow" do
31 c1 <- Color.fromHexString s1
32 let
33 { r, g, b } = Color.toRGBA' c1
34 pure $ Color.cssStringRGBA (Color.rgba' r g b alpha)
36unsafeAlaColor ∷ (Color -> Color) -> String -> String
37unsafeAlaColor fn s1 =
38 fromMaybe "hotpink" do
39 c1 <- Color.fromHexString s1
40 pure $ Color.toHexString (fn c1)
42f ∷ ∀ fieldName. SProxy fieldName
43f = SProxy
45fromTheme ∷ Theme -> CSSTheme
46fromTheme theme =
47 RB.build
48 ( {- background -} RB.insert (f ∷ _ "backgroundColourLighter")
49 (theme.backgroundColour # lighter)
50 >>> RB.insert (f ∷ _ "backgroundColourLightest")
51 (theme.backgroundColour # lighter # lighter)
52 >>> RB.insert (f ∷ _ "backgroundColourDarker")
53 (theme.backgroundColour # darker)
54 >>> RB.insert (f ∷ _ "backgroundColourDarkest")
55 (theme.backgroundColour # darker # darker)
56 >>> RB.insert (f ∷ _ "interfaceColourLighter")
57 (theme.interfaceColour # lighter)
58 >>> RB.insert (f ∷ _ "interfaceColourLightest")
59 (theme.interfaceColour # lighter >>> lighter)
60 >>> RB.insert (f ∷ _ "interfaceColourDarker")
61 (theme.interfaceColour # darker)
62 >>> RB.insert (f ∷ _ "interfaceColourDarkest")
63 (theme.interfaceColour # darker >>> darker)
64 -- foreground
66 >>> RB.insert (f ∷ _ "textColourLighter")
67 (theme.textColour # lighter)
68 >>> RB.insert (f ∷ _ "textColourLightest")
69 (theme.textColour # lighter >>> lighter)
70 >>> RB.insert (f ∷ _ "textColourDarker")
71 (theme.textColour # darker)
72 >>> RB.insert (f ∷ _ "textColourDarkest")
73 (theme.textColour # darker >>> darker)
74 -- highlight
76 >>> RB.insert (f ∷ _ "highlightColourDark")
77 (theme.highlightColour # darken 0.2 # rotateHue (-10.0))
78 >>> RB.insert (f ∷ _ "highlightColourRotatedForwards")
79 (theme.highlightColour # rotateHue (20.0))
80 >>> RB.insert (f ∷ _ "highlightColourRotatedBackwards")
81 (theme.highlightColour # rotateHue (-20.0))
82 -- altHighlight
84 >>> RB.insert (f ∷ _ "altHighlightColourDark")
85 (theme.altHighlightColour # darken 0.2)
86 -- fonts
88 >>> RB.modify (f ∷ _ "textFontFamily") (intercalate ",")
89 >>> RB.modify (f ∷ _ "headingFontFamily") (intercalate ",")
90 >>> RB.modify (f ∷ _ "codeFontFamily") (intercalate ",")
91 >>> RB.insert (f ∷ _ "isLight") isLightTheme
92 >>> RB.insert (f ∷ _ "fontWeightBold") "300"
93 )
94 theme
95 where
96 isLightTheme = isLight theme.backgroundColour
97 lighter ∷ Color -> Color
98 lighter = if isLightTheme then lighten 0.04 else lighten 0.02
99 darker ∷ Color -> Color
100 darker = if isLightTheme then darken 0.01 else darken 0.01