1 /*---------------------------------------------------------------------------------------------
2 * Copyright (c) Microsoft Corporation. All rights reserved.
3 * Licensed under the MIT License. See License.txt in the project root for license information.
4 *--------------------------------------------------------------------------------------------*/
10 export function hexDigit(charCode) {
11 if (charCode < Digit0) {
14 if (charCode <= Digit9) {
15 return charCode - Digit0;
20 if (charCode >= a && charCode <= f) {
21 return charCode - a + 10;
25 export function colorFromHex(text) {
26 if (text[0] !== '#') {
29 switch (text.length) {
32 red: (hexDigit(text.charCodeAt(1)) * 0x11) / 255.0,
33 green: (hexDigit(text.charCodeAt(2)) * 0x11) / 255.0,
34 blue: (hexDigit(text.charCodeAt(3)) * 0x11) / 255.0,
39 red: (hexDigit(text.charCodeAt(1)) * 0x11) / 255.0,
40 green: (hexDigit(text.charCodeAt(2)) * 0x11) / 255.0,
41 blue: (hexDigit(text.charCodeAt(3)) * 0x11) / 255.0,
42 alpha: (hexDigit(text.charCodeAt(4)) * 0x11) / 255.0,
46 red: (hexDigit(text.charCodeAt(1)) * 0x10 + hexDigit(text.charCodeAt(2))) / 255.0,
47 green: (hexDigit(text.charCodeAt(3)) * 0x10 + hexDigit(text.charCodeAt(4))) / 255.0,
48 blue: (hexDigit(text.charCodeAt(5)) * 0x10 + hexDigit(text.charCodeAt(6))) / 255.0,
53 red: (hexDigit(text.charCodeAt(1)) * 0x10 + hexDigit(text.charCodeAt(2))) / 255.0,
54 green: (hexDigit(text.charCodeAt(3)) * 0x10 + hexDigit(text.charCodeAt(4))) / 255.0,
55 blue: (hexDigit(text.charCodeAt(5)) * 0x10 + hexDigit(text.charCodeAt(6))) / 255.0,
56 alpha: (hexDigit(text.charCodeAt(7)) * 0x10 + hexDigit(text.charCodeAt(8))) / 255.0
61 export function colorFrom256RGB(red, green, blue, alpha) {
62 if (alpha === void 0) { alpha = 1.0; }