app.js 65 KB

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