@@ -26,6 +26,7 @@ class ThemeBrowserAdapter {
2626 }
2727
2828 private fun buildJsCodeToUpdateTheme (theme : AmazonQTheme ) = buildString {
29+ val (bg, altBg, inputBg) = determineInputAndBgColor(theme)
2930 appendDarkMode(theme.darkMode)
3031
3132 append(" {\n " )
@@ -42,14 +43,14 @@ class ThemeBrowserAdapter {
4243 append(CssVariable .TextColorWeak , theme.inactiveText)
4344 append(CssVariable .TextColorDisabled , theme.inactiveText)
4445
45- append(CssVariable .Background , theme.editorBackground )
46- append(CssVariable .BackgroundAlt , theme.background )
47- append(CssVariable .CardBackground , theme.editorBackground )
48- append(CssVariable .CardBackgroundAlt , theme.background )
46+ append(CssVariable .Background , bg )
47+ append(CssVariable .BackgroundAlt , altBg )
48+ append(CssVariable .CardBackground , bg )
49+ append(CssVariable .CardBackgroundAlt , altBg )
4950 append(CssVariable .BorderDefault , theme.border)
5051 append(CssVariable .TabActive , theme.activeTab)
5152
52- append(CssVariable .InputBackground , theme.textFieldBackground )
53+ append(CssVariable .InputBackground , inputBg )
5354
5455 append(CssVariable .ButtonBackground , theme.buttonBackground)
5556 append(CssVariable .ButtonForeground , theme.buttonForeground)
@@ -110,4 +111,15 @@ class ThemeBrowserAdapter {
110111
111112 // Some font names have characters that require them to be wrapped in quotes in the CSS variable, for example if they have spaces or a period.
112113 private fun Font.toCssFontFamily (fallback : String = "system-ui") = " \" $family \" , $fallback "
114+
115+ // darkest = bg, second darkest is alt bg, lightest is input bg
116+ private fun determineInputAndBgColor (theme : AmazonQTheme ): Triple <Color , Color , Color > {
117+ val colors = arrayOf(theme.editorBackground, theme.background, theme.textFieldBackground).sortedWith(
118+ Comparator .comparing {
119+ // luma calculation for brightness
120+ (0.2126 * it.red) + (0.7152 * it.green) + (0.0722 * it.blue)
121+ }
122+ )
123+ return Triple (colors[0 ], colors[1 ], colors[2 ])
124+ }
113125}
0 commit comments