pdf_single_page_viewer.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.PDFSinglePageViewer = 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 PDFSinglePageViewer =
  41. /*#__PURE__*/
  42. function (_BaseViewer) {
  43. _inherits(PDFSinglePageViewer, _BaseViewer);
  44. function PDFSinglePageViewer(options) {
  45. var _this;
  46. _classCallCheck(this, PDFSinglePageViewer);
  47. _this = _possibleConstructorReturn(this, _getPrototypeOf(PDFSinglePageViewer).call(this, options));
  48. _this.eventBus.on('pagesinit', function (evt) {
  49. _this._ensurePageViewVisible();
  50. });
  51. return _this;
  52. }
  53. _createClass(PDFSinglePageViewer, [{
  54. key: "_resetView",
  55. value: function _resetView() {
  56. _get(_getPrototypeOf(PDFSinglePageViewer.prototype), "_resetView", this).call(this);
  57. this._previousPageNumber = 1;
  58. this._shadowViewer = document.createDocumentFragment();
  59. this._updateScrollDown = null;
  60. }
  61. }, {
  62. key: "_ensurePageViewVisible",
  63. value: function _ensurePageViewVisible() {
  64. var pageView = this._pages[this._currentPageNumber - 1];
  65. var previousPageView = this._pages[this._previousPageNumber - 1];
  66. var viewerNodes = this.viewer.childNodes;
  67. switch (viewerNodes.length) {
  68. case 0:
  69. this.viewer.appendChild(pageView.div);
  70. break;
  71. case 1:
  72. if (viewerNodes[0] !== previousPageView.div) {
  73. throw new Error('_ensurePageViewVisible: Unexpected previously visible page.');
  74. }
  75. if (pageView === previousPageView) {
  76. break;
  77. }
  78. this._shadowViewer.appendChild(previousPageView.div);
  79. this.viewer.appendChild(pageView.div);
  80. this.container.scrollTop = 0;
  81. break;
  82. default:
  83. throw new Error('_ensurePageViewVisible: Only one page should be visible at a time.');
  84. }
  85. this._previousPageNumber = this._currentPageNumber;
  86. }
  87. }, {
  88. key: "_scrollUpdate",
  89. value: function _scrollUpdate() {
  90. if (this._updateScrollDown) {
  91. this._updateScrollDown();
  92. }
  93. _get(_getPrototypeOf(PDFSinglePageViewer.prototype), "_scrollUpdate", this).call(this);
  94. }
  95. }, {
  96. key: "_scrollIntoView",
  97. value: function _scrollIntoView(_ref) {
  98. var _this2 = this;
  99. var pageDiv = _ref.pageDiv,
  100. _ref$pageSpot = _ref.pageSpot,
  101. pageSpot = _ref$pageSpot === void 0 ? null : _ref$pageSpot,
  102. _ref$pageNumber = _ref.pageNumber,
  103. pageNumber = _ref$pageNumber === void 0 ? null : _ref$pageNumber;
  104. if (pageNumber) {
  105. this._setCurrentPageNumber(pageNumber);
  106. }
  107. var scrolledDown = this._currentPageNumber >= this._previousPageNumber;
  108. this._ensurePageViewVisible();
  109. this.update();
  110. _get(_getPrototypeOf(PDFSinglePageViewer.prototype), "_scrollIntoView", this).call(this, {
  111. pageDiv: pageDiv,
  112. pageSpot: pageSpot,
  113. pageNumber: pageNumber
  114. });
  115. this._updateScrollDown = function () {
  116. _this2.scroll.down = scrolledDown;
  117. _this2._updateScrollDown = null;
  118. };
  119. }
  120. }, {
  121. key: "_getVisiblePages",
  122. value: function _getVisiblePages() {
  123. return this._getCurrentVisiblePage();
  124. }
  125. }, {
  126. key: "_updateHelper",
  127. value: function _updateHelper(visiblePages) {}
  128. }, {
  129. key: "_updateScrollMode",
  130. value: function _updateScrollMode() {}
  131. }, {
  132. key: "_updateSpreadMode",
  133. value: function _updateSpreadMode() {}
  134. }, {
  135. key: "_setDocumentViewerElement",
  136. get: function get() {
  137. return (0, _pdf.shadow)(this, '_setDocumentViewerElement', this._shadowViewer);
  138. }
  139. }, {
  140. key: "_isScrollModeHorizontal",
  141. get: function get() {
  142. return (0, _pdf.shadow)(this, '_isScrollModeHorizontal', false);
  143. }
  144. }]);
  145. return PDFSinglePageViewer;
  146. }(_base_viewer.BaseViewer);
  147. exports.PDFSinglePageViewer = PDFSinglePageViewer;