app.js 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745
  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. _pdf.GlobalWorkerOptions.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. parameters.verbosity = _pdf.PDFJS.verbosity;
  524. if (args) {
  525. for (var prop in args) {
  526. if (prop === 'length') {
  527. this.pdfDocumentProperties.setFileSize(args[prop]);
  528. }
  529. parameters[prop] = args[prop];
  530. }
  531. }
  532. if (this.url && (0, _ui_utils.isFileSchema)(this.url)) {
  533. var appConfig = this.appConfig;
  534. appConfig.toolbar.download.setAttribute('hidden', 'true');
  535. appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
  536. }
  537. var loadingTask = (0, _pdf.getDocument)(parameters);
  538. this.pdfLoadingTask = loadingTask;
  539. loadingTask.onPassword = function (updateCallback, reason) {
  540. _this3.passwordPrompt.setUpdateCallback(updateCallback, reason);
  541. _this3.passwordPrompt.open();
  542. };
  543. loadingTask.onProgress = function (_ref) {
  544. var loaded = _ref.loaded,
  545. total = _ref.total;
  546. _this3.progress(loaded / total);
  547. };
  548. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  549. return loadingTask.promise.then(function (pdfDocument) {
  550. _this3.load(pdfDocument);
  551. }, function (exception) {
  552. if (loadingTask !== _this3.pdfLoadingTask) {
  553. return;
  554. }
  555. var message = exception && exception.message;
  556. var loadingErrorMessage = void 0;
  557. if (exception instanceof _pdf.InvalidPDFException) {
  558. loadingErrorMessage = _this3.l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
  559. } else if (exception instanceof _pdf.MissingPDFException) {
  560. loadingErrorMessage = _this3.l10n.get('missing_file_error', null, 'Missing PDF file.');
  561. } else if (exception instanceof _pdf.UnexpectedResponseException) {
  562. loadingErrorMessage = _this3.l10n.get('unexpected_response_error', null, 'Unexpected server response.');
  563. } else {
  564. loadingErrorMessage = _this3.l10n.get('loading_error', null, 'An error occurred while loading the PDF.');
  565. }
  566. return loadingErrorMessage.then(function (msg) {
  567. _this3.error(msg, { message: message });
  568. throw new Error(msg);
  569. });
  570. });
  571. },
  572. download: function download() {
  573. var _this4 = this;
  574. function downloadByUrl() {
  575. downloadManager.downloadUrl(url, filename);
  576. }
  577. var url = this.baseUrl;
  578. var filename = this.contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url);
  579. var downloadManager = this.downloadManager;
  580. downloadManager.onerror = function (err) {
  581. _this4.error('PDF failed to download: ' + err);
  582. };
  583. if (!this.pdfDocument || !this.downloadComplete) {
  584. downloadByUrl();
  585. return;
  586. }
  587. this.pdfDocument.getData().then(function (data) {
  588. var blob = (0, _pdf.createBlob)(data, 'application/pdf');
  589. downloadManager.download(blob, url, filename);
  590. }).catch(downloadByUrl);
  591. },
  592. fallback: function fallback(featureId) {},
  593. error: function error(message, moreInfo) {
  594. var moreInfoText = [this.l10n.get('error_version_info', {
  595. version: _pdf.version || '?',
  596. build: _pdf.build || '?'
  597. }, 'PDF.js v{{version}} (build: {{build}})')];
  598. if (moreInfo) {
  599. moreInfoText.push(this.l10n.get('error_message', { message: moreInfo.message }, 'Message: {{message}}'));
  600. if (moreInfo.stack) {
  601. moreInfoText.push(this.l10n.get('error_stack', { stack: moreInfo.stack }, 'Stack: {{stack}}'));
  602. } else {
  603. if (moreInfo.filename) {
  604. moreInfoText.push(this.l10n.get('error_file', { file: moreInfo.filename }, 'File: {{file}}'));
  605. }
  606. if (moreInfo.lineNumber) {
  607. moreInfoText.push(this.l10n.get('error_line', { line: moreInfo.lineNumber }, 'Line: {{line}}'));
  608. }
  609. }
  610. }
  611. var errorWrapperConfig = this.appConfig.errorWrapper;
  612. var errorWrapper = errorWrapperConfig.container;
  613. errorWrapper.removeAttribute('hidden');
  614. var errorMessage = errorWrapperConfig.errorMessage;
  615. errorMessage.textContent = message;
  616. var closeButton = errorWrapperConfig.closeButton;
  617. closeButton.onclick = function () {
  618. errorWrapper.setAttribute('hidden', 'true');
  619. };
  620. var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  621. var moreInfoButton = errorWrapperConfig.moreInfoButton;
  622. var lessInfoButton = errorWrapperConfig.lessInfoButton;
  623. moreInfoButton.onclick = function () {
  624. errorMoreInfo.removeAttribute('hidden');
  625. moreInfoButton.setAttribute('hidden', 'true');
  626. lessInfoButton.removeAttribute('hidden');
  627. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
  628. };
  629. lessInfoButton.onclick = function () {
  630. errorMoreInfo.setAttribute('hidden', 'true');
  631. moreInfoButton.removeAttribute('hidden');
  632. lessInfoButton.setAttribute('hidden', 'true');
  633. };
  634. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  635. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  636. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  637. moreInfoButton.removeAttribute('hidden');
  638. lessInfoButton.setAttribute('hidden', 'true');
  639. Promise.all(moreInfoText).then(function (parts) {
  640. errorMoreInfo.value = parts.join('\n');
  641. });
  642. },
  643. progress: function progress(level) {
  644. var _this5 = this;
  645. if (this.downloadComplete) {
  646. return;
  647. }
  648. var percent = Math.round(level * 100);
  649. if (percent > this.loadingBar.percent || isNaN(percent)) {
  650. this.loadingBar.percent = percent;
  651. if (_pdf.PDFJS.disableAutoFetch && percent) {
  652. if (this.disableAutoFetchLoadingBarTimeout) {
  653. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  654. this.disableAutoFetchLoadingBarTimeout = null;
  655. }
  656. this.loadingBar.show();
  657. this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
  658. _this5.loadingBar.hide();
  659. _this5.disableAutoFetchLoadingBarTimeout = null;
  660. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  661. }
  662. }
  663. },
  664. load: function load(pdfDocument) {
  665. var _this6 = this;
  666. this.pdfDocument = pdfDocument;
  667. pdfDocument.getDownloadInfo().then(function () {
  668. _this6.downloadComplete = true;
  669. _this6.loadingBar.hide();
  670. firstPagePromise.then(function () {
  671. _this6.eventBus.dispatch('documentload', { source: _this6 });
  672. });
  673. });
  674. var pageModePromise = pdfDocument.getPageMode().catch(function () {});
  675. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  676. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  677. var id = this.documentFingerprint = pdfDocument.fingerprint;
  678. var store = this.store = new _view_history.ViewHistory(id);
  679. var baseDocumentUrl = void 0;
  680. baseDocumentUrl = null;
  681. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  682. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  683. var pdfViewer = this.pdfViewer;
  684. pdfViewer.setDocument(pdfDocument);
  685. var firstPagePromise = pdfViewer.firstPagePromise;
  686. var pagesPromise = pdfViewer.pagesPromise;
  687. var onePageRendered = pdfViewer.onePageRendered;
  688. var pdfThumbnailViewer = this.pdfThumbnailViewer;
  689. pdfThumbnailViewer.setDocument(pdfDocument);
  690. firstPagePromise.then(function (pdfPage) {
  691. _this6.loadingBar.setWidth(_this6.appConfig.viewerContainer);
  692. if (!_pdf.PDFJS.disableHistory && !_this6.isViewerEmbedded) {
  693. var resetHistory = !_this6.viewerPrefs['showPreviousViewOnLoad'];
  694. _this6.pdfHistory.initialize(id, resetHistory);
  695. if (_this6.pdfHistory.initialBookmark) {
  696. _this6.initialBookmark = _this6.pdfHistory.initialBookmark;
  697. _this6.initialRotation = _this6.pdfHistory.initialRotation;
  698. }
  699. }
  700. var initialParams = {
  701. bookmark: null,
  702. hash: null
  703. };
  704. var storePromise = store.getMultiple({
  705. exists: false,
  706. page: '1',
  707. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  708. scrollLeft: '0',
  709. scrollTop: '0',
  710. rotation: null,
  711. sidebarView: _pdf_sidebar.SidebarView.NONE
  712. }).catch(function () {});
  713. Promise.all([storePromise, pageModePromise]).then(function (_ref2) {
  714. var _ref3 = _slicedToArray(_ref2, 2),
  715. _ref3$ = _ref3[0],
  716. values = _ref3$ === undefined ? {} : _ref3$,
  717. pageMode = _ref3[1];
  718. var hash = _this6.viewerPrefs['defaultZoomValue'] ? 'zoom=' + _this6.viewerPrefs['defaultZoomValue'] : null;
  719. var rotation = null;
  720. var sidebarView = _this6.viewerPrefs['sidebarViewOnLoad'];
  721. if (values.exists && _this6.viewerPrefs['showPreviousViewOnLoad']) {
  722. hash = 'page=' + values.page + '&zoom=' + (_this6.viewerPrefs['defaultZoomValue'] || values.zoom) + ',' + values.scrollLeft + ',' + values.scrollTop;
  723. rotation = parseInt(values.rotation, 10);
  724. sidebarView = sidebarView || values.sidebarView | 0;
  725. }
  726. if (pageMode && !_this6.viewerPrefs['disablePageMode']) {
  727. sidebarView = sidebarView || apiPageModeToSidebarView(pageMode);
  728. }
  729. return {
  730. hash: hash,
  731. rotation: rotation,
  732. sidebarView: sidebarView
  733. };
  734. }).then(function (_ref4) {
  735. var hash = _ref4.hash,
  736. rotation = _ref4.rotation,
  737. sidebarView = _ref4.sidebarView;
  738. initialParams.bookmark = _this6.initialBookmark;
  739. initialParams.hash = hash;
  740. _this6.setInitialView(hash, {
  741. rotation: rotation,
  742. sidebarView: sidebarView
  743. });
  744. if (!_this6.isViewerEmbedded) {
  745. pdfViewer.focus();
  746. }
  747. return pagesPromise;
  748. }).then(function () {
  749. if (!initialParams.bookmark && !initialParams.hash) {
  750. return;
  751. }
  752. if (pdfViewer.hasEqualPageSizes) {
  753. return;
  754. }
  755. _this6.initialBookmark = initialParams.bookmark;
  756. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  757. _this6.setInitialView(initialParams.hash);
  758. }).then(function () {
  759. pdfViewer.update();
  760. });
  761. });
  762. pdfDocument.getPageLabels().then(function (labels) {
  763. if (!labels || _this6.viewerPrefs['disablePageLabels']) {
  764. return;
  765. }
  766. var i = 0,
  767. numLabels = labels.length;
  768. if (numLabels !== _this6.pagesCount) {
  769. console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
  770. return;
  771. }
  772. while (i < numLabels && labels[i] === (i + 1).toString()) {
  773. i++;
  774. }
  775. if (i === numLabels) {
  776. return;
  777. }
  778. pdfViewer.setPageLabels(labels);
  779. pdfThumbnailViewer.setPageLabels(labels);
  780. _this6.toolbar.setPagesCount(pdfDocument.numPages, true);
  781. _this6.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  782. });
  783. pagesPromise.then(function () {
  784. if (!_this6.supportsPrinting) {
  785. return;
  786. }
  787. pdfDocument.getJavaScript().then(function (javaScript) {
  788. if (!javaScript) {
  789. return;
  790. }
  791. javaScript.some(function (js) {
  792. if (!js) {
  793. return false;
  794. }
  795. console.warn('Warning: JavaScript is not supported');
  796. _this6.fallback(_pdf.UNSUPPORTED_FEATURES.javaScript);
  797. return true;
  798. });
  799. var regex = /\bprint\s*\(/;
  800. for (var i = 0, ii = javaScript.length; i < ii; i++) {
  801. var js = javaScript[i];
  802. if (js && regex.test(js)) {
  803. setTimeout(function () {
  804. window.print();
  805. });
  806. return;
  807. }
  808. }
  809. });
  810. });
  811. Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
  812. pdfDocument.getOutline().then(function (outline) {
  813. _this6.pdfOutlineViewer.render({ outline: outline });
  814. });
  815. pdfDocument.getAttachments().then(function (attachments) {
  816. _this6.pdfAttachmentViewer.render({ attachments: attachments });
  817. });
  818. });
  819. pdfDocument.getMetadata().then(function (_ref5) {
  820. var info = _ref5.info,
  821. metadata = _ref5.metadata,
  822. contentDispositionFilename = _ref5.contentDispositionFilename;
  823. _this6.documentInfo = info;
  824. _this6.metadata = metadata;
  825. _this6.contentDispositionFilename = contentDispositionFilename;
  826. console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (_pdf.version || '-') + (_this6.viewerPrefs['enableWebGL'] ? ' [WebGL]' : '') + ')');
  827. var pdfTitle = void 0;
  828. if (metadata && metadata.has('dc:title')) {
  829. var title = metadata.get('dc:title');
  830. if (title !== 'Untitled') {
  831. pdfTitle = title;
  832. }
  833. }
  834. if (!pdfTitle && info && info['Title']) {
  835. pdfTitle = info['Title'];
  836. }
  837. if (pdfTitle) {
  838. _this6.setTitle(pdfTitle + ' - ' + (contentDispositionFilename || document.title));
  839. } else if (contentDispositionFilename) {
  840. _this6.setTitle(contentDispositionFilename);
  841. }
  842. if (info.IsAcroFormPresent) {
  843. console.warn('Warning: AcroForm/XFA is not supported');
  844. _this6.fallback(_pdf.UNSUPPORTED_FEATURES.forms);
  845. }
  846. });
  847. },
  848. setInitialView: function setInitialView(storedHash) {
  849. var _this7 = this;
  850. var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  851. rotation = _ref6.rotation,
  852. sidebarView = _ref6.sidebarView;
  853. var setRotation = function setRotation(angle) {
  854. if ((0, _ui_utils.isValidRotation)(angle)) {
  855. _this7.pdfViewer.pagesRotation = angle;
  856. }
  857. };
  858. this.isInitialViewSet = true;
  859. this.pdfSidebar.setInitialView(sidebarView);
  860. if (this.initialBookmark) {
  861. setRotation(this.initialRotation);
  862. delete this.initialRotation;
  863. this.pdfLinkService.setHash(this.initialBookmark);
  864. this.initialBookmark = null;
  865. } else if (storedHash) {
  866. setRotation(rotation);
  867. this.pdfLinkService.setHash(storedHash);
  868. }
  869. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  870. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  871. if (!this.pdfViewer.currentScaleValue) {
  872. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  873. }
  874. },
  875. cleanup: function cleanup() {
  876. if (!this.pdfDocument) {
  877. return;
  878. }
  879. this.pdfViewer.cleanup();
  880. this.pdfThumbnailViewer.cleanup();
  881. if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
  882. this.pdfDocument.cleanup();
  883. }
  884. },
  885. forceRendering: function forceRendering() {
  886. this.pdfRenderingQueue.printing = this.printing;
  887. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  888. this.pdfRenderingQueue.renderHighestPriority();
  889. },
  890. beforePrint: function beforePrint() {
  891. var _this8 = this;
  892. if (this.printService) {
  893. return;
  894. }
  895. if (!this.supportsPrinting) {
  896. this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
  897. _this8.error(printMessage);
  898. });
  899. return;
  900. }
  901. if (!this.pdfViewer.pageViewsReady) {
  902. this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
  903. window.alert(notReadyMessage);
  904. });
  905. return;
  906. }
  907. var pagesOverview = this.pdfViewer.getPagesOverview();
  908. var printContainer = this.appConfig.printContainer;
  909. var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
  910. this.printService = printService;
  911. this.forceRendering();
  912. printService.layout();
  913. },
  914. afterPrint: function pdfViewSetupAfterPrint() {
  915. if (this.printService) {
  916. this.printService.destroy();
  917. this.printService = null;
  918. }
  919. this.forceRendering();
  920. },
  921. rotatePages: function rotatePages(delta) {
  922. if (!this.pdfDocument) {
  923. return;
  924. }
  925. var newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
  926. this.pdfViewer.pagesRotation = newRotation;
  927. },
  928. requestPresentationMode: function requestPresentationMode() {
  929. if (!this.pdfPresentationMode) {
  930. return;
  931. }
  932. this.pdfPresentationMode.request();
  933. },
  934. bindEvents: function bindEvents() {
  935. var eventBus = this.eventBus,
  936. _boundEvents = this._boundEvents;
  937. _boundEvents.beforePrint = this.beforePrint.bind(this);
  938. _boundEvents.afterPrint = this.afterPrint.bind(this);
  939. eventBus.on('resize', webViewerResize);
  940. eventBus.on('hashchange', webViewerHashchange);
  941. eventBus.on('beforeprint', _boundEvents.beforePrint);
  942. eventBus.on('afterprint', _boundEvents.afterPrint);
  943. eventBus.on('pagerendered', webViewerPageRendered);
  944. eventBus.on('textlayerrendered', webViewerTextLayerRendered);
  945. eventBus.on('updateviewarea', webViewerUpdateViewarea);
  946. eventBus.on('pagechanging', webViewerPageChanging);
  947. eventBus.on('scalechanging', webViewerScaleChanging);
  948. eventBus.on('rotationchanging', webViewerRotationChanging);
  949. eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
  950. eventBus.on('pagemode', webViewerPageMode);
  951. eventBus.on('namedaction', webViewerNamedAction);
  952. eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
  953. eventBus.on('presentationmode', webViewerPresentationMode);
  954. eventBus.on('openfile', webViewerOpenFile);
  955. eventBus.on('print', webViewerPrint);
  956. eventBus.on('download', webViewerDownload);
  957. eventBus.on('firstpage', webViewerFirstPage);
  958. eventBus.on('lastpage', webViewerLastPage);
  959. eventBus.on('nextpage', webViewerNextPage);
  960. eventBus.on('previouspage', webViewerPreviousPage);
  961. eventBus.on('zoomin', webViewerZoomIn);
  962. eventBus.on('zoomout', webViewerZoomOut);
  963. eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
  964. eventBus.on('scalechanged', webViewerScaleChanged);
  965. eventBus.on('rotatecw', webViewerRotateCw);
  966. eventBus.on('rotateccw', webViewerRotateCcw);
  967. eventBus.on('documentproperties', webViewerDocumentProperties);
  968. eventBus.on('find', webViewerFind);
  969. eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
  970. eventBus.on('fileinputchange', webViewerFileInputChange);
  971. },
  972. bindWindowEvents: function bindWindowEvents() {
  973. var eventBus = this.eventBus,
  974. _boundEvents = this._boundEvents;
  975. _boundEvents.windowResize = function () {
  976. eventBus.dispatch('resize', { source: window });
  977. };
  978. _boundEvents.windowHashChange = function () {
  979. eventBus.dispatch('hashchange', { hash: document.location.hash.substring(1) });
  980. };
  981. _boundEvents.windowBeforePrint = function () {
  982. eventBus.dispatch('beforeprint');
  983. };
  984. _boundEvents.windowAfterPrint = function () {
  985. eventBus.dispatch('afterprint');
  986. };
  987. window.addEventListener('wheel', webViewerWheel);
  988. window.addEventListener('click', webViewerClick);
  989. window.addEventListener('keydown', webViewerKeyDown);
  990. window.addEventListener('resize', _boundEvents.windowResize);
  991. window.addEventListener('hashchange', _boundEvents.windowHashChange);
  992. window.addEventListener('beforeprint', _boundEvents.windowBeforePrint);
  993. window.addEventListener('afterprint', _boundEvents.windowAfterPrint);
  994. },
  995. unbindEvents: function unbindEvents() {
  996. var eventBus = this.eventBus,
  997. _boundEvents = this._boundEvents;
  998. eventBus.off('resize', webViewerResize);
  999. eventBus.off('hashchange', webViewerHashchange);
  1000. eventBus.off('beforeprint', _boundEvents.beforePrint);
  1001. eventBus.off('afterprint', _boundEvents.afterPrint);
  1002. eventBus.off('pagerendered', webViewerPageRendered);
  1003. eventBus.off('textlayerrendered', webViewerTextLayerRendered);
  1004. eventBus.off('updateviewarea', webViewerUpdateViewarea);
  1005. eventBus.off('pagechanging', webViewerPageChanging);
  1006. eventBus.off('scalechanging', webViewerScaleChanging);
  1007. eventBus.off('rotationchanging', webViewerRotationChanging);
  1008. eventBus.off('sidebarviewchanged', webViewerSidebarViewChanged);
  1009. eventBus.off('pagemode', webViewerPageMode);
  1010. eventBus.off('namedaction', webViewerNamedAction);
  1011. eventBus.off('presentationmodechanged', webViewerPresentationModeChanged);
  1012. eventBus.off('presentationmode', webViewerPresentationMode);
  1013. eventBus.off('openfile', webViewerOpenFile);
  1014. eventBus.off('print', webViewerPrint);
  1015. eventBus.off('download', webViewerDownload);
  1016. eventBus.off('firstpage', webViewerFirstPage);
  1017. eventBus.off('lastpage', webViewerLastPage);
  1018. eventBus.off('nextpage', webViewerNextPage);
  1019. eventBus.off('previouspage', webViewerPreviousPage);
  1020. eventBus.off('zoomin', webViewerZoomIn);
  1021. eventBus.off('zoomout', webViewerZoomOut);
  1022. eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
  1023. eventBus.off('scalechanged', webViewerScaleChanged);
  1024. eventBus.off('rotatecw', webViewerRotateCw);
  1025. eventBus.off('rotateccw', webViewerRotateCcw);
  1026. eventBus.off('documentproperties', webViewerDocumentProperties);
  1027. eventBus.off('find', webViewerFind);
  1028. eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
  1029. eventBus.off('fileinputchange', webViewerFileInputChange);
  1030. _boundEvents.beforePrint = null;
  1031. _boundEvents.afterPrint = null;
  1032. },
  1033. unbindWindowEvents: function unbindWindowEvents() {
  1034. var _boundEvents = this._boundEvents;
  1035. window.removeEventListener('wheel', webViewerWheel);
  1036. window.removeEventListener('click', webViewerClick);
  1037. window.removeEventListener('keydown', webViewerKeyDown);
  1038. window.removeEventListener('resize', _boundEvents.windowResize);
  1039. window.removeEventListener('hashchange', _boundEvents.windowHashChange);
  1040. window.removeEventListener('beforeprint', _boundEvents.windowBeforePrint);
  1041. window.removeEventListener('afterprint', _boundEvents.windowAfterPrint);
  1042. _boundEvents.windowResize = null;
  1043. _boundEvents.windowHashChange = null;
  1044. _boundEvents.windowBeforePrint = null;
  1045. _boundEvents.windowAfterPrint = null;
  1046. }
  1047. };
  1048. var validateFileURL = void 0;
  1049. {
  1050. var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
  1051. validateFileURL = function validateFileURL(file) {
  1052. if (file === undefined) {
  1053. return;
  1054. }
  1055. try {
  1056. var viewerOrigin = new URL(window.location.href).origin || 'null';
  1057. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1058. return;
  1059. }
  1060. var fileOrigin = new URL(file, window.location.href).origin;
  1061. if (fileOrigin !== viewerOrigin) {
  1062. throw new Error('file origin does not match viewer\'s');
  1063. }
  1064. } catch (ex) {
  1065. var message = ex && ex.message;
  1066. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
  1067. PDFViewerApplication.error(loadingErrorMessage, { message: message });
  1068. });
  1069. throw ex;
  1070. }
  1071. };
  1072. }
  1073. function loadFakeWorker() {
  1074. return new Promise(function (resolve, reject) {
  1075. var script = document.createElement('script');
  1076. script.src = _pdf.PDFWorker.getWorkerSrc();
  1077. script.onload = function () {
  1078. resolve();
  1079. };
  1080. script.onerror = function () {
  1081. reject(new Error('Cannot load fake worker at: ' + script.src));
  1082. };
  1083. (document.head || document.documentElement).appendChild(script);
  1084. });
  1085. }
  1086. function loadAndEnablePDFBug(enabledTabs) {
  1087. return new Promise(function (resolve, reject) {
  1088. var appConfig = PDFViewerApplication.appConfig;
  1089. var script = document.createElement('script');
  1090. script.src = appConfig.debuggerScriptPath;
  1091. script.onload = function () {
  1092. PDFBug.enable(enabledTabs);
  1093. PDFBug.init({ OPS: _pdf.OPS }, appConfig.mainContainer);
  1094. resolve();
  1095. };
  1096. script.onerror = function () {
  1097. reject(new Error('Cannot load debugger at ' + script.src));
  1098. };
  1099. (document.getElementsByTagName('head')[0] || document.body).appendChild(script);
  1100. });
  1101. }
  1102. function webViewerInitialized() {
  1103. var appConfig = PDFViewerApplication.appConfig;
  1104. var file = void 0;
  1105. var queryString = document.location.search.substring(1);
  1106. var params = (0, _ui_utils.parseQueryString)(queryString);
  1107. file = 'file' in params ? params.file : appConfig.defaultUrl;
  1108. validateFileURL(file);
  1109. var fileInput = document.createElement('input');
  1110. fileInput.id = appConfig.openFileInputName;
  1111. fileInput.className = 'fileInput';
  1112. fileInput.setAttribute('type', 'file');
  1113. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1114. document.body.appendChild(fileInput);
  1115. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1116. appConfig.toolbar.openFile.setAttribute('hidden', 'true');
  1117. appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
  1118. } else {
  1119. fileInput.value = null;
  1120. }
  1121. fileInput.addEventListener('change', function (evt) {
  1122. var files = evt.target.files;
  1123. if (!files || files.length === 0) {
  1124. return;
  1125. }
  1126. PDFViewerApplication.eventBus.dispatch('fileinputchange', { fileInput: evt.target });
  1127. });
  1128. if (!PDFViewerApplication.supportsPrinting) {
  1129. appConfig.toolbar.print.classList.add('hidden');
  1130. appConfig.secondaryToolbar.printButton.classList.add('hidden');
  1131. }
  1132. if (!PDFViewerApplication.supportsFullscreen) {
  1133. appConfig.toolbar.presentationModeButton.classList.add('hidden');
  1134. appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
  1135. }
  1136. if (PDFViewerApplication.supportsIntegratedFind) {
  1137. appConfig.toolbar.viewFind.classList.add('hidden');
  1138. }
  1139. appConfig.mainContainer.addEventListener('transitionend', function (evt) {
  1140. if (evt.target === this) {
  1141. PDFViewerApplication.eventBus.dispatch('resize', { source: this });
  1142. }
  1143. }, true);
  1144. appConfig.sidebar.toggleButton.addEventListener('click', function () {
  1145. PDFViewerApplication.pdfSidebar.toggle();
  1146. });
  1147. Promise.resolve().then(function () {
  1148. webViewerOpenFileViaURL(file);
  1149. }).catch(function (reason) {
  1150. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
  1151. PDFViewerApplication.error(msg, reason);
  1152. });
  1153. });
  1154. }
  1155. var webViewerOpenFileViaURL = void 0;
  1156. {
  1157. webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
  1158. if (file && file.lastIndexOf('file:', 0) === 0) {
  1159. PDFViewerApplication.setTitleUsingUrl(file);
  1160. var xhr = new XMLHttpRequest();
  1161. xhr.onload = function () {
  1162. PDFViewerApplication.open(new Uint8Array(xhr.response));
  1163. };
  1164. try {
  1165. xhr.open('GET', file);
  1166. xhr.responseType = 'arraybuffer';
  1167. xhr.send();
  1168. } catch (ex) {
  1169. throw ex;
  1170. }
  1171. return;
  1172. }
  1173. if (file) {
  1174. PDFViewerApplication.open(file);
  1175. }
  1176. };
  1177. }
  1178. function webViewerPageRendered(evt) {
  1179. var pageNumber = evt.pageNumber;
  1180. var pageIndex = pageNumber - 1;
  1181. var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  1182. if (pageNumber === PDFViewerApplication.page) {
  1183. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1184. }
  1185. if (!pageView) {
  1186. return;
  1187. }
  1188. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1189. var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  1190. thumbnailView.setImage(pageView);
  1191. }
  1192. if (typeof Stats !== 'undefined' && Stats.enabled && pageView.stats) {
  1193. Stats.add(pageNumber, pageView.stats);
  1194. }
  1195. if (pageView.error) {
  1196. PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
  1197. PDFViewerApplication.error(msg, pageView.error);
  1198. });
  1199. }
  1200. }
  1201. function webViewerTextLayerRendered(evt) {}
  1202. function webViewerPageMode(evt) {
  1203. var mode = evt.mode,
  1204. view = void 0;
  1205. switch (mode) {
  1206. case 'thumbs':
  1207. view = _pdf_sidebar.SidebarView.THUMBS;
  1208. break;
  1209. case 'bookmarks':
  1210. case 'outline':
  1211. view = _pdf_sidebar.SidebarView.OUTLINE;
  1212. break;
  1213. case 'attachments':
  1214. view = _pdf_sidebar.SidebarView.ATTACHMENTS;
  1215. break;
  1216. case 'none':
  1217. view = _pdf_sidebar.SidebarView.NONE;
  1218. break;
  1219. default:
  1220. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1221. return;
  1222. }
  1223. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1224. }
  1225. function webViewerNamedAction(evt) {
  1226. var action = evt.action;
  1227. switch (action) {
  1228. case 'GoToPage':
  1229. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1230. break;
  1231. case 'Find':
  1232. if (!PDFViewerApplication.supportsIntegratedFind) {
  1233. PDFViewerApplication.findBar.toggle();
  1234. }
  1235. break;
  1236. }
  1237. }
  1238. function webViewerPresentationModeChanged(evt) {
  1239. var active = evt.active,
  1240. switchInProgress = evt.switchInProgress;
  1241. PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _ui_utils.PresentationModeState.CHANGING : active ? _ui_utils.PresentationModeState.FULLSCREEN : _ui_utils.PresentationModeState.NORMAL;
  1242. }
  1243. function webViewerSidebarViewChanged(evt) {
  1244. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1245. var store = PDFViewerApplication.store;
  1246. if (store && PDFViewerApplication.isInitialViewSet) {
  1247. store.set('sidebarView', evt.view).catch(function () {});
  1248. }
  1249. }
  1250. function webViewerUpdateViewarea(evt) {
  1251. var location = evt.location,
  1252. store = PDFViewerApplication.store;
  1253. if (store && PDFViewerApplication.isInitialViewSet) {
  1254. store.setMultiple({
  1255. 'exists': true,
  1256. 'page': location.pageNumber,
  1257. 'zoom': location.scale,
  1258. 'scrollLeft': location.left,
  1259. 'scrollTop': location.top,
  1260. 'rotation': location.rotation
  1261. }).catch(function () {});
  1262. }
  1263. var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1264. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1265. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1266. var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1267. var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1268. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1269. }
  1270. function webViewerResize() {
  1271. var pdfDocument = PDFViewerApplication.pdfDocument,
  1272. pdfViewer = PDFViewerApplication.pdfViewer;
  1273. if (!pdfDocument) {
  1274. return;
  1275. }
  1276. var currentScaleValue = pdfViewer.currentScaleValue;
  1277. if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
  1278. pdfViewer.currentScaleValue = currentScaleValue;
  1279. }
  1280. pdfViewer.update();
  1281. }
  1282. function webViewerHashchange(evt) {
  1283. var hash = evt.hash;
  1284. if (!hash) {
  1285. return;
  1286. }
  1287. if (!PDFViewerApplication.isInitialViewSet) {
  1288. PDFViewerApplication.initialBookmark = hash;
  1289. } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  1290. PDFViewerApplication.pdfLinkService.setHash(hash);
  1291. }
  1292. }
  1293. var webViewerFileInputChange = void 0;
  1294. {
  1295. webViewerFileInputChange = function webViewerFileInputChange(evt) {
  1296. var file = evt.fileInput.files[0];
  1297. if (!_pdf.PDFJS.disableCreateObjectURL && URL.createObjectURL) {
  1298. PDFViewerApplication.open(URL.createObjectURL(file));
  1299. } else {
  1300. var fileReader = new FileReader();
  1301. fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
  1302. var buffer = evt.target.result;
  1303. PDFViewerApplication.open(new Uint8Array(buffer));
  1304. };
  1305. fileReader.readAsArrayBuffer(file);
  1306. }
  1307. PDFViewerApplication.setTitleUsingUrl(file.name);
  1308. var appConfig = PDFViewerApplication.appConfig;
  1309. appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
  1310. appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
  1311. appConfig.toolbar.download.setAttribute('hidden', 'true');
  1312. appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
  1313. };
  1314. }
  1315. function webViewerPresentationMode() {
  1316. PDFViewerApplication.requestPresentationMode();
  1317. }
  1318. function webViewerOpenFile() {
  1319. var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  1320. document.getElementById(openFileInputName).click();
  1321. }
  1322. function webViewerPrint() {
  1323. window.print();
  1324. }
  1325. function webViewerDownload() {
  1326. PDFViewerApplication.download();
  1327. }
  1328. function webViewerFirstPage() {
  1329. if (PDFViewerApplication.pdfDocument) {
  1330. PDFViewerApplication.page = 1;
  1331. }
  1332. }
  1333. function webViewerLastPage() {
  1334. if (PDFViewerApplication.pdfDocument) {
  1335. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1336. }
  1337. }
  1338. function webViewerNextPage() {
  1339. PDFViewerApplication.page++;
  1340. }
  1341. function webViewerPreviousPage() {
  1342. PDFViewerApplication.page--;
  1343. }
  1344. function webViewerZoomIn() {
  1345. PDFViewerApplication.zoomIn();
  1346. }
  1347. function webViewerZoomOut() {
  1348. PDFViewerApplication.zoomOut();
  1349. }
  1350. function webViewerPageNumberChanged(evt) {
  1351. var pdfViewer = PDFViewerApplication.pdfViewer;
  1352. pdfViewer.currentPageLabel = evt.value;
  1353. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1354. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1355. }
  1356. }
  1357. function webViewerScaleChanged(evt) {
  1358. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1359. }
  1360. function webViewerRotateCw() {
  1361. PDFViewerApplication.rotatePages(90);
  1362. }
  1363. function webViewerRotateCcw() {
  1364. PDFViewerApplication.rotatePages(-90);
  1365. }
  1366. function webViewerDocumentProperties() {
  1367. PDFViewerApplication.pdfDocumentProperties.open();
  1368. }
  1369. function webViewerFind(evt) {
  1370. PDFViewerApplication.findController.executeCommand('find' + evt.type, {
  1371. query: evt.query,
  1372. phraseSearch: evt.phraseSearch,
  1373. caseSensitive: evt.caseSensitive,
  1374. highlightAll: evt.highlightAll,
  1375. findPrevious: evt.findPrevious
  1376. });
  1377. }
  1378. function webViewerFindFromUrlHash(evt) {
  1379. PDFViewerApplication.findController.executeCommand('find', {
  1380. query: evt.query,
  1381. phraseSearch: evt.phraseSearch,
  1382. caseSensitive: false,
  1383. highlightAll: true,
  1384. findPrevious: false
  1385. });
  1386. }
  1387. function webViewerScaleChanging(evt) {
  1388. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  1389. PDFViewerApplication.pdfViewer.update();
  1390. }
  1391. function webViewerRotationChanging(evt) {
  1392. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  1393. PDFViewerApplication.forceRendering();
  1394. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  1395. }
  1396. function webViewerPageChanging(evt) {
  1397. var page = evt.pageNumber;
  1398. PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
  1399. PDFViewerApplication.secondaryToolbar.setPageNumber(page);
  1400. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1401. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
  1402. }
  1403. if (typeof Stats !== 'undefined' && Stats.enabled) {
  1404. var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
  1405. if (pageView && pageView.stats) {
  1406. Stats.add(page, pageView.stats);
  1407. }
  1408. }
  1409. }
  1410. var zoomDisabled = false,
  1411. zoomDisabledTimeout = void 0;
  1412. function webViewerWheel(evt) {
  1413. var pdfViewer = PDFViewerApplication.pdfViewer;
  1414. if (pdfViewer.isInPresentationMode) {
  1415. return;
  1416. }
  1417. if (evt.ctrlKey || evt.metaKey) {
  1418. var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
  1419. if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
  1420. return;
  1421. }
  1422. evt.preventDefault();
  1423. if (zoomDisabled) {
  1424. return;
  1425. }
  1426. var previousScale = pdfViewer.currentScale;
  1427. var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  1428. var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
  1429. var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
  1430. if (ticks < 0) {
  1431. PDFViewerApplication.zoomOut(-ticks);
  1432. } else {
  1433. PDFViewerApplication.zoomIn(ticks);
  1434. }
  1435. var currentScale = pdfViewer.currentScale;
  1436. if (previousScale !== currentScale) {
  1437. var scaleCorrectionFactor = currentScale / previousScale - 1;
  1438. var rect = pdfViewer.container.getBoundingClientRect();
  1439. var dx = evt.clientX - rect.left;
  1440. var dy = evt.clientY - rect.top;
  1441. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  1442. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  1443. }
  1444. } else {
  1445. zoomDisabled = true;
  1446. clearTimeout(zoomDisabledTimeout);
  1447. zoomDisabledTimeout = setTimeout(function () {
  1448. zoomDisabled = false;
  1449. }, 1000);
  1450. }
  1451. }
  1452. function webViewerClick(evt) {
  1453. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  1454. return;
  1455. }
  1456. var appConfig = PDFViewerApplication.appConfig;
  1457. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  1458. PDFViewerApplication.secondaryToolbar.close();
  1459. }
  1460. }
  1461. function webViewerKeyDown(evt) {
  1462. if (PDFViewerApplication.overlayManager.active) {
  1463. return;
  1464. }
  1465. var handled = false,
  1466. ensureViewerFocused = false;
  1467. var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  1468. var pdfViewer = PDFViewerApplication.pdfViewer;
  1469. var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
  1470. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  1471. switch (evt.keyCode) {
  1472. case 70:
  1473. if (!PDFViewerApplication.supportsIntegratedFind) {
  1474. PDFViewerApplication.findBar.open();
  1475. handled = true;
  1476. }
  1477. break;
  1478. case 71:
  1479. if (!PDFViewerApplication.supportsIntegratedFind) {
  1480. var findState = PDFViewerApplication.findController.state;
  1481. if (findState) {
  1482. PDFViewerApplication.findController.executeCommand('findagain', {
  1483. query: findState.query,
  1484. phraseSearch: findState.phraseSearch,
  1485. caseSensitive: findState.caseSensitive,
  1486. highlightAll: findState.highlightAll,
  1487. findPrevious: cmd === 5 || cmd === 12
  1488. });
  1489. }
  1490. handled = true;
  1491. }
  1492. break;
  1493. case 61:
  1494. case 107:
  1495. case 187:
  1496. case 171:
  1497. if (!isViewerInPresentationMode) {
  1498. PDFViewerApplication.zoomIn();
  1499. }
  1500. handled = true;
  1501. break;
  1502. case 173:
  1503. case 109:
  1504. case 189:
  1505. if (!isViewerInPresentationMode) {
  1506. PDFViewerApplication.zoomOut();
  1507. }
  1508. handled = true;
  1509. break;
  1510. case 48:
  1511. case 96:
  1512. if (!isViewerInPresentationMode) {
  1513. setTimeout(function () {
  1514. pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1515. });
  1516. handled = false;
  1517. }
  1518. break;
  1519. case 38:
  1520. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1521. PDFViewerApplication.page = 1;
  1522. handled = true;
  1523. ensureViewerFocused = true;
  1524. }
  1525. break;
  1526. case 40:
  1527. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1528. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1529. handled = true;
  1530. ensureViewerFocused = true;
  1531. }
  1532. break;
  1533. }
  1534. }
  1535. if (cmd === 1 || cmd === 8) {
  1536. switch (evt.keyCode) {
  1537. case 83:
  1538. PDFViewerApplication.download();
  1539. handled = true;
  1540. break;
  1541. }
  1542. }
  1543. if (cmd === 3 || cmd === 10) {
  1544. switch (evt.keyCode) {
  1545. case 80:
  1546. PDFViewerApplication.requestPresentationMode();
  1547. handled = true;
  1548. break;
  1549. case 71:
  1550. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1551. handled = true;
  1552. break;
  1553. }
  1554. }
  1555. if (handled) {
  1556. if (ensureViewerFocused && !isViewerInPresentationMode) {
  1557. pdfViewer.focus();
  1558. }
  1559. evt.preventDefault();
  1560. return;
  1561. }
  1562. var curElement = document.activeElement || document.querySelector(':focus');
  1563. var curElementTagName = curElement && curElement.tagName.toUpperCase();
  1564. if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
  1565. if (evt.keyCode !== 27) {
  1566. return;
  1567. }
  1568. }
  1569. if (cmd === 0) {
  1570. switch (evt.keyCode) {
  1571. case 38:
  1572. case 33:
  1573. case 8:
  1574. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1575. break;
  1576. }
  1577. case 37:
  1578. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1579. break;
  1580. }
  1581. case 75:
  1582. case 80:
  1583. if (PDFViewerApplication.page > 1) {
  1584. PDFViewerApplication.page--;
  1585. }
  1586. handled = true;
  1587. break;
  1588. case 27:
  1589. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  1590. PDFViewerApplication.secondaryToolbar.close();
  1591. handled = true;
  1592. }
  1593. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  1594. PDFViewerApplication.findBar.close();
  1595. handled = true;
  1596. }
  1597. break;
  1598. case 13:
  1599. case 40:
  1600. case 34:
  1601. case 32:
  1602. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1603. break;
  1604. }
  1605. case 39:
  1606. if (pdfViewer.isHorizontalScrollbarEnabled) {
  1607. break;
  1608. }
  1609. case 74:
  1610. case 78:
  1611. if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1612. PDFViewerApplication.page++;
  1613. }
  1614. handled = true;
  1615. break;
  1616. case 36:
  1617. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  1618. PDFViewerApplication.page = 1;
  1619. handled = true;
  1620. ensureViewerFocused = true;
  1621. }
  1622. break;
  1623. case 35:
  1624. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  1625. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1626. handled = true;
  1627. ensureViewerFocused = true;
  1628. }
  1629. break;
  1630. case 83:
  1631. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  1632. break;
  1633. case 72:
  1634. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  1635. break;
  1636. case 82:
  1637. PDFViewerApplication.rotatePages(90);
  1638. break;
  1639. }
  1640. }
  1641. if (cmd === 4) {
  1642. switch (evt.keyCode) {
  1643. case 13:
  1644. case 32:
  1645. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  1646. break;
  1647. }
  1648. if (PDFViewerApplication.page > 1) {
  1649. PDFViewerApplication.page--;
  1650. }
  1651. handled = true;
  1652. break;
  1653. case 82:
  1654. PDFViewerApplication.rotatePages(-90);
  1655. break;
  1656. }
  1657. }
  1658. if (!handled && !isViewerInPresentationMode) {
  1659. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
  1660. ensureViewerFocused = true;
  1661. }
  1662. }
  1663. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  1664. pdfViewer.focus();
  1665. }
  1666. if (handled) {
  1667. evt.preventDefault();
  1668. }
  1669. }
  1670. function apiPageModeToSidebarView(mode) {
  1671. switch (mode) {
  1672. case 'UseNone':
  1673. return _pdf_sidebar.SidebarView.NONE;
  1674. case 'UseThumbs':
  1675. return _pdf_sidebar.SidebarView.THUMBS;
  1676. case 'UseOutlines':
  1677. return _pdf_sidebar.SidebarView.OUTLINE;
  1678. case 'UseAttachments':
  1679. return _pdf_sidebar.SidebarView.ATTACHMENTS;
  1680. case 'UseOC':
  1681. }
  1682. return _pdf_sidebar.SidebarView.NONE;
  1683. }
  1684. var PDFPrintServiceFactory = {
  1685. instance: {
  1686. supportsPrinting: false,
  1687. createPrintService: function createPrintService() {
  1688. throw new Error('Not implemented: createPrintService');
  1689. }
  1690. }
  1691. };
  1692. exports.PDFViewerApplication = PDFViewerApplication;
  1693. exports.DefaultExternalServices = DefaultExternalServices;
  1694. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;