Repository: mozilla/pdf.js
File: web/pdf_page_view.js (JavaScript)

Code before:
      if (this.drawLayer) {
        this.drawLayer.cancel();
        this.drawLayer = null;
      }
      this.annotationEditorLayer.cancel();
      this.annotationEditorLayer = null;
    }
    if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
      this.xfaLayer.cancel();
      this.xfaLayer = null;
      this._textHighlighter?.disable();
    }
  }

  cssTransform({
    redrawAnnotationLayer = false,
    redrawAnnotationEditorLayer = false,
    redrawXfaLayer = false,
    redrawTextLayer = false,
    hideTextLayer = false,
  }) {
    const { canvas } = this;
    if (!canvas) {
      return;
    }
    if (!canvas.hasAttribute("zooming")) {
      canvas.setAttribute("zooming", true);
      const { style } = canvas;
      style.width = style.height = "";
    }

    const originalViewport = this.#viewportMap.get(canvas);
    if (this.viewport !== originalViewport) {
      // The canvas may have been originally rotated; rotate relative to that.
      const relativeRotation =
        this.viewport.rotation - originalViewport.rotation;
      const absRotation = Math.abs(relativeRotation);
      if (absRotation === 90 || absRotation === 270) {
        const { width, height } = this.viewport;
        // Scale x and y because of the rotation.
        const scaleX = height / width;
        const scaleY = width / height;
        canvas.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX},${scaleY})`;
      } else if (absRotation === 180) {
        canvas.style.transform = `rotate(${relativeRotation}deg)`;
      }
    }

    if (redrawAnnotationLayer && this.annotationLayer) {
      this.#renderAnnotationLayer();
    }

Review comment (suggestion):
Not directly related to this patch, but I wonder if we still need the following CSS rule?
https://github.com/mozilla/pdf.js/blob/a4eb8407c1b3695be0d1f91791f393655b476dd9/web/pdf_viewer.css#L95-L98
Note that since a little while back, all `canvas`es have those properties set:
https://github.com/mozilla/pdf.js/blob/a4eb8407c1b3695be0d1f91791f393655b476dd9/web/pdf_viewer.css#L88-L89

Code after:
      if (this.drawLayer) {
        this.drawLayer.cancel();
        this.drawLayer = null;
      }
      this.annotationEditorLayer.cancel();
      this.annotationEditorLayer = null;
    }
    if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) {
      this.xfaLayer.cancel();
      this.xfaLayer = null;
      this._textHighlighter?.disable();
    }
  }

  cssTransform({
    redrawAnnotationLayer = false,
    redrawAnnotationEditorLayer = false,
    redrawXfaLayer = false,
    redrawTextLayer = false,
    hideTextLayer = false,
  }) {
    const { canvas } = this;
    if (!canvas) {
      return;
    }

    const originalViewport = this.#originalViewport;
    if (this.viewport !== originalViewport) {
      // The canvas may have been originally rotated; rotate relative to that.
      const relativeRotation =
        (360 + this.viewport.rotation - originalViewport.rotation) % 360;
      if (relativeRotation === 90 || relativeRotation === 270) {
        const { width, height } = this.viewport;
        // Scale x and y because of the rotation.
        const scaleX = height / width;
        const scaleY = width / height;
        canvas.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX},${scaleY})`;
      } else {
        canvas.style.transform =
          relativeRotation === 0 ? "" : `rotate(${relativeRotation}deg)`;
      }
    }

    if (redrawAnnotationLayer && this.annotationLayer) {
      this.#renderAnnotationLayer();
    }
    if (redrawAnnotationEditorLayer && this.annotationEditorLayer) {
      if (this.drawLayer) {
        this.#renderDrawLayer();
      }
      this.#renderAnnotationEditorLayer();