From 0be421991b2960699b5049ab705524fe9f7721a5 Mon Sep 17 00:00:00 2001 From: Volodymyr Baydalka Date: Wed, 22 May 2024 00:35:33 +0300 Subject: [PATCH] Minor changes --- src/docx-preview.ts | 3 +-- src/html-renderer.ts | 14 ++++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/docx-preview.ts b/src/docx-preview.ts index 22b9581..699974b 100644 --- a/src/docx-preview.ts +++ b/src/docx-preview.ts @@ -50,8 +50,7 @@ export function parseAsync(data: Blob | any, userOptions?: Partial): Pr export async function renderDocument(document: any, bodyContainer: HTMLElement, styleContainer?: HTMLElement, userOptions?: Partial): Promise { const ops = { ...defaultOptions, ...userOptions }; const renderer = new HtmlRenderer(window.document); - renderer.render(document, bodyContainer, styleContainer, ops); - return Promise.allSettled(renderer.tasks); + return await renderer.render(document, bodyContainer, styleContainer, ops); } export async function renderAsync(data: Blob | any, bodyContainer: HTMLElement, styleContainer?: HTMLElement, userOptions?: Partial): Promise { diff --git a/src/html-renderer.ts b/src/html-renderer.ts index 1610b80..b83afae 100644 --- a/src/html-renderer.ts +++ b/src/html-renderer.ts @@ -64,7 +64,6 @@ export class HtmlRenderer { defaultTabSize: string; currentTabs: any[] = []; - tabsTimeout: any = 0; commentHighlight: any; commentMap: Record = {}; @@ -75,7 +74,7 @@ export class HtmlRenderer { constructor(public htmlDocument: Document) { } - render(document: WordDocument, bodyContainer: HTMLElement, styleContainer: HTMLElement = null, options: Options) { + async render(document: WordDocument, bodyContainer: HTMLElement, styleContainer: HTMLElement = null, options: Options) { this.document = document; this.options = options; this.className = options.className; @@ -142,9 +141,11 @@ export class HtmlRenderer { (CSS as any).highlights.set(`${this.className}-comments`, this.commentHighlight); } - this.refreshTabStops(); - this.postRenderTasks.forEach(t => t()); + + await Promise.allSettled(this.tasks); + + this.refreshTabStops(); } renderTheme(themePart: ThemePart, styleContainer: HTMLElement) { @@ -193,7 +194,6 @@ export class HtmlRenderer { appendComment(styleContainer, `docxjs ${f.name} font`); const cssText = this.styleToString("@font-face", cssValues); styleContainer.appendChild(createStyleElement(cssText)); - this.refreshTabStops(); })); } } @@ -1485,9 +1485,7 @@ section.${c}>footer { z-index: 1; } if (!this.options.experimental) return; - clearTimeout(this.tabsTimeout); - - this.tabsTimeout = setTimeout(() => { + setTimeout(() => { const pixelToPoint = computePixelToPoint(); for (let tab of this.currentTabs) {