@opensumi/ide-theme 2.21.13 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/icon-theme-data.js.map +1 -1
- package/lib/browser/icon-theme-store.js.map +1 -1
- package/lib/browser/icon.service.d.ts +3 -1
- package/lib/browser/icon.service.d.ts.map +1 -1
- package/lib/browser/icon.service.js +56 -24
- package/lib/browser/icon.service.js.map +1 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/semantic-tokens-registry.js.map +1 -1
- package/lib/browser/style.service.js.map +1 -1
- package/lib/browser/theme-data.js +7 -7
- package/lib/browser/theme-data.js.map +1 -1
- package/lib/browser/theme-store.js.map +1 -1
- package/lib/browser/theme.contribution.js +3 -3
- package/lib/browser/theme.contribution.js.map +1 -1
- package/lib/browser/workbench.theme.service.js +2 -2
- package/lib/browser/workbench.theme.service.js.map +1 -1
- package/lib/common/color-tokens/basic-color.d.ts +1 -1
- package/lib/common/color-tokens/basic-color.d.ts.map +1 -1
- package/lib/common/color-tokens/editor.d.ts +13 -0
- package/lib/common/color-tokens/editor.d.ts.map +1 -1
- package/lib/common/color-tokens/editor.js +35 -1
- package/lib/common/color-tokens/editor.js.map +1 -1
- package/lib/common/color.js +40 -40
- package/lib/common/color.js.map +1 -1
- package/lib/common/mocks/theme.service.js.map +1 -1
- package/lib/common/plistParser.js +40 -40
- package/lib/common/plistParser.js.map +1 -1
- package/lib/common/semantic-tokens-registry.d.ts +7 -7
- package/lib/common/semantic-tokens-registry.d.ts.map +1 -1
- package/lib/common/theme.service.d.ts +26 -6
- package/lib/common/theme.service.d.ts.map +1 -1
- package/lib/common/theme.service.js.map +1 -1
- package/package.json +11 -10
- package/src/browser/default-theme.ts +547 -0
- package/src/browser/icon-theme-data.ts +294 -0
- package/src/browser/icon-theme-store.ts +38 -0
- package/src/browser/icon.less +15 -0
- package/src/browser/icon.service.ts +457 -0
- package/src/browser/index.ts +45 -0
- package/src/browser/semantic-tokens-registry.ts +217 -0
- package/src/browser/style.service.ts +51 -0
- package/src/browser/theme-data.ts +719 -0
- package/src/browser/theme-store.ts +95 -0
- package/src/browser/theme.contribution.ts +343 -0
- package/src/browser/workbench.theme.service.ts +703 -0
- package/src/common/color-registry.ts +52 -0
- package/src/common/color-tokens/activity-bar.ts +122 -0
- package/src/common/color-tokens/badge.ts +31 -0
- package/src/common/color-tokens/base.ts +90 -0
- package/src/common/color-tokens/basic-color.ts +9 -0
- package/src/common/color-tokens/breadcrumb.ts +60 -0
- package/src/common/color-tokens/button.ts +69 -0
- package/src/common/color-tokens/charts.ts +68 -0
- package/src/common/color-tokens/checkbox.ts +23 -0
- package/src/common/color-tokens/custom/actionbar.ts +51 -0
- package/src/common/color-tokens/custom/activity-bar.ts +16 -0
- package/src/common/color-tokens/custom/badge.ts +30 -0
- package/src/common/color-tokens/custom/base.ts +111 -0
- package/src/common/color-tokens/custom/button.ts +359 -0
- package/src/common/color-tokens/custom/checkbox.ts +36 -0
- package/src/common/color-tokens/custom/decoration.ts +71 -0
- package/src/common/color-tokens/custom/editor.ts +27 -0
- package/src/common/color-tokens/custom/extension.ts +9 -0
- package/src/common/color-tokens/custom/icon.ts +30 -0
- package/src/common/color-tokens/custom/index.ts +26 -0
- package/src/common/color-tokens/custom/input.ts +48 -0
- package/src/common/color-tokens/custom/menu.ts +61 -0
- package/src/common/color-tokens/custom/modal.ts +57 -0
- package/src/common/color-tokens/custom/notification.ts +16 -0
- package/src/common/color-tokens/custom/panel.ts +112 -0
- package/src/common/color-tokens/custom/popover.ts +28 -0
- package/src/common/color-tokens/custom/select.ts +155 -0
- package/src/common/color-tokens/custom/settings.ts +32 -0
- package/src/common/color-tokens/custom/statusbar.ts +16 -0
- package/src/common/color-tokens/custom/tab.ts +31 -0
- package/src/common/color-tokens/custom/tooltip.ts +55 -0
- package/src/common/color-tokens/custom/tree.ts +106 -0
- package/src/common/color-tokens/debug.ts +103 -0
- package/src/common/color-tokens/debugToolbar.ts +134 -0
- package/src/common/color-tokens/dropdown.ts +27 -0
- package/src/common/color-tokens/editor.ts +945 -0
- package/src/common/color-tokens/index.ts +35 -0
- package/src/common/color-tokens/input.ts +105 -0
- package/src/common/color-tokens/list-tree.ts +205 -0
- package/src/common/color-tokens/menu-bar.ts +43 -0
- package/src/common/color-tokens/menu.ts +53 -0
- package/src/common/color-tokens/merge-conflict.ts +145 -0
- package/src/common/color-tokens/minimap.ts +99 -0
- package/src/common/color-tokens/notification.ts +169 -0
- package/src/common/color-tokens/panel.ts +177 -0
- package/src/common/color-tokens/pick-view.ts +96 -0
- package/src/common/color-tokens/picker.ts +15 -0
- package/src/common/color-tokens/progress-bar.ts +12 -0
- package/src/common/color-tokens/quick-input.ts +57 -0
- package/src/common/color-tokens/scrollbar.ts +42 -0
- package/src/common/color-tokens/settings.ts +126 -0
- package/src/common/color-tokens/sidebar.ts +121 -0
- package/src/common/color-tokens/snippet.ts +33 -0
- package/src/common/color-tokens/status-bar.ts +350 -0
- package/src/common/color-tokens/tab.ts +346 -0
- package/src/common/color-tokens/testing.ts +105 -0
- package/src/common/color-tokens/text.ts +41 -0
- package/src/common/color-tokens/title-bar.ts +62 -0
- package/src/common/color-tokens/toolbar.ts +28 -0
- package/src/common/color-tokens/welcome-page.ts +27 -0
- package/src/common/color.ts +647 -0
- package/src/common/default-themes.ts +273 -0
- package/src/common/event.ts +9 -0
- package/src/common/index.ts +8 -0
- package/src/common/mocks/theme.service.ts +55 -0
- package/src/common/plistParser.ts +525 -0
- package/src/common/semantic-tokens-registry.ts +439 -0
- package/src/common/style.ts +9 -0
- package/src/common/theme.service.ts +363 -0
- package/src/common/themeCompatibility.ts +95 -0
- package/src/common/utils.ts +195 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { IRawThemeSetting } from 'vscode-textmate';
|
|
2
|
+
|
|
3
|
+
import { Event, URI, IDisposable, IThemeColor, Deferred } from '@opensumi/ide-core-common';
|
|
4
|
+
|
|
5
|
+
import { Color } from './color';
|
|
6
|
+
import { vs, vs_dark, hc_black, hc_light } from './default-themes';
|
|
7
|
+
|
|
8
|
+
export const ThemeServicePath = 'themeServicePath';
|
|
9
|
+
|
|
10
|
+
export const DEFAULT_THEME_ID = 'ide-dark';
|
|
11
|
+
// from vscode
|
|
12
|
+
export const colorIdPattern = '^\\w+[.\\w+]*$';
|
|
13
|
+
|
|
14
|
+
export interface IIconTheme {
|
|
15
|
+
hasFileIcons: boolean;
|
|
16
|
+
hasFolderIcons: boolean;
|
|
17
|
+
hidesExplorerArrows: boolean;
|
|
18
|
+
styleSheetContent: string;
|
|
19
|
+
load(location?: URI): Promise<string>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const IIconService = Symbol('IIconTheme');
|
|
23
|
+
|
|
24
|
+
export enum IconType {
|
|
25
|
+
Mask = 'mask',
|
|
26
|
+
Background = 'background',
|
|
27
|
+
Base64 = 'base64',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export enum IconShape {
|
|
31
|
+
Circle,
|
|
32
|
+
Square,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IIconService {
|
|
36
|
+
currentThemeId: string;
|
|
37
|
+
currentTheme: IIconTheme;
|
|
38
|
+
iconThemeLoaded: Deferred<void>;
|
|
39
|
+
|
|
40
|
+
onThemeChange: Event<IIconTheme>;
|
|
41
|
+
/**
|
|
42
|
+
* 应用主题(外部需要改主题请直接修改preference)
|
|
43
|
+
* @param themeId 主题ID
|
|
44
|
+
* */
|
|
45
|
+
applyTheme(themeId: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* 将 Base64 路径进行转义,便于在 `background: url("${iconPath}")` 结构中使用
|
|
48
|
+
* @param iconPath Base64 路径
|
|
49
|
+
*/
|
|
50
|
+
encodeBase64Path(iconPath: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* 将 codicon 的 id 转换为 codicon 的 class
|
|
53
|
+
* @param str codicon id eg. $(add), $(add~sync)
|
|
54
|
+
*/
|
|
55
|
+
fromString(str: string): string | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* 将一个url地址或插件主题url转换为icon的class
|
|
58
|
+
* @param basePath 路径前缀
|
|
59
|
+
* @param icon iconUrl地址,可以是直接的字符串,或者和主题类型有关的 object 字符串对象
|
|
60
|
+
* @param type 选择采用Mask或者Background的方式渲染icon资源, 默认值为IconType.Mask
|
|
61
|
+
* @returns icon的className
|
|
62
|
+
*/
|
|
63
|
+
fromIcon(
|
|
64
|
+
basePath: string,
|
|
65
|
+
icon?: { [index in IconThemeType]: string } | string,
|
|
66
|
+
type?: IconType,
|
|
67
|
+
shape?: IconShape,
|
|
68
|
+
fromExtension?: boolean,
|
|
69
|
+
): string | undefined;
|
|
70
|
+
registerIconThemes(iconThemesContribution: ThemeContribution[], extPath: URI): void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 注册来自插件的字体图标
|
|
74
|
+
*/
|
|
75
|
+
registerFontIcons(definitions: FontIconDefinition[], iconFontFamilies: IconFontFamily[]): void;
|
|
76
|
+
getAvailableThemeInfos(): IconThemeInfo[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface IThemeData extends IStandaloneThemeData {
|
|
80
|
+
name: string;
|
|
81
|
+
id: string;
|
|
82
|
+
colorMap: IColorMap;
|
|
83
|
+
themeSettings: IRawThemeSetting[];
|
|
84
|
+
settings: IRawThemeSetting[];
|
|
85
|
+
initializeFromData(data): void;
|
|
86
|
+
initializeThemeData(id, name, base, themeLocation: URI): Promise<void>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface FontIconDefinition {
|
|
90
|
+
id: string;
|
|
91
|
+
content: string;
|
|
92
|
+
fontFamily: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface IconFontFamily {
|
|
96
|
+
source: string;
|
|
97
|
+
fontFamily: string;
|
|
98
|
+
format: string;
|
|
99
|
+
display: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface IThemeService {
|
|
103
|
+
currentThemeId: string;
|
|
104
|
+
colorThemeLoaded: Deferred<void>;
|
|
105
|
+
onThemeChange: Event<ITheme>;
|
|
106
|
+
registerThemes(themeContributions: ThemeContribution[], extPath: URI): IDisposable;
|
|
107
|
+
/**
|
|
108
|
+
* 应用主题(外部需要改主题请直接修改preference)
|
|
109
|
+
* @param id 主题ID
|
|
110
|
+
*/
|
|
111
|
+
applyTheme(id: string): Promise<void>;
|
|
112
|
+
getAvailableThemeInfos(): ThemeInfo[];
|
|
113
|
+
getCurrentTheme(): Promise<ITheme>;
|
|
114
|
+
getCurrentThemeSync(): ITheme;
|
|
115
|
+
getColor(id: string | IThemeColor | undefined): string | undefined;
|
|
116
|
+
getColorVar(id: string | IThemeColor | undefined): string | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* 获取指定 color token 的 className
|
|
119
|
+
*/
|
|
120
|
+
getColorClassNameByColorToken(colorId: string | IThemeColor | undefined): string | undefined;
|
|
121
|
+
registerColor(contribution: ExtColorContribution): void;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export const IThemeService = Symbol('IThemeService');
|
|
125
|
+
|
|
126
|
+
export interface ITokenColorizationRule {
|
|
127
|
+
name?: string;
|
|
128
|
+
scope?: string | string[];
|
|
129
|
+
settings: ITokenColorizationSetting;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface ITokenColorizationSetting {
|
|
133
|
+
foreground?: string;
|
|
134
|
+
background?: string;
|
|
135
|
+
fontStyle?: string; // italic, underline, bold
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export interface ISemanticTokenColorizationSetting {
|
|
139
|
+
foreground?: string;
|
|
140
|
+
fontStyle?: string /* [italic|underline|bold] */;
|
|
141
|
+
bold?: boolean;
|
|
142
|
+
underline?: boolean;
|
|
143
|
+
italic?: boolean;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface IColorMap {
|
|
147
|
+
[id: string]: Color;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Color scheme used by the OS and by color themes.
|
|
152
|
+
*/
|
|
153
|
+
export enum ColorScheme {
|
|
154
|
+
DARK = 'dark',
|
|
155
|
+
LIGHT = 'light',
|
|
156
|
+
HIGH_CONTRAST_DARK = 'hcDark',
|
|
157
|
+
HIGH_CONTRAST_LIGHT = 'hcLight',
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export type BuiltinTheme = 'vs' | 'vs-dark' | 'hc-black' | 'hc-light';
|
|
161
|
+
|
|
162
|
+
export function getThemeTypeName(base: BuiltinTheme) {
|
|
163
|
+
const map = {
|
|
164
|
+
vs: 'theme.base.vs',
|
|
165
|
+
'vs-dark': 'theme.base.vs-dark',
|
|
166
|
+
'hc-black': 'theme.base.hc',
|
|
167
|
+
'hc-light': 'theme.base.hc',
|
|
168
|
+
};
|
|
169
|
+
return map[base];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export enum BuiltinThemeComparator {
|
|
173
|
+
'vs',
|
|
174
|
+
'vs-dark',
|
|
175
|
+
'hc-black',
|
|
176
|
+
'hc-light',
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface IStandaloneThemeData {
|
|
180
|
+
base: BuiltinTheme;
|
|
181
|
+
inherit: boolean;
|
|
182
|
+
rules: ITokenThemeRule[];
|
|
183
|
+
encodedTokensColors?: string[];
|
|
184
|
+
colors: IColors;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface IColors {
|
|
188
|
+
[colorId: string]: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export interface ITokenThemeRule {
|
|
192
|
+
token: string;
|
|
193
|
+
foreground?: string;
|
|
194
|
+
background?: string;
|
|
195
|
+
fontStyle?: string;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface ITokenColorCustomizations {
|
|
199
|
+
[groupIdOrThemeSettingsId: string]:
|
|
200
|
+
| string
|
|
201
|
+
| ITokenColorizationSetting
|
|
202
|
+
| ITokenColorCustomizations
|
|
203
|
+
| undefined
|
|
204
|
+
| ITokenColorizationRule[];
|
|
205
|
+
comments?: string | ITokenColorizationSetting;
|
|
206
|
+
strings?: string | ITokenColorizationSetting;
|
|
207
|
+
numbers?: string | ITokenColorizationSetting;
|
|
208
|
+
keywords?: string | ITokenColorizationSetting;
|
|
209
|
+
types?: string | ITokenColorizationSetting;
|
|
210
|
+
functions?: string | ITokenColorizationSetting;
|
|
211
|
+
variables?: string | ITokenColorizationSetting;
|
|
212
|
+
textMateRules?: ITokenColorizationRule[];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export const VS_LIGHT_THEME_NAME = 'vs';
|
|
216
|
+
export const VS_DARK_THEME_NAME = 'vs-dark';
|
|
217
|
+
export const HC_BLACK_THEME_NAME = 'hc-black';
|
|
218
|
+
export const HC_LIGHT_THEME_NAME = 'hc-light';
|
|
219
|
+
export interface ThemeContribution {
|
|
220
|
+
id?: string;
|
|
221
|
+
label: string;
|
|
222
|
+
// default to be vs
|
|
223
|
+
uiTheme?: BuiltinTheme;
|
|
224
|
+
path: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// base themes
|
|
228
|
+
export const DARK: ThemeType = 'dark';
|
|
229
|
+
export const LIGHT: ThemeType = 'light';
|
|
230
|
+
export const HIGH_CONTRAST_DARK: ThemeType = 'hcDark';
|
|
231
|
+
export const HIGH_CONTRAST_LIGHT: ThemeType = 'hcLight';
|
|
232
|
+
export type ThemeType = 'light' | 'dark' | 'hcDark' | 'hcLight';
|
|
233
|
+
|
|
234
|
+
export type IconThemeType = 'light' | 'dark';
|
|
235
|
+
|
|
236
|
+
export function getBuiltinRules(builtinTheme: BuiltinTheme): IStandaloneThemeData {
|
|
237
|
+
switch (builtinTheme) {
|
|
238
|
+
case VS_LIGHT_THEME_NAME:
|
|
239
|
+
return vs;
|
|
240
|
+
case VS_DARK_THEME_NAME:
|
|
241
|
+
return vs_dark;
|
|
242
|
+
case HC_BLACK_THEME_NAME:
|
|
243
|
+
return hc_black;
|
|
244
|
+
case HC_LIGHT_THEME_NAME:
|
|
245
|
+
return hc_light;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function getThemeTypeSelector(type: ThemeType): string {
|
|
250
|
+
switch (type) {
|
|
251
|
+
case DARK:
|
|
252
|
+
return 'vs-dark';
|
|
253
|
+
case HIGH_CONTRAST_DARK:
|
|
254
|
+
return 'hc-black';
|
|
255
|
+
case HIGH_CONTRAST_LIGHT:
|
|
256
|
+
return 'hc-light';
|
|
257
|
+
default:
|
|
258
|
+
return 'vs';
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function getThemeType(base: BuiltinTheme): ThemeType {
|
|
263
|
+
switch (base) {
|
|
264
|
+
case VS_LIGHT_THEME_NAME:
|
|
265
|
+
return LIGHT;
|
|
266
|
+
case VS_DARK_THEME_NAME:
|
|
267
|
+
return DARK;
|
|
268
|
+
case HC_BLACK_THEME_NAME:
|
|
269
|
+
return HIGH_CONTRAST_DARK;
|
|
270
|
+
case HC_LIGHT_THEME_NAME:
|
|
271
|
+
return HIGH_CONTRAST_LIGHT;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export type ColorIdentifier = string;
|
|
276
|
+
|
|
277
|
+
export interface ITheme {
|
|
278
|
+
readonly type: ThemeType;
|
|
279
|
+
readonly themeData: IThemeData;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Resolves the color of the given color identifier. If the theme does not
|
|
283
|
+
* specify the color, the default color is returned unless <code>useDefault</code> is set to false.
|
|
284
|
+
* @param color the id of the color
|
|
285
|
+
* @param useDefault specifies if the default color should be used. If not set, the default is used.
|
|
286
|
+
*/
|
|
287
|
+
getColor(color: ColorIdentifier, useDefault?: boolean): Color | undefined;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Returns whether the theme defines a value for the color. If not, that means the
|
|
291
|
+
* default color will be used.
|
|
292
|
+
*/
|
|
293
|
+
defines(color: ColorIdentifier): boolean;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface IColorCustomizations {
|
|
297
|
+
[colorIdOrThemeSettingsId: string]: string | IColorCustomizations;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface ColorContribution {
|
|
301
|
+
readonly id: ColorIdentifier;
|
|
302
|
+
readonly description: string;
|
|
303
|
+
readonly defaults: ColorDefaults | null;
|
|
304
|
+
readonly needsTransparency: boolean;
|
|
305
|
+
readonly deprecationMessage: string | undefined;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export interface ExtColorContribution {
|
|
309
|
+
id: string;
|
|
310
|
+
description: string;
|
|
311
|
+
defaults: { light: string; dark: string; highContrast: string; highContrastLight?: string };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export type ColorFunction = (theme: ITheme) => Color | undefined;
|
|
315
|
+
|
|
316
|
+
export interface ColorDefaults {
|
|
317
|
+
light: ColorValue | null;
|
|
318
|
+
dark: ColorValue | null;
|
|
319
|
+
hcDark: ColorValue | null;
|
|
320
|
+
hcLight: ColorValue | null;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* A Color Value is either a color literal, a refence to other color or a derived color
|
|
325
|
+
*/
|
|
326
|
+
export type ColorValue = Color | string | ColorIdentifier | ColorFunction;
|
|
327
|
+
|
|
328
|
+
export interface ThemeInfo {
|
|
329
|
+
name: string;
|
|
330
|
+
base: BuiltinTheme;
|
|
331
|
+
themeId: string;
|
|
332
|
+
inherit?: boolean;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export interface IconThemeInfo {
|
|
336
|
+
name: string;
|
|
337
|
+
themeId: string;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export function themeColorFromId(id: ColorIdentifier) {
|
|
341
|
+
return { id };
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export function getThemeId(contribution: ThemeContribution) {
|
|
345
|
+
if (contribution.id) {
|
|
346
|
+
return contribution.id;
|
|
347
|
+
}
|
|
348
|
+
return `${contribution.uiTheme || 'vs-dark'} ${toCSSSelector('vscode-theme', contribution.path)}`;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function toCSSSelector(extensionId: string, path: string) {
|
|
352
|
+
if (path.indexOf('./') === 0) {
|
|
353
|
+
path = path.substr(2);
|
|
354
|
+
}
|
|
355
|
+
let str = `${extensionId}-${path}`;
|
|
356
|
+
|
|
357
|
+
// remove all characters that are not allowed in css
|
|
358
|
+
str = str.replace(/[^_\-a-zA-Z0-9]/g, '-');
|
|
359
|
+
if (str.charAt(0).match(/[0-9\-]/)) {
|
|
360
|
+
str = '_' + str;
|
|
361
|
+
}
|
|
362
|
+
return str;
|
|
363
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
|
|
6
|
+
import { Color } from './color';
|
|
7
|
+
import * as colorRegistry from './color-registry';
|
|
8
|
+
import { ITokenColorizationRule, IColorMap } from './theme.service';
|
|
9
|
+
|
|
10
|
+
const settingToColorIdMapping: { [settingId: string]: string[] } = {};
|
|
11
|
+
function addSettingMapping(settingId: string, colorId: string) {
|
|
12
|
+
let colorIds = settingToColorIdMapping[settingId];
|
|
13
|
+
if (!colorIds) {
|
|
14
|
+
settingToColorIdMapping[settingId] = colorIds = [];
|
|
15
|
+
}
|
|
16
|
+
colorIds.push(colorId);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 旧的settings和新的ITokenColorizationRule的转换(主要是一些key的映射)
|
|
20
|
+
// tslint:disable
|
|
21
|
+
export function convertSettings(
|
|
22
|
+
oldSettings: ITokenColorizationRule[],
|
|
23
|
+
resultRules: ITokenColorizationRule[],
|
|
24
|
+
resultColors: IColorMap,
|
|
25
|
+
): void {
|
|
26
|
+
for (const rule of oldSettings) {
|
|
27
|
+
resultRules.push(rule);
|
|
28
|
+
if (!rule.scope) {
|
|
29
|
+
const settings = rule.settings;
|
|
30
|
+
if (!settings) {
|
|
31
|
+
rule.settings = {};
|
|
32
|
+
} else {
|
|
33
|
+
// eslint-disable-next-line guard-for-in
|
|
34
|
+
for (const key in settings) {
|
|
35
|
+
const mappings = settingToColorIdMapping[key];
|
|
36
|
+
if (mappings) {
|
|
37
|
+
const colorHex = settings[key];
|
|
38
|
+
if (typeof colorHex === 'string') {
|
|
39
|
+
const color = Color.fromHex(colorHex);
|
|
40
|
+
for (const colorId of mappings) {
|
|
41
|
+
resultColors[colorId] = color;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (key !== 'foreground' && key !== 'background' && key !== 'fontStyle') {
|
|
46
|
+
delete settings[key];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
addSettingMapping('background', colorRegistry.editorBackground);
|
|
55
|
+
addSettingMapping('foreground', colorRegistry.editorForeground);
|
|
56
|
+
addSettingMapping('selection', colorRegistry.editorSelectionBackground);
|
|
57
|
+
addSettingMapping('inactiveSelection', colorRegistry.editorInactiveSelection);
|
|
58
|
+
addSettingMapping('selectionHighlightColor', colorRegistry.editorSelectionHighlight);
|
|
59
|
+
addSettingMapping('findMatchHighlight', colorRegistry.editorFindMatchHighlight);
|
|
60
|
+
addSettingMapping('currentFindMatchHighlight', colorRegistry.editorFindMatch);
|
|
61
|
+
addSettingMapping('hoverHighlight', colorRegistry.editorHoverHighlight);
|
|
62
|
+
addSettingMapping('wordHighlight', 'editor.wordHighlightBackground'); // inlined to avoid editor/contrib dependenies
|
|
63
|
+
addSettingMapping('wordHighlightStrong', 'editor.wordHighlightStrongBackground');
|
|
64
|
+
addSettingMapping('findRangeHighlight', colorRegistry.editorFindRangeHighlight);
|
|
65
|
+
addSettingMapping('findMatchHighlight', 'peekViewResult.matchHighlightBackground');
|
|
66
|
+
addSettingMapping('referenceHighlight', 'peekViewEditor.matchHighlightBackground');
|
|
67
|
+
addSettingMapping('lineHighlight', colorRegistry.editorLineHighlight);
|
|
68
|
+
addSettingMapping('rangeHighlight', colorRegistry.editorRangeHighlight);
|
|
69
|
+
addSettingMapping('caret', colorRegistry.editorCursorForeground);
|
|
70
|
+
addSettingMapping('invisibles', colorRegistry.editorWhitespaces);
|
|
71
|
+
addSettingMapping('guide', colorRegistry.editorIndentGuides);
|
|
72
|
+
addSettingMapping('activeGuide', colorRegistry.editorActiveIndentGuides);
|
|
73
|
+
|
|
74
|
+
const ansiColorMap = [
|
|
75
|
+
'ansiBlack',
|
|
76
|
+
'ansiRed',
|
|
77
|
+
'ansiGreen',
|
|
78
|
+
'ansiYellow',
|
|
79
|
+
'ansiBlue',
|
|
80
|
+
'ansiMagenta',
|
|
81
|
+
'ansiCyan',
|
|
82
|
+
'ansiWhite',
|
|
83
|
+
'ansiBrightBlack',
|
|
84
|
+
'ansiBrightRed',
|
|
85
|
+
'ansiBrightGreen',
|
|
86
|
+
'ansiBrightYellow',
|
|
87
|
+
'ansiBrightBlue',
|
|
88
|
+
'ansiBrightMagenta',
|
|
89
|
+
'ansiBrightCyan',
|
|
90
|
+
'ansiBrightWhite',
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
for (const color of ansiColorMap) {
|
|
94
|
+
addSettingMapping(color, 'terminal.' + color);
|
|
95
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Emitter, Event } from '@opensumi/ide-core-common';
|
|
2
|
+
|
|
3
|
+
import { Color } from './color';
|
|
4
|
+
import { ColorValue, ColorFunction, ITheme, ColorContribution, ColorDefaults, ColorIdentifier } from './theme.service';
|
|
5
|
+
|
|
6
|
+
// color registry
|
|
7
|
+
export const Extensions = {
|
|
8
|
+
ColorContribution: 'base.contributions.colors',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export interface IColorRegistry {
|
|
12
|
+
/**
|
|
13
|
+
* Register a color to the registry.
|
|
14
|
+
* @param id The color id as used in theme description files
|
|
15
|
+
* @param defaults The default values
|
|
16
|
+
* @description the description
|
|
17
|
+
*/
|
|
18
|
+
registerColor(id: string, defaults: ColorDefaults, description: string): ColorIdentifier;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Register a color to the registry.
|
|
22
|
+
*/
|
|
23
|
+
deregisterColor(id: string): void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Get all color contributions
|
|
27
|
+
*/
|
|
28
|
+
getColors(): ColorContribution[];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Gets the default color of the given id
|
|
32
|
+
*/
|
|
33
|
+
resolveDefaultColor(id: ColorIdentifier, theme: ITheme): Color | undefined;
|
|
34
|
+
|
|
35
|
+
onDidColorChangedEvent: Event<void>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class ColorRegistry implements IColorRegistry {
|
|
39
|
+
private colorsById: { [key: string]: ColorContribution };
|
|
40
|
+
|
|
41
|
+
private onDidColorChanged: Emitter<void> = new Emitter();
|
|
42
|
+
|
|
43
|
+
onDidColorChangedEvent: Event<void> = Event.debounce(this.onDidColorChanged.event, () => {}, 500);
|
|
44
|
+
|
|
45
|
+
constructor() {
|
|
46
|
+
this.colorsById = {};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public registerColor(
|
|
50
|
+
id: string,
|
|
51
|
+
defaults: ColorDefaults | null,
|
|
52
|
+
description: string,
|
|
53
|
+
needsTransparency = false,
|
|
54
|
+
deprecationMessage?: string,
|
|
55
|
+
): ColorIdentifier {
|
|
56
|
+
const colorContribution: ColorContribution = { id, description, defaults, needsTransparency, deprecationMessage };
|
|
57
|
+
this.colorsById[id] = colorContribution;
|
|
58
|
+
this.onDidColorChanged.fire();
|
|
59
|
+
return id;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public deregisterColor(id: string): void {
|
|
63
|
+
delete this.colorsById[id];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public getColors(): ColorContribution[] {
|
|
67
|
+
return Object.keys(this.colorsById).map((id) => this.colorsById[id]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public resolveDefaultColor(id: ColorIdentifier, theme: ITheme): Color | undefined {
|
|
71
|
+
const colorDesc = this.colorsById[id];
|
|
72
|
+
if (colorDesc && colorDesc.defaults) {
|
|
73
|
+
const colorValue = colorDesc.defaults[theme.type];
|
|
74
|
+
return resolveColorValue(colorValue, theme);
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public toString() {
|
|
80
|
+
const sorter = (a: string, b: string) => {
|
|
81
|
+
const cat1 = a.indexOf('.') === -1 ? 0 : 1;
|
|
82
|
+
const cat2 = b.indexOf('.') === -1 ? 0 : 1;
|
|
83
|
+
if (cat1 !== cat2) {
|
|
84
|
+
return cat1 - cat2;
|
|
85
|
+
}
|
|
86
|
+
return a.localeCompare(b);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return Object.keys(this.colorsById)
|
|
90
|
+
.sort(sorter)
|
|
91
|
+
.map((k) => `- \`${k}\`: ${this.colorsById[k].description}`)
|
|
92
|
+
.join('\n');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const colorRegistry = new ColorRegistry();
|
|
97
|
+
|
|
98
|
+
export function getColorRegistry(): IColorRegistry {
|
|
99
|
+
return colorRegistry;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function registerColor(
|
|
103
|
+
id: string,
|
|
104
|
+
defaults: ColorDefaults | null,
|
|
105
|
+
description: string,
|
|
106
|
+
needsTransparency?: boolean,
|
|
107
|
+
deprecationMessage?: string,
|
|
108
|
+
): ColorIdentifier {
|
|
109
|
+
return colorRegistry.registerColor(id, defaults, description, needsTransparency, deprecationMessage);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function darken(colorValue: ColorValue, factor: number): ColorFunction {
|
|
113
|
+
return (theme) => {
|
|
114
|
+
const color = resolveColorValue(colorValue, theme);
|
|
115
|
+
if (color) {
|
|
116
|
+
return color.darken(factor);
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function lighten(colorValue: ColorValue, factor: number): ColorFunction {
|
|
123
|
+
return (theme) => {
|
|
124
|
+
const color = resolveColorValue(colorValue, theme);
|
|
125
|
+
if (color) {
|
|
126
|
+
return color.lighten(factor);
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function transparent(colorValue: ColorValue, factor: number): ColorFunction {
|
|
133
|
+
return (theme) => {
|
|
134
|
+
const color = resolveColorValue(colorValue, theme);
|
|
135
|
+
if (color) {
|
|
136
|
+
return color.transparent(factor);
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function oneOf(...colorValues: ColorValue[]): ColorFunction {
|
|
143
|
+
return (theme) => {
|
|
144
|
+
for (const colorValue of colorValues) {
|
|
145
|
+
const color = resolveColorValue(colorValue, theme);
|
|
146
|
+
if (color) {
|
|
147
|
+
return color;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return undefined;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function lessProminent(
|
|
155
|
+
colorValue: ColorValue,
|
|
156
|
+
backgroundColorValue: ColorValue,
|
|
157
|
+
factor: number,
|
|
158
|
+
transparency: number,
|
|
159
|
+
): ColorFunction {
|
|
160
|
+
return (theme) => {
|
|
161
|
+
const from = resolveColorValue(colorValue, theme);
|
|
162
|
+
if (from) {
|
|
163
|
+
const backgroundColor = resolveColorValue(backgroundColorValue, theme);
|
|
164
|
+
if (backgroundColor) {
|
|
165
|
+
if (from.isDarkerThan(backgroundColor)) {
|
|
166
|
+
return Color.getLighterColor(from, backgroundColor, factor).transparent(transparency);
|
|
167
|
+
}
|
|
168
|
+
return Color.getDarkerColor(from, backgroundColor, factor).transparent(transparency);
|
|
169
|
+
}
|
|
170
|
+
return from.transparent(factor * transparency);
|
|
171
|
+
}
|
|
172
|
+
return undefined;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @param colorValue Resolve a color value in the context of a theme
|
|
178
|
+
*/
|
|
179
|
+
export function resolveColorValue(colorValue: ColorValue | null, theme: ITheme): Color | undefined {
|
|
180
|
+
if (colorValue === null) {
|
|
181
|
+
return undefined;
|
|
182
|
+
} else if (colorValue === 'transparent') {
|
|
183
|
+
return Color.fromHex('#00000000');
|
|
184
|
+
} else if (typeof colorValue === 'string') {
|
|
185
|
+
if (colorValue[0] === '#') {
|
|
186
|
+
return Color.fromHex(colorValue);
|
|
187
|
+
}
|
|
188
|
+
return theme.getColor(colorValue);
|
|
189
|
+
} else if (colorValue instanceof Color) {
|
|
190
|
+
return colorValue;
|
|
191
|
+
} else if (typeof colorValue === 'function') {
|
|
192
|
+
return colorValue(theme) as Color;
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './common';
|