Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
VolodymyrBaydalka committed May 21, 2024
1 parent 4e700ac commit 0be4219
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/docx-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ export function parseAsync(data: Blob | any, userOptions?: Partial<Options>): Pr
export async function renderDocument(document: any, bodyContainer: HTMLElement, styleContainer?: HTMLElement, userOptions?: Partial<Options>): Promise<any> {
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<Options>): Promise<any> {
Expand Down
14 changes: 6 additions & 8 deletions src/html-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export class HtmlRenderer {

defaultTabSize: string;
currentTabs: any[] = [];
tabsTimeout: any = 0;

commentHighlight: any;
commentMap: Record<string, Range> = {};
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}));
}
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0be4219

Please sign in to comment.