@whitesev/utils 2.7.2 → 2.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.amd.js +98 -203
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +98 -203
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +98 -203
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +98 -203
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +98 -203
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +98 -203
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +30 -2
- package/dist/types/src/types/Event.d.ts +1 -2
- package/dist/types/src/types/Httpx.d.ts +4 -21
- package/dist/types/src/types/ajaxHooker.d.ts +1 -5
- package/package.json +1 -1
- package/src/ColorConversion.ts +5 -18
- package/src/CommonUtil.ts +8 -31
- package/src/DOMUtils.ts +9 -22
- package/src/Dictionary.ts +2 -7
- package/src/GBKEncoder.ts +1 -6
- package/src/Hooks.ts +1 -4
- package/src/Httpx.ts +102 -277
- package/src/LockFunction.ts +1 -3
- package/src/Log.ts +7 -23
- package/src/Progress.ts +2 -10
- package/src/TryCatch.ts +3 -11
- package/src/Utils.ts +209 -555
- package/src/UtilsCommon.ts +5 -9
- package/src/UtilsGMCookie.ts +1 -4
- package/src/UtilsGMMenu.ts +10 -29
- package/src/Vue.ts +2 -11
- package/src/indexedDB.ts +3 -12
- package/src/types/Event.d.ts +1 -2
- package/src/types/Httpx.d.ts +4 -21
- package/src/types/ajaxHooker.d.ts +1 -5
package/src/Utils.ts
CHANGED
|
@@ -17,11 +17,7 @@ import type { UtilsAjaxHookResult } from "./types/ajaxHooker";
|
|
|
17
17
|
import { GenerateUUID } from "./UtilsCommon";
|
|
18
18
|
import { WindowApi } from "./WindowApi";
|
|
19
19
|
import { Vue } from "./Vue";
|
|
20
|
-
import {
|
|
21
|
-
type ArgsType,
|
|
22
|
-
type JSTypeNames,
|
|
23
|
-
type UtilsOwnObject,
|
|
24
|
-
} from "./types/global";
|
|
20
|
+
import { type ArgsType, type JSTypeNames, type UtilsOwnObject } from "./types/global";
|
|
25
21
|
import type { WindowApiOption } from "./types/WindowApi";
|
|
26
22
|
import {
|
|
27
23
|
clearInterval as WorkerClearInterval,
|
|
@@ -39,7 +35,7 @@ class Utils {
|
|
|
39
35
|
this.windowApi = new WindowApi(option);
|
|
40
36
|
}
|
|
41
37
|
/** 版本号 */
|
|
42
|
-
version = "2025.
|
|
38
|
+
version = "2025.8.11";
|
|
43
39
|
/**
|
|
44
40
|
* 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
|
|
45
41
|
* @param cssText css字符串
|
|
@@ -62,9 +58,7 @@ class Utils {
|
|
|
62
58
|
} else if (this.windowApi.document.body) {
|
|
63
59
|
/* 插入body后 */
|
|
64
60
|
this.windowApi.document.body.appendChild(cssNode);
|
|
65
|
-
} else if (
|
|
66
|
-
this.windowApi.document.documentElement.childNodes.length === 0
|
|
67
|
-
) {
|
|
61
|
+
} else if (this.windowApi.document.documentElement.childNodes.length === 0) {
|
|
68
62
|
/* 插入#html第一个元素后 */
|
|
69
63
|
this.windowApi.document.documentElement.appendChild(cssNode);
|
|
70
64
|
} else {
|
|
@@ -180,9 +174,7 @@ class Utils {
|
|
|
180
174
|
view = this.windowApi.window
|
|
181
175
|
) {
|
|
182
176
|
if (!(canvasElement instanceof HTMLCanvasElement)) {
|
|
183
|
-
throw new Error(
|
|
184
|
-
"Utils.canvasClickByPosition 参数canvasElement必须是canvas元素"
|
|
185
|
-
);
|
|
177
|
+
throw new Error("Utils.canvasClickByPosition 参数canvasElement必须是canvas元素");
|
|
186
178
|
}
|
|
187
179
|
clientX = parseInt(clientX.toString());
|
|
188
180
|
clientY = parseInt(clientY.toString());
|
|
@@ -213,24 +205,16 @@ class Utils {
|
|
|
213
205
|
checkUserClickInNode(element: Element | Node | HTMLElement) {
|
|
214
206
|
let UtilsContext = this;
|
|
215
207
|
if (!UtilsContext.isDOM(element)) {
|
|
216
|
-
throw new Error(
|
|
217
|
-
"Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型"
|
|
218
|
-
);
|
|
208
|
+
throw new Error("Utils.checkUserClickInNode 参数 targetNode 必须为 Element|Node 类型");
|
|
219
209
|
}
|
|
220
210
|
let clickEvent = UtilsContext.windowApi.window.event as PointerEvent;
|
|
221
211
|
let touchEvent = UtilsContext.windowApi.window.event as TouchEvent;
|
|
222
212
|
let $click = clickEvent?.composedPath()?.[0] as HTMLElement;
|
|
223
213
|
|
|
224
214
|
// 点击的x坐标
|
|
225
|
-
let clickPosX =
|
|
226
|
-
clickEvent?.clientX != null
|
|
227
|
-
? clickEvent.clientX
|
|
228
|
-
: touchEvent.touches[0].clientX;
|
|
215
|
+
let clickPosX = clickEvent?.clientX != null ? clickEvent.clientX : touchEvent.touches[0].clientX;
|
|
229
216
|
// 点击的y坐标
|
|
230
|
-
let clickPosY =
|
|
231
|
-
clickEvent?.clientY != null
|
|
232
|
-
? clickEvent.clientY
|
|
233
|
-
: touchEvent.touches[0].clientY;
|
|
217
|
+
let clickPosY = clickEvent?.clientY != null ? clickEvent.clientY : touchEvent.touches[0].clientY;
|
|
234
218
|
let {
|
|
235
219
|
/* 要检测的元素的相对屏幕的横坐标最左边 */
|
|
236
220
|
left: elementPosXLeft,
|
|
@@ -265,8 +249,7 @@ class Utils {
|
|
|
265
249
|
): T {
|
|
266
250
|
let clonedFormData = new FormData() as T;
|
|
267
251
|
for (let [key, value] of (formData as any).entries()) {
|
|
268
|
-
let isFilter =
|
|
269
|
-
typeof filterFn === "function" ? filterFn(key, value) : false;
|
|
252
|
+
let isFilter = typeof filterFn === "function" ? filterFn(key, value) : false;
|
|
270
253
|
if (typeof isFilter === "boolean" && isFilter) {
|
|
271
254
|
continue;
|
|
272
255
|
}
|
|
@@ -298,17 +281,13 @@ class Utils {
|
|
|
298
281
|
/**
|
|
299
282
|
* 前面的参数都是字符串,最后一个参数是函数
|
|
300
283
|
*/
|
|
301
|
-
addImpl<T extends JSTypeNames[]>(
|
|
302
|
-
...args: [...T, (...args: ArgsType<T>) => any]
|
|
303
|
-
): void;
|
|
284
|
+
addImpl<T extends JSTypeNames[]>(...args: [...T, (...args: ArgsType<T>) => any]): void;
|
|
304
285
|
};
|
|
305
286
|
createOverload(): {
|
|
306
287
|
/**
|
|
307
288
|
* 前面的参数都是字符串,最后一个参数是函数
|
|
308
289
|
*/
|
|
309
|
-
addImpl<T extends JSTypeNames[]>(
|
|
310
|
-
...args: [...T, (...args: ArgsType<T>) => any]
|
|
311
|
-
): void;
|
|
290
|
+
addImpl<T extends JSTypeNames[]>(...args: [...T, (...args: ArgsType<T>) => any]): void;
|
|
312
291
|
} {
|
|
313
292
|
let fnMap = new Map();
|
|
314
293
|
function overload(this: any, ...args: any[]) {
|
|
@@ -344,10 +323,7 @@ class Utils {
|
|
|
344
323
|
* @param fn 需要触发的回调
|
|
345
324
|
* @param delay 防抖判定时间(毫秒),默认是0ms
|
|
346
325
|
*/
|
|
347
|
-
debounce<A extends any[], R>(
|
|
348
|
-
fn: (...args: A) => R,
|
|
349
|
-
delay?: number
|
|
350
|
-
): (...args: A) => void;
|
|
326
|
+
debounce<A extends any[], R>(fn: (...args: A) => R, delay?: number): (...args: A) => void;
|
|
351
327
|
debounce<A extends any[], R>(fn: (...args: A) => R, delay = 0) {
|
|
352
328
|
let timer: any = null as any;
|
|
353
329
|
let UtilsContext = this;
|
|
@@ -369,33 +345,20 @@ class Utils {
|
|
|
369
345
|
* Utils.deleteParentNode(document.querySelector("a"),".xxx");
|
|
370
346
|
* > true
|
|
371
347
|
**/
|
|
372
|
-
deleteParentNode(
|
|
373
|
-
|
|
374
|
-
targetSelector: string
|
|
375
|
-
): boolean;
|
|
376
|
-
deleteParentNode(
|
|
377
|
-
element: Node | HTMLElement | Element | null,
|
|
378
|
-
targetSelector: string
|
|
379
|
-
) {
|
|
348
|
+
deleteParentNode(element: Node | HTMLElement | Element | null, targetSelector: string): boolean;
|
|
349
|
+
deleteParentNode(element: Node | HTMLElement | Element | null, targetSelector: string) {
|
|
380
350
|
let UtilsContext = this;
|
|
381
351
|
if (element == null) {
|
|
382
352
|
return;
|
|
383
353
|
}
|
|
384
354
|
if (!UtilsContext.isDOM(element)) {
|
|
385
|
-
throw new Error(
|
|
386
|
-
"Utils.deleteParentNode 参数 target 必须为 Node|HTMLElement 类型"
|
|
387
|
-
);
|
|
355
|
+
throw new Error("Utils.deleteParentNode 参数 target 必须为 Node|HTMLElement 类型");
|
|
388
356
|
}
|
|
389
357
|
if (typeof targetSelector !== "string") {
|
|
390
|
-
throw new Error(
|
|
391
|
-
"Utils.deleteParentNode 参数 targetSelector 必须为 string 类型"
|
|
392
|
-
);
|
|
358
|
+
throw new Error("Utils.deleteParentNode 参数 targetSelector 必须为 string 类型");
|
|
393
359
|
}
|
|
394
360
|
let result = false;
|
|
395
|
-
let needRemoveDOM = domUtils.closest(
|
|
396
|
-
element as HTMLElement,
|
|
397
|
-
targetSelector
|
|
398
|
-
);
|
|
361
|
+
let needRemoveDOM = domUtils.closest(element as HTMLElement, targetSelector);
|
|
399
362
|
if (needRemoveDOM) {
|
|
400
363
|
needRemoveDOM.remove();
|
|
401
364
|
result = true;
|
|
@@ -441,11 +404,7 @@ class Utils {
|
|
|
441
404
|
* @example
|
|
442
405
|
* Utils.dispatchEvent(document.querySelector("input","input"))
|
|
443
406
|
*/
|
|
444
|
-
dispatchEvent(
|
|
445
|
-
element: HTMLElement | Document,
|
|
446
|
-
eventName: string,
|
|
447
|
-
details?: any
|
|
448
|
-
): void;
|
|
407
|
+
dispatchEvent(element: HTMLElement | Document, eventName: string, details?: any): void;
|
|
449
408
|
dispatchEvent(
|
|
450
409
|
element: HTMLElement | Document,
|
|
451
410
|
eventName: DOMUtils_EventType | DOMUtils_EventType[] | string,
|
|
@@ -475,17 +434,11 @@ class Utils {
|
|
|
475
434
|
* @example
|
|
476
435
|
* Utils.downloadBase64("data:image/jpeg:base64/,xxxxxx");
|
|
477
436
|
**/
|
|
478
|
-
downloadBase64(
|
|
479
|
-
base64Data: string,
|
|
480
|
-
fileName: string,
|
|
481
|
-
isIFrame?: boolean
|
|
482
|
-
): void;
|
|
437
|
+
downloadBase64(base64Data: string, fileName: string, isIFrame?: boolean): void;
|
|
483
438
|
downloadBase64(base64Data: string, fileName: string, isIFrame = false) {
|
|
484
439
|
let UtilsContext = this;
|
|
485
440
|
if (typeof base64Data !== "string") {
|
|
486
|
-
throw new Error(
|
|
487
|
-
"Utils.downloadBase64 参数 base64Data 必须为 string 类型"
|
|
488
|
-
);
|
|
441
|
+
throw new Error("Utils.downloadBase64 参数 base64Data 必须为 string 类型");
|
|
489
442
|
}
|
|
490
443
|
if (typeof fileName !== "string") {
|
|
491
444
|
throw new Error("Utils.downloadBase64 参数 fileName 必须为 string 类型");
|
|
@@ -497,11 +450,7 @@ class Utils {
|
|
|
497
450
|
iframeElement.src = base64Data;
|
|
498
451
|
this.windowApi.document.body.appendChild(iframeElement);
|
|
499
452
|
UtilsContext.workerSetTimeout(() => {
|
|
500
|
-
iframeElement!.contentWindow!.document.execCommand(
|
|
501
|
-
"SaveAs",
|
|
502
|
-
true,
|
|
503
|
-
fileName
|
|
504
|
-
);
|
|
453
|
+
iframeElement!.contentWindow!.document.execCommand("SaveAs", true, fileName);
|
|
505
454
|
this.windowApi.document.body.removeChild(iframeElement);
|
|
506
455
|
}, 100);
|
|
507
456
|
} else {
|
|
@@ -536,11 +485,7 @@ class Utils {
|
|
|
536
485
|
/* CODE FOR BROWSERS THAT SUPPORT window.find */
|
|
537
486
|
let windowFind = (this.windowApi.self as any).find;
|
|
538
487
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
539
|
-
if (
|
|
540
|
-
strFound &&
|
|
541
|
-
this.windowApi.self.getSelection &&
|
|
542
|
-
!this.windowApi.self.getSelection()!.anchorNode
|
|
543
|
-
) {
|
|
488
|
+
if (strFound && this.windowApi.self.getSelection && !this.windowApi.self.getSelection()!.anchorNode) {
|
|
544
489
|
strFound = windowFind(str, caseSensitive, true, true, false);
|
|
545
490
|
}
|
|
546
491
|
if (!strFound) {
|
|
@@ -589,19 +534,15 @@ class Utils {
|
|
|
589
534
|
let that = this;
|
|
590
535
|
if ((element as HTMLElement).outerHTML.includes(text)) {
|
|
591
536
|
if ((element as HTMLElement).children.length === 0) {
|
|
592
|
-
let filterResult =
|
|
593
|
-
typeof filter === "function" ? filter(element) : false;
|
|
537
|
+
let filterResult = typeof filter === "function" ? filter(element) : false;
|
|
594
538
|
if (!filterResult) {
|
|
595
539
|
yield element as any;
|
|
596
540
|
}
|
|
597
541
|
} else {
|
|
598
|
-
let textElement = Array.from(element.childNodes).filter(
|
|
599
|
-
(ele) => ele.nodeType === Node.TEXT_NODE
|
|
600
|
-
);
|
|
542
|
+
let textElement = Array.from(element.childNodes).filter((ele) => ele.nodeType === Node.TEXT_NODE);
|
|
601
543
|
for (let ele of textElement) {
|
|
602
544
|
if ((ele as any).textContent.includes(text)) {
|
|
603
|
-
let filterResult =
|
|
604
|
-
typeof filter === "function" ? filter(element) : false;
|
|
545
|
+
let filterResult = typeof filter === "function" ? filter(element) : false;
|
|
605
546
|
if (!filterResult) {
|
|
606
547
|
yield ele;
|
|
607
548
|
}
|
|
@@ -610,11 +551,7 @@ class Utils {
|
|
|
610
551
|
}
|
|
611
552
|
}
|
|
612
553
|
|
|
613
|
-
for (
|
|
614
|
-
let index = 0;
|
|
615
|
-
index < (element as HTMLElement).children.length;
|
|
616
|
-
index++
|
|
617
|
-
) {
|
|
554
|
+
for (let index = 0; index < (element as HTMLElement).children.length; index++) {
|
|
618
555
|
let childElement = (element as HTMLElement).children[index] as any;
|
|
619
556
|
yield* that.findElementsWithText(childElement, text, filter);
|
|
620
557
|
}
|
|
@@ -686,9 +623,7 @@ class Utils {
|
|
|
686
623
|
}
|
|
687
624
|
}
|
|
688
625
|
result = result.toFixed(2) as any;
|
|
689
|
-
result = addType
|
|
690
|
-
? result + resultType.toString()
|
|
691
|
-
: (parseFloat(result.toString()) as any);
|
|
626
|
+
result = addType ? result + resultType.toString() : (parseFloat(result.toString()) as any);
|
|
692
627
|
return result;
|
|
693
628
|
}
|
|
694
629
|
/**
|
|
@@ -863,14 +798,7 @@ class Utils {
|
|
|
863
798
|
if (text.length === 8) {
|
|
864
799
|
/* 该字符串只有时分秒 */
|
|
865
800
|
let today = new Date();
|
|
866
|
-
text =
|
|
867
|
-
today.getFullYear() +
|
|
868
|
-
"-" +
|
|
869
|
-
(today.getMonth() + 1) +
|
|
870
|
-
"-" +
|
|
871
|
-
today.getDate() +
|
|
872
|
-
" " +
|
|
873
|
-
text;
|
|
801
|
+
text = today.getFullYear() + "-" + (today.getMonth() + 1) + "-" + today.getDate() + " " + text;
|
|
874
802
|
}
|
|
875
803
|
text = text.substring(0, 19);
|
|
876
804
|
text = text.replace(/-/g, "/");
|
|
@@ -891,25 +819,13 @@ class Utils {
|
|
|
891
819
|
* 获取 transitionend 的在各个浏览器的兼容名
|
|
892
820
|
*/
|
|
893
821
|
getTransitionEndNameList() {
|
|
894
|
-
return [
|
|
895
|
-
"webkitTransitionEnd",
|
|
896
|
-
"mozTransitionEnd",
|
|
897
|
-
"MSTransitionEnd",
|
|
898
|
-
"otransitionend",
|
|
899
|
-
"transitionend",
|
|
900
|
-
];
|
|
822
|
+
return ["webkitTransitionEnd", "mozTransitionEnd", "MSTransitionEnd", "otransitionend", "transitionend"];
|
|
901
823
|
}
|
|
902
824
|
/**
|
|
903
825
|
* 获取 animationend 的在各个浏览器的兼容名
|
|
904
826
|
*/
|
|
905
827
|
getAnimationEndNameList() {
|
|
906
|
-
return [
|
|
907
|
-
"webkitAnimationEnd",
|
|
908
|
-
"mozAnimationEnd",
|
|
909
|
-
"MSAnimationEnd",
|
|
910
|
-
"oanimationend",
|
|
911
|
-
"animationend",
|
|
912
|
-
];
|
|
828
|
+
return ["webkitAnimationEnd", "mozAnimationEnd", "MSAnimationEnd", "oanimationend", "animationend"];
|
|
913
829
|
}
|
|
914
830
|
/**
|
|
915
831
|
* 获取NodeList或Array对象中的最后一个的值
|
|
@@ -965,11 +881,7 @@ class Utils {
|
|
|
965
881
|
* Utils.getDaysDifference(new Date().getTime(),undefined,"秒");
|
|
966
882
|
* > 0
|
|
967
883
|
*/
|
|
968
|
-
getDaysDifference(
|
|
969
|
-
timestamp1?: number,
|
|
970
|
-
timestamp2?: number,
|
|
971
|
-
type?: "auto"
|
|
972
|
-
): string;
|
|
884
|
+
getDaysDifference(timestamp1?: number, timestamp2?: number, type?: "auto"): string;
|
|
973
885
|
/**
|
|
974
886
|
* 获取天数差异,如何获取某个时间与另一个时间相差的天数
|
|
975
887
|
* @param timestamp1 (可选)时间戳(毫秒|秒),不区分哪个更大,默认为:Date.now()
|
|
@@ -987,11 +899,7 @@ class Utils {
|
|
|
987
899
|
timestamp2?: number,
|
|
988
900
|
type?: "年" | "月" | "天" | "时" | "分" | "秒"
|
|
989
901
|
): number;
|
|
990
|
-
getDaysDifference(
|
|
991
|
-
timestamp1 = Date.now(),
|
|
992
|
-
timestamp2 = Date.now(),
|
|
993
|
-
type = "天"
|
|
994
|
-
): number | string {
|
|
902
|
+
getDaysDifference(timestamp1 = Date.now(), timestamp2 = Date.now(), type = "天"): number | string {
|
|
995
903
|
type = type.trim();
|
|
996
904
|
if (timestamp1.toString().length === 10) {
|
|
997
905
|
timestamp1 = timestamp1 * 1000;
|
|
@@ -1023,9 +931,7 @@ class Utils {
|
|
|
1023
931
|
} else if (type === "秒") {
|
|
1024
932
|
remainderValue = oneSecond;
|
|
1025
933
|
}
|
|
1026
|
-
let diffValue = Math.round(
|
|
1027
|
-
Math.abs(((bigDate as any) - (smallDate as any)) / remainderValue)
|
|
1028
|
-
);
|
|
934
|
+
let diffValue = Math.round(Math.abs(((bigDate as any) - (smallDate as any)) / remainderValue));
|
|
1029
935
|
if (type === "auto") {
|
|
1030
936
|
let timeDifference = bigTimeStamp - smallTimeStamp;
|
|
1031
937
|
diffValue = Math.floor(timeDifference / (24 * 3600 * 1000));
|
|
@@ -1033,8 +939,7 @@ class Utils {
|
|
|
1033
939
|
(diffValue as any) = diffValue + "天";
|
|
1034
940
|
} else {
|
|
1035
941
|
/* 计算出小时数 */
|
|
1036
|
-
let leave1 =
|
|
1037
|
-
timeDifference % (24 * 3600 * 1000); /* 计算天数后剩余的毫秒数 */
|
|
942
|
+
let leave1 = timeDifference % (24 * 3600 * 1000); /* 计算天数后剩余的毫秒数 */
|
|
1038
943
|
let hours = Math.floor(leave1 / (3600 * 1000));
|
|
1039
944
|
if (hours > 0) {
|
|
1040
945
|
(diffValue as any) = hours + "小时";
|
|
@@ -1077,11 +982,8 @@ class Utils {
|
|
|
1077
982
|
}
|
|
1078
983
|
/* 如果有多个相同类型的兄弟元素,则需要添加索引 */
|
|
1079
984
|
if (element.parentElement.querySelectorAll(element.tagName).length > 1) {
|
|
1080
|
-
let index =
|
|
1081
|
-
|
|
1082
|
-
1;
|
|
1083
|
-
selector +=
|
|
1084
|
-
" > " + element.tagName.toLowerCase() + ":nth-child(" + index + ")";
|
|
985
|
+
let index = Array.prototype.indexOf.call(element.parentElement.children, element) + 1;
|
|
986
|
+
selector += " > " + element.tagName.toLowerCase() + ":nth-child(" + index + ")";
|
|
1085
987
|
} else {
|
|
1086
988
|
selector += " > " + element.tagName.toLowerCase();
|
|
1087
989
|
}
|
|
@@ -1107,10 +1009,7 @@ class Utils {
|
|
|
1107
1009
|
* Utils.getMaxValue({1:123,2:345,3:456},(key,value)=>{return parseInt(value)})
|
|
1108
1010
|
* > 456
|
|
1109
1011
|
*/
|
|
1110
|
-
getMaxValue(
|
|
1111
|
-
val: UtilsOwnObject<number>,
|
|
1112
|
-
handler: (key: any, value: any) => number
|
|
1113
|
-
): number;
|
|
1012
|
+
getMaxValue(val: UtilsOwnObject<number>, handler: (key: any, value: any) => number): number;
|
|
1114
1013
|
/**
|
|
1115
1014
|
* 获取最大值
|
|
1116
1015
|
* @example
|
|
@@ -1124,11 +1023,7 @@ class Utils {
|
|
|
1124
1023
|
return void 0 as any as number;
|
|
1125
1024
|
}
|
|
1126
1025
|
if (result.length > 1) {
|
|
1127
|
-
if (
|
|
1128
|
-
result.length === 2 &&
|
|
1129
|
-
typeof result[0] === "object" &&
|
|
1130
|
-
typeof result[1] === "function"
|
|
1131
|
-
) {
|
|
1026
|
+
if (result.length === 2 && typeof result[0] === "object" && typeof result[1] === "function") {
|
|
1132
1027
|
let data = result[0];
|
|
1133
1028
|
let handleDataFunc = result[1];
|
|
1134
1029
|
Object.keys(data).forEach((keyName) => {
|
|
@@ -1166,9 +1061,7 @@ class Utils {
|
|
|
1166
1061
|
getMaxZIndexNodeInfo(
|
|
1167
1062
|
deviation?: number,
|
|
1168
1063
|
target?: Element | ShadowRoot | Document,
|
|
1169
|
-
ignoreCallBack?: (
|
|
1170
|
-
$ele: Element | HTMLElement | ShadowRoot
|
|
1171
|
-
) => boolean | void
|
|
1064
|
+
ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void
|
|
1172
1065
|
): {
|
|
1173
1066
|
node: Element;
|
|
1174
1067
|
zIndex: number;
|
|
@@ -1176,9 +1069,7 @@ class Utils {
|
|
|
1176
1069
|
getMaxZIndexNodeInfo(
|
|
1177
1070
|
deviation = 1,
|
|
1178
1071
|
target: Element | ShadowRoot | Document = this.windowApi.document,
|
|
1179
|
-
ignoreCallBack?: (
|
|
1180
|
-
$ele: Element | HTMLElement | ShadowRoot
|
|
1181
|
-
) => boolean | void
|
|
1072
|
+
ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void
|
|
1182
1073
|
): {
|
|
1183
1074
|
node: Element;
|
|
1184
1075
|
zIndex: number;
|
|
@@ -1257,16 +1148,12 @@ class Utils {
|
|
|
1257
1148
|
getMaxZIndex(
|
|
1258
1149
|
deviation?: number,
|
|
1259
1150
|
target?: Element | DocumentOrShadowRoot | Document,
|
|
1260
|
-
ignoreCallBack?: (
|
|
1261
|
-
$ele: Element | HTMLElement | ShadowRoot
|
|
1262
|
-
) => boolean | void
|
|
1151
|
+
ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void
|
|
1263
1152
|
): number;
|
|
1264
1153
|
getMaxZIndex(
|
|
1265
1154
|
deviation = 1,
|
|
1266
1155
|
target: Element | ShadowRoot | Document = this.windowApi.document,
|
|
1267
|
-
ignoreCallBack?: (
|
|
1268
|
-
$ele: Element | HTMLElement | ShadowRoot
|
|
1269
|
-
) => boolean | void
|
|
1156
|
+
ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void
|
|
1270
1157
|
): number {
|
|
1271
1158
|
return this.getMaxZIndexNodeInfo(deviation, target, ignoreCallBack).zIndex;
|
|
1272
1159
|
}
|
|
@@ -1290,20 +1177,14 @@ class Utils {
|
|
|
1290
1177
|
* Utils.getMinValue({1:123,2:345,3:456},(key,value)=>{return parseInt(value)})
|
|
1291
1178
|
* > 123
|
|
1292
1179
|
*/
|
|
1293
|
-
getMinValue(
|
|
1294
|
-
val: UtilsOwnObject<number>,
|
|
1295
|
-
handler: (key: any, value: any) => number
|
|
1296
|
-
): number;
|
|
1180
|
+
getMinValue(val: UtilsOwnObject<number>, handler: (key: any, value: any) => number): number;
|
|
1297
1181
|
/**
|
|
1298
1182
|
* 获取最小值
|
|
1299
1183
|
* @example
|
|
1300
1184
|
* Utils.getMinValue([{1:123},{2:345},{3:456}],(index,value)=>{return parseInt(index)})
|
|
1301
1185
|
* > 0
|
|
1302
1186
|
*/
|
|
1303
|
-
getMinValue(
|
|
1304
|
-
val: UtilsOwnObject<number>[],
|
|
1305
|
-
handler: (index: number, value: any) => number
|
|
1306
|
-
): number;
|
|
1187
|
+
getMinValue(val: UtilsOwnObject<number>[], handler: (index: number, value: any) => number): number;
|
|
1307
1188
|
getMinValue(...args: any[]): number {
|
|
1308
1189
|
let result = [...args];
|
|
1309
1190
|
let newResult: number[] = [];
|
|
@@ -1311,11 +1192,7 @@ class Utils {
|
|
|
1311
1192
|
return void 0 as any as number;
|
|
1312
1193
|
}
|
|
1313
1194
|
if (result.length > 1) {
|
|
1314
|
-
if (
|
|
1315
|
-
result.length === 2 &&
|
|
1316
|
-
typeof result[0] === "object" &&
|
|
1317
|
-
typeof result[1] === "function"
|
|
1318
|
-
) {
|
|
1195
|
+
if (result.length === 2 && typeof result[0] === "object" && typeof result[1] === "function") {
|
|
1319
1196
|
let data = result[0];
|
|
1320
1197
|
let handleDataFunc = result[1];
|
|
1321
1198
|
Object.keys(data).forEach((keyName) => {
|
|
@@ -1430,23 +1307,14 @@ class Utils {
|
|
|
1430
1307
|
* Utils.getRandomValue({1:1},{2:2})
|
|
1431
1308
|
* > {1: 1}
|
|
1432
1309
|
*/
|
|
1433
|
-
getRandomValue<T extends any>(
|
|
1434
|
-
val_1: UtilsOwnObject<T>,
|
|
1435
|
-
val_2: UtilsOwnObject<T>
|
|
1436
|
-
): T;
|
|
1310
|
+
getRandomValue<T extends any>(val_1: UtilsOwnObject<T>, val_2: UtilsOwnObject<T>): T;
|
|
1437
1311
|
getRandomValue(...args: any[]): any {
|
|
1438
1312
|
let result = [...args];
|
|
1439
1313
|
if (result.length > 1) {
|
|
1440
|
-
if (
|
|
1441
|
-
result.length === 2 &&
|
|
1442
|
-
typeof result[0] === "number" &&
|
|
1443
|
-
typeof result[1] === "number"
|
|
1444
|
-
) {
|
|
1314
|
+
if (result.length === 2 && typeof result[0] === "number" && typeof result[1] === "number") {
|
|
1445
1315
|
let leftNumber = result[0] > result[1] ? result[1] : result[0];
|
|
1446
1316
|
let rightNumber = result[0] > result[1] ? result[0] : result[1];
|
|
1447
|
-
return (
|
|
1448
|
-
Math.round(Math.random() * (rightNumber - leftNumber)) + leftNumber
|
|
1449
|
-
);
|
|
1317
|
+
return Math.round(Math.random() * (rightNumber - leftNumber)) + leftNumber;
|
|
1450
1318
|
} else {
|
|
1451
1319
|
return result[Math.floor(Math.random() * result.length)];
|
|
1452
1320
|
}
|
|
@@ -1454,14 +1322,9 @@ class Utils {
|
|
|
1454
1322
|
let paramData = result[0];
|
|
1455
1323
|
if (Array.isArray(paramData)) {
|
|
1456
1324
|
return paramData[Math.floor(Math.random() * paramData.length)];
|
|
1457
|
-
} else if (
|
|
1458
|
-
typeof paramData === "object" &&
|
|
1459
|
-
Object.keys(paramData).length > 0
|
|
1460
|
-
) {
|
|
1325
|
+
} else if (typeof paramData === "object" && Object.keys(paramData).length > 0) {
|
|
1461
1326
|
let paramObjDataKey =
|
|
1462
|
-
Object.keys(paramData)[
|
|
1463
|
-
Math.floor(Math.random() * Object.keys(paramData).length)
|
|
1464
|
-
];
|
|
1327
|
+
Object.keys(paramData)[Math.floor(Math.random() * Object.keys(paramData).length)];
|
|
1465
1328
|
return paramData[paramObjDataKey];
|
|
1466
1329
|
} else {
|
|
1467
1330
|
return paramData;
|
|
@@ -1550,16 +1413,10 @@ class Utils {
|
|
|
1550
1413
|
* Utils.getTextStorageSize("测试文本");
|
|
1551
1414
|
* > '12.00B'
|
|
1552
1415
|
*/
|
|
1553
|
-
getTextStorageSize<T extends boolean>(
|
|
1554
|
-
text: string,
|
|
1555
|
-
addType?: T
|
|
1556
|
-
): T extends true ? string : number;
|
|
1416
|
+
getTextStorageSize<T extends boolean>(text: string, addType?: T): T extends true ? string : number;
|
|
1557
1417
|
getTextStorageSize(text: string, addType = true) {
|
|
1558
1418
|
let UtilsContext = this;
|
|
1559
|
-
return UtilsContext.formatByteToSize(
|
|
1560
|
-
UtilsContext.getTextLength(text),
|
|
1561
|
-
addType
|
|
1562
|
-
);
|
|
1419
|
+
return UtilsContext.formatByteToSize(UtilsContext.getTextLength(text), addType);
|
|
1563
1420
|
}
|
|
1564
1421
|
/**
|
|
1565
1422
|
* 获取迅雷协议的Url
|
|
@@ -1800,9 +1657,7 @@ class Utils {
|
|
|
1800
1657
|
*/
|
|
1801
1658
|
isNativeFunc(target: Function): boolean;
|
|
1802
1659
|
isNativeFunc(target: Function): boolean {
|
|
1803
|
-
return Boolean(
|
|
1804
|
-
target.toString().match(/^function .*\(\) { \[native code\] }$/)
|
|
1805
|
-
);
|
|
1660
|
+
return Boolean(target.toString().match(/^function .*\(\) { \[native code\] }$/));
|
|
1806
1661
|
}
|
|
1807
1662
|
/**
|
|
1808
1663
|
* 判断当前的位置是否位于页面底部附近
|
|
@@ -1824,15 +1679,12 @@ class Utils {
|
|
|
1824
1679
|
let checkWindow = () => {
|
|
1825
1680
|
// 已滚动的距离
|
|
1826
1681
|
let scrollTop: number =
|
|
1827
|
-
this.windowApi.window.pageYOffset ||
|
|
1828
|
-
this.windowApi.document.documentElement.scrollTop;
|
|
1682
|
+
this.windowApi.window.pageYOffset || this.windowApi.document.documentElement.scrollTop;
|
|
1829
1683
|
// 视窗高度
|
|
1830
1684
|
let viewportHeight: number =
|
|
1831
|
-
this.windowApi.window.innerHeight ||
|
|
1832
|
-
this.windowApi.document.documentElement.clientHeight;
|
|
1685
|
+
this.windowApi.window.innerHeight || this.windowApi.document.documentElement.clientHeight;
|
|
1833
1686
|
// 最大滚动距离
|
|
1834
|
-
let maxScrollHeight: number =
|
|
1835
|
-
this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
|
|
1687
|
+
let maxScrollHeight: number = this.windowApi.document.documentElement.scrollHeight - nearBottomHeight;
|
|
1836
1688
|
|
|
1837
1689
|
return scrollTop + viewportHeight >= maxScrollHeight;
|
|
1838
1690
|
};
|
|
@@ -1843,8 +1695,7 @@ class Utils {
|
|
|
1843
1695
|
// 视窗高度
|
|
1844
1696
|
let viewportHeight: number = $ele.clientHeight;
|
|
1845
1697
|
// 最大滚动距离
|
|
1846
|
-
let maxScrollHeight: number =
|
|
1847
|
-
$ele.scrollHeight - viewportHeight - nearBottomHeight;
|
|
1698
|
+
let maxScrollHeight: number = $ele.scrollHeight - viewportHeight - nearBottomHeight;
|
|
1848
1699
|
|
|
1849
1700
|
return scrollTop >= maxScrollHeight;
|
|
1850
1701
|
};
|
|
@@ -2159,8 +2010,7 @@ class Utils {
|
|
|
2159
2010
|
*/
|
|
2160
2011
|
isThemeDark(): boolean;
|
|
2161
2012
|
isThemeDark(): boolean {
|
|
2162
|
-
return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
|
|
2163
|
-
.matches;
|
|
2013
|
+
return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
2164
2014
|
}
|
|
2165
2015
|
/**
|
|
2166
2016
|
* 判断元素是否在页面中可见
|
|
@@ -2175,10 +2025,7 @@ class Utils {
|
|
|
2175
2025
|
* Utils.isVisible(document.documentElement)
|
|
2176
2026
|
* > true
|
|
2177
2027
|
*/
|
|
2178
|
-
isVisible(
|
|
2179
|
-
element: HTMLElement | HTMLElement[] | Element | NodeList,
|
|
2180
|
-
inView: boolean = false
|
|
2181
|
-
): boolean {
|
|
2028
|
+
isVisible(element: HTMLElement | HTMLElement[] | Element | NodeList, inView: boolean = false): boolean {
|
|
2182
2029
|
let needCheckDomList = [];
|
|
2183
2030
|
if (element instanceof Array || element instanceof NodeList) {
|
|
2184
2031
|
element = element as HTMLElement[];
|
|
@@ -2195,11 +2042,9 @@ class Utils {
|
|
|
2195
2042
|
let domClientRect = domItem.getBoundingClientRect();
|
|
2196
2043
|
if (inView) {
|
|
2197
2044
|
let viewportWidth =
|
|
2198
|
-
this.windowApi.window.innerWidth ||
|
|
2199
|
-
this.windowApi.document.documentElement.clientWidth;
|
|
2045
|
+
this.windowApi.window.innerWidth || this.windowApi.document.documentElement.clientWidth;
|
|
2200
2046
|
let viewportHeight =
|
|
2201
|
-
this.windowApi.window.innerHeight ||
|
|
2202
|
-
this.windowApi.document.documentElement.clientHeight;
|
|
2047
|
+
this.windowApi.window.innerHeight || this.windowApi.document.documentElement.clientHeight;
|
|
2203
2048
|
result = !(
|
|
2204
2049
|
domClientRect.right < 0 ||
|
|
2205
2050
|
domClientRect.left > viewportWidth ||
|
|
@@ -2235,10 +2080,7 @@ class Utils {
|
|
|
2235
2080
|
for (const key in Object.values((this.windowApi.top.window as any).via)) {
|
|
2236
2081
|
if (Reflect.has((this.windowApi.top.window as any).via, key)) {
|
|
2237
2082
|
let objValueFunc = (this.windowApi.top.window as any).via[key];
|
|
2238
|
-
if (
|
|
2239
|
-
typeof objValueFunc === "function" &&
|
|
2240
|
-
UtilsContext.isNativeFunc(objValueFunc)
|
|
2241
|
-
) {
|
|
2083
|
+
if (typeof objValueFunc === "function" && UtilsContext.isNativeFunc(objValueFunc)) {
|
|
2242
2084
|
result = true;
|
|
2243
2085
|
} else {
|
|
2244
2086
|
result = false;
|
|
@@ -2265,15 +2107,10 @@ class Utils {
|
|
|
2265
2107
|
let result = true;
|
|
2266
2108
|
let UtilsContext = this;
|
|
2267
2109
|
if (typeof (this.windowApi.top.window as any).mbrowser === "object") {
|
|
2268
|
-
for (const key in Object.values(
|
|
2269
|
-
(this.windowApi.top.window as any).mbrowser
|
|
2270
|
-
)) {
|
|
2110
|
+
for (const key in Object.values((this.windowApi.top.window as any).mbrowser)) {
|
|
2271
2111
|
if (Reflect.has((this.windowApi.top.window as any).mbrowser, key)) {
|
|
2272
2112
|
let objValueFunc = (this.windowApi.top.window as any).mbrowser[key];
|
|
2273
|
-
if (
|
|
2274
|
-
typeof objValueFunc === "function" &&
|
|
2275
|
-
UtilsContext.isNativeFunc(objValueFunc)
|
|
2276
|
-
) {
|
|
2113
|
+
if (typeof objValueFunc === "function" && UtilsContext.isNativeFunc(objValueFunc)) {
|
|
2277
2114
|
result = true;
|
|
2278
2115
|
} else {
|
|
2279
2116
|
result = false;
|
|
@@ -2297,9 +2134,7 @@ class Utils {
|
|
|
2297
2134
|
parseObjectToArray<T extends any>(target: T): T[keyof T][];
|
|
2298
2135
|
parseObjectToArray<T extends any>(target: T) {
|
|
2299
2136
|
if (typeof target !== "object") {
|
|
2300
|
-
throw new Error(
|
|
2301
|
-
"Utils.parseObjectToArray 参数 target 必须为 object 类型"
|
|
2302
|
-
);
|
|
2137
|
+
throw new Error("Utils.parseObjectToArray 参数 target 必须为 object 类型");
|
|
2303
2138
|
}
|
|
2304
2139
|
let result: T[keyof T][] = [];
|
|
2305
2140
|
Object.keys(target!).forEach(function (keyName) {
|
|
@@ -2357,14 +2192,8 @@ class Utils {
|
|
|
2357
2192
|
* Utils.mergeArrayToString([{"name":"数组内数据部分字段合并成字符串->"},{"name":"mergeToString"}],(item)=>{return item["name"]});
|
|
2358
2193
|
* > '数组内数据部分字段合并成字符串->mergeToString'
|
|
2359
2194
|
**/
|
|
2360
|
-
mergeArrayToString<T extends any>(
|
|
2361
|
-
|
|
2362
|
-
handleFunc?: ((val: T) => T) | keyof T
|
|
2363
|
-
): string;
|
|
2364
|
-
mergeArrayToString<T extends any>(
|
|
2365
|
-
data: T[],
|
|
2366
|
-
handleFunc?: ((val: T) => T) | keyof T
|
|
2367
|
-
): string {
|
|
2195
|
+
mergeArrayToString<T extends any>(data: T[], handleFunc?: ((val: T) => T) | keyof T): string;
|
|
2196
|
+
mergeArrayToString<T extends any>(data: T[], handleFunc?: ((val: T) => T) | keyof T): string {
|
|
2368
2197
|
if (!(data instanceof Array)) {
|
|
2369
2198
|
throw new Error("Utils.mergeArrayToString 参数 data 必须为 Array 类型");
|
|
2370
2199
|
}
|
|
@@ -2485,10 +2314,7 @@ class Utils {
|
|
|
2485
2314
|
},
|
|
2486
2315
|
immediate: false,
|
|
2487
2316
|
};
|
|
2488
|
-
observer_config = UtilsContext.assign(
|
|
2489
|
-
default_obverser_config,
|
|
2490
|
-
observer_config
|
|
2491
|
-
);
|
|
2317
|
+
observer_config = UtilsContext.assign(default_obverser_config, observer_config);
|
|
2492
2318
|
let windowMutationObserver =
|
|
2493
2319
|
this.windowApi.window.MutationObserver ||
|
|
2494
2320
|
(this.windowApi.window as any).webkitMutationObserver ||
|
|
@@ -2536,10 +2362,7 @@ class Utils {
|
|
|
2536
2362
|
*/
|
|
2537
2363
|
mutationVisible(
|
|
2538
2364
|
target: Element | Element[],
|
|
2539
|
-
callback: (
|
|
2540
|
-
entries: IntersectionObserverEntry[],
|
|
2541
|
-
observer: IntersectionObserver
|
|
2542
|
-
) => void,
|
|
2365
|
+
callback: (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void,
|
|
2543
2366
|
options?: IntersectionObserverInit
|
|
2544
2367
|
) {
|
|
2545
2368
|
if (typeof IntersectionObserver === "undefined") {
|
|
@@ -2628,34 +2451,24 @@ class Utils {
|
|
|
2628
2451
|
): void {
|
|
2629
2452
|
let UtilsContext = this;
|
|
2630
2453
|
if (typeof needReleaseObject !== "object") {
|
|
2631
|
-
throw new Error(
|
|
2632
|
-
"Utils.noConflictFunc 参数 needReleaseObject 必须为 object 类型"
|
|
2633
|
-
);
|
|
2454
|
+
throw new Error("Utils.noConflictFunc 参数 needReleaseObject 必须为 object 类型");
|
|
2634
2455
|
}
|
|
2635
2456
|
if (typeof needReleaseName !== "string") {
|
|
2636
|
-
throw new Error(
|
|
2637
|
-
"Utils.noConflictFunc 参数 needReleaseName 必须为 string 类型"
|
|
2638
|
-
);
|
|
2457
|
+
throw new Error("Utils.noConflictFunc 参数 needReleaseName 必须为 string 类型");
|
|
2639
2458
|
}
|
|
2640
2459
|
if (!Array.isArray(functionNameList)) {
|
|
2641
|
-
throw new Error(
|
|
2642
|
-
"Utils.noConflictFunc 参数 functionNameList 必须为 Array 类型"
|
|
2643
|
-
);
|
|
2460
|
+
throw new Error("Utils.noConflictFunc 参数 functionNameList 必须为 Array 类型");
|
|
2644
2461
|
}
|
|
2645
2462
|
let needReleaseKey = "__" + needReleaseName;
|
|
2646
2463
|
/**
|
|
2647
2464
|
* 释放所有
|
|
2648
2465
|
*/
|
|
2649
2466
|
function releaseAll() {
|
|
2650
|
-
if (
|
|
2651
|
-
typeof (UtilsContext.windowApi.window as any)[needReleaseKey] !==
|
|
2652
|
-
"undefined"
|
|
2653
|
-
) {
|
|
2467
|
+
if (typeof (UtilsContext.windowApi.window as any)[needReleaseKey] !== "undefined") {
|
|
2654
2468
|
/* 已存在 */
|
|
2655
2469
|
return;
|
|
2656
2470
|
}
|
|
2657
|
-
(UtilsContext.windowApi.window as any)[needReleaseKey] =
|
|
2658
|
-
UtilsContext.deepClone(needReleaseObject);
|
|
2471
|
+
(UtilsContext.windowApi.window as any)[needReleaseKey] = UtilsContext.deepClone(needReleaseObject);
|
|
2659
2472
|
Object.values(needReleaseObject).forEach((value) => {
|
|
2660
2473
|
if (typeof value === "function") {
|
|
2661
2474
|
(needReleaseObject as any)[value.name] = () => {};
|
|
@@ -2669,16 +2482,13 @@ class Utils {
|
|
|
2669
2482
|
Array.from(functionNameList).forEach((item) => {
|
|
2670
2483
|
Object.values(needReleaseObject).forEach((value) => {
|
|
2671
2484
|
if (typeof value === "function") {
|
|
2672
|
-
if (
|
|
2673
|
-
typeof (UtilsContext.windowApi.window as any)[needReleaseKey] ===
|
|
2674
|
-
"undefined"
|
|
2675
|
-
) {
|
|
2485
|
+
if (typeof (UtilsContext.windowApi.window as any)[needReleaseKey] === "undefined") {
|
|
2676
2486
|
(UtilsContext.windowApi.window as any)[needReleaseKey] = {};
|
|
2677
2487
|
}
|
|
2678
2488
|
if (item === value.name) {
|
|
2679
|
-
(UtilsContext.windowApi.window as any)[needReleaseKey][
|
|
2489
|
+
(UtilsContext.windowApi.window as any)[needReleaseKey][value.name] = (needReleaseObject as any)[
|
|
2680
2490
|
value.name
|
|
2681
|
-
]
|
|
2491
|
+
];
|
|
2682
2492
|
(needReleaseObject as any)[value.name] = () => {};
|
|
2683
2493
|
}
|
|
2684
2494
|
}
|
|
@@ -2689,47 +2499,27 @@ class Utils {
|
|
|
2689
2499
|
* 恢复所有
|
|
2690
2500
|
*/
|
|
2691
2501
|
function recoveryAll() {
|
|
2692
|
-
if (
|
|
2693
|
-
typeof (UtilsContext.windowApi.window as any)[needReleaseKey] ===
|
|
2694
|
-
"undefined"
|
|
2695
|
-
) {
|
|
2502
|
+
if (typeof (UtilsContext.windowApi.window as any)[needReleaseKey] === "undefined") {
|
|
2696
2503
|
/* 未存在 */
|
|
2697
2504
|
return;
|
|
2698
2505
|
}
|
|
2699
|
-
Object.assign(
|
|
2700
|
-
|
|
2701
|
-
(UtilsContext.windowApi.window as any)[needReleaseKey]
|
|
2702
|
-
);
|
|
2703
|
-
Reflect.deleteProperty(
|
|
2704
|
-
UtilsContext.windowApi.window as any,
|
|
2705
|
-
"needReleaseKey"
|
|
2706
|
-
);
|
|
2506
|
+
Object.assign(needReleaseObject, (UtilsContext.windowApi.window as any)[needReleaseKey]);
|
|
2507
|
+
Reflect.deleteProperty(UtilsContext.windowApi.window as any, "needReleaseKey");
|
|
2707
2508
|
}
|
|
2708
2509
|
|
|
2709
2510
|
/**
|
|
2710
2511
|
* 恢复单个
|
|
2711
2512
|
*/
|
|
2712
2513
|
function recoveryOne() {
|
|
2713
|
-
if (
|
|
2714
|
-
typeof (UtilsContext.windowApi.window as any)[needReleaseKey] ===
|
|
2715
|
-
"undefined"
|
|
2716
|
-
) {
|
|
2514
|
+
if (typeof (UtilsContext.windowApi.window as any)[needReleaseKey] === "undefined") {
|
|
2717
2515
|
/* 未存在 */
|
|
2718
2516
|
return;
|
|
2719
2517
|
}
|
|
2720
2518
|
Array.from(functionNameList).forEach((item) => {
|
|
2721
2519
|
if ((UtilsContext.windowApi.window as any)[needReleaseKey][item]) {
|
|
2722
|
-
(needReleaseObject as any)[item] = (
|
|
2723
|
-
|
|
2724
|
-
)[needReleaseKey]
|
|
2725
|
-
Reflect.deleteProperty(
|
|
2726
|
-
(UtilsContext.windowApi.window as any)[needReleaseKey],
|
|
2727
|
-
item
|
|
2728
|
-
);
|
|
2729
|
-
if (
|
|
2730
|
-
Object.keys((UtilsContext.windowApi.window as any)[needReleaseKey])
|
|
2731
|
-
.length === 0
|
|
2732
|
-
) {
|
|
2520
|
+
(needReleaseObject as any)[item] = (UtilsContext.windowApi.window as any)[needReleaseKey][item];
|
|
2521
|
+
Reflect.deleteProperty((UtilsContext.windowApi.window as any)[needReleaseKey], item);
|
|
2522
|
+
if (Object.keys((UtilsContext.windowApi.window as any)[needReleaseKey]).length === 0) {
|
|
2733
2523
|
Reflect.deleteProperty(window, needReleaseKey);
|
|
2734
2524
|
}
|
|
2735
2525
|
}
|
|
@@ -2764,9 +2554,7 @@ class Utils {
|
|
|
2764
2554
|
parseBase64ToBlob(dataUri: string): Blob;
|
|
2765
2555
|
parseBase64ToBlob(dataUri: string): Blob {
|
|
2766
2556
|
if (typeof dataUri !== "string") {
|
|
2767
|
-
throw new Error(
|
|
2768
|
-
"Utils.parseBase64ToBlob 参数 dataUri 必须为 string 类型"
|
|
2769
|
-
);
|
|
2557
|
+
throw new Error("Utils.parseBase64ToBlob 参数 dataUri 必须为 string 类型");
|
|
2770
2558
|
}
|
|
2771
2559
|
let dataUriSplit = dataUri.split(","),
|
|
2772
2560
|
dataUriMime = (dataUriSplit[0] as any).match(/:(.*?);/)[1],
|
|
@@ -2792,14 +2580,10 @@ class Utils {
|
|
|
2792
2580
|
parseBase64ToFile(dataUri: string, fileName?: string): File;
|
|
2793
2581
|
parseBase64ToFile(dataUri: string, fileName = "example") {
|
|
2794
2582
|
if (typeof dataUri !== "string") {
|
|
2795
|
-
throw new Error(
|
|
2796
|
-
"Utils.parseBase64ToFile 参数 dataUri 必须为 string 类型"
|
|
2797
|
-
);
|
|
2583
|
+
throw new Error("Utils.parseBase64ToFile 参数 dataUri 必须为 string 类型");
|
|
2798
2584
|
}
|
|
2799
2585
|
if (typeof fileName !== "string") {
|
|
2800
|
-
throw new Error(
|
|
2801
|
-
"Utils.parseBase64ToFile 参数 fileName 必须为 string 类型"
|
|
2802
|
-
);
|
|
2586
|
+
throw new Error("Utils.parseBase64ToFile 参数 fileName 必须为 string 类型");
|
|
2803
2587
|
}
|
|
2804
2588
|
let dataUriSplit = dataUri.split(","),
|
|
2805
2589
|
dataUriMime = (dataUriSplit[0] as any).match(/:(.*?);/)[1],
|
|
@@ -2836,10 +2620,7 @@ class Utils {
|
|
|
2836
2620
|
* Utils.parseInt(["aaaaaaa"],"aa");
|
|
2837
2621
|
* > NaN
|
|
2838
2622
|
**/
|
|
2839
|
-
parseInt(
|
|
2840
|
-
matchList?: any[] | null | undefined | RegExpMatchArray,
|
|
2841
|
-
defaultValue?: number
|
|
2842
|
-
): number;
|
|
2623
|
+
parseInt(matchList?: any[] | null | undefined | RegExpMatchArray, defaultValue?: number): number;
|
|
2843
2624
|
parseInt(matchList: any[] = [], defaultValue = 0): number {
|
|
2844
2625
|
if (matchList == null) {
|
|
2845
2626
|
return parseInt(defaultValue.toString());
|
|
@@ -2859,10 +2640,7 @@ class Utils {
|
|
|
2859
2640
|
* > object
|
|
2860
2641
|
**/
|
|
2861
2642
|
parseBlobToFile(blobUrl: string, fileName?: string): Promise<File | Error>;
|
|
2862
|
-
async parseBlobToFile(
|
|
2863
|
-
blobUrl: string,
|
|
2864
|
-
fileName: string = "example"
|
|
2865
|
-
): Promise<File | Error> {
|
|
2643
|
+
async parseBlobToFile(blobUrl: string, fileName: string = "example"): Promise<File | Error> {
|
|
2866
2644
|
return new Promise((resolve, reject) => {
|
|
2867
2645
|
fetch(blobUrl)
|
|
2868
2646
|
.then((response) => response.blob())
|
|
@@ -2927,12 +2705,7 @@ class Utils {
|
|
|
2927
2705
|
*/
|
|
2928
2706
|
parseFromString(
|
|
2929
2707
|
text: string,
|
|
2930
|
-
mimeType?:
|
|
2931
|
-
| "text/html"
|
|
2932
|
-
| "text/xml"
|
|
2933
|
-
| "application/xml"
|
|
2934
|
-
| "application/xhtml+xml"
|
|
2935
|
-
| "image/svg+xml"
|
|
2708
|
+
mimeType?: "text/html" | "text/xml" | "application/xml" | "application/xhtml+xml" | "image/svg+xml"
|
|
2936
2709
|
): HTMLElement | XMLDocument | SVGElement;
|
|
2937
2710
|
parseFromString(
|
|
2938
2711
|
text: string,
|
|
@@ -2980,11 +2753,7 @@ class Utils {
|
|
|
2980
2753
|
* @example
|
|
2981
2754
|
* Utils.preventEvent(event);
|
|
2982
2755
|
*/
|
|
2983
|
-
preventEvent(
|
|
2984
|
-
element: HTMLElement,
|
|
2985
|
-
eventNameList?: string | string[],
|
|
2986
|
-
capture?: boolean
|
|
2987
|
-
): boolean;
|
|
2756
|
+
preventEvent(element: HTMLElement, eventNameList?: string | string[], capture?: boolean): boolean;
|
|
2988
2757
|
preventEvent(
|
|
2989
2758
|
element: HTMLElement | Event,
|
|
2990
2759
|
eventNameList: string | string[] = [],
|
|
@@ -3028,14 +2797,8 @@ class Utils {
|
|
|
3028
2797
|
* @example
|
|
3029
2798
|
* Utils.registerTrustClickEvent()
|
|
3030
2799
|
*/
|
|
3031
|
-
registerTrustClickEvent(
|
|
3032
|
-
|
|
3033
|
-
filter?: (typeName: string) => boolean
|
|
3034
|
-
): void;
|
|
3035
|
-
registerTrustClickEvent(
|
|
3036
|
-
isTrustValue: boolean = true,
|
|
3037
|
-
filter?: (typeName: string) => boolean
|
|
3038
|
-
): void {
|
|
2800
|
+
registerTrustClickEvent(isTrustValue?: boolean, filter?: (typeName: string) => boolean): void;
|
|
2801
|
+
registerTrustClickEvent(isTrustValue: boolean = true, filter?: (typeName: string) => boolean): void {
|
|
3039
2802
|
function trustEvent(event: Event) {
|
|
3040
2803
|
return new Proxy(event, {
|
|
3041
2804
|
get: function (target, property) {
|
|
@@ -3219,10 +2982,7 @@ class Utils {
|
|
|
3219
2982
|
let copyStatus = false;
|
|
3220
2983
|
let requestPermissionStatus = await this.requestClipboardPermission();
|
|
3221
2984
|
console.log(requestPermissionStatus);
|
|
3222
|
-
if (
|
|
3223
|
-
this.hasClipboard() &&
|
|
3224
|
-
(this.hasClipboardWrite() || this.hasClipboardWriteText())
|
|
3225
|
-
) {
|
|
2985
|
+
if (this.hasClipboard() && (this.hasClipboardWrite() || this.hasClipboardWriteText())) {
|
|
3226
2986
|
try {
|
|
3227
2987
|
copyStatus = await this.copyDataByClipboard();
|
|
3228
2988
|
} catch (error) {
|
|
@@ -3257,8 +3017,7 @@ class Utils {
|
|
|
3257
3017
|
*/
|
|
3258
3018
|
copyTextByTextArea() {
|
|
3259
3019
|
try {
|
|
3260
|
-
let copyElement =
|
|
3261
|
-
UtilsContext.windowApi.document.createElement("textarea");
|
|
3020
|
+
let copyElement = UtilsContext.windowApi.document.createElement("textarea");
|
|
3262
3021
|
copyElement.value = this.#copyData;
|
|
3263
3022
|
copyElement.setAttribute("type", "text");
|
|
3264
3023
|
copyElement.setAttribute("style", "opacity:0;position:absolute;");
|
|
@@ -3361,15 +3120,10 @@ class Utils {
|
|
|
3361
3120
|
* > ƒ tryCatchObj() {}
|
|
3362
3121
|
**/
|
|
3363
3122
|
setTimeout(callback: (() => void) | string, delayTime?: number): Promise<any>;
|
|
3364
|
-
setTimeout(
|
|
3365
|
-
callback: (() => void) | string,
|
|
3366
|
-
delayTime: number = 0
|
|
3367
|
-
): Promise<any> {
|
|
3123
|
+
setTimeout(callback: (() => void) | string, delayTime: number = 0): Promise<any> {
|
|
3368
3124
|
let UtilsContext = this;
|
|
3369
3125
|
if (typeof callback !== "function" && typeof callback !== "string") {
|
|
3370
|
-
throw new TypeError(
|
|
3371
|
-
"Utils.setTimeout 参数 callback 必须为 function|string 类型"
|
|
3372
|
-
);
|
|
3126
|
+
throw new TypeError("Utils.setTimeout 参数 callback 必须为 function|string 类型");
|
|
3373
3127
|
}
|
|
3374
3128
|
if (typeof delayTime !== "number") {
|
|
3375
3129
|
throw new TypeError("Utils.setTimeout 参数 delayTime 必须为 number 类型");
|
|
@@ -3408,19 +3162,11 @@ class Utils {
|
|
|
3408
3162
|
* Utils.dragSlider("#xxxx",100);
|
|
3409
3163
|
*/
|
|
3410
3164
|
dragSlider(selector: string | Element | Node, offsetX?: number): void;
|
|
3411
|
-
dragSlider(
|
|
3412
|
-
selector: string | Element | Node,
|
|
3413
|
-
offsetX: number = this.windowApi.window.innerWidth
|
|
3414
|
-
): void {
|
|
3165
|
+
dragSlider(selector: string | Element | Node, offsetX: number = this.windowApi.window.innerWidth): void {
|
|
3415
3166
|
let UtilsContext = this;
|
|
3416
|
-
function initMouseEvent(
|
|
3417
|
-
eventName: string,
|
|
3418
|
-
offSetX: number,
|
|
3419
|
-
offSetY: number
|
|
3420
|
-
) {
|
|
3167
|
+
function initMouseEvent(eventName: string, offSetX: number, offSetY: number) {
|
|
3421
3168
|
let win = typeof unsafeWindow === "undefined" ? globalThis : unsafeWindow;
|
|
3422
|
-
let mouseEvent =
|
|
3423
|
-
UtilsContext.windowApi.document.createEvent("MouseEvents");
|
|
3169
|
+
let mouseEvent = UtilsContext.windowApi.document.createEvent("MouseEvents");
|
|
3424
3170
|
mouseEvent.initMouseEvent(
|
|
3425
3171
|
eventName,
|
|
3426
3172
|
true,
|
|
@@ -3440,14 +3186,8 @@ class Utils {
|
|
|
3440
3186
|
);
|
|
3441
3187
|
return mouseEvent;
|
|
3442
3188
|
}
|
|
3443
|
-
let sliderElement =
|
|
3444
|
-
|
|
3445
|
-
? domUtils.selector<HTMLElement>(selector)
|
|
3446
|
-
: selector;
|
|
3447
|
-
if (
|
|
3448
|
-
!(sliderElement instanceof Node) ||
|
|
3449
|
-
!(sliderElement instanceof Element)
|
|
3450
|
-
) {
|
|
3189
|
+
let sliderElement = typeof selector === "string" ? domUtils.selector<HTMLElement>(selector) : selector;
|
|
3190
|
+
if (!(sliderElement instanceof Node) || !(sliderElement instanceof Element)) {
|
|
3451
3191
|
throw new Error("Utils.dragSlider 参数selector 必须为Node/Element类型");
|
|
3452
3192
|
}
|
|
3453
3193
|
let rect = sliderElement.getBoundingClientRect(),
|
|
@@ -3495,9 +3235,7 @@ class Utils {
|
|
|
3495
3235
|
* Utils.exitFullScreen();
|
|
3496
3236
|
*/
|
|
3497
3237
|
exitFullScreen(element?: HTMLElement): Promise<void>;
|
|
3498
|
-
exitFullScreen(
|
|
3499
|
-
element: HTMLElement = this.windowApi.document.documentElement
|
|
3500
|
-
): Promise<void> {
|
|
3238
|
+
exitFullScreen(element: HTMLElement = this.windowApi.document.documentElement): Promise<void> {
|
|
3501
3239
|
if (this.windowApi.document.exitFullscreen) {
|
|
3502
3240
|
return this.windowApi.document.exitFullscreen();
|
|
3503
3241
|
} else if ((this.windowApi.document as any).msExitFullscreen) {
|
|
@@ -3538,23 +3276,14 @@ class Utils {
|
|
|
3538
3276
|
sortByDesc: boolean = true
|
|
3539
3277
|
): T[] {
|
|
3540
3278
|
let UtilsContext = this;
|
|
3541
|
-
if (
|
|
3542
|
-
|
|
3543
|
-
typeof getPropertyValueFunc !== "string"
|
|
3544
|
-
) {
|
|
3545
|
-
throw new Error(
|
|
3546
|
-
"Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型"
|
|
3547
|
-
);
|
|
3279
|
+
if (typeof getPropertyValueFunc !== "function" && typeof getPropertyValueFunc !== "string") {
|
|
3280
|
+
throw new Error("Utils.sortListByProperty 参数 getPropertyValueFunc 必须为 function|string 类型");
|
|
3548
3281
|
}
|
|
3549
3282
|
if (typeof sortByDesc !== "boolean") {
|
|
3550
|
-
throw new Error(
|
|
3551
|
-
"Utils.sortListByProperty 参数 sortByDesc 必须为 boolean 类型"
|
|
3552
|
-
);
|
|
3283
|
+
throw new Error("Utils.sortListByProperty 参数 sortByDesc 必须为 boolean 类型");
|
|
3553
3284
|
}
|
|
3554
3285
|
let getObjValue = function (obj: any) {
|
|
3555
|
-
return typeof getPropertyValueFunc === "string"
|
|
3556
|
-
? obj[getPropertyValueFunc]
|
|
3557
|
-
: getPropertyValueFunc(obj);
|
|
3286
|
+
return typeof getPropertyValueFunc === "string" ? obj[getPropertyValueFunc] : getPropertyValueFunc(obj);
|
|
3558
3287
|
};
|
|
3559
3288
|
/**
|
|
3560
3289
|
* 排序方法
|
|
@@ -3627,16 +3356,11 @@ class Utils {
|
|
|
3627
3356
|
}
|
|
3628
3357
|
if (Array.isArray(data)) {
|
|
3629
3358
|
data.sort(sortFunc);
|
|
3630
|
-
} else if (
|
|
3631
|
-
(data as any) instanceof NodeList ||
|
|
3632
|
-
UtilsContext.isJQuery(data)
|
|
3633
|
-
) {
|
|
3359
|
+
} else if ((data as any) instanceof NodeList || UtilsContext.isJQuery(data)) {
|
|
3634
3360
|
sortNodeFunc(data as any, getDataFunc as any);
|
|
3635
3361
|
result = (getDataFunc as any)();
|
|
3636
3362
|
} else {
|
|
3637
|
-
throw new Error(
|
|
3638
|
-
"Utils.sortListByProperty 参数 data 必须为 Array|NodeList|jQuery 类型"
|
|
3639
|
-
);
|
|
3363
|
+
throw new Error("Utils.sortListByProperty 参数 data 必须为 Array|NodeList|jQuery 类型");
|
|
3640
3364
|
}
|
|
3641
3365
|
return result;
|
|
3642
3366
|
}
|
|
@@ -3645,27 +3369,16 @@ class Utils {
|
|
|
3645
3369
|
* @param targetString 需要进行转换的字符串
|
|
3646
3370
|
* @param flags 正则标志
|
|
3647
3371
|
*/
|
|
3648
|
-
stringToRegular(
|
|
3649
|
-
|
|
3650
|
-
flags?: "g" | "i" | "m" | "u" | "y" | string
|
|
3651
|
-
): RegExp;
|
|
3652
|
-
stringToRegular(
|
|
3653
|
-
targetString: string | RegExp,
|
|
3654
|
-
flags: "g" | "i" | "m" | "u" | "y" | string = "ig"
|
|
3655
|
-
): RegExp {
|
|
3372
|
+
stringToRegular(targetString: string | RegExp, flags?: "g" | "i" | "m" | "u" | "y" | string): RegExp;
|
|
3373
|
+
stringToRegular(targetString: string | RegExp, flags: "g" | "i" | "m" | "u" | "y" | string = "ig"): RegExp {
|
|
3656
3374
|
let reg;
|
|
3657
3375
|
flags = flags.toLowerCase();
|
|
3658
3376
|
if (typeof targetString === "string") {
|
|
3659
|
-
reg = new RegExp(
|
|
3660
|
-
targetString.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"),
|
|
3661
|
-
flags
|
|
3662
|
-
);
|
|
3377
|
+
reg = new RegExp(targetString.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&"), flags);
|
|
3663
3378
|
} else if ((targetString as any) instanceof RegExp) {
|
|
3664
3379
|
reg = targetString;
|
|
3665
3380
|
} else {
|
|
3666
|
-
throw new Error(
|
|
3667
|
-
"Utils.stringToRegular 参数targetString必须是string|Regexp类型"
|
|
3668
|
-
);
|
|
3381
|
+
throw new Error("Utils.stringToRegular 参数targetString必须是string|Regexp类型");
|
|
3669
3382
|
}
|
|
3670
3383
|
return reg;
|
|
3671
3384
|
}
|
|
@@ -3674,14 +3387,8 @@ class Utils {
|
|
|
3674
3387
|
* @param targetString 目标字符串
|
|
3675
3388
|
* @param otherStrToLowerCase (可选)剩余部分字符串转小写,默认false
|
|
3676
3389
|
*/
|
|
3677
|
-
stringTitleToUpperCase(
|
|
3678
|
-
|
|
3679
|
-
otherStrToLowerCase?: boolean
|
|
3680
|
-
): string;
|
|
3681
|
-
stringTitleToUpperCase(
|
|
3682
|
-
targetString: string,
|
|
3683
|
-
otherStrToLowerCase: boolean = false
|
|
3684
|
-
): string {
|
|
3390
|
+
stringTitleToUpperCase(targetString: string, otherStrToLowerCase?: boolean): string;
|
|
3391
|
+
stringTitleToUpperCase(targetString: string, otherStrToLowerCase: boolean = false): string {
|
|
3685
3392
|
let newTargetString = targetString.slice(0, 1).toUpperCase();
|
|
3686
3393
|
if (otherStrToLowerCase) {
|
|
3687
3394
|
newTargetString = newTargetString + targetString.slice(1).toLowerCase();
|
|
@@ -3698,16 +3405,8 @@ class Utils {
|
|
|
3698
3405
|
* @param searchString 需要搜索的字符串
|
|
3699
3406
|
* @param position (可选)目标字符串的判断起点,要求≥0,默认为0
|
|
3700
3407
|
*/
|
|
3701
|
-
startsWith(
|
|
3702
|
-
|
|
3703
|
-
searchString: string | RegExp | string[],
|
|
3704
|
-
position?: number
|
|
3705
|
-
): boolean;
|
|
3706
|
-
startsWith(
|
|
3707
|
-
target: string,
|
|
3708
|
-
searchString: string | RegExp | string[],
|
|
3709
|
-
position: number = 0
|
|
3710
|
-
): boolean {
|
|
3408
|
+
startsWith(target: string, searchString: string | RegExp | string[], position?: number): boolean;
|
|
3409
|
+
startsWith(target: string, searchString: string | RegExp | string[], position: number = 0): boolean {
|
|
3711
3410
|
let UtilsContext = this;
|
|
3712
3411
|
if (position > target.length) {
|
|
3713
3412
|
/* 超出目标字符串的长度 */
|
|
@@ -3736,14 +3435,8 @@ class Utils {
|
|
|
3736
3435
|
* @param targetString 目标字符串
|
|
3737
3436
|
* @param otherStrToLowerCase (可选)剩余部分字符串转大写,默认false
|
|
3738
3437
|
*/
|
|
3739
|
-
stringTitleToLowerCase(
|
|
3740
|
-
|
|
3741
|
-
otherStrToUpperCase?: boolean
|
|
3742
|
-
): string;
|
|
3743
|
-
stringTitleToLowerCase(
|
|
3744
|
-
targetString: string,
|
|
3745
|
-
otherStrToUpperCase: boolean = false
|
|
3746
|
-
): string {
|
|
3438
|
+
stringTitleToLowerCase(targetString: string, otherStrToUpperCase?: boolean): string;
|
|
3439
|
+
stringTitleToLowerCase(targetString: string, otherStrToUpperCase: boolean = false): string {
|
|
3747
3440
|
let newTargetString = targetString.slice(0, 1).toLowerCase();
|
|
3748
3441
|
if (otherStrToUpperCase) {
|
|
3749
3442
|
newTargetString = newTargetString + targetString.slice(1).toUpperCase();
|
|
@@ -3805,15 +3498,11 @@ class Utils {
|
|
|
3805
3498
|
/**
|
|
3806
3499
|
* 将UrlSearchParams格式的字符串转为对象
|
|
3807
3500
|
*/
|
|
3808
|
-
searchParamStrToObj<T extends any>(
|
|
3809
|
-
searhParamsStr?: string | null | undefined
|
|
3810
|
-
): T {
|
|
3501
|
+
searchParamStrToObj<T extends any>(searhParamsStr?: string | null | undefined): T {
|
|
3811
3502
|
if (typeof searhParamsStr !== "string") {
|
|
3812
3503
|
return {} as any as T;
|
|
3813
3504
|
}
|
|
3814
|
-
return Object.fromEntries(
|
|
3815
|
-
new URLSearchParams(searhParamsStr) as any
|
|
3816
|
-
) as any;
|
|
3505
|
+
return Object.fromEntries(new URLSearchParams(searhParamsStr) as any) as any;
|
|
3817
3506
|
}
|
|
3818
3507
|
/**
|
|
3819
3508
|
* 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
@@ -3856,10 +3545,7 @@ class Utils {
|
|
|
3856
3545
|
* Utils.uniqueArray([{name:"1",host:"baidu.com"},{name:"2",host:"baidu.com"},{name:"3",host:"baidu.com"}]);
|
|
3857
3546
|
* > [{name:"1",host:"baidu.com"}]
|
|
3858
3547
|
*/
|
|
3859
|
-
uniqueArray<T>(
|
|
3860
|
-
uniqueArrayData: T[],
|
|
3861
|
-
getIdentfierValue: (itemValue: T) => any
|
|
3862
|
-
): T[];
|
|
3548
|
+
uniqueArray<T>(uniqueArrayData: T[], getIdentfierValue: (itemValue: T) => any): T[];
|
|
3863
3549
|
uniqueArray<T, T2>(
|
|
3864
3550
|
uniqueArrayData: T[] = [],
|
|
3865
3551
|
compareArrayData: any,
|
|
@@ -3898,19 +3584,11 @@ class Utils {
|
|
|
3898
3584
|
* @example
|
|
3899
3585
|
* await Utils.waitArrayLoopToEnd([callback,callback,callback],xxxcallback);
|
|
3900
3586
|
**/
|
|
3901
|
-
waitArrayLoopToEnd(
|
|
3902
|
-
|
|
3903
|
-
handleFunc: Function
|
|
3904
|
-
): Promise<void[]>;
|
|
3905
|
-
waitArrayLoopToEnd(
|
|
3906
|
-
data: any[] | HTMLElement[],
|
|
3907
|
-
handleFunc: Function
|
|
3908
|
-
): Promise<void[]> {
|
|
3587
|
+
waitArrayLoopToEnd(data: any[] | HTMLElement[], handleFunc: Function): Promise<void[]>;
|
|
3588
|
+
waitArrayLoopToEnd(data: any[] | HTMLElement[], handleFunc: Function): Promise<void[]> {
|
|
3909
3589
|
let UtilsContext = this;
|
|
3910
3590
|
if (typeof handleFunc !== "function" && typeof handleFunc !== "string") {
|
|
3911
|
-
throw new Error(
|
|
3912
|
-
"Utils.waitArrayLoopToEnd 参数 handleDataFunction 必须为 function|string 类型"
|
|
3913
|
-
);
|
|
3591
|
+
throw new Error("Utils.waitArrayLoopToEnd 参数 handleDataFunction 必须为 function|string 类型");
|
|
3914
3592
|
}
|
|
3915
3593
|
return Promise.all(
|
|
3916
3594
|
Array.from(data).map(async (item, index) => {
|
|
@@ -3979,27 +3657,24 @@ class Utils {
|
|
|
3979
3657
|
const UtilsContext = this;
|
|
3980
3658
|
let __timeout__ = typeof timeout === "number" ? timeout : 0;
|
|
3981
3659
|
return new Promise((resolve) => {
|
|
3982
|
-
let observer = UtilsContext.mutationObserver(
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
if (
|
|
3994
|
-
|
|
3995
|
-
if (typeof __observer__?.disconnect === "function") {
|
|
3996
|
-
__observer__.disconnect();
|
|
3997
|
-
}
|
|
3998
|
-
resolve(result.data);
|
|
3660
|
+
let observer = UtilsContext.mutationObserver(parent || UtilsContext.windowApi.document, {
|
|
3661
|
+
config: {
|
|
3662
|
+
subtree: true,
|
|
3663
|
+
childList: true,
|
|
3664
|
+
attributes: true,
|
|
3665
|
+
},
|
|
3666
|
+
immediate: true,
|
|
3667
|
+
callback(mutations, __observer__) {
|
|
3668
|
+
let result = checkFn();
|
|
3669
|
+
if (result.success) {
|
|
3670
|
+
// 取消观察器
|
|
3671
|
+
if (typeof __observer__?.disconnect === "function") {
|
|
3672
|
+
__observer__.disconnect();
|
|
3999
3673
|
}
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
3674
|
+
resolve(result.data);
|
|
3675
|
+
}
|
|
3676
|
+
},
|
|
3677
|
+
});
|
|
4003
3678
|
if (__timeout__ > 0) {
|
|
4004
3679
|
UtilsContext.workerSetTimeout(() => {
|
|
4005
3680
|
// 取消观察器
|
|
@@ -4041,10 +3716,7 @@ class Utils {
|
|
|
4041
3716
|
selector: K,
|
|
4042
3717
|
parent?: Node | Element | Document | HTMLElement
|
|
4043
3718
|
): Promise<HTMLElementTagNameMap[K]>;
|
|
4044
|
-
waitNode<T extends Element>(
|
|
4045
|
-
selector: string,
|
|
4046
|
-
parent?: Node | Element | Document | HTMLElement
|
|
4047
|
-
): Promise<T>;
|
|
3719
|
+
waitNode<T extends Element>(selector: string, parent?: Node | Element | Document | HTMLElement): Promise<T>;
|
|
4048
3720
|
/**
|
|
4049
3721
|
* 等待元素出现
|
|
4050
3722
|
* @param selectorList CSS选择器数组
|
|
@@ -4118,10 +3790,7 @@ class Utils {
|
|
|
4118
3790
|
selector: K,
|
|
4119
3791
|
timeout: number
|
|
4120
3792
|
): Promise<HTMLElementTagNameMap[K] | null>;
|
|
4121
|
-
waitNode<T extends Element>(
|
|
4122
|
-
selector: string,
|
|
4123
|
-
timeout: number
|
|
4124
|
-
): Promise<T | null>;
|
|
3793
|
+
waitNode<T extends Element>(selector: string, timeout: number): Promise<T | null>;
|
|
4125
3794
|
/**
|
|
4126
3795
|
* 等待元素出现
|
|
4127
3796
|
* @param selectorList CSS选择器数组
|
|
@@ -4135,10 +3804,7 @@ class Utils {
|
|
|
4135
3804
|
selectorList: K[],
|
|
4136
3805
|
timeout: number
|
|
4137
3806
|
): Promise<HTMLElementTagNameMap[K] | null>;
|
|
4138
|
-
waitNode<T extends Element[]>(
|
|
4139
|
-
selectorList: string[],
|
|
4140
|
-
timeout: number
|
|
4141
|
-
): Promise<T | null>;
|
|
3807
|
+
waitNode<T extends Element[]>(selectorList: string[], timeout: number): Promise<T | null>;
|
|
4142
3808
|
waitNode<T extends Element | Element[]>(...args: any[]): Promise<T | null> {
|
|
4143
3809
|
// 过滤掉undefined
|
|
4144
3810
|
args = args.filter((arg) => arg !== void 0);
|
|
@@ -4149,14 +3815,8 @@ class Utils {
|
|
|
4149
3815
|
let parent: Element = UtilsContext.windowApi.document as any as Element;
|
|
4150
3816
|
// 超时时间
|
|
4151
3817
|
let timeout = 0;
|
|
4152
|
-
if (
|
|
4153
|
-
|
|
4154
|
-
!Array.isArray(args[0]) &&
|
|
4155
|
-
typeof args[0] !== "function"
|
|
4156
|
-
) {
|
|
4157
|
-
throw new TypeError(
|
|
4158
|
-
"Utils.waitNode 第一个参数必须是string|string[]|Function"
|
|
4159
|
-
);
|
|
3818
|
+
if (typeof args[0] !== "string" && !Array.isArray(args[0]) && typeof args[0] !== "function") {
|
|
3819
|
+
throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]|Function");
|
|
4160
3820
|
}
|
|
4161
3821
|
if (args.length === 1) {
|
|
4162
3822
|
// 上面已做处理
|
|
@@ -4165,10 +3825,7 @@ class Utils {
|
|
|
4165
3825
|
if (typeof secondParam === "number") {
|
|
4166
3826
|
// "div",10000
|
|
4167
3827
|
timeout = secondParam;
|
|
4168
|
-
} else if (
|
|
4169
|
-
typeof secondParam === "object" &&
|
|
4170
|
-
secondParam instanceof Node
|
|
4171
|
-
) {
|
|
3828
|
+
} else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
4172
3829
|
// "div",document
|
|
4173
3830
|
parent = secondParam as any as Element;
|
|
4174
3831
|
} else {
|
|
@@ -4283,10 +3940,7 @@ class Utils {
|
|
|
4283
3940
|
selectorList: K[],
|
|
4284
3941
|
timeout: number
|
|
4285
3942
|
): Promise<HTMLElementTagNameMap[K] | null>;
|
|
4286
|
-
waitAnyNode<T extends Element>(
|
|
4287
|
-
selectorList: string[],
|
|
4288
|
-
timeout: number
|
|
4289
|
-
): Promise<T | null>;
|
|
3943
|
+
waitAnyNode<T extends Element>(selectorList: string[], timeout: number): Promise<T | null>;
|
|
4290
3944
|
waitAnyNode<T extends Element>(...args: any[]): Promise<T | null> {
|
|
4291
3945
|
// 过滤掉undefined
|
|
4292
3946
|
args = args.filter((arg) => arg !== void 0);
|
|
@@ -4307,10 +3961,7 @@ class Utils {
|
|
|
4307
3961
|
if (typeof secondParam === "number") {
|
|
4308
3962
|
// "div",10000
|
|
4309
3963
|
timeout = secondParam;
|
|
4310
|
-
} else if (
|
|
4311
|
-
typeof secondParam === "object" &&
|
|
4312
|
-
secondParam instanceof Node
|
|
4313
|
-
) {
|
|
3964
|
+
} else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
4314
3965
|
// "div",document
|
|
4315
3966
|
parent = secondParam as any as Element;
|
|
4316
3967
|
} else {
|
|
@@ -4433,10 +4084,7 @@ class Utils {
|
|
|
4433
4084
|
selector: K[],
|
|
4434
4085
|
timeout: number
|
|
4435
4086
|
): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
|
|
4436
|
-
waitNodeList<T extends NodeListOf<Element>>(
|
|
4437
|
-
selector: string[],
|
|
4438
|
-
timeout: number
|
|
4439
|
-
): Promise<T | null>;
|
|
4087
|
+
waitNodeList<T extends NodeListOf<Element>>(selector: string[], timeout: number): Promise<T | null>;
|
|
4440
4088
|
/**
|
|
4441
4089
|
* 等待元素数组出现
|
|
4442
4090
|
* @param selectorList CSS选择器数组
|
|
@@ -4450,13 +4098,8 @@ class Utils {
|
|
|
4450
4098
|
selectorList: K[],
|
|
4451
4099
|
timeout: number
|
|
4452
4100
|
): Promise<NodeListOf<HTMLElementTagNameMap[K]>[] | null>;
|
|
4453
|
-
waitNodeList<T extends NodeListOf<Element>>(
|
|
4454
|
-
|
|
4455
|
-
timeout: number
|
|
4456
|
-
): Promise<T[] | null>;
|
|
4457
|
-
waitNodeList<T extends NodeListOf<Element> | NodeListOf<Element>[]>(
|
|
4458
|
-
...args: any[]
|
|
4459
|
-
): Promise<T | null> {
|
|
4101
|
+
waitNodeList<T extends NodeListOf<Element>>(selectorList: string[], timeout: number): Promise<T[] | null>;
|
|
4102
|
+
waitNodeList<T extends NodeListOf<Element> | NodeListOf<Element>[]>(...args: any[]): Promise<T | null> {
|
|
4460
4103
|
// 过滤掉undefined
|
|
4461
4104
|
args = args.filter((arg) => arg !== void 0);
|
|
4462
4105
|
let UtilsContext = this;
|
|
@@ -4476,10 +4119,7 @@ class Utils {
|
|
|
4476
4119
|
if (typeof secondParam === "number") {
|
|
4477
4120
|
// "div",10000
|
|
4478
4121
|
timeout = secondParam;
|
|
4479
|
-
} else if (
|
|
4480
|
-
typeof secondParam === "object" &&
|
|
4481
|
-
secondParam instanceof Node
|
|
4482
|
-
) {
|
|
4122
|
+
} else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
4483
4123
|
// "div",document
|
|
4484
4124
|
parent = secondParam as any as Element;
|
|
4485
4125
|
} else {
|
|
@@ -4595,13 +4235,8 @@ class Utils {
|
|
|
4595
4235
|
selectorList: K[],
|
|
4596
4236
|
timeout: number
|
|
4597
4237
|
): Promise<NodeListOf<HTMLElementTagNameMap[K]> | null>;
|
|
4598
|
-
waitAnyNodeList<T extends Element>(
|
|
4599
|
-
|
|
4600
|
-
timeout: number
|
|
4601
|
-
): Promise<NodeListOf<T> | null>;
|
|
4602
|
-
waitAnyNodeList<T extends Element>(
|
|
4603
|
-
...args: any[]
|
|
4604
|
-
): Promise<NodeListOf<T> | null> {
|
|
4238
|
+
waitAnyNodeList<T extends Element>(selectorList: string[], timeout: number): Promise<NodeListOf<T> | null>;
|
|
4239
|
+
waitAnyNodeList<T extends Element>(...args: any[]): Promise<NodeListOf<T> | null> {
|
|
4605
4240
|
// 过滤掉undefined
|
|
4606
4241
|
args = args.filter((arg) => arg !== void 0);
|
|
4607
4242
|
let UtilsContext = this;
|
|
@@ -4621,16 +4256,11 @@ class Utils {
|
|
|
4621
4256
|
if (typeof secondParam === "number") {
|
|
4622
4257
|
// "div",10000
|
|
4623
4258
|
timeout = secondParam;
|
|
4624
|
-
} else if (
|
|
4625
|
-
typeof secondParam === "object" &&
|
|
4626
|
-
secondParam instanceof Node
|
|
4627
|
-
) {
|
|
4259
|
+
} else if (typeof secondParam === "object" && secondParam instanceof Node) {
|
|
4628
4260
|
// "div",document
|
|
4629
4261
|
parent = secondParam as any as Element;
|
|
4630
4262
|
} else {
|
|
4631
|
-
throw new TypeError(
|
|
4632
|
-
"Utils.waitAnyNodeList 第二个参数必须是number|Node"
|
|
4633
|
-
);
|
|
4263
|
+
throw new TypeError("Utils.waitAnyNodeList 第二个参数必须是number|Node");
|
|
4634
4264
|
}
|
|
4635
4265
|
} else if (args.length === 3) {
|
|
4636
4266
|
// "div",document,10000
|
|
@@ -4653,11 +4283,7 @@ class Utils {
|
|
|
4653
4283
|
}
|
|
4654
4284
|
|
|
4655
4285
|
let promiseList = selectorList.map((selector) => {
|
|
4656
|
-
return UtilsContext.waitNodeList<NodeListOf<T>>(
|
|
4657
|
-
selector,
|
|
4658
|
-
parent,
|
|
4659
|
-
timeout
|
|
4660
|
-
);
|
|
4286
|
+
return UtilsContext.waitNodeList<NodeListOf<T>>(selector, parent, timeout);
|
|
4661
4287
|
});
|
|
4662
4288
|
return Promise.any(promiseList);
|
|
4663
4289
|
}
|
|
@@ -4674,14 +4300,8 @@ class Utils {
|
|
|
4674
4300
|
* > "test success set"
|
|
4675
4301
|
*
|
|
4676
4302
|
*/
|
|
4677
|
-
waitProperty<T extends any>(
|
|
4678
|
-
|
|
4679
|
-
checkPropertyName: string
|
|
4680
|
-
): Promise<T>;
|
|
4681
|
-
waitProperty<T extends any>(
|
|
4682
|
-
checkObj: any | (() => any),
|
|
4683
|
-
checkPropertyName: string
|
|
4684
|
-
): Promise<T> {
|
|
4303
|
+
waitProperty<T extends any>(checkObj: any | (() => any), checkPropertyName: string): Promise<T>;
|
|
4304
|
+
waitProperty<T extends any>(checkObj: any | (() => any), checkPropertyName: string): Promise<T> {
|
|
4685
4305
|
return new Promise((resolve) => {
|
|
4686
4306
|
let obj = checkObj;
|
|
4687
4307
|
if (typeof checkObj === "function") {
|
|
@@ -4861,10 +4481,7 @@ class Utils {
|
|
|
4861
4481
|
getCallBack: (value: any) => void,
|
|
4862
4482
|
setCallBack: (value: any) => void
|
|
4863
4483
|
): void {
|
|
4864
|
-
if (
|
|
4865
|
-
typeof getCallBack !== "function" &&
|
|
4866
|
-
typeof setCallBack !== "function"
|
|
4867
|
-
) {
|
|
4484
|
+
if (typeof getCallBack !== "function" && typeof setCallBack !== "function") {
|
|
4868
4485
|
return;
|
|
4869
4486
|
}
|
|
4870
4487
|
|
|
@@ -4903,19 +4520,18 @@ class Utils {
|
|
|
4903
4520
|
});
|
|
4904
4521
|
}
|
|
4905
4522
|
}
|
|
4906
|
-
|
|
4907
4523
|
/**
|
|
4908
4524
|
* 深度获取对象属性
|
|
4909
4525
|
* @param target 待获取的对象
|
|
4910
4526
|
* @param handler 获取属性的回调
|
|
4911
4527
|
*/
|
|
4912
|
-
queryProperty(
|
|
4528
|
+
queryProperty<T extends any = any>(
|
|
4913
4529
|
target: any,
|
|
4914
|
-
handler: (target:
|
|
4530
|
+
handler: (target: T) => {
|
|
4915
4531
|
/**
|
|
4916
4532
|
* 是否是需要的属性
|
|
4917
|
-
* + true 将目标值赋值给data
|
|
4918
|
-
* + false 不是需要的,data为下一个处理的对象
|
|
4533
|
+
* + `true` 将目标值赋值给data
|
|
4534
|
+
* + `false` 不是需要的,data为下一个处理的对象
|
|
4919
4535
|
*/
|
|
4920
4536
|
isFind: boolean;
|
|
4921
4537
|
/**
|
|
@@ -4928,16 +4544,54 @@ class Utils {
|
|
|
4928
4544
|
return;
|
|
4929
4545
|
}
|
|
4930
4546
|
let handleResult = handler(target);
|
|
4931
|
-
if (
|
|
4932
|
-
handleResult &&
|
|
4933
|
-
typeof handleResult.isFind === "boolean" &&
|
|
4934
|
-
handleResult.isFind
|
|
4935
|
-
) {
|
|
4547
|
+
if (handleResult && typeof handleResult.isFind === "boolean" && handleResult.isFind) {
|
|
4936
4548
|
return handleResult.data;
|
|
4937
4549
|
}
|
|
4938
4550
|
return this.queryProperty(handleResult.data, handler);
|
|
4939
4551
|
}
|
|
4940
|
-
|
|
4552
|
+
/**
|
|
4553
|
+
* 异步-深度获取对象属性
|
|
4554
|
+
* @param target 待获取的对象
|
|
4555
|
+
* @param handler 获取属性的回调
|
|
4556
|
+
*/
|
|
4557
|
+
async asyncQueryProperty<T extends any = any>(
|
|
4558
|
+
target: any,
|
|
4559
|
+
handler: (target: T) =>
|
|
4560
|
+
| {
|
|
4561
|
+
/**
|
|
4562
|
+
* 是否是需要的属性
|
|
4563
|
+
* + true 将目标值赋值给data
|
|
4564
|
+
* + false 不是需要的,data为下一个处理的对象
|
|
4565
|
+
*/
|
|
4566
|
+
isFind: boolean;
|
|
4567
|
+
/**
|
|
4568
|
+
* 对象/目标值
|
|
4569
|
+
*/
|
|
4570
|
+
data: any;
|
|
4571
|
+
}
|
|
4572
|
+
| Promise<{
|
|
4573
|
+
/**
|
|
4574
|
+
* 是否是需要的属性
|
|
4575
|
+
* + true 将目标值赋值给data
|
|
4576
|
+
* + false 不是需要的,data为下一个处理的对象
|
|
4577
|
+
*/
|
|
4578
|
+
isFind: boolean;
|
|
4579
|
+
/**
|
|
4580
|
+
* 对象/目标值
|
|
4581
|
+
*/
|
|
4582
|
+
data: any;
|
|
4583
|
+
}>
|
|
4584
|
+
): Promise<Awaited<T>> {
|
|
4585
|
+
if (target == null) {
|
|
4586
|
+
// @ts-ignore
|
|
4587
|
+
return;
|
|
4588
|
+
}
|
|
4589
|
+
let handleResult = await handler(target);
|
|
4590
|
+
if (handleResult && typeof handleResult.isFind === "boolean" && handleResult.isFind) {
|
|
4591
|
+
return handleResult.data;
|
|
4592
|
+
}
|
|
4593
|
+
return await this.asyncQueryProperty(handleResult.data, handler);
|
|
4594
|
+
}
|
|
4941
4595
|
/**
|
|
4942
4596
|
* 创建一个新的Utils实例
|
|
4943
4597
|
* @param option
|