css-color-parser-h 3.0.4 → 3.0.6

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.

Potentially problematic release.


This version of css-color-parser-h might be problematic. Click here for more details.

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