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