dsh-jiuling-remote-mobile 1.0.2 → 1.0.4

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 (3) hide show
  1. package/lib/client.js +36 -0
  2. package/lib/index.js +692 -566
  3. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -88,6 +88,42 @@ window.__ModuleLoader__.load({
88
88
  err: 'padding:10px 16px;font-size:12px;color:var(--dsw-alias-state-error-primary,#ff6b6b);word-break:break-all;',
89
89
  };
90
90
 
91
+ /**
92
+ * 把 CSS 文本解析成 React 的 style **对象**。
93
+ *
94
+ * ⚠️ **这一步不能省**:React 的 `style` prop 只接受对象,给字符串会当场抛
95
+ * `Minified React error #62`(React 18 的
96
+ * `if (style != null && typeof style != "object") throw Error(62)`),
97
+ * 组件随即被 slot 系统 `abdicate` 退役、渲染回落到官方对话框 ——
98
+ * 表现就是「电脑」页签根本不出现,而控制台里只有一条难懂的 #62。
99
+ *
100
+ * 键名同时做 kebab → camelCase(`min-width` → `minWidth`),否则 React
101
+ * 会逐条告警「Unsupported style property」。
102
+ *
103
+ * @param text - 形如 `'a:1;b:2;'` 的 CSS 声明串。
104
+ * @returns React style 对象。
105
+ */
106
+ function toStyle(text) {
107
+ var out = {};
108
+ var parts = String(text).split(';');
109
+ for (var index = 0; index < parts.length; index += 1) {
110
+ var part = parts[index];
111
+ if (part === '') continue;
112
+ var colon = part.indexOf(':');
113
+ if (colon < 0) continue;
114
+ var name = part.slice(0, colon).trim();
115
+ var value = part.slice(colon + 1).trim();
116
+ if (name === '' || value === '') continue;
117
+ out[name.replace(/-([a-z])/g, function (match, letter) {
118
+ return letter.toUpperCase();
119
+ })] = value;
120
+ }
121
+ return out;
122
+ }
123
+
124
+ // 就地转成对象:下游一律写 `style: CSS.xxx`,不会再碰到字符串形式。
125
+ for (var styleKey in CSS) CSS[styleKey] = toStyle(CSS[styleKey]);
126
+
91
127
  /**
92
128
  * 调宿主桥的一条 RPC(令牌只在引擎进程里,浏览器侧不持有)。
93
129
  *