@whitesev/pops 2.1.8 → 2.1.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.
@@ -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
  /**