@whitesev/utils 2.2.5 → 2.2.7

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.umd.js CHANGED
@@ -3657,7 +3657,7 @@
3657
3657
  this.windowApi = new WindowApi(option);
3658
3658
  }
3659
3659
  /** 版本号 */
3660
- version = "2024.9.4";
3660
+ version = "2024.9.10";
3661
3661
  addStyle(cssText) {
3662
3662
  if (typeof cssText !== "string") {
3663
3663
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");
@@ -4353,32 +4353,66 @@
4353
4353
  return Math.max(...newResult);
4354
4354
  }
4355
4355
  }
4356
- getMaxZIndex(deviation = 1) {
4356
+ getMaxZIndexNodeInfo(deviation = 1) {
4357
4357
  deviation = Number.isNaN(deviation) ? 1 : deviation;
4358
+ const UtilsContext = this;
4358
4359
  // 最大值2147483647
4359
- let maxZIndex = Math.pow(2, 31) - 1;
4360
+ const maxZIndex = Math.pow(2, 31) - 1;
4360
4361
  // 比较值2000000000
4361
- let maxZIndexCompare = 2 * Math.pow(10, 9);
4362
+ const maxZIndexCompare = 2 * Math.pow(10, 9);
4362
4363
  // 当前页面最大的z-index
4363
4364
  let zIndex = 0;
4364
- this.windowApi.document.querySelectorAll("*").forEach(($ele, index) => {
4365
- let nodeStyle = this.windowApi.window.getComputedStyle($ele);
4365
+ // 当前的最大z-index的元素,调试使用
4366
+ // @ts-ignore
4367
+ let maxZIndexNode = null;
4368
+ /**
4369
+ * 元素是否可见
4370
+ * @param $css
4371
+ */
4372
+ function isVisibleNode($css) {
4373
+ return $css.position !== "static" && $css.display !== "none";
4374
+ }
4375
+ /**
4376
+ * 查询元素的z-index
4377
+ * 并比较值是否是已获取的最大值
4378
+ * @param $ele
4379
+ */
4380
+ function queryMaxZIndex($ele) {
4381
+ /** 元素的样式 */
4382
+ const nodeStyle = UtilsContext.windowApi.window.getComputedStyle($ele);
4366
4383
  /* 不对position为static和display为none的元素进行获取它们的z-index */
4367
- if (nodeStyle.position !== "static" && nodeStyle.display !== "none") {
4384
+ if (isVisibleNode(nodeStyle)) {
4368
4385
  let nodeZIndex = parseInt(nodeStyle.zIndex);
4369
4386
  if (!isNaN(nodeZIndex)) {
4370
4387
  if (nodeZIndex > zIndex) {
4388
+ // 赋值到全局
4371
4389
  zIndex = nodeZIndex;
4390
+ maxZIndexNode = $ele;
4372
4391
  }
4373
4392
  }
4393
+ // 判断shadowRoot
4394
+ if ($ele.shadowRoot != null && $ele instanceof ShadowRoot) {
4395
+ $ele.shadowRoot.querySelectorAll("*").forEach(($shadowEle) => {
4396
+ queryMaxZIndex($shadowEle);
4397
+ });
4398
+ }
4374
4399
  }
4400
+ }
4401
+ this.windowApi.document.querySelectorAll("*").forEach(($ele, index) => {
4402
+ queryMaxZIndex($ele);
4375
4403
  });
4376
4404
  zIndex += deviation;
4377
4405
  if (zIndex >= maxZIndexCompare) {
4378
4406
  // 最好不要超过最大值
4379
4407
  zIndex = maxZIndex;
4380
4408
  }
4381
- return zIndex;
4409
+ return {
4410
+ node: maxZIndexNode,
4411
+ zIndex: zIndex,
4412
+ };
4413
+ }
4414
+ getMaxZIndex(deviation = 1) {
4415
+ return this.getMaxZIndexNodeInfo(deviation).zIndex;
4382
4416
  }
4383
4417
  getMinValue(...args) {
4384
4418
  let result = [...args];
@@ -6097,7 +6131,7 @@
6097
6131
  });
6098
6132
  return result;
6099
6133
  }
6100
- toSearchParamsStr(obj) {
6134
+ toSearchParamsStr(obj, addPrefix) {
6101
6135
  let UtilsContext = this;
6102
6136
  let searhParamsStr = "";
6103
6137
  if (Array.isArray(obj)) {
@@ -6113,8 +6147,22 @@
6113
6147
  else {
6114
6148
  searhParamsStr = new URLSearchParams(Object.entries(obj)).toString();
6115
6149
  }
6150
+ if (addPrefix && !searhParamsStr.startsWith("?")) {
6151
+ searhParamsStr = "?" + searhParamsStr;
6152
+ }
6116
6153
  return searhParamsStr;
6117
6154
  }
6155
+ /**
6156
+ * 将UrlSearchParams格式的字符串转为对象
6157
+ */
6158
+ searchParamStrToObj(searhParamsStr) {
6159
+ if (typeof searhParamsStr !== "string") {
6160
+ // @ts-ignore
6161
+ return {};
6162
+ }
6163
+ // @ts-ignore
6164
+ return Object.fromEntries(new URLSearchParams(searhParamsStr));
6165
+ }
6118
6166
  /**
6119
6167
  * 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
6120
6168
  * @example