jetbrains infrastructure
This commit is contained in:
parent
83e9650946
commit
f4d56e6545
8 changed files with 300 additions and 133 deletions
|
|
@ -2,12 +2,12 @@ import { ToIdeFromWebviewOrCoreProtocol } from "./ide";
|
|||
import { ToWebviewFromIdeOrCoreProtocol } from "./webview";
|
||||
|
||||
import {
|
||||
AcceptOrRejectDiffPayload,
|
||||
ApplyState,
|
||||
SetCodeToEditPayload,
|
||||
HighlightedCodePayload,
|
||||
MessageContent,
|
||||
RangeInFileWithContents,
|
||||
AcceptOrRejectDiffPayload,
|
||||
SetCodeToEditPayload,
|
||||
} from "../";
|
||||
|
||||
export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
||||
|
|
@ -41,7 +41,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
|||
vscMediaUrl: string;
|
||||
},
|
||||
];
|
||||
"jetbrains/getColors": [undefined, Record<string, string>];
|
||||
"jetbrains/getColors": [undefined, Record<string, string | null | undefined>];
|
||||
"vscode/openMoveRightMarkdown": [undefined, void];
|
||||
setGitHubAuthToken: [{ token: string }, void];
|
||||
acceptDiff: [AcceptOrRejectDiffPayload, void];
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ export type ToWebviewFromIdeOrCoreProtocol = {
|
|||
setTTSActive: [boolean, void];
|
||||
getWebviewHistoryLength: [undefined, number];
|
||||
getCurrentSessionId: [undefined, string];
|
||||
"jetbrains/setColors": [Record<string, string>, void];
|
||||
"jetbrains/setColors": [Record<string, string | null | undefined>, void];
|
||||
sessionUpdate: [{ sessionInfo: ControlPlaneSessionInfo | undefined }, void];
|
||||
toolCallPartialOutput: [{ toolCallId: string; contextItems: any[] }, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -38,64 +38,117 @@ class GetTheme {
|
|||
return globalScheme.getColor(EditorColors.MODIFIED_TAB_ICON_COLOR) ?: globalScheme.defaultForeground
|
||||
}
|
||||
|
||||
fun getTheme(): Map<String, String> {
|
||||
fun toHex(color: Color): String {
|
||||
return String.format("#%02x%02x%02x", color.red, color.green, color.blue)
|
||||
fun toHex(color: Color?): String? {
|
||||
if(color == null) {
|
||||
return null
|
||||
}
|
||||
return String.format("#%02x%02x%02x", color.red, color.green, color.blue)
|
||||
}
|
||||
|
||||
fun namedColor(name: String): Color? {
|
||||
// JB Color named color will fall back to a default unless we give it a fallback
|
||||
// We want defaults to be handled on the GUI side, so we give it this filler color
|
||||
// Which has a very low chance of conflicting with a real one
|
||||
// And return undefined if it gets the skip color
|
||||
val SKIP_COLOR = Color (18, 52, 86) // Hex #123456
|
||||
val color = JBColor.namedColor(name, SKIP_COLOR)
|
||||
if(toHex(color) == "#123456") {
|
||||
return null
|
||||
}
|
||||
return color
|
||||
}
|
||||
|
||||
fun getTheme(): Map<String, String?> {
|
||||
try {
|
||||
// IDE colors
|
||||
val background = JBColor.background()
|
||||
val foreground = JBColor.foreground()
|
||||
|
||||
val buttonBackground = JBColor.namedColor("Button.background", Color(230, 230, 230))
|
||||
val buttonForeground = JBColor.namedColor("Button.foreground", Color(0, 0, 0))
|
||||
|
||||
val badgeBackground = JBColor.namedColor("Badge.background", Color(150, 150, 150))
|
||||
val badgeForeground = JBColor.namedColor("Badge.foreground", Color(0, 0, 0))
|
||||
|
||||
val inputBackground = JBColor.namedColor("TextField.background", Color(255, 255, 255))
|
||||
|
||||
val border = JBColor.border()
|
||||
val focusBorder = JBColor.namedColor("Focus.borderColor", Color(100, 100, 255))
|
||||
val focusBorder = namedColor("Focus.borderColor") ?: namedColor("Component.focusedBorderColor")
|
||||
|
||||
val buttonBackground = namedColor("Button.background")
|
||||
val buttonForeground = namedColor("Button.foreground")
|
||||
val buttonHoverBackground = namedColor("Button.hoverBackground") ?: namedColor("Button.darcula.hoverBackground")
|
||||
|
||||
val badgeBackground = namedColor("Badge.background")
|
||||
val badgeForeground = namedColor("Badge.foreground")
|
||||
|
||||
val commandBackground = namedColor("CommandButton.background") ?: namedColor("ToolWindow.background")
|
||||
val commandForeground = namedColor("CommandButton.foreground") ?: namedColor("ToolWindow.foreground")
|
||||
|
||||
val inputBackground = namedColor("TextField.background")
|
||||
val inputForeground = namedColor("TextField.foreground")
|
||||
val inputPlaceholder = namedColor("TextField.inactiveForeground")
|
||||
|
||||
val listHoverBackground = namedColor("List.hoverBackground") ?: namedColor("List.dropLineColor")
|
||||
val actionHoverBackground = namedColor("ActionButton.hoverBackground") ?: namedColor("Button.darcula.hoverBackground")
|
||||
val hoverBackground = namedColor("Table.hoverBackground") ?: namedColor("Table.stripeColor") ?: namedColor("List.dropLineColor")
|
||||
val listSelectionForeground = namedColor("List.selectionForeground")
|
||||
|
||||
|
||||
val description = namedColor("Label.infoForeground") ?: namedColor("ToolTip.foreground")
|
||||
val mutedDescription = namedColor("Label.disabledForeground")
|
||||
|
||||
val link = namedColor("Link.activeForeground")
|
||||
|
||||
val successColor = namedColor("Notification.Success.background") ?: namedColor("ProgressBar.progressColor")
|
||||
val warningColor = namedColor("Notification.Warning.background") ?: namedColor("ProgressBar.warningColor")
|
||||
val errorColor = namedColor("ErrorBackground") ?: namedColor("Notification.Error.background") ?: namedColor("ProgressBar.errorColor")
|
||||
val accentColor = namedColor("Focus.defaultButtonBorderColor") ?: namedColor("Button.default.focusedBorderColor") ?: namedColor("Button.focusedBorderColor")
|
||||
|
||||
// Editor colors
|
||||
val editorScheme = EditorColorsManager.getInstance().globalScheme
|
||||
|
||||
val editorBackground = editorScheme.defaultBackground
|
||||
val editorForeground = editorScheme.defaultForeground
|
||||
|
||||
val actionHoverBackground = JBColor.namedColor("ActionButton.hoverBackground", Color(220, 220, 220))
|
||||
|
||||
val findMatchBackground = editorScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES)?.backgroundColor ?: Color(255, 221, 0)
|
||||
val findMatchBackground = editorScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES)?.backgroundColor
|
||||
|
||||
val findMatchSelectedBackground = namedColor("SearchMatch.selectedBackground") ?:
|
||||
editorScheme.getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES)?.backgroundColor
|
||||
|
||||
// These should match the keys in GUI's theme.ts
|
||||
val theme = mapOf(
|
||||
"--vscode-editor-foreground" to toHex(editorForeground),
|
||||
"--vscode-editor-background" to toHex(editorBackground),
|
||||
|
||||
"--vscode-button-background" to toHex(buttonBackground),
|
||||
"--vscode-button-foreground" to toHex(buttonForeground),
|
||||
|
||||
"--vscode-list-activeSelectionBackground" to toHex(actionHoverBackground) + "50",
|
||||
|
||||
"--vscode-quickInputList-focusForeground" to toHex(foreground),
|
||||
"--vscode-quickInput-background" to toHex(inputBackground),
|
||||
|
||||
"--vscode-badge-background" to toHex(badgeBackground),
|
||||
"--vscode-badge-foreground" to toHex(badgeForeground),
|
||||
|
||||
"--vscode-input-background" to toHex(inputBackground),
|
||||
"--vscode-input-border" to toHex(border),
|
||||
"--vscode-sideBar-background" to toHex(background),
|
||||
"--vscode-sideBar-border" to toHex(border),
|
||||
"--vscode-focusBorder" to toHex(focusBorder),
|
||||
|
||||
"--vscode-commandCenter-activeBorder" to toHex(focusBorder),
|
||||
"--vscode-commandCenter-inactiveBorder" to toHex(border),
|
||||
|
||||
"--vscode-editor-findMatchHighlightBackground" to toHex(findMatchBackground) + "40"
|
||||
"background" to toHex(background),
|
||||
"foreground" to toHex(foreground),
|
||||
"editor-background" to toHex(editorBackground),
|
||||
"editor-foreground" to toHex(editorForeground),
|
||||
"primary-background" to toHex(buttonBackground),
|
||||
"primary-foreground" to toHex(buttonForeground),
|
||||
"primary-hover" to toHex(buttonHoverBackground),
|
||||
"secondary-background" to toHex(getSecondaryDark()),
|
||||
"secondary-foreground" to toHex(foreground),
|
||||
"secondary-hover" to toHex(hoverBackground),
|
||||
"border" to toHex(border),
|
||||
"border-focus" to toHex(focusBorder),
|
||||
"command-background" to toHex(commandBackground),
|
||||
"command-foreground" to toHex(commandForeground),
|
||||
"command-border" to toHex(border), // make command specific
|
||||
"command-border-focus" to toHex(focusBorder), // make command specific
|
||||
"description" to toHex(description),
|
||||
"description-muted" to toHex(mutedDescription),
|
||||
"input-background" to toHex(inputBackground),
|
||||
"input-foreground" to toHex(inputForeground),
|
||||
"input-border" to toHex(border),
|
||||
"input-placeholder" to toHex(inputPlaceholder),
|
||||
"table-oddRow" to toHex(hoverBackground),
|
||||
"badge-background" to toHex(badgeBackground),
|
||||
"badge-foreground" to toHex(badgeForeground),
|
||||
"success" to toHex(successColor),
|
||||
"warning" to toHex(warningColor),
|
||||
"error" to toHex(errorColor),
|
||||
"link" to toHex(link),
|
||||
"accent" to toHex(accentColor),
|
||||
"find-match" to toHex(findMatchBackground) + "40",
|
||||
"find-match-selected" to toHex(findMatchSelectedBackground),
|
||||
"list-hover" to toHex(listHoverBackground),
|
||||
"list-active" to toHex(actionHoverBackground) + "50",
|
||||
"list-active-foreground" to toHex(listSelectionForeground)
|
||||
)
|
||||
|
||||
return theme
|
||||
} catch (error: Error) {
|
||||
return mapOf()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ 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 vscEditorBackground = varWithFallback("editor-background");
|
||||
export const vscListActiveBackground = varWithFallback("list-active");
|
||||
export const vscFocusBorder = varWithFallback("border-focus");
|
||||
export const vscListActiveForeground = varWithFallback(
|
||||
|
|
@ -20,7 +20,7 @@ export const vscListActiveForeground = varWithFallback(
|
|||
);
|
||||
export const vscInputBorder = varWithFallback("input-border");
|
||||
export const vscInputBorderFocus = varWithFallback("border-focus");
|
||||
export const vscBadgeBackground = varWithFallback("badge");
|
||||
export const vscBadgeBackground = varWithFallback("badge-background");
|
||||
export const vscBadgeForeground = varWithFallback("badge-foreground");
|
||||
export const vscCommandCenterActiveBorder = varWithFallback(
|
||||
"command-border-focus",
|
||||
|
|
|
|||
|
|
@ -28,7 +28,10 @@ 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 {
|
||||
setDocumentStylesFromLocalStorage,
|
||||
setDocumentStylesFromTheme,
|
||||
} from "../styles/theme";
|
||||
import { isJetBrains } from "../util";
|
||||
import { setLocalStorage } from "../util/localStorage";
|
||||
import { useWebviewListener } from "./useWebviewListener";
|
||||
|
|
@ -139,34 +142,13 @@ function ParallelListeners() {
|
|||
dispatch(cancelStream());
|
||||
|
||||
const jetbrains = isJetBrains();
|
||||
for (const [colorName, themeVals] of Object.entries(THEME_COLORS)) {
|
||||
const cssVarName = themeVals.var;
|
||||
if (jetbrains) {
|
||||
const cached = localStorage.getItem(colorName);
|
||||
if (cached) {
|
||||
document.body.style.setProperty(cssVarName, cached);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove alpha channel from colors
|
||||
const value = getComputedStyle(document.documentElement).getPropertyValue(
|
||||
cssVarName,
|
||||
);
|
||||
if (value.startsWith("#") && value.length > 7) {
|
||||
document.body.style.setProperty(cssVarName, value.slice(0, 7));
|
||||
}
|
||||
}
|
||||
setDocumentStylesFromLocalStorage(jetbrains);
|
||||
|
||||
if (jetbrains) {
|
||||
// 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(([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);
|
||||
});
|
||||
setDocumentStylesFromTheme(result.content);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -183,24 +165,13 @@ function ParallelListeners() {
|
|||
(window as any).vscMachineId = msg.vscMachineId;
|
||||
(window as any).vscMediaUrl = msg.vscMediaUrl;
|
||||
});
|
||||
|
||||
for (const [colorName, themeVals] of Object.entries(THEME_COLORS)) {
|
||||
const currentVal = document.body.style.getPropertyValue(themeVals.var);
|
||||
if (currentVal) {
|
||||
localStorage.setItem(colorName, currentVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
useWebviewListener(
|
||||
"jetbrains/setColors",
|
||||
async (data) => {
|
||||
Object.entries(data).forEach(([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);
|
||||
});
|
||||
setDocumentStylesFromTheme(data);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,18 +3,27 @@ import {
|
|||
ExclamationCircleIcon,
|
||||
ExclamationTriangleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useState } from "react";
|
||||
import { useContext, useEffect, useMemo, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { THEME_COLORS } from "./theme";
|
||||
import { Button } from "../components";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { isJetBrains } from "../util";
|
||||
import {
|
||||
clearThemeLocalCache,
|
||||
setDocumentStylesFromTheme,
|
||||
THEME_COLORS,
|
||||
} from "./theme";
|
||||
|
||||
const ThemeTailwindClassExample = ({
|
||||
className,
|
||||
varName,
|
||||
defaultColor,
|
||||
isMissing,
|
||||
}: {
|
||||
className: string;
|
||||
varName: string;
|
||||
defaultColor: string;
|
||||
isMissing?: boolean;
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
|
|
@ -22,7 +31,7 @@ const ThemeTailwindClassExample = ({
|
|||
{className}
|
||||
</div>
|
||||
<div
|
||||
className={`line-clamp-1 break-all p-1 text-[9px]`}
|
||||
className={`line-clamp-1 break-all p-1 text-[9px] ${isMissing ? "text-error" : ""}`}
|
||||
style={{
|
||||
backgroundColor: `var(${varName})`,
|
||||
}}
|
||||
|
|
@ -44,6 +53,37 @@ const ThemeTailwindClassExample = ({
|
|||
function ThemePage() {
|
||||
const navigate = useNavigate();
|
||||
const [listToggled, setListToggled] = useState(false);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const jetbrains = useMemo(() => {
|
||||
return isJetBrains();
|
||||
}, []);
|
||||
|
||||
const refreshJetbrainsColors = () => {
|
||||
ideMessenger.request("jetbrains/getColors", undefined).then((result) => {
|
||||
console.log(result);
|
||||
if (result.status === "success") {
|
||||
setDocumentStylesFromTheme(result.content);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const [missingVars, setMissingVars] = useState<string[]>([]);
|
||||
const checkMissingClasses = () => {
|
||||
const missingVars: string[] = [];
|
||||
Object.entries(THEME_COLORS).forEach(([colorName, themeVals]) => {
|
||||
const value = getComputedStyle(document.documentElement).getPropertyValue(
|
||||
themeVals.var,
|
||||
);
|
||||
if (!value) {
|
||||
missingVars.push(`${colorName}`); //: ${themeVals.var}`);
|
||||
}
|
||||
});
|
||||
setMissingVars(missingVars);
|
||||
};
|
||||
useEffect(() => {
|
||||
checkMissingClasses();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex flex-1 flex-col gap-3 px-2 py-2">
|
||||
<span
|
||||
|
|
@ -110,6 +150,38 @@ function ThemePage() {
|
|||
<span>Editor</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-2">
|
||||
<h2 className="mb-2 mt-6 text-xl font-semibold">
|
||||
Missing Theme Variables
|
||||
</h2>
|
||||
{missingVars.length > 0 ? (
|
||||
<div className="flex flex-col gap-1">
|
||||
{missingVars.map((varName) => (
|
||||
<div key={varName} className="text-error">
|
||||
{varName}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-success">No missing variables</div>
|
||||
)}
|
||||
<Button onClick={checkMissingClasses}>
|
||||
Re-check Missing Theme Vars
|
||||
</Button>
|
||||
</div>
|
||||
{jetbrains ? (
|
||||
<>
|
||||
<h2 className="mb-2 mt-6 text-xl font-semibold">
|
||||
Manage Jetbrains Theme
|
||||
</h2>
|
||||
<div className="flex flex-col flex-wrap gap-2">
|
||||
<Button onClick={refreshJetbrainsColors}>
|
||||
Refresh Jetbrains Theme
|
||||
</Button>
|
||||
<Button onClick={clearThemeLocalCache}>Clear Theme Cache</Button>
|
||||
</div>
|
||||
</>
|
||||
) : null}
|
||||
<h2 className="mb-2 mt-6 text-xl font-semibold">All Theme Colors</h2>
|
||||
<div className="grid grid-cols-3">
|
||||
<div className="p-1">
|
||||
|
|
@ -121,10 +193,11 @@ function ThemePage() {
|
|||
<div className="p-1">
|
||||
<span className="font-bold">Fallback</span>
|
||||
</div>
|
||||
{Object.entries(THEME_COLORS).map(([key, val]) => (
|
||||
{Object.entries(THEME_COLORS).map(([colorName, val]) => (
|
||||
<ThemeTailwindClassExample
|
||||
key={key}
|
||||
className={key}
|
||||
isMissing={missingVars.includes(colorName)}
|
||||
key={colorName}
|
||||
className={colorName}
|
||||
defaultColor={val.default}
|
||||
varName={val.var}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -1,148 +1,150 @@
|
|||
// All vscode variables https://gist.github.com/estruyf/ba49203e1a7d6868e9320a4ea480c27a
|
||||
// Examples for vscode https://github.com/githubocto/tailwind-vscode/blob/main/index.js
|
||||
|
||||
// The current default theme is dark with blue accents
|
||||
export const THEME_COLORS = {
|
||||
background: {
|
||||
var: "--vscode-sideBar-background",
|
||||
default: "#1e1e1e",
|
||||
default: "#1e1e1e", // dark gray
|
||||
},
|
||||
foreground: {
|
||||
var: "--vscode-sideBar-foreground", // --vscode-editor-foreground
|
||||
default: "rgba(243, 239, 245)",
|
||||
default: "#e6e6e6", // light gray
|
||||
},
|
||||
editor: {
|
||||
"editor-background": {
|
||||
var: "--vscode-editor-background",
|
||||
default: "#1e1e1e",
|
||||
default: "#1e1e1e", // dark gray
|
||||
},
|
||||
"editor-foreground": {
|
||||
var: "--vscode-editor-foreground",
|
||||
default: "#f3eff5",
|
||||
default: "#e6e6e6", // light gray
|
||||
},
|
||||
"primary-background": {
|
||||
var: "--vscode-button-background",
|
||||
default: "#1b3ebe",
|
||||
default: "#2c5aa0", // medium blue
|
||||
},
|
||||
"primary-foreground": {
|
||||
var: "--vscode-button-foreground",
|
||||
default: "#ffffff",
|
||||
default: "#ffffff", // white
|
||||
},
|
||||
"primary-hover": {
|
||||
var: "--vscode-button-hoverBackground",
|
||||
default: "#2847ad",
|
||||
default: "#3a6db3", // lighter blue
|
||||
},
|
||||
secondary: {
|
||||
"secondary-background": {
|
||||
var: "--vscode-button-secondaryBackground",
|
||||
default: "rgba(243, 239, 245, 0.2)",
|
||||
default: "#303030", // medium dark gray
|
||||
},
|
||||
"secondary-foreground": {
|
||||
var: "--vscode-button-secondaryForeground",
|
||||
default: "#f3eff5",
|
||||
default: "#e6e6e6", // light gray
|
||||
},
|
||||
"secondary-hover": {
|
||||
var: "--vscode-button-secondaryHoverBackground",
|
||||
default: "rgba(243, 239, 245, 0.2)",
|
||||
default: "#3a3a3a", // medium gray
|
||||
},
|
||||
border: {
|
||||
// --vscode-panel-border
|
||||
var: "--vscode-sideBar-border",
|
||||
default: "#242d34",
|
||||
default: "#2a2a2a", // dark gray border
|
||||
},
|
||||
"border-focus": {
|
||||
var: "--vscode-focusBorder",
|
||||
default: "#263354",
|
||||
default: "#3a6db3", // lighter blue
|
||||
},
|
||||
// Command styles are used for tip-tap editor
|
||||
command: {
|
||||
"command-background": {
|
||||
var: "--vscode-commandCenter-background",
|
||||
default: "#141c2d",
|
||||
default: "#252525", // dark gray
|
||||
},
|
||||
"command-foreground": {
|
||||
var: "--vscode-commandCenter-foreground",
|
||||
default: "#f3eff5",
|
||||
default: "#e6e6e6", // light gray
|
||||
},
|
||||
"command-border": {
|
||||
var: "--vscode-commandCenter-inactiveBorder",
|
||||
default: "#999998",
|
||||
default: "#555555", // medium gray
|
||||
},
|
||||
"command-border-focus": {
|
||||
var: "--vscode-commandCenter-activeBorder",
|
||||
default: "#ed1292",
|
||||
default: "#4d8bf0", // bright blue
|
||||
},
|
||||
description: {
|
||||
var: "--vscode-descriptionForeground",
|
||||
default: "rgba(243, 239, 245, 0.7)",
|
||||
default: "#b3b3b3", // medium light gray
|
||||
},
|
||||
"description-muted": {
|
||||
var: "--vscode-list-deemphasizedForeground",
|
||||
default: "#8c8c8c",
|
||||
default: "#8c8c8c", // medium gray
|
||||
},
|
||||
"input-background": {
|
||||
var: "--vscode-input-background",
|
||||
default: "#2d2d2d",
|
||||
default: "#2d2d2d", // dark gray
|
||||
},
|
||||
"input-foreground": {
|
||||
var: "--vscode-input-foreground",
|
||||
default: "#f3eff5",
|
||||
default: "#e6e6e6", // light gray
|
||||
},
|
||||
"input-border": {
|
||||
var: "--vscode-input-border",
|
||||
default: "#999998",
|
||||
default: "#555555", // medium gray
|
||||
},
|
||||
"input-placeholder": {
|
||||
var: "--vscode-input-placeholderForeground",
|
||||
default: "rgba(243, 239, 245, 0.5)",
|
||||
default: "#9e9e9e", // medium light gray
|
||||
},
|
||||
"table-oddRow": {
|
||||
var: "--vscode-tree-tableOddRowsBackground",
|
||||
default: "rgb(45, 45, 45)",
|
||||
default: "#2d2d2d", // dark gray
|
||||
},
|
||||
badge: {
|
||||
"badge-background": {
|
||||
var: "--vscode-badge-background",
|
||||
default: "rgb(80, 80, 80)",
|
||||
default: "#4d4d4d", // medium dark gray
|
||||
},
|
||||
"badge-foreground": {
|
||||
var: "--vscode-badge-foreground",
|
||||
default: "#ffffff",
|
||||
default: "#ffffff", // white
|
||||
},
|
||||
success: {
|
||||
var: "--vscode-notebookStatusSuccessIcon-foreground", // "var(--vscode-testing-iconPassed, #1bbe84)" // --vscode-charts-green
|
||||
default: "#1bbe84",
|
||||
default: "#4caf50", // green
|
||||
},
|
||||
warning: {
|
||||
var: "--vscode-editorWarning-foreground", // --vscode-list-warningForeground
|
||||
default: "#ffe45e",
|
||||
default: "#ffb74d", // amber/yellow
|
||||
},
|
||||
error: {
|
||||
var: "--vscode-editorError-foreground", // --vscode-list-errorForeground
|
||||
default: "#fe4a49",
|
||||
default: "#f44336", // red
|
||||
},
|
||||
link: {
|
||||
var: "--vscode-textLink-foreground",
|
||||
default: "#4da6ff",
|
||||
default: "#5c9ce6", // medium blue
|
||||
},
|
||||
accent: {
|
||||
var: "--vscode-tab-activeBorderTop",
|
||||
default: "#ed1292",
|
||||
default: "#4d8bf0", // bright blue
|
||||
},
|
||||
"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)",
|
||||
default: "#264f7840", // translucent blue
|
||||
},
|
||||
"find-match-selected": {
|
||||
var: "--vscode-editor-findMatchHighlightBackground",
|
||||
default: "rgba(255, 223, 0, 0.3)",
|
||||
default: "#ffb74d40", // translucent amber
|
||||
},
|
||||
"list-hover": {
|
||||
// --vscode-tab-hoverBackground
|
||||
var: "--vscode-list-hoverBackground",
|
||||
default: "rgba(243, 239, 245, 0.13)",
|
||||
default: "#383838", // medium dark gray
|
||||
},
|
||||
"list-active": {
|
||||
var: "--vscode-list-activeSelectionBackground",
|
||||
default: "rgba(243, 239, 245, 0.2)",
|
||||
default: "#2c5aa050", // translucent medium blue
|
||||
},
|
||||
"list-active-foreground": {
|
||||
var: "--vscode-list-activeSelectionForeground",
|
||||
default: "#f3eff5",
|
||||
default: "#ffffff", // white
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -172,3 +174,71 @@ export const THEME_DEFAULTS = Object.entries(THEME_COLORS).reduce(
|
|||
|
||||
export const varWithFallback = (className: keyof typeof THEME_COLORS) =>
|
||||
`var(${THEME_COLORS[className].var}, ${THEME_COLORS[className].default})`;
|
||||
|
||||
export const setDocumentStylesFromTheme = (
|
||||
theme: Record<string, string | undefined | null>,
|
||||
) => {
|
||||
// Check for missing theme items
|
||||
const themeKeys = Object.keys(THEME_COLORS);
|
||||
const missingKeys = themeKeys.filter(
|
||||
(key) => !Object.keys(theme).includes(key),
|
||||
);
|
||||
if (missingKeys.length > 0) {
|
||||
console.warn(
|
||||
`Missing theme keys: ${missingKeys.join(", ")}. Please check theme`,
|
||||
);
|
||||
}
|
||||
// Write each theme color to the document
|
||||
Object.entries(theme).forEach(([colorName, value]) => {
|
||||
if (value) {
|
||||
const cssVarName =
|
||||
THEME_COLORS[colorName as keyof typeof THEME_COLORS]?.var;
|
||||
// TODO VALUE WITHOUT ALPHA CHANNEL
|
||||
document.body.style.setProperty(cssVarName, value);
|
||||
document.documentElement.style.setProperty(cssVarName, value);
|
||||
localStorage.setItem(colorName, value);
|
||||
} else {
|
||||
console.warn(
|
||||
`Theme color ${colorName} is undefined or null. Please check theme. Falling back to defaults.`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Cache values in local storage
|
||||
for (const [colorName, themeVals] of Object.entries(THEME_COLORS)) {
|
||||
const currentVal = document.body.style.getPropertyValue(themeVals.var);
|
||||
if (currentVal) {
|
||||
localStorage.setItem(colorName, currentVal);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const setDocumentStylesFromLocalStorage = (checkCache: boolean) => {
|
||||
for (const [colorName, themeVals] of Object.entries(THEME_COLORS)) {
|
||||
const cssVarName = themeVals.var;
|
||||
|
||||
// Get cached values (for non-vscode IDEs)
|
||||
if (checkCache) {
|
||||
const cached = localStorage.getItem(colorName);
|
||||
if (cached) {
|
||||
document.body.style.setProperty(cssVarName, cached);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove alpha channel from all hex colors besides ones that are expected to have it
|
||||
if (!colorName.includes("find-match")) {
|
||||
const value = getComputedStyle(document.documentElement).getPropertyValue(
|
||||
cssVarName,
|
||||
);
|
||||
if (value.startsWith("#") && value.length > 7) {
|
||||
document.body.style.setProperty(cssVarName, value.slice(0, 7));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const clearThemeLocalCache = () => {
|
||||
for (const colorName of Object.keys(THEME_COLORS)) {
|
||||
localStorage.removeItem(colorName);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ module.exports = {
|
|||
background: varWithFallback("background"),
|
||||
foreground: varWithFallback("foreground"),
|
||||
editor: {
|
||||
DEFAULT: varWithFallback("editor"),
|
||||
DEFAULT: varWithFallback("editor-background"),
|
||||
foreground: varWithFallback("editor-foreground"),
|
||||
},
|
||||
primary: {
|
||||
|
|
@ -42,7 +42,7 @@ module.exports = {
|
|||
hover: varWithFallback("primary-hover"),
|
||||
},
|
||||
secondary: {
|
||||
DEFAULT: varWithFallback("secondary"),
|
||||
DEFAULT: varWithFallback("secondary-background"),
|
||||
foreground: varWithFallback("secondary-foreground"),
|
||||
hover: varWithFallback("secondary-hover"),
|
||||
},
|
||||
|
|
@ -51,7 +51,7 @@ module.exports = {
|
|||
focus: varWithFallback("border-focus"),
|
||||
},
|
||||
command: {
|
||||
DEFAULT: varWithFallback("command"),
|
||||
DEFAULT: varWithFallback("command-background"),
|
||||
foreground: varWithFallback("command-foreground"),
|
||||
border: {
|
||||
DEFAULT: varWithFallback("command-border"),
|
||||
|
|
@ -72,7 +72,7 @@ module.exports = {
|
|||
oddRow: varWithFallback("table-oddRow"),
|
||||
},
|
||||
badge: {
|
||||
DEFAULT: varWithFallback("badge"),
|
||||
DEFAULT: varWithFallback("badge-background"),
|
||||
foreground: varWithFallback("badge-foreground"),
|
||||
},
|
||||
success: varWithFallback("success"),
|
||||
|
|
@ -97,7 +97,7 @@ module.exports = {
|
|||
"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-editor-background": varWithFallback("editor-background"), // use "editor" instead
|
||||
"vsc-input-border": varWithFallback("input-border"), // use "input-border" instead
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue