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