css-color-parser-h 3.0.4 → 3.0.5

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.
@@ -1,2550 +0,0 @@
1
- /******/ (function() { // webpackBootstrap
2
- /******/ var __webpack_modules__ = ({
3
-
4
- /***/ 208:
5
- /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
6
-
7
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
12
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
- /* MIT license */
14
- /* eslint-disable no-mixed-operators */
15
- var cssKeywords = __webpack_require__(101);
16
-
17
- // NOTE: conversions should only return primitive values (i.e. arrays, or
18
- // values that give correct `typeof` results).
19
- // do not use box values types (i.e. Number(), String(), etc.)
20
-
21
- var reverseKeywords = {};
22
- for (var _i = 0, _Object$keys = Object.keys(cssKeywords); _i < _Object$keys.length; _i++) {
23
- var key = _Object$keys[_i];
24
- reverseKeywords[cssKeywords[key]] = key;
25
- }
26
- var convert = {
27
- rgb: {
28
- channels: 3,
29
- labels: 'rgb'
30
- },
31
- hsl: {
32
- channels: 3,
33
- labels: 'hsl'
34
- },
35
- hsv: {
36
- channels: 3,
37
- labels: 'hsv'
38
- },
39
- hwb: {
40
- channels: 3,
41
- labels: 'hwb'
42
- },
43
- cmyk: {
44
- channels: 4,
45
- labels: 'cmyk'
46
- },
47
- xyz: {
48
- channels: 3,
49
- labels: 'xyz'
50
- },
51
- lab: {
52
- channels: 3,
53
- labels: 'lab'
54
- },
55
- lch: {
56
- channels: 3,
57
- labels: 'lch'
58
- },
59
- hex: {
60
- channels: 1,
61
- labels: ['hex']
62
- },
63
- keyword: {
64
- channels: 1,
65
- labels: ['keyword']
66
- },
67
- ansi16: {
68
- channels: 1,
69
- labels: ['ansi16']
70
- },
71
- ansi256: {
72
- channels: 1,
73
- labels: ['ansi256']
74
- },
75
- hcg: {
76
- channels: 3,
77
- labels: ['h', 'c', 'g']
78
- },
79
- apple: {
80
- channels: 3,
81
- labels: ['r16', 'g16', 'b16']
82
- },
83
- gray: {
84
- channels: 1,
85
- labels: ['gray']
86
- }
87
- };
88
- module.exports = convert;
89
-
90
- // Hide .channels and .labels properties
91
- for (var _i2 = 0, _Object$keys2 = Object.keys(convert); _i2 < _Object$keys2.length; _i2++) {
92
- var model = _Object$keys2[_i2];
93
- if (!('channels' in convert[model])) {
94
- throw new Error('missing channels property: ' + model);
95
- }
96
- if (!('labels' in convert[model])) {
97
- throw new Error('missing channel labels property: ' + model);
98
- }
99
- if (convert[model].labels.length !== convert[model].channels) {
100
- throw new Error('channel and label counts mismatch: ' + model);
101
- }
102
- var _convert$model = convert[model],
103
- channels = _convert$model.channels,
104
- labels = _convert$model.labels;
105
- delete convert[model].channels;
106
- delete convert[model].labels;
107
- Object.defineProperty(convert[model], 'channels', {
108
- value: channels
109
- });
110
- Object.defineProperty(convert[model], 'labels', {
111
- value: labels
112
- });
113
- }
114
- convert.rgb.hsl = function (rgb) {
115
- var r = rgb[0] / 255;
116
- var g = rgb[1] / 255;
117
- var b = rgb[2] / 255;
118
- var min = Math.min(r, g, b);
119
- var max = Math.max(r, g, b);
120
- var delta = max - min;
121
- var h;
122
- var s;
123
- if (max === min) {
124
- h = 0;
125
- } else if (r === max) {
126
- h = (g - b) / delta;
127
- } else if (g === max) {
128
- h = 2 + (b - r) / delta;
129
- } else if (b === max) {
130
- h = 4 + (r - g) / delta;
131
- }
132
- h = Math.min(h * 60, 360);
133
- if (h < 0) {
134
- h += 360;
135
- }
136
- var l = (min + max) / 2;
137
- if (max === min) {
138
- s = 0;
139
- } else if (l <= 0.5) {
140
- s = delta / (max + min);
141
- } else {
142
- s = delta / (2 - max - min);
143
- }
144
- return [h, s * 100, l * 100];
145
- };
146
- convert.rgb.hsv = function (rgb) {
147
- var rdif;
148
- var gdif;
149
- var bdif;
150
- var h;
151
- var s;
152
- var r = rgb[0] / 255;
153
- var g = rgb[1] / 255;
154
- var b = rgb[2] / 255;
155
- var v = Math.max(r, g, b);
156
- var diff = v - Math.min(r, g, b);
157
- var diffc = function diffc(c) {
158
- return (v - c) / 6 / diff + 1 / 2;
159
- };
160
- if (diff === 0) {
161
- h = 0;
162
- s = 0;
163
- } else {
164
- s = diff / v;
165
- rdif = diffc(r);
166
- gdif = diffc(g);
167
- bdif = diffc(b);
168
- if (r === v) {
169
- h = bdif - gdif;
170
- } else if (g === v) {
171
- h = 1 / 3 + rdif - bdif;
172
- } else if (b === v) {
173
- h = 2 / 3 + gdif - rdif;
174
- }
175
- if (h < 0) {
176
- h += 1;
177
- } else if (h > 1) {
178
- h -= 1;
179
- }
180
- }
181
- return [h * 360, s * 100, v * 100];
182
- };
183
- convert.rgb.hwb = function (rgb) {
184
- var r = rgb[0];
185
- var g = rgb[1];
186
- var b = rgb[2];
187
- var h = convert.rgb.hsl(rgb)[0];
188
- var w = 1 / 255 * Math.min(r, Math.min(g, b));
189
- b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
190
- return [h, w * 100, b * 100];
191
- };
192
- convert.rgb.cmyk = function (rgb) {
193
- var r = rgb[0] / 255;
194
- var g = rgb[1] / 255;
195
- var b = rgb[2] / 255;
196
- var k = Math.min(1 - r, 1 - g, 1 - b);
197
- var c = (1 - r - k) / (1 - k) || 0;
198
- var m = (1 - g - k) / (1 - k) || 0;
199
- var y = (1 - b - k) / (1 - k) || 0;
200
- return [c * 100, m * 100, y * 100, k * 100];
201
- };
202
- function comparativeDistance(x, y) {
203
- /*
204
- See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
205
- */
206
- return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
207
- }
208
- convert.rgb.keyword = function (rgb) {
209
- var reversed = reverseKeywords[rgb];
210
- if (reversed) {
211
- return reversed;
212
- }
213
- var currentClosestDistance = Infinity;
214
- var currentClosestKeyword;
215
- for (var _i3 = 0, _Object$keys3 = Object.keys(cssKeywords); _i3 < _Object$keys3.length; _i3++) {
216
- var keyword = _Object$keys3[_i3];
217
- var value = cssKeywords[keyword];
218
-
219
- // Compute comparative distance
220
- var distance = comparativeDistance(rgb, value);
221
-
222
- // Check if its less, if so set as closest
223
- if (distance < currentClosestDistance) {
224
- currentClosestDistance = distance;
225
- currentClosestKeyword = keyword;
226
- }
227
- }
228
- return currentClosestKeyword;
229
- };
230
- convert.keyword.rgb = function (keyword) {
231
- return cssKeywords[keyword];
232
- };
233
- convert.rgb.xyz = function (rgb) {
234
- var r = rgb[0] / 255;
235
- var g = rgb[1] / 255;
236
- var b = rgb[2] / 255;
237
-
238
- // Assume sRGB
239
- r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
240
- g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
241
- b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
242
- var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
243
- var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
244
- var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
245
- return [x * 100, y * 100, z * 100];
246
- };
247
- convert.rgb.lab = function (rgb) {
248
- var xyz = convert.rgb.xyz(rgb);
249
- var x = xyz[0];
250
- var y = xyz[1];
251
- var z = xyz[2];
252
- x /= 95.047;
253
- y /= 100;
254
- z /= 108.883;
255
- x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
256
- y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
257
- z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
258
- var l = 116 * y - 16;
259
- var a = 500 * (x - y);
260
- var b = 200 * (y - z);
261
- return [l, a, b];
262
- };
263
- convert.hsl.rgb = function (hsl) {
264
- var h = hsl[0] / 360;
265
- var s = hsl[1] / 100;
266
- var l = hsl[2] / 100;
267
- var t2;
268
- var t3;
269
- var val;
270
- if (s === 0) {
271
- val = l * 255;
272
- return [val, val, val];
273
- }
274
- if (l < 0.5) {
275
- t2 = l * (1 + s);
276
- } else {
277
- t2 = l + s - l * s;
278
- }
279
- var t1 = 2 * l - t2;
280
- var rgb = [0, 0, 0];
281
- for (var i = 0; i < 3; i++) {
282
- t3 = h + 1 / 3 * -(i - 1);
283
- if (t3 < 0) {
284
- t3++;
285
- }
286
- if (t3 > 1) {
287
- t3--;
288
- }
289
- if (6 * t3 < 1) {
290
- val = t1 + (t2 - t1) * 6 * t3;
291
- } else if (2 * t3 < 1) {
292
- val = t2;
293
- } else if (3 * t3 < 2) {
294
- val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
295
- } else {
296
- val = t1;
297
- }
298
- rgb[i] = val * 255;
299
- }
300
- return rgb;
301
- };
302
- convert.hsl.hsv = function (hsl) {
303
- var h = hsl[0];
304
- var s = hsl[1] / 100;
305
- var l = hsl[2] / 100;
306
- var smin = s;
307
- var lmin = Math.max(l, 0.01);
308
- l *= 2;
309
- s *= l <= 1 ? l : 2 - l;
310
- smin *= lmin <= 1 ? lmin : 2 - lmin;
311
- var v = (l + s) / 2;
312
- var sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
313
- return [h, sv * 100, v * 100];
314
- };
315
- convert.hsv.rgb = function (hsv) {
316
- var h = hsv[0] / 60;
317
- var s = hsv[1] / 100;
318
- var v = hsv[2] / 100;
319
- var hi = Math.floor(h) % 6;
320
- var f = h - Math.floor(h);
321
- var p = 255 * v * (1 - s);
322
- var q = 255 * v * (1 - s * f);
323
- var t = 255 * v * (1 - s * (1 - f));
324
- v *= 255;
325
- switch (hi) {
326
- case 0:
327
- return [v, t, p];
328
- case 1:
329
- return [q, v, p];
330
- case 2:
331
- return [p, v, t];
332
- case 3:
333
- return [p, q, v];
334
- case 4:
335
- return [t, p, v];
336
- case 5:
337
- return [v, p, q];
338
- }
339
- };
340
- convert.hsv.hsl = function (hsv) {
341
- var h = hsv[0];
342
- var s = hsv[1] / 100;
343
- var v = hsv[2] / 100;
344
- var vmin = Math.max(v, 0.01);
345
- var sl;
346
- var l;
347
- l = (2 - s) * v;
348
- var lmin = (2 - s) * vmin;
349
- sl = s * vmin;
350
- sl /= lmin <= 1 ? lmin : 2 - lmin;
351
- sl = sl || 0;
352
- l /= 2;
353
- return [h, sl * 100, l * 100];
354
- };
355
-
356
- // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
357
- convert.hwb.rgb = function (hwb) {
358
- var h = hwb[0] / 360;
359
- var wh = hwb[1] / 100;
360
- var bl = hwb[2] / 100;
361
- var ratio = wh + bl;
362
- var f;
363
-
364
- // Wh + bl cant be > 1
365
- if (ratio > 1) {
366
- wh /= ratio;
367
- bl /= ratio;
368
- }
369
- var i = Math.floor(6 * h);
370
- var v = 1 - bl;
371
- f = 6 * h - i;
372
- if ((i & 0x01) !== 0) {
373
- f = 1 - f;
374
- }
375
- var n = wh + f * (v - wh); // Linear interpolation
376
-
377
- var r;
378
- var g;
379
- var b;
380
- /* eslint-disable max-statements-per-line,no-multi-spaces */
381
- switch (i) {
382
- default:
383
- case 6:
384
- case 0:
385
- r = v;
386
- g = n;
387
- b = wh;
388
- break;
389
- case 1:
390
- r = n;
391
- g = v;
392
- b = wh;
393
- break;
394
- case 2:
395
- r = wh;
396
- g = v;
397
- b = n;
398
- break;
399
- case 3:
400
- r = wh;
401
- g = n;
402
- b = v;
403
- break;
404
- case 4:
405
- r = n;
406
- g = wh;
407
- b = v;
408
- break;
409
- case 5:
410
- r = v;
411
- g = wh;
412
- b = n;
413
- break;
414
- }
415
- /* eslint-enable max-statements-per-line,no-multi-spaces */
416
-
417
- return [r * 255, g * 255, b * 255];
418
- };
419
- convert.cmyk.rgb = function (cmyk) {
420
- var c = cmyk[0] / 100;
421
- var m = cmyk[1] / 100;
422
- var y = cmyk[2] / 100;
423
- var k = cmyk[3] / 100;
424
- var r = 1 - Math.min(1, c * (1 - k) + k);
425
- var g = 1 - Math.min(1, m * (1 - k) + k);
426
- var b = 1 - Math.min(1, y * (1 - k) + k);
427
- return [r * 255, g * 255, b * 255];
428
- };
429
- convert.xyz.rgb = function (xyz) {
430
- var x = xyz[0] / 100;
431
- var y = xyz[1] / 100;
432
- var z = xyz[2] / 100;
433
- var r;
434
- var g;
435
- var b;
436
- r = x * 3.2406 + y * -1.5372 + z * -0.4986;
437
- g = x * -0.9689 + y * 1.8758 + z * 0.0415;
438
- b = x * 0.0557 + y * -0.2040 + z * 1.0570;
439
-
440
- // Assume sRGB
441
- r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
442
- g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
443
- b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
444
- r = Math.min(Math.max(0, r), 1);
445
- g = Math.min(Math.max(0, g), 1);
446
- b = Math.min(Math.max(0, b), 1);
447
- return [r * 255, g * 255, b * 255];
448
- };
449
- convert.xyz.lab = function (xyz) {
450
- var x = xyz[0];
451
- var y = xyz[1];
452
- var z = xyz[2];
453
- x /= 95.047;
454
- y /= 100;
455
- z /= 108.883;
456
- x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
457
- y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
458
- z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
459
- var l = 116 * y - 16;
460
- var a = 500 * (x - y);
461
- var b = 200 * (y - z);
462
- return [l, a, b];
463
- };
464
- convert.lab.xyz = function (lab) {
465
- var l = lab[0];
466
- var a = lab[1];
467
- var b = lab[2];
468
- var x;
469
- var y;
470
- var z;
471
- y = (l + 16) / 116;
472
- x = a / 500 + y;
473
- z = y - b / 200;
474
- var y2 = Math.pow(y, 3);
475
- var x2 = Math.pow(x, 3);
476
- var z2 = Math.pow(z, 3);
477
- y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
478
- x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
479
- z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
480
- x *= 95.047;
481
- y *= 100;
482
- z *= 108.883;
483
- return [x, y, z];
484
- };
485
- convert.lab.lch = function (lab) {
486
- var l = lab[0];
487
- var a = lab[1];
488
- var b = lab[2];
489
- var h;
490
- var hr = Math.atan2(b, a);
491
- h = hr * 360 / 2 / Math.PI;
492
- if (h < 0) {
493
- h += 360;
494
- }
495
- var c = Math.sqrt(a * a + b * b);
496
- return [l, c, h];
497
- };
498
- convert.lch.lab = function (lch) {
499
- var l = lch[0];
500
- var c = lch[1];
501
- var h = lch[2];
502
- var hr = h / 360 * 2 * Math.PI;
503
- var a = c * Math.cos(hr);
504
- var b = c * Math.sin(hr);
505
- return [l, a, b];
506
- };
507
- convert.rgb.ansi16 = function (args) {
508
- var saturation = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
509
- var _args = _slicedToArray(args, 3),
510
- r = _args[0],
511
- g = _args[1],
512
- b = _args[2];
513
- var value = saturation === null ? convert.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
514
-
515
- value = Math.round(value / 50);
516
- if (value === 0) {
517
- return 30;
518
- }
519
- var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
520
- if (value === 2) {
521
- ansi += 60;
522
- }
523
- return ansi;
524
- };
525
- convert.hsv.ansi16 = function (args) {
526
- // Optimization here; we already know the value and don't need to get
527
- // it converted for us.
528
- return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
529
- };
530
- convert.rgb.ansi256 = function (args) {
531
- var r = args[0];
532
- var g = args[1];
533
- var b = args[2];
534
-
535
- // We use the extended greyscale palette here, with the exception of
536
- // black and white. normal palette only has 4 greyscale shades.
537
- if (r === g && g === b) {
538
- if (r < 8) {
539
- return 16;
540
- }
541
- if (r > 248) {
542
- return 231;
543
- }
544
- return Math.round((r - 8) / 247 * 24) + 232;
545
- }
546
- var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
547
- return ansi;
548
- };
549
- convert.ansi16.rgb = function (args) {
550
- var color = args % 10;
551
-
552
- // Handle greyscale
553
- if (color === 0 || color === 7) {
554
- if (args > 50) {
555
- color += 3.5;
556
- }
557
- color = color / 10.5 * 255;
558
- return [color, color, color];
559
- }
560
- var mult = (~~(args > 50) + 1) * 0.5;
561
- var r = (color & 1) * mult * 255;
562
- var g = (color >> 1 & 1) * mult * 255;
563
- var b = (color >> 2 & 1) * mult * 255;
564
- return [r, g, b];
565
- };
566
- convert.ansi256.rgb = function (args) {
567
- // Handle greyscale
568
- if (args >= 232) {
569
- var c = (args - 232) * 10 + 8;
570
- return [c, c, c];
571
- }
572
- args -= 16;
573
- var rem;
574
- var r = Math.floor(args / 36) / 5 * 255;
575
- var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
576
- var b = rem % 6 / 5 * 255;
577
- return [r, g, b];
578
- };
579
- convert.rgb.hex = function (args) {
580
- var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
581
- var string = integer.toString(16).toUpperCase();
582
- return '000000'.substring(string.length) + string;
583
- };
584
- convert.hex.rgb = function (args) {
585
- var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
586
- if (!match) {
587
- return [0, 0, 0];
588
- }
589
- var colorString = match[0];
590
- if (match[0].length === 3) {
591
- colorString = colorString.split('').map(function (_char) {
592
- return _char + _char;
593
- }).join('');
594
- }
595
- var integer = parseInt(colorString, 16);
596
- var r = integer >> 16 & 0xFF;
597
- var g = integer >> 8 & 0xFF;
598
- var b = integer & 0xFF;
599
- return [r, g, b];
600
- };
601
- convert.rgb.hcg = function (rgb) {
602
- var r = rgb[0] / 255;
603
- var g = rgb[1] / 255;
604
- var b = rgb[2] / 255;
605
- var max = Math.max(Math.max(r, g), b);
606
- var min = Math.min(Math.min(r, g), b);
607
- var chroma = max - min;
608
- var grayscale;
609
- var hue;
610
- if (chroma < 1) {
611
- grayscale = min / (1 - chroma);
612
- } else {
613
- grayscale = 0;
614
- }
615
- if (chroma <= 0) {
616
- hue = 0;
617
- } else if (max === r) {
618
- hue = (g - b) / chroma % 6;
619
- } else if (max === g) {
620
- hue = 2 + (b - r) / chroma;
621
- } else {
622
- hue = 4 + (r - g) / chroma;
623
- }
624
- hue /= 6;
625
- hue %= 1;
626
- return [hue * 360, chroma * 100, grayscale * 100];
627
- };
628
- convert.hsl.hcg = function (hsl) {
629
- var s = hsl[1] / 100;
630
- var l = hsl[2] / 100;
631
- var c = l < 0.5 ? 2.0 * s * l : 2.0 * s * (1.0 - l);
632
- var f = 0;
633
- if (c < 1.0) {
634
- f = (l - 0.5 * c) / (1.0 - c);
635
- }
636
- return [hsl[0], c * 100, f * 100];
637
- };
638
- convert.hsv.hcg = function (hsv) {
639
- var s = hsv[1] / 100;
640
- var v = hsv[2] / 100;
641
- var c = s * v;
642
- var f = 0;
643
- if (c < 1.0) {
644
- f = (v - c) / (1 - c);
645
- }
646
- return [hsv[0], c * 100, f * 100];
647
- };
648
- convert.hcg.rgb = function (hcg) {
649
- var h = hcg[0] / 360;
650
- var c = hcg[1] / 100;
651
- var g = hcg[2] / 100;
652
- if (c === 0.0) {
653
- return [g * 255, g * 255, g * 255];
654
- }
655
- var pure = [0, 0, 0];
656
- var hi = h % 1 * 6;
657
- var v = hi % 1;
658
- var w = 1 - v;
659
- var mg = 0;
660
-
661
- /* eslint-disable max-statements-per-line */
662
- switch (Math.floor(hi)) {
663
- case 0:
664
- pure[0] = 1;
665
- pure[1] = v;
666
- pure[2] = 0;
667
- break;
668
- case 1:
669
- pure[0] = w;
670
- pure[1] = 1;
671
- pure[2] = 0;
672
- break;
673
- case 2:
674
- pure[0] = 0;
675
- pure[1] = 1;
676
- pure[2] = v;
677
- break;
678
- case 3:
679
- pure[0] = 0;
680
- pure[1] = w;
681
- pure[2] = 1;
682
- break;
683
- case 4:
684
- pure[0] = v;
685
- pure[1] = 0;
686
- pure[2] = 1;
687
- break;
688
- default:
689
- pure[0] = 1;
690
- pure[1] = 0;
691
- pure[2] = w;
692
- }
693
- /* eslint-enable max-statements-per-line */
694
-
695
- mg = (1.0 - c) * g;
696
- return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
697
- };
698
- convert.hcg.hsv = function (hcg) {
699
- var c = hcg[1] / 100;
700
- var g = hcg[2] / 100;
701
- var v = c + g * (1.0 - c);
702
- var f = 0;
703
- if (v > 0.0) {
704
- f = c / v;
705
- }
706
- return [hcg[0], f * 100, v * 100];
707
- };
708
- convert.hcg.hsl = function (hcg) {
709
- var c = hcg[1] / 100;
710
- var g = hcg[2] / 100;
711
- var l = g * (1.0 - c) + 0.5 * c;
712
- var s = 0;
713
- if (l > 0.0 && l < 0.5) {
714
- s = c / (2 * l);
715
- } else if (l >= 0.5 && l < 1.0) {
716
- s = c / (2 * (1 - l));
717
- }
718
- return [hcg[0], s * 100, l * 100];
719
- };
720
- convert.hcg.hwb = function (hcg) {
721
- var c = hcg[1] / 100;
722
- var g = hcg[2] / 100;
723
- var v = c + g * (1.0 - c);
724
- return [hcg[0], (v - c) * 100, (1 - v) * 100];
725
- };
726
- convert.hwb.hcg = function (hwb) {
727
- var w = hwb[1] / 100;
728
- var b = hwb[2] / 100;
729
- var v = 1 - b;
730
- var c = v - w;
731
- var g = 0;
732
- if (c < 1) {
733
- g = (v - c) / (1 - c);
734
- }
735
- return [hwb[0], c * 100, g * 100];
736
- };
737
- convert.apple.rgb = function (apple) {
738
- return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
739
- };
740
- convert.rgb.apple = function (rgb) {
741
- return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
742
- };
743
- convert.gray.rgb = function (args) {
744
- return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
745
- };
746
- convert.gray.hsl = function (args) {
747
- return [0, 0, args[0]];
748
- };
749
- convert.gray.hsv = convert.gray.hsl;
750
- convert.gray.hwb = function (gray) {
751
- return [0, 100, gray[0]];
752
- };
753
- convert.gray.cmyk = function (gray) {
754
- return [0, 0, 0, gray[0]];
755
- };
756
- convert.gray.lab = function (gray) {
757
- return [gray[0], 0, 0];
758
- };
759
- convert.gray.hex = function (gray) {
760
- var val = Math.round(gray[0] / 100 * 255) & 0xFF;
761
- var integer = (val << 16) + (val << 8) + val;
762
- var string = integer.toString(16).toUpperCase();
763
- return '000000'.substring(string.length) + string;
764
- };
765
- convert.rgb.gray = function (rgb) {
766
- var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
767
- return [val / 255 * 100];
768
- };
769
-
770
- /***/ }),
771
-
772
- /***/ 907:
773
- /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
774
-
775
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
776
- var conversions = __webpack_require__(208);
777
- var route = __webpack_require__(171);
778
- var convert = {};
779
- var models = Object.keys(conversions);
780
- function wrapRaw(fn) {
781
- var wrappedFn = function wrappedFn() {
782
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
783
- args[_key] = arguments[_key];
784
- }
785
- var arg0 = args[0];
786
- if (arg0 === undefined || arg0 === null) {
787
- return arg0;
788
- }
789
- if (arg0.length > 1) {
790
- args = arg0;
791
- }
792
- return fn(args);
793
- };
794
-
795
- // Preserve .conversion property if there is one
796
- if ('conversion' in fn) {
797
- wrappedFn.conversion = fn.conversion;
798
- }
799
- return wrappedFn;
800
- }
801
- function wrapRounded(fn) {
802
- var wrappedFn = function wrappedFn() {
803
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
804
- args[_key2] = arguments[_key2];
805
- }
806
- var arg0 = args[0];
807
- if (arg0 === undefined || arg0 === null) {
808
- return arg0;
809
- }
810
- if (arg0.length > 1) {
811
- args = arg0;
812
- }
813
- var result = fn(args);
814
-
815
- // We're assuming the result is an array here.
816
- // see notice in conversions.js; don't use box types
817
- // in conversion functions.
818
- if (_typeof(result) === 'object') {
819
- for (var len = result.length, i = 0; i < len; i++) {
820
- result[i] = Math.round(result[i]);
821
- }
822
- }
823
- return result;
824
- };
825
-
826
- // Preserve .conversion property if there is one
827
- if ('conversion' in fn) {
828
- wrappedFn.conversion = fn.conversion;
829
- }
830
- return wrappedFn;
831
- }
832
- models.forEach(function (fromModel) {
833
- convert[fromModel] = {};
834
- Object.defineProperty(convert[fromModel], 'channels', {
835
- value: conversions[fromModel].channels
836
- });
837
- Object.defineProperty(convert[fromModel], 'labels', {
838
- value: conversions[fromModel].labels
839
- });
840
- var routes = route(fromModel);
841
- var routeModels = Object.keys(routes);
842
- routeModels.forEach(function (toModel) {
843
- var fn = routes[toModel];
844
- convert[fromModel][toModel] = wrapRounded(fn);
845
- convert[fromModel][toModel].raw = wrapRaw(fn);
846
- });
847
- });
848
- module.exports = convert;
849
-
850
- /***/ }),
851
-
852
- /***/ 171:
853
- /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
854
-
855
- var conversions = __webpack_require__(208);
856
-
857
- /*
858
- This function routes a model to all other models.
859
-
860
- all functions that are routed have a property `.conversion` attached
861
- to the returned synthetic function. This property is an array
862
- of strings, each with the steps in between the 'from' and 'to'
863
- color models (inclusive).
864
-
865
- conversions that are not possible simply are not included.
866
- */
867
-
868
- function buildGraph() {
869
- var graph = {};
870
- // https://jsperf.com/object-keys-vs-for-in-with-closure/3
871
- var models = Object.keys(conversions);
872
- for (var len = models.length, i = 0; i < len; i++) {
873
- graph[models[i]] = {
874
- // http://jsperf.com/1-vs-infinity
875
- // micro-opt, but this is simple.
876
- distance: -1,
877
- parent: null
878
- };
879
- }
880
- return graph;
881
- }
882
-
883
- // https://en.wikipedia.org/wiki/Breadth-first_search
884
- function deriveBFS(fromModel) {
885
- var graph = buildGraph();
886
- var queue = [fromModel]; // Unshift -> queue -> pop
887
-
888
- graph[fromModel].distance = 0;
889
- while (queue.length) {
890
- var current = queue.pop();
891
- var adjacents = Object.keys(conversions[current]);
892
- for (var len = adjacents.length, i = 0; i < len; i++) {
893
- var adjacent = adjacents[i];
894
- var node = graph[adjacent];
895
- if (node.distance === -1) {
896
- node.distance = graph[current].distance + 1;
897
- node.parent = current;
898
- queue.unshift(adjacent);
899
- }
900
- }
901
- }
902
- return graph;
903
- }
904
- function link(from, to) {
905
- return function (args) {
906
- return to(from(args));
907
- };
908
- }
909
- function wrapConversion(toModel, graph) {
910
- var path = [graph[toModel].parent, toModel];
911
- var fn = conversions[graph[toModel].parent][toModel];
912
- var cur = graph[toModel].parent;
913
- while (graph[cur].parent) {
914
- path.unshift(graph[cur].parent);
915
- fn = link(conversions[graph[cur].parent][cur], fn);
916
- cur = graph[cur].parent;
917
- }
918
- fn.conversion = path;
919
- return fn;
920
- }
921
- module.exports = function (fromModel) {
922
- var graph = deriveBFS(fromModel);
923
- var conversion = {};
924
- var models = Object.keys(graph);
925
- for (var len = models.length, i = 0; i < len; i++) {
926
- var toModel = models[i];
927
- var node = graph[toModel];
928
- if (node.parent === null) {
929
- // No possible conversion, or this node is the source model.
930
- continue;
931
- }
932
- conversion[toModel] = wrapConversion(toModel, graph);
933
- }
934
- return conversion;
935
- };
936
-
937
- /***/ }),
938
-
939
- /***/ 101:
940
- /***/ (function(module) {
941
-
942
- "use strict";
943
-
944
-
945
- module.exports = {
946
- "aliceblue": [240, 248, 255],
947
- "antiquewhite": [250, 235, 215],
948
- "aqua": [0, 255, 255],
949
- "aquamarine": [127, 255, 212],
950
- "azure": [240, 255, 255],
951
- "beige": [245, 245, 220],
952
- "bisque": [255, 228, 196],
953
- "black": [0, 0, 0],
954
- "blanchedalmond": [255, 235, 205],
955
- "blue": [0, 0, 255],
956
- "blueviolet": [138, 43, 226],
957
- "brown": [165, 42, 42],
958
- "burlywood": [222, 184, 135],
959
- "cadetblue": [95, 158, 160],
960
- "chartreuse": [127, 255, 0],
961
- "chocolate": [210, 105, 30],
962
- "coral": [255, 127, 80],
963
- "cornflowerblue": [100, 149, 237],
964
- "cornsilk": [255, 248, 220],
965
- "crimson": [220, 20, 60],
966
- "cyan": [0, 255, 255],
967
- "darkblue": [0, 0, 139],
968
- "darkcyan": [0, 139, 139],
969
- "darkgoldenrod": [184, 134, 11],
970
- "darkgray": [169, 169, 169],
971
- "darkgreen": [0, 100, 0],
972
- "darkgrey": [169, 169, 169],
973
- "darkkhaki": [189, 183, 107],
974
- "darkmagenta": [139, 0, 139],
975
- "darkolivegreen": [85, 107, 47],
976
- "darkorange": [255, 140, 0],
977
- "darkorchid": [153, 50, 204],
978
- "darkred": [139, 0, 0],
979
- "darksalmon": [233, 150, 122],
980
- "darkseagreen": [143, 188, 143],
981
- "darkslateblue": [72, 61, 139],
982
- "darkslategray": [47, 79, 79],
983
- "darkslategrey": [47, 79, 79],
984
- "darkturquoise": [0, 206, 209],
985
- "darkviolet": [148, 0, 211],
986
- "deeppink": [255, 20, 147],
987
- "deepskyblue": [0, 191, 255],
988
- "dimgray": [105, 105, 105],
989
- "dimgrey": [105, 105, 105],
990
- "dodgerblue": [30, 144, 255],
991
- "firebrick": [178, 34, 34],
992
- "floralwhite": [255, 250, 240],
993
- "forestgreen": [34, 139, 34],
994
- "fuchsia": [255, 0, 255],
995
- "gainsboro": [220, 220, 220],
996
- "ghostwhite": [248, 248, 255],
997
- "gold": [255, 215, 0],
998
- "goldenrod": [218, 165, 32],
999
- "gray": [128, 128, 128],
1000
- "green": [0, 128, 0],
1001
- "greenyellow": [173, 255, 47],
1002
- "grey": [128, 128, 128],
1003
- "honeydew": [240, 255, 240],
1004
- "hotpink": [255, 105, 180],
1005
- "indianred": [205, 92, 92],
1006
- "indigo": [75, 0, 130],
1007
- "ivory": [255, 255, 240],
1008
- "khaki": [240, 230, 140],
1009
- "lavender": [230, 230, 250],
1010
- "lavenderblush": [255, 240, 245],
1011
- "lawngreen": [124, 252, 0],
1012
- "lemonchiffon": [255, 250, 205],
1013
- "lightblue": [173, 216, 230],
1014
- "lightcoral": [240, 128, 128],
1015
- "lightcyan": [224, 255, 255],
1016
- "lightgoldenrodyellow": [250, 250, 210],
1017
- "lightgray": [211, 211, 211],
1018
- "lightgreen": [144, 238, 144],
1019
- "lightgrey": [211, 211, 211],
1020
- "lightpink": [255, 182, 193],
1021
- "lightsalmon": [255, 160, 122],
1022
- "lightseagreen": [32, 178, 170],
1023
- "lightskyblue": [135, 206, 250],
1024
- "lightslategray": [119, 136, 153],
1025
- "lightslategrey": [119, 136, 153],
1026
- "lightsteelblue": [176, 196, 222],
1027
- "lightyellow": [255, 255, 224],
1028
- "lime": [0, 255, 0],
1029
- "limegreen": [50, 205, 50],
1030
- "linen": [250, 240, 230],
1031
- "magenta": [255, 0, 255],
1032
- "maroon": [128, 0, 0],
1033
- "mediumaquamarine": [102, 205, 170],
1034
- "mediumblue": [0, 0, 205],
1035
- "mediumorchid": [186, 85, 211],
1036
- "mediumpurple": [147, 112, 219],
1037
- "mediumseagreen": [60, 179, 113],
1038
- "mediumslateblue": [123, 104, 238],
1039
- "mediumspringgreen": [0, 250, 154],
1040
- "mediumturquoise": [72, 209, 204],
1041
- "mediumvioletred": [199, 21, 133],
1042
- "midnightblue": [25, 25, 112],
1043
- "mintcream": [245, 255, 250],
1044
- "mistyrose": [255, 228, 225],
1045
- "moccasin": [255, 228, 181],
1046
- "navajowhite": [255, 222, 173],
1047
- "navy": [0, 0, 128],
1048
- "oldlace": [253, 245, 230],
1049
- "olive": [128, 128, 0],
1050
- "olivedrab": [107, 142, 35],
1051
- "orange": [255, 165, 0],
1052
- "orangered": [255, 69, 0],
1053
- "orchid": [218, 112, 214],
1054
- "palegoldenrod": [238, 232, 170],
1055
- "palegreen": [152, 251, 152],
1056
- "paleturquoise": [175, 238, 238],
1057
- "palevioletred": [219, 112, 147],
1058
- "papayawhip": [255, 239, 213],
1059
- "peachpuff": [255, 218, 185],
1060
- "peru": [205, 133, 63],
1061
- "pink": [255, 192, 203],
1062
- "plum": [221, 160, 221],
1063
- "powderblue": [176, 224, 230],
1064
- "purple": [128, 0, 128],
1065
- "rebeccapurple": [102, 51, 153],
1066
- "red": [255, 0, 0],
1067
- "rosybrown": [188, 143, 143],
1068
- "royalblue": [65, 105, 225],
1069
- "saddlebrown": [139, 69, 19],
1070
- "salmon": [250, 128, 114],
1071
- "sandybrown": [244, 164, 96],
1072
- "seagreen": [46, 139, 87],
1073
- "seashell": [255, 245, 238],
1074
- "sienna": [160, 82, 45],
1075
- "silver": [192, 192, 192],
1076
- "skyblue": [135, 206, 235],
1077
- "slateblue": [106, 90, 205],
1078
- "slategray": [112, 128, 144],
1079
- "slategrey": [112, 128, 144],
1080
- "snow": [255, 250, 250],
1081
- "springgreen": [0, 255, 127],
1082
- "steelblue": [70, 130, 180],
1083
- "tan": [210, 180, 140],
1084
- "teal": [0, 128, 128],
1085
- "thistle": [216, 191, 216],
1086
- "tomato": [255, 99, 71],
1087
- "turquoise": [64, 224, 208],
1088
- "violet": [238, 130, 238],
1089
- "wheat": [245, 222, 179],
1090
- "white": [255, 255, 255],
1091
- "whitesmoke": [245, 245, 245],
1092
- "yellow": [255, 255, 0],
1093
- "yellowgreen": [154, 205, 50]
1094
- };
1095
-
1096
- /***/ })
1097
-
1098
- /******/ });
1099
- /************************************************************************/
1100
- /******/ // The module cache
1101
- /******/ var __webpack_module_cache__ = {};
1102
- /******/
1103
- /******/ // The require function
1104
- /******/ function __webpack_require__(moduleId) {
1105
- /******/ // Check if module is in cache
1106
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
1107
- /******/ if (cachedModule !== undefined) {
1108
- /******/ return cachedModule.exports;
1109
- /******/ }
1110
- /******/ // Create a new module (and put it into the cache)
1111
- /******/ var module = __webpack_module_cache__[moduleId] = {
1112
- /******/ // no module.id needed
1113
- /******/ // no module.loaded needed
1114
- /******/ exports: {}
1115
- /******/ };
1116
- /******/
1117
- /******/ // Execute the module function
1118
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
1119
- /******/
1120
- /******/ // Return the exports of the module
1121
- /******/ return module.exports;
1122
- /******/ }
1123
- /******/
1124
- /************************************************************************/
1125
- /******/ /* webpack/runtime/compat get default export */
1126
- /******/ !function() {
1127
- /******/ // getDefaultExport function for compatibility with non-harmony modules
1128
- /******/ __webpack_require__.n = function(module) {
1129
- /******/ var getter = module && module.__esModule ?
1130
- /******/ function() { return module['default']; } :
1131
- /******/ function() { return module; };
1132
- /******/ __webpack_require__.d(getter, { a: getter });
1133
- /******/ return getter;
1134
- /******/ };
1135
- /******/ }();
1136
- /******/
1137
- /******/ /* webpack/runtime/define property getters */
1138
- /******/ !function() {
1139
- /******/ // define getter functions for harmony exports
1140
- /******/ __webpack_require__.d = function(exports, definition) {
1141
- /******/ for(var key in definition) {
1142
- /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
1143
- /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
1144
- /******/ }
1145
- /******/ }
1146
- /******/ };
1147
- /******/ }();
1148
- /******/
1149
- /******/ /* webpack/runtime/hasOwnProperty shorthand */
1150
- /******/ !function() {
1151
- /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
1152
- /******/ }();
1153
- /******/
1154
- /******/ /* webpack/runtime/make namespace object */
1155
- /******/ !function() {
1156
- /******/ // define __esModule on exports
1157
- /******/ __webpack_require__.r = function(exports) {
1158
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
1159
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1160
- /******/ }
1161
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
1162
- /******/ };
1163
- /******/ }();
1164
- /******/
1165
- /************************************************************************/
1166
- var __webpack_exports__ = {};
1167
- // This entry need to be wrapped in an IIFE because it need to be in strict mode.
1168
- !function() {
1169
- "use strict";
1170
- // ESM COMPAT FLAG
1171
- __webpack_require__.r(__webpack_exports__);
1172
-
1173
- // EXPORTS
1174
- __webpack_require__.d(__webpack_exports__, {
1175
- "CssColorParser": function() { return /* reexport */ src_CssColorParser; },
1176
- "CssColorParserPlus": function() { return /* reexport */ src_CssColorParserPlus; }
1177
- });
1178
-
1179
- ;// CONCATENATED MODULE: ./src/utils/common.ts
1180
- var Check = /** @class */ (function () {
1181
- function Check() {
1182
- }
1183
- Check.type = function (paramName, value, type) {
1184
- var valueType = typeof value;
1185
- if (valueType !== type) {
1186
- throw new Error("Expected ".concat(paramName, " to be typeof ").concat(type, ", actual typeof was ").concat(valueType));
1187
- }
1188
- };
1189
- Check.types = function (paramName, value, types) {
1190
- var valueType = typeof value;
1191
- var isContained = types.includes(valueType);
1192
- if (!isContained) {
1193
- throw new Error("Expected ".concat(paramName, " to be typeof ").concat(types.join('|'), ", actual typeof was ").concat(valueType));
1194
- }
1195
- };
1196
- Check.numValue = function (paramName, value, min, max) {
1197
- Check.numMinValue(paramName, value, min);
1198
- Check.numMaxValue(paramName, value, max);
1199
- };
1200
- Check.numMinValue = function (paramName, value, min) {
1201
- if (value < min) {
1202
- throw new Error("Expected ".concat(paramName, " to > ").concat(min, ", actual value was ").concat(value));
1203
- }
1204
- };
1205
- Check.numMaxValue = function (paramName, value, max) {
1206
- if (value > max) {
1207
- throw new Error("Expected ".concat(paramName, " to < ").concat(max, ", actual value was ").concat(value));
1208
- }
1209
- };
1210
- Check.numIsInt = function (paramName, value, expectIsInt) {
1211
- var isInt = Math.floor(value) === value;
1212
- if (isInt !== expectIsInt) {
1213
- throw new Error("Expected ".concat(paramName, " to ").concat(expectIsInt ? 'Integer' : 'Float', ", actual value was ").concat(isInt ? 'Integer' : 'Float'));
1214
- }
1215
- };
1216
- return Check;
1217
- }());
1218
-
1219
- var ColorJson = /** @class */ (function () {
1220
- function ColorJson() {
1221
- }
1222
- return ColorJson;
1223
- }());
1224
-
1225
- function defaultValue(v, defaultV) {
1226
- if (v === undefined || v === null) {
1227
- return defaultV;
1228
- }
1229
- if (isNaN(v) && typeof defaultV === 'number') {
1230
- return defaultV;
1231
- }
1232
- return v;
1233
- }
1234
- function limitNumber(min, max, v) {
1235
- if (v > max) {
1236
- v = max;
1237
- }
1238
- else if (v < min) {
1239
- v = min;
1240
- }
1241
- return v;
1242
- }
1243
- function setNumberPrecision(number, precision) {
1244
- if (number === void 0) { number = 0; }
1245
- var prec = Math.pow(10, precision);
1246
- return Math.round(number * prec) / prec;
1247
- }
1248
-
1249
- ;// CONCATENATED MODULE: ./src/utils/color-tools.ts
1250
-
1251
- /*
1252
- * @Author: roman_123
1253
- * @Description: 部分核心代码修改自cesium
1254
- * @Date: 2022-11-28 17:32:57
1255
- * @LastEditTime: 2022-12-06 00:02:21
1256
- */
1257
- var CssColorStringParser = /** @class */ (function () {
1258
- function CssColorStringParser() {
1259
- }
1260
- // 去除字符串内所有空格
1261
- CssColorStringParser.clearStrSpace = function (v) {
1262
- return v.replace(/\s/g, '');
1263
- };
1264
- // 去除字符串两边空格,将中间多个空格合并为一个
1265
- CssColorStringParser.trimStr = function (v) {
1266
- v = v.replace(/\s+/g, ' ');
1267
- return v.trim();
1268
- };
1269
- // 解析3位16进制 #fff #fff0
1270
- CssColorStringParser.parse3BitsHEX = function (v) {
1271
- var regx = /^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i;
1272
- var res = regx.exec(v);
1273
- if (res) {
1274
- var res4 = defaultValue(res[4], 'f');
1275
- var r = CssColorStringParser._parseResStrForRgb(parseInt(res[1] + res[1], 16));
1276
- var g = CssColorStringParser._parseResStrForRgb(parseInt(res[2] + res[2], 16));
1277
- var b = CssColorStringParser._parseResStrForRgb(parseInt(res[3] + res[3], 16));
1278
- var a = CssColorStringParser._parsePercent(parseInt(res4 + res4, 16) / 255);
1279
- return [r, g, b, a];
1280
- }
1281
- return null;
1282
- };
1283
- // 解析6位16进制 #ffffff #ffffff00
1284
- CssColorStringParser.parse6BitsHEX = function (v) {
1285
- var regx = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i;
1286
- var res = regx.exec(v);
1287
- if (res) {
1288
- var res4 = defaultValue(res[4], 'ff');
1289
- var r = CssColorStringParser._parseResStrForRgb(parseInt(res[1], 16));
1290
- var g = CssColorStringParser._parseResStrForRgb(parseInt(res[2], 16));
1291
- var b = CssColorStringParser._parseResStrForRgb(parseInt(res[3], 16));
1292
- var a = CssColorStringParser._parsePercent(parseInt(res4, 16) / 255.0);
1293
- return [r, g, b, a];
1294
- }
1295
- return null;
1296
- };
1297
- // 解析rgb rgba rgb(255,255,255) rgba(255,255,255,1) rgba(100%,100%,100%, 1)
1298
- CssColorStringParser.parseRGBA = function (v) {
1299
- var regx = /^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i;
1300
- var res = regx.exec(v);
1301
- if (res) {
1302
- var r = CssColorStringParser._parseResStrForRgb(res[1]);
1303
- var g = CssColorStringParser._parseResStrForRgb(res[2]);
1304
- var b = CssColorStringParser._parseResStrForRgb(res[3]);
1305
- var a = CssColorStringParser._parsePercent(res[4]);
1306
- return [r, g, b, a];
1307
- }
1308
- return null;
1309
- };
1310
- // 解析hsl hsla hsl(360,100%,100%) hsla(360,100%,100%,1)
1311
- CssColorStringParser.parseHSLA = function (v) {
1312
- var regx = /^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i;
1313
- var res = regx.exec(v);
1314
- if (res) {
1315
- var h = CssColorStringParser._parseResStrForHue(res[1]);
1316
- var s = CssColorStringParser._parsePercent(res[2]);
1317
- var l = CssColorStringParser._parsePercent(res[3]);
1318
- var a = CssColorStringParser._parsePercent(res[4]);
1319
- return [h, s, l, a];
1320
- }
1321
- return null;
1322
- };
1323
- // 解析hwb
1324
- CssColorStringParser.parseHWB = function (v) {
1325
- var regx = /^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i;
1326
- var res = regx.exec(v);
1327
- if (res) {
1328
- var h = CssColorStringParser._parseResStrForHue(res[1]);
1329
- var w = CssColorStringParser._parsePercent(res[2]);
1330
- var b = CssColorStringParser._parsePercent(res[3]);
1331
- var a = CssColorStringParser._parsePercent(res[4]);
1332
- return [h, w, b, a];
1333
- }
1334
- return null;
1335
- };
1336
- // 解析rgb rgb(178 57 57 / 44%) 字符串中存在空格,因此使用清除两侧空格的原始字符串
1337
- CssColorStringParser.parseRGBA2 = function (v) {
1338
- var regx = /^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i;
1339
- var res = regx.exec(v);
1340
- if (res) {
1341
- var r = CssColorStringParser._parseResStrForRgb(res[1]);
1342
- var g = CssColorStringParser._parseResStrForRgb(res[2]);
1343
- var b = CssColorStringParser._parseResStrForRgb(res[3]);
1344
- var a = CssColorStringParser._parsePercent(res[4]);
1345
- return [r, g, b, a];
1346
- }
1347
- return null;
1348
- };
1349
- // 解析hsl hsl(215 85% 62% / 1)
1350
- CssColorStringParser.parseHSLA2 = function (v) {
1351
- var regx = /^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i;
1352
- var res = regx.exec(v);
1353
- if (res) {
1354
- var h = CssColorStringParser._parseResStrForHue(res[1]);
1355
- var s = CssColorStringParser._parsePercent(res[2]);
1356
- var l = CssColorStringParser._parsePercent(res[3]);
1357
- var a = CssColorStringParser._parsePercent(res[4]);
1358
- return [h, s, l, a];
1359
- }
1360
- return null;
1361
- };
1362
- // 将结果解析为数字
1363
- CssColorStringParser._parseResStrForRgb = function (v) {
1364
- if (typeof v === 'string') {
1365
- v = parseFloat(v) / ('%' === v.substr(-1) ? 100.0 / 255 : 1);
1366
- }
1367
- if (isNaN(v)) {
1368
- v = 1;
1369
- }
1370
- return limitNumber(0, 255, v);
1371
- };
1372
- CssColorStringParser._parseResStrForHue = function (v) {
1373
- if (typeof v === 'string') {
1374
- v = parseFloat(v);
1375
- }
1376
- if (isNaN(v)) {
1377
- v = 0;
1378
- }
1379
- return limitNumber(0, 360, v);
1380
- };
1381
- CssColorStringParser._parsePercent = function (v) {
1382
- if (typeof v === 'string') {
1383
- v = parseFloat(v) / ('%' === v.substr(-1) ? 100.0 : 1);
1384
- }
1385
- if (isNaN(v)) {
1386
- v = 1;
1387
- }
1388
- return limitNumber(0, 1, v);
1389
- };
1390
- return CssColorStringParser;
1391
- }());
1392
-
1393
-
1394
- ;// CONCATENATED MODULE: ./src/CssColorParser.ts
1395
- /*
1396
- * @Descripttion: 颜色解析器(轻量)
1397
- * @version: 1.0.0
1398
- * @Author: roman_123
1399
- * @Date: 2021-01-19 09:22:11
1400
- * @LastEditors: Please set LastEditors
1401
- * @LastEditTime: 2023-06-27 19:01:50
1402
- */
1403
-
1404
-
1405
- var CssColorParser = /** @class */ (function () {
1406
- function CssColorParser(red, green, blue, alpha) {
1407
- this.r = 255;
1408
- this.g = 255;
1409
- this.b = 255;
1410
- this.a = 1;
1411
- this._outColorPrecision = 2;
1412
- this._outAlphaPrecision = 2;
1413
- this.setColor(red, green, blue, alpha);
1414
- }
1415
- /**
1416
- * @description: 设置CssColorParser实例输出的精度
1417
- * @param {number} colorPrecision 输出颜色的精度
1418
- * @param {number} outAlphaPrecision 输出透明度的精度
1419
- * @return {CssColorParser}
1420
- */
1421
- CssColorParser.prototype.setOutPrecision = function (colorPrecision, outAlphaPrecision) {
1422
- Check.type('colorPrecision', colorPrecision, 'number');
1423
- Check.type('outAlphaPrecision', outAlphaPrecision, 'number');
1424
- Check.numMinValue('colorPrecision', colorPrecision, 0);
1425
- Check.numMinValue('outAlphaPrecision', outAlphaPrecision, 0);
1426
- Check.numIsInt('colorPrecision', colorPrecision, true);
1427
- Check.numIsInt('outAlphaPrecision', outAlphaPrecision, true);
1428
- this._outColorPrecision = colorPrecision;
1429
- this._outAlphaPrecision = outAlphaPrecision;
1430
- return this;
1431
- };
1432
- /**
1433
- * 设置颜色
1434
- * @param red
1435
- * @param green
1436
- * @param blue
1437
- * @param alpha
1438
- * @example: this.setColor(255,255,255,1)
1439
- */
1440
- CssColorParser.prototype.setColor = function (red, green, blue, alpha) {
1441
- this.r = limitNumber(0, 255, defaultValue(Number(red), 0));
1442
- this.g = limitNumber(0, 255, defaultValue(Number(green), 0));
1443
- this.b = limitNumber(0, 255, defaultValue(Number(blue), 0));
1444
- this.a = limitNumber(0, 1, defaultValue(Number(alpha), 1));
1445
- return this;
1446
- };
1447
- /**
1448
- * @description: 设置透明度
1449
- * @param {number} alpha
1450
- * @return {CssColorParser}
1451
- */
1452
- CssColorParser.prototype.setAlpha = function (alpha) {
1453
- this.a = limitNumber(0, 1, defaultValue(Number(alpha), 1));
1454
- return this;
1455
- };
1456
- /**
1457
- * @description: 设置红色值
1458
- * @param {number} red
1459
- * @return {CssColorParser}
1460
- */
1461
- CssColorParser.prototype.setRed = function (red) {
1462
- this.r = limitNumber(0, 255, defaultValue(Number(red), 0));
1463
- return this;
1464
- };
1465
- /**
1466
- * @description: 设置绿色值
1467
- * @param {number} green
1468
- * @return {CssColorParser}
1469
- */
1470
- CssColorParser.prototype.setGreen = function (green) {
1471
- this.g = limitNumber(0, 255, defaultValue(Number(green), 0));
1472
- return this;
1473
- };
1474
- /**
1475
- * @description: 设置蓝色值
1476
- * @param {number} blue
1477
- * @return {CssColorParser}
1478
- */
1479
- CssColorParser.prototype.setBlue = function (blue) {
1480
- this.b = limitNumber(0, 255, defaultValue(Number(blue), 0));
1481
- return this;
1482
- };
1483
- /**
1484
- * @description: 返回rgba格式的css字符串
1485
- * @return {string}
1486
- */
1487
- CssColorParser.prototype.toRGBA = function () {
1488
- var color = this.toJson();
1489
- if (color.a === 1) {
1490
- return "rgb(".concat(color.r, ",").concat(color.g, ",").concat(color.b, ")");
1491
- }
1492
- return "rgba(".concat(color.r, ",").concat(color.g, ",").concat(color.b, ",").concat(color.a, ")");
1493
- };
1494
- /**
1495
- * @description: 返回字符串
1496
- * @return {string}
1497
- */
1498
- CssColorParser.prototype.toString = function () {
1499
- return this.toRGBA();
1500
- };
1501
- /**
1502
- * @description: 归一化
1503
- * @return {array}
1504
- */
1505
- CssColorParser.prototype.toNormalize = function () {
1506
- var r = setNumberPrecision(this.r / 255, this._outColorPrecision);
1507
- var g = setNumberPrecision(this.g / 255, this._outColorPrecision);
1508
- var b = setNumberPrecision(this.b / 255, this._outColorPrecision);
1509
- var a = setNumberPrecision(this.a, this._outAlphaPrecision);
1510
- return [r, g, b, a];
1511
- };
1512
- /**
1513
- * @description: 返回16进制格式的css字符串
1514
- * @return {string}
1515
- */
1516
- CssColorParser.prototype.toHEX = function () {
1517
- var color = this.toJson();
1518
- var r = color.r.toString(16);
1519
- if (r.length < 2) {
1520
- r = "0".concat(r);
1521
- }
1522
- var g = color.g.toString(16);
1523
- if (g.length < 2) {
1524
- g = "0".concat(g);
1525
- }
1526
- var b = color.b.toString(16);
1527
- if (b.length < 2) {
1528
- b = "0".concat(b);
1529
- }
1530
- // 由于tojson后a会丢失精度,此处使用this.a
1531
- if (this.a < 1) {
1532
- var hexAlpha = parseInt((this.a * 255).toFixed()).toString(16);
1533
- if (hexAlpha.length < 2) {
1534
- hexAlpha = "0".concat(hexAlpha);
1535
- }
1536
- return "#".concat(r).concat(g).concat(b).concat(hexAlpha);
1537
- }
1538
- return "#".concat(r).concat(g).concat(b);
1539
- };
1540
- /**
1541
- * @description: 返回rgba数组
1542
- * @return {array}
1543
- */
1544
- CssColorParser.prototype.toArray = function () {
1545
- var color = this.toJson();
1546
- return [color.r, color.g, color.b, color.a];
1547
- };
1548
- /**
1549
- * @description: 返回ColorJson
1550
- * @return {ColorJson}
1551
- */
1552
- CssColorParser.prototype.toJson = function () {
1553
- return {
1554
- r: setNumberPrecision(this.r, this._outColorPrecision),
1555
- g: setNumberPrecision(this.g, this._outColorPrecision),
1556
- b: setNumberPrecision(this.b, this._outColorPrecision),
1557
- a: setNumberPrecision(this.a, this._outAlphaPrecision),
1558
- };
1559
- };
1560
- /**
1561
- * @description: 返回取反色后的新的实例
1562
- * @return {CssColorParser}
1563
- */
1564
- CssColorParser.prototype.toInvert = function () {
1565
- var r = 255 - this.r;
1566
- var g = 255 - this.g;
1567
- var b = 255 - this.b;
1568
- var a = 1 - this.a;
1569
- return new CssColorParser(r, g, b, a);
1570
- };
1571
- /**
1572
- * @description: 拷贝
1573
- * @return {CssColorParser}
1574
- */
1575
- CssColorParser.prototype.clone = function () {
1576
- return new CssColorParser(this.r, this.g, this.b, this.a);
1577
- };
1578
- /**
1579
- * @description: 比较两个解析对象的数据是否相等
1580
- * @param {string} color
1581
- * @return {boolean}
1582
- */
1583
- CssColorParser.prototype.equals = function (color) {
1584
- if (this === color) {
1585
- return true;
1586
- }
1587
- else {
1588
- var json1 = this.toJson();
1589
- var json2 = color.toJson();
1590
- return (json1.r === json2.r &&
1591
- json1.g === json2.g &&
1592
- json1.b === json2.g &&
1593
- json1.a === json2.a);
1594
- }
1595
- };
1596
- /**
1597
- * @description: 反色
1598
- * @return {CssColorParser}
1599
- */
1600
- CssColorParser.prototype.setInvert = function () {
1601
- this.r = 255 - this.r;
1602
- this.g = 255 - this.g;
1603
- this.b = 255 - this.b;
1604
- this.a = 1 - this.a;
1605
- return this;
1606
- };
1607
- /**
1608
- * @description: 乘以倍数
1609
- * @param {number} scalar
1610
- * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1611
- * @return {CssColorParser}
1612
- */
1613
- CssColorParser.prototype.multiplyByScalar = function (scalar, isSetAlpha) {
1614
- if (isSetAlpha === void 0) { isSetAlpha = true; }
1615
- var r = this.r * scalar;
1616
- var g = this.g * scalar;
1617
- var b = this.b * scalar;
1618
- var a = isSetAlpha ? this.a * scalar : this.a;
1619
- return this.setColor(r, g, b, a);
1620
- };
1621
- /**
1622
- * @description: 除以倍数
1623
- * @param {number} scalar
1624
- * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1625
- * @return {CssColorParser}
1626
- */
1627
- CssColorParser.prototype.divideByScalar = function (scalar, isSetAlpha) {
1628
- if (isSetAlpha === void 0) { isSetAlpha = true; }
1629
- var r = this.r / scalar;
1630
- var g = this.g / scalar;
1631
- var b = this.b / scalar;
1632
- var a = isSetAlpha ? this.a / scalar : this.a;
1633
- return this.setColor(r, g, b, a);
1634
- };
1635
- /**
1636
- * @description: 实例相加
1637
- * @param {CssColorParser} colorParser
1638
- * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1639
- * @return {CssColorParser}
1640
- */
1641
- CssColorParser.prototype.add = function (colorParser, isSetAlpha) {
1642
- if (isSetAlpha === void 0) { isSetAlpha = true; }
1643
- var r = this.r + colorParser.r;
1644
- var g = this.g + colorParser.g;
1645
- var b = this.b + colorParser.b;
1646
- var a = isSetAlpha ? this.a + colorParser.a : this.a;
1647
- return this.setColor(r, g, b, a);
1648
- };
1649
- /**
1650
- * @description: 实例相减
1651
- * @param {CssColorParser} colorParser
1652
- * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1653
- * @return {CssColorParser}
1654
- */
1655
- CssColorParser.prototype.subtract = function (colorParser, isSetAlpha) {
1656
- if (isSetAlpha === void 0) { isSetAlpha = true; }
1657
- var r = this.r - colorParser.r;
1658
- var g = this.g - colorParser.g;
1659
- var b = this.b - colorParser.b;
1660
- var a = isSetAlpha ? this.a - colorParser.a : this.a;
1661
- return this.setColor(r, g, b, a);
1662
- };
1663
- /**
1664
- * @description: 实例相乘
1665
- * @param {CssColorParser} colorParser
1666
- * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1667
- * @return {CssColorParser}
1668
- */
1669
- CssColorParser.prototype.multiply = function (colorParser, isSetAlpha) {
1670
- if (isSetAlpha === void 0) { isSetAlpha = true; }
1671
- var r = this.r * colorParser.r;
1672
- var g = this.g * colorParser.g;
1673
- var b = this.b * colorParser.b;
1674
- var a = isSetAlpha ? this.a * colorParser.a : this.a;
1675
- return this.setColor(r, g, b, a);
1676
- };
1677
- /**
1678
- * @description: 实例相除
1679
- * @param {CssColorParser} colorParser
1680
- * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1681
- * @return {CssColorParser}
1682
- */
1683
- CssColorParser.prototype.divide = function (colorParser, isSetAlpha) {
1684
- if (isSetAlpha === void 0) { isSetAlpha = true; }
1685
- var r = this.r / colorParser.r;
1686
- var g = this.g / colorParser.g;
1687
- var b = this.b / colorParser.b;
1688
- var a = isSetAlpha ? this.a / colorParser.a : this.a;
1689
- return this.setColor(r, g, b, a);
1690
- };
1691
- /**
1692
- * @description: 颜色RGB加上数字
1693
- * @param {number} num
1694
- * @return {CssColorParser}
1695
- */
1696
- CssColorParser.prototype.addNumberForRGB = function (num) {
1697
- this.r = this.r + num;
1698
- this.g = this.g + num;
1699
- this.b = this.b + num;
1700
- return this;
1701
- };
1702
- /**
1703
- * @description: 透明度加上数字
1704
- * @param {number} num
1705
- * @return {CssColorParser}
1706
- */
1707
- CssColorParser.prototype.addNumberForAlpha = function (num) {
1708
- this.a = this.a + num;
1709
- return this;
1710
- };
1711
- /**
1712
- * @description: 解析16进制颜色
1713
- * @param {string} v
1714
- * @return {CssColorParser}
1715
- * @example: CssColorParser.parseHEX('#FFF')
1716
- */
1717
- CssColorParser.parseHEX = function (v) {
1718
- var cssStr = CssColorStringParser.clearStrSpace(v);
1719
- var res = CssColorStringParser.parse3BitsHEX(cssStr);
1720
- if (!res) {
1721
- res = CssColorStringParser.parse6BitsHEX(cssStr);
1722
- }
1723
- return res && CssColorParser.fromArray(res);
1724
- };
1725
- /**
1726
- * @description: 解析rgba、rgb颜色
1727
- * @param {string} v
1728
- * @return {CssColorParser}
1729
- * @example: CssColorParser.parseRGBA('rgba(255,255,255,1)')
1730
- */
1731
- CssColorParser.parseRGBA = function (v) {
1732
- var cssStr = CssColorStringParser.clearStrSpace(v);
1733
- var res = CssColorStringParser.parseRGBA(cssStr);
1734
- if (!res) {
1735
- var cssStr2 = CssColorStringParser.trimStr(v);
1736
- res = CssColorStringParser.parseRGBA2(cssStr2);
1737
- }
1738
- return res && CssColorParser.fromArray(res);
1739
- };
1740
- /**
1741
- * @description: 将ColorJson格式的json数据转换为解析对象
1742
- * @param {ColorJson} json
1743
- * @return {CssColorParser}
1744
- * @example: CssColorParser.fromJson({r: 255, g: 255, b: 255, a: 1})
1745
- */
1746
- CssColorParser.fromJson = function (json) {
1747
- return new CssColorParser(json.r, json.g, json.b, json.a);
1748
- };
1749
- /**
1750
- * @description: 将RGBA数组转换为解析对象
1751
- * @param {Array} color
1752
- * @return {CssColorParser}
1753
- * @example: CssColorParser.fromArray([255,255,255,1])
1754
- */
1755
- CssColorParser.fromArray = function (color) {
1756
- return new CssColorParser(color[0], color[1], color[2], color[3]);
1757
- };
1758
- /**
1759
- * @description: 产生随机颜色
1760
- * @return {CssColorParser}
1761
- * @example: CssColorParser.fromRandom(new CssColorParser(0,0,0,0), new CssColorParser(255,255,255,1))
1762
- */
1763
- CssColorParser.fromRandom = function (color1, color2) {
1764
- var r = Math.random() * Math.abs(color2.r - color1.r) +
1765
- Math.min(color1.r, color2.r);
1766
- var g = Math.random() * Math.abs(color2.g - color1.g) +
1767
- Math.min(color1.g, color2.g);
1768
- var b = Math.random() * Math.abs(color2.b - color1.b) +
1769
- Math.min(color1.b, color2.b);
1770
- var a = Math.random() * Math.abs(color2.a - color1.a) +
1771
- Math.min(color1.a, color2.a);
1772
- return new CssColorParser(r, g, b, a);
1773
- };
1774
- /**
1775
- * @description: 颜色序列化数组转换为CssColorParser对象实例
1776
- * @param {array} colorArr
1777
- * @example: CssColorParser.fromNormaliz([1, 0, 0, 1])
1778
- */
1779
- CssColorParser.fromNormalize = function (colorArr) {
1780
- var r = colorArr[0] * 255;
1781
- var g = colorArr[1] * 255;
1782
- var b = colorArr[2] * 255;
1783
- var a = colorArr[3];
1784
- return CssColorParser.fromArray([r, g, b, a]);
1785
- };
1786
- return CssColorParser;
1787
- }());
1788
- /* harmony default export */ var src_CssColorParser = (CssColorParser);
1789
-
1790
- ;// CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.js
1791
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1792
- /******************************************************************************
1793
- Copyright (c) Microsoft Corporation.
1794
-
1795
- Permission to use, copy, modify, and/or distribute this software for any
1796
- purpose with or without fee is hereby granted.
1797
-
1798
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1799
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1800
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1801
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1802
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1803
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1804
- PERFORMANCE OF THIS SOFTWARE.
1805
- ***************************************************************************** */
1806
- /* global Reflect, Promise */
1807
-
1808
- var _extendStatics = function extendStatics(d, b) {
1809
- _extendStatics = Object.setPrototypeOf || {
1810
- __proto__: []
1811
- } instanceof Array && function (d, b) {
1812
- d.__proto__ = b;
1813
- } || function (d, b) {
1814
- for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
1815
- };
1816
- return _extendStatics(d, b);
1817
- };
1818
- function __extends(d, b) {
1819
- if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1820
- _extendStatics(d, b);
1821
- function __() {
1822
- this.constructor = d;
1823
- }
1824
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1825
- }
1826
- var _assign = function __assign() {
1827
- _assign = Object.assign || function __assign(t) {
1828
- for (var s, i = 1, n = arguments.length; i < n; i++) {
1829
- s = arguments[i];
1830
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1831
- }
1832
- return t;
1833
- };
1834
- return _assign.apply(this, arguments);
1835
- };
1836
-
1837
- function __rest(s, e) {
1838
- var t = {};
1839
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
1840
- if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
1841
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
1842
- }
1843
- return t;
1844
- }
1845
- function __decorate(decorators, target, key, desc) {
1846
- var c = arguments.length,
1847
- r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
1848
- d;
1849
- if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1850
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1851
- }
1852
- function __param(paramIndex, decorator) {
1853
- return function (target, key) {
1854
- decorator(target, key, paramIndex);
1855
- };
1856
- }
1857
- function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
1858
- function accept(f) {
1859
- if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
1860
- return f;
1861
- }
1862
- var kind = contextIn.kind,
1863
- key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
1864
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
1865
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
1866
- var _,
1867
- done = false;
1868
- for (var i = decorators.length - 1; i >= 0; i--) {
1869
- var context = {};
1870
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
1871
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
1872
- context.addInitializer = function (f) {
1873
- if (done) throw new TypeError("Cannot add initializers after decoration has completed");
1874
- extraInitializers.push(accept(f || null));
1875
- };
1876
- var result = (0, decorators[i])(kind === "accessor" ? {
1877
- get: descriptor.get,
1878
- set: descriptor.set
1879
- } : descriptor[key], context);
1880
- if (kind === "accessor") {
1881
- if (result === void 0) continue;
1882
- if (result === null || _typeof(result) !== "object") throw new TypeError("Object expected");
1883
- if (_ = accept(result.get)) descriptor.get = _;
1884
- if (_ = accept(result.set)) descriptor.set = _;
1885
- if (_ = accept(result.init)) initializers.unshift(_);
1886
- } else if (_ = accept(result)) {
1887
- if (kind === "field") initializers.unshift(_);else descriptor[key] = _;
1888
- }
1889
- }
1890
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
1891
- done = true;
1892
- }
1893
- ;
1894
- function __runInitializers(thisArg, initializers, value) {
1895
- var useValue = arguments.length > 2;
1896
- for (var i = 0; i < initializers.length; i++) {
1897
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
1898
- }
1899
- return useValue ? value : void 0;
1900
- }
1901
- ;
1902
- function __propKey(x) {
1903
- return _typeof(x) === "symbol" ? x : "".concat(x);
1904
- }
1905
- ;
1906
- function __setFunctionName(f, name, prefix) {
1907
- if (_typeof(name) === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
1908
- return Object.defineProperty(f, "name", {
1909
- configurable: true,
1910
- value: prefix ? "".concat(prefix, " ", name) : name
1911
- });
1912
- }
1913
- ;
1914
- function __metadata(metadataKey, metadataValue) {
1915
- if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
1916
- }
1917
- function __awaiter(thisArg, _arguments, P, generator) {
1918
- function adopt(value) {
1919
- return value instanceof P ? value : new P(function (resolve) {
1920
- resolve(value);
1921
- });
1922
- }
1923
- return new (P || (P = Promise))(function (resolve, reject) {
1924
- function fulfilled(value) {
1925
- try {
1926
- step(generator.next(value));
1927
- } catch (e) {
1928
- reject(e);
1929
- }
1930
- }
1931
- function rejected(value) {
1932
- try {
1933
- step(generator["throw"](value));
1934
- } catch (e) {
1935
- reject(e);
1936
- }
1937
- }
1938
- function step(result) {
1939
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1940
- }
1941
- step((generator = generator.apply(thisArg, _arguments || [])).next());
1942
- });
1943
- }
1944
- function __generator(thisArg, body) {
1945
- var _ = {
1946
- label: 0,
1947
- sent: function sent() {
1948
- if (t[0] & 1) throw t[1];
1949
- return t[1];
1950
- },
1951
- trys: [],
1952
- ops: []
1953
- },
1954
- f,
1955
- y,
1956
- t,
1957
- g;
1958
- return g = {
1959
- next: verb(0),
1960
- "throw": verb(1),
1961
- "return": verb(2)
1962
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
1963
- return this;
1964
- }), g;
1965
- function verb(n) {
1966
- return function (v) {
1967
- return step([n, v]);
1968
- };
1969
- }
1970
- function step(op) {
1971
- if (f) throw new TypeError("Generator is already executing.");
1972
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
1973
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1974
- if (y = 0, t) op = [op[0] & 2, t.value];
1975
- switch (op[0]) {
1976
- case 0:
1977
- case 1:
1978
- t = op;
1979
- break;
1980
- case 4:
1981
- _.label++;
1982
- return {
1983
- value: op[1],
1984
- done: false
1985
- };
1986
- case 5:
1987
- _.label++;
1988
- y = op[1];
1989
- op = [0];
1990
- continue;
1991
- case 7:
1992
- op = _.ops.pop();
1993
- _.trys.pop();
1994
- continue;
1995
- default:
1996
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1997
- _ = 0;
1998
- continue;
1999
- }
2000
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
2001
- _.label = op[1];
2002
- break;
2003
- }
2004
- if (op[0] === 6 && _.label < t[1]) {
2005
- _.label = t[1];
2006
- t = op;
2007
- break;
2008
- }
2009
- if (t && _.label < t[2]) {
2010
- _.label = t[2];
2011
- _.ops.push(op);
2012
- break;
2013
- }
2014
- if (t[2]) _.ops.pop();
2015
- _.trys.pop();
2016
- continue;
2017
- }
2018
- op = body.call(thisArg, _);
2019
- } catch (e) {
2020
- op = [6, e];
2021
- y = 0;
2022
- } finally {
2023
- f = t = 0;
2024
- }
2025
- if (op[0] & 5) throw op[1];
2026
- return {
2027
- value: op[0] ? op[1] : void 0,
2028
- done: true
2029
- };
2030
- }
2031
- }
2032
- var __createBinding = Object.create ? function (o, m, k, k2) {
2033
- if (k2 === undefined) k2 = k;
2034
- var desc = Object.getOwnPropertyDescriptor(m, k);
2035
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
2036
- desc = {
2037
- enumerable: true,
2038
- get: function get() {
2039
- return m[k];
2040
- }
2041
- };
2042
- }
2043
- Object.defineProperty(o, k2, desc);
2044
- } : function (o, m, k, k2) {
2045
- if (k2 === undefined) k2 = k;
2046
- o[k2] = m[k];
2047
- };
2048
- function __exportStar(m, o) {
2049
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
2050
- }
2051
- function __values(o) {
2052
- var s = typeof Symbol === "function" && Symbol.iterator,
2053
- m = s && o[s],
2054
- i = 0;
2055
- if (m) return m.call(o);
2056
- if (o && typeof o.length === "number") return {
2057
- next: function next() {
2058
- if (o && i >= o.length) o = void 0;
2059
- return {
2060
- value: o && o[i++],
2061
- done: !o
2062
- };
2063
- }
2064
- };
2065
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
2066
- }
2067
- function __read(o, n) {
2068
- var m = typeof Symbol === "function" && o[Symbol.iterator];
2069
- if (!m) return o;
2070
- var i = m.call(o),
2071
- r,
2072
- ar = [],
2073
- e;
2074
- try {
2075
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
2076
- } catch (error) {
2077
- e = {
2078
- error: error
2079
- };
2080
- } finally {
2081
- try {
2082
- if (r && !r.done && (m = i["return"])) m.call(i);
2083
- } finally {
2084
- if (e) throw e.error;
2085
- }
2086
- }
2087
- return ar;
2088
- }
2089
-
2090
- /** @deprecated */
2091
- function __spread() {
2092
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
2093
- return ar;
2094
- }
2095
-
2096
- /** @deprecated */
2097
- function __spreadArrays() {
2098
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
2099
- for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
2100
- return r;
2101
- }
2102
- function __spreadArray(to, from, pack) {
2103
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
2104
- if (ar || !(i in from)) {
2105
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
2106
- ar[i] = from[i];
2107
- }
2108
- }
2109
- return to.concat(ar || Array.prototype.slice.call(from));
2110
- }
2111
- function __await(v) {
2112
- return this instanceof __await ? (this.v = v, this) : new __await(v);
2113
- }
2114
- function __asyncGenerator(thisArg, _arguments, generator) {
2115
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
2116
- var g = generator.apply(thisArg, _arguments || []),
2117
- i,
2118
- q = [];
2119
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
2120
- return this;
2121
- }, i;
2122
- function verb(n) {
2123
- if (g[n]) i[n] = function (v) {
2124
- return new Promise(function (a, b) {
2125
- q.push([n, v, a, b]) > 1 || resume(n, v);
2126
- });
2127
- };
2128
- }
2129
- function resume(n, v) {
2130
- try {
2131
- step(g[n](v));
2132
- } catch (e) {
2133
- settle(q[0][3], e);
2134
- }
2135
- }
2136
- function step(r) {
2137
- r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
2138
- }
2139
- function fulfill(value) {
2140
- resume("next", value);
2141
- }
2142
- function reject(value) {
2143
- resume("throw", value);
2144
- }
2145
- function settle(f, v) {
2146
- if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
2147
- }
2148
- }
2149
- function __asyncDelegator(o) {
2150
- var i, p;
2151
- return i = {}, verb("next"), verb("throw", function (e) {
2152
- throw e;
2153
- }), verb("return"), i[Symbol.iterator] = function () {
2154
- return this;
2155
- }, i;
2156
- function verb(n, f) {
2157
- i[n] = o[n] ? function (v) {
2158
- return (p = !p) ? {
2159
- value: __await(o[n](v)),
2160
- done: false
2161
- } : f ? f(v) : v;
2162
- } : f;
2163
- }
2164
- }
2165
- function __asyncValues(o) {
2166
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
2167
- var m = o[Symbol.asyncIterator],
2168
- i;
2169
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
2170
- return this;
2171
- }, i);
2172
- function verb(n) {
2173
- i[n] = o[n] && function (v) {
2174
- return new Promise(function (resolve, reject) {
2175
- v = o[n](v), settle(resolve, reject, v.done, v.value);
2176
- });
2177
- };
2178
- }
2179
- function settle(resolve, reject, d, v) {
2180
- Promise.resolve(v).then(function (v) {
2181
- resolve({
2182
- value: v,
2183
- done: d
2184
- });
2185
- }, reject);
2186
- }
2187
- }
2188
- function __makeTemplateObject(cooked, raw) {
2189
- if (Object.defineProperty) {
2190
- Object.defineProperty(cooked, "raw", {
2191
- value: raw
2192
- });
2193
- } else {
2194
- cooked.raw = raw;
2195
- }
2196
- return cooked;
2197
- }
2198
- ;
2199
- var __setModuleDefault = Object.create ? function (o, v) {
2200
- Object.defineProperty(o, "default", {
2201
- enumerable: true,
2202
- value: v
2203
- });
2204
- } : function (o, v) {
2205
- o["default"] = v;
2206
- };
2207
- function __importStar(mod) {
2208
- if (mod && mod.__esModule) return mod;
2209
- var result = {};
2210
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
2211
- __setModuleDefault(result, mod);
2212
- return result;
2213
- }
2214
- function __importDefault(mod) {
2215
- return mod && mod.__esModule ? mod : {
2216
- "default": mod
2217
- };
2218
- }
2219
- function __classPrivateFieldGet(receiver, state, kind, f) {
2220
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
2221
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
2222
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
2223
- }
2224
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
2225
- if (kind === "m") throw new TypeError("Private method is not writable");
2226
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
2227
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
2228
- return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
2229
- }
2230
- function __classPrivateFieldIn(state, receiver) {
2231
- if (receiver === null || _typeof(receiver) !== "object" && typeof receiver !== "function") throw new TypeError("Cannot use 'in' operator on non-object");
2232
- return typeof state === "function" ? receiver === state : state.has(receiver);
2233
- }
2234
- /* harmony default export */ var tslib_es6 = ({
2235
- __extends: __extends,
2236
- __assign: _assign,
2237
- __rest: __rest,
2238
- __decorate: __decorate,
2239
- __param: __param,
2240
- __metadata: __metadata,
2241
- __awaiter: __awaiter,
2242
- __generator: __generator,
2243
- __createBinding: __createBinding,
2244
- __exportStar: __exportStar,
2245
- __values: __values,
2246
- __read: __read,
2247
- __spread: __spread,
2248
- __spreadArrays: __spreadArrays,
2249
- __spreadArray: __spreadArray,
2250
- __await: __await,
2251
- __asyncGenerator: __asyncGenerator,
2252
- __asyncDelegator: __asyncDelegator,
2253
- __asyncValues: __asyncValues,
2254
- __makeTemplateObject: __makeTemplateObject,
2255
- __importStar: __importStar,
2256
- __importDefault: __importDefault,
2257
- __classPrivateFieldGet: __classPrivateFieldGet,
2258
- __classPrivateFieldSet: __classPrivateFieldSet,
2259
- __classPrivateFieldIn: __classPrivateFieldIn
2260
- });
2261
- // EXTERNAL MODULE: ./node_modules/color-convert/index.js
2262
- var color_convert = __webpack_require__(907);
2263
- var color_convert_default = /*#__PURE__*/__webpack_require__.n(color_convert);
2264
- ;// CONCATENATED MODULE: ./src/CssColorParserPlus.ts
2265
- /*
2266
- * @Descripttion: 颜色解析器(增强)
2267
- * @version: 1.0.0
2268
- * @Author: roman_123
2269
- * @Date: 2021-01-19 09:22:11
2270
- * @LastEditors: Please set LastEditors
2271
- * @LastEditTime: 2023-06-27 18:53:31
2272
- */
2273
-
2274
-
2275
-
2276
-
2277
-
2278
- var CssColorParserPlus = /** @class */ (function (_super) {
2279
- __extends(CssColorParserPlus, _super);
2280
- function CssColorParserPlus() {
2281
- return _super !== null && _super.apply(this, arguments) || this;
2282
- }
2283
- /**
2284
- * @description: 返回取反色后的新的实例
2285
- * @return {CssColorParserPlus}
2286
- */
2287
- CssColorParserPlus.prototype.toInvert = function () {
2288
- var r = 255 - this.r;
2289
- var g = 255 - this.g;
2290
- var b = 255 - this.b;
2291
- var a = 1 - this.a;
2292
- return new CssColorParserPlus(r, g, b, a);
2293
- };
2294
- /**
2295
- * @description: 拷贝
2296
- * @return {CssColorParserPlus}
2297
- */
2298
- CssColorParserPlus.prototype.clone = function () {
2299
- return new CssColorParserPlus(this.r, this.g, this.b, this.a);
2300
- };
2301
- /**
2302
- * @description: 比较两个解析对象的数据是否相等
2303
- * @param {string} color
2304
- * @return {boolean}
2305
- */
2306
- CssColorParserPlus.prototype.equals = function (color) {
2307
- color = CssColorParserPlus.parseColor(color);
2308
- if (this === color) {
2309
- return true;
2310
- }
2311
- else {
2312
- var json1 = this.toJson();
2313
- var json2 = color.toJson();
2314
- return (json1.r === json2.r &&
2315
- json1.g === json2.g &&
2316
- json1.b === json2.g &&
2317
- json1.a === json2.a);
2318
- }
2319
- };
2320
- /**
2321
- * @description: 实例相加
2322
- * @param {CssColorParser} colorParser
2323
- * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
2324
- * @return {CssColorParser}
2325
- */
2326
- CssColorParserPlus.prototype.add = function (color, isSetAlpha) {
2327
- if (isSetAlpha === void 0) { isSetAlpha = true; }
2328
- var colorParser = CssColorParserPlus.parseColor(color);
2329
- return _super.prototype.add.call(this, colorParser, isSetAlpha);
2330
- };
2331
- /**
2332
- * @description: 实例相减
2333
- * @param {CssColorParser} colorParser
2334
- * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
2335
- * @return {CssColorParser}
2336
- */
2337
- CssColorParserPlus.prototype.subtract = function (color, isSetAlpha) {
2338
- if (isSetAlpha === void 0) { isSetAlpha = true; }
2339
- var colorParser = CssColorParserPlus.parseColor(color);
2340
- return _super.prototype.subtract.call(this, colorParser, isSetAlpha);
2341
- };
2342
- /**
2343
- * @description: 实例相乘
2344
- * @param {CssColorParser} colorParser
2345
- * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
2346
- * @return {CssColorParser}
2347
- */
2348
- CssColorParserPlus.prototype.multiply = function (color, isSetAlpha) {
2349
- if (isSetAlpha === void 0) { isSetAlpha = true; }
2350
- var colorParser = CssColorParserPlus.parseColor(color);
2351
- return _super.prototype.multiply.call(this, colorParser, isSetAlpha);
2352
- };
2353
- /**
2354
- * @description: 实例相除
2355
- * @param {CssColorParser} colorParser
2356
- * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
2357
- * @return {CssColorParser}
2358
- */
2359
- CssColorParserPlus.prototype.divide = function (color, isSetAlpha) {
2360
- if (isSetAlpha === void 0) { isSetAlpha = true; }
2361
- var colorParser = CssColorParserPlus.parseColor(color);
2362
- return _super.prototype.divide.call(this, colorParser, isSetAlpha);
2363
- };
2364
- /**
2365
- * @description: 解析css颜色
2366
- * @param {string} v
2367
- * @return {CssColorParserPlus}
2368
- * @example: parseCssColorStr('rgba(255,255,255,1)')
2369
- */
2370
- CssColorParserPlus.parseColor = function (v) {
2371
- if (v instanceof src_CssColorParser) {
2372
- return v;
2373
- }
2374
- return CssColorParserPlus.parseCssColorStr(v);
2375
- };
2376
- /**
2377
- * @description: 将css字符串转换为解析对象
2378
- * @param {string} v
2379
- * @return {CssColorParserPlus}
2380
- * @example: parseCssColorStr('rgba(255,255,255,1)')
2381
- */
2382
- CssColorParserPlus.parseCssColorStr = function (v) {
2383
- Check.type('color', v, 'string');
2384
- return (CssColorParserPlus.parseHEX(v) ||
2385
- CssColorParserPlus.parseRGBA(v) ||
2386
- CssColorParserPlus.parseKeyWord(v) ||
2387
- CssColorParserPlus.parseHSLA(v) ||
2388
- CssColorParserPlus.parseHWB(v));
2389
- };
2390
- /**
2391
- * @description: 解析颜色关键字
2392
- * @param {string} v
2393
- * @return {CssColorParserPlus}
2394
- * @example: parseKeyWord('red')
2395
- */
2396
- CssColorParserPlus.parseKeyWord = function (v) {
2397
- var cssStr = CssColorStringParser.clearStrSpace(v);
2398
- var res = color_convert_default().keyword.rgb(cssStr);
2399
- return res && CssColorParserPlus.fromArray(res);
2400
- };
2401
- /**
2402
- * @description: 解析HSLA
2403
- * @param {string} v
2404
- * @return {CssColorParserPlus}
2405
- * @example: parseHSLA('hsla(215,85%,62%,0.8)')
2406
- */
2407
- CssColorParserPlus.parseHSLA = function (v) {
2408
- var cssStr = CssColorStringParser.clearStrSpace(v);
2409
- var res = CssColorStringParser.parseHSLA(cssStr);
2410
- if (!res) {
2411
- var cssStr2 = CssColorStringParser.trimStr(v);
2412
- res = CssColorStringParser.parseHSLA2(cssStr2);
2413
- }
2414
- return res && CssColorParserPlus.fromHSL(res[0], res[1], res[2], res[3]);
2415
- };
2416
- /**
2417
- * @description: 解析HWB
2418
- * @param {string} v
2419
- * @return {CssColorParserPlus}
2420
- * @example: parseHWB('hwb(215deg 30% 6% / 80%)')
2421
- */
2422
- CssColorParserPlus.parseHWB = function (v) {
2423
- var cssStr2 = CssColorStringParser.trimStr(v);
2424
- var res = CssColorStringParser.parseHWB(cssStr2);
2425
- return res && CssColorParserPlus.fromHWB(res[0], res[1], res[2], res[3]);
2426
- };
2427
- /**
2428
- * @description: 将HSL色彩模式转换为解析对象
2429
- * @param {number} hue 色相
2430
- * @param {number} saturation 饱和度
2431
- * @param {number} lightness 亮度
2432
- * @param {number} alpha 不透明度
2433
- * @return {CssColorParserPlus}
2434
- * @example: fromHSL(0,1,1,1)
2435
- */
2436
- CssColorParserPlus.fromHSL = function (h, s, l, a) {
2437
- var res = color_convert_default().hsl.rgb(limitNumber(0, 360, h), limitNumber(0, 100, s * 100), limitNumber(0, 100, l * 100));
2438
- return new CssColorParserPlus(res[0], res[1], res[2], defaultValue(Number(a), 1));
2439
- };
2440
- /**
2441
- * @description: 将HWB色彩模式转换为解析对象
2442
- * @param {number} h 色调
2443
- * @param {number} w 白度
2444
- * @param {number} b 黑度
2445
- * @param {number} a 不透明度
2446
- * @return {CssColorParserPlus}
2447
- * @example: fromHSL(0,1,1,1)
2448
- */
2449
- CssColorParserPlus.fromHWB = function (h, w, b, a) {
2450
- var res = color_convert_default().hwb.rgb(limitNumber(0, 360, h), limitNumber(0, 100, w * 100), limitNumber(0, 100, b * 100));
2451
- return new CssColorParserPlus(res[0], res[1], res[2], defaultValue(Number(a), 1));
2452
- };
2453
- /**
2454
- * @description: 解析16进制颜色
2455
- * @param {string} v
2456
- * @return {CssColorParserPlus}
2457
- * @example: CssColorParserPlus.parseHEX('#FFF')
2458
- */
2459
- CssColorParserPlus.parseHEX = function (v) {
2460
- var cssStr = CssColorStringParser.clearStrSpace(v);
2461
- var res = CssColorStringParser.parse3BitsHEX(cssStr);
2462
- if (!res) {
2463
- res = CssColorStringParser.parse6BitsHEX(cssStr);
2464
- }
2465
- return res && CssColorParserPlus.fromArray(res);
2466
- };
2467
- /**
2468
- * @description: 解析rgba、rgb颜色
2469
- * @param {string} v
2470
- * @return {CssColorParserPlus}
2471
- * @example: CssColorParserPlus.parseRGBA('rgba(255,255,255,1)')
2472
- */
2473
- CssColorParserPlus.parseRGBA = function (v) {
2474
- var cssStr = CssColorStringParser.clearStrSpace(v);
2475
- var res = CssColorStringParser.parseRGBA(cssStr);
2476
- if (!res) {
2477
- var cssStr2 = CssColorStringParser.trimStr(v);
2478
- res = CssColorStringParser.parseRGBA2(cssStr2);
2479
- }
2480
- return res && CssColorParserPlus.fromArray(res);
2481
- };
2482
- /**
2483
- * @description: 将ColorJson格式的json数据转换为解析对象
2484
- * @param {ColorJson} json
2485
- * @return {CssColorParserPlus}
2486
- * @example: CssColorParserPlus.fromJson({r: 255, g: 255, b: 255, a: 1})
2487
- */
2488
- CssColorParserPlus.fromJson = function (json) {
2489
- return new CssColorParserPlus(json.r, json.g, json.b, json.a);
2490
- };
2491
- /**
2492
- * @description: 将RGBA数组转换为解析对象
2493
- * @param {Array} color
2494
- * @return {CssColorParserPlus}
2495
- * @example: CssColorParserPlus.fromArray([255,255,255,1])
2496
- */
2497
- CssColorParserPlus.fromArray = function (color) {
2498
- return new CssColorParserPlus(color[0], color[1], color[2], color[3]);
2499
- };
2500
- /**
2501
- * @description: 产生随机颜色
2502
- * @return {CssColorParserPlus}
2503
- * @example: CssColorParserPlus.fromRandom('black', new CssColorParserPlus(255,255,255,1))
2504
- */
2505
- CssColorParserPlus.fromRandom = function (color1, color2) {
2506
- color1 = CssColorParserPlus.parseColor(color1);
2507
- color2 = CssColorParserPlus.parseColor(color2);
2508
- var r = Math.random() * Math.abs(color2.r - color1.r) +
2509
- Math.min(color1.r, color2.r);
2510
- var g = Math.random() * Math.abs(color2.g - color1.g) +
2511
- Math.min(color1.g, color2.g);
2512
- var b = Math.random() * Math.abs(color2.b - color1.b) +
2513
- Math.min(color1.b, color2.b);
2514
- var a = Math.random() * Math.abs(color2.a - color1.a) +
2515
- Math.min(color1.a, color2.a);
2516
- return new CssColorParserPlus(r, g, b, a);
2517
- };
2518
- /**
2519
- * @description: 颜色序列化数组转换为CssColorParserPlus对象实例
2520
- * @param {array} colorArr
2521
- * @example: CssColorParserPlus.fromNormaliz([1, 0, 0, 1])
2522
- */
2523
- CssColorParserPlus.fromNormalize = function (colorArr) {
2524
- var r = colorArr[0] * 255;
2525
- var g = colorArr[1] * 255;
2526
- var b = colorArr[2] * 255;
2527
- var a = colorArr[3];
2528
- return CssColorParserPlus.fromArray([r, g, b, a]);
2529
- };
2530
- return CssColorParserPlus;
2531
- }(src_CssColorParser));
2532
- /* harmony default export */ var src_CssColorParserPlus = (CssColorParserPlus);
2533
-
2534
- ;// CONCATENATED MODULE: ./src/main.ts
2535
- /*
2536
- * @Author: roman_123
2537
- * @Description:
2538
- * @Date: 2023-05-25 17:45:22
2539
- * @LastEditTime: 2023-06-27 18:45:32
2540
- */
2541
-
2542
-
2543
-
2544
-
2545
- }();
2546
- var __webpack_export_target__ = exports;
2547
- for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
2548
- if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
2549
- /******/ })()
2550
- ;