@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
package/src/vcf-pdf-viewer.js
CHANGED
|
@@ -1,1072 +1,1214 @@
|
|
|
1
|
-
import { LitElement, html, css } from "lit";
|
|
2
|
-
import { ElementMixin } from "@vaadin/component-base/src/element-mixin";
|
|
3
|
-
import { ThemeDetectionMixin } from "@vaadin/vaadin-themable-mixin/vaadin-theme-detection-mixin";
|
|
4
|
-
import { ResizeMixin, SlotStylesMixin } from "@vaadin/component-base/";
|
|
5
|
-
import { ThemableMixin } from "@vaadin/vaadin-themable-mixin";
|
|
6
|
-
|
|
7
|
-
import "@vaadin/text-field";
|
|
8
|
-
import "@vaadin/select";
|
|
9
|
-
import "@vaadin/item";
|
|
10
|
-
import "@vaadin/button";
|
|
11
|
-
import "@vaadin/icon";
|
|
12
|
-
import "@vaadin/icons";
|
|
13
|
-
import "@vaadin/tooltip";
|
|
14
|
-
|
|
15
|
-
import * as pdfjsLib from "../pdfjs/dist/pdf";
|
|
16
|
-
import * as pdfjsViewer from "../pdfjs/dist/pdf_viewer";
|
|
17
|
-
import * as pdfUtils from "../pdfjs/dist/ui_utils";
|
|
18
|
-
import
|
|
19
|
-
import * as
|
|
20
|
-
import * as
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
|
|
24
|
-
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* `<vcf-pdf-viewer>` is a Web Component for rendering PDF files without
|
|
28
|
-
* the need of plugins. You can provide a pdf file to it through the src
|
|
29
|
-
* attribute.
|
|
30
|
-
*
|
|
31
|
-
* ```
|
|
32
|
-
* <vcf-pdf-viewer src="myfile.pdf"></vcf-pdf-viewer>
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @
|
|
36
|
-
* @
|
|
37
|
-
* @
|
|
38
|
-
* @
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
[
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
[part~="toolbar"] #
|
|
62
|
-
[part~="toolbar"] #
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
[part~="toolbar"]
|
|
67
|
-
[part~="toolbar"]
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
[part~="toolbar"].ready #
|
|
72
|
-
[part~="toolbar"].ready #
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
[part~="
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
[part~="
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
.textLayer .
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
top:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
-
|
|
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
|
-
this.
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
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
|
-
this.
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
);
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
this.
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
)
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
if (
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
this.
|
|
828
|
-
this.
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
this.
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
this.
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
if (
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
this.
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
this.
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
var
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
this.__viewer.
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1
|
+
import { LitElement, html, css } from "lit";
|
|
2
|
+
import { ElementMixin } from "@vaadin/component-base/src/element-mixin";
|
|
3
|
+
import { ThemeDetectionMixin } from "@vaadin/vaadin-themable-mixin/vaadin-theme-detection-mixin";
|
|
4
|
+
import { ResizeMixin, SlotStylesMixin } from "@vaadin/component-base/";
|
|
5
|
+
import { ThemableMixin } from "@vaadin/vaadin-themable-mixin";
|
|
6
|
+
|
|
7
|
+
import "@vaadin/text-field";
|
|
8
|
+
import "@vaadin/select";
|
|
9
|
+
import "@vaadin/item";
|
|
10
|
+
import "@vaadin/button";
|
|
11
|
+
import "@vaadin/icon";
|
|
12
|
+
import "@vaadin/icons";
|
|
13
|
+
import "@vaadin/tooltip";
|
|
14
|
+
|
|
15
|
+
import * as pdfjsLib from "../pdfjs/dist/pdf";
|
|
16
|
+
import * as pdfjsViewer from "../pdfjs/dist/pdf_viewer";
|
|
17
|
+
import * as pdfUtils from "../pdfjs/dist/ui_utils";
|
|
18
|
+
import { EventBus } from "../pdfjs/dist/event_utils";
|
|
19
|
+
import * as pdfjsLinkService from "../pdfjs/dist/pdf_link_service";
|
|
20
|
+
import * as pdfjsThumbnailViewer from "../pdfjs/dist/pdf_thumbnail_viewer";
|
|
21
|
+
import * as pdfjsRenderingQueue from "../pdfjs/dist/pdf_rendering_queue";
|
|
22
|
+
import { GenericL10n } from "../pdfjs/dist/genericl10n";
|
|
23
|
+
|
|
24
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = "../pdfjs/dist/worker.js";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `<vcf-pdf-viewer>` is a Web Component for rendering PDF files without
|
|
28
|
+
* the need of plugins. You can provide a pdf file to it through the src
|
|
29
|
+
* attribute.
|
|
30
|
+
*
|
|
31
|
+
* ```
|
|
32
|
+
* <vcf-pdf-viewer src="myfile.pdf"></vcf-pdf-viewer>
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @tagname vcf-pdf-viewer
|
|
36
|
+
* @fires {CustomEvent} currentPage-changed - Fired after the element itself updated `currentPage`.
|
|
37
|
+
* @fires {CustomEvent} document-loaded - Fired once the document behind `src` finished loading, with the pdf.js document in `detail.document`.
|
|
38
|
+
* @fires {CustomEvent} thumbnail-clicked - Fired when a sidebar thumbnail is clicked, after navigating to its page. Dispatched on the viewer, which is also passed as `detail.source`, together with `detail.pageNumber`.
|
|
39
|
+
* @memberof Vaadin
|
|
40
|
+
* @mixes Vaadin.ElementMixin
|
|
41
|
+
* @mixes Vaadin.ThemableMixin
|
|
42
|
+
* @demo demo/index.html
|
|
43
|
+
*/
|
|
44
|
+
export class PdfViewerElement extends ResizeMixin(
|
|
45
|
+
SlotStylesMixin(ThemeDetectionMixin(ThemableMixin(ElementMixin(LitElement)))),
|
|
46
|
+
) {
|
|
47
|
+
static get styles() {
|
|
48
|
+
return css`
|
|
49
|
+
:host {
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-direction: column;
|
|
52
|
+
width: 100%;
|
|
53
|
+
height: 500px;
|
|
54
|
+
--pdf-viewer-link-hover-color: rgb(255 255 0);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
:host([hidden]) {
|
|
58
|
+
display: none !important;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
[part~="toolbar"] #currentPage,
|
|
62
|
+
[part~="toolbar"] #pageSeparator,
|
|
63
|
+
[part~="toolbar"] #totalPages,
|
|
64
|
+
[part~="toolbar"] #previousPage,
|
|
65
|
+
[part~="toolbar"] #nextPage,
|
|
66
|
+
[part~="toolbar"] #zoom,
|
|
67
|
+
[part~="toolbar"] #sidebarToggle {
|
|
68
|
+
display: none;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
[part~="toolbar"].ready #currentPage,
|
|
72
|
+
[part~="toolbar"].ready #pageSeparator,
|
|
73
|
+
[part~="toolbar"].ready #totalPages,
|
|
74
|
+
[part~="toolbar"].ready #previousPage,
|
|
75
|
+
[part~="toolbar"].ready #nextPage,
|
|
76
|
+
[part~="toolbar"].ready #zoom,
|
|
77
|
+
[part~="toolbar"].ready #sidebarToggle {
|
|
78
|
+
display: inherit;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
[part~="outer-container"] {
|
|
82
|
+
width: 100%;
|
|
83
|
+
height: 100%;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
[part~="main-container"] {
|
|
87
|
+
position: absolute;
|
|
88
|
+
top: 0;
|
|
89
|
+
right: 0;
|
|
90
|
+
bottom: 0;
|
|
91
|
+
left: 0;
|
|
92
|
+
min-width: 320px;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
[part~="viewer-container"] {
|
|
96
|
+
position: absolute;
|
|
97
|
+
flex: 1;
|
|
98
|
+
overflow: auto;
|
|
99
|
+
width: 100%;
|
|
100
|
+
height: -moz-calc(100% - 45px); /* Firefox */
|
|
101
|
+
height: -webkit-calc(100% - 45px); /* Chrome, Safari */
|
|
102
|
+
height: calc(100% - 45px); /*all other browsers */
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
[part~="sidebar-container"] {
|
|
106
|
+
position: absolute;
|
|
107
|
+
width: 200px;
|
|
108
|
+
top: 45px;
|
|
109
|
+
bottom: 0;
|
|
110
|
+
visibility: hidden;
|
|
111
|
+
height: -moz-calc(100% - 45px); /* Firefox */
|
|
112
|
+
height: -webkit-calc(100% - 45px); /* Chrome, Safari */
|
|
113
|
+
height: calc(100% - 45px); /*all other browsers */
|
|
114
|
+
z-index: 100;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
[part~="sidebar-content"] {
|
|
118
|
+
position: absolute;
|
|
119
|
+
top: 0;
|
|
120
|
+
bottom: 0;
|
|
121
|
+
overflow: auto;
|
|
122
|
+
width: 100%;
|
|
123
|
+
background-color: rgba(0, 0, 0, 0.1);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
[part~="thumbnail-view"] {
|
|
127
|
+
position: absolute;
|
|
128
|
+
top: 0;
|
|
129
|
+
bottom: 0;
|
|
130
|
+
padding: 10px 30px 0;
|
|
131
|
+
overflow: auto;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
[part~="toolbar"] {
|
|
135
|
+
height: 44px;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.page {
|
|
139
|
+
position: relative;
|
|
140
|
+
margin: 0 auto;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.canvasWrapper {
|
|
144
|
+
position: absolute;
|
|
145
|
+
top: 0;
|
|
146
|
+
left: 0;
|
|
147
|
+
width: 100%;
|
|
148
|
+
height: 100%;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.textLayer {
|
|
152
|
+
position: absolute;
|
|
153
|
+
left: 0;
|
|
154
|
+
top: 0;
|
|
155
|
+
right: 0;
|
|
156
|
+
bottom: 0;
|
|
157
|
+
overflow: hidden;
|
|
158
|
+
line-height: 1;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.textLayer > span {
|
|
162
|
+
color: transparent;
|
|
163
|
+
position: absolute;
|
|
164
|
+
white-space: pre;
|
|
165
|
+
cursor: text;
|
|
166
|
+
-webkit-transform-origin: 0% 0%;
|
|
167
|
+
transform-origin: 0% 0%;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.textLayer .highlight {
|
|
171
|
+
margin: -1px;
|
|
172
|
+
padding: 1px;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.textLayer .highlight.begin {
|
|
176
|
+
border-radius: 4px 0 0 4px;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.textLayer .highlight.end {
|
|
180
|
+
border-radius: 0 4px 4px 0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.textLayer .highlight.middle {
|
|
184
|
+
border-radius: 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.textLayer .endOfContent {
|
|
188
|
+
display: block;
|
|
189
|
+
position: absolute;
|
|
190
|
+
left: 0;
|
|
191
|
+
top: 100%;
|
|
192
|
+
right: 0;
|
|
193
|
+
bottom: 0;
|
|
194
|
+
z-index: -1;
|
|
195
|
+
cursor: default;
|
|
196
|
+
-webkit-user-select: none;
|
|
197
|
+
-moz-user-select: none;
|
|
198
|
+
-ms-user-select: none;
|
|
199
|
+
user-select: none;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.textLayer .endOfContent.active {
|
|
203
|
+
top: 0;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
#header {
|
|
207
|
+
display: flex;
|
|
208
|
+
flex-direction: row;
|
|
209
|
+
align-items: baseline;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
::slotted(#currentPage) {
|
|
213
|
+
align-self: baseline;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
#outerContainer.sidebarOpen #viewerContainer {
|
|
217
|
+
transition-property: left;
|
|
218
|
+
left: 200px;
|
|
219
|
+
width: -moz-calc(100% - 200px); /* Firefox */
|
|
220
|
+
width: -webkit-calc(100% - 200px); /* Chrome, Safari */
|
|
221
|
+
width: calc(100% - 200px); /*all other browsers */
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
#outerContainer.sidebarOpen #sidebarContainer {
|
|
225
|
+
visibility: visible;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.thumbnail {
|
|
229
|
+
margin: 5px;
|
|
230
|
+
padding: 7px 7px 0px 7px;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.thumbnailImage {
|
|
234
|
+
border: 1px solid rgba(0, 0, 0, 0);
|
|
235
|
+
box-shadow:
|
|
236
|
+
0 0 0 1px rgba(0, 0, 0, 0.5),
|
|
237
|
+
0 2px 8px rgba(0, 0, 0, 0.3);
|
|
238
|
+
opacity: 1;
|
|
239
|
+
z-index: 99;
|
|
240
|
+
background-color: rgba(255, 255, 255, 1);
|
|
241
|
+
background-clip: content-box;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.thumbnail.selected {
|
|
245
|
+
background-color: rgba(0, 0, 0, 0.15);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
[part~="toolbar"].ready ::slotted(.toolbar-zoom.hide-zoom) {
|
|
249
|
+
display: none;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/* Annotation layer */
|
|
253
|
+
|
|
254
|
+
.annotationLayer {
|
|
255
|
+
--annotation-unfocused-field-background: url("data:image/svg+xml;charset=UTF-8,<svg width='1px' height='1px' xmlns='http://www.w3.org/2000/svg'><rect width='100%' height='100%' style='fill:rgba(0, 54, 255, 0.13);'/></svg>");
|
|
256
|
+
--input-focus-border-color: Highlight;
|
|
257
|
+
--input-focus-outline: 1px solid Canvas;
|
|
258
|
+
--input-unfocused-border-color: transparent;
|
|
259
|
+
--input-disabled-border-color: transparent;
|
|
260
|
+
--input-hover-border-color: black;
|
|
261
|
+
--link-outline: none;
|
|
262
|
+
position: absolute;
|
|
263
|
+
top: 0;
|
|
264
|
+
left: 0;
|
|
265
|
+
pointer-events: none;
|
|
266
|
+
transform-origin: 0 0;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.annotationLayer section {
|
|
270
|
+
position: absolute;
|
|
271
|
+
text-align: initial;
|
|
272
|
+
pointer-events: auto;
|
|
273
|
+
box-sizing: border-box;
|
|
274
|
+
transform-origin: 0 0;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.annotationLayer :is(.linkAnnotation, .buttonWidgetAnnotation.pushButton) > a {
|
|
278
|
+
position: absolute;
|
|
279
|
+
font-size: 1em;
|
|
280
|
+
top: 0;
|
|
281
|
+
left: 0;
|
|
282
|
+
width: 100%;
|
|
283
|
+
height: 100%;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.annotationLayer :is(.linkAnnotation, .buttonWidgetAnnotation.pushButton):not(.hasBorder) > a:hover {
|
|
287
|
+
opacity: 0.2;
|
|
288
|
+
background-color: var(--pdf-viewer-link-hover-color);
|
|
289
|
+
box-shadow: 0 2px 10px var(--pdf-viewer-link-hover-color);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.annotationLayer .linkAnnotation.hasBorder:hover {
|
|
293
|
+
background-color: color-mix(in srgb, var(--pdf-viewer-link-hover-color) 20%, transparent);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.annotationLayer .hasBorder {
|
|
297
|
+
background-size: 100% 100%;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.annotationLayer .textWidgetAnnotation :is(input, textarea),
|
|
301
|
+
.annotationLayer .choiceWidgetAnnotation select,
|
|
302
|
+
.annotationLayer .buttonWidgetAnnotation:is(.checkBox, .radioButton) input {
|
|
303
|
+
background-image: var(--annotation-unfocused-field-background);
|
|
304
|
+
border: 2px solid var(--input-unfocused-border-color);
|
|
305
|
+
box-sizing: border-box;
|
|
306
|
+
font: calc(9px * var(--scale-factor)) sans-serif;
|
|
307
|
+
height: 100%;
|
|
308
|
+
margin: 0;
|
|
309
|
+
vertical-align: top;
|
|
310
|
+
width: 100%;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
.annotationLayer .textWidgetAnnotation :is(input, textarea):hover,
|
|
314
|
+
.annotationLayer .choiceWidgetAnnotation select:hover,
|
|
315
|
+
.annotationLayer .buttonWidgetAnnotation:is(.checkBox, .radioButton) input:hover {
|
|
316
|
+
border: 2px solid var(--input-hover-border-color);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
.annotationLayer .textWidgetAnnotation :is(input, textarea):focus,
|
|
320
|
+
.annotationLayer .choiceWidgetAnnotation select:focus {
|
|
321
|
+
background: none;
|
|
322
|
+
border: 2px solid var(--input-focus-border-color);
|
|
323
|
+
border-radius: 2px;
|
|
324
|
+
outline: var(--input-focus-outline);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
.annotationLayer .buttonWidgetAnnotation.radioButton input {
|
|
328
|
+
border-radius: 50%;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
.annotationLayer .textWidgetAnnotation textarea {
|
|
332
|
+
resize: none;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
.annotationLayer .buttonWidgetAnnotation:is(.checkBox, .radioButton) input {
|
|
336
|
+
appearance: none;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
.annotationLayer .buttonWidgetAnnotation.checkBox input:checked::before,
|
|
340
|
+
.annotationLayer .buttonWidgetAnnotation.checkBox input:checked::after,
|
|
341
|
+
.annotationLayer .buttonWidgetAnnotation.radioButton input:checked::before {
|
|
342
|
+
background-color: CanvasText;
|
|
343
|
+
content: "";
|
|
344
|
+
display: block;
|
|
345
|
+
position: absolute;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.annotationLayer .buttonWidgetAnnotation.checkBox input:checked::before,
|
|
349
|
+
.annotationLayer .buttonWidgetAnnotation.checkBox input:checked::after {
|
|
350
|
+
height: 80%;
|
|
351
|
+
left: 45%;
|
|
352
|
+
width: 1px;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
.annotationLayer .buttonWidgetAnnotation.checkBox input:checked::before {
|
|
356
|
+
transform: rotate(45deg);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
.annotationLayer .buttonWidgetAnnotation.checkBox input:checked::after {
|
|
360
|
+
transform: rotate(-45deg);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
.annotationLayer .buttonWidgetAnnotation.radioButton input:checked::before {
|
|
364
|
+
border-radius: 50%;
|
|
365
|
+
height: 50%;
|
|
366
|
+
left: 25%;
|
|
367
|
+
top: 25%;
|
|
368
|
+
width: 50%;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
.annotationLayer .textWidgetAnnotation :is(input, textarea)[disabled],
|
|
372
|
+
.annotationLayer .choiceWidgetAnnotation select[disabled],
|
|
373
|
+
.annotationLayer .buttonWidgetAnnotation:is(.checkBox, .radioButton) input[disabled] {
|
|
374
|
+
background: none;
|
|
375
|
+
border: 2px solid var(--input-disabled-border-color);
|
|
376
|
+
cursor: not-allowed;
|
|
377
|
+
}
|
|
378
|
+
`;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** @protected */
|
|
382
|
+
get slotStyles() {
|
|
383
|
+
const tag = "vcf-pdf-viewer";
|
|
384
|
+
const lumo = '[data-application-theme="lumo"]';
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* These rules target a <vaadin-text-field> element with a child element
|
|
388
|
+
* having the 'toggle-button' class name. We can't use `::slotted()` as
|
|
389
|
+
* the toggle button is not a direct child of the month picker element.
|
|
390
|
+
* Also for `vaadin-popover` we can't use `::part()` after `::slotted()`.
|
|
391
|
+
*/
|
|
392
|
+
return [
|
|
393
|
+
`
|
|
394
|
+
${tag}:not(${lumo}) vaadin-button.toolbar-button vaadin-icon {
|
|
395
|
+
display: none;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
${tag}:not(${lumo}) vaadin-button.toolbar-button {
|
|
399
|
+
height: var(--vaadin-icon-size, 1.5lh);
|
|
400
|
+
width: var(--vaadin-icon-size, 1.5lh);
|
|
401
|
+
padding: 0;
|
|
402
|
+
justify-content: flex-start;
|
|
403
|
+
box-sizing: content-box;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
${tag}:not(${lumo}) vaadin-button.toolbar-button::before {
|
|
407
|
+
content: '';
|
|
408
|
+
flex: none;
|
|
409
|
+
background: var(--vaadin-input-field-button-text-color, var(--vaadin-text-color-secondary));
|
|
410
|
+
cursor: var(--vaadin-clickable-cursor);
|
|
411
|
+
touch-action: manipulation;
|
|
412
|
+
-webkit-tap-highlight-color: transparent;
|
|
413
|
+
-webkit-user-select: none;
|
|
414
|
+
user-select: none;
|
|
415
|
+
height: var(--vaadin-icon-size, 1.5lh);
|
|
416
|
+
width: var(--vaadin-icon-size, 1.5lh);
|
|
417
|
+
mask-size: var(--vaadin-icon-visual-size, 100%);
|
|
418
|
+
mask-position: 50%;
|
|
419
|
+
mask-repeat: no-repeat;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
${tag}:not(${lumo}) vaadin-button.toolbar-button#sidebarToggle::before {
|
|
423
|
+
mask-image: var(--pdf-viewer-toggle-button-icon-closed);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
${tag}:not(${lumo}) vaadin-button.toolbar-button#sidebarToggle:has(vaadin-icon.sidebarOpen)::before {
|
|
427
|
+
mask-image: var(--pdf-viewer-toggle-button-icon-open);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
${tag}:not(${lumo}) vaadin-button.toolbar-button#previousPage::before {
|
|
431
|
+
mask-image: var(--pdf-viewer-previous-page-button-icon);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
${tag}:not(${lumo}) vaadin-button.toolbar-button#nextPage::before {
|
|
435
|
+
mask-image: var(--pdf-viewer-next-page-button-icon);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
${tag}${lumo} vaadin-button[theme~="icon"] {
|
|
439
|
+
padding-left: 6px;
|
|
440
|
+
padding-right: 6px;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
${tag}${lumo} vaadin-button.toolbar-button#sidebarToggle {
|
|
444
|
+
border: 2px solid;
|
|
445
|
+
border-color: rgba(0, 0, 0, 0.5);
|
|
446
|
+
}
|
|
447
|
+
`,
|
|
448
|
+
];
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
render() {
|
|
452
|
+
return html`
|
|
453
|
+
<div id="outerContainer" part="outer-container">
|
|
454
|
+
<div id="sidebarContainer" part="sidebar-container">
|
|
455
|
+
<div id="sidebarContent" part="sidebar-content">
|
|
456
|
+
<div id="thumbnailView" part="thumbnail-view"></div>
|
|
457
|
+
</div>
|
|
458
|
+
</div>
|
|
459
|
+
<div id="mainContainer" part="main-container">
|
|
460
|
+
<div id="toolbar" part="toolbar">
|
|
461
|
+
<slot name="sidebar-toggle-button-slot"></slot>
|
|
462
|
+
<span id="title" part="toolbar-text toolbar-title"
|
|
463
|
+
>${this.__title}</span
|
|
464
|
+
>
|
|
465
|
+
<slot name="toolbar-zoom-slot"></slot>
|
|
466
|
+
<div part="toolbar-pages">
|
|
467
|
+
<slot name="toolbar-current-page-slot"></slot>
|
|
468
|
+
<span
|
|
469
|
+
id="pageSeparator"
|
|
470
|
+
part="toolbar-text toolbar-page-separator"
|
|
471
|
+
>/</span
|
|
472
|
+
>
|
|
473
|
+
<span id="totalPages" part="toolbar-text toolbar-total-pages"
|
|
474
|
+
>${this.__totalPages}</span
|
|
475
|
+
>
|
|
476
|
+
<slot name="previous-page-button-slot"></slot>
|
|
477
|
+
<slot name="next-page-button-slot"></slot>
|
|
478
|
+
</div>
|
|
479
|
+
<slot></slot>
|
|
480
|
+
</div>
|
|
481
|
+
|
|
482
|
+
<div id="viewerContainer" part="viewer-container">
|
|
483
|
+
<div id="viewer" part="viewer"></div>
|
|
484
|
+
</div>
|
|
485
|
+
</div>
|
|
486
|
+
</div>
|
|
487
|
+
`;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
static get is() {
|
|
491
|
+
return "vcf-pdf-viewer";
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
static get version() {
|
|
495
|
+
return "4.1.0";
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
static get properties() {
|
|
499
|
+
return {
|
|
500
|
+
/**
|
|
501
|
+
* You can set a pdf file that you want to render with src. Note that regular cross
|
|
502
|
+
* site scripting (XSS) rules apply. This means that the file should be on the same
|
|
503
|
+
* server as where the component is run, or that the server where the file is on should
|
|
504
|
+
* be configured to allow loading files from other sites.
|
|
505
|
+
*/
|
|
506
|
+
src: { type: String },
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* The viewer, which takes care of rendering content into a DOM element.
|
|
510
|
+
*/
|
|
511
|
+
__viewer: Object,
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* The viewer for thumbnails.
|
|
515
|
+
*/
|
|
516
|
+
__thumbnailViewer: Object,
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* The link service.
|
|
520
|
+
*/
|
|
521
|
+
__linkService: Object,
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* A represenentation of a document that has been read in.
|
|
525
|
+
*/
|
|
526
|
+
__document: Object,
|
|
527
|
+
/**
|
|
528
|
+
* The title for the PDF shown in the toolbar of component. It uses both the file name and
|
|
529
|
+
* the title in the PDF metadata if available.
|
|
530
|
+
*/
|
|
531
|
+
__title: { type: String },
|
|
532
|
+
/**
|
|
533
|
+
* Relative filename
|
|
534
|
+
*/
|
|
535
|
+
__filename: String,
|
|
536
|
+
/**
|
|
537
|
+
* The pdf metadata title
|
|
538
|
+
*/
|
|
539
|
+
__pdfTitle: String,
|
|
540
|
+
/**
|
|
541
|
+
* The level of zoom on the document.
|
|
542
|
+
* Allowed values are
|
|
543
|
+
* - Number, for zoom percentage. Eg. 1.5 means 150% zoom
|
|
544
|
+
* - 'auto', default value
|
|
545
|
+
* - 'page-fit', fit a full page into component
|
|
546
|
+
*/
|
|
547
|
+
zoom: { type: String },
|
|
548
|
+
/**
|
|
549
|
+
* The current page visible viewed right now
|
|
550
|
+
*/
|
|
551
|
+
currentPage: { type: String },
|
|
552
|
+
/**
|
|
553
|
+
* Total amount of pages in an opened document
|
|
554
|
+
*/
|
|
555
|
+
__totalPages: Number,
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Loading state
|
|
559
|
+
*/
|
|
560
|
+
__loading: { type: Boolean },
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Whether sidebar is open after loading or not
|
|
564
|
+
*/
|
|
565
|
+
__sidebarOpen: { type: Boolean },
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Flag to indicate if toolbar should only show filename as title
|
|
569
|
+
*/
|
|
570
|
+
toolbarOnlyFilename: { type: Boolean },
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Property to define auto zoom label
|
|
574
|
+
*/
|
|
575
|
+
autoZoomOptionLabel: { type: String },
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Property to define page fit zoom label
|
|
579
|
+
*/
|
|
580
|
+
fitZoomOptionLabel: { type: String },
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Property to define a custom title for the viewer
|
|
584
|
+
*/
|
|
585
|
+
customTitle: { type: String },
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Renders interactive form elements in the annotation layer (html) if true,
|
|
589
|
+
* renders values of form elements directly onto the canvas if false
|
|
590
|
+
*/
|
|
591
|
+
renderInteractiveForms: { type: Boolean },
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Allows to hide the zoom dropdown. By default it's always shown.
|
|
595
|
+
*/
|
|
596
|
+
hideZoom: { type: Boolean },
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Property to define a custom tooltip for the sidebar toggle button
|
|
600
|
+
*/
|
|
601
|
+
sidebarToggleTooltip: { type: String },
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Property to define a custom tooltip for the previous page button
|
|
605
|
+
*/
|
|
606
|
+
previousPageTooltip: { type: String },
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Property to define a custom tooltip for the next page button
|
|
610
|
+
*/
|
|
611
|
+
nextPageTooltip: { type: String },
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
get __zoomItems() {
|
|
616
|
+
return this.__computeZoomItems(
|
|
617
|
+
this.autoZoomOptionLabel,
|
|
618
|
+
this.fitZoomOptionLabel,
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
constructor() {
|
|
623
|
+
super();
|
|
624
|
+
this.__title = "PDF";
|
|
625
|
+
this.zoom = "auto";
|
|
626
|
+
this.currentPage = "1";
|
|
627
|
+
this.__loading = true;
|
|
628
|
+
this.__sidebarOpen = false;
|
|
629
|
+
this.toolbarOnlyFilename = false;
|
|
630
|
+
this.autoZoomOptionLabel = "Automatic zoom";
|
|
631
|
+
this.fitZoomOptionLabel = "Page fit";
|
|
632
|
+
this.customTitle = "";
|
|
633
|
+
this.renderInteractiveForms = true;
|
|
634
|
+
this.hideZoom = false;
|
|
635
|
+
this.sidebarToggleTooltip = "";
|
|
636
|
+
this.previousPageTooltip = "";
|
|
637
|
+
this.nextPageTooltip = "";
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
willUpdate(changedProperties) {
|
|
641
|
+
super.willUpdate(changedProperties);
|
|
642
|
+
|
|
643
|
+
// Compute filename if src changes
|
|
644
|
+
if (changedProperties.has("src")) {
|
|
645
|
+
this.__setFilename(this.src);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// Compute title before rendering to avoid setting reactive properties during update
|
|
649
|
+
if (
|
|
650
|
+
changedProperties.has("src") ||
|
|
651
|
+
changedProperties.has("customTitle") ||
|
|
652
|
+
changedProperties.has("toolbarOnlyFilename")
|
|
653
|
+
) {
|
|
654
|
+
this.__setTitle(this.__pdfTitle, this.__filename);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
updated(changedProperties) {
|
|
659
|
+
super.updated(changedProperties);
|
|
660
|
+
|
|
661
|
+
// Defer property synchronization to avoid "update during update" warning
|
|
662
|
+
// This ensures these calls happen after the current update cycle completes
|
|
663
|
+
Promise.resolve().then(() => {
|
|
664
|
+
if (changedProperties.has("src")) {
|
|
665
|
+
this.__srcChanged(this.src);
|
|
666
|
+
}
|
|
667
|
+
if (changedProperties.has("zoom")) {
|
|
668
|
+
const zoomSelect = this.querySelector("#zoom");
|
|
669
|
+
if (zoomSelect && zoomSelect.value !== this.zoom) {
|
|
670
|
+
zoomSelect.value = this.zoom;
|
|
671
|
+
}
|
|
672
|
+
this.__zoomChanged(this.zoom);
|
|
673
|
+
}
|
|
674
|
+
if (changedProperties.has("currentPage")) {
|
|
675
|
+
const currentPageInput = this.querySelector("#currentPage");
|
|
676
|
+
if (currentPageInput && currentPageInput.value !== this.currentPage) {
|
|
677
|
+
currentPageInput.value = this.currentPage;
|
|
678
|
+
this.__pageChange();
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
__createToolbarButton() {
|
|
685
|
+
const icon = document.createElement("vaadin-icon");
|
|
686
|
+
icon.setAttribute("slot", "prefix");
|
|
687
|
+
|
|
688
|
+
const tooltip = document.createElement("vaadin-tooltip");
|
|
689
|
+
tooltip.setAttribute("slot", "tooltip");
|
|
690
|
+
|
|
691
|
+
const button = document.createElement("vaadin-button");
|
|
692
|
+
button.classList.add("toolbar-button");
|
|
693
|
+
button.setAttribute("theme", "icon tertiary contrast");
|
|
694
|
+
|
|
695
|
+
button.appendChild(icon);
|
|
696
|
+
button.appendChild(tooltip);
|
|
697
|
+
return button;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Adds toggle button to the toolbar slot named "sidebar-toggle-button-slot".
|
|
702
|
+
*/
|
|
703
|
+
_createSideBarToggleButton() {
|
|
704
|
+
const button = this.__createToolbarButton();
|
|
705
|
+
const icon = button.querySelector("vaadin-icon");
|
|
706
|
+
icon.classList.add("toggle-button-icon");
|
|
707
|
+
button
|
|
708
|
+
.querySelector("vaadin-tooltip")
|
|
709
|
+
.setAttribute("text", this.sidebarToggleTooltip);
|
|
710
|
+
button.setAttribute("slot", "sidebar-toggle-button-slot");
|
|
711
|
+
button.setAttribute("id", "sidebarToggle");
|
|
712
|
+
button.setAttribute("aria-label", "Sidebar toggle");
|
|
713
|
+
button.addEventListener("click", () => {
|
|
714
|
+
this.__toogleSidebar();
|
|
715
|
+
if (this._outerContainer.classList.contains("sidebarOpen")) {
|
|
716
|
+
icon.classList.add("sidebarOpen");
|
|
717
|
+
} else {
|
|
718
|
+
icon.classList.remove("sidebarOpen");
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
this.appendChild(button);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Adds previous page button to the toolbar slot named "previous-page-button-slot".
|
|
726
|
+
*/
|
|
727
|
+
_createPreviousPageButton() {
|
|
728
|
+
const button = this.__createToolbarButton();
|
|
729
|
+
button
|
|
730
|
+
.querySelector("vaadin-icon")
|
|
731
|
+
.classList.add("previous-page-button-icon");
|
|
732
|
+
button
|
|
733
|
+
.querySelector("vaadin-tooltip")
|
|
734
|
+
.setAttribute("text", this.previousPageTooltip);
|
|
735
|
+
button.setAttribute("slot", "previous-page-button-slot");
|
|
736
|
+
button.setAttribute("id", "previousPage");
|
|
737
|
+
button.setAttribute("aria-label", "Previous page");
|
|
738
|
+
button.addEventListener("click", () => this.__previousPage());
|
|
739
|
+
this.appendChild(button);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
/**
|
|
743
|
+
* Adds next page button to the toolbar slot named "next-page-button-slot".
|
|
744
|
+
*/
|
|
745
|
+
_createNextPageButton() {
|
|
746
|
+
const button = this.__createToolbarButton();
|
|
747
|
+
button.querySelector("vaadin-icon").classList.add("next-page-button-icon");
|
|
748
|
+
button
|
|
749
|
+
.querySelector("vaadin-tooltip")
|
|
750
|
+
.setAttribute("text", this.nextPageTooltip);
|
|
751
|
+
button.setAttribute("slot", "next-page-button-slot");
|
|
752
|
+
button.setAttribute("id", "nextPage");
|
|
753
|
+
button.setAttribute("aria-label", "Next page");
|
|
754
|
+
button.addEventListener("click", () => this.__nextPage());
|
|
755
|
+
this.appendChild(button);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Adds current page text field to the toolbar slot named "toolbar-current-page-slot".
|
|
760
|
+
*/
|
|
761
|
+
_createCurrentPageTextField() {
|
|
762
|
+
const textField = document.createElement("vaadin-text-field");
|
|
763
|
+
textField.setAttribute("slot", "toolbar-current-page-slot");
|
|
764
|
+
textField.setAttribute("id", "currentPage");
|
|
765
|
+
textField.classList.add("toolbar-current-page");
|
|
766
|
+
textField.setAttribute("value", this.currentPage);
|
|
767
|
+
textField.addEventListener("change", () => this.__pageChange());
|
|
768
|
+
this.appendChild(textField);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Adds zoom select to the toolbar slot named "toolbar-zoom-slot".
|
|
773
|
+
*/
|
|
774
|
+
_createZoomSelect() {
|
|
775
|
+
const select = document.createElement("vaadin-select");
|
|
776
|
+
select.setAttribute("slot", "toolbar-zoom-slot");
|
|
777
|
+
select.setAttribute("id", "zoom");
|
|
778
|
+
select.classList.add("toolbar-zoom");
|
|
779
|
+
select.setAttribute("value", this.zoom);
|
|
780
|
+
select.items = this.__zoomItems;
|
|
781
|
+
select.addEventListener("value-changed", (e) => {
|
|
782
|
+
if (e.detail.value !== this.zoom) {
|
|
783
|
+
this.__zoomChanged(e.detail.value);
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
if (this.hideZoom) {
|
|
787
|
+
select.classList.add("hide-zoom");
|
|
788
|
+
} else {
|
|
789
|
+
select.classList.remove("hide-zoom");
|
|
790
|
+
}
|
|
791
|
+
this.appendChild(select);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
__computeZoomItems(autoZoomOptionLabel, fitZoomOptionLabel) {
|
|
795
|
+
return [
|
|
796
|
+
{ label: autoZoomOptionLabel, value: "auto" },
|
|
797
|
+
{ label: fitZoomOptionLabel, value: "page-fit" },
|
|
798
|
+
{ label: "50%", value: "0.5" },
|
|
799
|
+
{ label: "75%", value: "0.75" },
|
|
800
|
+
{ label: "100%", value: "1.0" },
|
|
801
|
+
{ label: "125%", value: "1.25" },
|
|
802
|
+
{ label: "150%", value: "1.5" },
|
|
803
|
+
{ label: "200%", value: "2.0" },
|
|
804
|
+
{ label: "300%", value: "3.0" },
|
|
805
|
+
{ label: "400%", value: "4.0" },
|
|
806
|
+
];
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
__setTitle(pdfTitle, filename) {
|
|
810
|
+
if (this.customTitle) {
|
|
811
|
+
this.__title = this.customTitle;
|
|
812
|
+
} else if (this.__viewer && this.toolbarOnlyFilename && filename) {
|
|
813
|
+
this.__title = filename;
|
|
814
|
+
} else if (pdfTitle && filename) {
|
|
815
|
+
this.__title = pdfTitle + " - " + filename;
|
|
816
|
+
} else if (pdfTitle) {
|
|
817
|
+
this.__title = pdfTitle;
|
|
818
|
+
} else if (filename) {
|
|
819
|
+
this.__title = filename;
|
|
820
|
+
} else {
|
|
821
|
+
this.__title = "PDF";
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
_addToolbarButtons() {
|
|
826
|
+
this._createSideBarToggleButton();
|
|
827
|
+
this._createZoomSelect();
|
|
828
|
+
this._createCurrentPageTextField();
|
|
829
|
+
this._createPreviousPageButton();
|
|
830
|
+
this._createNextPageButton();
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
firstUpdated() {
|
|
834
|
+
// Required by PDF.js annotation editor: --freetext-line-height must match
|
|
835
|
+
// the LINE_FACTOR constant (1.35) defined in src/shared/util.js
|
|
836
|
+
document.documentElement.style.setProperty('--freetext-line-height', '1.35');
|
|
837
|
+
|
|
838
|
+
this._toolbar = this.shadowRoot.querySelector("#toolbar");
|
|
839
|
+
this._viewerContainer = this.shadowRoot.querySelector("#viewerContainer");
|
|
840
|
+
this._outerContainer = this.shadowRoot.querySelector("#outerContainer");
|
|
841
|
+
this._viewer = this.shadowRoot.querySelector("#viewer");
|
|
842
|
+
this._thumbnailView = this.shadowRoot.querySelector("#thumbnailView");
|
|
843
|
+
|
|
844
|
+
this._addToolbarButtons();
|
|
845
|
+
|
|
846
|
+
this._viewerContainer.addEventListener(
|
|
847
|
+
"focus",
|
|
848
|
+
(e) => this.__setFocused(true),
|
|
849
|
+
true,
|
|
850
|
+
);
|
|
851
|
+
this._viewerContainer.addEventListener(
|
|
852
|
+
"blur",
|
|
853
|
+
(e) => this.__setFocused(false),
|
|
854
|
+
true,
|
|
855
|
+
);
|
|
856
|
+
this._viewerContainer.addEventListener("mousedown", (e) => {
|
|
857
|
+
this._mousedown = true;
|
|
858
|
+
const mouseUpListener = () => {
|
|
859
|
+
this._mousedown = false;
|
|
860
|
+
document.removeEventListener("mouseup", mouseUpListener);
|
|
861
|
+
};
|
|
862
|
+
document.addEventListener("mouseup", mouseUpListener);
|
|
863
|
+
});
|
|
864
|
+
|
|
865
|
+
// options
|
|
866
|
+
const eventBus = new EventBus();
|
|
867
|
+
|
|
868
|
+
// Defer initialization of reactive controller properties to avoid immediate update request
|
|
869
|
+
// that triggers "update scheduled after update" warning.
|
|
870
|
+
Promise.resolve().then(() => {
|
|
871
|
+
this.__linkService = new pdfjsLinkService.PDFLinkService({
|
|
872
|
+
eventBus,
|
|
873
|
+
});
|
|
874
|
+
var pdfRenderingQueue = new pdfjsRenderingQueue.PDFRenderingQueue();
|
|
875
|
+
var l10n = new GenericL10n(navigator.language || 'en-US');
|
|
876
|
+
|
|
877
|
+
// pdfViewer
|
|
878
|
+
this.__viewer = new pdfjsViewer.PDFViewer({
|
|
879
|
+
container: this._viewerContainer,
|
|
880
|
+
textLayerMode: 2,
|
|
881
|
+
viewer: this._viewer,
|
|
882
|
+
eventBus: eventBus,
|
|
883
|
+
linkService: this.__linkService,
|
|
884
|
+
renderingQueue: pdfRenderingQueue,
|
|
885
|
+
l10n: l10n,
|
|
886
|
+
annotationMode: this.renderInteractiveForms
|
|
887
|
+
? pdfjsLib.AnnotationMode.ENABLE_FORMS
|
|
888
|
+
: pdfjsLib.AnnotationMode.ENABLE,
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
this.__linkService.setViewer(this.__viewer);
|
|
892
|
+
pdfRenderingQueue.setViewer(this.__viewer);
|
|
893
|
+
|
|
894
|
+
// thumbnailViewer
|
|
895
|
+
this.__thumbnailViewer = new pdfjsThumbnailViewer.PDFThumbnailViewer({
|
|
896
|
+
container: this._thumbnailView,
|
|
897
|
+
eventBus: eventBus,
|
|
898
|
+
linkService: this.__linkService,
|
|
899
|
+
renderingQueue: pdfRenderingQueue,
|
|
900
|
+
l10n: l10n,
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
pdfRenderingQueue.setThumbnailViewer(this.__thumbnailViewer);
|
|
904
|
+
|
|
905
|
+
// Initialize listeners after viewer creation
|
|
906
|
+
this.__initListeners(eventBus);
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
__initListeners(eventBus) {
|
|
911
|
+
// listeners
|
|
912
|
+
eventBus.on("pagesinit", () => {
|
|
913
|
+
this.__viewer.currentScaleValue = this.zoom;
|
|
914
|
+
this.__loading = false;
|
|
915
|
+
this.__updateThumbnailViewer();
|
|
916
|
+
if (this.__sidebarOpen) {
|
|
917
|
+
this.__openSidebar();
|
|
918
|
+
} else {
|
|
919
|
+
this.__closeSidebar();
|
|
920
|
+
}
|
|
921
|
+
this.__viewer.currentPage = this.setCurrentPage();
|
|
922
|
+
});
|
|
923
|
+
eventBus.on("pagechanging", (event) => {
|
|
924
|
+
this.__updateCurrentPageValue(event.pageNumber);
|
|
925
|
+
this.__updatePageNumberStates();
|
|
926
|
+
if (
|
|
927
|
+
this.__thumbnailViewer &&
|
|
928
|
+
this.__thumbnailViewer.renderingQueue.isThumbnailViewEnabled
|
|
929
|
+
) {
|
|
930
|
+
this.__thumbnailViewer.scrollThumbnailIntoView(this.currentPage);
|
|
931
|
+
}
|
|
932
|
+
const currentPageInput = this.querySelector("#currentPage");
|
|
933
|
+
if (currentPageInput) {
|
|
934
|
+
currentPageInput.value = this.currentPage;
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
__updateCurrentPageValue(pageNumber) {
|
|
940
|
+
this.currentPage = "" + pageNumber;
|
|
941
|
+
this.dispatchEvent(new CustomEvent("currentPage-changed"));
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
__setFocused(focused) {
|
|
945
|
+
if (focused) {
|
|
946
|
+
this._viewerContainer.setAttribute("focused", "");
|
|
947
|
+
if (!this._mousedown) {
|
|
948
|
+
this._viewerContainer.setAttribute("focus-ring", "");
|
|
949
|
+
}
|
|
950
|
+
} else {
|
|
951
|
+
this._viewerContainer.removeAttribute("focused");
|
|
952
|
+
this._viewerContainer.removeAttribute("focus-ring");
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
__open(src) {
|
|
957
|
+
// Is there already a document loaded?
|
|
958
|
+
if (this.__document) {
|
|
959
|
+
// We need to close the current document
|
|
960
|
+
return this.__close().then(() => {
|
|
961
|
+
// and start over with opening the new one
|
|
962
|
+
return this.__open(src);
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
if (!src) {
|
|
966
|
+
// No file given, show nothing.
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
this.__setFilename(src);
|
|
970
|
+
this.__document = pdfjsLib.getDocument(new URL(src, document.baseURI).href);
|
|
971
|
+
return this.__document.promise.then(
|
|
972
|
+
(pdfDocument) => {
|
|
973
|
+
// Document loaded, specifying document for the viewer.
|
|
974
|
+
this.__thumbnailViewer.setDocument(pdfDocument);
|
|
975
|
+
this.__viewer.setDocument(pdfDocument);
|
|
976
|
+
this.__linkService.setDocument(pdfDocument);
|
|
977
|
+
|
|
978
|
+
this._toolbar.classList.add("ready");
|
|
979
|
+
this.__totalPages = pdfDocument.numPages;
|
|
980
|
+
this.__updatePageNumberStates();
|
|
981
|
+
this.__setPdfTitleFromMetadata(pdfDocument).then(() => {
|
|
982
|
+
this.dispatchEvent(
|
|
983
|
+
new CustomEvent("document-loaded", {
|
|
984
|
+
detail: {
|
|
985
|
+
document: pdfDocument,
|
|
986
|
+
},
|
|
987
|
+
}),
|
|
988
|
+
);
|
|
989
|
+
});
|
|
990
|
+
},
|
|
991
|
+
function (exception) {
|
|
992
|
+
console.error(exception && exception.message);
|
|
993
|
+
},
|
|
994
|
+
);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
__srcChanged(newSrc) {
|
|
998
|
+
this.__open(newSrc);
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* Closes opened PDF document.
|
|
1003
|
+
* @returns {Promise} - Returns the promise, which is resolved when all
|
|
1004
|
+
* destruction is completed.
|
|
1005
|
+
*/
|
|
1006
|
+
__close() {
|
|
1007
|
+
this._toolbar.classList.remove("ready");
|
|
1008
|
+
this.__filename = "PDF";
|
|
1009
|
+
if (!this.__document) {
|
|
1010
|
+
return Promise.resolve();
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
var promise = this.__document.destroy();
|
|
1014
|
+
if (this.__document) {
|
|
1015
|
+
this.__document = null;
|
|
1016
|
+
this.__viewer.setDocument(null);
|
|
1017
|
+
this.__thumbnailViewer.setDocument(null);
|
|
1018
|
+
this.__linkService.setDocument(null);
|
|
1019
|
+
}
|
|
1020
|
+
return promise;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
__setFilename(src) {
|
|
1024
|
+
let filename = pdfjsLib.getFilenameFromUrl(src) || src;
|
|
1025
|
+
try {
|
|
1026
|
+
filename = decodeURIComponent(filename);
|
|
1027
|
+
} catch (e) {
|
|
1028
|
+
// decodeURIComponent may throw URIError,
|
|
1029
|
+
// fall back to using the unprocessed url in that case
|
|
1030
|
+
}
|
|
1031
|
+
this.__filename = filename;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
__setPdfTitleFromMetadata(pdfDocument) {
|
|
1035
|
+
return pdfDocument.getMetadata().then((data) => {
|
|
1036
|
+
let pdfTitle;
|
|
1037
|
+
const metadata = data.metadata;
|
|
1038
|
+
if (metadata && metadata.has("dc:title")) {
|
|
1039
|
+
const title = metadata.get("dc:title");
|
|
1040
|
+
// Ghostscript sometimes returns 'Untitled', so prevent setting the
|
|
1041
|
+
// title to 'Untitled'.
|
|
1042
|
+
if (title !== "Untitled") {
|
|
1043
|
+
pdfTitle = title;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
const info = data.info;
|
|
1048
|
+
if (!pdfTitle && info && info["Title"]) {
|
|
1049
|
+
pdfTitle = info["Title"];
|
|
1050
|
+
}
|
|
1051
|
+
this.__pdfTitle = pdfTitle;
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
__updatePageNumberStates() {
|
|
1056
|
+
this.querySelector("#previousPage").disabled = this.currentPage === "1";
|
|
1057
|
+
this.querySelector("#nextPage").disabled =
|
|
1058
|
+
this.currentPage === "" + this.__totalPages;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
__zoomChanged(value) {
|
|
1062
|
+
if (!this.__viewer || this.__loading) {
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
// This logs error 'TextLayerBuilder._bindEvents: `this.cancel()` should have
|
|
1066
|
+
// been called when the page was reset, or rendering cancelled.'
|
|
1067
|
+
//
|
|
1068
|
+
// There is a problem deep inside pdfjs viewer that causes an console.error()
|
|
1069
|
+
// to be logged, but the component still works. It seems to be due to
|
|
1070
|
+
// webcomponents/shadow dom messing with
|
|
1071
|
+
// TODO: Fix the issue so that we get rid of the error in log
|
|
1072
|
+
this.__viewer.currentScaleValue = value;
|
|
1073
|
+
this.__viewer.forceRendering();
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
__pageChange(event) {
|
|
1077
|
+
const currentPageInput = this.querySelector("#currentPage");
|
|
1078
|
+
if (!currentPageInput) {
|
|
1079
|
+
return; // Component not yet rendered, skip
|
|
1080
|
+
}
|
|
1081
|
+
const currentPageValue = currentPageInput.value;
|
|
1082
|
+
let pageNumber = parseInt(currentPageValue, 10);
|
|
1083
|
+
if (isNaN(pageNumber)) {
|
|
1084
|
+
pageNumber = this.__viewer.currentPageNumber;
|
|
1085
|
+
currentPageInput.value = "" + pageNumber;
|
|
1086
|
+
}
|
|
1087
|
+
if (pageNumber < 1) {
|
|
1088
|
+
pageNumber = 1;
|
|
1089
|
+
}
|
|
1090
|
+
if (pageNumber > this.__totalPages) {
|
|
1091
|
+
pageNumber = this.__totalPages;
|
|
1092
|
+
}
|
|
1093
|
+
this.__viewer.currentPageNumber = pageNumber;
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
setCurrentPage(value) {
|
|
1097
|
+
if (value != undefined) {
|
|
1098
|
+
this.currentPage = "" + value;
|
|
1099
|
+
}
|
|
1100
|
+
this.__pageChange();
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
_getPage() {
|
|
1104
|
+
return this.__viewer.currentPageNumber;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
__previousPage() {
|
|
1108
|
+
this.__viewer.currentPageNumber--;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
__nextPage() {
|
|
1112
|
+
this.__viewer.currentPageNumber++;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
__toogleSidebar() {
|
|
1116
|
+
if (this._outerContainer.classList.length == 0) {
|
|
1117
|
+
this.__openSidebar();
|
|
1118
|
+
} else {
|
|
1119
|
+
this.__closeSidebar();
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
__openSidebar() {
|
|
1124
|
+
if (!this.__thumbnailViewer || this.__loading) {
|
|
1125
|
+
this.__sidebarOpen = true;
|
|
1126
|
+
} else {
|
|
1127
|
+
this.__thumbnailViewer.renderingQueue.isThumbnailViewEnabled = true;
|
|
1128
|
+
this.__updateThumbnailViewer();
|
|
1129
|
+
this._outerContainer.classList.add("sidebarOpen");
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
__closeSidebar() {
|
|
1134
|
+
if (!this.__thumbnailViewer || this.__loading) {
|
|
1135
|
+
this.__sidebarOpen = false;
|
|
1136
|
+
} else {
|
|
1137
|
+
this.__thumbnailViewer.renderingQueue.isThumbnailViewEnabled = false;
|
|
1138
|
+
this._outerContainer.classList.remove("sidebarOpen");
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
__updateThumbnailViewer() {
|
|
1143
|
+
const pagesCount = this.__totalPages;
|
|
1144
|
+
for (let i = 0; i < pagesCount; i++) {
|
|
1145
|
+
const pageView = this.__viewer.getPageView(i);
|
|
1146
|
+
if (
|
|
1147
|
+
pageView.renderingState === pdfUtils.RenderingStates.FINISHED
|
|
1148
|
+
) {
|
|
1149
|
+
const thumbnailView = this.__thumbnailViewer.getThumbnail(i);
|
|
1150
|
+
thumbnailView.setImage(pageView);
|
|
1151
|
+
} else {
|
|
1152
|
+
this.__thumbnailViewer.renderingQueue.renderHighestPriority();
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
var component = this;
|
|
1156
|
+
for (let i = 0; i < this.__thumbnailViewer._thumbnails.length; i++) {
|
|
1157
|
+
const thumbnailView = this.__thumbnailViewer.getThumbnail(i);
|
|
1158
|
+
thumbnailView.anchor.onclick = function () {
|
|
1159
|
+
const id = thumbnailView.id;
|
|
1160
|
+
thumbnailView.linkService.goToPage(id);
|
|
1161
|
+
component.dispatchEvent(
|
|
1162
|
+
new CustomEvent("thumbnail-clicked", {
|
|
1163
|
+
detail: {
|
|
1164
|
+
source: component,
|
|
1165
|
+
pageNumber: id,
|
|
1166
|
+
},
|
|
1167
|
+
}),
|
|
1168
|
+
);
|
|
1169
|
+
return false;
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
if (
|
|
1173
|
+
this.__thumbnailViewer &&
|
|
1174
|
+
this.__thumbnailViewer.renderingQueue.isThumbnailViewEnabled
|
|
1175
|
+
) {
|
|
1176
|
+
this.__thumbnailViewer.scrollThumbnailIntoView(this.currentPage);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
_onResize() {
|
|
1181
|
+
if (this.offsetWidth < 600) {
|
|
1182
|
+
this.classList.add("small-size");
|
|
1183
|
+
this._toolbar.classList.add("small-size");
|
|
1184
|
+
} else {
|
|
1185
|
+
this.classList.remove("small-size");
|
|
1186
|
+
this._toolbar.classList.remove("small-size");
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
/**
|
|
1191
|
+
* Rotates document clockwise.
|
|
1192
|
+
*/
|
|
1193
|
+
rotateCw() {
|
|
1194
|
+
let delta = 90;
|
|
1195
|
+
this.__viewer.pagesRotation += delta;
|
|
1196
|
+
this.__viewer.forceRendering();
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Rotates document counterclockwise.
|
|
1201
|
+
*/
|
|
1202
|
+
rotateCcw() {
|
|
1203
|
+
let delta = -90;
|
|
1204
|
+
this.__viewer.pagesRotation += delta;
|
|
1205
|
+
this.__viewer.forceRendering();
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
customElements.define(PdfViewerElement.is, PdfViewerElement);
|
|
1210
|
+
|
|
1211
|
+
/**
|
|
1212
|
+
* @namespace Vaadin
|
|
1213
|
+
*/
|
|
1214
|
+
window.Vaadin.PdfViewerElement = PdfViewerElement;
|