app.js 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2017 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. 'use strict';
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = undefined;
  27. var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
  28. var _ui_utils = require('./ui_utils');
  29. var _pdf = require('../pdf');
  30. var _pdf_cursor_tools = require('./pdf_cursor_tools');
  31. var _pdf_rendering_queue = require('./pdf_rendering_queue');
  32. var _pdf_sidebar = require('./pdf_sidebar');
  33. var _dom_events = require('./dom_events');
  34. var _overlay_manager = require('./overlay_manager');
  35. var _password_prompt = require('./password_prompt');
  36. var _pdf_attachment_viewer = require('./pdf_attachment_viewer');
  37. var _pdf_document_properties = require('./pdf_document_properties');
  38. var _pdf_find_bar = require('./pdf_find_bar');
  39. var _pdf_find_controller = require('./pdf_find_controller');
  40. var _pdf_history = require('./pdf_history');
  41. var _pdf_link_service = require('./pdf_link_service');
  42. var _pdf_outline_viewer = require('./pdf_outline_viewer');
  43. var _pdf_presentation_mode = require('./pdf_presentation_mode');
  44. var _pdf_sidebar_resizer = require('./pdf_sidebar_resizer');
  45. var _pdf_thumbnail_viewer = require('./pdf_thumbnail_viewer');
  46. var _pdf_viewer = require('./pdf_viewer');
  47. var _secondary_toolbar = require('./secondary_toolbar');
  48. var _toolbar = require('./toolbar');
  49. var _viewer_compatibility = require('./viewer_compatibility');
  50. var _view_history = require('./view_history');
  51. var DEFAULT_SCALE_DELTA = 1.1;
  52. var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  53. function configure(PDFJS) {
  54. PDFJS.imageResourcesPath = './images/';
  55. PDFJS.workerSrc = '../build/pdf.worker.js';
  56. PDFJS.cMapUrl = '../web/cmaps/';
  57. PDFJS.cMapPacked = true;
  58. }
  59. var DefaultExternalServices = {
  60. updateFindControlState: function updateFindControlState(data) {},
  61. initPassiveLoading: function initPassiveLoading(callbacks) {},
  62. fallback: function fallback(data, callback) {},
  63. reportTelemetry: function reportTelemetry(data) {},
  64. createDownloadManager: function createDownloadManager() {
  65. throw new Error('Not implemented: createDownloadManager');
  66. },
  67. createPreferences: function createPreferences() {
  68. throw new Error('Not implemented: createPreferences');
  69. },
  70. createL10n: function createL10n() {
  71. throw new Error('Not implemented: createL10n');
  72. },
  73. supportsIntegratedFind: false,
  74. supportsDocumentFonts: true,
  75. supportsDocumentColors: true,
  76. supportedMouseWheelZoomModifierKeys: {
  77. ctrlKey: true,
  78. metaKey: true
  79. }
  80. };
  81. var PDFViewerApplication = {
  82. initialBookmark: document.location.hash.substring(1),
  83. initialized: false,
  84. fellback: false,
  85. appConfig: null,
  86. pdfDocument: null,
  87. pdfLoadingTask: null,
  88. printService: null,
  89. pdfViewer: null,
  90. pdfThumbnailViewer: null,
  91. pdfRenderingQueue: null,
  92. pdfPresentationMode: null,
  93. pdfDocumentProperties: null,
  94. pdfLinkService: null,
  95. pdfHistory: null,
  96. pdfSidebar: null,
  97. pdfSidebarResizer: null,
  98. pdfOutlineViewer: null,
  99. pdfAttachmentViewer: null,
  100. pdfCursorTools: null,
  101. store: null,
  102. downloadManager: null,
  103. overlayManager: null,
  104. preferences: null,
  105. toolbar: null,
  106. secondaryToolbar: null,
  107. eventBus: null,
  108. l10n: null,
  109. isInitialViewSet: false,
  110. downloadComplete: false,
  111. viewerPrefs: {
  112. enableWebGL: false,
  113. sidebarViewOnLoad: _pdf_sidebar.SidebarView.NONE,
  114. pdfBugEnabled: false,
  115. showPreviousViewOnLoad: true,
  116. defaultZoomValue: '',
  117. disablePageMode: false,
  118. disablePageLabels: false,
  119. renderer: 'canvas',
  120. textLayerMode: _ui_utils.TextLayerMode.ENABLE,
  121. renderInteractiveForms: false,
  122. enablePrintAutoRotate: false
  123. },
  124. isViewerEmbedded: window.parent !== window,
  125. url: '',
  126. baseUrl: '',
  127. externalServices: DefaultExternalServices,
  128. _boundEvents: {},
  129. contentDispositionFilename: null,
  130. initialize: function initialize(appConfig) {
  131. var _this = this;
  132. this.preferences = this.externalServices.createPreferences();
  133. configure(_pdf.PDFJS);
  134. this.appConfig = appConfig;
  135. return this._readPreferences().then(function () {
  136. return _this._parseHashParameters();
  137. }).then(function () {
  138. return _this._initializeL10n();
  139. }).then(function () {
  140. return _this._initializeViewerComponents();
  141. }).then(function () {
  142. _this.bindEvents();
  143. _this.bindWindowEvents();
  144. var appContainer = appConfig.appContainer || document.documentElement;
  145. _this.l10n.translate(appContainer).then(function () {
  146. _this.eventBus.dispatch('localized');
  147. });
  148. if (_this.isViewerEmbedded && _pdf.PDFJS.externalLinkTarget === _pdf.LinkTarget.NONE) {
  149. _pdf.PDFJS.externalLinkTarget = _pdf.LinkTarget.TOP;
  150. }
  151. _this.initialized = true;
  152. });
  153. },
  154. _readPreferences: function _readPreferences() {
  155. var preferences = this.preferences,
  156. viewerPrefs = this.viewerPrefs;
  157. return Promise.all([preferences.get('enableWebGL').then(function resolved(value) {
  158. viewerPrefs['enableWebGL'] = value;
  159. }), preferences.get('sidebarViewOnLoad').then(function resolved(value) {
  160. viewerPrefs['sidebarViewOnLoad'] = value;
  161. }), preferences.get('pdfBugEnabled').then(function resolved(value) {
  162. viewerPrefs['pdfBugEnabled'] = value;
  163. }), preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
  164. viewerPrefs['showPreviousViewOnLoad'] = value;
  165. }), preferences.get('defaultZoomValue').then(function resolved(value) {
  166. viewerPrefs['defaultZoomValue'] = value;
  167. }), preferences.get('textLayerMode').then(function resolved(value) {
  168. if (viewerPrefs['textLayerMode'] === _ui_utils.TextLayerMode.DISABLE) {
  169. return;
  170. }
  171. viewerPrefs['textLayerMode'] = value;
  172. }), preferences.get('disableRange').then(function resolved(value) {
  173. if (_pdf.PDFJS.disableRange === true) {
  174. return;
  175. }
  176. _pdf.PDFJS.disableRange = value;
  177. }), preferences.get('disableStream').then(function resolved(value) {
  178. if (_pdf.PDFJS.disableStream === true) {
  179. return;
  180. }
  181. _pdf.PDFJS.disableStream = value;
  182. }), preferences.get('disableAutoFetch').then(function resolved(value) {
  183. _pdf.PDFJS.disableAutoFetch = value;
  184. }), preferences.get('disableFontFace').then(function resolved(value) {
  185. if (_pdf.PDFJS.disableFontFace === true) {
  186. return;
  187. }
  188. _pdf.PDFJS.disableFontFace = value;
  189. }), preferences.get('useOnlyCssZoom').then(function resolved(value) {
  190. _pdf.PDFJS.useOnlyCssZoom = value;
  191. }), preferences.get('externalLinkTarget').then(function resolved(value) {
  192. if (_pdf.PDFJS.externalLinkTarget !== _pdf.LinkTarget.NONE) {
  193. return;
  194. }
  195. _pdf.PDFJS.externalLinkTarget = value;
  196. }), preferences.get('renderer').then(function resolved(value) {
  197. viewerPrefs['renderer'] = value;
  198. }), preferences.get('renderInteractiveForms').then(function resolved(value) {
  199. viewerPrefs['renderInteractiveForms'] = value;
  200. }), preferences.get('disablePageMode').then(function resolved(value) {
  201. viewerPrefs['disablePageMode'] = value;
  202. }), preferences.get('disablePageLabels').then(function resolved(value) {
  203. viewerPrefs['disablePageLabels'] = value;
  204. }), preferences.get('enablePrintAutoRotate').then(function resolved(value) {
  205. viewerPrefs['enablePrintAutoRotate'] = value;
  206. })]).catch(function (reason) {});
  207. },
  208. _parseHashParameters: function _parseHashParameters() {
  209. var appConfig = this.appConfig,
  210. viewerPrefs = this.viewerPrefs;
  211. var waitOn = [];
  212. if (viewerPrefs['pdfBugEnabled']) {
  213. var hash = document.location.hash.substring(1);
  214. var hashParams = (0, _ui_utils.parseQueryString)(hash);
  215. if ('disableworker' in hashParams && hashParams['disableworker'] === 'true') {
  216. waitOn.push(loadFakeWorker());
  217. }
  218. if ('disablerange' in hashParams) {
  219. _pdf.PDFJS.disableRange = hashParams['disablerange'] === 'true';
  220. }
  221. if ('disablestream' in hashParams) {
  222. _pdf.PDFJS.disableStream = hashParams['disablestream'] === 'true';
  223. }
  224. if ('disableautofetch' in hashParams) {
  225. _pdf.PDFJS.disableAutoFetch = hashParams['disableautofetch'] === 'true';
  226. }
  227. if ('disablefontface' in hashParams) {
  228. _pdf.PDFJS.disableFontFace = hashParams['disablefontface'] === 'true';
  229. }
  230. if ('disablehistory' in hashParams) {
  231. _pdf.PDFJS.disableHistory = hashParams['disablehistory'] === 'true';
  232. }
  233. if ('webgl' in hashParams) {
  234. viewerPrefs['enableWebGL'] = hashParams['webgl'] === 'true';
  235. }
  236. if ('useonlycsszoom' in hashParams) {
  237. _pdf.PDFJS.useOnlyCssZoom = hashParams['useonlycsszoom'] === 'true';
  238. }
  239. if ('verbosity' in hashParams) {
  240. _pdf.PDFJS.verbosity = hashParams['verbosity'] | 0;
  241. }
  242. if ('textlayer' in hashParams) {
  243. switch (hashParams['textlayer']) {
  244. case 'off':
  245. viewerPrefs['textLayerMode'] = _ui_utils.TextLayerMode.DISABLE;
  246. break;
  247. case 'visible':
  248. case 'shadow':
  249. case 'hover':
  250. var viewer = appConfig.viewerContainer;
  251. viewer.classList.add('textLayer-' + hashParams['textlayer']);
  252. break;
  253. }
  254. }
  255. if ('pdfbug' in hashParams) {
  256. _pdf.PDFJS.pdfBug = true;
  257. var enabled = hashParams['pdfbug'].split(',');
  258. waitOn.push(loadAndEnablePDFBug(enabled));
  259. }
  260. if ('locale' in hashParams) {
  261. _pdf.PDFJS.locale = hashParams['locale'];
  262. }
  263. }
  264. return Promise.all(waitOn);
  265. },
  266. _initializeL10n: function _initializeL10n() {
  267. this.l10n = this.externalServices.createL10n({ locale: _pdf.PDFJS.locale });
  268. return this.l10n.getDirection().then(function (dir) {
  269. document.getElementsByTagName('html')[0].dir = dir;
  270. });
  271. },
  272. _initializeViewerComponents: function _initializeViewerComponents() {
  273. var _this2 = this;
  274. var appConfig = this.appConfig,
  275. viewerPrefs = this.viewerPrefs;
  276. return new Promise(function (resolve, reject) {
  277. _this2.overlayManager = new _overlay_manager.OverlayManager();
  278. var eventBus = appConfig.eventBus || (0, _dom_events.getGlobalEventBus)();
  279. _this2.eventBus = eventBus;
  280. var pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  281. pdfRenderingQueue.onIdle = _this2.cleanup.bind(_this2);
  282. _this2.pdfRenderingQueue = pdfRenderingQueue;
  283. var pdfLinkService = new _pdf_link_service.PDFLinkService({
  284. eventBus: eventBus,
  285. externalLinkTarget: _pdf.PDFJS.externalLinkTarget,
  286. externalLinkRel: _pdf.PDFJS.externalLinkRel
  287. });
  288. _this2.pdfLinkService = pdfLinkService;
  289. var downloadManager = _this2.externalServices.createDownloadManager();
  290. _this2.downloadManager = downloadManager;
  291. var container = appConfig.mainContainer;
  292. var viewer = appConfig.viewerContainer;
  293. _this2.pdfViewer = new _pdf_viewer.PDFViewer({
  294. container: container,
  295. viewer: viewer,
  296. eventBus: eventBus,
  297. renderingQueue: pdfRenderingQueue,
  298. linkService: pdfLinkService,
  299. downloadManager: downloadManager,
  300. renderer: viewerPrefs['renderer'],
  301. enableWebGL: viewerPrefs['enableWebGL'],
  302. l10n: _this2.l10n,
  303. textLayerMode: viewerPrefs['textLayerMode'],
  304. imageResourcesPath: _pdf.PDFJS.imageResourcesPath,
  305. renderInteractiveForms: viewerPrefs['renderInteractiveForms'],
  306. enablePrintAutoRotate: viewerPrefs['enablePrintAutoRotate'],
  307. useOnlyCssZoom: _pdf.PDFJS.useOnlyCssZoom,
  308. maxCanvasPixels: _pdf.PDFJS.maxCanvasPixels
  309. });
  310. pdfRenderingQueue.setViewer(_this2.pdfViewer);
  311. pdfLinkService.setViewer(_this2.pdfViewer);
  312. var thumbnailContainer = appConfig.sidebar.thumbnailView;
  313. _this2.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  314. container: thumbnailContainer,
  315. renderingQueue: pdfRenderingQueue,
  316. linkService: pdfLinkService,
  317. l10n: _this2.l10n
  318. });
  319. pdfRenderingQueue.setThumbnailViewer(_this2.pdfThumbnailViewer);
  320. _this2.pdfHistory = new _pdf_history.PDFHistory({
  321. linkService: pdfLinkService,
  322. eventBus: eventBus
  323. });
  324. pdfLinkService.setHistory(_this2.pdfHistory);
  325. _this2.findController = new _pdf_find_controller.PDFFindController({ pdfViewer: _this2.pdfViewer });
  326. _this2.findController.onUpdateResultsCount = function (matchCount) {
  327. if (_this2.supportsIntegratedFind) {
  328. return;
  329. }
  330. _this2.findBar.updateResultsCount(matchCount);
  331. };
  332. _this2.findController.onUpdateState = function (state, previous, matchCount) {
  333. if (_this2.supportsIntegratedFind) {
  334. _this2.externalServices.updateFindControlState({
  335. result: state,
  336. findPrevious: previous
  337. });
  338. } else {
  339. _this2.findBar.updateUIState(state, previous, matchCount);
  340. }
  341. };
  342. _this2.pdfViewer.setFindController(_this2.findController);
  343. var findBarConfig = Object.create(appConfig.findBar);
  344. findBarConfig.findController = _this2.findController;
  345. findBarConfig.eventBus = eventBus;
  346. _this2.findBar = new _pdf_find_bar.PDFFindBar(findBarConfig, _this2.l10n);
  347. _this2.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, _this2.overlayManager, _this2.l10n);
  348. _this2.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  349. container: container,
  350. eventBus: eventBus,
  351. preferences: _this2.preferences
  352. });
  353. _this2.toolbar = new _toolbar.Toolbar(appConfig.toolbar, container, eventBus, _this2.l10n);
  354. _this2.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  355. if (_this2.supportsFullscreen) {
  356. _this2.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  357. container: container,
  358. viewer: viewer,
  359. pdfViewer: _this2.pdfViewer,
  360. eventBus: eventBus,
  361. contextMenuItems: appConfig.fullscreen
  362. });
  363. }
  364. _this2.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, _this2.overlayManager, _this2.l10n);
  365. _this2.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  366. container: appConfig.sidebar.outlineView,
  367. eventBus: eventBus,
  368. linkService: pdfLinkService
  369. });
  370. _this2.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  371. container: appConfig.sidebar.attachmentsView,
  372. eventBus: eventBus,
  373. downloadManager: downloadManager
  374. });
  375. var sidebarConfig = Object.create(appConfig.sidebar);
  376. sidebarConfig.pdfViewer = _this2.pdfViewer;
  377. sidebarConfig.pdfThumbnailViewer = _this2.pdfThumbnailViewer;
  378. sidebarConfig.pdfOutlineViewer = _this2.pdfOutlineViewer;
  379. sidebarConfig.eventBus = eventBus;
  380. _this2.pdfSidebar = new _pdf_sidebar.PDFSidebar(sidebarConfig, _this2.l10n);
  381. _this2.pdfSidebar.onToggled = _this2.forceRendering.bind(_this2);
  382. _this2.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, _this2.l10n);
  383. resolve(undefined);
  384. });
  385. },
  386. run: function run(config) {
  387. this.initialize(config).then(webViewerInitialized);
  388. },
  389. zoomIn: function zoomIn(ticks) {
  390. var newScale = this.pdfViewer.currentScale;
  391. do {
  392. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  393. newScale = Math.ceil(newScale * 10) / 10;
  394. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  395. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  396. this.pdfViewer.currentScaleValue = newScale;
  397. },
  398. zoomOut: function zoomOut(ticks) {
  399. var newScale = this.pdfViewer.currentScale;
  400. do {
  401. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  402. newScale = Math.floor(newScale * 10) / 10;
  403. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  404. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  405. this.pdfViewer.currentScaleValue = newScale;
  406. },
  407. get pagesCount() {
  408. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  409. },
  410. set page(val) {
  411. this.pdfViewer.currentPageNumber = val;
  412. },
  413. get page() {
  414. return this.pdfViewer.currentPageNumber;
  415. },
  416. get printing() {
  417. return !!this.printService;
  418. },
  419. get supportsPrinting() {
  420. return PDFPrintServiceFactory.instance.supportsPrinting;
  421. },
  422. get supportsFullscreen() {
  423. var support = void 0;
  424. var doc = document.documentElement;
  425. support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
  426. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
  427. support = false;
  428. }
  429. if (support && _viewer_compatibility.viewerCompatibilityParams['disableFullscreen'] === true) {
  430. support = false;
  431. }
  432. return (0, _pdf.shadow)(this, 'supportsFullscreen', support);
  433. },
  434. get supportsIntegratedFind() {
  435. return this.externalServices.supportsIntegratedFind;
  436. },
  437. get supportsDocumentFonts() {
  438. return this.externalServices.supportsDocumentFonts;
  439. },
  440. get supportsDocumentColors() {
  441. return this.externalServices.supportsDocumentColors;
  442. },
  443. get loadingBar() {
  444. var bar = new _ui_utils.ProgressBar('#loadingBar');
  445. return (0, _pdf.shadow)(this, 'loadingBar', bar);
  446. },
  447. get supportedMouseWheelZoomModifierKeys() {
  448. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  449. },
  450. initPassiveLoading: function initPassiveLoading() {
  451. throw new Error('Not implemented: initPassiveLoading');
  452. },
  453. setTitleUsingUrl: function setTitleUsingUrl(url) {
  454. this.url = url;
  455. this.baseUrl = url.split('#')[0];
  456. var title = (0, _ui_utils.getPDFFileNameFromURL)(url, '');
  457. if (!title) {
  458. try {
  459. title = decodeURIComponent((0, _pdf.getFilenameFromUrl)(url)) || url;
  460. } catch (ex) {
  461. title = url;
  462. }
  463. }
  464. this.setTitle(title);
  465. },
  466. setTitle: function setTitle(title) {
  467. if (this.isViewerEmbedded) {
  468. return;
  469. }
  470. document.title = title;
  471. },
  472. close: function close() {
  473. var errorWrapper = this.appConfig.errorWrapper.container;
  474. errorWrapper.setAttribute('hidden', 'true');
  475. if (!this.pdfLoadingTask) {
  476. return Promise.resolve();
  477. }
  478. var promise = this.pdfLoadingTask.destroy();
  479. this.pdfLoadingTask = null;
  480. if (this.pdfDocument) {
  481. this.pdfDocument = null;
  482. this.pdfThumbnailViewer.setDocument(null);
  483. this.pdfViewer.setDocument(null);
  484. this.pdfLinkService.setDocument(null, null);
  485. this.pdfDocumentProperties.setDocument(null, null);
  486. }
  487. this.store = null;
  488. this.isInitialViewSet = false;
  489. this.downloadComplete = false;
  490. this.url = '';
  491. this.baseUrl = '';
  492. this.contentDispositionFilename = null;
  493. this.pdfSidebar.reset();
  494. this.pdfOutlineViewer.reset();
  495. this.pdfAttachmentViewer.reset();
  496. this.findController.reset();
  497. this.findBar.reset();
  498. this.toolbar.reset();
  499. this.secondaryToolbar.reset();
  500. if (typeof PDFBug !== 'undefined') {
  501. PDFBug.cleanup();
  502. }
  503. return promise;
  504. },
  505. open: function open(file, args) {
  506. var _this3 = this;
  507. if (this.pdfLoadingTask) {
  508. return this.close().then(function () {
  509. _this3.preferences.reload();
  510. return _this3.open(file, args);
  511. });
  512. }
  513. var parameters = Object.create(null);
  514. if (typeof file === 'string') {
  515. this.setTitleUsingUrl(file);
  516. parameters.url = file;
  517. } else if (file && 'byteLength' in file) {
  518. parameters.data = file;
  519. } else if (file.url && file.originalUrl) {
  520. this.setTitleUsingUrl(file.originalUrl);
  521. parameters.url = file.url;
  522. }
  523. if (args) {
  524. for (var prop in args) {
  525. if (prop === 'length') {
  526. this.pdfDocumentProperties.setFileSize(args[prop]);
  527. }
  528. parameters[prop] = args[prop];
  529. }
  530. }
  531. if (this.url && (0, _ui_utils.isFileSchema)(this.url)) {
  532. var appConfig = this.appConfig;
  533. appConfig.toolbar.download.setAttribute('hidden', 'true');
  534. appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
  535. }
  536. var loadingTask = (0, _pdf.getDocument)(parameters);
  537. this.pdfLoadingTask = loadingTask;
  538. loadingTask.onPassword = function (updateCallback, reason) {
  539. _this3.passwordPrompt.setUpdateCallback(updateCallback, reason);
  540. _this3.passwordPrompt.open();
  541. };
  542. loadingTask.onProgress = function (_ref) {
  543. var loaded = _ref.loaded,
  544. total = _ref.total;
  545. _this3.progress(loaded / total);
  546. };
  547. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  548. return loadingTask.promise.then(function (pdfDocument) {
  549. _this3.load(pdfDocument);
  550. }, function (exception) {
  551. if (loadingTask !== _this3.pdfLoadingTask) {
  552. return;
  553. }
  554. var message = exception && exception.message;
  555. var loadingErrorMessage = void 0;
  556. if (exception instanceof _pdf.InvalidPDFException) {
  557. loadingErrorMessage = _this3.l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
  558. } else if (exception instanceof _pdf.MissingPDFException) {
  559. loadingErrorMessage = _this3.l10n.get('missing_file_error', null, 'Missing PDF file.');
  560. } else if (exception instanceof _pdf.UnexpectedResponseException) {
  561. loadingErrorMessage = _this3.l10n.get('unexpected_response_error', null, 'Unexpected server response.');
  562. } else {
  563. loadingErrorMessage = _this3.l10n.get('loading_error', null, 'An error occurred while loading the PDF.');
  564. }
  565. return loadingErrorMessage.then(function (msg) {
  566. _this3.error(msg, { message: message });
  567. throw new Error(msg);
  568. });
  569. });
  570. },
  571. download: function download() {
  572. var _this4 = this;
  573. function downloadByUrl() {
  574. downloadManager.downloadUrl(url, filename);
  575. }
  576. var url = this.baseUrl;
  577. var filename = this.contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url);
  578. var downloadManager = this.downloadManager;
  579. downloadManager.onerror = function (err) {
  580. _this4.error('PDF failed to download: ' + err);
  581. };
  582. if (!this.pdfDocument || !this.downloadComplete) {
  583. downloadByUrl();
  584. return;
  585. }
  586. this.pdfDocument.getData().then(function (data) {
  587. var blob = (0, _pdf.createBlob)(data, 'application/pdf');
  588. downloadManager.download(blob, url, filename);
  589. }).catch(downloadByUrl);
  590. },
  591. fallback: function fallback(featureId) {},
  592. error: function error(message, moreInfo) {
  593. var moreInfoText = [this.l10n.get('error_version_info', {
  594. version: _pdf.version || '?',
  595. build: _pdf.build || '?'
  596. }, 'PDF.js v{{version}} (build: {{build}})')];
  597. if (moreInfo) {
  598. moreInfoText.push(this.l10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}'));
  599. if (moreInfo.stack) {
  600. moreInfoText.push(this.l10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}'));
  601. } else {
  602. if (moreInfo.filename) {
  603. moreInfoText.push(this.l10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}'));
  604. }
  605. if (moreInfo.lineNumber) {
  606. moreInfoText.push(this.l10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}'));
  607. }
  608. }
  609. }
  610. var errorWrapperConfig = this.appConfig.errorWrapper;
  611. var errorWrapper = errorWrapperConfig.container;
  612. errorWrapper.removeAttribute('hidden');
  613. var errorMessage = errorWrapperConfig.errorMessage;
  614. errorMessage.textContent = message;
  615. var closeButton = errorWrapperConfig.closeButton;
  616. closeButton.onclick = function () {
  617. errorWrapper.setAttribute('hidden', 'true');
  618. };
  619. var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  620. var moreInfoButton = errorWrapperConfig.moreInfoButton;
  621. var lessInfoButton = errorWrapperConfig.lessInfoButton;
  622. moreInfoButton.onclick = function () {
  623. errorMoreInfo.removeAttribute('hidden');
  624. moreInfoButton.setAttribute('hidden', 'true');
  625. lessInfoButton.removeAttribute('hidden');
  626. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
  627. };
  628. lessInfoButton.onclick = function () {
  629. errorMoreInfo.setAttribute('hidden', 'true');
  630. moreInfoButton.removeAttribute('hidden');
  631. lessInfoButton.setAttribute('hidden', 'true');
  632. };
  633. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  634. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  635. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  636. moreInfoButton.removeAttribute('hidden');
  637. lessInfoButton.setAttribute('hidden', 'true');
  638. Promise.all(moreInfoText).then(function (parts) {
  639. errorMoreInfo.value = parts.join('\n');
  640. });
  641. },
  642. progress: function progress(level) {
  643. var _this5 = this;
  644. if (this.downloadComplete) {
  645. return;
  646. }
  647. var percent = Math.round(level * 100);
  648. if (percent > this.loadingBar.percent || isNaN(percent)) {
  649. this.loadingBar.percent = percent;
  650. if (_pdf.PDFJS.disableAutoFetch && percent) {
  651. if (this.disableAutoFetchLoadingBarTimeout) {
  652. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  653. this.disableAutoFetchLoadingBarTimeout = null;
  654. }
  655. this.loadingBar.show();
  656. this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
  657. _this5.loadingBar.hide();
  658. _this5.disableAutoFetchLoadingBarTimeout = null;
  659. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  660. }
  661. }
  662. },
  663. load: function load(pdfDocument) {
  664. var _this6 = this;
  665. this.pdfDocument = pdfDocument;
  666. pdfDocument.getDownloadInfo().then(function () {
  667. _this6.downloadComplete = true;
  668. _this6.loadingBar.hide();
  669. firstPagePromise.then(function () {
  670. _this6.eventBus.dispatch('documentload', { source: _this6 });
  671. });
  672. });
  673. var pageModePromise = pdfDocument.getPageMode().catch(function () {});
  674. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  675. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  676. var id = this.documentFingerprint = pdfDocument.fingerprint;
  677. var store = this.store = new _view_history.ViewHistory(id);
  678. var baseDocumentUrl = void 0;
  679. baseDocumentUrl = null;
  680. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  681. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  682. var pdfViewer = this.pdfViewer;
  683. pdfViewer.setDocument(pdfDocument);
  684. var firstPagePromise = pdfViewer.firstPagePromise;
  685. var pagesPromise = pdfViewer.pagesPromise;
  686. var onePageRendered = pdfViewer.onePageRendered;
  687. var pdfThumbnailViewer = this.pdfThumbnailViewer;
  688. pdfThumbnailViewer.setDocument(pdfDocument);
  689. firstPagePromise.then(function (pdfPage) {
  690. _this6.loadingBar.setWidth(_this6.appConfig.viewerContainer);
  691. if (!_pdf.PDFJS.disableHistory && !_this6.isViewerEmbedded) {
  692. var resetHistory = !_this6.viewerPrefs['showPreviousViewOnLoad'];
  693. _this6.pdfHistory.initialize(id, resetHistory);
  694. if (_this6.pdfHistory.initialBookmark) {
  695. _this6.initialBookmark = _this6.pdfHistory.initialBookmark;
  696. _this6.initialRotation = _this6.pdfHistory.initialRotation;
  697. }
  698. }
  699. var initialParams = {
  700. bookmark: null,
  701. hash: null
  702. };
  703. var storePromise = store.getMultiple({
  704. exists: false,
  705. page: '1',
  706. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  707. scrollLeft: '0',
  708. scrollTop: '0',
  709. rotation: null,
  710. sidebarView: _pdf_sidebar.SidebarView.NONE
  711. }).catch(function () {});
  712. Promise.all([storePromise, pageModePromise]).then(function (_ref2) {
  713. var _ref3 = _slicedToArray(_ref2, 2),
  714. _ref3$ = _ref3[0],
  715. values = _ref3$ === undefined ? {} : _ref3$,
  716. pageMode = _ref3[1];
  717. var hash = _this6.viewerPrefs['defaultZoomValue'] ? 'zoom=' + _this6.viewerPrefs['defaultZoomValue'] : null;
  718. var rotation = null;
  719. var sidebarView = _this6.viewerPrefs['sidebarViewOnLoad'];
  720. if (values.exists && _this6.viewerPrefs['showPreviousViewOnLoad']) {
  721. hash = 'page=' + values.page + '&zoom=' + (_this6.viewerPrefs['defaultZoomValue'] || values.zoom) + ',' + values.scrollLeft + ',' + values.scrollTop;
  722. rotation = parseInt(values.rotation, 10);
  723. sidebarView = sidebarView || values.sidebarView | 0;
  724. }
  725. if (pageMode && !_this6.viewerPrefs['disablePageMode']) {
  726. sidebarView = sidebarView || apiPageModeToSidebarView(pageMode);
  727. }
  728. return {
  729. hash: hash,
  730. rotation: rotation,
  731. sidebarView: sidebarView
  732. };
  733. }).then(function (_ref4) {
  734. var hash = _ref4.hash,
  735. rotation = _ref4.rotation,
  736. sidebarView = _ref4.sidebarView;
  737. initialParams.bookmark = _this6.initialBookmark;
  738. initialParams.hash = hash;
  739. _this6.setInitialView(hash, {
  740. rotation: rotation,
  741. sidebarView: sidebarView
  742. });
  743. if (!_this6.isViewerEmbedded) {
  744. pdfViewer.focus();
  745. }
  746. return pagesPromise;
  747. }).then(function () {
  748. if (!initialParams.bookmark && !initialParams.hash) {
  749. return;
  750. }
  751. if (pdfViewer.hasEqualPageSizes) {
  752. return;
  753. }
  754. _this6.initialBookmark = initialParams.bookmark;
  755. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  756. _this6.setInitialView(initialParams.hash);
  757. }).then(function () {
  758. pdfViewer.update();
  759. });
  760. });
  761. pdfDocument.getPageLabels().then(function (labels) {
  762. if (!labels || _this6.viewerPrefs['disablePageLabels']) {
  763. return;
  764. }
  765. var i = 0,
  766. numLabels = labels.length;
  767. if (numLabels !== _this6.pagesCount) {
  768. console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
  769. return;
  770. }
  771. while (i < numLabels && labels[i] === (i + 1).toString()) {
  772. i++;
  773. }
  774. if (i === numLabels) {
  775. return;
  776. }
  777. pdfViewer.setPageLabels(labels);
  778. pdfThumbnailViewer.setPageLabels(labels);
  779. _this6.toolbar.setPagesCount(pdfDocument.numPages, true);
  780. _this6.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  781. });
  782. pagesPromise.then(function () {
  783. if (!_this6.supportsPrinting) {
  784. return;
  785. }
  786. pdfDocument.getJavaScript().then(function (javaScript) {
  787. if (!javaScript) {
  788. return;
  789. }
  790. javaScript.some(function (js) {
  791. if (!js) {
  792. return false;
  793. }
  794. console.warn('Warning: JavaScript is not supported');
  795. _this6.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
  796. return true;
  797. });
  798. var regex = /\bprint\s*\(/;
  799. for (var i = 0, ii = javaScript.length; i < ii; i++) {
  800. var js = javaScript[i];
  801. if (js && regex.test(js)) {
  802. setTimeout(function () {
  803. window.print();
  804. });
  805. return;
  806. }
  807. }
  808. });
  809. });
  810. Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
  811. pdfDocument.getOutline().then(function (outline) {
  812. _this6.pdfOutlineViewer.render({ outline: outline });
  813. });
  814. pdfDocument.getAttachments().then(function (attachments) {
  815. _this6.pdfAttachmentViewer.render({ attachments: attachments });
  816. });
  817. });
  818. pdfDocument.getMetadata().then(function (_ref5) {
  819. var info = _ref5.info,
  820. metadata = _ref5.metadata,
  821. contentDispositionFilename = _ref5.contentDispositionFilename;
  822. _this6.documentInfo = info;
  823. _this6.metadata = metadata;
  824. _this6.contentDispositionFilename = contentDispositionFilename;
  825. console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (_pdf.version || '-') + (_this6.viewerPrefs['enableWebGL'] ? ' [WebGL]' : '') + ')');
  826. var pdfTitle = void 0;
  827. if (metadata && metadata.has('dc:title')) {
  828. var title = metadata.get('dc:title');
  829. if (title !== 'Untitled') {
  830. pdfTitle = title;
  831. }
  832. }
  833. if (!pdfTitle && info && info['Title']) {
  834. pdfTitle = info['Title'];
  835. }
  836. if (pdfTitle) {
  837. _this6.setTitle(pdfTitle + ' - ' + (contentDispositionFilename || document.title));
  838. } else if (contentDispositionFilename) {
  839. _this6.setTitle(contentDispositionFilename);
  840. }
  841. if (info.IsAcroFormPresent) {
  842. console.warn('Warning: AcroForm/XFA is not supported');
  843. _this6.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
  844. }
  845. });
  846. },
  847. setInitialView: function setInitialView(storedHash) {
  848. var _this7 = this;
  849. var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  850. rotation = _ref6.rotation,
  851. sidebarView = _ref6.sidebarView;
  852. var setRotation = function setRotation(angle) {
  853. if ((0, _ui_utils.isValidRotation)(angle)) {
  854. _this7.pdfViewer.pagesRotation = angle;
  855. }
  856. };
  857. this.isInitialViewSet = true;
  858. this.pdfSidebar.setInitialView(sidebarView);
  859. if (this.initialBookmark) {
  860. setRotation(this.initialRotation);
  861. delete this.initialRotation;
  862. this.pdfLinkService.setHash(this.initialBookmark);
  863. this.initialBookmark = null;
  864. } else if (storedHash) {
  865. setRotation(rotation);
  866. this.pdfLinkService.setHash(storedHash);
  867. }
  868. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  869. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  870. if (!this.pdfViewer.currentScaleValue) {
  871. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  872. }
  873. },
  874. cleanup: function cleanup() {
  875. if (!this.pdfDocument) {
  876. return;
  877. }
  878. this.pdfViewer.cleanup();
  879. this.pdfThumbnailViewer.cleanup();
  880. if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
  881. this.pdfDocument.cleanup();
  882. }
  883. },
  884. forceRendering: function forceRendering() {
  885. this.pdfRenderingQueue.printing = this.printing;
  886. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  887. this.pdfRenderingQueue.renderHighestPriority();
  888. },
  889. beforePrint: function beforePrint() {
  890. var _this8 = this;
  891. if (this.printService) {
  892. return;
  893. }
  894. if (!this.supportsPrinting) {
  895. this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
  896. _this8.error(printMessage);
  897. });
  898. return;
  899. }
  900. if (!this.pdfViewer.pageViewsReady) {
  901. this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
  902. window.alert(notReadyMessage);
  903. });
  904. return;
  905. }
  906. var pagesOverview = this.pdfViewer.getPagesOverview();
  907. var printContainer = this.appConfig.printContainer;
  908. var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
  909. this.printService = printService;
  910. this.forceRendering();
  911. printService.layout();
  912. },
  913. afterPrint: function pdfViewSetupAfterPrint() {
  914. if (this.printService) {
  915. this.printService.destroy();
  916. this.printService = null;
  917. }
  918. this.forceRendering();
  919. },
  920. rotatePages: function rotatePages(delta) {
  921. if (!this.pdfDocument) {
  922. return;
  923. }
  924. var newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
  925. this.pdfViewer.pagesRotation = newRotation;
  926. },
  927. requestPresentationMode: function requestPresentationMode() {
  928. if (!this.pdfPresentationMode) {
  929. return;
  930. }
  931. this.pdfPresentationMode.request();
  932. },
  933. bindEvents: function bindEvents() {
  934. var eventBus = this.eventBus,
  935. _boundEvents = this._boundEvents;
  936. _boundEvents.beforePrint = this.beforePrint.bind(this);
  937. _boundEvents.afterPrint = this.afterPrint.bind(this);
  938. eventBus.on('resize', webViewerResize);
  939. eventBus.on('hashchange', webViewerHashchange);
  940. eventBus.on('beforeprint', _boundEvents.beforePrint);
  941. eventBus.on('afterprint', _boundEvents.afterPrint);
  942. eventBus.on('pagerendered', webViewerPageRendered);
  943. eventBus.on('textlayerrendered', webViewerTextLayerRendered);
  944. eventBus.on('updateviewarea', webViewerUpdateViewarea);
  945. eventBus.on('pagechanging', webViewerPageChanging);
  946. eventBus.on('scalechanging', webViewerScaleChanging);
  947. eventBus.on('rotationchanging', webViewerRotationChanging);
  948. eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
  949. eventBus.on('pagemode', webViewerPageMode);
  950. eventBus.on('namedaction', webViewerNamedAction);
  951. eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
  952. eventBus.on('presentationmode', webViewerPresentationMode);
  953. eventBus.on('openfile', webViewerOpenFile);
  954. eventBus.on('print', webViewerPrint);
  955. eventBus.on('download', webViewerDownload);
  956. eventBus.on('firstpage', webViewerFirstPage);
  957. eventBus.on('lastpage', webViewerLastPage);
  958. eventBus.on('nextpage', webViewerNextPage);
  959. eventBus.on('previouspage', webViewerPreviousPage);
  960. eventBus.on('zoomin', webViewerZoomIn);
  961. eventBus.on('zoomout', webViewerZoomOut);
  962. eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
  963. eventBus.on('scalechanged', webViewerScaleChanged);
  964. eventBus.on('rotatecw', webViewerRotateCw);
  965. eventBus.on('rotateccw', webViewerRotateCcw);
  966. eventBus.on('documentproperties', webViewerDocumentProperties);
  967. eventBus.on('find', webViewerFind);
  968. eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
  969. eventBus.on('fileinputchange', webViewerFileInputChange);
  970. },
  971. bindWindowEvents: function bindWindowEvents() {
  972. var eventBus = this.eventBus,
  973. _boundEvents = this._boundEvents;
  974. _boundEvents.windowResize = function () {
  975. eventBus.dispatch('resize', { source: window });
  976. };
  977. _boundEvents.windowHashChange = function () {
  978. eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
  979. };
  980. _boundEvents.windowBeforePrint = function () {
  981. eventBus.dispatch('beforeprint');
  982. };
  983. _boundEvents.windowAfterPrint = function () {
  984. eventBus.dispatch('afterprint');
  985. };
  986. window.addEventListener('wheel', webViewerWheel);
  987. window.addEventListener('click', webViewerClick);
  988. window.addEventListener('keydown', webViewerKeyDown);
  989. window.addEventListener('resize', _boundEvents.windowResize);
  990. window.addEventListener('hashchange', _boundEvents.windowHashChange);
  991. window.addEventListener('beforeprint', _boundEvents.windowBeforePrint);
  992. window.addEventListener('afterprint', _boundEvents.windowAfterPrint);
  993. },
  994. unbindEvents: function unbindEvents() {
  995. var eventBus = this.eventBus,
  996. _boundEvents = this._boundEvents;
  997. eventBus.off('resize', webViewerResize);
  998. eventBus.off('hashchange', webViewerHashchange);
  999. eventBus.off('beforeprint', _boundEvents.beforePrint);
  1000. eventBus.off('afterprint', _boundEvents.afterPrint);
  1001. eventBus.off('pagerendered', webViewerPageRendered);
  1002. eventBus.off('textlayerrendered', webViewerTextLayerRendered);
  1003. eventBus.off('updateviewarea', webViewerUpdateViewarea);
  1004. eventBus.off('pagechanging', webViewerPageChanging);
  1005. eventBus.off('scalechanging', webViewerScaleChanging);
  1006. eventBus.off('rotationchanging', webViewerRotationChanging);
  1007. eventBus.off('sidebarviewchanged', webViewerSidebarViewChanged);
  1008. eventBus.off('pagemode', webViewerPageMode);
  1009. eventBus.off('namedaction', webViewerNamedAction);
  1010. eventBus.off('presentationmodechanged', webViewerPresentationModeChanged);
  1011. eventBus.off('presentationmode', webViewerPresentationMode);
  1012. eventBus.off('openfile', webViewerOpenFile);
  1013. eventBus.off('print', webViewerPrint);
  1014. eventBus.off('download', webViewerDownload);
  1015. eventBus.off('firstpage', webViewerFirstPage);
  1016. eventBus.off('lastpage', webViewerLastPage);
  1017. eventBus.off('nextpage', webViewerNextPage);
  1018. eventBus.off('previouspage', webViewerPreviousPage);
  1019. eventBus.off('zoomin', webViewerZoomIn);
  1020. eventBus.off('zoomout', webViewerZoomOut);
  1021. eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
  1022. eventBus.off('scalechanged', webViewerScaleChanged);
  1023. eventBus.off('rotatecw', webViewerRotateCw);
  1024. eventBus.off('rotateccw', webViewerRotateCcw);
  1025. eventBus.off('documentproperties', webViewerDocumentProperties);
  1026. eventBus.off('find', webViewerFind);
  1027. eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
  1028. eventBus.off('fileinputchange', webViewerFileInputChange);
  1029. _boundEvents.beforePrint = null;
  1030. _boundEvents.afterPrint = null;
  1031. },
  1032. unbindWindowEvents: function unbindWindowEvents() {
  1033. var _boundEvents = this._boundEvents;
  1034. window.removeEventListener('wheel', webViewerWheel);
  1035. window.removeEventListener('click', webViewerClick);
  1036. window.removeEventListener('keydown', webViewerKeyDown);
  1037. window.removeEventListener('resize', _boundEvents.windowResize);
  1038. window.removeEventListener('hashchange', _boundEvents.windowHashChange);
  1039. window.removeEventListener('beforeprint', _boundEvents.windowBeforePrint);
  1040. window.removeEventListener('afterprint', _boundEvents.windowAfterPrint);
  1041. _boundEvents.windowResize = null;
  1042. _boundEvents.windowHashChange = null;
  1043. _boundEvents.windowBeforePrint = null;
  1044. _boundEvents.windowAfterPrint = null;
  1045. }
  1046. };
  1047. var validateFileURL = void 0;
  1048. {
  1049. var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
  1050. validateFileURL = function validateFileURL(file) {
  1051. if (file === undefined) {
  1052. return;
  1053. }
  1054. try {
  1055. var viewerOrigin = new URL(window.location.href).origin || 'null';
  1056. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1057. return;
  1058. }
  1059. var fileOrigin = new URL(file, window.location.href).origin;
  1060. if (fileOrigin !== viewerOrigin) {
  1061. throw new Error('file origin does not match viewer\'s');
  1062. }
  1063. } catch (ex) {
  1064. var message = ex && ex.message;
  1065. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
  1066. PDFViewerApplication.error(loadingErrorMessage, { message: message });
  1067. });
  1068. throw ex;
  1069. }
  1070. };
  1071. }
  1072. function loadFakeWorker() {
  1073. return new Promise(function (resolve, reject) {
  1074. var script = document.createElement('script');
  1075. script.src = _pdf.PDFWorker.getWorkerSrc();
  1076. script.onload = function () {
  1077. resolve();
  1078. };
  1079. script.onerror = function () {
  1080. reject(new Error('Cannot load fake worker at: ' + script.src));
  1081. };
  1082. (document.head || document.documentElement).appendChild(script);
  1083. });
  1084. }
  1085. function loadAndEnablePDFBug(enabledTabs) {
  1086. return new Promise(function (resolve, reject) {
  1087. var appConfig = PDFViewerApplication.appConfig;
  1088. var script = document.createElement('script');
  1089. script.src = appConfig.debuggerScriptPath;
  1090. script.onload = function () {
  1091. PDFBug.enable(enabledTabs);
  1092. PDFBug.init({ OPS: _pdf.OPS }, appConfig.mainContainer);
  1093. resolve();
  1094. };
  1095. script.onerror = function () {
  1096. reject(new Error('Cannot load debugger at ' + script.src));
  1097. };
  1098. (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
  1099. });
  1100. }
  1101. function webViewerInitialized() {
  1102. var appConfig = PDFViewerApplication.appConfig;
  1103. var file = void 0;
  1104. var queryString = document.location.search.substring(1);
  1105. var params = (0, _ui_utils.parseQueryString)(queryString);
  1106. file = 'file' in params ? params.file : appConfig.defaultUrl;
  1107. validateFileURL(file);
  1108. var fileInput = document.createElement('input');
  1109. fileInput.id = appConfig.openFileInputName;
  1110. fileInput.className = 'fileInput';
  1111. fileInput.setAttribute('type', 'file');
  1112. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1113. document.body.appendChild(fileInput);
  1114. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1115. appConfig.toolbar.openFile.setAttribute('hidden', 'true');
  1116. appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
  1117. } else {
  1118. fileInput.value = null;
  1119. }
  1120. fileInput.addEventListener('change', function (evt) {
  1121. var files = evt.target.files;
  1122. if (!files || files.length === 0) {
  1123. return;
  1124. }
  1125. PDFViewerApplication.eventBus.dispatch('fileinputchange', { fileInput: evt.target });
  1126. });
  1127. if (!PDFViewerApplication.supportsPrinting) {
  1128. appConfig.toolbar.print.classList.add('hidden');
  1129. appConfig.secondaryToolbar.printButton.classList.add('hidden');
  1130. }
  1131. if (!PDFViewerApplication.supportsFullscreen) {
  1132. appConfig.toolbar.presentationModeButton.classList.add('hidden');
  1133. appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
  1134. }
  1135. if (PDFViewerApplication.supportsIntegratedFind) {
  1136. appConfig.toolbar.viewFind.classList.add('hidden');
  1137. }
  1138. appConfig.mainContainer.addEventListener('transitionend', function (evt) {
  1139. if (evt.target === this) {
  1140. PDFViewerApplication.eventBus.dispatch('resize', { source: this });
  1141. }
  1142. }, true);
  1143. appConfig.sidebar.toggleButton.addEventListener('click', function () {
  1144. PDFViewerApplication.pdfSidebar.toggle();
  1145. });
  1146. Promise.resolve().then(function () {
  1147. webViewerOpenFileViaURL(file);
  1148. }).catch(function (reason) {
  1149. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
  1150. PDFViewerApplication.error(msg, reason);
  1151. });
  1152. });
  1153. }
  1154. var webViewerOpenFileViaURL = void 0;
  1155. {
  1156. webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
  1157. if (file && file.lastIndexOf('file:', 0) === 0) {
  1158. PDFViewerApplication.setTitleUsingUrl(file);
  1159. var xhr = new XMLHttpRequest();
  1160. xhr.onload = function () {
  1161. PDFViewerApplication.open(new Uint8Array(xhr.response));
  1162. };
  1163. try {
  1164. xhr.open('GET', file);
  1165. xhr.responseType = 'arraybuffer';
  1166. xhr.send();
  1167. } catch (ex) {
  1168. throw ex;
  1169. }
  1170. return;
  1171. }
  1172. if (file) {
  1173. PDFViewerApplication.open(file);
  1174. }
  1175. };
  1176. }
  1177. function webViewerPageRendered(evt) {
  1178. var pageNumber = evt.pageNumber;
  1179. var pageIndex = pageNumber - 1;
  1180. var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  1181. if (pageNumber === PDFViewerApplication.page) {
  1182. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1183. }
  1184. if (!pageView) {
  1185. return;
  1186. }
  1187. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1188. var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  1189. thumbnailView.setImage(pageView);
  1190. }
  1191. if (typeof Stats !== 'undefined' && Stats.enabled && pageView.stats) {
  1192. Stats.add(pageNumber, pageView.stats);
  1193. }
  1194. if (pageView.error) {
  1195. PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
  1196. PDFViewerApplication.error(msg, pageView.error);
  1197. });
  1198. }
  1199. }
  1200. function webViewerTextLayerRendered(evt) {}
  1201. function webViewerPageMode(evt) {
  1202. var mode = evt.mode,
  1203. view = void 0;
  1204. switch (mode) {
  1205. case 'thumbs':
  1206. view = _pdf_sidebar.SidebarView.THUMBS;
  1207. break;
  1208. case 'bookmarks':
  1209. case 'outline':
  1210. view = _pdf_sidebar.SidebarView.OUTLINE;
  1211. break;
  1212. case 'attachments':
  1213. view = _pdf_sidebar.SidebarView.ATTACHMENTS;
  1214. break;
  1215. case 'none':
  1216. view = _pdf_sidebar.SidebarView.NONE;
  1217. break;
  1218. default:
  1219. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1220. return;
  1221. }
  1222. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1223. }
  1224. function webViewerNamedAction(evt) {
  1225. var action = evt.action;
  1226. switch (action) {
  1227. case 'GoToPage':
  1228. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1229. break;
  1230. case 'Find':
  1231. if (!PDFViewerApplication.supportsIntegratedFind) {
  1232. PDFViewerApplication.findBar.toggle();
  1233. }
  1234. break;
  1235. }
  1236. }
  1237. function webViewerPresentationModeChanged(evt) {
  1238. var active = evt.active,
  1239. switchInProgress = evt.switchInProgress;
  1240. PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _ui_utils.PresentationModeState.CHANGING : active ? _ui_utils.PresentationModeState.FULLSCREEN : _ui_utils.PresentationModeState.NORMAL;
  1241. }
  1242. function webViewerSidebarViewChanged(evt) {
  1243. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1244. var store = PDFViewerApplication.store;
  1245. if (store && PDFViewerApplication.isInitialViewSet) {
  1246. store.set('sidebarView', evt.view).catch(function () {});
  1247. }
  1248. }
  1249. function webViewerUpdateViewarea(evt) {
  1250. var location = evt.location,
  1251. store = PDFViewerApplication.store;
  1252. if (store && PDFViewerApplication.isInitialViewSet) {
  1253. store.setMultiple({
  1254. 'exists': true,
  1255. 'page': location.pageNumber,
  1256. 'zoom': location.scale,
  1257. 'scrollLeft': location.left,
  1258. 'scrollTop': location.top,
  1259. 'rotation': location.rotation
  1260. }).catch(function () {});
  1261. }
  1262. var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1263. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1264. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1265. var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1266. var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1267. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1268. }
  1269. function webViewerResize() {
  1270. var pdfDocument = PDFViewerApplication.pdfDocument,
  1271. pdfViewer = PDFViewerApplication.pdfViewer;
  1272. if (!pdfDocument) {
  1273. return;
  1274. }
  1275. var currentScaleValue = pdfViewer.currentScaleValue;
  1276. if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
  1277. pdfViewer.currentScaleValue = currentScaleValue;
  1278. }
  1279. pdfViewer.update();
  1280. }
  1281. function webViewerHashchange(evt) {
  1282. var hash = evt.hash;
  1283. if (!hash) {
  1284. return;
  1285. }
  1286. if (!PDFViewerApplication.isInitialViewSet) {
  1287. PDFViewerApplication.initialBookmark = hash;
  1288. } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  1289. PDFViewerApplication.pdfLinkService.setHash(hash);
  1290. }
  1291. }
  1292. var webViewerFileInputChange = void 0;
  1293. {
  1294. webViewerFileInputChange = function webViewerFileInputChange(evt) {
  1295. var file = evt.fileInput.files[0];
  1296. if (!_pdf.PDFJS.disableCreateObjectURL && URL.createObjectURL) {
  1297. PDFViewerApplication.open(URL.createObjectURL(file));
  1298. } else {
  1299. var fileReader = new FileReader();
  1300. fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
  1301. var buffer = evt.target.result;
  1302. PDFViewerApplication.open(new Uint8Array(buffer));
  1303. };
  1304. fileReader.readAsArrayBuffer(file);
  1305. }
  1306. PDFViewerApplication.setTitleUsingUrl(file.name);
  1307. var appConfig = PDFViewerApplication.appConfig;
  1308. appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
  1309. appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
  1310. appConfig.toolbar.download.setAttribute('hidden', 'true');
  1311. appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
  1312. };
  1313. }
  1314. function webViewerPresentationMode() {
  1315. PDFViewerApplication.requestPresentationMode();
  1316. }
  1317. function webViewerOpenFile() {
  1318. var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  1319. document.getElementById(openFileInputName).click();
  1320. }
  1321. function webViewerPrint() {
  1322. window.print();
  1323. }
  1324. function webViewerDownload() {
  1325. PDFViewerApplication.download();
  1326. }
  1327. function webViewerFirstPage() {
  1328. if (PDFViewerApplication.pdfDocument) {
  1329. PDFViewerApplication.page = 1;
  1330. }
  1331. }
  1332. function webViewerLastPage() {
  1333. if (PDFViewerApplication.pdfDocument) {
  1334. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1335. }
  1336. }
  1337. function webViewerNextPage() {
  1338. PDFViewerApplication.page++;
  1339. }
  1340. function webViewerPreviousPage() {
  1341. PDFViewerApplication.page--;
  1342. }
  1343. function webViewerZoomIn() {
  1344. PDFViewerApplication.zoomIn();
  1345. }
  1346. function webViewerZoomOut() {
  1347. PDFViewerApplication.zoomOut();
  1348. }
  1349. function webViewerPageNumberChanged(evt) {
  1350. var pdfViewer = PDFViewerApplication.pdfViewer;
  1351. pdfViewer.currentPageLabel = evt.value;
  1352. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1353. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1354. }
  1355. }
  1356. function webViewerScaleChanged(evt) {
  1357. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1358. }
  1359. function webViewerRotateCw() {
  1360. PDFViewerApplication.rotatePages(90);
  1361. }
  1362. function webViewerRotateCcw() {
  1363. PDFViewerApplication.rotatePages(-90);
  1364. }
  1365. function webViewerDocumentProperties() {
  1366. PDFViewerApplication.pdfDocumentProperties.open();
  1367. }
  1368. function webViewerFind(evt) {
  1369. PDFViewerApplication.findController.executeCommand('find' + evt.type, {
  1370. query: evt.query,
  1371. phraseSearch: evt.phraseSearch,
  1372. caseSensitive: evt.caseSensitive,
  1373. highlightAll: evt.highlightAll,
  1374. findPrevious: evt.findPrevious
  1375. });
  1376. }
  1377. function webViewerFindFromUrlHash(evt) {
  1378. PDFViewerApplication.findController.executeCommand('find', {
  1379. query: evt.query,
  1380. phraseSearch: evt.phraseSearch,
  1381. caseSensitive: false,
  1382. highlightAll: true,
  1383. findPrevious: false
  1384. });
  1385. }
  1386. function webViewerScaleChanging(evt) {
  1387. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  1388. PDFViewerApplication.pdfViewer.update();
  1389. }
  1390. function webViewerRotationChanging(evt) {
  1391. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  1392. PDFViewerApplication.forceRendering();
  1393. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  1394. }
  1395. function webViewerPageChanging(evt) {
  1396. var page = evt.pageNumber;
  1397. PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
  1398. PDFViewerApplication.secondaryToolbar.setPageNumber(page);
  1399. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1400. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
  1401. }
  1402. if (typeof Stats !== 'undefined' && Stats.enabled) {
  1403. var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
  1404. if (pageView && pageView.stats) {
  1405. Stats.add(page, pageView.stats);
  1406. }
  1407. }
  1408. }
  1409. var zoomDisabled = false,
  1410. zoomDisabledTimeout = void 0;
  1411. function webViewerWheel(evt) {
  1412. var pdfViewer = PDFViewerApplication.pdfViewer;
  1413. if (pdfViewer.isInPresentationMode) {
  1414. return;
  1415. }
  1416. if (evt.ctrlKey || evt.metaKey) {
  1417. var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
  1418. if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
  1419. return;
  1420. }
  1421. evt.preventDefault();
  1422. if (zoomDisabled) {
  1423. return;
  1424. }
  1425. var previousScale = pdfViewer.currentScale;
  1426. var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  1427. var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
  1428. var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
  1429. if (ticks < 0) {
  1430. PDFViewerApplication.zoomOut(-ticks);
  1431. } else {
  1432. PDFViewerApplication.zoomIn(ticks);
  1433. }
  1434. var currentScale = pdfViewer.currentScale;
  1435. if (previousScale !== currentScale) {
  1436. var scaleCorrectionFactor = currentScale / previousScale - 1;
  1437. var rect = pdfViewer.container.getBoundingClientRect();
  1438. var dx = evt.clientX - rect.left;
  1439. var dy = evt.clientY - rect.top;
  1440. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  1441. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  1442. }
  1443. } else {
  1444. zoomDisabled = true;
  1445. clearTimeout(zoomDisabledTimeout);
  1446. zoomDisabledTimeout = setTimeout(function () {
  1447. zoomDisabled = false;
  1448. }, 1000);
  1449. }
  1450. }
  1451. function webViewerClick(evt) {
  1452. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  1453. return;
  1454. }
  1455. var appConfig = PDFViewerApplication.appConfig;
  1456. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  1457. PDFViewerApplication.secondaryToolbar.close();
  1458. }
  1459. }
  1460. function webViewerKeyDown(evt) {
  1461. if (PDFViewerApplication.overlayManager.active) {
  1462. return;
  1463. }
  1464. var handled = false,
  1465. ensureViewerFocused = false;
  1466. var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  1467. var pdfViewer = PDFViewerApplication.pdfViewer;
  1468. var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
  1469. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  1470. switch (evt.keyCode) {
  1471. case 70:
  1472. if (!PDFViewerApplication.supportsIntegratedFind) {
  1473. PDFViewerApplication.findBar.open();
  1474. handled = true;
  1475. }
  1476. break;
  1477. case 71:
  1478. if (!PDFViewerApplication.supportsIntegratedFind) {
  1479. var findState = PDFViewerApplication.findController.state;
  1480. if (findState) {
  1481. PDFViewerApplication.findController.executeCommand('findagain', {
  1482. query: findState.query,
  1483. phraseSearch: findState.phraseSearch,
  1484. caseSensitive: findState.caseSensitive,
  1485. highlightAll: findState.highlightAll,
  1486. findPrevious: cmd === 5 || cmd === 12
  1487. });
  1488. }
  1489. handled = true;
  1490. }
  1491. break;
  1492. case 61:
  1493. case 107:
  1494. case 187:
  1495. case 171:
  1496. if (!isViewerInPresentationMode) {
  1497. PDFViewerApplication.zoomIn();
  1498. }
  1499. handled = true;
  1500. break;
  1501. case 173:
  1502. case 109:
  1503. case 189:
  1504. if (!isViewerInPresentationMode) {
  1505. PDFViewerApplication.zoomOut();
  1506. }
  1507. handled = true;
  1508. break;
  1509. case 48:
  1510. case 96:
  1511. if (!isViewerInPresentationMode) {
  1512. setTimeout(function () {
  1513. pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1514. });
  1515. handled = false;
  1516. }
  1517. break;
  1518. case 38:
  1519. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1520. PDFViewerApplication.page = 1;
  1521. handled = true;
  1522. ensureViewerFocused = true;
  1523. }
  1524. break;
  1525. case 40:
  1526. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1527. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1528. handled = true;
  1529. ensureViewerFocused = true;
  1530. }
  1531. break;
  1532. }
  1533. }
  1534. if (cmd === 1 || cmd === 8) {
  1535. switch (evt.keyCode) {
  1536. case 83:
  1537. PDFViewerApplication.download();
  1538. handled = true;
  1539. break;
  1540. }
  1541. }
  1542. if (cmd === 3 || cmd === 10) {
  1543. switch (evt.keyCode) {
  1544. case 80:
  1545. PDFViewerApplication.requestPresentationMode();
  1546. handled = true;
  1547. break;
  1548. case 71:
  1549. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1550. handled = true;
  1551. break;
  1552. }
  1553. }
  1554. if (handled) {
  1555. if (ensureViewerFocused && !isViewerInPresentationMode) {
  1556. pdfViewer.focus();
  1557. }
  1558. evt.preventDefault();
  1559. return;
  1560. }
  1561. var curElement = document.activeElement || document.querySelector(':focus');
  1562. var curElementTagName = curElement && curElement.tagName.toUpperCase();
  1563. if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
  1564. if (evt.keyCode !== 27) {
  1565. return;
  1566. }
  1567. }
  1568. if (cmd === 0) {
  1569. switch (evt.keyCode) {
  1570. case 38:
  1571. case 33:
  1572. case 8:
  1573. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1574. break;
  1575. }
  1576. case 37:
  1577. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1578. break;
  1579. }
  1580. case 75:
  1581. case 80:
  1582. if (PDFViewerApplication.page > 1) {
  1583. PDFViewerApplication.page--;
  1584. }
  1585. handled = true;
  1586. break;
  1587. case 27:
  1588. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  1589. PDFViewerApplication.secondaryToolbar.close();
  1590. handled = true;
  1591. }
  1592. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  1593. PDFViewerApplication.findBar.close();
  1594. handled = true;
  1595. }
  1596. break;
  1597. case 13:
  1598. case 40:
  1599. case 34:
  1600. case 32:
  1601. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1602. break;
  1603. }
  1604. case 39:
  1605. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1606. break;
  1607. }
  1608. case 74:
  1609. case 78:
  1610. if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1611. PDFViewerApplication.page++;
  1612. }
  1613. handled = true;
  1614. break;
  1615. case 36:
  1616. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1617. PDFViewerApplication.page = 1;
  1618. handled = true;
  1619. ensureViewerFocused = true;
  1620. }
  1621. break;
  1622. case 35:
  1623. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1624. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1625. handled = true;
  1626. ensureViewerFocused = true;
  1627. }
  1628. break;
  1629. case 83:
  1630. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  1631. break;
  1632. case 72:
  1633. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  1634. break;
  1635. case 82:
  1636. PDFViewerApplication.rotatePages(90);
  1637. break;
  1638. }
  1639. }
  1640. if (cmd === 4) {
  1641. switch (evt.keyCode) {
  1642. case 13:
  1643. case 32:
  1644. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1645. break;
  1646. }
  1647. if (PDFViewerApplication.page > 1) {
  1648. PDFViewerApplication.page--;
  1649. }
  1650. handled = true;
  1651. break;
  1652. case 82:
  1653. PDFViewerApplication.rotatePages(-90);
  1654. break;
  1655. }
  1656. }
  1657. if (!handled && !isViewerInPresentationMode) {
  1658. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
  1659. ensureViewerFocused = true;
  1660. }
  1661. }
  1662. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  1663. pdfViewer.focus();
  1664. }
  1665. if (handled) {
  1666. evt.preventDefault();
  1667. }
  1668. }
  1669. function apiPageModeToSidebarView(mode) {
  1670. switch (mode) {
  1671. case 'UseNone':
  1672. return _pdf_sidebar.SidebarView.NONE;
  1673. case 'UseThumbs':
  1674. return _pdf_sidebar.SidebarView.THUMBS;
  1675. case 'UseOutlines':
  1676. return _pdf_sidebar.SidebarView.OUTLINE;
  1677. case 'UseAttachments':
  1678. return _pdf_sidebar.SidebarView.ATTACHMENTS;
  1679. case 'UseOC':
  1680. }
  1681. return _pdf_sidebar.SidebarView.NONE;
  1682. }
  1683. var PDFPrintServiceFactory = {
  1684. instance: {
  1685. supportsPrinting: false,
  1686. createPrintService: function createPrintService() {
  1687. throw new Error('Not implemented: createPrintService');
  1688. }
  1689. }
  1690. };
  1691. exports.PDFViewerApplication = PDFViewerApplication;
  1692. exports.DefaultExternalServices = DefaultExternalServices;
  1693. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;