UNPKG

@sussudio/platform

Version:

Internal APIs for VS Code's service injection the base services.

174 lines (173 loc) 6.02 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { Color } from '@sussudio/base/common/color.mjs'; import { activeContrastBorder, editorWidgetBorder, focusBorder, inputActiveOptionBackground, inputActiveOptionBorder, inputActiveOptionForeground, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationInfoForeground, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationWarningForeground, listActiveSelectionBackground, listActiveSelectionForeground, listActiveSelectionIconForeground, listDropBackground, listFocusBackground, listFocusForeground, listFocusOutline, listHoverBackground, listHoverForeground, listInactiveFocusBackground, listInactiveFocusOutline, listInactiveSelectionBackground, listInactiveSelectionForeground, listInactiveSelectionIconForeground, menuBackground, menuBorder, menuForeground, menuSelectionBackground, menuSelectionBorder, menuSelectionForeground, menuSeparatorBackground, pickerGroupForeground, quickInputListFocusBackground, quickInputListFocusForeground, quickInputListFocusIconForeground, resolveColorValue, scrollbarShadow, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, selectBackground, selectBorder, selectForeground, selectListBackground, tableColumnsBorder, tableOddRowsBackgroundColor, treeIndentGuidesStroke, widgetShadow, listFocusAndSelectionOutline, } from './colorRegistry.mjs'; import { isHighContrast } from './theme.mjs'; export function computeStyles(theme, styleMap) { const styles = Object.create(null); for (const key in styleMap) { const value = styleMap[key]; if (value) { styles[key] = resolveColorValue(value, theme); } } return styles; } export function attachStyler(themeService, styleMap, widgetOrCallback) { function applyStyles() { const styles = computeStyles(themeService.getColorTheme(), styleMap); if (typeof widgetOrCallback === 'function') { widgetOrCallback(styles); } else { widgetOrCallback.style(styles); } } applyStyles(); return themeService.onDidColorThemeChange(applyStyles); } export function attachSelectBoxStyler(widget, themeService, style) { return attachStyler( themeService, { selectBackground: style?.selectBackground || selectBackground, selectListBackground: style?.selectListBackground || selectListBackground, selectForeground: style?.selectForeground || selectForeground, decoratorRightForeground: style?.pickerGroupForeground || pickerGroupForeground, selectBorder: style?.selectBorder || selectBorder, focusBorder: style?.focusBorder || focusBorder, listFocusBackground: style?.listFocusBackground || quickInputListFocusBackground, listInactiveSelectionIconForeground: style?.listInactiveSelectionIconForeground || quickInputListFocusIconForeground, listFocusForeground: style?.listFocusForeground || quickInputListFocusForeground, listFocusOutline: style?.listFocusOutline || ((theme) => (isHighContrast(theme.type) ? activeContrastBorder : Color.transparent)), listHoverBackground: style?.listHoverBackground || listHoverBackground, listHoverForeground: style?.listHoverForeground || listHoverForeground, listHoverOutline: style?.listFocusOutline || activeContrastBorder, selectListBorder: style?.selectListBorder || editorWidgetBorder, }, widget, ); } export function attachListStyler(widget, themeService, overrides) { return attachStyler(themeService, { ...defaultListStyles, ...(overrides || {}) }, widget); } export const defaultListStyles = { listFocusBackground, listFocusForeground, listFocusOutline, listActiveSelectionBackground, listActiveSelectionForeground, listActiveSelectionIconForeground, listFocusAndSelectionOutline, listFocusAndSelectionBackground: listActiveSelectionBackground, listFocusAndSelectionForeground: listActiveSelectionForeground, listInactiveSelectionBackground, listInactiveSelectionIconForeground, listInactiveSelectionForeground, listInactiveFocusBackground, listInactiveFocusOutline, listHoverBackground, listHoverForeground, listDropBackground, listSelectionOutline: activeContrastBorder, listHoverOutline: activeContrastBorder, treeIndentGuidesStroke, tableColumnsBorder, tableOddRowsBackgroundColor, inputActiveOptionBorder, inputActiveOptionForeground, inputActiveOptionBackground, inputBackground, inputForeground, inputBorder, inputValidationInfoBackground, inputValidationInfoForeground, inputValidationInfoBorder, inputValidationWarningBackground, inputValidationWarningForeground, inputValidationWarningBorder, inputValidationErrorBackground, inputValidationErrorForeground, inputValidationErrorBorder, }; export function attachStylerCallback(themeService, colors, callback) { return attachStyler(themeService, colors, callback); } export const defaultMenuStyles = { shadowColor: widgetShadow, borderColor: menuBorder, foregroundColor: menuForeground, backgroundColor: menuBackground, selectionForegroundColor: menuSelectionForeground, selectionBackgroundColor: menuSelectionBackground, selectionBorderColor: menuSelectionBorder, separatorColor: menuSeparatorBackground, scrollbarShadow: scrollbarShadow, scrollbarSliderBackground: scrollbarSliderBackground, scrollbarSliderHoverBackground: scrollbarSliderHoverBackground, scrollbarSliderActiveBackground: scrollbarSliderActiveBackground, }; export function attachMenuStyler(widget, themeService, style) { return attachStyler(themeService, { ...defaultMenuStyles, ...style }, widget); }