parent
9bde5b212e
commit
13cc14f971
@ -0,0 +1,17 @@
|
|||||||
|
type StyleRecord = Record<string, string | number | null | undefined>;
|
||||||
|
|
||||||
|
function serializeStyle(style: unknown): string {
|
||||||
|
if (!style) return '';
|
||||||
|
if (typeof style === 'string') return style.trim();
|
||||||
|
if (typeof style !== 'object') return '';
|
||||||
|
|
||||||
|
return Object.entries(style as StyleRecord)
|
||||||
|
.filter(([, value]) => value !== undefined && value !== null)
|
||||||
|
.map(([name, value]) => `${name}: ${value};`)
|
||||||
|
.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function composeInlineStyle(...styles: unknown[]): string | undefined {
|
||||||
|
const parts = styles.map(serializeStyle).filter(Boolean);
|
||||||
|
return parts.length ? parts.join(' ') : undefined;
|
||||||
|
}
|
||||||
Loading…
Reference in new issue