@cowave-cli/utils 2.5.3

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/dist/vue.cjs ADDED
@@ -0,0 +1,1846 @@
1
+ 'use strict';
2
+
3
+ var axios = require('axios');
4
+ var lodash = require('lodash');
5
+ var vue = require('vue');
6
+
7
+ /*
8
+ * @Description: 字符串处理
9
+ * @Author: Zye
10
+ * @Date: 2024-03-11
11
+ */
12
+ /**
13
+ * @deprecated 这个函数已弃用,请使用 toHump() 代替
14
+ */
15
+ const pathToHump = (path, isGreatHump = true) => {
16
+ if (isGreatHump) {
17
+ path = path.replace(/^([a-z])/g, (_, p1) => p1.toUpperCase());
18
+ }
19
+ path = path.replace(/-([a-z])/g, (_, p1) => p1.toUpperCase());
20
+ return path;
21
+ };
22
+ /**
23
+ * 将连接符字符串转换为驼峰字符串
24
+ *
25
+ * @param strings 字符串(列表)
26
+ * @param hyphenType 连接符
27
+ * @param isGreatHump 是否为大驼峰
28
+ * @returns humpString
29
+ */
30
+ const toHump = (strings, hyphenType = '-', isGreatHump = false) => {
31
+ hyphenType = hyphenType || '-';
32
+ const results = (typeof strings === 'string' ? [strings] : strings).map(string => {
33
+ if (isGreatHump) {
34
+ string = string.replace(/^([a-z])/g, (_, p1) => p1.toUpperCase());
35
+ }
36
+ string = string.replace(new RegExp(hyphenType + '([a-z])', 'g'), (_, p1) => p1.toUpperCase());
37
+ return string;
38
+ });
39
+ return typeof strings === 'string' ? results[0] : results;
40
+ };
41
+ /**
42
+ * 将驼峰字符串转换为连接符字符串
43
+ *
44
+ * @param strings 字符串(列表)
45
+ * @param hyphenType 连接符
46
+ * @returns hyphenString
47
+ */
48
+ const toHyphen = (strings, hyphenType = '-') => {
49
+ const results = (typeof strings === 'string' ? [strings] : strings).map(string => {
50
+ string = string.replace(/^([A-Z])/g, (_, p1) => p1.toLowerCase());
51
+ string = string.replace(/([A-Z])/g, (_, p1) => hyphenType + p1.toLowerCase());
52
+ });
53
+ return typeof strings === 'string' ? results[0] : results;
54
+ };
55
+ // 字符串拼接
56
+ /**
57
+ * 将object转换成query参数
58
+ *
59
+ * @param keyValue 对象
60
+ * @returns query参数
61
+ */
62
+ const query = (keyValue) => {
63
+ return keyValue
64
+ ? '?' +
65
+ Object.keys(keyValue)
66
+ .filter((key) => keyValue[key] !== undefined && keyValue[key] !== null)
67
+ .map((key) => encodeURIComponent(key) + '=' + encodeURIComponent(keyValue[key]))
68
+ .join('&')
69
+ : '';
70
+ };
71
+ /**
72
+ *
73
+ * 将url 传参转成data格式
74
+ *
75
+ * @param url (?********)
76
+ * @returns
77
+ */
78
+ const urlToData = (url) => {
79
+ const res = [];
80
+ const index = url.indexOf('?');
81
+ if (index === -1)
82
+ return [{ key: '', value: '' }];
83
+ url
84
+ .slice(index + 1)
85
+ .split('&')
86
+ .forEach((v) => {
87
+ res.push({
88
+ key: decodeURI(v.split('=')[0]),
89
+ value: decodeURI(v.split('=')[1]),
90
+ });
91
+ });
92
+ return [
93
+ ...res,
94
+ {
95
+ key: '',
96
+ value: '',
97
+ },
98
+ ];
99
+ };
100
+ /**
101
+ *
102
+ * 判断url格式
103
+ *
104
+ * @param url
105
+ * @returns
106
+ */
107
+ const isUrl = (path) => {
108
+ const reg = /^(https?:\/\/)([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)\/?(\?[^\s#]*)?$/;
109
+ return reg.test(path);
110
+ };
111
+
112
+ /*
113
+ * @Description: 时间处理
114
+ * @Author: Zye
115
+ * @Date: 2024-03-11
116
+ *
117
+ * setTime(time) time -> 服务器时间
118
+ * getTime() 返回服务器时间戳
119
+ *
120
+ */
121
+ // 服务器时间戳 减去 客户端时间戳
122
+ let _time_diff = 0;
123
+ // 同步时间
124
+ /**
125
+ * @param callback 获取服务器时间的回调函数,需要返回服务器时间
126
+ *
127
+ * @example
128
+ *
129
+ * setTime(async () => {
130
+ * return await getServerTime()
131
+ * })
132
+ *
133
+ */
134
+ const setTime = async (callback) => {
135
+ let _time_before, _time_after, _time_server;
136
+ _time_before = new Date().getTime();
137
+ _time_server = new Date(await callback()).getTime();
138
+ _time_after = new Date().getTime();
139
+ _time_diff = _time_diff
140
+ ? (_time_diff + _time_server - _time_before / 2 - _time_after / 2) / 2
141
+ : _time_server - _time_before / 2 - _time_after / 2;
142
+ };
143
+ // 获取本地时间戳
144
+ const _local_time = () => new Date().getTime();
145
+ /**
146
+ * 获取服务器时间戳
147
+ *
148
+ * @returns 服务器时间戳
149
+ */
150
+ const getTime = () => _local_time() + _time_diff;
151
+ /** 时间格式化 (参考dayjs)
152
+ *
153
+ * @param date 时间
154
+ * @param formatStr 格式如下
155
+ * @returns 格式化后的时间
156
+ *
157
+ * @formatStr
158
+ *
159
+ * |格式 |输出| 描述|
160
+ * |----|----|----|
161
+ * |YY| 18 |两位数年份|
162
+ * |YYYY| 2018 |四位数年份|
163
+ * |M| 1-12 |月份,从 1 开始|
164
+ * |MM |01-12 |月份,2 位数字|
165
+ * |D |1-31 |该月的哪一天|
166
+ * |DD| 01-31| 月份中的日期,2 位数字|
167
+ * |h| 0-23| 小时|
168
+ * |hh |00-23 |小时,2 位数字|
169
+ * |m| 0-59| 分钟|
170
+ * |mm |00-59 |分钟,2 位数字|
171
+ * |s |0-59| 秒钟|
172
+ * |ss |00-59 |秒钟,2 位数字|
173
+ */
174
+ const getDate = (date, formatStr) => {
175
+ if (!date)
176
+ date = getTime();
177
+ if (typeof date == 'string' || typeof date == 'number') {
178
+ date = new Date(date);
179
+ }
180
+ if (!formatStr)
181
+ return new Date(date);
182
+ let ret;
183
+ let d = {
184
+ year: date.getFullYear().toString(),
185
+ month: (date.getMonth() + 1).toString(),
186
+ day: date.getDate().toString(),
187
+ hour: date.getHours().toString(),
188
+ minutes: date.getMinutes().toString(),
189
+ seconds: date.getSeconds().toString(),
190
+ week: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'][date.getDay()],
191
+ };
192
+ let keys = {
193
+ 'YYYY': d.year,
194
+ 'YY': d.year.slice(2),
195
+ 'M+': d.month,
196
+ 'D+': d.day,
197
+ '[Hh]+': d.hour,
198
+ 'm+': d.minutes,
199
+ 's+': d.seconds,
200
+ '[Ww]+': d.week,
201
+ };
202
+ for (let key in keys) {
203
+ ret = new RegExp('(' + key + ')').exec(formatStr);
204
+ if (ret) {
205
+ formatStr = formatStr.replace(ret[1], keys[key].padStart(ret[1].length, '0'));
206
+ }
207
+ }
208
+ return formatStr;
209
+ };
210
+ /** 获取特殊时间节点
211
+ *
212
+ * @param {'weekstart' | 'weekend' | 'monthstart' | 'monthend' | 'yearstart' | 'yearend' | 'weekbefore' |'weekafter'| 'monthbefore' | 'yearbefore' | 'yearafter'} dateType 获取特殊时间
213
+ * @param {string } formatter 格式字符串或预设方案数字
214
+ *
215
+ * dateType:
216
+ *
217
+ * - weekstart —— 本周起始日期
218
+ *
219
+ * - weekend —— 本周结束日期
220
+ *
221
+ * - weekbefore —— 一周前日期
222
+ *
223
+ * - weekafter —— 一周后日期
224
+ *
225
+ * - monthstart —— 本月起始日期
226
+ *
227
+ * - monthend —— 本月结束日期
228
+ *
229
+ * - monthbefore—— 一个月前日期
230
+ *
231
+ * - yearstart —— 今年1月1日
232
+ *
233
+ * - yearend —— 今年12月31日
234
+ *
235
+ * - yearbefore —— 一年前日期
236
+ *
237
+ * - yearafter —— 一年后日期
238
+ *
239
+ * formatter: 参考 getDate
240
+ *
241
+ * @returns {Date | string}
242
+ */
243
+ const getSpecialDate = (dateType, date, formatter) => {
244
+ // 是否为开始时间
245
+ let isStart = true;
246
+ let time = new Date(date || getTime());
247
+ const setTime = () => {
248
+ if (isStart) {
249
+ time.setHours(0);
250
+ time.setMinutes(0);
251
+ time.setSeconds(0);
252
+ }
253
+ else {
254
+ time.setHours(23);
255
+ time.setMinutes(59);
256
+ time.setSeconds(59);
257
+ }
258
+ };
259
+ switch (dateType) {
260
+ case 'daybefore':
261
+ time = new Date(time.getTime() - 24 * 60 * 60 * 1000);
262
+ break;
263
+ case 'dayafter':
264
+ isStart = false;
265
+ time = new Date(time.getTime() + 24 * 60 * 60 * 1000);
266
+ break;
267
+ case 'weekstart':
268
+ time = new Date(time.getTime() - (time.getDay() - 1) * 24 * 60 * 60 * 1000);
269
+ break;
270
+ case 'weekstart7': //从周日开始
271
+ time = new Date(time.getTime() - time.getDay() * 24 * 60 * 60 * 1000);
272
+ break;
273
+ case 'weekend':
274
+ isStart = false;
275
+ time = new Date(time.getTime() + (7 - time.getDay()) * 24 * 60 * 60 * 1000);
276
+ break;
277
+ case 'weekbefore':
278
+ time = new Date(time.getTime() - 7 * 24 * 60 * 60 * 1000);
279
+ break;
280
+ case 'weekafter':
281
+ isStart = false;
282
+ time = (new Date(time.getTime() + 7 * 24 * 60 * 60 * 1000));
283
+ break;
284
+ case 'monthstart':
285
+ time = (new Date(time.getFullYear(), time.getMonth(), 1));
286
+ break;
287
+ case 'monthend':
288
+ isStart = false;
289
+ time = new Date(time.getFullYear(), time.getMonth() + 1, 0);
290
+ break;
291
+ case 'monthbefore':
292
+ time.setMonth(time.getMonth() - 1);
293
+ break;
294
+ case 'monthafter':
295
+ isStart = false;
296
+ time.setMonth(time.getMonth() + 1);
297
+ break;
298
+ case 'yearstart':
299
+ time.setMonth(0);
300
+ time.setDate(1);
301
+ break;
302
+ case 'yearend':
303
+ isStart = false;
304
+ time.setMonth(11);
305
+ time.setDate(31);
306
+ break;
307
+ case 'yearbefore':
308
+ time.setFullYear(time.getFullYear() - 1);
309
+ break;
310
+ case 'yearafter':
311
+ isStart = false;
312
+ time.setFullYear(time.getFullYear() + 1);
313
+ break;
314
+ }
315
+ setTime();
316
+ return getDate(time, formatter);
317
+ };
318
+
319
+ /*
320
+ * @Description: 对象处理
321
+ * @Author: Zye
322
+ * @Date: 2022-09-08
323
+ */
324
+ /**
325
+ * 从对象数组中获取匹配特定键值对的对象。
326
+ * @param objectArr 对象数组,每个对象至少包含一个键值对。
327
+ * @param keyName 需要匹配的键的名称。
328
+ * @param keyValue 需要匹配的键对应的值。可以是具体值或函数,如果为函数,则会将函数应用于数组中每个对象的键值进行匹配。
329
+ * @param foundKeyName 如果找到匹配的对象,从该对象中返回的键的名称。如果未指定,则返回整个对象。
330
+ * @returns 如果找到匹配的对象且指定了`foundKeyName`,则返回该键的值;如果未指定`foundKeyName`,则返回整个匹配的对象。如果没有找到匹配的对象,则返回一个空对象。
331
+ */
332
+ const getObject = (objectArr, keyName, keyValue, foundKeyName) => {
333
+ // 使用find方法查找数组中匹配的元素,如果未找到则返回一个空对象
334
+ let obj = objectArr.find((v) => (typeof keyValue == 'function' ? keyValue(v[keyName]) : v[keyName] == keyValue)) || new Object();
335
+ // 根据是否指定了foundKeyName返回不同的结果
336
+ return foundKeyName ? obj[foundKeyName] : obj;
337
+ };
338
+ /**
339
+ * 将源对象[src]的属性分配到目标对象[dist],并递归地合并它们的属性。
340
+ * 如果源对象的属性是一个对象(且不是数组),则会递归地将其属性分配到目标对象的相应属性中。
341
+ * 如果源对象的属性是数组或其他类型,则直接覆盖目标对象的相应属性。
342
+ *
343
+ * @param dist 目标对象,其属性将被源对象的属性覆盖或合并。
344
+ * @param src 源对象,其属性将覆盖或合并到目标对象中。
345
+ * @returns 返回合并后的目标对象。
346
+ * @template T 目标对象和源对象的类型,该类型必须是可深度写入的对象类型。
347
+ */
348
+ const assignObject = (dist, src) => {
349
+ const obj = {};
350
+ for (const [key, value] of Object.entries(dist)) {
351
+ if (typeof value !== 'object' || value === null) {
352
+ obj[key] = value;
353
+ }
354
+ }
355
+ for (const [key, value] of Object.entries(src)) {
356
+ if (!dist[key] || typeof value !== 'object' || value === null) {
357
+ obj[key] = value;
358
+ }
359
+ else {
360
+ // 如果源对象中的键值是可深度写入的对象,则递归调用assignObject函数进行合并
361
+ obj[key] = assignObject(dist[key], value);
362
+ }
363
+ }
364
+ return obj;
365
+ };
366
+ /**
367
+ * 此函数用来处理中间件向上透传方法 (仅用于Vue组件封装)
368
+ *
369
+ * @example
370
+ *
371
+ * com.vue
372
+ * !暴露form表单的所有方法,table表格的所有方法,以及onClick
373
+ * defineExpose( { onClick: () => { console.log('click') } }, formRef,tableRef)
374
+ * !父组件调用
375
+ * com.value.change() //调用表单change方法
376
+ * com.value.onClick() //调用onClick方法
377
+ *
378
+ * @param callback 回调函数,传onMounted
379
+ * @param option 默认暴露对象
380
+ * @param refs 要暴露的组件
381
+ * @returns 暴露对象
382
+ */
383
+ const expose = (option, ...refs) => {
384
+ return new Proxy(option, {
385
+ get(_, prop) {
386
+ for (const ref of refs) {
387
+ if (ref.value && prop in ref.value) {
388
+ return ref.value?.[prop];
389
+ }
390
+ }
391
+ },
392
+ has(_, prop) {
393
+ for (const ref of refs) {
394
+ if (ref.value && prop in ref.value) {
395
+ return true;
396
+ }
397
+ }
398
+ return false;
399
+ }
400
+ });
401
+ };
402
+ /**
403
+ * 此函数用来处理中间件向上透传事件 (仅用于Vue组件封装)
404
+ *
405
+ * @param emit emit
406
+ * @param emitStrs
407
+ * @returns
408
+ */
409
+ const on = (emit, emitStrs) => {
410
+ const emits = {};
411
+ if (!Array.isArray(emitStrs)) {
412
+ emitStrs = Object.keys(emitStrs);
413
+ }
414
+ emitStrs.forEach(key => {
415
+ emits[key] = (...args) => {
416
+ emit(key, ...args);
417
+ };
418
+ });
419
+ return emits;
420
+ };
421
+
422
+ /*
423
+ * @Description: 逻辑处理
424
+ * @Author: Zye
425
+ * @Date: 2022-11-21
426
+ */
427
+ const setValue = (condition, value, def = undefined) => {
428
+ return condition ? value : def;
429
+ };
430
+
431
+ /*
432
+ * @Description: 全屏
433
+ * @Author: Zye
434
+ * @Date: 2022-09-29
435
+ */
436
+ /**
437
+ * 是否全屏
438
+ *
439
+ * @returns boolean
440
+ */
441
+ function isFullscreen() {
442
+ return !!(document.fullscreenElement ||
443
+ document.mozFullScreenElement ||
444
+ document.webkitFullscreenElement ||
445
+ document.msFullscreenElement);
446
+ }
447
+ /**
448
+ * 进入全屏
449
+ *
450
+ * @param { HTMLElement } el 需要进入全屏的元素
451
+ *
452
+ */
453
+ function inFullscreen(el = document.querySelector('body')) {
454
+ if (el.requestFullscreen) {
455
+ el.requestFullscreen();
456
+ }
457
+ else if (el.mozRequestFullScreen) {
458
+ // Firefox
459
+ el.mozRequestFullScreen();
460
+ }
461
+ else if (el.webkitRequestFullscreen) {
462
+ // Chrome, Safari, Opera
463
+ el.webkitRequestFullscreen();
464
+ }
465
+ else if (el.msRequestFullscreen) {
466
+ // IE/Edge
467
+ el.msRequestFullscreen();
468
+ }
469
+ }
470
+ /**
471
+ * 退出全屏
472
+ *
473
+ */
474
+ function exitFullscreen() {
475
+ if (document.exitFullscreen) {
476
+ document.exitFullscreen();
477
+ }
478
+ else if (document.mozCancelFullScreen) {
479
+ // Firefox
480
+ document.mozCancelFullScreen();
481
+ }
482
+ else if (document.webkitExitFullscreen) {
483
+ // Chrome, Safari, Opera
484
+ document.webkitExitFullscreen();
485
+ }
486
+ else if (document.msExitFullscreen) {
487
+ // IE/Edge
488
+ document.msExitFullscreen();
489
+ }
490
+ }
491
+ /**
492
+ * 切换全屏显示
493
+ *
494
+ * @param { HTMLElement } el 需要进入全屏的元素
495
+ */
496
+ function fullscreen(el = document.querySelector('body')) {
497
+ isFullscreen() ? exitFullscreen() : inFullscreen(el);
498
+ }
499
+
500
+ /*
501
+ * @Description: 数字处理
502
+ * @Author: Zye
503
+ * @Date: 2021-11-04
504
+ */
505
+ /**
506
+ * 取近似值,取整
507
+ *
508
+ * @param num 数字
509
+ * @param factor 近似因子
510
+ * @returns 数字
511
+ *
512
+ * @ep
513
+ *
514
+ * Num(13,5) // 15
515
+ *
516
+ * Num(1.264,0.01) //1.26
517
+ *
518
+ */
519
+ const Num = (num, factor) => {
520
+ if (!num)
521
+ return 0;
522
+ if (typeof num == 'string') {
523
+ num = parseFloat(num);
524
+ }
525
+ return factor ? Math.round(num / factor) * factor : num;
526
+ };
527
+
528
+ /**
529
+ * 浏览器引擎判断
530
+ *
531
+ * Gecke 火狐(Firefox)
532
+ * Blink (谷歌, 欧朋)
533
+ * WebKit (苹果,老版谷歌)
534
+ * Unknown (其他)
535
+ */
536
+ function browserEngine() {
537
+ var userAgent = navigator.userAgent;
538
+ var isGecko = /Gecko\/\d+\.\d+/i.test(userAgent) && !/like Gecko/.test(userAgent);
539
+ var isBlink = /Chrome\/[\d.]+/.test(userAgent) && /Safari\/[\d.]+/.test(userAgent);
540
+ var isWebKit = /AppleWebKit\/[\d.]+/.test(userAgent) && !isBlink;
541
+ if (isGecko) {
542
+ return 'Gecko';
543
+ }
544
+ else if (isBlink) {
545
+ return 'Blink';
546
+ }
547
+ else if (isWebKit) {
548
+ return 'WebKit';
549
+ }
550
+ else {
551
+ return 'Unknown';
552
+ }
553
+ }
554
+
555
+ /**
556
+ *
557
+ * @param px 像素或者数字
558
+ * @returns
559
+ */
560
+ function addPx(px) {
561
+ return typeof px === 'number' ? px + 'px' : px;
562
+ }
563
+
564
+ /**
565
+ *
566
+ * @param config 配置 (如配置 baseUrl、timeout 等 )
567
+ * @param request 请求拦截
568
+ * @param response 响应成功拦截
569
+ * @param reject 响应错误拦截 (正常情况用不到)
570
+ * @returns
571
+ */
572
+ const createHttp = ({ config = {}, request = config => config, response = data => data, reject = error => Promise.reject(error), }) => {
573
+ // 创建Axios
574
+ const axiosClone = axios.create({ timeout: 1000 * 60 * 5, ...(config || {}) });
575
+ // 请求
576
+ axiosClone.interceptors.request.use((config) => {
577
+ return request(config);
578
+ });
579
+ // 响应
580
+ axiosClone.interceptors.response.use((res) => {
581
+ // 处理文件
582
+ const contentType = res.headers['content-type'];
583
+ if ((contentType && contentType.includes('application/octet-stream')) || contentType.includes('file'))
584
+ return res.data;
585
+ // 处理数据
586
+ return response(res.data, res);
587
+ }, (error) => {
588
+ return Promise.reject(reject(error));
589
+ });
590
+ // 重写http
591
+ const http = (config) => {
592
+ return axiosClone(config);
593
+ };
594
+ const get = (method) => {
595
+ return http[method] = (url, params = {}, config = {}) => {
596
+ return axiosClone[method](url, {
597
+ ...config,
598
+ params,
599
+ });
600
+ };
601
+ };
602
+ const post = (method) => {
603
+ return http[method] = (url, data = {}, config = {}) => {
604
+ return axiosClone[method](url, data, config);
605
+ };
606
+ };
607
+ http.get = get('get');
608
+ http.delete = get('delete');
609
+ http.head = get('head');
610
+ http.post = post('post');
611
+ http.put = post('put');
612
+ http.patch = post('patch');
613
+ return http;
614
+ };
615
+
616
+ let trimLeft = /^\s+/;
617
+ let trimRight = /\s+$/;
618
+ let mathRound = Math.round;
619
+ let mathMin = Math.min;
620
+ let mathMax = Math.max;
621
+ let mathRandom = Math.random;
622
+ class TinyColor {
623
+ matchers;
624
+ names;
625
+ _originalInput;
626
+ _r;
627
+ _g;
628
+ _b;
629
+ _a;
630
+ _roundA;
631
+ _format;
632
+ _gradientType;
633
+ _ok;
634
+ isDark;
635
+ isLight;
636
+ isValid;
637
+ constructor(color, opts) {
638
+ // If input is already a tinycolor, return itself
639
+ if (color instanceof TinyColor) {
640
+ return color;
641
+ }
642
+ this.init(color, opts);
643
+ }
644
+ init(color, opts) {
645
+ this.matchers = this.initMatchers();
646
+ this.names = TinyColor.initNames();
647
+ const rgb = this.inputToRGB(color);
648
+ this._originalInput = typeof color !== 'undefined' ? color : '';
649
+ this._r = rgb.r;
650
+ this._g = rgb.g;
651
+ this._b = rgb.b;
652
+ this._a = rgb.a;
653
+ this._roundA = mathRound(100 * this._a) / 100;
654
+ // this._format = typeof opts !== 'undefined' && typeof opts.format !== 'undefined' ? opts.format : rgb.format || ''
655
+ this._format = opts?.format || rgb?.format || '';
656
+ // this._gradientType = typeof opts !== 'undefined' && typeof opts.gradientType !== 'undefined' ? opts.gradientType : ''
657
+ this._gradientType = opts?.gradientType || '';
658
+ // Don't let the range of [0,255] come back in [0,1].
659
+ // Potentially lose a little bit of precision here, but will fix issues where
660
+ // .5 gets interpreted as half of the total, instead of half of 1
661
+ // If it was supposed to be 128, this was already taken care of by `inputToRgb`
662
+ if (this._r < 1) {
663
+ this._r = mathRound(this._r);
664
+ }
665
+ if (this._g < 1) {
666
+ this._g = mathRound(this._g);
667
+ }
668
+ if (this._b < 1) {
669
+ this._b = mathRound(this._b);
670
+ }
671
+ this._ok = rgb.ok;
672
+ this.initAttr();
673
+ }
674
+ initAttr() {
675
+ this.isDark = this.getBrightness() < 128;
676
+ this.isLight = !this.isDark;
677
+ this.isValid = this._ok;
678
+ }
679
+ static initNames() {
680
+ // Big List of Colors
681
+ // ------------------
682
+ // <http://www.w3.org/TR/css3-color/#svg-color>
683
+ return {
684
+ aliceblue: 'f0f8ff',
685
+ antiquewhite: 'faebd7',
686
+ aqua: '0ff',
687
+ aquamarine: '7fffd4',
688
+ azure: 'f0ffff',
689
+ beige: 'f5f5dc',
690
+ bisque: 'ffe4c4',
691
+ black: '000',
692
+ blanchedalmond: 'ffebcd',
693
+ blue: '00f',
694
+ blueviolet: '8a2be2',
695
+ brown: 'a52a2a',
696
+ burlywood: 'deb887',
697
+ burntsienna: 'ea7e5d',
698
+ cadetblue: '5f9ea0',
699
+ chartreuse: '7fff00',
700
+ chocolate: 'd2691e',
701
+ coral: 'ff7f50',
702
+ cornflowerblue: '6495ed',
703
+ cornsilk: 'fff8dc',
704
+ crimson: 'dc143c',
705
+ cyan: '0ff',
706
+ darkblue: '00008b',
707
+ darkcyan: '008b8b',
708
+ darkgoldenrod: 'b8860b',
709
+ darkgray: 'a9a9a9',
710
+ darkgreen: '006400',
711
+ darkgrey: 'a9a9a9',
712
+ darkkhaki: 'bdb76b',
713
+ darkmagenta: '8b008b',
714
+ darkolivegreen: '556b2f',
715
+ darkorange: 'ff8c00',
716
+ darkorchid: '9932cc',
717
+ darkred: '8b0000',
718
+ darksalmon: 'e9967a',
719
+ darkseagreen: '8fbc8f',
720
+ darkslateblue: '483d8b',
721
+ darkslategray: '2f4f4f',
722
+ darkslategrey: '2f4f4f',
723
+ darkturquoise: '00ced1',
724
+ darkviolet: '9400d3',
725
+ deeppink: 'ff1493',
726
+ deepskyblue: '00bfff',
727
+ dimgray: '696969',
728
+ dimgrey: '696969',
729
+ dodgerblue: '1e90ff',
730
+ firebrick: 'b22222',
731
+ floralwhite: 'fffaf0',
732
+ forestgreen: '228b22',
733
+ fuchsia: 'f0f',
734
+ gainsboro: 'dcdcdc',
735
+ ghostwhite: 'f8f8ff',
736
+ gold: 'ffd700',
737
+ goldenrod: 'daa520',
738
+ gray: '808080',
739
+ green: '008000',
740
+ greenyellow: 'adff2f',
741
+ grey: '808080',
742
+ honeydew: 'f0fff0',
743
+ hotpink: 'ff69b4',
744
+ indianred: 'cd5c5c',
745
+ indigo: '4b0082',
746
+ ivory: 'fffff0',
747
+ khaki: 'f0e68c',
748
+ lavender: 'e6e6fa',
749
+ lavenderblush: 'fff0f5',
750
+ lawngreen: '7cfc00',
751
+ lemonchiffon: 'fffacd',
752
+ lightblue: 'add8e6',
753
+ lightcoral: 'f08080',
754
+ lightcyan: 'e0ffff',
755
+ lightgoldenrodyellow: 'fafad2',
756
+ lightgray: 'd3d3d3',
757
+ lightgreen: '90ee90',
758
+ lightgrey: 'd3d3d3',
759
+ lightpink: 'ffb6c1',
760
+ lightsalmon: 'ffa07a',
761
+ lightseagreen: '20b2aa',
762
+ lightskyblue: '87cefa',
763
+ lightslategray: '789',
764
+ lightslategrey: '789',
765
+ lightsteelblue: 'b0c4de',
766
+ lightyellow: 'ffffe0',
767
+ lime: '0f0',
768
+ limegreen: '32cd32',
769
+ linen: 'faf0e6',
770
+ magenta: 'f0f',
771
+ maroon: '800000',
772
+ mediumaquamarine: '66cdaa',
773
+ mediumblue: '0000cd',
774
+ mediumorchid: 'ba55d3',
775
+ mediumpurple: '9370db',
776
+ mediumseagreen: '3cb371',
777
+ mediumslateblue: '7b68ee',
778
+ mediumspringgreen: '00fa9a',
779
+ mediumturquoise: '48d1cc',
780
+ mediumvioletred: 'c71585',
781
+ midnightblue: '191970',
782
+ mintcream: 'f5fffa',
783
+ mistyrose: 'ffe4e1',
784
+ moccasin: 'ffe4b5',
785
+ navajowhite: 'ffdead',
786
+ navy: '000080',
787
+ oldlace: 'fdf5e6',
788
+ olive: '808000',
789
+ olivedrab: '6b8e23',
790
+ orange: 'ffa500',
791
+ orangered: 'ff4500',
792
+ orchid: 'da70d6',
793
+ palegoldenrod: 'eee8aa',
794
+ palegreen: '98fb98',
795
+ paleturquoise: 'afeeee',
796
+ palevioletred: 'db7093',
797
+ papayawhip: 'ffefd5',
798
+ peachpuff: 'ffdab9',
799
+ peru: 'cd853f',
800
+ pink: 'ffc0cb',
801
+ plum: 'dda0dd',
802
+ powderblue: 'b0e0e6',
803
+ purple: '800080',
804
+ rebeccapurple: '663399',
805
+ red: 'f00',
806
+ rosybrown: 'bc8f8f',
807
+ royalblue: '4169e1',
808
+ saddlebrown: '8b4513',
809
+ salmon: 'fa8072',
810
+ sandybrown: 'f4a460',
811
+ seagreen: '2e8b57',
812
+ seashell: 'fff5ee',
813
+ sienna: 'a0522d',
814
+ silver: 'c0c0c0',
815
+ skyblue: '87ceeb',
816
+ slateblue: '6a5acd',
817
+ slategray: '708090',
818
+ slategrey: '708090',
819
+ snow: 'fffafa',
820
+ springgreen: '00ff7f',
821
+ steelblue: '4682b4',
822
+ tan: 'd2b48c',
823
+ teal: '008080',
824
+ thistle: 'd8bfd8',
825
+ tomato: 'ff6347',
826
+ turquoise: '40e0d0',
827
+ violet: 'ee82ee',
828
+ wheat: 'f5deb3',
829
+ white: 'fff',
830
+ whitesmoke: 'f5f5f5',
831
+ yellow: 'ff0',
832
+ yellowgreen: '9acd32',
833
+ };
834
+ }
835
+ initMatchers() {
836
+ // <http://www.w3.org/TR/css3-values/#integers>
837
+ const CSS_INTEGER = '[-\\+]?\\d+%?';
838
+ // <http://www.w3.org/TR/css3-values/#number-value>
839
+ const CSS_NUMBER = '[-\\+]?\\d*\\.\\d+%?';
840
+ // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
841
+ const CSS_UNIT = '(?:' + CSS_NUMBER + ')|(?:' + CSS_INTEGER + ')';
842
+ // Actual matching.
843
+ // Parentheses and commas are optional, but not required.
844
+ // Whitespace can take the place of commas or opening paren
845
+ const PERMISSIVE_MATCH3 = '[\\s|\\(]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')\\s*\\)?';
846
+ const PERMISSIVE_MATCH4 = '[\\s|\\(]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')[,|\\s]+(' + CSS_UNIT + ')\\s*\\)?';
847
+ return {
848
+ CSS_UNIT: new RegExp(CSS_UNIT),
849
+ rgb: new RegExp('rgb' + PERMISSIVE_MATCH3),
850
+ rgba: new RegExp('rgba' + PERMISSIVE_MATCH4),
851
+ hsl: new RegExp('hsl' + PERMISSIVE_MATCH3),
852
+ hsla: new RegExp('hsla' + PERMISSIVE_MATCH4),
853
+ hsv: new RegExp('hsv' + PERMISSIVE_MATCH3),
854
+ hsva: new RegExp('hsva' + PERMISSIVE_MATCH4),
855
+ hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
856
+ hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
857
+ hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
858
+ hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
859
+ };
860
+ }
861
+ getBrightness() {
862
+ //http://www.w3.org/TR/AERT#color-contrast
863
+ const rgb = this.toRgb();
864
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
865
+ }
866
+ toRgb() {
867
+ return {
868
+ r: mathRound(this._r),
869
+ g: mathRound(this._g),
870
+ b: mathRound(this._b),
871
+ a: this._a,
872
+ };
873
+ }
874
+ static getNames() {
875
+ return this.initNames();
876
+ }
877
+ getOriginalInput() {
878
+ return this._originalInput;
879
+ }
880
+ getFormat() {
881
+ return this._format;
882
+ }
883
+ getAlpha() {
884
+ return this._a;
885
+ }
886
+ getLuminance() {
887
+ //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
888
+ const rgb = this.toRgb();
889
+ let RsRGB, GsRGB, BsRGB, R, G, B;
890
+ RsRGB = rgb.r / 255;
891
+ GsRGB = rgb.g / 255;
892
+ BsRGB = rgb.b / 255;
893
+ if (RsRGB <= 0.03928) {
894
+ R = RsRGB / 12.92;
895
+ }
896
+ else {
897
+ R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
898
+ }
899
+ if (GsRGB <= 0.03928) {
900
+ G = GsRGB / 12.92;
901
+ }
902
+ else {
903
+ G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
904
+ }
905
+ if (BsRGB <= 0.03928) {
906
+ B = BsRGB / 12.92;
907
+ }
908
+ else {
909
+ B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
910
+ }
911
+ return 0.2126 * R + 0.7152 * G + 0.0722 * B;
912
+ }
913
+ setAlpha(value) {
914
+ this._a = this.boundAlpha(value);
915
+ this._roundA = mathRound(100 * this._a) / 100;
916
+ return this;
917
+ }
918
+ toHsv() {
919
+ let hsv = this.rgbToHsv(this._r, this._g, this._b);
920
+ return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
921
+ }
922
+ toHsvString() {
923
+ let hsv = this.rgbToHsv(this._r, this._g, this._b);
924
+ let h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
925
+ return this._a == 1 ? 'hsv(' + h + ', ' + s + '%, ' + v + '%)' : 'hsva(' + h + ', ' + s + '%, ' + v + '%, ' + this._roundA + ')';
926
+ }
927
+ toHsl() {
928
+ let hsl = this.rgbToHsl(this._r, this._g, this._b);
929
+ return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
930
+ }
931
+ toHslString() {
932
+ let hsl = this.rgbToHsl(this._r, this._g, this._b);
933
+ let h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
934
+ return this._a == 1 ? 'hsl(' + h + ', ' + s + '%, ' + l + '%)' : 'hsla(' + h + ', ' + s + '%, ' + l + '%, ' + this._roundA + ')';
935
+ }
936
+ toHex(allow3Char) {
937
+ return this.rgbToHex(this._r, this._g, this._b, allow3Char);
938
+ }
939
+ toHexString(allow3Char) {
940
+ return '#' + this.toHex(allow3Char);
941
+ }
942
+ toHex8(allow4Char) {
943
+ return this.rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
944
+ }
945
+ toHex8String(allow4Char) {
946
+ return '#' + this.toHex8(allow4Char);
947
+ }
948
+ toRgbString() {
949
+ return this._a == 1
950
+ ? 'rgb(' + mathRound(this._r) + ', ' + mathRound(this._g) + ', ' + mathRound(this._b) + ')'
951
+ : 'rgba(' + mathRound(this._r) + ', ' + mathRound(this._g) + ', ' + mathRound(this._b) + ', ' + this._roundA + ')';
952
+ }
953
+ toPercentageRgb() {
954
+ return {
955
+ r: mathRound(this.bound01(this._r, 255) * 100) + '%',
956
+ g: mathRound(this.bound01(this._g, 255) * 100) + '%',
957
+ b: mathRound(this.bound01(this._b, 255) * 100) + '%',
958
+ a: this._a,
959
+ };
960
+ }
961
+ toPercentageRgbString() {
962
+ return this._a == 1
963
+ ? 'rgb(' +
964
+ mathRound(this.bound01(this._r, 255) * 100) +
965
+ '%, ' +
966
+ mathRound(this.bound01(this._g, 255) * 100) +
967
+ '%, ' +
968
+ mathRound(this.bound01(this._b, 255) * 100) +
969
+ '%)'
970
+ : 'rgba(' +
971
+ mathRound(this.bound01(this._r, 255) * 100) +
972
+ '%, ' +
973
+ mathRound(this.bound01(this._g, 255) * 100) +
974
+ '%, ' +
975
+ mathRound(this.bound01(this._b, 255) * 100) +
976
+ '%, ' +
977
+ this._roundA +
978
+ ')';
979
+ }
980
+ toName() {
981
+ if (this._a === 0) {
982
+ return 'transparent';
983
+ }
984
+ if (this._a < 1) {
985
+ return false;
986
+ }
987
+ return this._flip()[this.rgbToHex(this._r, this._g, this._b, true)] || false;
988
+ }
989
+ toFilter(secondColor) {
990
+ let hex8String = '#' + this.rgbaToArgbHex(this._r, this._g, this._b, this._a);
991
+ let secondHex8String = hex8String;
992
+ let gradientType = this._gradientType ? 'GradientType = 1, ' : '';
993
+ if (secondColor) {
994
+ const tinyColorObj = new TinyColor(secondColor);
995
+ secondHex8String = '#' + this.rgbaToArgbHex(tinyColorObj._r, tinyColorObj._g, tinyColorObj._b, tinyColorObj._a);
996
+ }
997
+ return ('progid:DXImageTransform.Microsoft.gradient(' +
998
+ gradientType +
999
+ 'startColorstr=' +
1000
+ hex8String +
1001
+ ',endColorstr=' +
1002
+ secondHex8String +
1003
+ ')');
1004
+ }
1005
+ toString(format) {
1006
+ let formatSet = !!format;
1007
+ format = format || this._format;
1008
+ let formattedString = '';
1009
+ let hasAlpha = this._a < 1 && this._a >= 0;
1010
+ let needsAlphaFormat = !formatSet &&
1011
+ hasAlpha &&
1012
+ (format === 'hex' || format === 'hex6' || format === 'hex3' || format === 'hex4' || format === 'hex8' || format === 'name');
1013
+ if (needsAlphaFormat) {
1014
+ if (format === 'name' && this._a === 0) {
1015
+ return this.toName();
1016
+ }
1017
+ return this.toRgbString();
1018
+ }
1019
+ if (format === 'rgb') {
1020
+ formattedString = this.toRgbString();
1021
+ }
1022
+ if (format === 'prgb') {
1023
+ formattedString = this.toPercentageRgbString();
1024
+ }
1025
+ if (format === 'hex' || format === 'hex6') {
1026
+ formattedString = this.toHexString();
1027
+ }
1028
+ if (format === 'hex3') {
1029
+ formattedString = this.toHexString(true);
1030
+ }
1031
+ if (format === 'hex4') {
1032
+ formattedString = this.toHex8String(true);
1033
+ }
1034
+ if (format === 'hex8') {
1035
+ formattedString = this.toHex8String();
1036
+ }
1037
+ if (format === 'name') {
1038
+ formattedString = this.toName();
1039
+ }
1040
+ if (format === 'hsl') {
1041
+ formattedString = this.toHslString();
1042
+ }
1043
+ if (format === 'hsv') {
1044
+ formattedString = this.toHsvString();
1045
+ }
1046
+ return formattedString || this.toHexString();
1047
+ }
1048
+ clone() {
1049
+ return new TinyColor(this.toString());
1050
+ }
1051
+ _applyModification(fn, args) {
1052
+ let color = fn.apply(null, [this].concat([].slice.call(args)));
1053
+ this._r = color._r;
1054
+ this._g = color._g;
1055
+ this._b = color._b;
1056
+ this.setAlpha(color._a);
1057
+ return this;
1058
+ }
1059
+ _lighten(color, amount) {
1060
+ amount = amount === 0 ? 0 : amount || 10;
1061
+ let hsl = new TinyColor(color).toHsl();
1062
+ hsl.l += amount / 100;
1063
+ hsl.l = color.clamp01(hsl.l);
1064
+ return new TinyColor(hsl);
1065
+ }
1066
+ lighten(...args) {
1067
+ return this._applyModification(this._lighten, args);
1068
+ }
1069
+ _brighten(color, amount) {
1070
+ amount = amount === 0 ? 0 : amount || 10;
1071
+ let rgb = new TinyColor(color).toRgb();
1072
+ rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * -(amount / 100))));
1073
+ rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * -(amount / 100))));
1074
+ rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * -(amount / 100))));
1075
+ return new TinyColor(rgb);
1076
+ }
1077
+ brighten(...args) {
1078
+ return this._applyModification(this._brighten, args);
1079
+ }
1080
+ _darken(color, amount) {
1081
+ amount = amount === 0 ? 0 : amount || 10;
1082
+ let hsl = new TinyColor(color).toHsl();
1083
+ hsl.l -= amount / 100;
1084
+ hsl.l = color.clamp01(hsl.l);
1085
+ return new TinyColor(hsl);
1086
+ }
1087
+ darken(...args) {
1088
+ return this._applyModification(this._darken, args);
1089
+ }
1090
+ _desaturate(color, amount) {
1091
+ amount = amount === 0 ? 0 : amount || 10;
1092
+ let hsl = new TinyColor(color).toHsl();
1093
+ hsl.s -= amount / 100;
1094
+ hsl.s = color.clamp01(hsl.s);
1095
+ return new TinyColor(hsl);
1096
+ }
1097
+ desaturate(...args) {
1098
+ return this._applyModification(this._desaturate, args);
1099
+ }
1100
+ _saturate(color, amount) {
1101
+ amount = amount === 0 ? 0 : amount || 10;
1102
+ let hsl = new TinyColor(color).toHsl();
1103
+ hsl.s += amount / 100;
1104
+ hsl.s = color.clamp01(hsl.s);
1105
+ return new TinyColor(hsl);
1106
+ }
1107
+ saturate(...args) {
1108
+ return this._applyModification(this._saturate, args);
1109
+ }
1110
+ _greyscale(color) {
1111
+ return new TinyColor(color).desaturate(100);
1112
+ }
1113
+ greyscale(...args) {
1114
+ return this._applyModification(this._greyscale, args);
1115
+ }
1116
+ _spin(color, amount) {
1117
+ let hsl = new TinyColor(color).toHsl();
1118
+ let hue = (hsl.h + amount) % 360;
1119
+ hsl.h = hue < 0 ? 360 + hue : hue;
1120
+ return new TinyColor(hsl);
1121
+ }
1122
+ spin(...args) {
1123
+ return this._applyModification(this._spin, args);
1124
+ }
1125
+ _applyCombination(fn, args) {
1126
+ return fn.apply(null, [this].concat([].slice.call(args)));
1127
+ }
1128
+ _analogous(color, results, slices) {
1129
+ results = results || 6;
1130
+ slices = slices || 30;
1131
+ let hsl = new TinyColor(color).toHsl();
1132
+ let part = 360 / slices;
1133
+ let ret = [new TinyColor(color)];
1134
+ for (hsl.h = (hsl.h - ((part * results) >> 1) + 720) % 360; --results;) {
1135
+ hsl.h = (hsl.h + part) % 360;
1136
+ ret.push(new TinyColor(hsl));
1137
+ }
1138
+ return ret;
1139
+ }
1140
+ analogous(...args) {
1141
+ return this._applyCombination(this._analogous, args);
1142
+ }
1143
+ _complement(color) {
1144
+ let hsl = new TinyColor(color).toHsl();
1145
+ hsl.h = (hsl.h + 180) % 360;
1146
+ return new TinyColor(hsl);
1147
+ }
1148
+ complement(...args) {
1149
+ return this._applyCombination(this._complement, args);
1150
+ }
1151
+ _monochromatic(color, results) {
1152
+ results = results || 6;
1153
+ let hsv = new TinyColor(color).toHsv();
1154
+ let h = hsv.h, s = hsv.s, v = hsv.v;
1155
+ let ret = [];
1156
+ let modification = 1 / results;
1157
+ while (results--) {
1158
+ ret.push(new TinyColor({ h: h, s: s, v: v }));
1159
+ v = (v + modification) % 1;
1160
+ }
1161
+ return ret;
1162
+ }
1163
+ monochromatic(...args) {
1164
+ return this._applyCombination(this._monochromatic, args);
1165
+ }
1166
+ _splitcomplement(color) {
1167
+ let hsl = new TinyColor(color).toHsl();
1168
+ let h = hsl.h;
1169
+ return [
1170
+ new TinyColor(color),
1171
+ new TinyColor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l }),
1172
+ new TinyColor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l }),
1173
+ ];
1174
+ }
1175
+ splitcomplement(...args) {
1176
+ return this._applyCombination(this._splitcomplement, args);
1177
+ }
1178
+ _triad(color) {
1179
+ let hsl = new TinyColor(color).toHsl();
1180
+ let h = hsl.h;
1181
+ return [
1182
+ new TinyColor(color),
1183
+ new TinyColor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
1184
+ new TinyColor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l }),
1185
+ ];
1186
+ }
1187
+ triad(...args) {
1188
+ return this._applyCombination(this._triad, args);
1189
+ }
1190
+ _tetrad(obj) {
1191
+ let hsl = new TinyColor(obj).toHsl();
1192
+ let h = hsl.h;
1193
+ return [
1194
+ new TinyColor(obj),
1195
+ new TinyColor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),
1196
+ new TinyColor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
1197
+ new TinyColor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l }),
1198
+ ];
1199
+ }
1200
+ tetrad(...args) {
1201
+ return this._applyCombination(this._tetrad, args);
1202
+ }
1203
+ static fromRatio(color, opts) {
1204
+ if (typeof color == 'object') {
1205
+ let newColor = {};
1206
+ for (let i in color) {
1207
+ if (color.hasOwnProperty(i)) {
1208
+ if (i === 'a') {
1209
+ newColor[i] = color[i];
1210
+ }
1211
+ else {
1212
+ newColor[i] = TinyColor.convertToPercentage(color[i]);
1213
+ }
1214
+ }
1215
+ }
1216
+ color = newColor;
1217
+ }
1218
+ return new TinyColor(color, opts);
1219
+ }
1220
+ static equals(color1, color2) {
1221
+ if (!color1 || !color2) {
1222
+ return false;
1223
+ }
1224
+ return new TinyColor(color1).toRgbString() == new TinyColor(color2).toRgbString();
1225
+ }
1226
+ static random() {
1227
+ return TinyColor.fromRatio({
1228
+ r: mathRandom(),
1229
+ g: mathRandom(),
1230
+ b: mathRandom(),
1231
+ });
1232
+ }
1233
+ static mix(color1, color2, amount) {
1234
+ amount = amount === 0 ? 0 : amount || 50;
1235
+ let rgb1 = new TinyColor(color1).toRgb();
1236
+ let rgb2 = new TinyColor(color2).toRgb();
1237
+ let p = amount / 100;
1238
+ let rgba = {
1239
+ r: (rgb2.r - rgb1.r) * p + rgb1.r,
1240
+ g: (rgb2.g - rgb1.g) * p + rgb1.g,
1241
+ b: (rgb2.b - rgb1.b) * p + rgb1.b,
1242
+ a: (rgb2.a - rgb1.a) * p + rgb1.a,
1243
+ };
1244
+ return new TinyColor(rgba);
1245
+ }
1246
+ static readability(color1, color2) {
1247
+ let c1 = new TinyColor(color1);
1248
+ let c2 = new TinyColor(color2);
1249
+ return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
1250
+ }
1251
+ static isReadable(color1, color2, wcag2) {
1252
+ let readability = TinyColor.readability(color1, color2);
1253
+ let wcag2Parms, out;
1254
+ out = false;
1255
+ wcag2Parms = TinyColor.validateWCAG2Parms(wcag2);
1256
+ switch (wcag2Parms.level + wcag2Parms.size) {
1257
+ case 'AAsmall':
1258
+ case 'AAAlarge':
1259
+ out = readability >= 4.5;
1260
+ break;
1261
+ case 'AAlarge':
1262
+ out = readability >= 3;
1263
+ break;
1264
+ case 'AAAsmall':
1265
+ out = readability >= 7;
1266
+ break;
1267
+ }
1268
+ return out;
1269
+ }
1270
+ static mostReadable(baseColor, colorList, args) {
1271
+ let bestColor = '';
1272
+ let bestScore = 0;
1273
+ let readability;
1274
+ let includeFallbackColors, level, size;
1275
+ args = args || {};
1276
+ includeFallbackColors = args.includeFallbackColors;
1277
+ level = args.level;
1278
+ size = args.size;
1279
+ for (let item of colorList) {
1280
+ readability = TinyColor.readability(baseColor, item);
1281
+ if (readability > bestScore) {
1282
+ bestScore = readability;
1283
+ bestColor = new TinyColor(item);
1284
+ }
1285
+ }
1286
+ if (TinyColor.isReadable(baseColor, bestColor, {
1287
+ level: level,
1288
+ size: size,
1289
+ }) ||
1290
+ !includeFallbackColors) {
1291
+ return bestColor;
1292
+ }
1293
+ else {
1294
+ args.includeFallbackColors = false;
1295
+ return TinyColor.mostReadable(baseColor, ['#fff', '#000'], args);
1296
+ }
1297
+ }
1298
+ clamp01(val) {
1299
+ return mathMin(1, mathMax(0, val));
1300
+ }
1301
+ _flip() {
1302
+ let flipped = {};
1303
+ let allName = TinyColor.initNames();
1304
+ for (let i in allName) {
1305
+ if (allName.hasOwnProperty(i)) {
1306
+ flipped[allName[i]] = i;
1307
+ }
1308
+ }
1309
+ return flipped;
1310
+ }
1311
+ isValidCSSUnit(color) {
1312
+ return !!this.matchers.CSS_UNIT.exec(color);
1313
+ }
1314
+ isOnePointZero(n) {
1315
+ return typeof n == 'string' && n.indexOf('.') != -1 && parseFloat(n) === 1;
1316
+ }
1317
+ isPercentage(n) {
1318
+ return typeof n === 'string' && n.indexOf('%') != -1;
1319
+ }
1320
+ pad2(c) {
1321
+ return c.length == 1 ? '0' + c : '' + c;
1322
+ }
1323
+ bound01(n, max) {
1324
+ if (this.isOnePointZero(n)) {
1325
+ n = '100%';
1326
+ }
1327
+ let processPercent = this.isPercentage(n);
1328
+ n = mathMin(max, mathMax(0, parseFloat(n)));
1329
+ // Automatically convert percentage into number
1330
+ if (processPercent) {
1331
+ n = parseInt('' + n * max, 10) / 100;
1332
+ }
1333
+ // Handle floating point rounding errors
1334
+ if (Math.abs(n - max) < 0.000001) {
1335
+ return 1;
1336
+ }
1337
+ // Convert into [0, 1] range if it isn't already
1338
+ return (n % max) / parseFloat(max);
1339
+ }
1340
+ convertDecimalToHex(d) {
1341
+ return Math.round(parseFloat(d) * 255).toString(16);
1342
+ }
1343
+ rgbToRgb(r, g, b) {
1344
+ return {
1345
+ r: this.bound01(r, 255) * 255,
1346
+ g: this.bound01(g, 255) * 255,
1347
+ b: this.bound01(b, 255) * 255,
1348
+ };
1349
+ }
1350
+ hsvToRgb(h, s, v) {
1351
+ h = this.bound01(h, 360) * 6;
1352
+ s = this.bound01(s, 100);
1353
+ v = this.bound01(v, 100);
1354
+ let i = Math.floor(h), f = h - i, p = v * (1 - s), q = v * (1 - f * s), t = v * (1 - (1 - f) * s), mod = i % 6, r = [v, q, p, p, t, v][mod], g = [t, v, v, q, p, p][mod], b = [p, p, t, v, v, q][mod];
1355
+ return { r: r * 255, g: g * 255, b: b * 255 };
1356
+ }
1357
+ hslToRgb(h, s, l) {
1358
+ let r, g, b;
1359
+ h = this.bound01(h, 360);
1360
+ s = this.bound01(s, 100);
1361
+ l = this.bound01(l, 100);
1362
+ function hue2rgb(p, q, t) {
1363
+ if (t < 0)
1364
+ t += 1;
1365
+ if (t > 1)
1366
+ t -= 1;
1367
+ if (t < 1 / 6)
1368
+ return p + (q - p) * 6 * t;
1369
+ if (t < 1 / 2)
1370
+ return q;
1371
+ if (t < 2 / 3)
1372
+ return p + (q - p) * (2 / 3 - t) * 6;
1373
+ return p;
1374
+ }
1375
+ if (s === 0) {
1376
+ r = g = b = l; // achromatic
1377
+ }
1378
+ else {
1379
+ let q = l < 0.5 ? l * (1 + s) : l + s - l * s;
1380
+ let p = 2 * l - q;
1381
+ r = hue2rgb(p, q, h + 1 / 3);
1382
+ g = hue2rgb(p, q, h);
1383
+ b = hue2rgb(p, q, h - 1 / 3);
1384
+ }
1385
+ return { r: r * 255, g: g * 255, b: b * 255 };
1386
+ }
1387
+ rgbToHsl(r, g, b) {
1388
+ r = this.bound01(r, 255);
1389
+ g = this.bound01(g, 255);
1390
+ b = this.bound01(b, 255);
1391
+ let max = mathMax(r, g, b), min = mathMin(r, g, b);
1392
+ let h, s, l = (max + min) / 2;
1393
+ if (max == min) {
1394
+ h = s = 0; // achromatic
1395
+ }
1396
+ else {
1397
+ let d = max - min;
1398
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
1399
+ switch (max) {
1400
+ case r:
1401
+ h = (g - b) / d + (g < b ? 6 : 0);
1402
+ break;
1403
+ case g:
1404
+ h = (b - r) / d + 2;
1405
+ break;
1406
+ case b:
1407
+ h = (r - g) / d + 4;
1408
+ break;
1409
+ }
1410
+ h /= 6;
1411
+ }
1412
+ return { h: h, s: s, l: l };
1413
+ }
1414
+ rgbToHsv(r, g, b) {
1415
+ r = this.bound01(r, 255);
1416
+ g = this.bound01(g, 255);
1417
+ b = this.bound01(b, 255);
1418
+ let max = mathMax(r, g, b), min = mathMin(r, g, b);
1419
+ let h, s, v = max;
1420
+ let d = max - min;
1421
+ s = max === 0 ? 0 : d / max;
1422
+ if (max == min) {
1423
+ h = 0; // achromatic
1424
+ }
1425
+ else {
1426
+ switch (max) {
1427
+ case r:
1428
+ h = (g - b) / d + (g < b ? 6 : 0);
1429
+ break;
1430
+ case g:
1431
+ h = (b - r) / d + 2;
1432
+ break;
1433
+ case b:
1434
+ h = (r - g) / d + 4;
1435
+ break;
1436
+ }
1437
+ h /= 6;
1438
+ }
1439
+ return { h: h, s: s, v: v };
1440
+ }
1441
+ rgbToHex(r, g, b, allow3Char) {
1442
+ let hex = [this.pad2(mathRound(r).toString(16)), this.pad2(mathRound(g).toString(16)), this.pad2(mathRound(b).toString(16))];
1443
+ // Return a 3 character hex if possible
1444
+ if (allow3Char &&
1445
+ hex[0].charAt(0) == hex[0].charAt(1) &&
1446
+ hex[1].charAt(0) == hex[1].charAt(1) &&
1447
+ hex[2].charAt(0) == hex[2].charAt(1)) {
1448
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
1449
+ }
1450
+ return hex.join('');
1451
+ }
1452
+ rgbaToHex(r, g, b, a, allow4Char) {
1453
+ let hex = [
1454
+ this.pad2(mathRound(r).toString(16)),
1455
+ this.pad2(mathRound(g).toString(16)),
1456
+ this.pad2(mathRound(b).toString(16)),
1457
+ this.pad2(this.convertDecimalToHex('' + a)),
1458
+ ];
1459
+ // Return a 4 character hex if possible
1460
+ if (allow4Char &&
1461
+ hex[0].charAt(0) == hex[0].charAt(1) &&
1462
+ hex[1].charAt(0) == hex[1].charAt(1) &&
1463
+ hex[2].charAt(0) == hex[2].charAt(1) &&
1464
+ hex[3].charAt(0) == hex[3].charAt(1)) {
1465
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
1466
+ }
1467
+ return hex.join('');
1468
+ }
1469
+ rgbaToArgbHex(r, g, b, a) {
1470
+ let hex = [
1471
+ this.pad2(this.convertDecimalToHex('' + a)),
1472
+ this.pad2(mathRound(r).toString(16)),
1473
+ this.pad2(mathRound(g).toString(16)),
1474
+ this.pad2(mathRound(b).toString(16)),
1475
+ ];
1476
+ return hex.join('');
1477
+ }
1478
+ static convertToPercentage(n) {
1479
+ if (n <= 1) {
1480
+ n = n * 100 + '%';
1481
+ }
1482
+ return n;
1483
+ }
1484
+ boundAlpha(a) {
1485
+ a = parseFloat(a);
1486
+ if (isNaN(a) || a < 0 || a > 1) {
1487
+ a = 1;
1488
+ }
1489
+ return a;
1490
+ }
1491
+ inputToRGB(color) {
1492
+ let rgb = { r: 0, g: 0, b: 0 };
1493
+ let a = 1;
1494
+ let s = null;
1495
+ let v = null;
1496
+ let l = null;
1497
+ let ok = false;
1498
+ let format = '';
1499
+ if (color === null) {
1500
+ color = '';
1501
+ }
1502
+ if (typeof color == 'string') {
1503
+ color = this.stringInputToObject(color);
1504
+ }
1505
+ if (typeof color == 'object') {
1506
+ if (this.isValidCSSUnit(color.r) && this.isValidCSSUnit(color.g) && this.isValidCSSUnit(color.b)) {
1507
+ rgb = this.rgbToRgb(color.r, color.g, color.b);
1508
+ ok = true;
1509
+ format = String(color.r).substr(-1) === '%' ? 'prgb' : 'rgb';
1510
+ }
1511
+ else if (this.isValidCSSUnit(color.h) && this.isValidCSSUnit(color.s) && this.isValidCSSUnit(color.v)) {
1512
+ s = TinyColor.convertToPercentage(color.s);
1513
+ v = TinyColor.convertToPercentage(color.v);
1514
+ rgb = this.hsvToRgb(color.h, s, v);
1515
+ ok = true;
1516
+ format = 'hsv';
1517
+ }
1518
+ else if (this.isValidCSSUnit(color.h) && this.isValidCSSUnit(color.s) && this.isValidCSSUnit(color.l)) {
1519
+ s = TinyColor.convertToPercentage(color.s);
1520
+ l = TinyColor.convertToPercentage(color.l);
1521
+ rgb = this.hslToRgb(color.h, s, l);
1522
+ ok = true;
1523
+ format = 'hsl';
1524
+ }
1525
+ if (color.hasOwnProperty('a')) {
1526
+ a = color.a;
1527
+ }
1528
+ }
1529
+ a = this.boundAlpha(a);
1530
+ return {
1531
+ ok: ok,
1532
+ format: color.format || format,
1533
+ r: mathMin(255, mathMax(rgb.r, 0)),
1534
+ g: mathMin(255, mathMax(rgb.g, 0)),
1535
+ b: mathMin(255, mathMax(rgb.b, 0)),
1536
+ a: a,
1537
+ };
1538
+ }
1539
+ parseIntFromHex(val) {
1540
+ return parseInt(val, 16);
1541
+ }
1542
+ convertHexToDecimal(h) {
1543
+ return this.parseIntFromHex(h) / 255;
1544
+ }
1545
+ stringInputToObject(color) {
1546
+ color = color.replace(trimLeft, '').replace(trimRight, '').toLowerCase();
1547
+ let named = false;
1548
+ if (this.names[color]) {
1549
+ color = this.names[color];
1550
+ named = true;
1551
+ }
1552
+ else if (color == 'transparent') {
1553
+ return { r: 0, g: 0, b: 0, a: 0, format: 'name' };
1554
+ }
1555
+ // Try to match string input using regular expressions.
1556
+ // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
1557
+ // Just return an object and let the conversion functions handle that.
1558
+ // This way the result will be the same whether the tinycolor is initialized with string or object.
1559
+ let match;
1560
+ if ((match = this.matchers.rgb.exec(color))) {
1561
+ return { r: match[1], g: match[2], b: match[3] };
1562
+ }
1563
+ if ((match = this.matchers.rgba.exec(color))) {
1564
+ return { r: match[1], g: match[2], b: match[3], a: match[4] };
1565
+ }
1566
+ if ((match = this.matchers.hsl.exec(color))) {
1567
+ return { h: match[1], s: match[2], l: match[3] };
1568
+ }
1569
+ if ((match = this.matchers.hsla.exec(color))) {
1570
+ return { h: match[1], s: match[2], l: match[3], a: match[4] };
1571
+ }
1572
+ if ((match = this.matchers.hsv.exec(color))) {
1573
+ return { h: match[1], s: match[2], v: match[3] };
1574
+ }
1575
+ if ((match = this.matchers.hsva.exec(color))) {
1576
+ return { h: match[1], s: match[2], v: match[3], a: match[4] };
1577
+ }
1578
+ if ((match = this.matchers.hex8.exec(color))) {
1579
+ return {
1580
+ r: this.parseIntFromHex(match[1]),
1581
+ g: this.parseIntFromHex(match[2]),
1582
+ b: this.parseIntFromHex(match[3]),
1583
+ a: this.convertHexToDecimal(match[4]),
1584
+ format: named ? 'name' : 'hex8',
1585
+ };
1586
+ }
1587
+ if ((match = this.matchers.hex6.exec(color))) {
1588
+ return {
1589
+ r: this.parseIntFromHex(match[1]),
1590
+ g: this.parseIntFromHex(match[2]),
1591
+ b: this.parseIntFromHex(match[3]),
1592
+ format: named ? 'name' : 'hex',
1593
+ };
1594
+ }
1595
+ if ((match = this.matchers.hex4.exec(color))) {
1596
+ return {
1597
+ r: this.parseIntFromHex(match[1] + '' + match[1]),
1598
+ g: this.parseIntFromHex(match[2] + '' + match[2]),
1599
+ b: this.parseIntFromHex(match[3] + '' + match[3]),
1600
+ a: this.convertHexToDecimal(match[4] + '' + match[4]),
1601
+ format: named ? 'name' : 'hex8',
1602
+ };
1603
+ }
1604
+ if ((match = this.matchers.hex3.exec(color))) {
1605
+ return {
1606
+ r: this.parseIntFromHex(match[1] + '' + match[1]),
1607
+ g: this.parseIntFromHex(match[2] + '' + match[2]),
1608
+ b: this.parseIntFromHex(match[3] + '' + match[3]),
1609
+ format: named ? 'name' : 'hex',
1610
+ };
1611
+ }
1612
+ return false;
1613
+ }
1614
+ static validateWCAG2Parms(parms) {
1615
+ // return valid WCAG2 parms for isReadable.
1616
+ // If input parms are invalid, return {"level":"AA", "size":"small"}
1617
+ let level, size;
1618
+ parms = parms || { level: 'AA', size: 'small' };
1619
+ level = (parms.level || 'AA').toUpperCase();
1620
+ size = (parms.size || 'small').toLowerCase();
1621
+ if (level !== 'AA' && level !== 'AAA') {
1622
+ level = 'AA';
1623
+ }
1624
+ if (size !== 'small' && size !== 'large') {
1625
+ size = 'small';
1626
+ }
1627
+ return { level: level, size: size };
1628
+ }
1629
+ }
1630
+
1631
+ function defineStore(storeFunction) {
1632
+ /**
1633
+ * 初始化数据
1634
+ *
1635
+ */
1636
+ // 获取store
1637
+ const store = storeFunction();
1638
+ // 备份初始store
1639
+ const storeBackups = {};
1640
+ const storeKeys = Object.keys(store).filter(key => vue.isRef(store[key]) || vue.isReactive(store[key]));
1641
+ storeKeys.forEach(key => (storeBackups[key] = lodash.cloneDeep(vue.isRef(store[key]) ? vue.unref(store[key]) : vue.toRaw(store[key]))));
1642
+ // 初始化store
1643
+ const storeInit = () => {
1644
+ storeKeys.forEach((key) => {
1645
+ if (vue.isRef(store[key])) {
1646
+ store[key].value = lodash.cloneDeep(storeBackups[key]);
1647
+ }
1648
+ else if (vue.isReactive(store[key])) {
1649
+ Object.keys(store[key]).forEach(reactiveKey => delete store[key][reactiveKey]);
1650
+ Object.assign(store[key], lodash.cloneDeep(storeBackups[key]));
1651
+ }
1652
+ });
1653
+ };
1654
+ /**
1655
+ * 活动Components
1656
+ *
1657
+ */
1658
+ let componentsCount = 0;
1659
+ const countPlus = () => {
1660
+ componentsCount++;
1661
+ };
1662
+ const countMinus = () => {
1663
+ componentsCount--;
1664
+ componentsCount === 0 && storeInit();
1665
+ };
1666
+ /**
1667
+ * 组件内调用
1668
+ */
1669
+ return (component) => {
1670
+ // 组件自定义周期
1671
+ if (component) {
1672
+ vue.onMounted(() => component.value.setStore(countPlus, countMinus));
1673
+ }
1674
+ // 根据组件周期自动销毁数据
1675
+ else {
1676
+ vue.onMounted(countPlus);
1677
+ // 使用宏任务,让组件切换时不执行init
1678
+ vue.onUnmounted(() => setTimeout(countMinus));
1679
+ }
1680
+ return store;
1681
+ };
1682
+ }
1683
+
1684
+ /*
1685
+ * @Description: 发布订阅(需要有生命周期)
1686
+ * @Author: Zye
1687
+ * @Date: 2022-12-08
1688
+ */
1689
+ function Subscribe() {
1690
+ // 存放订阅者
1691
+ const callbacks = [];
1692
+ // 设置订阅者
1693
+ const setCallback = (callback) => {
1694
+ if (callbacks.includes(callback))
1695
+ return;
1696
+ callbacks.push(callback);
1697
+ };
1698
+ // 移除订阅者
1699
+ const removeCallBack = (callback) => {
1700
+ const index = callbacks.indexOf(callback);
1701
+ index > -1 && callbacks.splice(index, 1);
1702
+ };
1703
+ return {
1704
+ send(...args) {
1705
+ callbacks.forEach((callback) => callback(...args));
1706
+ },
1707
+ set onmessage(callback) {
1708
+ if (vue.onMounted) {
1709
+ vue.onMounted(() => setCallback(callback));
1710
+ vue.onUnmounted(() => removeCallBack(callback));
1711
+ }
1712
+ else {
1713
+ console.error(`subscribe当前所处位置无生命周期,callback无法被订阅\n${callback}`);
1714
+ }
1715
+ },
1716
+ };
1717
+ }
1718
+
1719
+ /**
1720
+ *
1721
+ * @param callback 回调函数
1722
+ * @param throttleTime 节流时长
1723
+ *
1724
+ *
1725
+ * @example
1726
+ *
1727
+ * 1. 初始化 api/dict.ts -> initDict
1728
+ *
1729
+ * // initDict 接收callback函数,callback函数的参数为字典类型集合,如['dictType1','dictType2']
1730
+ * // initDict 返回值为字典集合,如{dictType1:[],dictType2:[]},可以为异步
1731
+ * export const useDict = initDict((dictTypes:string[])=>{
1732
+ * return http.get('/api/dict'{dictTypes})
1733
+ * })
1734
+ *
1735
+ * 2. 注册 views/xxx/xxx.vue -> useDict
1736
+ *
1737
+ * //页面注册dict ( 用于保存页面dict数据 )
1738
+ * const dict = useDict()
1739
+ *
1740
+ * 3. 调用 views/xxx/xxx.vue -> dict
1741
+ * dict('dictType1') // 获取dictType1字典
1742
+ * dict('dictType2') // 获取dictType2字典
1743
+ *
1744
+ * @returns
1745
+ */
1746
+ const initDict = (callback, throttleTime = 100) => {
1747
+ const useDict = () => {
1748
+ const dictTypes = [];
1749
+ const dictArrs = {};
1750
+ const dict = lodash.throttle(async (cb, dictType) => {
1751
+ const setDictTypes = [...new Set(dictTypes)];
1752
+ const res = await callback(setDictTypes);
1753
+ setDictTypes.forEach((dictType) => {
1754
+ !dictArrs[dictType].value?.length && dictArrs[dictType].value.push(...res[dictType]);
1755
+ });
1756
+ cb?.(res[dictType]);
1757
+ }, throttleTime, { leading: false });
1758
+ const getDict = (dictType, cb) => {
1759
+ if (!dictArrs[dictType]) {
1760
+ dictArrs[dictType] = vue.ref([]);
1761
+ dictTypes.push(dictType);
1762
+ dict(cb, dictType);
1763
+ }
1764
+ return dictArrs[dictType].value;
1765
+ };
1766
+ return getDict;
1767
+ };
1768
+ return useDict;
1769
+ };
1770
+
1771
+ /**
1772
+ *
1773
+ * 将文件夹下的文件按照 {文件名:文件} 的格式返回对象
1774
+ *
1775
+ * @param files
1776
+ * @param stop
1777
+ * @returns
1778
+ */
1779
+ function importFile(files, stop) {
1780
+ const fileObj = {};
1781
+ Object.keys(files).forEach((key) => {
1782
+ if (stop?.(key))
1783
+ return;
1784
+ const path = key.match(/\/([\w0-9\-]+)\/([\w0-9\-]+)\./);
1785
+ if (path)
1786
+ fileObj[path[2] === 'index' ? path[1] : path[2]] = files[key];
1787
+ });
1788
+ return fileObj;
1789
+ }
1790
+ /**
1791
+ *
1792
+ * 获取文件上传状态
1793
+ *
1794
+ * @returns 文件被拖入浏览器ref(true) 文件被拖出浏览器/松开鼠标(false)
1795
+ */
1796
+ function dragEvent() {
1797
+ const drag = vue.ref(false);
1798
+ const _true = () => (drag.value = true);
1799
+ const _false = () => (drag.value = false);
1800
+ const _in = lodash.throttle(_true, 200);
1801
+ const _out = lodash.debounce(_false, 200);
1802
+ const _over = (e) => {
1803
+ e.preventDefault();
1804
+ _in();
1805
+ _out();
1806
+ };
1807
+ vue.onMounted(() => {
1808
+ document.addEventListener('dragover', _over, false);
1809
+ document.addEventListener('drop', _false, false);
1810
+ });
1811
+ vue.onUnmounted(() => {
1812
+ document.removeEventListener('dragover', _over);
1813
+ document.removeEventListener('drop', _false);
1814
+ });
1815
+ return drag;
1816
+ }
1817
+
1818
+ exports.Num = Num;
1819
+ exports.Subscribe = Subscribe;
1820
+ exports.TinyColor = TinyColor;
1821
+ exports.addPx = addPx;
1822
+ exports.assignObject = assignObject;
1823
+ exports.browserEngine = browserEngine;
1824
+ exports.createHttp = createHttp;
1825
+ exports.defineStore = defineStore;
1826
+ exports.dragEvent = dragEvent;
1827
+ exports.exitFullscreen = exitFullscreen;
1828
+ exports.expose = expose;
1829
+ exports.fullscreen = fullscreen;
1830
+ exports.getDate = getDate;
1831
+ exports.getObject = getObject;
1832
+ exports.getSpecialDate = getSpecialDate;
1833
+ exports.getTime = getTime;
1834
+ exports.importFile = importFile;
1835
+ exports.inFullscreen = inFullscreen;
1836
+ exports.initDict = initDict;
1837
+ exports.isFullscreen = isFullscreen;
1838
+ exports.isUrl = isUrl;
1839
+ exports.on = on;
1840
+ exports.pathToHump = pathToHump;
1841
+ exports.query = query;
1842
+ exports.setTime = setTime;
1843
+ exports.setValue = setValue;
1844
+ exports.toHump = toHump;
1845
+ exports.toHyphen = toHyphen;
1846
+ exports.urlToData = urlToData;