Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ThemeBrowserAdapter {
}

private fun buildJsCodeToUpdateTheme(theme: AmazonQTheme) = buildString {
val (bg, altBg, inputBg) = determineInputAndBgColor(theme)
appendDarkMode(theme.darkMode)

append("{\n")
Expand All @@ -42,14 +43,14 @@ class ThemeBrowserAdapter {
append(CssVariable.TextColorWeak, theme.inactiveText)
append(CssVariable.TextColorDisabled, theme.inactiveText)

append(CssVariable.Background, theme.editorBackground)
append(CssVariable.BackgroundAlt, theme.background)
append(CssVariable.CardBackground, theme.editorBackground)
append(CssVariable.CardBackgroundAlt, theme.background)
append(CssVariable.Background, bg)
append(CssVariable.BackgroundAlt, altBg)
append(CssVariable.CardBackground, bg)
append(CssVariable.CardBackgroundAlt, altBg)
append(CssVariable.BorderDefault, theme.border)
append(CssVariable.TabActive, theme.activeTab)

append(CssVariable.InputBackground, theme.textFieldBackground)
append(CssVariable.InputBackground, inputBg)

append(CssVariable.ButtonBackground, theme.buttonBackground)
append(CssVariable.ButtonForeground, theme.buttonForeground)
Expand Down Expand Up @@ -110,4 +111,13 @@ class ThemeBrowserAdapter {

// 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.
private fun Font.toCssFontFamily(fallback: String = "system-ui") = "\"$family\", $fallback"

// darkest = bg, second darkest is alt bg, lightest is input bg
private fun determineInputAndBgColor(theme: AmazonQTheme): Triple<Color, Color, Color> {
val colors = arrayOf(theme.editorBackground, theme.background, theme.textFieldBackground).sortedWith(Comparator.comparing {
// luma calculation for brightness
(0.2126 * it.red) + (0.7152 * it.green) + (0.0722 * it.blue)
})
return Triple(colors[0], colors[1], colors[2])
}
}
Loading