Skip to content

Commit

Permalink
Copy adoptedStyleSheets async.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardasB committed Sep 3, 2024
1 parent 1fcb402 commit 0a54160
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ui/appui-react/src/appui-react/childwindow/CopyStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ export async function copyStyles(
// Adopted stylesheet have no ownerNode and can't be shared between multiple documents.
if (!targetDoc.defaultView) return;
const newStyleSheet = new targetDoc.defaultView.CSSStyleSheet();
Array.from(styleSheet.cssRules).forEach((rule, index) => {
// `cssText` might not serialize complex shorthand properties correctly: https://github.com/iTwin/appui/issues/893
newStyleSheet.insertRule(rule.cssText, index);
});
promises.push(
newStyleSheet.replace(stringifyStyleSheet(styleSheet)).then(() => {})
);
targetDoc.adoptedStyleSheets.push(newStyleSheet);
});

Expand All @@ -55,3 +54,9 @@ export async function copyStyles(

return Promise.all(promises);
}

function stringifyStyleSheet(stylesheet: CSSStyleSheet) {
return Array.from(stylesheet.cssRules)
.map((rule) => rule.cssText)
.join("\n");
}

0 comments on commit 0a54160

Please sign in to comment.