UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

79 lines • 3.41 kB
// ***************************************************************************** // Copyright (C) 2022 TypeFox and others. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: GNU General Public License, version 2 // with the GNU Classpath Exception which is available at // https://www.gnu.org/software/classpath/license.html. // // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** import { __decorate } from "tslib"; import { inject, injectable, named } from 'inversify'; import { ContributionProvider } from '../common/contribution-provider.js'; import { ColorRegistry } from './color-registry.js'; import { DecorationStyle } from './decoration-style.js'; import { ThemeService } from './theming.js'; import { SecondaryWindowService } from './window/secondary-window-service.js'; export const StylingParticipant = Symbol('StylingParticipant'); let StylingService = class StylingService { constructor() { this.cssElements = new Map(); } onStart() { this.registerWindow(window); // registered per window rather than per widget, as a window may contain several widgets this.secondaryWindowService.onWindowLoaded(win => this.registerWindow(win)); this.secondaryWindowService.onWindowClosed(window => { this.cssElements.delete(window); }); this.themeService.onDidColorThemeChange(e => this.applyStylingToWindows(e.newTheme)); } registerWindow(win) { const cssElement = DecorationStyle.createStyleElement('contributedColorTheme', win.document.head); this.cssElements.set(win, cssElement); this.applyStyling(this.themeService.getCurrentTheme(), cssElement); } applyStylingToWindows(theme) { this.cssElements.forEach(cssElement => this.applyStyling(theme, cssElement)); } applyStyling(theme, cssElement) { const rules = []; const colorTheme = { type: theme.type, label: theme.label, getColor: color => this.colorRegistry.getCurrentColor(color) }; const styleCollector = { addRule: rule => rules.push(rule) }; for (const themingParticipant of this.themingParticipants.getContributions()) { themingParticipant.registerThemeStyle(colorTheme, styleCollector); } const fullCss = rules.join('\n'); cssElement.innerText = fullCss; } }; __decorate([ inject(ThemeService) ], StylingService.prototype, "themeService", void 0); __decorate([ inject(ColorRegistry) ], StylingService.prototype, "colorRegistry", void 0); __decorate([ inject(ContributionProvider), named(StylingParticipant) ], StylingService.prototype, "themingParticipants", void 0); __decorate([ inject(SecondaryWindowService) ], StylingService.prototype, "secondaryWindowService", void 0); StylingService = __decorate([ injectable() ], StylingService); export { StylingService }; //# sourceMappingURL=styling-service.js.map