1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
18 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
19 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
20 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
21 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
22 | };
|
23 | var __metadata = (this && this.__metadata) || function (k, v) {
|
24 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
25 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | exports.StylingService = exports.StylingParticipant = void 0;
|
28 | const inversify_1 = require("inversify");
|
29 | const contribution_provider_1 = require("../common/contribution-provider");
|
30 | const color_registry_1 = require("./color-registry");
|
31 | const decoration_style_1 = require("./decoration-style");
|
32 | const theming_1 = require("./theming");
|
33 | const common_1 = require("../common");
|
34 | exports.StylingParticipant = Symbol('StylingParticipant');
|
35 | let StylingService = class StylingService {
|
36 | constructor() {
|
37 | this.cssElements = new Map();
|
38 | }
|
39 | onStart() {
|
40 | this.registerWindow(window);
|
41 | this.themeService.onDidColorThemeChange(e => this.applyStylingToWindows(e.newTheme));
|
42 | }
|
43 | registerWindow(win) {
|
44 | const cssElement = decoration_style_1.DecorationStyle.createStyleElement('contributedColorTheme', win.document.head);
|
45 | this.cssElements.set(win, cssElement);
|
46 | this.applyStyling(this.themeService.getCurrentTheme(), cssElement);
|
47 | return common_1.Disposable.create(() => this.cssElements.delete(win));
|
48 | }
|
49 | applyStylingToWindows(theme) {
|
50 | this.cssElements.forEach(cssElement => this.applyStyling(theme, cssElement));
|
51 | }
|
52 | applyStyling(theme, cssElement) {
|
53 | const rules = [];
|
54 | const colorTheme = {
|
55 | type: theme.type,
|
56 | label: theme.label,
|
57 | getColor: color => this.colorRegistry.getCurrentColor(color)
|
58 | };
|
59 | const styleCollector = {
|
60 | addRule: rule => rules.push(rule)
|
61 | };
|
62 | for (const themingParticipant of this.themingParticipants.getContributions()) {
|
63 | themingParticipant.registerThemeStyle(colorTheme, styleCollector);
|
64 | }
|
65 | const fullCss = rules.join('\n');
|
66 | cssElement.innerText = fullCss;
|
67 | }
|
68 | };
|
69 | __decorate([
|
70 | (0, inversify_1.inject)(theming_1.ThemeService),
|
71 | __metadata("design:type", theming_1.ThemeService)
|
72 | ], StylingService.prototype, "themeService", void 0);
|
73 | __decorate([
|
74 | (0, inversify_1.inject)(color_registry_1.ColorRegistry),
|
75 | __metadata("design:type", color_registry_1.ColorRegistry)
|
76 | ], StylingService.prototype, "colorRegistry", void 0);
|
77 | __decorate([
|
78 | (0, inversify_1.inject)(contribution_provider_1.ContributionProvider),
|
79 | (0, inversify_1.named)(exports.StylingParticipant),
|
80 | __metadata("design:type", Object)
|
81 | ], StylingService.prototype, "themingParticipants", void 0);
|
82 | StylingService = __decorate([
|
83 | (0, inversify_1.injectable)()
|
84 | ], StylingService);
|
85 | exports.StylingService = StylingService;
|
86 |
|
\ | No newline at end of file |