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