css-color-parser-h 2.0.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/index.d.ts +219 -143
- package/dist/css-color-parser-h.common.js +272 -154
- package/dist/css-color-parser-h.common.min.js +1 -1
- package/dist/css-color-parser-h.umd.js +741 -154
- package/dist/css-color-parser-h.umd.min.js +1 -1
- package/example.html +9 -47
- package/package.json +1 -1
- package/readme.md +50 -41
|
@@ -52,18 +52,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
52
52
|
// EXPORTS
|
|
53
53
|
__webpack_require__.d(__webpack_exports__, {
|
|
54
54
|
"CssColorParser": function() { return /* reexport */ src_CssColorParser; },
|
|
55
|
-
"
|
|
56
|
-
"fromColorStr": function() { return /* reexport */ fromColorStr; },
|
|
57
|
-
"fromHSL": function() { return /* reexport */ fromHSL; },
|
|
58
|
-
"fromHWB": function() { return /* reexport */ fromHWB; },
|
|
59
|
-
"fromJson": function() { return /* reexport */ fromJson; },
|
|
60
|
-
"fromRandom": function() { return /* reexport */ fromRandom; },
|
|
61
|
-
"parseCssColorStr": function() { return /* reexport */ parseCssColorStr; },
|
|
62
|
-
"parseHEX": function() { return /* reexport */ parseHEX; },
|
|
63
|
-
"parseHSLA": function() { return /* reexport */ parseHSLA; },
|
|
64
|
-
"parseHWB": function() { return /* reexport */ parseHWB; },
|
|
65
|
-
"parseKeyWord": function() { return /* reexport */ parseKeyWord; },
|
|
66
|
-
"parseRGBA": function() { return /* reexport */ parseRGBA; }
|
|
55
|
+
"CssColorParserPlus": function() { return /* reexport */ src_CssColorParserPlus; }
|
|
67
56
|
});
|
|
68
57
|
|
|
69
58
|
;// CONCATENATED MODULE: ./src/utils/common.ts
|
|
@@ -283,12 +272,12 @@ var CssColorStringParser = /** @class */ (function () {
|
|
|
283
272
|
|
|
284
273
|
;// CONCATENATED MODULE: ./src/CssColorParser.ts
|
|
285
274
|
/*
|
|
286
|
-
* @Descripttion:
|
|
275
|
+
* @Descripttion: 颜色解析器(轻量)
|
|
287
276
|
* @version: 1.0.0
|
|
288
277
|
* @Author: roman_123
|
|
289
278
|
* @Date: 2021-01-19 09:22:11
|
|
290
|
-
* @LastEditors:
|
|
291
|
-
* @LastEditTime: 2023-06-
|
|
279
|
+
* @LastEditors: Please set LastEditors
|
|
280
|
+
* @LastEditTime: 2023-06-27 19:01:50
|
|
292
281
|
*/
|
|
293
282
|
|
|
294
283
|
|
|
@@ -448,7 +437,7 @@ var CssColorParser = /** @class */ (function () {
|
|
|
448
437
|
};
|
|
449
438
|
};
|
|
450
439
|
/**
|
|
451
|
-
* @description:
|
|
440
|
+
* @description: 返回取反色后的新的实例
|
|
452
441
|
* @return {CssColorParser}
|
|
453
442
|
*/
|
|
454
443
|
CssColorParser.prototype.toInvert = function () {
|
|
@@ -677,158 +666,287 @@ var CssColorParser = /** @class */ (function () {
|
|
|
677
666
|
}());
|
|
678
667
|
/* harmony default export */ var src_CssColorParser = (CssColorParser);
|
|
679
668
|
|
|
669
|
+
;// CONCATENATED MODULE: external "tslib"
|
|
670
|
+
var external_tslib_namespaceObject = require("tslib");
|
|
680
671
|
;// CONCATENATED MODULE: external "color-convert"
|
|
681
672
|
var external_color_convert_namespaceObject = require("color-convert");
|
|
682
673
|
var external_color_convert_default = /*#__PURE__*/__webpack_require__.n(external_color_convert_namespaceObject);
|
|
683
|
-
;// CONCATENATED MODULE: ./src/
|
|
674
|
+
;// CONCATENATED MODULE: ./src/CssColorParserPlus.ts
|
|
675
|
+
/*
|
|
676
|
+
* @Descripttion: 颜色解析器(增强)
|
|
677
|
+
* @version: 1.0.0
|
|
678
|
+
* @Author: roman_123
|
|
679
|
+
* @Date: 2021-01-19 09:22:11
|
|
680
|
+
* @LastEditors: Please set LastEditors
|
|
681
|
+
* @LastEditTime: 2023-06-27 18:53:31
|
|
682
|
+
*/
|
|
684
683
|
|
|
685
684
|
|
|
686
685
|
|
|
687
686
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
*/
|
|
694
|
-
function parseKeyWord(v) {
|
|
695
|
-
var cssStr = CssColorStringParser.clearStrSpace(v);
|
|
696
|
-
var res = external_color_convert_default().keyword.rgb(cssStr);
|
|
697
|
-
return res && fromArray(res);
|
|
698
|
-
}
|
|
699
|
-
/**
|
|
700
|
-
* @description: 解析16进制字符串
|
|
701
|
-
* @param {string} v
|
|
702
|
-
* @return {CssColorParser}
|
|
703
|
-
* @example: parseHEX('#FFF')
|
|
704
|
-
*/
|
|
705
|
-
function parseHEX(v) {
|
|
706
|
-
return src_CssColorParser.parseHEX(v);
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* @description: 解析RGBA
|
|
710
|
-
* @param {string} v
|
|
711
|
-
* @return {CssColorParser}
|
|
712
|
-
* @example: parseRGBA('rgba(255,255,255,1)')
|
|
713
|
-
*/
|
|
714
|
-
function parseRGBA(v) {
|
|
715
|
-
return src_CssColorParser.parseRGBA(v);
|
|
716
|
-
}
|
|
717
|
-
/**
|
|
718
|
-
* @description: 解析HSLA
|
|
719
|
-
* @param {string} v
|
|
720
|
-
* @return {CssColorParser}
|
|
721
|
-
* @example: parseHSLA('hsla(215,85%,62%,0.8)')
|
|
722
|
-
*/
|
|
723
|
-
function parseHSLA(v) {
|
|
724
|
-
var cssStr = CssColorStringParser.clearStrSpace(v);
|
|
725
|
-
var res = CssColorStringParser.parseHSLA(cssStr);
|
|
726
|
-
if (!res) {
|
|
727
|
-
var cssStr2 = CssColorStringParser.trimStr(v);
|
|
728
|
-
res = CssColorStringParser.parseHSLA2(cssStr2);
|
|
729
|
-
}
|
|
730
|
-
return res && fromHSL(res[0], res[1], res[2], res[3]);
|
|
731
|
-
}
|
|
732
|
-
/**
|
|
733
|
-
* @description: 解析HWB
|
|
734
|
-
* @param {string} v
|
|
735
|
-
* @return {CssColorParser}
|
|
736
|
-
* @example: parseHWB('hwb(215deg 30% 6% / 80%)')
|
|
737
|
-
*/
|
|
738
|
-
function parseHWB(v) {
|
|
739
|
-
var cssStr2 = CssColorStringParser.trimStr(v);
|
|
740
|
-
var res = CssColorStringParser.parseHWB(cssStr2);
|
|
741
|
-
return res && fromHWB(res[0], res[1], res[2], res[3]);
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* @description: 将css字符串转换为解析对象
|
|
745
|
-
* @param {string} v
|
|
746
|
-
* @return {CssColorParser}
|
|
747
|
-
* @example: parseCssColorStr('rgba(255,255,255,1)')
|
|
748
|
-
*/
|
|
749
|
-
function parseCssColorStr(v) {
|
|
750
|
-
Check.type('color', v, 'string');
|
|
751
|
-
return parseHEX(v) || parseRGBA(v) || parseKeyWord(v) || parseHSLA(v) || parseHWB(v);
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* **Deprecated method.** Use `parseCssColorStr()` instead.
|
|
755
|
-
* @description: since 2.0.1
|
|
756
|
-
* @deprecated
|
|
757
|
-
* @param {string} v
|
|
758
|
-
* @return {CssColorParser}
|
|
759
|
-
* @example: fromColorStr('rgba(255,255,255,1)')
|
|
760
|
-
*/
|
|
761
|
-
function fromColorStr(v) {
|
|
762
|
-
return parseCssColorStr(v);
|
|
763
|
-
}
|
|
764
|
-
/**
|
|
765
|
-
* @description: 将HSL色彩模式转换为解析对象
|
|
766
|
-
* @param {number} hue 色相
|
|
767
|
-
* @param {number} saturation 饱和度
|
|
768
|
-
* @param {number} lightness 亮度
|
|
769
|
-
* @param {number} alpha 不透明度
|
|
770
|
-
* @return {CssColorParser}
|
|
771
|
-
* @example: fromHSL(0,1,1,1)
|
|
772
|
-
*/
|
|
773
|
-
function fromHSL(h, s, l, a) {
|
|
774
|
-
var res = external_color_convert_default().hsl.rgb(limitNumber(0, 360, h), limitNumber(0, 100, s * 100), limitNumber(0, 100, l * 100));
|
|
775
|
-
return new src_CssColorParser(res[0], res[1], res[2], defaultValue(Number(a), 1));
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* @description: 将HWB色彩模式转换为解析对象
|
|
779
|
-
* @param {number} h 色调
|
|
780
|
-
* @param {number} w 白度
|
|
781
|
-
* @param {number} b 黑度
|
|
782
|
-
* @param {number} a 不透明度
|
|
783
|
-
* @return {CssColorParser}
|
|
784
|
-
* @example: fromHSL(0,1,1,1)
|
|
785
|
-
*/
|
|
786
|
-
function fromHWB(h, w, b, a) {
|
|
787
|
-
var res = external_color_convert_default().hwb.rgb(limitNumber(0, 360, h), limitNumber(0, 100, w * 100), limitNumber(0, 100, b * 100));
|
|
788
|
-
return new src_CssColorParser(res[0], res[1], res[2], defaultValue(Number(a), 1));
|
|
789
|
-
}
|
|
790
|
-
/**
|
|
791
|
-
* @description: 产生随机颜色
|
|
792
|
-
* @return {CssColorParser}
|
|
793
|
-
* @example: fromRandom('#000', ''#fff)
|
|
794
|
-
*/
|
|
795
|
-
function fromRandom(color1, color2) {
|
|
796
|
-
if (typeof color1 === 'string') {
|
|
797
|
-
color1 = parseCssColorStr(color1);
|
|
798
|
-
}
|
|
799
|
-
if (typeof color2 === 'string') {
|
|
800
|
-
color2 = parseCssColorStr(color2);
|
|
801
|
-
}
|
|
802
|
-
if (!color1 || !color2) {
|
|
803
|
-
throw new Error('fail to create object from random');
|
|
687
|
+
|
|
688
|
+
var CssColorParserPlus = /** @class */ (function (_super) {
|
|
689
|
+
(0,external_tslib_namespaceObject.__extends)(CssColorParserPlus, _super);
|
|
690
|
+
function CssColorParserPlus() {
|
|
691
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
804
692
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
/**
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
693
|
+
/**
|
|
694
|
+
* @description: 返回取反色后的新的实例
|
|
695
|
+
* @return {CssColorParserPlus}
|
|
696
|
+
*/
|
|
697
|
+
CssColorParserPlus.prototype.toInvert = function () {
|
|
698
|
+
var r = 255 - this.r;
|
|
699
|
+
var g = 255 - this.g;
|
|
700
|
+
var b = 255 - this.b;
|
|
701
|
+
var a = 1 - this.a;
|
|
702
|
+
return new CssColorParserPlus(r, g, b, a);
|
|
703
|
+
};
|
|
704
|
+
/**
|
|
705
|
+
* @description: 拷贝
|
|
706
|
+
* @return {CssColorParserPlus}
|
|
707
|
+
*/
|
|
708
|
+
CssColorParserPlus.prototype.clone = function () {
|
|
709
|
+
return new CssColorParserPlus(this.r, this.g, this.b, this.a);
|
|
710
|
+
};
|
|
711
|
+
/**
|
|
712
|
+
* @description: 比较两个解析对象的数据是否相等
|
|
713
|
+
* @param {string} color
|
|
714
|
+
* @return {boolean}
|
|
715
|
+
*/
|
|
716
|
+
CssColorParserPlus.prototype.equals = function (color) {
|
|
717
|
+
color = CssColorParserPlus.parseColor(color);
|
|
718
|
+
if (this === color) {
|
|
719
|
+
return true;
|
|
720
|
+
}
|
|
721
|
+
else {
|
|
722
|
+
var json1 = this.toJson();
|
|
723
|
+
var json2 = color.toJson();
|
|
724
|
+
return (json1.r === json2.r &&
|
|
725
|
+
json1.g === json2.g &&
|
|
726
|
+
json1.b === json2.g &&
|
|
727
|
+
json1.a === json2.a);
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
/**
|
|
731
|
+
* @description: 实例相加
|
|
732
|
+
* @param {CssColorParser} colorParser
|
|
733
|
+
* @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
|
|
734
|
+
* @return {CssColorParser}
|
|
735
|
+
*/
|
|
736
|
+
CssColorParserPlus.prototype.add = function (color, isSetAlpha) {
|
|
737
|
+
if (isSetAlpha === void 0) { isSetAlpha = true; }
|
|
738
|
+
var colorParser = CssColorParserPlus.parseColor(color);
|
|
739
|
+
return _super.prototype.add.call(this, colorParser, isSetAlpha);
|
|
740
|
+
};
|
|
741
|
+
/**
|
|
742
|
+
* @description: 实例相减
|
|
743
|
+
* @param {CssColorParser} colorParser
|
|
744
|
+
* @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
|
|
745
|
+
* @return {CssColorParser}
|
|
746
|
+
*/
|
|
747
|
+
CssColorParserPlus.prototype.subtract = function (color, isSetAlpha) {
|
|
748
|
+
if (isSetAlpha === void 0) { isSetAlpha = true; }
|
|
749
|
+
var colorParser = CssColorParserPlus.parseColor(color);
|
|
750
|
+
return _super.prototype.subtract.call(this, colorParser, isSetAlpha);
|
|
751
|
+
};
|
|
752
|
+
/**
|
|
753
|
+
* @description: 实例相乘
|
|
754
|
+
* @param {CssColorParser} colorParser
|
|
755
|
+
* @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
|
|
756
|
+
* @return {CssColorParser}
|
|
757
|
+
*/
|
|
758
|
+
CssColorParserPlus.prototype.multiply = function (color, isSetAlpha) {
|
|
759
|
+
if (isSetAlpha === void 0) { isSetAlpha = true; }
|
|
760
|
+
var colorParser = CssColorParserPlus.parseColor(color);
|
|
761
|
+
return _super.prototype.multiply.call(this, colorParser, isSetAlpha);
|
|
762
|
+
};
|
|
763
|
+
/**
|
|
764
|
+
* @description: 实例相除
|
|
765
|
+
* @param {CssColorParser} colorParser
|
|
766
|
+
* @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
|
|
767
|
+
* @return {CssColorParser}
|
|
768
|
+
*/
|
|
769
|
+
CssColorParserPlus.prototype.divide = function (color, isSetAlpha) {
|
|
770
|
+
if (isSetAlpha === void 0) { isSetAlpha = true; }
|
|
771
|
+
var colorParser = CssColorParserPlus.parseColor(color);
|
|
772
|
+
return _super.prototype.divide.call(this, colorParser, isSetAlpha);
|
|
773
|
+
};
|
|
774
|
+
/**
|
|
775
|
+
* @description: 解析css颜色
|
|
776
|
+
* @param {string} v
|
|
777
|
+
* @return {CssColorParserPlus}
|
|
778
|
+
* @example: parseCssColorStr('rgba(255,255,255,1)')
|
|
779
|
+
*/
|
|
780
|
+
CssColorParserPlus.parseColor = function (v) {
|
|
781
|
+
if (v instanceof src_CssColorParser) {
|
|
782
|
+
return v;
|
|
783
|
+
}
|
|
784
|
+
return CssColorParserPlus.parseCssColorStr(v);
|
|
785
|
+
};
|
|
786
|
+
/**
|
|
787
|
+
* @description: 将css字符串转换为解析对象
|
|
788
|
+
* @param {string} v
|
|
789
|
+
* @return {CssColorParserPlus}
|
|
790
|
+
* @example: parseCssColorStr('rgba(255,255,255,1)')
|
|
791
|
+
*/
|
|
792
|
+
CssColorParserPlus.parseCssColorStr = function (v) {
|
|
793
|
+
Check.type('color', v, 'string');
|
|
794
|
+
return (CssColorParserPlus.parseHEX(v) ||
|
|
795
|
+
CssColorParserPlus.parseRGBA(v) ||
|
|
796
|
+
CssColorParserPlus.parseKeyWord(v) ||
|
|
797
|
+
CssColorParserPlus.parseHSLA(v) ||
|
|
798
|
+
CssColorParserPlus.parseHWB(v));
|
|
799
|
+
};
|
|
800
|
+
/**
|
|
801
|
+
* @description: 解析颜色关键字
|
|
802
|
+
* @param {string} v
|
|
803
|
+
* @return {CssColorParserPlus}
|
|
804
|
+
* @example: parseKeyWord('red')
|
|
805
|
+
*/
|
|
806
|
+
CssColorParserPlus.parseKeyWord = function (v) {
|
|
807
|
+
var cssStr = CssColorStringParser.clearStrSpace(v);
|
|
808
|
+
var res = external_color_convert_default().keyword.rgb(cssStr);
|
|
809
|
+
return res && CssColorParserPlus.fromArray(res);
|
|
810
|
+
};
|
|
811
|
+
/**
|
|
812
|
+
* @description: 解析HSLA
|
|
813
|
+
* @param {string} v
|
|
814
|
+
* @return {CssColorParserPlus}
|
|
815
|
+
* @example: parseHSLA('hsla(215,85%,62%,0.8)')
|
|
816
|
+
*/
|
|
817
|
+
CssColorParserPlus.parseHSLA = function (v) {
|
|
818
|
+
var cssStr = CssColorStringParser.clearStrSpace(v);
|
|
819
|
+
var res = CssColorStringParser.parseHSLA(cssStr);
|
|
820
|
+
if (!res) {
|
|
821
|
+
var cssStr2 = CssColorStringParser.trimStr(v);
|
|
822
|
+
res = CssColorStringParser.parseHSLA2(cssStr2);
|
|
823
|
+
}
|
|
824
|
+
return res && CssColorParserPlus.fromHSL(res[0], res[1], res[2], res[3]);
|
|
825
|
+
};
|
|
826
|
+
/**
|
|
827
|
+
* @description: 解析HWB
|
|
828
|
+
* @param {string} v
|
|
829
|
+
* @return {CssColorParserPlus}
|
|
830
|
+
* @example: parseHWB('hwb(215deg 30% 6% / 80%)')
|
|
831
|
+
*/
|
|
832
|
+
CssColorParserPlus.parseHWB = function (v) {
|
|
833
|
+
var cssStr2 = CssColorStringParser.trimStr(v);
|
|
834
|
+
var res = CssColorStringParser.parseHWB(cssStr2);
|
|
835
|
+
return res && CssColorParserPlus.fromHWB(res[0], res[1], res[2], res[3]);
|
|
836
|
+
};
|
|
837
|
+
/**
|
|
838
|
+
* @description: 将HSL色彩模式转换为解析对象
|
|
839
|
+
* @param {number} hue 色相
|
|
840
|
+
* @param {number} saturation 饱和度
|
|
841
|
+
* @param {number} lightness 亮度
|
|
842
|
+
* @param {number} alpha 不透明度
|
|
843
|
+
* @return {CssColorParserPlus}
|
|
844
|
+
* @example: fromHSL(0,1,1,1)
|
|
845
|
+
*/
|
|
846
|
+
CssColorParserPlus.fromHSL = function (h, s, l, a) {
|
|
847
|
+
var res = external_color_convert_default().hsl.rgb(limitNumber(0, 360, h), limitNumber(0, 100, s * 100), limitNumber(0, 100, l * 100));
|
|
848
|
+
return new CssColorParserPlus(res[0], res[1], res[2], defaultValue(Number(a), 1));
|
|
849
|
+
};
|
|
850
|
+
/**
|
|
851
|
+
* @description: 将HWB色彩模式转换为解析对象
|
|
852
|
+
* @param {number} h 色调
|
|
853
|
+
* @param {number} w 白度
|
|
854
|
+
* @param {number} b 黑度
|
|
855
|
+
* @param {number} a 不透明度
|
|
856
|
+
* @return {CssColorParserPlus}
|
|
857
|
+
* @example: fromHSL(0,1,1,1)
|
|
858
|
+
*/
|
|
859
|
+
CssColorParserPlus.fromHWB = function (h, w, b, a) {
|
|
860
|
+
var res = external_color_convert_default().hwb.rgb(limitNumber(0, 360, h), limitNumber(0, 100, w * 100), limitNumber(0, 100, b * 100));
|
|
861
|
+
return new CssColorParserPlus(res[0], res[1], res[2], defaultValue(Number(a), 1));
|
|
862
|
+
};
|
|
863
|
+
/**
|
|
864
|
+
* @description: 解析16进制颜色
|
|
865
|
+
* @param {string} v
|
|
866
|
+
* @return {CssColorParserPlus}
|
|
867
|
+
* @example: CssColorParserPlus.parseHEX('#FFF')
|
|
868
|
+
*/
|
|
869
|
+
CssColorParserPlus.parseHEX = function (v) {
|
|
870
|
+
var cssStr = CssColorStringParser.clearStrSpace(v);
|
|
871
|
+
var res = CssColorStringParser.parse3BitsHEX(cssStr);
|
|
872
|
+
if (!res) {
|
|
873
|
+
res = CssColorStringParser.parse6BitsHEX(cssStr);
|
|
874
|
+
}
|
|
875
|
+
return res && CssColorParserPlus.fromArray(res);
|
|
876
|
+
};
|
|
877
|
+
/**
|
|
878
|
+
* @description: 解析rgba、rgb颜色
|
|
879
|
+
* @param {string} v
|
|
880
|
+
* @return {CssColorParserPlus}
|
|
881
|
+
* @example: CssColorParserPlus.parseRGBA('rgba(255,255,255,1)')
|
|
882
|
+
*/
|
|
883
|
+
CssColorParserPlus.parseRGBA = function (v) {
|
|
884
|
+
var cssStr = CssColorStringParser.clearStrSpace(v);
|
|
885
|
+
var res = CssColorStringParser.parseRGBA(cssStr);
|
|
886
|
+
if (!res) {
|
|
887
|
+
var cssStr2 = CssColorStringParser.trimStr(v);
|
|
888
|
+
res = CssColorStringParser.parseRGBA2(cssStr2);
|
|
889
|
+
}
|
|
890
|
+
return res && CssColorParserPlus.fromArray(res);
|
|
891
|
+
};
|
|
892
|
+
/**
|
|
893
|
+
* @description: 将ColorJson格式的json数据转换为解析对象
|
|
894
|
+
* @param {ColorJson} json
|
|
895
|
+
* @return {CssColorParserPlus}
|
|
896
|
+
* @example: CssColorParserPlus.fromJson({r: 255, g: 255, b: 255, a: 1})
|
|
897
|
+
*/
|
|
898
|
+
CssColorParserPlus.fromJson = function (json) {
|
|
899
|
+
return new CssColorParserPlus(json.r, json.g, json.b, json.a);
|
|
900
|
+
};
|
|
901
|
+
/**
|
|
902
|
+
* @description: 将RGBA数组转换为解析对象
|
|
903
|
+
* @param {Array} color
|
|
904
|
+
* @return {CssColorParserPlus}
|
|
905
|
+
* @example: CssColorParserPlus.fromArray([255,255,255,1])
|
|
906
|
+
*/
|
|
907
|
+
CssColorParserPlus.fromArray = function (color) {
|
|
908
|
+
return new CssColorParserPlus(color[0], color[1], color[2], color[3]);
|
|
909
|
+
};
|
|
910
|
+
/**
|
|
911
|
+
* @description: 产生随机颜色
|
|
912
|
+
* @return {CssColorParserPlus}
|
|
913
|
+
* @example: CssColorParserPlus.fromRandom('black', new CssColorParserPlus(255,255,255,1))
|
|
914
|
+
*/
|
|
915
|
+
CssColorParserPlus.fromRandom = function (color1, color2) {
|
|
916
|
+
color1 = CssColorParserPlus.parseColor(color1);
|
|
917
|
+
color2 = CssColorParserPlus.parseColor(color2);
|
|
918
|
+
var r = Math.random() * Math.abs(color2.r - color1.r) +
|
|
919
|
+
Math.min(color1.r, color2.r);
|
|
920
|
+
var g = Math.random() * Math.abs(color2.g - color1.g) +
|
|
921
|
+
Math.min(color1.g, color2.g);
|
|
922
|
+
var b = Math.random() * Math.abs(color2.b - color1.b) +
|
|
923
|
+
Math.min(color1.b, color2.b);
|
|
924
|
+
var a = Math.random() * Math.abs(color2.a - color1.a) +
|
|
925
|
+
Math.min(color1.a, color2.a);
|
|
926
|
+
return new CssColorParserPlus(r, g, b, a);
|
|
927
|
+
};
|
|
928
|
+
/**
|
|
929
|
+
* @description: 颜色序列化数组转换为CssColorParserPlus对象实例
|
|
930
|
+
* @param {array} colorArr
|
|
931
|
+
* @example: CssColorParserPlus.fromNormaliz([1, 0, 0, 1])
|
|
932
|
+
*/
|
|
933
|
+
CssColorParserPlus.fromNormalize = function (colorArr) {
|
|
934
|
+
var r = colorArr[0] * 255;
|
|
935
|
+
var g = colorArr[1] * 255;
|
|
936
|
+
var b = colorArr[2] * 255;
|
|
937
|
+
var a = colorArr[3];
|
|
938
|
+
return CssColorParserPlus.fromArray([r, g, b, a]);
|
|
939
|
+
};
|
|
940
|
+
return CssColorParserPlus;
|
|
941
|
+
}(src_CssColorParser));
|
|
942
|
+
/* harmony default export */ var src_CssColorParserPlus = (CssColorParserPlus);
|
|
825
943
|
|
|
826
944
|
;// CONCATENATED MODULE: ./src/main.ts
|
|
827
945
|
/*
|
|
828
946
|
* @Author: roman_123
|
|
829
947
|
* @Description:
|
|
830
948
|
* @Date: 2023-05-25 17:45:22
|
|
831
|
-
* @LastEditTime: 2023-
|
|
949
|
+
* @LastEditTime: 2023-06-27 18:45:32
|
|
832
950
|
*/
|
|
833
951
|
|
|
834
952
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";var t={n:function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return t.d(n,{a:n}),n},d:function(r,n){for(var e in n)t.o(n,e)&&!t.o(r,e)&&Object.defineProperty(r,e,{enumerable:!0,get:n[e]})},o:function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},r={};t.r(r),t.d(r,{CssColorParser:function(){return s},fromArray:function(){return _},fromColorStr:function(){return m},fromHSL:function(){return y},fromHWB:function(){return v},fromJson:function(){return S},fromRandom:function(){return d},parseCssColorStr:function(){return g},parseHEX:function(){return f},parseHSLA:function(){return l},parseHWB:function(){return b},parseKeyWord:function(){return p},parseRGBA:function(){return h}});var n=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 e(t,r){return null==t||isNaN(t)&&"number"==typeof r?r:t}function o(t,r,n){return n>r?n=r:n<t&&(n=t),n}function i(t,r){void 0===t&&(t=0);var n=Math.pow(10,r);return Math.round(t*n)/n}var a=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 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),o(0,255,t)},t._parseResStrForHue=function(t){return"string"==typeof t&&(t=parseFloat(t)),isNaN(t)&&(t=0),o(0,360,t)},t._parsePercent=function(t){return"string"==typeof t&&(t=parseFloat(t)/("%"===t.substr(-1)?100:1)),isNaN(t)&&(t=1),o(0,1,t)},t}(),s=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,r){return n.type("colorPrecision",t,"number"),n.type("outAlphaPrecision",r,"number"),n.numMinValue("colorPrecision",t,0),n.numMinValue("outAlphaPrecision",r,0),n.numIsInt("colorPrecision",t,!0),n.numIsInt("outAlphaPrecision",r,!0),this._outColorPrecision=t,this._outAlphaPrecision=r,this},t.prototype.setColor=function(t,r,n,i){return this.r=o(0,255,e(Number(t),0)),this.g=o(0,255,e(Number(r),0)),this.b=o(0,255,e(Number(n),0)),this.a=o(0,1,e(Number(i),1)),this},t.prototype.setAlpha=function(t){return this.a=o(0,1,e(Number(t),1)),this},t.prototype.setRed=function(t){return this.r=o(0,255,e(Number(t),0)),this},t.prototype.setGreen=function(t){return this.g=o(0,255,e(Number(t),0)),this},t.prototype.setBlue=function(t){return this.b=o(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[i(this.r/255,this._outColorPrecision),i(this.g/255,this._outColorPrecision),i(this.b/255,this._outColorPrecision),i(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:i(this.r,this._outColorPrecision),g:i(this.g,this._outColorPrecision),b:i(this.b,this._outColorPrecision),a:i(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,i=r?this.a*t:this.a;return this.setColor(n,e,o,i)},t.prototype.divideByScalar=function(t,r){void 0===r&&(r=!0);var n=this.r/t,e=this.g/t,o=this.b/t,i=r?this.a/t:this.a;return this.setColor(n,e,o,i)},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,i=r?this.a+t.a:this.a;return this.setColor(n,e,o,i)},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,i=r?this.a-t.a:this.a;return this.setColor(n,e,o,i)},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,i=r?this.a*t.a:this.a;return this.setColor(n,e,o,i)},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,i=r?this.a/t.a:this.a;return this.setColor(n,e,o,i)},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=a.clearStrSpace(r),e=a.parse3BitsHEX(n);return e||(e=a.parse6BitsHEX(n)),e&&t.fromArray(e)},t.parseRGBA=function(r){var n=a.clearStrSpace(r),e=a.parseRGBA(n);if(!e){var o=a.trimStr(r);e=a.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],i=r[3];return t.fromArray([n,e,o,i])},t}(),u=require("color-convert"),c=t.n(u);function p(t){var r=a.clearStrSpace(t),n=c().keyword.rgb(r);return n&&_(n)}function f(t){return s.parseHEX(t)}function h(t){return s.parseRGBA(t)}function l(t){var r=a.clearStrSpace(t),n=a.parseHSLA(r);if(!n){var e=a.trimStr(t);n=a.parseHSLA2(e)}return n&&y(n[0],n[1],n[2],n[3])}function b(t){var r=a.trimStr(t),n=a.parseHWB(r);return n&&v(n[0],n[1],n[2],n[3])}function g(t){return n.type("color",t,"string"),f(t)||h(t)||p(t)||l(t)||b(t)}function m(t){return g(t)}function y(t,r,n,i){var a=c().hsl.rgb(o(0,360,t),o(0,100,100*r),o(0,100,100*n));return new s(a[0],a[1],a[2],e(Number(i),1))}function v(t,r,n,i){var a=c().hwb.rgb(o(0,360,t),o(0,100,100*r),o(0,100,100*n));return new s(a[0],a[1],a[2],e(Number(i),1))}function d(t,r){if("string"==typeof t&&(t=g(t)),"string"==typeof r&&(r=g(r)),!t||!r)throw new Error("fail to create object from random");return s.fromRandom(t,r)}function S(t){return s.fromJson(t)}function _(t){return s.fromArray(t)}var R=exports;for(var P in r)R[P]=r[P];r.__esModule&&Object.defineProperty(R,"__esModule",{value:!0})}();
|
|
1
|
+
!function(){"use strict";var r={n:function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,{a:e}),e},d:function(t,e){for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},o:function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},r:function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})}},t={};r.r(t),r.d(t,{CssColorParser:function(){return i},CssColorParserPlus:function(){return f}});var e=function(){function r(){}return r.type=function(r,t,e){var o=typeof t;if(o!==e)throw new Error("Expected ".concat(r," to be typeof ").concat(e,", actual typeof was ").concat(o))},r.types=function(r,t,e){var o=typeof t;if(!e.includes(o))throw new Error("Expected ".concat(r," to be typeof ").concat(e.join("|"),", actual typeof was ").concat(o))},r.numValue=function(t,e,o,n){r.numMinValue(t,e,o),r.numMaxValue(t,e,n)},r.numMinValue=function(r,t,e){if(t<e)throw new Error("Expected ".concat(r," to > ").concat(e,", actual value was ").concat(t))},r.numMaxValue=function(r,t,e){if(t>e)throw new Error("Expected ".concat(r," to < ").concat(e,", actual value was ").concat(t))},r.numIsInt=function(r,t,e){var o=Math.floor(t)===t;if(o!==e)throw new Error("Expected ".concat(r," to ").concat(e?"Integer":"Float",", actual value was ").concat(o?"Integer":"Float"))},r}();function o(r,t){return null==r||isNaN(r)&&"number"==typeof t?t:r}function n(r,t,e){return e>t?e=t:e<r&&(e=r),e}function a(r,t){void 0===r&&(r=0);var e=Math.pow(10,t);return Math.round(r*e)/e}var s=function(){function r(){}return r.clearStrSpace=function(r){return r.replace(/\s/g,"")},r.trimStr=function(r){return(r=r.replace(/\s+/g," ")).trim()},r.parse3BitsHEX=function(t){var e=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i.exec(t);if(e){var n=o(e[4],"f");return[r._parseResStrForRgb(parseInt(e[1]+e[1],16)),r._parseResStrForRgb(parseInt(e[2]+e[2],16)),r._parseResStrForRgb(parseInt(e[3]+e[3],16)),r._parsePercent(parseInt(n+n,16)/255)]}return null},r.parse6BitsHEX=function(t){var e=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(t);if(e){var n=o(e[4],"ff");return[r._parseResStrForRgb(parseInt(e[1],16)),r._parseResStrForRgb(parseInt(e[2],16)),r._parseResStrForRgb(parseInt(e[3],16)),r._parsePercent(parseInt(n,16)/255)]}return null},r.parseRGBA=function(t){var e=/^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(t);return e?[r._parseResStrForRgb(e[1]),r._parseResStrForRgb(e[2]),r._parseResStrForRgb(e[3]),r._parsePercent(e[4])]:null},r.parseHSLA=function(t){var e=/^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i.exec(t);return e?[r._parseResStrForHue(e[1]),r._parsePercent(e[2]),r._parsePercent(e[3]),r._parsePercent(e[4])]:null},r.parseHWB=function(t){var e=/^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(t);return e?[r._parseResStrForHue(e[1]),r._parsePercent(e[2]),r._parsePercent(e[3]),r._parsePercent(e[4])]:null},r.parseRGBA2=function(t){var e=/^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i.exec(t);return e?[r._parseResStrForRgb(e[1]),r._parseResStrForRgb(e[2]),r._parseResStrForRgb(e[3]),r._parsePercent(e[4])]:null},r.parseHSLA2=function(t){var e=/^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i.exec(t);return e?[r._parseResStrForHue(e[1]),r._parsePercent(e[2]),r._parsePercent(e[3]),r._parsePercent(e[4])]:null},r._parseResStrForRgb=function(r){return"string"==typeof r&&(r=parseFloat(r)/("%"===r.substr(-1)?100/255:1)),isNaN(r)&&(r=1),n(0,255,r)},r._parseResStrForHue=function(r){return"string"==typeof r&&(r=parseFloat(r)),isNaN(r)&&(r=0),n(0,360,r)},r._parsePercent=function(r){return"string"==typeof r&&(r=parseFloat(r)/("%"===r.substr(-1)?100:1)),isNaN(r)&&(r=1),n(0,1,r)},r}(),i=function(){function r(r,t,e,o){this.r=255,this.g=255,this.b=255,this.a=1,this._outColorPrecision=2,this._outAlphaPrecision=2,this.setColor(r,t,e,o)}return r.prototype.setOutPrecision=function(r,t){return e.type("colorPrecision",r,"number"),e.type("outAlphaPrecision",t,"number"),e.numMinValue("colorPrecision",r,0),e.numMinValue("outAlphaPrecision",t,0),e.numIsInt("colorPrecision",r,!0),e.numIsInt("outAlphaPrecision",t,!0),this._outColorPrecision=r,this._outAlphaPrecision=t,this},r.prototype.setColor=function(r,t,e,a){return this.r=n(0,255,o(Number(r),0)),this.g=n(0,255,o(Number(t),0)),this.b=n(0,255,o(Number(e),0)),this.a=n(0,1,o(Number(a),1)),this},r.prototype.setAlpha=function(r){return this.a=n(0,1,o(Number(r),1)),this},r.prototype.setRed=function(r){return this.r=n(0,255,o(Number(r),0)),this},r.prototype.setGreen=function(r){return this.g=n(0,255,o(Number(r),0)),this},r.prototype.setBlue=function(r){return this.b=n(0,255,o(Number(r),0)),this},r.prototype.toRGBA=function(){var r=this.toJson();return 1===r.a?"rgb(".concat(r.r,",").concat(r.g,",").concat(r.b,")"):"rgba(".concat(r.r,",").concat(r.g,",").concat(r.b,",").concat(r.a,")")},r.prototype.toString=function(){return this.toRGBA()},r.prototype.toNormalize=function(){return[a(this.r/255,this._outColorPrecision),a(this.g/255,this._outColorPrecision),a(this.b/255,this._outColorPrecision),a(this.a,this._outAlphaPrecision)]},r.prototype.toHEX=function(){var r=this.toJson(),t=r.r.toString(16);t.length<2&&(t="0".concat(t));var e=r.g.toString(16);e.length<2&&(e="0".concat(e));var o=r.b.toString(16);if(o.length<2&&(o="0".concat(o)),this.a<1){var n=parseInt((255*this.a).toFixed()).toString(16);return n.length<2&&(n="0".concat(n)),"#".concat(t).concat(e).concat(o).concat(n)}return"#".concat(t).concat(e).concat(o)},r.prototype.toArray=function(){var r=this.toJson();return[r.r,r.g,r.b,r.a]},r.prototype.toJson=function(){return{r:a(this.r,this._outColorPrecision),g:a(this.g,this._outColorPrecision),b:a(this.b,this._outColorPrecision),a:a(this.a,this._outAlphaPrecision)}},r.prototype.toInvert=function(){return new r(255-this.r,255-this.g,255-this.b,1-this.a)},r.prototype.clone=function(){return new r(this.r,this.g,this.b,this.a)},r.prototype.equals=function(r){if(this===r)return!0;var t=this.toJson(),e=r.toJson();return t.r===e.r&&t.g===e.g&&t.b===e.g&&t.a===e.a},r.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},r.prototype.multiplyByScalar=function(r,t){void 0===t&&(t=!0);var e=this.r*r,o=this.g*r,n=this.b*r,a=t?this.a*r:this.a;return this.setColor(e,o,n,a)},r.prototype.divideByScalar=function(r,t){void 0===t&&(t=!0);var e=this.r/r,o=this.g/r,n=this.b/r,a=t?this.a/r:this.a;return this.setColor(e,o,n,a)},r.prototype.add=function(r,t){void 0===t&&(t=!0);var e=this.r+r.r,o=this.g+r.g,n=this.b+r.b,a=t?this.a+r.a:this.a;return this.setColor(e,o,n,a)},r.prototype.subtract=function(r,t){void 0===t&&(t=!0);var e=this.r-r.r,o=this.g-r.g,n=this.b-r.b,a=t?this.a-r.a:this.a;return this.setColor(e,o,n,a)},r.prototype.multiply=function(r,t){void 0===t&&(t=!0);var e=this.r*r.r,o=this.g*r.g,n=this.b*r.b,a=t?this.a*r.a:this.a;return this.setColor(e,o,n,a)},r.prototype.divide=function(r,t){void 0===t&&(t=!0);var e=this.r/r.r,o=this.g/r.g,n=this.b/r.b,a=t?this.a/r.a:this.a;return this.setColor(e,o,n,a)},r.prototype.addNumberForRGB=function(r){return this.r=this.r+r,this.g=this.g+r,this.b=this.b+r,this},r.prototype.addNumberForAlpha=function(r){return this.a=this.a+r,this},r.parseHEX=function(t){var e=s.clearStrSpace(t),o=s.parse3BitsHEX(e);return o||(o=s.parse6BitsHEX(e)),o&&r.fromArray(o)},r.parseRGBA=function(t){var e=s.clearStrSpace(t),o=s.parseRGBA(e);if(!o){var n=s.trimStr(t);o=s.parseRGBA2(n)}return o&&r.fromArray(o)},r.fromJson=function(t){return new r(t.r,t.g,t.b,t.a)},r.fromArray=function(t){return new r(t[0],t[1],t[2],t[3])},r.fromRandom=function(t,e){return new r(Math.random()*Math.abs(e.r-t.r)+Math.min(t.r,e.r),Math.random()*Math.abs(e.g-t.g)+Math.min(t.g,e.g),Math.random()*Math.abs(e.b-t.b)+Math.min(t.b,e.b),Math.random()*Math.abs(e.a-t.a)+Math.min(t.a,e.a))},r.fromNormalize=function(t){var e=255*t[0],o=255*t[1],n=255*t[2],a=t[3];return r.fromArray([e,o,n,a])},r}(),u=require("tslib"),c=require("color-convert"),p=r.n(c),h=function(r){function t(){return null!==r&&r.apply(this,arguments)||this}return(0,u.__extends)(t,r),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(r){if(this===(r=t.parseColor(r)))return!0;var e=this.toJson(),o=r.toJson();return e.r===o.r&&e.g===o.g&&e.b===o.g&&e.a===o.a},t.prototype.add=function(e,o){void 0===o&&(o=!0);var n=t.parseColor(e);return r.prototype.add.call(this,n,o)},t.prototype.subtract=function(e,o){void 0===o&&(o=!0);var n=t.parseColor(e);return r.prototype.subtract.call(this,n,o)},t.prototype.multiply=function(e,o){void 0===o&&(o=!0);var n=t.parseColor(e);return r.prototype.multiply.call(this,n,o)},t.prototype.divide=function(e,o){void 0===o&&(o=!0);var n=t.parseColor(e);return r.prototype.divide.call(this,n,o)},t.parseColor=function(r){return r instanceof i?r:t.parseCssColorStr(r)},t.parseCssColorStr=function(r){return e.type("color",r,"string"),t.parseHEX(r)||t.parseRGBA(r)||t.parseKeyWord(r)||t.parseHSLA(r)||t.parseHWB(r)},t.parseKeyWord=function(r){var e=s.clearStrSpace(r),o=p().keyword.rgb(e);return o&&t.fromArray(o)},t.parseHSLA=function(r){var e=s.clearStrSpace(r),o=s.parseHSLA(e);if(!o){var n=s.trimStr(r);o=s.parseHSLA2(n)}return o&&t.fromHSL(o[0],o[1],o[2],o[3])},t.parseHWB=function(r){var e=s.trimStr(r),o=s.parseHWB(e);return o&&t.fromHWB(o[0],o[1],o[2],o[3])},t.fromHSL=function(r,e,a,s){var i=p().hsl.rgb(n(0,360,r),n(0,100,100*e),n(0,100,100*a));return new t(i[0],i[1],i[2],o(Number(s),1))},t.fromHWB=function(r,e,a,s){var i=p().hwb.rgb(n(0,360,r),n(0,100,100*e),n(0,100,100*a));return new t(i[0],i[1],i[2],o(Number(s),1))},t.parseHEX=function(r){var e=s.clearStrSpace(r),o=s.parse3BitsHEX(e);return o||(o=s.parse6BitsHEX(e)),o&&t.fromArray(o)},t.parseRGBA=function(r){var e=s.clearStrSpace(r),o=s.parseRGBA(e);if(!o){var n=s.trimStr(r);o=s.parseRGBA2(n)}return o&&t.fromArray(o)},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 r=t.parseColor(r),e=t.parseColor(e),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],o=255*r[1],n=255*r[2],a=r[3];return t.fromArray([e,o,n,a])},t}(i),f=h,l=exports;for(var b in t)l[b]=t[b];t.__esModule&&Object.defineProperty(l,"__esModule",{value:!0})}();
|