mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
Add fromHSLA and fromHex methods to API
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { Color as CommonColor, HSLA } from 'vs/base/common/color';
|
||||
import { illegalArgument } from 'vs/base/common/errors';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
@@ -1016,10 +1017,10 @@ export class DocumentLink {
|
||||
}
|
||||
|
||||
export class Color {
|
||||
red: number;
|
||||
green: number;
|
||||
blue: number;
|
||||
alpha: number;
|
||||
readonly red: number;
|
||||
readonly green: number;
|
||||
readonly blue: number;
|
||||
readonly alpha: number;
|
||||
|
||||
constructor(red: number, green: number, blue: number, alpha?: number) {
|
||||
this.red = red;
|
||||
@@ -1027,6 +1028,19 @@ export class Color {
|
||||
this.blue = blue;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
static fromHSLA(hue: number, saturation: number, luminosity: number, alpha?: number): Color {
|
||||
if (!alpha) {
|
||||
alpha = 1;
|
||||
}
|
||||
const color = CommonColor.fromHSLA(new HSLA(hue, saturation, luminosity, alpha)).toRGBA();
|
||||
return new Color(color.r, color.g, color.b, color.a / 255);
|
||||
}
|
||||
|
||||
static fromHex(hex: string): Color {
|
||||
const color = CommonColor.fromHex(hex).toRGBA();
|
||||
return new Color(color.r, color.g, color.b, color.a / 255);
|
||||
}
|
||||
}
|
||||
|
||||
export class ColorInfo {
|
||||
|
||||
Reference in New Issue
Block a user