@whitesev/utils 2.2.5 → 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.amd.js +42 -8
- package/dist/index.amd.js.map +1 -1
- package/dist/index.cjs.js +42 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +42 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.iife.js +42 -8
- package/dist/index.iife.js.map +1 -1
- package/dist/index.system.js +42 -8
- package/dist/index.system.js.map +1 -1
- package/dist/index.umd.js +42 -8
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/Utils.d.ts +14 -0
- package/package.json +3 -2
- package/src/Utils.ts +60 -13
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];
|