@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.amd.js +57 -9
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +57 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +57 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +57 -9
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +57 -9
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +57 -9
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Httpx.d.ts +7 -6
- package/dist/types/src/Utils.d.ts +39 -3
- package/package.json +3 -2
- package/src/Httpx.ts +7 -6
- package/src/Utils.ts +99 -20
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.
|
|
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
|
-
|
|
4350
|
+
getMaxZIndexNodeInfo(deviation = 1) {
|
|
4351
4351
|
deviation = Number.isNaN(deviation) ? 1 : deviation;
|
|
4352
|
+
const UtilsContext = this;
|
|
4352
4353
|
// 最大值2147483647
|
|
4353
|
-
|
|
4354
|
+
const maxZIndex = Math.pow(2, 31) - 1;
|
|
4354
4355
|
// 比较值2000000000
|
|
4355
|
-
|
|
4356
|
+
const maxZIndexCompare = 2 * Math.pow(10, 9);
|
|
4356
4357
|
// 当前页面最大的z-index
|
|
4357
4358
|
let zIndex = 0;
|
|
4358
|
-
|
|
4359
|
-
|
|
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
|
|
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
|
|
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];
|
|
@@ -6091,7 +6125,7 @@ class Utils {
|
|
|
6091
6125
|
});
|
|
6092
6126
|
return result;
|
|
6093
6127
|
}
|
|
6094
|
-
toSearchParamsStr(obj) {
|
|
6128
|
+
toSearchParamsStr(obj, addPrefix) {
|
|
6095
6129
|
let UtilsContext = this;
|
|
6096
6130
|
let searhParamsStr = "";
|
|
6097
6131
|
if (Array.isArray(obj)) {
|
|
@@ -6107,8 +6141,22 @@ class Utils {
|
|
|
6107
6141
|
else {
|
|
6108
6142
|
searhParamsStr = new URLSearchParams(Object.entries(obj)).toString();
|
|
6109
6143
|
}
|
|
6144
|
+
if (addPrefix && !searhParamsStr.startsWith("?")) {
|
|
6145
|
+
searhParamsStr = "?" + searhParamsStr;
|
|
6146
|
+
}
|
|
6110
6147
|
return searhParamsStr;
|
|
6111
6148
|
}
|
|
6149
|
+
/**
|
|
6150
|
+
* 将UrlSearchParams格式的字符串转为对象
|
|
6151
|
+
*/
|
|
6152
|
+
searchParamStrToObj(searhParamsStr) {
|
|
6153
|
+
if (typeof searhParamsStr !== "string") {
|
|
6154
|
+
// @ts-ignore
|
|
6155
|
+
return {};
|
|
6156
|
+
}
|
|
6157
|
+
// @ts-ignore
|
|
6158
|
+
return Object.fromEntries(new URLSearchParams(searhParamsStr));
|
|
6159
|
+
}
|
|
6112
6160
|
/**
|
|
6113
6161
|
* 提供一个封装了 try-catch 的函数,可以执行传入的函数并捕获其可能抛出的错误,并通过传入的错误处理函数进行处理。
|
|
6114
6162
|
* @example
|