eaa9ba759c9932a872669404d999458a03bc561bd6d5ddac16cb30771e00c10e77ee3679a8f67c92af65bb41ac0ac9456cef21b3de37b25bfbeb7ddae2b474 5.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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, inputActiveOptionBackground, inputActiveOptionBorder, inputActiveOptionForeground, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationInfoForeground, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationWarningForeground, 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, listFocusAndSelectionOutline, listFilterWidgetShadow } from './colorRegistry.js';
  6. export function computeStyles(theme, styleMap) {
  7. const styles = Object.create(null);
  8. for (const 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. listFocusAndSelectionOutline,
  47. listFocusAndSelectionBackground: listActiveSelectionBackground,
  48. listFocusAndSelectionForeground: listActiveSelectionForeground,
  49. listInactiveSelectionBackground,
  50. listInactiveSelectionIconForeground,
  51. listInactiveSelectionForeground,
  52. listInactiveFocusBackground,
  53. listInactiveFocusOutline,
  54. listHoverBackground,
  55. listHoverForeground,
  56. listDropBackground,
  57. listSelectionOutline: activeContrastBorder,
  58. listHoverOutline: activeContrastBorder,
  59. listFilterWidgetBackground,
  60. listFilterWidgetOutline,
  61. listFilterWidgetNoMatchesOutline,
  62. listFilterWidgetShadow,
  63. treeIndentGuidesStroke,
  64. tableColumnsBorder,
  65. tableOddRowsBackgroundColor,
  66. inputActiveOptionBorder,
  67. inputActiveOptionForeground,
  68. inputActiveOptionBackground,
  69. inputBackground,
  70. inputForeground,
  71. inputBorder,
  72. inputValidationInfoBackground,
  73. inputValidationInfoForeground,
  74. inputValidationInfoBorder,
  75. inputValidationWarningBackground,
  76. inputValidationWarningForeground,
  77. inputValidationWarningBorder,
  78. inputValidationErrorBackground,
  79. inputValidationErrorForeground,
  80. inputValidationErrorBorder,
  81. };
  82. export const defaultMenuStyles = {
  83. shadowColor: widgetShadow,
  84. borderColor: menuBorder,
  85. foregroundColor: menuForeground,
  86. backgroundColor: menuBackground,
  87. selectionForegroundColor: menuSelectionForeground,
  88. selectionBackgroundColor: menuSelectionBackground,
  89. selectionBorderColor: menuSelectionBorder,
  90. separatorColor: menuSeparatorBackground,
  91. scrollbarShadow: scrollbarShadow,
  92. scrollbarSliderBackground: scrollbarSliderBackground,
  93. scrollbarSliderHoverBackground: scrollbarSliderHoverBackground,
  94. scrollbarSliderActiveBackground: scrollbarSliderActiveBackground
  95. };
  96. export function attachMenuStyler(widget, themeService, style) {
  97. return attachStyler(themeService, Object.assign(Object.assign({}, defaultMenuStyles), style), widget);
  98. }