@whitesev/utils 2.2.4 → 2.2.6

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
@@ -3651,7 +3651,7 @@ class Utils {
3651
3651
  this.windowApi = new WindowApi(option);
3652
3652
  }
3653
3653
  /** 版本号 */
3654
- version = "2024.9.4";
3654
+ version = "2024.9.10";
3655
3655
  addStyle(cssText) {
3656
3656
  if (typeof cssText !== "string") {
3657
3657
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -4347,32 +4347,66 @@ class Utils {
4347
4347
  return Math.max(...newResult);
4348
4348
  }
4349
4349
  }
4350
- getMaxZIndex(deviation = 1) {
4350
+ getMaxZIndexNodeInfo(deviation = 1) {
4351
4351
  deviation = Number.isNaN(deviation) ? 1 : deviation;
4352
+ const UtilsContext = this;
4352
4353
  // 最大值2147483647
4353
- let maxZIndex = Math.pow(2, 31) - 1;
4354
+ const maxZIndex = Math.pow(2, 31) - 1;
4354
4355
  // 比较值2000000000
4355
- let maxZIndexCompare = 2 * Math.pow(10, 9);
4356
+ const maxZIndexCompare = 2 * Math.pow(10, 9);
4356
4357
  // 当前页面最大的z-index
4357
4358
  let zIndex = 0;
4358
- this.windowApi.document.querySelectorAll("*").forEach(($ele, index) => {
4359
- let nodeStyle = this.windowApi.window.getComputedStyle($ele);
4359
+ // 当前的最大z-index的元素,调试使用
4360
+ // @ts-ignore
4361
+ let maxZIndexNode = null;
4362
+ /**
4363
+ * 元素是否可见
4364
+ * @param $css
4365
+ */
4366
+ function isVisibleNode($css) {
4367
+ return $css.position !== "static" && $css.display !== "none";
4368
+ }
4369
+ /**
4370
+ * 查询元素的z-index
4371
+ * 并比较值是否是已获取的最大值
4372
+ * @param $ele
4373
+ */
4374
+ function queryMaxZIndex($ele) {
4375
+ /** 元素的样式 */
4376
+ const nodeStyle = UtilsContext.windowApi.window.getComputedStyle($ele);
4360
4377
  /* 不对position为static和display为none的元素进行获取它们的z-index */
4361
- if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
4378
+ if (isVisibleNode(nodeStyle)) {
4362
4379
  let nodeZIndex = parseInt(nodeStyle.zIndex);
4363
4380
  if (!isNaN(nodeZIndex)) {
4364
4381
  if (nodeZIndex > zIndex) {
4382
+ // 赋值到全局
4365
4383
  zIndex = nodeZIndex;
4384
+ maxZIndexNode = $ele;
4366
4385
  }
4367
4386
  }
4387
+ // 判断shadowRoot
4388
+ if ($ele.shadowRoot != null && $ele instanceof ShadowRoot) {
4389
+ $ele.shadowRoot.querySelectorAll("*").forEach(($shadowEle) => {
4390
+ queryMaxZIndex($shadowEle);
4391
+ });
4392
+ }
4368
4393
  }
4394
+ }
4395
+ this.windowApi.document.querySelectorAll("*").forEach(($ele, index) => {
4396
+ queryMaxZIndex($ele);
4369
4397
  });
4370
4398
  zIndex += deviation;
4371
4399
  if (zIndex >= maxZIndexCompare) {
4372
4400
  // 最好不要超过最大值
4373
4401
  zIndex = maxZIndex;
4374
4402
  }
4375
- return zIndex;
4403
+ return {
4404
+ node: maxZIndexNode,
4405
+ zIndex: zIndex,
4406
+ };
4407
+ }
4408
+ getMaxZIndex(deviation = 1) {
4409
+ return this.getMaxZIndexNodeInfo(deviation).zIndex;
4376
4410
  }
4377
4411
  getMinValue(...args) {
4378
4412
  let result = [...args];
@@ -5291,6 +5325,10 @@ class Utils {
5291
5325
  * @param target 目标元素
5292
5326
  * @param callback 触发的回调
5293
5327
  * @param options 观察器配置
5328
+ * @example
5329
+ * Utils.mutationVisible(document.querySelector("div.xxxx"),(entries,observer)=>{
5330
+ * console.log("该元素出现在视图内");
5331
+ * }))
5294
5332
  */
5295
5333
  mutationVisible(target, callback, options) {
5296
5334
  if (typeof IntersectionObserver === "undefined") {