@whitesev/utils 2.6.7 → 2.6.9

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/index.amd.js CHANGED
@@ -226,6 +226,273 @@ define((function () { 'use strict';
226
226
  }
227
227
  }
228
228
 
229
+ const TryCatch = function (...args) {
230
+ /* 定义变量和函数 */
231
+ let callbackFunction = null;
232
+ let context = null;
233
+ let handleError = (error) => { };
234
+ let defaultDetails = {
235
+ log: true,
236
+ };
237
+ const TryCatchCore = {
238
+ /**
239
+ *
240
+ * @param paramDetails 配置
241
+ * @returns
242
+ */
243
+ config(paramDetails) {
244
+ defaultDetails = Object.assign(defaultDetails, paramDetails);
245
+ return TryCatchCore;
246
+ },
247
+ /**
248
+ * 处理错误
249
+ * @param handler
250
+ */
251
+ error(handler) {
252
+ // @ts-ignore
253
+ handleError = handler;
254
+ return TryCatchCore;
255
+ },
256
+ /**
257
+ * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
258
+ * @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
259
+ * @param __context__ 待执行函数的作用域,用于apply指定
260
+ * @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
261
+ * @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
262
+ */
263
+ run(callback, __context__) {
264
+ callbackFunction = callback;
265
+ context = __context__ || this;
266
+ let result = executeTryCatch(callbackFunction, handleError, context);
267
+ // @ts-ignore
268
+ return result !== undefined ? result : TryCatchCore;
269
+ },
270
+ };
271
+ /**
272
+ * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
273
+ * @param callback - 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
274
+ * @param handleErrorFunc - 错误处理函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
275
+ * @param funcThis - 待执行函数的作用域,用于apply指定
276
+ * @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
277
+ */
278
+ function executeTryCatch(callback, handleErrorFunc, funcThis) {
279
+ let result = undefined;
280
+ try {
281
+ if (typeof callback === "string") {
282
+ result = new Function(callback).apply(funcThis, args);
283
+ }
284
+ else {
285
+ result = callback.apply(funcThis, args);
286
+ }
287
+ }
288
+ catch (error) {
289
+ if (defaultDetails.log) {
290
+ callback = callback;
291
+ console.log(`%c ${callback?.name ? callback?.name : callback + "出现错误"} `, "color: #f20000");
292
+ console.log(`%c 错误原因:${error}`, "color: #f20000");
293
+ console.trace(callback);
294
+ }
295
+ if (handleErrorFunc) {
296
+ if (typeof handleErrorFunc === "string") {
297
+ result = new Function(handleErrorFunc).apply(funcThis, [
298
+ ...args,
299
+ error,
300
+ ]);
301
+ }
302
+ else {
303
+ result = handleErrorFunc.apply(funcThis, [...args, error]);
304
+ }
305
+ }
306
+ }
307
+ return result;
308
+ }
309
+ return TryCatchCore;
310
+ };
311
+
312
+ class CommonUtil {
313
+ assign(target = {}, source = {}, isAdd = false) {
314
+ let UtilsContext = this;
315
+ if (Array.isArray(source)) {
316
+ let canTraverse = source.filter((item) => {
317
+ return typeof item === "object";
318
+ });
319
+ if (!canTraverse.length) {
320
+ return source;
321
+ }
322
+ }
323
+ if (source == null) {
324
+ return target;
325
+ }
326
+ if (target == null) {
327
+ target = {};
328
+ }
329
+ if (isAdd) {
330
+ for (const sourceKeyName in source) {
331
+ const targetKeyName = sourceKeyName;
332
+ let targetValue = target[targetKeyName];
333
+ let sourceValue = source[sourceKeyName];
334
+ if (typeof sourceValue === "object" &&
335
+ sourceValue != null &&
336
+ sourceKeyName in target &&
337
+ !UtilsContext.isDOM(sourceValue)) {
338
+ /* 源端的值是object类型,且不是元素节点 */
339
+ target[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
340
+ continue;
341
+ }
342
+ target[sourceKeyName] = sourceValue;
343
+ }
344
+ }
345
+ else {
346
+ for (const targetKeyName in target) {
347
+ if (targetKeyName in source) {
348
+ let targetValue = target[targetKeyName];
349
+ let sourceValue = source[targetKeyName];
350
+ if (typeof sourceValue === "object" &&
351
+ sourceValue != null &&
352
+ !UtilsContext.isDOM(sourceValue) &&
353
+ Object.keys(sourceValue).length) {
354
+ /* 源端的值是object类型,且不是元素节点 */
355
+ target[targetKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
356
+ continue;
357
+ }
358
+ /* 直接赋值 */
359
+ target[targetKeyName] = sourceValue;
360
+ }
361
+ }
362
+ }
363
+ return target;
364
+ }
365
+ isNull(...args) {
366
+ let result = true;
367
+ let checkList = [...args];
368
+ for (const objItem of checkList) {
369
+ let itemResult = false;
370
+ if (objItem === null || objItem === undefined) {
371
+ itemResult = true;
372
+ }
373
+ else {
374
+ switch (typeof objItem) {
375
+ case "object":
376
+ if (typeof objItem[Symbol.iterator] === "function") {
377
+ /* 可迭代 */
378
+ itemResult = objItem.length === 0;
379
+ }
380
+ else {
381
+ itemResult = Object.keys(objItem).length === 0;
382
+ }
383
+ break;
384
+ case "number":
385
+ itemResult = objItem === 0;
386
+ break;
387
+ case "string":
388
+ itemResult =
389
+ objItem.trim() === "" ||
390
+ objItem === "null" ||
391
+ objItem === "undefined";
392
+ break;
393
+ case "boolean":
394
+ itemResult = !objItem;
395
+ break;
396
+ case "function":
397
+ let funcStr = objItem.toString().replace(/\s/g, "");
398
+ /* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
399
+ itemResult = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
400
+ break;
401
+ }
402
+ }
403
+ result = result && itemResult;
404
+ }
405
+ return result;
406
+ }
407
+ /**
408
+ * 判断对象是否是元素
409
+ * @param target
410
+ * @returns
411
+ * + true 是元素
412
+ * + false 不是元素
413
+ * @example
414
+ * Utils.isDOM(document.querySelector("a"))
415
+ * > true
416
+ */
417
+ isDOM(target) {
418
+ return target instanceof Node;
419
+ }
420
+ isNotNull(...args) {
421
+ let UtilsContext = this;
422
+ return !UtilsContext.isNull.apply(this, args);
423
+ }
424
+ deepClone(obj) {
425
+ let UtilsContext = this;
426
+ if (obj === undefined)
427
+ return undefined;
428
+ if (obj === null)
429
+ return null;
430
+ let clone = obj instanceof Array ? [] : {};
431
+ for (const [key, value] of Object.entries(obj)) {
432
+ clone[key] =
433
+ typeof value === "object" ? UtilsContext.deepClone(value) : value;
434
+ }
435
+ return clone;
436
+ }
437
+ /**
438
+ * 覆盖对象中的函数this指向
439
+ * @param target 需要覆盖的对象
440
+ * @param [objectThis] 覆盖的this指向,如果为传入,则默认为对象本身
441
+ */
442
+ coverObjectFunctionThis(target, objectThis) {
443
+ if (typeof target !== "object" || target === null) {
444
+ throw new Error("target must be object");
445
+ }
446
+ objectThis = objectThis || target;
447
+ Object.keys(target).forEach((key) => {
448
+ if (typeof target[key] === "function") {
449
+ target[key] = target[key].bind(objectThis);
450
+ }
451
+ });
452
+ }
453
+ toJSON(data, errorCallBack) {
454
+ let result = {};
455
+ if (typeof data === "object") {
456
+ return data;
457
+ }
458
+ TryCatch()
459
+ .config({ log: false })
460
+ .error((error) => {
461
+ TryCatch()
462
+ .error(() => {
463
+ try {
464
+ result = new Function("return " + data)();
465
+ }
466
+ catch (error2) {
467
+ if (typeof errorCallBack === "function") {
468
+ errorCallBack(error2);
469
+ }
470
+ }
471
+ })
472
+ .run(() => {
473
+ if (data &&
474
+ /^[\],:{}\s]*$/.test(data
475
+ .replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
476
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
477
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) {
478
+ result = new Function("return " + data)();
479
+ }
480
+ else {
481
+ if (typeof errorCallBack === "function") {
482
+ errorCallBack(new Error("target is not a JSON"));
483
+ }
484
+ }
485
+ });
486
+ })
487
+ .run(() => {
488
+ data = data.trim();
489
+ result = JSON.parse(data);
490
+ });
491
+ return result;
492
+ }
493
+ }
494
+ let commonUtil = new CommonUtil();
495
+
229
496
  class UtilsGMCookie {
230
497
  windowApi = {
231
498
  window: window,
@@ -298,7 +565,7 @@ define((function () { 'use strict';
298
565
  name: "",
299
566
  path: "/",
300
567
  };
301
- defaultOption = utils.assign(defaultOption, option);
568
+ defaultOption = commonUtil.assign(defaultOption, option);
302
569
  let cookies = this.getCookiesList();
303
570
  cookies.forEach((item) => {
304
571
  item = item.trim();
@@ -349,7 +616,7 @@ define((function () { 'use strict';
349
616
  name: "",
350
617
  path: "/",
351
618
  };
352
- defaultOption = utils.assign(defaultOption, option);
619
+ defaultOption = commonUtil.assign(defaultOption, option);
353
620
  let cookies = this.getCookiesList();
354
621
  cookies.forEach((item) => {
355
622
  item = item.trim();
@@ -398,7 +665,7 @@ define((function () { 'use strict';
398
665
  */
399
666
  expirationDate: Math.floor(Date.now()) + 60 * 60 * 24 * 30,
400
667
  };
401
- defaultOption = utils.assign(defaultOption, option);
668
+ defaultOption = commonUtil.assign(defaultOption, option);
402
669
  let life = defaultOption.expirationDate
403
670
  ? defaultOption.expirationDate
404
671
  : Math.floor(Date.now()) + 60 * 60 * 24 * 30;
@@ -408,7 +675,7 @@ define((function () { 'use strict';
408
675
  ";expires=" +
409
676
  new Date(life).toGMTString() +
410
677
  "; path=/";
411
- if (utils.isNotNull(defaultOption.domain)) {
678
+ if (commonUtil.isNull(defaultOption.domain)) {
412
679
  cookieStr += "; domain=" + defaultOption.domain;
413
680
  }
414
681
  this.windowApi.document.cookie = cookieStr;
@@ -436,9 +703,9 @@ define((function () { 'use strict';
436
703
  path: "/",
437
704
  firstPartyDomain: "",
438
705
  };
439
- defaultOption = utils.assign(defaultOption, option);
706
+ defaultOption = commonUtil.assign(defaultOption, option);
440
707
  let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}`;
441
- if (utils.isNotNull(defaultOption.firstPartyDomain)) {
708
+ if (commonUtil.isNull(defaultOption.firstPartyDomain)) {
442
709
  cookieStr += `; domain=${defaultOption.firstPartyDomain};`;
443
710
  }
444
711
  this.windowApi.document.cookie = cookieStr;
@@ -1623,7 +1890,7 @@ define((function () { 'use strict';
1623
1890
  menuOptions = [menuOptions];
1624
1891
  }
1625
1892
  for (let index = 0; index < menuOptions.length; index++) {
1626
- let cloneMenuOptionData = utils.deepClone(menuOptions[index].data);
1893
+ let cloneMenuOptionData = commonUtil.deepClone(menuOptions[index].data);
1627
1894
  const { showText, clickCallBack } = this.handleMenuData(cloneMenuOptionData);
1628
1895
  let menuId = that.context.GM_Api.registerMenuCommand(showText, clickCallBack);
1629
1896
  menuOptions[index].id = menuId;
@@ -2025,16 +2292,12 @@ define((function () { 'use strict';
2025
2292
  return "";
2026
2293
  }
2027
2294
  try {
2028
- eval("_context[_funcName] = function " +
2029
- _funcName +
2030
- "(){\n" +
2031
- "let args = Array.prototype.slice.call(arguments,0);\n" +
2032
- "let obj = this;\n" +
2033
- "hookFunc.apply(obj,args);\n" +
2034
- "return _context['realFunc_" +
2035
- _funcName +
2036
- "'].apply(obj,args);\n" +
2037
- "};");
2295
+ new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
2296
+ let args = Array.prototype.slice.call(arguments, 0);
2297
+ let obj = this;
2298
+ hookFunc.apply(obj, args);
2299
+ return _context['realFunc_${_funcName}'].apply(obj, args);
2300
+ };`)(_context, _funcName, hookFunc);
2038
2301
  _context[_funcName].prototype.isHooked = true;
2039
2302
  return true;
2040
2303
  }
@@ -2294,14 +2557,14 @@ define((function () { 'use strict';
2294
2557
  if (typeof args[1] === "object") {
2295
2558
  /* 处理第二个参数details */
2296
2559
  let optionArg = args[1];
2297
- utils.assign(option, optionArg, true);
2560
+ commonUtil.assign(option, optionArg, true);
2298
2561
  option.url = url;
2299
2562
  }
2300
2563
  }
2301
2564
  else {
2302
2565
  /* 传入的是配置 */
2303
2566
  let optionArg = args[0];
2304
- utils.assign(option, optionArg, true);
2567
+ commonUtil.assign(option, optionArg, true);
2305
2568
  }
2306
2569
  return option;
2307
2570
  },
@@ -2334,7 +2597,7 @@ define((function () { 'use strict';
2334
2597
  responseType: userRequestOption.responseType ||
2335
2598
  this.context.#defaultRequestOption.responseType,
2336
2599
  /* 对象使用深拷贝 */
2337
- headers: utils.deepClone(this.context.#defaultRequestOption.headers),
2600
+ headers: commonUtil.deepClone(this.context.#defaultRequestOption.headers),
2338
2601
  data: userRequestOption.data || this.context.#defaultRequestOption.data,
2339
2602
  redirect: userRequestOption.redirect ||
2340
2603
  this.context.#defaultRequestOption.redirect,
@@ -2347,7 +2610,7 @@ define((function () { 'use strict';
2347
2610
  revalidate: userRequestOption.revalidate ||
2348
2611
  this.context.#defaultRequestOption.revalidate,
2349
2612
  /* 对象使用深拷贝 */
2350
- context: utils.deepClone(userRequestOption.context ||
2613
+ context: commonUtil.deepClone(userRequestOption.context ||
2351
2614
  this.context.#defaultRequestOption.context),
2352
2615
  overrideMimeType: userRequestOption.overrideMimeType ||
2353
2616
  this.context.#defaultRequestOption.overrideMimeType,
@@ -2355,7 +2618,7 @@ define((function () { 'use strict';
2355
2618
  this.context.#defaultRequestOption.anonymous,
2356
2619
  fetch: userRequestOption.fetch || this.context.#defaultRequestOption.fetch,
2357
2620
  /* 对象使用深拷贝 */
2358
- fetchInit: utils.deepClone(this.context.#defaultRequestOption.fetchInit),
2621
+ fetchInit: commonUtil.deepClone(this.context.#defaultRequestOption.fetchInit),
2359
2622
  allowInterceptConfig: {
2360
2623
  beforeRequest: this.context.#defaultRequestOption
2361
2624
  .allowInterceptConfig.beforeRequest,
@@ -2581,12 +2844,12 @@ define((function () { 'use strict';
2581
2844
  Object.keys(option).forEach((keyName) => {
2582
2845
  if (option[keyName] == null ||
2583
2846
  (option[keyName] instanceof Function &&
2584
- utils.isNull(option[keyName]))) {
2847
+ commonUtil.isNull(option[keyName]))) {
2585
2848
  Reflect.deleteProperty(option, keyName);
2586
2849
  return;
2587
2850
  }
2588
2851
  });
2589
- if (utils.isNull(option.url)) {
2852
+ if (commonUtil.isNull(option.url)) {
2590
2853
  throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${option.url}`);
2591
2854
  }
2592
2855
  return option;
@@ -2785,10 +3048,10 @@ define((function () { 'use strict';
2785
3048
  /* X浏览器会因为设置了responseType导致不返回responseText */
2786
3049
  let originResponse = argsResult[0];
2787
3050
  /* responseText为空,response不为空的情况 */
2788
- if (utils.isNull(originResponse["responseText"]) &&
2789
- utils.isNotNull(originResponse["response"])) {
3051
+ if (commonUtil.isNull(originResponse["responseText"]) &&
3052
+ commonUtil.isNotNull(originResponse["response"])) {
2790
3053
  if (typeof originResponse["response"] === "object") {
2791
- utils.tryCatch().run(() => {
3054
+ TryCatch().run(() => {
2792
3055
  originResponse["responseText"] = JSON.stringify(originResponse["response"]);
2793
3056
  });
2794
3057
  }
@@ -2805,7 +3068,7 @@ define((function () { 'use strict';
2805
3068
  // 自定义个新的response
2806
3069
  let httpxResponse = httpxResponseText;
2807
3070
  if (details.responseType === "json") {
2808
- httpxResponse = utils.toJSON(httpxResponseText);
3071
+ httpxResponse = commonUtil.toJSON(httpxResponseText);
2809
3072
  }
2810
3073
  else if (details.responseType === "document") {
2811
3074
  let parser = new DOMParser();
@@ -3015,7 +3278,7 @@ define((function () { 'use strict';
3015
3278
  (typeof fetchResponseType === "string" &&
3016
3279
  fetchResponseType.includes("application/json"))) {
3017
3280
  // response返回格式是JSON格式
3018
- response = utils.toJSON(responseText);
3281
+ response = commonUtil.toJSON(responseText);
3019
3282
  }
3020
3283
  else if (option.responseType === "document" ||
3021
3284
  option.responseType == null) {
@@ -3116,7 +3379,7 @@ define((function () { 'use strict';
3116
3379
  if (typeof option.xmlHttpRequest !== "function") {
3117
3380
  console.warn("[Httpx-constructor] 未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,将默认使用window.fetch");
3118
3381
  }
3119
- utils.coverObjectFunctionThis(this);
3382
+ commonUtil.coverObjectFunctionThis(this);
3120
3383
  this.interceptors.request.context = this;
3121
3384
  this.interceptors.response.context = this;
3122
3385
  this.config(option);
@@ -3129,8 +3392,8 @@ define((function () { 'use strict';
3129
3392
  if (typeof option.xmlHttpRequest === "function") {
3130
3393
  this.GM_Api.xmlHttpRequest = option.xmlHttpRequest;
3131
3394
  }
3132
- this.#defaultRequestOption = utils.assign(this.#defaultRequestOption, option);
3133
- this.#defaultInitOption = utils.assign(this.#defaultInitOption, option);
3395
+ this.#defaultRequestOption = commonUtil.assign(this.#defaultRequestOption, option);
3396
+ this.#defaultInitOption = commonUtil.assign(this.#defaultInitOption, option);
3134
3397
  }
3135
3398
  /**
3136
3399
  * 拦截器
@@ -3694,7 +3957,7 @@ define((function () { 'use strict';
3694
3957
  #flag = false;
3695
3958
  #delayTime = 0;
3696
3959
  #callback;
3697
- #context;
3960
+ #timeId = undefined;
3698
3961
  lock;
3699
3962
  unlock;
3700
3963
  run;
@@ -3704,23 +3967,22 @@ define((function () { 'use strict';
3704
3967
  this.#callback = callback;
3705
3968
  if (typeof context === "number") {
3706
3969
  this.#delayTime = context;
3707
- this.#context = utils;
3708
3970
  }
3709
3971
  else {
3710
3972
  this.#delayTime = delayTime;
3711
- this.#context = context;
3712
3973
  }
3713
3974
  /**
3714
3975
  * 锁
3715
3976
  */
3716
3977
  this.lock = function () {
3717
3978
  that.#flag = true;
3979
+ clearTimeout(that.#timeId);
3718
3980
  };
3719
3981
  /**
3720
3982
  * 解锁
3721
3983
  */
3722
3984
  this.unlock = function () {
3723
- utils.workerSetTimeout(() => {
3985
+ that.#timeId = setTimeout(() => {
3724
3986
  that.#flag = false;
3725
3987
  }, that.#delayTime);
3726
3988
  };
@@ -3738,7 +4000,7 @@ define((function () { 'use strict';
3738
4000
  return;
3739
4001
  }
3740
4002
  that.lock();
3741
- await that.#callback.apply(that.#context, args);
4003
+ await that.#callback.apply(this, args);
3742
4004
  that.unlock();
3743
4005
  };
3744
4006
  }
@@ -4026,7 +4288,7 @@ define((function () { 'use strict';
4026
4288
  * @param paramConfig 配置信息
4027
4289
  */
4028
4290
  constructor(paramConfig) {
4029
- this.#config = utils.assign(this.#config, paramConfig);
4291
+ this.#config = commonUtil.assign(this.#config, paramConfig);
4030
4292
  if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
4031
4293
  throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
4032
4294
  }
@@ -4085,91 +4347,6 @@ define((function () { 'use strict';
4085
4347
  }
4086
4348
  }
4087
4349
 
4088
- const TryCatch = function (...args) {
4089
- /* 定义变量和函数 */
4090
- let callbackFunction = null;
4091
- let context = null;
4092
- let handleError = (error) => { };
4093
- let defaultDetails = {
4094
- log: true,
4095
- };
4096
- const TryCatchCore = {
4097
- /**
4098
- *
4099
- * @param paramDetails 配置
4100
- * @returns
4101
- */
4102
- config(paramDetails) {
4103
- defaultDetails = utils.assign(defaultDetails, paramDetails);
4104
- return TryCatchCore;
4105
- },
4106
- /**
4107
- * 处理错误
4108
- * @param handler
4109
- */
4110
- error(handler) {
4111
- // @ts-ignore
4112
- handleError = handler;
4113
- return TryCatchCore;
4114
- },
4115
- /**
4116
- * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
4117
- * @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
4118
- * @param __context__ 待执行函数的作用域,用于apply指定
4119
- * @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
4120
- * @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
4121
- */
4122
- run(callback, __context__) {
4123
- callbackFunction = callback;
4124
- context = __context__ || this;
4125
- let result = executeTryCatch(callbackFunction, handleError, context);
4126
- // @ts-ignore
4127
- return result !== undefined ? result : TryCatchCore;
4128
- },
4129
- };
4130
- /**
4131
- * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
4132
- * @param callback - 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
4133
- * @param handleErrorFunc - 错误处理函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
4134
- * @param funcThis - 待执行函数的作用域,用于apply指定
4135
- * @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
4136
- */
4137
- function executeTryCatch(callback, handleErrorFunc, funcThis) {
4138
- let result = undefined;
4139
- try {
4140
- if (typeof callback === "string") {
4141
- (function () {
4142
- eval(callback);
4143
- }).apply(funcThis, args);
4144
- }
4145
- else {
4146
- result = callback.apply(funcThis, args);
4147
- }
4148
- }
4149
- catch (error) {
4150
- if (defaultDetails.log) {
4151
- callback = callback;
4152
- console.log(`%c ${callback?.name ? callback?.name : callback + "出现错误"} `, "color: #f20000");
4153
- console.log(`%c 错误原因:${error}`, "color: #f20000");
4154
- console.trace(callback);
4155
- }
4156
- if (handleErrorFunc) {
4157
- if (typeof handleErrorFunc === "string") {
4158
- result = function () {
4159
- return eval(handleErrorFunc);
4160
- // @ts-ignore
4161
- }.apply(funcThis, [...args, error]);
4162
- }
4163
- else {
4164
- result = handleErrorFunc.apply(funcThis, [...args, error]);
4165
- }
4166
- }
4167
- }
4168
- return result;
4169
- }
4170
- return TryCatchCore;
4171
- };
4172
-
4173
4350
  class UtilsDictionary {
4174
4351
  items = {};
4175
4352
  constructor(key, value) {
@@ -4285,7 +4462,7 @@ define((function () { 'use strict';
4285
4462
  * @param data 需要合并的字典
4286
4463
  */
4287
4464
  concat(data) {
4288
- this.items = utils.assign(this.items, data.getItems());
4465
+ this.items = commonUtil.assign(this.items, data.getItems());
4289
4466
  }
4290
4467
  forEach(callbackfn) {
4291
4468
  for (const key in this.getItems()) {
@@ -4844,7 +5021,7 @@ define((function () { 'use strict';
4844
5021
 
4845
5022
  const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
4846
5023
  const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
4847
- const clearTimeout = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
5024
+ const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
4848
5025
  const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
4849
5026
  const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
4850
5027
 
@@ -5246,13 +5423,194 @@ define((function () { 'use strict';
5246
5423
  }
5247
5424
  }
5248
5425
 
5426
+ class DOMUtils {
5427
+ windowApi;
5428
+ constructor(option) {
5429
+ this.windowApi = new WindowApi(option);
5430
+ }
5431
+ selector(selector, parent) {
5432
+ return this.selectorAll(selector, parent)[0];
5433
+ }
5434
+ selectorAll(selector, parent) {
5435
+ const context = this;
5436
+ parent = parent || context.windowApi.document;
5437
+ selector = selector.trim();
5438
+ if (selector.match(/[^\s]{1}:empty$/gi)) {
5439
+ // empty 语法
5440
+ selector = selector.replace(/:empty$/gi, "");
5441
+ return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
5442
+ return $ele?.innerHTML?.trim() === "";
5443
+ });
5444
+ }
5445
+ else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
5446
+ selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
5447
+ // contains 语法
5448
+ let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
5449
+ let text = textMatch[2];
5450
+ selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
5451
+ return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
5452
+ // @ts-ignore
5453
+ return ($ele?.textContent || $ele?.innerText)?.includes(text);
5454
+ });
5455
+ }
5456
+ else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
5457
+ selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
5458
+ // regexp 语法
5459
+ let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
5460
+ let pattern = textMatch[2];
5461
+ let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
5462
+ let flags = "";
5463
+ if (flagMatch) {
5464
+ pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
5465
+ flags = flagMatch[3];
5466
+ }
5467
+ let regexp = new RegExp(pattern, flags);
5468
+ selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
5469
+ return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
5470
+ // @ts-ignore
5471
+ return Boolean(($ele?.textContent || $ele?.innerText)?.match(regexp));
5472
+ });
5473
+ }
5474
+ else {
5475
+ // 普通语法
5476
+ return Array.from(parent.querySelectorAll(selector));
5477
+ }
5478
+ }
5479
+ /**
5480
+ * 匹配元素,可使用以下的额外语法
5481
+ *
5482
+ * + :contains([text]) 作用: 找到包含指定文本内容的指定元素
5483
+ * + :empty 作用:找到既没有文本内容也没有子元素的指定元素
5484
+ * + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
5485
+ * @param $el 元素
5486
+ * @param selector 选择器
5487
+ * @example
5488
+ * DOMUtils.matches("div:contains('测试')")
5489
+ * > true
5490
+ * @example
5491
+ * DOMUtils.matches("div:empty")
5492
+ * > true
5493
+ * @example
5494
+ * DOMUtils.matches("div:regexp('^xxxx$')")
5495
+ * > true
5496
+ * @example
5497
+ * DOMUtils.matches("div:regexp(/^xxx/ig)")
5498
+ * > false
5499
+ */
5500
+ matches($el, selector) {
5501
+ selector = selector.trim();
5502
+ if ($el == null) {
5503
+ return false;
5504
+ }
5505
+ if (selector.match(/[^\s]{1}:empty$/gi)) {
5506
+ // empty 语法
5507
+ selector = selector.replace(/:empty$/gi, "");
5508
+ return $el.matches(selector) && $el?.innerHTML?.trim() === "";
5509
+ }
5510
+ else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
5511
+ selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
5512
+ // contains 语法
5513
+ let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
5514
+ let text = textMatch[2];
5515
+ selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
5516
+ // @ts-ignore
5517
+ let content = $el?.textContent || $el?.innerText;
5518
+ if (typeof content !== "string") {
5519
+ content = "";
5520
+ }
5521
+ return $el.matches(selector) && content?.includes(text);
5522
+ }
5523
+ else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
5524
+ selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
5525
+ // regexp 语法
5526
+ let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
5527
+ let pattern = textMatch[2];
5528
+ let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
5529
+ let flags = "";
5530
+ if (flagMatch) {
5531
+ pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
5532
+ flags = flagMatch[3];
5533
+ }
5534
+ let regexp = new RegExp(pattern, flags);
5535
+ selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
5536
+ // @ts-ignore
5537
+ let content = $el?.textContent || $el?.innerText;
5538
+ if (typeof content !== "string") {
5539
+ content = "";
5540
+ }
5541
+ return $el.matches(selector) && Boolean(content?.match(regexp));
5542
+ }
5543
+ else {
5544
+ // 普通语法
5545
+ return $el.matches(selector);
5546
+ }
5547
+ }
5548
+ closest($el, selector) {
5549
+ selector = selector.trim();
5550
+ if (selector.match(/[^\s]{1}:empty$/gi)) {
5551
+ // empty 语法
5552
+ selector = selector.replace(/:empty$/gi, "");
5553
+ let $closest = $el?.closest(selector);
5554
+ if ($closest && $closest?.innerHTML?.trim() === "") {
5555
+ return $closest;
5556
+ }
5557
+ return null;
5558
+ }
5559
+ else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
5560
+ selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
5561
+ // contains 语法
5562
+ let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
5563
+ let text = textMatch[2];
5564
+ selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
5565
+ let $closest = $el?.closest(selector);
5566
+ if ($closest) {
5567
+ // @ts-ignore
5568
+ let content = $el?.textContent || $el?.innerText;
5569
+ if (typeof content === "string" && content.includes(text)) {
5570
+ return $closest;
5571
+ }
5572
+ }
5573
+ return null;
5574
+ }
5575
+ else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
5576
+ selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
5577
+ // regexp 语法
5578
+ let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
5579
+ let pattern = textMatch[2];
5580
+ let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
5581
+ let flags = "";
5582
+ if (flagMatch) {
5583
+ pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
5584
+ flags = flagMatch[3];
5585
+ }
5586
+ let regexp = new RegExp(pattern, flags);
5587
+ selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
5588
+ let $closest = $el?.closest(selector);
5589
+ if ($closest) {
5590
+ // @ts-ignore
5591
+ let content = $el?.textContent || $el?.innerText;
5592
+ if (typeof content === "string" && content.match(regexp)) {
5593
+ return $closest;
5594
+ }
5595
+ }
5596
+ return null;
5597
+ }
5598
+ else {
5599
+ // 普通语法
5600
+ let $closest = $el?.closest(selector);
5601
+ return $closest;
5602
+ }
5603
+ }
5604
+ }
5605
+ let domUtils = new DOMUtils();
5606
+
5249
5607
  class Utils {
5250
5608
  windowApi;
5251
5609
  constructor(option) {
5252
5610
  this.windowApi = new WindowApi(option);
5253
5611
  }
5254
5612
  /** 版本号 */
5255
- version = "2025.5.26";
5613
+ version = "2025.6.7";
5256
5614
  addStyle(cssText) {
5257
5615
  if (typeof cssText !== "string") {
5258
5616
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -5278,58 +5636,22 @@ define((function () { 'use strict';
5278
5636
  }
5279
5637
  return cssNode;
5280
5638
  }
5281
- assign(target = {}, source = {}, isAdd = false) {
5282
- let UtilsContext = this;
5283
- if (Array.isArray(source)) {
5284
- let canTraverse = source.filter((item) => {
5285
- return typeof item === "object";
5286
- });
5287
- if (!canTraverse.length) {
5288
- return source;
5289
- }
5290
- }
5291
- if (source == null) {
5292
- return target;
5293
- }
5294
- if (target == null) {
5295
- target = {};
5296
- }
5297
- if (isAdd) {
5298
- for (const sourceKeyName in source) {
5299
- const targetKeyName = sourceKeyName;
5300
- let targetValue = target[targetKeyName];
5301
- let sourceValue = source[sourceKeyName];
5302
- if (typeof sourceValue === "object" &&
5303
- sourceValue != null &&
5304
- sourceKeyName in target &&
5305
- !UtilsContext.isDOM(sourceValue)) {
5306
- /* 源端的值是object类型,且不是元素节点 */
5307
- target[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
5308
- continue;
5309
- }
5310
- target[sourceKeyName] = sourceValue;
5311
- }
5312
- }
5313
- else {
5314
- for (const targetKeyName in target) {
5315
- if (targetKeyName in source) {
5316
- let targetValue = target[targetKeyName];
5317
- let sourceValue = source[targetKeyName];
5318
- if (typeof sourceValue === "object" &&
5319
- sourceValue != null &&
5320
- !UtilsContext.isDOM(sourceValue) &&
5321
- Object.keys(sourceValue).length) {
5322
- /* 源端的值是object类型,且不是元素节点 */
5323
- target[targetKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
5324
- continue;
5325
- }
5326
- /* 直接赋值 */
5327
- target[targetKeyName] = sourceValue;
5328
- }
5639
+ /**
5640
+ * JSON数据从源端替换到目标端中,如果目标端存在该数据则替换,不添加,返回结果为目标端替换完毕的结果
5641
+ * @param target 目标数据
5642
+ * @param source 源数据
5643
+ * @param isAdd 是否可以追加键,默认false
5644
+ * @example
5645
+ * Utils.assign({"1":1,"2":{"3":3}}, {"2":{"3":4}});
5646
+ * >
5647
+ * {
5648
+ "1": 1,
5649
+ "2": {
5650
+ "3": 4
5329
5651
  }
5330
5652
  }
5331
- return target;
5332
- }
5653
+ */
5654
+ assign = commonUtil.assign.bind(commonUtil);
5333
5655
  async asyncReplaceAll(string, pattern, asyncFn) {
5334
5656
  let UtilsContext = this;
5335
5657
  if (typeof string !== "string") {
@@ -5482,19 +5804,11 @@ define((function () { 'use strict';
5482
5804
  * @returns
5483
5805
  */
5484
5806
  ColorConversion = ColorConversion;
5485
- deepClone(obj) {
5486
- let UtilsContext = this;
5487
- if (obj === undefined)
5488
- return undefined;
5489
- if (obj === null)
5490
- return null;
5491
- let clone = obj instanceof Array ? [] : {};
5492
- for (const [key, value] of Object.entries(obj)) {
5493
- clone[key] =
5494
- typeof value === "object" ? UtilsContext.deepClone(value) : value;
5495
- }
5496
- return clone;
5497
- }
5807
+ /**
5808
+ * 深拷贝
5809
+ * @param obj 对象
5810
+ */
5811
+ deepClone = commonUtil.deepClone.bind(commonUtil);
5498
5812
  debounce(fn, delay = 0) {
5499
5813
  let timer = null;
5500
5814
  let UtilsContext = this;
@@ -5517,7 +5831,7 @@ define((function () { 'use strict';
5517
5831
  throw new Error("Utils.deleteParentNode 参数 targetSelector 必须为 string 类型");
5518
5832
  }
5519
5833
  let result = false;
5520
- let needRemoveDOM = element.closest(targetSelector);
5834
+ let needRemoveDOM = domUtils.closest(element, targetSelector);
5521
5835
  if (needRemoveDOM) {
5522
5836
  needRemoveDOM.remove();
5523
5837
  result = true;
@@ -6505,9 +6819,17 @@ define((function () { 'use strict';
6505
6819
  throw new TypeError("参数1类型错误" + typeof firstArg);
6506
6820
  }
6507
6821
  }
6508
- isDOM(target) {
6509
- return target instanceof Node;
6510
- }
6822
+ /**
6823
+ * 判断对象是否是元素
6824
+ * @param target
6825
+ * @returns
6826
+ * + true 是元素
6827
+ * + false 不是元素
6828
+ * @example
6829
+ * Utils.isDOM(document.querySelector("a"))
6830
+ * > true
6831
+ */
6832
+ isDOM = commonUtil.isDOM.bind(commonUtil);
6511
6833
  isFullscreenEnabled() {
6512
6834
  return !!(this.windowApi.document.fullscreenEnabled ||
6513
6835
  this.windowApi.document.webkitFullScreenEnabled ||
@@ -6698,52 +7020,62 @@ define((function () { 'use strict';
6698
7020
  }
6699
7021
  return result;
6700
7022
  }
6701
- isNotNull(...args) {
6702
- let UtilsContext = this;
6703
- return !UtilsContext.isNull.apply(this, args);
6704
- }
6705
- isNull(...args) {
6706
- let result = true;
6707
- let checkList = [...args];
6708
- for (const objItem of checkList) {
6709
- let itemResult = false;
6710
- if (objItem === null || objItem === undefined) {
6711
- itemResult = true;
6712
- }
6713
- else {
6714
- switch (typeof objItem) {
6715
- case "object":
6716
- if (typeof objItem[Symbol.iterator] === "function") {
6717
- /* 可迭代 */
6718
- itemResult = objItem.length === 0;
6719
- }
6720
- else {
6721
- itemResult = Object.keys(objItem).length === 0;
6722
- }
6723
- break;
6724
- case "number":
6725
- itemResult = objItem === 0;
6726
- break;
6727
- case "string":
6728
- itemResult =
6729
- objItem.trim() === "" ||
6730
- objItem === "null" ||
6731
- objItem === "undefined";
6732
- break;
6733
- case "boolean":
6734
- itemResult = !objItem;
6735
- break;
6736
- case "function":
6737
- let funcStr = objItem.toString().replace(/\s/g, "");
6738
- /* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
6739
- itemResult = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
6740
- break;
6741
- }
6742
- }
6743
- result = result && itemResult;
6744
- }
6745
- return result;
6746
- }
7023
+ /**
7024
+ * 判断对象是否不为空
7025
+ * @returns {boolean}
7026
+ * + true 不为空
7027
+ * + false 为空
7028
+ * @example
7029
+ * Utils.isNotNull("123");
7030
+ * > true
7031
+ */
7032
+ isNotNull = commonUtil.isNotNull.bind(commonUtil);
7033
+ /**
7034
+ * 判断对象或数据是否为空
7035
+ * + `String`判空的值,如 ""、"null"、"undefined"、" "
7036
+ * + `Number`判空的值,如 0
7037
+ * + `Object`判空的值,如 {}、null、undefined
7038
+ * + `Array`(存在属性Symbol.iterator)判空的值,如 []
7039
+ * + `Boolean`判空的值,如false
7040
+ * + `Function`判空的值,如()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){}
7041
+ * @returns
7042
+ * + true 为空
7043
+ * + false 不为空
7044
+ * @example
7045
+ Utils.isNull({});
7046
+ > true
7047
+ * @example
7048
+ Utils.isNull([]);
7049
+ > true
7050
+ * @example
7051
+ Utils.isNull(" ");
7052
+ > true
7053
+ * @example
7054
+ Utils.isNull(function(){});
7055
+ > true
7056
+ * @example
7057
+ Utils.isNull(()=>{}));
7058
+ > true
7059
+ * @example
7060
+ Utils.isNull("undefined");
7061
+ > true
7062
+ * @example
7063
+ Utils.isNull("null");
7064
+ > true
7065
+ * @example
7066
+ Utils.isNull(" ", false);
7067
+ > true
7068
+ * @example
7069
+ Utils.isNull([1],[]);
7070
+ > false
7071
+ * @example
7072
+ Utils.isNull([],[1]);
7073
+ > false
7074
+ * @example
7075
+ Utils.isNull(false,[123]);
7076
+ > false
7077
+ **/
7078
+ isNull = commonUtil.isNull.bind(commonUtil);
6747
7079
  isThemeDark() {
6748
7080
  return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
6749
7081
  .matches;
@@ -7552,7 +7884,7 @@ define((function () { 'use strict';
7552
7884
  return mouseEvent;
7553
7885
  }
7554
7886
  let sliderElement = typeof selector === "string"
7555
- ? this.windowApi.document.querySelector(selector)
7887
+ ? domUtils.selector(selector)
7556
7888
  : selector;
7557
7889
  if (!(sliderElement instanceof Node) ||
7558
7890
  !(sliderElement instanceof Element)) {
@@ -7762,47 +8094,15 @@ define((function () { 'use strict';
7762
8094
  }
7763
8095
  return newTargetString;
7764
8096
  }
7765
- toJSON(data, errorCallBack) {
7766
- let UtilsContext = this;
7767
- let result = {};
7768
- if (typeof data === "object") {
7769
- return data;
7770
- }
7771
- UtilsContext.tryCatch()
7772
- .config({ log: false })
7773
- .error((error) => {
7774
- UtilsContext.tryCatch()
7775
- .error(() => {
7776
- try {
7777
- result = UtilsContext.windowApi.window.eval("(" + data + ")");
7778
- }
7779
- catch (error2) {
7780
- if (typeof errorCallBack === "function") {
7781
- errorCallBack(error2);
7782
- }
7783
- }
7784
- })
7785
- .run(() => {
7786
- if (data &&
7787
- /^[\],:{}\s]*$/.test(data
7788
- .replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
7789
- .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
7790
- .replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) {
7791
- result = new Function("return " + data)();
7792
- }
7793
- else {
7794
- if (typeof errorCallBack === "function") {
7795
- errorCallBack(new Error("target is not a JSON"));
7796
- }
7797
- }
7798
- });
7799
- })
7800
- .run(() => {
7801
- data = data.trim();
7802
- result = JSON.parse(data);
7803
- });
7804
- return result;
7805
- }
8097
+ /**
8098
+ * 字符串转Object对象,类似'{"test":""}' => {"test":""}
8099
+ * @param data
8100
+ * @param errorCallBack (可选)错误回调
8101
+ * @example
8102
+ * Utils.toJSON("{123:123}")
8103
+ * > {123:123}
8104
+ */
8105
+ toJSON = commonUtil.toJSON.bind(commonUtil);
7806
8106
  toSearchParamsStr(obj, addPrefix) {
7807
8107
  let UtilsContext = this;
7808
8108
  let searhParamsStr = "";
@@ -7968,7 +8268,7 @@ define((function () { 'use strict';
7968
8268
  if (Array.isArray(selector)) {
7969
8269
  let result = [];
7970
8270
  for (let index = 0; index < selector.length; index++) {
7971
- let node = parent.querySelector(selector[index]);
8271
+ let node = domUtils.selector(selector[index]);
7972
8272
  if (node) {
7973
8273
  result.push(node);
7974
8274
  }
@@ -7981,7 +8281,7 @@ define((function () { 'use strict';
7981
8281
  return selector();
7982
8282
  }
7983
8283
  else {
7984
- return parent.querySelector(selector);
8284
+ return domUtils.selector(selector, parent);
7985
8285
  }
7986
8286
  }
7987
8287
  return UtilsContext.wait(() => {
@@ -8111,7 +8411,7 @@ define((function () { 'use strict';
8111
8411
  if (Array.isArray(selector)) {
8112
8412
  let result = [];
8113
8413
  for (let index = 0; index < selector.length; index++) {
8114
- let nodeList = parent.querySelectorAll(selector[index]);
8414
+ let nodeList = domUtils.selectorAll(selector[index], parent);
8115
8415
  if (nodeList.length) {
8116
8416
  result.push(nodeList);
8117
8417
  }
@@ -8121,7 +8421,7 @@ define((function () { 'use strict';
8121
8421
  }
8122
8422
  }
8123
8423
  else {
8124
- let nodeList = parent.querySelectorAll(selector);
8424
+ let nodeList = domUtils.selectorAll(selector, parent);
8125
8425
  if (nodeList.length) {
8126
8426
  return nodeList;
8127
8427
  }
@@ -8430,17 +8730,7 @@ define((function () { 'use strict';
8430
8730
  * @param target 需要覆盖的对象
8431
8731
  * @param [objectThis] 覆盖的this指向,如果为传入,则默认为对象本身
8432
8732
  */
8433
- coverObjectFunctionThis(target, objectThis) {
8434
- if (typeof target !== "object" || target === null) {
8435
- throw new Error("target must be object");
8436
- }
8437
- objectThis = objectThis || target;
8438
- Object.keys(target).forEach((key) => {
8439
- if (typeof target[key] === "function") {
8440
- target[key] = target[key].bind(objectThis);
8441
- }
8442
- });
8443
- }
8733
+ coverObjectFunctionThis = commonUtil.coverObjectFunctionThis.bind(commonUtil);
8444
8734
  /**
8445
8735
  * 生成uuid
8446
8736
  * @example
@@ -8481,7 +8771,7 @@ define((function () { 'use strict';
8481
8771
  workerClearTimeout(timeId) {
8482
8772
  try {
8483
8773
  if (timeId != null) {
8484
- clearTimeout(timeId);
8774
+ clearTimeout$1(timeId);
8485
8775
  }
8486
8776
  }
8487
8777
  catch (error) {
@@ -8519,6 +8809,74 @@ define((function () { 'use strict';
8519
8809
  globalThis.clearInterval(timeId);
8520
8810
  }
8521
8811
  }
8812
+ /**
8813
+ * 获取剪贴板信息
8814
+ */
8815
+ async getClipboardInfo() {
8816
+ return new Promise((resolve) => {
8817
+ /** 读取剪贴板 */
8818
+ function readClipboardText() {
8819
+ navigator.clipboard
8820
+ .readText()
8821
+ .then((clipboardText) => {
8822
+ resolve({
8823
+ error: null,
8824
+ content: clipboardText,
8825
+ });
8826
+ })
8827
+ .catch((error) => {
8828
+ resolve({
8829
+ error: error,
8830
+ content: "",
8831
+ });
8832
+ });
8833
+ }
8834
+ /** 申请读取剪贴板的权限 */
8835
+ function requestPermissionsWithClipboard() {
8836
+ navigator.permissions
8837
+ .query({
8838
+ // @ts-ignore
8839
+ name: "clipboard-read",
8840
+ })
8841
+ .then((permissionStatus) => {
8842
+ readClipboardText();
8843
+ })
8844
+ .catch((error) => {
8845
+ /* 该权限申请Api可能在该环境下不生效,尝试直接读取剪贴板 */
8846
+ readClipboardText();
8847
+ });
8848
+ }
8849
+ /**
8850
+ * 检查当前环境是否支持读取剪贴板Api
8851
+ */
8852
+ function checkClipboardApi() {
8853
+ if (typeof navigator?.clipboard?.readText !== "function") {
8854
+ return false;
8855
+ }
8856
+ if (typeof navigator?.permissions?.query !== "function") {
8857
+ return false;
8858
+ }
8859
+ return true;
8860
+ }
8861
+ if (!checkClipboardApi()) {
8862
+ resolve({
8863
+ error: new Error("当前环境不支持读取剪贴板Api"),
8864
+ content: "",
8865
+ });
8866
+ return;
8867
+ }
8868
+ if (document.hasFocus()) {
8869
+ requestPermissionsWithClipboard();
8870
+ }
8871
+ else {
8872
+ window.addEventListener("focus", () => {
8873
+ requestPermissionsWithClipboard();
8874
+ }, {
8875
+ once: true,
8876
+ });
8877
+ }
8878
+ });
8879
+ }
8522
8880
  }
8523
8881
  let utils = new Utils();
8524
8882