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