css-color-parser-h 2.0.3 → 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.
@@ -1183,37 +1183,46 @@ __webpack_require__.r(__webpack_exports__);
1183
1183
  // EXPORTS
1184
1184
  __webpack_require__.d(__webpack_exports__, {
1185
1185
  "CssColorParser": function() { return /* reexport */ src_CssColorParser; },
1186
- "fromArray": function() { return /* reexport */ fromArray; },
1187
- "fromColorStr": function() { return /* reexport */ fromColorStr; },
1188
- "fromHSL": function() { return /* reexport */ fromHSL; },
1189
- "fromHWB": function() { return /* reexport */ fromHWB; },
1190
- "fromJson": function() { return /* reexport */ fromJson; },
1191
- "fromRandom": function() { return /* reexport */ fromRandom; },
1192
- "parseCssColorStr": function() { return /* reexport */ parseCssColorStr; },
1193
- "parseHEX": function() { return /* reexport */ parseHEX; },
1194
- "parseHSLA": function() { return /* reexport */ parseHSLA; },
1195
- "parseHWB": function() { return /* reexport */ parseHWB; },
1196
- "parseKeyWord": function() { return /* reexport */ parseKeyWord; },
1197
- "parseRGBA": function() { return /* reexport */ parseRGBA; }
1186
+ "CssColorParserPlus": function() { return /* reexport */ src_CssColorParserPlus; }
1198
1187
  });
1199
1188
 
1200
1189
  ;// CONCATENATED MODULE: ./src/utils/common.ts
