css-color-parser-h 1.0.4 → 2.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.
@@ -0,0 +1,578 @@
1
+ /******/ (function() { // webpackBootstrap
2
+ /******/ "use strict";
3
+ /******/ var __webpack_modules__ = ({
4
+
5
+ /***/ 819:
6
+ /***/ (function(module) {
7
+
8
+ module.exports = require("color-convert");
9
+
10
+ /***/ })
11
+
12
+ /******/ });
13
+ /************************************************************************/
14
+ /******/ // The module cache
15
+ /******/ var __webpack_module_cache__ = {};
16
+ /******/
17
+ /******/ // The require function
18
+ /******/ function __webpack_require__(moduleId) {
19
+ /******/ // Check if module is in cache
20
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
21
+ /******/ if (cachedModule !== undefined) {
22
+ /******/ return cachedModule.exports;
23
+ /******/ }
24
+ /******/ // Create a new module (and put it into the cache)
25
+ /******/ var module = __webpack_module_cache__[moduleId] = {
26
+ /******/ // no module.id needed
27
+ /******/ // no module.loaded needed
28
+ /******/ exports: {}
29
+ /******/ };
30
+ /******/
31
+ /******/ // Execute the module function
32
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
33
+ /******/
34
+ /******/ // Return the exports of the module
35
+ /******/ return module.exports;
36
+ /******/ }
37
+ /******/
38
+ /************************************************************************/
39
+ /******/ /* webpack/runtime/define property getters */
40
+ /******/ !function() {
41
+ /******/ // define getter functions for harmony exports
42
+ /******/ __webpack_require__.d = function(exports, definition) {
43
+ /******/ for(var key in definition) {
44
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
45
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
46
+ /******/ }
47
+ /******/ }
48
+ /******/ };
49
+ /******/ }();
50
+ /******/
51
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
52
+ /******/ !function() {
53
+ /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
54
+ /******/ }();
55
+ /******/
56
+ /******/ /* webpack/runtime/make namespace object */
57
+ /******/ !function() {
58
+ /******/ // define __esModule on exports
59
+ /******/ __webpack_require__.r = function(exports) {
60
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
61
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
62
+ /******/ }
63
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
64
+ /******/ };
65
+ /******/ }();
66
+ /******/
67
+ /************************************************************************/
68
+ var __webpack_exports__ = {};
69
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
70
+ !function() {
71
+ // ESM COMPAT FLAG
72
+ __webpack_require__.r(__webpack_exports__);
73
+
74
+ // EXPORTS
75
+ __webpack_require__.d(__webpack_exports__, {
76
+ "CssColorParser": function() { return /* reexport */ src_CssColorParser; },
77
+ "fromArray": function() { return /* reexport */ fromArray; },
78
+ "fromColorStr": function() { return /* reexport */ fromColorStr; },
79
+ "fromHSL": function() { return /* reexport */ fromHSL; },
80
+ "fromHWB": function() { return /* reexport */ fromHWB; },
81
+ "fromJson": function() { return /* reexport */ fromJson; },
82
+ "fromRandom": function() { return /* reexport */ fromRandom; },
83
+ "parseCssColorStr": function() { return /* reexport */ parseCssColorStr; },
84
+ "parseHEX": function() { return /* reexport */ parseHEX; },
85
+ "parseHSLA": function() { return /* reexport */ parseHSLA; },
86
+ "parseHWB": function() { return /* reexport */ parseHWB; },
87
+ "parseKeyWord": function() { return /* reexport */ parseKeyWord; },
88
+ "parseRGBA": function() { return /* reexport */ parseRGBA; }
89
+ });
90
+
91
+ ;// CONCATENATED MODULE: ./src/utils/common.ts
92
+ var Check = /** @class */ (function () {
93
+ function Check() {
94
+ }
95
+ Check.type = function (type, paramName, value) {
96
+ var valueType = typeof value;
97
+ if (valueType !== type) {
98
+ throw new Error("Expected ".concat(paramName, " to be typeof ").concat(type, ", actual typeof was ").concat(valueType));
99
+ }
100
+ };
101
+ Check.types = function (types, paramName, value) {
102
+ var valueType = typeof value;
103
+ var isContained = types.includes(valueType);
104
+ if (!isContained) {
105
+ throw new Error("Expected ".concat(paramName, " to be typeof ").concat(types.join('|'), ", actual typeof was ").concat(valueType));
106
+ }
107
+ };
108
+ return Check;
109
+ }());
110
+
111
+ var ColorJson = /** @class */ (function () {
112
+ function ColorJson() {
113
+ }
114
+ return ColorJson;
115
+ }());
116
+
117
+ function defaultValue(v, defaultV) {
118
+ if (v === undefined || v === null) {
119
+ return defaultV;
120
+ }
121
+ if (isNaN(v) && typeof defaultV === 'number') {
122
+ return defaultV;
123
+ }
124
+ return v;
125
+ }
126
+ function limitNumber(min, max, v) {
127
+ if (v > max) {
128
+ v = max;
129
+ }
130
+ else if (v < min) {
131
+ v = min;
132
+ }
133
+ return v;
134
+ }
135
+ function setNumberPrecision(number, precision) {
136
+ return Number(number.toFixed(precision));
137
+ }
138
+
139
+ ;// CONCATENATED MODULE: ./src/CssColorParser.ts
140
+ /*
141
+ * @Descripttion: 颜色解析器
142
+ * @version: 1.0.0
143
+ * @Author: roman_123
144
+ * @Date: 2021-01-19 09:22:11
145
+ * @LastEditors: Please set LastEditors
146
+ * @LastEditTime: 2023-05-26 11:20:17
147
+ */
148
+
149
+ var CssColorParser = /** @class */ (function () {
150
+ function CssColorParser(red, green, blue, alpha) {
151
+ this.r = 255;
152
+ this.g = 255;
153
+ this.b = 255;
154
+ this.a = 1;
155
+ this.setColor(red, green, blue, alpha);
156
+ }
157
+ /**
158
+ * 设置颜色
159
+ * @param red
160
+ * @param green
161
+ * @param blue
162
+ * @param alpha
163
+ * @example: this.setColor(255,255,255,1)
164
+ */
165
+ CssColorParser.prototype.setColor = function (red, green, blue, alpha) {
166
+ this.r = limitNumber(0, 255, defaultValue(Number(red), 0));
167
+ this.g = limitNumber(0, 255, defaultValue(Number(green), 0));
168
+ this.b = limitNumber(0, 255, defaultValue(Number(blue), 0));
169
+ this.a = limitNumber(0, 1, defaultValue(Number(alpha), 1));
170
+ };
171
+ /**
172
+ * @description: 返回rgba格式的css字符串
173
+ * @return {*}
174
+ * @author: roman_123
175
+ */
176
+ CssColorParser.prototype.toRGBA = function () {
177
+ var color = this.toJson();
178
+ if (color.a === 1) {
179
+ return "rgb(".concat(color.r, ",").concat(color.g, ",").concat(color.b, ")");
180
+ }
181
+ return "rgba(".concat(color.r, ",").concat(color.g, ",").concat(color.b, ",").concat(color.a, ")");
182
+ };
183
+ /**
184
+ * @description: 返回字符串
185
+ * @return {*}
186
+ * @author: roman_123
187
+ */
188
+ CssColorParser.prototype.toString = function () {
189
+ return this.toRGBA();
190
+ };
191
+ /**
192
+ * @description: 归一化
193
+ * @return {*}
194
+ * @author: roman_123
195
+ */
196
+ CssColorParser.prototype.toNormalize = function () {
197
+ return {
198
+ r: setNumberPrecision(this.r / 255, 2),
199
+ g: setNumberPrecision(this.g / 255, 2),
200
+ b: setNumberPrecision(this.b / 255, 2),
201
+ a: setNumberPrecision(this.a, 2)
202
+ };
203
+ };
204
+ /**
205
+ * @description: 返回16进制格式的css字符串
206
+ * @return {*}
207
+ * @author: roman_123
208
+ */
209
+ CssColorParser.prototype.toHEX = function () {
210
+ var color = this.toJson();
211
+ var r = color.r.toString(16);
212
+ if (r.length < 2) {
213
+ r = "0".concat(r);
214
+ }
215
+ var g = color.g.toString(16);
216
+ if (g.length < 2) {
217
+ g = "0".concat(g);
218
+ }
219
+ var b = color.b.toString(16);
220
+ if (b.length < 2) {
221
+ b = "0".concat(b);
222
+ }
223
+ // 由于tojson后a会丢失精度,此处使用this.a
224
+ if (this.a < 1) {
225
+ var hexAlpha = parseInt((this.a * 255).toFixed()).toString(16);
226
+ if (hexAlpha.length < 2) {
227
+ hexAlpha = "0".concat(hexAlpha);
228
+ }
229
+ return "#".concat(r).concat(g).concat(b).concat(hexAlpha);
230
+ }
231
+ return "#".concat(r).concat(g).concat(b);
232
+ };
233
+ /**
234
+ * @description: 返回rgba数组
235
+ * @return {*}
236
+ * @author: roman_123
237
+ */
238
+ CssColorParser.prototype.toArray = function () {
239
+ var color = this.toJson();
240
+ return [color.r, color.g, color.b, color.a];
241
+ };
242
+ /**
243
+ * @description: 返回ColorJson
244
+ * @return {*}
245
+ * @author: roman_123
246
+ */
247
+ CssColorParser.prototype.toJson = function () {
248
+ return {
249
+ r: parseInt(this.r.toFixed()),
250
+ g: parseInt(this.g.toFixed()),
251
+ b: parseInt(this.b.toFixed()),
252
+ a: parseFloat(this.a.toFixed(2))
253
+ };
254
+ };
255
+ /**
256
+ * @description: 拷贝
257
+ * @return {*}
258
+ * @author: roman_123
259
+ */
260
+ CssColorParser.prototype.clone = function () {
261
+ return new CssColorParser(this.r, this.g, this.b, this.a);
262
+ };
263
+ /**
264
+ * @description: 比较两个解析对象的数据是否相等
265
+ * @param {*} color
266
+ * @return {*}
267
+ * @author: roman_123
268
+ */
269
+ CssColorParser.prototype.equals = function (color) {
270
+ if (this === color) {
271
+ return true;
272
+ }
273
+ else {
274
+ return (this.r === color.r &&
275
+ this.g === color.g &&
276
+ this.b === color.g &&
277
+ this.a === color.a);
278
+ }
279
+ };
280
+ return CssColorParser;
281
+ }());
282
+ /* harmony default export */ var src_CssColorParser = (CssColorParser);
283
+
284
+ ;// CONCATENATED MODULE: ./src/utils/color-tools.ts
285
+
286
+ /*
287
+ * @Author: roman_123
288
+ * @Description: 部分核心代码修改自cesium
289
+ * @Date: 2022-11-28 17:32:57
290
+ * @LastEditTime: 2022-12-06 00:02:21
291
+ */
292
+ var CssColorStringParser = /** @class */ (function () {
293
+ function CssColorStringParser() {
294
+ }
295
+ // 去除字符串内所有空格
296
+ CssColorStringParser.clearStrSpace = function (v) {
297
+ return v.replace(/\s/g, '');
298
+ };
299
+ // 去除字符串两边空格,将中间多个空格合并为一个
300
+ CssColorStringParser.trimStr = function (v) {
301
+ v = v.replace(/\s+/g, ' ');
302
+ return v.trim();
303
+ };
304
+ // 解析3位16进制 #fff #fff0
305
+ CssColorStringParser.parse3BitsHEX = function (v) {
306
+ var regx = /^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i;
307
+ var res = regx.exec(v);
308
+ if (res) {
309
+ var res4 = defaultValue(res[4], 'f');
310
+ var r = CssColorStringParser._parseResStrForRgb(parseInt(res[1] + res[1], 16));
311
+ var g = CssColorStringParser._parseResStrForRgb(parseInt(res[2] + res[2], 16));
312
+ var b = CssColorStringParser._parseResStrForRgb(parseInt(res[3] + res[3], 16));
313
+ var a = CssColorStringParser._parsePercent(parseInt(res4 + res4, 16) / 255);
314
+ return [r, g, b, a];
315
+ }
316
+ return null;
317
+ };
318
+ // 解析6位16进制 #ffffff #ffffff00
319
+ CssColorStringParser.parse6BitsHEX = function (v) {
320
+ var regx = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i;
321
+ var res = regx.exec(v);
322
+ if (res) {
323
+ var res4 = defaultValue(res[4], 'ff');
324
+ var r = CssColorStringParser._parseResStrForRgb(parseInt(res[1], 16));
325
+ var g = CssColorStringParser._parseResStrForRgb(parseInt(res[2], 16));
326
+ var b = CssColorStringParser._parseResStrForRgb(parseInt(res[3], 16));
327
+ var a = CssColorStringParser._parsePercent(parseInt(res4, 16) / 255.0);
328
+ return [r, g, b, a];
329
+ }
330
+ return null;
331
+ };
332
+ // 解析rgb rgba rgb(255,255,255) rgba(255,255,255,1) rgba(100%,100%,100%, 1)
333
+ CssColorStringParser.parseRGBA = function (v) {
334
+ var regx = /^rgba?\(([0-9.]+%?),([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i;
335
+ var res = regx.exec(v);
336
+ if (res) {
337
+ var r = CssColorStringParser._parseResStrForRgb(res[1]);
338
+ var g = CssColorStringParser._parseResStrForRgb(res[2]);
339
+ var b = CssColorStringParser._parseResStrForRgb(res[3]);
340
+ var a = CssColorStringParser._parsePercent(res[4]);
341
+ return [r, g, b, a];
342
+ }
343
+ return null;
344
+ };
345
+ // 解析hsl hsla hsl(360,100%,100%) hsla(360,100%,100%,1)
346
+ CssColorStringParser.parseHSLA = function (v) {
347
+ var regx = /^hsla?\(([0-9.]+)(?:deg)?,([0-9.]+%?),([0-9.]+%?)(?:,([0-9.]+%?))?\)$/i;
348
+ var res = regx.exec(v);
349
+ if (res) {
350
+ var h = CssColorStringParser._parseResStrForHue(res[1]);
351
+ var s = CssColorStringParser._parsePercent(res[2]);
352
+ var l = CssColorStringParser._parsePercent(res[3]);
353
+ var a = CssColorStringParser._parsePercent(res[4]);
354
+ return [h, s, l, a];
355
+ }
356
+ return null;
357
+ };
358
+ // 解析hwb
359
+ CssColorStringParser.parseHWB = function (v) {
360
+ var regx = /^hwb\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i;
361
+ var res = regx.exec(v);
362
+ if (res) {
363
+ var h = CssColorStringParser._parseResStrForHue(res[1]);
364
+ var w = CssColorStringParser._parsePercent(res[2]);
365
+ var b = CssColorStringParser._parsePercent(res[3]);
366
+ var a = CssColorStringParser._parsePercent(res[4]);
367
+ return [h, w, b, a];
368
+ }
369
+ return null;
370
+ };
371
+ // 解析rgb rgb(178 57 57 / 44%) 字符串中存在空格,因此使用清除两侧空格的原始字符串
372
+ CssColorStringParser.parseRGBA2 = function (v) {
373
+ var regx = /^rgba?\s?\(\s?([0-9.]+%?)\s?([0-9.]+%?)\s?([0-9.]+%?)(?:\s?\/\s?([0-9.]+%?))?\s?\)$/i;
374
+ var res = regx.exec(v);
375
+ if (res) {
376
+ var r = CssColorStringParser._parseResStrForRgb(res[1]);
377
+ var g = CssColorStringParser._parseResStrForRgb(res[2]);
378
+ var b = CssColorStringParser._parseResStrForRgb(res[3]);
379
+ var a = CssColorStringParser._parsePercent(res[4]);
380
+ return [r, g, b, a];
381
+ }
382
+ return null;
383
+ };
384
+ // 解析hsl hsl(215 85% 62% / 1)
385
+ CssColorStringParser.parseHSLA2 = function (v) {
386
+ var regx = /^hsla?\s?\(\s?([0-9.]+)(?:deg)?\s([0-9.]+%?)\s([0-9.]+%?)\s?(?:\/\s?([0-9.]+%?))?\s?\)$/i;
387
+ var res = regx.exec(v);
388
+ if (res) {
389
+ var h = CssColorStringParser._parseResStrForHue(res[1]);
390
+ var s = CssColorStringParser._parsePercent(res[2]);
391
+ var l = CssColorStringParser._parsePercent(res[3]);
392
+ var a = CssColorStringParser._parsePercent(res[4]);
393
+ return [h, s, l, a];
394
+ }
395
+ return null;
396
+ };
397
+ // 将结果解析为数字
398
+ CssColorStringParser._parseResStrForRgb = function (v) {
399
+ if (typeof v === 'string') {
400
+ v = parseFloat(v) / ('%' === v.substr(-1) ? 100.0 / 255 : 1);
401
+ }
402
+ if (isNaN(v)) {
403
+ v = 1;
404
+ }
405
+ return limitNumber(0, 255, v);
406
+ };
407
+ CssColorStringParser._parseResStrForHue = function (v) {
408
+ if (typeof v === 'string') {
409
+ v = parseFloat(v);
410
+ }
411
+ if (isNaN(v)) {
412
+ v = 0;
413
+ }
414
+ return limitNumber(0, 360, v);
415
+ };
416
+ CssColorStringParser._parsePercent = function (v) {
417
+ if (typeof v === 'string') {
418
+ v = parseFloat(v) / ('%' === v.substr(-1) ? 100.0 : 1);
419
+ }
420
+ if (isNaN(v)) {
421
+ v = 1;
422
+ }
423
+ return limitNumber(0, 1, v);
424
+ };
425
+ return CssColorStringParser;
426
+ }());
427
+
428
+
429
+ ;// CONCATENATED MODULE: ./src/utils/parsers/parsers.ts
430
+
431
+
432
+
433
+ var convert = __webpack_require__(819);
434
+ function parseKeyWord(v) {
435
+ var cssStr = CssColorStringParser.clearStrSpace(v);
436
+ var res = convert.keyword.rgb(cssStr);
437
+ return res && fromArray(res);
438
+ }
439
+ function parseHEX(v) {
440
+ var cssStr = CssColorStringParser.clearStrSpace(v);
441
+ var res = CssColorStringParser.parse3BitsHEX(cssStr);
442
+ if (!res) {
443
+ res = CssColorStringParser.parse6BitsHEX(cssStr);
444
+ }
445
+ return res && fromArray(res);
446
+ }
447
+ function parseRGBA(v) {
448
+ var cssStr = CssColorStringParser.clearStrSpace(v);
449
+ var res = CssColorStringParser.parseRGBA(cssStr);
450
+ if (!res) {
451
+ var cssStr2 = CssColorStringParser.trimStr(v);
452
+ res = CssColorStringParser.parseRGBA2(cssStr2);
453
+ }
454
+ return res && fromArray(res);
455
+ }
456
+ function parseHSLA(v) {
457
+ var cssStr = CssColorStringParser.clearStrSpace(v);
458
+ var res = CssColorStringParser.parseHSLA(cssStr);
459
+ if (!res) {
460
+ var cssStr2 = CssColorStringParser.trimStr(v);
461
+ res = CssColorStringParser.parseHSLA2(cssStr2);
462
+ }
463
+ return res && fromHSL(res[0], res[1], res[2], res[3]);
464
+ }
465
+ function parseHWB(v) {
466
+ var cssStr2 = CssColorStringParser.trimStr(v);
467
+ var res = CssColorStringParser.parseHWB(cssStr2);
468
+ return res && fromHWB(res[0], res[1], res[2], res[3]);
469
+ }
470
+ /**
471
+ * @description: 将css字符串转换为解析对象
472
+ * @param {string} v
473
+ * @return {CssColorParser}
474
+ * @example: parseCssColorStr('rgba(255,255,255,1)')
475
+ */
476
+ function parseCssColorStr(v) {
477
+ Check.type('string', 'color', v);
478
+ return parseHEX(v) || parseRGBA(v) || parseKeyWord(v) || parseHSLA(v) || parseHWB(v);
479
+ }
480
+ /**
481
+ * **Deprecated method.** Use `parseCssColorStr()` instead.
482
+ * @description: since 2.0.1
483
+ * @deprecated
484
+ * @param {string} v
485
+ * @return {CssColorParser}
486
+ * @example: fromColorStr('rgba(255,255,255,1)')
487
+ */
488
+ function fromColorStr(v) {
489
+ Check.type('string', 'color', v);
490
+ return parseHEX(v) || parseRGBA(v) || parseKeyWord(v) || parseHSLA(v) || parseHWB(v);
491
+ }
492
+ /**
493
+ * @description: 将HSL色彩模式转换为解析对象
494
+ * @param {number} hue 色相
495
+ * @param {number} saturation 饱和度
496
+ * @param {number} lightness 亮度
497
+ * @param {number} alpha 不透明度
498
+ * @return {CssColorParser}
499
+ * @example: fromHSL(0,1,1,1)
500
+ */
501
+ function fromHSL(h, s, l, a) {
502
+ var res = convert.hsl.rgb(limitNumber(0, 360, h), limitNumber(0, 100, s * 100), limitNumber(0, 100, l * 100));
503
+ return new src_CssColorParser(res[0], res[1], res[2], defaultValue(Number(a), 1));
504
+ }
505
+ /**
506
+ * @description: 将HWB色彩模式转换为解析对象
507
+ * @param {number} h 色调
508
+ * @param {number} w 白度
509
+ * @param {number} b 黑度
510
+ * @param {number} a 不透明度
511
+ * @return {CssColorParser}
512
+ * @example: fromHSL(0,1,1,1)
513
+ */
514
+ function fromHWB(h, w, b, a) {
515
+ var res = convert.hwb.rgb(limitNumber(0, 360, h), limitNumber(0, 100, w * 100), limitNumber(0, 100, b * 100));
516
+ return new src_CssColorParser(res[0], res[1], res[2], defaultValue(Number(a), 1));
517
+ }
518
+ /**
519
+ * @description: 从解析器中产生随机颜色
520
+ * @return {CssColorParser}
521
+ * @author: roman_123
522
+ */
523
+ function fromRandom(color1, color2) {
524
+ if (typeof color1 === 'string') {
525
+ color1 = parseCssColorStr(color1);
526
+ }
527
+ if (typeof color2 === 'string') {
528
+ color2 = parseCssColorStr(color2);
529
+ }
530
+ if (!color1 || !color2) {
531
+ throw new Error('fail to create object from random');
532
+ }
533
+ var r = Math.random() * Math.abs(color2.r - color1.r) +
534
+ Math.min(color1.r, color2.r);
535
+ var g = Math.random() * Math.abs(color2.g - color1.g) +
536
+ Math.min(color1.g, color2.g);
537
+ var b = Math.random() * Math.abs(color2.b - color1.b) +
538
+ Math.min(color1.b, color2.b);
539
+ var a = Math.random() * Math.abs(color2.a - color1.a) +
540
+ Math.min(color1.a, color2.a);
541
+ return new src_CssColorParser(r, g, b, a);
542
+ }
543
+ /**
544
+ * @description: 将ColorJson格式的json数据转换为解析对象
545
+ * @param {ColorJson} json
546
+ * @return {CssColorParser}
547
+ * @author: roman_123
548
+ */
549
+ function fromJson(json) {
550
+ return new src_CssColorParser(json.r, json.g, json.b, json.a);
551
+ }
552
+ /**
553
+ * @description: 将rgba数组转换为解析对象
554
+ * @param {Array} color
555
+ * @return {CssColorParser}
556
+ * @author: roman_123
557
+ */
558
+ function fromArray(color) {
559
+ return new src_CssColorParser(color[0], color[1], color[2], color[3]);
560
+ }
561
+
562
+ ;// CONCATENATED MODULE: ./src/main.ts
563
+ /*
564
+ * @Author: roman_123
565
+ * @Description:
566
+ * @Date: 2023-05-25 17:45:22
567
+ * @LastEditTime: 2023-05-26 11:17:48
568
+ */
569
+
570
+
571
+
572
+
573
+ }();
574
+ var __webpack_export_target__ = exports;
575
+ for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
576
+ if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
577
+ /******/ })()
578
+ ;
@@ -0,0 +1 @@
1
+ !function(){"use strict";var r={819:function(r){r.exports=require("color-convert")}},t={};function e(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return r[n](a,a.exports,e),a.exports}e.d=function(r,t){for(var n in t)e.o(t,n)&&!e.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:t[n]})},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})};var n={};!function(){e.r(n),e.d(n,{CssColorParser:function(){return s},fromArray:function(){return _},fromColorStr:function(){return h},fromHSL:function(){return S},fromHWB:function(){return v},fromJson:function(){return R},fromRandom:function(){return y},parseCssColorStr:function(){return l},parseHEX:function(){return p},parseHSLA:function(){return b},parseHWB:function(){return g},parseKeyWord:function(){return u},parseRGBA:function(){return f}});var r=function(){function r(){}return r.type=function(r,t,e){var n=typeof e;if(n!==r)throw new Error("Expected ".concat(t," to be typeof ").concat(r,", actual typeof was ").concat(n))},r.types=function(r,t,e){var n=typeof e;if(!r.includes(n))throw new Error("Expected ".concat(t," to be typeof ").concat(r.join("|"),", actual typeof was ").concat(n))},r}();function t(r,t){return null==r||isNaN(r)&&"number"==typeof t?t:r}function o(r,t,e){return e>t?e=t:e<r&&(e=r),e}function a(r,t){return Number(r.toFixed(t))}var s=function(){function r(r,t,e,n){this.r=255,this.g=255,this.b=255,this.a=1,this.setColor(r,t,e,n)}return r.prototype.setColor=function(r,e,n,a){this.r=o(0,255,t(Number(r),0)),this.g=o(0,255,t(Number(e),0)),this.b=o(0,255,t(Number(n),0)),this.a=o(0,1,t(Number(a),1))},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{r:a(this.r/255,2),g:a(this.g/255,2),b:a(this.b/255,2),a:a(this.a,2)}},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 n=r.b.toString(16);if(n.length<2&&(n="0".concat(n)),this.a<1){var o=parseInt((255*this.a).toFixed()).toString(16);return o.length<2&&(o="0".concat(o)),"#".concat(t).concat(e).concat(n).concat(o)}return"#".concat(t).concat(e).concat(n)},r.prototype.toArray=function(){var r=this.toJson();return[r.r,r.g,r.b,r.a]},r.prototype.toJson=function(){return{r:parseInt(this.r.toFixed()),g:parseInt(this.g.toFixed()),b:parseInt(this.b.toFixed()),a:parseFloat(this.a.toFixed(2))}},r.prototype.clone=function(){return new r(this.r,this.g,this.b,this.a)},r.prototype.equals=function(r){return this===r||this.r===r.r&&this.g===r.g&&this.b===r.g&&this.a===r.a},r}(),c=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(e){var n=/^#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])?$/i.exec(e);if(n){var o=t(n[4],"f");return[r._parseResStrForRgb(parseInt(n[1]+n[1],16)),r._parseResStrForRgb(parseInt(n[2]+n[2],16)),r._parseResStrForRgb(parseInt(n[3]+n[3],16)),r._parsePercent(parseInt(o+o,16)/255)]}return null},r.parse6BitsHEX=function(e){var n=/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})?$/i.exec(e);if(n){var o=t(n[4],"ff");return[r._parseResStrForRgb(parseInt(n[1],16)),r._parseResStrForRgb(parseInt(n[2],16)),r._parseResStrForRgb(parseInt(n[3],16)),r._parsePercent(parseInt(o,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),o(0,255,r)},r._parseResStrForHue=function(r){return"string"==typeof r&&(r=parseFloat(r)),isNaN(r)&&(r=0),o(0,360,r)},r._parsePercent=function(r){return"string"==typeof r&&(r=parseFloat(r)/("%"===r.substr(-1)?100:1)),isNaN(r)&&(r=1),o(0,1,r)},r}(),i=e(819);function u(r){var t=c.clearStrSpace(r),e=i.keyword.rgb(t);return e&&_(e)}function p(r){var t=c.clearStrSpace(r),e=c.parse3BitsHEX(t);return e||(e=c.parse6BitsHEX(t)),e&&_(e)}function f(r){var t=c.clearStrSpace(r),e=c.parseRGBA(t);if(!e){var n=c.trimStr(r);e=c.parseRGBA2(n)}return e&&_(e)}function b(r){var t=c.clearStrSpace(r),e=c.parseHSLA(t);if(!e){var n=c.trimStr(r);e=c.parseHSLA2(n)}return e&&S(e[0],e[1],e[2],e[3])}function g(r){var t=c.trimStr(r),e=c.parseHWB(t);return e&&v(e[0],e[1],e[2],e[3])}function l(t){return r.type("string","color",t),p(t)||f(t)||u(t)||b(t)||g(t)}function h(t){return r.type("string","color",t),p(t)||f(t)||u(t)||b(t)||g(t)}function S(r,e,n,a){var c=i.hsl.rgb(o(0,360,r),o(0,100,100*e),o(0,100,100*n));return new s(c[0],c[1],c[2],t(Number(a),1))}function v(r,e,n,a){var c=i.hwb.rgb(o(0,360,r),o(0,100,100*e),o(0,100,100*n));return new s(c[0],c[1],c[2],t(Number(a),1))}function y(r,t){if("string"==typeof r&&(r=l(r)),"string"==typeof t&&(t=l(t)),!r||!t)throw new Error("fail to create object from random");var e=Math.random()*Math.abs(t.r-r.r)+Math.min(r.r,t.r),n=Math.random()*Math.abs(t.g-r.g)+Math.min(r.g,t.g),o=Math.random()*Math.abs(t.b-r.b)+Math.min(r.b,t.b),a=Math.random()*Math.abs(t.a-r.a)+Math.min(r.a,t.a);return new s(e,n,o,a)}function R(r){return new s(r.r,r.g,r.b,r.a)}function _(r){return new s(r[0],r[1],r[2],r[3])}}();var o=exports;for(var a in n)o[a]=n[a];n.__esModule&&Object.defineProperty(o,"__esModule",{value:!0})}();