Skip to content

Commit

Permalink
support CSSStyleSheet export
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefED committed Oct 3, 2023
1 parent be621dc commit afa4b38
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,27 @@ export const DefaultOutputVisualizer = (props: {
if (styleElement) {
styleElement.ownerNode?.remove();
setStyleElement(undefined);
document.adoptedStyleSheets = document.adoptedStyleSheets.filter(
(sheet) => sheet !== styleElement,
);
}

if (mainExport instanceof HTMLStyleElement) {
document.head.appendChild(mainExport);
const sheet = findStyleSheet(mainExport);
if (!sheet) {
throw new Error("css sheet not found");
if (
mainExport instanceof HTMLStyleElement ||
mainExport instanceof CSSStyleSheet
) {
let sheet = mainExport;

if (sheet instanceof HTMLStyleElement) {
document.head.appendChild(sheet);
const foundSheet = findStyleSheet(sheet);
if (!foundSheet) {
throw new Error("css sheet not found");
}
sheet = foundSheet;
} else {
// add CSSSTyleSheet sheet to document
document.adoptedStyleSheets.push(sheet);
}
// based on: https://stackoverflow.com/a/33237161/194651
const rules = sheet.cssRules;
Expand Down

0 comments on commit afa4b38

Please sign in to comment.