msw 0.22.2 → 0.22.3
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/lib/esm/{matchRequestUrl-deps.js → getCallFrame-deps.js} +26 -1
- package/lib/esm/graphql.js +13 -1
- package/lib/esm/index.js +14 -2
- package/lib/esm/rest-deps.js +10 -1
- package/lib/esm/rest.js +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/node/glossary.d.ts +4 -0
- package/lib/types/setupWorker/glossary.d.ts +4 -0
- package/lib/types/utils/handlers/requestHandler.d.ts +13 -1
- package/lib/types/utils/internal/getCallFrame.d.ts +4 -0
- package/lib/umd/index.js +58 -0
- package/native/index.js +1981 -87
- package/node/index.js +1981 -87
- package/package.json +1 -1
package/native/index.js
CHANGED
|
@@ -3,8 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var XMLHttpRequest = require('node-request-interceptor/lib/interceptors/XMLHttpRequest');
|
|
6
|
+
var os = require('os');
|
|
7
|
+
var tty = require('tty');
|
|
6
8
|
var nodeRequestInterceptor = require('node-request-interceptor');
|
|
7
9
|
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
|
13
|
+
var tty__default = /*#__PURE__*/_interopDefaultLegacy(tty);
|
|
14
|
+
|
|
8
15
|
/*! *****************************************************************************
|
|
9
16
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
10
17
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -30,108 +37,1980 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
30
37
|
});
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
/*!
|
|
34
|
-
* cookie
|
|
35
|
-
* Copyright(c) 2012-2014 Roman Shtylman
|
|
36
|
-
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
37
|
-
* MIT Licensed
|
|
38
|
-
*/
|
|
40
|
+
/*!
|
|
41
|
+
* cookie
|
|
42
|
+
* Copyright(c) 2012-2014 Roman Shtylman
|
|
43
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
44
|
+
* MIT Licensed
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Module exports.
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
var parse_1 = parse;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Module variables.
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
var decode = decodeURIComponent;
|
|
60
|
+
var pairSplitRegExp = /; */;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Parse a cookie header.
|
|
64
|
+
*
|
|
65
|
+
* Parse the given cookie header string into an object
|
|
66
|
+
* The object has the various cookies as keys(names) => values
|
|
67
|
+
*
|
|
68
|
+
* @param {string} str
|
|
69
|
+
* @param {object} [options]
|
|
70
|
+
* @return {object}
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
function parse(str, options) {
|
|
75
|
+
if (typeof str !== 'string') {
|
|
76
|
+
throw new TypeError('argument str must be a string');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var obj = {};
|
|
80
|
+
var opt = options || {};
|
|
81
|
+
var pairs = str.split(pairSplitRegExp);
|
|
82
|
+
var dec = opt.decode || decode;
|
|
83
|
+
|
|
84
|
+
for (var i = 0; i < pairs.length; i++) {
|
|
85
|
+
var pair = pairs[i];
|
|
86
|
+
var eq_idx = pair.indexOf('=');
|
|
87
|
+
|
|
88
|
+
// skip things that don't look like key=value
|
|
89
|
+
if (eq_idx < 0) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
var key = pair.substr(0, eq_idx).trim();
|
|
94
|
+
var val = pair.substr(++eq_idx, pair.length).trim();
|
|
95
|
+
|
|
96
|
+
// quoted values
|
|
97
|
+
if ('"' == val[0]) {
|
|
98
|
+
val = val.slice(1, -1);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// only assign once
|
|
102
|
+
if (undefined == obj[key]) {
|
|
103
|
+
obj[key] = tryDecode(val, dec);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return obj;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Try decoding a string using a decoding function.
|
|
112
|
+
*
|
|
113
|
+
* @param {string} str
|
|
114
|
+
* @param {function} decode
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
function tryDecode(str, decode) {
|
|
119
|
+
try {
|
|
120
|
+
return decode(str);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
return str;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
127
|
+
|
|
128
|
+
function createCommonjsModule(fn, basedir, module) {
|
|
129
|
+
return module = {
|
|
130
|
+
path: basedir,
|
|
131
|
+
exports: {},
|
|
132
|
+
require: function (path, base) {
|
|
133
|
+
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
|
|
134
|
+
}
|
|
135
|
+
}, fn(module, module.exports), module.exports;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function commonjsRequire () {
|
|
139
|
+
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
var colorName = {
|
|
143
|
+
"aliceblue": [240, 248, 255],
|
|
144
|
+
"antiquewhite": [250, 235, 215],
|
|
145
|
+
"aqua": [0, 255, 255],
|
|
146
|
+
"aquamarine": [127, 255, 212],
|
|
147
|
+
"azure": [240, 255, 255],
|
|
148
|
+
"beige": [245, 245, 220],
|
|
149
|
+
"bisque": [255, 228, 196],
|
|
150
|
+
"black": [0, 0, 0],
|
|
151
|
+
"blanchedalmond": [255, 235, 205],
|
|
152
|
+
"blue": [0, 0, 255],
|
|
153
|
+
"blueviolet": [138, 43, 226],
|
|
154
|
+
"brown": [165, 42, 42],
|
|
155
|
+
"burlywood": [222, 184, 135],
|
|
156
|
+
"cadetblue": [95, 158, 160],
|
|
157
|
+
"chartreuse": [127, 255, 0],
|
|
158
|
+
"chocolate": [210, 105, 30],
|
|
159
|
+
"coral": [255, 127, 80],
|
|
160
|
+
"cornflowerblue": [100, 149, 237],
|
|
161
|
+
"cornsilk": [255, 248, 220],
|
|
162
|
+
"crimson": [220, 20, 60],
|
|
163
|
+
"cyan": [0, 255, 255],
|
|
164
|
+
"darkblue": [0, 0, 139],
|
|
165
|
+
"darkcyan": [0, 139, 139],
|
|
166
|
+
"darkgoldenrod": [184, 134, 11],
|
|
167
|
+
"darkgray": [169, 169, 169],
|
|
168
|
+
"darkgreen": [0, 100, 0],
|
|
169
|
+
"darkgrey": [169, 169, 169],
|
|
170
|
+
"darkkhaki": [189, 183, 107],
|
|
171
|
+
"darkmagenta": [139, 0, 139],
|
|
172
|
+
"darkolivegreen": [85, 107, 47],
|
|
173
|
+
"darkorange": [255, 140, 0],
|
|
174
|
+
"darkorchid": [153, 50, 204],
|
|
175
|
+
"darkred": [139, 0, 0],
|
|
176
|
+
"darksalmon": [233, 150, 122],
|
|
177
|
+
"darkseagreen": [143, 188, 143],
|
|
178
|
+
"darkslateblue": [72, 61, 139],
|
|
179
|
+
"darkslategray": [47, 79, 79],
|
|
180
|
+
"darkslategrey": [47, 79, 79],
|
|
181
|
+
"darkturquoise": [0, 206, 209],
|
|
182
|
+
"darkviolet": [148, 0, 211],
|
|
183
|
+
"deeppink": [255, 20, 147],
|
|
184
|
+
"deepskyblue": [0, 191, 255],
|
|
185
|
+
"dimgray": [105, 105, 105],
|
|
186
|
+
"dimgrey": [105, 105, 105],
|
|
187
|
+
"dodgerblue": [30, 144, 255],
|
|
188
|
+
"firebrick": [178, 34, 34],
|
|
189
|
+
"floralwhite": [255, 250, 240],
|
|
190
|
+
"forestgreen": [34, 139, 34],
|
|
191
|
+
"fuchsia": [255, 0, 255],
|
|
192
|
+
"gainsboro": [220, 220, 220],
|
|
193
|
+
"ghostwhite": [248, 248, 255],
|
|
194
|
+
"gold": [255, 215, 0],
|
|
195
|
+
"goldenrod": [218, 165, 32],
|
|
196
|
+
"gray": [128, 128, 128],
|
|
197
|
+
"green": [0, 128, 0],
|
|
198
|
+
"greenyellow": [173, 255, 47],
|
|
199
|
+
"grey": [128, 128, 128],
|
|
200
|
+
"honeydew": [240, 255, 240],
|
|
201
|
+
"hotpink": [255, 105, 180],
|
|
202
|
+
"indianred": [205, 92, 92],
|
|
203
|
+
"indigo": [75, 0, 130],
|
|
204
|
+
"ivory": [255, 255, 240],
|
|
205
|
+
"khaki": [240, 230, 140],
|
|
206
|
+
"lavender": [230, 230, 250],
|
|
207
|
+
"lavenderblush": [255, 240, 245],
|
|
208
|
+
"lawngreen": [124, 252, 0],
|
|
209
|
+
"lemonchiffon": [255, 250, 205],
|
|
210
|
+
"lightblue": [173, 216, 230],
|
|
211
|
+
"lightcoral": [240, 128, 128],
|
|
212
|
+
"lightcyan": [224, 255, 255],
|
|
213
|
+
"lightgoldenrodyellow": [250, 250, 210],
|
|
214
|
+
"lightgray": [211, 211, 211],
|
|
215
|
+
"lightgreen": [144, 238, 144],
|
|
216
|
+
"lightgrey": [211, 211, 211],
|
|
217
|
+
"lightpink": [255, 182, 193],
|
|
218
|
+
"lightsalmon": [255, 160, 122],
|
|
219
|
+
"lightseagreen": [32, 178, 170],
|
|
220
|
+
"lightskyblue": [135, 206, 250],
|
|
221
|
+
"lightslategray": [119, 136, 153],
|
|
222
|
+
"lightslategrey": [119, 136, 153],
|
|
223
|
+
"lightsteelblue": [176, 196, 222],
|
|
224
|
+
"lightyellow": [255, 255, 224],
|
|
225
|
+
"lime": [0, 255, 0],
|
|
226
|
+
"limegreen": [50, 205, 50],
|
|
227
|
+
"linen": [250, 240, 230],
|
|
228
|
+
"magenta": [255, 0, 255],
|
|
229
|
+
"maroon": [128, 0, 0],
|
|
230
|
+
"mediumaquamarine": [102, 205, 170],
|
|
231
|
+
"mediumblue": [0, 0, 205],
|
|
232
|
+
"mediumorchid": [186, 85, 211],
|
|
233
|
+
"mediumpurple": [147, 112, 219],
|
|
234
|
+
"mediumseagreen": [60, 179, 113],
|
|
235
|
+
"mediumslateblue": [123, 104, 238],
|
|
236
|
+
"mediumspringgreen": [0, 250, 154],
|
|
237
|
+
"mediumturquoise": [72, 209, 204],
|
|
238
|
+
"mediumvioletred": [199, 21, 133],
|
|
239
|
+
"midnightblue": [25, 25, 112],
|
|
240
|
+
"mintcream": [245, 255, 250],
|
|
241
|
+
"mistyrose": [255, 228, 225],
|
|
242
|
+
"moccasin": [255, 228, 181],
|
|
243
|
+
"navajowhite": [255, 222, 173],
|
|
244
|
+
"navy": [0, 0, 128],
|
|
245
|
+
"oldlace": [253, 245, 230],
|
|
246
|
+
"olive": [128, 128, 0],
|
|
247
|
+
"olivedrab": [107, 142, 35],
|
|
248
|
+
"orange": [255, 165, 0],
|
|
249
|
+
"orangered": [255, 69, 0],
|
|
250
|
+
"orchid": [218, 112, 214],
|
|
251
|
+
"palegoldenrod": [238, 232, 170],
|
|
252
|
+
"palegreen": [152, 251, 152],
|
|
253
|
+
"paleturquoise": [175, 238, 238],
|
|
254
|
+
"palevioletred": [219, 112, 147],
|
|
255
|
+
"papayawhip": [255, 239, 213],
|
|
256
|
+
"peachpuff": [255, 218, 185],
|
|
257
|
+
"peru": [205, 133, 63],
|
|
258
|
+
"pink": [255, 192, 203],
|
|
259
|
+
"plum": [221, 160, 221],
|
|
260
|
+
"powderblue": [176, 224, 230],
|
|
261
|
+
"purple": [128, 0, 128],
|
|
262
|
+
"rebeccapurple": [102, 51, 153],
|
|
263
|
+
"red": [255, 0, 0],
|
|
264
|
+
"rosybrown": [188, 143, 143],
|
|
265
|
+
"royalblue": [65, 105, 225],
|
|
266
|
+
"saddlebrown": [139, 69, 19],
|
|
267
|
+
"salmon": [250, 128, 114],
|
|
268
|
+
"sandybrown": [244, 164, 96],
|
|
269
|
+
"seagreen": [46, 139, 87],
|
|
270
|
+
"seashell": [255, 245, 238],
|
|
271
|
+
"sienna": [160, 82, 45],
|
|
272
|
+
"silver": [192, 192, 192],
|
|
273
|
+
"skyblue": [135, 206, 235],
|
|
274
|
+
"slateblue": [106, 90, 205],
|
|
275
|
+
"slategray": [112, 128, 144],
|
|
276
|
+
"slategrey": [112, 128, 144],
|
|
277
|
+
"snow": [255, 250, 250],
|
|
278
|
+
"springgreen": [0, 255, 127],
|
|
279
|
+
"steelblue": [70, 130, 180],
|
|
280
|
+
"tan": [210, 180, 140],
|
|
281
|
+
"teal": [0, 128, 128],
|
|
282
|
+
"thistle": [216, 191, 216],
|
|
283
|
+
"tomato": [255, 99, 71],
|
|
284
|
+
"turquoise": [64, 224, 208],
|
|
285
|
+
"violet": [238, 130, 238],
|
|
286
|
+
"wheat": [245, 222, 179],
|
|
287
|
+
"white": [255, 255, 255],
|
|
288
|
+
"whitesmoke": [245, 245, 245],
|
|
289
|
+
"yellow": [255, 255, 0],
|
|
290
|
+
"yellowgreen": [154, 205, 50]
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/* MIT license */
|
|
294
|
+
/* eslint-disable no-mixed-operators */
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
// NOTE: conversions should only return primitive values (i.e. arrays, or
|
|
298
|
+
// values that give correct `typeof` results).
|
|
299
|
+
// do not use box values types (i.e. Number(), String(), etc.)
|
|
300
|
+
|
|
301
|
+
const reverseKeywords = {};
|
|
302
|
+
for (const key of Object.keys(colorName)) {
|
|
303
|
+
reverseKeywords[colorName[key]] = key;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const convert = {
|
|
307
|
+
rgb: {channels: 3, labels: 'rgb'},
|
|
308
|
+
hsl: {channels: 3, labels: 'hsl'},
|
|
309
|
+
hsv: {channels: 3, labels: 'hsv'},
|
|
310
|
+
hwb: {channels: 3, labels: 'hwb'},
|
|
311
|
+
cmyk: {channels: 4, labels: 'cmyk'},
|
|
312
|
+
xyz: {channels: 3, labels: 'xyz'},
|
|
313
|
+
lab: {channels: 3, labels: 'lab'},
|
|
314
|
+
lch: {channels: 3, labels: 'lch'},
|
|
315
|
+
hex: {channels: 1, labels: ['hex']},
|
|
316
|
+
keyword: {channels: 1, labels: ['keyword']},
|
|
317
|
+
ansi16: {channels: 1, labels: ['ansi16']},
|
|
318
|
+
ansi256: {channels: 1, labels: ['ansi256']},
|
|
319
|
+
hcg: {channels: 3, labels: ['h', 'c', 'g']},
|
|
320
|
+
apple: {channels: 3, labels: ['r16', 'g16', 'b16']},
|
|
321
|
+
gray: {channels: 1, labels: ['gray']}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
var conversions = convert;
|
|
325
|
+
|
|
326
|
+
// Hide .channels and .labels properties
|
|
327
|
+
for (const model of Object.keys(convert)) {
|
|
328
|
+
if (!('channels' in convert[model])) {
|
|
329
|
+
throw new Error('missing channels property: ' + model);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (!('labels' in convert[model])) {
|
|
333
|
+
throw new Error('missing channel labels property: ' + model);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (convert[model].labels.length !== convert[model].channels) {
|
|
337
|
+
throw new Error('channel and label counts mismatch: ' + model);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const {channels, labels} = convert[model];
|
|
341
|
+
delete convert[model].channels;
|
|
342
|
+
delete convert[model].labels;
|
|
343
|
+
Object.defineProperty(convert[model], 'channels', {value: channels});
|
|
344
|
+
Object.defineProperty(convert[model], 'labels', {value: labels});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
convert.rgb.hsl = function (rgb) {
|
|
348
|
+
const r = rgb[0] / 255;
|
|
349
|
+
const g = rgb[1] / 255;
|
|
350
|
+
const b = rgb[2] / 255;
|
|
351
|
+
const min = Math.min(r, g, b);
|
|
352
|
+
const max = Math.max(r, g, b);
|
|
353
|
+
const delta = max - min;
|
|
354
|
+
let h;
|
|
355
|
+
let s;
|
|
356
|
+
|
|
357
|
+
if (max === min) {
|
|
358
|
+
h = 0;
|
|
359
|
+
} else if (r === max) {
|
|
360
|
+
h = (g - b) / delta;
|
|
361
|
+
} else if (g === max) {
|
|
362
|
+
h = 2 + (b - r) / delta;
|
|
363
|
+
} else if (b === max) {
|
|
364
|
+
h = 4 + (r - g) / delta;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
h = Math.min(h * 60, 360);
|
|
368
|
+
|
|
369
|
+
if (h < 0) {
|
|
370
|
+
h += 360;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const l = (min + max) / 2;
|
|
374
|
+
|
|
375
|
+
if (max === min) {
|
|
376
|
+
s = 0;
|
|
377
|
+
} else if (l <= 0.5) {
|
|
378
|
+
s = delta / (max + min);
|
|
379
|
+
} else {
|
|
380
|
+
s = delta / (2 - max - min);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return [h, s * 100, l * 100];
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
convert.rgb.hsv = function (rgb) {
|
|
387
|
+
let rdif;
|
|
388
|
+
let gdif;
|
|
389
|
+
let bdif;
|
|
390
|
+
let h;
|
|
391
|
+
let s;
|
|
392
|
+
|
|
393
|
+
const r = rgb[0] / 255;
|
|
394
|
+
const g = rgb[1] / 255;
|
|
395
|
+
const b = rgb[2] / 255;
|
|
396
|
+
const v = Math.max(r, g, b);
|
|
397
|
+
const diff = v - Math.min(r, g, b);
|
|
398
|
+
const diffc = function (c) {
|
|
399
|
+
return (v - c) / 6 / diff + 1 / 2;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
if (diff === 0) {
|
|
403
|
+
h = 0;
|
|
404
|
+
s = 0;
|
|
405
|
+
} else {
|
|
406
|
+
s = diff / v;
|
|
407
|
+
rdif = diffc(r);
|
|
408
|
+
gdif = diffc(g);
|
|
409
|
+
bdif = diffc(b);
|
|
410
|
+
|
|
411
|
+
if (r === v) {
|
|
412
|
+
h = bdif - gdif;
|
|
413
|
+
} else if (g === v) {
|
|
414
|
+
h = (1 / 3) + rdif - bdif;
|
|
415
|
+
} else if (b === v) {
|
|
416
|
+
h = (2 / 3) + gdif - rdif;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (h < 0) {
|
|
420
|
+
h += 1;
|
|
421
|
+
} else if (h > 1) {
|
|
422
|
+
h -= 1;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return [
|
|
427
|
+
h * 360,
|
|
428
|
+
s * 100,
|
|
429
|
+
v * 100
|
|
430
|
+
];
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
convert.rgb.hwb = function (rgb) {
|
|
434
|
+
const r = rgb[0];
|
|
435
|
+
const g = rgb[1];
|
|
436
|
+
let b = rgb[2];
|
|
437
|
+
const h = convert.rgb.hsl(rgb)[0];
|
|
438
|
+
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
439
|
+
|
|
440
|
+
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
441
|
+
|
|
442
|
+
return [h, w * 100, b * 100];
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
convert.rgb.cmyk = function (rgb) {
|
|
446
|
+
const r = rgb[0] / 255;
|
|
447
|
+
const g = rgb[1] / 255;
|
|
448
|
+
const b = rgb[2] / 255;
|
|
449
|
+
|
|
450
|
+
const k = Math.min(1 - r, 1 - g, 1 - b);
|
|
451
|
+
const c = (1 - r - k) / (1 - k) || 0;
|
|
452
|
+
const m = (1 - g - k) / (1 - k) || 0;
|
|
453
|
+
const y = (1 - b - k) / (1 - k) || 0;
|
|
454
|
+
|
|
455
|
+
return [c * 100, m * 100, y * 100, k * 100];
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
function comparativeDistance(x, y) {
|
|
459
|
+
/*
|
|
460
|
+
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
|
|
461
|
+
*/
|
|
462
|
+
return (
|
|
463
|
+
((x[0] - y[0]) ** 2) +
|
|
464
|
+
((x[1] - y[1]) ** 2) +
|
|
465
|
+
((x[2] - y[2]) ** 2)
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
convert.rgb.keyword = function (rgb) {
|
|
470
|
+
const reversed = reverseKeywords[rgb];
|
|
471
|
+
if (reversed) {
|
|
472
|
+
return reversed;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
let currentClosestDistance = Infinity;
|
|
476
|
+
let currentClosestKeyword;
|
|
477
|
+
|
|
478
|
+
for (const keyword of Object.keys(colorName)) {
|
|
479
|
+
const value = colorName[keyword];
|
|
480
|
+
|
|
481
|
+
// Compute comparative distance
|
|
482
|
+
const distance = comparativeDistance(rgb, value);
|
|
483
|
+
|
|
484
|
+
// Check if its less, if so set as closest
|
|
485
|
+
if (distance < currentClosestDistance) {
|
|
486
|
+
currentClosestDistance = distance;
|
|
487
|
+
currentClosestKeyword = keyword;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
return currentClosestKeyword;
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
convert.keyword.rgb = function (keyword) {
|
|
495
|
+
return colorName[keyword];
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
convert.rgb.xyz = function (rgb) {
|
|
499
|
+
let r = rgb[0] / 255;
|
|
500
|
+
let g = rgb[1] / 255;
|
|
501
|
+
let b = rgb[2] / 255;
|
|
502
|
+
|
|
503
|
+
// Assume sRGB
|
|
504
|
+
r = r > 0.04045 ? (((r + 0.055) / 1.055) ** 2.4) : (r / 12.92);
|
|
505
|
+
g = g > 0.04045 ? (((g + 0.055) / 1.055) ** 2.4) : (g / 12.92);
|
|
506
|
+
b = b > 0.04045 ? (((b + 0.055) / 1.055) ** 2.4) : (b / 12.92);
|
|
507
|
+
|
|
508
|
+
const x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
|
|
509
|
+
const y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
|
|
510
|
+
const z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
|
|
511
|
+
|
|
512
|
+
return [x * 100, y * 100, z * 100];
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
convert.rgb.lab = function (rgb) {
|
|
516
|
+
const xyz = convert.rgb.xyz(rgb);
|
|
517
|
+
let x = xyz[0];
|
|
518
|
+
let y = xyz[1];
|
|
519
|
+
let z = xyz[2];
|
|
520
|
+
|
|
521
|
+
x /= 95.047;
|
|
522
|
+
y /= 100;
|
|
523
|
+
z /= 108.883;
|
|
524
|
+
|
|
525
|
+
x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
|
|
526
|
+
y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
|
|
527
|
+
z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
|
|
528
|
+
|
|
529
|
+
const l = (116 * y) - 16;
|
|
530
|
+
const a = 500 * (x - y);
|
|
531
|
+
const b = 200 * (y - z);
|
|
532
|
+
|
|
533
|
+
return [l, a, b];
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
convert.hsl.rgb = function (hsl) {
|
|
537
|
+
const h = hsl[0] / 360;
|
|
538
|
+
const s = hsl[1] / 100;
|
|
539
|
+
const l = hsl[2] / 100;
|
|
540
|
+
let t2;
|
|
541
|
+
let t3;
|
|
542
|
+
let val;
|
|
543
|
+
|
|
544
|
+
if (s === 0) {
|
|
545
|
+
val = l * 255;
|
|
546
|
+
return [val, val, val];
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
if (l < 0.5) {
|
|
550
|
+
t2 = l * (1 + s);
|
|
551
|
+
} else {
|
|
552
|
+
t2 = l + s - l * s;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
const t1 = 2 * l - t2;
|
|
556
|
+
|
|
557
|
+
const rgb = [0, 0, 0];
|
|
558
|
+
for (let i = 0; i < 3; i++) {
|
|
559
|
+
t3 = h + 1 / 3 * -(i - 1);
|
|
560
|
+
if (t3 < 0) {
|
|
561
|
+
t3++;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
if (t3 > 1) {
|
|
565
|
+
t3--;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if (6 * t3 < 1) {
|
|
569
|
+
val = t1 + (t2 - t1) * 6 * t3;
|
|
570
|
+
} else if (2 * t3 < 1) {
|
|
571
|
+
val = t2;
|
|
572
|
+
} else if (3 * t3 < 2) {
|
|
573
|
+
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
574
|
+
} else {
|
|
575
|
+
val = t1;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
rgb[i] = val * 255;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return rgb;
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
convert.hsl.hsv = function (hsl) {
|
|
585
|
+
const h = hsl[0];
|
|
586
|
+
let s = hsl[1] / 100;
|
|
587
|
+
let l = hsl[2] / 100;
|
|
588
|
+
let smin = s;
|
|
589
|
+
const lmin = Math.max(l, 0.01);
|
|
590
|
+
|
|
591
|
+
l *= 2;
|
|
592
|
+
s *= (l <= 1) ? l : 2 - l;
|
|
593
|
+
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
594
|
+
const v = (l + s) / 2;
|
|
595
|
+
const sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);
|
|
596
|
+
|
|
597
|
+
return [h, sv * 100, v * 100];
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
convert.hsv.rgb = function (hsv) {
|
|
601
|
+
const h = hsv[0] / 60;
|
|
602
|
+
const s = hsv[1] / 100;
|
|
603
|
+
let v = hsv[2] / 100;
|
|
604
|
+
const hi = Math.floor(h) % 6;
|
|
605
|
+
|
|
606
|
+
const f = h - Math.floor(h);
|
|
607
|
+
const p = 255 * v * (1 - s);
|
|
608
|
+
const q = 255 * v * (1 - (s * f));
|
|
609
|
+
const t = 255 * v * (1 - (s * (1 - f)));
|
|
610
|
+
v *= 255;
|
|
611
|
+
|
|
612
|
+
switch (hi) {
|
|
613
|
+
case 0:
|
|
614
|
+
return [v, t, p];
|
|
615
|
+
case 1:
|
|
616
|
+
return [q, v, p];
|
|
617
|
+
case 2:
|
|
618
|
+
return [p, v, t];
|
|
619
|
+
case 3:
|
|
620
|
+
return [p, q, v];
|
|
621
|
+
case 4:
|
|
622
|
+
return [t, p, v];
|
|
623
|
+
case 5:
|
|
624
|
+
return [v, p, q];
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
convert.hsv.hsl = function (hsv) {
|
|
629
|
+
const h = hsv[0];
|
|
630
|
+
const s = hsv[1] / 100;
|
|
631
|
+
const v = hsv[2] / 100;
|
|
632
|
+
const vmin = Math.max(v, 0.01);
|
|
633
|
+
let sl;
|
|
634
|
+
let l;
|
|
635
|
+
|
|
636
|
+
l = (2 - s) * v;
|
|
637
|
+
const lmin = (2 - s) * vmin;
|
|
638
|
+
sl = s * vmin;
|
|
639
|
+
sl /= (lmin <= 1) ? lmin : 2 - lmin;
|
|
640
|
+
sl = sl || 0;
|
|
641
|
+
l /= 2;
|
|
642
|
+
|
|
643
|
+
return [h, sl * 100, l * 100];
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// http://dev.w3.org/csswg/css-color/#hwb-to-rgb
|
|
647
|
+
convert.hwb.rgb = function (hwb) {
|
|
648
|
+
const h = hwb[0] / 360;
|
|
649
|
+
let wh = hwb[1] / 100;
|
|
650
|
+
let bl = hwb[2] / 100;
|
|
651
|
+
const ratio = wh + bl;
|
|
652
|
+
let f;
|
|
653
|
+
|
|
654
|
+
// Wh + bl cant be > 1
|
|
655
|
+
if (ratio > 1) {
|
|
656
|
+
wh /= ratio;
|
|
657
|
+
bl /= ratio;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
const i = Math.floor(6 * h);
|
|
661
|
+
const v = 1 - bl;
|
|
662
|
+
f = 6 * h - i;
|
|
663
|
+
|
|
664
|
+
if ((i & 0x01) !== 0) {
|
|
665
|
+
f = 1 - f;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const n = wh + f * (v - wh); // Linear interpolation
|
|
669
|
+
|
|
670
|
+
let r;
|
|
671
|
+
let g;
|
|
672
|
+
let b;
|
|
673
|
+
/* eslint-disable max-statements-per-line,no-multi-spaces */
|
|
674
|
+
switch (i) {
|
|
675
|
+
default:
|
|
676
|
+
case 6:
|
|
677
|
+
case 0: r = v; g = n; b = wh; break;
|
|
678
|
+
case 1: r = n; g = v; b = wh; break;
|
|
679
|
+
case 2: r = wh; g = v; b = n; break;
|
|
680
|
+
case 3: r = wh; g = n; b = v; break;
|
|
681
|
+
case 4: r = n; g = wh; b = v; break;
|
|
682
|
+
case 5: r = v; g = wh; b = n; break;
|
|
683
|
+
}
|
|
684
|
+
/* eslint-enable max-statements-per-line,no-multi-spaces */
|
|
685
|
+
|
|
686
|
+
return [r * 255, g * 255, b * 255];
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
convert.cmyk.rgb = function (cmyk) {
|
|
690
|
+
const c = cmyk[0] / 100;
|
|
691
|
+
const m = cmyk[1] / 100;
|
|
692
|
+
const y = cmyk[2] / 100;
|
|
693
|
+
const k = cmyk[3] / 100;
|
|
694
|
+
|
|
695
|
+
const r = 1 - Math.min(1, c * (1 - k) + k);
|
|
696
|
+
const g = 1 - Math.min(1, m * (1 - k) + k);
|
|
697
|
+
const b = 1 - Math.min(1, y * (1 - k) + k);
|
|
698
|
+
|
|
699
|
+
return [r * 255, g * 255, b * 255];
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
convert.xyz.rgb = function (xyz) {
|
|
703
|
+
const x = xyz[0] / 100;
|
|
704
|
+
const y = xyz[1] / 100;
|
|
705
|
+
const z = xyz[2] / 100;
|
|
706
|
+
let r;
|
|
707
|
+
let g;
|
|
708
|
+
let b;
|
|
709
|
+
|
|
710
|
+
r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
|
|
711
|
+
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
|
|
712
|
+
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
|
|
713
|
+
|
|
714
|
+
// Assume sRGB
|
|
715
|
+
r = r > 0.0031308
|
|
716
|
+
? ((1.055 * (r ** (1.0 / 2.4))) - 0.055)
|
|
717
|
+
: r * 12.92;
|
|
718
|
+
|
|
719
|
+
g = g > 0.0031308
|
|
720
|
+
? ((1.055 * (g ** (1.0 / 2.4))) - 0.055)
|
|
721
|
+
: g * 12.92;
|
|
722
|
+
|
|
723
|
+
b = b > 0.0031308
|
|
724
|
+
? ((1.055 * (b ** (1.0 / 2.4))) - 0.055)
|
|
725
|
+
: b * 12.92;
|
|
726
|
+
|
|
727
|
+
r = Math.min(Math.max(0, r), 1);
|
|
728
|
+
g = Math.min(Math.max(0, g), 1);
|
|
729
|
+
b = Math.min(Math.max(0, b), 1);
|
|
730
|
+
|
|
731
|
+
return [r * 255, g * 255, b * 255];
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
convert.xyz.lab = function (xyz) {
|
|
735
|
+
let x = xyz[0];
|
|
736
|
+
let y = xyz[1];
|
|
737
|
+
let z = xyz[2];
|
|
738
|
+
|
|
739
|
+
x /= 95.047;
|
|
740
|
+
y /= 100;
|
|
741
|
+
z /= 108.883;
|
|
742
|
+
|
|
743
|
+
x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
|
|
744
|
+
y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
|
|
745
|
+
z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
|
|
746
|
+
|
|
747
|
+
const l = (116 * y) - 16;
|
|
748
|
+
const a = 500 * (x - y);
|
|
749
|
+
const b = 200 * (y - z);
|
|
750
|
+
|
|
751
|
+
return [l, a, b];
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
convert.lab.xyz = function (lab) {
|
|
755
|
+
const l = lab[0];
|
|
756
|
+
const a = lab[1];
|
|
757
|
+
const b = lab[2];
|
|
758
|
+
let x;
|
|
759
|
+
let y;
|
|
760
|
+
let z;
|
|
761
|
+
|
|
762
|
+
y = (l + 16) / 116;
|
|
763
|
+
x = a / 500 + y;
|
|
764
|
+
z = y - b / 200;
|
|
765
|
+
|
|
766
|
+
const y2 = y ** 3;
|
|
767
|
+
const x2 = x ** 3;
|
|
768
|
+
const z2 = z ** 3;
|
|
769
|
+
y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
|
|
770
|
+
x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
|
|
771
|
+
z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
|
|
772
|
+
|
|
773
|
+
x *= 95.047;
|
|
774
|
+
y *= 100;
|
|
775
|
+
z *= 108.883;
|
|
776
|
+
|
|
777
|
+
return [x, y, z];
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
convert.lab.lch = function (lab) {
|
|
781
|
+
const l = lab[0];
|
|
782
|
+
const a = lab[1];
|
|
783
|
+
const b = lab[2];
|
|
784
|
+
let h;
|
|
785
|
+
|
|
786
|
+
const hr = Math.atan2(b, a);
|
|
787
|
+
h = hr * 360 / 2 / Math.PI;
|
|
788
|
+
|
|
789
|
+
if (h < 0) {
|
|
790
|
+
h += 360;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
const c = Math.sqrt(a * a + b * b);
|
|
794
|
+
|
|
795
|
+
return [l, c, h];
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
convert.lch.lab = function (lch) {
|
|
799
|
+
const l = lch[0];
|
|
800
|
+
const c = lch[1];
|
|
801
|
+
const h = lch[2];
|
|
802
|
+
|
|
803
|
+
const hr = h / 360 * 2 * Math.PI;
|
|
804
|
+
const a = c * Math.cos(hr);
|
|
805
|
+
const b = c * Math.sin(hr);
|
|
806
|
+
|
|
807
|
+
return [l, a, b];
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
convert.rgb.ansi16 = function (args, saturation = null) {
|
|
811
|
+
const [r, g, b] = args;
|
|
812
|
+
let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
|
|
813
|
+
|
|
814
|
+
value = Math.round(value / 50);
|
|
815
|
+
|
|
816
|
+
if (value === 0) {
|
|
817
|
+
return 30;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
let ansi = 30
|
|
821
|
+
+ ((Math.round(b / 255) << 2)
|
|
822
|
+
| (Math.round(g / 255) << 1)
|
|
823
|
+
| Math.round(r / 255));
|
|
824
|
+
|
|
825
|
+
if (value === 2) {
|
|
826
|
+
ansi += 60;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
return ansi;
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
convert.hsv.ansi16 = function (args) {
|
|
833
|
+
// Optimization here; we already know the value and don't need to get
|
|
834
|
+
// it converted for us.
|
|
835
|
+
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
convert.rgb.ansi256 = function (args) {
|
|
839
|
+
const r = args[0];
|
|
840
|
+
const g = args[1];
|
|
841
|
+
const b = args[2];
|
|
842
|
+
|
|
843
|
+
// We use the extended greyscale palette here, with the exception of
|
|
844
|
+
// black and white. normal palette only has 4 greyscale shades.
|
|
845
|
+
if (r === g && g === b) {
|
|
846
|
+
if (r < 8) {
|
|
847
|
+
return 16;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
if (r > 248) {
|
|
851
|
+
return 231;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
return Math.round(((r - 8) / 247) * 24) + 232;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
const ansi = 16
|
|
858
|
+
+ (36 * Math.round(r / 255 * 5))
|
|
859
|
+
+ (6 * Math.round(g / 255 * 5))
|
|
860
|
+
+ Math.round(b / 255 * 5);
|
|
861
|
+
|
|
862
|
+
return ansi;
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
convert.ansi16.rgb = function (args) {
|
|
866
|
+
let color = args % 10;
|
|
867
|
+
|
|
868
|
+
// Handle greyscale
|
|
869
|
+
if (color === 0 || color === 7) {
|
|
870
|
+
if (args > 50) {
|
|
871
|
+
color += 3.5;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
color = color / 10.5 * 255;
|
|
875
|
+
|
|
876
|
+
return [color, color, color];
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
const mult = (~~(args > 50) + 1) * 0.5;
|
|
880
|
+
const r = ((color & 1) * mult) * 255;
|
|
881
|
+
const g = (((color >> 1) & 1) * mult) * 255;
|
|
882
|
+
const b = (((color >> 2) & 1) * mult) * 255;
|
|
883
|
+
|
|
884
|
+
return [r, g, b];
|
|
885
|
+
};
|
|
886
|
+
|
|
887
|
+
convert.ansi256.rgb = function (args) {
|
|
888
|
+
// Handle greyscale
|
|
889
|
+
if (args >= 232) {
|
|
890
|
+
const c = (args - 232) * 10 + 8;
|
|
891
|
+
return [c, c, c];
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
args -= 16;
|
|
895
|
+
|
|
896
|
+
let rem;
|
|
897
|
+
const r = Math.floor(args / 36) / 5 * 255;
|
|
898
|
+
const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
899
|
+
const b = (rem % 6) / 5 * 255;
|
|
900
|
+
|
|
901
|
+
return [r, g, b];
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
convert.rgb.hex = function (args) {
|
|
905
|
+
const integer = ((Math.round(args[0]) & 0xFF) << 16)
|
|
906
|
+
+ ((Math.round(args[1]) & 0xFF) << 8)
|
|
907
|
+
+ (Math.round(args[2]) & 0xFF);
|
|
908
|
+
|
|
909
|
+
const string = integer.toString(16).toUpperCase();
|
|
910
|
+
return '000000'.substring(string.length) + string;
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
convert.hex.rgb = function (args) {
|
|
914
|
+
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
915
|
+
if (!match) {
|
|
916
|
+
return [0, 0, 0];
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
let colorString = match[0];
|
|
920
|
+
|
|
921
|
+
if (match[0].length === 3) {
|
|
922
|
+
colorString = colorString.split('').map(char => {
|
|
923
|
+
return char + char;
|
|
924
|
+
}).join('');
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
const integer = parseInt(colorString, 16);
|
|
928
|
+
const r = (integer >> 16) & 0xFF;
|
|
929
|
+
const g = (integer >> 8) & 0xFF;
|
|
930
|
+
const b = integer & 0xFF;
|
|
931
|
+
|
|
932
|
+
return [r, g, b];
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
convert.rgb.hcg = function (rgb) {
|
|
936
|
+
const r = rgb[0] / 255;
|
|
937
|
+
const g = rgb[1] / 255;
|
|
938
|
+
const b = rgb[2] / 255;
|
|
939
|
+
const max = Math.max(Math.max(r, g), b);
|
|
940
|
+
const min = Math.min(Math.min(r, g), b);
|
|
941
|
+
const chroma = (max - min);
|
|
942
|
+
let grayscale;
|
|
943
|
+
let hue;
|
|
944
|
+
|
|
945
|
+
if (chroma < 1) {
|
|
946
|
+
grayscale = min / (1 - chroma);
|
|
947
|
+
} else {
|
|
948
|
+
grayscale = 0;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
if (chroma <= 0) {
|
|
952
|
+
hue = 0;
|
|
953
|
+
} else
|
|
954
|
+
if (max === r) {
|
|
955
|
+
hue = ((g - b) / chroma) % 6;
|
|
956
|
+
} else
|
|
957
|
+
if (max === g) {
|
|
958
|
+
hue = 2 + (b - r) / chroma;
|
|
959
|
+
} else {
|
|
960
|
+
hue = 4 + (r - g) / chroma;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
hue /= 6;
|
|
964
|
+
hue %= 1;
|
|
965
|
+
|
|
966
|
+
return [hue * 360, chroma * 100, grayscale * 100];
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
convert.hsl.hcg = function (hsl) {
|
|
970
|
+
const s = hsl[1] / 100;
|
|
971
|
+
const l = hsl[2] / 100;
|
|
972
|
+
|
|
973
|
+
const c = l < 0.5 ? (2.0 * s * l) : (2.0 * s * (1.0 - l));
|
|
974
|
+
|
|
975
|
+
let f = 0;
|
|
976
|
+
if (c < 1.0) {
|
|
977
|
+
f = (l - 0.5 * c) / (1.0 - c);
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
return [hsl[0], c * 100, f * 100];
|
|
981
|
+
};
|
|
982
|
+
|
|
983
|
+
convert.hsv.hcg = function (hsv) {
|
|
984
|
+
const s = hsv[1] / 100;
|
|
985
|
+
const v = hsv[2] / 100;
|
|
986
|
+
|
|
987
|
+
const c = s * v;
|
|
988
|
+
let f = 0;
|
|
989
|
+
|
|
990
|
+
if (c < 1.0) {
|
|
991
|
+
f = (v - c) / (1 - c);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
return [hsv[0], c * 100, f * 100];
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
convert.hcg.rgb = function (hcg) {
|
|
998
|
+
const h = hcg[0] / 360;
|
|
999
|
+
const c = hcg[1] / 100;
|
|
1000
|
+
const g = hcg[2] / 100;
|
|
1001
|
+
|
|
1002
|
+
if (c === 0.0) {
|
|
1003
|
+
return [g * 255, g * 255, g * 255];
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
const pure = [0, 0, 0];
|
|
1007
|
+
const hi = (h % 1) * 6;
|
|
1008
|
+
const v = hi % 1;
|
|
1009
|
+
const w = 1 - v;
|
|
1010
|
+
let mg = 0;
|
|
1011
|
+
|
|
1012
|
+
/* eslint-disable max-statements-per-line */
|
|
1013
|
+
switch (Math.floor(hi)) {
|
|
1014
|
+
case 0:
|
|
1015
|
+
pure[0] = 1; pure[1] = v; pure[2] = 0; break;
|
|
1016
|
+
case 1:
|
|
1017
|
+
pure[0] = w; pure[1] = 1; pure[2] = 0; break;
|
|
1018
|
+
case 2:
|
|
1019
|
+
pure[0] = 0; pure[1] = 1; pure[2] = v; break;
|
|
1020
|
+
case 3:
|
|
1021
|
+
pure[0] = 0; pure[1] = w; pure[2] = 1; break;
|
|
1022
|
+
case 4:
|
|
1023
|
+
pure[0] = v; pure[1] = 0; pure[2] = 1; break;
|
|
1024
|
+
default:
|
|
1025
|
+
pure[0] = 1; pure[1] = 0; pure[2] = w;
|
|
1026
|
+
}
|
|
1027
|
+
/* eslint-enable max-statements-per-line */
|
|
1028
|
+
|
|
1029
|
+
mg = (1.0 - c) * g;
|
|
1030
|
+
|
|
1031
|
+
return [
|
|
1032
|
+
(c * pure[0] + mg) * 255,
|
|
1033
|
+
(c * pure[1] + mg) * 255,
|
|
1034
|
+
(c * pure[2] + mg) * 255
|
|
1035
|
+
];
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
convert.hcg.hsv = function (hcg) {
|
|
1039
|
+
const c = hcg[1] / 100;
|
|
1040
|
+
const g = hcg[2] / 100;
|
|
1041
|
+
|
|
1042
|
+
const v = c + g * (1.0 - c);
|
|
1043
|
+
let f = 0;
|
|
1044
|
+
|
|
1045
|
+
if (v > 0.0) {
|
|
1046
|
+
f = c / v;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
return [hcg[0], f * 100, v * 100];
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
convert.hcg.hsl = function (hcg) {
|
|
1053
|
+
const c = hcg[1] / 100;
|
|
1054
|
+
const g = hcg[2] / 100;
|
|
1055
|
+
|
|
1056
|
+
const l = g * (1.0 - c) + 0.5 * c;
|
|
1057
|
+
let s = 0;
|
|
1058
|
+
|
|
1059
|
+
if (l > 0.0 && l < 0.5) {
|
|
1060
|
+
s = c / (2 * l);
|
|
1061
|
+
} else
|
|
1062
|
+
if (l >= 0.5 && l < 1.0) {
|
|
1063
|
+
s = c / (2 * (1 - l));
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
return [hcg[0], s * 100, l * 100];
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
convert.hcg.hwb = function (hcg) {
|
|
1070
|
+
const c = hcg[1] / 100;
|
|
1071
|
+
const g = hcg[2] / 100;
|
|
1072
|
+
const v = c + g * (1.0 - c);
|
|
1073
|
+
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
convert.hwb.hcg = function (hwb) {
|
|
1077
|
+
const w = hwb[1] / 100;
|
|
1078
|
+
const b = hwb[2] / 100;
|
|
1079
|
+
const v = 1 - b;
|
|
1080
|
+
const c = v - w;
|
|
1081
|
+
let g = 0;
|
|
1082
|
+
|
|
1083
|
+
if (c < 1) {
|
|
1084
|
+
g = (v - c) / (1 - c);
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
return [hwb[0], c * 100, g * 100];
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
convert.apple.rgb = function (apple) {
|
|
1091
|
+
return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255];
|
|
1092
|
+
};
|
|
1093
|
+
|
|
1094
|
+
convert.rgb.apple = function (rgb) {
|
|
1095
|
+
return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535];
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
convert.gray.rgb = function (args) {
|
|
1099
|
+
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
convert.gray.hsl = function (args) {
|
|
1103
|
+
return [0, 0, args[0]];
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
convert.gray.hsv = convert.gray.hsl;
|
|
1107
|
+
|
|
1108
|
+
convert.gray.hwb = function (gray) {
|
|
1109
|
+
return [0, 100, gray[0]];
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
convert.gray.cmyk = function (gray) {
|
|
1113
|
+
return [0, 0, 0, gray[0]];
|
|
1114
|
+
};
|
|
1115
|
+
|
|
1116
|
+
convert.gray.lab = function (gray) {
|
|
1117
|
+
return [gray[0], 0, 0];
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1120
|
+
convert.gray.hex = function (gray) {
|
|
1121
|
+
const val = Math.round(gray[0] / 100 * 255) & 0xFF;
|
|
1122
|
+
const integer = (val << 16) + (val << 8) + val;
|
|
1123
|
+
|
|
1124
|
+
const string = integer.toString(16).toUpperCase();
|
|
1125
|
+
return '000000'.substring(string.length) + string;
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
convert.rgb.gray = function (rgb) {
|
|
1129
|
+
const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
1130
|
+
return [val / 255 * 100];
|
|
1131
|
+
};
|
|
1132
|
+
|
|
1133
|
+
/*
|
|
1134
|
+
This function routes a model to all other models.
|
|
1135
|
+
|
|
1136
|
+
all functions that are routed have a property `.conversion` attached
|
|
1137
|
+
to the returned synthetic function. This property is an array
|
|
1138
|
+
of strings, each with the steps in between the 'from' and 'to'
|
|
1139
|
+
color models (inclusive).
|
|
1140
|
+
|
|
1141
|
+
conversions that are not possible simply are not included.
|
|
1142
|
+
*/
|
|
1143
|
+
|
|
1144
|
+
function buildGraph() {
|
|
1145
|
+
const graph = {};
|
|
1146
|
+
// https://jsperf.com/object-keys-vs-for-in-with-closure/3
|
|
1147
|
+
const models = Object.keys(conversions);
|
|
1148
|
+
|
|
1149
|
+
for (let len = models.length, i = 0; i < len; i++) {
|
|
1150
|
+
graph[models[i]] = {
|
|
1151
|
+
// http://jsperf.com/1-vs-infinity
|
|
1152
|
+
// micro-opt, but this is simple.
|
|
1153
|
+
distance: -1,
|
|
1154
|
+
parent: null
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
return graph;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
// https://en.wikipedia.org/wiki/Breadth-first_search
|
|
1162
|
+
function deriveBFS(fromModel) {
|
|
1163
|
+
const graph = buildGraph();
|
|
1164
|
+
const queue = [fromModel]; // Unshift -> queue -> pop
|
|
1165
|
+
|
|
1166
|
+
graph[fromModel].distance = 0;
|
|
1167
|
+
|
|
1168
|
+
while (queue.length) {
|
|
1169
|
+
const current = queue.pop();
|
|
1170
|
+
const adjacents = Object.keys(conversions[current]);
|
|
1171
|
+
|
|
1172
|
+
for (let len = adjacents.length, i = 0; i < len; i++) {
|
|
1173
|
+
const adjacent = adjacents[i];
|
|
1174
|
+
const node = graph[adjacent];
|
|
1175
|
+
|
|
1176
|
+
if (node.distance === -1) {
|
|
1177
|
+
node.distance = graph[current].distance + 1;
|
|
1178
|
+
node.parent = current;
|
|
1179
|
+
queue.unshift(adjacent);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
return graph;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
function link(from, to) {
|
|
1188
|
+
return function (args) {
|
|
1189
|
+
return to(from(args));
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
function wrapConversion(toModel, graph) {
|
|
1194
|
+
const path = [graph[toModel].parent, toModel];
|
|
1195
|
+
let fn = conversions[graph[toModel].parent][toModel];
|
|
1196
|
+
|
|
1197
|
+
let cur = graph[toModel].parent;
|
|
1198
|
+
while (graph[cur].parent) {
|
|
1199
|
+
path.unshift(graph[cur].parent);
|
|
1200
|
+
fn = link(conversions[graph[cur].parent][cur], fn);
|
|
1201
|
+
cur = graph[cur].parent;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
fn.conversion = path;
|
|
1205
|
+
return fn;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
var route = function (fromModel) {
|
|
1209
|
+
const graph = deriveBFS(fromModel);
|
|
1210
|
+
const conversion = {};
|
|
1211
|
+
|
|
1212
|
+
const models = Object.keys(graph);
|
|
1213
|
+
for (let len = models.length, i = 0; i < len; i++) {
|
|
1214
|
+
const toModel = models[i];
|
|
1215
|
+
const node = graph[toModel];
|
|
1216
|
+
|
|
1217
|
+
if (node.parent === null) {
|
|
1218
|
+
// No possible conversion, or this node is the source model.
|
|
1219
|
+
continue;
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
conversion[toModel] = wrapConversion(toModel, graph);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
return conversion;
|
|
1226
|
+
};
|
|
1227
|
+
|
|
1228
|
+
const convert$1 = {};
|
|
1229
|
+
|
|
1230
|
+
const models = Object.keys(conversions);
|
|
1231
|
+
|
|
1232
|
+
function wrapRaw(fn) {
|
|
1233
|
+
const wrappedFn = function (...args) {
|
|
1234
|
+
const arg0 = args[0];
|
|
1235
|
+
if (arg0 === undefined || arg0 === null) {
|
|
1236
|
+
return arg0;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
if (arg0.length > 1) {
|
|
1240
|
+
args = arg0;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
return fn(args);
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1246
|
+
// Preserve .conversion property if there is one
|
|
1247
|
+
if ('conversion' in fn) {
|
|
1248
|
+
wrappedFn.conversion = fn.conversion;
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
return wrappedFn;
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
function wrapRounded(fn) {
|
|
1255
|
+
const wrappedFn = function (...args) {
|
|
1256
|
+
const arg0 = args[0];
|
|
1257
|
+
|
|
1258
|
+
if (arg0 === undefined || arg0 === null) {
|
|
1259
|
+
return arg0;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
if (arg0.length > 1) {
|
|
1263
|
+
args = arg0;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
const result = fn(args);
|
|
1267
|
+
|
|
1268
|
+
// We're assuming the result is an array here.
|
|
1269
|
+
// see notice in conversions.js; don't use box types
|
|
1270
|
+
// in conversion functions.
|
|
1271
|
+
if (typeof result === 'object') {
|
|
1272
|
+
for (let len = result.length, i = 0; i < len; i++) {
|
|
1273
|
+
result[i] = Math.round(result[i]);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
return result;
|
|
1278
|
+
};
|
|
1279
|
+
|
|
1280
|
+
// Preserve .conversion property if there is one
|
|
1281
|
+
if ('conversion' in fn) {
|
|
1282
|
+
wrappedFn.conversion = fn.conversion;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
return wrappedFn;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
models.forEach(fromModel => {
|
|
1289
|
+
convert$1[fromModel] = {};
|
|
1290
|
+
|
|
1291
|
+
Object.defineProperty(convert$1[fromModel], 'channels', {value: conversions[fromModel].channels});
|
|
1292
|
+
Object.defineProperty(convert$1[fromModel], 'labels', {value: conversions[fromModel].labels});
|
|
1293
|
+
|
|
1294
|
+
const routes = route(fromModel);
|
|
1295
|
+
const routeModels = Object.keys(routes);
|
|
1296
|
+
|
|
1297
|
+
routeModels.forEach(toModel => {
|
|
1298
|
+
const fn = routes[toModel];
|
|
1299
|
+
|
|
1300
|
+
convert$1[fromModel][toModel] = wrapRounded(fn);
|
|
1301
|
+
convert$1[fromModel][toModel].raw = wrapRaw(fn);
|
|
1302
|
+
});
|
|
1303
|
+
});
|
|
1304
|
+
|
|
1305
|
+
var colorConvert = convert$1;
|
|
1306
|
+
|
|
1307
|
+
var ansiStyles = createCommonjsModule(function (module) {
|
|
1308
|
+
|
|
1309
|
+
const wrapAnsi16 = (fn, offset) => (...args) => {
|
|
1310
|
+
const code = fn(...args);
|
|
1311
|
+
return `\u001B[${code + offset}m`;
|
|
1312
|
+
};
|
|
1313
|
+
|
|
1314
|
+
const wrapAnsi256 = (fn, offset) => (...args) => {
|
|
1315
|
+
const code = fn(...args);
|
|
1316
|
+
return `\u001B[${38 + offset};5;${code}m`;
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
const wrapAnsi16m = (fn, offset) => (...args) => {
|
|
1320
|
+
const rgb = fn(...args);
|
|
1321
|
+
return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
|
|
1322
|
+
};
|
|
1323
|
+
|
|
1324
|
+
const ansi2ansi = n => n;
|
|
1325
|
+
const rgb2rgb = (r, g, b) => [r, g, b];
|
|
1326
|
+
|
|
1327
|
+
const setLazyProperty = (object, property, get) => {
|
|
1328
|
+
Object.defineProperty(object, property, {
|
|
1329
|
+
get: () => {
|
|
1330
|
+
const value = get();
|
|
1331
|
+
|
|
1332
|
+
Object.defineProperty(object, property, {
|
|
1333
|
+
value,
|
|
1334
|
+
enumerable: true,
|
|
1335
|
+
configurable: true
|
|
1336
|
+
});
|
|
1337
|
+
|
|
1338
|
+
return value;
|
|
1339
|
+
},
|
|
1340
|
+
enumerable: true,
|
|
1341
|
+
configurable: true
|
|
1342
|
+
});
|
|
1343
|
+
};
|
|
1344
|
+
|
|
1345
|
+
/** @type {typeof import('color-convert')} */
|
|
1346
|
+
let colorConvert$1;
|
|
1347
|
+
const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
|
|
1348
|
+
if (colorConvert$1 === undefined) {
|
|
1349
|
+
colorConvert$1 = colorConvert;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
const offset = isBackground ? 10 : 0;
|
|
1353
|
+
const styles = {};
|
|
1354
|
+
|
|
1355
|
+
for (const [sourceSpace, suite] of Object.entries(colorConvert$1)) {
|
|
1356
|
+
const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace;
|
|
1357
|
+
if (sourceSpace === targetSpace) {
|
|
1358
|
+
styles[name] = wrap(identity, offset);
|
|
1359
|
+
} else if (typeof suite === 'object') {
|
|
1360
|
+
styles[name] = wrap(suite[targetSpace], offset);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
return styles;
|
|
1365
|
+
};
|
|
1366
|
+
|
|
1367
|
+
function assembleStyles() {
|
|
1368
|
+
const codes = new Map();
|
|
1369
|
+
const styles = {
|
|
1370
|
+
modifier: {
|
|
1371
|
+
reset: [0, 0],
|
|
1372
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
1373
|
+
bold: [1, 22],
|
|
1374
|
+
dim: [2, 22],
|
|
1375
|
+
italic: [3, 23],
|
|
1376
|
+
underline: [4, 24],
|
|
1377
|
+
inverse: [7, 27],
|
|
1378
|
+
hidden: [8, 28],
|
|
1379
|
+
strikethrough: [9, 29]
|
|
1380
|
+
},
|
|
1381
|
+
color: {
|
|
1382
|
+
black: [30, 39],
|
|
1383
|
+
red: [31, 39],
|
|
1384
|
+
green: [32, 39],
|
|
1385
|
+
yellow: [33, 39],
|
|
1386
|
+
blue: [34, 39],
|
|
1387
|
+
magenta: [35, 39],
|
|
1388
|
+
cyan: [36, 39],
|
|
1389
|
+
white: [37, 39],
|
|
1390
|
+
|
|
1391
|
+
// Bright color
|
|
1392
|
+
blackBright: [90, 39],
|
|
1393
|
+
redBright: [91, 39],
|
|
1394
|
+
greenBright: [92, 39],
|
|
1395
|
+
yellowBright: [93, 39],
|
|
1396
|
+
blueBright: [94, 39],
|
|
1397
|
+
magentaBright: [95, 39],
|
|
1398
|
+
cyanBright: [96, 39],
|
|
1399
|
+
whiteBright: [97, 39]
|
|
1400
|
+
},
|
|
1401
|
+
bgColor: {
|
|
1402
|
+
bgBlack: [40, 49],
|
|
1403
|
+
bgRed: [41, 49],
|
|
1404
|
+
bgGreen: [42, 49],
|
|
1405
|
+
bgYellow: [43, 49],
|
|
1406
|
+
bgBlue: [44, 49],
|
|
1407
|
+
bgMagenta: [45, 49],
|
|
1408
|
+
bgCyan: [46, 49],
|
|
1409
|
+
bgWhite: [47, 49],
|
|
1410
|
+
|
|
1411
|
+
// Bright color
|
|
1412
|
+
bgBlackBright: [100, 49],
|
|
1413
|
+
bgRedBright: [101, 49],
|
|
1414
|
+
bgGreenBright: [102, 49],
|
|
1415
|
+
bgYellowBright: [103, 49],
|
|
1416
|
+
bgBlueBright: [104, 49],
|
|
1417
|
+
bgMagentaBright: [105, 49],
|
|
1418
|
+
bgCyanBright: [106, 49],
|
|
1419
|
+
bgWhiteBright: [107, 49]
|
|
1420
|
+
}
|
|
1421
|
+
};
|
|
1422
|
+
|
|
1423
|
+
// Alias bright black as gray (and grey)
|
|
1424
|
+
styles.color.gray = styles.color.blackBright;
|
|
1425
|
+
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
|
1426
|
+
styles.color.grey = styles.color.blackBright;
|
|
1427
|
+
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
|
1428
|
+
|
|
1429
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
1430
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
1431
|
+
styles[styleName] = {
|
|
1432
|
+
open: `\u001B[${style[0]}m`,
|
|
1433
|
+
close: `\u001B[${style[1]}m`
|
|
1434
|
+
};
|
|
1435
|
+
|
|
1436
|
+
group[styleName] = styles[styleName];
|
|
1437
|
+
|
|
1438
|
+
codes.set(style[0], style[1]);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
Object.defineProperty(styles, groupName, {
|
|
1442
|
+
value: group,
|
|
1443
|
+
enumerable: false
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
Object.defineProperty(styles, 'codes', {
|
|
1448
|
+
value: codes,
|
|
1449
|
+
enumerable: false
|
|
1450
|
+
});
|
|
1451
|
+
|
|
1452
|
+
styles.color.close = '\u001B[39m';
|
|
1453
|
+
styles.bgColor.close = '\u001B[49m';
|
|
1454
|
+
|
|
1455
|
+
setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
|
|
1456
|
+
setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
|
|
1457
|
+
setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
|
|
1458
|
+
setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
|
|
1459
|
+
setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
|
|
1460
|
+
setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
|
|
1461
|
+
|
|
1462
|
+
return styles;
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// Make the export immutable
|
|
1466
|
+
Object.defineProperty(module, 'exports', {
|
|
1467
|
+
enumerable: true,
|
|
1468
|
+
get: assembleStyles
|
|
1469
|
+
});
|
|
1470
|
+
});
|
|
39
1471
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1472
|
+
var hasFlag = (flag, argv = process.argv) => {
|
|
1473
|
+
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
|
|
1474
|
+
const position = argv.indexOf(prefix + flag);
|
|
1475
|
+
const terminatorPosition = argv.indexOf('--');
|
|
1476
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
1477
|
+
};
|
|
44
1478
|
|
|
45
|
-
|
|
1479
|
+
const {env} = process;
|
|
1480
|
+
|
|
1481
|
+
let forceColor;
|
|
1482
|
+
if (hasFlag('no-color') ||
|
|
1483
|
+
hasFlag('no-colors') ||
|
|
1484
|
+
hasFlag('color=false') ||
|
|
1485
|
+
hasFlag('color=never')) {
|
|
1486
|
+
forceColor = 0;
|
|
1487
|
+
} else if (hasFlag('color') ||
|
|
1488
|
+
hasFlag('colors') ||
|
|
1489
|
+
hasFlag('color=true') ||
|
|
1490
|
+
hasFlag('color=always')) {
|
|
1491
|
+
forceColor = 1;
|
|
1492
|
+
}
|
|
46
1493
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
1494
|
+
if ('FORCE_COLOR' in env) {
|
|
1495
|
+
if (env.FORCE_COLOR === 'true') {
|
|
1496
|
+
forceColor = 1;
|
|
1497
|
+
} else if (env.FORCE_COLOR === 'false') {
|
|
1498
|
+
forceColor = 0;
|
|
1499
|
+
} else {
|
|
1500
|
+
forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
51
1503
|
|
|
52
|
-
|
|
53
|
-
|
|
1504
|
+
function translateLevel(level) {
|
|
1505
|
+
if (level === 0) {
|
|
1506
|
+
return false;
|
|
1507
|
+
}
|
|
54
1508
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* @param {object} [options]
|
|
63
|
-
* @return {object}
|
|
64
|
-
* @public
|
|
65
|
-
*/
|
|
1509
|
+
return {
|
|
1510
|
+
level,
|
|
1511
|
+
hasBasic: true,
|
|
1512
|
+
has256: level >= 2,
|
|
1513
|
+
has16m: level >= 3
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
66
1516
|
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
1517
|
+
function supportsColor(haveStream, streamIsTTY) {
|
|
1518
|
+
if (forceColor === 0) {
|
|
1519
|
+
return 0;
|
|
1520
|
+
}
|
|
71
1521
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
1522
|
+
if (hasFlag('color=16m') ||
|
|
1523
|
+
hasFlag('color=full') ||
|
|
1524
|
+
hasFlag('color=truecolor')) {
|
|
1525
|
+
return 3;
|
|
1526
|
+
}
|
|
76
1527
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1528
|
+
if (hasFlag('color=256')) {
|
|
1529
|
+
return 2;
|
|
1530
|
+
}
|
|
80
1531
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
1532
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
1533
|
+
return 0;
|
|
1534
|
+
}
|
|
85
1535
|
|
|
86
|
-
|
|
87
|
-
var val = pair.substr(++eq_idx, pair.length).trim();
|
|
1536
|
+
const min = forceColor || 0;
|
|
88
1537
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
1538
|
+
if (env.TERM === 'dumb') {
|
|
1539
|
+
return min;
|
|
1540
|
+
}
|
|
93
1541
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
1542
|
+
if (process.platform === 'win32') {
|
|
1543
|
+
// Windows 10 build 10586 is the first Windows release that supports 256 colors.
|
|
1544
|
+
// Windows 10 build 14931 is the first release that supports 16m/TrueColor.
|
|
1545
|
+
const osRelease = os__default['default'].release().split('.');
|
|
1546
|
+
if (
|
|
1547
|
+
Number(osRelease[0]) >= 10 &&
|
|
1548
|
+
Number(osRelease[2]) >= 10586
|
|
1549
|
+
) {
|
|
1550
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
1551
|
+
}
|
|
99
1552
|
|
|
100
|
-
|
|
1553
|
+
return 1;
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
if ('CI' in env) {
|
|
1557
|
+
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
|
1558
|
+
return 1;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
return min;
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
if ('TEAMCITY_VERSION' in env) {
|
|
1565
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
if ('GITHUB_ACTIONS' in env) {
|
|
1569
|
+
return 1;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
if (env.COLORTERM === 'truecolor') {
|
|
1573
|
+
return 3;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
if ('TERM_PROGRAM' in env) {
|
|
1577
|
+
const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
1578
|
+
|
|
1579
|
+
switch (env.TERM_PROGRAM) {
|
|
1580
|
+
case 'iTerm.app':
|
|
1581
|
+
return version >= 3 ? 3 : 2;
|
|
1582
|
+
case 'Apple_Terminal':
|
|
1583
|
+
return 2;
|
|
1584
|
+
// No default
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
1589
|
+
return 2;
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
1593
|
+
return 1;
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
if ('COLORTERM' in env) {
|
|
1597
|
+
return 1;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
return min;
|
|
101
1601
|
}
|
|
102
1602
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
* @param {function} decode
|
|
108
|
-
* @private
|
|
109
|
-
*/
|
|
1603
|
+
function getSupportLevel(stream) {
|
|
1604
|
+
const level = supportsColor(stream, stream && stream.isTTY);
|
|
1605
|
+
return translateLevel(level);
|
|
1606
|
+
}
|
|
110
1607
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
1608
|
+
var supportsColor_1 = {
|
|
1609
|
+
supportsColor: getSupportLevel,
|
|
1610
|
+
stdout: translateLevel(supportsColor(true, tty__default['default'].isatty(1))),
|
|
1611
|
+
stderr: translateLevel(supportsColor(true, tty__default['default'].isatty(2)))
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
const stringReplaceAll = (string, substring, replacer) => {
|
|
1615
|
+
let index = string.indexOf(substring);
|
|
1616
|
+
if (index === -1) {
|
|
1617
|
+
return string;
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
const substringLength = substring.length;
|
|
1621
|
+
let endIndex = 0;
|
|
1622
|
+
let returnValue = '';
|
|
1623
|
+
do {
|
|
1624
|
+
returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
|
|
1625
|
+
endIndex = index + substringLength;
|
|
1626
|
+
index = string.indexOf(substring, endIndex);
|
|
1627
|
+
} while (index !== -1);
|
|
1628
|
+
|
|
1629
|
+
returnValue += string.substr(endIndex);
|
|
1630
|
+
return returnValue;
|
|
1631
|
+
};
|
|
1632
|
+
|
|
1633
|
+
const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
|
|
1634
|
+
let endIndex = 0;
|
|
1635
|
+
let returnValue = '';
|
|
1636
|
+
do {
|
|
1637
|
+
const gotCR = string[index - 1] === '\r';
|
|
1638
|
+
returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
|
|
1639
|
+
endIndex = index + 1;
|
|
1640
|
+
index = string.indexOf('\n', endIndex);
|
|
1641
|
+
} while (index !== -1);
|
|
1642
|
+
|
|
1643
|
+
returnValue += string.substr(endIndex);
|
|
1644
|
+
return returnValue;
|
|
1645
|
+
};
|
|
1646
|
+
|
|
1647
|
+
var util = {
|
|
1648
|
+
stringReplaceAll,
|
|
1649
|
+
stringEncaseCRLFWithFirstIndex
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1652
|
+
const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
|
1653
|
+
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
|
1654
|
+
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
|
1655
|
+
const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
|
|
1656
|
+
|
|
1657
|
+
const ESCAPES = new Map([
|
|
1658
|
+
['n', '\n'],
|
|
1659
|
+
['r', '\r'],
|
|
1660
|
+
['t', '\t'],
|
|
1661
|
+
['b', '\b'],
|
|
1662
|
+
['f', '\f'],
|
|
1663
|
+
['v', '\v'],
|
|
1664
|
+
['0', '\0'],
|
|
1665
|
+
['\\', '\\'],
|
|
1666
|
+
['e', '\u001B'],
|
|
1667
|
+
['a', '\u0007']
|
|
1668
|
+
]);
|
|
1669
|
+
|
|
1670
|
+
function unescape(c) {
|
|
1671
|
+
const u = c[0] === 'u';
|
|
1672
|
+
const bracket = c[1] === '{';
|
|
1673
|
+
|
|
1674
|
+
if ((u && !bracket && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
|
|
1675
|
+
return String.fromCharCode(parseInt(c.slice(1), 16));
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
if (u && bracket) {
|
|
1679
|
+
return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
return ESCAPES.get(c) || c;
|
|
117
1683
|
}
|
|
118
1684
|
|
|
119
|
-
|
|
1685
|
+
function parseArguments(name, arguments_) {
|
|
1686
|
+
const results = [];
|
|
1687
|
+
const chunks = arguments_.trim().split(/\s*,\s*/g);
|
|
1688
|
+
let matches;
|
|
1689
|
+
|
|
1690
|
+
for (const chunk of chunks) {
|
|
1691
|
+
const number = Number(chunk);
|
|
1692
|
+
if (!Number.isNaN(number)) {
|
|
1693
|
+
results.push(number);
|
|
1694
|
+
} else if ((matches = chunk.match(STRING_REGEX))) {
|
|
1695
|
+
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character));
|
|
1696
|
+
} else {
|
|
1697
|
+
throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
120
1700
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
1701
|
+
return results;
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
function parseStyle(style) {
|
|
1705
|
+
STYLE_REGEX.lastIndex = 0;
|
|
1706
|
+
|
|
1707
|
+
const results = [];
|
|
1708
|
+
let matches;
|
|
1709
|
+
|
|
1710
|
+
while ((matches = STYLE_REGEX.exec(style)) !== null) {
|
|
1711
|
+
const name = matches[1];
|
|
1712
|
+
|
|
1713
|
+
if (matches[2]) {
|
|
1714
|
+
const args = parseArguments(name, matches[2]);
|
|
1715
|
+
results.push([name].concat(args));
|
|
1716
|
+
} else {
|
|
1717
|
+
results.push([name]);
|
|
127
1718
|
}
|
|
128
|
-
}
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
return results;
|
|
129
1722
|
}
|
|
130
1723
|
|
|
131
|
-
function
|
|
132
|
-
|
|
1724
|
+
function buildStyle(chalk, styles) {
|
|
1725
|
+
const enabled = {};
|
|
1726
|
+
|
|
1727
|
+
for (const layer of styles) {
|
|
1728
|
+
for (const style of layer.styles) {
|
|
1729
|
+
enabled[style[0]] = layer.inverse ? null : style.slice(1);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
let current = chalk;
|
|
1734
|
+
for (const [styleName, styles] of Object.entries(enabled)) {
|
|
1735
|
+
if (!Array.isArray(styles)) {
|
|
1736
|
+
continue;
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
if (!(styleName in current)) {
|
|
1740
|
+
throw new Error(`Unknown Chalk style: ${styleName}`);
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
current = styles.length > 0 ? current[styleName](...styles) : current[styleName];
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
return current;
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
var templates = (chalk, temporary) => {
|
|
1750
|
+
const styles = [];
|
|
1751
|
+
const chunks = [];
|
|
1752
|
+
let chunk = [];
|
|
1753
|
+
|
|
1754
|
+
// eslint-disable-next-line max-params
|
|
1755
|
+
temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
|
|
1756
|
+
if (escapeCharacter) {
|
|
1757
|
+
chunk.push(unescape(escapeCharacter));
|
|
1758
|
+
} else if (style) {
|
|
1759
|
+
const string = chunk.join('');
|
|
1760
|
+
chunk = [];
|
|
1761
|
+
chunks.push(styles.length === 0 ? string : buildStyle(chalk, styles)(string));
|
|
1762
|
+
styles.push({inverse, styles: parseStyle(style)});
|
|
1763
|
+
} else if (close) {
|
|
1764
|
+
if (styles.length === 0) {
|
|
1765
|
+
throw new Error('Found extraneous } in Chalk template literal');
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
chunks.push(buildStyle(chalk, styles)(chunk.join('')));
|
|
1769
|
+
chunk = [];
|
|
1770
|
+
styles.pop();
|
|
1771
|
+
} else {
|
|
1772
|
+
chunk.push(character);
|
|
1773
|
+
}
|
|
1774
|
+
});
|
|
1775
|
+
|
|
1776
|
+
chunks.push(chunk.join(''));
|
|
1777
|
+
|
|
1778
|
+
if (styles.length > 0) {
|
|
1779
|
+
const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
|
|
1780
|
+
throw new Error(errMessage);
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
return chunks.join('');
|
|
1784
|
+
};
|
|
1785
|
+
|
|
1786
|
+
const {stdout: stdoutColor, stderr: stderrColor} = supportsColor_1;
|
|
1787
|
+
const {
|
|
1788
|
+
stringReplaceAll: stringReplaceAll$1,
|
|
1789
|
+
stringEncaseCRLFWithFirstIndex: stringEncaseCRLFWithFirstIndex$1
|
|
1790
|
+
} = util;
|
|
1791
|
+
|
|
1792
|
+
const {isArray} = Array;
|
|
1793
|
+
|
|
1794
|
+
// `supportsColor.level` → `ansiStyles.color[name]` mapping
|
|
1795
|
+
const levelMapping = [
|
|
1796
|
+
'ansi',
|
|
1797
|
+
'ansi',
|
|
1798
|
+
'ansi256',
|
|
1799
|
+
'ansi16m'
|
|
1800
|
+
];
|
|
1801
|
+
|
|
1802
|
+
const styles = Object.create(null);
|
|
1803
|
+
|
|
1804
|
+
const applyOptions = (object, options = {}) => {
|
|
1805
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
1806
|
+
throw new Error('The `level` option should be an integer from 0 to 3');
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
// Detect level if not set manually
|
|
1810
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
1811
|
+
object.level = options.level === undefined ? colorLevel : options.level;
|
|
1812
|
+
};
|
|
1813
|
+
|
|
1814
|
+
class ChalkClass {
|
|
1815
|
+
constructor(options) {
|
|
1816
|
+
// eslint-disable-next-line no-constructor-return
|
|
1817
|
+
return chalkFactory(options);
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
const chalkFactory = options => {
|
|
1822
|
+
const chalk = {};
|
|
1823
|
+
applyOptions(chalk, options);
|
|
1824
|
+
|
|
1825
|
+
chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_);
|
|
1826
|
+
|
|
1827
|
+
Object.setPrototypeOf(chalk, Chalk.prototype);
|
|
1828
|
+
Object.setPrototypeOf(chalk.template, chalk);
|
|
1829
|
+
|
|
1830
|
+
chalk.template.constructor = () => {
|
|
1831
|
+
throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.');
|
|
1832
|
+
};
|
|
1833
|
+
|
|
1834
|
+
chalk.template.Instance = ChalkClass;
|
|
1835
|
+
|
|
1836
|
+
return chalk.template;
|
|
1837
|
+
};
|
|
1838
|
+
|
|
1839
|
+
function Chalk(options) {
|
|
1840
|
+
return chalkFactory(options);
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
for (const [styleName, style] of Object.entries(ansiStyles)) {
|
|
1844
|
+
styles[styleName] = {
|
|
1845
|
+
get() {
|
|
1846
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
|
|
1847
|
+
Object.defineProperty(this, styleName, {value: builder});
|
|
1848
|
+
return builder;
|
|
1849
|
+
}
|
|
1850
|
+
};
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
styles.visible = {
|
|
1854
|
+
get() {
|
|
1855
|
+
const builder = createBuilder(this, this._styler, true);
|
|
1856
|
+
Object.defineProperty(this, 'visible', {value: builder});
|
|
1857
|
+
return builder;
|
|
1858
|
+
}
|
|
1859
|
+
};
|
|
1860
|
+
|
|
1861
|
+
const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256'];
|
|
1862
|
+
|
|
1863
|
+
for (const model of usedModels) {
|
|
1864
|
+
styles[model] = {
|
|
1865
|
+
get() {
|
|
1866
|
+
const {level} = this;
|
|
1867
|
+
return function (...arguments_) {
|
|
1868
|
+
const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler);
|
|
1869
|
+
return createBuilder(this, styler, this._isEmpty);
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
for (const model of usedModels) {
|
|
1876
|
+
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
|
1877
|
+
styles[bgModel] = {
|
|
1878
|
+
get() {
|
|
1879
|
+
const {level} = this;
|
|
1880
|
+
return function (...arguments_) {
|
|
1881
|
+
const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler);
|
|
1882
|
+
return createBuilder(this, styler, this._isEmpty);
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
133
1886
|
}
|
|
134
1887
|
|
|
1888
|
+
const proto = Object.defineProperties(() => {}, {
|
|
1889
|
+
...styles,
|
|
1890
|
+
level: {
|
|
1891
|
+
enumerable: true,
|
|
1892
|
+
get() {
|
|
1893
|
+
return this._generator.level;
|
|
1894
|
+
},
|
|
1895
|
+
set(level) {
|
|
1896
|
+
this._generator.level = level;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
});
|
|
1900
|
+
|
|
1901
|
+
const createStyler = (open, close, parent) => {
|
|
1902
|
+
let openAll;
|
|
1903
|
+
let closeAll;
|
|
1904
|
+
if (parent === undefined) {
|
|
1905
|
+
openAll = open;
|
|
1906
|
+
closeAll = close;
|
|
1907
|
+
} else {
|
|
1908
|
+
openAll = parent.openAll + open;
|
|
1909
|
+
closeAll = close + parent.closeAll;
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
return {
|
|
1913
|
+
open,
|
|
1914
|
+
close,
|
|
1915
|
+
openAll,
|
|
1916
|
+
closeAll,
|
|
1917
|
+
parent
|
|
1918
|
+
};
|
|
1919
|
+
};
|
|
1920
|
+
|
|
1921
|
+
const createBuilder = (self, _styler, _isEmpty) => {
|
|
1922
|
+
const builder = (...arguments_) => {
|
|
1923
|
+
if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
|
|
1924
|
+
// Called as a template literal, for example: chalk.red`2 + 3 = {bold ${2+3}}`
|
|
1925
|
+
return applyStyle(builder, chalkTag(builder, ...arguments_));
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
// Single argument is hot path, implicit coercion is faster than anything
|
|
1929
|
+
// eslint-disable-next-line no-implicit-coercion
|
|
1930
|
+
return applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
|
|
1931
|
+
};
|
|
1932
|
+
|
|
1933
|
+
// We alter the prototype because we must return a function, but there is
|
|
1934
|
+
// no way to create a function with a different prototype
|
|
1935
|
+
Object.setPrototypeOf(builder, proto);
|
|
1936
|
+
|
|
1937
|
+
builder._generator = self;
|
|
1938
|
+
builder._styler = _styler;
|
|
1939
|
+
builder._isEmpty = _isEmpty;
|
|
1940
|
+
|
|
1941
|
+
return builder;
|
|
1942
|
+
};
|
|
1943
|
+
|
|
1944
|
+
const applyStyle = (self, string) => {
|
|
1945
|
+
if (self.level <= 0 || !string) {
|
|
1946
|
+
return self._isEmpty ? '' : string;
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
let styler = self._styler;
|
|
1950
|
+
|
|
1951
|
+
if (styler === undefined) {
|
|
1952
|
+
return string;
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
const {openAll, closeAll} = styler;
|
|
1956
|
+
if (string.indexOf('\u001B') !== -1) {
|
|
1957
|
+
while (styler !== undefined) {
|
|
1958
|
+
// Replace any instances already present with a re-opening code
|
|
1959
|
+
// otherwise only the part of the string until said closing code
|
|
1960
|
+
// will be colored, and the rest will simply be 'plain'.
|
|
1961
|
+
string = stringReplaceAll$1(string, styler.close, styler.open);
|
|
1962
|
+
|
|
1963
|
+
styler = styler.parent;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
// We can move both next actions out of loop, because remaining actions in loop won't have
|
|
1968
|
+
// any/visible effect on parts we add here. Close the styling before a linebreak and reopen
|
|
1969
|
+
// after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
|
|
1970
|
+
const lfIndex = string.indexOf('\n');
|
|
1971
|
+
if (lfIndex !== -1) {
|
|
1972
|
+
string = stringEncaseCRLFWithFirstIndex$1(string, closeAll, openAll, lfIndex);
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
return openAll + string + closeAll;
|
|
1976
|
+
};
|
|
1977
|
+
|
|
1978
|
+
let template;
|
|
1979
|
+
const chalkTag = (chalk, ...strings) => {
|
|
1980
|
+
const [firstString] = strings;
|
|
1981
|
+
|
|
1982
|
+
if (!isArray(firstString) || !isArray(firstString.raw)) {
|
|
1983
|
+
// If chalk() was called by itself or with a string,
|
|
1984
|
+
// return the string itself as a string.
|
|
1985
|
+
return strings.join(' ');
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
const arguments_ = strings.slice(1);
|
|
1989
|
+
const parts = [firstString.raw[0]];
|
|
1990
|
+
|
|
1991
|
+
for (let i = 1; i < firstString.length; i++) {
|
|
1992
|
+
parts.push(
|
|
1993
|
+
String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'),
|
|
1994
|
+
String(firstString.raw[i])
|
|
1995
|
+
);
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
if (template === undefined) {
|
|
1999
|
+
template = templates;
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
return template(chalk, parts.join(''));
|
|
2003
|
+
};
|
|
2004
|
+
|
|
2005
|
+
Object.defineProperties(Chalk.prototype, styles);
|
|
2006
|
+
|
|
2007
|
+
const chalk = Chalk(); // eslint-disable-line new-cap
|
|
2008
|
+
chalk.supportsColor = stdoutColor;
|
|
2009
|
+
chalk.stderr = Chalk({level: stderrColor ? stderrColor.level : 0}); // eslint-disable-line new-cap
|
|
2010
|
+
chalk.stderr.supportsColor = stderrColor;
|
|
2011
|
+
|
|
2012
|
+
var source = chalk;
|
|
2013
|
+
|
|
135
2014
|
var Headers_1 = createCommonjsModule(function (module, exports) {
|
|
136
2015
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
137
2016
|
var HEADERS_INVALID_CHARACTERS = /[^a-z0-9\-#$%&'*+.^_`|~]/i;
|
|
@@ -1243,7 +3122,7 @@ var punycode = createCommonjsModule(function (module, exports) {
|
|
|
1243
3122
|
}(commonjsGlobal));
|
|
1244
3123
|
});
|
|
1245
3124
|
|
|
1246
|
-
var util = {
|
|
3125
|
+
var util$1 = {
|
|
1247
3126
|
isString: function(arg) {
|
|
1248
3127
|
return typeof(arg) === 'string';
|
|
1249
3128
|
},
|
|
@@ -1438,7 +3317,7 @@ var protocolPattern = /^([a-z0-9.+-]+:)/i,
|
|
|
1438
3317
|
};
|
|
1439
3318
|
|
|
1440
3319
|
function urlParse(url, parseQueryString, slashesDenoteHost) {
|
|
1441
|
-
if (url && util.isObject(url) && url instanceof Url) return url;
|
|
3320
|
+
if (url && util$1.isObject(url) && url instanceof Url) return url;
|
|
1442
3321
|
|
|
1443
3322
|
var u = new Url;
|
|
1444
3323
|
u.parse(url, parseQueryString, slashesDenoteHost);
|
|
@@ -1446,7 +3325,7 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
|
|
|
1446
3325
|
}
|
|
1447
3326
|
|
|
1448
3327
|
Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
|
|
1449
|
-
if (!util.isString(url)) {
|
|
3328
|
+
if (!util$1.isString(url)) {
|
|
1450
3329
|
throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
|
|
1451
3330
|
}
|
|
1452
3331
|
|
|
@@ -1712,7 +3591,7 @@ function urlFormat(obj) {
|
|
|
1712
3591
|
// If it's an obj, this is a no-op.
|
|
1713
3592
|
// this way, you can call url_format() on strings
|
|
1714
3593
|
// to clean up potentially wonky urls.
|
|
1715
|
-
if (util.isString(obj)) obj = urlParse(obj);
|
|
3594
|
+
if (util$1.isString(obj)) obj = urlParse(obj);
|
|
1716
3595
|
if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
|
|
1717
3596
|
return obj.format();
|
|
1718
3597
|
}
|
|
@@ -1743,7 +3622,7 @@ Url.prototype.format = function() {
|
|
|
1743
3622
|
}
|
|
1744
3623
|
|
|
1745
3624
|
if (this.query &&
|
|
1746
|
-
util.isObject(this.query) &&
|
|
3625
|
+
util$1.isObject(this.query) &&
|
|
1747
3626
|
Object.keys(this.query).length) {
|
|
1748
3627
|
query = querystring.stringify(this.query);
|
|
1749
3628
|
}
|
|
@@ -1778,7 +3657,7 @@ Url.prototype.resolve = function(relative) {
|
|
|
1778
3657
|
};
|
|
1779
3658
|
|
|
1780
3659
|
Url.prototype.resolveObject = function(relative) {
|
|
1781
|
-
if (util.isString(relative)) {
|
|
3660
|
+
if (util$1.isString(relative)) {
|
|
1782
3661
|
var rel = new Url();
|
|
1783
3662
|
rel.parse(relative, false, true);
|
|
1784
3663
|
relative = rel;
|
|
@@ -1924,7 +3803,7 @@ Url.prototype.resolveObject = function(relative) {
|
|
|
1924
3803
|
srcPath = srcPath.concat(relPath);
|
|
1925
3804
|
result.search = relative.search;
|
|
1926
3805
|
result.query = relative.query;
|
|
1927
|
-
} else if (!util.isNullOrUndefined(relative.search)) {
|
|
3806
|
+
} else if (!util$1.isNullOrUndefined(relative.search)) {
|
|
1928
3807
|
// just pull out the search.
|
|
1929
3808
|
// like href='?foo'.
|
|
1930
3809
|
// Put this after the other two cases because it simplifies the booleans
|
|
@@ -1943,7 +3822,7 @@ Url.prototype.resolveObject = function(relative) {
|
|
|
1943
3822
|
result.search = relative.search;
|
|
1944
3823
|
result.query = relative.query;
|
|
1945
3824
|
//to support http.request
|
|
1946
|
-
if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
|
|
3825
|
+
if (!util$1.isNull(result.pathname) || !util$1.isNull(result.search)) {
|
|
1947
3826
|
result.path = (result.pathname ? result.pathname : '') +
|
|
1948
3827
|
(result.search ? result.search : '');
|
|
1949
3828
|
}
|
|
@@ -2037,7 +3916,7 @@ Url.prototype.resolveObject = function(relative) {
|
|
|
2037
3916
|
}
|
|
2038
3917
|
|
|
2039
3918
|
//to support request.http
|
|
2040
|
-
if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
|
|
3919
|
+
if (!util$1.isNull(result.pathname) || !util$1.isNull(result.search)) {
|
|
2041
3920
|
result.path = (result.pathname ? result.pathname : '') +
|
|
2042
3921
|
(result.search ? result.search : '');
|
|
2043
3922
|
}
|
|
@@ -2187,6 +4066,21 @@ function createSetupServer(...interceptors) {
|
|
|
2187
4066
|
resetHandlers(...nextHandlers) {
|
|
2188
4067
|
currentHandlers = resetHandlers(requestHandlers, ...nextHandlers);
|
|
2189
4068
|
},
|
|
4069
|
+
/**
|
|
4070
|
+
* Prints the list of currently active request handlers.
|
|
4071
|
+
*/
|
|
4072
|
+
printHandlers() {
|
|
4073
|
+
currentHandlers.forEach((handler) => {
|
|
4074
|
+
const meta = handler.getMetaInfo();
|
|
4075
|
+
console.log(`\
|
|
4076
|
+
${source.bold(meta.header)}
|
|
4077
|
+
Declaration: ${meta.callFrame}
|
|
4078
|
+
`);
|
|
4079
|
+
});
|
|
4080
|
+
},
|
|
4081
|
+
/**
|
|
4082
|
+
* Stops requests interception by restoring all augmented modules.
|
|
4083
|
+
*/
|
|
2190
4084
|
close() {
|
|
2191
4085
|
interceptor.restore();
|
|
2192
4086
|
},
|