|
@@ -64,8 +64,6 @@ const ViewerCssTheme = {
|
|
|
LIGHT: 1,
|
|
|
DARK: 2
|
|
|
};
|
|
|
-const KNOWN_VERSIONS = ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3"];
|
|
|
-const KNOWN_GENERATORS = ["acrobat distiller", "acrobat pdfwriter", "adobe livecycle", "adobe pdf library", "adobe photoshop", "ghostscript", "tcpdf", "cairo", "dvipdfm", "dvips", "pdftex", "pdfkit", "itext", "prince", "quarkxpress", "mac os x", "microsoft", "openoffice", "oracle", "luradocument", "pdf-xchange", "antenna house", "aspose.cells", "fpdf"];
|
|
|
class DefaultExternalServices {
|
|
|
constructor() {
|
|
|
throw new Error("Cannot initialize DefaultExternalServices.");
|
|
@@ -74,7 +72,7 @@ class DefaultExternalServices {
|
|
|
static updateFindMatchesCount(data) {}
|
|
|
static initPassiveLoading(callbacks) {}
|
|
|
static reportTelemetry(data) {}
|
|
|
- static createDownloadManager(options) {
|
|
|
+ static createDownloadManager() {
|
|
|
throw new Error("Not implemented: createDownloadManager");
|
|
|
}
|
|
|
static createPreferences() {
|
|
@@ -149,7 +147,6 @@ const PDFViewerApplication = {
|
|
|
_contentDispositionFilename: null,
|
|
|
_contentLength: null,
|
|
|
_saveInProgress: false,
|
|
|
- _docStats: null,
|
|
|
_wheelUnusedTicks: 0,
|
|
|
_PDFBug: null,
|
|
|
_hasAnnotationEditors: false,
|
|
@@ -352,6 +349,7 @@ const PDFViewerApplication = {
|
|
|
imageResourcesPath: _app_options.AppOptions.get("imageResourcesPath"),
|
|
|
enablePrintAutoRotate: _app_options.AppOptions.get("enablePrintAutoRotate"),
|
|
|
useOnlyCssZoom: _app_options.AppOptions.get("useOnlyCssZoom"),
|
|
|
+ isOffscreenCanvasSupported: _app_options.AppOptions.get("isOffscreenCanvasSupported"),
|
|
|
maxCanvasPixels: _app_options.AppOptions.get("maxCanvasPixels"),
|
|
|
enablePermissions: _app_options.AppOptions.get("enablePermissions"),
|
|
|
pageColors
|
|
@@ -359,15 +357,17 @@ const PDFViewerApplication = {
|
|
|
pdfRenderingQueue.setViewer(this.pdfViewer);
|
|
|
pdfLinkService.setViewer(this.pdfViewer);
|
|
|
pdfScriptingManager.setViewer(this.pdfViewer);
|
|
|
- this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
|
|
|
- container: appConfig.sidebar.thumbnailView,
|
|
|
- eventBus,
|
|
|
- renderingQueue: pdfRenderingQueue,
|
|
|
- linkService: pdfLinkService,
|
|
|
- l10n: this.l10n,
|
|
|
- pageColors
|
|
|
- });
|
|
|
- pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
|
|
|
+ if (appConfig.sidebar?.thumbnailView) {
|
|
|
+ this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
|
|
|
+ container: appConfig.sidebar.thumbnailView,
|
|
|
+ eventBus,
|
|
|
+ renderingQueue: pdfRenderingQueue,
|
|
|
+ linkService: pdfLinkService,
|
|
|
+ l10n: this.l10n,
|
|
|
+ pageColors
|
|
|
+ });
|
|
|
+ pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
|
|
|
+ }
|
|
|
if (!this.isViewerEmbedded && !_app_options.AppOptions.get("disableHistory")) {
|
|
|
this.pdfHistory = new _pdf_history.PDFHistory({
|
|
|
linkService: pdfLinkService,
|
|
@@ -375,26 +375,34 @@ const PDFViewerApplication = {
|
|
|
});
|
|
|
pdfLinkService.setHistory(this.pdfHistory);
|
|
|
}
|
|
|
- if (!this.supportsIntegratedFind) {
|
|
|
+ if (!this.supportsIntegratedFind && appConfig.findBar) {
|
|
|
this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
|
|
|
}
|
|
|
- if (annotationEditorMode !== _pdf.AnnotationEditorType.DISABLE) {
|
|
|
- this.annotationEditorParams = new _annotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
|
|
|
- } else {
|
|
|
- for (const element of [document.getElementById("editorModeButtons"), document.getElementById("editorModeSeparator")]) {
|
|
|
- element.hidden = true;
|
|
|
+ if (appConfig.annotationEditorParams) {
|
|
|
+ if (annotationEditorMode !== _pdf.AnnotationEditorType.DISABLE) {
|
|
|
+ this.annotationEditorParams = new _annotation_editor_params.AnnotationEditorParams(appConfig.annotationEditorParams, eventBus);
|
|
|
+ } else {
|
|
|
+ for (const id of ["editorModeButtons", "editorModeSeparator"]) {
|
|
|
+ document.getElementById(id)?.classList.add("hidden");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => {
|
|
|
- return this._docFilename;
|
|
|
- });
|
|
|
+ if (appConfig.documentProperties) {
|
|
|
+ this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n, () => {
|
|
|
+ return this._docFilename;
|
|
|
+ });
|
|
|
+ }
|
|
|
this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
|
|
|
container,
|
|
|
eventBus,
|
|
|
cursorToolOnLoad: _app_options.AppOptions.get("cursorToolOnLoad")
|
|
|
});
|
|
|
- this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
|
|
|
- this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, this.externalServices);
|
|
|
+ if (appConfig.toolbar) {
|
|
|
+ this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
|
|
|
+ }
|
|
|
+ if (appConfig.secondaryToolbar) {
|
|
|
+ this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, eventBus, this.externalServices);
|
|
|
+ }
|
|
|
if (this.supportsFullscreen) {
|
|
|
this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
|
|
|
container,
|
|
@@ -402,32 +410,42 @@ const PDFViewerApplication = {
|
|
|
eventBus
|
|
|
});
|
|
|
}
|
|
|
- this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
|
|
|
- this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
|
|
|
- container: appConfig.sidebar.outlineView,
|
|
|
- eventBus,
|
|
|
- linkService: pdfLinkService,
|
|
|
- downloadManager
|
|
|
- });
|
|
|
- this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
|
|
|
- container: appConfig.sidebar.attachmentsView,
|
|
|
- eventBus,
|
|
|
- downloadManager
|
|
|
- });
|
|
|
- this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
|
|
|
- container: appConfig.sidebar.layersView,
|
|
|
- eventBus,
|
|
|
- l10n: this.l10n
|
|
|
- });
|
|
|
- this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
|
|
|
- elements: appConfig.sidebar,
|
|
|
- pdfViewer: this.pdfViewer,
|
|
|
- pdfThumbnailViewer: this.pdfThumbnailViewer,
|
|
|
- eventBus,
|
|
|
- l10n: this.l10n
|
|
|
- });
|
|
|
- this.pdfSidebar.onToggled = this.forceRendering.bind(this);
|
|
|
- this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
|
|
|
+ if (appConfig.passwordOverlay) {
|
|
|
+ this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n, this.isViewerEmbedded);
|
|
|
+ }
|
|
|
+ if (appConfig.sidebar?.outlineView) {
|
|
|
+ this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
|
|
|
+ container: appConfig.sidebar.outlineView,
|
|
|
+ eventBus,
|
|
|
+ linkService: pdfLinkService,
|
|
|
+ downloadManager
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (appConfig.sidebar?.attachmentsView) {
|
|
|
+ this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
|
|
|
+ container: appConfig.sidebar.attachmentsView,
|
|
|
+ eventBus,
|
|
|
+ downloadManager
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (appConfig.sidebar?.layersView) {
|
|
|
+ this.pdfLayerViewer = new _pdf_layer_viewer.PDFLayerViewer({
|
|
|
+ container: appConfig.sidebar.layersView,
|
|
|
+ eventBus,
|
|
|
+ l10n: this.l10n
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (appConfig.sidebar) {
|
|
|
+ this.pdfSidebar = new _pdf_sidebar.PDFSidebar({
|
|
|
+ elements: appConfig.sidebar,
|
|
|
+ pdfViewer: this.pdfViewer,
|
|
|
+ pdfThumbnailViewer: this.pdfThumbnailViewer,
|
|
|
+ eventBus,
|
|
|
+ l10n: this.l10n
|
|
|
+ });
|
|
|
+ this.pdfSidebar.onToggled = this.forceRendering.bind(this);
|
|
|
+ this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
|
|
|
+ }
|
|
|
},
|
|
|
run(config) {
|
|
|
this.initialize(config).then(webViewerInitialized);
|
|
@@ -442,13 +460,17 @@ const PDFViewerApplication = {
|
|
|
if (this.pdfViewer.isInPresentationMode) {
|
|
|
return;
|
|
|
}
|
|
|
- this.pdfViewer.increaseScale(steps);
|
|
|
+ this.pdfViewer.increaseScale(steps, {
|
|
|
+ drawingDelay: _app_options.AppOptions.get("defaultZoomDelay")
|
|
|
+ });
|
|
|
},
|
|
|
zoomOut(steps) {
|
|
|
if (this.pdfViewer.isInPresentationMode) {
|
|
|
return;
|
|
|
}
|
|
|
- this.pdfViewer.decreaseScale(steps);
|
|
|
+ this.pdfViewer.decreaseScale(steps, {
|
|
|
+ drawingDelay: _app_options.AppOptions.get("defaultZoomDelay")
|
|
|
+ });
|
|
|
},
|
|
|
zoomReset() {
|
|
|
if (this.pdfViewer.isInPresentationMode) {
|
|
@@ -478,7 +500,8 @@ const PDFViewerApplication = {
|
|
|
return this.externalServices.supportsDocumentFonts;
|
|
|
},
|
|
|
get loadingBar() {
|
|
|
- const bar = new _ui_utils.ProgressBar("loadingBar");
|
|
|
+ const barElement = document.getElementById("loadingBar");
|
|
|
+ const bar = barElement ? new _ui_utils.ProgressBar(barElement) : null;
|
|
|
return (0, _pdf.shadow)(this, "loadingBar", bar);
|
|
|
},
|
|
|
get supportedMouseWheelZoomModifierKeys() {
|
|
@@ -493,6 +516,9 @@ const PDFViewerApplication = {
|
|
|
if (downloadUrl) {
|
|
|
this._downloadUrl = downloadUrl === url ? this.baseUrl : downloadUrl.split("#")[0];
|
|
|
}
|
|
|
+ if ((0, _pdf.isDataScheme)(url)) {
|
|
|
+ this._hideViewBookmark();
|
|
|
+ }
|
|
|
let title = (0, _pdf.getPdfFilenameFromUrl)(url, "");
|
|
|
if (!title) {
|
|
|
try {
|
|
@@ -515,7 +541,13 @@ const PDFViewerApplication = {
|
|
|
return this._contentDispositionFilename || (0, _pdf.getPdfFilenameFromUrl)(this.url);
|
|
|
},
|
|
|
_hideViewBookmark() {
|
|
|
- this.appConfig.secondaryToolbar.viewBookmarkButton.hidden = true;
|
|
|
+ const {
|
|
|
+ secondaryToolbar
|
|
|
+ } = this.appConfig;
|
|
|
+ secondaryToolbar?.viewBookmarkButton.classList.add("hidden");
|
|
|
+ if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) {
|
|
|
+ document.getElementById("viewBookmarkSeparator")?.classList.add("hidden");
|
|
|
+ }
|
|
|
},
|
|
|
async close() {
|
|
|
this._unblockDocumentLoadEvent();
|
|
@@ -533,10 +565,10 @@ const PDFViewerApplication = {
|
|
|
this.pdfLoadingTask = null;
|
|
|
if (this.pdfDocument) {
|
|
|
this.pdfDocument = null;
|
|
|
- this.pdfThumbnailViewer.setDocument(null);
|
|
|
+ this.pdfThumbnailViewer?.setDocument(null);
|
|
|
this.pdfViewer.setDocument(null);
|
|
|
this.pdfLinkService.setDocument(null);
|
|
|
- this.pdfDocumentProperties.setDocument(null);
|
|
|
+ this.pdfDocumentProperties?.setDocument(null);
|
|
|
}
|
|
|
this.pdfLinkService.externalLinkEnabled = true;
|
|
|
this.store = null;
|
|
@@ -550,18 +582,17 @@ const PDFViewerApplication = {
|
|
|
this._contentDispositionFilename = null;
|
|
|
this._contentLength = null;
|
|
|
this._saveInProgress = false;
|
|
|
- this._docStats = null;
|
|
|
this._hasAnnotationEditors = false;
|
|
|
promises.push(this.pdfScriptingManager.destroyPromise);
|
|
|
this.setTitle();
|
|
|
- this.pdfSidebar.reset();
|
|
|
- this.pdfOutlineViewer.reset();
|
|
|
- this.pdfAttachmentViewer.reset();
|
|
|
- this.pdfLayerViewer.reset();
|
|
|
+ this.pdfSidebar?.reset();
|
|
|
+ this.pdfOutlineViewer?.reset();
|
|
|
+ this.pdfAttachmentViewer?.reset();
|
|
|
+ this.pdfLayerViewer?.reset();
|
|
|
this.pdfHistory?.reset();
|
|
|
this.findBar?.reset();
|
|
|
- this.toolbar.reset();
|
|
|
- this.secondaryToolbar.reset();
|
|
|
+ this.toolbar?.reset();
|
|
|
+ this.secondaryToolbar?.reset();
|
|
|
this._PDFBug?.cleanup();
|
|
|
await Promise.all(promises);
|
|
|
},
|
|
@@ -610,7 +641,6 @@ const PDFViewerApplication = {
|
|
|
}) => {
|
|
|
this.progress(loaded / total);
|
|
|
};
|
|
|
- loadingTask.onUnsupportedFeature = this.fallback.bind(this);
|
|
|
return loadingTask.promise.then(pdfDocument => {
|
|
|
this.load(pdfDocument);
|
|
|
}, reason => {
|
|
@@ -691,12 +721,6 @@ const PDFViewerApplication = {
|
|
|
this.download();
|
|
|
}
|
|
|
},
|
|
|
- fallback(featureId) {
|
|
|
- this.externalServices.reportTelemetry({
|
|
|
- type: "unsupportedFeature",
|
|
|
- featureId
|
|
|
- });
|
|
|
- },
|
|
|
_documentError(message, moreInfo = null) {
|
|
|
this._unblockDocumentLoadEvent();
|
|
|
this._otherError(message, moreInfo);
|
|
@@ -722,10 +746,9 @@ const PDFViewerApplication = {
|
|
|
}
|
|
|
}
|
|
|
console.error(`${message}\n\n${moreInfoText.join("\n")}`);
|
|
|
- this.fallback();
|
|
|
},
|
|
|
progress(level) {
|
|
|
- if (this.downloadComplete) {
|
|
|
+ if (!this.loadingBar || this.downloadComplete) {
|
|
|
return;
|
|
|
}
|
|
|
const percent = Math.round(level * 100);
|
|
@@ -754,7 +777,7 @@ const PDFViewerApplication = {
|
|
|
}) => {
|
|
|
this._contentLength = length;
|
|
|
this.downloadComplete = true;
|
|
|
- this.loadingBar.hide();
|
|
|
+ this.loadingBar?.hide();
|
|
|
firstPagePromise.then(() => {
|
|
|
this.eventBus.dispatch("documentloaded", {
|
|
|
source: this
|
|
@@ -764,12 +787,15 @@ const PDFViewerApplication = {
|
|
|
const pageLayoutPromise = pdfDocument.getPageLayout().catch(function () {});
|
|
|
const pageModePromise = pdfDocument.getPageMode().catch(function () {});
|
|
|
const openActionPromise = pdfDocument.getOpenAction().catch(function () {});
|
|
|
- this.toolbar.setPagesCount(pdfDocument.numPages, false);
|
|
|
- this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
|
|
|
+ this.toolbar?.setPagesCount(pdfDocument.numPages, false);
|
|
|
+ this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
|
|
|
let baseDocumentUrl;
|
|
|
baseDocumentUrl = null;
|
|
|
+ if (baseDocumentUrl && (0, _pdf.isDataScheme)(baseDocumentUrl)) {
|
|
|
+ baseDocumentUrl = null;
|
|
|
+ }
|
|
|
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
|
|
- this.pdfDocumentProperties.setDocument(pdfDocument);
|
|
|
+ this.pdfDocumentProperties?.setDocument(pdfDocument);
|
|
|
const pdfViewer = this.pdfViewer;
|
|
|
pdfViewer.setDocument(pdfDocument);
|
|
|
const {
|
|
@@ -777,8 +803,7 @@ const PDFViewerApplication = {
|
|
|
onePageRendered,
|
|
|
pagesPromise
|
|
|
} = pdfViewer;
|
|
|
- const pdfThumbnailViewer = this.pdfThumbnailViewer;
|
|
|
- pdfThumbnailViewer.setDocument(pdfDocument);
|
|
|
+ this.pdfThumbnailViewer?.setDocument(pdfDocument);
|
|
|
const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprints[0])).getMultiple({
|
|
|
page: null,
|
|
|
zoom: _ui_utils.DEFAULT_SCALE_VALUE,
|
|
@@ -792,7 +817,7 @@ const PDFViewerApplication = {
|
|
|
return Object.create(null);
|
|
|
});
|
|
|
firstPagePromise.then(pdfPage => {
|
|
|
- this.loadingBar.setWidth(this.appConfig.viewerContainer);
|
|
|
+ this.loadingBar?.setWidth(this.appConfig.viewerContainer);
|
|
|
this._initializeAnnotationStorageCallbacks(pdfDocument);
|
|
|
Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => {
|
|
|
const viewOnLoad = _app_options.AppOptions.get("viewOnLoad");
|
|
@@ -877,7 +902,7 @@ const PDFViewerApplication = {
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
return;
|
|
|
}
|
|
|
- this.pdfOutlineViewer.render({
|
|
|
+ this.pdfOutlineViewer?.render({
|
|
|
outline,
|
|
|
pdfDocument
|
|
|
});
|
|
@@ -886,7 +911,7 @@ const PDFViewerApplication = {
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
return;
|
|
|
}
|
|
|
- this.pdfAttachmentViewer.render({
|
|
|
+ this.pdfAttachmentViewer?.render({
|
|
|
attachments
|
|
|
});
|
|
|
});
|
|
@@ -894,7 +919,7 @@ const PDFViewerApplication = {
|
|
|
if (pdfDocument !== this.pdfDocument) {
|
|
|
return;
|
|
|
}
|
|
|
- this.pdfLayerViewer.render({
|
|
|
+ this.pdfLayerViewer?.render({
|
|
|
optionalContentConfig,
|
|
|
pdfDocument
|
|
|
});
|
|
@@ -950,7 +975,6 @@ const PDFViewerApplication = {
|
|
|
return false;
|
|
|
}
|
|
|
console.warn("Warning: JavaScript support is not enabled");
|
|
|
- this.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
|
|
|
return true;
|
|
|
});
|
|
|
if (!triggerAutoPrint) {
|
|
@@ -999,42 +1023,12 @@ const PDFViewerApplication = {
|
|
|
} else {
|
|
|
console.warn("Warning: XFA support is not enabled");
|
|
|
}
|
|
|
- this.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
|
|
|
} else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) {
|
|
|
console.warn("Warning: Interactive form support is not enabled");
|
|
|
- this.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
|
|
|
}
|
|
|
if (info.IsSignaturesPresent) {
|
|
|
console.warn("Warning: Digital signatures validation is not supported");
|
|
|
- this.fallback(_pdf.UNSUPPORTED_FEATURES.signatures);
|
|
|
- }
|
|
|
- let versionId = "other";
|
|
|
- if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) {
|
|
|
- versionId = `v${info.PDFFormatVersion.replace(".", "_")}`;
|
|
|
- }
|
|
|
- let generatorId = "other";
|
|
|
- if (info.Producer) {
|
|
|
- const producer = info.Producer.toLowerCase();
|
|
|
- KNOWN_GENERATORS.some(function (generator) {
|
|
|
- if (!producer.includes(generator)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- generatorId = generator.replace(/[ .-]/g, "_");
|
|
|
- return true;
|
|
|
- });
|
|
|
}
|
|
|
- let formType = null;
|
|
|
- if (info.IsXFAPresent) {
|
|
|
- formType = "xfa";
|
|
|
- } else if (info.IsAcroFormPresent) {
|
|
|
- formType = "acroform";
|
|
|
- }
|
|
|
- this.externalServices.reportTelemetry({
|
|
|
- type: "documentInfo",
|
|
|
- version: versionId,
|
|
|
- generator: generatorId,
|
|
|
- formType
|
|
|
- });
|
|
|
this.eventBus.dispatch("metadataloaded", {
|
|
|
source: this
|
|
|
});
|
|
@@ -1069,9 +1063,9 @@ const PDFViewerApplication = {
|
|
|
toolbar
|
|
|
} = this;
|
|
|
pdfViewer.setPageLabels(labels);
|
|
|
- pdfThumbnailViewer.setPageLabels(labels);
|
|
|
- toolbar.setPagesCount(numLabels, true);
|
|
|
- toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
|
|
|
+ pdfThumbnailViewer?.setPageLabels(labels);
|
|
|
+ toolbar?.setPagesCount(numLabels, true);
|
|
|
+ toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
|
|
|
},
|
|
|
_initializePdfHistory({
|
|
|
fingerprint,
|
|
@@ -1146,7 +1140,7 @@ const PDFViewerApplication = {
|
|
|
}
|
|
|
};
|
|
|
this.isInitialViewSet = true;
|
|
|
- this.pdfSidebar.setInitialView(sidebarView);
|
|
|
+ this.pdfSidebar?.setInitialView(sidebarView);
|
|
|
setViewerModes(scrollMode, spreadMode);
|
|
|
if (this.initialBookmark) {
|
|
|
setRotation(this.initialRotation);
|
|
@@ -1157,8 +1151,8 @@ const PDFViewerApplication = {
|
|
|
setRotation(rotation);
|
|
|
this.pdfLinkService.setHash(storedHash);
|
|
|
}
|
|
|
- this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
|
|
|
- this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
|
|
|
+ this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
|
|
|
+ this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber);
|
|
|
if (!this.pdfViewer.currentScaleValue) {
|
|
|
this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
|
|
|
}
|
|
@@ -1168,12 +1162,12 @@ const PDFViewerApplication = {
|
|
|
return;
|
|
|
}
|
|
|
this.pdfViewer.cleanup();
|
|
|
- this.pdfThumbnailViewer.cleanup();
|
|
|
+ this.pdfThumbnailViewer?.cleanup();
|
|
|
this.pdfDocument.cleanup(this.pdfViewer.renderer === _ui_utils.RendererType.SVG);
|
|
|
},
|
|
|
forceRendering() {
|
|
|
this.pdfRenderingQueue.printing = !!this.printService;
|
|
|
- this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS;
|
|
|
+ this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS;
|
|
|
this.pdfRenderingQueue.renderHighestPriority();
|
|
|
},
|
|
|
beforePrint() {
|
|
@@ -1204,9 +1198,6 @@ const PDFViewerApplication = {
|
|
|
this.forceRendering();
|
|
|
this.setTitle();
|
|
|
printService.layout();
|
|
|
- this.externalServices.reportTelemetry({
|
|
|
- type: "print"
|
|
|
- });
|
|
|
if (this._hasAnnotationEditors) {
|
|
|
this.externalServices.reportTelemetry({
|
|
|
type: "editing",
|
|
@@ -1254,6 +1245,7 @@ const PDFViewerApplication = {
|
|
|
eventBus._on("hashchange", webViewerHashchange);
|
|
|
eventBus._on("beforeprint", _boundEvents.beforePrint);
|
|
|
eventBus._on("afterprint", _boundEvents.afterPrint);
|
|
|
+ eventBus._on("pagerender", webViewerPageRender);
|
|
|
eventBus._on("pagerendered", webViewerPageRendered);
|
|
|
eventBus._on("updateviewarea", webViewerUpdateViewarea);
|
|
|
eventBus._on("pagechanging", webViewerPageChanging);
|
|
@@ -1366,6 +1358,7 @@ const PDFViewerApplication = {
|
|
|
eventBus._off("hashchange", webViewerHashchange);
|
|
|
eventBus._off("beforeprint", _boundEvents.beforePrint);
|
|
|
eventBus._off("afterprint", _boundEvents.afterPrint);
|
|
|
+ eventBus._off("pagerender", webViewerPageRender);
|
|
|
eventBus._off("pagerendered", webViewerPageRendered);
|
|
|
eventBus._off("updateviewarea", webViewerUpdateViewarea);
|
|
|
eventBus._off("pagechanging", webViewerPageChanging);
|
|
@@ -1438,7 +1431,7 @@ const PDFViewerApplication = {
|
|
|
this._wheelUnusedTicks = 0;
|
|
|
}
|
|
|
this._wheelUnusedTicks += ticks;
|
|
|
- const wholeTicks = Math.sign(this._wheelUnusedTicks) * Math.floor(Math.abs(this._wheelUnusedTicks));
|
|
|
+ const wholeTicks = Math.trunc(this._wheelUnusedTicks);
|
|
|
this._wheelUnusedTicks -= wholeTicks;
|
|
|
return wholeTicks;
|
|
|
},
|
|
@@ -1446,18 +1439,6 @@ const PDFViewerApplication = {
|
|
|
document.blockUnblockOnload?.(false);
|
|
|
this._unblockDocumentLoadEvent = () => {};
|
|
|
},
|
|
|
- _reportDocumentStatsTelemetry() {
|
|
|
- const {
|
|
|
- stats
|
|
|
- } = this.pdfDocument;
|
|
|
- if (stats !== this._docStats) {
|
|
|
- this._docStats = stats;
|
|
|
- this.externalServices.reportTelemetry({
|
|
|
- type: "documentStats",
|
|
|
- stats
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
get scriptingReady() {
|
|
|
return this.pdfScriptingManager.ready;
|
|
|
}
|
|
@@ -1558,14 +1539,14 @@ function webViewerInitialized() {
|
|
|
});
|
|
|
}
|
|
|
if (!PDFViewerApplication.supportsPrinting) {
|
|
|
- appConfig.toolbar.print.classList.add("hidden");
|
|
|
- appConfig.secondaryToolbar.printButton.classList.add("hidden");
|
|
|
+ appConfig.toolbar?.print.classList.add("hidden");
|
|
|
+ appConfig.secondaryToolbar?.printButton.classList.add("hidden");
|
|
|
}
|
|
|
if (!PDFViewerApplication.supportsFullscreen) {
|
|
|
- appConfig.secondaryToolbar.presentationModeButton.classList.add("hidden");
|
|
|
+ appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden");
|
|
|
}
|
|
|
if (PDFViewerApplication.supportsIntegratedFind) {
|
|
|
- appConfig.toolbar.viewFind.classList.add("hidden");
|
|
|
+ appConfig.toolbar?.viewFind.classList.add("hidden");
|
|
|
}
|
|
|
appConfig.mainContainer.addEventListener("transitionend", function (evt) {
|
|
|
if (evt.target === this) {
|
|
@@ -1586,16 +1567,23 @@ function webViewerInitialized() {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+function webViewerPageRender({
|
|
|
+ pageNumber
|
|
|
+}) {
|
|
|
+ if (pageNumber === PDFViewerApplication.page) {
|
|
|
+ PDFViewerApplication.toolbar?.updateLoadingIndicatorState(true);
|
|
|
+ }
|
|
|
+}
|
|
|
function webViewerPageRendered({
|
|
|
pageNumber,
|
|
|
error
|
|
|
}) {
|
|
|
if (pageNumber === PDFViewerApplication.page) {
|
|
|
- PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
|
|
|
+ PDFViewerApplication.toolbar?.updateLoadingIndicatorState(false);
|
|
|
}
|
|
|
- if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
|
|
|
+ if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
|
|
|
const pageView = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
|
|
|
- const thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageNumber - 1);
|
|
|
+ const thumbnailView = PDFViewerApplication.pdfThumbnailViewer?.getThumbnail(pageNumber - 1);
|
|
|
if (pageView && thumbnailView) {
|
|
|
thumbnailView.setImage(pageView);
|
|
|
}
|
|
@@ -1605,7 +1593,6 @@ function webViewerPageRendered({
|
|
|
PDFViewerApplication._otherError(msg, error);
|
|
|
});
|
|
|
}
|
|
|
- PDFViewerApplication._reportDocumentStatsTelemetry();
|
|
|
}
|
|
|
function webViewerPageMode({
|
|
|
mode
|
|
@@ -1632,16 +1619,16 @@ function webViewerPageMode({
|
|
|
console.error('Invalid "pagemode" hash parameter: ' + mode);
|
|
|
return;
|
|
|
}
|
|
|
- PDFViewerApplication.pdfSidebar.switchView(view, true);
|
|
|
+ PDFViewerApplication.pdfSidebar?.switchView(view, true);
|
|
|
}
|
|
|
function webViewerNamedAction(evt) {
|
|
|
switch (evt.action) {
|
|
|
case "GoToPage":
|
|
|
- PDFViewerApplication.appConfig.toolbar.pageNumber.select();
|
|
|
+ PDFViewerApplication.appConfig.toolbar?.pageNumber.select();
|
|
|
break;
|
|
|
case "Find":
|
|
|
if (!PDFViewerApplication.supportsIntegratedFind) {
|
|
|
- PDFViewerApplication.findBar.toggle();
|
|
|
+ PDFViewerApplication?.findBar.toggle();
|
|
|
}
|
|
|
break;
|
|
|
case "Print":
|
|
@@ -1675,11 +1662,10 @@ function webViewerUpdateViewarea({
|
|
|
rotation: location.rotation
|
|
|
}).catch(() => {});
|
|
|
}
|
|
|
- const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
|
|
|
- PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
|
|
|
- const currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
|
|
|
- const loading = currentPage?.renderingState !== _ui_utils.RenderingStates.FINISHED;
|
|
|
- PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
|
|
|
+ if (PDFViewerApplication.appConfig.secondaryToolbar) {
|
|
|
+ const href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
|
|
|
+ PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
|
|
|
+ }
|
|
|
}
|
|
|
function webViewerScrollModeChanged(evt) {
|
|
|
if (PDFViewerApplication.isInitialViewSet && !PDFViewerApplication.pdfViewer.isInPresentationMode) {
|
|
@@ -1700,7 +1686,6 @@ function webViewerResize() {
|
|
|
if (pdfRenderingQueue.printing && window.matchMedia("print").matches) {
|
|
|
return;
|
|
|
}
|
|
|
- pdfViewer.updateContainerHeightCss();
|
|
|
if (!pdfDocument) {
|
|
|
return;
|
|
|
}
|
|
@@ -1787,7 +1772,7 @@ function webViewerPageNumberChanged(evt) {
|
|
|
PDFViewerApplication.pdfLinkService.goToPage(evt.value);
|
|
|
}
|
|
|
if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
|
|
|
- PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
|
|
|
+ PDFViewerApplication.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
|
|
|
}
|
|
|
}
|
|
|
function webViewerScaleChanged(evt) {
|
|
@@ -1809,7 +1794,7 @@ function webViewerSwitchSpreadMode(evt) {
|
|
|
PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
|
|
|
}
|
|
|
function webViewerDocumentProperties() {
|
|
|
- PDFViewerApplication.pdfDocumentProperties.open();
|
|
|
+ PDFViewerApplication.pdfDocumentProperties?.open();
|
|
|
}
|
|
|
function webViewerFindFromUrlHash(evt) {
|
|
|
PDFViewerApplication.eventBus.dispatch("find", {
|
|
@@ -1847,15 +1832,17 @@ function webViewerUpdateFindControlState({
|
|
|
rawQuery
|
|
|
});
|
|
|
} else {
|
|
|
- PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
|
|
|
+ PDFViewerApplication.findBar?.updateUIState(state, previous, matchesCount);
|
|
|
}
|
|
|
}
|
|
|
function webViewerScaleChanging(evt) {
|
|
|
- PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
|
|
|
+ PDFViewerApplication.toolbar?.setPageScale(evt.presetValue, evt.scale);
|
|
|
PDFViewerApplication.pdfViewer.update();
|
|
|
}
|
|
|
function webViewerRotationChanging(evt) {
|
|
|
- PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
|
|
|
+ if (PDFViewerApplication.pdfThumbnailViewer) {
|
|
|
+ PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
|
|
|
+ }
|
|
|
PDFViewerApplication.forceRendering();
|
|
|
PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
|
|
|
}
|
|
@@ -1863,11 +1850,13 @@ function webViewerPageChanging({
|
|
|
pageNumber,
|
|
|
pageLabel
|
|
|
}) {
|
|
|
- PDFViewerApplication.toolbar.setPageNumber(pageNumber, pageLabel);
|
|
|
- PDFViewerApplication.secondaryToolbar.setPageNumber(pageNumber);
|
|
|
- if (PDFViewerApplication.pdfSidebar.visibleView === _ui_utils.SidebarView.THUMBS) {
|
|
|
- PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(pageNumber);
|
|
|
+ PDFViewerApplication.toolbar?.setPageNumber(pageNumber, pageLabel);
|
|
|
+ PDFViewerApplication.secondaryToolbar?.setPageNumber(pageNumber);
|
|
|
+ if (PDFViewerApplication.pdfSidebar?.visibleView === _ui_utils.SidebarView.THUMBS) {
|
|
|
+ PDFViewerApplication.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber);
|
|
|
}
|
|
|
+ const currentPage = PDFViewerApplication.pdfViewer.getPageView(pageNumber - 1);
|
|
|
+ PDFViewerApplication.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === _ui_utils.RenderingStates.RUNNING);
|
|
|
}
|
|
|
function webViewerResolutionChange(evt) {
|
|
|
PDFViewerApplication.pdfViewer.refresh();
|
|
@@ -1921,9 +1910,9 @@ function webViewerWheel(evt) {
|
|
|
const currentScale = pdfViewer.currentScale;
|
|
|
if (previousScale !== currentScale) {
|
|
|
const scaleCorrectionFactor = currentScale / previousScale - 1;
|
|
|
- const rect = pdfViewer.container.getBoundingClientRect();
|
|
|
- const dx = evt.clientX - rect.left;
|
|
|
- const dy = evt.clientY - rect.top;
|
|
|
+ const [top, left] = pdfViewer.containerTopLeft;
|
|
|
+ const dx = evt.clientX - left;
|
|
|
+ const dy = evt.clientY - top;
|
|
|
pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
|
|
|
pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
|
|
|
}
|
|
@@ -1937,11 +1926,11 @@ function webViewerTouchStart(evt) {
|
|
|
}
|
|
|
}
|
|
|
function webViewerClick(evt) {
|
|
|
- if (!PDFViewerApplication.secondaryToolbar.isOpen) {
|
|
|
+ if (!PDFViewerApplication.secondaryToolbar?.isOpen) {
|
|
|
return;
|
|
|
}
|
|
|
const appConfig = PDFViewerApplication.appConfig;
|
|
|
- if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
|
|
|
+ if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar?.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar?.toggleButton) {
|
|
|
PDFViewerApplication.secondaryToolbar.close();
|
|
|
}
|
|
|
}
|
|
@@ -1961,7 +1950,7 @@ function webViewerKeyDown(evt) {
|
|
|
switch (evt.keyCode) {
|
|
|
case 70:
|
|
|
if (!PDFViewerApplication.supportsIntegratedFind && !evt.shiftKey) {
|
|
|
- PDFViewerApplication.findBar.open();
|
|
|
+ PDFViewerApplication.findBar?.open();
|
|
|
handled = true;
|
|
|
}
|
|
|
break;
|
|
@@ -2054,8 +2043,10 @@ function webViewerKeyDown(evt) {
|
|
|
});
|
|
|
break;
|
|
|
case 71:
|
|
|
- PDFViewerApplication.appConfig.toolbar.pageNumber.select();
|
|
|
- handled = true;
|
|
|
+ if (PDFViewerApplication.appConfig.toolbar) {
|
|
|
+ PDFViewerApplication.appConfig.toolbar.pageNumber.select();
|
|
|
+ handled = true;
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -2099,11 +2090,11 @@ function webViewerKeyDown(evt) {
|
|
|
turnPage = -1;
|
|
|
break;
|
|
|
case 27:
|
|
|
- if (PDFViewerApplication.secondaryToolbar.isOpen) {
|
|
|
+ if (PDFViewerApplication.secondaryToolbar?.isOpen) {
|
|
|
PDFViewerApplication.secondaryToolbar.close();
|
|
|
handled = true;
|
|
|
}
|
|
|
- if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
|
|
|
+ if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar?.opened) {
|
|
|
PDFViewerApplication.findBar.close();
|
|
|
handled = true;
|
|
|
}
|
|
@@ -2145,16 +2136,16 @@ function webViewerKeyDown(evt) {
|
|
|
}
|
|
|
break;
|
|
|
case 83:
|
|
|
- PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
|
|
|
+ PDFViewerApplication.pdfCursorTools?.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
|
|
|
break;
|
|
|
case 72:
|
|
|
- PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
|
|
|
+ PDFViewerApplication.pdfCursorTools?.switchTool(_pdf_cursor_tools.CursorTool.HAND);
|
|
|
break;
|
|
|
case 82:
|
|
|
PDFViewerApplication.rotatePages(90);
|
|
|
break;
|
|
|
case 115:
|
|
|
- PDFViewerApplication.pdfSidebar.toggle();
|
|
|
+ PDFViewerApplication.pdfSidebar?.toggle();
|
|
|
break;
|
|
|
}
|
|
|
if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) {
|