fix(cv): wait for usable layout before preview pagination

This commit is contained in:
cesnimda
2026-10-10 21:55:01 +02:00
parent 57054349ef
commit c22f3fc753
2 changed files with 17 additions and 0 deletions
+7
View File
@@ -6,6 +6,13 @@ export function previewDocumentHtml(html: string, fallbackHeightPx: number, page
const page=document.querySelector('.page');if(!page)return;
await document.fonts.ready;
await Promise.all(Array.from(document.images).map(image=>image.decode().catch(()=>{})));
// Visible-page frames can start inside the compact editor's hidden pane.
if(!page.getBoundingClientRect().width)await new Promise(resolve=>{
const observer=new ResizeObserver(()=>{
if(page.getBoundingClientRect().width){observer.disconnect();resolve();}
});
observer.observe(page);
});
const width=page.getBoundingClientRect().width;
const height=parseFloat(getComputedStyle(page).minHeight)||${fallbackHeightPx};
const margin=parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--cv-page-margin'))*96/25.4;