Merge pull request #15884 from Snuffleupagus/enable-defaultZoomDelay

Enable the `defaultZoomDelay` option/preference unconditionally, and other (small) improvements
This commit is contained in:
Jonas Jenwald 2023-01-02 15:38:29 +01:00 committed by GitHub
commit 1ba6e9437c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

@ -70,8 +70,7 @@ const defaultOptions = {
}, },
defaultZoomDelay: { defaultZoomDelay: {
/** @type {number} */ /** @type {number} */
value: value: 400,
typeof PDFJSDev === "undefined" || !PDFJSDev.test("GENERIC") ? 400 : -1,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE, kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
}, },
defaultZoomValue: { defaultZoomValue: {

View File

@ -230,20 +230,13 @@ class PDFViewer {
); );
} }
this.container = options.container; this.container = options.container;
this.#resizeObserver.observe(this.container);
this.viewer = options.viewer || options.container.firstElementChild; this.viewer = options.viewer || options.container.firstElementChild;
if ( if (
typeof PDFJSDev === "undefined" || typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC") PDFJSDev.test("!PRODUCTION || GENERIC")
) { ) {
if ( if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") {
!(
this.container?.tagName.toUpperCase() === "DIV" &&
this.viewer?.tagName.toUpperCase() === "DIV"
)
) {
throw new Error("Invalid `container` and/or `viewer` option."); throw new Error("Invalid `container` and/or `viewer` option.");
} }
@ -254,6 +247,8 @@ class PDFViewer {
throw new Error("The `container` must be absolutely positioned."); throw new Error("The `container` must be absolutely positioned.");
} }
} }
this.#resizeObserver.observe(this.container);
this.eventBus = options.eventBus; this.eventBus = options.eventBus;
this.linkService = options.linkService || new SimpleLinkService(); this.linkService = options.linkService || new SimpleLinkService();
this.downloadManager = options.downloadManager || null; this.downloadManager = options.downloadManager || null;
@ -2001,6 +1996,9 @@ class PDFViewer {
* @param {Object|null} [options] * @param {Object|null} [options]
*/ */
increaseScale(steps = 1, options = null) { increaseScale(steps = 1, options = null) {
if (!this.pdfDocument) {
return;
}
let newScale = this._currentScale; let newScale = this._currentScale;
do { do {
newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2); newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
@ -2019,6 +2017,9 @@ class PDFViewer {
* @param {Object|null} [options] * @param {Object|null} [options]
*/ */
decreaseScale(steps = 1, options = null) { decreaseScale(steps = 1, options = null) {
if (!this.pdfDocument) {
return;
}
let newScale = this._currentScale; let newScale = this._currentScale;
do { do {
newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2); newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);