@whitesev/pops 3.3.5 → 4.0.1

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 +13099 -12934
  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 +752 -587
  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 +752 -587
  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 +13100 -12935
  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 +13103 -12938
  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 +13102 -12937
  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 +131 -77
  26. package/dist/types/src/PopsAnimation.d.ts +33 -0
  27. package/dist/types/src/PopsIcon.d.ts +1 -1
  28. package/dist/types/src/components/alert/index.d.ts +3 -1
  29. package/dist/types/src/components/confirm/index.d.ts +3 -1
  30. package/dist/types/src/components/drawer/index.d.ts +3 -1
  31. package/dist/types/src/components/folder/index.d.ts +3 -1
  32. package/dist/types/src/components/iframe/index.d.ts +6 -1
  33. package/dist/types/src/components/iframe/types/index.d.ts +4 -2
  34. package/dist/types/src/components/loading/index.d.ts +3 -1
  35. package/dist/types/src/components/panel/handlerComponents.d.ts +4 -1
  36. package/dist/types/src/components/panel/index.d.ts +2 -16
  37. package/dist/types/src/components/panel/types/index.d.ts +7 -2
  38. package/dist/types/src/components/prompt/index.d.ts +3 -1
  39. package/dist/types/src/components/searchSuggestion/index.d.ts +4 -1
  40. package/dist/types/src/components/tooltip/index.d.ts +5 -1
  41. package/dist/types/src/config/GlobalConfig.d.ts +63 -23
  42. package/dist/types/src/event/EventEmiter.d.ts +33 -0
  43. package/dist/types/src/handler/PopsHandler.d.ts +16 -11
  44. package/dist/types/src/handler/PopsInstHandler.d.ts +67 -0
  45. package/dist/types/src/types/EventEmitter.d.ts +18 -0
  46. package/dist/types/src/types/PopsDOMUtilsEventType.d.ts +4 -0
  47. package/dist/types/src/types/button.d.ts +2 -1
  48. package/dist/types/src/types/event.d.ts +6 -2
  49. package/dist/types/src/types/inst.d.ts +4 -4
  50. package/dist/types/src/utils/PopsDOMUtils.d.ts +0 -16
  51. package/dist/types/src/utils/PopsInstanceUtils.d.ts +1 -89
  52. package/dist/types/src/utils/PopsUtils.d.ts +57 -0
  53. package/package.json +3 -3
  54. package/src/Pops.ts +7 -2
  55. package/src/PopsAnimation.ts +126 -0
  56. package/src/components/alert/index.ts +9 -9
  57. package/src/components/confirm/index.ts +9 -9
  58. package/src/components/drawer/index.ts +12 -9
  59. package/src/components/folder/index.ts +9 -8
  60. package/src/components/iframe/index.ts +18 -12
  61. package/src/components/iframe/types/index.ts +10 -8
  62. package/src/components/loading/index.ts +12 -6
  63. package/src/components/panel/defaultConfig.ts +1 -0
  64. package/src/components/panel/handlerComponents.ts +41 -111
  65. package/src/components/panel/index.ts +34 -28
  66. package/src/components/panel/types/index.ts +7 -2
  67. package/src/components/prompt/index.ts +9 -8
  68. package/src/components/rightClickMenu/index.ts +17 -14
  69. package/src/components/searchSuggestion/index.ts +5 -1
  70. package/src/components/tooltip/index.ts +20 -10
  71. package/src/config/GlobalConfig.ts +21 -14
  72. package/src/css/index.css +2 -0
  73. package/src/event/EventEmiter.ts +95 -0
  74. package/src/handler/PopsElementHandler.ts +8 -6
  75. package/src/handler/PopsHandler.ts +65 -48
  76. package/src/handler/PopsInstHandler.ts +557 -0
  77. package/src/types/EventEmitter.d.ts +18 -0
  78. package/src/types/PopsDOMUtilsEventType.d.ts +4 -0
  79. package/src/types/button.d.ts +2 -1
  80. package/src/types/event.d.ts +6 -2
  81. package/src/types/inst.d.ts +4 -4
  82. package/src/utils/PopsDOMUtils.ts +1 -40
  83. package/src/utils/PopsInstanceUtils.ts +10 -639
  84. package/src/utils/PopsUtils.ts +194 -0
@@ -4,6 +4,16 @@ import { PopsCore } from "../PopsCore";
4
4
  import type { PopsUtilsOwnObject } from "../types/main";
5
5
 
