diff options
Diffstat (limited to 'js/pdfjs/web/viewer.js')
-rw-r--r-- | js/pdfjs/web/viewer.js | 743 |
1 files changed, 410 insertions, 333 deletions
diff --git a/js/pdfjs/web/viewer.js b/js/pdfjs/web/viewer.js index 6ecebce..3cf8bee 100644 --- a/js/pdfjs/web/viewer.js +++ b/js/pdfjs/web/viewer.js @@ -256,8 +256,17 @@ function webViewerLoad() { window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication; window.PDFViewerApplicationOptions = pdfjsWebAppOptions.AppOptions; const event = document.createEvent("CustomEvent"); - event.initCustomEvent("webviewerloaded", true, true, {}); - document.dispatchEvent(event); + event.initCustomEvent("webviewerloaded", true, true, { + source: window + }); + + try { + parent.document.dispatchEvent(event); + } catch (ex) { + console.error(`webviewerloaded: ${ex}`); + document.dispatchEvent(event); + } + pdfjsWebApp.PDFViewerApplication.run(config); } @@ -283,7 +292,7 @@ var _ui_utils = __webpack_require__(2); var _app_options = __webpack_require__(3); -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); var _pdf_cursor_tools = __webpack_require__(6); @@ -327,6 +336,7 @@ const DEFAULT_SCALE_DELTA = 1.1; const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; const FORCE_PAGES_LOADED_TIMEOUT = 10000; const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; +const ENABLE_PERMISSIONS_CLASS = "enablePermissions"; const ViewOnLoad = { UNKNOWN: -1, PREVIOUS: 0, @@ -375,6 +385,10 @@ class DefaultExternalServices { }); } + static get isInAutomation() { + return (0, _pdfjsLib.shadow)(this, "isInAutomation", false); + } + } exports.DefaultExternalServices = DefaultExternalServices; @@ -440,7 +454,7 @@ const PDFViewerApplication = { }, async _readPreferences() { - if (_app_options.AppOptions.get("disablePreferences") === true) { + if (_app_options.AppOptions.get("disablePreferences")) { return; } @@ -469,40 +483,40 @@ const PDFViewerApplication = { const hashParams = (0, _ui_utils.parseQueryString)(hash), waitOn = []; - if ("disableworker" in hashParams && hashParams["disableworker"] === "true") { + if ("disableworker" in hashParams && hashParams.disableworker === "true") { waitOn.push(loadFakeWorker()); } if ("disablerange" in hashParams) { - _app_options.AppOptions.set("disableRange", hashParams["disablerange"] === "true"); + _app_options.AppOptions.set("disableRange", hashParams.disablerange === "true"); } if ("disablestream" in hashParams) { - _app_options.AppOptions.set("disableStream", hashParams["disablestream"] === "true"); + _app_options.AppOptions.set("disableStream", hashParams.disablestream === "true"); } if ("disableautofetch" in hashParams) { - _app_options.AppOptions.set("disableAutoFetch", hashParams["disableautofetch"] === "true"); + _app_options.AppOptions.set("disableAutoFetch", hashParams.disableautofetch === "true"); } if ("disablefontface" in hashParams) { - _app_options.AppOptions.set("disableFontFace", hashParams["disablefontface"] === "true"); + _app_options.AppOptions.set("disableFontFace", hashParams.disablefontface === "true"); } if ("disablehistory" in hashParams) { - _app_options.AppOptions.set("disableHistory", hashParams["disablehistory"] === "true"); + _app_options.AppOptions.set("disableHistory", hashParams.disablehistory === "true"); } if ("webgl" in hashParams) { - _app_options.AppOptions.set("enableWebGL", hashParams["webgl"] === "true"); + _app_options.AppOptions.set("enableWebGL", hashParams.webgl === "true"); } if ("verbosity" in hashParams) { - _app_options.AppOptions.set("verbosity", hashParams["verbosity"] | 0); + _app_options.AppOptions.set("verbosity", hashParams.verbosity | 0); } if ("textlayer" in hashParams) { - switch (hashParams["textlayer"]) { + switch (hashParams.textlayer) { case "off": _app_options.AppOptions.set("textLayerMode", _ui_utils.TextLayerMode.DISABLE); @@ -512,7 +526,7 @@ const PDFViewerApplication = { case "shadow": case "hover": const viewer = this.appConfig.viewerContainer; - viewer.classList.add("textLayer-" + hashParams["textlayer"]); + viewer.classList.add("textLayer-" + hashParams.textlayer); break; } } @@ -520,12 +534,14 @@ const PDFViewerApplication = { if ("pdfbug" in hashParams) { _app_options.AppOptions.set("pdfBug", true); - const enabled = hashParams["pdfbug"].split(","); + _app_options.AppOptions.set("fontExtraProperties", true); + + const enabled = hashParams.pdfbug.split(","); waitOn.push(loadAndEnablePDFBug(enabled)); } if ("locale" in hashParams) { - _app_options.AppOptions.set("locale", hashParams["locale"]); + _app_options.AppOptions.set("locale", hashParams.locale); } return Promise.all(waitOn).catch(reason => { @@ -543,11 +559,11 @@ const PDFViewerApplication = { async _initializeViewerComponents() { const appConfig = this.appConfig; - this.overlayManager = new _overlay_manager.OverlayManager(); const eventBus = appConfig.eventBus || new _ui_utils.EventBus({ - dispatchToDOM: _app_options.AppOptions.get("eventBusDispatchToDOM") + isInAutomation: this.externalServices.isInAutomation }); this.eventBus = eventBus; + this.overlayManager = new _overlay_manager.OverlayManager(); const pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue(); pdfRenderingQueue.onIdle = this.cleanup.bind(this); this.pdfRenderingQueue = pdfRenderingQueue; @@ -702,14 +718,14 @@ const PDFViewerApplication = { return this.pdfDocument ? this.pdfDocument.numPages : 0; }, - set page(val) { - this.pdfViewer.currentPageNumber = val; - }, - get page() { return this.pdfViewer.currentPageNumber; }, + set page(val) { + this.pdfViewer.currentPageNumber = val; + }, + get printing() { return !!this.printService; }, @@ -794,6 +810,7 @@ const PDFViewerApplication = { this.pdfDocumentProperties.setDocument(null); } + webViewerResetPermissions(); this.store = null; this.isInitialViewSet = false; this.downloadComplete = false; @@ -908,7 +925,7 @@ const PDFViewerApplication = { this.error(msg, { message }); - throw new Error(msg); + throw exception; }); }); }, @@ -1034,7 +1051,7 @@ const PDFViewerApplication = { if (percent > this.loadingBar.percent || isNaN(percent)) { this.loadingBar.percent = percent; - const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams["disableAutoFetch"] : _app_options.AppOptions.get("disableAutoFetch"); + const disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams.disableAutoFetch : _app_options.AppOptions.get("disableAutoFetch"); if (disableAutoFetch && percent) { if (this.disableAutoFetchLoadingBarTimeout) { @@ -1067,7 +1084,6 @@ const PDFViewerApplication = { const openActionPromise = pdfDocument.getOpenAction().catch(function () {}); this.toolbar.setPagesCount(pdfDocument.numPages, false); this.secondaryToolbar.setPagesCount(pdfDocument.numPages); - const store = this.store = new _view_history.ViewHistory(pdfDocument.fingerprint); let baseDocumentUrl; baseDocumentUrl = null; this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl); @@ -1081,19 +1097,21 @@ const PDFViewerApplication = { } = pdfViewer; const pdfThumbnailViewer = this.pdfThumbnailViewer; pdfThumbnailViewer.setDocument(pdfDocument); + const storedPromise = (this.store = new _view_history.ViewHistory(pdfDocument.fingerprint)).getMultiple({ + page: null, + zoom: _ui_utils.DEFAULT_SCALE_VALUE, + scrollLeft: "0", + scrollTop: "0", + rotation: null, + sidebarView: _pdf_sidebar.SidebarView.UNKNOWN, + scrollMode: _ui_utils.ScrollMode.UNKNOWN, + spreadMode: _ui_utils.SpreadMode.UNKNOWN + }).catch(() => { + return Object.create(null); + }); firstPagePromise.then(pdfPage => { this.loadingBar.setWidth(this.appConfig.viewerContainer); - const storePromise = store.getMultiple({ - page: null, - zoom: _ui_utils.DEFAULT_SCALE_VALUE, - scrollLeft: "0", - scrollTop: "0", - rotation: null, - sidebarView: _pdf_sidebar.SidebarView.UNKNOWN, - scrollMode: _ui_utils.ScrollMode.UNKNOWN, - spreadMode: _ui_utils.SpreadMode.UNKNOWN - }).catch(() => {}); - Promise.all([_ui_utils.animationStarted, storePromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, values = {}, pageLayout, pageMode, openAction]) => { + Promise.all([_ui_utils.animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => { const viewOnLoad = _app_options.AppOptions.get("viewOnLoad"); this._initializePdfHistory({ @@ -1115,20 +1133,20 @@ const PDFViewerApplication = { let spreadMode = _app_options.AppOptions.get("spreadModeOnLoad"); - if (values.page && viewOnLoad !== ViewOnLoad.INITIAL) { - hash = `page=${values.page}&zoom=${zoom || values.zoom},` + `${values.scrollLeft},${values.scrollTop}`; - rotation = parseInt(values.rotation, 10); + if (stored.page && viewOnLoad !== ViewOnLoad.INITIAL) { + hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`; + rotation = parseInt(stored.rotation, 10); if (sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) { - sidebarView = values.sidebarView | 0; + sidebarView = stored.sidebarView | 0; } if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) { - scrollMode = values.scrollMode | 0; + scrollMode = stored.scrollMode | 0; } if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) { - spreadMode = values.spreadMode | 0; + spreadMode = stored.spreadMode | 0; } } @@ -1154,6 +1172,8 @@ const PDFViewerApplication = { pdfViewer.focus(); } + this._initializePermissions(pdfDocument); + await Promise.race([pagesPromise, new Promise(resolve => { setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT); })]); @@ -1175,162 +1195,194 @@ const PDFViewerApplication = { pdfViewer.update(); }); }); - pdfDocument.getPageLabels().then(labels => { - if (!labels || _app_options.AppOptions.get("disablePageLabels")) { - return; - } - - const numLabels = labels.length; + pagesPromise.then(() => { + this._initializeAutoPrint(pdfDocument, openActionPromise); + }); + onePageRendered.then(() => { + pdfDocument.getOutline().then(outline => { + this.pdfOutlineViewer.render({ + outline + }); + }); + pdfDocument.getAttachments().then(attachments => { + this.pdfAttachmentViewer.render({ + attachments + }); + }); + }); - if (numLabels !== this.pagesCount) { - console.error("The number of Page Labels does not match " + "the number of pages in the document."); - return; - } + this._initializePageLabels(pdfDocument); - let i = 0; + this._initializeMetadata(pdfDocument); + }, - while (i < numLabels && labels[i] === (i + 1).toString()) { - i++; - } + async _initializeAutoPrint(pdfDocument, openActionPromise) { + const [openAction, javaScript] = await Promise.all([openActionPromise, pdfDocument.getJavaScript()]); - if (i === numLabels) { - return; - } + if (pdfDocument !== this.pdfDocument) { + return; + } - pdfViewer.setPageLabels(labels); - pdfThumbnailViewer.setPageLabels(labels); - this.toolbar.setPagesCount(pdfDocument.numPages, true); - this.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel); - }); - pagesPromise.then(async () => { - const [openAction, javaScript] = await Promise.all([openActionPromise, pdfDocument.getJavaScript()]); - let triggerAutoPrint = false; + let triggerAutoPrint = false; - if (openAction && openAction.action === "Print") { - triggerAutoPrint = true; - } + if (openAction && openAction.action === "Print") { + triggerAutoPrint = true; + } - if (javaScript) { - javaScript.some(js => { - if (!js) { - return false; - } + if (javaScript) { + javaScript.some(js => { + if (!js) { + return false; + } - console.warn("Warning: JavaScript is not supported"); - this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript); - return true; - }); + console.warn("Warning: JavaScript is not supported"); + this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript); + return true; + }); - if (!triggerAutoPrint) { - for (const js of javaScript) { - if (js && _ui_utils.AutoPrintRegExp.test(js)) { - triggerAutoPrint = true; - break; - } + if (!triggerAutoPrint) { + for (const js of javaScript) { + if (js && _ui_utils.AutoPrintRegExp.test(js)) { + triggerAutoPrint = true; + break; } } } + } - if (!this.supportsPrinting) { - return; - } + if (!this.supportsPrinting) { + return; + } - if (triggerAutoPrint) { - setTimeout(function () { - window.print(); - }); - } - }); - onePageRendered.then(() => { - pdfDocument.getOutline().then(outline => { - this.pdfOutlineViewer.render({ - outline - }); + if (triggerAutoPrint) { + setTimeout(function () { + window.print(); }); - pdfDocument.getAttachments().then(attachments => { - this.pdfAttachmentViewer.render({ - attachments - }); - }); - }); - pdfDocument.getMetadata().then(({ + } + }, + + async _initializeMetadata(pdfDocument) { + const { info, metadata, contentDispositionFilename - }) => { - this.documentInfo = info; - this.metadata = metadata; - this.contentDispositionFilename = contentDispositionFilename; - console.log("PDF " + pdfDocument.fingerprint + " [" + info.PDFFormatVersion + " " + (info.Producer || "-").trim() + " / " + (info.Creator || "-").trim() + "]" + " (PDF.js: " + (_pdfjsLib.version || "-") + (_app_options.AppOptions.get("enableWebGL") ? " [WebGL]" : "") + ")"); - let pdfTitle; - const infoTitle = info && info["Title"]; + } = await pdfDocument.getMetadata(); - if (infoTitle) { - pdfTitle = infoTitle; - } + if (pdfDocument !== this.pdfDocument) { + return; + } - const metadataTitle = metadata && metadata.get("dc:title"); + this.documentInfo = info; + this.metadata = metadata; + this.contentDispositionFilename = contentDispositionFilename; + console.log(`PDF ${pdfDocument.fingerprint} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "-"}` + `${this.pdfViewer.enableWebGL ? " [WebGL]" : ""})`); + let pdfTitle; + const infoTitle = info && info.Title; - if (metadataTitle) { - if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) { - pdfTitle = metadataTitle; - } - } + if (infoTitle) { + pdfTitle = infoTitle; + } - if (pdfTitle) { - this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`); - } else if (contentDispositionFilename) { - this.setTitle(contentDispositionFilename); - } + const metadataTitle = metadata && metadata.get("dc:title"); - if (info.IsAcroFormPresent) { - console.warn("Warning: AcroForm/XFA is not supported"); - this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms); + if (metadataTitle) { + if (metadataTitle !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(metadataTitle)) { + pdfTitle = metadataTitle; } + } - let versionId = "other"; - 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"]; - - if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) { - versionId = `v${info.PDFFormatVersion.replace(".", "_")}`; - } + if (pdfTitle) { + this.setTitle(`${pdfTitle} - ${contentDispositionFilename || document.title}`); + } else if (contentDispositionFilename) { + this.setTitle(contentDispositionFilename); + } - let generatorId = "other"; - 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"]; + if (info.IsAcroFormPresent) { + console.warn("Warning: AcroForm/XFA is not supported"); + this.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms); + } - if (info.Producer) { - const producer = info.Producer.toLowerCase(); - KNOWN_GENERATORS.some(function (generator) { - if (!producer.includes(generator)) { - return false; - } + let versionId = "other"; + 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"]; - generatorId = generator.replace(/[ .\-]/g, "_"); - return true; - }); - } + if (KNOWN_VERSIONS.includes(info.PDFFormatVersion)) { + versionId = `v${info.PDFFormatVersion.replace(".", "_")}`; + } - let formType = null; + let generatorId = "other"; + 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"]; - if (info.IsAcroFormPresent) { - formType = info.IsXFAPresent ? "xfa" : "acroform"; - } + if (info.Producer) { + const producer = info.Producer.toLowerCase(); + KNOWN_GENERATORS.some(function (generator) { + if (!producer.includes(generator)) { + return false; + } - this.externalServices.reportTelemetry({ - type: "documentInfo", - version: versionId, - generator: generatorId, - formType + generatorId = generator.replace(/[ .\-]/g, "_"); + return true; }); + } + + let formType = null; + + if (info.IsAcroFormPresent) { + formType = info.IsXFAPresent ? "xfa" : "acroform"; + } + + this.externalServices.reportTelemetry({ + type: "documentInfo", + version: versionId, + generator: generatorId, + formType }); }, + async _initializePageLabels(pdfDocument) { + const labels = await pdfDocument.getPageLabels(); + + if (pdfDocument !== this.pdfDocument) { + return; + } + + if (!labels || _app_options.AppOptions.get("disablePageLabels")) { + return; + } + + const numLabels = labels.length; + + if (numLabels !== this.pagesCount) { + console.error("The number of Page Labels does not match the number of pages in the document."); + return; + } + + let i = 0; + + while (i < numLabels && labels[i] === (i + 1).toString()) { + i++; + } + + if (i === numLabels) { + return; + } + + const { + pdfViewer, + pdfThumbnailViewer, + toolbar + } = this; + pdfViewer.setPageLabels(labels); + pdfThumbnailViewer.setPageLabels(labels); + toolbar.setPagesCount(numLabels, true); + toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel); + }, + _initializePdfHistory({ fingerprint, viewOnLoad, initialDest = null }) { - if (_app_options.AppOptions.get("disableHistory") || this.isViewerEmbedded) { + if (this.isViewerEmbedded || _app_options.AppOptions.get("disableHistory")) { return; } @@ -1354,6 +1406,22 @@ const PDFViewerApplication = { } }, + async _initializePermissions(pdfDocument) { + const permissions = await pdfDocument.getPermissions(); + + if (pdfDocument !== this.pdfDocument) { + return; + } + + if (!permissions || !_app_options.AppOptions.get("enablePermissions")) { + return; + } + + if (!permissions.includes(_pdfjsLib.PermissionFlag.COPY)) { + this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS); + } + }, + setInitialView(storedHash, { rotation, sidebarView, @@ -1692,7 +1760,9 @@ const PDFViewerApplication = { _boundEvents } = this; window.removeEventListener("visibilitychange", webViewerVisibilityChange); - window.removeEventListener("wheel", webViewerWheel); + window.removeEventListener("wheel", webViewerWheel, { + passive: false + }); window.removeEventListener("click", webViewerClick); window.removeEventListener("keydown", webViewerKeyDown); window.removeEventListener("resize", _boundEvents.windowResize); @@ -1874,6 +1944,18 @@ let webViewerOpenFileViaURL; }; } +function webViewerResetPermissions() { + const { + appConfig + } = PDFViewerApplication; + + if (!appConfig) { + return; + } + + appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS); +} + function webViewerPageRendered(evt) { const pageNumber = evt.pageNumber; const pageIndex = pageNumber - 1; @@ -2066,7 +2148,7 @@ let webViewerFileInputChange, webViewerOpenFile; const file = evt.fileInput.files[0]; - if (URL.createObjectURL && !_app_options.AppOptions.get("disableCreateObjectURL")) { + if (!_app_options.AppOptions.get("disableCreateObjectURL")) { let url = URL.createObjectURL(file); if (file.name) { @@ -2425,12 +2507,27 @@ function webViewerKeyDown(evt) { } } + const { + eventBus + } = PDFViewerApplication; + if (cmd === 1 || cmd === 8) { switch (evt.keyCode) { case 83: - PDFViewerApplication.download(); + eventBus.dispatch("download", { + source: window + }); handled = true; break; + + case 79: + { + eventBus.dispatch("openfile", { + source: window + }); + handled = true; + } + break; } } @@ -2689,7 +2786,6 @@ exports.isValidRotation = isValidRotation; exports.isValidScrollMode = isValidScrollMode; exports.isValidSpreadMode = isValidSpreadMode; exports.isPortraitOrientation = isPortraitOrientation; -exports.getGlobalEventBus = getGlobalEventBus; exports.clamp = clamp; exports.getPDFFileNameFromURL = getPDFFileNameFromURL; exports.noContextMenuHandler = noContextMenuHandler; @@ -2897,7 +2993,7 @@ function binarySearchFirstItem(items, condition) { let minIndex = 0; let maxIndex = items.length - 1; - if (items.length === 0 || !condition(items[maxIndex])) { + if (maxIndex < 0 || !condition(items[maxIndex])) { return items.length; } @@ -3227,41 +3323,12 @@ const animationStarted = new Promise(function (resolve) { exports.animationStarted = animationStarted; function dispatchDOMEvent(eventName, args = null) { - const details = Object.create(null); - - if (args && args.length > 0) { - const obj = args[0]; - - for (const key in obj) { - const value = obj[key]; - - if (key === "source") { - if (value === window || value === document) { - return; - } - - continue; - } - - details[key] = value; - } - } - - const event = document.createEvent("CustomEvent"); - event.initCustomEvent(eventName, true, true, details); - document.dispatchEvent(event); + throw new Error("Not implemented: dispatchDOMEvent"); } class EventBus { - constructor({ - dispatchToDOM = false - } = {}) { + constructor(options) { this._listeners = Object.create(null); - this._dispatchToDOM = dispatchToDOM === true; - - if (dispatchToDOM) { - console.error("The `eventBusDispatchToDOM` option/preference is deprecated, " + "add event listeners to the EventBus instance rather than the DOM."); - } } on(eventName, listener) { @@ -3280,11 +3347,6 @@ class EventBus { const eventListeners = this._listeners[eventName]; if (!eventListeners || eventListeners.length === 0) { - if (this._dispatchToDOM) { - const args = Array.prototype.slice.call(arguments, 1); - dispatchDOMEvent(eventName, args); - } - return; } @@ -3312,10 +3374,6 @@ class EventBus { }); externalListeners = null; } - - if (this._dispatchToDOM) { - dispatchDOMEvent(eventName, args); - } } _on(eventName, listener, options = null) { @@ -3349,19 +3407,6 @@ class EventBus { } exports.EventBus = EventBus; -let globalEventBus = null; - -function getGlobalEventBus(dispatchToDOM = false) { - console.error("getGlobalEventBus is deprecated, use a manually created EventBus instance instead."); - - if (!globalEventBus) { - globalEventBus = new EventBus({ - dispatchToDOM - }); - } - - return globalEventBus; -} function clamp(v, min, max) { return Math.min(Math.max(v, min), max); @@ -3474,9 +3519,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.OptionKind = exports.AppOptions = void 0; -var _pdfjsLib = __webpack_require__(4); - -var _viewer_compatibility = __webpack_require__(5); +var _viewer_compatibility = __webpack_require__(4); const OptionKind = { VIEWER: 0x02, @@ -3498,6 +3541,11 @@ const defaultOptions = { value: "", kind: OptionKind.VIEWER + OptionKind.PREFERENCE }, + disableCreateObjectURL: { + value: false, + compatibility: _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL, + kind: OptionKind.VIEWER + }, disableHistory: { value: false, kind: OptionKind.VIEWER @@ -3506,15 +3554,15 @@ const defaultOptions = { value: false, kind: OptionKind.VIEWER + OptionKind.PREFERENCE }, - enablePrintAutoRotate: { + enablePermissions: { value: false, kind: OptionKind.VIEWER + OptionKind.PREFERENCE }, - enableWebGL: { + enablePrintAutoRotate: { value: false, kind: OptionKind.VIEWER + OptionKind.PREFERENCE }, - eventBusDispatchToDOM: { + enableWebGL: { value: false, kind: OptionKind.VIEWER + OptionKind.PREFERENCE }, @@ -3547,6 +3595,10 @@ const defaultOptions = { value: false, kind: OptionKind.VIEWER + OptionKind.PREFERENCE }, + printResolution: { + value: 150, + kind: OptionKind.VIEWER + }, renderer: { value: "canvas", kind: OptionKind.VIEWER + OptionKind.PREFERENCE @@ -3591,11 +3643,6 @@ const defaultOptions = { value: false, kind: OptionKind.API + OptionKind.PREFERENCE }, - disableCreateObjectURL: { - value: false, - compatibility: _pdfjsLib.apiCompatibilityParams.disableCreateObjectURL, - kind: OptionKind.API - }, disableFontFace: { value: false, kind: OptionKind.API + OptionKind.PREFERENCE @@ -3612,6 +3659,10 @@ const defaultOptions = { value: "", kind: OptionKind.API }, + fontExtraProperties: { + value: false, + kind: OptionKind.API + }, isEvalSupported: { value: true, kind: OptionKind.API @@ -3646,10 +3697,6 @@ const defaultOptions = { value: typeof navigator !== "undefined" ? navigator.language : "en-US", kind: OptionKind.VIEWER }; - defaultOptions.printResolution = { - value: 150, - kind: OptionKind.VIEWER - }; } const userOptions = Object.create(null); @@ -3724,30 +3771,25 @@ exports.AppOptions = AppOptions; "use strict"; -let pdfjsLib; - -if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) { - pdfjsLib = window["pdfjs-dist/build/pdf"]; -} else { - pdfjsLib = require("../build/pdf.js"); -} - -module.exports = pdfjsLib; - -/***/ }), -/* 5 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.viewerCompatibilityParams = void 0; const compatibilityParams = Object.create(null); { const userAgent = typeof navigator !== "undefined" && navigator.userAgent || ""; const platform = typeof navigator !== "undefined" && navigator.platform || ""; const maxTouchPoints = typeof navigator !== "undefined" && navigator.maxTouchPoints || 1; const isAndroid = /Android/.test(userAgent); + const isIE = /Trident/.test(userAgent); const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1; + const isIOSChrome = /CriOS/.test(userAgent); + + (function checkOnBlobSupport() { + if (isIE || isIOSChrome) { + compatibilityParams.disableCreateObjectURL = true; + } + })(); (function checkCanvasSizeLimitation() { if (isIOS || isAndroid) { @@ -3755,7 +3797,25 @@ const compatibilityParams = Object.create(null); } })(); } -exports.viewerCompatibilityParams = Object.freeze(compatibilityParams); +const viewerCompatibilityParams = Object.freeze(compatibilityParams); +exports.viewerCompatibilityParams = viewerCompatibilityParams; + +/***/ }), +/* 5 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +let pdfjsLib; + +if (typeof window !== "undefined" && window["pdfjs-dist/build/pdf"]) { + pdfjsLib = window["pdfjs-dist/build/pdf"]; +} else { + pdfjsLib = require("../build/pdf.js"); +} + +module.exports = pdfjsLib; /***/ }), /* 6 */ @@ -4689,7 +4749,7 @@ exports.PasswordPrompt = void 0; var _ui_utils = __webpack_require__(2); -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); class PasswordPrompt { constructor(options, overlayManager, l10n = _ui_utils.NullL10n) { @@ -4766,7 +4826,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.PDFAttachmentViewer = void 0; -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); class PDFAttachmentViewer { constructor({ @@ -4801,20 +4861,27 @@ class PDFAttachmentViewer { } _bindPdfLink(button, content, filename) { - if (this.downloadManager.disableCreateObjectURL) { - throw new Error('bindPdfLink: Unsupported "disableCreateObjectURL" value.'); - } - let blobUrl; - button.onclick = function () { + button.onclick = () => { if (!blobUrl) { - blobUrl = (0, _pdfjsLib.createObjectURL)(content, "application/pdf"); + blobUrl = URL.createObjectURL(new Blob([content], { + type: "application/pdf" + })); } let viewerUrl; viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename); - window.open(viewerUrl); + + try { + window.open(viewerUrl); + } catch (ex) { + console.error(`_bindPdfLink: ${ex}`); + URL.revokeObjectURL(blobUrl); + blobUrl = null; + this.downloadManager.downloadData(content, filename, "application/pdf"); + } + return false; }; } @@ -4915,7 +4982,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.PDFDocumentProperties = void 0; -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); var _ui_utils = __webpack_require__(2); @@ -4951,21 +5018,16 @@ class PDFDocumentProperties { this._reset(); - if (closeButton) { - closeButton.addEventListener("click", this.close.bind(this)); - } - + closeButton.addEventListener("click", this.close.bind(this)); this.overlayManager.register(this.overlayName, this.container, this.close.bind(this)); - if (eventBus) { - eventBus._on("pagechanging", evt => { - this._currentPageNumber = evt.pageNumber; - }); + eventBus._on("pagechanging", evt => { + this._currentPageNumber = evt.pageNumber; + }); - eventBus._on("rotationchanging", evt => { - this._pagesRotation = evt.pagesRotation; - }); - } + eventBus._on("rotationchanging", evt => { + this._pagesRotation = evt.pagesRotation; + }); this._isNonMetricLocale = true; l10n.getLanguage().then(locale => { @@ -4987,7 +5049,7 @@ class PDFDocumentProperties { const currentPageNumber = this._currentPageNumber; const pagesRotation = this._pagesRotation; - if (this.fieldData && currentPageNumber === this.fieldData["_currentPageNumber"] && pagesRotation === this.fieldData["_pagesRotation"]) { + if (this.fieldData && currentPageNumber === this.fieldData._currentPageNumber && pagesRotation === this.fieldData._pagesRotation) { this._updateUI(); return; @@ -4998,7 +5060,7 @@ class PDFDocumentProperties { metadata, contentDispositionFilename }) => { - return Promise.all([info, metadata, contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url || ""), this._parseFileSize(this.maybeFileSize), this._parseDate(info.CreationDate), this._parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => { + return Promise.all([info, metadata, contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url), this._parseFileSize(this.maybeFileSize), this._parseDate(info.CreationDate), this._parseDate(info.ModDate), this.pdfDocument.getPage(currentPageNumber).then(pdfPage => { return this._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation); }), this._parseLinearization(info.IsLinearized)]); }).then(([info, metadata, fileName, fileSize, creationDate, modDate, pageSize, isLinearized]) => { @@ -5030,12 +5092,12 @@ class PDFDocumentProperties { this.maybeFileSize = length; return this._parseFileSize(length); }).then(fileSize => { - if (fileSize === this.fieldData["fileSize"]) { + if (fileSize === this.fieldData.fileSize) { return; } const data = Object.assign(Object.create(null), this.fieldData); - data["fileSize"] = fileSize; + data.fileSize = fileSize; freezeFieldData(data); this._updateUI(); @@ -5215,10 +5277,10 @@ Object.defineProperty(exports, "__esModule", { }); exports.PDFFindBar = void 0; -var _ui_utils = __webpack_require__(2); - var _pdf_find_controller = __webpack_require__(15); +var _ui_utils = __webpack_require__(2); + const MATCHES_COUNT_LIMIT = 1000; class PDFFindBar { @@ -5234,7 +5296,7 @@ class PDFFindBar { this.findResultsCount = options.findResultsCount || null; this.findPreviousButton = options.findPreviousButton || null; this.findNextButton = options.findNextButton || null; - this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)(); + this.eventBus = eventBus; this.l10n = l10n; this.toggleButton.addEventListener("click", () => { this.toggle(); @@ -5426,12 +5488,12 @@ Object.defineProperty(exports, "__esModule", { }); exports.PDFFindController = exports.FindState = void 0; -var _ui_utils = __webpack_require__(2); - -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); var _pdf_find_utils = __webpack_require__(16); +var _ui_utils = __webpack_require__(2); + const FindState = { FOUND: 0, NOT_FOUND: 1, @@ -5474,7 +5536,7 @@ class PDFFindController { eventBus }) { this._linkService = linkService; - this._eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)(); + this._eventBus = eventBus; this._reset(); @@ -6221,7 +6283,7 @@ class PDFHistory { eventBus }) { this.linkService = linkService; - this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)(); + this.eventBus = eventBus; this._initialized = false; this._fingerprint = ""; this.reset(); @@ -6280,7 +6342,7 @@ class PDFHistory { hash, page, rotation - } = this._parseCurrentHash(); + } = this._parseCurrentHash(true); if (!hash || reInitialized || resetHistory) { this._pushOrReplaceState(null, true); @@ -6558,11 +6620,13 @@ class PDFHistory { this._numPositionUpdates = 0; } - _parseCurrentHash() { + _parseCurrentHash(checkNameddest = false) { const hash = unescape(getCurrentHash()).substring(1); - let page = (0, _ui_utils.parseQueryString)(hash).page | 0; + const params = (0, _ui_utils.parseQueryString)(hash); + const nameddest = params.nameddest || ""; + let page = params.page | 0; - if (!(Number.isInteger(page) && page > 0 && page <= this.linkService.pagesCount)) { + if (!(Number.isInteger(page) && page > 0 && page <= this.linkService.pagesCount) || checkNameddest && nameddest.length > 0) { page = null; } @@ -6799,7 +6863,7 @@ class PDFLinkService { externalLinkEnabled = true, ignoreDestinationZoom = false } = {}) { - this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)(); + this.eventBus = eventBus; this.externalLinkTarget = externalLinkTarget; this.externalLinkRel = externalLinkRel; this.externalLinkEnabled = externalLinkEnabled; @@ -6947,16 +7011,11 @@ class PDFLinkService { if ("search" in params) { this.eventBus.dispatch("findfromurlhash", { source: this, - query: params["search"].replace(/"/g, ""), - phraseSearch: params["phrase"] === "true" + query: params.search.replace(/"/g, ""), + phraseSearch: params.phrase === "true" }); } - if ("nameddest" in params) { - this.navigateTo(params.nameddest); - return; - } - if ("page" in params) { pageNumber = params.page | 0 || 1; } @@ -7009,6 +7068,10 @@ class PDFLinkService { mode: params.pagemode }); } + + if ("nameddest" in params) { + this.navigateTo(params.nameddest); + } } else { dest = unescape(hash); @@ -7229,7 +7292,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.PDFOutlineViewer = void 0; -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); const DEFAULT_TITLE = "\u2013"; @@ -7769,7 +7832,9 @@ class PDFPresentationMode { this.touchSwipeBind = this._touchSwipe.bind(this); window.addEventListener("mousemove", this.showControlsBind); window.addEventListener("mousedown", this.mouseDownBind); - window.addEventListener("wheel", this.mouseWheelBind); + window.addEventListener("wheel", this.mouseWheelBind, { + passive: false + }); window.addEventListener("keydown", this.resetMouseScrollStateBind); window.addEventListener("contextmenu", this.contextMenuBind); window.addEventListener("touchstart", this.touchSwipeBind); @@ -7780,7 +7845,9 @@ class PDFPresentationMode { _removeWindowListeners() { window.removeEventListener("mousemove", this.showControlsBind); window.removeEventListener("mousedown", this.mouseDownBind); - window.removeEventListener("wheel", this.mouseWheelBind); + window.removeEventListener("wheel", this.mouseWheelBind, { + passive: false + }); window.removeEventListener("keydown", this.resetMouseScrollStateBind); window.removeEventListener("contextmenu", this.contextMenuBind); window.removeEventListener("touchstart", this.touchSwipeBind); @@ -8240,7 +8307,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.PDFThumbnailView = void 0; -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); var _ui_utils = __webpack_require__(2); @@ -8652,11 +8719,11 @@ exports.PDFViewer = void 0; var _base_viewer = __webpack_require__(25); -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); class PDFViewer extends _base_viewer.BaseViewer { - get _setDocumentViewerElement() { - return (0, _pdfjsLib.shadow)(this, "_setDocumentViewerElement", this.viewer); + get _viewerElement() { + return (0, _pdfjsLib.shadow)(this, "_viewerElement", this.viewer); } _scrollIntoView({ @@ -8743,7 +8810,7 @@ var _pdf_rendering_queue = __webpack_require__(8); var _annotation_layer_builder = __webpack_require__(26); -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); var _pdf_page_view = __webpack_require__(27); @@ -8812,7 +8879,7 @@ class BaseViewer { this._name = this.constructor.name; this.container = options.container; this.viewer = options.viewer || options.container.firstElementChild; - this.eventBus = options.eventBus || (0, _ui_utils.getGlobalEventBus)(); + this.eventBus = options.eventBus; this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService(); this.downloadManager = options.downloadManager || null; this.findController = options.findController || null; @@ -9019,8 +9086,16 @@ class BaseViewer { return this.pdfDocument ? this._pagesCapability.promise : null; } - get _setDocumentViewerElement() { - throw new Error("Not implemented: _setDocumentViewerElement"); + get _viewerElement() { + throw new Error("Not implemented: _viewerElement"); + } + + _onePageRenderedOrForceFetch() { + if (!this.container.offsetParent || this._getVisiblePages().views.length === 0) { + return Promise.resolve(); + } + + return this._onePageRenderedCapability.promise; } setDocument(pdfDocument) { @@ -9087,7 +9162,7 @@ class BaseViewer { for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { const pageView = new _pdf_page_view.PDFPageView({ - container: this._setDocumentViewerElement, + container: this._viewerElement, eventBus: this.eventBus, id: pageNum, scale, @@ -9119,12 +9194,12 @@ class BaseViewer { this._updateSpreadMode(); } - this._onePageRenderedCapability.promise.then(() => { + this._onePageRenderedOrForceFetch().then(() => { if (this.findController) { this.findController.setDocument(pdfDocument); } - if (pdfDocument.loadingParams["disableAutoFetch"] || pagesCount > 7500) { + if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > 7500) { this._pagesCapability.resolve(); return; @@ -9849,7 +9924,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0; -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); var _ui_utils = __webpack_require__(2); @@ -9962,11 +10037,11 @@ exports.PDFPageView = void 0; var _ui_utils = __webpack_require__(2); -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); var _pdf_rendering_queue = __webpack_require__(8); -var _viewer_compatibility = __webpack_require__(5); +var _viewer_compatibility = __webpack_require__(4); const MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216; @@ -9988,7 +10063,7 @@ class PDFPageView { this.renderInteractiveForms = options.renderInteractiveForms || false; this.useOnlyCssZoom = options.useOnlyCssZoom || false; this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS; - this.eventBus = options.eventBus || (0, _ui_utils.getGlobalEventBus)(); + this.eventBus = options.eventBus; this.renderingQueue = options.renderingQueue; this.textLayerFactory = options.textLayerFactory; this.annotationLayerFactory = options.annotationLayerFactory; @@ -10558,9 +10633,7 @@ Object.defineProperty(exports, "__esModule", { }); exports.DefaultTextLayerFactory = exports.TextLayerBuilder = void 0; -var _ui_utils = __webpack_require__(2); - -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); const EXPAND_DIVS_TIMEOUT = 300; @@ -10574,7 +10647,7 @@ class TextLayerBuilder { enhanceTextSelection = false }) { this.textLayerDiv = textLayerDiv; - this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)(); + this.eventBus = eventBus; this.textContent = null; this.textContentItemsStr = []; this.textContentStream = null; @@ -11264,7 +11337,7 @@ exports.PDFSinglePageViewer = void 0; var _base_viewer = __webpack_require__(25); -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); class PDFSinglePageViewer extends _base_viewer.BaseViewer { constructor(options) { @@ -11275,8 +11348,8 @@ class PDFSinglePageViewer extends _base_viewer.BaseViewer { }); } - get _setDocumentViewerElement() { - return (0, _pdfjsLib.shadow)(this, "_setDocumentViewerElement", this._shadowViewer); + get _viewerElement() { + return (0, _pdfjsLib.shadow)(this, "_viewerElement", this._shadowViewer); } _resetView() { @@ -11661,23 +11734,22 @@ class ViewHistory { this.cacheSize = cacheSize; this._initializedPromise = this._readFromStorage().then(databaseStr => { const database = JSON.parse(databaseStr || "{}"); + let index = -1; - if (!("files" in database)) { + if (!Array.isArray(database.files)) { database.files = []; } else { while (database.files.length >= this.cacheSize) { database.files.shift(); } - } - - let index = -1; - for (let i = 0, length = database.files.length; i < length; i++) { - const branch = database.files[i]; + for (let i = 0, ii = database.files.length; i < ii; i++) { + const branch = database.files[i]; - if (branch.fingerprint === this.fingerprint) { - index = i; - break; + if (branch.fingerprint === this.fingerprint) { + index = i; + break; + } } } @@ -11804,6 +11876,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.BasePreferences = void 0; + +var _app_options = __webpack_require__(3); + let defaultPreferences = null; function getDefaultPreferences() { @@ -11812,9 +11887,9 @@ function getDefaultPreferences() { "cursorToolOnLoad": 0, "defaultZoomValue": "", "disablePageLabels": false, + "enablePermissions": false, "enablePrintAutoRotate": false, "enableWebGL": false, - "eventBusDispatchToDOM": false, "externalLinkTarget": 0, "historyUpdateUrl": false, "ignoreDestinationZoom": false, @@ -11952,10 +12027,12 @@ Object.defineProperty(exports, "__esModule", { }); exports.DownloadManager = void 0; -var _pdfjsLib = __webpack_require__(4); +var _pdfjsLib = __webpack_require__(5); + +var _viewer_compatibility = __webpack_require__(4); ; -const DISABLE_CREATE_OBJECT_URL = _pdfjsLib.apiCompatibilityParams.disableCreateObjectURL || false; +const DISABLE_CREATE_OBJECT_URL = _viewer_compatibility.viewerCompatibilityParams.disableCreateObjectURL || false; function download(blobUrl, filename) { const a = document.createElement("a"); @@ -12956,7 +13033,7 @@ function PDFPrintService(pdfDocument, pagesOverview, printContainer, l10n) { this.pagesOverview = pagesOverview; this.printContainer = printContainer; this.l10n = l10n || _ui_utils.NullL10n; - this.disableCreateObjectURL = pdfDocument.loadingParams["disableCreateObjectURL"]; + this.disableCreateObjectURL = _app_options.AppOptions.get("disableCreateObjectURL"); this.currentPage = -1; this.scratchCanvas = document.createElement("canvas"); } |