massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-json / node_modules / vscode-json-languageservice / lib / esm / utils / colors.js
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  *--------------------------------------------------------------------------------------------*/
5 var Digit0 = 48;
6 var Digit9 = 57;
7 var A = 65;
8 var a = 97;
9 var f = 102;
10 export function hexDigit(charCode) {
11     if (charCode < Digit0) {
12         return 0;
13     }
14     if (charCode <= Digit9) {
15         return charCode - Digit0;
16     }
17     if (charCode < a) {
18         charCode += (a - A);
19     }
20     if (charCode >= a && charCode <= f) {
21         return charCode - a + 10;
22     }
23     return 0;
24 }
25 export function colorFromHex(text) {
26     if (text[0] !== '#') {
27         return undefined;
28     }
29     switch (text.length) {
30         case 4:
31             return {
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,
35                 alpha: 1
36             };
37         case 5:
38             return {
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,
43             };
44         case 7:
45             return {
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,
49                 alpha: 1
50             };
51         case 9:
52             return {
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
57             };
58     }
59     return undefined;
60 }
61 export function colorFrom256RGB(red, green, blue, alpha) {
62     if (alpha === void 0) { alpha = 1.0; }
63     return {
64         red: red / 255.0,
65         green: green / 255.0,
66         blue: blue / 255.0,
67         alpha: alpha
68     };
69 }