diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index 8ef9dbdb5..c68051d36 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; +import { AnnotationLayer } from 'pdfjs-web/pdfjs'; import { mozL10n } from 'pdfjs-web/ui_utils'; import { SimpleLinkService } from 'pdfjs-web/pdf_link_service'; @@ -72,7 +72,7 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() { if (self.div) { // If an annotationLayer already exists, refresh its children's // transformation matrices. - pdfjsLib.AnnotationLayer.update(parameters); + AnnotationLayer.update(parameters); } else { // Create an annotation layer div and render the annotations // if there is at least one annotation. @@ -85,7 +85,7 @@ var AnnotationLayerBuilder = (function AnnotationLayerBuilderClosure() { self.pageDiv.appendChild(self.div); parameters.div = self.div; - pdfjsLib.AnnotationLayer.render(parameters); + AnnotationLayer.render(parameters); if (typeof mozL10n !== 'undefined') { mozL10n.translate(self.div); } diff --git a/web/app.js b/web/app.js index e0cdc0df4..237f9e8fe 100644 --- a/web/app.js +++ b/web/app.js @@ -14,12 +14,16 @@ */ /* globals PDFBug, Stats */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; import { animationStarted, DEFAULT_SCALE_VALUE, getPDFFileNameFromURL, localized, MAX_SCALE, MIN_SCALE, mozL10n, noContextMenuHandler, normalizeWheelEventDelta, parseQueryString, ProgressBar, RendererType, UNKNOWN_SCALE } from 'pdfjs-web/ui_utils'; +import { + build, createBlob, getDocument, getFilenameFromUrl, InvalidPDFException, + MissingPDFException, OPS, PDFJS, shadow, UnexpectedResponseException, + UNSUPPORTED_FEATURES, version, +} from 'pdfjs-web/pdfjs'; import { PDFRenderingQueue, RenderingStates } from 'pdfjs-web/pdf_rendering_queue'; @@ -140,7 +144,6 @@ var PDFViewerApplication = { // called once when the document is loaded initialize: function pdfViewInitialize(appConfig) { var self = this; - var PDFJS = pdfjsLib.PDFJS; Preferences.initialize(); this.preferences = Preferences; @@ -179,7 +182,6 @@ var PDFViewerApplication = { */ _readPreferences: function () { var self = this; - var PDFJS = pdfjsLib.PDFJS; return Promise.all([ Preferences.get('enableWebGL').then(function resolved(value) { @@ -445,11 +447,11 @@ var PDFViewerApplication = { support = false; } } - if (support && pdfjsLib.PDFJS.disableFullscreen === true) { + if (support && PDFJS.disableFullscreen === true) { support = false; } - return pdfjsLib.shadow(this, 'supportsFullscreen', support); + return shadow(this, 'supportsFullscreen', support); }, get supportsIntegratedFind() { @@ -467,7 +469,7 @@ var PDFViewerApplication = { get loadingBar() { var bar = new ProgressBar('#loadingBar', {}); - return pdfjsLib.shadow(this, 'loadingBar', bar); + return shadow(this, 'loadingBar', bar); }, get supportedMouseWheelZoomModifierKeys() { @@ -517,7 +519,7 @@ var PDFViewerApplication = { var title = getPDFFileNameFromURL(url, ''); if (!title) { try { - title = decodeURIComponent(pdfjsLib.getFilenameFromUrl(url)) || url; + title = decodeURIComponent(getFilenameFromUrl(url)) || url; } catch (e) { // decodeURIComponent may throw URIError, // fall back to using the unprocessed url in that case @@ -632,7 +634,7 @@ var PDFViewerApplication = { var self = this; self.downloadComplete = false; - var loadingTask = pdfjsLib.getDocument(parameters); + var loadingTask = getDocument(parameters); this.pdfLoadingTask = loadingTask; loadingTask.onPassword = function passwordNeeded(updateCallback, reason) { @@ -656,15 +658,15 @@ var PDFViewerApplication = { var loadingErrorMessage = mozL10n.get('loading_error', null, 'An error occurred while loading the PDF.'); - if (exception instanceof pdfjsLib.InvalidPDFException) { + if (exception instanceof InvalidPDFException) { // change error message also for other builds loadingErrorMessage = mozL10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.'); - } else if (exception instanceof pdfjsLib.MissingPDFException) { + } else if (exception instanceof MissingPDFException) { // special message for missing PDF's loadingErrorMessage = mozL10n.get('missing_file_error', null, 'Missing PDF file.'); - } else if (exception instanceof pdfjsLib.UnexpectedResponseException) { + } else if (exception instanceof UnexpectedResponseException) { loadingErrorMessage = mozL10n.get('unexpected_response_error', null, 'Unexpected server response.'); } @@ -707,7 +709,7 @@ var PDFViewerApplication = { this.pdfDocument.getData().then( function getDataSuccess(data) { - var blob = pdfjsLib.createBlob(data, 'application/pdf'); + var blob = createBlob(data, 'application/pdf'); downloadManager.download(blob, url, filename); }, downloadByUrl // Error occurred try downloading with just the url. @@ -744,7 +746,7 @@ var PDFViewerApplication = { */ error: function pdfViewError(message, moreInfo) { var moreInfoText = mozL10n.get('error_version_info', - {version: pdfjsLib.version || '?', build: pdfjsLib.build || '?'}, + {version: version || '?', build: build || '?'}, 'PDF.js v{{version}} (build: {{build}})') + '\n'; if (moreInfo) { moreInfoText += @@ -822,7 +824,7 @@ var PDFViewerApplication = { // the loading bar will not be completely filled, nor will it be hidden. // To prevent displaying a partially filled loading bar permanently, we // hide it when no data has been loaded during a certain amount of time. - if (pdfjsLib.PDFJS.disableAutoFetch && percent) { + if (PDFJS.disableAutoFetch && percent) { if (this.disableAutoFetchLoadingBarTimeout) { clearTimeout(this.disableAutoFetchLoadingBarTimeout); this.disableAutoFetchLoadingBarTimeout = null; @@ -885,7 +887,7 @@ var PDFViewerApplication = { self.loadingBar.setWidth(self.appConfig.viewerContainer); - if (!pdfjsLib.PDFJS.disableHistory && !self.isViewerEmbedded) { + if (!PDFJS.disableHistory && !self.isViewerEmbedded) { // The browsing history is only enabled when the viewer is standalone, // i.e. not when it is embedded in a web page. if (!self.viewerPrefs['showPreviousViewOnLoad']) { @@ -989,7 +991,7 @@ var PDFViewerApplication = { pdfDocument.getJavaScript().then(function(javaScript) { if (javaScript.length) { console.warn('Warning: JavaScript is not supported'); - self.fallback(pdfjsLib.UNSUPPORTED_FEATURES.javaScript); + self.fallback(UNSUPPORTED_FEATURES.javaScript); } // Hack to support auto printing. var regex = /\bprint\s*\(/; @@ -1024,8 +1026,8 @@ var PDFViewerApplication = { console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + - ' (PDF.js: ' + (pdfjsLib.version || '-') + - (!pdfjsLib.PDFJS.disableWebGL ? ' [WebGL]' : '') + ')'); + ' (PDF.js: ' + (version || '-') + + (!PDFJS.disableWebGL ? ' [WebGL]' : '') + ')'); var pdfTitle; if (metadata && metadata.has('dc:title')) { @@ -1046,7 +1048,7 @@ var PDFViewerApplication = { if (info.IsAcroFormPresent) { console.warn('Warning: AcroForm/XFA is not supported'); - self.fallback(pdfjsLib.UNSUPPORTED_FEATURES.forms); + self.fallback(UNSUPPORTED_FEATURES.forms); } if (typeof PDFJSDev !== 'undefined' && @@ -1329,7 +1331,10 @@ function loadAndEnablePDFBug(enabledTabs) { script.src = appConfig.debuggerScriptPath; script.onload = function () { PDFBug.enable(enabledTabs); - PDFBug.init(pdfjsLib, appConfig.mainContainer); + PDFBug.init({ + PDFJS, + OPS, + }, appConfig.mainContainer); resolve(); }; script.onerror = function () { @@ -1375,8 +1380,6 @@ function webViewerInitialized() { appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true'); } - var PDFJS = pdfjsLib.PDFJS; - if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) || PDFViewerApplication.viewerPrefs['pdfBugEnabled']) { // Special debugging flags in the hash section of the URL. @@ -1555,7 +1558,7 @@ function webViewerPageRendered(e) { thumbnailView.setImage(pageView); } - if (pdfjsLib.PDFJS.pdfBug && Stats.enabled && pageView.stats) { + if (PDFJS.pdfBug && Stats.enabled && pageView.stats) { Stats.add(pageNumber, pageView.stats); } @@ -1720,7 +1723,7 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { webViewerFileInputChange = function webViewerFileInputChange(e) { var file = e.fileInput.files[0]; - if (!pdfjsLib.PDFJS.disableCreateObjectURL && + if (!PDFJS.disableCreateObjectURL && typeof URL !== 'undefined' && URL.createObjectURL) { PDFViewerApplication.open(URL.createObjectURL(file)); } else { @@ -1843,7 +1846,7 @@ function webViewerPageChanging(e) { } // we need to update stats - if (pdfjsLib.PDFJS.pdfBug && Stats.enabled) { + if (PDFJS.pdfBug && Stats.enabled) { var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1); if (pageView.stats) { Stats.add(page, pageView.stats); diff --git a/web/chromecom.js b/web/chromecom.js index decff7590..d0e1a93d1 100644 --- a/web/chromecom.js +++ b/web/chromecom.js @@ -14,9 +14,9 @@ */ /* globals chrome */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; import { DefaultExternalServices, PDFViewerApplication } from 'pdfjs-web/app'; import { OverlayManager } from 'pdfjs-web/overlay_manager'; +import { PDFJS } from 'pdfjs-web/pdfjs'; import { Preferences } from 'pdfjs-web/preferences'; if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('CHROME')) { @@ -63,7 +63,7 @@ ChromeCom.resolvePDFFile = function ChromeCom_resolvePDFFile(file, callback) { file = file.replace(/^drive:/i, 'filesystem:' + location.origin + '/external/'); - if (/^filesystem:/.test(file) && !pdfjsLib.PDFJS.disableWorker) { + if (/^filesystem:/.test(file) && !PDFJS.disableWorker) { // The security origin of filesystem:-URLs are not preserved when the // URL is passed to a Web worker, (http://crbug.com/362061), so we have // to create an intermediate blob:-URL as a work-around. diff --git a/web/download_manager.js b/web/download_manager.js index 206ecd209..dfcc95ad3 100644 --- a/web/download_manager.js +++ b/web/download_manager.js @@ -13,7 +13,9 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; +import { + createObjectURL, createValidAbsoluteUrl, PDFJS +} from 'pdfjs-web/pdfjs'; import { DefaultExternalServices, PDFViewerApplication } from 'pdfjs-web/app'; if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('CHROME || GENERIC')) { @@ -61,7 +63,7 @@ function DownloadManager() {} DownloadManager.prototype = { downloadUrl: function DownloadManager_downloadUrl(url, filename) { - if (!pdfjsLib.createValidAbsoluteUrl(url, 'http://example.com')) { + if (!createValidAbsoluteUrl(url, 'http://example.com')) { return; // restricted/invalid URL } download(url + '#pdfjs.action=download', filename); @@ -74,8 +76,8 @@ DownloadManager.prototype = { filename); } - var blobUrl = pdfjsLib.createObjectURL(data, contentType, - pdfjsLib.PDFJS.disableCreateObjectURL); + var blobUrl = createObjectURL(data, contentType, + PDFJS.disableCreateObjectURL); download(blobUrl, filename); }, @@ -88,7 +90,7 @@ DownloadManager.prototype = { return; } - if (pdfjsLib.PDFJS.disableCreateObjectURL) { + if (PDFJS.disableCreateObjectURL) { // URL.createObjectURL is not supported this.downloadUrl(url, filename); return; diff --git a/web/firefox_print_service.js b/web/firefox_print_service.js index 3f128c5db..a8dd45b9e 100644 --- a/web/firefox_print_service.js +++ b/web/firefox_print_service.js @@ -13,9 +13,9 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; import { CSS_UNITS } from 'pdfjs-web/ui_utils'; import { PDFPrintServiceFactory } from 'pdfjs-web/app'; +import { shadow } from 'pdfjs-web/pdfjs'; // Creates a placeholder with div and canvas with right size for the page. function composePage(pdfDocument, pageNumber, size, printContainer) { @@ -96,7 +96,7 @@ PDFPrintServiceFactory.instance = { var canvas = document.createElement('canvas'); var value = 'mozPrintCallback' in canvas; - return pdfjsLib.shadow(this, 'supportsPrinting', value); + return shadow(this, 'supportsPrinting', value); }, createPrintService: function (pdfDocument, pagesOverview, printContainer) { diff --git a/web/firefoxcom.js b/web/firefoxcom.js index f3d956334..64e2085e5 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -13,7 +13,9 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; +import { + createObjectURL, PDFDataRangeTransport, shadow +} from 'pdfjs-web/pdfjs'; import { PDFViewerApplication } from 'pdfjs-web/app'; import { Preferences } from 'pdfjs-web/preferences'; @@ -94,7 +96,7 @@ var DownloadManager = (function DownloadManagerClosure() { downloadData: function DownloadManager_downloadData(data, filename, contentType) { - var blobUrl = pdfjsLib.createObjectURL(data, contentType, false); + var blobUrl = createObjectURL(data, contentType, false); FirefoxCom.request('download', { blobUrl: blobUrl, @@ -168,10 +170,10 @@ Preferences._readFromStorage = function (prefObj) { })(); function FirefoxComDataRangeTransport(length, initialData) { - pdfjsLib.PDFDataRangeTransport.call(this, length, initialData); + PDFDataRangeTransport.call(this, length, initialData); } FirefoxComDataRangeTransport.prototype = - Object.create(pdfjsLib.PDFDataRangeTransport.prototype); + Object.create(PDFDataRangeTransport.prototype); FirefoxComDataRangeTransport.prototype.requestDataRange = function FirefoxComDataRangeTransport_requestDataRange(begin, end) { FirefoxCom.request('requestDataRange', { begin: begin, end: end }); @@ -247,23 +249,22 @@ PDFViewerApplication.externalServices = { get supportsIntegratedFind() { var support = FirefoxCom.requestSync('supportsIntegratedFind'); - return pdfjsLib.shadow(this, 'supportsIntegratedFind', support); + return shadow(this, 'supportsIntegratedFind', support); }, get supportsDocumentFonts() { var support = FirefoxCom.requestSync('supportsDocumentFonts'); - return pdfjsLib.shadow(this, 'supportsDocumentFonts', support); + return shadow(this, 'supportsDocumentFonts', support); }, get supportsDocumentColors() { var support = FirefoxCom.requestSync('supportsDocumentColors'); - return pdfjsLib.shadow(this, 'supportsDocumentColors', support); + return shadow(this, 'supportsDocumentColors', support); }, get supportedMouseWheelZoomModifierKeys() { var support = FirefoxCom.requestSync('supportedMouseWheelZoomModifierKeys'); - return pdfjsLib.shadow(this, 'supportedMouseWheelZoomModifierKeys', - support); + return shadow(this, 'supportedMouseWheelZoomModifierKeys', support); }, }; diff --git a/web/password_prompt.js b/web/password_prompt.js index 771ab8aba..710ddd370 100644 --- a/web/password_prompt.js +++ b/web/password_prompt.js @@ -13,9 +13,9 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; import { mozL10n } from 'pdfjs-web/ui_utils'; import { OverlayManager } from 'pdfjs-web/overlay_manager'; +import { PasswordResponses } from 'pdfjs-web/pdfjs'; /** * @typedef {Object} PasswordPromptOptions @@ -71,7 +71,7 @@ var PasswordPrompt = (function PasswordPromptClosure() { var promptString = mozL10n.get('password_label', null, 'Enter the password to open this PDF file.'); - if (this.reason === pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) { + if (this.reason === PasswordResponses.INCORRECT_PASSWORD) { promptString = mozL10n.get('password_invalid', null, 'Invalid password. Please try again.'); } diff --git a/web/pdf_attachment_viewer.js b/web/pdf_attachment_viewer.js index 0b0b64ca5..141c480bd 100644 --- a/web/pdf_attachment_viewer.js +++ b/web/pdf_attachment_viewer.js @@ -13,7 +13,10 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; +import { + createObjectURL, createPromiseCapability, getFilenameFromUrl, PDFJS, + removeNullCharacters +} from 'pdfjs-web/pdfjs'; /** * @typedef {Object} PDFAttachmentViewerOptions @@ -41,7 +44,7 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() { this.eventBus = options.eventBus; this.downloadManager = options.downloadManager; - this._renderedCapability = pdfjsLib.createPromiseCapability(); + this._renderedCapability = createPromiseCapability(); this.eventBus.on('fileattachmentannotation', this._appendAttachment.bind(this)); } @@ -56,7 +59,7 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() { if (!keepRenderedCapability) { // NOTE: The *only* situation in which the `_renderedCapability` should // not be replaced is when appending file attachment annotations. - this._renderedCapability = pdfjsLib.createPromiseCapability(); + this._renderedCapability = createPromiseCapability(); } }, @@ -81,8 +84,8 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() { var blobUrl; button.onclick = function() { if (!blobUrl) { - blobUrl = pdfjsLib.createObjectURL( - content, 'application/pdf', pdfjsLib.PDFJS.disableCreateObjectURL); + blobUrl = createObjectURL( + content, 'application/pdf', PDFJS.disableCreateObjectURL); } var viewerUrl; if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { @@ -142,8 +145,7 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() { for (var i = 0; i < attachmentsCount; i++) { var item = attachments[names[i]]; - var filename = pdfjsLib.getFilenameFromUrl(item.filename); - filename = pdfjsLib.removeNullCharacters(filename); + var filename = removeNullCharacters(getFilenameFromUrl(item.filename)); var div = document.createElement('div'); div.className = 'attachmentsItem'; diff --git a/web/pdf_outline_viewer.js b/web/pdf_outline_viewer.js index 0098489f0..ce8d2e909 100644 --- a/web/pdf_outline_viewer.js +++ b/web/pdf_outline_viewer.js @@ -13,9 +13,9 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; - -var PDFJS = pdfjsLib.PDFJS; +import { + addLinkAttributes, PDFJS, removeNullCharacters +} from 'pdfjs-web/pdfjs'; var DEFAULT_TITLE = '\u2013'; @@ -74,7 +74,7 @@ var PDFOutlineViewer = (function PDFOutlineViewerClosure() { */ _bindLink: function PDFOutlineViewer_bindLink(element, item) { if (item.url) { - pdfjsLib.addLinkAttributes(element, { + addLinkAttributes(element, { url: item.url, target: (item.newWindow ? PDFJS.LinkTarget.BLANK : undefined), }); @@ -189,7 +189,7 @@ var PDFOutlineViewer = (function PDFOutlineViewerClosure() { this._bindLink(element, item); this._setStyles(element, item); element.textContent = - pdfjsLib.removeNullCharacters(item.title) || DEFAULT_TITLE; + removeNullCharacters(item.title) || DEFAULT_TITLE; div.appendChild(element); diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 5718bb102..37c5c6f31 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -13,11 +13,13 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; import { approximateFraction, CSS_UNITS, DEFAULT_SCALE, getOutputScale, RendererType, roundToDivide } from 'pdfjs-web/ui_utils'; +import { + CustomStyle, PDFJS, RenderingCancelledException, SVGGraphics +} from 'pdfjs-web/pdfjs'; import { domEvents } from 'pdfjs-web/dom_events'; import { RenderingStates } from 'pdfjs-web/pdf_rendering_queue'; @@ -216,17 +218,17 @@ var PDFPageView = (function PDFPageViewClosure() { } var isScalingRestricted = false; - if (this.canvas && pdfjsLib.PDFJS.maxCanvasPixels > 0) { + if (this.canvas && PDFJS.maxCanvasPixels > 0) { var outputScale = this.outputScale; if (((Math.floor(this.viewport.width) * outputScale.sx) | 0) * ((Math.floor(this.viewport.height) * outputScale.sy) | 0) > - pdfjsLib.PDFJS.maxCanvasPixels) { + PDFJS.maxCanvasPixels) { isScalingRestricted = true; } } if (this.canvas) { - if (pdfjsLib.PDFJS.useOnlyCssZoom || + if (PDFJS.useOnlyCssZoom || (this.hasRestrictedScaling && isScalingRestricted)) { this.cssTransform(this.canvas, true); @@ -272,8 +274,6 @@ var PDFPageView = (function PDFPageViewClosure() { }, cssTransform: function PDFPageView_transform(target, redrawAnnotations) { - var CustomStyle = pdfjsLib.CustomStyle; - // Scale target (canvas or svg), its wrapper, and page container. var width = this.viewport.width; var height = this.viewport.height; @@ -425,7 +425,7 @@ var PDFPageView = (function PDFPageViewClosure() { if (((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PDFJS_NEXT')) && error === 'cancelled') || - error instanceof pdfjsLib.RenderingCancelledException) { + error instanceof RenderingCancelledException) { self.error = null; return Promise.resolve(undefined); } @@ -535,7 +535,7 @@ var PDFPageView = (function PDFPageViewClosure() { var outputScale = getOutputScale(ctx); this.outputScale = outputScale; - if (pdfjsLib.PDFJS.useOnlyCssZoom) { + if (PDFJS.useOnlyCssZoom) { var actualSizeViewport = viewport.clone({scale: CSS_UNITS}); // Use a scale that will make the canvas be the original intended size // of the page. @@ -544,10 +544,9 @@ var PDFPageView = (function PDFPageViewClosure() { outputScale.scaled = true; } - if (pdfjsLib.PDFJS.maxCanvasPixels > 0) { + if (PDFJS.maxCanvasPixels > 0) { var pixelsInViewport = viewport.width * viewport.height; - var maxScale = - Math.sqrt(pdfjsLib.PDFJS.maxCanvasPixels / pixelsInViewport); + var maxScale = Math.sqrt(PDFJS.maxCanvasPixels / pixelsInViewport); if (outputScale.sx > maxScale || outputScale.sy > maxScale) { outputScale.sx = maxScale; outputScale.sy = maxScale; @@ -617,8 +616,8 @@ var PDFPageView = (function PDFPageViewClosure() { var ensureNotCancelled = function () { if (cancelled) { if ((typeof PDFJSDev !== 'undefined' && - PDFJSDev.test('PDFJS_NEXT')) || pdfjsLib.PDFJS.pdfjsNext) { - throw new pdfjsLib.RenderingCancelledException( + PDFJSDev.test('PDFJS_NEXT')) || PDFJS.pdfjsNext) { + throw new RenderingCancelledException( 'Rendering cancelled, page ' + self.id, 'svg'); } else { throw 'cancelled'; // eslint-disable-line no-throw-literal @@ -628,7 +627,6 @@ var PDFPageView = (function PDFPageViewClosure() { var self = this; var pdfPage = this.pdfPage; - var SVGGraphics = pdfjsLib.SVGGraphics; var actualSizeViewport = this.viewport.clone({scale: CSS_UNITS}); var promise = pdfPage.getOperatorList().then(function (opList) { ensureNotCancelled(); diff --git a/web/pdf_print_service.js b/web/pdf_print_service.js index 02f677bb7..e759d789b 100644 --- a/web/pdf_print_service.js +++ b/web/pdf_print_service.js @@ -13,9 +13,9 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; import { CSS_UNITS, mozL10n } from 'pdfjs-web/ui_utils'; import { OverlayManager } from 'pdfjs-web/overlay_manager'; +import { PDFJS } from 'pdfjs-web/pdfjs'; import { PDFPrintServiceFactory } from 'pdfjs-web/app'; var activeService = null; @@ -152,8 +152,7 @@ PDFPrintService.prototype = { img.style.height = printItem.height; var scratchCanvas = this.scratchCanvas; - if (('toBlob' in scratchCanvas) && - !pdfjsLib.PDFJS.disableCreateObjectURL) { + if (('toBlob' in scratchCanvas) && !PDFJS.disableCreateObjectURL) { scratchCanvas.toBlob(function (blob) { img.src = URL.createObjectURL(blob); }); diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 5ce49efba..30925a9dc 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -13,7 +13,6 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; import { CSS_UNITS, DEFAULT_SCALE, DEFAULT_SCALE_VALUE, getVisibleElements, MAX_AUTO_SCALE, RendererType, SCROLLBAR_PADDING, scrollIntoView, @@ -24,6 +23,7 @@ import { } from 'pdfjs-web/pdf_rendering_queue'; import { AnnotationLayerBuilder } from 'pdfjs-web/annotation_layer_builder'; import { domEvents } from 'pdfjs-web/dom_events'; +import { PDFJS } from 'pdfjs-web/pdfjs'; import { PDFPageView } from 'pdfjs-web/pdf_page_view'; import { SimpleLinkService } from 'pdfjs-web/pdf_link_service'; import { TextLayerBuilder } from 'pdfjs-web/text_layer_builder'; @@ -362,7 +362,7 @@ var PDFViewer = (function pdfViewer() { var viewport = pdfPage.getViewport(scale * CSS_UNITS); for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) { var textLayerFactory = null; - if (!pdfjsLib.PDFJS.disableTextLayer) { + if (!PDFJS.disableTextLayer) { textLayerFactory = this; } var pageView = new PDFPageView({ @@ -388,7 +388,7 @@ var PDFViewer = (function pdfViewer() { // starts to create the correct size canvas. Wait until one page is // rendered so we don't tie up too many resources early on. onePageRendered.then(function () { - if (!pdfjsLib.PDFJS.disableAutoFetch) { + if (!PDFJS.disableAutoFetch) { var getPagesLeft = pagesCount; for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) { pdfDocument.getPage(pageNum).then(function (pageNum, pdfPage) { @@ -500,7 +500,7 @@ var PDFViewer = (function pdfViewer() { if (!noScroll) { var page = this._currentPageNumber, dest; - if (this._location && !pdfjsLib.PDFJS.ignoreCurrentPositionOnZoom && + if (this._location && !PDFJS.ignoreCurrentPositionOnZoom && !(this.isInPresentationMode || this.isChangingPresentationMode)) { page = this._location.pageNumber; dest = [null, { name: 'XYZ' }, this._location.left, diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js index aca55f206..2552b68e7 100644 --- a/web/text_layer_builder.js +++ b/web/text_layer_builder.js @@ -13,8 +13,8 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; import { domEvents } from 'pdfjs-web/dom_events'; +import { renderTextLayer } from 'pdfjs-web/pdfjs'; var EXPAND_DIVS_TIMEOUT = 300; // ms @@ -86,7 +86,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() { this.textDivs = []; var textLayerFrag = document.createDocumentFragment(); - this.textLayerRenderTask = pdfjsLib.renderTextLayer({ + this.textLayerRenderTask = renderTextLayer({ textContent: this.textContent, container: textLayerFrag, viewport: this.viewport, diff --git a/web/ui_utils.js b/web/ui_utils.js index 2c7ce599d..8cd6960ff 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import * as pdfjsLib from 'pdfjs-web/pdfjs'; +import { PDFJS } from 'pdfjs-web/pdfjs'; var CSS_UNITS = 96.0 / 72.0; var DEFAULT_SCALE_VALUE = 'auto'; @@ -32,8 +32,6 @@ var RendererType = { var mozL10n = document.mozL10n || document.webL10n; -var PDFJS = pdfjsLib.PDFJS; - /** * Disables fullscreen support, and by extension Presentation Mode, * in browsers which support the fullscreen API.