diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index bdd37caf7..681895a55 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.36", + "version": "1.1.37", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.36", + "version": "1.1.37", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", diff --git a/gui/src/App.tsx b/gui/src/App.tsx index 03b6fb05a..6fc120707 100644 --- a/gui/src/App.tsx +++ b/gui/src/App.tsx @@ -9,6 +9,7 @@ import ErrorPage from "./pages/error"; import Chat from "./pages/gui"; import History from "./pages/history"; import Stats from "./pages/stats"; +import ThemePage from "./styles/ThemePage"; import { ROUTES } from "./util/navigation"; const router = createMemoryRouter([ @@ -37,6 +38,10 @@ const router = createMemoryRouter([ path: ROUTES.CONFIG, element: , }, + { + path: ROUTES.THEME, + element: , + }, ], }, ]); diff --git a/gui/src/components/StyledMarkdownPreview/SymbolLink.tsx b/gui/src/components/StyledMarkdownPreview/SymbolLink.tsx index 40ca69708..8224af794 100644 --- a/gui/src/components/StyledMarkdownPreview/SymbolLink.tsx +++ b/gui/src/components/StyledMarkdownPreview/SymbolLink.tsx @@ -44,14 +44,7 @@ function SymbolLink({ symbol, content }: SymbolLinkProps) { data-tooltip-id={id} data-tooltip-delay-show={500} > - - {content} - + {content}
{processedContent ?? symbol.filepath}
diff --git a/gui/src/components/TabBar/TabBar.tsx b/gui/src/components/TabBar/TabBar.tsx index 3b87a23c6..2fe905674 100644 --- a/gui/src/components/TabBar/TabBar.tsx +++ b/gui/src/components/TabBar/TabBar.tsx @@ -13,13 +13,25 @@ import { } from "../../redux/slices/tabsSlice"; import { AppDispatch, RootState } from "../../redux/store"; import { loadSession, saveCurrentSession } from "../../redux/thunks/session"; +import { varWithFallback } from "../../styles/theme"; + +// Haven't set up theme colors for tabs yet +// Will keep it simple and choose from existing ones. Comments show vars we could use +const tabBorderVar = varWithFallback("border"); // --vscode-tab-border +const tabBackgroundVar = varWithFallback("background"); // --vscode-tab-inactiveBackground +const tabForegroundVar = varWithFallback("foreground"); // --vscode-tab-inactiveForeground +const tabHoverBackgroundVar = varWithFallback("list-hover"); // --vscode-tab-hoverBackground +const tabHoverForegroundVar = varWithFallback("foreground"); // --vscode-tab-hoverForeground +const tabSelectedBackgroundVar = varWithFallback("list-hover"); // --vscode-tab-activeBackground +const tabSelectedForegroundVar = varWithFallback("list-active-foreground"); // --vscode-tab-activeForeground +const tabAccentVar = varWithFallback("accent"); // --vscode-tab-activeBorderTop const TabBarContainer = styled.div` display: flex; flex-wrap: wrap; flex-shrink: 0; flex-grow: 0; - background-color: var(--vscode-tab-inactiveBackground); + background-color: ${tabBackgroundVar}; border-bottom: none; position: relative; margin-top: 2px; @@ -41,24 +53,18 @@ const Tab = styled.div<{ isActive: boolean }>` max-width: 150px; height: 25px; background-color: ${(props) => - props.isActive - ? "var(--vscode-tab-activeBackground)" - : "var(--vscode-tab-inactiveBackground)"}; + props.isActive ? tabSelectedBackgroundVar : tabBackgroundVar}; color: ${(props) => - props.isActive - ? "var(--vscode-tab-activeForeground)" - : "var(--vscode-tab-inactiveForeground)"}; + props.isActive ? tabSelectedForegroundVar : tabForegroundVar}; cursor: pointer; - border: 1px solid var(--vscode-tab-border); + border: 1px solid ${tabBorderVar}; border-bottom: ${(props) => - props.isActive ? "none" : `1px solid var(--vscode-tab-border)`}; + props.isActive ? "none" : `1px solid ${tabBorderVar}`}; user-select: none; position: relative; transition: background-color 0.2s; border-top: ${(props) => - props.isActive - ? `1px solid var(--vscode-tab-activeBorderTop, --vscode-tab-border)` - : `1px solid var(--vscode-tab-border)`}; + props.isActive ? `1px solid ${tabAccentVar}` : `1px solid ${tabBorderVar}`}; &:first-child { border-left: none; } @@ -68,13 +74,9 @@ const Tab = styled.div<{ isActive: boolean }>` &:hover { background-color: ${(props) => - props.isActive - ? "var(--vscode-tab-activeBackground)" - : "var(--vscode-tab-hoverBackground)"}; + props.isActive ? tabSelectedBackgroundVar : tabHoverBackgroundVar}; color: ${(props) => - props.isActive - ? "var(--vscode-tab-activeForeground)" - : "var(--vscode-tab-hoverForeground)"}; + props.isActive ? tabSelectedForegroundVar : tabHoverForegroundVar}; } `; @@ -104,7 +106,7 @@ const CloseButton = styled.button` &:hover { opacity: 1; - background-color: var(--vscode-tab-hoverBackground); + background-color: ${tabHoverBackgroundVar}; } ${Tab}:hover & { @@ -119,33 +121,12 @@ const CloseButton = styled.button` const TabBarSpace = styled.div` flex: 1; display: flex; - border-bottom: 1px solid var(--vscode-tab-border); - background-color: var(--vscode-tab-inactiveBackground); -`; - -const NewTabButton = styled.button` - display: flex; - align-items: center; - justify-content: center; - width: 35px; - height: 100%; - border: none; - background: transparent; - color: var(--vscode-tab-inactiveForeground); - cursor: pointer; - opacity: 0.7; - transition: opacity 0.2s; - - &:hover { - opacity: 1; - background-color: var(--vscode-tab-hoverBackground); - color: var(--vscode-tab-hoverForeground); - } + border-bottom: 1px solid ${tabBorderVar}; + background-color: ${tabBackgroundVar}; `; export function TabBar() { const dispatch = useDispatch(); - const currentSession = useSelector((state: RootState) => state.session); const currentSessionId = useSelector((state: RootState) => state.session.id); const currentSessionTitle = useSelector( (state: RootState) => state.session.title, diff --git a/gui/src/components/dialogs/index.tsx b/gui/src/components/dialogs/index.tsx index 5acf040b6..c4a80e0b4 100644 --- a/gui/src/components/dialogs/index.tsx +++ b/gui/src/components/dialogs/index.tsx @@ -4,12 +4,12 @@ import ReactMarkdown from "react-markdown"; import styled from "styled-components"; import { CloseButton, - VSC_BACKGROUND_VAR, defaultBorderRadius, - parseColorForHex, vscBackground, vscForeground, } from ".."; +import { THEME_COLORS } from "../../styles/theme"; +import { parseColorForHex } from "../../styles/utils"; interface TextDialogProps { showDialog: boolean; @@ -22,7 +22,7 @@ const ScreenCover = styled.div` position: fixed; width: 100%; height: 100%; - background-color: ${parseColorForHex(VSC_BACKGROUND_VAR)}aa; + background-color: ${parseColorForHex(THEME_COLORS["background"].var)}aa; z-index: 100000; flex-direction: column; `; diff --git a/gui/src/components/find/FindWidget.tsx b/gui/src/components/find/FindWidget.tsx index fd174f59c..c5a245d8f 100644 --- a/gui/src/components/find/FindWidget.tsx +++ b/gui/src/components/find/FindWidget.tsx @@ -12,8 +12,8 @@ import { useState, } from "react"; import { HeaderButton, Input } from ".."; -import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; import { useAppSelector } from "../../redux/hooks"; +import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; interface SearchMatch { index: number; @@ -41,7 +41,7 @@ const HighlightOverlay = (props: HighlightOverlayProps) => { const { isCurrent, top, left, width, height } = props; return (
+
6) { - hexColor = hexColor.slice(0, 6); - } - - const r = parseInt(hexColor.substring(0, 2), 16); - const g = parseInt(hexColor.substring(2, 4), 16); - const b = parseInt(hexColor.substring(4, 6), 16); - - return { r, g, b }; -} - -export function parseColorForHex(colorVar: string): string { - const value = getComputedStyle(document.documentElement).getPropertyValue( - colorVar, - ); - if (value.startsWith("#")) { - return value.slice(0, 7); - } - - // Parse rgb/rgba - const rgbValues = value - .slice(value.startsWith("rgba") ? 5 : 4, -1) - .split(",") - .map((x) => x.trim()) - .filter((_, i) => i < 3) // Only take the first 3 values (RGB, ignore alpha) - .map((x) => parseInt(x, 10)); - - let hex = - "#" + - rgbValues - .map((x) => x.toString(16)) - .map((x) => (x.length === 1 ? "0" + x : x)) - .join(""); - - return hex; -} +export const vscInputBackground = varWithFallback("input-background"); +export const vscQuickInputBackground = varWithFallback("input-background"); +export const vscBackground = varWithFallback("background"); +export const vscForeground = varWithFallback("foreground"); +export const vscButtonBackground = varWithFallback("primary-background"); +export const vscButtonForeground = varWithFallback("primary-foreground"); +export const vscEditorBackground = varWithFallback("editor"); +export const vscListActiveBackground = varWithFallback("list-active"); +export const vscFocusBorder = varWithFallback("border-focus"); +export const vscListActiveForeground = varWithFallback( + "list-active-foreground", +); +export const vscInputBorder = varWithFallback("input-border"); +export const vscInputBorderFocus = varWithFallback("border-focus"); +export const vscBadgeBackground = varWithFallback("badge"); +export const vscBadgeForeground = varWithFallback("badge-foreground"); +export const vscCommandCenterActiveBorder = varWithFallback( + "command-border-focus", +); +export const vscCommandCenterInactiveBorder = varWithFallback("command-border"); export const Button = styled.button` padding: 6px 12px; @@ -226,10 +143,6 @@ export const Input = styled.input` } `; -export const Label = styled.label<{ fontSize?: number }>` - font-size: ${(props) => props.fontSize || getFontSize()}px; -`; - export const HeaderButton = styled.button<{ inverted: boolean | undefined; backgroundColor?: string; diff --git a/gui/src/components/mainInput/TipTapEditor/components/ExpandableToolbarPreview.tsx b/gui/src/components/mainInput/TipTapEditor/components/ExpandableToolbarPreview.tsx index a5b89d0f4..3b8359e96 100644 --- a/gui/src/components/mainInput/TipTapEditor/components/ExpandableToolbarPreview.tsx +++ b/gui/src/components/mainInput/TipTapEditor/components/ExpandableToolbarPreview.tsx @@ -159,7 +159,7 @@ export function ExpandableToolbarPreview(props: ExpandableToolbarPreviewProps) { contentEditable={false} >
diff --git a/gui/src/context/VscTheme.tsx b/gui/src/context/VscTheme.tsx index 2ca1dac59..8a0195141 100644 --- a/gui/src/context/VscTheme.tsx +++ b/gui/src/context/VscTheme.tsx @@ -1,6 +1,6 @@ import { createContext, useContext, useState } from "react"; -import { parseHexColor } from "../components"; import { useWebviewListener } from "../hooks/useWebviewListener"; +import { parseHexColor } from "../styles/utils"; const hljsToTextMate: Record = { ".hljs-comment": ["comment"], diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index 1b609ce39..a0a2fd209 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -1,5 +1,4 @@ import { useCallback, useContext, useEffect, useRef } from "react"; -import { VSC_THEME_COLOR_VARS } from "../components"; import { IdeMessengerContext } from "../context/IdeMessenger"; import { EDIT_MODE_STREAM_ID } from "core/edit/constants"; @@ -29,6 +28,7 @@ import { cancelStream } from "../redux/thunks/cancelStream"; import { refreshSessionMetadata } from "../redux/thunks/session"; import { streamResponseThunk } from "../redux/thunks/streamResponse"; import { updateFileSymbolsFromHistory } from "../redux/thunks/updateFileSymbols"; +import { THEME_COLORS } from "../styles/theme"; import { isJetBrains } from "../util"; import { setLocalStorage } from "../util/localStorage"; import { useWebviewListener } from "./useWebviewListener"; @@ -139,20 +139,21 @@ function ParallelListeners() { dispatch(cancelStream()); const jetbrains = isJetBrains(); - for (const colorVar of VSC_THEME_COLOR_VARS) { + for (const [colorName, themeVals] of Object.entries(THEME_COLORS)) { + const cssVarName = themeVals.var; if (jetbrains) { - const cached = localStorage.getItem(colorVar); + const cached = localStorage.getItem(colorName); if (cached) { - document.body.style.setProperty(colorVar, cached); + document.body.style.setProperty(cssVarName, cached); } } // Remove alpha channel from colors const value = getComputedStyle(document.documentElement).getPropertyValue( - colorVar, + cssVarName, ); - if (colorVar.startsWith("#") && value.length > 7) { - document.body.style.setProperty(colorVar, value.slice(0, 7)); + if (value.startsWith("#") && value.length > 7) { + document.body.style.setProperty(cssVarName, value.slice(0, 7)); } } @@ -160,9 +161,11 @@ function ParallelListeners() { // Save theme colors to local storage for immediate loading in JetBrains ideMessenger.request("jetbrains/getColors", undefined).then((result) => { if (result.status === "success") { - Object.entries(result.content).forEach(([key, value]) => { - document.body.style.setProperty(key, value); - document.documentElement.style.setProperty(key, value); + Object.entries(result.content).forEach(([colorName, value]) => { + const cssVarName = + THEME_COLORS[colorName as keyof typeof THEME_COLORS]?.var; + document.body.style.setProperty(cssVarName, value); + document.documentElement.style.setProperty(cssVarName, value); }); } }); @@ -181,12 +184,10 @@ function ParallelListeners() { (window as any).vscMediaUrl = msg.vscMediaUrl; }); - for (const colorVar of VSC_THEME_COLOR_VARS) { - if (document.body.style.getPropertyValue(colorVar)) { - localStorage.setItem( - colorVar, - document.body.style.getPropertyValue(colorVar), - ); + for (const [colorName, themeVals] of Object.entries(THEME_COLORS)) { + const currentVal = document.body.style.getPropertyValue(themeVals.var); + if (currentVal) { + localStorage.setItem(colorName, currentVal); } } } @@ -196,8 +197,9 @@ function ParallelListeners() { "jetbrains/setColors", async (data) => { Object.entries(data).forEach(([key, value]) => { - document.body.style.setProperty(key, value); - document.documentElement.style.setProperty(key, value); + const cssVarName = THEME_COLORS[key as keyof typeof THEME_COLORS]?.var; + document.body.style.setProperty(cssVarName, value); + document.documentElement.style.setProperty(cssVarName, value); }); }, [], diff --git a/gui/src/index.css b/gui/src/index.css index 6ef5e902e..34d0d004f 100644 --- a/gui/src/index.css +++ b/gui/src/index.css @@ -25,7 +25,7 @@ body, #root { height: 100%; line-height: 1.3; - background-color: var(--vscode-editor-background); + background-color: var(--vscode-sideBar-background); font-family: system-ui, -apple-system, @@ -42,7 +42,7 @@ body, body { padding: 0; - color: var(--vscode-editor-foreground); + color: var(--vscode-sideBar-foreground); padding: 0px; margin: 0px; height: 100%; diff --git a/gui/src/pages/config/HelpCenterSection.tsx b/gui/src/pages/config/HelpCenterSection.tsx index a82b775a8..e49a17780 100644 --- a/gui/src/pages/config/HelpCenterSection.tsx +++ b/gui/src/pages/config/HelpCenterSection.tsx @@ -1,6 +1,7 @@ import { ArrowTopRightOnSquareIcon, DocumentArrowUpIcon, + PaintBrushIcon, TableCellsIcon, } from "@heroicons/react/24/outline"; import { useContext } from "react"; @@ -9,6 +10,7 @@ import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useAppDispatch } from "../../redux/hooks"; import { setOnboardingCard } from "../../redux/slices/uiSlice"; import { saveCurrentSession } from "../../redux/thunks/session"; +import { ROUTES } from "../../util/navigation"; import MoreHelpRow from "./MoreHelpRow"; export function HelpCenterSection() { @@ -83,6 +85,16 @@ export function HelpCenterSection() { ideMessenger.post("showTutorial", undefined); }} /> + {process.env.NODE_ENV === "development" && ( + { + navigate(ROUTES.THEME); + }} + /> + )}
); diff --git a/gui/src/pages/config/KeyboardShortcuts.tsx b/gui/src/pages/config/KeyboardShortcuts.tsx index d7c3828d7..77d8c2733 100644 --- a/gui/src/pages/config/KeyboardShortcuts.tsx +++ b/gui/src/pages/config/KeyboardShortcuts.tsx @@ -11,7 +11,7 @@ interface KeyboardShortcutProps { function KeyboardShortcut(props: KeyboardShortcutProps) { return (
{props.description}: diff --git a/gui/src/styles/ThemePage.tsx b/gui/src/styles/ThemePage.tsx new file mode 100644 index 000000000..c08252b35 --- /dev/null +++ b/gui/src/styles/ThemePage.tsx @@ -0,0 +1,136 @@ +import { + CheckCircleIcon, + ExclamationCircleIcon, + ExclamationTriangleIcon, +} from "@heroicons/react/24/outline"; +import { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { THEME_COLORS } from "./theme"; + +const ThemeTailwindClassExample = ({ + className, + varName, + defaultColor, +}: { + className: string; + varName: string; + defaultColor: string; +}) => { + return ( + <> +
+ {className} +
+
+ {varName} +
+
+ {defaultColor} +
+ + ); +}; + +function ThemePage() { + const navigate = useNavigate(); + const [listToggled, setListToggled] = useState(false); + return ( +
+ navigate("/more")} + > + ← + Back to Settings + + +
+
+

Normal text

+

Description text

+

Muted text

+
+ + + + +
+ Normal border +
+ +
+ Focus border +
+ + + +
+ Badge +
+ +
+
+ + Success +
+
+ + Warning +
+
+ + Error +
+
+ +
setListToggled(!listToggled)} + className={`cursor-pointer p-2 ${listToggled ? "bg-list-active text-list-active-foreground" : "bg-background text-foreground hover:bg-list-hover"}`} + > + List item (click to select) +
+
+ Editor +
+
+

All Theme Colors

+
+
+ Tailwind Class +
+
+ CSS Var +
+
+ Fallback +
+ {Object.entries(THEME_COLORS).map(([key, val]) => ( + + ))} +
+
+ ); +} +export default ThemePage; diff --git a/gui/src/styles/theme.ts b/gui/src/styles/theme.ts new file mode 100644 index 000000000..b5f2b3535 --- /dev/null +++ b/gui/src/styles/theme.ts @@ -0,0 +1,225 @@ +// All vscode variables https://gist.github.com/estruyf/ba49203e1a7d6868e9320a4ea480c27a +// Examples for vscode https://github.com/githubocto/tailwind-vscode/blob/main/index.js +export const THEME_COLORS = { + background: { + var: "--vscode-sideBar-background", + default: "#141c2d", + }, + foreground: { + var: "--vscode-sideBar-foreground", // --vscode-editor-foreground + default: "rgba(243, 239, 245, 0.8)", + }, + editor: { + var: "--vscode-editor-background", + default: "#0e131f", + }, + "editor-foreground": { + var: "--vscode-editor-foreground", + default: "#f3eff5", + }, + "primary-background": { + var: "--vscode-button-background", + default: "#1bbe84", + }, + "primary-foreground": { + var: "--vscode-button-foreground", + default: "#ffffff", + }, + "primary-hover": { + var: "--vscode-button-hoverBackground", + default: "#24dfe8", + }, + secondary: { + var: "--vscode-button-secondaryBackground", + default: "rgba(243, 239, 245, 0.2)", + }, + "secondary-foreground": { + var: "--vscode-button-secondaryForeground", + default: "#f3eff5", + }, + "secondary-hover": { + var: "--vscode-button-secondaryHoverBackground", + default: "rgba(243, 239, 245, 0.2)", + }, + border: { + // --vscode-panel-border + var: "--vscode-sideBar-border", + default: "#242d34", + }, + "border-focus": { + var: "--vscode-focusBorder", + default: "#263354", + }, + // Command styles are used for tip-tap editor + command: { + var: "--vscode-commandCenter-background", + default: "#141c2d", + }, + "command-foreground": { + var: "--vscode-commandCenter-foreground", + default: "#f3eff5", + }, + "command-border": { + var: "--vscode-commandCenter-inactiveBorder", + default: "#999998", + }, + "command-border-focus": { + var: "--vscode-commandCenter-activeBorder", + default: "#ed1292", + }, + description: { + var: "--vscode-descriptionForeground", + default: "rgba(243, 239, 245, 0.7)", + }, + "description-muted": { + var: "--vscode-list-deemphasizedForeground", + default: "#8c8c8c", + }, + "input-background": { + var: "--vscode-input-background", + default: "#0d1217", + }, + "input-foreground": { + var: "--vscode-input-foreground", + default: "#f3eff5", + }, + "input-border": { + var: "--vscode-input-border", + default: "#242d34", + }, + "input-placeholder": { + var: "--vscode-input-placeholderForeground", + default: "rgba(243, 239, 245, 0.5)", + }, + "table-oddRow": { + var: "--vscode-tree-tableOddRowsBackground", + default: "rgb(45, 45, 45)", + }, + badge: { + var: "--vscode-badge-background", + default: "rgb(80, 80, 80)", + }, + "badge-foreground": { + var: "--vscode-badge-foreground", + default: "#fff", + }, + success: { + var: "--vscode-notebookStatusSuccessIcon-foreground", // "var(--vscode-testing-iconPassed, #1bbe84)" // --vscode-charts-green + default: "#1bbe84", + }, + warning: { + var: "--vscode-editorWarning-foreground", // --vscode-list-warningForeground + default: "#ffe45e", + }, + error: { + var: "--vscode-editorError-foreground", // --vscode-list-errorForeground + default: "#fe4a49", + }, + link: { + var: "--vscode-textLink-foreground", + default: "#4da6ff", + }, + accent: { + var: "--vscode-tab-activeBorderTop", + default: "#ed1292", + }, + "find-match": { + var: "--vscode-editor-findMatchBackground", // Can't get "var(--vscode-editor-findMatchBackground, rgba(237, 18, 146, 0.5))" to work + default: "rgba(191, 219, 254, 0.3)", + }, + "find-match-selected": { + var: "--vscode-editor-findMatchHighlightBackground", + default: "rgba(255, 223, 0, 0.3)", + }, + "list-hover": { + var: "--vscode-list-hoverBackground", + default: "rgba(243, 239, 245, 0.13)", + }, + "list-active": { + var: "--vscode-list-activeSelectionBackground", + default: "rgba(243, 239, 245, 0.2)", + }, + "list-active-foreground": { + var: "--vscode-list-activeSelectionForeground", + default: "#f3eff5", + }, +}; + +// Consider defaults +// export const vscInputBackground = `var(${VSC_INPUT_BACKGROUND_VAR}, rgb(45 45 45))`; +// export const vscQuickInputBackground = `var(${VSC_QUICK_INPUT_BACKGROUND_VAR}, ${VSC_INPUT_BACKGROUND_VAR}, rgb(45 45 45))`; +// export const vscBackground = `var(${VSC_BACKGROUND_VAR}, rgb(30 30 30))`; +// export const vscForeground = `var(${VSC_FOREGROUND_VAR}, #fff)`; +// export const vscButtonBackground = `var(${VSC_BUTTON_BACKGROUND_VAR}, #1bbe84)`; +// export const vscButtonForeground = `var(${VSC_BUTTON_FOREGROUND_VAR}, #ffffff)`; +// export const vscEditorBackground = `var(${VSC_EDITOR_BACKGROUND_VAR}, ${VSC_BACKGROUND_VAR}, rgb(30 30 30))`; +// export const vscListActiveBackground = `var(${VSC_LIST_SELECTION_BACKGROUND_VAR}, #1bbe84)`; +// export const vscFocusBorder = `var(${VSC_FOCUS_BORDER_VAR}, #1bbe84)`; +// export const vscListActiveForeground = `var(${VSC_LIST_ACTIVE_FOREGROUND_VAR}, ${VSC_FOREGROUND_VAR})`; +// export const vscInputBorder = `var(${VSC_INPUT_BORDER_VAR}, ${lightGray})`; +// export const vscInputBorderFocus = `var(${VSC_FOCUS_BORDER_VAR}, ${lightGray})`; +// export const vscBadgeBackground = `var(${VSC_BADGE_BACKGROUND_VAR}, #1bbe84)`; +// export const vscBadgeForeground = `var(${VSC_BADGE_FOREGROUND_VAR}, #ffffff)`; +// export const vscCommandCenterActiveBorder = `var(${VSC_COMMAND_CENTER_ACTIVE_BORDER_VAR}, #1bbe84)`; +// export const vscCommandCenterInactiveBorder = `var(${VSC_COMMAND_CENTER_INACTIVE_BORDER_VAR}, #1bbe84)`; +// export const vscFindMatchSelected = `var(${VSC_FIND_MATCH_SELECTED_VAR}, rgba(255, 223, 0))`; + +// Fonts: +// --vscode - editor - font - family; +// --vscode - font - family; + +// Current list of CSS variables needed (e.g. for jetbrains to send!) +// --vscode-sideBar-background +// --vscode-sideBar-foreground +// --vscode-editor-background +// --vscode-editor-foreground +// --vscode-button-background +// --vscode-button-foreground +// --vscode-button-secondaryBackground +// --vscode-button-secondaryForeground +// --vscode-sideBar-border +// --vscode-focusBorder +// --vscode-commandCenter-background +// --vscode-commandCenter-foreground +// --vscode-commandCenter-inactiveBorder +// --vscode-commandCenter-activeBorder +// --vscode-descriptionForeground +// --vscode-list-deemphasizedForeground +// --vscode-input-background +// --vscode-input-foreground +// --vscode-input-border +// --vscode-input-placeholderForeground +// --vscode-tree-tableOddRowsBackground +// --vscode-badge-background +// --vscode-badge-foreground +// --vscode-notebookStatusSuccessIcon-foreground +// --vscode-editorWarning-foreground +// --vscode-editorError-foreground +// --vscode-editor-findMatchBackground +// --vscode-editor-findMatchHighlightBackground +// --vscode-list-hoverBackground +// --vscode-list-activeSelectionBackground +// --vscode-list-activeSelectionForeground + +export const THEME_CSS_VARS = Object.values(THEME_COLORS).map( + (value) => value.var, +); + +export const THEME_CSS_VAR_DEFAULTS = Object.entries(THEME_COLORS).reduce( + (acc, [_, value]) => { + acc[value.var] = value.default; + return acc; + }, + {} as Record, +); + +export const THEME_DEFAULTS = Object.entries(THEME_COLORS).reduce( + (acc, [key, value]) => { + acc[key] = value.default; + return acc; + }, + {} as Record, +); + +export const varWithFallback = (className: keyof typeof THEME_COLORS) => + `var(${THEME_COLORS[className].var}, ${THEME_COLORS[className].default})`; diff --git a/gui/src/styles/utils.ts b/gui/src/styles/utils.ts new file mode 100644 index 000000000..a46860ac4 --- /dev/null +++ b/gui/src/styles/utils.ts @@ -0,0 +1,45 @@ +export function parseHexColor(hexColor: string): { + r: number; + g: number; + b: number; +} { + if (hexColor.startsWith("#")) { + hexColor = hexColor.slice(1); + } + + if (hexColor.length > 6) { + hexColor = hexColor.slice(0, 6); + } + + const r = parseInt(hexColor.substring(0, 2), 16); + const g = parseInt(hexColor.substring(2, 4), 16); + const b = parseInt(hexColor.substring(4, 6), 16); + + return { r, g, b }; +} + +export function parseColorForHex(colorVar: string): string { + const value = getComputedStyle(document.documentElement).getPropertyValue( + colorVar, + ); + if (value.startsWith("#")) { + return value.slice(0, 7); + } + + // Parse rgb/rgba + const rgbValues = value + .slice(value.startsWith("rgba") ? 5 : 4, -1) + .split(",") + .map((x) => x.trim()) + .filter((_, i) => i < 3) // Only take the first 3 values (RGB, ignore alpha) + .map((x) => parseInt(x, 10)); + + let hex = + "#" + + rgbValues + .map((x) => x.toString(16)) + .map((x) => (x.length === 1 ? "0" + x : x)) + .join(""); + + return hex; +} diff --git a/gui/src/util/navigation.ts b/gui/src/util/navigation.ts index 0f145b6cd..44ef9a9ee 100644 --- a/gui/src/util/navigation.ts +++ b/gui/src/util/navigation.ts @@ -2,5 +2,6 @@ export const ROUTES = { HOME: "/", CONFIG: "/config", + THEME: "/theme", // EXAMPLE_ROUTE_WITH_PARAMS: (params: ParamsType) => `/route/${params}`, }; diff --git a/gui/tailwind.config.cjs b/gui/tailwind.config.cjs index 941429d2e..a1270a857 100644 --- a/gui/tailwind.config.cjs +++ b/gui/tailwind.config.cjs @@ -1,5 +1,6 @@ /** @type {import('tailwindcss').Config} */ const defaultTheme = require("tailwindcss/defaultTheme"); +const { varWithFallback, THEME_COLORS } = require("./src/styles/theme"); module.exports = { content: [ @@ -29,25 +30,75 @@ module.exports = { default: "5px", }, colors: { - lightgray: "#999998", - "vsc-input-background": "var(--vscode-input-background, rgb(45 45 45))", - "vsc-background": "var(--vscode-sideBar-background, rgb(30 30 30))", - "vsc-foreground": "var(--vscode-editor-foreground, #fff)", - "vsc-editor-background": - "var(--vscode-editor-background, var(--vscode-sideBar-background, rgb(30 30 30)))", - "vsc-input-border": "var(--vscode-input-border, #999998)", - "vsc-commandCenter-inactiveBorder": - "var(--vscode-commandCenter-inactiveBorder, #999998)", + background: varWithFallback("background"), + foreground: varWithFallback("foreground"), + editor: { + DEFAULT: varWithFallback("editor"), + foreground: varWithFallback("editor-foreground"), + }, + primary: { + DEFAULT: varWithFallback("primary-background"), + foreground: varWithFallback("primary-foreground"), + hover: varWithFallback("primary-hover"), + }, + secondary: { + DEFAULT: varWithFallback("secondary"), + foreground: varWithFallback("secondary-foreground"), + hover: varWithFallback("secondary-hover"), + }, + border: { + DEFAULT: varWithFallback("border"), + focus: varWithFallback("border-focus"), + }, + command: { + DEFAULT: varWithFallback("command"), + foreground: varWithFallback("command-foreground"), + border: { + DEFAULT: varWithFallback("command-border"), + focus: varWithFallback("command-border-focus"), + }, + }, + description: { + DEFAULT: varWithFallback("description"), + muted: varWithFallback("description-muted"), + }, + input: { + DEFAULT: varWithFallback("input-background"), + foreground: varWithFallback("input-foreground"), + border: varWithFallback("input-border"), + placeholder: varWithFallback("input-placeholder"), + }, + table: { + oddRow: varWithFallback("table-oddRow"), + }, + badge: { + DEFAULT: varWithFallback("badge"), + foreground: varWithFallback("badge-foreground"), + }, + success: varWithFallback("success"), + warning: varWithFallback("warning"), + error: varWithFallback("error"), + link: varWithFallback("link"), + accent: varWithFallback("accent"), + findMatch: { + DEFAULT: THEME_COLORS["find-match"].default, + selected: varWithFallback("find-match-selected"), + }, + list: { + hover: varWithFallback("list-hover"), + active: { + DEFAULT: varWithFallback("list-active"), + foreground: varWithFallback("list-active-foreground"), + }, + }, - // Starting to make things less vsc-specific - // TODO make it all non-IDE-specific naming - "find-match-selected": - "var(--vscode-editor-findMatchHighlightBackground, rgba(255, 223, 0))", - "table-odd-rows":"var(--vscode-tree-tableOddRowsBackground, #1bbe84)", - "list-active": "var(--vscode-list-activeSelectionBackground, #1bbe84)", - "list-active-foreground": - "var(--vscode-quickInputList-focusForeground, var(--vscode-editor-foreground))", - badge: "var(--vscode-badge-background, #1bbe84)", + // DEPRECATED, slowly remove usages of these ide-named or explicit colors + lightgray: "#999998", // use border, description, or description-muted instead + "vsc-input-background": varWithFallback("input-background"), // use "input-background" instead + "vsc-background": varWithFallback("background"), // use "background" instead + "vsc-foreground": varWithFallback("foreground"), // use "foreground" instead // NOTE - might want to use editor-foreground + "vsc-editor-background": varWithFallback("editor"), // use "editor" instead + "vsc-input-border": varWithFallback("input-border"), // use "input-border" instead }, }, },