@whitesev/utils 2.11.7 → 2.11.9

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.
@@ -351,17 +351,26 @@ declare class Utils {
351
351
  /**
352
352
  * 获取页面的坐标中最大的z-index的元素信息
353
353
  *
354
- * 其中坐标为
355
- *
356
- * + 左上角(宽: 1/8,高: 1/8)
357
- * + 右上角(宽: 7/8,高: 1/8)
358
- * + 左下角(宽: 1/8,高: 7/8)
359
- * + 右下角(宽: 7/8,高: 7/8)
360
- * + 中间(宽: 1/2,高: 1/2)
354
+ * 矩阵坐标计算
361
355
  * @param $el 仅检测目标元素最大的z-index(自动往上层找)
362
356
  * @param deviation 将对所有获取到的z-index处理偏移量(增加或减少),默认为10
357
+ * @example
358
+ * Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"));
359
+ * @example
360
+ * Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"), 20);
361
+ * @example
362
+ * Utils.getMaxZIndexNodeInfoFromPoint([document.querySelector("a"), document.querySelector("div")]);
363
+ * @example
364
+ * Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500});
365
+ * @example
366
+ * Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500}, 20);
367
+ * @example
368
+ * Utils.getMaxZIndexNodeInfoFromPoint(() => {x: 500, y: 500}, 20);
363
369
  */
364
- getMaxZIndexNodeInfoFromPoint($el?: IFunction<HTMLElement | HTMLElement[]>, deviation?: number): {
370
+ getMaxZIndexNodeInfoFromPoint($el?: IFunction<IArray<HTMLElement> | IArray<{
371
+ x: number;
372
+ y: number;
373
+ }>>, deviation?: number): {
365
374
  /** 处理了偏移量后的z-index值 */
366
375
  zIndex: number;
367
376
  /** 原始z-index值 */
@@ -378,14 +387,10 @@ declare class Utils {
378
387
  /**
379
388
  * 获取页面的坐标中最大的z-index的元素信息
380
389
  *
381
- * 其中坐标为
382
- *
383
- * + 左上角(宽: 1/8,高: 1/8)
384
- * + 右上角(宽: 7/8,高: 1/8)
385
- * + 左下角(宽: 1/8,高: 7/8)
386
- * + 右下角(宽: 7/8,高: 7/8)
387
- * + 中间(宽: 1/2,高: 1/2)
390
+ * 矩阵坐标计算
388
391
  * @param deviation 将对所有获取到的z-index处理偏移量(增加或减少)
392
+ * @example
393
+ * Utils.getMaxZIndexNodeInfoFromPoint(20);
389
394
  */
390
395
  getMaxZIndexNodeInfoFromPoint(deviation: IFunction<number>): {
391
396
  /** 处理了偏移量后的z-index值 */
@@ -1491,8 +1496,22 @@ declare class Utils {
1491
1496
  * 深度获取对象的某个属性
1492
1497
  * @param target 待获取的对象
1493
1498
  * @param handler 获取属性的回调
1499
+ * @example
1500
+ * Utils.queryProperty(window,(target)=>{
1501
+ * if(target.xxx){
1502
+ * return {
1503
+ * isFind: true,
1504
+ * data: target.xxx,
1505
+ * }
1506
+ * }else{
1507
+ * return {
1508
+ * isFind: false,
1509
+ * data: target.aabbcc,
1510
+ * }
1511
+ * }
1512
+ * })
1494
1513
  */
1495
- queryProperty<T = any>(target: any, handler: (
1514
+ queryProperty<T = any, R = any>(target: any, handler: (
1496
1515
  /**
1497
1516
  * 该值为返回的data值
1498
1517
  */
@@ -1505,26 +1524,37 @@ declare class Utils {
1505
1524
  isFind: boolean;
1506
1525
  /**
1507
1526
  * 对象/目标值
1527
+ *
1528
+ * 若`isFind`为true,那该值为返回的结果
1529
+ *
1530
+ * 若`isFind`为false,那该值为下次迭代传入的`target`
1508
1531
  */
1509
- data: any;
1510
- }): any;
1532
+ data: T | R | null | void;
1533
+ }): R | void | null;
1511
1534
  /**
1512
1535
  * 异步-深度获取对象属性
1513
1536
  * @param target 待获取的对象
1514
1537
  * @param handler 获取属性的回调
1538
+ * @example
1539
+ * Utils.asyncQueryProperty(window, async (target)=>{
1540
+ * if(target.xxx){
1541
+ * return {
1542
+ * isFind: true,
1543
+ * data: target.xxx,
1544
+ * }
1545
+ * }else{
1546
+ * return {
1547
+ * isFind: false,
1548
+ * data: target.aabbcc,
1549
+ * }
1550
+ * }
1551
+ * })
1515
1552
  */
1516
- asyncQueryProperty<T = any>(target: any, handler: (target: T) => {
1517
- /**
1518
- * 是否是需要的属性
1519
- * + true 将目标值赋值给data
1520
- * + false 不是需要的,data为下一个处理的对象
1521
- */
1522
- isFind: boolean;
1523
- /**
1524
- * 对象/目标值
1525
- */
1526
- data: any;
1527
- } | Promise<{
1553
+ asyncQueryProperty<T = any, R = any>(target: any, handler: (
1554
+ /**
1555
+ * 该值为返回的data值
1556
+ */
1557
+ target: T) => IPromise<{
1528
1558
  /**
1529
1559
  * 是否是需要的属性
1530
1560
  * + true 将目标值赋值给data
@@ -1533,13 +1563,18 @@ declare class Utils {
1533
1563
  isFind: boolean;
1534
1564
  /**
1535
1565
  * 对象/目标值
1566
+ *
1567
+ * 若`isFind`为true,那该值为返回的结果
1568
+ *
1569
+ * 若`isFind`为false,那该值为下次迭代传入的`target`
1536
1570
  */
1537
- data: any;
1538
- }>): Promise<Awaited<T>>;
1571
+ data: T | R | null | void;
1572
+ }>): Promise<R | void | null>;
1539
1573
  /**
1540
1574
  * 创建一个新的Utils实例
1541
1575
  * @param option
1542
- * @returns
1576
+ * @example
1577
+ * Utils.createUtils();
1543
1578
  */
1544
1579
  createUtils(option?: WindowApiOption): Utils;
1545
1580
  /**
@@ -1567,7 +1602,9 @@ declare class Utils {
1567
1602
  /**
1568
1603
  * 覆盖对象中的函数this指向
1569
1604
  * @param target 需要覆盖的对象
1570
- * @param [objectThis] 覆盖的this指向,如果为传入,则默认为对象本身
1605
+ * @param objectThis 覆盖的this指向,如果为传入,则默认为对象本身
1606
+ * @example
1607
+ * Utils.coverObjectFunctionThis({})
1571
1608
  */
1572
1609
  coverObjectFunctionThis: (target: any, objectThis?: any) => void;
1573
1610
  /**
@@ -1618,7 +1655,7 @@ declare class Utils {
1618
1655
  /**
1619
1656
  * 自动使用 Worker 执行 setTimeout
1620
1657
  * @param callback 回调函数
1621
- * @param [timeout=0] 延迟时间,默认为0
1658
+ * @param timeout 延迟时间,默认为0
1622
1659
  */
1623
1660
  workerSetTimeout(callback: (...args: any[]) => any, timeout?: number): number;
1624
1661
  /**
@@ -1678,6 +1715,10 @@ declare class Utils {
1678
1715
  /**
1679
1716
  * 判断页面中是否存在`worker-src`的CSP规则
1680
1717
  * @param timeout 超时时间,默认为`1500ms`
1718
+ * @example
1719
+ * Utils.hasWorkerCSP().then((hasCSP) => {
1720
+ * console.log(hasCSP);
1721
+ * })
1681
1722
  */
1682
1723
  hasWorkerCSP(timeout?: number): Promise<boolean>;
1683
1724
  /**
@@ -1686,12 +1727,18 @@ declare class Utils {
1686
1727
  * @param positionY 坐标y信息
1687
1728
  * @param otherPositionX 坐标x信息
1688
1729
  * @param otherPositionY 坐标y信息
1730
+ * @example
1731
+ * Utils.calcPositionDistance(1, 2, 3, 4);
1732
+ * > 2.8284271247461903
1689
1733
  */
1690
1734
  calcPositionDistance(positionX: number | string, positionY: number | string, otherPositionX: number | string, otherPositionY: number | string): number;
1691
1735
  /**
1692
1736
  * 计算两个坐标的直线距离
1693
1737
  * @param position 坐标信息
1694
1738
  * @param otherPosition 坐标信息
1739
+ * @example
1740
+ * Utils.calcPositionDistance({x: 1, y: 2}, {x: 3, y: 4});
1741
+ * > 2.8284271247461903
1695
1742
  */
1696
1743
  calcPositionDistance(position: {
1697
1744
  x: number | string;
@@ -9,3 +9,5 @@ declare var msIndexedDB: IDBFactory | null;
9
9
  declare type IPromise<T> = T | Promise<T>;
10
10
 
11
11
  declare type IFunction<T> = T | (() => T);
12
+
13
+ declare type IArray<T> = T | Array<T>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@whitesev/utils",
4
- "version": "2.11.7",
4
+ "version": "2.11.9",
5
5
  "description": "一个常用的工具库",
6
6
  "keywords": [
7
7
  "ScriptCat",