1 | import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
2 | import * as namedColors from 'css-color-names';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export var R50 = '#FFEBE6';
|
12 | export var R75 = '#FFBDAD';
|
13 | export var R100 = '#FF8F73';
|
14 | export var R300 = '#FF5630';
|
15 | export var R400 = '#DE350B';
|
16 | export var R500 = '#BF2600';
|
17 | export var Y50 = '#FFFAE6';
|
18 | export var Y75 = '#FFF0B3';
|
19 | export var Y200 = '#FFC400';
|
20 | export var Y400 = '#FF991F';
|
21 | export var Y500 = '#FF8B00';
|
22 | export var G50 = '#E3FCEF';
|
23 | export var G75 = '#ABF5D1';
|
24 | export var G200 = '#57D9A3';
|
25 | export var G300 = '#36B37E';
|
26 | export var G400 = '#00875A';
|
27 | export var G500 = '#006644';
|
28 | export var B50 = '#DEEBFF';
|
29 | export var B75 = '#B3D4FF';
|
30 | export var B100 = '#4C9AFF';
|
31 | export var B400 = '#0052CC';
|
32 | export var B500 = '#0747A6';
|
33 | export var N0 = '#FFFFFF';
|
34 | export var N20 = '#F4F5F7';
|
35 | export var N30 = '#EBECF0';
|
36 | export var N40 = '#DFE1E6';
|
37 | export var N50 = '#C1C7D0';
|
38 | export var N60 = '#B3BAC5';
|
39 | export var N80 = '#97A0AF';
|
40 | export var N90 = '#8993A4';
|
41 | export var N200 = '#6B778C';
|
42 | export var N300 = '#5E6C84';
|
43 | export var N300A = '#091E4224';
|
44 | export var N500 = '#42526E';
|
45 | export var N600 = '#758195';
|
46 | export var N800 = '#172B4D';
|
47 | export var N1000 = '#172B4D';
|
48 | export var P50 = '#EAE6FF';
|
49 | export var P75 = '#C0B6F2';
|
50 | export var P100 = '#998DD9';
|
51 | export var P300 = '#6554C0';
|
52 | export var P400 = '#5243AA';
|
53 | export var P500 = '#403294';
|
54 | export var T50 = '#E6FCFF';
|
55 | export var T75 = '#B3F5FF';
|
56 | export var T100 = '#79E2F2';
|
57 | export var T300 = '#00B8D9';
|
58 | export var T500 = '#008DA6';
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | export function normalizeHexColor(color, defaultColor) {
|
64 | if (!color) {
|
65 | return null;
|
66 | }
|
67 |
|
68 |
|
69 | color = color.trim().toLowerCase();
|
70 | if (isHex(color)) {
|
71 |
|
72 | if (color.length === 4) {
|
73 | color = color.split('').map(function (c) {
|
74 | return c === '#' ? '#' : "".concat(c).concat(c);
|
75 | }).join('');
|
76 | }
|
77 | } else if (isRgb(color)) {
|
78 | return rgbToHex(color);
|
79 | } else {
|
80 |
|
81 | if (color === 'default') {
|
82 | return null;
|
83 | } else if (namedColors.default && namedColors.default[color]) {
|
84 | color = namedColors.default[color];
|
85 | } else if (namedColors && namedColors[color]) {
|
86 | color = namedColors[color];
|
87 | } else {
|
88 | return null;
|
89 | }
|
90 | }
|
91 | if (color === defaultColor) {
|
92 | return null;
|
93 | }
|
94 | return color;
|
95 | }
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | export function hexToRgb(color) {
|
104 | if (!isHex(color)) {
|
105 | return null;
|
106 | }
|
107 | var colorBits = color.substring(1).split('');
|
108 | if (colorBits.length === 3) {
|
109 | colorBits = [colorBits[0], colorBits[0], colorBits[1], colorBits[1], colorBits[2], colorBits[2]];
|
110 | }
|
111 | var rgb = Number("0x".concat(colorBits.join('')));
|
112 |
|
113 | return "rgb(".concat(rgb >> 16 & 255, ",").concat(rgb >> 8 & 255, ",").concat(rgb & 255, ")");
|
114 | }
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | export function hexToRgba(rawColor, alpha) {
|
122 | var color = normalizeHexColor(rawColor);
|
123 | if (!color) {
|
124 | return null;
|
125 | }
|
126 | var hex2rgb = function hex2rgb(color) {
|
127 | return color.match(/[a-z0-9]{2}/gi).map(function (hex) {
|
128 | return parseInt(hex, 16);
|
129 | });
|
130 | };
|
131 | return "rgba(".concat(hex2rgb(color).concat(alpha).join(','), ")");
|
132 | }
|
133 | export function rgbToHex(value) {
|
134 | var matches = value.match(/(0?\.?\d{1,3})%?\b/g);
|
135 | if (matches && matches.length >= 3) {
|
136 | var _matches$map = matches.map(Number),
|
137 | _matches$map2 = _slicedToArray(_matches$map, 3),
|
138 | red = _matches$map2[0],
|
139 | green = _matches$map2[1],
|
140 | blue = _matches$map2[2];
|
141 | return '#' + (blue | green << 8 | red << 16 | 1 << 24).toString(16).slice(1)
|
142 | ;
|
143 | }
|
144 |
|
145 | return null;
|
146 | }
|
147 | export function isRgb(color) {
|
148 | return /rgba?\(/.test(color);
|
149 | }
|
150 | export function isHex(color) {
|
151 | return /^#([A-Fa-f0-9]{3}){1,2}$/.test(color);
|
152 | } |
\ | No newline at end of file |