git.iko.soy/rowtype-yoga/psfp
on 15d5152 help sign in
95 lines 3.5 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)
23unsafeWithAlpha ∷ Number -> String -> String
24unsafeWithAlpha alpha s1 =
25 fromMaybe "yellow" do
26 c1 <- Color.fromHexString s1
27 let
28 { r, g, b } = Color.toRGBA' c1
29 pure $ Color.cssStringRGBA (Color.rgba' r g b alpha)
31unsafeAlaColor ∷ (Color -> Color) -> String -> String
32unsafeAlaColor fn s1 =
33 fromMaybe "hotpink" do
34 c1 <- Color.fromHexString s1
35 pure $ Color.toHexString (fn c1)
37f ∷ ∀ fieldName. SProxy fieldName
38f = SProxy
40fromTheme ∷ Theme -> CSSTheme
41fromTheme theme =
42 RB.build
43 ( {- background -} RB.insert (f ∷ _ "backgroundColourLighter")
44 (theme.backgroundColour # lighter)
45 >>> RB.insert (f ∷ _ "backgroundColourLightest")
46 (theme.backgroundColour # lighter # lighter)
47 >>> RB.insert (f ∷ _ "backgroundColourDarker")
48 (theme.backgroundColour # darker)
49 >>> RB.insert (f ∷ _ "backgroundColourDarkest")
50 (theme.backgroundColour # darker # darker)
51 >>> RB.insert (f ∷ _ "interfaceColourLighter")
52 (theme.interfaceColour # lighter)
53 >>> RB.insert (f ∷ _ "interfaceColourLightest")
54 (theme.interfaceColour # lighter >>> lighter)
55 >>> RB.insert (f ∷ _ "interfaceColourDarker")
56 (theme.interfaceColour # darker)
57 >>> RB.insert (f ∷ _ "interfaceColourDarkest")
58 (theme.interfaceColour # darker >>> darker)
59 -- foreground
61 >>> RB.insert (f ∷ _ "textColourLighter")
62 (theme.textColour # lighter)
63 >>> RB.insert (f ∷ _ "textColourLightest")
64 (theme.textColour # lighter >>> lighter)
65 >>> RB.insert (f ∷ _ "textColourDarker")
66 (theme.textColour # darker)
67 >>> RB.insert (f ∷ _ "textColourDarkest")
68 (theme.textColour # darker >>> darker)
69 -- highlight
71 >>> RB.insert (f ∷ _ "highlightColourDark")
72 (theme.highlightColour # darken 0.2 # rotateHue (-10.0))
73 >>> RB.insert (f ∷ _ "highlightColourRotatedForwards")
74 (theme.highlightColour # rotateHue (20.0))
75 >>> RB.insert (f ∷ _ "highlightColourRotatedBackwards")
76 (theme.highlightColour # rotateHue (-20.0))
77 -- altHighlight
79 >>> RB.insert (f ∷ _ "altHighlightColourDark")
80 (theme.altHighlightColour # darken 0.2)
81 -- fonts
83 >>> RB.modify (f ∷ _ "textFontFamily") (intercalate ",")
84 >>> RB.modify (f ∷ _ "headingFontFamily") (intercalate ",")
85 >>> RB.modify (f ∷ _ "codeFontFamily") (intercalate ",")
86 >>> RB.insert (f ∷ _ "isLight") isLightTheme
87 >>> RB.insert (f ∷ _ "fontWeightBold") "300"
88 )
89 theme
90 where
91 isLightTheme = isLight theme.backgroundColour
92 lighter ∷ Color -> Color
93 lighter = if isLightTheme then lighten 0.04 else lighten 0.02
94 darker ∷ Color -> Color
95 darker = if isLightTheme then darken 0.01 else darken 0.01