styler.js 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import { activeContrastBorder, badgeBackground, badgeForeground, contrastBorder, listActiveSelectionBackground, listActiveSelectionForeground, listActiveSelectionIconForeground, listDropBackground, listFilterWidgetBackground, listFilterWidgetNoMatchesOutline, listFilterWidgetOutline, listFocusBackground, listFocusForeground, listFocusOutline, listHoverBackground, listHoverForeground, listInactiveFocusBackground, listInactiveFocusOutline, listInactiveSelectionBackground, listInactiveSelectionForeground, listInactiveSelectionIconForeground, menuBackground, menuBorder, menuForeground, menuSelectionBackground, menuSelectionBorder, menuSelectionForeground, menuSeparatorBackground, resolveColorValue, scrollbarShadow, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, tableColumnsBorder, tableOddRowsBackgroundColor, treeIndentGuidesStroke, widgetShadow } from './colorRegistry.js';
  6. export function computeStyles(theme, styleMap) {
  7. const styles = Object.create(null);
  8. for (let key in styleMap) {
  9. const value = styleMap[key];
  10. if (value) {
  11. styles[key] = resolveColorValue(value, theme);
  12. }
  13. }
  14. return styles;
  15. }
  16. export function attachStyler(themeService, styleMap, widgetOrCallback) {
  17. function applyStyles() {
  18. const styles = computeStyles(themeService.getColorTheme(), styleMap);
  19. if (typeof widgetOrCallback === 'function') {
  20. widgetOrCallback(styles);
  21. }
  22. else {
  23. widgetOrCallback.style(styles);
  24. }
  25. }
  26. applyStyles();
  27. return themeService.onDidColorThemeChange(applyStyles);
  28. }
  29. export function attachBadgeStyler(widget, themeService, style) {
  30. return attachStyler(themeService, {
  31. badgeBackground: (style === null || style === void 0 ? void 0 : style.badgeBackground) || badgeBackground,
  32. badgeForeground: (style === null || style === void 0 ? void 0 : style.badgeForeground) || badgeForeground,
  33. badgeBorder: contrastBorder
  34. }, widget);
  35. }
  36. export function attachListStyler(widget, themeService, overrides) {
  37. return attachStyler(themeService, Object.assign(Object.assign({}, defaultListStyles), (overrides || {})), widget);
  38. }
  39. export const defaultListStyles = {
  40. listFocusBackground,
  41. listFocusForeground,
  42. listFocusOutline,
  43. listActiveSelectionBackground,
  44. listActiveSelectionForeground,
  45. listActiveSelectionIconForeground,
  46. listFocusAndSelectionBackground: listActiveSelectionBackground,
  47. listFocusAndSelectionForeground: listActiveSelectionForeground,
  48. listInactiveSelectionBackground,
  49. listInactiveSelectionIconForeground,
  50. listInactiveSelectionForeground,
  51. listInactiveFocusBackground,
  52. listInactiveFocusOutline,
  53. listHoverBackground,
  54. listHoverForeground,
  55. listDropBackground,
  56. listSelectionOutline: activeContrastBorder,
  57. listHoverOutline: activeContrastBorder,
  58. listFilterWidgetBackground,
  59. listFilterWidgetOutline,
  60. listFilterWidgetNoMatchesOutline,
  61. listMatchesShadow: widgetShadow,
  62. treeIndentGuidesStroke,
  63. tableColumnsBorder,
  64. tableOddRowsBackgroundColor
  65. };
  66. export const defaultMenuStyles = {
  67. shadowColor: widgetShadow,
  68. borderColor: menuBorder,
  69. foregroundColor: menuForeground,
  70. backgroundColor: menuBackground,
  71. selectionForegroundColor: menuSelectionForeground,
  72. selectionBackgroundColor: menuSelectionBackground,
  73. selectionBorderColor: menuSelectionBorder,
  74. separatorColor: menuSeparatorBackground,
  75. scrollbarShadow: scrollbarShadow,
  76. scrollbarSliderBackground: scrollbarSliderBackground,
  77. scrollbarSliderHoverBackground: scrollbarSliderHoverBackground,
  78. scrollbarSliderActiveBackground: scrollbarSliderActiveBackground
  79. };
  80. export function attachMenuStyler(widget, themeService, style) {
  81. return attachStyler(themeService, Object.assign(Object.assign({}, defaultMenuStyles), style), widget);
  82. }