6
6
  class PopsUtils {
7
+ /**
8
+ * 超时时间
9
+ */
10
+ sleep(timeout: number) {
11
+ return new Promise((resolve) => {
12
+ setTimeout(() => {
13
+ resolve(true);
14
+ }, timeout);
15
+ });
16
+ }
7
17
  /**
8
18
  * 判断是否是window,例如window、self、globalThis
9
19
  * @param target
@@ -401,6 +411,190 @@ class PopsUtils {
401
411
  }
402
412
  (<any>target)[key] = newArr;
403
413
  }
414
+ /**
415
+ * 获取页面的坐标中最大的z-index的元素信息
416
+ *
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)
424
+ * @param $el 仅检测目标元素最大的z-index(自动往上层找)
425
+ * @param deviation 将对所有获取到的z-index处理偏移量(增加或减少),默认为10
426
+ */
427
+ getMaxZIndexNodeInfoFromPoint(
428
+ $el?: IFunction<HTMLElement | HTMLElement[]>,
429
+ deviation?: number
430
+ ): {
431
+ /** 处理了偏移量后的z-index值 */
432
+ zIndex: number;
433
+ /** 原始z-index值 */
434
+ originZIndex: number;
435
+ /** 拥有最大z-index的元素 */
436
+ node: HTMLElement | null;
437
+ /** 目标坐标元素 */
438
+ positionNode: HTMLElement;
439
+ /** x坐标 */
440
+ positionX: number;
441
+ /** y坐标 */
442
+ positionY: number;
443
+ }[];
444
+ /**
445
+ * 获取页面的坐标中最大的z-index的元素信息
446
+ *
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)
454
+ * @param deviation 将对所有获取到的z-index处理偏移量(增加或减少)
455
+ */
456
+ getMaxZIndexNodeInfoFromPoint(deviation: IFunction<number>): {
457
+ /** 处理了偏移量后的z-index值 */
458
+ zIndex: number;
459
+ /** 原始z-index值 */
460
+ originZIndex: number;
461
+ /** 拥有最大z-index的元素 */
462
+ node: HTMLElement | null;
463
+ /** 目标坐标元素 */
464
+ positionNode: HTMLElement;
465
+ /** x坐标 */
466
+ positionX: number;
467
+ /** y坐标 */
468
+ positionY: number;
469
+ }[];
470
+ getMaxZIndexNodeInfoFromPoint(
471
+ $el?: IFunction<HTMLElement | HTMLElement[] | number>,
472
+ deviation?: number
473
+ ): {
474
+ /** 处理了偏移量后的z-index值 */
475
+ zIndex: number;
476
+ /** 原始z-index值 */
477
+ originZIndex: number;
478
+ /** 拥有最大z-index的元素 */
479
+ node: HTMLElement | null;
480
+ /** 目标坐标元素 */
481
+ positionNode: HTMLElement;
482
+ /** x坐标 */
483
+ positionX: number;
484
+ /** y坐标 */
485
+ positionY: number;
486
+ }[] {
487
+ if (typeof $el === "function") {
488
+ $el = $el();
489
+ }
490
+ if (typeof $el === "number") {
491
+ deviation = $el;
492
+ $el = void 0;
493
+ }
494
+ if (typeof deviation !== "number" || Number.isNaN(deviation)) {
495
+ deviation = 10;
496
+ }
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
+ ];
524
+ if ($el) {
525
+ delayHandlerElementPostionList.length = 0;
526
+ if (Array.isArray($el)) {
527
+ delayHandlerElementPostionList.push(...$el);
528
+ } else {
529
+ delayHandlerElementPostionList.push($el);
530
+ }
531
+ }
532
+ const positionInfoList = delayHandlerElementPostionList
533
+ .map((position) => {
534
+ let positionNode: Element | null;
535
+ let positionX: number;
536
+ let positionY: number;
537
+ if (position instanceof HTMLElement) {
538
+ positionNode = position;
539
+ const nodeRect = position.getBoundingClientRect();
540
+ positionX = nodeRect.x + nodeRect.width / 2;
541
+ positionY = nodeRect.y + nodeRect.height / 2;
542
+ } else {
543
+ positionNode = document.elementFromPoint(position.x, position.y);
544
+ positionX = position.x;
545
+ positionY = position.y;
546
+ }
547
+ const shadowRoot = positionNode?.shadowRoot;
548
+ if (shadowRoot) {
549
+ positionNode = shadowRoot.elementFromPoint(positionX, positionY);
550
+ }
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
+ let zIndex = 0;
558
+ let maxZIndexNode: HTMLElement | null = null;
559
+ while (parent) {
560
+ const nodeStyle = globalThis.getComputedStyle(parent);
561
+ const nodeZIndex = parseInt(nodeStyle.zIndex);
562
+ if (nodeStyle.position !== "static" && !isNaN(nodeZIndex)) {
563
+ if (nodeZIndex > zIndex) {
564
+ zIndex = nodeZIndex;
565
+ maxZIndexNode = parent;
566
+ }
567
+ }
568
+ parent = parent.parentElement;
569
+ }
570
+ return {
571
+ /** 处理了偏移量后的z-index值 */
572
+ zIndex: zIndex + deviation,
573
+ /** 原始z-index值 */
574
+ originZIndex: zIndex,
575
+ /** 拥有最大z-index的元素 */
576
+ node: maxZIndexNode,
577
+ /** 目标坐标元素 */
578
+ positionNode: positionNode,
579
+ /** x坐标 */
580
+ positionX: positionX,
581
+ /** y坐标 */
582
+ positionY: positionY,
583
+ };
584
+ })
585
+ .filter((it) => it != null);
586
+ // 降序排序
587
+ positionInfoList.sort((a, b) => {
588
+ if (a.zIndex < b.zIndex) {
589
+ return 1;
590
+ } else if (a.zIndex > b.zIndex) {
591
+ return -1;
592
+ } else {
593
+ return 0;
594
+ }
595
+ });
596
+ return positionInfoList;
597
+ }
404
598
  }
405
599
 
406
600
  const popsUtils = new PopsUtils();