fix(cv): wait for usable layout before preview pagination
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user