pdf_viewer.js 2.5 KB

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