Move color to common, work with IColor

IColor is needed for the minimum contrast ratio function currently.
This commit is contained in:
Daniel Imms
2022-05-09 14:00:39 -07:00
parent 63eb9a4555
commit 0c6877f46f
19 changed files with 46 additions and 51 deletions
+8 -15
View File
@@ -3,10 +3,11 @@
* @license MIT
*/
import { css } from 'common/Color';
import { EventEmitter } from 'common/EventEmitter';
import { Disposable } from 'common/Lifecycle';
import { IDecorationService, IInternalDecoration } from 'common/services/Services';
import { IColorRGB } from 'common/Types';
import { IColor } from 'common/Types';
import { IDecorationOptions, IDecoration, IMarker, IEvent } from 'xterm';
export class DecorationService extends Disposable implements IDecorationService {
@@ -75,11 +76,11 @@ class Decoration extends Disposable implements IInternalDecoration {
public readonly onDispose = this._onDispose.event;
// TODO: React to changes on options
private _cachedBg: IColorRGB | undefined | null = null;
public get backgroundColorRGB(): IColorRGB | undefined {
private _cachedBg: IColor | undefined | null = null;
public get backgroundColorRGB(): IColor | undefined {
if (this._cachedBg === null) {
if (this.options.backgroundColor) {
this._cachedBg = toColorRGB(this.options.backgroundColor);
this._cachedBg = css.toColor(this.options.backgroundColor);
} else {
this._cachedBg = undefined;
}
@@ -88,11 +89,11 @@ class Decoration extends Disposable implements IInternalDecoration {
}
// TODO: React to changes on options
private _cachedFg: IColorRGB | undefined | null = null;
public get foregroundColorRGB(): IColorRGB | undefined {
private _cachedFg: IColor | undefined | null = null;
public get foregroundColorRGB(): IColor | undefined {
if (this._cachedFg === null) {
if (this.options.foregroundColor) {
this._cachedFg = toColorRGB(this.options.foregroundColor);
this._cachedFg = css.toColor(this.options.foregroundColor);
} else {
this._cachedFg = undefined;
}
@@ -119,11 +120,3 @@ class Decoration extends Disposable implements IInternalDecoration {
super.dispose();
}
}
function toColorRGB(css: string): IColorRGB {
// #rrggbb
if (css.length === 7) {
return [parseInt(css.slice(1, 3), 16), parseInt(css.slice(3, 5), 16), parseInt(css.slice(5, 7), 16)];
}
throw new Error('css.toColor: Unsupported css format');
}
+3 -3
View File
@@ -5,7 +5,7 @@
import { IEvent, IEventEmitter } from 'common/EventEmitter';
import { IBuffer, IBufferSet } from 'common/buffer/Types';
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, ICharset, IWindowOptions, IModes, IAttributeData, ScrollSource, IDisposable, IColorRGB } from 'common/Types';
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, ICharset, IWindowOptions, IModes, IAttributeData, ScrollSource, IDisposable, IColorRGB, IColor } from 'common/Types';
import { createDecorator } from 'common/services/ServiceRegistry';
import { IDecorationOptions, IDecoration } from 'xterm';
@@ -313,7 +313,7 @@ export interface IDecorationService extends IDisposable {
}
export interface IInternalDecoration extends IDecoration {
readonly options: IDecorationOptions;
readonly backgroundColorRGB: IColorRGB | undefined;
readonly foregroundColorRGB: IColorRGB | undefined;
readonly backgroundColorRGB: IColor | undefined;
readonly foregroundColorRGB: IColor | undefined;
readonly onRenderEmitter: IEventEmitter<HTMLElement>;
}