@whitesev/pops 4.0.2 → 4.2.0

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.
Files changed (84) hide show
  1. package/dist/index.amd.js +363 -275
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.amd.min.js +1 -1
  4. package/dist/index.amd.min.js.map +1 -1
  5. package/dist/index.cjs.js +363 -275
  6. package/dist/index.cjs.js.map +1 -1
  7. package/dist/index.cjs.min.js +1 -1
  8. package/dist/index.cjs.min.js.map +1 -1
  9. package/dist/index.esm.js +363 -275
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/index.esm.min.js +1 -1
  12. package/dist/index.esm.min.js.map +1 -1
  13. package/dist/index.iife.js +363 -275
  14. package/dist/index.iife.js.map +1 -1
  15. package/dist/index.iife.min.js +1 -1
  16. package/dist/index.iife.min.js.map +1 -1
  17. package/dist/index.system.js +363 -275
  18. package/dist/index.system.js.map +1 -1
  19. package/dist/index.system.min.js +1 -1
  20. package/dist/index.system.min.js.map +1 -1
  21. package/dist/index.umd.js +363 -275
  22. package/dist/index.umd.js.map +1 -1
  23. package/dist/index.umd.min.js +1 -1
  24. package/dist/index.umd.min.js.map +1 -1
  25. package/dist/types/src/Pops.d.ts +116 -16
  26. package/dist/types/src/components/loading/types/index.d.ts +1 -1
  27. package/dist/types/src/components/panel/index.d.ts +3 -2
  28. package/dist/types/src/components/rightClickMenu/types/index.d.ts +1 -1
  29. package/dist/types/src/components/searchSuggestion/types/index.d.ts +1 -1
  30. package/dist/types/src/components/tooltip/index.d.ts +82 -1
  31. package/dist/types/src/components/tooltip/types/index.d.ts +1 -1
  32. package/dist/types/src/config/GlobalConfig.d.ts +3 -3
  33. package/dist/types/src/event/EventEmiter.d.ts +7 -1
  34. package/dist/types/src/handler/PopsInstHandler.d.ts +4 -4
  35. package/dist/types/src/types/EventEmitter.d.ts +21 -0
  36. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +1 -1
  37. package/dist/types/src/types/components.d.ts +15 -18
  38. package/dist/types/src/types/global.d.ts +2 -0
  39. package/dist/types/src/types/mask.d.ts +6 -6
  40. package/dist/types/src/utils/PopsDOMUtils.d.ts +2 -2
  41. package/dist/types/src/utils/PopsInstanceUtils.d.ts +22 -0
  42. package/dist/types/src/utils/PopsUtils.d.ts +21 -16
  43. package/package.json +1 -1
  44. package/src/Pops.ts +11 -11
  45. package/src/components/alert/defaultConfig.ts +1 -1
  46. package/src/components/alert/index.ts +1 -1
  47. package/src/components/confirm/defaultConfig.ts +1 -1
  48. package/src/components/confirm/index.ts +1 -1
  49. package/src/components/drawer/defaultConfig.ts +1 -1
  50. package/src/components/drawer/index.ts +2 -1
  51. package/src/components/folder/defaultConfig.ts +1 -1
  52. package/src/components/folder/index.ts +1 -1
  53. package/src/components/iframe/defaultConfig.ts +1 -1
  54. package/src/components/iframe/index.ts +10 -6
  55. package/src/components/loading/defaultConfig.ts +1 -0
  56. package/src/components/loading/index.ts +10 -10
  57. package/src/components/loading/types/index.ts +1 -4
  58. package/src/components/panel/defaultConfig.ts +1 -1
  59. package/src/components/panel/handlerComponents.ts +4 -4
  60. package/src/components/panel/index.ts +3 -2
  61. package/src/components/prompt/defaultConfig.ts +1 -1
  62. package/src/components/prompt/index.ts +1 -1
  63. package/src/components/rightClickMenu/defaultConfig.ts +1 -1
  64. package/src/components/rightClickMenu/index.ts +1 -1
  65. package/src/components/rightClickMenu/types/index.ts +1 -1
  66. package/src/components/searchSuggestion/defaultConfig.ts +1 -0
  67. package/src/components/searchSuggestion/index.ts +1 -1
  68. package/src/components/searchSuggestion/types/index.ts +1 -1
  69. package/src/components/tooltip/defaultConfig.ts +1 -1
  70. package/src/components/tooltip/index.ts +1 -1
  71. package/src/components/tooltip/types/index.ts +1 -1
  72. package/src/event/EventEmiter.ts +15 -14
  73. package/src/handler/PopsHandler.ts +9 -21
  74. package/src/handler/PopsInstHandler.ts +65 -47
  75. package/src/types/EventEmitter.d.ts +21 -0
  76. package/src/types/PopsDOMUtilsEventType.d.ts +1 -1
  77. package/src/types/components.d.ts +15 -18
  78. package/src/types/global.d.ts +2 -0
  79. package/src/types/mask.d.ts +6 -6
  80. package/src/utils/PopsDOMUtils.ts +6 -3
  81. package/src/utils/PopsInstanceUtils.ts +50 -0
  82. package/src/utils/PopsUtils.ts +95 -68
  83. package/dist/types/src/utils/PopsDOMUtilsEventsConfig.d.ts +0 -4
  84. package/src/utils/PopsDOMUtilsEventsConfig.ts +0 -4
