app.js 62 KB

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