From 0a5416059e448552efde6d8f0f4d17491a57b1fb Mon Sep 17 00:00:00 2001 From: GerardasB <10091419+GerardasB@users.noreply.github.com> Date: Tue, 3 Sep 2024 23:22:40 +0300 Subject: [PATCH] Copy adoptedStyleSheets async. --- .../src/appui-react/childwindow/CopyStyles.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ui/appui-react/src/appui-react/childwindow/CopyStyles.ts b/ui/appui-react/src/appui-react/childwindow/CopyStyles.ts index 4e1903b57a0..1377f30bed1 100644 --- a/ui/appui-react/src/appui-react/childwindow/CopyStyles.ts +++ b/ui/appui-react/src/appui-react/childwindow/CopyStyles.ts @@ -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); }); @@ -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"); +}