|
@@ -22,18 +22,7 @@
|
|
/** @typedef {import("./event_utils").EventBus} EventBus */
|
|
/** @typedef {import("./event_utils").EventBus} EventBus */
|
|
/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */
|
|
/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */
|
|
/** @typedef {import("./interfaces").IL10n} IL10n */
|
|
/** @typedef {import("./interfaces").IL10n} IL10n */
|
|
-// eslint-disable-next-line max-len
|
|
|
|
-/** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */
|
|
|
|
-// eslint-disable-next-line max-len
|
|
|
|
-/** @typedef {import("./interfaces").IPDFAnnotationEditorLayerFactory} IPDFAnnotationEditorLayerFactory */
|
|
|
|
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
|
|
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
|
|
-// eslint-disable-next-line max-len
|
|
|
|
-/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */
|
|
|
|
-// eslint-disable-next-line max-len
|
|
|
|
-/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */
|
|
|
|
-/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
|
|
|
|
-// eslint-disable-next-line max-len
|
|
|
|
-/** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */
|
|
|
|
|
|
|
|
import {
|
|
import {
|
|
AnnotationEditorType,
|
|
AnnotationEditorType,
|
|
@@ -69,16 +58,10 @@ import {
|
|
VERTICAL_PADDING,
|
|
VERTICAL_PADDING,
|
|
watchScroll,
|
|
watchScroll,
|
|
} from "./ui_utils.js";
|
|
} from "./ui_utils.js";
|
|
-import { AnnotationEditorLayerBuilder } from "./annotation_editor_layer_builder.js";
|
|
|
|
-import { AnnotationLayerBuilder } from "./annotation_layer_builder.js";
|
|
|
|
import { NullL10n } from "./l10n_utils.js";
|
|
import { NullL10n } from "./l10n_utils.js";
|
|
import { PDFPageView } from "./pdf_page_view.js";
|
|
import { PDFPageView } from "./pdf_page_view.js";
|
|
import { PDFRenderingQueue } from "./pdf_rendering_queue.js";
|
|
import { PDFRenderingQueue } from "./pdf_rendering_queue.js";
|
|
import { SimpleLinkService } from "./pdf_link_service.js";
|
|
import { SimpleLinkService } from "./pdf_link_service.js";
|
|
-import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js";
|
|
|
|
-import { TextHighlighter } from "./text_highlighter.js";
|
|
|
|
-import { TextLayerBuilder } from "./text_layer_builder.js";
|
|
|
|
-import { XfaLayerBuilder } from "./xfa_layer_builder.js";
|
|
|
|
|
|
|
|
const DEFAULT_CACHE_SIZE = 10;
|
|
const DEFAULT_CACHE_SIZE = 10;
|
|
const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
|
|
const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
|
|
@@ -128,6 +111,8 @@ function isValidAnnotationEditorMode(mode) {
|
|
* landscape pages upon printing. The default is `false`.
|
|
* landscape pages upon printing. The default is `false`.
|
|
* @property {boolean} [useOnlyCssZoom] - Enables CSS only zooming. The default
|
|
* @property {boolean} [useOnlyCssZoom] - Enables CSS only zooming. The default
|
|
* value is `false`.
|
|
* value is `false`.
|
|
|
|
+ * @property {boolean} [isOffscreenCanvasSupported] - Allows to use an
|
|
|
|
+ * OffscreenCanvas if needed.
|
|
* @property {number} [maxCanvasPixels] - The maximum supported canvas size in
|
|
* @property {number} [maxCanvasPixels] - The maximum supported canvas size in
|
|
* total pixels, i.e. width * height. Use -1 for no limit. The default value
|
|
* total pixels, i.e. width * height. Use -1 for no limit. The default value
|
|
* is 4096 * 4096 (16 mega-pixels).
|
|
* is 4096 * 4096 (16 mega-pixels).
|
|
@@ -209,12 +194,6 @@ class PDFPageViewBuffer {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Simple viewer control to display PDF content/pages.
|
|
* Simple viewer control to display PDF content/pages.
|
|
- *
|
|
|
|
- * @implements {IPDFAnnotationLayerFactory}
|
|
|
|
- * @implements {IPDFAnnotationEditorLayerFactory}
|
|
|
|
- * @implements {IPDFStructTreeLayerFactory}
|
|
|
|
- * @implements {IPDFTextLayerFactory}
|
|
|
|
- * @implements {IPDFXfaLayerFactory}
|
|
|
|
*/
|
|
*/
|
|
class PDFViewer {
|
|
class PDFViewer {
|
|
#buffer = null;
|
|
#buffer = null;
|
|
@@ -225,14 +204,20 @@ class PDFViewer {
|
|
|
|
|
|
#annotationMode = AnnotationMode.ENABLE_FORMS;
|
|
#annotationMode = AnnotationMode.ENABLE_FORMS;
|
|
|
|
|
|
|
|
+ #containerTopLeft = null;
|
|
|
|
+
|
|
#enablePermissions = false;
|
|
#enablePermissions = false;
|
|
|
|
|
|
#previousContainerHeight = 0;
|
|
#previousContainerHeight = 0;
|
|
|
|
|
|
|
|
+ #resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this));
|
|
|
|
+
|
|
#scrollModePageState = null;
|
|
#scrollModePageState = null;
|
|
|
|
|
|
#onVisibilityChange = null;
|
|
#onVisibilityChange = null;
|
|
|
|
|
|
|
|
+ #scaleTimeoutId = null;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param {PDFViewerOptions} options
|
|
* @param {PDFViewerOptions} options
|
|
*/
|
|
*/
|
|
@@ -252,12 +237,7 @@ class PDFViewer {
|
|
typeof PDFJSDev === "undefined" ||
|
|
typeof PDFJSDev === "undefined" ||
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
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.");
|
|
throw new Error("Invalid `container` and/or `viewer` option.");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -268,12 +248,13 @@ 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;
|
|
this.findController = options.findController || null;
|
|
this.findController = options.findController || null;
|
|
this._scriptingManager = options.scriptingManager || null;
|
|
this._scriptingManager = options.scriptingManager || null;
|
|
- this.removePageBorders = options.removePageBorders || false;
|
|
|
|
this.textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
|
|
this.textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
|
|
this.#annotationMode =
|
|
this.#annotationMode =
|
|
options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
|
|
options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
|
|
@@ -285,9 +266,12 @@ class PDFViewer {
|
|
typeof PDFJSDev === "undefined" ||
|
|
typeof PDFJSDev === "undefined" ||
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
PDFJSDev.test("!PRODUCTION || GENERIC")
|
|
) {
|
|
) {
|
|
|
|
+ this.removePageBorders = options.removePageBorders || false;
|
|
this.renderer = options.renderer || RendererType.CANVAS;
|
|
this.renderer = options.renderer || RendererType.CANVAS;
|
|
}
|
|
}
|
|
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
|
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
|
|
|
+ this.isOffscreenCanvasSupported =
|
|
|
|
+ options.isOffscreenCanvasSupported ?? true;
|
|
this.maxCanvasPixels = options.maxCanvasPixels;
|
|
this.maxCanvasPixels = options.maxCanvasPixels;
|
|
this.l10n = options.l10n || NullL10n;
|
|
this.l10n = options.l10n || NullL10n;
|
|
this.#enablePermissions = options.enablePermissions || false;
|
|
this.#enablePermissions = options.enablePermissions || false;
|
|
@@ -324,10 +308,14 @@ class PDFViewer {
|
|
this._onBeforeDraw = this._onAfterDraw = null;
|
|
this._onBeforeDraw = this._onAfterDraw = null;
|
|
this._resetView();
|
|
this._resetView();
|
|
|
|
|
|
- if (this.removePageBorders) {
|
|
|
|
|
|
+ if (
|
|
|
|
+ (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
|
|
|
+ this.removePageBorders
|
|
|
|
+ ) {
|
|
this.viewer.classList.add("removePageBorders");
|
|
this.viewer.classList.add("removePageBorders");
|
|
}
|
|
}
|
|
- this.updateContainerHeightCss();
|
|
|
|
|
|
+
|
|
|
|
+ this.#updateContainerHeightCss();
|
|
}
|
|
}
|
|
|
|
|
|
get pagesCount() {
|
|
get pagesCount() {
|
|
@@ -467,7 +455,7 @@ class PDFViewer {
|
|
if (!this.pdfDocument) {
|
|
if (!this.pdfDocument) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- this._setScale(val, false);
|
|
|
|
|
|
+ this._setScale(val, { noScroll: false });
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -484,7 +472,7 @@ class PDFViewer {
|
|
if (!this.pdfDocument) {
|
|
if (!this.pdfDocument) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- this._setScale(val, false);
|
|
|
|
|
|
+ this._setScale(val, { noScroll: false });
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -516,14 +504,12 @@ class PDFViewer {
|
|
|
|
|
|
const pageNumber = this._currentPageNumber;
|
|
const pageNumber = this._currentPageNumber;
|
|
|
|
|
|
- const updateArgs = { rotation };
|
|
|
|
- for (const pageView of this._pages) {
|
|
|
|
- pageView.update(updateArgs);
|
|
|
|
- }
|
|
|
|
|
|
+ this.refresh(true, { rotation });
|
|
|
|
+
|
|
// Prevent errors in case the rotation changes *before* the scale has been
|
|
// Prevent errors in case the rotation changes *before* the scale has been
|
|
// set to a non-default value.
|
|
// set to a non-default value.
|
|
if (this._currentScaleValue) {
|
|
if (this._currentScaleValue) {
|
|
- this._setScale(this._currentScaleValue, true);
|
|
|
|
|
|
+ this._setScale(this._currentScaleValue, { noScroll: true });
|
|
}
|
|
}
|
|
|
|
|
|
this.eventBus.dispatch("rotationchanging", {
|
|
this.eventBus.dispatch("rotationchanging", {
|
|
@@ -549,6 +535,36 @@ class PDFViewer {
|
|
return this.pdfDocument ? this._pagesCapability.promise : null;
|
|
return this.pdfDocument ? this._pagesCapability.promise : null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #layerProperties() {
|
|
|
|
+ const self = this;
|
|
|
|
+ return {
|
|
|
|
+ get annotationEditorUIManager() {
|
|
|
|
+ return self.#annotationEditorUIManager;
|
|
|
|
+ },
|
|
|
|
+ get annotationStorage() {
|
|
|
|
+ return self.pdfDocument?.annotationStorage;
|
|
|
|
+ },
|
|
|
|
+ get downloadManager() {
|
|
|
|
+ return self.downloadManager;
|
|
|
|
+ },
|
|
|
|
+ get enableScripting() {
|
|
|
|
+ return !!self._scriptingManager;
|
|
|
|
+ },
|
|
|
|
+ get fieldObjectsPromise() {
|
|
|
|
+ return self.pdfDocument?.getFieldObjects();
|
|
|
|
+ },
|
|
|
|
+ get findController() {
|
|
|
|
+ return self.findController;
|
|
|
|
+ },
|
|
|
|
+ get hasJSActionsPromise() {
|
|
|
|
+ return self.pdfDocument?.hasJSActions();
|
|
|
|
+ },
|
|
|
|
+ get linkService() {
|
|
|
|
+ return self.linkService;
|
|
|
|
+ },
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Currently only *some* permissions are supported.
|
|
* Currently only *some* permissions are supported.
|
|
* @returns {Object}
|
|
* @returns {Object}
|
|
@@ -648,7 +664,6 @@ class PDFViewer {
|
|
if (!pdfDocument) {
|
|
if (!pdfDocument) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- const isPureXfa = pdfDocument.isPureXfa;
|
|
|
|
const pagesCount = pdfDocument.numPages;
|
|
const pagesCount = pdfDocument.numPages;
|
|
const firstPagePromise = pdfDocument.getPage(1);
|
|
const firstPagePromise = pdfDocument.getPage(1);
|
|
// Rendering (potentially) depends on this, hence fetching it immediately.
|
|
// Rendering (potentially) depends on this, hence fetching it immediately.
|
|
@@ -722,12 +737,13 @@ class PDFViewer {
|
|
if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
|
|
if (annotationEditorMode !== AnnotationEditorType.DISABLE) {
|
|
const mode = annotationEditorMode;
|
|
const mode = annotationEditorMode;
|
|
|
|
|
|
- if (isPureXfa) {
|
|
|
|
|
|
+ if (pdfDocument.isPureXfa) {
|
|
console.warn("Warning: XFA-editing is not implemented.");
|
|
console.warn("Warning: XFA-editing is not implemented.");
|
|
} else if (isValidAnnotationEditorMode(mode)) {
|
|
} else if (isValidAnnotationEditorMode(mode)) {
|
|
this.#annotationEditorUIManager = new AnnotationEditorUIManager(
|
|
this.#annotationEditorUIManager = new AnnotationEditorUIManager(
|
|
this.container,
|
|
this.container,
|
|
- this.eventBus
|
|
|
|
|
|
+ this.eventBus,
|
|
|
|
+ pdfDocument?.annotationStorage
|
|
);
|
|
);
|
|
if (mode !== AnnotationEditorType.NONE) {
|
|
if (mode !== AnnotationEditorType.NONE) {
|
|
this.#annotationEditorUIManager.updateMode(mode);
|
|
this.#annotationEditorUIManager.updateMode(mode);
|
|
@@ -737,20 +753,16 @@ class PDFViewer {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ const layerProperties = this.#layerProperties.bind(this);
|
|
const viewerElement =
|
|
const viewerElement =
|
|
this._scrollMode === ScrollMode.PAGE ? null : this.viewer;
|
|
this._scrollMode === ScrollMode.PAGE ? null : this.viewer;
|
|
const scale = this.currentScale;
|
|
const scale = this.currentScale;
|
|
const viewport = firstPdfPage.getViewport({
|
|
const viewport = firstPdfPage.getViewport({
|
|
scale: scale * PixelsPerInch.PDF_TO_CSS_UNITS,
|
|
scale: scale * PixelsPerInch.PDF_TO_CSS_UNITS,
|
|
});
|
|
});
|
|
- const textLayerFactory =
|
|
|
|
- textLayerMode !== TextLayerMode.DISABLE && !isPureXfa ? this : null;
|
|
|
|
- const annotationLayerFactory =
|
|
|
|
- annotationMode !== AnnotationMode.DISABLE ? this : null;
|
|
|
|
- const xfaLayerFactory = isPureXfa ? this : null;
|
|
|
|
- const annotationEditorLayerFactory = this.#annotationEditorUIManager
|
|
|
|
- ? this
|
|
|
|
- : null;
|
|
|
|
|
|
+ // Ensure that the various layers always get the correct initial size,
|
|
|
|
+ // see issue 15795.
|
|
|
|
+ this.viewer.style.setProperty("--scale-factor", viewport.scale);
|
|
|
|
|
|
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
|
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
|
const pageView = new PDFPageView({
|
|
const pageView = new PDFPageView({
|
|
@@ -761,14 +773,8 @@ class PDFViewer {
|
|
defaultViewport: viewport.clone(),
|
|
defaultViewport: viewport.clone(),
|
|
optionalContentConfigPromise,
|
|
optionalContentConfigPromise,
|
|
renderingQueue: this.renderingQueue,
|
|
renderingQueue: this.renderingQueue,
|
|
- textLayerFactory,
|
|
|
|
textLayerMode,
|
|
textLayerMode,
|
|
- annotationLayerFactory,
|
|
|
|
annotationMode,
|
|
annotationMode,
|
|
- xfaLayerFactory,
|
|
|
|
- annotationEditorLayerFactory,
|
|
|
|
- textHighlighterFactory: this,
|
|
|
|
- structTreeLayerFactory: this,
|
|
|
|
imageResourcesPath: this.imageResourcesPath,
|
|
imageResourcesPath: this.imageResourcesPath,
|
|
renderer:
|
|
renderer:
|
|
typeof PDFJSDev === "undefined" ||
|
|
typeof PDFJSDev === "undefined" ||
|
|
@@ -776,9 +782,11 @@ class PDFViewer {
|
|
? this.renderer
|
|
? this.renderer
|
|
: null,
|
|
: null,
|
|
useOnlyCssZoom: this.useOnlyCssZoom,
|
|
useOnlyCssZoom: this.useOnlyCssZoom,
|
|
|
|
+ isOffscreenCanvasSupported: this.isOffscreenCanvasSupported,
|
|
maxCanvasPixels: this.maxCanvasPixels,
|
|
maxCanvasPixels: this.maxCanvasPixels,
|
|
pageColors: this.pageColors,
|
|
pageColors: this.pageColors,
|
|
l10n: this.l10n,
|
|
l10n: this.l10n,
|
|
|
|
+ layerProperties,
|
|
});
|
|
});
|
|
this._pages.push(pageView);
|
|
this._pages.push(pageView);
|
|
}
|
|
}
|
|
@@ -1024,10 +1032,12 @@ class PDFViewer {
|
|
#scrollIntoView(pageView, pageSpot = null) {
|
|
#scrollIntoView(pageView, pageSpot = null) {
|
|
const { div, id } = pageView;
|
|
const { div, id } = pageView;
|
|
|
|
|
|
- if (this._scrollMode === ScrollMode.PAGE) {
|
|
|
|
- // Ensure that `this._currentPageNumber` is correct.
|
|
|
|
|
|
+ // Ensure that `this._currentPageNumber` is correct, when `#scrollIntoView`
|
|
|
|
+ // is called directly (and not from `#resetCurrentPageView`).
|
|
|
|
+ if (this._currentPageNumber !== id) {
|
|
this._setCurrentPageNumber(id);
|
|
this._setCurrentPageNumber(id);
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+ if (this._scrollMode === ScrollMode.PAGE) {
|
|
this.#ensurePageViewVisible();
|
|
this.#ensurePageViewVisible();
|
|
// Ensure that rendering always occurs, to avoid showing a blank page,
|
|
// Ensure that rendering always occurs, to avoid showing a blank page,
|
|
// even if the current position doesn't change when the page is scrolled.
|
|
// even if the current position doesn't change when the page is scrolled.
|
|
@@ -1047,6 +1057,15 @@ class PDFViewer {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
scrollIntoView(div, pageSpot);
|
|
scrollIntoView(div, pageSpot);
|
|
|
|
+
|
|
|
|
+ // Ensure that the correct *initial* document position is set, when any
|
|
|
|
+ // OpenParameters are used, for documents with non-default Scroll/Spread
|
|
|
|
+ // modes (fixes issue 15695). This is necessary since the scroll-handler
|
|
|
|
+ // invokes the `update`-method asynchronously, and `this._location` could
|
|
|
|
+ // thus be wrong when the initial zooming occurs in the default viewer.
|
|
|
|
+ if (!this._currentScaleValue && this._location) {
|
|
|
|
+ this._location = null;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1060,7 +1079,11 @@ class PDFViewer {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- _setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
|
|
|
|
|
|
+ _setScaleUpdatePages(
|
|
|
|
+ newScale,
|
|
|
|
+ newValue,
|
|
|
|
+ { noScroll = false, preset = false, drawingDelay = -1 }
|
|
|
|
+ ) {
|
|
this._currentScaleValue = newValue.toString();
|
|
this._currentScaleValue = newValue.toString();
|
|
|
|
|
|
if (this.#isSameScale(newScale)) {
|
|
if (this.#isSameScale(newScale)) {
|
|
@@ -1074,15 +1097,24 @@ class PDFViewer {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- docStyle.setProperty(
|
|
|
|
|
|
+ this.viewer.style.setProperty(
|
|
"--scale-factor",
|
|
"--scale-factor",
|
|
newScale * PixelsPerInch.PDF_TO_CSS_UNITS
|
|
newScale * PixelsPerInch.PDF_TO_CSS_UNITS
|
|
);
|
|
);
|
|
|
|
|
|
- const updateArgs = { scale: newScale };
|
|
|
|
- for (const pageView of this._pages) {
|
|
|
|
- pageView.update(updateArgs);
|
|
|
|
|
|
+ const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
|
|
|
|
+ this.refresh(true, {
|
|
|
|
+ scale: newScale,
|
|
|
|
+ drawingDelay: postponeDrawing ? drawingDelay : -1,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (postponeDrawing) {
|
|
|
|
+ this.#scaleTimeoutId = setTimeout(() => {
|
|
|
|
+ this.#scaleTimeoutId = null;
|
|
|
|
+ this.refresh();
|
|
|
|
+ }, drawingDelay);
|
|
}
|
|
}
|
|
|
|
+
|
|
this._currentScale = newScale;
|
|
this._currentScale = newScale;
|
|
|
|
|
|
if (!noScroll) {
|
|
if (!noScroll) {
|
|
@@ -1117,7 +1149,6 @@ class PDFViewer {
|
|
if (this.defaultRenderingQueue) {
|
|
if (this.defaultRenderingQueue) {
|
|
this.update();
|
|
this.update();
|
|
}
|
|
}
|
|
- this.updateContainerHeightCss();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1133,11 +1164,12 @@ class PDFViewer {
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
- _setScale(value, noScroll = false) {
|
|
|
|
|
|
+ _setScale(value, options) {
|
|
let scale = parseFloat(value);
|
|
let scale = parseFloat(value);
|
|
|
|
|
|
if (scale > 0) {
|
|
if (scale > 0) {
|
|
- this._setScaleUpdatePages(scale, value, noScroll, /* preset = */ false);
|
|
|
|
|
|
+ options.preset = false;
|
|
|
|
+ this._setScaleUpdatePages(scale, value, options);
|
|
} else {
|
|
} else {
|
|
const currentPage = this._pages[this._currentPageNumber - 1];
|
|
const currentPage = this._pages[this._currentPageNumber - 1];
|
|
if (!currentPage) {
|
|
if (!currentPage) {
|
|
@@ -1147,8 +1179,18 @@ class PDFViewer {
|
|
vPadding = VERTICAL_PADDING;
|
|
vPadding = VERTICAL_PADDING;
|
|
|
|
|
|
if (this.isInPresentationMode) {
|
|
if (this.isInPresentationMode) {
|
|
- hPadding = vPadding = 4;
|
|
|
|
- } else if (this.removePageBorders) {
|
|
|
|
|
|
+ // Pages have a 2px (transparent) border in PresentationMode, see
|
|
|
|
+ // the `web/pdf_viewer.css` file.
|
|
|
|
+ hPadding = vPadding = 4; // 2 * 2px
|
|
|
|
+ if (this._spreadMode !== SpreadMode.NONE) {
|
|
|
|
+ // Account for two pages being visible in PresentationMode, thus
|
|
|
|
+ // "doubling" the total border width.
|
|
|
|
+ hPadding *= 2;
|
|
|
|
+ }
|
|
|
|
+ } else if (
|
|
|
|
+ (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
|
|
|
+ this.removePageBorders
|
|
|
|
+ ) {
|
|
hPadding = vPadding = 0;
|
|
hPadding = vPadding = 0;
|
|
} else if (this._scrollMode === ScrollMode.HORIZONTAL) {
|
|
} else if (this._scrollMode === ScrollMode.HORIZONTAL) {
|
|
[hPadding, vPadding] = [vPadding, hPadding]; // Swap the padding values.
|
|
[hPadding, vPadding] = [vPadding, hPadding]; // Swap the padding values.
|
|
@@ -1185,7 +1227,8 @@ class PDFViewer {
|
|
console.error(`_setScale: "${value}" is an unknown zoom value.`);
|
|
console.error(`_setScale: "${value}" is an unknown zoom value.`);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- this._setScaleUpdatePages(scale, value, noScroll, /* preset = */ true);
|
|
|
|
|
|
+ options.preset = true;
|
|
|
|
+ this._setScaleUpdatePages(scale, value, options);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1197,7 +1240,7 @@ class PDFViewer {
|
|
|
|
|
|
if (this.isInPresentationMode) {
|
|
if (this.isInPresentationMode) {
|
|
// Fixes the case when PDF has different page sizes.
|
|
// Fixes the case when PDF has different page sizes.
|
|
- this._setScale(this._currentScaleValue, true);
|
|
|
|
|
|
+ this._setScale(this._currentScaleValue, { noScroll: true });
|
|
}
|
|
}
|
|
this.#scrollIntoView(pageView);
|
|
this.#scrollIntoView(pageView);
|
|
}
|
|
}
|
|
@@ -1314,9 +1357,15 @@ class PDFViewer {
|
|
y = destArray[3];
|
|
y = destArray[3];
|
|
width = destArray[4] - x;
|
|
width = destArray[4] - x;
|
|
height = destArray[5] - y;
|
|
height = destArray[5] - y;
|
|
- const hPadding = this.removePageBorders ? 0 : SCROLLBAR_PADDING;
|
|
|
|
- const vPadding = this.removePageBorders ? 0 : VERTICAL_PADDING;
|
|
|
|
-
|
|
|
|
|
|
+ let hPadding = SCROLLBAR_PADDING,
|
|
|
|
+ vPadding = VERTICAL_PADDING;
|
|
|
|
+
|
|
|
|
+ if (
|
|
|
|
+ (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
|
|
|
+ this.removePageBorders
|
|
|
|
+ ) {
|
|
|
|
+ hPadding = vPadding = 0;
|
|
|
|
+ }
|
|
widthScale =
|
|
widthScale =
|
|
(this.container.clientWidth - hPadding) /
|
|
(this.container.clientWidth - hPadding) /
|
|
width /
|
|
width /
|
|
@@ -1582,23 +1631,6 @@ class PDFViewer {
|
|
return this.scroll.down;
|
|
return this.scroll.down;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Only show the `loadingIcon`-spinner on visible pages (see issue 14242).
|
|
|
|
- */
|
|
|
|
- #toggleLoadingIconSpinner(visibleIds) {
|
|
|
|
- for (const id of visibleIds) {
|
|
|
|
- const pageView = this._pages[id - 1];
|
|
|
|
- pageView?.toggleLoadingIconSpinner(/* viewVisible = */ true);
|
|
|
|
- }
|
|
|
|
- for (const pageView of this.#buffer) {
|
|
|
|
- if (visibleIds.has(pageView.id)) {
|
|
|
|
- // Handled above, since the "buffer" may not contain all visible pages.
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- pageView.toggleLoadingIconSpinner(/* viewVisible = */ false);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
forceRendering(currentlyVisiblePages) {
|
|
forceRendering(currentlyVisiblePages) {
|
|
const visiblePages = currentlyVisiblePages || this._getVisiblePages();
|
|
const visiblePages = currentlyVisiblePages || this._getVisiblePages();
|
|
const scrollAhead = this.#getScrollAhead(visiblePages);
|
|
const scrollAhead = this.#getScrollAhead(visiblePages);
|
|
@@ -1612,7 +1644,6 @@ class PDFViewer {
|
|
scrollAhead,
|
|
scrollAhead,
|
|
preRenderExtra
|
|
preRenderExtra
|
|
);
|
|
);
|
|
- this.#toggleLoadingIconSpinner(visiblePages.ids);
|
|
|
|
|
|
|
|
if (pageView) {
|
|
if (pageView) {
|
|
this.#ensurePdfPageLoaded(pageView).then(() => {
|
|
this.#ensurePdfPageLoaded(pageView).then(() => {
|
|
@@ -1623,185 +1654,6 @@ class PDFViewer {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * @typedef {Object} CreateTextLayerBuilderParameters
|
|
|
|
- * @property {HTMLDivElement} textLayerDiv
|
|
|
|
- * @property {number} pageIndex
|
|
|
|
- * @property {PageViewport} viewport
|
|
|
|
- * @property {EventBus} eventBus
|
|
|
|
- * @property {TextHighlighter} highlighter
|
|
|
|
- * @property {TextAccessibilityManager} [accessibilityManager]
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @param {CreateTextLayerBuilderParameters}
|
|
|
|
- * @returns {TextLayerBuilder}
|
|
|
|
- */
|
|
|
|
- createTextLayerBuilder({
|
|
|
|
- textLayerDiv,
|
|
|
|
- pageIndex,
|
|
|
|
- viewport,
|
|
|
|
- eventBus,
|
|
|
|
- highlighter,
|
|
|
|
- accessibilityManager = null,
|
|
|
|
- }) {
|
|
|
|
- return new TextLayerBuilder({
|
|
|
|
- textLayerDiv,
|
|
|
|
- eventBus,
|
|
|
|
- pageIndex,
|
|
|
|
- viewport,
|
|
|
|
- highlighter,
|
|
|
|
- accessibilityManager,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @typedef {Object} CreateTextHighlighterParameters
|
|
|
|
- * @property {number} pageIndex
|
|
|
|
- * @property {EventBus} eventBus
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @param {CreateTextHighlighterParameters}
|
|
|
|
- * @returns {TextHighlighter}
|
|
|
|
- */
|
|
|
|
- createTextHighlighter({ pageIndex, eventBus }) {
|
|
|
|
- return new TextHighlighter({
|
|
|
|
- eventBus,
|
|
|
|
- pageIndex,
|
|
|
|
- findController: this.isInPresentationMode ? null : this.findController,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @typedef {Object} CreateAnnotationLayerBuilderParameters
|
|
|
|
- * @property {HTMLDivElement} pageDiv
|
|
|
|
- * @property {PDFPageProxy} pdfPage
|
|
|
|
- * @property {AnnotationStorage} [annotationStorage] - Storage for annotation
|
|
|
|
- * data in forms.
|
|
|
|
- * @property {string} [imageResourcesPath] - Path for image resources, mainly
|
|
|
|
- * for annotation icons. Include trailing slash.
|
|
|
|
- * @property {boolean} renderForms
|
|
|
|
- * @property {IL10n} l10n
|
|
|
|
- * @property {boolean} [enableScripting]
|
|
|
|
- * @property {Promise<boolean>} [hasJSActionsPromise]
|
|
|
|
- * @property {Object} [mouseState]
|
|
|
|
- * @property {Promise<Object<string, Array<Object>> | null>}
|
|
|
|
- * [fieldObjectsPromise]
|
|
|
|
- * @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap] - Map some
|
|
|
|
- * annotation ids with canvases used to render them.
|
|
|
|
- * @property {TextAccessibilityManager} [accessibilityManager]
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @param {CreateAnnotationLayerBuilderParameters}
|
|
|
|
- * @returns {AnnotationLayerBuilder}
|
|
|
|
- */
|
|
|
|
- createAnnotationLayerBuilder({
|
|
|
|
- pageDiv,
|
|
|
|
- pdfPage,
|
|
|
|
- annotationStorage = this.pdfDocument?.annotationStorage,
|
|
|
|
- imageResourcesPath = "",
|
|
|
|
- renderForms = true,
|
|
|
|
- l10n = NullL10n,
|
|
|
|
- enableScripting = this.enableScripting,
|
|
|
|
- hasJSActionsPromise = this.pdfDocument?.hasJSActions(),
|
|
|
|
- mouseState = this._scriptingManager?.mouseState,
|
|
|
|
- fieldObjectsPromise = this.pdfDocument?.getFieldObjects(),
|
|
|
|
- annotationCanvasMap = null,
|
|
|
|
- accessibilityManager = null,
|
|
|
|
- }) {
|
|
|
|
- return new AnnotationLayerBuilder({
|
|
|
|
- pageDiv,
|
|
|
|
- pdfPage,
|
|
|
|
- annotationStorage,
|
|
|
|
- imageResourcesPath,
|
|
|
|
- renderForms,
|
|
|
|
- linkService: this.linkService,
|
|
|
|
- downloadManager: this.downloadManager,
|
|
|
|
- l10n,
|
|
|
|
- enableScripting,
|
|
|
|
- hasJSActionsPromise,
|
|
|
|
- mouseState,
|
|
|
|
- fieldObjectsPromise,
|
|
|
|
- annotationCanvasMap,
|
|
|
|
- accessibilityManager,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @typedef {Object} CreateAnnotationEditorLayerBuilderParameters
|
|
|
|
- * @property {AnnotationEditorUIManager} [uiManager]
|
|
|
|
- * @property {HTMLDivElement} pageDiv
|
|
|
|
- * @property {PDFPageProxy} pdfPage
|
|
|
|
- * @property {IL10n} l10n
|
|
|
|
- * @property {AnnotationStorage} [annotationStorage] - Storage for annotation
|
|
|
|
- * @property {TextAccessibilityManager} [accessibilityManager]
|
|
|
|
- * data in forms.
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @param {CreateAnnotationEditorLayerBuilderParameters}
|
|
|
|
- * @returns {AnnotationEditorLayerBuilder}
|
|
|
|
- */
|
|
|
|
- createAnnotationEditorLayerBuilder({
|
|
|
|
- uiManager = this.#annotationEditorUIManager,
|
|
|
|
- pageDiv,
|
|
|
|
- pdfPage,
|
|
|
|
- accessibilityManager = null,
|
|
|
|
- l10n,
|
|
|
|
- annotationStorage = this.pdfDocument?.annotationStorage,
|
|
|
|
- }) {
|
|
|
|
- return new AnnotationEditorLayerBuilder({
|
|
|
|
- uiManager,
|
|
|
|
- pageDiv,
|
|
|
|
- pdfPage,
|
|
|
|
- annotationStorage,
|
|
|
|
- accessibilityManager,
|
|
|
|
- l10n,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @typedef {Object} CreateXfaLayerBuilderParameters
|
|
|
|
- * @property {HTMLDivElement} pageDiv
|
|
|
|
- * @property {PDFPageProxy} pdfPage
|
|
|
|
- * @property {AnnotationStorage} [annotationStorage] - Storage for annotation
|
|
|
|
- * data in forms.
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @param {CreateXfaLayerBuilderParameters}
|
|
|
|
- * @returns {XfaLayerBuilder}
|
|
|
|
- */
|
|
|
|
- createXfaLayerBuilder({
|
|
|
|
- pageDiv,
|
|
|
|
- pdfPage,
|
|
|
|
- annotationStorage = this.pdfDocument?.annotationStorage,
|
|
|
|
- }) {
|
|
|
|
- return new XfaLayerBuilder({
|
|
|
|
- pageDiv,
|
|
|
|
- pdfPage,
|
|
|
|
- annotationStorage,
|
|
|
|
- linkService: this.linkService,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @typedef {Object} CreateStructTreeLayerBuilderParameters
|
|
|
|
- * @property {PDFPageProxy} pdfPage
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @param {CreateStructTreeLayerBuilderParameters}
|
|
|
|
- * @returns {StructTreeLayerBuilder}
|
|
|
|
- */
|
|
|
|
- createStructTreeLayerBuilder({ pdfPage }) {
|
|
|
|
- return new StructTreeLayerBuilder({
|
|
|
|
- pdfPage,
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* @type {boolean} Whether all pages of the PDF document have identical
|
|
* @type {boolean} Whether all pages of the PDF document have identical
|
|
* widths and heights.
|
|
* widths and heights.
|
|
@@ -1878,11 +1730,7 @@ class PDFViewer {
|
|
}
|
|
}
|
|
this._optionalContentConfigPromise = promise;
|
|
this._optionalContentConfigPromise = promise;
|
|
|
|
|
|
- const updateArgs = { optionalContentConfigPromise: promise };
|
|
|
|
- for (const pageView of this._pages) {
|
|
|
|
- pageView.update(updateArgs);
|
|
|
|
- }
|
|
|
|
- this.update();
|
|
|
|
|
|
+ this.refresh(false, { optionalContentConfigPromise: promise });
|
|
|
|
|
|
this.eventBus.dispatch("optionalcontentconfigchanged", {
|
|
this.eventBus.dispatch("optionalcontentconfigchanged", {
|
|
source: this,
|
|
source: this,
|
|
@@ -1945,7 +1793,7 @@ class PDFViewer {
|
|
// Call this before re-scrolling to the current page, to ensure that any
|
|
// Call this before re-scrolling to the current page, to ensure that any
|
|
// changes in scale don't move the current page.
|
|
// changes in scale don't move the current page.
|
|
if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
|
|
if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
|
|
- this._setScale(this._currentScaleValue, true);
|
|
|
|
|
|
+ this._setScale(this._currentScaleValue, { noScroll: true });
|
|
}
|
|
}
|
|
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
|
|
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
|
|
this.update();
|
|
this.update();
|
|
@@ -2017,7 +1865,7 @@ class PDFViewer {
|
|
// Call this before re-scrolling to the current page, to ensure that any
|
|
// Call this before re-scrolling to the current page, to ensure that any
|
|
// changes in scale don't move the current page.
|
|
// changes in scale don't move the current page.
|
|
if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
|
|
if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
|
|
- this._setScale(this._currentScaleValue, true);
|
|
|
|
|
|
+ this._setScale(this._currentScaleValue, { noScroll: true });
|
|
}
|
|
}
|
|
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
|
|
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
|
|
this.update();
|
|
this.update();
|
|
@@ -2157,42 +2005,110 @@ class PDFViewer {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Increase the current zoom level one, or more, times.
|
|
* Increase the current zoom level one, or more, times.
|
|
- * @param {number} [steps] - Defaults to zooming once.
|
|
|
|
|
|
+ * @param {Object|null} [options]
|
|
*/
|
|
*/
|
|
- increaseScale(steps = 1) {
|
|
|
|
|
|
+ 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 };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!this.pdfDocument) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ options ||= Object.create(null);
|
|
|
|
+
|
|
let newScale = this._currentScale;
|
|
let newScale = this._currentScale;
|
|
- do {
|
|
|
|
- newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
|
|
|
|
- newScale = Math.ceil(newScale * 10) / 10;
|
|
|
|
- newScale = Math.min(MAX_SCALE, newScale);
|
|
|
|
- } while (--steps > 0 && newScale < MAX_SCALE);
|
|
|
|
- this.currentScaleValue = newScale;
|
|
|
|
|
|
+ if (options.scaleFactor > 1) {
|
|
|
|
+ newScale = Math.min(
|
|
|
|
+ MAX_SCALE,
|
|
|
|
+ Math.round(newScale * options.scaleFactor * 100) / 100
|
|
|
|
+ );
|
|
|
|
+ } else {
|
|
|
|
+ let steps = options.steps ?? 1;
|
|
|
|
+ do {
|
|
|
|
+ newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
|
|
|
|
+ newScale = Math.ceil(newScale * 10) / 10;
|
|
|
|
+ newScale = Math.min(MAX_SCALE, newScale);
|
|
|
|
+ } while (--steps > 0 && newScale < MAX_SCALE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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 {number} [steps] - Defaults to zooming once.
|
|
|
|
|
|
+ * @param {Object|null} [options]
|
|
*/
|
|
*/
|
|
- decreaseScale(steps = 1) {
|
|
|
|
|
|
+ decreaseScale(options = null) {
|
|
|
|
+ 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) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ options ||= Object.create(null);
|
|
|
|
+
|
|
let newScale = this._currentScale;
|
|
let newScale = this._currentScale;
|
|
- do {
|
|
|
|
- newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
|
|
|
|
- newScale = Math.floor(newScale * 10) / 10;
|
|
|
|
- newScale = Math.max(MIN_SCALE, newScale);
|
|
|
|
- } while (--steps > 0 && newScale > MIN_SCALE);
|
|
|
|
- this.currentScaleValue = newScale;
|
|
|
|
- }
|
|
|
|
|
|
+ if (options.scaleFactor > 0 && options.scaleFactor < 1) {
|
|
|
|
+ newScale = Math.max(
|
|
|
|
+ MIN_SCALE,
|
|
|
|
+ Math.round(newScale * options.scaleFactor * 100) / 100
|
|
|
|
+ );
|
|
|
|
+ } else {
|
|
|
|
+ let steps = options.steps ?? 1;
|
|
|
|
+ do {
|
|
|
|
+ newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
|
|
|
|
+ newScale = Math.floor(newScale * 10) / 10;
|
|
|
|
+ newScale = Math.max(MIN_SCALE, newScale);
|
|
|
|
+ } while (--steps > 0 && newScale > MIN_SCALE);
|
|
|
|
+ }
|
|
|
|
|
|
- updateContainerHeightCss() {
|
|
|
|
- const height = this.container.clientHeight;
|
|
|
|
|
|
+ options.noScroll = false;
|
|
|
|
+ this._setScale(newScale, options);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ #updateContainerHeightCss(height = this.container.clientHeight) {
|
|
if (height !== this.#previousContainerHeight) {
|
|
if (height !== this.#previousContainerHeight) {
|
|
this.#previousContainerHeight = height;
|
|
this.#previousContainerHeight = height;
|
|
-
|
|
|
|
docStyle.setProperty("--viewer-container-height", `${height}px`);
|
|
docStyle.setProperty("--viewer-container-height", `${height}px`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ #resizeObserverCallback(entries) {
|
|
|
|
+ for (const entry of entries) {
|
|
|
|
+ if (entry.target === this.container) {
|
|
|
|
+ this.#updateContainerHeightCss(
|
|
|
|
+ Math.floor(entry.borderBoxSize[0].blockSize)
|
|
|
|
+ );
|
|
|
|
+ this.#containerTopLeft = null;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ get containerTopLeft() {
|
|
|
|
+ return (this.#containerTopLeft ||= [
|
|
|
|
+ this.container.offsetTop,
|
|
|
|
+ this.container.offsetLeft,
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @type {number}
|
|
* @type {number}
|
|
*/
|
|
*/
|
|
@@ -2235,15 +2151,20 @@ class PDFViewer {
|
|
this.#annotationEditorUIManager.updateParams(type, value);
|
|
this.#annotationEditorUIManager.updateParams(type, value);
|
|
}
|
|
}
|
|
|
|
|
|
- refresh() {
|
|
|
|
|
|
+ refresh(noUpdate = false, updateArgs = Object.create(null)) {
|
|
if (!this.pdfDocument) {
|
|
if (!this.pdfDocument) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- const updateArgs = {};
|
|
|
|
for (const pageView of this._pages) {
|
|
for (const pageView of this._pages) {
|
|
pageView.update(updateArgs);
|
|
pageView.update(updateArgs);
|
|
}
|
|
}
|
|
- this.update();
|
|
|
|
|
|
+ if (this.#scaleTimeoutId !== null) {
|
|
|
|
+ clearTimeout(this.#scaleTimeoutId);
|
|
|
|
+ this.#scaleTimeoutId = null;
|
|
|
|
+ }
|
|
|
|
+ if (!noUpdate) {
|
|
|
|
+ this.update();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|