pdf_viewer.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 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.js");
  28. var _pdf = require("../pdf");
  29. class PDFViewer extends _base_viewer.BaseViewer {
  30. get _viewerElement() {
  31. return (0, _pdf.shadow)(this, "_viewerElement", this.viewer);
  32. }
  33. _scrollIntoView({
  34. pageDiv,
  35. pageSpot = null,
  36. pageNumber = null
  37. }) {
  38. if (!pageSpot && !this.isInPresentationMode) {
  39. const left = pageDiv.offsetLeft + pageDiv.clientLeft;
  40. const right = left + pageDiv.clientWidth;
  41. const {
  42. scrollLeft,
  43. clientWidth
  44. } = this.container;
  45. if (this._isScrollModeHorizontal || left < scrollLeft || right > scrollLeft + clientWidth) {
  46. pageSpot = {
  47. left: 0,
  48. top: 0
  49. };
  50. }
  51. }
  52. super._scrollIntoView({
  53. pageDiv,
  54. pageSpot,
  55. pageNumber
  56. });
  57. }
  58. _getVisiblePages() {
  59. if (this.isInPresentationMode) {
  60. return this._getCurrentVisiblePage();
  61. }
  62. return super._getVisiblePages();
  63. }
  64. _updateHelper(visiblePages) {
  65. if (this.isInPresentationMode) {
  66. return;
  67. }
  68. let currentId = this._currentPageNumber;
  69. let stillFullyVisible = false;
  70. for (const page of visiblePages) {
  71. if (page.percent < 100) {
  72. break;
  73. }
  74. if (page.id === currentId) {
  75. stillFullyVisible = true;
  76. break;
  77. }
  78. }
  79. if (!stillFullyVisible) {
  80. currentId = visiblePages[0].id;
  81. }
  82. this._setCurrentPageNumber(currentId);
  83. }
  84. }
  85. exports.PDFViewer = PDFViewer;