analogger 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ana-logger.d.cts +6 -1
- package/browser/ana-logger.mjs +154 -4
- package/browser/html-to-image.js +2 -2
- package/cli.cjs +1 -1
- package/dist/ana-light.min.css +1 -1
- package/dist/analogger-browser.min.mjs +8 -8
- package/dist/analogger.min.css +1 -1
- package/dist/html-to-image-plugin.min.mjs +8 -8
- package/esm/ana-logger.mjs +154 -4
- package/package.json +1 -1
- package/src/ana-logger.cjs +154 -4
- package/src/constants.cjs +50 -50
- package/src/html-to-image.js +2 -2
- package/browser/ana-logger.d.mts +0 -488
- package/browser/constants.d.mts +0 -19
- package/browser/imported/flatted/esm/index.d.mts +0 -4
- package/browser/imported/to-ansi/index.d.mts +0 -144
- package/browser/src/ana-logger.mjs +0 -2675
- package/browser/src/constants.mjs +0 -56
- package/esm/browser/ana-logger.mjs +0 -2660
- package/esm/browser/constants.mjs +0 -56
- package/esm/browser/imported/flatted/esm/index.mjs +0 -94
- package/esm/browser/imported/to-ansi/index.mjs +0 -682
- package/esm/html-to-image.mjs +0 -31
- package/esm/src/ana-logger.mjs +0 -2688
- package/esm/src/constants.mjs +0 -56
|
@@ -1,682 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NOT EDIT THIS FILE DIRECTLY.
|
|
3
|
-
* This file is generated following the conversion of
|
|
4
|
-
* [./index.cjs]{@link ./index.cjs}
|
|
5
|
-
*
|
|
6
|
-
**/
|
|
7
|
-
/**
|
|
8
|
-
* Colorizer for terminals
|
|
9
|
-
* @author Patrice Thimothee
|
|
10
|
-
* @licence MIT
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
// ----------------------------------------
|
|
14
|
-
// Types
|
|
15
|
-
// ----------------------------------------
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {Object} RGBType
|
|
18
|
-
* @property {number} red
|
|
19
|
-
* @property {number} green
|
|
20
|
-
* @property {number} blue
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @typedef {Object} HSLType
|
|
25
|
-
* @property {number} hue
|
|
26
|
-
* @property {number} lightness
|
|
27
|
-
* @property {number} saturation
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Return colorized text based on given value
|
|
32
|
-
* @typedef {Object} ColorPropType
|
|
33
|
-
* @property {string|RGBType|HSLType} [fg] colourName Actual name color (i.e. orange, yellow), color code (#00F00F), or
|
|
34
|
-
* color object
|
|
35
|
-
* (rgb, hsl)
|
|
36
|
-
* @property {string|RGBType|HSLType} [bg] colourName Actual name color (i.e. orange, yellow) or color code (#00F00F)
|
|
37
|
-
* @property {boolean|null} [isUnderline]
|
|
38
|
-
* @property {boolean|null} [isBold]
|
|
39
|
-
* @property {boolean|null} [isReversed]
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
// ----------------------------------------
|
|
43
|
-
// Constants
|
|
44
|
-
// ----------------------------------------
|
|
45
|
-
const COLOR_TYPE = {
|
|
46
|
-
Foreground: 38,
|
|
47
|
-
Background: 48,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const backward = "\u001b[1D"
|
|
51
|
-
export const RESET = "\x1b[0m" + backward;
|
|
52
|
-
|
|
53
|
-
export const FONT_STYLE = {
|
|
54
|
-
Bold : "\x1b[1m" + backward,
|
|
55
|
-
Underline: "\x1b[4m" + backward,
|
|
56
|
-
Reversed : "\x1b[7m" + backward,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const STYLE = {
|
|
60
|
-
Bold : "\x1b[1m" + backward,
|
|
61
|
-
Underline: "\x1b[4m" + backward,
|
|
62
|
-
Reversed : "\x1b[7m" + backward,
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const colors = {
|
|
66
|
-
"aliceblue" : "#f0f8ff",
|
|
67
|
-
"antiquewhite" : "#faebd7",
|
|
68
|
-
"aqua" : "#00ffff",
|
|
69
|
-
"aquamarine" : "#7fffd4",
|
|
70
|
-
"azure" : "#f0ffff",
|
|
71
|
-
"beige" : "#f5f5dc",
|
|
72
|
-
"bisque" : "#ffe4c4",
|
|
73
|
-
"black" : "#000000",
|
|
74
|
-
"blanchedalmond" : "#ffebcd",
|
|
75
|
-
"blue" : "#0000ff",
|
|
76
|
-
"blueviolet" : "#8a2be2",
|
|
77
|
-
"brown" : "#a52a2a",
|
|
78
|
-
"burlywood" : "#deb887",
|
|
79
|
-
"cadetblue" : "#5f9ea0",
|
|
80
|
-
"chartreuse" : "#7fff00",
|
|
81
|
-
"chocolate" : "#d2691e",
|
|
82
|
-
"coral" : "#ff7f50",
|
|
83
|
-
"cornflowerblue" : "#6495ed",
|
|
84
|
-
"cornsilk" : "#fff8dc",
|
|
85
|
-
"crimson" : "#dc143c",
|
|
86
|
-
"cyan" : "#00ffff",
|
|
87
|
-
"darkblue" : "#00008b",
|
|
88
|
-
"darkcyan" : "#008b8b",
|
|
89
|
-
"darkgoldenrod" : "#b8860b",
|
|
90
|
-
"darkgray" : "#a9a9a9",
|
|
91
|
-
"darkgreen" : "#006400",
|
|
92
|
-
"darkkhaki" : "#bdb76b",
|
|
93
|
-
"darkmagenta" : "#8b008b",
|
|
94
|
-
"darkolivegreen" : "#556b2f",
|
|
95
|
-
"darkorange" : "#ff8c00",
|
|
96
|
-
"darkorchid" : "#9932cc",
|
|
97
|
-
"darkred" : "#8b0000",
|
|
98
|
-
"darksalmon" : "#e9967a",
|
|
99
|
-
"darkseagreen" : "#8fbc8f",
|
|
100
|
-
"darkslateblue" : "#483d8b",
|
|
101
|
-
"darkslategray" : "#2f4f4f",
|
|
102
|
-
"darkturquoise" : "#00ced1",
|
|
103
|
-
"darkviolet" : "#9400d3",
|
|
104
|
-
"deeppink" : "#ff1493",
|
|
105
|
-
"deepskyblue" : "#00bfff",
|
|
106
|
-
"dimgray" : "#696969",
|
|
107
|
-
"dodgerblue" : "#1e90ff",
|
|
108
|
-
"firebrick" : "#b22222",
|
|
109
|
-
"floralwhite" : "#fffaf0",
|
|
110
|
-
"forestgreen" : "#228b22",
|
|
111
|
-
"fuchsia" : "#ff00ff",
|
|
112
|
-
"gainsboro" : "#dcdcdc",
|
|
113
|
-
"ghostwhite" : "#f8f8ff",
|
|
114
|
-
"gold" : "#ffd700",
|
|
115
|
-
"goldenrod" : "#daa520",
|
|
116
|
-
"gray" : "#808080",
|
|
117
|
-
"green" : "#008000",
|
|
118
|
-
"greenyellow" : "#adff2f",
|
|
119
|
-
"honeydew" : "#f0fff0",
|
|
120
|
-
"hotpink" : "#ff69b4",
|
|
121
|
-
"indianred " : "#cd5c5c",
|
|
122
|
-
"indigo" : "#4b0082",
|
|
123
|
-
"ivory" : "#fffff0",
|
|
124
|
-
"khaki" : "#f0e68c",
|
|
125
|
-
"lavender" : "#e6e6fa",
|
|
126
|
-
"lavenderblush" : "#fff0f5",
|
|
127
|
-
"lawngreen" : "#7cfc00",
|
|
128
|
-
"lemonchiffon" : "#fffacd",
|
|
129
|
-
"lightblue" : "#add8e6",
|
|
130
|
-
"lightcoral" : "#f08080",
|
|
131
|
-
"lightcyan" : "#e0ffff",
|
|
132
|
-
"lightgoldenrodyellow": "#fafad2",
|
|
133
|
-
"lightgrey" : "#d3d3d3",
|
|
134
|
-
"lightgreen" : "#90ee90",
|
|
135
|
-
"lightpink" : "#ffb6c1",
|
|
136
|
-
"lightsalmon" : "#ffa07a",
|
|
137
|
-
"lightseagreen" : "#20b2aa",
|
|
138
|
-
"lightskyblue" : "#87cefa",
|
|
139
|
-
"lightslategray" : "#778899",
|
|
140
|
-
"lightsteelblue" : "#b0c4de",
|
|
141
|
-
"lightyellow" : "#ffffe0",
|
|
142
|
-
"lime" : "#00ff00",
|
|
143
|
-
"limegreen" : "#32cd32",
|
|
144
|
-
"linen" : "#faf0e6",
|
|
145
|
-
"magenta" : "#ff00ff",
|
|
146
|
-
"maroon" : "#800000",
|
|
147
|
-
"mediumaquamarine" : "#66cdaa",
|
|
148
|
-
"mediumblue" : "#0000cd",
|
|
149
|
-
"mediumorchid" : "#ba55d3",
|
|
150
|
-
"mediumpurple" : "#9370d8",
|
|
151
|
-
"mediumseagreen" : "#3cb371",
|
|
152
|
-
"mediumslateblue" : "#7b68ee",
|
|
153
|
-
"mediumspringgreen" : "#00fa9a",
|
|
154
|
-
"mediumturquoise" : "#48d1cc",
|
|
155
|
-
"mediumvioletred" : "#c71585",
|
|
156
|
-
"midnightblue" : "#191970",
|
|
157
|
-
"mintcream" : "#f5fffa",
|
|
158
|
-
"mistyrose" : "#ffe4e1",
|
|
159
|
-
"moccasin" : "#ffe4b5",
|
|
160
|
-
"navajowhite" : "#ffdead",
|
|
161
|
-
"navy" : "#000080",
|
|
162
|
-
"oldlace" : "#fdf5e6",
|
|
163
|
-
"olive" : "#808000",
|
|
164
|
-
"olivedrab" : "#6b8e23",
|
|
165
|
-
"orange" : "#ffa500",
|
|
166
|
-
"orangered" : "#ff4500",
|
|
167
|
-
"orchid" : "#da70d6",
|
|
168
|
-
"palegoldenrod" : "#eee8aa",
|
|
169
|
-
"palegreen" : "#98fb98",
|
|
170
|
-
"paleturquoise" : "#afeeee",
|
|
171
|
-
"palevioletred" : "#d87093",
|
|
172
|
-
"papayawhip" : "#ffefd5",
|
|
173
|
-
"peachpuff" : "#ffdab9",
|
|
174
|
-
"peru" : "#cd853f",
|
|
175
|
-
"pink" : "#ffc0cb",
|
|
176
|
-
"plum" : "#dda0dd",
|
|
177
|
-
"powderblue" : "#b0e0e6",
|
|
178
|
-
"purple" : "#800080",
|
|
179
|
-
"rebeccapurple" : "#663399",
|
|
180
|
-
"red" : "#ff0000",
|
|
181
|
-
"rosybrown" : "#bc8f8f",
|
|
182
|
-
"royalblue" : "#4169e1",
|
|
183
|
-
"saddlebrown" : "#8b4513",
|
|
184
|
-
"salmon" : "#fa8072",
|
|
185
|
-
"sandybrown" : "#f4a460",
|
|
186
|
-
"seagreen" : "#2e8b57",
|
|
187
|
-
"seashell" : "#fff5ee",
|
|
188
|
-
"sienna" : "#a0522d",
|
|
189
|
-
"silver" : "#c0c0c0",
|
|
190
|
-
"skyblue" : "#87ceeb",
|
|
191
|
-
"slateblue" : "#6a5acd",
|
|
192
|
-
"slategray" : "#708090",
|
|
193
|
-
"snow" : "#fffafa",
|
|
194
|
-
"springgreen" : "#00ff7f",
|
|
195
|
-
"steelblue" : "#4682b4",
|
|
196
|
-
"tan" : "#d2b48c",
|
|
197
|
-
"teal" : "#008080",
|
|
198
|
-
"thistle" : "#d8bfd8",
|
|
199
|
-
"tomato" : "#ff6347",
|
|
200
|
-
"turquoise" : "#40e0d0",
|
|
201
|
-
"violet" : "#ee82ee",
|
|
202
|
-
"wheat" : "#f5deb3",
|
|
203
|
-
"white" : "#ffffff",
|
|
204
|
-
"whitesmoke" : "#f5f5f5",
|
|
205
|
-
"yellow" : "#ffff00",
|
|
206
|
-
"yellowgreen" : "#9acd32"
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
// ----------------------------------------
|
|
210
|
-
// Functions
|
|
211
|
-
// ----------------------------------------
|
|
212
|
-
/**
|
|
213
|
-
* Returns whether a color name is supported
|
|
214
|
-
* @param colourName
|
|
215
|
-
* @returns {boolean}
|
|
216
|
-
*/
|
|
217
|
-
function isLiteralColor(colourName)
|
|
218
|
-
{
|
|
219
|
-
return !!colors[colourName]
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* @see [Code and original author]
|
|
224
|
-
* {@link https://stackoverflow.com/questions/15682537/ansi-color-specific-rgb-sequence-bash}
|
|
225
|
-
* @param {number} red
|
|
226
|
-
* @param {number} green
|
|
227
|
-
* @param {number} blue
|
|
228
|
-
* @returns {number}
|
|
229
|
-
*/
|
|
230
|
-
export const rgbToAnsi256 = (red, green, blue) =>
|
|
231
|
-
{
|
|
232
|
-
if (red === green && green === blue)
|
|
233
|
-
{
|
|
234
|
-
if (red < 8)
|
|
235
|
-
{
|
|
236
|
-
return 16;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (red > 248)
|
|
240
|
-
{
|
|
241
|
-
return 231;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return Math.round(((red - 8) / 247) * 24) + 232;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return 16
|
|
248
|
-
+ (36 * Math.round(red / 255 * 5))
|
|
249
|
-
+ (6 * Math.round(green / 255 * 5))
|
|
250
|
-
+ Math.round(blue / 255 * 5);
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* @see [Code and original author]
|
|
255
|
-
* {@link https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb/5624139#5624139}
|
|
256
|
-
* @param hex
|
|
257
|
-
* @returns {{red: number, green: number, blue: number}|null}
|
|
258
|
-
*/
|
|
259
|
-
export const hexToRgb = (hex) =>
|
|
260
|
-
{
|
|
261
|
-
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
262
|
-
hex = hex.replace(shorthandRegex, function (m, r, g, b)
|
|
263
|
-
{
|
|
264
|
-
return r + r + g + g + b + b;
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
268
|
-
return result ? {
|
|
269
|
-
red : parseInt(result[1], 16),
|
|
270
|
-
blue : parseInt(result[2], 16),
|
|
271
|
-
green: parseInt(result[3], 16)
|
|
272
|
-
} : {};
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* @see [Code and original author {@link https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb]
|
|
277
|
-
* @param red
|
|
278
|
-
* @param green
|
|
279
|
-
* @param blue
|
|
280
|
-
* @returns {string}
|
|
281
|
-
*/
|
|
282
|
-
export const rgbToHex = function ({red, green, blue})
|
|
283
|
-
{
|
|
284
|
-
const rgb = (red << 16) | (green << 8) | (blue << 0);
|
|
285
|
-
return '#' + (0x1000000 + rgb).toString(16).slice(1);
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
export const rgbStringToRgb = function (rgbString)
|
|
289
|
-
{
|
|
290
|
-
const matches = rgbString.matchAll(/\d+/g);
|
|
291
|
-
const rgbArray = [];
|
|
292
|
-
for (const match of matches)
|
|
293
|
-
{
|
|
294
|
-
const color = parseInt(match[0]);
|
|
295
|
-
if (color > 255)
|
|
296
|
-
{
|
|
297
|
-
return null;
|
|
298
|
-
}
|
|
299
|
-
rgbArray.push(color);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (rgbArray.length !== 3)
|
|
303
|
-
{
|
|
304
|
-
return null;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return {red: rgbArray[0], green: rgbArray[1], blue: rgbArray[2]}
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
export const rgbStringToHex = function (rgbString)
|
|
311
|
-
{
|
|
312
|
-
const rgb = rgbStringToRgb(rgbString);
|
|
313
|
-
if (!rgb)
|
|
314
|
-
{
|
|
315
|
-
return rgb;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return rgbToHex(rgb);
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
export const hue2rgb = function hue2rgb(p, q, t)
|
|
322
|
-
{
|
|
323
|
-
if (t < 0)
|
|
324
|
-
{
|
|
325
|
-
t += 1;
|
|
326
|
-
}
|
|
327
|
-
if (t > 1)
|
|
328
|
-
{
|
|
329
|
-
t -= 1;
|
|
330
|
-
}
|
|
331
|
-
if (t < 1 / 6)
|
|
332
|
-
{
|
|
333
|
-
return p + (q - p) * 6 * t;
|
|
334
|
-
}
|
|
335
|
-
if (t < 1 / 2)
|
|
336
|
-
{
|
|
337
|
-
return q;
|
|
338
|
-
}
|
|
339
|
-
if (t < 2 / 3)
|
|
340
|
-
{
|
|
341
|
-
return p + (q - p) * (2 / 3 - t) * 6;
|
|
342
|
-
}
|
|
343
|
-
return p;
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Converts an HSL color value to RGB. Conversion formula
|
|
348
|
-
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
|
|
349
|
-
* Assumes h, s, and l are contained in the set [0, 1] and
|
|
350
|
-
* returns r, g, and b in the set [0, 255].
|
|
351
|
-
* @see [Original code and author] {@link https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion}
|
|
352
|
-
* @param {HSLType}
|
|
353
|
-
* @return {Array} The RGB representation
|
|
354
|
-
*/
|
|
355
|
-
export const hslToRgb = ({hue, saturation, lightness}) =>
|
|
356
|
-
{
|
|
357
|
-
let r, g, b;
|
|
358
|
-
|
|
359
|
-
if (saturation === 0)
|
|
360
|
-
{
|
|
361
|
-
r = g = b = lightness; // achromatic
|
|
362
|
-
}
|
|
363
|
-
else
|
|
364
|
-
{
|
|
365
|
-
const q = lightness < 0.5 ? lightness * (1 + saturation) : lightness + saturation - lightness * saturation;
|
|
366
|
-
const p = 2 * lightness - q;
|
|
367
|
-
r = hue2rgb(p, q, hue + 1 / 3);
|
|
368
|
-
g = hue2rgb(p, q, hue);
|
|
369
|
-
b = hue2rgb(p, q, hue - 1 / 3);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
return {
|
|
373
|
-
red : Math.round(r * 255),
|
|
374
|
-
blue : Math.round(b * 255),
|
|
375
|
-
green: Math.round(g * 255)
|
|
376
|
-
};
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* @see https://stackoverflow.com/questions/1573053/javascript-function-to-convert-color-names-to-hex-codes
|
|
381
|
-
* @param {string} colour
|
|
382
|
-
* @returns {boolean|*}
|
|
383
|
-
*/
|
|
384
|
-
export const colorNameToHex = (colour) =>
|
|
385
|
-
{
|
|
386
|
-
const colorName = colour.toLowerCase()
|
|
387
|
-
if (typeof colors[colorName] != 'undefined')
|
|
388
|
-
{
|
|
389
|
-
return colors[colorName];
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
return "";
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* Returns ANSI code for given RGB color
|
|
397
|
-
* @param {RGBType}
|
|
398
|
-
* @param {boolean} isForeground
|
|
399
|
-
* @returns {string}
|
|
400
|
-
*/
|
|
401
|
-
export function fromRgb ({red, blue, green}, isForeground = true)
|
|
402
|
-
{
|
|
403
|
-
if (red === undefined || blue === undefined || green === undefined)
|
|
404
|
-
{
|
|
405
|
-
return "";
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
const code = rgbToAnsi256(red, blue, green);
|
|
409
|
-
|
|
410
|
-
let ground = isForeground ? COLOR_TYPE.Foreground : COLOR_TYPE.Background;
|
|
411
|
-
return `\x1b[${ground};5;` + code + "m " + backward;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Returns ANSI code for given hexadecimal color
|
|
416
|
-
* @param {string} hexa
|
|
417
|
-
* @param {boolean} isForeground
|
|
418
|
-
* @returns {string}
|
|
419
|
-
*/
|
|
420
|
-
export function fromHexa (hexa, isForeground = true)
|
|
421
|
-
{
|
|
422
|
-
const {red, green, blue} = hexToRgb(hexa);
|
|
423
|
-
return fromRgb({red, green, blue}, isForeground);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
* Returns ANSI code for given HSL color
|
|
428
|
-
* @param {HSLType}
|
|
429
|
-
* @param {boolean} isForeground
|
|
430
|
-
* @returns {string}
|
|
431
|
-
*/
|
|
432
|
-
export function fromHsl ({hue, saturation, lightness}, isForeground)
|
|
433
|
-
{
|
|
434
|
-
const {red, green, blue} = hslToRgb({hue, saturation, lightness});
|
|
435
|
-
return fromRgb({red, green, blue}, isForeground);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Return ANSI code color for a given value
|
|
440
|
-
* @param {string|Object} okayColor Actual name color (i.e. orange, yellow) or color code (#00F00F)
|
|
441
|
-
* @param isForeground
|
|
442
|
-
* @returns {string}
|
|
443
|
-
*/
|
|
444
|
-
export function fromColor (okayColor, isForeground = true)
|
|
445
|
-
{
|
|
446
|
-
try
|
|
447
|
-
{
|
|
448
|
-
let hexa;
|
|
449
|
-
okayColor = okayColor || ""
|
|
450
|
-
|
|
451
|
-
if (!okayColor)
|
|
452
|
-
{
|
|
453
|
-
return "";
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
if (typeof okayColor === 'string' || okayColor instanceof String)
|
|
457
|
-
{
|
|
458
|
-
okayColor = okayColor.trim()
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// Color name
|
|
462
|
-
if (isLiteralColor(okayColor))
|
|
463
|
-
{
|
|
464
|
-
hexa = colorNameToHex(okayColor);
|
|
465
|
-
return fromHexa(hexa, isForeground);
|
|
466
|
-
}
|
|
467
|
-
// RGB
|
|
468
|
-
else if (
|
|
469
|
-
typeof okayColor === 'object' && !!okayColor.red && !!okayColor.blue && !!okayColor.green
|
|
470
|
-
)
|
|
471
|
-
{
|
|
472
|
-
return fromRgb(okayColor, isForeground);
|
|
473
|
-
}
|
|
474
|
-
// HSL
|
|
475
|
-
else if (
|
|
476
|
-
typeof okayColor === 'object' && !!okayColor.hue && !!okayColor.saturation && !!okayColor.lightness
|
|
477
|
-
)
|
|
478
|
-
{
|
|
479
|
-
return fromHsl(okayColor, isForeground);
|
|
480
|
-
}
|
|
481
|
-
else if (okayColor.startsWith("#"))
|
|
482
|
-
{
|
|
483
|
-
return fromHexa(okayColor, isForeground);
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
okayColor = okayColor.toString()
|
|
487
|
-
if (!/^[\da-fA-F]+$/.test(okayColor))
|
|
488
|
-
{
|
|
489
|
-
return ""
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
return fromHexa("#" + okayColor, isForeground);
|
|
493
|
-
}
|
|
494
|
-
catch (e)
|
|
495
|
-
{
|
|
496
|
-
/* istanbul ignore next */
|
|
497
|
-
console.error("TO_ANSI_INVALID_ARGUMENT_ERROR", e.message)
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
function getTextFromAnsi(text, {
|
|
502
|
-
fg,
|
|
503
|
-
bg,
|
|
504
|
-
isUnderline = false,
|
|
505
|
-
isBold = false,
|
|
506
|
-
isReversed = false
|
|
507
|
-
})
|
|
508
|
-
{
|
|
509
|
-
let modified = false;
|
|
510
|
-
|
|
511
|
-
let prefix = ""
|
|
512
|
-
if (fg)
|
|
513
|
-
{
|
|
514
|
-
modified = true;
|
|
515
|
-
prefix = prefix + fg;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
if (bg)
|
|
519
|
-
{
|
|
520
|
-
modified = true;
|
|
521
|
-
prefix = prefix + bg;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
if (isUnderline)
|
|
525
|
-
{
|
|
526
|
-
modified = true;
|
|
527
|
-
prefix = prefix + FONT_STYLE.Underline;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
if (isBold)
|
|
531
|
-
{
|
|
532
|
-
modified = true;
|
|
533
|
-
prefix = prefix + FONT_STYLE.Bold;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
if (isReversed)
|
|
537
|
-
{
|
|
538
|
-
modified = true;
|
|
539
|
-
prefix = prefix + FONT_STYLE.Reversed;
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
if (!modified)
|
|
543
|
-
{
|
|
544
|
-
return text;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
return prefix + text + RESET;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
export function getTextFromRgb (text, {
|
|
552
|
-
fg = {},
|
|
553
|
-
bg = {},
|
|
554
|
-
isUnderline = false,
|
|
555
|
-
isBold = false,
|
|
556
|
-
isReversed = false
|
|
557
|
-
})
|
|
558
|
-
{
|
|
559
|
-
if (fg)
|
|
560
|
-
{
|
|
561
|
-
fg = fromRgb({...fg});
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
if (bg)
|
|
565
|
-
{
|
|
566
|
-
bg = fromRgb({...bg}, false);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
return getTextFromAnsi(text, {fg, bg, isUnderline, isBold, isReversed});
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
export function getTextFromHsl (text, {
|
|
573
|
-
fg = "",
|
|
574
|
-
bg = "",
|
|
575
|
-
isUnderline = false,
|
|
576
|
-
isBold = false,
|
|
577
|
-
isReversed = false
|
|
578
|
-
})
|
|
579
|
-
{
|
|
580
|
-
if (fg)
|
|
581
|
-
{
|
|
582
|
-
fg = fromHsl({...fg});
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
if (bg)
|
|
586
|
-
{
|
|
587
|
-
bg = fromHsl({...bg}, false);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
return getTextFromAnsi(text, {fg, bg, isUnderline, isBold, isReversed});
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
export function getTextFromHex (text, {
|
|
594
|
-
fg = "",
|
|
595
|
-
bg = "",
|
|
596
|
-
isUnderline = false,
|
|
597
|
-
isBold = false,
|
|
598
|
-
isReversed = false
|
|
599
|
-
})
|
|
600
|
-
{
|
|
601
|
-
if (fg)
|
|
602
|
-
{
|
|
603
|
-
fg = fromHexa(fg);
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
if (bg)
|
|
607
|
-
{
|
|
608
|
-
bg = fromHexa(bg, false);
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
return getTextFromAnsi(text, {fg, bg, isUnderline, isBold, isReversed});
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
/**
|
|
615
|
-
* Return colorized text based on given value
|
|
616
|
-
* @param text
|
|
617
|
-
* @param {ColorPropType} props
|
|
618
|
-
* @returns {string}
|
|
619
|
-
*/
|
|
620
|
-
export function getTextFromColor (text, props = null)
|
|
621
|
-
{
|
|
622
|
-
if (!props)
|
|
623
|
-
{
|
|
624
|
-
return text;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
let {
|
|
628
|
-
fg = "",
|
|
629
|
-
bg = "",
|
|
630
|
-
isUnderline = false,
|
|
631
|
-
isBold = false,
|
|
632
|
-
isReversed = false
|
|
633
|
-
} = props;
|
|
634
|
-
|
|
635
|
-
if (fg)
|
|
636
|
-
{
|
|
637
|
-
fg = fromColor(fg);
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
if (bg)
|
|
641
|
-
{
|
|
642
|
-
bg = fromColor(bg, false);
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
return getTextFromAnsi(text, {fg, bg, isUnderline, isBold, isReversed});
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
// ----------------------------------------
|
|
649
|
-
// Exports
|
|
650
|
-
// ----------------------------------------
|
|
651
|
-
export default {
|
|
652
|
-
fromRgb, fromHexa, fromHsl, fromColor,
|
|
653
|
-
getTextFromRgb, getTextFromHsl, getTextFromHex, getTextFromColor,
|
|
654
|
-
colorNameToHex, hslToRgb, hexToRgb, rgbToHex, rgbToAnsi256, rgbStringToRgb, rgbStringToHex, hue2rgb, RESET, FONT_STYLE, STYLE
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
/**
|
|
658
|
-
* For the conversion with to-esm, the named export and the function to export must use the same identifier.
|
|
659
|
-
* Otherwise, the conversion will fail.
|
|
660
|
-
*/
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|