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