1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #18689 from Snuffleupagus/StructTreeLayerBuilder-render-caching

Improve the `StructTreeLayerBuilder.render` method
This commit is contained in:
calixteman 2024-09-04 14:07:18 +02:00 committed by GitHub
commit 4fb045b9eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -76,7 +76,9 @@ const HEADING_PATTERN = /^H(\d+)$/;
class StructTreeLayerBuilder {
#promise;
#treeDom = undefined;
#treeDom = null;
#treePromise;
#elementAttributes = new Map();
@ -85,13 +87,23 @@ class StructTreeLayerBuilder {
}
async render() {
if (this.#treeDom !== undefined) {
return this.#treeDom;
if (this.#treePromise) {
return this.#treePromise;
}
const { promise, resolve, reject } = Promise.withResolvers();
this.#treePromise = promise;
try {
this.#treeDom = this.#walk(await this.#promise);
} catch (ex) {
reject(ex);
}
const treeDom = (this.#treeDom = this.#walk(await this.#promise));
this.#promise = null;
treeDom?.classList.add("structTree");
return treeDom;
this.#treeDom?.classList.add("structTree");
resolve(this.#treeDom);
return promise;
}
async getAriaAttributes(annotationId) {