app.js 76 KB

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