UNPKG

4.2 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2022 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17var __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};
23var __metadata = (this && this.__metadata) || function (k, v) {
24 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27exports.StylingService = exports.StylingParticipant = void 0;
28const inversify_1 = require("inversify");
29const contribution_provider_1 = require("../common/contribution-provider");
30const color_registry_1 = require("./color-registry");
31const decoration_style_1 = require("./decoration-style");
32const theming_1 = require("./theming");
33const common_1 = require("../common");
34exports.StylingParticipant = Symbol('StylingParticipant');
35let 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);
82StylingService = __decorate([
83 (0, inversify_1.injectable)()
84], StylingService);
85exports.StylingService = StylingService;
86//# sourceMappingURL=styling-service.js.map
\No newline at end of file