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