2
0

app.js 65 KB

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