Clean-up the PDFViewer.{increaseScale, decreaseScale} methods
				
					
				
			The signatures of these methods were changed in PR 15886, which has now been included in a couple of releases, hence it should hopefully be OK to remove the fallback code-paths now. Also, the methods are updated slightly to be explicit about what options are supported and we'll no longer pass along any arbitrary options to the "private" methods.
This commit is contained in:
		
							parent
							
								
									9db4509664
								
							
						
					
					
						commit
						9060757064
					
				@ -2003,83 +2003,58 @@ class PDFViewer {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Increase the current zoom level one, or more, times.
 | 
					   * @typedef {Object} ChangeScaleOptions
 | 
				
			||||||
   * @param {Object|null} [options]
 | 
					   * @property {number} [drawingDelay]
 | 
				
			||||||
 | 
					   * @property {number} [scaleFactor]
 | 
				
			||||||
 | 
					   * @property {number} [steps]
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  increaseScale(options = null) {
 | 
					 | 
				
			||||||
    if (
 | 
					 | 
				
			||||||
      (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
 | 
					 | 
				
			||||||
      typeof options === "number"
 | 
					 | 
				
			||||||
    ) {
 | 
					 | 
				
			||||||
      console.error(
 | 
					 | 
				
			||||||
        "The `increaseScale` method-signature was updated, please use an object instead."
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
      options = { steps: options };
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * Increase the current zoom level one, or more, times.
 | 
				
			||||||
 | 
					   * @param {ChangeScaleOptions} [options]
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  increaseScale({ drawingDelay, scaleFactor, steps } = {}) {
 | 
				
			||||||
    if (!this.pdfDocument) {
 | 
					    if (!this.pdfDocument) {
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    options ||= Object.create(null);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let newScale = this._currentScale;
 | 
					    let newScale = this._currentScale;
 | 
				
			||||||
    if (options.scaleFactor > 1) {
 | 
					    if (scaleFactor > 1) {
 | 
				
			||||||
      newScale = Math.min(
 | 
					      newScale = Math.min(
 | 
				
			||||||
        MAX_SCALE,
 | 
					        MAX_SCALE,
 | 
				
			||||||
        Math.round(newScale * options.scaleFactor * 100) / 100
 | 
					        Math.round(newScale * scaleFactor * 100) / 100
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      let steps = options.steps ?? 1;
 | 
					      steps ??= 1;
 | 
				
			||||||
      do {
 | 
					      do {
 | 
				
			||||||
        newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
 | 
					        newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
 | 
				
			||||||
        newScale = Math.ceil(newScale * 10) / 10;
 | 
					        newScale = Math.min(MAX_SCALE, Math.ceil(newScale * 10) / 10);
 | 
				
			||||||
        newScale = Math.min(MAX_SCALE, newScale);
 | 
					 | 
				
			||||||
      } while (--steps > 0 && newScale < MAX_SCALE);
 | 
					      } while (--steps > 0 && newScale < MAX_SCALE);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    this._setScale(newScale, { noScroll: false, drawingDelay });
 | 
				
			||||||
    options.noScroll = false;
 | 
					 | 
				
			||||||
    this._setScale(newScale, options);
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Decrease the current zoom level one, or more, times.
 | 
					   * Decrease the current zoom level one, or more, times.
 | 
				
			||||||
   * @param {Object|null} [options]
 | 
					   * @param {ChangeScaleOptions} [options]
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  decreaseScale(options = null) {
 | 
					  decreaseScale({ drawingDelay, scaleFactor, steps } = {}) {
 | 
				
			||||||
    if (
 | 
					 | 
				
			||||||
      (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
 | 
					 | 
				
			||||||
      typeof options === "number"
 | 
					 | 
				
			||||||
    ) {
 | 
					 | 
				
			||||||
      console.error(
 | 
					 | 
				
			||||||
        "The `decreaseScale` method-signature was updated, please use an object instead."
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
      options = { steps: options };
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (!this.pdfDocument) {
 | 
					    if (!this.pdfDocument) {
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    options ||= Object.create(null);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let newScale = this._currentScale;
 | 
					    let newScale = this._currentScale;
 | 
				
			||||||
    if (options.scaleFactor > 0 && options.scaleFactor < 1) {
 | 
					    if (scaleFactor > 0 && scaleFactor < 1) {
 | 
				
			||||||
      newScale = Math.max(
 | 
					      newScale = Math.max(
 | 
				
			||||||
        MIN_SCALE,
 | 
					        MIN_SCALE,
 | 
				
			||||||
        Math.round(newScale * options.scaleFactor * 100) / 100
 | 
					        Math.round(newScale * scaleFactor * 100) / 100
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      let steps = options.steps ?? 1;
 | 
					      steps ??= 1;
 | 
				
			||||||
      do {
 | 
					      do {
 | 
				
			||||||
        newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
 | 
					        newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
 | 
				
			||||||
        newScale = Math.floor(newScale * 10) / 10;
 | 
					        newScale = Math.max(MIN_SCALE, Math.floor(newScale * 10) / 10);
 | 
				
			||||||
        newScale = Math.max(MIN_SCALE, newScale);
 | 
					 | 
				
			||||||
      } while (--steps > 0 && newScale > MIN_SCALE);
 | 
					      } while (--steps > 0 && newScale > MIN_SCALE);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    this._setScale(newScale, { noScroll: false, drawingDelay });
 | 
				
			||||||
    options.noScroll = false;
 | 
					 | 
				
			||||||
    this._setScale(newScale, options);
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  #updateContainerHeightCss(height = this.container.clientHeight) {
 | 
					  #updateContainerHeightCss(height = this.container.clientHeight) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user