css-color-parser-h 3.0.5 → 3.0.10

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.
@@ -95,7 +95,7 @@ export default class CssColorParser {
95
95
  * @description: 返回ColorJson
96
96
  * @return {ColorJson}
97
97
  */
98
- toJson(): ColorJson;
98
+ toJson(isLimit:boolean, colorPrecision?:number, alphaPrecision?:number): ColorJson;
99
99
  /**
100
100
  * @description: 返回取反色后的新的实例
101
101
  * @return {CssColorParser}
@@ -5,6 +5,9 @@ export interface ColorJson {
5
5
  b: number;
6
6
  a: number;
7
7
  }
8
+ export interface ColorLerpOpt {
9
+ [key: number]: string | CssColorParser;
10
+ }
8
11
  export default class CssColorParserPlus extends CssColorParser {
9
12
  /**
10
13
  * @description: 返回取反色后的新的实例
@@ -161,8 +164,8 @@ export default class CssColorParserPlus extends CssColorParser {
161
164
  * @example: CssColorParserPlus.fromRandom('black', new CssColorParserPlus(255,255,255,1))
162
165
  */
163
166
  static fromRandom(
164
- color1: CssColorParserPlus | string,
165
- color2: CssColorParserPlus | string
167
+ color1?: CssColorParserPlus | string,
168
+ color2?: CssColorParserPlus | string
166
169
  ): CssColorParserPlus;
167
170
  /**
168
171
  * @description: 颜色序列化数组转换为CssColorParserPlus对象实例
@@ -172,4 +175,12 @@ export default class CssColorParserPlus extends CssColorParser {
172
175
  static fromNormalize(
173
176
  colorArr: [number, number, number, number]
174
177
  ): CssColorParserPlus;
178
+ /**
179
+ * @description: 获取颜色插值
180
+ * @param opt ColorLerpOpt
181
+ * @param value number
182
+ * @returns {CssColorParserPlus}
183
+ * @example: CssColorParserPlus.lerp({0: "rgba(255, 255, 0, 1)",0.5: "rgba(0, 255, 0, 1)",1: "rgba(255, 0, 0, 1)"}, 0.8)
184
+ */
185
+ static lerp(opt: ColorLerpOpt, value: number): CssColorParserPlus
175
186
  }
package/@types/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- /*
2
- * @Author: roman_123
3
- * @Description:
4
- * @Date: 2023-05-26 13:29:45
5
- * @LastEditTime: 2023-06-27 19:23:00
6
- */
7
- import CssColorParser from "./CssColorParser"
8
- import CssColorParserPlus from "./CssColorParserPlus"
9
-
10
- export { CssColorParser, CssColorParserPlus };
1
+ /*
2
+ * @Author: roman_123
3
+ * @Description:
4
+ * @Date: 2023-05-26 13:29:45
5
+ * @LastEditTime: 2023-06-27 19:23:00
6
+ */
7
+ import CssColorParser from "./CssColorParser"
8
+ import CssColorParserPlus from "./CssColorParserPlus"
9
+
10
+ export { CssColorParser, CssColorParserPlus };
package/example.html CHANGED
@@ -2,7 +2,7 @@
2
2
  * @Author: roman_123
3
3
  * @Description:
4
4
  * @Date: 2022-12-06 11:15:17
5
- * @LastEditTime: 2023-06-27 19:24:53
5
+ * @LastEditTime: 2026-02-25 14:56:54
6
6
  -->
7
7
  <!DOCTYPE html>
8
8
  <html lang="en">
@@ -17,19 +17,37 @@
17
17
  <meta http-equiv="Pragma" content="no-cache" />
18
18
  <meta http-equiv="Expires" content="0" />
19
19
  <title>css-color-parser示例</title>
20
- <script src="./dist/css-color-parser-h.umd.js"></script>
20
+ <script src="./lib/css-color-parser-h.umd.js"></script>
21
21
  </head>
22
22
 
23
23
  <body>
24
24
  <h2>f12 to view console log</h2>
25
25
  <script>
26
- const cssColorParser = new Parser.CssColorParserPlus()
26
+ const cssColorParser = new Parser.CssColorParserPlus(100.2,200.3,200.4,0.88123)
27
27
  console.log(cssColorParser.toHEX())
28
28
  console.log(cssColorParser.toRGBA())
29
29
  cssColorParser.add('#333').add('red')
30
- console.log(cssColorParser.toRGBA())
30
+ console.log(cssColorParser)
31
31
  cssColorParser.subtract('blue', false)
32
32
  console.log(cssColorParser.toRGBA())
33
+ const lerpedColor = Parser.CssColorParserPlus.lerp({
34
+ 0: Parser.CssColorParserPlus.parseColor('rgba(255, 255, 0, 1)'),
35
+ 0.5: Parser.CssColorParserPlus.parseColor('rgba(0, 255, 0, 1)'),
36
+ 1: Parser.CssColorParserPlus.parseColor('rgba(255, 0, 0, 1)')
37
+ }, 0.4)
38
+ console.log(lerpedColor)
39
+ const lerpedColor2 = Parser.CssColorParserPlus.lerp({
40
+ 0: Parser.CssColorParserPlus.parseColor('rgba(255, 255, 0, 1)'),
41
+ 0.5: Parser.CssColorParserPlus.parseColor('rgba(0, 255, 0, 1)'),
42
+ 1: Parser.CssColorParserPlus.parseColor('rgba(255, 0, 0, 1)')
43
+ }, 0.4)
44
+ console.log(lerpedColor2)
45
+ const lerpedColor3 = Parser.CssColorParserPlus.lerp({
46
+ 0: Parser.CssColorParserPlus.parseColor('rgba(255, 255, 0, 1)'),
47
+ 0.5: Parser.CssColorParserPlus.parseColor('rgba(0, 255, 0, 1)'),
48
+ 1: Parser.CssColorParserPlus.parseColor('rgba(255, 0, 0, 1)')
49
+ }, 0.4)
50
+ console.log(lerpedColor3)
33
51
  </script>
34
52
  </body>
35
53
  </html>
