css-color-parser-h 3.0.5 → 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.

@@ -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: 返回取反色后的新的实例
@@ -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
@@ -17,7 +17,7 @@
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>
@@ -30,6 +30,8 @@
30
30
  console.log(cssColorParser.toRGBA())
31
31
  cssColorParser.subtract('blue', false)
32
32
  console.log(cssColorParser.toRGBA())
33
+ const lerpedColor = Parser.CssColorParserPlus.lerp({0: "rgba(255, 255, 0, 1)",0.5: "rgba(0, 255, 0, 1)",1: "rgba(255, 0, 0, 1)"}, 0.8)
34
+ console.log(lerpedColor)
33
35
  </script>
34
36
  </body>
35
37
  </html>
@@ -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
@@ -428,7 +444,7 @@ var CssColorParser = /** @class */ (function () {
428
444
  var g = this.g * scalar;
429
445
  var b = this.b * scalar;
430
446
  var a = isSetAlpha ? this.a * scalar : this.a;
431
- return this.setColor(r, g, b, a);
447
+ return this.setColor(r, g, b, a, false);
432
448
  };
433
449
  /**
434
450
  * @description: 除以倍数
@@ -442,7 +458,7 @@ var CssColorParser = /** @class */ (function () {
442
458
  var g = this.g / scalar;
443
459
  var b = this.b / scalar;
444
460
  var a = isSetAlpha ? this.a / scalar : this.a;
445
- return this.setColor(r, g, b, a);
461
+ return this.setColor(r, g, b, a, false);
446
462
  };
447
463
  /**
448
464
  * @description: 实例相加
@@ -456,7 +472,7 @@ var CssColorParser = /** @class */ (function () {
456
472
  var g = this.g + colorParser.g;
457
473
  var b = this.b + colorParser.b;
458
474
  var a = isSetAlpha ? this.a + colorParser.a : this.a;
459
- return this.setColor(r, g, b, a);
475
+ return this.setColor(r, g, b, a, false);
460
476
  };
461
477
  /**
462
478
  * @description: 实例相减
@@ -470,7 +486,7 @@ var CssColorParser = /** @class */ (function () {
470
486
  var g = this.g - colorParser.g;
471
487
  var b = this.b - colorParser.b;
472
488
  var a = isSetAlpha ? this.a - colorParser.a : this.a;
473
- return this.setColor(r, g, b, a);
489
+ return this.setColor(r, g, b, a, false);
474
490
  };
475
491
  /**
476
492
  * @description: 实例相乘
@@ -484,7 +500,7 @@ var CssColorParser = /** @class */ (function () {
484
500
  var g = this.g * colorParser.g;
485
501
  var b = this.b * colorParser.b;
486
502
  var a = isSetAlpha ? this.a * colorParser.a : this.a;
487
- return this.setColor(r, g, b, a);
503
+ return this.setColor(r, g, b, a, false);
488
504
  };
489
505
  /**
490
506
  * @description: 实例相除
@@ -498,7 +514,7 @@ var CssColorParser = /** @class */ (function () {
498
514
  var g = this.g / colorParser.g;
499
515
  var b = this.b / colorParser.b;
500
516
  var a = isSetAlpha ? this.a / colorParser.a : this.a;
501
- return this.setColor(r, g, b, a);
517
+ return this.setColor(r, g, b, a, false);
502
518
  };
503
519
  /**
504
520
  * @description: 颜色RGB加上数字
@@ -886,6 +902,33 @@ var CssColorParserPlus = /** @class */ (function (_super) {
886
902
  var a = colorArr[3];
887
903
  return CssColorParserPlus.fromArray([r, g, b, a]);
888
904
  };
905
+ /**
906
+ * @description: 获取颜色插值
907
+ * @param opt ColorLerpOpt
908
+ * @param value number
909
+ * @returns {CssColorParserPlus}
910
+ * @example: CssColorParserPlus.lerp({0: "rgba(255, 255, 0, 1)",0.5: "rgba(0, 255, 0, 1)",1: "rgba(255, 0, 0, 1)"}, 0.8)
911
+ */
912
+ CssColorParserPlus.lerp = function (opt, value) {
913
+ var keys = Object.keys(opt).map(function (k) { return Number(k); });
914
+ keys.sort(function (a, b) { return a - b; });
915
+ for (var i = 0; i < keys.length; i++) {
916
+ if (value <= keys[i]) {
917
+ var last = keys[i - 1];
918
+ var next = keys[i];
919
+ if (last === undefined) {
920
+ return CssColorParserPlus.parseColor(opt[next]);
921
+ }
922
+ else {
923
+ var ratio = (value - last) / (next - last);
924
+ var color1 = CssColorParserPlus.parseColor(opt[last]);
925
+ var color2 = CssColorParserPlus.parseColor(opt[next]);
926
+ return color2.subtract(color1).multiplyByScalar(ratio).add(color1);
927
+ }
928
+ }
929
+ }
930
+ return CssColorParserPlus.parseColor(opt[keys[keys.length - 1]]).limitColor();
931
+ };
889
932
  return CssColorParserPlus;
890
933
  }(CssColorParser));
891
934
 
@@ -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
@@ -426,7 +442,7 @@ var CssColorParser = /** @class */ (function () {
426
442
  var g = this.g * scalar;
427
443
  var b = this.b * scalar;
428
444
  var a = isSetAlpha ? this.a * scalar : this.a;
429
- return this.setColor(r, g, b, a);
445
+ return this.setColor(r, g, b, a, false);
430
446
  };
431
447
  /**
432
448
  * @description: 除以倍数
@@ -440,7 +456,7 @@ var CssColorParser = /** @class */ (function () {
440
456
  var g = this.g / scalar;
441
457
  var b = this.b / scalar;
442
458
  var a = isSetAlpha ? this.a / scalar : this.a;
443
- return this.setColor(r, g, b, a);
459
+ return this.setColor(r, g, b, a, false);
444
460
  };
445
461
  /**
446
462
  * @description: 实例相加
@@ -454,7 +470,7 @@ var CssColorParser = /** @class */ (function () {
454
470
  var g = this.g + colorParser.g;
455
471
  var b = this.b + colorParser.b;
456
472
  var a = isSetAlpha ? this.a + colorParser.a : this.a;
457
- return this.setColor(r, g, b, a);
473
+ return this.setColor(r, g, b, a, false);
458
474
  };
459
475
  /**
460
476
  * @description: 实例相减
@@ -468,7 +484,7 @@ var CssColorParser = /** @class */ (function () {
468
484
  var g = this.g - colorParser.g;
469
485
  var b = this.b - colorParser.b;
470
486
  var a = isSetAlpha ? this.a - colorParser.a : this.a;
471
- return this.setColor(r, g, b, a);
487
+ return this.setColor(r, g, b, a, false);
472
488
  };
473
489
  /**
474
490
  * @description: 实例相乘
@@ -482,7 +498,7 @@ var CssColorParser = /** @class */ (function () {
482
498
  var g = this.g * colorParser.g;
483
499
  var b = this.b * colorParser.b;
484
500
  var a = isSetAlpha ? this.a * colorParser.a : this.a;
485
- return this.setColor(r, g, b, a);
501
+ return this.setColor(r, g, b, a, false);
486
502
  };
487
503
  /**
488
504
  * @description: 实例相除
@@ -496,7 +512,7 @@ var CssColorParser = /** @class */ (function () {
496
512
  var g = this.g / colorParser.g;
497
513
  var b = this.b / colorParser.b;
498
514
  var a = isSetAlpha ? this.a / colorParser.a : this.a;
499
- return this.setColor(r, g, b, a);
515
+ return this.setColor(r, g, b, a, false);
500
516
  };
501
517
  /**
502
518
  * @description: 颜色RGB加上数字
@@ -884,6 +900,33 @@ var CssColorParserPlus = /** @class */ (function (_super) {
884
900
  var a = colorArr[3];
885
901
  return CssColorParserPlus.fromArray([r, g, b, a]);
886
902
  };
903
+ /**
904
+ * @description: 获取颜色插值
905
+ * @param opt ColorLerpOpt
906
+ * @param value number
907
+ * @returns {CssColorParserPlus}
908
+ * @example: CssColorParserPlus.lerp({0: "rgba(255, 255, 0, 1)",0.5: "rgba(0, 255, 0, 1)",1: "rgba(255, 0, 0, 1)"}, 0.8)
909
+ */
910
+ CssColorParserPlus.lerp = function (opt, value) {
911
+ var keys = Object.keys(opt).map(function (k) { return Number(k); });
912
+ keys.sort(function (a, b) { return a - b; });
913
+ for (var i = 0; i < keys.length; i++) {
914
+ if (value <= keys[i]) {
915
+ var last = keys[i - 1];
916
+ var next = keys[i];
917
+ if (last === undefined) {
918
+ return CssColorParserPlus.parseColor(opt[next]);
919
+ }
920
+ else {
921
+ var ratio = (value - last) / (next - last);
922
+ var color1 = CssColorParserPlus.parseColor(opt[last]);
923
+ var color2 = CssColorParserPlus.parseColor(opt[next]);
924
+ return color2.subtract(color1).multiplyByScalar(ratio).add(color1);
925
+ }
926
+ }
927
+ }
928
+ return CssColorParserPlus.parseColor(opt[keys[keys.length - 1]]).limitColor();
929
+ };
887
930
  return CssColorParserPlus;
888
931
  }(CssColorParser));
889
932
 
@@ -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,e){var n=typeof r;if(n!==e)throw new Error("Expected ".concat(t," to be typeof ").concat(e,", actual typeof was ").concat(n))},t.types=function(t,r,e){var n=typeof r;if(!e.includes(n))throw new Error("Expected ".concat(t," to be typeof ").concat(e.join("|"),", actual typeof was ").concat(n))},t.numValue=function(r,e,n,o){t.numMinValue(r,e,n),t.numMaxValue(r,e,o)},t.numMinValue=function(t,r,e){if(r<e)throw new Error("Expected ".concat(t," to > ").concat(e,", actual value was ").concat(r))},t.numMaxValue=function(t,r,e){if(r>e)throw new Error("Expected ".concat(t," to < ").concat(e,", actual value was ").concat(r))},t.numIsInt=function(t,r,e){var n=Math.floor(r)===r;if(n!==e)throw new Error("Expected ".concat(t," to ").concat(e?"Integer":"Float",", actual value was ").concat(n?"Integer":"Float"))},t}();function e(t,r){return null==t||isNaN(t)&&"number"==typeof r?r:t}function n(t,r,e){return e>r?e=r:e<t&&(e=t),e}function o(t,r){void 0===t&&(t=0);var e=Math.pow(10,r);return Math.round(t*e)/e}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 n=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i.exec(r);if(n){var o=e(n[4],"f");return[t._parseResStrForRgb(parseInt(n[1]+n[1],16)),t._parseResStrForRgb(parseInt(n[2]+n[2],16)),t._parseResStrForRgb(parseInt(n[3]+n[3],16)),t._parsePercent(parseInt(o+o,16)/255)]}return null},t.parse6BitsHEX=function(r){var n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(r);if(n){var o=e(n[4],"ff");return[t._parseResStrForRgb(parseInt(n[1],16)),t._parseResStrForRgb(parseInt(n[2],16)),t._parseResStrForRgb(parseInt(n[3],16)),t._parsePercent(parseInt(o,16)/255)]}return null},t.parseRGBA=function(r){var e=/^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(r);return e?[t._parseResStrForRgb(e[1]),t._parseResStrForRgb(e[2]),t._parseResStrForRgb(e[3]),t._parsePercent(e[4])]:null},t.parseHSLA=function(r){var e=/^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(r);return e?[t._parseResStrForHue(e[1]),t._parsePercent(e[2]),t._parsePercent(e[3]),t._parsePercent(e[4])]:null},t.parseHWB=function(r){var e=/^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return e?[t._parseResStrForHue(e[1]),t._parsePercent(e[2]),t._parsePercent(e[3]),t._parsePercent(e[4])]:null},t.parseRGBA2=function(r){var e=/^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return e?[t._parseResStrForRgb(e[1]),t._parseResStrForRgb(e[2]),t._parseResStrForRgb(e[3]),t._parsePercent(e[4])]:null},t.parseHSLA2=function(r){var e=/^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(r);return e?[t._parseResStrForHue(e[1]),t._parsePercent(e[2]),t._parsePercent(e[3]),t._parsePercent(e[4])]:null},t._parseResStrForRgb=function(t){return"string"==typeof t&&(t=parseFloat(t)/("%"===t.substr(-1)?100/255:1)),isNaN(t)&&(t=1),n(0,255,t)},t._parseResStrForHue=function(t){return"string"==typeof t&&(t=parseFloat(t)),isNaN(t)&&(t=0),n(0,360,t)},t._parsePercent=function(t){return"string"==typeof t&&(t=parseFloat(t)/("%"===t.substr(-1)?100:1)),isNaN(t)&&(t=1),n(0,1,t)},t}(),b=function(){function t(t,r,e,n){this.r=255,this.g=255,this.b=255,this.a=1,this._outColorPrecision=2,this._outAlphaPrecision=2,this.setColor(t,r,e,n)}return t.prototype.setOutPrecision=function(t,e){return r.type("colorPrecision",t,"number"),r.type("outAlphaPrecision",e,"number"),r.numMinValue("colorPrecision",t,0),r.numMinValue("outAlphaPrecision",e,0),r.numIsInt("colorPrecision",t,!0),r.numIsInt("outAlphaPrecision",e,!0),this._outColorPrecision=t,this._outAlphaPrecision=e,this},t.prototype.setColor=function(t,r,o,a,s){return void 0===s&&(s=!0),s?(this.r=n(0,255,e(Number(t),0)),this.g=n(0,255,e(Number(r),0)),this.b=n(0,255,e(Number(o),0)),this.a=n(0,1,e(Number(a),1))):(this.r=e(Number(t),0),this.g=e(Number(r),0),this.b=e(Number(o),0),this.a=e(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=n(0,1,e(Number(t),1)),this},t.prototype.setRed=function(t){return this.r=n(0,255,e(Number(t),0)),this},t.prototype.setGreen=function(t){return this.g=n(0,255,e(Number(t),0)),this},t.prototype.setBlue=function(t){return this.b=n(0,255,e(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 e=t.g.toString(16);e.length<2&&(e="0".concat(e));var n=t.b.toString(16);if(n.length<2&&(n="0".concat(n)),this.a<1){var o=parseInt((255*this.a).toFixed()).toString(16);return o.length<2&&(o="0".concat(o)),"#".concat(r).concat(e).concat(n).concat(o)}return"#".concat(r).concat(e).concat(n)},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(),e=t.toJson();return r.r===e.r&&r.g===e.g&&r.b===e.g&&r.a===e.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 e=this.r*t,n=this.g*t,o=this.b*t,a=r?this.a*t:this.a;return this.setColor(e,n,o,a,!1)},t.prototype.divideByScalar=function(t,r){void 0===r&&(r=!0);var e=this.r/t,n=this.g/t,o=this.b/t,a=r?this.a/t:this.a;return this.setColor(e,n,o,a,!1)},t.prototype.add=function(t,r){void 0===r&&(r=!0);var e=this.r+t.r,n=this.g+t.g,o=this.b+t.b,a=r?this.a+t.a:this.a;return this.setColor(e,n,o,a,!1)},t.prototype.subtract=function(t,r){void 0===r&&(r=!0);var e=this.r-t.r,n=this.g-t.g,o=this.b-t.b,a=r?this.a-t.a:this.a;return this.setColor(e,n,o,a,!1)},t.prototype.multiply=function(t,r){void 0===r&&(r=!0);var e=this.r*t.r,n=this.g*t.g,o=this.b*t.b,a=r?this.a*t.a:this.a;return this.setColor(e,n,o,a,!1)},t.prototype.divide=function(t,r){void 0===r&&(r=!0);var e=this.r/t.r,n=this.g/t.g,o=this.b/t.b,a=r?this.a/t.a:this.a;return this.setColor(e,n,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 e=f.clearStrSpace(r),n=f.parse3BitsHEX(e);return n||(n=f.parse6BitsHEX(e)),n&&t.fromArray(n)},t.parseRGBA=function(r){var e=f.clearStrSpace(r),n=f.parseRGBA(e);if(!n){var o=f.trimStr(r);n=f.parseRGBA2(o)}return n&&t.fromArray(n)},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,e){return new t(Math.random()*Math.abs(e.r-r.r)+Math.min(r.r,e.r),Math.random()*Math.abs(e.g-r.g)+Math.min(r.g,e.g),Math.random()*Math.abs(e.b-r.b)+Math.min(r.b,e.b),Math.random()*Math.abs(e.a-r.a)+Math.min(r.a,e.a))},t.fromNormalize=function(r){var e=255*r[0],n=255*r[1],o=255*r[2],a=r[3];return t.fromArray([e,n,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 e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])},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 e of Object.keys(t))r[t[e]]=e;const e={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=e;for(const t of Object.keys(e)){if(!("channels"in e[t]))throw new Error("missing channels property: "+t);if(!("labels"in e[t]))throw new Error("missing channel labels property: "+t);if(e[t].labels.length!==e[t].channels)throw new Error("channel and label counts mismatch: "+t);const{channels:r,labels:n}=e[t];delete e[t].channels,delete e[t].labels,Object.defineProperty(e[t],"channels",{value:r}),Object.defineProperty(e[t],"labels",{value:n})}return e.rgb.hsl=function(t){const r=t[0]/255,e=t[1]/255,n=t[2]/255,o=Math.min(r,e,n),a=Math.max(r,e,n),s=a-o;let i,c;a===o?i=0:r===a?i=(e-n)/s:e===a?i=2+(n-r)/s:n===a&&(i=4+(r-e)/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]},e.rgb.hsv=function(t){let r,e,n,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),e=h(i),n=h(c),s===u?o=n-e:i===u?o=1/3+r-n:c===u&&(o=2/3+e-r),o<0?o+=1:o>1&&(o-=1)),[360*o,100*a,100*u]},e.rgb.hwb=function(t){const r=t[0],n=t[1];let o=t[2];const a=e.rgb.hsl(t)[0],s=1/255*Math.min(r,Math.min(n,o));return o=1-1/255*Math.max(r,Math.max(n,o)),[a,100*s,100*o]},e.rgb.cmyk=function(t){const r=t[0]/255,e=t[1]/255,n=t[2]/255,o=Math.min(1-r,1-e,1-n);return[100*((1-r-o)/(1-o)||0),100*((1-e-o)/(1-o)||0),100*((1-n-o)/(1-o)||0),100*o]},e.rgb.keyword=function(e){const n=r[e];if(n)return n;let o,a=1/0;for(const r of Object.keys(t)){const n=t[r],c=(i=n,((s=e)[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},e.keyword.rgb=function(r){return t[r]},e.rgb.xyz=function(t){let r=t[0]/255,e=t[1]/255,n=t[2]/255;r=r>.04045?((r+.055)/1.055)**2.4:r/12.92,e=e>.04045?((e+.055)/1.055)**2.4:e/12.92,n=n>.04045?((n+.055)/1.055)**2.4:n/12.92;return[100*(.4124*r+.3576*e+.1805*n),100*(.2126*r+.7152*e+.0722*n),100*(.0193*r+.1192*e+.9505*n)]},e.rgb.lab=function(t){const r=e.rgb.xyz(t);let n=r[0],o=r[1],a=r[2];n/=95.047,o/=100,a/=108.883,n=n>.008856?n**(1/3):7.787*n+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*(n-o),200*(o-a)]},e.hsl.rgb=function(t){const r=t[0]/360,e=t[1]/100,n=t[2]/100;let o,a,s;if(0===e)return s=255*n,[s,s,s];o=n<.5?n*(1+e):n+e-n*e;const i=2*n-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},e.hsl.hsv=function(t){const r=t[0];let e=t[1]/100,n=t[2]/100,o=e;const a=Math.max(n,.01);n*=2,e*=n<=1?n:2-n,o*=a<=1?a:2-a;return[r,100*(0===n?2*o/(a+o):2*e/(n+e)),100*((n+e)/2)]},e.hsv.rgb=function(t){const r=t[0]/60,e=t[1]/100;let n=t[2]/100;const o=Math.floor(r)%6,a=r-Math.floor(r),s=255*n*(1-e),i=255*n*(1-e*a),c=255*n*(1-e*(1-a));switch(n*=255,o){case 0:return[n,c,s];case 1:return[i,n,s];case 2:return[s,n,c];case 3:return[s,i,n];case 4:return[c,s,n];case 5:return[n,s,i]}},e.hsv.hsl=function(t){const r=t[0],e=t[1]/100,n=t[2]/100,o=Math.max(n,.01);let a,s;s=(2-e)*n;const i=(2-e)*o;return a=e*o,a/=i<=1?i:2-i,a=a||0,s/=2,[r,100*a,100*s]},e.hwb.rgb=function(t){const r=t[0]/360;let e=t[1]/100,n=t[2]/100;const o=e+n;let a;o>1&&(e/=o,n/=o);const s=Math.floor(6*r),i=1-n;a=6*r-s,1&s&&(a=1-a);const c=e+a*(i-e);let u,l,h;switch(s){default:case 6:case 0:u=i,l=c,h=e;break;case 1:u=c,l=i,h=e;break;case 2:u=e,l=i,h=c;break;case 3:u=e,l=c,h=i;break;case 4:u=c,l=e,h=i;break;case 5:u=i,l=e,h=c}return[255*u,255*l,255*h]},e.cmyk.rgb=function(t){const r=t[0]/100,e=t[1]/100,n=t[2]/100,o=t[3]/100;return[255*(1-Math.min(1,r*(1-o)+o)),255*(1-Math.min(1,e*(1-o)+o)),255*(1-Math.min(1,n*(1-o)+o))]},e.xyz.rgb=function(t){const r=t[0]/100,e=t[1]/100,n=t[2]/100;let o,a,s;return o=3.2406*r+-1.5372*e+-.4986*n,a=-.9689*r+1.8758*e+.0415*n,s=.0557*r+-.204*e+1.057*n,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]},e.xyz.lab=function(t){let r=t[0],e=t[1],n=t[2];r/=95.047,e/=100,n/=108.883,r=r>.008856?r**(1/3):7.787*r+16/116,e=e>.008856?e**(1/3):7.787*e+16/116,n=n>.008856?n**(1/3):7.787*n+16/116;return[116*e-16,500*(r-e),200*(e-n)]},e.lab.xyz=function(t){let r,e,n;e=(t[0]+16)/116,r=t[1]/500+e,n=e-t[2]/200;const o=e**3,a=r**3,s=n**3;return e=o>.008856?o:(e-16/116)/7.787,r=a>.008856?a:(r-16/116)/7.787,n=s>.008856?s:(n-16/116)/7.787,r*=95.047,e*=100,n*=108.883,[r,e,n]},e.lab.lch=function(t){const r=t[0],e=t[1],n=t[2];let o;o=360*Math.atan2(n,e)/2/Math.PI,o<0&&(o+=360);return[r,Math.sqrt(e*e+n*n),o]},e.lch.lab=function(t){const r=t[0],e=t[1],n=t[2]/360*2*Math.PI;return[r,e*Math.cos(n),e*Math.sin(n)]},e.rgb.ansi16=function(t,r=null){const[n,o,a]=t;let s=null===r?e.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(n/255));return 2===s&&(i+=60),i},e.hsv.ansi16=function(t){return e.rgb.ansi16(e.hsv.rgb(t),t[2])},e.rgb.ansi256=function(t){const r=t[0],e=t[1],n=t[2];if(r===e&&e===n)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(e/255*5)+Math.round(n/255*5)},e.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 e=.5*(1+~~(t>50));return[(1&r)*e*255,(r>>1&1)*e*255,(r>>2&1)*e*255]},e.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]},e.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},e.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 e=r[0];3===r[0].length&&(e=e.split("").map((t=>t+t)).join(""));const n=parseInt(e,16);return[n>>16&255,n>>8&255,255&n]},e.rgb.hcg=function(t){const r=t[0]/255,e=t[1]/255,n=t[2]/255,o=Math.max(Math.max(r,e),n),a=Math.min(Math.min(r,e),n),s=o-a;let i,c;return i=s<1?a/(1-s):0,c=s<=0?0:o===r?(e-n)/s%6:o===e?2+(n-r)/s:4+(r-e)/s,c/=6,c%=1,[360*c,100*s,100*i]},e.hsl.hcg=function(t){const r=t[1]/100,e=t[2]/100,n=e<.5?2*r*e:2*r*(1-e);let o=0;return n<1&&(o=(e-.5*n)/(1-n)),[t[0],100*n,100*o]},e.hsv.hcg=function(t){const r=t[1]/100,e=t[2]/100,n=r*e;let o=0;return n<1&&(o=(e-n)/(1-n)),[t[0],100*n,100*o]},e.hcg.rgb=function(t){const r=t[0]/360,e=t[1]/100,n=t[2]/100;if(0===e)return[255*n,255*n,255*n];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-e)*n,[255*(e*o[0]+c),255*(e*o[1]+c),255*(e*o[2]+c)]},e.hcg.hsv=function(t){const r=t[1]/100,e=r+t[2]/100*(1-r);let n=0;return e>0&&(n=r/e),[t[0],100*n,100*e]},e.hcg.hsl=function(t){const r=t[1]/100,e=t[2]/100*(1-r)+.5*r;let n=0;return e>0&&e<.5?n=r/(2*e):e>=.5&&e<1&&(n=r/(2*(1-e))),[t[0],100*n,100*e]},e.hcg.hwb=function(t){const r=t[1]/100,e=r+t[2]/100*(1-r);return[t[0],100*(e-r),100*(1-e)]},e.hwb.hcg=function(t){const r=t[1]/100,e=1-t[2]/100,n=e-r;let o=0;return n<1&&(o=(e-n)/(1-n)),[t[0],100*n,100*o]},e.apple.rgb=function(t){return[t[0]/65535*255,t[1]/65535*255,t[2]/65535*255]},e.rgb.apple=function(t){return[t[0]/255*65535,t[1]/255*65535,t[2]/255*65535]},e.gray.rgb=function(t){return[t[0]/100*255,t[0]/100*255,t[0]/100*255]},e.gray.hsl=function(t){return[0,0,t[0]]},e.gray.hsv=e.gray.hsl,e.gray.hwb=function(t){return[0,100,t[0]]},e.gray.cmyk=function(t){return[0,0,0,t[0]]},e.gray.lab=function(t){return[t[0],0,0]},e.gray.hex=function(t){const r=255&Math.round(t[0]/100*255),e=((r<<16)+(r<<8)+r).toString(16).toUpperCase();return"000000".substring(e.length)+e},e.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 e=function(){const r={},e=Object.keys(t);for(let t=e.length,n=0;n<t;n++)r[e[n]]={distance:-1,parent:null};return r}(),n=[r];for(e[r].distance=0;n.length;){const r=n.pop(),o=Object.keys(t[r]);for(let t=o.length,a=0;a<t;a++){const t=o[a],s=e[t];-1===s.distance&&(s.distance=e[r].distance+1,s.parent=r,n.unshift(t))}}return e}function e(t,r){return function(e){return r(t(e))}}function n(r,n){const o=[n[r].parent,r];let a=t[n[r].parent][r],s=n[r].parent;for(;n[s].parent;)o.unshift(n[s].parent),a=e(t[n[s].parent][s],a),s=n[s].parent;return a.conversion=o,a}return u=function(t){const e=r(t),o={},a=Object.keys(e);for(let t=a.length,r=0;r<t;r++){const t=a[r];null!==e[t].parent&&(o[t]=n(t,e))}return o}}"function"==typeof SuppressedError&&SuppressedError;var v=function(){if(p)return h;p=1;const t=y(),r=m(),e={};return Object.keys(t).forEach((n=>{e[n]={},Object.defineProperty(e[n],"channels",{value:t[n].channels}),Object.defineProperty(e[n],"labels",{value:t[n].labels});const o=r(n);Object.keys(o).forEach((t=>{const r=o[t];e[n][t]=function(t){const r=function(...r){const e=r[0];if(null==e)return e;e.length>1&&(r=e);const n=t(r);if("object"==typeof n)for(let t=n.length,r=0;r<t;r++)n[r]=Math.round(n[r]);return n};return"conversion"in t&&(r.conversion=t.conversion),r}(r),e[n][t].raw=function(t){const r=function(...r){const e=r[0];return null==e?e:(e.length>1&&(r=e),t(r))};return"conversion"in t&&(r.conversion=t.conversion),r}(r)}))})),h=e}(),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 e(){this.constructor=t}g(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}(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(),e=t.toJson();return r.r===e.r&&r.g===e.g&&r.b===e.g&&r.a===e.a},o.prototype.add=function(r,e){void 0===e&&(e=!0);var n=o.parseColor(r);return t.prototype.add.call(this,n,e)},o.prototype.subtract=function(r,e){void 0===e&&(e=!0);var n=o.parseColor(r);return t.prototype.subtract.call(this,n,e)},o.prototype.multiply=function(r,e){void 0===e&&(e=!0);var n=o.parseColor(r);return t.prototype.multiply.call(this,n,e)},o.prototype.divide=function(r,e){void 0===e&&(e=!0);var n=o.parseColor(r);return t.prototype.divide.call(this,n,e)},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),e=M.keyword.rgb(r);return e&&o.fromArray(e)},o.parseHSLA=function(t){var r=f.clearStrSpace(t),e=f.parseHSLA(r);if(!e){var n=f.trimStr(t);e=f.parseHSLA2(n)}return e&&o.fromHSL(e[0],e[1],e[2],e[3])},o.parseHWB=function(t){var r=f.trimStr(t),e=f.parseHWB(r);return e&&o.fromHWB(e[0],e[1],e[2],e[3])},o.fromHSL=function(t,r,a,s){var i=M.hsl.rgb(n(0,360,t),n(0,100,100*r),n(0,100,100*a));return new o(i[0],i[1],i[2],e(Number(s),1))},o.fromHWB=function(t,r,a,s){var i=M.hwb.rgb(n(0,360,t),n(0,100,100*r),n(0,100,100*a));return new o(i[0],i[1],i[2],e(Number(s),1))},o.parseHEX=function(t){var r=f.clearStrSpace(t),e=f.parse3BitsHEX(r);return e||(e=f.parse6BitsHEX(r)),e&&o.fromArray(e)},o.parseRGBA=function(t){var r=f.clearStrSpace(t),e=f.parseRGBA(r);if(!e){var n=f.trimStr(t);e=f.parseRGBA2(n)}return e&&o.fromArray(e)},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],e=255*t[1],n=255*t[2],a=t[3];return o.fromArray([r,e,n,a])},o.lerp=function(t,r){var e=Object.keys(t).map((function(t){return Number(t)}));e.sort((function(t,r){return t-r}));for(var n=0;n<e.length;n++)if(r<=e[n]){var a=e[n-1],s=e[n];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[e[e.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.6",
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
+ }
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
  ```