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