@@ -1,3 +1,4 @@
1
+ import { PopsCommonCSSClassName } from "../config/CommonCSSClassName";
1
2
  import { PopsInstData } from "../PopsInst";
2
3
  import type { PopsInstStoreType } from "../types/main";
3
4
  import { popsUtils } from "./PopsUtils";
@@ -82,4 +83,53 @@ export const PopsInstanceUtils = {
82
83
  }
83
84
  };
84
85
  },
86
+ /**
87
+ * 是否是隐藏状态
88
+ *
89
+ * 检测以下项:
90
+ *
91
+ * + `display`: none
92
+ * + `visibility`: hidden
93
+ * + `opacity`: 0
94
+ * + `使用了pops的自定义的隐藏class类`
95
+ * @param $el 需要检测的元素
96
+ */
97
+ isHide($el: Element) {
98
+ let flag = false;
99
+ if (
100
+ $el?.classList?.contains(PopsCommonCSSClassName.hide) ||
101
+ $el?.classList?.contains(PopsCommonCSSClassName.hideImportant)
102
+ ) {
103
+ flag = true;
104
+ } else {
105
+ if ($el instanceof HTMLElement) {
106
+ const style = $el.style;
107
+ flag = style.display.includes("none") || style.visibility.includes("hidden") || style.opacity !== "0";
108
+ }
109
+ if (!flag) {
110
+ const style = globalThis.getComputedStyle($el);
111
+ flag = style.display.includes("none") || style.visibility.includes("hidden") || style.opacity !== "0";
112
+ }
113
+ }
114
+ return flag;
115
+ },
116
+ /**
117
+ * 判断元素是否是在`.pops`内
118
+ * @param $el 目标元素
119
+ */
120
+ isNodeInPopsNode($el: Element) {
121
+ return !!($el.closest(".pops") || $el.matches(".pops"));
122
+ },
123
+ /**
124
+ * 判断是否是`.pops-anim`元素
125
+ * @param $el 目标元素
126
+ */
127
+ isAnimNode($el: Element) {
128
+ return !!(
129
+ $el?.localName?.toLowerCase() === "div" &&
130
+ $el.className &&
131
+ $el.className === "pops-anim" &&
132
+ $el.hasAttribute("anim")
133
+ );
134
+ },
85
135
  };
