@logto/connector-apple 1.0.0 → 1.0.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/LICENSE +379 -21
- package/lib/index.js +32 -2063
- package/package.json +23 -42
package/lib/index.js
CHANGED
|
@@ -1,1975 +1,23 @@
|
|
|
1
1
|
import { ConnectorPlatform, ConnectorConfigFormItemType, ConnectorType, validateConfig, ConnectorError, ConnectorErrorCodes } from '@logto/connector-kit';
|
|
2
2
|
import * as crypto from 'crypto';
|
|
3
|
-
import { randomFillSync, KeyObject, createPublicKey,
|
|
3
|
+
import { randomFillSync, KeyObject, createPublicKey, createPrivateKey, createSecretKey, constants } from 'crypto';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
6
6
|
import * as util from 'util';
|
|
7
7
|
import { promisify } from 'util';
|
|
8
|
-
import { inflateRaw, deflateRaw } from 'zlib';
|
|
9
8
|
import * as http from 'http';
|
|
10
9
|
import * as https from 'https';
|
|
11
10
|
import { once } from 'events';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"aliceblue": [240, 248, 255],
|
|
21
|
-
"antiquewhite": [250, 235, 215],
|
|
22
|
-
"aqua": [0, 255, 255],
|
|
23
|
-
"aquamarine": [127, 255, 212],
|
|
24
|
-
"azure": [240, 255, 255],
|
|
25
|
-
"beige": [245, 245, 220],
|
|
26
|
-
"bisque": [255, 228, 196],
|
|
27
|
-
"black": [0, 0, 0],
|
|
28
|
-
"blanchedalmond": [255, 235, 205],
|
|
29
|
-
"blue": [0, 0, 255],
|
|
30
|
-
"blueviolet": [138, 43, 226],
|
|
31
|
-
"brown": [165, 42, 42],
|
|
32
|
-
"burlywood": [222, 184, 135],
|
|
33
|
-
"cadetblue": [95, 158, 160],
|
|
34
|
-
"chartreuse": [127, 255, 0],
|
|
35
|
-
"chocolate": [210, 105, 30],
|
|
36
|
-
"coral": [255, 127, 80],
|
|
37
|
-
"cornflowerblue": [100, 149, 237],
|
|
38
|
-
"cornsilk": [255, 248, 220],
|
|
39
|
-
"crimson": [220, 20, 60],
|
|
40
|
-
"cyan": [0, 255, 255],
|
|
41
|
-
"darkblue": [0, 0, 139],
|
|
42
|
-
"darkcyan": [0, 139, 139],
|
|
43
|
-
"darkgoldenrod": [184, 134, 11],
|
|
44
|
-
"darkgray": [169, 169, 169],
|
|
45
|
-
"darkgreen": [0, 100, 0],
|
|
46
|
-
"darkgrey": [169, 169, 169],
|
|
47
|
-
"darkkhaki": [189, 183, 107],
|
|
48
|
-
"darkmagenta": [139, 0, 139],
|
|
49
|
-
"darkolivegreen": [85, 107, 47],
|
|
50
|
-
"darkorange": [255, 140, 0],
|
|
51
|
-
"darkorchid": [153, 50, 204],
|
|
52
|
-
"darkred": [139, 0, 0],
|
|
53
|
-
"darksalmon": [233, 150, 122],
|
|
54
|
-
"darkseagreen": [143, 188, 143],
|
|
55
|
-
"darkslateblue": [72, 61, 139],
|
|
56
|
-
"darkslategray": [47, 79, 79],
|
|
57
|
-
"darkslategrey": [47, 79, 79],
|
|
58
|
-
"darkturquoise": [0, 206, 209],
|
|
59
|
-
"darkviolet": [148, 0, 211],
|
|
60
|
-
"deeppink": [255, 20, 147],
|
|
61
|
-
"deepskyblue": [0, 191, 255],
|
|
62
|
-
"dimgray": [105, 105, 105],
|
|
63
|
-
"dimgrey": [105, 105, 105],
|
|
64
|
-
"dodgerblue": [30, 144, 255],
|
|
65
|
-
"firebrick": [178, 34, 34],
|
|
66
|
-
"floralwhite": [255, 250, 240],
|
|
67
|
-
"forestgreen": [34, 139, 34],
|
|
68
|
-
"fuchsia": [255, 0, 255],
|
|
69
|
-
"gainsboro": [220, 220, 220],
|
|
70
|
-
"ghostwhite": [248, 248, 255],
|
|
71
|
-
"gold": [255, 215, 0],
|
|
72
|
-
"goldenrod": [218, 165, 32],
|
|
73
|
-
"gray": [128, 128, 128],
|
|
74
|
-
"green": [0, 128, 0],
|
|
75
|
-
"greenyellow": [173, 255, 47],
|
|
76
|
-
"grey": [128, 128, 128],
|
|
77
|
-
"honeydew": [240, 255, 240],
|
|
78
|
-
"hotpink": [255, 105, 180],
|
|
79
|
-
"indianred": [205, 92, 92],
|
|
80
|
-
"indigo": [75, 0, 130],
|
|
81
|
-
"ivory": [255, 255, 240],
|
|
82
|
-
"khaki": [240, 230, 140],
|
|
83
|
-
"lavender": [230, 230, 250],
|
|
84
|
-
"lavenderblush": [255, 240, 245],
|
|
85
|
-
"lawngreen": [124, 252, 0],
|
|
86
|
-
"lemonchiffon": [255, 250, 205],
|
|
87
|
-
"lightblue": [173, 216, 230],
|
|
88
|
-
"lightcoral": [240, 128, 128],
|
|
89
|
-
"lightcyan": [224, 255, 255],
|
|
90
|
-
"lightgoldenrodyellow": [250, 250, 210],
|
|
91
|
-
"lightgray": [211, 211, 211],
|
|
92
|
-
"lightgreen": [144, 238, 144],
|
|
93
|
-
"lightgrey": [211, 211, 211],
|
|
94
|
-
"lightpink": [255, 182, 193],
|
|
95
|
-
"lightsalmon": [255, 160, 122],
|
|
96
|
-
"lightseagreen": [32, 178, 170],
|
|
97
|
-
"lightskyblue": [135, 206, 250],
|
|
98
|
-
"lightslategray": [119, 136, 153],
|
|
99
|
-
"lightslategrey": [119, 136, 153],
|
|
100
|
-
"lightsteelblue": [176, 196, 222],
|
|
101
|
-
"lightyellow": [255, 255, 224],
|
|
102
|
-
"lime": [0, 255, 0],
|
|
103
|
-
"limegreen": [50, 205, 50],
|
|
104
|
-
"linen": [250, 240, 230],
|
|
105
|
-
"magenta": [255, 0, 255],
|
|
106
|
-
"maroon": [128, 0, 0],
|
|
107
|
-
"mediumaquamarine": [102, 205, 170],
|
|
108
|
-
"mediumblue": [0, 0, 205],
|
|
109
|
-
"mediumorchid": [186, 85, 211],
|
|
110
|
-
"mediumpurple": [147, 112, 219],
|
|
111
|
-
"mediumseagreen": [60, 179, 113],
|
|
112
|
-
"mediumslateblue": [123, 104, 238],
|
|
113
|
-
"mediumspringgreen": [0, 250, 154],
|
|
114
|
-
"mediumturquoise": [72, 209, 204],
|
|
115
|
-
"mediumvioletred": [199, 21, 133],
|
|
116
|
-
"midnightblue": [25, 25, 112],
|
|
117
|
-
"mintcream": [245, 255, 250],
|
|
118
|
-
"mistyrose": [255, 228, 225],
|
|
119
|
-
"moccasin": [255, 228, 181],
|
|
120
|
-
"navajowhite": [255, 222, 173],
|
|
121
|
-
"navy": [0, 0, 128],
|
|
122
|
-
"oldlace": [253, 245, 230],
|
|
123
|
-
"olive": [128, 128, 0],
|
|
124
|
-
"olivedrab": [107, 142, 35],
|
|
125
|
-
"orange": [255, 165, 0],
|
|
126
|
-
"orangered": [255, 69, 0],
|
|
127
|
-
"orchid": [218, 112, 214],
|
|
128
|
-
"palegoldenrod": [238, 232, 170],
|
|
129
|
-
"palegreen": [152, 251, 152],
|
|
130
|
-
"paleturquoise": [175, 238, 238],
|
|
131
|
-
"palevioletred": [219, 112, 147],
|
|
132
|
-
"papayawhip": [255, 239, 213],
|
|
133
|
-
"peachpuff": [255, 218, 185],
|
|
134
|
-
"peru": [205, 133, 63],
|
|
135
|
-
"pink": [255, 192, 203],
|
|
136
|
-
"plum": [221, 160, 221],
|
|
137
|
-
"powderblue": [176, 224, 230],
|
|
138
|
-
"purple": [128, 0, 128],
|
|
139
|
-
"rebeccapurple": [102, 51, 153],
|
|
140
|
-
"red": [255, 0, 0],
|
|
141
|
-
"rosybrown": [188, 143, 143],
|
|
142
|
-
"royalblue": [65, 105, 225],
|
|
143
|
-
"saddlebrown": [139, 69, 19],
|
|
144
|
-
"salmon": [250, 128, 114],
|
|
145
|
-
"sandybrown": [244, 164, 96],
|
|
146
|
-
"seagreen": [46, 139, 87],
|
|
147
|
-
"seashell": [255, 245, 238],
|
|
148
|
-
"sienna": [160, 82, 45],
|
|
149
|
-
"silver": [192, 192, 192],
|
|
150
|
-
"skyblue": [135, 206, 235],
|
|
151
|
-
"slateblue": [106, 90, 205],
|
|
152
|
-
"slategray": [112, 128, 144],
|
|
153
|
-
"slategrey": [112, 128, 144],
|
|
154
|
-
"snow": [255, 250, 250],
|
|
155
|
-
"springgreen": [0, 255, 127],
|
|
156
|
-
"steelblue": [70, 130, 180],
|
|
157
|
-
"tan": [210, 180, 140],
|
|
158
|
-
"teal": [0, 128, 128],
|
|
159
|
-
"thistle": [216, 191, 216],
|
|
160
|
-
"tomato": [255, 99, 71],
|
|
161
|
-
"turquoise": [64, 224, 208],
|
|
162
|
-
"violet": [238, 130, 238],
|
|
163
|
-
"wheat": [245, 222, 179],
|
|
164
|
-
"white": [255, 255, 255],
|
|
165
|
-
"whitesmoke": [245, 245, 245],
|
|
166
|
-
"yellow": [255, 255, 0],
|
|
167
|
-
"yellowgreen": [154, 205, 50]
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
var simpleSwizzleExports = {};
|
|
171
|
-
var simpleSwizzle = {
|
|
172
|
-
get exports(){ return simpleSwizzleExports; },
|
|
173
|
-
set exports(v){ simpleSwizzleExports = v; },
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
var isArrayish$1 = function isArrayish(obj) {
|
|
177
|
-
if (!obj || typeof obj === 'string') {
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return obj instanceof Array || Array.isArray(obj) ||
|
|
182
|
-
(obj.length >= 0 && (obj.splice instanceof Function ||
|
|
183
|
-
(Object.getOwnPropertyDescriptor(obj, (obj.length - 1)) && obj.constructor.name !== 'String')));
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
var isArrayish = isArrayish$1;
|
|
187
|
-
|
|
188
|
-
var concat$1 = Array.prototype.concat;
|
|
189
|
-
var slice = Array.prototype.slice;
|
|
190
|
-
|
|
191
|
-
var swizzle$1 = simpleSwizzle.exports = function swizzle(args) {
|
|
192
|
-
var results = [];
|
|
193
|
-
|
|
194
|
-
for (var i = 0, len = args.length; i < len; i++) {
|
|
195
|
-
var arg = args[i];
|
|
196
|
-
|
|
197
|
-
if (isArrayish(arg)) {
|
|
198
|
-
// http://jsperf.com/javascript-array-concat-vs-push/98
|
|
199
|
-
results = concat$1.call(results, slice.call(arg));
|
|
200
|
-
} else {
|
|
201
|
-
results.push(arg);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return results;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
swizzle$1.wrap = function (fn) {
|
|
209
|
-
return function () {
|
|
210
|
-
return fn(swizzle$1(arguments));
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
/* MIT license */
|
|
215
|
-
|
|
216
|
-
var colorNames = colorName;
|
|
217
|
-
var swizzle = simpleSwizzleExports;
|
|
218
|
-
var hasOwnProperty = Object.hasOwnProperty;
|
|
219
|
-
|
|
220
|
-
var reverseNames = Object.create(null);
|
|
221
|
-
|
|
222
|
-
// create a list of reverse color names
|
|
223
|
-
for (var name in colorNames) {
|
|
224
|
-
if (hasOwnProperty.call(colorNames, name)) {
|
|
225
|
-
reverseNames[colorNames[name]] = name;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
var cs = colorString$1.exports = {
|
|
230
|
-
to: {},
|
|
231
|
-
get: {}
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
cs.get = function (string) {
|
|
235
|
-
var prefix = string.substring(0, 3).toLowerCase();
|
|
236
|
-
var val;
|
|
237
|
-
var model;
|
|
238
|
-
switch (prefix) {
|
|
239
|
-
case 'hsl':
|
|
240
|
-
val = cs.get.hsl(string);
|
|
241
|
-
model = 'hsl';
|
|
242
|
-
break;
|
|
243
|
-
case 'hwb':
|
|
244
|
-
val = cs.get.hwb(string);
|
|
245
|
-
model = 'hwb';
|
|
246
|
-
break;
|
|
247
|
-
default:
|
|
248
|
-
val = cs.get.rgb(string);
|
|
249
|
-
model = 'rgb';
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (!val) {
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return {model: model, value: val};
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
cs.get.rgb = function (string) {
|
|
261
|
-
if (!string) {
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
var abbr = /^#([a-f0-9]{3,4})$/i;
|
|
266
|
-
var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
|
|
267
|
-
var rgba = /^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
|
268
|
-
var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/;
|
|
269
|
-
var keyword = /^(\w+)$/;
|
|
270
|
-
|
|
271
|
-
var rgb = [0, 0, 0, 1];
|
|
272
|
-
var match;
|
|
273
|
-
var i;
|
|
274
|
-
var hexAlpha;
|
|
275
|
-
|
|
276
|
-
if (match = string.match(hex)) {
|
|
277
|
-
hexAlpha = match[2];
|
|
278
|
-
match = match[1];
|
|
279
|
-
|
|
280
|
-
for (i = 0; i < 3; i++) {
|
|
281
|
-
// https://jsperf.com/slice-vs-substr-vs-substring-methods-long-string/19
|
|
282
|
-
var i2 = i * 2;
|
|
283
|
-
rgb[i] = parseInt(match.slice(i2, i2 + 2), 16);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (hexAlpha) {
|
|
287
|
-
rgb[3] = parseInt(hexAlpha, 16) / 255;
|
|
288
|
-
}
|
|
289
|
-
} else if (match = string.match(abbr)) {
|
|
290
|
-
match = match[1];
|
|
291
|
-
hexAlpha = match[3];
|
|
292
|
-
|
|
293
|
-
for (i = 0; i < 3; i++) {
|
|
294
|
-
rgb[i] = parseInt(match[i] + match[i], 16);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (hexAlpha) {
|
|
298
|
-
rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
|
|
299
|
-
}
|
|
300
|
-
} else if (match = string.match(rgba)) {
|
|
301
|
-
for (i = 0; i < 3; i++) {
|
|
302
|
-
rgb[i] = parseInt(match[i + 1], 0);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (match[4]) {
|
|
306
|
-
if (match[5]) {
|
|
307
|
-
rgb[3] = parseFloat(match[4]) * 0.01;
|
|
308
|
-
} else {
|
|
309
|
-
rgb[3] = parseFloat(match[4]);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
} else if (match = string.match(per)) {
|
|
313
|
-
for (i = 0; i < 3; i++) {
|
|
314
|
-
rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
if (match[4]) {
|
|
318
|
-
if (match[5]) {
|
|
319
|
-
rgb[3] = parseFloat(match[4]) * 0.01;
|
|
320
|
-
} else {
|
|
321
|
-
rgb[3] = parseFloat(match[4]);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
} else if (match = string.match(keyword)) {
|
|
325
|
-
if (match[1] === 'transparent') {
|
|
326
|
-
return [0, 0, 0, 0];
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (!hasOwnProperty.call(colorNames, match[1])) {
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
rgb = colorNames[match[1]];
|
|
334
|
-
rgb[3] = 1;
|
|
335
|
-
|
|
336
|
-
return rgb;
|
|
337
|
-
} else {
|
|
338
|
-
return null;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
for (i = 0; i < 3; i++) {
|
|
342
|
-
rgb[i] = clamp(rgb[i], 0, 255);
|
|
343
|
-
}
|
|
344
|
-
rgb[3] = clamp(rgb[3], 0, 1);
|
|
345
|
-
|
|
346
|
-
return rgb;
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
cs.get.hsl = function (string) {
|
|
350
|
-
if (!string) {
|
|
351
|
-
return null;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
|
355
|
-
var match = string.match(hsl);
|
|
356
|
-
|
|
357
|
-
if (match) {
|
|
358
|
-
var alpha = parseFloat(match[4]);
|
|
359
|
-
var h = ((parseFloat(match[1]) % 360) + 360) % 360;
|
|
360
|
-
var s = clamp(parseFloat(match[2]), 0, 100);
|
|
361
|
-
var l = clamp(parseFloat(match[3]), 0, 100);
|
|
362
|
-
var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
|
|
363
|
-
|
|
364
|
-
return [h, s, l, a];
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
return null;
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
cs.get.hwb = function (string) {
|
|
371
|
-
if (!string) {
|
|
372
|
-
return null;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/;
|
|
376
|
-
var match = string.match(hwb);
|
|
377
|
-
|
|
378
|
-
if (match) {
|
|
379
|
-
var alpha = parseFloat(match[4]);
|
|
380
|
-
var h = ((parseFloat(match[1]) % 360) + 360) % 360;
|
|
381
|
-
var w = clamp(parseFloat(match[2]), 0, 100);
|
|
382
|
-
var b = clamp(parseFloat(match[3]), 0, 100);
|
|
383
|
-
var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
|
|
384
|
-
return [h, w, b, a];
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
return null;
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
cs.to.hex = function () {
|
|
391
|
-
var rgba = swizzle(arguments);
|
|
392
|
-
|
|
393
|
-
return (
|
|
394
|
-
'#' +
|
|
395
|
-
hexDouble(rgba[0]) +
|
|
396
|
-
hexDouble(rgba[1]) +
|
|
397
|
-
hexDouble(rgba[2]) +
|
|
398
|
-
(rgba[3] < 1
|
|
399
|
-
? (hexDouble(Math.round(rgba[3] * 255)))
|
|
400
|
-
: '')
|
|
401
|
-
);
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
cs.to.rgb = function () {
|
|
405
|
-
var rgba = swizzle(arguments);
|
|
406
|
-
|
|
407
|
-
return rgba.length < 4 || rgba[3] === 1
|
|
408
|
-
? 'rgb(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ')'
|
|
409
|
-
: 'rgba(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ', ' + rgba[3] + ')';
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
cs.to.rgb.percent = function () {
|
|
413
|
-
var rgba = swizzle(arguments);
|
|
414
|
-
|
|
415
|
-
var r = Math.round(rgba[0] / 255 * 100);
|
|
416
|
-
var g = Math.round(rgba[1] / 255 * 100);
|
|
417
|
-
var b = Math.round(rgba[2] / 255 * 100);
|
|
418
|
-
|
|
419
|
-
return rgba.length < 4 || rgba[3] === 1
|
|
420
|
-
? 'rgb(' + r + '%, ' + g + '%, ' + b + '%)'
|
|
421
|
-
: 'rgba(' + r + '%, ' + g + '%, ' + b + '%, ' + rgba[3] + ')';
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
cs.to.hsl = function () {
|
|
425
|
-
var hsla = swizzle(arguments);
|
|
426
|
-
return hsla.length < 4 || hsla[3] === 1
|
|
427
|
-
? 'hsl(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%)'
|
|
428
|
-
: 'hsla(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%, ' + hsla[3] + ')';
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
// hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
|
|
432
|
-
// (hwb have alpha optional & 1 is default value)
|
|
433
|
-
cs.to.hwb = function () {
|
|
434
|
-
var hwba = swizzle(arguments);
|
|
435
|
-
|
|
436
|
-
var a = '';
|
|
437
|
-
if (hwba.length >= 4 && hwba[3] !== 1) {
|
|
438
|
-
a = ', ' + hwba[3];
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
return 'hwb(' + hwba[0] + ', ' + hwba[1] + '%, ' + hwba[2] + '%' + a + ')';
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
cs.to.keyword = function (rgb) {
|
|
445
|
-
return reverseNames[rgb.slice(0, 3)];
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
// helpers
|
|
449
|
-
function clamp(num, min, max) {
|
|
450
|
-
return Math.min(Math.max(min, num), max);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
function hexDouble(num) {
|
|
454
|
-
var str = Math.round(num).toString(16).toUpperCase();
|
|
455
|
-
return (str.length < 2) ? '0' + str : str;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/* MIT license */
|
|
459
|
-
|
|
460
|
-
/* eslint-disable no-mixed-operators */
|
|
461
|
-
const cssKeywords = colorName;
|
|
462
|
-
|
|
463
|
-
// NOTE: conversions should only return primitive values (i.e. arrays, or
|
|
464
|
-
// values that give correct `typeof` results).
|
|
465
|
-
// do not use box values types (i.e. Number(), String(), etc.)
|
|
466
|
-
|
|
467
|
-
const reverseKeywords = {};
|
|
468
|
-
for (const key of Object.keys(cssKeywords)) {
|
|
469
|
-
reverseKeywords[cssKeywords[key]] = key;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
const convert$2 = {
|
|
473
|
-
rgb: {channels: 3, labels: 'rgb'},
|
|
474
|
-
hsl: {channels: 3, labels: 'hsl'},
|
|
475
|
-
hsv: {channels: 3, labels: 'hsv'},
|
|
476
|
-
hwb: {channels: 3, labels: 'hwb'},
|
|
477
|
-
cmyk: {channels: 4, labels: 'cmyk'},
|
|
478
|
-
xyz: {channels: 3, labels: 'xyz'},
|
|
479
|
-
lab: {channels: 3, labels: 'lab'},
|
|
480
|
-
lch: {channels: 3, labels: 'lch'},
|
|
481
|
-
hex: {channels: 1, labels: ['hex']},
|
|
482
|
-
keyword: {channels: 1, labels: ['keyword']},
|
|
483
|
-
ansi16: {channels: 1, labels: ['ansi16']},
|
|
484
|
-
ansi256: {channels: 1, labels: ['ansi256']},
|
|
485
|
-
hcg: {channels: 3, labels: ['h', 'c', 'g']},
|
|
486
|
-
apple: {channels: 3, labels: ['r16', 'g16', 'b16']},
|
|
487
|
-
gray: {channels: 1, labels: ['gray']}
|
|
488
|
-
};
|
|
489
|
-
|
|
490
|
-
var conversions$2 = convert$2;
|
|
491
|
-
|
|
492
|
-
// Hide .channels and .labels properties
|
|
493
|
-
for (const model of Object.keys(convert$2)) {
|
|
494
|
-
if (!('channels' in convert$2[model])) {
|
|
495
|
-
throw new Error('missing channels property: ' + model);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
if (!('labels' in convert$2[model])) {
|
|
499
|
-
throw new Error('missing channel labels property: ' + model);
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
if (convert$2[model].labels.length !== convert$2[model].channels) {
|
|
503
|
-
throw new Error('channel and label counts mismatch: ' + model);
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
const {channels, labels} = convert$2[model];
|
|
507
|
-
delete convert$2[model].channels;
|
|
508
|
-
delete convert$2[model].labels;
|
|
509
|
-
Object.defineProperty(convert$2[model], 'channels', {value: channels});
|
|
510
|
-
Object.defineProperty(convert$2[model], 'labels', {value: labels});
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
convert$2.rgb.hsl = function (rgb) {
|
|
514
|
-
const r = rgb[0] / 255;
|
|
515
|
-
const g = rgb[1] / 255;
|
|
516
|
-
const b = rgb[2] / 255;
|
|
517
|
-
const min = Math.min(r, g, b);
|
|
518
|
-
const max = Math.max(r, g, b);
|
|
519
|
-
const delta = max - min;
|
|
520
|
-
let h;
|
|
521
|
-
let s;
|
|
522
|
-
|
|
523
|
-
if (max === min) {
|
|
524
|
-
h = 0;
|
|
525
|
-
} else if (r === max) {
|
|
526
|
-
h = (g - b) / delta;
|
|
527
|
-
} else if (g === max) {
|
|
528
|
-
h = 2 + (b - r) / delta;
|
|
529
|
-
} else if (b === max) {
|
|
530
|
-
h = 4 + (r - g) / delta;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
h = Math.min(h * 60, 360);
|
|
534
|
-
|
|
535
|
-
if (h < 0) {
|
|
536
|
-
h += 360;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
const l = (min + max) / 2;
|
|
540
|
-
|
|
541
|
-
if (max === min) {
|
|
542
|
-
s = 0;
|
|
543
|
-
} else if (l <= 0.5) {
|
|
544
|
-
s = delta / (max + min);
|
|
545
|
-
} else {
|
|
546
|
-
s = delta / (2 - max - min);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
return [h, s * 100, l * 100];
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
convert$2.rgb.hsv = function (rgb) {
|
|
553
|
-
let rdif;
|
|
554
|
-
let gdif;
|
|
555
|
-
let bdif;
|
|
556
|
-
let h;
|
|
557
|
-
let s;
|
|
558
|
-
|
|
559
|
-
const r = rgb[0] / 255;
|
|
560
|
-
const g = rgb[1] / 255;
|
|
561
|
-
const b = rgb[2] / 255;
|
|
562
|
-
const v = Math.max(r, g, b);
|
|
563
|
-
const diff = v - Math.min(r, g, b);
|
|
564
|
-
const diffc = function (c) {
|
|
565
|
-
return (v - c) / 6 / diff + 1 / 2;
|
|
566
|
-
};
|
|
567
|
-
|
|
568
|
-
if (diff === 0) {
|
|
569
|
-
h = 0;
|
|
570
|
-
s = 0;
|
|
571
|
-
} else {
|
|
572
|
-
s = diff / v;
|
|
573
|
-
rdif = diffc(r);
|
|
574
|
-
gdif = diffc(g);
|
|
575
|
-
bdif = diffc(b);
|
|
576
|
-
|
|
577
|
-
if (r === v) {
|
|
578
|
-
h = bdif - gdif;
|
|
579
|
-
} else if (g === v) {
|
|
580
|
-
h = (1 / 3) + rdif - bdif;
|
|
581
|
-
} else if (b === v) {
|
|
582
|
-
h = (2 / 3) + gdif - rdif;
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
if (h < 0) {
|
|
586
|
-
h += 1;
|
|
587
|
-
} else if (h > 1) {
|
|
588
|
-
h -= 1;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
return [
|
|
593
|
-
h * 360,
|
|
594
|
-
s * 100,
|
|
595
|
-
v * 100
|
|
596
|
-
];
|
|
597
|
-
};
|
|
598
|
-
|
|
599
|
-
convert$2.rgb.hwb = function (rgb) {
|
|
600
|
-
const r = rgb[0];
|
|
601
|
-
const g = rgb[1];
|
|
602
|
-
let b = rgb[2];
|
|
603
|
-
const h = convert$2.rgb.hsl(rgb)[0];
|
|
604
|
-
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
605
|
-
|
|
606
|
-
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
607
|
-
|
|
608
|
-
return [h, w * 100, b * 100];
|
|
609
|
-
};
|
|
610
|
-
|
|
611
|
-
convert$2.rgb.cmyk = function (rgb) {
|
|
612
|
-
const r = rgb[0] / 255;
|
|
613
|
-
const g = rgb[1] / 255;
|
|
614
|
-
const b = rgb[2] / 255;
|
|
615
|
-
|
|
616
|
-
const k = Math.min(1 - r, 1 - g, 1 - b);
|
|
617
|
-
const c = (1 - r - k) / (1 - k) || 0;
|
|
618
|
-
const m = (1 - g - k) / (1 - k) || 0;
|
|
619
|
-
const y = (1 - b - k) / (1 - k) || 0;
|
|
620
|
-
|
|
621
|
-
return [c * 100, m * 100, y * 100, k * 100];
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
function comparativeDistance(x, y) {
|
|
625
|
-
/*
|
|
626
|
-
See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
|
|
627
|
-
*/
|
|
628
|
-
return (
|
|
629
|
-
((x[0] - y[0]) ** 2) +
|
|
630
|
-
((x[1] - y[1]) ** 2) +
|
|
631
|
-
((x[2] - y[2]) ** 2)
|
|
632
|
-
);
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
convert$2.rgb.keyword = function (rgb) {
|
|
636
|
-
const reversed = reverseKeywords[rgb];
|
|
637
|
-
if (reversed) {
|
|
638
|
-
return reversed;
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
let currentClosestDistance = Infinity;
|
|
642
|
-
let currentClosestKeyword;
|
|
643
|
-
|
|
644
|
-
for (const keyword of Object.keys(cssKeywords)) {
|
|
645
|
-
const value = cssKeywords[keyword];
|
|
646
|
-
|
|
647
|
-
// Compute comparative distance
|
|
648
|
-
const distance = comparativeDistance(rgb, value);
|
|
649
|
-
|
|
650
|
-
// Check if its less, if so set as closest
|
|
651
|
-
if (distance < currentClosestDistance) {
|
|
652
|
-
currentClosestDistance = distance;
|
|
653
|
-
currentClosestKeyword = keyword;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
return currentClosestKeyword;
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
convert$2.keyword.rgb = function (keyword) {
|
|
661
|
-
return cssKeywords[keyword];
|
|
662
|
-
};
|
|
663
|
-
|
|
664
|
-
convert$2.rgb.xyz = function (rgb) {
|
|
665
|
-
let r = rgb[0] / 255;
|
|
666
|
-
let g = rgb[1] / 255;
|
|
667
|
-
let b = rgb[2] / 255;
|
|
668
|
-
|
|
669
|
-
// Assume sRGB
|
|
670
|
-
r = r > 0.04045 ? (((r + 0.055) / 1.055) ** 2.4) : (r / 12.92);
|
|
671
|
-
g = g > 0.04045 ? (((g + 0.055) / 1.055) ** 2.4) : (g / 12.92);
|
|
672
|
-
b = b > 0.04045 ? (((b + 0.055) / 1.055) ** 2.4) : (b / 12.92);
|
|
673
|
-
|
|
674
|
-
const x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
|
|
675
|
-
const y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
|
|
676
|
-
const z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
|
|
677
|
-
|
|
678
|
-
return [x * 100, y * 100, z * 100];
|
|
679
|
-
};
|
|
680
|
-
|
|
681
|
-
convert$2.rgb.lab = function (rgb) {
|
|
682
|
-
const xyz = convert$2.rgb.xyz(rgb);
|
|
683
|
-
let x = xyz[0];
|
|
684
|
-
let y = xyz[1];
|
|
685
|
-
let z = xyz[2];
|
|
686
|
-
|
|
687
|
-
x /= 95.047;
|
|
688
|
-
y /= 100;
|
|
689
|
-
z /= 108.883;
|
|
690
|
-
|
|
691
|
-
x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
|
|
692
|
-
y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
|
|
693
|
-
z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
|
|
694
|
-
|
|
695
|
-
const l = (116 * y) - 16;
|
|
696
|
-
const a = 500 * (x - y);
|
|
697
|
-
const b = 200 * (y - z);
|
|
698
|
-
|
|
699
|
-
return [l, a, b];
|
|
700
|
-
};
|
|
701
|
-
|
|
702
|
-
convert$2.hsl.rgb = function (hsl) {
|
|
703
|
-
const h = hsl[0] / 360;
|
|
704
|
-
const s = hsl[1] / 100;
|
|
705
|
-
const l = hsl[2] / 100;
|
|
706
|
-
let t2;
|
|
707
|
-
let t3;
|
|
708
|
-
let val;
|
|
709
|
-
|
|
710
|
-
if (s === 0) {
|
|
711
|
-
val = l * 255;
|
|
712
|
-
return [val, val, val];
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
if (l < 0.5) {
|
|
716
|
-
t2 = l * (1 + s);
|
|
717
|
-
} else {
|
|
718
|
-
t2 = l + s - l * s;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
const t1 = 2 * l - t2;
|
|
722
|
-
|
|
723
|
-
const rgb = [0, 0, 0];
|
|
724
|
-
for (let i = 0; i < 3; i++) {
|
|
725
|
-
t3 = h + 1 / 3 * -(i - 1);
|
|
726
|
-
if (t3 < 0) {
|
|
727
|
-
t3++;
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
if (t3 > 1) {
|
|
731
|
-
t3--;
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
if (6 * t3 < 1) {
|
|
735
|
-
val = t1 + (t2 - t1) * 6 * t3;
|
|
736
|
-
} else if (2 * t3 < 1) {
|
|
737
|
-
val = t2;
|
|
738
|
-
} else if (3 * t3 < 2) {
|
|
739
|
-
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
740
|
-
} else {
|
|
741
|
-
val = t1;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
rgb[i] = val * 255;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
return rgb;
|
|
748
|
-
};
|
|
749
|
-
|
|
750
|
-
convert$2.hsl.hsv = function (hsl) {
|
|
751
|
-
const h = hsl[0];
|
|
752
|
-
let s = hsl[1] / 100;
|
|
753
|
-
let l = hsl[2] / 100;
|
|
754
|
-
let smin = s;
|
|
755
|
-
const lmin = Math.max(l, 0.01);
|
|
756
|
-
|
|
757
|
-
l *= 2;
|
|
758
|
-
s *= (l <= 1) ? l : 2 - l;
|
|
759
|
-
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
760
|
-
const v = (l + s) / 2;
|
|
761
|
-
const sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s);
|
|
762
|
-
|
|
763
|
-
return [h, sv * 100, v * 100];
|
|
764
|
-
};
|
|
765
|
-
|
|
766
|
-
convert$2.hsv.rgb = function (hsv) {
|
|
767
|
-
const h = hsv[0] / 60;
|
|
768
|
-
const s = hsv[1] / 100;
|
|
769
|
-
let v = hsv[2] / 100;
|
|
770
|
-
const hi = Math.floor(h) % 6;
|
|
771
|
-
|
|
772
|
-
const f = h - Math.floor(h);
|
|
773
|
-
const p = 255 * v * (1 - s);
|
|
774
|
-
const q = 255 * v * (1 - (s * f));
|
|
775
|
-
const t = 255 * v * (1 - (s * (1 - f)));
|
|
776
|
-
v *= 255;
|
|
777
|
-
|
|
778
|
-
switch (hi) {
|
|
779
|
-
case 0:
|
|
780
|
-
return [v, t, p];
|
|
781
|
-
case 1:
|
|
782
|
-
return [q, v, p];
|
|
783
|
-
case 2:
|
|
784
|
-
return [p, v, t];
|
|
785
|
-
case 3:
|
|
786
|
-
return [p, q, v];
|
|
787
|
-
case 4:
|
|
788
|
-
return [t, p, v];
|
|
789
|
-
case 5:
|
|
790
|
-
return [v, p, q];
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
|
|
794
|
-
convert$2.hsv.hsl = function (hsv) {
|
|
795
|
-
const h = hsv[0];
|
|
796
|
-
const s = hsv[1] / 100;
|
|
797
|
-
const v = hsv[2] / 100;
|
|
798
|
-
const vmin = Math.max(v, 0.01);
|
|
799
|
-
let sl;
|
|
800
|
-
let l;
|
|
801
|
-
|
|
802
|
-
l = (2 - s) * v;
|
|
803
|
-
const lmin = (2 - s) * vmin;
|
|
804
|
-
sl = s * vmin;
|
|
805
|
-
sl /= (lmin <= 1) ? lmin : 2 - lmin;
|
|
806
|
-
sl = sl || 0;
|
|
807
|
-
l /= 2;
|
|
808
|
-
|
|
809
|
-
return [h, sl * 100, l * 100];
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
// http://dev.w3.org/csswg/css-color/#hwb-to-rgb
|
|
813
|
-
convert$2.hwb.rgb = function (hwb) {
|
|
814
|
-
const h = hwb[0] / 360;
|
|
815
|
-
let wh = hwb[1] / 100;
|
|
816
|
-
let bl = hwb[2] / 100;
|
|
817
|
-
const ratio = wh + bl;
|
|
818
|
-
let f;
|
|
819
|
-
|
|
820
|
-
// Wh + bl cant be > 1
|
|
821
|
-
if (ratio > 1) {
|
|
822
|
-
wh /= ratio;
|
|
823
|
-
bl /= ratio;
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
const i = Math.floor(6 * h);
|
|
827
|
-
const v = 1 - bl;
|
|
828
|
-
f = 6 * h - i;
|
|
829
|
-
|
|
830
|
-
if ((i & 0x01) !== 0) {
|
|
831
|
-
f = 1 - f;
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
const n = wh + f * (v - wh); // Linear interpolation
|
|
835
|
-
|
|
836
|
-
let r;
|
|
837
|
-
let g;
|
|
838
|
-
let b;
|
|
839
|
-
/* eslint-disable max-statements-per-line,no-multi-spaces */
|
|
840
|
-
switch (i) {
|
|
841
|
-
default:
|
|
842
|
-
case 6:
|
|
843
|
-
case 0: r = v; g = n; b = wh; break;
|
|
844
|
-
case 1: r = n; g = v; b = wh; break;
|
|
845
|
-
case 2: r = wh; g = v; b = n; break;
|
|
846
|
-
case 3: r = wh; g = n; b = v; break;
|
|
847
|
-
case 4: r = n; g = wh; b = v; break;
|
|
848
|
-
case 5: r = v; g = wh; b = n; break;
|
|
849
|
-
}
|
|
850
|
-
/* eslint-enable max-statements-per-line,no-multi-spaces */
|
|
851
|
-
|
|
852
|
-
return [r * 255, g * 255, b * 255];
|
|
853
|
-
};
|
|
854
|
-
|
|
855
|
-
convert$2.cmyk.rgb = function (cmyk) {
|
|
856
|
-
const c = cmyk[0] / 100;
|
|
857
|
-
const m = cmyk[1] / 100;
|
|
858
|
-
const y = cmyk[2] / 100;
|
|
859
|
-
const k = cmyk[3] / 100;
|
|
860
|
-
|
|
861
|
-
const r = 1 - Math.min(1, c * (1 - k) + k);
|
|
862
|
-
const g = 1 - Math.min(1, m * (1 - k) + k);
|
|
863
|
-
const b = 1 - Math.min(1, y * (1 - k) + k);
|
|
864
|
-
|
|
865
|
-
return [r * 255, g * 255, b * 255];
|
|
866
|
-
};
|
|
867
|
-
|
|
868
|
-
convert$2.xyz.rgb = function (xyz) {
|
|
869
|
-
const x = xyz[0] / 100;
|
|
870
|
-
const y = xyz[1] / 100;
|
|
871
|
-
const z = xyz[2] / 100;
|
|
872
|
-
let r;
|
|
873
|
-
let g;
|
|
874
|
-
let b;
|
|
875
|
-
|
|
876
|
-
r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
|
|
877
|
-
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
|
|
878
|
-
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
|
|
879
|
-
|
|
880
|
-
// Assume sRGB
|
|
881
|
-
r = r > 0.0031308
|
|
882
|
-
? ((1.055 * (r ** (1.0 / 2.4))) - 0.055)
|
|
883
|
-
: r * 12.92;
|
|
884
|
-
|
|
885
|
-
g = g > 0.0031308
|
|
886
|
-
? ((1.055 * (g ** (1.0 / 2.4))) - 0.055)
|
|
887
|
-
: g * 12.92;
|
|
888
|
-
|
|
889
|
-
b = b > 0.0031308
|
|
890
|
-
? ((1.055 * (b ** (1.0 / 2.4))) - 0.055)
|
|
891
|
-
: b * 12.92;
|
|
892
|
-
|
|
893
|
-
r = Math.min(Math.max(0, r), 1);
|
|
894
|
-
g = Math.min(Math.max(0, g), 1);
|
|
895
|
-
b = Math.min(Math.max(0, b), 1);
|
|
896
|
-
|
|
897
|
-
return [r * 255, g * 255, b * 255];
|
|
898
|
-
};
|
|
899
|
-
|
|
900
|
-
convert$2.xyz.lab = function (xyz) {
|
|
901
|
-
let x = xyz[0];
|
|
902
|
-
let y = xyz[1];
|
|
903
|
-
let z = xyz[2];
|
|
904
|
-
|
|
905
|
-
x /= 95.047;
|
|
906
|
-
y /= 100;
|
|
907
|
-
z /= 108.883;
|
|
908
|
-
|
|
909
|
-
x = x > 0.008856 ? (x ** (1 / 3)) : (7.787 * x) + (16 / 116);
|
|
910
|
-
y = y > 0.008856 ? (y ** (1 / 3)) : (7.787 * y) + (16 / 116);
|
|
911
|
-
z = z > 0.008856 ? (z ** (1 / 3)) : (7.787 * z) + (16 / 116);
|
|
912
|
-
|
|
913
|
-
const l = (116 * y) - 16;
|
|
914
|
-
const a = 500 * (x - y);
|
|
915
|
-
const b = 200 * (y - z);
|
|
916
|
-
|
|
917
|
-
return [l, a, b];
|
|
918
|
-
};
|
|
919
|
-
|
|
920
|
-
convert$2.lab.xyz = function (lab) {
|
|
921
|
-
const l = lab[0];
|
|
922
|
-
const a = lab[1];
|
|
923
|
-
const b = lab[2];
|
|
924
|
-
let x;
|
|
925
|
-
let y;
|
|
926
|
-
let z;
|
|
927
|
-
|
|
928
|
-
y = (l + 16) / 116;
|
|
929
|
-
x = a / 500 + y;
|
|
930
|
-
z = y - b / 200;
|
|
931
|
-
|
|
932
|
-
const y2 = y ** 3;
|
|
933
|
-
const x2 = x ** 3;
|
|
934
|
-
const z2 = z ** 3;
|
|
935
|
-
y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
|
|
936
|
-
x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
|
|
937
|
-
z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
|
|
938
|
-
|
|
939
|
-
x *= 95.047;
|
|
940
|
-
y *= 100;
|
|
941
|
-
z *= 108.883;
|
|
942
|
-
|
|
943
|
-
return [x, y, z];
|
|
944
|
-
};
|
|
945
|
-
|
|
946
|
-
convert$2.lab.lch = function (lab) {
|
|
947
|
-
const l = lab[0];
|
|
948
|
-
const a = lab[1];
|
|
949
|
-
const b = lab[2];
|
|
950
|
-
let h;
|
|
951
|
-
|
|
952
|
-
const hr = Math.atan2(b, a);
|
|
953
|
-
h = hr * 360 / 2 / Math.PI;
|
|
954
|
-
|
|
955
|
-
if (h < 0) {
|
|
956
|
-
h += 360;
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
const c = Math.sqrt(a * a + b * b);
|
|
960
|
-
|
|
961
|
-
return [l, c, h];
|
|
962
|
-
};
|
|
963
|
-
|
|
964
|
-
convert$2.lch.lab = function (lch) {
|
|
965
|
-
const l = lch[0];
|
|
966
|
-
const c = lch[1];
|
|
967
|
-
const h = lch[2];
|
|
968
|
-
|
|
969
|
-
const hr = h / 360 * 2 * Math.PI;
|
|
970
|
-
const a = c * Math.cos(hr);
|
|
971
|
-
const b = c * Math.sin(hr);
|
|
972
|
-
|
|
973
|
-
return [l, a, b];
|
|
974
|
-
};
|
|
975
|
-
|
|
976
|
-
convert$2.rgb.ansi16 = function (args, saturation = null) {
|
|
977
|
-
const [r, g, b] = args;
|
|
978
|
-
let value = saturation === null ? convert$2.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
|
|
979
|
-
|
|
980
|
-
value = Math.round(value / 50);
|
|
981
|
-
|
|
982
|
-
if (value === 0) {
|
|
983
|
-
return 30;
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
let ansi = 30
|
|
987
|
-
+ ((Math.round(b / 255) << 2)
|
|
988
|
-
| (Math.round(g / 255) << 1)
|
|
989
|
-
| Math.round(r / 255));
|
|
990
|
-
|
|
991
|
-
if (value === 2) {
|
|
992
|
-
ansi += 60;
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
return ansi;
|
|
996
|
-
};
|
|
997
|
-
|
|
998
|
-
convert$2.hsv.ansi16 = function (args) {
|
|
999
|
-
// Optimization here; we already know the value and don't need to get
|
|
1000
|
-
// it converted for us.
|
|
1001
|
-
return convert$2.rgb.ansi16(convert$2.hsv.rgb(args), args[2]);
|
|
1002
|
-
};
|
|
1003
|
-
|
|
1004
|
-
convert$2.rgb.ansi256 = function (args) {
|
|
1005
|
-
const r = args[0];
|
|
1006
|
-
const g = args[1];
|
|
1007
|
-
const b = args[2];
|
|
1008
|
-
|
|
1009
|
-
// We use the extended greyscale palette here, with the exception of
|
|
1010
|
-
// black and white. normal palette only has 4 greyscale shades.
|
|
1011
|
-
if (r === g && g === b) {
|
|
1012
|
-
if (r < 8) {
|
|
1013
|
-
return 16;
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
if (r > 248) {
|
|
1017
|
-
return 231;
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
return Math.round(((r - 8) / 247) * 24) + 232;
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
const ansi = 16
|
|
1024
|
-
+ (36 * Math.round(r / 255 * 5))
|
|
1025
|
-
+ (6 * Math.round(g / 255 * 5))
|
|
1026
|
-
+ Math.round(b / 255 * 5);
|
|
1027
|
-
|
|
1028
|
-
return ansi;
|
|
1029
|
-
};
|
|
1030
|
-
|
|
1031
|
-
convert$2.ansi16.rgb = function (args) {
|
|
1032
|
-
let color = args % 10;
|
|
1033
|
-
|
|
1034
|
-
// Handle greyscale
|
|
1035
|
-
if (color === 0 || color === 7) {
|
|
1036
|
-
if (args > 50) {
|
|
1037
|
-
color += 3.5;
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
color = color / 10.5 * 255;
|
|
1041
|
-
|
|
1042
|
-
return [color, color, color];
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
|
-
const mult = (~~(args > 50) + 1) * 0.5;
|
|
1046
|
-
const r = ((color & 1) * mult) * 255;
|
|
1047
|
-
const g = (((color >> 1) & 1) * mult) * 255;
|
|
1048
|
-
const b = (((color >> 2) & 1) * mult) * 255;
|
|
1049
|
-
|
|
1050
|
-
return [r, g, b];
|
|
1051
|
-
};
|
|
1052
|
-
|
|
1053
|
-
convert$2.ansi256.rgb = function (args) {
|
|
1054
|
-
// Handle greyscale
|
|
1055
|
-
if (args >= 232) {
|
|
1056
|
-
const c = (args - 232) * 10 + 8;
|
|
1057
|
-
return [c, c, c];
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
args -= 16;
|
|
1061
|
-
|
|
1062
|
-
let rem;
|
|
1063
|
-
const r = Math.floor(args / 36) / 5 * 255;
|
|
1064
|
-
const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
1065
|
-
const b = (rem % 6) / 5 * 255;
|
|
1066
|
-
|
|
1067
|
-
return [r, g, b];
|
|
1068
|
-
};
|
|
1069
|
-
|
|
1070
|
-
convert$2.rgb.hex = function (args) {
|
|
1071
|
-
const integer = ((Math.round(args[0]) & 0xFF) << 16)
|
|
1072
|
-
+ ((Math.round(args[1]) & 0xFF) << 8)
|
|
1073
|
-
+ (Math.round(args[2]) & 0xFF);
|
|
1074
|
-
|
|
1075
|
-
const string = integer.toString(16).toUpperCase();
|
|
1076
|
-
return '000000'.substring(string.length) + string;
|
|
1077
|
-
};
|
|
1078
|
-
|
|
1079
|
-
convert$2.hex.rgb = function (args) {
|
|
1080
|
-
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
1081
|
-
if (!match) {
|
|
1082
|
-
return [0, 0, 0];
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
let colorString = match[0];
|
|
1086
|
-
|
|
1087
|
-
if (match[0].length === 3) {
|
|
1088
|
-
colorString = colorString.split('').map(char => {
|
|
1089
|
-
return char + char;
|
|
1090
|
-
}).join('');
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
const integer = parseInt(colorString, 16);
|
|
1094
|
-
const r = (integer >> 16) & 0xFF;
|
|
1095
|
-
const g = (integer >> 8) & 0xFF;
|
|
1096
|
-
const b = integer & 0xFF;
|
|
1097
|
-
|
|
1098
|
-
return [r, g, b];
|
|
1099
|
-
};
|
|
1100
|
-
|
|
1101
|
-
convert$2.rgb.hcg = function (rgb) {
|
|
1102
|
-
const r = rgb[0] / 255;
|
|
1103
|
-
const g = rgb[1] / 255;
|
|
1104
|
-
const b = rgb[2] / 255;
|
|
1105
|
-
const max = Math.max(Math.max(r, g), b);
|
|
1106
|
-
const min = Math.min(Math.min(r, g), b);
|
|
1107
|
-
const chroma = (max - min);
|
|
1108
|
-
let grayscale;
|
|
1109
|
-
let hue;
|
|
1110
|
-
|
|
1111
|
-
if (chroma < 1) {
|
|
1112
|
-
grayscale = min / (1 - chroma);
|
|
1113
|
-
} else {
|
|
1114
|
-
grayscale = 0;
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
if (chroma <= 0) {
|
|
1118
|
-
hue = 0;
|
|
1119
|
-
} else
|
|
1120
|
-
if (max === r) {
|
|
1121
|
-
hue = ((g - b) / chroma) % 6;
|
|
1122
|
-
} else
|
|
1123
|
-
if (max === g) {
|
|
1124
|
-
hue = 2 + (b - r) / chroma;
|
|
1125
|
-
} else {
|
|
1126
|
-
hue = 4 + (r - g) / chroma;
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
hue /= 6;
|
|
1130
|
-
hue %= 1;
|
|
1131
|
-
|
|
1132
|
-
return [hue * 360, chroma * 100, grayscale * 100];
|
|
1133
|
-
};
|
|
1134
|
-
|
|
1135
|
-
convert$2.hsl.hcg = function (hsl) {
|
|
1136
|
-
const s = hsl[1] / 100;
|
|
1137
|
-
const l = hsl[2] / 100;
|
|
1138
|
-
|
|
1139
|
-
const c = l < 0.5 ? (2.0 * s * l) : (2.0 * s * (1.0 - l));
|
|
1140
|
-
|
|
1141
|
-
let f = 0;
|
|
1142
|
-
if (c < 1.0) {
|
|
1143
|
-
f = (l - 0.5 * c) / (1.0 - c);
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
return [hsl[0], c * 100, f * 100];
|
|
1147
|
-
};
|
|
1148
|
-
|
|
1149
|
-
convert$2.hsv.hcg = function (hsv) {
|
|
1150
|
-
const s = hsv[1] / 100;
|
|
1151
|
-
const v = hsv[2] / 100;
|
|
1152
|
-
|
|
1153
|
-
const c = s * v;
|
|
1154
|
-
let f = 0;
|
|
1155
|
-
|
|
1156
|
-
if (c < 1.0) {
|
|
1157
|
-
f = (v - c) / (1 - c);
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
return [hsv[0], c * 100, f * 100];
|
|
1161
|
-
};
|
|
1162
|
-
|
|
1163
|
-
convert$2.hcg.rgb = function (hcg) {
|
|
1164
|
-
const h = hcg[0] / 360;
|
|
1165
|
-
const c = hcg[1] / 100;
|
|
1166
|
-
const g = hcg[2] / 100;
|
|
1167
|
-
|
|
1168
|
-
if (c === 0.0) {
|
|
1169
|
-
return [g * 255, g * 255, g * 255];
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
const pure = [0, 0, 0];
|
|
1173
|
-
const hi = (h % 1) * 6;
|
|
1174
|
-
const v = hi % 1;
|
|
1175
|
-
const w = 1 - v;
|
|
1176
|
-
let mg = 0;
|
|
1177
|
-
|
|
1178
|
-
/* eslint-disable max-statements-per-line */
|
|
1179
|
-
switch (Math.floor(hi)) {
|
|
1180
|
-
case 0:
|
|
1181
|
-
pure[0] = 1; pure[1] = v; pure[2] = 0; break;
|
|
1182
|
-
case 1:
|
|
1183
|
-
pure[0] = w; pure[1] = 1; pure[2] = 0; break;
|
|
1184
|
-
case 2:
|
|
1185
|
-
pure[0] = 0; pure[1] = 1; pure[2] = v; break;
|
|
1186
|
-
case 3:
|
|
1187
|
-
pure[0] = 0; pure[1] = w; pure[2] = 1; break;
|
|
1188
|
-
case 4:
|
|
1189
|
-
pure[0] = v; pure[1] = 0; pure[2] = 1; break;
|
|
1190
|
-
default:
|
|
1191
|
-
pure[0] = 1; pure[1] = 0; pure[2] = w;
|
|
1192
|
-
}
|
|
1193
|
-
/* eslint-enable max-statements-per-line */
|
|
1194
|
-
|
|
1195
|
-
mg = (1.0 - c) * g;
|
|
1196
|
-
|
|
1197
|
-
return [
|
|
1198
|
-
(c * pure[0] + mg) * 255,
|
|
1199
|
-
(c * pure[1] + mg) * 255,
|
|
1200
|
-
(c * pure[2] + mg) * 255
|
|
1201
|
-
];
|
|
1202
|
-
};
|
|
1203
|
-
|
|
1204
|
-
convert$2.hcg.hsv = function (hcg) {
|
|
1205
|
-
const c = hcg[1] / 100;
|
|
1206
|
-
const g = hcg[2] / 100;
|
|
1207
|
-
|
|
1208
|
-
const v = c + g * (1.0 - c);
|
|
1209
|
-
let f = 0;
|
|
1210
|
-
|
|
1211
|
-
if (v > 0.0) {
|
|
1212
|
-
f = c / v;
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
return [hcg[0], f * 100, v * 100];
|
|
1216
|
-
};
|
|
1217
|
-
|
|
1218
|
-
convert$2.hcg.hsl = function (hcg) {
|
|
1219
|
-
const c = hcg[1] / 100;
|
|
1220
|
-
const g = hcg[2] / 100;
|
|
1221
|
-
|
|
1222
|
-
const l = g * (1.0 - c) + 0.5 * c;
|
|
1223
|
-
let s = 0;
|
|
1224
|
-
|
|
1225
|
-
if (l > 0.0 && l < 0.5) {
|
|
1226
|
-
s = c / (2 * l);
|
|
1227
|
-
} else
|
|
1228
|
-
if (l >= 0.5 && l < 1.0) {
|
|
1229
|
-
s = c / (2 * (1 - l));
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
return [hcg[0], s * 100, l * 100];
|
|
1233
|
-
};
|
|
1234
|
-
|
|
1235
|
-
convert$2.hcg.hwb = function (hcg) {
|
|
1236
|
-
const c = hcg[1] / 100;
|
|
1237
|
-
const g = hcg[2] / 100;
|
|
1238
|
-
const v = c + g * (1.0 - c);
|
|
1239
|
-
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
|
1240
|
-
};
|
|
1241
|
-
|
|
1242
|
-
convert$2.hwb.hcg = function (hwb) {
|
|
1243
|
-
const w = hwb[1] / 100;
|
|
1244
|
-
const b = hwb[2] / 100;
|
|
1245
|
-
const v = 1 - b;
|
|
1246
|
-
const c = v - w;
|
|
1247
|
-
let g = 0;
|
|
1248
|
-
|
|
1249
|
-
if (c < 1) {
|
|
1250
|
-
g = (v - c) / (1 - c);
|
|
1251
|
-
}
|
|
1252
|
-
|
|
1253
|
-
return [hwb[0], c * 100, g * 100];
|
|
1254
|
-
};
|
|
1255
|
-
|
|
1256
|
-
convert$2.apple.rgb = function (apple) {
|
|
1257
|
-
return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255];
|
|
1258
|
-
};
|
|
1259
|
-
|
|
1260
|
-
convert$2.rgb.apple = function (rgb) {
|
|
1261
|
-
return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535];
|
|
1262
|
-
};
|
|
1263
|
-
|
|
1264
|
-
convert$2.gray.rgb = function (args) {
|
|
1265
|
-
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
1266
|
-
};
|
|
1267
|
-
|
|
1268
|
-
convert$2.gray.hsl = function (args) {
|
|
1269
|
-
return [0, 0, args[0]];
|
|
1270
|
-
};
|
|
1271
|
-
|
|
1272
|
-
convert$2.gray.hsv = convert$2.gray.hsl;
|
|
1273
|
-
|
|
1274
|
-
convert$2.gray.hwb = function (gray) {
|
|
1275
|
-
return [0, 100, gray[0]];
|
|
1276
|
-
};
|
|
1277
|
-
|
|
1278
|
-
convert$2.gray.cmyk = function (gray) {
|
|
1279
|
-
return [0, 0, 0, gray[0]];
|
|
1280
|
-
};
|
|
1281
|
-
|
|
1282
|
-
convert$2.gray.lab = function (gray) {
|
|
1283
|
-
return [gray[0], 0, 0];
|
|
1284
|
-
};
|
|
1285
|
-
|
|
1286
|
-
convert$2.gray.hex = function (gray) {
|
|
1287
|
-
const val = Math.round(gray[0] / 100 * 255) & 0xFF;
|
|
1288
|
-
const integer = (val << 16) + (val << 8) + val;
|
|
1289
|
-
|
|
1290
|
-
const string = integer.toString(16).toUpperCase();
|
|
1291
|
-
return '000000'.substring(string.length) + string;
|
|
1292
|
-
};
|
|
1293
|
-
|
|
1294
|
-
convert$2.rgb.gray = function (rgb) {
|
|
1295
|
-
const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
1296
|
-
return [val / 255 * 100];
|
|
1297
|
-
};
|
|
1298
|
-
|
|
1299
|
-
const conversions$1 = conversions$2;
|
|
1300
|
-
|
|
1301
|
-
/*
|
|
1302
|
-
This function routes a model to all other models.
|
|
1303
|
-
|
|
1304
|
-
all functions that are routed have a property `.conversion` attached
|
|
1305
|
-
to the returned synthetic function. This property is an array
|
|
1306
|
-
of strings, each with the steps in between the 'from' and 'to'
|
|
1307
|
-
color models (inclusive).
|
|
1308
|
-
|
|
1309
|
-
conversions that are not possible simply are not included.
|
|
1310
|
-
*/
|
|
1311
|
-
|
|
1312
|
-
function buildGraph() {
|
|
1313
|
-
const graph = {};
|
|
1314
|
-
// https://jsperf.com/object-keys-vs-for-in-with-closure/3
|
|
1315
|
-
const models = Object.keys(conversions$1);
|
|
1316
|
-
|
|
1317
|
-
for (let len = models.length, i = 0; i < len; i++) {
|
|
1318
|
-
graph[models[i]] = {
|
|
1319
|
-
// http://jsperf.com/1-vs-infinity
|
|
1320
|
-
// micro-opt, but this is simple.
|
|
1321
|
-
distance: -1,
|
|
1322
|
-
parent: null
|
|
1323
|
-
};
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
return graph;
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
// https://en.wikipedia.org/wiki/Breadth-first_search
|
|
1330
|
-
function deriveBFS(fromModel) {
|
|
1331
|
-
const graph = buildGraph();
|
|
1332
|
-
const queue = [fromModel]; // Unshift -> queue -> pop
|
|
1333
|
-
|
|
1334
|
-
graph[fromModel].distance = 0;
|
|
1335
|
-
|
|
1336
|
-
while (queue.length) {
|
|
1337
|
-
const current = queue.pop();
|
|
1338
|
-
const adjacents = Object.keys(conversions$1[current]);
|
|
1339
|
-
|
|
1340
|
-
for (let len = adjacents.length, i = 0; i < len; i++) {
|
|
1341
|
-
const adjacent = adjacents[i];
|
|
1342
|
-
const node = graph[adjacent];
|
|
1343
|
-
|
|
1344
|
-
if (node.distance === -1) {
|
|
1345
|
-
node.distance = graph[current].distance + 1;
|
|
1346
|
-
node.parent = current;
|
|
1347
|
-
queue.unshift(adjacent);
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
return graph;
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
function link(from, to) {
|
|
1356
|
-
return function (args) {
|
|
1357
|
-
return to(from(args));
|
|
1358
|
-
};
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
function wrapConversion(toModel, graph) {
|
|
1362
|
-
const path = [graph[toModel].parent, toModel];
|
|
1363
|
-
let fn = conversions$1[graph[toModel].parent][toModel];
|
|
1364
|
-
|
|
1365
|
-
let cur = graph[toModel].parent;
|
|
1366
|
-
while (graph[cur].parent) {
|
|
1367
|
-
path.unshift(graph[cur].parent);
|
|
1368
|
-
fn = link(conversions$1[graph[cur].parent][cur], fn);
|
|
1369
|
-
cur = graph[cur].parent;
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
fn.conversion = path;
|
|
1373
|
-
return fn;
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
var route$1 = function (fromModel) {
|
|
1377
|
-
const graph = deriveBFS(fromModel);
|
|
1378
|
-
const conversion = {};
|
|
1379
|
-
|
|
1380
|
-
const models = Object.keys(graph);
|
|
1381
|
-
for (let len = models.length, i = 0; i < len; i++) {
|
|
1382
|
-
const toModel = models[i];
|
|
1383
|
-
const node = graph[toModel];
|
|
1384
|
-
|
|
1385
|
-
if (node.parent === null) {
|
|
1386
|
-
// No possible conversion, or this node is the source model.
|
|
1387
|
-
continue;
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
conversion[toModel] = wrapConversion(toModel, graph);
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
return conversion;
|
|
1394
|
-
};
|
|
1395
|
-
|
|
1396
|
-
const conversions = conversions$2;
|
|
1397
|
-
const route = route$1;
|
|
1398
|
-
|
|
1399
|
-
const convert$1 = {};
|
|
1400
|
-
|
|
1401
|
-
const models = Object.keys(conversions);
|
|
1402
|
-
|
|
1403
|
-
function wrapRaw(fn) {
|
|
1404
|
-
const wrappedFn = function (...args) {
|
|
1405
|
-
const arg0 = args[0];
|
|
1406
|
-
if (arg0 === undefined || arg0 === null) {
|
|
1407
|
-
return arg0;
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
if (arg0.length > 1) {
|
|
1411
|
-
args = arg0;
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
|
-
return fn(args);
|
|
1415
|
-
};
|
|
1416
|
-
|
|
1417
|
-
// Preserve .conversion property if there is one
|
|
1418
|
-
if ('conversion' in fn) {
|
|
1419
|
-
wrappedFn.conversion = fn.conversion;
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
return wrappedFn;
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
function wrapRounded(fn) {
|
|
1426
|
-
const wrappedFn = function (...args) {
|
|
1427
|
-
const arg0 = args[0];
|
|
1428
|
-
|
|
1429
|
-
if (arg0 === undefined || arg0 === null) {
|
|
1430
|
-
return arg0;
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
if (arg0.length > 1) {
|
|
1434
|
-
args = arg0;
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
const result = fn(args);
|
|
1438
|
-
|
|
1439
|
-
// We're assuming the result is an array here.
|
|
1440
|
-
// see notice in conversions.js; don't use box types
|
|
1441
|
-
// in conversion functions.
|
|
1442
|
-
if (typeof result === 'object') {
|
|
1443
|
-
for (let len = result.length, i = 0; i < len; i++) {
|
|
1444
|
-
result[i] = Math.round(result[i]);
|
|
1445
|
-
}
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
return result;
|
|
1449
|
-
};
|
|
1450
|
-
|
|
1451
|
-
// Preserve .conversion property if there is one
|
|
1452
|
-
if ('conversion' in fn) {
|
|
1453
|
-
wrappedFn.conversion = fn.conversion;
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
return wrappedFn;
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
models.forEach(fromModel => {
|
|
1460
|
-
convert$1[fromModel] = {};
|
|
1461
|
-
|
|
1462
|
-
Object.defineProperty(convert$1[fromModel], 'channels', {value: conversions[fromModel].channels});
|
|
1463
|
-
Object.defineProperty(convert$1[fromModel], 'labels', {value: conversions[fromModel].labels});
|
|
1464
|
-
|
|
1465
|
-
const routes = route(fromModel);
|
|
1466
|
-
const routeModels = Object.keys(routes);
|
|
1467
|
-
|
|
1468
|
-
routeModels.forEach(toModel => {
|
|
1469
|
-
const fn = routes[toModel];
|
|
1470
|
-
|
|
1471
|
-
convert$1[fromModel][toModel] = wrapRounded(fn);
|
|
1472
|
-
convert$1[fromModel][toModel].raw = wrapRaw(fn);
|
|
1473
|
-
});
|
|
1474
|
-
});
|
|
1475
|
-
|
|
1476
|
-
var colorConvert = convert$1;
|
|
1477
|
-
|
|
1478
|
-
const colorString = colorStringExports;
|
|
1479
|
-
const convert = colorConvert;
|
|
1480
|
-
|
|
1481
|
-
const skippedModels = [
|
|
1482
|
-
// To be honest, I don't really feel like keyword belongs in color convert, but eh.
|
|
1483
|
-
'keyword',
|
|
1484
|
-
|
|
1485
|
-
// Gray conflicts with some method names, and has its own method defined.
|
|
1486
|
-
'gray',
|
|
1487
|
-
|
|
1488
|
-
// Shouldn't really be in color-convert either...
|
|
1489
|
-
'hex',
|
|
1490
|
-
];
|
|
1491
|
-
|
|
1492
|
-
const hashedModelKeys = {};
|
|
1493
|
-
for (const model of Object.keys(convert)) {
|
|
1494
|
-
hashedModelKeys[[...convert[model].labels].sort().join('')] = model;
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
const limiters = {};
|
|
1498
|
-
|
|
1499
|
-
function Color(object, model) {
|
|
1500
|
-
if (!(this instanceof Color)) {
|
|
1501
|
-
return new Color(object, model);
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
if (model && model in skippedModels) {
|
|
1505
|
-
model = null;
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
if (model && !(model in convert)) {
|
|
1509
|
-
throw new Error('Unknown model: ' + model);
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
let i;
|
|
1513
|
-
let channels;
|
|
1514
|
-
|
|
1515
|
-
if (object == null) { // eslint-disable-line no-eq-null,eqeqeq
|
|
1516
|
-
this.model = 'rgb';
|
|
1517
|
-
this.color = [0, 0, 0];
|
|
1518
|
-
this.valpha = 1;
|
|
1519
|
-
} else if (object instanceof Color) {
|
|
1520
|
-
this.model = object.model;
|
|
1521
|
-
this.color = [...object.color];
|
|
1522
|
-
this.valpha = object.valpha;
|
|
1523
|
-
} else if (typeof object === 'string') {
|
|
1524
|
-
const result = colorString.get(object);
|
|
1525
|
-
if (result === null) {
|
|
1526
|
-
throw new Error('Unable to parse color from string: ' + object);
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
this.model = result.model;
|
|
1530
|
-
channels = convert[this.model].channels;
|
|
1531
|
-
this.color = result.value.slice(0, channels);
|
|
1532
|
-
this.valpha = typeof result.value[channels] === 'number' ? result.value[channels] : 1;
|
|
1533
|
-
} else if (object.length > 0) {
|
|
1534
|
-
this.model = model || 'rgb';
|
|
1535
|
-
channels = convert[this.model].channels;
|
|
1536
|
-
const newArray = Array.prototype.slice.call(object, 0, channels);
|
|
1537
|
-
this.color = zeroArray(newArray, channels);
|
|
1538
|
-
this.valpha = typeof object[channels] === 'number' ? object[channels] : 1;
|
|
1539
|
-
} else if (typeof object === 'number') {
|
|
1540
|
-
// This is always RGB - can be converted later on.
|
|
1541
|
-
this.model = 'rgb';
|
|
1542
|
-
this.color = [
|
|
1543
|
-
(object >> 16) & 0xFF,
|
|
1544
|
-
(object >> 8) & 0xFF,
|
|
1545
|
-
object & 0xFF,
|
|
1546
|
-
];
|
|
1547
|
-
this.valpha = 1;
|
|
1548
|
-
} else {
|
|
1549
|
-
this.valpha = 1;
|
|
1550
|
-
|
|
1551
|
-
const keys = Object.keys(object);
|
|
1552
|
-
if ('alpha' in object) {
|
|
1553
|
-
keys.splice(keys.indexOf('alpha'), 1);
|
|
1554
|
-
this.valpha = typeof object.alpha === 'number' ? object.alpha : 0;
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
const hashedKeys = keys.sort().join('');
|
|
1558
|
-
if (!(hashedKeys in hashedModelKeys)) {
|
|
1559
|
-
throw new Error('Unable to parse color from object: ' + JSON.stringify(object));
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
this.model = hashedModelKeys[hashedKeys];
|
|
1563
|
-
|
|
1564
|
-
const {labels} = convert[this.model];
|
|
1565
|
-
const color = [];
|
|
1566
|
-
for (i = 0; i < labels.length; i++) {
|
|
1567
|
-
color.push(object[labels[i]]);
|
|
1568
|
-
}
|
|
1569
|
-
|
|
1570
|
-
this.color = zeroArray(color);
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1573
|
-
// Perform limitations (clamping, etc.)
|
|
1574
|
-
if (limiters[this.model]) {
|
|
1575
|
-
channels = convert[this.model].channels;
|
|
1576
|
-
for (i = 0; i < channels; i++) {
|
|
1577
|
-
const limit = limiters[this.model][i];
|
|
1578
|
-
if (limit) {
|
|
1579
|
-
this.color[i] = limit(this.color[i]);
|
|
1580
|
-
}
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
this.valpha = Math.max(0, Math.min(1, this.valpha));
|
|
1585
|
-
|
|
1586
|
-
if (Object.freeze) {
|
|
1587
|
-
Object.freeze(this);
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
Color.prototype = {
|
|
1592
|
-
toString() {
|
|
1593
|
-
return this.string();
|
|
1594
|
-
},
|
|
1595
|
-
|
|
1596
|
-
toJSON() {
|
|
1597
|
-
return this[this.model]();
|
|
1598
|
-
},
|
|
1599
|
-
|
|
1600
|
-
string(places) {
|
|
1601
|
-
let self = this.model in colorString.to ? this : this.rgb();
|
|
1602
|
-
self = self.round(typeof places === 'number' ? places : 1);
|
|
1603
|
-
const args = self.valpha === 1 ? self.color : [...self.color, this.valpha];
|
|
1604
|
-
return colorString.to[self.model](args);
|
|
1605
|
-
},
|
|
1606
|
-
|
|
1607
|
-
percentString(places) {
|
|
1608
|
-
const self = this.rgb().round(typeof places === 'number' ? places : 1);
|
|
1609
|
-
const args = self.valpha === 1 ? self.color : [...self.color, this.valpha];
|
|
1610
|
-
return colorString.to.rgb.percent(args);
|
|
1611
|
-
},
|
|
1612
|
-
|
|
1613
|
-
array() {
|
|
1614
|
-
return this.valpha === 1 ? [...this.color] : [...this.color, this.valpha];
|
|
1615
|
-
},
|
|
1616
|
-
|
|
1617
|
-
object() {
|
|
1618
|
-
const result = {};
|
|
1619
|
-
const {channels} = convert[this.model];
|
|
1620
|
-
const {labels} = convert[this.model];
|
|
1621
|
-
|
|
1622
|
-
for (let i = 0; i < channels; i++) {
|
|
1623
|
-
result[labels[i]] = this.color[i];
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
if (this.valpha !== 1) {
|
|
1627
|
-
result.alpha = this.valpha;
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
return result;
|
|
1631
|
-
},
|
|
1632
|
-
|
|
1633
|
-
unitArray() {
|
|
1634
|
-
const rgb = this.rgb().color;
|
|
1635
|
-
rgb[0] /= 255;
|
|
1636
|
-
rgb[1] /= 255;
|
|
1637
|
-
rgb[2] /= 255;
|
|
1638
|
-
|
|
1639
|
-
if (this.valpha !== 1) {
|
|
1640
|
-
rgb.push(this.valpha);
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
return rgb;
|
|
1644
|
-
},
|
|
1645
|
-
|
|
1646
|
-
unitObject() {
|
|
1647
|
-
const rgb = this.rgb().object();
|
|
1648
|
-
rgb.r /= 255;
|
|
1649
|
-
rgb.g /= 255;
|
|
1650
|
-
rgb.b /= 255;
|
|
1651
|
-
|
|
1652
|
-
if (this.valpha !== 1) {
|
|
1653
|
-
rgb.alpha = this.valpha;
|
|
1654
|
-
}
|
|
1655
|
-
|
|
1656
|
-
return rgb;
|
|
1657
|
-
},
|
|
1658
|
-
|
|
1659
|
-
round(places) {
|
|
1660
|
-
places = Math.max(places || 0, 0);
|
|
1661
|
-
return new Color([...this.color.map(roundToPlace(places)), this.valpha], this.model);
|
|
1662
|
-
},
|
|
1663
|
-
|
|
1664
|
-
alpha(value) {
|
|
1665
|
-
if (value !== undefined) {
|
|
1666
|
-
return new Color([...this.color, Math.max(0, Math.min(1, value))], this.model);
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
return this.valpha;
|
|
1670
|
-
},
|
|
1671
|
-
|
|
1672
|
-
// Rgb
|
|
1673
|
-
red: getset('rgb', 0, maxfn(255)),
|
|
1674
|
-
green: getset('rgb', 1, maxfn(255)),
|
|
1675
|
-
blue: getset('rgb', 2, maxfn(255)),
|
|
1676
|
-
|
|
1677
|
-
hue: getset(['hsl', 'hsv', 'hsl', 'hwb', 'hcg'], 0, value => ((value % 360) + 360) % 360),
|
|
1678
|
-
|
|
1679
|
-
saturationl: getset('hsl', 1, maxfn(100)),
|
|
1680
|
-
lightness: getset('hsl', 2, maxfn(100)),
|
|
1681
|
-
|
|
1682
|
-
saturationv: getset('hsv', 1, maxfn(100)),
|
|
1683
|
-
value: getset('hsv', 2, maxfn(100)),
|
|
1684
|
-
|
|
1685
|
-
chroma: getset('hcg', 1, maxfn(100)),
|
|
1686
|
-
gray: getset('hcg', 2, maxfn(100)),
|
|
1687
|
-
|
|
1688
|
-
white: getset('hwb', 1, maxfn(100)),
|
|
1689
|
-
wblack: getset('hwb', 2, maxfn(100)),
|
|
1690
|
-
|
|
1691
|
-
cyan: getset('cmyk', 0, maxfn(100)),
|
|
1692
|
-
magenta: getset('cmyk', 1, maxfn(100)),
|
|
1693
|
-
yellow: getset('cmyk', 2, maxfn(100)),
|
|
1694
|
-
black: getset('cmyk', 3, maxfn(100)),
|
|
1695
|
-
|
|
1696
|
-
x: getset('xyz', 0, maxfn(95.047)),
|
|
1697
|
-
y: getset('xyz', 1, maxfn(100)),
|
|
1698
|
-
z: getset('xyz', 2, maxfn(108.833)),
|
|
1699
|
-
|
|
1700
|
-
l: getset('lab', 0, maxfn(100)),
|
|
1701
|
-
a: getset('lab', 1),
|
|
1702
|
-
b: getset('lab', 2),
|
|
1703
|
-
|
|
1704
|
-
keyword(value) {
|
|
1705
|
-
if (value !== undefined) {
|
|
1706
|
-
return new Color(value);
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
return convert[this.model].keyword(this.color);
|
|
1710
|
-
},
|
|
1711
|
-
|
|
1712
|
-
hex(value) {
|
|
1713
|
-
if (value !== undefined) {
|
|
1714
|
-
return new Color(value);
|
|
1715
|
-
}
|
|
1716
|
-
|
|
1717
|
-
return colorString.to.hex(this.rgb().round().color);
|
|
1718
|
-
},
|
|
1719
|
-
|
|
1720
|
-
hexa(value) {
|
|
1721
|
-
if (value !== undefined) {
|
|
1722
|
-
return new Color(value);
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
const rgbArray = this.rgb().round().color;
|
|
1726
|
-
|
|
1727
|
-
let alphaHex = Math.round(this.valpha * 255).toString(16).toUpperCase();
|
|
1728
|
-
if (alphaHex.length === 1) {
|
|
1729
|
-
alphaHex = '0' + alphaHex;
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
return colorString.to.hex(rgbArray) + alphaHex;
|
|
1733
|
-
},
|
|
1734
|
-
|
|
1735
|
-
rgbNumber() {
|
|
1736
|
-
const rgb = this.rgb().color;
|
|
1737
|
-
return ((rgb[0] & 0xFF) << 16) | ((rgb[1] & 0xFF) << 8) | (rgb[2] & 0xFF);
|
|
1738
|
-
},
|
|
1739
|
-
|
|
1740
|
-
luminosity() {
|
|
1741
|
-
// http://www.w3.org/TR/WCAG20/#relativeluminancedef
|
|
1742
|
-
const rgb = this.rgb().color;
|
|
1743
|
-
|
|
1744
|
-
const lum = [];
|
|
1745
|
-
for (const [i, element] of rgb.entries()) {
|
|
1746
|
-
const chan = element / 255;
|
|
1747
|
-
lum[i] = (chan <= 0.04045) ? chan / 12.92 : ((chan + 0.055) / 1.055) ** 2.4;
|
|
1748
|
-
}
|
|
1749
|
-
|
|
1750
|
-
return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
|
|
1751
|
-
},
|
|
1752
|
-
|
|
1753
|
-
contrast(color2) {
|
|
1754
|
-
// http://www.w3.org/TR/WCAG20/#contrast-ratiodef
|
|
1755
|
-
const lum1 = this.luminosity();
|
|
1756
|
-
const lum2 = color2.luminosity();
|
|
1757
|
-
|
|
1758
|
-
if (lum1 > lum2) {
|
|
1759
|
-
return (lum1 + 0.05) / (lum2 + 0.05);
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
return (lum2 + 0.05) / (lum1 + 0.05);
|
|
1763
|
-
},
|
|
1764
|
-
|
|
1765
|
-
level(color2) {
|
|
1766
|
-
// https://www.w3.org/TR/WCAG/#contrast-enhanced
|
|
1767
|
-
const contrastRatio = this.contrast(color2);
|
|
1768
|
-
if (contrastRatio >= 7) {
|
|
1769
|
-
return 'AAA';
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
|
-
return (contrastRatio >= 4.5) ? 'AA' : '';
|
|
1773
|
-
},
|
|
1774
|
-
|
|
1775
|
-
isDark() {
|
|
1776
|
-
// YIQ equation from http://24ways.org/2010/calculating-color-contrast
|
|
1777
|
-
const rgb = this.rgb().color;
|
|
1778
|
-
const yiq = (rgb[0] * 2126 + rgb[1] * 7152 + rgb[2] * 722) / 10000;
|
|
1779
|
-
return yiq < 128;
|
|
1780
|
-
},
|
|
1781
|
-
|
|
1782
|
-
isLight() {
|
|
1783
|
-
return !this.isDark();
|
|
1784
|
-
},
|
|
1785
|
-
|
|
1786
|
-
negate() {
|
|
1787
|
-
const rgb = this.rgb();
|
|
1788
|
-
for (let i = 0; i < 3; i++) {
|
|
1789
|
-
rgb.color[i] = 255 - rgb.color[i];
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
return rgb;
|
|
1793
|
-
},
|
|
1794
|
-
|
|
1795
|
-
lighten(ratio) {
|
|
1796
|
-
const hsl = this.hsl();
|
|
1797
|
-
hsl.color[2] += hsl.color[2] * ratio;
|
|
1798
|
-
return hsl;
|
|
1799
|
-
},
|
|
1800
|
-
|
|
1801
|
-
darken(ratio) {
|
|
1802
|
-
const hsl = this.hsl();
|
|
1803
|
-
hsl.color[2] -= hsl.color[2] * ratio;
|
|
1804
|
-
return hsl;
|
|
1805
|
-
},
|
|
1806
|
-
|
|
1807
|
-
saturate(ratio) {
|
|
1808
|
-
const hsl = this.hsl();
|
|
1809
|
-
hsl.color[1] += hsl.color[1] * ratio;
|
|
1810
|
-
return hsl;
|
|
1811
|
-
},
|
|
1812
|
-
|
|
1813
|
-
desaturate(ratio) {
|
|
1814
|
-
const hsl = this.hsl();
|
|
1815
|
-
hsl.color[1] -= hsl.color[1] * ratio;
|
|
1816
|
-
return hsl;
|
|
1817
|
-
},
|
|
1818
|
-
|
|
1819
|
-
whiten(ratio) {
|
|
1820
|
-
const hwb = this.hwb();
|
|
1821
|
-
hwb.color[1] += hwb.color[1] * ratio;
|
|
1822
|
-
return hwb;
|
|
1823
|
-
},
|
|
1824
|
-
|
|
1825
|
-
blacken(ratio) {
|
|
1826
|
-
const hwb = this.hwb();
|
|
1827
|
-
hwb.color[2] += hwb.color[2] * ratio;
|
|
1828
|
-
return hwb;
|
|
1829
|
-
},
|
|
1830
|
-
|
|
1831
|
-
grayscale() {
|
|
1832
|
-
// http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
|
|
1833
|
-
const rgb = this.rgb().color;
|
|
1834
|
-
const value = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
|
|
1835
|
-
return Color.rgb(value, value, value);
|
|
1836
|
-
},
|
|
1837
|
-
|
|
1838
|
-
fade(ratio) {
|
|
1839
|
-
return this.alpha(this.valpha - (this.valpha * ratio));
|
|
1840
|
-
},
|
|
1841
|
-
|
|
1842
|
-
opaquer(ratio) {
|
|
1843
|
-
return this.alpha(this.valpha + (this.valpha * ratio));
|
|
1844
|
-
},
|
|
1845
|
-
|
|
1846
|
-
rotate(degrees) {
|
|
1847
|
-
const hsl = this.hsl();
|
|
1848
|
-
let hue = hsl.color[0];
|
|
1849
|
-
hue = (hue + degrees) % 360;
|
|
1850
|
-
hue = hue < 0 ? 360 + hue : hue;
|
|
1851
|
-
hsl.color[0] = hue;
|
|
1852
|
-
return hsl;
|
|
1853
|
-
},
|
|
1854
|
-
|
|
1855
|
-
mix(mixinColor, weight) {
|
|
1856
|
-
// Ported from sass implementation in C
|
|
1857
|
-
// https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209
|
|
1858
|
-
if (!mixinColor || !mixinColor.rgb) {
|
|
1859
|
-
throw new Error('Argument to "mix" was not a Color instance, but rather an instance of ' + typeof mixinColor);
|
|
1860
|
-
}
|
|
1861
|
-
|
|
1862
|
-
const color1 = mixinColor.rgb();
|
|
1863
|
-
const color2 = this.rgb();
|
|
1864
|
-
const p = weight === undefined ? 0.5 : weight;
|
|
1865
|
-
|
|
1866
|
-
const w = 2 * p - 1;
|
|
1867
|
-
const a = color1.alpha() - color2.alpha();
|
|
1868
|
-
|
|
1869
|
-
const w1 = (((w * a === -1) ? w : (w + a) / (1 + w * a)) + 1) / 2;
|
|
1870
|
-
const w2 = 1 - w1;
|
|
1871
|
-
|
|
1872
|
-
return Color.rgb(
|
|
1873
|
-
w1 * color1.red() + w2 * color2.red(),
|
|
1874
|
-
w1 * color1.green() + w2 * color2.green(),
|
|
1875
|
-
w1 * color1.blue() + w2 * color2.blue(),
|
|
1876
|
-
color1.alpha() * p + color2.alpha() * (1 - p));
|
|
1877
|
-
},
|
|
12
|
+
// https://github.com/facebook/jest/issues/7547
|
|
13
|
+
const assert = (value, error) => {
|
|
14
|
+
if (!value) {
|
|
15
|
+
// https://github.com/typescript-eslint/typescript-eslint/issues/3814
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
1878
19
|
};
|
|
1879
20
|
|
|
1880
|
-
// Model conversion methods and static constructors
|
|
1881
|
-
for (const model of Object.keys(convert)) {
|
|
1882
|
-
if (skippedModels.includes(model)) {
|
|
1883
|
-
continue;
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
const {channels} = convert[model];
|
|
1887
|
-
|
|
1888
|
-
// Conversion methods
|
|
1889
|
-
Color.prototype[model] = function (...args) {
|
|
1890
|
-
if (this.model === model) {
|
|
1891
|
-
return new Color(this);
|
|
1892
|
-
}
|
|
1893
|
-
|
|
1894
|
-
if (args.length > 0) {
|
|
1895
|
-
return new Color(args, model);
|
|
1896
|
-
}
|
|
1897
|
-
|
|
1898
|
-
return new Color([...assertArray(convert[this.model][model].raw(this.color)), this.valpha], model);
|
|
1899
|
-
};
|
|
1900
|
-
|
|
1901
|
-
// 'static' construction methods
|
|
1902
|
-
Color[model] = function (...args) {
|
|
1903
|
-
let color = args[0];
|
|
1904
|
-
if (typeof color === 'number') {
|
|
1905
|
-
color = zeroArray(args, channels);
|
|
1906
|
-
}
|
|
1907
|
-
|
|
1908
|
-
return new Color(color, model);
|
|
1909
|
-
};
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
|
-
function roundTo(number, places) {
|
|
1913
|
-
return Number(number.toFixed(places));
|
|
1914
|
-
}
|
|
1915
|
-
|
|
1916
|
-
function roundToPlace(places) {
|
|
1917
|
-
return function (number) {
|
|
1918
|
-
return roundTo(number, places);
|
|
1919
|
-
};
|
|
1920
|
-
}
|
|
1921
|
-
|
|
1922
|
-
function getset(model, channel, modifier) {
|
|
1923
|
-
model = Array.isArray(model) ? model : [model];
|
|
1924
|
-
|
|
1925
|
-
for (const m of model) {
|
|
1926
|
-
(limiters[m] || (limiters[m] = []))[channel] = modifier;
|
|
1927
|
-
}
|
|
1928
|
-
|
|
1929
|
-
model = model[0];
|
|
1930
|
-
|
|
1931
|
-
return function (value) {
|
|
1932
|
-
let result;
|
|
1933
|
-
|
|
1934
|
-
if (value !== undefined) {
|
|
1935
|
-
if (modifier) {
|
|
1936
|
-
value = modifier(value);
|
|
1937
|
-
}
|
|
1938
|
-
|
|
1939
|
-
result = this[model]();
|
|
1940
|
-
result.color[channel] = value;
|
|
1941
|
-
return result;
|
|
1942
|
-
}
|
|
1943
|
-
|
|
1944
|
-
result = this[model]().color[channel];
|
|
1945
|
-
if (modifier) {
|
|
1946
|
-
result = modifier(result);
|
|
1947
|
-
}
|
|
1948
|
-
|
|
1949
|
-
return result;
|
|
1950
|
-
};
|
|
1951
|
-
}
|
|
1952
|
-
|
|
1953
|
-
function maxfn(max) {
|
|
1954
|
-
return function (v) {
|
|
1955
|
-
return Math.max(0, Math.min(max, v));
|
|
1956
|
-
};
|
|
1957
|
-
}
|
|
1958
|
-
|
|
1959
|
-
function assertArray(value) {
|
|
1960
|
-
return Array.isArray(value) ? value : [value];
|
|
1961
|
-
}
|
|
1962
|
-
|
|
1963
|
-
function zeroArray(array, length) {
|
|
1964
|
-
for (let i = 0; i < length; i++) {
|
|
1965
|
-
if (typeof array[i] !== 'number') {
|
|
1966
|
-
array[i] = 0;
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
|
|
1970
|
-
return array;
|
|
1971
|
-
}
|
|
1972
|
-
|
|
1973
21
|
const POOL_SIZE_MULTIPLIER = 128;
|
|
1974
22
|
let pool, poolOffset;
|
|
1975
23
|
let fillPool = bytes => {
|
|
@@ -2005,88 +53,11 @@ let customRandom = (alphabet, defaultSize, getRandom) => {
|
|
|
2005
53
|
let customAlphabet = (alphabet, size = 21) =>
|
|
2006
54
|
customRandom(alphabet, size, random);
|
|
2007
55
|
|
|
2008
|
-
const
|
|
2009
|
-
const
|
|
56
|
+
const lowercaseAlphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
57
|
+
const alphabet = `${lowercaseAlphabet}ABCDEFGHIJKLMNOPQRSTUVWXYZ`;
|
|
58
|
+
const buildIdGenerator = (size, includingUppercase = false) => customAlphabet(includingUppercase ? alphabet : lowercaseAlphabet, size);
|
|
2010
59
|
const generateStandardId = buildIdGenerator(21);
|
|
2011
60
|
|
|
2012
|
-
var ReservedScope;
|
|
2013
|
-
(function (ReservedScope) {
|
|
2014
|
-
ReservedScope["OpenId"] = "openid";
|
|
2015
|
-
ReservedScope["OfflineAccess"] = "offline_access";
|
|
2016
|
-
})(ReservedScope || (ReservedScope = {}));
|
|
2017
|
-
/**
|
|
2018
|
-
* Scopes for ID Token and Userinfo Endpoint.
|
|
2019
|
-
*/
|
|
2020
|
-
var UserScope;
|
|
2021
|
-
(function (UserScope) {
|
|
2022
|
-
/**
|
|
2023
|
-
* Scope for basic user info.
|
|
2024
|
-
*
|
|
2025
|
-
* See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
|
|
2026
|
-
*/
|
|
2027
|
-
UserScope["Profile"] = "profile";
|
|
2028
|
-
/**
|
|
2029
|
-
* Scope for user email address.
|
|
2030
|
-
*
|
|
2031
|
-
* See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
|
|
2032
|
-
*/
|
|
2033
|
-
UserScope["Email"] = "email";
|
|
2034
|
-
/**
|
|
2035
|
-
* Scope for user phone number.
|
|
2036
|
-
*
|
|
2037
|
-
* See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
|
|
2038
|
-
*/
|
|
2039
|
-
UserScope["Phone"] = "phone";
|
|
2040
|
-
/**
|
|
2041
|
-
* Scope for user's custom data.
|
|
2042
|
-
*
|
|
2043
|
-
* See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
|
|
2044
|
-
*/
|
|
2045
|
-
UserScope["CustomData"] = "custom_data";
|
|
2046
|
-
/**
|
|
2047
|
-
* Scope for user's social identity details.
|
|
2048
|
-
*
|
|
2049
|
-
* See {@link idTokenClaims} for mapped claims in ID Token and {@link userinfoClaims} for additional claims in Userinfo Endpoint.
|
|
2050
|
-
*/
|
|
2051
|
-
UserScope["Identities"] = "identities";
|
|
2052
|
-
})(UserScope || (UserScope = {}));
|
|
2053
|
-
/**
|
|
2054
|
-
* Mapped claims that ID Token includes.
|
|
2055
|
-
*/
|
|
2056
|
-
const idTokenClaims = Object.freeze({
|
|
2057
|
-
[UserScope.Profile]: ['name', 'picture', 'username', 'role_names'],
|
|
2058
|
-
[UserScope.Email]: ['email', 'email_verified'],
|
|
2059
|
-
[UserScope.Phone]: ['phone_number', 'phone_number_verified'],
|
|
2060
|
-
[UserScope.CustomData]: [],
|
|
2061
|
-
[UserScope.Identities]: [],
|
|
2062
|
-
});
|
|
2063
|
-
/**
|
|
2064
|
-
* Additional claims that Userinfo Endpoint returns.
|
|
2065
|
-
*/
|
|
2066
|
-
const userinfoClaims = Object.freeze({
|
|
2067
|
-
[UserScope.Profile]: [],
|
|
2068
|
-
[UserScope.Email]: [],
|
|
2069
|
-
[UserScope.Phone]: [],
|
|
2070
|
-
[UserScope.CustomData]: ['custom_data'],
|
|
2071
|
-
[UserScope.Identities]: ['identities'],
|
|
2072
|
-
});
|
|
2073
|
-
Object.freeze(
|
|
2074
|
-
// Hard to infer type directly, use `as` for a workaround.
|
|
2075
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
2076
|
-
Object.fromEntries(Object.values(UserScope).map((current) => [
|
|
2077
|
-
current,
|
|
2078
|
-
[...idTokenClaims[current], ...userinfoClaims[current]],
|
|
2079
|
-
])));
|
|
2080
|
-
|
|
2081
|
-
// https://github.com/facebook/jest/issues/7547
|
|
2082
|
-
const assert = (value, error) => {
|
|
2083
|
-
if (!value) {
|
|
2084
|
-
// https://github.com/typescript-eslint/typescript-eslint/issues/3814
|
|
2085
|
-
// eslint-disable-next-line @typescript-eslint/no-throw-literal
|
|
2086
|
-
throw error;
|
|
2087
|
-
}
|
|
2088
|
-
};
|
|
2089
|
-
|
|
2090
61
|
const encoder = new TextEncoder();
|
|
2091
62
|
const decoder = new TextDecoder();
|
|
2092
63
|
function concat(...buffers) {
|
|
@@ -2320,6 +291,12 @@ function checkSigCryptoKey(key, alg, ...usages) {
|
|
|
2320
291
|
throw unusable('NODE-ED25519');
|
|
2321
292
|
break;
|
|
2322
293
|
}
|
|
294
|
+
case 'EdDSA': {
|
|
295
|
+
if (key.algorithm.name !== 'Ed25519' && key.algorithm.name !== 'Ed448') {
|
|
296
|
+
throw unusable('Ed25519 or Ed448');
|
|
297
|
+
}
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
2323
300
|
case 'ES256':
|
|
2324
301
|
case 'ES384':
|
|
2325
302
|
case 'ES512': {
|
|
@@ -2337,8 +314,7 @@ function checkSigCryptoKey(key, alg, ...usages) {
|
|
|
2337
314
|
checkUsage(key, usages);
|
|
2338
315
|
}
|
|
2339
316
|
|
|
2340
|
-
|
|
2341
|
-
let msg = 'Key must be ';
|
|
317
|
+
function message(msg, actual, ...types) {
|
|
2342
318
|
if (types.length > 2) {
|
|
2343
319
|
const last = types.pop();
|
|
2344
320
|
msg += `one of type ${types.join(', ')}, or ${last}.`;
|
|
@@ -2361,7 +337,13 @@ var invalidKeyInput = (actual, ...types) => {
|
|
|
2361
337
|
}
|
|
2362
338
|
}
|
|
2363
339
|
return msg;
|
|
340
|
+
}
|
|
341
|
+
var invalidKeyInput = (actual, ...types) => {
|
|
342
|
+
return message('Key must be ', actual, ...types);
|
|
2364
343
|
};
|
|
344
|
+
function withAlg(alg, actual, ...types) {
|
|
345
|
+
return message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
346
|
+
}
|
|
2365
347
|
|
|
2366
348
|
var isKeyLike = (key) => isKeyObject(key) || isCryptoKey(key);
|
|
2367
349
|
const types = ['KeyObject'];
|
|
@@ -2369,9 +351,6 @@ if (parseInt(process.versions.node) >= 16) {
|
|
|
2369
351
|
types.push('CryptoKey');
|
|
2370
352
|
}
|
|
2371
353
|
|
|
2372
|
-
promisify(inflateRaw);
|
|
2373
|
-
promisify(deflateRaw);
|
|
2374
|
-
|
|
2375
354
|
const isDisjoint = (...headers) => {
|
|
2376
355
|
const sources = headers.filter(Boolean);
|
|
2377
356
|
if (sources.length === 0 || sources.length === 1) {
|
|
@@ -2495,10 +474,6 @@ function setCurve(keyObject, curve) {
|
|
|
2495
474
|
weakMap$1.set(keyObject, curve);
|
|
2496
475
|
}
|
|
2497
476
|
|
|
2498
|
-
promisify(generateKeyPair);
|
|
2499
|
-
|
|
2500
|
-
promisify(pbkdf2);
|
|
2501
|
-
|
|
2502
477
|
const weakMap = new WeakMap();
|
|
2503
478
|
const getLength = (buf, index) => {
|
|
2504
479
|
let len = buf.readUInt8(1);
|
|
@@ -2749,6 +724,7 @@ const parse = (jwk) => {
|
|
|
2749
724
|
};
|
|
2750
725
|
|
|
2751
726
|
async function importJWK(jwk, alg, octAsKeyObject) {
|
|
727
|
+
var _a;
|
|
2752
728
|
if (!isObject(jwk)) {
|
|
2753
729
|
throw new TypeError('JWK must be an object');
|
|
2754
730
|
}
|
|
@@ -2763,7 +739,7 @@ async function importJWK(jwk, alg, octAsKeyObject) {
|
|
|
2763
739
|
}
|
|
2764
740
|
octAsKeyObject !== null && octAsKeyObject !== void 0 ? octAsKeyObject : (octAsKeyObject = jwk.ext !== true);
|
|
2765
741
|
if (octAsKeyObject) {
|
|
2766
|
-
return parse({ ...jwk, alg, ext: false });
|
|
742
|
+
return parse({ ...jwk, alg, ext: (_a = jwk.ext) !== null && _a !== void 0 ? _a : false });
|
|
2767
743
|
}
|
|
2768
744
|
return decode(jwk.k);
|
|
2769
745
|
case 'RSA':
|
|
@@ -2778,19 +754,19 @@ async function importJWK(jwk, alg, octAsKeyObject) {
|
|
|
2778
754
|
}
|
|
2779
755
|
}
|
|
2780
756
|
|
|
2781
|
-
const symmetricTypeCheck = (key) => {
|
|
757
|
+
const symmetricTypeCheck = (alg, key) => {
|
|
2782
758
|
if (key instanceof Uint8Array)
|
|
2783
759
|
return;
|
|
2784
760
|
if (!isKeyLike(key)) {
|
|
2785
|
-
throw new TypeError(
|
|
761
|
+
throw new TypeError(withAlg(alg, key, ...types, 'Uint8Array'));
|
|
2786
762
|
}
|
|
2787
763
|
if (key.type !== 'secret') {
|
|
2788
764
|
throw new TypeError(`${types.join(' or ')} instances for symmetric algorithms must be of type "secret"`);
|
|
2789
765
|
}
|
|
2790
766
|
};
|
|
2791
|
-
const asymmetricTypeCheck = (key, usage) => {
|
|
767
|
+
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
2792
768
|
if (!isKeyLike(key)) {
|
|
2793
|
-
throw new TypeError(
|
|
769
|
+
throw new TypeError(withAlg(alg, key, ...types));
|
|
2794
770
|
}
|
|
2795
771
|
if (key.type === 'secret') {
|
|
2796
772
|
throw new TypeError(`${types.join(' or ')} instances for asymmetric algorithms must not be of type "secret"`);
|
|
@@ -2814,10 +790,10 @@ const checkKeyType = (alg, key, usage) => {
|
|
|
2814
790
|
alg.startsWith('PBES2') ||
|
|
2815
791
|
/^A\d{3}(?:GCM)?KW$/.test(alg);
|
|
2816
792
|
if (symmetric) {
|
|
2817
|
-
symmetricTypeCheck(key);
|
|
793
|
+
symmetricTypeCheck(alg, key);
|
|
2818
794
|
}
|
|
2819
795
|
else {
|
|
2820
|
-
asymmetricTypeCheck(key, usage);
|
|
796
|
+
asymmetricTypeCheck(alg, key, usage);
|
|
2821
797
|
}
|
|
2822
798
|
};
|
|
2823
799
|
|
|
@@ -2865,11 +841,6 @@ const validateAlgorithms = (option, algorithms) => {
|
|
|
2865
841
|
return new Set(algorithms);
|
|
2866
842
|
};
|
|
2867
843
|
|
|
2868
|
-
process.version
|
|
2869
|
-
.slice(1)
|
|
2870
|
-
.split('.')
|
|
2871
|
-
.map((str) => parseInt(str, 10));
|
|
2872
|
-
|
|
2873
844
|
function dsaDigest(alg) {
|
|
2874
845
|
switch (alg) {
|
|
2875
846
|
case 'PS256':
|
|
@@ -3522,8 +1493,6 @@ function createRemoteJWKSet(url, options) {
|
|
|
3522
1493
|
return RemoteJWKSet.prototype.getKey.bind(new RemoteJWKSet(url, options));
|
|
3523
1494
|
}
|
|
3524
1495
|
|
|
3525
|
-
promisify(generateKeyPair);
|
|
3526
|
-
|
|
3527
1496
|
// https://appleid.apple.com/.well-known/openid-configuration
|
|
3528
1497
|
const issuer = 'https://appleid.apple.com';
|
|
3529
1498
|
const authorizationEndpoint = `${issuer}/auth/authorize`;
|