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