UNPKG

4.07 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// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.StylingService = exports.StylingParticipant = void 0;
19const tslib_1 = require("tslib");
20const inversify_1 = require("inversify");
21const contribution_provider_1 = require("../common/contribution-provider");
22const color_registry_1 = require("./color-registry");
23const decoration_style_1 = require("./decoration-style");
24const theming_1 = require("./theming");
25const secondary_window_handler_1 = require("./secondary-window-handler");
26exports.StylingParticipant = Symbol('StylingParticipant');
27let StylingService = class StylingService {
28 constructor() {
29 this.cssElements = new Map();
30 }
31 onStart() {
32 this.registerWindow(window);
33 this.secondaryWindowHandler.onWillAddWidget(([widget, window]) => {
34 this.registerWindow(window);
35 });
36 this.secondaryWindowHandler.onWillRemoveWidget(([widget, window]) => {
37 this.cssElements.delete(window);
38 });
39 this.themeService.onDidColorThemeChange(e => this.applyStylingToWindows(e.newTheme));
40 }
41 registerWindow(win) {
42 const cssElement = decoration_style_1.DecorationStyle.createStyleElement('contributedColorTheme', win.document.head);
43 this.cssElements.set(win, cssElement);
44 this.applyStyling(this.themeService.getCurrentTheme(), cssElement);
45 }
46 applyStylingToWindows(theme) {
47 this.cssElements.forEach(cssElement => this.applyStyling(theme, cssElement));
48 }
49 applyStyling(theme, cssElement) {
50 const rules = [];
51 const colorTheme = {
52 type: theme.type,
53 label: theme.label,
54 getColor: color => this.colorRegistry.getCurrentColor(color)
55 };
56 const styleCollector = {
57 addRule: rule => rules.push(rule)
58 };
59 for (const themingParticipant of this.themingParticipants.getContributions()) {
60 themingParticipant.registerThemeStyle(colorTheme, styleCollector);
61 }
62 const fullCss = rules.join('\n');
63 cssElement.innerText = fullCss;
64 }
65};
66(0, tslib_1.__decorate)([
67 (0, inversify_1.inject)(theming_1.ThemeService),
68 (0, tslib_1.__metadata)("design:type", theming_1.ThemeService)
69], StylingService.prototype, "themeService", void 0);
70(0, tslib_1.__decorate)([
71 (0, inversify_1.inject)(color_registry_1.ColorRegistry),
72 (0, tslib_1.__metadata)("design:type", color_registry_1.ColorRegistry)
73], StylingService.prototype, "colorRegistry", void 0);
74(0, tslib_1.__decorate)([
75 (0, inversify_1.inject)(contribution_provider_1.ContributionProvider),
76 (0, inversify_1.named)(exports.StylingParticipant),
77 (0, tslib_1.__metadata)("design:type", Object)
78], StylingService.prototype, "themingParticipants", void 0);
79(0, tslib_1.__decorate)([
80 (0, inversify_1.inject)(secondary_window_handler_1.SecondaryWindowHandler),
81 (0, tslib_1.__metadata)("design:type", secondary_window_handler_1.SecondaryWindowHandler)
82], StylingService.prototype, "secondaryWindowHandler", void 0);
83StylingService = (0, tslib_1.__decorate)([
84 (0, inversify_1.injectable)()
85], StylingService);
86exports.StylingService = StylingService;
87//# sourceMappingURL=styling-service.js.map
\No newline at end of file