@whitesev/utils 2.1.5 → 2.2.1
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 +14 -34
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +14 -34
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +14 -34
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +14 -34
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +14 -34
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +14 -34
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +1 -67
- package/package.json +1 -1
- package/src/Utils.ts +2 -129
package/dist/index.umd.js
CHANGED
|
@@ -3555,7 +3555,7 @@
|
|
|
3555
3555
|
this.windowApi = new WindowApi(option);
|
|
3556
3556
|
}
|
|
3557
3557
|
/** 版本号 */
|
|
3558
|
-
version = "2024.
|
|
3558
|
+
version = "2024.9.1";
|
|
3559
3559
|
addStyle(cssText) {
|
|
3560
3560
|
if (typeof cssText !== "string") {
|
|
3561
3561
|
throw new Error("Utils.addStyle 参数cssText 必须为String类型");
|
|
@@ -4939,6 +4939,19 @@
|
|
|
4939
4939
|
return this.windowApi.globalThis.matchMedia("(prefers-color-scheme: dark)")
|
|
4940
4940
|
.matches;
|
|
4941
4941
|
}
|
|
4942
|
+
/**
|
|
4943
|
+
* 判断元素是否在页面中可见
|
|
4944
|
+
* @param element 需要检查的元素,可以是普通元素|数组形式的元素|通过querySelectorAll获取的元素数组
|
|
4945
|
+
* @param inView
|
|
4946
|
+
* + true 在窗口可视区域
|
|
4947
|
+
* + false 不在窗口可视区域
|
|
4948
|
+
* @returns
|
|
4949
|
+
* + true 可见
|
|
4950
|
+
* + false 不可见
|
|
4951
|
+
* @example
|
|
4952
|
+
* Utils.isVisible(document.documentElement)
|
|
4953
|
+
* > true
|
|
4954
|
+
*/
|
|
4942
4955
|
isVisible(element, inView = false) {
|
|
4943
4956
|
let needCheckDomList = [];
|
|
4944
4957
|
if (element instanceof Array || element instanceof NodeList) {
|
|
@@ -5033,39 +5046,6 @@
|
|
|
5033
5046
|
});
|
|
5034
5047
|
return result;
|
|
5035
5048
|
}
|
|
5036
|
-
listenKeyboard(target, eventName = "keypress", callback, options) {
|
|
5037
|
-
if (typeof target !== "object" ||
|
|
5038
|
-
(typeof target["addEventListener"] !== "function" &&
|
|
5039
|
-
typeof target["removeEventListener"] !== "function")) {
|
|
5040
|
-
throw new Error("Utils.listenKeyboard 参数 target 必须为 Window|HTMLElement 类型");
|
|
5041
|
-
}
|
|
5042
|
-
let keyEvent = function (event) {
|
|
5043
|
-
let keyName = event.key || event.code;
|
|
5044
|
-
let keyValue = event.charCode || event.keyCode || event.which;
|
|
5045
|
-
let otherCodeList = [];
|
|
5046
|
-
if (event.ctrlKey) {
|
|
5047
|
-
otherCodeList.push("ctrl");
|
|
5048
|
-
}
|
|
5049
|
-
if (event.altKey) {
|
|
5050
|
-
otherCodeList.push("alt");
|
|
5051
|
-
}
|
|
5052
|
-
if (event.metaKey) {
|
|
5053
|
-
otherCodeList.push("meta");
|
|
5054
|
-
}
|
|
5055
|
-
if (event.shiftKey) {
|
|
5056
|
-
otherCodeList.push("shift");
|
|
5057
|
-
}
|
|
5058
|
-
if (typeof callback === "function") {
|
|
5059
|
-
callback(keyName, keyValue.toString(), otherCodeList, event);
|
|
5060
|
-
}
|
|
5061
|
-
};
|
|
5062
|
-
target.addEventListener(eventName, keyEvent, options);
|
|
5063
|
-
return {
|
|
5064
|
-
removeListen() {
|
|
5065
|
-
target.removeEventListener(eventName, keyEvent);
|
|
5066
|
-
},
|
|
5067
|
-
};
|
|
5068
|
-
}
|
|
5069
5049
|
/**
|
|
5070
5050
|
* 自动锁对象,用于循环判断运行的函数,在循环外new后使用,注意,如果函数内部存在异步操作,需要使用await
|
|
5071
5051
|
* @example
|