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