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