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