clipper: inline styles if cssRules.length > 0

Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
This commit is contained in:
01zulfi
2025-06-12 13:52:10 +05:00
committed by Abdullah Atta
parent fd64c1cf2d
commit 5e5930e9e8

View File

@@ -97,8 +97,26 @@ export async function addStylesToHead(
if (styleNode) {
head.appendChild(styleNode);
}
} else if (node instanceof HTMLStyleElement) {
continue;
}
if (sheet.cssRules.length) {
const styleNode = rulesToStyleNode(sheet.cssRules);
head.appendChild(styleNode);
continue;
}
if (node instanceof HTMLStyleElement) {
head.appendChild(node.cloneNode(true));
}
}
}
function rulesToStyleNode(cssRules: CSSRuleList) {
const cssText = Array.from(cssRules)
.map((r) => r.cssText)
.reduce((acc, text) => acc + text);
const style = document.createElement("style");
style.innerHTML = cssText;
return style;
}