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