@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.
Files changed (117) hide show
  1. package/lib/browser/icon-theme-data.js.map +1 -1
  2. package/lib/browser/icon-theme-store.js.map +1 -1
  3. package/lib/browser/icon.service.d.ts +3 -1
  4. package/lib/browser/icon.service.d.ts.map +1 -1
  5. package/lib/browser/icon.service.js +56 -24
  6. package/lib/browser/icon.service.js.map +1 -1
  7. package/lib/browser/index.js.map +1 -1
  8. package/lib/browser/semantic-tokens-registry.js.map +1 -1
  9. package/lib/browser/style.service.js.map +1 -1
  10. package/lib/browser/theme-data.js +7 -7
  11. package/lib/browser/theme-data.js.map +1 -1
  12. package/lib/browser/theme-store.js.map +1 -1
  13. package/lib/browser/theme.contribution.js +3 -3
  14. package/lib/browser/theme.contribution.js.map +1 -1
  15. package/lib/browser/workbench.theme.service.js +2 -2
  16. package/lib/browser/workbench.theme.service.js.map +1 -1
  17. package/lib/common/color-tokens/basic-color.d.ts +1 -1
  18. package/lib/common/color-tokens/basic-color.d.ts.map +1 -1
  19. package/lib/common/color-tokens/editor.d.ts +13 -0
  20. package/lib/common/color-tokens/editor.d.ts.map +1 -1
  21. package/lib/common/color-tokens/editor.js +35 -1
  22. package/lib/common/color-tokens/editor.js.map +1 -1
  23. package/lib/common/color.js +40 -40
  24. package/lib/common/color.js.map +1 -1
  25. package/lib/common/mocks/theme.service.js.map +1 -1
  26. package/lib/common/plistParser.js +40 -40
  27. package/lib/common/plistParser.js.map +1 -1
  28. package/lib/common/semantic-tokens-registry.d.ts +7 -7
  29. package/lib/common/semantic-tokens-registry.d.ts.map +1 -1
  30. package/lib/common/theme.service.d.ts +26 -6
  31. package/lib/common/theme.service.d.ts.map +1 -1
  32. package/lib/common/theme.service.js.map +1 -1
  33. package/package.json +11 -10
  34. package/src/browser/default-theme.ts +547 -0
  35. package/src/browser/icon-theme-data.ts +294 -0
  36. package/src/browser/icon-theme-store.ts +38 -0
  37. package/src/browser/icon.less +15 -0
  38. package/src/browser/icon.service.ts +457 -0
  39. package/src/browser/index.ts +45 -0
  40. package/src/browser/semantic-tokens-registry.ts +217 -0
  41. package/src/browser/style.service.ts +51 -0
  42. package/src/browser/theme-data.ts +719 -0
  43. package/src/browser/theme-store.ts +95 -0
  44. package/src/browser/theme.contribution.ts +343 -0
  45. package/src/browser/workbench.theme.service.ts +703 -0
  46. package/src/common/color-registry.ts +52 -0
  47. package/src/common/color-tokens/activity-bar.ts +122 -0
  48. package/src/common/color-tokens/badge.ts +31 -0
  49. package/src/common/color-tokens/base.ts +90 -0
  50. package/src/common/color-tokens/basic-color.ts +9 -0
  51. package/src/common/color-tokens/breadcrumb.ts +60 -0
  52. package/src/common/color-tokens/button.ts +69 -0
  53. package/src/common/color-tokens/charts.ts +68 -0
  54. package/src/common/color-tokens/checkbox.ts +23 -0
  55. package/src/common/color-tokens/custom/actionbar.ts +51 -0
  56. package/src/common/color-tokens/custom/activity-bar.ts +16 -0
  57. package/src/common/color-tokens/custom/badge.ts +30 -0
  58. package/src/common/color-tokens/custom/base.ts +111 -0
  59. package/src/common/color-tokens/custom/button.ts +359 -0
  60. package/src/common/color-tokens/custom/checkbox.ts +36 -0
  61. package/src/common/color-tokens/custom/decoration.ts +71 -0
  62. package/src/common/color-tokens/custom/editor.ts +27 -0
  63. package/src/common/color-tokens/custom/extension.ts +9 -0
  64. package/src/common/color-tokens/custom/icon.ts +30 -0
  65. package/src/common/color-tokens/custom/index.ts +26 -0
  66. package/src/common/color-tokens/custom/input.ts +48 -0
  67. package/src/common/color-tokens/custom/menu.ts +61 -0
  68. package/src/common/color-tokens/custom/modal.ts +57 -0
  69. package/src/common/color-tokens/custom/notification.ts +16 -0
  70. package/src/common/color-tokens/custom/panel.ts +112 -0
  71. package/src/common/color-tokens/custom/popover.ts +28 -0
  72. package/src/common/color-tokens/custom/select.ts +155 -0
  73. package/src/common/color-tokens/custom/settings.ts +32 -0
  74. package/src/common/color-tokens/custom/statusbar.ts +16 -0
  75. package/src/common/color-tokens/custom/tab.ts +31 -0
  76. package/src/common/color-tokens/custom/tooltip.ts +55 -0
  77. package/src/common/color-tokens/custom/tree.ts +106 -0
  78. package/src/common/color-tokens/debug.ts +103 -0
  79. package/src/common/color-tokens/debugToolbar.ts +134 -0
  80. package/src/common/color-tokens/dropdown.ts +27 -0
  81. package/src/common/color-tokens/editor.ts +945 -0
  82. package/src/common/color-tokens/index.ts +35 -0
  83. package/src/common/color-tokens/input.ts +105 -0
  84. package/src/common/color-tokens/list-tree.ts +205 -0
  85. package/src/common/color-tokens/menu-bar.ts +43 -0
  86. package/src/common/color-tokens/menu.ts +53 -0
  87. package/src/common/color-tokens/merge-conflict.ts +145 -0
  88. package/src/common/color-tokens/minimap.ts +99 -0
  89. package/src/common/color-tokens/notification.ts +169 -0
  90. package/src/common/color-tokens/panel.ts +177 -0
  91. package/src/common/color-tokens/pick-view.ts +96 -0
  92. package/src/common/color-tokens/picker.ts +15 -0
  93. package/src/common/color-tokens/progress-bar.ts +12 -0
  94. package/src/common/color-tokens/quick-input.ts +57 -0
  95. package/src/common/color-tokens/scrollbar.ts +42 -0
  96. package/src/common/color-tokens/settings.ts +126 -0
  97. package/src/common/color-tokens/sidebar.ts +121 -0
  98. package/src/common/color-tokens/snippet.ts +33 -0
  99. package/src/common/color-tokens/status-bar.ts +350 -0
  100. package/src/common/color-tokens/tab.ts +346 -0
  101. package/src/common/color-tokens/testing.ts +105 -0
  102. package/src/common/color-tokens/text.ts +41 -0
  103. package/src/common/color-tokens/title-bar.ts +62 -0
  104. package/src/common/color-tokens/toolbar.ts +28 -0
  105. package/src/common/color-tokens/welcome-page.ts +27 -0
  106. package/src/common/color.ts +647 -0
  107. package/src/common/default-themes.ts +273 -0
  108. package/src/common/event.ts +9 -0
  109. package/src/common/index.ts +8 -0
  110. package/src/common/mocks/theme.service.ts +55 -0
  111. package/src/common/plistParser.ts +525 -0
  112. package/src/common/semantic-tokens-registry.ts +439 -0
  113. package/src/common/style.ts +9 -0
  114. package/src/common/theme.service.ts +363 -0
  115. package/src/common/themeCompatibility.ts +95 -0
  116. package/src/common/utils.ts +195 -0
  117. package/src/index.ts +1 -0
