@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.umd.js
CHANGED
|
@@ -3657,7 +3657,7 @@
|
|
|
3657
3657
|
this.windowApi = new WindowApi(option);
|
|
3658
3658
|
}
|
|
3659
3659
|
/** 版本号 */
|
|
3660
|
-
version = "2024.9.
|
|
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
|
-
|
|
4356
|
+
getMaxZIndexNodeInfo(deviation = 1) {
|
|
4357
4357
|
deviation = Number.isNaN(deviation) ? 1 : deviation;
|
|
4358
|
+
const UtilsContext = this;
|
|
4358
4359
|
// 最大值2147483647
|
|
4359
|
-
|
|
4360
|
+
const maxZIndex = Math.pow(2, 31) - 1;
|
|
4360
4361
|
// 比较值2000000000
|
|
4361
|
-
|
|
4362
|
+
const maxZIndexCompare = 2 * Math.pow(10, 9);
|
|
4362
4363
|
// 当前页面最大的z-index
|
|
4363
4364
|
let zIndex = 0;
|
|
4364
|
-
|
|
4365
|
-
|
|
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
|
|
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
|
|
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];
|
|
@@ -5297,6 +5331,10 @@
|
|
|
5297
5331
|
* @param target 目标元素
|
|
5298
5332
|
* @param callback 触发的回调
|
|
5299
5333
|
* @param options 观察器配置
|
|
5334
|
+
* @example
|
|
5335
|
+
* Utils.mutationVisible(document.querySelector("div.xxxx"),(entries,observer)=>{
|
|
5336
|
+
* console.log("该元素出现在视图内");
|
|
5337
|
+
* }))
|
|
5300
5338
|
*/
|
|
5301
5339
|
mutationVisible(target, callback, options) {
|
|
5302
5340
|
if (typeof IntersectionObserver === "undefined") {
|