pdf_viewer.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2019 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.PDFViewer = void 0;
  27. var _base_viewer = require("./base_viewer");
  28. var _pdf = require("../pdf");
  29. 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); }
  30. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  31. 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); } }
  32. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  33. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  34. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  35. 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); }
  36. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  37. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  38. 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); }
  39. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  40. var PDFViewer =
  41. /*#__PURE__*/
  42. function (_BaseViewer) {
  43. _inherits(PDFViewer, _BaseViewer);
  44. function PDFViewer() {
  45. _classCallCheck(this, PDFViewer);
  46. return _possibleConstructorReturn(this, _getPrototypeOf(PDFViewer).apply(this, arguments));
  47. }
  48. _createClass(PDFViewer, [{
  49. key: "_scrollIntoView",
  50. value: function _scrollIntoView(_ref) {
  51. var pageDiv = _ref.pageDiv,
  52. _ref$pageSpot = _ref.pageSpot,
  53. pageSpot = _ref$pageSpot === void 0 ? null : _ref$pageSpot,
  54. _ref$pageNumber = _ref.pageNumber,
  55. pageNumber = _ref$pageNumber === void 0 ? null : _ref$pageNumber;
  56. if (!pageSpot && !this.isInPresentationMode) {
  57. var left = pageDiv.offsetLeft + pageDiv.clientLeft;
  58. var right = left + pageDiv.clientWidth;
  59. var _this$container = this.container,
  60. scrollLeft = _this$container.scrollLeft,
  61. clientWidth = _this$container.clientWidth;
  62. if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
  63. pageSpot = {
  64. left: 0,
  65. top: 0
  66. };
  67. }
  68. }
  69. _get(_getPrototypeOf(PDFViewer.prototype), "_scrollIntoView", this).call(this, {
  70. pageDiv: pageDiv,
  71. pageSpot: pageSpot,
  72. pageNumber: pageNumber
  73. });
  74. }
  75. }, {
  76. key: "_getVisiblePages",
  77. value: function _getVisiblePages() {
  78. if (this.isInPresentationMode) {
  79. return this._getCurrentVisiblePage();
  80. }
  81. return _get(_getPrototypeOf(PDFViewer.prototype), "_getVisiblePages", this).call(this);
  82. }
  83. }, {
  84. key: "_updateHelper",
  85. value: function _updateHelper(visiblePages) {
  86. if (this.isInPresentationMode) {
  87. return;
  88. }
  89. var currentId = this._currentPageNumber;
  90. var stillFullyVisible = false;
  91. var _iteratorNormalCompletion = true;
  92. var _didIteratorError = false;
  93. var _iteratorError = undefined;
  94. try {
  95. for (var _iterator = visiblePages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  96. var page = _step.value;
  97. if (page.percent < 100) {
  98. break;
  99. }
  100. if (page.id === currentId) {
  101. stillFullyVisible = true;
  102. break;
  103. }
  104. }
  105. } catch (err) {
  106. _didIteratorError = true;
  107. _iteratorError = err;
  108. } finally {
  109. try {
  110. if (!_iteratorNormalCompletion && _iterator["return"] != null) {
  111. _iterator["return"]();
  112. }
  113. } finally {
  114. if (_didIteratorError) {
  115. throw _iteratorError;
  116. }
  117. }
  118. }
  119. if (!stillFullyVisible) {
  120. currentId = visiblePages[0].id;
  121. }
  122. this._setCurrentPageNumber(currentId);
  123. }
  124. }, {
  125. key: "_setDocumentViewerElement",
  126. get: function get() {
  127. return (0, _pdf.shadow)(this, '_setDocumentViewerElement', this.viewer);
  128. }
  129. }]);
  130. return PDFViewer;
  131. }(_base_viewer.BaseViewer);
  132. exports.PDFViewer = PDFViewer;