@@ -0,0 +1,439 @@
1
+ import { IJSONSchema } from '@opensumi/ide-core-common/lib/json-schema';
2
+
3
+ import { Color } from './color';
4
+ import { ITokenColorizationSetting } from './theme.service';
5
+
6
+ export const ISemanticTokenRegistry = Symbol('ISemanticTokenRegistry');
7
+
8
+ export const TOKEN_TYPE_WILDCARD = '*';
9
+ export const TOKEN_CLASSIFIER_LANGUAGE_SEPARATOR = ':';
10
+ export const CLASSIFIER_MODIFIER_SEPARATOR = '.';
11
+
12
+ const CHAR_LANGUAGE = TOKEN_CLASSIFIER_LANGUAGE_SEPARATOR.charCodeAt(0);
13
+ const CHAR_MODIFIER = CLASSIFIER_MODIFIER_SEPARATOR.charCodeAt(0);
14
+
15
+ // qualified string [type|*](.modifier)*(/language)!
16
+ export type TokenClassificationString = string;
17
+
18
+ export const idPattern = '\\w+[-_\\w+]*';
19
+ export const typeAndModifierIdPattern = `^${idPattern}$`;
20
+
21
+ export const selectorPattern = `^(${idPattern}|\\*)(\\${CLASSIFIER_MODIFIER_SEPARATOR}${idPattern})*(\\${TOKEN_CLASSIFIER_LANGUAGE_SEPARATOR}${idPattern})?$`;
22
+
23
+ export const fontStylePattern = '^(\\s*(italic|bold|underline))*\\s*$';
24
+
25
+ export interface TokenSelector {
26
+ match(type: string, modifiers: string[], language: string): number;
27
+ readonly id: string;
28
+ }
29
+
30
+ export interface SemanticTokenDefaultRule {
31
+ selector: TokenSelector;
32
+ defaults: TokenStyleDefaults;
33
+ }
34
+
35
+ export interface TokenTypeOrModifierContribution {
36
+ readonly num: number;
37
+ readonly id: string;
38
+ readonly superType?: string;
39
+ readonly description: string;
40
+ readonly deprecationMessage?: string;
41
+ }
42
+
43
+ export interface TokenStyleData {
44
+ foreground?: Color;
45
+ bold?: boolean;
46
+ underline?: boolean;
47
+ italic?: boolean;
48
+ }
49
+
50
+ export class TokenStyle implements Readonly<TokenStyleData> {
51
+ constructor(
52
+ public readonly foreground?: Color,
53
+ public readonly bold?: boolean,
54
+ public readonly underline?: boolean,
55
+ public readonly italic?: boolean,
56
+ ) {}
57
+ }
58
+
59
+ export namespace TokenStyle {
60
+ export function toJSONObject(style: TokenStyle): any {
61
+ return {
62
+ _foreground: style.foreground === undefined ? null : Color.Format.CSS.formatHexA(style.foreground, true),
63
+ _bold: style.bold === undefined ? null : style.bold,
64
+ _underline: style.underline === undefined ? null : style.underline,
65
+ _italic: style.italic === undefined ? null : style.italic,
66
+ };
67
+ }
68
+ export function fromJSONObject(obj: any): TokenStyle | undefined {
69
+ if (obj) {
70
+ const boolOrUndef = (b: any) => (typeof b === 'boolean' ? b : undefined);
71
+ const colorOrUndef = (s: any) => (typeof s === 'string' ? Color.fromHex(s) : undefined);
72
+ return new TokenStyle(
73
+ colorOrUndef(obj._foreground),
74
+ boolOrUndef(obj._bold),
75
+ boolOrUndef(obj._underline),
76
+ boolOrUndef(obj._italic),
77
+ );
78
+ }
79
+ return undefined;
80
+ }
81
+ export function equals(s1: any, s2: any): boolean {
82
+ if (s1 === s2) {
83
+ return true;
84
+ }
85
+ return (
86
+ s1 !== undefined &&
87
+ s2 !== undefined &&
88
+ (s1.foreground instanceof Color ? s1.foreground.equals(s2.foreground) : s2.foreground === undefined) &&
89
+ s1.bold === s2.bold &&
90
+ s1.underline === s2.underline &&
91
+ s1.italic === s2.italic
92
+ );
93
+ }
94
+ export function is(s: any): s is TokenStyle {
95
+ return s instanceof TokenStyle;
96
+ }
97
+ export function fromData(data: {
98
+ foreground?: Color;
99
+ bold?: boolean;
100
+ underline?: boolean;
101
+ italic?: boolean;
102
+ }): TokenStyle {
103
+ return new TokenStyle(data.foreground, data.bold, data.underline, data.italic);
104
+ }
105
+ export function fromSettings(
106
+ foreground: string | undefined,
107
+ fontStyle: string | undefined,
108
+ bold?: boolean,
109
+ underline?: boolean,
110
+ italic?: boolean,
111
+ ): TokenStyle {
112
+ let foregroundColor: Color | undefined;
113
+ if (foreground !== undefined) {
114
+ foregroundColor = Color.fromHex(foreground);
115
+ }
116
+ if (fontStyle !== undefined) {
117
+ bold = italic = underline = false;
118
+ const expression = /italic|bold|underline/g;
119
+ let match;
120
+ while ((match = expression.exec(fontStyle))) {
121
+ switch (match[0]) {
122
+ case 'bold':
123
+ bold = true;
124
+ break;
125
+ case 'italic':
126
+ italic = true;
127
+ break;
128
+ case 'underline':
129
+ underline = true;
130
+ break;
131
+ }
132
+ }
133
+ }
134
+ return new TokenStyle(foregroundColor, bold, underline, italic);
135
+ }
136
+ }
137
+
138
+ export interface SemanticTokenRule {
139
+ style: TokenStyle;
140
+ selector: TokenSelector;
141
+ }
142
+
143
+ export interface ITextMateThemingRule {
144
+ name?: string;
145
+ scope?: string | string[];
146
+ settings: ITokenColorizationSetting;
147
+ }
148
+
149
+ export type TokenStyleDefinition = SemanticTokenRule | ProbeScope[] | TokenStyleValue;
150
+ export type TokenStyleDefinitions = {
151
+ [P in keyof TokenStyleData]?: TokenStyleDefinition | undefined;
152
+ };
153
+
154
+ export type TextMateThemingRuleDefinitions = {
155
+ [P in keyof TokenStyleData]?: ITextMateThemingRule | undefined;
156
+ } & { scope?: ProbeScope };
157
+
158
+ /**
159
+ * A TokenStyle Value is either a token style literal, or a TokenClassificationString
160
+ */
161
+ export type TokenStyleValue = TokenStyle | TokenClassificationString;
162
+
163
+ export type ProbeScope = string[];
164
+
165
+ export type Matcher<T> = (matcherInput: T) => number;
166
+
167
+ export const noMatch = (_scope: ProbeScope) => -1;
168
+
169
+ export function nameMatcher(identifers: string[], scope: ProbeScope): number {
170
+ function findInIdents(s: string, lastIndent: number): number {
171
+ for (let i = lastIndent - 1; i >= 0; i--) {
172
+ if (scopesAreMatching(s, identifers[i])) {
173
+ return i;
174
+ }
175
+ }
176
+ return -1;
177
+ }
178
+ if (scope.length < identifers.length) {
179
+ return -1;
180
+ }
181
+ let lastScopeIndex = scope.length - 1;
182
+ let lastIdentifierIndex = findInIdents(scope[lastScopeIndex--], identifers.length);
183
+ if (lastIdentifierIndex >= 0) {
184
+ const score = (lastIdentifierIndex + 1) * 0x10000 + identifers[lastIdentifierIndex].length;
185
+ while (lastScopeIndex >= 0) {
186
+ lastIdentifierIndex = findInIdents(scope[lastScopeIndex--], lastIdentifierIndex);
187
+ if (lastIdentifierIndex === -1) {
188
+ return -1;
189
+ }
190
+ }
191
+ return score;
192
+ }
193
+ return -1;
194
+ }
195
+
196
+ export interface MatcherWithPriority<T> {
197
+ matcher: Matcher<T>;
198
+ priority: -1 | 0 | 1;
199
+ }
200
+
201
+ function isIdentifier(token: string | null): token is string {
202
+ return !!token && !!token.match(/[\w.:]+/);
203
+ }
204
+
205
+ function newTokenizer(input: string): { next: () => string | null } {
206
+ const regex = /([LR]:|[\w.:][\w.:-]*|[,|\-()])/g;
207
+ let match = regex.exec(input);
208
+ return {
209
+ next: () => {
210
+ if (!match) {
211
+ return null;
212
+ }
213
+ const res = match[0];
214
+ match = regex.exec(input);
215
+ return res;
216
+ },
217
+ };
218
+ }
219
+
220
+ export function createMatchers<T>(
221
+ selector: string,
222
+ matchesName: (names: string[], matcherInput: T) => number,
223
+ results: MatcherWithPriority<T>[],
224
+ ): void {
225
+ const tokenizer = newTokenizer(selector);
226
+ let token = tokenizer.next();
227
+ while (token !== null) {
228
+ let priority: -1 | 0 | 1 = 0;
229
+ if (token.length === 2 && token.charAt(1) === ':') {
230
+ switch (token.charAt(0)) {
231
+ case 'R':
232
+ priority = 1;
233
+ break;
234
+ case 'L':
235
+ priority = -1;
236
+ break;
237
+ default:
238
+ // eslint-disable-next-line no-console
239
+ console.log(`Unknown priority ${token} in scope selector`);
240
+ }
241
+ token = tokenizer.next();
242
+ }
243
+ const matcher = parseConjunction();
244
+ if (matcher) {
245
+ results.push({ matcher, priority });
246
+ }
247
+ if (token !== ',') {
248
+ break;
249
+ }
250
+ token = tokenizer.next();
251
+ }
252
+
253
+ function parseOperand(): Matcher<T> | null {
254
+ if (token === '-') {
255
+ token = tokenizer.next();
256
+ const expressionToNegate = parseOperand();
257
+ if (!expressionToNegate) {
258
+ return null;
259
+ }
260
+ return (matcherInput) => {
261
+ const score = expressionToNegate(matcherInput);
262
+ return score < 0 ? 0 : -1;
263
+ };
264
+ }
265
+ if (token === '(') {
266
+ token = tokenizer.next();
267
+ const expressionInParents = parseInnerExpression();
268
+ if (token === ')') {
269
+ token = tokenizer.next();
270
+ }
271
+ return expressionInParents;
272
+ }
273
+ if (isIdentifier(token)) {
274
+ const identifiers: string[] = [];
275
+ do {
276
+ identifiers.push(token);
277
+ token = tokenizer.next();
278
+ } while (isIdentifier(token));
279
+ return (matcherInput) => matchesName(identifiers, matcherInput);
280
+ }
281
+ return null;
282
+ }
283
+ function parseConjunction(): Matcher<T> | null {
284
+ let matcher = parseOperand();
285
+ if (!matcher) {
286
+ return null;
287
+ }
288
+
289
+ const matchers: Matcher<T>[] = [];
290
+ while (matcher) {
291
+ matchers.push(matcher);
292
+ matcher = parseOperand();
293
+ }
294
+ return (matcherInput) => {
295
+ // and
296
+ let min = matchers[0](matcherInput);
297
+ for (let i = 1; min >= 0 && i < matchers.length; i++) {
298
+ min = Math.min(min, matchers[i](matcherInput));
299
+ }
300
+ return min;
301
+ };
302
+ }
303
+ function parseInnerExpression(): Matcher<T> | null {
304
+ let matcher = parseConjunction();
305
+ if (!matcher) {
306
+ return null;
307
+ }
308
+ const matchers: Matcher<T>[] = [];
309
+ while (matcher) {
310
+ matchers.push(matcher);
311
+ if (token === '|' || token === ',') {
312
+ do {
313
+ token = tokenizer.next();
314
+ } while (token === '|' || token === ','); // ignore subsequent commas
315
+ } else {
316
+ break;
317
+ }
318
+ matcher = parseConjunction();
319
+ }
320
+ return (matcherInput) => {
321
+ // or
322
+ let max = matchers[0](matcherInput);
323
+ for (let i = 1; i < matchers.length; i++) {
324
+ max = Math.max(max, matchers[i](matcherInput));
325
+ }
326
+ return max;
327
+ };
328
+ }
329
+ }
330
+
331
+ function scopesAreMatching(thisScopeName: string, scopeName: string): boolean {
332
+ if (!thisScopeName) {
333
+ return false;
334
+ }
335
+ if (thisScopeName === scopeName) {
336
+ return true;
337
+ }
338
+ const len = scopeName.length;
339
+ return thisScopeName.length > len && thisScopeName.substr(0, len) === scopeName && thisScopeName[len] === '.';
340
+ }
341
+
342
+ export interface TokenStyleDefaults {
343
+ scopesToProbe?: ProbeScope[];
344
+ light?: TokenStyleValue;
345
+ dark?: TokenStyleValue;
346
+ hc?: TokenStyleValue;
347
+ }
348
+
349
+ export interface ISemanticTokenRegistry {
350
+ /**
351
+ * Parses a token selector from a selector string.
352
+ * @param selectorString selector string in the form (*|type)(.modifier)*
353
+ * @param language language to which the selector applies or undefined if the selector is for all language
354
+ * @returns the parsed selector
355
+ * @throws an error if the string is not a valid selector
356
+ */
357
+ parseTokenSelector(selectorString: string, language?: string): TokenSelector;
358
+
359
+ /**
360
+ * Register a TokenStyle default to the registry.
361
+ * @param selector The rule selector
362
+ * @param defaults The default values
363
+ */
364
+ registerTokenStyleDefault(selector: TokenSelector, defaults: TokenStyleDefaults): void;
365
+
366
+ /**
367
+ * Deregister a TokenStyle default to the registry.
368
+ * @param selector The rule selector
369
+ */
370
+ deregisterTokenStyleDefault(selector: TokenSelector): void;
371
+
372
+ /**
373
+ * The styling rules to used when a schema does not define any styling rules.
374
+ */
375
+ getTokenStylingDefaultRules(): SemanticTokenDefaultRule[];
376
+
377
+ /**
378
+ * Register a token type to the registry.
379
+ * @param id The TokenType id as used in theme description files
380
+ * @param description the description
381
+ */
382
+ registerTokenType(id: string, description: string, superType?: string, deprecationMessage?: string): void;
383
+
384
+ /**
385
+ * Register a token modifier to the registry.
386
+ * @param id The TokenModifier id as used in theme description files
387
+ * @param description the description
388
+ */
389
+ registerTokenModifier(id: string, description: string, deprecationMessage?: string): void;
390
+ }
391
+
392
+ export function parseClassifierString(
393
+ s: string,
394
+ defaultLanguage: string,
395
+ ): { type: string; modifiers: string[]; language: string };
396
+ export function parseClassifierString(
397
+ s: string,
398
+ defaultLanguage?: string,
399
+ ): { type: string; modifiers: string[]; language: string | undefined };
400
+ export function parseClassifierString(
401
+ s: string,
402
+ defaultLanguage: string | undefined,
403
+ ): { type: string; modifiers: string[]; language: string | undefined } {
404
+ let k = s.length;
405
+ let language: string | undefined = defaultLanguage;
406
+ const modifiers: string[] = [];
407
+
408
+ for (let i = k - 1; i >= 0; i--) {
409
+ const ch = s.charCodeAt(i);
410
+ if (ch === CHAR_LANGUAGE || ch === CHAR_MODIFIER) {
411
+ const segment = s.substring(i + 1, k);
412
+ k = i;
413
+ if (ch === CHAR_LANGUAGE) {
414
+ language = segment;
415
+ } else {
416
+ modifiers.push(segment);
417
+ }
418
+ }
419
+ }
420
+ const type = s.substring(0, k);
421
+ return { type, modifiers, language };
422
+ }
423
+
424
+ export function getStylingSchemeEntry(description?: string, deprecationMessage?: string): IJSONSchema {
425
+ return {
426
+ description,
427
+ deprecationMessage,
428
+ defaultSnippets: [{ body: '${1:#ff0000}' }],
429
+ anyOf: [
430
+ {
431
+ type: 'string',
432
+ format: 'color-hex',
433
+ },
434
+ {
435
+ $ref: '#definitions/style',
436
+ },
437
+ ],
438
+ };
439
+ }
@@ -0,0 +1,9 @@
1
+ import { IDisposable } from '@opensumi/ide-core-common';
2
+
3
+ export interface ICSSStyleService {
4
+ addClass(classname: string, style: Partial<CSSStyleDeclaration>): IDisposable;
5
+
6
+ removeClass(classname: string);
7
+ }
8
+
9
+ export const ICSSStyleService = Symbol('ICSSStyleService');