@vaadin-component-factory/vcf-pdf-viewer 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/pdfjs/dist/display_utils.js +714 -714
- package/pdfjs/dist/fetch_stream.js +293 -293
- package/pdfjs/dist/l10n_utils.js +122 -122
- package/pdfjs/dist/message_handler.js +524 -524
- package/pdfjs/dist/network.js +552 -552
- package/pdfjs/dist/network_utils.js +309 -309
- package/pdfjs/dist/node_stream.js +481 -481
- package/pdfjs/dist/pdf.js +11687 -11687
- package/pdfjs/dist/pdf_link_service.js +534 -534
- package/pdfjs/dist/pdf_rendering_queue.js +154 -154
- package/pdfjs/dist/pdf_thumbnail_viewer.js +738 -738
- package/pdfjs/dist/pdf_viewer.js +3207 -3207
- package/pdfjs/dist/ui_utils.js +881 -881
- package/pdfjs/dist/util.js +991 -991
- package/pdfjs/dist/worker.js +60846 -60846
- package/src/vcf-pdf-viewer.js +12 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { getOutputScale, watchScroll, getVisibleElements, scrollIntoView, isValidRotation } from './ui_utils.js';
|
|
2
|
-
import './pdf.js';
|
|
3
|
-
import { RenderingStates } from './pdf_rendering_queue.js';
|
|
4
|
-
import { R as RenderingCancelledException } from './display_utils.js';
|
|
5
|
-
import './util.js';
|
|
6
|
-
import './message_handler.js';
|
|
7
|
-
|
|
1
|
+
import { getOutputScale, watchScroll, getVisibleElements, scrollIntoView, isValidRotation } from './ui_utils.js';
|
|
2
|
+
import './pdf.js';
|
|
3
|
+
import { RenderingStates } from './pdf_rendering_queue.js';
|
|
4
|
+
import { R as RenderingCancelledException } from './display_utils.js';
|
|
5
|
+
import './util.js';
|
|
6
|
+
import './message_handler.js';
|
|
7
|
+
|
|
8
8
|
/* Copyright 2012 Mozilla Foundation
|
|
9
9
|
*
|
|
10
10
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -18,14 +18,14 @@ import './message_handler.js';
|
|
|
18
18
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
|
-
*/
|
|
22
|
-
const DRAW_UPSCALE_FACTOR = 2; // See comment in `PDFThumbnailView.draw` below.
|
|
23
|
-
|
|
24
|
-
const MAX_NUM_SCALING_STEPS = 3;
|
|
25
|
-
const THUMBNAIL_CANVAS_BORDER_WIDTH = 1; // px
|
|
26
|
-
|
|
27
|
-
const THUMBNAIL_WIDTH = 98; // px
|
|
28
|
-
|
|
21
|
+
*/
|
|
22
|
+
const DRAW_UPSCALE_FACTOR = 2; // See comment in `PDFThumbnailView.draw` below.
|
|
23
|
+
|
|
24
|
+
const MAX_NUM_SCALING_STEPS = 3;
|
|
25
|
+
const THUMBNAIL_CANVAS_BORDER_WIDTH = 1; // px
|
|
26
|
+
|
|
27
|
+
const THUMBNAIL_WIDTH = 98; // px
|
|
28
|
+
|
|
29
29
|
/**
|
|
30
30
|
* @typedef {Object} PDFThumbnailViewOptions
|
|
31
31
|
* @property {HTMLDivElement} container - The viewer element.
|
|
@@ -38,452 +38,452 @@ const THUMBNAIL_WIDTH = 98; // px
|
|
|
38
38
|
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
|
39
39
|
* @property {function} checkSetImageDisabled
|
|
40
40
|
* @property {IL10n} l10n - Localization service.
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
const TempImageFactory = function TempImageFactoryClosure() {
|
|
44
|
-
let tempCanvasCache = null;
|
|
45
|
-
return {
|
|
46
|
-
getCanvas(width, height) {
|
|
47
|
-
let tempCanvas = tempCanvasCache;
|
|
48
|
-
|
|
49
|
-
if (!tempCanvas) {
|
|
50
|
-
tempCanvas = document.createElement("canvas");
|
|
51
|
-
tempCanvasCache = tempCanvas;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
tempCanvas.width = width;
|
|
55
|
-
tempCanvas.height = height; // Since this is a temporary canvas, we need to fill it with a white
|
|
56
|
-
// background ourselves. `_getPageDrawContext` uses CSS rules for this.
|
|
57
|
-
|
|
58
|
-
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("MOZCENTRAL || GENERIC")) {
|
|
59
|
-
tempCanvas.mozOpaque = true;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const ctx = tempCanvas.getContext("2d", {
|
|
63
|
-
alpha: false
|
|
64
|
-
});
|
|
65
|
-
ctx.save();
|
|
66
|
-
ctx.fillStyle = "rgb(255, 255, 255)";
|
|
67
|
-
ctx.fillRect(0, 0, width, height);
|
|
68
|
-
ctx.restore();
|
|
69
|
-
return [tempCanvas, tempCanvas.getContext("2d")];
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
destroyCanvas() {
|
|
73
|
-
const tempCanvas = tempCanvasCache;
|
|
74
|
-
|
|
75
|
-
if (tempCanvas) {
|
|
76
|
-
// Zeroing the width and height causes Firefox to release graphics
|
|
77
|
-
// resources immediately, which can greatly reduce memory consumption.
|
|
78
|
-
tempCanvas.width = 0;
|
|
79
|
-
tempCanvas.height = 0;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
tempCanvasCache = null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
};
|
|
86
|
-
}();
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
const TempImageFactory = function TempImageFactoryClosure() {
|
|
44
|
+
let tempCanvasCache = null;
|
|
45
|
+
return {
|
|
46
|
+
getCanvas(width, height) {
|
|
47
|
+
let tempCanvas = tempCanvasCache;
|
|
48
|
+
|
|
49
|
+
if (!tempCanvas) {
|
|
50
|
+
tempCanvas = document.createElement("canvas");
|
|
51
|
+
tempCanvasCache = tempCanvas;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
tempCanvas.width = width;
|
|
55
|
+
tempCanvas.height = height; // Since this is a temporary canvas, we need to fill it with a white
|
|
56
|
+
// background ourselves. `_getPageDrawContext` uses CSS rules for this.
|
|
57
|
+
|
|
58
|
+
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("MOZCENTRAL || GENERIC")) {
|
|
59
|
+
tempCanvas.mozOpaque = true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const ctx = tempCanvas.getContext("2d", {
|
|
63
|
+
alpha: false
|
|
64
|
+
});
|
|
65
|
+
ctx.save();
|
|
66
|
+
ctx.fillStyle = "rgb(255, 255, 255)";
|
|
67
|
+
ctx.fillRect(0, 0, width, height);
|
|
68
|
+
ctx.restore();
|
|
69
|
+
return [tempCanvas, tempCanvas.getContext("2d")];
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
destroyCanvas() {
|
|
73
|
+
const tempCanvas = tempCanvasCache;
|
|
74
|
+
|
|
75
|
+
if (tempCanvas) {
|
|
76
|
+
// Zeroing the width and height causes Firefox to release graphics
|
|
77
|
+
// resources immediately, which can greatly reduce memory consumption.
|
|
78
|
+
tempCanvas.width = 0;
|
|
79
|
+
tempCanvas.height = 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
tempCanvasCache = null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
};
|
|
86
|
+
}();
|
|
87
87
|
/**
|
|
88
88
|
* @implements {IRenderableView}
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
class PDFThumbnailView {
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class PDFThumbnailView {
|
|
93
93
|
/**
|
|
94
94
|
* @param {PDFThumbnailViewOptions} options
|
|
95
|
-
*/
|
|
96
|
-
constructor({
|
|
97
|
-
container,
|
|
98
|
-
id,
|
|
99
|
-
defaultViewport,
|
|
100
|
-
optionalContentConfigPromise,
|
|
101
|
-
linkService,
|
|
102
|
-
renderingQueue,
|
|
103
|
-
checkSetImageDisabled,
|
|
104
|
-
l10n
|
|
105
|
-
}) {
|
|
106
|
-
this.id = id;
|
|
107
|
-
this.renderingId = "thumbnail" + id;
|
|
108
|
-
this.pageLabel = null;
|
|
109
|
-
this.pdfPage = null;
|
|
110
|
-
this.rotation = 0;
|
|
111
|
-
this.viewport = defaultViewport;
|
|
112
|
-
this.pdfPageRotate = defaultViewport.rotation;
|
|
113
|
-
this._optionalContentConfigPromise = optionalContentConfigPromise || null;
|
|
114
|
-
this.linkService = linkService;
|
|
115
|
-
this.renderingQueue = renderingQueue;
|
|
116
|
-
this.renderTask = null;
|
|
117
|
-
this.renderingState = RenderingStates.INITIAL;
|
|
118
|
-
this.resume = null;
|
|
119
|
-
|
|
120
|
-
this._checkSetImageDisabled = checkSetImageDisabled || function () {
|
|
121
|
-
return false;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const pageWidth = this.viewport.width,
|
|
125
|
-
pageHeight = this.viewport.height,
|
|
126
|
-
pageRatio = pageWidth / pageHeight;
|
|
127
|
-
this.canvasWidth = THUMBNAIL_WIDTH;
|
|
128
|
-
this.canvasHeight = this.canvasWidth / pageRatio | 0;
|
|
129
|
-
this.scale = this.canvasWidth / pageWidth;
|
|
130
|
-
this.l10n = l10n;
|
|
131
|
-
const anchor = document.createElement("a");
|
|
132
|
-
anchor.href = linkService.getAnchorUrl("#page=" + id);
|
|
133
|
-
|
|
134
|
-
this._thumbPageTitle.then(msg => {
|
|
135
|
-
anchor.title = msg;
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
anchor.onclick = function () {
|
|
139
|
-
linkService.goToPage(id);
|
|
140
|
-
return false;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
this.anchor = anchor;
|
|
144
|
-
const div = document.createElement("div");
|
|
145
|
-
div.className = "thumbnail";
|
|
146
|
-
div.setAttribute("data-page-number", this.id);
|
|
147
|
-
this.div = div;
|
|
148
|
-
const ring = document.createElement("div");
|
|
149
|
-
ring.className = "thumbnailSelectionRing";
|
|
150
|
-
const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
|
151
|
-
ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
|
152
|
-
ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
|
153
|
-
this.ring = ring;
|
|
154
|
-
div.appendChild(ring);
|
|
155
|
-
anchor.appendChild(div);
|
|
156
|
-
container.appendChild(anchor);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
setPdfPage(pdfPage) {
|
|
160
|
-
this.pdfPage = pdfPage;
|
|
161
|
-
this.pdfPageRotate = pdfPage.rotate;
|
|
162
|
-
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
|
163
|
-
this.viewport = pdfPage.getViewport({
|
|
164
|
-
scale: 1,
|
|
165
|
-
rotation: totalRotation
|
|
166
|
-
});
|
|
167
|
-
this.reset();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
reset() {
|
|
171
|
-
this.cancelRendering();
|
|
172
|
-
this.renderingState = RenderingStates.INITIAL;
|
|
173
|
-
const pageWidth = this.viewport.width,
|
|
174
|
-
pageHeight = this.viewport.height,
|
|
175
|
-
pageRatio = pageWidth / pageHeight;
|
|
176
|
-
this.canvasHeight = this.canvasWidth / pageRatio | 0;
|
|
177
|
-
this.scale = this.canvasWidth / pageWidth;
|
|
178
|
-
this.div.removeAttribute("data-loaded");
|
|
179
|
-
const ring = this.ring;
|
|
180
|
-
ring.textContent = ""; // Remove the thumbnail from the DOM.
|
|
181
|
-
|
|
182
|
-
const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
|
183
|
-
ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
|
184
|
-
ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
|
185
|
-
|
|
186
|
-
if (this.canvas) {
|
|
187
|
-
// Zeroing the width and height causes Firefox to release graphics
|
|
188
|
-
// resources immediately, which can greatly reduce memory consumption.
|
|
189
|
-
this.canvas.width = 0;
|
|
190
|
-
this.canvas.height = 0;
|
|
191
|
-
delete this.canvas;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (this.image) {
|
|
195
|
-
this.image.removeAttribute("src");
|
|
196
|
-
delete this.image;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
update(rotation) {
|
|
201
|
-
if (typeof rotation !== "undefined") {
|
|
202
|
-
this.rotation = rotation;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
|
206
|
-
this.viewport = this.viewport.clone({
|
|
207
|
-
scale: 1,
|
|
208
|
-
rotation: totalRotation
|
|
209
|
-
});
|
|
210
|
-
this.reset();
|
|
211
|
-
}
|
|
95
|
+
*/
|
|
96
|
+
constructor({
|
|
97
|
+
container,
|
|
98
|
+
id,
|
|
99
|
+
defaultViewport,
|
|
100
|
+
optionalContentConfigPromise,
|
|
101
|
+
linkService,
|
|
102
|
+
renderingQueue,
|
|
103
|
+
checkSetImageDisabled,
|
|
104
|
+
l10n
|
|
105
|
+
}) {
|
|
106
|
+
this.id = id;
|
|
107
|
+
this.renderingId = "thumbnail" + id;
|
|
108
|
+
this.pageLabel = null;
|
|
109
|
+
this.pdfPage = null;
|
|
110
|
+
this.rotation = 0;
|
|
111
|
+
this.viewport = defaultViewport;
|
|
112
|
+
this.pdfPageRotate = defaultViewport.rotation;
|
|
113
|
+
this._optionalContentConfigPromise = optionalContentConfigPromise || null;
|
|
114
|
+
this.linkService = linkService;
|
|
115
|
+
this.renderingQueue = renderingQueue;
|
|
116
|
+
this.renderTask = null;
|
|
117
|
+
this.renderingState = RenderingStates.INITIAL;
|
|
118
|
+
this.resume = null;
|
|
119
|
+
|
|
120
|
+
this._checkSetImageDisabled = checkSetImageDisabled || function () {
|
|
121
|
+
return false;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const pageWidth = this.viewport.width,
|
|
125
|
+
pageHeight = this.viewport.height,
|
|
126
|
+
pageRatio = pageWidth / pageHeight;
|
|
127
|
+
this.canvasWidth = THUMBNAIL_WIDTH;
|
|
128
|
+
this.canvasHeight = this.canvasWidth / pageRatio | 0;
|
|
129
|
+
this.scale = this.canvasWidth / pageWidth;
|
|
130
|
+
this.l10n = l10n;
|
|
131
|
+
const anchor = document.createElement("a");
|
|
132
|
+
anchor.href = linkService.getAnchorUrl("#page=" + id);
|
|
133
|
+
|
|
134
|
+
this._thumbPageTitle.then(msg => {
|
|
135
|
+
anchor.title = msg;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
anchor.onclick = function () {
|
|
139
|
+
linkService.goToPage(id);
|
|
140
|
+
return false;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
this.anchor = anchor;
|
|
144
|
+
const div = document.createElement("div");
|
|
145
|
+
div.className = "thumbnail";
|
|
146
|
+
div.setAttribute("data-page-number", this.id);
|
|
147
|
+
this.div = div;
|
|
148
|
+
const ring = document.createElement("div");
|
|
149
|
+
ring.className = "thumbnailSelectionRing";
|
|
150
|
+
const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
|
151
|
+
ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
|
152
|
+
ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
|
153
|
+
this.ring = ring;
|
|
154
|
+
div.appendChild(ring);
|
|
155
|
+
anchor.appendChild(div);
|
|
156
|
+
container.appendChild(anchor);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
setPdfPage(pdfPage) {
|
|
160
|
+
this.pdfPage = pdfPage;
|
|
161
|
+
this.pdfPageRotate = pdfPage.rotate;
|
|
162
|
+
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
|
163
|
+
this.viewport = pdfPage.getViewport({
|
|
164
|
+
scale: 1,
|
|
165
|
+
rotation: totalRotation
|
|
166
|
+
});
|
|
167
|
+
this.reset();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
reset() {
|
|
171
|
+
this.cancelRendering();
|
|
172
|
+
this.renderingState = RenderingStates.INITIAL;
|
|
173
|
+
const pageWidth = this.viewport.width,
|
|
174
|
+
pageHeight = this.viewport.height,
|
|
175
|
+
pageRatio = pageWidth / pageHeight;
|
|
176
|
+
this.canvasHeight = this.canvasWidth / pageRatio | 0;
|
|
177
|
+
this.scale = this.canvasWidth / pageWidth;
|
|
178
|
+
this.div.removeAttribute("data-loaded");
|
|
179
|
+
const ring = this.ring;
|
|
180
|
+
ring.textContent = ""; // Remove the thumbnail from the DOM.
|
|
181
|
+
|
|
182
|
+
const borderAdjustment = 2 * THUMBNAIL_CANVAS_BORDER_WIDTH;
|
|
183
|
+
ring.style.width = this.canvasWidth + borderAdjustment + "px";
|
|
184
|
+
ring.style.height = this.canvasHeight + borderAdjustment + "px";
|
|
185
|
+
|
|
186
|
+
if (this.canvas) {
|
|
187
|
+
// Zeroing the width and height causes Firefox to release graphics
|
|
188
|
+
// resources immediately, which can greatly reduce memory consumption.
|
|
189
|
+
this.canvas.width = 0;
|
|
190
|
+
this.canvas.height = 0;
|
|
191
|
+
delete this.canvas;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (this.image) {
|
|
195
|
+
this.image.removeAttribute("src");
|
|
196
|
+
delete this.image;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
update(rotation) {
|
|
201
|
+
if (typeof rotation !== "undefined") {
|
|
202
|
+
this.rotation = rotation;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
|
206
|
+
this.viewport = this.viewport.clone({
|
|
207
|
+
scale: 1,
|
|
208
|
+
rotation: totalRotation
|
|
209
|
+
});
|
|
210
|
+
this.reset();
|
|
211
|
+
}
|
|
212
212
|
/**
|
|
213
213
|
* PLEASE NOTE: Most likely you want to use the `this.reset()` method,
|
|
214
214
|
* rather than calling this one directly.
|
|
215
|
-
*/
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
cancelRendering() {
|
|
219
|
-
if (this.renderTask) {
|
|
220
|
-
this.renderTask.cancel();
|
|
221
|
-
this.renderTask = null;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
this.resume = null;
|
|
225
|
-
}
|
|
215
|
+
*/
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
cancelRendering() {
|
|
219
|
+
if (this.renderTask) {
|
|
220
|
+
this.renderTask.cancel();
|
|
221
|
+
this.renderTask = null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
this.resume = null;
|
|
225
|
+
}
|
|
226
226
|
/**
|
|
227
227
|
* @private
|
|
228
|
-
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
_getPageDrawContext(upscaleFactor = 1) {
|
|
232
|
-
// Keep the no-thumbnail outline visible, i.e. `data-loaded === false`,
|
|
233
|
-
// until rendering/image conversion is complete, to avoid display issues.
|
|
234
|
-
const canvas = document.createElement("canvas");
|
|
235
|
-
|
|
236
|
-
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("MOZCENTRAL || GENERIC")) {
|
|
237
|
-
canvas.mozOpaque = true;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const ctx = canvas.getContext("2d", {
|
|
241
|
-
alpha: false
|
|
242
|
-
});
|
|
243
|
-
const outputScale = getOutputScale(ctx);
|
|
244
|
-
canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
|
|
245
|
-
canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
|
|
246
|
-
const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
|
|
247
|
-
return {
|
|
248
|
-
ctx,
|
|
249
|
-
canvas,
|
|
250
|
-
transform
|
|
251
|
-
};
|
|
252
|
-
}
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
_getPageDrawContext(upscaleFactor = 1) {
|
|
232
|
+
// Keep the no-thumbnail outline visible, i.e. `data-loaded === false`,
|
|
233
|
+
// until rendering/image conversion is complete, to avoid display issues.
|
|
234
|
+
const canvas = document.createElement("canvas");
|
|
235
|
+
|
|
236
|
+
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("MOZCENTRAL || GENERIC")) {
|
|
237
|
+
canvas.mozOpaque = true;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const ctx = canvas.getContext("2d", {
|
|
241
|
+
alpha: false
|
|
242
|
+
});
|
|
243
|
+
const outputScale = getOutputScale(ctx);
|
|
244
|
+
canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
|
|
245
|
+
canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
|
|
246
|
+
const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
|
|
247
|
+
return {
|
|
248
|
+
ctx,
|
|
249
|
+
canvas,
|
|
250
|
+
transform
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
253
|
/**
|
|
254
254
|
* @private
|
|
255
|
-
*/
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
_convertCanvasToImage(canvas) {
|
|
259
|
-
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
260
|
-
throw new Error("_convertCanvasToImage: Rendering has not finished.");
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const reducedCanvas = this._reduceImage(canvas);
|
|
264
|
-
|
|
265
|
-
const image = document.createElement("img");
|
|
266
|
-
image.className = "thumbnailImage";
|
|
267
|
-
|
|
268
|
-
this._thumbPageCanvas.then(msg => {
|
|
269
|
-
image.setAttribute("aria-label", msg);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
image.style.width = this.canvasWidth + "px";
|
|
273
|
-
image.style.height = this.canvasHeight + "px";
|
|
274
|
-
image.src = reducedCanvas.toDataURL();
|
|
275
|
-
this.image = image;
|
|
276
|
-
this.div.setAttribute("data-loaded", true);
|
|
277
|
-
this.ring.appendChild(image); // Zeroing the width and height causes Firefox to release graphics
|
|
278
|
-
// resources immediately, which can greatly reduce memory consumption.
|
|
279
|
-
|
|
280
|
-
reducedCanvas.width = 0;
|
|
281
|
-
reducedCanvas.height = 0;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
draw() {
|
|
285
|
-
if (this.renderingState !== RenderingStates.INITIAL) {
|
|
286
|
-
console.error("Must be in new state before drawing");
|
|
287
|
-
return Promise.resolve(undefined);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const {
|
|
291
|
-
pdfPage
|
|
292
|
-
} = this;
|
|
293
|
-
|
|
294
|
-
if (!pdfPage) {
|
|
295
|
-
this.renderingState = RenderingStates.FINISHED;
|
|
296
|
-
return Promise.reject(new Error("pdfPage is not loaded"));
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
this.renderingState = RenderingStates.RUNNING;
|
|
300
|
-
|
|
301
|
-
const finishRenderTask = async (error = null) => {
|
|
302
|
-
// The renderTask may have been replaced by a new one, so only remove
|
|
303
|
-
// the reference to the renderTask if it matches the one that is
|
|
304
|
-
// triggering this callback.
|
|
305
|
-
if (renderTask === this.renderTask) {
|
|
306
|
-
this.renderTask = null;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if (error instanceof RenderingCancelledException) {
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
this.renderingState = RenderingStates.FINISHED;
|
|
314
|
-
|
|
315
|
-
this._convertCanvasToImage(canvas);
|
|
316
|
-
|
|
317
|
-
if (error) {
|
|
318
|
-
throw error;
|
|
319
|
-
}
|
|
320
|
-
}; // Render the thumbnail at a larger size and downsize the canvas (similar
|
|
321
|
-
// to `setImage`), to improve consistency between thumbnails created by
|
|
322
|
-
// the `draw` and `setImage` methods (fixes issue 8233).
|
|
323
|
-
// NOTE: To primarily avoid increasing memory usage too much, but also to
|
|
324
|
-
// reduce downsizing overhead, we purposely limit the up-scaling factor.
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const {
|
|
328
|
-
ctx,
|
|
329
|
-
canvas,
|
|
330
|
-
transform
|
|
331
|
-
} = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
|
|
332
|
-
|
|
333
|
-
const drawViewport = this.viewport.clone({
|
|
334
|
-
scale: DRAW_UPSCALE_FACTOR * this.scale
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
const renderContinueCallback = cont => {
|
|
338
|
-
if (!this.renderingQueue.isHighestPriority(this)) {
|
|
339
|
-
this.renderingState = RenderingStates.PAUSED;
|
|
340
|
-
|
|
341
|
-
this.resume = () => {
|
|
342
|
-
this.renderingState = RenderingStates.RUNNING;
|
|
343
|
-
cont();
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
cont();
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
const renderContext = {
|
|
353
|
-
canvasContext: ctx,
|
|
354
|
-
transform,
|
|
355
|
-
viewport: drawViewport,
|
|
356
|
-
optionalContentConfigPromise: this._optionalContentConfigPromise
|
|
357
|
-
};
|
|
358
|
-
const renderTask = this.renderTask = pdfPage.render(renderContext);
|
|
359
|
-
renderTask.onContinue = renderContinueCallback;
|
|
360
|
-
const resultPromise = renderTask.promise.then(function () {
|
|
361
|
-
return finishRenderTask(null);
|
|
362
|
-
}, function (error) {
|
|
363
|
-
return finishRenderTask(error);
|
|
364
|
-
});
|
|
365
|
-
resultPromise.finally(() => {
|
|
366
|
-
// Zeroing the width and height causes Firefox to release graphics
|
|
367
|
-
// resources immediately, which can greatly reduce memory consumption.
|
|
368
|
-
canvas.width = 0;
|
|
369
|
-
canvas.height = 0; // Only trigger cleanup, once rendering has finished, when the current
|
|
370
|
-
// pageView is *not* cached on the `BaseViewer`-instance.
|
|
371
|
-
|
|
372
|
-
const pageCached = this.linkService.isPageCached(this.id);
|
|
373
|
-
|
|
374
|
-
if (!pageCached) {
|
|
375
|
-
var _this$pdfPage;
|
|
376
|
-
|
|
377
|
-
(_this$pdfPage = this.pdfPage) === null || _this$pdfPage === void 0 ? void 0 : _this$pdfPage.cleanup();
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
return resultPromise;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
setImage(pageView) {
|
|
384
|
-
if (this._checkSetImageDisabled()) {
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
if (this.renderingState !== RenderingStates.INITIAL) {
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
const {
|
|
393
|
-
canvas,
|
|
394
|
-
pdfPage
|
|
395
|
-
} = pageView;
|
|
396
|
-
|
|
397
|
-
if (!canvas) {
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
if (!this.pdfPage) {
|
|
402
|
-
this.setPdfPage(pdfPage);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
this.renderingState = RenderingStates.FINISHED;
|
|
406
|
-
|
|
407
|
-
this._convertCanvasToImage(canvas);
|
|
408
|
-
}
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
_convertCanvasToImage(canvas) {
|
|
259
|
+
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
260
|
+
throw new Error("_convertCanvasToImage: Rendering has not finished.");
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const reducedCanvas = this._reduceImage(canvas);
|
|
264
|
+
|
|
265
|
+
const image = document.createElement("img");
|
|
266
|
+
image.className = "thumbnailImage";
|
|
267
|
+
|
|
268
|
+
this._thumbPageCanvas.then(msg => {
|
|
269
|
+
image.setAttribute("aria-label", msg);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
image.style.width = this.canvasWidth + "px";
|
|
273
|
+
image.style.height = this.canvasHeight + "px";
|
|
274
|
+
image.src = reducedCanvas.toDataURL();
|
|
275
|
+
this.image = image;
|
|
276
|
+
this.div.setAttribute("data-loaded", true);
|
|
277
|
+
this.ring.appendChild(image); // Zeroing the width and height causes Firefox to release graphics
|
|
278
|
+
// resources immediately, which can greatly reduce memory consumption.
|
|
279
|
+
|
|
280
|
+
reducedCanvas.width = 0;
|
|
281
|
+
reducedCanvas.height = 0;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
draw() {
|
|
285
|
+
if (this.renderingState !== RenderingStates.INITIAL) {
|
|
286
|
+
console.error("Must be in new state before drawing");
|
|
287
|
+
return Promise.resolve(undefined);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const {
|
|
291
|
+
pdfPage
|
|
292
|
+
} = this;
|
|
293
|
+
|
|
294
|
+
if (!pdfPage) {
|
|
295
|
+
this.renderingState = RenderingStates.FINISHED;
|
|
296
|
+
return Promise.reject(new Error("pdfPage is not loaded"));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
this.renderingState = RenderingStates.RUNNING;
|
|
300
|
+
|
|
301
|
+
const finishRenderTask = async (error = null) => {
|
|
302
|
+
// The renderTask may have been replaced by a new one, so only remove
|
|
303
|
+
// the reference to the renderTask if it matches the one that is
|
|
304
|
+
// triggering this callback.
|
|
305
|
+
if (renderTask === this.renderTask) {
|
|
306
|
+
this.renderTask = null;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (error instanceof RenderingCancelledException) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
this.renderingState = RenderingStates.FINISHED;
|
|
314
|
+
|
|
315
|
+
this._convertCanvasToImage(canvas);
|
|
316
|
+
|
|
317
|
+
if (error) {
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
}; // Render the thumbnail at a larger size and downsize the canvas (similar
|
|
321
|
+
// to `setImage`), to improve consistency between thumbnails created by
|
|
322
|
+
// the `draw` and `setImage` methods (fixes issue 8233).
|
|
323
|
+
// NOTE: To primarily avoid increasing memory usage too much, but also to
|
|
324
|
+
// reduce downsizing overhead, we purposely limit the up-scaling factor.
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
const {
|
|
328
|
+
ctx,
|
|
329
|
+
canvas,
|
|
330
|
+
transform
|
|
331
|
+
} = this._getPageDrawContext(DRAW_UPSCALE_FACTOR);
|
|
332
|
+
|
|
333
|
+
const drawViewport = this.viewport.clone({
|
|
334
|
+
scale: DRAW_UPSCALE_FACTOR * this.scale
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
const renderContinueCallback = cont => {
|
|
338
|
+
if (!this.renderingQueue.isHighestPriority(this)) {
|
|
339
|
+
this.renderingState = RenderingStates.PAUSED;
|
|
340
|
+
|
|
341
|
+
this.resume = () => {
|
|
342
|
+
this.renderingState = RenderingStates.RUNNING;
|
|
343
|
+
cont();
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
cont();
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
const renderContext = {
|
|
353
|
+
canvasContext: ctx,
|
|
354
|
+
transform,
|
|
355
|
+
viewport: drawViewport,
|
|
356
|
+
optionalContentConfigPromise: this._optionalContentConfigPromise
|
|
357
|
+
};
|
|
358
|
+
const renderTask = this.renderTask = pdfPage.render(renderContext);
|
|
359
|
+
renderTask.onContinue = renderContinueCallback;
|
|
360
|
+
const resultPromise = renderTask.promise.then(function () {
|
|
361
|
+
return finishRenderTask(null);
|
|
362
|
+
}, function (error) {
|
|
363
|
+
return finishRenderTask(error);
|
|
364
|
+
});
|
|
365
|
+
resultPromise.finally(() => {
|
|
366
|
+
// Zeroing the width and height causes Firefox to release graphics
|
|
367
|
+
// resources immediately, which can greatly reduce memory consumption.
|
|
368
|
+
canvas.width = 0;
|
|
369
|
+
canvas.height = 0; // Only trigger cleanup, once rendering has finished, when the current
|
|
370
|
+
// pageView is *not* cached on the `BaseViewer`-instance.
|
|
371
|
+
|
|
372
|
+
const pageCached = this.linkService.isPageCached(this.id);
|
|
373
|
+
|
|
374
|
+
if (!pageCached) {
|
|
375
|
+
var _this$pdfPage;
|
|
376
|
+
|
|
377
|
+
(_this$pdfPage = this.pdfPage) === null || _this$pdfPage === void 0 ? void 0 : _this$pdfPage.cleanup();
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
return resultPromise;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
setImage(pageView) {
|
|
384
|
+
if (this._checkSetImageDisabled()) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (this.renderingState !== RenderingStates.INITIAL) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const {
|
|
393
|
+
canvas,
|
|
394
|
+
pdfPage
|
|
395
|
+
} = pageView;
|
|
396
|
+
|
|
397
|
+
if (!canvas) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (!this.pdfPage) {
|
|
402
|
+
this.setPdfPage(pdfPage);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
this.renderingState = RenderingStates.FINISHED;
|
|
406
|
+
|
|
407
|
+
this._convertCanvasToImage(canvas);
|
|
408
|
+
}
|
|
409
409
|
/**
|
|
410
410
|
* @private
|
|
411
|
-
*/
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
_reduceImage(img) {
|
|
415
|
-
const {
|
|
416
|
-
ctx,
|
|
417
|
-
canvas
|
|
418
|
-
} = this._getPageDrawContext();
|
|
419
|
-
|
|
420
|
-
if (img.width <= 2 * canvas.width) {
|
|
421
|
-
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
|
|
422
|
-
return canvas;
|
|
423
|
-
} // drawImage does an awful job of rescaling the image, doing it gradually.
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
|
|
427
|
-
let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
|
428
|
-
const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
|
429
|
-
|
|
430
|
-
while (reducedWidth > img.width || reducedHeight > img.height) {
|
|
431
|
-
reducedWidth >>= 1;
|
|
432
|
-
reducedHeight >>= 1;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
|
|
436
|
-
|
|
437
|
-
while (reducedWidth > 2 * canvas.width) {
|
|
438
|
-
reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
|
|
439
|
-
reducedWidth >>= 1;
|
|
440
|
-
reducedHeight >>= 1;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
|
|
444
|
-
return canvas;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
get _thumbPageTitle() {
|
|
448
|
-
var _this$pageLabel;
|
|
449
|
-
|
|
450
|
-
return this.l10n.get("thumb_page_title", {
|
|
451
|
-
page: (_this$pageLabel = this.pageLabel) !== null && _this$pageLabel !== void 0 ? _this$pageLabel : this.id
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
get _thumbPageCanvas() {
|
|
456
|
-
var _this$pageLabel2;
|
|
457
|
-
|
|
458
|
-
return this.l10n.get("thumb_page_canvas", {
|
|
459
|
-
page: (_this$pageLabel2 = this.pageLabel) !== null && _this$pageLabel2 !== void 0 ? _this$pageLabel2 : this.id
|
|
460
|
-
});
|
|
461
|
-
}
|
|
411
|
+
*/
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
_reduceImage(img) {
|
|
415
|
+
const {
|
|
416
|
+
ctx,
|
|
417
|
+
canvas
|
|
418
|
+
} = this._getPageDrawContext();
|
|
419
|
+
|
|
420
|
+
if (img.width <= 2 * canvas.width) {
|
|
421
|
+
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
|
|
422
|
+
return canvas;
|
|
423
|
+
} // drawImage does an awful job of rescaling the image, doing it gradually.
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
|
|
427
|
+
let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
|
428
|
+
const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
|
429
|
+
|
|
430
|
+
while (reducedWidth > img.width || reducedHeight > img.height) {
|
|
431
|
+
reducedWidth >>= 1;
|
|
432
|
+
reducedHeight >>= 1;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
|
|
436
|
+
|
|
437
|
+
while (reducedWidth > 2 * canvas.width) {
|
|
438
|
+
reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
|
|
439
|
+
reducedWidth >>= 1;
|
|
440
|
+
reducedHeight >>= 1;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
|
|
444
|
+
return canvas;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
get _thumbPageTitle() {
|
|
448
|
+
var _this$pageLabel;
|
|
449
|
+
|
|
450
|
+
return this.l10n.get("thumb_page_title", {
|
|
451
|
+
page: (_this$pageLabel = this.pageLabel) !== null && _this$pageLabel !== void 0 ? _this$pageLabel : this.id
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
get _thumbPageCanvas() {
|
|
456
|
+
var _this$pageLabel2;
|
|
457
|
+
|
|
458
|
+
return this.l10n.get("thumb_page_canvas", {
|
|
459
|
+
page: (_this$pageLabel2 = this.pageLabel) !== null && _this$pageLabel2 !== void 0 ? _this$pageLabel2 : this.id
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
462
|
/**
|
|
463
463
|
* @param {string|null} label
|
|
464
|
-
*/
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
setPageLabel(label) {
|
|
468
|
-
this.pageLabel = typeof label === "string" ? label : null;
|
|
469
|
-
|
|
470
|
-
this._thumbPageTitle.then(msg => {
|
|
471
|
-
this.anchor.title = msg;
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
this._thumbPageCanvas.then(msg => {
|
|
479
|
-
var _this$image;
|
|
480
|
-
|
|
481
|
-
(_this$image = this.image) === null || _this$image === void 0 ? void 0 : _this$image.setAttribute("aria-label", msg);
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
|
|
464
|
+
*/
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
setPageLabel(label) {
|
|
468
|
+
this.pageLabel = typeof label === "string" ? label : null;
|
|
469
|
+
|
|
470
|
+
this._thumbPageTitle.then(msg => {
|
|
471
|
+
this.anchor.title = msg;
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
this._thumbPageCanvas.then(msg => {
|
|
479
|
+
var _this$image;
|
|
480
|
+
|
|
481
|
+
(_this$image = this.image) === null || _this$image === void 0 ? void 0 : _this$image.setAttribute("aria-label", msg);
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
}
|
|
486
|
+
|
|
487
487
|
/* Copyright 2012 Mozilla Foundation
|
|
488
488
|
*
|
|
489
489
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -497,9 +497,9 @@ class PDFThumbnailView {
|
|
|
497
497
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
498
498
|
* See the License for the specific language governing permissions and
|
|
499
499
|
* limitations under the License.
|
|
500
|
-
*/
|
|
501
|
-
const THUMBNAIL_SCROLL_MARGIN = -19;
|
|
502
|
-
const THUMBNAIL_SELECTED_CLASS = "selected";
|
|
500
|
+
*/
|
|
501
|
+
const THUMBNAIL_SCROLL_MARGIN = -19;
|
|
502
|
+
const THUMBNAIL_SELECTED_CLASS = "selected";
|
|
503
503
|
/**
|
|
504
504
|
* @typedef {Object} PDFThumbnailViewerOptions
|
|
505
505
|
* @property {HTMLDivElement} container - The container for the thumbnail
|
|
@@ -508,312 +508,312 @@ const THUMBNAIL_SELECTED_CLASS = "selected";
|
|
|
508
508
|
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
|
509
509
|
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
|
510
510
|
* @property {IL10n} l10n - Localization service.
|
|
511
|
-
*/
|
|
512
|
-
|
|
511
|
+
*/
|
|
512
|
+
|
|
513
513
|
/**
|
|
514
514
|
* Viewer control to display thumbnails for pages in a PDF document.
|
|
515
515
|
*
|
|
516
516
|
* @implements {IRenderableView}
|
|
517
|
-
*/
|
|
518
|
-
|
|
519
|
-
class PDFThumbnailViewer {
|
|
517
|
+
*/
|
|
518
|
+
|
|
519
|
+
class PDFThumbnailViewer {
|
|
520
520
|
/**
|
|
521
521
|
* @param {PDFThumbnailViewerOptions} options
|
|
522
|
-
*/
|
|
523
|
-
constructor({
|
|
524
|
-
container,
|
|
525
|
-
eventBus,
|
|
526
|
-
linkService,
|
|
527
|
-
renderingQueue,
|
|
528
|
-
l10n
|
|
529
|
-
}) {
|
|
530
|
-
this.container = container;
|
|
531
|
-
this.linkService = linkService;
|
|
532
|
-
this.renderingQueue = renderingQueue;
|
|
533
|
-
this.l10n = l10n;
|
|
534
|
-
this.scroll = watchScroll(this.container, this._scrollUpdated.bind(this));
|
|
535
|
-
|
|
536
|
-
this._resetView();
|
|
537
|
-
|
|
538
|
-
eventBus._on("optionalcontentconfigchanged", () => {
|
|
539
|
-
// Ensure that the thumbnails always render with the *default* optional
|
|
540
|
-
// content configuration.
|
|
541
|
-
this._setImageDisabled = true;
|
|
542
|
-
});
|
|
543
|
-
}
|
|
522
|
+
*/
|
|
523
|
+
constructor({
|
|
524
|
+
container,
|
|
525
|
+
eventBus,
|
|
526
|
+
linkService,
|
|
527
|
+
renderingQueue,
|
|
528
|
+
l10n
|
|
529
|
+
}) {
|
|
530
|
+
this.container = container;
|
|
531
|
+
this.linkService = linkService;
|
|
532
|
+
this.renderingQueue = renderingQueue;
|
|
533
|
+
this.l10n = l10n;
|
|
534
|
+
this.scroll = watchScroll(this.container, this._scrollUpdated.bind(this));
|
|
535
|
+
|
|
536
|
+
this._resetView();
|
|
537
|
+
|
|
538
|
+
eventBus._on("optionalcontentconfigchanged", () => {
|
|
539
|
+
// Ensure that the thumbnails always render with the *default* optional
|
|
540
|
+
// content configuration.
|
|
541
|
+
this._setImageDisabled = true;
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
544
|
/**
|
|
545
545
|
* @private
|
|
546
|
-
*/
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
_scrollUpdated() {
|
|
550
|
-
this.renderingQueue.renderHighestPriority();
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
getThumbnail(index) {
|
|
554
|
-
return this._thumbnails[index];
|
|
555
|
-
}
|
|
546
|
+
*/
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
_scrollUpdated() {
|
|
550
|
+
this.renderingQueue.renderHighestPriority();
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
getThumbnail(index) {
|
|
554
|
+
return this._thumbnails[index];
|
|
555
|
+
}
|
|
556
556
|
/**
|
|
557
557
|
* @private
|
|
558
|
-
*/
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
_getVisibleThumbs() {
|
|
562
|
-
return getVisibleElements({
|
|
563
|
-
scrollEl: this.container,
|
|
564
|
-
views: this._thumbnails
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
scrollThumbnailIntoView(pageNumber) {
|
|
569
|
-
if (!this.pdfDocument) {
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
const thumbnailView = this._thumbnails[pageNumber - 1];
|
|
574
|
-
|
|
575
|
-
if (!thumbnailView) {
|
|
576
|
-
console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
if (pageNumber !== this._currentPageNumber) {
|
|
581
|
-
const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1]; // Remove the highlight from the previous thumbnail...
|
|
582
|
-
|
|
583
|
-
prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS); // ... and add the highlight to the new thumbnail.
|
|
584
|
-
|
|
585
|
-
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
const visibleThumbs = this._getVisibleThumbs();
|
|
589
|
-
|
|
590
|
-
const numVisibleThumbs = visibleThumbs.views.length; // If the thumbnail isn't currently visible, scroll it into view.
|
|
591
|
-
|
|
592
|
-
if (numVisibleThumbs > 0) {
|
|
593
|
-
const first = visibleThumbs.first.id; // Account for only one thumbnail being visible.
|
|
594
|
-
|
|
595
|
-
const last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
|
|
596
|
-
let shouldScroll = false;
|
|
597
|
-
|
|
598
|
-
if (pageNumber <= first || pageNumber >= last) {
|
|
599
|
-
shouldScroll = true;
|
|
600
|
-
} else {
|
|
601
|
-
visibleThumbs.views.some(function (view) {
|
|
602
|
-
if (view.id !== pageNumber) {
|
|
603
|
-
return false;
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
shouldScroll = view.percent < 100;
|
|
607
|
-
return true;
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
if (shouldScroll) {
|
|
612
|
-
scrollIntoView(thumbnailView.div, {
|
|
613
|
-
top: THUMBNAIL_SCROLL_MARGIN
|
|
614
|
-
});
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
this._currentPageNumber = pageNumber;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
get pagesRotation() {
|
|
622
|
-
return this._pagesRotation;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
set pagesRotation(rotation) {
|
|
626
|
-
if (!isValidRotation(rotation)) {
|
|
627
|
-
throw new Error("Invalid thumbnails rotation angle.");
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
if (!this.pdfDocument) {
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
if (this._pagesRotation === rotation) {
|
|
635
|
-
return; // The rotation didn't change.
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
this._pagesRotation = rotation;
|
|
639
|
-
|
|
640
|
-
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
|
641
|
-
this._thumbnails[i].update(rotation);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
cleanup() {
|
|
646
|
-
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
|
647
|
-
if (this._thumbnails[i] && this._thumbnails[i].renderingState !== RenderingStates.FINISHED) {
|
|
648
|
-
this._thumbnails[i].reset();
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
TempImageFactory.destroyCanvas();
|
|
653
|
-
}
|
|
558
|
+
*/
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
_getVisibleThumbs() {
|
|
562
|
+
return getVisibleElements({
|
|
563
|
+
scrollEl: this.container,
|
|
564
|
+
views: this._thumbnails
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
scrollThumbnailIntoView(pageNumber) {
|
|
569
|
+
if (!this.pdfDocument) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
const thumbnailView = this._thumbnails[pageNumber - 1];
|
|
574
|
+
|
|
575
|
+
if (!thumbnailView) {
|
|
576
|
+
console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (pageNumber !== this._currentPageNumber) {
|
|
581
|
+
const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1]; // Remove the highlight from the previous thumbnail...
|
|
582
|
+
|
|
583
|
+
prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS); // ... and add the highlight to the new thumbnail.
|
|
584
|
+
|
|
585
|
+
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const visibleThumbs = this._getVisibleThumbs();
|
|
589
|
+
|
|
590
|
+
const numVisibleThumbs = visibleThumbs.views.length; // If the thumbnail isn't currently visible, scroll it into view.
|
|
591
|
+
|
|
592
|
+
if (numVisibleThumbs > 0) {
|
|
593
|
+
const first = visibleThumbs.first.id; // Account for only one thumbnail being visible.
|
|
594
|
+
|
|
595
|
+
const last = numVisibleThumbs > 1 ? visibleThumbs.last.id : first;
|
|
596
|
+
let shouldScroll = false;
|
|
597
|
+
|
|
598
|
+
if (pageNumber <= first || pageNumber >= last) {
|
|
599
|
+
shouldScroll = true;
|
|
600
|
+
} else {
|
|
601
|
+
visibleThumbs.views.some(function (view) {
|
|
602
|
+
if (view.id !== pageNumber) {
|
|
603
|
+
return false;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
shouldScroll = view.percent < 100;
|
|
607
|
+
return true;
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
if (shouldScroll) {
|
|
612
|
+
scrollIntoView(thumbnailView.div, {
|
|
613
|
+
top: THUMBNAIL_SCROLL_MARGIN
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
this._currentPageNumber = pageNumber;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
get pagesRotation() {
|
|
622
|
+
return this._pagesRotation;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
set pagesRotation(rotation) {
|
|
626
|
+
if (!isValidRotation(rotation)) {
|
|
627
|
+
throw new Error("Invalid thumbnails rotation angle.");
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
if (!this.pdfDocument) {
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
if (this._pagesRotation === rotation) {
|
|
635
|
+
return; // The rotation didn't change.
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
this._pagesRotation = rotation;
|
|
639
|
+
|
|
640
|
+
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
|
641
|
+
this._thumbnails[i].update(rotation);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
cleanup() {
|
|
646
|
+
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
|
647
|
+
if (this._thumbnails[i] && this._thumbnails[i].renderingState !== RenderingStates.FINISHED) {
|
|
648
|
+
this._thumbnails[i].reset();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
TempImageFactory.destroyCanvas();
|
|
653
|
+
}
|
|
654
654
|
/**
|
|
655
655
|
* @private
|
|
656
|
-
*/
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
_resetView() {
|
|
660
|
-
this._thumbnails = [];
|
|
661
|
-
this._currentPageNumber = 1;
|
|
662
|
-
this._pageLabels = null;
|
|
663
|
-
this._pagesRotation = 0;
|
|
664
|
-
this._optionalContentConfigPromise = null;
|
|
665
|
-
this._pagesRequests = new WeakMap();
|
|
666
|
-
this._setImageDisabled = false; // Remove the thumbnails from the DOM.
|
|
667
|
-
|
|
668
|
-
this.container.textContent = "";
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
setDocument(pdfDocument) {
|
|
672
|
-
if (this.pdfDocument) {
|
|
673
|
-
this._cancelRendering();
|
|
674
|
-
|
|
675
|
-
this._resetView();
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
this.pdfDocument = pdfDocument;
|
|
679
|
-
|
|
680
|
-
if (!pdfDocument) {
|
|
681
|
-
return;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
const firstPagePromise = pdfDocument.getPage(1);
|
|
685
|
-
const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
|
|
686
|
-
firstPagePromise.then(firstPdfPage => {
|
|
687
|
-
this._optionalContentConfigPromise = optionalContentConfigPromise;
|
|
688
|
-
const pagesCount = pdfDocument.numPages;
|
|
689
|
-
const viewport = firstPdfPage.getViewport({
|
|
690
|
-
scale: 1
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
const checkSetImageDisabled = () => {
|
|
694
|
-
return this._setImageDisabled;
|
|
695
|
-
};
|
|
696
|
-
|
|
697
|
-
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
|
698
|
-
const thumbnail = new PDFThumbnailView({
|
|
699
|
-
container: this.container,
|
|
700
|
-
id: pageNum,
|
|
701
|
-
defaultViewport: viewport.clone(),
|
|
702
|
-
optionalContentConfigPromise,
|
|
703
|
-
linkService: this.linkService,
|
|
704
|
-
renderingQueue: this.renderingQueue,
|
|
705
|
-
checkSetImageDisabled,
|
|
706
|
-
l10n: this.l10n
|
|
707
|
-
});
|
|
708
|
-
|
|
709
|
-
this._thumbnails.push(thumbnail);
|
|
710
|
-
} // Set the first `pdfPage` immediately, since it's already loaded,
|
|
711
|
-
// rather than having to repeat the `PDFDocumentProxy.getPage` call in
|
|
712
|
-
// the `this._ensurePdfPageLoaded` method before rendering can start.
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
const firstThumbnailView = this._thumbnails[0];
|
|
716
|
-
|
|
717
|
-
if (firstThumbnailView) {
|
|
718
|
-
firstThumbnailView.setPdfPage(firstPdfPage);
|
|
719
|
-
} // Ensure that the current thumbnail is always highlighted on load.
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
|
|
723
|
-
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
|
724
|
-
}).catch(reason => {
|
|
725
|
-
console.error("Unable to initialize thumbnail viewer", reason);
|
|
726
|
-
});
|
|
727
|
-
}
|
|
656
|
+
*/
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
_resetView() {
|
|
660
|
+
this._thumbnails = [];
|
|
661
|
+
this._currentPageNumber = 1;
|
|
662
|
+
this._pageLabels = null;
|
|
663
|
+
this._pagesRotation = 0;
|
|
664
|
+
this._optionalContentConfigPromise = null;
|
|
665
|
+
this._pagesRequests = new WeakMap();
|
|
666
|
+
this._setImageDisabled = false; // Remove the thumbnails from the DOM.
|
|
667
|
+
|
|
668
|
+
this.container.textContent = "";
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
setDocument(pdfDocument) {
|
|
672
|
+
if (this.pdfDocument) {
|
|
673
|
+
this._cancelRendering();
|
|
674
|
+
|
|
675
|
+
this._resetView();
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
this.pdfDocument = pdfDocument;
|
|
679
|
+
|
|
680
|
+
if (!pdfDocument) {
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const firstPagePromise = pdfDocument.getPage(1);
|
|
685
|
+
const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();
|
|
686
|
+
firstPagePromise.then(firstPdfPage => {
|
|
687
|
+
this._optionalContentConfigPromise = optionalContentConfigPromise;
|
|
688
|
+
const pagesCount = pdfDocument.numPages;
|
|
689
|
+
const viewport = firstPdfPage.getViewport({
|
|
690
|
+
scale: 1
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
const checkSetImageDisabled = () => {
|
|
694
|
+
return this._setImageDisabled;
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
|
698
|
+
const thumbnail = new PDFThumbnailView({
|
|
699
|
+
container: this.container,
|
|
700
|
+
id: pageNum,
|
|
701
|
+
defaultViewport: viewport.clone(),
|
|
702
|
+
optionalContentConfigPromise,
|
|
703
|
+
linkService: this.linkService,
|
|
704
|
+
renderingQueue: this.renderingQueue,
|
|
705
|
+
checkSetImageDisabled,
|
|
706
|
+
l10n: this.l10n
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
this._thumbnails.push(thumbnail);
|
|
710
|
+
} // Set the first `pdfPage` immediately, since it's already loaded,
|
|
711
|
+
// rather than having to repeat the `PDFDocumentProxy.getPage` call in
|
|
712
|
+
// the `this._ensurePdfPageLoaded` method before rendering can start.
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
const firstThumbnailView = this._thumbnails[0];
|
|
716
|
+
|
|
717
|
+
if (firstThumbnailView) {
|
|
718
|
+
firstThumbnailView.setPdfPage(firstPdfPage);
|
|
719
|
+
} // Ensure that the current thumbnail is always highlighted on load.
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
|
|
723
|
+
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
|
724
|
+
}).catch(reason => {
|
|
725
|
+
console.error("Unable to initialize thumbnail viewer", reason);
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
728
|
/**
|
|
729
729
|
* @private
|
|
730
|
-
*/
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
_cancelRendering() {
|
|
734
|
-
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
|
735
|
-
if (this._thumbnails[i]) {
|
|
736
|
-
this._thumbnails[i].cancelRendering();
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}
|
|
730
|
+
*/
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
_cancelRendering() {
|
|
734
|
+
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
|
735
|
+
if (this._thumbnails[i]) {
|
|
736
|
+
this._thumbnails[i].cancelRendering();
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
740
|
/**
|
|
741
741
|
* @param {Array|null} labels
|
|
742
|
-
*/
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
setPageLabels(labels) {
|
|
746
|
-
if (!this.pdfDocument) {
|
|
747
|
-
return;
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
if (!labels) {
|
|
751
|
-
this._pageLabels = null;
|
|
752
|
-
} else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
|
|
753
|
-
this._pageLabels = null;
|
|
754
|
-
console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
|
|
755
|
-
} else {
|
|
756
|
-
this._pageLabels = labels;
|
|
757
|
-
} // Update all the `PDFThumbnailView` instances.
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
|
761
|
-
var _this$_pageLabels$i, _this$_pageLabels;
|
|
762
|
-
|
|
763
|
-
this._thumbnails[i].setPageLabel((_this$_pageLabels$i = (_this$_pageLabels = this._pageLabels) === null || _this$_pageLabels === void 0 ? void 0 : _this$_pageLabels[i]) !== null && _this$_pageLabels$i !== void 0 ? _this$_pageLabels$i : null);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
742
|
+
*/
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
setPageLabels(labels) {
|
|
746
|
+
if (!this.pdfDocument) {
|
|
747
|
+
return;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
if (!labels) {
|
|
751
|
+
this._pageLabels = null;
|
|
752
|
+
} else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
|
|
753
|
+
this._pageLabels = null;
|
|
754
|
+
console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
|
|
755
|
+
} else {
|
|
756
|
+
this._pageLabels = labels;
|
|
757
|
+
} // Update all the `PDFThumbnailView` instances.
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
|
761
|
+
var _this$_pageLabels$i, _this$_pageLabels;
|
|
762
|
+
|
|
763
|
+
this._thumbnails[i].setPageLabel((_this$_pageLabels$i = (_this$_pageLabels = this._pageLabels) === null || _this$_pageLabels === void 0 ? void 0 : _this$_pageLabels[i]) !== null && _this$_pageLabels$i !== void 0 ? _this$_pageLabels$i : null);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
766
|
/**
|
|
767
767
|
* @param {PDFThumbnailView} thumbView
|
|
768
768
|
* @returns {PDFPage}
|
|
769
769
|
* @private
|
|
770
|
-
*/
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
_ensurePdfPageLoaded(thumbView) {
|
|
774
|
-
if (thumbView.pdfPage) {
|
|
775
|
-
return Promise.resolve(thumbView.pdfPage);
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
if (this._pagesRequests.has(thumbView)) {
|
|
779
|
-
return this._pagesRequests.get(thumbView);
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
const promise = this.pdfDocument.getPage(thumbView.id).then(pdfPage => {
|
|
783
|
-
if (!thumbView.pdfPage) {
|
|
784
|
-
thumbView.setPdfPage(pdfPage);
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
this._pagesRequests.delete(thumbView);
|
|
788
|
-
|
|
789
|
-
return pdfPage;
|
|
790
|
-
}).catch(reason => {
|
|
791
|
-
console.error("Unable to get page for thumb view", reason); // Page error -- there is nothing that can be done.
|
|
792
|
-
|
|
793
|
-
this._pagesRequests.delete(thumbView);
|
|
794
|
-
});
|
|
795
|
-
|
|
796
|
-
this._pagesRequests.set(thumbView, promise);
|
|
797
|
-
|
|
798
|
-
return promise;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
forceRendering() {
|
|
802
|
-
const visibleThumbs = this._getVisibleThumbs();
|
|
803
|
-
|
|
804
|
-
const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, this.scroll.down);
|
|
805
|
-
|
|
806
|
-
if (thumbView) {
|
|
807
|
-
this._ensurePdfPageLoaded(thumbView).then(() => {
|
|
808
|
-
this.renderingQueue.renderView(thumbView);
|
|
809
|
-
});
|
|
810
|
-
|
|
811
|
-
return true;
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
return false;
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
export { PDFThumbnailViewer };
|
|
770
|
+
*/
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
_ensurePdfPageLoaded(thumbView) {
|
|
774
|
+
if (thumbView.pdfPage) {
|
|
775
|
+
return Promise.resolve(thumbView.pdfPage);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (this._pagesRequests.has(thumbView)) {
|
|
779
|
+
return this._pagesRequests.get(thumbView);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
const promise = this.pdfDocument.getPage(thumbView.id).then(pdfPage => {
|
|
783
|
+
if (!thumbView.pdfPage) {
|
|
784
|
+
thumbView.setPdfPage(pdfPage);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
this._pagesRequests.delete(thumbView);
|
|
788
|
+
|
|
789
|
+
return pdfPage;
|
|
790
|
+
}).catch(reason => {
|
|
791
|
+
console.error("Unable to get page for thumb view", reason); // Page error -- there is nothing that can be done.
|
|
792
|
+
|
|
793
|
+
this._pagesRequests.delete(thumbView);
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
this._pagesRequests.set(thumbView, promise);
|
|
797
|
+
|
|
798
|
+
return promise;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
forceRendering() {
|
|
802
|
+
const visibleThumbs = this._getVisibleThumbs();
|
|
803
|
+
|
|
804
|
+
const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, this.scroll.down);
|
|
805
|
+
|
|
806
|
+
if (thumbView) {
|
|
807
|
+
this._ensurePdfPageLoaded(thumbView).then(() => {
|
|
808
|
+
this.renderingQueue.renderView(thumbView);
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
return true;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
return false;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
export { PDFThumbnailViewer };
|