ph-utils 0.10.0 → 0.10.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.
- package/lib/dom.d.ts +6 -0
- package/lib/dom.js +24 -0
- package/package.json +1 -1
package/lib/dom.d.ts
CHANGED
@@ -151,6 +151,12 @@ export declare function isMobile(): boolean;
|
|
151
151
|
* @returns 格式化后的类名字符串
|
152
152
|
*/
|
153
153
|
export declare function formatClass(classObj: (boolean | string | undefined | null)[] | Record<string, boolean | string | undefined | null>): string;
|
154
|
+
/**
|
155
|
+
* 将样式对象格式化为 CSS 样式字符串。
|
156
|
+
* @param styleObj - 样式对象,可以是字符串数组或键值对对象。
|
157
|
+
* @returns 格式化后的 CSS 样式字符串。
|
158
|
+
*/
|
159
|
+
export declare function formatStyle(styleObj: (string | undefined | null | "")[] | Record<string, string>): string;
|
154
160
|
/**
|
155
161
|
* 在下一个动画帧执行回调函数。
|
156
162
|
* @param cb - 要在下一个动画帧执行的回调函数。
|
package/lib/dom.js
CHANGED
@@ -316,6 +316,30 @@ export function formatClass(classObj) {
|
|
316
316
|
}
|
317
317
|
return classes.trim();
|
318
318
|
}
|
319
|
+
/**
|
320
|
+
* 将样式对象格式化为 CSS 样式字符串。
|
321
|
+
* @param styleObj - 样式对象,可以是字符串数组或键值对对象。
|
322
|
+
* @returns 格式化后的 CSS 样式字符串。
|
323
|
+
*/
|
324
|
+
export function formatStyle(styleObj) {
|
325
|
+
let styleStr = "";
|
326
|
+
if (Array.isArray(styleObj)) {
|
327
|
+
for (let i = 0, len = styleObj.length; i < len; i++) {
|
328
|
+
const item = styleObj[i];
|
329
|
+
if (item) {
|
330
|
+
styleStr += `${item};`;
|
331
|
+
}
|
332
|
+
}
|
333
|
+
}
|
334
|
+
else {
|
335
|
+
for (const key in styleObj) {
|
336
|
+
if (styleObj[key]) {
|
337
|
+
styleStr += `${key}:${styleObj[key]};`;
|
338
|
+
}
|
339
|
+
}
|
340
|
+
}
|
341
|
+
return styleStr;
|
342
|
+
}
|
319
343
|
/**
|
320
344
|
* 在下一个动画帧执行回调函数。
|
321
345
|
* @param cb - 要在下一个动画帧执行的回调函数。
|