@whitesev/pops 2.1.8 → 2.1.10

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.
@@ -29,9 +29,18 @@ export const PopsSearchSuggestion = {
29
29
 
30
30
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
31
31
  PopsHandler.handleInit($shadowRoot, [
32
- PopsCSS.index,
33
- PopsCSS.anim,
34
- PopsCSS.common,
32
+ {
33
+ name: "index",
34
+ css: PopsCSS.index,
35
+ },
36
+ {
37
+ name: "anim",
38
+ css: PopsCSS.anim,
39
+ },
40
+ {
41
+ name: "common",
42
+ css: PopsCSS.common,
43
+ },
35
44
  ]);
36
45
 
37
46
  if (config.style != null) {
@@ -613,10 +613,22 @@ export const PopsTooltip = {
613
613
 
614
614
  const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow(config);
615
615
  PopsHandler.handleInit($shadowRoot, [
616
- PopsCSS.index,
617
- PopsCSS.anim,
618
- PopsCSS.common,
619
- PopsCSS.tooltipCSS,
616
+ {
617
+ name: "index",
618
+ css: PopsCSS.index,
619
+ },
620
+ {
621
+ name: "anim",
622
+ css: PopsCSS.anim,
623
+ },
624
+ {
625
+ name: "common",
626
+ css: PopsCSS.common,
627
+ },
628
+ {
629
+ name: "tooltipCSS",
630
+ css: PopsCSS.tooltipCSS,
631
+ },
620
632
  ]);
621
633
 
622
634
  let toolTip = new ToolTip(config, guid, {
package/src/css/index.css CHANGED
@@ -13,6 +13,7 @@
13
13
  --pops-bd-opacity: 1;
14
14
  --pops-font-size: 16px;
15
15
  interpolate-size: allow-keywords;
16
+ --pops-color: #000000;
16
17
  --pops-bg-color: rgb(255, 255, 255, var(--pops-bg-opacity));
17
18
  --pops-bd-color: rgb(235, 238, 245, var(--pops-bd-opacity));
18
19
  --pops-box-shadow-color: rgba(0, 0, 0, 0.12);
@@ -29,6 +30,7 @@
29
30
  @media (prefers-color-scheme: dark) {
30
31
  .pops {
31
32
  --pops-mask-bg-opacity: 0.8;
33
+ --pops-color: #ffffff;
32
34
  --pops-bg-color: rgb(17, 17, 17, var(--pops-bg-opacity));
33
35
  --pops-bd-color: rgb(55, 55, 55, var(--pops-bd-opacity));
34
36
  --pops-box-shadow-color: rgba(81, 81, 81, 0.12);
@@ -38,6 +40,7 @@
38
40
  }
39
41
  }
40
42
  .pops {
43
+ color: var(--pops-color);
41
44
  background-color: var(--pops-bg-color);
42
45
  border: 1px solid var(--pops-bd-color);
43
46
  border-radius: 4px;
@@ -44,32 +44,63 @@ export const PopsHandler = {
44
44
  },
45
45
  /**
46
46
  * 处理初始化
47
- * @param $shadowRoot 所在的shadowRoot
48
- * @param cssText 添加进ShadowRoot的CSS
47
+ * @param $styleParent style元素的父元素
48
+ * @param css 添加进ShadowRoot的CSS
49
49
  */
50
50
  handleInit(
51
- $shadowRoot?: ShadowRoot | HTMLElement,
52
- cssText?: string | string[]
51
+ $styleParent?: ShadowRoot | HTMLElement,
52
+ css?:
53
+ | string
54
+ | string[]
55
+ | {
56
+ name?: string;
57
+ css: string;
58
+ }[]
53
59
  ) {
54
60
  PopsAnimation.init();
55
61
  if (!arguments.length) {
56
62
  return;
57
63
  }
58
- if (Array.isArray(cssText)) {
59
- for (let index = 0; index < cssText.length; index++) {
60
- this.handleInit($shadowRoot, cssText[index]);
64
+ if ($styleParent == null) {
65
+ return;
66
+ }
67
+ if (css == null) {
68
+ return;
69
+ }
70
+
71
+ if (typeof css === "string") {
72
+ if (css.trim() === "") {
73
+ return;
61
74
  }
75
+ css = [
76
+ {
77
+ css: css,
78
+ },
79
+ ];
62
80
  } else {
81
+ css = css.map((item) => {
82
+ if (typeof item === "string") {
83
+ return {
84
+ css: item,
85
+ };
86
+ } else {
87
+ return item;
88
+ }
89
+ });
90
+ }
91
+ for (const cssItem of css) {
63
92
  let $css = popsDOMUtils.createElement(
64
93
  "style",
65
- {
66
- innerHTML: cssText,
67
- },
94
+ {},
68
95
  {
69
96
  "data-type": "PopsHandler.handleInit",
70
97
  }
71
98
  );
72
- $shadowRoot!.appendChild($css);
99
+ $css.textContent = cssItem.css;
100
+ if (typeof cssItem.name === "string") {
101
+ $css.setAttribute("data-name", cssItem.name);
102
+ }
103
+ $styleParent.appendChild($css);
73
104
  }
74
105
  },
75
106
  /**
@@ -2517,6 +2517,119 @@ class PopsDOMUtils extends PopsDOMUtilsEvent {
2517
2517
  });
2518
2518
  return result;
2519
2519
  }
2520
+ /**
2521
+ * 颜色转换函数
2522
+ * @method hexToRgb hex 颜色转 rgb 颜色
2523
+ * @method rgbToHex rgb 颜色转 Hex 颜色
2524
+ * @method getDarkColor 加深颜色值
2525
+ * @method getLightColor 变浅颜色值
2526
+ */
2527
+ calcColor() {
2528
+ function useChangeColor() {
2529
+ /**
2530
+ * hex 颜色转 rgb 颜色
2531
+ */
2532
+ const hexToRgb = (
2533
+ /**
2534
+ * hex 颜色值
2535
+ */
2536
+ str: string
2537
+ ): any => {
2538
+ let hexs: any = "";
2539
+ let reg = /^#(?:[0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
2540
+ if (!reg.test(str)) {
2541
+ console.warn("输入错误的hex");
2542
+ return "";
2543
+ }
2544
+ str = str.replace("#", "");
2545
+ hexs = str.match(/../g);
2546
+ for (let i = 0; i < 3; i++) hexs[i] = parseInt(hexs[i], 16);
2547
+ return hexs;
2548
+ };
2549
+
2550
+ /**
2551
+ * rgb转hex
2552
+ */
2553
+ const rgbToHex = (
2554
+ /**
2555
+ * 红色
2556
+ */
2557
+ r: any,
2558
+ /**
2559
+ * 绿色
2560
+ */
2561
+ g: any,
2562
+ /**
2563
+ * 蓝色
2564
+ */
2565
+ b: any
2566
+ ): string => {
2567
+ let reg = /^\d{1,3}$/;
2568
+ if (!reg.test(r) || !reg.test(g) || !reg.test(b)) {
2569
+ console.warn("输入错误的rgb颜色值");
2570
+ return "";
2571
+ }
2572
+ let hexs = [r.toString(16), g.toString(16), b.toString(16)];
2573
+ for (let i = 0; i < 3; i++)
2574
+ if (hexs[i].length == 1) hexs[i] = `0${hexs[i]}`;
2575
+ return `#${hexs.join("")}`;
2576
+ };
2577
+
2578
+ /**
2579
+ * 获取深色
2580
+ */
2581
+ const getDarkColor = (
2582
+ /**
2583
+ * 颜色值字符串
2584
+ */
2585
+ color: string,
2586
+ /**
2587
+ * 加深的程度,限0-1之间
2588
+ */
2589
+ level: number
2590
+ ): string => {
2591
+ let reg = /^#(?:[0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
2592
+ if (!reg.test(color)) {
2593
+ console.warn("输入错误的hex颜色值");
2594
+ return "";
2595
+ }
2596
+ let rgb = useChangeColor().hexToRgb(color);
2597
+ for (let i = 0; i < 3; i++) rgb[i] = Math.floor(rgb[i] * (1 - level));
2598
+ return useChangeColor().rgbToHex(rgb[0], rgb[1], rgb[2]);
2599
+ };
2600
+
2601
+ /**
2602
+ * 获取颜色变浅后的颜色值
2603
+ */
2604
+ const getLightColor = (
2605
+ /**
2606
+ * 颜色值字符串
2607
+ */
2608
+ color: string,
2609
+ /**
2610
+ * 加深的程度,限0-1之间
2611
+ */
2612
+ level: number
2613
+ ): string => {
2614
+ let reg = /^#(?:[0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/;
2615
+ if (!reg.test(color)) {
2616
+ console.warn("输入错误的hex颜色值");
2617
+ return "";
2618
+ }
2619
+ let rgb = useChangeColor().hexToRgb(color);
2620
+ for (let i = 0; i < 3; i++)
2621
+ rgb[i] = Math.floor((255 - rgb[i]) * level + rgb[i]);
2622
+ return useChangeColor().rgbToHex(rgb[0], rgb[1], rgb[2]);
2623
+ };
2624
+ return {
2625
+ hexToRgb,
2626
+ rgbToHex,
2627
+ getDarkColor,
2628
+ getLightColor,
2629
+ };
2630
+ }
2631
+ return useChangeColor();
2632
+ }
2520
2633
  }
2521
2634
 
2522
2635
  const popsDOMUtils = new PopsDOMUtils();