@@ -211,8 +211,8 @@ var CssColorStringParser = /** @class */ (function () {
211
211
  * @version: 1.0.0
212
212
  * @Author: roman_123
213
213
  * @Date: 2021-01-19 09:22:11
214
- * @LastEditors: Please set LastEditors
215
- * @LastEditTime: 2023-06-27 19:01:50
214
+ * @LastEditors: zhangyu 306863030@qq.com
215
+ * @LastEditTime: 2026-02-25 14:59:49
216
216
  */
217
217
  var CssColorParser = /** @class */ (function () {
218
218
  function CssColorParser(red, green, blue, alpha) {
@@ -249,13 +249,29 @@ var CssColorParser = /** @class */ (function () {
249
249
  * @param alpha
250
250
  * @example: this.setColor(255,255,255,1)
251
251
  */
252
- CssColorParser.prototype.setColor = function (red, green, blue, alpha) {
253
- this.r = limitNumber(0, 255, defaultValue(Number(red), 0));
254
- this.g = limitNumber(0, 255, defaultValue(Number(green), 0));
255
- this.b = limitNumber(0, 255, defaultValue(Number(blue), 0));
256
- this.a = limitNumber(0, 1, defaultValue(Number(alpha), 1));
252
+ CssColorParser.prototype.setColor = function (red, green, blue, alpha, isLimit) {
253
+ if (isLimit === void 0) { isLimit = true; }
254
+ if (isLimit) {
255
+ this.r = limitNumber(0, 255, defaultValue(Number(red), 0));
256
+ this.g = limitNumber(0, 255, defaultValue(Number(green), 0));
257
+ this.b = limitNumber(0, 255, defaultValue(Number(blue), 0));
258
+ this.a = limitNumber(0, 1, defaultValue(Number(alpha), 1));
259
+ }
260
+ else {
261
+ this.r = defaultValue(Number(red), 0);
262
+ this.g = defaultValue(Number(green), 0);
263
+ this.b = defaultValue(Number(blue), 0);
264
+ this.a = defaultValue(Number(alpha), 1);
265
+ }
257
266
  return this;
258
267
  };
268
+ /**
269
+ * 设置颜色到范围内
270
+ * @example: this.limitColor()
271
+ */
272
+ CssColorParser.prototype.limitColor = function () {
273
+ return this.setColor(this.r, this.g, this.b, this.a, true);
274
+ };
259
275
  /**
260
276
  * @description: 设置透明度
261
277
  * @param {number} alpha
@@ -315,39 +331,36 @@ var CssColorParser = /** @class */ (function () {
315
331
  * @return {array}
316
332
  */
317
333
  CssColorParser.prototype.toNormalize = function () {
318
- var r = setNumberPrecision(this.r / 255, this._outColorPrecision);
319
- var g = setNumberPrecision(this.g / 255, this._outColorPrecision);
320
- var b = setNumberPrecision(this.b / 255, this._outColorPrecision);
321
- var a = setNumberPrecision(this.a, this._outAlphaPrecision);
322
- return [r, g, b, a];
334
+ var _a = this.toJson(), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
335
+ return [r / 255, g / 255, b / 255, a];
323
336
  };
324
337
  /**
325
338
  * @description: 返回16进制格式的css字符串
326
339
  * @return {string}
327
340
  */
328
341
  CssColorParser.prototype.toHEX = function () {
329
- var color = this.toJson();
330
- var r = color.r.toString(16);
331
- if (r.length < 2) {
332
- r = "0".concat(r);
342
+ var _a = this.toJson(true, 0, 0), r = _a.r, g = _a.g, b = _a.b;
343
+ var red = r.toString(16);
344
+ if (red.length < 2) {
345
+ red = "0".concat(red);
333
346
  }
334
- var g = color.g.toString(16);
335
- if (g.length < 2) {
336
- g = "0".concat(g);
347
+ var green = g.toString(16);
348
+ if (green.length < 2) {
349
+ green = "0".concat(green);
337
350
  }
338
- var b = color.b.toString(16);
339
- if (b.length < 2) {
340
- b = "0".concat(b);
351
+ var blue = b.toString(16);
352
+ if (blue.length < 2) {
353
+ blue = "0".concat(blue);
341
354
  }
342
355
  // 由于tojson后a会丢失精度,此处使用this.a
343
356
  if (this.a < 1) {
344
- var hexAlpha = parseInt((this.a * 255).toFixed()).toString(16);
357
+ var hexAlpha = setNumberPrecision(this.a * 255, 0).toString(16);
345
358
  if (hexAlpha.length < 2) {
346
359
  hexAlpha = "0".concat(hexAlpha);
347
360
  }
348
- return "#".concat(r).concat(g).concat(b).concat(hexAlpha);
361
+ return "#".concat(red).concat(green).concat(blue).concat(hexAlpha);
349
362
  }
350
- return "#".concat(r).concat(g).concat(b);
363
+ return "#".concat(red).concat(green).concat(blue);
351
364
  };
352
365
  /**
353
366
  * @description: 返回rgba数组
@@ -361,12 +374,25 @@ var CssColorParser = /** @class */ (function () {
361
374
  * @description: 返回ColorJson
362
375
  * @return {ColorJson}
363
376
  */
364
- CssColorParser.prototype.toJson = function () {
377
+ CssColorParser.prototype.toJson = function (isLimit, colorPrecision, alphaPrecision) {
378
+ if (isLimit === void 0) { isLimit = true; }
379
+ if (colorPrecision === void 0) { colorPrecision = this._outColorPrecision; }
380
+ if (alphaPrecision === void 0) { alphaPrecision = this._outAlphaPrecision; }
381
+ var r = this.r;
382
+ var g = this.g;
383
+ var b = this.b;
384
+ var a = this.a;
385
+ if (isLimit) {
386
+ r = limitNumber(0, 255, this.r);
387
+ g = limitNumber(0, 255, this.g);
388
+ b = limitNumber(0, 255, this.b);
389
+ a = limitNumber(0, 1, this.a);
390
+ }
365
391
  return {
366
- r: setNumberPrecision(this.r, this._outColorPrecision),
367
- g: setNumberPrecision(this.g, this._outColorPrecision),
368
- b: setNumberPrecision(this.b, this._outColorPrecision),
369
- a: setNumberPrecision(this.a, this._outAlphaPrecision),
392
+ r: setNumberPrecision(r, colorPrecision),
393
+ g: setNumberPrecision(g, colorPrecision),
394
+ b: setNumberPrecision(b, colorPrecision),
395
+ a: setNumberPrecision(a, alphaPrecision),
370
396
  };
371
397
  };
372
398
  /**
@@ -374,10 +400,11 @@ var CssColorParser = /** @class */ (function () {
374
400
  * @return {CssColorParser}
375
401
  */
376
402
  CssColorParser.prototype.toInvert = function () {
377
- var r = 255 - this.r;
378
- var g = 255 - this.g;
379
- var b = 255 - this.b;
380
- var a = 1 - this.a;
403
+ var _a = this.toJson(), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
404
+ r = 255 - this.r;
405
+ g = 255 - this.g;
406
+ b = 255 - this.b;
407
+ a = 1 - this.a;
381
408
  return new CssColorParser(r, g, b, a);
382
409
  };
383
410
  /**
@@ -385,7 +412,10 @@ var CssColorParser = /** @class */ (function () {
385
412
  * @return {CssColorParser}
386
413
  */
387
414
  CssColorParser.prototype.clone = function () {
388
- return new CssColorParser(this.r, this.g, this.b, this.a);
415
+ var newParser = new CssColorParser(this.r, this.g, this.b, this.a);
416
+ newParser._outColorPrecision = this._outColorPrecision;
417
+ newParser._outAlphaPrecision = this._outAlphaPrecision;
418
+ return newParser;
389
419
  };
390
420
  /**
391
421
  * @description: 比较两个解析对象的数据是否相等
@@ -410,10 +440,11 @@ var CssColorParser = /** @class */ (function () {
410
440
  * @return {CssColorParser}
411
441
  */
412
442
  CssColorParser.prototype.setInvert = function () {
413
- this.r = 255 - this.r;
414
- this.g = 255 - this.g;
415
- this.b = 255 - this.b;
416
- this.a = 1 - this.a;
443
+ var _a = this.toJson(), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
444
+ this.r = 255 - r;
445
+ this.g = 255 - g;
446
+ this.b = 255 - b;
447
+ this.a = 1 - a;
417
448
  return this;
418
449
  };
419
450
  /**
@@ -428,7 +459,7 @@ var CssColorParser = /** @class */ (function () {
428
459
  var g = this.g * scalar;
429
460
  var b = this.b * scalar;
430
461
  var a = isSetAlpha ? this.a * scalar : this.a;
431
- return this.setColor(r, g, b, a);
462
+ return this.setColor(r, g, b, a, false);
432
463
  };
433
464
  /**
434
465
  * @description: 除以倍数
@@ -442,7 +473,7 @@ var CssColorParser = /** @class */ (function () {
442
473
  var g = this.g / scalar;
443
474
  var b = this.b / scalar;
444
475
  var a = isSetAlpha ? this.a / scalar : this.a;
445
- return this.setColor(r, g, b, a);
476
+ return this.setColor(r, g, b, a, false);
446
477
  };
447
478
  /**
448
479
  * @description: 实例相加
@@ -456,7 +487,7 @@ var CssColorParser = /** @class */ (function () {
456
487
  var g = this.g + colorParser.g;
457
488
  var b = this.b + colorParser.b;
458
489
  var a = isSetAlpha ? this.a + colorParser.a : this.a;
459
- return this.setColor(r, g, b, a);
490
+ return this.setColor(r, g, b, a, false);
460
491
  };
461
492
  /**
462
493
  * @description: 实例相减
@@ -470,7 +501,7 @@ var CssColorParser = /** @class */ (function () {
470
501
  var g = this.g - colorParser.g;
471
502
  var b = this.b - colorParser.b;
472
503
  var a = isSetAlpha ? this.a - colorParser.a : this.a;
473
- return this.setColor(r, g, b, a);
504
+ return this.setColor(r, g, b, a, false);
474
505
  };
475
506
  /**
476
507
  * @description: 实例相乘
@@ -484,7 +515,7 @@ var CssColorParser = /** @class */ (function () {
484
515
  var g = this.g * colorParser.g;
485
516
  var b = this.b * colorParser.b;
486
517
  var a = isSetAlpha ? this.a * colorParser.a : this.a;
487
- return this.setColor(r, g, b, a);
518
+ return this.setColor(r, g, b, a, false);
488
519
  };
489
520
  /**
490
521
  * @description: 实例相除
@@ -498,7 +529,7 @@ var CssColorParser = /** @class */ (function () {
498
529
  var g = this.g / colorParser.g;
499
530
  var b = this.b / colorParser.b;
500
531
  var a = isSetAlpha ? this.a / colorParser.a : this.a;
501
- return this.setColor(r, g, b, a);
532
+ return this.setColor(r, g, b, a, false);
502
533
  };
503
534
  /**
504
535
  * @description: 颜色RGB加上数字
@@ -644,10 +675,11 @@ var CssColorParserPlus = /** @class */ (function (_super) {
644
675
  * @return {CssColorParserPlus}
645
676
  */
646
677
  CssColorParserPlus.prototype.toInvert = function () {
647
- var r = 255 - this.r;
648
- var g = 255 - this.g;
649
- var b = 255 - this.b;
650
- var a = 1 - this.a;
678
+ var _a = this.toJson(), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
679
+ r = 255 - this.r;
680
+ g = 255 - this.g;
681
+ b = 255 - this.b;
682
+ a = 1 - this.a;
651
683
  return new CssColorParserPlus(r, g, b, a);
652
684
  };
653
685
  /**
@@ -655,7 +687,10 @@ var CssColorParserPlus = /** @class */ (function (_super) {
655
687
  * @return {CssColorParserPlus}
656
688
  */
657
689
  CssColorParserPlus.prototype.clone = function () {
658
- return new CssColorParserPlus(this.r, this.g, this.b, this.a);
690
+ var newParser = new CssColorParserPlus(this.r, this.g, this.b, this.a);
691
+ newParser._outColorPrecision = this._outColorPrecision;
692
+ newParser._outAlphaPrecision = this._outAlphaPrecision;
693
+ return newParser;
659
694
  };
660
695
  /**
661
696
  * @description: 比较两个解析对象的数据是否相等
@@ -728,7 +763,7 @@ var CssColorParserPlus = /** @class */ (function (_super) {
728
763
  */
729
764
  CssColorParserPlus.parseColor = function (v) {
730
765
  if (v instanceof CssColorParser) {
731
- return v;
766
+ return v.clone();
732
767
  }
733
768
  return CssColorParserPlus.parseCssColorStr(v);
734
769
  };
@@ -862,6 +897,8 @@ var CssColorParserPlus = /** @class */ (function (_super) {
862
897
  * @example: CssColorParserPlus.fromRandom('black', new CssColorParserPlus(255,255,255,1))
863
898
  */
864
899
  CssColorParserPlus.fromRandom = function (color1, color2) {
900
+ if (color1 === void 0) { color1 = new CssColorParserPlus(0, 0, 0, 1); }
901
+ if (color2 === void 0) { color2 = new CssColorParserPlus(255, 255, 255, 1); }
865
902
  color1 = CssColorParserPlus.parseColor(color1);
866
903
  color2 = CssColorParserPlus.parseColor(color2);
867
904
  var r = Math.random() * Math.abs(color2.r - color1.r) +
@@ -886,6 +923,33 @@ var CssColorParserPlus = /** @class */ (function (_super) {
886
923
  var a = colorArr[3];
887
924
  return CssColorParserPlus.fromArray([r, g, b, a]);
888
925
  };
926
+ /**
927
+ * @description: 获取颜色插值
928
+ * @param opt ColorLerpOpt
929
+ * @param value number
930
+ * @returns {CssColorParserPlus}
931
+ * @example: CssColorParserPlus.lerp({0: "rgba(255, 255, 0, 1)",0.5: "rgba(0, 255, 0, 1)",1: "rgba(255, 0, 0, 1)"}, 0.8)
932
+ */
933
+ CssColorParserPlus.lerp = function (opt, value) {
934
+ var keys = Object.keys(opt).map(function (k) { return Number(k); });
935
+ keys.sort(function (a, b) { return a - b; });
936
+ for (var i = 0; i < keys.length; i++) {
937
+ if (value <= keys[i]) {
938
+ var last = keys[i - 1];
939
+ var next = keys[i];
940
+ if (last === undefined) {
941
+ return CssColorParserPlus.parseColor(opt[next]);
942
+ }
943
+ else {
944
+ var ratio = (value - last) / (next - last);
945
+ var color1 = CssColorParserPlus.parseColor(opt[last]);
946
+ var color2 = CssColorParserPlus.parseColor(opt[next]);
947
+ return color2.subtract(color1).multiplyByScalar(ratio).add(color1);
948
+ }
949
+ }
950
+ }
951
+ return CssColorParserPlus.parseColor(opt[keys[keys.length - 1]]).limitColor();
952
+ };
889
953
  return CssColorParserPlus;
890
954
  }(CssColorParser));
891
955
 
@@ -209,8 +209,8 @@ var CssColorStringParser = /** @class */ (function () {
209
209
  * @version: 1.0.0
210
210
  * @Author: roman_123
211
211
  * @Date: 2021-01-19 09:22:11
212
- * @LastEditors: Please set LastEditors
213
- * @LastEditTime: 2023-06-27 19:01:50
212
+ * @LastEditors: zhangyu 306863030@qq.com
213
+ * @LastEditTime: 2026-02-25 14:59:49
214
214
  */
215
215
  var CssColorParser = /** @class */ (function () {
216
216
  function CssColorParser(red, green, blue, alpha) {
@@ -247,13 +247,29 @@ var CssColorParser = /** @class */ (function () {
247
247
  * @param alpha
248
248
  * @example: this.setColor(255,255,255,1)
249
249
  */
250
- CssColorParser.prototype.setColor = function (red, green, blue, alpha) {
251
- this.r = limitNumber(0, 255, defaultValue(Number(red), 0));
252
- this.g = limitNumber(0, 255, defaultValue(Number(green), 0));
253
- this.b = limitNumber(0, 255, defaultValue(Number(blue), 0));
254
- this.a = limitNumber(0, 1, defaultValue(Number(alpha), 1));
250
+ CssColorParser.prototype.setColor = function (red, green, blue, alpha, isLimit) {
251
+ if (isLimit === void 0) { isLimit = true; }
252
+ if (isLimit) {
253
+ this.r = limitNumber(0, 255, defaultValue(Number(red), 0));
254
+ this.g = limitNumber(0, 255, defaultValue(Number(green), 0));
255
+ this.b = limitNumber(0, 255, defaultValue(Number(blue), 0));
256
+ this.a = limitNumber(0, 1, defaultValue(Number(alpha), 1));
257
+ }
258
+ else {
259
+ this.r = defaultValue(Number(red), 0);
260
+ this.g = defaultValue(Number(green), 0);
261
+ this.b = defaultValue(Number(blue), 0);
262
+ this.a = defaultValue(Number(alpha), 1);
263
+ }
255
264
  return this;
256
265
  };
266
+ /**
267
+ * 设置颜色到范围内
268
+ * @example: this.limitColor()
269
+ */
270
+ CssColorParser.prototype.limitColor = function () {
271
+ return this.setColor(this.r, this.g, this.b, this.a, true);
272
+ };
257
273
  /**
258
274
  * @description: 设置透明度
259
275
  * @param {number} alpha
@@ -313,39 +329,36 @@ var CssColorParser = /** @class */ (function () {
313
329
  * @return {array}
314
330
  */
315
331
  CssColorParser.prototype.toNormalize = function () {
316
- var r = setNumberPrecision(this.r / 255, this._outColorPrecision);
317
- var g = setNumberPrecision(this.g / 255, this._outColorPrecision);
318
- var b = setNumberPrecision(this.b / 255, this._outColorPrecision);
319
- var a = setNumberPrecision(this.a, this._outAlphaPrecision);
320
- return [r, g, b, a];
332
+ var _a = this.toJson(), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
333
+ return [r / 255, g / 255, b / 255, a];
321
334
  };
322
335
  /**
323
336
  * @description: 返回16进制格式的css字符串
324
337
  * @return {string}
325
338
  */
326
339
  CssColorParser.prototype.toHEX = function () {
327
- var color = this.toJson();
328
- var r = color.r.toString(16);
329
- if (r.length < 2) {
330
- r = "0".concat(r);
340
+ var _a = this.toJson(true, 0, 0), r = _a.r, g = _a.g, b = _a.b;
341
+ var red = r.toString(16);
342
+ if (red.length < 2) {
343
+ red = "0".concat(red);
331
344
  }
332
- var g = color.g.toString(16);
333
- if (g.length < 2) {
334
- g = "0".concat(g);
345
+ var green = g.toString(16);
346
+ if (green.length < 2) {
347
+ green = "0".concat(green);
335
348
  }
336
- var b = color.b.toString(16);
337
- if (b.length < 2) {
338
- b = "0".concat(b);
349
+ var blue = b.toString(16);
350
+ if (blue.length < 2) {
351
+ blue = "0".concat(blue);
339
352
  }
340
353
  // 由于tojson后a会丢失精度,此处使用this.a
341
354
  if (this.a < 1) {
342
- var hexAlpha = parseInt((this.a * 255).toFixed()).toString(16);
355
+ var hexAlpha = setNumberPrecision(this.a * 255, 0).toString(16);
343
356
  if (hexAlpha.length < 2) {
344
357
  hexAlpha = "0".concat(hexAlpha);
345
358
  }
346
- return "#".concat(r).concat(g).concat(b).concat(hexAlpha);
359
+ return "#".concat(red).concat(green).concat(blue).concat(hexAlpha);
347
360
  }
348
- return "#".concat(r).concat(g).concat(b);
361
+ return "#".concat(red).concat(green).concat(blue);
349
362
  };
350
363
  /**
351
364
  * @description: 返回rgba数组
@@ -359,12 +372,25 @@ var CssColorParser = /** @class */ (function () {
359
372
  * @description: 返回ColorJson
360
373
  * @return {ColorJson}
361
374
  */
362
- CssColorParser.prototype.toJson = function () {
375
+ CssColorParser.prototype.toJson = function (isLimit, colorPrecision, alphaPrecision) {
376
+ if (isLimit === void 0) { isLimit = true; }
377
+ if (colorPrecision === void 0) { colorPrecision = this._outColorPrecision; }
378
+ if (alphaPrecision === void 0) { alphaPrecision = this._outAlphaPrecision; }
379
+ var r = this.r;
380
+ var g = this.g;
381
+ var b = this.b;
382
+ var a = this.a;
383
+ if (isLimit) {
384
+ r = limitNumber(0, 255, this.r);
385
+ g = limitNumber(0, 255, this.g);
386
+ b = limitNumber(0, 255, this.b);
387
+ a = limitNumber(0, 1, this.a);
388
+ }
363
389
  return {
364
- r: setNumberPrecision(this.r, this._outColorPrecision),
365
- g: setNumberPrecision(this.g, this._outColorPrecision),
366
- b: setNumberPrecision(this.b, this._outColorPrecision),
367
- a: setNumberPrecision(this.a, this._outAlphaPrecision),
390
+ r: setNumberPrecision(r, colorPrecision),
391
+ g: setNumberPrecision(g, colorPrecision),
392
+ b: setNumberPrecision(b, colorPrecision),
393
+ a: setNumberPrecision(a, alphaPrecision),
368
394
  };
369
395
  };
370
396
  /**
@@ -372,10 +398,11 @@ var CssColorParser = /** @class */ (function () {
372
398
  * @return {CssColorParser}
373
399
  */
374
400
  CssColorParser.prototype.toInvert = function () {
375
- var r = 255 - this.r;
376
- var g = 255 - this.g;
377
- var b = 255 - this.b;
378
- var a = 1 - this.a;
401
+ var _a = this.toJson(), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
402
+ r = 255 - this.r;
403
+ g = 255 - this.g;
404
+ b = 255 - this.b;
405
+ a = 1 - this.a;
379
406
  return new CssColorParser(r, g, b, a);
380
407
  };
381
408
  /**
@@ -383,7 +410,10 @@ var CssColorParser = /** @class */ (function () {
383
410
  * @return {CssColorParser}
384
411
  */
385
412
  CssColorParser.prototype.clone = function () {
386
- return new CssColorParser(this.r, this.g, this.b, this.a);
413
+ var newParser = new CssColorParser(this.r, this.g, this.b, this.a);
414
+ newParser._outColorPrecision = this._outColorPrecision;
415
+ newParser._outAlphaPrecision = this._outAlphaPrecision;
416
+ return newParser;
387
417
  };
388
418
  /**
389
419
  * @description: 比较两个解析对象的数据是否相等
@@ -408,10 +438,11 @@ var CssColorParser = /** @class */ (function () {
408
438
  * @return {CssColorParser}
409
439
  */
410
440
  CssColorParser.prototype.setInvert = function () {
411
- this.r = 255 - this.r;
412
- this.g = 255 - this.g;
413
- this.b = 255 - this.b;
414
- this.a = 1 - this.a;
441
+ var _a = this.toJson(), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
442
+ this.r = 255 - r;
443
+ this.g = 255 - g;
444
+ this.b = 255 - b;
445
+ this.a = 1 - a;
415
446
  return this;
416
447
  };
417
448
  /**
@@ -426,7 +457,7 @@ var CssColorParser = /** @class */ (function () {
426
457
  var g = this.g * scalar;
427
458
  var b = this.b * scalar;
428
459
  var a = isSetAlpha ? this.a * scalar : this.a;
429
- return this.setColor(r, g, b, a);
460
+ return this.setColor(r, g, b, a, false);
430
461
  };
431
462
  /**
432
463
  * @description: 除以倍数
@@ -440,7 +471,7 @@ var CssColorParser = /** @class */ (function () {
440
471
  var g = this.g / scalar;
441
472
  var b = this.b / scalar;
442
473
  var a = isSetAlpha ? this.a / scalar : this.a;
443
- return this.setColor(r, g, b, a);
474
+ return this.setColor(r, g, b, a, false);
444
475
  };
445
476
  /**
446
477
  * @description: 实例相加
@@ -454,7 +485,7 @@ var CssColorParser = /** @class */ (function () {
454
485
  var g = this.g + colorParser.g;
455
486
  var b = this.b + colorParser.b;
456
487
  var a = isSetAlpha ? this.a + colorParser.a : this.a;
457
- return this.setColor(r, g, b, a);
488
+ return this.setColor(r, g, b, a, false);
458
489
  };
459
490
  /**
460
491
  * @description: 实例相减
@@ -468,7 +499,7 @@ var CssColorParser = /** @class */ (function () {
468
499
  var g = this.g - colorParser.g;
469
500
  var b = this.b - colorParser.b;
470
501
  var a = isSetAlpha ? this.a - colorParser.a : this.a;
471
- return this.setColor(r, g, b, a);
502
+ return this.setColor(r, g, b, a, false);
472
503
  };
473
504
  /**
474
505
  * @description: 实例相乘
@@ -482,7 +513,7 @@ var CssColorParser = /** @class */ (function () {
482
513
  var g = this.g * colorParser.g;
483
514
  var b = this.b * colorParser.b;
484
515
  var a = isSetAlpha ? this.a * colorParser.a : this.a;
485
- return this.setColor(r, g, b, a);
516
+ return this.setColor(r, g, b, a, false);
486
517
  };
487
518
  /**
488
519
  * @description: 实例相除
@@ -496,7 +527,7 @@ var CssColorParser = /** @class */ (function () {
496
527
  var g = this.g / colorParser.g;
497
528
  var b = this.b / colorParser.b;
498
529
  var a = isSetAlpha ? this.a / colorParser.a : this.a;
499
- return this.setColor(r, g, b, a);
530
+ return this.setColor(r, g, b, a, false);
500
531
  };
501
532
  /**
502
533
  * @description: 颜色RGB加上数字
@@ -642,10 +673,11 @@ var CssColorParserPlus = /** @class */ (function (_super) {
642
673
  * @return {CssColorParserPlus}
643
674
  */
644
675
  CssColorParserPlus.prototype.toInvert = function () {
645
- var r = 255 - this.r;
646
- var g = 255 - this.g;
647
- var b = 255 - this.b;
648
- var a = 1 - this.a;
676
+ var _a = this.toJson(), r = _a.r, g = _a.g, b = _a.b, a = _a.a;
677
+ r = 255 - this.r;
678
+ g = 255 - this.g;
679
+ b = 255 - this.b;
680
+ a = 1 - this.a;
649
681
  return new CssColorParserPlus(r, g, b, a);
650
682
  };
651
683
  /**
@@ -653,7 +685,10 @@ var CssColorParserPlus = /** @class */ (function (_super) {
653
685
  * @return {CssColorParserPlus}
654
686
  */
655
687
  CssColorParserPlus.prototype.clone = function () {
656
- return new CssColorParserPlus(this.r, this.g, this.b, this.a);
688
+ var newParser = new CssColorParserPlus(this.r, this.g, this.b, this.a);
689
+ newParser._outColorPrecision = this._outColorPrecision;
690
+ newParser._outAlphaPrecision = this._outAlphaPrecision;
691
+ return newParser;
657
692
  };
658
693
  /**
659
694
  * @description: 比较两个解析对象的数据是否相等
@@ -726,7 +761,7 @@ var CssColorParserPlus = /** @class */ (function (_super) {
726
761
  */
727
762
  CssColorParserPlus.parseColor = function (v) {
728
763
  if (v instanceof CssColorParser) {
729
- return v;
764
+ return v.clone();
730
765
  }
731
766
  return CssColorParserPlus.parseCssColorStr(v);
732
767
  };
@@ -860,6 +895,8 @@ var CssColorParserPlus = /** @class */ (function (_super) {
860
895
  * @example: CssColorParserPlus.fromRandom('black', new CssColorParserPlus(255,255,255,1))
861
896
  */
862
897
  CssColorParserPlus.fromRandom = function (color1, color2) {
898
+ if (color1 === void 0) { color1 = new CssColorParserPlus(0, 0, 0, 1); }
899
+ if (color2 === void 0) { color2 = new CssColorParserPlus(255, 255, 255, 1); }
863
900
  color1 = CssColorParserPlus.parseColor(color1);
864
901
  color2 = CssColorParserPlus.parseColor(color2);
865
902
  var r = Math.random() * Math.abs(color2.r - color1.r) +
@@ -884,6 +921,33 @@ var CssColorParserPlus = /** @class */ (function (_super) {
884
921
  var a = colorArr[3];
885
922
  return CssColorParserPlus.fromArray([r, g, b, a]);
886
923
  };
924
+ /**
925
+ * @description: 获取颜色插值
926
+ * @param opt ColorLerpOpt
927
+ * @param value number
928
+ * @returns {CssColorParserPlus}
929
+ * @example: CssColorParserPlus.lerp({0: "rgba(255, 255, 0, 1)",0.5: "rgba(0, 255, 0, 1)",1: "rgba(255, 0, 0, 1)"}, 0.8)
930
+ */
931
+ CssColorParserPlus.lerp = function (opt, value) {
932
+ var keys = Object.keys(opt).map(function (k) { return Number(k); });
933
+ keys.sort(function (a, b) { return a - b; });
934
+ for (var i = 0; i < keys.length; i++) {
935
+ if (value <= keys[i]) {
936
+ var last = keys[i - 1];
937
+ var next = keys[i];
938
+ if (last === undefined) {
939
+ return CssColorParserPlus.parseColor(opt[next]);
940
+ }
941
+ else {
942
+ var ratio = (value - last) / (next - last);
943
+ var color1 = CssColorParserPlus.parseColor(opt[last]);
944
+ var color2 = CssColorParserPlus.parseColor(opt[next]);
945
+ return color2.subtract(color1).multiplyByScalar(ratio).add(color1);
946
+ }
947
+ }
948
+ }
949
+ return CssColorParserPlus.parseColor(opt[keys[keys.length - 1]]).limitColor();
950
+ };
887
951
  return CssColorParserPlus;
888
952
  }(CssColorParser));
889
953
 
@@ -1 +1 @@
1
- !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).Parser={})}(this,(function(t){"use strict";var r=function(){function t(){}return t.type=function(t,r,n){var e=typeof r;if(e!==n)throw new Error("Expected ".concat(t," to be typeof ").concat(n,", actual typeof was ").concat(e))},t.types=function(t,r,n){var e=typeof r;if(!n.includes(e))throw new Error("Expected ".concat(t," to be typeof ").concat(n.join("|"),", actual typeof was ").concat(e))},t.numValue=function(r,n,e,o){t.numMinValue(r,n,e),t.numMaxValue(r,n,o)},t.numMinValue=function(t,r,n){if(r<n)throw new Error("Expected ".concat(t," to > ").concat(n,", actual value was ").concat(r))},t.numMaxValue=function(t,r,n){if(r>n)throw new Error("Expected ".concat(t," to < ").concat(n,", actual value was ").concat(r))},t.numIsInt=function(t,r,n){var e=Math.floor(r)===r;if(e!==n)throw new Error("Expected ".concat(t," to ").concat(n?"Integer":"Float",", actual value was ").concat(e?"Integer":"Float"))},t}();function n(t,r){return null==t||isNaN(t)&&"number"==typeof r?r:t}function e(t,r,n){return n>r?n=r:n<t&&(n=t),n}function o(t,r){void 0===t&&(t=0);var n=Math.pow(10,r);return Math.round(t*n)/n}var a,s,i,c,u,l,h,p,f=function(){function t(){}return t.clearStrSpace=function(t){return t.replace(/\s/g,"")},t.trimStr=function(t){return(t=t.replace(/\s+/g," ")).trim()},t.parse3BitsHEX=function(r){var e=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i.exec(r);if(e){var o=n(e[4],"f");return[t._parseResStrForRgb(parseInt(e[1]+e[1],16)),t._parseResStrForRgb(parseInt(e[2]+e[2],16)),t._parseResStrForRgb(parseInt(e[3]+e[3],16)),t._parsePercent(parseInt(o+o,16)/255)]}return null},t.parse6BitsHEX=function(r){var e=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(r);if(e){var o=n(e[4],"ff");return[t._parseResStrForRgb(parseInt(e[1],16)),t._parseResStrForRgb(parseInt(e[2],16)),t._parseResStrForRgb(parseInt(e[3],16)),t._parsePercent(parseInt(o,16)/255)]}return null},t.parseRGBA=function(r){var n=/^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(r);return n?[t._parseResStrForRgb(n[1]),t._parseResStrForRgb(n[2]),t._parseResStrForRgb(n[3]),t._parsePercent(n[4])]:null},t.parseHSLA=function(r){var n=/^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(r);return n?[t._parseResStrForHue(n[1]),t._parsePercent(n[2]),t._parsePercent(n[3]),t._parsePercent(n[4])]:null},t.parseHWB=function(r){var n=/^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return n?[t._parseResStrForHue(n[1]),t._parsePercent(n[2]),t._parsePercent(n[3]),t._parsePercent(n[4])]:null},t.parseRGBA2=function(r){var n=/^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return n?[t._parseResStrForRgb(n[1]),t._parseResStrForRgb(n[2]),t._parseResStrForRgb(n[3]),t._parsePercent(n[4])]:null},t.parseHSLA2=function(r){var n=/^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return n?[t._parseResStrForHue(n[1]),t._parsePercent(n[2]),t._parsePercent(n[3]),t._parsePercent(n[4])]:null},t._parseResStrForRgb=function(t){return"string"==typeof t&&(t=parseFloat(t)/("%"===t.substr(-1)?100/255:1)),isNaN(t)&&(t=1),e(0,255,t)},t._parseResStrForHue=function(t){return"string"==typeof t&&(t=parseFloat(t)),isNaN(t)&&(t=0),e(0,360,t)},t._parsePercent=function(t){return"string"==typeof t&&(t=parseFloat(t)/("%"===t.substr(-1)?100:1)),isNaN(t)&&(t=1),e(0,1,t)},t}(),b=function(){function t(t,r,n,e){this.r=255,this.g=255,this.b=255,this.a=1,this._outColorPrecision=2,this._outAlphaPrecision=2,this.setColor(t,r,n,e)}return t.prototype.setOutPrecision=function(t,n){return r.type("colorPrecision",t,"number"),r.type("outAlphaPrecision",n,"number"),r.numMinValue("colorPrecision",t,0),r.numMinValue("outAlphaPrecision",n,0),r.numIsInt("colorPrecision",t,!0),r.numIsInt("outAlphaPrecision",n,!0),this._outColorPrecision=t,this._outAlphaPrecision=n,this},t.prototype.setColor=function(t,r,o,a){return this.r=e(0,255,n(Number(t),0)),this.g=e(0,255,n(Number(r),0)),this.b=e(0,255,n(Number(o),0)),this.a=e(0,1,n(Number(a),1)),this},t.prototype.setAlpha=function(t){return this.a=e(0,1,n(Number(t),1)),this},t.prototype.setRed=function(t){return this.r=e(0,255,n(Number(t),0)),this},t.prototype.setGreen=function(t){return this.g=e(0,255,n(Number(t),0)),this},t.prototype.setBlue=function(t){return this.b=e(0,255,n(Number(t),0)),this},t.prototype.toRGBA=function(){var t=this.toJson();return 1===t.a?"rgb(".concat(t.r,",").concat(t.g,",").concat(t.b,")"):"rgba(".concat(t.r,",").concat(t.g,",").concat(t.b,",").concat(t.a,")")},t.prototype.toString=function(){return this.toRGBA()},t.prototype.toNormalize=function(){return[o(this.r/255,this._outColorPrecision),o(this.g/255,this._outColorPrecision),o(this.b/255,this._outColorPrecision),o(this.a,this._outAlphaPrecision)]},t.prototype.toHEX=function(){var t=this.toJson(),r=t.r.toString(16);r.length<2&&(r="0".concat(r));var n=t.g.toString(16);n.length<2&&(n="0".concat(n));var e=t.b.toString(16);if(e.length<2&&(e="0".concat(e)),this.a<1){var o=parseInt((255*this.a).toFixed()).toString(16);return o.length<2&&(o="0".concat(o)),"#".concat(r).concat(n).concat(e).concat(o)}return"#".concat(r).concat(n).concat(e)},t.prototype.toArray=function(){var t=this.toJson();return[t.r,t.g,t.b,t.a]},t.prototype.toJson=function(){return{r:o(this.r,this._outColorPrecision),g:o(this.g,this._outColorPrecision),b:o(this.b,this._outColorPrecision),a:o(this.a,this._outAlphaPrecision)}},t.prototype.toInvert=function(){return new t(255-this.r,255-this.g,255-this.b,1-this.a)},t.prototype.clone=function(){return new t(this.r,this.g,this.b,this.a)},t.prototype.equals=function(t){if(this===t)return!0;var r=this.toJson(),n=t.toJson();return r.r===n.r&&r.g===n.g&&r.b===n.g&&r.a===n.a},t.prototype.setInvert=function(){return this.r=255-this.r,this.g=255-this.g,this.b=255-this.b,this.a=1-this.a,this},t.prototype.multiplyByScalar=function(t,r){void 0===r&&(r=!0);var n=this.r*t,e=this.g*t,o=this.b*t,a=r?this.a*t:this.a;return this.setColor(n,e,o,a)},t.prototype.divideByScalar=function(t,r){void 0===r&&(r=!0);var n=this.r/t,e=this.g/t,o=this.b/t,a=r?this.a/t:this.a;return this.setColor(n,e,o,a)},t.prototype.add=function(t,r){void 0===r&&(r=!0);var n=this.r+t.r,e=this.g+t.g,o=this.b+t.b,a=r?this.a+t.a:this.a;return this.setColor(n,e,o,a)},t.prototype.subtract=function(t,r){void 0===r&&(r=!0);var n=this.r-t.r,e=this.g-t.g,o=this.b-t.b,a=r?this.a-t.a:this.a;return this.setColor(n,e,o,a)},t.prototype.multiply=function(t,r){void 0===r&&(r=!0);var n=this.r*t.r,e=this.g*t.g,o=this.b*t.b,a=r?this.a*t.a:this.a;return this.setColor(n,e,o,a)},t.prototype.divide=function(t,r){void 0===r&&(r=!0);var n=this.r/t.r,e=this.g/t.g,o=this.b/t.b,a=r?this.a/t.a:this.a;return this.setColor(n,e,o,a)},t.prototype.addNumberForRGB=function(t){return this.r=this.r+t,this.g=this.g+t,this.b=this.b+t,this},t.prototype.addNumberForAlpha=function(t){return this.a=this.a+t,this},t.parseHEX=function(r){var n=f.clearStrSpace(r),e=f.parse3BitsHEX(n);return e||(e=f.parse6BitsHEX(n)),e&&t.fromArray(e)},t.parseRGBA=function(r){var n=f.clearStrSpace(r),e=f.parseRGBA(n);if(!e){var o=f.trimStr(r);e=f.parseRGBA2(o)}return e&&t.fromArray(e)},t.fromJson=function(r){return new t(r.r,r.g,r.b,r.a)},t.fromArray=function(r){return new t(r[0],r[1],r[2],r[3])},t.fromRandom=function(r,n){return new t(Math.random()*Math.abs(n.r-r.r)+Math.min(r.r,n.r),Math.random()*Math.abs(n.g-r.g)+Math.min(r.g,n.g),Math.random()*Math.abs(n.b-r.b)+Math.min(r.b,n.b),Math.random()*Math.abs(n.a-r.a)+Math.min(r.a,n.a))},t.fromNormalize=function(r){var n=255*r[0],e=255*r[1],o=255*r[2],a=r[3];return t.fromArray([n,e,o,a])},t}(),g=function(t,r){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])},g(t,r)};function d(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function y(){if(c)return i;c=1;const t=s?a:(s=1,a={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}),r={};for(const n of Object.keys(t))r[t[n]]=n;const n={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};i=n;for(const t of Object.keys(n)){if(!("channels"in n[t]))throw new Error("missing channels property: "+t);if(!("labels"in n[t]))throw new Error("missing channel labels property: "+t);if(n[t].labels.length!==n[t].channels)throw new Error("channel and label counts mismatch: "+t);const{channels:r,labels:e}=n[t];delete n[t].channels,delete n[t].labels,Object.defineProperty(n[t],"channels",{value:r}),Object.defineProperty(n[t],"labels",{value:e})}return n.rgb.hsl=function(t){const r=t[0]/255,n=t[1]/255,e=t[2]/255,o=Math.min(r,n,e),a=Math.max(r,n,e),s=a-o;let i,c;a===o?i=0:r===a?i=(n-e)/s:n===a?i=2+(e-r)/s:e===a&&(i=4+(r-n)/s),i=Math.min(60*i,360),i<0&&(i+=360);const u=(o+a)/2;return c=a===o?0:u<=.5?s/(a+o):s/(2-a-o),[i,100*c,100*u]},n.rgb.hsv=function(t){let r,n,e,o,a;const s=t[0]/255,i=t[1]/255,c=t[2]/255,u=Math.max(s,i,c),l=u-Math.min(s,i,c),h=function(t){return(u-t)/6/l+.5};return 0===l?(o=0,a=0):(a=l/u,r=h(s),n=h(i),e=h(c),s===u?o=e-n:i===u?o=1/3+r-e:c===u&&(o=2/3+n-r),o<0?o+=1:o>1&&(o-=1)),[360*o,100*a,100*u]},n.rgb.hwb=function(t){const r=t[0],e=t[1];let o=t[2];const a=n.rgb.hsl(t)[0],s=1/255*Math.min(r,Math.min(e,o));return o=1-1/255*Math.max(r,Math.max(e,o)),[a,100*s,100*o]},n.rgb.cmyk=function(t){const r=t[0]/255,n=t[1]/255,e=t[2]/255,o=Math.min(1-r,1-n,1-e);return[100*((1-r-o)/(1-o)||0),100*((1-n-o)/(1-o)||0),100*((1-e-o)/(1-o)||0),100*o]},n.rgb.keyword=function(n){const e=r[n];if(e)return e;let o,a=1/0;for(const r of Object.keys(t)){const e=t[r],c=(i=e,((s=n)[0]-i[0])**2+(s[1]-i[1])**2+(s[2]-i[2])**2);c<a&&(a=c,o=r)}var s,i;return o},n.keyword.rgb=function(r){return t[r]},n.rgb.xyz=function(t){let r=t[0]/255,n=t[1]/255,e=t[2]/255;r=r>.04045?((r+.055)/1.055)**2.4:r/12.92,n=n>.04045?((n+.055)/1.055)**2.4:n/12.92,e=e>.04045?((e+.055)/1.055)**2.4:e/12.92;return[100*(.4124*r+.3576*n+.1805*e),100*(.2126*r+.7152*n+.0722*e),100*(.0193*r+.1192*n+.9505*e)]},n.rgb.lab=function(t){const r=n.rgb.xyz(t);let e=r[0],o=r[1],a=r[2];e/=95.047,o/=100,a/=108.883,e=e>.008856?e**(1/3):7.787*e+16/116,o=o>.008856?o**(1/3):7.787*o+16/116,a=a>.008856?a**(1/3):7.787*a+16/116;return[116*o-16,500*(e-o),200*(o-a)]},n.hsl.rgb=function(t){const r=t[0]/360,n=t[1]/100,e=t[2]/100;let o,a,s;if(0===n)return s=255*e,[s,s,s];o=e<.5?e*(1+n):e+n-e*n;const i=2*e-o,c=[0,0,0];for(let t=0;t<3;t++)a=r+1/3*-(t-1),a<0&&a++,a>1&&a--,s=6*a<1?i+6*(o-i)*a:2*a<1?o:3*a<2?i+(o-i)*(2/3-a)*6:i,c[t]=255*s;return c},n.hsl.hsv=function(t){const r=t[0];let n=t[1]/100,e=t[2]/100,o=n;const a=Math.max(e,.01);e*=2,n*=e<=1?e:2-e,o*=a<=1?a:2-a;return[r,100*(0===e?2*o/(a+o):2*n/(e+n)),100*((e+n)/2)]},n.hsv.rgb=function(t){const r=t[0]/60,n=t[1]/100;let e=t[2]/100;const o=Math.floor(r)%6,a=r-Math.floor(r),s=255*e*(1-n),i=255*e*(1-n*a),c=255*e*(1-n*(1-a));switch(e*=255,o){case 0:return[e,c,s];case 1:return[i,e,s];case 2:return[s,e,c];case 3:return[s,i,e];case 4:return[c,s,e];case 5:return[e,s,i]}},n.hsv.hsl=function(t){const r=t[0],n=t[1]/100,e=t[2]/100,o=Math.max(e,.01);let a,s;s=(2-n)*e;const i=(2-n)*o;return a=n*o,a/=i<=1?i:2-i,a=a||0,s/=2,[r,100*a,100*s]},n.hwb.rgb=function(t){const r=t[0]/360;let n=t[1]/100,e=t[2]/100;const o=n+e;let a;o>1&&(n/=o,e/=o);const s=Math.floor(6*r),i=1-e;a=6*r-s,1&s&&(a=1-a);const c=n+a*(i-n);let u,l,h;switch(s){default:case 6:case 0:u=i,l=c,h=n;break;case 1:u=c,l=i,h=n;break;case 2:u=n,l=i,h=c;break;case 3:u=n,l=c,h=i;break;case 4:u=c,l=n,h=i;break;case 5:u=i,l=n,h=c}return[255*u,255*l,255*h]},n.cmyk.rgb=function(t){const r=t[0]/100,n=t[1]/100,e=t[2]/100,o=t[3]/100;return[255*(1-Math.min(1,r*(1-o)+o)),255*(1-Math.min(1,n*(1-o)+o)),255*(1-Math.min(1,e*(1-o)+o))]},n.xyz.rgb=function(t){const r=t[0]/100,n=t[1]/100,e=t[2]/100;let o,a,s;return o=3.2406*r+-1.5372*n+-.4986*e,a=-.9689*r+1.8758*n+.0415*e,s=.0557*r+-.204*n+1.057*e,o=o>.0031308?1.055*o**(1/2.4)-.055:12.92*o,a=a>.0031308?1.055*a**(1/2.4)-.055:12.92*a,s=s>.0031308?1.055*s**(1/2.4)-.055:12.92*s,o=Math.min(Math.max(0,o),1),a=Math.min(Math.max(0,a),1),s=Math.min(Math.max(0,s),1),[255*o,255*a,255*s]},n.xyz.lab=function(t){let r=t[0],n=t[1],e=t[2];r/=95.047,n/=100,e/=108.883,r=r>.008856?r**(1/3):7.787*r+16/116,n=n>.008856?n**(1/3):7.787*n+16/116,e=e>.008856?e**(1/3):7.787*e+16/116;return[116*n-16,500*(r-n),200*(n-e)]},n.lab.xyz=function(t){let r,n,e;n=(t[0]+16)/116,r=t[1]/500+n,e=n-t[2]/200;const o=n**3,a=r**3,s=e**3;return n=o>.008856?o:(n-16/116)/7.787,r=a>.008856?a:(r-16/116)/7.787,e=s>.008856?s:(e-16/116)/7.787,r*=95.047,n*=100,e*=108.883,[r,n,e]},n.lab.lch=function(t){const r=t[0],n=t[1],e=t[2];let o;o=360*Math.atan2(e,n)/2/Math.PI,o<0&&(o+=360);return[r,Math.sqrt(n*n+e*e),o]},n.lch.lab=function(t){const r=t[0],n=t[1],e=t[2]/360*2*Math.PI;return[r,n*Math.cos(e),n*Math.sin(e)]},n.rgb.ansi16=function(t,r=null){const[e,o,a]=t;let s=null===r?n.rgb.hsv(t)[2]:r;if(s=Math.round(s/50),0===s)return 30;let i=30+(Math.round(a/255)<<2|Math.round(o/255)<<1|Math.round(e/255));return 2===s&&(i+=60),i},n.hsv.ansi16=function(t){return n.rgb.ansi16(n.hsv.rgb(t),t[2])},n.rgb.ansi256=function(t){const r=t[0],n=t[1],e=t[2];if(r===n&&n===e)return r<8?16:r>248?231:Math.round((r-8)/247*24)+232;return 16+36*Math.round(r/255*5)+6*Math.round(n/255*5)+Math.round(e/255*5)},n.ansi16.rgb=function(t){let r=t%10;if(0===r||7===r)return t>50&&(r+=3.5),r=r/10.5*255,[r,r,r];const n=.5*(1+~~(t>50));return[(1&r)*n*255,(r>>1&1)*n*255,(r>>2&1)*n*255]},n.ansi256.rgb=function(t){if(t>=232){const r=10*(t-232)+8;return[r,r,r]}let r;t-=16;return[Math.floor(t/36)/5*255,Math.floor((r=t%36)/6)/5*255,r%6/5*255]},n.rgb.hex=function(t){const r=(((255&Math.round(t[0]))<<16)+((255&Math.round(t[1]))<<8)+(255&Math.round(t[2]))).toString(16).toUpperCase();return"000000".substring(r.length)+r},n.hex.rgb=function(t){const r=t.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!r)return[0,0,0];let n=r[0];3===r[0].length&&(n=n.split("").map((t=>t+t)).join(""));const e=parseInt(n,16);return[e>>16&255,e>>8&255,255&e]},n.rgb.hcg=function(t){const r=t[0]/255,n=t[1]/255,e=t[2]/255,o=Math.max(Math.max(r,n),e),a=Math.min(Math.min(r,n),e),s=o-a;let i,c;return i=s<1?a/(1-s):0,c=s<=0?0:o===r?(n-e)/s%6:o===n?2+(e-r)/s:4+(r-n)/s,c/=6,c%=1,[360*c,100*s,100*i]},n.hsl.hcg=function(t){const r=t[1]/100,n=t[2]/100,e=n<.5?2*r*n:2*r*(1-n);let o=0;return e<1&&(o=(n-.5*e)/(1-e)),[t[0],100*e,100*o]},n.hsv.hcg=function(t){const r=t[1]/100,n=t[2]/100,e=r*n;let o=0;return e<1&&(o=(n-e)/(1-e)),[t[0],100*e,100*o]},n.hcg.rgb=function(t){const r=t[0]/360,n=t[1]/100,e=t[2]/100;if(0===n)return[255*e,255*e,255*e];const o=[0,0,0],a=r%1*6,s=a%1,i=1-s;let c=0;switch(Math.floor(a)){case 0:o[0]=1,o[1]=s,o[2]=0;break;case 1:o[0]=i,o[1]=1,o[2]=0;break;case 2:o[0]=0,o[1]=1,o[2]=s;break;case 3:o[0]=0,o[1]=i,o[2]=1;break;case 4:o[0]=s,o[1]=0,o[2]=1;break;default:o[0]=1,o[1]=0,o[2]=i}return c=(1-n)*e,[255*(n*o[0]+c),255*(n*o[1]+c),255*(n*o[2]+c)]},n.hcg.hsv=function(t){const r=t[1]/100,n=r+t[2]/100*(1-r);let e=0;return n>0&&(e=r/n),[t[0],100*e,100*n]},n.hcg.hsl=function(t){const r=t[1]/100,n=t[2]/100*(1-r)+.5*r;let e=0;return n>0&&n<.5?e=r/(2*n):n>=.5&&n<1&&(e=r/(2*(1-n))),[t[0],100*e,100*n]},n.hcg.hwb=function(t){const r=t[1]/100,n=r+t[2]/100*(1-r);return[t[0],100*(n-r),100*(1-n)]},n.hwb.hcg=function(t){const r=t[1]/100,n=1-t[2]/100,e=n-r;let o=0;return e<1&&(o=(n-e)/(1-e)),[t[0],100*e,100*o]},n.apple.rgb=function(t){return[t[0]/65535*255,t[1]/65535*255,t[2]/65535*255]},n.rgb.apple=function(t){return[t[0]/255*65535,t[1]/255*65535,t[2]/255*65535]},n.gray.rgb=function(t){return[t[0]/100*255,t[0]/100*255,t[0]/100*255]},n.gray.hsl=function(t){return[0,0,t[0]]},n.gray.hsv=n.gray.hsl,n.gray.hwb=function(t){return[0,100,t[0]]},n.gray.cmyk=function(t){return[0,0,0,t[0]]},n.gray.lab=function(t){return[t[0],0,0]},n.gray.hex=function(t){const r=255&Math.round(t[0]/100*255),n=((r<<16)+(r<<8)+r).toString(16).toUpperCase();return"000000".substring(n.length)+n},n.rgb.gray=function(t){return[(t[0]+t[1]+t[2])/3/255*100]},i}function m(){if(l)return u;l=1;const t=y();function r(r){const n=function(){const r={},n=Object.keys(t);for(let t=n.length,e=0;e<t;e++)r[n[e]]={distance:-1,parent:null};return r}(),e=[r];for(n[r].distance=0;e.length;){const r=e.pop(),o=Object.keys(t[r]);for(let t=o.length,a=0;a<t;a++){const t=o[a],s=n[t];-1===s.distance&&(s.distance=n[r].distance+1,s.parent=r,e.unshift(t))}}return n}function n(t,r){return function(n){return r(t(n))}}function e(r,e){const o=[e[r].parent,r];let a=t[e[r].parent][r],s=e[r].parent;for(;e[s].parent;)o.unshift(e[s].parent),a=n(t[e[s].parent][s],a),s=e[s].parent;return a.conversion=o,a}return u=function(t){const n=r(t),o={},a=Object.keys(n);for(let t=a.length,r=0;r<t;r++){const t=a[r];null!==n[t].parent&&(o[t]=e(t,n))}return o}}"function"==typeof SuppressedError&&SuppressedError;var v=function(){if(p)return h;p=1;const t=y(),r=m(),n={};return Object.keys(t).forEach((e=>{n[e]={},Object.defineProperty(n[e],"channels",{value:t[e].channels}),Object.defineProperty(n[e],"labels",{value:t[e].labels});const o=r(e);Object.keys(o).forEach((t=>{const r=o[t];n[e][t]=function(t){const r=function(...r){const n=r[0];if(null==n)return n;n.length>1&&(r=n);const e=t(r);if("object"==typeof e)for(let t=e.length,r=0;r<t;r++)e[r]=Math.round(e[r]);return e};return"conversion"in t&&(r.conversion=t.conversion),r}(r),n[e][t].raw=function(t){const r=function(...r){const n=r[0];return null==n?n:(n.length>1&&(r=n),t(r))};return"conversion"in t&&(r.conversion=t.conversion),r}(r)}))})),h=n}(),M=d(v),w=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}g(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}(o,t),o.prototype.toInvert=function(){return new o(255-this.r,255-this.g,255-this.b,1-this.a)},o.prototype.clone=function(){return new o(this.r,this.g,this.b,this.a)},o.prototype.equals=function(t){if(this===(t=o.parseColor(t)))return!0;var r=this.toJson(),n=t.toJson();return r.r===n.r&&r.g===n.g&&r.b===n.g&&r.a===n.a},o.prototype.add=function(r,n){void 0===n&&(n=!0);var e=o.parseColor(r);return t.prototype.add.call(this,e,n)},o.prototype.subtract=function(r,n){void 0===n&&(n=!0);var e=o.parseColor(r);return t.prototype.subtract.call(this,e,n)},o.prototype.multiply=function(r,n){void 0===n&&(n=!0);var e=o.parseColor(r);return t.prototype.multiply.call(this,e,n)},o.prototype.divide=function(r,n){void 0===n&&(n=!0);var e=o.parseColor(r);return t.prototype.divide.call(this,e,n)},o.parseColor=function(t){return t instanceof b?t:o.parseCssColorStr(t)},o.parseCssColorStr=function(t){return r.type("color",t,"string"),o.parseHEX(t)||o.parseRGBA(t)||o.parseKeyWord(t)||o.parseHSLA(t)||o.parseHWB(t)},o.parseKeyWord=function(t){var r=f.clearStrSpace(t),n=M.keyword.rgb(r);return n&&o.fromArray(n)},o.parseHSLA=function(t){var r=f.clearStrSpace(t),n=f.parseHSLA(r);if(!n){var e=f.trimStr(t);n=f.parseHSLA2(e)}return n&&o.fromHSL(n[0],n[1],n[2],n[3])},o.parseHWB=function(t){var r=f.trimStr(t),n=f.parseHWB(r);return n&&o.fromHWB(n[0],n[1],n[2],n[3])},o.fromHSL=function(t,r,a,s){var i=M.hsl.rgb(e(0,360,t),e(0,100,100*r),e(0,100,100*a));return new o(i[0],i[1],i[2],n(Number(s),1))},o.fromHWB=function(t,r,a,s){var i=M.hwb.rgb(e(0,360,t),e(0,100,100*r),e(0,100,100*a));return new o(i[0],i[1],i[2],n(Number(s),1))},o.parseHEX=function(t){var r=f.clearStrSpace(t),n=f.parse3BitsHEX(r);return n||(n=f.parse6BitsHEX(r)),n&&o.fromArray(n)},o.parseRGBA=function(t){var r=f.clearStrSpace(t),n=f.parseRGBA(r);if(!n){var e=f.trimStr(t);n=f.parseRGBA2(e)}return n&&o.fromArray(n)},o.fromJson=function(t){return new o(t.r,t.g,t.b,t.a)},o.fromArray=function(t){return new o(t[0],t[1],t[2],t[3])},o.fromRandom=function(t,r){return t=o.parseColor(t),r=o.parseColor(r),new o(Math.random()*Math.abs(r.r-t.r)+Math.min(t.r,r.r),Math.random()*Math.abs(r.g-t.g)+Math.min(t.g,r.g),Math.random()*Math.abs(r.b-t.b)+Math.min(t.b,r.b),Math.random()*Math.abs(r.a-t.a)+Math.min(t.a,r.a))},o.fromNormalize=function(t){var r=255*t[0],n=255*t[1],e=255*t[2],a=t[3];return o.fromArray([r,n,e,a])},o}(b);t.CssColorParser=b,t.CssColorParserPlus=w}));
1
+ !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self).Parser={})}(this,(function(t){"use strict";var r=function(){function t(){}return t.type=function(t,r,n){var e=typeof r;if(e!==n)throw new Error("Expected ".concat(t," to be typeof ").concat(n,", actual typeof was ").concat(e))},t.types=function(t,r,n){var e=typeof r;if(!n.includes(e))throw new Error("Expected ".concat(t," to be typeof ").concat(n.join("|"),", actual typeof was ").concat(e))},t.numValue=function(r,n,e,o){t.numMinValue(r,n,e),t.numMaxValue(r,n,o)},t.numMinValue=function(t,r,n){if(r<n)throw new Error("Expected ".concat(t," to > ").concat(n,", actual value was ").concat(r))},t.numMaxValue=function(t,r,n){if(r>n)throw new Error("Expected ".concat(t," to < ").concat(n,", actual value was ").concat(r))},t.numIsInt=function(t,r,n){var e=Math.floor(r)===r;if(e!==n)throw new Error("Expected ".concat(t," to ").concat(n?"Integer":"Float",", actual value was ").concat(e?"Integer":"Float"))},t}();function n(t,r){return null==t||isNaN(t)&&"number"==typeof r?r:t}function e(t,r,n){return n>r?n=r:n<t&&(n=t),n}function o(t,r){void 0===t&&(t=0);var n=Math.pow(10,r);return Math.round(t*n)/n}var a,s,i,c,u,l,h,p,f=function(){function t(){}return t.clearStrSpace=function(t){return t.replace(/\s/g,"")},t.trimStr=function(t){return(t=t.replace(/\s+/g," ")).trim()},t.parse3BitsHEX=function(r){var e=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i.exec(r);if(e){var o=n(e[4],"f");return[t._parseResStrForRgb(parseInt(e[1]+e[1],16)),t._parseResStrForRgb(parseInt(e[2]+e[2],16)),t._parseResStrForRgb(parseInt(e[3]+e[3],16)),t._parsePercent(parseInt(o+o,16)/255)]}return null},t.parse6BitsHEX=function(r){var e=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(r);if(e){var o=n(e[4],"ff");return[t._parseResStrForRgb(parseInt(e[1],16)),t._parseResStrForRgb(parseInt(e[2],16)),t._parseResStrForRgb(parseInt(e[3],16)),t._parsePercent(parseInt(o,16)/255)]}return null},t.parseRGBA=function(r){var n=/^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(r);return n?[t._parseResStrForRgb(n[1]),t._parseResStrForRgb(n[2]),t._parseResStrForRgb(n[3]),t._parsePercent(n[4])]:null},t.parseHSLA=function(r){var n=/^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(r);return n?[t._parseResStrForHue(n[1]),t._parsePercent(n[2]),t._parsePercent(n[3]),t._parsePercent(n[4])]:null},t.parseHWB=function(r){var n=/^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return n?[t._parseResStrForHue(n[1]),t._parsePercent(n[2]),t._parsePercent(n[3]),t._parsePercent(n[4])]:null},t.parseRGBA2=function(r){var n=/^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return n?[t._parseResStrForRgb(n[1]),t._parseResStrForRgb(n[2]),t._parseResStrForRgb(n[3]),t._parsePercent(n[4])]:null},t.parseHSLA2=function(r){var n=/^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return n?[t._parseResStrForHue(n[1]),t._parsePercent(n[2]),t._parsePercent(n[3]),t._parsePercent(n[4])]:null},t._parseResStrForRgb=function(t){return"string"==typeof t&&(t=parseFloat(t)/("%"===t.substr(-1)?100/255:1)),isNaN(t)&&(t=1),e(0,255,t)},t._parseResStrForHue=function(t){return"string"==typeof t&&(t=parseFloat(t)),isNaN(t)&&(t=0),e(0,360,t)},t._parsePercent=function(t){return"string"==typeof t&&(t=parseFloat(t)/("%"===t.substr(-1)?100:1)),isNaN(t)&&(t=1),e(0,1,t)},t}(),b=function(){function t(t,r,n,e){this.r=255,this.g=255,this.b=255,this.a=1,this._outColorPrecision=2,this._outAlphaPrecision=2,this.setColor(t,r,n,e)}return t.prototype.setOutPrecision=function(t,n){return r.type("colorPrecision",t,"number"),r.type("outAlphaPrecision",n,"number"),r.numMinValue("colorPrecision",t,0),r.numMinValue("outAlphaPrecision",n,0),r.numIsInt("colorPrecision",t,!0),r.numIsInt("outAlphaPrecision",n,!0),this._outColorPrecision=t,this._outAlphaPrecision=n,this},t.prototype.setColor=function(t,r,o,a,s){return void 0===s&&(s=!0),s?(this.r=e(0,255,n(Number(t),0)),this.g=e(0,255,n(Number(r),0)),this.b=e(0,255,n(Number(o),0)),this.a=e(0,1,n(Number(a),1))):(this.r=n(Number(t),0),this.g=n(Number(r),0),this.b=n(Number(o),0),this.a=n(Number(a),1)),this},t.prototype.limitColor=function(){return this.setColor(this.r,this.g,this.b,this.a,!0)},t.prototype.setAlpha=function(t){return this.a=e(0,1,n(Number(t),1)),this},t.prototype.setRed=function(t){return this.r=e(0,255,n(Number(t),0)),this},t.prototype.setGreen=function(t){return this.g=e(0,255,n(Number(t),0)),this},t.prototype.setBlue=function(t){return this.b=e(0,255,n(Number(t),0)),this},t.prototype.toRGBA=function(){var t=this.toJson();return 1===t.a?"rgb(".concat(t.r,",").concat(t.g,",").concat(t.b,")"):"rgba(".concat(t.r,",").concat(t.g,",").concat(t.b,",").concat(t.a,")")},t.prototype.toString=function(){return this.toRGBA()},t.prototype.toNormalize=function(){var t=this.toJson();return[t.r/255,t.g/255,t.b/255,t.a]},t.prototype.toHEX=function(){var t=this.toJson(!0,0,0),r=t.r,n=t.g,e=t.b,a=r.toString(16);a.length<2&&(a="0".concat(a));var s=n.toString(16);s.length<2&&(s="0".concat(s));var i=e.toString(16);if(i.length<2&&(i="0".concat(i)),this.a<1){var c=o(255*this.a,0).toString(16);return c.length<2&&(c="0".concat(c)),"#".concat(a).concat(s).concat(i).concat(c)}return"#".concat(a).concat(s).concat(i)},t.prototype.toArray=function(){var t=this.toJson();return[t.r,t.g,t.b,t.a]},t.prototype.toJson=function(t,r,n){void 0===t&&(t=!0),void 0===r&&(r=this._outColorPrecision),void 0===n&&(n=this._outAlphaPrecision);var a=this.r,s=this.g,i=this.b,c=this.a;return t&&(a=e(0,255,this.r),s=e(0,255,this.g),i=e(0,255,this.b),c=e(0,1,this.a)),{r:o(a,r),g:o(s,r),b:o(i,r),a:o(c,n)}},t.prototype.toInvert=function(){var r=this.toJson();r.r,r.g,r.b,r.a;return new t(255-this.r,255-this.g,255-this.b,1-this.a)},t.prototype.clone=function(){var r=new t(this.r,this.g,this.b,this.a);return r._outColorPrecision=this._outColorPrecision,r._outAlphaPrecision=this._outAlphaPrecision,r},t.prototype.equals=function(t){if(this===t)return!0;var r=this.toJson(),n=t.toJson();return r.r===n.r&&r.g===n.g&&r.b===n.g&&r.a===n.a},t.prototype.setInvert=function(){var t=this.toJson(),r=t.r,n=t.g,e=t.b,o=t.a;return this.r=255-r,this.g=255-n,this.b=255-e,this.a=1-o,this},t.prototype.multiplyByScalar=function(t,r){void 0===r&&(r=!0);var n=this.r*t,e=this.g*t,o=this.b*t,a=r?this.a*t:this.a;return this.setColor(n,e,o,a,!1)},t.prototype.divideByScalar=function(t,r){void 0===r&&(r=!0);var n=this.r/t,e=this.g/t,o=this.b/t,a=r?this.a/t:this.a;return this.setColor(n,e,o,a,!1)},t.prototype.add=function(t,r){void 0===r&&(r=!0);var n=this.r+t.r,e=this.g+t.g,o=this.b+t.b,a=r?this.a+t.a:this.a;return this.setColor(n,e,o,a,!1)},t.prototype.subtract=function(t,r){void 0===r&&(r=!0);var n=this.r-t.r,e=this.g-t.g,o=this.b-t.b,a=r?this.a-t.a:this.a;return this.setColor(n,e,o,a,!1)},t.prototype.multiply=function(t,r){void 0===r&&(r=!0);var n=this.r*t.r,e=this.g*t.g,o=this.b*t.b,a=r?this.a*t.a:this.a;return this.setColor(n,e,o,a,!1)},t.prototype.divide=function(t,r){void 0===r&&(r=!0);var n=this.r/t.r,e=this.g/t.g,o=this.b/t.b,a=r?this.a/t.a:this.a;return this.setColor(n,e,o,a,!1)},t.prototype.addNumberForRGB=function(t){return this.r=this.r+t,this.g=this.g+t,this.b=this.b+t,this},t.prototype.addNumberForAlpha=function(t){return this.a=this.a+t,this},t.parseHEX=function(r){var n=f.clearStrSpace(r),e=f.parse3BitsHEX(n);return e||(e=f.parse6BitsHEX(n)),e&&t.fromArray(e)},t.parseRGBA=function(r){var n=f.clearStrSpace(r),e=f.parseRGBA(n);if(!e){var o=f.trimStr(r);e=f.parseRGBA2(o)}return e&&t.fromArray(e)},t.fromJson=function(r){return new t(r.r,r.g,r.b,r.a)},t.fromArray=function(r){return new t(r[0],r[1],r[2],r[3])},t.fromRandom=function(r,n){return new t(Math.random()*Math.abs(n.r-r.r)+Math.min(r.r,n.r),Math.random()*Math.abs(n.g-r.g)+Math.min(r.g,n.g),Math.random()*Math.abs(n.b-r.b)+Math.min(r.b,n.b),Math.random()*Math.abs(n.a-r.a)+Math.min(r.a,n.a))},t.fromNormalize=function(r){var n=255*r[0],e=255*r[1],o=255*r[2],a=r[3];return t.fromArray([n,e,o,a])},t}(),g=function(t,r){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])},g(t,r)};function d(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function y(){if(c)return i;c=1;const t=s?a:(s=1,a={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]}),r={};for(const n of Object.keys(t))r[t[n]]=n;const n={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};i=n;for(const t of Object.keys(n)){if(!("channels"in n[t]))throw new Error("missing channels property: "+t);if(!("labels"in n[t]))throw new Error("missing channel labels property: "+t);if(n[t].labels.length!==n[t].channels)throw new Error("channel and label counts mismatch: "+t);const{channels:r,labels:e}=n[t];delete n[t].channels,delete n[t].labels,Object.defineProperty(n[t],"channels",{value:r}),Object.defineProperty(n[t],"labels",{value:e})}return n.rgb.hsl=function(t){const r=t[0]/255,n=t[1]/255,e=t[2]/255,o=Math.min(r,n,e),a=Math.max(r,n,e),s=a-o;let i,c;a===o?i=0:r===a?i=(n-e)/s:n===a?i=2+(e-r)/s:e===a&&(i=4+(r-n)/s),i=Math.min(60*i,360),i<0&&(i+=360);const u=(o+a)/2;return c=a===o?0:u<=.5?s/(a+o):s/(2-a-o),[i,100*c,100*u]},n.rgb.hsv=function(t){let r,n,e,o,a;const s=t[0]/255,i=t[1]/255,c=t[2]/255,u=Math.max(s,i,c),l=u-Math.min(s,i,c),h=function(t){return(u-t)/6/l+.5};return 0===l?(o=0,a=0):(a=l/u,r=h(s),n=h(i),e=h(c),s===u?o=e-n:i===u?o=1/3+r-e:c===u&&(o=2/3+n-r),o<0?o+=1:o>1&&(o-=1)),[360*o,100*a,100*u]},n.rgb.hwb=function(t){const r=t[0],e=t[1];let o=t[2];const a=n.rgb.hsl(t)[0],s=1/255*Math.min(r,Math.min(e,o));return o=1-1/255*Math.max(r,Math.max(e,o)),[a,100*s,100*o]},n.rgb.cmyk=function(t){const r=t[0]/255,n=t[1]/255,e=t[2]/255,o=Math.min(1-r,1-n,1-e);return[100*((1-r-o)/(1-o)||0),100*((1-n-o)/(1-o)||0),100*((1-e-o)/(1-o)||0),100*o]},n.rgb.keyword=function(n){const e=r[n];if(e)return e;let o,a=1/0;for(const r of Object.keys(t)){const e=t[r],c=(i=e,((s=n)[0]-i[0])**2+(s[1]-i[1])**2+(s[2]-i[2])**2);c<a&&(a=c,o=r)}var s,i;return o},n.keyword.rgb=function(r){return t[r]},n.rgb.xyz=function(t){let r=t[0]/255,n=t[1]/255,e=t[2]/255;r=r>.04045?((r+.055)/1.055)**2.4:r/12.92,n=n>.04045?((n+.055)/1.055)**2.4:n/12.92,e=e>.04045?((e+.055)/1.055)**2.4:e/12.92;return[100*(.4124*r+.3576*n+.1805*e),100*(.2126*r+.7152*n+.0722*e),100*(.0193*r+.1192*n+.9505*e)]},n.rgb.lab=function(t){const r=n.rgb.xyz(t);let e=r[0],o=r[1],a=r[2];e/=95.047,o/=100,a/=108.883,e=e>.008856?e**(1/3):7.787*e+16/116,o=o>.008856?o**(1/3):7.787*o+16/116,a=a>.008856?a**(1/3):7.787*a+16/116;return[116*o-16,500*(e-o),200*(o-a)]},n.hsl.rgb=function(t){const r=t[0]/360,n=t[1]/100,e=t[2]/100;let o,a,s;if(0===n)return s=255*e,[s,s,s];o=e<.5?e*(1+n):e+n-e*n;const i=2*e-o,c=[0,0,0];for(let t=0;t<3;t++)a=r+1/3*-(t-1),a<0&&a++,a>1&&a--,s=6*a<1?i+6*(o-i)*a:2*a<1?o:3*a<2?i+(o-i)*(2/3-a)*6:i,c[t]=255*s;return c},n.hsl.hsv=function(t){const r=t[0];let n=t[1]/100,e=t[2]/100,o=n;const a=Math.max(e,.01);e*=2,n*=e<=1?e:2-e,o*=a<=1?a:2-a;return[r,100*(0===e?2*o/(a+o):2*n/(e+n)),100*((e+n)/2)]},n.hsv.rgb=function(t){const r=t[0]/60,n=t[1]/100;let e=t[2]/100;const o=Math.floor(r)%6,a=r-Math.floor(r),s=255*e*(1-n),i=255*e*(1-n*a),c=255*e*(1-n*(1-a));switch(e*=255,o){case 0:return[e,c,s];case 1:return[i,e,s];case 2:return[s,e,c];case 3:return[s,i,e];case 4:return[c,s,e];case 5:return[e,s,i]}},n.hsv.hsl=function(t){const r=t[0],n=t[1]/100,e=t[2]/100,o=Math.max(e,.01);let a,s;s=(2-n)*e;const i=(2-n)*o;return a=n*o,a/=i<=1?i:2-i,a=a||0,s/=2,[r,100*a,100*s]},n.hwb.rgb=function(t){const r=t[0]/360;let n=t[1]/100,e=t[2]/100;const o=n+e;let a;o>1&&(n/=o,e/=o);const s=Math.floor(6*r),i=1-e;a=6*r-s,1&s&&(a=1-a);const c=n+a*(i-n);let u,l,h;switch(s){default:case 6:case 0:u=i,l=c,h=n;break;case 1:u=c,l=i,h=n;break;case 2:u=n,l=i,h=c;break;case 3:u=n,l=c,h=i;break;case 4:u=c,l=n,h=i;break;case 5:u=i,l=n,h=c}return[255*u,255*l,255*h]},n.cmyk.rgb=function(t){const r=t[0]/100,n=t[1]/100,e=t[2]/100,o=t[3]/100;return[255*(1-Math.min(1,r*(1-o)+o)),255*(1-Math.min(1,n*(1-o)+o)),255*(1-Math.min(1,e*(1-o)+o))]},n.xyz.rgb=function(t){const r=t[0]/100,n=t[1]/100,e=t[2]/100;let o,a,s;return o=3.2406*r+-1.5372*n+-.4986*e,a=-.9689*r+1.8758*n+.0415*e,s=.0557*r+-.204*n+1.057*e,o=o>.0031308?1.055*o**(1/2.4)-.055:12.92*o,a=a>.0031308?1.055*a**(1/2.4)-.055:12.92*a,s=s>.0031308?1.055*s**(1/2.4)-.055:12.92*s,o=Math.min(Math.max(0,o),1),a=Math.min(Math.max(0,a),1),s=Math.min(Math.max(0,s),1),[255*o,255*a,255*s]},n.xyz.lab=function(t){let r=t[0],n=t[1],e=t[2];r/=95.047,n/=100,e/=108.883,r=r>.008856?r**(1/3):7.787*r+16/116,n=n>.008856?n**(1/3):7.787*n+16/116,e=e>.008856?e**(1/3):7.787*e+16/116;return[116*n-16,500*(r-n),200*(n-e)]},n.lab.xyz=function(t){let r,n,e;n=(t[0]+16)/116,r=t[1]/500+n,e=n-t[2]/200;const o=n**3,a=r**3,s=e**3;return n=o>.008856?o:(n-16/116)/7.787,r=a>.008856?a:(r-16/116)/7.787,e=s>.008856?s:(e-16/116)/7.787,r*=95.047,n*=100,e*=108.883,[r,n,e]},n.lab.lch=function(t){const r=t[0],n=t[1],e=t[2];let o;o=360*Math.atan2(e,n)/2/Math.PI,o<0&&(o+=360);return[r,Math.sqrt(n*n+e*e),o]},n.lch.lab=function(t){const r=t[0],n=t[1],e=t[2]/360*2*Math.PI;return[r,n*Math.cos(e),n*Math.sin(e)]},n.rgb.ansi16=function(t,r=null){const[e,o,a]=t;let s=null===r?n.rgb.hsv(t)[2]:r;if(s=Math.round(s/50),0===s)return 30;let i=30+(Math.round(a/255)<<2|Math.round(o/255)<<1|Math.round(e/255));return 2===s&&(i+=60),i},n.hsv.ansi16=function(t){return n.rgb.ansi16(n.hsv.rgb(t),t[2])},n.rgb.ansi256=function(t){const r=t[0],n=t[1],e=t[2];if(r===n&&n===e)return r<8?16:r>248?231:Math.round((r-8)/247*24)+232;return 16+36*Math.round(r/255*5)+6*Math.round(n/255*5)+Math.round(e/255*5)},n.ansi16.rgb=function(t){let r=t%10;if(0===r||7===r)return t>50&&(r+=3.5),r=r/10.5*255,[r,r,r];const n=.5*(1+~~(t>50));return[(1&r)*n*255,(r>>1&1)*n*255,(r>>2&1)*n*255]},n.ansi256.rgb=function(t){if(t>=232){const r=10*(t-232)+8;return[r,r,r]}let r;t-=16;return[Math.floor(t/36)/5*255,Math.floor((r=t%36)/6)/5*255,r%6/5*255]},n.rgb.hex=function(t){const r=(((255&Math.round(t[0]))<<16)+((255&Math.round(t[1]))<<8)+(255&Math.round(t[2]))).toString(16).toUpperCase();return"000000".substring(r.length)+r},n.hex.rgb=function(t){const r=t.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!r)return[0,0,0];let n=r[0];3===r[0].length&&(n=n.split("").map((t=>t+t)).join(""));const e=parseInt(n,16);return[e>>16&255,e>>8&255,255&e]},n.rgb.hcg=function(t){const r=t[0]/255,n=t[1]/255,e=t[2]/255,o=Math.max(Math.max(r,n),e),a=Math.min(Math.min(r,n),e),s=o-a;let i,c;return i=s<1?a/(1-s):0,c=s<=0?0:o===r?(n-e)/s%6:o===n?2+(e-r)/s:4+(r-n)/s,c/=6,c%=1,[360*c,100*s,100*i]},n.hsl.hcg=function(t){const r=t[1]/100,n=t[2]/100,e=n<.5?2*r*n:2*r*(1-n);let o=0;return e<1&&(o=(n-.5*e)/(1-e)),[t[0],100*e,100*o]},n.hsv.hcg=function(t){const r=t[1]/100,n=t[2]/100,e=r*n;let o=0;return e<1&&(o=(n-e)/(1-e)),[t[0],100*e,100*o]},n.hcg.rgb=function(t){const r=t[0]/360,n=t[1]/100,e=t[2]/100;if(0===n)return[255*e,255*e,255*e];const o=[0,0,0],a=r%1*6,s=a%1,i=1-s;let c=0;switch(Math.floor(a)){case 0:o[0]=1,o[1]=s,o[2]=0;break;case 1:o[0]=i,o[1]=1,o[2]=0;break;case 2:o[0]=0,o[1]=1,o[2]=s;break;case 3:o[0]=0,o[1]=i,o[2]=1;break;case 4:o[0]=s,o[1]=0,o[2]=1;break;default:o[0]=1,o[1]=0,o[2]=i}return c=(1-n)*e,[255*(n*o[0]+c),255*(n*o[1]+c),255*(n*o[2]+c)]},n.hcg.hsv=function(t){const r=t[1]/100,n=r+t[2]/100*(1-r);let e=0;return n>0&&(e=r/n),[t[0],100*e,100*n]},n.hcg.hsl=function(t){const r=t[1]/100,n=t[2]/100*(1-r)+.5*r;let e=0;return n>0&&n<.5?e=r/(2*n):n>=.5&&n<1&&(e=r/(2*(1-n))),[t[0],100*e,100*n]},n.hcg.hwb=function(t){const r=t[1]/100,n=r+t[2]/100*(1-r);return[t[0],100*(n-r),100*(1-n)]},n.hwb.hcg=function(t){const r=t[1]/100,n=1-t[2]/100,e=n-r;let o=0;return e<1&&(o=(n-e)/(1-e)),[t[0],100*e,100*o]},n.apple.rgb=function(t){return[t[0]/65535*255,t[1]/65535*255,t[2]/65535*255]},n.rgb.apple=function(t){return[t[0]/255*65535,t[1]/255*65535,t[2]/255*65535]},n.gray.rgb=function(t){return[t[0]/100*255,t[0]/100*255,t[0]/100*255]},n.gray.hsl=function(t){return[0,0,t[0]]},n.gray.hsv=n.gray.hsl,n.gray.hwb=function(t){return[0,100,t[0]]},n.gray.cmyk=function(t){return[0,0,0,t[0]]},n.gray.lab=function(t){return[t[0],0,0]},n.gray.hex=function(t){const r=255&Math.round(t[0]/100*255),n=((r<<16)+(r<<8)+r).toString(16).toUpperCase();return"000000".substring(n.length)+n},n.rgb.gray=function(t){return[(t[0]+t[1]+t[2])/3/255*100]},i}function m(){if(l)return u;l=1;const t=y();function r(r){const n=function(){const r={},n=Object.keys(t);for(let t=n.length,e=0;e<t;e++)r[n[e]]={distance:-1,parent:null};return r}(),e=[r];for(n[r].distance=0;e.length;){const r=e.pop(),o=Object.keys(t[r]);for(let t=o.length,a=0;a<t;a++){const t=o[a],s=n[t];-1===s.distance&&(s.distance=n[r].distance+1,s.parent=r,e.unshift(t))}}return n}function n(t,r){return function(n){return r(t(n))}}function e(r,e){const o=[e[r].parent,r];let a=t[e[r].parent][r],s=e[r].parent;for(;e[s].parent;)o.unshift(e[s].parent),a=n(t[e[s].parent][s],a),s=e[s].parent;return a.conversion=o,a}return u=function(t){const n=r(t),o={},a=Object.keys(n);for(let t=a.length,r=0;r<t;r++){const t=a[r];null!==n[t].parent&&(o[t]=e(t,n))}return o}}"function"==typeof SuppressedError&&SuppressedError;var v=function(){if(p)return h;p=1;const t=y(),r=m(),n={};return Object.keys(t).forEach((e=>{n[e]={},Object.defineProperty(n[e],"channels",{value:t[e].channels}),Object.defineProperty(n[e],"labels",{value:t[e].labels});const o=r(e);Object.keys(o).forEach((t=>{const r=o[t];n[e][t]=function(t){const r=function(...r){const n=r[0];if(null==n)return n;n.length>1&&(r=n);const e=t(r);if("object"==typeof e)for(let t=e.length,r=0;r<t;r++)e[r]=Math.round(e[r]);return e};return"conversion"in t&&(r.conversion=t.conversion),r}(r),n[e][t].raw=function(t){const r=function(...r){const n=r[0];return null==n?n:(n.length>1&&(r=n),t(r))};return"conversion"in t&&(r.conversion=t.conversion),r}(r)}))})),h=n}(),M=d(v),w=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}g(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}(o,t),o.prototype.toInvert=function(){var t=this.toJson();t.r,t.g,t.b,t.a;return new o(255-this.r,255-this.g,255-this.b,1-this.a)},o.prototype.clone=function(){var t=new o(this.r,this.g,this.b,this.a);return t._outColorPrecision=this._outColorPrecision,t._outAlphaPrecision=this._outAlphaPrecision,t},o.prototype.equals=function(t){if(this===(t=o.parseColor(t)))return!0;var r=this.toJson(),n=t.toJson();return r.r===n.r&&r.g===n.g&&r.b===n.g&&r.a===n.a},o.prototype.add=function(r,n){void 0===n&&(n=!0);var e=o.parseColor(r);return t.prototype.add.call(this,e,n)},o.prototype.subtract=function(r,n){void 0===n&&(n=!0);var e=o.parseColor(r);return t.prototype.subtract.call(this,e,n)},o.prototype.multiply=function(r,n){void 0===n&&(n=!0);var e=o.parseColor(r);return t.prototype.multiply.call(this,e,n)},o.prototype.divide=function(r,n){void 0===n&&(n=!0);var e=o.parseColor(r);return t.prototype.divide.call(this,e,n)},o.parseColor=function(t){return t instanceof b?t.clone():o.parseCssColorStr(t)},o.parseCssColorStr=function(t){return r.type("color",t,"string"),o.parseHEX(t)||o.parseRGBA(t)||o.parseKeyWord(t)||o.parseHSLA(t)||o.parseHWB(t)},o.parseKeyWord=function(t){var r=f.clearStrSpace(t),n=M.keyword.rgb(r);return n&&o.fromArray(n)},o.parseHSLA=function(t){var r=f.clearStrSpace(t),n=f.parseHSLA(r);if(!n){var e=f.trimStr(t);n=f.parseHSLA2(e)}return n&&o.fromHSL(n[0],n[1],n[2],n[3])},o.parseHWB=function(t){var r=f.trimStr(t),n=f.parseHWB(r);return n&&o.fromHWB(n[0],n[1],n[2],n[3])},o.fromHSL=function(t,r,a,s){var i=M.hsl.rgb(e(0,360,t),e(0,100,100*r),e(0,100,100*a));return new o(i[0],i[1],i[2],n(Number(s),1))},o.fromHWB=function(t,r,a,s){var i=M.hwb.rgb(e(0,360,t),e(0,100,100*r),e(0,100,100*a));return new o(i[0],i[1],i[2],n(Number(s),1))},o.parseHEX=function(t){var r=f.clearStrSpace(t),n=f.parse3BitsHEX(r);return n||(n=f.parse6BitsHEX(r)),n&&o.fromArray(n)},o.parseRGBA=function(t){var r=f.clearStrSpace(t),n=f.parseRGBA(r);if(!n){var e=f.trimStr(t);n=f.parseRGBA2(e)}return n&&o.fromArray(n)},o.fromJson=function(t){return new o(t.r,t.g,t.b,t.a)},o.fromArray=function(t){return new o(t[0],t[1],t[2],t[3])},o.fromRandom=function(t,r){return void 0===t&&(t=new o(0,0,0,1)),void 0===r&&(r=new o(255,255,255,1)),t=o.parseColor(t),r=o.parseColor(r),new o(Math.random()*Math.abs(r.r-t.r)+Math.min(t.r,r.r),Math.random()*Math.abs(r.g-t.g)+Math.min(t.g,r.g),Math.random()*Math.abs(r.b-t.b)+Math.min(t.b,r.b),Math.random()*Math.abs(r.a-t.a)+Math.min(t.a,r.a))},o.fromNormalize=function(t){var r=255*t[0],n=255*t[1],e=255*t[2],a=t[3];return o.fromArray([r,n,e,a])},o.lerp=function(t,r){var n=Object.keys(t).map((function(t){return Number(t)}));n.sort((function(t,r){return t-r}));for(var e=0;e<n.length;e++)if(r<=n[e]){var a=n[e-1],s=n[e];if(void 0===a)return o.parseColor(t[s]);var i=(r-a)/(s-a),c=o.parseColor(t[a]);return o.parseColor(t[s]).subtract(c).multiplyByScalar(i).add(c)}return o.parseColor(t[n[n.length-1]]).limitColor()},o}(b);t.CssColorParser=b,t.CssColorParserPlus=w}));
package/package.json CHANGED
@@ -1,59 +1,59 @@
1
- {
2
- "name": "css-color-parser-h",
3
- "version": "3.0.5",
4
- "description": "A tool for parsing css color",
5
- "main": "lib/css-color-parser-h.cjs.js",
6
- "module": "lib/css-color-parser-h.esm.js",
7
- "jsnext:main": "lib/css-color-parser-h.esm.js",
8
- "browser": "lib/css-color-parser-h.umd.js",
9
- "types": "@types/css-color-parser-h.d.ts",
10
- "exports": {
11
- ".": {
12
- "types": "./@types/index.d.ts",
13
- "import": "./lib/css-color-parser-h.esm.js",
14
- "require": "./lib/css-color-parser-h.cjs.js"
15
- },
16
- "./package.json": "./package.json"
17
- },
18
- "files": [
19
- "lib",
20
- "@types",
21
- "example.html"
22
- ],
23
- "type": "module",
24
- "scripts": {
25
- "build": "rollup -c rollup.config.mjs",
26
- "test": "npm run build && jest",
27
- "test-c": "jest --coverage"
28
- },
29
- "repository": {
30
- "type": "git",
31
- "url": "https://gitee.com/roman_123/css-color-parser.git"
32
- },
33
- "keywords": [
34
- "html",
35
- "css",
36
- "color",
37
- "parser",
38
- "conversion"
39
- ],
40
- "author": "roman_123",
41
- "license": "ISC",
42
- "dependencies": {
43
- "color-convert": "^2.0.1"
44
- },
45
- "devDependencies": {
46
- "@babel/plugin-transform-runtime": "^7.26.10",
47
- "@babel/preset-env": "^7.26.9",
48
- "@rollup/plugin-babel": "^6.0.4",
49
- "@rollup/plugin-commonjs": "^28.0.3",
50
- "@rollup/plugin-node-resolve": "^16.0.1",
51
- "@rollup/plugin-terser": "^0.4.4",
52
- "@rollup/plugin-typescript": "^12.1.2",
53
- "rollup": "^4.37.0",
54
- "rollup-plugin-copy": "^3.5.0",
55
- "tslib": "^2.8.1",
56
- "typescript": "^5.8.2",
57
- "jest": "^29.7.0"
58
- }
59
- }
1
+ {
2
+ "name": "css-color-parser-h",
3
+ "version": "3.0.10",
4
+ "description": "A tool for parsing css color",
5
+ "main": "lib/css-color-parser-h.cjs.js",
6
+ "module": "lib/css-color-parser-h.esm.js",
7
+ "jsnext:main": "lib/css-color-parser-h.esm.js",
8
+ "browser": "lib/css-color-parser-h.umd.js",
9
+ "types": "@types/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./@types/index.d.ts",
13
+ "import": "./lib/css-color-parser-h.esm.js",
14
+ "require": "./lib/css-color-parser-h.cjs.js"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "files": [
19
+ "lib",
20
+ "@types",
21
+ "example.html"
22
+ ],
23
+ "type": "module",
24
+ "scripts": {
25
+ "build": "rollup -c rollup.config.mjs",
26
+ "test": "npm run build && jest",
27
+ "test-c": "jest --coverage"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://gitee.com/roman_123/css-color-parser.git"
32
+ },
33
+ "keywords": [
34
+ "html",
35
+ "css",
36
+ "color",
37
+ "parser",
38
+ "conversion"
39
+ ],
40
+ "author": "roman_123",
41
+ "license": "ISC",
42
+ "dependencies": {
43
+ "color-convert": "^2.0.1"
44
+ },
45
+ "devDependencies": {
46
+ "@babel/plugin-transform-runtime": "^7.26.10",
47
+ "@babel/preset-env": "^7.26.9",
48
+ "@rollup/plugin-babel": "^6.0.4",
49
+ "@rollup/plugin-commonjs": "^28.0.3",
50
+ "@rollup/plugin-node-resolve": "^16.0.1",
51
+ "@rollup/plugin-terser": "^0.4.4",
52
+ "@rollup/plugin-typescript": "^12.1.2",
53
+ "rollup": "^4.37.0",
54
+ "rollup-plugin-copy": "^3.5.0",
55
+ "tslib": "^2.8.1",
56
+ "typescript": "^5.8.2",
57
+ "jest": "^29.7.0"
58
+ }
59
+ }
package/readme.md CHANGED
@@ -26,14 +26,14 @@ You can then use it as a window global or as an CommonJs module
26
26
  new Parser.CssColorParserPlus(255,255,255,1)
27
27
 
28
28
  // commonJs
29
- const {CssColorParser, CssColorParserPlus} = require('css-color-parser-h')
29
+ const {CssColorParserPlus} = require('css-color-parser-h')
30
30
 
31
31
  // es6 module 使用ES6模块,需要在项目中集成webpack等打包工具
32
32
  /**
33
33
  * If you want to use this library by esm, you must ensure that your project
34
34
  * has used webpack, vite, rollup or other packaging tools.
35
35
  */
36
- import {CssColorParser, CssColorParserPlus} from 'css-color-parser-h'
36
+ import {CssColorParserPlus} from 'css-color-parser-h'
37
37
 
38
38
  //parse from '#4c90f0cc' to: CssColorParser { r: 76, g: 144, b: 240, a: 0.8 }
39
39
  CssColorParserPlus.parseColor('#4c90f0cc')
@@ -79,6 +79,8 @@ colorParser.addNumberForRGB(num: number): CssColorParserPlus;
79
79
  colorParser.addNumberForAlpha(num: number): CssColorParserPlus;
80
80
  colorParser.clone():CssColorParserPlus
81
81
  colorParser.equals(color: CssColorParserPlus):boolean
82
+ // 将颜色限制在0-255之间
83
+ colorParser.limitColor(): CssColorParserPlus
82
84
  // 静态方法
83
85
  CssColorParserPlus.parseKeyWord(v: string): CssColorParserPlus
84
86
  CssColorParserPlus.parseHEX(v: string): CssColorParserPlus
@@ -93,6 +95,8 @@ CssColorParserPlus.fromRandom(color1: string | CssColorParser,color2: string | C
93
95
  CssColorParserPlus.fromJson(json: ColorJson): CssColorParserPlus
94
96
  CssColorParserPlus.fromArray(color: Array<number>): CssColorParserPlus
95
97
  CssColorParserPlus.fromNormalize(colorArr: [number, number, number, number]): CssColorParserPlus;
98
+ // 计算颜色插值
99
+ CssColorParserPlus.lerp(opt: ColorLerpOpt, value: number): CssColorParserPlus
96
100
  ```
97
101
 
98
102
  ## Example
@@ -132,4 +136,6 @@ const res = CssColorParserPlus.parseColor('#000').add('red').subtract('rgba(10,2
132
136
  console.log(res)
133
137
  // 归一化
134
138
  CssColorParserPlus.fromArray([100, 200, 0, 0.552]).toNormalize() // { r: 0.39, g: 0.78, b: 0, a: 0.55 }
139
+ // 计算插值
140
+ CssColorParserPlus.lerp({0: "rgba(255, 255, 0, 1)",0.5: "rgba(0, 255, 0, 1)", 1: "rgba(255, 0, 0, 1)"}, 0.8) // CssColorParser { r: 153, g: 102, b: 0, a: 1 }
135
141
  ```