本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15559 lines
459KB

  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. /******/ (function(modules) { // webpackBootstrap
  23. /******/ // The module cache
  24. /******/ var installedModules = {};
  25. /******/
  26. /******/ // The require function
  27. /******/ function __webpack_require__(moduleId) {
  28. /******/
  29. /******/ // Check if module is in cache
  30. /******/ if(installedModules[moduleId]) {
  31. /******/ return installedModules[moduleId].exports;
  32. /******/ }
  33. /******/ // Create a new module (and put it into the cache)
  34. /******/ var module = installedModules[moduleId] = {
  35. /******/ i: moduleId,
  36. /******/ l: false,
  37. /******/ exports: {}
  38. /******/ };
  39. /******/
  40. /******/ // Execute the module function
  41. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  42. /******/
  43. /******/ // Flag the module as loaded
  44. /******/ module.l = true;
  45. /******/
  46. /******/ // Return the exports of the module
  47. /******/ return module.exports;
  48. /******/ }
  49. /******/
  50. /******/
  51. /******/ // expose the modules object (__webpack_modules__)
  52. /******/ __webpack_require__.m = modules;
  53. /******/
  54. /******/ // expose the module cache
  55. /******/ __webpack_require__.c = installedModules;
  56. /******/
  57. /******/ // define getter function for harmony exports
  58. /******/ __webpack_require__.d = function(exports, name, getter) {
  59. /******/ if(!__webpack_require__.o(exports, name)) {
  60. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  61. /******/ }
  62. /******/ };
  63. /******/
  64. /******/ // define __esModule on exports
  65. /******/ __webpack_require__.r = function(exports) {
  66. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  67. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  68. /******/ }
  69. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  70. /******/ };
  71. /******/
  72. /******/ // create a fake namespace object
  73. /******/ // mode & 1: value is a module id, require it
  74. /******/ // mode & 2: merge all properties of value into the ns
  75. /******/ // mode & 4: return value when already ns object
  76. /******/ // mode & 8|1: behave like require
  77. /******/ __webpack_require__.t = function(value, mode) {
  78. /******/ if(mode & 1) value = __webpack_require__(value);
  79. /******/ if(mode & 8) return value;
  80. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  81. /******/ var ns = Object.create(null);
  82. /******/ __webpack_require__.r(ns);
  83. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  84. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  85. /******/ return ns;
  86. /******/ };
  87. /******/
  88. /******/ // getDefaultExport function for compatibility with non-harmony modules
  89. /******/ __webpack_require__.n = function(module) {
  90. /******/ var getter = module && module.__esModule ?
  91. /******/ function getDefault() { return module['default']; } :
  92. /******/ function getModuleExports() { return module; };
  93. /******/ __webpack_require__.d(getter, 'a', getter);
  94. /******/ return getter;
  95. /******/ };
  96. /******/
  97. /******/ // Object.prototype.hasOwnProperty.call
  98. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  99. /******/
  100. /******/ // __webpack_public_path__
  101. /******/ __webpack_require__.p = "";
  102. /******/
  103. /******/
  104. /******/ // Load entry module and return exports
  105. /******/ return __webpack_require__(__webpack_require__.s = 0);
  106. /******/ })
  107. /************************************************************************/
  108. /******/ ([
  109. /* 0 */
  110. /***/ (function(module, exports, __webpack_require__) {
  111. "use strict";
  112. ;
  113. var pdfjsWebApp, pdfjsWebAppOptions;
  114. {
  115. pdfjsWebApp = __webpack_require__(1);
  116. pdfjsWebAppOptions = __webpack_require__(12);
  117. }
  118. ;
  119. {
  120. __webpack_require__(37);
  121. }
  122. ;
  123. {
  124. __webpack_require__(42);
  125. }
  126. function getViewerConfiguration() {
  127. return {
  128. appContainer: document.body,
  129. mainContainer: document.getElementById('viewerContainer'),
  130. viewerContainer: document.getElementById('viewer'),
  131. eventBus: null,
  132. toolbar: {
  133. container: document.getElementById('toolbarViewer'),
  134. numPages: document.getElementById('numPages'),
  135. pageNumber: document.getElementById('pageNumber'),
  136. scaleSelectContainer: document.getElementById('scaleSelectContainer'),
  137. scaleSelect: document.getElementById('scaleSelect'),
  138. customScaleOption: document.getElementById('customScaleOption'),
  139. previous: document.getElementById('previous'),
  140. next: document.getElementById('next'),
  141. zoomIn: document.getElementById('zoomIn'),
  142. zoomOut: document.getElementById('zoomOut'),
  143. viewFind: document.getElementById('viewFind'),
  144. openFile: document.getElementById('openFile'),
  145. print: document.getElementById('print'),
  146. presentationModeButton: document.getElementById('presentationMode'),
  147. download: document.getElementById('download'),
  148. viewBookmark: document.getElementById('viewBookmark')
  149. },
  150. secondaryToolbar: {
  151. toolbar: document.getElementById('secondaryToolbar'),
  152. toggleButton: document.getElementById('secondaryToolbarToggle'),
  153. toolbarButtonContainer: document.getElementById('secondaryToolbarButtonContainer'),
  154. presentationModeButton: document.getElementById('secondaryPresentationMode'),
  155. openFileButton: document.getElementById('secondaryOpenFile'),
  156. printButton: document.getElementById('secondaryPrint'),
  157. downloadButton: document.getElementById('secondaryDownload'),
  158. viewBookmarkButton: document.getElementById('secondaryViewBookmark'),
  159. firstPageButton: document.getElementById('firstPage'),
  160. lastPageButton: document.getElementById('lastPage'),
  161. pageRotateCwButton: document.getElementById('pageRotateCw'),
  162. pageRotateCcwButton: document.getElementById('pageRotateCcw'),
  163. cursorSelectToolButton: document.getElementById('cursorSelectTool'),
  164. cursorHandToolButton: document.getElementById('cursorHandTool'),
  165. scrollVerticalButton: document.getElementById('scrollVertical'),
  166. scrollHorizontalButton: document.getElementById('scrollHorizontal'),
  167. scrollWrappedButton: document.getElementById('scrollWrapped'),
  168. spreadNoneButton: document.getElementById('spreadNone'),
  169. spreadOddButton: document.getElementById('spreadOdd'),
  170. spreadEvenButton: document.getElementById('spreadEven'),
  171. documentPropertiesButton: document.getElementById('documentProperties')
  172. },
  173. fullscreen: {
  174. contextFirstPage: document.getElementById('contextFirstPage'),
  175. contextLastPage: document.getElementById('contextLastPage'),
  176. contextPageRotateCw: document.getElementById('contextPageRotateCw'),
  177. contextPageRotateCcw: document.getElementById('contextPageRotateCcw')
  178. },
  179. sidebar: {
  180. outerContainer: document.getElementById('outerContainer'),
  181. viewerContainer: document.getElementById('viewerContainer'),
  182. toggleButton: document.getElementById('sidebarToggle'),
  183. thumbnailButton: document.getElementById('viewThumbnail'),
  184. outlineButton: document.getElementById('viewOutline'),
  185. attachmentsButton: document.getElementById('viewAttachments'),
  186. thumbnailView: document.getElementById('thumbnailView'),
  187. outlineView: document.getElementById('outlineView'),
  188. attachmentsView: document.getElementById('attachmentsView')
  189. },
  190. sidebarResizer: {
  191. outerContainer: document.getElementById('outerContainer'),
  192. resizer: document.getElementById('sidebarResizer')
  193. },
  194. findBar: {
  195. bar: document.getElementById('findbar'),
  196. toggleButton: document.getElementById('viewFind'),
  197. findField: document.getElementById('findInput'),
  198. highlightAllCheckbox: document.getElementById('findHighlightAll'),
  199. caseSensitiveCheckbox: document.getElementById('findMatchCase'),
  200. entireWordCheckbox: document.getElementById('findEntireWord'),
  201. findMsg: document.getElementById('findMsg'),
  202. findResultsCount: document.getElementById('findResultsCount'),
  203. findPreviousButton: document.getElementById('findPrevious'),
  204. findNextButton: document.getElementById('findNext')
  205. },
  206. passwordOverlay: {
  207. overlayName: 'passwordOverlay',
  208. container: document.getElementById('passwordOverlay'),
  209. label: document.getElementById('passwordText'),
  210. input: document.getElementById('password'),
  211. submitButton: document.getElementById('passwordSubmit'),
  212. cancelButton: document.getElementById('passwordCancel')
  213. },
  214. documentProperties: {
  215. overlayName: 'documentPropertiesOverlay',
  216. container: document.getElementById('documentPropertiesOverlay'),
  217. closeButton: document.getElementById('documentPropertiesClose'),
  218. fields: {
  219. 'fileName': document.getElementById('fileNameField'),
  220. 'fileSize': document.getElementById('fileSizeField'),
  221. 'title': document.getElementById('titleField'),
  222. 'author': document.getElementById('authorField'),
  223. 'subject': document.getElementById('subjectField'),
  224. 'keywords': document.getElementById('keywordsField'),
  225. 'creationDate': document.getElementById('creationDateField'),
  226. 'modificationDate': document.getElementById('modificationDateField'),
  227. 'creator': document.getElementById('creatorField'),
  228. 'producer': document.getElementById('producerField'),
  229. 'version': document.getElementById('versionField'),
  230. 'pageCount': document.getElementById('pageCountField'),
  231. 'pageSize': document.getElementById('pageSizeField'),
  232. 'linearized': document.getElementById('linearizedField')
  233. }
  234. },
  235. errorWrapper: {
  236. container: document.getElementById('errorWrapper'),
  237. errorMessage: document.getElementById('errorMessage'),
  238. closeButton: document.getElementById('errorClose'),
  239. errorMoreInfo: document.getElementById('errorMoreInfo'),
  240. moreInfoButton: document.getElementById('errorShowMore'),
  241. lessInfoButton: document.getElementById('errorShowLess')
  242. },
  243. printContainer: document.getElementById('printContainer'),
  244. openFileInputName: 'fileInput',
  245. debuggerScriptPath: './debugger.js'
  246. };
  247. }
  248. function webViewerLoad() {
  249. var config = getViewerConfiguration();
  250. window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;
  251. window.PDFViewerApplicationOptions = pdfjsWebAppOptions.AppOptions;
  252. var event = document.createEvent('CustomEvent');
  253. event.initCustomEvent('webviewerloaded', true, true, {});
  254. document.dispatchEvent(event);
  255. pdfjsWebApp.PDFViewerApplication.run(config);
  256. }
  257. if (document.readyState === 'interactive' || document.readyState === 'complete') {
  258. webViewerLoad();
  259. } else {
  260. document.addEventListener('DOMContentLoaded', webViewerLoad, true);
  261. }
  262. /***/ }),
  263. /* 1 */
  264. /***/ (function(module, exports, __webpack_require__) {
  265. "use strict";
  266. Object.defineProperty(exports, "__esModule", {
  267. value: true
  268. });
  269. exports.PDFPrintServiceFactory = exports.DefaultExternalServices = exports.PDFViewerApplication = void 0;
  270. var _regenerator = _interopRequireDefault(__webpack_require__(2));
  271. var _ui_utils = __webpack_require__(6);
  272. var _pdfjsLib = __webpack_require__(7);
  273. var _pdf_cursor_tools = __webpack_require__(8);
  274. var _pdf_rendering_queue = __webpack_require__(10);
  275. var _pdf_sidebar = __webpack_require__(11);
  276. var _app_options = __webpack_require__(12);
  277. var _overlay_manager = __webpack_require__(14);
  278. var _password_prompt = __webpack_require__(15);
  279. var _pdf_attachment_viewer = __webpack_require__(16);
  280. var _pdf_document_properties = __webpack_require__(17);
  281. var _pdf_find_bar = __webpack_require__(18);
  282. var _pdf_find_controller = __webpack_require__(19);
  283. var _pdf_history = __webpack_require__(21);
  284. var _pdf_link_service = __webpack_require__(22);
  285. var _pdf_outline_viewer = __webpack_require__(23);
  286. var _pdf_presentation_mode = __webpack_require__(24);
  287. var _pdf_sidebar_resizer = __webpack_require__(25);
  288. var _pdf_thumbnail_viewer = __webpack_require__(26);
  289. var _pdf_viewer = __webpack_require__(28);
  290. var _secondary_toolbar = __webpack_require__(33);
  291. var _toolbar = __webpack_require__(35);
  292. var _view_history = __webpack_require__(36);
  293. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  294. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
  295. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
  296. 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; }
  297. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  298. 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); } }
  299. 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); }); }; }
  300. var DEFAULT_SCALE_DELTA = 1.1;
  301. var DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000;
  302. var FORCE_PAGES_LOADED_TIMEOUT = 10000;
  303. var WHEEL_ZOOM_DISABLED_TIMEOUT = 1000;
  304. var ViewOnLoad = {
  305. UNKNOWN: -1,
  306. PREVIOUS: 0,
  307. INITIAL: 1
  308. };
  309. var DefaultExternalServices = {
  310. updateFindControlState: function updateFindControlState(data) {},
  311. updateFindMatchesCount: function updateFindMatchesCount(data) {},
  312. initPassiveLoading: function initPassiveLoading(callbacks) {},
  313. fallback: function fallback(data, callback) {},
  314. reportTelemetry: function reportTelemetry(data) {},
  315. createDownloadManager: function createDownloadManager(options) {
  316. throw new Error('Not implemented: createDownloadManager');
  317. },
  318. createPreferences: function createPreferences() {
  319. throw new Error('Not implemented: createPreferences');
  320. },
  321. createL10n: function createL10n(options) {
  322. throw new Error('Not implemented: createL10n');
  323. },
  324. supportsIntegratedFind: false,
  325. supportsDocumentFonts: true,
  326. supportsDocumentColors: true,
  327. supportedMouseWheelZoomModifierKeys: {
  328. ctrlKey: true,
  329. metaKey: true
  330. }
  331. };
  332. exports.DefaultExternalServices = DefaultExternalServices;
  333. var PDFViewerApplication = {
  334. initialBookmark: document.location.hash.substring(1),
  335. initialized: false,
  336. fellback: false,
  337. appConfig: null,
  338. pdfDocument: null,
  339. pdfLoadingTask: null,
  340. printService: null,
  341. pdfViewer: null,
  342. pdfThumbnailViewer: null,
  343. pdfRenderingQueue: null,
  344. pdfPresentationMode: null,
  345. pdfDocumentProperties: null,
  346. pdfLinkService: null,
  347. pdfHistory: null,
  348. pdfSidebar: null,
  349. pdfSidebarResizer: null,
  350. pdfOutlineViewer: null,
  351. pdfAttachmentViewer: null,
  352. pdfCursorTools: null,
  353. store: null,
  354. downloadManager: null,
  355. overlayManager: null,
  356. preferences: null,
  357. toolbar: null,
  358. secondaryToolbar: null,
  359. eventBus: null,
  360. l10n: null,
  361. isInitialViewSet: false,
  362. downloadComplete: false,
  363. isViewerEmbedded: window.parent !== window,
  364. url: '',
  365. baseUrl: '',
  366. externalServices: DefaultExternalServices,
  367. _boundEvents: {},
  368. contentDispositionFilename: null,
  369. initialize: function () {
  370. var _initialize = _asyncToGenerator(
  371. /*#__PURE__*/
  372. _regenerator.default.mark(function _callee(appConfig) {
  373. var _this = this;
  374. var appContainer;
  375. return _regenerator.default.wrap(function _callee$(_context) {
  376. while (1) {
  377. switch (_context.prev = _context.next) {
  378. case 0:
  379. this.preferences = this.externalServices.createPreferences();
  380. this.appConfig = appConfig;
  381. _context.next = 4;
  382. return this._readPreferences();
  383. case 4:
  384. _context.next = 6;
  385. return this._parseHashParameters();
  386. case 6:
  387. _context.next = 8;
  388. return this._initializeL10n();
  389. case 8:
  390. if (this.isViewerEmbedded && _app_options.AppOptions.get('externalLinkTarget') === _pdfjsLib.LinkTarget.NONE) {
  391. _app_options.AppOptions.set('externalLinkTarget', _pdfjsLib.LinkTarget.TOP);
  392. }
  393. _context.next = 11;
  394. return this._initializeViewerComponents();
  395. case 11:
  396. this.bindEvents();
  397. this.bindWindowEvents();
  398. appContainer = appConfig.appContainer || document.documentElement;
  399. this.l10n.translate(appContainer).then(function () {
  400. _this.eventBus.dispatch('localized', {
  401. source: _this
  402. });
  403. });
  404. this.initialized = true;
  405. case 16:
  406. case "end":
  407. return _context.stop();
  408. }
  409. }
  410. }, _callee, this);
  411. }));
  412. function initialize(_x) {
  413. return _initialize.apply(this, arguments);
  414. }
  415. return initialize;
  416. }(),
  417. _readPreferences: function () {
  418. var _readPreferences2 = _asyncToGenerator(
  419. /*#__PURE__*/
  420. _regenerator.default.mark(function _callee2() {
  421. var prefs, name;
  422. return _regenerator.default.wrap(function _callee2$(_context2) {
  423. while (1) {
  424. switch (_context2.prev = _context2.next) {
  425. case 0:
  426. if (!(_app_options.AppOptions.get('disablePreferences') === true)) {
  427. _context2.next = 2;
  428. break;
  429. }
  430. return _context2.abrupt("return");
  431. case 2:
  432. _context2.prev = 2;
  433. _context2.next = 5;
  434. return this.preferences.getAll();
  435. case 5:
  436. prefs = _context2.sent;
  437. for (name in prefs) {
  438. _app_options.AppOptions.set(name, prefs[name]);
  439. }
  440. _context2.next = 11;
  441. break;
  442. case 9:
  443. _context2.prev = 9;
  444. _context2.t0 = _context2["catch"](2);
  445. case 11:
  446. case "end":
  447. return _context2.stop();
  448. }
  449. }
  450. }, _callee2, this, [[2, 9]]);
  451. }));
  452. function _readPreferences() {
  453. return _readPreferences2.apply(this, arguments);
  454. }
  455. return _readPreferences;
  456. }(),
  457. _parseHashParameters: function () {
  458. var _parseHashParameters2 = _asyncToGenerator(
  459. /*#__PURE__*/
  460. _regenerator.default.mark(function _callee3() {
  461. var waitOn, hash, hashParams, viewer, enabled;
  462. return _regenerator.default.wrap(function _callee3$(_context3) {
  463. while (1) {
  464. switch (_context3.prev = _context3.next) {
  465. case 0:
  466. if (_app_options.AppOptions.get('pdfBugEnabled')) {
  467. _context3.next = 2;
  468. break;
  469. }
  470. return _context3.abrupt("return");
  471. case 2:
  472. waitOn = [];
  473. hash = document.location.hash.substring(1);
  474. hashParams = (0, _ui_utils.parseQueryString)(hash);
  475. if ('disableworker' in hashParams && hashParams['disableworker'] === 'true') {
  476. waitOn.push(loadFakeWorker());
  477. }
  478. if ('disablerange' in hashParams) {
  479. _app_options.AppOptions.set('disableRange', hashParams['disablerange'] === 'true');
  480. }
  481. if ('disablestream' in hashParams) {
  482. _app_options.AppOptions.set('disableStream', hashParams['disablestream'] === 'true');
  483. }
  484. if ('disableautofetch' in hashParams) {
  485. _app_options.AppOptions.set('disableAutoFetch', hashParams['disableautofetch'] === 'true');
  486. }
  487. if ('disablefontface' in hashParams) {
  488. _app_options.AppOptions.set('disableFontFace', hashParams['disablefontface'] === 'true');
  489. }
  490. if ('disablehistory' in hashParams) {
  491. _app_options.AppOptions.set('disableHistory', hashParams['disablehistory'] === 'true');
  492. }
  493. if ('webgl' in hashParams) {
  494. _app_options.AppOptions.set('enableWebGL', hashParams['webgl'] === 'true');
  495. }
  496. if ('useonlycsszoom' in hashParams) {
  497. _app_options.AppOptions.set('useOnlyCssZoom', hashParams['useonlycsszoom'] === 'true');
  498. }
  499. if ('verbosity' in hashParams) {
  500. _app_options.AppOptions.set('verbosity', hashParams['verbosity'] | 0);
  501. }
  502. if (!('textlayer' in hashParams)) {
  503. _context3.next = 23;
  504. break;
  505. }
  506. _context3.t0 = hashParams['textlayer'];
  507. _context3.next = _context3.t0 === 'off' ? 18 : _context3.t0 === 'visible' ? 20 : _context3.t0 === 'shadow' ? 20 : _context3.t0 === 'hover' ? 20 : 23;
  508. break;
  509. case 18:
  510. _app_options.AppOptions.set('textLayerMode', _ui_utils.TextLayerMode.DISABLE);
  511. return _context3.abrupt("break", 23);
  512. case 20:
  513. viewer = this.appConfig.viewerContainer;
  514. viewer.classList.add('textLayer-' + hashParams['textlayer']);
  515. return _context3.abrupt("break", 23);
  516. case 23:
  517. if ('pdfbug' in hashParams) {
  518. _app_options.AppOptions.set('pdfBug', true);
  519. enabled = hashParams['pdfbug'].split(',');
  520. waitOn.push(loadAndEnablePDFBug(enabled));
  521. }
  522. if ('locale' in hashParams) {
  523. _app_options.AppOptions.set('locale', hashParams['locale']);
  524. }
  525. return _context3.abrupt("return", Promise.all(waitOn).catch(function (reason) {
  526. console.error("_parseHashParameters: \"".concat(reason.message, "\"."));
  527. }));
  528. case 26:
  529. case "end":
  530. return _context3.stop();
  531. }
  532. }
  533. }, _callee3, this);
  534. }));
  535. function _parseHashParameters() {
  536. return _parseHashParameters2.apply(this, arguments);
  537. }
  538. return _parseHashParameters;
  539. }(),
  540. _initializeL10n: function () {
  541. var _initializeL10n2 = _asyncToGenerator(
  542. /*#__PURE__*/
  543. _regenerator.default.mark(function _callee4() {
  544. var dir;
  545. return _regenerator.default.wrap(function _callee4$(_context4) {
  546. while (1) {
  547. switch (_context4.prev = _context4.next) {
  548. case 0:
  549. this.l10n = this.externalServices.createL10n({
  550. locale: _app_options.AppOptions.get('locale')
  551. });
  552. _context4.next = 3;
  553. return this.l10n.getDirection();
  554. case 3:
  555. dir = _context4.sent;
  556. document.getElementsByTagName('html')[0].dir = dir;
  557. case 5:
  558. case "end":
  559. return _context4.stop();
  560. }
  561. }
  562. }, _callee4, this);
  563. }));
  564. function _initializeL10n() {
  565. return _initializeL10n2.apply(this, arguments);
  566. }
  567. return _initializeL10n;
  568. }(),
  569. _initializeViewerComponents: function () {
  570. var _initializeViewerComponents2 = _asyncToGenerator(
  571. /*#__PURE__*/
  572. _regenerator.default.mark(function _callee5() {
  573. var appConfig, dispatchToDOM, eventBus, pdfRenderingQueue, pdfLinkService, downloadManager, findController, container, viewer, thumbnailContainer, sidebarConfig;
  574. return _regenerator.default.wrap(function _callee5$(_context5) {
  575. while (1) {
  576. switch (_context5.prev = _context5.next) {
  577. case 0:
  578. appConfig = this.appConfig;
  579. this.overlayManager = new _overlay_manager.OverlayManager();
  580. dispatchToDOM = _app_options.AppOptions.get('eventBusDispatchToDOM');
  581. eventBus = appConfig.eventBus || (0, _ui_utils.getGlobalEventBus)(dispatchToDOM);
  582. this.eventBus = eventBus;
  583. pdfRenderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  584. pdfRenderingQueue.onIdle = this.cleanup.bind(this);
  585. this.pdfRenderingQueue = pdfRenderingQueue;
  586. pdfLinkService = new _pdf_link_service.PDFLinkService({
  587. eventBus: eventBus,
  588. externalLinkTarget: _app_options.AppOptions.get('externalLinkTarget'),
  589. externalLinkRel: _app_options.AppOptions.get('externalLinkRel')
  590. });
  591. this.pdfLinkService = pdfLinkService;
  592. downloadManager = this.externalServices.createDownloadManager({
  593. disableCreateObjectURL: _app_options.AppOptions.get('disableCreateObjectURL')
  594. });
  595. this.downloadManager = downloadManager;
  596. findController = new _pdf_find_controller.PDFFindController({
  597. linkService: pdfLinkService,
  598. eventBus: eventBus
  599. });
  600. this.findController = findController;
  601. container = appConfig.mainContainer;
  602. viewer = appConfig.viewerContainer;
  603. this.pdfViewer = new _pdf_viewer.PDFViewer({
  604. container: container,
  605. viewer: viewer,
  606. eventBus: eventBus,
  607. renderingQueue: pdfRenderingQueue,
  608. linkService: pdfLinkService,
  609. downloadManager: downloadManager,
  610. findController: findController,
  611. renderer: _app_options.AppOptions.get('renderer'),
  612. enableWebGL: _app_options.AppOptions.get('enableWebGL'),
  613. l10n: this.l10n,
  614. textLayerMode: _app_options.AppOptions.get('textLayerMode'),
  615. imageResourcesPath: _app_options.AppOptions.get('imageResourcesPath'),
  616. renderInteractiveForms: _app_options.AppOptions.get('renderInteractiveForms'),
  617. enablePrintAutoRotate: _app_options.AppOptions.get('enablePrintAutoRotate'),
  618. useOnlyCssZoom: _app_options.AppOptions.get('useOnlyCssZoom'),
  619. maxCanvasPixels: _app_options.AppOptions.get('maxCanvasPixels')
  620. });
  621. pdfRenderingQueue.setViewer(this.pdfViewer);
  622. pdfLinkService.setViewer(this.pdfViewer);
  623. thumbnailContainer = appConfig.sidebar.thumbnailView;
  624. this.pdfThumbnailViewer = new _pdf_thumbnail_viewer.PDFThumbnailViewer({
  625. container: thumbnailContainer,
  626. renderingQueue: pdfRenderingQueue,
  627. linkService: pdfLinkService,
  628. l10n: this.l10n
  629. });
  630. pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
  631. this.pdfHistory = new _pdf_history.PDFHistory({
  632. linkService: pdfLinkService,
  633. eventBus: eventBus
  634. });
  635. pdfLinkService.setHistory(this.pdfHistory);
  636. this.findBar = new _pdf_find_bar.PDFFindBar(appConfig.findBar, eventBus, this.l10n);
  637. this.pdfDocumentProperties = new _pdf_document_properties.PDFDocumentProperties(appConfig.documentProperties, this.overlayManager, eventBus, this.l10n);
  638. this.pdfCursorTools = new _pdf_cursor_tools.PDFCursorTools({
  639. container: container,
  640. eventBus: eventBus,
  641. cursorToolOnLoad: _app_options.AppOptions.get('cursorToolOnLoad')
  642. });
  643. this.toolbar = new _toolbar.Toolbar(appConfig.toolbar, eventBus, this.l10n);
  644. this.secondaryToolbar = new _secondary_toolbar.SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
  645. if (this.supportsFullscreen) {
  646. this.pdfPresentationMode = new _pdf_presentation_mode.PDFPresentationMode({
  647. container: container,
  648. viewer: viewer,
  649. pdfViewer: this.pdfViewer,
  650. eventBus: eventBus,
  651. contextMenuItems: appConfig.fullscreen
  652. });
  653. }
  654. this.passwordPrompt = new _password_prompt.PasswordPrompt(appConfig.passwordOverlay, this.overlayManager, this.l10n);
  655. this.pdfOutlineViewer = new _pdf_outline_viewer.PDFOutlineViewer({
  656. container: appConfig.sidebar.outlineView,
  657. eventBus: eventBus,
  658. linkService: pdfLinkService
  659. });
  660. this.pdfAttachmentViewer = new _pdf_attachment_viewer.PDFAttachmentViewer({
  661. container: appConfig.sidebar.attachmentsView,
  662. eventBus: eventBus,
  663. downloadManager: downloadManager
  664. });
  665. sidebarConfig = Object.create(appConfig.sidebar);
  666. sidebarConfig.pdfViewer = this.pdfViewer;
  667. sidebarConfig.pdfThumbnailViewer = this.pdfThumbnailViewer;
  668. this.pdfSidebar = new _pdf_sidebar.PDFSidebar(sidebarConfig, eventBus, this.l10n);
  669. this.pdfSidebar.onToggled = this.forceRendering.bind(this);
  670. this.pdfSidebarResizer = new _pdf_sidebar_resizer.PDFSidebarResizer(appConfig.sidebarResizer, eventBus, this.l10n);
  671. case 39:
  672. case "end":
  673. return _context5.stop();
  674. }
  675. }
  676. }, _callee5, this);
  677. }));
  678. function _initializeViewerComponents() {
  679. return _initializeViewerComponents2.apply(this, arguments);
  680. }
  681. return _initializeViewerComponents;
  682. }(),
  683. run: function run(config) {
  684. this.initialize(config).then(webViewerInitialized);
  685. },
  686. zoomIn: function zoomIn(ticks) {
  687. var newScale = this.pdfViewer.currentScale;
  688. do {
  689. newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
  690. newScale = Math.ceil(newScale * 10) / 10;
  691. newScale = Math.min(_ui_utils.MAX_SCALE, newScale);
  692. } while (--ticks > 0 && newScale < _ui_utils.MAX_SCALE);
  693. this.pdfViewer.currentScaleValue = newScale;
  694. },
  695. zoomOut: function zoomOut(ticks) {
  696. var newScale = this.pdfViewer.currentScale;
  697. do {
  698. newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
  699. newScale = Math.floor(newScale * 10) / 10;
  700. newScale = Math.max(_ui_utils.MIN_SCALE, newScale);
  701. } while (--ticks > 0 && newScale > _ui_utils.MIN_SCALE);
  702. this.pdfViewer.currentScaleValue = newScale;
  703. },
  704. get pagesCount() {
  705. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  706. },
  707. set page(val) {
  708. this.pdfViewer.currentPageNumber = val;
  709. },
  710. get page() {
  711. return this.pdfViewer.currentPageNumber;
  712. },
  713. get printing() {
  714. return !!this.printService;
  715. },
  716. get supportsPrinting() {
  717. return PDFPrintServiceFactory.instance.supportsPrinting;
  718. },
  719. get supportsFullscreen() {
  720. var support;
  721. var doc = document.documentElement;
  722. support = !!(doc.requestFullscreen || doc.mozRequestFullScreen || doc.webkitRequestFullScreen || doc.msRequestFullscreen);
  723. if (document.fullscreenEnabled === false || document.mozFullScreenEnabled === false || document.webkitFullscreenEnabled === false || document.msFullscreenEnabled === false) {
  724. support = false;
  725. }
  726. return (0, _pdfjsLib.shadow)(this, 'supportsFullscreen', support);
  727. },
  728. get supportsIntegratedFind() {
  729. return this.externalServices.supportsIntegratedFind;
  730. },
  731. get supportsDocumentFonts() {
  732. return this.externalServices.supportsDocumentFonts;
  733. },
  734. get supportsDocumentColors() {
  735. return this.externalServices.supportsDocumentColors;
  736. },
  737. get loadingBar() {
  738. var bar = new _ui_utils.ProgressBar('#loadingBar');
  739. return (0, _pdfjsLib.shadow)(this, 'loadingBar', bar);
  740. },
  741. get supportedMouseWheelZoomModifierKeys() {
  742. return this.externalServices.supportedMouseWheelZoomModifierKeys;
  743. },
  744. initPassiveLoading: function initPassiveLoading() {
  745. throw new Error('Not implemented: initPassiveLoading');
  746. },
  747. setTitleUsingUrl: function setTitleUsingUrl() {
  748. var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  749. this.url = url;
  750. this.baseUrl = url.split('#')[0];
  751. var title = (0, _ui_utils.getPDFFileNameFromURL)(url, '');
  752. if (!title) {
  753. try {
  754. title = decodeURIComponent((0, _pdfjsLib.getFilenameFromUrl)(url)) || url;
  755. } catch (ex) {
  756. title = url;
  757. }
  758. }
  759. this.setTitle(title);
  760. },
  761. setTitle: function setTitle(title) {
  762. if (this.isViewerEmbedded) {
  763. return;
  764. }
  765. document.title = title;
  766. },
  767. close: function () {
  768. var _close = _asyncToGenerator(
  769. /*#__PURE__*/
  770. _regenerator.default.mark(function _callee6() {
  771. var errorWrapper, promise;
  772. return _regenerator.default.wrap(function _callee6$(_context6) {
  773. while (1) {
  774. switch (_context6.prev = _context6.next) {
  775. case 0:
  776. errorWrapper = this.appConfig.errorWrapper.container;
  777. errorWrapper.setAttribute('hidden', 'true');
  778. if (this.pdfLoadingTask) {
  779. _context6.next = 4;
  780. break;
  781. }
  782. return _context6.abrupt("return");
  783. case 4:
  784. promise = this.pdfLoadingTask.destroy();
  785. this.pdfLoadingTask = null;
  786. if (this.pdfDocument) {
  787. this.pdfDocument = null;
  788. this.pdfThumbnailViewer.setDocument(null);
  789. this.pdfViewer.setDocument(null);
  790. this.pdfLinkService.setDocument(null);
  791. this.pdfDocumentProperties.setDocument(null);
  792. }
  793. this.store = null;
  794. this.isInitialViewSet = false;
  795. this.downloadComplete = false;
  796. this.url = '';
  797. this.baseUrl = '';
  798. this.contentDispositionFilename = null;
  799. this.pdfSidebar.reset();
  800. this.pdfOutlineViewer.reset();
  801. this.pdfAttachmentViewer.reset();
  802. this.findBar.reset();
  803. this.toolbar.reset();
  804. this.secondaryToolbar.reset();
  805. if (typeof PDFBug !== 'undefined') {
  806. PDFBug.cleanup();
  807. }
  808. return _context6.abrupt("return", promise);
  809. case 21:
  810. case "end":
  811. return _context6.stop();
  812. }
  813. }
  814. }, _callee6, this);
  815. }));
  816. function close() {
  817. return _close.apply(this, arguments);
  818. }
  819. return close;
  820. }(),
  821. open: function () {
  822. var _open = _asyncToGenerator(
  823. /*#__PURE__*/
  824. _regenerator.default.mark(function _callee7(file, args) {
  825. var _this2 = this;
  826. var workerParameters, key, parameters, apiParameters, _key, prop, loadingTask;
  827. return _regenerator.default.wrap(function _callee7$(_context7) {
  828. while (1) {
  829. switch (_context7.prev = _context7.next) {
  830. case 0:
  831. if (!this.pdfLoadingTask) {
  832. _context7.next = 3;
  833. break;
  834. }
  835. _context7.next = 3;
  836. return this.close();
  837. case 3:
  838. workerParameters = _app_options.AppOptions.getAll('worker');
  839. for (key in workerParameters) {
  840. _pdfjsLib.GlobalWorkerOptions[key] = workerParameters[key];
  841. }
  842. parameters = Object.create(null);
  843. if (typeof file === 'string') {
  844. this.setTitleUsingUrl(file);
  845. parameters.url = file;
  846. } else if (file && 'byteLength' in file) {
  847. parameters.data = file;
  848. } else if (file.url && file.originalUrl) {
  849. this.setTitleUsingUrl(file.originalUrl);
  850. parameters.url = file.url;
  851. }
  852. apiParameters = _app_options.AppOptions.getAll('api');
  853. for (_key in apiParameters) {
  854. parameters[_key] = apiParameters[_key];
  855. }
  856. if (args) {
  857. for (prop in args) {
  858. if (prop === 'length') {
  859. this.pdfDocumentProperties.setFileSize(args[prop]);
  860. }
  861. parameters[prop] = args[prop];
  862. }
  863. }
  864. loadingTask = (0, _pdfjsLib.getDocument)(parameters);
  865. this.pdfLoadingTask = loadingTask;
  866. loadingTask.onPassword = function (updateCallback, reason) {
  867. _this2.passwordPrompt.setUpdateCallback(updateCallback, reason);
  868. _this2.passwordPrompt.open();
  869. };
  870. loadingTask.onProgress = function (_ref) {
  871. var loaded = _ref.loaded,
  872. total = _ref.total;
  873. _this2.progress(loaded / total);
  874. };
  875. loadingTask.onUnsupportedFeature = this.fallback.bind(this);
  876. return _context7.abrupt("return", loadingTask.promise.then(function (pdfDocument) {
  877. _this2.load(pdfDocument);
  878. }, function (exception) {
  879. if (loadingTask !== _this2.pdfLoadingTask) {
  880. return;
  881. }
  882. var message = exception && exception.message;
  883. var loadingErrorMessage;
  884. if (exception instanceof _pdfjsLib.InvalidPDFException) {
  885. loadingErrorMessage = _this2.l10n.get('invalid_file_error', null, 'Invalid or corrupted PDF file.');
  886. } else if (exception instanceof _pdfjsLib.MissingPDFException) {
  887. loadingErrorMessage = _this2.l10n.get('missing_file_error', null, 'Missing PDF file.');
  888. } else if (exception instanceof _pdfjsLib.UnexpectedResponseException) {
  889. loadingErrorMessage = _this2.l10n.get('unexpected_response_error', null, 'Unexpected server response.');
  890. } else {
  891. loadingErrorMessage = _this2.l10n.get('loading_error', null, 'An error occurred while loading the PDF.');
  892. }
  893. return loadingErrorMessage.then(function (msg) {
  894. _this2.error(msg, {
  895. message: message
  896. });
  897. throw new Error(msg);
  898. });
  899. }));
  900. case 16:
  901. case "end":
  902. return _context7.stop();
  903. }
  904. }
  905. }, _callee7, this);
  906. }));
  907. function open(_x2, _x3) {
  908. return _open.apply(this, arguments);
  909. }
  910. return open;
  911. }(),
  912. download: function download() {
  913. var _this3 = this;
  914. function downloadByUrl() {
  915. downloadManager.downloadUrl(url, filename);
  916. }
  917. var url = this.baseUrl;
  918. var filename = this.contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(this.url);
  919. var downloadManager = this.downloadManager;
  920. downloadManager.onerror = function (err) {
  921. _this3.error("PDF failed to download: ".concat(err));
  922. };
  923. if (!this.pdfDocument || !this.downloadComplete) {
  924. downloadByUrl();
  925. return;
  926. }
  927. this.pdfDocument.getData().then(function (data) {
  928. var blob = new Blob([data], {
  929. type: 'application/pdf'
  930. });
  931. downloadManager.download(blob, url, filename);
  932. }).catch(downloadByUrl);
  933. },
  934. fallback: function fallback(featureId) {},
  935. error: function error(message, moreInfo) {
  936. var moreInfoText = [this.l10n.get('error_version_info', {
  937. version: _pdfjsLib.version || '?',
  938. build: _pdfjsLib.build || '?'
  939. }, 'PDF.js v{{version}} (build: {{build}})')];
  940. if (moreInfo) {
  941. moreInfoText.push(this.l10n.get('error_message', {
  942. message: moreInfo.message
  943. }, 'Message: {{message}}'));
  944. if (moreInfo.stack) {
  945. moreInfoText.push(this.l10n.get('error_stack', {
  946. stack: moreInfo.stack
  947. }, 'Stack: {{stack}}'));
  948. } else {
  949. if (moreInfo.filename) {
  950. moreInfoText.push(this.l10n.get('error_file', {
  951. file: moreInfo.filename
  952. }, 'File: {{file}}'));
  953. }
  954. if (moreInfo.lineNumber) {
  955. moreInfoText.push(this.l10n.get('error_line', {
  956. line: moreInfo.lineNumber
  957. }, 'Line: {{line}}'));
  958. }
  959. }
  960. }
  961. var errorWrapperConfig = this.appConfig.errorWrapper;
  962. var errorWrapper = errorWrapperConfig.container;
  963. errorWrapper.removeAttribute('hidden');
  964. var errorMessage = errorWrapperConfig.errorMessage;
  965. errorMessage.textContent = message;
  966. var closeButton = errorWrapperConfig.closeButton;
  967. closeButton.onclick = function () {
  968. errorWrapper.setAttribute('hidden', 'true');
  969. };
  970. var errorMoreInfo = errorWrapperConfig.errorMoreInfo;
  971. var moreInfoButton = errorWrapperConfig.moreInfoButton;
  972. var lessInfoButton = errorWrapperConfig.lessInfoButton;
  973. moreInfoButton.onclick = function () {
  974. errorMoreInfo.removeAttribute('hidden');
  975. moreInfoButton.setAttribute('hidden', 'true');
  976. lessInfoButton.removeAttribute('hidden');
  977. errorMoreInfo.style.height = errorMoreInfo.scrollHeight + 'px';
  978. };
  979. lessInfoButton.onclick = function () {
  980. errorMoreInfo.setAttribute('hidden', 'true');
  981. moreInfoButton.removeAttribute('hidden');
  982. lessInfoButton.setAttribute('hidden', 'true');
  983. };
  984. moreInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  985. lessInfoButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  986. closeButton.oncontextmenu = _ui_utils.noContextMenuHandler;
  987. moreInfoButton.removeAttribute('hidden');
  988. lessInfoButton.setAttribute('hidden', 'true');
  989. Promise.all(moreInfoText).then(function (parts) {
  990. errorMoreInfo.value = parts.join('\n');
  991. });
  992. },
  993. progress: function progress(level) {
  994. var _this4 = this;
  995. if (this.downloadComplete) {
  996. return;
  997. }
  998. var percent = Math.round(level * 100);
  999. if (percent > this.loadingBar.percent || isNaN(percent)) {
  1000. this.loadingBar.percent = percent;
  1001. var disableAutoFetch = this.pdfDocument ? this.pdfDocument.loadingParams['disableAutoFetch'] : _app_options.AppOptions.get('disableAutoFetch');
  1002. if (disableAutoFetch && percent) {
  1003. if (this.disableAutoFetchLoadingBarTimeout) {
  1004. clearTimeout(this.disableAutoFetchLoadingBarTimeout);
  1005. this.disableAutoFetchLoadingBarTimeout = null;
  1006. }
  1007. this.loadingBar.show();
  1008. this.disableAutoFetchLoadingBarTimeout = setTimeout(function () {
  1009. _this4.loadingBar.hide();
  1010. _this4.disableAutoFetchLoadingBarTimeout = null;
  1011. }, DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT);
  1012. }
  1013. }
  1014. },
  1015. load: function load(pdfDocument) {
  1016. var _this5 = this;
  1017. this.pdfDocument = pdfDocument;
  1018. pdfDocument.getDownloadInfo().then(function () {
  1019. _this5.downloadComplete = true;
  1020. _this5.loadingBar.hide();
  1021. firstPagePromise.then(function () {
  1022. _this5.eventBus.dispatch('documentloaded', {
  1023. source: _this5
  1024. });
  1025. });
  1026. });
  1027. var pageModePromise = pdfDocument.getPageMode().catch(function () {});
  1028. var openActionDestPromise = pdfDocument.getOpenActionDestination().catch(function () {});
  1029. this.toolbar.setPagesCount(pdfDocument.numPages, false);
  1030. this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
  1031. var store = this.store = new _view_history.ViewHistory(pdfDocument.fingerprint);
  1032. var baseDocumentUrl;
  1033. baseDocumentUrl = null;
  1034. this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
  1035. this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
  1036. var pdfViewer = this.pdfViewer;
  1037. pdfViewer.setDocument(pdfDocument);
  1038. var firstPagePromise = pdfViewer.firstPagePromise;
  1039. var pagesPromise = pdfViewer.pagesPromise;
  1040. var onePageRendered = pdfViewer.onePageRendered;
  1041. var pdfThumbnailViewer = this.pdfThumbnailViewer;
  1042. pdfThumbnailViewer.setDocument(pdfDocument);
  1043. firstPagePromise.then(function (pdfPage) {
  1044. _this5.loadingBar.setWidth(_this5.appConfig.viewerContainer);
  1045. var storePromise = store.getMultiple({
  1046. page: null,
  1047. zoom: _ui_utils.DEFAULT_SCALE_VALUE,
  1048. scrollLeft: '0',
  1049. scrollTop: '0',
  1050. rotation: null,
  1051. sidebarView: _pdf_sidebar.SidebarView.UNKNOWN,
  1052. scrollMode: _ui_utils.ScrollMode.UNKNOWN,
  1053. spreadMode: _ui_utils.SpreadMode.UNKNOWN
  1054. }).catch(function () {});
  1055. Promise.all([storePromise, pageModePromise, openActionDestPromise]).then(
  1056. /*#__PURE__*/
  1057. function () {
  1058. var _ref3 = _asyncToGenerator(
  1059. /*#__PURE__*/
  1060. _regenerator.default.mark(function _callee8(_ref2) {
  1061. var _ref4, _ref4$, values, pageMode, openActionDest, viewOnLoad, initialBookmark, zoom, hash, rotation, sidebarView, scrollMode, spreadMode;
  1062. return _regenerator.default.wrap(function _callee8$(_context8) {
  1063. while (1) {
  1064. switch (_context8.prev = _context8.next) {
  1065. case 0:
  1066. _ref4 = _slicedToArray(_ref2, 3), _ref4$ = _ref4[0], values = _ref4$ === void 0 ? {} : _ref4$, pageMode = _ref4[1], openActionDest = _ref4[2];
  1067. viewOnLoad = _app_options.AppOptions.get('viewOnLoad');
  1068. _this5._initializePdfHistory({
  1069. fingerprint: pdfDocument.fingerprint,
  1070. viewOnLoad: viewOnLoad,
  1071. initialDest: openActionDest
  1072. });
  1073. initialBookmark = _this5.initialBookmark;
  1074. zoom = _app_options.AppOptions.get('defaultZoomValue');
  1075. hash = zoom ? "zoom=".concat(zoom) : null;
  1076. rotation = null;
  1077. sidebarView = _app_options.AppOptions.get('sidebarViewOnLoad');
  1078. scrollMode = _app_options.AppOptions.get('scrollModeOnLoad');
  1079. spreadMode = _app_options.AppOptions.get('spreadModeOnLoad');
  1080. if (values.page && viewOnLoad !== ViewOnLoad.INITIAL) {
  1081. hash = "page=".concat(values.page, "&zoom=").concat(zoom || values.zoom, ",") + "".concat(values.scrollLeft, ",").concat(values.scrollTop);
  1082. rotation = parseInt(values.rotation, 10);
  1083. if (sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
  1084. sidebarView = values.sidebarView | 0;
  1085. }
  1086. if (scrollMode === _ui_utils.ScrollMode.UNKNOWN) {
  1087. scrollMode = values.scrollMode | 0;
  1088. }
  1089. if (spreadMode === _ui_utils.SpreadMode.UNKNOWN) {
  1090. spreadMode = values.spreadMode | 0;
  1091. }
  1092. }
  1093. if (pageMode && sidebarView === _pdf_sidebar.SidebarView.UNKNOWN) {
  1094. sidebarView = apiPageModeToSidebarView(pageMode);
  1095. }
  1096. _this5.setInitialView(hash, {
  1097. rotation: rotation,
  1098. sidebarView: sidebarView,
  1099. scrollMode: scrollMode,
  1100. spreadMode: spreadMode
  1101. });
  1102. _this5.eventBus.dispatch('documentinit', {
  1103. source: _this5
  1104. });
  1105. if (!_this5.isViewerEmbedded) {
  1106. pdfViewer.focus();
  1107. }
  1108. _context8.next = 17;
  1109. return Promise.race([pagesPromise, new Promise(function (resolve) {
  1110. setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT);
  1111. })]);
  1112. case 17:
  1113. if (!(!initialBookmark && !hash)) {
  1114. _context8.next = 19;
  1115. break;
  1116. }
  1117. return _context8.abrupt("return");
  1118. case 19:
  1119. if (!pdfViewer.hasEqualPageSizes) {
  1120. _context8.next = 21;
  1121. break;
  1122. }
  1123. return _context8.abrupt("return");
  1124. case 21:
  1125. _this5.initialBookmark = initialBookmark;
  1126. pdfViewer.currentScaleValue = pdfViewer.currentScaleValue;
  1127. _this5.setInitialView(hash);
  1128. case 24:
  1129. case "end":
  1130. return _context8.stop();
  1131. }
  1132. }
  1133. }, _callee8, this);
  1134. }));
  1135. return function (_x4) {
  1136. return _ref3.apply(this, arguments);
  1137. };
  1138. }()).catch(function () {
  1139. _this5.setInitialView();
  1140. }).then(function () {
  1141. pdfViewer.update();
  1142. });
  1143. });
  1144. pdfDocument.getPageLabels().then(function (labels) {
  1145. if (!labels || _app_options.AppOptions.get('disablePageLabels')) {
  1146. return;
  1147. }
  1148. var i = 0,
  1149. numLabels = labels.length;
  1150. if (numLabels !== _this5.pagesCount) {
  1151. console.error('The number of Page Labels does not match ' + 'the number of pages in the document.');
  1152. return;
  1153. }
  1154. while (i < numLabels && labels[i] === (i + 1).toString()) {
  1155. i++;
  1156. }
  1157. if (i === numLabels) {
  1158. return;
  1159. }
  1160. pdfViewer.setPageLabels(labels);
  1161. pdfThumbnailViewer.setPageLabels(labels);
  1162. _this5.toolbar.setPagesCount(pdfDocument.numPages, true);
  1163. _this5.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1164. });
  1165. pagesPromise.then(function () {
  1166. if (!_this5.supportsPrinting) {
  1167. return;
  1168. }
  1169. pdfDocument.getJavaScript().then(function (javaScript) {
  1170. if (!javaScript) {
  1171. return;
  1172. }
  1173. javaScript.some(function (js) {
  1174. if (!js) {
  1175. return false;
  1176. }
  1177. console.warn('Warning: JavaScript is not supported');
  1178. _this5.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.javaScript);
  1179. return true;
  1180. });
  1181. var regex = /\bprint\s*\(/;
  1182. for (var i = 0, ii = javaScript.length; i < ii; i++) {
  1183. var js = javaScript[i];
  1184. if (js && regex.test(js)) {
  1185. setTimeout(function () {
  1186. window.print();
  1187. });
  1188. return;
  1189. }
  1190. }
  1191. });
  1192. });
  1193. Promise.all([onePageRendered, _ui_utils.animationStarted]).then(function () {
  1194. pdfDocument.getOutline().then(function (outline) {
  1195. _this5.pdfOutlineViewer.render({
  1196. outline: outline
  1197. });
  1198. });
  1199. pdfDocument.getAttachments().then(function (attachments) {
  1200. _this5.pdfAttachmentViewer.render({
  1201. attachments: attachments
  1202. });
  1203. });
  1204. });
  1205. pdfDocument.getMetadata().then(function (_ref5) {
  1206. var info = _ref5.info,
  1207. metadata = _ref5.metadata,
  1208. contentDispositionFilename = _ref5.contentDispositionFilename;
  1209. _this5.documentInfo = info;
  1210. _this5.metadata = metadata;
  1211. _this5.contentDispositionFilename = contentDispositionFilename;
  1212. console.log('PDF ' + pdfDocument.fingerprint + ' [' + info.PDFFormatVersion + ' ' + (info.Producer || '-').trim() + ' / ' + (info.Creator || '-').trim() + ']' + ' (PDF.js: ' + (_pdfjsLib.version || '-') + (_app_options.AppOptions.get('enableWebGL') ? ' [WebGL]' : '') + ')');
  1213. var pdfTitle;
  1214. if (metadata && metadata.has('dc:title')) {
  1215. var title = metadata.get('dc:title');
  1216. if (title !== 'Untitled') {
  1217. pdfTitle = title;
  1218. }
  1219. }
  1220. if (!pdfTitle && info && info['Title']) {
  1221. pdfTitle = info['Title'];
  1222. }
  1223. if (pdfTitle) {
  1224. _this5.setTitle("".concat(pdfTitle, " - ").concat(contentDispositionFilename || document.title));
  1225. } else if (contentDispositionFilename) {
  1226. _this5.setTitle(contentDispositionFilename);
  1227. }
  1228. if (info.IsAcroFormPresent) {
  1229. console.warn('Warning: AcroForm/XFA is not supported');
  1230. _this5.fallback(_pdfjsLib.UNSUPPORTED_FEATURES.forms);
  1231. }
  1232. });
  1233. },
  1234. _initializePdfHistory: function _initializePdfHistory(_ref6) {
  1235. var fingerprint = _ref6.fingerprint,
  1236. viewOnLoad = _ref6.viewOnLoad,
  1237. _ref6$initialDest = _ref6.initialDest,
  1238. initialDest = _ref6$initialDest === void 0 ? null : _ref6$initialDest;
  1239. if (_app_options.AppOptions.get('disableHistory') || this.isViewerEmbedded) {
  1240. return;
  1241. }
  1242. this.pdfHistory.initialize({
  1243. fingerprint: fingerprint,
  1244. resetHistory: viewOnLoad === ViewOnLoad.INITIAL,
  1245. updateUrl: _app_options.AppOptions.get('historyUpdateUrl')
  1246. });
  1247. if (this.pdfHistory.initialBookmark) {
  1248. this.initialBookmark = this.pdfHistory.initialBookmark;
  1249. this.initialRotation = this.pdfHistory.initialRotation;
  1250. }
  1251. if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) {
  1252. this.initialBookmark = JSON.stringify(initialDest);
  1253. this.pdfHistory.push({
  1254. explicitDest: initialDest,
  1255. pageNumber: null
  1256. });
  1257. }
  1258. },
  1259. setInitialView: function setInitialView(storedHash) {
  1260. var _this6 = this;
  1261. var _ref7 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  1262. rotation = _ref7.rotation,
  1263. sidebarView = _ref7.sidebarView,
  1264. scrollMode = _ref7.scrollMode,
  1265. spreadMode = _ref7.spreadMode;
  1266. var setRotation = function setRotation(angle) {
  1267. if ((0, _ui_utils.isValidRotation)(angle)) {
  1268. _this6.pdfViewer.pagesRotation = angle;
  1269. }
  1270. };
  1271. var setViewerModes = function setViewerModes(scroll, spread) {
  1272. if ((0, _ui_utils.isValidScrollMode)(scroll)) {
  1273. _this6.pdfViewer.scrollMode = scroll;
  1274. }
  1275. if ((0, _ui_utils.isValidSpreadMode)(spread)) {
  1276. _this6.pdfViewer.spreadMode = spread;
  1277. }
  1278. };
  1279. this.isInitialViewSet = true;
  1280. this.pdfSidebar.setInitialView(sidebarView);
  1281. setViewerModes(scrollMode, spreadMode);
  1282. if (this.initialBookmark) {
  1283. setRotation(this.initialRotation);
  1284. delete this.initialRotation;
  1285. this.pdfLinkService.setHash(this.initialBookmark);
  1286. this.initialBookmark = null;
  1287. } else if (storedHash) {
  1288. setRotation(rotation);
  1289. this.pdfLinkService.setHash(storedHash);
  1290. }
  1291. this.toolbar.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel);
  1292. this.secondaryToolbar.setPageNumber(this.pdfViewer.currentPageNumber);
  1293. if (!this.pdfViewer.currentScaleValue) {
  1294. this.pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  1295. }
  1296. },
  1297. cleanup: function cleanup() {
  1298. if (!this.pdfDocument) {
  1299. return;
  1300. }
  1301. this.pdfViewer.cleanup();
  1302. this.pdfThumbnailViewer.cleanup();
  1303. if (this.pdfViewer.renderer !== _ui_utils.RendererType.SVG) {
  1304. this.pdfDocument.cleanup();
  1305. }
  1306. },
  1307. forceRendering: function forceRendering() {
  1308. this.pdfRenderingQueue.printing = this.printing;
  1309. this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar.isThumbnailViewVisible;
  1310. this.pdfRenderingQueue.renderHighestPriority();
  1311. },
  1312. beforePrint: function beforePrint() {
  1313. var _this7 = this;
  1314. if (this.printService) {
  1315. return;
  1316. }
  1317. if (!this.supportsPrinting) {
  1318. this.l10n.get('printing_not_supported', null, 'Warning: Printing is not fully supported by ' + 'this browser.').then(function (printMessage) {
  1319. _this7.error(printMessage);
  1320. });
  1321. return;
  1322. }
  1323. if (!this.pdfViewer.pageViewsReady) {
  1324. this.l10n.get('printing_not_ready', null, 'Warning: The PDF is not fully loaded for printing.').then(function (notReadyMessage) {
  1325. window.alert(notReadyMessage);
  1326. });
  1327. return;
  1328. }
  1329. var pagesOverview = this.pdfViewer.getPagesOverview();
  1330. var printContainer = this.appConfig.printContainer;
  1331. var printService = PDFPrintServiceFactory.instance.createPrintService(this.pdfDocument, pagesOverview, printContainer, this.l10n);
  1332. this.printService = printService;
  1333. this.forceRendering();
  1334. printService.layout();
  1335. },
  1336. afterPrint: function pdfViewSetupAfterPrint() {
  1337. if (this.printService) {
  1338. this.printService.destroy();
  1339. this.printService = null;
  1340. }
  1341. this.forceRendering();
  1342. },
  1343. rotatePages: function rotatePages(delta) {
  1344. if (!this.pdfDocument) {
  1345. return;
  1346. }
  1347. var newRotation = (this.pdfViewer.pagesRotation + 360 + delta) % 360;
  1348. this.pdfViewer.pagesRotation = newRotation;
  1349. },
  1350. requestPresentationMode: function requestPresentationMode() {
  1351. if (!this.pdfPresentationMode) {
  1352. return;
  1353. }
  1354. this.pdfPresentationMode.request();
  1355. },
  1356. bindEvents: function bindEvents() {
  1357. var eventBus = this.eventBus,
  1358. _boundEvents = this._boundEvents;
  1359. _boundEvents.beforePrint = this.beforePrint.bind(this);
  1360. _boundEvents.afterPrint = this.afterPrint.bind(this);
  1361. eventBus.on('resize', webViewerResize);
  1362. eventBus.on('hashchange', webViewerHashchange);
  1363. eventBus.on('beforeprint', _boundEvents.beforePrint);
  1364. eventBus.on('afterprint', _boundEvents.afterPrint);
  1365. eventBus.on('pagerendered', webViewerPageRendered);
  1366. eventBus.on('textlayerrendered', webViewerTextLayerRendered);
  1367. eventBus.on('updateviewarea', webViewerUpdateViewarea);
  1368. eventBus.on('pagechanging', webViewerPageChanging);
  1369. eventBus.on('scalechanging', webViewerScaleChanging);
  1370. eventBus.on('rotationchanging', webViewerRotationChanging);
  1371. eventBus.on('sidebarviewchanged', webViewerSidebarViewChanged);
  1372. eventBus.on('pagemode', webViewerPageMode);
  1373. eventBus.on('namedaction', webViewerNamedAction);
  1374. eventBus.on('presentationmodechanged', webViewerPresentationModeChanged);
  1375. eventBus.on('presentationmode', webViewerPresentationMode);
  1376. eventBus.on('openfile', webViewerOpenFile);
  1377. eventBus.on('print', webViewerPrint);
  1378. eventBus.on('download', webViewerDownload);
  1379. eventBus.on('firstpage', webViewerFirstPage);
  1380. eventBus.on('lastpage', webViewerLastPage);
  1381. eventBus.on('nextpage', webViewerNextPage);
  1382. eventBus.on('previouspage', webViewerPreviousPage);
  1383. eventBus.on('zoomin', webViewerZoomIn);
  1384. eventBus.on('zoomout', webViewerZoomOut);
  1385. eventBus.on('pagenumberchanged', webViewerPageNumberChanged);
  1386. eventBus.on('scalechanged', webViewerScaleChanged);
  1387. eventBus.on('rotatecw', webViewerRotateCw);
  1388. eventBus.on('rotateccw', webViewerRotateCcw);
  1389. eventBus.on('switchscrollmode', webViewerSwitchScrollMode);
  1390. eventBus.on('scrollmodechanged', webViewerScrollModeChanged);
  1391. eventBus.on('switchspreadmode', webViewerSwitchSpreadMode);
  1392. eventBus.on('spreadmodechanged', webViewerSpreadModeChanged);
  1393. eventBus.on('documentproperties', webViewerDocumentProperties);
  1394. eventBus.on('find', webViewerFind);
  1395. eventBus.on('findfromurlhash', webViewerFindFromUrlHash);
  1396. eventBus.on('updatefindmatchescount', webViewerUpdateFindMatchesCount);
  1397. eventBus.on('updatefindcontrolstate', webViewerUpdateFindControlState);
  1398. eventBus.on('fileinputchange', webViewerFileInputChange);
  1399. },
  1400. bindWindowEvents: function bindWindowEvents() {
  1401. var eventBus = this.eventBus,
  1402. _boundEvents = this._boundEvents;
  1403. _boundEvents.windowResize = function () {
  1404. eventBus.dispatch('resize', {
  1405. source: window
  1406. });
  1407. };
  1408. _boundEvents.windowHashChange = function () {
  1409. eventBus.dispatch('hashchange', {
  1410. source: window,
  1411. hash: document.location.hash.substring(1)
  1412. });
  1413. };
  1414. _boundEvents.windowBeforePrint = function () {
  1415. eventBus.dispatch('beforeprint', {
  1416. source: window
  1417. });
  1418. };
  1419. _boundEvents.windowAfterPrint = function () {
  1420. eventBus.dispatch('afterprint', {
  1421. source: window
  1422. });
  1423. };
  1424. window.addEventListener('visibilitychange', webViewerVisibilityChange);
  1425. window.addEventListener('wheel', webViewerWheel);
  1426. window.addEventListener('click', webViewerClick);
  1427. window.addEventListener('keydown', webViewerKeyDown);
  1428. window.addEventListener('resize', _boundEvents.windowResize);
  1429. window.addEventListener('hashchange', _boundEvents.windowHashChange);
  1430. window.addEventListener('beforeprint', _boundEvents.windowBeforePrint);
  1431. window.addEventListener('afterprint', _boundEvents.windowAfterPrint);
  1432. },
  1433. unbindEvents: function unbindEvents() {
  1434. var eventBus = this.eventBus,
  1435. _boundEvents = this._boundEvents;
  1436. eventBus.off('resize', webViewerResize);
  1437. eventBus.off('hashchange', webViewerHashchange);
  1438. eventBus.off('beforeprint', _boundEvents.beforePrint);
  1439. eventBus.off('afterprint', _boundEvents.afterPrint);
  1440. eventBus.off('pagerendered', webViewerPageRendered);
  1441. eventBus.off('textlayerrendered', webViewerTextLayerRendered);
  1442. eventBus.off('updateviewarea', webViewerUpdateViewarea);
  1443. eventBus.off('pagechanging', webViewerPageChanging);
  1444. eventBus.off('scalechanging', webViewerScaleChanging);
  1445. eventBus.off('rotationchanging', webViewerRotationChanging);
  1446. eventBus.off('sidebarviewchanged', webViewerSidebarViewChanged);
  1447. eventBus.off('pagemode', webViewerPageMode);
  1448. eventBus.off('namedaction', webViewerNamedAction);
  1449. eventBus.off('presentationmodechanged', webViewerPresentationModeChanged);
  1450. eventBus.off('presentationmode', webViewerPresentationMode);
  1451. eventBus.off('openfile', webViewerOpenFile);
  1452. eventBus.off('print', webViewerPrint);
  1453. eventBus.off('download', webViewerDownload);
  1454. eventBus.off('firstpage', webViewerFirstPage);
  1455. eventBus.off('lastpage', webViewerLastPage);
  1456. eventBus.off('nextpage', webViewerNextPage);
  1457. eventBus.off('previouspage', webViewerPreviousPage);
  1458. eventBus.off('zoomin', webViewerZoomIn);
  1459. eventBus.off('zoomout', webViewerZoomOut);
  1460. eventBus.off('pagenumberchanged', webViewerPageNumberChanged);
  1461. eventBus.off('scalechanged', webViewerScaleChanged);
  1462. eventBus.off('rotatecw', webViewerRotateCw);
  1463. eventBus.off('rotateccw', webViewerRotateCcw);
  1464. eventBus.off('switchscrollmode', webViewerSwitchScrollMode);
  1465. eventBus.off('scrollmodechanged', webViewerScrollModeChanged);
  1466. eventBus.off('switchspreadmode', webViewerSwitchSpreadMode);
  1467. eventBus.off('spreadmodechanged', webViewerSpreadModeChanged);
  1468. eventBus.off('documentproperties', webViewerDocumentProperties);
  1469. eventBus.off('find', webViewerFind);
  1470. eventBus.off('findfromurlhash', webViewerFindFromUrlHash);
  1471. eventBus.off('updatefindmatchescount', webViewerUpdateFindMatchesCount);
  1472. eventBus.off('updatefindcontrolstate', webViewerUpdateFindControlState);
  1473. eventBus.off('fileinputchange', webViewerFileInputChange);
  1474. _boundEvents.beforePrint = null;
  1475. _boundEvents.afterPrint = null;
  1476. },
  1477. unbindWindowEvents: function unbindWindowEvents() {
  1478. var _boundEvents = this._boundEvents;
  1479. window.removeEventListener('visibilitychange', webViewerVisibilityChange);
  1480. window.removeEventListener('wheel', webViewerWheel);
  1481. window.removeEventListener('click', webViewerClick);
  1482. window.removeEventListener('keydown', webViewerKeyDown);
  1483. window.removeEventListener('resize', _boundEvents.windowResize);
  1484. window.removeEventListener('hashchange', _boundEvents.windowHashChange);
  1485. window.removeEventListener('beforeprint', _boundEvents.windowBeforePrint);
  1486. window.removeEventListener('afterprint', _boundEvents.windowAfterPrint);
  1487. _boundEvents.windowResize = null;
  1488. _boundEvents.windowHashChange = null;
  1489. _boundEvents.windowBeforePrint = null;
  1490. _boundEvents.windowAfterPrint = null;
  1491. }
  1492. };
  1493. exports.PDFViewerApplication = PDFViewerApplication;
  1494. var validateFileURL;
  1495. {
  1496. var HOSTED_VIEWER_ORIGINS = ['null', 'http://mozilla.github.io', 'https://mozilla.github.io'];
  1497. validateFileURL = function validateFileURL(file) {
  1498. if (file === undefined) {
  1499. return;
  1500. }
  1501. try {
  1502. var viewerOrigin = new _pdfjsLib.URL(window.location.href).origin || 'null';
  1503. if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
  1504. return;
  1505. }
  1506. var _ref8 = new _pdfjsLib.URL(file, window.location.href),
  1507. origin = _ref8.origin,
  1508. protocol = _ref8.protocol;
  1509. if (origin !== viewerOrigin && protocol !== 'blob:') {
  1510. throw new Error('file origin does not match viewer\'s');
  1511. }
  1512. } catch (ex) {
  1513. var message = ex && ex.message;
  1514. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (loadingErrorMessage) {
  1515. PDFViewerApplication.error(loadingErrorMessage, {
  1516. message: message
  1517. });
  1518. });
  1519. throw ex;
  1520. }
  1521. };
  1522. }
  1523. function loadFakeWorker() {
  1524. if (!_pdfjsLib.GlobalWorkerOptions.workerSrc) {
  1525. _pdfjsLib.GlobalWorkerOptions.workerSrc = _app_options.AppOptions.get('workerSrc');
  1526. }
  1527. return (0, _pdfjsLib.loadScript)(_pdfjsLib.PDFWorker.getWorkerSrc());
  1528. }
  1529. function loadAndEnablePDFBug(enabledTabs) {
  1530. var appConfig = PDFViewerApplication.appConfig;
  1531. return (0, _pdfjsLib.loadScript)(appConfig.debuggerScriptPath).then(function () {
  1532. PDFBug.enable(enabledTabs);
  1533. PDFBug.init({
  1534. OPS: _pdfjsLib.OPS,
  1535. createObjectURL: _pdfjsLib.createObjectURL
  1536. }, appConfig.mainContainer);
  1537. });
  1538. }
  1539. function webViewerInitialized() {
  1540. var appConfig = PDFViewerApplication.appConfig;
  1541. var file;
  1542. var queryString = document.location.search.substring(1);
  1543. var params = (0, _ui_utils.parseQueryString)(queryString);
  1544. file = 'file' in params ? params.file : _app_options.AppOptions.get('defaultUrl');
  1545. validateFileURL(file);
  1546. var fileInput = document.createElement('input');
  1547. fileInput.id = appConfig.openFileInputName;
  1548. fileInput.className = 'fileInput';
  1549. fileInput.setAttribute('type', 'file');
  1550. fileInput.oncontextmenu = _ui_utils.noContextMenuHandler;
  1551. document.body.appendChild(fileInput);
  1552. if (!window.File || !window.FileReader || !window.FileList || !window.Blob) {
  1553. appConfig.toolbar.openFile.setAttribute('hidden', 'true');
  1554. appConfig.secondaryToolbar.openFileButton.setAttribute('hidden', 'true');
  1555. } else {
  1556. fileInput.value = null;
  1557. }
  1558. fileInput.addEventListener('change', function (evt) {
  1559. var files = evt.target.files;
  1560. if (!files || files.length === 0) {
  1561. return;
  1562. }
  1563. PDFViewerApplication.eventBus.dispatch('fileinputchange', {
  1564. source: this,
  1565. fileInput: evt.target
  1566. });
  1567. });
  1568. appConfig.mainContainer.addEventListener('dragover', function (evt) {
  1569. evt.preventDefault();
  1570. evt.dataTransfer.dropEffect = 'move';
  1571. });
  1572. appConfig.mainContainer.addEventListener('drop', function (evt) {
  1573. evt.preventDefault();
  1574. var files = evt.dataTransfer.files;
  1575. if (!files || files.length === 0) {
  1576. return;
  1577. }
  1578. PDFViewerApplication.eventBus.dispatch('fileinputchange', {
  1579. source: this,
  1580. fileInput: evt.dataTransfer
  1581. });
  1582. });
  1583. if (!PDFViewerApplication.supportsPrinting) {
  1584. appConfig.toolbar.print.classList.add('hidden');
  1585. appConfig.secondaryToolbar.printButton.classList.add('hidden');
  1586. }
  1587. if (!PDFViewerApplication.supportsFullscreen) {
  1588. appConfig.toolbar.presentationModeButton.classList.add('hidden');
  1589. appConfig.secondaryToolbar.presentationModeButton.classList.add('hidden');
  1590. }
  1591. if (PDFViewerApplication.supportsIntegratedFind) {
  1592. appConfig.toolbar.viewFind.classList.add('hidden');
  1593. }
  1594. appConfig.mainContainer.addEventListener('transitionend', function (evt) {
  1595. if (evt.target === this) {
  1596. PDFViewerApplication.eventBus.dispatch('resize', {
  1597. source: this
  1598. });
  1599. }
  1600. }, true);
  1601. appConfig.sidebar.toggleButton.addEventListener('click', function () {
  1602. PDFViewerApplication.pdfSidebar.toggle();
  1603. });
  1604. try {
  1605. webViewerOpenFileViaURL(file);
  1606. } catch (reason) {
  1607. PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
  1608. PDFViewerApplication.error(msg, reason);
  1609. });
  1610. }
  1611. }
  1612. var webViewerOpenFileViaURL;
  1613. {
  1614. webViewerOpenFileViaURL = function webViewerOpenFileViaURL(file) {
  1615. if (file && file.lastIndexOf('file:', 0) === 0) {
  1616. PDFViewerApplication.setTitleUsingUrl(file);
  1617. var xhr = new XMLHttpRequest();
  1618. xhr.onload = function () {
  1619. PDFViewerApplication.open(new Uint8Array(xhr.response));
  1620. };
  1621. xhr.open('GET', file);
  1622. xhr.responseType = 'arraybuffer';
  1623. xhr.send();
  1624. return;
  1625. }
  1626. if (file) {
  1627. PDFViewerApplication.open(file);
  1628. }
  1629. };
  1630. }
  1631. function webViewerPageRendered(evt) {
  1632. var pageNumber = evt.pageNumber;
  1633. var pageIndex = pageNumber - 1;
  1634. var pageView = PDFViewerApplication.pdfViewer.getPageView(pageIndex);
  1635. if (pageNumber === PDFViewerApplication.page) {
  1636. PDFViewerApplication.toolbar.updateLoadingIndicatorState(false);
  1637. }
  1638. if (!pageView) {
  1639. return;
  1640. }
  1641. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1642. var thumbnailView = PDFViewerApplication.pdfThumbnailViewer.getThumbnail(pageIndex);
  1643. thumbnailView.setImage(pageView);
  1644. }
  1645. if (typeof Stats !== 'undefined' && Stats.enabled && pageView.stats) {
  1646. Stats.add(pageNumber, pageView.stats);
  1647. }
  1648. if (pageView.error) {
  1649. PDFViewerApplication.l10n.get('rendering_error', null, 'An error occurred while rendering the page.').then(function (msg) {
  1650. PDFViewerApplication.error(msg, pageView.error);
  1651. });
  1652. }
  1653. }
  1654. function webViewerTextLayerRendered(evt) {}
  1655. function webViewerPageMode(evt) {
  1656. var mode = evt.mode,
  1657. view;
  1658. switch (mode) {
  1659. case 'thumbs':
  1660. view = _pdf_sidebar.SidebarView.THUMBS;
  1661. break;
  1662. case 'bookmarks':
  1663. case 'outline':
  1664. view = _pdf_sidebar.SidebarView.OUTLINE;
  1665. break;
  1666. case 'attachments':
  1667. view = _pdf_sidebar.SidebarView.ATTACHMENTS;
  1668. break;
  1669. case 'none':
  1670. view = _pdf_sidebar.SidebarView.NONE;
  1671. break;
  1672. default:
  1673. console.error('Invalid "pagemode" hash parameter: ' + mode);
  1674. return;
  1675. }
  1676. PDFViewerApplication.pdfSidebar.switchView(view, true);
  1677. }
  1678. function webViewerNamedAction(evt) {
  1679. var action = evt.action;
  1680. switch (action) {
  1681. case 'GoToPage':
  1682. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  1683. break;
  1684. case 'Find':
  1685. if (!PDFViewerApplication.supportsIntegratedFind) {
  1686. PDFViewerApplication.findBar.toggle();
  1687. }
  1688. break;
  1689. }
  1690. }
  1691. function webViewerPresentationModeChanged(evt) {
  1692. var active = evt.active,
  1693. switchInProgress = evt.switchInProgress;
  1694. PDFViewerApplication.pdfViewer.presentationModeState = switchInProgress ? _ui_utils.PresentationModeState.CHANGING : active ? _ui_utils.PresentationModeState.FULLSCREEN : _ui_utils.PresentationModeState.NORMAL;
  1695. }
  1696. function webViewerSidebarViewChanged(evt) {
  1697. PDFViewerApplication.pdfRenderingQueue.isThumbnailViewEnabled = PDFViewerApplication.pdfSidebar.isThumbnailViewVisible;
  1698. var store = PDFViewerApplication.store;
  1699. if (store && PDFViewerApplication.isInitialViewSet) {
  1700. store.set('sidebarView', evt.view).catch(function () {});
  1701. }
  1702. }
  1703. function webViewerUpdateViewarea(evt) {
  1704. var location = evt.location,
  1705. store = PDFViewerApplication.store;
  1706. if (store && PDFViewerApplication.isInitialViewSet) {
  1707. store.setMultiple({
  1708. 'page': location.pageNumber,
  1709. 'zoom': location.scale,
  1710. 'scrollLeft': location.left,
  1711. 'scrollTop': location.top,
  1712. 'rotation': location.rotation
  1713. }).catch(function () {});
  1714. }
  1715. var href = PDFViewerApplication.pdfLinkService.getAnchorUrl(location.pdfOpenParams);
  1716. PDFViewerApplication.appConfig.toolbar.viewBookmark.href = href;
  1717. PDFViewerApplication.appConfig.secondaryToolbar.viewBookmarkButton.href = href;
  1718. var currentPage = PDFViewerApplication.pdfViewer.getPageView(PDFViewerApplication.page - 1);
  1719. var loading = currentPage.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED;
  1720. PDFViewerApplication.toolbar.updateLoadingIndicatorState(loading);
  1721. }
  1722. function webViewerScrollModeChanged(evt) {
  1723. var store = PDFViewerApplication.store;
  1724. if (store && PDFViewerApplication.isInitialViewSet) {
  1725. store.set('scrollMode', evt.mode).catch(function () {});
  1726. }
  1727. }
  1728. function webViewerSpreadModeChanged(evt) {
  1729. var store = PDFViewerApplication.store;
  1730. if (store && PDFViewerApplication.isInitialViewSet) {
  1731. store.set('spreadMode', evt.mode).catch(function () {});
  1732. }
  1733. }
  1734. function webViewerResize() {
  1735. var pdfDocument = PDFViewerApplication.pdfDocument,
  1736. pdfViewer = PDFViewerApplication.pdfViewer;
  1737. if (!pdfDocument) {
  1738. return;
  1739. }
  1740. var currentScaleValue = pdfViewer.currentScaleValue;
  1741. if (currentScaleValue === 'auto' || currentScaleValue === 'page-fit' || currentScaleValue === 'page-width') {
  1742. pdfViewer.currentScaleValue = currentScaleValue;
  1743. }
  1744. pdfViewer.update();
  1745. }
  1746. function webViewerHashchange(evt) {
  1747. var hash = evt.hash;
  1748. if (!hash) {
  1749. return;
  1750. }
  1751. if (!PDFViewerApplication.isInitialViewSet) {
  1752. PDFViewerApplication.initialBookmark = hash;
  1753. } else if (!PDFViewerApplication.pdfHistory.popStateInProgress) {
  1754. PDFViewerApplication.pdfLinkService.setHash(hash);
  1755. }
  1756. }
  1757. var webViewerFileInputChange;
  1758. {
  1759. webViewerFileInputChange = function webViewerFileInputChange(evt) {
  1760. if (PDFViewerApplication.pdfViewer && PDFViewerApplication.pdfViewer.isInPresentationMode) {
  1761. return;
  1762. }
  1763. var file = evt.fileInput.files[0];
  1764. if (_pdfjsLib.URL.createObjectURL && !_app_options.AppOptions.get('disableCreateObjectURL')) {
  1765. var url = _pdfjsLib.URL.createObjectURL(file);
  1766. if (file.name) {
  1767. url = {
  1768. url: url,
  1769. originalUrl: file.name
  1770. };
  1771. }
  1772. PDFViewerApplication.open(url);
  1773. } else {
  1774. PDFViewerApplication.setTitleUsingUrl(file.name);
  1775. var fileReader = new FileReader();
  1776. fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
  1777. var buffer = evt.target.result;
  1778. PDFViewerApplication.open(new Uint8Array(buffer));
  1779. };
  1780. fileReader.readAsArrayBuffer(file);
  1781. }
  1782. var appConfig = PDFViewerApplication.appConfig;
  1783. appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
  1784. appConfig.secondaryToolbar.viewBookmarkButton.setAttribute('hidden', 'true');
  1785. appConfig.toolbar.download.setAttribute('hidden', 'true');
  1786. appConfig.secondaryToolbar.downloadButton.setAttribute('hidden', 'true');
  1787. };
  1788. }
  1789. function webViewerPresentationMode() {
  1790. PDFViewerApplication.requestPresentationMode();
  1791. }
  1792. function webViewerOpenFile() {
  1793. var openFileInputName = PDFViewerApplication.appConfig.openFileInputName;
  1794. document.getElementById(openFileInputName).click();
  1795. }
  1796. function webViewerPrint() {
  1797. window.print();
  1798. }
  1799. function webViewerDownload() {
  1800. PDFViewerApplication.download();
  1801. }
  1802. function webViewerFirstPage() {
  1803. if (PDFViewerApplication.pdfDocument) {
  1804. PDFViewerApplication.page = 1;
  1805. }
  1806. }
  1807. function webViewerLastPage() {
  1808. if (PDFViewerApplication.pdfDocument) {
  1809. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  1810. }
  1811. }
  1812. function webViewerNextPage() {
  1813. PDFViewerApplication.page++;
  1814. }
  1815. function webViewerPreviousPage() {
  1816. PDFViewerApplication.page--;
  1817. }
  1818. function webViewerZoomIn() {
  1819. PDFViewerApplication.zoomIn();
  1820. }
  1821. function webViewerZoomOut() {
  1822. PDFViewerApplication.zoomOut();
  1823. }
  1824. function webViewerPageNumberChanged(evt) {
  1825. var pdfViewer = PDFViewerApplication.pdfViewer;
  1826. if (evt.value !== '') {
  1827. pdfViewer.currentPageLabel = evt.value;
  1828. }
  1829. if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) {
  1830. PDFViewerApplication.toolbar.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel);
  1831. }
  1832. }
  1833. function webViewerScaleChanged(evt) {
  1834. PDFViewerApplication.pdfViewer.currentScaleValue = evt.value;
  1835. }
  1836. function webViewerRotateCw() {
  1837. PDFViewerApplication.rotatePages(90);
  1838. }
  1839. function webViewerRotateCcw() {
  1840. PDFViewerApplication.rotatePages(-90);
  1841. }
  1842. function webViewerSwitchScrollMode(evt) {
  1843. PDFViewerApplication.pdfViewer.scrollMode = evt.mode;
  1844. }
  1845. function webViewerSwitchSpreadMode(evt) {
  1846. PDFViewerApplication.pdfViewer.spreadMode = evt.mode;
  1847. }
  1848. function webViewerDocumentProperties() {
  1849. PDFViewerApplication.pdfDocumentProperties.open();
  1850. }
  1851. function webViewerFind(evt) {
  1852. PDFViewerApplication.findController.executeCommand('find' + evt.type, {
  1853. query: evt.query,
  1854. phraseSearch: evt.phraseSearch,
  1855. caseSensitive: evt.caseSensitive,
  1856. entireWord: evt.entireWord,
  1857. highlightAll: evt.highlightAll,
  1858. findPrevious: evt.findPrevious
  1859. });
  1860. }
  1861. function webViewerFindFromUrlHash(evt) {
  1862. PDFViewerApplication.findController.executeCommand('find', {
  1863. query: evt.query,
  1864. phraseSearch: evt.phraseSearch,
  1865. caseSensitive: false,
  1866. entireWord: false,
  1867. highlightAll: true,
  1868. findPrevious: false
  1869. });
  1870. }
  1871. function webViewerUpdateFindMatchesCount(_ref9) {
  1872. var matchesCount = _ref9.matchesCount;
  1873. if (PDFViewerApplication.supportsIntegratedFind) {
  1874. PDFViewerApplication.externalServices.updateFindMatchesCount(matchesCount);
  1875. } else {
  1876. PDFViewerApplication.findBar.updateResultsCount(matchesCount);
  1877. }
  1878. }
  1879. function webViewerUpdateFindControlState(_ref10) {
  1880. var state = _ref10.state,
  1881. previous = _ref10.previous,
  1882. matchesCount = _ref10.matchesCount;
  1883. if (PDFViewerApplication.supportsIntegratedFind) {
  1884. PDFViewerApplication.externalServices.updateFindControlState({
  1885. result: state,
  1886. findPrevious: previous,
  1887. matchesCount: matchesCount
  1888. });
  1889. } else {
  1890. PDFViewerApplication.findBar.updateUIState(state, previous, matchesCount);
  1891. }
  1892. }
  1893. function webViewerScaleChanging(evt) {
  1894. PDFViewerApplication.toolbar.setPageScale(evt.presetValue, evt.scale);
  1895. PDFViewerApplication.pdfViewer.update();
  1896. }
  1897. function webViewerRotationChanging(evt) {
  1898. PDFViewerApplication.pdfThumbnailViewer.pagesRotation = evt.pagesRotation;
  1899. PDFViewerApplication.forceRendering();
  1900. PDFViewerApplication.pdfViewer.currentPageNumber = evt.pageNumber;
  1901. }
  1902. function webViewerPageChanging(evt) {
  1903. var page = evt.pageNumber;
  1904. PDFViewerApplication.toolbar.setPageNumber(page, evt.pageLabel || null);
  1905. PDFViewerApplication.secondaryToolbar.setPageNumber(page);
  1906. if (PDFViewerApplication.pdfSidebar.isThumbnailViewVisible) {
  1907. PDFViewerApplication.pdfThumbnailViewer.scrollThumbnailIntoView(page);
  1908. }
  1909. if (typeof Stats !== 'undefined' && Stats.enabled) {
  1910. var pageView = PDFViewerApplication.pdfViewer.getPageView(page - 1);
  1911. if (pageView && pageView.stats) {
  1912. Stats.add(page, pageView.stats);
  1913. }
  1914. }
  1915. }
  1916. function webViewerVisibilityChange(evt) {
  1917. if (document.visibilityState === 'visible') {
  1918. setZoomDisabledTimeout();
  1919. }
  1920. }
  1921. var zoomDisabledTimeout = null;
  1922. function setZoomDisabledTimeout() {
  1923. if (zoomDisabledTimeout) {
  1924. clearTimeout(zoomDisabledTimeout);
  1925. }
  1926. zoomDisabledTimeout = setTimeout(function () {
  1927. zoomDisabledTimeout = null;
  1928. }, WHEEL_ZOOM_DISABLED_TIMEOUT);
  1929. }
  1930. function webViewerWheel(evt) {
  1931. var pdfViewer = PDFViewerApplication.pdfViewer;
  1932. if (pdfViewer.isInPresentationMode) {
  1933. return;
  1934. }
  1935. if (evt.ctrlKey || evt.metaKey) {
  1936. var support = PDFViewerApplication.supportedMouseWheelZoomModifierKeys;
  1937. if (evt.ctrlKey && !support.ctrlKey || evt.metaKey && !support.metaKey) {
  1938. return;
  1939. }
  1940. evt.preventDefault();
  1941. if (zoomDisabledTimeout || document.visibilityState === 'hidden') {
  1942. return;
  1943. }
  1944. var previousScale = pdfViewer.currentScale;
  1945. var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  1946. var MOUSE_WHEEL_DELTA_PER_PAGE_SCALE = 3.0;
  1947. var ticks = delta * MOUSE_WHEEL_DELTA_PER_PAGE_SCALE;
  1948. if (ticks < 0) {
  1949. PDFViewerApplication.zoomOut(-ticks);
  1950. } else {
  1951. PDFViewerApplication.zoomIn(ticks);
  1952. }
  1953. var currentScale = pdfViewer.currentScale;
  1954. if (previousScale !== currentScale) {
  1955. var scaleCorrectionFactor = currentScale / previousScale - 1;
  1956. var rect = pdfViewer.container.getBoundingClientRect();
  1957. var dx = evt.clientX - rect.left;
  1958. var dy = evt.clientY - rect.top;
  1959. pdfViewer.container.scrollLeft += dx * scaleCorrectionFactor;
  1960. pdfViewer.container.scrollTop += dy * scaleCorrectionFactor;
  1961. }
  1962. } else {
  1963. setZoomDisabledTimeout();
  1964. }
  1965. }
  1966. function webViewerClick(evt) {
  1967. if (!PDFViewerApplication.secondaryToolbar.isOpen) {
  1968. return;
  1969. }
  1970. var appConfig = PDFViewerApplication.appConfig;
  1971. if (PDFViewerApplication.pdfViewer.containsElement(evt.target) || appConfig.toolbar.container.contains(evt.target) && evt.target !== appConfig.secondaryToolbar.toggleButton) {
  1972. PDFViewerApplication.secondaryToolbar.close();
  1973. }
  1974. }
  1975. function webViewerKeyDown(evt) {
  1976. if (PDFViewerApplication.overlayManager.active) {
  1977. return;
  1978. }
  1979. var handled = false,
  1980. ensureViewerFocused = false;
  1981. var cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0);
  1982. var pdfViewer = PDFViewerApplication.pdfViewer;
  1983. var isViewerInPresentationMode = pdfViewer && pdfViewer.isInPresentationMode;
  1984. if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) {
  1985. switch (evt.keyCode) {
  1986. case 70:
  1987. if (!PDFViewerApplication.supportsIntegratedFind) {
  1988. PDFViewerApplication.findBar.open();
  1989. handled = true;
  1990. }
  1991. break;
  1992. case 71:
  1993. if (!PDFViewerApplication.supportsIntegratedFind) {
  1994. var findState = PDFViewerApplication.findController.state;
  1995. if (findState) {
  1996. PDFViewerApplication.findController.executeCommand('findagain', {
  1997. query: findState.query,
  1998. phraseSearch: findState.phraseSearch,
  1999. caseSensitive: findState.caseSensitive,
  2000. entireWord: findState.entireWord,
  2001. highlightAll: findState.highlightAll,
  2002. findPrevious: cmd === 5 || cmd === 12
  2003. });
  2004. }
  2005. handled = true;
  2006. }
  2007. break;
  2008. case 61:
  2009. case 107:
  2010. case 187:
  2011. case 171:
  2012. if (!isViewerInPresentationMode) {
  2013. PDFViewerApplication.zoomIn();
  2014. }
  2015. handled = true;
  2016. break;
  2017. case 173:
  2018. case 109:
  2019. case 189:
  2020. if (!isViewerInPresentationMode) {
  2021. PDFViewerApplication.zoomOut();
  2022. }
  2023. handled = true;
  2024. break;
  2025. case 48:
  2026. case 96:
  2027. if (!isViewerInPresentationMode) {
  2028. setTimeout(function () {
  2029. pdfViewer.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  2030. });
  2031. handled = false;
  2032. }
  2033. break;
  2034. case 38:
  2035. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2036. PDFViewerApplication.page = 1;
  2037. handled = true;
  2038. ensureViewerFocused = true;
  2039. }
  2040. break;
  2041. case 40:
  2042. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2043. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2044. handled = true;
  2045. ensureViewerFocused = true;
  2046. }
  2047. break;
  2048. }
  2049. }
  2050. if (cmd === 1 || cmd === 8) {
  2051. switch (evt.keyCode) {
  2052. case 83:
  2053. PDFViewerApplication.download();
  2054. handled = true;
  2055. break;
  2056. }
  2057. }
  2058. if (cmd === 3 || cmd === 10) {
  2059. switch (evt.keyCode) {
  2060. case 80:
  2061. PDFViewerApplication.requestPresentationMode();
  2062. handled = true;
  2063. break;
  2064. case 71:
  2065. PDFViewerApplication.appConfig.toolbar.pageNumber.select();
  2066. handled = true;
  2067. break;
  2068. }
  2069. }
  2070. if (handled) {
  2071. if (ensureViewerFocused && !isViewerInPresentationMode) {
  2072. pdfViewer.focus();
  2073. }
  2074. evt.preventDefault();
  2075. return;
  2076. }
  2077. var curElement = document.activeElement || document.querySelector(':focus');
  2078. var curElementTagName = curElement && curElement.tagName.toUpperCase();
  2079. if (curElementTagName === 'INPUT' || curElementTagName === 'TEXTAREA' || curElementTagName === 'SELECT') {
  2080. if (evt.keyCode !== 27) {
  2081. return;
  2082. }
  2083. }
  2084. if (cmd === 0) {
  2085. var turnPage = 0,
  2086. turnOnlyIfPageFit = false;
  2087. switch (evt.keyCode) {
  2088. case 38:
  2089. case 33:
  2090. if (pdfViewer.isVerticalScrollbarEnabled) {
  2091. turnOnlyIfPageFit = true;
  2092. }
  2093. turnPage = -1;
  2094. break;
  2095. case 8:
  2096. if (!isViewerInPresentationMode) {
  2097. turnOnlyIfPageFit = true;
  2098. }
  2099. turnPage = -1;
  2100. break;
  2101. case 37:
  2102. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2103. turnOnlyIfPageFit = true;
  2104. }
  2105. case 75:
  2106. case 80:
  2107. turnPage = -1;
  2108. break;
  2109. case 27:
  2110. if (PDFViewerApplication.secondaryToolbar.isOpen) {
  2111. PDFViewerApplication.secondaryToolbar.close();
  2112. handled = true;
  2113. }
  2114. if (!PDFViewerApplication.supportsIntegratedFind && PDFViewerApplication.findBar.opened) {
  2115. PDFViewerApplication.findBar.close();
  2116. handled = true;
  2117. }
  2118. break;
  2119. case 40:
  2120. case 34:
  2121. if (pdfViewer.isVerticalScrollbarEnabled) {
  2122. turnOnlyIfPageFit = true;
  2123. }
  2124. turnPage = 1;
  2125. break;
  2126. case 13:
  2127. case 32:
  2128. if (!isViewerInPresentationMode) {
  2129. turnOnlyIfPageFit = true;
  2130. }
  2131. turnPage = 1;
  2132. break;
  2133. case 39:
  2134. if (pdfViewer.isHorizontalScrollbarEnabled) {
  2135. turnOnlyIfPageFit = true;
  2136. }
  2137. case 74:
  2138. case 78:
  2139. turnPage = 1;
  2140. break;
  2141. case 36:
  2142. if (isViewerInPresentationMode || PDFViewerApplication.page > 1) {
  2143. PDFViewerApplication.page = 1;
  2144. handled = true;
  2145. ensureViewerFocused = true;
  2146. }
  2147. break;
  2148. case 35:
  2149. if (isViewerInPresentationMode || PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2150. PDFViewerApplication.page = PDFViewerApplication.pagesCount;
  2151. handled = true;
  2152. ensureViewerFocused = true;
  2153. }
  2154. break;
  2155. case 83:
  2156. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.SELECT);
  2157. break;
  2158. case 72:
  2159. PDFViewerApplication.pdfCursorTools.switchTool(_pdf_cursor_tools.CursorTool.HAND);
  2160. break;
  2161. case 82:
  2162. PDFViewerApplication.rotatePages(90);
  2163. break;
  2164. case 115:
  2165. PDFViewerApplication.pdfSidebar.toggle();
  2166. break;
  2167. }
  2168. if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === 'page-fit')) {
  2169. if (turnPage > 0) {
  2170. if (PDFViewerApplication.page < PDFViewerApplication.pagesCount) {
  2171. PDFViewerApplication.page++;
  2172. }
  2173. } else {
  2174. if (PDFViewerApplication.page > 1) {
  2175. PDFViewerApplication.page--;
  2176. }
  2177. }
  2178. handled = true;
  2179. }
  2180. }
  2181. if (cmd === 4) {
  2182. switch (evt.keyCode) {
  2183. case 13:
  2184. case 32:
  2185. if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== 'page-fit') {
  2186. break;
  2187. }
  2188. if (PDFViewerApplication.page > 1) {
  2189. PDFViewerApplication.page--;
  2190. }
  2191. handled = true;
  2192. break;
  2193. case 82:
  2194. PDFViewerApplication.rotatePages(-90);
  2195. break;
  2196. }
  2197. }
  2198. if (!handled && !isViewerInPresentationMode) {
  2199. if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== 'BUTTON') {
  2200. ensureViewerFocused = true;
  2201. }
  2202. }
  2203. if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) {
  2204. pdfViewer.focus();
  2205. }
  2206. if (handled) {
  2207. evt.preventDefault();
  2208. }
  2209. }
  2210. function apiPageModeToSidebarView(mode) {
  2211. switch (mode) {
  2212. case 'UseNone':
  2213. return _pdf_sidebar.SidebarView.NONE;
  2214. case 'UseThumbs':
  2215. return _pdf_sidebar.SidebarView.THUMBS;
  2216. case 'UseOutlines':
  2217. return _pdf_sidebar.SidebarView.OUTLINE;
  2218. case 'UseAttachments':
  2219. return _pdf_sidebar.SidebarView.ATTACHMENTS;
  2220. case 'UseOC':
  2221. }
  2222. return _pdf_sidebar.SidebarView.NONE;
  2223. }
  2224. var PDFPrintServiceFactory = {
  2225. instance: {
  2226. supportsPrinting: false,
  2227. createPrintService: function createPrintService() {
  2228. throw new Error('Not implemented: createPrintService');
  2229. }
  2230. }
  2231. };
  2232. exports.PDFPrintServiceFactory = PDFPrintServiceFactory;
  2233. /***/ }),
  2234. /* 2 */
  2235. /***/ (function(module, exports, __webpack_require__) {
  2236. "use strict";
  2237. module.exports = __webpack_require__(3);
  2238. /***/ }),
  2239. /* 3 */
  2240. /***/ (function(module, exports, __webpack_require__) {
  2241. "use strict";
  2242. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  2243. var g = function () {
  2244. return this || (typeof self === "undefined" ? "undefined" : _typeof(self)) === "object" && self;
  2245. }() || Function("return this")();
  2246. var hadRuntime = g.regeneratorRuntime && Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime") >= 0;
  2247. var oldRuntime = hadRuntime && g.regeneratorRuntime;
  2248. g.regeneratorRuntime = undefined;
  2249. module.exports = __webpack_require__(4);
  2250. if (hadRuntime) {
  2251. g.regeneratorRuntime = oldRuntime;
  2252. } else {
  2253. try {
  2254. delete g.regeneratorRuntime;
  2255. } catch (e) {
  2256. g.regeneratorRuntime = undefined;
  2257. }
  2258. }
  2259. /***/ }),
  2260. /* 4 */
  2261. /***/ (function(module, exports, __webpack_require__) {
  2262. "use strict";
  2263. /* WEBPACK VAR INJECTION */(function(module) {
  2264. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  2265. !function (global) {
  2266. "use strict";
  2267. var Op = Object.prototype;
  2268. var hasOwn = Op.hasOwnProperty;
  2269. var undefined;
  2270. var $Symbol = typeof Symbol === "function" ? Symbol : {};
  2271. var iteratorSymbol = $Symbol.iterator || "@@iterator";
  2272. var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
  2273. var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  2274. var inModule = ( false ? undefined : _typeof(module)) === "object";
  2275. var runtime = global.regeneratorRuntime;
  2276. if (runtime) {
  2277. if (inModule) {
  2278. module.exports = runtime;
  2279. }
  2280. return;
  2281. }
  2282. runtime = global.regeneratorRuntime = inModule ? module.exports : {};
  2283. function wrap(innerFn, outerFn, self, tryLocsList) {
  2284. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
  2285. var generator = Object.create(protoGenerator.prototype);
  2286. var context = new Context(tryLocsList || []);
  2287. generator._invoke = makeInvokeMethod(innerFn, self, context);
  2288. return generator;
  2289. }
  2290. runtime.wrap = wrap;
  2291. function tryCatch(fn, obj, arg) {
  2292. try {
  2293. return {
  2294. type: "normal",
  2295. arg: fn.call(obj, arg)
  2296. };
  2297. } catch (err) {
  2298. return {
  2299. type: "throw",
  2300. arg: err
  2301. };
  2302. }
  2303. }
  2304. var GenStateSuspendedStart = "suspendedStart";
  2305. var GenStateSuspendedYield = "suspendedYield";
  2306. var GenStateExecuting = "executing";
  2307. var GenStateCompleted = "completed";
  2308. var ContinueSentinel = {};
  2309. function Generator() {}
  2310. function GeneratorFunction() {}
  2311. function GeneratorFunctionPrototype() {}
  2312. var IteratorPrototype = {};
  2313. IteratorPrototype[iteratorSymbol] = function () {
  2314. return this;
  2315. };
  2316. var getProto = Object.getPrototypeOf;
  2317. var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  2318. if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
  2319. IteratorPrototype = NativeIteratorPrototype;
  2320. }
  2321. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  2322. GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
  2323. GeneratorFunctionPrototype.constructor = GeneratorFunction;
  2324. GeneratorFunctionPrototype[toStringTagSymbol] = GeneratorFunction.displayName = "GeneratorFunction";
  2325. function defineIteratorMethods(prototype) {
  2326. ["next", "throw", "return"].forEach(function (method) {
  2327. prototype[method] = function (arg) {
  2328. return this._invoke(method, arg);
  2329. };
  2330. });
  2331. }
  2332. runtime.isGeneratorFunction = function (genFun) {
  2333. var ctor = typeof genFun === "function" && genFun.constructor;
  2334. return ctor ? ctor === GeneratorFunction || (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
  2335. };
  2336. runtime.mark = function (genFun) {
  2337. if (Object.setPrototypeOf) {
  2338. Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
  2339. } else {
  2340. genFun.__proto__ = GeneratorFunctionPrototype;
  2341. if (!(toStringTagSymbol in genFun)) {
  2342. genFun[toStringTagSymbol] = "GeneratorFunction";
  2343. }
  2344. }
  2345. genFun.prototype = Object.create(Gp);
  2346. return genFun;
  2347. };
  2348. runtime.awrap = function (arg) {
  2349. return {
  2350. __await: arg
  2351. };
  2352. };
  2353. function AsyncIterator(generator) {
  2354. function invoke(method, arg, resolve, reject) {
  2355. var record = tryCatch(generator[method], generator, arg);
  2356. if (record.type === "throw") {
  2357. reject(record.arg);
  2358. } else {
  2359. var result = record.arg;
  2360. var value = result.value;
  2361. if (value && _typeof(value) === "object" && hasOwn.call(value, "__await")) {
  2362. return Promise.resolve(value.__await).then(function (value) {
  2363. invoke("next", value, resolve, reject);
  2364. }, function (err) {
  2365. invoke("throw", err, resolve, reject);
  2366. });
  2367. }
  2368. return Promise.resolve(value).then(function (unwrapped) {
  2369. result.value = unwrapped;
  2370. resolve(result);
  2371. }, function (error) {
  2372. return invoke("throw", error, resolve, reject);
  2373. });
  2374. }
  2375. }
  2376. var previousPromise;
  2377. function enqueue(method, arg) {
  2378. function callInvokeWithMethodAndArg() {
  2379. return new Promise(function (resolve, reject) {
  2380. invoke(method, arg, resolve, reject);
  2381. });
  2382. }
  2383. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  2384. }
  2385. this._invoke = enqueue;
  2386. }
  2387. defineIteratorMethods(AsyncIterator.prototype);
  2388. AsyncIterator.prototype[asyncIteratorSymbol] = function () {
  2389. return this;
  2390. };
  2391. runtime.AsyncIterator = AsyncIterator;
  2392. runtime.async = function (innerFn, outerFn, self, tryLocsList) {
  2393. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList));
  2394. return runtime.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  2395. return result.done ? result.value : iter.next();
  2396. });
  2397. };
  2398. function makeInvokeMethod(innerFn, self, context) {
  2399. var state = GenStateSuspendedStart;
  2400. return function invoke(method, arg) {
  2401. if (state === GenStateExecuting) {
  2402. throw new Error("Generator is already running");
  2403. }
  2404. if (state === GenStateCompleted) {
  2405. if (method === "throw") {
  2406. throw arg;
  2407. }
  2408. return doneResult();
  2409. }
  2410. context.method = method;
  2411. context.arg = arg;
  2412. while (true) {
  2413. var delegate = context.delegate;
  2414. if (delegate) {
  2415. var delegateResult = maybeInvokeDelegate(delegate, context);
  2416. if (delegateResult) {
  2417. if (delegateResult === ContinueSentinel) continue;
  2418. return delegateResult;
  2419. }
  2420. }
  2421. if (context.method === "next") {
  2422. context.sent = context._sent = context.arg;
  2423. } else if (context.method === "throw") {
  2424. if (state === GenStateSuspendedStart) {
  2425. state = GenStateCompleted;
  2426. throw context.arg;
  2427. }
  2428. context.dispatchException(context.arg);
  2429. } else if (context.method === "return") {
  2430. context.abrupt("return", context.arg);
  2431. }
  2432. state = GenStateExecuting;
  2433. var record = tryCatch(innerFn, self, context);
  2434. if (record.type === "normal") {
  2435. state = context.done ? GenStateCompleted : GenStateSuspendedYield;
  2436. if (record.arg === ContinueSentinel) {
  2437. continue;
  2438. }
  2439. return {
  2440. value: record.arg,
  2441. done: context.done
  2442. };
  2443. } else if (record.type === "throw") {
  2444. state = GenStateCompleted;
  2445. context.method = "throw";
  2446. context.arg = record.arg;
  2447. }
  2448. }
  2449. };
  2450. }
  2451. function maybeInvokeDelegate(delegate, context) {
  2452. var method = delegate.iterator[context.method];
  2453. if (method === undefined) {
  2454. context.delegate = null;
  2455. if (context.method === "throw") {
  2456. if (delegate.iterator.return) {
  2457. context.method = "return";
  2458. context.arg = undefined;
  2459. maybeInvokeDelegate(delegate, context);
  2460. if (context.method === "throw") {
  2461. return ContinueSentinel;
  2462. }
  2463. }
  2464. context.method = "throw";
  2465. context.arg = new TypeError("The iterator does not provide a 'throw' method");
  2466. }
  2467. return ContinueSentinel;
  2468. }
  2469. var record = tryCatch(method, delegate.iterator, context.arg);
  2470. if (record.type === "throw") {
  2471. context.method = "throw";
  2472. context.arg = record.arg;
  2473. context.delegate = null;
  2474. return ContinueSentinel;
  2475. }
  2476. var info = record.arg;
  2477. if (!info) {
  2478. context.method = "throw";
  2479. context.arg = new TypeError("iterator result is not an object");
  2480. context.delegate = null;
  2481. return ContinueSentinel;
  2482. }
  2483. if (info.done) {
  2484. context[delegate.resultName] = info.value;
  2485. context.next = delegate.nextLoc;
  2486. if (context.method !== "return") {
  2487. context.method = "next";
  2488. context.arg = undefined;
  2489. }
  2490. } else {
  2491. return info;
  2492. }
  2493. context.delegate = null;
  2494. return ContinueSentinel;
  2495. }
  2496. defineIteratorMethods(Gp);
  2497. Gp[toStringTagSymbol] = "Generator";
  2498. Gp[iteratorSymbol] = function () {
  2499. return this;
  2500. };
  2501. Gp.toString = function () {
  2502. return "[object Generator]";
  2503. };
  2504. function pushTryEntry(locs) {
  2505. var entry = {
  2506. tryLoc: locs[0]
  2507. };
  2508. if (1 in locs) {
  2509. entry.catchLoc = locs[1];
  2510. }
  2511. if (2 in locs) {
  2512. entry.finallyLoc = locs[2];
  2513. entry.afterLoc = locs[3];
  2514. }
  2515. this.tryEntries.push(entry);
  2516. }
  2517. function resetTryEntry(entry) {
  2518. var record = entry.completion || {};
  2519. record.type = "normal";
  2520. delete record.arg;
  2521. entry.completion = record;
  2522. }
  2523. function Context(tryLocsList) {
  2524. this.tryEntries = [{
  2525. tryLoc: "root"
  2526. }];
  2527. tryLocsList.forEach(pushTryEntry, this);
  2528. this.reset(true);
  2529. }
  2530. runtime.keys = function (object) {
  2531. var keys = [];
  2532. for (var key in object) {
  2533. keys.push(key);
  2534. }
  2535. keys.reverse();
  2536. return function next() {
  2537. while (keys.length) {
  2538. var key = keys.pop();
  2539. if (key in object) {
  2540. next.value = key;
  2541. next.done = false;
  2542. return next;
  2543. }
  2544. }
  2545. next.done = true;
  2546. return next;
  2547. };
  2548. };
  2549. function values(iterable) {
  2550. if (iterable) {
  2551. var iteratorMethod = iterable[iteratorSymbol];
  2552. if (iteratorMethod) {
  2553. return iteratorMethod.call(iterable);
  2554. }
  2555. if (typeof iterable.next === "function") {
  2556. return iterable;
  2557. }
  2558. if (!isNaN(iterable.length)) {
  2559. var i = -1,
  2560. next = function next() {
  2561. while (++i < iterable.length) {
  2562. if (hasOwn.call(iterable, i)) {
  2563. next.value = iterable[i];
  2564. next.done = false;
  2565. return next;
  2566. }
  2567. }
  2568. next.value = undefined;
  2569. next.done = true;
  2570. return next;
  2571. };
  2572. return next.next = next;
  2573. }
  2574. }
  2575. return {
  2576. next: doneResult
  2577. };
  2578. }
  2579. runtime.values = values;
  2580. function doneResult() {
  2581. return {
  2582. value: undefined,
  2583. done: true
  2584. };
  2585. }
  2586. Context.prototype = {
  2587. constructor: Context,
  2588. reset: function reset(skipTempReset) {
  2589. this.prev = 0;
  2590. this.next = 0;
  2591. this.sent = this._sent = undefined;
  2592. this.done = false;
  2593. this.delegate = null;
  2594. this.method = "next";
  2595. this.arg = undefined;
  2596. this.tryEntries.forEach(resetTryEntry);
  2597. if (!skipTempReset) {
  2598. for (var name in this) {
  2599. if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
  2600. this[name] = undefined;
  2601. }
  2602. }
  2603. }
  2604. },
  2605. stop: function stop() {
  2606. this.done = true;
  2607. var rootEntry = this.tryEntries[0];
  2608. var rootRecord = rootEntry.completion;
  2609. if (rootRecord.type === "throw") {
  2610. throw rootRecord.arg;
  2611. }
  2612. return this.rval;
  2613. },
  2614. dispatchException: function dispatchException(exception) {
  2615. if (this.done) {
  2616. throw exception;
  2617. }
  2618. var context = this;
  2619. function handle(loc, caught) {
  2620. record.type = "throw";
  2621. record.arg = exception;
  2622. context.next = loc;
  2623. if (caught) {
  2624. context.method = "next";
  2625. context.arg = undefined;
  2626. }
  2627. return !!caught;
  2628. }
  2629. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  2630. var entry = this.tryEntries[i];
  2631. var record = entry.completion;
  2632. if (entry.tryLoc === "root") {
  2633. return handle("end");
  2634. }
  2635. if (entry.tryLoc <= this.prev) {
  2636. var hasCatch = hasOwn.call(entry, "catchLoc");
  2637. var hasFinally = hasOwn.call(entry, "finallyLoc");
  2638. if (hasCatch && hasFinally) {
  2639. if (this.prev < entry.catchLoc) {
  2640. return handle(entry.catchLoc, true);
  2641. } else if (this.prev < entry.finallyLoc) {
  2642. return handle(entry.finallyLoc);
  2643. }
  2644. } else if (hasCatch) {
  2645. if (this.prev < entry.catchLoc) {
  2646. return handle(entry.catchLoc, true);
  2647. }
  2648. } else if (hasFinally) {
  2649. if (this.prev < entry.finallyLoc) {
  2650. return handle(entry.finallyLoc);
  2651. }
  2652. } else {
  2653. throw new Error("try statement without catch or finally");
  2654. }
  2655. }
  2656. }
  2657. },
  2658. abrupt: function abrupt(type, arg) {
  2659. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  2660. var entry = this.tryEntries[i];
  2661. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  2662. var finallyEntry = entry;
  2663. break;
  2664. }
  2665. }
  2666. if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
  2667. finallyEntry = null;
  2668. }
  2669. var record = finallyEntry ? finallyEntry.completion : {};
  2670. record.type = type;
  2671. record.arg = arg;
  2672. if (finallyEntry) {
  2673. this.method = "next";
  2674. this.next = finallyEntry.finallyLoc;
  2675. return ContinueSentinel;
  2676. }
  2677. return this.complete(record);
  2678. },
  2679. complete: function complete(record, afterLoc) {
  2680. if (record.type === "throw") {
  2681. throw record.arg;
  2682. }
  2683. if (record.type === "break" || record.type === "continue") {
  2684. this.next = record.arg;
  2685. } else if (record.type === "return") {
  2686. this.rval = this.arg = record.arg;
  2687. this.method = "return";
  2688. this.next = "end";
  2689. } else if (record.type === "normal" && afterLoc) {
  2690. this.next = afterLoc;
  2691. }
  2692. return ContinueSentinel;
  2693. },
  2694. finish: function finish(finallyLoc) {
  2695. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  2696. var entry = this.tryEntries[i];
  2697. if (entry.finallyLoc === finallyLoc) {
  2698. this.complete(entry.completion, entry.afterLoc);
  2699. resetTryEntry(entry);
  2700. return ContinueSentinel;
  2701. }
  2702. }
  2703. },
  2704. "catch": function _catch(tryLoc) {
  2705. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  2706. var entry = this.tryEntries[i];
  2707. if (entry.tryLoc === tryLoc) {
  2708. var record = entry.completion;
  2709. if (record.type === "throw") {
  2710. var thrown = record.arg;
  2711. resetTryEntry(entry);
  2712. }
  2713. return thrown;
  2714. }
  2715. }
  2716. throw new Error("illegal catch attempt");
  2717. },
  2718. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  2719. this.delegate = {
  2720. iterator: values(iterable),
  2721. resultName: resultName,
  2722. nextLoc: nextLoc
  2723. };
  2724. if (this.method === "next") {
  2725. this.arg = undefined;
  2726. }
  2727. return ContinueSentinel;
  2728. }
  2729. };
  2730. }(function () {
  2731. return this || (typeof self === "undefined" ? "undefined" : _typeof(self)) === "object" && self;
  2732. }() || Function("return this")());
  2733. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(5)(module)))
  2734. /***/ }),
  2735. /* 5 */
  2736. /***/ (function(module, exports, __webpack_require__) {
  2737. "use strict";
  2738. module.exports = function (module) {
  2739. if (!module.webpackPolyfill) {
  2740. module.deprecate = function () {};
  2741. module.paths = [];
  2742. if (!module.children) module.children = [];
  2743. Object.defineProperty(module, "loaded", {
  2744. enumerable: true,
  2745. get: function get() {
  2746. return module.l;
  2747. }
  2748. });
  2749. Object.defineProperty(module, "id", {
  2750. enumerable: true,
  2751. get: function get() {
  2752. return module.i;
  2753. }
  2754. });
  2755. module.webpackPolyfill = 1;
  2756. }
  2757. return module;
  2758. };
  2759. /***/ }),
  2760. /* 6 */
  2761. /***/ (function(module, exports, __webpack_require__) {
  2762. "use strict";
  2763. Object.defineProperty(exports, "__esModule", {
  2764. value: true
  2765. });
  2766. exports.isValidRotation = isValidRotation;
  2767. exports.isValidScrollMode = isValidScrollMode;
  2768. exports.isValidSpreadMode = isValidSpreadMode;
  2769. exports.isPortraitOrientation = isPortraitOrientation;
  2770. exports.getGlobalEventBus = getGlobalEventBus;
  2771. exports.getPDFFileNameFromURL = getPDFFileNameFromURL;
  2772. exports.noContextMenuHandler = noContextMenuHandler;
  2773. exports.parseQueryString = parseQueryString;
  2774. exports.backtrackBeforeAllVisibleElements = backtrackBeforeAllVisibleElements;
  2775. exports.getVisibleElements = getVisibleElements;
  2776. exports.roundToDivide = roundToDivide;
  2777. exports.getPageSizeInches = getPageSizeInches;
  2778. exports.approximateFraction = approximateFraction;
  2779. exports.getOutputScale = getOutputScale;
  2780. exports.scrollIntoView = scrollIntoView;
  2781. exports.watchScroll = watchScroll;
  2782. exports.binarySearchFirstItem = binarySearchFirstItem;
  2783. exports.normalizeWheelEventDelta = normalizeWheelEventDelta;
  2784. exports.waitOnEventOrTimeout = waitOnEventOrTimeout;
  2785. exports.moveToEndOfArray = moveToEndOfArray;
  2786. exports.WaitOnType = exports.animationStarted = exports.ProgressBar = exports.EventBus = exports.NullL10n = exports.SpreadMode = exports.ScrollMode = exports.TextLayerMode = exports.RendererType = exports.PresentationModeState = exports.VERTICAL_PADDING = exports.SCROLLBAR_PADDING = exports.MAX_AUTO_SCALE = exports.UNKNOWN_SCALE = exports.MAX_SCALE = exports.MIN_SCALE = exports.DEFAULT_SCALE = exports.DEFAULT_SCALE_VALUE = exports.CSS_UNITS = void 0;
  2787. var _regenerator = _interopRequireDefault(__webpack_require__(2));
  2788. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  2789. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  2790. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  2791. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  2792. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  2793. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
  2794. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
  2795. 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; }
  2796. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  2797. 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); } }
  2798. 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); }); }; }
  2799. var CSS_UNITS = 96.0 / 72.0;
  2800. exports.CSS_UNITS = CSS_UNITS;
  2801. var DEFAULT_SCALE_VALUE = 'auto';
  2802. exports.DEFAULT_SCALE_VALUE = DEFAULT_SCALE_VALUE;
  2803. var DEFAULT_SCALE = 1.0;
  2804. exports.DEFAULT_SCALE = DEFAULT_SCALE;
  2805. var MIN_SCALE = 0.10;
  2806. exports.MIN_SCALE = MIN_SCALE;
  2807. var MAX_SCALE = 10.0;
  2808. exports.MAX_SCALE = MAX_SCALE;
  2809. var UNKNOWN_SCALE = 0;
  2810. exports.UNKNOWN_SCALE = UNKNOWN_SCALE;
  2811. var MAX_AUTO_SCALE = 1.25;
  2812. exports.MAX_AUTO_SCALE = MAX_AUTO_SCALE;
  2813. var SCROLLBAR_PADDING = 40;
  2814. exports.SCROLLBAR_PADDING = SCROLLBAR_PADDING;
  2815. var VERTICAL_PADDING = 5;
  2816. exports.VERTICAL_PADDING = VERTICAL_PADDING;
  2817. var PresentationModeState = {
  2818. UNKNOWN: 0,
  2819. NORMAL: 1,
  2820. CHANGING: 2,
  2821. FULLSCREEN: 3
  2822. };
  2823. exports.PresentationModeState = PresentationModeState;
  2824. var RendererType = {
  2825. CANVAS: 'canvas',
  2826. SVG: 'svg'
  2827. };
  2828. exports.RendererType = RendererType;
  2829. var TextLayerMode = {
  2830. DISABLE: 0,
  2831. ENABLE: 1,
  2832. ENABLE_ENHANCE: 2
  2833. };
  2834. exports.TextLayerMode = TextLayerMode;
  2835. var ScrollMode = {
  2836. UNKNOWN: -1,
  2837. VERTICAL: 0,
  2838. HORIZONTAL: 1,
  2839. WRAPPED: 2
  2840. };
  2841. exports.ScrollMode = ScrollMode;
  2842. var SpreadMode = {
  2843. UNKNOWN: -1,
  2844. NONE: 0,
  2845. ODD: 1,
  2846. EVEN: 2
  2847. };
  2848. exports.SpreadMode = SpreadMode;
  2849. function formatL10nValue(text, args) {
  2850. if (!args) {
  2851. return text;
  2852. }
  2853. return text.replace(/\{\{\s*(\w+)\s*\}\}/g, function (all, name) {
  2854. return name in args ? args[name] : '{{' + name + '}}';
  2855. });
  2856. }
  2857. var NullL10n = {
  2858. getLanguage: function () {
  2859. var _getLanguage = _asyncToGenerator(
  2860. /*#__PURE__*/
  2861. _regenerator.default.mark(function _callee() {
  2862. return _regenerator.default.wrap(function _callee$(_context) {
  2863. while (1) {
  2864. switch (_context.prev = _context.next) {
  2865. case 0:
  2866. return _context.abrupt("return", 'en-us');
  2867. case 1:
  2868. case "end":
  2869. return _context.stop();
  2870. }
  2871. }
  2872. }, _callee, this);
  2873. }));
  2874. function getLanguage() {
  2875. return _getLanguage.apply(this, arguments);
  2876. }
  2877. return getLanguage;
  2878. }(),
  2879. getDirection: function () {
  2880. var _getDirection = _asyncToGenerator(
  2881. /*#__PURE__*/
  2882. _regenerator.default.mark(function _callee2() {
  2883. return _regenerator.default.wrap(function _callee2$(_context2) {
  2884. while (1) {
  2885. switch (_context2.prev = _context2.next) {
  2886. case 0:
  2887. return _context2.abrupt("return", 'ltr');
  2888. case 1:
  2889. case "end":
  2890. return _context2.stop();
  2891. }
  2892. }
  2893. }, _callee2, this);
  2894. }));
  2895. function getDirection() {
  2896. return _getDirection.apply(this, arguments);
  2897. }
  2898. return getDirection;
  2899. }(),
  2900. get: function () {
  2901. var _get = _asyncToGenerator(
  2902. /*#__PURE__*/
  2903. _regenerator.default.mark(function _callee3(property, args, fallback) {
  2904. return _regenerator.default.wrap(function _callee3$(_context3) {
  2905. while (1) {
  2906. switch (_context3.prev = _context3.next) {
  2907. case 0:
  2908. return _context3.abrupt("return", formatL10nValue(fallback, args));
  2909. case 1:
  2910. case "end":
  2911. return _context3.stop();
  2912. }
  2913. }
  2914. }, _callee3, this);
  2915. }));
  2916. function get(_x, _x2, _x3) {
  2917. return _get.apply(this, arguments);
  2918. }
  2919. return get;
  2920. }(),
  2921. translate: function () {
  2922. var _translate = _asyncToGenerator(
  2923. /*#__PURE__*/
  2924. _regenerator.default.mark(function _callee4(element) {
  2925. return _regenerator.default.wrap(function _callee4$(_context4) {
  2926. while (1) {
  2927. switch (_context4.prev = _context4.next) {
  2928. case 0:
  2929. case "end":
  2930. return _context4.stop();
  2931. }
  2932. }
  2933. }, _callee4, this);
  2934. }));
  2935. function translate(_x4) {
  2936. return _translate.apply(this, arguments);
  2937. }
  2938. return translate;
  2939. }()
  2940. };
  2941. exports.NullL10n = NullL10n;
  2942. function getOutputScale(ctx) {
  2943. var devicePixelRatio = window.devicePixelRatio || 1;
  2944. var backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1;
  2945. var pixelRatio = devicePixelRatio / backingStoreRatio;
  2946. return {
  2947. sx: pixelRatio,
  2948. sy: pixelRatio,
  2949. scaled: pixelRatio !== 1
  2950. };
  2951. }
  2952. function scrollIntoView(element, spot) {
  2953. var skipOverflowHiddenElements = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  2954. var parent = element.offsetParent;
  2955. if (!parent) {
  2956. console.error('offsetParent is not set -- cannot scroll');
  2957. return;
  2958. }
  2959. var offsetY = element.offsetTop + element.clientTop;
  2960. var offsetX = element.offsetLeft + element.clientLeft;
  2961. while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || skipOverflowHiddenElements && getComputedStyle(parent).overflow === 'hidden') {
  2962. if (parent.dataset._scaleY) {
  2963. offsetY /= parent.dataset._scaleY;
  2964. offsetX /= parent.dataset._scaleX;
  2965. }
  2966. offsetY += parent.offsetTop;
  2967. offsetX += parent.offsetLeft;
  2968. parent = parent.offsetParent;
  2969. if (!parent) {
  2970. return;
  2971. }
  2972. }
  2973. if (spot) {
  2974. if (spot.top !== undefined) {
  2975. offsetY += spot.top;
  2976. }
  2977. if (spot.left !== undefined) {
  2978. offsetX += spot.left;
  2979. parent.scrollLeft = offsetX;
  2980. }
  2981. }
  2982. parent.scrollTop = offsetY;
  2983. }
  2984. function watchScroll(viewAreaElement, callback) {
  2985. var debounceScroll = function debounceScroll(evt) {
  2986. if (rAF) {
  2987. return;
  2988. }
  2989. rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
  2990. rAF = null;
  2991. var currentX = viewAreaElement.scrollLeft;
  2992. var lastX = state.lastX;
  2993. if (currentX !== lastX) {
  2994. state.right = currentX > lastX;
  2995. }
  2996. state.lastX = currentX;
  2997. var currentY = viewAreaElement.scrollTop;
  2998. var lastY = state.lastY;
  2999. if (currentY !== lastY) {
  3000. state.down = currentY > lastY;
  3001. }
  3002. state.lastY = currentY;
  3003. callback(state);
  3004. });
  3005. };
  3006. var state = {
  3007. right: true,
  3008. down: true,
  3009. lastX: viewAreaElement.scrollLeft,
  3010. lastY: viewAreaElement.scrollTop,
  3011. _eventHandler: debounceScroll
  3012. };
  3013. var rAF = null;
  3014. viewAreaElement.addEventListener('scroll', debounceScroll, true);
  3015. return state;
  3016. }
  3017. function parseQueryString(query) {
  3018. var parts = query.split('&');
  3019. var params = Object.create(null);
  3020. for (var i = 0, ii = parts.length; i < ii; ++i) {
  3021. var param = parts[i].split('=');
  3022. var key = param[0].toLowerCase();
  3023. var value = param.length > 1 ? param[1] : null;
  3024. params[decodeURIComponent(key)] = decodeURIComponent(value);
  3025. }
  3026. return params;
  3027. }
  3028. function binarySearchFirstItem(items, condition) {
  3029. var minIndex = 0;
  3030. var maxIndex = items.length - 1;
  3031. if (items.length === 0 || !condition(items[maxIndex])) {
  3032. return items.length;
  3033. }
  3034. if (condition(items[minIndex])) {
  3035. return minIndex;
  3036. }
  3037. while (minIndex < maxIndex) {
  3038. var currentIndex = minIndex + maxIndex >> 1;
  3039. var currentItem = items[currentIndex];
  3040. if (condition(currentItem)) {
  3041. maxIndex = currentIndex;
  3042. } else {
  3043. minIndex = currentIndex + 1;
  3044. }
  3045. }
  3046. return minIndex;
  3047. }
  3048. function approximateFraction(x) {
  3049. if (Math.floor(x) === x) {
  3050. return [x, 1];
  3051. }
  3052. var xinv = 1 / x;
  3053. var limit = 8;
  3054. if (xinv > limit) {
  3055. return [1, limit];
  3056. } else if (Math.floor(xinv) === xinv) {
  3057. return [1, xinv];
  3058. }
  3059. var x_ = x > 1 ? xinv : x;
  3060. var a = 0,
  3061. b = 1,
  3062. c = 1,
  3063. d = 1;
  3064. while (true) {
  3065. var p = a + c,
  3066. q = b + d;
  3067. if (q > limit) {
  3068. break;
  3069. }
  3070. if (x_ <= p / q) {
  3071. c = p;
  3072. d = q;
  3073. } else {
  3074. a = p;
  3075. b = q;
  3076. }
  3077. }
  3078. var result;
  3079. if (x_ - a / b < c / d - x_) {
  3080. result = x_ === x ? [a, b] : [b, a];
  3081. } else {
  3082. result = x_ === x ? [c, d] : [d, c];
  3083. }
  3084. return result;
  3085. }
  3086. function roundToDivide(x, div) {
  3087. var r = x % div;
  3088. return r === 0 ? x : Math.round(x - r + div);
  3089. }
  3090. function getPageSizeInches(_ref) {
  3091. var view = _ref.view,
  3092. userUnit = _ref.userUnit,
  3093. rotate = _ref.rotate;
  3094. var _view = _slicedToArray(view, 4),
  3095. x1 = _view[0],
  3096. y1 = _view[1],
  3097. x2 = _view[2],
  3098. y2 = _view[3];
  3099. var changeOrientation = rotate % 180 !== 0;
  3100. var width = (x2 - x1) / 72 * userUnit;
  3101. var height = (y2 - y1) / 72 * userUnit;
  3102. return {
  3103. width: changeOrientation ? height : width,
  3104. height: changeOrientation ? width : height
  3105. };
  3106. }
  3107. function backtrackBeforeAllVisibleElements(index, views, top) {
  3108. if (index < 2) {
  3109. return index;
  3110. }
  3111. var elt = views[index].div;
  3112. var pageTop = elt.offsetTop + elt.clientTop;
  3113. if (pageTop >= top) {
  3114. elt = views[index - 1].div;
  3115. pageTop = elt.offsetTop + elt.clientTop;
  3116. }
  3117. for (var i = index - 2; i >= 0; --i) {
  3118. elt = views[i].div;
  3119. if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) {
  3120. break;
  3121. }
  3122. index = i;
  3123. }
  3124. return index;
  3125. }
  3126. function getVisibleElements(scrollEl, views) {
  3127. var sortByVisibility = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  3128. var horizontal = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  3129. var top = scrollEl.scrollTop,
  3130. bottom = top + scrollEl.clientHeight;
  3131. var left = scrollEl.scrollLeft,
  3132. right = left + scrollEl.clientWidth;
  3133. function isElementBottomAfterViewTop(view) {
  3134. var element = view.div;
  3135. var elementBottom = element.offsetTop + element.clientTop + element.clientHeight;
  3136. return elementBottom > top;
  3137. }
  3138. function isElementRightAfterViewLeft(view) {
  3139. var element = view.div;
  3140. var elementRight = element.offsetLeft + element.clientLeft + element.clientWidth;
  3141. return elementRight > left;
  3142. }
  3143. var visible = [],
  3144. numViews = views.length;
  3145. var firstVisibleElementInd = numViews === 0 ? 0 : binarySearchFirstItem(views, horizontal ? isElementRightAfterViewLeft : isElementBottomAfterViewTop);
  3146. if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) {
  3147. firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top);
  3148. }
  3149. var lastEdge = horizontal ? right : -1;
  3150. for (var i = firstVisibleElementInd; i < numViews; i++) {
  3151. var view = views[i],
  3152. element = view.div;
  3153. var currentWidth = element.offsetLeft + element.clientLeft;
  3154. var currentHeight = element.offsetTop + element.clientTop;
  3155. var viewWidth = element.clientWidth,
  3156. viewHeight = element.clientHeight;
  3157. var viewRight = currentWidth + viewWidth;
  3158. var viewBottom = currentHeight + viewHeight;
  3159. if (lastEdge === -1) {
  3160. if (viewBottom >= bottom) {
  3161. lastEdge = viewBottom;
  3162. }
  3163. } else if ((horizontal ? currentWidth : currentHeight) > lastEdge) {
  3164. break;
  3165. }
  3166. if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) {
  3167. continue;
  3168. }
  3169. var hiddenHeight = Math.max(0, top - currentHeight) + Math.max(0, viewBottom - bottom);
  3170. var hiddenWidth = Math.max(0, left - currentWidth) + Math.max(0, viewRight - right);
  3171. var percent = (viewHeight - hiddenHeight) * (viewWidth - hiddenWidth) * 100 / viewHeight / viewWidth | 0;
  3172. visible.push({
  3173. id: view.id,
  3174. x: currentWidth,
  3175. y: currentHeight,
  3176. view: view,
  3177. percent: percent
  3178. });
  3179. }
  3180. var first = visible[0],
  3181. last = visible[visible.length - 1];
  3182. if (sortByVisibility) {
  3183. visible.sort(function (a, b) {
  3184. var pc = a.percent - b.percent;
  3185. if (Math.abs(pc) > 0.001) {
  3186. return -pc;
  3187. }
  3188. return a.id - b.id;
  3189. });
  3190. }
  3191. return {
  3192. first: first,
  3193. last: last,
  3194. views: visible
  3195. };
  3196. }
  3197. function noContextMenuHandler(evt) {
  3198. evt.preventDefault();
  3199. }
  3200. function isDataSchema(url) {
  3201. var i = 0,
  3202. ii = url.length;
  3203. while (i < ii && url[i].trim() === '') {
  3204. i++;
  3205. }
  3206. return url.substring(i, i + 5).toLowerCase() === 'data:';
  3207. }
  3208. function getPDFFileNameFromURL(url) {
  3209. var defaultFilename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'document.pdf';
  3210. if (typeof url !== 'string') {
  3211. return defaultFilename;
  3212. }
  3213. if (isDataSchema(url)) {
  3214. console.warn('getPDFFileNameFromURL: ' + 'ignoring "data:" URL for performance reasons.');
  3215. return defaultFilename;
  3216. }
  3217. var reURI = /^(?:(?:[^:]+:)?\/\/[^\/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
  3218. var reFilename = /[^\/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
  3219. var splitURI = reURI.exec(url);
  3220. var suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
  3221. if (suggestedFilename) {
  3222. suggestedFilename = suggestedFilename[0];
  3223. if (suggestedFilename.includes('%')) {
  3224. try {
  3225. suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
  3226. } catch (ex) {}
  3227. }
  3228. }
  3229. return suggestedFilename || defaultFilename;
  3230. }
  3231. function normalizeWheelEventDelta(evt) {
  3232. var delta = Math.sqrt(evt.deltaX * evt.deltaX + evt.deltaY * evt.deltaY);
  3233. var angle = Math.atan2(evt.deltaY, evt.deltaX);
  3234. if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) {
  3235. delta = -delta;
  3236. }
  3237. var MOUSE_DOM_DELTA_PIXEL_MODE = 0;
  3238. var MOUSE_DOM_DELTA_LINE_MODE = 1;
  3239. var MOUSE_PIXELS_PER_LINE = 30;
  3240. var MOUSE_LINES_PER_PAGE = 30;
  3241. if (evt.deltaMode === MOUSE_DOM_DELTA_PIXEL_MODE) {
  3242. delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE;
  3243. } else if (evt.deltaMode === MOUSE_DOM_DELTA_LINE_MODE) {
  3244. delta /= MOUSE_LINES_PER_PAGE;
  3245. }
  3246. return delta;
  3247. }
  3248. function isValidRotation(angle) {
  3249. return Number.isInteger(angle) && angle % 90 === 0;
  3250. }
  3251. function isValidScrollMode(mode) {
  3252. return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN;
  3253. }
  3254. function isValidSpreadMode(mode) {
  3255. return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN;
  3256. }
  3257. function isPortraitOrientation(size) {
  3258. return size.width <= size.height;
  3259. }
  3260. var WaitOnType = {
  3261. EVENT: 'event',
  3262. TIMEOUT: 'timeout'
  3263. };
  3264. exports.WaitOnType = WaitOnType;
  3265. function waitOnEventOrTimeout(_ref2) {
  3266. var target = _ref2.target,
  3267. name = _ref2.name,
  3268. _ref2$delay = _ref2.delay,
  3269. delay = _ref2$delay === void 0 ? 0 : _ref2$delay;
  3270. return new Promise(function (resolve, reject) {
  3271. if (_typeof(target) !== 'object' || !(name && typeof name === 'string') || !(Number.isInteger(delay) && delay >= 0)) {
  3272. throw new Error('waitOnEventOrTimeout - invalid parameters.');
  3273. }
  3274. function handler(type) {
  3275. if (target instanceof EventBus) {
  3276. target.off(name, eventHandler);
  3277. } else {
  3278. target.removeEventListener(name, eventHandler);
  3279. }
  3280. if (timeout) {
  3281. clearTimeout(timeout);
  3282. }
  3283. resolve(type);
  3284. }
  3285. var eventHandler = handler.bind(null, WaitOnType.EVENT);
  3286. if (target instanceof EventBus) {
  3287. target.on(name, eventHandler);
  3288. } else {
  3289. target.addEventListener(name, eventHandler);
  3290. }
  3291. var timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT);
  3292. var timeout = setTimeout(timeoutHandler, delay);
  3293. });
  3294. }
  3295. var animationStarted = new Promise(function (resolve) {
  3296. window.requestAnimationFrame(resolve);
  3297. });
  3298. exports.animationStarted = animationStarted;
  3299. var EventBus =
  3300. /*#__PURE__*/
  3301. function () {
  3302. function EventBus() {
  3303. var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  3304. _ref3$dispatchToDOM = _ref3.dispatchToDOM,
  3305. dispatchToDOM = _ref3$dispatchToDOM === void 0 ? false : _ref3$dispatchToDOM;
  3306. _classCallCheck(this, EventBus);
  3307. this._listeners = Object.create(null);
  3308. this._dispatchToDOM = dispatchToDOM === true;
  3309. }
  3310. _createClass(EventBus, [{
  3311. key: "on",
  3312. value: function on(eventName, listener) {
  3313. var eventListeners = this._listeners[eventName];
  3314. if (!eventListeners) {
  3315. eventListeners = [];
  3316. this._listeners[eventName] = eventListeners;
  3317. }
  3318. eventListeners.push(listener);
  3319. }
  3320. }, {
  3321. key: "off",
  3322. value: function off(eventName, listener) {
  3323. var eventListeners = this._listeners[eventName];
  3324. var i;
  3325. if (!eventListeners || (i = eventListeners.indexOf(listener)) < 0) {
  3326. return;
  3327. }
  3328. eventListeners.splice(i, 1);
  3329. }
  3330. }, {
  3331. key: "dispatch",
  3332. value: function dispatch(eventName) {
  3333. var eventListeners = this._listeners[eventName];
  3334. if (!eventListeners || eventListeners.length === 0) {
  3335. if (this._dispatchToDOM) {
  3336. var _args5 = Array.prototype.slice.call(arguments, 1);
  3337. this._dispatchDOMEvent(eventName, _args5);
  3338. }
  3339. return;
  3340. }
  3341. var args = Array.prototype.slice.call(arguments, 1);
  3342. eventListeners.slice(0).forEach(function (listener) {
  3343. listener.apply(null, args);
  3344. });
  3345. if (this._dispatchToDOM) {
  3346. this._dispatchDOMEvent(eventName, args);
  3347. }
  3348. }
  3349. }, {
  3350. key: "_dispatchDOMEvent",
  3351. value: function _dispatchDOMEvent(eventName) {
  3352. var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  3353. var details = Object.create(null);
  3354. if (args && args.length > 0) {
  3355. var obj = args[0];
  3356. for (var key in obj) {
  3357. var value = obj[key];
  3358. if (key === 'source') {
  3359. if (value === window || value === document) {
  3360. return;
  3361. }
  3362. continue;
  3363. }
  3364. details[key] = value;
  3365. }
  3366. }
  3367. var event = document.createEvent('CustomEvent');
  3368. event.initCustomEvent(eventName, true, true, details);
  3369. document.dispatchEvent(event);
  3370. }
  3371. }]);
  3372. return EventBus;
  3373. }();
  3374. exports.EventBus = EventBus;
  3375. var globalEventBus = null;
  3376. function getGlobalEventBus() {
  3377. var dispatchToDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  3378. if (!globalEventBus) {
  3379. globalEventBus = new EventBus({
  3380. dispatchToDOM: dispatchToDOM
  3381. });
  3382. }
  3383. return globalEventBus;
  3384. }
  3385. function clamp(v, min, max) {
  3386. return Math.min(Math.max(v, min), max);
  3387. }
  3388. var ProgressBar =
  3389. /*#__PURE__*/
  3390. function () {
  3391. function ProgressBar(id) {
  3392. var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  3393. height = _ref4.height,
  3394. width = _ref4.width,
  3395. units = _ref4.units;
  3396. _classCallCheck(this, ProgressBar);
  3397. this.visible = true;
  3398. this.div = document.querySelector(id + ' .progress');
  3399. this.bar = this.div.parentNode;
  3400. this.height = height || 100;
  3401. this.width = width || 100;
  3402. this.units = units || '%';
  3403. this.div.style.height = this.height + this.units;
  3404. this.percent = 0;
  3405. }
  3406. _createClass(ProgressBar, [{
  3407. key: "_updateBar",
  3408. value: function _updateBar() {
  3409. if (this._indeterminate) {
  3410. this.div.classList.add('indeterminate');
  3411. this.div.style.width = this.width + this.units;
  3412. return;
  3413. }
  3414. this.div.classList.remove('indeterminate');
  3415. var progressSize = this.width * this._percent / 100;
  3416. this.div.style.width = progressSize + this.units;
  3417. }
  3418. }, {
  3419. key: "setWidth",
  3420. value: function setWidth(viewer) {
  3421. if (!viewer) {
  3422. return;
  3423. }
  3424. var container = viewer.parentNode;
  3425. var scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
  3426. if (scrollbarWidth > 0) {
  3427. this.bar.setAttribute('style', 'width: calc(100% - ' + scrollbarWidth + 'px);');
  3428. }
  3429. }
  3430. }, {
  3431. key: "hide",
  3432. value: function hide() {
  3433. if (!this.visible) {
  3434. return;
  3435. }
  3436. this.visible = false;
  3437. this.bar.classList.add('hidden');
  3438. document.body.classList.remove('loadingInProgress');
  3439. }
  3440. }, {
  3441. key: "show",
  3442. value: function show() {
  3443. if (this.visible) {
  3444. return;
  3445. }
  3446. this.visible = true;
  3447. document.body.classList.add('loadingInProgress');
  3448. this.bar.classList.remove('hidden');
  3449. }
  3450. }, {
  3451. key: "percent",
  3452. get: function get() {
  3453. return this._percent;
  3454. },
  3455. set: function set(val) {
  3456. this._indeterminate = isNaN(val);
  3457. this._percent = clamp(val, 0, 100);
  3458. this._updateBar();
  3459. }
  3460. }]);
  3461. return ProgressBar;
  3462. }();
  3463. exports.ProgressBar = ProgressBar;
  3464. function moveToEndOfArray(arr, condition) {
  3465. var moved = [],
  3466. len = arr.length;
  3467. var write = 0;
  3468. for (var read = 0; read < len; ++read) {
  3469. if (condition(arr[read])) {
  3470. moved.push(arr[read]);
  3471. } else {
  3472. arr[write] = arr[read];
  3473. ++write;
  3474. }
  3475. }
  3476. for (var _read = 0; write < len; ++_read, ++write) {
  3477. arr[write] = moved[_read];
  3478. }
  3479. }
  3480. /***/ }),
  3481. /* 7 */
  3482. /***/ (function(module, exports, __webpack_require__) {
  3483. "use strict";
  3484. var pdfjsLib;
  3485. if (typeof window !== 'undefined' && window['pdfjs-dist/build/pdf']) {
  3486. pdfjsLib = window['pdfjs-dist/build/pdf'];
  3487. } else {
  3488. pdfjsLib = require('../build/pdf.js');
  3489. }
  3490. module.exports = pdfjsLib;
  3491. /***/ }),
  3492. /* 8 */
  3493. /***/ (function(module, exports, __webpack_require__) {
  3494. "use strict";
  3495. Object.defineProperty(exports, "__esModule", {
  3496. value: true
  3497. });
  3498. exports.PDFCursorTools = exports.CursorTool = void 0;
  3499. var _grab_to_pan = __webpack_require__(9);
  3500. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3501. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3502. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  3503. var CursorTool = {
  3504. SELECT: 0,
  3505. HAND: 1,
  3506. ZOOM: 2
  3507. };
  3508. exports.CursorTool = CursorTool;
  3509. var PDFCursorTools =
  3510. /*#__PURE__*/
  3511. function () {
  3512. function PDFCursorTools(_ref) {
  3513. var _this = this;
  3514. var container = _ref.container,
  3515. eventBus = _ref.eventBus,
  3516. _ref$cursorToolOnLoad = _ref.cursorToolOnLoad,
  3517. cursorToolOnLoad = _ref$cursorToolOnLoad === void 0 ? CursorTool.SELECT : _ref$cursorToolOnLoad;
  3518. _classCallCheck(this, PDFCursorTools);
  3519. this.container = container;
  3520. this.eventBus = eventBus;
  3521. this.active = CursorTool.SELECT;
  3522. this.activeBeforePresentationMode = null;
  3523. this.handTool = new _grab_to_pan.GrabToPan({
  3524. element: this.container
  3525. });
  3526. this._addEventListeners();
  3527. Promise.resolve().then(function () {
  3528. _this.switchTool(cursorToolOnLoad);
  3529. });
  3530. }
  3531. _createClass(PDFCursorTools, [{
  3532. key: "switchTool",
  3533. value: function switchTool(tool) {
  3534. var _this2 = this;
  3535. if (this.activeBeforePresentationMode !== null) {
  3536. return;
  3537. }
  3538. if (tool === this.active) {
  3539. return;
  3540. }
  3541. var disableActiveTool = function disableActiveTool() {
  3542. switch (_this2.active) {
  3543. case CursorTool.SELECT:
  3544. break;
  3545. case CursorTool.HAND:
  3546. _this2.handTool.deactivate();
  3547. break;
  3548. case CursorTool.ZOOM:
  3549. }
  3550. };
  3551. switch (tool) {
  3552. case CursorTool.SELECT:
  3553. disableActiveTool();
  3554. break;
  3555. case CursorTool.HAND:
  3556. disableActiveTool();
  3557. this.handTool.activate();
  3558. break;
  3559. case CursorTool.ZOOM:
  3560. default:
  3561. console.error("switchTool: \"".concat(tool, "\" is an unsupported value."));
  3562. return;
  3563. }
  3564. this.active = tool;
  3565. this._dispatchEvent();
  3566. }
  3567. }, {
  3568. key: "_dispatchEvent",
  3569. value: function _dispatchEvent() {
  3570. this.eventBus.dispatch('cursortoolchanged', {
  3571. source: this,
  3572. tool: this.active
  3573. });
  3574. }
  3575. }, {
  3576. key: "_addEventListeners",
  3577. value: function _addEventListeners() {
  3578. var _this3 = this;
  3579. this.eventBus.on('switchcursortool', function (evt) {
  3580. _this3.switchTool(evt.tool);
  3581. });
  3582. this.eventBus.on('presentationmodechanged', function (evt) {
  3583. if (evt.switchInProgress) {
  3584. return;
  3585. }
  3586. var previouslyActive;
  3587. if (evt.active) {
  3588. previouslyActive = _this3.active;
  3589. _this3.switchTool(CursorTool.SELECT);
  3590. _this3.activeBeforePresentationMode = previouslyActive;
  3591. } else {
  3592. previouslyActive = _this3.activeBeforePresentationMode;
  3593. _this3.activeBeforePresentationMode = null;
  3594. _this3.switchTool(previouslyActive);
  3595. }
  3596. });
  3597. }
  3598. }, {
  3599. key: "activeTool",
  3600. get: function get() {
  3601. return this.active;
  3602. }
  3603. }]);
  3604. return PDFCursorTools;
  3605. }();
  3606. exports.PDFCursorTools = PDFCursorTools;
  3607. /***/ }),
  3608. /* 9 */
  3609. /***/ (function(module, exports, __webpack_require__) {
  3610. "use strict";
  3611. Object.defineProperty(exports, "__esModule", {
  3612. value: true
  3613. });
  3614. exports.GrabToPan = GrabToPan;
  3615. function GrabToPan(options) {
  3616. this.element = options.element;
  3617. this.document = options.element.ownerDocument;
  3618. if (typeof options.ignoreTarget === 'function') {
  3619. this.ignoreTarget = options.ignoreTarget;
  3620. }
  3621. this.onActiveChanged = options.onActiveChanged;
  3622. this.activate = this.activate.bind(this);
  3623. this.deactivate = this.deactivate.bind(this);
  3624. this.toggle = this.toggle.bind(this);
  3625. this._onmousedown = this._onmousedown.bind(this);
  3626. this._onmousemove = this._onmousemove.bind(this);
  3627. this._endPan = this._endPan.bind(this);
  3628. var overlay = this.overlay = document.createElement('div');
  3629. overlay.className = 'grab-to-pan-grabbing';
  3630. }
  3631. GrabToPan.prototype = {
  3632. CSS_CLASS_GRAB: 'grab-to-pan-grab',
  3633. activate: function GrabToPan_activate() {
  3634. if (!this.active) {
  3635. this.active = true;
  3636. this.element.addEventListener('mousedown', this._onmousedown, true);
  3637. this.element.classList.add(this.CSS_CLASS_GRAB);
  3638. if (this.onActiveChanged) {
  3639. this.onActiveChanged(true);
  3640. }
  3641. }
  3642. },
  3643. deactivate: function GrabToPan_deactivate() {
  3644. if (this.active) {
  3645. this.active = false;
  3646. this.element.removeEventListener('mousedown', this._onmousedown, true);
  3647. this._endPan();
  3648. this.element.classList.remove(this.CSS_CLASS_GRAB);
  3649. if (this.onActiveChanged) {
  3650. this.onActiveChanged(false);
  3651. }
  3652. }
  3653. },
  3654. toggle: function GrabToPan_toggle() {
  3655. if (this.active) {
  3656. this.deactivate();
  3657. } else {
  3658. this.activate();
  3659. }
  3660. },
  3661. ignoreTarget: function GrabToPan_ignoreTarget(node) {
  3662. return node[matchesSelector]('a[href], a[href] *, input, textarea, button, button *, select, option');
  3663. },
  3664. _onmousedown: function GrabToPan__onmousedown(event) {
  3665. if (event.button !== 0 || this.ignoreTarget(event.target)) {
  3666. return;
  3667. }
  3668. if (event.originalTarget) {
  3669. try {
  3670. event.originalTarget.tagName;
  3671. } catch (e) {
  3672. return;
  3673. }
  3674. }
  3675. this.scrollLeftStart = this.element.scrollLeft;
  3676. this.scrollTopStart = this.element.scrollTop;
  3677. this.clientXStart = event.clientX;
  3678. this.clientYStart = event.clientY;
  3679. this.document.addEventListener('mousemove', this._onmousemove, true);
  3680. this.document.addEventListener('mouseup', this._endPan, true);
  3681. this.element.addEventListener('scroll', this._endPan, true);
  3682. event.preventDefault();
  3683. event.stopPropagation();
  3684. var focusedElement = document.activeElement;
  3685. if (focusedElement && !focusedElement.contains(event.target)) {
  3686. focusedElement.blur();
  3687. }
  3688. },
  3689. _onmousemove: function GrabToPan__onmousemove(event) {
  3690. this.element.removeEventListener('scroll', this._endPan, true);
  3691. if (isLeftMouseReleased(event)) {
  3692. this._endPan();
  3693. return;
  3694. }
  3695. var xDiff = event.clientX - this.clientXStart;
  3696. var yDiff = event.clientY - this.clientYStart;
  3697. var scrollTop = this.scrollTopStart - yDiff;
  3698. var scrollLeft = this.scrollLeftStart - xDiff;
  3699. if (this.element.scrollTo) {
  3700. this.element.scrollTo({
  3701. top: scrollTop,
  3702. left: scrollLeft,
  3703. behavior: 'instant'
  3704. });
  3705. } else {
  3706. this.element.scrollTop = scrollTop;
  3707. this.element.scrollLeft = scrollLeft;
  3708. }
  3709. if (!this.overlay.parentNode) {
  3710. document.body.appendChild(this.overlay);
  3711. }
  3712. },
  3713. _endPan: function GrabToPan__endPan() {
  3714. this.element.removeEventListener('scroll', this._endPan, true);
  3715. this.document.removeEventListener('mousemove', this._onmousemove, true);
  3716. this.document.removeEventListener('mouseup', this._endPan, true);
  3717. this.overlay.remove();
  3718. }
  3719. };
  3720. var matchesSelector;
  3721. ['webkitM', 'mozM', 'msM', 'oM', 'm'].some(function (prefix) {
  3722. var name = prefix + 'atches';
  3723. if (name in document.documentElement) {
  3724. matchesSelector = name;
  3725. }
  3726. name += 'Selector';
  3727. if (name in document.documentElement) {
  3728. matchesSelector = name;
  3729. }
  3730. return matchesSelector;
  3731. });
  3732. var isNotIEorIsIE10plus = !document.documentMode || document.documentMode > 9;
  3733. var chrome = window.chrome;
  3734. var isChrome15OrOpera15plus = chrome && (chrome.webstore || chrome.app);
  3735. var isSafari6plus = /Apple/.test(navigator.vendor) && /Version\/([6-9]\d*|[1-5]\d+)/.test(navigator.userAgent);
  3736. function isLeftMouseReleased(event) {
  3737. if ('buttons' in event && isNotIEorIsIE10plus) {
  3738. return !(event.buttons & 1);
  3739. }
  3740. if (isChrome15OrOpera15plus || isSafari6plus) {
  3741. return event.which === 0;
  3742. }
  3743. }
  3744. /***/ }),
  3745. /* 10 */
  3746. /***/ (function(module, exports, __webpack_require__) {
  3747. "use strict";
  3748. Object.defineProperty(exports, "__esModule", {
  3749. value: true
  3750. });
  3751. exports.PDFRenderingQueue = exports.RenderingStates = void 0;
  3752. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3753. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3754. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  3755. var CLEANUP_TIMEOUT = 30000;
  3756. var RenderingStates = {
  3757. INITIAL: 0,
  3758. RUNNING: 1,
  3759. PAUSED: 2,
  3760. FINISHED: 3
  3761. };
  3762. exports.RenderingStates = RenderingStates;
  3763. var PDFRenderingQueue =
  3764. /*#__PURE__*/
  3765. function () {
  3766. function PDFRenderingQueue() {
  3767. _classCallCheck(this, PDFRenderingQueue);
  3768. this.pdfViewer = null;
  3769. this.pdfThumbnailViewer = null;
  3770. this.onIdle = null;
  3771. this.highestPriorityPage = null;
  3772. this.idleTimeout = null;
  3773. this.printing = false;
  3774. this.isThumbnailViewEnabled = false;
  3775. }
  3776. _createClass(PDFRenderingQueue, [{
  3777. key: "setViewer",
  3778. value: function setViewer(pdfViewer) {
  3779. this.pdfViewer = pdfViewer;
  3780. }
  3781. }, {
  3782. key: "setThumbnailViewer",
  3783. value: function setThumbnailViewer(pdfThumbnailViewer) {
  3784. this.pdfThumbnailViewer = pdfThumbnailViewer;
  3785. }
  3786. }, {
  3787. key: "isHighestPriority",
  3788. value: function isHighestPriority(view) {
  3789. return this.highestPriorityPage === view.renderingId;
  3790. }
  3791. }, {
  3792. key: "renderHighestPriority",
  3793. value: function renderHighestPriority(currentlyVisiblePages) {
  3794. if (this.idleTimeout) {
  3795. clearTimeout(this.idleTimeout);
  3796. this.idleTimeout = null;
  3797. }
  3798. if (this.pdfViewer.forceRendering(currentlyVisiblePages)) {
  3799. return;
  3800. }
  3801. if (this.pdfThumbnailViewer && this.isThumbnailViewEnabled) {
  3802. if (this.pdfThumbnailViewer.forceRendering()) {
  3803. return;
  3804. }
  3805. }
  3806. if (this.printing) {
  3807. return;
  3808. }
  3809. if (this.onIdle) {
  3810. this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT);
  3811. }
  3812. }
  3813. }, {
  3814. key: "getHighestPriority",
  3815. value: function getHighestPriority(visible, views, scrolledDown) {
  3816. var visibleViews = visible.views;
  3817. var numVisible = visibleViews.length;
  3818. if (numVisible === 0) {
  3819. return false;
  3820. }
  3821. for (var i = 0; i < numVisible; ++i) {
  3822. var view = visibleViews[i].view;
  3823. if (!this.isViewFinished(view)) {
  3824. return view;
  3825. }
  3826. }
  3827. if (scrolledDown) {
  3828. var nextPageIndex = visible.last.id;
  3829. if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) {
  3830. return views[nextPageIndex];
  3831. }
  3832. } else {
  3833. var previousPageIndex = visible.first.id - 2;
  3834. if (views[previousPageIndex] && !this.isViewFinished(views[previousPageIndex])) {
  3835. return views[previousPageIndex];
  3836. }
  3837. }
  3838. return null;
  3839. }
  3840. }, {
  3841. key: "isViewFinished",
  3842. value: function isViewFinished(view) {
  3843. return view.renderingState === RenderingStates.FINISHED;
  3844. }
  3845. }, {
  3846. key: "renderView",
  3847. value: function renderView(view) {
  3848. var _this = this;
  3849. switch (view.renderingState) {
  3850. case RenderingStates.FINISHED:
  3851. return false;
  3852. case RenderingStates.PAUSED:
  3853. this.highestPriorityPage = view.renderingId;
  3854. view.resume();
  3855. break;
  3856. case RenderingStates.RUNNING:
  3857. this.highestPriorityPage = view.renderingId;
  3858. break;
  3859. case RenderingStates.INITIAL:
  3860. this.highestPriorityPage = view.renderingId;
  3861. var continueRendering = function continueRendering() {
  3862. _this.renderHighestPriority();
  3863. };
  3864. view.draw().then(continueRendering, continueRendering);
  3865. break;
  3866. }
  3867. return true;
  3868. }
  3869. }]);
  3870. return PDFRenderingQueue;
  3871. }();
  3872. exports.PDFRenderingQueue = PDFRenderingQueue;
  3873. /***/ }),
  3874. /* 11 */
  3875. /***/ (function(module, exports, __webpack_require__) {
  3876. "use strict";
  3877. Object.defineProperty(exports, "__esModule", {
  3878. value: true
  3879. });
  3880. exports.PDFSidebar = exports.SidebarView = void 0;
  3881. var _ui_utils = __webpack_require__(6);
  3882. var _pdf_rendering_queue = __webpack_require__(10);
  3883. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3884. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3885. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  3886. var UI_NOTIFICATION_CLASS = 'pdfSidebarNotification';
  3887. var SidebarView = {
  3888. UNKNOWN: -1,
  3889. NONE: 0,
  3890. THUMBS: 1,
  3891. OUTLINE: 2,
  3892. ATTACHMENTS: 3,
  3893. LAYERS: 4
  3894. };
  3895. exports.SidebarView = SidebarView;
  3896. var PDFSidebar =
  3897. /*#__PURE__*/
  3898. function () {
  3899. function PDFSidebar(options, eventBus) {
  3900. var l10n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ui_utils.NullL10n;
  3901. _classCallCheck(this, PDFSidebar);
  3902. this.isOpen = false;
  3903. this.active = SidebarView.THUMBS;
  3904. this.isInitialViewSet = false;
  3905. this.onToggled = null;
  3906. this.pdfViewer = options.pdfViewer;
  3907. this.pdfThumbnailViewer = options.pdfThumbnailViewer;
  3908. this.outerContainer = options.outerContainer;
  3909. this.viewerContainer = options.viewerContainer;
  3910. this.toggleButton = options.toggleButton;
  3911. this.thumbnailButton = options.thumbnailButton;
  3912. this.outlineButton = options.outlineButton;
  3913. this.attachmentsButton = options.attachmentsButton;
  3914. this.thumbnailView = options.thumbnailView;
  3915. this.outlineView = options.outlineView;
  3916. this.attachmentsView = options.attachmentsView;
  3917. this.disableNotification = options.disableNotification || false;
  3918. this.eventBus = eventBus;
  3919. this.l10n = l10n;
  3920. this._addEventListeners();
  3921. }
  3922. _createClass(PDFSidebar, [{
  3923. key: "reset",
  3924. value: function reset() {
  3925. this.isInitialViewSet = false;
  3926. this._hideUINotification(null);
  3927. this.switchView(SidebarView.THUMBS);
  3928. this.outlineButton.disabled = false;
  3929. this.attachmentsButton.disabled = false;
  3930. }
  3931. }, {
  3932. key: "setInitialView",
  3933. value: function setInitialView() {
  3934. var view = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : SidebarView.NONE;
  3935. if (this.isInitialViewSet) {
  3936. return;
  3937. }
  3938. this.isInitialViewSet = true;
  3939. if (view === SidebarView.NONE || view === SidebarView.UNKNOWN) {
  3940. this._dispatchEvent();
  3941. return;
  3942. }
  3943. if (!this._switchView(view, true)) {
  3944. this._dispatchEvent();
  3945. }
  3946. }
  3947. }, {
  3948. key: "switchView",
  3949. value: function switchView(view) {
  3950. var forceOpen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  3951. this._switchView(view, forceOpen);
  3952. }
  3953. }, {
  3954. key: "_switchView",
  3955. value: function _switchView(view) {
  3956. var forceOpen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  3957. var isViewChanged = view !== this.active;
  3958. var shouldForceRendering = false;
  3959. switch (view) {
  3960. case SidebarView.NONE:
  3961. if (this.isOpen) {
  3962. this.close();
  3963. return true;
  3964. }
  3965. return false;
  3966. case SidebarView.THUMBS:
  3967. if (this.isOpen && isViewChanged) {
  3968. shouldForceRendering = true;
  3969. }
  3970. break;
  3971. case SidebarView.OUTLINE:
  3972. if (this.outlineButton.disabled) {
  3973. return false;
  3974. }
  3975. break;
  3976. case SidebarView.ATTACHMENTS:
  3977. if (this.attachmentsButton.disabled) {
  3978. return false;
  3979. }
  3980. break;
  3981. default:
  3982. console.error("PDFSidebar._switchView: \"".concat(view, "\" is not a valid view."));
  3983. return false;
  3984. }
  3985. this.active = view;
  3986. this.thumbnailButton.classList.toggle('toggled', view === SidebarView.THUMBS);
  3987. this.outlineButton.classList.toggle('toggled', view === SidebarView.OUTLINE);
  3988. this.attachmentsButton.classList.toggle('toggled', view === SidebarView.ATTACHMENTS);
  3989. this.thumbnailView.classList.toggle('hidden', view !== SidebarView.THUMBS);
  3990. this.outlineView.classList.toggle('hidden', view !== SidebarView.OUTLINE);
  3991. this.attachmentsView.classList.toggle('hidden', view !== SidebarView.ATTACHMENTS);
  3992. if (forceOpen && !this.isOpen) {
  3993. this.open();
  3994. return true;
  3995. }
  3996. if (shouldForceRendering) {
  3997. this._updateThumbnailViewer();
  3998. this._forceRendering();
  3999. }
  4000. if (isViewChanged) {
  4001. this._dispatchEvent();
  4002. }
  4003. this._hideUINotification(this.active);
  4004. return isViewChanged;
  4005. }
  4006. }, {
  4007. key: "open",
  4008. value: function open() {
  4009. if (this.isOpen) {
  4010. return;
  4011. }
  4012. this.isOpen = true;
  4013. this.toggleButton.classList.add('toggled');
  4014. this.outerContainer.classList.add('sidebarMoving', 'sidebarOpen');
  4015. if (this.active === SidebarView.THUMBS) {
  4016. this._updateThumbnailViewer();
  4017. }
  4018. this._forceRendering();
  4019. this._dispatchEvent();
  4020. this._hideUINotification(this.active);
  4021. }
  4022. }, {
  4023. key: "close",
  4024. value: function close() {
  4025. if (!this.isOpen) {
  4026. return;
  4027. }
  4028. this.isOpen = false;
  4029. this.toggleButton.classList.remove('toggled');
  4030. this.outerContainer.classList.add('sidebarMoving');
  4031. this.outerContainer.classList.remove('sidebarOpen');
  4032. this._forceRendering();
  4033. this._dispatchEvent();
  4034. }
  4035. }, {
  4036. key: "toggle",
  4037. value: function toggle() {
  4038. if (this.isOpen) {
  4039. this.close();
  4040. } else {
  4041. this.open();
  4042. }
  4043. }
  4044. }, {
  4045. key: "_dispatchEvent",
  4046. value: function _dispatchEvent() {
  4047. this.eventBus.dispatch('sidebarviewchanged', {
  4048. source: this,
  4049. view: this.visibleView
  4050. });
  4051. }
  4052. }, {
  4053. key: "_forceRendering",
  4054. value: function _forceRendering() {
  4055. if (this.onToggled) {
  4056. this.onToggled();
  4057. } else {
  4058. this.pdfViewer.forceRendering();
  4059. this.pdfThumbnailViewer.forceRendering();
  4060. }
  4061. }
  4062. }, {
  4063. key: "_updateThumbnailViewer",
  4064. value: function _updateThumbnailViewer() {
  4065. var pdfViewer = this.pdfViewer,
  4066. pdfThumbnailViewer = this.pdfThumbnailViewer;
  4067. var pagesCount = pdfViewer.pagesCount;
  4068. for (var pageIndex = 0; pageIndex < pagesCount; pageIndex++) {
  4069. var pageView = pdfViewer.getPageView(pageIndex);
  4070. if (pageView && pageView.renderingState === _pdf_rendering_queue.RenderingStates.FINISHED) {
  4071. var thumbnailView = pdfThumbnailViewer.getThumbnail(pageIndex);
  4072. thumbnailView.setImage(pageView);
  4073. }
  4074. }
  4075. pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber);
  4076. }
  4077. }, {
  4078. key: "_showUINotification",
  4079. value: function _showUINotification(view) {
  4080. var _this = this;
  4081. if (this.disableNotification) {
  4082. return;
  4083. }
  4084. this.l10n.get('toggle_sidebar_notification.title', null, 'Toggle Sidebar (document contains outline/attachments)').then(function (msg) {
  4085. _this.toggleButton.title = msg;
  4086. });
  4087. if (!this.isOpen) {
  4088. this.toggleButton.classList.add(UI_NOTIFICATION_CLASS);
  4089. } else if (view === this.active) {
  4090. return;
  4091. }
  4092. switch (view) {
  4093. case SidebarView.OUTLINE:
  4094. this.outlineButton.classList.add(UI_NOTIFICATION_CLASS);
  4095. break;
  4096. case SidebarView.ATTACHMENTS:
  4097. this.attachmentsButton.classList.add(UI_NOTIFICATION_CLASS);
  4098. break;
  4099. }
  4100. }
  4101. }, {
  4102. key: "_hideUINotification",
  4103. value: function _hideUINotification(view) {
  4104. var _this2 = this;
  4105. if (this.disableNotification) {
  4106. return;
  4107. }
  4108. var removeNotification = function removeNotification(view) {
  4109. switch (view) {
  4110. case SidebarView.OUTLINE:
  4111. _this2.outlineButton.classList.remove(UI_NOTIFICATION_CLASS);
  4112. break;
  4113. case SidebarView.ATTACHMENTS:
  4114. _this2.attachmentsButton.classList.remove(UI_NOTIFICATION_CLASS);
  4115. break;
  4116. }
  4117. };
  4118. if (!this.isOpen && view !== null) {
  4119. return;
  4120. }
  4121. this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS);
  4122. if (view !== null) {
  4123. removeNotification(view);
  4124. return;
  4125. }
  4126. for (view in SidebarView) {
  4127. removeNotification(SidebarView[view]);
  4128. }
  4129. this.l10n.get('toggle_sidebar.title', null, 'Toggle Sidebar').then(function (msg) {
  4130. _this2.toggleButton.title = msg;
  4131. });
  4132. }
  4133. }, {
  4134. key: "_addEventListeners",
  4135. value: function _addEventListeners() {
  4136. var _this3 = this;
  4137. this.viewerContainer.addEventListener('transitionend', function (evt) {
  4138. if (evt.target === _this3.viewerContainer) {
  4139. _this3.outerContainer.classList.remove('sidebarMoving');
  4140. }
  4141. });
  4142. this.thumbnailButton.addEventListener('click', function () {
  4143. _this3.switchView(SidebarView.THUMBS);
  4144. });
  4145. this.outlineButton.addEventListener('click', function () {
  4146. _this3.switchView(SidebarView.OUTLINE);
  4147. });
  4148. this.outlineButton.addEventListener('dblclick', function () {
  4149. _this3.eventBus.dispatch('toggleoutlinetree', {
  4150. source: _this3
  4151. });
  4152. });
  4153. this.attachmentsButton.addEventListener('click', function () {
  4154. _this3.switchView(SidebarView.ATTACHMENTS);
  4155. });
  4156. this.eventBus.on('outlineloaded', function (evt) {
  4157. var outlineCount = evt.outlineCount;
  4158. _this3.outlineButton.disabled = !outlineCount;
  4159. if (outlineCount) {
  4160. _this3._showUINotification(SidebarView.OUTLINE);
  4161. } else if (_this3.active === SidebarView.OUTLINE) {
  4162. _this3.switchView(SidebarView.THUMBS);
  4163. }
  4164. });
  4165. this.eventBus.on('attachmentsloaded', function (evt) {
  4166. if (evt.attachmentsCount) {
  4167. _this3.attachmentsButton.disabled = false;
  4168. _this3._showUINotification(SidebarView.ATTACHMENTS);
  4169. return;
  4170. }
  4171. Promise.resolve().then(function () {
  4172. if (_this3.attachmentsView.hasChildNodes()) {
  4173. return;
  4174. }
  4175. _this3.attachmentsButton.disabled = true;
  4176. if (_this3.active === SidebarView.ATTACHMENTS) {
  4177. _this3.switchView(SidebarView.THUMBS);
  4178. }
  4179. });
  4180. });
  4181. this.eventBus.on('presentationmodechanged', function (evt) {
  4182. if (!evt.active && !evt.switchInProgress && _this3.isThumbnailViewVisible) {
  4183. _this3._updateThumbnailViewer();
  4184. }
  4185. });
  4186. }
  4187. }, {
  4188. key: "visibleView",
  4189. get: function get() {
  4190. return this.isOpen ? this.active : SidebarView.NONE;
  4191. }
  4192. }, {
  4193. key: "isThumbnailViewVisible",
  4194. get: function get() {
  4195. return this.isOpen && this.active === SidebarView.THUMBS;
  4196. }
  4197. }, {
  4198. key: "isOutlineViewVisible",
  4199. get: function get() {
  4200. return this.isOpen && this.active === SidebarView.OUTLINE;
  4201. }
  4202. }, {
  4203. key: "isAttachmentsViewVisible",
  4204. get: function get() {
  4205. return this.isOpen && this.active === SidebarView.ATTACHMENTS;
  4206. }
  4207. }]);
  4208. return PDFSidebar;
  4209. }();
  4210. exports.PDFSidebar = PDFSidebar;
  4211. /***/ }),
  4212. /* 12 */
  4213. /***/ (function(module, exports, __webpack_require__) {
  4214. "use strict";
  4215. Object.defineProperty(exports, "__esModule", {
  4216. value: true
  4217. });
  4218. exports.OptionKind = exports.AppOptions = void 0;
  4219. var _pdfjsLib = __webpack_require__(7);
  4220. var _viewer_compatibility = __webpack_require__(13);
  4221. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4222. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4223. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  4224. var OptionKind = {
  4225. VIEWER: 'viewer',
  4226. API: 'api',
  4227. WORKER: 'worker'
  4228. };
  4229. exports.OptionKind = OptionKind;
  4230. var defaultOptions = {
  4231. cursorToolOnLoad: {
  4232. value: 0,
  4233. kind: OptionKind.VIEWER
  4234. },
  4235. defaultUrl: {
  4236. value: 'compressed.tracemonkey-pldi-09.pdf',
  4237. kind: OptionKind.VIEWER
  4238. },
  4239. defaultZoomValue: {
  4240. value: '',
  4241. kind: OptionKind.VIEWER
  4242. },
  4243. disableHistory: {
  4244. value: false,
  4245. kind: OptionKind.VIEWER
  4246. },
  4247. disablePageLabels: {
  4248. value: false,
  4249. kind: OptionKind.VIEWER
  4250. },
  4251. enablePrintAutoRotate: {
  4252. value: false,
  4253. kind: OptionKind.VIEWER
  4254. },
  4255. enableWebGL: {
  4256. value: false,
  4257. kind: OptionKind.VIEWER
  4258. },
  4259. eventBusDispatchToDOM: {
  4260. value: false,
  4261. kind: OptionKind.VIEWER
  4262. },
  4263. externalLinkRel: {
  4264. value: 'noopener noreferrer nofollow',
  4265. kind: OptionKind.VIEWER
  4266. },
  4267. externalLinkTarget: {
  4268. value: 0,
  4269. kind: OptionKind.VIEWER
  4270. },
  4271. historyUpdateUrl: {
  4272. value: false,
  4273. kind: OptionKind.VIEWER
  4274. },
  4275. imageResourcesPath: {
  4276. value: './images/',
  4277. kind: OptionKind.VIEWER
  4278. },
  4279. maxCanvasPixels: {
  4280. value: 16777216,
  4281. compatibility: _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels,
  4282. kind: OptionKind.VIEWER
  4283. },
  4284. pdfBugEnabled: {
  4285. value: false,
  4286. kind: OptionKind.VIEWER
  4287. },
  4288. renderer: {
  4289. value: 'canvas',
  4290. kind: OptionKind.VIEWER
  4291. },
  4292. renderInteractiveForms: {
  4293. value: false,
  4294. kind: OptionKind.VIEWER
  4295. },
  4296. sidebarViewOnLoad: {
  4297. value: -1,
  4298. kind: OptionKind.VIEWER
  4299. },
  4300. scrollModeOnLoad: {
  4301. value: -1,
  4302. kind: OptionKind.VIEWER
  4303. },
  4304. spreadModeOnLoad: {
  4305. value: -1,
  4306. kind: OptionKind.VIEWER
  4307. },
  4308. textLayerMode: {
  4309. value: 1,
  4310. kind: OptionKind.VIEWER
  4311. },
  4312. useOnlyCssZoom: {
  4313. value: false,
  4314. kind: OptionKind.VIEWER
  4315. },
  4316. viewOnLoad: {
  4317. value: 0,
  4318. kind: OptionKind.VIEWER
  4319. },
  4320. cMapPacked: {
  4321. value: true,
  4322. kind: OptionKind.API
  4323. },
  4324. cMapUrl: {
  4325. value: '../web/cmaps/',
  4326. kind: OptionKind.API
  4327. },
  4328. disableAutoFetch: {
  4329. value: false,
  4330. kind: OptionKind.API
  4331. },
  4332. disableCreateObjectURL: {
  4333. value: false,
  4334. compatibility: _pdfjsLib.apiCompatibilityParams.disableCreateObjectURL,
  4335. kind: OptionKind.API
  4336. },
  4337. disableFontFace: {
  4338. value: false,
  4339. kind: OptionKind.API
  4340. },
  4341. disableRange: {
  4342. value: false,
  4343. kind: OptionKind.API
  4344. },
  4345. disableStream: {
  4346. value: false,
  4347. kind: OptionKind.API
  4348. },
  4349. isEvalSupported: {
  4350. value: true,
  4351. kind: OptionKind.API
  4352. },
  4353. maxImageSize: {
  4354. value: -1,
  4355. kind: OptionKind.API
  4356. },
  4357. pdfBug: {
  4358. value: false,
  4359. kind: OptionKind.API
  4360. },
  4361. postMessageTransfers: {
  4362. value: true,
  4363. kind: OptionKind.API
  4364. },
  4365. verbosity: {
  4366. value: 1,
  4367. kind: OptionKind.API
  4368. },
  4369. workerPort: {
  4370. value: null,
  4371. kind: OptionKind.WORKER
  4372. },
  4373. workerSrc: {
  4374. value: '../build/pdf.worker.js',
  4375. kind: OptionKind.WORKER
  4376. }
  4377. };
  4378. {
  4379. defaultOptions.disablePreferences = {
  4380. value: false,
  4381. kind: OptionKind.VIEWER
  4382. };
  4383. defaultOptions.locale = {
  4384. value: typeof navigator !== 'undefined' ? navigator.language : 'en-US',
  4385. kind: OptionKind.VIEWER
  4386. };
  4387. }
  4388. var userOptions = Object.create(null);
  4389. var AppOptions =
  4390. /*#__PURE__*/
  4391. function () {
  4392. function AppOptions() {
  4393. _classCallCheck(this, AppOptions);
  4394. throw new Error('Cannot initialize AppOptions.');
  4395. }
  4396. _createClass(AppOptions, null, [{
  4397. key: "get",
  4398. value: function get(name) {
  4399. var userOption = userOptions[name];
  4400. if (userOption !== undefined) {
  4401. return userOption;
  4402. }
  4403. var defaultOption = defaultOptions[name];
  4404. if (defaultOption !== undefined) {
  4405. return defaultOption.compatibility || defaultOption.value;
  4406. }
  4407. return undefined;
  4408. }
  4409. }, {
  4410. key: "getAll",
  4411. value: function getAll() {
  4412. var kind = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  4413. var options = Object.create(null);
  4414. for (var name in defaultOptions) {
  4415. var defaultOption = defaultOptions[name];
  4416. if (kind && kind !== defaultOption.kind) {
  4417. continue;
  4418. }
  4419. var userOption = userOptions[name];
  4420. options[name] = userOption !== undefined ? userOption : defaultOption.compatibility || defaultOption.value;
  4421. }
  4422. return options;
  4423. }
  4424. }, {
  4425. key: "set",
  4426. value: function set(name, value) {
  4427. userOptions[name] = value;
  4428. }
  4429. }, {
  4430. key: "remove",
  4431. value: function remove(name) {
  4432. delete userOptions[name];
  4433. }
  4434. }]);
  4435. return AppOptions;
  4436. }();
  4437. exports.AppOptions = AppOptions;
  4438. /***/ }),
  4439. /* 13 */
  4440. /***/ (function(module, exports, __webpack_require__) {
  4441. "use strict";
  4442. var compatibilityParams = Object.create(null);
  4443. {
  4444. var userAgent = typeof navigator !== 'undefined' && navigator.userAgent || '';
  4445. var isAndroid = /Android/.test(userAgent);
  4446. var isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent);
  4447. (function checkCanvasSizeLimitation() {
  4448. if (isIOS || isAndroid) {
  4449. compatibilityParams.maxCanvasPixels = 5242880;
  4450. }
  4451. })();
  4452. }
  4453. exports.viewerCompatibilityParams = Object.freeze(compatibilityParams);
  4454. /***/ }),
  4455. /* 14 */
  4456. /***/ (function(module, exports, __webpack_require__) {
  4457. "use strict";
  4458. Object.defineProperty(exports, "__esModule", {
  4459. value: true
  4460. });
  4461. exports.OverlayManager = void 0;
  4462. var _regenerator = _interopRequireDefault(__webpack_require__(2));
  4463. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  4464. 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); } }
  4465. 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); }); }; }
  4466. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4467. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4468. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  4469. var OverlayManager =
  4470. /*#__PURE__*/
  4471. function () {
  4472. function OverlayManager() {
  4473. _classCallCheck(this, OverlayManager);
  4474. this._overlays = {};
  4475. this._active = null;
  4476. this._keyDownBound = this._keyDown.bind(this);
  4477. }
  4478. _createClass(OverlayManager, [{
  4479. key: "register",
  4480. value: function () {
  4481. var _register = _asyncToGenerator(
  4482. /*#__PURE__*/
  4483. _regenerator.default.mark(function _callee(name, element) {
  4484. var callerCloseMethod,
  4485. canForceClose,
  4486. container,
  4487. _args = arguments;
  4488. return _regenerator.default.wrap(function _callee$(_context) {
  4489. while (1) {
  4490. switch (_context.prev = _context.next) {
  4491. case 0:
  4492. callerCloseMethod = _args.length > 2 && _args[2] !== undefined ? _args[2] : null;
  4493. canForceClose = _args.length > 3 && _args[3] !== undefined ? _args[3] : false;
  4494. if (!(!name || !element || !(container = element.parentNode))) {
  4495. _context.next = 6;
  4496. break;
  4497. }
  4498. throw new Error('Not enough parameters.');
  4499. case 6:
  4500. if (!this._overlays[name]) {
  4501. _context.next = 8;
  4502. break;
  4503. }
  4504. throw new Error('The overlay is already registered.');
  4505. case 8:
  4506. this._overlays[name] = {
  4507. element: element,
  4508. container: container,
  4509. callerCloseMethod: callerCloseMethod,
  4510. canForceClose: canForceClose
  4511. };
  4512. case 9:
  4513. case "end":
  4514. return _context.stop();
  4515. }
  4516. }
  4517. }, _callee, this);
  4518. }));
  4519. function register(_x, _x2) {
  4520. return _register.apply(this, arguments);
  4521. }
  4522. return register;
  4523. }()
  4524. }, {
  4525. key: "unregister",
  4526. value: function () {
  4527. var _unregister = _asyncToGenerator(
  4528. /*#__PURE__*/
  4529. _regenerator.default.mark(function _callee2(name) {
  4530. return _regenerator.default.wrap(function _callee2$(_context2) {
  4531. while (1) {
  4532. switch (_context2.prev = _context2.next) {
  4533. case 0:
  4534. if (this._overlays[name]) {
  4535. _context2.next = 4;
  4536. break;
  4537. }
  4538. throw new Error('The overlay does not exist.');
  4539. case 4:
  4540. if (!(this._active === name)) {
  4541. _context2.next = 6;
  4542. break;
  4543. }
  4544. throw new Error('The overlay cannot be removed while it is active.');
  4545. case 6:
  4546. delete this._overlays[name];
  4547. case 7:
  4548. case "end":
  4549. return _context2.stop();
  4550. }
  4551. }
  4552. }, _callee2, this);
  4553. }));
  4554. function unregister(_x3) {
  4555. return _unregister.apply(this, arguments);
  4556. }
  4557. return unregister;
  4558. }()
  4559. }, {
  4560. key: "open",
  4561. value: function () {
  4562. var _open = _asyncToGenerator(
  4563. /*#__PURE__*/
  4564. _regenerator.default.mark(function _callee3(name) {
  4565. return _regenerator.default.wrap(function _callee3$(_context3) {
  4566. while (1) {
  4567. switch (_context3.prev = _context3.next) {
  4568. case 0:
  4569. if (this._overlays[name]) {
  4570. _context3.next = 4;
  4571. break;
  4572. }
  4573. throw new Error('The overlay does not exist.');
  4574. case 4:
  4575. if (!this._active) {
  4576. _context3.next = 14;
  4577. break;
  4578. }
  4579. if (!this._overlays[name].canForceClose) {
  4580. _context3.next = 9;
  4581. break;
  4582. }
  4583. this._closeThroughCaller();
  4584. _context3.next = 14;
  4585. break;
  4586. case 9:
  4587. if (!(this._active === name)) {
  4588. _context3.next = 13;
  4589. break;
  4590. }
  4591. throw new Error('The overlay is already active.');
  4592. case 13:
  4593. throw new Error('Another overlay is currently active.');
  4594. case 14:
  4595. this._active = name;
  4596. this._overlays[this._active].element.classList.remove('hidden');
  4597. this._overlays[this._active].container.classList.remove('hidden');
  4598. window.addEventListener('keydown', this._keyDownBound);
  4599. case 18:
  4600. case "end":
  4601. return _context3.stop();
  4602. }
  4603. }
  4604. }, _callee3, this);
  4605. }));
  4606. function open(_x4) {
  4607. return _open.apply(this, arguments);
  4608. }
  4609. return open;
  4610. }()
  4611. }, {
  4612. key: "close",
  4613. value: function () {
  4614. var _close = _asyncToGenerator(
  4615. /*#__PURE__*/
  4616. _regenerator.default.mark(function _callee4(name) {
  4617. return _regenerator.default.wrap(function _callee4$(_context4) {
  4618. while (1) {
  4619. switch (_context4.prev = _context4.next) {
  4620. case 0:
  4621. if (this._overlays[name]) {
  4622. _context4.next = 4;
  4623. break;
  4624. }
  4625. throw new Error('The overlay does not exist.');
  4626. case 4:
  4627. if (this._active) {
  4628. _context4.next = 8;
  4629. break;
  4630. }
  4631. throw new Error('The overlay is currently not active.');
  4632. case 8:
  4633. if (!(this._active !== name)) {
  4634. _context4.next = 10;
  4635. break;
  4636. }
  4637. throw new Error('Another overlay is currently active.');
  4638. case 10:
  4639. this._overlays[this._active].container.classList.add('hidden');
  4640. this._overlays[this._active].element.classList.add('hidden');
  4641. this._active = null;
  4642. window.removeEventListener('keydown', this._keyDownBound);
  4643. case 14:
  4644. case "end":
  4645. return _context4.stop();
  4646. }
  4647. }
  4648. }, _callee4, this);
  4649. }));
  4650. function close(_x5) {
  4651. return _close.apply(this, arguments);
  4652. }
  4653. return close;
  4654. }()
  4655. }, {
  4656. key: "_keyDown",
  4657. value: function _keyDown(evt) {
  4658. if (this._active && evt.keyCode === 27) {
  4659. this._closeThroughCaller();
  4660. evt.preventDefault();
  4661. }
  4662. }
  4663. }, {
  4664. key: "_closeThroughCaller",
  4665. value: function _closeThroughCaller() {
  4666. if (this._overlays[this._active].callerCloseMethod) {
  4667. this._overlays[this._active].callerCloseMethod();
  4668. }
  4669. if (this._active) {
  4670. this.close(this._active);
  4671. }
  4672. }
  4673. }, {
  4674. key: "active",
  4675. get: function get() {
  4676. return this._active;
  4677. }
  4678. }]);
  4679. return OverlayManager;
  4680. }();
  4681. exports.OverlayManager = OverlayManager;
  4682. /***/ }),
  4683. /* 15 */
  4684. /***/ (function(module, exports, __webpack_require__) {
  4685. "use strict";
  4686. Object.defineProperty(exports, "__esModule", {
  4687. value: true
  4688. });
  4689. exports.PasswordPrompt = void 0;
  4690. var _ui_utils = __webpack_require__(6);
  4691. var _pdfjsLib = __webpack_require__(7);
  4692. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4693. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4694. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  4695. var PasswordPrompt =
  4696. /*#__PURE__*/
  4697. function () {
  4698. function PasswordPrompt(options, overlayManager) {
  4699. var _this = this;
  4700. var l10n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ui_utils.NullL10n;
  4701. _classCallCheck(this, PasswordPrompt);
  4702. this.overlayName = options.overlayName;
  4703. this.container = options.container;
  4704. this.label = options.label;
  4705. this.input = options.input;
  4706. this.submitButton = options.submitButton;
  4707. this.cancelButton = options.cancelButton;
  4708. this.overlayManager = overlayManager;
  4709. this.l10n = l10n;
  4710. this.updateCallback = null;
  4711. this.reason = null;
  4712. this.submitButton.addEventListener('click', this.verify.bind(this));
  4713. this.cancelButton.addEventListener('click', this.close.bind(this));
  4714. this.input.addEventListener('keydown', function (e) {
  4715. if (e.keyCode === 13) {
  4716. _this.verify();
  4717. }
  4718. });
  4719. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this), true);
  4720. }
  4721. _createClass(PasswordPrompt, [{
  4722. key: "open",
  4723. value: function open() {
  4724. var _this2 = this;
  4725. this.overlayManager.open(this.overlayName).then(function () {
  4726. _this2.input.focus();
  4727. var promptString;
  4728. if (_this2.reason === _pdfjsLib.PasswordResponses.INCORRECT_PASSWORD) {
  4729. promptString = _this2.l10n.get('password_invalid', null, 'Invalid password. Please try again.');
  4730. } else {
  4731. promptString = _this2.l10n.get('password_label', null, 'Enter the password to open this PDF file.');
  4732. }
  4733. promptString.then(function (msg) {
  4734. _this2.label.textContent = msg;
  4735. });
  4736. });
  4737. }
  4738. }, {
  4739. key: "close",
  4740. value: function close() {
  4741. var _this3 = this;
  4742. this.overlayManager.close(this.overlayName).then(function () {
  4743. _this3.input.value = '';
  4744. });
  4745. }
  4746. }, {
  4747. key: "verify",
  4748. value: function verify() {
  4749. var password = this.input.value;
  4750. if (password && password.length > 0) {
  4751. this.close();
  4752. return this.updateCallback(password);
  4753. }
  4754. }
  4755. }, {
  4756. key: "setUpdateCallback",
  4757. value: function setUpdateCallback(updateCallback, reason) {
  4758. this.updateCallback = updateCallback;
  4759. this.reason = reason;
  4760. }
  4761. }]);
  4762. return PasswordPrompt;
  4763. }();
  4764. exports.PasswordPrompt = PasswordPrompt;
  4765. /***/ }),
  4766. /* 16 */
  4767. /***/ (function(module, exports, __webpack_require__) {
  4768. "use strict";
  4769. Object.defineProperty(exports, "__esModule", {
  4770. value: true
  4771. });
  4772. exports.PDFAttachmentViewer = void 0;
  4773. var _pdfjsLib = __webpack_require__(7);
  4774. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4775. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4776. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  4777. var PDFAttachmentViewer =
  4778. /*#__PURE__*/
  4779. function () {
  4780. function PDFAttachmentViewer(_ref) {
  4781. var container = _ref.container,
  4782. eventBus = _ref.eventBus,
  4783. downloadManager = _ref.downloadManager;
  4784. _classCallCheck(this, PDFAttachmentViewer);
  4785. this.container = container;
  4786. this.eventBus = eventBus;
  4787. this.downloadManager = downloadManager;
  4788. this.reset();
  4789. this.eventBus.on('fileattachmentannotation', this._appendAttachment.bind(this));
  4790. }
  4791. _createClass(PDFAttachmentViewer, [{
  4792. key: "reset",
  4793. value: function reset() {
  4794. var keepRenderedCapability = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  4795. this.attachments = null;
  4796. this.container.textContent = '';
  4797. if (!keepRenderedCapability) {
  4798. this._renderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  4799. }
  4800. }
  4801. }, {
  4802. key: "_dispatchEvent",
  4803. value: function _dispatchEvent(attachmentsCount) {
  4804. this._renderedCapability.resolve();
  4805. this.eventBus.dispatch('attachmentsloaded', {
  4806. source: this,
  4807. attachmentsCount: attachmentsCount
  4808. });
  4809. }
  4810. }, {
  4811. key: "_bindPdfLink",
  4812. value: function _bindPdfLink(button, content, filename) {
  4813. if (this.downloadManager.disableCreateObjectURL) {
  4814. throw new Error('bindPdfLink: Unsupported "disableCreateObjectURL" value.');
  4815. }
  4816. var blobUrl;
  4817. button.onclick = function () {
  4818. if (!blobUrl) {
  4819. blobUrl = (0, _pdfjsLib.createObjectURL)(content, 'application/pdf');
  4820. }
  4821. var viewerUrl;
  4822. viewerUrl = '?file=' + encodeURIComponent(blobUrl + '#' + filename);
  4823. window.open(viewerUrl);
  4824. return false;
  4825. };
  4826. }
  4827. }, {
  4828. key: "_bindLink",
  4829. value: function _bindLink(button, content, filename) {
  4830. var _this = this;
  4831. button.onclick = function () {
  4832. _this.downloadManager.downloadData(content, filename, '');
  4833. return false;
  4834. };
  4835. }
  4836. }, {
  4837. key: "render",
  4838. value: function render(_ref2) {
  4839. var attachments = _ref2.attachments,
  4840. _ref2$keepRenderedCap = _ref2.keepRenderedCapability,
  4841. keepRenderedCapability = _ref2$keepRenderedCap === void 0 ? false : _ref2$keepRenderedCap;
  4842. var attachmentsCount = 0;
  4843. if (this.attachments) {
  4844. this.reset(keepRenderedCapability === true);
  4845. }
  4846. this.attachments = attachments || null;
  4847. if (!attachments) {
  4848. this._dispatchEvent(attachmentsCount);
  4849. return;
  4850. }
  4851. var names = Object.keys(attachments).sort(function (a, b) {
  4852. return a.toLowerCase().localeCompare(b.toLowerCase());
  4853. });
  4854. attachmentsCount = names.length;
  4855. for (var i = 0; i < attachmentsCount; i++) {
  4856. var item = attachments[names[i]];
  4857. var filename = (0, _pdfjsLib.removeNullCharacters)((0, _pdfjsLib.getFilenameFromUrl)(item.filename));
  4858. var div = document.createElement('div');
  4859. div.className = 'attachmentsItem';
  4860. var button = document.createElement('button');
  4861. button.textContent = filename;
  4862. if (/\.pdf$/i.test(filename) && !this.downloadManager.disableCreateObjectURL) {
  4863. this._bindPdfLink(button, item.content, filename);
  4864. } else {
  4865. this._bindLink(button, item.content, filename);
  4866. }
  4867. div.appendChild(button);
  4868. this.container.appendChild(div);
  4869. }
  4870. this._dispatchEvent(attachmentsCount);
  4871. }
  4872. }, {
  4873. key: "_appendAttachment",
  4874. value: function _appendAttachment(_ref3) {
  4875. var _this2 = this;
  4876. var id = _ref3.id,
  4877. filename = _ref3.filename,
  4878. content = _ref3.content;
  4879. this._renderedCapability.promise.then(function () {
  4880. var attachments = _this2.attachments;
  4881. if (!attachments) {
  4882. attachments = Object.create(null);
  4883. } else {
  4884. for (var name in attachments) {
  4885. if (id === name) {
  4886. return;
  4887. }
  4888. }
  4889. }
  4890. attachments[id] = {
  4891. filename: filename,
  4892. content: content
  4893. };
  4894. _this2.render({
  4895. attachments: attachments,
  4896. keepRenderedCapability: true
  4897. });
  4898. });
  4899. }
  4900. }]);
  4901. return PDFAttachmentViewer;
  4902. }();
  4903. exports.PDFAttachmentViewer = PDFAttachmentViewer;
  4904. /***/ }),
  4905. /* 17 */
  4906. /***/ (function(module, exports, __webpack_require__) {
  4907. "use strict";
  4908. Object.defineProperty(exports, "__esModule", {
  4909. value: true
  4910. });
  4911. exports.PDFDocumentProperties = void 0;
  4912. var _ui_utils = __webpack_require__(6);
  4913. var _pdfjsLib = __webpack_require__(7);
  4914. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
  4915. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
  4916. 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; }
  4917. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  4918. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4919. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4920. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  4921. var DEFAULT_FIELD_CONTENT = '-';
  4922. var NON_METRIC_LOCALES = ['en-us', 'en-lr', 'my'];
  4923. var US_PAGE_NAMES = {
  4924. '8.5x11': 'Letter',
  4925. '8.5x14': 'Legal'
  4926. };
  4927. var METRIC_PAGE_NAMES = {
  4928. '297x420': 'A3',
  4929. '210x297': 'A4'
  4930. };
  4931. function getPageName(size, isPortrait, pageNames) {
  4932. var width = isPortrait ? size.width : size.height;
  4933. var height = isPortrait ? size.height : size.width;
  4934. return pageNames["".concat(width, "x").concat(height)];
  4935. }
  4936. var PDFDocumentProperties =
  4937. /*#__PURE__*/
  4938. function () {
  4939. function PDFDocumentProperties(_ref, overlayManager, eventBus) {
  4940. var _this = this;
  4941. var overlayName = _ref.overlayName,
  4942. fields = _ref.fields,
  4943. container = _ref.container,
  4944. closeButton = _ref.closeButton;
  4945. var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
  4946. _classCallCheck(this, PDFDocumentProperties);
  4947. this.overlayName = overlayName;
  4948. this.fields = fields;
  4949. this.container = container;
  4950. this.overlayManager = overlayManager;
  4951. this.l10n = l10n;
  4952. this._reset();
  4953. if (closeButton) {
  4954. closeButton.addEventListener('click', this.close.bind(this));
  4955. }
  4956. this.overlayManager.register(this.overlayName, this.container, this.close.bind(this));
  4957. if (eventBus) {
  4958. eventBus.on('pagechanging', function (evt) {
  4959. _this._currentPageNumber = evt.pageNumber;
  4960. });
  4961. eventBus.on('rotationchanging', function (evt) {
  4962. _this._pagesRotation = evt.pagesRotation;
  4963. });
  4964. }
  4965. this._isNonMetricLocale = true;
  4966. l10n.getLanguage().then(function (locale) {
  4967. _this._isNonMetricLocale = NON_METRIC_LOCALES.includes(locale);
  4968. });
  4969. }
  4970. _createClass(PDFDocumentProperties, [{
  4971. key: "open",
  4972. value: function open() {
  4973. var _this2 = this;
  4974. var freezeFieldData = function freezeFieldData(data) {
  4975. Object.defineProperty(_this2, 'fieldData', {
  4976. value: Object.freeze(data),
  4977. writable: false,
  4978. enumerable: true,
  4979. configurable: true
  4980. });
  4981. };
  4982. Promise.all([this.overlayManager.open(this.overlayName), this._dataAvailableCapability.promise]).then(function () {
  4983. var currentPageNumber = _this2._currentPageNumber;
  4984. var pagesRotation = _this2._pagesRotation;
  4985. if (_this2.fieldData && currentPageNumber === _this2.fieldData['_currentPageNumber'] && pagesRotation === _this2.fieldData['_pagesRotation']) {
  4986. _this2._updateUI();
  4987. return;
  4988. }
  4989. _this2.pdfDocument.getMetadata().then(function (_ref2) {
  4990. var info = _ref2.info,
  4991. metadata = _ref2.metadata,
  4992. contentDispositionFilename = _ref2.contentDispositionFilename;
  4993. return Promise.all([info, metadata, contentDispositionFilename || (0, _ui_utils.getPDFFileNameFromURL)(_this2.url || ''), _this2._parseFileSize(_this2.maybeFileSize), _this2._parseDate(info.CreationDate), _this2._parseDate(info.ModDate), _this2.pdfDocument.getPage(currentPageNumber).then(function (pdfPage) {
  4994. return _this2._parsePageSize((0, _ui_utils.getPageSizeInches)(pdfPage), pagesRotation);
  4995. }), _this2._parseLinearization(info.IsLinearized)]);
  4996. }).then(function (_ref3) {
  4997. var _ref4 = _slicedToArray(_ref3, 8),
  4998. info = _ref4[0],
  4999. metadata = _ref4[1],
  5000. fileName = _ref4[2],
  5001. fileSize = _ref4[3],
  5002. creationDate = _ref4[4],
  5003. modDate = _ref4[5],
  5004. pageSize = _ref4[6],
  5005. isLinearized = _ref4[7];
  5006. freezeFieldData({
  5007. 'fileName': fileName,
  5008. 'fileSize': fileSize,
  5009. 'title': info.Title,
  5010. 'author': info.Author,
  5011. 'subject': info.Subject,
  5012. 'keywords': info.Keywords,
  5013. 'creationDate': creationDate,
  5014. 'modificationDate': modDate,
  5015. 'creator': info.Creator,
  5016. 'producer': info.Producer,
  5017. 'version': info.PDFFormatVersion,
  5018. 'pageCount': _this2.pdfDocument.numPages,
  5019. 'pageSize': pageSize,
  5020. 'linearized': isLinearized,
  5021. '_currentPageNumber': currentPageNumber,
  5022. '_pagesRotation': pagesRotation
  5023. });
  5024. _this2._updateUI();
  5025. return _this2.pdfDocument.getDownloadInfo();
  5026. }).then(function (_ref5) {
  5027. var length = _ref5.length;
  5028. _this2.maybeFileSize = length;
  5029. return _this2._parseFileSize(length);
  5030. }).then(function (fileSize) {
  5031. if (fileSize === _this2.fieldData['fileSize']) {
  5032. return;
  5033. }
  5034. var data = Object.assign(Object.create(null), _this2.fieldData);
  5035. data['fileSize'] = fileSize;
  5036. freezeFieldData(data);
  5037. _this2._updateUI();
  5038. });
  5039. });
  5040. }
  5041. }, {
  5042. key: "close",
  5043. value: function close() {
  5044. this.overlayManager.close(this.overlayName);
  5045. }
  5046. }, {
  5047. key: "setDocument",
  5048. value: function setDocument(pdfDocument) {
  5049. var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  5050. if (this.pdfDocument) {
  5051. this._reset();
  5052. this._updateUI(true);
  5053. }
  5054. if (!pdfDocument) {
  5055. return;
  5056. }
  5057. this.pdfDocument = pdfDocument;
  5058. this.url = url;
  5059. this._dataAvailableCapability.resolve();
  5060. }
  5061. }, {
  5062. key: "setFileSize",
  5063. value: function setFileSize(fileSize) {
  5064. if (Number.isInteger(fileSize) && fileSize > 0) {
  5065. this.maybeFileSize = fileSize;
  5066. }
  5067. }
  5068. }, {
  5069. key: "_reset",
  5070. value: function _reset() {
  5071. this.pdfDocument = null;
  5072. this.url = null;
  5073. this.maybeFileSize = 0;
  5074. delete this.fieldData;
  5075. this._dataAvailableCapability = (0, _pdfjsLib.createPromiseCapability)();
  5076. this._currentPageNumber = 1;
  5077. this._pagesRotation = 0;
  5078. }
  5079. }, {
  5080. key: "_updateUI",
  5081. value: function _updateUI() {
  5082. var reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  5083. if (reset || !this.fieldData) {
  5084. for (var id in this.fields) {
  5085. this.fields[id].textContent = DEFAULT_FIELD_CONTENT;
  5086. }
  5087. return;
  5088. }
  5089. if (this.overlayManager.active !== this.overlayName) {
  5090. return;
  5091. }
  5092. for (var _id in this.fields) {
  5093. var content = this.fieldData[_id];
  5094. this.fields[_id].textContent = content || content === 0 ? content : DEFAULT_FIELD_CONTENT;
  5095. }
  5096. }
  5097. }, {
  5098. key: "_parseFileSize",
  5099. value: function _parseFileSize() {
  5100. var fileSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  5101. var kb = fileSize / 1024;
  5102. if (!kb) {
  5103. return Promise.resolve(undefined);
  5104. } else if (kb < 1024) {
  5105. return this.l10n.get('document_properties_kb', {
  5106. size_kb: (+kb.toPrecision(3)).toLocaleString(),
  5107. size_b: fileSize.toLocaleString()
  5108. }, '{{size_kb}} KB ({{size_b}} bytes)');
  5109. }
  5110. return this.l10n.get('document_properties_mb', {
  5111. size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),
  5112. size_b: fileSize.toLocaleString()
  5113. }, '{{size_mb}} MB ({{size_b}} bytes)');
  5114. }
  5115. }, {
  5116. key: "_parsePageSize",
  5117. value: function _parsePageSize(pageSizeInches, pagesRotation) {
  5118. var _this3 = this;
  5119. if (!pageSizeInches) {
  5120. return Promise.resolve(undefined);
  5121. }
  5122. if (pagesRotation % 180 !== 0) {
  5123. pageSizeInches = {
  5124. width: pageSizeInches.height,
  5125. height: pageSizeInches.width
  5126. };
  5127. }
  5128. var isPortrait = (0, _ui_utils.isPortraitOrientation)(pageSizeInches);
  5129. var sizeInches = {
  5130. width: Math.round(pageSizeInches.width * 100) / 100,
  5131. height: Math.round(pageSizeInches.height * 100) / 100
  5132. };
  5133. var sizeMillimeters = {
  5134. width: Math.round(pageSizeInches.width * 25.4 * 10) / 10,
  5135. height: Math.round(pageSizeInches.height * 25.4 * 10) / 10
  5136. };
  5137. var pageName = null;
  5138. var name = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES);
  5139. if (!name && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) {
  5140. var exactMillimeters = {
  5141. width: pageSizeInches.width * 25.4,
  5142. height: pageSizeInches.height * 25.4
  5143. };
  5144. var intMillimeters = {
  5145. width: Math.round(sizeMillimeters.width),
  5146. height: Math.round(sizeMillimeters.height)
  5147. };
  5148. if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) {
  5149. name = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES);
  5150. if (name) {
  5151. sizeInches = {
  5152. width: Math.round(intMillimeters.width / 25.4 * 100) / 100,
  5153. height: Math.round(intMillimeters.height / 25.4 * 100) / 100
  5154. };
  5155. sizeMillimeters = intMillimeters;
  5156. }
  5157. }
  5158. }
  5159. if (name) {
  5160. pageName = this.l10n.get('document_properties_page_size_name_' + name.toLowerCase(), null, name);
  5161. }
  5162. return Promise.all([this._isNonMetricLocale ? sizeInches : sizeMillimeters, this.l10n.get('document_properties_page_size_unit_' + (this._isNonMetricLocale ? 'inches' : 'millimeters'), null, this._isNonMetricLocale ? 'in' : 'mm'), pageName, this.l10n.get('document_properties_page_size_orientation_' + (isPortrait ? 'portrait' : 'landscape'), null, isPortrait ? 'portrait' : 'landscape')]).then(function (_ref6) {
  5163. var _ref7 = _slicedToArray(_ref6, 4),
  5164. _ref7$ = _ref7[0],
  5165. width = _ref7$.width,
  5166. height = _ref7$.height,
  5167. unit = _ref7[1],
  5168. name = _ref7[2],
  5169. orientation = _ref7[3];
  5170. return _this3.l10n.get('document_properties_page_size_dimension_' + (name ? 'name_' : '') + 'string', {
  5171. width: width.toLocaleString(),
  5172. height: height.toLocaleString(),
  5173. unit: unit,
  5174. name: name,
  5175. orientation: orientation
  5176. }, '{{width}} × {{height}} {{unit}} (' + (name ? '{{name}}, ' : '') + '{{orientation}})');
  5177. });
  5178. }
  5179. }, {
  5180. key: "_parseDate",
  5181. value: function _parseDate(inputDate) {
  5182. if (!inputDate) {
  5183. return;
  5184. }
  5185. var dateToParse = inputDate;
  5186. if (dateToParse.substring(0, 2) === 'D:') {
  5187. dateToParse = dateToParse.substring(2);
  5188. }
  5189. var year = parseInt(dateToParse.substring(0, 4), 10);
  5190. var month = parseInt(dateToParse.substring(4, 6), 10) - 1;
  5191. var day = parseInt(dateToParse.substring(6, 8), 10);
  5192. var hours = parseInt(dateToParse.substring(8, 10), 10);
  5193. var minutes = parseInt(dateToParse.substring(10, 12), 10);
  5194. var seconds = parseInt(dateToParse.substring(12, 14), 10);
  5195. var utRel = dateToParse.substring(14, 15);
  5196. var offsetHours = parseInt(dateToParse.substring(15, 17), 10);
  5197. var offsetMinutes = parseInt(dateToParse.substring(18, 20), 10);
  5198. if (utRel === '-') {
  5199. hours += offsetHours;
  5200. minutes += offsetMinutes;
  5201. } else if (utRel === '+') {
  5202. hours -= offsetHours;
  5203. minutes -= offsetMinutes;
  5204. }
  5205. var date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));
  5206. var dateString = date.toLocaleDateString();
  5207. var timeString = date.toLocaleTimeString();
  5208. return this.l10n.get('document_properties_date_string', {
  5209. date: dateString,
  5210. time: timeString
  5211. }, '{{date}}, {{time}}');
  5212. }
  5213. }, {
  5214. key: "_parseLinearization",
  5215. value: function _parseLinearization(isLinearized) {
  5216. return this.l10n.get('document_properties_linearized_' + (isLinearized ? 'yes' : 'no'), null, isLinearized ? 'Yes' : 'No');
  5217. }
  5218. }]);
  5219. return PDFDocumentProperties;
  5220. }();
  5221. exports.PDFDocumentProperties = PDFDocumentProperties;
  5222. /***/ }),
  5223. /* 18 */
  5224. /***/ (function(module, exports, __webpack_require__) {
  5225. "use strict";
  5226. Object.defineProperty(exports, "__esModule", {
  5227. value: true
  5228. });
  5229. exports.PDFFindBar = void 0;
  5230. var _ui_utils = __webpack_require__(6);
  5231. var _pdf_find_controller = __webpack_require__(19);
  5232. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5233. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5234. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  5235. var MATCHES_COUNT_LIMIT = 1000;
  5236. var PDFFindBar =
  5237. /*#__PURE__*/
  5238. function () {
  5239. function PDFFindBar(options) {
  5240. var _this = this;
  5241. var eventBus = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _ui_utils.getGlobalEventBus)();
  5242. var l10n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ui_utils.NullL10n;
  5243. _classCallCheck(this, PDFFindBar);
  5244. this.opened = false;
  5245. this.bar = options.bar || null;
  5246. this.toggleButton = options.toggleButton || null;
  5247. this.findField = options.findField || null;
  5248. this.highlightAll = options.highlightAllCheckbox || null;
  5249. this.caseSensitive = options.caseSensitiveCheckbox || null;
  5250. this.entireWord = options.entireWordCheckbox || null;
  5251. this.findMsg = options.findMsg || null;
  5252. this.findResultsCount = options.findResultsCount || null;
  5253. this.findPreviousButton = options.findPreviousButton || null;
  5254. this.findNextButton = options.findNextButton || null;
  5255. this.eventBus = eventBus;
  5256. this.l10n = l10n;
  5257. this.toggleButton.addEventListener('click', function () {
  5258. _this.toggle();
  5259. });
  5260. this.findField.addEventListener('input', function () {
  5261. _this.dispatchEvent('');
  5262. });
  5263. this.bar.addEventListener('keydown', function (e) {
  5264. switch (e.keyCode) {
  5265. case 13:
  5266. if (e.target === _this.findField) {
  5267. _this.dispatchEvent('again', e.shiftKey);
  5268. }
  5269. break;
  5270. case 27:
  5271. _this.close();
  5272. break;
  5273. }
  5274. });
  5275. this.findPreviousButton.addEventListener('click', function () {
  5276. _this.dispatchEvent('again', true);
  5277. });
  5278. this.findNextButton.addEventListener('click', function () {
  5279. _this.dispatchEvent('again', false);
  5280. });
  5281. this.highlightAll.addEventListener('click', function () {
  5282. _this.dispatchEvent('highlightallchange');
  5283. });
  5284. this.caseSensitive.addEventListener('click', function () {
  5285. _this.dispatchEvent('casesensitivitychange');
  5286. });
  5287. this.entireWord.addEventListener('click', function () {
  5288. _this.dispatchEvent('entirewordchange');
  5289. });
  5290. this.eventBus.on('resize', this._adjustWidth.bind(this));
  5291. }
  5292. _createClass(PDFFindBar, [{
  5293. key: "reset",
  5294. value: function reset() {
  5295. this.updateUIState();
  5296. }
  5297. }, {
  5298. key: "dispatchEvent",
  5299. value: function dispatchEvent(type, findPrev) {
  5300. this.eventBus.dispatch('find', {
  5301. source: this,
  5302. type: type,
  5303. query: this.findField.value,
  5304. phraseSearch: true,
  5305. caseSensitive: this.caseSensitive.checked,
  5306. entireWord: this.entireWord.checked,
  5307. highlightAll: this.highlightAll.checked,
  5308. findPrevious: findPrev
  5309. });
  5310. }
  5311. }, {
  5312. key: "updateUIState",
  5313. value: function updateUIState(state, previous, matchesCount) {
  5314. var _this2 = this;
  5315. var notFound = false;
  5316. var findMsg = '';
  5317. var status = '';
  5318. switch (state) {
  5319. case _pdf_find_controller.FindState.FOUND:
  5320. break;
  5321. case _pdf_find_controller.FindState.PENDING:
  5322. status = 'pending';
  5323. break;
  5324. case _pdf_find_controller.FindState.NOT_FOUND:
  5325. findMsg = this.l10n.get('find_not_found', null, 'Phrase not found');
  5326. notFound = true;
  5327. break;
  5328. case _pdf_find_controller.FindState.WRAPPED:
  5329. if (previous) {
  5330. findMsg = this.l10n.get('find_reached_top', null, 'Reached top of document, continued from bottom');
  5331. } else {
  5332. findMsg = this.l10n.get('find_reached_bottom', null, 'Reached end of document, continued from top');
  5333. }
  5334. break;
  5335. }
  5336. this.findField.classList.toggle('notFound', notFound);
  5337. this.findField.setAttribute('data-status', status);
  5338. Promise.resolve(findMsg).then(function (msg) {
  5339. _this2.findMsg.textContent = msg;
  5340. _this2._adjustWidth();
  5341. });
  5342. this.updateResultsCount(matchesCount);
  5343. }
  5344. }, {
  5345. key: "updateResultsCount",
  5346. value: function updateResultsCount() {
  5347. var _this3 = this;
  5348. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  5349. _ref$current = _ref.current,
  5350. current = _ref$current === void 0 ? 0 : _ref$current,
  5351. _ref$total = _ref.total,
  5352. total = _ref$total === void 0 ? 0 : _ref$total;
  5353. if (!this.findResultsCount) {
  5354. return;
  5355. }
  5356. var matchesCountMsg = '',
  5357. limit = MATCHES_COUNT_LIMIT;
  5358. if (total > 0) {
  5359. if (total > limit) {
  5360. matchesCountMsg = this.l10n.get('find_match_count_limit', {
  5361. limit: limit
  5362. }, 'More than {{limit}} match' + (limit !== 1 ? 'es' : ''));
  5363. } else {
  5364. matchesCountMsg = this.l10n.get('find_match_count', {
  5365. current: current,
  5366. total: total
  5367. }, '{{current}} of {{total}} match' + (total !== 1 ? 'es' : ''));
  5368. }
  5369. }
  5370. Promise.resolve(matchesCountMsg).then(function (msg) {
  5371. _this3.findResultsCount.textContent = msg;
  5372. _this3.findResultsCount.classList.toggle('hidden', !total);
  5373. _this3._adjustWidth();
  5374. });
  5375. }
  5376. }, {
  5377. key: "open",
  5378. value: function open() {
  5379. if (!this.opened) {
  5380. this.opened = true;
  5381. this.toggleButton.classList.add('toggled');
  5382. this.bar.classList.remove('hidden');
  5383. }
  5384. this.findField.select();
  5385. this.findField.focus();
  5386. this._adjustWidth();
  5387. }
  5388. }, {
  5389. key: "close",
  5390. value: function close() {
  5391. if (!this.opened) {
  5392. return;
  5393. }
  5394. this.opened = false;
  5395. this.toggleButton.classList.remove('toggled');
  5396. this.bar.classList.add('hidden');
  5397. this.eventBus.dispatch('findbarclose', {
  5398. source: this
  5399. });
  5400. }
  5401. }, {
  5402. key: "toggle",
  5403. value: function toggle() {
  5404. if (this.opened) {
  5405. this.close();
  5406. } else {
  5407. this.open();
  5408. }
  5409. }
  5410. }, {
  5411. key: "_adjustWidth",
  5412. value: function _adjustWidth() {
  5413. if (!this.opened) {
  5414. return;
  5415. }
  5416. this.bar.classList.remove('wrapContainers');
  5417. var findbarHeight = this.bar.clientHeight;
  5418. var inputContainerHeight = this.bar.firstElementChild.clientHeight;
  5419. if (findbarHeight > inputContainerHeight) {
  5420. this.bar.classList.add('wrapContainers');
  5421. }
  5422. }
  5423. }]);
  5424. return PDFFindBar;
  5425. }();
  5426. exports.PDFFindBar = PDFFindBar;
  5427. /***/ }),
  5428. /* 19 */
  5429. /***/ (function(module, exports, __webpack_require__) {
  5430. "use strict";
  5431. Object.defineProperty(exports, "__esModule", {
  5432. value: true
  5433. });
  5434. exports.PDFFindController = exports.FindState = void 0;
  5435. var _ui_utils = __webpack_require__(6);
  5436. var _pdfjsLib = __webpack_require__(7);
  5437. var _pdf_find_utils = __webpack_require__(20);
  5438. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5439. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5440. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  5441. var FindState = {
  5442. FOUND: 0,
  5443. NOT_FOUND: 1,
  5444. WRAPPED: 2,
  5445. PENDING: 3
  5446. };
  5447. exports.FindState = FindState;
  5448. var FIND_TIMEOUT = 250;
  5449. var MATCH_SCROLL_OFFSET_TOP = -50;
  5450. var MATCH_SCROLL_OFFSET_LEFT = -400;
  5451. var CHARACTERS_TO_NORMALIZE = {
  5452. "\u2018": '\'',
  5453. "\u2019": '\'',
  5454. "\u201A": '\'',
  5455. "\u201B": '\'',
  5456. "\u201C": '"',
  5457. "\u201D": '"',
  5458. "\u201E": '"',
  5459. "\u201F": '"',
  5460. "\xBC": '1/4',
  5461. "\xBD": '1/2',
  5462. "\xBE": '3/4'
  5463. };
  5464. var normalizationRegex = null;
  5465. function normalize(text) {
  5466. if (!normalizationRegex) {
  5467. var replace = Object.keys(CHARACTERS_TO_NORMALIZE).join('');
  5468. normalizationRegex = new RegExp("[".concat(replace, "]"), 'g');
  5469. }
  5470. return text.replace(normalizationRegex, function (ch) {
  5471. return CHARACTERS_TO_NORMALIZE[ch];
  5472. });
  5473. }
  5474. var PDFFindController =
  5475. /*#__PURE__*/
  5476. function () {
  5477. function PDFFindController(_ref) {
  5478. var linkService = _ref.linkService,
  5479. _ref$eventBus = _ref.eventBus,
  5480. eventBus = _ref$eventBus === void 0 ? (0, _ui_utils.getGlobalEventBus)() : _ref$eventBus;
  5481. _classCallCheck(this, PDFFindController);
  5482. this._linkService = linkService;
  5483. this._eventBus = eventBus;
  5484. this._reset();
  5485. eventBus.on('findbarclose', this._onFindBarClose.bind(this));
  5486. }
  5487. _createClass(PDFFindController, [{
  5488. key: "setDocument",
  5489. value: function setDocument(pdfDocument) {
  5490. if (this._pdfDocument) {
  5491. this._reset();
  5492. }
  5493. if (!pdfDocument) {
  5494. return;
  5495. }
  5496. this._pdfDocument = pdfDocument;
  5497. this._firstPageCapability.resolve();
  5498. }
  5499. }, {
  5500. key: "executeCommand",
  5501. value: function executeCommand(cmd, state) {
  5502. var _this = this;
  5503. if (!state) {
  5504. return;
  5505. }
  5506. var pdfDocument = this._pdfDocument;
  5507. if (this._state === null || this._shouldDirtyMatch(cmd, state)) {
  5508. this._dirtyMatch = true;
  5509. }
  5510. this._state = state;
  5511. if (cmd !== 'findhighlightallchange') {
  5512. this._updateUIState(FindState.PENDING);
  5513. }
  5514. this._firstPageCapability.promise.then(function () {
  5515. if (!_this._pdfDocument || pdfDocument && _this._pdfDocument !== pdfDocument) {
  5516. return;
  5517. }
  5518. _this._extractText();
  5519. var findbarClosed = !_this._highlightMatches;
  5520. var pendingTimeout = !!_this._findTimeout;
  5521. if (_this._findTimeout) {
  5522. clearTimeout(_this._findTimeout);
  5523. _this._findTimeout = null;
  5524. }
  5525. if (cmd === 'find') {
  5526. _this._findTimeout = setTimeout(function () {
  5527. _this._nextMatch();
  5528. _this._findTimeout = null;
  5529. }, FIND_TIMEOUT);
  5530. } else if (_this._dirtyMatch) {
  5531. _this._nextMatch();
  5532. } else if (cmd === 'findagain') {
  5533. _this._nextMatch();
  5534. if (findbarClosed && _this._state.highlightAll) {
  5535. _this._updateAllPages();
  5536. }
  5537. } else if (cmd === 'findhighlightallchange') {
  5538. if (pendingTimeout) {
  5539. _this._nextMatch();
  5540. } else {
  5541. _this._highlightMatches = true;
  5542. }
  5543. _this._updateAllPages();
  5544. } else {
  5545. _this._nextMatch();
  5546. }
  5547. });
  5548. }
  5549. }, {
  5550. key: "scrollMatchIntoView",
  5551. value: function scrollMatchIntoView(_ref2) {
  5552. var _ref2$element = _ref2.element,
  5553. element = _ref2$element === void 0 ? null : _ref2$element,
  5554. _ref2$pageIndex = _ref2.pageIndex,
  5555. pageIndex = _ref2$pageIndex === void 0 ? -1 : _ref2$pageIndex,
  5556. _ref2$matchIndex = _ref2.matchIndex,
  5557. matchIndex = _ref2$matchIndex === void 0 ? -1 : _ref2$matchIndex;
  5558. if (!this._scrollMatches || !element) {
  5559. return;
  5560. } else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) {
  5561. return;
  5562. } else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) {
  5563. return;
  5564. }
  5565. this._scrollMatches = false;
  5566. var spot = {
  5567. top: MATCH_SCROLL_OFFSET_TOP,
  5568. left: MATCH_SCROLL_OFFSET_LEFT
  5569. };
  5570. (0, _ui_utils.scrollIntoView)(element, spot, true);
  5571. }
  5572. }, {
  5573. key: "_reset",
  5574. value: function _reset() {
  5575. this._highlightMatches = false;
  5576. this._scrollMatches = false;
  5577. this._pdfDocument = null;
  5578. this._pageMatches = [];
  5579. this._pageMatchesLength = [];
  5580. this._state = null;
  5581. this._selected = {
  5582. pageIdx: -1,
  5583. matchIdx: -1
  5584. };
  5585. this._offset = {
  5586. pageIdx: null,
  5587. matchIdx: null,
  5588. wrapped: false
  5589. };
  5590. this._extractTextPromises = [];
  5591. this._pageContents = [];
  5592. this._matchesCountTotal = 0;
  5593. this._pagesToSearch = null;
  5594. this._pendingFindMatches = Object.create(null);
  5595. this._resumePageIdx = null;
  5596. this._dirtyMatch = false;
  5597. clearTimeout(this._findTimeout);
  5598. this._findTimeout = null;
  5599. this._firstPageCapability = (0, _pdfjsLib.createPromiseCapability)();
  5600. }
  5601. }, {
  5602. key: "_shouldDirtyMatch",
  5603. value: function _shouldDirtyMatch(cmd, state) {
  5604. if (state.query !== this._state.query) {
  5605. return true;
  5606. }
  5607. switch (cmd) {
  5608. case 'findagain':
  5609. var pageNumber = this._selected.pageIdx + 1;
  5610. var linkService = this._linkService;
  5611. if (pageNumber >= 1 && pageNumber <= linkService.pagesCount && linkService.page !== pageNumber && linkService.isPageVisible && !linkService.isPageVisible(pageNumber)) {
  5612. break;
  5613. }
  5614. return false;
  5615. case 'findhighlightallchange':
  5616. return false;
  5617. }
  5618. return true;
  5619. }
  5620. }, {
  5621. key: "_prepareMatches",
  5622. value: function _prepareMatches(matchesWithLength, matches, matchesLength) {
  5623. function isSubTerm(matchesWithLength, currentIndex) {
  5624. var currentElem = matchesWithLength[currentIndex];
  5625. var nextElem = matchesWithLength[currentIndex + 1];
  5626. if (currentIndex < matchesWithLength.length - 1 && currentElem.match === nextElem.match) {
  5627. currentElem.skipped = true;
  5628. return true;
  5629. }
  5630. for (var i = currentIndex - 1; i >= 0; i--) {
  5631. var prevElem = matchesWithLength[i];
  5632. if (prevElem.skipped) {
  5633. continue;
  5634. }
  5635. if (prevElem.match + prevElem.matchLength < currentElem.match) {
  5636. break;
  5637. }
  5638. if (prevElem.match + prevElem.matchLength >= currentElem.match + currentElem.matchLength) {
  5639. currentElem.skipped = true;
  5640. return true;
  5641. }
  5642. }
  5643. return false;
  5644. }
  5645. matchesWithLength.sort(function (a, b) {
  5646. return a.match === b.match ? a.matchLength - b.matchLength : a.match - b.match;
  5647. });
  5648. for (var i = 0, len = matchesWithLength.length; i < len; i++) {
  5649. if (isSubTerm(matchesWithLength, i)) {
  5650. continue;
  5651. }
  5652. matches.push(matchesWithLength[i].match);
  5653. matchesLength.push(matchesWithLength[i].matchLength);
  5654. }
  5655. }
  5656. }, {
  5657. key: "_isEntireWord",
  5658. value: function _isEntireWord(content, startIdx, length) {
  5659. if (startIdx > 0) {
  5660. var first = content.charCodeAt(startIdx);
  5661. var limit = content.charCodeAt(startIdx - 1);
  5662. if ((0, _pdf_find_utils.getCharacterType)(first) === (0, _pdf_find_utils.getCharacterType)(limit)) {
  5663. return false;
  5664. }
  5665. }
  5666. var endIdx = startIdx + length - 1;
  5667. if (endIdx < content.length - 1) {
  5668. var last = content.charCodeAt(endIdx);
  5669. var _limit = content.charCodeAt(endIdx + 1);
  5670. if ((0, _pdf_find_utils.getCharacterType)(last) === (0, _pdf_find_utils.getCharacterType)(_limit)) {
  5671. return false;
  5672. }
  5673. }
  5674. return true;
  5675. }
  5676. }, {
  5677. key: "_calculatePhraseMatch",
  5678. value: function _calculatePhraseMatch(query, pageIndex, pageContent, entireWord) {
  5679. var matches = [];
  5680. var queryLen = query.length;
  5681. var matchIdx = -queryLen;
  5682. while (true) {
  5683. matchIdx = pageContent.indexOf(query, matchIdx + queryLen);
  5684. if (matchIdx === -1) {
  5685. break;
  5686. }
  5687. if (entireWord && !this._isEntireWord(pageContent, matchIdx, queryLen)) {
  5688. continue;
  5689. }
  5690. matches.push(matchIdx);
  5691. }
  5692. this._pageMatches[pageIndex] = matches;
  5693. }
  5694. }, {
  5695. key: "_calculateWordMatch",
  5696. value: function _calculateWordMatch(query, pageIndex, pageContent, entireWord) {
  5697. var matchesWithLength = [];
  5698. var queryArray = query.match(/\S+/g);
  5699. for (var i = 0, len = queryArray.length; i < len; i++) {
  5700. var subquery = queryArray[i];
  5701. var subqueryLen = subquery.length;
  5702. var matchIdx = -subqueryLen;
  5703. while (true) {
  5704. matchIdx = pageContent.indexOf(subquery, matchIdx + subqueryLen);
  5705. if (matchIdx === -1) {
  5706. break;
  5707. }
  5708. if (entireWord && !this._isEntireWord(pageContent, matchIdx, subqueryLen)) {
  5709. continue;
  5710. }
  5711. matchesWithLength.push({
  5712. match: matchIdx,
  5713. matchLength: subqueryLen,
  5714. skipped: false
  5715. });
  5716. }
  5717. }
  5718. this._pageMatchesLength[pageIndex] = [];
  5719. this._pageMatches[pageIndex] = [];
  5720. this._prepareMatches(matchesWithLength, this._pageMatches[pageIndex], this._pageMatchesLength[pageIndex]);
  5721. }
  5722. }, {
  5723. key: "_calculateMatch",
  5724. value: function _calculateMatch(pageIndex) {
  5725. var pageContent = this._pageContents[pageIndex];
  5726. var query = this._query;
  5727. var _this$_state = this._state,
  5728. caseSensitive = _this$_state.caseSensitive,
  5729. entireWord = _this$_state.entireWord,
  5730. phraseSearch = _this$_state.phraseSearch;
  5731. if (query.length === 0) {
  5732. return;
  5733. }
  5734. if (!caseSensitive) {
  5735. pageContent = pageContent.toLowerCase();
  5736. query = query.toLowerCase();
  5737. }
  5738. if (phraseSearch) {
  5739. this._calculatePhraseMatch(query, pageIndex, pageContent, entireWord);
  5740. } else {
  5741. this._calculateWordMatch(query, pageIndex, pageContent, entireWord);
  5742. }
  5743. if (this._state.highlightAll) {
  5744. this._updatePage(pageIndex);
  5745. }
  5746. if (this._resumePageIdx === pageIndex) {
  5747. this._resumePageIdx = null;
  5748. this._nextPageMatch();
  5749. }
  5750. var pageMatchesCount = this._pageMatches[pageIndex].length;
  5751. if (pageMatchesCount > 0) {
  5752. this._matchesCountTotal += pageMatchesCount;
  5753. this._updateUIResultsCount();
  5754. }
  5755. }
  5756. }, {
  5757. key: "_extractText",
  5758. value: function _extractText() {
  5759. var _this2 = this;
  5760. if (this._extractTextPromises.length > 0) {
  5761. return;
  5762. }
  5763. var promise = Promise.resolve();
  5764. var _loop = function _loop(i, ii) {
  5765. var extractTextCapability = (0, _pdfjsLib.createPromiseCapability)();
  5766. _this2._extractTextPromises[i] = extractTextCapability.promise;
  5767. promise = promise.then(function () {
  5768. return _this2._pdfDocument.getPage(i + 1).then(function (pdfPage) {
  5769. return pdfPage.getTextContent({
  5770. normalizeWhitespace: true
  5771. });
  5772. }).then(function (textContent) {
  5773. var textItems = textContent.items;
  5774. var strBuf = [];
  5775. for (var j = 0, jj = textItems.length; j < jj; j++) {
  5776. strBuf.push(textItems[j].str);
  5777. }
  5778. _this2._pageContents[i] = normalize(strBuf.join(''));
  5779. extractTextCapability.resolve(i);
  5780. }, function (reason) {
  5781. console.error("Unable to get text content for page ".concat(i + 1), reason);
  5782. _this2._pageContents[i] = '';
  5783. extractTextCapability.resolve(i);
  5784. });
  5785. });
  5786. };
  5787. for (var i = 0, ii = this._linkService.pagesCount; i < ii; i++) {
  5788. _loop(i, ii);
  5789. }
  5790. }
  5791. }, {
  5792. key: "_updatePage",
  5793. value: function _updatePage(index) {
  5794. if (this._scrollMatches && this._selected.pageIdx === index) {
  5795. this._linkService.page = index + 1;
  5796. }
  5797. this._eventBus.dispatch('updatetextlayermatches', {
  5798. source: this,
  5799. pageIndex: index
  5800. });
  5801. }
  5802. }, {
  5803. key: "_updateAllPages",
  5804. value: function _updateAllPages() {
  5805. this._eventBus.dispatch('updatetextlayermatches', {
  5806. source: this,
  5807. pageIndex: -1
  5808. });
  5809. }
  5810. }, {
  5811. key: "_nextMatch",
  5812. value: function _nextMatch() {
  5813. var _this3 = this;
  5814. var previous = this._state.findPrevious;
  5815. var currentPageIndex = this._linkService.page - 1;
  5816. var numPages = this._linkService.pagesCount;
  5817. this._highlightMatches = true;
  5818. if (this._dirtyMatch) {
  5819. this._dirtyMatch = false;
  5820. this._selected.pageIdx = this._selected.matchIdx = -1;
  5821. this._offset.pageIdx = currentPageIndex;
  5822. this._offset.matchIdx = null;
  5823. this._offset.wrapped = false;
  5824. this._resumePageIdx = null;
  5825. this._pageMatches.length = 0;
  5826. this._pageMatchesLength.length = 0;
  5827. this._matchesCountTotal = 0;
  5828. this._updateAllPages();
  5829. for (var i = 0; i < numPages; i++) {
  5830. if (this._pendingFindMatches[i] === true) {
  5831. continue;
  5832. }
  5833. this._pendingFindMatches[i] = true;
  5834. this._extractTextPromises[i].then(function (pageIdx) {
  5835. delete _this3._pendingFindMatches[pageIdx];
  5836. _this3._calculateMatch(pageIdx);
  5837. });
  5838. }
  5839. }
  5840. if (this._query === '') {
  5841. this._updateUIState(FindState.FOUND);
  5842. return;
  5843. }
  5844. if (this._resumePageIdx) {
  5845. return;
  5846. }
  5847. var offset = this._offset;
  5848. this._pagesToSearch = numPages;
  5849. if (offset.matchIdx !== null) {
  5850. var numPageMatches = this._pageMatches[offset.pageIdx].length;
  5851. if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) {
  5852. offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1;
  5853. this._updateMatch(true);
  5854. return;
  5855. }
  5856. this._advanceOffsetPage(previous);
  5857. }
  5858. this._nextPageMatch();
  5859. }
  5860. }, {
  5861. key: "_matchesReady",
  5862. value: function _matchesReady(matches) {
  5863. var offset = this._offset;
  5864. var numMatches = matches.length;
  5865. var previous = this._state.findPrevious;
  5866. if (numMatches) {
  5867. offset.matchIdx = previous ? numMatches - 1 : 0;
  5868. this._updateMatch(true);
  5869. return true;
  5870. }
  5871. this._advanceOffsetPage(previous);
  5872. if (offset.wrapped) {
  5873. offset.matchIdx = null;
  5874. if (this._pagesToSearch < 0) {
  5875. this._updateMatch(false);
  5876. return true;
  5877. }
  5878. }
  5879. return false;
  5880. }
  5881. }, {
  5882. key: "_nextPageMatch",
  5883. value: function _nextPageMatch() {
  5884. if (this._resumePageIdx !== null) {
  5885. console.error('There can only be one pending page.');
  5886. }
  5887. var matches = null;
  5888. do {
  5889. var pageIdx = this._offset.pageIdx;
  5890. matches = this._pageMatches[pageIdx];
  5891. if (!matches) {
  5892. this._resumePageIdx = pageIdx;
  5893. break;
  5894. }
  5895. } while (!this._matchesReady(matches));
  5896. }
  5897. }, {
  5898. key: "_advanceOffsetPage",
  5899. value: function _advanceOffsetPage(previous) {
  5900. var offset = this._offset;
  5901. var numPages = this._linkService.pagesCount;
  5902. offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1;
  5903. offset.matchIdx = null;
  5904. this._pagesToSearch--;
  5905. if (offset.pageIdx >= numPages || offset.pageIdx < 0) {
  5906. offset.pageIdx = previous ? numPages - 1 : 0;
  5907. offset.wrapped = true;
  5908. }
  5909. }
  5910. }, {
  5911. key: "_updateMatch",
  5912. value: function _updateMatch() {
  5913. var found = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  5914. var state = FindState.NOT_FOUND;
  5915. var wrapped = this._offset.wrapped;
  5916. this._offset.wrapped = false;
  5917. if (found) {
  5918. var previousPage = this._selected.pageIdx;
  5919. this._selected.pageIdx = this._offset.pageIdx;
  5920. this._selected.matchIdx = this._offset.matchIdx;
  5921. state = wrapped ? FindState.WRAPPED : FindState.FOUND;
  5922. if (previousPage !== -1 && previousPage !== this._selected.pageIdx) {
  5923. this._updatePage(previousPage);
  5924. }
  5925. }
  5926. this._updateUIState(state, this._state.findPrevious);
  5927. if (this._selected.pageIdx !== -1) {
  5928. this._scrollMatches = true;
  5929. this._updatePage(this._selected.pageIdx);
  5930. }
  5931. }
  5932. }, {
  5933. key: "_onFindBarClose",
  5934. value: function _onFindBarClose(evt) {
  5935. var _this4 = this;
  5936. var pdfDocument = this._pdfDocument;
  5937. this._firstPageCapability.promise.then(function () {
  5938. if (!_this4._pdfDocument || pdfDocument && _this4._pdfDocument !== pdfDocument) {
  5939. return;
  5940. }
  5941. if (_this4._findTimeout) {
  5942. clearTimeout(_this4._findTimeout);
  5943. _this4._findTimeout = null;
  5944. }
  5945. if (_this4._resumePageIdx) {
  5946. _this4._resumePageIdx = null;
  5947. _this4._dirtyMatch = true;
  5948. }
  5949. _this4._updateUIState(FindState.FOUND);
  5950. _this4._highlightMatches = false;
  5951. _this4._updateAllPages();
  5952. });
  5953. }
  5954. }, {
  5955. key: "_requestMatchesCount",
  5956. value: function _requestMatchesCount() {
  5957. var _this$_selected = this._selected,
  5958. pageIdx = _this$_selected.pageIdx,
  5959. matchIdx = _this$_selected.matchIdx;
  5960. var current = 0,
  5961. total = this._matchesCountTotal;
  5962. if (matchIdx !== -1) {
  5963. for (var i = 0; i < pageIdx; i++) {
  5964. current += this._pageMatches[i] && this._pageMatches[i].length || 0;
  5965. }
  5966. current += matchIdx + 1;
  5967. }
  5968. if (current < 1 || current > total) {
  5969. current = total = 0;
  5970. }
  5971. return {
  5972. current: current,
  5973. total: total
  5974. };
  5975. }
  5976. }, {
  5977. key: "_updateUIResultsCount",
  5978. value: function _updateUIResultsCount() {
  5979. this._eventBus.dispatch('updatefindmatchescount', {
  5980. source: this,
  5981. matchesCount: this._requestMatchesCount()
  5982. });
  5983. }
  5984. }, {
  5985. key: "_updateUIState",
  5986. value: function _updateUIState(state, previous) {
  5987. this._eventBus.dispatch('updatefindcontrolstate', {
  5988. source: this,
  5989. state: state,
  5990. previous: previous,
  5991. matchesCount: this._requestMatchesCount()
  5992. });
  5993. }
  5994. }, {
  5995. key: "highlightMatches",
  5996. get: function get() {
  5997. return this._highlightMatches;
  5998. }
  5999. }, {
  6000. key: "pageMatches",
  6001. get: function get() {
  6002. return this._pageMatches;
  6003. }
  6004. }, {
  6005. key: "pageMatchesLength",
  6006. get: function get() {
  6007. return this._pageMatchesLength;
  6008. }
  6009. }, {
  6010. key: "selected",
  6011. get: function get() {
  6012. return this._selected;
  6013. }
  6014. }, {
  6015. key: "state",
  6016. get: function get() {
  6017. return this._state;
  6018. }
  6019. }, {
  6020. key: "_query",
  6021. get: function get() {
  6022. if (this._state.query !== this._rawQuery) {
  6023. this._rawQuery = this._state.query;
  6024. this._normalizedQuery = normalize(this._state.query);
  6025. }
  6026. return this._normalizedQuery;
  6027. }
  6028. }]);
  6029. return PDFFindController;
  6030. }();
  6031. exports.PDFFindController = PDFFindController;
  6032. /***/ }),
  6033. /* 20 */
  6034. /***/ (function(module, exports, __webpack_require__) {
  6035. "use strict";
  6036. Object.defineProperty(exports, "__esModule", {
  6037. value: true
  6038. });
  6039. exports.getCharacterType = getCharacterType;
  6040. exports.CharacterType = void 0;
  6041. var CharacterType = {
  6042. SPACE: 0,
  6043. ALPHA_LETTER: 1,
  6044. PUNCT: 2,
  6045. HAN_LETTER: 3,
  6046. KATAKANA_LETTER: 4,
  6047. HIRAGANA_LETTER: 5,
  6048. HALFWIDTH_KATAKANA_LETTER: 6,
  6049. THAI_LETTER: 7
  6050. };
  6051. exports.CharacterType = CharacterType;
  6052. function isAlphabeticalScript(charCode) {
  6053. return charCode < 0x2E80;
  6054. }
  6055. function isAscii(charCode) {
  6056. return (charCode & 0xFF80) === 0;
  6057. }
  6058. function isAsciiAlpha(charCode) {
  6059. return charCode >= 0x61 && charCode <= 0x7A || charCode >= 0x41 && charCode <= 0x5A;
  6060. }
  6061. function isAsciiDigit(charCode) {
  6062. return charCode >= 0x30 && charCode <= 0x39;
  6063. }
  6064. function isAsciiSpace(charCode) {
  6065. return charCode === 0x20 || charCode === 0x09 || charCode === 0x0D || charCode === 0x0A;
  6066. }
  6067. function isHan(charCode) {
  6068. return charCode >= 0x3400 && charCode <= 0x9FFF || charCode >= 0xF900 && charCode <= 0xFAFF;
  6069. }
  6070. function isKatakana(charCode) {
  6071. return charCode >= 0x30A0 && charCode <= 0x30FF;
  6072. }
  6073. function isHiragana(charCode) {
  6074. return charCode >= 0x3040 && charCode <= 0x309F;
  6075. }
  6076. function isHalfwidthKatakana(charCode) {
  6077. return charCode >= 0xFF60 && charCode <= 0xFF9F;
  6078. }
  6079. function isThai(charCode) {
  6080. return (charCode & 0xFF80) === 0x0E00;
  6081. }
  6082. function getCharacterType(charCode) {
  6083. if (isAlphabeticalScript(charCode)) {
  6084. if (isAscii(charCode)) {
  6085. if (isAsciiSpace(charCode)) {
  6086. return CharacterType.SPACE;
  6087. } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5F) {
  6088. return CharacterType.ALPHA_LETTER;
  6089. }
  6090. return CharacterType.PUNCT;
  6091. } else if (isThai(charCode)) {
  6092. return CharacterType.THAI_LETTER;
  6093. } else if (charCode === 0xA0) {
  6094. return CharacterType.SPACE;
  6095. }
  6096. return CharacterType.ALPHA_LETTER;
  6097. }
  6098. if (isHan(charCode)) {
  6099. return CharacterType.HAN_LETTER;
  6100. } else if (isKatakana(charCode)) {
  6101. return CharacterType.KATAKANA_LETTER;
  6102. } else if (isHiragana(charCode)) {
  6103. return CharacterType.HIRAGANA_LETTER;
  6104. } else if (isHalfwidthKatakana(charCode)) {
  6105. return CharacterType.HALFWIDTH_KATAKANA_LETTER;
  6106. }
  6107. return CharacterType.ALPHA_LETTER;
  6108. }
  6109. /***/ }),
  6110. /* 21 */
  6111. /***/ (function(module, exports, __webpack_require__) {
  6112. "use strict";
  6113. Object.defineProperty(exports, "__esModule", {
  6114. value: true
  6115. });
  6116. exports.isDestHashesEqual = isDestHashesEqual;
  6117. exports.isDestArraysEqual = isDestArraysEqual;
  6118. exports.PDFHistory = void 0;
  6119. var _ui_utils = __webpack_require__(6);
  6120. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  6121. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
  6122. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
  6123. 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; }
  6124. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  6125. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6126. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  6127. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6128. var HASH_CHANGE_TIMEOUT = 1000;
  6129. var POSITION_UPDATED_THRESHOLD = 50;
  6130. var UPDATE_VIEWAREA_TIMEOUT = 1000;
  6131. function getCurrentHash() {
  6132. return document.location.hash;
  6133. }
  6134. function parseCurrentHash(linkService) {
  6135. var hash = unescape(getCurrentHash()).substring(1);
  6136. var params = (0, _ui_utils.parseQueryString)(hash);
  6137. var page = params.page | 0;
  6138. if (!(Number.isInteger(page) && page > 0 && page <= linkService.pagesCount)) {
  6139. page = null;
  6140. }
  6141. return {
  6142. hash: hash,
  6143. page: page,
  6144. rotation: linkService.rotation
  6145. };
  6146. }
  6147. var PDFHistory =
  6148. /*#__PURE__*/
  6149. function () {
  6150. function PDFHistory(_ref) {
  6151. var _this = this;
  6152. var linkService = _ref.linkService,
  6153. eventBus = _ref.eventBus;
  6154. _classCallCheck(this, PDFHistory);
  6155. this.linkService = linkService;
  6156. this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
  6157. this.initialized = false;
  6158. this.initialBookmark = null;
  6159. this.initialRotation = null;
  6160. this._boundEvents = Object.create(null);
  6161. this._isViewerInPresentationMode = false;
  6162. this._isPagesLoaded = false;
  6163. this.eventBus.on('presentationmodechanged', function (evt) {
  6164. _this._isViewerInPresentationMode = evt.active || evt.switchInProgress;
  6165. });
  6166. this.eventBus.on('pagesloaded', function (evt) {
  6167. _this._isPagesLoaded = !!evt.pagesCount;
  6168. });
  6169. }
  6170. _createClass(PDFHistory, [{
  6171. key: "initialize",
  6172. value: function initialize(_ref2) {
  6173. var fingerprint = _ref2.fingerprint,
  6174. _ref2$resetHistory = _ref2.resetHistory,
  6175. resetHistory = _ref2$resetHistory === void 0 ? false : _ref2$resetHistory,
  6176. _ref2$updateUrl = _ref2.updateUrl,
  6177. updateUrl = _ref2$updateUrl === void 0 ? false : _ref2$updateUrl;
  6178. if (!fingerprint || typeof fingerprint !== 'string') {
  6179. console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.');
  6180. return;
  6181. }
  6182. var reInitialized = this.initialized && this.fingerprint !== fingerprint;
  6183. this.fingerprint = fingerprint;
  6184. this._updateUrl = updateUrl === true;
  6185. if (!this.initialized) {
  6186. this._bindEvents();
  6187. }
  6188. var state = window.history.state;
  6189. this.initialized = true;
  6190. this.initialBookmark = null;
  6191. this.initialRotation = null;
  6192. this._popStateInProgress = false;
  6193. this._blockHashChange = 0;
  6194. this._currentHash = getCurrentHash();
  6195. this._numPositionUpdates = 0;
  6196. this._uid = this._maxUid = 0;
  6197. this._destination = null;
  6198. this._position = null;
  6199. if (!this._isValidState(state, true) || resetHistory) {
  6200. var _parseCurrentHash = parseCurrentHash(this.linkService),
  6201. hash = _parseCurrentHash.hash,
  6202. page = _parseCurrentHash.page,
  6203. rotation = _parseCurrentHash.rotation;
  6204. if (!hash || reInitialized || resetHistory) {
  6205. this._pushOrReplaceState(null, true);
  6206. return;
  6207. }
  6208. this._pushOrReplaceState({
  6209. hash: hash,
  6210. page: page,
  6211. rotation: rotation
  6212. }, true);
  6213. return;
  6214. }
  6215. var destination = state.destination;
  6216. this._updateInternalState(destination, state.uid, true);
  6217. if (this._uid > this._maxUid) {
  6218. this._maxUid = this._uid;
  6219. }
  6220. if (destination.rotation !== undefined) {
  6221. this.initialRotation = destination.rotation;
  6222. }
  6223. if (destination.dest) {
  6224. this.initialBookmark = JSON.stringify(destination.dest);
  6225. this._destination.page = null;
  6226. } else if (destination.hash) {
  6227. this.initialBookmark = destination.hash;
  6228. } else if (destination.page) {
  6229. this.initialBookmark = "page=".concat(destination.page);
  6230. }
  6231. }
  6232. }, {
  6233. key: "push",
  6234. value: function push(_ref3) {
  6235. var _this2 = this;
  6236. var _ref3$namedDest = _ref3.namedDest,
  6237. namedDest = _ref3$namedDest === void 0 ? null : _ref3$namedDest,
  6238. explicitDest = _ref3.explicitDest,
  6239. pageNumber = _ref3.pageNumber;
  6240. if (!this.initialized) {
  6241. return;
  6242. }
  6243. if (namedDest && typeof namedDest !== 'string') {
  6244. console.error('PDFHistory.push: ' + "\"".concat(namedDest, "\" is not a valid namedDest parameter."));
  6245. return;
  6246. } else if (!Array.isArray(explicitDest)) {
  6247. console.error('PDFHistory.push: ' + "\"".concat(explicitDest, "\" is not a valid explicitDest parameter."));
  6248. return;
  6249. } else if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.linkService.pagesCount)) {
  6250. if (pageNumber !== null || this._destination) {
  6251. console.error('PDFHistory.push: ' + "\"".concat(pageNumber, "\" is not a valid pageNumber parameter."));
  6252. return;
  6253. }
  6254. }
  6255. var hash = namedDest || JSON.stringify(explicitDest);
  6256. if (!hash) {
  6257. return;
  6258. }
  6259. var forceReplace = false;
  6260. if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) {
  6261. if (this._destination.page) {
  6262. return;
  6263. }
  6264. forceReplace = true;
  6265. }
  6266. if (this._popStateInProgress && !forceReplace) {
  6267. return;
  6268. }
  6269. this._pushOrReplaceState({
  6270. dest: explicitDest,
  6271. hash: hash,
  6272. page: pageNumber,
  6273. rotation: this.linkService.rotation
  6274. }, forceReplace);
  6275. if (!this._popStateInProgress) {
  6276. this._popStateInProgress = true;
  6277. Promise.resolve().then(function () {
  6278. _this2._popStateInProgress = false;
  6279. });
  6280. }
  6281. }
  6282. }, {
  6283. key: "pushCurrentPosition",
  6284. value: function pushCurrentPosition() {
  6285. if (!this.initialized || this._popStateInProgress) {
  6286. return;
  6287. }
  6288. this._tryPushCurrentPosition();
  6289. }
  6290. }, {
  6291. key: "back",
  6292. value: function back() {
  6293. if (!this.initialized || this._popStateInProgress) {
  6294. return;
  6295. }
  6296. var state = window.history.state;
  6297. if (this._isValidState(state) && state.uid > 0) {
  6298. window.history.back();
  6299. }
  6300. }
  6301. }, {
  6302. key: "forward",
  6303. value: function forward() {
  6304. if (!this.initialized || this._popStateInProgress) {
  6305. return;
  6306. }
  6307. var state = window.history.state;
  6308. if (this._isValidState(state) && state.uid < this._maxUid) {
  6309. window.history.forward();
  6310. }
  6311. }
  6312. }, {
  6313. key: "_pushOrReplaceState",
  6314. value: function _pushOrReplaceState(destination) {
  6315. var forceReplace = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  6316. var shouldReplace = forceReplace || !this._destination;
  6317. var newState = {
  6318. fingerprint: this.fingerprint,
  6319. uid: shouldReplace ? this._uid : this._uid + 1,
  6320. destination: destination
  6321. };
  6322. this._updateInternalState(destination, newState.uid);
  6323. var newUrl;
  6324. if (this._updateUrl && destination && destination.hash) {
  6325. var baseUrl = document.location.href.split('#')[0];
  6326. if (!baseUrl.startsWith('file://')) {
  6327. newUrl = "".concat(baseUrl, "#").concat(destination.hash);
  6328. }
  6329. }
  6330. if (shouldReplace) {
  6331. if (newUrl) {
  6332. window.history.replaceState(newState, '', newUrl);
  6333. } else {
  6334. window.history.replaceState(newState, '');
  6335. }
  6336. } else {
  6337. this._maxUid = this._uid;
  6338. if (newUrl) {
  6339. window.history.pushState(newState, '', newUrl);
  6340. } else {
  6341. window.history.pushState(newState, '');
  6342. }
  6343. }
  6344. }
  6345. }, {
  6346. key: "_tryPushCurrentPosition",
  6347. value: function _tryPushCurrentPosition() {
  6348. var temporary = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  6349. if (!this._position) {
  6350. return;
  6351. }
  6352. var position = this._position;
  6353. if (temporary) {
  6354. position = Object.assign(Object.create(null), this._position);
  6355. position.temporary = true;
  6356. }
  6357. if (!this._destination) {
  6358. this._pushOrReplaceState(position);
  6359. return;
  6360. }
  6361. if (this._destination.temporary) {
  6362. this._pushOrReplaceState(position, true);
  6363. return;
  6364. }
  6365. if (this._destination.hash === position.hash) {
  6366. return;
  6367. }
  6368. if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) {
  6369. return;
  6370. }
  6371. var forceReplace = false;
  6372. if (this._destination.page >= position.first && this._destination.page <= position.page) {
  6373. if (this._destination.dest || !this._destination.first) {
  6374. return;
  6375. }
  6376. forceReplace = true;
  6377. }
  6378. this._pushOrReplaceState(position, forceReplace);
  6379. }
  6380. }, {
  6381. key: "_isValidState",
  6382. value: function _isValidState(state) {
  6383. var checkReload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  6384. if (!state) {
  6385. return false;
  6386. }
  6387. if (state.fingerprint !== this.fingerprint) {
  6388. if (checkReload) {
  6389. if (typeof state.fingerprint !== 'string' || state.fingerprint.length !== this.fingerprint.length) {
  6390. return false;
  6391. }
  6392. var _performance$getEntri = performance.getEntriesByType('navigation'),
  6393. _performance$getEntri2 = _slicedToArray(_performance$getEntri, 1),
  6394. perfEntry = _performance$getEntri2[0];
  6395. if (!perfEntry || perfEntry.type !== 'reload') {
  6396. return false;
  6397. }
  6398. } else {
  6399. return false;
  6400. }
  6401. }
  6402. if (!Number.isInteger(state.uid) || state.uid < 0) {
  6403. return false;
  6404. }
  6405. if (state.destination === null || _typeof(state.destination) !== 'object') {
  6406. return false;
  6407. }
  6408. return true;
  6409. }
  6410. }, {
  6411. key: "_updateInternalState",
  6412. value: function _updateInternalState(destination, uid) {
  6413. var removeTemporary = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  6414. if (this._updateViewareaTimeout) {
  6415. clearTimeout(this._updateViewareaTimeout);
  6416. this._updateViewareaTimeout = null;
  6417. }
  6418. if (removeTemporary && destination && destination.temporary) {
  6419. delete destination.temporary;
  6420. }
  6421. this._destination = destination;
  6422. this._uid = uid;
  6423. this._numPositionUpdates = 0;
  6424. }
  6425. }, {
  6426. key: "_updateViewarea",
  6427. value: function _updateViewarea(_ref4) {
  6428. var _this3 = this;
  6429. var location = _ref4.location;
  6430. if (this._updateViewareaTimeout) {
  6431. clearTimeout(this._updateViewareaTimeout);
  6432. this._updateViewareaTimeout = null;
  6433. }
  6434. this._position = {
  6435. hash: this._isViewerInPresentationMode ? "page=".concat(location.pageNumber) : location.pdfOpenParams.substring(1),
  6436. page: this.linkService.page,
  6437. first: location.pageNumber,
  6438. rotation: location.rotation
  6439. };
  6440. if (this._popStateInProgress) {
  6441. return;
  6442. }
  6443. if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) {
  6444. this._numPositionUpdates++;
  6445. }
  6446. if (UPDATE_VIEWAREA_TIMEOUT > 0) {
  6447. this._updateViewareaTimeout = setTimeout(function () {
  6448. if (!_this3._popStateInProgress) {
  6449. _this3._tryPushCurrentPosition(true);
  6450. }
  6451. _this3._updateViewareaTimeout = null;
  6452. }, UPDATE_VIEWAREA_TIMEOUT);
  6453. }
  6454. }
  6455. }, {
  6456. key: "_popState",
  6457. value: function _popState(_ref5) {
  6458. var _this4 = this;
  6459. var state = _ref5.state;
  6460. var newHash = getCurrentHash(),
  6461. hashChanged = this._currentHash !== newHash;
  6462. this._currentHash = newHash;
  6463. if (!state || false) {
  6464. this._uid++;
  6465. var _parseCurrentHash2 = parseCurrentHash(this.linkService),
  6466. hash = _parseCurrentHash2.hash,
  6467. page = _parseCurrentHash2.page,
  6468. rotation = _parseCurrentHash2.rotation;
  6469. this._pushOrReplaceState({
  6470. hash: hash,
  6471. page: page,
  6472. rotation: rotation
  6473. }, true);
  6474. return;
  6475. }
  6476. if (!this._isValidState(state)) {
  6477. return;
  6478. }
  6479. this._popStateInProgress = true;
  6480. if (hashChanged) {
  6481. this._blockHashChange++;
  6482. (0, _ui_utils.waitOnEventOrTimeout)({
  6483. target: window,
  6484. name: 'hashchange',
  6485. delay: HASH_CHANGE_TIMEOUT
  6486. }).then(function () {
  6487. _this4._blockHashChange--;
  6488. });
  6489. }
  6490. var destination = state.destination;
  6491. this._updateInternalState(destination, state.uid, true);
  6492. if (this._uid > this._maxUid) {
  6493. this._maxUid = this._uid;
  6494. }
  6495. if ((0, _ui_utils.isValidRotation)(destination.rotation)) {
  6496. this.linkService.rotation = destination.rotation;
  6497. }
  6498. if (destination.dest) {
  6499. this.linkService.navigateTo(destination.dest);
  6500. } else if (destination.hash) {
  6501. this.linkService.setHash(destination.hash);
  6502. } else if (destination.page) {
  6503. this.linkService.page = destination.page;
  6504. }
  6505. Promise.resolve().then(function () {
  6506. _this4._popStateInProgress = false;
  6507. });
  6508. }
  6509. }, {
  6510. key: "_bindEvents",
  6511. value: function _bindEvents() {
  6512. var _this5 = this;
  6513. var _boundEvents = this._boundEvents,
  6514. eventBus = this.eventBus;
  6515. _boundEvents.updateViewarea = this._updateViewarea.bind(this);
  6516. _boundEvents.popState = this._popState.bind(this);
  6517. _boundEvents.pageHide = function (evt) {
  6518. if (!_this5._destination || _this5._destination.temporary) {
  6519. _this5._tryPushCurrentPosition();
  6520. }
  6521. };
  6522. eventBus.on('updateviewarea', _boundEvents.updateViewarea);
  6523. window.addEventListener('popstate', _boundEvents.popState);
  6524. window.addEventListener('pagehide', _boundEvents.pageHide);
  6525. }
  6526. }, {
  6527. key: "popStateInProgress",
  6528. get: function get() {
  6529. return this.initialized && (this._popStateInProgress || this._blockHashChange > 0);
  6530. }
  6531. }]);
  6532. return PDFHistory;
  6533. }();
  6534. exports.PDFHistory = PDFHistory;
  6535. function isDestHashesEqual(destHash, pushHash) {
  6536. if (typeof destHash !== 'string' || typeof pushHash !== 'string') {
  6537. return false;
  6538. }
  6539. if (destHash === pushHash) {
  6540. return true;
  6541. }
  6542. var _parseQueryString = (0, _ui_utils.parseQueryString)(destHash),
  6543. nameddest = _parseQueryString.nameddest;
  6544. if (nameddest === pushHash) {
  6545. return true;
  6546. }
  6547. return false;
  6548. }
  6549. function isDestArraysEqual(firstDest, secondDest) {
  6550. function isEntryEqual(first, second) {
  6551. if (_typeof(first) !== _typeof(second)) {
  6552. return false;
  6553. }
  6554. if (Array.isArray(first) || Array.isArray(second)) {
  6555. return false;
  6556. }
  6557. if (first !== null && _typeof(first) === 'object' && second !== null) {
  6558. if (Object.keys(first).length !== Object.keys(second).length) {
  6559. return false;
  6560. }
  6561. for (var key in first) {
  6562. if (!isEntryEqual(first[key], second[key])) {
  6563. return false;
  6564. }
  6565. }
  6566. return true;
  6567. }
  6568. return first === second || Number.isNaN(first) && Number.isNaN(second);
  6569. }
  6570. if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) {
  6571. return false;
  6572. }
  6573. if (firstDest.length !== secondDest.length) {
  6574. return false;
  6575. }
  6576. for (var i = 0, ii = firstDest.length; i < ii; i++) {
  6577. if (!isEntryEqual(firstDest[i], secondDest[i])) {
  6578. return false;
  6579. }
  6580. }
  6581. return true;
  6582. }
  6583. /***/ }),
  6584. /* 22 */
  6585. /***/ (function(module, exports, __webpack_require__) {
  6586. "use strict";
  6587. Object.defineProperty(exports, "__esModule", {
  6588. value: true
  6589. });
  6590. exports.SimpleLinkService = exports.PDFLinkService = void 0;
  6591. var _ui_utils = __webpack_require__(6);
  6592. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  6593. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6594. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  6595. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6596. var PDFLinkService =
  6597. /*#__PURE__*/
  6598. function () {
  6599. function PDFLinkService() {
  6600. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  6601. eventBus = _ref.eventBus,
  6602. _ref$externalLinkTarg = _ref.externalLinkTarget,
  6603. externalLinkTarget = _ref$externalLinkTarg === void 0 ? null : _ref$externalLinkTarg,
  6604. _ref$externalLinkRel = _ref.externalLinkRel,
  6605. externalLinkRel = _ref$externalLinkRel === void 0 ? null : _ref$externalLinkRel;
  6606. _classCallCheck(this, PDFLinkService);
  6607. this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
  6608. this.externalLinkTarget = externalLinkTarget;
  6609. this.externalLinkRel = externalLinkRel;
  6610. this.baseUrl = null;
  6611. this.pdfDocument = null;
  6612. this.pdfViewer = null;
  6613. this.pdfHistory = null;
  6614. this._pagesRefCache = null;
  6615. }
  6616. _createClass(PDFLinkService, [{
  6617. key: "setDocument",
  6618. value: function setDocument(pdfDocument) {
  6619. var baseUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  6620. this.baseUrl = baseUrl;
  6621. this.pdfDocument = pdfDocument;
  6622. this._pagesRefCache = Object.create(null);
  6623. }
  6624. }, {
  6625. key: "setViewer",
  6626. value: function setViewer(pdfViewer) {
  6627. this.pdfViewer = pdfViewer;
  6628. }
  6629. }, {
  6630. key: "setHistory",
  6631. value: function setHistory(pdfHistory) {
  6632. this.pdfHistory = pdfHistory;
  6633. }
  6634. }, {
  6635. key: "navigateTo",
  6636. value: function navigateTo(dest) {
  6637. var _this = this;
  6638. var goToDestination = function goToDestination(_ref2) {
  6639. var namedDest = _ref2.namedDest,
  6640. explicitDest = _ref2.explicitDest;
  6641. var destRef = explicitDest[0],
  6642. pageNumber;
  6643. if (destRef instanceof Object) {
  6644. pageNumber = _this._cachedPageNumber(destRef);
  6645. if (pageNumber === null) {
  6646. _this.pdfDocument.getPageIndex(destRef).then(function (pageIndex) {
  6647. _this.cachePageRef(pageIndex + 1, destRef);
  6648. goToDestination({
  6649. namedDest: namedDest,
  6650. explicitDest: explicitDest
  6651. });
  6652. }).catch(function () {
  6653. console.error("PDFLinkService.navigateTo: \"".concat(destRef, "\" is not ") + "a valid page reference, for dest=\"".concat(dest, "\"."));
  6654. });
  6655. return;
  6656. }
  6657. } else if (Number.isInteger(destRef)) {
  6658. pageNumber = destRef + 1;
  6659. } else {
  6660. console.error("PDFLinkService.navigateTo: \"".concat(destRef, "\" is not ") + "a valid destination reference, for dest=\"".concat(dest, "\"."));
  6661. return;
  6662. }
  6663. if (!pageNumber || pageNumber < 1 || pageNumber > _this.pagesCount) {
  6664. console.error("PDFLinkService.navigateTo: \"".concat(pageNumber, "\" is not ") + "a valid page number, for dest=\"".concat(dest, "\"."));
  6665. return;
  6666. }
  6667. if (_this.pdfHistory) {
  6668. _this.pdfHistory.pushCurrentPosition();
  6669. _this.pdfHistory.push({
  6670. namedDest: namedDest,
  6671. explicitDest: explicitDest,
  6672. pageNumber: pageNumber
  6673. });
  6674. }
  6675. _this.pdfViewer.scrollPageIntoView({
  6676. pageNumber: pageNumber,
  6677. destArray: explicitDest
  6678. });
  6679. };
  6680. new Promise(function (resolve, reject) {
  6681. if (typeof dest === 'string') {
  6682. _this.pdfDocument.getDestination(dest).then(function (destArray) {
  6683. resolve({
  6684. namedDest: dest,
  6685. explicitDest: destArray
  6686. });
  6687. });
  6688. return;
  6689. }
  6690. resolve({
  6691. namedDest: '',
  6692. explicitDest: dest
  6693. });
  6694. }).then(function (data) {
  6695. if (!Array.isArray(data.explicitDest)) {
  6696. console.error("PDFLinkService.navigateTo: \"".concat(data.explicitDest, "\" is") + " not a valid destination array, for dest=\"".concat(dest, "\"."));
  6697. return;
  6698. }
  6699. goToDestination(data);
  6700. });
  6701. }
  6702. }, {
  6703. key: "getDestinationHash",
  6704. value: function getDestinationHash(dest) {
  6705. if (typeof dest === 'string') {
  6706. return this.getAnchorUrl('#' + escape(dest));
  6707. }
  6708. if (Array.isArray(dest)) {
  6709. var str = JSON.stringify(dest);
  6710. return this.getAnchorUrl('#' + escape(str));
  6711. }
  6712. return this.getAnchorUrl('');
  6713. }
  6714. }, {
  6715. key: "getAnchorUrl",
  6716. value: function getAnchorUrl(anchor) {
  6717. return (this.baseUrl || '') + anchor;
  6718. }
  6719. }, {
  6720. key: "setHash",
  6721. value: function setHash(hash) {
  6722. var pageNumber, dest;
  6723. if (hash.includes('=')) {
  6724. var params = (0, _ui_utils.parseQueryString)(hash);
  6725. if ('search' in params) {
  6726. this.eventBus.dispatch('findfromurlhash', {
  6727. source: this,
  6728. query: params['search'].replace(/"/g, ''),
  6729. phraseSearch: params['phrase'] === 'true'
  6730. });
  6731. }
  6732. if ('nameddest' in params) {
  6733. this.navigateTo(params.nameddest);
  6734. return;
  6735. }
  6736. if ('page' in params) {
  6737. pageNumber = params.page | 0 || 1;
  6738. }
  6739. if ('zoom' in params) {
  6740. var zoomArgs = params.zoom.split(',');
  6741. var zoomArg = zoomArgs[0];
  6742. var zoomArgNumber = parseFloat(zoomArg);
  6743. if (!zoomArg.includes('Fit')) {
  6744. dest = [null, {
  6745. name: 'XYZ'
  6746. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
  6747. } else {
  6748. if (zoomArg === 'Fit' || zoomArg === 'FitB') {
  6749. dest = [null, {
  6750. name: zoomArg
  6751. }];
  6752. } else if (zoomArg === 'FitH' || zoomArg === 'FitBH' || zoomArg === 'FitV' || zoomArg === 'FitBV') {
  6753. dest = [null, {
  6754. name: zoomArg
  6755. }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
  6756. } else if (zoomArg === 'FitR') {
  6757. if (zoomArgs.length !== 5) {
  6758. console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
  6759. } else {
  6760. dest = [null, {
  6761. name: zoomArg
  6762. }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
  6763. }
  6764. } else {
  6765. console.error("PDFLinkService.setHash: \"".concat(zoomArg, "\" is not ") + 'a valid zoom value.');
  6766. }
  6767. }
  6768. }
  6769. if (dest) {
  6770. this.pdfViewer.scrollPageIntoView({
  6771. pageNumber: pageNumber || this.page,
  6772. destArray: dest,
  6773. allowNegativeOffset: true
  6774. });
  6775. } else if (pageNumber) {
  6776. this.page = pageNumber;
  6777. }
  6778. if ('pagemode' in params) {
  6779. this.eventBus.dispatch('pagemode', {
  6780. source: this,
  6781. mode: params.pagemode
  6782. });
  6783. }
  6784. } else {
  6785. dest = unescape(hash);
  6786. try {
  6787. dest = JSON.parse(dest);
  6788. if (!Array.isArray(dest)) {
  6789. dest = dest.toString();
  6790. }
  6791. } catch (ex) {}
  6792. if (typeof dest === 'string' || isValidExplicitDestination(dest)) {
  6793. this.navigateTo(dest);
  6794. return;
  6795. }
  6796. console.error("PDFLinkService.setHash: \"".concat(unescape(hash), "\" is not ") + 'a valid destination.');
  6797. }
  6798. }
  6799. }, {
  6800. key: "executeNamedAction",
  6801. value: function executeNamedAction(action) {
  6802. switch (action) {
  6803. case 'GoBack':
  6804. if (this.pdfHistory) {
  6805. this.pdfHistory.back();
  6806. }
  6807. break;
  6808. case 'GoForward':
  6809. if (this.pdfHistory) {
  6810. this.pdfHistory.forward();
  6811. }
  6812. break;
  6813. case 'NextPage':
  6814. if (this.page < this.pagesCount) {
  6815. this.page++;
  6816. }
  6817. break;
  6818. case 'PrevPage':
  6819. if (this.page > 1) {
  6820. this.page--;
  6821. }
  6822. break;
  6823. case 'LastPage':
  6824. this.page = this.pagesCount;
  6825. break;
  6826. case 'FirstPage':
  6827. this.page = 1;
  6828. break;
  6829. default:
  6830. break;
  6831. }
  6832. this.eventBus.dispatch('namedaction', {
  6833. source: this,
  6834. action: action
  6835. });
  6836. }
  6837. }, {
  6838. key: "cachePageRef",
  6839. value: function cachePageRef(pageNum, pageRef) {
  6840. if (!pageRef) {
  6841. return;
  6842. }
  6843. var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
  6844. this._pagesRefCache[refStr] = pageNum;
  6845. }
  6846. }, {
  6847. key: "_cachedPageNumber",
  6848. value: function _cachedPageNumber(pageRef) {
  6849. var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
  6850. return this._pagesRefCache && this._pagesRefCache[refStr] || null;
  6851. }
  6852. }, {
  6853. key: "isPageVisible",
  6854. value: function isPageVisible(pageNumber) {
  6855. return this.pdfViewer.isPageVisible(pageNumber);
  6856. }
  6857. }, {
  6858. key: "pagesCount",
  6859. get: function get() {
  6860. return this.pdfDocument ? this.pdfDocument.numPages : 0;
  6861. }
  6862. }, {
  6863. key: "page",
  6864. get: function get() {
  6865. return this.pdfViewer.currentPageNumber;
  6866. },
  6867. set: function set(value) {
  6868. this.pdfViewer.currentPageNumber = value;
  6869. }
  6870. }, {
  6871. key: "rotation",
  6872. get: function get() {
  6873. return this.pdfViewer.pagesRotation;
  6874. },
  6875. set: function set(value) {
  6876. this.pdfViewer.pagesRotation = value;
  6877. }
  6878. }]);
  6879. return PDFLinkService;
  6880. }();
  6881. exports.PDFLinkService = PDFLinkService;
  6882. function isValidExplicitDestination(dest) {
  6883. if (!Array.isArray(dest)) {
  6884. return false;
  6885. }
  6886. var destLength = dest.length,
  6887. allowNull = true;
  6888. if (destLength < 2) {
  6889. return false;
  6890. }
  6891. var page = dest[0];
  6892. if (!(_typeof(page) === 'object' && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
  6893. return false;
  6894. }
  6895. var zoom = dest[1];
  6896. if (!(_typeof(zoom) === 'object' && typeof zoom.name === 'string')) {
  6897. return false;
  6898. }
  6899. switch (zoom.name) {
  6900. case 'XYZ':
  6901. if (destLength !== 5) {
  6902. return false;
  6903. }
  6904. break;
  6905. case 'Fit':
  6906. case 'FitB':
  6907. return destLength === 2;
  6908. case 'FitH':
  6909. case 'FitBH':
  6910. case 'FitV':
  6911. case 'FitBV':
  6912. if (destLength !== 3) {
  6913. return false;
  6914. }
  6915. break;
  6916. case 'FitR':
  6917. if (destLength !== 6) {
  6918. return false;
  6919. }
  6920. allowNull = false;
  6921. break;
  6922. default:
  6923. return false;
  6924. }
  6925. for (var i = 2; i < destLength; i++) {
  6926. var param = dest[i];
  6927. if (!(typeof param === 'number' || allowNull && param === null)) {
  6928. return false;
  6929. }
  6930. }
  6931. return true;
  6932. }
  6933. var SimpleLinkService =
  6934. /*#__PURE__*/
  6935. function () {
  6936. function SimpleLinkService() {
  6937. _classCallCheck(this, SimpleLinkService);
  6938. this.externalLinkTarget = null;
  6939. this.externalLinkRel = null;
  6940. }
  6941. _createClass(SimpleLinkService, [{
  6942. key: "navigateTo",
  6943. value: function navigateTo(dest) {}
  6944. }, {
  6945. key: "getDestinationHash",
  6946. value: function getDestinationHash(dest) {
  6947. return '#';
  6948. }
  6949. }, {
  6950. key: "getAnchorUrl",
  6951. value: function getAnchorUrl(hash) {
  6952. return '#';
  6953. }
  6954. }, {
  6955. key: "setHash",
  6956. value: function setHash(hash) {}
  6957. }, {
  6958. key: "executeNamedAction",
  6959. value: function executeNamedAction(action) {}
  6960. }, {
  6961. key: "cachePageRef",
  6962. value: function cachePageRef(pageNum, pageRef) {}
  6963. }, {
  6964. key: "isPageVisible",
  6965. value: function isPageVisible(pageNumber) {
  6966. return true;
  6967. }
  6968. }, {
  6969. key: "pagesCount",
  6970. get: function get() {
  6971. return 0;
  6972. }
  6973. }, {
  6974. key: "page",
  6975. get: function get() {
  6976. return 0;
  6977. },
  6978. set: function set(value) {}
  6979. }, {
  6980. key: "rotation",
  6981. get: function get() {
  6982. return 0;
  6983. },
  6984. set: function set(value) {}
  6985. }]);
  6986. return SimpleLinkService;
  6987. }();
  6988. exports.SimpleLinkService = SimpleLinkService;
  6989. /***/ }),
  6990. /* 23 */
  6991. /***/ (function(module, exports, __webpack_require__) {
  6992. "use strict";
  6993. Object.defineProperty(exports, "__esModule", {
  6994. value: true
  6995. });
  6996. exports.PDFOutlineViewer = void 0;
  6997. var _pdfjsLib = __webpack_require__(7);
  6998. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6999. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7000. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7001. var DEFAULT_TITLE = "\u2013";
  7002. var PDFOutlineViewer =
  7003. /*#__PURE__*/
  7004. function () {
  7005. function PDFOutlineViewer(_ref) {
  7006. var container = _ref.container,
  7007. linkService = _ref.linkService,
  7008. eventBus = _ref.eventBus;
  7009. _classCallCheck(this, PDFOutlineViewer);
  7010. this.container = container;
  7011. this.linkService = linkService;
  7012. this.eventBus = eventBus;
  7013. this.reset();
  7014. eventBus.on('toggleoutlinetree', this.toggleOutlineTree.bind(this));
  7015. }
  7016. _createClass(PDFOutlineViewer, [{
  7017. key: "reset",
  7018. value: function reset() {
  7019. this.outline = null;
  7020. this.lastToggleIsShow = true;
  7021. this.container.textContent = '';
  7022. this.container.classList.remove('outlineWithDeepNesting');
  7023. }
  7024. }, {
  7025. key: "_dispatchEvent",
  7026. value: function _dispatchEvent(outlineCount) {
  7027. this.eventBus.dispatch('outlineloaded', {
  7028. source: this,
  7029. outlineCount: outlineCount
  7030. });
  7031. }
  7032. }, {
  7033. key: "_bindLink",
  7034. value: function _bindLink(element, _ref2) {
  7035. var url = _ref2.url,
  7036. newWindow = _ref2.newWindow,
  7037. dest = _ref2.dest;
  7038. var linkService = this.linkService;
  7039. if (url) {
  7040. (0, _pdfjsLib.addLinkAttributes)(element, {
  7041. url: url,
  7042. target: newWindow ? _pdfjsLib.LinkTarget.BLANK : linkService.externalLinkTarget,
  7043. rel: linkService.externalLinkRel
  7044. });
  7045. return;
  7046. }
  7047. element.href = linkService.getDestinationHash(dest);
  7048. element.onclick = function () {
  7049. if (dest) {
  7050. linkService.navigateTo(dest);
  7051. }
  7052. return false;
  7053. };
  7054. }
  7055. }, {
  7056. key: "_setStyles",
  7057. value: function _setStyles(element, _ref3) {
  7058. var bold = _ref3.bold,
  7059. italic = _ref3.italic;
  7060. var styleStr = '';
  7061. if (bold) {
  7062. styleStr += 'font-weight: bold;';
  7063. }
  7064. if (italic) {
  7065. styleStr += 'font-style: italic;';
  7066. }
  7067. if (styleStr) {
  7068. element.setAttribute('style', styleStr);
  7069. }
  7070. }
  7071. }, {
  7072. key: "_addToggleButton",
  7073. value: function _addToggleButton(div) {
  7074. var _this = this;
  7075. var toggler = document.createElement('div');
  7076. toggler.className = 'outlineItemToggler';
  7077. toggler.onclick = function (evt) {
  7078. evt.stopPropagation();
  7079. toggler.classList.toggle('outlineItemsHidden');
  7080. if (evt.shiftKey) {
  7081. var shouldShowAll = !toggler.classList.contains('outlineItemsHidden');
  7082. _this._toggleOutlineItem(div, shouldShowAll);
  7083. }
  7084. };
  7085. div.insertBefore(toggler, div.firstChild);
  7086. }
  7087. }, {
  7088. key: "_toggleOutlineItem",
  7089. value: function _toggleOutlineItem(root) {
  7090. var show = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  7091. this.lastToggleIsShow = show;
  7092. var _iteratorNormalCompletion = true;
  7093. var _didIteratorError = false;
  7094. var _iteratorError = undefined;
  7095. try {
  7096. for (var _iterator = root.querySelectorAll('.outlineItemToggler')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  7097. var toggler = _step.value;
  7098. toggler.classList.toggle('outlineItemsHidden', !show);
  7099. }
  7100. } catch (err) {
  7101. _didIteratorError = true;
  7102. _iteratorError = err;
  7103. } finally {
  7104. try {
  7105. if (!_iteratorNormalCompletion && _iterator.return != null) {
  7106. _iterator.return();
  7107. }
  7108. } finally {
  7109. if (_didIteratorError) {
  7110. throw _iteratorError;
  7111. }
  7112. }
  7113. }
  7114. }
  7115. }, {
  7116. key: "toggleOutlineTree",
  7117. value: function toggleOutlineTree() {
  7118. if (!this.outline) {
  7119. return;
  7120. }
  7121. this._toggleOutlineItem(this.container, !this.lastToggleIsShow);
  7122. }
  7123. }, {
  7124. key: "render",
  7125. value: function render(_ref4) {
  7126. var outline = _ref4.outline;
  7127. var outlineCount = 0;
  7128. if (this.outline) {
  7129. this.reset();
  7130. }
  7131. this.outline = outline || null;
  7132. if (!outline) {
  7133. this._dispatchEvent(outlineCount);
  7134. return;
  7135. }
  7136. var fragment = document.createDocumentFragment();
  7137. var queue = [{
  7138. parent: fragment,
  7139. items: this.outline
  7140. }];
  7141. var hasAnyNesting = false;
  7142. while (queue.length > 0) {
  7143. var levelData = queue.shift();
  7144. for (var i = 0, len = levelData.items.length; i < len; i++) {
  7145. var item = levelData.items[i];
  7146. var div = document.createElement('div');
  7147. div.className = 'outlineItem';
  7148. var element = document.createElement('a');
  7149. this._bindLink(element, item);
  7150. this._setStyles(element, item);
  7151. element.textContent = (0, _pdfjsLib.removeNullCharacters)(item.title) || DEFAULT_TITLE;
  7152. div.appendChild(element);
  7153. if (item.items.length > 0) {
  7154. hasAnyNesting = true;
  7155. this._addToggleButton(div);
  7156. var itemsDiv = document.createElement('div');
  7157. itemsDiv.className = 'outlineItems';
  7158. div.appendChild(itemsDiv);
  7159. queue.push({
  7160. parent: itemsDiv,
  7161. items: item.items
  7162. });
  7163. }
  7164. levelData.parent.appendChild(div);
  7165. outlineCount++;
  7166. }
  7167. }
  7168. if (hasAnyNesting) {
  7169. this.container.classList.add('outlineWithDeepNesting');
  7170. }
  7171. this.container.appendChild(fragment);
  7172. this._dispatchEvent(outlineCount);
  7173. }
  7174. }]);
  7175. return PDFOutlineViewer;
  7176. }();
  7177. exports.PDFOutlineViewer = PDFOutlineViewer;
  7178. /***/ }),
  7179. /* 24 */
  7180. /***/ (function(module, exports, __webpack_require__) {
  7181. "use strict";
  7182. Object.defineProperty(exports, "__esModule", {
  7183. value: true
  7184. });
  7185. exports.PDFPresentationMode = void 0;
  7186. var _ui_utils = __webpack_require__(6);
  7187. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7188. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7189. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7190. var DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1500;
  7191. var DELAY_BEFORE_HIDING_CONTROLS = 3000;
  7192. var ACTIVE_SELECTOR = 'pdfPresentationMode';
  7193. var CONTROLS_SELECTOR = 'pdfPresentationModeControls';
  7194. var MOUSE_SCROLL_COOLDOWN_TIME = 50;
  7195. var PAGE_SWITCH_THRESHOLD = 0.1;
  7196. var SWIPE_MIN_DISTANCE_THRESHOLD = 50;
  7197. var SWIPE_ANGLE_THRESHOLD = Math.PI / 6;
  7198. var PDFPresentationMode =
  7199. /*#__PURE__*/
  7200. function () {
  7201. function PDFPresentationMode(_ref) {
  7202. var _this = this;
  7203. var container = _ref.container,
  7204. _ref$viewer = _ref.viewer,
  7205. viewer = _ref$viewer === void 0 ? null : _ref$viewer,
  7206. pdfViewer = _ref.pdfViewer,
  7207. eventBus = _ref.eventBus,
  7208. _ref$contextMenuItems = _ref.contextMenuItems,
  7209. contextMenuItems = _ref$contextMenuItems === void 0 ? null : _ref$contextMenuItems;
  7210. _classCallCheck(this, PDFPresentationMode);
  7211. this.container = container;
  7212. this.viewer = viewer || container.firstElementChild;
  7213. this.pdfViewer = pdfViewer;
  7214. this.eventBus = eventBus;
  7215. this.active = false;
  7216. this.args = null;
  7217. this.contextMenuOpen = false;
  7218. this.mouseScrollTimeStamp = 0;
  7219. this.mouseScrollDelta = 0;
  7220. this.touchSwipeState = null;
  7221. if (contextMenuItems) {
  7222. contextMenuItems.contextFirstPage.addEventListener('click', function () {
  7223. _this.contextMenuOpen = false;
  7224. _this.eventBus.dispatch('firstpage', {
  7225. source: _this
  7226. });
  7227. });
  7228. contextMenuItems.contextLastPage.addEventListener('click', function () {
  7229. _this.contextMenuOpen = false;
  7230. _this.eventBus.dispatch('lastpage', {
  7231. source: _this
  7232. });
  7233. });
  7234. contextMenuItems.contextPageRotateCw.addEventListener('click', function () {
  7235. _this.contextMenuOpen = false;
  7236. _this.eventBus.dispatch('rotatecw', {
  7237. source: _this
  7238. });
  7239. });
  7240. contextMenuItems.contextPageRotateCcw.addEventListener('click', function () {
  7241. _this.contextMenuOpen = false;
  7242. _this.eventBus.dispatch('rotateccw', {
  7243. source: _this
  7244. });
  7245. });
  7246. }
  7247. }
  7248. _createClass(PDFPresentationMode, [{
  7249. key: "request",
  7250. value: function request() {
  7251. if (this.switchInProgress || this.active || !this.viewer.hasChildNodes()) {
  7252. return false;
  7253. }
  7254. this._addFullscreenChangeListeners();
  7255. this._setSwitchInProgress();
  7256. this._notifyStateChange();
  7257. if (this.container.requestFullscreen) {
  7258. this.container.requestFullscreen();
  7259. } else if (this.container.mozRequestFullScreen) {
  7260. this.container.mozRequestFullScreen();
  7261. } else if (this.container.webkitRequestFullscreen) {
  7262. this.container.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  7263. } else if (this.container.msRequestFullscreen) {
  7264. this.container.msRequestFullscreen();
  7265. } else {
  7266. return false;
  7267. }
  7268. this.args = {
  7269. page: this.pdfViewer.currentPageNumber,
  7270. previousScale: this.pdfViewer.currentScaleValue
  7271. };
  7272. return true;
  7273. }
  7274. }, {
  7275. key: "_mouseWheel",
  7276. value: function _mouseWheel(evt) {
  7277. if (!this.active) {
  7278. return;
  7279. }
  7280. evt.preventDefault();
  7281. var delta = (0, _ui_utils.normalizeWheelEventDelta)(evt);
  7282. var currentTime = new Date().getTime();
  7283. var storedTime = this.mouseScrollTimeStamp;
  7284. if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) {
  7285. return;
  7286. }
  7287. if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) {
  7288. this._resetMouseScrollState();
  7289. }
  7290. this.mouseScrollDelta += delta;
  7291. if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
  7292. var totalDelta = this.mouseScrollDelta;
  7293. this._resetMouseScrollState();
  7294. var success = totalDelta > 0 ? this._goToPreviousPage() : this._goToNextPage();
  7295. if (success) {
  7296. this.mouseScrollTimeStamp = currentTime;
  7297. }
  7298. }
  7299. }
  7300. }, {
  7301. key: "_goToPreviousPage",
  7302. value: function _goToPreviousPage() {
  7303. var page = this.pdfViewer.currentPageNumber;
  7304. if (page <= 1) {
  7305. return false;
  7306. }
  7307. this.pdfViewer.currentPageNumber = page - 1;
  7308. return true;
  7309. }
  7310. }, {
  7311. key: "_goToNextPage",
  7312. value: function _goToNextPage() {
  7313. var page = this.pdfViewer.currentPageNumber;
  7314. if (page >= this.pdfViewer.pagesCount) {
  7315. return false;
  7316. }
  7317. this.pdfViewer.currentPageNumber = page + 1;
  7318. return true;
  7319. }
  7320. }, {
  7321. key: "_notifyStateChange",
  7322. value: function _notifyStateChange() {
  7323. this.eventBus.dispatch('presentationmodechanged', {
  7324. source: this,
  7325. active: this.active,
  7326. switchInProgress: !!this.switchInProgress
  7327. });
  7328. }
  7329. }, {
  7330. key: "_setSwitchInProgress",
  7331. value: function _setSwitchInProgress() {
  7332. var _this2 = this;
  7333. if (this.switchInProgress) {
  7334. clearTimeout(this.switchInProgress);
  7335. }
  7336. this.switchInProgress = setTimeout(function () {
  7337. _this2._removeFullscreenChangeListeners();
  7338. delete _this2.switchInProgress;
  7339. _this2._notifyStateChange();
  7340. }, DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS);
  7341. }
  7342. }, {
  7343. key: "_resetSwitchInProgress",
  7344. value: function _resetSwitchInProgress() {
  7345. if (this.switchInProgress) {
  7346. clearTimeout(this.switchInProgress);
  7347. delete this.switchInProgress;
  7348. }
  7349. }
  7350. }, {
  7351. key: "_enter",
  7352. value: function _enter() {
  7353. var _this3 = this;
  7354. this.active = true;
  7355. this._resetSwitchInProgress();
  7356. this._notifyStateChange();
  7357. this.container.classList.add(ACTIVE_SELECTOR);
  7358. setTimeout(function () {
  7359. _this3.pdfViewer.currentPageNumber = _this3.args.page;
  7360. _this3.pdfViewer.currentScaleValue = 'page-fit';
  7361. }, 0);
  7362. this._addWindowListeners();
  7363. this._showControls();
  7364. this.contextMenuOpen = false;
  7365. this.container.setAttribute('contextmenu', 'viewerContextMenu');
  7366. window.getSelection().removeAllRanges();
  7367. }
  7368. }, {
  7369. key: "_exit",
  7370. value: function _exit() {
  7371. var _this4 = this;
  7372. var page = this.pdfViewer.currentPageNumber;
  7373. this.container.classList.remove(ACTIVE_SELECTOR);
  7374. setTimeout(function () {
  7375. _this4.active = false;
  7376. _this4._removeFullscreenChangeListeners();
  7377. _this4._notifyStateChange();
  7378. _this4.pdfViewer.currentScaleValue = _this4.args.previousScale;
  7379. _this4.pdfViewer.currentPageNumber = page;
  7380. _this4.args = null;
  7381. }, 0);
  7382. this._removeWindowListeners();
  7383. this._hideControls();
  7384. this._resetMouseScrollState();
  7385. this.container.removeAttribute('contextmenu');
  7386. this.contextMenuOpen = false;
  7387. }
  7388. }, {
  7389. key: "_mouseDown",
  7390. value: function _mouseDown(evt) {
  7391. if (this.contextMenuOpen) {
  7392. this.contextMenuOpen = false;
  7393. evt.preventDefault();
  7394. return;
  7395. }
  7396. if (evt.button === 0) {
  7397. var isInternalLink = evt.target.href && evt.target.classList.contains('internalLink');
  7398. if (!isInternalLink) {
  7399. evt.preventDefault();
  7400. if (evt.shiftKey) {
  7401. this._goToPreviousPage();
  7402. } else {
  7403. this._goToNextPage();
  7404. }
  7405. }
  7406. }
  7407. }
  7408. }, {
  7409. key: "_contextMenu",
  7410. value: function _contextMenu() {
  7411. this.contextMenuOpen = true;
  7412. }
  7413. }, {
  7414. key: "_showControls",
  7415. value: function _showControls() {
  7416. var _this5 = this;
  7417. if (this.controlsTimeout) {
  7418. clearTimeout(this.controlsTimeout);
  7419. } else {
  7420. this.container.classList.add(CONTROLS_SELECTOR);
  7421. }
  7422. this.controlsTimeout = setTimeout(function () {
  7423. _this5.container.classList.remove(CONTROLS_SELECTOR);
  7424. delete _this5.controlsTimeout;
  7425. }, DELAY_BEFORE_HIDING_CONTROLS);
  7426. }
  7427. }, {
  7428. key: "_hideControls",
  7429. value: function _hideControls() {
  7430. if (!this.controlsTimeout) {
  7431. return;
  7432. }
  7433. clearTimeout(this.controlsTimeout);
  7434. this.container.classList.remove(CONTROLS_SELECTOR);
  7435. delete this.controlsTimeout;
  7436. }
  7437. }, {
  7438. key: "_resetMouseScrollState",
  7439. value: function _resetMouseScrollState() {
  7440. this.mouseScrollTimeStamp = 0;
  7441. this.mouseScrollDelta = 0;
  7442. }
  7443. }, {
  7444. key: "_touchSwipe",
  7445. value: function _touchSwipe(evt) {
  7446. if (!this.active) {
  7447. return;
  7448. }
  7449. if (evt.touches.length > 1) {
  7450. this.touchSwipeState = null;
  7451. return;
  7452. }
  7453. switch (evt.type) {
  7454. case 'touchstart':
  7455. this.touchSwipeState = {
  7456. startX: evt.touches[0].pageX,
  7457. startY: evt.touches[0].pageY,
  7458. endX: evt.touches[0].pageX,
  7459. endY: evt.touches[0].pageY
  7460. };
  7461. break;
  7462. case 'touchmove':
  7463. if (this.touchSwipeState === null) {
  7464. return;
  7465. }
  7466. this.touchSwipeState.endX = evt.touches[0].pageX;
  7467. this.touchSwipeState.endY = evt.touches[0].pageY;
  7468. evt.preventDefault();
  7469. break;
  7470. case 'touchend':
  7471. if (this.touchSwipeState === null) {
  7472. return;
  7473. }
  7474. var delta = 0;
  7475. var dx = this.touchSwipeState.endX - this.touchSwipeState.startX;
  7476. var dy = this.touchSwipeState.endY - this.touchSwipeState.startY;
  7477. var absAngle = Math.abs(Math.atan2(dy, dx));
  7478. if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) {
  7479. delta = dx;
  7480. } else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) {
  7481. delta = dy;
  7482. }
  7483. if (delta > 0) {
  7484. this._goToPreviousPage();
  7485. } else if (delta < 0) {
  7486. this._goToNextPage();
  7487. }
  7488. break;
  7489. }
  7490. }
  7491. }, {
  7492. key: "_addWindowListeners",
  7493. value: function _addWindowListeners() {
  7494. this.showControlsBind = this._showControls.bind(this);
  7495. this.mouseDownBind = this._mouseDown.bind(this);
  7496. this.mouseWheelBind = this._mouseWheel.bind(this);
  7497. this.resetMouseScrollStateBind = this._resetMouseScrollState.bind(this);
  7498. this.contextMenuBind = this._contextMenu.bind(this);
  7499. this.touchSwipeBind = this._touchSwipe.bind(this);
  7500. window.addEventListener('mousemove', this.showControlsBind);
  7501. window.addEventListener('mousedown', this.mouseDownBind);
  7502. window.addEventListener('wheel', this.mouseWheelBind);
  7503. window.addEventListener('keydown', this.resetMouseScrollStateBind);
  7504. window.addEventListener('contextmenu', this.contextMenuBind);
  7505. window.addEventListener('touchstart', this.touchSwipeBind);
  7506. window.addEventListener('touchmove', this.touchSwipeBind);
  7507. window.addEventListener('touchend', this.touchSwipeBind);
  7508. }
  7509. }, {
  7510. key: "_removeWindowListeners",
  7511. value: function _removeWindowListeners() {
  7512. window.removeEventListener('mousemove', this.showControlsBind);
  7513. window.removeEventListener('mousedown', this.mouseDownBind);
  7514. window.removeEventListener('wheel', this.mouseWheelBind);
  7515. window.removeEventListener('keydown', this.resetMouseScrollStateBind);
  7516. window.removeEventListener('contextmenu', this.contextMenuBind);
  7517. window.removeEventListener('touchstart', this.touchSwipeBind);
  7518. window.removeEventListener('touchmove', this.touchSwipeBind);
  7519. window.removeEventListener('touchend', this.touchSwipeBind);
  7520. delete this.showControlsBind;
  7521. delete this.mouseDownBind;
  7522. delete this.mouseWheelBind;
  7523. delete this.resetMouseScrollStateBind;
  7524. delete this.contextMenuBind;
  7525. delete this.touchSwipeBind;
  7526. }
  7527. }, {
  7528. key: "_fullscreenChange",
  7529. value: function _fullscreenChange() {
  7530. if (this.isFullscreen) {
  7531. this._enter();
  7532. } else {
  7533. this._exit();
  7534. }
  7535. }
  7536. }, {
  7537. key: "_addFullscreenChangeListeners",
  7538. value: function _addFullscreenChangeListeners() {
  7539. this.fullscreenChangeBind = this._fullscreenChange.bind(this);
  7540. window.addEventListener('fullscreenchange', this.fullscreenChangeBind);
  7541. window.addEventListener('mozfullscreenchange', this.fullscreenChangeBind);
  7542. window.addEventListener('webkitfullscreenchange', this.fullscreenChangeBind);
  7543. window.addEventListener('MSFullscreenChange', this.fullscreenChangeBind);
  7544. }
  7545. }, {
  7546. key: "_removeFullscreenChangeListeners",
  7547. value: function _removeFullscreenChangeListeners() {
  7548. window.removeEventListener('fullscreenchange', this.fullscreenChangeBind);
  7549. window.removeEventListener('mozfullscreenchange', this.fullscreenChangeBind);
  7550. window.removeEventListener('webkitfullscreenchange', this.fullscreenChangeBind);
  7551. window.removeEventListener('MSFullscreenChange', this.fullscreenChangeBind);
  7552. delete this.fullscreenChangeBind;
  7553. }
  7554. }, {
  7555. key: "isFullscreen",
  7556. get: function get() {
  7557. return !!(document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement);
  7558. }
  7559. }]);
  7560. return PDFPresentationMode;
  7561. }();
  7562. exports.PDFPresentationMode = PDFPresentationMode;
  7563. /***/ }),
  7564. /* 25 */
  7565. /***/ (function(module, exports, __webpack_require__) {
  7566. "use strict";
  7567. Object.defineProperty(exports, "__esModule", {
  7568. value: true
  7569. });
  7570. exports.PDFSidebarResizer = void 0;
  7571. var _ui_utils = __webpack_require__(6);
  7572. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7573. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7574. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7575. var SIDEBAR_WIDTH_VAR = '--sidebar-width';
  7576. var SIDEBAR_MIN_WIDTH = 200;
  7577. var SIDEBAR_RESIZING_CLASS = 'sidebarResizing';
  7578. var PDFSidebarResizer =
  7579. /*#__PURE__*/
  7580. function () {
  7581. function PDFSidebarResizer(options, eventBus) {
  7582. var _this = this;
  7583. var l10n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ui_utils.NullL10n;
  7584. _classCallCheck(this, PDFSidebarResizer);
  7585. this.enabled = false;
  7586. this.isRTL = false;
  7587. this.sidebarOpen = false;
  7588. this.doc = document.documentElement;
  7589. this._width = null;
  7590. this._outerContainerWidth = null;
  7591. this._boundEvents = Object.create(null);
  7592. this.outerContainer = options.outerContainer;
  7593. this.resizer = options.resizer;
  7594. this.eventBus = eventBus;
  7595. this.l10n = l10n;
  7596. if (typeof CSS === 'undefined' || typeof CSS.supports !== 'function' || !CSS.supports(SIDEBAR_WIDTH_VAR, "calc(-1 * ".concat(SIDEBAR_MIN_WIDTH, "px)"))) {
  7597. console.warn('PDFSidebarResizer: ' + 'The browser does not support resizing of the sidebar.');
  7598. return;
  7599. }
  7600. this.enabled = true;
  7601. this.resizer.classList.remove('hidden');
  7602. this.l10n.getDirection().then(function (dir) {
  7603. _this.isRTL = dir === 'rtl';
  7604. });
  7605. this._addEventListeners();
  7606. }
  7607. _createClass(PDFSidebarResizer, [{
  7608. key: "_updateWidth",
  7609. value: function _updateWidth() {
  7610. var width = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  7611. if (!this.enabled) {
  7612. return false;
  7613. }
  7614. var maxWidth = Math.floor(this.outerContainerWidth / 2);
  7615. if (width > maxWidth) {
  7616. width = maxWidth;
  7617. }
  7618. if (width < SIDEBAR_MIN_WIDTH) {
  7619. width = SIDEBAR_MIN_WIDTH;
  7620. }
  7621. if (width === this._width) {
  7622. return false;
  7623. }
  7624. this._width = width;
  7625. this.doc.style.setProperty(SIDEBAR_WIDTH_VAR, "".concat(width, "px"));
  7626. return true;
  7627. }
  7628. }, {
  7629. key: "_mouseMove",
  7630. value: function _mouseMove(evt) {
  7631. var width = evt.clientX;
  7632. if (this.isRTL) {
  7633. width = this.outerContainerWidth - width;
  7634. }
  7635. this._updateWidth(width);
  7636. }
  7637. }, {
  7638. key: "_mouseUp",
  7639. value: function _mouseUp(evt) {
  7640. this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7641. this.eventBus.dispatch('resize', {
  7642. source: this
  7643. });
  7644. var _boundEvents = this._boundEvents;
  7645. window.removeEventListener('mousemove', _boundEvents.mouseMove);
  7646. window.removeEventListener('mouseup', _boundEvents.mouseUp);
  7647. }
  7648. }, {
  7649. key: "_addEventListeners",
  7650. value: function _addEventListeners() {
  7651. var _this2 = this;
  7652. if (!this.enabled) {
  7653. return;
  7654. }
  7655. var _boundEvents = this._boundEvents;
  7656. _boundEvents.mouseMove = this._mouseMove.bind(this);
  7657. _boundEvents.mouseUp = this._mouseUp.bind(this);
  7658. this.resizer.addEventListener('mousedown', function (evt) {
  7659. if (evt.button !== 0) {
  7660. return;
  7661. }
  7662. _this2.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7663. window.addEventListener('mousemove', _boundEvents.mouseMove);
  7664. window.addEventListener('mouseup', _boundEvents.mouseUp);
  7665. });
  7666. this.eventBus.on('sidebarviewchanged', function (evt) {
  7667. _this2.sidebarOpen = !!(evt && evt.view);
  7668. });
  7669. this.eventBus.on('resize', function (evt) {
  7670. if (evt && evt.source === window) {
  7671. _this2._outerContainerWidth = null;
  7672. if (_this2._width) {
  7673. if (_this2.sidebarOpen) {
  7674. _this2.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
  7675. var updated = _this2._updateWidth(_this2._width);
  7676. Promise.resolve().then(function () {
  7677. _this2.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS);
  7678. if (updated) {
  7679. _this2.eventBus.dispatch('resize', {
  7680. source: _this2
  7681. });
  7682. }
  7683. });
  7684. } else {
  7685. _this2._updateWidth(_this2._width);
  7686. }
  7687. }
  7688. }
  7689. });
  7690. }
  7691. }, {
  7692. key: "outerContainerWidth",
  7693. get: function get() {
  7694. if (!this._outerContainerWidth) {
  7695. this._outerContainerWidth = this.outerContainer.clientWidth;
  7696. }
  7697. return this._outerContainerWidth;
  7698. }
  7699. }]);
  7700. return PDFSidebarResizer;
  7701. }();
  7702. exports.PDFSidebarResizer = PDFSidebarResizer;
  7703. /***/ }),
  7704. /* 26 */
  7705. /***/ (function(module, exports, __webpack_require__) {
  7706. "use strict";
  7707. Object.defineProperty(exports, "__esModule", {
  7708. value: true
  7709. });
  7710. exports.PDFThumbnailViewer = void 0;
  7711. var _ui_utils = __webpack_require__(6);
  7712. var _pdf_thumbnail_view = __webpack_require__(27);
  7713. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7714. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7715. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7716. var THUMBNAIL_SCROLL_MARGIN = -19;
  7717. var THUMBNAIL_SELECTED_CLASS = 'selected';
  7718. var PDFThumbnailViewer =
  7719. /*#__PURE__*/
  7720. function () {
  7721. function PDFThumbnailViewer(_ref) {
  7722. var container = _ref.container,
  7723. linkService = _ref.linkService,
  7724. renderingQueue = _ref.renderingQueue,
  7725. _ref$l10n = _ref.l10n,
  7726. l10n = _ref$l10n === void 0 ? _ui_utils.NullL10n : _ref$l10n;
  7727. _classCallCheck(this, PDFThumbnailViewer);
  7728. this.container = container;
  7729. this.linkService = linkService;
  7730. this.renderingQueue = renderingQueue;
  7731. this.l10n = l10n;
  7732. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdated.bind(this));
  7733. this._resetView();
  7734. }
  7735. _createClass(PDFThumbnailViewer, [{
  7736. key: "_scrollUpdated",
  7737. value: function _scrollUpdated() {
  7738. this.renderingQueue.renderHighestPriority();
  7739. }
  7740. }, {
  7741. key: "getThumbnail",
  7742. value: function getThumbnail(index) {
  7743. return this._thumbnails[index];
  7744. }
  7745. }, {
  7746. key: "_getVisibleThumbs",
  7747. value: function _getVisibleThumbs() {
  7748. return (0, _ui_utils.getVisibleElements)(this.container, this._thumbnails);
  7749. }
  7750. }, {
  7751. key: "scrollThumbnailIntoView",
  7752. value: function scrollThumbnailIntoView(pageNumber) {
  7753. if (!this.pdfDocument) {
  7754. return;
  7755. }
  7756. var thumbnailView = this._thumbnails[pageNumber - 1];
  7757. if (!thumbnailView) {
  7758. console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
  7759. return;
  7760. }
  7761. if (pageNumber !== this._currentPageNumber) {
  7762. var prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
  7763. prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
  7764. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7765. }
  7766. var visibleThumbs = this._getVisibleThumbs();
  7767. var numVisibleThumbs = visibleThumbs.views.length;
  7768. if (numVisibleThumbs > 0) {
  7769. var first = visibleThumbs.first.id;
  7770. var last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
  7771. var shouldScroll = false;
  7772. if (pageNumber <= first || pageNumber >= last) {
  7773. shouldScroll = true;
  7774. } else {
  7775. visibleThumbs.views.some(function (view) {
  7776. if (view.id !== pageNumber) {
  7777. return false;
  7778. }
  7779. shouldScroll = view.percent < 100;
  7780. return true;
  7781. });
  7782. }
  7783. if (shouldScroll) {
  7784. (0, _ui_utils.scrollIntoView)(thumbnailView.div, {
  7785. top: THUMBNAIL_SCROLL_MARGIN
  7786. });
  7787. }
  7788. }
  7789. this._currentPageNumber = pageNumber;
  7790. }
  7791. }, {
  7792. key: "cleanup",
  7793. value: function cleanup() {
  7794. _pdf_thumbnail_view.PDFThumbnailView.cleanup();
  7795. }
  7796. }, {
  7797. key: "_resetView",
  7798. value: function _resetView() {
  7799. this._thumbnails = [];
  7800. this._currentPageNumber = 1;
  7801. this._pageLabels = null;
  7802. this._pagesRotation = 0;
  7803. this._pagesRequests = [];
  7804. this.container.textContent = '';
  7805. }
  7806. }, {
  7807. key: "setDocument",
  7808. value: function setDocument(pdfDocument) {
  7809. var _this = this;
  7810. if (this.pdfDocument) {
  7811. this._cancelRendering();
  7812. this._resetView();
  7813. }
  7814. this.pdfDocument = pdfDocument;
  7815. if (!pdfDocument) {
  7816. return;
  7817. }
  7818. pdfDocument.getPage(1).then(function (firstPage) {
  7819. var pagesCount = pdfDocument.numPages;
  7820. var viewport = firstPage.getViewport({
  7821. scale: 1
  7822. });
  7823. for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  7824. var thumbnail = new _pdf_thumbnail_view.PDFThumbnailView({
  7825. container: _this.container,
  7826. id: pageNum,
  7827. defaultViewport: viewport.clone(),
  7828. linkService: _this.linkService,
  7829. renderingQueue: _this.renderingQueue,
  7830. disableCanvasToImageConversion: false,
  7831. l10n: _this.l10n
  7832. });
  7833. _this._thumbnails.push(thumbnail);
  7834. }
  7835. var thumbnailView = _this._thumbnails[_this._currentPageNumber - 1];
  7836. thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
  7837. }).catch(function (reason) {
  7838. console.error('Unable to initialize thumbnail viewer', reason);
  7839. });
  7840. }
  7841. }, {
  7842. key: "_cancelRendering",
  7843. value: function _cancelRendering() {
  7844. for (var i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7845. if (this._thumbnails[i]) {
  7846. this._thumbnails[i].cancelRendering();
  7847. }
  7848. }
  7849. }
  7850. }, {
  7851. key: "setPageLabels",
  7852. value: function setPageLabels(labels) {
  7853. if (!this.pdfDocument) {
  7854. return;
  7855. }
  7856. if (!labels) {
  7857. this._pageLabels = null;
  7858. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  7859. this._pageLabels = null;
  7860. console.error('PDFThumbnailViewer_setPageLabels: Invalid page labels.');
  7861. } else {
  7862. this._pageLabels = labels;
  7863. }
  7864. for (var i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7865. var label = this._pageLabels && this._pageLabels[i];
  7866. this._thumbnails[i].setPageLabel(label);
  7867. }
  7868. }
  7869. }, {
  7870. key: "_ensurePdfPageLoaded",
  7871. value: function _ensurePdfPageLoaded(thumbView) {
  7872. var _this2 = this;
  7873. if (thumbView.pdfPage) {
  7874. return Promise.resolve(thumbView.pdfPage);
  7875. }
  7876. var pageNumber = thumbView.id;
  7877. if (this._pagesRequests[pageNumber]) {
  7878. return this._pagesRequests[pageNumber];
  7879. }
  7880. var promise = this.pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  7881. thumbView.setPdfPage(pdfPage);
  7882. _this2._pagesRequests[pageNumber] = null;
  7883. return pdfPage;
  7884. }).catch(function (reason) {
  7885. console.error('Unable to get page for thumb view', reason);
  7886. _this2._pagesRequests[pageNumber] = null;
  7887. });
  7888. this._pagesRequests[pageNumber] = promise;
  7889. return promise;
  7890. }
  7891. }, {
  7892. key: "forceRendering",
  7893. value: function forceRendering() {
  7894. var _this3 = this;
  7895. var visibleThumbs = this._getVisibleThumbs();
  7896. var thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, this.scroll.down);
  7897. if (thumbView) {
  7898. this._ensurePdfPageLoaded(thumbView).then(function () {
  7899. _this3.renderingQueue.renderView(thumbView);
  7900. });
  7901. return true;
  7902. }
  7903. return false;
  7904. }
  7905. }, {
  7906. key: "pagesRotation",
  7907. get: function get() {
  7908. return this._pagesRotation;
  7909. },
  7910. set: function set(rotation) {
  7911. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  7912. throw new Error('Invalid thumbnails rotation angle.');
  7913. }
  7914. if (!this.pdfDocument) {
  7915. return;
  7916. }
  7917. if (this._pagesRotation === rotation) {
  7918. return;
  7919. }
  7920. this._pagesRotation = rotation;
  7921. for (var i = 0, ii = this._thumbnails.length; i < ii; i++) {
  7922. this._thumbnails[i].update(rotation);
  7923. }
  7924. }
  7925. }]);
  7926. return PDFThumbnailViewer;
  7927. }();
  7928. exports.PDFThumbnailViewer = PDFThumbnailViewer;
  7929. /***/ }),
  7930. /* 27 */
  7931. /***/ (function(module, exports, __webpack_require__) {
  7932. "use strict";
  7933. Object.defineProperty(exports, "__esModule", {
  7934. value: true
  7935. });
  7936. exports.PDFThumbnailView = void 0;
  7937. var _pdfjsLib = __webpack_require__(7);
  7938. var _ui_utils = __webpack_require__(6);
  7939. var _pdf_rendering_queue = __webpack_require__(10);
  7940. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7941. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  7942. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  7943. var MAX_NUM_SCALING_STEPS = 3;
  7944. var THUMBNAIL_CANVAS_BORDER_WIDTH = 1;
  7945. var THUMBNAIL_WIDTH = 98;
  7946. var TempImageFactory = function TempImageFactoryClosure() {
  7947. var tempCanvasCache = null;
  7948. return {
  7949. getCanvas: function getCanvas(width, height) {
  7950. var tempCanvas = tempCanvasCache;
  7951. if (!tempCanvas) {
  7952. tempCanvas = document.createElement('canvas');
  7953. tempCanvasCache = tempCanvas;
  7954. }
  7955. tempCanvas.width = width;
  7956. tempCanvas.height = height;
  7957. tempCanvas.mozOpaque = true;
  7958. var ctx = tempCanvas.getContext('2d', {
  7959. alpha: false
  7960. });
  7961. ctx.save();
  7962. ctx.fillStyle = 'rgb(255, 255, 255)';
  7963. ctx.fillRect(0, 0, width, height);
  7964. ctx.restore();
  7965. return tempCanvas;
  7966. },
  7967. destroyCanvas: function destroyCanvas() {
  7968. var tempCanvas = tempCanvasCache;
  7969. if (tempCanvas) {
  7970. tempCanvas.width = 0;
  7971. tempCanvas.height = 0;
  7972. }
  7973. tempCanvasCache = null;
  7974. }
  7975. };
  7976. }();
  7977. var PDFThumbnailView =
  7978. /*#__PURE__*/
  7979. function () {
  7980. function PDFThumbnailView(_ref) {
  7981. var container = _ref.container,
  7982. id = _ref.id,
  7983. defaultViewport = _ref.defaultViewport,
  7984. linkService = _ref.linkService,
  7985. renderingQueue = _ref.renderingQueue,
  7986. _ref$disableCanvasToI = _ref.disableCanvasToImageConversion,
  7987. disableCanvasToImageConversion = _ref$disableCanvasToI === void 0 ? false : _ref$disableCanvasToI,
  7988. _ref$l10n = _ref.l10n,
  7989. l10n = _ref$l10n === void 0 ? _ui_utils.NullL10n : _ref$l10n;
  7990. _classCallCheck(this, PDFThumbnailView);
  7991. this.id = id;
  7992. this.renderingId = 'thumbnail' + id;
  7993. this.pageLabel = null;
  7994. this.pdfPage = null;
  7995. this.rotation = 0;
  7996. this.viewport = defaultViewport;
  7997. this.pdfPageRotate = defaultViewport.rotation;
  7998. this.linkService = linkService;
  7999. this.renderingQueue = renderingQueue;
  8000. this.renderTask = null;
  8001. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  8002. this.resume = null;
  8003. this.disableCanvasToImageConversion = disableCanvasToImageConversion;
  8004. this.pageWidth = this.viewport.width;
  8005. this.pageHeight = this.viewport.height;
  8006. this.pageRatio = this.pageWidth / this.pageHeight;
  8007. this.canvasWidth = THUMBNAIL_WIDTH;
  8008. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  8009. this.scale = this.canvasWidth / this.pageWidth;
  8010. this.l10n = l10n;
  8011. var anchor = document.createElement('a');
  8012. anchor.href = linkService.getAnchorUrl('#page=' + id);
  8013. this.l10n.get('thumb_page_title', {
  8014. page: id
  8015. }, 'Page {{page}}').then(function (msg) {
  8016. anchor.title = msg;
  8017. });
  8018. anchor.onclick = function () {
  8019. linkService.page = id;
  8020. return false;
  8021. };
  8022. this.anchor = anchor;
  8023. var div = document.createElement('div');
  8024. div.className = 'thumbnail';
  8025. div.setAttribute('data-page-number', this.id);
  8026. this.div = div;
  8027. var ring = document.createElement('div');
  8028. ring.className = 'thumbnailSelectionRing';
  8029. var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  8030. ring.style.width = this.canvasWidth + borderAdjustment + 'px';
  8031. ring.style.height = this.canvasHeight + borderAdjustment + 'px';
  8032. this.ring = ring;
  8033. div.appendChild(ring);
  8034. anchor.appendChild(div);
  8035. container.appendChild(anchor);
  8036. }
  8037. _createClass(PDFThumbnailView, [{
  8038. key: "setPdfPage",
  8039. value: function setPdfPage(pdfPage) {
  8040. this.pdfPage = pdfPage;
  8041. this.pdfPageRotate = pdfPage.rotate;
  8042. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8043. this.viewport = pdfPage.getViewport({
  8044. scale: 1,
  8045. rotation: totalRotation
  8046. });
  8047. this.reset();
  8048. }
  8049. }, {
  8050. key: "reset",
  8051. value: function reset() {
  8052. this.cancelRendering();
  8053. this.pageWidth = this.viewport.width;
  8054. this.pageHeight = this.viewport.height;
  8055. this.pageRatio = this.pageWidth / this.pageHeight;
  8056. this.canvasHeight = this.canvasWidth / this.pageRatio | 0;
  8057. this.scale = this.canvasWidth / this.pageWidth;
  8058. this.div.removeAttribute('data-loaded');
  8059. var ring = this.ring;
  8060. var childNodes = ring.childNodes;
  8061. for (var i = childNodes.length - 1; i >= 0; i--) {
  8062. ring.removeChild(childNodes[i]);
  8063. }
  8064. var borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
  8065. ring.style.width = this.canvasWidth + borderAdjustment + 'px';
  8066. ring.style.height = this.canvasHeight + borderAdjustment + 'px';
  8067. if (this.canvas) {
  8068. this.canvas.width = 0;
  8069. this.canvas.height = 0;
  8070. delete this.canvas;
  8071. }
  8072. if (this.image) {
  8073. this.image.removeAttribute('src');
  8074. delete this.image;
  8075. }
  8076. }
  8077. }, {
  8078. key: "update",
  8079. value: function update(rotation) {
  8080. if (typeof rotation !== 'undefined') {
  8081. this.rotation = rotation;
  8082. }
  8083. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  8084. this.viewport = this.viewport.clone({
  8085. scale: 1,
  8086. rotation: totalRotation
  8087. });
  8088. this.reset();
  8089. }
  8090. }, {
  8091. key: "cancelRendering",
  8092. value: function cancelRendering() {
  8093. if (this.renderTask) {
  8094. this.renderTask.cancel();
  8095. this.renderTask = null;
  8096. }
  8097. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  8098. this.resume = null;
  8099. }
  8100. }, {
  8101. key: "_getPageDrawContext",
  8102. value: function _getPageDrawContext() {
  8103. var noCtxScale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  8104. var canvas = document.createElement('canvas');
  8105. this.canvas = canvas;
  8106. canvas.mozOpaque = true;
  8107. var ctx = canvas.getContext('2d', {
  8108. alpha: false
  8109. });
  8110. var outputScale = (0, _ui_utils.getOutputScale)(ctx);
  8111. canvas.width = this.canvasWidth * outputScale.sx | 0;
  8112. canvas.height = this.canvasHeight * outputScale.sy | 0;
  8113. canvas.style.width = this.canvasWidth + 'px';
  8114. canvas.style.height = this.canvasHeight + 'px';
  8115. if (!noCtxScale && outputScale.scaled) {
  8116. ctx.scale(outputScale.sx, outputScale.sy);
  8117. }
  8118. return ctx;
  8119. }
  8120. }, {
  8121. key: "_convertCanvasToImage",
  8122. value: function _convertCanvasToImage() {
  8123. var _this = this;
  8124. if (!this.canvas) {
  8125. return;
  8126. }
  8127. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  8128. return;
  8129. }
  8130. var id = this.renderingId;
  8131. var className = 'thumbnailImage';
  8132. if (this.disableCanvasToImageConversion) {
  8133. this.canvas.id = id;
  8134. this.canvas.className = className;
  8135. this.l10n.get('thumb_page_canvas', {
  8136. page: this.pageId
  8137. }, 'Thumbnail of Page {{page}}').then(function (msg) {
  8138. _this.canvas.setAttribute('aria-label', msg);
  8139. });
  8140. this.div.setAttribute('data-loaded', true);
  8141. this.ring.appendChild(this.canvas);
  8142. return;
  8143. }
  8144. var image = document.createElement('img');
  8145. image.id = id;
  8146. image.className = className;
  8147. this.l10n.get('thumb_page_canvas', {
  8148. page: this.pageId
  8149. }, 'Thumbnail of Page {{page}}').then(function (msg) {
  8150. image.setAttribute('aria-label', msg);
  8151. });
  8152. image.style.width = this.canvasWidth + 'px';
  8153. image.style.height = this.canvasHeight + 'px';
  8154. image.src = this.canvas.toDataURL();
  8155. this.image = image;
  8156. this.div.setAttribute('data-loaded', true);
  8157. this.ring.appendChild(image);
  8158. this.canvas.width = 0;
  8159. this.canvas.height = 0;
  8160. delete this.canvas;
  8161. }
  8162. }, {
  8163. key: "draw",
  8164. value: function draw() {
  8165. var _this2 = this;
  8166. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  8167. console.error('Must be in new state before drawing');
  8168. return Promise.resolve(undefined);
  8169. }
  8170. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  8171. var renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  8172. var finishRenderTask = function finishRenderTask(error) {
  8173. if (renderTask === _this2.renderTask) {
  8174. _this2.renderTask = null;
  8175. }
  8176. if (error instanceof _pdfjsLib.RenderingCancelledException) {
  8177. renderCapability.resolve(undefined);
  8178. return;
  8179. }
  8180. _this2.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  8181. _this2._convertCanvasToImage();
  8182. if (!error) {
  8183. renderCapability.resolve(undefined);
  8184. } else {
  8185. renderCapability.reject(error);
  8186. }
  8187. };
  8188. var ctx = this._getPageDrawContext();
  8189. var drawViewport = this.viewport.clone({
  8190. scale: this.scale
  8191. });
  8192. var renderContinueCallback = function renderContinueCallback(cont) {
  8193. if (!_this2.renderingQueue.isHighestPriority(_this2)) {
  8194. _this2.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  8195. _this2.resume = function () {
  8196. _this2.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  8197. cont();
  8198. };
  8199. return;
  8200. }
  8201. cont();
  8202. };
  8203. var renderContext = {
  8204. canvasContext: ctx,
  8205. viewport: drawViewport
  8206. };
  8207. var renderTask = this.renderTask = this.pdfPage.render(renderContext);
  8208. renderTask.onContinue = renderContinueCallback;
  8209. renderTask.promise.then(function () {
  8210. finishRenderTask(null);
  8211. }, function (error) {
  8212. finishRenderTask(error);
  8213. });
  8214. return renderCapability.promise;
  8215. }
  8216. }, {
  8217. key: "setImage",
  8218. value: function setImage(pageView) {
  8219. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  8220. return;
  8221. }
  8222. var img = pageView.canvas;
  8223. if (!img) {
  8224. return;
  8225. }
  8226. if (!this.pdfPage) {
  8227. this.setPdfPage(pageView.pdfPage);
  8228. }
  8229. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  8230. var ctx = this._getPageDrawContext(true);
  8231. var canvas = ctx.canvas;
  8232. if (img.width <= 2 * canvas.width) {
  8233. ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
  8234. this._convertCanvasToImage();
  8235. return;
  8236. }
  8237. var reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
  8238. var reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
  8239. var reducedImage = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
  8240. var reducedImageCtx = reducedImage.getContext('2d');
  8241. while (reducedWidth > img.width || reducedHeight > img.height) {
  8242. reducedWidth >>= 1;
  8243. reducedHeight >>= 1;
  8244. }
  8245. reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
  8246. while (reducedWidth > 2 * canvas.width) {
  8247. reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
  8248. reducedWidth >>= 1;
  8249. reducedHeight >>= 1;
  8250. }
  8251. ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
  8252. this._convertCanvasToImage();
  8253. }
  8254. }, {
  8255. key: "setPageLabel",
  8256. value: function setPageLabel(label) {
  8257. var _this3 = this;
  8258. this.pageLabel = typeof label === 'string' ? label : null;
  8259. this.l10n.get('thumb_page_title', {
  8260. page: this.pageId
  8261. }, 'Page {{page}}').then(function (msg) {
  8262. _this3.anchor.title = msg;
  8263. });
  8264. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  8265. return;
  8266. }
  8267. this.l10n.get('thumb_page_canvas', {
  8268. page: this.pageId
  8269. }, 'Thumbnail of Page {{page}}').then(function (ariaLabel) {
  8270. if (_this3.image) {
  8271. _this3.image.setAttribute('aria-label', ariaLabel);
  8272. } else if (_this3.disableCanvasToImageConversion && _this3.canvas) {
  8273. _this3.canvas.setAttribute('aria-label', ariaLabel);
  8274. }
  8275. });
  8276. }
  8277. }, {
  8278. key: "pageId",
  8279. get: function get() {
  8280. return this.pageLabel !== null ? this.pageLabel : this.id;
  8281. }
  8282. }], [{
  8283. key: "cleanup",
  8284. value: function cleanup() {
  8285. TempImageFactory.destroyCanvas();
  8286. }
  8287. }]);
  8288. return PDFThumbnailView;
  8289. }();
  8290. exports.PDFThumbnailView = PDFThumbnailView;
  8291. /***/ }),
  8292. /* 28 */
  8293. /***/ (function(module, exports, __webpack_require__) {
  8294. "use strict";
  8295. Object.defineProperty(exports, "__esModule", {
  8296. value: true
  8297. });
  8298. exports.PDFViewer = void 0;
  8299. var _base_viewer = __webpack_require__(29);
  8300. var _pdfjsLib = __webpack_require__(7);
  8301. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  8302. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8303. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8304. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8305. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  8306. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8307. function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
  8308. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  8309. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8310. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8311. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8312. var PDFViewer =
  8313. /*#__PURE__*/
  8314. function (_BaseViewer) {
  8315. _inherits(PDFViewer, _BaseViewer);
  8316. function PDFViewer() {
  8317. _classCallCheck(this, PDFViewer);
  8318. return _possibleConstructorReturn(this, _getPrototypeOf(PDFViewer).apply(this, arguments));
  8319. }
  8320. _createClass(PDFViewer, [{
  8321. key: "_scrollIntoView",
  8322. value: function _scrollIntoView(_ref) {
  8323. var pageDiv = _ref.pageDiv,
  8324. _ref$pageSpot = _ref.pageSpot,
  8325. pageSpot = _ref$pageSpot === void 0 ? null : _ref$pageSpot,
  8326. _ref$pageNumber = _ref.pageNumber,
  8327. pageNumber = _ref$pageNumber === void 0 ? null : _ref$pageNumber;
  8328. if (!pageSpot && !this.isInPresentationMode) {
  8329. var left = pageDiv.offsetLeft + pageDiv.clientLeft;
  8330. var right = left + pageDiv.clientWidth;
  8331. var _this$container = this.container,
  8332. scrollLeft = _this$container.scrollLeft,
  8333. clientWidth = _this$container.clientWidth;
  8334. if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
  8335. pageSpot = {
  8336. left: 0,
  8337. top: 0
  8338. };
  8339. }
  8340. }
  8341. _get(_getPrototypeOf(PDFViewer.prototype), "_scrollIntoView", this).call(this, {
  8342. pageDiv: pageDiv,
  8343. pageSpot: pageSpot,
  8344. pageNumber: pageNumber
  8345. });
  8346. }
  8347. }, {
  8348. key: "_getVisiblePages",
  8349. value: function _getVisiblePages() {
  8350. if (this.isInPresentationMode) {
  8351. return this._getCurrentVisiblePage();
  8352. }
  8353. return _get(_getPrototypeOf(PDFViewer.prototype), "_getVisiblePages", this).call(this);
  8354. }
  8355. }, {
  8356. key: "_updateHelper",
  8357. value: function _updateHelper(visiblePages) {
  8358. if (this.isInPresentationMode) {
  8359. return;
  8360. }
  8361. var currentId = this._currentPageNumber;
  8362. var stillFullyVisible = false;
  8363. var _iteratorNormalCompletion = true;
  8364. var _didIteratorError = false;
  8365. var _iteratorError = undefined;
  8366. try {
  8367. for (var _iterator = visiblePages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  8368. var page = _step.value;
  8369. if (page.percent < 100) {
  8370. break;
  8371. }
  8372. if (page.id === currentId) {
  8373. stillFullyVisible = true;
  8374. break;
  8375. }
  8376. }
  8377. } catch (err) {
  8378. _didIteratorError = true;
  8379. _iteratorError = err;
  8380. } finally {
  8381. try {
  8382. if (!_iteratorNormalCompletion && _iterator.return != null) {
  8383. _iterator.return();
  8384. }
  8385. } finally {
  8386. if (_didIteratorError) {
  8387. throw _iteratorError;
  8388. }
  8389. }
  8390. }
  8391. if (!stillFullyVisible) {
  8392. currentId = visiblePages[0].id;
  8393. }
  8394. this._setCurrentPageNumber(currentId);
  8395. }
  8396. }, {
  8397. key: "_setDocumentViewerElement",
  8398. get: function get() {
  8399. return (0, _pdfjsLib.shadow)(this, '_setDocumentViewerElement', this.viewer);
  8400. }
  8401. }]);
  8402. return PDFViewer;
  8403. }(_base_viewer.BaseViewer);
  8404. exports.PDFViewer = PDFViewer;
  8405. /***/ }),
  8406. /* 29 */
  8407. /***/ (function(module, exports, __webpack_require__) {
  8408. "use strict";
  8409. Object.defineProperty(exports, "__esModule", {
  8410. value: true
  8411. });
  8412. exports.BaseViewer = void 0;
  8413. var _ui_utils = __webpack_require__(6);
  8414. var _pdf_rendering_queue = __webpack_require__(10);
  8415. var _annotation_layer_builder = __webpack_require__(30);
  8416. var _pdfjsLib = __webpack_require__(7);
  8417. var _pdf_page_view = __webpack_require__(31);
  8418. var _pdf_link_service = __webpack_require__(22);
  8419. var _text_layer_builder = __webpack_require__(32);
  8420. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8421. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8422. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  8423. var DEFAULT_CACHE_SIZE = 10;
  8424. function PDFPageViewBuffer(size) {
  8425. var data = [];
  8426. this.push = function (view) {
  8427. var i = data.indexOf(view);
  8428. if (i >= 0) {
  8429. data.splice(i, 1);
  8430. }
  8431. data.push(view);
  8432. if (data.length > size) {
  8433. data.shift().destroy();
  8434. }
  8435. };
  8436. this.resize = function (newSize, pagesToKeep) {
  8437. size = newSize;
  8438. if (pagesToKeep) {
  8439. var pageIdsToKeep = new Set();
  8440. for (var i = 0, iMax = pagesToKeep.length; i < iMax; ++i) {
  8441. pageIdsToKeep.add(pagesToKeep[i].id);
  8442. }
  8443. (0, _ui_utils.moveToEndOfArray)(data, function (page) {
  8444. return pageIdsToKeep.has(page.id);
  8445. });
  8446. }
  8447. while (data.length > size) {
  8448. data.shift().destroy();
  8449. }
  8450. };
  8451. }
  8452. function isSameScale(oldScale, newScale) {
  8453. if (newScale === oldScale) {
  8454. return true;
  8455. }
  8456. if (Math.abs(newScale - oldScale) < 1e-15) {
  8457. return true;
  8458. }
  8459. return false;
  8460. }
  8461. var BaseViewer =
  8462. /*#__PURE__*/
  8463. function () {
  8464. function BaseViewer(options) {
  8465. var _this = this;
  8466. _classCallCheck(this, BaseViewer);
  8467. if (this.constructor === BaseViewer) {
  8468. throw new Error('Cannot initialize BaseViewer.');
  8469. }
  8470. this._name = this.constructor.name;
  8471. this.container = options.container;
  8472. this.viewer = options.viewer || options.container.firstElementChild;
  8473. this.eventBus = options.eventBus || (0, _ui_utils.getGlobalEventBus)();
  8474. this.linkService = options.linkService || new _pdf_link_service.SimpleLinkService();
  8475. this.downloadManager = options.downloadManager || null;
  8476. this.findController = options.findController || null;
  8477. this.removePageBorders = options.removePageBorders || false;
  8478. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  8479. this.imageResourcesPath = options.imageResourcesPath || '';
  8480. this.renderInteractiveForms = options.renderInteractiveForms || false;
  8481. this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
  8482. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  8483. this.enableWebGL = options.enableWebGL || false;
  8484. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  8485. this.maxCanvasPixels = options.maxCanvasPixels;
  8486. this.l10n = options.l10n || _ui_utils.NullL10n;
  8487. this.defaultRenderingQueue = !options.renderingQueue;
  8488. if (this.defaultRenderingQueue) {
  8489. this.renderingQueue = new _pdf_rendering_queue.PDFRenderingQueue();
  8490. this.renderingQueue.setViewer(this);
  8491. } else {
  8492. this.renderingQueue = options.renderingQueue;
  8493. }
  8494. this.scroll = (0, _ui_utils.watchScroll)(this.container, this._scrollUpdate.bind(this));
  8495. this.presentationModeState = _ui_utils.PresentationModeState.UNKNOWN;
  8496. this._resetView();
  8497. if (this.removePageBorders) {
  8498. this.viewer.classList.add('removePageBorders');
  8499. }
  8500. Promise.resolve().then(function () {
  8501. _this.eventBus.dispatch('baseviewerinit', {
  8502. source: _this
  8503. });
  8504. });
  8505. }
  8506. _createClass(BaseViewer, [{
  8507. key: "getPageView",
  8508. value: function getPageView(index) {
  8509. return this._pages[index];
  8510. }
  8511. }, {
  8512. key: "_setCurrentPageNumber",
  8513. value: function _setCurrentPageNumber(val) {
  8514. var resetCurrentPageView = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  8515. if (this._currentPageNumber === val) {
  8516. if (resetCurrentPageView) {
  8517. this._resetCurrentPageView();
  8518. }
  8519. return true;
  8520. }
  8521. if (!(0 < val && val <= this.pagesCount)) {
  8522. return false;
  8523. }
  8524. this._currentPageNumber = val;
  8525. this.eventBus.dispatch('pagechanging', {
  8526. source: this,
  8527. pageNumber: val,
  8528. pageLabel: this._pageLabels && this._pageLabels[val - 1]
  8529. });
  8530. if (resetCurrentPageView) {
  8531. this._resetCurrentPageView();
  8532. }
  8533. return true;
  8534. }
  8535. }, {
  8536. key: "setDocument",
  8537. value: function setDocument(pdfDocument) {
  8538. var _this2 = this;
  8539. if (this.pdfDocument) {
  8540. this._cancelRendering();
  8541. this._resetView();
  8542. if (this.findController) {
  8543. this.findController.setDocument(null);
  8544. }
  8545. }
  8546. this.pdfDocument = pdfDocument;
  8547. if (!pdfDocument) {
  8548. return;
  8549. }
  8550. var pagesCount = pdfDocument.numPages;
  8551. var pagesCapability = (0, _pdfjsLib.createPromiseCapability)();
  8552. this.pagesPromise = pagesCapability.promise;
  8553. pagesCapability.promise.then(function () {
  8554. _this2._pageViewsReady = true;
  8555. _this2.eventBus.dispatch('pagesloaded', {
  8556. source: _this2,
  8557. pagesCount: pagesCount
  8558. });
  8559. });
  8560. var onePageRenderedCapability = (0, _pdfjsLib.createPromiseCapability)();
  8561. this.onePageRendered = onePageRenderedCapability.promise;
  8562. var bindOnAfterAndBeforeDraw = function bindOnAfterAndBeforeDraw(pageView) {
  8563. pageView.onBeforeDraw = function () {
  8564. _this2._buffer.push(pageView);
  8565. };
  8566. pageView.onAfterDraw = function () {
  8567. if (!onePageRenderedCapability.settled) {
  8568. onePageRenderedCapability.resolve();
  8569. }
  8570. };
  8571. };
  8572. var firstPagePromise = pdfDocument.getPage(1);
  8573. this.firstPagePromise = firstPagePromise;
  8574. firstPagePromise.then(function (pdfPage) {
  8575. var scale = _this2.currentScale;
  8576. var viewport = pdfPage.getViewport({
  8577. scale: scale * _ui_utils.CSS_UNITS
  8578. });
  8579. for (var pageNum = 1; pageNum <= pagesCount; ++pageNum) {
  8580. var textLayerFactory = null;
  8581. if (_this2.textLayerMode !== _ui_utils.TextLayerMode.DISABLE) {
  8582. textLayerFactory = _this2;
  8583. }
  8584. var pageView = new _pdf_page_view.PDFPageView({
  8585. container: _this2._setDocumentViewerElement,
  8586. eventBus: _this2.eventBus,
  8587. id: pageNum,
  8588. scale: scale,
  8589. defaultViewport: viewport.clone(),
  8590. renderingQueue: _this2.renderingQueue,
  8591. textLayerFactory: textLayerFactory,
  8592. textLayerMode: _this2.textLayerMode,
  8593. annotationLayerFactory: _this2,
  8594. imageResourcesPath: _this2.imageResourcesPath,
  8595. renderInteractiveForms: _this2.renderInteractiveForms,
  8596. renderer: _this2.renderer,
  8597. enableWebGL: _this2.enableWebGL,
  8598. useOnlyCssZoom: _this2.useOnlyCssZoom,
  8599. maxCanvasPixels: _this2.maxCanvasPixels,
  8600. l10n: _this2.l10n
  8601. });
  8602. bindOnAfterAndBeforeDraw(pageView);
  8603. _this2._pages.push(pageView);
  8604. }
  8605. if (_this2._spreadMode !== _ui_utils.SpreadMode.NONE) {
  8606. _this2._updateSpreadMode();
  8607. }
  8608. onePageRenderedCapability.promise.then(function () {
  8609. if (pdfDocument.loadingParams['disableAutoFetch']) {
  8610. pagesCapability.resolve();
  8611. return;
  8612. }
  8613. var getPagesLeft = pagesCount;
  8614. var _loop = function _loop(_pageNum) {
  8615. pdfDocument.getPage(_pageNum).then(function (pdfPage) {
  8616. var pageView = _this2._pages[_pageNum - 1];
  8617. if (!pageView.pdfPage) {
  8618. pageView.setPdfPage(pdfPage);
  8619. }
  8620. _this2.linkService.cachePageRef(_pageNum, pdfPage.ref);
  8621. if (--getPagesLeft === 0) {
  8622. pagesCapability.resolve();
  8623. }
  8624. }, function (reason) {
  8625. console.error("Unable to get page ".concat(_pageNum, " to initialize viewer"), reason);
  8626. if (--getPagesLeft === 0) {
  8627. pagesCapability.resolve();
  8628. }
  8629. });
  8630. };
  8631. for (var _pageNum = 1; _pageNum <= pagesCount; ++_pageNum) {
  8632. _loop(_pageNum);
  8633. }
  8634. });
  8635. _this2.eventBus.dispatch('pagesinit', {
  8636. source: _this2
  8637. });
  8638. if (_this2.findController) {
  8639. _this2.findController.setDocument(pdfDocument);
  8640. }
  8641. if (_this2.defaultRenderingQueue) {
  8642. _this2.update();
  8643. }
  8644. }).catch(function (reason) {
  8645. console.error('Unable to initialize viewer', reason);
  8646. });
  8647. }
  8648. }, {
  8649. key: "setPageLabels",
  8650. value: function setPageLabels(labels) {
  8651. if (!this.pdfDocument) {
  8652. return;
  8653. }
  8654. if (!labels) {
  8655. this._pageLabels = null;
  8656. } else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
  8657. this._pageLabels = null;
  8658. console.error("".concat(this._name, ".setPageLabels: Invalid page labels."));
  8659. } else {
  8660. this._pageLabels = labels;
  8661. }
  8662. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  8663. var pageView = this._pages[i];
  8664. var label = this._pageLabels && this._pageLabels[i];
  8665. pageView.setPageLabel(label);
  8666. }
  8667. }
  8668. }, {
  8669. key: "_resetView",
  8670. value: function _resetView() {
  8671. this._pages = [];
  8672. this._currentPageNumber = 1;
  8673. this._currentScale = _ui_utils.UNKNOWN_SCALE;
  8674. this._currentScaleValue = null;
  8675. this._pageLabels = null;
  8676. this._buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
  8677. this._location = null;
  8678. this._pagesRotation = 0;
  8679. this._pagesRequests = [];
  8680. this._pageViewsReady = false;
  8681. this._scrollMode = _ui_utils.ScrollMode.VERTICAL;
  8682. this._spreadMode = _ui_utils.SpreadMode.NONE;
  8683. this.viewer.textContent = '';
  8684. this._updateScrollMode();
  8685. }
  8686. }, {
  8687. key: "_scrollUpdate",
  8688. value: function _scrollUpdate() {
  8689. if (this.pagesCount === 0) {
  8690. return;
  8691. }
  8692. this.update();
  8693. }
  8694. }, {
  8695. key: "_scrollIntoView",
  8696. value: function _scrollIntoView(_ref) {
  8697. var pageDiv = _ref.pageDiv,
  8698. _ref$pageSpot = _ref.pageSpot,
  8699. pageSpot = _ref$pageSpot === void 0 ? null : _ref$pageSpot,
  8700. _ref$pageNumber = _ref.pageNumber,
  8701. pageNumber = _ref$pageNumber === void 0 ? null : _ref$pageNumber;
  8702. (0, _ui_utils.scrollIntoView)(pageDiv, pageSpot);
  8703. }
  8704. }, {
  8705. key: "_setScaleUpdatePages",
  8706. value: function _setScaleUpdatePages(newScale, newValue) {
  8707. var noScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  8708. var preset = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  8709. this._currentScaleValue = newValue.toString();
  8710. if (isSameScale(this._currentScale, newScale)) {
  8711. if (preset) {
  8712. this.eventBus.dispatch('scalechanging', {
  8713. source: this,
  8714. scale: newScale,
  8715. presetValue: newValue
  8716. });
  8717. }
  8718. return;
  8719. }
  8720. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  8721. this._pages[i].update(newScale);
  8722. }
  8723. this._currentScale = newScale;
  8724. if (!noScroll) {
  8725. var page = this._currentPageNumber,
  8726. dest;
  8727. if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) {
  8728. page = this._location.pageNumber;
  8729. dest = [null, {
  8730. name: 'XYZ'
  8731. }, this._location.left, this._location.top, null];
  8732. }
  8733. this.scrollPageIntoView({
  8734. pageNumber: page,
  8735. destArray: dest,
  8736. allowNegativeOffset: true
  8737. });
  8738. }
  8739. this.eventBus.dispatch('scalechanging', {
  8740. source: this,
  8741. scale: newScale,
  8742. presetValue: preset ? newValue : undefined
  8743. });
  8744. if (this.defaultRenderingQueue) {
  8745. this.update();
  8746. }
  8747. }
  8748. }, {
  8749. key: "_setScale",
  8750. value: function _setScale(value) {
  8751. var noScroll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  8752. var scale = parseFloat(value);
  8753. if (scale > 0) {
  8754. this._setScaleUpdatePages(scale, value, noScroll, false);
  8755. } else {
  8756. var currentPage = this._pages[this._currentPageNumber - 1];
  8757. if (!currentPage) {
  8758. return;
  8759. }
  8760. var noPadding = this.isInPresentationMode || this.removePageBorders;
  8761. var hPadding = noPadding ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8762. var vPadding = noPadding ? 0 : _ui_utils.VERTICAL_PADDING;
  8763. if (!noPadding && this._isScrollModeHorizontal) {
  8764. var _ref2 = [vPadding, hPadding];
  8765. hPadding = _ref2[0];
  8766. vPadding = _ref2[1];
  8767. }
  8768. var pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale;
  8769. var pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;
  8770. switch (value) {
  8771. case 'page-actual':
  8772. scale = 1;
  8773. break;
  8774. case 'page-width':
  8775. scale = pageWidthScale;
  8776. break;
  8777. case 'page-height':
  8778. scale = pageHeightScale;
  8779. break;
  8780. case 'page-fit':
  8781. scale = Math.min(pageWidthScale, pageHeightScale);
  8782. break;
  8783. case 'auto':
  8784. var horizontalScale = (0, _ui_utils.isPortraitOrientation)(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale);
  8785. scale = Math.min(_ui_utils.MAX_AUTO_SCALE, horizontalScale);
  8786. break;
  8787. default:
  8788. console.error("".concat(this._name, "._setScale: \"").concat(value, "\" is an unknown zoom value."));
  8789. return;
  8790. }
  8791. this._setScaleUpdatePages(scale, value, noScroll, true);
  8792. }
  8793. }
  8794. }, {
  8795. key: "_resetCurrentPageView",
  8796. value: function _resetCurrentPageView() {
  8797. if (this.isInPresentationMode) {
  8798. this._setScale(this._currentScaleValue, true);
  8799. }
  8800. var pageView = this._pages[this._currentPageNumber - 1];
  8801. this._scrollIntoView({
  8802. pageDiv: pageView.div
  8803. });
  8804. }
  8805. }, {
  8806. key: "scrollPageIntoView",
  8807. value: function scrollPageIntoView(_ref3) {
  8808. var pageNumber = _ref3.pageNumber,
  8809. _ref3$destArray = _ref3.destArray,
  8810. destArray = _ref3$destArray === void 0 ? null : _ref3$destArray,
  8811. _ref3$allowNegativeOf = _ref3.allowNegativeOffset,
  8812. allowNegativeOffset = _ref3$allowNegativeOf === void 0 ? false : _ref3$allowNegativeOf;
  8813. if (!this.pdfDocument) {
  8814. return;
  8815. }
  8816. var pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1];
  8817. if (!pageView) {
  8818. console.error("".concat(this._name, ".scrollPageIntoView: ") + "\"".concat(pageNumber, "\" is not a valid pageNumber parameter."));
  8819. return;
  8820. }
  8821. if (this.isInPresentationMode || !destArray) {
  8822. this._setCurrentPageNumber(pageNumber, true);
  8823. return;
  8824. }
  8825. var x = 0,
  8826. y = 0;
  8827. var width = 0,
  8828. height = 0,
  8829. widthScale,
  8830. heightScale;
  8831. var changeOrientation = pageView.rotation % 180 === 0 ? false : true;
  8832. var pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / _ui_utils.CSS_UNITS;
  8833. var pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / _ui_utils.CSS_UNITS;
  8834. var scale = 0;
  8835. switch (destArray[1].name) {
  8836. case 'XYZ':
  8837. x = destArray[2];
  8838. y = destArray[3];
  8839. scale = destArray[4];
  8840. x = x !== null ? x : 0;
  8841. y = y !== null ? y : pageHeight;
  8842. break;
  8843. case 'Fit':
  8844. case 'FitB':
  8845. scale = 'page-fit';
  8846. break;
  8847. case 'FitH':
  8848. case 'FitBH':
  8849. y = destArray[2];
  8850. scale = 'page-width';
  8851. if (y === null && this._location) {
  8852. x = this._location.left;
  8853. y = this._location.top;
  8854. }
  8855. break;
  8856. case 'FitV':
  8857. case 'FitBV':
  8858. x = destArray[2];
  8859. width = pageWidth;
  8860. height = pageHeight;
  8861. scale = 'page-height';
  8862. break;
  8863. case 'FitR':
  8864. x = destArray[2];
  8865. y = destArray[3];
  8866. width = destArray[4] - x;
  8867. height = destArray[5] - y;
  8868. var hPadding = this.removePageBorders ? 0 : _ui_utils.SCROLLBAR_PADDING;
  8869. var vPadding = this.removePageBorders ? 0 : _ui_utils.VERTICAL_PADDING;
  8870. widthScale = (this.container.clientWidth - hPadding) / width / _ui_utils.CSS_UNITS;
  8871. heightScale = (this.container.clientHeight - vPadding) / height / _ui_utils.CSS_UNITS;
  8872. scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
  8873. break;
  8874. default:
  8875. console.error("".concat(this._name, ".scrollPageIntoView: ") + "\"".concat(destArray[1].name, "\" is not a valid destination type."));
  8876. return;
  8877. }
  8878. if (scale && scale !== this._currentScale) {
  8879. this.currentScaleValue = scale;
  8880. } else if (this._currentScale === _ui_utils.UNKNOWN_SCALE) {
  8881. this.currentScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  8882. }
  8883. if (scale === 'page-fit' && !destArray[4]) {
  8884. this._scrollIntoView({
  8885. pageDiv: pageView.div,
  8886. pageNumber: pageNumber
  8887. });
  8888. return;
  8889. }
  8890. var boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)];
  8891. var left = Math.min(boundingRect[0][0], boundingRect[1][0]);
  8892. var top = Math.min(boundingRect[0][1], boundingRect[1][1]);
  8893. if (!allowNegativeOffset) {
  8894. left = Math.max(left, 0);
  8895. top = Math.max(top, 0);
  8896. }
  8897. this._scrollIntoView({
  8898. pageDiv: pageView.div,
  8899. pageSpot: {
  8900. left: left,
  8901. top: top
  8902. },
  8903. pageNumber: pageNumber
  8904. });
  8905. }
  8906. }, {
  8907. key: "_updateLocation",
  8908. value: function _updateLocation(firstPage) {
  8909. var currentScale = this._currentScale;
  8910. var currentScaleValue = this._currentScaleValue;
  8911. var normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue;
  8912. var pageNumber = firstPage.id;
  8913. var pdfOpenParams = '#page=' + pageNumber;
  8914. pdfOpenParams += '&zoom=' + normalizedScaleValue;
  8915. var currentPageView = this._pages[pageNumber - 1];
  8916. var container = this.container;
  8917. var topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y);
  8918. var intLeft = Math.round(topLeft[0]);
  8919. var intTop = Math.round(topLeft[1]);
  8920. pdfOpenParams += ',' + intLeft + ',' + intTop;
  8921. this._location = {
  8922. pageNumber: pageNumber,
  8923. scale: normalizedScaleValue,
  8924. top: intTop,
  8925. left: intLeft,
  8926. rotation: this._pagesRotation,
  8927. pdfOpenParams: pdfOpenParams
  8928. };
  8929. }
  8930. }, {
  8931. key: "_updateHelper",
  8932. value: function _updateHelper(visiblePages) {
  8933. throw new Error('Not implemented: _updateHelper');
  8934. }
  8935. }, {
  8936. key: "update",
  8937. value: function update() {
  8938. var visible = this._getVisiblePages();
  8939. var visiblePages = visible.views,
  8940. numVisiblePages = visiblePages.length;
  8941. if (numVisiblePages === 0) {
  8942. return;
  8943. }
  8944. var newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1);
  8945. this._buffer.resize(newCacheSize, visiblePages);
  8946. this.renderingQueue.renderHighestPriority(visible);
  8947. this._updateHelper(visiblePages);
  8948. this._updateLocation(visible.first);
  8949. this.eventBus.dispatch('updateviewarea', {
  8950. source: this,
  8951. location: this._location
  8952. });
  8953. }
  8954. }, {
  8955. key: "containsElement",
  8956. value: function containsElement(element) {
  8957. return this.container.contains(element);
  8958. }
  8959. }, {
  8960. key: "focus",
  8961. value: function focus() {
  8962. this.container.focus();
  8963. }
  8964. }, {
  8965. key: "_getCurrentVisiblePage",
  8966. value: function _getCurrentVisiblePage() {
  8967. if (!this.pagesCount) {
  8968. return {
  8969. views: []
  8970. };
  8971. }
  8972. var pageView = this._pages[this._currentPageNumber - 1];
  8973. var element = pageView.div;
  8974. var view = {
  8975. id: pageView.id,
  8976. x: element.offsetLeft + element.clientLeft,
  8977. y: element.offsetTop + element.clientTop,
  8978. view: pageView
  8979. };
  8980. return {
  8981. first: view,
  8982. last: view,
  8983. views: [view]
  8984. };
  8985. }
  8986. }, {
  8987. key: "_getVisiblePages",
  8988. value: function _getVisiblePages() {
  8989. return (0, _ui_utils.getVisibleElements)(this.container, this._pages, true, this._isScrollModeHorizontal);
  8990. }
  8991. }, {
  8992. key: "isPageVisible",
  8993. value: function isPageVisible(pageNumber) {
  8994. if (!this.pdfDocument) {
  8995. return false;
  8996. }
  8997. if (this.pageNumber < 1 || pageNumber > this.pagesCount) {
  8998. console.error("".concat(this._name, ".isPageVisible: \"").concat(pageNumber, "\" is out of bounds."));
  8999. return false;
  9000. }
  9001. return this._getVisiblePages().views.some(function (view) {
  9002. return view.id === pageNumber;
  9003. });
  9004. }
  9005. }, {
  9006. key: "cleanup",
  9007. value: function cleanup() {
  9008. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  9009. if (this._pages[i] && this._pages[i].renderingState !== _pdf_rendering_queue.RenderingStates.FINISHED) {
  9010. this._pages[i].reset();
  9011. }
  9012. }
  9013. }
  9014. }, {
  9015. key: "_cancelRendering",
  9016. value: function _cancelRendering() {
  9017. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  9018. if (this._pages[i]) {
  9019. this._pages[i].cancelRendering();
  9020. }
  9021. }
  9022. }
  9023. }, {
  9024. key: "_ensurePdfPageLoaded",
  9025. value: function _ensurePdfPageLoaded(pageView) {
  9026. var _this3 = this;
  9027. if (pageView.pdfPage) {
  9028. return Promise.resolve(pageView.pdfPage);
  9029. }
  9030. var pageNumber = pageView.id;
  9031. if (this._pagesRequests[pageNumber]) {
  9032. return this._pagesRequests[pageNumber];
  9033. }
  9034. var promise = this.pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  9035. if (!pageView.pdfPage) {
  9036. pageView.setPdfPage(pdfPage);
  9037. }
  9038. _this3._pagesRequests[pageNumber] = null;
  9039. return pdfPage;
  9040. }).catch(function (reason) {
  9041. console.error('Unable to get page for page view', reason);
  9042. _this3._pagesRequests[pageNumber] = null;
  9043. });
  9044. this._pagesRequests[pageNumber] = promise;
  9045. return promise;
  9046. }
  9047. }, {
  9048. key: "forceRendering",
  9049. value: function forceRendering(currentlyVisiblePages) {
  9050. var _this4 = this;
  9051. var visiblePages = currentlyVisiblePages || this._getVisiblePages();
  9052. var scrollAhead = this._isScrollModeHorizontal ? this.scroll.right : this.scroll.down;
  9053. var pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead);
  9054. if (pageView) {
  9055. this._ensurePdfPageLoaded(pageView).then(function () {
  9056. _this4.renderingQueue.renderView(pageView);
  9057. });
  9058. return true;
  9059. }
  9060. return false;
  9061. }
  9062. }, {
  9063. key: "createTextLayerBuilder",
  9064. value: function createTextLayerBuilder(textLayerDiv, pageIndex, viewport) {
  9065. var enhanceTextSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  9066. return new _text_layer_builder.TextLayerBuilder({
  9067. textLayerDiv: textLayerDiv,
  9068. eventBus: this.eventBus,
  9069. pageIndex: pageIndex,
  9070. viewport: viewport,
  9071. findController: this.isInPresentationMode ? null : this.findController,
  9072. enhanceTextSelection: this.isInPresentationMode ? false : enhanceTextSelection
  9073. });
  9074. }
  9075. }, {
  9076. key: "createAnnotationLayerBuilder",
  9077. value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  9078. var imageResourcesPath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  9079. var renderInteractiveForms = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  9080. var l10n = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : _ui_utils.NullL10n;
  9081. return new _annotation_layer_builder.AnnotationLayerBuilder({
  9082. pageDiv: pageDiv,
  9083. pdfPage: pdfPage,
  9084. imageResourcesPath: imageResourcesPath,
  9085. renderInteractiveForms: renderInteractiveForms,
  9086. linkService: this.linkService,
  9087. downloadManager: this.downloadManager,
  9088. l10n: l10n
  9089. });
  9090. }
  9091. }, {
  9092. key: "getPagesOverview",
  9093. value: function getPagesOverview() {
  9094. var pagesOverview = this._pages.map(function (pageView) {
  9095. var viewport = pageView.pdfPage.getViewport({
  9096. scale: 1
  9097. });
  9098. return {
  9099. width: viewport.width,
  9100. height: viewport.height,
  9101. rotation: viewport.rotation
  9102. };
  9103. });
  9104. if (!this.enablePrintAutoRotate) {
  9105. return pagesOverview;
  9106. }
  9107. var isFirstPagePortrait = (0, _ui_utils.isPortraitOrientation)(pagesOverview[0]);
  9108. return pagesOverview.map(function (size) {
  9109. if (isFirstPagePortrait === (0, _ui_utils.isPortraitOrientation)(size)) {
  9110. return size;
  9111. }
  9112. return {
  9113. width: size.height,
  9114. height: size.width,
  9115. rotation: (size.rotation + 90) % 360
  9116. };
  9117. });
  9118. }
  9119. }, {
  9120. key: "_updateScrollMode",
  9121. value: function _updateScrollMode() {
  9122. var pageNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  9123. var scrollMode = this._scrollMode,
  9124. viewer = this.viewer;
  9125. viewer.classList.toggle('scrollHorizontal', scrollMode === _ui_utils.ScrollMode.HORIZONTAL);
  9126. viewer.classList.toggle('scrollWrapped', scrollMode === _ui_utils.ScrollMode.WRAPPED);
  9127. if (!this.pdfDocument || !pageNumber) {
  9128. return;
  9129. }
  9130. if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
  9131. this._setScale(this._currentScaleValue, true);
  9132. }
  9133. this._setCurrentPageNumber(pageNumber, true);
  9134. this.update();
  9135. }
  9136. }, {
  9137. key: "_updateSpreadMode",
  9138. value: function _updateSpreadMode() {
  9139. var pageNumber = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  9140. if (!this.pdfDocument) {
  9141. return;
  9142. }
  9143. var viewer = this.viewer,
  9144. pages = this._pages;
  9145. viewer.textContent = '';
  9146. if (this._spreadMode === _ui_utils.SpreadMode.NONE) {
  9147. for (var i = 0, iMax = pages.length; i < iMax; ++i) {
  9148. viewer.appendChild(pages[i].div);
  9149. }
  9150. } else {
  9151. var parity = this._spreadMode - 1;
  9152. var spread = null;
  9153. for (var _i = 0, _iMax = pages.length; _i < _iMax; ++_i) {
  9154. if (spread === null) {
  9155. spread = document.createElement('div');
  9156. spread.className = 'spread';
  9157. viewer.appendChild(spread);
  9158. } else if (_i % 2 === parity) {
  9159. spread = spread.cloneNode(false);
  9160. viewer.appendChild(spread);
  9161. }
  9162. spread.appendChild(pages[_i].div);
  9163. }
  9164. }
  9165. if (!pageNumber) {
  9166. return;
  9167. }
  9168. this._setCurrentPageNumber(pageNumber, true);
  9169. this.update();
  9170. }
  9171. }, {
  9172. key: "pagesCount",
  9173. get: function get() {
  9174. return this._pages.length;
  9175. }
  9176. }, {
  9177. key: "pageViewsReady",
  9178. get: function get() {
  9179. return this._pageViewsReady;
  9180. }
  9181. }, {
  9182. key: "currentPageNumber",
  9183. get: function get() {
  9184. return this._currentPageNumber;
  9185. },
  9186. set: function set(val) {
  9187. if (!Number.isInteger(val)) {
  9188. throw new Error('Invalid page number.');
  9189. }
  9190. if (!this.pdfDocument) {
  9191. return;
  9192. }
  9193. if (!this._setCurrentPageNumber(val, true)) {
  9194. console.error("".concat(this._name, ".currentPageNumber: \"").concat(val, "\" is not a valid page."));
  9195. }
  9196. }
  9197. }, {
  9198. key: "currentPageLabel",
  9199. get: function get() {
  9200. return this._pageLabels && this._pageLabels[this._currentPageNumber - 1];
  9201. },
  9202. set: function set(val) {
  9203. if (!this.pdfDocument) {
  9204. return;
  9205. }
  9206. var page = val | 0;
  9207. if (this._pageLabels) {
  9208. var i = this._pageLabels.indexOf(val);
  9209. if (i >= 0) {
  9210. page = i + 1;
  9211. }
  9212. }
  9213. if (!this._setCurrentPageNumber(page, true)) {
  9214. console.error("".concat(this._name, ".currentPageLabel: \"").concat(val, "\" is not a valid page."));
  9215. }
  9216. }
  9217. }, {
  9218. key: "currentScale",
  9219. get: function get() {
  9220. return this._currentScale !== _ui_utils.UNKNOWN_SCALE ? this._currentScale : _ui_utils.DEFAULT_SCALE;
  9221. },
  9222. set: function set(val) {
  9223. if (isNaN(val)) {
  9224. throw new Error('Invalid numeric scale.');
  9225. }
  9226. if (!this.pdfDocument) {
  9227. return;
  9228. }
  9229. this._setScale(val, false);
  9230. }
  9231. }, {
  9232. key: "currentScaleValue",
  9233. get: function get() {
  9234. return this._currentScaleValue;
  9235. },
  9236. set: function set(val) {
  9237. if (!this.pdfDocument) {
  9238. return;
  9239. }
  9240. this._setScale(val, false);
  9241. }
  9242. }, {
  9243. key: "pagesRotation",
  9244. get: function get() {
  9245. return this._pagesRotation;
  9246. },
  9247. set: function set(rotation) {
  9248. if (!(0, _ui_utils.isValidRotation)(rotation)) {
  9249. throw new Error('Invalid pages rotation angle.');
  9250. }
  9251. if (!this.pdfDocument) {
  9252. return;
  9253. }
  9254. if (this._pagesRotation === rotation) {
  9255. return;
  9256. }
  9257. this._pagesRotation = rotation;
  9258. var pageNumber = this._currentPageNumber;
  9259. for (var i = 0, ii = this._pages.length; i < ii; i++) {
  9260. var pageView = this._pages[i];
  9261. pageView.update(pageView.scale, rotation);
  9262. }
  9263. if (this._currentScaleValue) {
  9264. this._setScale(this._currentScaleValue, true);
  9265. }
  9266. this.eventBus.dispatch('rotationchanging', {
  9267. source: this,
  9268. pagesRotation: rotation,
  9269. pageNumber: pageNumber
  9270. });
  9271. if (this.defaultRenderingQueue) {
  9272. this.update();
  9273. }
  9274. }
  9275. }, {
  9276. key: "_setDocumentViewerElement",
  9277. get: function get() {
  9278. throw new Error('Not implemented: _setDocumentViewerElement');
  9279. }
  9280. }, {
  9281. key: "_isScrollModeHorizontal",
  9282. get: function get() {
  9283. return this.isInPresentationMode ? false : this._scrollMode === _ui_utils.ScrollMode.HORIZONTAL;
  9284. }
  9285. }, {
  9286. key: "isInPresentationMode",
  9287. get: function get() {
  9288. return this.presentationModeState === _ui_utils.PresentationModeState.FULLSCREEN;
  9289. }
  9290. }, {
  9291. key: "isChangingPresentationMode",
  9292. get: function get() {
  9293. return this.presentationModeState === _ui_utils.PresentationModeState.CHANGING;
  9294. }
  9295. }, {
  9296. key: "isHorizontalScrollbarEnabled",
  9297. get: function get() {
  9298. return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth;
  9299. }
  9300. }, {
  9301. key: "isVerticalScrollbarEnabled",
  9302. get: function get() {
  9303. return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight;
  9304. }
  9305. }, {
  9306. key: "hasEqualPageSizes",
  9307. get: function get() {
  9308. var firstPageView = this._pages[0];
  9309. for (var i = 1, ii = this._pages.length; i < ii; ++i) {
  9310. var pageView = this._pages[i];
  9311. if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) {
  9312. return false;
  9313. }
  9314. }
  9315. return true;
  9316. }
  9317. }, {
  9318. key: "scrollMode",
  9319. get: function get() {
  9320. return this._scrollMode;
  9321. },
  9322. set: function set(mode) {
  9323. if (this._scrollMode === mode) {
  9324. return;
  9325. }
  9326. if (!(0, _ui_utils.isValidScrollMode)(mode)) {
  9327. throw new Error("Invalid scroll mode: ".concat(mode));
  9328. }
  9329. this._scrollMode = mode;
  9330. this.eventBus.dispatch('scrollmodechanged', {
  9331. source: this,
  9332. mode: mode
  9333. });
  9334. this._updateScrollMode(this._currentPageNumber);
  9335. }
  9336. }, {
  9337. key: "spreadMode",
  9338. get: function get() {
  9339. return this._spreadMode;
  9340. },
  9341. set: function set(mode) {
  9342. if (this._spreadMode === mode) {
  9343. return;
  9344. }
  9345. if (!(0, _ui_utils.isValidSpreadMode)(mode)) {
  9346. throw new Error("Invalid spread mode: ".concat(mode));
  9347. }
  9348. this._spreadMode = mode;
  9349. this.eventBus.dispatch('spreadmodechanged', {
  9350. source: this,
  9351. mode: mode
  9352. });
  9353. this._updateSpreadMode(this._currentPageNumber);
  9354. }
  9355. }]);
  9356. return BaseViewer;
  9357. }();
  9358. exports.BaseViewer = BaseViewer;
  9359. /***/ }),
  9360. /* 30 */
  9361. /***/ (function(module, exports, __webpack_require__) {
  9362. "use strict";
  9363. Object.defineProperty(exports, "__esModule", {
  9364. value: true
  9365. });
  9366. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
  9367. var _pdfjsLib = __webpack_require__(7);
  9368. var _ui_utils = __webpack_require__(6);
  9369. var _pdf_link_service = __webpack_require__(22);
  9370. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9371. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9372. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9373. var AnnotationLayerBuilder =
  9374. /*#__PURE__*/
  9375. function () {
  9376. function AnnotationLayerBuilder(_ref) {
  9377. var pageDiv = _ref.pageDiv,
  9378. pdfPage = _ref.pdfPage,
  9379. linkService = _ref.linkService,
  9380. downloadManager = _ref.downloadManager,
  9381. _ref$imageResourcesPa = _ref.imageResourcesPath,
  9382. imageResourcesPath = _ref$imageResourcesPa === void 0 ? '' : _ref$imageResourcesPa,
  9383. _ref$renderInteractiv = _ref.renderInteractiveForms,
  9384. renderInteractiveForms = _ref$renderInteractiv === void 0 ? false : _ref$renderInteractiv,
  9385. _ref$l10n = _ref.l10n,
  9386. l10n = _ref$l10n === void 0 ? _ui_utils.NullL10n : _ref$l10n;
  9387. _classCallCheck(this, AnnotationLayerBuilder);
  9388. this.pageDiv = pageDiv;
  9389. this.pdfPage = pdfPage;
  9390. this.linkService = linkService;
  9391. this.downloadManager = downloadManager;
  9392. this.imageResourcesPath = imageResourcesPath;
  9393. this.renderInteractiveForms = renderInteractiveForms;
  9394. this.l10n = l10n;
  9395. this.div = null;
  9396. this._cancelled = false;
  9397. }
  9398. _createClass(AnnotationLayerBuilder, [{
  9399. key: "render",
  9400. value: function render(viewport) {
  9401. var _this = this;
  9402. var intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'display';
  9403. this.pdfPage.getAnnotations({
  9404. intent: intent
  9405. }).then(function (annotations) {
  9406. if (_this._cancelled) {
  9407. return;
  9408. }
  9409. var parameters = {
  9410. viewport: viewport.clone({
  9411. dontFlip: true
  9412. }),
  9413. div: _this.div,
  9414. annotations: annotations,
  9415. page: _this.pdfPage,
  9416. imageResourcesPath: _this.imageResourcesPath,
  9417. renderInteractiveForms: _this.renderInteractiveForms,
  9418. linkService: _this.linkService,
  9419. downloadManager: _this.downloadManager
  9420. };
  9421. if (_this.div) {
  9422. _pdfjsLib.AnnotationLayer.update(parameters);
  9423. } else {
  9424. if (annotations.length === 0) {
  9425. return;
  9426. }
  9427. _this.div = document.createElement('div');
  9428. _this.div.className = 'annotationLayer';
  9429. _this.pageDiv.appendChild(_this.div);
  9430. parameters.div = _this.div;
  9431. _pdfjsLib.AnnotationLayer.render(parameters);
  9432. _this.l10n.translate(_this.div);
  9433. }
  9434. });
  9435. }
  9436. }, {
  9437. key: "cancel",
  9438. value: function cancel() {
  9439. this._cancelled = true;
  9440. }
  9441. }, {
  9442. key: "hide",
  9443. value: function hide() {
  9444. if (!this.div) {
  9445. return;
  9446. }
  9447. this.div.setAttribute('hidden', 'true');
  9448. }
  9449. }]);
  9450. return AnnotationLayerBuilder;
  9451. }();
  9452. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  9453. var DefaultAnnotationLayerFactory =
  9454. /*#__PURE__*/
  9455. function () {
  9456. function DefaultAnnotationLayerFactory() {
  9457. _classCallCheck(this, DefaultAnnotationLayerFactory);
  9458. }
  9459. _createClass(DefaultAnnotationLayerFactory, [{
  9460. key: "createAnnotationLayerBuilder",
  9461. value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  9462. var imageResourcesPath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  9463. var renderInteractiveForms = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  9464. var l10n = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : _ui_utils.NullL10n;
  9465. return new AnnotationLayerBuilder({
  9466. pageDiv: pageDiv,
  9467. pdfPage: pdfPage,
  9468. imageResourcesPath: imageResourcesPath,
  9469. renderInteractiveForms: renderInteractiveForms,
  9470. linkService: new _pdf_link_service.SimpleLinkService(),
  9471. l10n: l10n
  9472. });
  9473. }
  9474. }]);
  9475. return DefaultAnnotationLayerFactory;
  9476. }();
  9477. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;
  9478. /***/ }),
  9479. /* 31 */
  9480. /***/ (function(module, exports, __webpack_require__) {
  9481. "use strict";
  9482. Object.defineProperty(exports, "__esModule", {
  9483. value: true
  9484. });
  9485. exports.PDFPageView = void 0;
  9486. var _regenerator = _interopRequireDefault(__webpack_require__(2));
  9487. var _ui_utils = __webpack_require__(6);
  9488. var _pdfjsLib = __webpack_require__(7);
  9489. var _pdf_rendering_queue = __webpack_require__(10);
  9490. var _viewer_compatibility = __webpack_require__(13);
  9491. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9492. 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); } }
  9493. 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); }); }; }
  9494. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9495. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9496. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  9497. var MAX_CANVAS_PIXELS = _viewer_compatibility.viewerCompatibilityParams.maxCanvasPixels || 16777216;
  9498. var PDFPageView =
  9499. /*#__PURE__*/
  9500. function () {
  9501. function PDFPageView(options) {
  9502. _classCallCheck(this, PDFPageView);
  9503. var container = options.container;
  9504. var defaultViewport = options.defaultViewport;
  9505. this.id = options.id;
  9506. this.renderingId = 'page' + this.id;
  9507. this.pdfPage = null;
  9508. this.pageLabel = null;
  9509. this.rotation = 0;
  9510. this.scale = options.scale || _ui_utils.DEFAULT_SCALE;
  9511. this.viewport = defaultViewport;
  9512. this.pdfPageRotate = defaultViewport.rotation;
  9513. this.hasRestrictedScaling = false;
  9514. this.textLayerMode = Number.isInteger(options.textLayerMode) ? options.textLayerMode : _ui_utils.TextLayerMode.ENABLE;
  9515. this.imageResourcesPath = options.imageResourcesPath || '';
  9516. this.renderInteractiveForms = options.renderInteractiveForms || false;
  9517. this.useOnlyCssZoom = options.useOnlyCssZoom || false;
  9518. this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
  9519. this.eventBus = options.eventBus || (0, _ui_utils.getGlobalEventBus)();
  9520. this.renderingQueue = options.renderingQueue;
  9521. this.textLayerFactory = options.textLayerFactory;
  9522. this.annotationLayerFactory = options.annotationLayerFactory;
  9523. this.renderer = options.renderer || _ui_utils.RendererType.CANVAS;
  9524. this.enableWebGL = options.enableWebGL || false;
  9525. this.l10n = options.l10n || _ui_utils.NullL10n;
  9526. this.paintTask = null;
  9527. this.paintedViewportMap = new WeakMap();
  9528. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9529. this.resume = null;
  9530. this.error = null;
  9531. this.onBeforeDraw = null;
  9532. this.onAfterDraw = null;
  9533. this.annotationLayer = null;
  9534. this.textLayer = null;
  9535. this.zoomLayer = null;
  9536. var div = document.createElement('div');
  9537. div.className = 'page';
  9538. div.style.width = Math.floor(this.viewport.width) + 'px';
  9539. div.style.height = Math.floor(this.viewport.height) + 'px';
  9540. div.setAttribute('data-page-number', this.id);
  9541. this.div = div;
  9542. container.appendChild(div);
  9543. }
  9544. _createClass(PDFPageView, [{
  9545. key: "setPdfPage",
  9546. value: function setPdfPage(pdfPage) {
  9547. this.pdfPage = pdfPage;
  9548. this.pdfPageRotate = pdfPage.rotate;
  9549. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9550. this.viewport = pdfPage.getViewport({
  9551. scale: this.scale * _ui_utils.CSS_UNITS,
  9552. rotation: totalRotation
  9553. });
  9554. this.stats = pdfPage.stats;
  9555. this.reset();
  9556. }
  9557. }, {
  9558. key: "destroy",
  9559. value: function destroy() {
  9560. this.reset();
  9561. if (this.pdfPage) {
  9562. this.pdfPage.cleanup();
  9563. }
  9564. }
  9565. }, {
  9566. key: "_resetZoomLayer",
  9567. value: function _resetZoomLayer() {
  9568. var removeFromDOM = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  9569. if (!this.zoomLayer) {
  9570. return;
  9571. }
  9572. var zoomLayerCanvas = this.zoomLayer.firstChild;
  9573. this.paintedViewportMap.delete(zoomLayerCanvas);
  9574. zoomLayerCanvas.width = 0;
  9575. zoomLayerCanvas.height = 0;
  9576. if (removeFromDOM) {
  9577. this.zoomLayer.remove();
  9578. }
  9579. this.zoomLayer = null;
  9580. }
  9581. }, {
  9582. key: "reset",
  9583. value: function reset() {
  9584. var keepZoomLayer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  9585. var keepAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  9586. this.cancelRendering(keepAnnotations);
  9587. var div = this.div;
  9588. div.style.width = Math.floor(this.viewport.width) + 'px';
  9589. div.style.height = Math.floor(this.viewport.height) + 'px';
  9590. var childNodes = div.childNodes;
  9591. var currentZoomLayerNode = keepZoomLayer && this.zoomLayer || null;
  9592. var currentAnnotationNode = keepAnnotations && this.annotationLayer && this.annotationLayer.div || null;
  9593. for (var i = childNodes.length - 1; i >= 0; i--) {
  9594. var node = childNodes[i];
  9595. if (currentZoomLayerNode === node || currentAnnotationNode === node) {
  9596. continue;
  9597. }
  9598. div.removeChild(node);
  9599. }
  9600. div.removeAttribute('data-loaded');
  9601. if (currentAnnotationNode) {
  9602. this.annotationLayer.hide();
  9603. } else if (this.annotationLayer) {
  9604. this.annotationLayer.cancel();
  9605. this.annotationLayer = null;
  9606. }
  9607. if (!currentZoomLayerNode) {
  9608. if (this.canvas) {
  9609. this.paintedViewportMap.delete(this.canvas);
  9610. this.canvas.width = 0;
  9611. this.canvas.height = 0;
  9612. delete this.canvas;
  9613. }
  9614. this._resetZoomLayer();
  9615. }
  9616. if (this.svg) {
  9617. this.paintedViewportMap.delete(this.svg);
  9618. delete this.svg;
  9619. }
  9620. this.loadingIconDiv = document.createElement('div');
  9621. this.loadingIconDiv.className = 'loadingIcon';
  9622. div.appendChild(this.loadingIconDiv);
  9623. }
  9624. }, {
  9625. key: "update",
  9626. value: function update(scale, rotation) {
  9627. this.scale = scale || this.scale;
  9628. if (typeof rotation !== 'undefined') {
  9629. this.rotation = rotation;
  9630. }
  9631. var totalRotation = (this.rotation + this.pdfPageRotate) % 360;
  9632. this.viewport = this.viewport.clone({
  9633. scale: this.scale * _ui_utils.CSS_UNITS,
  9634. rotation: totalRotation
  9635. });
  9636. if (this.svg) {
  9637. this.cssTransform(this.svg, true);
  9638. this.eventBus.dispatch('pagerendered', {
  9639. source: this,
  9640. pageNumber: this.id,
  9641. cssTransform: true
  9642. });
  9643. return;
  9644. }
  9645. var isScalingRestricted = false;
  9646. if (this.canvas && this.maxCanvasPixels > 0) {
  9647. var outputScale = this.outputScale;
  9648. if ((Math.floor(this.viewport.width) * outputScale.sx | 0) * (Math.floor(this.viewport.height) * outputScale.sy | 0) > this.maxCanvasPixels) {
  9649. isScalingRestricted = true;
  9650. }
  9651. }
  9652. if (this.canvas) {
  9653. if (this.useOnlyCssZoom || this.hasRestrictedScaling && isScalingRestricted) {
  9654. this.cssTransform(this.canvas, true);
  9655. this.eventBus.dispatch('pagerendered', {
  9656. source: this,
  9657. pageNumber: this.id,
  9658. cssTransform: true
  9659. });
  9660. return;
  9661. }
  9662. if (!this.zoomLayer && !this.canvas.hasAttribute('hidden')) {
  9663. this.zoomLayer = this.canvas.parentNode;
  9664. this.zoomLayer.style.position = 'absolute';
  9665. }
  9666. }
  9667. if (this.zoomLayer) {
  9668. this.cssTransform(this.zoomLayer.firstChild);
  9669. }
  9670. this.reset(true, true);
  9671. }
  9672. }, {
  9673. key: "cancelRendering",
  9674. value: function cancelRendering() {
  9675. var keepAnnotations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  9676. var renderingState = this.renderingState;
  9677. if (this.paintTask) {
  9678. this.paintTask.cancel();
  9679. this.paintTask = null;
  9680. }
  9681. this.renderingState = _pdf_rendering_queue.RenderingStates.INITIAL;
  9682. this.resume = null;
  9683. if (this.textLayer) {
  9684. this.textLayer.cancel();
  9685. this.textLayer = null;
  9686. }
  9687. if (!keepAnnotations && this.annotationLayer) {
  9688. this.annotationLayer.cancel();
  9689. this.annotationLayer = null;
  9690. }
  9691. if (renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  9692. this.eventBus.dispatch('pagecancelled', {
  9693. source: this,
  9694. pageNumber: this.id,
  9695. renderingState: renderingState
  9696. });
  9697. }
  9698. }
  9699. }, {
  9700. key: "cssTransform",
  9701. value: function cssTransform(target) {
  9702. var redrawAnnotations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  9703. var width = this.viewport.width;
  9704. var height = this.viewport.height;
  9705. var div = this.div;
  9706. target.style.width = target.parentNode.style.width = div.style.width = Math.floor(width) + 'px';
  9707. target.style.height = target.parentNode.style.height = div.style.height = Math.floor(height) + 'px';
  9708. var relativeRotation = this.viewport.rotation - this.paintedViewportMap.get(target).rotation;
  9709. var absRotation = Math.abs(relativeRotation);
  9710. var scaleX = 1,
  9711. scaleY = 1;
  9712. if (absRotation === 90 || absRotation === 270) {
  9713. scaleX = height / width;
  9714. scaleY = width / height;
  9715. }
  9716. var cssTransform = 'rotate(' + relativeRotation + 'deg) ' + 'scale(' + scaleX + ',' + scaleY + ')';
  9717. target.style.transform = cssTransform;
  9718. if (this.textLayer) {
  9719. var textLayerViewport = this.textLayer.viewport;
  9720. var textRelativeRotation = this.viewport.rotation - textLayerViewport.rotation;
  9721. var textAbsRotation = Math.abs(textRelativeRotation);
  9722. var scale = width / textLayerViewport.width;
  9723. if (textAbsRotation === 90 || textAbsRotation === 270) {
  9724. scale = width / textLayerViewport.height;
  9725. }
  9726. var textLayerDiv = this.textLayer.textLayerDiv;
  9727. var transX, transY;
  9728. switch (textAbsRotation) {
  9729. case 0:
  9730. transX = transY = 0;
  9731. break;
  9732. case 90:
  9733. transX = 0;
  9734. transY = '-' + textLayerDiv.style.height;
  9735. break;
  9736. case 180:
  9737. transX = '-' + textLayerDiv.style.width;
  9738. transY = '-' + textLayerDiv.style.height;
  9739. break;
  9740. case 270:
  9741. transX = '-' + textLayerDiv.style.width;
  9742. transY = 0;
  9743. break;
  9744. default:
  9745. console.error('Bad rotation value.');
  9746. break;
  9747. }
  9748. textLayerDiv.style.transform = 'rotate(' + textAbsRotation + 'deg) ' + 'scale(' + scale + ', ' + scale + ') ' + 'translate(' + transX + ', ' + transY + ')';
  9749. textLayerDiv.style.transformOrigin = '0% 0%';
  9750. }
  9751. if (redrawAnnotations && this.annotationLayer) {
  9752. this.annotationLayer.render(this.viewport, 'display');
  9753. }
  9754. }
  9755. }, {
  9756. key: "getPagePoint",
  9757. value: function getPagePoint(x, y) {
  9758. return this.viewport.convertToPdfPoint(x, y);
  9759. }
  9760. }, {
  9761. key: "draw",
  9762. value: function draw() {
  9763. var _this = this;
  9764. if (this.renderingState !== _pdf_rendering_queue.RenderingStates.INITIAL) {
  9765. console.error('Must be in new state before drawing');
  9766. this.reset();
  9767. }
  9768. if (!this.pdfPage) {
  9769. this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9770. return Promise.reject(new Error('Page is not loaded'));
  9771. }
  9772. this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9773. var pdfPage = this.pdfPage;
  9774. var div = this.div;
  9775. var canvasWrapper = document.createElement('div');
  9776. canvasWrapper.style.width = div.style.width;
  9777. canvasWrapper.style.height = div.style.height;
  9778. canvasWrapper.classList.add('canvasWrapper');
  9779. if (this.annotationLayer && this.annotationLayer.div) {
  9780. div.insertBefore(canvasWrapper, this.annotationLayer.div);
  9781. } else {
  9782. div.appendChild(canvasWrapper);
  9783. }
  9784. var textLayer = null;
  9785. if (this.textLayerMode !== _ui_utils.TextLayerMode.DISABLE && this.textLayerFactory) {
  9786. var textLayerDiv = document.createElement('div');
  9787. textLayerDiv.className = 'textLayer';
  9788. textLayerDiv.style.width = canvasWrapper.style.width;
  9789. textLayerDiv.style.height = canvasWrapper.style.height;
  9790. if (this.annotationLayer && this.annotationLayer.div) {
  9791. div.insertBefore(textLayerDiv, this.annotationLayer.div);
  9792. } else {
  9793. div.appendChild(textLayerDiv);
  9794. }
  9795. textLayer = this.textLayerFactory.createTextLayerBuilder(textLayerDiv, this.id - 1, this.viewport, this.textLayerMode === _ui_utils.TextLayerMode.ENABLE_ENHANCE);
  9796. }
  9797. this.textLayer = textLayer;
  9798. var renderContinueCallback = null;
  9799. if (this.renderingQueue) {
  9800. renderContinueCallback = function renderContinueCallback(cont) {
  9801. if (!_this.renderingQueue.isHighestPriority(_this)) {
  9802. _this.renderingState = _pdf_rendering_queue.RenderingStates.PAUSED;
  9803. _this.resume = function () {
  9804. _this.renderingState = _pdf_rendering_queue.RenderingStates.RUNNING;
  9805. cont();
  9806. };
  9807. return;
  9808. }
  9809. cont();
  9810. };
  9811. }
  9812. var finishPaintTask =
  9813. /*#__PURE__*/
  9814. function () {
  9815. var _ref = _asyncToGenerator(
  9816. /*#__PURE__*/
  9817. _regenerator.default.mark(function _callee(error) {
  9818. return _regenerator.default.wrap(function _callee$(_context) {
  9819. while (1) {
  9820. switch (_context.prev = _context.next) {
  9821. case 0:
  9822. if (paintTask === _this.paintTask) {
  9823. _this.paintTask = null;
  9824. }
  9825. if (!(error instanceof _pdfjsLib.RenderingCancelledException)) {
  9826. _context.next = 4;
  9827. break;
  9828. }
  9829. _this.error = null;
  9830. return _context.abrupt("return");
  9831. case 4:
  9832. _this.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  9833. if (_this.loadingIconDiv) {
  9834. div.removeChild(_this.loadingIconDiv);
  9835. delete _this.loadingIconDiv;
  9836. }
  9837. _this._resetZoomLayer(true);
  9838. _this.error = error;
  9839. _this.stats = pdfPage.stats;
  9840. if (_this.onAfterDraw) {
  9841. _this.onAfterDraw();
  9842. }
  9843. _this.eventBus.dispatch('pagerendered', {
  9844. source: _this,
  9845. pageNumber: _this.id,
  9846. cssTransform: false
  9847. });
  9848. if (!error) {
  9849. _context.next = 13;
  9850. break;
  9851. }
  9852. throw error;
  9853. case 13:
  9854. case "end":
  9855. return _context.stop();
  9856. }
  9857. }
  9858. }, _callee, this);
  9859. }));
  9860. return function finishPaintTask(_x) {
  9861. return _ref.apply(this, arguments);
  9862. };
  9863. }();
  9864. var paintTask = this.renderer === _ui_utils.RendererType.SVG ? this.paintOnSvg(canvasWrapper) : this.paintOnCanvas(canvasWrapper);
  9865. paintTask.onRenderContinue = renderContinueCallback;
  9866. this.paintTask = paintTask;
  9867. var resultPromise = paintTask.promise.then(function () {
  9868. return finishPaintTask(null).then(function () {
  9869. if (textLayer) {
  9870. var readableStream = pdfPage.streamTextContent({
  9871. normalizeWhitespace: true
  9872. });
  9873. textLayer.setTextContentStream(readableStream);
  9874. textLayer.render();
  9875. }
  9876. });
  9877. }, function (reason) {
  9878. return finishPaintTask(reason);
  9879. });
  9880. if (this.annotationLayerFactory) {
  9881. if (!this.annotationLayer) {
  9882. this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(div, pdfPage, this.imageResourcesPath, this.renderInteractiveForms, this.l10n);
  9883. }
  9884. this.annotationLayer.render(this.viewport, 'display');
  9885. }
  9886. div.setAttribute('data-loaded', true);
  9887. if (this.onBeforeDraw) {
  9888. this.onBeforeDraw();
  9889. }
  9890. return resultPromise;
  9891. }
  9892. }, {
  9893. key: "paintOnCanvas",
  9894. value: function paintOnCanvas(canvasWrapper) {
  9895. var renderCapability = (0, _pdfjsLib.createPromiseCapability)();
  9896. var result = {
  9897. promise: renderCapability.promise,
  9898. onRenderContinue: function onRenderContinue(cont) {
  9899. cont();
  9900. },
  9901. cancel: function cancel() {
  9902. renderTask.cancel();
  9903. }
  9904. };
  9905. var viewport = this.viewport;
  9906. var canvas = document.createElement('canvas');
  9907. canvas.id = this.renderingId;
  9908. canvas.setAttribute('hidden', 'hidden');
  9909. var isCanvasHidden = true;
  9910. var showCanvas = function showCanvas() {
  9911. if (isCanvasHidden) {
  9912. canvas.removeAttribute('hidden');
  9913. isCanvasHidden = false;
  9914. }
  9915. };
  9916. canvasWrapper.appendChild(canvas);
  9917. this.canvas = canvas;
  9918. canvas.mozOpaque = true;
  9919. var ctx = canvas.getContext('2d', {
  9920. alpha: false
  9921. });
  9922. var outputScale = (0, _ui_utils.getOutputScale)(ctx);
  9923. this.outputScale = outputScale;
  9924. if (this.useOnlyCssZoom) {
  9925. var actualSizeViewport = viewport.clone({
  9926. scale: _ui_utils.CSS_UNITS
  9927. });
  9928. outputScale.sx *= actualSizeViewport.width / viewport.width;
  9929. outputScale.sy *= actualSizeViewport.height / viewport.height;
  9930. outputScale.scaled = true;
  9931. }
  9932. if (this.maxCanvasPixels > 0) {
  9933. var pixelsInViewport = viewport.width * viewport.height;
  9934. var maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
  9935. if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
  9936. outputScale.sx = maxScale;
  9937. outputScale.sy = maxScale;
  9938. outputScale.scaled = true;
  9939. this.hasRestrictedScaling = true;
  9940. } else {
  9941. this.hasRestrictedScaling = false;
  9942. }
  9943. }
  9944. var sfx = (0, _ui_utils.approximateFraction)(outputScale.sx);
  9945. var sfy = (0, _ui_utils.approximateFraction)(outputScale.sy);
  9946. canvas.width = (0, _ui_utils.roundToDivide)(viewport.width * outputScale.sx, sfx[0]);
  9947. canvas.height = (0, _ui_utils.roundToDivide)(viewport.height * outputScale.sy, sfy[0]);
  9948. canvas.style.width = (0, _ui_utils.roundToDivide)(viewport.width, sfx[1]) + 'px';
  9949. canvas.style.height = (0, _ui_utils.roundToDivide)(viewport.height, sfy[1]) + 'px';
  9950. this.paintedViewportMap.set(canvas, viewport);
  9951. var transform = !outputScale.scaled ? null : [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
  9952. var renderContext = {
  9953. canvasContext: ctx,
  9954. transform: transform,
  9955. viewport: this.viewport,
  9956. enableWebGL: this.enableWebGL,
  9957. renderInteractiveForms: this.renderInteractiveForms
  9958. };
  9959. var renderTask = this.pdfPage.render(renderContext);
  9960. renderTask.onContinue = function (cont) {
  9961. showCanvas();
  9962. if (result.onRenderContinue) {
  9963. result.onRenderContinue(cont);
  9964. } else {
  9965. cont();
  9966. }
  9967. };
  9968. renderTask.promise.then(function () {
  9969. showCanvas();
  9970. renderCapability.resolve(undefined);
  9971. }, function (error) {
  9972. showCanvas();
  9973. renderCapability.reject(error);
  9974. });
  9975. return result;
  9976. }
  9977. }, {
  9978. key: "paintOnSvg",
  9979. value: function paintOnSvg(wrapper) {
  9980. var _this2 = this;
  9981. var cancelled = false;
  9982. var ensureNotCancelled = function ensureNotCancelled() {
  9983. if (cancelled) {
  9984. throw new _pdfjsLib.RenderingCancelledException('Rendering cancelled, page ' + _this2.id, 'svg');
  9985. }
  9986. };
  9987. var pdfPage = this.pdfPage;
  9988. var actualSizeViewport = this.viewport.clone({
  9989. scale: _ui_utils.CSS_UNITS
  9990. });
  9991. var promise = pdfPage.getOperatorList().then(function (opList) {
  9992. ensureNotCancelled();
  9993. var svgGfx = new _pdfjsLib.SVGGraphics(pdfPage.commonObjs, pdfPage.objs);
  9994. return svgGfx.getSVG(opList, actualSizeViewport).then(function (svg) {
  9995. ensureNotCancelled();
  9996. _this2.svg = svg;
  9997. _this2.paintedViewportMap.set(svg, actualSizeViewport);
  9998. svg.style.width = wrapper.style.width;
  9999. svg.style.height = wrapper.style.height;
  10000. _this2.renderingState = _pdf_rendering_queue.RenderingStates.FINISHED;
  10001. wrapper.appendChild(svg);
  10002. });
  10003. });
  10004. return {
  10005. promise: promise,
  10006. onRenderContinue: function onRenderContinue(cont) {
  10007. cont();
  10008. },
  10009. cancel: function cancel() {
  10010. cancelled = true;
  10011. }
  10012. };
  10013. }
  10014. }, {
  10015. key: "setPageLabel",
  10016. value: function setPageLabel(label) {
  10017. this.pageLabel = typeof label === 'string' ? label : null;
  10018. if (this.pageLabel !== null) {
  10019. this.div.setAttribute('data-page-label', this.pageLabel);
  10020. } else {
  10021. this.div.removeAttribute('data-page-label');
  10022. }
  10023. }
  10024. }, {
  10025. key: "width",
  10026. get: function get() {
  10027. return this.viewport.width;
  10028. }
  10029. }, {
  10030. key: "height",
  10031. get: function get() {
  10032. return this.viewport.height;
  10033. }
  10034. }]);
  10035. return PDFPageView;
  10036. }();
  10037. exports.PDFPageView = PDFPageView;
  10038. /***/ }),
  10039. /* 32 */
  10040. /***/ (function(module, exports, __webpack_require__) {
  10041. "use strict";
  10042. Object.defineProperty(exports, "__esModule", {
  10043. value: true
  10044. });
  10045. exports.DefaultTextLayerFactory = exports.TextLayerBuilder = void 0;
  10046. var _ui_utils = __webpack_require__(6);
  10047. var _pdfjsLib = __webpack_require__(7);
  10048. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10049. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10050. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10051. var EXPAND_DIVS_TIMEOUT = 300;
  10052. var TextLayerBuilder =
  10053. /*#__PURE__*/
  10054. function () {
  10055. function TextLayerBuilder(_ref) {
  10056. var textLayerDiv = _ref.textLayerDiv,
  10057. eventBus = _ref.eventBus,
  10058. pageIndex = _ref.pageIndex,
  10059. viewport = _ref.viewport,
  10060. _ref$findController = _ref.findController,
  10061. findController = _ref$findController === void 0 ? null : _ref$findController,
  10062. _ref$enhanceTextSelec = _ref.enhanceTextSelection,
  10063. enhanceTextSelection = _ref$enhanceTextSelec === void 0 ? false : _ref$enhanceTextSelec;
  10064. _classCallCheck(this, TextLayerBuilder);
  10065. this.textLayerDiv = textLayerDiv;
  10066. this.eventBus = eventBus || (0, _ui_utils.getGlobalEventBus)();
  10067. this.textContent = null;
  10068. this.textContentItemsStr = [];
  10069. this.textContentStream = null;
  10070. this.renderingDone = false;
  10071. this.pageIdx = pageIndex;
  10072. this.pageNumber = this.pageIdx + 1;
  10073. this.matches = [];
  10074. this.viewport = viewport;
  10075. this.textDivs = [];
  10076. this.findController = findController;
  10077. this.textLayerRenderTask = null;
  10078. this.enhanceTextSelection = enhanceTextSelection;
  10079. this._boundEvents = Object.create(null);
  10080. this._bindEvents();
  10081. this._bindMouse();
  10082. }
  10083. _createClass(TextLayerBuilder, [{
  10084. key: "_finishRendering",
  10085. value: function _finishRendering() {
  10086. this.renderingDone = true;
  10087. if (!this.enhanceTextSelection) {
  10088. var endOfContent = document.createElement('div');
  10089. endOfContent.className = 'endOfContent';
  10090. this.textLayerDiv.appendChild(endOfContent);
  10091. }
  10092. this.eventBus.dispatch('textlayerrendered', {
  10093. source: this,
  10094. pageNumber: this.pageNumber,
  10095. numTextDivs: this.textDivs.length
  10096. });
  10097. }
  10098. }, {
  10099. key: "render",
  10100. value: function render() {
  10101. var _this = this;
  10102. var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  10103. if (!(this.textContent || this.textContentStream) || this.renderingDone) {
  10104. return;
  10105. }
  10106. this.cancel();
  10107. this.textDivs = [];
  10108. var textLayerFrag = document.createDocumentFragment();
  10109. this.textLayerRenderTask = (0, _pdfjsLib.renderTextLayer)({
  10110. textContent: this.textContent,
  10111. textContentStream: this.textContentStream,
  10112. container: textLayerFrag,
  10113. viewport: this.viewport,
  10114. textDivs: this.textDivs,
  10115. textContentItemsStr: this.textContentItemsStr,
  10116. timeout: timeout,
  10117. enhanceTextSelection: this.enhanceTextSelection
  10118. });
  10119. this.textLayerRenderTask.promise.then(function () {
  10120. _this.textLayerDiv.appendChild(textLayerFrag);
  10121. _this._finishRendering();
  10122. _this._updateMatches();
  10123. }, function (reason) {});
  10124. }
  10125. }, {
  10126. key: "cancel",
  10127. value: function cancel() {
  10128. if (this.textLayerRenderTask) {
  10129. this.textLayerRenderTask.cancel();
  10130. this.textLayerRenderTask = null;
  10131. }
  10132. }
  10133. }, {
  10134. key: "setTextContentStream",
  10135. value: function setTextContentStream(readableStream) {
  10136. this.cancel();
  10137. this.textContentStream = readableStream;
  10138. }
  10139. }, {
  10140. key: "setTextContent",
  10141. value: function setTextContent(textContent) {
  10142. this.cancel();
  10143. this.textContent = textContent;
  10144. }
  10145. }, {
  10146. key: "_convertMatches",
  10147. value: function _convertMatches(matches, matchesLength) {
  10148. if (!matches) {
  10149. return [];
  10150. }
  10151. var findController = this.findController,
  10152. textContentItemsStr = this.textContentItemsStr;
  10153. var i = 0,
  10154. iIndex = 0;
  10155. var end = textContentItemsStr.length - 1;
  10156. var queryLen = findController.state.query.length;
  10157. var result = [];
  10158. for (var m = 0, mm = matches.length; m < mm; m++) {
  10159. var matchIdx = matches[m];
  10160. while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) {
  10161. iIndex += textContentItemsStr[i].length;
  10162. i++;
  10163. }
  10164. if (i === textContentItemsStr.length) {
  10165. console.error('Could not find a matching mapping');
  10166. }
  10167. var match = {
  10168. begin: {
  10169. divIdx: i,
  10170. offset: matchIdx - iIndex
  10171. }
  10172. };
  10173. if (matchesLength) {
  10174. matchIdx += matchesLength[m];
  10175. } else {
  10176. matchIdx += queryLen;
  10177. }
  10178. while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) {
  10179. iIndex += textContentItemsStr[i].length;
  10180. i++;
  10181. }
  10182. match.end = {
  10183. divIdx: i,
  10184. offset: matchIdx - iIndex
  10185. };
  10186. result.push(match);
  10187. }
  10188. return result;
  10189. }
  10190. }, {
  10191. key: "_renderMatches",
  10192. value: function _renderMatches(matches) {
  10193. if (matches.length === 0) {
  10194. return;
  10195. }
  10196. var findController = this.findController,
  10197. pageIdx = this.pageIdx,
  10198. textContentItemsStr = this.textContentItemsStr,
  10199. textDivs = this.textDivs;
  10200. var isSelectedPage = pageIdx === findController.selected.pageIdx;
  10201. var selectedMatchIdx = findController.selected.matchIdx;
  10202. var highlightAll = findController.state.highlightAll;
  10203. var prevEnd = null;
  10204. var infinity = {
  10205. divIdx: -1,
  10206. offset: undefined
  10207. };
  10208. function beginText(begin, className) {
  10209. var divIdx = begin.divIdx;
  10210. textDivs[divIdx].textContent = '';
  10211. appendTextToDiv(divIdx, 0, begin.offset, className);
  10212. }
  10213. function appendTextToDiv(divIdx, fromOffset, toOffset, className) {
  10214. var div = textDivs[divIdx];
  10215. var content = textContentItemsStr[divIdx].substring(fromOffset, toOffset);
  10216. var node = document.createTextNode(content);
  10217. if (className) {
  10218. var span = document.createElement('span');
  10219. span.className = className;
  10220. span.appendChild(node);
  10221. div.appendChild(span);
  10222. return;
  10223. }
  10224. div.appendChild(node);
  10225. }
  10226. var i0 = selectedMatchIdx,
  10227. i1 = i0 + 1;
  10228. if (highlightAll) {
  10229. i0 = 0;
  10230. i1 = matches.length;
  10231. } else if (!isSelectedPage) {
  10232. return;
  10233. }
  10234. for (var i = i0; i < i1; i++) {
  10235. var match = matches[i];
  10236. var begin = match.begin;
  10237. var end = match.end;
  10238. var isSelected = isSelectedPage && i === selectedMatchIdx;
  10239. var highlightSuffix = isSelected ? ' selected' : '';
  10240. if (isSelected) {
  10241. findController.scrollMatchIntoView({
  10242. element: textDivs[begin.divIdx],
  10243. pageIndex: pageIdx,
  10244. matchIndex: selectedMatchIdx
  10245. });
  10246. }
  10247. if (!prevEnd || begin.divIdx !== prevEnd.divIdx) {
  10248. if (prevEnd !== null) {
  10249. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10250. }
  10251. beginText(begin);
  10252. } else {
  10253. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset);
  10254. }
  10255. if (begin.divIdx === end.divIdx) {
  10256. appendTextToDiv(begin.divIdx, begin.offset, end.offset, 'highlight' + highlightSuffix);
  10257. } else {
  10258. appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, 'highlight begin' + highlightSuffix);
  10259. for (var n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) {
  10260. textDivs[n0].className = 'highlight middle' + highlightSuffix;
  10261. }
  10262. beginText(end, 'highlight end' + highlightSuffix);
  10263. }
  10264. prevEnd = end;
  10265. }
  10266. if (prevEnd) {
  10267. appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset);
  10268. }
  10269. }
  10270. }, {
  10271. key: "_updateMatches",
  10272. value: function _updateMatches() {
  10273. if (!this.renderingDone) {
  10274. return;
  10275. }
  10276. var findController = this.findController,
  10277. matches = this.matches,
  10278. pageIdx = this.pageIdx,
  10279. textContentItemsStr = this.textContentItemsStr,
  10280. textDivs = this.textDivs;
  10281. var clearedUntilDivIdx = -1;
  10282. for (var i = 0, ii = matches.length; i < ii; i++) {
  10283. var match = matches[i];
  10284. var begin = Math.max(clearedUntilDivIdx, match.begin.divIdx);
  10285. for (var n = begin, end = match.end.divIdx; n <= end; n++) {
  10286. var div = textDivs[n];
  10287. div.textContent = textContentItemsStr[n];
  10288. div.className = '';
  10289. }
  10290. clearedUntilDivIdx = match.end.divIdx + 1;
  10291. }
  10292. if (!findController || !findController.highlightMatches) {
  10293. return;
  10294. }
  10295. var pageMatches = findController.pageMatches[pageIdx] || null;
  10296. var pageMatchesLength = findController.pageMatchesLength[pageIdx] || null;
  10297. this.matches = this._convertMatches(pageMatches, pageMatchesLength);
  10298. this._renderMatches(this.matches);
  10299. }
  10300. }, {
  10301. key: "_bindEvents",
  10302. value: function _bindEvents() {
  10303. var _this2 = this;
  10304. var eventBus = this.eventBus,
  10305. _boundEvents = this._boundEvents;
  10306. _boundEvents.pageCancelled = function (evt) {
  10307. if (evt.pageNumber !== _this2.pageNumber) {
  10308. return;
  10309. }
  10310. if (_this2.textLayerRenderTask) {
  10311. console.error('TextLayerBuilder._bindEvents: `this.cancel()` should ' + 'have been called when the page was reset, or rendering cancelled.');
  10312. return;
  10313. }
  10314. for (var name in _boundEvents) {
  10315. eventBus.off(name.toLowerCase(), _boundEvents[name]);
  10316. delete _boundEvents[name];
  10317. }
  10318. };
  10319. _boundEvents.updateTextLayerMatches = function (evt) {
  10320. if (evt.pageIndex !== _this2.pageIdx && evt.pageIndex !== -1) {
  10321. return;
  10322. }
  10323. _this2._updateMatches();
  10324. };
  10325. eventBus.on('pagecancelled', _boundEvents.pageCancelled);
  10326. eventBus.on('updatetextlayermatches', _boundEvents.updateTextLayerMatches);
  10327. }
  10328. }, {
  10329. key: "_bindMouse",
  10330. value: function _bindMouse() {
  10331. var _this3 = this;
  10332. var div = this.textLayerDiv;
  10333. var expandDivsTimer = null;
  10334. div.addEventListener('mousedown', function (evt) {
  10335. if (_this3.enhanceTextSelection && _this3.textLayerRenderTask) {
  10336. _this3.textLayerRenderTask.expandTextDivs(true);
  10337. if (expandDivsTimer) {
  10338. clearTimeout(expandDivsTimer);
  10339. expandDivsTimer = null;
  10340. }
  10341. return;
  10342. }
  10343. var end = div.querySelector('.endOfContent');
  10344. if (!end) {
  10345. return;
  10346. }
  10347. var adjustTop = evt.target !== div;
  10348. adjustTop = adjustTop && window.getComputedStyle(end).getPropertyValue('-moz-user-select') !== 'none';
  10349. if (adjustTop) {
  10350. var divBounds = div.getBoundingClientRect();
  10351. var r = Math.max(0, (evt.pageY - divBounds.top) / divBounds.height);
  10352. end.style.top = (r * 100).toFixed(2) + '%';
  10353. }
  10354. end.classList.add('active');
  10355. });
  10356. div.addEventListener('mouseup', function () {
  10357. if (_this3.enhanceTextSelection && _this3.textLayerRenderTask) {
  10358. expandDivsTimer = setTimeout(function () {
  10359. if (_this3.textLayerRenderTask) {
  10360. _this3.textLayerRenderTask.expandTextDivs(false);
  10361. }
  10362. expandDivsTimer = null;
  10363. }, EXPAND_DIVS_TIMEOUT);
  10364. return;
  10365. }
  10366. var end = div.querySelector('.endOfContent');
  10367. if (!end) {
  10368. return;
  10369. }
  10370. end.style.top = '';
  10371. end.classList.remove('active');
  10372. });
  10373. }
  10374. }]);
  10375. return TextLayerBuilder;
  10376. }();
  10377. exports.TextLayerBuilder = TextLayerBuilder;
  10378. var DefaultTextLayerFactory =
  10379. /*#__PURE__*/
  10380. function () {
  10381. function DefaultTextLayerFactory() {
  10382. _classCallCheck(this, DefaultTextLayerFactory);
  10383. }
  10384. _createClass(DefaultTextLayerFactory, [{
  10385. key: "createTextLayerBuilder",
  10386. value: function createTextLayerBuilder(textLayerDiv, pageIndex, viewport) {
  10387. var enhanceTextSelection = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  10388. return new TextLayerBuilder({
  10389. textLayerDiv: textLayerDiv,
  10390. pageIndex: pageIndex,
  10391. viewport: viewport,
  10392. enhanceTextSelection: enhanceTextSelection
  10393. });
  10394. }
  10395. }]);
  10396. return DefaultTextLayerFactory;
  10397. }();
  10398. exports.DefaultTextLayerFactory = DefaultTextLayerFactory;
  10399. /***/ }),
  10400. /* 33 */
  10401. /***/ (function(module, exports, __webpack_require__) {
  10402. "use strict";
  10403. Object.defineProperty(exports, "__esModule", {
  10404. value: true
  10405. });
  10406. exports.SecondaryToolbar = void 0;
  10407. var _ui_utils = __webpack_require__(6);
  10408. var _pdf_cursor_tools = __webpack_require__(8);
  10409. var _pdf_single_page_viewer = __webpack_require__(34);
  10410. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10411. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10412. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10413. var SecondaryToolbar =
  10414. /*#__PURE__*/
  10415. function () {
  10416. function SecondaryToolbar(options, mainContainer, eventBus) {
  10417. var _this = this;
  10418. _classCallCheck(this, SecondaryToolbar);
  10419. this.toolbar = options.toolbar;
  10420. this.toggleButton = options.toggleButton;
  10421. this.toolbarButtonContainer = options.toolbarButtonContainer;
  10422. this.buttons = [{
  10423. element: options.presentationModeButton,
  10424. eventName: 'presentationmode',
  10425. close: true
  10426. }, {
  10427. element: options.openFileButton,
  10428. eventName: 'openfile',
  10429. close: true
  10430. }, {
  10431. element: options.printButton,
  10432. eventName: 'print',
  10433. close: true
  10434. }, {
  10435. element: options.downloadButton,
  10436. eventName: 'download',
  10437. close: true
  10438. }, {
  10439. element: options.viewBookmarkButton,
  10440. eventName: null,
  10441. close: true
  10442. }, {
  10443. element: options.firstPageButton,
  10444. eventName: 'firstpage',
  10445. close: true
  10446. }, {
  10447. element: options.lastPageButton,
  10448. eventName: 'lastpage',
  10449. close: true
  10450. }, {
  10451. element: options.pageRotateCwButton,
  10452. eventName: 'rotatecw',
  10453. close: false
  10454. }, {
  10455. element: options.pageRotateCcwButton,
  10456. eventName: 'rotateccw',
  10457. close: false
  10458. }, {
  10459. element: options.cursorSelectToolButton,
  10460. eventName: 'switchcursortool',
  10461. eventDetails: {
  10462. tool: _pdf_cursor_tools.CursorTool.SELECT
  10463. },
  10464. close: true
  10465. }, {
  10466. element: options.cursorHandToolButton,
  10467. eventName: 'switchcursortool',
  10468. eventDetails: {
  10469. tool: _pdf_cursor_tools.CursorTool.HAND
  10470. },
  10471. close: true
  10472. }, {
  10473. element: options.scrollVerticalButton,
  10474. eventName: 'switchscrollmode',
  10475. eventDetails: {
  10476. mode: _ui_utils.ScrollMode.VERTICAL
  10477. },
  10478. close: true
  10479. }, {
  10480. element: options.scrollHorizontalButton,
  10481. eventName: 'switchscrollmode',
  10482. eventDetails: {
  10483. mode: _ui_utils.ScrollMode.HORIZONTAL
  10484. },
  10485. close: true
  10486. }, {
  10487. element: options.scrollWrappedButton,
  10488. eventName: 'switchscrollmode',
  10489. eventDetails: {
  10490. mode: _ui_utils.ScrollMode.WRAPPED
  10491. },
  10492. close: true
  10493. }, {
  10494. element: options.spreadNoneButton,
  10495. eventName: 'switchspreadmode',
  10496. eventDetails: {
  10497. mode: _ui_utils.SpreadMode.NONE
  10498. },
  10499. close: true
  10500. }, {
  10501. element: options.spreadOddButton,
  10502. eventName: 'switchspreadmode',
  10503. eventDetails: {
  10504. mode: _ui_utils.SpreadMode.ODD
  10505. },
  10506. close: true
  10507. }, {
  10508. element: options.spreadEvenButton,
  10509. eventName: 'switchspreadmode',
  10510. eventDetails: {
  10511. mode: _ui_utils.SpreadMode.EVEN
  10512. },
  10513. close: true
  10514. }, {
  10515. element: options.documentPropertiesButton,
  10516. eventName: 'documentproperties',
  10517. close: true
  10518. }];
  10519. this.items = {
  10520. firstPage: options.firstPageButton,
  10521. lastPage: options.lastPageButton,
  10522. pageRotateCw: options.pageRotateCwButton,
  10523. pageRotateCcw: options.pageRotateCcwButton
  10524. };
  10525. this.mainContainer = mainContainer;
  10526. this.eventBus = eventBus;
  10527. this.opened = false;
  10528. this.containerHeight = null;
  10529. this.previousContainerHeight = null;
  10530. this.reset();
  10531. this._bindClickListeners();
  10532. this._bindCursorToolsListener(options);
  10533. this._bindScrollModeListener(options);
  10534. this._bindSpreadModeListener(options);
  10535. this.eventBus.on('resize', this._setMaxHeight.bind(this));
  10536. this.eventBus.on('baseviewerinit', function (evt) {
  10537. if (evt.source instanceof _pdf_single_page_viewer.PDFSinglePageViewer) {
  10538. _this.toolbarButtonContainer.classList.add('hiddenScrollModeButtons', 'hiddenSpreadModeButtons');
  10539. } else {
  10540. _this.toolbarButtonContainer.classList.remove('hiddenScrollModeButtons', 'hiddenSpreadModeButtons');
  10541. }
  10542. });
  10543. }
  10544. _createClass(SecondaryToolbar, [{
  10545. key: "setPageNumber",
  10546. value: function setPageNumber(pageNumber) {
  10547. this.pageNumber = pageNumber;
  10548. this._updateUIState();
  10549. }
  10550. }, {
  10551. key: "setPagesCount",
  10552. value: function setPagesCount(pagesCount) {
  10553. this.pagesCount = pagesCount;
  10554. this._updateUIState();
  10555. }
  10556. }, {
  10557. key: "reset",
  10558. value: function reset() {
  10559. this.pageNumber = 0;
  10560. this.pagesCount = 0;
  10561. this._updateUIState();
  10562. this.eventBus.dispatch('secondarytoolbarreset', {
  10563. source: this
  10564. });
  10565. }
  10566. }, {
  10567. key: "_updateUIState",
  10568. value: function _updateUIState() {
  10569. this.items.firstPage.disabled = this.pageNumber <= 1;
  10570. this.items.lastPage.disabled = this.pageNumber >= this.pagesCount;
  10571. this.items.pageRotateCw.disabled = this.pagesCount === 0;
  10572. this.items.pageRotateCcw.disabled = this.pagesCount === 0;
  10573. }
  10574. }, {
  10575. key: "_bindClickListeners",
  10576. value: function _bindClickListeners() {
  10577. var _this2 = this;
  10578. this.toggleButton.addEventListener('click', this.toggle.bind(this));
  10579. var _loop = function _loop(button) {
  10580. var _this2$buttons$button = _this2.buttons[button],
  10581. element = _this2$buttons$button.element,
  10582. eventName = _this2$buttons$button.eventName,
  10583. close = _this2$buttons$button.close,
  10584. eventDetails = _this2$buttons$button.eventDetails;
  10585. element.addEventListener('click', function (evt) {
  10586. if (eventName !== null) {
  10587. var details = {
  10588. source: _this2
  10589. };
  10590. for (var property in eventDetails) {
  10591. details[property] = eventDetails[property];
  10592. }
  10593. _this2.eventBus.dispatch(eventName, details);
  10594. }
  10595. if (close) {
  10596. _this2.close();
  10597. }
  10598. });
  10599. };
  10600. for (var button in this.buttons) {
  10601. _loop(button);
  10602. }
  10603. }
  10604. }, {
  10605. key: "_bindCursorToolsListener",
  10606. value: function _bindCursorToolsListener(buttons) {
  10607. this.eventBus.on('cursortoolchanged', function (_ref) {
  10608. var tool = _ref.tool;
  10609. buttons.cursorSelectToolButton.classList.toggle('toggled', tool === _pdf_cursor_tools.CursorTool.SELECT);
  10610. buttons.cursorHandToolButton.classList.toggle('toggled', tool === _pdf_cursor_tools.CursorTool.HAND);
  10611. });
  10612. }
  10613. }, {
  10614. key: "_bindScrollModeListener",
  10615. value: function _bindScrollModeListener(buttons) {
  10616. var _this3 = this;
  10617. function scrollModeChanged(_ref2) {
  10618. var mode = _ref2.mode;
  10619. buttons.scrollVerticalButton.classList.toggle('toggled', mode === _ui_utils.ScrollMode.VERTICAL);
  10620. buttons.scrollHorizontalButton.classList.toggle('toggled', mode === _ui_utils.ScrollMode.HORIZONTAL);
  10621. buttons.scrollWrappedButton.classList.toggle('toggled', mode === _ui_utils.ScrollMode.WRAPPED);
  10622. var isScrollModeHorizontal = mode === _ui_utils.ScrollMode.HORIZONTAL;
  10623. buttons.spreadNoneButton.disabled = isScrollModeHorizontal;
  10624. buttons.spreadOddButton.disabled = isScrollModeHorizontal;
  10625. buttons.spreadEvenButton.disabled = isScrollModeHorizontal;
  10626. }
  10627. this.eventBus.on('scrollmodechanged', scrollModeChanged);
  10628. this.eventBus.on('secondarytoolbarreset', function (evt) {
  10629. if (evt.source === _this3) {
  10630. scrollModeChanged({
  10631. mode: _ui_utils.ScrollMode.VERTICAL
  10632. });
  10633. }
  10634. });
  10635. }
  10636. }, {
  10637. key: "_bindSpreadModeListener",
  10638. value: function _bindSpreadModeListener(buttons) {
  10639. var _this4 = this;
  10640. function spreadModeChanged(_ref3) {
  10641. var mode = _ref3.mode;
  10642. buttons.spreadNoneButton.classList.toggle('toggled', mode === _ui_utils.SpreadMode.NONE);
  10643. buttons.spreadOddButton.classList.toggle('toggled', mode === _ui_utils.SpreadMode.ODD);
  10644. buttons.spreadEvenButton.classList.toggle('toggled', mode === _ui_utils.SpreadMode.EVEN);
  10645. }
  10646. this.eventBus.on('spreadmodechanged', spreadModeChanged);
  10647. this.eventBus.on('secondarytoolbarreset', function (evt) {
  10648. if (evt.source === _this4) {
  10649. spreadModeChanged({
  10650. mode: _ui_utils.SpreadMode.NONE
  10651. });
  10652. }
  10653. });
  10654. }
  10655. }, {
  10656. key: "open",
  10657. value: function open() {
  10658. if (this.opened) {
  10659. return;
  10660. }
  10661. this.opened = true;
  10662. this._setMaxHeight();
  10663. this.toggleButton.classList.add('toggled');
  10664. this.toolbar.classList.remove('hidden');
  10665. }
  10666. }, {
  10667. key: "close",
  10668. value: function close() {
  10669. if (!this.opened) {
  10670. return;
  10671. }
  10672. this.opened = false;
  10673. this.toolbar.classList.add('hidden');
  10674. this.toggleButton.classList.remove('toggled');
  10675. }
  10676. }, {
  10677. key: "toggle",
  10678. value: function toggle() {
  10679. if (this.opened) {
  10680. this.close();
  10681. } else {
  10682. this.open();
  10683. }
  10684. }
  10685. }, {
  10686. key: "_setMaxHeight",
  10687. value: function _setMaxHeight() {
  10688. if (!this.opened) {
  10689. return;
  10690. }
  10691. this.containerHeight = this.mainContainer.clientHeight;
  10692. if (this.containerHeight === this.previousContainerHeight) {
  10693. return;
  10694. }
  10695. this.toolbarButtonContainer.setAttribute('style', 'max-height: ' + (this.containerHeight - _ui_utils.SCROLLBAR_PADDING) + 'px;');
  10696. this.previousContainerHeight = this.containerHeight;
  10697. }
  10698. }, {
  10699. key: "isOpen",
  10700. get: function get() {
  10701. return this.opened;
  10702. }
  10703. }]);
  10704. return SecondaryToolbar;
  10705. }();
  10706. exports.SecondaryToolbar = SecondaryToolbar;
  10707. /***/ }),
  10708. /* 34 */
  10709. /***/ (function(module, exports, __webpack_require__) {
  10710. "use strict";
  10711. Object.defineProperty(exports, "__esModule", {
  10712. value: true
  10713. });
  10714. exports.PDFSinglePageViewer = void 0;
  10715. var _base_viewer = __webpack_require__(29);
  10716. var _pdfjsLib = __webpack_require__(7);
  10717. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  10718. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10719. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10720. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10721. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10722. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  10723. function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
  10724. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  10725. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10726. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  10727. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  10728. var PDFSinglePageViewer =
  10729. /*#__PURE__*/
  10730. function (_BaseViewer) {
  10731. _inherits(PDFSinglePageViewer, _BaseViewer);
  10732. function PDFSinglePageViewer(options) {
  10733. var _this;
  10734. _classCallCheck(this, PDFSinglePageViewer);
  10735. _this = _possibleConstructorReturn(this, _getPrototypeOf(PDFSinglePageViewer).call(this, options));
  10736. _this.eventBus.on('pagesinit', function (evt) {
  10737. _this._ensurePageViewVisible();
  10738. });
  10739. return _this;
  10740. }
  10741. _createClass(PDFSinglePageViewer, [{
  10742. key: "_resetView",
  10743. value: function _resetView() {
  10744. _get(_getPrototypeOf(PDFSinglePageViewer.prototype), "_resetView", this).call(this);
  10745. this._previousPageNumber = 1;
  10746. this._shadowViewer = document.createDocumentFragment();
  10747. this._updateScrollDown = null;
  10748. }
  10749. }, {
  10750. key: "_ensurePageViewVisible",
  10751. value: function _ensurePageViewVisible() {
  10752. var pageView = this._pages[this._currentPageNumber - 1];
  10753. var previousPageView = this._pages[this._previousPageNumber - 1];
  10754. var viewerNodes = this.viewer.childNodes;
  10755. switch (viewerNodes.length) {
  10756. case 0:
  10757. this.viewer.appendChild(pageView.div);
  10758. break;
  10759. case 1:
  10760. if (viewerNodes[0] !== previousPageView.div) {
  10761. throw new Error('_ensurePageViewVisible: Unexpected previously visible page.');
  10762. }
  10763. if (pageView === previousPageView) {
  10764. break;
  10765. }
  10766. this._shadowViewer.appendChild(previousPageView.div);
  10767. this.viewer.appendChild(pageView.div);
  10768. this.container.scrollTop = 0;
  10769. break;
  10770. default:
  10771. throw new Error('_ensurePageViewVisible: Only one page should be visible at a time.');
  10772. }
  10773. this._previousPageNumber = this._currentPageNumber;
  10774. }
  10775. }, {
  10776. key: "_scrollUpdate",
  10777. value: function _scrollUpdate() {
  10778. if (this._updateScrollDown) {
  10779. this._updateScrollDown();
  10780. }
  10781. _get(_getPrototypeOf(PDFSinglePageViewer.prototype), "_scrollUpdate", this).call(this);
  10782. }
  10783. }, {
  10784. key: "_scrollIntoView",
  10785. value: function _scrollIntoView(_ref) {
  10786. var _this2 = this;
  10787. var pageDiv = _ref.pageDiv,
  10788. _ref$pageSpot = _ref.pageSpot,
  10789. pageSpot = _ref$pageSpot === void 0 ? null : _ref$pageSpot,
  10790. _ref$pageNumber = _ref.pageNumber,
  10791. pageNumber = _ref$pageNumber === void 0 ? null : _ref$pageNumber;
  10792. if (pageNumber) {
  10793. this._setCurrentPageNumber(pageNumber);
  10794. }
  10795. var scrolledDown = this._currentPageNumber >= this._previousPageNumber;
  10796. this._ensurePageViewVisible();
  10797. this.update();
  10798. _get(_getPrototypeOf(PDFSinglePageViewer.prototype), "_scrollIntoView", this).call(this, {
  10799. pageDiv: pageDiv,
  10800. pageSpot: pageSpot,
  10801. pageNumber: pageNumber
  10802. });
  10803. this._updateScrollDown = function () {
  10804. _this2.scroll.down = scrolledDown;
  10805. _this2._updateScrollDown = null;
  10806. };
  10807. }
  10808. }, {
  10809. key: "_getVisiblePages",
  10810. value: function _getVisiblePages() {
  10811. return this._getCurrentVisiblePage();
  10812. }
  10813. }, {
  10814. key: "_updateHelper",
  10815. value: function _updateHelper(visiblePages) {}
  10816. }, {
  10817. key: "_updateScrollMode",
  10818. value: function _updateScrollMode() {}
  10819. }, {
  10820. key: "_updateSpreadMode",
  10821. value: function _updateSpreadMode() {}
  10822. }, {
  10823. key: "_setDocumentViewerElement",
  10824. get: function get() {
  10825. return (0, _pdfjsLib.shadow)(this, '_setDocumentViewerElement', this._shadowViewer);
  10826. }
  10827. }, {
  10828. key: "_isScrollModeHorizontal",
  10829. get: function get() {
  10830. return (0, _pdfjsLib.shadow)(this, '_isScrollModeHorizontal', false);
  10831. }
  10832. }]);
  10833. return PDFSinglePageViewer;
  10834. }(_base_viewer.BaseViewer);
  10835. exports.PDFSinglePageViewer = PDFSinglePageViewer;
  10836. /***/ }),
  10837. /* 35 */
  10838. /***/ (function(module, exports, __webpack_require__) {
  10839. "use strict";
  10840. Object.defineProperty(exports, "__esModule", {
  10841. value: true
  10842. });
  10843. exports.Toolbar = void 0;
  10844. var _ui_utils = __webpack_require__(6);
  10845. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10846. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  10847. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  10848. var PAGE_NUMBER_LOADING_INDICATOR = 'visiblePageIsLoading';
  10849. var SCALE_SELECT_CONTAINER_PADDING = 8;
  10850. var SCALE_SELECT_PADDING = 22;
  10851. var Toolbar =
  10852. /*#__PURE__*/
  10853. function () {
  10854. function Toolbar(options, eventBus) {
  10855. var l10n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ui_utils.NullL10n;
  10856. _classCallCheck(this, Toolbar);
  10857. this.toolbar = options.container;
  10858. this.eventBus = eventBus;
  10859. this.l10n = l10n;
  10860. this.items = options;
  10861. this._wasLocalized = false;
  10862. this.reset();
  10863. this._bindListeners();
  10864. }
  10865. _createClass(Toolbar, [{
  10866. key: "setPageNumber",
  10867. value: function setPageNumber(pageNumber, pageLabel) {
  10868. this.pageNumber = pageNumber;
  10869. this.pageLabel = pageLabel;
  10870. this._updateUIState(false);
  10871. }
  10872. }, {
  10873. key: "setPagesCount",
  10874. value: function setPagesCount(pagesCount, hasPageLabels) {
  10875. this.pagesCount = pagesCount;
  10876. this.hasPageLabels = hasPageLabels;
  10877. this._updateUIState(true);
  10878. }
  10879. }, {
  10880. key: "setPageScale",
  10881. value: function setPageScale(pageScaleValue, pageScale) {
  10882. this.pageScaleValue = (pageScaleValue || pageScale).toString();
  10883. this.pageScale = pageScale;
  10884. this._updateUIState(false);
  10885. }
  10886. }, {
  10887. key: "reset",
  10888. value: function reset() {
  10889. this.pageNumber = 0;
  10890. this.pageLabel = null;
  10891. this.hasPageLabels = false;
  10892. this.pagesCount = 0;
  10893. this.pageScaleValue = _ui_utils.DEFAULT_SCALE_VALUE;
  10894. this.pageScale = _ui_utils.DEFAULT_SCALE;
  10895. this._updateUIState(true);
  10896. }
  10897. }, {
  10898. key: "_bindListeners",
  10899. value: function _bindListeners() {
  10900. var _this = this;
  10901. var eventBus = this.eventBus,
  10902. items = this.items;
  10903. var self = this;
  10904. items.previous.addEventListener('click', function () {
  10905. eventBus.dispatch('previouspage', {
  10906. source: self
  10907. });
  10908. });
  10909. items.next.addEventListener('click', function () {
  10910. eventBus.dispatch('nextpage', {
  10911. source: self
  10912. });
  10913. });
  10914. items.zoomIn.addEventListener('click', function () {
  10915. eventBus.dispatch('zoomin', {
  10916. source: self
  10917. });
  10918. });
  10919. items.zoomOut.addEventListener('click', function () {
  10920. eventBus.dispatch('zoomout', {
  10921. source: self
  10922. });
  10923. });
  10924. items.pageNumber.addEventListener('click', function () {
  10925. this.select();
  10926. });
  10927. items.pageNumber.addEventListener('change', function () {
  10928. eventBus.dispatch('pagenumberchanged', {
  10929. source: self,
  10930. value: this.value
  10931. });
  10932. });
  10933. items.scaleSelect.addEventListener('change', function () {
  10934. if (this.value === 'custom') {
  10935. return;
  10936. }
  10937. eventBus.dispatch('scalechanged', {
  10938. source: self,
  10939. value: this.value
  10940. });
  10941. });
  10942. items.presentationModeButton.addEventListener('click', function () {
  10943. eventBus.dispatch('presentationmode', {
  10944. source: self
  10945. });
  10946. });
  10947. items.openFile.addEventListener('click', function () {
  10948. eventBus.dispatch('openfile', {
  10949. source: self
  10950. });
  10951. });
  10952. items.print.addEventListener('click', function () {
  10953. eventBus.dispatch('print', {
  10954. source: self
  10955. });
  10956. });
  10957. items.download.addEventListener('click', function () {
  10958. eventBus.dispatch('download', {
  10959. source: self
  10960. });
  10961. });
  10962. items.scaleSelect.oncontextmenu = _ui_utils.noContextMenuHandler;
  10963. eventBus.on('localized', function () {
  10964. _this._localized();
  10965. });
  10966. }
  10967. }, {
  10968. key: "_localized",
  10969. value: function _localized() {
  10970. this._wasLocalized = true;
  10971. this._adjustScaleWidth();
  10972. this._updateUIState(true);
  10973. }
  10974. }, {
  10975. key: "_updateUIState",
  10976. value: function _updateUIState() {
  10977. var resetNumPages = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  10978. if (!this._wasLocalized) {
  10979. return;
  10980. }
  10981. var pageNumber = this.pageNumber,
  10982. pagesCount = this.pagesCount,
  10983. pageScaleValue = this.pageScaleValue,
  10984. pageScale = this.pageScale,
  10985. items = this.items;
  10986. if (resetNumPages) {
  10987. if (this.hasPageLabels) {
  10988. items.pageNumber.type = 'text';
  10989. } else {
  10990. items.pageNumber.type = 'number';
  10991. this.l10n.get('of_pages', {
  10992. pagesCount: pagesCount
  10993. }, 'of {{pagesCount}}').then(function (msg) {
  10994. items.numPages.textContent = msg;
  10995. });
  10996. }
  10997. items.pageNumber.max = pagesCount;
  10998. }
  10999. if (this.hasPageLabels) {
  11000. items.pageNumber.value = this.pageLabel;
  11001. this.l10n.get('page_of_pages', {
  11002. pageNumber: pageNumber,
  11003. pagesCount: pagesCount
  11004. }, '({{pageNumber}} of {{pagesCount}})').then(function (msg) {
  11005. items.numPages.textContent = msg;
  11006. });
  11007. } else {
  11008. items.pageNumber.value = pageNumber;
  11009. }
  11010. items.previous.disabled = pageNumber <= 1;
  11011. items.next.disabled = pageNumber >= pagesCount;
  11012. items.zoomOut.disabled = pageScale <= _ui_utils.MIN_SCALE;
  11013. items.zoomIn.disabled = pageScale >= _ui_utils.MAX_SCALE;
  11014. var customScale = Math.round(pageScale * 10000) / 100;
  11015. this.l10n.get('page_scale_percent', {
  11016. scale: customScale
  11017. }, '{{scale}}%').then(function (msg) {
  11018. var options = items.scaleSelect.options;
  11019. var predefinedValueFound = false;
  11020. for (var i = 0, ii = options.length; i < ii; i++) {
  11021. var option = options[i];
  11022. if (option.value !== pageScaleValue) {
  11023. option.selected = false;
  11024. continue;
  11025. }
  11026. option.selected = true;
  11027. predefinedValueFound = true;
  11028. }
  11029. if (!predefinedValueFound) {
  11030. items.customScaleOption.textContent = msg;
  11031. items.customScaleOption.selected = true;
  11032. }
  11033. });
  11034. }
  11035. }, {
  11036. key: "updateLoadingIndicatorState",
  11037. value: function updateLoadingIndicatorState() {
  11038. var loading = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  11039. var pageNumberInput = this.items.pageNumber;
  11040. pageNumberInput.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
  11041. }
  11042. }, {
  11043. key: "_adjustScaleWidth",
  11044. value: function _adjustScaleWidth() {
  11045. var container = this.items.scaleSelectContainer;
  11046. var select = this.items.scaleSelect;
  11047. _ui_utils.animationStarted.then(function () {
  11048. if (container.clientWidth === 0) {
  11049. container.setAttribute('style', 'display: inherit;');
  11050. }
  11051. if (container.clientWidth > 0) {
  11052. select.setAttribute('style', 'min-width: inherit;');
  11053. var width = select.clientWidth + SCALE_SELECT_CONTAINER_PADDING;
  11054. select.setAttribute('style', 'min-width: ' + (width + SCALE_SELECT_PADDING) + 'px;');
  11055. container.setAttribute('style', 'min-width: ' + width + 'px; ' + 'max-width: ' + width + 'px;');
  11056. }
  11057. });
  11058. }
  11059. }]);
  11060. return Toolbar;
  11061. }();
  11062. exports.Toolbar = Toolbar;
  11063. /***/ }),
  11064. /* 36 */
  11065. /***/ (function(module, exports, __webpack_require__) {
  11066. "use strict";
  11067. Object.defineProperty(exports, "__esModule", {
  11068. value: true
  11069. });
  11070. exports.ViewHistory = void 0;
  11071. var _regenerator = _interopRequireDefault(__webpack_require__(2));
  11072. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11073. 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); } }
  11074. 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); }); }; }
  11075. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11076. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11077. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11078. var DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20;
  11079. var ViewHistory =
  11080. /*#__PURE__*/
  11081. function () {
  11082. function ViewHistory(fingerprint) {
  11083. var _this = this;
  11084. var cacheSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_VIEW_HISTORY_CACHE_SIZE;
  11085. _classCallCheck(this, ViewHistory);
  11086. this.fingerprint = fingerprint;
  11087. this.cacheSize = cacheSize;
  11088. this._initializedPromise = this._readFromStorage().then(function (databaseStr) {
  11089. var database = JSON.parse(databaseStr || '{}');
  11090. if (!('files' in database)) {
  11091. database.files = [];
  11092. } else {
  11093. while (database.files.length >= _this.cacheSize) {
  11094. database.files.shift();
  11095. }
  11096. }
  11097. var index = -1;
  11098. for (var i = 0, length = database.files.length; i < length; i++) {
  11099. var branch = database.files[i];
  11100. if (branch.fingerprint === _this.fingerprint) {
  11101. index = i;
  11102. break;
  11103. }
  11104. }
  11105. if (index === -1) {
  11106. index = database.files.push({
  11107. fingerprint: _this.fingerprint
  11108. }) - 1;
  11109. }
  11110. _this.file = database.files[index];
  11111. _this.database = database;
  11112. });
  11113. }
  11114. _createClass(ViewHistory, [{
  11115. key: "_writeToStorage",
  11116. value: function () {
  11117. var _writeToStorage2 = _asyncToGenerator(
  11118. /*#__PURE__*/
  11119. _regenerator.default.mark(function _callee() {
  11120. var databaseStr;
  11121. return _regenerator.default.wrap(function _callee$(_context) {
  11122. while (1) {
  11123. switch (_context.prev = _context.next) {
  11124. case 0:
  11125. databaseStr = JSON.stringify(this.database);
  11126. localStorage.setItem('pdfjs.history', databaseStr);
  11127. case 2:
  11128. case "end":
  11129. return _context.stop();
  11130. }
  11131. }
  11132. }, _callee, this);
  11133. }));
  11134. function _writeToStorage() {
  11135. return _writeToStorage2.apply(this, arguments);
  11136. }
  11137. return _writeToStorage;
  11138. }()
  11139. }, {
  11140. key: "_readFromStorage",
  11141. value: function () {
  11142. var _readFromStorage2 = _asyncToGenerator(
  11143. /*#__PURE__*/
  11144. _regenerator.default.mark(function _callee2() {
  11145. return _regenerator.default.wrap(function _callee2$(_context2) {
  11146. while (1) {
  11147. switch (_context2.prev = _context2.next) {
  11148. case 0:
  11149. return _context2.abrupt("return", localStorage.getItem('pdfjs.history'));
  11150. case 1:
  11151. case "end":
  11152. return _context2.stop();
  11153. }
  11154. }
  11155. }, _callee2, this);
  11156. }));
  11157. function _readFromStorage() {
  11158. return _readFromStorage2.apply(this, arguments);
  11159. }
  11160. return _readFromStorage;
  11161. }()
  11162. }, {
  11163. key: "set",
  11164. value: function () {
  11165. var _set = _asyncToGenerator(
  11166. /*#__PURE__*/
  11167. _regenerator.default.mark(function _callee3(name, val) {
  11168. return _regenerator.default.wrap(function _callee3$(_context3) {
  11169. while (1) {
  11170. switch (_context3.prev = _context3.next) {
  11171. case 0:
  11172. _context3.next = 2;
  11173. return this._initializedPromise;
  11174. case 2:
  11175. this.file[name] = val;
  11176. return _context3.abrupt("return", this._writeToStorage());
  11177. case 4:
  11178. case "end":
  11179. return _context3.stop();
  11180. }
  11181. }
  11182. }, _callee3, this);
  11183. }));
  11184. function set(_x, _x2) {
  11185. return _set.apply(this, arguments);
  11186. }
  11187. return set;
  11188. }()
  11189. }, {
  11190. key: "setMultiple",
  11191. value: function () {
  11192. var _setMultiple = _asyncToGenerator(
  11193. /*#__PURE__*/
  11194. _regenerator.default.mark(function _callee4(properties) {
  11195. var name;
  11196. return _regenerator.default.wrap(function _callee4$(_context4) {
  11197. while (1) {
  11198. switch (_context4.prev = _context4.next) {
  11199. case 0:
  11200. _context4.next = 2;
  11201. return this._initializedPromise;
  11202. case 2:
  11203. for (name in properties) {
  11204. this.file[name] = properties[name];
  11205. }
  11206. return _context4.abrupt("return", this._writeToStorage());
  11207. case 4:
  11208. case "end":
  11209. return _context4.stop();
  11210. }
  11211. }
  11212. }, _callee4, this);
  11213. }));
  11214. function setMultiple(_x3) {
  11215. return _setMultiple.apply(this, arguments);
  11216. }
  11217. return setMultiple;
  11218. }()
  11219. }, {
  11220. key: "get",
  11221. value: function () {
  11222. var _get = _asyncToGenerator(
  11223. /*#__PURE__*/
  11224. _regenerator.default.mark(function _callee5(name, defaultValue) {
  11225. var val;
  11226. return _regenerator.default.wrap(function _callee5$(_context5) {
  11227. while (1) {
  11228. switch (_context5.prev = _context5.next) {
  11229. case 0:
  11230. _context5.next = 2;
  11231. return this._initializedPromise;
  11232. case 2:
  11233. val = this.file[name];
  11234. return _context5.abrupt("return", val !== undefined ? val : defaultValue);
  11235. case 4:
  11236. case "end":
  11237. return _context5.stop();
  11238. }
  11239. }
  11240. }, _callee5, this);
  11241. }));
  11242. function get(_x4, _x5) {
  11243. return _get.apply(this, arguments);
  11244. }
  11245. return get;
  11246. }()
  11247. }, {
  11248. key: "getMultiple",
  11249. value: function () {
  11250. var _getMultiple = _asyncToGenerator(
  11251. /*#__PURE__*/
  11252. _regenerator.default.mark(function _callee6(properties) {
  11253. var values, name, val;
  11254. return _regenerator.default.wrap(function _callee6$(_context6) {
  11255. while (1) {
  11256. switch (_context6.prev = _context6.next) {
  11257. case 0:
  11258. _context6.next = 2;
  11259. return this._initializedPromise;
  11260. case 2:
  11261. values = Object.create(null);
  11262. for (name in properties) {
  11263. val = this.file[name];
  11264. values[name] = val !== undefined ? val : properties[name];
  11265. }
  11266. return _context6.abrupt("return", values);
  11267. case 5:
  11268. case "end":
  11269. return _context6.stop();
  11270. }
  11271. }
  11272. }, _callee6, this);
  11273. }));
  11274. function getMultiple(_x6) {
  11275. return _getMultiple.apply(this, arguments);
  11276. }
  11277. return getMultiple;
  11278. }()
  11279. }]);
  11280. return ViewHistory;
  11281. }();
  11282. exports.ViewHistory = ViewHistory;
  11283. /***/ }),
  11284. /* 37 */
  11285. /***/ (function(module, exports, __webpack_require__) {
  11286. "use strict";
  11287. Object.defineProperty(exports, "__esModule", {
  11288. value: true
  11289. });
  11290. exports.GenericCom = void 0;
  11291. var _regenerator = _interopRequireDefault(__webpack_require__(2));
  11292. var _app = __webpack_require__(1);
  11293. var _preferences = __webpack_require__(38);
  11294. var _download_manager = __webpack_require__(39);
  11295. var _genericl10n = __webpack_require__(40);
  11296. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11297. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11298. 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); } }
  11299. 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); }); }; }
  11300. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11301. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11302. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11303. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  11304. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11305. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  11306. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11307. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  11308. ;
  11309. var GenericCom = {};
  11310. exports.GenericCom = GenericCom;
  11311. var GenericPreferences =
  11312. /*#__PURE__*/
  11313. function (_BasePreferences) {
  11314. _inherits(GenericPreferences, _BasePreferences);
  11315. function GenericPreferences() {
  11316. _classCallCheck(this, GenericPreferences);
  11317. return _possibleConstructorReturn(this, _getPrototypeOf(GenericPreferences).apply(this, arguments));
  11318. }
  11319. _createClass(GenericPreferences, [{
  11320. key: "_writeToStorage",
  11321. value: function () {
  11322. var _writeToStorage2 = _asyncToGenerator(
  11323. /*#__PURE__*/
  11324. _regenerator.default.mark(function _callee(prefObj) {
  11325. return _regenerator.default.wrap(function _callee$(_context) {
  11326. while (1) {
  11327. switch (_context.prev = _context.next) {
  11328. case 0:
  11329. localStorage.setItem('pdfjs.preferences', JSON.stringify(prefObj));
  11330. case 1:
  11331. case "end":
  11332. return _context.stop();
  11333. }
  11334. }
  11335. }, _callee, this);
  11336. }));
  11337. function _writeToStorage(_x) {
  11338. return _writeToStorage2.apply(this, arguments);
  11339. }
  11340. return _writeToStorage;
  11341. }()
  11342. }, {
  11343. key: "_readFromStorage",
  11344. value: function () {
  11345. var _readFromStorage2 = _asyncToGenerator(
  11346. /*#__PURE__*/
  11347. _regenerator.default.mark(function _callee2(prefObj) {
  11348. return _regenerator.default.wrap(function _callee2$(_context2) {
  11349. while (1) {
  11350. switch (_context2.prev = _context2.next) {
  11351. case 0:
  11352. return _context2.abrupt("return", JSON.parse(localStorage.getItem('pdfjs.preferences')));
  11353. case 1:
  11354. case "end":
  11355. return _context2.stop();
  11356. }
  11357. }
  11358. }, _callee2, this);
  11359. }));
  11360. function _readFromStorage(_x2) {
  11361. return _readFromStorage2.apply(this, arguments);
  11362. }
  11363. return _readFromStorage;
  11364. }()
  11365. }]);
  11366. return GenericPreferences;
  11367. }(_preferences.BasePreferences);
  11368. var GenericExternalServices = Object.create(_app.DefaultExternalServices);
  11369. GenericExternalServices.createDownloadManager = function (options) {
  11370. return new _download_manager.DownloadManager(options);
  11371. };
  11372. GenericExternalServices.createPreferences = function () {
  11373. return new GenericPreferences();
  11374. };
  11375. GenericExternalServices.createL10n = function (_ref) {
  11376. var _ref$locale = _ref.locale,
  11377. locale = _ref$locale === void 0 ? 'en-US' : _ref$locale;
  11378. return new _genericl10n.GenericL10n(locale);
  11379. };
  11380. _app.PDFViewerApplication.externalServices = GenericExternalServices;
  11381. /***/ }),
  11382. /* 38 */
  11383. /***/ (function(module, exports, __webpack_require__) {
  11384. "use strict";
  11385. Object.defineProperty(exports, "__esModule", {
  11386. value: true
  11387. });
  11388. exports.BasePreferences = void 0;
  11389. var _regenerator = _interopRequireDefault(__webpack_require__(2));
  11390. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11391. 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); } }
  11392. 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); }); }; }
  11393. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  11394. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11395. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11396. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11397. var defaultPreferences = null;
  11398. function getDefaultPreferences() {
  11399. if (!defaultPreferences) {
  11400. defaultPreferences = Promise.resolve({
  11401. "viewOnLoad": 0,
  11402. "defaultZoomValue": "",
  11403. "sidebarViewOnLoad": -1,
  11404. "cursorToolOnLoad": 0,
  11405. "enableWebGL": false,
  11406. "eventBusDispatchToDOM": false,
  11407. "pdfBugEnabled": false,
  11408. "disableRange": false,
  11409. "disableStream": false,
  11410. "disableAutoFetch": false,
  11411. "disableFontFace": false,
  11412. "textLayerMode": 1,
  11413. "useOnlyCssZoom": false,
  11414. "externalLinkTarget": 0,
  11415. "renderer": "canvas",
  11416. "renderInteractiveForms": false,
  11417. "enablePrintAutoRotate": false,
  11418. "disablePageLabels": false,
  11419. "historyUpdateUrl": false,
  11420. "scrollModeOnLoad": -1,
  11421. "spreadModeOnLoad": -1
  11422. });
  11423. }
  11424. return defaultPreferences;
  11425. }
  11426. var BasePreferences =
  11427. /*#__PURE__*/
  11428. function () {
  11429. function BasePreferences() {
  11430. var _this = this;
  11431. _classCallCheck(this, BasePreferences);
  11432. if (this.constructor === BasePreferences) {
  11433. throw new Error('Cannot initialize BasePreferences.');
  11434. }
  11435. this.prefs = null;
  11436. this._initializedPromise = getDefaultPreferences().then(function (defaults) {
  11437. Object.defineProperty(_this, 'defaults', {
  11438. value: Object.freeze(defaults),
  11439. writable: false,
  11440. enumerable: true,
  11441. configurable: false
  11442. });
  11443. _this.prefs = Object.assign(Object.create(null), defaults);
  11444. return _this._readFromStorage(defaults);
  11445. }).then(function (prefs) {
  11446. if (!prefs) {
  11447. return;
  11448. }
  11449. for (var name in prefs) {
  11450. var defaultValue = _this.defaults[name],
  11451. prefValue = prefs[name];
  11452. if (defaultValue === undefined || _typeof(prefValue) !== _typeof(defaultValue)) {
  11453. continue;
  11454. }
  11455. _this.prefs[name] = prefValue;
  11456. }
  11457. });
  11458. }
  11459. _createClass(BasePreferences, [{
  11460. key: "_writeToStorage",
  11461. value: function () {
  11462. var _writeToStorage2 = _asyncToGenerator(
  11463. /*#__PURE__*/
  11464. _regenerator.default.mark(function _callee(prefObj) {
  11465. return _regenerator.default.wrap(function _callee$(_context) {
  11466. while (1) {
  11467. switch (_context.prev = _context.next) {
  11468. case 0:
  11469. throw new Error('Not implemented: _writeToStorage');
  11470. case 1:
  11471. case "end":
  11472. return _context.stop();
  11473. }
  11474. }
  11475. }, _callee, this);
  11476. }));
  11477. function _writeToStorage(_x) {
  11478. return _writeToStorage2.apply(this, arguments);
  11479. }
  11480. return _writeToStorage;
  11481. }()
  11482. }, {
  11483. key: "_readFromStorage",
  11484. value: function () {
  11485. var _readFromStorage2 = _asyncToGenerator(
  11486. /*#__PURE__*/
  11487. _regenerator.default.mark(function _callee2(prefObj) {
  11488. return _regenerator.default.wrap(function _callee2$(_context2) {
  11489. while (1) {
  11490. switch (_context2.prev = _context2.next) {
  11491. case 0:
  11492. throw new Error('Not implemented: _readFromStorage');
  11493. case 1:
  11494. case "end":
  11495. return _context2.stop();
  11496. }
  11497. }
  11498. }, _callee2, this);
  11499. }));
  11500. function _readFromStorage(_x2) {
  11501. return _readFromStorage2.apply(this, arguments);
  11502. }
  11503. return _readFromStorage;
  11504. }()
  11505. }, {
  11506. key: "reset",
  11507. value: function () {
  11508. var _reset = _asyncToGenerator(
  11509. /*#__PURE__*/
  11510. _regenerator.default.mark(function _callee3() {
  11511. return _regenerator.default.wrap(function _callee3$(_context3) {
  11512. while (1) {
  11513. switch (_context3.prev = _context3.next) {
  11514. case 0:
  11515. _context3.next = 2;
  11516. return this._initializedPromise;
  11517. case 2:
  11518. this.prefs = Object.assign(Object.create(null), this.defaults);
  11519. return _context3.abrupt("return", this._writeToStorage(this.defaults));
  11520. case 4:
  11521. case "end":
  11522. return _context3.stop();
  11523. }
  11524. }
  11525. }, _callee3, this);
  11526. }));
  11527. function reset() {
  11528. return _reset.apply(this, arguments);
  11529. }
  11530. return reset;
  11531. }()
  11532. }, {
  11533. key: "set",
  11534. value: function () {
  11535. var _set = _asyncToGenerator(
  11536. /*#__PURE__*/
  11537. _regenerator.default.mark(function _callee4(name, value) {
  11538. var defaultValue, valueType, defaultType;
  11539. return _regenerator.default.wrap(function _callee4$(_context4) {
  11540. while (1) {
  11541. switch (_context4.prev = _context4.next) {
  11542. case 0:
  11543. _context4.next = 2;
  11544. return this._initializedPromise;
  11545. case 2:
  11546. defaultValue = this.defaults[name];
  11547. if (!(defaultValue === undefined)) {
  11548. _context4.next = 7;
  11549. break;
  11550. }
  11551. throw new Error("Set preference: \"".concat(name, "\" is undefined."));
  11552. case 7:
  11553. if (!(value === undefined)) {
  11554. _context4.next = 9;
  11555. break;
  11556. }
  11557. throw new Error('Set preference: no value is specified.');
  11558. case 9:
  11559. valueType = _typeof(value);
  11560. defaultType = _typeof(defaultValue);
  11561. if (!(valueType !== defaultType)) {
  11562. _context4.next = 19;
  11563. break;
  11564. }
  11565. if (!(valueType === 'number' && defaultType === 'string')) {
  11566. _context4.next = 16;
  11567. break;
  11568. }
  11569. value = value.toString();
  11570. _context4.next = 17;
  11571. break;
  11572. case 16:
  11573. throw new Error("Set preference: \"".concat(value, "\" is a ").concat(valueType, ", ") + "expected a ".concat(defaultType, "."));
  11574. case 17:
  11575. _context4.next = 21;
  11576. break;
  11577. case 19:
  11578. if (!(valueType === 'number' && !Number.isInteger(value))) {
  11579. _context4.next = 21;
  11580. break;
  11581. }
  11582. throw new Error("Set preference: \"".concat(value, "\" must be an integer."));
  11583. case 21:
  11584. this.prefs[name] = value;
  11585. return _context4.abrupt("return", this._writeToStorage(this.prefs));
  11586. case 23:
  11587. case "end":
  11588. return _context4.stop();
  11589. }
  11590. }
  11591. }, _callee4, this);
  11592. }));
  11593. function set(_x3, _x4) {
  11594. return _set.apply(this, arguments);
  11595. }
  11596. return set;
  11597. }()
  11598. }, {
  11599. key: "get",
  11600. value: function () {
  11601. var _get = _asyncToGenerator(
  11602. /*#__PURE__*/
  11603. _regenerator.default.mark(function _callee5(name) {
  11604. var defaultValue, prefValue;
  11605. return _regenerator.default.wrap(function _callee5$(_context5) {
  11606. while (1) {
  11607. switch (_context5.prev = _context5.next) {
  11608. case 0:
  11609. _context5.next = 2;
  11610. return this._initializedPromise;
  11611. case 2:
  11612. defaultValue = this.defaults[name];
  11613. if (!(defaultValue === undefined)) {
  11614. _context5.next = 7;
  11615. break;
  11616. }
  11617. throw new Error("Get preference: \"".concat(name, "\" is undefined."));
  11618. case 7:
  11619. prefValue = this.prefs[name];
  11620. if (!(prefValue !== undefined)) {
  11621. _context5.next = 10;
  11622. break;
  11623. }
  11624. return _context5.abrupt("return", prefValue);
  11625. case 10:
  11626. return _context5.abrupt("return", defaultValue);
  11627. case 11:
  11628. case "end":
  11629. return _context5.stop();
  11630. }
  11631. }
  11632. }, _callee5, this);
  11633. }));
  11634. function get(_x5) {
  11635. return _get.apply(this, arguments);
  11636. }
  11637. return get;
  11638. }()
  11639. }, {
  11640. key: "getAll",
  11641. value: function () {
  11642. var _getAll = _asyncToGenerator(
  11643. /*#__PURE__*/
  11644. _regenerator.default.mark(function _callee6() {
  11645. return _regenerator.default.wrap(function _callee6$(_context6) {
  11646. while (1) {
  11647. switch (_context6.prev = _context6.next) {
  11648. case 0:
  11649. _context6.next = 2;
  11650. return this._initializedPromise;
  11651. case 2:
  11652. return _context6.abrupt("return", Object.assign(Object.create(null), this.defaults, this.prefs));
  11653. case 3:
  11654. case "end":
  11655. return _context6.stop();
  11656. }
  11657. }
  11658. }, _callee6, this);
  11659. }));
  11660. function getAll() {
  11661. return _getAll.apply(this, arguments);
  11662. }
  11663. return getAll;
  11664. }()
  11665. }]);
  11666. return BasePreferences;
  11667. }();
  11668. exports.BasePreferences = BasePreferences;
  11669. /***/ }),
  11670. /* 39 */
  11671. /***/ (function(module, exports, __webpack_require__) {
  11672. "use strict";
  11673. Object.defineProperty(exports, "__esModule", {
  11674. value: true
  11675. });
  11676. exports.DownloadManager = void 0;
  11677. var _pdfjsLib = __webpack_require__(7);
  11678. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11679. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11680. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11681. ;
  11682. var DISABLE_CREATE_OBJECT_URL = _pdfjsLib.apiCompatibilityParams.disableCreateObjectURL || false;
  11683. function _download(blobUrl, filename) {
  11684. var a = document.createElement('a');
  11685. if (!a.click) {
  11686. throw new Error('DownloadManager: "a.click()" is not supported.');
  11687. }
  11688. a.href = blobUrl;
  11689. a.target = '_parent';
  11690. if ('download' in a) {
  11691. a.download = filename;
  11692. }
  11693. (document.body || document.documentElement).appendChild(a);
  11694. a.click();
  11695. a.remove();
  11696. }
  11697. var DownloadManager =
  11698. /*#__PURE__*/
  11699. function () {
  11700. function DownloadManager(_ref) {
  11701. var _ref$disableCreateObj = _ref.disableCreateObjectURL,
  11702. disableCreateObjectURL = _ref$disableCreateObj === void 0 ? DISABLE_CREATE_OBJECT_URL : _ref$disableCreateObj;
  11703. _classCallCheck(this, DownloadManager);
  11704. this.disableCreateObjectURL = disableCreateObjectURL;
  11705. }
  11706. _createClass(DownloadManager, [{
  11707. key: "downloadUrl",
  11708. value: function downloadUrl(url, filename) {
  11709. if (!(0, _pdfjsLib.createValidAbsoluteUrl)(url, 'http://example.com')) {
  11710. return;
  11711. }
  11712. _download(url + '#pdfjs.action=download', filename);
  11713. }
  11714. }, {
  11715. key: "downloadData",
  11716. value: function downloadData(data, filename, contentType) {
  11717. if (navigator.msSaveBlob) {
  11718. return navigator.msSaveBlob(new Blob([data], {
  11719. type: contentType
  11720. }), filename);
  11721. }
  11722. var blobUrl = (0, _pdfjsLib.createObjectURL)(data, contentType, this.disableCreateObjectURL);
  11723. _download(blobUrl, filename);
  11724. }
  11725. }, {
  11726. key: "download",
  11727. value: function download(blob, url, filename) {
  11728. if (navigator.msSaveBlob) {
  11729. if (!navigator.msSaveBlob(blob, filename)) {
  11730. this.downloadUrl(url, filename);
  11731. }
  11732. return;
  11733. }
  11734. if (this.disableCreateObjectURL) {
  11735. this.downloadUrl(url, filename);
  11736. return;
  11737. }
  11738. var blobUrl = _pdfjsLib.URL.createObjectURL(blob);
  11739. _download(blobUrl, filename);
  11740. }
  11741. }]);
  11742. return DownloadManager;
  11743. }();
  11744. exports.DownloadManager = DownloadManager;
  11745. /***/ }),
  11746. /* 40 */
  11747. /***/ (function(module, exports, __webpack_require__) {
  11748. "use strict";
  11749. Object.defineProperty(exports, "__esModule", {
  11750. value: true
  11751. });
  11752. exports.GenericL10n = void 0;
  11753. var _regenerator = _interopRequireDefault(__webpack_require__(2));
  11754. __webpack_require__(41);
  11755. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11756. 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); } }
  11757. 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); }); }; }
  11758. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11759. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  11760. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  11761. var webL10n = document.webL10n;
  11762. var GenericL10n =
  11763. /*#__PURE__*/
  11764. function () {
  11765. function GenericL10n(lang) {
  11766. _classCallCheck(this, GenericL10n);
  11767. this._lang = lang;
  11768. this._ready = new Promise(function (resolve, reject) {
  11769. webL10n.setLanguage(lang, function () {
  11770. resolve(webL10n);
  11771. });
  11772. });
  11773. }
  11774. _createClass(GenericL10n, [{
  11775. key: "getLanguage",
  11776. value: function () {
  11777. var _getLanguage = _asyncToGenerator(
  11778. /*#__PURE__*/
  11779. _regenerator.default.mark(function _callee() {
  11780. var l10n;
  11781. return _regenerator.default.wrap(function _callee$(_context) {
  11782. while (1) {
  11783. switch (_context.prev = _context.next) {
  11784. case 0:
  11785. _context.next = 2;
  11786. return this._ready;
  11787. case 2:
  11788. l10n = _context.sent;
  11789. return _context.abrupt("return", l10n.getLanguage());
  11790. case 4:
  11791. case "end":
  11792. return _context.stop();
  11793. }
  11794. }
  11795. }, _callee, this);
  11796. }));
  11797. function getLanguage() {
  11798. return _getLanguage.apply(this, arguments);
  11799. }
  11800. return getLanguage;
  11801. }()
  11802. }, {
  11803. key: "getDirection",
  11804. value: function () {
  11805. var _getDirection = _asyncToGenerator(
  11806. /*#__PURE__*/
  11807. _regenerator.default.mark(function _callee2() {
  11808. var l10n;
  11809. return _regenerator.default.wrap(function _callee2$(_context2) {
  11810. while (1) {
  11811. switch (_context2.prev = _context2.next) {
  11812. case 0:
  11813. _context2.next = 2;
  11814. return this._ready;
  11815. case 2:
  11816. l10n = _context2.sent;
  11817. return _context2.abrupt("return", l10n.getDirection());
  11818. case 4:
  11819. case "end":
  11820. return _context2.stop();
  11821. }
  11822. }
  11823. }, _callee2, this);
  11824. }));
  11825. function getDirection() {
  11826. return _getDirection.apply(this, arguments);
  11827. }
  11828. return getDirection;
  11829. }()
  11830. }, {
  11831. key: "get",
  11832. value: function () {
  11833. var _get = _asyncToGenerator(
  11834. /*#__PURE__*/
  11835. _regenerator.default.mark(function _callee3(property, args, fallback) {
  11836. var l10n;
  11837. return _regenerator.default.wrap(function _callee3$(_context3) {
  11838. while (1) {
  11839. switch (_context3.prev = _context3.next) {
  11840. case 0:
  11841. _context3.next = 2;
  11842. return this._ready;
  11843. case 2:
  11844. l10n = _context3.sent;
  11845. return _context3.abrupt("return", l10n.get(property, args, fallback));
  11846. case 4:
  11847. case "end":
  11848. return _context3.stop();
  11849. }
  11850. }
  11851. }, _callee3, this);
  11852. }));
  11853. function get(_x, _x2, _x3) {
  11854. return _get.apply(this, arguments);
  11855. }
  11856. return get;
  11857. }()
  11858. }, {
  11859. key: "translate",
  11860. value: function () {
  11861. var _translate = _asyncToGenerator(
  11862. /*#__PURE__*/
  11863. _regenerator.default.mark(function _callee4(element) {
  11864. var l10n;
  11865. return _regenerator.default.wrap(function _callee4$(_context4) {
  11866. while (1) {
  11867. switch (_context4.prev = _context4.next) {
  11868. case 0:
  11869. _context4.next = 2;
  11870. return this._ready;
  11871. case 2:
  11872. l10n = _context4.sent;
  11873. return _context4.abrupt("return", l10n.translate(element));
  11874. case 4:
  11875. case "end":
  11876. return _context4.stop();
  11877. }
  11878. }
  11879. }, _callee4, this);
  11880. }));
  11881. function translate(_x4) {
  11882. return _translate.apply(this, arguments);
  11883. }
  11884. return translate;
  11885. }()
  11886. }]);
  11887. return GenericL10n;
  11888. }();
  11889. exports.GenericL10n = GenericL10n;
  11890. /***/ }),
  11891. /* 41 */
  11892. /***/ (function(module, exports, __webpack_require__) {
  11893. "use strict";
  11894. document.webL10n = function (window, document, undefined) {
  11895. var gL10nData = {};
  11896. var gTextData = '';
  11897. var gTextProp = 'textContent';
  11898. var gLanguage = '';
  11899. var gMacros = {};
  11900. var gReadyState = 'loading';
  11901. var gAsyncResourceLoading = true;
  11902. function getL10nResourceLinks() {
  11903. return document.querySelectorAll('link[type="application/l10n"]');
  11904. }
  11905. function getL10nDictionary() {
  11906. var script = document.querySelector('script[type="application/l10n"]');
  11907. return script ? JSON.parse(script.innerHTML) : null;
  11908. }
  11909. function getTranslatableChildren(element) {
  11910. return element ? element.querySelectorAll('*[data-l10n-id]') : [];
  11911. }
  11912. function getL10nAttributes(element) {
  11913. if (!element) return {};
  11914. var l10nId = element.getAttribute('data-l10n-id');
  11915. var l10nArgs = element.getAttribute('data-l10n-args');
  11916. var args = {};
  11917. if (l10nArgs) {
  11918. try {
  11919. args = JSON.parse(l10nArgs);
  11920. } catch (e) {
  11921. console.warn('could not parse arguments for #' + l10nId);
  11922. }
  11923. }
  11924. return {
  11925. id: l10nId,
  11926. args: args
  11927. };
  11928. }
  11929. function fireL10nReadyEvent(lang) {
  11930. var evtObject = document.createEvent('Event');
  11931. evtObject.initEvent('localized', true, false);
  11932. evtObject.language = lang;
  11933. document.dispatchEvent(evtObject);
  11934. }
  11935. function xhrLoadText(url, onSuccess, onFailure) {
  11936. onSuccess = onSuccess || function _onSuccess(data) {};
  11937. onFailure = onFailure || function _onFailure() {};
  11938. var xhr = new XMLHttpRequest();
  11939. xhr.open('GET', url, gAsyncResourceLoading);
  11940. if (xhr.overrideMimeType) {
  11941. xhr.overrideMimeType('text/plain; charset=utf-8');
  11942. }
  11943. xhr.onreadystatechange = function () {
  11944. if (xhr.readyState == 4) {
  11945. if (xhr.status == 200 || xhr.status === 0) {
  11946. onSuccess(xhr.responseText);
  11947. } else {
  11948. onFailure();
  11949. }
  11950. }
  11951. };
  11952. xhr.onerror = onFailure;
  11953. xhr.ontimeout = onFailure;
  11954. try {
  11955. xhr.send(null);
  11956. } catch (e) {
  11957. onFailure();
  11958. }
  11959. }
  11960. function parseResource(href, lang, successCallback, failureCallback) {
  11961. var baseURL = href.replace(/[^\/]*$/, '') || './';
  11962. function evalString(text) {
  11963. if (text.lastIndexOf('\\') < 0) return text;
  11964. return text.replace(/\\\\/g, '\\').replace(/\\n/g, '\n').replace(/\\r/g, '\r').replace(/\\t/g, '\t').replace(/\\b/g, '\b').replace(/\\f/g, '\f').replace(/\\{/g, '{').replace(/\\}/g, '}').replace(/\\"/g, '"').replace(/\\'/g, "'");
  11965. }
  11966. function parseProperties(text, parsedPropertiesCallback) {
  11967. var dictionary = {};
  11968. var reBlank = /^\s*|\s*$/;
  11969. var reComment = /^\s*#|^\s*$/;
  11970. var reSection = /^\s*\[(.*)\]\s*$/;
  11971. var reImport = /^\s*@import\s+url\((.*)\)\s*$/i;
  11972. var reSplit = /^([^=\s]*)\s*=\s*(.+)$/;
  11973. function parseRawLines(rawText, extendedSyntax, parsedRawLinesCallback) {
  11974. var entries = rawText.replace(reBlank, '').split(/[\r\n]+/);
  11975. var currentLang = '*';
  11976. var genericLang = lang.split('-', 1)[0];
  11977. var skipLang = false;
  11978. var match = '';
  11979. function nextEntry() {
  11980. while (true) {
  11981. if (!entries.length) {
  11982. parsedRawLinesCallback();
  11983. return;
  11984. }
  11985. var line = entries.shift();
  11986. if (reComment.test(line)) continue;
  11987. if (extendedSyntax) {
  11988. match = reSection.exec(line);
  11989. if (match) {
  11990. currentLang = match[1].toLowerCase();
  11991. skipLang = currentLang !== '*' && currentLang !== lang && currentLang !== genericLang;
  11992. continue;
  11993. } else if (skipLang) {
  11994. continue;
  11995. }
  11996. match = reImport.exec(line);
  11997. if (match) {
  11998. loadImport(baseURL + match[1], nextEntry);
  11999. return;
  12000. }
  12001. }
  12002. var tmp = line.match(reSplit);
  12003. if (tmp && tmp.length == 3) {
  12004. dictionary[tmp[1]] = evalString(tmp[2]);
  12005. }
  12006. }
  12007. }
  12008. nextEntry();
  12009. }
  12010. function loadImport(url, callback) {
  12011. xhrLoadText(url, function (content) {
  12012. parseRawLines(content, false, callback);
  12013. }, function () {
  12014. console.warn(url + ' not found.');
  12015. callback();
  12016. });
  12017. }
  12018. parseRawLines(text, true, function () {
  12019. parsedPropertiesCallback(dictionary);
  12020. });
  12021. }
  12022. xhrLoadText(href, function (response) {
  12023. gTextData += response;
  12024. parseProperties(response, function (data) {
  12025. for (var key in data) {
  12026. var id,
  12027. prop,
  12028. index = key.lastIndexOf('.');
  12029. if (index > 0) {
  12030. id = key.substring(0, index);
  12031. prop = key.substring(index + 1);
  12032. } else {
  12033. id = key;
  12034. prop = gTextProp;
  12035. }
  12036. if (!gL10nData[id]) {
  12037. gL10nData[id] = {};
  12038. }
  12039. gL10nData[id][prop] = data[key];
  12040. }
  12041. if (successCallback) {
  12042. successCallback();
  12043. }
  12044. });
  12045. }, failureCallback);
  12046. }
  12047. function loadLocale(lang, callback) {
  12048. if (lang) {
  12049. lang = lang.toLowerCase();
  12050. }
  12051. callback = callback || function _callback() {};
  12052. clear();
  12053. gLanguage = lang;
  12054. var langLinks = getL10nResourceLinks();
  12055. var langCount = langLinks.length;
  12056. if (langCount === 0) {
  12057. var dict = getL10nDictionary();
  12058. if (dict && dict.locales && dict.default_locale) {
  12059. console.log('using the embedded JSON directory, early way out');
  12060. gL10nData = dict.locales[lang];
  12061. if (!gL10nData) {
  12062. var defaultLocale = dict.default_locale.toLowerCase();
  12063. for (var anyCaseLang in dict.locales) {
  12064. anyCaseLang = anyCaseLang.toLowerCase();
  12065. if (anyCaseLang === lang) {
  12066. gL10nData = dict.locales[lang];
  12067. break;
  12068. } else if (anyCaseLang === defaultLocale) {
  12069. gL10nData = dict.locales[defaultLocale];
  12070. }
  12071. }
  12072. }
  12073. callback();
  12074. } else {
  12075. console.log('no resource to load, early way out');
  12076. }
  12077. fireL10nReadyEvent(lang);
  12078. gReadyState = 'complete';
  12079. return;
  12080. }
  12081. var onResourceLoaded = null;
  12082. var gResourceCount = 0;
  12083. onResourceLoaded = function onResourceLoaded() {
  12084. gResourceCount++;
  12085. if (gResourceCount >= langCount) {
  12086. callback();
  12087. fireL10nReadyEvent(lang);
  12088. gReadyState = 'complete';
  12089. }
  12090. };
  12091. function L10nResourceLink(link) {
  12092. var href = link.href;
  12093. this.load = function (lang, callback) {
  12094. parseResource(href, lang, callback, function () {
  12095. console.warn(href + ' not found.');
  12096. console.warn('"' + lang + '" resource not found');
  12097. gLanguage = '';
  12098. callback();
  12099. });
  12100. };
  12101. }
  12102. for (var i = 0; i < langCount; i++) {
  12103. var resource = new L10nResourceLink(langLinks[i]);
  12104. resource.load(lang, onResourceLoaded);
  12105. }
  12106. }
  12107. function clear() {
  12108. gL10nData = {};
  12109. gTextData = '';
  12110. gLanguage = '';
  12111. }
  12112. function getPluralRules(lang) {
  12113. var locales2rules = {
  12114. 'af': 3,
  12115. 'ak': 4,
  12116. 'am': 4,
  12117. 'ar': 1,
  12118. 'asa': 3,
  12119. 'az': 0,
  12120. 'be': 11,
  12121. 'bem': 3,
  12122. 'bez': 3,
  12123. 'bg': 3,
  12124. 'bh': 4,
  12125. 'bm': 0,
  12126. 'bn': 3,
  12127. 'bo': 0,
  12128. 'br': 20,
  12129. 'brx': 3,
  12130. 'bs': 11,
  12131. 'ca': 3,
  12132. 'cgg': 3,
  12133. 'chr': 3,
  12134. 'cs': 12,
  12135. 'cy': 17,
  12136. 'da': 3,
  12137. 'de': 3,
  12138. 'dv': 3,
  12139. 'dz': 0,
  12140. 'ee': 3,
  12141. 'el': 3,
  12142. 'en': 3,
  12143. 'eo': 3,
  12144. 'es': 3,
  12145. 'et': 3,
  12146. 'eu': 3,
  12147. 'fa': 0,
  12148. 'ff': 5,
  12149. 'fi': 3,
  12150. 'fil': 4,
  12151. 'fo': 3,
  12152. 'fr': 5,
  12153. 'fur': 3,
  12154. 'fy': 3,
  12155. 'ga': 8,
  12156. 'gd': 24,
  12157. 'gl': 3,
  12158. 'gsw': 3,
  12159. 'gu': 3,
  12160. 'guw': 4,
  12161. 'gv': 23,
  12162. 'ha': 3,
  12163. 'haw': 3,
  12164. 'he': 2,
  12165. 'hi': 4,
  12166. 'hr': 11,
  12167. 'hu': 0,
  12168. 'id': 0,
  12169. 'ig': 0,
  12170. 'ii': 0,
  12171. 'is': 3,
  12172. 'it': 3,
  12173. 'iu': 7,
  12174. 'ja': 0,
  12175. 'jmc': 3,
  12176. 'jv': 0,
  12177. 'ka': 0,
  12178. 'kab': 5,
  12179. 'kaj': 3,
  12180. 'kcg': 3,
  12181. 'kde': 0,
  12182. 'kea': 0,
  12183. 'kk': 3,
  12184. 'kl': 3,
  12185. 'km': 0,
  12186. 'kn': 0,
  12187. 'ko': 0,
  12188. 'ksb': 3,
  12189. 'ksh': 21,
  12190. 'ku': 3,
  12191. 'kw': 7,
  12192. 'lag': 18,
  12193. 'lb': 3,
  12194. 'lg': 3,
  12195. 'ln': 4,
  12196. 'lo': 0,
  12197. 'lt': 10,
  12198. 'lv': 6,
  12199. 'mas': 3,
  12200. 'mg': 4,
  12201. 'mk': 16,
  12202. 'ml': 3,
  12203. 'mn': 3,
  12204. 'mo': 9,
  12205. 'mr': 3,
  12206. 'ms': 0,
  12207. 'mt': 15,
  12208. 'my': 0,
  12209. 'nah': 3,
  12210. 'naq': 7,
  12211. 'nb': 3,
  12212. 'nd': 3,
  12213. 'ne': 3,
  12214. 'nl': 3,
  12215. 'nn': 3,
  12216. 'no': 3,
  12217. 'nr': 3,
  12218. 'nso': 4,
  12219. 'ny': 3,
  12220. 'nyn': 3,
  12221. 'om': 3,
  12222. 'or': 3,
  12223. 'pa': 3,
  12224. 'pap': 3,
  12225. 'pl': 13,
  12226. 'ps': 3,
  12227. 'pt': 3,
  12228. 'rm': 3,
  12229. 'ro': 9,
  12230. 'rof': 3,
  12231. 'ru': 11,
  12232. 'rwk': 3,
  12233. 'sah': 0,
  12234. 'saq': 3,
  12235. 'se': 7,
  12236. 'seh': 3,
  12237. 'ses': 0,
  12238. 'sg': 0,
  12239. 'sh': 11,
  12240. 'shi': 19,
  12241. 'sk': 12,
  12242. 'sl': 14,
  12243. 'sma': 7,
  12244. 'smi': 7,
  12245. 'smj': 7,
  12246. 'smn': 7,
  12247. 'sms': 7,
  12248. 'sn': 3,
  12249. 'so': 3,
  12250. 'sq': 3,
  12251. 'sr': 11,
  12252. 'ss': 3,
  12253. 'ssy': 3,
  12254. 'st': 3,
  12255. 'sv': 3,
  12256. 'sw': 3,
  12257. 'syr': 3,
  12258. 'ta': 3,
  12259. 'te': 3,
  12260. 'teo': 3,
  12261. 'th': 0,
  12262. 'ti': 4,
  12263. 'tig': 3,
  12264. 'tk': 3,
  12265. 'tl': 4,
  12266. 'tn': 3,
  12267. 'to': 0,
  12268. 'tr': 0,
  12269. 'ts': 3,
  12270. 'tzm': 22,
  12271. 'uk': 11,
  12272. 'ur': 3,
  12273. 've': 3,
  12274. 'vi': 0,
  12275. 'vun': 3,
  12276. 'wa': 4,
  12277. 'wae': 3,
  12278. 'wo': 0,
  12279. 'xh': 3,
  12280. 'xog': 3,
  12281. 'yo': 0,
  12282. 'zh': 0,
  12283. 'zu': 3
  12284. };
  12285. function isIn(n, list) {
  12286. return list.indexOf(n) !== -1;
  12287. }
  12288. function isBetween(n, start, end) {
  12289. return start <= n && n <= end;
  12290. }
  12291. var pluralRules = {
  12292. '0': function _(n) {
  12293. return 'other';
  12294. },
  12295. '1': function _(n) {
  12296. if (isBetween(n % 100, 3, 10)) return 'few';
  12297. if (n === 0) return 'zero';
  12298. if (isBetween(n % 100, 11, 99)) return 'many';
  12299. if (n == 2) return 'two';
  12300. if (n == 1) return 'one';
  12301. return 'other';
  12302. },
  12303. '2': function _(n) {
  12304. if (n !== 0 && n % 10 === 0) return 'many';
  12305. if (n == 2) return 'two';
  12306. if (n == 1) return 'one';
  12307. return 'other';
  12308. },
  12309. '3': function _(n) {
  12310. if (n == 1) return 'one';
  12311. return 'other';
  12312. },
  12313. '4': function _(n) {
  12314. if (isBetween(n, 0, 1)) return 'one';
  12315. return 'other';
  12316. },
  12317. '5': function _(n) {
  12318. if (isBetween(n, 0, 2) && n != 2) return 'one';
  12319. return 'other';
  12320. },
  12321. '6': function _(n) {
  12322. if (n === 0) return 'zero';
  12323. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12324. return 'other';
  12325. },
  12326. '7': function _(n) {
  12327. if (n == 2) return 'two';
  12328. if (n == 1) return 'one';
  12329. return 'other';
  12330. },
  12331. '8': function _(n) {
  12332. if (isBetween(n, 3, 6)) return 'few';
  12333. if (isBetween(n, 7, 10)) return 'many';
  12334. if (n == 2) return 'two';
  12335. if (n == 1) return 'one';
  12336. return 'other';
  12337. },
  12338. '9': function _(n) {
  12339. if (n === 0 || n != 1 && isBetween(n % 100, 1, 19)) return 'few';
  12340. if (n == 1) return 'one';
  12341. return 'other';
  12342. },
  12343. '10': function _(n) {
  12344. if (isBetween(n % 10, 2, 9) && !isBetween(n % 100, 11, 19)) return 'few';
  12345. if (n % 10 == 1 && !isBetween(n % 100, 11, 19)) return 'one';
  12346. return 'other';
  12347. },
  12348. '11': function _(n) {
  12349. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12350. if (n % 10 === 0 || isBetween(n % 10, 5, 9) || isBetween(n % 100, 11, 14)) return 'many';
  12351. if (n % 10 == 1 && n % 100 != 11) return 'one';
  12352. return 'other';
  12353. },
  12354. '12': function _(n) {
  12355. if (isBetween(n, 2, 4)) return 'few';
  12356. if (n == 1) return 'one';
  12357. return 'other';
  12358. },
  12359. '13': function _(n) {
  12360. if (isBetween(n % 10, 2, 4) && !isBetween(n % 100, 12, 14)) return 'few';
  12361. if (n != 1 && isBetween(n % 10, 0, 1) || isBetween(n % 10, 5, 9) || isBetween(n % 100, 12, 14)) return 'many';
  12362. if (n == 1) return 'one';
  12363. return 'other';
  12364. },
  12365. '14': function _(n) {
  12366. if (isBetween(n % 100, 3, 4)) return 'few';
  12367. if (n % 100 == 2) return 'two';
  12368. if (n % 100 == 1) return 'one';
  12369. return 'other';
  12370. },
  12371. '15': function _(n) {
  12372. if (n === 0 || isBetween(n % 100, 2, 10)) return 'few';
  12373. if (isBetween(n % 100, 11, 19)) return 'many';
  12374. if (n == 1) return 'one';
  12375. return 'other';
  12376. },
  12377. '16': function _(n) {
  12378. if (n % 10 == 1 && n != 11) return 'one';
  12379. return 'other';
  12380. },
  12381. '17': function _(n) {
  12382. if (n == 3) return 'few';
  12383. if (n === 0) return 'zero';
  12384. if (n == 6) return 'many';
  12385. if (n == 2) return 'two';
  12386. if (n == 1) return 'one';
  12387. return 'other';
  12388. },
  12389. '18': function _(n) {
  12390. if (n === 0) return 'zero';
  12391. if (isBetween(n, 0, 2) && n !== 0 && n != 2) return 'one';
  12392. return 'other';
  12393. },
  12394. '19': function _(n) {
  12395. if (isBetween(n, 2, 10)) return 'few';
  12396. if (isBetween(n, 0, 1)) return 'one';
  12397. return 'other';
  12398. },
  12399. '20': function _(n) {
  12400. if ((isBetween(n % 10, 3, 4) || n % 10 == 9) && !(isBetween(n % 100, 10, 19) || isBetween(n % 100, 70, 79) || isBetween(n % 100, 90, 99))) return 'few';
  12401. if (n % 1000000 === 0 && n !== 0) return 'many';
  12402. if (n % 10 == 2 && !isIn(n % 100, [12, 72, 92])) return 'two';
  12403. if (n % 10 == 1 && !isIn(n % 100, [11, 71, 91])) return 'one';
  12404. return 'other';
  12405. },
  12406. '21': function _(n) {
  12407. if (n === 0) return 'zero';
  12408. if (n == 1) return 'one';
  12409. return 'other';
  12410. },
  12411. '22': function _(n) {
  12412. if (isBetween(n, 0, 1) || isBetween(n, 11, 99)) return 'one';
  12413. return 'other';
  12414. },
  12415. '23': function _(n) {
  12416. if (isBetween(n % 10, 1, 2) || n % 20 === 0) return 'one';
  12417. return 'other';
  12418. },
  12419. '24': function _(n) {
  12420. if (isBetween(n, 3, 10) || isBetween(n, 13, 19)) return 'few';
  12421. if (isIn(n, [2, 12])) return 'two';
  12422. if (isIn(n, [1, 11])) return 'one';
  12423. return 'other';
  12424. }
  12425. };
  12426. var index = locales2rules[lang.replace(/-.*$/, '')];
  12427. if (!(index in pluralRules)) {
  12428. console.warn('plural form unknown for [' + lang + ']');
  12429. return function () {
  12430. return 'other';
  12431. };
  12432. }
  12433. return pluralRules[index];
  12434. }
  12435. gMacros.plural = function (str, param, key, prop) {
  12436. var n = parseFloat(param);
  12437. if (isNaN(n)) return str;
  12438. if (prop != gTextProp) return str;
  12439. if (!gMacros._pluralRules) {
  12440. gMacros._pluralRules = getPluralRules(gLanguage);
  12441. }
  12442. var index = '[' + gMacros._pluralRules(n) + ']';
  12443. if (n === 0 && key + '[zero]' in gL10nData) {
  12444. str = gL10nData[key + '[zero]'][prop];
  12445. } else if (n == 1 && key + '[one]' in gL10nData) {
  12446. str = gL10nData[key + '[one]'][prop];
  12447. } else if (n == 2 && key + '[two]' in gL10nData) {
  12448. str = gL10nData[key + '[two]'][prop];
  12449. } else if (key + index in gL10nData) {
  12450. str = gL10nData[key + index][prop];
  12451. } else if (key + '[other]' in gL10nData) {
  12452. str = gL10nData[key + '[other]'][prop];
  12453. }
  12454. return str;
  12455. };
  12456. function getL10nData(key, args, fallback) {
  12457. var data = gL10nData[key];
  12458. if (!data) {
  12459. console.warn('#' + key + ' is undefined.');
  12460. if (!fallback) {
  12461. return null;
  12462. }
  12463. data = fallback;
  12464. }
  12465. var rv = {};
  12466. for (var prop in data) {
  12467. var str = data[prop];
  12468. str = substIndexes(str, args, key, prop);
  12469. str = substArguments(str, args, key);
  12470. rv[prop] = str;
  12471. }
  12472. return rv;
  12473. }
  12474. function substIndexes(str, args, key, prop) {
  12475. var reIndex = /\{\[\s*([a-zA-Z]+)\(([a-zA-Z]+)\)\s*\]\}/;
  12476. var reMatch = reIndex.exec(str);
  12477. if (!reMatch || !reMatch.length) return str;
  12478. var macroName = reMatch[1];
  12479. var paramName = reMatch[2];
  12480. var param;
  12481. if (args && paramName in args) {
  12482. param = args[paramName];
  12483. } else if (paramName in gL10nData) {
  12484. param = gL10nData[paramName];
  12485. }
  12486. if (macroName in gMacros) {
  12487. var macro = gMacros[macroName];
  12488. str = macro(str, param, key, prop);
  12489. }
  12490. return str;
  12491. }
  12492. function substArguments(str, args, key) {
  12493. var reArgs = /\{\{\s*(.+?)\s*\}\}/g;
  12494. return str.replace(reArgs, function (matched_text, arg) {
  12495. if (args && arg in args) {
  12496. return args[arg];
  12497. }
  12498. if (arg in gL10nData) {
  12499. return gL10nData[arg];
  12500. }
  12501. console.log('argument {{' + arg + '}} for #' + key + ' is undefined.');
  12502. return matched_text;
  12503. });
  12504. }
  12505. function translateElement(element) {
  12506. var l10n = getL10nAttributes(element);
  12507. if (!l10n.id) return;
  12508. var data = getL10nData(l10n.id, l10n.args);
  12509. if (!data) {
  12510. console.warn('#' + l10n.id + ' is undefined.');
  12511. return;
  12512. }
  12513. if (data[gTextProp]) {
  12514. if (getChildElementCount(element) === 0) {
  12515. element[gTextProp] = data[gTextProp];
  12516. } else {
  12517. var children = element.childNodes;
  12518. var found = false;
  12519. for (var i = 0, l = children.length; i < l; i++) {
  12520. if (children[i].nodeType === 3 && /\S/.test(children[i].nodeValue)) {
  12521. if (found) {
  12522. children[i].nodeValue = '';
  12523. } else {
  12524. children[i].nodeValue = data[gTextProp];
  12525. found = true;
  12526. }
  12527. }
  12528. }
  12529. if (!found) {
  12530. var textNode = document.createTextNode(data[gTextProp]);
  12531. element.insertBefore(textNode, element.firstChild);
  12532. }
  12533. }
  12534. delete data[gTextProp];
  12535. }
  12536. for (var k in data) {
  12537. element[k] = data[k];
  12538. }
  12539. }
  12540. function getChildElementCount(element) {
  12541. if (element.children) {
  12542. return element.children.length;
  12543. }
  12544. if (typeof element.childElementCount !== 'undefined') {
  12545. return element.childElementCount;
  12546. }
  12547. var count = 0;
  12548. for (var i = 0; i < element.childNodes.length; i++) {
  12549. count += element.nodeType === 1 ? 1 : 0;
  12550. }
  12551. return count;
  12552. }
  12553. function translateFragment(element) {
  12554. element = element || document.documentElement;
  12555. var children = getTranslatableChildren(element);
  12556. var elementCount = children.length;
  12557. for (var i = 0; i < elementCount; i++) {
  12558. translateElement(children[i]);
  12559. }
  12560. translateElement(element);
  12561. }
  12562. return {
  12563. get: function get(key, args, fallbackString) {
  12564. var index = key.lastIndexOf('.');
  12565. var prop = gTextProp;
  12566. if (index > 0) {
  12567. prop = key.substring(index + 1);
  12568. key = key.substring(0, index);
  12569. }
  12570. var fallback;
  12571. if (fallbackString) {
  12572. fallback = {};
  12573. fallback[prop] = fallbackString;
  12574. }
  12575. var data = getL10nData(key, args, fallback);
  12576. if (data && prop in data) {
  12577. return data[prop];
  12578. }
  12579. return '{{' + key + '}}';
  12580. },
  12581. getData: function getData() {
  12582. return gL10nData;
  12583. },
  12584. getText: function getText() {
  12585. return gTextData;
  12586. },
  12587. getLanguage: function getLanguage() {
  12588. return gLanguage;
  12589. },
  12590. setLanguage: function setLanguage(lang, callback) {
  12591. loadLocale(lang, function () {
  12592. if (callback) callback();
  12593. });
  12594. },
  12595. getDirection: function getDirection() {
  12596. var rtlList = ['ar', 'he', 'fa', 'ps', 'ur'];
  12597. var shortCode = gLanguage.split('-', 1)[0];
  12598. return rtlList.indexOf(shortCode) >= 0 ? 'rtl' : 'ltr';
  12599. },
  12600. translate: translateFragment,
  12601. getReadyState: function getReadyState() {
  12602. return gReadyState;
  12603. },
  12604. ready: function ready(callback) {
  12605. if (!callback) {
  12606. return;
  12607. } else if (gReadyState == 'complete' || gReadyState == 'interactive') {
  12608. window.setTimeout(function () {
  12609. callback();
  12610. });
  12611. } else if (document.addEventListener) {
  12612. document.addEventListener('localized', function once() {
  12613. document.removeEventListener('localized', once);
  12614. callback();
  12615. });
  12616. }
  12617. }
  12618. };
  12619. }(window, document);
  12620. /***/ }),
  12621. /* 42 */
  12622. /***/ (function(module, exports, __webpack_require__) {
  12623. "use strict";
  12624. Object.defineProperty(exports, "__esModule", {
  12625. value: true
  12626. });
  12627. exports.PDFPrintService = PDFPrintService;
  12628. var _ui_utils = __webpack_require__(6);
  12629. var _app = __webpack_require__(1);
  12630. var _pdfjsLib = __webpack_require__(7);
  12631. var activeService = null;
  12632. var overlayManager = null;
  12633. function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size) {
  12634. var scratchCanvas = activeService.scratchCanvas;
  12635. var PRINT_RESOLUTION = 150;
  12636. var PRINT_UNITS = PRINT_RESOLUTION / 72.0;
  12637. scratchCanvas.width = Math.floor(size.width * PRINT_UNITS);
  12638. scratchCanvas.height = Math.floor(size.height * PRINT_UNITS);
  12639. var width = Math.floor(size.width * _ui_utils.CSS_UNITS) + 'px';
  12640. var height = Math.floor(size.height * _ui_utils.CSS_UNITS) + 'px';
  12641. var ctx = scratchCanvas.getContext('2d');
  12642. ctx.save();
  12643. ctx.fillStyle = 'rgb(255, 255, 255)';
  12644. ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height);
  12645. ctx.restore();
  12646. return pdfDocument.getPage(pageNumber).then(function (pdfPage) {
  12647. var renderContext = {
  12648. canvasContext: ctx,
  12649. transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
  12650. viewport: pdfPage.getViewport({
  12651. scale: 1,
  12652. rotation: size.rotation
  12653. }),
  12654. intent: 'print'
  12655. };
  12656. return pdfPage.render(renderContext).promise;
  12657. }).then(function () {
  12658. return {
  12659. width: width,
  12660. height: height
  12661. };
  12662. });
  12663. }
  12664. function PDFPrintService(pdfDocument, pagesOverview, printContainer, l10n) {
  12665. this.pdfDocument = pdfDocument;
  12666. this.pagesOverview = pagesOverview;
  12667. this.printContainer = printContainer;
  12668. this.l10n = l10n || _ui_utils.NullL10n;
  12669. this.disableCreateObjectURL = pdfDocument.loadingParams['disableCreateObjectURL'];
  12670. this.currentPage = -1;
  12671. this.scratchCanvas = document.createElement('canvas');
  12672. }
  12673. PDFPrintService.prototype = {
  12674. layout: function layout() {
  12675. this.throwIfInactive();
  12676. var body = document.querySelector('body');
  12677. body.setAttribute('data-pdfjsprinting', true);
  12678. var hasEqualPageSizes = this.pagesOverview.every(function (size) {
  12679. return size.width === this.pagesOverview[0].width && size.height === this.pagesOverview[0].height;
  12680. }, this);
  12681. if (!hasEqualPageSizes) {
  12682. console.warn('Not all pages have the same size. The printed ' + 'result may be incorrect!');
  12683. }
  12684. this.pageStyleSheet = document.createElement('style');
  12685. var pageSize = this.pagesOverview[0];
  12686. this.pageStyleSheet.textContent = '@supports ((size:A4) and (size:1pt 1pt)) {' + '@page { size: ' + pageSize.width + 'pt ' + pageSize.height + 'pt;}' + '}';
  12687. body.appendChild(this.pageStyleSheet);
  12688. },
  12689. destroy: function destroy() {
  12690. if (activeService !== this) {
  12691. return;
  12692. }
  12693. this.printContainer.textContent = '';
  12694. if (this.pageStyleSheet) {
  12695. this.pageStyleSheet.remove();
  12696. this.pageStyleSheet = null;
  12697. }
  12698. this.scratchCanvas.width = this.scratchCanvas.height = 0;
  12699. this.scratchCanvas = null;
  12700. activeService = null;
  12701. ensureOverlay().then(function () {
  12702. if (overlayManager.active !== 'printServiceOverlay') {
  12703. return;
  12704. }
  12705. overlayManager.close('printServiceOverlay');
  12706. });
  12707. },
  12708. renderPages: function renderPages() {
  12709. var _this = this;
  12710. var pageCount = this.pagesOverview.length;
  12711. var renderNextPage = function renderNextPage(resolve, reject) {
  12712. _this.throwIfInactive();
  12713. if (++_this.currentPage >= pageCount) {
  12714. renderProgress(pageCount, pageCount, _this.l10n);
  12715. resolve();
  12716. return;
  12717. }
  12718. var index = _this.currentPage;
  12719. renderProgress(index, pageCount, _this.l10n);
  12720. renderPage(_this, _this.pdfDocument, index + 1, _this.pagesOverview[index]).then(_this.useRenderedPage.bind(_this)).then(function () {
  12721. renderNextPage(resolve, reject);
  12722. }, reject);
  12723. };
  12724. return new Promise(renderNextPage);
  12725. },
  12726. useRenderedPage: function useRenderedPage(printItem) {
  12727. this.throwIfInactive();
  12728. var img = document.createElement('img');
  12729. img.style.width = printItem.width;
  12730. img.style.height = printItem.height;
  12731. var scratchCanvas = this.scratchCanvas;
  12732. if ('toBlob' in scratchCanvas && !this.disableCreateObjectURL) {
  12733. scratchCanvas.toBlob(function (blob) {
  12734. img.src = _pdfjsLib.URL.createObjectURL(blob);
  12735. });
  12736. } else {
  12737. img.src = scratchCanvas.toDataURL();
  12738. }
  12739. var wrapper = document.createElement('div');
  12740. wrapper.appendChild(img);
  12741. this.printContainer.appendChild(wrapper);
  12742. return new Promise(function (resolve, reject) {
  12743. img.onload = resolve;
  12744. img.onerror = reject;
  12745. });
  12746. },
  12747. performPrint: function performPrint() {
  12748. var _this2 = this;
  12749. this.throwIfInactive();
  12750. return new Promise(function (resolve) {
  12751. setTimeout(function () {
  12752. if (!_this2.active) {
  12753. resolve();
  12754. return;
  12755. }
  12756. print.call(window);
  12757. setTimeout(resolve, 20);
  12758. }, 0);
  12759. });
  12760. },
  12761. get active() {
  12762. return this === activeService;
  12763. },
  12764. throwIfInactive: function throwIfInactive() {
  12765. if (!this.active) {
  12766. throw new Error('This print request was cancelled or completed.');
  12767. }
  12768. }
  12769. };
  12770. var print = window.print;
  12771. window.print = function print() {
  12772. if (activeService) {
  12773. console.warn('Ignored window.print() because of a pending print job.');
  12774. return;
  12775. }
  12776. ensureOverlay().then(function () {
  12777. if (activeService) {
  12778. overlayManager.open('printServiceOverlay');
  12779. }
  12780. });
  12781. try {
  12782. dispatchEvent('beforeprint');
  12783. } finally {
  12784. if (!activeService) {
  12785. console.error('Expected print service to be initialized.');
  12786. ensureOverlay().then(function () {
  12787. if (overlayManager.active === 'printServiceOverlay') {
  12788. overlayManager.close('printServiceOverlay');
  12789. }
  12790. });
  12791. return;
  12792. }
  12793. var activeServiceOnEntry = activeService;
  12794. activeService.renderPages().then(function () {
  12795. return activeServiceOnEntry.performPrint();
  12796. }).catch(function () {}).then(function () {
  12797. if (activeServiceOnEntry.active) {
  12798. abort();
  12799. }
  12800. });
  12801. }
  12802. };
  12803. function dispatchEvent(eventType) {
  12804. var event = document.createEvent('CustomEvent');
  12805. event.initCustomEvent(eventType, false, false, 'custom');
  12806. window.dispatchEvent(event);
  12807. }
  12808. function abort() {
  12809. if (activeService) {
  12810. activeService.destroy();
  12811. dispatchEvent('afterprint');
  12812. }
  12813. }
  12814. function renderProgress(index, total, l10n) {
  12815. var progressContainer = document.getElementById('printServiceOverlay');
  12816. var progress = Math.round(100 * index / total);
  12817. var progressBar = progressContainer.querySelector('progress');
  12818. var progressPerc = progressContainer.querySelector('.relative-progress');
  12819. progressBar.value = progress;
  12820. l10n.get('print_progress_percent', {
  12821. progress: progress
  12822. }, progress + '%').then(function (msg) {
  12823. progressPerc.textContent = msg;
  12824. });
  12825. }
  12826. var hasAttachEvent = !!document.attachEvent;
  12827. window.addEventListener('keydown', function (event) {
  12828. if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
  12829. window.print();
  12830. if (hasAttachEvent) {
  12831. return;
  12832. }
  12833. event.preventDefault();
  12834. if (event.stopImmediatePropagation) {
  12835. event.stopImmediatePropagation();
  12836. } else {
  12837. event.stopPropagation();
  12838. }
  12839. return;
  12840. }
  12841. }, true);
  12842. if (hasAttachEvent) {
  12843. document.attachEvent('onkeydown', function (event) {
  12844. event = event || window.event;
  12845. if (event.keyCode === 80 && event.ctrlKey) {
  12846. event.keyCode = 0;
  12847. return false;
  12848. }
  12849. });
  12850. }
  12851. if ('onbeforeprint' in window) {
  12852. var stopPropagationIfNeeded = function stopPropagationIfNeeded(event) {
  12853. if (event.detail !== 'custom' && event.stopImmediatePropagation) {
  12854. event.stopImmediatePropagation();
  12855. }
  12856. };
  12857. window.addEventListener('beforeprint', stopPropagationIfNeeded);
  12858. window.addEventListener('afterprint', stopPropagationIfNeeded);
  12859. }
  12860. var overlayPromise;
  12861. function ensureOverlay() {
  12862. if (!overlayPromise) {
  12863. overlayManager = _app.PDFViewerApplication.overlayManager;
  12864. if (!overlayManager) {
  12865. throw new Error('The overlay manager has not yet been initialized.');
  12866. }
  12867. overlayPromise = overlayManager.register('printServiceOverlay', document.getElementById('printServiceOverlay'), abort, true);
  12868. document.getElementById('printCancel').onclick = abort;
  12869. }
  12870. return overlayPromise;
  12871. }
  12872. _app.PDFPrintServiceFactory.instance = {
  12873. supportsPrinting: true,
  12874. createPrintService: function createPrintService(pdfDocument, pagesOverview, printContainer, l10n) {
  12875. if (activeService) {
  12876. throw new Error('The print service is created and active.');
  12877. }
  12878. activeService = new PDFPrintService(pdfDocument, pagesOverview, printContainer, l10n);
  12879. return activeService;
  12880. }
  12881. };
  12882. /***/ })
  12883. /******/ ]);
  12884. //# sourceMappingURL=viewer.js.map
上海开阖软件有限公司 沪ICP备12045867号-1