@whitesev/utils 2.5.6 → 2.5.7
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 -91
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +98 -91
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +98 -91
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +98 -91
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +98 -91
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +98 -91
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +65 -18
- package/dist/types/src/types/global.d.ts +1 -0
- package/package.json +1 -1
- package/src/Utils.ts +203 -113
- package/src/types/global.d.ts +1 -0
package/dist/index.umd.js
CHANGED
|
@@ -4145,7 +4145,7 @@
|
|
|
4145
4145
|
this.windowApi = new WindowApi(option);
|
|
4146
4146
|
}
|
|
4147
4147
|
/** 版本号 */
|
|
4148
|
-
version = "
|
|
4148
|
+
version = "2025.1.1";
|
|
4149
4149
|
addStyle(cssText) {
|
|
4150
4150
|
if (typeof cssText !== "string") {
|
|
4151
4151
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -6759,6 +6759,39 @@
|
|
|
6759
6759
|
await UtilsContext.tryCatch(index, item).run(handleFunc);
|
|
6760
6760
|
}));
|
|
6761
6761
|
}
|
|
6762
|
+
wait(checkFn, timeout, parent) {
|
|
6763
|
+
const UtilsContext = this;
|
|
6764
|
+
let __timeout__ = typeof timeout === "number" ? timeout : 0;
|
|
6765
|
+
return new Promise((resolve) => {
|
|
6766
|
+
let observer = UtilsContext.mutationObserver(parent || UtilsContext.windowApi.document, {
|
|
6767
|
+
config: {
|
|
6768
|
+
subtree: true,
|
|
6769
|
+
childList: true,
|
|
6770
|
+
attributes: true,
|
|
6771
|
+
},
|
|
6772
|
+
immediate: true,
|
|
6773
|
+
callback(mutations, __observer__) {
|
|
6774
|
+
let result = checkFn();
|
|
6775
|
+
if (result.success) {
|
|
6776
|
+
// 取消观察器
|
|
6777
|
+
if (typeof __observer__?.disconnect === "function") {
|
|
6778
|
+
__observer__.disconnect();
|
|
6779
|
+
}
|
|
6780
|
+
resolve(result.data);
|
|
6781
|
+
}
|
|
6782
|
+
},
|
|
6783
|
+
});
|
|
6784
|
+
if (__timeout__ > 0) {
|
|
6785
|
+
setTimeout(() => {
|
|
6786
|
+
// 取消观察器
|
|
6787
|
+
if (typeof observer?.disconnect === "function") {
|
|
6788
|
+
observer.disconnect();
|
|
6789
|
+
}
|
|
6790
|
+
resolve(null);
|
|
6791
|
+
}, __timeout__);
|
|
6792
|
+
}
|
|
6793
|
+
});
|
|
6794
|
+
}
|
|
6762
6795
|
waitNode(...args) {
|
|
6763
6796
|
// 过滤掉undefined
|
|
6764
6797
|
args = args.filter((arg) => arg !== void 0);
|
|
@@ -6769,8 +6802,10 @@
|
|
|
6769
6802
|
let parent = UtilsContext.windowApi.document;
|
|
6770
6803
|
// 超时时间
|
|
6771
6804
|
let timeout = 0;
|
|
6772
|
-
if (typeof args[0] !== "string" &&
|
|
6773
|
-
|
|
6805
|
+
if (typeof args[0] !== "string" &&
|
|
6806
|
+
!Array.isArray(args[0]) &&
|
|
6807
|
+
typeof args[0] !== "function") {
|
|
6808
|
+
throw new TypeError("Utils.waitNode 第一个参数必须是string|string[]|Function");
|
|
6774
6809
|
}
|
|
6775
6810
|
if (args.length === 1) ;
|
|
6776
6811
|
else if (args.length === 2) {
|
|
@@ -6810,53 +6845,41 @@
|
|
|
6810
6845
|
else {
|
|
6811
6846
|
throw new TypeError("Utils.waitNode 参数个数错误");
|
|
6812
6847
|
}
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
result.push(node);
|
|
6821
|
-
}
|
|
6822
|
-
}
|
|
6823
|
-
if (result.length === selector.length) {
|
|
6824
|
-
return result;
|
|
6848
|
+
function getNode() {
|
|
6849
|
+
if (Array.isArray(selector)) {
|
|
6850
|
+
let result = [];
|
|
6851
|
+
for (let index = 0; index < selector.length; index++) {
|
|
6852
|
+
let node = parent.querySelector(selector[index]);
|
|
6853
|
+
if (node) {
|
|
6854
|
+
result.push(node);
|
|
6825
6855
|
}
|
|
6826
6856
|
}
|
|
6827
|
-
|
|
6828
|
-
return
|
|
6857
|
+
if (result.length === selector.length) {
|
|
6858
|
+
return result;
|
|
6829
6859
|
}
|
|
6830
6860
|
}
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
subtree: true,
|
|
6834
|
-
childList: true,
|
|
6835
|
-
attributes: true,
|
|
6836
|
-
},
|
|
6837
|
-
callback() {
|
|
6838
|
-
let node = getNode();
|
|
6839
|
-
if (node) {
|
|
6840
|
-
// 取消观察器
|
|
6841
|
-
if (typeof observer?.disconnect === "function") {
|
|
6842
|
-
observer.disconnect();
|
|
6843
|
-
}
|
|
6844
|
-
resolve(node);
|
|
6845
|
-
return;
|
|
6846
|
-
}
|
|
6847
|
-
},
|
|
6848
|
-
immediate: true,
|
|
6849
|
-
});
|
|
6850
|
-
if (timeout > 0) {
|
|
6851
|
-
setTimeout(() => {
|
|
6852
|
-
// 取消观察器
|
|
6853
|
-
if (typeof observer?.disconnect === "function") {
|
|
6854
|
-
observer.disconnect();
|
|
6855
|
-
}
|
|
6856
|
-
resolve(null);
|
|
6857
|
-
}, timeout);
|
|
6861
|
+
else if (typeof selector === "function") {
|
|
6862
|
+
return selector();
|
|
6858
6863
|
}
|
|
6859
|
-
|
|
6864
|
+
else {
|
|
6865
|
+
return parent.querySelector(selector);
|
|
6866
|
+
}
|
|
6867
|
+
}
|
|
6868
|
+
return UtilsContext.wait(() => {
|
|
6869
|
+
let node = getNode();
|
|
6870
|
+
if (node) {
|
|
6871
|
+
return {
|
|
6872
|
+
success: true,
|
|
6873
|
+
data: node,
|
|
6874
|
+
};
|
|
6875
|
+
}
|
|
6876
|
+
else {
|
|
6877
|
+
return {
|
|
6878
|
+
success: false,
|
|
6879
|
+
data: node,
|
|
6880
|
+
};
|
|
6881
|
+
}
|
|
6882
|
+
}, timeout, parent);
|
|
6860
6883
|
}
|
|
6861
6884
|
waitAnyNode(...args) {
|
|
6862
6885
|
// 过滤掉undefined
|
|
@@ -6965,57 +6988,41 @@
|
|
|
6965
6988
|
else {
|
|
6966
6989
|
throw new TypeError("Utils.waitNodeList 参数个数错误");
|
|
6967
6990
|
}
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
let nodeList = parent.querySelectorAll(selector[index]);
|
|
6974
|
-
if (nodeList.length) {
|
|
6975
|
-
result.push(nodeList);
|
|
6976
|
-
}
|
|
6977
|
-
}
|
|
6978
|
-
if (result.length === selector.length) {
|
|
6979
|
-
return result;
|
|
6980
|
-
}
|
|
6981
|
-
}
|
|
6982
|
-
else {
|
|
6983
|
-
let nodeList = parent.querySelectorAll(selector);
|
|
6991
|
+
function getNodeList() {
|
|
6992
|
+
if (Array.isArray(selector)) {
|
|
6993
|
+
let result = [];
|
|
6994
|
+
for (let index = 0; index < selector.length; index++) {
|
|
6995
|
+
let nodeList = parent.querySelectorAll(selector[index]);
|
|
6984
6996
|
if (nodeList.length) {
|
|
6985
|
-
|
|
6997
|
+
result.push(nodeList);
|
|
6986
6998
|
}
|
|
6987
6999
|
}
|
|
7000
|
+
if (result.length === selector.length) {
|
|
7001
|
+
return result;
|
|
7002
|
+
}
|
|
6988
7003
|
}
|
|
6989
|
-
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
},
|
|
6995
|
-
callback() {
|
|
6996
|
-
let node = getNodeList();
|
|
6997
|
-
if (node) {
|
|
6998
|
-
// 取消观察器
|
|
6999
|
-
try {
|
|
7000
|
-
observer.disconnect();
|
|
7001
|
-
}
|
|
7002
|
-
catch (error) { }
|
|
7003
|
-
resolve(node);
|
|
7004
|
-
return;
|
|
7005
|
-
}
|
|
7006
|
-
},
|
|
7007
|
-
immediate: true,
|
|
7008
|
-
});
|
|
7009
|
-
if (timeout > 0) {
|
|
7010
|
-
setTimeout(() => {
|
|
7011
|
-
// 取消观察器
|
|
7012
|
-
if (typeof observer?.disconnect === "function") {
|
|
7013
|
-
observer.disconnect();
|
|
7014
|
-
}
|
|
7015
|
-
resolve(null);
|
|
7016
|
-
}, timeout);
|
|
7004
|
+
else {
|
|
7005
|
+
let nodeList = parent.querySelectorAll(selector);
|
|
7006
|
+
if (nodeList.length) {
|
|
7007
|
+
return nodeList;
|
|
7008
|
+
}
|
|
7017
7009
|
}
|
|
7018
|
-
}
|
|
7010
|
+
}
|
|
7011
|
+
return UtilsContext.wait(() => {
|
|
7012
|
+
let node = getNodeList();
|
|
7013
|
+
if (node) {
|
|
7014
|
+
return {
|
|
7015
|
+
success: true,
|
|
7016
|
+
data: node,
|
|
7017
|
+
};
|
|
7018
|
+
}
|
|
7019
|
+
else {
|
|
7020
|
+
return {
|
|
7021
|
+
success: false,
|
|
7022
|
+
data: node,
|
|
7023
|
+
};
|
|
7024
|
+
}
|
|
7025
|
+
}, timeout, parent);
|
|
7019
7026
|
}
|
|
7020
7027
|
waitAnyNodeList(...args) {
|
|
7021
7028
|
// 过滤掉undefined
|