@@ -1,5 +1,6 @@
1
- import AnyTouch from "any-touch";
2
1
  import doubletap from "@any-touch/doubletap";
2
+ import AnyTouch from "any-touch";
3
+ import { EventEmiter } from "../event/EventEmiter";
3
4
  import { PopsCore } from "../PopsCore";
4
5
  import type { PopsUtilsOwnObject } from "../types/main";
5
6
 
@@ -136,7 +137,8 @@ class PopsUtils {
136
137
  typeof sourceValue === "object" &&
137
138
  sourceValue != null &&
138
139
  keyName in target &&
139
- !UtilsContext.isDOM(sourceValue)
140
+ !UtilsContext.isDOM(sourceValue) &&
141
+ !(sourceValue instanceof EventEmiter)
140
142
  ) {
141
143
  // 源端的值是object类型,且不是元素节点
142
144
  // 如果是数组,那此数组中有值,清空旧的数组再赋值
@@ -151,7 +153,7 @@ class PopsUtils {
151
153
  }
152
154
  Reflect.set(target, keyName, childObjectValue);
153
155
  } else {
154
- /* 直接赋值 */
156
+ // 直接赋值
155
157
  Reflect.set(target, keyName, sourceValue);
156
158
  }
157
159
  }
@@ -414,18 +416,24 @@ class PopsUtils {
414
416
  /**
415
417
  * 获取页面的坐标中最大的z-index的元素信息
416
418
  *
417
- * 其中坐标为
418
- *
419
- * + 左上角(宽: 1/8,高: 1/8)
420
- * + 右上角(宽: 7/8,高: 1/8)
421
- * + 左下角(宽: 1/8,高: 7/8)
422
- * + 右下角(宽: 7/8,高: 7/8)
423
- * + 中间(宽: 1/2,高: 1/2)
419
+ * 矩阵坐标计算
424
420
  * @param $el 仅检测目标元素最大的z-index(自动往上层找)
425
421
  * @param deviation 将对所有获取到的z-index处理偏移量(增加或减少),默认为10
422
+ * @example
423
+ * Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"));
424
+ * @example
425
+ * Utils.getMaxZIndexNodeInfoFromPoint(document.querySelector("a"), 20);
426
+ * @example
427
+ * Utils.getMaxZIndexNodeInfoFromPoint([document.querySelector("a"), document.querySelector("div")]);
428
+ * @example
429
+ * Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500});
430
+ * @example
431
+ * Utils.getMaxZIndexNodeInfoFromPoint({x: 500, y: 500}, 20);
432
+ * @example
433
+ * Utils.getMaxZIndexNodeInfoFromPoint(() => {x: 500, y: 500}, 20);
426
434
  */
427
435
  getMaxZIndexNodeInfoFromPoint(
428
- $el?: IFunction<HTMLElement | HTMLElement[]>,
436
+ $el?: IFunction<IArray<HTMLElement> | IArray<{ x: number; y: number }>>,
429
437
  deviation?: number
430
438
  ): {
431
439
  /** 处理了偏移量后的z-index值 */
@@ -444,14 +452,10 @@ class PopsUtils {
444
452
  /**
445
453
  * 获取页面的坐标中最大的z-index的元素信息
446
454
  *
447
- * 其中坐标为
448
- *
449
- * + 左上角(宽: 1/8,高: 1/8)
450
- * + 右上角(宽: 7/8,高: 1/8)
451
- * + 左下角(宽: 1/8,高: 7/8)
452
- * + 右下角(宽: 7/8,高: 7/8)
453
- * + 中间(宽: 1/2,高: 1/2)
455
+ * 矩阵坐标计算
454
456
  * @param deviation 将对所有获取到的z-index处理偏移量(增加或减少)
457
+ * @example
458
+ * Utils.getMaxZIndexNodeInfoFromPoint(20);
455
459
  */
456
460
  getMaxZIndexNodeInfoFromPoint(deviation: IFunction<number>): {
457
461
  /** 处理了偏移量后的z-index值 */
@@ -468,7 +472,7 @@ class PopsUtils {
468
472
  positionY: number;
469
473
  }[];
470
474
  getMaxZIndexNodeInfoFromPoint(
471
- $el?: IFunction<HTMLElement | HTMLElement[] | number>,
475
+ $el?: IFunction<IArray<HTMLElement> | number | IArray<{ x: number; y: number }>>,
472
476
  deviation?: number
473
477
  ): {
474
478
  /** 处理了偏移量后的z-index值 */
@@ -494,33 +498,34 @@ class PopsUtils {
494
498
  if (typeof deviation !== "number" || Number.isNaN(deviation)) {
495
499
  deviation = 10;
496
500
  }
497
- const leftTop = {
498
- x: globalThis.innerWidth * (1 / 8),
499
- y: globalThis.innerHeight * (1 / 8),
500
- };
501
- const leftBottom = {
502
- x: globalThis.innerWidth * (1 / 8),
503
- y: globalThis.innerHeight * (7 / 8),
504
- };
505
- const rightTop = {
506
- x: globalThis.innerWidth * (7 / 8),
507
- y: globalThis.innerHeight * (1 / 8),
508
- };
509
- const rightBottom = {
510
- x: globalThis.innerWidth * (7 / 8),
511
- y: globalThis.innerHeight * (7 / 8),
512
- };
513
- const center = {
514
- x: globalThis.innerWidth / 2,
515
- y: globalThis.innerHeight / 2,
516
- };
517
- const delayHandlerElementPostionList: ({ x: number; y: number } | HTMLElement)[] = [
518
- leftTop,
519
- leftBottom,
520
- rightTop,
521
- rightBottom,
522
- center,
523
- ];
501
+ /** 坐标偏移 */
502
+ const positionDistance = 10;
503
+ const defaultCalcPostion: {
504
+ x: number;
505
+ y: number;
506
+ }[] = [];
507
+ const maxPostionX = globalThis.innerWidth;
508
+ const maxPostionY = globalThis.innerHeight;
509
+ const gridXCount = 8;
510
+ const gridYCount = 8;
511
+ for (let i = 0; i < gridXCount; i++) {
512
+ for (let j = 0; j < gridYCount; j++) {
513
+ const positionX = globalThis.innerWidth * (i / gridXCount) + positionDistance;
514
+ const positionY = globalThis.innerHeight * (j / gridYCount) + positionDistance;
515
+ const position: (typeof defaultCalcPostion)[0] = {
516
+ x: positionX,
517
+ y: positionY,
518
+ };
519
+ if (position.x > maxPostionX) {
520
+ position.x = maxPostionX;
521
+ }
522
+ if (position.y > maxPostionY) {
523
+ position.y = maxPostionY;
524
+ }
525
+ defaultCalcPostion.push(position);
526
+ }
527
+ }
528
+ const delayHandlerElementPostionList: ({ x: number; y: number } | HTMLElement)[] = defaultCalcPostion;
524
529
  if ($el) {
525
530
  delayHandlerElementPostionList.length = 0;
526
531
  if (Array.isArray($el)) {
@@ -531,55 +536,77 @@ class PopsUtils {
531
536
  }
532
537
  const positionInfoList = delayHandlerElementPostionList
533
538
  .map((position) => {
534
- let positionNode: Element | null;
539
+ let $position: Element | null;
535
540
  let positionX: number;
536
541
  let positionY: number;
537
542
  if (position instanceof HTMLElement) {
538
- positionNode = position;
543
+ $position = position;
539
544
  const nodeRect = position.getBoundingClientRect();
540
545
  positionX = nodeRect.x + nodeRect.width / 2;
541
546
  positionY = nodeRect.y + nodeRect.height / 2;
542
547
  } else {
543
- positionNode = document.elementFromPoint(position.x, position.y);
548
+ $position = document.elementFromPoint(position.x, position.y);
544
549
  positionX = position.x;
545
550
  positionY = position.y;
546
551
  }
547
- const shadowRoot = positionNode?.shadowRoot;
552
+ const shadowRoot = $position?.shadowRoot;
548
553
  if (shadowRoot) {
549
- positionNode = shadowRoot.elementFromPoint(positionX, positionY);
554
+ // 处理ShadowRoot
555
+ $position = shadowRoot.elementFromPoint(positionX, positionY);
550
556
  }
551
- if (positionNode instanceof HTMLStyleElement) return;
552
- if (positionNode instanceof HTMLScriptElement) return;
553
- if (positionNode instanceof HTMLMetaElement) return;
554
- if (positionNode instanceof HTMLHeadElement) return;
555
- if (!(positionNode instanceof HTMLElement)) return;
556
- let parent: HTMLElement | null = positionNode;
557
+ if (!($position instanceof HTMLElement)) return;
558
+ let $parent: HTMLElement | null = $position;
557
559
  let zIndex = 0;
558
- let maxZIndexNode: HTMLElement | null = null;
559
- while (parent) {
560
- const nodeStyle = globalThis.getComputedStyle(parent);
560
+ let $maxZIndexNode: HTMLElement | null = null;
561
+ let rect = {
562
+ x: 0,
563
+ y: 0,
564
+ width: 0,
565
+ height: 0,
566
+ top: 0,
567
+ right: 0,
568
+ bottom: 0,
569
+ left: 0,
570
+ } as Omit<DOMRect, "toJSON">;
571
+ while ($parent) {
572
+ const nodeStyle = globalThis.getComputedStyle($parent);
561
573
  const nodeZIndex = parseInt(nodeStyle.zIndex);
562
574
  if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
563
575
  if (nodeZIndex > zIndex) {
564
576
  zIndex = nodeZIndex;
565
- maxZIndexNode = parent;
577
+ $maxZIndexNode = $parent;
566
578
  }
567
579
  }
568
- parent = parent.parentElement;
580
+ $parent = $parent.parentElement;
581
+ }
582
+ if ($maxZIndexNode) {
583
+ const maxRect = $maxZIndexNode.getBoundingClientRect();
584
+ rect = {
585
+ x: maxRect.x,
586
+ y: maxRect.y,
587
+ width: maxRect.width,
588
+ height: maxRect.height,
589
+ top: maxRect.top,
590
+ right: maxRect.right,
591
+ bottom: maxRect.bottom,
592
+ left: maxRect.left,
593
+ };
569
594
  }
570
595
  return {
571
- /** 处理了偏移量后的z-index值 */
596
+ /** 计算偏移量后的z-index值 */
572
597
  zIndex: zIndex + deviation,
573
- /** 原始z-index值 */
598
+ /** 获取到的最大的z-index值 */
574
599
  originZIndex: zIndex,
575
600
  /** 拥有最大z-index的元素 */
576
- node: maxZIndexNode,
601
+ node: $maxZIndexNode,
577
602
  /** 目标坐标元素 */
578
- positionNode: positionNode,
579
- /** x坐标 */
603
+ positionNode: $position,
604
+ /** 目标x坐标 */
580
605
  positionX: positionX,
581
- /** y坐标 */
606
+ /** 目标y坐标 */
582
607
  positionY: positionY,
608
+ /** node位置信息 */
609
+ rect,
583
610
  };
584
611
  })
585
612
  .filter((it) => it != null);
@@ -1,4 +0,0 @@
1
- /**
2
- * 存储在元素属性上的事件名
3
- */
4
- export declare const SymbolEvents: unique symbol;
@@ -1,4 +0,0 @@
1
- /**
2
- * 存储在元素属性上的事件名
3
- */
4
- export const SymbolEvents = Symbol("events_" + (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1));