@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.
@@ -229,6 +229,273 @@ System.register('Utils', [], (function (exports) {
229
229
  }
230
230
  }
231
231
 
232
+ const TryCatch = function (...args) {
233
+ /* 定义变量和函数 */
234
+ let callbackFunction = null;
235
+ let context = null;
236
+ let handleError = (error) => { };
237
+ let defaultDetails = {
238
+ log: true,
239
+ };
240
+ const TryCatchCore = {
241
+ /**
242
+ *
243
+ * @param paramDetails 配置
244
+ * @returns
245
+ */
246
+ config(paramDetails) {
247
+ defaultDetails = Object.assign(defaultDetails, paramDetails);
248
+ return TryCatchCore;
249
+ },
250
+ /**
251
+ * 处理错误
252
+ * @param handler
253
+ */
254
+ error(handler) {
255
+ // @ts-ignore
256
+ handleError = handler;
257
+ return TryCatchCore;
258
+ },
259
+ /**
260
+ * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
261
+ * @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
262
+ * @param __context__ 待执行函数的作用域,用于apply指定
263
+ * @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
264
+ * @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
265
+ */
266
+ run(callback, __context__) {
267
+ callbackFunction = callback;
268
+ context = __context__ || this;
269
+ let result = executeTryCatch(callbackFunction, handleError, context);
270
+ // @ts-ignore
271
+ return result !== undefined ? result : TryCatchCore;
272
+ },
273
+ };
274
+ /**
275
+ * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
276
+ * @param callback - 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
277
+ * @param handleErrorFunc - 错误处理函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
278
+ * @param funcThis - 待执行函数的作用域,用于apply指定
279
+ * @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
280
+ */
281
+ function executeTryCatch(callback, handleErrorFunc, funcThis) {
282
+ let result = undefined;
283
+ try {
284
+ if (typeof callback === "string") {
285
+ result = new Function(callback).apply(funcThis, args);
286
+ }
287
+ else {
288
+ result = callback.apply(funcThis, args);
289
+ }
290
+ }
291
+ catch (error) {
292
+ if (defaultDetails.log) {
293
+ callback = callback;
294
+ console.log(`%c ${callback?.name ? callback?.name : callback + "出现错误"} `, "color: #f20000");
295
+ console.log(`%c 错误原因:${error}`, "color: #f20000");
296
+ console.trace(callback);
297
+ }
298
+ if (handleErrorFunc) {
299
+ if (typeof handleErrorFunc === "string") {
300
+ result = new Function(handleErrorFunc).apply(funcThis, [
301
+ ...args,
302
+ error,
303
+ ]);
304
+ }
305
+ else {
306
+ result = handleErrorFunc.apply(funcThis, [...args, error]);
307
+ }
308
+ }
309
+ }
310
+ return result;
311
+ }
312
+ return TryCatchCore;
313
+ };
314
+
315
+ class CommonUtil {
316
+ assign(target = {}, source = {}, isAdd = false) {
317
+ let UtilsContext = this;
318
+ if (Array.isArray(source)) {
319
+ let canTraverse = source.filter((item) => {
320
+ return typeof item === "object";
321
+ });
322
+ if (!canTraverse.length) {
323
+ return source;
324
+ }
325
+ }
326
+ if (source == null) {
327
+ return target;
328
+ }
329
+ if (target == null) {
330
+ target = {};
331
+ }
332
+ if (isAdd) {
333
+ for (const sourceKeyName in source) {
334
+ const targetKeyName = sourceKeyName;
335
+ let targetValue = target[targetKeyName];
336
+ let sourceValue = source[sourceKeyName];
337
+ if (typeof sourceValue === "object" &&
338
+ sourceValue != null &&
339
+ sourceKeyName in target &&
340
+ !UtilsContext.isDOM(sourceValue)) {
341
+ /* 源端的值是object类型,且不是元素节点 */
342
+ target[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
343
+ continue;
344
+ }
345
+ target[sourceKeyName] = sourceValue;
346
+ }
347
+ }
348
+ else {
349
+ for (const targetKeyName in target) {
350
+ if (targetKeyName in source) {
351
+ let targetValue = target[targetKeyName];
352
+ let sourceValue = source[targetKeyName];
353
+ if (typeof sourceValue === "object" &&
354
+ sourceValue != null &&
355
+ !UtilsContext.isDOM(sourceValue) &&
356
+ Object.keys(sourceValue).length) {
357
+ /* 源端的值是object类型,且不是元素节点 */
358
+ target[targetKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
359
+ continue;
360
+ }
361
+ /* 直接赋值 */
362
+ target[targetKeyName] = sourceValue;
363
+ }
364
+ }
365
+ }
366
+ return target;
367
+ }
368
+ isNull(...args) {
369
+ let result = true;
370
+ let checkList = [...args];
371
+ for (const objItem of checkList) {
372
+ let itemResult = false;
373
+ if (objItem === null || objItem === undefined) {
374
+ itemResult = true;
375
+ }
376
+ else {
377
+ switch (typeof objItem) {
378
+ case "object":
379
+ if (typeof objItem[Symbol.iterator] === "function") {
380
+ /* 可迭代 */
381
+ itemResult = objItem.length === 0;
382
+ }
383
+ else {
384
+ itemResult = Object.keys(objItem).length === 0;
385
+ }
386
+ break;
387
+ case "number":
388
+ itemResult = objItem === 0;
389
+ break;
390
+ case "string":
391
+ itemResult =
392
+ objItem.trim() === "" ||
393
+ objItem === "null" ||
394
+ objItem === "undefined";
395
+ break;
396
+ case "boolean":
397
+ itemResult = !objItem;
398
+ break;
399
+ case "function":
400
+ let funcStr = objItem.toString().replace(/\s/g, "");
401
+ /* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
402
+ itemResult = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
403
+ break;
404
+ }
405
+ }
406
+ result = result && itemResult;
407
+ }
408
+ return result;
409
+ }
410
+ /**
411
+ * 判断对象是否是元素
412
+ * @param target
413
+ * @returns
414
+ * + true 是元素
415
+ * + false 不是元素
416
+ * @example
417
+ * Utils.isDOM(document.querySelector("a"))
418
+ * > true
419
+ */
420
+ isDOM(target) {
421
+ return target instanceof Node;
422
+ }
423
+ isNotNull(...args) {
424
+ let UtilsContext = this;
425
+ return !UtilsContext.isNull.apply(this, args);
426
+ }
427
+ deepClone(obj) {
428
+ let UtilsContext = this;
429
+ if (obj === undefined)
430
+ return undefined;
431
+ if (obj === null)
432
+ return null;
433
+ let clone = obj instanceof Array ? [] : {};
434
+ for (const [key, value] of Object.entries(obj)) {
435
+ clone[key] =
436
+ typeof value === "object" ? UtilsContext.deepClone(value) : value;
437
+ }
438
+ return clone;
439
+ }
440
+ /**
441
+ * 覆盖对象中的函数this指向
442
+ * @param target 需要覆盖的对象
443
+ * @param [objectThis] 覆盖的this指向,如果为传入,则默认为对象本身
444
+ */
445
+ coverObjectFunctionThis(target, objectThis) {
446
+ if (typeof target !== "object" || target === null) {
447
+ throw new Error("target must be object");
448
+ }
449
+ objectThis = objectThis || target;
450
+ Object.keys(target).forEach((key) => {
451
+ if (typeof target[key] === "function") {
452
+ target[key] = target[key].bind(objectThis);
453
+ }
454
+ });
455
+ }
456
+ toJSON(data, errorCallBack) {
457
+ let result = {};
458
+ if (typeof data === "object") {
459
+ return data;
460
+ }
461
+ TryCatch()
462
+ .config({ log: false })
463
+ .error((error) => {
464
+ TryCatch()
465
+ .error(() => {
466
+ try {
467
+ result = new Function("return " + data)();
468
+ }
469
+ catch (error2) {
470
+ if (typeof errorCallBack === "function") {
471
+ errorCallBack(error2);
472
+ }
473
+ }
474
+ })
475
+ .run(() => {
476
+ if (data &&
477
+ /^[\],:{}\s]*$/.test(data
478
+ .replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
479
+ .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
480
+ .replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) {
481
+ result = new Function("return " + data)();
482
+ }
483
+ else {
484
+ if (typeof errorCallBack === "function") {
485
+ errorCallBack(new Error("target is not a JSON"));
486
+ }
487
+ }
488
+ });
489
+ })
490
+ .run(() => {
491
+ data = data.trim();
492
+ result = JSON.parse(data);
493
+ });
494
+ return result;
495
+ }
496
+ }
497
+ let commonUtil = new CommonUtil();
498
+
232
499
  class UtilsGMCookie {
233
500
  windowApi = {
234
501
  window: window,
@@ -301,7 +568,7 @@ System.register('Utils', [], (function (exports) {
301
568
  name: "",
302
569
  path: "/",
303
570
  };
304
- defaultOption = utils.assign(defaultOption, option);
571
+ defaultOption = commonUtil.assign(defaultOption, option);
305
572
  let cookies = this.getCookiesList();
306
573
  cookies.forEach((item) => {
307
574
  item = item.trim();
@@ -352,7 +619,7 @@ System.register('Utils', [], (function (exports) {
352
619
  name: "",
353
620
  path: "/",
354
621
  };
355
- defaultOption = utils.assign(defaultOption, option);
622
+ defaultOption = commonUtil.assign(defaultOption, option);
356
623
  let cookies = this.getCookiesList();
357
624
  cookies.forEach((item) => {
358
625
  item = item.trim();
@@ -401,7 +668,7 @@ System.register('Utils', [], (function (exports) {
401
668
  */
402
669
  expirationDate: Math.floor(Date.now()) + 60 * 60 * 24 * 30,
403
670
  };
404
- defaultOption = utils.assign(defaultOption, option);
671
+ defaultOption = commonUtil.assign(defaultOption, option);
405
672
  let life = defaultOption.expirationDate
406
673
  ? defaultOption.expirationDate
407
674
  : Math.floor(Date.now()) + 60 * 60 * 24 * 30;
@@ -411,7 +678,7 @@ System.register('Utils', [], (function (exports) {
411
678
  ";expires=" +
412
679
  new Date(life).toGMTString() +
413
680
  "; path=/";
414
- if (utils.isNotNull(defaultOption.domain)) {
681
+ if (commonUtil.isNull(defaultOption.domain)) {
415
682
  cookieStr += "; domain=" + defaultOption.domain;
416
683
  }
417
684
  this.windowApi.document.cookie = cookieStr;
@@ -439,9 +706,9 @@ System.register('Utils', [], (function (exports) {
439
706
  path: "/",
440
707
  firstPartyDomain: "",
441
708
  };
442
- defaultOption = utils.assign(defaultOption, option);
709
+ defaultOption = commonUtil.assign(defaultOption, option);
443
710
  let cookieStr = `${defaultOption.name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${defaultOption.path}`;
444
- if (utils.isNotNull(defaultOption.firstPartyDomain)) {
711
+ if (commonUtil.isNull(defaultOption.firstPartyDomain)) {
445
712
  cookieStr += `; domain=${defaultOption.firstPartyDomain};`;
446
713
  }
447
714
  this.windowApi.document.cookie = cookieStr;
@@ -1626,7 +1893,7 @@ System.register('Utils', [], (function (exports) {
1626
1893
  menuOptions = [menuOptions];
1627
1894
  }
1628
1895
  for (let index = 0; index < menuOptions.length; index++) {
1629
- let cloneMenuOptionData = utils.deepClone(menuOptions[index].data);
1896
+ let cloneMenuOptionData = commonUtil.deepClone(menuOptions[index].data);
1630
1897
  const { showText, clickCallBack } = this.handleMenuData(cloneMenuOptionData);
1631
1898
  let menuId = that.context.GM_Api.registerMenuCommand(showText, clickCallBack);
1632
1899
  menuOptions[index].id = menuId;
@@ -2028,16 +2295,12 @@ System.register('Utils', [], (function (exports) {
2028
2295
  return "";
2029
2296
  }
2030
2297
  try {
2031
- eval("_context[_funcName] = function " +
2032
- _funcName +
2033
- "(){\n" +
2034
- "let args = Array.prototype.slice.call(arguments,0);\n" +
2035
- "let obj = this;\n" +
2036
- "hookFunc.apply(obj,args);\n" +
2037
- "return _context['realFunc_" +
2038
- _funcName +
2039
- "'].apply(obj,args);\n" +
2040
- "};");
2298
+ new Function("_context", "_funcName", "hookFunc", `_context[_funcName] = function ${_funcName}() {
2299
+ let args = Array.prototype.slice.call(arguments, 0);
2300
+ let obj = this;
2301
+ hookFunc.apply(obj, args);
2302
+ return _context['realFunc_${_funcName}'].apply(obj, args);
2303
+ };`)(_context, _funcName, hookFunc);
2041
2304
  _context[_funcName].prototype.isHooked = true;
2042
2305
  return true;
2043
2306
  }
@@ -2297,14 +2560,14 @@ System.register('Utils', [], (function (exports) {
2297
2560
  if (typeof args[1] === "object") {
2298
2561
  /* 处理第二个参数details */
2299
2562
  let optionArg = args[1];
2300
- utils.assign(option, optionArg, true);
2563
+ commonUtil.assign(option, optionArg, true);
2301
2564
  option.url = url;
2302
2565
  }
2303
2566
  }
2304
2567
  else {
2305
2568
  /* 传入的是配置 */
2306
2569
  let optionArg = args[0];
2307
- utils.assign(option, optionArg, true);
2570
+ commonUtil.assign(option, optionArg, true);
2308
2571
  }
2309
2572
  return option;
2310
2573
  },
@@ -2337,7 +2600,7 @@ System.register('Utils', [], (function (exports) {
2337
2600
  responseType: userRequestOption.responseType ||
2338
2601
  this.context.#defaultRequestOption.responseType,
2339
2602
  /* 对象使用深拷贝 */
2340
- headers: utils.deepClone(this.context.#defaultRequestOption.headers),
2603
+ headers: commonUtil.deepClone(this.context.#defaultRequestOption.headers),
2341
2604
  data: userRequestOption.data || this.context.#defaultRequestOption.data,
2342
2605
  redirect: userRequestOption.redirect ||
2343
2606
  this.context.#defaultRequestOption.redirect,
@@ -2350,7 +2613,7 @@ System.register('Utils', [], (function (exports) {
2350
2613
  revalidate: userRequestOption.revalidate ||
2351
2614
  this.context.#defaultRequestOption.revalidate,
2352
2615
  /* 对象使用深拷贝 */
2353
- context: utils.deepClone(userRequestOption.context ||
2616
+ context: commonUtil.deepClone(userRequestOption.context ||
2354
2617
  this.context.#defaultRequestOption.context),
2355
2618
  overrideMimeType: userRequestOption.overrideMimeType ||
2356
2619
  this.context.#defaultRequestOption.overrideMimeType,
@@ -2358,7 +2621,7 @@ System.register('Utils', [], (function (exports) {
2358
2621
  this.context.#defaultRequestOption.anonymous,
2359
2622
  fetch: userRequestOption.fetch || this.context.#defaultRequestOption.fetch,
2360
2623
  /* 对象使用深拷贝 */
2361
- fetchInit: utils.deepClone(this.context.#defaultRequestOption.fetchInit),
2624
+ fetchInit: commonUtil.deepClone(this.context.#defaultRequestOption.fetchInit),
2362
2625
  allowInterceptConfig: {
2363
2626
  beforeRequest: this.context.#defaultRequestOption
2364
2627
  .allowInterceptConfig.beforeRequest,
@@ -2584,12 +2847,12 @@ System.register('Utils', [], (function (exports) {
2584
2847
  Object.keys(option).forEach((keyName) => {
2585
2848
  if (option[keyName] == null ||
2586
2849
  (option[keyName] instanceof Function &&
2587
- utils.isNull(option[keyName]))) {
2850
+ commonUtil.isNull(option[keyName]))) {
2588
2851
  Reflect.deleteProperty(option, keyName);
2589
2852
  return;
2590
2853
  }
2591
2854
  });
2592
- if (utils.isNull(option.url)) {
2855
+ if (commonUtil.isNull(option.url)) {
2593
2856
  throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${option.url}`);
2594
2857
  }
2595
2858
  return option;
@@ -2788,10 +3051,10 @@ System.register('Utils', [], (function (exports) {
2788
3051
  /* X浏览器会因为设置了responseType导致不返回responseText */
2789
3052
  let originResponse = argsResult[0];
2790
3053
  /* responseText为空,response不为空的情况 */
2791
- if (utils.isNull(originResponse["responseText"]) &&
2792
- utils.isNotNull(originResponse["response"])) {
3054
+ if (commonUtil.isNull(originResponse["responseText"]) &&
3055
+ commonUtil.isNotNull(originResponse["response"])) {
2793
3056
  if (typeof originResponse["response"] === "object") {
2794
- utils.tryCatch().run(() => {
3057
+ TryCatch().run(() => {
2795
3058
  originResponse["responseText"] = JSON.stringify(originResponse["response"]);
2796
3059
  });
2797
3060
  }
@@ -2808,7 +3071,7 @@ System.register('Utils', [], (function (exports) {
2808
3071
  // 自定义个新的response
2809
3072
  let httpxResponse = httpxResponseText;
2810
3073
  if (details.responseType === "json") {
2811
- httpxResponse = utils.toJSON(httpxResponseText);
3074
+ httpxResponse = commonUtil.toJSON(httpxResponseText);
2812
3075
  }
2813
3076
  else if (details.responseType === "document") {
2814
3077
  let parser = new DOMParser();
@@ -3018,7 +3281,7 @@ System.register('Utils', [], (function (exports) {
3018
3281
  (typeof fetchResponseType === "string" &&
3019
3282
  fetchResponseType.includes("application/json"))) {
3020
3283
  // response返回格式是JSON格式
3021
- response = utils.toJSON(responseText);
3284
+ response = commonUtil.toJSON(responseText);
3022
3285
  }
3023
3286
  else if (option.responseType === "document" ||
3024
3287
  option.responseType == null) {
@@ -3119,7 +3382,7 @@ System.register('Utils', [], (function (exports) {
3119
3382
  if (typeof option.xmlHttpRequest !== "function") {
3120
3383
  console.warn("[Httpx-constructor] 未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,将默认使用window.fetch");
3121
3384
  }
3122
- utils.coverObjectFunctionThis(this);
3385
+ commonUtil.coverObjectFunctionThis(this);
3123
3386
  this.interceptors.request.context = this;
3124
3387
  this.interceptors.response.context = this;
3125
3388
  this.config(option);
@@ -3132,8 +3395,8 @@ System.register('Utils', [], (function (exports) {
3132
3395
  if (typeof option.xmlHttpRequest === "function") {
3133
3396
  this.GM_Api.xmlHttpRequest = option.xmlHttpRequest;
3134
3397
  }
3135
- this.#defaultRequestOption = utils.assign(this.#defaultRequestOption, option);
3136
- this.#defaultInitOption = utils.assign(this.#defaultInitOption, option);
3398
+ this.#defaultRequestOption = commonUtil.assign(this.#defaultRequestOption, option);
3399
+ this.#defaultInitOption = commonUtil.assign(this.#defaultInitOption, option);
3137
3400
  }
3138
3401
  /**
3139
3402
  * 拦截器
@@ -3697,7 +3960,7 @@ System.register('Utils', [], (function (exports) {
3697
3960
  #flag = false;
3698
3961
  #delayTime = 0;
3699
3962
  #callback;
3700
- #context;
3963
+ #timeId = undefined;
3701
3964
  lock;
3702
3965
  unlock;
3703
3966
  run;
@@ -3707,23 +3970,22 @@ System.register('Utils', [], (function (exports) {
3707
3970
  this.#callback = callback;
3708
3971
  if (typeof context === "number") {
3709
3972
  this.#delayTime = context;
3710
- this.#context = utils;
3711
3973
  }
3712
3974
  else {
3713
3975
  this.#delayTime = delayTime;
3714
- this.#context = context;
3715
3976
  }
3716
3977
  /**
3717
3978
  * 锁
3718
3979
  */
3719
3980
  this.lock = function () {
3720
3981
  that.#flag = true;
3982
+ clearTimeout(that.#timeId);
3721
3983
  };
3722
3984
  /**
3723
3985
  * 解锁
3724
3986
  */
3725
3987
  this.unlock = function () {
3726
- utils.workerSetTimeout(() => {
3988
+ that.#timeId = setTimeout(() => {
3727
3989
  that.#flag = false;
3728
3990
  }, that.#delayTime);
3729
3991
  };
@@ -3741,7 +4003,7 @@ System.register('Utils', [], (function (exports) {
3741
4003
  return;
3742
4004
  }
3743
4005
  that.lock();
3744
- await that.#callback.apply(that.#context, args);
4006
+ await that.#callback.apply(this, args);
3745
4007
  that.unlock();
3746
4008
  };
3747
4009
  }
@@ -4029,7 +4291,7 @@ System.register('Utils', [], (function (exports) {
4029
4291
  * @param paramConfig 配置信息
4030
4292
  */
4031
4293
  constructor(paramConfig) {
4032
- this.#config = utils.assign(this.#config, paramConfig);
4294
+ this.#config = commonUtil.assign(this.#config, paramConfig);
4033
4295
  if (!(this.#config.canvasNode instanceof HTMLCanvasElement)) {
4034
4296
  throw new Error("Utils.Progress 参数 canvasNode 必须是 HTMLCanvasElement");
4035
4297
  }
@@ -4083,95 +4345,10 @@ System.register('Utils', [], (function (exports) {
4083
4345
  /* 获取文本宽度 */
4084
4346
  let w = this.#ctx.measureText(txt).width;
4085
4347
  let h = this.#config.fontSize / 2;
4086
- this.#ctx.fillStyle = this.#config.textColor;
4087
- this.#ctx.fillText(txt, this.#width / 2 - w / 2, this.#height / 2 + h / 2);
4088
- }
4089
- }
4090
-
4091
- const TryCatch = function (...args) {
4092
- /* 定义变量和函数 */
4093
- let callbackFunction = null;
4094
- let context = null;
4095
- let handleError = (error) => { };
4096
- let defaultDetails = {
4097
- log: true,
4098
- };
4099
- const TryCatchCore = {
4100
- /**
4101
- *
4102
- * @param paramDetails 配置
4103
- * @returns
4104
- */
4105
- config(paramDetails) {
4106
- defaultDetails = utils.assign(defaultDetails, paramDetails);
4107
- return TryCatchCore;
4108
- },
4109
- /**
4110
- * 处理错误
4111
- * @param handler
4112
- */
4113
- error(handler) {
4114
- // @ts-ignore
4115
- handleError = handler;
4116
- return TryCatchCore;
4117
- },
4118
- /**
4119
- * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
4120
- * @param callback 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
4121
- * @param __context__ 待执行函数的作用域,用于apply指定
4122
- * @returns 如果函数有返回值,则返回该返回值;否则返回 tryCatchObj 函数以支持链式调用。
4123
- * @throws {Error} 如果传入参数不符合要求,则会抛出相应类型的错误。
4124
- */
4125
- run(callback, __context__) {
4126
- callbackFunction = callback;
4127
- context = __context__ || this;
4128
- let result = executeTryCatch(callbackFunction, handleError, context);
4129
- // @ts-ignore
4130
- return result !== undefined ? result : TryCatchCore;
4131
- },
4132
- };
4133
- /**
4134
- * 执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
4135
- * @param callback - 待执行函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
4136
- * @param handleErrorFunc - 错误处理函数,可以是 function 或者 string 类型。如果是 string 类型,则会被当做代码进行执行。
4137
- * @param funcThis - 待执行函数的作用域,用于apply指定
4138
- * @returns 如果函数有返回值,则返回该返回值;否则返回 undefined。
4139
- */
4140
- function executeTryCatch(callback, handleErrorFunc, funcThis) {
4141
- let result = undefined;
4142
- try {
4143
- if (typeof callback === "string") {
4144
- (function () {
4145
- eval(callback);
4146
- }).apply(funcThis, args);
4147
- }
4148
- else {
4149
- result = callback.apply(funcThis, args);
4150
- }
4151
- }
4152
- catch (error) {
4153
- if (defaultDetails.log) {
4154
- callback = callback;
4155
- console.log(`%c ${callback?.name ? callback?.name : callback + "出现错误"} `, "color: #f20000");
4156
- console.log(`%c 错误原因:${error}`, "color: #f20000");
4157
- console.trace(callback);
4158
- }
4159
- if (handleErrorFunc) {
4160
- if (typeof handleErrorFunc === "string") {
4161
- result = function () {
4162
- return eval(handleErrorFunc);
4163
- // @ts-ignore
4164
- }.apply(funcThis, [...args, error]);
4165
- }
4166
- else {
4167
- result = handleErrorFunc.apply(funcThis, [...args, error]);
4168
- }
4169
- }
4170
- }
4171
- return result;
4348
+ this.#ctx.fillStyle = this.#config.textColor;
4349
+ this.#ctx.fillText(txt, this.#width / 2 - w / 2, this.#height / 2 + h / 2);
4172
4350
  }
4173
- return TryCatchCore;
4174
- };
4351
+ }
4175
4352
 
4176
4353
  class UtilsDictionary {
4177
4354
  items = {};
@@ -4288,7 +4465,7 @@ System.register('Utils', [], (function (exports) {
4288
4465
  * @param data 需要合并的字典
4289
4466
  */
4290
4467
  concat(data) {
4291
- this.items = utils.assign(this.items, data.getItems());
4468
+ this.items = commonUtil.assign(this.items, data.getItems());
4292
4469
  }
4293
4470
  forEach(callbackfn) {
4294
4471
  for (const key in this.getItems()) {
@@ -4847,7 +5024,7 @@ System.register('Utils', [], (function (exports) {
4847
5024
 
4848
5025
  const loadOrReturnBroker = createLoadOrReturnBroker(load, worker);
4849
5026
  const clearInterval = (timerId) => loadOrReturnBroker().clearInterval(timerId);
4850
- const clearTimeout = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
5027
+ const clearTimeout$1 = (timerId) => loadOrReturnBroker().clearTimeout(timerId);
4851
5028
  const setInterval = (...args) => loadOrReturnBroker().setInterval(...args);
4852
5029
  const setTimeout$1 = (...args) => loadOrReturnBroker().setTimeout(...args);
4853
5030
 
@@ -5249,13 +5426,194 @@ System.register('Utils', [], (function (exports) {
5249
5426
  }
5250
5427
  }
5251
5428
 
5429
+ class DOMUtils {
5430
+ windowApi;
5431
+ constructor(option) {
5432
+ this.windowApi = new WindowApi(option);
5433
+ }
5434
+ selector(selector, parent) {
5435
+ return this.selectorAll(selector, parent)[0];
5436
+ }
5437
+ selectorAll(selector, parent) {
5438
+ const context = this;
5439
+ parent = parent || context.windowApi.document;
5440
+ selector = selector.trim();
5441
+ if (selector.match(/[^\s]{1}:empty$/gi)) {
5442
+ // empty 语法
5443
+ selector = selector.replace(/:empty$/gi, "");
5444
+ return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
5445
+ return $ele?.innerHTML?.trim() === "";
5446
+ });
5447
+ }
5448
+ else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
5449
+ selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
5450
+ // contains 语法
5451
+ let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
5452
+ let text = textMatch[2];
5453
+ selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
5454
+ return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
5455
+ // @ts-ignore
5456
+ return ($ele?.textContent || $ele?.innerText)?.includes(text);
5457
+ });
5458
+ }
5459
+ else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
5460
+ selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
5461
+ // regexp 语法
5462
+ let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
5463
+ let pattern = textMatch[2];
5464
+ let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
5465
+ let flags = "";
5466
+ if (flagMatch) {
5467
+ pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
5468
+ flags = flagMatch[3];
5469
+ }
5470
+ let regexp = new RegExp(pattern, flags);
5471
+ selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
5472
+ return Array.from(parent.querySelectorAll(selector)).filter(($ele) => {
5473
+ // @ts-ignore
5474
+ return Boolean(($ele?.textContent || $ele?.innerText)?.match(regexp));
5475
+ });
5476
+ }
5477
+ else {
5478
+ // 普通语法
5479
+ return Array.from(parent.querySelectorAll(selector));
5480
+ }
5481
+ }
5482
+ /**
5483
+ * 匹配元素,可使用以下的额外语法
5484
+ *
5485
+ * + :contains([text]) 作用: 找到包含指定文本内容的指定元素
5486
+ * + :empty 作用:找到既没有文本内容也没有子元素的指定元素
5487
+ * + :regexp([text]) 作用: 找到符合正则表达式的内容的指定元素
5488
+ * @param $el 元素
5489
+ * @param selector 选择器
5490
+ * @example
5491
+ * DOMUtils.matches("div:contains('测试')")
5492
+ * > true
5493
+ * @example
5494
+ * DOMUtils.matches("div:empty")
5495
+ * > true
5496
+ * @example
5497
+ * DOMUtils.matches("div:regexp('^xxxx$')")
5498
+ * > true
5499
+ * @example
5500
+ * DOMUtils.matches("div:regexp(/^xxx/ig)")
5501
+ * > false
5502
+ */
5503
+ matches($el, selector) {
5504
+ selector = selector.trim();
5505
+ if ($el == null) {
5506
+ return false;
5507
+ }
5508
+ if (selector.match(/[^\s]{1}:empty$/gi)) {
5509
+ // empty 语法
5510
+ selector = selector.replace(/:empty$/gi, "");
5511
+ return $el.matches(selector) && $el?.innerHTML?.trim() === "";
5512
+ }
5513
+ else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
5514
+ selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
5515
+ // contains 语法
5516
+ let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
5517
+ let text = textMatch[2];
5518
+ selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
5519
+ // @ts-ignore
5520
+ let content = $el?.textContent || $el?.innerText;
5521
+ if (typeof content !== "string") {
5522
+ content = "";
5523
+ }
5524
+ return $el.matches(selector) && content?.includes(text);
5525
+ }
5526
+ else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
5527
+ selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
5528
+ // regexp 语法
5529
+ let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
5530
+ let pattern = textMatch[2];
5531
+ let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
5532
+ let flags = "";
5533
+ if (flagMatch) {
5534
+ pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
5535
+ flags = flagMatch[3];
5536
+ }
5537
+ let regexp = new RegExp(pattern, flags);
5538
+ selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
5539
+ // @ts-ignore
5540
+ let content = $el?.textContent || $el?.innerText;
5541
+ if (typeof content !== "string") {
5542
+ content = "";
5543
+ }
5544
+ return $el.matches(selector) && Boolean(content?.match(regexp));
5545
+ }
5546
+ else {
5547
+ // 普通语法
5548
+ return $el.matches(selector);
5549
+ }
5550
+ }
5551
+ closest($el, selector) {
5552
+ selector = selector.trim();
5553
+ if (selector.match(/[^\s]{1}:empty$/gi)) {
5554
+ // empty 语法
5555
+ selector = selector.replace(/:empty$/gi, "");
5556
+ let $closest = $el?.closest(selector);
5557
+ if ($closest && $closest?.innerHTML?.trim() === "") {
5558
+ return $closest;
5559
+ }
5560
+ return null;
5561
+ }
5562
+ else if (selector.match(/[^\s]{1}:contains\("(.*)"\)$/i) ||
5563
+ selector.match(/[^\s]{1}:contains\('(.*)'\)$/i)) {
5564
+ // contains 语法
5565
+ let textMatch = selector.match(/:contains\(("|')(.*)("|')\)$/i);
5566
+ let text = textMatch[2];
5567
+ selector = selector.replace(/:contains\(("|')(.*)("|')\)$/gi, "");
5568
+ let $closest = $el?.closest(selector);
5569
+ if ($closest) {
5570
+ // @ts-ignore
5571
+ let content = $el?.textContent || $el?.innerText;
5572
+ if (typeof content === "string" && content.includes(text)) {
5573
+ return $closest;
5574
+ }
5575
+ }
5576
+ return null;
5577
+ }
5578
+ else if (selector.match(/[^\s]{1}:regexp\("(.*)"\)$/i) ||
5579
+ selector.match(/[^\s]{1}:regexp\('(.*)'\)$/i)) {
5580
+ // regexp 语法
5581
+ let textMatch = selector.match(/:regexp\(("|')(.*)("|')\)$/i);
5582
+ let pattern = textMatch[2];
5583
+ let flagMatch = pattern.match(/("|'),[\s]*("|')([igm]{0,3})$/i);
5584
+ let flags = "";
5585
+ if (flagMatch) {
5586
+ pattern = pattern.replace(/("|'),[\s]*("|')([igm]{0,3})$/gi, "");
5587
+ flags = flagMatch[3];
5588
+ }
5589
+ let regexp = new RegExp(pattern, flags);
5590
+ selector = selector.replace(/:regexp\(("|')(.*)("|')\)$/gi, "");
5591
+ let $closest = $el?.closest(selector);
5592
+ if ($closest) {
5593
+ // @ts-ignore
5594
+ let content = $el?.textContent || $el?.innerText;
5595
+ if (typeof content === "string" && content.match(regexp)) {
5596
+ return $closest;
5597
+ }
5598
+ }
5599
+ return null;
5600
+ }
5601
+ else {
5602
+ // 普通语法
5603
+ let $closest = $el?.closest(selector);
5604
+ return $closest;
5605
+ }
5606
+ }
5607
+ }
5608
+ let domUtils = new DOMUtils();
5609
+
5252
5610
  class Utils {
5253
5611
  windowApi;
5254
5612
  constructor(option) {
5255
5613
  this.windowApi = new WindowApi(option);
5256
5614
  }
5257
5615
  /** 版本号 */
5258
- version = "2025.5.28";
5616
+ version = "2025.6.7";
5259
5617
  addStyle(cssText) {
5260
5618
  if (typeof cssText !== "string") {
5261
5619
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -5281,58 +5639,22 @@ System.register('Utils', [], (function (exports) {
5281
5639
  }
5282
5640
  return cssNode;
5283
5641
  }
5284
- assign(target = {}, source = {}, isAdd = false) {
5285
- let UtilsContext = this;
5286
- if (Array.isArray(source)) {
5287
- let canTraverse = source.filter((item) => {
5288
- return typeof item === "object";
5289
- });
5290
- if (!canTraverse.length) {
5291
- return source;
5292
- }
5293
- }
5294
- if (source == null) {
5295
- return target;
5296
- }
5297
- if (target == null) {
5298
- target = {};
5299
- }
5300
- if (isAdd) {
5301
- for (const sourceKeyName in source) {
5302
- const targetKeyName = sourceKeyName;
5303
- let targetValue = target[targetKeyName];
5304
- let sourceValue = source[sourceKeyName];
5305
- if (typeof sourceValue === "object" &&
5306
- sourceValue != null &&
5307
- sourceKeyName in target &&
5308
- !UtilsContext.isDOM(sourceValue)) {
5309
- /* 源端的值是object类型,且不是元素节点 */
5310
- target[sourceKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
5311
- continue;
5312
- }
5313
- target[sourceKeyName] = sourceValue;
5314
- }
5315
- }
5316
- else {
5317
- for (const targetKeyName in target) {
5318
- if (targetKeyName in source) {
5319
- let targetValue = target[targetKeyName];
5320
- let sourceValue = source[targetKeyName];
5321
- if (typeof sourceValue === "object" &&
5322
- sourceValue != null &&
5323
- !UtilsContext.isDOM(sourceValue) &&
5324
- Object.keys(sourceValue).length) {
5325
- /* 源端的值是object类型,且不是元素节点 */
5326
- target[targetKeyName] = UtilsContext.assign(targetValue, sourceValue, isAdd);
5327
- continue;
5328
- }
5329
- /* 直接赋值 */
5330
- target[targetKeyName] = sourceValue;
5331
- }
5642
+ /**
5643
+ * JSON数据从源端替换到目标端中,如果目标端存在该数据则替换,不添加,返回结果为目标端替换完毕的结果
5644
+ * @param target 目标数据
5645
+ * @param source 源数据
5646
+ * @param isAdd 是否可以追加键,默认false
5647
+ * @example
5648
+ * Utils.assign({"1":1,"2":{"3":3}}, {"2":{"3":4}});
5649
+ * >
5650
+ * {
5651
+ "1": 1,
5652
+ "2": {
5653
+ "3": 4
5332
5654
  }
5333
5655
  }
5334
- return target;
5335
- }
5656
+ */
5657
+ assign = commonUtil.assign.bind(commonUtil);
5336
5658
  async asyncReplaceAll(string, pattern, asyncFn) {
5337
5659
  let UtilsContext = this;
5338
5660
  if (typeof string !== "string") {
@@ -5485,19 +5807,11 @@ System.register('Utils', [], (function (exports) {
5485
5807
  * @returns
5486
5808
  */
5487
5809
  ColorConversion = ColorConversion;
5488
- deepClone(obj) {
5489
- let UtilsContext = this;
5490
- if (obj === undefined)
5491
- return undefined;
5492
- if (obj === null)
5493
- return null;
5494
- let clone = obj instanceof Array ? [] : {};
5495
- for (const [key, value] of Object.entries(obj)) {
5496
- clone[key] =
5497
- typeof value === "object" ? UtilsContext.deepClone(value) : value;
5498
- }
5499
- return clone;
5500
- }
5810
+ /**
5811
+ * 深拷贝
5812
+ * @param obj 对象
5813
+ */
5814
+ deepClone = commonUtil.deepClone.bind(commonUtil);
5501
5815
  debounce(fn, delay = 0) {
5502
5816
  let timer = null;
5503
5817
  let UtilsContext = this;
@@ -5520,7 +5834,7 @@ System.register('Utils', [], (function (exports) {
5520
5834
  throw new Error("Utils.deleteParentNode 参数 targetSelector 必须为 string 类型");
5521
5835
  }
5522
5836
  let result = false;
5523
- let needRemoveDOM = element.closest(targetSelector);
5837
+ let needRemoveDOM = domUtils.closest(element, targetSelector);
5524
5838
  if (needRemoveDOM) {
5525
5839
  needRemoveDOM.remove();
5526
5840
  result = true;
@@ -6508,9 +6822,17 @@ System.register('Utils', [], (function (exports) {
6508
6822
  throw new TypeError("参数1类型错误" + typeof firstArg);
6509
6823
  }
6510
6824
  }
6511
- isDOM(target) {
6512
- return target instanceof Node;
6513
- }
6825
+ /**
6826
+ * 判断对象是否是元素
6827
+ * @param target
6828
+ * @returns
6829
+ * + true 是元素
6830
+ * + false 不是元素
6831
+ * @example
6832
+ * Utils.isDOM(document.querySelector("a"))
6833
+ * > true
6834
+ */
6835
+ isDOM = commonUtil.isDOM.bind(commonUtil);
6514
6836
  isFullscreenEnabled() {
6515
6837
  return !!(this.windowApi.document.fullscreenEnabled ||
6516
6838
  this.windowApi.document.webkitFullScreenEnabled ||
@@ -6701,52 +7023,62 @@ System.register('Utils', [], (function (exports) {
6701
7023
  }
6702
7024
  return result;
6703
7025
  }
6704
- isNotNull(...args) {
6705
- let UtilsContext = this;
6706
- return !UtilsContext.isNull.apply(this, args);
6707
- }
6708
- isNull(...args) {
6709
- let result = true;
6710
- let checkList = [...args];
6711
- for (const objItem of checkList) {
6712
- let itemResult = false;
6713
- if (objItem === null || objItem === undefined) {
6714
- itemResult = true;
6715
- }
6716
- else {
6717
- switch (typeof objItem) {
6718
- case "object":
6719
- if (typeof objItem[Symbol.iterator] === "function") {
6720
- /* 可迭代 */
6721
- itemResult = objItem.length === 0;
6722
- }
6723
- else {
6724
- itemResult = Object.keys(objItem).length === 0;
6725
- }
6726
- break;
6727
- case "number":
6728
- itemResult = objItem === 0;
6729
- break;
6730
- case "string":
6731
- itemResult =
6732
- objItem.trim() === "" ||
6733
- objItem === "null" ||
6734
- objItem === "undefined";
6735
- break;
6736
- case "boolean":
6737
- itemResult = !objItem;
6738
- break;
6739
- case "function":
6740
- let funcStr = objItem.toString().replace(/\s/g, "");
6741
- /* 排除()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){} */
6742
- itemResult = Boolean(funcStr.match(/^\(.*?\)=>\{\}$|^function.*?\(.*?\)\{\}$/));
6743
- break;
6744
- }
6745
- }
6746
- result = result && itemResult;
6747
- }
6748
- return result;
6749
- }
7026
+ /**
7027
+ * 判断对象是否不为空
7028
+ * @returns {boolean}
7029
+ * + true 不为空
7030
+ * + false 为空
7031
+ * @example
7032
+ * Utils.isNotNull("123");
7033
+ * > true
7034
+ */
7035
+ isNotNull = commonUtil.isNotNull.bind(commonUtil);
7036
+ /**
7037
+ * 判断对象或数据是否为空
7038
+ * + `String`判空的值,如 ""、"null"、"undefined"、" "
7039
+ * + `Number`判空的值,如 0
7040
+ * + `Object`判空的值,如 {}、null、undefined
7041
+ * + `Array`(存在属性Symbol.iterator)判空的值,如 []
7042
+ * + `Boolean`判空的值,如false
7043
+ * + `Function`判空的值,如()=>{}、(xxx="")=>{}、function(){}、function(xxx=""){}
7044
+ * @returns
7045
+ * + true 为空
7046
+ * + false 不为空
7047
+ * @example
7048
+ Utils.isNull({});
7049
+ > true
7050
+ * @example
7051
+ Utils.isNull([]);
7052
+ > true
7053
+ * @example
7054
+ Utils.isNull(" ");
7055
+ > true
7056
+ * @example
7057
+ Utils.isNull(function(){});
7058
+ > true
7059
+ * @example
7060
+ Utils.isNull(()=>{}));
7061
+ > true
7062
+ * @example
7063
+ Utils.isNull("undefined");
7064
+ > true
7065
+ * @example
7066
+ Utils.isNull("null");
7067
+ > true
7068
+ * @example
7069
+ Utils.isNull(" ", false);
7070
+ > true
7071
+ * @example
7072
+ Utils.isNull([1],[]);
7073
+ > false
7074
+ * @example
7075
+ Utils.isNull([],[1]);
7076
+ > false
7077
+ * @example
7078
+ Utils.isNull(false,[123]);
7079
+ > false
7080
+ **/
7081
+ isNull = commonUtil.isNull.bind(commonUtil);
6750
7082
  isThemeDark() {
6751
7083
  return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
6752
7084
  .matches;
@@ -7555,7 +7887,7 @@ System.register('Utils', [], (function (exports) {
7555
7887
  return mouseEvent;
7556
7888
  }
7557
7889
  let sliderElement = typeof selector === "string"
7558
- ? this.windowApi.document.querySelector(selector)
7890
+ ? domUtils.selector(selector)
7559
7891
  : selector;
7560
7892
  if (!(sliderElement instanceof Node) ||
7561
7893
  !(sliderElement instanceof Element)) {
@@ -7765,47 +8097,15 @@ System.register('Utils', [], (function (exports) {
7765
8097
  }
7766
8098
  return newTargetString;
7767
8099
  }
7768
- toJSON(data, errorCallBack) {
7769
- let UtilsContext = this;
7770
- let result = {};
7771
- if (typeof data === "object") {
7772
- return data;
7773
- }
7774
- UtilsContext.tryCatch()
7775
- .config({ log: false })
7776
- .error((error) => {
7777
- UtilsContext.tryCatch()
7778
- .error(() => {
7779
- try {
7780
- result = UtilsContext.windowApi.window.eval("(" + data + ")");
7781
- }
7782
- catch (error2) {
7783
- if (typeof errorCallBack === "function") {
7784
- errorCallBack(error2);
7785
- }
7786
- }
7787
- })
7788
- .run(() => {
7789
- if (data &&
7790
- /^[\],:{}\s]*$/.test(data
7791
- .replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
7792
- .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
7793
- .replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) {
7794
- result = new Function("return " + data)();
7795
- }
7796
- else {
7797
- if (typeof errorCallBack === "function") {
7798
- errorCallBack(new Error("target is not a JSON"));
7799
- }
7800
- }
7801
- });
7802
- })
7803
- .run(() => {
7804
- data = data.trim();
7805
- result = JSON.parse(data);
7806
- });
7807
- return result;
7808
- }
8100
+ /**
8101
+ * 字符串转Object对象,类似'{"test":""}' => {"test":""}
8102
+ * @param data
8103
+ * @param errorCallBack (可选)错误回调
8104
+ * @example
8105
+ * Utils.toJSON("{123:123}")
8106
+ * > {123:123}
8107
+ */
8108
+ toJSON = commonUtil.toJSON.bind(commonUtil);
7809
8109
  toSearchParamsStr(obj, addPrefix) {
7810
8110
  let UtilsContext = this;
7811
8111
  let searhParamsStr = "";
@@ -7971,7 +8271,7 @@ System.register('Utils', [], (function (exports) {
7971
8271
  if (Array.isArray(selector)) {
7972
8272
  let result = [];
7973
8273
  for (let index = 0; index < selector.length; index++) {
7974
- let node = parent.querySelector(selector[index]);
8274
+ let node = domUtils.selector(selector[index]);
7975
8275
  if (node) {
7976
8276
  result.push(node);
7977
8277
  }
@@ -7984,7 +8284,7 @@ System.register('Utils', [], (function (exports) {
7984
8284
  return selector();
7985
8285
  }
7986
8286
  else {
7987
- return parent.querySelector(selector);
8287
+ return domUtils.selector(selector, parent);
7988
8288
  }
7989
8289
  }
7990
8290
  return UtilsContext.wait(() => {
@@ -8114,7 +8414,7 @@ System.register('Utils', [], (function (exports) {
8114
8414
  if (Array.isArray(selector)) {
8115
8415
  let result = [];
8116
8416
  for (let index = 0; index < selector.length; index++) {
8117
- let nodeList = parent.querySelectorAll(selector[index]);
8417
+ let nodeList = domUtils.selectorAll(selector[index], parent);
8118
8418
  if (nodeList.length) {
8119
8419
  result.push(nodeList);
8120
8420
  }
@@ -8124,7 +8424,7 @@ System.register('Utils', [], (function (exports) {
8124
8424
  }
8125
8425
  }
8126
8426
  else {
8127
- let nodeList = parent.querySelectorAll(selector);
8427
+ let nodeList = domUtils.selectorAll(selector, parent);
8128
8428
  if (nodeList.length) {
8129
8429
  return nodeList;
8130
8430
  }
@@ -8433,17 +8733,7 @@ System.register('Utils', [], (function (exports) {
8433
8733
  * @param target 需要覆盖的对象
8434
8734
  * @param [objectThis] 覆盖的this指向,如果为传入,则默认为对象本身
8435
8735
  */
8436
- coverObjectFunctionThis(target, objectThis) {
8437
- if (typeof target !== "object" || target === null) {
8438
- throw new Error("target must be object");
8439
- }
8440
- objectThis = objectThis || target;
8441
- Object.keys(target).forEach((key) => {
8442
- if (typeof target[key] === "function") {
8443
- target[key] = target[key].bind(objectThis);
8444
- }
8445
- });
8446
- }
8736
+ coverObjectFunctionThis = commonUtil.coverObjectFunctionThis.bind(commonUtil);
8447
8737
  /**
8448
8738
  * 生成uuid
8449
8739
  * @example
@@ -8484,7 +8774,7 @@ System.register('Utils', [], (function (exports) {
8484
8774
  workerClearTimeout(timeId) {
8485
8775
  try {
8486
8776
  if (timeId != null) {
8487
- clearTimeout(timeId);
8777
+ clearTimeout$1(timeId);
8488
8778
  }
8489
8779
  }
8490
8780
  catch (error) {