UNPKG

2.18 kBPlain TextView Raw
1// *****************************************************************************
2// Copyright (C) 2019 TypeFox and others.
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License v. 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0.
7//
8// This Source Code may also be made available under the following Secondary
9// Licenses when the conditions for such availability set forth in the Eclipse
10// Public License v. 2.0 are satisfied: GNU General Public License, version 2
11// with the GNU Classpath Exception which is available at
12// https://www.gnu.org/software/classpath/license.html.
13//
14// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15// *****************************************************************************
16
17import { injectable } from 'inversify';
18import { DisposableCollection, Disposable } from '../common/disposable';
19import { Emitter } from '../common/event';
20import { ColorDefinition, ColorCssVariable } from '../common/color';
21
22@injectable()
23export class ColorRegistry {
24
25 protected readonly onDidChangeEmitter = new Emitter<void>();
26 readonly onDidChange = this.onDidChangeEmitter.event;
27 protected fireDidChange(): void {
28 this.onDidChangeEmitter.fire(undefined);
29 }
30
31 *getColors(): IterableIterator<string> { }
32
33 getCurrentCssVariable(id: string): ColorCssVariable | undefined {
34 const value = this.getCurrentColor(id);
35 if (!value) {
36 return undefined;
37 }
38 const name = this.toCssVariableName(id);
39 return { name, value };
40 }
41
42 toCssVariableName(id: string, prefix = 'theia'): string {
43 return `--${prefix}-${id.replace(/\./g, '-')}`;
44 }
45
46 getCurrentColor(id: string): string | undefined {
47 return undefined;
48 }
49
50 register(...definitions: ColorDefinition[]): Disposable {
51 const result = new DisposableCollection(...definitions.map(definition => this.doRegister(definition)));
52 this.fireDidChange();
53 return result;
54 }
55
56 protected doRegister(definition: ColorDefinition): Disposable {
57 return Disposable.NULL;
58 }
59
60}