Validate the options before adding the ResizeObserver in the PDFViewer constructor (PR 15830 follow-up)

In the GENERIC viewer, it doesn't make sense to register the `ResizeObserver` if the `container`/`viewer` options are not valid.
This commit is contained in:
Jonas Jenwald 2023-01-02 14:10:36 +01:00
parent 0860a5b168
commit 9089e75cce

View File

@ -230,20 +230,13 @@ class PDFViewer {
);
}
this.container = options.container;
this.#resizeObserver.observe(this.container);
this.viewer = options.viewer || options.container.firstElementChild;
if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")
) {
if (
!(
this.container?.tagName.toUpperCase() === "DIV" &&
this.viewer?.tagName.toUpperCase() === "DIV"
)
) {
if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
throw new Error("Invalid `container` and/or `viewer` option.");
}
@ -254,6 +247,8 @@ class PDFViewer {
throw new Error("The `container` must be absolutely positioned.");
}
}
this.#resizeObserver.observe(this.container);
this.eventBus = options.eventBus;
this.linkService = options.linkService || new SimpleLinkService();
this.downloadManager = options.downloadManager || null;