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