@whitesev/utils 2.3.5 → 2.3.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.
@@ -434,7 +434,9 @@ declare class Utils {
434
434
  getMaxValue(val: UtilsOwnObject<number>, handler: (key: any, value: any) => number): number;
435
435
  /**
436
436
  * 获取页面中最大的z-index的元素信息
437
- * @param deviation 获取最大的z-index值的偏移,默认是+1
437
+ * @param deviation 获取最大的z-index值的偏移,默认是1
438
+ * @param node 进行判断的元素,默认是document
439
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
438
440
  * @example
439
441
  * Utils.getMaxZIndexNodeInfo();
440
442
  * > {
@@ -442,18 +444,20 @@ declare class Utils {
442
444
  * zIndex: 1001
443
445
  * }
444
446
  **/
445
- getMaxZIndexNodeInfo(deviation?: number): {
447
+ getMaxZIndexNodeInfo(deviation?: number, target?: Element | ShadowRoot | Document, ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void): {
446
448
  node: Element;
447
449
  zIndex: number;
448
450
  };
449
451
  /**
450
452
  * 获取页面中最大的z-index
451
- * @param deviation 获取最大的z-index值的偏移,默认是+1
453
+ * @param deviation 获取最大的z-index值的偏移,默认是1
454
+ * @param node 进行判断的元素,默认是document
455
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
452
456
  * @example
453
457
  * Utils.getMaxZIndex();
454
458
  * > 1001
455
459
  **/
456
- getMaxZIndex(deviation?: number): number;
460
+ getMaxZIndex(deviation?: number, target?: Element | DocumentOrShadowRoot | Document, ignoreCallBack?: ($ele: Element | HTMLElement | ShadowRoot) => boolean | void): number;
457
461
  /**
458
462
  * 获取最小值
459
463
  * @example
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitesev/utils",
3
- "version": "2.3.5",
3
+ "version": "2.3.6",
4
4
  "description": "一个常用的工具库",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
package/src/Utils.ts CHANGED
@@ -53,7 +53,7 @@ class Utils {
53
53
  this.windowApi = new WindowApi(option);
54
54
  }
55
55
  /** 版本号 */
56
- version = "2024.9.28";
56
+ version = "2024.10.13";
57
57
 
58
58
  /**
59
59
  * 在页面中增加style元素,如果html节点存在子节点,添加子节点第一个,反之,添加到html节点的子节点最后一个
@@ -1228,7 +1228,9 @@ class Utils {
1228
1228
  }
1229
1229
  /**
1230
1230
  * 获取页面中最大的z-index的元素信息
1231
- * @param deviation 获取最大的z-index值的偏移,默认是+1
1231
+ * @param deviation 获取最大的z-index值的偏移,默认是1
1232
+ * @param node 进行判断的元素,默认是document
1233
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
1232
1234
  * @example
1233
1235
  * Utils.getMaxZIndexNodeInfo();
1234
1236
  * > {
@@ -1236,11 +1238,23 @@ class Utils {
1236
1238
  * zIndex: 1001
1237
1239
  * }
1238
1240
  **/
1239
- getMaxZIndexNodeInfo(deviation?: number): {
1241
+ getMaxZIndexNodeInfo(
1242
+ deviation?: number,
1243
+ target?: Element | ShadowRoot | Document,
1244
+ ignoreCallBack?: (
1245
+ $ele: Element | HTMLElement | ShadowRoot
1246
+ ) => boolean | void
1247
+ ): {
1240
1248
  node: Element;
1241
1249
  zIndex: number;
1242
1250
  };
1243
- getMaxZIndexNodeInfo(deviation = 1): {
1251
+ getMaxZIndexNodeInfo(
1252
+ deviation = 1,
1253
+ target: Element | ShadowRoot | Document = this.windowApi.document,
1254
+ ignoreCallBack?: (
1255
+ $ele: Element | HTMLElement | ShadowRoot
1256
+ ) => boolean | void
1257
+ ): {
1244
1258
  node: Element;
1245
1259
  zIndex: number;
1246
1260
  } {
@@ -1268,6 +1282,12 @@ class Utils {
1268
1282
  * @param $ele
1269
1283
  */
1270
1284
  function queryMaxZIndex($ele: Element) {
1285
+ if (typeof ignoreCallBack === "function") {
1286
+ let ignoreResult = ignoreCallBack($ele);
1287
+ if (typeof ignoreResult === "boolean" && !ignoreResult) {
1288
+ return;
1289
+ }
1290
+ }
1271
1291
  /** 元素的样式 */
1272
1292
  const nodeStyle = UtilsContext.windowApi.window.getComputedStyle($ele);
1273
1293
  /* 不对position为static和display为none的元素进行获取它们的z-index */
@@ -1288,7 +1308,7 @@ class Utils {
1288
1308
  }
1289
1309
  }
1290
1310
  }
1291
- this.windowApi.document.querySelectorAll("*").forEach(($ele, index) => {
1311
+ target.querySelectorAll("*").forEach(($ele, index) => {
1292
1312
  queryMaxZIndex($ele);
1293
1313
  });
1294
1314
  zIndex += deviation;
@@ -1303,14 +1323,28 @@ class Utils {
1303
1323
  }
1304
1324
  /**
1305
1325
  * 获取页面中最大的z-index
1306
- * @param deviation 获取最大的z-index值的偏移,默认是+1
1326
+ * @param deviation 获取最大的z-index值的偏移,默认是1
1327
+ * @param node 进行判断的元素,默认是document
1328
+ * @param ignoreCallBack 执行元素处理时调用的函数,返回false可忽略不想要处理的元素
1307
1329
  * @example
1308
1330
  * Utils.getMaxZIndex();
1309
1331
  * > 1001
1310
1332
  **/
1311
- getMaxZIndex(deviation?: number): number;
1312
- getMaxZIndex(deviation = 1): number {
1313
- return this.getMaxZIndexNodeInfo(deviation).zIndex;
1333
+ getMaxZIndex(
1334
+ deviation?: number,
1335
+ target?: Element | DocumentOrShadowRoot | Document,
1336
+ ignoreCallBack?: (
1337
+ $ele: Element | HTMLElement | ShadowRoot
1338
+ ) => boolean | void
1339
+ ): number;
1340
+ getMaxZIndex(
1341
+ deviation = 1,
1342
+ target: Element | ShadowRoot | Document = this.windowApi.document,
1343
+ ignoreCallBack?: (
1344
+ $ele: Element | HTMLElement | ShadowRoot
1345
+ ) => boolean | void
1346
+ ): number {
1347
+ return this.getMaxZIndexNodeInfo(deviation, target, ignoreCallBack).zIndex;
1314
1348
  }
1315
1349
  /**
1316
1350
  * 获取最小值