@vaadin-component-factory/vcf-pdf-viewer 4.0.2 → 4.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/LICENSE +190 -190
- package/README.md +35 -35
- package/custom-elements.json +664 -0
- package/package.json +118 -83
- package/pdfjs/dist/event_utils.js +207 -0
- package/pdfjs/dist/genericl10n.js +2420 -0
- package/pdfjs/dist/message_handler.js +704 -569
- package/pdfjs/dist/node_stream.js +2 -494
- package/pdfjs/dist/node_stream2.js +1759 -0
- package/pdfjs/dist/pdf.js +20927 -12778
- package/pdfjs/dist/pdf.worker.js +24 -0
- package/pdfjs/dist/pdf_link_service.js +483 -638
- package/pdfjs/dist/pdf_rendering_queue.js +199 -199
- package/pdfjs/dist/pdf_thumbnail_viewer.js +636 -819
- package/pdfjs/dist/pdf_viewer.js +4743 -3598
- package/pdfjs/dist/ui_utils.js +762 -1033
- package/pdfjs/dist/util.js +855 -1066
- package/pdfjs/dist/worker.js +61967 -62813
- package/src/vcf-pdf-viewer.d.ts +247 -0
- package/src/vcf-pdf-viewer.js +1214 -1072
- package/theme/base/vcf-pdf-viewer-styles.js +144 -144
- package/theme/base/vcf-pdf-viewer-toolbar-icons-styles.js +39 -39
- package/theme/base/vcf-pdf-viewer.d.ts +6 -0
- package/theme/base/vcf-pdf-viewer.js +2 -2
- package/vcf-pdf-viewer.d.ts +6 -0
- package/vcf-pdf-viewer.js +2 -2
- package/pdfjs/dist/display_utils.js +0 -848
- package/pdfjs/dist/fetch_stream.js +0 -306
- package/pdfjs/dist/l10n_utils.js +0 -140
- package/pdfjs/dist/network.js +0 -565
- package/pdfjs/dist/network_utils.js +0 -340
|
@@ -1,819 +1,636 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import './pdf.js';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import './
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const DRAW_UPSCALE_FACTOR = 2; // See comment in `PDFThumbnailView.draw` below.
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* @
|
|
31
|
-
* @property {
|
|
32
|
-
* @property {
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @property {
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
this.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.
|
|
116
|
-
this.
|
|
117
|
-
this
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
this.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
this.
|
|
154
|
-
div.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
296
|
-
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
this.
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
ctx,
|
|
329
|
-
canvas
|
|
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
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
this.
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
return;
|
|
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
|
-
if (
|
|
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
|
-
}
|
|
654
|
-
/**
|
|
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
|
-
}
|
|
728
|
-
/**
|
|
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
|
-
}
|
|
740
|
-
/**
|
|
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
|
-
}
|
|
766
|
-
/**
|
|
767
|
-
* @param {PDFThumbnailView} thumbView
|
|
768
|
-
* @returns {PDFPage}
|
|
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 };
|
|
1
|
+
import { RenderingStates, OutputScale, watchScroll, getVisibleElements, scrollIntoView, isValidRotation } from './ui_utils.js';
|
|
2
|
+
import './pdf.js';
|
|
3
|
+
import { R as RenderingCancelledException } from './node_stream2.js';
|
|
4
|
+
import './util.js';
|
|
5
|
+
import './message_handler.js';
|
|
6
|
+
|
|
7
|
+
/* Copyright 2012 Mozilla Foundation
|
|
8
|
+
*
|
|
9
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License.
|
|
11
|
+
* You may obtain a copy of the License at
|
|
12
|
+
*
|
|
13
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
* See the License for the specific language governing permissions and
|
|
19
|
+
* limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const DRAW_UPSCALE_FACTOR = 2; // See comment in `PDFThumbnailView.draw` below.
|
|
23
|
+
const MAX_NUM_SCALING_STEPS = 3;
|
|
24
|
+
const THUMBNAIL_WIDTH = 98; // px
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {Object} PDFThumbnailViewOptions
|
|
28
|
+
* @property {HTMLDivElement} container - The viewer element.
|
|
29
|
+
* @property {EventBus} eventBus - The application event bus.
|
|
30
|
+
* @property {number} id - The thumbnail's unique ID (normally its number).
|
|
31
|
+
* @property {PageViewport} defaultViewport - The page viewport.
|
|
32
|
+
* @property {Promise<OptionalContentConfig>} [optionalContentConfigPromise] -
|
|
33
|
+
* A promise that is resolved with an {@link OptionalContentConfig} instance.
|
|
34
|
+
* The default value is `null`.
|
|
35
|
+
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
|
36
|
+
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
|
37
|
+
* @property {Object} [pageColors] - Overwrites background and foreground colors
|
|
38
|
+
* with user defined ones in order to improve readability in high contrast
|
|
39
|
+
* mode.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
class TempImageFactory {
|
|
43
|
+
static #tempCanvas = null;
|
|
44
|
+
static getCanvas(width, height) {
|
|
45
|
+
const tempCanvas = this.#tempCanvas || (this.#tempCanvas = document.createElement("canvas"));
|
|
46
|
+
tempCanvas.width = width;
|
|
47
|
+
tempCanvas.height = height;
|
|
48
|
+
|
|
49
|
+
// Since this is a temporary canvas, we need to fill it with a white
|
|
50
|
+
// background ourselves. `#getPageDrawContext` uses CSS rules for this.
|
|
51
|
+
const ctx = tempCanvas.getContext("2d", {
|
|
52
|
+
alpha: false
|
|
53
|
+
});
|
|
54
|
+
ctx.save();
|
|
55
|
+
ctx.fillStyle = "rgb(255, 255, 255)";
|
|
56
|
+
ctx.fillRect(0, 0, width, height);
|
|
57
|
+
ctx.restore();
|
|
58
|
+
return [tempCanvas, tempCanvas.getContext("2d")];
|
|
59
|
+
}
|
|
60
|
+
static destroyCanvas() {
|
|
61
|
+
const tempCanvas = this.#tempCanvas;
|
|
62
|
+
if (tempCanvas) {
|
|
63
|
+
// Zeroing the width and height causes Firefox to release graphics
|
|
64
|
+
// resources immediately, which can greatly reduce memory consumption.
|
|
65
|
+
tempCanvas.width = 0;
|
|
66
|
+
tempCanvas.height = 0;
|
|
67
|
+
}
|
|
68
|
+
this.#tempCanvas = null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @implements {IRenderableView}
|
|
74
|
+
*/
|
|
75
|
+
class PDFThumbnailView {
|
|
76
|
+
/**
|
|
77
|
+
* @param {PDFThumbnailViewOptions} options
|
|
78
|
+
*/
|
|
79
|
+
constructor({
|
|
80
|
+
container,
|
|
81
|
+
eventBus,
|
|
82
|
+
id,
|
|
83
|
+
defaultViewport,
|
|
84
|
+
optionalContentConfigPromise,
|
|
85
|
+
linkService,
|
|
86
|
+
renderingQueue,
|
|
87
|
+
pageColors
|
|
88
|
+
}) {
|
|
89
|
+
this.id = id;
|
|
90
|
+
this.renderingId = "thumbnail" + id;
|
|
91
|
+
this.pageLabel = null;
|
|
92
|
+
this.pdfPage = null;
|
|
93
|
+
this.rotation = 0;
|
|
94
|
+
this.viewport = defaultViewport;
|
|
95
|
+
this.pdfPageRotate = defaultViewport.rotation;
|
|
96
|
+
this._optionalContentConfigPromise = optionalContentConfigPromise || null;
|
|
97
|
+
this.pageColors = pageColors || null;
|
|
98
|
+
this.eventBus = eventBus;
|
|
99
|
+
this.linkService = linkService;
|
|
100
|
+
this.renderingQueue = renderingQueue;
|
|
101
|
+
this.renderTask = null;
|
|
102
|
+
this.renderingState = RenderingStates.INITIAL;
|
|
103
|
+
this.resume = null;
|
|
104
|
+
const anchor = document.createElement("a");
|
|
105
|
+
anchor.href = linkService.getAnchorUrl("#page=" + id);
|
|
106
|
+
anchor.setAttribute("data-l10n-id", "pdfjs-thumb-page-title");
|
|
107
|
+
anchor.setAttribute("data-l10n-args", this.#pageL10nArgs);
|
|
108
|
+
anchor.onclick = function () {
|
|
109
|
+
linkService.goToPage(id);
|
|
110
|
+
return false;
|
|
111
|
+
};
|
|
112
|
+
this.anchor = anchor;
|
|
113
|
+
const div = document.createElement("div");
|
|
114
|
+
div.className = "thumbnail";
|
|
115
|
+
div.setAttribute("data-page-number", this.id);
|
|
116
|
+
this.div = div;
|
|
117
|
+
this.#updateDims();
|
|
118
|
+
const img = document.createElement("div");
|
|
119
|
+
img.className = "thumbnailImage";
|
|
120
|
+
this._placeholderImg = img;
|
|
121
|
+
div.append(img);
|
|
122
|
+
anchor.append(div);
|
|
123
|
+
container.append(anchor);
|
|
124
|
+
}
|
|
125
|
+
#updateDims() {
|
|
126
|
+
const {
|
|
127
|
+
width,
|
|
128
|
+
height
|
|
129
|
+
} = this.viewport;
|
|
130
|
+
const ratio = width / height;
|
|
131
|
+
this.canvasWidth = THUMBNAIL_WIDTH;
|
|
132
|
+
this.canvasHeight = this.canvasWidth / ratio | 0;
|
|
133
|
+
this.scale = this.canvasWidth / width;
|
|
134
|
+
const {
|
|
135
|
+
style
|
|
136
|
+
} = this.div;
|
|
137
|
+
style.setProperty("--thumbnail-width", `${this.canvasWidth}px`);
|
|
138
|
+
style.setProperty("--thumbnail-height", `${this.canvasHeight}px`);
|
|
139
|
+
}
|
|
140
|
+
setPdfPage(pdfPage) {
|
|
141
|
+
this.pdfPage = pdfPage;
|
|
142
|
+
this.pdfPageRotate = pdfPage.rotate;
|
|
143
|
+
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
|
144
|
+
this.viewport = pdfPage.getViewport({
|
|
145
|
+
scale: 1,
|
|
146
|
+
rotation: totalRotation
|
|
147
|
+
});
|
|
148
|
+
this.reset();
|
|
149
|
+
}
|
|
150
|
+
reset() {
|
|
151
|
+
var _this$image;
|
|
152
|
+
this.cancelRendering();
|
|
153
|
+
this.renderingState = RenderingStates.INITIAL;
|
|
154
|
+
this.div.removeAttribute("data-loaded");
|
|
155
|
+
(_this$image = this.image) === null || _this$image === void 0 ? void 0 : _this$image.replaceWith(this._placeholderImg);
|
|
156
|
+
this.#updateDims();
|
|
157
|
+
if (this.image) {
|
|
158
|
+
this.image.removeAttribute("src");
|
|
159
|
+
delete this.image;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
update({
|
|
163
|
+
rotation = null
|
|
164
|
+
}) {
|
|
165
|
+
if (typeof rotation === "number") {
|
|
166
|
+
this.rotation = rotation; // The rotation may be zero.
|
|
167
|
+
}
|
|
168
|
+
const totalRotation = (this.rotation + this.pdfPageRotate) % 360;
|
|
169
|
+
this.viewport = this.viewport.clone({
|
|
170
|
+
scale: 1,
|
|
171
|
+
rotation: totalRotation
|
|
172
|
+
});
|
|
173
|
+
this.reset();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* PLEASE NOTE: Most likely you want to use the `this.reset()` method,
|
|
178
|
+
* rather than calling this one directly.
|
|
179
|
+
*/
|
|
180
|
+
cancelRendering() {
|
|
181
|
+
if (this.renderTask) {
|
|
182
|
+
this.renderTask.cancel();
|
|
183
|
+
this.renderTask = null;
|
|
184
|
+
}
|
|
185
|
+
this.resume = null;
|
|
186
|
+
}
|
|
187
|
+
#getPageDrawContext(upscaleFactor = 1) {
|
|
188
|
+
// Keep the no-thumbnail outline visible, i.e. `data-loaded === false`,
|
|
189
|
+
// until rendering/image conversion is complete, to avoid display issues.
|
|
190
|
+
const canvas = document.createElement("canvas");
|
|
191
|
+
const ctx = canvas.getContext("2d", {
|
|
192
|
+
alpha: false
|
|
193
|
+
});
|
|
194
|
+
const outputScale = new OutputScale();
|
|
195
|
+
canvas.width = upscaleFactor * this.canvasWidth * outputScale.sx | 0;
|
|
196
|
+
canvas.height = upscaleFactor * this.canvasHeight * outputScale.sy | 0;
|
|
197
|
+
const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
|
|
198
|
+
return {
|
|
199
|
+
ctx,
|
|
200
|
+
canvas,
|
|
201
|
+
transform
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
#convertCanvasToImage(canvas) {
|
|
205
|
+
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
206
|
+
throw new Error("#convertCanvasToImage: Rendering has not finished.");
|
|
207
|
+
}
|
|
208
|
+
const reducedCanvas = this.#reduceImage(canvas);
|
|
209
|
+
const image = document.createElement("img");
|
|
210
|
+
image.className = "thumbnailImage";
|
|
211
|
+
image.setAttribute("data-l10n-id", "pdfjs-thumb-page-canvas");
|
|
212
|
+
image.setAttribute("data-l10n-args", this.#pageL10nArgs);
|
|
213
|
+
image.src = reducedCanvas.toDataURL();
|
|
214
|
+
this.image = image;
|
|
215
|
+
this.div.setAttribute("data-loaded", true);
|
|
216
|
+
this._placeholderImg.replaceWith(image);
|
|
217
|
+
|
|
218
|
+
// Zeroing the width and height causes Firefox to release graphics
|
|
219
|
+
// resources immediately, which can greatly reduce memory consumption.
|
|
220
|
+
reducedCanvas.width = 0;
|
|
221
|
+
reducedCanvas.height = 0;
|
|
222
|
+
}
|
|
223
|
+
async #finishRenderTask(renderTask, canvas, error = null) {
|
|
224
|
+
// The renderTask may have been replaced by a new one, so only remove
|
|
225
|
+
// the reference to the renderTask if it matches the one that is
|
|
226
|
+
// triggering this callback.
|
|
227
|
+
if (renderTask === this.renderTask) {
|
|
228
|
+
this.renderTask = null;
|
|
229
|
+
}
|
|
230
|
+
if (error instanceof RenderingCancelledException) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
this.renderingState = RenderingStates.FINISHED;
|
|
234
|
+
this.#convertCanvasToImage(canvas);
|
|
235
|
+
if (error) {
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
async draw() {
|
|
240
|
+
if (this.renderingState !== RenderingStates.INITIAL) {
|
|
241
|
+
console.error("Must be in new state before drawing");
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
const {
|
|
245
|
+
pdfPage
|
|
246
|
+
} = this;
|
|
247
|
+
if (!pdfPage) {
|
|
248
|
+
this.renderingState = RenderingStates.FINISHED;
|
|
249
|
+
throw new Error("pdfPage is not loaded");
|
|
250
|
+
}
|
|
251
|
+
this.renderingState = RenderingStates.RUNNING;
|
|
252
|
+
|
|
253
|
+
// Render the thumbnail at a larger size and downsize the canvas (similar
|
|
254
|
+
// to `setImage`), to improve consistency between thumbnails created by
|
|
255
|
+
// the `draw` and `setImage` methods (fixes issue 8233).
|
|
256
|
+
// NOTE: To primarily avoid increasing memory usage too much, but also to
|
|
257
|
+
// reduce downsizing overhead, we purposely limit the up-scaling factor.
|
|
258
|
+
const {
|
|
259
|
+
ctx,
|
|
260
|
+
canvas,
|
|
261
|
+
transform
|
|
262
|
+
} = this.#getPageDrawContext(DRAW_UPSCALE_FACTOR);
|
|
263
|
+
const drawViewport = this.viewport.clone({
|
|
264
|
+
scale: DRAW_UPSCALE_FACTOR * this.scale
|
|
265
|
+
});
|
|
266
|
+
const renderContinueCallback = cont => {
|
|
267
|
+
if (!this.renderingQueue.isHighestPriority(this)) {
|
|
268
|
+
this.renderingState = RenderingStates.PAUSED;
|
|
269
|
+
this.resume = () => {
|
|
270
|
+
this.renderingState = RenderingStates.RUNNING;
|
|
271
|
+
cont();
|
|
272
|
+
};
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
cont();
|
|
276
|
+
};
|
|
277
|
+
const renderContext = {
|
|
278
|
+
canvasContext: ctx,
|
|
279
|
+
transform,
|
|
280
|
+
viewport: drawViewport,
|
|
281
|
+
optionalContentConfigPromise: this._optionalContentConfigPromise,
|
|
282
|
+
pageColors: this.pageColors
|
|
283
|
+
};
|
|
284
|
+
const renderTask = this.renderTask = pdfPage.render(renderContext);
|
|
285
|
+
renderTask.onContinue = renderContinueCallback;
|
|
286
|
+
const resultPromise = renderTask.promise.then(() => this.#finishRenderTask(renderTask, canvas), error => this.#finishRenderTask(renderTask, canvas, error));
|
|
287
|
+
resultPromise.finally(() => {
|
|
288
|
+
// Zeroing the width and height causes Firefox to release graphics
|
|
289
|
+
// resources immediately, which can greatly reduce memory consumption.
|
|
290
|
+
canvas.width = 0;
|
|
291
|
+
canvas.height = 0;
|
|
292
|
+
this.eventBus.dispatch("thumbnailrendered", {
|
|
293
|
+
source: this,
|
|
294
|
+
pageNumber: this.id,
|
|
295
|
+
pdfPage: this.pdfPage
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
return resultPromise;
|
|
299
|
+
}
|
|
300
|
+
setImage(pageView) {
|
|
301
|
+
if (this.renderingState !== RenderingStates.INITIAL) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const {
|
|
305
|
+
thumbnailCanvas: canvas,
|
|
306
|
+
pdfPage,
|
|
307
|
+
scale
|
|
308
|
+
} = pageView;
|
|
309
|
+
if (!canvas) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (!this.pdfPage) {
|
|
313
|
+
this.setPdfPage(pdfPage);
|
|
314
|
+
}
|
|
315
|
+
if (scale < this.scale) {
|
|
316
|
+
// Avoid upscaling the image, since that makes the thumbnail look blurry.
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
this.renderingState = RenderingStates.FINISHED;
|
|
320
|
+
this.#convertCanvasToImage(canvas);
|
|
321
|
+
}
|
|
322
|
+
#reduceImage(img) {
|
|
323
|
+
const {
|
|
324
|
+
ctx,
|
|
325
|
+
canvas
|
|
326
|
+
} = this.#getPageDrawContext();
|
|
327
|
+
if (img.width <= 2 * canvas.width) {
|
|
328
|
+
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height);
|
|
329
|
+
return canvas;
|
|
330
|
+
}
|
|
331
|
+
// drawImage does an awful job of rescaling the image, doing it gradually.
|
|
332
|
+
let reducedWidth = canvas.width << MAX_NUM_SCALING_STEPS;
|
|
333
|
+
let reducedHeight = canvas.height << MAX_NUM_SCALING_STEPS;
|
|
334
|
+
const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight);
|
|
335
|
+
while (reducedWidth > img.width || reducedHeight > img.height) {
|
|
336
|
+
reducedWidth >>= 1;
|
|
337
|
+
reducedHeight >>= 1;
|
|
338
|
+
}
|
|
339
|
+
reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight);
|
|
340
|
+
while (reducedWidth > 2 * canvas.width) {
|
|
341
|
+
reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1);
|
|
342
|
+
reducedWidth >>= 1;
|
|
343
|
+
reducedHeight >>= 1;
|
|
344
|
+
}
|
|
345
|
+
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height);
|
|
346
|
+
return canvas;
|
|
347
|
+
}
|
|
348
|
+
get #pageL10nArgs() {
|
|
349
|
+
var _this$pageLabel;
|
|
350
|
+
return JSON.stringify({
|
|
351
|
+
page: (_this$pageLabel = this.pageLabel) !== null && _this$pageLabel !== void 0 ? _this$pageLabel : this.id
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* @param {string|null} label
|
|
357
|
+
*/
|
|
358
|
+
setPageLabel(label) {
|
|
359
|
+
var _this$image2;
|
|
360
|
+
this.pageLabel = typeof label === "string" ? label : null;
|
|
361
|
+
this.anchor.setAttribute("data-l10n-args", this.#pageL10nArgs);
|
|
362
|
+
if (this.renderingState !== RenderingStates.FINISHED) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
(_this$image2 = this.image) === null || _this$image2 === void 0 ? void 0 : _this$image2.setAttribute("data-l10n-args", this.#pageL10nArgs);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/* Copyright 2012 Mozilla Foundation
|
|
370
|
+
*
|
|
371
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
372
|
+
* you may not use this file except in compliance with the License.
|
|
373
|
+
* You may obtain a copy of the License at
|
|
374
|
+
*
|
|
375
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
376
|
+
*
|
|
377
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
378
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
379
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
380
|
+
* See the License for the specific language governing permissions and
|
|
381
|
+
* limitations under the License.
|
|
382
|
+
*/
|
|
383
|
+
|
|
384
|
+
const THUMBNAIL_SCROLL_MARGIN = -19;
|
|
385
|
+
const THUMBNAIL_SELECTED_CLASS = "selected";
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* @typedef {Object} PDFThumbnailViewerOptions
|
|
389
|
+
* @property {HTMLDivElement} container - The container for the thumbnail
|
|
390
|
+
* elements.
|
|
391
|
+
* @property {EventBus} eventBus - The application event bus.
|
|
392
|
+
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
|
393
|
+
* @property {PDFRenderingQueue} renderingQueue - The rendering queue object.
|
|
394
|
+
* @property {Object} [pageColors] - Overwrites background and foreground colors
|
|
395
|
+
* with user defined ones in order to improve readability in high contrast
|
|
396
|
+
* mode.
|
|
397
|
+
*/
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Viewer control to display thumbnails for pages in a PDF document.
|
|
401
|
+
*/
|
|
402
|
+
class PDFThumbnailViewer {
|
|
403
|
+
/**
|
|
404
|
+
* @param {PDFThumbnailViewerOptions} options
|
|
405
|
+
*/
|
|
406
|
+
constructor({
|
|
407
|
+
container,
|
|
408
|
+
eventBus,
|
|
409
|
+
linkService,
|
|
410
|
+
renderingQueue,
|
|
411
|
+
pageColors
|
|
412
|
+
}) {
|
|
413
|
+
this.container = container;
|
|
414
|
+
this.eventBus = eventBus;
|
|
415
|
+
this.linkService = linkService;
|
|
416
|
+
this.renderingQueue = renderingQueue;
|
|
417
|
+
this.pageColors = pageColors || null;
|
|
418
|
+
this.scroll = watchScroll(this.container, this.#scrollUpdated.bind(this));
|
|
419
|
+
this.#resetView();
|
|
420
|
+
}
|
|
421
|
+
#scrollUpdated() {
|
|
422
|
+
this.renderingQueue.renderHighestPriority();
|
|
423
|
+
}
|
|
424
|
+
getThumbnail(index) {
|
|
425
|
+
return this._thumbnails[index];
|
|
426
|
+
}
|
|
427
|
+
#getVisibleThumbs() {
|
|
428
|
+
return getVisibleElements({
|
|
429
|
+
scrollEl: this.container,
|
|
430
|
+
views: this._thumbnails
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
scrollThumbnailIntoView(pageNumber) {
|
|
434
|
+
if (!this.pdfDocument) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
const thumbnailView = this._thumbnails[pageNumber - 1];
|
|
438
|
+
if (!thumbnailView) {
|
|
439
|
+
console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.');
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (pageNumber !== this._currentPageNumber) {
|
|
443
|
+
const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1];
|
|
444
|
+
// Remove the highlight from the previous thumbnail...
|
|
445
|
+
prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS);
|
|
446
|
+
// ... and add the highlight to the new thumbnail.
|
|
447
|
+
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
|
448
|
+
}
|
|
449
|
+
const {
|
|
450
|
+
first,
|
|
451
|
+
last,
|
|
452
|
+
views
|
|
453
|
+
} = this.#getVisibleThumbs();
|
|
454
|
+
|
|
455
|
+
// If the thumbnail isn't currently visible, scroll it into view.
|
|
456
|
+
if (views.length > 0) {
|
|
457
|
+
let shouldScroll = false;
|
|
458
|
+
if (pageNumber <= first.id || pageNumber >= last.id) {
|
|
459
|
+
shouldScroll = true;
|
|
460
|
+
} else {
|
|
461
|
+
for (const {
|
|
462
|
+
id,
|
|
463
|
+
percent
|
|
464
|
+
} of views) {
|
|
465
|
+
if (id !== pageNumber) {
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
shouldScroll = percent < 100;
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (shouldScroll) {
|
|
473
|
+
scrollIntoView(thumbnailView.div, {
|
|
474
|
+
top: THUMBNAIL_SCROLL_MARGIN
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
this._currentPageNumber = pageNumber;
|
|
479
|
+
}
|
|
480
|
+
get pagesRotation() {
|
|
481
|
+
return this._pagesRotation;
|
|
482
|
+
}
|
|
483
|
+
set pagesRotation(rotation) {
|
|
484
|
+
if (!isValidRotation(rotation)) {
|
|
485
|
+
throw new Error("Invalid thumbnails rotation angle.");
|
|
486
|
+
}
|
|
487
|
+
if (!this.pdfDocument) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (this._pagesRotation === rotation) {
|
|
491
|
+
return; // The rotation didn't change.
|
|
492
|
+
}
|
|
493
|
+
this._pagesRotation = rotation;
|
|
494
|
+
const updateArgs = {
|
|
495
|
+
rotation
|
|
496
|
+
};
|
|
497
|
+
for (const thumbnail of this._thumbnails) {
|
|
498
|
+
thumbnail.update(updateArgs);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
cleanup() {
|
|
502
|
+
for (const thumbnail of this._thumbnails) {
|
|
503
|
+
if (thumbnail.renderingState !== RenderingStates.FINISHED) {
|
|
504
|
+
thumbnail.reset();
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
TempImageFactory.destroyCanvas();
|
|
508
|
+
}
|
|
509
|
+
#resetView() {
|
|
510
|
+
this._thumbnails = [];
|
|
511
|
+
this._currentPageNumber = 1;
|
|
512
|
+
this._pageLabels = null;
|
|
513
|
+
this._pagesRotation = 0;
|
|
514
|
+
|
|
515
|
+
// Remove the thumbnails from the DOM.
|
|
516
|
+
this.container.textContent = "";
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* @param {PDFDocumentProxy} pdfDocument
|
|
521
|
+
*/
|
|
522
|
+
setDocument(pdfDocument) {
|
|
523
|
+
if (this.pdfDocument) {
|
|
524
|
+
this.#cancelRendering();
|
|
525
|
+
this.#resetView();
|
|
526
|
+
}
|
|
527
|
+
this.pdfDocument = pdfDocument;
|
|
528
|
+
if (!pdfDocument) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
const firstPagePromise = pdfDocument.getPage(1);
|
|
532
|
+
const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({
|
|
533
|
+
intent: "display"
|
|
534
|
+
});
|
|
535
|
+
firstPagePromise.then(firstPdfPage => {
|
|
536
|
+
var _this$_thumbnails$;
|
|
537
|
+
const pagesCount = pdfDocument.numPages;
|
|
538
|
+
const viewport = firstPdfPage.getViewport({
|
|
539
|
+
scale: 1
|
|
540
|
+
});
|
|
541
|
+
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
|
542
|
+
const thumbnail = new PDFThumbnailView({
|
|
543
|
+
container: this.container,
|
|
544
|
+
eventBus: this.eventBus,
|
|
545
|
+
id: pageNum,
|
|
546
|
+
defaultViewport: viewport.clone(),
|
|
547
|
+
optionalContentConfigPromise,
|
|
548
|
+
linkService: this.linkService,
|
|
549
|
+
renderingQueue: this.renderingQueue,
|
|
550
|
+
pageColors: this.pageColors
|
|
551
|
+
});
|
|
552
|
+
this._thumbnails.push(thumbnail);
|
|
553
|
+
}
|
|
554
|
+
// Set the first `pdfPage` immediately, since it's already loaded,
|
|
555
|
+
// rather than having to repeat the `PDFDocumentProxy.getPage` call in
|
|
556
|
+
// the `this.#ensurePdfPageLoaded` method before rendering can start.
|
|
557
|
+
(_this$_thumbnails$ = this._thumbnails[0]) === null || _this$_thumbnails$ === void 0 ? void 0 : _this$_thumbnails$.setPdfPage(firstPdfPage);
|
|
558
|
+
|
|
559
|
+
// Ensure that the current thumbnail is always highlighted on load.
|
|
560
|
+
const thumbnailView = this._thumbnails[this._currentPageNumber - 1];
|
|
561
|
+
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS);
|
|
562
|
+
}).catch(reason => {
|
|
563
|
+
console.error("Unable to initialize thumbnail viewer", reason);
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
#cancelRendering() {
|
|
567
|
+
for (const thumbnail of this._thumbnails) {
|
|
568
|
+
thumbnail.cancelRendering();
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* @param {Array|null} labels
|
|
574
|
+
*/
|
|
575
|
+
setPageLabels(labels) {
|
|
576
|
+
if (!this.pdfDocument) {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (!labels) {
|
|
580
|
+
this._pageLabels = null;
|
|
581
|
+
} else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) {
|
|
582
|
+
this._pageLabels = null;
|
|
583
|
+
console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels.");
|
|
584
|
+
} else {
|
|
585
|
+
this._pageLabels = labels;
|
|
586
|
+
}
|
|
587
|
+
// Update all the `PDFThumbnailView` instances.
|
|
588
|
+
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) {
|
|
589
|
+
var _this$_pageLabels$i, _this$_pageLabels;
|
|
590
|
+
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);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* @param {PDFThumbnailView} thumbView
|
|
596
|
+
* @returns {Promise<PDFPageProxy | null>}
|
|
597
|
+
*/
|
|
598
|
+
async #ensurePdfPageLoaded(thumbView) {
|
|
599
|
+
if (thumbView.pdfPage) {
|
|
600
|
+
return thumbView.pdfPage;
|
|
601
|
+
}
|
|
602
|
+
try {
|
|
603
|
+
const pdfPage = await this.pdfDocument.getPage(thumbView.id);
|
|
604
|
+
if (!thumbView.pdfPage) {
|
|
605
|
+
thumbView.setPdfPage(pdfPage);
|
|
606
|
+
}
|
|
607
|
+
return pdfPage;
|
|
608
|
+
} catch (reason) {
|
|
609
|
+
console.error("Unable to get page for thumb view", reason);
|
|
610
|
+
return null; // Page error -- there is nothing that can be done.
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
#getScrollAhead(visible) {
|
|
614
|
+
var _visible$first, _visible$last;
|
|
615
|
+
if (((_visible$first = visible.first) === null || _visible$first === void 0 ? void 0 : _visible$first.id) === 1) {
|
|
616
|
+
return true;
|
|
617
|
+
} else if (((_visible$last = visible.last) === null || _visible$last === void 0 ? void 0 : _visible$last.id) === this._thumbnails.length) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
return this.scroll.down;
|
|
621
|
+
}
|
|
622
|
+
forceRendering() {
|
|
623
|
+
const visibleThumbs = this.#getVisibleThumbs();
|
|
624
|
+
const scrollAhead = this.#getScrollAhead(visibleThumbs);
|
|
625
|
+
const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead);
|
|
626
|
+
if (thumbView) {
|
|
627
|
+
this.#ensurePdfPageLoaded(thumbView).then(() => {
|
|
628
|
+
this.renderingQueue.renderView(thumbView);
|
|
629
|
+
});
|
|
630
|
+
return true;
|
|
631
|
+
}
|
|
632
|
+
return false;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export { PDFThumbnailViewer };
|