-
Notifications
You must be signed in to change notification settings - Fork 30.6k
/
Copy pathstyle.ts
238 lines (212 loc) · 8.71 KB
/
style.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/style';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { iconForeground, foreground, selectionBackground, focusBorder, scrollbarShadow, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, listHighlightForeground, inputPlaceholderForeground, toolbarHoverBackground, toolbarActiveBackground, toolbarHoverOutline, listFocusHighlightForeground } from 'vs/platform/theme/common/colorRegistry';
import { WORKBENCH_BACKGROUND, TITLE_BAR_ACTIVE_BACKGROUND } from 'vs/workbench/common/theme';
import { isWeb, isIOS, isMacintosh, isWindows } from 'vs/base/common/platform';
import { createMetaElement } from 'vs/base/browser/dom';
import { isSafari, isStandalone } from 'vs/base/browser/browser';
import { ColorScheme } from 'vs/platform/theme/common/theme';
registerThemingParticipant((theme, collector) => {
// Foreground
const windowForeground = theme.getColor(foreground);
if (windowForeground) {
collector.addRule(`.monaco-workbench { color: ${windowForeground}; }`);
}
// Background (We need to set the workbench background color so that on Windows we get subpixel-antialiasing)
const workbenchBackground = WORKBENCH_BACKGROUND(theme);
collector.addRule(`.monaco-workbench { background-color: ${workbenchBackground}; }`);
// Icon defaults
const iconForegroundColor = theme.getColor(iconForeground);
if (iconForegroundColor) {
collector.addRule(`.codicon { color: ${iconForegroundColor}; }`);
}
// Selection
const windowSelectionBackground = theme.getColor(selectionBackground);
if (windowSelectionBackground) {
collector.addRule(`.monaco-workbench ::selection { background-color: ${windowSelectionBackground}; }`);
}
// Input placeholder
const placeholderForeground = theme.getColor(inputPlaceholderForeground);
if (placeholderForeground) {
collector.addRule(`
.monaco-workbench input::placeholder { color: ${placeholderForeground}; }
.monaco-workbench input::-webkit-input-placeholder { color: ${placeholderForeground}; }
.monaco-workbench input::-moz-placeholder { color: ${placeholderForeground}; }
`);
collector.addRule(`
.monaco-workbench textarea::placeholder { color: ${placeholderForeground}; }
.monaco-workbench textarea::-webkit-input-placeholder { color: ${placeholderForeground}; }
.monaco-workbench textarea::-moz-placeholder { color: ${placeholderForeground}; }
`);
}
// List highlight
const listHighlightForegroundColor = theme.getColor(listHighlightForeground);
if (listHighlightForegroundColor) {
collector.addRule(`
.monaco-workbench .monaco-list .monaco-list-row .monaco-highlighted-label .highlight {
color: ${listHighlightForegroundColor};
}
`);
}
// List highlight w/ focus
const listHighlightFocusForegroundColor = theme.getColor(listFocusHighlightForeground);
if (listHighlightFocusForegroundColor) {
collector.addRule(`
.monaco-workbench .monaco-list .monaco-list-row.focused .monaco-highlighted-label .highlight {
color: ${listHighlightFocusForegroundColor};
}
`);
}
// Scrollbars
const scrollbarShadowColor = theme.getColor(scrollbarShadow);
if (scrollbarShadowColor) {
collector.addRule(`
.monaco-workbench .monaco-scrollable-element > .shadow.top {
box-shadow: ${scrollbarShadowColor} 0 6px 6px -6px inset;
}
.monaco-workbench .monaco-scrollable-element > .shadow.left {
box-shadow: ${scrollbarShadowColor} 6px 0 6px -6px inset;
}
.monaco-workbench .monaco-scrollable-element > .shadow.top.left {
box-shadow: ${scrollbarShadowColor} 6px 6px 6px -6px inset;
}
`);
}
const scrollbarSliderBackgroundColor = theme.getColor(scrollbarSliderBackground);
if (scrollbarSliderBackgroundColor) {
collector.addRule(`
.monaco-workbench .monaco-scrollable-element > .scrollbar > .slider {
background: ${scrollbarSliderBackgroundColor};
}
`);
}
const scrollbarSliderHoverBackgroundColor = theme.getColor(scrollbarSliderHoverBackground);
if (scrollbarSliderHoverBackgroundColor) {
collector.addRule(`
.monaco-workbench .monaco-scrollable-element > .scrollbar > .slider:hover {
background: ${scrollbarSliderHoverBackgroundColor};
}
`);
}
const scrollbarSliderActiveBackgroundColor = theme.getColor(scrollbarSliderActiveBackground);
if (scrollbarSliderActiveBackgroundColor) {
collector.addRule(`
.monaco-workbench .monaco-scrollable-element > .scrollbar > .slider.active {
background: ${scrollbarSliderActiveBackgroundColor};
}
`);
}
// Focus outline
const focusOutline = theme.getColor(focusBorder);
if (focusOutline) {
collector.addRule(`
.monaco-workbench [tabindex="0"]:focus,
.monaco-workbench [tabindex="-1"]:focus,
.monaco-workbench .synthetic-focus,
.monaco-workbench select:focus,
.monaco-workbench .monaco-list:not(.element-focused):focus:before,
.monaco-workbench input[type="button"]:focus,
.monaco-workbench input[type="text"]:focus,
.monaco-workbench button:focus,
.monaco-workbench textarea:focus,
.monaco-workbench input[type="search"]:focus,
.monaco-workbench input[type="checkbox"]:focus {
outline-color: ${focusOutline};
}
`);
}
// High Contrast theme overwrites for outline
if (theme.type === ColorScheme.HIGH_CONTRAST) {
collector.addRule(`
.hc-black [tabindex="0"]:focus,
.hc-black [tabindex="-1"]:focus,
.hc-black .synthetic-focus,
.hc-black select:focus,
.hc-black input[type="button"]:focus,
.hc-black input[type="text"]:focus,
.hc-black textarea:focus,
.hc-black input[type="checkbox"]:focus {
outline-style: solid;
outline-width: 1px;
}
.hc-black .synthetic-focus input {
background: transparent; /* Search input focus fix when in high contrast */
}
`);
}
// Update <meta name="theme-color" content=""> based on selected theme
if (isWeb) {
const titleBackground = theme.getColor(TITLE_BAR_ACTIVE_BACKGROUND);
if (titleBackground) {
const metaElementId = 'monaco-workbench-meta-theme-color';
let metaElement = document.getElementById(metaElementId) as HTMLMetaElement | null;
if (!metaElement) {
metaElement = createMetaElement();
metaElement.name = 'theme-color';
metaElement.id = metaElementId;
}
metaElement.content = titleBackground.toString();
}
}
// We disable user select on the root element, however on Safari this seems
// to prevent any text selection in the monaco editor. As a workaround we
// allow to select text in monaco editor instances.
if (isSafari) {
collector.addRule(`
body.web {
touch-action: none;
}
.monaco-workbench .monaco-editor .view-lines {
user-select: text;
-webkit-user-select: text;
}
`);
}
// Update body background color to ensure the home indicator area looks similar to the workbench
if (isIOS && isStandalone) {
collector.addRule(`body { background-color: ${workbenchBackground}; }`);
}
// Action bars
const toolbarHoverBackgroundColor = theme.getColor(toolbarHoverBackground);
if (toolbarHoverBackgroundColor) {
collector.addRule(`
.monaco-action-bar:not(.vertical) .action-label:not(.disabled):hover {
background-color: ${toolbarHoverBackgroundColor};
}
.monaco-action-bar:not(.vertical) .monaco-dropdown-with-primary:not(.disabled):hover {
background-color: ${toolbarHoverBackgroundColor};
}
`);
}
const toolbarActiveBackgroundColor = theme.getColor(toolbarActiveBackground);
if (toolbarActiveBackgroundColor) {
collector.addRule(`
.monaco-action-bar:not(.vertical) .action-item.active .action-label:not(.disabled),
.monaco-action-bar:not(.vertical) .monaco-dropdown.active .action-label:not(.disabled) {
background-color: ${toolbarActiveBackgroundColor};
}
`);
}
const toolbarHoverOutlineColor = theme.getColor(toolbarHoverOutline);
if (toolbarHoverOutlineColor) {
collector.addRule(`
.monaco-action-bar:not(.vertical) .action-item .action-label:hover:not(.disabled) {
outline: 1px dashed ${toolbarHoverOutlineColor};
outline-offset: -1px;
}
`);
}
});
/**
* The best font-family to be used in CSS based on the platform:
* - Windows: Segoe preferred, fallback to sans-serif
* - macOS: standard system font, fallback to sans-serif
* - Linux: standard system font preferred, fallback to Ubuntu fonts
*
* Note: this currently does not adjust for different locales.
*/
export const DEFAULT_FONT_FAMILY = isWindows ? '"Segoe WPC", "Segoe UI", sans-serif' : isMacintosh ? '-apple-system, BlinkMacSystemFont, sans-serif' : 'system-ui, "Ubuntu", "Droid Sans", sans-serif';