UNPKG

3.35 kBJavaScriptView Raw
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
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.PDFSinglePageViewer = void 0;
28
29var _base_viewer = require("./base_viewer.js");
30
31var _pdf = require("../pdf");
32
33class PDFSinglePageViewer extends _base_viewer.BaseViewer {
34 constructor(options) {
35 super(options);
36
37 this.eventBus._on("pagesinit", evt => {
38 this._ensurePageViewVisible();
39 });
40 }
41
42 get _setDocumentViewerElement() {
43 return (0, _pdf.shadow)(this, "_setDocumentViewerElement", this._shadowViewer);
44 }
45
46 _resetView() {
47 super._resetView();
48
49 this._previousPageNumber = 1;
50 this._shadowViewer = document.createDocumentFragment();
51 this._updateScrollDown = null;
52 }
53
54 _ensurePageViewVisible() {
55 const pageView = this._pages[this._currentPageNumber - 1];
56 const previousPageView = this._pages[this._previousPageNumber - 1];
57 const viewerNodes = this.viewer.childNodes;
58
59 switch (viewerNodes.length) {
60 case 0:
61 this.viewer.appendChild(pageView.div);
62 break;
63
64 case 1:
65 if (viewerNodes[0] !== previousPageView.div) {
66 throw new Error("_ensurePageViewVisible: Unexpected previously visible page.");
67 }
68
69 if (pageView === previousPageView) {
70 break;
71 }
72
73 this._shadowViewer.appendChild(previousPageView.div);
74
75 this.viewer.appendChild(pageView.div);
76 this.container.scrollTop = 0;
77 break;
78
79 default:
80 throw new Error("_ensurePageViewVisible: Only one page should be visible at a time.");
81 }
82
83 this._previousPageNumber = this._currentPageNumber;
84 }
85
86 _scrollUpdate() {
87 if (this._updateScrollDown) {
88 this._updateScrollDown();
89 }
90
91 super._scrollUpdate();
92 }
93
94 _scrollIntoView({
95 pageDiv,
96 pageSpot = null,
97 pageNumber = null
98 }) {
99 if (pageNumber) {
100 this._setCurrentPageNumber(pageNumber);
101 }
102
103 const scrolledDown = this._currentPageNumber >= this._previousPageNumber;
104
105 this._ensurePageViewVisible();
106
107 this.update();
108
109 super._scrollIntoView({
110 pageDiv,
111 pageSpot,
112 pageNumber
113 });
114
115 this._updateScrollDown = () => {
116 this.scroll.down = scrolledDown;
117 this._updateScrollDown = null;
118 };
119 }
120
121 _getVisiblePages() {
122 return this._getCurrentVisiblePage();
123 }
124
125 _updateHelper(visiblePages) {}
126
127 get _isScrollModeHorizontal() {
128 return (0, _pdf.shadow)(this, "_isScrollModeHorizontal", false);
129 }
130
131 _updateScrollMode() {}
132
133 _updateSpreadMode() {}
134
135}
136
137exports.PDFSinglePageViewer = PDFSinglePageViewer;
\No newline at end of file