1201
1190
  var Check = /** @class */ (function () {
1202
1191
  function Check() {
1203
1192
  }
1204
- Check.type = function (type, paramName, value) {
1193
+ Check.type = function (paramName, value, type) {
1205
1194
  var valueType = typeof value;
1206
1195
  if (valueType !== type) {
1207
1196
  throw new Error("Expected ".concat(paramName, " to be typeof ").concat(type, ", actual typeof was ").concat(valueType));
1208
1197
  }
1209
1198
  };
1210
- Check.types = function (types, paramName, value) {
1199
+ Check.types = function (paramName, value, types) {
1211
1200
  var valueType = typeof value;
1212
1201
  var isContained = types.includes(valueType);
1213
1202
  if (!isContained) {
1214
1203
  throw new Error("Expected ".concat(paramName, " to be typeof ").concat(types.join('|'), ", actual typeof was ").concat(valueType));
1215
1204
  }
1216
1205
  };
1206
+ Check.numValue = function (paramName, value, min, max) {
1207
+ Check.numMinValue(paramName, value, min);
1208
+ Check.numMaxValue(paramName, value, max);
1209
+ };
1210
+ Check.numMinValue = function (paramName, value, min) {
1211
+ if (value < min) {
1212
+ throw new Error("Expected ".concat(paramName, " to > ").concat(min, ", actual value was ").concat(value));
1213
+ }
1214
+ };
1215
+ Check.numMaxValue = function (paramName, value, max) {
1216
+ if (value > max) {
1217
+ throw new Error("Expected ".concat(paramName, " to < ").concat(max, ", actual value was ").concat(value));
1218
+ }
1219
+ };
1220
+ Check.numIsInt = function (paramName, value, expectIsInt) {
1221
+ var isInt = Math.floor(value) === value;
1222
+ if (isInt !== expectIsInt) {
1223
+ throw new Error("Expected ".concat(paramName, " to ").concat(expectIsInt ? 'Integer' : 'Float', ", actual value was ").concat(isInt ? 'Integer' : 'Float'));
1224
+ }
1225
+ };
1217
1226
  return Check;
1218
1227
  }());
1219
1228
 
@@ -1242,7 +1251,9 @@ function limitNumber(min, max, v) {
1242
1251
  return v;
1243
1252
  }
1244
1253
  function setNumberPrecision(number, precision) {
1245
- return Number(number.toFixed(precision));
1254
+ if (number === void 0) { number = 0; }
1255
+ var prec = Math.pow(10, precision);
1256
+ return Math.round(number * prec) / prec;
1246
1257
  }
1247
1258
 
1248
1259
  ;// CONCATENATED MODULE: ./src/utils/color-tools.ts
@@ -1392,12 +1403,12 @@ var CssColorStringParser = /** @class */ (function () {
1392
1403
 
1393
1404
  ;// CONCATENATED MODULE: ./src/CssColorParser.ts
1394
1405
  /*
1395
- * @Descripttion: 颜色解析器
1406
+ * @Descripttion: 颜色解析器(轻量)
1396
1407
  * @version: 1.0.0
1397
1408
  * @Author: roman_123
1398
1409
  * @Date: 2021-01-19 09:22:11
1399
1410
  * @LastEditors: Please set LastEditors
1400
- * @LastEditTime: 2023-05-26 15:59:40
1411
+ * @LastEditTime: 2023-06-27 19:01:50
1401
1412
  */
1402
1413
 
1403
1414
 
@@ -1407,8 +1418,27 @@ var CssColorParser = /** @class */ (function () {
1407
1418
  this.g = 255;
1408
1419
  this.b = 255;
1409
1420
  this.a = 1;
1421
+ this._outColorPrecision = 2;
1422
+ this._outAlphaPrecision = 2;
1410
1423
  this.setColor(red, green, blue, alpha);
1411
1424
  }
1425
+ /**
1426
+ * @description: 设置CssColorParser实例输出的精度
1427
+ * @param {number} colorPrecision 输出颜色的精度
1428
+ * @param {number} outAlphaPrecision 输出透明度的精度
1429
+ * @return {CssColorParser}
1430
+ */
1431
+ CssColorParser.prototype.setOutPrecision = function (colorPrecision, outAlphaPrecision) {
1432
+ Check.type('colorPrecision', colorPrecision, 'number');
1433
+ Check.type('outAlphaPrecision', outAlphaPrecision, 'number');
1434
+ Check.numMinValue('colorPrecision', colorPrecision, 0);
1435
+ Check.numMinValue('outAlphaPrecision', outAlphaPrecision, 0);
1436
+ Check.numIsInt('colorPrecision', colorPrecision, true);
1437
+ Check.numIsInt('outAlphaPrecision', outAlphaPrecision, true);
1438
+ this._outColorPrecision = colorPrecision;
1439
+ this._outAlphaPrecision = outAlphaPrecision;
1440
+ return this;
1441
+ };
1412
1442
  /**
1413
1443
  * 设置颜色
1414
1444
  * @param red
@@ -1422,11 +1452,47 @@ var CssColorParser = /** @class */ (function () {
1422
1452
  this.g = limitNumber(0, 255, defaultValue(Number(green), 0));
1423
1453
  this.b = limitNumber(0, 255, defaultValue(Number(blue), 0));
1424
1454
  this.a = limitNumber(0, 1, defaultValue(Number(alpha), 1));
1455
+ return this;
1456
+ };
1457
+ /**
1458
+ * @description: 设置透明度
1459
+ * @param {number} alpha
1460
+ * @return {CssColorParser}
1461
+ */
1462
+ CssColorParser.prototype.setAlpha = function (alpha) {
1463
+ this.a = limitNumber(0, 1, defaultValue(Number(alpha), 1));
1464
+ return this;
1465
+ };
1466
+ /**
1467
+ * @description: 设置红色值
1468
+ * @param {number} red
1469
+ * @return {CssColorParser}
1470
+ */
1471
+ CssColorParser.prototype.setRed = function (red) {
1472
+ this.r = limitNumber(0, 255, defaultValue(Number(red), 0));
1473
+ return this;
1474
+ };
1475
+ /**
1476
+ * @description: 设置绿色值
1477
+ * @param {number} green
1478
+ * @return {CssColorParser}
1479
+ */
1480
+ CssColorParser.prototype.setGreen = function (green) {
1481
+ this.g = limitNumber(0, 255, defaultValue(Number(green), 0));
1482
+ return this;
1483
+ };
1484
+ /**
1485
+ * @description: 设置蓝色值
1486
+ * @param {number} blue
1487
+ * @return {CssColorParser}
1488
+ */
1489
+ CssColorParser.prototype.setBlue = function (blue) {
1490
+ this.b = limitNumber(0, 255, defaultValue(Number(blue), 0));
1491
+ return this;
1425
1492
  };
1426
1493
  /**
1427
1494
  * @description: 返回rgba格式的css字符串
1428
- * @return {*}
1429
- * @author: roman_123
1495
+ * @return {string}
1430
1496
  */
1431
1497
  CssColorParser.prototype.toRGBA = function () {
1432
1498
  var color = this.toJson();
@@ -1437,29 +1503,25 @@ var CssColorParser = /** @class */ (function () {
1437
1503
  };
1438
1504
  /**
1439
1505
  * @description: 返回字符串
1440
- * @return {*}
1441
- * @author: roman_123
1506
+ * @return {string}
1442
1507
  */
1443
1508
  CssColorParser.prototype.toString = function () {
1444
1509
  return this.toRGBA();
1445
1510
  };
1446
1511
  /**
1447
1512
  * @description: 归一化
1448
- * @return {*}
1449
- * @author: roman_123
1513
+ * @return {array}
1450
1514
  */
1451
1515
  CssColorParser.prototype.toNormalize = function () {
1452
- return {
1453
- r: setNumberPrecision(this.r / 255, 2),
1454
- g: setNumberPrecision(this.g / 255, 2),
1455
- b: setNumberPrecision(this.b / 255, 2),
1456
- a: setNumberPrecision(this.a, 2)
1457
- };
1516
+ var r = setNumberPrecision(this.r / 255, this._outColorPrecision);
1517
+ var g = setNumberPrecision(this.g / 255, this._outColorPrecision);
1518
+ var b = setNumberPrecision(this.b / 255, this._outColorPrecision);
1519
+ var a = setNumberPrecision(this.a, this._outAlphaPrecision);
1520
+ return [r, g, b, a];
1458
1521
  };
1459
1522
  /**
1460
1523
  * @description: 返回16进制格式的css字符串
1461
- * @return {*}
1462
- * @author: roman_123
1524
+ * @return {string}
1463
1525
  */
1464
1526
  CssColorParser.prototype.toHEX = function () {
1465
1527
  var color = this.toJson();
@@ -1487,8 +1549,7 @@ var CssColorParser = /** @class */ (function () {
1487
1549
  };
1488
1550
  /**
1489
1551
  * @description: 返回rgba数组
1490
- * @return {*}
1491
- * @author: roman_123
1552
+ * @return {array}
1492
1553
  */
1493
1554
  CssColorParser.prototype.toArray = function () {
1494
1555
  var color = this.toJson();
@@ -1496,47 +1557,172 @@ var CssColorParser = /** @class */ (function () {
1496
1557
  };
1497
1558
  /**
1498
1559
  * @description: 返回ColorJson
1499
- * @return {*}
1500
- * @author: roman_123
1560
+ * @return {ColorJson}
1501
1561
  */
1502
1562
  CssColorParser.prototype.toJson = function () {
1503
1563
  return {
1504
- r: parseInt(this.r.toFixed()),
1505
- g: parseInt(this.g.toFixed()),
1506
- b: parseInt(this.b.toFixed()),
1507
- a: parseFloat(this.a.toFixed(2))
1564
+ r: setNumberPrecision(this.r, this._outColorPrecision),
1565
+ g: setNumberPrecision(this.g, this._outColorPrecision),
1566
+ b: setNumberPrecision(this.b, this._outColorPrecision),
1567
+ a: setNumberPrecision(this.a, this._outAlphaPrecision),
1508
1568
  };
1509
1569
  };
1570
+ /**
1571
+ * @description: 返回取反色后的新的实例
1572
+ * @return {CssColorParser}
1573
+ */
1574
+ CssColorParser.prototype.toInvert = function () {
1575
+ var r = 255 - this.r;
1576
+ var g = 255 - this.g;
1577
+ var b = 255 - this.b;
1578
+ var a = 1 - this.a;
1579
+ return new CssColorParser(r, g, b, a);
1580
+ };
1510
1581
  /**
1511
1582
  * @description: 拷贝
1512
- * @return {*}
1513
- * @author: roman_123
1583
+ * @return {CssColorParser}
1514
1584
  */
1515
1585
  CssColorParser.prototype.clone = function () {
1516
1586
  return new CssColorParser(this.r, this.g, this.b, this.a);
1517
1587
  };
1518
1588
  /**
1519
1589
  * @description: 比较两个解析对象的数据是否相等
1520
- * @param {*} color
1521
- * @return {*}
1522
- * @author: roman_123
1590
+ * @param {string} color
1591
+ * @return {boolean}
1523
1592
  */
1524
1593
  CssColorParser.prototype.equals = function (color) {
1525
1594
  if (this === color) {
1526
1595
  return true;
1527
1596
  }
1528
1597
  else {
1529
- return (this.r === color.r &&
1530
- this.g === color.g &&
1531
- this.b === color.g &&
1532
- this.a === color.a);
1598
+ var json1 = this.toJson();
1599
+ var json2 = color.toJson();
1600
+ return (json1.r === json2.r &&
1601
+ json1.g === json2.g &&
1602
+ json1.b === json2.g &&
1603
+ json1.a === json2.a);
1533
1604
  }
1534
1605
  };
1606
+ /**
1607
+ * @description: 反色
1608
+ * @return {CssColorParser}
1609
+ */
1610
+ CssColorParser.prototype.setInvert = function () {
1611
+ this.r = 255 - this.r;
1612
+ this.g = 255 - this.g;
1613
+ this.b = 255 - this.b;
1614
+ this.a = 1 - this.a;
1615
+ return this;
1616
+ };
1617
+ /**
1618
+ * @description: 乘以倍数
1619
+ * @param {number} scalar
1620
+ * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1621
+ * @return {CssColorParser}
1622
+ */
1623
+ CssColorParser.prototype.multiplyByScalar = function (scalar, isSetAlpha) {
1624
+ if (isSetAlpha === void 0) { isSetAlpha = true; }
1625
+ var r = this.r * scalar;
1626
+ var g = this.g * scalar;
1627
+ var b = this.b * scalar;
1628
+ var a = isSetAlpha ? this.a * scalar : this.a;
1629
+ return this.setColor(r, g, b, a);
1630
+ };
1631
+ /**
1632
+ * @description: 除以倍数
1633
+ * @param {number} scalar
1634
+ * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1635
+ * @return {CssColorParser}
1636
+ */
1637
+ CssColorParser.prototype.divideByScalar = function (scalar, isSetAlpha) {
1638
+ if (isSetAlpha === void 0) { isSetAlpha = true; }
1639
+ var r = this.r / scalar;
1640
+ var g = this.g / scalar;
1641
+ var b = this.b / scalar;
1642
+ var a = isSetAlpha ? this.a / scalar : this.a;
1643
+ return this.setColor(r, g, b, a);
1644
+ };
1645
+ /**
1646
+ * @description: 实例相加
1647
+ * @param {CssColorParser} colorParser
1648
+ * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1649
+ * @return {CssColorParser}
1650
+ */
1651
+ CssColorParser.prototype.add = function (colorParser, isSetAlpha) {
1652
+ if (isSetAlpha === void 0) { isSetAlpha = true; }
1653
+ var r = this.r + colorParser.r;
1654
+ var g = this.g + colorParser.g;
1655
+ var b = this.b + colorParser.b;
1656
+ var a = isSetAlpha ? this.a + colorParser.a : this.a;
1657
+ return this.setColor(r, g, b, a);
1658
+ };
1659
+ /**
1660
+ * @description: 实例相减
1661
+ * @param {CssColorParser} colorParser
1662
+ * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1663
+ * @return {CssColorParser}
1664
+ */
1665
+ CssColorParser.prototype.subtract = function (colorParser, isSetAlpha) {
1666
+ if (isSetAlpha === void 0) { isSetAlpha = true; }
1667
+ var r = this.r - colorParser.r;
1668
+ var g = this.g - colorParser.g;
1669
+ var b = this.b - colorParser.b;
1670
+ var a = isSetAlpha ? this.a - colorParser.a : this.a;
1671
+ return this.setColor(r, g, b, a);
1672
+ };
1673
+ /**
1674
+ * @description: 实例相乘
1675
+ * @param {CssColorParser} colorParser
1676
+ * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1677
+ * @return {CssColorParser}
1678
+ */
1679
+ CssColorParser.prototype.multiply = function (colorParser, isSetAlpha) {
1680
+ if (isSetAlpha === void 0) { isSetAlpha = true; }
1681
+ var r = this.r * colorParser.r;
1682
+ var g = this.g * colorParser.g;
1683
+ var b = this.b * colorParser.b;
1684
+ var a = isSetAlpha ? this.a * colorParser.a : this.a;
1685
+ return this.setColor(r, g, b, a);
1686
+ };
1687
+ /**
1688
+ * @description: 实例相除
1689
+ * @param {CssColorParser} colorParser
1690
+ * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
1691
+ * @return {CssColorParser}
1692
+ */
1693
+ CssColorParser.prototype.divide = function (colorParser, isSetAlpha) {
1694
+ if (isSetAlpha === void 0) { isSetAlpha = true; }
1695
+ var r = this.r / colorParser.r;
1696
+ var g = this.g / colorParser.g;
1697
+ var b = this.b / colorParser.b;
1698
+ var a = isSetAlpha ? this.a / colorParser.a : this.a;
1699
+ return this.setColor(r, g, b, a);
1700
+ };
1701
+ /**
1702
+ * @description: 颜色RGB加上数字
1703
+ * @param {number} num
1704
+ * @return {CssColorParser}
1705
+ */
1706
+ CssColorParser.prototype.addNumberForRGB = function (num) {
1707
+ this.r = this.r + num;
1708
+ this.g = this.g + num;
1709
+ this.b = this.b + num;
1710
+ return this;
1711
+ };
1712
+ /**
1713
+ * @description: 透明度加上数字
1714
+ * @param {number} num
1715
+ * @return {CssColorParser}
1716
+ */
1717
+ CssColorParser.prototype.addNumberForAlpha = function (num) {
1718
+ this.a = this.a + num;
1719
+ return this;
1720
+ };
1535
1721
  /**
1536
1722
  * @description: 解析16进制颜色
1537
1723
  * @param {string} v
1538
1724
  * @return {CssColorParser}
1539
- * @example: parseHEX('#FFF')
1725
+ * @example: CssColorParser.parseHEX('#FFF')
1540
1726
  */
1541
1727
  CssColorParser.parseHEX = function (v) {
1542
1728
  var cssStr = CssColorStringParser.clearStrSpace(v);
@@ -1550,7 +1736,7 @@ var CssColorParser = /** @class */ (function () {
1550
1736
  * @description: 解析rgba、rgb颜色
1551
1737
  * @param {string} v
1552
1738
  * @return {CssColorParser}
1553
- * @example: parseRGBA('rgba(255,255,255,1)')
1739
+ * @example: CssColorParser.parseRGBA('rgba(255,255,255,1)')
1554
1740
  */
1555
1741
  CssColorParser.parseRGBA = function (v) {
1556
1742
  var cssStr = CssColorStringParser.clearStrSpace(v);
@@ -1565,7 +1751,7 @@ var CssColorParser = /** @class */ (function () {
1565
1751
  * @description: 将ColorJson格式的json数据转换为解析对象
1566
1752
  * @param {ColorJson} json
1567
1753
  * @return {CssColorParser}
1568
- * @example: fromJson({r: 255, g: 255, b: 255, a: 1})
1754
+ * @example: CssColorParser.fromJson({r: 255, g: 255, b: 255, a: 1})
1569
1755
  */
1570
1756
  CssColorParser.fromJson = function (json) {
1571
1757
  return new CssColorParser(json.r, json.g, json.b, json.a);
@@ -1574,7 +1760,7 @@ var CssColorParser = /** @class */ (function () {
1574
1760
  * @description: 将RGBA数组转换为解析对象
1575
1761
  * @param {Array} color
1576
1762
  * @return {CssColorParser}
1577
- * @example: fromJson([255,255,255,1])
1763
+ * @example: CssColorParser.fromArray([255,255,255,1])
1578
1764
  */
1579
1765
  CssColorParser.fromArray = function (color) {
1580
1766
  return new CssColorParser(color[0], color[1], color[2], color[3]);
@@ -1582,7 +1768,7 @@ var CssColorParser = /** @class */ (function () {
1582
1768
  /**
1583
1769
  * @description: 产生随机颜色
1584
1770
  * @return {CssColorParser}
1585
- * @example: fromRandom(new CssColorParser(0,0,0,0), new CssColorParser(255,255,255,1))
1771
+ * @example: CssColorParser.fromRandom(new CssColorParser(0,0,0,0), new CssColorParser(255,255,255,1))
1586
1772
  */
1587
1773
  CssColorParser.fromRandom = function (color1, color2) {
1588
1774
  var r = Math.random() * Math.abs(color2.r - color1.r) +
@@ -1595,182 +1781,772 @@ var CssColorParser = /** @class */ (function () {
1595
1781
  Math.min(color1.a, color2.a);
1596
1782
  return new CssColorParser(r, g, b, a);
1597
1783
  };
1784
+ /**
1785
+ * @description: 颜色序列化数组转换为CssColorParser对象实例
1786
+ * @param {array} colorArr
1787
+ * @example: CssColorParser.fromNormaliz([1, 0, 0, 1])
1788
+ */
1789
+ CssColorParser.fromNormalize = function (colorArr) {
1790
+ var r = colorArr[0] * 255;
1791
+ var g = colorArr[1] * 255;
1792
+ var b = colorArr[2] * 255;
1793
+ var a = colorArr[3];
1794
+ return CssColorParser.fromArray([r, g, b, a]);
1795
+ };
1598
1796
  return CssColorParser;
1599
1797
  }());
1600
1798
  /* harmony default export */ var src_CssColorParser = (CssColorParser);
1601
1799
 
1800
+ ;// CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.js
1801
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1802
+ /******************************************************************************
1803
+ Copyright (c) Microsoft Corporation.
1804
+
1805
+ Permission to use, copy, modify, and/or distribute this software for any
1806
+ purpose with or without fee is hereby granted.
1807
+
1808
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1809
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1810
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1811
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1812
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1813
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1814
+ PERFORMANCE OF THIS SOFTWARE.
1815
+ ***************************************************************************** */
1816
+ /* global Reflect, Promise */
1817
+
1818
+ var _extendStatics = function extendStatics(d, b) {
1819
+ _extendStatics = Object.setPrototypeOf || {
1820
+ __proto__: []
1821
+ } instanceof Array && function (d, b) {
1822
+ d.__proto__ = b;
1823
+ } || function (d, b) {
1824
+ for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
1825
+ };
1826
+ return _extendStatics(d, b);
1827
+ };
1828
+ function __extends(d, b) {
1829
+ if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
1830
+ _extendStatics(d, b);
1831
+ function __() {
1832
+ this.constructor = d;
1833
+ }
1834
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1835
+ }
1836
+ var _assign = function __assign() {
1837
+ _assign = Object.assign || function __assign(t) {
1838
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
1839
+ s = arguments[i];
1840
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
1841
+ }
1842
+ return t;
1843
+ };
1844
+ return _assign.apply(this, arguments);
1845
+ };
1846
+
1847
+ function __rest(s, e) {
1848
+ var t = {};
1849
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
1850
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
1851
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
1852
+ }
1853
+ return t;
1854
+ }
1855
+ function __decorate(decorators, target, key, desc) {
1856
+ var c = arguments.length,
1857
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
1858
+ d;
1859
+ if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1860
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1861
+ }
1862
+ function __param(paramIndex, decorator) {
1863
+ return function (target, key) {
1864
+ decorator(target, key, paramIndex);
1865
+ };
1866
+ }
1867
+ function __esDecorate(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
1868
+ function accept(f) {
1869
+ if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected");
1870
+ return f;
1871
+ }
1872
+ var kind = contextIn.kind,
1873
+ key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
1874
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
1875
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
1876
+ var _,
1877
+ done = false;
1878
+ for (var i = decorators.length - 1; i >= 0; i--) {
1879
+ var context = {};
1880
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
1881
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
1882
+ context.addInitializer = function (f) {
1883
+ if (done) throw new TypeError("Cannot add initializers after decoration has completed");
1884
+ extraInitializers.push(accept(f || null));
1885
+ };
1886
+ var result = (0, decorators[i])(kind === "accessor" ? {
1887
+ get: descriptor.get,
1888
+ set: descriptor.set
1889
+ } : descriptor[key], context);
1890
+ if (kind === "accessor") {
1891
+ if (result === void 0) continue;
1892
+ if (result === null || _typeof(result) !== "object") throw new TypeError("Object expected");
1893
+ if (_ = accept(result.get)) descriptor.get = _;
1894
+ if (_ = accept(result.set)) descriptor.set = _;
1895
+ if (_ = accept(result.init)) initializers.unshift(_);
1896
+ } else if (_ = accept(result)) {
1897
+ if (kind === "field") initializers.unshift(_);else descriptor[key] = _;
1898
+ }
1899
+ }
1900
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
1901
+ done = true;
1902
+ }
1903
+ ;
1904
+ function __runInitializers(thisArg, initializers, value) {
1905
+ var useValue = arguments.length > 2;
1906
+ for (var i = 0; i < initializers.length; i++) {
1907
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
1908
+ }
1909
+ return useValue ? value : void 0;
1910
+ }
1911
+ ;
1912
+ function __propKey(x) {
1913
+ return _typeof(x) === "symbol" ? x : "".concat(x);
1914
+ }
1915
+ ;
1916
+ function __setFunctionName(f, name, prefix) {
1917
+ if (_typeof(name) === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
1918
+ return Object.defineProperty(f, "name", {
1919
+ configurable: true,
1920
+ value: prefix ? "".concat(prefix, " ", name) : name
1921
+ });
1922
+ }
1923
+ ;
1924
+ function __metadata(metadataKey, metadataValue) {
1925
+ if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
1926
+ }
1927
+ function __awaiter(thisArg, _arguments, P, generator) {
1928
+ function adopt(value) {
1929
+ return value instanceof P ? value : new P(function (resolve) {
1930
+ resolve(value);
1931
+ });
1932
+ }
1933
+ return new (P || (P = Promise))(function (resolve, reject) {
1934
+ function fulfilled(value) {
1935
+ try {
1936
+ step(generator.next(value));
1937
+ } catch (e) {
1938
+ reject(e);
1939
+ }
1940
+ }
1941
+ function rejected(value) {
1942
+ try {
1943
+ step(generator["throw"](value));
1944
+ } catch (e) {
1945
+ reject(e);
1946
+ }
1947
+ }
1948
+ function step(result) {
1949
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1950
+ }
1951
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1952
+ });
1953
+ }
1954
+ function __generator(thisArg, body) {
1955
+ var _ = {
1956
+ label: 0,
1957
+ sent: function sent() {
1958
+ if (t[0] & 1) throw t[1];
1959
+ return t[1];
1960
+ },
1961
+ trys: [],
1962
+ ops: []
1963
+ },
1964
+ f,
1965
+ y,
1966
+ t,
1967
+ g;
1968
+ return g = {
1969
+ next: verb(0),
1970
+ "throw": verb(1),
1971
+ "return": verb(2)
1972
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
1973
+ return this;
1974
+ }), g;
1975
+ function verb(n) {
1976
+ return function (v) {
1977
+ return step([n, v]);
1978
+ };
1979
+ }
1980
+ function step(op) {
1981
+ if (f) throw new TypeError("Generator is already executing.");
1982
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
1983
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1984
+ if (y = 0, t) op = [op[0] & 2, t.value];
1985
+ switch (op[0]) {
1986
+ case 0:
1987
+ case 1:
1988
+ t = op;
1989
+ break;
1990
+ case 4:
1991
+ _.label++;
1992
+ return {
1993
+ value: op[1],
1994
+ done: false
1995
+ };
1996
+ case 5:
1997
+ _.label++;
1998
+ y = op[1];
1999
+ op = [0];
2000
+ continue;
2001
+ case 7:
2002
+ op = _.ops.pop();
2003
+ _.trys.pop();
2004
+ continue;
2005
+ default:
2006
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
2007
+ _ = 0;
2008
+ continue;
2009
+ }
2010
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
2011
+ _.label = op[1];
2012
+ break;
2013
+ }
2014
+ if (op[0] === 6 && _.label < t[1]) {
2015
+ _.label = t[1];
2016
+ t = op;
2017
+ break;
2018
+ }
2019
+ if (t && _.label < t[2]) {
2020
+ _.label = t[2];
2021
+ _.ops.push(op);
2022
+ break;
2023
+ }
2024
+ if (t[2]) _.ops.pop();
2025
+ _.trys.pop();
2026
+ continue;
2027
+ }
2028
+ op = body.call(thisArg, _);
2029
+ } catch (e) {
2030
+ op = [6, e];
2031
+ y = 0;
2032
+ } finally {
2033
+ f = t = 0;
2034
+ }
2035
+ if (op[0] & 5) throw op[1];
2036
+ return {
2037
+ value: op[0] ? op[1] : void 0,
2038
+ done: true
2039
+ };
2040
+ }
2041
+ }
2042
+ var __createBinding = Object.create ? function (o, m, k, k2) {
2043
+ if (k2 === undefined) k2 = k;
2044
+ var desc = Object.getOwnPropertyDescriptor(m, k);
2045
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
2046
+ desc = {
2047
+ enumerable: true,
2048
+ get: function get() {
2049
+ return m[k];
2050
+ }
2051
+ };
2052
+ }
2053
+ Object.defineProperty(o, k2, desc);
2054
+ } : function (o, m, k, k2) {
2055
+ if (k2 === undefined) k2 = k;
2056
+ o[k2] = m[k];
2057
+ };
2058
+ function __exportStar(m, o) {
2059
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);
2060
+ }
2061
+ function __values(o) {
2062
+ var s = typeof Symbol === "function" && Symbol.iterator,
2063
+ m = s && o[s],
2064
+ i = 0;
2065
+ if (m) return m.call(o);
2066
+ if (o && typeof o.length === "number") return {
2067
+ next: function next() {
2068
+ if (o && i >= o.length) o = void 0;
2069
+ return {
2070
+ value: o && o[i++],
2071
+ done: !o
2072
+ };
2073
+ }
2074
+ };
2075
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
2076
+ }
2077
+ function __read(o, n) {
2078
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
2079
+ if (!m) return o;
2080
+ var i = m.call(o),
2081
+ r,
2082
+ ar = [],
2083
+ e;
2084
+ try {
2085
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
2086
+ } catch (error) {
2087
+ e = {
2088
+ error: error
2089
+ };
2090
+ } finally {
2091
+ try {
2092
+ if (r && !r.done && (m = i["return"])) m.call(i);
2093
+ } finally {
2094
+ if (e) throw e.error;
2095
+ }
2096
+ }
2097
+ return ar;
2098
+ }
2099
+
2100
+ /** @deprecated */
2101
+ function __spread() {
2102
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
2103
+ return ar;
2104
+ }
2105
+
2106
+ /** @deprecated */
2107
+ function __spreadArrays() {
2108
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
2109
+ for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
2110
+ return r;
2111
+ }
2112
+ function __spreadArray(to, from, pack) {
2113
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
2114
+ if (ar || !(i in from)) {
2115
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
2116
+ ar[i] = from[i];
2117
+ }
2118
+ }
2119
+ return to.concat(ar || Array.prototype.slice.call(from));
2120
+ }
2121
+ function __await(v) {
2122
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
2123
+ }
2124
+ function __asyncGenerator(thisArg, _arguments, generator) {
2125
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
2126
+ var g = generator.apply(thisArg, _arguments || []),
2127
+ i,
2128
+ q = [];
2129
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
2130
+ return this;
2131
+ }, i;
2132
+ function verb(n) {
2133
+ if (g[n]) i[n] = function (v) {
2134
+ return new Promise(function (a, b) {
2135
+ q.push([n, v, a, b]) > 1 || resume(n, v);
2136
+ });
2137
+ };
2138
+ }
2139
+ function resume(n, v) {
2140
+ try {
2141
+ step(g[n](v));
2142
+ } catch (e) {
2143
+ settle(q[0][3], e);
2144
+ }
2145
+ }
2146
+ function step(r) {
2147
+ r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
2148
+ }
2149
+ function fulfill(value) {
2150
+ resume("next", value);
2151
+ }
2152
+ function reject(value) {
2153
+ resume("throw", value);
2154
+ }
2155
+ function settle(f, v) {
2156
+ if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
2157
+ }
2158
+ }
2159
+ function __asyncDelegator(o) {
2160
+ var i, p;
2161
+ return i = {}, verb("next"), verb("throw", function (e) {
2162
+ throw e;
2163
+ }), verb("return"), i[Symbol.iterator] = function () {
2164
+ return this;
2165
+ }, i;
2166
+ function verb(n, f) {
2167
+ i[n] = o[n] ? function (v) {
2168
+ return (p = !p) ? {
2169
+ value: __await(o[n](v)),
2170
+ done: false
2171
+ } : f ? f(v) : v;
2172
+ } : f;
2173
+ }
2174
+ }
2175
+ function __asyncValues(o) {
2176
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
2177
+ var m = o[Symbol.asyncIterator],
2178
+ i;
2179
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
2180
+ return this;
2181
+ }, i);
2182
+ function verb(n) {
2183
+ i[n] = o[n] && function (v) {
2184
+ return new Promise(function (resolve, reject) {
2185
+ v = o[n](v), settle(resolve, reject, v.done, v.value);
2186
+ });
2187
+ };
2188
+ }
2189
+ function settle(resolve, reject, d, v) {
2190
+ Promise.resolve(v).then(function (v) {
2191
+ resolve({
2192
+ value: v,
2193
+ done: d
2194
+ });
2195
+ }, reject);
2196
+ }
2197
+ }
2198
+ function __makeTemplateObject(cooked, raw) {
2199
+ if (Object.defineProperty) {
2200
+ Object.defineProperty(cooked, "raw", {
2201
+ value: raw
2202
+ });
2203
+ } else {
2204
+ cooked.raw = raw;
2205
+ }
2206
+ return cooked;
2207
+ }
2208
+ ;
2209
+ var __setModuleDefault = Object.create ? function (o, v) {
2210
+ Object.defineProperty(o, "default", {
2211
+ enumerable: true,
2212
+ value: v
2213
+ });
2214
+ } : function (o, v) {
2215
+ o["default"] = v;
2216
+ };
2217
+ function __importStar(mod) {
2218
+ if (mod && mod.__esModule) return mod;
2219
+ var result = {};
2220
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
2221
+ __setModuleDefault(result, mod);
2222
+ return result;
2223
+ }
2224
+ function __importDefault(mod) {
2225
+ return mod && mod.__esModule ? mod : {
2226
+ "default": mod
2227
+ };
2228
+ }
2229
+ function __classPrivateFieldGet(receiver, state, kind, f) {
2230
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
2231
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
2232
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
2233
+ }
2234
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
2235
+ if (kind === "m") throw new TypeError("Private method is not writable");
2236
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
2237
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
2238
+ return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
2239
+ }
2240
+ function __classPrivateFieldIn(state, receiver) {
2241
+ if (receiver === null || _typeof(receiver) !== "object" && typeof receiver !== "function") throw new TypeError("Cannot use 'in' operator on non-object");
2242
+ return typeof state === "function" ? receiver === state : state.has(receiver);
2243
+ }
2244
+ /* harmony default export */ var tslib_es6 = ({
2245
+ __extends: __extends,
2246
+ __assign: _assign,
2247
+ __rest: __rest,
2248
+ __decorate: __decorate,
2249
+ __param: __param,
2250
+ __metadata: __metadata,
2251
+ __awaiter: __awaiter,
2252
+ __generator: __generator,
2253
+ __createBinding: __createBinding,
2254
+ __exportStar: __exportStar,
2255
+ __values: __values,
2256
+ __read: __read,
2257
+ __spread: __spread,
2258
+ __spreadArrays: __spreadArrays,
2259
+ __spreadArray: __spreadArray,
2260
+ __await: __await,
2261
+ __asyncGenerator: __asyncGenerator,
2262
+ __asyncDelegator: __asyncDelegator,
2263
+ __asyncValues: __asyncValues,
2264
+ __makeTemplateObject: __makeTemplateObject,
2265
+ __importStar: __importStar,
2266
+ __importDefault: __importDefault,
2267
+ __classPrivateFieldGet: __classPrivateFieldGet,
2268
+ __classPrivateFieldSet: __classPrivateFieldSet,
2269
+ __classPrivateFieldIn: __classPrivateFieldIn
2270
+ });
1602
2271
  // EXTERNAL MODULE: ./node_modules/color-convert/index.js
1603
2272
  var color_convert = __webpack_require__(907);
1604
2273
  var color_convert_default = /*#__PURE__*/__webpack_require__.n(color_convert);
1605
- ;// CONCATENATED MODULE: ./src/utils/parsers.ts
2274
+ ;// CONCATENATED MODULE: ./src/CssColorParserPlus.ts
2275
+ /*
2276
+ * @Descripttion: 颜色解析器(增强)
2277
+ * @version: 1.0.0
2278
+ * @Author: roman_123
2279
+ * @Date: 2021-01-19 09:22:11
2280
+ * @LastEditors: Please set LastEditors
2281
+ * @LastEditTime: 2023-06-27 18:53:31
2282
+ */
1606
2283
 
1607
2284
 
1608
2285
 
1609
2286
 
1610
- /**
1611
- * @description: 解析颜色关键字
1612
- * @param {string} v
1613
- * @return {CssColorParser}
1614
- * @example: parseKeyWord('red')
1615
- */
1616
- function parseKeyWord(v) {
1617
- var cssStr = CssColorStringParser.clearStrSpace(v);
1618
- var res = color_convert_default().keyword.rgb(cssStr);
1619
- return res && fromArray(res);
1620
- }
1621
- /**
1622
- * @description: 解析16进制字符串
1623
- * @param {string} v
1624
- * @return {CssColorParser}
1625
- * @example: parseHEX('#FFF')
1626
- */
1627
- function parseHEX(v) {
1628
- var cssStr = CssColorStringParser.clearStrSpace(v);
1629
- var res = CssColorStringParser.parse3BitsHEX(cssStr);
1630
- if (!res) {
1631
- res = CssColorStringParser.parse6BitsHEX(cssStr);
1632
- }
1633
- return res && fromArray(res);
1634
- }
1635
- /**
1636
- * @description: 解析RGBA
1637
- * @param {string} v
1638
- * @return {CssColorParser}
1639
- * @example: parseRGBA('rgba(255,255,255,1)')
1640
- */
1641
- function parseRGBA(v) {
1642
- var cssStr = CssColorStringParser.clearStrSpace(v);
1643
- var res = CssColorStringParser.parseRGBA(cssStr);
1644
- if (!res) {
1645
- var cssStr2 = CssColorStringParser.trimStr(v);
1646
- res = CssColorStringParser.parseRGBA2(cssStr2);
2287
+
2288
+ var CssColorParserPlus = /** @class */ (function (_super) {
2289
+ __extends(CssColorParserPlus, _super);
2290
+ function CssColorParserPlus() {
2291
+ return _super !== null && _super.apply(this, arguments) || this;
1647
2292
  }
1648
- return res && fromArray(res);
1649
- }
1650
- /**
1651
- * @description: 解析HSLA
1652
- * @param {string} v
1653
- * @return {CssColorParser}
1654
- * @example: parseHSLA('hsla(215,85%,62%,0.8)')
1655
- */
1656
- function parseHSLA(v) {
1657
- var cssStr = CssColorStringParser.clearStrSpace(v);
1658
- var res = CssColorStringParser.parseHSLA(cssStr);
1659
- if (!res) {
2293
+ /**
2294
+ * @description: 返回取反色后的新的实例
2295
+ * @return {CssColorParserPlus}
2296
+ */
2297
+ CssColorParserPlus.prototype.toInvert = function () {
2298
+ var r = 255 - this.r;
2299
+ var g = 255 - this.g;
2300
+ var b = 255 - this.b;
2301
+ var a = 1 - this.a;
2302
+ return new CssColorParserPlus(r, g, b, a);
2303
+ };
2304
+ /**
2305
+ * @description: 拷贝
2306
+ * @return {CssColorParserPlus}
2307
+ */
2308
+ CssColorParserPlus.prototype.clone = function () {
2309
+ return new CssColorParserPlus(this.r, this.g, this.b, this.a);
2310
+ };
2311
+ /**
2312
+ * @description: 比较两个解析对象的数据是否相等
2313
+ * @param {string} color
2314
+ * @return {boolean}
2315
+ */
2316
+ CssColorParserPlus.prototype.equals = function (color) {
2317
+ color = CssColorParserPlus.parseColor(color);
2318
+ if (this === color) {
2319
+ return true;
2320
+ }
2321
+ else {
2322
+ var json1 = this.toJson();
2323
+ var json2 = color.toJson();
2324
+ return (json1.r === json2.r &&
2325
+ json1.g === json2.g &&
2326
+ json1.b === json2.g &&
2327
+ json1.a === json2.a);
2328
+ }
2329
+ };
2330
+ /**
2331
+ * @description: 实例相加
2332
+ * @param {CssColorParser} colorParser
2333
+ * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
2334
+ * @return {CssColorParser}
2335
+ */
2336
+ CssColorParserPlus.prototype.add = function (color, isSetAlpha) {
2337
+ if (isSetAlpha === void 0) { isSetAlpha = true; }
2338
+ var colorParser = CssColorParserPlus.parseColor(color);
2339
+ return _super.prototype.add.call(this, colorParser, isSetAlpha);
2340
+ };
2341
+ /**
2342
+ * @description: 实例相减
2343
+ * @param {CssColorParser} colorParser
2344
+ * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
2345
+ * @return {CssColorParser}
2346
+ */
2347
+ CssColorParserPlus.prototype.subtract = function (color, isSetAlpha) {
2348
+ if (isSetAlpha === void 0) { isSetAlpha = true; }
2349
+ var colorParser = CssColorParserPlus.parseColor(color);
2350
+ return _super.prototype.subtract.call(this, colorParser, isSetAlpha);
2351
+ };
2352
+ /**
2353
+ * @description: 实例相乘
2354
+ * @param {CssColorParser} colorParser
2355
+ * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
2356
+ * @return {CssColorParser}
2357
+ */
2358
+ CssColorParserPlus.prototype.multiply = function (color, isSetAlpha) {
2359
+ if (isSetAlpha === void 0) { isSetAlpha = true; }
2360
+ var colorParser = CssColorParserPlus.parseColor(color);
2361
+ return _super.prototype.multiply.call(this, colorParser, isSetAlpha);
2362
+ };
2363
+ /**
2364
+ * @description: 实例相除
2365
+ * @param {CssColorParser} colorParser
2366
+ * @param {boolean} isSetAlpha 透明度值是否参与计算(默认:是)
2367
+ * @return {CssColorParser}
2368
+ */
2369
+ CssColorParserPlus.prototype.divide = function (color, isSetAlpha) {
2370
+ if (isSetAlpha === void 0) { isSetAlpha = true; }
2371
+ var colorParser = CssColorParserPlus.parseColor(color);
2372
+ return _super.prototype.divide.call(this, colorParser, isSetAlpha);
2373
+ };
2374
+ /**
2375
+ * @description: 解析css颜色
2376
+ * @param {string} v
2377
+ * @return {CssColorParserPlus}
2378
+ * @example: parseCssColorStr('rgba(255,255,255,1)')
2379
+ */
2380
+ CssColorParserPlus.parseColor = function (v) {
2381
+ if (v instanceof src_CssColorParser) {
2382
+ return v;
2383
+ }
2384
+ return CssColorParserPlus.parseCssColorStr(v);
2385
+ };
2386
+ /**
2387
+ * @description: 将css字符串转换为解析对象
2388
+ * @param {string} v
2389
+ * @return {CssColorParserPlus}
2390
+ * @example: parseCssColorStr('rgba(255,255,255,1)')
2391
+ */
2392
+ CssColorParserPlus.parseCssColorStr = function (v) {
2393
+ Check.type('color', v, 'string');
2394
+ return (CssColorParserPlus.parseHEX(v) ||
2395
+ CssColorParserPlus.parseRGBA(v) ||
2396
+ CssColorParserPlus.parseKeyWord(v) ||
2397
+ CssColorParserPlus.parseHSLA(v) ||
2398
+ CssColorParserPlus.parseHWB(v));
2399
+ };
2400
+ /**
2401
+ * @description: 解析颜色关键字
2402
+ * @param {string} v
2403
+ * @return {CssColorParserPlus}
2404
+ * @example: parseKeyWord('red')
2405
+ */
2406
+ CssColorParserPlus.parseKeyWord = function (v) {
2407
+ var cssStr = CssColorStringParser.clearStrSpace(v);
2408
+ var res = color_convert_default().keyword.rgb(cssStr);
2409
+ return res && CssColorParserPlus.fromArray(res);
2410
+ };
2411
+ /**
2412
+ * @description: 解析HSLA
2413
+ * @param {string} v
2414
+ * @return {CssColorParserPlus}
2415
+ * @example: parseHSLA('hsla(215,85%,62%,0.8)')
2416
+ */
2417
+ CssColorParserPlus.parseHSLA = function (v) {
2418
+ var cssStr = CssColorStringParser.clearStrSpace(v);
2419
+ var res = CssColorStringParser.parseHSLA(cssStr);
2420
+ if (!res) {
2421
+ var cssStr2 = CssColorStringParser.trimStr(v);
2422
+ res = CssColorStringParser.parseHSLA2(cssStr2);
2423
+ }
2424
+ return res && CssColorParserPlus.fromHSL(res[0], res[1], res[2], res[3]);
2425
+ };
2426
+ /**
2427
+ * @description: 解析HWB
2428
+ * @param {string} v
2429
+ * @return {CssColorParserPlus}
2430
+ * @example: parseHWB('hwb(215deg 30% 6% / 80%)')
2431
+ */
2432
+ CssColorParserPlus.parseHWB = function (v) {
1660
2433
  var cssStr2 = CssColorStringParser.trimStr(v);
1661
- res = CssColorStringParser.parseHSLA2(cssStr2);
1662
- }
1663
- return res && fromHSL(res[0], res[1], res[2], res[3]);
1664
- }
1665
- /**
1666
- * @description: 解析HWB
1667
- * @param {string} v
1668
- * @return {CssColorParser}
1669
- * @example: parseHWB('hwb(215deg 30% 6% / 80%)')
1670
- */
1671
- function parseHWB(v) {
1672
- var cssStr2 = CssColorStringParser.trimStr(v);
1673
- var res = CssColorStringParser.parseHWB(cssStr2);
1674
- return res && fromHWB(res[0], res[1], res[2], res[3]);
1675
- }
1676
- /**
1677
- * @description: 将css字符串转换为解析对象
1678
- * @param {string} v
1679
- * @return {CssColorParser}
1680
- * @example: parseCssColorStr('rgba(255,255,255,1)')
1681
- */
1682
- function parseCssColorStr(v) {
1683
- Check.type('string', 'color', v);
1684
- return parseHEX(v) || parseRGBA(v) || parseKeyWord(v) || parseHSLA(v) || parseHWB(v);
1685
- }
1686
- /**
1687
- * **Deprecated method.** Use `parseCssColorStr()` instead.
1688
- * @description: since 2.0.1
1689
- * @deprecated
1690
- * @param {string} v
1691
- * @return {CssColorParser}
1692
- * @example: fromColorStr('rgba(255,255,255,1)')
1693
- */
1694
- function fromColorStr(v) {
1695
- Check.type('string', 'color', v);
1696
- return parseHEX(v) || parseRGBA(v) || parseKeyWord(v) || parseHSLA(v) || parseHWB(v);
1697
- }
1698
- /**
1699
- * @description: 将HSL色彩模式转换为解析对象
1700
- * @param {number} hue 色相
1701
- * @param {number} saturation 饱和度
1702
- * @param {number} lightness 亮度
1703
- * @param {number} alpha 不透明度
1704
- * @return {CssColorParser}
1705
- * @example: fromHSL(0,1,1,1)
1706
- */
1707
- function fromHSL(h, s, l, a) {
1708
- var res = color_convert_default().hsl.rgb(limitNumber(0, 360, h), limitNumber(0, 100, s * 100), limitNumber(0, 100, l * 100));
1709
- return new src_CssColorParser(res[0], res[1], res[2], defaultValue(Number(a), 1));
1710
- }
1711
- /**
1712
- * @description: 将HWB色彩模式转换为解析对象
1713
- * @param {number} h 色调
1714
- * @param {number} w 白度
1715
- * @param {number} b 黑度
1716
- * @param {number} a 不透明度
1717
- * @return {CssColorParser}
1718
- * @example: fromHSL(0,1,1,1)
1719
- */
1720
- function fromHWB(h, w, b, a) {
1721
- var res = color_convert_default().hwb.rgb(limitNumber(0, 360, h), limitNumber(0, 100, w * 100), limitNumber(0, 100, b * 100));
1722
- return new src_CssColorParser(res[0], res[1], res[2], defaultValue(Number(a), 1));
1723
- }
1724
- /**
1725
- * @description: 产生随机颜色
1726
- * @return {CssColorParser}
1727
- * @example: fromRandom('#000', ''#fff)
1728
- */
1729
- function fromRandom(color1, color2) {
1730
- if (typeof color1 === 'string') {
1731
- color1 = parseCssColorStr(color1);
1732
- }
1733
- if (typeof color2 === 'string') {
1734
- color2 = parseCssColorStr(color2);
1735
- }
1736
- if (!color1 || !color2) {
1737
- throw new Error('fail to create object from random');
1738
- }
1739
- var r = Math.random() * Math.abs(color2.r - color1.r) +
1740
- Math.min(color1.r, color2.r);
1741
- var g = Math.random() * Math.abs(color2.g - color1.g) +
1742
- Math.min(color1.g, color2.g);
1743
- var b = Math.random() * Math.abs(color2.b - color1.b) +
1744
- Math.min(color1.b, color2.b);
1745
- var a = Math.random() * Math.abs(color2.a - color1.a) +
1746
- Math.min(color1.a, color2.a);
1747
- return new src_CssColorParser(r, g, b, a);
1748
- }
1749
- /**
1750
- * @description: 将ColorJson格式的json数据转换为解析对象
1751
- * @param {ColorJson} json
1752
- * @return {CssColorParser}
1753
- * @author: roman_123
1754
- */
1755
- function fromJson(json) {
1756
- return new src_CssColorParser(json.r, json.g, json.b, json.a);
1757
- }
1758
- /**
1759
- * @description: 将rgba数组转换为解析对象
1760
- * @param {Array} color
1761
- * @return {CssColorParser}
1762
- * @author: roman_123
1763
- */
1764
- function fromArray(color) {
1765
- return new src_CssColorParser(color[0], color[1], color[2], color[3]);
1766
- }
2434
+ var res = CssColorStringParser.parseHWB(cssStr2);
2435
+ return res && CssColorParserPlus.fromHWB(res[0], res[1], res[2], res[3]);
2436
+ };
2437
+ /**
2438
+ * @description: 将HSL色彩模式转换为解析对象
2439
+ * @param {number} hue 色相
2440
+ * @param {number} saturation 饱和度
2441
+ * @param {number} lightness 亮度
2442
+ * @param {number} alpha 不透明度
2443
+ * @return {CssColorParserPlus}
2444
+ * @example: fromHSL(0,1,1,1)
2445
+ */
2446
+ CssColorParserPlus.fromHSL = function (h, s, l, a) {
2447
+ var res = color_convert_default().hsl.rgb(limitNumber(0, 360, h), limitNumber(0, 100, s * 100), limitNumber(0, 100, l * 100));
2448
+ return new CssColorParserPlus(res[0], res[1], res[2], defaultValue(Number(a), 1));
2449
+ };
2450
+ /**
2451
+ * @description: 将HWB色彩模式转换为解析对象
2452
+ * @param {number} h 色调
2453
+ * @param {number} w 白度
2454
+ * @param {number} b 黑度
2455
+ * @param {number} a 不透明度
2456
+ * @return {CssColorParserPlus}
2457
+ * @example: fromHSL(0,1,1,1)
2458
+ */
2459
+ CssColorParserPlus.fromHWB = function (h, w, b, a) {
2460
+ var res = color_convert_default().hwb.rgb(limitNumber(0, 360, h), limitNumber(0, 100, w * 100), limitNumber(0, 100, b * 100));
2461
+ return new CssColorParserPlus(res[0], res[1], res[2], defaultValue(Number(a), 1));
2462
+ };
2463
+ /**
2464
+ * @description: 解析16进制颜色
2465
+ * @param {string} v
2466
+ * @return {CssColorParserPlus}
2467
+ * @example: CssColorParserPlus.parseHEX('#FFF')
2468
+ */
2469
+ CssColorParserPlus.parseHEX = function (v) {
2470
+ var cssStr = CssColorStringParser.clearStrSpace(v);
2471
+ var res = CssColorStringParser.parse3BitsHEX(cssStr);
2472
+ if (!res) {
2473
+ res = CssColorStringParser.parse6BitsHEX(cssStr);
2474
+ }
2475
+ return res && CssColorParserPlus.fromArray(res);
2476
+ };
2477
+ /**
2478
+ * @description: 解析rgba、rgb颜色
2479
+ * @param {string} v
2480
+ * @return {CssColorParserPlus}
2481
+ * @example: CssColorParserPlus.parseRGBA('rgba(255,255,255,1)')
2482
+ */
2483
+ CssColorParserPlus.parseRGBA = function (v) {
2484
+ var cssStr = CssColorStringParser.clearStrSpace(v);
2485
+ var res = CssColorStringParser.parseRGBA(cssStr);
2486
+ if (!res) {
2487
+ var cssStr2 = CssColorStringParser.trimStr(v);
2488
+ res = CssColorStringParser.parseRGBA2(cssStr2);
2489
+ }
2490
+ return res && CssColorParserPlus.fromArray(res);
2491
+ };
2492
+ /**
2493
+ * @description: 将ColorJson格式的json数据转换为解析对象
2494
+ * @param {ColorJson} json
2495
+ * @return {CssColorParserPlus}
2496
+ * @example: CssColorParserPlus.fromJson({r: 255, g: 255, b: 255, a: 1})
2497
+ */
2498
+ CssColorParserPlus.fromJson = function (json) {
2499
+ return new CssColorParserPlus(json.r, json.g, json.b, json.a);
2500
+ };
2501
+ /**
2502
+ * @description: 将RGBA数组转换为解析对象
2503
+ * @param {Array} color
2504
+ * @return {CssColorParserPlus}
2505
+ * @example: CssColorParserPlus.fromArray([255,255,255,1])
2506
+ */
2507
+ CssColorParserPlus.fromArray = function (color) {
2508
+ return new CssColorParserPlus(color[0], color[1], color[2], color[3]);
2509
+ };
2510
+ /**
2511
+ * @description: 产生随机颜色
2512
+ * @return {CssColorParserPlus}
2513
+ * @example: CssColorParserPlus.fromRandom('black', new CssColorParserPlus(255,255,255,1))
2514
+ */
2515
+ CssColorParserPlus.fromRandom = function (color1, color2) {
2516
+ color1 = CssColorParserPlus.parseColor(color1);
2517
+ color2 = CssColorParserPlus.parseColor(color2);
2518
+ var r = Math.random() * Math.abs(color2.r - color1.r) +
2519
+ Math.min(color1.r, color2.r);
2520
+ var g = Math.random() * Math.abs(color2.g - color1.g) +
2521
+ Math.min(color1.g, color2.g);
2522
+ var b = Math.random() * Math.abs(color2.b - color1.b) +
2523
+ Math.min(color1.b, color2.b);
2524
+ var a = Math.random() * Math.abs(color2.a - color1.a) +
2525
+ Math.min(color1.a, color2.a);
2526
+ return new CssColorParserPlus(r, g, b, a);
2527
+ };
2528
+ /**
2529
+ * @description: 颜色序列化数组转换为CssColorParserPlus对象实例
2530
+ * @param {array} colorArr
2531
+ * @example: CssColorParserPlus.fromNormaliz([1, 0, 0, 1])
2532
+ */
2533
+ CssColorParserPlus.fromNormalize = function (colorArr) {
2534
+ var r = colorArr[0] * 255;
2535
+ var g = colorArr[1] * 255;
2536
+ var b = colorArr[2] * 255;
2537
+ var a = colorArr[3];
2538
+ return CssColorParserPlus.fromArray([r, g, b, a]);
2539
+ };
2540
+ return CssColorParserPlus;
2541
+ }(src_CssColorParser));
2542
+ /* harmony default export */ var src_CssColorParserPlus = (CssColorParserPlus);
1767
2543
 
1768
2544
  ;// CONCATENATED MODULE: ./src/main.ts
1769
2545
  /*
1770
2546
  * @Author: roman_123
1771
2547
  * @Description:
1772
2548
  * @Date: 2023-05-25 17:45:22
1773
- * @LastEditTime: 2023-05-26 15:54:02
2549
+ * @LastEditTime: 2023-06-27 18:45:32
1774
2550
  */
1775
2551
 
1776
2552